Commit 42c3decc authored by Administrator's avatar Administrator
Browse files

add bindables and drawables

parent ca26976f
#include "App.h"
#include <sstream>
#include <iomanip>
#include "Box.h"
#include <memory>
App::App()
:
wnd( 800,600,"Oasis Demo")
{}
{
std::mt19937 rng(std::random_device{}());
std::uniform_real_distribution<float> adist(0.0f, 3.1415f * 2.0f);
std::uniform_real_distribution<float> ddist(0.0f, 3.1415f * 2.0f);
std::uniform_real_distribution<float> odist(0.0f, 3.1415f * 0.3f);
std::uniform_real_distribution<float> rdist(6.0f, 20.0f);
for (auto i = 0; i < 8; i++)
{
boxes.push_back(std::make_unique<Box>(
wnd.Gfx(), rng, adist,
ddist, odist, rdist
));
}
wnd.Gfx().SetProjection(DirectX::XMMatrixPerspectiveLH(1.0f, 3.0f / 4.0f, 0.5f, 40.0f));
}
int App::Go()
{
......@@ -21,14 +37,17 @@ int App::Go()
}
}
App::~App()
{}
void App::DoFrame()
{
const float c = sin(timer.Peek()) / 2.0f + 0.5f;
wnd.Gfx().ClearBuffer(c, c, 1.0f);
wnd.Gfx().DrawTestTriangle(
timer.Peek(),
wnd.mouse.GetPosX() / 400.0f - 1.0f,
- wnd.mouse.GetPosY() / 300.0f + 1.0f
);
auto dt = timer.Mark();
wnd.Gfx().ClearBuffer(0.07f, 0.0f, 0.12f);
for (auto& b : boxes)
{
b->Update(dt);
b->Draw(wnd.Gfx());
}
wnd.Gfx().EndFrame();
}
\ No newline at end of file
......@@ -8,9 +8,11 @@ public:
App();
// master frame / message loop
int Go();
~App();
private:
void DoFrame();
private:
Window wnd;
ChiliTimer timer;
std::vector<std::unique_ptr<class Box>> boxes;
};
\ No newline at end of file
#include "Bindable.h"
ID3D11DeviceContext* Bindable::GetContext( Graphics& gfx ) noexcept
{
return gfx.pContext.Get();
}
ID3D11Device* Bindable::GetDevice( Graphics& gfx ) noexcept
{
return gfx.pDevice.Get();
}
DxgiInfoManager& Bindable::GetInfoManager( Graphics& gfx ) noexcept(!IS_DEBUG)
{
#ifndef NDEBUG
return gfx.infoManager;
#else
throw std::logic_error( "YouFuckedUp! (tried to access gfx.infoManager in Release config)" );
#endif
}
#pragma once
#include "Graphics.h"
class Bindable
{
public:
virtual void Bind( Graphics& gfx ) noexcept = 0;
virtual ~Bindable() = default;
protected:
static ID3D11DeviceContext* GetContext( Graphics& gfx ) noexcept;
static ID3D11Device* GetDevice( Graphics& gfx ) noexcept;
static DxgiInfoManager& GetInfoManager( Graphics& gfx ) noexcept(!IS_DEBUG);
};
\ No newline at end of file
#pragma once
#include "ConstantBuffers.h"
#include "IndexBuffer.h"
#include "InputLayout.h"
#include "PixelShader.h"
#include "Topology.h"
#include "TransformCbuf.h"
#include "VertexBuffer.h"
#include "VertexShader.h"
\ No newline at end of file
#include "Box.h"
#include "BindableBase.h"
#include "GraphicsThrowMacros.h"
Box::Box( Graphics& gfx,
std::mt19937& rng,
std::uniform_real_distribution<float>& adist,
std::uniform_real_distribution<float>& ddist,
std::uniform_real_distribution<float>& odist,
std::uniform_real_distribution<float>& rdist )
:
r( rdist( rng ) ),
droll( ddist( rng ) ),
dpitch( ddist( rng ) ),
dyaw( ddist( rng ) ),
dphi( odist( rng ) ),
dtheta( odist( rng ) ),
dchi( odist( rng ) ),
chi( adist( rng ) ),
theta( adist( rng ) ),
phi( adist( rng ) )
{
struct Vertex
{
struct
{
float x;
float y;
float z;
} pos;
};
const std::vector<Vertex> vertices =
{
{ -1.0f,-1.0f,-1.0f },
{ 1.0f,-1.0f,-1.0f },
{ -1.0f,1.0f,-1.0f },
{ 1.0f,1.0f,-1.0f },
{ -1.0f,-1.0f,1.0f },
{ 1.0f,-1.0f,1.0f },
{ -1.0f,1.0f,1.0f },
{ 1.0f,1.0f,1.0f },
};
AddBind( std::make_unique<VertexBuffer>( gfx,vertices ) );
auto pvs = std::make_unique<VertexShader>( gfx,L"VertexShader.cso" );
auto pvsbc = pvs->GetBytecode();
AddBind( std::move( pvs ) );
AddBind( std::make_unique<PixelShader>( gfx,L"PixelShader.cso" ) );
const std::vector<unsigned short> indices =
{
0,2,1, 2,3,1,
1,3,5, 3,7,5,
2,6,3, 3,6,7,
4,5,7, 4,7,6,
0,4,2, 2,4,6,
0,1,4, 1,5,4
};
AddIndexBuffer( std::make_unique<IndexBuffer>( gfx,indices ) );
struct ConstantBuffer2
{
struct
{
float r;
float g;
float b;
float a;
} face_colors[6];
};
const ConstantBuffer2 cb2 =
{
{
{ 1.0f,0.0f,1.0f },
{ 1.0f,0.0f,0.0f },
{ 0.0f,1.0f,0.0f },
{ 0.0f,0.0f,1.0f },
{ 1.0f,1.0f,0.0f },
{ 0.0f,1.0f,1.0f },
}
};
AddBind( std::make_unique<PixelConstantBuffer<ConstantBuffer2>>( gfx,cb2 ) );
const std::vector<D3D11_INPUT_ELEMENT_DESC> ied =
{
{ "Position",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 },
};
AddBind( std::make_unique<InputLayout>( gfx,ied,pvsbc ) );
AddBind( std::make_unique<Topology>( gfx,D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ) );
AddBind( std::make_unique<TransformCbuf>( gfx,*this ) );
}
void Box::Update( float dt ) noexcept
{
roll += droll * dt;
pitch += dpitch * dt;
yaw += dyaw * dt;
theta += dtheta * dt;
phi += dphi * dt;
chi += dchi * dt;
}
DirectX::XMMATRIX Box::GetTransformXM() const noexcept
{
return DirectX::XMMatrixRotationRollPitchYaw( pitch,yaw,roll ) *
DirectX::XMMatrixTranslation( r,0.0f,0.0f ) *
DirectX::XMMatrixRotationRollPitchYaw( theta,phi,chi ) *
DirectX::XMMatrixTranslation( 0.0f,0.0f,20.0f );
}
#pragma once
#include "Drawable.h"
class Box : public Drawable
{
public:
Box( Graphics& gfx,std::mt19937& rng,
std::uniform_real_distribution<float>& adist,
std::uniform_real_distribution<float>& ddist,
std::uniform_real_distribution<float>& odist,
std::uniform_real_distribution<float>& rdist );
void Update( float dt ) noexcept override;
DirectX::XMMATRIX GetTransformXM() const noexcept override;
private:
// positional
float r;
float roll = 0.0f;
float pitch = 0.0f;
float yaw = 0.0f;
float theta;
float phi;
float chi;
// speed (delta/s)
float droll;
float dpitch;
float dyaw;
float dtheta;
float dphi;
float dchi;
};
\ No newline at end of file
#pragma once
#include "Bindable.h"
#include "GraphicsThrowMacros.h"
template<typename C>
class ConstantBuffer : public Bindable
{
public:
void Update( Graphics& gfx,const C& consts )
{
INFOMAN( gfx );
D3D11_MAPPED_SUBRESOURCE msr;
GFX_THROW_INFO( GetContext( gfx )->Map(
pConstantBuffer.Get(),0u,
D3D11_MAP_WRITE_DISCARD,0u,
&msr
) );
memcpy( msr.pData,&consts,sizeof( consts ) );
GetContext( gfx )->Unmap( pConstantBuffer.Get(),0u );
}
ConstantBuffer( Graphics& gfx,const C& consts )
{
INFOMAN( gfx );
D3D11_BUFFER_DESC cbd;
cbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
cbd.Usage = D3D11_USAGE_DYNAMIC;
cbd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
cbd.MiscFlags = 0u;
cbd.ByteWidth = sizeof( consts );
cbd.StructureByteStride = 0u;
D3D11_SUBRESOURCE_DATA csd = {};
csd.pSysMem = &consts;
GFX_THROW_INFO( GetDevice( gfx )->CreateBuffer( &cbd,&csd,&pConstantBuffer ) );
}
ConstantBuffer( Graphics& gfx )
{
INFOMAN( gfx );
D3D11_BUFFER_DESC cbd;
cbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
cbd.Usage = D3D11_USAGE_DYNAMIC;
cbd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
cbd.MiscFlags = 0u;
cbd.ByteWidth = sizeof( C );
cbd.StructureByteStride = 0u;
GFX_THROW_INFO( GetDevice( gfx )->CreateBuffer( &cbd,nullptr,&pConstantBuffer ) );
}
protected:
Microsoft::WRL::ComPtr<ID3D11Buffer> pConstantBuffer;
};
template<typename C>
class VertexConstantBuffer : public ConstantBuffer<C>
{
using ConstantBuffer<C>::pConstantBuffer;
using Bindable::GetContext;
public:
using ConstantBuffer<C>::ConstantBuffer;
void Bind( Graphics& gfx ) noexcept override
{
GetContext( gfx )->VSSetConstantBuffers( 0u,1u,pConstantBuffer.GetAddressOf() );
}
};
template<typename C>
class PixelConstantBuffer : public ConstantBuffer<C>
{
using ConstantBuffer<C>::pConstantBuffer;
using Bindable::GetContext;
public:
using ConstantBuffer<C>::ConstantBuffer;
void Bind( Graphics& gfx ) noexcept override
{
GetContext( gfx )->PSSetConstantBuffers( 0u,1u,pConstantBuffer.GetAddressOf() );
}
};
\ No newline at end of file
#include "Drawable.h"
#include "GraphicsThrowMacros.h"
#include "IndexBuffer.h"
#include <cassert>
#include <typeinfo>
void Drawable::Draw( Graphics& gfx ) const noexcept(!IS_DEBUG)
{
for( auto& b : binds )
{
b->Bind( gfx );
}
gfx.DrawIndexed( pIndexBuffer->GetCount() );
}
void Drawable::AddBind( std::unique_ptr<Bindable> bind ) noexcept(!IS_DEBUG)
{
assert( "*Must* use AddIndexBuffer to bind index buffer" && typeid(*bind) != typeid(IndexBuffer) );
binds.push_back( std::move( bind ) );
}
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 ) );
}
#pragma once
#include "Graphics.h"
#include <DirectXMath.h>
class Bindable;
class Drawable
{
public:
Drawable() = default;
Drawable( const Drawable& ) = delete;
virtual DirectX::XMMATRIX GetTransformXM() const noexcept = 0;
void Draw( Graphics& gfx ) const noexcept(!IS_DEBUG);
virtual void Update( float dt ) noexcept = 0;
void AddBind( std::unique_ptr<Bindable> bind ) noexcept(!IS_DEBUG);
void AddIndexBuffer( std::unique_ptr<class IndexBuffer> ibuf ) noexcept;
virtual ~Drawable() = default;
private:
const IndexBuffer* pIndexBuffer = nullptr;
std::vector<std::unique_ptr<Bindable>> binds;
};
\ No newline at end of file
......@@ -96,6 +96,16 @@ Graphics::Graphics( HWND hWnd )
// Bind depth stencil view to out put merger
pContext->OMSetRenderTargets(1u, pTarget.GetAddressOf(), pDSView.Get());
// configure viewport
D3D11_VIEWPORT vp;
vp.Width = 800.0f;
vp.Height = 600.0f;
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
vp.TopLeftX = 0.0f;
vp.TopLeftY = 0.0f;
pContext->RSSetViewports(1u, &vp);
}
void Graphics::EndFrame()
......@@ -125,222 +135,19 @@ void Graphics::ClearBuffer(float red, float green, float blue) noexcept
pContext->ClearDepthStencilView(pDSView.Get(), D3D11_CLEAR_DEPTH, 1.0f, 0u);
}
void Graphics::DrawTestTriangle(float angle, float x, float y)
void Graphics::DrawIndexed(UINT count) noexcept(!IS_DEBUG)
{
namespace wrl = Microsoft::WRL;
HRESULT hr;
struct Vertex
{
struct
{
float x;
float y;
float z;
} pos;
};
// create vertex buffer (8 vertices for one cube)
const Vertex vertices[] =
{
// left bottom back
{ -1.0f, -1.0f, -1.0f },
// right bottom back
{ 1.0f, -1.0f, -1.0f },
// left top back
{ -1.0f, 1.0f, -1.0f },
// right top back
{ 1.0f, 1.0f, -1.0f },
// left bottom front
{ -1.0f, -1.0f, 1.0f },
// right bottom front
{ 1.0f, -1.0f, 1.0f },
// left top front
{ -1.0f, 1.0f, 1.0f },
// right top front
{ 1.0f, 1.0f, 1.0f },
};
wrl::ComPtr<ID3D11Buffer> pVertexBuffer;
D3D11_BUFFER_DESC bd = {};
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.Usage = D3D11_USAGE_DEFAULT;
bd.CPUAccessFlags = 0u;
bd.MiscFlags = 0u;
bd.ByteWidth = sizeof(vertices);
bd.StructureByteStride = sizeof(Vertex);
D3D11_SUBRESOURCE_DATA sd = {};
sd.pSysMem = vertices;
GFX_THROW_INFO(pDevice->CreateBuffer(&bd, &sd, &pVertexBuffer));
// Bind vertex buffer to pipeline
const UINT stride = sizeof(Vertex);
const UINT offset = 0u;
pContext->IASetVertexBuffers(0u, 1u, pVertexBuffer.GetAddressOf(), &stride, &offset);
// Create index buffer
const unsigned short indices[] =
{
// back surface
0, 2, 1, 2, 3, 1,
// right surface
1, 3, 5, 3, 7, 5,
// top surface
2, 6, 3, 3, 6, 7,
// front surface
4, 5, 7, 4, 7, 6,
// left surface
0, 4, 2, 2, 4, 6,
// bottom surface
0, 1, 4, 1, 5, 4,
};
wrl::ComPtr<ID3D11Buffer> pIndexBuffer;
D3D11_BUFFER_DESC ibd = {};
ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
ibd.Usage = D3D11_USAGE_DEFAULT;
ibd.CPUAccessFlags = 0u;
ibd.MiscFlags = 0u;
ibd.ByteWidth = sizeof(indices);
ibd.StructureByteStride = sizeof(unsigned short);
D3D11_SUBRESOURCE_DATA isd = {};
isd.pSysMem = indices;
GFX_THROW_INFO(pDevice->CreateBuffer(&ibd, &isd, &pIndexBuffer));
// Bind index buffer to pipeline
pContext->IASetIndexBuffer(pIndexBuffer.Get(), DXGI_FORMAT_R16_UINT, 0u);
// Create constant buffer for transformation matrix
struct ConstantBuffer
{
// Use extended mathematics matrix which is optmized for SIMD
// SIMD (Single Instruction Multiple Data) is available in mordern processors
dx::XMMATRIX transform;
};
const float heightWidthRatio = 0.3f / 0.4f;
const ConstantBuffer cb =
{
// transpose the matrix to change from row_major to column_major
dx::XMMatrixTranspose(
// rotate Z axis
dx::XMMatrixRotationZ(-angle)
// rotate X axis
* dx::XMMatrixRotationX(-angle)
// rotate Y axis
* dx::XMMatrixRotationY(-angle)
// attach the image to mouse
* dx::XMMatrixTranslation( x, 0.0f, 4.0f + y )
// projection
* dx::XMMatrixPerspectiveLH( 1.0f, heightWidthRatio, 0.5f, 10.0f)
)
};
wrl::ComPtr<ID3D11Buffer> pConstantBuffer;
D3D11_BUFFER_DESC cbd = {};
cbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
cbd.Usage = D3D11_USAGE_DYNAMIC;
cbd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
cbd.MiscFlags = 0u;
cbd.ByteWidth = sizeof(cb);
cbd.StructureByteStride = 0u;
D3D11_SUBRESOURCE_DATA csd = {};
csd.pSysMem = &cb;
GFX_THROW_INFO(pDevice->CreateBuffer(&cbd, &csd, &pConstantBuffer));
// Bind constant buffer to vertex
pContext->VSSetConstantBuffers(0u, 1u, pConstantBuffer.GetAddressOf());
// Create constant buffer for color
struct ColorConstantBuffer
{
struct
{
float r;
float g;
float b;
float a;
} face_colors[6];
};
const ColorConstantBuffer ccb =
{
{
{ 1.0f, 0.0f, 1.0f },
{ 1.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f },
{ 1.0f, 1.0f, 0.0f },
{ 0.0f, 1.0f, 1.0f },
}
};
wrl::ComPtr<ID3D11Buffer> pColorConstantBuffer;
D3D11_BUFFER_DESC ccbd = {};
ccbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
ccbd.Usage = D3D11_USAGE_DEFAULT;
ccbd.CPUAccessFlags = 0u;
ccbd.MiscFlags = 0u;
ccbd.ByteWidth = sizeof(ccb);
ccbd.StructureByteStride = 0u;
D3D11_SUBRESOURCE_DATA ccsd = {};
ccsd.pSysMem = &ccb;
GFX_THROW_INFO(pDevice->CreateBuffer(&ccbd, &ccsd, &pColorConstantBuffer));
// Bind constant buffer to vertex
pContext->PSSetConstantBuffers(0u, 1u, pColorConstantBuffer.GetAddressOf());
// create pixel shader
wrl::ComPtr<ID3D11PixelShader> pPixelShader;
wrl::ComPtr<ID3DBlob> pBlob;
GFX_THROW_INFO(D3DReadFileToBlob(L"PixelShader.cso", &pBlob));
GFX_THROW_INFO(pDevice->CreatePixelShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), nullptr, &pPixelShader));
// bind pixel shader
pContext->PSSetShader(pPixelShader.Get(), nullptr, 0u);
// create vertex shader
wrl::ComPtr<ID3D11VertexShader> pVertexShader;
GFX_THROW_INFO(D3DReadFileToBlob(L"VertexShader.cso", &pBlob));
GFX_THROW_INFO(pDevice->CreateVertexShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), nullptr, &pVertexShader));
// bind vertex shader
pContext->VSSetShader(pVertexShader.Get(), nullptr, 0u);
// create pixel shader
// input (vertex) layout (2d position only)
wrl::ComPtr<ID3D11InputLayout> pInputLayout;
const D3D11_INPUT_ELEMENT_DESC ied[] =
{
{ "Position",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 },
//{ "Color",0,DXGI_FORMAT_R32G32B32_FLOAT,0,12,D3D11_INPUT_PER_VERTEX_DATA,0 },
};
GFX_THROW_INFO(pDevice->CreateInputLayout(
ied, (UINT)std::size(ied),
pBlob->GetBufferPointer(),
pBlob->GetBufferSize(),
&pInputLayout
));
// bind vertex layout
pContext->IASetInputLayout(pInputLayout.Get());
// bind render target
// After apply depth stencil view to Output Merger, we remove this one
//pContext->OMSetRenderTargets(1u, pTarget.GetAddressOf(), nullptr);
// Set primitive topology to triangle list (groups of 3 vertices)
pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
GFX_THROW_INFO_ONLY( pContext->DrawIndexed( count,0u,0u ) );
}
// configure viewport
D3D11_VIEWPORT vp;
vp.Width = 800;
vp.Height = 600;
vp.MinDepth = 0;
vp.MaxDepth = 1;
vp.TopLeftX = 0;
vp.TopLeftY = 0;
pContext->RSSetViewports(1u, &vp);
void Graphics::SetProjection( DirectX::FXMMATRIX proj ) noexcept
{
projection = proj;
}
//GFX_THROW_INFO_ONLY(pContext->Draw((UINT)std::size(vertices), 0u));
GFX_THROW_INFO_ONLY(pContext->DrawIndexed((UINT)std::size(indices), 0u, 0u));
DirectX::XMMATRIX Graphics::GetProjection() const noexcept
{
return projection;
}
// Graphics exception stuff
......
......@@ -5,9 +5,14 @@
#include <wrl.h>
#include <vector>
#include "DxgiInfoManager.h"
#include <d3dcompiler.h>
#include <DirectXMath.h>
#include <memory>
#include <random>
class Graphics
{
friend class Bindable;
public:
class Exception : public ChiliException
{
......@@ -53,8 +58,12 @@ public:
void EndFrame();
// 刷新RGB
void ClearBuffer(float red, float green, float blue) noexcept;
void DrawTestTriangle(float angle, float x, float y);
//void DrawTestTriangle(float angle, float x, float y);
void DrawIndexed(UINT count) noexcept(!IS_DEBUG);
void SetProjection(DirectX::FXMMATRIX proj) noexcept;
DirectX::XMMATRIX GetProjection() const noexcept;
private:
DirectX::XMMATRIX projection;
#ifndef NDEBUG
DxgiInfoManager infoManager;
#endif
......
......@@ -2,7 +2,6 @@
// HRESULT hr should exist in the local scope for these macros to work
#define GFX_EXCEPT_NOINFO(hr) Graphics::HrException( __LINE__,__FILE__,(hr) )
#define GFX_THROW_NOINFO(hrcall) if( FAILED( hr = (hrcall) ) ) throw Graphics::HrException( __LINE__,__FILE__,hr )
......@@ -19,9 +18,9 @@
#endif
// macro for importing infomanager into local scope
// this.GetInfoManager() must exist
// this.GetInfoManager(Graphics gfx) must exist
#ifdef NDEBUG
#define INFOMAN() HRESULT hr
#define INFOMAN(gfx) HRESULT hr
#else
#define INFOMAN() HRESULT hr; DxgiInfoManager& infoManager = GetInfoManager()
#define INFOMAN(gfx) HRESULT hr; DxgiInfoManager& infoManager = GetInfoManager(gfx)
#endif
#include "IndexBuffer.h"
#include "GraphicsThrowMacros.h"
IndexBuffer::IndexBuffer( Graphics& gfx,const std::vector<unsigned short>& indices )
:
count( (UINT)indices.size() )
{
INFOMAN( gfx );
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();
GFX_THROW_INFO( 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"
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
#include "InputLayout.h"
#include "GraphicsThrowMacros.h"
InputLayout::InputLayout( Graphics& gfx,
const std::vector<D3D11_INPUT_ELEMENT_DESC>& layout,
ID3DBlob* pVertexShaderBytecode )
{
INFOMAN( gfx );
GFX_THROW_INFO( GetDevice( gfx )->CreateInputLayout(
layout.data(),(UINT)layout.size(),
pVertexShaderBytecode->GetBufferPointer(),
pVertexShaderBytecode->GetBufferSize(),
&pInputLayout
) );
}
void InputLayout::Bind( Graphics& gfx ) noexcept
{
GetContext( gfx )->IASetInputLayout( pInputLayout.Get() );
}
#pragma once
#include "Bindable.h"
class InputLayout : public Bindable
{
public:
InputLayout( Graphics& gfx,
const std::vector<D3D11_INPUT_ELEMENT_DESC>& layout,
ID3DBlob* pVertexShaderBytecode );
void Bind( Graphics& gfx ) noexcept override;
protected:
Microsoft::WRL::ComPtr<ID3D11InputLayout> pInputLayout;
};
\ No newline at end of file
#include "PixelShader.h"
#include "GraphicsThrowMacros.h"
PixelShader::PixelShader( Graphics& gfx,const std::wstring& path )
{
INFOMAN( gfx );
Microsoft::WRL::ComPtr<ID3DBlob> pBlob;
GFX_THROW_INFO( D3DReadFileToBlob( path.c_str(),&pBlob ) );
GFX_THROW_INFO( GetDevice( gfx )->CreatePixelShader( pBlob->GetBufferPointer(),pBlob->GetBufferSize(),nullptr,&pPixelShader ) );
}
void PixelShader::Bind( Graphics& gfx ) noexcept
{
GetContext( gfx )->PSSetShader( pPixelShader.Get(),nullptr,0u );
}
#pragma once
#include "Bindable.h"
class PixelShader : public Bindable
{
public:
PixelShader( Graphics& gfx,const std::wstring& path );
void Bind( Graphics& gfx ) noexcept override;
protected:
Microsoft::WRL::ComPtr<ID3D11PixelShader> pPixelShader;
};
\ No newline at end of file
......@@ -102,7 +102,7 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions); IS_DEBUG=true</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
......@@ -138,29 +138,51 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="App.cpp" />
<ClCompile Include="Bindable.cpp" />
<ClCompile Include="Box.cpp" />
<ClCompile Include="ChiliException.cpp" />
<ClCompile Include="ChiliTimer.cpp" />
<ClCompile Include="Drawable.cpp" />
<ClCompile Include="dxerr.cpp" />
<ClCompile Include="DxgiInfoManager.cpp" />
<ClCompile Include="Graphics.cpp" />
<ClCompile Include="IndexBuffer.cpp" />
<ClCompile Include="InputLayout.cpp" />
<ClCompile Include="Keyboard.cpp" />
<ClCompile Include="Mouse.cpp" />
<ClCompile Include="PixelShader.cpp" />
<ClCompile Include="Topology.cpp" />
<ClCompile Include="TransformCbuf.cpp" />
<ClCompile Include="VertexBuffer.cpp" />
<ClCompile Include="VertexShader.cpp" />
<ClCompile Include="Window.cpp" />
<ClCompile Include="WindowsMessageMap.cpp" />
<ClCompile Include="WinMain.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="App.h" />
<ClInclude Include="Bindable.h" />
<ClInclude Include="BindableBase.h" />
<ClInclude Include="Box.h" />
<ClInclude Include="ChiliException.h" />
<ClInclude Include="ChiliTimer.h" />
<ClInclude Include="ChiliWin.h" />
<ClInclude Include="ConstantBuffers.h" />
<ClInclude Include="Drawable.h" />
<ClInclude Include="dxerr.h" />
<ClInclude Include="DxgiInfoManager.h" />
<ClInclude Include="Graphics.h" />
<ClInclude Include="GraphicsThrowMacros.h" />
<ClInclude Include="IndexBuffer.h" />
<ClInclude Include="InputLayout.h" />
<ClInclude Include="Keyboard.h" />
<ClInclude Include="Mouse.h" />
<ClInclude Include="PixelShader.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="Topology.h" />
<ClInclude Include="TransformCbuf.h" />
<ClInclude Include="VertexBuffer.h" />
<ClInclude Include="VertexShader.h" />
<ClInclude Include="Window.h" />
<ClInclude Include="WindowsMessageMap.h" />
<ClInclude Include="WindowsThrowMacros.h" />
......
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