Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

GlslVariableMap.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2005 Serious Hack Inc.
00004 // 
00005 // This software is provided 'as-is', without any express or implied
00006 // warranty. In no event will the authors be held liable for any damages
00007 // arising from the use of this software.
00008 // 
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it
00011 // freely, subject to the following restrictions:
00012 // 
00013 // 1. The origin of this software must not be misrepresented; you must
00014 // not claim that you wrote the original software. If you use this
00015 // software in a product, an acknowledgment in the product documentation
00016 // would be appreciated but is not required.
00017 // 
00018 // 2. Altered source versions must be plainly marked as such, and must
00019 // not be misrepresented as being the original software.
00020 // 
00021 // 3. This notice may not be removed or altered from any source
00022 // distribution.
00024 #ifndef GLSLVARIABLEMAP_HPP
00025 #define GLSLVARIABLEMAP_HPP
00026 
00027 #include "Glsl.hpp"
00028 #include "ShVariableNode.hpp"
00029 #include "ShProgramNode.hpp"
00030 #include "GlslVariable.hpp"
00031 #include <map>
00032 #include <string>
00033 #include <list>
00034 #include <string>
00035 
00036 namespace shgl {
00037 
00038 struct GlslBindingSpecs {
00039   GlslVarBinding binding;
00040   int max_bindings;
00041   SH::ShSemanticType semantic_type;
00042   bool allow_generic;
00043 };
00044 
00045 class GlslVariableMap {
00046 public:
00047   GlslVariableMap(SH::ShProgramNode* shader, GlslProgramType unit);
00048   
00049   std::string resolve(const SH::ShVariable& v, int index = -1);
00050   std::string resolve(const SH::ShVariable& v, const SH::ShVariable& index);
00051   const GlslVariable& variable(const SH::ShVariableNodePtr& node);
00052   bool contains(const SH::ShVariableNodePtr& node) const;
00053 
00054   typedef std::list<std::string> DeclarationList;
00055 
00056   DeclarationList::const_iterator uniform_begin() const;
00057   DeclarationList::const_iterator uniform_end() const;
00058   DeclarationList::const_iterator regular_begin() const;
00059   DeclarationList::const_iterator regular_end() const;
00060 
00061   typedef std::list<SH::ShVariableNodePtr> NodeList;
00062   
00063   NodeList::iterator node_begin() { return m_nodes.begin(); }
00064   NodeList::iterator node_end() { return m_nodes.end(); }
00065 
00066 private:
00067   SH::ShProgramNode* m_shader;
00068   GlslProgramType m_unit;
00069 
00070   unsigned m_nb_uniform_variables;
00071   unsigned m_nb_regular_variables;
00072   std::map<const SH::ShVariableNodePtr, GlslVariable> m_varmap;
00073   NodeList m_nodes;
00074   
00075   DeclarationList m_uniform_declarations;
00076   DeclarationList m_regular_declarations;
00077 
00078   std::map<GlslVarBinding, int> m_input_bindings;
00079   std::map<GlslVarBinding, int> m_output_bindings;
00080 
00081   void allocate_builtin(const SH::ShVariableNodePtr& node,
00082                         const GlslBindingSpecs* specs, std::map<GlslVarBinding, int>& bindings,
00083                         bool generic);
00084   void allocate_builtin_inputs();
00085   void allocate_builtin_outputs();
00086   void allocate_temp(const SH::ShVariableNodePtr& node);
00087   
00088   void map_insert(const SH::ShVariableNodePtr& node, GlslVariable var);
00089 
00090   std::string real_resolve(const SH::ShVariable& v, const std::string& array_index, int index);
00091   std::string swizzle(const SH::ShVariable& v, int var_size) const;
00092   std::string repeat_scalar(const std::string& name, SH::ShValueType type, int size) const;
00093 };
00094 
00095 }
00096 
00097 #endif /* GLSLVARIABLEMAP_HPP */

Generated on Thu Apr 21 17:32:45 2005 for Sh by  doxygen 1.4.2