Thank you for your help.I created a swap chain on DirectX 12.
Since then, I have encountered the GetCurrentBackBufferIndex not returning 0 or 1.
The operating system used is Windows 10 64bit
The compiler is visual studio 2019
The code is as follows:
window and create a hwnd
void Window::CreateGameWindow (WNDCLASSEX&windowClass)
{
auto result=CoInitializeEx(nullptr,COINIT_MULTITHREADED);
m_windowClass.hInstance=GetModuleHandle(nullptr);
m_windowClass.cbSize=sizeof(WNDCLASSEX);
m_windowClass.lpfnWndProc=(WNDPROC) Windowprocedure;
m_windowClass.lpszClassName="DirectX12 Sample";
RegisterClassEx(&m_windowClass);
RECT wrc={};
wrc.left = 0;
wrc.top = 0;
wrc.right = window_width;
wrc.bottom=window_height;
AdjustWindowRect (&wrc, WS_OVERLAPPEDWINDOW, false);
m_hwnd = CreateWindow(
m_windowClass.lpszClassName,
"DirectX12",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
wrc.right-wrc.left,
wrc.bottom-wrc.top,
nullptr,
nullptr,
m_windowClass.hInstance,
nullptr
);
ShowWindow(m_hwnd,SW_SHOW); // Window Display
}
Generate swap chains
DXGI_SWAP_CHAIN_DESC1swapchainDesc={};
swapchainDesc.Width=window.window_width;
swapchainDesc.Height=window.window_height;
swapchainDesc.Format=DXGI_FORMAT_R8G8B8A8_UNORM;
swapchainDesc.Stereo=false;
swapchainDesc.SampleDesc.Count=1;
swapchainDesc.SampleDesc.Quality=0;
swapchainDesc.BufferUsage=DXGI_USAGE_BACK_BUFFER;
swapchainDesc.BufferCount=2;
swapchainDesc.Scaling=DXGI_SCALING_STRETCH;
swapchainDesc.SwapEffect=DXGI_SWAP_EFFECT_FLIP_DISCARD;
swapchainDesc.AlphaMode=DXGI_ALPHA_MODE_UNSPECIFIED;
swapchainDesc.Flags=DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
auto result=m_dxgifactory->CreateSwapChainForHwnd(
m_cqueue.Get(),
hwnd,
&swapchainDesc,
nullptr,
nullptr,
(IDXGISwapChain1**) (m_swapchain.ReleaseAndGetAddressOf())
);
//Tick processing. call backbuffer index
autoBbufferIndex=m_swapchain->GetCurrentBackBufferIndex();
Swapchain generation seems to have failed, but it returned S_OK at generation, and there may be other factors.
I would appreciate it if you could let me know if there are any factors that make the swap chain apparently successful.
c++
Do you mean GetCurrentBackBufferIndex
is IDXGISwapChain3::GetCurrentBackBufferIndex
? If that's the case,
auto result=m_dxgifactory->CreateSwapChainForHwnd(
m_cqueue.Get(),
hwnd,
&swapchainDesc,
nullptr,
nullptr,
(IDXGISwapChain1**) (m_swapchain.ReleaseAndGetAddressOf())
);
I'm concerned that I'm forcing a C-format cast here.
ComPtr<IDXGISwapChain1>swapchain1;
auto result=m_dxgifactory->CreateSwapChainForHwnd(
m_cqueue.Get(),
hwnd,
&swapchainDesc,
nullptr,
nullptr,
&swapChain1
);
result=swapchain1.As(&m_swapchain);
How about casting with IUnknown::QueryInterface
sometimes?
© 2024 OneMinuteCode. All rights reserved.