From de19ce6250dcdcaae8a5a67d2e88694b771eafad Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 19 Aug 2020 13:02:54 +0200 Subject: 3D/GL: make polygon generation code cleaner, add quicker codepath for triangles (also laying ground for some evil experiment) also fix stupid bug with line polygons --- src/GPU3D_OpenGL.cpp | 126 +++++++++++++++++++++++++-------------------------- 1 file changed, 63 insertions(+), 63 deletions(-) (limited to 'src/GPU3D_OpenGL.cpp') diff --git a/src/GPU3D_OpenGL.cpp b/src/GPU3D_OpenGL.cpp index 8a06874..b47f0b5 100644 --- a/src/GPU3D_OpenGL.cpp +++ b/src/GPU3D_OpenGL.cpp @@ -527,6 +527,46 @@ void SetupPolygon(RendererPolygon* rp, Polygon* polygon) } } +u32* SetupVertex(Polygon* poly, int vid, Vertex* vtx, u32 vtxattr, u32* vptr) +{ + u32 z = poly->FinalZ[vid]; + u32 w = poly->FinalW[vid]; + + u32 alpha = (poly->Attr >> 16) & 0x1F; + + // Z should always fit within 16 bits, so it's okay to do this + u32 zshift = 0; + while (z > 0xFFFF) { z >>= 1; zshift++; } + + u32 x, y; + if (ScaleFactor > 1) + { + x = (vtx->HiresPosition[0] * ScaleFactor) >> 4; + y = (vtx->HiresPosition[1] * ScaleFactor) >> 4; + } + else + { + x = vtx->FinalPosition[0]; + y = vtx->FinalPosition[1]; + } + + *vptr++ = x | (y << 16); + *vptr++ = z | (w << 16); + + *vptr++ = (vtx->FinalColor[0] >> 1) | + ((vtx->FinalColor[1] >> 1) << 8) | + ((vtx->FinalColor[2] >> 1) << 16) | + (alpha << 24); + + *vptr++ = (u16)vtx->TexCoords[0] | ((u16)vtx->TexCoords[1] << 16); + + *vptr++ = vtxattr | (zshift << 16); + *vptr++ = poly->TexParam; + *vptr++ = poly->TexPalette; + + return vptr; +} + void BuildPolygons(RendererPolygon* polygons, int npolys) { u32* vptr = &VertexBuffer[0]; @@ -564,43 +604,16 @@ void BuildPolygons(RendererPolygon* polygons, int npolys) { Vertex* vtx = poly->Vertices[j]; - u32 z = poly->FinalZ[j]; - u32 w = poly->FinalW[j]; - - // Z should always fit within 16 bits, so it's okay to do this - u32 zshift = 0; - while (z > 0xFFFF) { z >>= 1; zshift++; } - - u32 x, y; - if (ScaleFactor > 1) - { - x = (vtx->HiresPosition[0] * ScaleFactor) >> 4; - y = (vtx->HiresPosition[1] * ScaleFactor) >> 4; - } - else - { - x = vtx->FinalPosition[0]; - y = vtx->FinalPosition[1]; - } - if (j > 0) { - if (lastx == x && lasty == y) continue; + if (lastx == vtx->FinalPosition[0] && + lasty == vtx->FinalPosition[1]) continue; } - *vptr++ = x | (y << 16); - *vptr++ = z | (w << 16); - - *vptr++ = (vtx->FinalColor[0] >> 1) | - ((vtx->FinalColor[1] >> 1) << 8) | - ((vtx->FinalColor[2] >> 1) << 16) | - (alpha << 24); - - *vptr++ = (u16)vtx->TexCoords[0] | ((u16)vtx->TexCoords[1] << 16); + lastx = vtx->FinalPosition[0]; + lasty = vtx->FinalPosition[1]; - *vptr++ = vtxattr | (zshift << 16); - *vptr++ = poly->TexParam; - *vptr++ = poly->TexPalette; + vptr = SetupVertex(poly, j, vtx, vtxattr, vptr); *iptr++ = vidx; rp->NumIndices++; @@ -610,46 +623,33 @@ void BuildPolygons(RendererPolygon* polygons, int npolys) if (nout >= 2) break; } } - else + else if (poly->NumVertices == 3) // regular triangle { rp->PrimType = GL_TRIANGLES; - for (int j = 0; j < poly->NumVertices; j++) + for (int j = 0; j < 3; j++) { Vertex* vtx = poly->Vertices[j]; - u32 z = poly->FinalZ[j]; - u32 w = poly->FinalW[j]; - - // Z should always fit within 16 bits, so it's okay to do this - u32 zshift = 0; - while (z > 0xFFFF) { z >>= 1; zshift++; } - - u32 x, y; - if (ScaleFactor > 1) - { - x = (vtx->HiresPosition[0] * ScaleFactor) >> 4; - y = (vtx->HiresPosition[1] * ScaleFactor) >> 4; - } - else - { - x = vtx->FinalPosition[0]; - y = vtx->FinalPosition[1]; - } - - *vptr++ = x | (y << 16); - *vptr++ = z | (w << 16); + vptr = SetupVertex(poly, j, vtx, vtxattr, vptr); + vidx++; + } - *vptr++ = (vtx->FinalColor[0] >> 1) | - ((vtx->FinalColor[1] >> 1) << 8) | - ((vtx->FinalColor[2] >> 1) << 16) | - (alpha << 24); + // build a triangle + *iptr++ = vidx_first; + *iptr++ = vidx - 2; + *iptr++ = vidx - 1; + rp->NumIndices += 3; + } + else + { + rp->PrimType = GL_TRIANGLES; - *vptr++ = (u16)vtx->TexCoords[0] | ((u16)vtx->TexCoords[1] << 16); + for (int j = 0; j < poly->NumVertices; j++) + { + Vertex* vtx = poly->Vertices[j]; - *vptr++ = vtxattr | (zshift << 16); - *vptr++ = poly->TexParam; - *vptr++ = poly->TexPalette; + vptr = SetupVertex(poly, j, vtx, vtxattr, vptr); if (j >= 2) { -- cgit v1.2.3 From 00f33343e4b2b58eacba46238928fc7c870063ad Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 19 Aug 2020 14:53:42 +0200 Subject: 3D/GL: experimental attempt at reducing warping on quads, pentagons, etc... --- src/GPU3D_OpenGL.cpp | 124 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 114 insertions(+), 10 deletions(-) (limited to 'src/GPU3D_OpenGL.cpp') diff --git a/src/GPU3D_OpenGL.cpp b/src/GPU3D_OpenGL.cpp index b47f0b5..1abc1de 100644 --- a/src/GPU3D_OpenGL.cpp +++ b/src/GPU3D_OpenGL.cpp @@ -641,26 +641,130 @@ void BuildPolygons(RendererPolygon* polygons, int npolys) *iptr++ = vidx - 1; rp->NumIndices += 3; } - else + else // quad, pentagon, etc { rp->PrimType = GL_TRIANGLES; - for (int j = 0; j < poly->NumVertices; j++) + if (false) { - Vertex* vtx = poly->Vertices[j]; + // regular triangle-splitting - vptr = SetupVertex(poly, j, vtx, vtxattr, vptr); + for (int j = 0; j < poly->NumVertices; j++) + { + Vertex* vtx = poly->Vertices[j]; + + vptr = SetupVertex(poly, j, vtx, vtxattr, vptr); - if (j >= 2) + if (j >= 2) + { + // build a triangle + *iptr++ = vidx_first; + *iptr++ = vidx - 1; + *iptr++ = vidx; + rp->NumIndices += 3; + } + + vidx++; + } + } + else + { + // attempt at 'better' splitting + // this doesn't get rid of the error while splitting a bigger polygon into triangles + // but we can attempt to reduce it + + u32 cX = 0, cY = 0; + float cZ = 0; + float cW = 0; + + float cR = 0, cG = 0, cB = 0; + float cS = 0, cT = 0; + + for (int j = 0; j < poly->NumVertices; j++) { - // build a triangle - *iptr++ = vidx_first; - *iptr++ = vidx - 1; - *iptr++ = vidx; - rp->NumIndices += 3; + Vertex* vtx = poly->Vertices[j]; + + cX += vtx->HiresPosition[0]; + cY += vtx->HiresPosition[1]; + + float fw = (float)poly->FinalW[j] * poly->NumVertices; + cW += 1.0f / fw; + + if (poly->WBuffer) cZ += poly->FinalZ[j] / fw; + else cZ += poly->FinalZ[j]; + + cR += (vtx->FinalColor[0] >> 1) / fw; + cG += (vtx->FinalColor[1] >> 1) / fw; + cB += (vtx->FinalColor[2] >> 1) / fw; + + cS += vtx->TexCoords[0] / fw; + cT += vtx->TexCoords[1] / fw; } + cX /= poly->NumVertices; + cY /= poly->NumVertices; + + cW = 1.0f / cW; + + if (poly->WBuffer) cZ *= cW; + else cZ /= poly->NumVertices; + + cR *= cW; + cG *= cW; + cB *= cW; + + cS *= cW; + cT *= cW; + + cX = (cX * ScaleFactor) >> 4; + cY = (cY * ScaleFactor) >> 4; + + u32 w = (u32)cW; + + u32 z = (u32)cZ; + u32 zshift = 0; + while (z > 0xFFFF) { z >>= 1; zshift++; } + + // build center vertex + *vptr++ = cX | (cY << 16); + *vptr++ = z | (w << 16); + + *vptr++ = (u32)cR | + ((u32)cG << 8) | + ((u32)cB << 16) | + (alpha << 24); + + *vptr++ = (u16)cS | ((u16)cT << 16); + + *vptr++ = vtxattr | (zshift << 16); + *vptr++ = poly->TexParam; + *vptr++ = poly->TexPalette; + vidx++; + + // build the final polygon + for (int j = 0; j < poly->NumVertices; j++) + { + Vertex* vtx = poly->Vertices[j]; + + vptr = SetupVertex(poly, j, vtx, vtxattr, vptr); + + if (j >= 1) + { + // build a triangle + *iptr++ = vidx_first; + *iptr++ = vidx - 1; + *iptr++ = vidx; + rp->NumIndices += 3; + } + + vidx++; + } + + *iptr++ = vidx_first; + *iptr++ = vidx - 1; + *iptr++ = vidx_first + 1; + rp->NumIndices += 3; } } -- cgit v1.2.3 From 959e7f568da28872058c7e266db6aca1cc3f464c Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 20 Aug 2020 01:19:09 +0200 Subject: GL: be more careful with framebuffer mappings. might fix issues. --- src/GPU3D_OpenGL.cpp | 5 +++-- src/GPU_OpenGL.cpp | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src/GPU3D_OpenGL.cpp') diff --git a/src/GPU3D_OpenGL.cpp b/src/GPU3D_OpenGL.cpp index 1abc1de..f7b9b42 100644 --- a/src/GPU3D_OpenGL.cpp +++ b/src/GPU3D_OpenGL.cpp @@ -1159,8 +1159,9 @@ void RenderFrame() { CurShaderID = -1; - if (Antialias) glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[2]); - else glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[FrontBuffer]); + glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); + if (Antialias) glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferID[2]); + else glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferID[FrontBuffer]); ShaderConfig.uScreenSize[0] = ScreenW; ShaderConfig.uScreenSize[1] = ScreenH; diff --git a/src/GPU_OpenGL.cpp b/src/GPU_OpenGL.cpp index 1cb6864..b460e07 100644 --- a/src/GPU_OpenGL.cpp +++ b/src/GPU_OpenGL.cpp @@ -162,7 +162,8 @@ void SetRenderSettings(RenderSettings& settings) void RenderFrame() { - glBindFramebuffer(GL_FRAMEBUFFER, CompScreenOutputFB); + glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, CompScreenOutputFB); glDisable(GL_DEPTH_TEST); glDisable(GL_STENCIL_TEST); -- cgit v1.2.3 From 0688a15e47eeb8a2761e0d318b8686a9728ce227 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 20 Aug 2020 01:37:33 +0200 Subject: blarg --- src/GPU3D_OpenGL.cpp | 4 ++++ src/GPU_OpenGL.cpp | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'src/GPU3D_OpenGL.cpp') diff --git a/src/GPU3D_OpenGL.cpp b/src/GPU3D_OpenGL.cpp index f7b9b42..debb5fa 100644 --- a/src/GPU3D_OpenGL.cpp +++ b/src/GPU3D_OpenGL.cpp @@ -372,6 +372,8 @@ bool Init() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5_A1, 1024, 48, 0, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, NULL); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + return true; } @@ -479,6 +481,8 @@ void SetRenderSettings(GPU::RenderSettings& settings) glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelbufferID); glBufferData(GL_PIXEL_PACK_BUFFER, 256*192*4, NULL, GL_DYNAMIC_READ); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + //glLineWidth(scale); //glLineWidth(1.5); } diff --git a/src/GPU_OpenGL.cpp b/src/GPU_OpenGL.cpp index b460e07..359e9cd 100644 --- a/src/GPU_OpenGL.cpp +++ b/src/GPU_OpenGL.cpp @@ -121,6 +121,8 @@ bool Init() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + return true; } @@ -157,6 +159,8 @@ void SetRenderSettings(RenderSettings& settings) glBindFramebuffer(GL_FRAMEBUFFER, CompScreenOutputFB); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, CompScreenOutputTex, 0); glDrawBuffers(1, fbassign); + + glBindFramebuffer(GL_FRAMEBUFFER, 0); } -- cgit v1.2.3 From b5f9278b3a12dbeca2a3b33e8c6331dd9995d5e0 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 20 Aug 2020 03:01:05 +0200 Subject: GL: hopefully finally fix the checkerboard issue --- src/GPU3D_OpenGL.cpp | 74 +++++++++++----------------------------------------- 1 file changed, 15 insertions(+), 59 deletions(-) (limited to 'src/GPU3D_OpenGL.cpp') diff --git a/src/GPU3D_OpenGL.cpp b/src/GPU3D_OpenGL.cpp index debb5fa..72b3fc6 100644 --- a/src/GPU3D_OpenGL.cpp +++ b/src/GPU3D_OpenGL.cpp @@ -342,9 +342,6 @@ bool Init() SetupDefaultTexParams(FramebufferTex[5]); SetupDefaultTexParams(FramebufferTex[7]); - // downscale framebuffer for antialiased mode - SetupDefaultTexParams(FramebufferTex[2]); - // downscale framebuffer for display capture (always 256x192) SetupDefaultTexParams(FramebufferTex[3]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 192, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); @@ -406,52 +403,26 @@ void Reset() void SetRenderSettings(GPU::RenderSettings& settings) { int scale = settings.GL_ScaleFactor; - bool antialias = false; // REMOVE ME! - - if (antialias) scale *= 2; ScaleFactor = scale; - Antialias = antialias; ScreenW = 256 * scale; ScreenH = 192 * scale; - if (!antialias) - { - glBindTexture(GL_TEXTURE_2D, FramebufferTex[0]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glBindTexture(GL_TEXTURE_2D, FramebufferTex[1]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glBindTexture(GL_TEXTURE_2D, FramebufferTex[2]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glBindTexture(GL_TEXTURE_2D, FramebufferTex[4]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, ScreenW, ScreenH, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL); - //glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH32F_STENCIL8, ScreenW, ScreenH, 0, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, NULL); - glBindTexture(GL_TEXTURE_2D, FramebufferTex[5]); - //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, ScreenW, ScreenH, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, NULL); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, ScreenW, ScreenH, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); - glBindTexture(GL_TEXTURE_2D, FramebufferTex[6]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, 1, 1, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL); - glBindTexture(GL_TEXTURE_2D, FramebufferTex[7]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, NULL); - } - else - { - glBindTexture(GL_TEXTURE_2D, FramebufferTex[0]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW/2, ScreenH/2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glBindTexture(GL_TEXTURE_2D, FramebufferTex[1]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW/2, ScreenH/2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glBindTexture(GL_TEXTURE_2D, FramebufferTex[2]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glBindTexture(GL_TEXTURE_2D, FramebufferTex[4]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, ScreenW/2, ScreenH/2, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL); - glBindTexture(GL_TEXTURE_2D, FramebufferTex[5]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, ScreenW/2, ScreenH/2, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, NULL); - glBindTexture(GL_TEXTURE_2D, FramebufferTex[6]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, ScreenW, ScreenH, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL); - glBindTexture(GL_TEXTURE_2D, FramebufferTex[7]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, ScreenW, ScreenH, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, NULL); - } + glBindTexture(GL_TEXTURE_2D, FramebufferTex[0]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glBindTexture(GL_TEXTURE_2D, FramebufferTex[1]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + + glBindTexture(GL_TEXTURE_2D, FramebufferTex[4]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, ScreenW, ScreenH, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL); + glBindTexture(GL_TEXTURE_2D, FramebufferTex[5]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, ScreenW, ScreenH, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + + glBindTexture(GL_TEXTURE_2D, FramebufferTex[6]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, ScreenW, ScreenH, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL); + glBindTexture(GL_TEXTURE_2D, FramebufferTex[7]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, ScreenW, ScreenH, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[3]); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FramebufferTex[3], 0); @@ -466,12 +437,6 @@ void SetRenderSettings(GPU::RenderSettings& settings) glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[1]); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FramebufferTex[1], 0); - glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, FramebufferTex[4], 0); - glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, FramebufferTex[5], 0); - glDrawBuffers(2, fbassign); - - glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[2]); - glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FramebufferTex[2], 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, FramebufferTex[6], 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, FramebufferTex[7], 0); glDrawBuffers(2, fbassign); @@ -1164,8 +1129,7 @@ void RenderFrame() CurShaderID = -1; glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); - if (Antialias) glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferID[2]); - else glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferID[FrontBuffer]); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferID[FrontBuffer]); ShaderConfig.uScreenSize[0] = ScreenW; ShaderConfig.uScreenSize[1] = ScreenH; @@ -1327,14 +1291,6 @@ void RenderFrame() RenderSceneChunk(0, 192); } - if (Antialias) - { - glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferID[2]); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferID[FrontBuffer]); - glBlitFramebuffer(0, 0, ScreenW, ScreenH, 0, 0, ScreenW/2, ScreenH/2, GL_COLOR_BUFFER_BIT, GL_LINEAR); - } - - //glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[FrontBuffer]); FrontBuffer = FrontBuffer ? 0 : 1; } -- cgit v1.2.3 From c29e6303140af7aa7744d4bc4650399e286a3ac1 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 24 Aug 2020 12:00:13 +0200 Subject: oops. fixes #725 --- src/GPU3D_OpenGL.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/GPU3D_OpenGL.cpp') diff --git a/src/GPU3D_OpenGL.cpp b/src/GPU3D_OpenGL.cpp index 72b3fc6..ba77a0c 100644 --- a/src/GPU3D_OpenGL.cpp +++ b/src/GPU3D_OpenGL.cpp @@ -519,6 +519,27 @@ u32* SetupVertex(Polygon* poly, int vid, Vertex* vtx, u32 vtxattr, u32* vptr) y = vtx->FinalPosition[1]; } + // correct nearly-vertical edges that would look vertical on the DS + /*{ + int vtopid = vid - 1; + if (vtopid < 0) vtopid = poly->NumVertices-1; + Vertex* vtop = poly->Vertices[vtopid]; + if (vtop->FinalPosition[1] >= vtx->FinalPosition[1]) + { + vtopid = vid + 1; + if (vtopid >= poly->NumVertices) vtopid = 0; + vtop = poly->Vertices[vtopid]; + } + if ((vtop->FinalPosition[1] < vtx->FinalPosition[1]) && + (vtx->FinalPosition[0] == vtop->FinalPosition[0]-1)) + { + if (ScaleFactor > 1) + x = (vtop->HiresPosition[0] * ScaleFactor) >> 4; + else + x = vtop->FinalPosition[0]; + } + }*/ + *vptr++ = x | (y << 16); *vptr++ = z | (w << 16); @@ -1076,9 +1097,9 @@ void RenderSceneChunk(int y, int h) glStencilMask(0); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, FramebufferTex[4]); + glBindTexture(GL_TEXTURE_2D, FramebufferTex[FrontBuffer ? 6 : 4]); glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, FramebufferTex[5]); + glBindTexture(GL_TEXTURE_2D, FramebufferTex[FrontBuffer ? 7 : 5]); glBindBuffer(GL_ARRAY_BUFFER, ClearVertexBufferID); glBindVertexArray(ClearVertexArrayID); -- cgit v1.2.3 From e7025abcdc81f558706204375b753aad77490147 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 24 Aug 2020 19:32:07 +0200 Subject: * fix build error * make betterer polygon splitting an option * add GL_LEQUAL depth test for 'equal' mode, might help --- src/Config.cpp | 2 ++ src/GPU.h | 1 + src/GPU3D_OpenGL.cpp | 27 +++++++++++++++++++-------- src/frontend/qt_sdl/PlatformConfig.cpp | 4 ++-- src/frontend/qt_sdl/PlatformConfig.h | 2 +- src/frontend/qt_sdl/VideoSettingsDialog.cpp | 7 +++++++ src/frontend/qt_sdl/VideoSettingsDialog.h | 1 + src/frontend/qt_sdl/VideoSettingsDialog.ui | 12 +++++++++++- src/frontend/qt_sdl/main.cpp | 3 +++ 9 files changed, 47 insertions(+), 12 deletions(-) (limited to 'src/GPU3D_OpenGL.cpp') diff --git a/src/Config.cpp b/src/Config.cpp index 2a98935..949c1bf 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -37,6 +37,8 @@ char DSiBIOS7Path[1024]; char DSiFirmwarePath[1024]; char DSiNANDPath[1024]; +int RandomizeMAC; + #ifdef JIT_ENABLED int JIT_Enable = false; int JIT_MaxBlockSize = 32; diff --git a/src/GPU.h b/src/GPU.h index 039e065..c7d25ec 100644 --- a/src/GPU.h +++ b/src/GPU.h @@ -79,6 +79,7 @@ typedef struct bool Soft_Threaded; int GL_ScaleFactor; + bool GL_BetterPolygons; } RenderSettings; diff --git a/src/GPU3D_OpenGL.cpp b/src/GPU3D_OpenGL.cpp index ba77a0c..658b261 100644 --- a/src/GPU3D_OpenGL.cpp +++ b/src/GPU3D_OpenGL.cpp @@ -113,7 +113,7 @@ GLuint TexMemID; GLuint TexPalMemID; int ScaleFactor; -bool Antialias; +bool BetterPolygons; int ScreenW, ScreenH; GLuint FramebufferTex[8]; @@ -405,6 +405,7 @@ void SetRenderSettings(GPU::RenderSettings& settings) int scale = settings.GL_ScaleFactor; ScaleFactor = scale; + BetterPolygons = settings.GL_BetterPolygons; ScreenW = 256 * scale; ScreenH = 192 * scale; @@ -635,7 +636,7 @@ void BuildPolygons(RendererPolygon* polygons, int npolys) { rp->PrimType = GL_TRIANGLES; - if (false) + if (!BetterPolygons) { // regular triangle-splitting @@ -835,6 +836,10 @@ void RenderSceneChunk(int y, int h) GLboolean fogenable = (RenderDispCnt & (1<<7)) ? GL_TRUE : GL_FALSE; + // TODO: proper 'equal' depth test! + // (has margin of +-0x200 in Z-buffer mode, +-0xFF in W-buffer mode) + // for now we're using GL_LEQUAL to make it work to some extent + // pass 1: opaque pixels UseRenderShader(flags); @@ -853,8 +858,10 @@ void RenderSceneChunk(int y, int h) if (rp->PolyData->IsShadowMask) { i++; continue; } - // zorp - glDepthFunc(GL_LESS); + if (rp->PolyData->Attr & (1<<14)) + glDepthFunc(GL_LEQUAL); + else + glDepthFunc(GL_LESS); u32 polyattr = rp->PolyData->Attr; u32 polyid = (polyattr >> 24) & 0x3F; @@ -939,8 +946,10 @@ void RenderSceneChunk(int y, int h) { UseRenderShader(flags | RenderFlag_Trans); - // zorp - glDepthFunc(GL_LESS); + if (rp->PolyData->Attr & (1<<14)) + glDepthFunc(GL_LEQUAL); + else + glDepthFunc(GL_LESS); u32 polyattr = rp->PolyData->Attr; u32 polyid = (polyattr >> 24) & 0x3F; @@ -1030,8 +1039,10 @@ void RenderSceneChunk(int y, int h) if (!(polyattr & (1<<15))) transfog = fogenable; else transfog = GL_FALSE; - // zorp - glDepthFunc(GL_LESS); + if (rp->PolyData->Attr & (1<<14)) + glDepthFunc(GL_LEQUAL); + else + glDepthFunc(GL_LESS); if (rp->PolyData->IsShadow) { diff --git a/src/frontend/qt_sdl/PlatformConfig.cpp b/src/frontend/qt_sdl/PlatformConfig.cpp index 76c5f4b..0628eaa 100644 --- a/src/frontend/qt_sdl/PlatformConfig.cpp +++ b/src/frontend/qt_sdl/PlatformConfig.cpp @@ -51,7 +51,7 @@ int _3DRenderer; int Threaded3D; int GL_ScaleFactor; -int GL_Antialias; +int GL_BetterPolygons; int LimitFPS; int AudioSync; @@ -143,7 +143,7 @@ ConfigEntry PlatformConfigFile[] = {"Threaded3D", 0, &Threaded3D, 1, NULL, 0}, {"GL_ScaleFactor", 0, &GL_ScaleFactor, 1, NULL, 0}, - {"GL_Antialias", 0, &GL_Antialias, 0, NULL, 0}, + {"GL_BetterPolygons", 0, &GL_BetterPolygons, 0, NULL, 0}, {"LimitFPS", 0, &LimitFPS, 0, NULL, 0}, {"AudioSync", 0, &AudioSync, 1, NULL, 0}, diff --git a/src/frontend/qt_sdl/PlatformConfig.h b/src/frontend/qt_sdl/PlatformConfig.h index bc9bba4..9deee7f 100644 --- a/src/frontend/qt_sdl/PlatformConfig.h +++ b/src/frontend/qt_sdl/PlatformConfig.h @@ -64,7 +64,7 @@ extern int _3DRenderer; extern int Threaded3D; extern int GL_ScaleFactor; -extern int GL_Antialias; +extern int GL_BetterPolygons; extern int LimitFPS; extern int AudioSync; diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index ba433c3..ac1ed7a 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -167,3 +167,10 @@ void VideoSettingsDialog::on_cbxGLResolution_currentIndexChanged(int idx) emit updateVideoSettings(false); } + +void VideoSettingsDialog::on_cbBetterPolygons_stateChanged(int state) +{ + Config::GL_BetterPolygons = (state != 0); + + emit updateVideoSettings(false); +} diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.h b/src/frontend/qt_sdl/VideoSettingsDialog.h index 2311d4d..f18793c 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.h +++ b/src/frontend/qt_sdl/VideoSettingsDialog.h @@ -64,6 +64,7 @@ private slots: void on_sbVSyncInterval_valueChanged(int val); void on_cbxGLResolution_currentIndexChanged(int idx); + void on_cbBetterPolygons_stateChanged(int state); void on_cbSoftwareThreaded_stateChanged(int state); diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.ui b/src/frontend/qt_sdl/VideoSettingsDialog.ui index 6cdd5d8..6985304 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.ui +++ b/src/frontend/qt_sdl/VideoSettingsDialog.ui @@ -7,7 +7,7 @@ 0 0 482 - 237 + 244 @@ -43,6 +43,16 @@ + + + + <html><head/><body><p>Enabling this may help reduce distortion on quads and more complex polygons, but may also reduce performance.</p></body></html> + + + Improved polygon splitting + + + diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 0228399..1e7e4a6 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -405,8 +405,11 @@ void EmuThread::run() videoRenderer = hasOGL ? Config::_3DRenderer : 0; videoSettingsDirty = false; + videoSettings.Soft_Threaded = Config::Threaded3D != 0; videoSettings.GL_ScaleFactor = Config::GL_ScaleFactor; + videoSettings.GL_BetterPolygons = Config::GL_BetterPolygons; + GPU::SetRenderSettings(videoRenderer, videoSettings); } -- cgit v1.2.3