gl: fully recreate opengl texture when loading a custom one

Regenerate texID and call glTexStorage2D when loading a custom texture
(GL 4.2+, GLES3).
rend: missing old_vqtexture_hash in move constructor.
This commit is contained in:
Flyinghead 2024-03-14 12:56:11 +01:00
parent de89d8cfed
commit 3ffb09ec72
3 changed files with 17 additions and 6 deletions

View File

@ -592,6 +592,7 @@ public:
Updates = other.Updates; Updates = other.Updates;
palette_hash = other.palette_hash; palette_hash = other.palette_hash;
texture_hash = other.texture_hash; texture_hash = other.texture_hash;
old_vqtexture_hash = other.old_vqtexture_hash;
old_texture_hash = other.old_texture_hash; old_texture_hash = other.old_texture_hash;
std::swap(custom_image_data, other.custom_image_data); std::swap(custom_image_data, other.custom_image_data);
custom_width = other.custom_width; custom_width = other.custom_width;

View File

@ -452,13 +452,13 @@ extern struct ShaderUniforms_t
class TextureCacheData final : public BaseTextureCacheData class TextureCacheData final : public BaseTextureCacheData
{ {
public: public:
TextureCacheData(TSP tsp, TCW tcw) : BaseTextureCacheData(tsp, tcw), texID(glcache.GenTexture()) { TextureCacheData(TSP tsp, TCW tcw) : BaseTextureCacheData(tsp, tcw) {
} }
TextureCacheData(TextureCacheData&& other) : BaseTextureCacheData(std::move(other)) { TextureCacheData(TextureCacheData&& other) : BaseTextureCacheData(std::move(other)) {
std::swap(texID, other.texID); std::swap(texID, other.texID);
} }
GLuint texID; //gl texture GLuint texID = 0; //gl texture
std::string GetId() override { return std::to_string(texID); } std::string GetId() override { return std::to_string(texID); }
void UploadToGPU(int width, int height, const u8 *temp_tex_buffer, bool mipmapped, bool mipmapsIncluded = false) override; void UploadToGPU(int width, int height, const u8 *temp_tex_buffer, bool mipmapped, bool mipmapsIncluded = false) override;
bool Delete() override; bool Delete() override;

View File

@ -46,6 +46,8 @@ static void getOpenGLTexParams(TextureType texType, u32& bytesPerPixel, GLuint&
void TextureCacheData::UploadToGPUGl2(int width, int height, const u8 *temp_tex_buffer, bool mipmapped, bool mipmapsIncluded) void TextureCacheData::UploadToGPUGl2(int width, int height, const u8 *temp_tex_buffer, bool mipmapped, bool mipmapsIncluded)
{ {
if (texID == 0)
texID = glcache.GenTexture();
glcache.BindTexture(GL_TEXTURE_2D, texID); glcache.BindTexture(GL_TEXTURE_2D, texID);
GLuint comps; GLuint comps;
GLuint gltype; GLuint gltype;
@ -77,7 +79,6 @@ void TextureCacheData::UploadToGPUGl2(int width, int height, const u8 *temp_tex_
void TextureCacheData::UploadToGPUGl4(int width, int height, const u8 *temp_tex_buffer, bool mipmapped, bool mipmapsIncluded) void TextureCacheData::UploadToGPUGl4(int width, int height, const u8 *temp_tex_buffer, bool mipmapped, bool mipmapsIncluded)
{ {
#if !defined(GLES2) && (!defined(__APPLE__) || defined(TARGET_IPHONE)) #if !defined(GLES2) && (!defined(__APPLE__) || defined(TARGET_IPHONE))
glcache.BindTexture(GL_TEXTURE_2D, texID);
GLuint comps; GLuint comps;
GLuint gltype; GLuint gltype;
GLuint internalFormat; GLuint internalFormat;
@ -94,8 +95,15 @@ void TextureCacheData::UploadToGPUGl4(int width, int height, const u8 *temp_tex_
dim >>= 1; dim >>= 1;
} }
} }
if (Updates == 1) if (texID == 0)
{
texID = glcache.GenTexture();
glcache.BindTexture(GL_TEXTURE_2D, texID);
glTexStorage2D(GL_TEXTURE_2D, mipmapLevels, internalFormat, width, height); glTexStorage2D(GL_TEXTURE_2D, mipmapLevels, internalFormat, width, height);
}
else {
glcache.BindTexture(GL_TEXTURE_2D, texID);
}
if (mipmapsIncluded) if (mipmapsIncluded)
{ {
for (int i = 0; i < mipmapLevels; i++) { for (int i = 0; i < mipmapLevels; i++) {
@ -133,8 +141,10 @@ bool TextureCacheData::Delete()
if (!BaseTextureCacheData::Delete()) if (!BaseTextureCacheData::Delete())
return false; return false;
if (texID) if (texID != 0) {
glcache.DeleteTextures(1, &texID); glcache.DeleteTextures(1, &texID);
texID = 0;
}
return true; return true;
} }
@ -276,7 +286,7 @@ BaseTextureCacheData *OpenGLRenderer::GetTexture(TSP tsp, TCW tcw)
else if (tf->IsCustomTextureAvailable()) else if (tf->IsCustomTextureAvailable())
{ {
TexCache.DeleteLater(tf->texID); TexCache.DeleteLater(tf->texID);
tf->texID = glcache.GenTexture(); tf->texID = 0;
tf->CheckCustomTexture(); tf->CheckCustomTexture();
} }