У меня проблема при рисовании моего куба в окне. Я не вижу графику в окне. Я вижу следующие предупреждающие сообщения в visual studio:
D3D11 WARNING: ID3D11DeviceContext::DrawIndexed: The Pixel Shader expects a Render Target View bound to slot 0, but the Render Target View was unbound during a call to Present. A successful Present call for DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL SwapChains unbinds backbuffer 0 from all GPU writeable bind points. [ EXECUTION WARNING #3146082:
D3D11 WARNING: ID3D11DeviceContext::DrawIndexed: The Pixel Shader expects a Render Target View bound to slot 0, but none is bound. This is OK, as writes of an unbound Render Target View are discarded. It is also possible the developer knows the data will not be used anyway. This is only a problem if the developer actually intended to bind a Render Target View here. [ EXECUTION WARNING #3146081: DEVICE_DRAW_RENDERTARGETVIEW_NOT_SET]
Я создал swapchain
, используя следующий API:
virtual IDXGISwapChain* SwapChain(HWND wnd)
{
HRESULT hr = S_OK;
IDXGISwapChain* swapchain = nullptr;
DXGI_SWAP_CHAIN_DESC desc;
ZeroMemory(&desc, sizeof(DXGI_SWAP_CHAIN_DESC));
desc.Windowed = TRUE; // Sets the initial state of full-screen mode.
desc.BufferCount = 2;
desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.SampleDesc.Count = 1; //multisampling setting
desc.SampleDesc.Quality = 0; //vendor-specific flag
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
desc.OutputWindow = wnd;
// Create the DXGI device object to use in other factories, such as Direct2D.
IDXGIDevice3* dxgiDevice;
hr = device_->QueryInterface(__uuidof(IDXGIDevice3), reinterpret_cast<void**>(&dxgiDevice));
if (FAILED(hr))
return nullptr;
// Create swap chain.
IDXGIAdapter* adapter;
IDXGIFactory* factory;
hr = dxgiDevice->GetAdapter(&adapter);
dxgiDevice->Release();
if (FAILED(hr))
return nullptr;
adapter->GetParent(IID_PPV_ARGS(&factory));
hr = factory->CreateSwapChain(device_, &desc, &swapchain);
adapter->Release();
factory->Release();
return swapchain;
}
Визуализация цели связана с помощью вызова:
m_d3dDevice.Context()->OMSetRenderTargets(1, &m_pRenderTarget, , _pDepthStencilView);
Present
реализован как:
swap_chain->Present(0, 0);
Код шейдера:
cbuffer ConstantBuffer : register(b0)
{
matrix World;
matrix View;
matrix Projection;
float4 vLightDir[2];
float4 vLightColor[2];
float4 vOutputColor;
}
struct VS_INPUT
{
float4 Pos : POSITION;
float3 Norm : NORMAL;
};
struct PS_INPUT
{
float4 Pos : SV_POSITION;
float3 Norm : TEXCOORD0;
};
PS_INPUT VS(VS_INPUT input)
{
PS_INPUT output = (PS_INPUT)0;
output.Pos = mul(input.Pos, World);
output.Pos = mul(output.Pos, View);
output.Pos = mul(output.Pos, Projection);
output.Norm = mul(float4(input.Norm, 1), World).xyz;
return output;
}
float4 PS(PS_INPUT input) : SV_Target
{
float4 finalColor = 0;
//do NdotL lighting for 2 lights
for (int i = 0; i < 2; i++)
{
finalColor += saturate(dot((float3)vLightDir[i],input.Norm) * vLightColor[i]);
}
finalColor.a = 1;
return finalColor;
}
float4 PSSolid(PS_INPUT input) : SV_Target
{
return vOutputColor;
}