Пример #1
0
void RenderTargetD3D9::setRenderState( const RenderState & rs)
{
    //矩阵状态
    setWorldMatrix( rs.m_mtxWorld);
    setViewMatrix(rs.m_mtxView);
    setProjectionMatrix( rs.m_mtxProjection);

    //背面拣选
    setCullingMode(rs.m_cullingMode);

    //光照参数
    setLightingEnabled(rs.m_bLightingEnabled);

    //深度检测
    setDepthBufferCheckEnabled(rs.m_bDepthCheckEnabled);
    setDepthBufferFunction(rs.m_DepthBufferFunction);
    setDepthBufferWriteEnabled(rs.m_bDepthWriteEnabled);
}
Пример #2
0
void RenderDeviceD3D::initialize()
{
	int width = m_Width;
	int height = m_Height;

	HRESULT hr;

	// Init the render target
    ID3D11Texture2D *pBackBuffer;
    m_Swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer);

    m_Device->CreateRenderTargetView(pBackBuffer, NULL, &m_RenderTargetView);
    pBackBuffer->Release();

	// Depth buffer
	D3D11_TEXTURE2D_DESC descDepth;
    ZeroMemory( &descDepth, sizeof(descDepth) );
    descDepth.Width = width;
    descDepth.Height = height;
    descDepth.MipLevels = 1;
    descDepth.ArraySize = 1;
    descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
    descDepth.SampleDesc.Count = 1;
    descDepth.SampleDesc.Quality = 0;
    descDepth.Usage = D3D11_USAGE_DEFAULT;
    descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
    descDepth.CPUAccessFlags = 0;
    descDepth.MiscFlags = 0;
    
	hr = m_Device->CreateTexture2D( &descDepth, NULL, &m_DepthStencil );
	if (FAILED(hr)) {
		return;
	}


    D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
    ZeroMemory( &descDSV, sizeof(descDSV) );
    descDSV.Format = descDepth.Format;
    descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
    descDSV.Texture2D.MipSlice = 0;
    
	hr = m_Device->CreateDepthStencilView( m_DepthStencil, &descDSV, &m_DepthStencilView );
	if (hr == S_FALSE) {
		std::cerr << "Depth buffer problem" << std::endl;
	} else if (FAILED(hr)) {
		return;
	}

	setDepthStencilMode(DEPTH);
	setBlendingMode(NO_BLENDING);    
	setCullingMode(NO_CULLING);

	// Set the viewport
    D3D11_VIEWPORT viewport;
    ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));

    viewport.TopLeftX = 0;
    viewport.TopLeftY = 0;
    viewport.Width = width;
    viewport.Height = height;
	viewport.MinDepth = 0.0f;
	viewport.MaxDepth = 1.0f;

    m_DeviceContext->RSSetViewports(1, &viewport);

	bindBackBuffer();
}