ivideo/shader/shader.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2002 by Marten Svanfeldt 00003 Anders Stenberg 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 00021 #ifndef __CS_IVIDEO_SHADER_H__ 00022 #define __CS_IVIDEO_SHADER_H__ 00023 00028 #include "csutil/scf.h" 00029 00030 #include "iutil/array.h" 00031 00032 #include "csgfx/shadervar.h" 00033 #include "csutil/array.h" 00034 #include "csutil/refarr.h" 00035 #include "csutil/set.h" 00036 #include "csutil/strset.h" 00037 00038 struct iDocumentNode; 00039 struct iLight; 00040 struct iObject; 00041 struct iLoaderContext; 00042 00043 struct csRenderMesh; 00044 class csShaderVariable; 00045 00046 struct iShader; 00047 struct iShaderCompiler; 00048 struct iShaderManager; 00049 00051 00055 typedef csArray<csShaderVariable*> csShaderVarStack; 00056 struct iShaderVarStack : public iArrayChangeAll<csShaderVariable*> 00057 { 00058 SCF_IARRAYCHANGEALL_INTERFACE (iShaderVarStack); 00059 }; 00061 00063 00066 static inline csShaderVariable* csGetShaderVariableFromStack 00067 (const csShaderVarStack& stack, const csStringID &name) 00068 { 00069 if ((name != csInvalidStringID) && 00070 (name < (csStringID)stack.Length ())) 00071 { 00072 return stack[name]; 00073 } 00074 return 0; 00075 } 00076 static inline csShaderVariable* csGetShaderVariableFromStack 00077 (const iShaderVarStack* stack, const csStringID &name) 00078 { 00079 if ((name != csInvalidStringID) && 00080 (name < (csStringID)stack->GetSize ())) 00081 { 00082 return static_cast<const iArrayReadOnly<csShaderVariable*>*> (stack) 00083 ->Get (name); 00084 } 00085 return 0; 00086 } 00088 00093 struct iShaderVariableContext : public virtual iBase 00094 { 00095 SCF_INTERFACE(iShaderVariableContext, 2, 1, 1); 00096 00102 virtual void AddVariable (csShaderVariable *variable) = 0; 00103 00105 virtual csShaderVariable* GetVariable (csStringID name) const = 0; 00106 00108 csShaderVariable* GetVariableAdd (csStringID name) 00109 { 00110 csShaderVariable* sv; 00111 sv = GetVariable (name); 00112 if (sv == 0) 00113 { 00114 csRef<csShaderVariable> nsv ( 00115 csPtr<csShaderVariable> (new csShaderVariable (name))); 00116 AddVariable (nsv); 00117 sv = nsv; // OK, sv won't be destructed, SV context takes ownership 00118 } 00119 return sv; 00120 } 00121 00123 virtual const csRefArray<csShaderVariable>& GetShaderVariables () const = 0; 00124 00129 virtual void PushVariables (iShaderVarStack* stacks) const = 0; 00130 00132 virtual bool IsEmpty () const = 0; 00133 00140 virtual void ReplaceVariable (csShaderVariable* variable) = 0; 00141 00143 virtual void Clear() = 0; 00144 00146 virtual bool RemoveVariable (csShaderVariable* variable) = 0; 00147 }; 00148 00152 enum csShaderTagPresence 00153 { 00158 TagNeutral, 00162 TagForbidden, 00168 TagRequired 00169 }; 00170 00174 struct iShaderManager : public virtual iShaderVariableContext 00175 { 00176 SCF_INTERFACE (iShaderManager, 1, 1, 0); 00181 virtual void RegisterShader (iShader* shader) = 0; 00183 virtual void UnregisterShader (iShader* shader) = 0; 00185 virtual iShader* GetShader (const char* name) = 0; 00187 virtual const csRefArray<iShader> &GetShaders () = 0; 00188 00190 virtual void RegisterCompiler (iShaderCompiler* compiler) = 0; 00192 virtual iShaderCompiler* GetCompiler(const char* name) = 0; 00193 00195 virtual iShaderVarStack* GetShaderVariableStack () = 0; 00196 00205 virtual void SetTagOptions (csStringID tag, csShaderTagPresence presence, 00206 int priority = 0) = 0; 00211 virtual void GetTagOptions (csStringID tag, csShaderTagPresence& presence, 00212 int& priority) = 0; 00213 00217 virtual const csSet<csStringID>& GetTags (csShaderTagPresence presence, 00218 int& count) = 0; 00219 00224 virtual void SetActiveLights (const csArray<iLight*>& lights) = 0; 00225 00229 virtual const csArray<iLight*>& GetActiveLights () const = 0; 00230 }; 00231 00239 struct csShaderMetadata 00240 { 00242 char *description; 00243 00249 uint numberOfLights; 00250 00252 csShaderMetadata () 00253 : description (0), numberOfLights (0) 00254 {} 00255 }; 00256 00261 struct iShader : public virtual iShaderVariableContext 00262 { 00263 SCF_INTERFACE(iShader, 3, 1, 0); 00264 00266 virtual iObject* QueryObject () = 0; 00267 00269 virtual const char* GetFileName () = 0; 00270 00272 virtual void SetFileName (const char* filename) = 0; 00273 00284 virtual size_t GetTicket (const csRenderMeshModes& modes, 00285 const iShaderVarStack* stacks) = 0; 00286 00288 virtual size_t GetNumberOfPasses (size_t ticket) = 0; 00289 00291 virtual bool ActivatePass (size_t ticket, size_t number) = 0; 00292 00294 virtual bool SetupPass (size_t ticket, const csRenderMesh *mesh, 00295 csRenderMeshModes& modes, 00296 const iShaderVarStack* stacks) = 0; 00297 00302 virtual bool TeardownPass (size_t ticket) = 0; 00303 00305 virtual bool DeactivatePass (size_t ticket) = 0; 00306 00308 virtual const csShaderMetadata& GetMetadata (size_t ticket) const = 0; 00309 }; 00310 00311 00315 struct iShaderPriorityList : public virtual iBase 00316 { 00317 SCF_INTERFACE (iShaderPriorityList, 1,0,0); 00319 virtual size_t GetCount () const = 0; 00321 virtual int GetPriority (size_t idx) const = 0; 00322 }; 00323 00329 struct iShaderCompiler : public virtual iBase 00330 { 00331 SCF_INTERFACE (iShaderCompiler, 0,0,1); 00333 virtual const char* GetName() = 0; 00334 00343 virtual csPtr<iShader> CompileShader ( 00344 iLoaderContext* ldr_context, iDocumentNode *templ, 00345 int forcepriority = -1) = 0; 00346 00348 virtual bool ValidateTemplate (iDocumentNode *templ) = 0; 00349 00351 virtual bool IsTemplateToCompiler (iDocumentNode *templ) = 0; 00352 00358 virtual csPtr<iShaderPriorityList> GetPriorities ( 00359 iDocumentNode* templ) = 0; 00360 }; 00361 00362 #endif // __CS_IVIDEO_SHADER_H__
Generated for Crystal Space by doxygen 1.4.7