opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
shared_color_render_buffer.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <memory>
8
9namespace osc { struct ColorRenderBufferParams; }
10
11namespace osc
12{
13 // A render buffer that's shareable between `Material`s, `RenderTarget`s,
14 // and `RenderTexture`s.
15 //
16 // Unlike most of `osc`'s graphics classes, this one _doesn't_ have value
17 // semantics. Instead, it should be thought of as a `std::shared_ptr<RenderBuffer>`. The
18 // reason for this change of style is to support typical use-cases, such as:
19 //
20 // - Calling code allocates a `RenderTexture` (i.e. color + depth `RenderBuffer`s)
21 // (owners: `RenderTexture`)
22 //
23 // - Calling code wants to render to only the color part of the `RenderTexture`, so it
24 // creates a `RenderTarget` that points to the `RenderTexture`'s color `RenderBuffer`
25 // (owners: `RenderTexture`, `RenderTarget`)
26 //
27 // - After a render pass to the `RenderTarget`, calling code then wants to sample from
28 // the `RenderBuffer` in a downstream pass (e.g. for deferred shading, or similar), so
29 // the code sets the `RenderBuffer` in a `Material` or `MaterialPropertyBlock`
30 // (owners: `RenderTexture`, `RenderTarget`, `Material`)
31 //
32 // You might (rightfully) be thinking that the last step should be solved by explicitly
33 // blitting the `RenderBuffer` to (e.g.) a `Texture2D`, followed by assigning that `Texture2D`
34 // to the `Material`. However, in typical multi-frame rendering operations that potentially
35 // allocates an additional `Texture2D`, because the calling code would have to:
36 //
37 // - First blit the `RenderBuffer` to a new `Texture2D`
38 // - Then assign the new `Texture2D` over the old one present in the `Material` from the
39 // last frame
40 //
41 // The second step is problematic, because it implies there exists a point in time where
42 // there's two instances of `Texture2D` hanging around. Callers would have to explicitly
43 // remember to `unset` the `Texture2D` after sampling it in the downstream `Material`, which
44 // is a pain in the ass to remember. Whereas `SharedRenderBuffer`s just keep everything as
45 // shared references and it's assumed that the calling code knows when/where to share it.
46 // This also makes it easier for graph traversal algorithms to figure out the dependency
47 // chains between render passes.
49 public:
52
53 friend bool operator==(const SharedColorRenderBuffer&, const SharedColorRenderBuffer&) = default;
54
55 // returns an independent (as in, not-shared) copy of the underlying render buffer data
57
58 // Returns the dimensions of the buffer in physical pixels.
62
64 const ColorRenderBuffer& impl() const { return *impl_; }
65 private:
66 friend class Camera;
67 friend class GraphicsBackend;
68 friend class RenderTexture;
69
71
72 bool has_been_rendered_to() const;
73
74 std::shared_ptr<ColorRenderBuffer> impl_;
75 };
76}
Definition anti_aliasing_level.h:11
Definition camera.h:27
Definition render_texture.h:18
Definition shared_color_render_buffer.h:48
const ColorRenderBuffer & impl() const
Definition shared_color_render_buffer.h:64
friend class GraphicsBackend
Definition shared_color_render_buffer.h:67
SharedColorRenderBuffer clone() const
Vector2i pixel_dimensions() const
TextureDimensionality dimensionality() const
friend bool operator==(const SharedColorRenderBuffer &, const SharedColorRenderBuffer &)=default
SharedColorRenderBuffer(const ColorRenderBufferParams &)
AntiAliasingLevel anti_aliasing_level() const
Definition custom_decoration_generator.h:5
constexpr U to(T &&value)
Definition conversion.h:56
TextureDimensionality
Definition texture_dimensionality.h:5
Definition color_render_buffer_params.h:10