]> git.tdb.fi Git - libs/gl.git/commitdiff
Use emplace_back return value from C++17 for shorter code
authorMikko Rasa <tdb@tdb.fi>
Tue, 12 Dec 2023 22:37:43 +0000 (00:37 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 12 Dec 2023 22:37:43 +0000 (00:37 +0200)
14 files changed:
Build
source/backends/opengl/program_backend.cpp
source/backends/vulkan/memoryallocator.cpp
source/backends/vulkan/program_backend.cpp
source/backends/vulkan/structurebuilder.cpp
source/backends/vulkan/synchronizer.cpp
source/backends/vulkan/windowview_backend.cpp
source/core/module.cpp
source/core/program.cpp
source/effects/shadowmap.cpp
source/glsl/optimize.cpp
source/render/instancearray.cpp
source/render/renderer.cpp
source/render/sequence.cpp

diff --git a/Build b/Build
index 9de35f311ef3f75142ed31d6d0a60db1c1f5f850..469710fc642b6f97e8c8811325d1d37bbcbe3dd7 100644 (file)
--- a/Build
+++ b/Build
@@ -42,7 +42,7 @@ package "mspgl"
 
        build_info
        {
-               standard CXX "c++14";
+               standard CXX "c++17";
        };
 
        generate "RES"
index 732967d28ea011529dbc99f4388ec861dc1acde1..994373f3f0268d97267559e8e0f498c12c64c227 100644 (file)
@@ -339,8 +339,7 @@ void OpenGLProgram::query_uniforms()
                        if(len>3 && !strcmp(name+len-3, "[0]"))
                                name[len-3] = 0;
 
-                       rd.uniforms.emplace_back();
-                       ReflectData::UniformInfo &info = rd.uniforms.back();
+                       ReflectData::UniformInfo &info = rd.uniforms.emplace_back();
                        info.tag = info.name = name;
                        info.array_size = size;
                        info.type = from_gl_type(type);
@@ -360,8 +359,7 @@ void OpenGLProgram::query_uniforms()
                query_uniform_blocks(uniforms_by_index);
        }
 
-       rd.blocks.emplace_back();
-       ReflectData::BlockInfo &default_block = rd.blocks.back();
+       ReflectData::BlockInfo &default_block = rd.blocks.emplace_back();
 
        for(ReflectData::UniformInfo &u: rd.uniforms)
                if(!u.block)
