Cleanup: GPU, Clang-Tidy else-after-return fixes

This addresses warnings from Clang-Tidy's `readability-else-after-return`
rule in the `source/blender/gpu` module.

No functional changes.
This commit is contained in:
2020-08-07 12:39:35 +02:00
parent 326e137a8c
commit c889d93c80
16 changed files with 153 additions and 178 deletions

View File

@@ -129,12 +129,11 @@ GPUBatch *GPU_batch_preset_sphere(int lod)
if (lod == 0) {
return g_presets_3d.batch.sphere_low;
}
else if (lod == 1) {
if (lod == 1) {
return g_presets_3d.batch.sphere_med;
}
else {
return g_presets_3d.batch.sphere_high;
}
return g_presets_3d.batch.sphere_high;
}
GPUBatch *GPU_batch_preset_sphere_wire(int lod)
@@ -145,9 +144,8 @@ GPUBatch *GPU_batch_preset_sphere_wire(int lod)
if (lod == 0) {
return g_presets_3d.batch.sphere_wire_low;
}
else {
return g_presets_3d.batch.sphere_wire_med;
}
return g_presets_3d.batch.sphere_wire_med;
}
/** \} */

View File

@@ -1083,9 +1083,8 @@ GPUBatch *GPU_pbvh_buffers_batch_get(GPU_PBVH_Buffers *buffers, bool fast, bool
if (wires) {
return (fast && buffers->lines_fast) ? buffers->lines_fast : buffers->lines;
}
else {
return (fast && buffers->triangles_fast) ? buffers->triangles_fast : buffers->triangles;
}
return (fast && buffers->triangles_fast) ? buffers->triangles_fast : buffers->triangles;
}
bool GPU_pbvh_buffers_has_overlays(GPU_PBVH_Buffers *buffers)

View File

