OpenGLDevice: Set unpack row length on create

This commit is contained in:
Stenzek 2023-09-23 12:54:37 +10:00
parent 2067b660f6
commit 6d18863d65
2 changed files with 25 additions and 7 deletions

View file

@ -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;

View file

@ -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<void*>(static_cast<uintptr_t>(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)