diff options
author | Mike Erwin <significant.bit@gmail.com> | 2016-10-18 07:08:34 +0300 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2016-10-18 07:08:34 +0300 |
commit | 70ff63e63fc3a63dccc6a6c567bbc347c64d6c7d (patch) | |
tree | 76934061ddae6dc4091541f5ee227bedc0346ad6 /source/blender/windowmanager/intern/wm_stereo.c | |
parent | 0c6939f5f597e4e7fe5777de7a49b49ff53fa987 (diff) |
OpenGL: tweak image shaders & code that uses them
- rename image shaders to describe exactly what they do
- rename inputs to match other built-in shaders
- set & use active texture unit
- no need to enable/disable textures with GLSL
- pull vertex format setup out of loops
Diffstat (limited to 'source/blender/windowmanager/intern/wm_stereo.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_stereo.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/source/blender/windowmanager/intern/wm_stereo.c b/source/blender/windowmanager/intern/wm_stereo.c index e2b6df65ce8..c72bd676364 100644 --- a/source/blender/windowmanager/intern/wm_stereo.c +++ b/source/blender/windowmanager/intern/wm_stereo.c @@ -173,6 +173,13 @@ static void wm_method_draw_stereo3d_sidebyside(wmWindow *win) int soffx; bool cross_eyed = (win->stereo3d_format->flag & S3D_SIDEBYSIDE_CROSSEYED) != 0; + const int activeTex = GL_TEXTURE0; + glActiveTexture(activeTex); + + VertexFormat *format = immVertexFormat(); + unsigned texcoord = add_attrib(format, "texCoord", GL_FLOAT, 2, KEEP_FLOAT); + unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT); + for (view = 0; view < 2; view ++) { drawdata = BLI_findlink(&win->drawdata, (view * 2) + 1); triple = drawdata->triple; @@ -204,16 +211,12 @@ static void wm_method_draw_stereo3d_sidebyside(wmWindow *win) halfy /= triple->y; } - VertexFormat *format = immVertexFormat(); - unsigned texcoord = add_attrib(format, "texcoord", GL_FLOAT, 2, KEEP_FLOAT); - unsigned pos = add_attrib(format, "position", GL_FLOAT, 2, KEEP_FLOAT); - - glEnable(triple->target); - immBindBuiltinProgram((triple->target == GL_TEXTURE_2D) ? GPU_SHADER_2D_TEXTURE_2D : GPU_SHADER_2D_TEXTURE_RECT); + /* TODO: if target is always same for both eyes, bind program & set uniform before loop */ + immBindBuiltinProgram((triple->target == GL_TEXTURE_2D) ? GPU_SHADER_3D_IMAGE_MODULATE_ALPHA : GPU_SHADER_3D_IMAGE_RECT_MODULATE_ALPHA); glBindTexture(triple->target, triple->bind); - immUniform1i("texture_map", 0); + immUniform1i("image", activeTex); immBegin(GL_QUADS, 4); @@ -230,10 +233,10 @@ static void wm_method_draw_stereo3d_sidebyside(wmWindow *win) immVertex2f(pos, soffx, sizey); immEnd(); - immUnbindProgram(); + /* TODO: if target is always same for both eyes, unbind program & texture target after loop */ glBindTexture(triple->target, 0); - glDisable(triple->target); + immUnbindProgram(); } } @@ -245,6 +248,13 @@ static void wm_method_draw_stereo3d_topbottom(wmWindow *win) int view; int soffy; + const int activeTex = GL_TEXTURE0; + glActiveTexture(activeTex); + + VertexFormat *format = immVertexFormat(); + unsigned texcoord = add_attrib(format, "texCoord", GL_FLOAT, 2, KEEP_FLOAT); + unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT); + for (view = 0; view < 2; view ++) { drawdata = BLI_findlink(&win->drawdata, (view * 2) + 1); triple = drawdata->triple; @@ -273,17 +283,13 @@ static void wm_method_draw_stereo3d_topbottom(wmWindow *win) halfy /= triple->y; } - VertexFormat *format = immVertexFormat(); - unsigned texcoord = add_attrib(format, "texcoord", GL_FLOAT, 2, KEEP_FLOAT); - unsigned pos = add_attrib(format, "position", GL_FLOAT, 2, KEEP_FLOAT); - - glEnable(triple->target); - immBindBuiltinProgram((triple->target == GL_TEXTURE_2D) ? GPU_SHADER_2D_TEXTURE_2D : GPU_SHADER_2D_TEXTURE_RECT); + /* TODO: if target is always same for both eyes, bind program & set uniforms before loop */ + immBindBuiltinProgram((triple->target == GL_TEXTURE_2D) ? GPU_SHADER_3D_IMAGE_MODULATE_ALPHA : GPU_SHADER_3D_IMAGE_RECT_MODULATE_ALPHA); glBindTexture(triple->target, triple->bind); immUniform1f("alpha", 1.0f); - immUniform1i("texture_map", 0); + immUniform1i("image", activeTex); immBegin(GL_QUADS, 4); @@ -300,10 +306,10 @@ static void wm_method_draw_stereo3d_topbottom(wmWindow *win) immVertex2f(pos, 0.0f, soffy + (sizey * 0.5f)); immEnd(); - immUnbindProgram(); + /* TODO: if target is always same for both eyes, unbind program & texture target after loop */ + immUnbindProgram(); glBindTexture(triple->target, 0); - glDisable(triple->target); } } |