]> git.tdb.fi Git - libs/gl.git/blobdiff - source/programdata.cpp
Deprecate some Buffer features which don't translate to Vulkan
[libs/gl.git] / source / programdata.cpp
index f454fe5145f595ed1cd6c62488c5b433aaba9a83..1589d9b0d44e00258d2457fc1f8acb0def28b23e 100644 (file)
@@ -489,21 +489,31 @@ ProgramData::SharedBlock *ProgramData::get_shared_block(const Program::UniformBl
        if(i==blocks.end())
        {
                bool any_found = false;
-               for(vector<const Program::UniformInfo *>::const_iterator j=info.uniforms.begin(); (!any_found && j!=info.uniforms.end()); ++j)
-                       any_found = (find_uniform_index((*j)->name)>=0);
+               bool all_found = true;
+               for(vector<const Program::UniformInfo *>::const_iterator j=info.uniforms.begin(); j!=info.uniforms.end(); ++j)
+               {
+                       if(find_uniform_index((*j)->name)>=0)
+                               any_found = true;
+                       else
+                               all_found = false;
+               }
 
-               // TODO throw if all uniforms for a buffer-backed block are not found
                if(!any_found)
                        return 0;
+               else if(!all_found && info.bind_point>=0)
+               {
+#ifdef DEBUG
+                       IO::print(IO::cerr, "Warning: not all uniforms for block %s are present\n", info.name);
+#else
+                       throw incomplete_uniform_block(info.name);
+#endif
+               }
 
                UniformBlock *block;
                if(info.bind_point>=0)
                {
                        if(!buffer)
-                       {
                                buffer = new Buffer(UNIFORM_BUFFER);
-                               buffer->set_usage(STREAM_DRAW);
-                       }
 
                        block = new UniformBlock(info.data_size);
                        block->use_buffer(buffer, last_block);
@@ -546,6 +556,7 @@ void ProgramData::apply() const
 
                const Program::UniformBlockMap &prog_blocks = prog->get_uniform_blocks();
 
+               UniformBlock *old_last_block = last_block;
                if(pu.dirty==ALL_ONES)
                {
                        /* The set of uniforms has changed since this program was last used.
@@ -587,6 +598,13 @@ void ProgramData::apply() const
                to avoid state thrashing. */
                if(buffered_blocks_updated && !ARB_direct_state_access)
                        buffer->bind();
+
+               if(last_block!=old_last_block)
+               {
+                       unsigned required_size = last_block->get_required_buffer_size();
+                       if(last_block->get_required_buffer_size()>buffer->get_size())
+                               buffer->data(required_size, 0);
+               }
        }
 
        for(vector<ProgramBlock>::iterator i=pu.blocks.begin(); i!=pu.blocks.end(); ++i)