X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Frender%2Fprogramdata.h;h=f1c5996eb910e3e51368571472e94e6902d12bec;hp=6f20d4d8317da1d393e5da555c0d4a3989498f67;hb=HEAD;hpb=ba1427f10d574ff8c4dafc4b8673452b19308ca2 diff --git a/source/render/programdata.h b/source/render/programdata.h deleted file mode 100644 index 6f20d4d8..00000000 --- a/source/render/programdata.h +++ /dev/null @@ -1,250 +0,0 @@ -#ifndef MSP_GL_PROGRAMDATA_H_ -#define MSP_GL_PROGRAMDATA_H_ - -#include -#include -#include -#include "datatype.h" -#include "matrix.h" -#include "program.h" -#include "tag.h" -#include "vector.h" - -namespace Msp { -namespace GL { - -class too_many_uniforms: public std::runtime_error -{ -public: - too_many_uniforms(const std::string &w): std::runtime_error(w) { } - virtual ~too_many_uniforms() throw() { } -}; - -class Buffer; -class Uniform; -class UniformBlock; -struct Color; - -/** -Stores uniform variables for shader programs. The uniforms are stored in a -program-independent way, and UniformBlocks are created to match the uniform -layouts of different programs. If multiple programs have the same layout, the -same block is used for them. - -The class is optimized for an access pattern where the set of uniforms and -programs stays constants, with only the values changing. -*/ -class ProgramData -{ -public: - class Loader: public DataFile::ObjectLoader - { - public: - Loader(ProgramData &); - private: - void uniform1i(const std::string &, int); - void uniform1f(const std::string &, float); - void uniform2i(const std::string &, int, int); - void uniform2f(const std::string &, float, float); - void uniform3i(const std::string &, int, int, int); - void uniform3f(const std::string &, float, float, float); - void uniform4i(const std::string &, int, int, int, int); - void uniform4f(const std::string &, float, float, float, float); - void uniform_array_(const std::string &, DataType, unsigned); - void uniform1i_array(const std::string &); - void uniform1f_array(const std::string &); - void uniform2i_array(const std::string &); - void uniform2f_array(const std::string &); - void uniform3i_array(const std::string &); - void uniform3f_array(const std::string &); - void uniform4i_array(const std::string &); - void uniform4f_array(const std::string &); - void uniform_array(const std::string &); - }; - -private: - class ArrayLoader: public DataFile::Loader - { - private: - DataType type; - unsigned element_size; - std::vector data; - - public: - ArrayLoader(DataType, unsigned); - - DataType get_data_type() const { return type; } - unsigned get_element_size() const { return element_size; } - const void *get_data() const { return &data[0]; } - unsigned get_size() const { return data.size()/(4*element_size); } - - private: - void uniform(DataType, unsigned, const void *); - void uniform1i(int); - void uniform1f(float); - void uniform2i(int, int); - void uniform2f(float, float); - void uniform3i(int, int, int); - void uniform3f(float, float, float); - void uniform4i(int, int, int, int); - void uniform4f(float, float, float, float); - }; - - typedef unsigned Mask; - - enum - { - MASK_BITS = sizeof(Mask)*8, - ALL_ONES = static_cast(-1) - }; - - struct TaggedUniform - { - Tag tag; - Uniform *value; - - TaggedUniform(); - - void replace_value(Uniform *); - }; - - struct SharedBlock - { - Program::LayoutHash block_hash; - Mask used; - Mask dirty; - UniformBlock *block; - union - { - UInt8 type_flag; - UInt8 values[16]; - struct - { - UInt8 type_flag; - UInt8 *values; - } dynamic; - } indices; - - SharedBlock(Program::LayoutHash); - - const UInt8 *get_uniform_indices() const; - }; - - struct ProgramBlock - { - Program::LayoutHash prog_hash; - int bind_point; - int block_index; - union - { - UniformBlock *block; - struct - { - Mask used; - Mask dirty; - } masks; - }; - - ProgramBlock(Program::LayoutHash); - }; - - // XXX All these mutables are a bit silly, but I'm out of better ideas - const Program *tied_program; - std::vector uniforms; - mutable std::vector blocks; - mutable std::vector programs; - mutable UniformBlock *last_block; - mutable Buffer *buffer; - mutable Mask dirty; - -public: - ProgramData(const Program * = 0); - ProgramData(const ProgramData &); - ProgramData(const ProgramData &, const Program *); - ProgramData &operator=(const ProgramData &); - ~ProgramData(); - -private: - void uniform(Tag, Uniform *); - template - void uniform(Tag, V); - template - void uniform_array(Tag, unsigned, V); - bool validate_tag(Tag) const; - void add_uniform(Tag, Uniform *); -public: - void uniform(Tag, const Uniform &); - void uniform(Tag, int); - void uniform(Tag, float); - void uniform(Tag, int, int); - void uniform(Tag, float, float); - void uniform2(Tag, const int *); - 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 uniform1_array(Tag, unsigned, const int *); - void uniform1_array(Tag, unsigned, const float *); - void uniform2_array(Tag, unsigned, const int *); - void uniform2_array(Tag, unsigned, const float *); - void uniform3_array(Tag, unsigned, const int *); - void uniform3_array(Tag, unsigned, const float *); - void uniform4_array(Tag, unsigned, const int *); - void uniform4_array(Tag, unsigned, const float *); - void uniform_matrix2_array(Tag, unsigned, const float *); - void uniform_matrix3x2_array(Tag, unsigned, const float *); - void uniform_matrix4x2_array(Tag, unsigned, const float *); - void uniform_matrix2x3_array(Tag, unsigned, const float *); - void uniform_matrix3_array(Tag, unsigned, const float *); - void uniform_matrix4x3_array(Tag, unsigned, const float *); - void uniform_matrix2x4_array(Tag, unsigned, const float *); - void uniform_matrix3x4_array(Tag, unsigned, const float *); - void uniform_matrix4_array(Tag, unsigned, const float *); - void remove_uniform(Tag); - - 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; - -public: - /** Applies uniform blocks for the currently bound program, creating them - if needed. */ - void apply() const; -}; - -} // namespace GL -} // namespace Msp - -#endif