Open hadronized opened 5 years ago
We want to be able to write several kinds of renderers:
ViewportRenderer
, that would enable us to perform a render per viewport fragment.ForwardRenderer
, that would enable us to render 3D objects with materials.WhateverRenderer
.The main challenge is to define what a renderer is so that people can create their own and what’s their public interface.
A renderer is a pipeline that displays images. Renderers can output to either one or many images. Those images are called render targets. A render target cannot be inspected as-is and one must use a method to get access to what it contains, if ever needed. Also, a render target should always represent a stream of rasterized fragments, not the fragments themselves.
So, to sum up:
The render::output::OutputType
trait is a good candidate to represent what fragments can have as properties. Render targets are just then an aggregation of of outputs.
Then, a renderer. Renderers must have their own trait. They are like functions that output into render targets:
trait Renderer {
type Input;
type Targets: RenderTargets;
fn render(&self, input: Input) -> Self::Targets;
}
The render targets then must be able to be carried around to other renderers… or ultimately, to the screen.
In order to render to the screen, a renderer must use a special render target: Backbuffer
. Rendering to that target will perform a draw that will show up on the screen.