OpenGL: transition away from GL_QUADS
authorMike Erwin <significant.bit@gmail.com>
Fri, 7 Apr 2017 19:03:24 +0000 (15:03 -0400)
committerMike Erwin <significant.bit@gmail.com>
Fri, 7 Apr 2017 19:03:24 +0000 (15:03 -0400)
Single quads are drawn as a TRIANGLE_FAN, with 4 verts in the same order.

Multiple quads now use PRIM_QUADS_XXX and will need further work. Only 8 places still use this.

Part of T49043

14 files changed:
source/blender/blenfont/intern/blf_font.c
source/blender/draw/intern/draw_view.c
source/blender/editors/gpencil/drawgpencil.c
source/blender/editors/interface/interface_draw.c
source/blender/editors/sculpt_paint/paint_cursor.c
source/blender/editors/space_clip/clip_draw.c
source/blender/editors/space_outliner/outliner_draw.c
source/blender/editors/space_sequencer/sequencer_draw.c
source/blender/editors/space_time/space_time.c
source/blender/editors/space_view3d/drawobject.c
source/blender/windowmanager/intern/wm_draw.c
source/blender/windowmanager/intern/wm_gesture.c
source/blender/windowmanager/intern/wm_operators.c
source/blender/windowmanager/intern/wm_stereo.c

