diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-06-15 01:37:01 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-06-15 01:37:01 +0300 |
commit | 0f208c6842ef13d8c68b179eb0ab88a37a0926b0 (patch) | |
tree | dc60df46116896fc362ac5067fbc464982ee2cc9 | |
parent | 8f9ffaa42e6fa11bb963fa9f1a1824d85a50b51b (diff) | |
download | manaplus-0f208c6842ef13d8c68b179eb0ab88a37a0926b0.tar.gz manaplus-0f208c6842ef13d8c68b179eb0ab88a37a0926b0.tar.bz2 manaplus-0f208c6842ef13d8c68b179eb0ab88a37a0926b0.tar.xz manaplus-0f208c6842ef13d8c68b179eb0ab88a37a0926b0.zip |
Add OpenGL extension GL_ARB_invalidate_subdata.
And use it for invalidate prepared for deletion images.
-rw-r--r-- | src/graphicsmanager.cpp | 10 | ||||
-rw-r--r-- | src/render/mgl.cpp | 1 | ||||
-rw-r--r-- | src/render/mgl.h | 1 | ||||
-rw-r--r-- | src/render/mgltypes.h | 1 | ||||
-rw-r--r-- | src/resources/image.cpp | 9 | ||||
-rw-r--r-- | src/resources/image.h | 2 | ||||
-rw-r--r-- | src/resources/openglimagehelper.cpp | 9 | ||||
-rw-r--r-- | src/resources/openglimagehelper.h | 2 | ||||
-rw-r--r-- | src/resources/subimage.cpp | 7 | ||||
-rw-r--r-- | src/resources/subimage.h | 4 |
10 files changed, 46 insertions, 0 deletions
diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp index 938c0ccf1..4661563e2 100644 --- a/src/graphicsmanager.cpp +++ b/src/graphicsmanager.cpp @@ -1054,6 +1054,16 @@ void GraphicsManager::initOpenGLFunctions() { logger->log1("GL_ARB_vertex_attrib_binding not supported"); } + if (checkGLVersion(4, 3) + || supportExtension("GL_ARB_invalidate_subdata")) + { + logger->log1("found GL_ARB_invalidate_subdata"); + assignFunction(glInvalidateTexImage, "glInvalidateTexImage"); + } + else + { + logger->log1("GL_ARB_invalidate_subdata not supported"); + } if (checkGLVersion(4, 4) || supportExtension("GL_ARB_multi_bind")) { logger->log1("found GL_ARB_multi_bind"); diff --git a/src/render/mgl.cpp b/src/render/mgl.cpp index 63730fbad..9818b7f04 100644 --- a/src/render/mgl.cpp +++ b/src/render/mgl.cpp @@ -95,6 +95,7 @@ defName(glBindVertexBuffers); defName(glIsBuffer); defName(glVertexAttribIFormat); defName(glVertexAttribIPointer); +defName(glInvalidateTexImage); #ifdef WIN32 defName(wglGetExtensionsString); diff --git a/src/render/mgl.h b/src/render/mgl.h index 53c6b714b..dbd9a4b38 100644 --- a/src/render/mgl.h +++ b/src/render/mgl.h @@ -98,6 +98,7 @@ defNameE(glBindVertexBuffers); defNameE(glIsBuffer); defNameE(glVertexAttribIFormat); defNameE(glVertexAttribIPointer); +defNameE(glInvalidateTexImage); #ifdef WIN32 defNameE(wglGetExtensionsString); diff --git a/src/render/mgltypes.h b/src/render/mgltypes.h index 9deefd41f..14b3b5760 100644 --- a/src/render/mgltypes.h +++ b/src/render/mgltypes.h @@ -144,6 +144,7 @@ typedef void (APIENTRY *glVertexAttribIFormat_t) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); typedef void (APIENTRY *glVertexAttribIPointer_t) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid * pointer); +typedef void (APIENTRY *glInvalidateTexImage_t) (GLuint texture, GLint level); // callback typedef void (APIENTRY *GLDEBUGPROC_t) (GLenum source, GLenum type, GLuint id, 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: |