Cleanup: style, use braces for gpu

This commit is contained in:
Campbell Barton 2019-04-22 09:32:37 +10:00
parent 620b960d3d
commit 14a49950ff
15 changed files with 532 additions and 266 deletions

View File

@ -194,8 +194,9 @@ int GPU_batch_vertbuf_add_ex(GPUBatch *batch, GPUVertBuf *verts, bool own_vbo)
#endif
batch->verts[v] = verts;
/* TODO: mark dirty so we can keep attribute bindings up-to-date */
if (own_vbo)
if (own_vbo) {
batch->owns_flag |= (1 << v);
}
return v;
}
}
@ -211,14 +212,18 @@ static GLuint batch_vao_get(GPUBatch *batch)
{
/* Search through cache */
if (batch->is_dynamic_vao_count) {
for (int i = 0; i < batch->dynamic_vaos.count; ++i)
if (batch->dynamic_vaos.interfaces[i] == batch->interface)
for (int i = 0; i < batch->dynamic_vaos.count; ++i) {
if (batch->dynamic_vaos.interfaces[i] == batch->interface) {
return batch->dynamic_vaos.vao_ids[i];
}
}
}
else {
for (int i = 0; i < GPU_BATCH_VAO_STATIC_LEN; ++i)
if (batch->static_vaos.interfaces[i] == batch->interface)
for (int i = 0; i < GPU_BATCH_VAO_STATIC_LEN; ++i) {
if (batch->static_vaos.interfaces[i] == batch->interface) {
return batch->static_vaos.vao_ids[i];
}
}
}
/* Set context of this batch.
@ -239,9 +244,11 @@ static GLuint batch_vao_get(GPUBatch *batch)
GLuint new_vao = 0;
if (!batch->is_dynamic_vao_count) {
int i; /* find first unused slot */
for (i = 0; i < GPU_BATCH_VAO_STATIC_LEN; ++i)
if (batch->static_vaos.vao_ids[i] == 0)
for (i = 0; i < GPU_BATCH_VAO_STATIC_LEN; ++i) {
if (batch->static_vaos.vao_ids[i] == 0) {
break;
}
}
if (i < GPU_BATCH_VAO_STATIC_LEN) {
batch->static_vaos.interfaces[i] = batch->interface;
@ -267,9 +274,11 @@ static GLuint batch_vao_get(GPUBatch *batch)
if (batch->is_dynamic_vao_count) {
int i; /* find first unused slot */
for (i = 0; i < batch->dynamic_vaos.count; ++i)
if (batch->dynamic_vaos.vao_ids[i] == 0)
for (i = 0; i < batch->dynamic_vaos.count; ++i) {
if (batch->dynamic_vaos.vao_ids[i] == 0) {
break;
}
}
if (i == batch->dynamic_vaos.count) {
/* Not enough place, realloc the array. */
@ -362,8 +371,9 @@ static void create_bindings(GPUVertBuf *verts,
for (uint n_idx = 0; n_idx < a->name_len; ++n_idx) {
const GPUShaderInput *input = GPU_shaderinterface_attr(interface, a->name[n_idx]);
if (input == NULL)
if (input == NULL) {
continue;
}
if (a->comp_len == 16 || a->comp_len == 12 || a->comp_len == 8) {
#if TRUST_NO_ONE
@ -540,10 +550,12 @@ static void primitive_restart_enable(const GPUIndexBuf *el)
GLuint restart_index = (GLuint)0xFFFFFFFF;
#if GPU_TRACK_INDEX_RANGE
if (el->index_type == GPU_INDEX_U8)
if (el->index_type == GPU_INDEX_U8) {
restart_index = (GLuint)0xFF;
else if (el->index_type == GPU_INDEX_U16)
}
else if (el->index_type == GPU_INDEX_U16) {
restart_index = (GLuint)0xFFFF;
}
#endif
glPrimitiveRestartIndex(restart_index);
@ -557,13 +569,16 @@ static void primitive_restart_disable(void)
static void *elem_offset(const GPUIndexBuf *el, int v_first)
{
#if GPU_TRACK_INDEX_RANGE
if (el->index_type == GPU_INDEX_U8)
if (el->index_type == GPU_INDEX_U8) {
return (GLubyte *)0 + v_first;
else if (el->index_type == GPU_INDEX_U16)
}
else if (el->index_type == GPU_INDEX_U16) {
return (GLushort *)0 + v_first;
else
}
else {
#endif
return (GLuint *)0 + v_first;
}
}
void GPU_batch_draw(GPUBatch *batch)

View File

@ -231,8 +231,9 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers,
buffers->mloop[lt->tri[2]].v,
};
if (paint_is_face_hidden(lt, mvert, buffers->mloop))
if (paint_is_face_hidden(lt, mvert, buffers->mloop)) {
continue;
}
/* Face normal and mask */
if (lt->poly != mpoly_prev) {
@ -291,8 +292,9 @@ GPU_PBVH_Buffers *GPU_pbvh_mesh_buffers_build(const int (*face_vert_indices)[3],
/* Count the number of visible triangles */
for (i = 0, tottri = 0; i < face_indices_len; ++i) {
const MLoopTri *lt = &looptri[face_indices[i]];
if (!paint_is_face_hidden(lt, mvert, mloop))
if (!paint_is_face_hidden(lt, mvert, mloop)) {
tottri++;
}
}
if (tottri == 0) {
@ -325,8 +327,9 @@ GPU_PBVH_Buffers *GPU_pbvh_mesh_buffers_build(const int (*face_vert_indices)[3],
const MLoopTri *lt = &looptri[face_indices[i]];
/* Skip hidden faces */
if (paint_is_face_hidden(lt, mvert, mloop))
if (paint_is_face_hidden(lt, mvert, mloop)) {
continue;
}
GPU_indexbuf_add_tri_verts(&elb, UNPACK3(face_vert_indices[i]));
@ -347,8 +350,9 @@ GPU_PBVH_Buffers *GPU_pbvh_mesh_buffers_build(const int (*face_vert_indices)[3],
const MLoopTri *lt = &looptri[face_indices[i]];
/* Skip hidden faces */
if (paint_is_face_hidden(lt, mvert, mloop))
if (paint_is_face_hidden(lt, mvert, mloop)) {
continue;
}
/* TODO skip "non-real" edges. */
GPU_indexbuf_add_line_verts(&elb_lines, i * 3 + 0, i * 3 + 1);
@ -706,13 +710,15 @@ static int gpu_bmesh_vert_visible_count(GSet *bm_unique_verts, GSet *bm_other_ve
GSET_ITER (gs_iter, bm_unique_verts) {
BMVert *v = BLI_gsetIterator_getKey(&gs_iter);
if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN))
if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN)) {
totvert++;
}
}
GSET_ITER (gs_iter, bm_other_verts) {
BMVert *v = BLI_gsetIterator_getKey(&gs_iter);
if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN))
if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN)) {
totvert++;
}
}
return totvert;
@ -727,8 +733,9 @@ static int gpu_bmesh_face_visible_count(GSet *bm_faces)
GSET_ITER (gh_iter, bm_faces) {
BMFace *f = BLI_gsetIterator_getKey(&gh_iter);
if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN))
if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
totface++;
}
}
return totface;
@ -966,10 +973,12 @@ void GPU_pbvh_buffers_free(GPU_PBVH_Buffers *buffers)
/* debug function, draws the pbvh BB */
void GPU_pbvh_BB_draw(float min[3], float max[3], bool leaf, uint pos)
{
if (leaf)
if (leaf) {
immUniformColor4f(0.0, 1.0, 0.0, 0.5);
else
}
else {
immUniformColor4f(1.0, 0.0, 0.0, 0.5);
}
/* TODO(merwin): revisit this after we have mutable VertexBuffers
* could keep a static batch & index buffer, change the VBO contents per draw

View File

@ -81,8 +81,9 @@ static uint32_t gpu_pass_hash(const char *frag_gen, const char *defs, GPUVertAtt
BLI_hash_mm2a_add(&hm2a, (uchar *)name, strlen(name));
}
}
if (defs)
if (defs) {
BLI_hash_mm2a_add(&hm2a, (uchar *)defs, strlen(defs));
}
return BLI_hash_mm2a_end(&hm2a);
}
@ -180,8 +181,9 @@ static GPUShader *FUNCTION_LIB = NULL;
static int gpu_str_prefix(const char *str, const char *prefix)
{
while (*str && *prefix) {
if (*str != *prefix)
if (*str != *prefix) {
return 0;
}
str++;
prefix++;
@ -196,8 +198,9 @@ static char *gpu_str_skip_token(char *str, char *token, int max)
/* skip a variable/function name */
while (*str) {
if (ELEM(*str, ' ', '(', ')', ',', ';', '\t', '\n', '\r'))
if (ELEM(*str, ' ', '(', ')', ',', ';', '\t', '\n', '\r')) {
break;
}
else {
if (token && len < max - 1) {
*token = *str;
@ -208,16 +211,19 @@ static char *gpu_str_skip_token(char *str, char *token, int max)
}
}
if (token)
if (token) {
*token = '\0';
}
/* skip the next special characters:
* note the missing ')' */
while (*str) {
if (ELEM(*str, ' ', '(', ',', ';', '\t', '\n', '\r'))
if (ELEM(*str, ' ', '(', ',', ';', '\t', '\n', '\r')) {
str++;
else
}
else {
break;
}
}
return str;
@ -240,12 +246,15 @@ static void gpu_parse_functions_string(GHash *hash, char *code)
while (*code && *code != ')') {
/* test if it's an input or output */
qual = FUNCTION_QUAL_IN;
if (gpu_str_prefix(code, "out "))
if (gpu_str_prefix(code, "out ")) {
qual = FUNCTION_QUAL_OUT;
if (gpu_str_prefix(code, "inout "))
}
if (gpu_str_prefix(code, "inout ")) {
qual = FUNCTION_QUAL_INOUT;
if ((qual != FUNCTION_QUAL_IN) || gpu_str_prefix(code, "in "))
}
if ((qual != FUNCTION_QUAL_IN) || gpu_str_prefix(code, "in ")) {
code = gpu_str_skip_token(code, NULL, 0);
}
/* test for type */
type = GPU_NONE;
@ -368,8 +377,9 @@ void gpu_codegen_exit(void)
{
extern Material defmaterial; /* render module abuse... */
if (defmaterial.gpumaterial.first)
if (defmaterial.gpumaterial.first) {
GPU_material_free(&defmaterial.gpumaterial);
}
if (FUNCTION_HASH) {
BLI_ghash_free(FUNCTION_HASH, NULL, MEM_freeN);
@ -407,46 +417,62 @@ static void codegen_convert_datatype(DynStr *ds, int from, int to, const char *t
BLI_dynstr_append(ds, name);
}
else if (to == GPU_FLOAT) {
if (from == GPU_VEC4)
if (from == GPU_VEC4) {
BLI_dynstr_appendf(ds, "convert_rgba_to_float(%s)", name);
else if (from == GPU_VEC3)
}
else if (from == GPU_VEC3) {
BLI_dynstr_appendf(ds, "(%s.r + %s.g + %s.b) / 3.0", name, name, name);
else if (from == GPU_VEC2)
}
else if (from == GPU_VEC2) {
BLI_dynstr_appendf(ds, "%s.r", name);
}
}
else if (to == GPU_VEC2) {
if (from == GPU_VEC4)
if (from == GPU_VEC4) {
BLI_dynstr_appendf(ds, "vec2((%s.r + %s.g + %s.b) / 3.0, %s.a)", name, name, name, name);
else if (from == GPU_VEC3)
}
else if (from == GPU_VEC3) {
BLI_dynstr_appendf(ds, "vec2((%s.r + %s.g + %s.b) / 3.0, 1.0)", name, name, name);
else if (from == GPU_FLOAT)
}
else if (from == GPU_FLOAT) {
BLI_dynstr_appendf(ds, "vec2(%s, 1.0)", name);
}
}
else if (to == GPU_VEC3) {
if (from == GPU_VEC4)
if (from == GPU_VEC4) {
BLI_dynstr_appendf(ds, "%s.rgb", name);
else if (from == GPU_VEC2)
}
else if (from == GPU_VEC2) {
BLI_dynstr_appendf(ds, "vec3(%s.r, %s.r, %s.r)", name, name, name);
else if (from == GPU_FLOAT)
}
else if (from == GPU_FLOAT) {
BLI_dynstr_appendf(ds, "vec3(%s, %s, %s)", name, name, name);
}
}
else if (to == GPU_VEC4) {
if (from == GPU_VEC3)
if (from == GPU_VEC3) {
BLI_dynstr_appendf(ds, "vec4(%s, 1.0)", name);
else if (from == GPU_VEC2)
}
else if (from == GPU_VEC2) {
BLI_dynstr_appendf(ds, "vec4(%s.r, %s.r, %s.r, %s.g)", name, name, name, name);
else if (from == GPU_FLOAT)
}
else if (from == GPU_FLOAT) {
BLI_dynstr_appendf(ds, "vec4(%s, %s, %s, 1.0)", name, name, name);
}
}
else if (to == GPU_CLOSURE) {
if (from == GPU_VEC4)
if (from == GPU_VEC4) {
BLI_dynstr_appendf(ds, "closure_emission(%s.rgb)", name);
else if (from == GPU_VEC3)
}
else if (from == GPU_VEC3) {
BLI_dynstr_appendf(ds, "closure_emission(%s.rgb)", name);
else if (from == GPU_VEC2)
}
else if (from == GPU_VEC2) {
BLI_dynstr_appendf(ds, "closure_emission(%s.rrr)", name);
else if (from == GPU_FLOAT)
}
else if (from == GPU_FLOAT) {
BLI_dynstr_appendf(ds, "closure_emission(vec3(%s, %s, %s))", name, name, name);
}
}
else {
BLI_dynstr_append(ds, name);
@ -461,69 +487,96 @@ static void codegen_print_datatype(DynStr *ds, const eGPUType type, float *data)
for (i = 0; i < type; i++) {
BLI_dynstr_appendf(ds, "%.12f", data[i]);
if (i == type - 1)
if (i == type - 1) {
BLI_dynstr_append(ds, ")");
else
}
else {
BLI_dynstr_append(ds, ", ");
}
}
}
static int codegen_input_has_texture(GPUInput *input)
{
if (input->link)
if (input->link) {
return 0;
else
}
else {
return (input->source == GPU_SOURCE_TEX);
}
}
const char *GPU_builtin_name(eGPUBuiltin builtin)
{
if (builtin == GPU_VIEW_MATRIX)
if (builtin == GPU_VIEW_MATRIX) {
return "unfviewmat";
else if (builtin == GPU_OBJECT_MATRIX)
}
else if (builtin == GPU_OBJECT_MATRIX) {
return "unfobmat";
else if (builtin == GPU_INVERSE_VIEW_MATRIX)
}
else if (builtin == GPU_INVERSE_VIEW_MATRIX) {
return "unfinvviewmat";
else if (builtin == GPU_INVERSE_OBJECT_MATRIX)
}
else if (builtin == GPU_INVERSE_OBJECT_MATRIX) {
return "unfinvobmat";
else if (builtin == GPU_INVERSE_NORMAL_MATRIX)
}
else if (builtin == GPU_INVERSE_NORMAL_MATRIX) {
return "unfinvnormat";
else if (builtin == GPU_LOC_TO_VIEW_MATRIX)
}
else if (builtin == GPU_LOC_TO_VIEW_MATRIX) {
return "unflocaltoviewmat";
else if (builtin == GPU_INVERSE_LOC_TO_VIEW_MATRIX)
}
else if (builtin == GPU_INVERSE_LOC_TO_VIEW_MATRIX) {
return "unfinvlocaltoviewmat";
else if (builtin == GPU_VIEW_POSITION)
}
else if (builtin == GPU_VIEW_POSITION) {
return "varposition";
else if (builtin == GPU_VIEW_NORMAL)
}
else if (builtin == GPU_VIEW_NORMAL) {
return "varnormal";
else if (builtin == GPU_OBCOLOR)
}
else if (builtin == GPU_OBCOLOR) {
return "unfobcolor";
else if (builtin == GPU_AUTO_BUMPSCALE)
}
else if (builtin == GPU_AUTO_BUMPSCALE) {
return "unfobautobumpscale";
else if (builtin == GPU_CAMERA_TEXCO_FACTORS)
}
else if (builtin == GPU_CAMERA_TEXCO_FACTORS) {
return "unfcameratexfactors";
else if (builtin == GPU_PARTICLE_SCALAR_PROPS)
}
else if (builtin == GPU_PARTICLE_SCALAR_PROPS) {
return "unfparticlescalarprops";
else if (builtin == GPU_PARTICLE_LOCATION)
}
else if (builtin == GPU_PARTICLE_LOCATION) {
return "unfparticleco";
else if (builtin == GPU_PARTICLE_VELOCITY)
}
else if (builtin == GPU_PARTICLE_VELOCITY) {
return "unfparticlevel";
else if (builtin == GPU_PARTICLE_ANG_VELOCITY)
}
else if (builtin == GPU_PARTICLE_ANG_VELOCITY) {
return "unfparticleangvel";
else if (builtin == GPU_OBJECT_INFO)
}
else if (builtin == GPU_OBJECT_INFO) {
return "unfobjectinfo";
else if (builtin == GPU_VOLUME_DENSITY)
}
else if (builtin == GPU_VOLUME_DENSITY) {
return "sampdensity";
else if (builtin == GPU_VOLUME_FLAME)
}
else if (builtin == GPU_VOLUME_FLAME) {
return "sampflame";
else if (builtin == GPU_VOLUME_TEMPERATURE)
}
else if (builtin == GPU_VOLUME_TEMPERATURE) {
return "unftemperature";
else if (builtin == GPU_BARYCENTRIC_TEXCO)
}
else if (builtin == GPU_BARYCENTRIC_TEXCO) {
return "unfbarycentrictex";
else if (builtin == GPU_BARYCENTRIC_DIST)
}
else if (builtin == GPU_BARYCENTRIC_DIST) {
return "unfbarycentricdist";
else
}
else {
return "";
}
}
/* assign only one texid per buffer to avoid sampling the same texture twice */
@ -706,32 +759,45 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final
}
else if (input->source == GPU_SOURCE_BUILTIN) {
/* TODO(fclem) get rid of that. */
if (input->builtin == GPU_INVERSE_VIEW_MATRIX)
if (input->builtin == GPU_INVERSE_VIEW_MATRIX) {
BLI_dynstr_append(ds, "viewinv");
else if (input->builtin == GPU_VIEW_MATRIX)
}
else if (input->builtin == GPU_VIEW_MATRIX) {
BLI_dynstr_append(ds, "viewmat");
else if (input->builtin == GPU_CAMERA_TEXCO_FACTORS)
}
else if (input->builtin == GPU_CAMERA_TEXCO_FACTORS) {
BLI_dynstr_append(ds, "camtexfac");
else if (input->builtin == GPU_LOC_TO_VIEW_MATRIX)
}
else if (input->builtin == GPU_LOC_TO_VIEW_MATRIX) {
BLI_dynstr_append(ds, "localtoviewmat");
else if (input->builtin == GPU_INVERSE_LOC_TO_VIEW_MATRIX)
}
else if (input->builtin == GPU_INVERSE_LOC_TO_VIEW_MATRIX) {
BLI_dynstr_append(ds, "invlocaltoviewmat");
else if (input->builtin == GPU_BARYCENTRIC_DIST)
}
else if (input->builtin == GPU_BARYCENTRIC_DIST) {
BLI_dynstr_append(ds, "barycentricDist");
else if (input->builtin == GPU_BARYCENTRIC_TEXCO)
}
else if (input->builtin == GPU_BARYCENTRIC_TEXCO) {
BLI_dynstr_append(ds, "barytexco");
else if (input->builtin == GPU_OBJECT_MATRIX)
}
else if (input->builtin == GPU_OBJECT_MATRIX) {
BLI_dynstr_append(ds, "objmat");
else if (input->builtin == GPU_INVERSE_OBJECT_MATRIX)
}
else if (input->builtin == GPU_INVERSE_OBJECT_MATRIX) {
BLI_dynstr_append(ds, "objinv");
else if (input->builtin == GPU_INVERSE_NORMAL_MATRIX)
}
else if (input->builtin == GPU_INVERSE_NORMAL_MATRIX) {
BLI_dynstr_append(ds, "norinv");
else if (input->builtin == GPU_VIEW_POSITION)
}
else if (input->builtin == GPU_VIEW_POSITION) {
BLI_dynstr_append(ds, "viewposition");
else if (input->builtin == GPU_VIEW_NORMAL)
}
else if (input->builtin == GPU_VIEW_NORMAL) {
BLI_dynstr_append(ds, "facingnormal");
else
}
else {
BLI_dynstr_append(ds, GPU_builtin_name(input->builtin));
}
}
else if (input->source == GPU_SOURCE_STRUCT) {
BLI_dynstr_appendf(ds, "strct%d", input->id);
@ -751,8 +817,9 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final
for (output = node->outputs.first; output; output = output->next) {
BLI_dynstr_appendf(ds, "tmp%d", output->id);
if (output->next)
if (output->next) {
BLI_dynstr_append(ds, ", ");
}
}
BLI_dynstr_append(ds, ");\n");
@ -778,11 +845,13 @@ static char *code_generate_fragment(GPUMaterial *material,
codegen_set_unique_ids(nodes);
*rbuiltins = builtins = codegen_process_uniforms_functions(material, ds, nodes);
if (builtins & GPU_BARYCENTRIC_TEXCO)
if (builtins & GPU_BARYCENTRIC_TEXCO) {
BLI_dynstr_append(ds, "in vec2 barycentricTexCo;\n");
}
if (builtins & GPU_BARYCENTRIC_DIST)
if (builtins & GPU_BARYCENTRIC_DIST) {
BLI_dynstr_append(ds, "flat in vec3 barycentricDist;\n");
}
BLI_dynstr_append(ds, "Closure nodetree_exec(void)\n{\n");
@ -798,26 +867,36 @@ static char *code_generate_fragment(GPUMaterial *material,
BLI_dynstr_append(ds, "#endif\n");
}
/* TODO(fclem) get rid of that. */
if (builtins & GPU_VIEW_MATRIX)
if (builtins & GPU_VIEW_MATRIX) {
BLI_dynstr_append(ds, "\t#define viewmat ViewMatrix\n");
if (builtins & GPU_CAMERA_TEXCO_FACTORS)
}
if (builtins & GPU_CAMERA_TEXCO_FACTORS) {
BLI_dynstr_append(ds, "\t#define camtexfac CameraTexCoFactors\n");
if (builtins & GPU_OBJECT_MATRIX)
}
if (builtins & GPU_OBJECT_MATRIX) {
BLI_dynstr_append(ds, "\t#define objmat ModelMatrix\n");
if (builtins & GPU_INVERSE_OBJECT_MATRIX)
}
if (builtins & GPU_INVERSE_OBJECT_MATRIX) {
BLI_dynstr_append(ds, "\t#define objinv ModelMatrixInverse\n");
if (builtins & GPU_INVERSE_NORMAL_MATRIX)
}
if (builtins & GPU_INVERSE_NORMAL_MATRIX) {
BLI_dynstr_append(ds, "\t#define norinv NormalMatrixInverse\n");
if (builtins & GPU_INVERSE_VIEW_MATRIX)
}
if (builtins & GPU_INVERSE_VIEW_MATRIX) {
BLI_dynstr_append(ds, "\t#define viewinv ViewMatrixInverse\n");
if (builtins & GPU_LOC_TO_VIEW_MATRIX)
}
if (builtins & GPU_LOC_TO_VIEW_MATRIX) {
BLI_dynstr_append(ds, "\t#define localtoviewmat ModelViewMatrix\n");
if (builtins & GPU_INVERSE_LOC_TO_VIEW_MATRIX)
}
if (builtins & GPU_INVERSE_LOC_TO_VIEW_MATRIX) {
BLI_dynstr_append(ds, "\t#define invlocaltoviewmat ModelViewMatrixInverse\n");
if (builtins & GPU_VIEW_NORMAL)
}
if (builtins & GPU_VIEW_NORMAL) {
BLI_dynstr_append(ds, "\tvec3 facingnormal = gl_FrontFacing? viewNormal: -viewNormal;\n");
if (builtins & GPU_VIEW_POSITION)
}
if (builtins & GPU_VIEW_POSITION) {
BLI_dynstr_append(ds, "\t#define viewposition viewPosition\n");
}
codegen_declare_tmps(ds, nodes);
codegen_call_functions(ds, nodes, output);
@ -1267,8 +1346,9 @@ void GPU_code_generate_glsl_lib(void)
DynStr *ds;
/* only initialize the library once */
if (glsl_material_library)
if (glsl_material_library) {
return;
}
ds = BLI_dynstr_new();
@ -1293,8 +1373,9 @@ void GPU_nodes_extract_dynamic_inputs(GPUShader *shader, ListBase *inputs, ListB
BLI_listbase_clear(inputs);
if (!shader)
if (!shader) {
return;
}
for (node = nodes->first; node; node = node->next) {
int z = 0;
@ -1308,8 +1389,9 @@ void GPU_nodes_extract_dynamic_inputs(GPUShader *shader, ListBase *inputs, ListB
continue;
}
if (input->source == GPU_SOURCE_TEX)
if (input->source == GPU_SOURCE_TEX) {
BLI_snprintf(input->shadername, sizeof(input->shadername), "samp%d", input->texid);
}
else {
BLI_snprintf(input->shadername, sizeof(input->shadername), "unf%d", input->id);
}
@ -1340,12 +1422,14 @@ static void gpu_node_link_free(GPUNodeLink *link)
{
link->users--;
if (link->users < 0)
if (link->users < 0) {
fprintf(stderr, "GPU_node_link_free: negative refcount\n");
}
if (link->users == 0) {
if (link->output)
if (link->output) {
link->output->link = NULL;
}
MEM_freeN(link);
}
}
@ -1374,8 +1458,9 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const eGPUType
if ((STR_ELEM(name, "set_value", "set_rgb", "set_rgba")) && (input->type == type)) {
input = MEM_dupallocN(outnode->inputs.first);
if (input->link)
if (input->link) {
input->link->users++;
}
BLI_addtail(&node->inputs, input);
return;
}
@ -1540,8 +1625,9 @@ void GPU_inputs_free(ListBase *inputs)
GPUInput *input;
for (input = inputs->first; input; input = input->next) {
if (input->link)
if (input->link) {
gpu_node_link_free(input->link);
}
}
BLI_freelistN(inputs);
@ -1553,11 +1639,12 @@ static void gpu_node_free(GPUNode *node)
GPU_inputs_free(&node->inputs);
for (output = node->outputs.first; output; output = output->next)
for (output = node->outputs.first; output; output = output->next) {
if (output->link) {
output->link->output = NULL;
gpu_node_link_free(output->link);
}
}
BLI_freelistN(&node->outputs);
MEM_freeN(node);
@ -1755,19 +1842,23 @@ bool GPU_stack_link(GPUMaterial *material,
linkptr = va_arg(params, GPUNodeLink **);
gpu_node_output(node, function->paramtype[i], linkptr);
}
else
else {
totout--;
}
}
else {
if (totin == 0) {
link = va_arg(params, GPUNodeLink *);
if (link->socket)
if (link->socket) {
gpu_node_input_socket(NULL, NULL, node, link->socket, -1);
else
}
else {
gpu_node_input_link(node, link, function->paramtype[i]);
}
}
else
else {
totin--;
}
}
}
va_end(params);
@ -1792,25 +1883,30 @@ static void gpu_nodes_tag(GPUNodeLink *link)
GPUNode *node;
GPUInput *input;
if (!link->output)
if (!link->output) {
return;
}
node = link->output->node;
if (node->tag)
if (node->tag) {
return;
}
node->tag = true;
for (input = node->inputs.first; input; input = input->next)
if (input->link)
for (input = node->inputs.first; input; input = input->next) {
if (input->link) {
gpu_nodes_tag(input->link);
}
}
}
void GPU_nodes_prune(ListBase *nodes, GPUNodeLink *outlink)
{
GPUNode *node, *next;
for (node = nodes->first; node; node = node->next)
for (node = nodes->first; node; node = node->next) {
node->tag = false;
}
gpu_nodes_tag(outlink);
@ -2069,8 +2165,9 @@ void GPU_pass_cache_garbage_collect(void)
const int shadercollectrate = 60; /* hardcoded for now. */
int ctime = (int)PIL_check_seconds_timer();
if (ctime < shadercollectrate + lasttime)
if (ctime < shadercollectrate + lasttime) {
return;
}
lasttime = ctime;

View File

@ -258,6 +258,7 @@ void GPU_string_marker(const char *buf)
void GPU_print_error_debug(const char *str)
{
if (G.debug & G_DEBUG)
if (G.debug & G_DEBUG) {
fprintf(stderr, "GPU: %s\n", str);
}
}

View File

@ -98,8 +98,9 @@ static int smaller_power_of_2_limit(int num)
int reslimit = (U.glreslimit != 0) ? min_ii(U.glreslimit, GPU_max_texture_size()) :
GPU_max_texture_size();
/* take texture clamping into account */
if (num > reslimit)
if (num > reslimit) {
return reslimit;
}
return power_of_2_min_i(num);
}
@ -149,10 +150,12 @@ static GLenum gpu_get_mipmap_filter(bool mag)
/* linearmipmap is off by default *when mipmapping is off,
* use unfiltered display */
if (mag) {
if (GTS.domipmap)
if (GTS.domipmap) {
return GL_LINEAR;
else
}
else {
return GL_NEAREST;
}
}
else {
if (GTS.domipmap) {
@ -177,8 +180,9 @@ void GPU_set_anisotropic(Main *bmain, float value)
/* Clamp value to the maximum value the graphics card supports */
const float max = GPU_max_texture_anisotropy();
if (value > max)
if (value > max) {
value = max;
}
GTS.anisotropic = value;
}
@ -193,10 +197,12 @@ float GPU_get_anisotropic(void)
static GPUTexture **gpu_get_image_gputexture(Image *ima, GLenum textarget)
{
if (textarget == GL_TEXTURE_2D)
if (textarget == GL_TEXTURE_2D) {
return &ima->gputexture[TEXTARGET_TEXTURE_2D];
else if (textarget == GL_TEXTURE_CUBE_MAP)
}
else if (textarget == GL_TEXTURE_CUBE_MAP) {
return &ima->gputexture[TEXTARGET_TEXTURE_CUBE_MAP];
}
return NULL;
}
@ -324,15 +330,18 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, int textarget
/* mark as non-color data texture */
if (bindcode) {
if (is_data)
if (is_data) {
ima->gpuflag |= IMA_GPU_IS_DATA;
else
}
else {
ima->gpuflag &= ~IMA_GPU_IS_DATA;
}
}
/* clean up */
if (srgb_frect)
if (srgb_frect) {
MEM_freeN(srgb_frect);
}
BKE_image_release_ibuf(ima, ibuf, NULL);
@ -348,13 +357,15 @@ static void **gpu_gen_cube_map(
int h = recth / 2;
int w = rectw / 3;
if ((use_high_bit_depth && frect == NULL) || (!use_high_bit_depth && rect == NULL) || w != h)
if ((use_high_bit_depth && frect == NULL) || (!use_high_bit_depth && rect == NULL) || w != h) {
return sides;
}
/* PosX, NegX, PosY, NegY, PosZ, NegZ */
sides = MEM_mallocN(sizeof(void *) * 6, "");
for (int i = 0; i < 6; i++)
for (int i = 0; i < 6; i++) {
sides[i] = MEM_mallocN(block_size * w * h, "");
}
/* divide image into six parts */
/* ______________________
@ -402,10 +413,12 @@ static void **gpu_gen_cube_map(
static void gpu_del_cube_map(void **cube_map)
{
int i;
if (cube_map == NULL)
if (cube_map == NULL) {
return;
for (i = 0; i < 6; i++)
}
for (i = 0; i < 6; i++) {
MEM_freeN(cube_map[i]);
}
MEM_freeN(cube_map);
}
@ -459,8 +472,9 @@ void GPU_create_gl_tex(uint *bind,
if (GPU_get_mipmap() && mipmap) {
glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
if (ima)
if (ima) {
ima->gpuflag |= IMA_GPU_MIPMAP_COMPLETE;
}
}
else {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@ -474,8 +488,8 @@ void GPU_create_gl_tex(uint *bind,
GLenum informat = use_high_bit_depth ? GL_RGBA16F : GL_RGBA8;
GLenum type = use_high_bit_depth ? GL_FLOAT : GL_UNSIGNED_BYTE;
if (cube_map)
for (int i = 0; i < 6; i++)
if (cube_map) {
for (int i = 0; i < 6; i++) {
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
0,
informat,
@ -485,6 +499,8 @@ void GPU_create_gl_tex(uint *bind,
GL_RGBA,
type,
cube_map[i]);
}
}
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
@ -492,8 +508,9 @@ void GPU_create_gl_tex(uint *bind,
glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
if (ima)
if (ima) {
ima->gpuflag |= IMA_GPU_MIPMAP_COMPLETE;
}
}
else {
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@ -509,13 +526,15 @@ void GPU_create_gl_tex(uint *bind,
}
}
if (GLEW_EXT_texture_filter_anisotropic)
if (GLEW_EXT_texture_filter_anisotropic) {
glTexParameterf(textarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, GPU_get_anisotropic());
}
glBindTexture(textarget, 0);
if (ibuf)
if (ibuf) {
IMB_freeImBuf(ibuf);
}
}
/**
@ -533,12 +552,15 @@ bool GPU_upload_dxt_texture(ImBuf *ibuf)
height = ibuf->y;
if (GLEW_EXT_texture_compression_s3tc) {
if (ibuf->dds_data.fourcc == FOURCC_DXT1)
if (ibuf->dds_data.fourcc == FOURCC_DXT1) {
format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
else if (ibuf->dds_data.fourcc == FOURCC_DXT3)
}
else if (ibuf->dds_data.fourcc == FOURCC_DXT3) {
format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
else if (ibuf->dds_data.fourcc == FOURCC_DXT5)
}
else if (ibuf->dds_data.fourcc == FOURCC_DXT5) {
format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
}
}
if (format == 0) {
@ -556,15 +578,18 @@ bool GPU_upload_dxt_texture(ImBuf *ibuf)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
if (GLEW_EXT_texture_filter_anisotropic)
if (GLEW_EXT_texture_filter_anisotropic) {
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, GPU_get_anisotropic());
}
blocksize = (ibuf->dds_data.fourcc == FOURCC_DXT1) ? 8 : 16;
for (i = 0; i < ibuf->dds_data.nummipmaps && (width || height); ++i) {
if (width == 0)
if (width == 0) {
width = 1;
if (height == 0)
}
if (height == 0) {
height = 1;
}
size = ((width + 3) / 4) * ((height + 3) / 4) * blocksize;
@ -612,8 +637,9 @@ void GPU_create_gl_tex_compressed(
* re-uploaded to OpenGL */
void GPU_paint_set_mipmap(Main *bmain, bool mipmap)
{
if (!GTS.domipmap)
if (!GTS.domipmap) {
return;
}
GTS.texpaint = !mipmap;
@ -628,11 +654,13 @@ void GPU_paint_set_mipmap(Main *bmain, bool mipmap)
GPU_texture_unbind(ima->gputexture[TEXTARGET_TEXTURE_2D]);
}
}
else
else {
GPU_free_image(ima);
}
}
else
else {
ima->gpuflag &= ~IMA_GPU_MIPMAP_COMPLETE;
}
}
}
else {
@ -645,8 +673,9 @@ void GPU_paint_set_mipmap(Main *bmain, bool mipmap)
GPU_texture_unbind(ima->gputexture[TEXTARGET_TEXTURE_2D]);
}
}
else
else {
ima->gpuflag &= ~IMA_GPU_MIPMAP_COMPLETE;
}
}
}
}
@ -672,10 +701,12 @@ static bool gpu_check_scaled_image(
y *= yratio;
/* ...but take back if we are over the limit! */
if (rectw + x > x_limit)
if (rectw + x > x_limit) {
rectw--;
if (recth + y > y_limit)
}
if (recth + y > y_limit) {
recth--;
}
GPU_texture_bind(ima->gputexture[TEXTARGET_TEXTURE_2D], 0);
@ -1028,28 +1059,34 @@ static GPUTexture *create_flame_texture(SmokeDomainSettings *sds, int highres)
void GPU_free_smoke(SmokeModifierData *smd)
{
if (smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain) {
if (smd->domain->tex)
if (smd->domain->tex) {
GPU_texture_free(smd->domain->tex);
}
smd->domain->tex = NULL;
if (smd->domain->tex_shadow)
if (smd->domain->tex_shadow) {
GPU_texture_free(smd->domain->tex_shadow);
}
smd->domain->tex_shadow = NULL;
if (smd->domain->tex_flame)
if (smd->domain->tex_flame) {
GPU_texture_free(smd->domain->tex_flame);
}
smd->domain->tex_flame = NULL;
if (smd->domain->tex_flame_coba)
if (smd->domain->tex_flame_coba) {
GPU_texture_free(smd->domain->tex_flame_coba);
}
smd->domain->tex_flame_coba = NULL;
if (smd->domain->tex_coba)
if (smd->domain->tex_coba) {
GPU_texture_free(smd->domain->tex_coba);
}
smd->domain->tex_coba = NULL;
if (smd->domain->tex_field)
if (smd->domain->tex_field) {
GPU_texture_free(smd->domain->tex_field);
}
smd->domain->tex_field = NULL;
}
}
@ -1143,14 +1180,17 @@ void GPU_create_smoke_velocity(SmokeModifierData *smd)
void GPU_free_smoke_velocity(SmokeModifierData *smd)
{
if (smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain) {
if (smd->domain->tex_velocity_x)
if (smd->domain->tex_velocity_x) {
GPU_texture_free(smd->domain->tex_velocity_x);
}
if (smd->domain->tex_velocity_y)
if (smd->domain->tex_velocity_y) {
GPU_texture_free(smd->domain->tex_velocity_y);
}
if (smd->domain->tex_velocity_z)
if (smd->domain->tex_velocity_z) {
GPU_texture_free(smd->domain->tex_velocity_z);
}
smd->domain->tex_velocity_x = NULL;
smd->domain->tex_velocity_y = NULL;
@ -1169,8 +1209,9 @@ static void gpu_queue_image_for_free(Image *ima)
void GPU_free_unused_buffers(Main *bmain)
{
if (!BLI_thread_is_main())
if (!BLI_thread_is_main()) {
return;
}
BLI_thread_lock(LOCK_OPENGL);
@ -1179,8 +1220,9 @@ void GPU_free_unused_buffers(Main *bmain)
Image *ima = node->link;
/* check in case it was freed in the meantime */
if (bmain && BLI_findindex(&bmain->images, ima) != -1)
if (bmain && BLI_findindex(&bmain->images, ima) != -1) {
GPU_free_image(ima);
}
}
BLI_linklist_free(image_free_queue, NULL);
@ -1242,12 +1284,14 @@ void GPU_free_images_old(Main *bmain)
* Run garbage collector once for every collecting period of time
* if textimeout is 0, that's the option to NOT run the collector
*/
if (U.textimeout == 0 || ctime % U.texcollectrate || ctime == lasttime)
if (U.textimeout == 0 || ctime % U.texcollectrate || ctime == lasttime) {
return;
}
/* of course not! */
if (G.is_rendering)
if (G.is_rendering) {
return;
}
lasttime = ctime;
@ -1280,8 +1324,9 @@ static void gpu_disable_multisample(void)
int samples = 0;
glGetIntegerv(GL_SAMPLES, &samples);
if (samples == 0)
if (samples == 0) {
toggle_ok = false;
}
}
if (toggle_ok) {

View File

@ -180,12 +180,15 @@ static uint index_range(const uint values[], uint value_len, uint *min_out, uint
uint max_value = values[0];
for (uint i = 1; i < value_len; ++i) {
const uint value = values[i];
if (value == GPU_PRIM_RESTART)
if (value == GPU_PRIM_RESTART) {
continue;
else if (value < min_value)
}
else if (value < min_value) {
min_value = value;
else if (value > max_value)
}
else if (value > max_value) {
max_value = value;
}
}
*min_out = min_value;
*max_out = max_value;

View File

@ -232,10 +232,12 @@ void gpu_extensions_init(void)
glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &GG.maxtexlayers);
glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &GG.maxcubemapsize);
if (GLEW_EXT_texture_filter_anisotropic)
if (GLEW_EXT_texture_filter_anisotropic) {
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &GG.max_anisotropy);
else
}
else {
GG.max_anisotropy = 1.0f;
}
glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_BLOCKS, &GG.maxubobinds);
glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &GG.maxubosize);

