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 namespace CS 00044 { 00045 namespace Graphics 00046 { 00047 struct RenderMesh; 00048 } 00049 } 00050 class csShaderVariable; 00051 00052 struct iShader; 00053 struct iShaderCompiler; 00054 struct iShaderManager; 00055 00057 00061 typedef csArray<csShaderVariable*> csShaderVarStack; 00062 struct iShaderVarStack : public iArrayChangeAll<csShaderVariable*> 00063 { 00064 SCF_IARRAYCHANGEALL_INTERFACE (iShaderVarStack); 00065 }; 00067 00069 00072 static inline csShaderVariable* csGetShaderVariableFromStack 00073 (const csShaderVarStack& stack, const csStringID &name) 00074 { 00075 if ((name != csInvalidStringID) && 00076 (name < (csStringID)stack.GetSize ())) 00077 { 00078 return stack[name]; 00079 } 00080 return 0; 00081 } 00082 static inline csShaderVariable* csGetShaderVariableFromStack 00083 (const iShaderVarStack* stack, const csStringID &name) 00084 { 00085 if ((name != csInvalidStringID) && 00086 (name < (csStringID)stack->GetSize ())) 00087 { 00088 return static_cast<const iArrayReadOnly<csShaderVariable*>*> (stack) 00089 ->Get (name); 00090 } 00091 return 0; 00092 } 00094 00099 struct iShaderVariableContext : public virtual iBase 00100 { 00101 SCF_INTERFACE(iShaderVariableContext, 2, 2, 0); 00102 00108 virtual void AddVariable (csShaderVariable *variable) = 0; 00109 00111 virtual csShaderVariable* GetVariable (csStringID name) const = 0; 00112 00114 csShaderVariable* GetVariableAdd (csStringID name) 00115 { 00116 csShaderVariable* sv; 00117 sv = GetVariable (name); 00118 if (sv == 0) 00119 { 00120 csRef<csShaderVariable> nsv ( 00121 csPtr<csShaderVariable> (new csShaderVariable (name))); 00122 AddVariable (nsv); 00123 sv = nsv; // OK, sv won't be destructed, SV context takes ownership 00124 } 00125 return sv; 00126 } 00127 00129 virtual const csRefArray<csShaderVariable>& GetShaderVariables () const = 0; 00130 00135 virtual void PushVariables (iShaderVarStack* stacks) const = 0; 00136 00138 virtual bool IsEmpty () const = 0; 00139 00146 virtual void ReplaceVariable (csShaderVariable* variable) = 0; 00147 00149 virtual void Clear() = 0; 00150 00152 virtual bool RemoveVariable (csShaderVariable* variable) = 0; 00153 00155 virtual bool RemoveVariable (csStringID name) = 0; 00156 }; 00157 00161 enum csShaderTagPresence 00162 { 00167 TagNeutral, 00171 TagForbidden, 00177 TagRequired 00178 }; 00179 00183 struct iShaderManager : public virtual iShaderVariableContext 00184 { 00185 SCF_INTERFACE (iShaderManager, 2, 0, 0); 00190 virtual void RegisterShader (iShader* shader) = 0; 00192 virtual void UnregisterShader (iShader* shader) = 0; 00194 virtual void UnregisterShaders () = 0; 00196 virtual iShader* GetShader (const char* name) = 0; 00198 virtual const csRefArray<iShader> &GetShaders () = 0; 00199 00201 virtual void RegisterCompiler (iShaderCompiler* compiler) = 0; 00203 virtual iShaderCompiler* GetCompiler(const char* name) = 0; 00204 00208 virtual void RegisterShaderVariableAccessor (const char* name, 00209 iShaderVariableAccessor* accessor) = 0; 00213 virtual void UnregisterShaderVariableAccessor (const char* name, 00214 iShaderVariableAccessor* accessor) = 0; 00218 virtual iShaderVariableAccessor* GetShaderVariableAccessor ( 00219 const char* name) = 0; 00220 00224 virtual void UnregisterShaderVariableAcessors () = 0; 00225 00227 virtual iShaderVarStack* GetShaderVariableStack () = 0; 00228 00237 virtual void SetTagOptions (csStringID tag, csShaderTagPresence presence, 00238 int priority = 0) = 0; 00243 virtual void GetTagOptions (csStringID tag, csShaderTagPresence& presence, 00244 int& priority) = 0; 00245 00249 virtual const csSet<csStringID>& GetTags (csShaderTagPresence presence, 00250 int& count) = 0; 00251 00256 virtual void SetActiveLights (const csArray<iLight*>& lights) = 0; 00257 00261 virtual const csArray<iLight*>& GetActiveLights () const = 0; 00262 }; 00263 00271 struct csShaderMetadata 00272 { 00274 char *description; 00275 00281 uint numberOfLights; 00282 00284 csShaderMetadata () 00285 : description (0), numberOfLights (0) 00286 {} 00287 }; 00288 00293 struct iShader : public virtual iShaderVariableContext 00294 { 00295 SCF_INTERFACE(iShader, 3, 1, 0); 00296 00298 virtual iObject* QueryObject () = 0; 00299 00301 virtual const char* GetFileName () = 0; 00302 00304 virtual void SetFileName (const char* filename) = 0; 00305 00316 virtual size_t GetTicket (const CS::Graphics::RenderMeshModes& modes, 00317 const iShaderVarStack* stacks) = 0; 00318 00320 virtual size_t GetNumberOfPasses (size_t ticket) = 0; 00321 00323 virtual bool ActivatePass (size_t ticket, size_t number) = 0; 00324 00326 virtual bool SetupPass (size_t ticket, const CS::Graphics::RenderMesh *mesh, 00327 CS::Graphics::RenderMeshModes& modes, 00328 const iShaderVarStack* stacks) = 0; 00329 00334 virtual bool TeardownPass (size_t ticket) = 0; 00335 00337 virtual bool DeactivatePass (size_t ticket) = 0; 00338 00340 virtual const csShaderMetadata& GetMetadata (size_t ticket) const = 0; 00341 }; 00342 00343 00347 struct iShaderPriorityList : public virtual iBase 00348 { 00349 SCF_INTERFACE (iShaderPriorityList, 1,0,0); 00351 virtual size_t GetCount () const = 0; 00353 virtual int GetPriority (size_t idx) const = 0; 00354 }; 00355 00361 struct iShaderCompiler : public virtual iBase 00362 { 00363 SCF_INTERFACE (iShaderCompiler, 0,0,1); 00365 virtual const char* GetName() = 0; 00366 00375 virtual csPtr<iShader> CompileShader ( 00376 iLoaderContext* ldr_context, iDocumentNode *templ, 00377 int forcepriority = -1) = 0; 00378 00380 virtual bool ValidateTemplate (iDocumentNode *templ) = 0; 00381 00383 virtual bool IsTemplateToCompiler (iDocumentNode *templ) = 0; 00384 00390 virtual csPtr<iShaderPriorityList> GetPriorities ( 00391 iDocumentNode* templ) = 0; 00392 }; 00393 00394 #endif // __CS_IVIDEO_SHADER_H__
Generated for Crystal Space 1.4.1 by doxygen 1.7.1