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
PracticeDx
Commits
ab9158a5
Commit
ab9158a5
authored
Mar 07, 2023
by
Administrator
Browse files
fixed VertexBuffer link error
DO NOT use template programming in VertexBuffer
parent
cb004c2c
Changes
5
Show whitespace changes
Inline
Side-by-side
PracticeDx/PracticeDx.vcxproj
View file @
ab9158a5
...
...
@@ -159,6 +159,7 @@
<ClInclude
Include=
"Bindable.h"
/>
<ClInclude
Include=
"Drawable.h"
/>
<ClInclude
Include=
"Graphics.h"
/>
<ClInclude
Include=
"Structs.h"
/>
<ClInclude
Include=
"Timer.h"
/>
<ClInclude
Include=
"Triangle.h"
/>
<ClInclude
Include=
"VertexBuffer.h"
/>
...
...
PracticeDx/Structs.h
0 → 100644
View file @
ab9158a5
#pragma once
struct
StructVertex
{
struct
{
float
x
;
float
y
;
float
z
;
}
pos
;
};
\ No newline at end of file
PracticeDx/Triangle.cpp
View file @
ab9158a5
...
...
@@ -10,25 +10,14 @@ Triangle::Triangle(Graphics& gfx, float** position, float r, float g, float b)
b
(
b
),
position
(
position
)
{
struct
Vertex
{
struct
{
float
x
;
float
y
;
float
z
;
}
pos
;
};
const
std
::
vector
<
Vertex
>
vertices
=
const
std
::
vector
<
StructVertex
>
vertices
=
{
{
position
[
0
][
0
],
position
[
0
][
1
],
position
[
0
][
2
]
},
{
position
[
1
][
0
],
position
[
1
][
1
],
position
[
1
][
2
]
},
{
position
[
2
][
0
],
position
[
2
][
1
],
position
[
2
][
2
]
}
};
//VertexBuffer vb(gfx, vertices);
//AddBind(std::make_unique<VertexBuffer>(gfx, vertices));
AddBind
(
std
::
make_unique
<
VertexBuffer
>
(
gfx
,
vertices
));
/*
...
...
PracticeDx/VertexBuffer.cpp
View file @
ab9158a5
#pragma once
#include "VertexBuffer.h"
template
<
class
V
>
VertexBuffer
::
VertexBuffer
(
Graphics
&
gfx
,
const
std
::
vector
<
V
>&
vertices
)
//
template<class V>
VertexBuffer
::
VertexBuffer
(
Graphics
&
gfx
,
const
std
::
vector
<
StructVertex
>&
vertices
)
:
stride
(
sizeof
(
V
))
stride
(
sizeof
(
StructVertex
))
{
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
);
bd
.
ByteWidth
=
UINT
(
sizeof
(
StructVertex
)
*
vertices
.
size
());
bd
.
StructureByteStride
=
sizeof
(
StructVertex
);
D3D11_SUBRESOURCE_DATA
sd
=
{};
sd
.
pSysMem
=
vertices
.
data
();
GetDevice
(
gfx
)
->
CreateBuffer
(
&
bd
,
&
sd
,
&
pVertexBuffer
);
...
...
PracticeDx/VertexBuffer.h
View file @
ab9158a5
...
...
@@ -3,12 +3,12 @@
#include <wrl.h>
#include <d3d11.h>
#include <vector>
#include "Structs.h"
class
VertexBuffer
:
public
Bindable
{
public:
template
<
class
V
>
VertexBuffer
(
Graphics
&
gfx
,
const
std
::
vector
<
V
>&
vertices
);
VertexBuffer
(
Graphics
&
gfx
,
const
std
::
vector
<
StructVertex
>&
vertices
);
void
Bind
(
Graphics
&
gfx
)
noexcept
override
;
protected:
...
...
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