Go to the documentation of this file.00001
00002
00003 #ifndef _SHADER_H_
00004 #define _SHADER_H_
00005
00006 #include <EngineConfig.h>
00007 #include <core/Types.h>
00008 #include <resource/Resource.h>
00009 #include <render/ShaderDefines.h>
00010 #include <render/ShaderParamData.h>
00011 #include <render/TextureDefines.h>
00012 #include <render/Color.h>
00013 #include <core/Vector2d.h>
00014 #include <core/Vector3d.h>
00015 #include <core/Vector4d.h>
00016 #include <core/Matrix4.h>
00017
00018 #include <string>
00019 #include <vector>
00020 #include <map>
00021
00022 namespace resource
00023 {
00024 class Serializer;
00025 }
00026
00027 namespace render
00028 {
00029
00030 class Light;
00031 class Texture;
00032
00033 struct ENGINE_PUBLIC_EXPORT ShaderParameter
00034 {
00035 ShaderParameter();
00036
00037 ShaderParameterType paramType;
00038 ShaderAutoParameterType autoParamType;
00039 u32 index;
00040 u32 elemCount;
00041 };
00042
00047 class ENGINE_PUBLIC_EXPORT Shader: public resource::Resource
00048 {
00049 public:
00050
00051 Shader(const std::string& name, resource::Serializer* serializer);
00052 virtual ~Shader();
00053
00055 void setShaderType(const ShaderType& type);
00056
00058 ShaderType getShaderType();
00059
00060 void setSource(const std::string& source);
00061
00062 void setEntryPoint(const std::string& entry);
00063
00064 virtual void bind();
00065
00066 virtual void unbind();
00067
00068 virtual void updateAutoParameters(ShaderParamData& data);
00069
00070 virtual void setParamerter(const std::string& name, const Color& col);
00071 virtual void setParamerter(const std::string& name, const core::vector2d& vec);
00072 virtual void setParamerter(const std::string& name, const core::vector3d& vec);
00073 virtual void setParamerter(const std::string& name, const core::vector4d& vec);
00074 virtual void setParamerter(const std::string& name, const core::matrix4& m);
00075 virtual void setParamerter(const std::string& name, const f32* val, u32 count);
00076 virtual void setParamerter(const std::string& name, const s32* val, u32 count);
00077
00078 virtual void addParamerter(const std::string& name, ShaderParameterType type);
00079
00080 void setAutoParamerter(const std::string& name, ShaderAutoParameterType type);
00081
00082 protected:
00083
00084 void initProperties();
00085
00086 virtual bool loadImpl();
00087 virtual void unloadImpl();
00088
00089 ShaderType mShaderType;
00090
00091 std::string mSource;
00092 std::string mEntryPoint;
00093
00094 ShaderParameter* createParameter(const std::string& name, ShaderParameterType type, u32 index, u32 elemCount);
00095 virtual ShaderParameter* createParameterImpl(const std::string& name);
00096
00097 ShaderParameter* findParameter(const std::string& name);
00098 void writedParameterData(u32 index, const f32* val, u32 count);
00099 void writedParameterData(u32 index, const s32* val, u32 count);
00100
00101 f32* getFloatPrameterData(u32 index);
00102 const f32* getFloatPrameterData(u32 index) const;
00103
00104 s32* getIntPrameterData(u32 index);
00105 const s32* getIntPrameterData(u32 index) const;
00106
00107 void removeAllParameters();
00108
00109 static bool isFloat(ShaderParameterType type);
00110 static bool isFloat(ShaderAutoParameterType type);
00111 static bool isSampler(ShaderParameterType type);
00112 static u32 getElementCount(ShaderParameterType type);
00113 static u32 getElementCount(ShaderAutoParameterType type);
00114 static ShaderParameterType getType(ShaderAutoParameterType type);
00115 static ShaderParameterType getType(TextureType type);
00116
00117 std::vector<f32> mFloatParameterData;
00118 std::vector<s32> mIntParameterData;
00119 hashmap<std::string, ShaderParameter*> mParameters;
00120 };
00121
00122 }
00123
00124 #endif