return programs.begin()+index;
}
+void ProgramData::recreate_buffer() const
+{
+ Buffer *old_buffer = buffer;
+ // Create the new buffer first to ensure it has a different address
+ buffer = new Buffer;
+ delete old_buffer;
+ if(last_buffer_block)
+ last_buffer_block->change_buffer(buffer);
+
+#ifdef DEBUG
+ if(!debug_name.empty())
+ buffer->set_debug_name(debug_name);
+#endif
+}
+
void ProgramData::update_block_uniform_indices(SharedBlock &block, const ReflectData::UniformBlockInfo &info) const
{
uint8_t *indices = block.indices.values;
if(info.bind_point>=0)
{
if(!buffer)
- {
- buffer = new Buffer();
-
-#ifdef DEBUG
- if(!debug_name.empty())
- buffer->set_debug_name(debug_name);
-#endif
- }
+ recreate_buffer();
block.block->use_buffer(buffer, last_buffer_block);
last_buffer_block = block.block;
if(last_buffer_block->get_required_buffer_size()>buffer->get_size())
{
if(buffer->get_size()>0)
- {
- delete buffer;
- buffer = new Buffer();
- last_buffer_block->change_buffer(buffer);
-
-#ifdef DEBUG
- if(!debug_name.empty())
- buffer->set_debug_name(debug_name);
-#endif
- }
+ recreate_buffer();
buffer->storage(required_size, STREAMING);
}
private:
int find_uniform_index(Tag) const;
std::vector<ProgramBlock>::iterator get_program(const Program &) const;
+ void recreate_buffer() const;
void update_block_uniform_indices(SharedBlock &, const ReflectData::UniformBlockInfo &) const;
void update_block(SharedBlock &, const ReflectData::UniformBlockInfo &) const;