diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2016-10-24 20:01:25 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2016-10-24 20:26:27 +0300 |
commit | 744718f6356ece21bf90c54550b39d56cf0a356e (patch) | |
tree | 5e5f7e24d92d8376d534e3d85c415f5d541de10e /source/blender/editors/space_view3d/view3d_draw_legacy.c | |
parent | a3b69c8131e4e680cc8ae1c88fad90b796af20d3 (diff) |
immediate mode: background
There is a problem here, which is that we can't use immediate mode here
until we rely on `GPU_material_bind`.
(cc: @merwin)
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_draw_legacy.c')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw_legacy.c | 75 |
1 files changed, 53 insertions, 22 deletions
diff --git a/source/blender/editors/space_view3d/view3d_draw_legacy.c b/source/blender/editors/space_view3d/view3d_draw_legacy.c index 2e40113feba..c260ab22d1b 100644 --- a/source/blender/editors/space_view3d/view3d_draw_legacy.c +++ b/source/blender/editors/space_view3d/view3d_draw_legacy.c @@ -2254,34 +2254,50 @@ static void view3d_main_region_clear(Scene *scene, View3D *v3d, ARegion *ar) bool material_not_bound = !GPU_material_bound(gpumat); + /* Draw world */ + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_ALWAYS); + if (material_not_bound) { + GPU_material_unbind(gpumat); + glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); - glColor4f(0.0f, 0.0f, 0.0f, 1.0f); - } - /* Draw world */ - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_ALWAYS); - glBegin(GL_TRIANGLE_STRIP); - glVertex3f(-1.0, -1.0, 1.0); - glVertex3f(1.0, -1.0, 1.0); - glVertex3f(-1.0, 1.0, 1.0); - glVertex3f(1.0, 1.0, 1.0); - glEnd(); + unsigned pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 3, KEEP_FLOAT); + immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); + immUniformColor4ub(0.0f, 0.0f, 0.0f, 1.0f); + + immBegin(GL_TRIANGLE_STRIP, 4); + immVertex3f(pos, -1.0f, -1.0f, 1.0f); + immVertex3f(pos, 1.0f, -1.0f, 1.0f); + immVertex3f(pos, -1.0f, 1.0f, 1.0f); + immVertex3f(pos, 1.0f, 1.0f, 1.0f); + immEnd(); + + immUnbindProgram(); - if (material_not_bound) { glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); } - - GPU_material_unbind(gpumat); + else { + /* TODO viewport (dfelinto): GPU_material_bind relies on immediate mode, + * we can't get rid of the following code without a bigger refactor + * or we dropping this functionality. */ + glBegin(GL_TRIANGLE_STRIP); + glVertex3f(-1.0f, -1.0f, 1.0f); + glVertex3f(1.0f, -1.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); + glVertex3f(1.0f, 1.0f, 1.0f); + glEnd(); + GPU_material_unbind(gpumat); + } glDepthFunc(GL_LEQUAL); glDisable(GL_DEPTH_TEST); @@ -2297,14 +2313,29 @@ static void view3d_main_region_clear(Scene *scene, View3D *v3d, ARegion *ar) glEnable(GL_DEPTH_TEST); glDepthFunc(GL_ALWAYS); - glBegin(GL_QUADS); - UI_ThemeColor(TH_LOW_GRAD); - glVertex3f(-1.0, -1.0, 1.0); - glVertex3f(1.0, -1.0, 1.0); - UI_ThemeColor(TH_HIGH_GRAD); - glVertex3f(1.0, 1.0, 1.0); - glVertex3f(-1.0, 1.0, 1.0); - glEnd(); + + VertexFormat *format = immVertexFormat(); + unsigned pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT); + unsigned color = add_attrib(format, "color", GL_UNSIGNED_BYTE, 3, NORMALIZE_INT_TO_FLOAT); + unsigned char col_hi[3], col_lo[3]; + + immBindBuiltinProgram(GPU_SHADER_3D_FLAT_COLOR); + + UI_GetThemeColor3ubv(TH_LOW_GRAD, col_lo); + UI_GetThemeColor3ubv(TH_LOW_GRAD, col_hi); + + immBegin(GL_QUADS, 4); + immAttrib3ubv(color, col_lo); + immVertex3f(pos, -1.0f, -1.0f, 1.0f); + immVertex3f(pos, 1.0f, -1.0f, 1.0f); + + immAttrib3ubv(color, col_hi); + immVertex3f(pos, 1.0f, 1.0f, 1.0f); + immVertex3f(pos, -1.0f, 1.0f, 1.0f); + immEnd(); + + immUnbindProgram(); + glDepthFunc(GL_LEQUAL); glDisable(GL_DEPTH_TEST); |