PageRenderTime 32ms CodeModel.GetById 19ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Core_WindowEvents/Win32D3D10/RenderContextPimpl_DIRECTX10.cpp

http://github.com/Akranar/daguerreo
C++ | 210 lines | 122 code | 56 blank | 32 comment | 0 complexity | 1efb9fb2009e7fa7dfdf5a9e3e749bac MD5 | raw file
Possible License(s): AGPL-3.0, LGPL-2.1, LGPL-3.0, GPL-2.0
  1#include "RenderContextPimpl_DIRECTX10.h"
  2#include "WindowData_DIRECTX10.h"
  3#include "../WindowPixelFormat.h"
  4#include "../RenderContext.h"
  5#include <iostream>
  6
  7
  8RenderContextPimpl::RenderContextPimpl(WindowData * window_data, const WindowPixelFormat * pixel_format)
  9{
 10	//	Initializing Direct3D
 11	//		1. Create ID3D10Device and IDXGISwapChain with D3D10CreateDeviceAndSwapChain.
 12	//		2. Create the Render Target View To Back Buffer.
 13	//		3. Set Viewport.
 14	//		4. Set Projection and View Matrices.
 15	
 16	//int width = 800;
 17	//int height = 600;
 18	int width = 1920;
 19	int height = 1080;
 20
 21	//1. Create ID3D10Device and IDXGISwapChain with D3D10CreateDeviceAndSwapChain {
 22	DXGI_SWAP_CHAIN_DESC swap_chain_description;
 23
 24	//Back buffer descriptions
 25	swap_chain_description.BufferDesc.Width = width; // use window�s client area dims
 26	swap_chain_description.BufferDesc.Height = height;
 27	swap_chain_description.BufferDesc.RefreshRate.Numerator = 60;
 28	swap_chain_description.BufferDesc.RefreshRate.Denominator = 1;
 29	swap_chain_description.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
 30	swap_chain_description.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
 31	swap_chain_description.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
 32
 33	// Sampling descriptions
 34	swap_chain_description.SampleDesc.Count = 1;
 35	swap_chain_description.SampleDesc.Quality = 0;
 36
 37	// Swap chain descriptions
 38	swap_chain_description.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
 39	swap_chain_description.BufferCount = 1;
 40	swap_chain_description.OutputWindow = window_data->GetWindowHandle();
 41	swap_chain_description.Windowed = true;
 42	swap_chain_description.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
 43	swap_chain_description.Flags = 0;
 44
 45
 46	UINT createDeviceFlags = 0;
 47	D3D10CreateDeviceAndSwapChain(0, D3D10_DRIVER_TYPE_HARDWARE, 0, createDeviceFlags, D3D10_SDK_VERSION, 
 48	&swap_chain_description, &swap_chain, &d3d_device);
 49
 50	
 51	//1. Create ID3D10Device and IDXGISwapChain with D3D10CreateDeviceAndSwapChain. }
 52	//2. Create the Render Target View To Back Buffer. {
 53	
 54
 55	
 56	ID3D10Texture2D* back_buffer;
 57	swap_chain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&back_buffer);
 58	d3d_device->CreateRenderTargetView(back_buffer, NULL, &render_target_view);
 59	back_buffer->Release();
 60
 61	D3D10_TEXTURE2D_DESC descDepth;
 62	descDepth.Width = width;
 63	descDepth.Height = height;
 64	descDepth.MipLevels = 1;
 65	descDepth.ArraySize = 1;
 66	descDepth.Format = DXGI_FORMAT_D32_FLOAT;
 67	descDepth.SampleDesc.Count = 1;
 68	descDepth.SampleDesc.Quality = 0;
 69	descDepth.Usage = D3D10_USAGE_DEFAULT;
 70	descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL;
 71	descDepth.CPUAccessFlags = 0;
 72	descDepth.MiscFlags = 0;
 73
 74	
 75	d3d_device->CreateTexture2D(&descDepth, NULL, &depth_stencil);
 76
 77	D3D10_DEPTH_STENCIL_VIEW_DESC descDSV;
 78	descDSV.Format = descDepth.Format;
 79	descDSV.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
 80	descDSV.Texture2D.MipSlice = 0;
 81
 82	d3d_device->CreateDepthStencilView(depth_stencil, &descDSV, &depth_stencil_view);
 83
 84	d3d_device->OMSetRenderTargets(1, &render_target_view, depth_stencil_view);
 85
 86	
 87	//2. Create the Render Target View To Back Buffer. }
 88	//3. Set Viewport. {
 89	
 90
 91	D3D10_VIEWPORT view_port;
 92	view_port.Width = width;
 93	view_port.Height = height;
 94	view_port.MinDepth = 0.0f;
 95	view_port.MaxDepth = 1.0f;
 96	view_port.TopLeftX = 0;
 97	view_port.TopLeftY = 0;
 98	 
 99	d3d_device->RSSetViewports(1, &view_port);
