skyBox.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SKYBOX_H_
  23. #define _SKYBOX_H_
  24. #ifndef _SCENEOBJECT_H_
  25. #include "scene/sceneObject.h"
  26. #endif
  27. #ifndef _GFXDEVICE_H_
  28. #include "gfx/gfxDevice.h"
  29. #endif
  30. #ifndef _CUBEMAPDATA_H_
  31. #include "gfx/sim/cubemapData.h"
  32. #endif
  33. #ifndef _MATERIALLIST_H_
  34. #include "materials/materialList.h"
  35. #endif
  36. #ifndef _GFXVERTEXBUFFER_H_
  37. #include "gfx/gfxVertexBuffer.h"
  38. #endif
  39. #ifndef _GFXPRIMITIVEBUFFER_H_
  40. #include "gfx/gfxPrimitiveBuffer.h"
  41. #endif
  42. GFXDeclareVertexFormat( GFXSkyVertex )
  43. {
  44. Point3F point;
  45. Point3F normal;
  46. GFXVertexColor color;
  47. };
  48. struct SkyMatParams
  49. {
  50. void init( BaseMatInstance *matInst ) {};
  51. };
  52. class MatrixSet;
  53. class SkyBox : public SceneObject
  54. {
  55. typedef SceneObject Parent;
  56. public:
  57. SkyBox();
  58. virtual ~SkyBox();
  59. DECLARE_CONOBJECT( SkyBox );
  60. // SimObject
  61. void onStaticModified( const char *slotName, const char *newValue );
  62. // ConsoleObject
  63. virtual bool onAdd();
  64. virtual void onRemove();
  65. static void initPersistFields();
  66. virtual void inspectPostApply();
  67. // NetObject
  68. virtual U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream );
  69. virtual void unpackUpdate( NetConnection *conn, BitStream *stream );
  70. // SceneObject
  71. void prepRenderImage( SceneRenderState* state );
  72. /// Our render delegate.
  73. void _renderObject( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *mi );
  74. /// Prepares rendering structures and geometry.
  75. void _initRender();
  76. protected:
  77. // Material
  78. String mMatName;
  79. BaseMatInstance *mMatInstance;
  80. SkyMatParams mMatParamHandle;
  81. SimObjectPtr<Material> mMaterial;
  82. GFXVertexBufferHandle<GFXVertexPNTT> mVB;
  83. GFXVertexBufferHandle<GFXVertexPC> mFogBandVB;
  84. Material *mFogBandMat;
  85. BaseMatInstance *mFogBandMatInst;
  86. ColorF mLastFogColor;
  87. bool mDrawBottom;
  88. bool mIsVBDirty;
  89. U32 mPrimCount;
  90. MatrixSet *mMatrixSet;
  91. F32 mFogBandHeight;
  92. void _updateMaterial();
  93. void _initMaterial();
  94. BaseMatInstance* _getMaterialInstance();
  95. };
  96. #endif // _SKYBOX_H_