@@ -220,63 +220,61 @@ static const char *gpu_builtin_name(eGPUBuiltin builtin)
if (builtin == GPU_VIEW_MATRIX) {
return "unfviewmat";
}
else if (builtin == GPU_OBJECT_MATRIX) {
if (builtin == GPU_OBJECT_MATRIX) {
return "unfobmat";
}
else if (builtin == GPU_INVERSE_VIEW_MATRIX) {
if (builtin == GPU_INVERSE_VIEW_MATRIX) {
return "unfinvviewmat";
}
else if (builtin == GPU_INVERSE_OBJECT_MATRIX) {
if (builtin == GPU_INVERSE_OBJECT_MATRIX) {
return "unfinvobmat";
}
else if (builtin == GPU_LOC_TO_VIEW_MATRIX) {
if (builtin == GPU_LOC_TO_VIEW_MATRIX) {
return "unflocaltoviewmat";
}
else if (builtin == GPU_INVERSE_LOC_TO_VIEW_MATRIX) {
if (builtin == GPU_INVERSE_LOC_TO_VIEW_MATRIX) {
return "unfinvlocaltoviewmat";
}
else if (builtin == GPU_VIEW_POSITION) {
if (builtin == GPU_VIEW_POSITION) {
return "varposition";
}
else if (builtin == GPU_WORLD_NORMAL) {
if (builtin == GPU_WORLD_NORMAL) {
return "varwnormal";
}
else if (builtin == GPU_VIEW_NORMAL) {
if (builtin == GPU_VIEW_NORMAL) {
return "varnormal";
}
else if (builtin == GPU_OBJECT_COLOR) {
if (builtin == GPU_OBJECT_COLOR) {
return "unfobjectcolor";
}
else if (builtin == GPU_AUTO_BUMPSCALE) {
if (builtin == GPU_AUTO_BUMPSCALE) {
return "unfobautobumpscale";
}
else if (builtin == GPU_CAMERA_TEXCO_FACTORS) {
if (builtin == GPU_CAMERA_TEXCO_FACTORS) {
return "unfcameratexfactors";
}
else if (builtin == GPU_PARTICLE_SCALAR_PROPS) {
if (builtin == GPU_PARTICLE_SCALAR_PROPS) {
return "unfparticlescalarprops";
}
else if (builtin == GPU_PARTICLE_LOCATION) {
if (builtin == GPU_PARTICLE_LOCATION) {
return "unfparticleco";
}
else if (builtin == GPU_PARTICLE_VELOCITY) {
if (builtin == GPU_PARTICLE_VELOCITY) {
return "unfparticlevel";
}
else if (builtin == GPU_PARTICLE_ANG_VELOCITY) {
if (builtin == GPU_PARTICLE_ANG_VELOCITY) {
return "unfparticleangvel";
}
else if (builtin == GPU_OBJECT_INFO) {
if (builtin == GPU_OBJECT_INFO) {
return "unfobjectinfo";
}
else if (builtin == GPU_BARYCENTRIC_TEXCO) {
if (builtin == GPU_BARYCENTRIC_TEXCO) {
return "unfbarycentrictex";
}
else if (builtin == GPU_BARYCENTRIC_DIST) {
if (builtin == GPU_BARYCENTRIC_DIST) {
return "unfbarycentricdist";
}
else {
return "";
}
return "";
}
static void codegen_set_unique_ids(GPUNodeGraph *graph)

View File

@@ -280,7 +280,7 @@ static uint index_range(const uint values[], uint value_len, uint *min_out, uint
if (value == RESTART_INDEX) {
continue;
}
else if (value < min_value) {
if (value < min_value) {
min_value = value;
}
else if (value > max_value) {
@@ -292,11 +292,10 @@ static uint index_range(const uint values[], uint value_len, uint *min_out, uint
*max_out = 0;
return 0;
}
else {
*min_out = min_value;
*max_out = max_value;
return max_value - min_value;
}
*min_out = min_value;
*max_out = max_value;
return max_value - min_value;
}
static void squeeze_indices_short(GPUIndexBufBuilder *builder,

View File

@@ -127,9 +127,8 @@ static GPUTexture *framebuffer_get_depth_tex(GPUFrameBuffer *fb)
if (fb->attachments[GPU_FB_DEPTH_ATTACHMENT].tex) {
return fb->attachments[GPU_FB_DEPTH_ATTACHMENT].tex;
}
else {
return fb->attachments[GPU_FB_DEPTH_STENCIL_ATTACHMENT].tex;
}
return fb->attachments[GPU_FB_DEPTH_STENCIL_ATTACHMENT].tex;
}
static GPUTexture *framebuffer_get_color_tex(GPUFrameBuffer *fb, int slot)
@@ -190,9 +189,8 @@ GPUFrameBuffer *GPU_framebuffer_active_get(void)
if (ctx) {
return gpu_context_active_framebuffer_get(ctx);
}
else {
return 0;
}
return 0;
}
static void gpu_framebuffer_current_set(GPUFrameBuffer *fb)
@@ -261,7 +259,7 @@ static void gpu_framebuffer_texture_attach_ex(
if ((attachment->tex == tex) && (attachment->mip == mip) && (attachment->layer == layer)) {
return; /* Exact same texture already bound here. */
}
else if (attachment->tex != NULL) {
if (attachment->tex != NULL) {
GPU_framebuffer_texture_detach(fb, attachment->tex);
}
@@ -414,7 +412,7 @@ static void gpu_framebuffer_update_attachments(GPUFrameBuffer *fb)
if (GPU_FB_ATTACHEMENT_IS_DIRTY(fb->dirty_flag, type) == false) {
continue;
}
else if (fb->attachments[type].tex != NULL) {
if (fb->attachments[type].tex != NULL) {
gpu_framebuffer_attachment_attach(&fb->attachments[type], type);
fb->multisample = (GPU_texture_samples(fb->attachments[type].tex) > 0);

View File

@@ -311,12 +311,11 @@ static float eval_profile(float r, short falloff_type, float sharpness, float pa
if (falloff_type == SHD_SUBSURFACE_BURLEY || falloff_type == SHD_SUBSURFACE_RANDOM_WALK) {
return burley_profile(r, param) / BURLEY_TRUNCATE_CDF;
}
else if (falloff_type == SHD_SUBSURFACE_CUBIC) {
if (falloff_type == SHD_SUBSURFACE_CUBIC) {
return cubic_profile(r, param, sharpness);
}
else {
return gaussian_profile(r, param);
}
return gaussian_profile(r, param);
}
/* Resolution for each sample of the precomputed kernel profile */

View File

@@ -678,14 +678,13 @@ char *gpu_str_skip_token(char *str, char *token, int max)
if (ELEM(*str, ' ', '(', ')', ',', ';', '\t', '\n', '\r')) {
break;
}
else {
if (token && len < max - 1) {
*token = *str;
token++;
len++;
}
str++;
if (token && len < max - 1) {
*token = *str;
token++;
len++;
}
str++;
}
if (token) {

View File

@@ -590,9 +590,8 @@ const float (*GPU_matrix_model_view_get(float m[4][4]))[4]
copy_m4_m4(m, ModelView);
return m;
}
else {
return ModelView;
}
return ModelView;
}
const float (*GPU_matrix_projection_get(float m[4][4]))[4]
@@ -601,9 +600,8 @@ const float (*GPU_matrix_projection_get(float m[4][4]))[4]
copy_m4_m4(m, Projection);
return m;
}
else {
return Projection;
}
return Projection;
}
const float (*GPU_matrix_model_view_projection_get(float m[4][4]))[4]

View File

@@ -204,12 +204,11 @@ static int depth_id_cmp(const void *v1, const void *v2)
if (d1->id < d2->id) {
return -1;
}
else if (d1->id > d2->id) {
if (d1->id > d2->id) {
return 1;
}
else {
return 0;
}
return 0;
}
static int depth_cmp(const void *v1, const void *v2)
@@ -218,12 +217,11 @@ static int depth_cmp(const void *v1, const void *v2)
if (d1->depth < d2->depth) {
return -1;
}
else if (d1->depth > d2->depth) {
if (d1->depth > d2->depth) {
return 1;
}
else {
return 0;
}
return 0;
}
/* depth sorting */

View File

@@ -147,9 +147,8 @@ bool gpu_select_query_load_id(uint id)
g_query_state.index++;
return true;
}
else {
return false;
}
return false;
}
}

View File

@@ -539,9 +539,8 @@ static const char *string_join_array_maybe_alloc(const char **str_arr, bool *r_i
if (is_alloc) {
return BLI_string_join_arrayN(str_arr, i);
}
else {
return str_arr[0];
}
return str_arr[0];
}
/**

View File

@@ -157,13 +157,12 @@ GPU_INLINE const GPUShaderInput *input_lookup(const GPUShaderInterface *shaderfa
}
return NULL; /* not found */
}
else {
/* This is a bit dangerous since we could have a hash collision.
* where the asked uniform that does not exist has the same hash
* as a real uniform. */
BLI_assert(match(name, shaderface->name_buffer + inputs[i].name_offset));
return inputs + i;
}
/* This is a bit dangerous since we could have a hash collision.
* where the asked uniform that does not exist has the same hash
* as a real uniform. */
BLI_assert(match(name, shaderface->name_buffer + inputs[i].name_offset));
return inputs + i;
}
}
return NULL; /* not found */

View File

@@ -312,31 +312,28 @@ static eGPUDataFormat gpu_get_data_format_from_tex_format(eGPUTextureFormat tex_
if (ELEM(tex_format, GPU_DEPTH_COMPONENT24, GPU_DEPTH_COMPONENT16, GPU_DEPTH_COMPONENT32F)) {
return GPU_DATA_FLOAT;
}
else if (ELEM(tex_format, GPU_DEPTH24_STENCIL8, GPU_DEPTH32F_STENCIL8)) {
if (ELEM(tex_format, GPU_DEPTH24_STENCIL8, GPU_DEPTH32F_STENCIL8)) {
return GPU_DATA_UNSIGNED_INT_24_8;
}
else {
/* Integer formats */
if (ELEM(tex_format, GPU_RG16I, GPU_R16I, GPU_RG16UI, GPU_R8UI, GPU_R16UI, GPU_R32UI)) {
if (ELEM(tex_format, GPU_R8UI, GPU_R16UI, GPU_RG16UI, GPU_R32UI)) {
return GPU_DATA_UNSIGNED_INT;
}
else {
return GPU_DATA_INT;
}
}
/* Byte formats */
else if (ELEM(tex_format, GPU_R8)) {
return GPU_DATA_UNSIGNED_BYTE;
}
/* Special case */
else if (ELEM(tex_format, GPU_R11F_G11F_B10F)) {
return GPU_DATA_10_11_11_REV;
}
else {
return GPU_DATA_FLOAT;
/* Integer formats */
if (ELEM(tex_format, GPU_RG16I, GPU_R16I, GPU_RG16UI, GPU_R8UI, GPU_R16UI, GPU_R32UI)) {
if (ELEM(tex_format, GPU_R8UI, GPU_R16UI, GPU_RG16UI, GPU_R32UI)) {
return GPU_DATA_UNSIGNED_INT;
}
return GPU_DATA_INT;
}
/* Byte formats */
if (ELEM(tex_format, GPU_R8)) {
return GPU_DATA_UNSIGNED_BYTE;
}
/* Special case */
if (ELEM(tex_format, GPU_R11F_G11F_B10F)) {
return GPU_DATA_10_11_11_REV;
}
return GPU_DATA_FLOAT;
}
/* Definitely not complete, edit according to the gl specification. */
@@ -347,51 +344,50 @@ static GLenum gpu_get_gl_dataformat(eGPUTextureFormat data_type,
*format_flag |= GPU_FORMAT_DEPTH;
return GL_DEPTH_COMPONENT;
}
else if (ELEM(data_type, GPU_DEPTH24_STENCIL8, GPU_DEPTH32F_STENCIL8)) {
if (ELEM(data_type, GPU_DEPTH24_STENCIL8, GPU_DEPTH32F_STENCIL8)) {
*format_flag |= GPU_FORMAT_DEPTH | GPU_FORMAT_STENCIL;
return GL_DEPTH_STENCIL;
}
/* Integer formats */
if (ELEM(data_type, GPU_R8UI, GPU_RG16I, GPU_R16I, GPU_RG16UI, GPU_R16UI, GPU_R32UI)) {
*format_flag |= GPU_FORMAT_INTEGER;
switch (gpu_get_component_count(data_type)) {
case 1:
return GL_RED_INTEGER;
break;
case 2:
return GL_RG_INTEGER;
break;
case 3:
return GL_RGB_INTEGER;
break;
case 4:
return GL_RGBA_INTEGER;
break;
}
}
else if (ELEM(data_type, GPU_R8)) {
*format_flag |= GPU_FORMAT_FLOAT;
return GL_RED;
}
else {
/* Integer formats */
if (ELEM(data_type, GPU_R8UI, GPU_RG16I, GPU_R16I, GPU_RG16UI, GPU_R16UI, GPU_R32UI)) {
*format_flag |= GPU_FORMAT_INTEGER;
*format_flag |= GPU_FORMAT_FLOAT;
switch (gpu_get_component_count(data_type)) {
case 1:
return GL_RED_INTEGER;
break;
case 2:
return GL_RG_INTEGER;
break;
case 3:
return GL_RGB_INTEGER;
break;
case 4:
return GL_RGBA_INTEGER;
break;
}
}
else if (ELEM(data_type, GPU_R8)) {
*format_flag |= GPU_FORMAT_FLOAT;
return GL_RED;
}
else {
*format_flag |= GPU_FORMAT_FLOAT;
switch (gpu_get_component_count(data_type)) {
case 1:
return GL_RED;
break;
case 2:
return GL_RG;
break;
case 3:
return GL_RGB;
break;
case 4:
return GL_RGBA;
break;
}
switch (gpu_get_component_count(data_type)) {
case 1:
return GL_RED;
break;
case 2:
return GL_RG;
break;
case 3:
return GL_RGB;
break;
case 4:
return GL_RGBA;
break;
}
}
@@ -667,31 +663,30 @@ static bool gpu_texture_check_capacity(
return true;
}
else {
switch (proxy) {
case GL_PROXY_TEXTURE_1D:
glTexImage1D(proxy, 0, internalformat, tex->w, 0, data_format, data_type, NULL);
break;
case GL_PROXY_TEXTURE_1D_ARRAY:
case GL_PROXY_TEXTURE_2D:
case GL_PROXY_TEXTURE_CUBE_MAP:
glTexImage2D(proxy, 0, internalformat, tex->w, tex->h, 0, data_format, data_type, NULL);
break;
case GL_PROXY_TEXTURE_2D_ARRAY:
case GL_PROXY_TEXTURE_3D:
glTexImage3D(
proxy, 0, internalformat, tex->w, tex->h, tex->d, 0, data_format, data_type, NULL);
break;
case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB:
glTexImage3D(
proxy, 0, internalformat, tex->w, tex->h, tex->d * 6, 0, data_format, data_type, NULL);
break;
}
int width = 0;
glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &width);
return (width > 0);
switch (proxy) {
case GL_PROXY_TEXTURE_1D:
glTexImage1D(proxy, 0, internalformat, tex->w, 0, data_format, data_type, NULL);
break;
case GL_PROXY_TEXTURE_1D_ARRAY:
case GL_PROXY_TEXTURE_2D:
case GL_PROXY_TEXTURE_CUBE_MAP:
glTexImage2D(proxy, 0, internalformat, tex->w, tex->h, 0, data_format, data_type, NULL);
break;
case GL_PROXY_TEXTURE_2D_ARRAY:
case GL_PROXY_TEXTURE_3D:
glTexImage3D(
proxy, 0, internalformat, tex->w, tex->h, tex->d, 0, data_format, data_type, NULL);
break;
case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB:
glTexImage3D(
proxy, 0, internalformat, tex->w, tex->h, tex->d * 6, 0, data_format, data_type, NULL);
break;
}
int width = 0;
glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &width);
return (width > 0);
}
/* This tries to allocate video memory for a given texture

View File

@@ -132,7 +132,7 @@ static void gpu_uniformbuffer_inputs_sort(ListBase *inputs)
BLI_assert(!"mat3 not supported in UBO");
continue;
}
else if (input->type > MAX_UBO_GPU_TYPE) {
if (input->type > MAX_UBO_GPU_TYPE) {
BLI_assert(!"GPU type not supported in UBO");
continue;
}
@@ -140,10 +140,9 @@ static void gpu_uniformbuffer_inputs_sort(ListBase *inputs)
if (input->type == cur_type) {
continue;
}
else {
inputs_lookup[input->type] = link;
cur_type = input->type;
}
inputs_lookup[input->type] = link;
cur_type = input->type;
}
/* If there is no GPU_VEC3 there is no need for alignment. */

View File

@@ -114,9 +114,8 @@ static uint attr_align(const GPUVertAttr *a)
if (a->comp_len == 3 && c <= 2) {
return 4 * c; /* AMD HW can't fetch these well, so pad it out (other vendors too?) */
}
else {
return c; /* most fetches are ok if components are naturally aligned */
}
return c; /* most fetches are ok if components are naturally aligned */
}
uint vertex_buffer_size(const GPUVertFormat *format, uint vertex_len)

View File

@@ -912,9 +912,8 @@ GPUTexture *GPU_viewport_color_texture(GPUViewport *viewport, int view)
if (viewport->active_view == view) {
return dtxl->color;
}
else {
return dtxl->color_stereo;
}
return dtxl->color_stereo;
}
return NULL;