- Clean up magic numbers related to the 3D framebuffer size.
This commit is contained in:
rogerman 2014-11-26 23:17:34 +00:00
parent fb2e4730e3
commit f17312c91d
6 changed files with 63 additions and 59 deletions

View File

@ -816,9 +816,9 @@ void OpenGLRenderer::ConvertFramebuffer(const u32 *__restrict srcBuffer, u32 *ds
// to the DS Y-coordinate.
for(int i = 0, y = 191; y >= 0; y--)
{
u32 *__restrict dst = dstBuffer + (y << 8); // Same as dstBuffer + (y * 256)
u32 *__restrict dst = dstBuffer + (y * GFX3D_FRAMEBUFFER_WIDTH);
for(unsigned int x = 0; x < 256; x++, i++)
for(unsigned int x = 0; x < GFX3D_FRAMEBUFFER_WIDTH; x++, i++)
{
// Use the correct endian format since OpenGL uses the native endian of
// the architecture it is running on.
@ -1067,7 +1067,7 @@ Render3DError OpenGLRenderer_1_2::CreatePBOs()
for (unsigned int i = 0; i < 2; i++)
{
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, this->ref->pboRenderDataID[i]);
glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, 256 * 192 * sizeof(u32), NULL, GL_STREAM_READ_ARB);
glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT * sizeof(u32), NULL, GL_STREAM_READ_ARB);
}
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
@ -1336,9 +1336,9 @@ Render3DError OpenGLRenderer_1_2::CreateMultisampledFBO()
glGenRenderbuffersEXT(1, &OGLRef.rboMultisampleDepthStencilID);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, OGLRef.rboMultisampleColorID);
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, maxSamples, GL_RGBA, 256, 192);
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, maxSamples, GL_RGBA, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, OGLRef.rboMultisampleDepthStencilID);
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, maxSamples, GL_DEPTH24_STENCIL8_EXT, 256, 192);
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, maxSamples, GL_DEPTH24_STENCIL8_EXT, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT);
// Set up multisampled rendering FBO
glGenFramebuffersEXT(1, &OGLRef.fboMultisampleRenderID);
@ -1505,7 +1505,7 @@ Render3DError OpenGLRenderer_1_2::CreateClearImage()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 192, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glBindTexture(GL_TEXTURE_2D, OGLRef.texClearImageDepthStencilID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@ -1513,7 +1513,7 @@ Render3DError OpenGLRenderer_1_2::CreateClearImage()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8_EXT, 256, 192, 0, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8_EXT, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, 0, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, NULL);
glActiveTextureARB(GL_TEXTURE0_ARB);
@ -1540,9 +1540,9 @@ Render3DError OpenGLRenderer_1_2::UploadClearImage(const GLushort *clearImageCol
glActiveTextureARB(GL_TEXTURE0_ARB + OGLTextureUnitID_ClearImage);
glBindTexture(GL_TEXTURE_2D, OGLRef.texClearImageColorID);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 192, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, clearImageColorBuffer);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, clearImageColorBuffer);
glBindTexture(GL_TEXTURE_2D, OGLRef.texClearImageDepthStencilID);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 192, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, clearImageDepthBuffer);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, clearImageDepthBuffer);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTextureARB(GL_TEXTURE0_ARB);
@ -1785,7 +1785,7 @@ Render3DError OpenGLRenderer_1_2::DownsampleFBO()
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, OGLRef.selectedRenderingFBO);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, OGLRef.fboFinalOutputID);
glBlitFramebufferEXT(0, 0, 256, 192, 0, 0, 256, 192, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBlitFramebufferEXT(0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, 0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboFinalOutputID);
return OGLERROR_NOERR;
@ -1800,7 +1800,7 @@ Render3DError OpenGLRenderer_1_2::ReadBackPixels()
this->DownsampleFBO();
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, this->ref->pboRenderDataID[i]);
glReadPixels(0, 0, 256, 192, GL_BGRA, GL_UNSIGNED_BYTE, 0);
glReadPixels(0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, GL_BGRA, GL_UNSIGNED_BYTE, 0);
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
}
@ -1959,8 +1959,8 @@ Render3DError OpenGLRenderer_1_2::EndRender(const u64 frameCount)
Render3DError OpenGLRenderer_1_2::UpdateClearImage(const u16 *__restrict colorBuffer, const u16 *__restrict depthBuffer, const u8 clearStencil, const u8 xScroll, const u8 yScroll)
{
static const size_t pixelsPerLine = 256;
static const size_t lineCount = 192;
static const size_t pixelsPerLine = GFX3D_FRAMEBUFFER_WIDTH;
static const size_t lineCount = GFX3D_FRAMEBUFFER_HEIGHT;
static const size_t totalPixelCount = pixelsPerLine * lineCount;
static const size_t bufferSize = totalPixelCount * sizeof(u16);
@ -2039,7 +2039,7 @@ Render3DError OpenGLRenderer_1_2::ClearUsingImage() const
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, OGLRef.fboClearImageID);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, OGLRef.selectedRenderingFBO);
glBlitFramebufferEXT(0, 0, 256, 192, 0, 0, 256, 192, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
glBlitFramebufferEXT(0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, 0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.selectedRenderingFBO);
// It might seem wasteful to be doing a separate glClear(GL_STENCIL_BUFFER_BIT) instead
@ -2388,7 +2388,7 @@ Render3DError OpenGLRenderer_1_2::RenderFinish()
this->DownsampleFBO();
u32 *__restrict workingBuffer = this->GPU_screen3D[i];
glReadPixels(0, 0, 256, 192, GL_BGRA, GL_UNSIGNED_BYTE, workingBuffer);
glReadPixels(0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, GL_BGRA, GL_UNSIGNED_BYTE, workingBuffer);
this->ConvertFramebuffer(workingBuffer, (u32 *)gfx3d_convertedScreen);
}
@ -2451,7 +2451,7 @@ Render3DError OpenGLRenderer_1_3::CreateClearImage()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 192, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glBindTexture(GL_TEXTURE_2D, OGLRef.texClearImageDepthStencilID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@ -2459,7 +2459,7 @@ Render3DError OpenGLRenderer_1_3::CreateClearImage()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8_EXT, 256, 192, 0, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8_EXT, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, 0, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, NULL);
glActiveTexture(GL_TEXTURE0);
@ -2486,9 +2486,9 @@ Render3DError OpenGLRenderer_1_3::UploadClearImage(const GLushort *clearImageCol
glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_ClearImage);
glBindTexture(GL_TEXTURE_2D, OGLRef.texClearImageColorID);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 192, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, clearImageColorBuffer);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, clearImageColorBuffer);
glBindTexture(GL_TEXTURE_2D, OGLRef.texClearImageDepthStencilID);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 192, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, clearImageDepthBuffer);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, clearImageDepthBuffer);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE0);
@ -2582,7 +2582,7 @@ Render3DError OpenGLRenderer_1_5::CreatePBOs()
for (unsigned int i = 0; i < 2; i++)
{
glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, OGLRef.pboRenderDataID[i]);
glBufferData(GL_PIXEL_PACK_BUFFER_ARB, 256 * 192 * sizeof(u32), NULL, GL_STREAM_READ);
glBufferData(GL_PIXEL_PACK_BUFFER_ARB, GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT * sizeof(u32), NULL, GL_STREAM_READ);
}
glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0);
@ -2713,7 +2713,7 @@ Render3DError OpenGLRenderer_1_5::ReadBackPixels()
this->DownsampleFBO();
glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, this->ref->pboRenderDataID[i]);
glReadPixels(0, 0, 256, 192, GL_BGRA, GL_UNSIGNED_BYTE, 0);
glReadPixels(0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, GL_BGRA, GL_UNSIGNED_BYTE, 0);
glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0);
}
@ -2751,7 +2751,7 @@ Render3DError OpenGLRenderer_1_5::RenderFinish()
this->DownsampleFBO();
u32 *__restrict workingBuffer = this->GPU_screen3D[i];
glReadPixels(0, 0, 256, 192, GL_BGRA, GL_UNSIGNED_BYTE, workingBuffer);
glReadPixels(0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, GL_BGRA, GL_UNSIGNED_BYTE, workingBuffer);
this->ConvertFramebuffer(workingBuffer, (u32 *)gfx3d_convertedScreen);
}
@ -3203,7 +3203,7 @@ Render3DError OpenGLRenderer_2_1::ReadBackPixels()
this->DownsampleFBO();
glBindBuffer(GL_PIXEL_PACK_BUFFER, this->ref->pboRenderDataID[i]);
glReadPixels(0, 0, 256, 192, GL_BGRA, GL_UNSIGNED_BYTE, 0);
glReadPixels(0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, GL_BGRA, GL_UNSIGNED_BYTE, 0);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
this->gpuScreen3DHasNewData[i] = true;

