Skip to content

Commit

Permalink
Major refactor (started at the mesh hierarchy)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt77hias committed Mar 26, 2017
1 parent b1ecbcd commit 135c1a3
Show file tree
Hide file tree
Showing 37 changed files with 747 additions and 485 deletions.
3 changes: 2 additions & 1 deletion MAGE/FPS/src/core/FPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class TestScene : public Scene {
SharedPtr< BehaviorScript > test_script(new TestScript(test_model));
AddScript(test_script);

SpriteFont font(g_engine->GetRenderer().GetDevice(), L"assets/fonts/calibri.spritefont", SpriteFontDescriptor());
//TODO
SpriteFont font(*(g_engine->GetRenderer().GetDevice().Get()), L"assets/fonts/calibri.spritefont", SpriteFontDescriptor());
}

private:
Expand Down
7 changes: 5 additions & 2 deletions MAGE/MAGE.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@
<ClInclude Include="MAGE\src\memory\memory.hpp" />
<ClInclude Include="MAGE\src\memory\memory_arena.hpp" />
<ClInclude Include="MAGE\src\mesh\mesh.hpp" />
<ClInclude Include="MAGE\src\mesh\static_mesh.hpp" />
<ClInclude Include="MAGE\src\mesh\mesh_descriptor.hpp" />
<ClInclude Include="MAGE\src\mesh\obj\obj_loader.hpp" />
<ClInclude Include="MAGE\src\mesh\obj\obj_reader.hpp" />
<ClInclude Include="MAGE\src\mesh\obj\obj_tokens.hpp" />
<ClInclude Include="MAGE\src\mesh\sprite_mesh.hpp" />
<ClInclude Include="MAGE\src\mesh\sprite_batch_mesh.hpp" />
<ClInclude Include="MAGE\src\mesh\vertex.hpp" />
<ClInclude Include="MAGE\src\model\meshmodel.hpp" />
<ClInclude Include="MAGE\src\model\model.hpp" />
Expand Down Expand Up @@ -146,6 +147,8 @@
<ClCompile Include="MAGE\src\math\transform.cpp" />
<ClCompile Include="MAGE\src\math\view_frustum.cpp" />
<ClCompile Include="MAGE\src\memory\memory_arena.cpp" />
<ClCompile Include="MAGE\src\mesh\sprite_batch_mesh.cpp" />
<ClCompile Include="MAGE\src\mesh\static_mesh.cpp" />
<ClCompile Include="MAGE\src\mesh\vertex.cpp" />
<ClCompile Include="MAGE\src\model\meshmodel.cpp" />
<ClCompile Include="MAGE\src\model\model.cpp" />
Expand Down Expand Up @@ -321,7 +324,7 @@
<ItemGroup>
<None Include="MAGE\src\binary\binary_reader.tpp" />
<None Include="MAGE\src\memory\memory_arena.tpp" />
<None Include="MAGE\src\mesh\mesh.tpp" />
<None Include="MAGE\src\mesh\static_mesh.tpp" />
<None Include="MAGE\src\mesh\obj\obj_reader.tpp" />
<None Include="MAGE\src\model\model_descriptor.tpp" />
<None Include="MAGE\src\model\model_loader.tpp" />
Expand Down
26 changes: 19 additions & 7 deletions MAGE/MAGE.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@
<Filter Include="Header Files\shader\cso">
<UniqueIdentifier>{3e728b6b-cea7-411c-907f-9061e4579b11}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\mesh">
<UniqueIdentifier>{e7352513-7730-49d0-b678-7af1f64efbcc}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="MAGE\src\collection\collection.hpp">
Expand Down Expand Up @@ -306,9 +309,6 @@
<ClInclude Include="MAGE\src\parallel\id_generator.hpp">
<Filter>Header Files\parallel</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\mesh\mesh.hpp">
<Filter>Header Files\mesh</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\model\model.hpp">
<Filter>Header Files\model</Filter>
</ClInclude>
Expand Down Expand Up @@ -501,7 +501,13 @@
<ClInclude Include="MAGE\src\math\sprite_transform.hpp">
<Filter>Header Files\math</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\mesh\sprite_mesh.hpp">
<ClInclude Include="MAGE\src\mesh\sprite_batch_mesh.hpp">
<Filter>Header Files\mesh</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\mesh\static_mesh.hpp">
<Filter>Header Files\mesh</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\mesh\mesh.hpp">
<Filter>Header Files\mesh</Filter>
</ClInclude>
</ItemGroup>
Expand Down Expand Up @@ -680,6 +686,12 @@
<ClCompile Include="MAGE\src\rendering\rendering_state.cpp">
<Filter>Source Files\rendering</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\mesh\sprite_batch_mesh.cpp">
<Filter>Source Files\mesh</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\mesh\static_mesh.cpp">
<Filter>Source Files\mesh</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<FxCompile Include="MAGE\shaders\lambertian.fx">
Expand Down Expand Up @@ -708,9 +720,6 @@
<None Include="MAGE\src\scripting\variable_script.tpp">
<Filter>Header Files\scripting</Filter>
</None>
<None Include="MAGE\src\mesh\mesh.tpp">
<Filter>Header Files\mesh</Filter>
</None>
<None Include="MAGE\src\mesh\obj\obj_reader.tpp">
<Filter>Header Files\mesh\obj</Filter>
</None>
Expand All @@ -732,5 +741,8 @@
<None Include="MAGE\src\resource\resource_pool.tpp">
<Filter>Header Files\resource</Filter>
</None>
<None Include="MAGE\src\mesh\static_mesh.tpp">
<Filter>Header Files\mesh</Filter>
</None>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion MAGE/MAGE/src/core/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ namespace mage {

// Render the current scene.
m_renderer->BeginFrame();
m_scene->Render(m_renderer->GetDeviceContext());
m_scene->Render();
m_renderer->EndFrame();
}
else {
Expand Down
2 changes: 1 addition & 1 deletion MAGE/MAGE/src/core/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#pragma region

#define MAGE_VERSION_MAJOR 0
#define MAGE_VERSION_MINOR 10
#define MAGE_VERSION_MINOR 11
#define MAGE_VERSION_PATCH 0

#define MAGE_QUOTE(S) #S
Expand Down
195 changes: 122 additions & 73 deletions MAGE/MAGE/src/mesh/mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
#pragma region

#include "memory\memory.hpp"
#include "rendering\rendering_factory.hpp"
#include "collection\collection.hpp"
#include "rendering\rendering.hpp"

#pragma endregion

//-----------------------------------------------------------------------------
// Engine Definitions and Declarations
// Engine Declarations and Definitions
//-----------------------------------------------------------------------------
namespace mage {

Expand All @@ -24,50 +23,18 @@ namespace mage {
public:

/**
Constructs a mesh.
@pre @a vertices may not be equal to @c nullptr
@pre @a indices may not be equal to @c nullptr
@tparam VertexT
The vertex type.
@param[in] device
A reference to the rendering device.
@param[in] vertices
A pointer to an array of vertices.
@param[in] nb_vertices
The number of vertices.
@param[in] indices
A pointer to an array of indices.
@param[in] nb_indices
The number of indices.
Destructs this mesh.
*/
template < typename VertexT >
Mesh(ID3D11Device2 &device, const VertexT *vertices, size_t nb_vertices, const uint32_t *indices, size_t nb_indices);
virtual ~Mesh() = default;

/**
Constructs a mesh.
Returns the size of the vertices of this mesh.
@pre The number of vertices must be greater than zero.
@pre The number of indices must be greater than zero.
@tparam VertexT
The vertex type.
@param[in] device
A reference to the rendering device.
@param[in] vertices
A reference to a vector of vertices.
@param[in] indices
A reference to a vector of indices.
@param[in] device
A pointer to an D3D11 device.
@return The vertex size of this static mesh.
*/
template < typename VertexT >
Mesh(ID3D11Device2 &device, const vector< VertexT > &vertices, const vector< uint32_t > &indices)
: Mesh(device, vertices.data(), vertices.size(), indices.data(), indices.size()) {}

/**
Destructs this mesh.
*/
virtual ~Mesh() = default;
size_t GetVertexSize() const {
return m_vertex_size;
}

/**
Returns the number of vertices of this mesh.
Expand All @@ -87,8 +54,111 @@ namespace mage {
return m_nb_indices;
}

/**
Returns the index format of this mesh.
@return The index format of this mesh.
*/
DXGI_FORMAT GetIndexFormat() const {
return m_index_format;
}

/**
Returns the primitive topology of this mesh.
@return The primitive topology of this mesh.
*/
D3D11_PRIMITIVE_TOPOLOGY GetPrimitiveTopology() const {
return m_primitive_topology;
}

/**
Prepare the drawing of this mesh.
*/
void PrepareDrawing() {
UINT stride = static_cast< UINT >(m_vertex_size);
UINT offset = 0;
m_device_context->IASetVertexBuffers(0, 1, m_vertex_buffer.GetAddressOf(), &stride, &offset);
m_device_context->IASetIndexBuffer(m_index_buffer.Get(), m_index_format, 0);
m_device_context->IASetPrimitiveTopology(m_primitive_topology);
}

/**
Draws this mesh.
*/
void Draw() {
m_device_context->DrawIndexed(static_cast< UINT >(m_nb_indices), 0, 0);
}

/**
Draws this mesh.
@param[in] start_index
The start index.
@param[in] nb_indices
The number of indices.
*/
void Draw(size_t start_index, size_t nb_indices) {
m_device_context->DrawIndexed(static_cast< UINT >(nb_indices), static_cast< UINT >(start_index), 0);
}

protected:

/**
Constructs a mesh.
@param[in] device
A pointer to the device.
@param[in] device_context
A pointer to the device context.
@param[in] vertex_size
The vertex size.
@param[in] index_format
The index format.
@param[in] primitive_topology
The primitive topology.
*/
Mesh(ComPtr< ID3D11Device2 > device, ComPtr< ID3D11DeviceContext2 > device_context, size_t vertex_size,
DXGI_FORMAT index_format = DXGI_FORMAT_R32_UINT,
D3D11_PRIMITIVE_TOPOLOGY primitive_topology = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST)
: m_device(device), m_device_context(device_context),
m_vertex_size(vertex_size), m_nb_vertices(0), m_nb_indices(0),
m_index_format(index_format), m_primitive_topology(primitive_topology) {}

/**
Sets the number of vertices of this mesh to the given number.
@param[in] nb_vertices
The number of vertices of this mesh.
*/
void SetNumberOfVertices(size_t nb_vertices) {
m_nb_vertices = nb_vertices;
}

/**
Sets the number of indices of this mesh to the given number.
@param[in] nb_indices
The number of indices of this mesh.
*/
void SetNumberOfIndices(size_t nb_indices) {
m_nb_indices = nb_indices;
}

/**
A pointer to the device of this mesh.
*/
ComPtr< ID3D11Device2 > m_device;

/**
A pointer to the vertex buffer of this mesh.
*/
ComPtr< ID3D11Buffer > m_vertex_buffer;

void Render(ID3D11DeviceContext2 &device_context) const;
/**
A pointer to the index buffer of this mesh.
*/
ComPtr< ID3D11Buffer > m_index_buffer;

private:

Expand Down Expand Up @@ -129,26 +199,14 @@ namespace mage {
Mesh &operator=(Mesh &&mesh) = delete;

/**
Initializes this mesh.
@pre @a vertices may not be equal to @c nullptr
@pre @a indices may not be equal to @c nullptr
@tparam VertexT
The vertex type.
@param[in] device
A reference to the rendering device.
@param[in] vertices
A pointer to an array of vertices.
@param[in] indices
A pointer to an array of indices.
A pointer to the device context of this mesh.
*/
template < typename VertexT >
HRESULT InitializeMesh(ID3D11Device2 &device, const VertexT *vertices, const uint32_t *indices);
ComPtr< ID3D11DeviceContext2 > m_device_context;

/**
The size of the vertices of this mesh.
The vertex size of this static mesh.
*/
size_t m_vertex_size;
const size_t m_vertex_size;

/**
The number of vertices of this mesh.
Expand All @@ -161,22 +219,13 @@ namespace mage {
size_t m_nb_indices;

/**
A pointer to the vertex buffer of this mesh.
The index format of this mesh.
*/
ComPtr< ID3D11Buffer > m_vertex_buffer;
const DXGI_FORMAT m_index_format;

/**
A pointer to the index buffer of this mesh.
The primitive topology of this mesh.
*/
ComPtr< ID3D11Buffer > m_index_buffer;
const D3D11_PRIMITIVE_TOPOLOGY m_primitive_topology;
};
}

//-----------------------------------------------------------------------------
// Engine Includes
//-----------------------------------------------------------------------------
#pragma region

#include "mesh\mesh.tpp"

#pragma endregion
}
Loading

0 comments on commit 135c1a3

Please sign in to comment.