CrystalSpace

Public API Reference

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

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 
00068 SCF_VERSION (iShaderVariableContext, 0, 0, 2);
00069 
00074 struct iShaderVariableContext : public iBase
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 
00209 SCF_VERSION (iShaderRenderInterface, 0,0,1);
00210 
00212 struct iShaderRenderInterface : public iBase
00213 {
00215   virtual void* GetPrivateObject(const char* name) = 0;
00216 };
00217 
00225 struct csShaderMetadata
00226 {
00228   char *description;
00229 
00235   uint numberOfLights;
00236 
00238   csShaderMetadata ()
00239     : description (0), numberOfLights (0)
00240   {}
00241 };
00242 
00243 SCF_VERSION (iShader, 0, 3, 0);
00244 
00249 struct iShader : public iShaderVariableContext
00250 {
00252   virtual iObject* QueryObject () = 0;
00253 
00255   virtual const char* GetFileName () = 0;
00256 
00258   virtual void SetFileName (const char* filename) = 0;
00259 
00270   virtual size_t GetTicket (const csRenderMeshModes& modes,
00271     const csShaderVarStack& stacks) = 0;
00272 
00274   virtual size_t GetNumberOfPasses (size_t ticket) = 0;
00275 
00277   virtual bool ActivatePass (size_t ticket, size_t number) = 0;
00278 
00280   virtual bool SetupPass (size_t ticket, const csRenderMesh *mesh,
00281     csRenderMeshModes& modes,
00282     const csShaderVarStack& stacks) = 0;
00283 
00288   virtual bool TeardownPass (size_t ticket) = 0;
00289 
00291   virtual bool DeactivatePass (size_t ticket) = 0;
00292 
00294   virtual const csShaderMetadata& GetMetadata (size_t ticket) const = 0;
00295 };
00296 
00297 
00298 SCF_VERSION (iShaderPriorityList, 0,0,1);
00302 struct iShaderPriorityList : public iBase
00303 {
00305   virtual size_t GetCount () const = 0;
00307   virtual int GetPriority (size_t idx) const = 0;
00308 };
00309 
00310 SCF_VERSION (iShaderCompiler, 0,0,1);
00316 struct iShaderCompiler : public virtual iBase
00317 {
00319   virtual const char* GetName() = 0;
00320 
00329   virtual csPtr<iShader> CompileShader (iDocumentNode *templ,
00330                   int forcepriority = -1) = 0;
00331 
00333   virtual bool ValidateTemplate (iDocumentNode *templ) = 0;
00334 
00336   virtual bool IsTemplateToCompiler (iDocumentNode *templ) = 0;
00337 
00343   virtual csPtr<iShaderPriorityList> GetPriorities (
00344                   iDocumentNode* templ) = 0;
00345 };
00346 
00347 #endif // __CS_IVIDEO_SHADER_H__

Generated for Crystal Space by doxygen 1.4.4