Revision: 16462
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16462
Author:   sirdude
Date:     2008-09-10 17:07:20 +0200 (Wed, 10 Sep 2008)

Log Message:
-----------
This is patch:
[#15135] imbuf DDS support: sync to nvidia texture tools revision 602 + fix for 
ATI2 compressed normal maps

It just updates the dds stuff.

Provided by Amorilia

Kent

Revision Links:
--------------
    
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=602

Modified Paths:
--------------
    trunk/blender/source/blender/imbuf/intern/dds/ColorBlock.cpp
    trunk/blender/source/blender/imbuf/intern/dds/ColorBlock.h
    trunk/blender/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp
    trunk/blender/source/blender/imbuf/intern/dds/DirectDrawSurface.h
    trunk/blender/source/blender/imbuf/intern/dds/dds_api.cpp

Modified: trunk/blender/source/blender/imbuf/intern/dds/ColorBlock.cpp
===================================================================
--- trunk/blender/source/blender/imbuf/intern/dds/ColorBlock.cpp        
2008-09-10 13:02:58 UTC (rev 16461)
+++ trunk/blender/source/blender/imbuf/intern/dds/ColorBlock.cpp        
2008-09-10 15:07:20 UTC (rev 16462)
@@ -53,6 +53,14 @@
 {
 }
 
+/// Init the color block from an array of colors.
+ColorBlock::ColorBlock(const uint * linearImage)
+{
+       for(uint i = 0; i < 16; i++) {
+               color(i) = Color32(linearImage[i]);
+       }
+}
+
 /// Init the color block with the contents of the given block.
 ColorBlock::ColorBlock(const ColorBlock & block)
 {
@@ -125,9 +133,12 @@
 /// Returns true if the block has a single color.
 bool ColorBlock::isSingleColor() const
 {
+       Color32 mask(0xFF, 0xFF, 0xFF, 0x00);
+       uint u = m_color[0].u & mask.u;
+       
        for(int i = 1; i < 16; i++)
        {
-               if (m_color[0] != m_color[i])
+               if (u != (m_color[i].u & mask.u))
                {
                        return false;
                }
@@ -136,6 +147,30 @@
        return true;
 }
 
+/// Returns true if the block has a single color, ignoring transparent pixels.
+bool ColorBlock::isSingleColorNoAlpha() const
+{
+       Color32 c;
+       int i;
+       for(i = 0; i < 16; i++)
+       {
+               if (m_color[i].a != 0) c = m_color[i];
+       }
+
+       Color32 mask(0xFF, 0xFF, 0xFF, 0x00);
+       uint u = c.u & mask.u;
+
+       for(; i < 16; i++)
+       {
+               if (u != (m_color[i].u & mask.u))
+               {
+                       return false;
+               }
+       }
+       
+       return true;
+}
+
 /// Count number of unique colors in this color block.
 uint ColorBlock::countUniqueColors() const
 {

Modified: trunk/blender/source/blender/imbuf/intern/dds/ColorBlock.h
===================================================================
--- trunk/blender/source/blender/imbuf/intern/dds/ColorBlock.h  2008-09-10 
13:02:58 UTC (rev 16461)
+++ trunk/blender/source/blender/imbuf/intern/dds/ColorBlock.h  2008-09-10 
15:07:20 UTC (rev 16462)
@@ -41,6 +41,7 @@
 struct ColorBlock
 {
        ColorBlock();
+       ColorBlock(const uint * linearImage);
        ColorBlock(const ColorBlock & block);
        ColorBlock(const Image * img, uint x, uint y);
        
@@ -51,6 +52,7 @@
        void splatY();
        
        bool isSingleColor() const;
+       bool isSingleColorNoAlpha() const;
        uint countUniqueColors() const;
        Color32 averageColor() const;
        bool hasAlpha() const;

Modified: trunk/blender/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp
===================================================================
--- trunk/blender/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp 
2008-09-10 13:02:58 UTC (rev 16461)
+++ trunk/blender/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp 
2008-09-10 15:07:20 UTC (rev 16462)
@@ -80,6 +80,10 @@
 static const uint FOURCC_ATI1 = MAKEFOURCC('A', 'T', 'I', '1');
 static const uint FOURCC_ATI2 = MAKEFOURCC('A', 'T', 'I', '2');
 
+static const uint FOURCC_A2XY = MAKEFOURCC('A', '2', 'X', 'Y');
+       
+static const uint FOURCC_DX10 = MAKEFOURCC('D', 'X', '1', '0');
+
 // 32 bit RGB formats.
 static const uint D3DFMT_R8G8B8 = 20;
 static const uint D3DFMT_A8R8G8B8 = 21;
@@ -279,6 +283,144 @@
                D3D10_RESOURCE_DIMENSION_TEXTURE3D = 4,
        };
 
+
+       const char * getDxgiFormatString(DXGI_FORMAT dxgiFormat)
+       {
+#define CASE(format) case DXGI_FORMAT_##format: return #format
+               switch(dxgiFormat)
+               {
+                       CASE(UNKNOWN);
+                       
+                       CASE(R32G32B32A32_TYPELESS);
+                       CASE(R32G32B32A32_FLOAT);
+                       CASE(R32G32B32A32_UINT);
+                       CASE(R32G32B32A32_SINT);
+                       
+                       CASE(R32G32B32_TYPELESS);
+                       CASE(R32G32B32_FLOAT);
+                       CASE(R32G32B32_UINT);
+                       CASE(R32G32B32_SINT);
+                       
+                       CASE(R16G16B16A16_TYPELESS);
+                       CASE(R16G16B16A16_FLOAT);
+                       CASE(R16G16B16A16_UNORM);
+                       CASE(R16G16B16A16_UINT);
+                       CASE(R16G16B16A16_SNORM);
+                       CASE(R16G16B16A16_SINT);
+                       
+                       CASE(R32G32_TYPELESS);
+                       CASE(R32G32_FLOAT);
+                       CASE(R32G32_UINT);
+                       CASE(R32G32_SINT);
+                       
+                       CASE(R32G8X24_TYPELESS);
+                       CASE(D32_FLOAT_S8X24_UINT);
+                       CASE(R32_FLOAT_X8X24_TYPELESS);
+                       CASE(X32_TYPELESS_G8X24_UINT);
+                       
+                       CASE(R10G10B10A2_TYPELESS);
+                       CASE(R10G10B10A2_UNORM);
+                       CASE(R10G10B10A2_UINT);
+                       
+                       CASE(R11G11B10_FLOAT);
+                       
+                       CASE(R8G8B8A8_TYPELESS);
+                       CASE(R8G8B8A8_UNORM);
+                       CASE(R8G8B8A8_UNORM_SRGB);
+                       CASE(R8G8B8A8_UINT);
+                       CASE(R8G8B8A8_SNORM);
+                       CASE(R8G8B8A8_SINT);
+                       
+                       CASE(R16G16_TYPELESS);
+                       CASE(R16G16_FLOAT);
+                       CASE(R16G16_UNORM);
+                       CASE(R16G16_UINT);
+                       CASE(R16G16_SNORM);
+                       CASE(R16G16_SINT);
+                       
+                       CASE(R32_TYPELESS);
+                       CASE(D32_FLOAT);
+                       CASE(R32_FLOAT);
+                       CASE(R32_UINT);
+                       CASE(R32_SINT);
+                       
+                       CASE(R24G8_TYPELESS);
+                       CASE(D24_UNORM_S8_UINT);
+                       CASE(R24_UNORM_X8_TYPELESS);
+                       CASE(X24_TYPELESS_G8_UINT);
+                       
+                       CASE(R8G8_TYPELESS);
+                       CASE(R8G8_UNORM);
+                       CASE(R8G8_UINT);
+                       CASE(R8G8_SNORM);
+                       CASE(R8G8_SINT);
+                       
+                       CASE(R16_TYPELESS);
+                       CASE(R16_FLOAT);
+                       CASE(D16_UNORM);
+                       CASE(R16_UNORM);
+                       CASE(R16_UINT);
+                       CASE(R16_SNORM);
+                       CASE(R16_SINT);
+                       
+                       CASE(R8_TYPELESS);
+                       CASE(R8_UNORM);
+                       CASE(R8_UINT);
+                       CASE(R8_SNORM);
+                       CASE(R8_SINT);
+                       CASE(A8_UNORM);
+
+                       CASE(R1_UNORM);
+               
+                       CASE(R9G9B9E5_SHAREDEXP);
+                       
+                       CASE(R8G8_B8G8_UNORM);
+                       CASE(G8R8_G8B8_UNORM);
+
+                       CASE(BC1_TYPELESS);
+                       CASE(BC1_UNORM);
+                       CASE(BC1_UNORM_SRGB);
+               
+                       CASE(BC2_TYPELESS);
+                       CASE(BC2_UNORM);
+                       CASE(BC2_UNORM_SRGB);
+               
+                       CASE(BC3_TYPELESS);
+                       CASE(BC3_UNORM);
+                       CASE(BC3_UNORM_SRGB);
+               
+                       CASE(BC4_TYPELESS);
+                       CASE(BC4_UNORM);
+                       CASE(BC4_SNORM);
+               
+                       CASE(BC5_TYPELESS);
+                       CASE(BC5_UNORM);
+                       CASE(BC5_SNORM);
+
+                       CASE(B5G6R5_UNORM);
+                       CASE(B5G5R5A1_UNORM);
+                       CASE(B8G8R8A8_UNORM);
+                       CASE(B8G8R8X8_UNORM);
+
+                       default: 
+                               return "UNKNOWN";
+               }
+#undef CASE
+       }
+       
+       const char * getD3d10ResourceDimensionString(D3D10_RESOURCE_DIMENSION 
resourceDimension)
+       {
+               switch(resourceDimension)
+               {
+                       default:
+                       case D3D10_RESOURCE_DIMENSION_UNKNOWN: return "UNKNOWN";
+                       case D3D10_RESOURCE_DIMENSION_BUFFER: return "BUFFER";
+                       case D3D10_RESOURCE_DIMENSION_TEXTURE1D: return 
"TEXTURE1D";
+                       case D3D10_RESOURCE_DIMENSION_TEXTURE2D: return 
"TEXTURE2D";
+                       case D3D10_RESOURCE_DIMENSION_TEXTURE3D: return 
"TEXTURE3D";
+               }
+       }
+
 /*** implementation ***/
 
 void mem_read(Stream & mem, DDSPixelFormat & pf)
@@ -451,7 +593,16 @@
        // set fourcc pixel format.
        this->pf.flags = DDPF_FOURCC;
        this->pf.fourcc = MAKEFOURCC(c0, c1, c2, c3);
-       this->pf.bitcount = 0;
+
+       if (this->pf.fourcc == FOURCC_ATI2)
+       {
+               this->pf.bitcount = FOURCC_A2XY;
+       }
+       else
+       {
+               this->pf.bitcount = 0;
+       }
+       
        this->pf.rmask = 0;
        this->pf.gmask = 0;
        this->pf.bmask = 0;
@@ -508,7 +659,8 @@
 
 void DDSHeader::setDX10Format(uint format)
 {
-       this->pf.flags = 0;
+       //this->pf.flags = 0;
+       this->pf.fourcc = FOURCC_DX10;
        this->header10.dxgiFormat = format;
 }
 
@@ -520,12 +672,18 @@
 
 bool DDSHeader::hasDX10Header() const
 {
-       return this->pf.flags == 0;
+       return this->pf.fourcc == FOURCC_DX10;  // @@ This is according to AMD
+       //return this->pf.flags == 0;             // @@ This is according to MS
 }
 
 DirectDrawSurface::DirectDrawSurface(unsigned char *mem, uint size) : 
stream(mem, size), header()
 {
        mem_read(stream, header);
+
+       // some ATI2 compressed normal maps do not have their
+       // normal flag set, so force it here (the original nvtt don't do
+       // this, but the decompressor has a -forcenormal flag)
+       if (header.pf.fourcc == FOURCC_ATI2) header.setNormalFlag(true);
 }
 
 DirectDrawSurface::~DirectDrawSurface()
@@ -539,7 +697,7 @@
                return false;
        }
        
-       const uint required = 
(DDSD_WIDTH|DDSD_HEIGHT|DDSD_CAPS|DDSD_PIXELFORMAT);
+       const uint required = 
(DDSD_WIDTH|DDSD_HEIGHT/*|DDSD_CAPS|DDSD_PIXELFORMAT*/);
        if( (header.flags & required) != required ) {
                return false;
        }
@@ -560,42 +718,48 @@
 
 bool DirectDrawSurface::isSupported() const
 {
-       if (header.pf.flags & DDPF_FOURCC)
+       if (header.hasDX10Header())
        {
-               if (header.pf.fourcc != FOURCC_DXT1 &&
-                   header.pf.fourcc != FOURCC_DXT2 &&
-                   header.pf.fourcc != FOURCC_DXT3 &&
-                   header.pf.fourcc != FOURCC_DXT4 &&
-                   header.pf.fourcc != FOURCC_DXT5 &&
-                   header.pf.fourcc != FOURCC_RXGB &&
-                   header.pf.fourcc != FOURCC_ATI1 &&
-                   header.pf.fourcc != FOURCC_ATI2)
+       }
+       else
+       {
+               if (header.pf.flags & DDPF_FOURCC)
                {
-                       // Unknown fourcc code.
+                       if (header.pf.fourcc != FOURCC_DXT1 &&
+                           header.pf.fourcc != FOURCC_DXT2 &&
+                           header.pf.fourcc != FOURCC_DXT3 &&
+                           header.pf.fourcc != FOURCC_DXT4 &&
+                           header.pf.fourcc != FOURCC_DXT5 &&
+                           header.pf.fourcc != FOURCC_RXGB &&
+                           header.pf.fourcc != FOURCC_ATI1 &&
+                           header.pf.fourcc != FOURCC_ATI2)
+                       {
+                               // Unknown fourcc code.
+                               return false;
+                       }
+               }
+               else if (header.pf.flags & DDPF_RGB)
+               {
+                       // All RGB formats are supported now.
+               }
+               else
+               {
                        return false;
                }
-       }
-       else if (header.pf.flags & DDPF_RGB)
-       {
-               // All RGB formats are supported now.
-       }
-       else
-       {
-               return false;
-       }
+               
+               if (isTextureCube() && (header.caps.caps2 & 
DDSCAPS2_CUBEMAP_ALL_FACES) != DDSCAPS2_CUBEMAP_ALL_FACES)
+               {
+                       // Cubemaps must contain all faces.
+                       return false;
+               }
        
-       if (isTextureCube() && (header.caps.caps2 & DDSCAPS2_CUBEMAP_ALL_FACES) 
!= DDSCAPS2_CUBEMAP_ALL_FACES)
-       {
-               // Cubemaps must contain all faces.
-               return false;
+               if (isTexture3D())
+               {
+                       // @@ 3D textures not supported yet.
+                       return false;
+               }
        }
        
-       if (isTexture3D())
-       {
-               // @@ 3D textures not supported yet.
-               return false;
-       }
-       
        return true;
 }
 
@@ -641,14 +805,37 @@
        }
 }
 
+bool DirectDrawSurface::isTexture1D() const
+{
+       if (header.hasDX10Header())
+       {
+               return header.header10.resourceDimension == 
D3D10_RESOURCE_DIMENSION_TEXTURE1D;
+       }
+       return false;
+}
+
 bool DirectDrawSurface::isTexture2D() const
 {
-       return !isTexture3D() && !isTextureCube();
+       if (header.hasDX10Header())
+       {
+               return header.header10.resourceDimension == 
D3D10_RESOURCE_DIMENSION_TEXTURE2D;
+       }
+       else
+       {
+               return !isTexture3D() && !isTextureCube();
+       }
 }
 
 bool DirectDrawSurface::isTexture3D() const
 {
+       if (header.hasDX10Header())
+       {
+               return header.header10.resourceDimension == 
D3D10_RESOURCE_DIMENSION_TEXTURE3D;
+       }
+       else
+       {
        return (header.caps.caps2 & DDSCAPS2_VOLUME) != 0;
+       }
 }
 
 bool DirectDrawSurface::isTextureCube() const
@@ -656,6 +843,11 @@
        return (header.caps.caps2 & DDSCAPS2_CUBEMAP) != 0;
 }
 
+void DirectDrawSurface::setNormalFlag(bool b)
+{
+       header.setNormalFlag(b);
+}
+
 void DirectDrawSurface::mipmap(Image * img, uint face, uint mipmap)
 {
        stream.seek(offset(face, mipmap));
@@ -709,7 +901,13 @@
                return;
        }
 
-       if (header.pf.amask != 0)
+       // set image format: RGB or ARGB

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to