So I create a render to texture with linked depth target like this:
impRenderTexture_ = new Texture2D(context_);
impRenderTexture_->SetSize(segment_res,
segment_res,
Graphics::GetRGBAFormat(),
Urho3D::TEXTURE_RENDERTARGET,
0);
impRenderTextureDepth_ = new Texture2D(context_);
impRenderTextureDepth_->SetSize(segment_res,
segment_res,
Graphics::GetDepthStencilFormat(),
Urho3D::TEXTURE_DEPTHSTENCIL,
0);
impRenderPath_ = new RenderPath();
impRenderPath_->Load(
GetSubsystem<ResourceCache>()
->GetResource<XMLFile>("RenderPaths/ImpostorForwardDepth.xml"));
RenderSurface* renderSurface = impRenderTexture_->GetRenderSurface();
impViewport_ = new Viewport(context_,
impScene_,
impCameraNode_->GetComponent<Camera>());
impViewport_->SetRenderPath(impRenderPath_);
renderSurface->SetUpdateMode(Urho3D::SURFACE_MANUALUPDATE);
renderSurface->SetLinkedDepthStencil(
impRenderTextureDepth_->GetRenderSurface());
renderSurface->SetViewport(0, impViewport_);
Then I start rendering it:
impRenderTexture_->GetRenderSurface()->QueueUpdate();
SubscribeToEvent (E_ENDVIEWRENDER,
URHO3D_HANDLER(Impostor, HandleRenderDone));
And when I recieve event I read texture data:
impRenderTexture_->GetData(0, my_buffer);
And it works good: my_buffer now contains whole the rendered frame data.
But when I try to read depth data like this:
auto surface = impRenderTexture_->GetRenderSurface()->GetLinkedDepthStencil();
Texture2D* tx2d = reinterpret_cast<Texture2D*>(tex->GetParentTexture());
// tx2d now actually points to the impRenderTextureDepth_ that we created
// and linked..
tx2d->GetData(0, my_depth_buffer);
But GetData() fails like this (in OGLTexture2D.cpp:303):
bool Texture2D::GetData(unsigned level, void* dest) const
{
if (!object_.name_ || !graphics_)
{
//<----------- FAILS HERE :( ------------>
URHO3D_LOGERROR("No texture created, can not get data");
return false;
}
...
Am I missing something on how it’s done?
Things I tried to no result so far:
- Let the engine create depth buffer automatically – don’t seem to have any way to access it then
SOLUTION is elaborated a bit in post #3