void BackBuffer::CreateReductionTargets(ID3D11Device* device) { // Create the staging textures for reading back the reduced depth buffer for (uint32 i = 0; i < MaxReadbackLatency; ++i) m_ReductionStagingTextures[i].Initialize(device, 1, 1, DXGI_FORMAT_R16G16_UNORM); m_DepthReductionTargets.clear(); uint32 w = m_SurfaceDesc.Width; uint32 h = m_SurfaceDesc.Height; auto DispatchSize = [](uint32 tgSize, uint32 numElements) { uint32 dispatchSize = numElements / tgSize; dispatchSize += numElements % tgSize > 0 ? 1 : 0; return dispatchSize; }; while (w > 1 || h > 1) { w = DispatchSize(ReductionTGSize, w); h = DispatchSize(ReductionTGSize, h); RenderTarget2D rt; rt.Initialize(device, w, h, DXGI_FORMAT_R16G16_UNORM, 1, 1, 0, FALSE, TRUE); m_DepthReductionTargets.push_back(rt); } }
void MeshRenderer::OnResize(uint32 width, uint32 height) { depthReductionTargets.clear(); uint32 w = width; uint32 h = height; while(w > 1 || h > 1) { w = DispatchSize(ReductionTGSize, w); h = DispatchSize(ReductionTGSize, h); RenderTarget2D rt; rt.Initialize(device, w, h, DXGI_FORMAT_R16G16_UNORM, 1, 1, 0, false, true); depthReductionTargets.push_back(rt); } }
//----------------------------------------------------------------------- void GraphicsContextDirect3D11::SetTexture(int index, RenderTarget2D & textureIn) { POMDOG_ASSERT(index >= 0); POMDOG_ASSERT(index < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT); POMDOG_ASSERT(index < static_cast<int>(textureResourceViews.size())); POMDOG_ASSERT(textureIn.NativeRenderTarget2D() != nullptr); auto texture = static_cast<RenderTarget2DDirect3D11*>(textureIn.NativeRenderTarget2D()); POMDOG_ASSERT(texture != nullptr); POMDOG_ASSERT(texture == dynamic_cast<RenderTarget2DDirect3D11*>(textureIn.NativeRenderTarget2D())); textureResourceViews[index] = texture->GetShaderResourceView(); POMDOG_ASSERT(deviceContext); deviceContext->PSSetShaderResources(0, 1, &textureResourceViews[index]); }
//----------------------------------------------------------------------- void GraphicsContextGL4::SetTexture(int textureUnit, RenderTarget2D & textureIn) { POMDOG_ASSERT(!textures.empty()); POMDOG_ASSERT(textureUnit >= 0); POMDOG_ASSERT(textureUnit < static_cast<int>(textures.size())); constexpr GLenum textureType = GL_TEXTURE_2D; if (textures[textureUnit] && *textures[textureUnit] != textureType) { // Unbind texture SetTexture(textureUnit); } textures[textureUnit] = textureType; POMDOG_ASSERT(textureIn.NativeRenderTarget2D()); auto renderTargetGL4 = dynamic_cast<RenderTarget2DGL4*>(textureIn.NativeRenderTarget2D()); POMDOG_ASSERT(renderTargetGL4 != nullptr); ApplyTexture2D(textureUnit, renderTargetGL4->GetTextureHandle()); }