From 6d18863d6537453079ee3c091c29ae4e611e7a53 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 23 Sep 2023 12:54:37 +1000 Subject: [PATCH] OpenGLDevice: Set unpack row length on create --- src/util/opengl_stream_buffer.cpp | 12 +++++++++--- src/util/opengl_texture.cpp | 20 ++++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/util/opengl_stream_buffer.cpp b/src/util/opengl_stream_buffer.cpp index 27f2b9051..5bdaf9559 100644 --- a/src/util/opengl_stream_buffer.cpp +++ b/src/util/opengl_stream_buffer.cpp @@ -267,9 +267,15 @@ public: DebugAssert((m_position + used_size) <= m_size); if (!m_coherent) { - // TODO: shouldn't be needed anymore - Bind(); - glFlushMappedBufferRange(m_target, m_position, used_size); + if (GLAD_GL_VERSION_4_5 || GLAD_GL_ARB_direct_state_access) + { + glFlushMappedNamedBufferRange(m_buffer_id, m_position, used_size); + } + else + { + Bind(); + glFlushMappedBufferRange(m_target, m_position, used_size); + } } const u32 prev_position = m_position; diff --git a/src/util/opengl_texture.cpp b/src/util/opengl_texture.cpp index 117e5ee62..7e61fe6bb 100644 --- a/src/util/opengl_texture.cpp +++ b/src/util/opengl_texture.cpp @@ -120,15 +120,22 @@ bool OpenGLTexture::Create(u32 width, u32 height, u32 layers, u32 levels, u32 sa if (data) { + glPixelStorei(GL_UNPACK_ROW_LENGTH, data_pitch / GetPixelSize(format)); + // TODO: Fix data for mipmaps here. if (layers > 1) glTexSubImage3D(target, 0, 0, 0, 0, width, height, layers, gl_format, gl_type, data); else glTexSubImage2D(target, 0, 0, 0, width, height, gl_format, gl_type, data); + + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); } } else { + if (data) + glPixelStorei(GL_UNPACK_ROW_LENGTH, data_pitch / GetPixelSize(format)); + for (u32 i = 0; i < levels; i++) { // TODO: Fix data pointer here. @@ -138,6 +145,9 @@ bool OpenGLTexture::Create(u32 width, u32 height, u32 layers, u32 levels, u32 sa glTexImage2D(target, i, gl_internal_format, width, height, 0, gl_format, gl_type, data); } + if (data) + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels); } @@ -206,6 +216,7 @@ bool OpenGLTexture::Update(u32 x, u32 y, u32 width, u32 height, const void* data GL_INS_FMT("Not using PBO for map size {}", map_size); glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch / GetPixelSize()); glTexSubImage2D(target, layer, x, y, width, height, gl_format, gl_type, data); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); } else { @@ -217,6 +228,7 @@ bool OpenGLTexture::Update(u32 x, u32 y, u32 width, u32 height, const void* data glPixelStorei(GL_UNPACK_ROW_LENGTH, preferred_pitch / GetPixelSize()); glTexSubImage2D(GL_TEXTURE_2D, layer, x, y, width, height, gl_format, gl_type, reinterpret_cast(static_cast(map.buffer_offset))); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); sb->Unbind(); } @@ -261,13 +273,13 @@ void OpenGLTexture::Unmap() sb->Unmap(upload_size); sb->Bind(); - glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch / GetPixelSize()); - OpenGLDevice::BindUpdateTextureUnit(); const GLenum target = GetGLTarget(); glBindTexture(target, m_id); + glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch / GetPixelSize()); + const auto [gl_internal_format, gl_format, gl_type] = GetPixelFormatMapping(m_format); if (IsTextureArray()) { @@ -282,9 +294,9 @@ void OpenGLTexture::Unmap() glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - sb->Unbind(); - glBindTexture(target, 0); + + sb->Unbind(); } void OpenGLTexture::SetDebugName(const std::string_view& name)