From 8e02106d0ddc7b31844d26037a824d56d3c65663 Mon Sep 17 00:00:00 2001 From: Ray Molenkamp Date: Wed, 27 Jun 2018 19:07:23 -0600 Subject: GLRefactor: partially remove gl calls from source/blender/editors. This translates the gl calls to the new GPU_ wrappers from D3501. Given it's tedious and repetitive work, this patch does as much as it can with search + replace, the remainder of the gl calls will need to be manually dealt with on a case by case basis. This fixes 13 of the 28 failing editors when building without opengl. For the list of substitutions see D3502 Reviewers: brecht Differential Revision: https://developer.blender.org/D3502 --- source/blender/editors/sculpt_paint/paint_cursor.c | 39 +++++++++++----------- source/blender/editors/sculpt_paint/paint_image.c | 13 ++++---- source/blender/editors/sculpt_paint/paint_stroke.c | 15 +++++---- source/blender/editors/sculpt_paint/paint_utils.c | 3 +- source/blender/editors/sculpt_paint/sculpt_uv.c | 9 ++--- 5 files changed, 42 insertions(+), 37 deletions(-) (limited to 'source/blender/editors/sculpt_paint') diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c index 848d12bcfaa..50d178bc757 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.c +++ b/source/blender/editors/sculpt_paint/paint_cursor.c @@ -62,6 +62,7 @@ #include "GPU_immediate.h" #include "GPU_immediate_util.h" #include "GPU_matrix.h" +#include "GPU_state.h" #include "UI_resources.h" @@ -607,7 +608,7 @@ static void paint_draw_tex_overlay(UnifiedPaintSettings *ups, Brush *brush, } if (load_tex(brush, vc, zoom, col, primary)) { - glEnable(GL_BLEND); + GPU_blend(true); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDepthMask(GL_FALSE); @@ -726,7 +727,7 @@ static void paint_draw_cursor_overlay(UnifiedPaintSettings *ups, Brush *brush, if (load_tex_cursor(brush, vc, zoom)) { bool do_pop = false; float center[2]; - glEnable(GL_BLEND); + GPU_blend(true); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDepthMask(GL_FALSE); @@ -829,7 +830,7 @@ BLI_INLINE void draw_tri_point( { immUniformColor4fv(selected ? sel_col : pivot_col); - glLineWidth(3.0f); + GPU_line_width(3.0f); float w = width / 2.0f; float tri[3][2] = { @@ -845,7 +846,7 @@ BLI_INLINE void draw_tri_point( immEnd(); immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5f); - glLineWidth(1.0f); + GPU_line_width(1.0f); immBegin(GWN_PRIM_LINE_LOOP, 3); immVertex2fv(pos, tri[0]); @@ -860,7 +861,7 @@ BLI_INLINE void draw_rect_point( { immUniformColor4fv(selected ? sel_col : handle_col); - glLineWidth(3.0f); + GPU_line_width(3.0f); float w = width / 2.0f; float minx = co[0] - w; @@ -871,7 +872,7 @@ BLI_INLINE void draw_rect_point( imm_draw_box_wire_2d(pos, minx, miny, maxx, maxy); immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5f); - glLineWidth(1.0f); + GPU_line_width(1.0f); imm_draw_box_wire_2d(pos, minx, miny, maxx, maxy); } @@ -880,7 +881,7 @@ BLI_INLINE void draw_rect_point( BLI_INLINE void draw_bezier_handle_lines(unsigned int pos, float sel_col[4], BezTriple *bez) { immUniformColor4f(0.0f, 0.0f, 0.0f, 0.5f); - glLineWidth(3.0f); + GPU_line_width(3.0f); immBegin(GWN_PRIM_LINE_STRIP, 3); immVertex2fv(pos, bez->vec[0]); @@ -888,7 +889,7 @@ BLI_INLINE void draw_bezier_handle_lines(unsigned int pos, float sel_col[4], Bez immVertex2fv(pos, bez->vec[2]); immEnd(); - glLineWidth(1.0f); + GPU_line_width(1.0f); if (bez->f1 || bez->f2) { immUniformColor4fv(sel_col); @@ -920,8 +921,8 @@ static void paint_draw_curve_cursor(Brush *brush) PaintCurve *pc = brush->paint_curve; PaintCurvePoint *cp = pc->points; - glEnable(GL_LINE_SMOOTH); - glEnable(GL_BLEND); + GPU_line_smooth(true); + GPU_blend(true); /* draw the bezier handles and the curve segment between the current and next point */ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); @@ -954,7 +955,7 @@ static void paint_draw_curve_cursor(Brush *brush) float (*v)[2] = (float(*)[2])data; immUniformColor4f(0.0f, 0.0f, 0.0f, 0.5f); - glLineWidth(3.0f); + GPU_line_width(3.0f); immBegin(GWN_PRIM_LINE_STRIP, PAINT_CURVE_NUM_SEGMENTS + 1); for (j = 0; j <= PAINT_CURVE_NUM_SEGMENTS; j++) { immVertex2fv(pos, v[j]); @@ -962,7 +963,7 @@ static void paint_draw_curve_cursor(Brush *brush) immEnd(); immUniformColor4f(0.9f, 0.9f, 1.0f, 0.5f); - glLineWidth(1.0f); + GPU_line_width(1.0f); immBegin(GWN_PRIM_LINE_STRIP, PAINT_CURVE_NUM_SEGMENTS + 1); for (j = 0; j <= PAINT_CURVE_NUM_SEGMENTS; j++) { immVertex2fv(pos, v[j]); @@ -976,8 +977,8 @@ static void paint_draw_curve_cursor(Brush *brush) draw_rect_point(pos, selec_col, handle_col, &cp->bez.vec[0][0], 8.0f, cp->bez.f1 || cp->bez.f2); draw_rect_point(pos, selec_col, handle_col, &cp->bez.vec[2][0], 8.0f, cp->bez.f3 || cp->bez.f2); - glDisable(GL_BLEND); - glDisable(GL_LINE_SMOOTH); + GPU_blend(false); + GPU_line_smooth(false); immUnbindProgram(); } @@ -1107,9 +1108,9 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) } /* make lines pretty */ - glLineWidth(1.0f); - glEnable(GL_BLEND); /* TODO: also set blend mode? */ - glEnable(GL_LINE_SMOOTH); + GPU_line_width(1.0f); + GPU_blend(true); /* TODO: also set blend mode? */ + GPU_line_smooth(true); unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); @@ -1129,8 +1130,8 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) immUnbindProgram(); /* restore GL state */ - glDisable(GL_BLEND); - glDisable(GL_LINE_SMOOTH); + GPU_blend(false); + GPU_line_smooth(false); } /* Public API */ diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index c3a0ca4299f..b5da9a5d68c 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -82,6 +82,7 @@ #include "GPU_draw.h" #include "GPU_immediate.h" +#include "GPU_state.h" #include "BIF_gl.h" @@ -413,15 +414,15 @@ static void gradient_draw_line(bContext *UNUSED(C), int x, int y, void *customda PaintOperation *pop = (PaintOperation *)customdata; if (pop) { - glEnable(GL_LINE_SMOOTH); - glEnable(GL_BLEND); + GPU_line_smooth(true); + GPU_blend(true); Gwn_VertFormat *format = immVertexFormat(); unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - glLineWidth(4.0); + GPU_line_width(4.0); immUniformColor4ub(0, 0, 0, 255); immBegin(GWN_PRIM_LINES, 2); @@ -429,7 +430,7 @@ static void gradient_draw_line(bContext *UNUSED(C), int x, int y, void *customda immVertex2i(pos, pop->startmouse[0], pop->startmouse[1]); immEnd(); - glLineWidth(2.0); + GPU_line_width(2.0); immUniformColor4ub(255, 255, 255, 255); immBegin(GWN_PRIM_LINES, 2); @@ -439,8 +440,8 @@ static void gradient_draw_line(bContext *UNUSED(C), int x, int y, void *customda immUnbindProgram(); - glDisable(GL_BLEND); - glDisable(GL_LINE_SMOOTH); + GPU_blend(false); + GPU_line_smooth(false); } } diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index a7aa19807dd..ee888c71659 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -62,6 +62,7 @@ #include "BIF_glutil.h" #include "GPU_immediate.h" +#include "GPU_state.h" #include "ED_screen.h" #include "ED_view3d.h" @@ -149,8 +150,8 @@ static void paint_draw_smooth_cursor(bContext *C, int x, int y, void *customdata PaintStroke *stroke = customdata; if (stroke && brush) { - glEnable(GL_LINE_SMOOTH); - glEnable(GL_BLEND); + GPU_line_smooth(true); + GPU_blend(true); ARegion *ar = stroke->vc.ar; @@ -168,8 +169,8 @@ static void paint_draw_smooth_cursor(bContext *C, int x, int y, void *customdata immUnbindProgram(); - glDisable(GL_BLEND); - glDisable(GL_LINE_SMOOTH); + GPU_blend(false); + GPU_line_smooth(false); } } @@ -178,14 +179,14 @@ static void paint_draw_line_cursor(bContext *C, int x, int y, void *customdata) Paint *paint = BKE_paint_get_active_from_context(C); PaintStroke *stroke = customdata; - glEnable(GL_LINE_SMOOTH); + GPU_line_smooth(true); uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR); float viewport_size[4]; - glGetFloatv(GL_VIEWPORT, viewport_size); + GPU_viewport_size_getf(viewport_size); immUniform2f("viewport_size", viewport_size[2], viewport_size[3]); immUniform1i("num_colors", 2); /* "advanced" mode */ @@ -218,7 +219,7 @@ static void paint_draw_line_cursor(bContext *C, int x, int y, void *customdata) immUnbindProgram(); - glDisable(GL_LINE_SMOOTH); + GPU_line_smooth(false); } static bool paint_tool_require_location(Brush *brush, ePaintMode mode) diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 80c4d4099a2..d6de9c235f1 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -65,6 +65,7 @@ #include "GPU_glew.h" #include "GPU_matrix.h" +#include "GPU_state.h" #include "IMB_colormanagement.h" #include "IMB_imbuf_types.h" @@ -291,7 +292,7 @@ static void imapaint_pick_uv(Mesh *me_eval, Scene *scene, Object *ob_eval, unsig const int *index_mp_to_orig = CustomData_get_layer(&me_eval->pdata, CD_ORIGINDEX); /* get the needed opengl matrices */ - glGetIntegerv(GL_VIEWPORT, view); + GPU_viewport_size_geti(view); gpuGetModelViewMatrix(matrix); gpuGetProjectionMatrix(proj); view[0] = view[1] = 0; diff --git a/source/blender/editors/sculpt_paint/sculpt_uv.c b/source/blender/editors/sculpt_paint/sculpt_uv.c index cf9feae62b5..1405de8cfa9 100644 --- a/source/blender/editors/sculpt_paint/sculpt_uv.c +++ b/source/blender/editors/sculpt_paint/sculpt_uv.c @@ -59,6 +59,7 @@ #include "GPU_immediate.h" #include "GPU_immediate_util.h" +#include "GPU_state.h" #include "WM_api.h" #include "WM_types.h" @@ -218,11 +219,11 @@ static void brush_drawcursor_uvsculpt(bContext *C, int x, int y, void *UNUSED(cu immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); immUniformColor3fvAlpha(brush->add_col, alpha); - glEnable(GL_LINE_SMOOTH); - glEnable(GL_BLEND); + GPU_line_smooth(true); + GPU_blend(true); imm_draw_circle_wire_2d(pos, (float)x, (float)y, size, 40); - glDisable(GL_BLEND); - glDisable(GL_LINE_SMOOTH); + GPU_blend(false); + GPU_line_smooth(false); immUnbindProgram(); } -- cgit v1.2.3