From 7a75581d92ad1df005f1da23a84a3d0aea20188e Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Fri, 7 Apr 2017 15:03:24 -0400 Subject: OpenGL: transition away from GL_QUADS 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 --- source/blender/blenfont/intern/blf_font.c | 6 +++--- source/blender/draw/intern/draw_view.c | 2 +- source/blender/editors/gpencil/drawgpencil.c | 2 +- source/blender/editors/interface/interface_draw.c | 7 +++++-- source/blender/editors/sculpt_paint/paint_cursor.c | 4 ++-- source/blender/editors/space_clip/clip_draw.c | 2 +- source/blender/editors/space_outliner/outliner_draw.c | 2 +- source/blender/editors/space_sequencer/sequencer_draw.c | 2 +- source/blender/editors/space_time/space_time.c | 2 +- source/blender/editors/space_view3d/drawobject.c | 15 ++++++++------- source/blender/windowmanager/intern/wm_draw.c | 2 +- source/blender/windowmanager/intern/wm_gesture.c | 14 +++----------- source/blender/windowmanager/intern/wm_operators.c | 2 +- source/blender/windowmanager/intern/wm_stereo.c | 6 +++--- 14 files changed, 32 insertions(+), 36 deletions(-) diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index d0293eccf3a..3702c70be35 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -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); diff --git a/source/blender/draw/intern/draw_view.c b/source/blender/draw/intern/draw_view.c index a0f0fb1a9ee..b5f4a13587d 100644 --- a/source/blender/draw/intern/draw_view.c +++ b/source/blender/draw/intern/draw_view.c @@ -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); diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c index 229aecc21ae..7e33de7b271 100644 --- a/source/blender/editors/gpencil/drawgpencil.c +++ b/source/blender/editors/gpencil/drawgpencil.c @@ -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 */ diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 89d9fe992ba..5e4cb9c1ba1 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -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); diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c index 44ef95ee0b6..9405de93cc5 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.c +++ b/source/blender/editors/sculpt_paint/paint_cursor.c @@ -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); diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c index dc40f083bc6..274e9b0f684 100644 --- a/source/blender/editors/space_clip/clip_draw.c +++ b/source/blender/editors/space_clip/clip_draw.c @@ -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); diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c index cfe6e6a2bb5..92193e93fbe 100644 --- a/source/blender/editors/space_outliner/outliner_draw.c +++ b/source/blender/editors/space_outliner/outliner_draw.c @@ -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; diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index a7a638d0952..13847efd22a 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -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) { diff --git a/source/blender/editors/space_time/space_time.c b/source/blender/editors/space_time/space_time.c index 9844a8053db..7dbf99dda90 100644 --- a/source/blender/editors/space_time/space_time.c +++ b/source/blender/editors/space_time/space_time.c @@ -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++) { diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 726a67a5d74..291592a0a4c 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -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); diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c index be3d75180a1..22af98e26c6 100644 --- a/source/blender/windowmanager/intern/wm_draw.c +++ b/source/blender/windowmanager/intern/wm_draw.c @@ -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); diff --git a/source/blender/windowmanager/intern/wm_gesture.c b/source/blender/windowmanager/intern/wm_gesture.c index c97995637a2..460b4ac3b6d 100644 --- a/source/blender/windowmanager/intern/wm_gesture.c +++ b/source/blender/windowmanager/intern/wm_gesture.c @@ -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(); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index c23eba2d48a..b4922570687 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -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); diff --git a/source/blender/windowmanager/intern/wm_stereo.c b/source/blender/windowmanager/intern/wm_stereo.c index d01bdc6d0ac..94e4e85026f 100644 --- a/source/blender/windowmanager/intern/wm_stereo.c +++ b/source/blender/windowmanager/intern/wm_stereo.c @@ -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); -- cgit v1.2.3