Skip to content

Commit

Permalink
Let glColorTableEXT allocate placeholder VRAM (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-sloth authored Nov 27, 2024
1 parent bedf615 commit 6194b32
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions include/nds/arm9/videoGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down
26 changes: 15 additions & 11 deletions source/arm9/videoGL.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand All @@ -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;
}
Expand Down

0 comments on commit 6194b32

Please sign in to comment.