diff --git a/src/nvimage/ColorBlock.cpp b/src/nvimage/ColorBlock.cpp index 2c9945f..945e0b4 100644 --- a/src/nvimage/ColorBlock.cpp +++ b/src/nvimage/ColorBlock.cpp @@ -62,7 +62,7 @@ void ColorBlock::init(const Image * img, uint x, uint y) nvDebugCheck(bw != 0); nvDebugCheck(bh != 0); - static int remainder[] = { + static const int remainder[] = { 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 2, 0, diff --git a/src/nvimage/DirectDrawSurface.cpp b/src/nvimage/DirectDrawSurface.cpp index 542ca8d..7219074 100644 --- a/src/nvimage/DirectDrawSurface.cpp +++ b/src/nvimage/DirectDrawSurface.cpp @@ -681,10 +681,17 @@ void DDSHeader::setPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask nvCheck((gmask & amask) == 0); nvCheck((bmask & amask) == 0); - this->pf.flags = DDPF_RGB; - - if (amask != 0) { - this->pf.flags |= DDPF_ALPHAPIXELS; + if (rmask != 0 || gmask != 0 || bmask != 0) + { + this->pf.flags = DDPF_RGB; + + if (amask != 0) { + this->pf.flags |= DDPF_ALPHAPIXELS; + } + } + else if (amask != 0) + { + this->pf.flags |= DDPF_ALPHA; } if (bitcount == 0) @@ -726,6 +733,12 @@ void DDSHeader::setNormalFlag(bool b) else this->pf.flags &= ~DDPF_NORMAL; } +void DDSHeader::setHasAlphaFlag(bool b) +{ + if (b) this->pf.flags |= DDPF_ALPHAPIXELS; + else this->pf.flags &= ~DDPF_ALPHAPIXELS; +} + void DDSHeader::swapBytes() { this->fourcc = POSH_LittleU32(this->fourcc); @@ -883,7 +896,7 @@ bool DirectDrawSurface::hasAlpha() const { if (header.hasDX10Header()) { - // @@ TODO: Update with all formats. +#pragma message(NV_FILE_LINE "Update hasAlpha to handle all DX10 formats.") return header.header10.dxgiFormat == DXGI_FORMAT_BC1_UNORM || header.header10.dxgiFormat == DXGI_FORMAT_BC2_UNORM || @@ -906,6 +919,7 @@ bool DirectDrawSurface::hasAlpha() const } else { + // @@ Here we could check the ALPHA_PIXELS flag, but nobody sets it. return true; } } @@ -991,6 +1005,13 @@ void DirectDrawSurface::setNormalFlag(bool b) header.setNormalFlag(b); } +void DirectDrawSurface::setHasAlphaFlag(bool b) +{ + nvDebugCheck(isValid()); + header.setHasAlphaFlag(b); +} + + void DirectDrawSurface::mipmap(Image * img, uint face, uint mipmap) { nvDebugCheck(isValid()); diff --git a/src/nvimage/DirectDrawSurface.h b/src/nvimage/DirectDrawSurface.h index 9f1ffd7..fb19ccc 100644 --- a/src/nvimage/DirectDrawSurface.h +++ b/src/nvimage/DirectDrawSurface.h @@ -98,6 +98,7 @@ namespace nv void setPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask); void setDX10Format(uint format); void setNormalFlag(bool b); + void setHasAlphaFlag(bool b); void swapBytes(); @@ -130,6 +131,7 @@ namespace nv bool isTextureCube() const; void setNormalFlag(bool b); + void setHasAlphaFlag(bool b); void mipmap(Image * img, uint f, uint m); // void mipmap(FloatImage * img, uint f, uint m); diff --git a/src/nvtt/Context.cpp b/src/nvtt/Context.cpp index 27fdb47..e7683d0 100644 --- a/src/nvtt/Context.cpp +++ b/src/nvtt/Context.cpp @@ -414,6 +414,7 @@ bool Compressor::Private::outputHeader(const InputOptions::Private & inputOption { if (compressionOptions.format == Format_DXT1 || compressionOptions.format == Format_DXT1a || compressionOptions.format == Format_DXT1n) { header.setDX10Format(71); + if (compressionOptions.format == Format_DXT1a) header.setHasAlphaFlag(true); if (inputOptions.isNormalMap) header.setNormalFlag(true); } else if (compressionOptions.format == Format_DXT3) {