transfer font texture width to the fragment shader via uniform variable

This commit is contained in:
decimad 2016-10-20 14:26:36 +02:00
parent ce83410c52
commit d9a8aac96c
2 changed files with 8 additions and 7 deletions

View File

@ -293,8 +293,10 @@ void OPENGL_GAL::BeginDrawing()
// Set shader parameter // Set shader parameter
GLint ufm_fontTexture = shader->AddParameter( "fontTexture" ); GLint ufm_fontTexture = shader->AddParameter( "fontTexture" );
GLint ufm_fontTextureWidth = shader->AddParameter( "fontTextureWidth" );
shader->Use(); 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(); shader->Deactivate();
checkGlError( "setting bitmap font sampler as shader parameter" ); checkGlError( "setting bitmap font sampler as shader parameter" );

View File

@ -27,10 +27,6 @@
#version 120 #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 // Multi-channel signed distance field
#define USE_MSDF #define USE_MSDF
@ -44,6 +40,9 @@ varying vec4 shaderParams;
varying vec2 circleCoords; varying vec2 circleCoords;
uniform sampler2D fontTexture; uniform sampler2D fontTexture;
// Needed to reconstruct the mipmap level / texel derivative
uniform int fontTextureWidth;
void filledCircle( vec2 aCoord ) void filledCircle( vec2 aCoord )
{ {
if( dot( aCoord, aCoord ) < 1.0 ) if( dot( aCoord, aCoord ) < 1.0 )
@ -89,7 +88,7 @@ void main()
// Unless we're streching chars it is okay to consider // Unless we're streching chars it is okay to consider
// one derivative for filtering // one derivative for filtering
float derivative = length( dFdx( tex ) ) * FONT_TEXTURE_WIDTH / 8; float derivative = length( dFdx( tex ) ) * fontTextureWidth / 4;
#ifdef USE_MSDF #ifdef USE_MSDF
float dist = median( texture2D( fontTexture, tex ).rgb ); float dist = median( texture2D( fontTexture, tex ).rgb );