diff --git a/include/nds/arm9/videoGL.h b/include/nds/arm9/videoGL.h index fdfcc92..e11df23 100644 --- a/include/nds/arm9/videoGL.h +++ b/include/nds/arm9/videoGL.h @@ -428,7 +428,7 @@ void glRotatef32i(int angle, s32 x, s32 y, s32 z); \param sizeY the vertical size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM \param empty2 not used, just here for OpenGL compatibility \param param parameters for the texture -\param texture pointer to the texture data to load +\param texture pointer to the texture data to load; if NULL, VRAM for the texture is allocated but the texture is not loaded yet \return 1 on success, 0 on failure*/ int glTexImage2D(int target, int empty1, GL_TEXTURE_TYPE_ENUM type, int sizeX, int sizeY, int empty2, int param, const void* texture); @@ -438,7 +438,7 @@ int glTexImage2D(int target, int empty1, GL_TEXTURE_TYPE_ENUM type, int sizeX, i \param width the length of the palette (if 0, then palette is removed from currently bound texture) \param empty2 ignored, only here for OpenGL compatability \param empty3 ignored, only here for OpenGL compatability -\param table pointer to the palette data to load (if NULL, then palette is removed from currently bound texture)*/ +\param table pointer to the palette data to load (if NULL, VRAM for the palette is allocated but the palette is not loaded yet)*/ void glColorTableEXT(int target, int empty1, u16 width, int empty2, int empty3, const u16* table); /*! \brief glColorSubTableEXT loads a 15-bit color format palette into a specific spot in a currently bound texture's existing palette diff --git a/source/arm9/videoGL.c b/source/arm9/videoGL.c index 922985c..68a4aff 100644 --- a/source/arm9/videoGL.c +++ b/source/arm9/videoGL.c @@ -739,8 +739,8 @@ void glColorTableEXT( int target, int empty1, u16 width, int empty2, int empty3, if( texture->palIndex ) // Remove prior palette if exists removePaletteFromTexture( texture ); - // Exit if no color table or color count is 0 (helpful in emptying the palette for the active texture) - if( !width || table == NULL ) + // Exit if color count is 0 (helpful in emptying the palette for the active texture) + if( !width ) return; // Allocate new palette block based on the texture's format @@ -776,6 +776,19 @@ void glColorTableEXT( int target, int empty1, u16 width, int empty2, int empty3, palette->connectCount = 1; palette->palSize = width << 1; + if( glGlob->deallocPalSize ) + texture->palIndex = (u32)DynamicArrayGet( &glGlob->deallocPal, glGlob->deallocPalSize-- ); + else + texture->palIndex = glGlob->palCount++; + DynamicArraySet( &glGlob->palettePtrs, texture->palIndex, (void*)palette ); + + GFX_PAL_FORMAT = palette->addr; + glGlob->activePalette = texture->palIndex; + + // allocate, but don't touch VRAM if table is NULL + if ( table == NULL ) + return; + // copy straight to VRAM, and assign a palette name u32 tempVRAM = VRAM_EFG_CR; u16 *startBank = vramGetBank( (u16*)palette->vramAddr ); @@ -795,15 +808,6 @@ void glColorTableEXT( int target, int empty1, u16 width, int empty2, int empty3, swiCopy( table, palette->vramAddr, width | COPY_MODE_HWORD ); vramRestoreBanks_EFG( tempVRAM ); - - if( glGlob->deallocPalSize ) - texture->palIndex = (u32)DynamicArrayGet( &glGlob->deallocPal, glGlob->deallocPalSize-- ); - else - texture->palIndex = glGlob->palCount++; - DynamicArraySet( &glGlob->palettePtrs, texture->palIndex, (void*)palette ); - - GFX_PAL_FORMAT = palette->addr; - glGlob->activePalette = texture->palIndex; } else GFX_PAL_FORMAT = glGlob->activePalette = texture->palIndex; }