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:
authorClément Foucault <foucault.clem@gmail.com>2018-02-14 20:59:15 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-02-14 20:59:42 +0300
commit0ef981f603a0d03a1b187995c91282c73ed50bd7 (patch)
tree0957ed900ee82ed6d2bfc3b6e9513cefc61fe50b /source/blender/draw/modes/object_mode.c
parent629a87481769d8886fcbe66ca4e4e4b60c767627 (diff)
DRW: Refactor: Less feature duplication with Gwn.
This removes the need of custom attribs for instancing. Instancing works fully with dynamic batches & Gwn_VertFormat now. This is in prevision of the VAO manager patch.
Diffstat (limited to 'source/blender/draw/modes/object_mode.c')
-rw-r--r--source/blender/draw/modes/object_mode.c45
1 files changed, 29 insertions, 16 deletions
diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c
index 7ed81366341..ec43316240e 100644
--- a/source/blender/draw/modes/object_mode.c
+++ b/source/blender/draw/modes/object_mode.c
@@ -55,6 +55,8 @@
#include "GPU_shader.h"
#include "GPU_texture.h"
+#include "MEM_guardedalloc.h"
+
#include "UI_resources.h"
#include "draw_mode_engines.h"
@@ -215,6 +217,10 @@ typedef struct OBJECT_PrivateData {
} OBJECT_PrivateData; /* Transient data */
static struct {
+ /* Instance Data format */
+ struct Gwn_VertFormat *empty_image_format;
+ struct Gwn_VertFormat *empty_image_wire_format;
+
/* fullscreen shaders */
GPUShader *outline_resolve_sh;
GPUShader *outline_resolve_aa_sh;
@@ -531,6 +537,8 @@ static void OBJECT_engine_init(void *vedata)
static void OBJECT_engine_free(void)
{
+ MEM_SAFE_FREE(e_data.empty_image_format);
+ MEM_SAFE_FREE(e_data.empty_image_wire_format);
DRW_SHADER_FREE_SAFE(e_data.outline_resolve_sh);
DRW_SHADER_FREE_SAFE(e_data.outline_resolve_aa_sh);
DRW_SHADER_FREE_SAFE(e_data.outline_detect_sh);
@@ -663,14 +671,16 @@ static void DRW_shgroup_empty_image(
image_calc_aspect(ob->data, ob->iuser, empty_image_data->image_aspect);
if (tex) {
+ DRW_shgroup_instance_format(e_data.empty_image_format, {
+ {"objectColor" , DRW_ATTRIB_FLOAT, 4},
+ {"size" , DRW_ATTRIB_FLOAT, 1},
+ {"offset" , DRW_ATTRIB_FLOAT, 2},
+ {"InstanceModelMatrix" , DRW_ATTRIB_FLOAT, 16},
+ });
+
struct Gwn_Batch *geom = DRW_cache_image_plane_get();
DRWShadingGroup *grp = DRW_shgroup_instance_create(
- e_data.object_empty_image_sh, psl->non_meshes, geom);
- DRW_shgroup_attrib_float(grp, "objectColor", 4);
- DRW_shgroup_attrib_float(grp, "size", 1);
- DRW_shgroup_attrib_float(grp, "offset", 2);
- DRW_shgroup_attrib_float(grp, "InstanceModelMatrix", 16);
-
+ e_data.object_empty_image_sh, psl->non_meshes, geom, e_data.empty_image_format);
DRW_shgroup_uniform_texture(grp, "image", tex);
DRW_shgroup_uniform_vec2(grp, "aspect", empty_image_data->image_aspect, 1);
@@ -681,14 +691,16 @@ static void DRW_shgroup_empty_image(
}
{
+ DRW_shgroup_instance_format(e_data.empty_image_wire_format, {
+ {"objectColor" , DRW_ATTRIB_FLOAT, 4},
+ {"size" , DRW_ATTRIB_FLOAT, 1},
+ {"offset" , DRW_ATTRIB_FLOAT, 2},
+ {"InstanceModelMatrix" , DRW_ATTRIB_FLOAT, 16}
+ });
+
struct Gwn_Batch *geom = DRW_cache_image_plane_wire_get();
DRWShadingGroup *grp = DRW_shgroup_instance_create(
- e_data.object_empty_image_wire_sh, psl->non_meshes, geom);
- DRW_shgroup_attrib_float(grp, "color", 3);
- DRW_shgroup_attrib_float(grp, "size", 1);
- DRW_shgroup_attrib_float(grp, "offset", 2);
- DRW_shgroup_attrib_float(grp, "InstanceModelMatrix", 16);
-
+ e_data.object_empty_image_wire_sh, psl->non_meshes, geom, e_data.empty_image_wire_format);
DRW_shgroup_uniform_vec2(grp, "aspect", empty_image_data->image_aspect, 1);
empty_image_data->shgrp_wire = grp;
@@ -1533,7 +1545,8 @@ static void DRW_shgroup_lightprobe(OBJECT_StorageList *stl, OBJECT_PassList *psl
mul_m4_v3(ob->obmat, prb_data->increment_z);
sub_v3_v3(prb_data->increment_z, prb_data->corner);
- DRWShadingGroup *grp = DRW_shgroup_instance_create(e_data.lightprobe_grid_sh, psl->lightprobes, DRW_cache_sphere_get());
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(e_data.lightprobe_grid_sh, psl->lightprobes,
+ DRW_cache_sphere_get(), NULL);
DRW_shgroup_set_instance_count(grp, prb->grid_resolution_x * prb->grid_resolution_y * prb->grid_resolution_z);
DRW_shgroup_uniform_vec4(grp, "color", color, 1);
DRW_shgroup_uniform_vec3(grp, "corner", prb_data->corner, 1);
@@ -1753,21 +1766,21 @@ static void OBJECT_cache_populate_particles(Object *ob,
break;
case PART_DRAW_CROSS:
shgrp = DRW_shgroup_instance_create(
- e_data.part_prim_sh, psl->particle, DRW_cache_particles_get_prim(PART_DRAW_CROSS));
+ e_data.part_prim_sh, psl->particle, DRW_cache_particles_get_prim(PART_DRAW_CROSS), NULL);
DRW_shgroup_uniform_texture(shgrp, "ramp", globals_ramp);
DRW_shgroup_uniform_vec3(shgrp, "color", ma ? &ma->r : def_prim_col, 1);
DRW_shgroup_uniform_int(shgrp, "screen_space", &screen_space[0], 1);
break;
case PART_DRAW_CIRC:
shgrp = DRW_shgroup_instance_create(
- e_data.part_prim_sh, psl->particle, DRW_cache_particles_get_prim(PART_DRAW_CIRC));
+ e_data.part_prim_sh, psl->particle, DRW_cache_particles_get_prim(PART_DRAW_CIRC), NULL);
DRW_shgroup_uniform_texture(shgrp, "ramp", globals_ramp);
DRW_shgroup_uniform_vec3(shgrp, "color", ma ? &ma->r : def_prim_col, 1);
DRW_shgroup_uniform_int(shgrp, "screen_space", &screen_space[1], 1);
break;
case PART_DRAW_AXIS:
shgrp = DRW_shgroup_instance_create(
- e_data.part_axis_sh, psl->particle, DRW_cache_particles_get_prim(PART_DRAW_AXIS));
+ e_data.part_axis_sh, psl->particle, DRW_cache_particles_get_prim(PART_DRAW_AXIS), NULL);
DRW_shgroup_uniform_int(shgrp, "screen_space", &screen_space[0], 1);
break;
default: