From 601442f94fc0dcfdc5a117c5f87d90b156d53045 Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 31 Oct 2021 14:27:26 +0800 Subject: +static initiator --- Runtime/Graphics/Texture.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'Runtime/Graphics/Texture.cpp') 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); -- cgit v1.1-26-g67d0