Skip to content

Commit

Permalink
gl: fully recreate opengl texture when loading a custom one
Browse files Browse the repository at this point in the history
Regenerate texID and call glTexStorage2D when loading a custom texture
(GL 4.2+, GLES3).
rend: missing old_vqtexture_hash in move constructor.
  • Loading branch information
flyinghead committed Mar 14, 2024
1 parent de89d8c commit 3ffb09e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions core/rend/TexCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ class BaseTextureCacheData
Updates = other.Updates;
palette_hash = other.palette_hash;
texture_hash = other.texture_hash;
old_vqtexture_hash = other.old_vqtexture_hash;
old_texture_hash = other.old_texture_hash;
std::swap(custom_image_data, other.custom_image_data);
custom_width = other.custom_width;
Expand Down
4 changes: 2 additions & 2 deletions core/rend/gles/gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,13 @@ extern struct ShaderUniforms_t
class TextureCacheData final : public BaseTextureCacheData
{
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)) {
std::swap(texID, other.texID);
}

GLuint texID; //gl texture
GLuint texID = 0; //gl texture
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;
bool Delete() override;
Expand Down
18 changes: 14 additions & 4 deletions core/rend/gles/gltex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
if (texID == 0)
texID = glcache.GenTexture();
glcache.BindTexture(GL_TEXTURE_2D, texID);
GLuint comps;
GLuint gltype;
Expand Down Expand Up @@ -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)
{
#if !defined(GLES2) && (!defined(__APPLE__) || defined(TARGET_IPHONE))
glcache.BindTexture(GL_TEXTURE_2D, texID);
GLuint comps;
GLuint gltype;
GLuint internalFormat;
Expand All @@ -94,8 +95,15 @@ void TextureCacheData::UploadToGPUGl4(int width, int height, const u8 *temp_tex_
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);
}
else {
glcache.BindTexture(GL_TEXTURE_2D, texID);
}
if (mipmapsIncluded)
{
for (int i = 0; i < mipmapLevels; i++) {
Expand Down Expand Up @@ -133,8 +141,10 @@ bool TextureCacheData::Delete()
if (!BaseTextureCacheData::Delete())
return false;

if (texID)
if (texID != 0) {
glcache.DeleteTextures(1, &texID);
texID = 0;
}

return true;
}
Expand Down Expand Up @@ -276,7 +286,7 @@ BaseTextureCacheData *OpenGLRenderer::GetTexture(TSP tsp, TCW tcw)
else if (tf->IsCustomTextureAvailable())
{
TexCache.DeleteLater(tf->texID);
tf->texID = glcache.GenTexture();
tf->texID = 0;
tf->CheckCustomTexture();
}

Expand Down

0 comments on commit 3ffb09e

Please sign in to comment.