Skip to content

Commit

Permalink
Port 6e9a7e7 to the OS X overlay.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrautz committed Feb 5, 2015
1 parent 8e3168b commit f4568b9
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion macx/overlay/overlay.m
Expand Up @@ -81,7 +81,9 @@
unsigned int uiMappedLength;
clock_t timeT;
unsigned int frameCount;


GLint maxVertexAttribs;
GLboolean* vertexAttribStates;
} Context;

static const char vshader[] = ""
Expand Down Expand Up @@ -164,6 +166,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) {
Expand Down Expand Up @@ -542,6 +547,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);
Expand Down Expand Up @@ -575,6 +590,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();

Expand Down

0 comments on commit f4568b9

Please sign in to comment.