Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGermano Cavalcante <germano.costa@ig.com.br>2022-04-29 08:14:16 +0300
committerGermano Cavalcante <germano.costa@ig.com.br>2022-04-29 16:15:04 +0300
commit3d877c8a0d06ee539db541c6d410852f94fc618d (patch)
tree047b92a10ee88c7e756b27f6729551a2070a9bdb /source/blender/draw/engines
parenta111a0f1e149dfbcf06b1dfd15d9764508d83028 (diff)
Select Engine: port shader to use 'GPUShaderCreateInfo'
Simple port with a few cosmetic changes: - Attribute named "color" for indices VBO is now called "index" - The indices VBO is now composed of `int`s instead of `uint`s (this simplifies the source) Differential Revision: https://developer.blender.org/D14800
Diffstat (limited to 'source/blender/draw/engines')
-rw-r--r--source/blender/draw/engines/select/select_engine.c27
-rw-r--r--source/blender/draw/engines/select/shaders/infos/select_id_info.hh43
-rw-r--r--source/blender/draw/engines/select/shaders/select_id_frag.glsl4
-rw-r--r--source/blender/draw/engines/select/shaders/select_id_vert.glsl15
-rw-r--r--source/blender/draw/engines/select/shaders/selection_id_3D_vert.glsl26
-rw-r--r--source/blender/draw/engines/select/shaders/selection_id_frag.glsl15
6 files changed, 66 insertions, 64 deletions
diff --git a/source/blender/draw/engines/select/select_engine.c b/source/blender/draw/engines/select/select_engine.c
index 0b3db521e74..88ae5ac707e 100644
--- a/source/blender/draw/engines/select/select_engine.c
+++ b/source/blender/draw/engines/select/select_engine.c
@@ -33,11 +33,6 @@ static struct {
uint runtime_new_objects;
} e_data = {NULL}; /* Engine data */
-/* Shaders */
-extern char datatoc_common_view_lib_glsl[];
-extern char datatoc_selection_id_3D_vert_glsl[];
-extern char datatoc_selection_id_frag_glsl[];
-
/* -------------------------------------------------------------------- */
/** \name Utils
* \{ */
@@ -88,26 +83,12 @@ static void select_engine_init(void *vedata)
/* Prepass */
if (!sh_data->select_id_flat) {
- const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg];
- sh_data->select_id_flat = GPU_shader_create_from_arrays({
- .vert = (const char *[]){sh_cfg_data->lib,
- datatoc_common_view_lib_glsl,
- datatoc_selection_id_3D_vert_glsl,
- NULL},
- .frag = (const char *[]){datatoc_selection_id_frag_glsl, NULL},
- .defs = (const char *[]){sh_cfg_data->def, NULL},
- });
+ sh_data->select_id_flat = GPU_shader_create_from_info_name(
+ sh_cfg == GPU_SHADER_CFG_CLIPPED ? "select_id_flat_clipped" : "select_id_flat");
}
if (!sh_data->select_id_uniform) {
- const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg];
- sh_data->select_id_uniform = GPU_shader_create_from_arrays({
- .vert = (const char *[]){sh_cfg_data->lib,
- datatoc_common_view_lib_glsl,
- datatoc_selection_id_3D_vert_glsl,
- NULL},
- .frag = (const char *[]){datatoc_selection_id_frag_glsl, NULL},
- .defs = (const char *[]){sh_cfg_data->def, "#define UNIFORM_ID\n", NULL},
- });
+ sh_data->select_id_uniform = GPU_shader_create_from_info_name(
+ sh_cfg == GPU_SHADER_CFG_CLIPPED ? "select_id_uniform_clipped" : "select_id_uniform");
}
if (!stl->g_data) {
diff --git a/source/blender/draw/engines/select/shaders/infos/select_id_info.hh b/source/blender/draw/engines/select/shaders/infos/select_id_info.hh
new file mode 100644
index 00000000000..ad0de61ffc3
--- /dev/null
+++ b/source/blender/draw/engines/select/shaders/infos/select_id_info.hh
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "gpu_shader_create_info.hh"
+
+/* -------------------------------------------------------------------- */
+/** \name Select ID fo Edit Mesh selection
+ * \{ */
+
+GPU_SHADER_INTERFACE_INFO(select_id_iface, "").flat(Type::INT, "id");
+
+GPU_SHADER_CREATE_INFO(select_id_flat)
+ .push_constant(Type::FLOAT, "sizeVertex")
+ .push_constant(Type::INT, "offset")
+ .vertex_in(0, Type::VEC3, "pos")
+ .vertex_in(1, Type::INT, "index")
+ .vertex_out(select_id_iface)
+ .fragment_out(0, Type::UINT, "fragColor")
+ .vertex_source("select_id_vert.glsl")
+ .fragment_source("select_id_frag.glsl")
+ .additional_info("draw_modelmat")
+ .do_static_compilation(true);
+
+GPU_SHADER_CREATE_INFO(select_id_uniform)
+ .define("UNIFORM_ID")
+ .push_constant(Type::FLOAT, "sizeVertex")
+ .push_constant(Type::INT, "id")
+ .vertex_in(0, Type::VEC3, "pos")
+ .fragment_out(0, Type::UINT, "fragColor")
+ .vertex_source("select_id_vert.glsl")
+ .fragment_source("select_id_frag.glsl")
+ .additional_info("draw_modelmat")
+ .do_static_compilation(true);
+
+GPU_SHADER_CREATE_INFO(select_id_flat_clipped)
+ .additional_info("select_id_flat")
+ .additional_info("drw_clipped")
+ .do_static_compilation(true);
+
+GPU_SHADER_CREATE_INFO(select_id_uniform_clipped)
+ .additional_info("select_id_uniform")
+ .additional_info("drw_clipped")
+ .do_static_compilation(true);
+/** \} */
diff --git a/source/blender/draw/engines/select/shaders/select_id_frag.glsl b/source/blender/draw/engines/select/shaders/select_id_frag.glsl
new file mode 100644
index 00000000000..aecf57b4766
--- /dev/null
+++ b/source/blender/draw/engines/select/shaders/select_id_frag.glsl
@@ -0,0 +1,4 @@
+void main()
+{
+ fragColor = floatBitsToUint(intBitsToFloat(id));
+}
diff --git a/source/blender/draw/engines/select/shaders/select_id_vert.glsl b/source/blender/draw/engines/select/shaders/select_id_vert.glsl
new file mode 100644
index 00000000000..7b3b0f9984d
--- /dev/null
+++ b/source/blender/draw/engines/select/shaders/select_id_vert.glsl
@@ -0,0 +1,15 @@
+#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl)
+#pragma BLENDER_REQUIRE(common_view_lib.glsl)
+
+void main()
+{
+#ifndef UNIFORM_ID
+ id = offset + index;
+#endif
+
+ vec3 world_pos = point_object_to_world(pos);
+ gl_Position = point_world_to_ndc(world_pos);
+ gl_PointSize = sizeVertex;
+
+ view_clipping_distances(world_pos);
+}
diff --git a/source/blender/draw/engines/select/shaders/selection_id_3D_vert.glsl b/source/blender/draw/engines/select/shaders/selection_id_3D_vert.glsl
deleted file mode 100644
index 9b0107cffdb..00000000000
--- a/source/blender/draw/engines/select/shaders/selection_id_3D_vert.glsl
+++ /dev/null
@@ -1,26 +0,0 @@
-
-uniform float sizeVertex;
-
-in vec3 pos;
-
-#ifndef UNIFORM_ID
-uniform int offset;
-in uint color;
-
-flat out uint id;
-#endif
-
-void main()
-{
-#ifndef UNIFORM_ID
- id = floatBitsToUint(intBitsToFloat(offset)) + color;
-#endif
-
- vec3 world_pos = point_object_to_world(pos);
- gl_Position = point_world_to_ndc(world_pos);
- gl_PointSize = sizeVertex;
-
-#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance(world_pos);
-#endif
-}
diff --git a/source/blender/draw/engines/select/shaders/selection_id_frag.glsl b/source/blender/draw/engines/select/shaders/selection_id_frag.glsl
deleted file mode 100644
index a84bbbb2cac..00000000000
--- a/source/blender/draw/engines/select/shaders/selection_id_frag.glsl
+++ /dev/null
@@ -1,15 +0,0 @@
-
-#ifdef UNIFORM_ID
-uniform int id;
-# define _id floatBitsToUint(intBitsToFloat(id))
-#else
-flat in uint id;
-# define _id id
-#endif
-
-out uint fragColor;
-
-void main()
-{
- fragColor = _id;
-}