Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenGL backend, restore state? #1166

Closed
ronen opened this issue Apr 27, 2016 · 2 comments
Closed

OpenGL backend, restore state? #1166

ronen opened this issue Apr 27, 2016 · 2 comments

Comments

@ronen
Copy link
Contributor

ronen commented Apr 27, 2016

Generalizing #1165, it seems there are several items of OpenGL state that end up changed after halide_opengl_run() finishes, which leads to surprisingly wrong--and hard to debug--results when a halide filter is used as part of an existing OpenGL app.

Here are ones @shoaibkamil and I have come across (there may be others, but I haven't trolled through the source to find out):

So my current code wraps the halide filter with:

// save state that halide will clobber
GLint program;
GLint viewport[4];
GLboolean cull_face;
GLboolean depth_test;
glGetIntegerv(GL_VIEWPORT, viewport);
glGetIntegerv(GL_CURRENT_PROGRAM, &program);
glGetBooleanv(GL_CULL_FACE, &cull_face);
glGetBooleanv(GL_DEPTH_TEST, &depth_test);

halide_filter(&input_buf, &output_buf);   // AOT compiled filter

// restore state
glUseProgram(program);
glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
(cull_face ? glEnable : glDisable)(GL_CULL_FACE);
(depth_test ? glEnable : glDisable)(GL_DEPTH_TEST);

Of course it might be that there's a good reason not to restore some part of the state; in which case though WBN to document that clearly.

@zvookin
Copy link
Member

zvookin commented Apr 20, 2017

@ronen @shoaibkamil Can this be closed now or is there more to do?

@ronen
Copy link
Contributor Author

ronen commented Apr 20, 2017

Can be closed. Closing.

@ronen ronen closed this as completed Apr 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants