From 08ddd44b634d4da78edd0964f539a310544c7883 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 3 Nov 2021 18:52:30 +0800 Subject: ! UI9Slicing --- Runtime/Graphics/Texture.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'Runtime/Graphics/Texture.cpp') diff --git a/Runtime/Graphics/Texture.cpp b/Runtime/Graphics/Texture.cpp index a1f4181..0cabd07 100644 --- a/Runtime/Graphics/Texture.cpp +++ b/Runtime/Graphics/Texture.cpp @@ -84,7 +84,22 @@ void Texture::Init(TextureSetting setting, ImageData* imgData) break; } - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imgData->width, imgData->height, 0, GL_RGB, GL_UNSIGNED_BYTE, imgData->pixels); + GLint srcFormat = GL_RGB; + switch (imgData->format) + { + case PixelFormat_R: srcFormat = GL_RED; break; + case PixelFormat_RGB: srcFormat = GL_RGB; break; + case PixelFormat_RGBA: srcFormat = GL_RGBA; break; + default: Assert(false); + } + GLint srcType = GL_UNSIGNED_BYTE; + switch (imgData->type) + { + case PixelType_UNSIGNED_BYTE: srcType = GL_UNSIGNED_BYTE; break; + default: Assert(false); + } + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imgData->width, imgData->height, 0, srcFormat, srcType, imgData->pixels); CheckGLError( glDeleteTextures(1, &m_GPUID); -- cgit v1.1-26-g67d0