CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

shader.h

00001 /*
00002     Copyright (C) 2002 by Mårten 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 
00024 #include "csgeom/vector4.h"
00025 #include "csutil/ref.h"
00026 #include "csutil/scf.h"
00027 #include "csutil/strhash.h"
00028 #include "csutil/csvector.h"
00029 #include "ivideo/render3d.h"
00030 
00031 struct iString;
00032 struct iDataBuffer;
00033 struct iDocumentNode;
00034 
00035 struct iShaderManager;
00036 struct iShaderRenderInterface;
00037 struct iShader;
00038 struct iShaderVariable;
00039 struct iShaderTechnique;
00040 struct iShaderPass;
00041 struct iShaderProgram;
00042 struct iShaderProgramPlugin;
00043 
00044 SCF_VERSION (iShaderManager, 0,0,1);
00048 struct iShaderManager : iBase
00049 {
00051   virtual csPtr<iShader> CreateShader() = 0;
00053   virtual iShader* GetShader(const char* name) = 0;
00055   virtual const csBasicVector &GetShaders () = 0;
00056 
00058   virtual csPtr<iShaderVariable> CreateVariable(const char* name) = 0;
00060   virtual bool AddVariable(iShaderVariable* variable) = 0;
00062   virtual iShaderVariable* GetVariable(int namehash) = 0;
00064   virtual csBasicVector GetAllVariableNames() = 0; 
00065 
00067   virtual csPtr<iShaderProgram> CreateShaderProgram(const char* type) = 0;
00068 };
00069 
00070 SCF_VERSION (iShaderRenderInterface, 0,0,1);
00071 struct iShaderRenderInterface : iBase
00072 {
00074   virtual void* GetPrivateObject(const char* name) = 0;
00075 };
00076 
00077 SCF_VERSION (iShader, 0,0,1);
00081 struct iShader : iBase
00082 {
00084   virtual void SetName( const char* name ) = 0;
00086   virtual const char* GetName() = 0;
00087 
00089   virtual csPtr<iShaderTechnique> CreateTechnique() = 0;
00091   virtual int GetTechniqueCount() = 0;
00093   virtual iShaderTechnique* GetTechnique( int technique ) = 0;
00095   virtual iShaderTechnique* GetBestTechnique() = 0;
00096 
00098   virtual bool AddVariable(iShaderVariable* variable) = 0;
00100   virtual iShaderVariable* GetVariable(int namehash) = 0;
00102   virtual csBasicVector GetAllVariableNames() = 0; 
00103 
00105   virtual bool IsValid() = 0;
00106 
00108   virtual bool Load(iDataBuffer* program) = 0;
00109 
00111   virtual bool Load(iDocumentNode* node) = 0;
00112 
00114   virtual bool Prepare() = 0;
00115 };
00116 
00117 SCF_VERSION (iShaderVariable, 0,0,1);
00118 struct iShaderVariable : iBase
00119 {
00120   enum VariableType
00121   {
00122     INT = 1,
00123     STRING,
00124     VECTOR1,
00125     VECTOR3,
00126     VECTOR4
00127   };
00128 
00129   virtual VariableType GetType() = 0;
00130   virtual void SetType(VariableType) = 0;
00131 
00132   virtual int GetHash() = 0;
00133 
00134   virtual void SetName(const char*) = 0;
00135   virtual const char* GetName() = 0;
00136   virtual bool GetValue(int& value) = 0;
00137   virtual bool GetValue(float& value) = 0;
00138   virtual bool GetValue(iString* value) = 0;
00139   virtual bool GetValue(csVector3& value) = 0;
00140   virtual bool GetValue(csVector4& value) = 0;
00141   virtual bool SetValue(int value) = 0;
00142   virtual bool SetValue(float value) = 0;
00143   virtual bool SetValue(iString* value) = 0;
00144   virtual bool SetValue(csVector3 value) = 0;
00145   virtual bool SetValue(csVector4 value) = 0;
00146 };
00147 
00148 SCF_VERSION (iShaderTechnique, 0,0,1);
00152 struct iShaderTechnique : iBase
00153 {
00154   /* Get technique priority. If there are several valid techniques
00155    * use the one with highest priority
00156    */
00157   virtual int GetPriority() = 0;
00158 
00160   virtual void SetPriority(int priority) = 0;
00161 
00163   virtual csPtr<iShaderPass> CreatePass() = 0;
00165   virtual int GetPassCount() = 0;
00167   virtual iShaderPass* GetPass( int pass ) = 0;
00168 
00170   virtual bool IsValid() = 0;
00171 
00173   virtual bool Load(iDataBuffer* program) = 0;
00174 
00176   virtual bool Load(iDocumentNode* node) = 0;
00177 
00179   virtual bool Prepare() = 0;
00180 };
00181 
00182 SCF_VERSION (iShaderPass, 0,0,1);
00186 struct iShaderPass : iBase
00187 {
00189   virtual void AddStreamMapping (csStringID name, csVertexAttrib attribute) = 0;
00191   virtual csStringID GetStreamMapping (csVertexAttrib attribute) = 0;
00192 
00194   virtual void AddTextureMapping (const char* name, int unit) = 0;
00196   virtual void AddTextureMapping (int layer, int unit) = 0;
00198   virtual int GetTextureMappingAsLayer (int unit) = 0;
00200   virtual iTextureHandle* GetTextureMappingAsDirect (int unit) = 0;
00201 
00203   virtual uint GetMixmodeOverride () = 0;
00204 
00206   virtual iShaderProgram* GetVertexProgram() = 0;
00207 
00209   virtual void SetVertexProgram(iShaderProgram* program) = 0;
00210 
00212   virtual iShaderProgram* GetFragmentProgram() = 0;
00213 
00215   virtual void SetFragmentProgram(iShaderProgram* program) = 0;
00216 
00218   virtual bool IsValid() = 0;
00219 
00221   virtual void Activate(csRenderMesh* mesh) = 0;
00222 
00224   virtual void Deactivate() = 0;
00225 
00227   virtual void SetupState (csRenderMesh* mesh) = 0;
00228 
00230   virtual void ResetState () = 0;
00231 
00233   virtual bool AddVariable(iShaderVariable* variable) = 0;
00235   virtual iShaderVariable* GetVariable(int namehash) = 0;
00237   virtual csBasicVector GetAllVariableNames() = 0; 
00238 
00240   virtual bool Load(iDataBuffer* program) = 0;
00241 
00243   virtual bool Load(iDocumentNode* node) = 0;
00244 
00246   virtual bool Prepare() = 0;
00247 };
00248 
00249 SCF_VERSION (iShaderProgram, 0,0,1);
00254 struct iShaderProgram : iBase
00255 {
00257   virtual csPtr<iString> GetProgramID() = 0;
00258 
00260   virtual void Activate(iShaderPass* current, csRenderMesh* mesh) = 0;
00261 
00263   virtual void Deactivate(iShaderPass* current) = 0;
00264 
00266   virtual void SetupState (iShaderPass* current, csRenderMesh* mesh) = 0;
00267 
00269   virtual void ResetState () = 0;
00270 
00271   /* Propertybag - get property, return false if no such property found
00272    * Which properties there is is implementation specific
00273    */
00274   virtual bool GetProperty(const char* name, iString* string) = 0;
00275   virtual bool GetProperty(const char* name, int* string) = 0;
00276   virtual bool GetProperty(const char* name, csVector3* string) = 0;
00277 //  virtual bool GetProperty(const char* name, csVector4* string) = 0;
00278 
00279   /* Propertybag - set property.
00280    * Which properties there is is implementation specific
00281    */
00282   virtual bool SetProperty(const char* name, iString* string) = 0;
00283   virtual bool SetProperty(const char* name, int* string) = 0;
00284   virtual bool SetProperty(const char* name, csVector3* string) = 0;
00285 //  virtual bool SetProperty(const char* name, csVector4* string) = 0;
00286 
00288   virtual bool AddVariable(iShaderVariable* variable) = 0;
00290   virtual iShaderVariable* GetVariable(int namehash) = 0;
00292   virtual csBasicVector GetAllVariableNames() = 0; 
00293 
00295   virtual bool IsValid() = 0;
00296 
00298   virtual bool Load(iDataBuffer* program) = 0;
00299 
00301   virtual bool Load(iDocumentNode* node) = 0;
00302 
00304   virtual bool Prepare() = 0;
00305 };
00306 
00307 SCF_VERSION(iShaderProgramPlugin, 0,0,1);
00308 struct iShaderProgramPlugin : iBase
00309 {
00310   virtual csPtr<iShaderProgram> CreateProgram(const char* type) = 0  ;
00311   virtual bool SupportType(const char* type) = 0;
00312   virtual void Open() = 0;
00313 };
00314 
00315 #endif // __CS_IVIDEO_SHADER_H__

Generated for Crystal Space by doxygen 1.2.14