diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp index 689821d8..0b6baf6b 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp @@ -278,6 +278,7 @@ public: "IN highp vec2 aTexCoord; \n" "IN lowp float aNumLights; \n" "IN highp vec4 aModify; \n" + "IN highp vec3 aBaryCoords; \n" " \n" "uniform int uTexturePersp; \n" "uniform lowp int uTextureFilterMode; \n" @@ -297,6 +298,7 @@ public: "OUT mediump vec2 vLodTexCoord; \n" "OUT lowp float vNumLights; \n" "OUT lowp vec4 vShadeColor; \n" + "OUT highp vec4 vBaryCoords; \n" ; if (!_glinfo.isGLESX || _glinfo.noPerspective) m_part += "noperspective OUT lowp vec4 vShadeColorNoperspective;\n"; @@ -348,6 +350,7 @@ public: " else \n" " vShadeColor.rgb = vec3(fp); \n" " } \n" + " vBaryCoords = vec4(aBaryCoords, 0.5f); \n" ; } }; @@ -362,6 +365,7 @@ public: "IN lowp vec4 aColor; \n" "IN lowp float aNumLights; \n" "IN highp vec4 aModify; \n" + "IN highp vec3 aBaryCoords; \n" " \n" "uniform lowp int uFogUsage; \n" "uniform mediump vec2 uFogScale; \n" @@ -369,6 +373,7 @@ public: " \n" "OUT lowp float vNumLights; \n" "OUT lowp vec4 vShadeColor; \n" + "OUT highp vec4 vBaryCoords; \n" ; if (!_glinfo.isGLESX || _glinfo.noPerspective) m_part += "noperspective OUT lowp vec4 vShadeColorNoperspective;\n"; @@ -405,6 +410,7 @@ public: " else \n" " vShadeColor.rgb = vec3(fp); \n" " } \n" + " vBaryCoords = vec4(aBaryCoords, 0.5f); \n" ; } }; @@ -418,11 +424,13 @@ public: "IN highp vec4 aRectPosition; \n" "IN highp vec2 aTexCoord0; \n" "IN highp vec2 aTexCoord1; \n" + "IN highp vec2 aBaryCoords; \n" " \n" "OUT highp vec2 vTexCoord0; \n" "OUT highp vec2 vTexCoord1; \n" "OUT lowp vec4 vShadeColor; \n" - ; + "OUT highp vec4 vBaryCoords;" + ; if (!_glinfo.isGLESX || _glinfo.noPerspective) m_part += "noperspective OUT lowp vec4 vShadeColorNoperspective;\n"; else @@ -436,6 +444,7 @@ public: " vShadeColorNoperspective = uRectColor; \n" " vTexCoord0 = aTexCoord0; \n" " vTexCoord1 = aTexCoord1; \n" + " vBaryCoords = vec4(aBaryCoords, vec2(1.0) - aBaryCoords); \n" ; } }; @@ -447,8 +456,10 @@ public: { m_part = "IN highp vec4 aRectPosition; \n" + "IN highp vec2 aBaryCoords; \n" " \n" "OUT lowp vec4 vShadeColor; \n" + "OUT highp vec4 vBaryCoords; \n" ; if (!_glinfo.isGLESX || _glinfo.noPerspective) m_part += "noperspective OUT lowp vec4 vShadeColorNoperspective;\n"; @@ -461,6 +472,7 @@ public: " gl_Position = aRectPosition; \n" " vShadeColor = uRectColor; \n" " vShadeColorNoperspective = uRectColor; \n" + " vBaryCoords = vec4(aBaryCoords, vec2(1.0f) - aBaryCoords);\n" ; } }; @@ -980,6 +992,7 @@ public: "IN highp vec2 vTexCoord1; \n" "IN mediump vec2 vLodTexCoord; \n" "IN lowp float vNumLights; \n" + "IN highp vec4 vBaryCoords; \n" ; if (_glinfo.dual_source_blending) { @@ -1086,6 +1099,7 @@ public: m_part += "IN lowp vec4 vShadeColor; \n" "IN lowp float vNumLights; \n" + "IN highp vec4 vBaryCoords; \n" ; if (_glinfo.dual_source_blending) { diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_Utils.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_Utils.cpp index 0909ee4a..2dc3e0a1 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_Utils.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_Utils.cpp @@ -9,6 +9,7 @@ void Utils::locateAttributes(GLuint _program, bool _rect, bool _textures) { if (_rect) { glBindAttribLocation(_program, opengl::rectAttrib::position, "aRectPosition"); + glBindAttribLocation(_program, opengl::rectAttrib::barycoords, "aBaryCoords"); if (_textures) { glBindAttribLocation(_program, opengl::rectAttrib::texcoord0, "aTexCoord0"); glBindAttribLocation(_program, opengl::rectAttrib::texcoord1, "aTexCoord1"); @@ -20,6 +21,7 @@ void Utils::locateAttributes(GLuint _program, bool _rect, bool _textures) glBindAttribLocation(_program, opengl::triangleAttrib::color, "aColor"); glBindAttribLocation(_program, opengl::triangleAttrib::numlights, "aNumLights"); glBindAttribLocation(_program, opengl::triangleAttrib::modify, "aModify"); + glBindAttribLocation(_program, opengl::triangleAttrib::barycoords, "aBaryCoords"); if (_textures) glBindAttribLocation(_program, opengl::triangleAttrib::texcoord, "aTexCoord"); } diff --git a/src/Graphics/OpenGLContext/opengl_Attributes.cpp b/src/Graphics/OpenGLContext/opengl_Attributes.cpp index 6f05bb53..d209efd5 100644 --- a/src/Graphics/OpenGLContext/opengl_Attributes.cpp +++ b/src/Graphics/OpenGLContext/opengl_Attributes.cpp @@ -8,6 +8,7 @@ namespace opengl { const GLuint texcoord = 2U; const GLuint numlights = 3U; const GLuint modify = 4U; + const GLuint barycoords = 8U; } // Rect attributes @@ -15,5 +16,6 @@ namespace opengl { const GLuint position = 5U; const GLuint texcoord0 = 6U; const GLuint texcoord1 = 7U; + const GLuint barycoords = 9U; } } diff --git a/src/Graphics/OpenGLContext/opengl_Attributes.h b/src/Graphics/OpenGLContext/opengl_Attributes.h index 89f7167a..3629500d 100644 --- a/src/Graphics/OpenGLContext/opengl_Attributes.h +++ b/src/Graphics/OpenGLContext/opengl_Attributes.h @@ -10,6 +10,7 @@ namespace opengl { extern const GLuint texcoord; extern const GLuint numlights; extern const GLuint modify; + extern const GLuint barycoords; } // Rect attributes @@ -17,7 +18,8 @@ namespace opengl { extern const GLuint position; extern const GLuint texcoord0; extern const GLuint texcoord1; + extern const GLuint barycoords; } -#define MaxAttribIndex 8 +#define MaxAttribIndex 10 } diff --git a/src/Graphics/OpenGLContext/opengl_BufferedDrawer.cpp b/src/Graphics/OpenGLContext/opengl_BufferedDrawer.cpp index e55b1717..08d1a416 100644 --- a/src/Graphics/OpenGLContext/opengl_BufferedDrawer.cpp +++ b/src/Graphics/OpenGLContext/opengl_BufferedDrawer.cpp @@ -29,9 +29,11 @@ BufferedDrawer::BufferedDrawer(const GLInfo & _glinfo, CachedVertexAttribArray * m_cachedAttribArray->enableVertexAttribArray(rectAttrib::position, true); m_cachedAttribArray->enableVertexAttribArray(rectAttrib::texcoord0, true); m_cachedAttribArray->enableVertexAttribArray(rectAttrib::texcoord1, true); + m_cachedAttribArray->enableVertexAttribArray(rectAttrib::barycoords, true); glVertexAttribPointer(rectAttrib::position, 4, GL_FLOAT, GL_FALSE, sizeof(RectVertex), (const GLvoid *)(offsetof(RectVertex, x))); glVertexAttribPointer(rectAttrib::texcoord0, 2, GL_FLOAT, GL_FALSE, sizeof(RectVertex), (const GLvoid *)(offsetof(RectVertex, s0))); glVertexAttribPointer(rectAttrib::texcoord1, 2, GL_FLOAT, GL_FALSE, sizeof(RectVertex), (const GLvoid *)(offsetof(RectVertex, s1))); + glVertexAttribPointer(rectAttrib::barycoords, 2, GL_FLOAT, GL_FALSE, sizeof(RectVertex), (const GLvoid *)(offsetof(RectVertex, bc0))); /* Init buffers for triangles */ glGenVertexArrays(1, &m_trisBuffers.vao); @@ -43,10 +45,12 @@ BufferedDrawer::BufferedDrawer(const GLInfo & _glinfo, CachedVertexAttribArray * m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::texcoord, true); m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::modify, true); m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::numlights, false); + m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::barycoords, true); glVertexAttribPointer(triangleAttrib::position, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)(offsetof(Vertex, x))); glVertexAttribPointer(triangleAttrib::color, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)(offsetof(Vertex, r))); glVertexAttribPointer(triangleAttrib::texcoord, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)(offsetof(Vertex, s))); glVertexAttribPointer(triangleAttrib::modify, 4, GL_BYTE, GL_TRUE, sizeof(Vertex), (const GLvoid *)(offsetof(Vertex, modify))); + glVertexAttribPointer(triangleAttrib::barycoords, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)(offsetof(Vertex, bc0))); } void BufferedDrawer::_initBuffer(Buffer & _buffer, GLuint _bufSize) @@ -162,6 +166,9 @@ void BufferedDrawer::_convertFromSPVertex(bool _flatColors, u32 _count, const SP dst.s = src.s; dst.t = src.t; dst.modify = src.modify; + dst.bc0 = src.bc0; + dst.bc1 = src.bc1; + dst.bc2 = src.bc2; } } diff --git a/src/Graphics/OpenGLContext/opengl_BufferedDrawer.h b/src/Graphics/OpenGLContext/opengl_BufferedDrawer.h index 40576b5c..7af163b5 100644 --- a/src/Graphics/OpenGLContext/opengl_BufferedDrawer.h +++ b/src/Graphics/OpenGLContext/opengl_BufferedDrawer.h @@ -58,6 +58,7 @@ namespace opengl { f32 r, g, b, a; f32 s, t; u32 modify; + f32 bc0, bc1, bc2; }; void _initBuffer(Buffer & _buffer, GLuint _bufSize); diff --git a/src/GraphicsDrawer.cpp b/src/GraphicsDrawer.cpp index 1b2ba02c..2547f3f8 100644 --- a/src/GraphicsDrawer.cpp +++ b/src/GraphicsDrawer.cpp @@ -58,6 +58,13 @@ void GraphicsDrawer::addTriangle(u32 _v0, u32 _v1, u32 _v2) triangles.vertices[_v1].modify | triangles.vertices[_v2].modify; + for (u32 i = firstIndex; i < triangles.num; ++i) { + SPVertex& vtx = triangles.vertices[triangles.elements[i]]; + vtx.bc0 = i - firstIndex == 0 ? 1.0f : 0.0f; + vtx.bc1 = i - firstIndex == 1 ? 1.0f : 0.0f; + vtx.bc2 = i - firstIndex == 2 ? 1.0f : 0.0f; + } + if ((gSP.geometryMode & G_LIGHTING) == 0) { if ((gSP.geometryMode & G_SHADE) == 0) { // Prim shading @@ -853,6 +860,10 @@ void GraphicsDrawer::drawScreenSpaceTriangle(u32 _numVtx, graphics::DrawModePara if (vtx.x < 0) vtx.clip |= CLIP_NEGX; if (vtx.y > gSP.viewport.height) vtx.clip |= CLIP_POSY; if (vtx.y < 0) vtx.clip |= CLIP_NEGY; + + vtx.bc0 = (i % 3 == 0) ? 1.0f : 0.0f; + vtx.bc1 = (i % 3 == 1) ? 1.0f : 0.0f; + vtx.bc2 = (i % 3 == 2) ? 1.0f : 0.0f; } m_modifyVertices = MODIFY_ALL; @@ -1061,6 +1072,15 @@ void GraphicsDrawer::drawRect(int _ulx, int _uly, int _lrx, int _lry) m_rect[3].z = Z; m_rect[3].w = W; + m_rect[0].bc0 = 0.0f; + m_rect[0].bc1 = 0.0f; + m_rect[1].bc0 = 0.0f; + m_rect[1].bc1 = 1.0f; + m_rect[2].bc0 = 1.0f; + m_rect[2].bc1 = 0.0f; + m_rect[3].bc0 = 1.0f; + m_rect[3].bc1 = 1.0f; + DisplayWindow & wnd = dwnd(); if (wnd.isAdjustScreen() && (gDP.colorImage.width > VI.width * 98 / 100) && (static_cast(_lrx - _ulx) < VI.width * 9 / 10)) { const float scale = wnd.getAdjustScale(); @@ -1448,6 +1468,16 @@ void GraphicsDrawer::drawTexturedRect(const TexturedRectParams & _params) m_rect[i].x *= scale; } + m_rect[0].bc0 = 0.0f; + m_rect[0].bc1 = 0.0f; + m_rect[1].bc0 = 0.0f; + m_rect[1].bc1 = 1.0f; + m_rect[2].bc0 = 1.0f; + m_rect[2].bc1 = 0.0f; + m_rect[3].bc0 = 1.0f; + m_rect[3].bc1 = 1.0f; + + if (bUseTexrectDrawer) { if (m_bBGMode) { m_texrectDrawer.addBackgroundRect(); diff --git a/src/GraphicsDrawer.h b/src/GraphicsDrawer.h index 6aa52dd3..bab599a9 100644 --- a/src/GraphicsDrawer.h +++ b/src/GraphicsDrawer.h @@ -34,6 +34,7 @@ struct RectVertex { float x, y, z, w; float s0, t0, s1, t1; + float bc0, bc1; }; typedef std::chrono::milliseconds Milliseconds; diff --git a/src/gSP.h b/src/gSP.h index ccdf0982..a187ec8e 100644 --- a/src/gSP.h +++ b/src/gSP.h @@ -43,6 +43,7 @@ struct SPVertex u32 modify; u8 HWLight; u8 clip; + f32 bc0, bc1, bc2; s16 flag; };