From 4536de98d18b8887edee37b03a12da015590bb45 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Thu, 1 Sep 2022 12:32:28 -0300 Subject: GPU: remove 'GPU_SHADER_2D_SMOOTH_COLOR' The only real difference between `GPU_SHADER_2D_SMOOTH_COLOR` and `GPU_SHADER_3D_SMOOTH_COLOR` is that in the vertex shader the 2D version uses `vec4(pos, 0.0, 1.0)` and the 3D version uses `vec4(pos, 1.0)`. But VBOs with 2D attributes work perfectly in shaders that use 3D attributes. Components not specified are filled with components from `vec4(0.0, 0.0, 0.0, 1.0)`. So there is no real benefit to having two different shader versions. This will simplify porting shaders to python as it will not be necessary to use a 3D and a 2D version of the shaders. In python the new name for '2D_SMOOTH_COLOR' and '3D_SMOOTH_COLOR' is 'SMOOTH_COLOR', but the old names still work for backward compatibility. --- source/blender/editors/interface/interface_draw.c | 6 +++--- source/blender/editors/interface/interface_widgets.c | 6 +++--- source/blender/gpu/CMakeLists.txt | 3 --- source/blender/gpu/GPU_shader.h | 1 - source/blender/gpu/intern/gpu_immediate.cc | 1 - source/blender/gpu/intern/gpu_shader_builtin.c | 7 ------- .../gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl | 7 ------- .../gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl | 6 ------ .../shaders/infos/gpu_shader_2D_smooth_color_info.hh | 20 -------------------- source/blender/windowmanager/intern/wm_gesture.c | 2 +- 10 files changed, 7 insertions(+), 52 deletions(-) delete mode 100644 source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl delete mode 100644 source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl delete mode 100644 source/blender/gpu/shaders/infos/gpu_shader_2D_smooth_color_info.hh diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 4dae8222b14..02325920e6d 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -205,7 +205,7 @@ void ui_draw_but_TAB_outline(const rcti *rect, mul_v2_fl(vec[a], rad); } - immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR); + immBindBuiltinProgram(GPU_SHADER_3D_SMOOTH_COLOR); immBeginAtMost(GPU_PRIM_LINE_STRIP, 25); immAttr3ubv(col, highlight); @@ -1242,7 +1242,7 @@ void ui_draw_but_COLORBAND(uiBut *but, const uiWidgetColors *UNUSED(wcol), const format = immVertexFormat(); pos_id = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); col_id = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR); + immBindBuiltinProgram(GPU_SHADER_3D_SMOOTH_COLOR); /* layer: color ramp */ GPU_blend(GPU_BLEND_ALPHA); @@ -2288,7 +2288,7 @@ void UI_draw_box_shadow(const rctf *rect, uchar alpha) uint color = GPU_vertformat_attr_add( format, "color", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT); - immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR); + immBindBuiltinProgram(GPU_SHADER_3D_SMOOTH_COLOR); immBegin(GPU_PRIM_TRIS, 54); diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index f49863cf306..53b1967d668 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -2930,7 +2930,7 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, const uiWidgetColors *wcol, const uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); const uint color = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR); + immBindBuiltinProgram(GPU_SHADER_3D_SMOOTH_COLOR); immBegin(GPU_PRIM_TRI_FAN, tot + 2); immAttr3fv(color, rgb_center); @@ -3061,7 +3061,7 @@ void ui_draw_gradient(const rcti *rect, GPUVertFormat *format = immVertexFormat(); const uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); const uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR); + immBindBuiltinProgram(GPU_SHADER_3D_SMOOTH_COLOR); immBegin(GPU_PRIM_TRIS, steps * 3 * 6); @@ -5155,7 +5155,7 @@ static void draw_disk_shaded(float start, const uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); if (shaded) { col = GPU_vertformat_attr_add(format, "color", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT); - immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR); + immBindBuiltinProgram(GPU_SHADER_3D_SMOOTH_COLOR); } else { immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index d1b0e227506..2eceeedf845 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -274,8 +274,6 @@ set(GLSL_SRC shaders/gpu_shader_2D_nodelink_vert.glsl shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl shaders/gpu_shader_2D_line_dashed_frag.glsl - shaders/gpu_shader_2D_smooth_color_vert.glsl - shaders/gpu_shader_2D_smooth_color_frag.glsl shaders/gpu_shader_2D_image_vert.glsl shaders/gpu_shader_2D_image_rect_vert.glsl shaders/gpu_shader_2D_image_multi_rect_vert.glsl @@ -588,7 +586,6 @@ set(SRC_SHADER_CREATE_INFOS shaders/infos/gpu_shader_2D_point_uniform_size_uniform_color_aa_info.hh shaders/infos/gpu_shader_2D_point_uniform_size_uniform_color_outline_aa_info.hh shaders/infos/gpu_shader_2D_point_varying_size_varying_color_info.hh - shaders/infos/gpu_shader_2D_smooth_color_info.hh shaders/infos/gpu_shader_2D_widget_info.hh shaders/infos/gpu_shader_3D_depth_only_info.hh shaders/infos/gpu_shader_3D_flat_color_info.hh diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h index 0f3a494fc3f..d694fcf4da1 100644 --- a/source/blender/gpu/GPU_shader.h +++ b/source/blender/gpu/GPU_shader.h @@ -212,7 +212,6 @@ typedef enum eGPUBuiltinShader { * \param color: in vec4 * \param pos: in vec2 */ - GPU_SHADER_2D_SMOOTH_COLOR, GPU_SHADER_2D_IMAGE_COLOR, GPU_SHADER_2D_IMAGE_DESATURATE_COLOR, GPU_SHADER_2D_IMAGE_RECT_COLOR, diff --git a/source/blender/gpu/intern/gpu_immediate.cc b/source/blender/gpu/intern/gpu_immediate.cc index 8574e886cd0..3b4accf9cc5 100644 --- a/source/blender/gpu/intern/gpu_immediate.cc +++ b/source/blender/gpu/intern/gpu_immediate.cc @@ -137,7 +137,6 @@ static void wide_line_workaround_start(GPUPrimType prim_type) case GPU_SHADER_3D_FLAT_COLOR: polyline_sh = GPU_SHADER_3D_POLYLINE_FLAT_COLOR; break; - case GPU_SHADER_2D_SMOOTH_COLOR: case GPU_SHADER_3D_SMOOTH_COLOR: polyline_sh = GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR; break; diff --git a/source/blender/gpu/intern/gpu_shader_builtin.c b/source/blender/gpu/intern/gpu_shader_builtin.c index 8afe3e04dc9..d255084609e 100644 --- a/source/blender/gpu/intern/gpu_shader_builtin.c +++ b/source/blender/gpu/intern/gpu_shader_builtin.c @@ -26,8 +26,6 @@ extern char datatoc_gpu_shader_2D_area_borders_vert_glsl[]; extern char datatoc_gpu_shader_2D_area_borders_frag_glsl[]; extern char datatoc_gpu_shader_2D_vert_glsl[]; extern char datatoc_gpu_shader_2D_smooth_color_uniform_alpha_vert_glsl[]; -extern char datatoc_gpu_shader_2D_smooth_color_vert_glsl[]; -extern char datatoc_gpu_shader_2D_smooth_color_frag_glsl[]; extern char datatoc_gpu_shader_2D_image_vert_glsl[]; extern char datatoc_gpu_shader_2D_image_rect_vert_glsl[]; extern char datatoc_gpu_shader_2D_image_multi_rect_vert_glsl[]; @@ -155,11 +153,6 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = { .create_info = "gpu_shader_2D_diag_stripes", }, - [GPU_SHADER_2D_SMOOTH_COLOR] = - { - .name = "GPU_SHADER_2D_SMOOTH_COLOR", - .create_info = "gpu_shader_2D_smooth_color", - }, [GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE] = { .name = "GPU_SHADER_2D_IMAGE_OVERLAYS_MERGE", diff --git a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl deleted file mode 100644 index 8690ba0767a..00000000000 --- a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl +++ /dev/null @@ -1,7 +0,0 @@ -#pragma BLENDER_REQUIRE(gpu_shader_colorspace_lib.glsl) - -void main() -{ - fragColor = finalColor; - fragColor = blender_srgb_to_framebuffer_space(fragColor); -} diff --git a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl deleted file mode 100644 index cf948bb2533..00000000000 --- a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl +++ /dev/null @@ -1,6 +0,0 @@ - -void main() -{ - gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0); - finalColor = color; -} diff --git a/source/blender/gpu/shaders/infos/gpu_shader_2D_smooth_color_info.hh b/source/blender/gpu/shaders/infos/gpu_shader_2D_smooth_color_info.hh deleted file mode 100644 index d6edeef0dfb..00000000000 --- a/source/blender/gpu/shaders/infos/gpu_shader_2D_smooth_color_info.hh +++ /dev/null @@ -1,20 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later - * Copyright 2022 Blender Foundation. All rights reserved. */ - -/** \file - * \ingroup gpu - */ - -#include "gpu_interface_info.hh" -#include "gpu_shader_create_info.hh" - -GPU_SHADER_CREATE_INFO(gpu_shader_2D_smooth_color) - .vertex_in(0, Type::VEC2, "pos") - .vertex_in(1, Type::VEC4, "color") - .vertex_out(smooth_color_iface) - .fragment_out(0, Type::VEC4, "fragColor") - .push_constant(Type::MAT4, "ModelViewProjectionMatrix") - .vertex_source("gpu_shader_2D_smooth_color_vert.glsl") - .fragment_source("gpu_shader_2D_smooth_color_frag.glsl") - .additional_info("gpu_srgb_to_framebuffer_space") - .do_static_compilation(true); diff --git a/source/blender/windowmanager/intern/wm_gesture.c b/source/blender/windowmanager/intern/wm_gesture.c index c4710260e54..7eec522690c 100644 --- a/source/blender/windowmanager/intern/wm_gesture.c +++ b/source/blender/windowmanager/intern/wm_gesture.c @@ -122,7 +122,7 @@ static void wm_gesture_draw_line_active_side(rcti *rect, const bool flip) uint shdr_col = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); GPU_blend(GPU_BLEND_ALPHA); - immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR); + immBindBuiltinProgram(GPU_SHADER_3D_SMOOTH_COLOR); const float gradient_length = 150.0f * U.pixelsize; float line_dir[2]; -- cgit v1.2.3