1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

Move zLUT initialization to DepthBufferList::init().

This commit is contained in:
Sergey Lipskiy 2015-01-27 17:56:22 +06:00
parent cd758aed08
commit 6ab92eac4f
4 changed files with 24 additions and 34 deletions

View File

@ -151,10 +151,25 @@ void DepthBuffer::bindDepthImageTexture() {
void DepthBufferList::init()
{
m_pCurrent = NULL;
m_pzLUT = new u16[0x40000];
for (int i = 0; i<0x40000; i++) {
u32 exponent = 0;
u32 testbit = 1 << 17;
while ((i & testbit) && (exponent < 7)) {
exponent++;
testbit = 1 << (17 - exponent);
}
const u32 mantissa = (i >> (6 - (6 < exponent ? 6 : exponent))) & 0x7ff;
m_pzLUT[i] = (u16)(((exponent << 11) | mantissa) << 2);
}
}
void DepthBufferList::destroy()
{
delete[] m_pzLUT;
m_pzLUT = NULL;
m_pCurrent = NULL;
m_list.clear();
}

View File

@ -40,13 +40,16 @@ public:
return depthBufferList;
}
const u16 * const getZLUT() const {return m_pzLUT;}
private:
DepthBufferList() : m_pCurrent(NULL) {}
DepthBufferList() : m_pCurrent(NULL), m_pzLUT(NULL) {}
DepthBufferList(const FrameBufferList &);
typedef std::list<DepthBuffer> DepthBuffers;
DepthBuffers m_list;
DepthBuffer *m_pCurrent;
u16 * m_pzLUT;
};
inline

View File

@ -70,7 +70,6 @@ private:
GLuint m_PBO;
CachedTexture * m_pTexture;
u32 m_lastDList;
u16 * zLUT;
};
#endif // GLES2
@ -728,20 +727,6 @@ void DepthBufferToRDRAM::Init()
glBindBuffer(GL_PIXEL_PACK_BUFFER, m_PBO);
glBufferData(GL_PIXEL_PACK_BUFFER, 640*480*sizeof(float), NULL, GL_DYNAMIC_DRAW);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
zLUT = new u16[0x40000];
for (int i = 0; i<0x40000; i++) {
u32 exponent = 0;
u32 testbit = 1 << 17;
while ((i & testbit) && (exponent < 7)) {
exponent++;
testbit = 1 << (17 - exponent);
}
u32 mantissa = (i >> (6 - (6 < exponent ? 6 : exponent))) & 0x7ff;
zLUT[i] = (u16)(((exponent << 11) | mantissa) << 2);
}
}
void DepthBufferToRDRAM::Destroy() {
@ -754,8 +739,6 @@ void DepthBufferToRDRAM::Destroy() {
}
glDeleteBuffers(1, &m_PBO);
m_PBO = 0;
delete[] zLUT;
zLUT = 0;
}
bool DepthBufferToRDRAM::CopyToRDRAM( u32 _address) {
@ -793,12 +776,13 @@ bool DepthBufferToRDRAM::CopyToRDRAM( u32 _address) {
f32 * ptr_src = (f32*)pixelData;
u16 *ptr_dst = (u16*)(RDRAM + address);
const float scale = gSP.viewport.vscale[2] * 32768.0f;
const float trans = gSP.viewport.vtrans[2] * 32768.0f;
const f32 scale = gSP.viewport.vscale[2] * 32768.0f;
const f32 trans = gSP.viewport.vtrans[2] * 32768.0f;
const u16 * const zLUT = depthBufferList().getZLUT();
for (u32 y = 0; y < VI.height; ++y) {
for (u32 x = 0; x < VI.width; ++x) {
float z = ptr_src[x + (VI.height - y - 1)*VI.width];
f32 z = ptr_src[x + (VI.height - y - 1)*VI.width];
if (z == 1.0f)
ptr_dst[(x + y*VI.width) ^ 1] = zLUT[0x3FFFF];
else {

View File

@ -72,18 +72,7 @@ void InitZlutTexture()
if (!video().getRender().isImageTexturesSupported())
return;
u16 * zLUT = new u16[0x40000];
for(int i=0; i<0x40000; i++) {
u32 exponent = 0;
u32 testbit = 1 << 17;
while((i & testbit) && (exponent < 7)) {
exponent++;
testbit = 1 << (17 - exponent);
}
u32 mantissa = (i >> (6 - (6 < exponent ? 6 : exponent))) & 0x7ff;
zLUT[i] = (u16)(((exponent << 11) | mantissa) << 2);
}
const u16 * const zLUT = depthBufferList().getZLUT();
glGenTextures(1, &g_zlut_tex);
glBindTexture(GL_TEXTURE_2D, g_zlut_tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@ -93,7 +82,6 @@ void InitZlutTexture()
glTexImage2D(GL_TEXTURE_2D, 0, GL_R16,
512, 512, 0, GL_RED, GL_UNSIGNED_SHORT,
zLUT);
delete[] zLUT;
glBindImageTexture(ZlutImageUnit, g_zlut_tex, 0, GL_FALSE, 0, GL_READ_ONLY, GL_R16UI);
}