-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeviceContext.cpp
More file actions
113 lines (90 loc) · 3.29 KB
/
DeviceContext.cpp
File metadata and controls
113 lines (90 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "DeviceContext.h"
#include "SwapChain.h"
#include "VertexBuffer.h"
#include "VertexShader.h"
#include "Texture.h"
DeviceContext::DeviceContext(ID3D11DeviceContext* device_context)
{
m_device_context = device_context;
}
void DeviceContext::clearRenderTargetColor(SwapChain* swap_chain, float red, float green, float blue, float alpha)
{
const FLOAT clear_color[] = { red, green, blue, alpha };
ID3D11RenderTargetView* rtv = swap_chain->getRenderTargetView();
ID3D11DepthStencilView* depthView = swap_chain->getDepthStencilView();
m_device_context->ClearRenderTargetView(rtv, clear_color);
m_device_context->ClearDepthStencilView(depthView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1, 0);
m_device_context->OMSetRenderTargets(1, &rtv, depthView);
}
bool DeviceContext::release()
{
m_device_context->Release();
delete this;
return true;
}
void DeviceContext::setVertexBuffer(VertexBuffer* vertex_buffer)
{
UINT stride = vertex_buffer->m_size_vertex;
UINT offset = 0;
m_device_context->IASetVertexBuffers(0, 1, &vertex_buffer->m_buffer, &stride, &offset);
m_device_context->IASetInputLayout(vertex_buffer->m_input_layout);
}
void DeviceContext::setVertexShader(VertexShader* vertex_shader)
{
m_device_context->VSSetShader(vertex_shader->getShader(), nullptr, 0);
}
void DeviceContext::setPixelShader(PixelShader* pixel_shader)
{
m_device_context->PSSetShader(pixel_shader->getShader(), nullptr, 0);
}
void DeviceContext::setIndexBuffer(IndexBuffer* index_buffer)
{
m_device_context->IASetIndexBuffer(index_buffer->getBuffer(), DXGI_FORMAT_R32_UINT, 0);
}
void DeviceContext::setRenderConfig(VertexShader* vertexShader, PixelShader* pixelShader)
{
this->m_device_context->VSSetShader(vertexShader->getShader(), NULL, 0);
this->m_device_context->PSSetShader(pixelShader->getShader(), NULL, 0);
}
void DeviceContext::setConstantBuffer(ConstantBuffer* buffer)
{
m_device_context->VSSetConstantBuffers(0, 1, &(buffer->m_buffer));
m_device_context->PSSetConstantBuffers(0, 1, &(buffer->m_buffer));
}
void DeviceContext::setTexture(Texture* texture)
{
ID3D11ShaderResourceView* shaderRes = texture->getShaderResource();
this->m_device_context->VSSetShaderResources(0, 1, &shaderRes);
this->m_device_context->PSSetShaderResources(0, 1, &shaderRes);
}
void DeviceContext::drawTriangleList(UINT vertex_count, UINT start_vertex_index)
{
m_device_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_device_context->Draw(vertex_count, start_vertex_index);
}
void DeviceContext::drawTriangleStrip(UINT vertex_count, UINT start_vertex_index)
{
m_device_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
m_device_context->Draw(vertex_count, start_vertex_index);
}
void DeviceContext::drawIndexedTriangleList(UINT index_count, UINT start_index_location, UINT start_vertex_index)
{
m_device_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_device_context->DrawIndexed(index_count, start_index_location, start_vertex_index);
}
void DeviceContext::setViewportSize(UINT width, UINT height)
{
D3D11_VIEWPORT vp= {};
vp.Width = width;
vp.Height = height;
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
m_device_context->RSSetViewports(1, &vp);
}
ID3D11DeviceContext* DeviceContext::getDeviceContext()
{
return m_device_context;
}
DeviceContext::~DeviceContext()
{
}