From 7473bf573d83a7af8567d4a69fcb16a3b42c6eaf Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 3 Apr 2003 21:00:12 +0000 Subject: [PATCH] Suported for mip mapping added by Rune. --- src/osgPlugins/dds/ReaderWriterDDS.cpp | 143 +++++++++++++++++++------ 1 file changed, 110 insertions(+), 33 deletions(-) diff --git a/src/osgPlugins/dds/ReaderWriterDDS.cpp b/src/osgPlugins/dds/ReaderWriterDDS.cpp index 558c8c693..eebfa9502 100644 --- a/src/osgPlugins/dds/ReaderWriterDDS.cpp +++ b/src/osgPlugins/dds/ReaderWriterDDS.cpp @@ -110,6 +110,10 @@ typedef struct _DDSURFACEDESC2 unsigned long dwTextureStage; } DDSURFACEDESC2; +#define DDPF_ALPHAPIXELS 0x00000001l +#define DDPF_FOURCC 0x00000004l +#define DDPF_RGB 0x00000040l + #ifndef MAKEFOURCC #define MAKEFOURCC(ch0, ch1, ch2, ch3) \ ((unsigned long)(char)(ch0) | ((unsigned long)(char)(ch1) << 8) | \ @@ -125,6 +129,15 @@ typedef struct _DDSURFACEDESC2 #define FOURCC_DXT4 (MAKEFOURCC('D','X','T','4')) #define FOURCC_DXT5 (MAKEFOURCC('D','X','T','5')) + +void shiftAlpha(int*imageData, int size){ + + for(int i=0;i1) { - osg::notify(osg::WARN)<<"Warning: Mipmaps in dds file are ignored."<MipLevelOffset(k); -// } -// image->setMipmapData(mipmaps); + // Now set mipmap data (offsets into image raw data). + osg::Image::MipmapDataType mipmaps; + // Number of offsets in osg is one less than num_mipmaps + // because it's assumed that first offset is 0. + mipmaps.resize(ddsd.dwMipMapCount-1); + // Handle compressed mipmaps. + if(ddsd.ddpfPixelFormat.dwFlags & DDPF_FOURCC) + { + int width = ddsd.dwWidth; + int height = ddsd.dwHeight; + int blockSize = (pixelFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) ? 8 : 16; + int offset = 0; + for (unsigned int k = 1; k < ddsd.dwMipMapCount && (width || height); ++k) + { + if (width == 0) + width = 1; + if (height == 0) + height = 1; + size = ((width+3)/4)*((height+3)/4)*blockSize; + offset += size; + mipmaps[k-1] = offset; + width >>= 1; + height >>= 1; + } + osgImage->setMipmapData(mipmaps); + } + // Handle uncompressed mipmaps + if(ddsd.ddpfPixelFormat.dwFlags & DDPF_RGB) + { + int offset = 0; + int width = ddsd.dwWidth; + int height = ddsd.dwHeight; + for (unsigned int k = 1; k < ddsd.dwMipMapCount && (width || height); ++k) + { + if (width == 0) + width = 1; + if (height == 0) + height = 1; + size = s*t*(ddsd.ddpfPixelFormat.dwRGBBitCount/8); + offset += size; + mipmaps[k-1] = offset; + width >>= 1; + height >>= 1; + } + osgImage->setMipmapData(mipmaps); + } } // Set image data and properties.