pioneerspacesim/pioneer — pull request #2356 by Luomu (2013-07-07 01:24:09+00:00)
Title: Render targets

Basic rendertarget framework, and implementation for the GL2 renderer. Not used anywhere yet.

1 create a target:

```
Graphics::RenderTargetDesc rtd(256, 256,
Graphics::TEXTURE_RGB_888, //color buffer format
Graphics::TEXTURE_DEPTH, //request a depth buffer, if you want depth testing to work
false); //depth buffer will not be accessible as a texture

Graphics::RenderTarget *renderTarget = renderer->CreateRenderTarget(rtd)
```

2 render to the target

```
renderer->SetRenderTarget(renderTarget);
//set viewport, clear depth, render some stuff
renderer->SetRenderTarget(0); //resume rendering to screen
```

3 use the texture

```
someMaterial->texture0 = renderTarget->GetColorTexture();
```

Alternative: request a RT without a color texture, and attach one later. For postprocessing you may want to create just one target and keep swapping the attachments.
```
RenderTargetDesc rtd(800, 600, Graphics::TEXTURE_NONE, Graphics::TEXTURE_NONE, false);
rt = renderer->CreateRenderTarget(rtd);
...
//later
rt->SetColorTexture(texture0);
//even later
rt->SetColorTexture(texture1);
etc.
```