100
101	//3. Set Viewport. }
102}
103
104RenderContextPimpl::RenderContextPimpl(WindowData * window_data, const RenderContext * render_context)
105{
106	//	Initializing Direct3D
107	//		1. Create ID3D10Device and IDXGISwapChain with D3D10CreateDeviceAndSwapChain.
108	//		2. Create the Render Target View To Back Buffer.
109	//		3. Set Viewport.
110	//		4. Set Projection and View Matrices.
111	
112	//int width = 800;
113	//int height = 600;
114	int width = 1024;
115	int height = 768;
116
117	//1. Create ID3D10Device and IDXGISwapChain with D3D10CreateDeviceAndSwapChain {
118	DXGI_SWAP_CHAIN_DESC swap_chain_description;
119
120	//Back buffer descriptions
121	swap_chain_description.BufferDesc.Width = width; // use window�s client area dims
122	swap_chain_description.BufferDesc.Height = height;
123	swap_chain_description.BufferDesc.RefreshRate.Numerator = 60;
124	swap_chain_description.BufferDesc.RefreshRate.Denominator = 1;
125	swap_chain_description.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
126	swap_chain_description.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
127	swap_chain_description.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
128
129	// Sampling descriptions
130	swap_chain_description.SampleDesc.Count = 1;
131	swap_chain_description.SampleDesc.Quality = 0;
132
133	// Swap chain descriptions
134	swap_chain_description.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
135	swap_chain_description.BufferCount = 1;
136	swap_chain_description.OutputWindow = window_data->GetWindowHandle();
137	swap_chain_description.Windowed = true;
138	swap_chain_description.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
139	swap_chain_description.Flags = 0;
140
141
142	UINT createDeviceFlags = 0;
143	D3D10CreateDeviceAndSwapChain(0, D3D10_DRIVER_TYPE_HARDWARE, 0, createDeviceFlags, D3D10_SDK_VERSION, 
144	&swap_chain_description, &swap_chain, &d3d_device);
145
146	
147	//1. Create ID3D10Device and IDXGISwapChain with D3D10CreateDeviceAndSwapChain. }
148	//2. Create the Render Target View To Back Buffer. {
149	
150
151	
152	ID3D10Texture2D* back_buffer;
153	swap_chain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&back_buffer);
154	d3d_device->CreateRenderTargetView(back_buffer, NULL, &render_target_view);
155	back_buffer->Release();
156	
157
158
159	D3D10_TEXTURE2D_DESC descDepth;
160	descDepth.Width = width;
161	descDepth.Height = height;
162	descDepth.MipLevels = 1;
163	descDepth.ArraySize = 1;
164	descDepth.Format = DXGI_FORMAT_D32_FLOAT;
165	descDepth.SampleDesc.Count = 1;
166	descDepth.SampleDesc.Quality = 0;
167	descDepth.Usage = D3D10_USAGE_DEFAULT;
168	descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL;
169	descDepth.CPUAccessFlags = 0;
170	descDepth.MiscFlags = 0;
171
172	
173	d3d_device->CreateTexture2D(&descDepth, NULL, &depth_stencil);
174
175	D3D10_DEPTH_STENCIL_VIEW_DESC descDSV;
176	descDSV.Format = descDepth.Format;
177	descDSV.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
178	descDSV.Texture2D.MipSlice = 0;
179
180	d3d_device->CreateDepthStencilView(depth_stencil, &descDSV, &depth_stencil_view);
181
182	d3d_device->OMSetRenderTargets(1, &render_target_view, depth_stencil_view);
183
184	
185	//2. Create the Render Target View To Back Buffer. }
186	//3. Set Viewport. {
187	
188
189	D3D10_VIEWPORT view_port;
190	view_port.Width = width;
191	view_port.Height = height;
192	view_port.MinDepth = 0.0f;
193	view_port.MaxDepth = 1.0f;
194	view_port.TopLeftX = 0;
195	view_port.TopLeftY = 0;
196	 
197	d3d_device->RSSetViewports(1, &view_port);
198
199
200	//3. Set Viewport. }
201}
202
203RenderContextPimpl::~RenderContextPimpl()
204{
205	d3d_device->Release();
206	swap_chain->Release();
207	render_target_view->Release();
208	depth_stencil_view->Release();
209}
210