From 0f208c6842ef13d8c68b179eb0ab88a37a0926b0 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 15 Jun 2014 01:37:01 +0300 Subject: Add OpenGL extension GL_ARB_invalidate_subdata. And use it for invalidate prepared for deletion images. --- src/resources/image.cpp | 9 +++++++++ src/resources/image.h | 2 ++ src/resources/openglimagehelper.cpp | 9 +++++++++ src/resources/openglimagehelper.h | 2 ++ src/resources/subimage.cpp | 7 +++++++ src/resources/subimage.h | 4 ++++ 6 files changed, 33 insertions(+) (limited to 'src/resources') diff --git a/src/resources/image.cpp b/src/resources/image.cpp index d9d2a8a01..d6f5cd27c 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -467,3 +467,12 @@ void Image::SDLTerminateAlphaCache() SDLCleanCache(); mUseAlphaCache = false; } + +#ifdef USE_OPENGL +void Image::decRef() +{ + if (getRefCount() <= 1) + OpenGLImageHelper::invalidate(mGLImage); + Resource::decRef(); +} +#endif diff --git a/src/resources/image.h b/src/resources/image.h index 2c67281b7..868b5690e 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -167,6 +167,8 @@ class Image notfinal : public Resource GLuint getGLImage() const A_WARN_UNUSED { return mGLImage; } + void decRef() override; + GLuint mGLImage; int mTexWidth; int mTexHeight; diff --git a/src/resources/openglimagehelper.cpp b/src/resources/openglimagehelper.cpp index 2ce4bd405..2eadf35ff 100644 --- a/src/resources/openglimagehelper.cpp +++ b/src/resources/openglimagehelper.cpp @@ -348,4 +348,13 @@ void OpenGLImageHelper::postInit() glGenTextures(texturesSize, &mTextures[mFreeTextureIndex]); } +void OpenGLImageHelper::invalidate(const GLuint textureId) +{ + if (mglInvalidateTexImage) + { + logger->log("invalidate: %u", textureId); + mglInvalidateTexImage(textureId, 0); + } +} + #endif diff --git a/src/resources/openglimagehelper.h b/src/resources/openglimagehelper.h index d87052592..2a91689d9 100644 --- a/src/resources/openglimagehelper.h +++ b/src/resources/openglimagehelper.h @@ -116,6 +116,8 @@ class OpenGLImageHelper final : public ImageHelper static void setUseTextureSampler(const bool b) { mUseTextureSampler = b; } + static void invalidate(const GLuint textureId); + SDL_Surface *create32BitSurface(int width, int height) const override final; diff --git a/src/resources/subimage.cpp b/src/resources/subimage.cpp index 717858ae0..ef9827810 100644 --- a/src/resources/subimage.cpp +++ b/src/resources/subimage.cpp @@ -211,3 +211,10 @@ Image *SubImage::getSubImage(const int x, const int y, else return nullptr; } + +#ifdef USE_OPENGL +void SubImage::decRef() +{ + Resource::decRef(); +} +#endif diff --git a/src/resources/subimage.h b/src/resources/subimage.h index 27a76d277..2fe562c30 100644 --- a/src/resources/subimage.h +++ b/src/resources/subimage.h @@ -79,6 +79,10 @@ class SubImage final : public Image const int width, const int height) override final A_WARN_UNUSED; +#ifdef USE_OPENGL + void decRef() override final; +#endif + SDL_Rect mInternalBounds; private: -- cgit v1.2.3-60-g2f50