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
Compare Revisions
62837c09da69cd247cb49a55ccecf8746ada7010...2526ae6c195eafa6f55c68e00217b2874c43354c
Hide whitespace changes
Inline
Side-by-side
hw3d/PhongVS.hlsl
View file @
2526ae6c
cbuffer
CBuf
{
matrix
modelView
;
matrix
modelViewProj
;
matrix
modelView
;
matrix
modelViewProj
;
};
struct
VSOut
{
float3
worldPos
:
Position
;
float3
normal
:
Normal
;
float4
pos
:
SV_Position
;
float3
worldPos
:
Position
;
float3
normal
:
Normal
;
float2
tc
:
Texcoord
;
float4
pos
:
SV_Position
;
};
VSOut
main
(
float3
pos
:
Position
,
float3
n
:
Normal
)
VSOut
main
(
float3
pos
:
Position
,
float3
n
:
Normal
,
float2
tc
:
Texcoord
)
{
VSOut
vso
;
vso
.
worldPos
=
(
float3
)
mul
(
float4
(
pos
,
1
.
0
f
),
modelView
);
vso
.
normal
=
mul
(
n
,(
float3x3
)
modelView
);
vso
.
pos
=
mul
(
float4
(
pos
,
1
.
0
f
),
modelViewProj
);
return
vso
;
VSOut
vso
;
vso
.
worldPos
=
(
float3
)
mul
(
float4
(
pos
,
1
.
0
f
),
modelView
);
vso
.
normal
=
mul
(
n
,
(
float3x3
)
modelView
);
vso
.
pos
=
mul
(
float4
(
pos
,
1
.
0
f
),
modelViewProj
);
vso
.
tc
=
tc
;
return
vso
;
}
\ No newline at end of file
hw3d/PixelShader.cpp
View file @
2526ae6c
#include "PixelShader.h"
#include "GraphicsThrowMacros.h"
#include "BindableCodex.h"
namespace
Bind
{
PixelShader
::
PixelShader
(
Graphics
&
gfx
,
const
std
::
wstring
&
path
)
PixelShader
::
PixelShader
(
Graphics
&
gfx
,
const
std
::
string
&
path
)
:
path
(
path
)
{
INFOMAN
(
gfx
);
Microsoft
::
WRL
::
ComPtr
<
ID3DBlob
>
pBlob
;
GFX_THROW_INFO
(
D3DReadFileToBlob
(
path
.
c_str
(),
&
pBlob
)
);
GFX_THROW_INFO
(
D3DReadFileToBlob
(
std
::
wstring
{
path
.
begin
(),
path
.
end
()}
.
c_str
(),
&
pBlob
)
);
GFX_THROW_INFO
(
GetDevice
(
gfx
)
->
CreatePixelShader
(
pBlob
->
GetBufferPointer
(),
pBlob
->
GetBufferSize
(),
nullptr
,
&
pPixelShader
)
);
}
...
...
@@ -16,4 +19,17 @@ namespace Bind
{
GetContext
(
gfx
)
->
PSSetShader
(
pPixelShader
.
Get
(),
nullptr
,
0u
);
}
std
::
shared_ptr
<
PixelShader
>
PixelShader
::
Resolve
(
Graphics
&
gfx
,
const
std
::
string
&
path
)
{
return
Codex
::
Resolve
<
PixelShader
>
(
gfx
,
path
);
}
std
::
string
PixelShader
::
GenerateUID
(
const
std
::
string
&
path
)
{
using
namespace
std
::
string_literals
;
return
typeid
(
PixelShader
).
name
()
+
"#"
s
+
path
;
}
std
::
string
PixelShader
::
GetUID
()
const
noexcept
{
return
GenerateUID
(
path
);
}
}
hw3d/PixelShader.h
View file @
2526ae6c
...
...
@@ -6,9 +6,13 @@ namespace Bind
class
PixelShader
:
public
Bindable
{
public:
PixelShader
(
Graphics
&
gfx
,
const
std
::
w
string
&
path
);
PixelShader
(
Graphics
&
gfx
,
const
std
::
string
&
path
);
void
Bind
(
Graphics
&
gfx
)
noexcept
override
;
static
std
::
shared_ptr
<
PixelShader
>
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
<
ID3D11PixelShader
>
pPixelShader
;
};
}
\ No newline at end of file
hw3d/Sampler.cpp
View file @
2526ae6c
#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
<
Sampler
>
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 @
2526ae6c
...
...
@@ -8,6 +8,9 @@ namespace Bind
public:
Sampler
(
Graphics
&
gfx
);
void
Bind
(
Graphics
&
gfx
)
noexcept
override
;
static
std
::
shared_ptr
<
Sampler
>
Resolve
(
Graphics
&
gfx
);
static
std
::
string
GenerateUID
();
std
::
string
GetUID
()
const
noexcept
override
;
protected:
Microsoft
::
WRL
::
ComPtr
<
ID3D11SamplerState
>
pSampler
;
};
...
...
hw3d/SolidSphere.cpp
View file @
2526ae6c
#include "SolidSphere.h"
#include "BindableCommon.h"
#include "GraphicsThrowMacros.h"
#include "Vertex.h"
#include "Sphere.h"
...
...
@@ -8,48 +9,32 @@ SolidSphere::SolidSphere( Graphics& gfx,float radius )
{
using
namespace
Bind
;
namespace
dx
=
DirectX
;
auto
model
=
Sphere
::
Make
();
model
.
Transform
(
dx
::
XMMatrixScaling
(
radius
,
radius
,
radius
)
);
const
auto
geometryTag
=
"$sphere."
+
std
::
to_string
(
radius
);
AddBind
(
VertexBuffer
::
Resolve
(
gfx
,
geometryTag
,
model
.
vertices
)
);
AddBind
(
IndexBuffer
::
Resolve
(
gfx
,
geometryTag
,
model
.
indices
)
);
if
(
!
IsStaticInitialized
()
)
{
struct
Vertex
{
dx
::
XMFLOAT3
pos
;
};
auto
model
=
Sphere
::
Make
<
Vertex
>
();
model
.
Transform
(
dx
::
XMMatrixScaling
(
radius
,
radius
,
radius
)
);
AddBind
(
std
::
make_unique
<
VertexBuffer
>
(
gfx
,
model
.
vertices
)
);
AddIndexBuffer
(
std
::
make_unique
<
IndexBuffer
>
(
gfx
,
model
.
indices
)
);
auto
pvs
=
std
::
make_unique
<
VertexShader
>
(
gfx
,
L"SolidVS.cso"
);
auto
pvsbc
=
pvs
->
GetBytecode
();
AddStaticBind
(
std
::
move
(
pvs
)
);
AddStaticBind
(
std
::
make_unique
<
PixelShader
>
(
gfx
,
L"SolidPS.cso"
)
);
struct
PSColorConstant
{
dx
::
XMFLOAT3
color
=
{
1.0
f
,
1.0
f
,
1.0
f
};
float
padding
;
}
colorConst
;
AddStaticBind
(
std
::
make_unique
<
PixelConstantBuffer
<
PSColorConstant
>>
(
gfx
,
colorConst
)
);
const
std
::
vector
<
D3D11_INPUT_ELEMENT_DESC
>
ied
=
{
{
"Position"
,
0
,
DXGI_FORMAT_R32G32B32_FLOAT
,
0
,
0
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
};
AddStaticBind
(
std
::
make_unique
<
InputLayout
>
(
gfx
,
ied
,
pvsbc
)
);
AddStaticBind
(
std
::
make_unique
<
Topology
>
(
gfx
,
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST
)
);
}
else
auto
pvs
=
VertexShader
::
Resolve
(
gfx
,
"SolidVS.cso"
);
auto
pvsbc
=
pvs
->
GetBytecode
();
AddBind
(
std
::
move
(
pvs
)
);
AddBind
(
PixelShader
::
Resolve
(
gfx
,
"SolidPS.cso"
)
);
struct
PSColorConstant
{
SetIndexFromStatic
();
}
dx
::
XMFLOAT3
color
=
{
1.0
f
,
1.0
f
,
1.0
f
};
float
padding
;
}
colorConst
;
AddBind
(
PixelConstantBuffer
<
PSColorConstant
>::
Resolve
(
gfx
,
colorConst
)
);
AddBind
(
std
::
make_unique
<
TransformCbuf
>
(
gfx
,
*
this
)
);
}
AddBind
(
InputLayout
::
Resolve
(
gfx
,
model
.
vertices
.
GetLayout
(),
pvsbc
)
);
AddBind
(
Topology
::
Resolve
(
gfx
,
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST
)
);
void
SolidSphere
::
Update
(
float
dt
)
noexcept
{}
AddBind
(
std
::
make_shared
<
TransformCbuf
>
(
gfx
,
*
this
)
);
}
void
SolidSphere
::
SetPos
(
DirectX
::
XMFLOAT3
pos
)
noexcept
{
...
...
hw3d/SolidSphere.h
View file @
2526ae6c
#pragma once
#include "Drawable
Base
.h"
#include "Drawable.h"
class
SolidSphere
:
public
Drawable
Base
<
SolidSphere
>
class
SolidSphere
:
public
Drawable
{
public:
SolidSphere
(
Graphics
&
gfx
,
float
radius
);
void
Update
(
float
dt
)
noexcept
override
;
void
SetPos
(
DirectX
::
XMFLOAT3
pos
)
noexcept
;
DirectX
::
XMMATRIX
GetTransformXM
()
const
noexcept
override
;
private:
...
...
hw3d/Sphere.h
View file @
2526ae6c
#pragma once
#include <optional>
#include "Vertex.h"
#include "IndexedTriangleList.h"
#include <DirectXMath.h>
#include "ChiliMath.h"
...
...
@@ -6,8 +8,7 @@
class
Sphere
{
public:
template
<
class
V
>
static
IndexedTriangleList
<
V
>
MakeTesselated
(
int
latDiv
,
int
longDiv
)
static
IndexedTriangleList
MakeTesselated
(
Dvtx
::
VertexLayout
layout
,
int
latDiv
,
int
longDiv
)
{
namespace
dx
=
DirectX
;
assert
(
latDiv
>=
3
);
...
...
@@ -18,7 +19,7 @@ public:
const
float
lattitudeAngle
=
PI
/
latDiv
;
const
float
longitudeAngle
=
2.0
f
*
PI
/
longDiv
;
std
::
vector
<
V
>
vertices
;
Dvtx
::
VertexBuffer
vb
{
std
::
move
(
layout
)
}
;
for
(
int
iLat
=
1
;
iLat
<
latDiv
;
iLat
++
)
{
const
auto
latBase
=
dx
::
XMVector3Transform
(
...
...
@@ -27,22 +28,29 @@ public:
);
for
(
int
iLong
=
0
;
iLong
<
longDiv
;
iLong
++
)
{
vertices
.
emplace_back
()
;
dx
::
XMFLOAT3
calculatedPos
;
auto
v
=
dx
::
XMVector3Transform
(
latBase
,
dx
::
XMMatrixRotationZ
(
longitudeAngle
*
iLong
)
);
dx
::
XMStoreFloat3
(
&
vertices
.
back
().
pos
,
v
);
dx
::
XMStoreFloat3
(
&
calculatedPos
,
v
);
vb
.
EmplaceBack
(
calculatedPos
);
}
}
// add the cap vertices
const
auto
iNorthPole
=
(
unsigned
short
)
vertices
.
size
();
vertices
.
emplace_back
();
dx
::
XMStoreFloat3
(
&
vertices
.
back
().
pos
,
base
);
const
auto
iSouthPole
=
(
unsigned
short
)
vertices
.
size
();
vertices
.
emplace_back
();
dx
::
XMStoreFloat3
(
&
vertices
.
back
().
pos
,
dx
::
XMVectorNegate
(
base
)
);
const
auto
iNorthPole
=
(
unsigned
short
)
vb
.
Size
();
{
dx
::
XMFLOAT3
northPos
;
dx
::
XMStoreFloat3
(
&
northPos
,
base
);
vb
.
EmplaceBack
(
northPos
);
}
const
auto
iSouthPole
=
(
unsigned
short
)
vb
.
Size
();
{
dx
::
XMFLOAT3
southPos
;
dx
::
XMStoreFloat3
(
&
southPos
,
dx
::
XMVectorNegate
(
base
)
);
vb
.
EmplaceBack
(
southPos
);
}
const
auto
calcIdx
=
[
latDiv
,
longDiv
](
unsigned
short
iLat
,
unsigned
short
iLong
)
{
return
iLat
*
longDiv
+
iLong
;
};
...
...
@@ -89,11 +97,15 @@ public:
indices
.
push_back
(
calcIdx
(
latDiv
-
2
,
longDiv
-
1
)
);
indices
.
push_back
(
iSouthPole
);
return
{
std
::
move
(
v
ertices
),
std
::
move
(
indices
)
};
return
{
std
::
move
(
v
b
),
std
::
move
(
indices
)
};
}
template
<
class
V
>
static
IndexedTriangleList
<
V
>
Make
()
static
IndexedTriangleList
Make
(
std
::
optional
<
Dvtx
::
VertexLayout
>
layout
=
std
::
nullopt
)
{
return
MakeTesselated
<
V
>
(
12
,
24
);
using
Element
=
Dvtx
::
VertexLayout
::
ElementType
;
if
(
!
layout
)
{
layout
=
Dvtx
::
VertexLayout
{}.
Append
(
Element
::
Position3D
);
}
return
MakeTesselated
(
std
::
move
(
*
layout
),
12
,
24
);
}
};
\ No newline at end of file
hw3d/Texture.cpp
View file @
2526ae6c
#include "Texture.h"
#include "Surface.h"
#include "GraphicsThrowMacros.h"
#include "BindableCodex.h"
namespace
Bind
{
namespace
wrl
=
Microsoft
::
WRL
;
Texture
::
Texture
(
Graphics
&
gfx
,
const
Surface
&
s
)
Texture
::
Texture
(
Graphics
&
gfx
,
const
std
::
string
&
path
,
UINT
slot
)
:
path
(
path
),
slot
(
slot
)
{
INFOMAN
(
gfx
);
// load surface
const
auto
s
=
Surface
::
FromFile
(
path
);
// create texture resource
D3D11_TEXTURE2D_DESC
textureDesc
=
{};
textureDesc
.
Width
=
s
.
GetWidth
();
...
...
@@ -44,6 +51,19 @@ namespace Bind
void
Texture
::
Bind
(
Graphics
&
gfx
)
noexcept
{
GetContext
(
gfx
)
->
PSSetShaderResources
(
0u
,
1u
,
pTextureView
.
GetAddressOf
()
);
GetContext
(
gfx
)
->
PSSetShaderResources
(
slot
,
1u
,
pTextureView
.
GetAddressOf
()
);
}
std
::
shared_ptr
<
Texture
>
Texture
::
Resolve
(
Graphics
&
gfx
,
const
std
::
string
&
path
,
UINT
slot
)
{
return
Codex
::
Resolve
<
Texture
>
(
gfx
,
path
,
slot
);
}
std
::
string
Texture
::
GenerateUID
(
const
std
::
string
&
path
,
UINT
slot
)
{
using
namespace
std
::
string_literals
;
return
typeid
(
Texture
).
name
()
+
"#"
s
+
path
+
"#"
+
std
::
to_string
(
slot
);
}
std
::
string
Texture
::
GetUID
()
const
noexcept
{
return
GenerateUID
(
path
,
slot
);
}
}
hw3d/Texture.h
View file @
2526ae6c
...
...
@@ -8,9 +8,15 @@ namespace Bind
class
Texture
:
public
Bindable
{
public:
Texture
(
Graphics
&
gfx
,
const
Surface
&
s
);
Texture
(
Graphics
&
gfx
,
const
std
::
string
&
path
,
UINT
slot
=
0
);
void
Bind
(
Graphics
&
gfx
)
noexcept
override
;
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
);
std
::
string
GetUID
()
const
noexcept
override
;
private:
unsigned
int
slot
;
protected:
std
::
string
path
;
Microsoft
::
WRL
::
ComPtr
<
ID3D11ShaderResourceView
>
pTextureView
;
};
}
hw3d/Topology.cpp
View file @
2526ae6c
#include "Topology.h"
#include "BindableCodex.h"
namespace
Bind
{
...
...
@@ -11,4 +12,17 @@ namespace Bind
{
GetContext
(
gfx
)
->
IASetPrimitiveTopology
(
type
);
}
std
::
shared_ptr
<
Topology
>
Topology
::
Resolve
(
Graphics
&
gfx
,
D3D11_PRIMITIVE_TOPOLOGY
type
)
{
return
Codex
::
Resolve
<
Topology
>
(
gfx
,
type
);
}
std
::
string
Topology
::
GenerateUID
(
D3D11_PRIMITIVE_TOPOLOGY
type
)
{
using
namespace
std
::
string_literals
;
return
typeid
(
Topology
).
name
()
+
"#"
s
+
std
::
to_string
(
type
);
}
std
::
string
Topology
::
GetUID
()
const
noexcept
{
return
GenerateUID
(
type
);
}
}
hw3d/Topology.h
View file @
2526ae6c
...
...
@@ -8,6 +8,9 @@ namespace Bind
public:
Topology
(
Graphics
&
gfx
,
D3D11_PRIMITIVE_TOPOLOGY
type
);
void
Bind
(
Graphics
&
gfx
)
noexcept
override
;
static
std
::
shared_ptr
<
Topology
>
Resolve
(
Graphics
&
gfx
,
D3D11_PRIMITIVE_TOPOLOGY
type
);
static
std
::
string
GenerateUID
(
D3D11_PRIMITIVE_TOPOLOGY
type
);
std
::
string
GetUID
()
const
noexcept
override
;
protected:
D3D11_PRIMITIVE_TOPOLOGY
type
;
};
...
...
hw3d/Vertex.cpp
View file @
2526ae6c
...
...
@@ -30,6 +30,15 @@ namespace Dvtx
}
return
desc
;
}
std
::
string
VertexLayout
::
GetCode
()
const
noxnd
{
std
::
string
code
;
for
(
const
auto
&
e
:
elements
)
{
code
+=
e
.
GetCode
();
}
return
code
;
}
// VertexLayout::Element
...
...
@@ -76,6 +85,28 @@ namespace Dvtx
{
return
type
;
}
const
char
*
Dvtx
::
VertexLayout
::
Element
::
GetCode
()
const
noexcept
{
switch
(
type
)
{
case
Position2D
:
return
Map
<
Position2D
>::
code
;
case
Position3D
:
return
Map
<
Position3D
>::
code
;
case
Texture2D
:
return
Map
<
Texture2D
>::
code
;
case
Normal
:
return
Map
<
Normal
>::
code
;
case
Float3Color
:
return
Map
<
Float3Color
>::
code
;
case
Float4Color
:
return
Map
<
Float4Color
>::
code
;
case
BGRAColor
:
return
Map
<
BGRAColor
>::
code
;
}
assert
(
"Invalid element type"
&&
false
);
return
"Invalid"
;
}
D3D11_INPUT_ELEMENT_DESC
VertexLayout
::
Element
::
GetDesc
()
const
noxnd
{
switch
(
type
)
...
...
hw3d/Vertex.h
View file @
2526ae6c
...
...
@@ -27,42 +27,49 @@ namespace Dvtx
using
SysType
=
DirectX
::
XMFLOAT2
;
static
constexpr
DXGI_FORMAT
dxgiFormat
=
DXGI_FORMAT_R32G32_FLOAT
;
static
constexpr
const
char
*
semantic
=
"Position"
;
static
constexpr
const
char
*
code
=
"P2"
;
};
template
<
>
struct
Map
<
Position3D
>
{
using
SysType
=
DirectX
::
XMFLOAT3
;
static
constexpr
DXGI_FORMAT
dxgiFormat
=
DXGI_FORMAT_R32G32B32_FLOAT
;
static
constexpr
const
char
*
semantic
=
"Position"
;
static
constexpr
const
char
*
code
=
"P3"
;
};
template
<
>
struct
Map
<
Texture2D
>
{
using
SysType
=
DirectX
::
XMFLOAT2
;
static
constexpr
DXGI_FORMAT
dxgiFormat
=
DXGI_FORMAT_R32G32_FLOAT
;
static
constexpr
const
char
*
semantic
=
"Texcoord"
;
static
constexpr
const
char
*
code
=
"T2"
;
};
template
<
>
struct
Map
<
Normal
>
{
using
SysType
=
DirectX
::
XMFLOAT3
;
static
constexpr
DXGI_FORMAT
dxgiFormat
=
DXGI_FORMAT_R32G32B32_FLOAT
;
static
constexpr
const
char
*
semantic
=
"Normal"
;
static
constexpr
const
char
*
code
=
"N"
;
};
template
<
>
struct
Map
<
Float3Color
>
{
using
SysType
=
DirectX
::
XMFLOAT3
;
static
constexpr
DXGI_FORMAT
dxgiFormat
=
DXGI_FORMAT_R32G32B32_FLOAT
;
static
constexpr
const
char
*
semantic
=
"Color"
;
static
constexpr
const
char
*
code
=
"C3"
;
};
template
<
>
struct
Map
<
Float4Color
>
{
using
SysType
=
DirectX
::
XMFLOAT4
;
static
constexpr
DXGI_FORMAT
dxgiFormat
=
DXGI_FORMAT_R32G32B32A32_FLOAT
;
static
constexpr
const
char
*
semantic
=
"Color"
;
static
constexpr
const
char
*
code
=
"C4"
;
};
template
<
>
struct
Map
<
BGRAColor
>
{
using
SysType
=
::
BGRAColor
;
static
constexpr
DXGI_FORMAT
dxgiFormat
=
DXGI_FORMAT_R8G8B8A8_UNORM
;
static
constexpr
const
char
*
semantic
=
"Color"
;
static
constexpr
const
char
*
code
=
"C8"
;
};
class
Element
...
...
@@ -75,9 +82,10 @@ namespace Dvtx
static
constexpr
size_t
SizeOf
(
ElementType
type
)
noxnd
;
ElementType
GetType
()
const
noexcept
;
D3D11_INPUT_ELEMENT_DESC
GetDesc
()
const
noxnd
;
const
char
*
GetCode
()
const
noexcept
;
private:
template
<
ElementType
type
>
static
constexpr
D3D11_INPUT_ELEMENT_DESC
GenerateDesc
(
size_t
offset
)
no
xnd
static
constexpr
D3D11_INPUT_ELEMENT_DESC
GenerateDesc
(
size_t
offset
)
no
except
{
return
{
Map
<
type
>::
semantic
,
0
,
Map
<
type
>::
dxgiFormat
,
0
,(
UINT
)
offset
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
};
}
...
...
@@ -104,6 +112,7 @@ namespace Dvtx
size_t
Size
()
const
noxnd
;
size_t
GetElementCount
()
const
noexcept
;
std
::
vector
<
D3D11_INPUT_ELEMENT_DESC
>
GetD3DLayout
()
const
noxnd
;
std
::
string
GetCode
()
const
noxnd
;
private:
std
::
vector
<
Element
>
elements
;
};
...
...
hw3d/VertexBuffer.cpp
View file @
2526ae6c
#include "VertexBuffer.h"
#include "BindableCodex.h"
namespace
Bind
{
VertexBuffer
::
VertexBuffer
(
Graphics
&
gfx
,
const
Dvtx
::
VertexBuffer
&
vbuf
)
:
stride
(
(
UINT
)
vbuf
.
GetLayout
().
Size
()
)
VertexBuffer
(
gfx
,
"?"
,
vbuf
)
{}
VertexBuffer
::
VertexBuffer
(
Graphics
&
gfx
,
const
std
::
string
&
tag
,
const
Dvtx
::
VertexBuffer
&
vbuf
)
:
stride
(
(
UINT
)
vbuf
.
GetLayout
().
Size
()
),
tag
(
tag
)
{
INFOMAN
(
gfx
);
...
...
@@ -25,4 +31,19 @@ namespace Bind
const
UINT
offset
=
0u
;
GetContext
(
gfx
)
->
IASetVertexBuffers
(
0u
,
1u
,
pVertexBuffer
.
GetAddressOf
(),
&
stride
,
&
offset
);
}
std
::
shared_ptr
<
VertexBuffer
>
VertexBuffer
::
Resolve
(
Graphics
&
gfx
,
const
std
::
string
&
tag
,
const
Dvtx
::
VertexBuffer
&
vbuf
)
{
assert
(
tag
!=
"?"
);
return
Codex
::
Resolve
<
VertexBuffer
>
(
gfx
,
tag
,
vbuf
);
}
std
::
string
VertexBuffer
::
GenerateUID_
(
const
std
::
string
&
tag
)
{
using
namespace
std
::
string_literals
;
return
typeid
(
VertexBuffer
).
name
()
+
"#"
s
+
tag
;
}
std
::
string
VertexBuffer
::
GetUID
()
const
noexcept
{
return
GenerateUID
(
tag
);
}
}
hw3d/VertexBuffer.h
View file @
2526ae6c
...
...
@@ -8,27 +8,21 @@ namespace Bind
class
VertexBuffer
:
public
Bindable
{
public:
template
<
class
V
>
VertexBuffer
(
Graphics
&
gfx
,
const
std
::
vector
<
V
>&
vertices
)
:
stride
(
sizeof
(
V
)
)
{
INFOMAN
(
gfx
);
D3D11_BUFFER_DESC
bd
=
{};
bd
.
BindFlags
=
D3D11_BIND_VERTEX_BUFFER
;
bd
.
Usage
=
D3D11_USAGE_DEFAULT
;
bd
.
CPUAccessFlags
=
0u
;
bd
.
MiscFlags
=
0u
;
bd
.
ByteWidth
=
UINT
(
sizeof
(
V
)
*
vertices
.
size
()
);
bd
.
StructureByteStride
=
sizeof
(
V
);
D3D11_SUBRESOURCE_DATA
sd
=
{};
sd
.
pSysMem
=
vertices
.
data
();
GFX_THROW_INFO
(
GetDevice
(
gfx
)
->
CreateBuffer
(
&
bd
,
&
sd
,
&
pVertexBuffer
)
);
}
VertexBuffer
(
Graphics
&
gfx
,
const
std
::
string
&
tag
,
const
Dvtx
::
VertexBuffer
&
vbuf
);
VertexBuffer
(
Graphics
&
gfx
,
const
Dvtx
::
VertexBuffer
&
vbuf
);
void
Bind
(
Graphics
&
gfx
)
noexcept
override
;
static
std
::
shared_ptr
<
VertexBuffer
>
Resolve
(
Graphics
&
gfx
,
const
std
::
string
&
tag
,
const
Dvtx
::
VertexBuffer
&
vbuf
);
template
<
typename
...
Ignore
>
static
std
::
string
GenerateUID
(
const
std
::
string
&
tag
,
Ignore
&&
...
ignore
)
{
return
GenerateUID_
(
tag
);
}
std
::
string
GetUID
()
const
noexcept
override
;
private:
static
std
::
string
GenerateUID_
(
const
std
::
string
&
tag
);
protected:
std
::
string
tag
;
UINT
stride
;
Microsoft
::
WRL
::
ComPtr
<
ID3D11Buffer
>
pVertexBuffer
;
};
...
...
hw3d/VertexShader.cpp
View file @
2526ae6c
#include "VertexShader.h"
#include "GraphicsThrowMacros.h"
#include "BindableCodex.h"
#include <typeinfo>
namespace
Bind
{
VertexShader
::
VertexShader
(
Graphics
&
gfx
,
const
std
::
wstring
&
path
)
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 +29,17 @@ namespace Bind
{
return
pBytecodeBlob
.
Get
();
}
std
::
shared_ptr
<
VertexShader
>
VertexShader
::
Resolve
(
Graphics
&
gfx
,
const
std
::
string
&
path
)
{
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
{
return
GenerateUID
(
path
);
}
}
hw3d/VertexShader.h
View file @
2526ae6c
...
...
@@ -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
<
VertexShader
>
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 @
2526ae6c
...
...
@@ -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"
/>
...
...
@@ -141,7 +142,6 @@
<ClInclude
Include=
"ConditionalNoexcept.h"
/>
<ClInclude
Include=
"ConstantBuffers.h"
/>
<ClInclude
Include=
"Drawable.h"
/>
<ClInclude
Include=
"DrawableBase.h"
/>
<ClInclude
Include=
"dxerr.h"
/>
<ClInclude
Include=
"DxgiInfoManager.h"
/>
<ClInclude
Include=
"GDIPlusManager.h"
/>
...
...
@@ -191,6 +191,14 @@
<None
Include=
"DXTrace.inl"
/>
</ItemGroup>
<ItemGroup>
<FxCompile
Include=
"PhongPSSpecMap.hlsl"
>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
Pixel
</ShaderType>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
4.0
</ShaderModel>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
Pixel
</ShaderType>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
4.0
</ShaderModel>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
</FxCompile>
<FxCompile
Include=
"SolidPS.hlsl"
>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
Pixel
</ShaderType>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
4.0
</ShaderModel>
...
...
hw3d/hw3d.vcxproj.filters
View file @
2526ae6c
...
...
@@ -221,9 +221,6 @@
<ClInclude
Include=
"Drawable.h"
>
<Filter>
Header Files\Drawable
</Filter>
</ClInclude>
<ClInclude
Include=
"DrawableBase.h"
>
<Filter>
Header Files\Drawable
</Filter>
</ClInclude>
<ClInclude
Include=
"WindowsThrowMacros.h"
>
<Filter>
Header Files\Macros
</Filter>
</ClInclude>
...
...
@@ -299,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"
>
...
...
@@ -334,5 +334,8 @@
<FxCompile
Include=
"SolidVS.hlsl"
>
<Filter>
Shader
</Filter>
</FxCompile>
<FxCompile
Include=
"PhongPSSpecMap.hlsl"
>
<Filter>
Shader
</Filter>
</FxCompile>
</ItemGroup>
</Project>
\ No newline at end of file
Prev
1
2
3
Next