Revert "port: change the loaded_texture system yet again; fix a couple crashes"
This reverts commit 6750bd9422.
This commit is contained in:
parent
76ed7f180e
commit
38343bfbf1
|
|
@ -32,6 +32,7 @@
|
|||
#include "gfx_screen_config.h"
|
||||
|
||||
uintptr_t gfxFramebuffer;
|
||||
std::stack<std::string> currentDir;
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
|
@ -141,15 +142,6 @@ struct RawTexMetadata {
|
|||
float h_byte_scale = 1, v_pixel_scale = 1;
|
||||
};
|
||||
|
||||
struct LoadedTexture {
|
||||
const uint8_t* addr;
|
||||
uint32_t orig_size_bytes;
|
||||
uint32_t full_size_bytes; // full_image_line_size_bytes * height
|
||||
uint32_t size_bytes; // line_size_bytes * height
|
||||
uint32_t full_image_line_size_bytes;
|
||||
uint32_t line_size_bytes;
|
||||
};
|
||||
|
||||
static struct RDP {
|
||||
uint16_t palette[256];
|
||||
const uint8_t* palette_addrs[2];
|
||||
|
|
@ -161,7 +153,18 @@ static struct RDP {
|
|||
uint32_t tex_flags;
|
||||
struct RawTexMetadata raw_tex_metadata;
|
||||
} texture_to_load;
|
||||
std::unordered_map<uint16_t, LoadedTexture> loaded_texture;
|
||||
struct {
|
||||
const uint8_t* addr;
|
||||
uint32_t orig_size_bytes;
|
||||
uint32_t full_size_bytes; // full_image_line_size_bytes * height
|
||||
uint32_t size_bytes; // line_size_bytes * height
|
||||
uint32_t full_image_line_size_bytes;
|
||||
uint32_t line_size_bytes;
|
||||
uint32_t tex_flags;
|
||||
struct RawTexMetadata raw_tex_metadata;
|
||||
bool masked;
|
||||
bool blended;
|
||||
} loaded_texture[3];
|
||||
struct {
|
||||
uint8_t fmt;
|
||||
uint8_t siz;
|
||||
|
|
@ -172,6 +175,7 @@ static struct RDP {
|
|||
uint16_t tmem; // 0-511, in 64-bit word units
|
||||
uint32_t line_size_bytes;
|
||||
uint8_t palette;
|
||||
uint8_t tmem_index; // 0 or 1 for offset 0 kB or offset 2 kB, respectively; 2 if this is a mip
|
||||
uint8_t level;
|
||||
} texture_tile[8];
|
||||
bool textures_changed[2];
|
||||
|
|
@ -567,14 +571,14 @@ static void gfx_texture_cache_delete(const uint8_t* orig_addr) {
|
|||
}
|
||||
}
|
||||
|
||||
static void import_texture_rgba16(int tile, const LoadedTexture& loaded_texture) {
|
||||
const uint8_t* addr = loaded_texture.addr;
|
||||
const uint32_t size_bytes = loaded_texture.size_bytes;
|
||||
const uint32_t full_image_line_size_bytes = loaded_texture.full_image_line_size_bytes;
|
||||
const uint32_t line_size_bytes = loaded_texture.line_size_bytes;
|
||||
// SUPPORT_CHECK(full_image_line_size_bytes == line_size_bytes);
|
||||
// TODO: this trips in some places with a garbage size in full_image_line_size_bytes
|
||||
// probably wherever framebuffer effects are used
|
||||
static void import_texture_rgba16(int tile, bool importReplacement) {
|
||||
const RawTexMetadata* metadata = &rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].raw_tex_metadata;
|
||||
const uint8_t* addr = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].addr;
|
||||
const uint32_t size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].size_bytes;
|
||||
const uint32_t full_image_line_size_bytes =
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].full_image_line_size_bytes;
|
||||
const uint32_t line_size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].line_size_bytes;
|
||||
SUPPORT_CHECK(full_image_line_size_bytes == line_size_bytes);
|
||||
|
||||
uint8_t *dest = tex_upload_buffer;
|
||||
for (uint32_t i = 0; i < size_bytes / 2; i++, dest += 4) {
|
||||
|
|
@ -593,15 +597,16 @@ static void import_texture_rgba16(int tile, const LoadedTexture& loaded_texture)
|
|||
const uint32_t height = size_bytes / rdp.texture_tile[tile].line_size_bytes;
|
||||
|
||||
gfx_rapi->upload_texture(tex_upload_buffer, width, height);
|
||||
// DumpTexture(loaded_texture.otr_path, rgba32_buf, width, height);
|
||||
// DumpTexture(rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path, rgba32_buf, width, height);
|
||||
}
|
||||
|
||||
static void import_texture_rgba32(int tile, const LoadedTexture& loaded_texture) {
|
||||
const uint8_t* addr = loaded_texture.addr;
|
||||
const uint32_t size_bytes = loaded_texture.size_bytes;
|
||||
static void import_texture_rgba32(int tile, bool importReplacement) {
|
||||
const RawTexMetadata* metadata = &rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].raw_tex_metadata;
|
||||
const uint8_t* addr = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].addr;
|
||||
const uint32_t size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].size_bytes;
|
||||
const uint32_t full_image_line_size_bytes =
|
||||
loaded_texture.full_image_line_size_bytes;
|
||||
const uint32_t line_size_bytes = loaded_texture.line_size_bytes;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].full_image_line_size_bytes;
|
||||
const uint32_t line_size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].line_size_bytes;
|
||||
SUPPORT_CHECK(full_image_line_size_bytes == line_size_bytes);
|
||||
|
||||
uint32_t *dest = (uint32_t *)tex_upload_buffer;
|
||||
|
|
@ -613,15 +618,16 @@ static void import_texture_rgba32(int tile, const LoadedTexture& loaded_texture)
|
|||
const uint32_t width = rdp.texture_tile[tile].line_size_bytes / 2;
|
||||
const uint32_t height = (size_bytes / 2) / rdp.texture_tile[tile].line_size_bytes;
|
||||
gfx_rapi->upload_texture(tex_upload_buffer, width, height);
|
||||
// DumpTexture(loaded_texture.otr_path, addr, width, height);
|
||||
// DumpTexture(rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path, addr, width, height);
|
||||
}
|
||||
|
||||
static void import_texture_ia4(int tile, const LoadedTexture& loaded_texture) {
|
||||
const uint8_t* addr = loaded_texture.addr;
|
||||
const uint32_t size_bytes = loaded_texture.size_bytes;
|
||||
static void import_texture_ia4(int tile, bool importReplacement) {
|
||||
const RawTexMetadata* metadata = &rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].raw_tex_metadata;
|
||||
const uint8_t* addr = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].addr;
|
||||
const uint32_t size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].size_bytes;
|
||||
const uint32_t full_image_line_size_bytes =
|
||||
loaded_texture.full_image_line_size_bytes;
|
||||
const uint32_t line_size_bytes = loaded_texture.line_size_bytes;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].full_image_line_size_bytes;
|
||||
const uint32_t line_size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].line_size_bytes;
|
||||
SUPPORT_CHECK(full_image_line_size_bytes == line_size_bytes);
|
||||
|
||||
uint8_t *dest = tex_upload_buffer;
|
||||
|
|
@ -641,15 +647,16 @@ static void import_texture_ia4(int tile, const LoadedTexture& loaded_texture) {
|
|||
const uint32_t height = size_bytes / rdp.texture_tile[tile].line_size_bytes;
|
||||
|
||||
gfx_rapi->upload_texture(tex_upload_buffer, width, height);
|
||||
// DumpTexture(loaded_texture.otr_path, rgba32_buf, width, height);
|
||||
// DumpTexture(rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path, rgba32_buf, width, height);
|
||||
}
|
||||
|
||||
static void import_texture_ia8(int tile, const LoadedTexture& loaded_texture) {
|
||||
const uint8_t* addr = loaded_texture.addr;
|
||||
const uint32_t size_bytes = loaded_texture.size_bytes;
|
||||
static void import_texture_ia8(int tile, bool importReplacement) {
|
||||
const RawTexMetadata* metadata = &rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].raw_tex_metadata;
|
||||
const uint8_t* addr = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].addr;
|
||||
const uint32_t size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].size_bytes;
|
||||
const uint32_t full_image_line_size_bytes =
|
||||
loaded_texture.full_image_line_size_bytes;
|
||||
const uint32_t line_size_bytes = loaded_texture.line_size_bytes;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].full_image_line_size_bytes;
|
||||
const uint32_t line_size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].line_size_bytes;
|
||||
SUPPORT_CHECK(full_image_line_size_bytes == line_size_bytes);
|
||||
|
||||
uint8_t *dest = tex_upload_buffer;
|
||||
|
|
@ -666,15 +673,16 @@ static void import_texture_ia8(int tile, const LoadedTexture& loaded_texture) {
|
|||
const uint32_t height = size_bytes / rdp.texture_tile[tile].line_size_bytes;
|
||||
|
||||
gfx_rapi->upload_texture(tex_upload_buffer, width, height);
|
||||
// DumpTexture(loaded_texture.otr_path, rgba32_buf, width, height);
|
||||
// DumpTexture(rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path, rgba32_buf, width, height);
|
||||
}
|
||||
|
||||
static void import_texture_ia16(int tile, const LoadedTexture& loaded_texture) {
|
||||
const uint8_t* addr = loaded_texture.addr;
|
||||
const uint32_t size_bytes = loaded_texture.size_bytes;
|
||||
static void import_texture_ia16(int tile, bool importReplacement) {
|
||||
const RawTexMetadata* metadata = &rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].raw_tex_metadata;
|
||||
const uint8_t* addr = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].addr;
|
||||
const uint32_t size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].size_bytes;
|
||||
const uint32_t full_image_line_size_bytes =
|
||||
loaded_texture.full_image_line_size_bytes;
|
||||
const uint32_t line_size_bytes = loaded_texture.line_size_bytes;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].full_image_line_size_bytes;
|
||||
const uint32_t line_size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].line_size_bytes;
|
||||
SUPPORT_CHECK(full_image_line_size_bytes == line_size_bytes);
|
||||
|
||||
uint8_t *dest = tex_upload_buffer;
|
||||
|
|
@ -691,15 +699,16 @@ static void import_texture_ia16(int tile, const LoadedTexture& loaded_texture) {
|
|||
const uint32_t height = size_bytes / rdp.texture_tile[tile].line_size_bytes;
|
||||
|
||||
gfx_rapi->upload_texture(tex_upload_buffer, width, height);
|
||||
// DumpTexture(loaded_texture.otr_path, rgba32_buf, width, height);
|
||||
// DumpTexture(rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path, rgba32_buf, width, height);
|
||||
}
|
||||
|
||||
static void import_texture_i4(int tile, const LoadedTexture& loaded_texture) {
|
||||
const uint8_t* addr = loaded_texture.addr;
|
||||
const uint32_t size_bytes = loaded_texture.size_bytes;
|
||||
static void import_texture_i4(int tile, bool importReplacement) {
|
||||
const RawTexMetadata* metadata = &rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].raw_tex_metadata;
|
||||
const uint8_t* addr = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].addr;
|
||||
const uint32_t size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].size_bytes;
|
||||
const uint32_t full_image_line_size_bytes =
|
||||
loaded_texture.full_image_line_size_bytes;
|
||||
const uint32_t line_size_bytes = loaded_texture.line_size_bytes;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].full_image_line_size_bytes;
|
||||
const uint32_t line_size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].line_size_bytes;
|
||||
SUPPORT_CHECK(full_image_line_size_bytes == line_size_bytes);
|
||||
|
||||
uint8_t *dest = tex_upload_buffer;
|
||||
|
|
@ -717,15 +726,16 @@ static void import_texture_i4(int tile, const LoadedTexture& loaded_texture) {
|
|||
const uint32_t height = size_bytes / rdp.texture_tile[tile].line_size_bytes;
|
||||
|
||||
gfx_rapi->upload_texture(tex_upload_buffer, width, height);
|
||||
// DumpTexture(loaded_texture.otr_path, rgba32_buf, width, height);
|
||||
// DumpTexture(rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path, rgba32_buf, width, height);
|
||||
}
|
||||
|
||||
static void import_texture_i8(int tile, const LoadedTexture& loaded_texture) {
|
||||
const uint8_t* addr = loaded_texture.addr;
|
||||
const uint32_t size_bytes = loaded_texture.size_bytes;
|
||||
static void import_texture_i8(int tile, bool importReplacement) {
|
||||
const RawTexMetadata* metadata = &rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].raw_tex_metadata;
|
||||
const uint8_t* addr = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].addr;
|
||||
const uint32_t size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].size_bytes;
|
||||
uint32_t full_image_line_size_bytes =
|
||||
loaded_texture.full_image_line_size_bytes;
|
||||
const uint32_t line_size_bytes = loaded_texture.line_size_bytes;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].full_image_line_size_bytes;
|
||||
const uint32_t line_size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].line_size_bytes;
|
||||
SUPPORT_CHECK(full_image_line_size_bytes == line_size_bytes);
|
||||
|
||||
uint8_t *dest = tex_upload_buffer;
|
||||
|
|
@ -741,7 +751,7 @@ static void import_texture_i8(int tile, const LoadedTexture& loaded_texture) {
|
|||
const uint32_t height = size_bytes / rdp.texture_tile[tile].line_size_bytes;
|
||||
|
||||
gfx_rapi->upload_texture(tex_upload_buffer, width, height);
|
||||
// DumpTexture(loaded_texture.otr_path, rgba32_buf, width, height);
|
||||
// DumpTexture(rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path, rgba32_buf, width, height);
|
||||
}
|
||||
|
||||
static inline void palette_to_rgba32(const uint16_t palentry, uint8_t *rgba32_buf) {
|
||||
|
|
@ -765,12 +775,13 @@ static inline void palette_to_rgba32(const uint16_t palentry, uint8_t *rgba32_bu
|
|||
}
|
||||
}
|
||||
|
||||
static void import_texture_ci4(int tile, const LoadedTexture& loaded_texture) {
|
||||
const uint8_t* addr = loaded_texture.addr;
|
||||
const uint32_t size_bytes = loaded_texture.size_bytes;
|
||||
static void import_texture_ci4(int tile, bool importReplacement) {
|
||||
const RawTexMetadata* metadata = &rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].raw_tex_metadata;
|
||||
const uint8_t* addr = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].addr;
|
||||
const uint32_t size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].size_bytes;
|
||||
const uint32_t full_image_line_size_bytes =
|
||||
loaded_texture.full_image_line_size_bytes;
|
||||
const uint32_t line_size_bytes = loaded_texture.line_size_bytes;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].full_image_line_size_bytes;
|
||||
const uint32_t line_size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].line_size_bytes;
|
||||
const uint32_t pal_idx = rdp.texture_tile[tile].palette; // 0-15
|
||||
const uint16_t* palette = (const uint16_t *)(rdp.palette + pal_idx * 16); // 16 pixel entries, 16 bits each
|
||||
SUPPORT_CHECK(full_image_line_size_bytes == line_size_bytes);
|
||||
|
|
@ -782,18 +793,23 @@ static void import_texture_ci4(int tile, const LoadedTexture& loaded_texture) {
|
|||
}
|
||||
|
||||
uint32_t result_line_size = rdp.texture_tile[tile].line_size_bytes;
|
||||
if (metadata->h_byte_scale != 1) {
|
||||
result_line_size *= metadata->h_byte_scale;
|
||||
}
|
||||
|
||||
const uint32_t width = result_line_size * 2;
|
||||
const uint32_t height = size_bytes / result_line_size;
|
||||
|
||||
gfx_rapi->upload_texture(tex_upload_buffer, width, height);
|
||||
}
|
||||
|
||||
static void import_texture_ci8(int tile, const LoadedTexture& loaded_texture) {
|
||||
const uint8_t* addr = loaded_texture.addr;
|
||||
const uint32_t size_bytes = loaded_texture.size_bytes;
|
||||
static void import_texture_ci8(int tile, bool importReplacement) {
|
||||
const RawTexMetadata* metadata = &rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].raw_tex_metadata;
|
||||
const uint8_t* addr = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].addr;
|
||||
const uint32_t size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].size_bytes;
|
||||
const uint32_t full_image_line_size_bytes =
|
||||
loaded_texture.full_image_line_size_bytes;
|
||||
const uint32_t line_size_bytes = loaded_texture.line_size_bytes;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].full_image_line_size_bytes;
|
||||
const uint32_t line_size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].line_size_bytes;
|
||||
|
||||
for (uint32_t i = 0, j = 0; i < size_bytes; j += full_image_line_size_bytes - line_size_bytes) {
|
||||
for (uint32_t k = 0; k < line_size_bytes; i++, k++, j++) {
|
||||
|
|
@ -803,31 +819,36 @@ static void import_texture_ci8(int tile, const LoadedTexture& loaded_texture) {
|
|||
}
|
||||
|
||||
uint32_t result_line_size = rdp.texture_tile[tile].line_size_bytes;
|
||||
if (metadata->h_byte_scale != 1) {
|
||||
result_line_size *= metadata->h_byte_scale;
|
||||
}
|
||||
|
||||
const uint32_t width = result_line_size;
|
||||
const uint32_t height = size_bytes / result_line_size;
|
||||
|
||||
gfx_rapi->upload_texture(tex_upload_buffer, width, height);
|
||||
// DumpTexture(loaded_texture.otr_path, rgba32_buf, width, height);
|
||||
// DumpTexture(rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].otr_path, rgba32_buf, width, height);
|
||||
}
|
||||
|
||||
static void import_texture(int i, int tile, bool importReplacement) {
|
||||
const uint8_t fmt = rdp.texture_tile[tile].fmt;
|
||||
const uint8_t siz = rdp.texture_tile[tile].siz;
|
||||
const uint32_t tmem_index = rdp.texture_tile[tile].tmem;
|
||||
const uint32_t texFlags = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].tex_flags;
|
||||
const uint32_t tmem_index = rdp.texture_tile[tile].tmem_index;
|
||||
const uint8_t palette_index = rdp.texture_tile[tile].palette;
|
||||
LoadedTexture& loaded_texture = rdp.loaded_texture[tmem_index];
|
||||
|
||||
if (rdp.tex_lod && tile == rdp.first_tile_index) {
|
||||
// set up miplevel 0
|
||||
loaded_texture.line_size_bytes = rdp.texture_tile[tile].line_size_bytes;
|
||||
loaded_texture.full_image_line_size_bytes = rdp.texture_tile[tile].line_size_bytes;
|
||||
loaded_texture.full_size_bytes = loaded_texture.full_image_line_size_bytes * rdp.texture_tile[tile].height;
|
||||
loaded_texture.size_bytes = loaded_texture.line_size_bytes * rdp.texture_tile[tile].height;
|
||||
loaded_texture.orig_size_bytes = loaded_texture.size_bytes;
|
||||
loaded_texture.addr = rdp.texture_to_load.addr;
|
||||
rdp.loaded_texture[tmem_index].line_size_bytes = rdp.texture_tile[tile].line_size_bytes;
|
||||
rdp.loaded_texture[tmem_index].full_image_line_size_bytes = rdp.texture_tile[tile].line_size_bytes;
|
||||
rdp.loaded_texture[tmem_index].full_size_bytes = rdp.loaded_texture[tmem_index].full_image_line_size_bytes * rdp.texture_tile[tile].height;
|
||||
rdp.loaded_texture[tmem_index].size_bytes = rdp.loaded_texture[tmem_index].line_size_bytes * rdp.texture_tile[tile].height;
|
||||
rdp.loaded_texture[tmem_index].orig_size_bytes = rdp.loaded_texture[tmem_index].size_bytes;
|
||||
rdp.loaded_texture[tmem_index].addr = rdp.texture_to_load.addr;
|
||||
}
|
||||
|
||||
const uint8_t* orig_addr = loaded_texture.addr;
|
||||
const RawTexMetadata* metadata = &rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].raw_tex_metadata;
|
||||
const uint8_t* orig_addr = rdp.loaded_texture[tmem_index].addr;
|
||||
SUPPORT_CHECK(orig_addr);
|
||||
|
||||
TextureCacheKey key;
|
||||
|
|
@ -843,35 +864,35 @@ static void import_texture(int i, int tile, bool importReplacement) {
|
|||
|
||||
if (fmt == G_IM_FMT_RGBA) {
|
||||
if (siz == G_IM_SIZ_16b) {
|
||||
import_texture_rgba16(tile, loaded_texture);
|
||||
import_texture_rgba16(tile, importReplacement);
|
||||
} else if (siz == G_IM_SIZ_32b) {
|
||||
import_texture_rgba32(tile, loaded_texture);
|
||||
import_texture_rgba32(tile, importReplacement);
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
} else if (fmt == G_IM_FMT_IA) {
|
||||
if (siz == G_IM_SIZ_4b) {
|
||||
import_texture_ia4(tile, loaded_texture);
|
||||
import_texture_ia4(tile, importReplacement);
|
||||
} else if (siz == G_IM_SIZ_8b) {
|
||||
import_texture_ia8(tile, loaded_texture);
|
||||
import_texture_ia8(tile, importReplacement);
|
||||
} else if (siz == G_IM_SIZ_16b) {
|
||||
import_texture_ia16(tile, loaded_texture);
|
||||
import_texture_ia16(tile, importReplacement);
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
} else if (fmt == G_IM_FMT_CI) {
|
||||
if (siz == G_IM_SIZ_4b) {
|
||||
import_texture_ci4(tile, loaded_texture);
|
||||
import_texture_ci4(tile, importReplacement);
|
||||
} else if (siz == G_IM_SIZ_8b) {
|
||||
import_texture_ci8(tile, loaded_texture);
|
||||
import_texture_ci8(tile, importReplacement);
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
} else if (fmt == G_IM_FMT_I) {
|
||||
if (siz == G_IM_SIZ_4b) {
|
||||
import_texture_i4(tile, loaded_texture);
|
||||
import_texture_i4(tile, importReplacement);
|
||||
} else if (siz == G_IM_SIZ_8b) {
|
||||
import_texture_i8(tile, loaded_texture);
|
||||
import_texture_i8(tile, importReplacement);
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
|
|
@ -1272,6 +1293,18 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo
|
|||
if (use_grayscale) {
|
||||
cc_options |= (uint64_t)SHADER_OPT_GRAYSCALE;
|
||||
}
|
||||
if (rdp.loaded_texture[0].masked) {
|
||||
cc_options |= (uint64_t)SHADER_OPT_TEXEL0_MASK;
|
||||
}
|
||||
if (rdp.loaded_texture[1].masked) {
|
||||
cc_options |= (uint64_t)SHADER_OPT_TEXEL1_MASK;
|
||||
}
|
||||
if (rdp.loaded_texture[0].blended) {
|
||||
cc_options |= (uint64_t)SHADER_OPT_TEXEL0_BLEND;
|
||||
}
|
||||
if (rdp.loaded_texture[1].blended) {
|
||||
cc_options |= (uint64_t)SHADER_OPT_TEXEL1_BLEND;
|
||||
}
|
||||
|
||||
// If we are not using alpha, clear the alpha components of the combiner as they have no effect
|
||||
if (!use_alpha) {
|
||||
|
|
@ -1300,7 +1333,7 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo
|
|||
uint8_t cms = rdp.texture_tile[tile].cms;
|
||||
uint8_t cmt = rdp.texture_tile[tile].cmt;
|
||||
|
||||
uint32_t tex_size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem].orig_size_bytes;
|
||||
uint32_t tex_size_bytes = rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].orig_size_bytes;
|
||||
uint32_t line_size = rdp.texture_tile[tile].line_size_bytes;
|
||||
|
||||
if (line_size == 0) {
|
||||
|
|
@ -1766,10 +1799,6 @@ static void gfx_dp_set_tile(uint8_t fmt, uint32_t siz, uint32_t line, uint32_t t
|
|||
if (fmt == G_IM_FMT_RGBA && siz < G_IM_SIZ_16b) {
|
||||
// HACK: sometimes the game will submit G_IM_FMT_RGBA, G_IM_SIZ_8b/4b, intending it to read as I8/I4
|
||||
fmt = G_IM_FMT_I;
|
||||
} else if (fmt == G_IM_FMT_IA && siz == G_IM_SIZ_32b) {
|
||||
// HACK: ... and sometimes it submits this, apparently intending it to be I8
|
||||
fmt = G_IM_FMT_I;
|
||||
siz = G_IM_SIZ_8b;
|
||||
}
|
||||
|
||||
rdp.texture_tile[tile].palette = palette; // palette should set upper 4 bits of color index in 4b mode
|
||||
|
|
@ -1789,6 +1818,11 @@ static void gfx_dp_set_tile(uint8_t fmt, uint32_t siz, uint32_t line, uint32_t t
|
|||
const int max_lod = rdp.texture_tile[rdp.first_tile_index].level;
|
||||
const int this_lod = tile - rdp.first_tile_index;
|
||||
rdp.texture_tile[tile].tmem = tmem;
|
||||
if (max_lod && this_lod > 0 && this_lod <= max_lod) {
|
||||
rdp.texture_tile[tile].tmem_index = 2; // a mip for rdp.first_tile_index
|
||||
} else {
|
||||
rdp.texture_tile[tile].tmem_index = (tmem != 0);
|
||||
}
|
||||
rdp.textures_changed[0] = true;
|
||||
rdp.textures_changed[1] = true;
|
||||
}
|
||||
|
|
@ -1854,14 +1888,18 @@ static void gfx_dp_load_block(uint8_t tile, uint32_t uls, uint32_t ult, uint32_t
|
|||
size_bytes *= rdp.texture_to_load.raw_tex_metadata.h_byte_scale;
|
||||
size_bytes *= rdp.texture_to_load.raw_tex_metadata.v_pixel_scale;
|
||||
}
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].orig_size_bytes = orig_size_bytes;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].size_bytes = size_bytes;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].full_size_bytes = size_bytes;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].line_size_bytes = size_bytes;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].full_image_line_size_bytes = size_bytes;
|
||||
// assert(size_bytes <= 4096 && "bug: too big texture");
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].tex_flags = rdp.texture_to_load.tex_flags;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].raw_tex_metadata = rdp.texture_to_load.raw_tex_metadata;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].addr = rdp.texture_to_load.addr;
|
||||
|
||||
LoadedTexture& loaded_texture = rdp.loaded_texture[rdp.texture_tile[tile].tmem];
|
||||
loaded_texture.orig_size_bytes = orig_size_bytes;
|
||||
loaded_texture.size_bytes = size_bytes;
|
||||
loaded_texture.full_size_bytes = size_bytes;
|
||||
loaded_texture.line_size_bytes = size_bytes;
|
||||
loaded_texture.full_image_line_size_bytes = size_bytes;
|
||||
loaded_texture.addr = rdp.texture_to_load.addr;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].masked = false;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].blended = false;
|
||||
|
||||
// LoadBlock will probably affect both textures
|
||||
rdp.textures_changed[0] = rdp.textures_changed[1] = true;
|
||||
|
|
@ -1894,13 +1932,19 @@ static void gfx_dp_load_tile(uint8_t tile, uint32_t uls, uint32_t ult, uint32_t
|
|||
tile_line_size_bytes *= h_byte_scale;
|
||||
}
|
||||
|
||||
LoadedTexture& loaded_texture = rdp.loaded_texture[rdp.texture_tile[tile].tmem];
|
||||
loaded_texture.orig_size_bytes = orig_size_bytes;
|
||||
loaded_texture.size_bytes = size_bytes;
|
||||
loaded_texture.full_size_bytes = full_image_line_size_bytes * tile_height;
|
||||
loaded_texture.full_image_line_size_bytes = full_image_line_size_bytes;
|
||||
loaded_texture.line_size_bytes = tile_line_size_bytes;
|
||||
loaded_texture.addr = rdp.texture_to_load.addr + start_offset_bytes;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].orig_size_bytes = orig_size_bytes;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].size_bytes = size_bytes;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].full_size_bytes = full_image_line_size_bytes * tile_height;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].full_image_line_size_bytes = full_image_line_size_bytes;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].line_size_bytes = tile_line_size_bytes;
|
||||
|
||||
// assert(size_bytes <= 4096 && "bug: too big texture");
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].tex_flags = rdp.texture_to_load.tex_flags;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].raw_tex_metadata = rdp.texture_to_load.raw_tex_metadata;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].addr = rdp.texture_to_load.addr + start_offset_bytes;
|
||||
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].masked = false;
|
||||
rdp.loaded_texture[rdp.texture_tile[tile].tmem_index].blended = false;
|
||||
|
||||
rdp.texture_tile[tile].uls = uls;
|
||||
rdp.texture_tile[tile].ult = ult;
|
||||
|
|
@ -1909,10 +1953,10 @@ static void gfx_dp_load_tile(uint8_t tile, uint32_t uls, uint32_t ult, uint32_t
|
|||
rdp.texture_tile[tile].width = ((lrs - uls) >> G_TEXTURE_IMAGE_FRAC) + 1;
|
||||
rdp.texture_tile[tile].height = ((lrt - ult) >> G_TEXTURE_IMAGE_FRAC) + 1;
|
||||
|
||||
if (rdp.tex_lod) {
|
||||
if (rdp.texture_tile[tile].tmem_index == 2) {
|
||||
rdp.textures_changed[0] = rdp.textures_changed[1] = true;
|
||||
} else {
|
||||
rdp.textures_changed[rdp.texture_tile[tile].tmem != 0] = true;
|
||||
rdp.textures_changed[rdp.texture_tile[tile].tmem_index] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2621,6 +2665,7 @@ extern "C" void gfx_run(Gfx* commands) {
|
|||
gfx_run_dl(commands);
|
||||
gfx_flush();
|
||||
gfxFramebuffer = 0;
|
||||
currentDir = std::stack<std::string>();
|
||||
|
||||
if (game_renders_to_framebuffer) {
|
||||
gfx_rapi->start_draw_to_framebuffer(0, 1);
|
||||
|
|
|
|||
Loading…
Reference in New Issue