Saturn: WIP textures

This commit is contained in:
UnknownShadow200 2024-06-23 17:25:02 +10:00
parent e493d80671
commit 197e440f1c

View File

@ -72,10 +72,12 @@ static GfxResourceID white_square;
void Gfx_RestoreState(void) { void Gfx_RestoreState(void) {
InitDefaultResources(); InitDefaultResources();
// 2x2 dummy white texture
struct Bitmap bmp; struct Bitmap bmp;
BitmapCol pixels[4] = { BitmapColor_RGB(255, 0, 0), BITMAPCOLOR_WHITE, BITMAPCOLOR_WHITE, BITMAPCOLOR_WHITE }; BitmapCol pixels[8 * 8];
Bitmap_Init(bmp, 2, 2, pixels); Mem_Set(pixels, 0xFF, sizeof(pixels));
pixels[0] = BitmapColor_RGB(255, 0, 0);
Bitmap_Init(bmp, 8, 8, pixels);
white_square = Gfx_CreateTexture(&bmp, 0, false); white_square = Gfx_CreateTexture(&bmp, 0, false);
} }
@ -98,8 +100,8 @@ void Gfx_Create(void) {
Gfx.MinTexWidth = 8; Gfx.MinTexWidth = 8;
Gfx.MinTexHeight = 8; Gfx.MinTexHeight = 8;
Gfx.MaxTexWidth = 128; Gfx.MaxTexWidth = 16; // 128
Gfx.MaxTexHeight = 128; Gfx.MaxTexHeight = 16; // 128
Gfx.Created = true; Gfx.Created = true;
} }
@ -114,33 +116,42 @@ void Gfx_Free(void) {
#define BGRA8_to_SATURN(src) \ #define BGRA8_to_SATURN(src) \
((src[2] & 0xF8) >> 3) | ((src[1] & 0xF8) << 2) | ((src[0] & 0xF8) << 7) | ((src[3] & 0x80) << 8) ((src[2] & 0xF8) >> 3) | ((src[1] & 0xF8) << 2) | ((src[0] & 0xF8) << 7) | ((src[3] & 0x80) << 8)
typedef struct CCTexture {
int width, height;
cc_uint16 pixels[];
} CCTexture;
static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) {
cc_uint16* tmp = Mem_TryAlloc(bmp->width * bmp->height, 2); CCTexture* tex = Mem_TryAlloc(4 + bmp->width * bmp->height, 2);
if (!tmp) return NULL; if (!tex) return NULL;
for (int y = 0; y < bmp->height; y++) for (int y = 0; y < bmp->height; y++)
{ {
cc_uint32* src = bmp->scan0 + y * rowWidth; cc_uint32* src = bmp->scan0 + y * rowWidth;
cc_uint16* dst = tmp + y * bmp->width; cc_uint16* dst = tex->pixels + y * bmp->width;
for (int x = 0; x < bmp->width; x++) for (int x = 0; x < bmp->width; x++)
{ {
cc_uint8* color = (cc_uint8*)&src[x]; cc_uint8* color = (cc_uint8*)&src[x];
dst[x] = BGRA8_to_SATURN(color); dst[x] = BGRA8_to_SATURN(color);
dst[x] = 0xFEEE; dst[x] = 0xFEEE;
} }
} }
return tex;
scu_dma_transfer(0, _vdp1_vram_partitions.texture_base, tmp, bmp->width * bmp->height * 2);
scu_dma_transfer_wait(0);
Mem_Free(tmp);
return (void*)1;
} }
void Gfx_BindTexture(GfxResourceID texId) { void Gfx_BindTexture(GfxResourceID texId) {
if (!texId) return;
CCTexture* tex = (CCTexture*)texId;
scu_dma_transfer(0, _vdp1_vram_partitions.texture_base, tex->pixels, tex->width * tex->height * 2);
scu_dma_transfer_wait(0);
} }
void Gfx_DeleteTexture(GfxResourceID* texId) { void Gfx_DeleteTexture(GfxResourceID* texId) {
CCTexture* tex = *texId;
if (tex) Mem_Free(tex);
*texId = NULL;
} }
void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, int rowWidth, cc_bool mipmaps) { void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, int rowWidth, cc_bool mipmaps) {
@ -377,18 +388,21 @@ static void DrawTexturedQuads2D(int verticesCount, int startVertex) {
vdp1_cmdt_t* cmd; vdp1_cmdt_t* cmd;
cmd = NextPrimitive(); cmd = NextPrimitive();
vdp1_cmdt_polygon_set(cmd); vdp1_cmdt_polygon_set(cmd);
vdp1_cmdt_color_set(cmd, RGB1555(1, R >> 3, G >> 3, B >> 3)); vdp1_cmdt_color_set(cmd, RGB1555(1, R >> 3, G >> 3, B >> 3));
vdp1_cmdt_draw_mode_set(cmd, color_draw_mode); vdp1_cmdt_draw_mode_set(cmd, color_draw_mode);
vdp1_cmdt_vtx_set(cmd, points); vdp1_cmdt_vtx_set(cmd, points);
/*cmd = NextPrimitive(); /*
cmd = NextPrimitive();
vdp1_cmdt_distorted_sprite_set(cmd); vdp1_cmdt_distorted_sprite_set(cmd);
vdp1_cmdt_char_size_set(cmd, 8, 8); vdp1_cmdt_char_size_set(cmd, 8, 8);
vdp1_cmdt_char_base_set(cmd, (vdp1_vram_t)_vdp1_vram_partitions.texture_base); vdp1_cmdt_char_base_set(cmd, (vdp1_vram_t)_vdp1_vram_partitions.texture_base);
vdp1_cmdt_draw_mode_set(cmd, texture_draw_mode); vdp1_cmdt_draw_mode_set(cmd, texture_draw_mode);
vdp1_cmdt_vtx_set(cmd, points);*/ vdp1_cmdt_vtx_set(cmd, points);
*/
} }
} }