summaryrefslogtreecommitdiff
path: root/src/resources/openglimagehelper.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-07-01 21:57:46 +0300
committerAndrei Karas <akaras@inbox.ru>2014-07-01 21:57:46 +0300
commit62e2ccbb158f146e2c3ceab14ff5581d3f3975ef (patch)
tree736e615b6ff94e09144df7df3aa06f9f231743ff /src/resources/openglimagehelper.cpp
parentd3b57bd96a07a674432fd28cefd2f20ae5404b8b (diff)
downloadmanaplus-62e2ccbb158f146e2c3ceab14ff5581d3f3975ef.tar.gz
manaplus-62e2ccbb158f146e2c3ceab14ff5581d3f3975ef.tar.bz2
manaplus-62e2ccbb158f146e2c3ceab14ff5581d3f3975ef.tar.xz
manaplus-62e2ccbb158f146e2c3ceab14ff5581d3f3975ef.zip
Add to image helper function to copy surface into part of image.
Diffstat (limited to 'src/resources/openglimagehelper.cpp')
-rw-r--r--src/resources/openglimagehelper.cpp54
1 files changed, 44 insertions, 10 deletions
diff --git a/src/resources/openglimagehelper.cpp b/src/resources/openglimagehelper.cpp
index d083b22b5..5f1ec643c 100644
--- a/src/resources/openglimagehelper.cpp
+++ b/src/resources/openglimagehelper.cpp
@@ -133,19 +133,12 @@ int OpenGLImageHelper::powerOfTwo(const int input)
return value >= mTextureSize ? mTextureSize : value;
}
-Image *OpenGLImageHelper::glLoad(SDL_Surface *tmpImage,
- int width, int height)
+SDL_Surface *OpenGLImageHelper::convertSurface(SDL_Surface *tmpImage,
+ int width, int height)
{
if (!tmpImage)
return nullptr;
- // Flush current error flag.
- graphicsManager.getLastError();
-
- if (!width)
- width = tmpImage->w;
- if (!height)
- height = tmpImage->h;
int realWidth = powerOfTwo(width);
int realHeight = powerOfTwo(height);
@@ -197,6 +190,28 @@ Image *OpenGLImageHelper::glLoad(SDL_Surface *tmpImage,
}
SDL_BlitSurface(oldImage, nullptr, tmpImage, nullptr);
}
+ return tmpImage;
+}
+
+Image *OpenGLImageHelper::glLoad(SDL_Surface *tmpImage,
+ int width, int height)
+{
+ if (!tmpImage)
+ return nullptr;
+
+ // Flush current error flag.
+ graphicsManager.getLastError();
+
+ if (!width)
+ width = tmpImage->w;
+ if (!height)
+ height = tmpImage->h;
+
+ SDL_Surface *oldImage = tmpImage;
+ tmpImage = convertSurface(tmpImage, width, height);
+
+ const int realWidth = tmpImage->w;
+ const int realHeight = tmpImage->h;
const GLuint texture = getNewTexture();
switch (mUseOpenGL)
@@ -281,7 +296,7 @@ Image *OpenGLImageHelper::glLoad(SDL_Surface *tmpImage,
if (SDL_MUSTLOCK(tmpImage))
SDL_UnlockSurface(tmpImage);
- if (oldImage)
+ if (oldImage != tmpImage)
MSDL_FreeSurface(tmpImage);
GLenum error = graphicsManager.getLastError();
@@ -358,4 +373,23 @@ void OpenGLImageHelper::invalidate(const GLuint textureId)
}
}
+void OpenGLImageHelper::copySurfaceToImage(Image *const image,
+ const int x, const int y,
+ SDL_Surface *surface) const
+{
+ if (!surface)
+ return;
+
+ SDL_Surface *const oldSurface = surface;
+ surface = convertSurface(surface, surface->w, surface->h);
+
+ glTexSubImage2D(mTextureType, 0,
+ x, y,
+ surface->w, surface->h,
+ GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);
+
+ if (surface != oldSurface)
+ MSDL_FreeSurface(surface);
+}
+
#endif