QGearsManualObject.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. -----------------------------------------------------------------------------
  3. The MIT License (MIT)
  4. Copyright (c) 2013-08-14 Tobias Peters <tobias.peters@kreativeffekt.at>
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. -----------------------------------------------------------------------------
  21. */
  22. #ifndef __QGearsManualObject_H__
  23. #define __QGearsManualObject_H__
  24. #include <OgreColourValue.h>
  25. #include <OgreMesh.h>
  26. #include <OgreSubMesh.h>
  27. #include <OgreVector2.h>
  28. #include <OgreVector3.h>
  29. #include "common/TypeDefine.h"
  30. namespace QGears
  31. {
  32. /*
  33. * When parsing files this is used to create the rendering engine object, e.g when we see a bone
  34. * in the file we are parsing then call bone() to add one.
  35. */
  36. class ManualObject
  37. {
  38. public:
  39. explicit ManualObject( Ogre::Mesh *mesh );
  40. virtual ~ManualObject();
  41. enum BufferBinding
  42. {
  43. BB_POSITION
  44. , BB_NORMAL
  45. , BB_COLOUR
  46. , BB_TEXTURE
  47. , BINDING_COUNT
  48. };
  49. virtual void begin( const String &name, const String &material_name
  50. ,size_t vertex_count, size_t index_count );
  51. virtual void position( const Ogre::Vector3 &position );
  52. virtual void normal( const Ogre::Vector3 &normal );
  53. virtual void colour( const Ogre::ColourValue &colour );
  54. virtual void textureCoord( const Ogre::Vector2 &texture_coordinate );
  55. virtual void index( const uint32 idx );
  56. virtual void bone( const uint32 idx, const uint16 bone_handle
  57. ,const Ogre::Real weight = 1 );
  58. virtual void end();
  59. protected:
  60. template<typename BufferType>
  61. BufferType* createBuffer( const BufferBinding binding, Ogre::VertexElementType type, Ogre::VertexElementSemantic semantic);
  62. virtual void createPositionBuffer();
  63. virtual void createNormalBuffer();
  64. virtual void createColourBuffer();
  65. virtual void createTextureCoordinateBuffer();
  66. virtual void createIndexBuffer();
  67. virtual void resetBuffers();
  68. template<typename BufferSharedPtr>
  69. void resetBuffer( BufferSharedPtr &buffer ) const;
  70. private:
  71. Ogre::Mesh *m_mesh;
  72. Ogre::SubMesh *m_section;
  73. Ogre::AxisAlignedBox m_bbox;
  74. Ogre::Real m_radius;
  75. typedef Ogre::HardwareVertexBufferSharedPtr VertexBuffer;
  76. typedef Ogre::HardwareIndexBufferSharedPtr IndexBuffer;
  77. VertexBuffer m_vertex_buffers[BINDING_COUNT];
  78. IndexBuffer m_index_buffer;
  79. Ogre::Vector3 *m_position;
  80. Ogre::Vector3 *m_normal;
  81. uint32 *m_colour;
  82. Ogre::Vector2 *m_texture_coordinate;
  83. uint16 *m_index;
  84. const Ogre::VertexElementType colour_type;
  85. };
  86. }
  87. #endif // __QGearsManualObject_H__