Render3D: Refactor common parts of OpenGLTexture and SoftRasterizerTexture into a new Render3DTexture class.
This commit is contained in:
parent
031f677486
commit
6d1db6daae
|
@ -26,9 +26,7 @@
|
|||
|
||||
#include "common.h"
|
||||
#include "debug.h"
|
||||
#include "gfx3d.h"
|
||||
#include "NDSSystem.h"
|
||||
#include "texcache.h"
|
||||
|
||||
#include "./filter/filter.h"
|
||||
#include "./filter/xbrz.h"
|
||||
|
@ -639,22 +637,12 @@ static void OGLGetDriverVersion(const char *oglVersionString,
|
|||
}
|
||||
}
|
||||
|
||||
OpenGLTexture::OpenGLTexture(u32 texAttributes, u32 palAttributes) : TextureStore(texAttributes, palAttributes)
|
||||
OpenGLTexture::OpenGLTexture(u32 texAttributes, u32 palAttributes) : Render3DTexture(texAttributes, palAttributes)
|
||||
{
|
||||
_cacheSize = GetUnpackSizeUsingFormat(TexFormat_32bpp);
|
||||
_invSizeS = 1.0f / (float)_sizeS;
|
||||
_invSizeT = 1.0f / (float)_sizeT;
|
||||
|
||||
_useDeposterize = false;
|
||||
_scalingFactor = 1;
|
||||
|
||||
memset(&_deposterizeSrcSurface, 0, sizeof(_deposterizeSrcSurface));
|
||||
memset(&_deposterizeDstSurface, 0, sizeof(_deposterizeDstSurface));
|
||||
|
||||
_deposterizeSrcSurface.Width = _deposterizeDstSurface.Width = _sizeS;
|
||||
_deposterizeSrcSurface.Height = _deposterizeDstSurface.Height = _sizeT;
|
||||
_deposterizeSrcSurface.Pitch = _deposterizeDstSurface.Pitch = 1;
|
||||
|
||||
_upscaleBuffer = NULL;
|
||||
|
||||
glGenTextures(1, &_texID);
|
||||
|
@ -665,26 +653,6 @@ OpenGLTexture::~OpenGLTexture()
|
|||
glDeleteTextures(1, &this->_texID);
|
||||
}
|
||||
|
||||
template <size_t SCALEFACTOR>
|
||||
void OpenGLTexture::_Upscale()
|
||||
{
|
||||
if ( (SCALEFACTOR != 2) && (SCALEFACTOR != 4) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
u32 *src = (u32 *)this->_deposterizeSrcSurface.Surface;
|
||||
|
||||
if ( (this->_packFormat == TEXMODE_A3I5) || (this->_packFormat == TEXMODE_A5I3) )
|
||||
{
|
||||
xbrz::scale<SCALEFACTOR, xbrz::ColorFormatARGB>(src, this->_upscaleBuffer, this->_sizeS, this->_sizeT);
|
||||
}
|
||||
else
|
||||
{
|
||||
xbrz::scale<SCALEFACTOR, xbrz::ColorFormatARGB_1bitAlpha>(src, this->_upscaleBuffer, this->_sizeS, this->_sizeT);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLTexture::Load(bool isNewTexture)
|
||||
{
|
||||
u32 *textureSrc = (u32 *)this->_deposterizeSrcSurface.Surface;
|
||||
|
@ -721,7 +689,7 @@ void OpenGLTexture::Load(bool isNewTexture)
|
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
|
||||
|
||||
this->_Upscale<2>();
|
||||
this->_Upscale<2>(textureSrc, this->_upscaleBuffer);
|
||||
|
||||
if (isNewTexture)
|
||||
{
|
||||
|
@ -741,13 +709,13 @@ void OpenGLTexture::Load(bool isNewTexture)
|
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
|
||||
|
||||
this->_Upscale<4>();
|
||||
this->_Upscale<4>(textureSrc, this->_upscaleBuffer);
|
||||
|
||||
if (isNewTexture)
|
||||
{
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, this->_sizeS*4, this->_sizeT*4, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, this->_upscaleBuffer);
|
||||
|
||||
this->_Upscale<2>();
|
||||
this->_Upscale<2>(textureSrc, this->_upscaleBuffer);
|
||||
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, this->_sizeS*2, this->_sizeT*2, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, this->_upscaleBuffer);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, this->_sizeS*1, this->_sizeT*1, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, textureSrc);
|
||||
|
@ -756,7 +724,7 @@ void OpenGLTexture::Load(bool isNewTexture)
|
|||
{
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, this->_sizeS*4, this->_sizeT*4, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, this->_upscaleBuffer);
|
||||
|
||||
this->_Upscale<2>();
|
||||
this->_Upscale<2>(textureSrc, this->_upscaleBuffer);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, this->_sizeS*2, this->_sizeT*2, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, this->_upscaleBuffer);
|
||||
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 2, 0, 0, this->_sizeS*1, this->_sizeT*1, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, textureSrc);
|
||||
|
@ -784,26 +752,6 @@ GLfloat OpenGLTexture::GetInvHeight() const
|
|||
return this->_invSizeT;
|
||||
}
|
||||
|
||||
bool OpenGLTexture::IsUsingDeposterize() const
|
||||
{
|
||||
return this->_useDeposterize;
|
||||
}
|
||||
|
||||
void OpenGLTexture::SetUseDeposterize(bool willDeposterize)
|
||||
{
|
||||
this->_useDeposterize = willDeposterize;
|
||||
}
|
||||
|
||||
size_t OpenGLTexture::GetScalingFactor() const
|
||||
{
|
||||
return this->_scalingFactor;
|
||||
}
|
||||
|
||||
void OpenGLTexture::SetScalingFactor(size_t scalingFactor)
|
||||
{
|
||||
this->_scalingFactor = ( (scalingFactor == 2) || (scalingFactor == 4) ) ? scalingFactor : 1;
|
||||
}
|
||||
|
||||
void OpenGLTexture::SetUnpackBuffer(void *unpackBuffer)
|
||||
{
|
||||
this->_deposterizeSrcSurface.Surface = (unsigned char *)unpackBuffer;
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include <set>
|
||||
#include <string>
|
||||
#include "render3D.h"
|
||||
#include "texcache.h"
|
||||
#include "types.h"
|
||||
|
||||
#ifndef OGLRENDER_3_2_H
|
||||
|
@ -511,7 +510,6 @@ struct VERTLIST;
|
|||
struct POLYLIST;
|
||||
struct INDEXLIST;
|
||||
struct POLY;
|
||||
class TexCacheItem;
|
||||
class OpenGLRenderer;
|
||||
|
||||
extern GPU3DInterface gpu3Dgl;
|
||||
|
@ -555,22 +553,15 @@ extern void (*OGLCreateRenderer_3_2_Func)(OpenGLRenderer **rendererPtr);
|
|||
|
||||
bool IsVersionSupported(unsigned int checkVersionMajor, unsigned int checkVersionMinor, unsigned int checkVersionRevision);
|
||||
|
||||
class OpenGLTexture : public TextureStore
|
||||
class OpenGLTexture : public Render3DTexture
|
||||
{
|
||||
private:
|
||||
protected:
|
||||
GLuint _texID;
|
||||
GLfloat _invSizeS;
|
||||
GLfloat _invSizeT;
|
||||
|
||||
bool _useDeposterize;
|
||||
size_t _scalingFactor;
|
||||
|
||||
SSurface _deposterizeSrcSurface;
|
||||
SSurface _deposterizeDstSurface;
|
||||
|
||||
u32 *_upscaleBuffer;
|
||||
|
||||
template<size_t SCALEFACTOR> void _Upscale();
|
||||
|
||||
public:
|
||||
OpenGLTexture(u32 texAttributes, u32 palAttributes);
|
||||
virtual ~OpenGLTexture();
|
||||
|
@ -581,12 +572,6 @@ public:
|
|||
GLfloat GetInvWidth() const;
|
||||
GLfloat GetInvHeight() const;
|
||||
|
||||
bool IsUsingDeposterize() const;
|
||||
void SetUseDeposterize(bool willDeposterize);
|
||||
|
||||
size_t GetScalingFactor() const;
|
||||
void SetScalingFactor(size_t scalingFactor);
|
||||
|
||||
void SetUnpackBuffer(void *unpackBuffer);
|
||||
void SetDeposterizeBuffer(void *dstBuffer, void *workingBuffer);
|
||||
void SetUpscalingBuffer(void *upscaleBuffer);
|
||||
|
|
|
@ -25,9 +25,7 @@
|
|||
|
||||
#include "common.h"
|
||||
#include "debug.h"
|
||||
#include "gfx3d.h"
|
||||
#include "NDSSystem.h"
|
||||
#include "texcache.h"
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
|
||||
#include "matrix.h"
|
||||
#include "render3D.h"
|
||||
#include "gfx3d.h"
|
||||
#include "MMU.h"
|
||||
#include "NDSSystem.h"
|
||||
#include "utils/task.h"
|
||||
|
@ -1148,13 +1147,11 @@ static void SoftRasterizerRendererDestroy()
|
|||
}
|
||||
}
|
||||
|
||||
SoftRasterizerTexture::SoftRasterizerTexture(u32 texAttributes, u32 palAttributes) : TextureStore(texAttributes, palAttributes)
|
||||
SoftRasterizerTexture::SoftRasterizerTexture(u32 texAttributes, u32 palAttributes) : Render3DTexture(texAttributes, palAttributes)
|
||||
{
|
||||
_cacheSize = GetUnpackSizeUsingFormat(TexFormat_15bpp);
|
||||
_unpackData = (u32 *)malloc_alignedCacheLine(_cacheSize);
|
||||
|
||||
_useDeposterize = false;
|
||||
_scalingFactor = 1;
|
||||
_customBuffer = NULL;
|
||||
|
||||
_renderData = _unpackData;
|
||||
|
@ -1164,12 +1161,6 @@ SoftRasterizerTexture::SoftRasterizerTexture(u32 texAttributes, u32 palAttribute
|
|||
_renderHeightMask = _renderHeight - 1;
|
||||
_renderWidthShift = 0;
|
||||
|
||||
memset(&_deposterizeSrcSurface, 0, sizeof(_deposterizeSrcSurface));
|
||||
memset(&_deposterizeDstSurface, 0, sizeof(_deposterizeDstSurface));
|
||||
|
||||
_deposterizeSrcSurface.Width = _deposterizeDstSurface.Width = _sizeS;
|
||||
_deposterizeSrcSurface.Height = _deposterizeDstSurface.Height = _sizeT;
|
||||
_deposterizeSrcSurface.Pitch = _deposterizeDstSurface.Pitch = 1;
|
||||
_deposterizeSrcSurface.Surface = (unsigned char *)_unpackData;
|
||||
|
||||
u32 tempWidth = _renderWidth;
|
||||
|
@ -1187,26 +1178,6 @@ SoftRasterizerTexture::~SoftRasterizerTexture()
|
|||
free_aligned(this->_customBuffer);
|
||||
}
|
||||
|
||||
template <size_t SCALEFACTOR>
|
||||
void SoftRasterizerTexture::_Upscale()
|
||||
{
|
||||
if ( (SCALEFACTOR != 2) && (SCALEFACTOR != 4) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
u32 *src = (this->_useDeposterize) ? (u32 *)this->_deposterizeDstSurface.Surface : this->_unpackData;
|
||||
|
||||
if (this->_packFormat == TEXMODE_A3I5 || this->_packFormat == TEXMODE_A5I3)
|
||||
{
|
||||
xbrz::scale<SCALEFACTOR, xbrz::ColorFormatARGB>(src, this->_customBuffer, this->_sizeS, this->_sizeT);
|
||||
}
|
||||
else
|
||||
{
|
||||
xbrz::scale<SCALEFACTOR, xbrz::ColorFormatARGB_1bitAlpha>(src, this->_customBuffer, this->_sizeS, this->_sizeT);
|
||||
}
|
||||
}
|
||||
|
||||
void SoftRasterizerTexture::Load()
|
||||
{
|
||||
if (this->_scalingFactor == 1 && !this->_useDeposterize)
|
||||
|
@ -1215,21 +1186,24 @@ void SoftRasterizerTexture::Load()
|
|||
}
|
||||
else
|
||||
{
|
||||
this->Unpack<TexFormat_32bpp>((u32 *)this->_unpackData);
|
||||
u32 *textureSrc = this->_unpackData;
|
||||
|
||||
this->Unpack<TexFormat_32bpp>(textureSrc);
|
||||
|
||||
if (this->_useDeposterize)
|
||||
{
|
||||
RenderDeposterize(this->_deposterizeSrcSurface, this->_deposterizeDstSurface);
|
||||
textureSrc = (u32 *)this->_deposterizeDstSurface.Surface;
|
||||
}
|
||||
|
||||
switch (this->_scalingFactor)
|
||||
{
|
||||
case 2:
|
||||
this->_Upscale<2>();
|
||||
this->_Upscale<2>(textureSrc, this->_customBuffer);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
this->_Upscale<4>();
|
||||
this->_Upscale<4>(textureSrc, this->_customBuffer);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -1275,11 +1249,6 @@ u32 SoftRasterizerTexture::GetRenderWidthShift() const
|
|||
return this->_renderWidthShift;
|
||||
}
|
||||
|
||||
bool SoftRasterizerTexture::IsUsingDeposterize() const
|
||||
{
|
||||
return this->_useDeposterize;
|
||||
}
|
||||
|
||||
void SoftRasterizerTexture::SetUseDeposterize(bool willDeposterize)
|
||||
{
|
||||
this->_useDeposterize = willDeposterize;
|
||||
|
@ -1312,11 +1281,6 @@ void SoftRasterizerTexture::SetUseDeposterize(bool willDeposterize)
|
|||
}
|
||||
}
|
||||
|
||||
size_t SoftRasterizerTexture::GetScalingFactor() const
|
||||
{
|
||||
return this->_scalingFactor;
|
||||
}
|
||||
|
||||
void SoftRasterizerTexture::SetScalingFactor(size_t scalingFactor)
|
||||
{
|
||||
if ( (scalingFactor != 2) && (scalingFactor != 4) )
|
||||
|
|
|
@ -20,13 +20,11 @@
|
|||
|
||||
#include "render3D.h"
|
||||
#include "gfx3d.h"
|
||||
#include "texcache.h"
|
||||
|
||||
#define SOFTRASTERIZER_DEPTH_EQUAL_TEST_TOLERANCE 0x200
|
||||
|
||||
extern GPU3DInterface gpu3DRasterize;
|
||||
|
||||
class TexCacheItem;
|
||||
class SoftRasterizerRenderer;
|
||||
|
||||
struct SoftRasterizerPostProcessParams
|
||||
|
@ -40,7 +38,7 @@ struct SoftRasterizerPostProcessParams
|
|||
bool fogAlphaOnly;
|
||||
};
|
||||
|
||||
class SoftRasterizerTexture : public TextureStore
|
||||
class SoftRasterizerTexture : public Render3DTexture
|
||||
{
|
||||
protected:
|
||||
u32 *_unpackData;
|
||||
|
@ -52,15 +50,8 @@ protected:
|
|||
u32 _renderHeightMask;
|
||||
u32 _renderWidthShift;
|
||||
|
||||
bool _useDeposterize;
|
||||
size_t _scalingFactor;
|
||||
u32 *_customBuffer;
|
||||
|
||||
SSurface _deposterizeSrcSurface;
|
||||
SSurface _deposterizeDstSurface;
|
||||
|
||||
template<size_t SCALEFACTOR> void _Upscale();
|
||||
|
||||
public:
|
||||
SoftRasterizerTexture(u32 texAttributes, u32 palAttributes);
|
||||
virtual ~SoftRasterizerTexture();
|
||||
|
@ -76,10 +67,7 @@ public:
|
|||
u32 GetRenderHeightMask() const;
|
||||
u32 GetRenderWidthShift() const;
|
||||
|
||||
bool IsUsingDeposterize() const;
|
||||
void SetUseDeposterize(bool willDeposterize);
|
||||
|
||||
size_t GetScalingFactor() const;
|
||||
void SetScalingFactor(size_t scalingFactor);
|
||||
};
|
||||
|
||||
|
|
|
@ -25,9 +25,7 @@
|
|||
#endif
|
||||
|
||||
#include "utils/bits.h"
|
||||
#include "gfx3d.h"
|
||||
#include "MMU.h"
|
||||
#include "texcache.h"
|
||||
#include "./filter/filter.h"
|
||||
#include "./filter/xbrz.h"
|
||||
|
||||
|
@ -195,6 +193,60 @@ void FragmentAttributesBuffer::SetAll(const FragmentAttributes &attr)
|
|||
}
|
||||
}
|
||||
|
||||
Render3DTexture::Render3DTexture(u32 texAttributes, u32 palAttributes) : TextureStore(texAttributes, palAttributes)
|
||||
{
|
||||
_useDeposterize = false;
|
||||
_scalingFactor = 1;
|
||||
|
||||
memset(&_deposterizeSrcSurface, 0, sizeof(_deposterizeSrcSurface));
|
||||
memset(&_deposterizeDstSurface, 0, sizeof(_deposterizeDstSurface));
|
||||
|
||||
_deposterizeSrcSurface.Width = _deposterizeDstSurface.Width = _sizeS;
|
||||
_deposterizeSrcSurface.Height = _deposterizeDstSurface.Height = _sizeT;
|
||||
_deposterizeSrcSurface.Pitch = _deposterizeDstSurface.Pitch = 1;
|
||||
}
|
||||
|
||||
template <size_t SCALEFACTOR>
|
||||
void Render3DTexture::_Upscale(const u32 *__restrict src, u32 *__restrict dst)
|
||||
{
|
||||
if ( (SCALEFACTOR != 2) && (SCALEFACTOR != 4) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( (this->_packFormat == TEXMODE_A3I5) || (this->_packFormat == TEXMODE_A5I3) )
|
||||
{
|
||||
xbrz::scale<SCALEFACTOR, xbrz::ColorFormatARGB>(src, dst, this->_sizeS, this->_sizeT);
|
||||
}
|
||||
else
|
||||
{
|
||||
xbrz::scale<SCALEFACTOR, xbrz::ColorFormatARGB_1bitAlpha>(src, dst, this->_sizeS, this->_sizeT);
|
||||
}
|
||||
}
|
||||
|
||||
bool Render3DTexture::IsUsingDeposterize() const
|
||||
{
|
||||
return this->_useDeposterize;
|
||||
}
|
||||
|
||||
void Render3DTexture::SetUseDeposterize(bool willDeposterize)
|
||||
{
|
||||
this->_useDeposterize = willDeposterize;
|
||||
}
|
||||
|
||||
size_t Render3DTexture::GetScalingFactor() const
|
||||
{
|
||||
return this->_scalingFactor;
|
||||
}
|
||||
|
||||
void Render3DTexture::SetScalingFactor(size_t scalingFactor)
|
||||
{
|
||||
this->_scalingFactor = ( (scalingFactor == 2) || (scalingFactor == 4) ) ? scalingFactor : 1;
|
||||
}
|
||||
|
||||
template void Render3DTexture::_Upscale<2>(const u32 *__restrict src, u32 *__restrict dst);
|
||||
template void Render3DTexture::_Upscale<4>(const u32 *__restrict src, u32 *__restrict dst);
|
||||
|
||||
void* Render3D::operator new(size_t size)
|
||||
{
|
||||
void *newPtr = malloc_alignedCacheLine(size);
|
||||
|
|
|
@ -19,8 +19,9 @@
|
|||
#ifndef RENDER3D_H
|
||||
#define RENDER3D_H
|
||||
|
||||
#include "gfx3d.h"
|
||||
#include "types.h"
|
||||
#include "gfx3d.h"
|
||||
#include "texcache.h"
|
||||
#include "./filter/filter.h"
|
||||
|
||||
#define kUnsetTranslucentPolyID 255
|
||||
|
@ -113,6 +114,26 @@ struct Render3DDeviceInfo
|
|||
u8 maxSamples;
|
||||
};
|
||||
|
||||
class Render3DTexture : public TextureStore
|
||||
{
|
||||
protected:
|
||||
bool _useDeposterize;
|
||||
size_t _scalingFactor;
|
||||
SSurface _deposterizeSrcSurface;
|
||||
SSurface _deposterizeDstSurface;
|
||||
|
||||
template<size_t SCALEFACTOR> void _Upscale(const u32 *__restrict src, u32 *__restrict dst);
|
||||
|
||||
public:
|
||||
Render3DTexture(u32 texAttributes, u32 palAttributes);
|
||||
|
||||
bool IsUsingDeposterize() const;
|
||||
void SetUseDeposterize(bool willDeposterize);
|
||||
|
||||
size_t GetScalingFactor() const;
|
||||
void SetScalingFactor(size_t scalingFactor);
|
||||
};
|
||||
|
||||
class Render3D
|
||||
{
|
||||
protected:
|
||||
|
|
Loading…
Reference in New Issue