From f68cfd6bb078482c4a779a6e26a56e2734edb5b8 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 25 Sep 2022 18:33:28 +1000 Subject: Cleanup: replace C-style casts with functional casts for numeric types --- source/blender/gpu/intern/gpu_codegen.cc | 2 +- source/blender/gpu/intern/gpu_index_buffer.cc | 2 +- source/blender/gpu/intern/gpu_matrix.cc | 6 ++--- source/blender/gpu/intern/gpu_shader_log.cc | 6 ++--- source/blender/gpu/intern/gpu_state.cc | 30 ++++++++++++------------ source/blender/gpu/opengl/gl_context.cc | 8 +++---- source/blender/gpu/opengl/gl_framebuffer.cc | 4 ++-- source/blender/gpu/opengl/gl_shader.cc | 2 +- source/blender/gpu/opengl/gl_shader_interface.cc | 4 ++-- source/blender/gpu/opengl/gl_vertex_array.cc | 4 ++-- 10 files changed, 34 insertions(+), 34 deletions(-) (limited to 'source/blender/gpu') diff --git a/source/blender/gpu/intern/gpu_codegen.cc b/source/blender/gpu/intern/gpu_codegen.cc index fdd0fe97a02..51644bc9307 100644 --- a/source/blender/gpu/intern/gpu_codegen.cc +++ b/source/blender/gpu/intern/gpu_codegen.cc @@ -874,7 +874,7 @@ void GPU_pass_cache_garbage_collect(void) { static int lasttime = 0; const int shadercollectrate = 60; /* hardcoded for now. */ - int ctime = (int)PIL_check_seconds_timer(); + int ctime = int(PIL_check_seconds_timer()); if (ctime < shadercollectrate + lasttime) { return; diff --git a/source/blender/gpu/intern/gpu_index_buffer.cc b/source/blender/gpu/intern/gpu_index_buffer.cc index 3a66f547403..42f4e048131 100644 --- a/source/blender/gpu/intern/gpu_index_buffer.cc +++ b/source/blender/gpu/intern/gpu_index_buffer.cc @@ -76,7 +76,7 @@ void GPU_indexbuf_init(GPUIndexBufBuilder *builder, #if TRUST_NO_ONE assert(verts_per_prim != -1); #endif - GPU_indexbuf_init_ex(builder, prim_type, prim_len * (uint)verts_per_prim, vertex_len); + GPU_indexbuf_init_ex(builder, prim_type, prim_len * uint(verts_per_prim), vertex_len); } GPUIndexBuf *GPU_indexbuf_build_on_device(uint index_len) diff --git a/source/blender/gpu/intern/gpu_matrix.cc b/source/blender/gpu/intern/gpu_matrix.cc index 94fd44f832b..12bbe13a296 100644 --- a/source/blender/gpu/intern/gpu_matrix.cc +++ b/source/blender/gpu/intern/gpu_matrix.cc @@ -429,7 +429,7 @@ void GPU_matrix_frustum_set( void GPU_matrix_perspective_set(float fovy, float aspect, float near, float far) { - float half_height = tanf(fovy * (float)(M_PI / 360.0)) * near; + float half_height = tanf(fovy * float(M_PI / 360.0)) * near; float half_width = half_height * aspect; GPU_matrix_frustum_set(-half_width, +half_width, -half_height, +half_height, near, far); } @@ -669,13 +669,13 @@ BLI_STATIC_ASSERT(GPU_PY_MATRIX_STACK_LEN + 1 == MATRIX_STACK_DEPTH, "define mis int GPU_matrix_stack_level_get_model_view() { GPUMatrixState *state = Context::get()->matrix_state; - return (int)state->model_view_stack.top; + return int(state->model_view_stack.top); } int GPU_matrix_stack_level_get_projection() { GPUMatrixState *state = Context::get()->matrix_state; - return (int)state->projection_stack.top; + return int(state->projection_stack.top); } /** \} */ diff --git a/source/blender/gpu/intern/gpu_shader_log.cc b/source/blender/gpu/intern/gpu_shader_log.cc index dbc36c5afd0..e593c4fa508 100644 --- a/source/blender/gpu/intern/gpu_shader_log.cc +++ b/source/blender/gpu/intern/gpu_shader_log.cc @@ -93,10 +93,10 @@ void Shader::print_log(Span sources, } /* Silence not useful lines. */ - StringRef logref = StringRefNull(log_line).substr(0, (size_t)line_end - (size_t)log_line); + StringRef logref = StringRefNull(log_line).substr(0, size_t(line_end) - size_t(log_line)); if (logref.endswith(" shader failed to compile with the following errors:") || logref.endswith(" No code generated")) { - log_line += (size_t)line_end - (size_t)log_line; + log_line += size_t(line_end) - size_t(log_line); continue; } @@ -291,7 +291,7 @@ bool GPULogParser::at_any(const char *log_line, const StringRef chars) const int GPULogParser::parse_number(const char *log_line, char **r_new_position) const { - return (int)strtol(log_line, r_new_position, 10); + return int(strtol(log_line, r_new_position, 10)); } /** \} */ diff --git a/source/blender/gpu/intern/gpu_state.cc b/source/blender/gpu/intern/gpu_state.cc index a1e0b8867a0..8e9d5cb3184 100644 --- a/source/blender/gpu/intern/gpu_state.cc +++ b/source/blender/gpu/intern/gpu_state.cc @@ -97,10 +97,10 @@ void GPU_color_mask(bool r, bool g, bool b, bool a) StateManager *stack = Context::get()->state_manager; auto &state = stack->state; uint32_t write_mask = state.write_mask; - SET_FLAG_FROM_TEST(write_mask, r, (uint32_t)GPU_WRITE_RED); - SET_FLAG_FROM_TEST(write_mask, g, (uint32_t)GPU_WRITE_GREEN); - SET_FLAG_FROM_TEST(write_mask, b, (uint32_t)GPU_WRITE_BLUE); - SET_FLAG_FROM_TEST(write_mask, a, (uint32_t)GPU_WRITE_ALPHA); + SET_FLAG_FROM_TEST(write_mask, r, uint32_t(GPU_WRITE_RED)); + SET_FLAG_FROM_TEST(write_mask, g, uint32_t(GPU_WRITE_GREEN)); + SET_FLAG_FROM_TEST(write_mask, b, uint32_t(GPU_WRITE_BLUE)); + SET_FLAG_FROM_TEST(write_mask, a, uint32_t(GPU_WRITE_ALPHA)); state.write_mask = write_mask; } @@ -109,7 +109,7 @@ void GPU_depth_mask(bool depth) StateManager *stack = Context::get()->state_manager; auto &state = stack->state; uint32_t write_mask = state.write_mask; - SET_FLAG_FROM_TEST(write_mask, depth, (uint32_t)GPU_WRITE_DEPTH); + SET_FLAG_FROM_TEST(write_mask, depth, uint32_t(GPU_WRITE_DEPTH)); state.write_mask = write_mask; } @@ -133,13 +133,13 @@ void GPU_state_set(eGPUWriteMask write_mask, { StateManager *stack = Context::get()->state_manager; auto &state = stack->state; - state.write_mask = (uint32_t)write_mask; - state.blend = (uint32_t)blend; - state.culling_test = (uint32_t)culling_test; - state.depth_test = (uint32_t)depth_test; - state.stencil_test = (uint32_t)stencil_test; - state.stencil_op = (uint32_t)stencil_op; - state.provoking_vert = (uint32_t)provoking_vert; + state.write_mask = uint32_t(write_mask); + state.blend = uint32_t(blend); + state.culling_test = uint32_t(culling_test); + state.depth_test = uint32_t(depth_test); + state.stencil_test = uint32_t(stencil_test); + state.stencil_op = uint32_t(stencil_op); + state.provoking_vert = uint32_t(provoking_vert); } /** \} */ @@ -196,17 +196,17 @@ void GPU_viewport(int x, int y, int width, int height) void GPU_stencil_reference_set(uint reference) { - SET_MUTABLE_STATE(stencil_reference, (uint8_t)reference); + SET_MUTABLE_STATE(stencil_reference, uint8_t(reference)); } void GPU_stencil_write_mask_set(uint write_mask) { - SET_MUTABLE_STATE(stencil_write_mask, (uint8_t)write_mask); + SET_MUTABLE_STATE(stencil_write_mask, uint8_t(write_mask)); } void GPU_stencil_compare_mask_set(uint compare_mask) { - SET_MUTABLE_STATE(stencil_compare_mask, (uint8_t)compare_mask); + SET_MUTABLE_STATE(stencil_compare_mask, uint8_t(compare_mask)); } /** \} */ diff --git a/source/blender/gpu/opengl/gl_context.cc b/source/blender/gpu/opengl/gl_context.cc index 31bd7e0c4dd..375194c09f3 100644 --- a/source/blender/gpu/opengl/gl_context.cc +++ b/source/blender/gpu/opengl/gl_context.cc @@ -191,11 +191,11 @@ void GLSharedOrphanLists::orphans_clear() lists_mutex.lock(); if (!buffers.is_empty()) { - glDeleteBuffers((uint)buffers.size(), buffers.data()); + glDeleteBuffers(uint(buffers.size()), buffers.data()); buffers.clear(); } if (!textures.is_empty()) { - glDeleteTextures((uint)textures.size(), textures.data()); + glDeleteTextures(uint(textures.size()), textures.data()); textures.clear(); } lists_mutex.unlock(); @@ -208,11 +208,11 @@ void GLContext::orphans_clear() lists_mutex_.lock(); if (!orphaned_vertarrays_.is_empty()) { - glDeleteVertexArrays((uint)orphaned_vertarrays_.size(), orphaned_vertarrays_.data()); + glDeleteVertexArrays(uint(orphaned_vertarrays_.size()), orphaned_vertarrays_.data()); orphaned_vertarrays_.clear(); } if (!orphaned_framebuffers_.is_empty()) { - glDeleteFramebuffers((uint)orphaned_framebuffers_.size(), orphaned_framebuffers_.data()); + glDeleteFramebuffers(uint(orphaned_framebuffers_.size()), orphaned_framebuffers_.data()); orphaned_framebuffers_.clear(); } lists_mutex_.unlock(); diff --git a/source/blender/gpu/opengl/gl_framebuffer.cc b/source/blender/gpu/opengl/gl_framebuffer.cc index 1ab22a16df4..e94f5b66b97 100644 --- a/source/blender/gpu/opengl/gl_framebuffer.cc +++ b/source/blender/gpu/opengl/gl_framebuffer.cc @@ -352,7 +352,7 @@ void GLFrameBuffer::clear_attachment(GPUAttachmentType type, if (type == GPU_FB_DEPTH_STENCIL_ATTACHMENT) { BLI_assert(data_format == GPU_DATA_UINT_24_8); - float depth = ((*(uint32_t *)clear_value) & 0x00FFFFFFu) / (float)0x00FFFFFFu; + float depth = ((*(uint32_t *)clear_value) & 0x00FFFFFFu) / float(0x00FFFFFFu); int stencil = ((*(uint32_t *)clear_value) >> 24); glClearBufferfi(GL_DEPTH_STENCIL, 0, depth, stencil); } @@ -361,7 +361,7 @@ void GLFrameBuffer::clear_attachment(GPUAttachmentType type, glClearBufferfv(GL_DEPTH, 0, (GLfloat *)clear_value); } else if (data_format == GPU_DATA_UINT) { - float depth = *(uint32_t *)clear_value / (float)0xFFFFFFFFu; + float depth = *(uint32_t *)clear_value / float(0xFFFFFFFFu); glClearBufferfv(GL_DEPTH, 0, &depth); } else { diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc index 1f2ef36716e..a1570735723 100644 --- a/source/blender/gpu/opengl/gl_shader.cc +++ b/source/blender/gpu/opengl/gl_shader.cc @@ -1138,7 +1138,7 @@ void GLShader::uniform_int(int location, int comp_len, int array_size, const int int GLShader::program_handle_get() const { - return (int)this->shader_program_; + return int(this->shader_program_); } /** \} */ diff --git a/source/blender/gpu/opengl/gl_shader_interface.cc b/source/blender/gpu/opengl/gl_shader_interface.cc index b230706b020..c9432fca561 100644 --- a/source/blender/gpu/opengl/gl_shader_interface.cc +++ b/source/blender/gpu/opengl/gl_shader_interface.cc @@ -295,7 +295,7 @@ GLShaderInterface::GLShaderInterface(GLuint program) enabled_attr_mask_ |= (1 << input->location); /* Used in `GPU_shader_get_attribute_info`. */ - attr_types_[input->location] = (uint8_t)gpu_type_from_gl_type(type); + attr_types_[input->location] = uint8_t(gpu_type_from_gl_type(type)); } /* Uniform Blocks */ @@ -457,7 +457,7 @@ GLShaderInterface::GLShaderInterface(GLuint program, const shader::ShaderCreateI enabled_attr_mask_ |= (1 << input->location); /* Used in `GPU_shader_get_attribute_info`. */ - attr_types_[input->location] = (uint8_t)attr.type; + attr_types_[input->location] = uint8_t(attr.type); } input++; diff --git a/source/blender/gpu/opengl/gl_vertex_array.cc b/source/blender/gpu/opengl/gl_vertex_array.cc index 6897ac9f4a2..9a6df38cb05 100644 --- a/source/blender/gpu/opengl/gl_vertex_array.cc +++ b/source/blender/gpu/opengl/gl_vertex_array.cc @@ -47,7 +47,7 @@ static uint16_t vbo_bind(const ShaderInterface *interface, } /* This is in fact an offset in memory. */ - const GLvoid *pointer = (const GLubyte *)(intptr_t)(offset + v_first * stride); + const GLvoid *pointer = (const GLubyte *)intptr_t(offset + v_first * stride); const GLenum type = to_gl(static_cast(a->comp_type)); for (uint n_idx = 0; n_idx < a->name_len; n_idx++) { @@ -137,7 +137,7 @@ void GLVertArray::update_bindings(const GLuint vao, GLContext *ctx = GLContext::get(); /* This replaces glVertexAttrib4f(a, 0.0f, 0.0f, 0.0f, 1.0f); with a more modern style. * Fix issues for some drivers (see T75069). */ - glBindVertexBuffer(a, ctx->default_attr_vbo_, (intptr_t)0, (intptr_t)0); + glBindVertexBuffer(a, ctx->default_attr_vbo_, intptr_t(0), intptr_t(0)); glEnableVertexAttribArray(a); glVertexAttribFormat(a, 4, GL_FLOAT, GL_FALSE, 0); glVertexAttribBinding(a, a); -- cgit v1.2.3