From 55c25a551b13057aca5527b2b8e624455db6908c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 4 Mar 2003 15:47:28 +0000 Subject: [PATCH] Added support for using the generate mip map extension within osgText. --- include/osg/Texture | 4 ++++ src/osg/Texture.cpp | 14 +++++++++----- src/osgText/Font.cpp | 42 ++++++++++++++++++++++++++++++++++++++---- 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/include/osg/Texture b/include/osg/Texture index 8fbf176e4..05b010e2e 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -70,6 +70,8 @@ #define GL_TEXTURE_3D 0x806F #endif + + namespace osg { /** Texture base class which encapsulates OpenGl texture functionality which common betweent the various types of OpenGL textures.*/ @@ -248,6 +250,7 @@ class SG_EXPORT Texture : public osg::StateAttribute bool isTextureMirroredRepeatSupported() const { return _isTextureMirroredRepeatSupported; } bool isTextureEdgeClampSupported() const { return _isTextureEdgeClampSupported; } bool isTextureBorderClampSupported() const { return _isTextureBorderClampSupported; } + bool isGenerateMipMapSupported() const { return _isGenerateMipMapSupported; } GLint maxTextureSize() const { return _maxTextureSize; } @@ -265,6 +268,7 @@ class SG_EXPORT Texture : public osg::StateAttribute bool _isTextureMirroredRepeatSupported; bool _isTextureEdgeClampSupported; bool _isTextureBorderClampSupported; + bool _isGenerateMipMapSupported; GLint _maxTextureSize; diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 42e4eb827..61856d336 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -518,12 +518,12 @@ Texture::Extensions::Extensions(const Extensions& rhs): Referenced() { _isTextureFilterAnisotropicSupported = rhs._isTextureFilterAnisotropicSupported; + _isTextureCompressionARBSupported = rhs._isTextureCompressionARBSupported; + _isTextureCompressionS3TCSupported = rhs._isTextureCompressionS3TCSupported; _isTextureMirroredRepeatSupported = rhs._isTextureMirroredRepeatSupported; _isTextureEdgeClampSupported = rhs._isTextureEdgeClampSupported; _isTextureBorderClampSupported = rhs._isTextureBorderClampSupported; - - _isTextureCompressionARBSupported = rhs._isTextureCompressionARBSupported; - _isTextureCompressionS3TCSupported = rhs._isTextureCompressionS3TCSupported; + _isGenerateMipMapSupported = rhs._isGenerateMipMapSupported; _maxTextureSize = rhs._maxTextureSize; @@ -539,6 +539,8 @@ void Texture::Extensions::lowestCommonDenominator(const Extensions& rhs) if (!rhs._isTextureCompressionARBSupported) _isTextureCompressionARBSupported = false; if (!rhs._isTextureCompressionS3TCSupported) _isTextureCompressionS3TCSupported = false; + + if (!rhs._isGenerateMipMapSupported) _isGenerateMipMapSupported = false; if (rhs._maxTextureSize<_maxTextureSize) _maxTextureSize = rhs._maxTextureSize; @@ -549,12 +551,14 @@ void Texture::Extensions::setupGLExtenions() { _isTextureFilterAnisotropicSupported = isGLExtensionSupported("GL_EXT_texture_filter_anisotropic"); + _isTextureCompressionARBSupported = isGLExtensionSupported("GL_ARB_texture_compression"); + _isTextureCompressionS3TCSupported = isGLExtensionSupported("GL_EXT_texture_compression_s3tc"); _isTextureMirroredRepeatSupported = isGLExtensionSupported("GL_IBM_texture_mirrored_repeat"); _isTextureEdgeClampSupported = isGLExtensionSupported("GL_EXT_texture_edge_clamp"); _isTextureBorderClampSupported = isGLExtensionSupported("GL_ARB_texture_border_clamp"); + _isGenerateMipMapSupported = (strncmp((const char*)glGetString(GL_VERSION),"1.4",3)>=0) || + isGLExtensionSupported("GL_SGIS_generate_mipmap"); - _isTextureCompressionARBSupported = isGLExtensionSupported("GL_ARB_texture_compression"); - _isTextureCompressionS3TCSupported = isGLExtensionSupported("GL_EXT_texture_compression_s3tc"); glGetIntegerv(GL_MAX_TEXTURE_SIZE,&_maxTextureSize); diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index 5745f7666..efc34a535 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -119,7 +119,7 @@ void Font::addGlyph(unsigned int width, unsigned int height, unsigned int charco // reserve enough space for the glyphs. glyphTexture->setTextureSize(256,256); glyphTexture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); - //glyphTexture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR_MIPMAP_LINEAR); + glyphTexture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR_MIPMAP_LINEAR); //glyphTexture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::NEAREST); glyphTexture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); glyphTexture->setMaxAnisotropy(8); @@ -245,6 +245,9 @@ void Font::GlyphTexture::apply(osg::State& state) const } + const Extensions* extensions = getExtensions(contextID,true); + bool generateMipMapSupported = extensions->isGenerateMipMapSupported(); + // get the globj for the current contextID. GLuint& handle = getTextureObject(contextID); @@ -256,8 +259,23 @@ void Font::GlyphTexture::apply(osg::State& state) const applyTexParameters(GL_TEXTURE_2D,state); - //glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE); - + // need to look at generate mip map extension if mip mapping required. + switch(_min_filter) + { + case NEAREST_MIPMAP_NEAREST: + case NEAREST_MIPMAP_LINEAR: + case LINEAR_MIPMAP_NEAREST: + case LINEAR_MIPMAP_LINEAR: + if (generateMipMapSupported) { + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE); + } + else glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, LINEAR); + break; + default: + // not mip mapping so no problems. + break; + } + // allocate the texture memory. glTexImage2D( GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, getTextureWidth(), getTextureHeight(), 0, @@ -271,11 +289,27 @@ void Font::GlyphTexture::apply(osg::State& state) const // reuse texture by binding. glBindTexture( GL_TEXTURE_2D, handle ); if (getTextureParameterDirty(contextID)) + { applyTexParameters(GL_TEXTURE_2D,state); + // need to look at generate mip map extension if mip mapping required. + switch(_min_filter) + { + case NEAREST_MIPMAP_NEAREST: + case NEAREST_MIPMAP_LINEAR: + case LINEAR_MIPMAP_NEAREST: + case LINEAR_MIPMAP_LINEAR: + if (generateMipMapSupported) glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE); + else glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, LINEAR); + break; + default: + // not mip mapping so no problems. + break; + } + } + } - //glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE); // now subload the glyphs that are outstanding for this graphics context. GlyphPtrList& glyphsWereSubloading = _glyphsToSubload[contextID];