@@ -391,8 +389,7 @@ void OpenGLProgram::query_uniform_blocks(const vector<ReflectData::UniformInfo *
        rd.blocks.reserve(count+1);
        for(unsigned i=0; i<count; ++i)
        {
-               rd.blocks.emplace_back();
-               ReflectData::BlockInfo &info = rd.blocks.back();
+               ReflectData::BlockInfo &info = rd.blocks.emplace_back();
 
                char name[128];
                int len;
@@ -472,8 +469,7 @@ void OpenGLProgram::query_attributes()
                        if(len>3 && !strcmp(name+len-3, "[0]"))
                                name[len-3] = 0;
 
-                       rd.attributes.emplace_back();
-                       ReflectData::AttributeInfo &info = rd.attributes.back();
+                       ReflectData::AttributeInfo &info = rd.attributes.emplace_back();
                        info.name = name;
                        info.location = glGetAttribLocation(id, name);
                        info.array_size = size;
@@ -493,8 +489,7 @@ void OpenGLProgram::query_storage_blocks()
        rd.blocks.reserve(rd.blocks.size()+count);
        for(unsigned i=0; i<count; ++i)
        {
-               rd.blocks.emplace_back();
-               ReflectData::BlockInfo &info = rd.blocks.back();
+               ReflectData::BlockInfo &info = rd.blocks.emplace_back();
 
                char name[128];
                int len;
index 24ffa7c89c2c85f0f3d6e129d1d610247ce0a1a5..046fc2fcd9592d243c2b01c7bdacd4b53149fc48 100644 (file)
@@ -206,9 +206,8 @@ unsigned MemoryAllocator::allocate(size_t size, size_t align, unsigned type_bits
 
 unsigned MemoryAllocator::split_block(unsigned index, size_t head_size)
 {
-       blocks.emplace_back();
+       Block &tail = blocks.emplace_back();
        Block &block = blocks[index];
-       Block &tail = blocks.back();
        unsigned tail_index = blocks.size()-1;
 
        tail.region = block.region;
index 2ee660cee1b41c40309eeea743fa02c091b43755..c422dc226f364506074caf5ec1455b0d65767a2a 100644 (file)
@@ -123,8 +123,7 @@ void VulkanProgram::finalize_uniforms()
                for(const ReflectData::BlockInfo &b: rd.blocks)
                        if(b.bind_point>=0 && static_cast<unsigned>(b.bind_point>>20)==j)
                        {
-                               bindings.emplace_back();
-                               VkDescriptorSetLayoutBinding &binding = bindings.back();
+                               VkDescriptorSetLayoutBinding &binding = bindings.emplace_back();
                                binding.binding = b.bind_point&0xFFFFF;
                                if(b.is_storage())
                                        binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
@@ -138,8 +137,7 @@ void VulkanProgram::finalize_uniforms()
                for(const ReflectData::UniformInfo &u: rd.uniforms)
                        if(u.binding>=0 && static_cast<unsigned>(u.binding>>20)==j && is_image(u.type))
                        {
-                               bindings.emplace_back();
-                               VkDescriptorSetLayoutBinding &binding = bindings.back();
+                               VkDescriptorSetLayoutBinding &binding = bindings.emplace_back();
                                binding.binding = u.binding&0xFFFFF;
                                if(u.is_storage_image())
                                        binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
index dd3d27ff18e521a67d5d818f7d6d26c4e354e79c..76b3cf2e1a54342254163da46bd6084a15938e8e 100644 (file)
@@ -18,8 +18,7 @@ void *const &StructureBuilder::add(std::size_t size, std::size_t align)
        if(parts.size()>=parts.capacity())
                throw invalid_operation("StructureBuilder::add");
 
-       parts.emplace_back();
-       Part &part = parts.back();
+       Part &part = parts.emplace_back();
        part.offset = storage.size()+align-1;
        part.offset -= part.offset%align;
 
index 06bb470192ea7e435f9efae92cd0cbec30f34adb..899e3e5a22fa0c9820e1c575912720e8887f347d 100644 (file)
@@ -141,8 +141,7 @@ void Synchronizer::barrier(const VulkanCommandRecorder &vkCmd)
                if(b.pending_write==b.was_written)
                        continue;
 
-               buffer_barriers.emplace_back(VkBufferMemoryBarrier{ });
-               VkBufferMemoryBarrier &barrier = buffer_barriers.back();
+               VkBufferMemoryBarrier &barrier = buffer_barriers.emplace_back(VkBufferMemoryBarrier{ });
 
                barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
                barrier.srcAccessMask = (b.was_written ? VK_ACCESS_MEMORY_WRITE_BIT : 0);
@@ -169,8 +168,7 @@ void Synchronizer::barrier(const VulkanCommandRecorder &vkCmd)
                if(i.level==-2 || i.pending_layout==i.current_layout)
                        continue;
 
-               image_barriers.emplace_back(VkImageMemoryBarrier{ });
-               VkImageMemoryBarrier &barrier = image_barriers.back();
+               VkImageMemoryBarrier &barrier = image_barriers.emplace_back(VkImageMemoryBarrier{ });
 
                barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
                barrier.srcAccessMask = (is_write_layout(i.current_layout) ? VK_ACCESS_MEMORY_WRITE_BIT : 0);
index c820f1ba6c8598be6163a443a740e744349a4217..e91518a0a5e12f5e2b6a3ba7e00f365e9125d5e0 100644 (file)
@@ -45,8 +45,8 @@ void VulkanWindowView::resize_framebuffer(unsigned w, unsigned h)
        for(unsigned i=0; i<n_images; ++i)
        {
                const SwapChainTexture &image = swap_chain->get_image(i);
-               framebuffers.emplace_back((COLOR_ATTACHMENT, image.get_format()));
-               framebuffers.back().attach(COLOR_ATTACHMENT, swap_chain->get_image(i));
+               Framebuffer &fb = framebuffers.emplace_back((COLOR_ATTACHMENT, image.get_format()));
+               fb.attach(COLOR_ATTACHMENT, swap_chain->get_image(i));
        }
 
        current_target = &framebuffers.front();
index 412cc27a0d96479dcac5c1616ed2f439378a96ce..5a268c66a68f0c51b9feef40b91a3c061a2013fc 100644 (file)
@@ -221,8 +221,7 @@ void SpirVModule::reflect()
        entry_points.reserve(reflection.entry_points.size());
        for(auto &kvp: reflection.entry_points)
        {
-               entry_points.emplace_back(move(kvp.second));
-               EntryPoint &entry = entry_points.back();
+               EntryPoint &entry = entry_points.emplace_back(move(kvp.second));
                for(const Variable *&v: entry.globals)
                {
                        auto i = var_indices.find(v);
index 7954ff5d3c5c837a3995bb03e7bd55f9f0fe8893..b2ea107ec6b8241fa12c92af108632fcfd44ed26 100644 (file)
@@ -69,8 +69,7 @@ void Program::collect_uniforms(const SpirVModule &mod)
        {
                if((v.storage==SpirVModule::UNIFORM || v.storage==SpirVModule::PUSH_CONSTANT || v.storage==SpirVModule::STORAGE_BUFFER) && v.struct_type)
                {
-                       reflect_data.blocks.emplace_back();
-                       ReflectData::BlockInfo &info = reflect_data.blocks.back();
+                       ReflectData::BlockInfo &info = reflect_data.blocks.emplace_back();
                        info.tag = info.name = v.struct_type->name;
                        if(v.storage!=SpirVModule::STORAGE_BUFFER)
                                info.data_size = v.struct_type->size;
@@ -88,20 +87,19 @@ void Program::collect_uniforms(const SpirVModule &mod)
                                reflect_data.n_descriptor_sets = max(reflect_data.n_descriptor_sets, v.descriptor_set+1);
                        }
 
-                       block_uniform_names.emplace_back();
+                       vector<string> &names = block_uniform_names.emplace_back();
                        if(!info.is_storage())
                        {
                                string prefix;
                                if(!v.name.empty())
                                        prefix = v.struct_type->name+".";
-                               collect_block_uniforms(*v.struct_type, prefix, 0, block_uniform_names.back());
+                               collect_block_uniforms(*v.struct_type, prefix, 0, names);
                        }
                }
                else if(v.storage==SpirVModule::UNIFORM_CONSTANT && (v.location>=0 || v.binding>=0))
                {
                        block_uniform_names[0].push_back(v.name);
-                       reflect_data.uniforms.emplace_back();
-                       ReflectData::UniformInfo &info = reflect_data.uniforms.back();
+                       ReflectData::UniformInfo &info = reflect_data.uniforms.emplace_back();
                        info.tag = info.name = v.name;
                        info.location = v.location;
                        if(v.binding>=0)
@@ -158,10 +156,8 @@ void Program::collect_block_uniforms(const SpirVModule::Structure &strct, const
                }
                else
                {
-                       uniform_names.emplace_back(prefix+m.name);
-                       const string &name = uniform_names.back();
-                       reflect_data.uniforms.emplace_back();
-                       ReflectData::UniformInfo &info = reflect_data.uniforms.back();
+                       const string &name = uniform_names.emplace_back(prefix+m.name);
+                       ReflectData::UniformInfo &info = reflect_data.uniforms.emplace_back();
                        info.name = name;
                        info.tag = name;
                        info.offset = offset;
@@ -181,8 +177,7 @@ void Program::collect_attributes(const SpirVModule &mod)
                        for(const SpirVModule::Variable *v: e.globals)
                                if(v->storage==SpirVModule::INPUT)
                                {
-                                       reflect_data.attributes.emplace_back();
-                                       ReflectData::AttributeInfo &info = reflect_data.attributes.back();
+                                       ReflectData::AttributeInfo &info = reflect_data.attributes.emplace_back();
                                        info.name = v->name;
                                        info.location = v->location;
                                        info.array_size = v->array_size;
index 6dd797aa1d70f8c5508975a2d7ae252f7157cd20..0345ac1fac7c6e694cdf2689a9fd5333344769d3 100644 (file)
@@ -102,8 +102,7 @@ void ShadowMap::add_light(const Light &light, unsigned s, ShadowType type, Rende
 
        unsigned n_views = (type==TETRAHEDRON ? 4 : 1);
 
-       lights.emplace_back();
-       ShadowedLight &sl = lights.back();
+       ShadowedLight &sl = lights.emplace_back();
        sl.light = &light;
        sl.index = index;
        sl.region = region;
index d35b4351de857fb44070e7e3d5d6fba31fb03a5e..be96517577e441d9af9563dc7e1534fdb8b50b83 100644 (file)
@@ -447,8 +447,7 @@ void ExpressionInliner::visit(Assignment &assign)
                        if(targets_overlap(i->first, assign.target))
                                i->second->blocked = true;
 
-               expressions.emplace_back();
-               ExpressionInfo &info = expressions.back();
+               ExpressionInfo &info = expressions.emplace_back();
                info.target = assign.target;
                // Self-referencing assignments can't be inlined without additional work.
                if(!assign.self_referencing)
@@ -494,8 +493,7 @@ void ExpressionInliner::visit(VariableDeclaration &var)
        analyze and non-trivial expressions could be expensive to inline.  */
        if((current_block->parent || (constant && r_trivial)) && var.interface.empty())
        {
-               expressions.emplace_back();
-               ExpressionInfo &info = expressions.back();
+               ExpressionInfo &info = expressions.emplace_back();
                info.target = &var;
                /* Assume variables declared in an iteration initialization statement
                will have their values change throughout the iteration. */
@@ -1407,8 +1405,7 @@ void UnusedVariableRemover::visit(FunctionCall &call)
 
 void UnusedVariableRemover::record_assignment(const Assignment::Target &target, Node &node)
 {
-       assignments.emplace_back();
-       AssignmentInfo &assign_info = assignments.back();
+       AssignmentInfo &assign_info = assignments.emplace_back();
        assign_info.node = &node;
        assign_info.target = target;
        assign_info.in_loop = in_loop;
index fee3b862ff56a07e3f85a613da3a1d72a9a998e7..d87aebe0ba16f9112e1ec6c7288eb8239d970772 100644 (file)
@@ -56,8 +56,7 @@ InstanceArrayBase::~InstanceArrayBase()
 
 void InstanceArrayBase::add_block(size_t count)
 {
-       storage.emplace_back();
-       Block &block = storage.back();
+       Block &block = storage.emplace_back();
        block.begin = new char[count*instance_size];
        block.end = block.begin+count*instance_size;
 
index e941d9fd86d540f4225a2b2009f198d69d438749..33ed0cca2cdd1ee603a7e978175f6e89028fc972 100644 (file)
@@ -37,8 +37,7 @@ void Renderer::begin()
                throw invalid_operation("Renderer::begin");
 
        ++frame_number;
-       state_stack.emplace_back();
-       current_state = &state_stack.back();
+       current_state = &state_stack.emplace_back();
 
        RendererBackend::begin();
 
@@ -224,8 +223,7 @@ void Renderer::set_resource(vector<BoundResource<T>> &stack, unsigned &count, Ta
                        break;
                }
 
-       stack.emplace_back();
-       BoundResource<T> &bound_res = stack.back();
+       BoundResource<T> &bound_res = stack.emplace_back();
        bound_res.tag = tag;
        bound_res.resource = res;
        count = stack.size();
index c355020e1458f820d2dd3f1ce72d678d5ee051c2..7ed16d3d40d47b380de817cc6746a837cec70866 100644 (file)
@@ -65,8 +65,7 @@ void Sequence::set_clear_stencil(int s)
 
 Sequence::Step &Sequence::add_step(Tag tag, Renderable &r)
 {
-       steps.emplace_back(tag, &r);
-       return steps.back();
+       return steps.emplace_back(tag, &r);
 }
 
 void Sequence::add_postprocessor(PostProcessor &pp)