19 ERROR(
"SwapChain",
"init",
"Invalid window handle. (m_hWnd is nullptr)");
26 unsigned int createDeviceFlags = 0;
28 createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
31 D3D_DRIVER_TYPE driverTypes[] = {
32 D3D_DRIVER_TYPE_HARDWARE,
34 D3D_DRIVER_TYPE_REFERENCE,
36 unsigned int numDriverTypes = ARRAYSIZE(driverTypes);
38 D3D_FEATURE_LEVEL featureLevels[] = {
39 D3D_FEATURE_LEVEL_11_0,
40 D3D_FEATURE_LEVEL_10_1,
41 D3D_FEATURE_LEVEL_10_0,
43 unsigned int numFeatureLevels = ARRAYSIZE(featureLevels);
46 for (
unsigned int driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++) {
47 D3D_DRIVER_TYPE driverType = driverTypes[driverTypeIndex];
48 hr = D3D11CreateDevice(
nullptr,
60 MESSAGE(
"SwapChain",
"init",
"Device created successfully.");
66 ERROR(
"SwapChain",
"init",
67 (
"Failed to create D3D11 device. HRESULT: " + std::to_string(hr)).c_str());
73 hr = device.
m_device->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM,
77 ERROR(
"SwapChain",
"init",
78 (
"MSAA not supported or invalid quality level. HRESULT: " + std::to_string(hr)).c_str());
83 DXGI_SWAP_CHAIN_DESC sd;
84 memset(&sd, 0,
sizeof(sd));
86 sd.BufferDesc.Width = window.
m_width;
87 sd.BufferDesc.Height = window.
m_height;
88 sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
89 sd.BufferDesc.RefreshRate.Numerator = 60;
90 sd.BufferDesc.RefreshRate.Denominator = 1;
91 sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
92 sd.OutputWindow = window.
m_hWnd;
94 sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
101 ERROR(
"SwapChain",
"init",
102 (
"Failed to query IDXGIDevice. HRESULT: " + std::to_string(hr)).c_str());
108 ERROR(
"SwapChain",
"init",
109 (
"Failed to get IDXGIAdapter. HRESULT: " + std::to_string(hr)).c_str());
116 ERROR(
"SwapChain",
"init",
117 (
"Failed to get IDXGIFactory. HRESULT: " + std::to_string(hr)).c_str());
125 ERROR(
"SwapChain",
"init",
126 (
"Failed to create swap chain. HRESULT: " + std::to_string(hr)).c_str());
131 hr =
m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D),
132 reinterpret_cast<void**
>(&backBuffer));
134 ERROR(
"SwapChain",
"init",
135 (
"Failed to get back buffer. HRESULT: " + std::to_string(hr)).c_str());
163 ERROR(
"SwapChain",
"present",
164 (
"Failed to present swap chain. HRESULT: " + std::to_string(hr)).c_str());
167 ERROR(
"SwapChain",
"present",
"Swap chain is not initialized.");
174 ERROR(
"SwapChain",
"resizeBuffers",
"Swap chain is not initialized.");
188 ERROR(
"SwapChain",
"resizeBuffers",
189 (
"ResizeBuffers failed. HRESULT: " + std::to_string(hr)).c_str());
199 ERROR(
"SwapChain",
"getBackBuffer",
"Swap chain is not initialized.");
205 0, __uuidof(ID3D11Texture2D),
206 reinterpret_cast<void**
>(&backBuffer)
210 ERROR(
"SwapChain",
"getBackBuffer",
211 (
"Failed to get back buffer. HRESULT: " + std::to_string(hr)).c_str());
Declara la API de DeviceContext dentro del subsistema Core.
Declara la API de Device dentro del subsistema Core.
#define MESSAGE(classObj, method, state)
#define ERROR(classObj, method, errorMSG)
Declara la API de SwapChain dentro del subsistema Core.
Declara la API de Texture dentro del subsistema Core.
Declara la API de Window dentro del subsistema Core.
ID3D11DeviceContext * m_deviceContext
Puntero al contexto inmediato de Direct3D 11.
Encapsula un ID3D11Device y facilita la creación de recursos gráficos en Direct3D 11.
ID3D11Device * m_device
Puntero al dispositivo Direct3D 11.
HRESULT init(Device &device, DeviceContext &deviceContext, Texture &backBuffer, Window window)
Inicializa el Swap Chain y obtiene el back buffer.
void present()
Presenta el back buffer en pantalla.
IDXGISwapChain * m_swapChain
Objeto principal del Swap Chain en Direct3D 11.
void destroy()
Libera todos los recursos asociados al Swap Chain.
IDXGIFactory * m_dxgiFactory
Interfaz DXGI para la fábrica (creación de swap chains).
unsigned int m_qualityLevels
Niveles de calidad soportados para la configuración de MSAA.
HRESULT resizeBuffers(unsigned int width, unsigned int height)
IDXGIDevice * m_dxgiDevice
Interfaz DXGI para el dispositivo.
HRESULT getBackBuffer(Texture &backBuffer)
IDXGIAdapter * m_dxgiAdapter
Interfaz DXGI para el adaptador (GPU).
D3D_FEATURE_LEVEL m_featureLevel
Nivel de características de Direct3D soportado por el dispositivo.
unsigned int m_sampleCount
Número de muestras para MSAA.
Encapsula una textura 2D en Direct3D 11, incluyendo su recurso y vista como Shader Resource.
Encapsula la creacion y administracion de la ventana principal de Win32.
unsigned int m_width
Ancho actual del area cliente.
unsigned int m_height
Alto actual del area cliente.
HWND m_hWnd
Handle de la ventana nativa.