Commit 551cc463 authored by chili's avatar chili
Browse files

refactoring tentative

parent ffdeae8c
#include "App.h" #include "App.h"
#include "Box.h"
#include "Cylinder.h"
#include "Pyramid.h"
#include "SkinnedBox.h"
#include "AssTest.h" #include "AssTest.h"
#include <memory> #include <memory>
#include <algorithm> #include <algorithm>
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "ImguiManager.h" #include "ImguiManager.h"
#include "Camera.h" #include "Camera.h"
#include "PointLight.h" #include "PointLight.h"
#include "Model.h" #include "Mesh.h"
#include <set> #include <set>
class App class App
......
#include "AssTest.h" #include "AssTest.h"
#include "BindableBase.h" #include "BindableCommon.h"
#include "GraphicsThrowMacros.h" #include "GraphicsThrowMacros.h"
#include <assimp/Importer.hpp> #include <assimp/Importer.hpp>
#include <assimp/scene.h> #include <assimp/scene.h>
#include <assimp/postprocess.h> #include <assimp/postprocess.h>
#include "Vertex.h" #include "Vertex.h"
using namespace Bind;
AssTest::AssTest( Graphics& gfx,std::mt19937& rng, AssTest::AssTest( Graphics& gfx,std::mt19937& rng,
std::uniform_real_distribution<float>& adist, std::uniform_real_distribution<float>& adist,
std::uniform_real_distribution<float>& ddist, std::uniform_real_distribution<float>& ddist,
...@@ -20,8 +22,8 @@ AssTest::AssTest( Graphics& gfx,std::mt19937& rng, ...@@ -20,8 +22,8 @@ AssTest::AssTest( Graphics& gfx,std::mt19937& rng,
if( !IsStaticInitialized() ) if( !IsStaticInitialized() )
{ {
using hw3dexp::VertexLayout; using Dvtx::VertexLayout;
hw3dexp::VertexBuffer vbuf( std::move( Dvtx::VertexBuffer vbuf( std::move(
VertexLayout{} VertexLayout{}
.Append( VertexLayout::Position3D ) .Append( VertexLayout::Position3D )
.Append( VertexLayout::Normal ) .Append( VertexLayout::Normal )
......
#include "Bindable.h" #include "Bindable.h"
ID3D11DeviceContext* Bindable::GetContext( Graphics& gfx ) noexcept namespace Bind
{ {
return gfx.pContext.Get(); ID3D11DeviceContext* Bindable::GetContext( Graphics& gfx ) noexcept
} {
return gfx.pContext.Get();
}
ID3D11Device* Bindable::GetDevice( Graphics& gfx ) noexcept ID3D11Device* Bindable::GetDevice( Graphics& gfx ) noexcept
{ {
return gfx.pDevice.Get(); return gfx.pDevice.Get();
} }
DxgiInfoManager& Bindable::GetInfoManager( Graphics& gfx ) noexcept(IS_DEBUG) DxgiInfoManager& Bindable::GetInfoManager( Graphics& gfx ) noxnd
{ {
#ifndef NDEBUG #ifndef NDEBUG
return gfx.infoManager; return gfx.infoManager;
#else #else
throw std::logic_error( "YouFuckedUp! (tried to access gfx.infoManager in Release config)" ); throw std::logic_error( "YouFuckedUp! (tried to access gfx.infoManager in Release config)" );
#endif #endif
}
} }
#pragma once #pragma once
#include "Graphics.h" #include "Graphics.h"
#include "ConditionalNoexcept.h"
class Bindable namespace Bind
{ {
public: class Bindable
virtual void Bind( Graphics& gfx ) noexcept = 0; {
virtual ~Bindable() = default; public:
protected: virtual void Bind( Graphics& gfx ) noexcept = 0;
static ID3D11DeviceContext* GetContext( Graphics& gfx ) noexcept; virtual ~Bindable() = default;
static ID3D11Device* GetDevice( Graphics& gfx ) noexcept; protected:
static DxgiInfoManager& GetInfoManager( Graphics& gfx ) noexcept(IS_DEBUG); static ID3D11DeviceContext* GetContext( Graphics& gfx ) noexcept;
}; static ID3D11Device* GetDevice( Graphics& gfx ) noexcept;
\ No newline at end of file static DxgiInfoManager& GetInfoManager( Graphics& gfx ) noxnd;
};
}
\ No newline at end of file
cbuffer LightCBuf
{
float3 lightPos;
float3 ambient;
float3 diffuseColor;
float diffuseIntensity;
float attConst;
float attLin;
float attQuad;
};
cbuffer ObjectCBuf
{
float specularIntensity;
float specularPower;
float padding[2];
};
float4 main( float3 worldPos : Position,float3 n : Normal,float3 color : Color ) : SV_Target
{
// fragment to light vector data
const float3 vToL = lightPos - worldPos;
const float distToL = length( vToL );
const float3 dirToL = vToL / distToL;
// attenuation
const float att = 1.0f / (attConst + attLin * distToL + attQuad * (distToL * distToL));
// diffuse intensity
const float3 diffuse = diffuseColor * diffuseIntensity * att * max( 0.0f,dot( dirToL,n ) );
// reflected light vector
const float3 w = n * dot( vToL,n );
const float3 r = w * 2.0f - vToL;
// calculate specular intensity based on angle between viewing vector and reflection vector, narrow with power function
const float3 specular = att * (diffuseColor * diffuseIntensity) * specularIntensity * pow( max( 0.0f,dot( normalize( -r ),normalize( worldPos ) ) ),specularPower );
// final color
return float4(saturate((diffuse + ambient + specular) * color), 1.0f);
}
\ No newline at end of file
cbuffer CBuf
{
matrix modelView;
matrix modelViewProj;
};
struct VSOut
{
float3 worldPos : Position;
float3 normal : Normal;
float3 color : Color;
float4 pos : SV_Position;
};
VSOut main( float3 pos : Position,float3 n : Normal,float3 color : Color )
{
VSOut vso;
vso.worldPos = (float3)mul( float4(pos,1.0f),modelView );
vso.normal = mul( n,(float3x3)modelView );
vso.pos = mul( float4(pos,1.0f),modelViewProj );
vso.color = color;
return vso;
}
\ No newline at end of file
#include "Box.h"
#include "BindableBase.h"
#include "GraphicsThrowMacros.h"
#include "Cube.h"
#include "imgui/imgui.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,
std::uniform_real_distribution<float>& bdist,
DirectX::XMFLOAT3 material )
:
TestObject( gfx,rng,adist,ddist,odist,rdist )
{
namespace dx = DirectX;
if( !IsStaticInitialized() )
{
struct Vertex
{
dx::XMFLOAT3 pos;
dx::XMFLOAT3 n;
};
auto model = Cube::MakeIndependent<Vertex>();
model.SetNormalsIndependentFlat();
AddStaticBind( std::make_unique<VertexBuffer>( gfx,model.vertices ) );
auto pvs = std::make_unique<VertexShader>( gfx,L"PhongVS.cso" );
auto pvsbc = pvs->GetBytecode();
AddStaticBind( std::move( pvs ) );
AddStaticBind( std::make_unique<PixelShader>( gfx,L"PhongPS.cso" ) );
AddStaticIndexBuffer( std::make_unique<IndexBuffer>( gfx,model.indices ) );
const std::vector<D3D11_INPUT_ELEMENT_DESC> ied =
{
{ "Position",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 },
{ "Normal",0,DXGI_FORMAT_R32G32B32_FLOAT,0,12,D3D11_INPUT_PER_VERTEX_DATA,0 },
};
AddStaticBind( std::make_unique<InputLayout>( gfx,ied,pvsbc ) );
AddStaticBind( std::make_unique<Topology>( gfx,D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ) );
}
else
{
SetIndexFromStatic();
}
AddBind( std::make_unique<TransformCbuf>( gfx,*this ) );
materialConstants.color = material;
AddBind( std::make_unique<MaterialCbuf>( gfx,materialConstants,1u ) );
// model deformation transform (per instance, not stored as bind)
dx::XMStoreFloat3x3(
&mt,
dx::XMMatrixScaling( 1.0f,1.0f,bdist( rng ) )
);
}
DirectX::XMMATRIX Box::GetTransformXM() const noexcept
{
namespace dx = DirectX;
return dx::XMLoadFloat3x3( &mt ) * TestObject::GetTransformXM();
}
bool Box::SpawnControlWindow( int id,Graphics& gfx ) noexcept
{
using namespace std::string_literals;
bool dirty = false;
bool open = true;
if( ImGui::Begin( ("Box "s + std::to_string( id )).c_str(),&open ) )
{
ImGui::Text( "Material Properties" );
const auto cd = ImGui::ColorEdit3( "Material Color",&materialConstants.color.x );
const auto sid = ImGui::SliderFloat( "Specular Intensity",&materialConstants.specularIntensity,0.05f,4.0f,"%.2f",2 );
const auto spd = ImGui::SliderFloat( "Specular Power",&materialConstants.specularPower,1.0f,200.0f,"%.2f",2 );
dirty = cd || sid || spd;
ImGui::Text( "Position" );
ImGui::SliderFloat( "R",&r,0.0f,80.0f,"%.1f" );
ImGui::SliderAngle( "Theta",&theta,-180.0f,180.0f );
ImGui::SliderAngle( "Phi",&phi,-180.0f,180.0f );
ImGui::Text( "Orientation" );
ImGui::SliderAngle( "Roll",&roll,-180.0f,180.0f );
ImGui::SliderAngle( "Pitch",&pitch,-180.0f,180.0f );
ImGui::SliderAngle( "Yaw",&yaw,-180.0f,180.0f );
}
ImGui::End();
if( dirty )
{
SyncMaterial( gfx );
}
return open;
}
void Box::SyncMaterial( Graphics& gfx ) noexcept(!IS_DEBUG)
{
auto pConstPS = QueryBindable<MaterialCbuf>();
assert( pConstPS != nullptr );
pConstPS->Update( gfx,materialConstants );
}
#pragma once
#include "TestObject.h"
#include "ConstantBuffers.h"
class Box : public TestObject<Box>
{
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,
std::uniform_real_distribution<float>& bdist,
DirectX::XMFLOAT3 material );
DirectX::XMMATRIX GetTransformXM() const noexcept override;
// returns false if window is closed
bool SpawnControlWindow( int id,Graphics& gfx ) noexcept;
private:
void SyncMaterial( Graphics& gfx ) noexcept(!IS_DEBUG);
private:
struct PSMaterialConstant
{
DirectX::XMFLOAT3 color;
float specularIntensity = 0.6f;
float specularPower = 30.0f;
float padding[3];
} materialConstants;
using MaterialCbuf = PixelConstantBuffer<PSMaterialConstant>;
private:
// model transform
DirectX::XMFLOAT3X3 mt;
};
\ No newline at end of file
#pragma once
struct BGRAColor
{
unsigned char a;
unsigned char r;
unsigned char g;
unsigned char b;
};
\ No newline at end of file
float4 main( float4 color : Color ) : SV_Target
{
return color;
}
\ No newline at end of file
cbuffer CBuf
{
matrix transform;
};
struct VSOut
{
float4 color : Color;
float4 pos : SV_Position;
};
VSOut main( float3 pos : Position,float4 color : Color )
{
VSOut vso;
vso.pos = mul( float4(pos,1.0f),transform );
vso.color = color;
return vso;
}
\ No newline at end of file
#pragma once
#define noxnd noexcept(!IS_DEBUG)
\ No newline at end of file
...@@ -2,85 +2,88 @@ ...@@ -2,85 +2,88 @@
#include "Bindable.h" #include "Bindable.h"
#include "GraphicsThrowMacros.h" #include "GraphicsThrowMacros.h"
template<typename C> namespace Bind
class ConstantBuffer : public Bindable
{ {
public: template<typename C>
void Update( Graphics& gfx,const C& consts ) class ConstantBuffer : public Bindable
{ {
INFOMAN( gfx ); public:
void Update( Graphics& gfx,const C& consts )
{
INFOMAN( gfx );
D3D11_MAPPED_SUBRESOURCE msr; D3D11_MAPPED_SUBRESOURCE msr;
GFX_THROW_INFO( GetContext( gfx )->Map( GFX_THROW_INFO( GetContext( gfx )->Map(
pConstantBuffer.Get(),0u, pConstantBuffer.Get(),0u,
D3D11_MAP_WRITE_DISCARD,0u, D3D11_MAP_WRITE_DISCARD,0u,
&msr &msr
) ); ) );
memcpy( msr.pData,&consts,sizeof( consts ) ); memcpy( msr.pData,&consts,sizeof( consts ) );
GetContext( gfx )->Unmap( pConstantBuffer.Get(),0u ); GetContext( gfx )->Unmap( pConstantBuffer.Get(),0u );
} }
ConstantBuffer( Graphics& gfx,const C& consts,UINT slot = 0u ) ConstantBuffer( Graphics& gfx,const C& consts,UINT slot = 0u )
: :
slot( slot ) slot( slot )
{ {
INFOMAN( gfx ); INFOMAN( gfx );
D3D11_BUFFER_DESC cbd; D3D11_BUFFER_DESC cbd;
cbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; cbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
cbd.Usage = D3D11_USAGE_DYNAMIC; cbd.Usage = D3D11_USAGE_DYNAMIC;
cbd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; cbd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
cbd.MiscFlags = 0u; cbd.MiscFlags = 0u;
cbd.ByteWidth = sizeof( consts ); cbd.ByteWidth = sizeof( consts );
cbd.StructureByteStride = 0u; cbd.StructureByteStride = 0u;
D3D11_SUBRESOURCE_DATA csd = {}; D3D11_SUBRESOURCE_DATA csd = {};
csd.pSysMem = &consts; csd.pSysMem = &consts;
GFX_THROW_INFO( GetDevice( gfx )->CreateBuffer( &cbd,&csd,&pConstantBuffer ) ); GFX_THROW_INFO( GetDevice( gfx )->CreateBuffer( &cbd,&csd,&pConstantBuffer ) );
} }
ConstantBuffer( Graphics& gfx,UINT slot = 0u ) ConstantBuffer( Graphics& gfx,UINT slot = 0u )
: :
slot( slot ) slot( slot )
{ {
INFOMAN( gfx ); INFOMAN( gfx );
D3D11_BUFFER_DESC cbd; D3D11_BUFFER_DESC cbd;
cbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; cbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
cbd.Usage = D3D11_USAGE_DYNAMIC; cbd.Usage = D3D11_USAGE_DYNAMIC;
cbd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; cbd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
cbd.MiscFlags = 0u; cbd.MiscFlags = 0u;
cbd.ByteWidth = sizeof( C ); cbd.ByteWidth = sizeof( C );
cbd.StructureByteStride = 0u; cbd.StructureByteStride = 0u;
GFX_THROW_INFO( GetDevice( gfx )->CreateBuffer( &cbd,nullptr,&pConstantBuffer ) ); GFX_THROW_INFO( GetDevice( gfx )->CreateBuffer( &cbd,nullptr,&pConstantBuffer ) );
} }
protected: protected:
Microsoft::WRL::ComPtr<ID3D11Buffer> pConstantBuffer; Microsoft::WRL::ComPtr<ID3D11Buffer> pConstantBuffer;
UINT slot; UINT slot;
}; };
template<typename C> template<typename C>
class VertexConstantBuffer : public ConstantBuffer<C> class VertexConstantBuffer : public ConstantBuffer<C>
{
using ConstantBuffer<C>::pConstantBuffer;
using ConstantBuffer<C>::slot;
using Bindable::GetContext;
public:
using ConstantBuffer<C>::ConstantBuffer;
void Bind( Graphics& gfx ) noexcept override
{ {
GetContext( gfx )->VSSetConstantBuffers( slot,1u,pConstantBuffer.GetAddressOf() ); using ConstantBuffer<C>::pConstantBuffer;
} using ConstantBuffer<C>::slot;
}; using Bindable::GetContext;
public:
using ConstantBuffer<C>::ConstantBuffer;
void Bind( Graphics& gfx ) noexcept override
{
GetContext( gfx )->VSSetConstantBuffers( slot,1u,pConstantBuffer.GetAddressOf() );
}
};
template<typename C> template<typename C>
class PixelConstantBuffer : public ConstantBuffer<C> class PixelConstantBuffer : public ConstantBuffer<C>
{
using ConstantBuffer<C>::pConstantBuffer;
using ConstantBuffer<C>::slot;
using Bindable::GetContext;
public:
using ConstantBuffer<C>::ConstantBuffer;
void Bind( Graphics& gfx ) noexcept override
{ {
GetContext( gfx )->PSSetConstantBuffers( slot,1u,pConstantBuffer.GetAddressOf() ); using ConstantBuffer<C>::pConstantBuffer;
} using ConstantBuffer<C>::slot;
}; using Bindable::GetContext;
\ No newline at end of file public:
using ConstantBuffer<C>::ConstantBuffer;
void Bind( Graphics& gfx ) noexcept override
{
GetContext( gfx )->PSSetConstantBuffers( slot,1u,pConstantBuffer.GetAddressOf() );
}
};
}
\ No newline at end of file
#include "Cylinder.h"
#include "Prism.h"
#include "BindableBase.h"
Cylinder::Cylinder( 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,
std::uniform_real_distribution<float>& bdist,
std::uniform_int_distribution<int>& tdist )
:
TestObject( gfx,rng,adist,ddist,odist,rdist )
{
namespace dx = DirectX;
if( !IsStaticInitialized() )
{
auto pvs = std::make_unique<VertexShader>( gfx,L"PhongVS.cso" );
auto pvsbc = pvs->GetBytecode();
AddStaticBind( std::move( pvs ) );
AddStaticBind( std::make_unique<PixelShader>( gfx,L"IndexedPhongPS.cso" ) );
const std::vector<D3D11_INPUT_ELEMENT_DESC> ied =
{
{ "Position",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 },
{ "Normal",0,DXGI_FORMAT_R32G32B32_FLOAT,0,12,D3D11_INPUT_PER_VERTEX_DATA,0 },
};
AddStaticBind( std::make_unique<InputLayout>( gfx,ied,pvsbc ) );
AddStaticBind( std::make_unique<Topology>( gfx,D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ) );
struct PSMaterialConstant
{
dx::XMFLOAT3A colors[6] = {
{1.0f,0.0f,0.0f},
{0.0f,1.0f,0.0f},
{0.0f,0.0f,1.0f},
{1.0f,1.0f,0.0f},
{1.0f,0.0f,1.0f},
{0.0f,1.0f,1.0f},
};
float specularIntensity = 0.6f;
float specularPower = 30.0f;
} matConst;
AddStaticBind( std::make_unique<PixelConstantBuffer<PSMaterialConstant>>( gfx,matConst,1u ) );
}
struct Vertex
{
dx::XMFLOAT3 pos;
dx::XMFLOAT3 n;
};
const auto model = Prism::MakeTesselatedIndependentCapNormals<Vertex>( tdist( rng ) );
AddBind( std::make_unique<VertexBuffer>( gfx,model.vertices ) );
AddIndexBuffer( std::make_unique<IndexBuffer>( gfx,model.indices ) );
AddBind( std::make_unique<TransformCbuf>( gfx,*this ) );
}
#pragma once
#include "TestObject.h"
class Cylinder : public TestObject<Cylinder>
{
public:
Cylinder( 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,
std::uniform_real_distribution<float>& bdist,
std::uniform_int_distribution<int>& tdist );
};
\ No newline at end of file
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
#include "IndexBuffer.h" #include "IndexBuffer.h"
#include <cassert> #include <cassert>
void Drawable::Draw( Graphics& gfx ) const noexcept(!IS_DEBUG) using namespace Bind;
void Drawable::Draw( Graphics& gfx ) const noxnd
{ {
for( auto& b : binds ) for( auto& b : binds )
{ {
...@@ -16,13 +18,13 @@ void Drawable::Draw( Graphics& gfx ) const noexcept(!IS_DEBUG) ...@@ -16,13 +18,13 @@ void Drawable::Draw( Graphics& gfx ) const noexcept(!IS_DEBUG)
gfx.DrawIndexed( pIndexBuffer->GetCount() ); gfx.DrawIndexed( pIndexBuffer->GetCount() );
} }
void Drawable::AddBind( std::unique_ptr<Bindable> bind ) noexcept(!IS_DEBUG) void Drawable::AddBind( std::unique_ptr<Bindable> bind ) noxnd
{ {
assert( "*Must* use AddIndexBuffer to bind index buffer" && typeid(*bind) != typeid(IndexBuffer) ); assert( "*Must* use AddIndexBuffer to bind index buffer" && typeid(*bind) != typeid(IndexBuffer) );
binds.push_back( std::move( bind ) ); binds.push_back( std::move( bind ) );
} }
void Drawable::AddIndexBuffer( std::unique_ptr<IndexBuffer> ibuf ) noexcept(!IS_DEBUG) void Drawable::AddIndexBuffer( std::unique_ptr<IndexBuffer> ibuf ) noxnd
{ {
assert( "Attempting to add index buffer a second time" && pIndexBuffer == nullptr ); assert( "Attempting to add index buffer a second time" && pIndexBuffer == nullptr );
pIndexBuffer = ibuf.get(); pIndexBuffer = ibuf.get();
......
#pragma once #pragma once
#include "Graphics.h" #include "Graphics.h"
#include <DirectXMath.h> #include <DirectXMath.h>
#include "ConditionalNoexcept.h"
class Bindable; namespace Bind
{
class Bindable;
class IndexBuffer;
}
class Drawable class Drawable
{ {
...@@ -12,7 +17,7 @@ public: ...@@ -12,7 +17,7 @@ public:
Drawable() = default; Drawable() = default;
Drawable( const Drawable& ) = delete; Drawable( const Drawable& ) = delete;
virtual DirectX::XMMATRIX GetTransformXM() const noexcept = 0; virtual DirectX::XMMATRIX GetTransformXM() const noexcept = 0;
void Draw( Graphics& gfx ) const noexcept(!IS_DEBUG); void Draw( Graphics& gfx ) const noxnd;
virtual void Update( float dt ) noexcept virtual void Update( float dt ) noexcept
{} {}
virtual ~Drawable() = default; virtual ~Drawable() = default;
...@@ -29,11 +34,11 @@ protected: ...@@ -29,11 +34,11 @@ protected:
} }
return nullptr; return nullptr;
} }
void AddBind( std::unique_ptr<Bindable> bind ) noexcept(!IS_DEBUG); void AddBind( std::unique_ptr<Bind::Bindable> bind ) noxnd;
void AddIndexBuffer( std::unique_ptr<class IndexBuffer> ibuf ) noexcept(!IS_DEBUG); void AddIndexBuffer( std::unique_ptr<Bind::IndexBuffer> ibuf ) noxnd;
private: private:
virtual const std::vector<std::unique_ptr<Bindable>>& GetStaticBinds() const noexcept = 0; virtual const std::vector<std::unique_ptr<Bind::Bindable>>& GetStaticBinds() const noexcept = 0;
private: private:
const class IndexBuffer* pIndexBuffer = nullptr; const Bind::IndexBuffer* pIndexBuffer = nullptr;
std::vector<std::unique_ptr<Bindable>> binds; std::vector<std::unique_ptr<Bind::Bindable>> binds;
}; };
\ No newline at end of file
#pragma once #pragma once
#include "Drawable.h" #include "Drawable.h"
#include "IndexBuffer.h" #include "IndexBuffer.h"
#include "ConditionalNoexcept.h"
template<class T> template<class T>
class DrawableBase : public Drawable class DrawableBase : public Drawable
...@@ -10,23 +11,23 @@ protected: ...@@ -10,23 +11,23 @@ protected:
{ {
return !staticBinds.empty(); return !staticBinds.empty();
} }
static void AddStaticBind( std::unique_ptr<Bindable> bind ) noexcept(!IS_DEBUG) static void AddStaticBind( std::unique_ptr<Bind::Bindable> bind ) noxnd
{ {
assert( "*Must* use AddStaticIndexBuffer to bind index buffer" && typeid(*bind) != typeid(IndexBuffer) ); assert( "*Must* use AddStaticIndexBuffer to bind index buffer" && typeid(*bind) != typeid(Bind::IndexBuffer) );
staticBinds.push_back( std::move( bind ) ); staticBinds.push_back( std::move( bind ) );
} }
void AddStaticIndexBuffer( std::unique_ptr<IndexBuffer> ibuf ) noexcept(!IS_DEBUG) void AddStaticIndexBuffer( std::unique_ptr<Bind::IndexBuffer> ibuf ) noxnd
{ {
assert( "Attempting to add index buffer a second time" && pIndexBuffer == nullptr ); assert( "Attempting to add index buffer a second time" && pIndexBuffer == nullptr );
pIndexBuffer = ibuf.get(); pIndexBuffer = ibuf.get();
staticBinds.push_back( std::move( ibuf ) ); staticBinds.push_back( std::move( ibuf ) );
} }
void SetIndexFromStatic() noexcept(!IS_DEBUG) void SetIndexFromStatic() noxnd
{ {
assert( "Attempting to add index buffer a second time" && pIndexBuffer == nullptr ); assert( "Attempting to add index buffer a second time" && pIndexBuffer == nullptr );
for( const auto& b : staticBinds ) for( const auto& b : staticBinds )
{ {
if( const auto p = dynamic_cast<IndexBuffer*>(b.get()) ) if( const auto p = dynamic_cast<Bind::IndexBuffer*>(b.get()) )
{ {
pIndexBuffer = p; pIndexBuffer = p;
return; return;
...@@ -35,13 +36,13 @@ protected: ...@@ -35,13 +36,13 @@ protected:
assert( "Failed to find index buffer in static binds" && pIndexBuffer != nullptr ); assert( "Failed to find index buffer in static binds" && pIndexBuffer != nullptr );
} }
private: private:
const std::vector<std::unique_ptr<Bindable>>& GetStaticBinds() const noexcept override const std::vector<std::unique_ptr<Bind::Bindable>>& GetStaticBinds() const noexcept override
{ {
return staticBinds; return staticBinds;
} }
private: private:
static std::vector<std::unique_ptr<Bindable>> staticBinds; static std::vector<std::unique_ptr<Bind::Bindable>> staticBinds;
}; };
template<class T> template<class T>
std::vector<std::unique_ptr<Bindable>> DrawableBase<T>::staticBinds; std::vector<std::unique_ptr<Bind::Bindable>> DrawableBase<T>::staticBinds;
\ No newline at end of file \ No newline at end of file
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