X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprogramdata.h;h=f11a254cb8014e5ec9a341f5c695c5685b7c802c;hp=605b41b1359c0da3146b05d2b78e9cf7dfb96e9f;hb=HEAD;hpb=d971f8d4848c0b3b453c626a2dafe19445e3e5a8 diff --git a/source/programdata.h b/source/programdata.h deleted file mode 100644 index 605b41b1..00000000 --- a/source/programdata.h +++ /dev/null @@ -1,238 +0,0 @@ -#ifndef MSP_GL_PROGRAMDATA_H_ -#define MSP_GL_PROGRAMDATA_H_ - -#include -#include -#include "datatype.h" -#include "matrix.h" -#include "program.h" -#include "vector.h" - -namespace Msp { -namespace GL { - -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 NamedUniform - { - std::string name; - Uniform *value; - - NamedUniform(); - - bool compare_name(const std::string &, unsigned) const; - void replace_value(Uniform *); - }; - - struct SharedBlock - { - Mask used; - Mask dirty; - UniformBlock *block; - union - { - UInt8 type_flag; - UInt8 values[16]; - struct - { - UInt8 type_flag; - UInt8 *values; - } dynamic; - } indices; - - SharedBlock(UniformBlock *); - - const UInt8 *get_uniform_indices() const; - }; - - struct ProgramBlock - { - int bind_point; - UniformBlock *block; - SharedBlock *shared; - - ProgramBlock(); - ProgramBlock(int, SharedBlock *); - }; - - struct ProgramUniforms - { - std::vector blocks; - Mask used; - Mask dirty; - - ProgramUniforms(); - }; - - 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; - mutable Buffer *buffer; - mutable unsigned dirty; - -public: - ProgramData(const Program * = 0); - ProgramData(const ProgramData &); - ProgramData &operator=(const ProgramData &); - ~ProgramData(); - -private: - void uniform(const std::string &, Uniform *); -public: - void uniform(const std::string &, const Uniform &); - void uniform(const std::string &, int); - void uniform(const std::string &, float); - void uniform(const std::string &, int, int); - void uniform(const std::string &, float, float); - void uniform2(const std::string &, const int *); - void uniform2(const std::string &, const float *); - void uniform(const std::string &, int, int, int); - void uniform(const std::string &, float, float, float); - void uniform(const std::string &, const Vector3 &); - void uniform3(const std::string &, const int *); - void uniform3(const std::string &, const float *); - void uniform(const std::string &, int, int, int, int); - void uniform(const std::string &, float, float, float, float); - void uniform(const std::string &, const Vector4 &); - void uniform(const std::string &, const Color &); - void uniform4(const std::string &, const int *); - void uniform4(const std::string &, const float *); - void uniform(const std::string &, const LinAl::Matrix &); - void uniform_matrix2(const std::string &, const float *); - void uniform(const std::string &, const LinAl::Matrix &); - void uniform_matrix3x2(const std::string &, const float *); - void uniform(const std::string &, const LinAl::Matrix &); - void uniform_matrix4x2(const std::string &, const float *); - void uniform(const std::string &, const LinAl::Matrix &); - void uniform_matrix2x3(const std::string &, const float *); - void uniform(const std::string &, const LinAl::Matrix &); - void uniform_matrix3(const std::string &, const float *); - void uniform(const std::string &, const LinAl::Matrix &); - void uniform_matrix4x3(const std::string &, const float *); - void uniform(const std::string &, const LinAl::Matrix &); - void uniform_matrix2x4(const std::string &, const float *); - void uniform(const std::string &, const LinAl::Matrix &); - void uniform_matrix3x4(const std::string &, const float *); - void uniform(const std::string &, const Matrix &); - void uniform_matrix4(const std::string &, const float *); - void uniform1_array(const std::string &, unsigned, const int *); - void uniform1_array(const std::string &, unsigned, const float *); - void uniform2_array(const std::string &, unsigned, const int *); - void uniform2_array(const std::string &, unsigned, const float *); - void uniform3_array(const std::string &, unsigned, const int *); - void uniform3_array(const std::string &, unsigned, const float *); - void uniform4_array(const std::string &, unsigned, const int *); - void uniform4_array(const std::string &, unsigned, const float *); - void uniform_matrix2_array(const std::string &, unsigned, const float *); - void uniform_matrix3x2_array(const std::string &, unsigned, const float *); - void uniform_matrix4x2_array(const std::string &, unsigned, const float *); - void uniform_matrix2x3_array(const std::string &, unsigned, const float *); - void uniform_matrix3_array(const std::string &, unsigned, const float *); - void uniform_matrix4x3_array(const std::string &, unsigned, const float *); - void uniform_matrix2x4_array(const std::string &, unsigned, const float *); - void uniform_matrix3x4_array(const std::string &, unsigned, const float *); - void uniform_matrix4_array(const std::string &, unsigned, const float *); - void remove_uniform(const std::string &); - - std::vector get_uniform_names() const; - const Uniform &get_uniform(const std::string &) const; - -private: - static bool uniform_name_compare(const NamedUniform &, const std::string &); - int find_uniform_index(const std::string &) 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; - -public: - /** Applies uniform blocks for the currently bound program, creating them - if needed. */ - void apply() const; -}; - -} // namespace GL -} // namespace Msp - -#endif