View File

@ -112,10 +112,12 @@ static GLenum convert_buffer_bits_to_gl(eGPUFrameBufferBits bits)
static GPUTexture *framebuffer_get_depth_tex(GPUFrameBuffer *fb)
{
if (fb->attachments[GPU_FB_DEPTH_ATTACHMENT].tex)
if (fb->attachments[GPU_FB_DEPTH_ATTACHMENT].tex) {
return fb->attachments[GPU_FB_DEPTH_ATTACHMENT].tex;
else
}
else {
return fb->attachments[GPU_FB_DEPTH_STENCIL_ATTACHMENT].tex;
}
}
static GPUTexture *framebuffer_get_color_tex(GPUFrameBuffer *fb, int slot)
@ -409,10 +411,12 @@ static void gpu_framebuffer_update_attachments(GPUFrameBuffer *fb)
/* Update draw buffers (color targets)
* This state is saved in the FBO */
if (numslots)
if (numslots) {
glDrawBuffers(numslots, gl_attachments);
else
}
else {
glDrawBuffer(GL_NONE);
}
}
/**
@ -497,11 +501,13 @@ static GPUFrameBuffer *gpuPopFrameBuffer(void)
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
{
if (fb->object == 0)
if (fb->object == 0) {
gpu_framebuffer_init(fb);
}
if (GPU_framebuffer_active_get() != fb)
if (GPU_framebuffer_active_get() != fb) {
glBindFramebuffer(GL_FRAMEBUFFER, fb->object);
}
gpu_framebuffer_current_set(fb);
@ -523,8 +529,9 @@ void GPU_framebuffer_bind(GPUFrameBuffer *fb)
}
#endif
if (fb->multisample)
if (fb->multisample) {
glEnable(GL_MULTISAMPLE);
}
glViewport(0, 0, fb->width, fb->height);
}
@ -544,8 +551,9 @@ bool GPU_framebuffer_bound(GPUFrameBuffer *fb)
bool GPU_framebuffer_check_valid(GPUFrameBuffer *fb, char err_out[256])
{
if (!GPU_framebuffer_bound(fb))
if (!GPU_framebuffer_bound(fb)) {
GPU_framebuffer_bind(fb);
}
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
@ -768,8 +776,9 @@ void GPU_framebuffer_recursive_downsample(GPUFrameBuffer *fb,
glViewport(0, 0, current_dim[0], current_dim[1]);
callback(userData, i);
if (current_dim[0] == 1 && current_dim[1] == 1)
if (current_dim[0] == 1 && current_dim[1] == 1) {
break;
}
}
for (GPUAttachmentType type = 0; type < GPU_FB_MAX_ATTACHEMENT; ++type) {
@ -844,12 +853,15 @@ GPUOffScreen *GPU_offscreen_create(
void GPU_offscreen_free(GPUOffScreen *ofs)
{
if (ofs->fb)
if (ofs->fb) {
GPU_framebuffer_free(ofs->fb);
if (ofs->color)
}
if (ofs->color) {
GPU_texture_free(ofs->color);
if (ofs->depth)
}
if (ofs->depth) {
GPU_texture_free(ofs->depth);
}
MEM_freeN(ofs);
}

View File

@ -141,8 +141,9 @@ void immBindProgram(GLuint program, const GPUShaderInterface *shaderface)
imm.bound_program = program;
imm.shader_interface = shaderface;
if (!imm.vertex_format.packed)
if (!imm.vertex_format.packed) {
VertexFormat_pack(&imm.vertex_format);
}
glUseProgram(program);
get_attr_locations(&imm.vertex_format, &imm.attr_binding, shaderface);

View File

@ -42,8 +42,9 @@ static bool initialized = false;
void GPU_init(void)
{
/* can't avoid calling this multiple times, see wm_window_ghostwindow_add */
if (initialized)
if (initialized) {
return;
}
initialized = true;
@ -52,8 +53,9 @@ void GPU_init(void)
gpu_codegen_init();
gpu_framebuffer_module_init();
if (G.debug & G_DEBUG_GPU)
if (G.debug & G_DEBUG_GPU) {
gpu_debug_init();
}
gpu_batch_init();
@ -72,8 +74,9 @@ void GPU_exit(void)
gpu_batch_exit();
if (G.debug & G_DEBUG_GPU)
if (G.debug & G_DEBUG_GPU) {
gpu_debug_exit();
}
gpu_framebuffer_module_exit();
gpu_codegen_exit();

