@@ -7,28 +7,54 @@ class MainApp final : public fra::AbstractApplication
77 AbstractApplication(serviceProvider)
88 {
99
10- mMeshPool = serviceProvider->GetService <fra::MeshPool>();
11- mTexturePool = serviceProvider->GetService <fra::TexturePool>();
10+ mMeshPool = serviceProvider->GetService <fra::MeshPool>();
11+ mTexturePool = serviceProvider->GetService <fra::TexturePool>();
12+ mMaterialPool = serviceProvider->GetService <fra::MaterialPool>();
1213 }
1314
1415 void StartUp () override
1516 {
1617 mRenderer ->ClearProjections ();
1718
18- mModelMatrix [0 ] = glm::translate (
19- glm::scale (glm::mat4 (1 ), glm::vec3 (3 )), glm::vec3 (- 1 , 0 , 0 ));
19+ mModelMatrix [0 ] = glm::scale (
20+ glm::translate (glm::mat4 (1 ), glm::vec3 (- 3 , 2 , 0 )), glm::vec3 (0.3 ));
2021
21- mModelMatrix [1 ] = glm::translate (
22- glm::scale (glm::mat4 (1 ), glm::vec3 (3 )), glm::vec3 (1 , 0 , 0 ));
22+ mModelMatrix [1 ] = glm::scale (
23+ glm::translate (glm::mat4 (1 ), glm::vec3 (3 , 2 , 0 )), glm::vec3 (0.3 ));
2324
24- mTextureA = mTexturePool ->CreateTextureFromFile (
25+ mModelMatrix [2 ] = glm::scale (
26+ glm::translate (glm::mat4 (1 ), glm::vec3 (-3 , -2 , 0 )), glm::vec3 (2 ));
27+
28+ mModelMatrix [3 ] = glm::scale (
29+ glm::translate (glm::mat4 (1 ), glm::vec3 (3 , -2 , 0 )), glm::vec3 (2 ));
30+
31+ mSofaAlbedo = mTexturePool ->CreateTextureFromFile (
2532 " ./Resources/Textures/OfficeSofa_BaseColor.png" );
26- mTextureB = mTexturePool ->CreateTextureFromFile (
33+ mSofaNormal = mTexturePool ->CreateTextureFromFile (
2734 " ./Resources/Textures/OfficeSofa_Normal.png" );
28- mTextureC = mTexturePool ->CreateTextureFromFile (
35+ mSofaRoughness = mTexturePool ->CreateTextureFromFile (
2936 " ./Resources/Textures/OfficeSofa_Roughness.png" );
30- mModelA =
37+
38+ mSofaMaterial =
39+ mMaterialPool ->Create ({ mSofaAlbedo , mSofaNormal , mSofaRoughness });
40+
41+ mSofaModel =
3142 mMeshPool ->CreateMeshFromFile (" ./Resources/Models/OfficeSofa.fbx" );
43+
44+ mSpaceShipAlbedo = mTexturePool ->CreateTextureFromFile (
45+ " ./Resources/Textures/SpaceShip_Base_color.jpg" );
46+
47+ mSpaceShipNormal = mTexturePool ->CreateTextureFromFile (
48+ " ./Resources/Textures/SpaceShip_Normal.jpg" );
49+
50+ mSpaceShipRoughness = mTexturePool ->CreateTextureFromFile (
51+ " ./Resources/Textures/SpaceShip_Roughness.jpg" );
52+
53+ mSpaceShipMaterial = mMaterialPool ->Create (
54+ { mSpaceShipAlbedo , mSpaceShipNormal , mSpaceShipRoughness });
55+
56+ mSpaceShipModel =
57+ mMeshPool ->CreateMeshFromFile (" ./Resources/Models/SpaceShip.fbx" );
3258 }
3359
3460 void Update () override
@@ -42,46 +68,64 @@ class MainApp final : public fra::AbstractApplication
4268 mModelMatrix [1 ], glm::radians (15 .0f * mWindow ->GetDeltaTime ()),
4369 glm::normalize (glm::vec3 (0.0 , 1.0 , 0.0 )));
4470
71+ mModelMatrix [2 ] = glm::rotate (
72+ mModelMatrix [2 ], glm::radians (15 .0f * mWindow ->GetDeltaTime ()),
73+ glm::normalize (glm::vec3 (0.0 , 1.0 , 0.0 )));
74+
75+ mModelMatrix [3 ] = glm::rotate (
76+ mModelMatrix [3 ], glm::radians (15 .0f * mWindow ->GetDeltaTime ()),
77+ glm::normalize (glm::vec3 (0.0 , 1.0 , 0.0 )));
78+
4579 mRenderer ->BeginFrame ();
4680
4781 if (mInstanceMatrixBuffers == nullptr )
4882 mInstanceMatrixBuffers =
4983 mRenderer ->GetBufferBuilder ()
5084 .SetData (&mModelMatrix [0 ][0 ])
51- .SetSize (sizeof (glm::mat4) * 2 )
85+ .SetSize (sizeof (glm::mat4) * 4 )
5286 .SetUsage (fra::BufferUsage::Instance)
5387 .Build ();
5488 else
5589 mInstanceMatrixBuffers ->Copy (
56- &mModelMatrix [0 ][0 ], sizeof (glm::mat4) * 2 );
90+ &mModelMatrix [0 ][0 ], sizeof (glm::mat4) * 4 );
5791
5892 mRenderer ->BindBuffer (mInstanceMatrixBuffers );
5993
60- for (const auto & mesh : mModelA )
94+ mMaterialPool ->Bind (mSpaceShipMaterial );
95+
96+ for (const auto & mesh : mSpaceShipModel )
6197 {
62- mTexturePool ->Bind (mTextureA , 0 );
63- mTexturePool ->Bind (mTextureB , 1 );
64- mTexturePool ->Bind (mTextureC , 2 );
98+ mMeshPool ->DrawInstanced (mesh, 2 );
99+ }
65100
66- mMeshPool ->DrawInstanced (mesh, 1 );
67- mMeshPool ->DrawInstanced (mesh, 1 , 1 );
101+ mMaterialPool ->Bind (mSofaMaterial );
102+
103+ for (const auto & mesh : mSofaModel )
104+ {
105+ mMeshPool ->DrawInstanced (mesh, 2 , 2 );
68106 }
69107
70108 mRenderer ->EndFrame ();
71109 }
72110
73111 private:
74- std::vector<unsigned > mModelA ;
75- std::uint32_t mTextureA {};
76-
77- std::vector<unsigned > mModelB ;
78- std::uint32_t mTextureB {};
79- std::uint32_t mTextureC {};
80-
81- Ref<fra::TexturePool> mTexturePool ;
82- Ref<fra::MeshPool> mMeshPool ;
83- glm::mat4 mModelMatrix [2 ] {};
84- float mCurrentTime {};
112+ std::vector<unsigned > mSofaModel ;
113+ std::uint32_t mSofaAlbedo {};
114+ std::uint32_t mSofaNormal {};
115+ std::uint32_t mSofaRoughness {};
116+ std::uint32_t mSofaMaterial {};
117+
118+ std::vector<unsigned > mSpaceShipModel ;
119+ std::uint32_t mSpaceShipAlbedo {};
120+ std::uint32_t mSpaceShipNormal {};
121+ std::uint32_t mSpaceShipRoughness {};
122+ std::uint32_t mSpaceShipMaterial {};
123+
124+ Ref<fra::MaterialPool> mMaterialPool ;
125+ Ref<fra::TexturePool> mTexturePool ;
126+ Ref<fra::MeshPool> mMeshPool ;
127+ glm::mat4 mModelMatrix [4 ] {};
128+ float mCurrentTime {};
85129
86130 Ref<fra::Buffer> mInstanceMatrixBuffers ;
87131};
0 commit comments