Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renderer recreated fixes #1988

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions core/renderer/TextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ Texture2D* TextureCache::addImage(const Data& imageData, std::string_view key)
{
if (texture->initWithImage(image))
{

#if CC_ENABLE_CACHE_TEXTURE_DATA
VolatileTextureMgr::addImage(texture, image);
#endif
Expand All @@ -598,7 +598,7 @@ Texture2D* TextureCache::addImage(const Data& imageData, std::string_view key)
{
AXLOG("axmol: Allocating memory for Texture2D failed!");
}

AX_SAFE_RELEASE(image);

} while (0);
Expand Down Expand Up @@ -978,13 +978,10 @@ void VolatileTextureMgr::reloadTexture(Texture2D* texture, std::string_view file
if (!texture)
return;

Image* image = new Image();
Data data = FileUtils::getInstance()->getDataFromFile(filename);

if (image->initWithImageData(data.getBytes(), data.getSize()))
texture->initWithImage(image, pixelFormat);
Image image;

AX_SAFE_DELETE(image);
if (image.initWithImageFile(filename))
texture->initWithImage(&image, pixelFormat);
}

#endif // AX_ENABLE_CACHE_TEXTURE_DATA
Expand Down
15 changes: 13 additions & 2 deletions core/renderer/backend/opengl/TextureGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ void Texture2DGL::updateData(uint8_t* data, std::size_t width, std::size_t heigh
return;

// Set the row align only when mipmapsNum == 1 and the data is uncompressed
auto mipmapEnalbed = isMipmapEnabled(_textureInfo.minFilterGL) || isMipmapEnabled(_textureInfo.magFilterGL);
if (!mipmapEnalbed)
auto mipmapEnabled = isMipmapEnabled(_textureInfo.minFilterGL) || isMipmapEnabled(_textureInfo.magFilterGL);
if (!mipmapEnabled)
{
unsigned int bytesPerRow = width * _bitsPerPixel / 8;

Expand Down Expand Up @@ -233,6 +233,14 @@ void Texture2DGL::updateData(uint8_t* data, std::size_t width, std::size_t heigh

CHECK_GL_ERROR_DEBUG();

#if AX_ENABLE_CACHE_TEXTURE_DATA
if (_generateMipmaps)
{
_hasMipmaps = false;
generateMipmaps();
}
#endif

if (!_hasMipmaps && level > 0)
_hasMipmaps = true;
}
Expand Down Expand Up @@ -304,6 +312,9 @@ void Texture2DGL::generateMipmaps()

if (!_hasMipmaps)
{
#if AX_ENABLE_CACHE_TEXTURE_DATA
_generateMipmaps = true;
#endif
_hasMipmaps = true;
__gl->bindTexture(GL_TEXTURE_2D, (GLuint)this->getHandler());
glGenerateMipmap(GL_TEXTURE_2D);
Expand Down
4 changes: 4 additions & 0 deletions core/renderer/backend/opengl/TextureGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ class Texture2DGL : public backend::Texture2DBackend

TextureInfoGL _textureInfo;
EventListener* _rendererRecreatedListener = nullptr;

#if AX_ENABLE_CACHE_TEXTURE_DATA
bool _generateMipmaps = false;
#endif
};

/**
Expand Down