Background.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2020, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. #pragma once
  35. namespace AssimpView
  36. {
  37. class CBackgroundPainter
  38. {
  39. CBackgroundPainter()
  40. :
  41. clrColor( D3DCOLOR_ARGB( 0xFF, 100, 100, 100 ) ),
  42. pcTexture( NULL ),
  43. piSkyBoxEffect( NULL ),
  44. eMode( SIMPLE_COLOR )
  45. {}
  46. public:
  47. // Supported background draw modi
  48. enum MODE { SIMPLE_COLOR, TEXTURE_2D, TEXTURE_CUBE };
  49. // Singleton accessors
  50. static CBackgroundPainter s_cInstance;
  51. inline static CBackgroundPainter& Instance()
  52. {
  53. return s_cInstance;
  54. }
  55. // set the current background color
  56. // (this removes any textures loaded)
  57. void SetColor( D3DCOLOR p_clrNew );
  58. // Setup a cubemap/a 2d texture as background
  59. void SetCubeMapBG( const char* p_szPath );
  60. void SetTextureBG( const char* p_szPath );
  61. // Called by the render loop
  62. void OnPreRender();
  63. void OnPostRender();
  64. // Release any native resources associated with the instance
  65. void ReleaseNativeResource();
  66. // Recreate any native resources associated with the instance
  67. void RecreateNativeResource();
  68. // Rotate the skybox
  69. void RotateSB( const aiMatrix4x4* pm );
  70. // Reset the state of the skybox
  71. void ResetSB();
  72. inline MODE GetMode() const
  73. {
  74. return this->eMode;
  75. }
  76. inline IDirect3DBaseTexture9* GetTexture()
  77. {
  78. return this->pcTexture;
  79. }
  80. inline ID3DXBaseEffect* GetEffect()
  81. {
  82. return this->piSkyBoxEffect;
  83. }
  84. private:
  85. void RemoveSBDeps();
  86. // current background color
  87. D3DCOLOR clrColor;
  88. // current background texture
  89. IDirect3DBaseTexture9* pcTexture;
  90. ID3DXEffect* piSkyBoxEffect;
  91. // current background mode
  92. MODE eMode;
  93. // path to the texture
  94. std::string szPath;
  95. // transformation matrix for the skybox
  96. aiMatrix4x4 mMatrix;
  97. };
  98. }