Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
shaderprogram.h
00001 /* 00002 Copyright (C) 2004 by Jorrit Tyberghein 00003 (C) 2004 by Frank Richter 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 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 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_SHADERPLUGINS_COMMON_SHADERPROGRAM_H__ 00021 #define __CS_SHADERPLUGINS_COMMON_SHADERPROGRAM_H__ 00022 00023 #include "csextern.h" 00024 #include "csutil/array.h" 00025 #include "csutil/ref.h" 00026 #include "csutil/strhash.h" 00027 00028 #include "csutil/leakguard.h" 00029 #include "iutil/strset.h" 00030 00031 #include "csplugincommon/shader/shaderplugin.h" 00032 00033 struct iDataBuffer; 00034 struct iFile; 00035 struct iSyntaxService; 00036 struct iObjectRegistry; 00037 00043 class CS_CRYSTALSPACE_EXPORT csShaderProgram : public iShaderProgram, 00044 public iShaderTUResolver 00045 { 00046 protected: 00047 csStringHash commonTokens; 00048 #define CS_INIT_TOKEN_TABLE_NAME InitCommonTokens 00049 #define CS_TOKEN_ITEM_FILE \ 00050 "csplugincommon/shader/shaderprogram.tok" 00051 #include "cstool/tokenlist.h" 00052 #undef CS_TOKEN_ITEM_FILE 00053 #undef CS_INIT_TOKEN_TABLE_NAME 00054 00055 protected: 00056 iObjectRegistry* objectReg; 00057 csRef<iSyntaxService> synsrv; 00058 csRef<iStringSet> strings; 00059 00063 enum ProgramParamType 00064 { 00065 ParamInvalid = 0, 00066 ParamFloat = 0x01, 00067 ParamVector2 = 0x02, 00068 ParamVector3 = 0x04, 00069 ParamVector4 = 0x08, 00070 ParamMatrix = 0x10, 00071 ParamTransform = 0x20, 00072 ParamArray = 0x40, 00073 ParamShaderExp = 0x80 00074 }; 00075 00079 struct ProgramParam 00080 { 00081 bool valid; 00082 00083 // Name of SV to use (if any) 00084 csStringID name; 00085 // Reference to const value shadervar 00086 csRef<csShaderVariable> var; 00087 00088 ProgramParam() : valid (false), name(csInvalidStringID) { } 00089 }; 00090 00092 bool ParseProgramParam (iDocumentNode* node, 00093 ProgramParam& param, uint types = ~0); 00094 00098 struct VariableMapEntry : public csShaderVarMapping 00099 { 00100 ProgramParam mappingParam; 00101 intptr_t userVal; 00102 00103 VariableMapEntry (csStringID s, const char* d) : 00104 csShaderVarMapping (s, d) 00105 { 00106 userVal = 0; 00107 mappingParam.name = s; 00108 mappingParam.valid = true; 00109 } 00110 VariableMapEntry (const csShaderVarMapping& other) : 00111 csShaderVarMapping (other.name, other.destination) 00112 { 00113 userVal = 0; 00114 mappingParam.name = other.name; 00115 mappingParam.valid = true; 00116 } 00117 }; 00118 // Variable mappings 00119 csArray<VariableMapEntry> variablemap; 00120 00122 csString description; 00123 00125 csRef<iDocumentNode> programNode; 00127 csRef<iFile> programFile; 00128 00130 csString programFileName; 00131 00136 bool doVerbose; 00137 00139 bool ParseCommon (iDocumentNode* child); 00141 iDocumentNode* GetProgramNode (); 00143 csPtr<iDataBuffer> GetProgramData (); 00144 00146 void DumpProgramInfo (csString& output); 00148 void DumpVariableMappings (csString& output); 00149 00151 00155 inline csVector4 GetParamVectorVal (const csShaderVarStack &stacks, 00156 const ProgramParam ¶m, const csVector4& defVal) 00157 { 00158 csRef<csShaderVariable> var; 00159 00160 var = csGetShaderVariableFromStack (stacks, param.name); 00161 if (!var.IsValid ()) 00162 var = param.var; 00163 00164 // If var is null now we have no const nor any passed value, ignore it 00165 if (!var.IsValid ()) 00166 return defVal; 00167 00168 csVector4 v; 00169 var->GetValue (v); 00170 return v; 00171 } 00172 inline float GetParamFloatVal (const csShaderVarStack &stacks, 00173 const ProgramParam ¶m, float defVal) 00174 { 00175 csRef<csShaderVariable> var; 00176 00177 var = csGetShaderVariableFromStack (stacks, param.name); 00178 if (!var.IsValid ()) 00179 var = param.var; 00180 00181 // If var is null now we have no const nor any passed value, ignore it 00182 if (!var.IsValid ()) 00183 return defVal; 00184 00185 float f; 00186 var->GetValue (f); 00187 return f; 00188 } 00190 public: 00191 SCF_DECLARE_IBASE; 00192 00193 CS_LEAKGUARD_DECLARE (csShaderProgram); 00194 00195 csShaderProgram (iObjectRegistry* objectReg); 00196 virtual ~csShaderProgram (); 00197 00198 virtual int ResolveTextureBinding (const char* /*binding*/) 00199 { return -1; } 00200 }; 00201 00202 #endif // __CS_SHADERPLUGINS_COMMON_SHADERPROGRAM_H__
Generated for Crystal Space by doxygen 1.4.4