diff options
Diffstat (limited to 'source/modules/asura-core/graphics/image.cpp')
-rw-r--r-- | source/modules/asura-core/graphics/image.cpp | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp index 2b274c2..530ea97 100644 --- a/source/modules/asura-core/graphics/image.cpp +++ b/source/modules/asura-core/graphics/image.cpp @@ -1,3 +1,5 @@ +#include <asura-utils/exceptions/exception.h> + #include "../core_config.h" #include "image.h" @@ -18,12 +20,19 @@ namespace AsuraEngine { } - bool Image::Refresh(DecodedData* data) + bool Image::Renew(DecodedData* data) { - ASSERT(data); - + if (!data) return false; ImageData* imgData = static_cast<ImageData*>(data); - ASSERT(imgData); + if (!imgData) return false; + + // ûԴһ + if (mTex == 0) + { + glGenTextures(1, &mTex); + if (mTex == 0) + throw Exception("OpenGL glGenTextures failed."); + } glBindTexture(GL_TEXTURE_2D, mTex); imgData->Lock(); @@ -40,8 +49,43 @@ namespace AsuraEngine , tf.type , imgData->pixels ); - mImageData = imgData; + mWidth = imgData->width; + mHeight = imgData->height; + imgData->Unlock(); + GLenum err = glGetError(); + if (err != GL_NO_ERROR) + throw Exception("OpenGL glTexImage2D cause error, error code=%d", err); + glBindTexture(GL_TEXTURE_2D, 0); + + return true; + } + + bool Image::Renew(AEIO::DecodedData* data, const AEMath::Vector2i& pos) + { + if (!data) return false; + ImageData* imgData = static_cast<ImageData*>(data); + if (!imgData) return false; + + glBindTexture(GL_TEXTURE_2D, mTex); + imgData->Lock(); + int width = imgData->width; + int height = imgData->height; + TextureFormat tf = ConvertColorFormat(imgData->format); + glTexSubImage2D( + GL_TEXTURE_2D + , 0 + , pos.x + , pos.y + , imgData->width + , imgData->height + , tf.externalformat + , tf.type + , imgData->pixels + ); imgData->Unlock(); + GLenum err = glGetError(); + if (err != GL_NO_ERROR) + throw Exception("OpenGL glTexSubImage2D cause error, error code=%d", err); glBindTexture(GL_TEXTURE_2D, 0); return true; |