Commit c87ca0bc authored by chili's avatar chili
Browse files

better system for bindable codex

parent 939f5af6
......@@ -18,7 +18,8 @@ App::App()
{
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::VertexShader::Resolve( wnd.Gfx(),"PhongVS.cso" );
auto b = Bind::Sampler::Resolve( wnd.Gfx() );
auto c = Bind::Sampler::Resolve( wnd.Gfx() );
}
void App::DoFrame()
......
......@@ -10,31 +10,28 @@ namespace Bind
class Codex
{
public:
static std::shared_ptr<Bindable> Resolve( const std::string& key ) noxnd
template<class T,typename...Params>
static std::shared_ptr<Bindable> Resolve( Graphics& gfx,Params&&...p ) noxnd
{
return Get().Resolve_( key );
}
static void Store( std::shared_ptr<Bindable> bind )
{
Get().Store_( std::move( bind ) );
return Get().Resolve_<T>( gfx,std::forward<Params>( p )... );
}
private:
std::shared_ptr<Bindable> Resolve_( const std::string& key ) const noxnd
template<class T,typename...Params>
std::shared_ptr<Bindable> Resolve_( Graphics& gfx,Params&&...p ) noxnd
{
auto i = binds.find( key );
const auto key = T::GenerateUID( std::forward<Params>( p )... );
const auto i = binds.find( key );
if( i == binds.end() )
{
return {};
auto bind = std::make_shared<T>( gfx,std::forward<Params>( p )... );
binds[key] = bind;
return bind;
}
else
{
return i->second;
}
}
void Store_( std::shared_ptr<Bindable> bind )
{
binds[bind->GetUID()] = std::move( bind );
}
static Codex& Get()
{
static Codex codex;
......
#include "Sampler.h"
#include "GraphicsThrowMacros.h"
#include "BindableCodex.h"
namespace Bind
{
......@@ -20,4 +21,16 @@ namespace Bind
{
GetContext( gfx )->PSSetSamplers( 0,1,pSampler.GetAddressOf() );
}
std::shared_ptr<Bindable> Sampler::Resolve( Graphics& gfx )
{
return Codex::Resolve<Sampler>( gfx );
}
std::string Sampler::GenerateUID()
{
return typeid(Sampler).name();
}
std::string Sampler::GetUID() const noexcept
{
return GenerateUID();
}
}
\ No newline at end of file
......@@ -8,6 +8,9 @@ namespace Bind
public:
Sampler( Graphics& gfx );
void Bind( Graphics& gfx ) noexcept override;
static std::shared_ptr<Bindable> Resolve( Graphics& gfx );
static std::string GenerateUID();
std::string GetUID() const noexcept override;
protected:
Microsoft::WRL::ComPtr<ID3D11SamplerState> pSampler;
};
......
......@@ -5,8 +5,6 @@
namespace Bind
{
using namespace std::string_literals;
VertexShader::VertexShader( Graphics& gfx,const std::string& path )
:
path( path )
......@@ -33,16 +31,11 @@ namespace Bind
}
std::shared_ptr<Bindable> VertexShader::Resolve( Graphics& gfx,const std::string& path )
{
auto bind = Codex::Resolve( GenerateUID( path ) );
if( !bind )
{
bind = std::make_shared<VertexShader>( gfx,path );
Codex::Store( bind );
}
return bind;
return Codex::Resolve<VertexShader>( gfx,path );
}
std::string VertexShader::GenerateUID( const std::string& path )
{
using namespace std::string_literals;
return typeid(VertexShader).name() + "#"s + path;
}
std::string VertexShader::GetUID() const noexcept
......
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