View File

@ -163,8 +163,9 @@ GPUTexture **gpu_material_ramp_texture_row_set(GPUMaterial *mat,
static void gpu_material_ramp_texture_build(GPUMaterial *mat)
{
if (mat->coba_builder == NULL)
if (mat->coba_builder == NULL) {
return;
}
GPUColorBandBuilder *builder = mat->coba_builder;
@ -523,8 +524,9 @@ struct GPUUniformBuffer *GPU_material_sss_profile_get(GPUMaterial *material,
int sample_len,
GPUTexture **tex_profile)
{
if (!material->sss_enabled)
if (!material->sss_enabled) {
return NULL;
}
if (material->sss_dirty || (material->sss_samples != sample_len)) {
GPUSssKernelData kd;
@ -577,8 +579,9 @@ void GPU_material_vertex_attrs(GPUMaterial *material, GPUVertAttrLayers *r_attrs
void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link)
{
if (!material->outlink)
if (!material->outlink) {
material->outlink = link;
}
}
void gpu_material_add_node(GPUMaterial *material, GPUNode *node)
@ -596,8 +599,9 @@ eGPUMaterialStatus GPU_material_status(GPUMaterial *mat)
bool GPU_material_do_color_management(GPUMaterial *mat)
{
if (!BKE_scene_check_color_management_enabled(mat->scene))
if (!BKE_scene_check_color_management_enabled(mat->scene)) {
return false;
}
return true;
}
@ -768,11 +772,13 @@ void GPU_materials_free(Main *bmain)
World *wo;
extern Material defmaterial;
for (ma = bmain->materials.first; ma; ma = ma->id.next)
for (ma = bmain->materials.first; ma; ma = ma->id.next) {
GPU_material_free(&ma->gpumaterial);
}
for (wo = bmain->worlds.first; wo; wo = wo->id.next)
for (wo = bmain->worlds.first; wo; wo = wo->id.next) {
GPU_material_free(&wo->gpumaterial);
}
GPU_material_free(&defmaterial.gpumaterial);
}

View File

@ -110,8 +110,9 @@ void GPU_select_begin(uint *buffer, uint bufsize, const rcti *input, char mode,
bool GPU_select_load_id(uint id)
{
/* if no selection mode active, ignore */
if (!g_select_state.select_is_active)
if (!g_select_state.select_is_active) {
return true;
}
switch (g_select_state.algorithm) {
case ALGO_GL_QUERY: {

View File

@ -266,20 +266,26 @@ static void gpu_shader_standard_extensions(char defines[MAX_EXT_DEFINE_LENGTH])
static void gpu_shader_standard_defines(char defines[MAX_DEFINE_LENGTH])
{
/* some useful defines to detect GPU type */
if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY))
if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY)) {
strcat(defines, "#define GPU_ATI\n");
else if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_ANY))
}
else if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_ANY)) {
strcat(defines, "#define GPU_NVIDIA\n");
else if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_ANY, GPU_DRIVER_ANY))
}
else if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_ANY, GPU_DRIVER_ANY)) {
strcat(defines, "#define GPU_INTEL\n");
}
/* some useful defines to detect OS type */
if (GPU_type_matches(GPU_DEVICE_ANY, GPU_OS_WIN, GPU_DRIVER_ANY))
if (GPU_type_matches(GPU_DEVICE_ANY, GPU_OS_WIN, GPU_DRIVER_ANY)) {
strcat(defines, "#define OS_WIN\n");
else if (GPU_type_matches(GPU_DEVICE_ANY, GPU_OS_MAC, GPU_DRIVER_ANY))
}
else if (GPU_type_matches(GPU_DEVICE_ANY, GPU_OS_MAC, GPU_DRIVER_ANY)) {
strcat(defines, "#define OS_MAC\n");
else if (GPU_type_matches(GPU_DEVICE_ANY, GPU_OS_UNIX, GPU_DRIVER_ANY))
}
else if (GPU_type_matches(GPU_DEVICE_ANY, GPU_OS_UNIX, GPU_DRIVER_ANY)) {
strcat(defines, "#define OS_UNIX\n");
}
return;
}
@ -371,12 +377,15 @@ GPUShader *GPU_shader_create_ex(const char *vertexcode,
/* At least a vertex shader and a fragment shader are required. */
BLI_assert((fragcode != NULL) && (vertexcode != NULL));
if (vertexcode)
if (vertexcode) {
shader->vertex = glCreateShader(GL_VERTEX_SHADER);
if (fragcode)
}
if (fragcode) {
shader->fragment = glCreateShader(GL_FRAGMENT_SHADER);
if (geocode)
}
if (geocode) {
shader->geometry = glCreateShader(GL_GEOMETRY_SHADER);
}
shader->program = glCreateProgram();
@ -400,8 +409,9 @@ GPUShader *GPU_shader_create_ex(const char *vertexcode,
source[num_source++] = standard_extensions;
source[num_source++] = standard_defines;
if (defines)
if (defines) {
source[num_source++] = defines;
}
source[num_source++] = vertexcode;
gpu_dump_shaders(source, num_source, DEBUG_SHADER_VERTEX);
@ -430,10 +440,12 @@ GPUShader *GPU_shader_create_ex(const char *vertexcode,
source[num_source++] = standard_extensions;
source[num_source++] = standard_defines;
if (defines)
if (defines) {
source[num_source++] = defines;
if (libcode)
}
if (libcode) {
source[num_source++] = libcode;
}
source[num_source++] = fragcode;
gpu_dump_shaders(source, num_source, DEBUG_SHADER_FRAGMENT);
@ -462,8 +474,9 @@ GPUShader *GPU_shader_create_ex(const char *vertexcode,
source[num_source++] = standard_extensions;
source[num_source++] = standard_defines;
if (defines)
if (defines) {
source[num_source++] = defines;
}
source[num_source++] = geocode;
gpu_dump_shaders(source, num_source, DEBUG_SHADER_GEOMETRY);
@ -495,14 +508,18 @@ GPUShader *GPU_shader_create_ex(const char *vertexcode,
if (!status) {
glGetProgramInfoLog(shader->program, sizeof(log), &length, log);
/* print attached shaders in pipeline order */
if (vertexcode)
if (vertexcode) {
shader_print_errors("linking", log, &vertexcode, 1);
if (geocode)
}
if (geocode) {
shader_print_errors("linking", log, &geocode, 1);
if (libcode)
}
if (libcode) {
shader_print_errors("linking", log, &libcode, 1);
if (fragcode)
}
if (fragcode) {
shader_print_errors("linking", log, &fragcode, 1);
}
GPU_shader_free(shader);
return NULL;
@ -637,17 +654,22 @@ void GPU_shader_free(GPUShader *shader)
#endif
BLI_assert(shader);
if (shader->vertex)
if (shader->vertex) {
glDeleteShader(shader->vertex);
if (shader->geometry)
}
if (shader->geometry) {
glDeleteShader(shader->geometry);
if (shader->fragment)
}
if (shader->fragment) {
glDeleteShader(shader->fragment);
if (shader->program)
}
if (shader->program) {
glDeleteProgram(shader->program);
}
if (shader->interface)
if (shader->interface) {
GPU_shaderinterface_discard(shader->interface);
}
MEM_freeN(shader);
}
@ -693,8 +715,9 @@ int GPU_shader_get_program(GPUShader *shader)
void GPU_shader_uniform_float(GPUShader *UNUSED(shader), int location, float value)
{
if (location == -1)
if (location == -1) {
return;
}
glUniform1f(location, value);
}
@ -702,43 +725,56 @@ void GPU_shader_uniform_float(GPUShader *UNUSED(shader), int location, float val
void GPU_shader_uniform_vector(
GPUShader *UNUSED(shader), int location, int length, int arraysize, const float *value)
{
if (location == -1 || value == NULL)
if (location == -1 || value == NULL) {
return;
}
if (length == 1)
if (length == 1) {
glUniform1fv(location, arraysize, value);
else if (length == 2)
}
else if (length == 2) {
glUniform2fv(location, arraysize, value);
else if (length == 3)
}
else if (length == 3) {
glUniform3fv(location, arraysize, value);
else if (length == 4)
}
else if (length == 4) {
glUniform4fv(location, arraysize, value);
else if (length == 9)
}
else if (length == 9) {
glUniformMatrix3fv(location, arraysize, 0, value);
else if (length == 16)
}
else if (length == 16) {
glUniformMatrix4fv(location, arraysize, 0, value);
}
}
void GPU_shader_uniform_vector_int(
GPUShader *UNUSED(shader), int location, int length, int arraysize, const int *value)
{
if (location == -1)
if (location == -1) {
return;
}
if (length == 1)
if (length == 1) {
glUniform1iv(location, arraysize, value);
else if (length == 2)
}
else if (length == 2) {
glUniform2iv(location, arraysize, value);
else if (length == 3)
}
else if (length == 3) {
glUniform3iv(location, arraysize, value);
else if (length == 4)
}
else if (length == 4) {
glUniform4iv(location, arraysize, value);
}
}
void GPU_shader_uniform_int(GPUShader *UNUSED(shader), int location, int value)
{
if (location == -1)
if (location == -1) {
return;
}
glUniform1i(location, value);
}
@ -764,8 +800,9 @@ void GPU_shader_uniform_texture(GPUShader *UNUSED(shader), int location, GPUText
return;
}
if (location == -1)
if (location == -1) {
return;
}
glUniform1i(location, number);
}

View File

@ -490,8 +490,9 @@ static float *GPU_texture_rescale_3d(
nfpixels[offset * 4 + 2] = fpixels[offset_orig * 4 + 2];
nfpixels[offset * 4 + 3] = fpixels[offset_orig * 4 + 3];
}
else
else {
nfpixels[offset] = fpixels[offset_orig];
}
}
}
}
@ -511,32 +512,37 @@ static bool gpu_texture_check_capacity(
* So manually check the maximum size and maximum number of layers. */
switch (proxy) {
case GL_PROXY_TEXTURE_2D_ARRAY:
if ((tex->d < 0) || (tex->d > GPU_max_texture_layers()))
if ((tex->d < 0) || (tex->d > GPU_max_texture_layers())) {
return false;
}
break;
case GL_PROXY_TEXTURE_1D_ARRAY:
if ((tex->h < 0) || (tex->h > GPU_max_texture_layers()))
if ((tex->h < 0) || (tex->h > GPU_max_texture_layers())) {
return false;
}
break;
}
switch (proxy) {
case GL_PROXY_TEXTURE_3D:
if ((tex->d < 0) || (tex->d > GPU_max_texture_size()))
if ((tex->d < 0) || (tex->d > GPU_max_texture_size())) {
return false;
}
ATTR_FALLTHROUGH;
case GL_PROXY_TEXTURE_2D:
case GL_PROXY_TEXTURE_2D_ARRAY:
if ((tex->h < 0) || (tex->h > GPU_max_texture_size()))
if ((tex->h < 0) || (tex->h > GPU_max_texture_size())) {
return false;
}
ATTR_FALLTHROUGH;
case GL_PROXY_TEXTURE_1D:
case GL_PROXY_TEXTURE_1D_ARRAY:
if ((tex->w < 0) || (tex->w > GPU_max_texture_size()))
if ((tex->w < 0) || (tex->w > GPU_max_texture_size())) {
return false;
}
ATTR_FALLTHROUGH;
}
@ -592,12 +598,15 @@ static bool gpu_texture_try_alloc(GPUTexture *tex,
tex->d /= 2;
/* really unlikely to happen but keep this just in case */
if (tex->w == 0)
if (tex->w == 0) {
break;
if (tex->h == 0 && proxy != GL_PROXY_TEXTURE_1D)
}
if (tex->h == 0 && proxy != GL_PROXY_TEXTURE_1D) {
break;
if (tex->d == 0 && proxy == GL_PROXY_TEXTURE_3D)
}
if (tex->d == 0 && proxy == GL_PROXY_TEXTURE_3D) {
break;
}
ret = gpu_texture_check_capacity(tex, proxy, internalformat, data_format, data_type);
} while (ret == false);
@ -654,16 +663,20 @@ GPUTexture *GPU_texture_create_nD(int w,
tex->format_flag = 0;
if (n == 2) {
if (d == 0)
if (d == 0) {
tex->target_base = tex->target = GL_TEXTURE_2D;
else
}
else {
tex->target_base = tex->target = GL_TEXTURE_2D_ARRAY;
}
}
else if (n == 1) {
if (h == 0)
if (h == 0) {
tex->target_base = tex->target = GL_TEXTURE_1D;
else
}
else {
tex->target_base = tex->target = GL_TEXTURE_1D_ARRAY;
}
}
else if (n == 3) {
tex->target_base = tex->target = GL_TEXTURE_3D;
@ -676,8 +689,9 @@ GPUTexture *GPU_texture_create_nD(int w,
gpu_validate_data_format(tex_format, gpu_data_format);
if (samples && n == 2 && d == 0)
if (samples && n == 2 && d == 0) {
tex->target = GL_TEXTURE_2D_MULTISAMPLE;
}
GLenum internalformat = gpu_get_gl_internalformat(tex_format);
GLenum data_format = gpu_get_gl_dataformat(tex_format, &tex->format_flag);
@ -703,14 +717,17 @@ GPUTexture *GPU_texture_create_nD(int w,
GLenum proxy = GL_PROXY_TEXTURE_2D;
if (n == 2) {
if (d > 1)
if (d > 1) {
proxy = GL_PROXY_TEXTURE_2D_ARRAY;
}
}
else if (n == 1) {
if (h == 0)
if (h == 0) {
proxy = GL_PROXY_TEXTURE_1D;
else
}
else {
proxy = GL_PROXY_TEXTURE_1D_ARRAY;
}
}
else if (n == 3) {
proxy = GL_PROXY_TEXTURE_3D;
@ -761,8 +778,9 @@ GPUTexture *GPU_texture_create_nD(int w,
tex->target == GL_TEXTURE_1D_ARRAY) {
if (samples) {
glTexImage2DMultisample(tex->target, samples, internalformat, tex->w, tex->h, true);
if (pix)
if (pix) {
glTexSubImage2D(tex->target, 0, 0, 0, tex->w, tex->h, data_format, data_type, pix);
}
}
else {
glTexImage2D(tex->target, 0, internalformat, tex->w, tex->h, 0, data_format, data_type, pix);
@ -776,8 +794,9 @@ GPUTexture *GPU_texture_create_nD(int w,
tex->target, 0, internalformat, tex->w, tex->h, tex->d, 0, data_format, data_type, pix);
}
if (rescaled_pixels)
if (rescaled_pixels) {
MEM_freeN(rescaled_pixels);
}
/* Texture Parameters */
if (GPU_texture_stencil(tex) || /* Does not support filtering */
@ -1029,10 +1048,12 @@ GPUTexture *GPU_texture_from_bindcode(int textarget, int bindcode)
GLenum gettarget;
if (textarget == GL_TEXTURE_2D)
if (textarget == GL_TEXTURE_2D) {
gettarget = GL_TEXTURE_2D;
else
}
else {
gettarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X;
}
glBindTexture(textarget, tex->bindcode);
glGetTexLevelParameteriv(gettarget, 0, GL_TEXTURE_WIDTH, &w);
@ -1050,8 +1071,9 @@ GPUTexture *GPU_texture_from_preview(PreviewImage *prv, int mipmap)
GPUTexture *tex = prv->gputexture[0];
GLuint bindcode = 0;
if (tex)
if (tex) {
bindcode = tex->bindcode;
}
/* this binds a texture, so that's why we restore it to 0 */
if (bindcode == 0) {
@ -1524,12 +1546,15 @@ void GPU_invalid_tex_bind(int mode)
void GPU_invalid_tex_free(void)
{
if (GG.invalid_tex_1D)
if (GG.invalid_tex_1D) {
GPU_texture_free(GG.invalid_tex_1D);
if (GG.invalid_tex_2D)
}
if (GG.invalid_tex_2D) {
GPU_texture_free(GG.invalid_tex_2D);
if (GG.invalid_tex_3D)
}
if (GG.invalid_tex_3D) {
GPU_texture_free(GG.invalid_tex_3D);
}
}
void GPU_texture_bind(GPUTexture *tex, int number)
@ -1555,18 +1580,21 @@ void GPU_texture_bind(GPUTexture *tex, int number)
glActiveTexture(GL_TEXTURE0 + number);
if (tex->bindcode != 0)
if (tex->bindcode != 0) {
glBindTexture(tex->target, tex->bindcode);
else
}
else {
GPU_invalid_tex_bind(tex->target_base);
}
tex->number = number;
}
void GPU_texture_unbind(GPUTexture *tex)
{
if (tex->number == -1)
if (tex->number == -1) {
return;
}
glActiveTexture(GL_TEXTURE0 + tex->number);
glBindTexture(tex->target, 0);
@ -1617,8 +1645,9 @@ void GPU_texture_compare_mode(GPUTexture *tex, bool use_compare)
WARN_NOT_BOUND(tex);
/* Could become an assertion ? (fclem) */
if (!GPU_texture_depth(tex))
if (!GPU_texture_depth(tex)) {
return;
}
GLenum mode = (use_compare) ? GL_COMPARE_REF_TO_TEXTURE : GL_NONE;
@ -1665,10 +1694,12 @@ void GPU_texture_wrap_mode(GPUTexture *tex, bool use_repeat)
glActiveTexture(GL_TEXTURE0 + tex->number);
glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_S, repeat);
if (tex->target_base != GL_TEXTURE_1D)
if (tex->target_base != GL_TEXTURE_1D) {
glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_T, repeat);
if (tex->target_base == GL_TEXTURE_3D)
}
if (tex->target_base == GL_TEXTURE_3D) {
glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_R, repeat);
}
}
static GLenum gpu_get_gl_filterfunction(eGPUFilterFunction filter)
@ -1703,8 +1734,9 @@ void GPU_texture_free(GPUTexture *tex)
{
tex->refcount--;
if (tex->refcount < 0)
if (tex->refcount < 0) {
fprintf(stderr, "GPUTexture: negative refcount\n");
}
if (tex->refcount == 0) {
for (int i = 0; i < GPU_TEX_MAX_FBO_ATTACHED; ++i) {
@ -1713,8 +1745,9 @@ void GPU_texture_free(GPUTexture *tex)
}
}
if (tex->bindcode)
if (tex->bindcode) {
GPU_tex_free(tex->bindcode);
}
gpu_texture_memory_footprint_remove(tex);

View File

@ -500,8 +500,9 @@ void GPU_viewport_draw_to_screen(GPUViewport *viewport, const rcti *rect)
{
DefaultFramebufferList *dfbl = viewport->fbl;
if (dfbl->default_fb == NULL)
if (dfbl->default_fb == NULL) {
return;
}
DefaultTextureList *dtxl = viewport->txl;