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
939f5af6
Commit
939f5af6
authored
Jul 28, 2019
by
chili
Browse files
bindable codex prototype
parent
9cd80da7
Changes
9
Show whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
939f5af6
...
...
@@ -5,6 +5,7 @@
#include "Surface.h"
#include "GDIPlusManager.h"
#include "imgui/imgui.h"
#include "VertexBuffer.h"
namespace
dx
=
DirectX
;
...
...
@@ -16,6 +17,8 @@ App::App()
light
(
wnd
.
Gfx
()
)
{
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"
);
}
void
App
::
DoFrame
()
...
...
hw3d/Bindable.h
View file @
939f5af6
...
...
@@ -8,6 +8,11 @@ namespace Bind
{
public:
virtual
void
Bind
(
Graphics
&
gfx
)
noexcept
=
0
;
virtual
std
::
string
GetUID
()
const
noexcept
{
assert
(
false
);
return
""
;
}
virtual
~
Bindable
()
=
default
;
protected:
static
ID3D11DeviceContext
*
GetContext
(
Graphics
&
gfx
)
noexcept
;
...
...
hw3d/BindableCodex.h
0 → 100644
View file @
939f5af6
#pragma once
#include "Bindable.h"
#include "BindableCodex.h"
#include <memory>
#include <unordered_map>
namespace
Bind
{
class
Codex
{
public:
static
std
::
shared_ptr
<
Bindable
>
Resolve
(
const
std
::
string
&
key
)
noxnd
{
return
Get
().
Resolve_
(
key
);
}
static
void
Store
(
std
::
shared_ptr
<
Bindable
>
bind
)
{
Get
().
Store_
(
std
::
move
(
bind
)
);
}
private:
std
::
shared_ptr
<
Bindable
>
Resolve_
(
const
std
::
string
&
key
)
const
noxnd
{
auto
i
=
binds
.
find
(
key
);
if
(
i
==
binds
.
end
()
)
{
return
{};
}
else
{
return
i
->
second
;
}
}
void
Store_
(
std
::
shared_ptr
<
Bindable
>
bind
)
{
binds
[
bind
->
GetUID
()]
=
std
::
move
(
bind
);
}
static
Codex
&
Get
()
{
static
Codex
codex
;
return
codex
;
}
private:
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
Bindable
>>
binds
;
};
}
\ No newline at end of file
hw3d/Mesh.cpp
View file @
939f5af6
...
...
@@ -289,7 +289,7 @@ std::unique_ptr<Mesh> Model::ParseMesh( Graphics& gfx,const aiMesh& mesh,const a
bindablePtrs
.
push_back
(
std
::
make_shared
<
Bind
::
IndexBuffer
>
(
gfx
,
indices
)
);
auto
pvs
=
std
::
make_shared
<
Bind
::
VertexShader
>
(
gfx
,
L
"PhongVS.cso"
);
auto
pvs
=
std
::
make_shared
<
Bind
::
VertexShader
>
(
gfx
,
"PhongVS.cso"
);
auto
pvsbc
=
pvs
->
GetBytecode
();
bindablePtrs
.
push_back
(
std
::
move
(
pvs
)
);
...
...
hw3d/SolidSphere.cpp
View file @
939f5af6
...
...
@@ -15,7 +15,7 @@ SolidSphere::SolidSphere( Graphics& gfx,float radius )
AddBind
(
std
::
make_shared
<
VertexBuffer
>
(
gfx
,
model
.
vertices
)
);
AddBind
(
std
::
make_shared
<
IndexBuffer
>
(
gfx
,
model
.
indices
)
);
auto
pvs
=
std
::
make_shared
<
VertexShader
>
(
gfx
,
L
"SolidVS.cso"
);
auto
pvs
=
std
::
make_shared
<
VertexShader
>
(
gfx
,
"SolidVS.cso"
);
auto
pvsbc
=
pvs
->
GetBytecode
();
AddBind
(
std
::
move
(
pvs
)
);
...
...
hw3d/VertexShader.cpp
View file @
939f5af6
#include "VertexShader.h"
#include "GraphicsThrowMacros.h"
#include "BindableCodex.h"
#include <typeinfo>
namespace
Bind
{
VertexShader
::
VertexShader
(
Graphics
&
gfx
,
const
std
::
wstring
&
path
)
using
namespace
std
::
string_literals
;
VertexShader
::
VertexShader
(
Graphics
&
gfx
,
const
std
::
string
&
path
)
:
path
(
path
)
{
INFOMAN
(
gfx
);
GFX_THROW_INFO
(
D3DReadFileToBlob
(
path
.
c_str
(),
&
pBytecodeBlob
)
);
GFX_THROW_INFO
(
D3DReadFileToBlob
(
std
::
wstring
{
path
.
begin
(),
path
.
end
()}
.
c_str
(),
&
pBytecodeBlob
)
);
GFX_THROW_INFO
(
GetDevice
(
gfx
)
->
CreateVertexShader
(
pBytecodeBlob
->
GetBufferPointer
(),
pBytecodeBlob
->
GetBufferSize
(),
...
...
@@ -25,4 +31,22 @@ namespace Bind
{
return
pBytecodeBlob
.
Get
();
}
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
;
}
std
::
string
VertexShader
::
GenerateUID
(
const
std
::
string
&
path
)
{
return
typeid
(
VertexShader
).
name
()
+
"#"
s
+
path
;
}
std
::
string
VertexShader
::
GetUID
()
const
noexcept
{
return
GenerateUID
(
path
);
}
}
hw3d/VertexShader.h
View file @
939f5af6
...
...
@@ -6,10 +6,14 @@ namespace Bind
class
VertexShader
:
public
Bindable
{
public:
VertexShader
(
Graphics
&
gfx
,
const
std
::
w
string
&
path
);
VertexShader
(
Graphics
&
gfx
,
const
std
::
string
&
path
);
void
Bind
(
Graphics
&
gfx
)
noexcept
override
;
ID3DBlob
*
GetBytecode
()
const
noexcept
;
static
std
::
shared_ptr
<
Bindable
>
Resolve
(
Graphics
&
gfx
,
const
std
::
string
&
path
);
static
std
::
string
GenerateUID
(
const
std
::
string
&
path
);
std
::
string
GetUID
()
const
noexcept
override
;
protected:
std
::
string
path
;
Microsoft
::
WRL
::
ComPtr
<
ID3DBlob
>
pBytecodeBlob
;
Microsoft
::
WRL
::
ComPtr
<
ID3D11VertexShader
>
pVertexShader
;
};
...
...
hw3d/hw3d.vcxproj
View file @
939f5af6
...
...
@@ -131,6 +131,7 @@
<ItemGroup>
<ClInclude
Include=
"App.h"
/>
<ClInclude
Include=
"Bindable.h"
/>
<ClInclude
Include=
"BindableCodex.h"
/>
<ClInclude
Include=
"BindableCommon.h"
/>
<ClInclude
Include=
"Camera.h"
/>
<ClInclude
Include=
"ChiliException.h"
/>
...
...
hw3d/hw3d.vcxproj.filters
View file @
939f5af6
...
...
@@ -296,6 +296,9 @@
<ClInclude
Include=
"ConditionalNoexcept.h"
>
<Filter>
Header Files\Macros
</Filter>
</ClInclude>
<ClInclude
Include=
"BindableCodex.h"
>
<Filter>
Header Files\Bindable
</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile
Include=
"hw3d.rc"
>
...
...
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