Archive 17/01/2023.

Rendertarget - Could not lock texture on DirectX 9

Absyl

Hello,

I am trying to render a texture which I update every frame in code.

I am creating the rendertarget like so:

SharedPtr<Texture2D> renderTarget_(new Texture2D(context));
renderTarget_->SetSize(context_->GetSubsystem<Graphics>()->GetWidth(), context_->GetSubsystem<Graphics>()->GetHeight(), Graphics::GetRGBAFormat(), TEXTURE_RENDERTARGET);
renderTarget_->GetRenderSurface()->SetUpdateMode(SURFACE_UPDATEALWAYS);

Whenever I receive updated pixels I set the texture data:

renderTarget_->SetData(0, 
	0,
	0,
	context_->GetSubsystem<Graphics>()->GetWidth(),
	context_->GetSubsystem<Graphics>()->GetHeight(),
	buffer); // buffer is |width| * |height| * 4 bytes in size representing a BGRA image

Running this code with DirectX 9 renderer gives the following error at SetData()

Running the same code on Urho3D built with DirectX 11 works with no problem.
Other texture types work fine (TEXTURE_DYNAMIC for example).

What am I doing wrong here? I’d like to use DX9 if possible.

cadaver

If you want to SetData() to a texture manually frequently, do not create it as a rendertarget, but as a dynamic texture. Both rendering to a texture and setting its data manually aren’t compatible.

Absyl

Alright, I’ll use a dynamic texture as per your recommendation. Thanks.