Simple dx render example.
This commit is contained in:
parent
36515556b8
commit
e0cad34d55
22 changed files with 339 additions and 60 deletions
|
@ -5,6 +5,8 @@
|
|||
#include "DrawingSurface.h"
|
||||
|
||||
#include "TriMesh.h"
|
||||
#include "TriFace.h"
|
||||
#include "FileLogger.h"
|
||||
|
||||
#include <directx/d3dx12.h>
|
||||
|
||||
|
@ -26,18 +28,45 @@ void DirectXMesh::update(DrawingContext* context, ID3D12Device* device)
|
|||
std::vector<float> color = { float(model_color[0]), float(model_color[1]), float(model_color[2]), float(model_color[3]) };
|
||||
|
||||
auto transform = mModel->getTransform();
|
||||
|
||||
for (const auto& face : dynamic_cast<TriMesh*>(mModel->getMesh())->getFaces())
|
||||
{
|
||||
for (const auto& loc : face->getNodeLocations(AbstractFace::Orientation::CW))
|
||||
{
|
||||
auto x = loc.getX() * transform.getScaleX() + transform.getLocation().getX();
|
||||
auto y = loc.getY() * transform.getScaleY() + transform.getLocation().getY();
|
||||
x = 2 * x - 1;
|
||||
y = 2 * y - 1;
|
||||
|
||||
Vertex vert;
|
||||
vert.position = DirectX::XMFLOAT3(x, y, 0.0);
|
||||
vert.color = DirectX::XMFLOAT4(color[0], color[1], color[2], color[3]);
|
||||
MLOG_INFO("Adding vert: " << x << " | " << y);
|
||||
mVertexBuffer.push_back(vert);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
for (const auto& node : mModel->getMesh()->getNodes())
|
||||
{
|
||||
auto x = node->getPoint().getX() * transform.getScaleX() + transform.getLocation().getX();
|
||||
x = 2 * x / width - 1.0;
|
||||
//x = 2 * x / width - 1.0;
|
||||
auto y = node->getPoint().getY() * transform.getScaleY() + transform.getLocation().getY();
|
||||
y = 2 * y / height;
|
||||
//y = 2 * y / height;
|
||||
Vertex vert;
|
||||
vert.position = DirectX::XMFLOAT3(x, y, 0.0);
|
||||
vert.color = DirectX::XMFLOAT4(color[0], color[1], color[2], color[3]);
|
||||
MLOG_INFO("Adding vert: " << x << " | " << y);
|
||||
mVertexBuffer.push_back(vert);
|
||||
}
|
||||
mIndexBuffer = dynamic_cast<TriMesh*>(mModel->getMesh())->getFaceNodeIds();
|
||||
*/
|
||||
|
||||
//mIndexBuffer = dynamic_cast<TriMesh*>(mModel->getMesh())->getFaceNodeIds();
|
||||
mIndexBuffer = { 0, 1, 2 };
|
||||
for (auto id : mIndexBuffer)
|
||||
{
|
||||
MLOG_INFO("Adding id: " << id);
|
||||
}
|
||||
|
||||
createD3dVertexBuffer(device);
|
||||
createD3dIndexBuffer(device);
|
||||
|
@ -88,6 +117,7 @@ void DirectXMesh::createD3dIndexBuffer(ID3D12Device* device)
|
|||
|
||||
mIndexBufferView.BufferLocation = mD3dIndexBuffer->GetGPUVirtualAddress();
|
||||
mIndexBufferView.SizeInBytes = buffer_size;
|
||||
mIndexBufferView.Format = DXGI_FORMAT_R16_UINT;
|
||||
}
|
||||
|
||||
void DirectXMesh::uploadIndexBuffer(unsigned char* pBuffer) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue