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
cef53f68
Commit
cef53f68
authored
Mar 07, 2023
by
Administrator
Browse files
added IndexBuffer; re-structured bindables and drawables into filters
parent
ab9158a5
Changes
7
Hide whitespace changes
Inline
Side-by-side
PracticeDx/Drawable.cpp
View file @
cef53f68
...
...
@@ -17,9 +17,9 @@ void Drawable::AddBind(std::unique_ptr<Bindable> bind) noexcept
binds
.
push_back
(
std
::
move
(
bind
));
}
/*
void Drawable::AddIndexBuffer(std::unique_ptr<IndexBuffer> ibuf) noexcept
void
Drawable
::
AddIndexBuffer
(
std
::
unique_ptr
<
IndexBuffer
>
ibuf
)
noexcept
{
assert
(
"Attempting to add index buffer a second time"
&&
pIndexBuffer
==
nullptr
);
pIndexBuffer
=
ibuf
.
get
();
binds
.
push_back
(
std
::
move
(
ibuf
));
}
*/
}
PracticeDx/Drawable.h
View file @
cef53f68
...
...
@@ -4,6 +4,7 @@
#include <memory>
#include <vector>
#include "Bindable.h"
#include "IndexBuffer.h"
class
Bindable
;
...
...
@@ -17,9 +18,9 @@ public:
//virtual void Update(float dt) noexcept = 0;
void
AddBind
(
std
::
unique_ptr
<
Bindable
>
bind
)
noexcept
;
//
void AddIndexBuffer(std::unique_ptr<class IndexBuffer> ibuf) noexcept;
void
AddIndexBuffer
(
std
::
unique_ptr
<
class
IndexBuffer
>
ibuf
)
noexcept
;
virtual
~
Drawable
()
=
default
;
private:
//
const IndexBuffer* pIndexBuffer = nullptr;
const
IndexBuffer
*
pIndexBuffer
=
nullptr
;
std
::
vector
<
std
::
unique_ptr
<
Bindable
>>
binds
;
};
\ No newline at end of file
PracticeDx/IndexBuffer.cpp
0 → 100644
View file @
cef53f68
#include "IndexBuffer.h"
IndexBuffer
::
IndexBuffer
(
Graphics
&
gfx
,
const
std
::
vector
<
unsigned
short
>&
indices
)
:
count
((
UINT
)
indices
.
size
())
{
D3D11_BUFFER_DESC
ibd
=
{};
ibd
.
BindFlags
=
D3D11_BIND_INDEX_BUFFER
;
ibd
.
Usage
=
D3D11_USAGE_DEFAULT
;
ibd
.
CPUAccessFlags
=
0u
;
ibd
.
MiscFlags
=
0u
;
ibd
.
ByteWidth
=
UINT
(
count
*
sizeof
(
unsigned
short
));
ibd
.
StructureByteStride
=
sizeof
(
unsigned
short
);
D3D11_SUBRESOURCE_DATA
isd
=
{};
isd
.
pSysMem
=
indices
.
data
();
GetDevice
(
gfx
)
->
CreateBuffer
(
&
ibd
,
&
isd
,
&
pIndexBuffer
);
}
void
IndexBuffer
::
Bind
(
Graphics
&
gfx
)
noexcept
{
GetContext
(
gfx
)
->
IASetIndexBuffer
(
pIndexBuffer
.
Get
(),
DXGI_FORMAT_R16_UINT
,
0u
);
}
UINT
IndexBuffer
::
GetCount
()
const
noexcept
{
return
count
;
}
PracticeDx/IndexBuffer.h
0 → 100644
View file @
cef53f68
#pragma once
#include "Bindable.h"
#include <d3d11.h>
#include <vector>
class
IndexBuffer
:
public
Bindable
{
public:
IndexBuffer
(
Graphics
&
gfx
,
const
std
::
vector
<
unsigned
short
>&
indices
);
void
Bind
(
Graphics
&
gfx
)
noexcept
override
;
UINT
GetCount
()
const
noexcept
;
protected:
UINT
count
;
Microsoft
::
WRL
::
ComPtr
<
ID3D11Buffer
>
pIndexBuffer
;
};
\ No newline at end of file
PracticeDx/PracticeDx.vcxproj
View file @
cef53f68
...
...
@@ -130,6 +130,7 @@
<ClCompile
Include=
"Bindable.cpp"
/>
<ClCompile
Include=
"Drawable.cpp"
/>
<ClCompile
Include=
"Graphics.cpp"
/>
<ClCompile
Include=
"IndexBuffer.cpp"
/>
<ClCompile
Include=
"Timer.cpp"
/>
<ClCompile
Include=
"Triangle.cpp"
/>
<ClCompile
Include=
"VertexBuffer.cpp"
/>
...
...
@@ -159,6 +160,7 @@
<ClInclude
Include=
"Bindable.h"
/>
<ClInclude
Include=
"Drawable.h"
/>
<ClInclude
Include=
"Graphics.h"
/>
<ClInclude
Include=
"IndexBuffer.h"
/>
<ClInclude
Include=
"Structs.h"
/>
<ClInclude
Include=
"Timer.h"
/>
<ClInclude
Include=
"Triangle.h"
/>
...
...
PracticeDx/Structs.h
View file @
cef53f68
#pragma once
// 用于定义顶点的结构,三维坐标
struct
StructVertex
{
struct
...
...
PracticeDx/Triangle.cpp
View file @
cef53f68
...
...
@@ -2,6 +2,7 @@
#include "Triangle.h"
#include "Bindable.h"
#include "VertexBuffer.h"
#include "IndexBuffer.h"
Triangle
::
Triangle
(
Graphics
&
gfx
,
float
**
position
,
float
r
,
float
g
,
float
b
)
:
...
...
@@ -26,6 +27,7 @@ Triangle::Triangle(Graphics& gfx, float** position, float r, float g, float b)
AddBind(std::move(pvs));
AddBind(std::make_unique<PixelShader>(gfx, L"PixelShader.cso"));
*/
const
std
::
vector
<
unsigned
short
>
indices
=
{
...
...
@@ -38,6 +40,7 @@ Triangle::Triangle(Graphics& gfx, float** position, float r, float g, float b)
};
AddIndexBuffer
(
std
::
make_unique
<
IndexBuffer
>
(
gfx
,
indices
));
/*
struct ConstantBuffer2
{
struct
...
...
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