diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2020-07-17 17:01:40 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2020-07-18 04:43:52 +0300 |
commit | e2305690ebee82dbf528665f087d44d51482b897 (patch) | |
tree | 3e96d732a9dbc631f993c16951bfdee94a83e7e4 /source/blender/windowmanager/intern/wm_operators.c | |
parent | 2d9eee15c58ba1d3e2bd05a17ca09d74421c47ea (diff) |
Cleanup: WM: Use GPUTexture for radial control drawing
Diffstat (limited to 'source/blender/windowmanager/intern/wm_operators.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 525f96329b7..f0cd1add48b 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -2120,7 +2120,7 @@ typedef struct { int slow_mouse[2]; bool slow_mode; Dial *dial; - unsigned int gltex; + GPUTexture *texture; ListBase orig_paintcursors; bool use_secondary_tex; void *cursor; @@ -2224,11 +2224,15 @@ static void radial_control_set_tex(RadialControl *rc) rc->image_id_ptr.data, rc->use_secondary_tex, !ELEM(rc->subtype, PROP_NONE, PROP_PIXEL, PROP_DISTANCE)))) { - glGenTextures(1, &rc->gltex); - glBindTexture(GL_TEXTURE_2D, rc->gltex); - glTexImage2D( - GL_TEXTURE_2D, 0, GL_R8, ibuf->x, ibuf->y, 0, GL_RED, GL_FLOAT, ibuf->rect_float); - glBindTexture(GL_TEXTURE_2D, 0); + + rc->texture = GPU_texture_create_nD( + ibuf->x, ibuf->y, 0, 2, ibuf->rect_float, GPU_R8, GPU_DATA_FLOAT, 0, false, NULL); + GPU_texture_filter_mode(rc->texture, true); + + GPU_texture_bind(rc->texture, 0); + GPU_texture_swizzle_set(rc->texture, "111r"); + GPU_texture_unbind(rc->texture); + MEM_freeN(ibuf->rect_float); MEM_freeN(ibuf); } @@ -2264,19 +2268,9 @@ static void radial_control_paint_tex(RadialControl *rc, float radius, float alph GPUVertFormat *format = immVertexFormat(); uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - if (rc->gltex) { - + if (rc->texture) { uint texCoord = GPU_vertformat_attr_add(format, "texCoord", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, rc->gltex); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - GLint swizzleMask[] = {GL_ZERO, GL_ZERO, GL_ZERO, GL_RED}; - glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); - /* set up rotation if available */ if (rc->rot_prop) { rot = RNA_property_float_get(&rc->rot_ptr, rc->rot_prop); @@ -2284,10 +2278,10 @@ static void radial_control_paint_tex(RadialControl *rc, float radius, float alph GPU_matrix_rotate_2d(RAD2DEGF(rot)); } - immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_MASK_UNIFORM_COLOR); + immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR); immUniformColor3fvAlpha(col, alpha); - immUniform1i("image", 0); + immBindTexture("image", rc->texture); /* draw textured quad */ immBegin(GPU_PRIM_TRI_FAN, 4); @@ -2306,6 +2300,8 @@ static void radial_control_paint_tex(RadialControl *rc, float radius, float alph immEnd(); + GPU_texture_unbind(rc->texture); + /* undo rotation */ if (rc->rot_prop) { GPU_matrix_pop(); @@ -2803,7 +2799,7 @@ static void radial_control_cancel(bContext *C, wmOperator *op) * new value is displayed in sliders/numfields */ WM_event_add_notifier(C, NC_WINDOW, NULL); - glDeleteTextures(1, &rc->gltex); + GPU_texture_free(rc->texture); MEM_freeN(rc); } |