Better api to get texture data

This commit is contained in:
jaburns
2020-10-12 14:08:55 -06:00
parent 8f893d6c0b
commit 20791ebcea
5 changed files with 28 additions and 38 deletions
+4 -4
View File
@@ -6,6 +6,7 @@
#include "guMtxF2L.h" #include "guMtxF2L.h"
#include "gfx_adapter.h" #include "gfx_adapter.h"
#include "gfx_adapter_commands.h" #include "gfx_adapter_commands.h"
#include "load_tex_data.h"
static Mat4 s_curMatrix; static Mat4 s_curMatrix;
static float s_curColor[3]; static float s_curColor[3];
@@ -34,8 +35,7 @@ static void convert_uv_to_atlas( float *atlas_uv_out, short tc[] )
float u = (float)((tc[0] * s_scaleS >> 16) - 8*s_uls) / 32.0f / s_texWidth; float u = (float)((tc[0] * s_scaleS >> 16) - 8*s_uls) / 32.0f / s_texWidth;
float v = (float)((tc[1] * s_scaleT >> 16) - 8*s_ult) / 32.0f / s_texHeight; float v = (float)((tc[1] * s_scaleT >> 16) - 8*s_ult) / 32.0f / s_texHeight;
// TODO define 11 (number of used textures) atlas_uv_out[0] = u * s_texWidth / 64.0f / (float)NUM_USED_TEXTURES + (float)s_textureIndex / (float)NUM_USED_TEXTURES;
atlas_uv_out[0] = u * s_texWidth / 64.0f / 11.0f + (float)s_textureIndex / 11.0f;
atlas_uv_out[1] = v * s_texHeight / 64.0f; atlas_uv_out[1] = v * s_texHeight / 64.0f;
} }
@@ -159,8 +159,8 @@ static void process_display_list( void *dl )
int64_t i = *ptr++; int64_t i = *ptr++;
s_textureIndex = (int)i; s_textureIndex = (int)i;
s_texWidth = 32.0f; s_texWidth = mario_tex_widths[s_textureIndex];
s_texHeight = 32.0f; s_texHeight = mario_tex_heights[s_textureIndex];
break; break;
} }
+3 -12
View File
@@ -76,13 +76,11 @@ static struct Area *hack_build_area( void )
return result; return result;
} }
void sm64_global_init( uint8_t *rom, uint8_t *outTexture, SM64DebugPrintFunctionPtr debugPrintFunction )
void sm64_global_init( uint8_t *rom, SM64DebugPrintFunctionPtr debugPrintFunction )
{ {
gDebugPrint = debugPrintFunction; gDebugPrint = debugPrintFunction;
load_mario_textures_from_rom( rom ); load_mario_textures_from_rom( rom, outTexture );
load_mario_anims_from_rom( rom ); load_mario_anims_from_rom( rom );
gMarioObject = hack_allocate_mario(); gMarioObject = hack_allocate_mario();
@@ -92,16 +90,9 @@ void sm64_global_init( uint8_t *rom, SM64DebugPrintFunctionPtr debugPrintFunctio
s_mario_geo_pool = alloc_only_pool_init(); s_mario_geo_pool = alloc_only_pool_init();
s_mario_graph_node = process_geo_layout( s_mario_geo_pool, mario_geo_ptr ); s_mario_graph_node = process_geo_layout( s_mario_geo_pool, mario_geo_ptr );
D_80339D10.animDmaTable = NULL; // gMarioAnimsPtr; // mario_anims_ptr; D_80339D10.animDmaTable = NULL;
D_80339D10.currentAnimAddr = NULL; D_80339D10.currentAnimAddr = NULL;
D_80339D10.targetAnim = NULL; D_80339D10.targetAnim = NULL;
//DEBUG_LOG( "Mario animations loaded from address %lu", (uint64_t)D_80339D10.animDmaTable );
}
uint8_t *sm64_get_texture( void )
{
return gLibSm64TextureRgba;
} }
void sm64_load_surfaces( uint16_t terrainType, const struct SM64Surface *surfaceArray, size_t numSurfaces ) void sm64_load_surfaces( uint16_t terrainType, const struct SM64Surface *surfaceArray, size_t numSurfaces )
+5 -4
View File
@@ -5,8 +5,6 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#define SM64_GEO_BUFFER_SIZE 9216 // 1024 triangles * 9 floats per triangle
struct SM64Surface struct SM64Surface
{ {
int16_t type; int16_t type;
@@ -41,8 +39,11 @@ struct SM64MarioGeometryBuffers
typedef void (*SM64DebugPrintFunctionPtr)( const char * ); typedef void (*SM64DebugPrintFunctionPtr)( const char * );
extern void sm64_global_init( uint8_t *rom, SM64DebugPrintFunctionPtr debugPrintFunction ); static const size_t SM64_TEXTURE_WIDTH = 64 * 11;
extern uint8_t *sm64_get_texture( void ); static const size_t SM64_TEXTURE_HEIGHT = 64;
static const size_t SM64_GEO_BUFFER_SIZE = 1024;
extern void sm64_global_init( uint8_t *rom, uint8_t *outTexture, SM64DebugPrintFunctionPtr debugPrintFunction );
extern void sm64_load_surfaces( uint16_t terrainType, const struct SM64Surface *surfaceArray, size_t numSurfaces ); extern void sm64_load_surfaces( uint16_t terrainType, const struct SM64Surface *surfaceArray, size_t numSurfaces );
extern void sm64_mario_reset( int16_t marioX, int16_t marioY, int16_t marioZ ); extern void sm64_mario_reset( int16_t marioX, int16_t marioY, int16_t marioZ );
extern void sm64_mario_tick( const struct SM64MarioInputs *inputs, struct SM64MarioState *outState, struct SM64MarioGeometryBuffers *outBuffers ); extern void sm64_mario_tick( const struct SM64MarioInputs *inputs, struct SM64MarioState *outState, struct SM64MarioGeometryBuffers *outBuffers );
+9 -16
View File
@@ -2,39 +2,32 @@
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#include "libsm64.h"
#include "tools/libmio0.h" #include "tools/libmio0.h"
#include "tools/n64graphics.h" #include "tools/n64graphics.h"
uint8_t *gLibSm64TextureRgba;
#define MARIO_TEX_ROM_OFFSET 1132368 #define MARIO_TEX_ROM_OFFSET 1132368
#define NUM_USED_TEXTURES 11
#define ATLAS_WIDTH (NUM_USED_TEXTURES * 64) #define ATLAS_WIDTH (NUM_USED_TEXTURES * 64)
#define ATLAS_HEIGHT 64 #define ATLAS_HEIGHT 64
static int mario_tex_offsets[NUM_USED_TEXTURES] = { 144, 4240, 6288, 8336, 10384, 12432, 14480, 16528, 30864, 32912, 37008 }; static void blt_image_to_atlas( rgba *img, int i, int w, int h, uint8_t *outTexture )
static int mario_tex_widths [NUM_USED_TEXTURES] = { 64, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 };
static int mario_tex_heights[NUM_USED_TEXTURES] = { 32, 32, 32, 32, 32, 32, 32, 32, 32, 64, 64 };
static void blt_image_to_atlas( rgba *img, int i, int w, int h )
{ {
for( int iy = 0; iy < h; ++iy ) for( int iy = 0; iy < h; ++iy )
for( int ix = 0; ix < w; ++ix ) for( int ix = 0; ix < w; ++ix )
{ {
int o = (ix + 64 * i) + iy * ATLAS_WIDTH; int o = (ix + 64 * i) + iy * ATLAS_WIDTH;
int q = ix + iy * w; int q = ix + iy * w;
gLibSm64TextureRgba[4*o + 0] = img[q].red; outTexture[4*o + 0] = img[q].red;
gLibSm64TextureRgba[4*o + 1] = img[q].green; outTexture[4*o + 1] = img[q].green;
gLibSm64TextureRgba[4*o + 2] = img[q].blue; outTexture[4*o + 2] = img[q].blue;
gLibSm64TextureRgba[4*o + 3] = img[q].alpha; outTexture[4*o + 3] = img[q].alpha;
} }
} }
void load_mario_textures_from_rom( uint8_t *rom ) void load_mario_textures_from_rom( uint8_t *rom, uint8_t *outTexture )
{ {
gLibSm64TextureRgba = malloc( 4 * ATLAS_WIDTH * ATLAS_HEIGHT ); memset( outTexture, 0, 4 * ATLAS_WIDTH * ATLAS_HEIGHT );
memset( gLibSm64TextureRgba, 0, 4 * ATLAS_WIDTH * ATLAS_HEIGHT );
mio0_header_t head; mio0_header_t head;
uint8_t *in_buf = rom + MARIO_TEX_ROM_OFFSET; uint8_t *in_buf = rom + MARIO_TEX_ROM_OFFSET;
@@ -47,7 +40,7 @@ void load_mario_textures_from_rom( uint8_t *rom )
{ {
uint8_t *raw = out_buf + mario_tex_offsets[i]; uint8_t *raw = out_buf + mario_tex_offsets[i];
rgba *img = raw2rgba( raw, mario_tex_widths[i], mario_tex_heights[i], 16 ); rgba *img = raw2rgba( raw, mario_tex_widths[i], mario_tex_heights[i], 16 );
blt_image_to_atlas( img, i, mario_tex_widths[i], mario_tex_heights[i] ); blt_image_to_atlas( img, i, mario_tex_widths[i], mario_tex_heights[i], outTexture );
free( img ); free( img );
} }
+7 -2
View File
@@ -25,5 +25,10 @@ enum MarioTextures
mario_texture_eyes_down mario_texture_eyes_down
}; };
extern uint8_t *gLibSm64TextureRgba; #define NUM_USED_TEXTURES 11
extern void load_mario_textures_from_rom( uint8_t *rom );
static int mario_tex_offsets[NUM_USED_TEXTURES] = { 144, 4240, 6288, 8336, 10384, 12432, 14480, 16528, 30864, 32912, 37008 };
static int mario_tex_widths [NUM_USED_TEXTURES] = { 64, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 };
static int mario_tex_heights[NUM_USED_TEXTURES] = { 32, 32, 32, 32, 32, 32, 32, 32, 32, 64, 64 };
extern void load_mario_textures_from_rom( uint8_t *rom, uint8_t *outTexture );