From e7e860b742190e9d05bdd1a9846bc0d8e92c1769 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 11 Apr 2011 19:11:25 +0000 Subject: [PATCH] Added support for explitly requesting DXT1a and DXT1c compression --- include/osg/Texture | 4 ++- src/osg/Texture.cpp | 30 ++++++++++++++++++++++ src/osgPlugins/dds/ReaderWriterDDS.cpp | 3 ++- src/osgPlugins/nvtt/NVTTImageProcessor.cpp | 6 +++++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/include/osg/Texture b/include/osg/Texture index 82cc19758..53c8930ae 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -447,7 +447,9 @@ class OSG_EXPORT Texture : public osg::StateAttribute USE_S3TC_DXT3_COMPRESSION, USE_S3TC_DXT5_COMPRESSION, USE_RGTC1_COMPRESSION, - USE_RGTC2_COMPRESSION + USE_RGTC2_COMPRESSION, + USE_S3TC_DXT1c_COMPRESSION, + USE_S3TC_DXT1a_COMPRESSION }; /** Sets the internal texture format mode. Note: If the texture format is diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 2a06fa6e3..f1544b4e3 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -1299,6 +1299,36 @@ void Texture::computeInternalFormatWithImage(const osg::Image& image) const else internalFormat = image.getInternalTextureFormat(); break; + case(USE_S3TC_DXT1c_COMPRESSION): + if (extensions->isTextureCompressionS3TCSupported()) + { + switch(image.getPixelFormat()) + { + case(3): + case(4): + case(GL_RGB): + case(GL_RGBA): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break; + default: internalFormat = image.getInternalTextureFormat(); break; + } + } + else internalFormat = image.getInternalTextureFormat(); + break; + + case(USE_S3TC_DXT1a_COMPRESSION): + if (extensions->isTextureCompressionS3TCSupported()) + { + switch(image.getPixelFormat()) + { + case(3): + case(4): + case(GL_RGB): + case(GL_RGBA): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break; + default: internalFormat = image.getInternalTextureFormat(); break; + } + } + else internalFormat = image.getInternalTextureFormat(); + break; + case(USE_S3TC_DXT3_COMPRESSION): if (extensions->isTextureCompressionS3TCSupported()) { diff --git a/src/osgPlugins/dds/ReaderWriterDDS.cpp b/src/osgPlugins/dds/ReaderWriterDDS.cpp index 9b3044a52..25302e6ea 100644 --- a/src/osgPlugins/dds/ReaderWriterDDS.cpp +++ b/src/osgPlugins/dds/ReaderWriterDDS.cpp @@ -177,7 +177,8 @@ struct DDSURFACEDESC2 // // Structure of a DXT-1 compressed texture block -// see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/Opaque_and_1_Bit_Alpha_Textures.asp +// see page "Opaque and 1-Bit Alpha Textures (Direct3D 9)" on http://msdn.microsoft.com +// url at time of writing http://msdn.microsoft.com/en-us/library/bb147243(v=VS.85).aspx // struct DXT1TexelsBlock { diff --git a/src/osgPlugins/nvtt/NVTTImageProcessor.cpp b/src/osgPlugins/nvtt/NVTTImageProcessor.cpp index dbf06d6a3..a98127220 100644 --- a/src/osgPlugins/nvtt/NVTTImageProcessor.cpp +++ b/src/osgPlugins/nvtt/NVTTImageProcessor.cpp @@ -307,6 +307,12 @@ void NVTTProcessor::compress(osg::Image& image, osg::Texture::InternalFormatMode else format = nvtt::Format_DXT1; break; + case osg::Texture::USE_S3TC_DXT1c_COMPRESSION: + format = nvtt::Format_DXT1; + break; + case osg::Texture::USE_S3TC_DXT1a_COMPRESSION: + format = nvtt::Format_DXT1a; + break; case osg::Texture::USE_S3TC_DXT3_COMPRESSION: format = nvtt::Format_DXT3; break;