Skip to content

Commit 6194b32

Browse files
authored
Let glColorTableEXT allocate placeholder VRAM (#64)
1 parent bedf615 commit 6194b32

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

include/nds/arm9/videoGL.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ void glRotatef32i(int angle, s32 x, s32 y, s32 z);
428428
\param sizeY the vertical size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM
429429
\param empty2 not used, just here for OpenGL compatibility
430430
\param param parameters for the texture
431-
\param texture pointer to the texture data to load
431+
\param texture pointer to the texture data to load; if NULL, VRAM for the texture is allocated but the texture is not loaded yet
432432
\return 1 on success, 0 on failure*/
433433
int glTexImage2D(int target, int empty1, GL_TEXTURE_TYPE_ENUM type, int sizeX, int sizeY, int empty2, int param, const void* texture);
434434

@@ -438,7 +438,7 @@ int glTexImage2D(int target, int empty1, GL_TEXTURE_TYPE_ENUM type, int sizeX, i
438438
\param width the length of the palette (if 0, then palette is removed from currently bound texture)
439439
\param empty2 ignored, only here for OpenGL compatability
440440
\param empty3 ignored, only here for OpenGL compatability
441-
\param table pointer to the palette data to load (if NULL, then palette is removed from currently bound texture)*/
441+
\param table pointer to the palette data to load (if NULL, VRAM for the palette is allocated but the palette is not loaded yet)*/
442442
void glColorTableEXT(int target, int empty1, u16 width, int empty2, int empty3, const u16* table);
443443

444444
/*! \brief glColorSubTableEXT loads a 15-bit color format palette into a specific spot in a currently bound texture's existing palette

source/arm9/videoGL.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -739,8 +739,8 @@ void glColorTableEXT( int target, int empty1, u16 width, int empty2, int empty3,
739739
if( texture->palIndex ) // Remove prior palette if exists
740740
removePaletteFromTexture( texture );
741741

742-
// Exit if no color table or color count is 0 (helpful in emptying the palette for the active texture)
743-
if( !width || table == NULL )
742+
// Exit if color count is 0 (helpful in emptying the palette for the active texture)
743+
if( !width )
744744
return;
745745

746746
// 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,
776776
palette->connectCount = 1;
777777
palette->palSize = width << 1;
778778

779+
if( glGlob->deallocPalSize )
780+
texture->palIndex = (u32)DynamicArrayGet( &glGlob->deallocPal, glGlob->deallocPalSize-- );
781+
else
782+
texture->palIndex = glGlob->palCount++;
783+
DynamicArraySet( &glGlob->palettePtrs, texture->palIndex, (void*)palette );
784+
785+
GFX_PAL_FORMAT = palette->addr;
786+
glGlob->activePalette = texture->palIndex;
787+
788+
// allocate, but don't touch VRAM if table is NULL
789+
if ( table == NULL )
790+
return;
791+
779792
// copy straight to VRAM, and assign a palette name
780793
u32 tempVRAM = VRAM_EFG_CR;
781794
u16 *startBank = vramGetBank( (u16*)palette->vramAddr );
@@ -795,15 +808,6 @@ void glColorTableEXT( int target, int empty1, u16 width, int empty2, int empty3,
795808

796809
swiCopy( table, palette->vramAddr, width | COPY_MODE_HWORD );
797810
vramRestoreBanks_EFG( tempVRAM );
798-
799-
if( glGlob->deallocPalSize )
800-
texture->palIndex = (u32)DynamicArrayGet( &glGlob->deallocPal, glGlob->deallocPalSize-- );
801-
else
802-
texture->palIndex = glGlob->palCount++;
803-
DynamicArraySet( &glGlob->palettePtrs, texture->palIndex, (void*)palette );
804-
805-
GFX_PAL_FORMAT = palette->addr;
806-
glGlob->activePalette = texture->palIndex;
807811
} else
808812
GFX_PAL_FORMAT = glGlob->activePalette = texture->palIndex;
809813
}

0 commit comments

Comments
 (0)