From e3cc42069f00911933f1c246873c017987690921 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Tue, 15 Nov 2022 00:38:24 -0600 Subject: [PATCH] VideoBackends:OGL: Creating vertex formats shouldn't unbind anything --- Source/Core/VideoBackends/OGL/OGLNativeVertexFormat.cpp | 4 +++- Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp | 6 ++++++ Source/Core/VideoBackends/OGL/ProgramShaderCache.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Source/Core/VideoBackends/OGL/OGLNativeVertexFormat.cpp b/Source/Core/VideoBackends/OGL/OGLNativeVertexFormat.cpp index 16bcabab4b..b77755bb12 100644 --- a/Source/Core/VideoBackends/OGL/OGLNativeVertexFormat.cpp +++ b/Source/Core/VideoBackends/OGL/OGLNativeVertexFormat.cpp @@ -59,7 +59,6 @@ GLVertexFormat::GLVertexFormat(const PortableVertexDeclaration& vtx_decl) glGenVertexArrays(1, &VAO); glBindVertexArray(VAO); - ProgramShaderCache::BindVertexFormat(this); // the element buffer is bound directly to the vao, so we must it set for every vao glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vm->GetIndexBufferHandle()); @@ -77,6 +76,9 @@ GLVertexFormat::GLVertexFormat(const PortableVertexDeclaration& vtx_decl) SetPointer(ShaderAttrib::TexCoord0 + i, vertex_stride, vtx_decl.texcoords[i]); SetPointer(ShaderAttrib::PositionMatrix, vertex_stride, vtx_decl.posmtx); + + // Other code shouldn't have to worry about its vertex formats being randomly unbound + ProgramShaderCache::ReBindVertexFormat(); } GLVertexFormat::~GLVertexFormat() diff --git a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp index 22a917c8c5..bd96f3be04 100644 --- a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp +++ b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp @@ -496,6 +496,12 @@ void ProgramShaderCache::BindVertexFormat(const GLVertexFormat* vertex_format) s_last_VAO = new_VAO; } +void ProgramShaderCache::ReBindVertexFormat() +{ + if (s_last_VAO) + glBindVertexArray(s_last_VAO); +} + bool ProgramShaderCache::IsValidVertexFormatBound() { return s_last_VAO != 0 && s_last_VAO != s_attributeless_VAO; diff --git a/Source/Core/VideoBackends/OGL/ProgramShaderCache.h b/Source/Core/VideoBackends/OGL/ProgramShaderCache.h index 9e198987b8..0d19abb490 100644 --- a/Source/Core/VideoBackends/OGL/ProgramShaderCache.h +++ b/Source/Core/VideoBackends/OGL/ProgramShaderCache.h @@ -69,6 +69,7 @@ class ProgramShaderCache { public: static void BindVertexFormat(const GLVertexFormat* vertex_format); + static void ReBindVertexFormat(); static bool IsValidVertexFormatBound(); static void InvalidateVertexFormat(); static void InvalidateVertexFormatIfBound(GLuint vao);