summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends
diff options
context:
space:
mode:
authorUnknown W. Brackets <checkins@unknownbrackets.org>2014-12-03 23:24:58 -0800
committerUnknown W. Brackets <checkins@unknownbrackets.org>2014-12-06 19:27:49 -0800
commitb19cff8a08a03b39653ea16ec5f51a2c80c5f2d1 (patch)
tree4153f73c3df632eebd9a5cde1d888e0455175305 /Source/Core/VideoBackends
parentf7a16eca84a868b5dcce113ece3e84d21347feae (diff)
OGL: Use a fixed VAO for attributeless rendering.
Instead of abusing whatever VAO is previously bound, which might have enabled arrays. Only used in one instance currently, which fixes a crash with older NVIDIA drivers.
Diffstat (limited to 'Source/Core/VideoBackends')
-rw-r--r--Source/Core/VideoBackends/OGL/GLUtil.cpp31
-rw-r--r--Source/Core/VideoBackends/OGL/GLUtil.h5
-rw-r--r--Source/Core/VideoBackends/OGL/PostProcessing.cpp2
-rw-r--r--Source/Core/VideoBackends/OGL/Render.cpp2
4 files changed, 40 insertions, 0 deletions
diff --git a/Source/Core/VideoBackends/OGL/GLUtil.cpp b/Source/Core/VideoBackends/OGL/GLUtil.cpp
index bfd6170839..f91b079c3b 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,32 @@ GLuint OpenGL_CompileProgram(const char* vertexShader, const char* fragmentShade
return programID;
}
+static void CreateAttributelessVAO()
+{
+ glGenVertexArrays(1, &attributelessVAO);
+
+ // In a compatibility context, we require a valid, bound array buffer.
+ glGenBuffers(1, &attributelessVBO);
+
+ // 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()
+{
+ if (attributelessVAO == 0)
+ CreateAttributelessVAO();
+
+ glBindVertexArray(attributelessVAO);
+ glBindBuffer(GL_ARRAY_BUFFER, attributelessVBO);
+}
+
+void OpenGL_DeleteAttributelessVAO()
+{
+ glDeleteVertexArrays(1, &attributelessVAO);
+ glDeleteBuffers(1, &attributelessVBO);
+}
diff --git a/Source/Core/VideoBackends/OGL/GLUtil.h b/Source/Core/VideoBackends/OGL/GLUtil.h
index 8bcfb06886..3d7e562971 100644
--- a/Source/Core/VideoBackends/OGL/GLUtil.h
+++ b/Source/Core/VideoBackends/OGL/GLUtil.h
@@ -18,6 +18,11 @@ void InitInterface();
// Helpers
GLuint OpenGL_CompileProgram(const char *vertexShader, const char *fragmentShader);
+// Binds (and creates, if necessary) a VAO and VBO suitable for attributeless rendering.
+void OpenGL_BindAttributelessVAO();
+// Deletes any existing VAO / VBO that has been created.
+void OpenGL_DeleteAttributelessVAO();
+
// 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 f33c59899c..c14753039d 100644
--- a/Source/Core/VideoBackends/OGL/Render.cpp
+++ b/Source/Core/VideoBackends/OGL/Render.cpp
@@ -686,6 +686,8 @@ void Renderer::Shutdown()
delete m_post_processor;
m_post_processor = nullptr;
+
+ OpenGL_DeleteAttributelessVAO();
}
void Renderer::Init()