Commit 37464aa1 authored by chili's avatar chili
Browse files

resolve returns actual type

parent d0fc42ad
...@@ -12,14 +12,14 @@ namespace Bind ...@@ -12,14 +12,14 @@ namespace Bind
{ {
public: public:
template<class T,typename...Params> template<class T,typename...Params>
static std::shared_ptr<Bindable> Resolve( Graphics& gfx,Params&&...p ) noxnd static std::shared_ptr<T> Resolve( Graphics& gfx,Params&&...p ) noxnd
{ {
static_assert( std::is_base_of<Bindable,T>::value,"Can only resolve classes derived from Bindable" ); static_assert( std::is_base_of<Bindable,T>::value,"Can only resolve classes derived from Bindable" );
return Get().Resolve_<T>( gfx,std::forward<Params>( p )... ); return Get().Resolve_<T>( gfx,std::forward<Params>( p )... );
} }
private: private:
template<class T,typename...Params> template<class T,typename...Params>
std::shared_ptr<Bindable> Resolve_( Graphics& gfx,Params&&...p ) noxnd std::shared_ptr<T> Resolve_( Graphics& gfx,Params&&...p ) noxnd
{ {
const auto key = T::GenerateUID( std::forward<Params>( p )... ); const auto key = T::GenerateUID( std::forward<Params>( p )... );
const auto i = binds.find( key ); const auto i = binds.find( key );
...@@ -31,7 +31,7 @@ namespace Bind ...@@ -31,7 +31,7 @@ namespace Bind
} }
else else
{ {
return i->second; return std::static_pointer_cast<T>( i->second );
} }
} }
static Codex& Get() static Codex& Get()
......
...@@ -72,11 +72,11 @@ namespace Bind ...@@ -72,11 +72,11 @@ namespace Bind
{ {
GetContext( gfx )->VSSetConstantBuffers( slot,1u,pConstantBuffer.GetAddressOf() ); GetContext( gfx )->VSSetConstantBuffers( slot,1u,pConstantBuffer.GetAddressOf() );
} }
static std::shared_ptr<Bindable> Resolve( Graphics& gfx,const C& consts,UINT slot = 0 ) static std::shared_ptr<VertexConstantBuffer> Resolve( Graphics& gfx,const C& consts,UINT slot = 0 )
{ {
return Codex::Resolve<VertexConstantBuffer>( gfx,consts,slot ); return Codex::Resolve<VertexConstantBuffer>( gfx,consts,slot );
} }
static std::shared_ptr<Bindable> Resolve( Graphics& gfx,UINT slot = 0 ) static std::shared_ptr<VertexConstantBuffer> Resolve( Graphics& gfx,UINT slot = 0 )
{ {
return Codex::Resolve<VertexConstantBuffer>( gfx,slot ); return Codex::Resolve<VertexConstantBuffer>( gfx,slot );
} }
...@@ -107,11 +107,11 @@ namespace Bind ...@@ -107,11 +107,11 @@ namespace Bind
{ {
GetContext( gfx )->PSSetConstantBuffers( slot,1u,pConstantBuffer.GetAddressOf() ); GetContext( gfx )->PSSetConstantBuffers( slot,1u,pConstantBuffer.GetAddressOf() );
} }
static std::shared_ptr<Bindable> Resolve( Graphics& gfx,const C& consts,UINT slot = 0 ) static std::shared_ptr<PixelConstantBuffer> Resolve( Graphics& gfx,const C& consts,UINT slot = 0 )
{ {
return Codex::Resolve<PixelConstantBuffer>( gfx,consts,slot ); return Codex::Resolve<PixelConstantBuffer>( gfx,consts,slot );
} }
static std::shared_ptr<Bindable> Resolve( Graphics& gfx,UINT slot = 0 ) static std::shared_ptr<PixelConstantBuffer> Resolve( Graphics& gfx,UINT slot = 0 )
{ {
return Codex::Resolve<PixelConstantBuffer>( gfx,slot ); return Codex::Resolve<PixelConstantBuffer>( gfx,slot );
} }
......
...@@ -36,7 +36,7 @@ namespace Bind ...@@ -36,7 +36,7 @@ namespace Bind
{ {
return count; return count;
} }
std::shared_ptr<Bindable> IndexBuffer::Resolve( Graphics& gfx,const std::string& tag, std::shared_ptr<IndexBuffer> IndexBuffer::Resolve( Graphics& gfx,const std::string& tag,
const std::vector<unsigned short>& indices ) const std::vector<unsigned short>& indices )
{ {
return Codex::Resolve<IndexBuffer>( gfx,tag,indices ); return Codex::Resolve<IndexBuffer>( gfx,tag,indices );
......
...@@ -10,7 +10,7 @@ namespace Bind ...@@ -10,7 +10,7 @@ namespace Bind
IndexBuffer( Graphics& gfx,std::string tag,const std::vector<unsigned short>& indices ); IndexBuffer( Graphics& gfx,std::string tag,const std::vector<unsigned short>& indices );
void Bind( Graphics& gfx ) noexcept override; void Bind( Graphics& gfx ) noexcept override;
UINT GetCount() const noexcept; UINT GetCount() const noexcept;
static std::shared_ptr<Bindable> Resolve( Graphics& gfx,const std::string& tag, static std::shared_ptr<IndexBuffer> Resolve( Graphics& gfx,const std::string& tag,
const std::vector<unsigned short>& indices ); const std::vector<unsigned short>& indices );
template<typename...Ignore> template<typename...Ignore>
static std::string GenerateUID( const std::string& tag,Ignore&&...ignore ) static std::string GenerateUID( const std::string& tag,Ignore&&...ignore )
......
...@@ -27,7 +27,7 @@ namespace Bind ...@@ -27,7 +27,7 @@ namespace Bind
{ {
GetContext( gfx )->IASetInputLayout( pInputLayout.Get() ); GetContext( gfx )->IASetInputLayout( pInputLayout.Get() );
} }
std::shared_ptr<Bindable> InputLayout::Resolve( Graphics& gfx, std::shared_ptr<InputLayout> InputLayout::Resolve( Graphics& gfx,
const Dvtx::VertexLayout& layout,ID3DBlob* pVertexShaderBytecode ) const Dvtx::VertexLayout& layout,ID3DBlob* pVertexShaderBytecode )
{ {
return Codex::Resolve<InputLayout>( gfx,layout,pVertexShaderBytecode ); return Codex::Resolve<InputLayout>( gfx,layout,pVertexShaderBytecode );
......
...@@ -11,7 +11,7 @@ namespace Bind ...@@ -11,7 +11,7 @@ namespace Bind
Dvtx::VertexLayout layout, Dvtx::VertexLayout layout,
ID3DBlob* pVertexShaderBytecode ); ID3DBlob* pVertexShaderBytecode );
void Bind( Graphics& gfx ) noexcept override; void Bind( Graphics& gfx ) noexcept override;
static std::shared_ptr<Bindable> Resolve( Graphics& gfx, static std::shared_ptr<InputLayout> Resolve( Graphics& gfx,
const Dvtx::VertexLayout& layout,ID3DBlob* pVertexShaderBytecode ); const Dvtx::VertexLayout& layout,ID3DBlob* pVertexShaderBytecode );
static std::string GenerateUID( const Dvtx::VertexLayout& layout,ID3DBlob* pVertexShaderBytecode = nullptr ); static std::string GenerateUID( const Dvtx::VertexLayout& layout,ID3DBlob* pVertexShaderBytecode = nullptr );
std::string GetUID() const noexcept override; std::string GetUID() const noexcept override;
......
...@@ -294,7 +294,7 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a ...@@ -294,7 +294,7 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
bindablePtrs.push_back( IndexBuffer::Resolve( gfx,meshTag,indices ) ); bindablePtrs.push_back( IndexBuffer::Resolve( gfx,meshTag,indices ) );
auto pvs = VertexShader::Resolve( gfx,"PhongVS.cso" ); auto pvs = VertexShader::Resolve( gfx,"PhongVS.cso" );
auto pvsbc = static_cast<VertexShader&>(*pvs).GetBytecode(); auto pvsbc = pvs->GetBytecode();
bindablePtrs.push_back( std::move( pvs ) ); bindablePtrs.push_back( std::move( pvs ) );
bindablePtrs.push_back( InputLayout::Resolve( gfx,vbuf.GetLayout(),pvsbc ) ); bindablePtrs.push_back( InputLayout::Resolve( gfx,vbuf.GetLayout(),pvsbc ) );
......
...@@ -19,7 +19,7 @@ namespace Bind ...@@ -19,7 +19,7 @@ namespace Bind
{ {
GetContext( gfx )->PSSetShader( pPixelShader.Get(),nullptr,0u ); GetContext( gfx )->PSSetShader( pPixelShader.Get(),nullptr,0u );
} }
std::shared_ptr<Bindable> PixelShader::Resolve( Graphics& gfx,const std::string& path ) std::shared_ptr<PixelShader> PixelShader::Resolve( Graphics& gfx,const std::string& path )
{ {
return Codex::Resolve<PixelShader>( gfx,path ); return Codex::Resolve<PixelShader>( gfx,path );
} }
......
...@@ -8,7 +8,7 @@ namespace Bind ...@@ -8,7 +8,7 @@ namespace Bind
public: public:
PixelShader( Graphics& gfx,const std::string& path ); PixelShader( Graphics& gfx,const std::string& path );
void Bind( Graphics& gfx ) noexcept override; void Bind( Graphics& gfx ) noexcept override;
static std::shared_ptr<Bindable> Resolve( Graphics& gfx,const std::string& path ); static std::shared_ptr<PixelShader> Resolve( Graphics& gfx,const std::string& path );
static std::string GenerateUID( const std::string& path ); static std::string GenerateUID( const std::string& path );
std::string GetUID() const noexcept override; std::string GetUID() const noexcept override;
protected: protected:
......
...@@ -21,7 +21,7 @@ namespace Bind ...@@ -21,7 +21,7 @@ namespace Bind
{ {
GetContext( gfx )->PSSetSamplers( 0,1,pSampler.GetAddressOf() ); GetContext( gfx )->PSSetSamplers( 0,1,pSampler.GetAddressOf() );
} }
std::shared_ptr<Bindable> Sampler::Resolve( Graphics& gfx ) std::shared_ptr<Sampler> Sampler::Resolve( Graphics& gfx )
{ {
return Codex::Resolve<Sampler>( gfx ); return Codex::Resolve<Sampler>( gfx );
} }
......
...@@ -8,7 +8,7 @@ namespace Bind ...@@ -8,7 +8,7 @@ namespace Bind
public: public:
Sampler( Graphics& gfx ); Sampler( Graphics& gfx );
void Bind( Graphics& gfx ) noexcept override; void Bind( Graphics& gfx ) noexcept override;
static std::shared_ptr<Bindable> Resolve( Graphics& gfx ); static std::shared_ptr<Sampler> Resolve( Graphics& gfx );
static std::string GenerateUID(); static std::string GenerateUID();
std::string GetUID() const noexcept override; std::string GetUID() const noexcept override;
protected: protected:
......
...@@ -17,7 +17,7 @@ SolidSphere::SolidSphere( Graphics& gfx,float radius ) ...@@ -17,7 +17,7 @@ SolidSphere::SolidSphere( Graphics& gfx,float radius )
AddBind( IndexBuffer::Resolve( gfx,geometryTag,model.indices ) ); AddBind( IndexBuffer::Resolve( gfx,geometryTag,model.indices ) );
auto pvs = VertexShader::Resolve( gfx,"SolidVS.cso" ); auto pvs = VertexShader::Resolve( gfx,"SolidVS.cso" );
auto pvsbc = static_cast<VertexShader&>(*pvs).GetBytecode(); auto pvsbc = pvs->GetBytecode();
AddBind( std::move( pvs ) ); AddBind( std::move( pvs ) );
AddBind( PixelShader::Resolve( gfx,"SolidPS.cso" ) ); AddBind( PixelShader::Resolve( gfx,"SolidPS.cso" ) );
......
...@@ -53,7 +53,7 @@ namespace Bind ...@@ -53,7 +53,7 @@ namespace Bind
{ {
GetContext( gfx )->PSSetShaderResources( slot,1u,pTextureView.GetAddressOf() ); GetContext( gfx )->PSSetShaderResources( slot,1u,pTextureView.GetAddressOf() );
} }
std::shared_ptr<Bindable> Texture::Resolve( Graphics& gfx,const std::string& path,UINT slot ) std::shared_ptr<Texture> Texture::Resolve( Graphics& gfx,const std::string& path,UINT slot )
{ {
return Codex::Resolve<Texture>( gfx,path,slot ); return Codex::Resolve<Texture>( gfx,path,slot );
} }
......
...@@ -10,7 +10,7 @@ namespace Bind ...@@ -10,7 +10,7 @@ namespace Bind
public: public:
Texture( Graphics& gfx,const std::string& path,UINT slot = 0 ); Texture( Graphics& gfx,const std::string& path,UINT slot = 0 );
void Bind( Graphics& gfx ) noexcept override; void Bind( Graphics& gfx ) noexcept override;
static std::shared_ptr<Bindable> Resolve( Graphics& gfx,const std::string& path,UINT slot = 0 ); static std::shared_ptr<Texture> Resolve( Graphics& gfx,const std::string& path,UINT slot = 0 );
static std::string GenerateUID( const std::string& path,UINT slot = 0 ); static std::string GenerateUID( const std::string& path,UINT slot = 0 );
std::string GetUID() const noexcept override; std::string GetUID() const noexcept override;
private: private:
......
...@@ -12,7 +12,7 @@ namespace Bind ...@@ -12,7 +12,7 @@ namespace Bind
{ {
GetContext( gfx )->IASetPrimitiveTopology( type ); GetContext( gfx )->IASetPrimitiveTopology( type );
} }
std::shared_ptr<Bindable> Topology::Resolve( Graphics& gfx,D3D11_PRIMITIVE_TOPOLOGY type ) std::shared_ptr<Topology> Topology::Resolve( Graphics& gfx,D3D11_PRIMITIVE_TOPOLOGY type )
{ {
return Codex::Resolve<Topology>( gfx,type ); return Codex::Resolve<Topology>( gfx,type );
} }
......
...@@ -8,7 +8,7 @@ namespace Bind ...@@ -8,7 +8,7 @@ namespace Bind
public: public:
Topology( Graphics& gfx,D3D11_PRIMITIVE_TOPOLOGY type ); Topology( Graphics& gfx,D3D11_PRIMITIVE_TOPOLOGY type );
void Bind( Graphics& gfx ) noexcept override; void Bind( Graphics& gfx ) noexcept override;
static std::shared_ptr<Bindable> Resolve( Graphics& gfx,D3D11_PRIMITIVE_TOPOLOGY type ); static std::shared_ptr<Topology> Resolve( Graphics& gfx,D3D11_PRIMITIVE_TOPOLOGY type );
static std::string GenerateUID( D3D11_PRIMITIVE_TOPOLOGY type ); static std::string GenerateUID( D3D11_PRIMITIVE_TOPOLOGY type );
std::string GetUID() const noexcept override; std::string GetUID() const noexcept override;
protected: protected:
......
...@@ -31,7 +31,7 @@ namespace Bind ...@@ -31,7 +31,7 @@ namespace Bind
const UINT offset = 0u; const UINT offset = 0u;
GetContext( gfx )->IASetVertexBuffers( 0u,1u,pVertexBuffer.GetAddressOf(),&stride,&offset ); GetContext( gfx )->IASetVertexBuffers( 0u,1u,pVertexBuffer.GetAddressOf(),&stride,&offset );
} }
std::shared_ptr<Bindable> VertexBuffer::Resolve( Graphics& gfx,const std::string& tag, std::shared_ptr<VertexBuffer> VertexBuffer::Resolve( Graphics& gfx,const std::string& tag,
const Dvtx::VertexBuffer& vbuf ) const Dvtx::VertexBuffer& vbuf )
{ {
return Codex::Resolve<VertexBuffer>( gfx,tag,vbuf ); return Codex::Resolve<VertexBuffer>( gfx,tag,vbuf );
......
...@@ -11,7 +11,7 @@ namespace Bind ...@@ -11,7 +11,7 @@ namespace Bind
VertexBuffer( Graphics& gfx,const std::string& tag,const Dvtx::VertexBuffer& vbuf ); VertexBuffer( Graphics& gfx,const std::string& tag,const Dvtx::VertexBuffer& vbuf );
VertexBuffer( Graphics& gfx,const Dvtx::VertexBuffer& vbuf ); VertexBuffer( Graphics& gfx,const Dvtx::VertexBuffer& vbuf );
void Bind( Graphics& gfx ) noexcept override; void Bind( Graphics& gfx ) noexcept override;
static std::shared_ptr<Bindable> Resolve( Graphics& gfx,const std::string& tag, static std::shared_ptr<VertexBuffer> Resolve( Graphics& gfx,const std::string& tag,
const Dvtx::VertexBuffer& vbuf ); const Dvtx::VertexBuffer& vbuf );
template<typename...Ignore> template<typename...Ignore>
static std::string GenerateUID( const std::string& tag,Ignore&&...ignore ) static std::string GenerateUID( const std::string& tag,Ignore&&...ignore )
......
...@@ -29,7 +29,7 @@ namespace Bind ...@@ -29,7 +29,7 @@ namespace Bind
{ {
return pBytecodeBlob.Get(); return pBytecodeBlob.Get();
} }
std::shared_ptr<Bindable> VertexShader::Resolve( Graphics& gfx,const std::string& path ) std::shared_ptr<VertexShader> VertexShader::Resolve( Graphics& gfx,const std::string& path )
{ {
return Codex::Resolve<VertexShader>( gfx,path ); return Codex::Resolve<VertexShader>( gfx,path );
} }
......
...@@ -9,7 +9,7 @@ namespace Bind ...@@ -9,7 +9,7 @@ namespace Bind
VertexShader( Graphics& gfx,const std::string& path ); VertexShader( Graphics& gfx,const std::string& path );
void Bind( Graphics& gfx ) noexcept override; void Bind( Graphics& gfx ) noexcept override;
ID3DBlob* GetBytecode() const noexcept; ID3DBlob* GetBytecode() const noexcept;
static std::shared_ptr<Bindable> Resolve( Graphics& gfx,const std::string& path ); static std::shared_ptr<VertexShader> Resolve( Graphics& gfx,const std::string& path );
static std::string GenerateUID( const std::string& path ); static std::string GenerateUID( const std::string& path );
std::string GetUID() const noexcept override; std::string GetUID() const noexcept override;
protected: protected:
......
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