View File

@ -418,7 +418,7 @@ protected:
u16 currentToonTable16[32];
bool toonTableNeedsUpdate;
DS_ALIGN(16) u32 GPU_screen3D[2][256 * 192 * sizeof(u32)];
DS_ALIGN(16) u32 GPU_screen3D[2][GFX3D_FRAMEBUFFER_WIDTH * GFX3D_FRAMEBUFFER_HEIGHT * sizeof(u32)];
bool gpuScreen3DHasNewData[2];
unsigned int doubleBufferIndex;
u8 clearImageStencilValue;

View File

@ -297,9 +297,9 @@ Render3DError OpenGLRenderer_3_2::CreateFBOs()
glGenRenderbuffers(1, &OGLRef.rboFinalOutputDepthStencilID);
glBindRenderbuffer(GL_RENDERBUFFER, OGLRef.rboFinalOutputColorID);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, 256, 192);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT);
glBindRenderbuffer(GL_RENDERBUFFER, OGLRef.rboFinalOutputDepthStencilID);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 256, 192);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT);
// Set up FBOs
glGenFramebuffers(1, &OGLRef.fboClearImageID);
@ -400,9 +400,9 @@ Render3DError OpenGLRenderer_3_2::CreateMultisampledFBO()
glGenRenderbuffers(1, &OGLRef.rboMultisampleDepthStencilID);
glBindRenderbuffer(GL_RENDERBUFFER, OGLRef.rboMultisampleColorID);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, maxSamples, GL_RGBA, 256, 192);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, maxSamples, GL_RGBA, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT);
glBindRenderbuffer(GL_RENDERBUFFER, OGLRef.rboMultisampleDepthStencilID);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, maxSamples, GL_DEPTH24_STENCIL8, 256, 192);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, maxSamples, GL_DEPTH24_STENCIL8, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT);
// Set up multisampled rendering FBO
glGenFramebuffers(1, &OGLRef.fboMultisampleRenderID);
@ -557,7 +557,7 @@ Render3DError OpenGLRenderer_3_2::DownsampleFBO()
glBindFramebuffer(GL_READ_FRAMEBUFFER, OGLRef.selectedRenderingFBO);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, OGLRef.fboFinalOutputID);
glBlitFramebuffer(0, 0, 256, 192, 0, 0, 256, 192, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBlitFramebuffer(0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, 0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboFinalOutputID);
return OGLERROR_NOERR;
@ -569,7 +569,7 @@ Render3DError OpenGLRenderer_3_2::ClearUsingImage() const
glBindFramebuffer(GL_READ_FRAMEBUFFER, OGLRef.fboClearImageID);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, OGLRef.selectedRenderingFBO);
glBlitFramebuffer(0, 0, 256, 192, 0, 0, 256, 192, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST);
glBlitFramebuffer(0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, 0, 0, GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.selectedRenderingFBO);
return OGLERROR_NOERR;

