Skip to content
Permalink
Browse files

Disable vertex attrib arrays in overlay_gl (fixes #1298)

This is a fix for the OpenGL overlay which disables
and enables the vertex attrib arrays inside drawContext.
The problem it fixes is that some games leave some of
the arrays enabled between frames, which I think
(not an OpenGL expert) causes the input to the vertex
shader to essentially be arbitrary.
  • Loading branch information...
scapula authored and hacst committed Oct 14, 2014
1 parent 1749ef4 commit 6e9a7e7cb1b1fa9468bba965f34bed0f24017805
Showing with 23 additions and 0 deletions.
  1. +23 −0 overlay_gl/overlay.c
@@ -93,6 +93,9 @@ typedef struct _Context {

clock_t timeT;
unsigned int frameCount;

GLint maxVertexAttribs;
GLboolean* vertexAttribStates;
} Context;

static const char vshader[] = ""
@@ -193,6 +196,9 @@ static void newContext(Context * ctx) {
glAttachShader(ctx->uiProgram, vs);
glAttachShader(ctx->uiProgram, fs);
glLinkProgram(ctx->uiProgram);

glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &ctx->maxVertexAttribs);
ctx->vertexAttribStates = (GLboolean*)calloc(ctx->maxVertexAttribs, sizeof(GLboolean));
}

static void releaseMem(Context *ctx) {
@@ -556,6 +562,16 @@ static void drawContext(Context * ctx, int width, int height) {
glDisable(GL_VERTEX_PROGRAM_ARB);
glDisable(GL_FRAGMENT_PROGRAM_ARB);

GLint enabled;
for (i=0;i<ctx->maxVertexAttribs;++i) {
enabled = GL_FALSE;
glGetVertexAttribiv((GLuint)i, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &enabled);
if (enabled == GL_TRUE) {
glDisableVertexAttribArray((GLuint)i);
ctx->vertexAttribStates[i] = GL_TRUE;
}
}

glUseProgram(ctx->uiProgram);

glEnable(GL_COLOR_MATERIAL);
@@ -589,6 +605,13 @@ static void drawContext(Context * ctx, int width, int height) {
if (vbobound != 0)
glBindBuffer(GL_ARRAY_BUFFER, vbobound);

for (i=0;i<ctx->maxVertexAttribs;++i) {
if (ctx->vertexAttribStates[i] == GL_TRUE) {
glEnableVertexAttribArray((GLuint)i);
ctx->vertexAttribStates[i] = GL_FALSE;
}
}

glMatrixMode(GL_TEXTURE);
glPopMatrix();

0 comments on commit 6e9a7e7

Please sign in to comment.
You can’t perform that action at this time.