Cleanup: DRW: Add and use DRW_shgroup_uniform_vec2_copy
authorClément Foucault <foucault.clem@gmail.com>
Mon, 13 May 2019 17:20:58 +0000 (19:20 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Tue, 14 May 2019 08:57:04 +0000 (10:57 +0200)
source/blender/draw/intern/DRW_render.h
source/blender/draw/intern/draw_manager_data.c
source/blender/draw/modes/object_mode.c
source/blender/draw/modes/shaders/object_empty_image_vert.glsl

index 722f9117f7d8d0abf1ad51794481d54ccb92b934..8337255464acfb43a70577c9eef65b9330fe1e5d 100644 (file)
@@ -509,6 +509,7 @@ void DRW_shgroup_uniform_mat4(DRWShadingGroup *shgroup, const char *name, const
 void DRW_shgroup_uniform_int_copy(DRWShadingGroup *shgroup, const char *name, const int value);
 void DRW_shgroup_uniform_bool_copy(DRWShadingGroup *shgroup, const char *name, const bool value);
 void DRW_shgroup_uniform_float_copy(DRWShadingGroup *shgroup, const char *name, const float value);
+void DRW_shgroup_uniform_vec2_copy(DRWShadingGroup *shgroup, const char *name, const float *value);
 
 bool DRW_shgroup_is_empty(DRWShadingGroup *shgroup);
 
index 1a58cb4c25f2f156c2c75ebfb25c24719dbb3810..e47433e60ab1d8523e9084621ddd45e13d097d0a 100644 (file)
@@ -293,6 +293,11 @@ void DRW_shgroup_uniform_float_copy(DRWShadingGroup *shgroup, const char *name,
   drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_FLOAT_COPY, &value, 1, 1);
 }
 
+void DRW_shgroup_uniform_vec2_copy(DRWShadingGroup *shgroup, const char *name, const float *value)
+{
+  drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_FLOAT_COPY, value, 2, 1);
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
index 6f6b4dc8d41aaf711cd925efbd4b6b19c9249477..9702f99e802fbdf52c277316909f7bb0a17fb52c 100644 (file)
@@ -1010,9 +1010,7 @@ static void DRW_shgroup_empty_image(OBJECT_Shaders *sh_data,
 
   {
     DRWShadingGroup *grp = DRW_shgroup_create(sh_data->object_empty_image_wire, sgl->non_meshes);
-    /* TODO(fclem) implement DRW_shgroup_uniform_vec2_copy */
-    DRW_shgroup_uniform_float_copy(grp, "aspectX", image_aspect[0]);
-    DRW_shgroup_uniform_float_copy(grp, "aspectY", image_aspect[1]);
+    DRW_shgroup_uniform_vec2_copy(grp, "aspect", image_aspect);
     DRW_shgroup_uniform_int_copy(grp, "depthMode", depth_mode);
     DRW_shgroup_uniform_float(grp, "size", &ob->empty_drawsize, 1);
     DRW_shgroup_uniform_vec2(grp, "offset", ob->ima_ofs, 1);
@@ -1030,8 +1028,7 @@ static void DRW_shgroup_empty_image(OBJECT_Shaders *sh_data,
   if (tex && ((ob->color[3] > 0.0f) || !use_alpha_blend)) {
     DRWShadingGroup *grp = DRW_shgroup_create(
         sh_data->object_empty_image, (use_alpha_blend) ? sgl->image_empties : sgl->non_meshes);
-    DRW_shgroup_uniform_float_copy(grp, "aspectX", image_aspect[0]);
-    DRW_shgroup_uniform_float_copy(grp, "aspectY", image_aspect[1]);
+    DRW_shgroup_uniform_vec2_copy(grp, "aspect", image_aspect);
     DRW_shgroup_uniform_int_copy(grp, "depthMode", depth_mode);
     DRW_shgroup_uniform_float(grp, "size", &ob->empty_drawsize, 1);
     DRW_shgroup_uniform_vec2(grp, "offset", ob->ima_ofs, 1);
index 881d7aa750e2b9b9350c476ca7e6be38571cf268..5ac3b49b3946c22944ec11d9136c65de4f08f0f5 100644 (file)
@@ -1,7 +1,6 @@
 uniform mat4 ModelMatrix;
 
-uniform float aspectX;
-uniform float aspectY;
+uniform vec2 aspect;
 uniform float size;
 uniform vec2 offset;
 #ifdef USE_WIRE
@@ -21,7 +20,7 @@ out vec2 texCoord_interp;
 
 void main()
 {
-  vec3 pos = vec3((pos + offset) * (size * vec2(aspectX, aspectY)), 0.0);
+  vec3 pos = vec3((pos + offset) * (size * aspect), 0.0);
   vec3 world_pos = point_object_to_world(pos);
   gl_Position = point_world_to_ndc(world_pos);
 #ifdef USE_WIRE