X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Freflect.h;h=9520feb6a924c797ee50b7e8a062dbd7b1f74795;hb=c701c8787cb19fbb6dc5b0bfae1a94e2b07dd549;hp=a48ad53f8cfa9b960665af6a61cd66e2a475d686;hpb=70d9d2d28e5fe723c6b46894276e4c935f578e2d;p=libs%2Fgl.git diff --git a/source/glsl/reflect.h b/source/glsl/reflect.h index a48ad53f..9520feb6 100644 --- a/source/glsl/reflect.h +++ b/source/glsl/reflect.h @@ -7,6 +7,32 @@ namespace Msp { namespace GL { namespace SL { +/** Compares two types for equality. Struct types are compared recursively. */ +class TypeComparer: private NodeVisitor +{ +private: + Node *first; + Node *second; + unsigned first_tag; + bool r_result; + + static unsigned next_tag; + +public: + TypeComparer(); + + bool apply(TypeDeclaration &t1, TypeDeclaration &t2) { compare(t1, t2); return r_result; } + +private: + void compare(Node &, Node &); + template + T *multi_visit(T &); + virtual void visit(BasicTypeDeclaration &); + virtual void visit(ImageTypeDeclaration &); + virtual void visit(StructDeclaration &); + virtual void visit(VariableDeclaration &); +}; + /** Determines the number of interface locations required by a variable. */ class LocationCounter: private NodeVisitor { @@ -25,6 +51,49 @@ 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 +{ +private: + std::set dependencies; + std::set locals; + +public: + std::set apply(FunctionDeclaration &); + +private: + virtual void visit(VariableReference &); + virtual void visit(InterfaceBlockReference &); + virtual void visit(FunctionCall &); + virtual void visit(VariableDeclaration &); +}; + } // namespace SL } // namespace GL } // namespace Msp