Skip to content

Commit

Permalink
MipMap support.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed May 10, 2011
1 parent 3a67432 commit 665f31b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions mojodds.c
Expand Up @@ -108,7 +108,7 @@ static uint32 readui32(const uint8 **_ptr, size_t *_len)
} // 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;
Expand Down Expand Up @@ -159,13 +159,15 @@ static int parse_dds(MOJODDS_Header *header, const uint8 **ptr, size_t *len,
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)
Expand Down Expand Up @@ -255,12 +257,12 @@ int MOJODDS_isDDS(const void *_ptr, const unsigned long _len)
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;
Expand Down
2 changes: 1 addition & 1 deletion mojodds.h
Expand Up @@ -10,7 +10,7 @@ int MOJODDS_isDDS(const void *_ptr, const unsigned long _len);
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
}
Expand Down

0 comments on commit 665f31b

Please sign in to comment.