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
c526e295
Commit
c526e295
authored
May 13, 2019
by
chili
Browse files
vertex layout template system working
parent
114a7d6b
Changes
2
Hide whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
c526e295
...
...
@@ -21,12 +21,27 @@ GDIPlusManager gdipm;
void
f
()
{
VertexLayout
vl
;
vl
.
Append
<
VertexLayout
::
Position3D
>
()
.
Append
<
VertexLayout
::
Normal
>
();
VertexBuffer
vb
(
std
::
move
(
vl
)
);
vb
.
EmplaceBack
(
dx
::
XMFLOAT3
{
1.0
f
,
1.0
f
,
5.0
f
},
dx
::
XMFLOAT3
{
2.0
f
,
1.0
f
,
4.0
f
}
);
VertexBuffer
vb
(
std
::
move
(
VertexLayout
{}
.
Append
<
VertexLayout
::
Position3D
>
()
.
Append
<
VertexLayout
::
Normal
>
()
.
Append
<
VertexLayout
::
Texture2D
>
()
)
);
vb
.
EmplaceBack
(
dx
::
XMFLOAT3
{
1.0
f
,
1.0
f
,
5.0
f
},
dx
::
XMFLOAT3
{
2.0
f
,
1.0
f
,
4.0
f
},
dx
::
XMFLOAT2
{
6.0
f
,
9.0
f
}
);
vb
.
EmplaceBack
(
dx
::
XMFLOAT3
{
6.0
f
,
9.0
f
,
6.0
f
},
dx
::
XMFLOAT3
{
9.0
f
,
6.0
f
,
9.0
f
},
dx
::
XMFLOAT2
{
4.2
f
,
0.0
f
}
);
auto
pos
=
vb
[
0
].
Attr
<
VertexLayout
::
Position3D
>
();
auto
nor
=
vb
[
0
].
Attr
<
VertexLayout
::
Normal
>
();
auto
tex
=
vb
[
1
].
Attr
<
VertexLayout
::
Texture2D
>
();
vb
.
Back
().
Attr
<
VertexLayout
::
Position3D
>
().
z
=
420.0
f
;
pos
=
vb
.
Back
().
Attr
<
VertexLayout
::
Position3D
>
();
}
App
::
App
()
...
...
hw3d/VertexLayout.h
View file @
c526e295
...
...
@@ -103,6 +103,10 @@ public:
{
return
elements
.
empty
()
?
0u
:
elements
.
back
().
GetOffsetAfter
();
}
size_t
GetElementCount
()
const
noexcept
{
return
elements
.
size
();
}
private:
std
::
vector
<
Element
>
elements
;
};
...
...
@@ -197,7 +201,7 @@ private:
void
SetAttributeByIndex
(
size_t
i
,
First
&&
first
,
Rest
&&
...
rest
)
noexcept
(
!
IS_DEBUG
)
{
SetAttributeByIndex
(
i
,
std
::
forward
<
First
>
(
first
)
);
SetAttributeByIndex
(
i
,
std
::
forward
<
Rest
>
(
rest
)...
);
SetAttributeByIndex
(
i
+
1
,
std
::
forward
<
Rest
>
(
rest
)...
);
}
// helper to reduce code duplication in SetAttributeByIndex
template
<
typename
Dest
,
typename
Src
>
...
...
@@ -235,6 +239,7 @@ public:
template
<
typename
...
Params
>
void
EmplaceBack
(
Params
&&
...
params
)
noexcept
(
!
IS_DEBUG
)
{
assert
(
sizeof
...(
params
)
==
layout
.
GetElementCount
()
&&
"Param count doesn't match number of vertex elements"
);
buffer
.
resize
(
buffer
.
size
()
+
layout
.
Size
()
);
Back
().
SetAttributeByIndex
(
0u
,
std
::
forward
<
Params
>
(
params
)...
);
}
...
...
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