From fa102a65c9f5c8a87faa8d21793420ea1205b8c1 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Fri, 24 Nov 2017 13:55:10 +0700 Subject: [PATCH] Do not revert Y for rects. --- .../GLSL/glsl_CombinerProgramBuilder.cpp | 2 -- .../GLSL/glsl_SpecialShadersFactory.cpp | 2 -- src/GraphicsDrawer.cpp | 32 +++++++++---------- src/TexrectDrawer.cpp | 18 +++++------ src/TextDrawer.cpp | 12 +++---- 5 files changed, 29 insertions(+), 37 deletions(-) diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp index 6e09581e..15c5bacb 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp @@ -395,7 +395,6 @@ public: "{ \n" " gl_Position = aRectPosition; \n" " vShadeColor = uRectColor; \n" - " gl_Position.y = -gl_Position.y; \n" " vTexCoord0 = aTexCoord0; \n" " vTexCoord1 = aTexCoord1; \n" ; @@ -424,7 +423,6 @@ public: "{ \n" " gl_Position = aRectPosition; \n" " vShadeColor = uRectColor; \n" - " gl_Position.y = -gl_Position.y; \n" ; if (!_glinfo.isGLESX) { m_part += diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp index edc7eff1..c794565f 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp @@ -25,7 +25,6 @@ namespace glsl { "void main() \n" "{ \n" " gl_Position = aRectPosition; \n" - " gl_Position.y = -gl_Position.y; \n" "} \n" ; } @@ -43,7 +42,6 @@ namespace glsl { "void main() \n" "{ \n" " gl_Position = aRectPosition; \n" - " gl_Position.y = -gl_Position.y;\n" " vTexCoord0 = aTexCoord0; \n" "} \n" ; diff --git a/src/GraphicsDrawer.cpp b/src/GraphicsDrawer.cpp index 7059af4a..6fc33ef2 100644 --- a/src/GraphicsDrawer.cpp +++ b/src/GraphicsDrawer.cpp @@ -921,7 +921,7 @@ void GraphicsDrawer::drawRect(int _ulx, int _uly, int _lrx, int _lry) const float Z = (gDP.otherMode.depthSource == G_ZS_PRIM) ? gDP.primDepth.z : 0.0f; const float W = 1.0f; m_rect[0].x = (float)_ulx * (2.0f * scaleX) - 1.0f; - m_rect[0].y = (float)_uly * (-2.0f * scaleY) + 1.0f; + m_rect[0].y = (float)_uly * (2.0f * scaleY) - 1.0f; m_rect[0].z = Z; m_rect[0].w = W; m_rect[1].x = (float)_lrx * (2.0f * scaleX) - 1.0f; @@ -929,7 +929,7 @@ void GraphicsDrawer::drawRect(int _ulx, int _uly, int _lrx, int _lry) m_rect[1].z = Z; m_rect[1].w = W; m_rect[2].x = m_rect[0].x; - m_rect[2].y = (float)_lry * (-2.0f * scaleY) + 1.0f; + m_rect[2].y = (float)_lry * (2.0f * scaleY) - 1.0f; m_rect[2].z = Z; m_rect[2].w = W; m_rect[3].x = m_rect[1].x; @@ -1140,31 +1140,29 @@ void GraphicsDrawer::drawTexturedRect(const TexturedRectParams & _params) calcCoordsScales(pCurrentBuffer, scaleX, scaleY); const float Z = (gDP.otherMode.depthSource == G_ZS_PRIM) ? gDP.primDepth.z : 0.0f; const float W = 1.0f; - f32 uly, lry; - if (bUseTexrectDrawer) { - uly = (float)_params.uly * (2.0f * scaleY) - 1.0f; - lry = (float)_params.lry * (2.0f * scaleY) - 1.0f; - } else { - uly = (float)_params.uly * (-2.0f * scaleY) + 1.0f; - lry = (float)_params.lry * (-2.0f * scaleY) + 1.0f; + const f32 ulx = _params.ulx * (2.0f * scaleX) - 1.0f; + const f32 uly = _params.uly * (2.0f * scaleY) - 1.0f; + const f32 lrx = _params.lrx * (2.0f * scaleX) - 1.0f; + const f32 lry = _params.lry * (2.0f * scaleY) - 1.0f; + if (!bUseTexrectDrawer) { // Flush text drawer if (m_texrectDrawer.draw()) _updateStates(DrawingState::TexRect); } - m_rect[0].x = (float)_params.ulx * (2.0f * scaleX) - 1.0f; + m_rect[0].x = ulx; m_rect[0].y = uly; m_rect[0].z = Z; m_rect[0].w = W; - m_rect[1].x = (float)(_params.lrx) * (2.0f * scaleX) - 1.0f; - m_rect[1].y = m_rect[0].y; + m_rect[1].x = lrx; + m_rect[1].y = uly; m_rect[1].z = Z; m_rect[1].w = W; - m_rect[2].x = m_rect[0].x; + m_rect[2].x = ulx; m_rect[2].y = lry; m_rect[2].z = Z; m_rect[2].w = W; - m_rect[3].x = m_rect[1].x; - m_rect[3].y = m_rect[2].y; + m_rect[3].x = lrx; + m_rect[3].y = lry; m_rect[3].z = Z; m_rect[3].w = W; @@ -1487,9 +1485,9 @@ void GraphicsDrawer::copyTexturedRect(const CopyRectParams & _params) const float Z = 0.0f; const float W = 1.0f; float X0 = _params.dstX0 * (2.0f * scaleX) - 1.0f; - float Y0 = _params.dstY0 * (-2.0f * scaleY) + 1.0f; + float Y0 = _params.dstY0 * (2.0f * scaleY) - 1.0f; float X1 = _params.dstX1 * (2.0f * scaleX) - 1.0f; - float Y1 = _params.dstY1 * (-2.0f * scaleY) + 1.0f; + float Y1 = _params.dstY1 * (2.0f * scaleY) - 1.0f; if (_params.invertX) { X0 = -X0; X1 = -X1; diff --git a/src/TexrectDrawer.cpp b/src/TexrectDrawer.cpp index 66c5e43c..ce1102b2 100644 --- a/src/TexrectDrawer.cpp +++ b/src/TexrectDrawer.cpp @@ -183,8 +183,6 @@ void TexrectDrawer::add() m_vecRectCoords.push_back(coords); ++m_numRects; - for (u32 i = 0; i < 4; ++i) - pRect[i].y = -pRect[i].y; Context::DrawRectParameters rectParams; rectParams.mode = drawmode::TRIANGLE_STRIP; rectParams.verticesCount = 4; @@ -259,25 +257,25 @@ bool TexrectDrawer::draw() m_programTex->setTextureBounds(texBounds); rect[0].x = m_ulx; - rect[0].y = -m_lry; + rect[0].y = m_lry; rect[0].z = m_Z; rect[0].w = W; rect[0].s0 = s0; rect[0].t0 = t0; rect[1].x = m_lrx; - rect[1].y = -m_lry; + rect[1].y = m_lry; rect[1].z = m_Z; rect[1].w = W; rect[1].s0 = s1; rect[1].t0 = t0; rect[2].x = m_ulx; - rect[2].y = -m_uly; + rect[2].y = m_uly; rect[2].z = m_Z; rect[2].w = W; rect[2].s0 = s0; rect[2].t0 = t1; rect[3].x = m_lrx; - rect[3].y = -m_uly; + rect[3].y = m_uly; rect[3].z = m_Z; rect[3].w = W; rect[3].s0 = s1; @@ -296,10 +294,10 @@ bool TexrectDrawer::draw() gfxContext.bindFramebuffer(bufferTarget::DRAW_FRAMEBUFFER, m_FBO); m_programClear->activate(); - rect[0].y = -m_uly; - rect[1].y = -m_uly; - rect[2].y = -m_lry; - rect[3].y = -m_lry; + rect[0].y = m_uly; + rect[1].y = m_uly; + rect[2].y = m_lry; + rect[3].y = m_lry; _setViewport(); diff --git a/src/TextDrawer.cpp b/src/TextDrawer.cpp index 7a0deafe..3d43bca6 100644 --- a/src/TextDrawer.cpp +++ b/src/TextDrawer.cpp @@ -288,37 +288,37 @@ void TextDrawer::drawText(const char *_pText, float _x, float _y) const continue; rect.x = x2; - rect.y = y2; + rect.y = -y2; rect.s0 = m_atlas->c[*p].tx; rect.t0 = m_atlas->c[*p].ty; coords.push_back(rect); rect.x = x2 + w; - rect.y = y2; + rect.y = -y2; rect.s0 = m_atlas->c[*p].tx + m_atlas->c[*p].bw / m_atlas->w; rect.t0 = m_atlas->c[*p].ty; coords.push_back(rect); rect.x = x2; - rect.y = y2 + h; + rect.y = -y2 - h; rect.s0 = m_atlas->c[*p].tx; rect.t0 = m_atlas->c[*p].ty + m_atlas->c[*p].bh / m_atlas->h; coords.push_back(rect); rect.x = x2 + w; - rect.y = y2; + rect.y = -y2; rect.s0 = m_atlas->c[*p].tx + m_atlas->c[*p].bw / m_atlas->w; rect.t0 = m_atlas->c[*p].ty; coords.push_back(rect); rect.x = x2; - rect.y = y2 + h; + rect.y = -y2 - h; rect.s0 = m_atlas->c[*p].tx; rect.t0 = m_atlas->c[*p].ty + m_atlas->c[*p].bh / m_atlas->h; coords.push_back(rect); rect.x = x2 + w; - rect.y = y2 + h; + rect.y = -y2 - h; rect.s0 = m_atlas->c[*p].tx + m_atlas->c[*p].bw / m_atlas->w; rect.t0 = m_atlas->c[*p].ty + m_atlas->c[*p].bh / m_atlas->h; coords.push_back(rect);