diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp index f266b502..659eb703 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp @@ -1,3 +1,4 @@ +#include // for setprecision #include #include #include @@ -7,6 +8,7 @@ #include "glsl_CombinerProgramImpl.h" #include "glsl_CombinerProgramBuilder.h" #include "glsl_CombinerProgramUniformFactory.h" +#include "GraphicsDrawer.h" using namespace glsl; @@ -268,6 +270,9 @@ public: m_part = ss.str(); } m_part += "uniform lowp vec2 uVertexOffset; \n"; + std::stringstream ss; + ss << "const lowp float screenSizeDims = " << std::setprecision(1) << std::fixed << SCREEN_SIZE_DIM << ";" << std::endl; + m_part += ss.str(); } }; @@ -513,8 +518,9 @@ public: m_part = " gl_Position.z /= 8.0; \n"; } m_part += - " gl_Position.xy += uVertexOffset * vec2(gl_Position.w); \n" - " gl_Position.zw *= vec2(1024.0); \n" + " gl_Position.xy += uVertexOffset * vec2(gl_Position.w); \n" + " gl_Position.xy -= vec2(0.5*screenSizeDims) * gl_Position.ww; \n" + " gl_Position.xy /= vec2(0.5*screenSizeDims); \n" "} \n" ; } diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_ShaderStorage.h b/src/Graphics/OpenGLContext/GLSL/glsl_ShaderStorage.h index a6d573b5..50a9ded7 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_ShaderStorage.h +++ b/src/Graphics/OpenGLContext/GLSL/glsl_ShaderStorage.h @@ -20,7 +20,7 @@ namespace glsl { bool _saveCombinerKeys(const graphics::Combiners & _combiners) const; bool _loadFromCombinerKeys(graphics::Combiners & _combiners); - const u32 m_formatVersion = 0x34U; + const u32 m_formatVersion = 0x35U; const u32 m_keysFormatVersion = 0x05; const opengl::GLInfo & m_glinfo; opengl::CachedUseProgram * m_useProgram; diff --git a/src/GraphicsDrawer.cpp b/src/GraphicsDrawer.cpp index baccfcbb..9f5a1694 100644 --- a/src/GraphicsDrawer.cpp +++ b/src/GraphicsDrawer.cpp @@ -253,10 +253,10 @@ void GraphicsDrawer::_updateViewport(const FrameBuffer* _pBuffer, const f32 scal } else { scaleX = scaleY = scale; } - X = roundup(-1024.0f, scaleX); - Y = roundup(-1024.0f, scaleY); - WIDTH = roundup(2048.0f, scaleX); - HEIGHT = roundup(2048.0f, scaleY); + X = 0; + Y = 0; + WIDTH = roundup(SCREEN_SIZE_DIM, scaleX); + HEIGHT = roundup(SCREEN_SIZE_DIM, scaleY); gfxContext.setViewport(X, Y, WIDTH, HEIGHT); gSP.changed |= CHANGED_VIEWPORT; } diff --git a/src/GraphicsDrawer.h b/src/GraphicsDrawer.h index 87f432ac..d1c479e8 100644 --- a/src/GraphicsDrawer.h +++ b/src/GraphicsDrawer.h @@ -20,6 +20,8 @@ struct FrameBuffer; #define VERTBUFF_SIZE 256U #define ELEMBUFF_SIZE 1024U +constexpr f32 SCREEN_SIZE_DIM = 640.0f; + enum class DrawingState { Non, diff --git a/src/TexrectDrawer.cpp b/src/TexrectDrawer.cpp index 6421c97d..4a64915e 100644 --- a/src/TexrectDrawer.cpp +++ b/src/TexrectDrawer.cpp @@ -380,8 +380,13 @@ bool TexrectDrawer::draw() const float t0 = m_lry / (float)m_pTexture->height;// +0.5f / (float)m_pTexture->height; const float s1 = m_lrx / (float)m_pTexture->width; const float t1 = m_uly / (float)m_pTexture->height; - const float W = 1024.0f; - const float Z = m_Z * 1024.0f; + const float W = 1.0f; + const float Z = m_Z; + constexpr float halfScreenSizeDims = SCREEN_SIZE_DIM * 0.5f; + m_ulx = (m_ulx - halfScreenSizeDims) / halfScreenSizeDims; + m_uly = (m_uly - halfScreenSizeDims) / halfScreenSizeDims; + m_lrx = (m_lrx - halfScreenSizeDims) / halfScreenSizeDims; + m_lry = (m_lry - halfScreenSizeDims) / halfScreenSizeDims; drawer._updateViewport(m_pBuffer);