[Bf-blender-cvs] [fc72a2ff4b] blender2.8: Draw module: code style, encapsulate static vars
Clément Foucault
noreply at git.blender.org
Mon Mar 20 15:29:20 CET 2017
Commit: fc72a2ff4b470b1563d8480d231ca5b1b03a7983
Author: Clément Foucault
Date: Sat Mar 18 22:14:53 2017 +0100
Branches: blender2.8
https://developer.blender.org/rBfc72a2ff4b470b1563d8480d231ca5b1b03a7983
Draw module: code style, encapsulate static vars
===================================================================
M source/blender/draw/engines/clay/clay.c
M source/blender/draw/engines/eevee/eevee.c
M source/blender/draw/modes/edit_armature_mode.c
M source/blender/draw/modes/edit_curve_mode.c
M source/blender/draw/modes/edit_lattice_mode.c
M source/blender/draw/modes/edit_mesh_mode.c
M source/blender/draw/modes/edit_metaball_mode.c
M source/blender/draw/modes/edit_surface_mode.c
M source/blender/draw/modes/edit_text_mode.c
M source/blender/draw/modes/object_mode.c
M source/blender/draw/modes/paint_texture_mode.c
M source/blender/draw/modes/paint_vertex_mode.c
M source/blender/draw/modes/paint_weight_mode.c
M source/blender/draw/modes/particle_mode.c
M source/blender/draw/modes/pose_mode.c
M source/blender/draw/modes/sculpt_mode.c
===================================================================
diff --git a/source/blender/draw/engines/clay/clay.c b/source/blender/draw/engines/clay/clay.c
index a40805a50c..6a7e8d10f9 100644
--- a/source/blender/draw/engines/clay/clay.c
+++ b/source/blender/draw/engines/clay/clay.c
@@ -44,7 +44,7 @@ extern char datatoc_clay_vert_glsl[];
extern char datatoc_ssao_alchemy_glsl[];
extern char datatoc_ssao_groundtruth_glsl[];
-/* Storage */
+/* *********** LISTS *********** */
/* UBOs data needs to be 16 byte aligned (size of vec4) */
/* Reminder : float, int, bool are 4 bytes */
@@ -64,24 +64,6 @@ typedef struct CLAY_UBO_Storage {
CLAY_UBO_Material materials[MAX_CLAY_MAT];
} CLAY_UBO_Storage;
-static struct CLAY_data {
- /* Depth Pre Pass */
- struct GPUShader *depth_sh;
- /* Shading Pass */
- struct GPUShader *clay_sh;
-
- /* Matcap textures */
- struct GPUTexture *matcap_array;
- float matcap_colors[24][3];
-
- /* Ssao */
- float winmat[4][4];
- float viewvecs[3][4];
- float ssao_params[4];
- struct GPUTexture *jitter_tx;
- struct GPUTexture *sampling_tx;
-} data = {NULL};
-
/* GPUViewport.storage
* Is freed everytime the viewport engine changes */
typedef struct CLAY_Storage {
@@ -91,9 +73,6 @@ typedef struct CLAY_Storage {
DRWShadingGroup *shgrps[MAX_CLAY_MAT];
} CLAY_Storage;
-/* Just a serie of int from 0 to MAX_CLAY_MAT-1 */
-static int ubo_mat_idxs[MAX_CLAY_MAT] = {0};
-
/* keep it under MAX_STORAGE */
typedef struct CLAY_StorageList {
struct CLAY_Storage *storage;
@@ -132,6 +111,38 @@ typedef struct CLAY_Data {
CLAY_StorageList *stl;
} CLAY_Data;
+/* *********** STATIC *********** */
+
+static struct {
+ /* Depth Pre Pass */
+ struct GPUShader *depth_sh;
+ /* Shading Pass */
+ struct GPUShader *clay_sh;
+
+ /* Matcap textures */
+ struct GPUTexture *matcap_array;
+ float matcap_colors[24][3];
+
+ /* Ssao */
+ float winmat[4][4];
+ float viewvecs[3][4];
+ float ssao_params[4];
+ struct GPUTexture *jitter_tx;
+ struct GPUTexture *sampling_tx;
+
+ /* Just a serie of int from 0 to MAX_CLAY_MAT-1 */
+ int ubo_mat_idxs[MAX_CLAY_MAT];
+} e_data = {NULL}; /* Engine data */
+
+static struct {
+ DRWShadingGroup *depth_shgrp;
+ DRWShadingGroup *depth_shgrp_select;
+ DRWShadingGroup *depth_shgrp_active;
+ DRWShadingGroup *depth_shgrp_cull;
+ DRWShadingGroup *depth_shgrp_cull_select;
+ DRWShadingGroup *depth_shgrp_cull_active;
+ CLAY_Data *vedata;
+} g_data = {NULL}; /* Transient data */
//#define GTAO
@@ -148,15 +159,15 @@ static void add_icon_to_rect(PreviewImage *prv, float *final_rect, int layer)
/* Find overall color */
for (int y = 0; y < 4; ++y) {
for (int x = 0; x < 4; ++x) {
- data.matcap_colors[layer][0] += new_rect[y * 512 * 128 * 4 + x * 128 * 4 + 0];
- data.matcap_colors[layer][1] += new_rect[y * 512 * 128 * 4 + x * 128 * 4 + 1];
- data.matcap_colors[layer][2] += new_rect[y * 512 * 128 * 4 + x * 128 * 4 + 2];
+ e_data.matcap_colors[layer][0] += new_rect[y * 512 * 128 * 4 + x * 128 * 4 + 0];
+ e_data.matcap_colors[layer][1] += new_rect[y * 512 * 128 * 4 + x * 128 * 4 + 1];
+ e_data.matcap_colors[layer][2] += new_rect[y * 512 * 128 * 4 + x * 128 * 4 + 2];
}
}
- data.matcap_colors[layer][0] /= 16.0f * 2.0f; /* the * 2 is to darken for shadows */
- data.matcap_colors[layer][1] /= 16.0f * 2.0f;
- data.matcap_colors[layer][2] /= 16.0f * 2.0f;
+ e_data.matcap_colors[layer][0] /= 16.0f * 2.0f; /* the * 2 is to darken for shadows */
+ e_data.matcap_colors[layer][1] /= 16.0f * 2.0f;
+ e_data.matcap_colors[layer][2] /= 16.0f * 2.0f;
}
static struct GPUTexture *load_matcaps(PreviewImage *prv[24], int nbr)
@@ -273,13 +284,13 @@ RenderEngineSettings *CLAY_render_settings_create(void)
static void CLAY_engine_init(void)
{
- CLAY_Data *vedata = DRW_viewport_engine_data_get("Clay");
- CLAY_StorageList *stl = vedata->stl;
- CLAY_TextureList *txl = vedata->txl;
- CLAY_FramebufferList *fbl = vedata->fbl;
+ CLAY_Data *ved = DRW_viewport_engine_data_get("Clay");
+ CLAY_StorageList *stl = ved->stl;
+ CLAY_TextureList *txl = ved->txl;
+ CLAY_FramebufferList *fbl = ved->fbl;
/* Create Texture Array */
- if (!data.matcap_array) {
+ if (!e_data.matcap_array) {
PreviewImage *prv[24]; /* For now use all of the 24 internal matcaps */
/* TODO only load used matcaps */
@@ -308,27 +319,27 @@ static void CLAY_engine_init(void)
prv[22] = UI_icon_to_preview(ICON_MATCAP_23);
prv[23] = UI_icon_to_preview(ICON_MATCAP_24);
- data.matcap_array = load_matcaps(prv, 24);
+ e_data.matcap_array = load_matcaps(prv, 24);
}
/* AO Jitter */
- if (!data.jitter_tx) {
- data.jitter_tx = create_jitter_texture();
+ if (!e_data.jitter_tx) {
+ e_data.jitter_tx = create_jitter_texture();
}
/* AO Samples */
/* TODO use hammersley sequence */
- if (!data.sampling_tx) {
- data.sampling_tx = create_spiral_sample_texture(500);
+ if (!e_data.sampling_tx) {
+ e_data.sampling_tx = create_spiral_sample_texture(500);
}
/* Depth prepass */
- if (!data.depth_sh) {
- data.depth_sh = DRW_shader_create_3D_depth_only();
+ if (!e_data.depth_sh) {
+ e_data.depth_sh = DRW_shader_create_3D_depth_only();
}
/* Shading pass */
- if (!data.clay_sh) {
+ if (!e_data.clay_sh) {
DynStr *ds = BLI_dynstr_new();
const char *max_mat =
"#define MAX_MATERIAL 512\n"
@@ -346,7 +357,7 @@ static void CLAY_engine_init(void)
matcap_with_ao = BLI_dynstr_get_cstring(ds);
- data.clay_sh = DRW_shader_create(datatoc_clay_vert_glsl, NULL, matcap_with_ao, max_mat);
+ e_data.clay_sh = DRW_shader_create(datatoc_clay_vert_glsl, NULL, matcap_with_ao, max_mat);
BLI_dynstr_free(ds);
MEM_freeN(matcap_with_ao);
@@ -360,10 +371,10 @@ static void CLAY_engine_init(void)
stl->mat_ubo = DRW_uniformbuffer_create(sizeof(CLAY_UBO_Storage), NULL);
}
- if (ubo_mat_idxs[1] == 0) {
+ if (e_data.ubo_mat_idxs[1] == 0) {
/* Just int to have pointers to them */
for (int i = 0; i < MAX_CLAY_MAT; ++i) {
- ubo_mat_idxs[i] = i;
+ e_data.ubo_mat_idxs[i] = i;
}
}
@@ -392,14 +403,14 @@ static void CLAY_engine_init(void)
DRW_get_dfdy_factors(dfdyfacs);
- data.ssao_params[0] = settings->ssao_samples;
- data.ssao_params[1] = size[0] / 64.0;
- data.ssao_params[2] = size[1] / 64.0;
- data.ssao_params[3] = dfdyfacs[1]; /* dfdy sign for offscreen */
+ e_data.ssao_params[0] = settings->ssao_samples;
+ e_data.ssao_params[1] = size[0] / 64.0;
+ e_data.ssao_params[2] = size[1] / 64.0;
+ e_data.ssao_params[3] = dfdyfacs[1]; /* dfdy sign for offscreen */
/* invert the view matrix */
- DRW_viewport_matrix_get(data.winmat, DRW_MAT_WIN);
- invert_m4_m4(invproj, data.winmat);
+ DRW_viewport_matrix_get(e_data.winmat, DRW_MAT_WIN);
+ invert_m4_m4(invproj, e_data.winmat);
/* convert the view vectors to view space */
for (i = 0; i < 3; i++) {
@@ -410,19 +421,19 @@ static void CLAY_engine_init(void)
mul_v3_fl(viewvecs[i], 1.0f / viewvecs[i][2]);
viewvecs[i][3] = 1.0;
- copy_v4_v4(data.viewvecs[i], viewvecs[i]);
+ copy_v4_v4(e_data.viewvecs[i], viewvecs[i]);
}
/* we need to store the differences */
- data.viewvecs[1][0] -= data.viewvecs[0][0];
- data.viewvecs[1][1] = data.viewvecs[2][1] - data.viewvecs[0][1];
+ e_data.viewvecs[1][0] -= e_data.viewvecs[0][0];
+ e_data.viewvecs[1][1] = e_data.viewvecs[2][1] - e_data.viewvecs[0][1];
/* calculate a depth offset as well */
if (!is_persp) {
float vec_far[] = {-1.0f, -1.0f, 1.0f, 1.0f};
mul_m4_v4(invproj, vec_far);
mul_v3_fl(vec_far, 1.0f / vec_far[3]);
- data.viewvecs[1][2] = vec_far[2] - data.viewvecs[0][2];
+ e_data.viewvecs[1][2] = vec_far[2] - e_data.viewvecs[0][2];
}
}
}
@@ -433,21 +444,21 @@ static DRWShadingGroup *CLAY_shgroup_create(DRWPass *pass, int *material_id)
CLAY_TextureList *txl = vedata->txl;
const int depthloc = 0, matcaploc = 1, jitterloc = 2, sampleloc = 3;
- DRWShadingGroup *grp = DRW_shgroup_create(data.clay_sh, pass);
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.clay_sh, pass);
DRW_shgroup_uniform_vec2(grp, "screenres", DRW_viewport_size_get(), 1);
DRW_shgroup_uniform_buffer(grp, "depthtex", &txl->depth_dup, depthloc);
- DRW_shgroup_uniform_texture(grp, "matcaps", data.matcap_array, matcaploc);
- DRW_shgroup_uniform_mat4(grp, "WinMatrix", (float *)data.winmat);
- DRW_shgroup_uniform_vec4(grp, "viewvecs", (float *)data.viewvecs, 3);
- DRW_shgroup_uniform_vec4(grp, "ssao_params", data.ssao_params, 1);
- DRW_shgroup_uniform_vec3(grp, "matcaps_color", (float *)data.matcap_colors, 24);
+ DRW_shgroup_uniform_texture(grp, "matcaps", e_data.matcap_array, matcaploc);
+ DRW_shgroup_uniform_mat4(grp, "WinMatrix", (float *)e_data.winmat);
+ DRW_shgroup_uniform_vec4(grp, "viewvecs", (float *)e_data.viewvecs, 3);
+ DRW_shgroup_uniform_vec4(grp, "ssao_params", e_data.ssao_params, 1);
+ DRW_shgroup_uniform_vec3(grp, "matcaps_color", (float *)e_data.matcap_colors, 24);
DRW_shgroup_uniform_int(grp, "mat_id", material_id, 1);
#ifndef GTAO
- DRW_shgroup_uniform_texture(grp, "ssao_jitter", data.jitter_tx, jitterloc);
- DRW_shgroup_uniform_texture(grp, "ssao_samples", data.sampling_tx, sampleloc);
+ DRW_shgroup_uniform_texture(grp, "ssao_jitter", e_data.jitter_tx, jitterloc);
+ DRW_shgroup_uniform_texture(grp, "ssao_samples", e_data.sampling_tx, sampleloc);
#endif
return grp;
@@ -586,7 +597,7 @@ static DRWShadingGroup *CLAY_object_shgrp_get(Object *ob, CLAY_StorageList *stl,
ssao_attenuation, matcap_icon);
if (shgrps[id] == NULL) {
- shgrps[id] = CLAY_shgroup_create(psl->clay_pass, &ubo_mat_idxs[id]);
+ shgrps[id] = CLAY_shgroup_create(psl->clay_pass, &e_data.ubo_mat_idxs[id]);
/* if it's the first shgrp, pass bind the material UBO */
if (stl->storage->ubo_current_id == 1) {
DRW_shgroup_uniform_block(shgrps[0], "material_block", stl->mat_ubo, 0);
@@ -596,38 +607,31 @@ static DRWShadingGroup *CLAY_object_shgrp_get(Object *ob, CLAY_StorageList *stl,
return shgrps[id];
}
-static DRWShadingGroup *depth_shgrp;
-static DRWShadingGroup *depth_shgrp_select;
-static DRWShadingGroup *depth_shgrp_active;
-static DRWShadingGroup *depth_shgrp_cull;
-static DRWShadingGroup *depth_shgrp_cull_select;
-static DRWShadingGroup *depth_shgrp_cull_active;
-
static void CLAY_cache_init(void)
{
- CLAY
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list