diff options
Diffstat (limited to 'source/modules/asura-core/graphics/image.cpp')
-rw-r--r-- | source/modules/asura-core/graphics/image.cpp | 180 |
1 files changed, 89 insertions, 91 deletions
diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp index a0dff8d..32fa870 100644 --- a/source/modules/asura-core/graphics/image.cpp +++ b/source/modules/asura-core/graphics/image.cpp @@ -9,97 +9,95 @@ using namespace AEIO; using namespace AEImage; -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +Image::Image() + : m_Width(0) + , m_Height(0) +{ +} + +Image::~Image() +{ +} + +bool Image::Load(ImageData* imgData) { - namespace Graphics + if (!imgData) return false; + + if (m_TexID == 0) { + glGenTextures(1, &m_TexID); + if (m_TexID == 0) + throw Exception("OpenGL glGenTextures failed."); + } + + glBindTexture(GL_TEXTURE_2D, m_TexID); + imgData->Lock(); + int width = imgData->width; + int height = imgData->height; + TextureFormat tf = ConvertColorFormat(imgData->format); + glTexImage2D( + GL_TEXTURE_2D + , 0 + , tf.internalformat + , width, height + , 0 + , tf.externalformat + , tf.type + , imgData->pixels + ); + + m_Width = imgData->width; + m_Height = 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::Load(ImageData* imgData, const AEMath::Vector2i& pos) +{ + if (!imgData) return false; + + glBindTexture(GL_TEXTURE_2D, m_TexID); + 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; +} + +uint32 Image::GetWidth() +{ + return m_Width; +} + +uint32 Image::GetHeight() +{ + return m_Height; +} - Image::Image() - : m_Width(0) - , m_Height(0) - { - } - - Image::~Image() - { - } - - bool Image::Load(ImageData* imgData) - { - if (!imgData) return false; - - if (m_TexID == 0) - { - glGenTextures(1, &m_TexID); - if (m_TexID == 0) - throw Exception("OpenGL glGenTextures failed."); - } - - glBindTexture(GL_TEXTURE_2D, m_TexID); - imgData->Lock(); - int width = imgData->width; - int height = imgData->height; - TextureFormat tf = ConvertColorFormat(imgData->format); - glTexImage2D( - GL_TEXTURE_2D - , 0 - , tf.internalformat - , width, height - , 0 - , tf.externalformat - , tf.type - , imgData->pixels - ); - - m_Width = imgData->width; - m_Height = 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::Load(ImageData* imgData, const AEMath::Vector2i& pos) - { - if (!imgData) return false; - - glBindTexture(GL_TEXTURE_2D, m_TexID); - 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; - } - - uint32 Image::GetWidth() - { - return m_Width; - } - - uint32 Image::GetHeight() - { - return m_Height; - } - - } // Graphics -} // AsuraEngine
\ No newline at end of file +namespace_end +namespace_end
\ No newline at end of file |