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

GlslVariable.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 GLSLVARIABLE_HPP
00025 #define GLSLVARIABLE_HPP
00026 
00027 #include "Glsl.hpp"
00028 #include "ShVariableType.hpp"
00029 #include "ShVariableNode.hpp"
00030 #include <string>
00031 
00032 namespace shgl {
00033 
00035 enum GlslVarBinding {
00036   // Output for vertex, input for fragment
00037   SH_GLSL_VAR_TEXCOORD,
00038 
00039   // Inputs to both units
00040   SH_GLSL_VAR_COLOR,
00041   SH_GLSL_VAR_SECONDARYCOLOR,
00042 
00043   // Vertex inputs
00044   SH_GLSL_VAR_VERTEX,
00045   SH_GLSL_VAR_NORMAL,
00046   SH_GLSL_VAR_MULTITEXCOORD0,
00047   SH_GLSL_VAR_MULTITEXCOORD1,
00048   SH_GLSL_VAR_MULTITEXCOORD2,
00049   SH_GLSL_VAR_MULTITEXCOORD3,
00050   SH_GLSL_VAR_MULTITEXCOORD4,
00051   SH_GLSL_VAR_MULTITEXCOORD5,
00052   SH_GLSL_VAR_MULTITEXCOORD6,
00053   SH_GLSL_VAR_MULTITEXCOORD7,
00054   
00055   // Fragment inputs
00056   SH_GLSL_VAR_FRAGCOORD,
00057 
00058   // Vertex outputs
00059   SH_GLSL_VAR_POSITION,
00060   SH_GLSL_VAR_FRONTCOLOR,
00061   SH_GLSL_VAR_FRONTSECONDARYCOLOR,
00062 
00063   // Fragment outputs
00064   SH_GLSL_VAR_FRAGDEPTH,
00065   SH_GLSL_VAR_FRAGCOLOR,
00066 
00067   SH_GLSL_VAR_NONE
00068 };
00069 
00070 struct GlslVarBindingInfo {
00071   char* name;
00072   int size;
00073   bool indexed;
00074 };
00075 
00076 class GlslVariable {
00077 public:
00078   static const GlslVarBindingInfo glslVarBindingInfo[SH_GLSL_VAR_NONE];
00079 
00080   GlslVariable(const SH::ShVariableNodePtr& v); 
00081   GlslVariable(); 
00082   GlslVariable(const GlslVariable& v); 
00083   
00084   std::string declaration() const;
00085 
00086   const std::string& name() const { return m_name; }
00087   const SH::ShSemanticType& semantic_type() const { return m_semantic_type; }
00088   const int size() const { return m_size; }
00089   const bool builtin() const { return m_builtin; }
00090   const bool uniform() const { return m_uniform; }
00091   const bool texture() const { return m_texture; }
00092 
00093   void name(int i, enum GlslProgramType unit); 
00094   void builtin(GlslVarBinding binding, int index); 
00095   
00096 private:
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 Thu Apr 21 17:32:45 2005 for Sh by  doxygen 1.4.2