CrystalSpace

Public API Reference

csgfx/shadervarcontext.h
Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2003 by Jorrit Tyberghein
00003               (C) 2003 by Frank Richter
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 #ifndef __CS_CSGFX_SHADERVARCONTEXT_H__
00021 #define __CS_CSGFX_SHADERVARCONTEXT_H__
00022 
00023 #include "csextern.h"
00024 
00025 #include "csutil/scf_implementation.h"
00026 
00027 #include "ivideo/shader/shader.h"
00028 #include "shadervar.h"
00029 
00034 namespace CS
00035 {
00036   namespace Graphics
00037   {
00043     class CS_CRYSTALSPACE_EXPORT ShaderVariableContextImpl :
00044       public virtual iShaderVariableContext
00045     {
00046     protected:
00047       csRefArray<csShaderVariable> variables;
00048   
00049     public:
00050       virtual ~ShaderVariableContextImpl();
00051   
00052       const csRefArray<csShaderVariable>& GetShaderVariables () const
00053       { return variables; }
00054       virtual void AddVariable (csShaderVariable *variable);
00055       virtual csShaderVariable* GetVariable (ShaderVarStringID name) const;
00056       virtual void PushVariables (csShaderVariableStack& stacks) const;
00057       virtual bool IsEmpty() const { return variables.GetSize () == 0; }  
00058       virtual void ReplaceVariable (csShaderVariable *variable);
00059       virtual void Clear () { variables.Empty(); }
00060       virtual bool RemoveVariable (csShaderVariable* variable);
00061       virtual bool RemoveVariable (ShaderVarStringID name);
00062     };
00063     
00068     class OverlayShaderVariableContextImpl : public ShaderVariableContextImpl
00069     {
00070       csRef<iShaderVariableContext> parentSVC;
00071     public:
00072       OverlayShaderVariableContextImpl (iShaderVariableContext* parent = 0) :
00073         parentSVC (parent) {}
00074           
00075       iShaderVariableContext* GetParentContext() const { return parentSVC; }
00076       void SetParentContext (iShaderVariableContext* parent)
00077       { parentSVC = parent; }
00078   
00079       void AddVariable (csShaderVariable *variable)
00080       { ShaderVariableContextImpl::AddVariable (variable); }
00081       csShaderVariable* GetVariable (ShaderVarStringID name) const
00082       { 
00083         csShaderVariable* sv = ShaderVariableContextImpl::GetVariable (name); 
00084         if ((sv == 0) && (parentSVC.IsValid()))
00085           sv = parentSVC->GetVariable (name);
00086         return sv;
00087       }
00088       const csRefArray<csShaderVariable>& GetShaderVariables () const
00089       { 
00090         // @@@ Will not return parent SVs
00091         return ShaderVariableContextImpl::GetShaderVariables (); 
00092       }
00093       void PushVariables (csShaderVariableStack& stacks) const
00094       { 
00095         if (parentSVC.IsValid()) parentSVC->PushVariables (stacks);
00096         ShaderVariableContextImpl::PushVariables (stacks); 
00097       }
00098       bool IsEmpty () const 
00099       {
00100         return ShaderVariableContextImpl::IsEmpty() 
00101           && (!parentSVC.IsValid() || parentSVC->IsEmpty());
00102       }
00103       void ReplaceVariable (csShaderVariable *variable)
00104       { ShaderVariableContextImpl::ReplaceVariable (variable); }
00105       void Clear () { ShaderVariableContextImpl::Clear(); }
00106       bool RemoveVariable (csShaderVariable* variable)
00107       { 
00108         // @@@ Also remove from parent?
00109         return ShaderVariableContextImpl::RemoveVariable (variable); 
00110       }
00111       bool RemoveVariable (ShaderVarStringID name)
00112       { 
00113         // @@@ Also remove from parent?
00114         return ShaderVariableContextImpl::RemoveVariable (name); 
00115       }
00116     };
00117   } // namespace Graphics
00118   
00119   // Deprecated in 1.3
00120   typedef CS_DEPRECATED_TYPE_MSG("Use Graphics::ShaderVariableContextImpl")
00121     Graphics::ShaderVariableContextImpl ShaderVariableContextImpl;
00122 }
00123 
00127 class CS_CRYSTALSPACE_EXPORT csShaderVariableContext :
00128   public scfImplementation1<csShaderVariableContext, 
00129                              scfFakeInterface<iShaderVariableContext> >,
00130   public CS::Graphics::ShaderVariableContextImpl
00131 {
00132 public:
00133   CS_LEAKGUARD_DECLARE (csShaderVariableContext);
00134 
00135   csShaderVariableContext ();
00136   csShaderVariableContext (const csShaderVariableContext& other);
00137   virtual ~csShaderVariableContext ();
00138 };
00139 
00140 #endif // __CS_CSGFX_SHADERVARCONTEXT_H__

Generated for Crystal Space 2.0 by doxygen 1.7.6.1