diff options
Diffstat (limited to 'source/blender/gpu')
43 files changed, 497 insertions, 263 deletions
diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h index 2f12625acac..67cd1a61aed 100644 --- a/source/blender/gpu/GPU_material.h +++ b/source/blender/gpu/GPU_material.h @@ -34,6 +34,7 @@ extern "C" { #endif +struct GHash; struct GPUMaterial; struct GPUNode; struct GPUNodeLink; @@ -143,6 +144,7 @@ typedef void (*GPUMaterialEvalCallbackFn)(GPUMaterial *mat, GPUNodeLink *GPU_constant(const float *num); GPUNodeLink *GPU_uniform(const float *num); GPUNodeLink *GPU_attribute(GPUMaterial *mat, CustomDataType type, const char *name); +GPUNodeLink *GPU_uniform_attribute(GPUMaterial *mat, const char *name, bool use_dupli); GPUNodeLink *GPU_image(GPUMaterial *mat, struct Image *ima, struct ImageUser *iuser, @@ -259,6 +261,31 @@ ListBase GPU_material_attributes(GPUMaterial *material); ListBase GPU_material_textures(GPUMaterial *material); ListBase GPU_material_volume_grids(GPUMaterial *material); +typedef struct GPUUniformAttr { + struct GPUUniformAttr *next, *prev; + + /* Meaningful part of the attribute set key. */ + char name[64]; /* MAX_CUSTOMDATA_LAYER_NAME */ + bool use_dupli; + + /* Helper fields used by code generation. */ + short id; + int users; +} GPUUniformAttr; + +typedef struct GPUUniformAttrList { + ListBase list; /* GPUUniformAttr */ + + /* List length and hash code precomputed for fast lookup and comparison. */ + unsigned int count, hash_code; +} GPUUniformAttrList; + +GPUUniformAttrList *GPU_material_uniform_attributes(GPUMaterial *material); + +struct GHash *GPU_uniform_attr_list_hash_new(const char *info); +void GPU_uniform_attr_list_copy(GPUUniformAttrList *dest, GPUUniformAttrList *src); +void GPU_uniform_attr_list_free(GPUUniformAttrList *set); + #ifdef __cplusplus } #endif diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h index 9aaa5d4cae8..27a7ea1e6a5 100644 --- a/source/blender/gpu/GPU_shader.h +++ b/source/blender/gpu/GPU_shader.h @@ -413,6 +413,9 @@ void GPU_shader_free_builtin_shaders(void); * This makes sure the GPUVertexFormat name buffer does not overflow. */ #define GPU_MAX_ATTR 15 +/* Determined by the maximum uniform buffer size divided by chunk size. */ +#define GPU_MAX_UNIFORM_ATTR 8 + #ifdef __cplusplus } #endif diff --git a/source/blender/gpu/GPU_uniform_buffer.h b/source/blender/gpu/GPU_uniform_buffer.h index ebcaa80e6f6..4efac0a8c00 100644 --- a/source/blender/gpu/GPU_uniform_buffer.h +++ b/source/blender/gpu/GPU_uniform_buffer.h @@ -53,6 +53,7 @@ void GPU_uniformbuf_unbind(GPUUniformBuf *ubo); void GPU_uniformbuf_unbind_all(void); #define GPU_UBO_BLOCK_NAME "nodeTree" +#define GPU_ATTRIBUTE_UBO_BLOCK_NAME "uniformAttrs" #ifdef __cplusplus } diff --git a/source/blender/gpu/GPU_viewport.h b/source/blender/gpu/GPU_viewport.h index 7b0d8c274d3..d8e4c5377b0 100644 --- a/source/blender/gpu/GPU_viewport.h +++ b/source/blender/gpu/GPU_viewport.h @@ -38,6 +38,7 @@ extern "C" { #define GPU_INFO_SIZE 512 /* IMA_MAX_RENDER_TEXT */ #define GLA_PIXEL_OFS 0.375f +typedef struct GHash GHash; typedef struct GPUViewport GPUViewport; struct GPUFrameBuffer; @@ -57,6 +58,7 @@ typedef struct ViewportMemoryPool { struct BLI_memblock *images; struct GPUUniformBuf **matrices_ubo; struct GPUUniformBuf **obinfos_ubo; + struct GHash *obattrs_ubo_pool; uint ubo_len; } ViewportMemoryPool; diff --git a/source/blender/gpu/intern/gpu_batch.cc b/source/blender/gpu/intern/gpu_batch.cc index 511ddd210af..3bf1233c000 100644 --- a/source/blender/gpu/intern/gpu_batch.cc +++ b/source/blender/gpu/intern/gpu_batch.cc @@ -73,21 +73,21 @@ void GPU_batch_init_ex(GPUBatch *batch, GPUIndexBuf *elem, eGPUBatchFlag owns_flag) { - BLI_assert(verts != NULL); + BLI_assert(verts != nullptr); /* Do not pass any other flag */ BLI_assert((owns_flag & ~(GPU_BATCH_OWNS_VBO | GPU_BATCH_OWNS_INDEX)) == 0); batch->verts[0] = verts; for (int v = 1; v < GPU_BATCH_VBO_MAX_LEN; v++) { - batch->verts[v] = NULL; + batch->verts[v] = nullptr; } for (int v = 0; v < GPU_BATCH_INST_VBO_MAX_LEN; v++) { - batch->inst[v] = NULL; + batch->inst[v] = nullptr; } batch->elem = elem; batch->prim_type = prim_type; batch->flag = owns_flag | GPU_BATCH_INIT | GPU_BATCH_DIRTY; - batch->shader = NULL; + batch->shader = nullptr; } /* This will share the VBOs with the new batch. */ @@ -171,7 +171,7 @@ int GPU_batch_instbuf_add_ex(GPUBatch *batch, GPUVertBuf *insts, bool own_vbo) batch->flag |= GPU_BATCH_DIRTY; for (uint v = 0; v < GPU_BATCH_INST_VBO_MAX_LEN; v++) { - if (batch->inst[v] == NULL) { + if (batch->inst[v] == nullptr) { /* for now all VertexBuffers must have same vertex_len */ if (batch->inst[0]) { /* Allow for different size of vertex buffer (will choose the smallest number of verts). */ @@ -195,9 +195,9 @@ int GPU_batch_vertbuf_add_ex(GPUBatch *batch, GPUVertBuf *verts, bool own_vbo) batch->flag |= GPU_BATCH_DIRTY; for (uint v = 0; v < GPU_BATCH_VBO_MAX_LEN; v++) { - if (batch->verts[v] == NULL) { + if (batch->verts[v] == nullptr) { /* for now all VertexBuffers must have same vertex_len */ - if (batch->verts[0] != NULL) { + if (batch->verts[0] != nullptr) { /* This is an issue for the HACK inside DRW_vbo_request(). */ // BLI_assert(verts->vertex_len == batch->verts[0]->vertex_len); } @@ -246,7 +246,7 @@ void GPU_batch_draw_range(GPUBatch *batch, int v_first, int v_count) /* Draw multiple instance of a batch without having any instance attributes. */ void GPU_batch_draw_instanced(GPUBatch *batch, int i_count) { - BLI_assert(batch->inst[0] == NULL); + BLI_assert(batch->inst[0] == nullptr); GPU_shader_bind(batch->shader); GPU_batch_draw_advanced(batch, 0, 0, 0, i_count); @@ -255,7 +255,7 @@ void GPU_batch_draw_instanced(GPUBatch *batch, int i_count) void GPU_batch_draw_advanced( GPUBatch *gpu_batch, int v_first, int v_count, int i_first, int i_count) { - BLI_assert(Context::get()->shader != NULL); + BLI_assert(Context::get()->shader != nullptr); Batch *batch = static_cast<Batch *>(gpu_batch); if (v_count == 0) { @@ -269,7 +269,7 @@ void GPU_batch_draw_advanced( if (i_count == 0) { i_count = (batch->inst[0]) ? batch->inst_(0)->vertex_len : 1; /* Meh. This is to be able to use different numbers of verts in instance vbos. */ - if (batch->inst[1] != NULL) { + if (batch->inst[1] != nullptr) { i_count = min_ii(i_count, batch->inst_(1)->vertex_len); } } diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index 2d76e793fc0..3ebe2edc89e 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -377,6 +377,19 @@ static int codegen_process_uniforms_functions(GPUMaterial *material, BLI_freelistN(&ubo_inputs); } + /* Generate the uniform attribute UBO if necessary. */ + if (!BLI_listbase_is_empty(&graph->uniform_attrs.list)) { + BLI_dynstr_append(ds, "\nstruct UniformAttributes {\n"); + LISTBASE_FOREACH (GPUUniformAttr *, attr, &graph->uniform_attrs.list) { + BLI_dynstr_appendf(ds, " vec4 attr%d;\n", attr->id); + } + BLI_dynstr_append(ds, "};\n"); + BLI_dynstr_appendf(ds, "layout (std140) uniform %s {\n", GPU_ATTRIBUTE_UBO_BLOCK_NAME); + BLI_dynstr_append(ds, " UniformAttributes uniform_attrs[DRW_RESOURCE_CHUNK_LEN];\n"); + BLI_dynstr_append(ds, "};\n"); + BLI_dynstr_append(ds, "#define GET_UNIFORM_ATTR(name) (uniform_attrs[resource_id].name)\n"); + } + BLI_dynstr_append(ds, "\n"); return builtins; @@ -478,7 +491,10 @@ static void codegen_call_functions(DynStr *ds, GPUNodeGraph *graph, GPUOutput *f BLI_dynstr_appendf(ds, "cons%d", input->id); } else if (input->source == GPU_SOURCE_ATTR) { - BLI_dynstr_appendf(ds, "var%d", input->attr->id); + codegen_convert_datatype(ds, input->attr->gputype, input->type, "var", input->attr->id); + } + else if (input->source == GPU_SOURCE_UNIFORM_ATTR) { + BLI_dynstr_appendf(ds, "GET_UNIFORM_ATTR(attr%d)", input->uniform_attr->id); } BLI_dynstr_append(ds, ", "); @@ -799,6 +815,7 @@ GPUPass *GPU_generate_pass(GPUMaterial *material, /* Prune the unused nodes and extract attributes before compiling so the * generated VBOs are ready to accept the future shader. */ gpu_node_graph_prune_unused(graph); + gpu_node_graph_finalize_uniform_attrs(graph); int builtins = 0; LISTBASE_FOREACH (GPUNode *, node, &graph->nodes) { @@ -914,7 +931,7 @@ static int count_active_texture_sampler(GPUShader *shader, char *source) /* Move past "uniform". */ code += 7; /* Skip sampler type suffix. */ - while (*code != ' ' && *code != '\0') { + while (!ELEM(*code, ' ', '\0')) { code++; } /* Skip following spaces. */ diff --git a/source/blender/gpu/intern/gpu_context.cc b/source/blender/gpu/intern/gpu_context.cc index 119c1ef9c55..a9d32dcf297 100644 --- a/source/blender/gpu/intern/gpu_context.cc +++ b/source/blender/gpu/intern/gpu_context.cc @@ -54,7 +54,7 @@ using namespace blender::gpu; -static thread_local Context *active_ctx = NULL; +static thread_local Context *active_ctx = nullptr; /* -------------------------------------------------------------------- */ /** \name gpu::Context methods @@ -80,12 +80,12 @@ Context::~Context() delete imm; } -bool Context::is_active_on_thread(void) +bool Context::is_active_on_thread() { return (this == active_ctx) && pthread_equal(pthread_self(), thread_); } -Context *Context::get(void) +Context *Context::get() { return active_ctx; } @@ -98,7 +98,7 @@ Context *Context::get(void) GPUContext *GPU_context_create(void *ghost_window) { - if (GPUBackend::get() == NULL) { + if (GPUBackend::get() == nullptr) { /* TODO move where it make sense. */ GPU_backend_init(GPU_BACKEND_OPENGL); } @@ -114,7 +114,7 @@ void GPU_context_discard(GPUContext *ctx_) { Context *ctx = unwrap(ctx_); delete ctx; - active_ctx = NULL; + active_ctx = nullptr; } /* ctx can be NULL */ @@ -166,7 +166,7 @@ static GPUBackend *g_backend; void GPU_backend_init(eGPUBackendType backend_type) { - BLI_assert(g_backend == NULL); + BLI_assert(g_backend == nullptr); switch (backend_type) { #if WITH_OPENGL_BACKEND @@ -185,10 +185,10 @@ void GPU_backend_exit(void) /* TODO assert no resource left. Currently UI textures are still not freed in their context * correctly. */ delete g_backend; - g_backend = NULL; + g_backend = nullptr; } -GPUBackend *GPUBackend::get(void) +GPUBackend *GPUBackend::get() { return g_backend; } diff --git a/source/blender/gpu/intern/gpu_framebuffer.cc b/source/blender/gpu/intern/gpu_framebuffer.cc index 8d9a1301be0..f11f1cea753 100644 --- a/source/blender/gpu/intern/gpu_framebuffer.cc +++ b/source/blender/gpu/intern/gpu_framebuffer.cc @@ -58,7 +58,7 @@ FrameBuffer::FrameBuffer(const char *name) dirty_state_ = true; for (int i = 0; i < ARRAY_SIZE(attachments_); i++) { - attachments_[i].tex = NULL; + attachments_[i].tex = nullptr; attachments_[i].mip = -1; attachments_[i].layer = -1; } @@ -67,7 +67,7 @@ FrameBuffer::FrameBuffer(const char *name) FrameBuffer::~FrameBuffer() { for (int i = 0; i < ARRAY_SIZE(attachments_); i++) { - if (attachments_[i].tex != NULL) { + if (attachments_[i].tex != nullptr) { reinterpret_cast<Texture *>(attachments_[i].tex)->detach_from(this); } } @@ -150,7 +150,7 @@ void FrameBuffer::recursive_downsample(int max_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); - if (tex != NULL) { + 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 * we allow GL_TEXTURE_MAX_LEVEL to be one level lower. In practice it does work! */ @@ -169,7 +169,7 @@ void FrameBuffer::recursive_downsample(int max_lvl, } for (int att = 0; att < ARRAY_SIZE(attachments_); att++) { - if (attachments_[att].tex != NULL) { + if (attachments_[att].tex != nullptr) { /* Reset mipmap level range. */ reinterpret_cast<Texture *>(attachments_[att].tex)->mip_range_set(0, max_lvl); /* Reset base level. NOTE: might not be the one bound at the start of this function. */ @@ -242,14 +242,14 @@ void GPU_framebuffer_restore(void) GPUFrameBuffer *GPU_framebuffer_active_get(void) { Context *ctx = Context::get(); - return wrap(ctx ? ctx->active_fb : NULL); + return wrap(ctx ? ctx->active_fb : nullptr); } /* Returns the default frame-buffer. Will always exists even if it's just a dummy. */ GPUFrameBuffer *GPU_framebuffer_back_get(void) { Context *ctx = Context::get(); - return wrap(ctx ? ctx->back_left : NULL); + return wrap(ctx ? ctx->back_left : nullptr); } bool GPU_framebuffer_bound(GPUFrameBuffer *gpu_fb) @@ -314,7 +314,7 @@ void GPU_framebuffer_config_array(GPUFrameBuffer *gpu_fb, if (depth_attachment.mip == -1) { /* GPU_ATTACHMENT_LEAVE */ } - else if (depth_attachment.tex == NULL) { + else if (depth_attachment.tex == nullptr) { /* GPU_ATTACHMENT_NONE: Need to clear both targets. */ fb->attachment_set(GPU_FB_DEPTH_STENCIL_ATTACHMENT, depth_attachment); fb->attachment_set(GPU_FB_DEPTH_ATTACHMENT, depth_attachment); @@ -487,7 +487,7 @@ void GPU_framebuffer_recursive_downsample(GPUFrameBuffer *gpu_fb, static struct { GPUFrameBuffer *framebuffers[FRAMEBUFFER_STACK_DEPTH]; uint top; -} FrameBufferStack = {{0}}; +} FrameBufferStack = {{nullptr}}; static void gpuPushFrameBuffer(GPUFrameBuffer *fb) { @@ -496,7 +496,7 @@ static void gpuPushFrameBuffer(GPUFrameBuffer *fb) FrameBufferStack.top++; } -static GPUFrameBuffer *gpuPopFrameBuffer(void) +static GPUFrameBuffer *gpuPopFrameBuffer() { BLI_assert(FrameBufferStack.top > 0); FrameBufferStack.top--; @@ -526,7 +526,7 @@ static GPUFrameBuffer *gpu_offscreen_fb_get(GPUOffScreen *ofs) BLI_assert(ctx); for (int i = 0; i < MAX_CTX_FB_LEN; i++) { - if (ofs->framebuffers[i].fb == NULL) { + if (ofs->framebuffers[i].fb == nullptr) { ofs->framebuffers[i].ctx = ctx; GPU_framebuffer_ensure_config(&ofs->framebuffers[i].fb, { @@ -552,7 +552,7 @@ static GPUFrameBuffer *gpu_offscreen_fb_get(GPUOffScreen *ofs) for (int i = 0; i < MAX_CTX_FB_LEN; i++) { GPU_framebuffer_free(ofs->framebuffers[i].fb); - ofs->framebuffers[i].fb = NULL; + ofs->framebuffers[i].fb = nullptr; } return gpu_offscreen_fb_get(ofs); @@ -569,16 +569,17 @@ GPUOffScreen *GPU_offscreen_create( width = max_ii(1, width); ofs->color = GPU_texture_create_2d( - "ofs_color", width, height, 1, (high_bitdepth) ? GPU_RGBA16F : GPU_RGBA8, NULL); + "ofs_color", width, height, 1, (high_bitdepth) ? GPU_RGBA16F : GPU_RGBA8, nullptr); if (depth) { - ofs->depth = GPU_texture_create_2d("ofs_depth", width, height, 1, GPU_DEPTH24_STENCIL8, NULL); + ofs->depth = GPU_texture_create_2d( + "ofs_depth", width, height, 1, GPU_DEPTH24_STENCIL8, nullptr); } if ((depth && !ofs->depth) || !ofs->color) { BLI_snprintf(err_out, 256, "GPUTexture: Texture allocation failed."); GPU_offscreen_free(ofs); - return NULL; + return nullptr; } GPUFrameBuffer *fb = gpu_offscreen_fb_get(ofs); @@ -586,7 +587,7 @@ GPUOffScreen *GPU_offscreen_create( /* check validity at the very end! */ if (!GPU_framebuffer_check_valid(fb, err_out)) { GPU_offscreen_free(ofs); - return NULL; + return nullptr; } GPU_framebuffer_restore(); return ofs; @@ -620,7 +621,7 @@ void GPU_offscreen_bind(GPUOffScreen *ofs, bool save) void GPU_offscreen_unbind(GPUOffScreen *UNUSED(ofs), bool restore) { - GPUFrameBuffer *fb = NULL; + GPUFrameBuffer *fb = nullptr; if (restore) { fb = gpuPopFrameBuffer(); } diff --git a/source/blender/gpu/intern/gpu_immediate.cc b/source/blender/gpu/intern/gpu_immediate.cc index 979b3cbb557..95718391165 100644 --- a/source/blender/gpu/intern/gpu_immediate.cc +++ b/source/blender/gpu/intern/gpu_immediate.cc @@ -39,19 +39,19 @@ using namespace blender::gpu; -static thread_local Immediate *imm = NULL; +static thread_local Immediate *imm = nullptr; -void immActivate(void) +void immActivate() { imm = Context::get()->imm; } -void immDeactivate(void) +void immDeactivate() { - imm = NULL; + imm = nullptr; } -GPUVertFormat *immVertexFormat(void) +GPUVertFormat *immVertexFormat() { GPU_vertformat_clear(&imm->vertex_format); return &imm->vertex_format; @@ -59,7 +59,7 @@ GPUVertFormat *immVertexFormat(void) void immBindShader(GPUShader *shader) { - BLI_assert(imm->shader == NULL); + BLI_assert(imm->shader == nullptr); imm->shader = shader; imm->builtin_shader_bound = GPU_SHADER_TEXT; /* Default value. */ @@ -81,16 +81,16 @@ void immBindBuiltinProgram(eGPUBuiltinShader shader_id) imm->builtin_shader_bound = shader_id; } -void immUnbindProgram(void) +void immUnbindProgram() { - BLI_assert(imm->shader != NULL); + BLI_assert(imm->shader != nullptr); GPU_shader_unbind(); - imm->shader = NULL; + imm->shader = nullptr; } /* XXX do not use it. Special hack to use OCIO with batch API. */ -GPUShader *immGetShader(void) +GPUShader *immGetShader() { return imm->shader; } @@ -192,7 +192,7 @@ static void wide_line_workaround_start(GPUPrimType prim_type) } } -static void wide_line_workaround_end(void) +static void wide_line_workaround_end() { if (imm->prev_shader) { if (GPU_blend_get() == GPU_BLEND_NONE) { @@ -202,7 +202,7 @@ static void wide_line_workaround_end(void) immUnbindProgram(); immBindShader(imm->prev_shader); - imm->prev_shader = NULL; + imm->prev_shader = nullptr; } } @@ -245,7 +245,7 @@ GPUBatch *immBeginBatch(GPUPrimType prim_type, uint vertex_len) imm->vertex_data = (uchar *)GPU_vertbuf_get_data(verts); - imm->batch = GPU_batch_create_ex(prim_type, verts, NULL, GPU_BATCH_OWNS_VBO); + imm->batch = GPU_batch_create_ex(prim_type, verts, nullptr, GPU_BATCH_OWNS_VBO); imm->batch->flag |= GPU_BATCH_BUILDING; return imm->batch; @@ -258,7 +258,7 @@ GPUBatch *immBeginBatchAtMost(GPUPrimType prim_type, uint vertex_len) return immBeginBatch(prim_type, vertex_len); } -void immEnd(void) +void immEnd() { BLI_assert(imm->prim_type != GPU_PRIM_NONE); /* Make sure we're between a Begin/End pair. */ BLI_assert(imm->vertex_data || imm->batch); @@ -279,7 +279,7 @@ void immEnd(void) } GPU_batch_set_shader(imm->batch, imm->shader); imm->batch->flag &= ~GPU_BATCH_BUILDING; - imm->batch = NULL; /* don't free, batch belongs to caller */ + imm->batch = nullptr; /* don't free, batch belongs to caller */ } else { imm->end(); @@ -288,7 +288,7 @@ void immEnd(void) /* Prepare for next immBegin. */ imm->prim_type = GPU_PRIM_NONE; imm->strict_vertex_len = true; - imm->vertex_data = NULL; + imm->vertex_data = nullptr; wide_line_workaround_end(); } @@ -489,7 +489,7 @@ void immAttrSkip(uint attr_id) setAttrValueBit(attr_id); } -static void immEndVertex(void) /* and move on to the next vertex */ +static void immEndVertex() /* and move on to the next vertex */ { BLI_assert(imm->prim_type != GPU_PRIM_NONE); /* make sure we're between a Begin/End pair */ BLI_assert(imm->vertex_idx < imm->vertex_len); diff --git a/source/blender/gpu/intern/gpu_immediate_util.c b/source/blender/gpu/intern/gpu_immediate_util.c index b8cd9fe356d..d18dc862ce7 100644 --- a/source/blender/gpu/intern/gpu_immediate_util.c +++ b/source/blender/gpu/intern/gpu_immediate_util.c @@ -455,8 +455,8 @@ void imm_draw_cylinder_fill_normal_3d( for (int j = 0; j < stacks; j++) { float fac1 = (float)j / (float)stacks; float fac2 = (float)(j + 1) / (float)stacks; - float r1 = base * (1.f - fac1) + top * fac1; - float r2 = base * (1.f - fac2) + top * fac2; + float r1 = base * (1.0f - fac1) + top * fac1; + float r2 = base * (1.0f - fac2) + top * fac2; float h1 = height * ((float)j / (float)stacks); float h2 = height * ((float)(j + 1) / (float)stacks); @@ -511,8 +511,8 @@ void imm_draw_cylinder_wire_3d( for (int j = 0; j < stacks; j++) { float fac1 = (float)j / (float)stacks; float fac2 = (float)(j + 1) / (float)stacks; - float r1 = base * (1.f - fac1) + top * fac1; - float r2 = base * (1.f - fac2) + top * fac2; + float r1 = base * (1.0f - fac1) + top * fac1; + float r2 = base * (1.0f - fac2) + top * fac2; float h1 = height * ((float)j / (float)stacks); float h2 = height * ((float)(j + 1) / (float)stacks); @@ -549,8 +549,8 @@ void imm_draw_cylinder_fill_3d( for (int j = 0; j < stacks; j++) { float fac1 = (float)j / (float)stacks; float fac2 = (float)(j + 1) / (float)stacks; - float r1 = base * (1.f - fac1) + top * fac1; - float r2 = base * (1.f - fac2) + top * fac2; + float r1 = base * (1.0f - fac1) + top * fac1; + float r2 = base * (1.0f - fac2) + top * fac2; float h1 = height * ((float)j / (float)stacks); float h2 = height * ((float)(j + 1) / (float)stacks); diff --git a/source/blender/gpu/intern/gpu_index_buffer.cc b/source/blender/gpu/intern/gpu_index_buffer.cc index 36f18f2da49..65932d2dbf4 100644 --- a/source/blender/gpu/intern/gpu_index_buffer.cc +++ b/source/blender/gpu/intern/gpu_index_buffer.cc @@ -69,7 +69,7 @@ void GPU_indexbuf_init(GPUIndexBufBuilder *builder, void GPU_indexbuf_add_generic_vert(GPUIndexBufBuilder *builder, uint v) { #if TRUST_NO_ONE - assert(builder->data != NULL); + assert(builder->data != nullptr); assert(builder->index_len < builder->max_index_len); assert(v <= builder->max_allowed_index); #endif @@ -79,7 +79,7 @@ void GPU_indexbuf_add_generic_vert(GPUIndexBufBuilder *builder, uint v) void GPU_indexbuf_add_primitive_restart(GPUIndexBufBuilder *builder) { #if TRUST_NO_ONE - assert(builder->data != NULL); + assert(builder->data != nullptr); assert(builder->index_len < builder->max_index_len); #endif builder->data[builder->index_len++] = RESTART_INDEX; @@ -336,7 +336,7 @@ GPUIndexBuf *GPU_indexbuf_create_subrange(GPUIndexBuf *elem_src, uint start, uin void GPU_indexbuf_build_in_place(GPUIndexBufBuilder *builder, GPUIndexBuf *elem) { - BLI_assert(builder->data != NULL); + BLI_assert(builder->data != nullptr); /* Transfer data ownership to GPUIndexBuf. * It will be uploaded upon first use. */ unwrap(elem)->init(builder->index_len, builder->data); diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 011d14673b4..a0fe77598f2 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -313,7 +313,7 @@ static float eval_profile(float r, short falloff_type, float sharpness, float pa { r = fabsf(r); - if (falloff_type == SHD_SUBSURFACE_BURLEY || falloff_type == SHD_SUBSURFACE_RANDOM_WALK) { + if (ELEM(falloff_type, SHD_SUBSURFACE_BURLEY, SHD_SUBSURFACE_RANDOM_WALK)) { return burley_profile(r, param) / BURLEY_TRUNCATE_CDF; } if (falloff_type == SHD_SUBSURFACE_CUBIC) { @@ -353,7 +353,7 @@ static void compute_sss_kernel( /* Christensen-Burley fitting */ float l[3], d[3]; - if (falloff_type == SHD_SUBSURFACE_BURLEY || falloff_type == SHD_SUBSURFACE_RANDOM_WALK) { + if (ELEM(falloff_type, SHD_SUBSURFACE_BURLEY, SHD_SUBSURFACE_RANDOM_WALK)) { mul_v3_v3fl(l, rad, 0.25f * M_1_PI); const float A = 1.0f; const float s = 1.9f - A + 3.5f * (A - 0.8f) * (A - 0.8f); @@ -584,6 +584,12 @@ ListBase GPU_material_volume_grids(GPUMaterial *material) return material->graph.volume_grids; } +GPUUniformAttrList *GPU_material_uniform_attributes(GPUMaterial *material) +{ + GPUUniformAttrList *attrs = &material->graph.uniform_attrs; + return attrs->count > 0 ? attrs : NULL; +} + void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link) { if (!material->graph.outlink) { diff --git a/source/blender/gpu/intern/gpu_matrix.cc b/source/blender/gpu/intern/gpu_matrix.cc index 0274966d4b9..dae56e39db6 100644 --- a/source/blender/gpu/intern/gpu_matrix.cc +++ b/source/blender/gpu/intern/gpu_matrix.cc @@ -606,7 +606,7 @@ const float (*GPU_matrix_projection_get(float m[4][4]))[4] const float (*GPU_matrix_model_view_projection_get(float m[4][4]))[4] { - if (m == NULL) { + if (m == nullptr) { static Mat4 temp; m = temp; } @@ -617,12 +617,12 @@ const float (*GPU_matrix_model_view_projection_get(float m[4][4]))[4] const float (*GPU_matrix_normal_get(float m[3][3]))[3] { - if (m == NULL) { + if (m == nullptr) { static Mat3 temp3; m = temp3; } - copy_m3_m4(m, (const float(*)[4])GPU_matrix_model_view_get(NULL)); + copy_m3_m4(m, (const float(*)[4])GPU_matrix_model_view_get(nullptr)); invert_m3(m); transpose_m3(m); @@ -632,7 +632,7 @@ const float (*GPU_matrix_normal_get(float m[3][3]))[3] const float (*GPU_matrix_normal_inverse_get(float m[3][3]))[3] { - if (m == NULL) { + if (m == nullptr) { static Mat3 temp3; m = temp3; } @@ -658,17 +658,18 @@ void GPU_matrix_bind(GPUShader *shader) int32_t P_inv = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_PROJECTION_INV); if (MV != -1) { - GPU_shader_uniform_vector(shader, MV, 16, 1, (const float *)GPU_matrix_model_view_get(NULL)); + GPU_shader_uniform_vector( + shader, MV, 16, 1, (const float *)GPU_matrix_model_view_get(nullptr)); } if (P != -1) { - GPU_shader_uniform_vector(shader, P, 16, 1, (const float *)GPU_matrix_projection_get(NULL)); + GPU_shader_uniform_vector(shader, P, 16, 1, (const float *)GPU_matrix_projection_get(nullptr)); } if (MVP != -1) { GPU_shader_uniform_vector( - shader, MVP, 16, 1, (const float *)GPU_matrix_model_view_projection_get(NULL)); + shader, MVP, 16, 1, (const float *)GPU_matrix_model_view_projection_get(nullptr)); } if (N != -1) { - GPU_shader_uniform_vector(shader, N, 9, 1, (const float *)GPU_matrix_normal_get(NULL)); + GPU_shader_uniform_vector(shader, N, 9, 1, (const float *)GPU_matrix_normal_get(nullptr)); } if (MV_inv != -1) { Mat4 m; diff --git a/source/blender/gpu/intern/gpu_node_graph.c b/source/blender/gpu/intern/gpu_node_graph.c index c890d56994f..2a2a51e32b3 100644 --- a/source/blender/gpu/intern/gpu_node_graph.c +++ b/source/blender/gpu/intern/gpu_node_graph.c @@ -132,7 +132,14 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const eGPUType case GPU_NODE_LINK_ATTR: input->source = GPU_SOURCE_ATTR; input->attr = link->attr; - input->attr->gputype = type; + /* Failsafe handling if the same attribute is used with different datatypes for + * some reason (only really makes sense with float/vec2/vec3/vec4 though). This + * can happen if mixing the generic Attribute node with specialized ones. */ + CLAMP_MIN(input->attr->gputype, type); + break; + case GPU_NODE_LINK_UNIFORM_ATTR: + input->source = GPU_SOURCE_UNIFORM_ATTR; + input->uniform_attr = link->uniform_attr; break; case GPU_NODE_LINK_CONSTANT: input->source = (type == GPU_CLOSURE) ? GPU_SOURCE_STRUCT : GPU_SOURCE_CONSTANT; @@ -259,8 +266,90 @@ static void gpu_node_output(GPUNode *node, const eGPUType type, GPUNodeLink **li BLI_addtail(&node->outputs, output); } +/* Uniform Attribute Functions */ + +static int uniform_attr_sort_cmp(const void *a, const void *b) +{ + const GPUUniformAttr *attr_a = a, *attr_b = b; + + int cmps = strcmp(attr_a->name, attr_b->name); + if (cmps != 0) { + return cmps > 0 ? 1 : 0; + } + + return (attr_a->use_dupli && !attr_b->use_dupli); +} + +static unsigned int uniform_attr_list_hash(const void *key) +{ + const GPUUniformAttrList *attrs = key; + return attrs->hash_code; +} + +static bool uniform_attr_list_cmp(const void *a, const void *b) +{ + const GPUUniformAttrList *set_a = a, *set_b = b; + + if (set_a->hash_code != set_b->hash_code || set_a->count != set_b->count) { + return true; + } + + GPUUniformAttr *attr_a = set_a->list.first, *attr_b = set_b->list.first; + + for (; attr_a && attr_b; attr_a = attr_a->next, attr_b = attr_b->next) { + if (!STREQ(attr_a->name, attr_b->name) || attr_a->use_dupli != attr_b->use_dupli) { + return true; + } + } + + return attr_a || attr_b; +} + +struct GHash *GPU_uniform_attr_list_hash_new(const char *info) +{ + return BLI_ghash_new(uniform_attr_list_hash, uniform_attr_list_cmp, info); +} + +void GPU_uniform_attr_list_copy(GPUUniformAttrList *dest, GPUUniformAttrList *src) +{ + dest->count = src->count; + dest->hash_code = src->hash_code; + BLI_duplicatelist(&dest->list, &src->list); +} + +void GPU_uniform_attr_list_free(GPUUniformAttrList *set) +{ + set->count = 0; + set->hash_code = 0; + BLI_freelistN(&set->list); +} + +void gpu_node_graph_finalize_uniform_attrs(GPUNodeGraph *graph) +{ + GPUUniformAttrList *attrs = &graph->uniform_attrs; + BLI_assert(attrs->count == BLI_listbase_count(&attrs->list)); + + /* Sort the attributes by name to ensure a stable order. */ + BLI_listbase_sort(&attrs->list, uniform_attr_sort_cmp); + + /* Compute the indices and the hash code. */ + int next_id = 0; + attrs->hash_code = 0; + + LISTBASE_FOREACH (GPUUniformAttr *, attr, &attrs->list) { + attr->id = next_id++; + + attrs->hash_code ^= BLI_ghashutil_strhash_p(attr->name); + + if (attr->use_dupli) { + attrs->hash_code ^= BLI_ghashutil_uinthash(attr->id); + } + } +} + /* Attributes and Textures */ +/** Add a new varying attribute of given type and name. Returns NULL if out of slots. */ static GPUMaterialAttribute *gpu_node_graph_add_attribute(GPUNodeGraph *graph, CustomDataType type, const char *name) @@ -296,6 +385,38 @@ static GPUMaterialAttribute *gpu_node_graph_add_attribute(GPUNodeGraph *graph, return attr; } +/** Add a new uniform attribute of given type and name. Returns NULL if out of slots. */ +static GPUUniformAttr *gpu_node_graph_add_uniform_attribute(GPUNodeGraph *graph, + const char *name, + bool use_dupli) +{ + /* Find existing attribute. */ + GPUUniformAttrList *attrs = &graph->uniform_attrs; + GPUUniformAttr *attr = attrs->list.first; + + for (; attr; attr = attr->next) { + if (STREQ(attr->name, name) && attr->use_dupli == use_dupli) { + break; + } + } + + /* Add new requested attribute if it's within GPU limits. */ + if (attr == NULL && attrs->count < GPU_MAX_UNIFORM_ATTR) { + attr = MEM_callocN(sizeof(*attr), __func__); + STRNCPY(attr->name, name); + attr->use_dupli = use_dupli; + attr->id = -1; + BLI_addtail(&attrs->list, attr); + attrs->count++; + } + + if (attr != NULL) { + attr->users++; + } + + return attr; +} + static GPUMaterialTexture *gpu_node_graph_add_texture(GPUNodeGraph *graph, Image *ima, ImageUser *iuser, @@ -369,6 +490,7 @@ GPUNodeLink *GPU_attribute(GPUMaterial *mat, const CustomDataType type, const ch GPUNodeGraph *graph = gpu_material_node_graph(mat); GPUMaterialAttribute *attr = gpu_node_graph_add_attribute(graph, type, name); + /* Dummy fallback if out of slots. */ if (attr == NULL) { static const float zero_data[GPU_MAX_CONSTANT_DATA] = {0.0f}; return GPU_constant(zero_data); @@ -380,6 +502,23 @@ GPUNodeLink *GPU_attribute(GPUMaterial *mat, const CustomDataType type, const ch return link; } +GPUNodeLink *GPU_uniform_attribute(GPUMaterial *mat, const char *name, bool use_dupli) +{ + GPUNodeGraph *graph = gpu_material_node_graph(mat); + GPUUniformAttr *attr = gpu_node_graph_add_uniform_attribute(graph, name, use_dupli); + + /* Dummy fallback if out of slots. */ + if (attr == NULL) { + static const float zero_data[GPU_MAX_CONSTANT_DATA] = {0.0f}; + return GPU_constant(zero_data); + } + + GPUNodeLink *link = gpu_node_link_create(); + link->link_type = GPU_NODE_LINK_UNIFORM_ATTR; + link->uniform_attr = attr; + return link; +} + GPUNodeLink *GPU_constant(const float *num) { GPUNodeLink *link = gpu_node_link_create(); @@ -616,6 +755,9 @@ static void gpu_inputs_free(ListBase *inputs) if (input->source == GPU_SOURCE_ATTR) { input->attr->users--; } + else if (input->source == GPU_SOURCE_UNIFORM_ATTR) { + input->uniform_attr->users--; + } else if (ELEM(input->source, GPU_SOURCE_TEX, GPU_SOURCE_TEX_TILED_MAPPING)) { input->texture->users--; } @@ -671,6 +813,7 @@ void gpu_node_graph_free(GPUNodeGraph *graph) BLI_freelistN(&graph->volume_grids); BLI_freelistN(&graph->textures); BLI_freelistN(&graph->attributes); + GPU_uniform_attr_list_free(&graph->uniform_attrs); } /* Prune Unused Nodes */ @@ -735,4 +878,13 @@ void gpu_node_graph_prune_unused(GPUNodeGraph *graph) BLI_freelinkN(&graph->volume_grids, grid); } } + + GPUUniformAttrList *uattrs = &graph->uniform_attrs; + + LISTBASE_FOREACH_MUTABLE (GPUUniformAttr *, attr, &uattrs->list) { + if (attr->users == 0) { + BLI_freelinkN(&uattrs->list, attr); + uattrs->count--; + } + } } diff --git a/source/blender/gpu/intern/gpu_node_graph.h b/source/blender/gpu/intern/gpu_node_graph.h index 7265abf4d65..a0e6298cd92 100644 --- a/source/blender/gpu/intern/gpu_node_graph.h +++ b/source/blender/gpu/intern/gpu_node_graph.h @@ -42,6 +42,7 @@ typedef enum eGPUDataSource { GPU_SOURCE_CONSTANT, GPU_SOURCE_UNIFORM, GPU_SOURCE_ATTR, + GPU_SOURCE_UNIFORM_ATTR, GPU_SOURCE_BUILTIN, GPU_SOURCE_STRUCT, GPU_SOURCE_TEX, @@ -53,6 +54,7 @@ typedef enum eGPUDataSource { typedef enum { GPU_NODE_LINK_NONE = 0, GPU_NODE_LINK_ATTR, + GPU_NODE_LINK_UNIFORM_ATTR, GPU_NODE_LINK_BUILTIN, GPU_NODE_LINK_COLORBAND, GPU_NODE_LINK_CONSTANT, @@ -96,6 +98,8 @@ struct GPUNodeLink { struct GPUOutput *output; /* GPU_NODE_LINK_ATTR */ struct GPUMaterialAttribute *attr; + /* GPU_NODE_LINK_UNIFORM_ATTR */ + struct GPUUniformAttr *uniform_attr; /* GPU_NODE_LINK_IMAGE_BLENDER */ struct GPUMaterialTexture *texture; }; @@ -130,6 +134,8 @@ typedef struct GPUInput { struct GPUMaterialTexture *texture; /* GPU_SOURCE_ATTR */ struct GPUMaterialAttribute *attr; + /* GPU_SOURCE_UNIFORM_ATTR */ + struct GPUUniformAttr *uniform_attr; /* GPU_SOURCE_VOLUME_GRID | GPU_SOURCE_VOLUME_GRID_TRANSFORM */ struct GPUMaterialVolumeGrid *volume_grid; }; @@ -146,11 +152,15 @@ typedef struct GPUNodeGraph { ListBase attributes; ListBase textures; ListBase volume_grids; + + /* The list of uniform attributes. */ + GPUUniformAttrList uniform_attrs; } GPUNodeGraph; /* Node Graph */ void gpu_node_graph_prune_unused(GPUNodeGraph *graph); +void gpu_node_graph_finalize_uniform_attrs(GPUNodeGraph *graph); void gpu_node_graph_free_nodes(GPUNodeGraph *graph); void gpu_node_graph_free(GPUNodeGraph *graph); diff --git a/source/blender/gpu/intern/gpu_platform.cc b/source/blender/gpu/intern/gpu_platform.cc index ad7142878e7..6b9878f2ba4 100644 --- a/source/blender/gpu/intern/gpu_platform.cc +++ b/source/blender/gpu/intern/gpu_platform.cc @@ -77,7 +77,7 @@ void GPUPlatformGlobal::create_gpu_name(const char *vendor, BLI_str_replace_char(gpu_name, '\r', ' '); } -void GPUPlatformGlobal::clear(void) +void GPUPlatformGlobal::clear() { MEM_SAFE_FREE(GPG.support_key); MEM_SAFE_FREE(GPG.gpu_name); @@ -94,12 +94,12 @@ void GPUPlatformGlobal::clear(void) using namespace blender::gpu; -eGPUSupportLevel GPU_platform_support_level(void) +eGPUSupportLevel GPU_platform_support_level() { return GPG.support_level; } -const char *GPU_platform_support_level_key(void) +const char *GPU_platform_support_level_key() { return GPG.support_key; } diff --git a/source/blender/gpu/intern/gpu_select_sample_query.cc b/source/blender/gpu/intern/gpu_select_sample_query.cc index 5bbf3bd05d3..6ca811895a5 100644 --- a/source/blender/gpu/intern/gpu_select_sample_query.cc +++ b/source/blender/gpu/intern/gpu_select_sample_query.cc @@ -70,7 +70,7 @@ typedef struct GPUSelectQueryState { eGPUDepthTest depth_test; } GPUSelectQueryState; -static GPUSelectQueryState g_query_state = {0}; +static GPUSelectQueryState g_query_state = {false}; void gpu_select_query_begin( uint (*buffer)[4], uint bufsize, const rcti *input, char mode, int oldhits) diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc index c13321ed205..49f96cb652c 100644 --- a/source/blender/gpu/intern/gpu_shader.cc +++ b/source/blender/gpu/intern/gpu_shader.cc @@ -291,7 +291,7 @@ GPUShader *GPU_shader_create_ex(const char *vertcode, const char *shname) { /* At least a vertex shader and a fragment shader are required. */ - BLI_assert((fragcode != NULL) && (vertcode != NULL)); + BLI_assert((fragcode != nullptr) && (vertcode != nullptr)); Shader *shader = GPUBackend::get()->shader_alloc(shname); @@ -342,14 +342,14 @@ GPUShader *GPU_shader_create_ex(const char *vertcode, shader->geometry_shader_from_glsl(sources); } - if (tf_names != NULL && tf_count > 0) { + if (tf_names != nullptr && tf_count > 0) { BLI_assert(tf_type != GPU_SHADER_TFB_NONE); shader->transform_feedback_names_set(Span<const char *>(tf_names, tf_count), tf_type); } if (!shader->finalize()) { delete shader; - return NULL; + return nullptr; }; return wrap(shader); @@ -374,7 +374,7 @@ GPUShader *GPU_shader_create(const char *vertcode, const char *shname) { return GPU_shader_create_ex( - vertcode, fragcode, geomcode, libcode, defines, GPU_SHADER_TFB_NONE, NULL, 0, shname); + vertcode, fragcode, geomcode, libcode, defines, GPU_SHADER_TFB_NONE, nullptr, 0, shname); } GPUShader *GPU_shader_create_from_python(const char *vertcode, @@ -383,17 +383,24 @@ GPUShader *GPU_shader_create_from_python(const char *vertcode, const char *libcode, const char *defines) { - char *libcodecat = NULL; + char *libcodecat = nullptr; - if (libcode == NULL) { + if (libcode == nullptr) { libcode = datatoc_gpu_shader_colorspace_lib_glsl; } else { libcode = libcodecat = BLI_strdupcat(libcode, datatoc_gpu_shader_colorspace_lib_glsl); } - GPUShader *sh = GPU_shader_create_ex( - vertcode, fragcode, geomcode, libcode, defines, GPU_SHADER_TFB_NONE, NULL, 0, "pyGPUShader"); + GPUShader *sh = GPU_shader_create_ex(vertcode, + fragcode, + geomcode, + libcode, + defines, + GPU_SHADER_TFB_NONE, + nullptr, + 0, + "pyGPUShader"); MEM_SAFE_FREE(libcodecat); return sh; @@ -402,9 +409,9 @@ GPUShader *GPU_shader_create_from_python(const char *vertcode, static const char *string_join_array_maybe_alloc(const char **str_arr, bool *r_is_alloc) { bool is_alloc = false; - if (str_arr == NULL) { + if (str_arr == nullptr) { *r_is_alloc = false; - return NULL; + return nullptr; } /* Skip empty strings (avoid alloc if we can). */ while (str_arr[0] && str_arr[0][0] == '\0') { @@ -450,7 +457,7 @@ struct GPUShader *GPU_shader_create_from_arrays_impl( struct { const char *str; bool is_alloc; - } str_dst[4] = {{0}}; + } str_dst[4] = {{nullptr}}; const char **str_src[4] = {params->vert, params->frag, params->geom, params->defs}; for (int i = 0; i < ARRAY_SIZE(str_src); i++) { @@ -461,7 +468,7 @@ struct GPUShader *GPU_shader_create_from_arrays_impl( BLI_snprintf(name, sizeof(name), "%s_%d", func, line); GPUShader *sh = GPU_shader_create( - str_dst[0].str, str_dst[1].str, str_dst[2].str, NULL, str_dst[3].str, name); + 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) { @@ -502,7 +509,7 @@ void GPU_shader_unbind(void) if (ctx->shader) { ctx->shader->unbind(); } - ctx->shader = NULL; + ctx->shader = nullptr; #endif } diff --git a/source/blender/gpu/intern/gpu_shader_interface.cc b/source/blender/gpu/intern/gpu_shader_interface.cc index e5fb8025e7f..81c1e013877 100644 --- a/source/blender/gpu/intern/gpu_shader_interface.cc +++ b/source/blender/gpu/intern/gpu_shader_interface.cc @@ -32,12 +32,12 @@ namespace blender::gpu { -ShaderInterface::ShaderInterface(void) +ShaderInterface::ShaderInterface() { /* TODO(fclem): add unique ID for debugging. */ } -ShaderInterface::~ShaderInterface(void) +ShaderInterface::~ShaderInterface() { /* Free memory used by name_buffer. */ MEM_freeN(name_buffer_); @@ -70,14 +70,14 @@ static void sort_input_list(MutableSpan<ShaderInput> dst) /* Sorts all inputs inside their respective array. * This is to allow fast hash collision detection. * See ShaderInterface::input_lookup for more details. */ -void ShaderInterface::sort_inputs(void) +void ShaderInterface::sort_inputs() { sort_input_list(MutableSpan<ShaderInput>(inputs_, attr_len_)); sort_input_list(MutableSpan<ShaderInput>(inputs_ + attr_len_, ubo_len_)); sort_input_list(MutableSpan<ShaderInput>(inputs_ + attr_len_ + ubo_len_, uniform_len_)); } -void ShaderInterface::debug_print(void) +void ShaderInterface::debug_print() { Span<ShaderInput> attrs = Span<ShaderInput>(inputs_, attr_len_); Span<ShaderInput> ubos = Span<ShaderInput>(inputs_ + attr_len_, ubo_len_); diff --git a/source/blender/gpu/intern/gpu_state.cc b/source/blender/gpu/intern/gpu_state.cc index 0b2e4989a33..407a8dd6e2b 100644 --- a/source/blender/gpu/intern/gpu_state.cc +++ b/source/blender/gpu/intern/gpu_state.cc @@ -260,7 +260,7 @@ eGPUStencilTest GPU_stencil_test_get() } /* NOTE: Already premultiplied by U.pixelsize. */ -float GPU_line_width_get(void) +float GPU_line_width_get() { GPUStateMutable &state = Context::get()->state_manager->mutable_state; return state.line_width; @@ -285,13 +285,13 @@ void GPU_viewport_size_get_i(int coords[4]) Context::get()->active_fb->viewport_get(coords); } -bool GPU_depth_mask_get(void) +bool GPU_depth_mask_get() { GPUState &state = Context::get()->state_manager->state; return (state.write_mask & GPU_WRITE_DEPTH) != 0; } -bool GPU_mipmap_enabled(void) +bool GPU_mipmap_enabled() { /* TODO(fclem): this used to be a userdef option. */ return true; @@ -303,17 +303,17 @@ bool GPU_mipmap_enabled(void) /** \name Context Utils * \{ */ -void GPU_flush(void) +void GPU_flush() { Context::get()->flush(); } -void GPU_finish(void) +void GPU_finish() { Context::get()->finish(); } -void GPU_apply_state(void) +void GPU_apply_state() { Context::get()->state_manager->apply_state(); } @@ -328,7 +328,7 @@ void GPU_apply_state(void) * bgl functions. * \{ */ -void GPU_bgl_start(void) +void GPU_bgl_start() { Context *ctx = Context::get(); if (!(ctx && ctx->state_manager)) { @@ -345,7 +345,7 @@ void GPU_bgl_start(void) } /* Just turn off the bgl safeguard system. Can be called even without GPU_bgl_start. */ -void GPU_bgl_end(void) +void GPU_bgl_end() { Context *ctx = Context::get(); if (!(ctx && ctx->state_manager)) { @@ -359,7 +359,7 @@ void GPU_bgl_end(void) } } -bool GPU_bgl_get(void) +bool GPU_bgl_get() { return Context::get()->state_manager->use_bgl; } @@ -381,7 +381,7 @@ void GPU_memory_barrier(eGPUBarrier barrier) /** \name Default State * \{ */ -StateManager::StateManager(void) +StateManager::StateManager() { /* Set default state. */ state.write_mask = GPU_WRITE_COLOR; diff --git a/source/blender/gpu/intern/gpu_texture.cc b/source/blender/gpu/intern/gpu_texture.cc index 99d286c3abd..d134d718cbe 100644 --- a/source/blender/gpu/intern/gpu_texture.cc +++ b/source/blender/gpu/intern/gpu_texture.cc @@ -49,14 +49,14 @@ Texture::Texture(const char *name) } for (int i = 0; i < ARRAY_SIZE(fb_); i++) { - fb_[i] = NULL; + fb_[i] = nullptr; } } Texture::~Texture() { for (int i = 0; i < ARRAY_SIZE(fb_); i++) { - if (fb_[i] != NULL) { + if (fb_[i] != nullptr) { fb_[i]->attachment_remove(fb_attachment_[i]); } } @@ -142,7 +142,7 @@ bool Texture::init_buffer(GPUVertBuf *vbo, eGPUTextureFormat format) void Texture::attach_to(FrameBuffer *fb, GPUAttachmentType type) { for (int i = 0; i < ARRAY_SIZE(fb_); i++) { - if (fb_[i] == NULL) { + if (fb_[i] == nullptr) { fb_attachment_[i] = type; fb_[i] = fb; return; @@ -156,7 +156,7 @@ void Texture::detach_from(FrameBuffer *fb) for (int i = 0; i < ARRAY_SIZE(fb_); i++) { if (fb_[i] == fb) { fb_[i]->attachment_remove(fb_attachment_[i]); - fb_[i] = NULL; + fb_[i] = nullptr; return; } } @@ -226,7 +226,7 @@ static inline GPUTexture *gpu_texture_create(const char *name, if (!success) { delete tex; - return NULL; + return nullptr; } if (pixels) { tex->update(data_format, pixels); @@ -295,7 +295,7 @@ GPUTexture *GPU_texture_create_compressed_2d( if (!success) { delete tex; - return NULL; + return nullptr; } if (data) { size_t ofs = 0; @@ -320,7 +320,7 @@ GPUTexture *GPU_texture_create_from_vertbuf(const char *name, GPUVertBuf *vert) bool success = tex->init_buffer(vert, tex_format); if (!success) { delete tex; - return NULL; + return nullptr; } return reinterpret_cast<GPUTexture *>(tex); } @@ -383,7 +383,7 @@ void *GPU_texture_read(GPUTexture *tex_, eGPUDataFormat data_format, int miplvl) */ void GPU_texture_clear(GPUTexture *tex, eGPUDataFormat data_format, const void *data) { - BLI_assert(data != NULL); /* Do not accept NULL as parameter. */ + BLI_assert(data != nullptr); /* Do not accept NULL as parameter. */ reinterpret_cast<Texture *>(tex)->clear(data_format, data); } diff --git a/source/blender/gpu/intern/gpu_uniform_buffer.cc b/source/blender/gpu/intern/gpu_uniform_buffer.cc index 2dea98f03ca..89c70c47e4a 100644 --- a/source/blender/gpu/intern/gpu_uniform_buffer.cc +++ b/source/blender/gpu/intern/gpu_uniform_buffer.cc @@ -73,7 +73,7 @@ static eGPUType get_padded_gpu_type(LinkData *link) GPUInput *input = (GPUInput *)link->data; eGPUType gputype = input->type; /* Unless the vec3 is followed by a float we need to treat it as a vec4. */ - if (gputype == GPU_VEC3 && (link->next != NULL) && + if (gputype == GPU_VEC3 && (link->next != nullptr) && (((GPUInput *)link->next->data)->type != GPU_FLOAT)) { gputype = GPU_VEC4; } @@ -106,7 +106,7 @@ static void buffer_from_list_inputs_sort(ListBase *inputs) BLI_listbase_sort(inputs, inputs_cmp); /* Creates a lookup table for the different types; */ - LinkData *inputs_lookup[MAX_UBO_GPU_TYPE + 1] = {NULL}; + LinkData *inputs_lookup[MAX_UBO_GPU_TYPE + 1] = {nullptr}; eGPUType cur_type = static_cast<eGPUType>(MAX_UBO_GPU_TYPE + 1); LISTBASE_FOREACH (LinkData *, link, inputs) { @@ -131,21 +131,21 @@ static void buffer_from_list_inputs_sort(ListBase *inputs) } /* If there is no GPU_VEC3 there is no need for alignment. */ - if (inputs_lookup[GPU_VEC3] == NULL) { + if (inputs_lookup[GPU_VEC3] == nullptr) { return; } LinkData *link = inputs_lookup[GPU_VEC3]; - while (link != NULL && ((GPUInput *)link->data)->type == GPU_VEC3) { + while (link != nullptr && ((GPUInput *)link->data)->type == GPU_VEC3) { LinkData *link_next = link->next; /* If GPU_VEC3 is followed by nothing or a GPU_FLOAT, no need for alignment. */ - if ((link_next == NULL) || ((GPUInput *)link_next->data)->type == GPU_FLOAT) { + if ((link_next == nullptr) || ((GPUInput *)link_next->data)->type == GPU_FLOAT) { break; } /* If there is a float, move it next to current vec3. */ - if (inputs_lookup[GPU_FLOAT] != NULL) { + if (inputs_lookup[GPU_FLOAT] != nullptr) { LinkData *float_input = inputs_lookup[GPU_FLOAT]; inputs_lookup[GPU_FLOAT] = float_input->next; @@ -195,7 +195,7 @@ GPUUniformBuf *GPU_uniformbuf_create_ex(size_t size, const void *data, const cha { UniformBuf *ubo = GPUBackend::get()->uniformbuf_alloc(size, name); /* Direct init. */ - if (data != NULL) { + if (data != nullptr) { ubo->update(data); } return wrap(ubo); @@ -211,7 +211,7 @@ GPUUniformBuf *GPU_uniformbuf_create_from_list(ListBase *inputs, const char *nam { /* There is no point on creating an UBO if there is no arguments. */ if (BLI_listbase_is_empty(inputs)) { - return NULL; + return nullptr; } buffer_from_list_inputs_sort(inputs); diff --git a/source/blender/gpu/intern/gpu_vertex_buffer.cc b/source/blender/gpu/intern/gpu_vertex_buffer.cc index 29fa8a89d27..09b9eba9f95 100644 --- a/source/blender/gpu/intern/gpu_vertex_buffer.cc +++ b/source/blender/gpu/intern/gpu_vertex_buffer.cc @@ -66,13 +66,13 @@ void VertBuf::init(const GPUVertFormat *format, GPUUsageType usage) flag |= GPU_VERTBUF_INIT; } -void VertBuf::clear(void) +void VertBuf::clear() { this->release_data(); flag = GPU_VERTBUF_INVALID; } -VertBuf *VertBuf::duplicate(void) +VertBuf *VertBuf::duplicate() { VertBuf *dst = GPUBackend::get()->vertbuf_alloc(); /* Full copy. */ @@ -107,7 +107,7 @@ void VertBuf::resize(uint vert_len) flag |= GPU_VERTBUF_DATA_DIRTY; } -void VertBuf::upload(void) +void VertBuf::upload() { this->upload_data(); } @@ -125,7 +125,7 @@ using namespace blender::gpu; /* -------- Creation & deletion -------- */ -GPUVertBuf *GPU_vertbuf_calloc(void) +GPUVertBuf *GPU_vertbuf_calloc() { return wrap(GPUBackend::get()->vertbuf_alloc()); } @@ -191,7 +191,7 @@ void GPU_vertbuf_data_resize(GPUVertBuf *verts, uint v_len) void GPU_vertbuf_data_len_set(GPUVertBuf *verts_, uint v_len) { VertBuf *verts = unwrap(verts_); - BLI_assert(verts->data != NULL); /* Only for dynamic data. */ + BLI_assert(verts->data != nullptr); /* Only for dynamic data. */ BLI_assert(v_len <= verts->vertex_alloc); verts->vertex_len = v_len; } @@ -203,7 +203,7 @@ void GPU_vertbuf_attr_set(GPUVertBuf *verts_, uint a_idx, uint v_idx, const void const GPUVertAttr *a = &format->attrs[a_idx]; BLI_assert(v_idx < verts->vertex_alloc); BLI_assert(a_idx < format->attr_len); - BLI_assert(verts->data != NULL); + BLI_assert(verts->data != nullptr); verts->flag |= GPU_VERTBUF_DATA_DIRTY; memcpy(verts->data + a->offset + v_idx * format->stride, data, a->sz); } @@ -225,7 +225,7 @@ void GPU_vertbuf_vert_set(GPUVertBuf *verts_, uint v_idx, const void *data) VertBuf *verts = unwrap(verts_); const GPUVertFormat *format = &verts->format; BLI_assert(v_idx < verts->vertex_alloc); - BLI_assert(verts->data != NULL); + BLI_assert(verts->data != nullptr); verts->flag |= GPU_VERTBUF_DATA_DIRTY; memcpy(verts->data + v_idx * format->stride, data, format->stride); } @@ -236,7 +236,7 @@ void GPU_vertbuf_attr_fill_stride(GPUVertBuf *verts_, uint a_idx, uint stride, c const GPUVertFormat *format = &verts->format; const GPUVertAttr *a = &format->attrs[a_idx]; BLI_assert(a_idx < format->attr_len); - BLI_assert(verts->data != NULL); + BLI_assert(verts->data != nullptr); verts->flag |= GPU_VERTBUF_DATA_DIRTY; const uint vertex_len = verts->vertex_len; @@ -259,7 +259,7 @@ void GPU_vertbuf_attr_get_raw_data(GPUVertBuf *verts_, uint a_idx, GPUVertBufRaw const GPUVertFormat *format = &verts->format; const GPUVertAttr *a = &format->attrs[a_idx]; BLI_assert(a_idx < format->attr_len); - BLI_assert(verts->data != NULL); + BLI_assert(verts->data != nullptr); verts->flag |= GPU_VERTBUF_DATA_DIRTY; verts->flag &= ~GPU_VERTBUF_DATA_UPLOADED; @@ -313,7 +313,7 @@ GPUVertBufStatus GPU_vertbuf_get_status(const GPUVertBuf *verts) return unwrap(verts)->flag; } -uint GPU_vertbuf_get_memory_usage(void) +uint GPU_vertbuf_get_memory_usage() { return VertBuf::memory_usage; } diff --git a/source/blender/gpu/intern/gpu_viewport.c b/source/blender/gpu/intern/gpu_viewport.c index 9063c8bdbce..188c8786665 100644 --- a/source/blender/gpu/intern/gpu_viewport.c +++ b/source/blender/gpu/intern/gpu_viewport.c @@ -1023,6 +1023,9 @@ void GPU_viewport_free(GPUViewport *viewport) } BLI_memblock_destroy(viewport->vmempool.images, NULL); } + if (viewport->vmempool.obattrs_ubo_pool != NULL) { + DRW_uniform_attrs_pool_free(viewport->vmempool.obattrs_ubo_pool); + } for (int i = 0; i < viewport->vmempool.ubo_len; i++) { GPU_uniformbuf_free(viewport->vmempool.matrices_ubo[i]); diff --git a/source/blender/gpu/opengl/gl_backend.cc b/source/blender/gpu/opengl/gl_backend.cc index 46e048d7f7c..b444bd1859d 100644 --- a/source/blender/gpu/opengl/gl_backend.cc +++ b/source/blender/gpu/opengl/gl_backend.cc @@ -38,7 +38,7 @@ namespace blender::gpu { /** \name Platform * \{ */ -void GLBackend::platform_init(void) +void GLBackend::platform_init() { BLI_assert(!GPG.initialized); GPG.initialized = true; @@ -135,7 +135,7 @@ void GLBackend::platform_init(void) GPG.create_gpu_name(vendor, renderer, version); } -void GLBackend::platform_exit(void) +void GLBackend::platform_exit() { BLI_assert(GPG.initialized); GPG.clear(); @@ -147,7 +147,7 @@ void GLBackend::platform_exit(void) /** \name Capabilities * \{ */ -static bool detect_mip_render_workaround(void) +static bool detect_mip_render_workaround() { int cube_size = 2; float clear_color[4] = {1.0f, 0.5f, 0.0f, 0.0f}; @@ -192,7 +192,7 @@ static bool detect_mip_render_workaround(void) return enable_workaround; } -static void detect_workarounds(void) +static void detect_workarounds() { const char *vendor = (const char *)glGetString(GL_VENDOR); const char *renderer = (const char *)glGetString(GL_RENDERER); @@ -376,7 +376,7 @@ bool GLContext::debug_layer_workaround = false; bool GLContext::unused_fb_slot_workaround = false; float GLContext::derivative_signs[2] = {1.0f, 1.0f}; -void GLBackend::capabilities_init(void) +void GLBackend::capabilities_init() { BLI_assert(GLEW_VERSION_3_3); /* Common Capabilities. */ diff --git a/source/blender/gpu/opengl/gl_batch.cc b/source/blender/gpu/opengl/gl_batch.cc index 6f36f128d18..89486b73b05 100644 --- a/source/blender/gpu/opengl/gl_batch.cc +++ b/source/blender/gpu/opengl/gl_batch.cc @@ -50,7 +50,7 @@ using namespace blender::gpu; * TODO(fclem): Could be revisited to avoid so much cross references. * \{ */ -GLVaoCache::GLVaoCache(void) +GLVaoCache::GLVaoCache() { init(); } @@ -60,13 +60,13 @@ GLVaoCache::~GLVaoCache() this->clear(); } -void GLVaoCache::init(void) +void GLVaoCache::init() { - context_ = NULL; - interface_ = NULL; + context_ = nullptr; + interface_ = nullptr; is_dynamic_vao_count = false; for (int i = 0; i < GPU_VAO_STATIC_LEN; i++) { - static_vaos.interfaces[i] = NULL; + static_vaos.interfaces[i] = nullptr; static_vaos.vao_ids[i] = 0; } vao_base_instance_ = 0; @@ -93,7 +93,7 @@ void GLVaoCache::insert(const GLShaderInterface *interface, GLuint vao) else { /* Erase previous entries, they will be added back if drawn again. */ for (int i = 0; i < GPU_VAO_STATIC_LEN; i++) { - if (static_vaos.interfaces[i] != NULL) { + if (static_vaos.interfaces[i] != nullptr) { const_cast<GLShaderInterface *>(static_vaos.interfaces[i])->ref_remove(this); context_->vao_free(static_vaos.vao_ids[i]); } @@ -143,13 +143,13 @@ void GLVaoCache::remove(const GLShaderInterface *interface) if (interfaces[i] == interface) { context_->vao_free(vaos[i]); vaos[i] = 0; - interfaces[i] = NULL; + interfaces[i] = nullptr; break; /* cannot have duplicates */ } } } -void GLVaoCache::clear(void) +void GLVaoCache::clear() { GLContext *ctx = GLContext::get(); const int count = (is_dynamic_vao_count) ? dynamic_vaos.count : GPU_VAO_STATIC_LEN; @@ -157,7 +157,7 @@ void GLVaoCache::clear(void) const GLShaderInterface **interfaces = (is_dynamic_vao_count) ? dynamic_vaos.interfaces : static_vaos.interfaces; /* Early out, nothing to free. */ - if (context_ == NULL) { + if (context_ == nullptr) { return; } @@ -174,7 +174,7 @@ void GLVaoCache::clear(void) } for (int i = 0; i < count; i++) { - if (interfaces[i] != NULL) { + if (interfaces[i] != nullptr) { const_cast<GLShaderInterface *>(interfaces[i])->ref_remove(this); } } @@ -207,13 +207,13 @@ GLuint GLVaoCache::lookup(const GLShaderInterface *interface) /* The GLVaoCache object is only valid for one GLContext. * Reset the cache if trying to draw in another context; */ -void GLVaoCache::context_check(void) +void GLVaoCache::context_check() { GLContext *ctx = GLContext::get(); BLI_assert(ctx); if (context_ != ctx) { - if (context_ != NULL) { + if (context_ != nullptr) { /* IMPORTANT: Trying to draw a batch in multiple different context will trash the VAO cache. * This has major performance impact and should be avoided in most cases. */ context_->vao_cache_unregister(this); @@ -282,7 +282,7 @@ GLuint GLVaoCache::vao_get(GPUBatch *batch) /** \name Creation & Deletion * \{ */ -GLBatch::GLBatch(void) +GLBatch::GLBatch() { } @@ -307,7 +307,7 @@ void GLBatch::bind(int i_first) #if GPU_TRACK_INDEX_RANGE /* Can be removed if GL 4.3 is required. */ - if (!GLContext::fixed_restart_index_support && (elem != NULL)) { + if (!GLContext::fixed_restart_index_support && (elem != nullptr)) { glPrimitiveRestartIndex(this->elem_()->restart_index()); } #endif diff --git a/source/blender/gpu/opengl/gl_context.cc b/source/blender/gpu/opengl/gl_context.cc index 9c98953f469..d766e6f0828 100644 --- a/source/blender/gpu/opengl/gl_context.cc +++ b/source/blender/gpu/opengl/gl_context.cc @@ -121,7 +121,7 @@ GLContext::~GLContext() /** \name Activate / Deactivate context * \{ */ -void GLContext::activate(void) +void GLContext::activate() { /* Make sure no other context is already bound to this thread. */ BLI_assert(is_active_ == false); @@ -160,7 +160,7 @@ void GLContext::activate(void) immActivate(); } -void GLContext::deactivate(void) +void GLContext::deactivate() { immDeactivate(); is_active_ = false; @@ -172,12 +172,12 @@ void GLContext::deactivate(void) /** \name Flush, Finish & sync * \{ */ -void GLContext::flush(void) +void GLContext::flush() { glFlush(); } -void GLContext::finish(void) +void GLContext::finish() { glFinish(); } @@ -191,7 +191,7 @@ void GLContext::finish(void) * In this case we delay the deletion until the context is bound again. * \{ */ -void GLSharedOrphanLists::orphans_clear(void) +void GLSharedOrphanLists::orphans_clear() { /* Check if any context is active on this thread! */ BLI_assert(GLContext::get()); @@ -208,7 +208,7 @@ void GLSharedOrphanLists::orphans_clear(void) lists_mutex.unlock(); }; -void GLContext::orphans_clear(void) +void GLContext::orphans_clear() { /* Check if context has been activated by another thread! */ BLI_assert(this->is_active_on_thread()); diff --git a/source/blender/gpu/opengl/gl_debug.cc b/source/blender/gpu/opengl/gl_debug.cc index 5564cbbabae..4e45ff11fc7 100644 --- a/source/blender/gpu/opengl/gl_debug.cc +++ b/source/blender/gpu/opengl/gl_debug.cc @@ -141,7 +141,7 @@ static void APIENTRY debug_callback(GLenum UNUSED(source), #undef APIENTRY /* This function needs to be called once per context. */ -void init_gl_callbacks(void) +void init_gl_callbacks() { CLOG_ENSURE(&LOG); @@ -152,8 +152,8 @@ void init_gl_callbacks(void) SNPRINTF(msg, format, GLEW_VERSION_4_3 ? "OpenGL 4.3" : "KHR_debug extension"); glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); - glDebugMessageCallback((GLDEBUGPROC)debug_callback, NULL); - glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); + glDebugMessageCallback((GLDEBUGPROC)debug_callback, nullptr); + glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE); glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0, @@ -164,8 +164,8 @@ void init_gl_callbacks(void) else if (GLEW_ARB_debug_output) { SNPRINTF(msg, format, "ARB_debug_output"); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); - glDebugMessageCallbackARB((GLDEBUGPROCARB)debug_callback, NULL); - glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); + glDebugMessageCallbackARB((GLDEBUGPROCARB)debug_callback, nullptr); + glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE); glDebugMessageInsertARB(GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_OTHER_ARB, 0, @@ -213,7 +213,7 @@ void check_gl_error(const char *info) default: char msg[256]; SNPRINTF(msg, "Unknown GL error: %x : %s", error, info); - debug_callback(0, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, 0, msg, NULL); + debug_callback(0, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, 0, msg, nullptr); break; } } @@ -250,7 +250,7 @@ void check_gl_resources(const char *info) const char *sh_name = ctx->shader->name_get(); char msg[256]; SNPRINTF(msg, "Missing UBO bind at slot %d : %s > %s : %s", i, sh_name, ubo_name, info); - debug_callback(0, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, 0, msg, NULL); + debug_callback(0, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, 0, msg, nullptr); } } @@ -262,7 +262,7 @@ void check_gl_resources(const char *info) const char *sh_name = ctx->shader->name_get(); char msg[256]; SNPRINTF(msg, "Missing Texture bind at slot %d : %s > %s : %s", i, sh_name, tex_name, info); - debug_callback(0, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, 0, msg, NULL); + debug_callback(0, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, 0, msg, nullptr); } } @@ -274,14 +274,14 @@ void check_gl_resources(const char *info) const char *sh_name = ctx->shader->name_get(); char msg[256]; SNPRINTF(msg, "Missing Image bind at slot %d : %s > %s : %s", i, sh_name, tex_name, info); - debug_callback(0, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, 0, msg, NULL); + debug_callback(0, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, 0, msg, nullptr); } } } void raise_gl_error(const char *info) { - debug_callback(0, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, 0, info, NULL); + debug_callback(0, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, 0, info, nullptr); } /** \} */ @@ -369,7 +369,7 @@ void GLContext::debug_group_begin(const char *name, int index) } } -void GLContext::debug_group_end(void) +void GLContext::debug_group_end() { if ((G.debug & G_DEBUG_GPU) && (GLEW_VERSION_4_3 || GLEW_KHR_debug)) { glPopDebugGroup(); diff --git a/source/blender/gpu/opengl/gl_debug_layer.cc b/source/blender/gpu/opengl/gl_debug_layer.cc index a4dc4679b7e..188083b0f50 100644 --- a/source/blender/gpu/opengl/gl_debug_layer.cc +++ b/source/blender/gpu/opengl/gl_debug_layer.cc @@ -108,7 +108,7 @@ DEBUG_FUNC_DECLARE(PFNGLUSEPROGRAMPROC, void, glUseProgram, GLuint, program); /* Init a fallback layer (to KHR_debug) that covers only some functions. * We override the functions pointers by our own implementation that just checks glGetError. * Some additional functions (not overridable) are covered inside the header using wrappers. */ -void init_debug_layer(void) +void init_debug_layer() { #define DEBUG_WRAP(function) \ do { \ diff --git a/source/blender/gpu/opengl/gl_drawlist.cc b/source/blender/gpu/opengl/gl_drawlist.cc index 990e1a8014b..aecadc4d14a 100644 --- a/source/blender/gpu/opengl/gl_drawlist.cc +++ b/source/blender/gpu/opengl/gl_drawlist.cc @@ -65,13 +65,13 @@ typedef struct GLDrawCommandIndexed { GLDrawList::GLDrawList(int length) { BLI_assert(length > 0); - batch_ = NULL; + batch_ = nullptr; buffer_id_ = 0; command_len_ = 0; command_offset_ = 0; data_offset_ = 0; data_size_ = 0; - data_ = NULL; + data_ = nullptr; if (GLContext::multi_draw_indirect_support) { /* Alloc the biggest possible command list, which is indexed. */ @@ -88,12 +88,12 @@ GLDrawList::~GLDrawList() GLContext::buf_free(buffer_id_); } -void GLDrawList::init(void) +void GLDrawList::init() { BLI_assert(GLContext::get()); BLI_assert(MDI_ENABLED); - BLI_assert(data_ == NULL); - batch_ = NULL; + BLI_assert(data_ == nullptr); + batch_ = nullptr; command_len_ = 0; if (buffer_id_ == 0) { @@ -105,7 +105,7 @@ void GLDrawList::init(void) glBindBuffer(GL_DRAW_INDIRECT_BUFFER, buffer_id_); /* If buffer is full, orphan buffer data and start fresh. */ // if (command_offset_ >= data_size_) { - glBufferData(GL_DRAW_INDIRECT_BUFFER, buffer_size_, NULL, GL_DYNAMIC_DRAW); + glBufferData(GL_DRAW_INDIRECT_BUFFER, buffer_size_, nullptr, GL_DYNAMIC_DRAW); data_offset_ = 0; // } /* Map the remaining range. */ @@ -123,7 +123,7 @@ void GLDrawList::append(GPUBatch *gpu_batch, int i_first, int i_count) return; } - if (data_ == NULL) { + if (data_ == nullptr) { this->init(); } @@ -169,7 +169,7 @@ void GLDrawList::append(GPUBatch *gpu_batch, int i_first, int i_count) } } -void GLDrawList::submit(void) +void GLDrawList::submit() { if (command_len_ == 0) { return; @@ -177,7 +177,7 @@ void GLDrawList::submit(void) /* Something's wrong if we get here without MDI support. */ BLI_assert(MDI_ENABLED); BLI_assert(data_); - BLI_assert(GLContext::get()->shader != NULL); + BLI_assert(GLContext::get()->shader != nullptr); /* Only do multi-draw indirect if doing more than 2 drawcall. This avoids the overhead of * buffer mapping if scene is not very instance friendly. BUT we also need to take into @@ -190,7 +190,7 @@ void GLDrawList::submit(void) glBindBuffer(GL_DRAW_INDIRECT_BUFFER, buffer_id_); glFlushMappedBufferRange(GL_DRAW_INDIRECT_BUFFER, 0, command_offset_); glUnmapBuffer(GL_DRAW_INDIRECT_BUFFER); - data_ = NULL; /* Unmapped */ + data_ = nullptr; /* Unmapped */ data_offset_ += command_offset_; batch_->bind(0); @@ -227,7 +227,7 @@ void GLDrawList::submit(void) /* Do not submit this buffer again. */ command_len_ = 0; /* Avoid keeping reference to the batch. */ - batch_ = NULL; + batch_ = nullptr; } /** \} */ diff --git a/source/blender/gpu/opengl/gl_framebuffer.cc b/source/blender/gpu/opengl/gl_framebuffer.cc index a180aa270b0..cbb332388dc 100644 --- a/source/blender/gpu/opengl/gl_framebuffer.cc +++ b/source/blender/gpu/opengl/gl_framebuffer.cc @@ -72,7 +72,7 @@ GLFrameBuffer::GLFrameBuffer( GLFrameBuffer::~GLFrameBuffer() { - if (context_ == NULL) { + if (context_ == nullptr) { return; } @@ -92,7 +92,7 @@ GLFrameBuffer::~GLFrameBuffer() } } -void GLFrameBuffer::init(void) +void GLFrameBuffer::init() { context_ = GLContext::get(); state_manager_ = static_cast<GLStateManager *>(context_->state_manager); @@ -154,7 +154,7 @@ bool GLFrameBuffer::check(char err_out[256]) return false; } -void GLFrameBuffer::update_attachments(void) +void GLFrameBuffer::update_attachments() { /* Default frame-buffers cannot have attachments. */ BLI_assert(immutable_ == false); @@ -176,7 +176,7 @@ void GLFrameBuffer::update_attachments(void) first_attachment = (attach.tex) ? type : first_attachment; } - if (attach.tex == NULL) { + if (attach.tex == nullptr) { glFramebufferTexture(GL_FRAMEBUFFER, gl_attachment, 0, 0); continue; } @@ -208,7 +208,7 @@ void GLFrameBuffer::update_attachments(void) for (int i = ARRAY_SIZE(gl_attachments_) - 1; i >= 0; --i) { GPUAttachmentType type = GPU_FB_COLOR_ATTACHMENT0 + i; GPUAttachment &attach = attachments_[type]; - if (attach.tex != NULL) { + if (attach.tex != nullptr) { gl_tex = static_cast<GLTexture *>(unwrap(attach.tex))->tex_id_; } else if (gl_tex != 0) { @@ -232,11 +232,11 @@ void GLFrameBuffer::update_attachments(void) glDrawBuffers(ARRAY_SIZE(gl_attachments_), gl_attachments_); if (G.debug & G_DEBUG_GPU) { - BLI_assert(this->check(NULL)); + BLI_assert(this->check(nullptr)); } } -void GLFrameBuffer::apply_state(void) +void GLFrameBuffer::apply_state() { if (dirty_state_ == false) { return; @@ -410,7 +410,7 @@ void GLFrameBuffer::clear_multi(const float (*clear_cols)[4]) * TODO(fclem): fix this insecurity? */ int type = GPU_FB_COLOR_ATTACHMENT0; for (int i = 0; type < GPU_FB_MAX_ATTACHMENT; i++, type++) { - if (attachments_[type].tex != NULL) { + if (attachments_[type].tex != nullptr) { this->clear_attachment(GPU_FB_COLOR_ATTACHMENT0 + i, GPU_DATA_FLOAT, clear_cols[i]); } } diff --git a/source/blender/gpu/opengl/gl_framebuffer.hh b/source/blender/gpu/opengl/gl_framebuffer.hh index cf159a60b01..1de366fc844 100644 --- a/source/blender/gpu/opengl/gl_framebuffer.hh +++ b/source/blender/gpu/opengl/gl_framebuffer.hh @@ -67,11 +67,11 @@ class GLFrameBuffer : public FrameBuffer { /** * Special frame-buffer encapsulating internal window frame-buffer. * (i.e.: #GL_FRONT_LEFT, #GL_BACK_RIGHT, ...) - * \param ctx: context the handle is from. - * \param target: the internal GL name (i.e: #GL_BACK_LEFT). - * \param fbo: the (optional) already created object for some implementation. Default is 0. - * \param w: buffer width. - * \param h: buffer height. + * \param ctx: Context the handle is from. + * \param target: The internal GL name (i.e: #GL_BACK_LEFT). + * \param fbo: The (optional) already created object for some implementation. Default is 0. + * \param w: Buffer width. + * \param h: Buffer height. **/ GLFrameBuffer(const char *name, GLContext *ctx, GLenum target, GLuint fbo, int w, int h); diff --git a/source/blender/gpu/opengl/gl_immediate.cc b/source/blender/gpu/opengl/gl_immediate.cc index b71f8766dbb..63e3162944d 100644 --- a/source/blender/gpu/opengl/gl_immediate.cc +++ b/source/blender/gpu/opengl/gl_immediate.cc @@ -50,12 +50,12 @@ GLImmediate::GLImmediate() buffer.buffer_size = DEFAULT_INTERNAL_BUFFER_SIZE; glGenBuffers(1, &buffer.vbo_id); glBindBuffer(GL_ARRAY_BUFFER, buffer.vbo_id); - glBufferData(GL_ARRAY_BUFFER, buffer.buffer_size, NULL, GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, buffer.buffer_size, nullptr, GL_DYNAMIC_DRAW); buffer_strict.buffer_size = DEFAULT_INTERNAL_BUFFER_SIZE; glGenBuffers(1, &buffer_strict.vbo_id); glBindBuffer(GL_ARRAY_BUFFER, buffer_strict.vbo_id); - glBufferData(GL_ARRAY_BUFFER, buffer_strict.buffer_size, NULL, GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, buffer_strict.buffer_size, nullptr, GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); @@ -112,7 +112,7 @@ uchar *GLImmediate::begin() } else { /* orphan this buffer & start with a fresh one */ - glBufferData(GL_ARRAY_BUFFER, buffer_size(), NULL, GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, buffer_size(), nullptr, GL_DYNAMIC_DRAW); buffer_offset() = 0; } @@ -129,13 +129,13 @@ uchar *GLImmediate::begin() access |= GL_MAP_FLUSH_EXPLICIT_BIT; } void *data = glMapBufferRange(GL_ARRAY_BUFFER, buffer_offset(), bytes_needed, access); - BLI_assert(data != NULL); + BLI_assert(data != nullptr); bytes_mapped_ = bytes_needed; return (uchar *)data; } -void GLImmediate::end(void) +void GLImmediate::end() { BLI_assert(prim_type != GPU_PRIM_NONE); /* make sure we're between a Begin/End pair */ diff --git a/source/blender/gpu/opengl/gl_index_buffer.cc b/source/blender/gpu/opengl/gl_index_buffer.cc index 0096a9a500f..e2c18c5d0b9 100644 --- a/source/blender/gpu/opengl/gl_index_buffer.cc +++ b/source/blender/gpu/opengl/gl_index_buffer.cc @@ -33,7 +33,7 @@ GLIndexBuf::~GLIndexBuf() GLContext::buf_free(ibo_id_); } -void GLIndexBuf::bind(void) +void GLIndexBuf::bind() { if (is_subrange_) { static_cast<GLIndexBuf *>(src_)->bind(); diff --git a/source/blender/gpu/opengl/gl_query.cc b/source/blender/gpu/opengl/gl_query.cc index 6da5cacfcb2..8a42719c665 100644 --- a/source/blender/gpu/opengl/gl_query.cc +++ b/source/blender/gpu/opengl/gl_query.cc @@ -48,7 +48,7 @@ void GLQueryPool::reset(GPUQueryType type) } #endif -void GLQueryPool::begin_query(void) +void GLQueryPool::begin_query() { /* TODO add assert about expected usage. */ while (query_issued_ >= query_ids_.size()) { @@ -59,7 +59,7 @@ void GLQueryPool::begin_query(void) glBeginQuery(gl_type_, query_ids_[query_issued_++]); } -void GLQueryPool::end_query(void) +void GLQueryPool::end_query() { /* TODO add assert about expected usage. */ glEndQuery(gl_type_); diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc index 193e4ee8a70..cc5f83228d6 100644 --- a/source/blender/gpu/opengl/gl_shader.cc +++ b/source/blender/gpu/opengl/gl_shader.cc @@ -53,7 +53,7 @@ GLShader::GLShader(const char *name) : Shader(name) debug::object_label(GL_PROGRAM, shader_program_, name); } -GLShader::~GLShader(void) +GLShader::~GLShader() { #if 0 /* Would be nice to have, but for now the Deferred compilation \ * does not have a GPUContext. */ @@ -72,7 +72,7 @@ GLShader::~GLShader(void) /** \name Shader stage creation * \{ */ -char *GLShader::glsl_patch_get(void) +char *GLShader::glsl_patch_get() { /** Used for shader patching. Init once. */ static char patch[512] = "\0"; @@ -123,14 +123,14 @@ GLuint GLShader::create_shader_stage(GLenum gl_stage, MutableSpan<const char *> /* Patch the shader code using the first source slot. */ sources[0] = glsl_patch_get(); - glShaderSource(shader, sources.size(), sources.data(), NULL); + glShaderSource(shader, sources.size(), sources.data(), nullptr); glCompileShader(shader); GLint status; glGetShaderiv(shader, GL_COMPILE_STATUS, &status); if (!status || (G.debug & G_DEBUG_GPU)) { char log[5000] = ""; - glGetShaderInfoLog(shader, sizeof(log), NULL, log); + glGetShaderInfoLog(shader, sizeof(log), nullptr, log); if (log[0] != '\0') { switch (gl_stage) { case GL_VERTEX_SHADER: @@ -172,7 +172,7 @@ void GLShader::fragment_shader_from_glsl(MutableSpan<const char *> sources) frag_shader_ = this->create_shader_stage(GL_FRAGMENT_SHADER, sources); } -bool GLShader::finalize(void) +bool GLShader::finalize() { if (compilation_failed_) { return false; @@ -184,7 +184,7 @@ bool GLShader::finalize(void) glGetProgramiv(shader_program_, GL_LINK_STATUS, &status); if (!status) { char log[5000]; - glGetProgramInfoLog(shader_program_, sizeof(log), NULL, log); + glGetProgramInfoLog(shader_program_, sizeof(log), nullptr, log); Span<const char *> sources; this->print_log(sources, log, "Linking", true); return false; @@ -201,13 +201,13 @@ bool GLShader::finalize(void) /** \name Binding * \{ */ -void GLShader::bind(void) +void GLShader::bind() { BLI_assert(shader_program_ != 0); glUseProgram(shader_program_); } -void GLShader::unbind(void) +void GLShader::unbind() { #ifndef NDEBUG glUseProgram(0); @@ -259,7 +259,7 @@ bool GLShader::transform_feedback_enable(GPUVertBuf *buf_) return true; } -void GLShader::transform_feedback_disable(void) +void GLShader::transform_feedback_disable() { glEndTransformFeedback(); } @@ -409,7 +409,7 @@ void GLShader::vertformat_from_shader(GPUVertFormat *format) const char name[256]; GLenum gl_type; GLint size; - glGetActiveAttrib(shader_program_, i, sizeof(name), NULL, &size, &gl_type, name); + glGetActiveAttrib(shader_program_, i, sizeof(name), nullptr, &size, &gl_type, name); /* Ignore OpenGL names like `gl_BaseInstanceARB`, `gl_InstanceID` and `gl_VertexID`. */ if (glGetAttribLocation(shader_program_, name) == -1) { diff --git a/source/blender/gpu/opengl/gl_shader_interface.cc b/source/blender/gpu/opengl/gl_shader_interface.cc index 2d55c222e9c..9533639b133 100644 --- a/source/blender/gpu/opengl/gl_shader_interface.cc +++ b/source/blender/gpu/opengl/gl_shader_interface.cc @@ -267,7 +267,7 @@ GLShaderInterface::GLShaderInterface(GLuint program) for (int32_t u_int = 0; u_int < GPU_NUM_UNIFORM_BLOCKS; u_int++) { GPUUniformBlockBuiltin u = static_cast<GPUUniformBlockBuiltin>(u_int); const ShaderInput *block = this->ubo_get(builtin_uniform_block_name(u)); - builtin_blocks_[u] = (block != NULL) ? block->binding : -1; + builtin_blocks_[u] = (block != nullptr) ? block->binding : -1; } MEM_freeN(uniforms_from_blocks); @@ -285,7 +285,7 @@ GLShaderInterface::GLShaderInterface(GLuint program) GLShaderInterface::~GLShaderInterface() { for (auto *ref : refs_) { - if (ref != NULL) { + if (ref != nullptr) { ref->remove(this); } } diff --git a/source/blender/gpu/opengl/gl_state.cc b/source/blender/gpu/opengl/gl_state.cc index 5483f889a8a..c5b5dd3efd2 100644 --- a/source/blender/gpu/opengl/gl_state.cc +++ b/source/blender/gpu/opengl/gl_state.cc @@ -42,7 +42,7 @@ namespace blender::gpu { /** \name GLStateManager * \{ */ -GLStateManager::GLStateManager(void) : StateManager() +GLStateManager::GLStateManager() { /* Set other states that never change. */ glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); @@ -71,7 +71,7 @@ GLStateManager::GLStateManager(void) : StateManager() set_mutable_state(mutable_state); } -void GLStateManager::apply_state(void) +void GLStateManager::apply_state() { if (!this->use_bgl) { this->set_state(this->state); @@ -84,7 +84,7 @@ void GLStateManager::apply_state(void) }; /* Will set all the states regardless of the current ones. */ -void GLStateManager::force_state(void) +void GLStateManager::force_state() { /* Little exception for clip distances since they need to keep the old count correct. */ uint32_t clip_distances = current_.clip_distances; @@ -511,7 +511,7 @@ void GLStateManager::texture_unbind(Texture *tex_) tex->is_bound_ = false; } -void GLStateManager::texture_unbind_all(void) +void GLStateManager::texture_unbind_all() { for (int i = 0; i < ARRAY_SIZE(textures_); i++) { if (textures_[i] != 0) { @@ -523,7 +523,7 @@ void GLStateManager::texture_unbind_all(void) this->texture_bind_apply(); } -void GLStateManager::texture_bind_apply(void) +void GLStateManager::texture_bind_apply() { if (dirty_texture_binds_ == 0) { return; @@ -555,7 +555,7 @@ void GLStateManager::texture_unpack_row_length_set(uint len) glPixelStorei(GL_UNPACK_ROW_LENGTH, len); } -uint64_t GLStateManager::bound_texture_slots(void) +uint64_t GLStateManager::bound_texture_slots() { uint64_t bound_slots = 0; for (int i = 0; i < ARRAY_SIZE(textures_); i++) { @@ -603,7 +603,7 @@ void GLStateManager::image_unbind(Texture *tex_) tex->is_bound_ = false; } -void GLStateManager::image_unbind_all(void) +void GLStateManager::image_unbind_all() { for (int i = 0; i < ARRAY_SIZE(images_); i++) { if (images_[i] != 0) { @@ -614,7 +614,7 @@ void GLStateManager::image_unbind_all(void) this->image_bind_apply(); } -void GLStateManager::image_bind_apply(void) +void GLStateManager::image_bind_apply() { if (dirty_image_binds_ == 0) { return; @@ -638,7 +638,7 @@ void GLStateManager::image_bind_apply(void) } } -uint8_t GLStateManager::bound_image_slots(void) +uint8_t GLStateManager::bound_image_slots() { uint8_t bound_slots = 0; for (int i = 0; i < ARRAY_SIZE(images_); i++) { diff --git a/source/blender/gpu/opengl/gl_texture.cc b/source/blender/gpu/opengl/gl_texture.cc index 070a86509ff..4f990b77bd0 100644 --- a/source/blender/gpu/opengl/gl_texture.cc +++ b/source/blender/gpu/opengl/gl_texture.cc @@ -44,7 +44,7 @@ namespace blender::gpu { GLTexture::GLTexture(const char *name) : Texture(name) { - BLI_assert(GLContext::get() != NULL); + BLI_assert(GLContext::get() != nullptr); glGenTextures(1, &tex_id_); } @@ -55,7 +55,7 @@ GLTexture::~GLTexture() GPU_framebuffer_free(framebuffer_); } GLContext *ctx = GLContext::get(); - if (ctx != NULL && is_bound_) { + if (ctx != nullptr && is_bound_) { /* This avoid errors when the texture is still inside the bound texture array. */ ctx->state_manager->texture_unbind(this); } @@ -63,7 +63,7 @@ GLTexture::~GLTexture() } /* Return true on success. */ -bool GLTexture::init_internal(void) +bool GLTexture::init_internal() { if ((format_ == GPU_DEPTH24_STENCIL8) && GPU_depth_blitting_workaround()) { /* MacOS + Radeon Pro fails to blit depth on GPU_DEPTH24_STENCIL8 @@ -148,7 +148,7 @@ void GLTexture::ensure_mipmaps(int miplvl) if (type_ == GPU_TEXTURE_CUBE) { for (int i = 0; i < d; i++) { GLenum target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i; - glTexImage2D(target, mip, internal_format, w, h, 0, gl_format, gl_type, NULL); + glTexImage2D(target, mip, internal_format, w, h, 0, gl_format, gl_type, nullptr); } } else if (format_flag_ & GPU_FORMAT_COMPRESSED) { @@ -156,13 +156,13 @@ void GLTexture::ensure_mipmaps(int miplvl) switch (dimensions) { default: case 1: - glCompressedTexImage1D(target_, mip, internal_format, w, 0, size, NULL); + glCompressedTexImage1D(target_, mip, internal_format, w, 0, size, nullptr); break; case 2: - glCompressedTexImage2D(target_, mip, internal_format, w, h, 0, size, NULL); + glCompressedTexImage2D(target_, mip, internal_format, w, h, 0, size, nullptr); break; case 3: - glCompressedTexImage3D(target_, mip, internal_format, w, h, d, 0, size, NULL); + glCompressedTexImage3D(target_, mip, internal_format, w, h, d, 0, size, nullptr); break; } } @@ -170,13 +170,13 @@ void GLTexture::ensure_mipmaps(int miplvl) switch (dimensions) { default: case 1: - glTexImage1D(target_, mip, internal_format, w, 0, gl_format, gl_type, NULL); + glTexImage1D(target_, mip, internal_format, w, 0, gl_format, gl_type, nullptr); break; case 2: - glTexImage2D(target_, mip, internal_format, w, h, 0, gl_format, gl_type, NULL); + glTexImage2D(target_, mip, internal_format, w, h, 0, gl_format, gl_type, nullptr); break; case 3: - glTexImage3D(target_, mip, internal_format, w, h, d, 0, gl_format, gl_type, NULL); + glTexImage3D(target_, mip, internal_format, w, h, d, 0, gl_format, gl_type, nullptr); break; } } @@ -231,7 +231,7 @@ void GLTexture::update_sub( int mip, int offset[3], int extent[3], eGPUDataFormat type, const void *data) { BLI_assert(validate_data_format(format_, type)); - BLI_assert(data != NULL); + BLI_assert(data != nullptr); this->ensure_mipmaps(mip); @@ -294,7 +294,7 @@ void GLTexture::update_sub( * WARNING: Depth textures are not populated but they have their mips correctly defined. * WARNING: This resets the mipmap range. */ -void GLTexture::generate_mipmap(void) +void GLTexture::generate_mipmap() { this->ensure_mipmaps(9999); /* Some drivers have bugs when using glGenerateMipmap with depth textures (see T56789). @@ -440,7 +440,7 @@ void GLTexture::mip_range_set(int min, int max) } } -struct GPUFrameBuffer *GLTexture::framebuffer_get(void) +struct GPUFrameBuffer *GLTexture::framebuffer_get() { if (framebuffer_) { return framebuffer_; @@ -461,7 +461,7 @@ struct GPUFrameBuffer *GLTexture::framebuffer_get(void) GLuint GLTexture::samplers_[GPU_SAMPLER_MAX] = {0}; -void GLTexture::samplers_init(void) +void GLTexture::samplers_init() { glGenSamplers(GPU_SAMPLER_MAX, samplers_); for (int i = 0; i <= GPU_SAMPLER_ICON - 1; i++) { @@ -517,7 +517,7 @@ void GLTexture::samplers_init(void) debug::object_label(GL_SAMPLER, icon_sampler, "icons"); } -void GLTexture::samplers_update(void) +void GLTexture::samplers_update() { if (!GLContext::texture_filter_anisotropic_support) { return; @@ -536,7 +536,7 @@ void GLTexture::samplers_update(void) } } -void GLTexture::samplers_free(void) +void GLTexture::samplers_free() { glDeleteSamplers(GPU_SAMPLER_MAX, samplers_); } @@ -617,13 +617,13 @@ bool GLTexture::proxy_check(int mip) switch (dimensions) { default: case 1: - glCompressedTexImage1D(gl_proxy, mip, size[0], 0, gl_format, img_size, NULL); + glCompressedTexImage1D(gl_proxy, mip, size[0], 0, gl_format, img_size, nullptr); break; case 2: - glCompressedTexImage2D(gl_proxy, mip, UNPACK2(size), 0, gl_format, img_size, NULL); + glCompressedTexImage2D(gl_proxy, mip, UNPACK2(size), 0, gl_format, img_size, nullptr); break; case 3: - glCompressedTexImage3D(gl_proxy, mip, UNPACK3(size), 0, gl_format, img_size, NULL); + glCompressedTexImage3D(gl_proxy, mip, UNPACK3(size), 0, gl_format, img_size, nullptr); break; } } @@ -631,13 +631,15 @@ bool GLTexture::proxy_check(int mip) switch (dimensions) { default: case 1: - glTexImage1D(gl_proxy, mip, internal_format, size[0], 0, gl_format, gl_type, NULL); + glTexImage1D(gl_proxy, mip, internal_format, size[0], 0, gl_format, gl_type, nullptr); break; case 2: - glTexImage2D(gl_proxy, mip, internal_format, UNPACK2(size), 0, gl_format, gl_type, NULL); + glTexImage2D( + gl_proxy, mip, internal_format, UNPACK2(size), 0, gl_format, gl_type, nullptr); break; case 3: - glTexImage3D(gl_proxy, mip, internal_format, UNPACK3(size), 0, gl_format, gl_type, NULL); + glTexImage3D( + gl_proxy, mip, internal_format, UNPACK3(size), 0, gl_format, gl_type, nullptr); break; } } @@ -649,7 +651,7 @@ bool GLTexture::proxy_check(int mip) /** \} */ -void GLTexture::check_feedback_loop(void) +void GLTexture::check_feedback_loop() { /* Recursive down sample workaround break this check. * See #recursive_downsample() for more information. */ @@ -679,7 +681,7 @@ void GLTexture::check_feedback_loop(void) } /* TODO(fclem): Legacy. Should be removed at some point. */ -uint GLTexture::gl_bindcode_get(void) const +uint GLTexture::gl_bindcode_get() const { return tex_id_; } diff --git a/source/blender/gpu/opengl/gl_uniform_buffer.cc b/source/blender/gpu/opengl/gl_uniform_buffer.cc index e6aaddf75d3..ecb233f2e5a 100644 --- a/source/blender/gpu/opengl/gl_uniform_buffer.cc +++ b/source/blender/gpu/opengl/gl_uniform_buffer.cc @@ -55,13 +55,13 @@ GLUniformBuf::~GLUniformBuf() /** \name Data upload / update * \{ */ -void GLUniformBuf::init(void) +void GLUniformBuf::init() { BLI_assert(GLContext::get()); glGenBuffers(1, &ubo_id_); glBindBuffer(GL_UNIFORM_BUFFER, ubo_id_); - glBufferData(GL_UNIFORM_BUFFER, size_in_bytes_, NULL, GL_DYNAMIC_DRAW); + glBufferData(GL_UNIFORM_BUFFER, size_in_bytes_, nullptr, GL_DYNAMIC_DRAW); debug::object_label(GL_UNIFORM_BUFFER, ubo_id_, name_); } @@ -97,7 +97,7 @@ void GLUniformBuf::bind(int slot) this->init(); } - if (data_ != NULL) { + if (data_ != nullptr) { this->update(data_); MEM_SAFE_FREE(data_); } @@ -111,7 +111,7 @@ void GLUniformBuf::bind(int slot) #endif } -void GLUniformBuf::unbind(void) +void GLUniformBuf::unbind() { #ifdef DEBUG /* NOTE: This only unbinds the last bound slot. */ diff --git a/source/blender/gpu/opengl/gl_vertex_array.cc b/source/blender/gpu/opengl/gl_vertex_array.cc index ed6699e51f3..ea2770f099d 100644 --- a/source/blender/gpu/opengl/gl_vertex_array.cc +++ b/source/blender/gpu/opengl/gl_vertex_array.cc @@ -70,13 +70,13 @@ static uint16_t vbo_bind(const ShaderInterface *interface, const char *name = GPU_vertformat_attr_name_get(format, a, n_idx); const ShaderInput *input = interface->attr_get(name); - if (input == NULL) { + if (input == nullptr) { continue; } enabled_attrib |= (1 << input->location); - if (a->comp_len == 16 || a->comp_len == 12 || a->comp_len == 8) { + if (ELEM(a->comp_len, 16, 12, 8)) { BLI_assert(a->fetch_mode == GPU_FETCH_FLOAT); BLI_assert(a->comp_type == GPU_COMP_F32); for (int i = 0; i < a->comp_len / 4; i++) { diff --git a/source/blender/gpu/opengl/gl_vertex_buffer.cc b/source/blender/gpu/opengl/gl_vertex_buffer.cc index c6efe577e15..a56d5269fde 100644 --- a/source/blender/gpu/opengl/gl_vertex_buffer.cc +++ b/source/blender/gpu/opengl/gl_vertex_buffer.cc @@ -27,19 +27,19 @@ namespace blender::gpu { -void GLVertBuf::acquire_data(void) +void GLVertBuf::acquire_data() { /* Discard previous data if any. */ MEM_SAFE_FREE(data); data = (uchar *)MEM_mallocN(sizeof(uchar) * this->size_alloc_get(), __func__); } -void GLVertBuf::resize_data(void) +void GLVertBuf::resize_data() { data = (uchar *)MEM_reallocN(data, sizeof(uchar) * this->size_alloc_get()); } -void GLVertBuf::release_data(void) +void GLVertBuf::release_data() { if (vbo_id_ != 0) { GLContext::buf_free(vbo_id_); @@ -52,7 +52,7 @@ void GLVertBuf::release_data(void) void GLVertBuf::duplicate_data(VertBuf *dst_) { - BLI_assert(GLContext::get() != NULL); + BLI_assert(GLContext::get() != nullptr); GLVertBuf *src = this; GLVertBuf *dst = static_cast<GLVertBuf *>(dst_); @@ -61,7 +61,7 @@ void GLVertBuf::duplicate_data(VertBuf *dst_) glGenBuffers(1, &dst->vbo_id_); glBindBuffer(GL_COPY_WRITE_BUFFER, dst->vbo_id_); - glBufferData(GL_COPY_WRITE_BUFFER, dst->vbo_size_, NULL, to_gl(dst->usage_)); + glBufferData(GL_COPY_WRITE_BUFFER, dst->vbo_size_, nullptr, to_gl(dst->usage_)); glBindBuffer(GL_COPY_READ_BUFFER, src->vbo_id_); @@ -75,14 +75,14 @@ void GLVertBuf::duplicate_data(VertBuf *dst_) } } -void GLVertBuf::upload_data(void) +void GLVertBuf::upload_data() { this->bind(); } -void GLVertBuf::bind(void) +void GLVertBuf::bind() { - BLI_assert(GLContext::get() != NULL); + BLI_assert(GLContext::get() != nullptr); if (vbo_id_ == 0) { glGenBuffers(1, &vbo_id_); @@ -93,7 +93,7 @@ void GLVertBuf::bind(void) if (flag & GPU_VERTBUF_DATA_DIRTY) { vbo_size_ = this->size_used_get(); /* Orphan the vbo to avoid sync then upload data. */ - glBufferData(GL_ARRAY_BUFFER, vbo_size_, NULL, to_gl(usage_)); + glBufferData(GL_ARRAY_BUFFER, vbo_size_, nullptr, to_gl(usage_)); glBufferSubData(GL_ARRAY_BUFFER, 0, vbo_size_, data); memory_usage += vbo_size_; diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_attribute.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_attribute.glsl index 10e1b4563bc..faf37db3ea6 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_attribute.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_attribute.glsl @@ -1,6 +1,8 @@ -void node_attribute(vec3 attr, out vec4 outcol, out vec3 outvec, out float outf) +void node_attribute( + vec4 attr, out vec4 outcol, out vec3 outvec, out float outf, out float outalpha) { - outcol = vec4(attr, 1.0); - outvec = attr; - outf = avg(attr); + outcol = vec4(attr.xyz, 1.0); + outvec = attr.xyz; + outf = avg(attr.xyz); + outalpha = attr.w; } |