X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Frender%2Fprogramdata.h;h=1bcd3aab42c6ea2158f5beb0fbdcaab8f200720e;hp=97f293430c1c718e06f594d84ddf0d2de1a84263;hb=3a1b9cbe2441ae670a97541dc8ccb0a2860c8302;hpb=3f5e469de3454aee1d1923045fc713329a32cc18 diff --git a/source/render/programdata.h b/source/render/programdata.h index 97f29343..1bcd3aab 100644 --- a/source/render/programdata.h +++ b/source/render/programdata.h @@ -8,6 +8,7 @@ #include "matrix.h" #include "program.h" #include "tag.h" +#include "uniform.h" #include "vector.h" namespace Msp { @@ -21,7 +22,8 @@ public: }; class Buffer; -class Uniform; +class BufferBackedUniformBlock; +class PipelineState; class UniformBlock; struct Color; @@ -110,55 +112,54 @@ private: struct SharedBlock { + Program::LayoutHash block_hash; Mask used; Mask dirty; UniformBlock *block; union { - UInt8 type_flag; - UInt8 values[16]; + std::uint8_t type_flag; + std::uint8_t values[16]; struct { - UInt8 type_flag; - UInt8 *values; + std::uint8_t type_flag; + std::uint8_t *values; } dynamic; } indices; - SharedBlock(UniformBlock *); + SharedBlock(Program::LayoutHash); - const UInt8 *get_uniform_indices() const; + const std::uint8_t *get_uniform_indices() const; }; struct ProgramBlock { + Program::LayoutHash prog_hash; int bind_point; - UniformBlock *block; - SharedBlock *shared; - - ProgramBlock(); - ProgramBlock(int, SharedBlock *); - }; - - struct ProgramUniforms - { - std::vector blocks; - Mask used; - Mask dirty; + int block_index; + union + { + UniformBlock *block; + struct + { + Mask used; + Mask dirty; + } masks; + }; - ProgramUniforms(); + ProgramBlock(Program::LayoutHash); }; - typedef std::map BlockMap; - typedef std::map ProgramMap; - // XXX All these mutables are a bit silly, but I'm out of better ideas const Program *tied_program; std::vector uniforms; - mutable BlockMap blocks; - mutable ProgramMap programs; - mutable UniformBlock *last_block; + unsigned generation; + mutable std::vector blocks; + mutable std::vector programs; + mutable BufferBackedUniformBlock *last_buffer_block; mutable Buffer *buffer; mutable Mask dirty; + std::string debug_name; public: ProgramData(const Program * = 0); @@ -175,6 +176,7 @@ private: void uniform_array(Tag, unsigned, V); bool validate_tag(Tag) const; void add_uniform(Tag, Uniform *); + void mark_dirty(Mask); public: void uniform(Tag, const Uniform &); void uniform(Tag, int); @@ -185,33 +187,25 @@ public: void uniform2(Tag, const float *); void uniform(Tag, int, int, int); void uniform(Tag, float, float, float); - void uniform(Tag, const Vector3 &); void uniform3(Tag, const int *); void uniform3(Tag, const float *); void uniform(Tag, int, int, int, int); void uniform(Tag, float, float, float, float); - void uniform(Tag, const Vector4 &); void uniform(Tag, const Color &); void uniform4(Tag, const int *); void uniform4(Tag, const float *); - void uniform(Tag, const LinAl::Matrix &); void uniform_matrix2(Tag, const float *); - void uniform(Tag, const LinAl::Matrix &); void uniform_matrix3x2(Tag, const float *); - void uniform(Tag, const LinAl::Matrix &); void uniform_matrix4x2(Tag, const float *); - void uniform(Tag, const LinAl::Matrix &); void uniform_matrix2x3(Tag, const float *); - void uniform(Tag, const LinAl::Matrix &); void uniform_matrix3(Tag, const float *); - void uniform(Tag, const LinAl::Matrix &); void uniform_matrix4x3(Tag, const float *); - void uniform(Tag, const LinAl::Matrix &); void uniform_matrix2x4(Tag, const float *); - void uniform(Tag, const LinAl::Matrix &); void uniform_matrix3x4(Tag, const float *); void uniform(Tag, const Matrix &); void uniform_matrix4(Tag, const float *); + void uniform_array(Tag, unsigned, const int *); + void uniform_array(Tag, unsigned, const float *); void uniform1_array(Tag, unsigned, const int *); void uniform1_array(Tag, unsigned, const float *); void uniform2_array(Tag, unsigned, const int *); @@ -229,24 +223,56 @@ public: void uniform_matrix2x4_array(Tag, unsigned, const float *); void uniform_matrix3x4_array(Tag, unsigned, const float *); void uniform_matrix4_array(Tag, unsigned, const float *); + + template + void uniform(Tag, const LinAl::Vector &); + + template + void uniform(Tag, const LinAl::Matrix &); + + template + void uniform_array(Tag, unsigned, const LinAl::Vector *); + + template + void uniform_array(Tag, unsigned, const LinAl::Matrix *); + void remove_uniform(Tag); + unsigned get_generation() const { return generation; } + std::vector get_uniform_tags() const; const Uniform &get_uniform(Tag) const; const Uniform *find_uniform(Tag) const; private: int find_uniform_index(Tag) const; + std::vector::iterator get_program(const Program &) const; void update_block_uniform_indices(SharedBlock &, const Program::UniformBlockInfo &) const; void update_block(SharedBlock &, const Program::UniformBlockInfo &) const; - SharedBlock *get_shared_block(const Program::UniformBlockInfo &) const; + std::vector::const_iterator prepare_program(const Program &) const; public: - /** Applies uniform blocks for the currently bound program, creating them - if needed. */ - void apply() const; + void apply(const Program &, PipelineState &) const; + + void set_debug_name(const std::string &); }; +template +void ProgramData::uniform(Tag tag, const LinAl::Vector &v) +{ uniform >(tag, &v.x); } + +template +void ProgramData::uniform(Tag tag, const LinAl::Matrix &v) +{ uniform >(tag, &v(0, 0)); } + +template +void ProgramData::uniform_array(Tag tag, unsigned n, const LinAl::Vector *v) +{ uniform_array >(tag, n, &v[0].x); } + +template +void ProgramData::uniform_array(Tag tag, unsigned n, const LinAl::Matrix *v) +{ uniform_array >(tag, n, &v[0](0, 0)); } + } // namespace GL } // namespace Msp