]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/finalize.h
Use default member initializers for simple types
[libs/gl.git] / source / glsl / finalize.h
index 28145aebd9e2837abedcb2b5ec54ae3b8f745414..1fe5fa45a494b02988c90f37068ee4c34e760ca1 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef MSP_GL_SL_COMPATIBILITY_H_
-#define MSP_GL_SL_COMPATIBILITY_H_
+#ifndef MSP_GL_SL_FINALIZE_H_
+#define MSP_GL_SL_FINALIZE_H_
 
 #include <string>
 #include "visitor.h"
@@ -8,23 +8,52 @@ namespace Msp {
 namespace GL {
 namespace SL {
 
+/** Assigns offset layout qualifiers to struct members. */
+class StructOrganizer: private TraversingVisitor
+{
+private:
+       int offset = -1;
+
+public:
+       void apply(Stage &s) { s.content.visit(*this); }
+
+private:
+       virtual void visit(StructDeclaration &);
+       virtual void visit(VariableDeclaration &);
+};
+
+/** Assigns location and binding layout qualifiers to interface variables and
+blocks. */
 class LocationAllocator: private TraversingVisitor
 {
 private:
+       struct Uniform
+       {
+               int location;
+               int desc_set;
+               int bind_point;
+
+               Uniform(): location(-1), desc_set(-1), bind_point(-1) { }
+       };
+
        std::map<std::string, std::set<unsigned> > used_locations;
-       std::map<std::string, unsigned> uniform_locations;
+       std::map<std::string, Uniform> uniforms;
+       std::map<unsigned, std::set<unsigned> > used_bindings;
        std::vector<VariableDeclaration *> unplaced_variables;
+       std::vector<VariableDeclaration *> unbound_textures;
+       std::vector<InterfaceBlock *> unbound_blocks;
 
 public:
-       void apply(Module &);
+       void apply(Module &, const Features &);
 private:
        void apply(Stage &);
 
        void allocate_locations(const std::string &);
-       void add_location(RefPtr<Layout> &, unsigned);
+       void bind_uniform(RefPtr<Layout> &, const std::string &, unsigned);
+       void add_layout_value(RefPtr<Layout> &, const std::string &, unsigned);
 
        virtual void visit(VariableDeclaration &);
-       virtual void visit(InterfaceBlock &) { }
+       virtual void visit(InterfaceBlock &);
        virtual void visit(FunctionDeclaration &) { }
 };
 
@@ -33,14 +62,12 @@ according to the requirements of the target API. */
 class PrecisionConverter: private TraversingVisitor
 {
 private:
-       Stage *stage;
+       Stage *stage = 0;
        std::set<std::string> have_default;
        NodeList<Statement>::iterator insert_point;
        std::set<Node *> nodes_to_remove;
 
 public:
-       PrecisionConverter();
-
        void apply(Stage &);
 
 private:
@@ -54,15 +81,13 @@ features. */
 class LegacyConverter: private TraversingVisitor
 {
 private:
-       Stage *stage;
+       Stage *stage = 0;
        Features features;
-       VariableDeclaration *frag_out;
+       VariableDeclaration *frag_out = 0;
        NodeList<Statement>::iterator uniform_insert_point;
        std::set<Node *> nodes_to_remove;
 
 public:
-       LegacyConverter();
-
        virtual void apply(Stage &, const Features &);
 
 private: