]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/program.h
Rename some things in Program
[libs/gl.git] / source / core / program.h
index e86ee0595f0ed307047681f74be256fbf06b3d70..48c18d0f56333371130710942a4dbdc9076e9f45 100644 (file)
@@ -5,13 +5,14 @@
 #include <vector>
 #include <msp/datafile/objectloader.h>
 #include "bindable.h"
+#include "datatype.h"
 #include "gl.h"
+#include "module.h"
 #include "vertexformat.h"
 
 namespace Msp {
 namespace GL {
 
-class Module;
 class Shader;
 
 /**
@@ -36,6 +37,25 @@ public:
                void vertex_shader(const std::string &);
        };
 
+private:
+       class SpecializationLoader: public DataFile::Loader
+       {
+       private:
+               std::map<std::string, int> &spec_values;
+
+               static ActionMap shared_actions;
+
+       public:
+               SpecializationLoader(std::map<std::string, int> &);
+
+       private:
+               virtual void init_actions();
+
+               void specialize_bool(const std::string &, bool);
+               void specialize_int(const std::string &, int);
+       };
+
+public:
        typedef unsigned LayoutHash;
        struct UniformBlockInfo;
 
@@ -43,11 +63,17 @@ public:
        {
                std::string name;
                const UniformBlockInfo *block;
-               unsigned location;
-               unsigned size;
+               union
+               {
+                       int location;
+                       unsigned offset;
+               };
+               unsigned array_size;
                unsigned array_stride;
                unsigned matrix_stride;
-               GLenum type;
+               DataType type;
+
+               UniformInfo();
        };
 
        struct UniformBlockInfo
@@ -57,14 +83,18 @@ public:
                int bind_point;
                std::vector<const UniformInfo *> uniforms;
                LayoutHash layout_hash;
+
+               UniformBlockInfo();
        };
 
        struct AttributeInfo
        {
                std::string name;
                unsigned location;
-               unsigned size;
-               GLenum type;
+               unsigned array_size;
+               DataType type;
+
+               AttributeInfo();
        };
 
        typedef std::map<std::string, UniformInfo> UniformMap;
@@ -73,7 +103,7 @@ public:
 
 private:
        unsigned id;
-       std::vector<unsigned> shader_ids;
+       std::vector<unsigned> stage_ids;
        const Module *module;
        bool linked;
        UniformBlockMap uniform_blocks;
@@ -82,37 +112,49 @@ private:
        AttributeMap attributes;
 
 public:
-       /// Constructs an empty Program with no Shaders attached.
+       /// Constructs an empty Program with no shader stages attached.
        Program();
 
        /// Constructs a Program from unified source code using ProgramCompiler.
-       Program(const std::string &);
+       DEPRECATED Program(const std::string &);
 
        /// Constructs a Program from vertex and fragment shader source code.
        DEPRECATED Program(const std::string &, const std::string &);
 
+       /// Constructs a Program from a Module, with specialization constants.
+       Program(const Module &, const std::map<std::string, int> & = std::map<std::string, int>());
+
 private:
        void init();
 public:
        virtual ~Program();
 
-       void add_stages(const Module &);
+       void add_stages(const Module &, const std::map<std::string, int> & = std::map<std::string, int>());
+private:
+       unsigned add_stage(GLenum);
+       void add_glsl_stages(const GlslModule &, const std::map<std::string, int> &);
+       void compile_glsl_stage(unsigned);
+       void add_spirv_stages(const SpirVModule &, const std::map<std::string, int> &);
 
+public:
        DEPRECATED void attach_shader(Shader &shader);
        DEPRECATED void attach_shader_owned(Shader *shader);
        DEPRECATED void detach_shader(Shader &shader);
        DEPRECATED const std::vector<Shader *> &get_attached_shaders() const;
 
        DEPRECATED void bind_attribute(unsigned, const std::string &);
-       DEPRECATED void bind_attribute(VertexComponent, const std::string &);
+       DEPRECATED void bind_attribute(VertexAttribute, const std::string &);
        DEPRECATED void bind_fragment_data(unsigned, const std::string &);
 
        void link();
 private:
-       static void require_type(GLenum);
        void query_uniforms();
        void query_uniform_blocks(const std::vector<UniformInfo *> &);
        void query_attributes();
+       void collect_uniforms();
+       void collect_block_uniforms(UniformBlockInfo &, const SpirVModule::Structure &, const std::string &, unsigned);
+       void collect_attributes();
+       void update_layout_hash();
        static LayoutHash compute_layout_hash(const std::vector<const UniformInfo *> &);
        static bool uniform_location_compare(const UniformInfo *, const UniformInfo *);
 public: