diff options
author | Arisotura <thetotalworm@gmail.com> | 2019-05-25 13:43:06 +0200 |
---|---|---|
committer | Arisotura <thetotalworm@gmail.com> | 2019-05-25 13:43:06 +0200 |
commit | 478ca019da6cbd6fb93908cbc79f821953402bc2 (patch) | |
tree | e757c77b510a624e73a5d183a15d8443f2ed67af /src | |
parent | 7cdeb7fa4e365dd3ef4e505985c9fc9a4c4045ab (diff) |
implement fog correctly
also some base work for edgemarking
Diffstat (limited to 'src')
-rw-r--r-- | src/GPU3D_OpenGL.cpp | 63 | ||||
-rw-r--r-- | src/GPU3D_OpenGL_shaders.h | 7 | ||||
-rw-r--r-- | src/OpenGLSupport.h | 1 |
3 files changed, 58 insertions, 13 deletions
diff --git a/src/GPU3D_OpenGL.cpp b/src/GPU3D_OpenGL.cpp index f8ed773..759c404 100644 --- a/src/GPU3D_OpenGL.cpp +++ b/src/GPU3D_OpenGL.cpp @@ -71,6 +71,9 @@ typedef struct u32 NumIndices; u16* Indices; + u32 NumEdgeIndices; + u16* EdgeIndices; + u32 RenderKey; } RendererPolygon; @@ -98,7 +101,7 @@ u32 VertexBuffer[10240 * 7]; u32 NumVertices; GLuint VertexArrayID; -u16 IndexBuffer[2048 * 10]; +u16 IndexBuffer[2048 * 40]; u32 NumTriangles; GLuint TexMemID; @@ -443,6 +446,8 @@ void UpdateDisplaySettings() glBindBuffer(GL_PIXEL_PACK_BUFFER, PixelbufferID); glBufferData(GL_PIXEL_PACK_BUFFER, 256*192*4, NULL, GL_DYNAMIC_READ); + + //glLineWidth(scale); } @@ -495,6 +500,7 @@ void BuildPolygons(RendererPolygon* polygons, int npolys) u32 vidx = 0; u16* iptr = &IndexBuffer[0]; + u16* eiptr = &IndexBuffer[2048*30]; u32 numtriangles = 0; for (int i = 0; i < npolys; i++) @@ -503,6 +509,7 @@ void BuildPolygons(RendererPolygon* polygons, int npolys) Polygon* poly = rp->PolyData; rp->Indices = iptr; + rp->NumIndices = 0; u32 vidx_first = vidx; @@ -514,8 +521,6 @@ void BuildPolygons(RendererPolygon* polygons, int npolys) if (poly->FacingView) vtxattr |= (1<<8); if (poly->WBuffer) vtxattr |= (1<<9); - rp->NumIndices = 0; - // assemble vertices for (int j = 0; j < poly->NumVertices; j++) { @@ -566,6 +571,17 @@ void BuildPolygons(RendererPolygon* polygons, int npolys) vidx++; } + + rp->EdgeIndices = eiptr; + rp->NumEdgeIndices = 0; + + for (int j = 1; j < poly->NumVertices; j++) + { + *eiptr++ = vidx_first; + *eiptr++ = vidx_first + 1; + vidx_first++; + rp->NumEdgeIndices += 2; + } } NumTriangles = numtriangles; @@ -599,6 +615,24 @@ int RenderPolygonBatch(int i) return numpolys; } +int RenderPolygonEdges() +{ + RendererPolygon* rp = &PolygonList[0]; + int numpolys = 0; + u32 numindices = 0; + + for (int iend = 0; iend < NumOpaqueFinalPolys; iend++) + { + RendererPolygon* cur_rp = &PolygonList[iend]; + + numpolys++; + numindices += cur_rp->NumEdgeIndices; + } + + glDrawElements(GL_LINES, numindices, GL_UNSIGNED_SHORT, rp->EdgeIndices); + return numpolys; +} + void RenderSceneChunk(int y, int h) { u32 flags = 0; @@ -639,6 +673,11 @@ void RenderSceneChunk(int y, int h) } glEnable(GL_BLEND); + if (RenderDispCnt & (1<<3)) + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); + else + glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ONE); + UseRenderShader(flags | RenderFlag_Trans); if (NumOpaqueFinalPolys > -1) @@ -821,6 +860,19 @@ void RenderSceneChunk(int y, int h) { glUseProgram(FinalPassShader[2]); + glEnable(GL_BLEND); + glBlendFuncSeparate(GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_ALPHA); + + { + u32 c = RenderFogColor; + u32 r = c & 0x1F; + u32 g = (c >> 5) & 0x1F; + u32 b = (c >> 10) & 0x1F; + u32 a = (c >> 16) & 0x1F; + + glBlendColor((float)b/31.0, (float)g/31.0, (float)r/31.0, (float)a/31.0); + } + glDepthFunc(GL_ALWAYS); glDepthMask(GL_FALSE); glStencilFunc(GL_ALWAYS, 0, 0); @@ -939,11 +991,6 @@ void RenderFrame() if (Antialias) glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[2]); else glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[FrontBuffer]); - if (RenderDispCnt & (1<<3)) - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); - else - glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ONE); - glDisable(GL_BLEND); glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glColorMaski(1, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); diff --git a/src/GPU3D_OpenGL_shaders.h b/src/GPU3D_OpenGL_shaders.h index 0e4c4fe..a1aa95a 100644 --- a/src/GPU3D_OpenGL_shaders.h +++ b/src/GPU3D_OpenGL_shaders.h @@ -111,12 +111,9 @@ vec4 CalculateFog(float depth) densityfrac = int(udepth & uint(0x1FFFF)); } - float density = - ((uFogDensity[densityid] * float(0x20000-densityfrac)) + - (uFogDensity[densityid+1] * float(densityfrac))) / float(0x20000); + float density = mix(uFogDensity[densityid], uFogDensity[densityid+1], float(densityfrac)/131072.0); - return vec4(uFogColor.bgr,density); - return uFogColor * density; + return vec4(density, density, density, density); } void main() diff --git a/src/OpenGLSupport.h b/src/OpenGLSupport.h index c922f7c..1ae0a35 100644 --- a/src/OpenGLSupport.h +++ b/src/OpenGLSupport.h @@ -102,6 +102,7 @@ \ func(GLBLENDFUNCSEPARATE, glBlendFuncSeparate); \ func(GLBLENDEQUATIONSEPARATE, glBlendEquationSeparate); \ + func(GLBLENDCOLOR, glBlendColor); \ \ func(GLCOLORMASKI, glColorMaski); \ \ |