From d9a8aac96c46715403be36550206fe24e385d187 Mon Sep 17 00:00:00 2001 From: decimad Date: Thu, 20 Oct 2016 14:26:36 +0200 Subject: [PATCH] transfer font texture width to the fragment shader via uniform variable --- common/gal/opengl/opengl_gal.cpp | 6 ++++-- common/gal/opengl/shader.frag | 9 ++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 5be3c47fc7..5533babba8 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -292,9 +292,11 @@ void OPENGL_GAL::BeginDrawing() } // Set shader parameter - GLint ufm_fontTexture = shader->AddParameter( "fontTexture" ); + GLint ufm_fontTexture = shader->AddParameter( "fontTexture" ); + GLint ufm_fontTextureWidth = shader->AddParameter( "fontTextureWidth" ); shader->Use(); - shader->SetParameter( ufm_fontTexture, (int) FONT_TEXTURE_UNIT ); + shader->SetParameter( ufm_fontTexture, (int) FONT_TEXTURE_UNIT ); + shader->SetParameter( ufm_fontTextureWidth, (int) font_image.width ); shader->Deactivate(); checkGlError( "setting bitmap font sampler as shader parameter" ); diff --git a/common/gal/opengl/shader.frag b/common/gal/opengl/shader.frag index b8dcfa6de1..8e6b12b05d 100644 --- a/common/gal/opengl/shader.frag +++ b/common/gal/opengl/shader.frag @@ -27,10 +27,6 @@ #version 120 -// Needed to reconstruct the mipmap level / texel derivative -const int FONT_TEXTURE_WIDTH = 1024; -const int FONT_TEXTURE_HEIGHT = 1024; - // Multi-channel signed distance field #define USE_MSDF @@ -44,6 +40,9 @@ varying vec4 shaderParams; varying vec2 circleCoords; uniform sampler2D fontTexture; +// Needed to reconstruct the mipmap level / texel derivative +uniform int fontTextureWidth; + void filledCircle( vec2 aCoord ) { if( dot( aCoord, aCoord ) < 1.0 ) @@ -89,7 +88,7 @@ void main() // Unless we're streching chars it is okay to consider // one derivative for filtering - float derivative = length( dFdx( tex ) ) * FONT_TEXTURE_WIDTH / 8; + float derivative = length( dFdx( tex ) ) * fontTextureWidth / 4; #ifdef USE_MSDF float dist = median( texture2D( fontTexture, tex ).rgb );