MipMap support.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 10 May 2011 14:22:31 -0400
changeset 10 1e5f3d130b53
parent 9 50157857e7d8
child 11 7e2785b01d10
MipMap support.
mojodds.c
mojodds.h
--- a/mojodds.c	Tue May 10 01:33:25 2011 -0400
+++ b/mojodds.c	Tue May 10 14:22:31 2011 -0400
@@ -108,7 +108,7 @@
 } // readui32
 
 static int parse_dds(MOJODDS_Header *header, const uint8 **ptr, size_t *len,
-                     unsigned int *_glfmt)
+                     unsigned int *_glfmt, unsigned int *_miplevels)
 {
     const uint32 pitchAndLinear = (DDSD_PITCH | DDSD_LINEARSIZE);
     uint32 width = 0;
@@ -159,13 +159,15 @@
         return 0;
     else if ((header->dwFlags & DDSD_REQ) != DDSD_REQ)  // must have these bits.
         return 0;
-    else if (header->dwCaps != DDSCAPS_TEXTURE)  // !!! FIXME
+    else if ((header->dwCaps & DDSCAPS_TEXTURE) == 0)
         return 0;
     else if (header->dwCaps2 != 0)  // !!! FIXME (non-zero with other bits in dwCaps set)
         return 0;
     else if ((header->dwFlags & pitchAndLinear) == pitchAndLinear)
         return 0;  // can't specify both.
 
+    *_miplevels = (header->dwCaps & DDSCAPS_MIPMAP) ? header->dwMipMapCount : 1;
+
     if (header->ddspf.dwFlags & DDPF_FOURCC)
     {
         switch (header->ddspf.dwFourCC)
@@ -255,12 +257,12 @@
 int MOJODDS_getTexture(const void *_ptr, const unsigned long _len,
                        const void **_tex, unsigned long *_texlen,
                        unsigned int *_glfmt, unsigned int *_w,
-                       unsigned int *_h)
+                       unsigned int *_h, unsigned int *_miplevels)
 {
     size_t len = (size_t) _len;
     const uint8 *ptr = (const uint8 *) _ptr;
     MOJODDS_Header header;
-    if (!parse_dds(&header, &ptr, &len, _glfmt))
+    if (!parse_dds(&header, &ptr, &len, _glfmt, _miplevels))
         return 0;
 
     *_tex = (const void *) ptr;
--- a/mojodds.h	Tue May 10 01:33:25 2011 -0400
+++ b/mojodds.h	Tue May 10 14:22:31 2011 -0400
@@ -10,7 +10,7 @@
 int MOJODDS_getTexture(const void *_ptr, const unsigned long _len,
                        const void **_tex, unsigned long *_texlen,
                        unsigned int *_glfmt, unsigned int *_w,
-                       unsigned int *_h);
+                       unsigned int *_h, unsigned int *_miplevels);
 
 #ifdef __cplusplus
 }