index d0293eccf3ad2543ef7f38d006c90f3d48db07fe..3702c70be35e1e57558637c703f698c6ef6bccb5 100644 (file)
@@ -206,7 +206,7 @@ static void blf_font_draw_ex(
 
        blf_font_ensure_ascii_table(font);
 
-       immBeginAtMost(GL_QUADS, verts_needed(font, str, len));
+       immBeginAtMost(PRIM_QUADS_XXX, verts_needed(font, str, len));
        /* at most because some glyphs might be clipped & not drawn */
 
        while ((i < len) && str[i]) {
@@ -253,7 +253,7 @@ static void blf_font_draw_ascii_ex(
 
        blf_font_ensure_ascii_table(font);
 
-       immBeginAtMost(GL_QUADS, verts_needed(font, str, len));
+       immBeginAtMost(PRIM_QUADS_XXX, verts_needed(font, str, len));
 
        while ((c = *(str++)) && len--) {
                BLI_assert(c < 128);
@@ -293,7 +293,7 @@ int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth)
 
        blf_font_ensure_ascii_table(font);
 
-       immBeginAtMost(GL_QUADS, verts_needed(font, str, len));
+       immBeginAtMost(PRIM_QUADS_XXX, verts_needed(font, str, len));
 
        while ((i < len) && str[i]) {
                BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
index a0f0fb1a9ee851c7d2a83665718c746d20c8ec2f..b5f4a13587d9b421075b82cade4213cd2c1743ee 100644 (file)
@@ -568,7 +568,7 @@ void DRW_draw_background(void)
                UI_GetThemeColor3ubv(TH_LOW_GRAD, col_lo);
                UI_GetThemeColor3ubv(TH_HIGH_GRAD, col_hi);
 
-               immBegin(GL_QUADS, 4);
+               immBegin(PRIM_TRIANGLE_FAN, 4);
                immAttrib3ubv(color, col_lo);
                immVertex2f(pos, -1.0f, -1.0f);
                immVertex2f(pos, 1.0f, -1.0f);
index 229aecc21ae813fbbc0d8880b50f5aeacefa4282..7e33de7b27117a0ad1bf2740ea0343677609da47 100644 (file)
@@ -740,7 +740,7 @@ static void gp_draw_stroke_2d(const bGPDspoint *points, int totpoints, short thi
                unsigned int color = VertexFormat_add_attrib(format, "color", COMP_U8, 4, NORMALIZE_INT_TO_FLOAT);
 
                immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
-               immBegin(GL_QUADS, (totpoints - 2) * 4 + 12);
+               immBegin(PRIM_QUADS_XXX, (totpoints - 2) * 4 + 12);
 
                for (i = 0, pt1 = points, pt2 = points + 1; i < (totpoints - 1); i++, pt1++, pt2++) {
                        float s0[2], s1[2];     /* segment 'center' points */
index 89d9fe992baf584049bc94eb8244a63610ac4f18..5e4cb9c1ba1bf9f495173882577901a028e36cb7 100644 (file)
@@ -1195,7 +1195,7 @@ static void ui_draw_colorband_handle_tri(unsigned int pos, float x1, float y1, f
 
 static void ui_draw_colorband_handle_box(unsigned int pos, float x1, float y1, float x2, float y2, bool fill)
 {
-       immBegin(fill ? GL_QUADS : GL_LINE_LOOP, 4);
+       immBegin(fill ? PRIM_TRIANGLE_FAN : PRIM_LINE_LOOP, 4);
        immVertex2f(pos, x1, y1);
        immVertex2f(pos, x1, y2);
        immVertex2f(pos, x2, y2);
@@ -1916,6 +1916,9 @@ void ui_draw_but_NODESOCKET(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol
 
 /* ****************************************************** */
 
+/* TODO: high quality UI drop shadows using GLSL shader and single draw call
+ * would replace / modify the following 3 functions  - merwin
+ */
 
 static void ui_shadowbox(unsigned pos, unsigned color, float minx, float miny, float maxx, float maxy, float shadsize, unsigned char alpha)
 {
@@ -1954,7 +1957,7 @@ void UI_draw_box_shadow(unsigned char alpha, float minx, float miny, float maxx,
 
        immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
 
-       immBegin(GL_QUADS, 36);
+       immBegin(PRIM_QUADS_XXX, 36);
 
        /* accumulated outline boxes to make shade not linear, is more pleasant */
        ui_shadowbox(pos, color, minx, miny, maxx, maxy, 11.0, (20 * alpha) >> 8);
index 44ef95ee0b60c4ef48e5cc7234f548c4a1abad38..9405de93cc5337d805431e5f7a91659e443fdf38 100644 (file)
@@ -684,7 +684,7 @@ static void paint_draw_tex_overlay(UnifiedPaintSettings *ups, Brush *brush,
                /* draw textured quad */
                immUniform1i("image", GL_TEXTURE0);
 
-               immBegin(GL_QUADS, 4);
+               immBegin(PRIM_TRIANGLE_FAN, 4);
                immAttrib2f(texCoord, 0.0f, 0.0f);
                immVertex2f(pos, quad.xmin, quad.ymin);
                immAttrib2f(texCoord, 1.0f, 0.0f);
@@ -773,7 +773,7 @@ static void paint_draw_cursor_overlay(UnifiedPaintSettings *ups, Brush *brush,
                /* draw textured quad */
                immUniform1i("image", GL_TEXTURE0);
 
-               immBegin(GL_QUADS, 4);
+               immBegin(PRIM_TRIANGLE_FAN, 4);
                immAttrib2f(texCoord, 0.0f, 0.0f);
                immVertex2f(pos, quad.xmin, quad.ymin);
                immAttrib2f(texCoord, 1.0f, 0.0f);
index dc40f083bc6686f51b24200bf8f090e9e4e9de4c..274e9b0f68418f970181e8c109876fac94fe120d 100644 (file)
@@ -1108,7 +1108,7 @@ static void draw_plane_marker_image(Scene *scene,
                        immUniform4f("color", 1.0f, 1.0f, 1.0f, plane_track->image_opacity);
                        immUniform1i("image", GL_TEXTURE0);
 
-                       immBegin(GL_QUADS, 4);
+                       immBegin(PRIM_TRIANGLE_FAN, 4);
 
                        immAttrib2f(texCoord, 0.0f, 0.0f);
                        immVertex2f(pos, 0.0f, 0.0f);
index cfe6e6a2bb5fc061466f0d089734952e192c00fc..92193e93fbee26db569bc0b5acad5516abe29e79 100644 (file)
@@ -1799,7 +1799,7 @@ static void outliner_back(ARegion *ar)
        int tot = (int)floor(ystart - ar->v2d.cur.ymin + 2 * UI_UNIT_Y) / (2 * UI_UNIT_Y);
 
        if (tot > 0) {
-               immBegin(GL_QUADS, 4 * tot);
+               immBegin(PRIM_QUADS_XXX, 4 * tot);
                while (tot--) {
                        y1 -= 2 * UI_UNIT_Y;
                        y2 = y1 + UI_UNIT_Y;
index a7a638d0952ada485ef034f619eb9570a307a70e..13847efd22aa8daf2e1e712bd7c72ddd4852a785 100644 (file)
@@ -1313,7 +1313,7 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
        immUniform4f("color", 1.0f, 1.0f, 1.0f, 1.0f);
        immUniform1i("image", GL_TEXTURE0);
 
-       immBegin(GL_QUADS, 4);
+       immBegin(PRIM_TRIANGLE_FAN, 4);
 
        if (draw_overlay) {
                if (sseq->overlay_type == SEQ_DRAW_OVERLAY_RECT) {
index 9844a8053dbd4824756ef9f61c85b4613239c279..7dbf99dda90ba95ceed729514b36136e7d18e5bb 100644 (file)
@@ -215,7 +215,7 @@ static void time_draw_cache(SpaceTime *stime, Object *ob, Scene *scene)
                immUniformColor4fv(col);
 
                if (len > 0) {
-                       immBeginAtMost(GL_QUADS, len);
+                       immBeginAtMost(PRIM_QUADS_XXX, len);
 
                        /* draw a quad for each cached frame */
                        for (int i = sta; i <= end; i++) {
index 726a67a5d74db7172afe50c95a446ccea43ca83e..291592a0a4ca06903614c3478f43ef31c70550a3 100644 (file)
@@ -1876,7 +1876,7 @@ static void draw_viewport_reconstruction(
 /* camera frame */
 static void drawcamera_frame(float vec[4][3], bool filled, unsigned pos)
 {
-       immBegin(filled ? GL_QUADS : GL_LINE_LOOP, 4);
+       immBegin(filled ? PRIM_TRIANGLE_FAN : PRIM_LINE_LOOP, 4);
        immVertex3fv(pos, vec[0]);
        immVertex3fv(pos, vec[1]);
        immVertex3fv(pos, vec[2]);
@@ -1905,7 +1905,7 @@ static void drawcamera_volume(float near_plane[4][3], float far_plane[4][3], boo
        drawcamera_frame(far_plane, filled, pos);
 
        if (filled) {
-               immBegin(GL_QUADS, 16); /* TODO(merwin): use GL_TRIANGLE_STRIP here */
+               immBegin(PRIM_QUADS_XXX, 16); /* TODO(merwin): use PRIM_TRIANGLE_STRIP here */
                immVertex3fv(pos, near_plane[0]);
                immVertex3fv(pos, far_plane[0]);
                immVertex3fv(pos, far_plane[1]);
@@ -5582,7 +5582,7 @@ static bool drawDispList(Scene *scene, SceneLayer *sl, View3D *v3d, RegionView3D
 /* *********** drawing for particles ************* */
 /* stride :   offset size in bytes
  * col[4] :   the color to use when *color is NULL, can be also NULL */
-static void draw_vertex_array(int dt, const float *vert, const float *nor, const float *color, int stride, int vert_ct, float col[4])
+static void draw_vertex_array(PrimitiveType prim_type, const float *vert, const float *nor, const float *color, int stride, int vert_ct, float col[4])
 {
        VertexFormat format = {0};
        unsigned int pos_id, nor_id, col_id;
@@ -5604,7 +5604,7 @@ static void draw_vertex_array(int dt, const float *vert, const float *nor, const
                if (color) VertexBuffer_fill_attrib_stride(vbo, col_id, stride, color);
        }
 
-       Batch *batch = Batch_create(dt, vbo, NULL);
+       Batch *batch = Batch_create(prim_type, vbo, NULL);
        if (nor && color) {
                Batch_set_builtin_program(batch, GPU_SHADER_SIMPLE_LIGHTING_SMOOTH_COLOR);
                Batch_Uniform3f(batch, "light", 0.0f, 0.0f, 1.0f);
@@ -5624,6 +5624,7 @@ static void draw_vertex_array(int dt, const float *vert, const float *nor, const
        Batch_draw(batch);
        Batch_discard_all(batch);
 }
+
 static void draw_particle_arrays_new(int draw_as, int ob_dt, int select,
                                      const float *vert, const float *nor, const float *color,
                                      int totpoint, float col[4])
@@ -5643,7 +5644,7 @@ static void draw_particle_arrays_new(int draw_as, int ob_dt, int select,
                        else
                                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
-                       draw_vertex_array(GL_QUADS, vert, nor, color, 0, 4 * totpoint, col);
+                       draw_vertex_array(PRIM_QUADS_XXX, vert, nor, color, 0, 4 * totpoint, col);
                        break;
                default:
                        draw_vertex_array(GL_POINTS, vert, nor, color, 0, totpoint, col);
@@ -8000,11 +8001,11 @@ static void imm_draw_box(const float vec[8][3], bool solid, unsigned pos)
 
        if (solid) {
                indices = quad_indices;
-               prim_type = GL_QUADS;
+               prim_type = PRIM_QUADS_XXX;
        }
        else {
                indices = line_indices;
-               prim_type = GL_LINES;
+               prim_type = PRIM_LINES;
        }
 
        immBegin(prim_type, 24);
index be3d75180a1abf51e6d98e39d1faa7e53a4241a3..22af98e26c6f5f374ffa545a024f3b1dd68ad3fa 100644 (file)
@@ -461,7 +461,7 @@ void wm_triple_draw_textures(wmWindow *win, wmDrawTriple *triple, float alpha)
        immUniform1f("alpha", alpha);
        immUniform1i("image", activeTex);
 
-       immBegin(GL_QUADS, 4);
+       immBegin(PRIM_TRIANGLE_FAN, 4);
 
        immAttrib2f(texcoord, halfx, halfy);
        immVertex2f(pos, 0.0f, 0.0f);
index c97995637a2e232bc8e2364276b0b2f73580ef25..460b4ac3b6da290ba09c07a7881ab0e4a330e7e0 100644 (file)
@@ -221,22 +221,14 @@ static void wm_gesture_draw_rect(wmGesture *gt)
        rcti *rect = (rcti *)gt->customdata;
 
        VertexFormat *format = immVertexFormat();
-       unsigned int pos = VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT);
+       unsigned int pos = VertexFormat_add_attrib(format, "pos", COMP_I32, 2, CONVERT_INT_TO_FLOAT);
 
-       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
-       
        glEnable(GL_BLEND);
 
+       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
        immUniform4f("color", 1.0f, 1.0f, 1.0f, 0.05f);
 
-       immBegin(GL_QUADS, 4);
-
-       immVertex2f(pos, (float)rect->xmax, (float)rect->ymin);
-       immVertex2f(pos, (float)rect->xmax, (float)rect->ymax);
-       immVertex2f(pos, (float)rect->xmin, (float)rect->ymax);
-       immVertex2f(pos, (float)rect->xmin, (float)rect->ymin);
-
-       immEnd();
+       immRecti(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
 
        immUnbindProgram();
 
index c23eba2d48a3ccb53df2be303dfa1aecf4972cdc..b492257068758b259ae5ac0f6148992f40de1559 100644 (file)
@@ -3100,7 +3100,7 @@ static void radial_control_paint_tex(RadialControl *rc, float radius, float alph
                }
 
                /* draw textured quad */
-               immBegin(GL_QUADS, 4);
+               immBegin(PRIM_TRIANGLE_FAN, 4);
 
                immAttrib2f(texCoord, 0, 0);
                immVertex2f(pos, -radius, -radius);
index d01bdc6d0ac89f20c3b4f715d4ebc6c4cba80117..94e4e85026fbbd9e62eb29163ca440f62b3cb3e2 100644 (file)
@@ -132,7 +132,7 @@ static void wm_method_draw_stereo3d_interlace(wmWindow *win)
 
        immUniform1i("interlace_id", interlace_gpu_id_from_type(interlace_type));
 
-       immBegin(GL_QUADS, 4);
+       immBegin(PRIM_TRIANGLE_FAN, 4);
 
        immAttrib2f(texcoord, halfx, halfy);
        immVertex2f(pos, 0.0f, 0.0f);
@@ -242,7 +242,7 @@ static void wm_method_draw_stereo3d_sidebyside(wmWindow *win)
                immUniform1f("alpha", 1.0f);
                immUniform1i("image", 0); /* default GL_TEXTURE0 unit */
 
-               immBegin(GL_QUADS, 4);
+               immBegin(PRIM_TRIANGLE_FAN, 4);
 
                immAttrib2f(texcoord, halfx, halfy);
                immVertex2f(pos, soffx, 0.0f);
@@ -312,7 +312,7 @@ static void wm_method_draw_stereo3d_topbottom(wmWindow *win)
                immUniform1f("alpha", 1.0f);
                immUniform1i("image", 0); /* default GL_TEXTURE0 unit */
 
-               immBegin(GL_QUADS, 4);
+               immBegin(PRIM_TRIANGLE_FAN, 4);
 
                immAttrib2f(texcoord, halfx, halfy);
                immVertex2f(pos, 0.0f, soffy);