Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Clark Lin
hw3d
Commits
c87ca0bc
Commit
c87ca0bc
authored
Jul 28, 2019
by
chili
Browse files
better system for bindable codex
parent
939f5af6
Changes
5
Show whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
c87ca0bc
...
...
@@ -18,7 +18,8 @@ App::App()
{
wnd
.
Gfx
().
SetProjection
(
dx
::
XMMatrixPerspectiveLH
(
1.0
f
,
9.0
f
/
16.0
f
,
0.5
f
,
40.0
f
)
);
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
()
...
...
hw3d/BindableCodex.h
View file @
c87ca0bc
...
...
@@ -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
;
...
...
hw3d/Sampler.cpp
View file @
c87ca0bc
#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
hw3d/Sampler.h
View file @
c87ca0bc
...
...
@@ -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
;
};
...
...
hw3d/VertexShader.cpp
View file @
c87ca0bc
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment