From 2303d6afc4a48adf3b7b8a309249b1f834808d42 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 13 Oct 2017 17:03:31 +0100 Subject: [PATCH] Cleaned up support for GL3 build --- include/osgText/Glyph | 9 ----- src/osgPlugins/freetype/FreeTypeFont.cpp | 6 ++-- src/osgText/DefaultFont.cpp | 6 ++-- src/osgText/Glyph.cpp | 44 ++++++++++++++++++------ src/osgText/shaders/text_sdf_frag.cpp | 18 +++++++--- 5 files changed, 51 insertions(+), 32 deletions(-) diff --git a/include/osgText/Glyph b/include/osgText/Glyph index 5dcfd12b3..adba880bc 100644 --- a/include/osgText/Glyph +++ b/include/osgText/Glyph @@ -30,15 +30,6 @@ #include -// GL_ALPHA is deprecated in GL3/GL4 core profile, use GL_RED and a shader in this case. See osgText example. -#if defined(OSG_GL3_AVAILABLE) && !defined(OSG_GL2_AVAILABLE) && !defined(OSG_GL1_AVAILABLE) -#define OSGTEXT_GLYPH_FORMAT GL_RED -#define OSGTEXT_GLYPH_INTERNALFORMAT GL_R8 -#else -#define OSGTEXT_GLYPH_FORMAT GL_ALPHA -#define OSGTEXT_GLYPH_INTERNALFORMAT GL_ALPHA -#endif - namespace osgText { class Font; diff --git a/src/osgPlugins/freetype/FreeTypeFont.cpp b/src/osgPlugins/freetype/FreeTypeFont.cpp index 323a874b6..d39f984c2 100644 --- a/src/osgPlugins/freetype/FreeTypeFont.cpp +++ b/src/osgPlugins/freetype/FreeTypeFont.cpp @@ -348,14 +348,12 @@ osgText::Glyph* FreeTypeFont::getGlyph(const osgText::FontResolution& fontRes, u for(unsigned char* p=data;psetImage(width,height,1, - OSGTEXT_GLYPH_INTERNALFORMAT, - OSGTEXT_GLYPH_FORMAT, GL_UNSIGNED_BYTE, + GL_ALPHA, + GL_ALPHA, GL_UNSIGNED_BYTE, data, osg::Image::USE_NEW_DELETE, 1); - glyph->setInternalTextureFormat(OSGTEXT_GLYPH_INTERNALFORMAT); - // copy image across to osgText::Glyph image. switch(glyphslot->bitmap.pixel_mode) { diff --git a/src/osgText/DefaultFont.cpp b/src/osgText/DefaultFont.cpp index cf3669cef..94aac9be3 100644 --- a/src/osgText/DefaultFont.cpp +++ b/src/osgText/DefaultFont.cpp @@ -207,14 +207,12 @@ void DefaultFont::constructGlyphs() for(unsigned char* p=data;psetImage(sourceWidth,sourceHeight,1, - OSGTEXT_GLYPH_INTERNALFORMAT, - OSGTEXT_GLYPH_FORMAT, GL_UNSIGNED_BYTE, + GL_ALPHA, + GL_ALPHA, GL_UNSIGNED_BYTE, data, osg::Image::USE_NEW_DELETE, 1); - glyph->setInternalTextureFormat(OSGTEXT_GLYPH_INTERNALFORMAT); - // now populate data array by converting bitmap into a luminance_alpha map. unsigned char* ptr = rasters[i-32]; unsigned char value_on = 255; diff --git a/src/osgText/Glyph.cpp b/src/osgText/Glyph.cpp index 8ca21f5bc..114f6649a 100644 --- a/src/osgText/Glyph.cpp +++ b/src/osgText/Glyph.cpp @@ -28,6 +28,22 @@ using namespace osgText; using namespace std; +// GL_ALPHA and GL_LUMINANCE_ALPHA are deprecated in GL3/GL4 core profile, use GL_RED & GL_RB in this case. +#if defined(OSG_GL3_AVAILABLE) && !defined(OSG_GL2_AVAILABLE) && !defined(OSG_GL1_AVAILABLE) +#define OSGTEXT_GLYPH_ALPHA_FORMAT GL_RED +#define OSGTEXT_GLYPH_ALPHA_INTERNALFORMAT GL_R8 +#define OSGTEXT_GLYPH_SDF_FORMAT GL_RG +#define OSGTEXT_GLYPH_SDF_INTERNALFORMAT GL_RG8 +#else +#define OSGTEXT_GLYPH_ALPHA_FORMAT GL_ALPHA +#define OSGTEXT_GLYPH_ALPHA_INTERNALFORMAT GL_ALPHA +#define OSGTEXT_GLYPH_SDF_FORMAT GL_LUMINANCE_ALPHA +#define OSGTEXT_GLYPH_SDF_INTERNALFORMAT GL_LUMINANCE_ALPHA +#endif + + + + #if 0 #define TEXTURE_IMAGE_NUM_CHANNELS 1 #define TEXTURE_IMAGE_FORMAT OSGTEXT_GLYPH_FORMAT @@ -160,6 +176,9 @@ void GlyphTexture::copyGlyphImage(Glyph* glyph) if (_glyphTextureFeatures==GREYSCALE) { // OSG_NOTICE<<"GlyphTexture::copyGlyphImage() greyscale copying. glyphTexture="<=130\n" + " #define ALPHA r\n" + " #define SDF g\n" + "#else\n" + " #define ALPHA a\n" + " #define SDF r\n" + "#endif\n" + "\n" + "\n" "uniform sampler2D glyphTexture;\n" "\n" "$OSG_VARYING_IN vec2 texCoord;\n" @@ -49,7 +59,7 @@ char text_sdf_frag[] = "$OSG_GLSL_VERSION\n" "\n" "float distanceFromEdge(vec2 tc)\n" "{\n" - " float center_alpha = TEXTURELOD(glyphTexture, tc, 0.0).r;\n" + " float center_alpha = TEXTURELOD(glyphTexture, tc, 0.0).SDF;\n" " if (center_alpha==0.0) return -1.0;\n" "\n" " //float distance_scale = (1.0/4.0)*1.41;\n" @@ -169,7 +179,7 @@ char text_sdf_frag[] = "$OSG_GLSL_VERSION\n" "\n" "#ifdef OUTLINE\n" "\n" - " float alpha = TEXTURE(glyphTexture, src_texCoord).a;\n" + " float alpha = TEXTURE(glyphTexture, src_texCoord).ALPHA;\n" " float delta_tc = 1.6*OUTLINE*GLYPH_DIMENSION/TEXTURE_DIMENSION;\n" "\n" " float outline_alpha = alpha;\n" @@ -184,7 +194,7 @@ char text_sdf_frag[] = "$OSG_GLSL_VERSION\n" " {\n" " for(float j=0.0; j