CrystalSpace

Public API Reference

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 "csgfx/shadervar.h"
00031 
00032 #include "csutil/array.h"
00033 #include "csutil/refarr.h"
00034 #include "csutil/set.h"
00035 #include "csutil/strset.h"
00036 
00037 struct iDocumentNode;
00038 struct iLight;
00039 struct iObject;
00040 
00041 struct csRenderMesh;
00042 class csShaderVariable;
00043 
00044 struct iShader;
00045 struct iShaderCompiler;
00046 struct iShaderManager;
00047 
00052 typedef csArray<csShaderVariable*> csShaderVarStack;
00053 
00057 static inline csShaderVariable* csGetShaderVariableFromStack 
00058   (const csShaderVarStack& stack, const csStringID &name)
00059 {
00060   if ((name != csInvalidStringID) &&
00061       (name < (csStringID)stack.Length ()))
00062   {
00063     return stack[name];
00064   }
00065   return 0;
00066 }
00067 
00072 struct iShaderVariableContext : public virtual iBase
00073 {
00074   SCF_INTERFACE(iShaderVariableContext, 2, 0, 0);
00075 
00081   virtual void AddVariable (csShaderVariable *variable) = 0;
00082   
00084   virtual csShaderVariable* GetVariable (csStringID name) const = 0;
00085 
00087   csShaderVariable* GetVariableAdd (csStringID name)
00088   {
00089     csShaderVariable* sv;
00090     sv = GetVariable (name);
00091     if (sv == 0)
00092     {
00093       csRef<csShaderVariable> nsv (
00094         csPtr<csShaderVariable> (new csShaderVariable (name)));
00095       AddVariable (nsv);
00096       sv = nsv; // OK, sv won't be destructed, SV context takes ownership
00097     }
00098     return sv;
00099   }
00100 
00102   virtual const csRefArray<csShaderVariable>& GetShaderVariables () const = 0;
00103 
00108   virtual void PushVariables (csShaderVarStack &stacks) const = 0;
00109 
00111   virtual bool IsEmpty () const = 0;
00112 
00119   virtual void ReplaceVariable (csShaderVariable* variable) = 0;
00120   
00122   virtual void Clear() = 0;
00123 };
00124 
00125 SCF_VERSION (iShaderManager, 0, 1, 0);
00126 
00130 enum csShaderTagPresence
00131 {
00136   TagNeutral,
00140   TagForbidden,
00146   TagRequired
00147 };
00148 
00152 struct iShaderManager : public iShaderVariableContext
00153 {
00158   virtual void RegisterShader (iShader* shader) = 0;
00160   virtual void UnregisterShader (iShader* shader) = 0;
00162   virtual iShader* GetShader (const char* name) = 0;
00164   virtual const csRefArray<iShader> &GetShaders ()  = 0;
00165 
00167   virtual void RegisterCompiler (iShaderCompiler* compiler) = 0;
00169   virtual iShaderCompiler* GetCompiler(const char* name) = 0;
00170 
00172   virtual csShaderVarStack& GetShaderVariableStack () = 0;
00173 
00182   virtual void SetTagOptions (csStringID tag, csShaderTagPresence presence, 
00183     int priority = 0) = 0;
00188   virtual void GetTagOptions (csStringID tag, csShaderTagPresence& presence, 
00189     int& priority) = 0;
00190 
00194   virtual const csSet<csStringID>& GetTags (csShaderTagPresence presence,
00195     int& count) = 0;
00196 
00201   virtual void SetActiveLights (const csArray<iLight*>& lights) = 0;
00202 
00206   virtual const csArray<iLight*>& GetActiveLights () const = 0;
00207 };
00208 
00216 struct csShaderMetadata
00217 {
00219   char *description;
00220 
00226   uint numberOfLights;
00227 
00229   csShaderMetadata ()
00230     : description (0), numberOfLights (0)
00231   {}
00232 };
00233 
00238 struct iShader : public iShaderVariableContext
00239 {
00240   SCF_INTERFACE(iShader, 2, 0, 0);
00241 
00243   virtual iObject* QueryObject () = 0;
00244 
00246   virtual const char* GetFileName () = 0;
00247 
00249   virtual void SetFileName (const char* filename) = 0;
00250 
00261   virtual size_t GetTicket (const csRenderMeshModes& modes,
00262     const csShaderVarStack& stacks) = 0;
00263 
00265   virtual size_t GetNumberOfPasses (size_t ticket) = 0;
00266 
00268   virtual bool ActivatePass (size_t ticket, size_t number) = 0;
00269 
00271   virtual bool SetupPass (size_t ticket, const csRenderMesh *mesh,
00272     csRenderMeshModes& modes,
00273     const csShaderVarStack& stacks) = 0;
00274 
00279   virtual bool TeardownPass (size_t ticket) = 0;
00280 
00282   virtual bool DeactivatePass (size_t ticket) = 0;
00283 
00285   virtual const csShaderMetadata& GetMetadata (size_t ticket) const = 0;
00286 };
00287 
00288 
00289 SCF_VERSION (iShaderPriorityList, 0,0,1);
00293 struct iShaderPriorityList : public iBase
00294 {
00296   virtual size_t GetCount () const = 0;
00298   virtual int GetPriority (size_t idx) const = 0;
00299 };
00300 
00301 SCF_VERSION (iShaderCompiler, 0,0,1);
00307 struct iShaderCompiler : public virtual iBase
00308 {
00310   virtual const char* GetName() = 0;
00311 
00320   virtual csPtr<iShader> CompileShader (iDocumentNode *templ,
00321                   int forcepriority = -1) = 0;
00322 
00324   virtual bool ValidateTemplate (iDocumentNode *templ) = 0;
00325 
00327   virtual bool IsTemplateToCompiler (iDocumentNode *templ) = 0;
00328 
00334   virtual csPtr<iShaderPriorityList> GetPriorities (
00335                   iDocumentNode* templ) = 0;
00336 };
00337 
00338 #endif // __CS_IVIDEO_SHADER_H__

Generated for Crystal Space by doxygen 1.4.6