blender 2.8: OpenGL immediate mode: anim_draw
authorMike Erwin <significant.bit@gmail.com>
Tue, 15 Nov 2016 17:16:47 +0000 (12:16 -0500)
committerMike Erwin <significant.bit@gmail.com>
Tue, 15 Nov 2016 17:19:47 +0000 (12:19 -0500)
Reviewers: merwin

Reviewed By: merwin

Maniphest Tasks: T49043

Differential Revision: https://developer.blender.org/D2353

source/blender/editors/animation/anim_draw.c

index 33e44d738945bfe9036828c180b08e337c535c4c..58b9b8eba91bd6af962e9f3ef06df473933d80e0 100644 (file)
@@ -62,6 +62,8 @@
 #include "UI_resources.h"
 #include "UI_view2d.h"
 
+#include "GPU_immediate.h"
+
 /* *************************************************** */
 /* CURRENT FRAME DRAWING */
 
@@ -95,9 +97,16 @@ static void draw_cfra_number(Scene *scene, View2D *v2d, const float cfra, const
        x = cfra * xscale;
        y = 0.9f * U.widget_unit;
        
+       VertexFormat *format = immVertexFormat();
+       unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+
+       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
        /* draw green box around/behind text */
-       UI_ThemeColorShade(TH_CFRAME, 0);
-       glRectf(x, y,  x + slen,  y + 0.75f * U.widget_unit);
+       immUniformThemeColorShade(TH_CFRAME, 0);
+
+       immRectf(pos, x, y,  x + slen,  y + 0.75f * U.widget_unit);
+       immUnbindProgram();
        
        /* draw current frame number - black text */
        UI_ThemeColor(TH_TEXT);
@@ -112,17 +121,23 @@ void ANIM_draw_cfra(const bContext *C, View2D *v2d, short flag)
 {
        Scene *scene = CTX_data_scene(C);
 
-       /* Draw a light green line to indicate current frame */
-       UI_ThemeColor(TH_CFRAME);
-
        const float x = (float)(scene->r.cfra * scene->r.framelen);
 
        glLineWidth((flag & DRAWCFRA_WIDE) ? 3.0 : 2.0);
 
-       glBegin(GL_LINES);
-       glVertex2f(x, v2d->cur.ymin - 500.0f); /* XXX arbitrary... want it go to bottom */
-       glVertex2f(x, v2d->cur.ymax);
-       glEnd();
+       VertexFormat *format = immVertexFormat();
+       unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+
+       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+       /* Draw a light green line to indicate current frame */
+       immUniformThemeColor(TH_CFRAME);
+
+       immBegin(GL_LINES, 2);
+       immVertex2f(pos, x, v2d->cur.ymin - 500.0f); /* XXX arbitrary... want it go to bottom */
+       immVertex2f(pos, x, v2d->cur.ymax);
+       immEnd();
+       immUnbindProgram();
 
        /* Draw current frame number in a little box */
        if (flag & DRAWCFRA_SHOW_NUMBOX) {
@@ -144,17 +159,24 @@ void ANIM_draw_previewrange(const bContext *C, View2D *v2d, int end_frame_width)
        if (PRVRANGEON) {
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                glEnable(GL_BLEND);
-               glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
-               
+
+               VertexFormat *format = immVertexFormat();
+               unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+
+               immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+               immUniformColor4f(0.0f, 0.0f, 0.0f, 0.4f);
+
                /* only draw two separate 'curtains' if there's no overlap between them */
                if (PSFRA < PEFRA + end_frame_width) {
-                       glRectf(v2d->cur.xmin, v2d->cur.ymin, (float)PSFRA, v2d->cur.ymax);
-                       glRectf((float)(PEFRA + end_frame_width), v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
+                       immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, (float)PSFRA, v2d->cur.ymax);
+                       immRectf(pos, (float)(PEFRA + end_frame_width), v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
                }
                else {
-                       glRectf(v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
+                       immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
                }
-               
+
+               immUnbindProgram();
+
                glDisable(GL_BLEND);
        }
 }