summaryrefslogtreecommitdiff
path: root/Runtime/Graphics/Texture.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-31 14:27:26 +0800
committerchai <chaifix@163.com>2021-10-31 14:27:26 +0800
commit601442f94fc0dcfdc5a117c5f87d90b156d53045 (patch)
treeb006bcd6a28a965a900c64f4716007fcb45eee98 /Runtime/Graphics/Texture.cpp
parent26f05c6e3dcac9995345fb5a2b031be7e3ea79e9 (diff)
+static initiator
Diffstat (limited to 'Runtime/Graphics/Texture.cpp')
-rw-r--r--Runtime/Graphics/Texture.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/Runtime/Graphics/Texture.cpp b/Runtime/Graphics/Texture.cpp
index f92c094..eed0b90 100644
--- a/Runtime/Graphics/Texture.cpp
+++ b/Runtime/Graphics/Texture.cpp
@@ -158,12 +158,13 @@ Texture::Texture(TextureSetting setting, int w, int h)
if (m_Format == ETextureFormat::R8)
{
internalFormat = GL_RED;
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
}
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, w, h, 0, GL_RED, GL_UNSIGNED_BYTE, NULL);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
+
CheckGLError(
glDeleteTextures(1, &m_GPUID);
glBindTexture(GL_TEXTURE_2D, 0);
@@ -185,6 +186,12 @@ void Texture::UpdateSubImage(Internal::Rect rect, int format, int type, const vo
throw TextureException(error);
);
+ int alignment = 4;
+ if (m_Format == ETextureFormat::R8)
+ {
+ alignment = 1;
+ }
+
GLenum fmt = GL_RED;
switch (format)
{
@@ -205,8 +212,12 @@ void Texture::UpdateSubImage(Internal::Rect rect, int format, int type, const vo
case EPixelElementType::PixelType_FLOAT: t = GL_FLOAT; break;
}
+ glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
+
glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x, rect.y, rect.width, rect.height, fmt, t, data);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
+
CheckGLError(
glBindTexture(GL_TEXTURE_2D, 0);
throw TextureException(error);