GS/OpenGL: Fix texture uploads in big picture mode

This commit is contained in:
Connor McLaughlin 2022-12-17 14:48:03 +10:00 committed by lightningterror
parent e233f1dded
commit f2ca07033c
3 changed files with 23 additions and 27 deletions

View File

@ -85,6 +85,9 @@ std::unique_ptr<HostDisplayTexture> OpenGLHostDisplay::CreateTexture(u32 width,
// clear error
glGetError();
// don't worry, I'm planning on removing this eventually - we'll use GSTexture instead.
glActiveTexture(GL_TEXTURE7);
GLuint id;
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
@ -100,6 +103,8 @@ std::unique_ptr<HostDisplayTexture> OpenGLHostDisplay::CreateTexture(u32 width,
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
}
glActiveTexture(GL_TEXTURE0);
GLenum error = glGetError();
if (error != GL_NO_ERROR)
{
@ -115,30 +120,15 @@ void OpenGLHostDisplay::UpdateTexture(HostDisplayTexture* texture, u32 x, u32 y,
{
OpenGLHostDisplayTexture* tex = static_cast<OpenGLHostDisplayTexture*>(texture);
GLint alignment;
if (texture_data_stride & 1)
alignment = 1;
else if (texture_data_stride & 2)
alignment = 2;
else
alignment = 4;
glActiveTexture(GL_TEXTURE7);
GLint old_texture_binding = 0, old_alignment = 0, old_row_length = 0;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_texture_binding);
glBindTexture(GL_TEXTURE_2D, tex->GetGLID());
glGetIntegerv(GL_UNPACK_ALIGNMENT, &old_alignment);
glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
glGetIntegerv(GL_UNPACK_ROW_LENGTH, &old_row_length);
glPixelStorei(GL_UNPACK_ROW_LENGTH, texture_data_stride / sizeof(u32));
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA8, GL_UNSIGNED_BYTE, texture_data);
glPixelStorei(GL_UNPACK_ROW_LENGTH, old_row_length);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, old_alignment);
glBindTexture(GL_TEXTURE_2D, old_texture_binding);
glActiveTexture(GL_TEXTURE0);
}
void OpenGLHostDisplay::SetVSync(VsyncMode mode)
@ -216,6 +206,9 @@ bool OpenGLHostDisplay::CreateDevice(const WindowInfo& wi, VsyncMode vsync)
bool OpenGLHostDisplay::SetupDevice()
{
// We do use 8-bit formats, and higher alignment for 32-bit formats won't hurt anything.
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
SetSwapInterval();
GL::Program::ResetLastProgram();
return true;
@ -363,11 +356,8 @@ bool OpenGLHostDisplay::BeginPresent(bool frame_skip)
void OpenGLHostDisplay::EndPresent()
{
// clear out pipeline bindings, since imgui doesn't use them
glBindProgramPipeline(0);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_STENCIL_TEST);
glActiveTexture(GL_TEXTURE0);
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

View File

@ -477,13 +477,14 @@ bool GSDeviceOGL::Create()
// ****************************************************************
if (!GLLoader::buggy_pbo)
{
// Mesa seems to use it to compute the row length. In our case, we are
// tightly packed so don't bother with this parameter and set it to the
// minimum alignment (1 byte)
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
s_texture_upload_buffer = GL::StreamBuffer::Create(GL_PIXEL_UNPACK_BUFFER, TEXTURE_UPLOAD_BUFFER_SIZE);
if (!s_texture_upload_buffer)
if (s_texture_upload_buffer)
{
// Don't keep it bound, we'll re-bind when we need it.
// Otherwise non-PBO texture uploads break. Yay for global state.
s_texture_upload_buffer->Unbind();
}
else
{
Console.Error("Failed to create texture upload buffer. Using slow path.");
GLLoader::buggy_pbo = true;
@ -569,6 +570,7 @@ void GSDeviceOGL::ResetAPIState()
// clear out DSB
glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO);
glDisable(GL_BLEND);
glActiveTexture(GL_TEXTURE0);
}
void GSDeviceOGL::RestoreAPIState()

View File

@ -256,6 +256,8 @@ bool GSTextureOGL::Update(const GSVector4i& r, const void* data, int pitch, int
glTextureSubImage2D(m_texture_id, layer, r.x, r.y, r.width(), r.height(), m_int_format, m_int_type,
reinterpret_cast<void*>(static_cast<uintptr_t>(map.buffer_offset)));
sb->Unbind();
}
m_needs_mipmaps_generated = true;
@ -316,6 +318,8 @@ void GSTextureOGL::Unmap()
glTextureSubImage2D(m_texture_id, m_layer, m_r_x, m_r_y, m_r_w, m_r_h, m_int_format, m_int_type,
reinterpret_cast<void*>(static_cast<uintptr_t>(m_map_offset)));
sb->Unbind();
m_needs_mipmaps_generated = true;
GL_POP(); // PUSH is in Map