Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_MATERIAL_STATES_H__
00009 #define __SP_MATERIAL_STATES_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013 #include "Base/spInputOutputString.hpp"
00014 #include "Base/spMaterialConfigTypes.hpp"
00015 #include "Base/spMaterialColor.hpp"
00016
00017 #include <limits.h>
00018
00019
00020 namespace sp
00021 {
00022 namespace video
00023 {
00024
00025
00027 class SP_EXPORT MaterialStates
00028 {
00029
00030 public:
00031
00032 MaterialStates();
00033 MaterialStates(const MaterialStates* Other);
00034 virtual ~MaterialStates();
00035
00036
00037
00039 virtual void copy(const MaterialStates* Other);
00040
00042 virtual bool compare(const MaterialStates* Other) const;
00043
00050 virtual void update();
00051
00052
00053
00055 inline void setWireframe(const EWireframeTypes Type)
00056 {
00057 RenderModeFront_ = RenderModeBack_ = Type;
00058 update();
00059 }
00060
00066 inline void setWireframe(const EWireframeTypes TypeFront, const EWireframeTypes TypeBack)
00067 {
00068 RenderModeFront_ = TypeFront;
00069 RenderModeBack_ = TypeBack;
00070 update();
00071 }
00072
00074 inline EWireframeTypes getWireframeFront() const
00075 {
00076 return RenderModeFront_;
00077 }
00079 inline EWireframeTypes getWireframeBack() const
00080 {
00081 return RenderModeBack_;
00082 }
00083
00089 inline void setRenderFace(const EFaceTypes Face)
00090 {
00091 RenderFace_ = Face;
00092 update();
00093 }
00094 inline EFaceTypes getRenderFace() const
00095 {
00096 return RenderFace_;
00097 }
00098
00103 inline void setShininess(f32 Intensity)
00104 {
00105 Shininess_ = 128.0f - math::MinMax(Intensity, 0.0f, 1.0f)*128;
00106 }
00108 inline f32 getShininess() const
00109 {
00110 return 1.0f - Shininess_/128;
00111 }
00112
00114 inline void setShininessFactor(f32 Factor)
00115 {
00116 Shininess_ = math::MinMax(Factor, 0.0f, 128.0f);
00117 }
00119 inline f32 getShininessFactor() const
00120 {
00121 return Shininess_;
00122 }
00123
00130 inline void setColorMaterial(bool isColorMaterial)
00131 {
00132 isColorMaterial_ = isColorMaterial;
00133 }
00135 inline bool getColorMaterial() const
00136 {
00137 return isColorMaterial_;
00138 }
00139
00141 inline void setLighting(bool isLighting)
00142 {
00143 isLighting_ = isLighting;
00144 }
00146 inline bool getLighting() const
00147 {
00148 return isLighting_;
00149 }
00150
00152 inline void setDepthBuffer(bool isDepthBuffer)
00153 {
00154 isZBuffer_ = isDepthBuffer;
00155 update();
00156 }
00158 inline bool getDepthBuffer() const
00159 {
00160 return isZBuffer_;
00161 }
00162
00164 inline void setBlending(bool isBlending)
00165 {
00166 isBlending_ = isBlending;
00167 update();
00168 }
00170 inline bool getBlending() const
00171 {
00172 return isBlending_;
00173 }
00174
00176 inline void setFog(bool isFog)
00177 {
00178 isFog_ = isFog;
00179 }
00181 inline bool getFog() const
00182 {
00183 return isFog_;
00184 }
00185
00187 inline void setPolygonOffset(bool isPolygonOffset)
00188 {
00189 isPolygonOffset_ = isPolygonOffset;
00190 update();
00191 }
00193 inline bool getPolygonOffset() const
00194 {
00195 return isPolygonOffset_;
00196 }
00197
00205 inline void setColors(
00206 const color &Diffuse, const color &Ambient, const color &Specular, const color &Emission)
00207 {
00208 ColorDiffuse_ = Diffuse;
00209 ColorAmbient_ = Ambient;
00210 ColorSpecular_ = Specular;
00211 ColorEmission_ = Emission;
00212 }
00213
00215 inline void setDiffuseColor(const color &Color)
00216 {
00217 ColorDiffuse_ = Color;
00218 }
00220 inline color getDiffuseColor() const
00221 {
00222 return ColorDiffuse_;
00223 }
00225 inline color& getDiffuseColor()
00226 {
00227 return ColorDiffuse_;
00228 }
00229
00231 inline void setAmbientColor(const color &Color)
00232 {
00233 ColorAmbient_ = Color;
00234 }
00236 inline color getAmbientColor() const
00237 {
00238 return ColorAmbient_;
00239 }
00241 inline color& getAmbientColor()
00242 {
00243 return ColorAmbient_;
00244 }
00245
00247 inline void setSpecularColor(const color &Color)
00248 {
00249 ColorSpecular_ = Color;
00250 }
00252 inline color getSpecularColor() const
00253 {
00254 return ColorSpecular_;
00255 }
00257 inline color& getSpecularColor()
00258 {
00259 return ColorSpecular_;
00260 }
00261
00266 inline void setEmissionColor(const color &Color)
00267 {
00268 ColorEmission_ = Color;
00269 }
00271 inline color getEmissionColor() const
00272 {
00273 return ColorEmission_;
00274 }
00276 inline color& getEmissionColor()
00277 {
00278 return ColorEmission_;
00279 }
00280
00282 inline void setDiffuseAlpha(f32 Alpha)
00283 {
00284 ColorDiffuse_.Alpha = static_cast<u8>(math::MinMax(Alpha * 255.0f, 0.0f, 255.0f));
00285 }
00286
00293 inline void setShading(const EShadingTypes Type)
00294 {
00295 Shading_ = Type;
00296 }
00298 inline EShadingTypes getShading() const
00299 {
00300 return Shading_;
00301 }
00302
00310 inline void setPolygonOffset(bool isPolygonOffset, f32 OffsetFactor, f32 OffsetUnits = 0.0f)
00311 {
00312 isPolygonOffset_ = isPolygonOffset;
00313 OffsetFactor_ = OffsetFactor;
00314 OffsetUnits_ = OffsetUnits;
00315 update();
00316 }
00317
00319 inline void setPolygonOffsetFactor(f32 Factor)
00320 {
00321 OffsetFactor_ = Factor;
00322 update();
00323 }
00325 inline f32 getPolygonOffsetFactor() const
00326 {
00327 return OffsetFactor_;
00328 }
00329
00331 inline void setPolygonOffsetUnits(f32 Units)
00332 {
00333 OffsetUnits_ = Units;
00334 update();
00335 }
00337 inline f32 getPolygonOffsetUnits() const
00338 {
00339 return OffsetUnits_;
00340 }
00341
00346 inline void setBlendingMode(const EDefaultBlendingTypes Mode)
00347 {
00348 setDefaultBlending(Mode, BlendSource_, BlendTarget_);
00349 }
00350
00357 inline void setBlendingMode(const EBlendingTypes BlendSource, const EBlendingTypes BlendTarget)
00358 {
00359 BlendSource_ = BlendSource;
00360 BlendTarget_ = BlendTarget;
00361 update();
00362 }
00363
00365 inline void setBlendSource(const EBlendingTypes BlendSource)
00366 {
00367 BlendSource_ = BlendSource;
00368 update();
00369 }
00371 inline EBlendingTypes getBlendSource() const
00372 {
00373 return BlendSource_;
00374 }
00375
00377 inline void setBlendTarget(const EBlendingTypes BlendTarget)
00378 {
00379 BlendTarget_ = BlendTarget;
00380 update();
00381 }
00383 inline EBlendingTypes getBlendTarget() const
00384 {
00385 return BlendTarget_;
00386 }
00387
00392 inline void setDepthMethod(const ESizeComparisionTypes Method)
00393 {
00394 DepthMethod_ = Method;
00395 update();
00396 }
00398 inline ESizeComparisionTypes getDepthMethod() const
00399 {
00400 return DepthMethod_;
00401 }
00402
00414 virtual void setAlphaMethod(const ESizeComparisionTypes Method, f32 AlphaReference);
00415
00417 inline void setAlphaMethod(const ESizeComparisionTypes Method)
00418 {
00419 setAlphaMethod(Method, AlphaReference_);
00420 }
00422 inline ESizeComparisionTypes getAlphaMethod() const
00423 {
00424 return AlphaMethod_;
00425 }
00427 inline void setAlphaReference(f32 AlphaReference)
00428 {
00429 setAlphaMethod(AlphaMethod_, AlphaReference);
00430 }
00432 inline f32 getAlphaReference() const
00433 {
00434 return AlphaReference_;
00435 }
00436
00442 inline void setMaterialCallback(const UserMaterialCallback &MaterialCallback)
00443 {
00444 UserMaterialProc_ = MaterialCallback;
00445 }
00447 inline UserMaterialCallback getMaterialCallback() const
00448 {
00449 return UserMaterialProc_;
00450 }
00451
00452 protected:
00453
00454
00455
00456 virtual void setDefaultBlending(
00457 const video::EDefaultBlendingTypes Mode, video::EBlendingTypes &SrcBlend, video::EBlendingTypes &DestBlend
00458 );
00459
00460
00461
00462 color ColorDiffuse_;
00463 color ColorAmbient_;
00464 color ColorSpecular_;
00465 color ColorEmission_;
00466
00467 f32 Shininess_;
00468 f32 AlphaReference_;
00469 f32 OffsetFactor_;
00470 f32 OffsetUnits_;
00471
00472 EShadingTypes Shading_;
00473 ESizeComparisionTypes DepthMethod_;
00474 ESizeComparisionTypes AlphaMethod_;
00475 EBlendingTypes BlendSource_;
00476 EBlendingTypes BlendTarget_;
00477 EWireframeTypes RenderModeFront_;
00478 EWireframeTypes RenderModeBack_;
00479 EFaceTypes RenderFace_;
00480
00481 bool isColorMaterial_;
00482 bool isLighting_;
00483 bool isBlending_;
00484 bool isZBuffer_;
00485 bool isFog_;
00486 bool isPolygonOffset_;
00487
00497 UserMaterialCallback UserMaterialProc_;
00498
00499 private:
00500
00501 friend class Direct3D9RenderSystem;
00502 friend class Direct3D11RenderSystem;
00503
00504
00505
00506
00507 void* RefRasterizerState_;
00508 void* RefDepthStencilState_;
00509 void* RefBlendState_;
00510
00511 };
00512
00513
00514 }
00515
00516 }
00517
00518
00519 #endif
00520
00521
00522
00523