Commit: 09bfc378895f320bcc12ac5c77252f58780e73fc
Author: Mike Erwin
Date:   Sun Feb 12 01:29:59 2017 -0500
Branches: blender2.8
https://developer.blender.org/rB09bfc378895f320bcc12ac5c77252f58780e73fc

OpenGL: convert NLA editor to new imm mode

Plus plenty of C99 cleanup.

Part of T49043. Needs more testing, I don't really use the NLA editor.

===================================================================

M       source/blender/editors/space_nla/nla_draw.c

===================================================================

diff --git a/source/blender/editors/space_nla/nla_draw.c 
b/source/blender/editors/space_nla/nla_draw.c
index 9d34b6c4e2..86eae70c0f 100644
--- a/source/blender/editors/space_nla/nla_draw.c
+++ b/source/blender/editors/space_nla/nla_draw.c
@@ -54,7 +54,6 @@
 #include "ED_anim_api.h"
 #include "ED_keyframes_draw.h"
 
-#include "BIF_gl.h"
 #include "BIF_glutil.h"
 
 #include "GPU_immediate.h"
@@ -109,7 +108,7 @@ static void nla_action_draw_keyframes(AnimData *adt, 
bAction *act, float y, floa
        action_to_keylist(adt, act, &keys, NULL);
        BLI_dlrbTree_linkedlist_sync(&keys);
 
-       if (ELEM(NULL, act, keys.first))
+       if (!(act && keys.first))
                return;
 
        /* draw a darkened region behind the strips 
@@ -168,57 +167,55 @@ static void nla_action_draw_keyframes(AnimData *adt, 
bAction *act, float y, floa
 /* Strip Markers ------------------------ */
 
 /* Markers inside an action strip */
-static void nla_actionclip_draw_markers(NlaStrip *strip, float yminc, float 
ymaxc)
+static void nla_actionclip_draw_markers(NlaStrip *strip, float yminc, float 
ymaxc, int shade, unsigned int pos)
 {
-       bAction *act = strip->act;
-       TimeMarker *marker;
-       
-       if (ELEM(NULL, strip->act, strip->act->markers.first))
+       const bAction *act = strip->act;
+
+       if (!(act && act->markers.first))
                return;
-       
-       for (marker = act->markers.first; marker; marker = marker->next) {
+
+       immUniformThemeColorShade(TH_STRIP_SELECT, shade);
+
+       immBeginAtMost(PRIM_POINTS, BLI_listbase_count(&act->markers));
+       for (TimeMarker *marker = act->markers.first; marker; marker = 
marker->next) {
                if ((marker->frame > strip->actstart) && (marker->frame < 
strip->actend)) {
                        float frame = nlastrip_get_frame(strip, marker->frame, 
NLATIME_CONVERT_MAP);
-                       
+
                        /* just a simple line for now */
-                       // XXX: draw a triangle instead...
-                       fdrawline(frame, yminc + 1, frame, ymaxc - 1);
+                       /* XXX: draw a triangle instead... */
+                       immVertex2f(pos, frame, yminc + 1);
+                       immVertex2f(pos, frame, ymaxc - 1);
                }
        }
+       immEnd();
 }
 
 /* Markers inside a NLA-Strip */
-static void nla_strip_draw_markers(NlaStrip *strip, float yminc, float ymaxc)
+static void nla_strip_draw_markers(NlaStrip *strip, float yminc, float ymaxc, 
unsigned int pos)
 {
        glLineWidth(2.0f);
        
        if (strip->type == NLASTRIP_TYPE_CLIP) {
                /* try not to be too conspicuous, while being visible enough 
when transforming */
-               if (strip->flag & NLASTRIP_FLAG_SELECT)
-                       UI_ThemeColorShade(TH_STRIP_SELECT, -60);
-               else
-                       UI_ThemeColorShade(TH_STRIP_SELECT, -40);
-               
+               int shade = (strip->flag & NLASTRIP_FLAG_SELECT) ? -60 : -40;
+
                setlinestyle(3);
                
                /* just draw the markers in this clip */
-               nla_actionclip_draw_markers(strip, yminc, ymaxc);
+               nla_actionclip_draw_markers(strip, yminc, ymaxc, shade, pos);
                
                setlinestyle(0);
        }
        else if (strip->flag & NLASTRIP_FLAG_TEMP_META) {
                /* just a solid color, so that it is very easy to spot */
-               UI_ThemeColorShade(TH_STRIP_SELECT, 20);
-               
+               int shade = 20;
                /* draw the markers in the first level of strips only (if they 
are actions) */
                for (NlaStrip *nls = strip->strips.first; nls; nls = nls->next) 
{
                        if (nls->type == NLASTRIP_TYPE_CLIP) {
-                               nla_actionclip_draw_markers(nls, yminc, ymaxc);
+                               nla_actionclip_draw_markers(nls, yminc, ymaxc, 
shade, pos);
                        }
                }
        }
-       
-       glLineWidth(1.0);
 }
 
 /* Strips (Proper) ---------------------- */
@@ -286,12 +283,8 @@ static void nla_strip_get_color_inside(AnimData *adt, 
NlaStrip *strip, float col
 }
 
 /* helper call for drawing influence/time control curves for a given NLA-strip 
*/
-static void nla_draw_strip_curves(NlaStrip *strip, float yminc, float ymaxc)
+static void nla_draw_strip_curves(NlaStrip *strip, float yminc, float ymaxc, 
unsigned int pos)
 {
-
-       VertexFormat *format = immVertexFormat();
-       unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
-       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
        immUniformColor4f(0.7f, 0.7f, 0.7f, 1.0f);
 
        const float yheight = ymaxc - yminc;
@@ -312,7 +305,7 @@ static void nla_draw_strip_curves(NlaStrip *strip, float 
yminc, float ymaxc)
                 *      - min y-val is yminc, max is y-maxc, so clamp in those 
regions
                 */
                for (cfra = strip->start; cfra <= strip->end; cfra += 1.0f) {
-                       float y = evaluate_fcurve(fcu, cfra);    // assume this 
to be in 0-1 range
+                       float y = evaluate_fcurve(fcu, cfra); /* assume this to 
be in 0-1 range */
                        immVertex2f(pos, cfra, ((y * yheight) + yminc));
                }
 
@@ -346,9 +339,6 @@ static void nla_draw_strip_curves(NlaStrip *strip, float 
yminc, float ymaxc)
        /* turn off AA'd lines */
        glDisable(GL_LINE_SMOOTH);
        glDisable(GL_BLEND);
-
-       //Unbind GPU_SHADER_2D_UNIFORM_COLOR
-       immUnbindProgram();
 }
 
 /* main call for drawing a single NLA-strip */
@@ -356,10 +346,13 @@ static void nla_draw_strip(SpaceNla *snla, AnimData *adt, 
NlaTrack *nlt, NlaStri
 {
        const bool non_solo = ((adt && (adt->flag & ADT_NLA_SOLO_TRACK)) && 
(nlt->flag & NLATRACK_SOLO) == 0);
        float color[4] = {1.0f, 1.0f, 1.0f, 1.0f};
-       
+
        /* get color of strip */
        nla_strip_get_color_inside(adt, strip, color);
-       
+
+       unsigned int pos = add_attrib(immVertexFormat(), "pos", COMP_F32, 2, 
KEEP_FLOAT);
+       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
        /* draw extrapolation info first (as backdrop)
         *      - but this should only be drawn if track has some contribution
         */
@@ -367,7 +360,7 @@ static void nla_draw_strip(SpaceNla *snla, AnimData *adt, 
NlaTrack *nlt, NlaStri
                /* enable transparency... */
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                glEnable(GL_BLEND);
-               
+
                switch (strip->extendmode) {
                        /* since this does both sides, only do the 'before' 
side, and leave the rest to the next case */
                        case NLASTRIP_EXTEND_HOLD: 
@@ -376,15 +369,10 @@ static void nla_draw_strip(SpaceNla *snla, AnimData *adt, 
NlaTrack *nlt, NlaStri
                                 */
                                if (strip->prev == NULL) {
                                        /* set the drawing color to the color 
of the strip, but with very faint alpha */
-                                       glColor4f(color[0], color[1], color[2], 
0.15f);
-                                       
+                                       immUniformColor3fvAlpha(color, 0.15f);
+
                                        /* draw the rect to the edge of the 
screen */
-                                       glBegin(GL_QUADS);
-                                       glVertex2f(v2d->cur.xmin, yminc);
-                                       glVertex2f(v2d->cur.xmin, ymaxc);
-                                       glVertex2f(strip->start, ymaxc);
-                                       glVertex2f(strip->start, yminc);
-                                       glEnd();
+                                       immRectf(pos, v2d->cur.xmin, yminc, 
strip->start, ymaxc);
                                }
                                /* fall-through */
 
@@ -393,121 +381,132 @@ static void nla_draw_strip(SpaceNla *snla, AnimData 
*adt, NlaTrack *nlt, NlaStri
                                /* only need to try and draw if the next strip 
doesn't occur immediately after */
                                if ((strip->next == NULL) || 
(IS_EQF(strip->next->start, strip->end) == 0)) {
                                        /* set the drawing color to the color 
of the strip, but this time less faint */
-                                       glColor4f(color[0], color[1], color[2], 
0.3f);
+                                       immUniformColor3fvAlpha(color, 0.3f);
                                        
                                        /* draw the rect to the next strip or 
the edge of the screen */
-                                       glBegin(GL_QUADS);
-                                       glVertex2f(strip->end, yminc);
-                                       glVertex2f(strip->end, ymaxc);
-                                               
-                                       if (strip->next) {
-                                               glVertex2f(strip->next->start, 
ymaxc);
-                                               glVertex2f(strip->next->start, 
yminc);
-                                       }
-                                       else {
-                                               glVertex2f(v2d->cur.xmax, 
ymaxc);
-                                               glVertex2f(v2d->cur.xmax, 
yminc);
-                                       }
-                                       glEnd();
+                                       float x2 = strip->next ? 
strip->next->start : v2d->cur.xmax;
+                                       immRectf(pos, strip->end, yminc, x2, 
ymaxc);
                                }
                                break;
                }
-               
+
                glDisable(GL_BLEND);
        }
-       
-       
+
+
        /* draw 'inside' of strip itself */
        if (non_solo == 0) {
+               immUnbindProgram();
+
                /* strip is in normal track */
                UI_draw_roundbox_corner_set(UI_CNR_ALL); /* all corners rounded 
*/
-               
                UI_draw_roundbox_shade_x(GL_TRIANGLE_FAN, strip->start, yminc, 
strip->end, ymaxc, 0.0, 0.5, 0.1, color);
+
+               /* restore current vertex format & program (roundbox trashes 
it) */
+               pos = add_attrib(immVertexFormat(), "pos", COMP_F32, 2, 
KEEP_FLOAT);
+               immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
        }
        else {
                /* strip is in disabled track - make less visible */
-               glColor4f(color[0], color[1], color[2], 0.1f);
+               immUniformColor3fvAlpha(color, 0.1f);
                
                glEnable(GL_BLEND);
-               glRectf(strip->start, yminc, strip->end, ymaxc);
+               immRectf(pos, strip->start, yminc, strip->end, ymaxc);
                glDisable(GL_BLEND);
        }
-       
-       
+
+
        /* draw strip's control 'curves'
         *      - only if user hasn't hidden them...
         */
        if ((snla->flag & SNLA_NOSTRIPCURVES) == 0)
-               nla_draw_strip_curves(strip, yminc, ymaxc);
-       
-       
+               nla_draw_strip_curves(strip, yminc, ymaxc, pos);
+
+
        /* draw markings indicating locations of local markers (useful for 
lining up different actions) */
        if ((snla->flag & SNLA_NOLOCALMARKERS) == 0)
-               nla_strip_draw_markers(strip, yminc, ymaxc);
-       
-       /* draw strip outline 
+               nla_strip_draw_markers(strip, yminc, ymaxc, pos);
+
+       immUnbindProgram();
+
+       /* draw strip outline
         *      - color used here is to indicate active vs non-active
         */
        if (strip->flag & NLASTRIP_FLAG_ACTIVE) {
                /* strip should appear 'sunken', so draw a light border around 
it */
-               glColor3f(0.9f, 1.0f, 0.9f); // FIXME: hardcoded temp-hack 
colors
-               color[0] = 0.9f;
+               color[0] = 0.9f; /* FIXME: hardcoded temp-hack colors */
                color[1] = 1.0f;
                color[2] = 0.9f;
        }
        else {
                /* strip should appear to stand out, so draw a dark border 
around it */
-               glColor3f(0.0f, 0.0f, 0.0f);
-               color[0] = color[1] = color[2] = 1.0f;
+               color[0] = color[1] = color[2] = 0.0f; /* FIXME: or 1.0f ?? */
        }
-       
+
        /* - line style: dotted for muted */
        if ((nlt->flag & NLATRACK_MUTED) || (strip->flag & NLASTRIP_FLAG_MUTED))
                setlinestyle(4);
-               
+
        /* draw outline */
        UI_draw_roundbox_shade_x(GL_LINE_LOOP, strip->start, yminc, strip->end, 
ymaxc, 0.0, 0.0, 0.1, color);
-       
+
+       /* restore current vertex format & program (roundbox trashes it) */
+       pos = add_attrib(immVertexFormat(), "pos", COMP_F32, 2, KEEP_FLOAT);
+       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+       immUniformColor3fv(color);
+
        /* if action-clip strip, draw lines delimiting repeats too (in the same 
color as outline) */
        if ((strip->type == NLASTRIP_TYPE_CLIP) && IS_EQF(strip->repeat, 1.0f) 
== 0) {
                float repeatLen = (strip->actend - strip->actstart) * strip->s

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to