Hehe, sure! I always try to post as little code as possible but maybe this time it was a little bit to little;)
First, this are the variables related to the problem:
ID3D10Texture2D* envMap[5]; // the 5 face texturesID3D10Texture2D* envMapDepthStencil; // Depth stencil ID3D10RenderTargetView* envMapRTView[5]; // 5 render target views, each view is used for 1 face of the env mapID3D10DepthStencilView* envMapDepthStencilView; // Depth stencil view for environment mapID3D10ShaderResourceView* envMapShaderView[5];
Second, this is my init code (I guess its not relevant, but I post it for completeness):
// Depth StencilD3D10_TEXTURE2D_DESC dstex;dstex.Width = ENVMAPSIZE;dstex.Height = ENVMAPSIZE;dstex.MipLevels = 1;dstex.ArraySize = 1; dstex.SampleDesc.Count = 1;dstex.SampleDesc.Quality = 0;dstex.Format = DXGI_FORMAT_D32_FLOAT;dstex.Usage = D3D10_USAGE_DEFAULT;dstex.BindFlags = D3D10_BIND_DEPTH_STENCIL;dstex.CPUAccessFlags = 0;dstex.MiscFlags = 0;d3d10device->CreateTexture2D( &dstex, NULL, &envMapDepthStencil ); // Create the depth stencil viewD3D10_DEPTH_STENCIL_VIEW_DESC DescDS;DescDS.Format = DXGI_FORMAT_D32_FLOAT;DescDS.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;DescDS.Texture2DArray.FirstArraySlice = 0;DescDS.Texture2DArray.ArraySize = 1;DescDS.Texture2DArray.MipSlice = 0;d3d10device->CreateDepthStencilView( envMapDepthStencil, &DescDS, &envMapDepthStencilView );// Create the 5 cube map facesdstex.Format = DXGI_FORMAT_R16G16B16A16_UNORM; dstex.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;dstex.MiscFlags = 0;dstex.MipLevels = 1;for(int i=0; i < 5; i++) d3d10device->CreateTexture2D( &dstex, NULL, &envMap );// Create the 5 Render Target ViewsD3D10_RENDER_TARGET_VIEW_DESC DescRT;DescRT.Format = dstex.Format;DescRT.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;DescRT.Texture2D.MipSlice = 0;for( int i = 0; i < 5; ++i ) d3d10device->CreateRenderTargetView( envMap, &DescRT, &envMapRTView); // Create the 5 Shader Resource ViewsD3D10_SHADER_RESOURCE_VIEW_DESC desc;desc.Format = dstex.Format;desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;desc.Texture2D.MipLevels = 1; desc.Texture2D.MostDetailedMip = 0;for(int i=0; i < 5; i++) d3d10device->CreateShaderResourceView(envMap, &desc, &envMapShaderView)
Now the update code which renders into the 5 faces:
void update() { // Save the old RT and DS buffer views ID3D10RenderTargetView* oldRTViews[1] = { NULL }; ID3D10DepthStencilView* oldDSView = NULL; d3d10device->OMGetRenderTargets(1, oldRTViews, &oldDSView); // Save the old viewport D3D10_VIEWPORT oldViewport; UINT numViewports = 1; d3d10device->RSGetViewports(&numViewports, &oldViewport); // Set a new viewport for rendering to cube map D3D10_VIEWPORT SMVP; SMVP.Height = ENVMAPSIZE; SMVP.Width = ENVMAPSIZE; SMVP.MinDepth = 0; SMVP.MaxDepth = 1; SMVP.TopLeftX = 0; SMVP.TopLeftY = 0; d3d10device->RSSetViewports( 1, &SMVP ); UINT stride = sizeof(SkyBoxVertex); UINT offset = 0; d3d10device->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset); d3d10device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); d3d10device->IASetInputLayout(vertexLayout); opticalDepthLUTSC->SetResource(lookupTableView); d3d10device->RSSetState(rasterizerState); techniqueUpdate->GetPassByIndex(0)->Apply(0); for(int view = 0; view < 5; ++view) { float clearColor[4] = { 1.0, 0.0, 0.0, 0.0 }; d3d10device->ClearRenderTargetView(envMapRTView[view], clearColor); d3d10device->ClearDepthStencilView(envMapDepthStencilView, D3D10_CLEAR_DEPTH, 1.0, 0); ID3D10RenderTargetView* RTViews[1] = { envMapRTView[view] }; d3d10device->OMSetRenderTargets(1, RTViews, envMapDepthStencilView); d3d10device->Draw(4, 4 * view); } // Restore old view port d3d10device->RSSetViewports(1, &oldViewport); // Restore old RT and DS buffer views d3d10device->OMSetRenderTargets(1, oldRTViews, oldDSView); SAFE_RELEASE(oldRTViews[0]); SAFE_RELEASE(oldDSView);
As you can see first I save the old render target and depth stencil, then I set a new viewport, set some stats and then I enter the loop. Inside the loop I render into envMapRTView, which is a RenderTargetView onto the 5 face textures.
After the loop I restore the old settings and restore the saved RenderTarget (Maybe here is a problem?)
Last my render code:
render() { UINT stride = sizeof(SkyBoxVertex); UINT offset = 0; d3d10device->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset); d3d10device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); d3d10device->IASetInputLayout(vertexLayout); d3d10device->RSSetState(rasterizerState); for(int i=0; i < 5; i++) { skyBoxFaceTextureSC->SetResource(envMapShaderView); techniqueRender->GetPassByIndex(0)->Apply(0); d3d10device->Draw(4, 4*i); } }
Inside the loop I render the 5 faces. First I set the current face texture and then I render 4 vertices.
If I comment out the first line of the loop (skyBoxFaceTextureSC->SetResource(envMapShaderView
);), then I dont get the warning!
My main programm just calls update and then render in a loop:
g_skyBox->update();
g_skyBox->render();
Maybe you have an idea what could be the problem. Thanks for the help!