@@ -11,6 +11,7 @@ Mesh::Mesh(std::string name) : Component::Component(name) {
1111 this ->m_renderer = this ->m_core ->GetRenderer ();
1212
1313 this ->m_bMeshLoaded = false ;
14+ this ->m_nTotalVertices = 0 ;
1415}
1516
1617void Mesh::Init () {
@@ -66,21 +67,64 @@ void Mesh::UploadVertices() {
6667void Mesh::Update () {
6768 Component::Update ();
6869
70+ }
71+
72+ void Mesh::Render () {
73+ this ->m_list ->IASetPrimitiveTopology (D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
6974 this ->m_list ->IASetVertexBuffers (0 , this ->m_VBVs .size (), &this ->m_VBVs [0 ]);
75+
76+ this ->m_list ->DrawInstanced (this ->m_nTotalVertices , 1 , 0 , 0 );
77+ // for (D3D12_VERTEX_BUFFER_VIEW vbv : this->m_VBVs) {
78+ // //this->m_list->DrawInstanced(nVertexCount, )
79+ // }
80+ }
81+
82+ void Mesh::InitPipeline () {
83+ this ->m_shader = new Shader (" GBufferPass.hlsl" , " VertexMain" , " PixelMain" );
84+
85+ LPVOID lpVertex, lpPixel = nullptr ;
86+ UINT nVertexSize = this ->m_shader ->GetBuffer (SHADER_BUFFER::VERTEX, lpVertex);
87+ UINT nPixelSize = this ->m_shader ->GetBuffer (SHADER_BUFFER::VERTEX, lpVertex);
88+
89+ D3D12_ROOT_SIGNATURE_DESC rootDesc = { };
90+ rootDesc.pParameters = nullptr ;
91+ rootDesc.NumParameters = 0 ;
92+ rootDesc.pStaticSamplers = nullptr ;
93+ rootDesc.NumStaticSamplers = 0 ;
94+ rootDesc.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT;
95+
96+ ComPtr<ID3DBlob> rsBlob, rsErrBlob;
97+ ThrowIfFailed (D3D12SerializeRootSignature (&rootDesc, D3D_ROOT_SIGNATURE_VERSION_1, rsBlob.GetAddressOf (), rsErrBlob.GetAddressOf ()));
98+
99+ if (rsErrBlob) {
100+ spdlog::error (" {0}: Error serializing root signature. {1}" , this ->m_name , (char *)rsErrBlob->GetBufferPointer ());
101+ return ;
102+ }
103+
104+ D3D12_INPUT_ELEMENT_DESC layout[] = {
105+ { " POSITION" , 0 , DXGI_FORMAT_R32G32B32_FLOAT, 0 , 0 , D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, NULL },
106+ { " TEXCOORD" , 0 , DXGI_FORMAT_R32G32B32_FLOAT, 0 , 12 , D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, NULL }
107+ };
108+
109+ D3D12_GRAPHICS_PIPELINE_STATE_DESC plDesc = { };
70110}
71111
72112void Mesh::D3D12Init (D3D12* renderer) {
73113 renderer->GetDevice (this ->m_dev );
74114 renderer->GetCommandList (this ->m_list );
75115
76116 this ->UploadVertices ();
117+ this ->InitPipeline ();
77118}
78119
79120/*
80121 Load a model from an FBX file with assimp.
81122*/
82123void Mesh::LoadModel (std::string filename) {
83- if (this ->m_bMeshLoaded ) return ;
124+ if (this ->m_bMeshLoaded ) {
125+ spdlog::error (" {0}: Tried to load another file when meshes already loaded" , this ->m_name );
126+ return ;
127+ };
84128
85129 Assimp::Importer importer;
86130 const aiScene* scene = importer.ReadFile (filename, NULL );
@@ -89,6 +133,7 @@ void Mesh::LoadModel(std::string filename) {
89133 aiMesh* mesh = scene->mMeshes [i];
90134 aiMaterial* material = scene->mMaterials [mesh->mMaterialIndex ];
91135 std::vector<Vertex> vertices;
136+ this ->m_nTotalVertices += mesh->mNumVertices ;
92137
93138 for (UINT x = 0 ; x < mesh->mNumVertices ; x++) {
94139 aiVector3D vec = mesh->mVertices [x];
0 commit comments