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
2b41752b
Commit
2b41752b
authored
May 13, 2019
by
chili
Browse files
const vertex handle
parent
c526e295
Changes
2
Show whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
2b41752b
...
...
@@ -13,7 +13,7 @@
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include "Vertex
Layout
.h"
#include "Vertex.h"
namespace
dx
=
DirectX
;
...
...
@@ -42,6 +42,8 @@ void f()
auto
tex
=
vb
[
1
].
Attr
<
VertexLayout
::
Texture2D
>
();
vb
.
Back
().
Attr
<
VertexLayout
::
Position3D
>
().
z
=
420.0
f
;
pos
=
vb
.
Back
().
Attr
<
VertexLayout
::
Position3D
>
();
const
auto
&
cvb
=
vb
;
pos
=
cvb
[
1
].
Attr
<
VertexLayout
::
Position3D
>
();
}
App
::
App
()
...
...
hw3d/Vertex
Layout
.h
→
hw3d/Vertex.h
View file @
2b41752b
...
...
@@ -62,7 +62,7 @@ public:
case
Float4Color
:
return
sizeof
(
XMFLOAT3
);
case
BGRAColor
:
return
sizeof
(
unsigned
int
);
return
sizeof
(
::
BGRAColor
);
}
assert
(
"Invalid element type"
&&
false
);
return
0u
;
...
...
@@ -188,7 +188,7 @@ public:
assert
(
"Bad element type"
&&
false
);
}
}
pr
ivate
:
pr
otected
:
Vertex
(
char
*
pData
,
const
VertexLayout
&
layout
)
noexcept
(
!
IS_DEBUG
)
:
pData
(
pData
),
...
...
@@ -196,6 +196,7 @@ private:
{
assert
(
pData
!=
nullptr
);
}
private:
template
<
typename
First
,
typename
...
Rest
>
// enables parameter pack setting of multiple parameters by element index
void
SetAttributeByIndex
(
size_t
i
,
First
&&
first
,
Rest
&&
...
rest
)
noexcept
(
!
IS_DEBUG
)
...
...
@@ -221,6 +222,22 @@ private:
const
VertexLayout
&
layout
;
};
class
ConstVertex
{
public:
ConstVertex
(
const
Vertex
&
v
)
noexcept
(
!
IS_DEBUG
)
:
vertex
(
v
)
{}
template
<
VertexLayout
::
ElementType
Type
>
const
auto
&
Attr
()
const
noexcept
(
!
IS_DEBUG
)
{
return
const_cast
<
Vertex
&>
(
vertex
).
Attr
<
Type
>
();
}
private:
Vertex
vertex
;
};
class
VertexBuffer
{
public:
...
...
@@ -258,6 +275,18 @@ public:
assert
(
i
<
Size
()
);
return
Vertex
{
buffer
.
data
()
+
layout
.
Size
()
*
i
,
layout
};
}
ConstVertex
Back
()
const
noexcept
(
!
IS_DEBUG
)
{
return
const_cast
<
VertexBuffer
*>
(
this
)
->
Back
();
}
ConstVertex
Front
()
const
noexcept
(
!
IS_DEBUG
)
{
return
const_cast
<
VertexBuffer
*>
(
this
)
->
Front
();
}
ConstVertex
operator
[](
size_t
i
)
const
noexcept
(
!
IS_DEBUG
)
{
return
const_cast
<
VertexBuffer
&>
(
*
this
)[
i
];
}
private:
std
::
vector
<
char
>
buffer
;
VertexLayout
layout
;
...
...
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