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 "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.GetSize ()))
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, 2, 0, 0);
00181   virtual void RegisterShader (iShader* shader) = 0;
00183   virtual void UnregisterShader (iShader* shader) = 0;
00185   virtual void UnregisterShaders () = 0;
00187   virtual iShader* GetShader (const char* name) = 0;
00189   virtual const csRefArray<iShader> &GetShaders ()  = 0;
00190 
00192   virtual void RegisterCompiler (iShaderCompiler* compiler) = 0;
00194   virtual iShaderCompiler* GetCompiler(const char* name) = 0;
00195 
00199   virtual void RegisterShaderVariableAccessor (const char* name,
00200       iShaderVariableAccessor* accessor) = 0;
00204   virtual void UnregisterShaderVariableAccessor (const char* name,
00205       iShaderVariableAccessor* accessor) = 0;
00209   virtual iShaderVariableAccessor* GetShaderVariableAccessor (
00210       const char* name) = 0;
00211 
00215   virtual void UnregisterShaderVariableAcessors () = 0;
00216 
00218   virtual iShaderVarStack* GetShaderVariableStack () = 0;
00219 
00228   virtual void SetTagOptions (csStringID tag, csShaderTagPresence presence, 
00229     int priority = 0) = 0;
00234   virtual void GetTagOptions (csStringID tag, csShaderTagPresence& presence, 
00235     int& priority) = 0;
00236 
00240   virtual const csSet<csStringID>& GetTags (csShaderTagPresence presence,
00241     int& count) = 0;
00242 
00247   virtual void SetActiveLights (const csArray<iLight*>& lights) = 0;
00248 
00252   virtual const csArray<iLight*>& GetActiveLights () const = 0;
00253 };
00254 
00262 struct csShaderMetadata
00263 {
00265   char *description;
00266 
00272   uint numberOfLights;
00273 
00275   csShaderMetadata ()
00276     : description (0), numberOfLights (0)
00277   {}
00278 };
00279 
00284 struct iShader : public virtual iShaderVariableContext
00285 {
00286   SCF_INTERFACE(iShader, 3, 1, 0);
00287 
00289   virtual iObject* QueryObject () = 0;
00290 
00292   virtual const char* GetFileName () = 0;
00293 
00295   virtual void SetFileName (const char* filename) = 0;
00296 
00307   virtual size_t GetTicket (const csRenderMeshModes& modes,
00308     const iShaderVarStack* stacks) = 0;
00309 
00311   virtual size_t GetNumberOfPasses (size_t ticket) = 0;
00312 
00314   virtual bool ActivatePass (size_t ticket, size_t number) = 0;
00315 
00317   virtual bool SetupPass (size_t ticket, const csRenderMesh *mesh,
00318     csRenderMeshModes& modes,
00319     const iShaderVarStack* stacks) = 0;
00320 
00325   virtual bool TeardownPass (size_t ticket) = 0;
00326 
00328   virtual bool DeactivatePass (size_t ticket) = 0;
00329 
00331   virtual const csShaderMetadata& GetMetadata (size_t ticket) const = 0;
00332 };
00333 
00334 
00338 struct iShaderPriorityList : public virtual iBase
00339 {
00340   SCF_INTERFACE (iShaderPriorityList, 1,0,0);
00342   virtual size_t GetCount () const = 0;
00344   virtual int GetPriority (size_t idx) const = 0;
00345 };
00346 
00352 struct iShaderCompiler : public virtual iBase
00353 {
00354   SCF_INTERFACE (iShaderCompiler, 0,0,1);
00356   virtual const char* GetName() = 0;
00357 
00366   virtual csPtr<iShader> CompileShader (
00367         iLoaderContext* ldr_context, iDocumentNode *templ,
00368         int forcepriority = -1) = 0;
00369 
00371   virtual bool ValidateTemplate (iDocumentNode *templ) = 0;
00372 
00374   virtual bool IsTemplateToCompiler (iDocumentNode *templ) = 0;
00375 
00381   virtual csPtr<iShaderPriorityList> GetPriorities (
00382                   iDocumentNode* templ) = 0;
00383 };
00384 
00385 #endif // __CS_IVIDEO_SHADER_H__

Generated for Crystal Space 1.2.1 by doxygen 1.5.3