diff --git a/Source/Core/VideoBackends/OGL/FramebufferManager.cpp b/Source/Core/VideoBackends/OGL/FramebufferManager.cpp index c458b79dc6..1089884b96 100644 --- a/Source/Core/VideoBackends/OGL/FramebufferManager.cpp +++ b/Source/Core/VideoBackends/OGL/FramebufferManager.cpp @@ -373,6 +373,8 @@ void FramebufferManager::ReinterpretPixelData(unsigned int convtype) { g_renderer->ResetAPIState(); + OpenGL_BindAttributelessVAO(); + GLuint src_texture = 0; // We aren't allowed to render and sample the same texture in one draw call, diff --git a/Source/Core/VideoBackends/OGL/GLUtil.cpp b/Source/Core/VideoBackends/OGL/GLUtil.cpp index bfd6170839..dddc299fb9 100644 --- a/Source/Core/VideoBackends/OGL/GLUtil.cpp +++ b/Source/Core/VideoBackends/OGL/GLUtil.cpp @@ -16,6 +16,8 @@ #include "VideoCommon/VideoConfig.h" cInterfaceBase *GLInterface; +static GLuint attributelessVAO = 0; +static GLuint attributelessVBO = 0; namespace OGL { @@ -113,3 +115,38 @@ GLuint OpenGL_CompileProgram(const char* vertexShader, const char* fragmentShade return programID; } +void OpenGL_CreateAttributelessVAO() +{ + glGenVertexArrays(1, &attributelessVAO); + _dbg_assert_msg_(VIDEO, attributelessVAO != 0, "Attributeless VAO should have been created successfully.") + + // In a compatibility context, we require a valid, bound array buffer. + glGenBuffers(1, &attributelessVBO); + _dbg_assert_msg_(VIDEO, attributelessVBO != 0, "Attributeless VBO should have been created successfully.") + + // Initialize the buffer with nothing. + glBindBuffer(GL_ARRAY_BUFFER, attributelessVBO); + glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat), nullptr, GL_STATIC_DRAW); + + // We must also define vertex attribute 0. + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, nullptr); +} + +void OpenGL_BindAttributelessVAO() +{ + _dbg_assert_msg_(VIDEO, attributelessVAO != 0, "Attributeless VAO should have already been created.") + glBindVertexArray(attributelessVAO); +} + +void OpenGL_DeleteAttributelessVAO() +{ + _dbg_assert_msg_(VIDEO, attributelessVAO != 0, "Attributeless VAO should have already been created.") + if (attributelessVAO != 0) + { + glDeleteVertexArrays(1, &attributelessVAO); + glDeleteBuffers(1, &attributelessVBO); + + attributelessVAO = 0; + attributelessVBO = 0; + } +} diff --git a/Source/Core/VideoBackends/OGL/GLUtil.h b/Source/Core/VideoBackends/OGL/GLUtil.h index 8bcfb06886..13052be293 100644 --- a/Source/Core/VideoBackends/OGL/GLUtil.h +++ b/Source/Core/VideoBackends/OGL/GLUtil.h @@ -18,6 +18,14 @@ void InitInterface(); // Helpers GLuint OpenGL_CompileProgram(const char *vertexShader, const char *fragmentShader); +// Creates and deletes a VAO and VBO suitable for attributeless rendering. +// Called by the Renderer. +void OpenGL_CreateAttributelessVAO(); +void OpenGL_DeleteAttributelessVAO(); + +// Binds the VAO suitable for attributeless rendering. +void OpenGL_BindAttributelessVAO(); + // this should be removed in future, but as long as glsl is unstable, we should really read this messages #if defined(_DEBUG) || defined(DEBUGFAST) #define DEBUG_GLSL 1 diff --git a/Source/Core/VideoBackends/OGL/PostProcessing.cpp b/Source/Core/VideoBackends/OGL/PostProcessing.cpp index 80bdf8eef4..74fd93147b 100644 --- a/Source/Core/VideoBackends/OGL/PostProcessing.cpp +++ b/Source/Core/VideoBackends/OGL/PostProcessing.cpp @@ -72,6 +72,8 @@ void OpenGLPostProcessing::BlitFromTexture(TargetRectangle src, TargetRectangle if (m_attribute_workaround) glBindVertexArray(m_attribute_vao); + else + OpenGL_BindAttributelessVAO(); m_shader.Bind(); diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 1ce829bb99..f26a1460ce 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -691,6 +691,8 @@ void Renderer::Shutdown() delete m_post_processor; m_post_processor = nullptr; + + OpenGL_DeleteAttributelessVAO(); } void Renderer::Init() @@ -717,6 +719,8 @@ void Renderer::Init() " ocol0 = c;\n" "}\n"); + OpenGL_CreateAttributelessVAO(); + // creating buffers glGenBuffers(1, &s_ShowEFBCopyRegions_VBO); glGenVertexArrays(1, &s_ShowEFBCopyRegions_VAO); diff --git a/Source/Core/VideoBackends/OGL/TextureCache.cpp b/Source/Core/VideoBackends/OGL/TextureCache.cpp index 49bfc98a55..f697d51c73 100644 --- a/Source/Core/VideoBackends/OGL/TextureCache.cpp +++ b/Source/Core/VideoBackends/OGL/TextureCache.cpp @@ -249,6 +249,8 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo { FramebufferManager::SetFramebuffer(framebuffer); + OpenGL_BindAttributelessVAO(); + glActiveTexture(GL_TEXTURE0+9); glBindTexture(GL_TEXTURE_2D_ARRAY, read_texture); diff --git a/Source/Core/VideoBackends/OGL/TextureConverter.cpp b/Source/Core/VideoBackends/OGL/TextureConverter.cpp index 8753b58e8a..6384991ceb 100644 --- a/Source/Core/VideoBackends/OGL/TextureConverter.cpp +++ b/Source/Core/VideoBackends/OGL/TextureConverter.cpp @@ -222,6 +222,8 @@ static void EncodeToRamUsingShader(GLuint srcTexture, // attach render buffer as color destination FramebufferManager::SetFramebuffer(s_texConvFrameBuffer[0]); + OpenGL_BindAttributelessVAO(); + // set source texture glActiveTexture(GL_TEXTURE0+9); glBindTexture(GL_TEXTURE_2D_ARRAY, srcTexture); @@ -362,6 +364,8 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur g_renderer->ResetAPIState(); // reset any game specific settings + OpenGL_BindAttributelessVAO(); + // switch to texture converter frame buffer // attach destTexture as color destination FramebufferManager::SetFramebuffer(s_texConvFrameBuffer[1]);