Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_SHADER_PROGRAM_H__
00009 #define __SP_SHADER_PROGRAM_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013 #include "Base/spInputOutput.hpp"
00014 #include "Base/spDimension.hpp"
00015 #include "Base/spVertexFormat.hpp"
00016 #include "Base/spMaterialColor.hpp"
00017 #include "RenderSystem/spShaderClass.hpp"
00018
00019 #include <vector>
00020
00021
00022 namespace sp
00023 {
00024 namespace video
00025 {
00026
00027
00029 struct SShaderConstant
00030 {
00031 SShaderConstant() :
00032 Type (CONSTANT_UNKNOWN ),
00033 Count (1 ),
00034 Location(-1 )
00035 {
00036 }
00037 ~SShaderConstant()
00038 {
00039 }
00040
00041
00042
00043 inline bool operator == (const SShaderConstant &Other) const
00044 {
00045 return
00046 Type == Other.Type &&
00047 AltName == Other.AltName &&
00048 Name == Other.Name &&
00049 Count == Other.Count &&
00050 Location == Other.Location;
00051 }
00052
00053
00054
00059 inline bool valid() const
00060 {
00061 return Type != CONSTANT_UNKNOWN && Location != -1;
00062 }
00063
00064
00065
00066 EConstantTypes Type;
00067 io::stringc Name;
00068
00073 io::stringc AltName;
00074 u32 Count;
00075 s32 Location;
00076 };
00077
00078
00079 class ConstantBuffer;
00080
00086 class SP_EXPORT Shader
00087 {
00088
00089 public:
00090
00091 Shader(ShaderClass* ShdClass, const EShaderTypes Type, const EShaderVersions Version);
00092 virtual ~Shader();
00093
00094
00095
00105 virtual bool compile(
00106 const std::list<io::stringc> &ShaderBuffer,
00107 const io::stringc &EntryPoint = "",
00108 const c8** CompilerOptions = 0
00109 );
00110
00116 virtual const SShaderConstant* getConstantRef(const io::stringc &Name) const;
00123 virtual const SShaderConstant& getConstant(const io::stringc &Name) const;
00124
00133 virtual ConstantBuffer* getConstantBuffer(const io::stringc &Name) const;
00134
00135
00136
00137 virtual bool setConstant(s32 Number, const EConstantTypes Type, const f32 Value);
00138 virtual bool setConstant(s32 Number, const EConstantTypes Type, const f32* Buffer, s32 Count);
00139
00140
00141
00142
00143 virtual bool setConstant(s32 Number, const EConstantTypes Type, const dim::vector3df &Position);
00144 virtual bool setConstant(s32 Number, const EConstantTypes Type, const video::color &Color);
00145 virtual bool setConstant(s32 Number, const EConstantTypes Type, const dim::matrix4f &Matrix);
00146
00147
00148
00149 virtual bool setConstant(const io::stringc &Name, const f32 Value);
00150 virtual bool setConstant(const io::stringc &Name, const f32* Buffer, s32 Count);
00151
00152 virtual bool setConstant(const io::stringc &Name, const s32 Value);
00153 virtual bool setConstant(const io::stringc &Name, const s32* Buffer, s32 Count);
00154
00155 virtual bool setConstant(const io::stringc &Name, const dim::vector3df &Position);
00156 virtual bool setConstant(const io::stringc &Name, const dim::vector4df &Position);
00157 virtual bool setConstant(const io::stringc &Name, const video::color &Color);
00158 virtual bool setConstant(const io::stringc &Name, const dim::matrix4f &Matrix);
00159
00160
00161
00162 virtual bool setConstant(const SShaderConstant &Constant, const f32 Value);
00163 virtual bool setConstant(const SShaderConstant &Constant, const f32* Buffer, s32 Count);
00164
00165 virtual bool setConstant(const SShaderConstant &Constant, const s32 Value);
00166 virtual bool setConstant(const SShaderConstant &Constant, const s32* Buffer, s32 Count);
00167
00168
00169 virtual bool setConstant(const SShaderConstant &Constant, const dim::vector3df &Vector);
00170 virtual bool setConstant(const SShaderConstant &Constant, const dim::vector4df &Vector);
00171 virtual bool setConstant(const SShaderConstant &Constant, const video::color &Color);
00172
00173
00174 virtual bool setConstant(const SShaderConstant &Constant, const dim::matrix4f &Matrix);
00175
00176
00177
00184 virtual bool setConstant(const f32* Buffer, s32 StartRegister, s32 ConstAmount);
00185
00192 virtual bool setConstantBuffer(const io::stringc &Name, const void* Buffer);
00193
00195 virtual bool setConstantBuffer(u32 Number, const void* Buffer);
00196
00197
00198
00200 static io::stringc getOption(const io::stringc &Op);
00201
00210 static void addOption(std::list<io::stringc> &ShaderCompilerOp, const io::stringc &Op);
00211
00219 static void addShaderCore(std::list<io::stringc> &ShaderCode, bool UseCg = false);
00220
00221
00222
00224 inline EShaderTypes getType() const
00225 {
00226 return Type_;
00227 }
00229 inline EShaderVersions getVersion() const
00230 {
00231 return Version_;
00232 }
00234 inline ShaderClass* getShaderClass() const
00235 {
00236 return ShdClass_;
00237 }
00238
00240 inline const std::vector<SShaderConstant>& getConstantList() const
00241 {
00242 return ConstantList_;
00243 }
00245 inline u32 getConstantCount() const
00246 {
00247 return ConstantList_.size();
00248 }
00249
00251 inline const std::vector<ConstantBuffer*>& getConstantBufferList() const
00252 {
00253 return ConstantBufferList_;
00254 }
00256 inline u32 getConstantBufferCount() const
00257 {
00258 return ConstantBufferList_.size();
00259 }
00260
00262 inline bool valid() const
00263 {
00264 return CompiledSuccessfully_;
00265 }
00266
00268 inline bool isHighLevel() const
00269 {
00270 return HighLevel_;
00271 }
00272
00273 protected:
00274
00275
00276
00277 void updateShaderClass();
00278
00279 void printError(const io::stringc &Message);
00280 void printWarning(const io::stringc &Message);
00281
00282 static void createProgramString(const std::list<io::stringc> &ShaderBuffer, c8* &ProgramBuffer);
00283
00284
00285
00286 EShaderTypes Type_;
00287 EShaderVersions Version_;
00288 ShaderClass* ShdClass_;
00289
00290 std::vector<SShaderConstant> ConstantList_;
00291 std::vector<ConstantBuffer*> ConstantBufferList_;
00292
00293 bool HighLevel_;
00294 bool OwnShaderClass_;
00295 bool CompiledSuccessfully_;
00296
00297 static SShaderConstant EmptyConstant_;
00298
00299 };
00300
00301
00302 }
00303
00304 }
00305
00306
00307 #endif
00308
00309
00310
00311