View File

@ -304,7 +304,7 @@ static float normalTable[1024];
#define fix2float(v) (((float)((s32)(v))) / (float)(1<<12))
#define fix10_2float(v) (((float)((s32)(v))) / (float)(1<<9))
CACHE_ALIGN u8 gfx3d_convertedScreen[256*192*4];
CACHE_ALIGN u8 gfx3d_convertedScreen[GFX3D_FRAMEBUFFER_WIDTH*GFX3D_FRAMEBUFFER_HEIGHT*4];
// Matrix stack handling
CACHE_ALIGN MatrixStack mtxStack[4] = {
@ -2313,12 +2313,12 @@ void gfx3d_GetLineData(int line, u8** dst)
void gfx3d_GetLineData15bpp(int line, u16** dst)
{
//TODO - this is not very thread safe!!!
static u16 buf[256];
static u16 buf[GFX3D_FRAMEBUFFER_WIDTH];
*dst = buf;
u8* lineData;
gfx3d_GetLineData(line, &lineData);
for(int i=0;i<256;i++)
for(int i=0; i<GFX3D_FRAMEBUFFER_WIDTH; i++)
{
const u8 r = lineData[i*4+0];
const u8 g = lineData[i*4+1];
@ -2415,7 +2415,7 @@ SFORMAT SF_GFX3D[]={
{ "GTVC", 4, 1, &tempVertInfo.count},
{ "GTVM", 4, 4, tempVertInfo.map},
{ "GTVF", 4, 1, &tempVertInfo.first},
{ "G3CX", 1, 4*256*192, gfx3d_convertedScreen},
{ "G3CX", 1, 4*GFX3D_FRAMEBUFFER_WIDTH*GFX3D_FRAMEBUFFER_HEIGHT, gfx3d_convertedScreen},
{ 0 }
};

View File

@ -26,6 +26,10 @@
#include "emufile.h"
// Pixel dimensions of the NDS 3D framebuffer
#define GFX3D_FRAMEBUFFER_WIDTH 256
#define GFX3D_FRAMEBUFFER_HEIGHT 192
//geometry engine command numbers
#define GFX3D_NOP 0x00
#define GFX3D_MTX_MODE 0x10
@ -754,8 +758,8 @@ extern CACHE_ALIGN const u8 material_3bit_to_8bit[8];
//these contain the 3d framebuffer converted into the most useful format
//they are stored here instead of in the renderers in order to consolidate the buffers
extern CACHE_ALIGN u8 gfx3d_convertedScreen[256*192*4];
extern CACHE_ALIGN u8 gfx3d_convertedAlpha[256*192*2]; //see cpp for explanation of illogical *2
extern CACHE_ALIGN u8 gfx3d_convertedScreen[GFX3D_FRAMEBUFFER_WIDTH*GFX3D_FRAMEBUFFER_HEIGHT*4];
extern CACHE_ALIGN u8 gfx3d_convertedAlpha[GFX3D_FRAMEBUFFER_WIDTH*GFX3D_FRAMEBUFFER_HEIGHT*2]; //see cpp for explanation of illogical *2
extern BOOL isSwapBuffers;

View File

@ -115,8 +115,8 @@ static FORCEINLINE int fastFloor(float f)
// verts[vert_index] = &rawvert;
//}
static Fragment _screen[256*192];
static FragmentColor _screenColor[256*192];
static Fragment _screen[GFX3D_FRAMEBUFFER_WIDTH*GFX3D_FRAMEBUFFER_HEIGHT];
static FragmentColor _screenColor[GFX3D_FRAMEBUFFER_WIDTH*GFX3D_FRAMEBUFFER_HEIGHT];
static FORCEINLINE int iround(float f) {
return (int)f; //lol
@ -817,14 +817,14 @@ public:
width -= -x;
x = 0;
}
if(x+width > (RENDERER?256:engine->width))
if(x+width > (RENDERER?GFX3D_FRAMEBUFFER_WIDTH:engine->width))
{
if(RENDERER && !lineHack)
{
printf("rasterizer rendering at x=%d! oops!\n",x+width-1);
return;
}
width = (RENDERER?256:engine->width)-x;
width = (RENDERER?GFX3D_FRAMEBUFFER_WIDTH:engine->width)-x;
}
while(width-- > 0)
@ -854,7 +854,7 @@ public:
bool first=true;
//HACK: special handling for horizontal line poly
if (lineHack && left->Height == 0 && right->Height == 0 && left->Y<192 && left->Y>=0)
if (lineHack && left->Height == 0 && right->Height == 0 && left->Y<GFX3D_FRAMEBUFFER_HEIGHT && left->Y>=0)
{
bool draw = (!SLI || (left->Y & SLI_MASK) == SLI_VALUE);
if(draw) drawscanline(left,right,lineHack);
@ -1217,7 +1217,7 @@ static void SoftRastVramReconfigureSignal()
static void SoftRastConvertFramebuffer()
{
memcpy(gfx3d_convertedScreen,_screenColor,256*192*4);
memcpy(gfx3d_convertedScreen, _screenColor, GFX3D_FRAMEBUFFER_WIDTH*GFX3D_FRAMEBUFFER_HEIGHT*4);
}
void SoftRasterizerEngine::initFramebuffer(const int width, const int height, const bool clearImage)
@ -1246,7 +1246,7 @@ void SoftRasterizerEngine::initFramebuffer(const int width, const int height, co
if(clearImage)
{
//need to handle this somehow..
assert(width==256 && height==192);
assert(width==GFX3D_FRAMEBUFFER_WIDTH && height==GFX3D_FRAMEBUFFER_HEIGHT);
u16* clearImage = (u16*)MMU.texInfo.textureSlotAddr[2];
u16* clearDepth = (u16*)MMU.texInfo.textureSlotAddr[3];
@ -1260,9 +1260,9 @@ void SoftRasterizerEngine::initFramebuffer(const int width, const int height, co
FragmentColor *dstColor = screenColor;
Fragment *dst = screen;
for(int iy=0;iy<192;iy++) {
for(int iy=0; iy<GFX3D_FRAMEBUFFER_HEIGHT; iy++) {
int y = ((iy + yscroll)&255)<<8;
for(int ix=0;ix<256;ix++) {
for(int ix=0; ix<GFX3D_FRAMEBUFFER_WIDTH; ix++) {
int x = (ix + xscroll)&255;
int adr = y + x;
@ -1397,9 +1397,9 @@ void SoftRasterizerEngine::framebufferProcess()
edgeMarkDisabled[i] = 0;
}
for(int i=0,y=0;y<192;y++)
for(int i=0,y=0; y<GFX3D_FRAMEBUFFER_HEIGHT; y++)
{
for(int x=0;x<256;x++,i++)
for(int x=0; x<GFX3D_FRAMEBUFFER_WIDTH; x++,i++)
{
Fragment destFragment = screen[i];
u8 self = destFragment.polyid.opaque;
@ -1413,8 +1413,8 @@ void SoftRasterizerEngine::framebufferProcess()
FragmentColor edgeColor = edgeMarkColors[self>>3];
#define PIXOFFSET(dx,dy) ((dx)+(256*(dy)))
#define ISEDGE(dx,dy) ((x+(dx)!=256) && (x+(dx)!=-1) && (y+(dy)!=192) && (y+(dy)!=-1) && self > screen[i+PIXOFFSET(dx,dy)].polyid.opaque)
#define PIXOFFSET(dx,dy) ((dx)+(GFX3D_FRAMEBUFFER_WIDTH*(dy)))
#define ISEDGE(dx,dy) ((x+(dx)!=GFX3D_FRAMEBUFFER_WIDTH) && (x+(dx)!=-1) && (y+(dy)!=GFX3D_FRAMEBUFFER_HEIGHT) && (y+(dy)!=-1) && self > screen[i+PIXOFFSET(dx,dy)].polyid.opaque)
#define DRAWEDGE(dx,dy) alphaBlend(screenColor[i+PIXOFFSET(dx,dy)], edgeColor)
bool upleft = ISEDGE(-1,-1);
@ -1457,7 +1457,7 @@ void SoftRasterizerEngine::framebufferProcess()
u32 g = GFX3D_5TO6((gfx3d.renderState.fogColor>>5)&0x1F);
u32 b = GFX3D_5TO6((gfx3d.renderState.fogColor>>10)&0x1F);
u32 a = (gfx3d.renderState.fogColor>>16)&0x1F;
for(int i=0;i<256*192;i++)
for(int i=0; i<GFX3D_FRAMEBUFFER_WIDTH*GFX3D_FRAMEBUFFER_HEIGHT; i++)
{
Fragment &destFragment = screen[i];
if(!destFragment.fogged) continue;
@ -1477,7 +1477,7 @@ void SoftRasterizerEngine::framebufferProcess()
}
////debug alpha channel framebuffer contents
//for(int i=0;i<256*192;i++)
//for(int i=0;i<GFX3D_FRAMEBUFFER_WIDTH*GFX3D_FRAMEBUFFER_HEIGHT;i++)
//{
// FragmentColor &destFragmentColor = screenColor[i];
// destFragmentColor.r = destFragmentColor.a;
@ -1512,10 +1512,10 @@ void SoftRasterizerEngine::performClipping(bool hirez)
template<bool CUSTOM> void SoftRasterizerEngine::performViewportTransforms(int width, int height)
{
const float xfactor = width/256.0f;
const float yfactor = height/192.0f;
const float xmax = 256.0f*xfactor-(CUSTOM?0.001f:0); //fudge factor to keep from overrunning render buffers
const float ymax = 192.0f*yfactor-(CUSTOM?0.001f:0);
const float xfactor = (float)width/GFX3D_FRAMEBUFFER_WIDTH;
const float yfactor = (float)height/GFX3D_FRAMEBUFFER_HEIGHT;
const float xmax = GFX3D_FRAMEBUFFER_WIDTH*xfactor-(CUSTOM?0.001f:0); //fudge factor to keep from overrunning render buffers
const float ymax = GFX3D_FRAMEBUFFER_HEIGHT*yfactor-(CUSTOM?0.001f:0);
//viewport transforms
@ -1668,18 +1668,18 @@ static void SoftRastRender()
mainSoftRasterizer.indexlist = &gfx3d.indexlist;
mainSoftRasterizer.screen = _screen;
mainSoftRasterizer.screenColor = _screenColor;
mainSoftRasterizer.width = 256;
mainSoftRasterizer.height = 192;
mainSoftRasterizer.width = GFX3D_FRAMEBUFFER_WIDTH;
mainSoftRasterizer.height = GFX3D_FRAMEBUFFER_HEIGHT;
//setup fog variables (but only if fog is enabled)
if(gfx3d.renderState.enableFog)
mainSoftRasterizer.updateFogTable();
mainSoftRasterizer.initFramebuffer(256,192,gfx3d.renderState.enableClearImage?true:false);
mainSoftRasterizer.initFramebuffer(GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT, gfx3d.renderState.enableClearImage?true:false);
mainSoftRasterizer.updateToonTable();
mainSoftRasterizer.updateFloatColors();
mainSoftRasterizer.performClipping(CommonSettings.GFX3D_HighResolutionInterpolateColor);
mainSoftRasterizer.performViewportTransforms<false>(256,192);
mainSoftRasterizer.performViewportTransforms<false>(GFX3D_FRAMEBUFFER_WIDTH, GFX3D_FRAMEBUFFER_HEIGHT);
mainSoftRasterizer.performBackfaceTests();
mainSoftRasterizer.performCoordAdjustment(true);
mainSoftRasterizer.setupTextures(true);