diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2020-12-07 14:21:11 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2020-12-07 14:41:17 +0300 |
commit | 11c4066159e12ff630673c5fd94b37fb8c0f9102 (patch) | |
tree | 79c365fe59bf852478c561c1a7fd1679831a2be7 /source/blender/gpu/intern | |
parent | 2072134faadf4fd901c88ed7440e2289d61e0299 (diff) |
Cleanup: partial Clang-Tidy modernize-loop-convert
Modernize loops by using the `for(type variable : container)` syntax.
Some loops were trivial to fix, whereas others required more attention
to avoid semantic changes. I couldn't address all old-style loops, so
this commit doesn't enable the `modernize-loop-convert` rule.
Although Clang-Tidy's auto-fixer prefers to use `auto` for the loop
variable declaration, I made as many declarations as possible explicit.
To me this increases local readability, as you don't need to fully
understand the container in order to understand the loop variable type.
No functional changes.
Diffstat (limited to 'source/blender/gpu/intern')
-rw-r--r-- | source/blender/gpu/intern/gpu_batch.cc | 4 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_framebuffer.cc | 52 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_shader.cc | 6 |
3 files changed, 31 insertions, 31 deletions
diff --git a/source/blender/gpu/intern/gpu_batch.cc b/source/blender/gpu/intern/gpu_batch.cc index cdb158572b7..08b2e3c0f00 100644 --- a/source/blender/gpu/intern/gpu_batch.cc +++ b/source/blender/gpu/intern/gpu_batch.cc @@ -81,8 +81,8 @@ void GPU_batch_init_ex(GPUBatch *batch, for (int v = 1; v < GPU_BATCH_VBO_MAX_LEN; v++) { batch->verts[v] = nullptr; } - for (int v = 0; v < GPU_BATCH_INST_VBO_MAX_LEN; v++) { - batch->inst[v] = nullptr; + for (auto & v : batch->inst) { + v = nullptr; } batch->elem = elem; batch->prim_type = prim_type; diff --git a/source/blender/gpu/intern/gpu_framebuffer.cc b/source/blender/gpu/intern/gpu_framebuffer.cc index f11f1cea753..d5d7994a154 100644 --- a/source/blender/gpu/intern/gpu_framebuffer.cc +++ b/source/blender/gpu/intern/gpu_framebuffer.cc @@ -57,18 +57,18 @@ FrameBuffer::FrameBuffer(const char *name) dirty_attachments_ = true; dirty_state_ = true; - for (int i = 0; i < ARRAY_SIZE(attachments_); i++) { - attachments_[i].tex = nullptr; - attachments_[i].mip = -1; - attachments_[i].layer = -1; + for (GPUAttachment &attachment : attachments_) { + attachment.tex = nullptr; + attachment.mip = -1; + attachment.layer = -1; } } FrameBuffer::~FrameBuffer() { - for (int i = 0; i < ARRAY_SIZE(attachments_); i++) { - if (attachments_[i].tex != nullptr) { - reinterpret_cast<Texture *>(attachments_[i].tex)->detach_from(this); + for (GPUAttachment &attachment : attachments_) { + if (attachment.tex != nullptr) { + reinterpret_cast<Texture *>(attachment.tex)->detach_from(this); } } } @@ -148,8 +148,8 @@ void FrameBuffer::recursive_downsample(int max_lvl, for (int mip_lvl = 1; mip_lvl <= max_lvl; mip_lvl++) { /* Replace attached mip-level for each attachment. */ - for (int att = 0; att < ARRAY_SIZE(attachments_); att++) { - Texture *tex = reinterpret_cast<Texture *>(attachments_[att].tex); + for (GPUAttachment &attachment : attachments_) { + Texture *tex = reinterpret_cast<Texture *>(attachment.tex); if (tex != nullptr) { /* Some Intel HDXXX have issue with rendering to a mipmap that is below * the texture GL_TEXTURE_MAX_LEVEL. So even if it not correct, in this case @@ -158,7 +158,7 @@ void FrameBuffer::recursive_downsample(int max_lvl, /* Restrict fetches only to previous level. */ tex->mip_range_set(mip_lvl - 1, mip_max); /* Bind next level. */ - attachments_[att].mip = mip_lvl; + attachment.mip = mip_lvl; } } /* Update the internal attachments and viewport size. */ @@ -168,12 +168,12 @@ void FrameBuffer::recursive_downsample(int max_lvl, callback(userData, mip_lvl); } - for (int att = 0; att < ARRAY_SIZE(attachments_); att++) { - if (attachments_[att].tex != nullptr) { + for (GPUAttachment &attachment : attachments_) { + if (attachment.tex != nullptr) { /* Reset mipmap level range. */ - reinterpret_cast<Texture *>(attachments_[att].tex)->mip_range_set(0, max_lvl); + reinterpret_cast<Texture *>(attachment.tex)->mip_range_set(0, max_lvl); /* Reset base level. NOTE: might not be the one bound at the start of this function. */ - attachments_[att].mip = 0; + attachment.mip = 0; } } dirty_attachments_ = true; @@ -525,18 +525,18 @@ static GPUFrameBuffer *gpu_offscreen_fb_get(GPUOffScreen *ofs) Context *ctx = Context::get(); BLI_assert(ctx); - for (int i = 0; i < MAX_CTX_FB_LEN; i++) { - if (ofs->framebuffers[i].fb == nullptr) { - ofs->framebuffers[i].ctx = ctx; - GPU_framebuffer_ensure_config(&ofs->framebuffers[i].fb, + for (auto &framebuffer : ofs->framebuffers) { + if (framebuffer.fb == nullptr) { + framebuffer.ctx = ctx; + GPU_framebuffer_ensure_config(&framebuffer.fb, { GPU_ATTACHMENT_TEXTURE(ofs->depth), GPU_ATTACHMENT_TEXTURE(ofs->color), }); } - if (ofs->framebuffers[i].ctx == ctx) { - return ofs->framebuffers[i].fb; + if (framebuffer.ctx == ctx) { + return framebuffer.fb; } } @@ -550,9 +550,9 @@ static GPUFrameBuffer *gpu_offscreen_fb_get(GPUOffScreen *ofs) "Warning: GPUOffscreen used in more than 3 GPUContext. " "This may create performance drop.\n"); - for (int i = 0; i < MAX_CTX_FB_LEN; i++) { - GPU_framebuffer_free(ofs->framebuffers[i].fb); - ofs->framebuffers[i].fb = nullptr; + for (auto &framebuffer : ofs->framebuffers) { + GPU_framebuffer_free(framebuffer.fb); + framebuffer.fb = nullptr; } return gpu_offscreen_fb_get(ofs); @@ -595,9 +595,9 @@ GPUOffScreen *GPU_offscreen_create( void GPU_offscreen_free(GPUOffScreen *ofs) { - for (int i = 0; i < MAX_CTX_FB_LEN; i++) { - if (ofs->framebuffers[i].fb) { - GPU_framebuffer_free(ofs->framebuffers[i].fb); + for (auto &framebuffer : ofs->framebuffers) { + if (framebuffer.fb) { + GPU_framebuffer_free(framebuffer.fb); } } if (ofs->color) { diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc index 827ea06686f..d47ad5e0100 100644 --- a/source/blender/gpu/intern/gpu_shader.cc +++ b/source/blender/gpu/intern/gpu_shader.cc @@ -470,9 +470,9 @@ struct GPUShader *GPU_shader_create_from_arrays_impl( GPUShader *sh = GPU_shader_create( str_dst[0].str, str_dst[1].str, str_dst[2].str, nullptr, str_dst[3].str, name); - for (int i = 0; i < ARRAY_SIZE(str_dst); i++) { - if (str_dst[i].is_alloc) { - MEM_freeN((void *)str_dst[i].str); + for (auto &i : str_dst) { + if (i.is_alloc) { + MEM_freeN((void *)i.str); } } return sh; |