1 #include <msp/core/algorithm.h>
2 #include <msp/core/maputils.h>
3 #include <msp/debug/demangle.h>
4 #include <msp/gl/extensions/arb_direct_state_access.h>
5 #include <msp/io/print.h>
11 #include "programdata.h"
13 #include "uniformblock.h"
21 ProgramData::ProgramData(const Program *p):
28 // Blocks are intentionally left uncopied
29 ProgramData::ProgramData(const ProgramData &other):
30 tied_program(other.tied_program),
31 uniforms(other.uniforms),
36 for(vector<TaggedUniform>::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
37 i->value = i->value->clone();
40 ProgramData::ProgramData(const ProgramData &other, const Program *p):
48 for(vector<TaggedUniform>::const_iterator i=other.uniforms.begin(); i!=other.uniforms.end(); ++i)
52 uniforms = other.uniforms;
53 for(vector<TaggedUniform>::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
54 i->value = i->value->clone();
57 ProgramData &ProgramData::operator=(const ProgramData &other)
59 tied_program = other.tied_program;
61 uniforms = other.uniforms;
62 for(vector<TaggedUniform>::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
63 i->value = i->value->clone();
65 for(vector<SharedBlock>::iterator i=blocks.begin(); i!=blocks.end(); ++i)
69 last_buffer_block = 0;
76 ProgramData::~ProgramData()
78 for(vector<TaggedUniform>::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
80 for(vector<SharedBlock>::iterator i=blocks.begin(); i!=blocks.end(); ++i)
82 if(i->indices.type_flag==0xFE)
83 delete[] i->indices.dynamic.values;
89 void ProgramData::uniform(Tag tag, Uniform *uni)
93 if(!validate_tag(tag))
105 int i = find_uniform_index(tag);
107 return add_uniform(tag, uni);
109 uniforms[i].replace_value(uni);
113 template<typename T, typename V>
114 void ProgramData::uniform(Tag tag, V value)
116 if(!validate_tag(tag))
119 int i = find_uniform_index(tag);
121 return add_uniform(tag, new T(value));
123 if(T *uni = dynamic_cast<T *>(uniforms[i].value))
126 uniforms[i].replace_value(new T(value));
131 template<typename T, typename V>
132 void ProgramData::uniform_array(Tag tag, unsigned n, V value)
134 if(!validate_tag(tag))
137 int i = find_uniform_index(tag);
139 return add_uniform(tag, new UniformArray<T>(n, value));
141 UniformArray<T> *uni = dynamic_cast<UniformArray<T> *>(uniforms[i].value);
142 if(uni && n==uni->size())
145 uniforms[i].replace_value(new UniformArray<T>(n, value));
150 bool ProgramData::validate_tag(Tag tag) const
158 const Program::UniformInfo &info = tied_program->get_uniform_info(tag);
159 if(is_image(info.type))
160 throw invalid_operation("ProgramData::uniform");
165 catch(const exception &e)
167 IO::print(IO::cerr, "Error while setting uniform %s: %s: %s\n", tag, Debug::demangle(typeid(e).name()), e.what());
173 void ProgramData::add_uniform(Tag tag, Uniform *uni)
175 if(uniforms.size()>=MASK_BITS)
178 throw too_many_uniforms(tag.str());
181 vector<TaggedUniform>::iterator j = lower_bound_member(uniforms, tag, &TaggedUniform::tag);
186 uniforms.insert(j, nu);
191 void ProgramData::uniform(Tag tag, const Uniform &u)
193 uniform(tag, u.clone());
196 void ProgramData::uniform(Tag tag, int v)
198 uniform<Uniform1i>(tag, v);
201 void ProgramData::uniform(Tag tag, float v)
203 uniform<Uniform1f>(tag, v);
206 void ProgramData::uniform(Tag tag, int v0, int v1)
208 int va[2] = { v0, v1 };
212 void ProgramData::uniform(Tag tag, float v0, float v1)
214 float va[2] = { v0, v1 };
218 void ProgramData::uniform2(Tag tag, const int *v)
220 uniform<Uniform2i>(tag, v);
223 void ProgramData::uniform2(Tag tag, const float *v)
225 uniform<Uniform2f>(tag, v);
228 void ProgramData::uniform(Tag tag, int v0, int v1, int v2)
230 int va[3] = { v0, v1, v2 };
234 void ProgramData::uniform(Tag tag, float v0, float v1, float v2)
236 float va[3] = { v0, v1, v2 };
240 void ProgramData::uniform(Tag tag, const Vector3 &v)
242 uniform(tag, v.x, v.y, v.z);
245 void ProgramData::uniform3(Tag tag, const int *v)
247 uniform<Uniform3i>(tag, v);
250 void ProgramData::uniform3(Tag tag, const float *v)
252 uniform<Uniform3f>(tag, v);
255 void ProgramData::uniform(Tag tag, int v0, int v1, int v2, int v3)
257 int va[4] = { v0, v1, v2, v3 };
261 void ProgramData::uniform(Tag tag, float v0, float v1, float v2, float v3)
263 float va[4] = { v0, v1, v2, v3 };
267 void ProgramData::uniform(Tag tag, const Vector4 &v)
269 uniform(tag, v.x, v.y, v.z, v.w);
272 void ProgramData::uniform(Tag tag, const Color &c)
274 uniform(tag, c.r, c.g, c.b, c.a);
277 void ProgramData::uniform4(Tag tag, const int *v)
279 uniform<Uniform4i>(tag, v);
282 void ProgramData::uniform4(Tag tag, const float *v)
284 uniform<Uniform4f>(tag, v);
287 void ProgramData::uniform(Tag tag, const LinAl::Matrix<float, 2, 2> &m)
289 uniform_matrix2(tag, &m(0, 0));
292 void ProgramData::uniform_matrix2(Tag tag, const float *v)
294 uniform<UniformMatrix2x2f>(tag, v);
297 void ProgramData::uniform(Tag tag, const LinAl::Matrix<float, 2, 3> &m)
299 uniform_matrix3x2(tag, &m(0, 0));
302 void ProgramData::uniform_matrix3x2(Tag tag, const float *v)
304 uniform<UniformMatrix3x2f>(tag, v);
307 void ProgramData::uniform(Tag tag, const LinAl::Matrix<float, 2, 4> &m)
309 uniform_matrix4x2(tag, &m(0, 0));
312 void ProgramData::uniform_matrix4x2(Tag tag, const float *v)
314 uniform<UniformMatrix4x2f>(tag, v);
317 void ProgramData::uniform(Tag tag, const LinAl::Matrix<float, 3, 2> &m)
319 uniform_matrix2x3(tag, &m(0, 0));
322 void ProgramData::uniform_matrix2x3(Tag tag, const float *v)
324 uniform<UniformMatrix2x3f>(tag, v);
327 void ProgramData::uniform(Tag tag, const LinAl::Matrix<float, 3, 3> &m)
329 uniform_matrix3(tag, &m(0, 0));
332 void ProgramData::uniform_matrix3(Tag tag, const float *v)
334 uniform<UniformMatrix3x3f>(tag, v);
337 void ProgramData::uniform(Tag tag, const LinAl::Matrix<float, 3, 4> &m)
339 uniform_matrix4x3(tag, &m(0, 0));
342 void ProgramData::uniform_matrix4x3(Tag tag, const float *v)
344 uniform<UniformMatrix4x3f>(tag, v);
347 void ProgramData::uniform(Tag tag, const LinAl::Matrix<float, 4, 2> &m)
349 uniform_matrix2x4(tag, &m(0, 0));
352 void ProgramData::uniform_matrix2x4(Tag tag, const float *v)
354 uniform<UniformMatrix2x4f>(tag, v);
357 void ProgramData::uniform(Tag tag, const LinAl::Matrix<float, 4, 3> &m)
359 uniform_matrix3x4(tag, &m(0, 0));
362 void ProgramData::uniform_matrix3x4(Tag tag, const float *v)
364 uniform<UniformMatrix3x4f>(tag, v);
367 void ProgramData::uniform(Tag tag, const Matrix &m)
369 uniform_matrix4(tag, m.data());
372 void ProgramData::uniform_matrix4(Tag tag, const float *v)
374 uniform<UniformMatrix4x4f>(tag, v);
377 void ProgramData::uniform1_array(Tag tag, unsigned n, const int *v)
379 uniform_array<Uniform1i>(tag, n, v);
382 void ProgramData::uniform1_array(Tag tag, unsigned n, const float *v)
384 uniform_array<Uniform1f>(tag, n, v);
387 void ProgramData::uniform2_array(Tag tag, unsigned n, const int *v)
389 uniform_array<Uniform2i>(tag, n, v);
392 void ProgramData::uniform2_array(Tag tag, unsigned n, const float *v)
394 uniform_array<Uniform2f>(tag, n, v);
397 void ProgramData::uniform3_array(Tag tag, unsigned n, const int *v)
399 uniform_array<Uniform3i>(tag, n, v);
402 void ProgramData::uniform3_array(Tag tag, unsigned n, const float *v)
404 uniform_array<Uniform3f>(tag, n, v);
407 void ProgramData::uniform4_array(Tag tag, unsigned n, const int *v)
409 uniform_array<Uniform4i>(tag, n, v);
412 void ProgramData::uniform4_array(Tag tag, unsigned n, const float *v)
414 uniform_array<Uniform4f>(tag, n, v);
417 void ProgramData::uniform_matrix2_array(Tag tag, unsigned n, const float *v)
419 uniform_array<UniformMatrix2x2f>(tag, n, v);
422 void ProgramData::uniform_matrix3x2_array(Tag tag, unsigned n, const float *v)
424 uniform_array<UniformMatrix3x2f>(tag, n, v);
427 void ProgramData::uniform_matrix4x2_array(Tag tag, unsigned n, const float *v)
429 uniform_array<UniformMatrix4x2f>(tag, n, v);
432 void ProgramData::uniform_matrix2x3_array(Tag tag, unsigned n, const float *v)
434 uniform_array<UniformMatrix2x3f>(tag, n, v);
437 void ProgramData::uniform_matrix3_array(Tag tag, unsigned n, const float *v)
439 uniform_array<UniformMatrix3x3f>(tag, n, v);
442 void ProgramData::uniform_matrix4x3_array(Tag tag, unsigned n, const float *v)
444 uniform_array<UniformMatrix4x3f>(tag, n, v);
447 void ProgramData::uniform_matrix2x4_array(Tag tag, unsigned n, const float *v)
449 uniform_array<UniformMatrix2x4f>(tag, n, v);
452 void ProgramData::uniform_matrix3x4_array(Tag tag, unsigned n, const float *v)
454 uniform_array<UniformMatrix3x4f>(tag, n, v);
457 void ProgramData::uniform_matrix4_array(Tag tag, unsigned n, const float *v)
459 uniform_array<UniformMatrix4x4f>(tag, n, v);
462 void ProgramData::remove_uniform(Tag tag)
464 vector<TaggedUniform>::const_iterator i = lower_bound_member(uniforms, tag, &TaggedUniform::tag);
465 if(i==uniforms.end() || i->tag!=tag)
474 vector<Tag> ProgramData::get_uniform_tags() const
477 tags.reserve(uniforms.size());
478 for(vector<TaggedUniform>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
479 tags.push_back(i->tag);
483 const Uniform &ProgramData::get_uniform(Tag tag) const
485 int i = find_uniform_index(tag);
487 throw key_error(tag);
488 return *uniforms[i].value;
491 const Uniform *ProgramData::find_uniform(Tag tag) const
493 int i = find_uniform_index(tag);
494 return (i>=0 ? uniforms[i].value : 0);
497 int ProgramData::find_uniform_index(Tag tag) const
499 vector<TaggedUniform>::const_iterator i = lower_bound_member(uniforms, tag, &TaggedUniform::tag);
500 return ((i!=uniforms.end() && i->tag==tag) ? i-uniforms.begin() : -1);
503 vector<ProgramData::ProgramBlock>::iterator ProgramData::get_program(const Program &prog) const
505 Program::LayoutHash prog_hash = prog.get_uniform_layout_hash();
506 vector<ProgramBlock>::iterator i = lower_bound_member(programs, prog_hash, &ProgramBlock::prog_hash);
507 if(i!=programs.end() && i->prog_hash==prog_hash)
510 const vector<Program::UniformBlockInfo> &block_infos = prog.get_uniform_blocks();
511 unsigned index = i-programs.begin();
512 programs.insert(i, 1+block_infos.size(), ProgramBlock(prog_hash));
514 /* Block indices may change if new shared blocks need to be inserted. Store
515 the hashes so they can be matched up later. */
516 vector<Program::LayoutHash> block_hashes;
517 block_hashes.reserve(programs.size());
518 for(vector<ProgramBlock>::iterator j=programs.begin(); j!=programs.end(); ++j)
519 block_hashes.push_back(j->block_index>=0 ? blocks[j->block_index].block_hash : 0);
521 for(unsigned j=0; j<block_infos.size(); ++j)
523 const Program::UniformBlockInfo &info = block_infos[j];
524 block_hashes[index+1+j] = info.layout_hash;
525 programs[index+1+j].bind_point = info.bind_point;
527 vector<SharedBlock>::iterator k = lower_bound_member(blocks, info.layout_hash, &SharedBlock::block_hash);
528 if(k==blocks.end() || k->block_hash!=info.layout_hash)
530 k = blocks.insert(k, SharedBlock(info.layout_hash));
531 update_block_uniform_indices(*k, info);
535 /* Reassign shared block indices from the stored hashes. */
536 for(unsigned j=0; j<programs.size(); ++j)
538 unsigned hash = block_hashes[j];
541 vector<SharedBlock>::const_iterator k = lower_bound_member(blocks, hash, &SharedBlock::block_hash);
542 programs[j].block_index = k-blocks.begin();
545 programs[j].block_index = -1;
548 return programs.begin()+index;
551 void ProgramData::update_block_uniform_indices(SharedBlock &block, const Program::UniformBlockInfo &info) const
553 UInt8 *indices = block.indices.values;
554 if(info.uniforms.size()>16)
556 if(block.indices.type_flag==0xFD)
558 block.indices.dynamic.values = new UInt8[info.uniforms.size()];
559 block.indices.type_flag = 0xFE;
561 indices = block.indices.dynamic.values;
564 bool any_missing = false;
567 for(unsigned i=0; i<info.uniforms.size(); ++i)
569 int j = find_uniform_index(info.uniforms[i]->tag);
573 if(static_cast<unsigned>(j)<MASK_BITS)
583 if(block.used && any_missing && info.bind_point>=0)
586 IO::print(IO::cerr, "Warning: not all uniforms for block %s are present\n", info.name);
588 throw incomplete_uniform_block(info.name);
592 block.dirty = block.used;
594 if(block.used && !block.block)
596 if(info.bind_point>=0)
599 buffer = new Buffer(UNIFORM_BUFFER);
601 BufferBackedUniformBlock *bb_block = new BufferBackedUniformBlock(info.data_size);
602 block.block = bb_block;
603 bb_block->use_buffer(buffer, last_buffer_block);
604 last_buffer_block = bb_block;
607 block.block = new DefaultUniformBlock;
611 void ProgramData::update_block(SharedBlock &block, const Program::UniformBlockInfo &info) const
613 const UInt8 *indices = block.get_uniform_indices();
614 for(unsigned i=0; i<info.uniforms.size(); ++i)
616 if(is_image(info.uniforms[i]->type))
617 ; // Temporarily ignore deprecated use of sampler uniforms in ProgramData
618 else if(indices[i]!=0xFF)
619 block.block->attach(*info.uniforms[i], *uniforms[indices[i]].value);
623 void ProgramData::apply() const
625 const Program *prog = Program::current();
627 throw invalid_operation("ProgramData::apply");
629 BufferBackedUniformBlock *old_last_block = last_buffer_block;
630 vector<ProgramBlock>::iterator prog_begin = get_program(*prog);
631 Program::LayoutHash prog_hash = prog->get_uniform_layout_hash();
633 Mask force_dirty = (dirty==ALL_ONES ? ALL_ONES : 0U);
634 Mask affected = (dirty&prog_begin->masks.used) | force_dirty;
635 if(affected|prog_begin->masks.dirty)
637 /* If the global dirty flag affects this program, add it to per-block and
638 per-program dirty flags and clear the global flag. A previously unseen
639 program will cause this to happen if there's any dirty uniforms. */
642 for(vector<SharedBlock>::iterator i=blocks.begin(); i!=blocks.end(); ++i)
643 i->dirty |= (dirty&i->used) | force_dirty;
644 for(vector<ProgramBlock>::iterator i=programs.begin(); i!=programs.end(); ++i)
646 i->masks.dirty |= (dirty&i->masks.used) | force_dirty;
650 const vector<Program::UniformBlockInfo> &block_infos = prog->get_uniform_blocks();
652 if(prog_begin->masks.dirty==ALL_ONES)
654 /* The set of uniforms has changed since this program was last used.
655 Refresh uniform indices within the program's blocks. */
656 prog_begin->masks.used = 0;
657 vector<ProgramBlock>::iterator j = prog_begin+1;
658 for(vector<Program::UniformBlockInfo>::const_iterator i=block_infos.begin(); i!=block_infos.end(); ++i, ++j)
660 SharedBlock &shared = blocks[j->block_index];
661 if(shared.dirty==ALL_ONES)
662 update_block_uniform_indices(shared, *i);
663 prog_begin->masks.used |= shared.used;
664 j->block = (shared.used ? shared.block : 0);
668 // Update the contents of all dirty blocks.
669 bool buffered_blocks_updated = false;
670 vector<ProgramBlock>::iterator j = prog_begin+1;
671 for(vector<Program::UniformBlockInfo>::const_iterator i=block_infos.begin(); i!=block_infos.end(); ++i, ++j)
673 SharedBlock &shared = blocks[j->block_index];
676 update_block(shared, *i);
678 buffered_blocks_updated |= (j->bind_point>=0);
682 prog_begin->masks.dirty = 0;
684 /* If any blocks stored in the buffer were updated, bind the buffer here
685 to avoid state thrashing. */
686 if(buffered_blocks_updated && !ARB_direct_state_access)
689 if(last_buffer_block!=old_last_block)
691 unsigned required_size = last_buffer_block->get_required_buffer_size();
692 if(last_buffer_block->get_required_buffer_size()>buffer->get_size())
694 if(buffer->get_size()>0)
697 buffer = new Buffer(UNIFORM_BUFFER);
698 last_buffer_block->change_buffer(buffer);
701 buffer->storage(required_size);
706 for(vector<ProgramBlock>::iterator i=prog_begin+1; (i!=programs.end() && i->prog_hash==prog_hash); ++i)
708 i->block->apply(i->bind_point);
712 ProgramData::TaggedUniform::TaggedUniform():
716 void ProgramData::TaggedUniform::replace_value(Uniform *v)
718 /* UniformBlock does not copy the uniforms, so existing default blocks
719 will be left with stale pointers. This is not a problem as long as no
720 one stores pointers to the blocks and expects them to stay valid. */
726 ProgramData::SharedBlock::SharedBlock(Program::LayoutHash h):
732 indices.type_flag = 0xFD;
735 const UInt8 *ProgramData::SharedBlock::get_uniform_indices() const
737 return (indices.type_flag==0xFE ? indices.dynamic.values : indices.values);
741 ProgramData::ProgramBlock::ProgramBlock(Program::LayoutHash h):
746 masks.used = ALL_ONES;
747 masks.dirty = ALL_ONES;
751 ProgramData::Loader::Loader(ProgramData &pd):
752 DataFile::ObjectLoader<ProgramData>(pd)
754 add("uniform", &Loader::uniform1i);
755 add("uniform1i", &Loader::uniform1i);
756 add("uniform", &Loader::uniform1f);
757 add("uniform1f", &Loader::uniform1f);
758 add("uniform", &Loader::uniform2i);
759 add("uniform2i", &Loader::uniform2i);
760 add("uniform", &Loader::uniform2f);
761 add("uniform2f", &Loader::uniform2f);
762 add("uniform", &Loader::uniform3i);
763 add("uniform3i", &Loader::uniform3i);
764 add("uniform", &Loader::uniform3f);
765 add("uniform3f", &Loader::uniform3f);
766 add("uniform", &Loader::uniform4i);
767 add("uniform4i", &Loader::uniform4i);
768 add("uniform", &Loader::uniform4f);
769 add("uniform4f", &Loader::uniform4f);
770 add("uniform1i_array", &Loader::uniform1i_array);
771 add("uniform1f_array", &Loader::uniform1f_array);
772 add("uniform2f_array", &Loader::uniform2f_array);
773 add("uniform3f_array", &Loader::uniform3f_array);
774 add("uniform4f_array", &Loader::uniform4f_array);
775 add("uniform_array", &Loader::uniform_array);
778 void ProgramData::Loader::uniform1i(const string &n, int v)
783 void ProgramData::Loader::uniform1f(const string &n, float v)
788 void ProgramData::Loader::uniform2i(const string &n, int v0, int v1)
790 obj.uniform(n, v0, v1);
793 void ProgramData::Loader::uniform2f(const string &n, float v0, float v1)
795 obj.uniform(n, v0, v1);
798 void ProgramData::Loader::uniform3i(const string &n, int v0, int v1, int v2)
800 obj.uniform(n, v0, v1, v2);
803 void ProgramData::Loader::uniform3f(const string &n, float v0, float v1, float v2)
805 obj.uniform(n, v0, v1, v2);
808 void ProgramData::Loader::uniform4i(const string &n, int v0, int v1, int v2, int v3)
810 obj.uniform(n, v0, v1, v2, v3);
813 void ProgramData::Loader::uniform4f(const string &n, float v0, float v1, float v2, float v3)
815 obj.uniform(n, v0, v1, v2, v3);
818 void ProgramData::Loader::uniform_array_(const string &n, DataType t, unsigned e)
820 ArrayLoader ldr(t, e);
822 unsigned size = ldr.get_size();
824 throw logic_error("empty uniform array");
826 DataType type = ldr.get_data_type();
827 unsigned elem_size = ldr.get_element_size();
830 const int *data = reinterpret_cast<const int *>(ldr.get_data());
832 obj.uniform1_array(n, size, data);
833 else if(elem_size==2)
834 obj.uniform2_array(n, size, data);
835 else if(elem_size==3)
836 obj.uniform3_array(n, size, data);
837 else if(elem_size==4)
838 obj.uniform4_array(n, size, data);
840 throw logic_error("unsupported combination of array type and element size");
844 const float *data = reinterpret_cast<const float *>(ldr.get_data());
846 obj.uniform1_array(n, size, data);
847 else if(elem_size==2)
848 obj.uniform2_array(n, size, data);
849 else if(elem_size==3)
850 obj.uniform3_array(n, size, data);
851 else if(elem_size==4)
852 obj.uniform4_array(n, size, data);
854 throw logic_error("unsupported combination of array type and element size");
857 throw logic_error("unsupported array type");
860 void ProgramData::Loader::uniform1i_array(const string &n)
862 uniform_array_(n, INT, 1);
865 void ProgramData::Loader::uniform1f_array(const string &n)
867 uniform_array_(n, FLOAT, 1);
870 void ProgramData::Loader::uniform2i_array(const string &n)
872 uniform_array_(n, INT, 2);
875 void ProgramData::Loader::uniform2f_array(const string &n)
877 uniform_array_(n, FLOAT, 2);
880 void ProgramData::Loader::uniform3i_array(const string &n)
882 uniform_array_(n, INT, 3);
885 void ProgramData::Loader::uniform3f_array(const string &n)
887 uniform_array_(n, FLOAT, 3);
890 void ProgramData::Loader::uniform4i_array(const string &n)
892 uniform_array_(n, INT, 4);
895 void ProgramData::Loader::uniform4f_array(const string &n)
897 uniform_array_(n, FLOAT, 4);
900 void ProgramData::Loader::uniform_array(const string &n)
902 uniform_array_(n, static_cast<DataType>(0), 0);
906 ProgramData::ArrayLoader::ArrayLoader(DataType t, unsigned e):
910 add("uniform", &ArrayLoader::uniform1i);
911 add("uniform1i", &ArrayLoader::uniform1i);
912 add("uniform", &ArrayLoader::uniform1f);
913 add("uniform1f", &ArrayLoader::uniform1f);
914 add("uniform", &ArrayLoader::uniform2f);
915 add("uniform2f", &ArrayLoader::uniform2f);
916 add("uniform", &ArrayLoader::uniform3f);
917 add("uniform3f", &ArrayLoader::uniform3f);
918 add("uniform", &ArrayLoader::uniform4f);
919 add("uniform4f", &ArrayLoader::uniform4f);
922 void ProgramData::ArrayLoader::uniform(DataType t, unsigned e, const void *v)
924 if(element_size && (t!=type || e!=element_size))
925 throw logic_error("heterogeneous array contents");
933 const char *cv = reinterpret_cast<const char *>(v);
934 data.insert(data.end(), cv, cv+element_size*4);
937 void ProgramData::ArrayLoader::uniform1i(int v)
942 void ProgramData::ArrayLoader::uniform1f(float v)
944 uniform(FLOAT, 1, &v);
947 void ProgramData::ArrayLoader::uniform2i(int v0, int v1)
949 int va[2] = { v0, v1 };
953 void ProgramData::ArrayLoader::uniform2f(float v0, float v1)
955 float va[2] = { v0, v1 };
956 uniform(FLOAT, 2, va);
959 void ProgramData::ArrayLoader::uniform3i(int v0, int v1, int v2)
961 int va[3] = { v0, v1, v2 };
965 void ProgramData::ArrayLoader::uniform3f(float v0, float v1, float v2)
967 float va[3] = { v0, v1, v2 };
968 uniform(FLOAT, 3, va);
971 void ProgramData::ArrayLoader::uniform4i(int v0, int v1, int v2, int v3)
973 int va[4] = { v0, v1, v2, v3 };
977 void ProgramData::ArrayLoader::uniform4f(float v0, float v1, float v2, float v3)
979 float va[4] = { v0, v1, v2, v3 };
980 uniform(FLOAT, 4, va);