]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/uniformblock.h
Check the flat qualifier from the correct member
[libs/gl.git] / source / core / uniformblock.h
index bc0b933b01666f3a8e4df77fb1e179f1a8123652..1144158d2ee3ae760bb994be535b8657c9650faa 100644 (file)
@@ -1,73 +1,42 @@
 #ifndef MSP_GL_UNIFORMBLOCK_H_
 #define MSP_GL_UNIFORMBLOCK_H_
 
-#include <map>
 #include <vector>
+#include <msp/core/noncopyable.h>
 #include "bufferable.h"
-#include "program.h"
-#include "vector.h"
+#include "reflectdata.h"
+#include "uniformblock_backend.h"
 
 namespace Msp {
 namespace GL {
 
-class BufferRange;
-class Matrix;
-class Uniform;
-struct Color;
-
 /**
-Stores uniforms with a specific layout.  Both named and default uniform blocks
-are supported.
-*/
-class UniformBlock: public NonCopyable
-{
-protected:
-       UniformBlock() { }
-public:
-       virtual ~UniformBlock() { }
+Stores uniform values in a block of memory.
 
-       virtual void attach(const Program::UniformInfo &, const Uniform &) = 0;
-       virtual void apply(int) const = 0;
-};
-
-/** Stores uniforms for the default uniform block.  Uniforms are associated
-with locations, as returned by Program::get_uniform_location. */
-class DefaultUniformBlock: public UniformBlock
-{
-private:
-       std::vector<const Uniform *> uniforms;
+For named uniform blocks the values are stored according to the reflected
+layout of the block, ready for use by shaders.  For the default uniform block,
+the location of the uniform is multiplied by 16 to obtain the memory offset.
 
-public:
-       DefaultUniformBlock();
-
-       virtual void attach(const Program::UniformInfo &, const Uniform &);
-       void attach(int, const Uniform &);
-       virtual void apply(int) const;
-};
-
-/** Stores uniforms for a buffer-backed uniform block.  Uniform values are
-stored in a memory block which can be uploaded into a buffer and bound for use
-by a Program. */
-class BufferBackedUniformBlock: public UniformBlock, public Bufferable
+Applications normally don't need to deal with UniformBlocks directly.  They're
+managed by the ProgramData class, which provides a higher-level interface for
+setting uniform values.
+*/
+class UniformBlock: public UniformBlockBackend, public Bufferable
 {
 private:
-       unsigned size;
        std::vector<char> data;
-       mutable BufferRange *buf_range;
 
 public:
-       BufferBackedUniformBlock(unsigned);
-       virtual ~BufferBackedUniformBlock();
+       UniformBlock(const ReflectData::UniformBlockInfo &);
 
-private:
-       virtual unsigned get_data_size() const { return size; }
+       virtual std::size_t get_data_size() const { return data.size(); }
        virtual const void *get_data_pointer() const { return &data[0]; }
-       virtual unsigned get_alignment() const;
-       virtual void location_changed(Buffer *, unsigned, unsigned) const;
+private:
+       virtual std::size_t get_alignment() const;
 
 public:
-       void attach(const Program::UniformInfo &, const Uniform &);
-       virtual void apply(int) const;
+       void store(const ReflectData::UniformInfo &, std::size_t, const void *);
+       void check_store_range(std::size_t, std::size_t);
 };
 
 } // namespace GL