Mesh.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #pragma once
  2. //========================================================================
  3. // File: Mesh.h - classes to render meshes in D3D9 and D3D11
  4. //
  5. // Part of the GameCode4 Application
  6. //
  7. // GameCode4 is the sample application that encapsulates much of the source code
  8. // discussed in "Game Coding Complete - 4th Edition" by Mike McShaffry and David
  9. // "Rez" Graham, published by Charles River Media.
  10. // ISBN-10: 1133776574 | ISBN-13: 978-1133776574
  11. //
  12. // If this source code has found it's way to you, and you think it has helped you
  13. // in any way, do the authors a favor and buy a new copy of the book - there are
  14. // detailed explanations in it that compliment this code well. Buy a copy at Amazon.com
  15. // by clicking here:
  16. // http://www.amazon.com/gp/product/1133776574/ref=olp_product_details?ie=UTF8&me=&seller=
  17. //
  18. // There's a companion web site at http://www.mcshaffry.com/GameCode/
  19. //
  20. // The source code is managed and maintained through Google Code:
  21. // http://code.google.com/p/gamecode4/
  22. //
  23. // (c) Copyright 2012 Michael L. McShaffry and David Graham
  24. //
  25. // This program is free software; you can redistribute it and/or
  26. // modify it under the terms of the GNU Lesser GPL v3
  27. // as published by the Free Software Foundation.
  28. //
  29. // This program is distributed in the hope that it will be useful,
  30. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  32. // http://www.gnu.org/licenses/lgpl-3.0.txt for more details.
  33. //
  34. // You should have received a copy of the GNU Lesser GPL v3
  35. // along with this program; if not, write to the Free Software
  36. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  37. //
  38. //========================================================================
  39. #include "Geometry.h"
  40. #include "SceneNodes.h"
  41. #include "Material.h"
  42. #include "Shaders.h"
  43. #include "../ResourceCache/ResCache.h"
  44. #include <assimp/cimport.h>
  45. #include <assimp/scene.h>
  46. #include <assimp/postprocess.h>
  47. //
  48. // class D3DSdkMeshResourceExtraData11 - Chapter 16, page 561
  49. //
  50. class OpenGLGlbMeshResourceExtraData : public IResourceExtraData
  51. {
  52. friend class GlbMeshResourceLoader;
  53. public:
  54. OpenGLGlbMeshResourceExtraData() { }
  55. virtual ~OpenGLGlbMeshResourceExtraData() { if (m_pScene) aiReleaseImport(m_pScene); }
  56. virtual std::string VToString() { return "OpenGLGlbMeshResourceExtraData"; }
  57. const aiScene* m_pScene;
  58. };
  59. //
  60. // class SdkMeshResourceLoader - Chapter 16, page 561
  61. //
  62. class GlbMeshResourceLoader : public IResourceLoader
  63. {
  64. public:
  65. virtual bool VUseRawFile() { return false; }
  66. virtual bool VDiscardRawBufferAfterLoad() { return false; }
  67. virtual unsigned int VGetLoadedResourceSize(char *rawBuffer, unsigned int rawSize);
  68. virtual bool VLoadResource(char *rawBuffer, unsigned int rawSize, std::shared_ptr<ResHandle> handle);
  69. virtual std::string VGetPattern() { return "*.glb"; }
  70. };
  71. ////////////////////////////////////////////////////
  72. //
  73. // class TeapotMeshNode9 - Chapter X, page Y
  74. //
  75. ////////////////////////////////////////////////////
  76. class OpenGLShaderMeshNode : public SceneNode
  77. {
  78. public:
  79. OpenGLShaderMeshNode(const ActorId actorId,
  80. WeakBaseRenderComponentPtr renderComponent,
  81. std::string meshFileName,
  82. RenderPass renderPass,
  83. const glm::mat4 t);
  84. virtual int VOnRestore(Scene *pScene);
  85. virtual int VOnLostDevice(Scene *pScene) { return 0; }
  86. virtual int VRender(Scene *pScene);
  87. // virtual int VPick(Scene *pScene, RayCast *pRayCast);
  88. protected:
  89. std::string m_meshFileName;
  90. GLuint *m_vao;
  91. GLuint *m_vbo;
  92. GLuint *m_ebo;
  93. size_t *m_numIndices;
  94. size_t *m_numVerts;
  95. size_t m_numMeshes;
  96. OpenGLShaderProgram m_ShaderProgram;
  97. };
  98. class OpenGLTeapotMeshNode : public OpenGLShaderMeshNode
  99. {
  100. public:
  101. OpenGLTeapotMeshNode(const ActorId actorId, WeakBaseRenderComponentPtr renderComponent, RenderPass renderPass, glm::mat4 t)
  102. : OpenGLShaderMeshNode(actorId, renderComponent, "art/3d assets/fantasy town kit/models/gltf format/hedge.glb", renderPass, t) { }
  103. bool VIsVisible() { return true; }
  104. };