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
7add7049
Commit
7add7049
authored
Feb 03, 2019
by
chili
Browse files
rotation cbuf
parent
2dfc064e
Changes
4
Show whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
7add7049
...
...
@@ -23,6 +23,6 @@ void App::DoFrame()
{
const
float
c
=
sin
(
timer
.
Peek
()
)
/
2.0
f
+
0.5
f
;
wnd
.
Gfx
().
ClearBuffer
(
c
,
c
,
1.0
f
);
wnd
.
Gfx
().
DrawTestTriangle
();
wnd
.
Gfx
().
DrawTestTriangle
(
timer
.
Peek
()
);
wnd
.
Gfx
().
EndFrame
();
}
\ No newline at end of file
hw3d/Graphics.cpp
View file @
7add7049
...
...
@@ -2,6 +2,7 @@
#include "dxerr.h"
#include <sstream>
#include <d3dcompiler.h>
#include <cmath>
namespace
wrl
=
Microsoft
::
WRL
;
...
...
@@ -98,7 +99,7 @@ void Graphics::ClearBuffer( float red,float green,float blue ) noexcept
pContext
->
ClearRenderTargetView
(
pTarget
.
Get
(),
color
);
}
void
Graphics
::
DrawTestTriangle
()
void
Graphics
::
DrawTestTriangle
(
float
angle
)
{
HRESULT
hr
;
...
...
@@ -171,6 +172,39 @@ void Graphics::DrawTestTriangle()
pContext
->
IASetIndexBuffer
(
pIndexBuffer
.
Get
(),
DXGI_FORMAT_R16_UINT
,
0u
);
// create constant buffer for transformation matrix
struct
ConstantBuffer
{
struct
{
float
element
[
4
][
4
];
}
transformation
;
};
const
ConstantBuffer
cb
=
{
{
std
::
cos
(
angle
),
std
::
sin
(
angle
),
0.0
f
,
0.0
f
,
-
std
::
sin
(
angle
),
std
::
cos
(
angle
),
0.0
f
,
0.0
f
,
0.0
f
,
0.0
f
,
1.0
f
,
0.0
f
,
0.0
f
,
0.0
f
,
0.0
f
,
1.0
f
,
}
};
wrl
::
ComPtr
<
ID3D11Buffer
>
pConstantBuffer
;
D3D11_BUFFER_DESC
cbd
;
cbd
.
BindFlags
=
D3D11_BIND_CONSTANT_BUFFER
;
cbd
.
Usage
=
D3D11_USAGE_DYNAMIC
;
cbd
.
CPUAccessFlags
=
D3D11_CPU_ACCESS_WRITE
;
cbd
.
MiscFlags
=
0u
;
cbd
.
ByteWidth
=
sizeof
(
cb
);
cbd
.
StructureByteStride
=
0u
;
D3D11_SUBRESOURCE_DATA
csd
=
{};
csd
.
pSysMem
=
&
cb
;
GFX_THROW_INFO
(
pDevice
->
CreateBuffer
(
&
cbd
,
&
csd
,
&
pConstantBuffer
)
);
// bind constant buffer to vertex shader
pContext
->
VSSetConstantBuffers
(
0u
,
1u
,
pConstantBuffer
.
GetAddressOf
()
);
// create pixel shader
wrl
::
ComPtr
<
ID3D11PixelShader
>
pPixelShader
;
wrl
::
ComPtr
<
ID3DBlob
>
pBlob
;
...
...
hw3d/Graphics.h
View file @
7add7049
...
...
@@ -52,7 +52,7 @@ public:
~
Graphics
()
=
default
;
void
EndFrame
();
void
ClearBuffer
(
float
red
,
float
green
,
float
blue
)
noexcept
;
void
DrawTestTriangle
();
void
DrawTestTriangle
(
float
angle
);
private:
#ifndef NDEBUG
DxgiInfoManager
infoManager
;
...
...
hw3d/VertexShader.hlsl
View file @
7add7049
...
...
@@ -4,10 +4,15 @@ struct VSOut
float4
pos
:
SV_Position
;
};
cbuffer
CBuf
{
matrix
transform
;
};
VSOut
main
(
float2
pos
:
Position
,
float3
color
:
Color
)
{
VSOut
vso
;
vso
.
pos
=
float4
(
pos
.
x
,
pos
.
y
,
0
.
0
f
,
1
.
0
f
);
vso
.
pos
=
mul
(
float4
(
pos
.
x
,
pos
.
y
,
0
.
0
f
,
1
.
0
f
),
transform
);
vso
.
color
=
color
;
return
vso
;
}
\ No newline at end of file
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