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:
authorDalai Felinto <dalai@blender.org>2020-04-03 20:15:01 +0300
committerDalai Felinto <dalai@blender.org>2020-04-03 20:27:46 +0300
commitd138cbfb47e379edc1ee915a8c6ff65b01f000d6 (patch)
treef4773ecce897c32eaf75295dd5f6a8e730d471ed /source/blender/gpu
parentb0c1184875d39abac4a65a5d20e263ea6d841009 (diff)
Code Quality: Replace for loops with LISTBASE_FOREACH
Note this only changes cases where the variable was declared inside the for loop. To handle it outside as well is a different challenge. Differential Revision: https://developer.blender.org/D7320
Diffstat (limited to 'source/blender/gpu')
-rw-r--r--source/blender/gpu/intern/gpu_batch_presets.c2
-rw-r--r--source/blender/gpu/intern/gpu_codegen.c20
-rw-r--r--source/blender/gpu/intern/gpu_material.c4
-rw-r--r--source/blender/gpu/intern/gpu_node_graph.c4
-rw-r--r--source/blender/gpu/intern/gpu_select_pick.c3
-rw-r--r--source/blender/gpu/intern/gpu_uniformbuffer.c6
-rw-r--r--source/blender/gpu/intern/gpu_viewport.c4
7 files changed, 21 insertions, 22 deletions
diff --git a/source/blender/gpu/intern/gpu_batch_presets.c b/source/blender/gpu/intern/gpu_batch_presets.c
index e00b6f78c2e..e322b9fb9b8 100644
--- a/source/blender/gpu/intern/gpu_batch_presets.c
+++ b/source/blender/gpu/intern/gpu_batch_presets.c
@@ -241,7 +241,7 @@ void gpu_batch_presets_reset(void)
BLI_mutex_lock(&g_presets_3d.mutex);
/* Reset vao caches for these every time we switch opengl context.
* This way they will draw correctly for each window. */
- for (LinkData *link = presets_list.first; link; link = link->next) {
+ LISTBASE_FOREACH (LinkData *, link, &presets_list) {
GPUBatch *preset = link->data;
GPU_batch_vao_cache_clear(preset);
}
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index f279ab2c86c..8a46e24d459 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -75,7 +75,7 @@ static uint32_t gpu_pass_hash(const char *frag_gen, const char *defs, ListBase *
BLI_HashMurmur2A hm2a;
BLI_hash_mm2a_init(&hm2a, 0);
BLI_hash_mm2a_add(&hm2a, (uchar *)frag_gen, strlen(frag_gen));
- for (GPUMaterialAttribute *attr = attributes->first; attr; attr = attr->next) {
+ LISTBASE_FOREACH (GPUMaterialAttribute *, attr, attributes) {
BLI_hash_mm2a_add(&hm2a, (uchar *)attr->name, strlen(attr->name));
}
if (defs) {
@@ -314,12 +314,12 @@ static int codegen_process_uniforms_functions(GPUMaterial *material,
ListBase ubo_inputs = {NULL, NULL};
/* Attributes */
- for (GPUMaterialAttribute *attr = graph->attributes.first; attr; attr = attr->next) {
+ LISTBASE_FOREACH (GPUMaterialAttribute *, attr, &graph->attributes) {
BLI_dynstr_appendf(ds, "in %s var%d;\n", gpu_data_type_to_string(attr->gputype), attr->id);
}
/* Textures */
- for (GPUMaterialTexture *tex = graph->textures.first; tex; tex = tex->next) {
+ LISTBASE_FOREACH (GPUMaterialTexture *, tex, &graph->textures) {
if (tex->colorband) {
BLI_dynstr_appendf(ds, "uniform sampler1DArray %s;\n", tex->sampler_name);
}
@@ -333,7 +333,7 @@ static int codegen_process_uniforms_functions(GPUMaterial *material,
}
/* Volume Grids */
- for (GPUMaterialVolumeGrid *grid = graph->volume_grids.first; grid; grid = grid->next) {
+ LISTBASE_FOREACH (GPUMaterialVolumeGrid *, grid, &graph->volume_grids) {
BLI_dynstr_appendf(ds, "uniform sampler3D %s;\n", grid->sampler_name);
BLI_dynstr_appendf(ds, "uniform mat4 %s = mat4(0.0);\n", grid->transform_name);
}
@@ -381,7 +381,7 @@ static int codegen_process_uniforms_functions(GPUMaterial *material,
/* Inputs are sorted */
BLI_dynstr_appendf(ds, "\nlayout (std140) uniform %s {\n", GPU_UBO_BLOCK_NAME);
- for (LinkData *link = ubo_inputs.first; link; link = link->next) {
+ LISTBASE_FOREACH (LinkData *, link, &ubo_inputs) {
input = link->data;
BLI_dynstr_appendf(ds, "\t%s unf%d;\n", gpu_data_type_to_string(input->type), input->id);
}
@@ -673,7 +673,7 @@ static char *code_generate_vertex(GPUNodeGraph *graph, const char *vert_code, bo
"#define DEFINE_ATTR(type, attr) in type attr\n"
"#endif\n");
- for (GPUMaterialAttribute *attr = graph->attributes.first; attr; attr = attr->next) {
+ LISTBASE_FOREACH (GPUMaterialAttribute *, attr, &graph->attributes) {
/* XXX FIXME : see notes in mesh_render_data_create() */
/* NOTE : Replicate changes to mesh_render_data_create() in draw_cache_impl_mesh.c */
if (attr->type == CD_ORCO) {
@@ -787,7 +787,7 @@ static char *code_generate_vertex(GPUNodeGraph *graph, const char *vert_code, bo
BLI_dynstr_append(ds, "\tbarycentricPosg = position;\n");
}
- for (GPUMaterialAttribute *attr = graph->attributes.first; attr; attr = attr->next) {
+ LISTBASE_FOREACH (GPUMaterialAttribute *, attr, &graph->attributes) {
if (attr->type == CD_TANGENT) {
/* Not supported by hairs */
BLI_dynstr_appendf(ds, "\tvar%d%s = vec4(0.0);\n", attr->id, use_geom ? "g" : "");
@@ -820,7 +820,7 @@ static char *code_generate_vertex(GPUNodeGraph *graph, const char *vert_code, bo
BLI_dynstr_append(ds, "\tbarycentricPosg = (ModelMatrix * vec4(position, 1.0)).xyz;\n");
}
- for (GPUMaterialAttribute *attr = graph->attributes.first; attr; attr = attr->next) {
+ LISTBASE_FOREACH (GPUMaterialAttribute *, attr, &graph->attributes) {
if (attr->type == CD_TANGENT) { /* silly exception */
BLI_dynstr_appendf(ds,
"\tvar%d%s.xyz = transpose(mat3(ModelMatrixInverse)) * att%d.xyz;\n",
@@ -903,7 +903,7 @@ static char *code_generate_geometry(GPUNodeGraph *graph,
}
}
- for (GPUMaterialAttribute *attr = graph->attributes.first; attr; attr = attr->next) {
+ LISTBASE_FOREACH (GPUMaterialAttribute *, attr, &graph->attributes) {
BLI_dynstr_appendf(ds, "in %s var%dg[];\n", gpu_data_type_to_string(attr->gputype), attr->id);
BLI_dynstr_appendf(ds, "out %s var%d;\n", gpu_data_type_to_string(attr->gputype), attr->id);
}
@@ -1010,7 +1010,7 @@ static char *code_generate_geometry(GPUNodeGraph *graph,
BLI_dynstr_append(ds, "#endif\n");
}
- for (GPUMaterialAttribute *attr = graph->attributes.first; attr; attr = attr->next) {
+ LISTBASE_FOREACH (GPUMaterialAttribute *, attr, &graph->attributes) {
/* TODO let shader choose what to do depending on what the attribute is. */
BLI_dynstr_appendf(ds, "\tvar%d = var%dg[vert];\n", attr->id, attr->id);
}
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c
index 3e73d156440..97e4c880644 100644
--- a/source/blender/gpu/intern/gpu_material.c
+++ b/source/blender/gpu/intern/gpu_material.c
@@ -191,7 +191,7 @@ static void gpu_material_free_single(GPUMaterial *material)
void GPU_material_free(ListBase *gpumaterial)
{
- for (LinkData *link = gpumaterial->first; link; link = link->next) {
+ LISTBASE_FOREACH (LinkData *, link, gpumaterial) {
GPUMaterial *material = link->data;
gpu_material_free_single(material);
MEM_freeN(material);
@@ -628,7 +628,7 @@ GPUMaterial *GPU_material_from_nodetree_find(ListBase *gpumaterials,
const void *engine_type,
int options)
{
- for (LinkData *link = gpumaterials->first; link; link = link->next) {
+ LISTBASE_FOREACH (LinkData *, link, gpumaterials) {
GPUMaterial *current_material = (GPUMaterial *)link->data;
if (current_material->engine_type == engine_type && current_material->options == options) {
return current_material;
diff --git a/source/blender/gpu/intern/gpu_node_graph.c b/source/blender/gpu/intern/gpu_node_graph.c
index 953b2eb40d8..876a6bef670 100644
--- a/source/blender/gpu/intern/gpu_node_graph.c
+++ b/source/blender/gpu/intern/gpu_node_graph.c
@@ -645,7 +645,7 @@ void gpu_node_graph_free(GPUNodeGraph *graph)
{
gpu_node_graph_free_nodes(graph);
- for (GPUMaterialVolumeGrid *grid = graph->volume_grids.first; grid; grid = grid->next) {
+ LISTBASE_FOREACH (GPUMaterialVolumeGrid *, grid, &graph->volume_grids) {
MEM_SAFE_FREE(grid->name);
}
BLI_freelistN(&graph->volume_grids);
@@ -679,7 +679,7 @@ static void gpu_nodes_tag(GPUNodeLink *link)
void gpu_node_graph_prune_unused(GPUNodeGraph *graph)
{
- for (GPUNode *node = graph->nodes.first; node; node = node->next) {
+ LISTBASE_FOREACH (GPUNode *, node, &graph->nodes) {
node->tag = false;
}
diff --git a/source/blender/gpu/intern/gpu_select_pick.c b/source/blender/gpu/intern/gpu_select_pick.c
index 56fe1e40d87..674ca06d109 100644
--- a/source/blender/gpu/intern/gpu_select_pick.c
+++ b/source/blender/gpu/intern/gpu_select_pick.c
@@ -731,8 +731,7 @@ void gpu_select_pick_cache_load_id(void)
#ifdef DEBUG_PRINT
printf("%s (building depth from cache)\n", __func__);
#endif
- for (DepthBufCache *rect_depth = ps->cache.bufs.first; rect_depth;
- rect_depth = rect_depth->next) {
+ LISTBASE_FOREACH (DepthBufCache *, rect_depth, &ps->cache.bufs) {
if (rect_depth->next != NULL) {
/* we know the buffers differ, but this sub-region may not.
* double check before adding an id-pass */
diff --git a/source/blender/gpu/intern/gpu_uniformbuffer.c b/source/blender/gpu/intern/gpu_uniformbuffer.c
index 943793956d1..130e8fe7da1 100644
--- a/source/blender/gpu/intern/gpu_uniformbuffer.c
+++ b/source/blender/gpu/intern/gpu_uniformbuffer.c
@@ -147,7 +147,7 @@ GPUUniformBuffer *GPU_uniformbuffer_dynamic_create(ListBase *inputs, char err_ou
/* Make sure we comply to the ubo alignment requirements. */
gpu_uniformbuffer_inputs_sort(inputs);
- for (LinkData *link = inputs->first; link; link = link->next) {
+ LISTBASE_FOREACH (LinkData *, link, inputs) {
const eGPUType gputype = get_padded_gpu_type(link);
ubo->buffer.size += gputype * sizeof(float);
}
@@ -160,7 +160,7 @@ GPUUniformBuffer *GPU_uniformbuffer_dynamic_create(ListBase *inputs, char err_ou
/* Now that we know the total ubo size we can start populating it. */
float *offset = ubo->data;
- for (LinkData *link = inputs->first; link; link = link->next) {
+ LISTBASE_FOREACH (LinkData *, link, inputs) {
GPUInput *input = link->data;
memcpy(offset, input->vec, input->type * sizeof(float));
offset += get_padded_gpu_type(link);
@@ -272,7 +272,7 @@ static void gpu_uniformbuffer_inputs_sort(ListBase *inputs)
LinkData *inputs_lookup[MAX_UBO_GPU_TYPE + 1] = {NULL};
eGPUType cur_type = MAX_UBO_GPU_TYPE + 1;
- for (LinkData *link = inputs->first; link; link = link->next) {
+ LISTBASE_FOREACH (LinkData *, link, inputs) {
GPUInput *input = link->data;
if (input->type == GPU_MAT3) {
diff --git a/source/blender/gpu/intern/gpu_viewport.c b/source/blender/gpu/intern/gpu_viewport.c
index 57efaf99b8b..b2e1cb17946 100644
--- a/source/blender/gpu/intern/gpu_viewport.c
+++ b/source/blender/gpu/intern/gpu_viewport.c
@@ -355,7 +355,7 @@ GPUTexture *GPU_viewport_texture_pool_query(
{
GPUTexture *tex;
- for (ViewportTempTexture *tmp_tex = viewport->tex_pool.first; tmp_tex; tmp_tex = tmp_tex->next) {
+ LISTBASE_FOREACH (ViewportTempTexture *, tmp_tex, &viewport->tex_pool) {
if ((GPU_texture_format(tmp_tex->texture) == format) &&
(GPU_texture_width(tmp_tex->texture) == width) &&
(GPU_texture_height(tmp_tex->texture) == height)) {
@@ -412,7 +412,7 @@ static void gpu_viewport_texture_pool_clear_users(GPUViewport *viewport)
static void gpu_viewport_texture_pool_free(GPUViewport *viewport)
{
- for (ViewportTempTexture *tmp_tex = viewport->tex_pool.first; tmp_tex; tmp_tex = tmp_tex->next) {
+ LISTBASE_FOREACH (ViewportTempTexture *, tmp_tex, &viewport->tex_pool) {
GPU_texture_free(tmp_tex->texture);
}