GlslVariable.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 GLSLVARIABLE_HPP
00021 #define GLSLVARIABLE_HPP
00022 
00023 #include "Glsl.hpp"
00024 #include "ShVariableType.hpp"
00025 #include "ShVariableNode.hpp"
00026 #include <string>
00027 
00028 namespace shgl {
00029 
00031 enum GlslVarBinding {
00032   // Output for vertex, input for fragment
00033   SH_GLSL_VAR_TEXCOORD,
00034 
00035   // Inputs to both units
00036   SH_GLSL_VAR_COLOR,
00037   SH_GLSL_VAR_SECONDARYCOLOR,
00038 
00039   // Vertex inputs
00040   SH_GLSL_VAR_VERTEX,
00041   SH_GLSL_VAR_NORMAL,
00042   SH_GLSL_VAR_MULTITEXCOORD0,
00043   SH_GLSL_VAR_MULTITEXCOORD1,
00044   SH_GLSL_VAR_MULTITEXCOORD2,
00045   SH_GLSL_VAR_MULTITEXCOORD3,
00046   SH_GLSL_VAR_MULTITEXCOORD4,
00047   SH_GLSL_VAR_MULTITEXCOORD5,
00048   SH_GLSL_VAR_MULTITEXCOORD6,
00049   SH_GLSL_VAR_MULTITEXCOORD7,
00050   
00051   // Fragment inputs
00052   SH_GLSL_VAR_FRAGCOORD,
00053 
00054   // Vertex outputs
00055   SH_GLSL_VAR_POSITION,
00056   SH_GLSL_VAR_FRONTCOLOR,
00057   SH_GLSL_VAR_FRONTSECONDARYCOLOR,
00058 
00059   // Fragment outputs
00060   SH_GLSL_VAR_FRAGDEPTH,
00061   SH_GLSL_VAR_FRAGCOLOR,
00062   SH_GLSL_VAR_FRAGDATA,
00063 
00064   SH_GLSL_VAR_NONE
00065 };
00066 
00067 struct GlslVarBindingInfo {
00068   char* name;
00069   int size;
00070   bool indexed;
00071 };
00072 
00073 class GlslVariable {
00074 public:
00075   static const GlslVarBindingInfo glslVarBindingInfo[SH_GLSL_VAR_NONE];
00076 
00077   GlslVariable(const SH::ShVariableNodePtr& v); 
00078   GlslVariable(); 
00079   GlslVariable(const GlslVariable& v); 
00080   
00081   std::string declaration() const;
00082 
00083   const std::string& name() const { return m_name; }
00084   const int attribute() const { return m_attribute; }
00085   const SH::ShSemanticType& semantic_type() const { return m_semantic_type; }
00086   const int size() const { return m_size; }
00087   const bool builtin() const { return m_builtin; }
00088   const bool uniform() const { return m_uniform; }
00089   const bool texture() const { return m_texture; }
00090 
00091   void name(int i, enum GlslProgramType unit); 
00092   void attribute(int index); 
00093   void builtin(GlslVarBinding binding, int index); 
00094   
00095 private:
00096   int m_attribute; 
00097   bool m_builtin; 
00098   bool m_texture;
00099   bool m_palette;
00100   bool m_uniform;
00101 
00102   std::string m_name;
00103 
00104   int m_size;
00105   SH::ShTextureDims m_dims; // if m_texture == true
00106   std::size_t m_length; // if m_palette == true
00107 
00108   SH::ShBindingType m_kind;
00109   SH::ShValueType m_type;
00110   SH::ShSemanticType m_semantic_type;
00111 
00112   std::string m_values;
00113   
00114   std::string type_string() const;
00115 };
00116 
00117 }
00118 
00119 #endif /* GLSLVARIABLE_HPP */

Generated on Wed Nov 9 15:29:24 2005 for Sh by  doxygen 1.4.5