Saturn: Copying textures to VRAM partially works

This commit is contained in:
UnknownShadow200 2024-06-23 17:52:01 +10:00
parent 197e440f1c
commit c34ceeab92

View File

@ -26,6 +26,8 @@ static PackedCol clear_color;
static vdp1_cmdt_t cmdts_all[CMDS_COUNT];
static int cmdts_count;
static vdp1_vram_partitions_t _vdp1_vram_partitions;
static void* tex_vram_addr;
static void* tex_vram_cur;
static vdp1_cmdt_t* NextPrimitive(void) {
if (cmdts_count >= CMDS_COUNT) Logger_Abort("Too many VDP1 commands");
@ -94,14 +96,17 @@ void Gfx_Create(void) {
RGB1555(1, 0, 3, 15));
vdp2_sprite_priority_set(0, 6);
tex_vram_addr = _vdp1_vram_partitions.texture_base;
tex_vram_cur = _vdp1_vram_partitions.texture_base;
UpdateVDP1Env();
CalcGouraudColours();
}
Gfx.MinTexWidth = 8;
Gfx.MinTexHeight = 8;
Gfx.MaxTexWidth = 16; // 128
Gfx.MaxTexHeight = 16; // 128
Gfx.MaxTexWidth = 8; // 128
Gfx.MaxTexHeight = 8; // 128
Gfx.Created = true;
}
@ -118,40 +123,53 @@ void Gfx_Free(void) {
typedef struct CCTexture {
int width, height;
cc_uint16 pixels[];
void* addr;
} CCTexture;
static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) {
CCTexture* tex = Mem_TryAlloc(4 + bmp->width * bmp->height, 2);
CCTexture* tex = Mem_TryAlloc(1, sizeof(CCTexture));
if (!tex) return NULL;
cc_uint16* tmp = Mem_TryAlloc(bmp->width * bmp->height, 2);
if (!tmp) return NULL;
cc_uintptr addr = tex_vram_addr;
tex->addr = tex_vram_addr;
tex->width = bmp->width;
tex->height = bmp->height;
tex_vram_addr += tex->width * tex->height * 2;
for (int y = 0; y < bmp->height; y++)
{
cc_uint32* src = bmp->scan0 + y * rowWidth;
cc_uint16* dst = tex->pixels + y * bmp->width;
cc_uint32* src = bmp->scan0 + y * rowWidth;
cc_uint16* dst = tmp + y * bmp->width;
for (int x = 0; x < bmp->width; x++)
{
cc_uint8* color = (cc_uint8*)&src[x];
dst[x] = BGRA8_to_SATURN(color);
dst[x] = 0xFEEE;
dst[x] = 0xFEDD;
}
}
scu_dma_transfer(0, tex->addr, tmp, tex->width * tex->height * 2);
scu_dma_transfer_wait(0);
return tex;
}
void Gfx_BindTexture(GfxResourceID texId) {
if (!texId) return;
if (!texId) texId = white_square;
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);
tex_vram_cur = tex->addr;
}
void Gfx_DeleteTexture(GfxResourceID* texId) {
CCTexture* tex = *texId;
if (tex) Mem_Free(tex);
*texId = NULL;
// TODO free vram ???
}
void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, int rowWidth, cc_bool mipmaps) {
@ -399,7 +417,7 @@ static void DrawTexturedQuads2D(int verticesCount, int startVertex) {
cmd = NextPrimitive();
vdp1_cmdt_distorted_sprite_set(cmd);
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)tex_vram_cur);
vdp1_cmdt_draw_mode_set(cmd, texture_draw_mode);
vdp1_cmdt_vtx_set(cmd, points);
*/
@ -470,18 +488,19 @@ static void DrawTexturedQuads3D(int verticesCount, int startVertex) {
vdp1_cmdt_t* cmd;
/*
cmd = NextPrimitive();
vdp1_cmdt_polygon_set(cmd);
vdp1_cmdt_color_set(cmd, RGB1555(1, R >> 3, G >> 3, B >> 3));
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_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)tex_vram_cur);
vdp1_cmdt_draw_mode_set(cmd, texture_draw_mode);
vdp1_cmdt_vtx_set(cmd, points);*/
vdp1_cmdt_vtx_set(cmd, points);
}
}