]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/reflect.h
Add visitors to calculate offsets of struct members
[libs/gl.git] / source / glsl / reflect.h
index 72a50c3eb6368b303ba5bd6e2fad8f7095e0189b..162ed9c0b8bcf4ddb01daf17724e4308138decd0 100644 (file)
@@ -25,6 +25,31 @@ private:
        virtual void visit(VariableDeclaration &);
 };
 
+/** Determines the size and alignment of a variable, in bytes. */
+class MemoryRequirementsCalculator: private NodeVisitor
+{
+public:
+       struct Result
+       {
+               unsigned size;
+               unsigned alignment;
+
+               Result(unsigned s, unsigned a): size(s), alignment(a) { }
+       };
+private:
+       unsigned r_size;
+       unsigned r_alignment;
+       int r_offset;
+
+public:
+       Result apply(VariableDeclaration &v) { v.visit(*this); return Result(r_size, r_alignment); }
+
+private:
+       virtual void visit(BasicTypeDeclaration &);
+       virtual void visit(StructDeclaration &);
+       virtual void visit(VariableDeclaration &);
+};
+
 /** Collects dependencies of a function.  This includes global variables,
 interface blocks, other functions and types. */
 class DependencyCollector: private TraversingVisitor