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 library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
00020 #ifndef GLSLVARIABLEMAP_HPP
00021 #define GLSLVARIABLEMAP_HPP
00022 
00023 #include "Glsl.hpp"
00024 #include "ShVariableNode.hpp"
00025 #include "ShProgramNode.hpp"
00026 #include "GlslVariable.hpp"
00027 #include <map>
00028 #include <string>
00029 #include <list>
00030 #include <string>
00031 
00032 namespace shgl {
00033 
00034 struct GlslBindingSpecs {
00035   GlslVarBinding binding;
00036   int max_bindings;
00037   SH::ShSemanticType semantic_type;
00038   bool allow_generic;
00039 };
00040 
00041 class GlslVariableMap {
00042 public:
00043   GlslVariableMap(SH::ShProgramNode* shader, GlslProgramType unit);
00044   
00045   std::string resolve(const SH::ShVariable& v, int index = -1);
00046   std::string resolve(const SH::ShVariable& v, const SH::ShVariable& index);
00047   const GlslVariable& variable(const SH::ShVariableNodePtr& node);
00048   bool contains(const SH::ShVariableNodePtr& node) const;
00049 
00050   typedef std::list<std::string> DeclarationList;
00051 
00052   DeclarationList::const_iterator uniform_begin() const;
00053   DeclarationList::const_iterator uniform_end() const;
00054   DeclarationList::const_iterator regular_begin() const;
00055   DeclarationList::const_iterator regular_end() const;
00056 
00057   typedef std::list<SH::ShVariableNodePtr> NodeList;
00058   
00059   NodeList::iterator node_begin() { return m_nodes.begin(); }
00060   NodeList::iterator node_end() { return m_nodes.end(); }
00061 
00062 private:
00063   SH::ShProgramNode* m_shader;
00064   GlslProgramType m_unit;
00065 
00066   unsigned m_nb_uniform_variables;
00067   unsigned m_nb_regular_variables;
00068   std::map<const SH::ShVariableNodePtr, GlslVariable> m_varmap;
00069   NodeList m_nodes;
00070   
00071   DeclarationList m_uniform_declarations;
00072   DeclarationList m_regular_declarations;
00073 
00074   std::map<GlslVarBinding, int> m_input_bindings;
00075   std::map<GlslVarBinding, int> m_output_bindings;
00076 
00077   void allocate_builtin(const SH::ShVariableNodePtr& node,
00078                         const GlslBindingSpecs* specs, std::map<GlslVarBinding, int>& bindings,
00079                         bool generic);
00080   void allocate_builtin_inputs();
00081   void allocate_builtin_outputs();
00082   void allocate_temp(const SH::ShVariableNodePtr& node);
00083   
00084   void map_insert(const SH::ShVariableNodePtr& node, GlslVariable var);
00085 
00086   std::string real_resolve(const SH::ShVariable& v, const std::string& array_index, int index);
00087   std::string swizzle(const SH::ShVariable& v, int var_size) const;
00088   std::string repeat_scalar(const std::string& name, SH::ShValueType type, int size) const;
00089 };
00090 
00091 }
00092 
00093 #endif /* GLSLVARIABLEMAP_HPP */

Generated on Thu Jul 28 17:33:00 2005 for Sh by  doxygen 1.4.3-20050530