Commit d0fc42ad authored by chili's avatar chili
Browse files

drawables use codex / bindables fixed

parent 3826545c
...@@ -17,9 +17,6 @@ App::App() ...@@ -17,9 +17,6 @@ App::App()
light( wnd.Gfx() ) light( wnd.Gfx() )
{ {
wnd.Gfx().SetProjection( dx::XMMatrixPerspectiveLH( 1.0f,9.0f / 16.0f,0.5f,40.0f ) ); wnd.Gfx().SetProjection( dx::XMMatrixPerspectiveLH( 1.0f,9.0f / 16.0f,0.5f,40.0f ) );
auto a = Bind::VertexShader::Resolve( wnd.Gfx(),"PhongVS.cso" );
auto b = Bind::Sampler::Resolve( wnd.Gfx() );
auto c = Bind::Sampler::Resolve( wnd.Gfx() );
} }
void App::DoFrame() void App::DoFrame()
......
...@@ -72,17 +72,26 @@ namespace Bind ...@@ -72,17 +72,26 @@ namespace Bind
{ {
GetContext( gfx )->VSSetConstantBuffers( slot,1u,pConstantBuffer.GetAddressOf() ); GetContext( gfx )->VSSetConstantBuffers( slot,1u,pConstantBuffer.GetAddressOf() );
} }
static std::shared_ptr<Bindable> Resolve( Graphics& gfx ) static std::shared_ptr<Bindable> Resolve( Graphics& gfx,const C& consts,UINT slot = 0 )
{ {
return Codex::Resolve<VertexConstantBuffer>( gfx ); return Codex::Resolve<VertexConstantBuffer>( gfx,consts,slot );
} }
static std::string GenerateUID() static std::shared_ptr<Bindable> Resolve( Graphics& gfx,UINT slot = 0 )
{ {
return typeid(VertexConstantBuffer).name(); return Codex::Resolve<VertexConstantBuffer>( gfx,slot );
}
static std::string GenerateUID( const C&,UINT slot )
{
return GenerateUID( slot );
}
static std::string GenerateUID( UINT slot = 0 )
{
using namespace std::string_literals;
return typeid(VertexConstantBuffer).name() + "#"s + std::to_string( slot );
} }
std::string GetUID() const noexcept override std::string GetUID() const noexcept override
{ {
return GenerateUID(); return GenerateUID( slot );
} }
}; };
...@@ -98,17 +107,26 @@ namespace Bind ...@@ -98,17 +107,26 @@ namespace Bind
{ {
GetContext( gfx )->PSSetConstantBuffers( slot,1u,pConstantBuffer.GetAddressOf() ); GetContext( gfx )->PSSetConstantBuffers( slot,1u,pConstantBuffer.GetAddressOf() );
} }
std::shared_ptr<Bindable> Resolve( Graphics& gfx ) static std::shared_ptr<Bindable> Resolve( Graphics& gfx,const C& consts,UINT slot = 0 )
{
return Codex::Resolve<PixelConstantBuffer>( gfx,consts,slot );
}
static std::shared_ptr<Bindable> Resolve( Graphics& gfx,UINT slot = 0 )
{
return Codex::Resolve<PixelConstantBuffer>( gfx,slot );
}
static std::string GenerateUID( const C&,UINT slot )
{ {
return Codex::Resolve<PixelConstantBuffer>( gfx ); return GenerateUID( slot );
} }
static std::string GenerateUID() static std::string GenerateUID( UINT slot = 0 )
{ {
return typeid(PixelConstantBuffer).name(); using namespace std::string_literals;
return typeid(PixelConstantBuffer).name() + "#"s + std::to_string( slot );
} }
std::string GetUID() const noexcept override std::string GetUID() const noexcept override
{ {
return GenerateUID(); return GenerateUID( slot );
} }
}; };
} }
\ No newline at end of file
...@@ -229,6 +229,7 @@ Model::~Model() noexcept ...@@ -229,6 +229,7 @@ Model::~Model() noexcept
std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const aiMaterial* const* pMaterials ) std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const aiMaterial* const* pMaterials )
{ {
using Dvtx::VertexLayout; using Dvtx::VertexLayout;
using namespace Bind;
Dvtx::VertexBuffer vbuf( std::move( Dvtx::VertexBuffer vbuf( std::move(
VertexLayout{} VertexLayout{}
...@@ -257,7 +258,10 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a ...@@ -257,7 +258,10 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
indices.push_back( face.mIndices[2] ); indices.push_back( face.mIndices[2] );
} }
std::vector<std::shared_ptr<Bind::Bindable>> bindablePtrs; std::vector<std::shared_ptr<Bindable>> bindablePtrs;
using namespace std::string_literals;
const auto base = "Models\\nano_textured\\"s;
bool hasSpecularMap = false; bool hasSpecularMap = false;
float shininess = 35.0f; float shininess = 35.0f;
...@@ -265,16 +269,14 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a ...@@ -265,16 +269,14 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
{ {
auto& material = *pMaterials[mesh.mMaterialIndex]; auto& material = *pMaterials[mesh.mMaterialIndex];
using namespace std::string_literals;
const auto base = "Models\\nano_textured\\"s;
aiString texFileName; aiString texFileName;
material.GetTexture( aiTextureType_DIFFUSE,0,&texFileName ); material.GetTexture( aiTextureType_DIFFUSE,0,&texFileName );
bindablePtrs.push_back( std::make_shared<Bind::Texture>( gfx,base + texFileName.C_Str() ) ); bindablePtrs.push_back( Texture::Resolve( gfx,base + texFileName.C_Str() ) );
if( material.GetTexture( aiTextureType_SPECULAR,0,&texFileName ) == aiReturn_SUCCESS ) if( material.GetTexture( aiTextureType_SPECULAR,0,&texFileName ) == aiReturn_SUCCESS )
{ {
bindablePtrs.push_back( std::make_shared<Bind::Texture>( gfx,base + texFileName.C_Str(),1 ) ); bindablePtrs.push_back( Texture::Resolve( gfx,base + texFileName.C_Str(),1 ) );
hasSpecularMap = true; hasSpecularMap = true;
} }
else else
...@@ -282,26 +284,28 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a ...@@ -282,26 +284,28 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
material.Get( AI_MATKEY_SHININESS,shininess ); material.Get( AI_MATKEY_SHININESS,shininess );
} }
bindablePtrs.push_back( std::make_shared<Bind::Sampler>( gfx ) ); bindablePtrs.push_back( Bind::Sampler::Resolve( gfx ) );
} }
bindablePtrs.push_back( std::make_shared<Bind::VertexBuffer>( gfx,vbuf ) ); auto meshTag = base + "%" + mesh.mName.C_Str();
bindablePtrs.push_back( VertexBuffer::Resolve( gfx,meshTag,vbuf ) );
bindablePtrs.push_back( std::make_shared<Bind::IndexBuffer>( gfx,indices ) ); bindablePtrs.push_back( IndexBuffer::Resolve( gfx,meshTag,indices ) );
auto pvs = std::make_shared<Bind::VertexShader>( gfx,"PhongVS.cso" ); auto pvs = VertexShader::Resolve( gfx,"PhongVS.cso" );
auto pvsbc = pvs->GetBytecode(); auto pvsbc = static_cast<VertexShader&>(*pvs).GetBytecode();
bindablePtrs.push_back( std::move( pvs ) ); bindablePtrs.push_back( std::move( pvs ) );
bindablePtrs.push_back( std::make_shared<Bind::InputLayout>( gfx,vbuf.GetLayout(),pvsbc ) ); bindablePtrs.push_back( InputLayout::Resolve( gfx,vbuf.GetLayout(),pvsbc ) );
if( hasSpecularMap ) if( hasSpecularMap )
{ {
bindablePtrs.push_back( std::make_shared<Bind::PixelShader>( gfx,"PhongPSSpecMap.cso" ) ); bindablePtrs.push_back( PixelShader::Resolve( gfx,"PhongPSSpecMap.cso" ) );
} }
else else
{ {
bindablePtrs.push_back( std::make_shared<Bind::PixelShader>( gfx,"PhongPS.cso" ) ); bindablePtrs.push_back( PixelShader::Resolve( gfx,"PhongPS.cso" ) );
struct PSMaterialConstant struct PSMaterialConstant
{ {
...@@ -310,7 +314,9 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a ...@@ -310,7 +314,9 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
float padding[2]; float padding[2];
} pmc; } pmc;
pmc.specularPower = shininess; pmc.specularPower = shininess;
bindablePtrs.push_back( std::make_shared<Bind::PixelConstantBuffer<PSMaterialConstant>>( gfx,pmc,1u ) ); // this is CLEARLY an issue... all meshes will share same mat const, but may have different
// Ns (specular power) specified for each in the material properties... bad conflict
bindablePtrs.push_back( PixelConstantBuffer<PSMaterialConstant>::Resolve( gfx,pmc,1u ) );
} }
return std::make_unique<Mesh>( gfx,std::move( bindablePtrs ) ); return std::make_unique<Mesh>( gfx,std::move( bindablePtrs ) );
......
...@@ -12,25 +12,26 @@ SolidSphere::SolidSphere( Graphics& gfx,float radius ) ...@@ -12,25 +12,26 @@ SolidSphere::SolidSphere( Graphics& gfx,float radius )
auto model = Sphere::Make(); auto model = Sphere::Make();
model.Transform( dx::XMMatrixScaling( radius,radius,radius ) ); model.Transform( dx::XMMatrixScaling( radius,radius,radius ) );
AddBind( std::make_shared<VertexBuffer>( gfx,model.vertices ) ); const auto geometryTag = "$sphere." + std::to_string( radius );
AddBind( std::make_shared<IndexBuffer>( gfx,model.indices ) ); AddBind( VertexBuffer::Resolve( gfx,geometryTag,model.vertices ) );
AddBind( IndexBuffer::Resolve( gfx,geometryTag,model.indices ) );
auto pvs = std::make_shared<VertexShader>( gfx,"SolidVS.cso" ); auto pvs = VertexShader::Resolve( gfx,"SolidVS.cso" );
auto pvsbc = pvs->GetBytecode(); auto pvsbc = static_cast<VertexShader&>(*pvs).GetBytecode();
AddBind( std::move( pvs ) ); AddBind( std::move( pvs ) );
AddBind( std::make_shared<PixelShader>( gfx,"SolidPS.cso" ) ); AddBind( PixelShader::Resolve( gfx,"SolidPS.cso" ) );
struct PSColorConstant struct PSColorConstant
{ {
dx::XMFLOAT3 color = { 1.0f,1.0f,1.0f }; dx::XMFLOAT3 color = { 1.0f,1.0f,1.0f };
float padding; float padding;
} colorConst; } colorConst;
AddBind( std::make_shared<PixelConstantBuffer<PSColorConstant>>( gfx,colorConst ) ); AddBind( PixelConstantBuffer<PSColorConstant>::Resolve( gfx,colorConst ) );
AddBind( std::make_shared<InputLayout>( gfx,model.vertices.GetLayout(),pvsbc ) ); AddBind( InputLayout::Resolve( gfx,model.vertices.GetLayout(),pvsbc ) );
AddBind( std::make_shared<Topology>( gfx,D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ) ); AddBind( Topology::Resolve( gfx,D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ) );
AddBind( std::make_shared<TransformCbuf>( gfx,*this ) ); AddBind( std::make_shared<TransformCbuf>( gfx,*this ) );
} }
......
...@@ -10,8 +10,8 @@ namespace Bind ...@@ -10,8 +10,8 @@ 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 ); static std::shared_ptr<Bindable> Resolve( Graphics& gfx,const std::string& path,UINT slot = 0 );
static std::string GenerateUID( const std::string& path,UINT slot ); 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:
unsigned int slot; unsigned int slot;
......
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