Commit cef53f68 authored by Administrator's avatar Administrator
Browse files

added IndexBuffer; re-structured bindables and drawables into filters

parent ab9158a5
......@@ -17,9 +17,9 @@ void Drawable::AddBind(std::unique_ptr<Bindable> bind) noexcept
binds.push_back(std::move(bind));
}
/*void Drawable::AddIndexBuffer(std::unique_ptr<IndexBuffer> ibuf) noexcept
void Drawable::AddIndexBuffer(std::unique_ptr<IndexBuffer> ibuf) noexcept
{
assert("Attempting to add index buffer a second time" && pIndexBuffer == nullptr);
pIndexBuffer = ibuf.get();
binds.push_back(std::move(ibuf));
}*/
}
......@@ -4,6 +4,7 @@
#include <memory>
#include <vector>
#include "Bindable.h"
#include "IndexBuffer.h"
class Bindable;
......@@ -17,9 +18,9 @@ public:
//virtual void Update(float dt) noexcept = 0;
void AddBind(std::unique_ptr<Bindable> bind) noexcept;
//void AddIndexBuffer(std::unique_ptr<class IndexBuffer> ibuf) noexcept;
void AddIndexBuffer(std::unique_ptr<class IndexBuffer> ibuf) noexcept;
virtual ~Drawable() = default;
private:
//const IndexBuffer* pIndexBuffer = nullptr;
const IndexBuffer* pIndexBuffer = nullptr;
std::vector<std::unique_ptr<Bindable>> binds;
};
\ No newline at end of file
#include "IndexBuffer.h"
IndexBuffer::IndexBuffer(Graphics& gfx, const std::vector<unsigned short>& indices)
:
count((UINT)indices.size())
{
D3D11_BUFFER_DESC ibd = {};
ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
ibd.Usage = D3D11_USAGE_DEFAULT;
ibd.CPUAccessFlags = 0u;
ibd.MiscFlags = 0u;
ibd.ByteWidth = UINT(count * sizeof(unsigned short));
ibd.StructureByteStride = sizeof(unsigned short);
D3D11_SUBRESOURCE_DATA isd = {};
isd.pSysMem = indices.data();
GetDevice(gfx)->CreateBuffer(&ibd, &isd, &pIndexBuffer);
}
void IndexBuffer::Bind(Graphics& gfx) noexcept
{
GetContext(gfx)->IASetIndexBuffer(pIndexBuffer.Get(), DXGI_FORMAT_R16_UINT, 0u);
}
UINT IndexBuffer::GetCount() const noexcept
{
return count;
}
#pragma once
#include "Bindable.h"
#include <d3d11.h>
#include <vector>
class IndexBuffer : public Bindable
{
public:
IndexBuffer(Graphics& gfx, const std::vector<unsigned short>& indices);
void Bind(Graphics& gfx) noexcept override;
UINT GetCount() const noexcept;
protected:
UINT count;
Microsoft::WRL::ComPtr<ID3D11Buffer> pIndexBuffer;
};
\ No newline at end of file
......@@ -130,6 +130,7 @@
<ClCompile Include="Bindable.cpp" />
<ClCompile Include="Drawable.cpp" />
<ClCompile Include="Graphics.cpp" />
<ClCompile Include="IndexBuffer.cpp" />
<ClCompile Include="Timer.cpp" />
<ClCompile Include="Triangle.cpp" />
<ClCompile Include="VertexBuffer.cpp" />
......@@ -159,6 +160,7 @@
<ClInclude Include="Bindable.h" />
<ClInclude Include="Drawable.h" />
<ClInclude Include="Graphics.h" />
<ClInclude Include="IndexBuffer.h" />
<ClInclude Include="Structs.h" />
<ClInclude Include="Timer.h" />
<ClInclude Include="Triangle.h" />
......
#pragma once
// 用于定义顶点的结构,三维坐标
struct StructVertex
{
struct
......
......@@ -2,6 +2,7 @@
#include "Triangle.h"
#include "Bindable.h"
#include "VertexBuffer.h"
#include "IndexBuffer.h"
Triangle::Triangle(Graphics& gfx, float** position, float r, float g, float b)
:
......@@ -26,6 +27,7 @@ Triangle::Triangle(Graphics& gfx, float** position, float r, float g, float b)
AddBind(std::move(pvs));
AddBind(std::make_unique<PixelShader>(gfx, L"PixelShader.cso"));
*/
const std::vector<unsigned short> indices =
{
......@@ -38,6 +40,7 @@ Triangle::Triangle(Graphics& gfx, float** position, float r, float g, float b)
};
AddIndexBuffer(std::make_unique<IndexBuffer>(gfx, indices));
/*
struct ConstantBuffer2
{
struct
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment