opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
liboscar
graphics
shared_color_render_buffer.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <
liboscar/graphics/anti_aliasing_level.h
>
4
#include <
liboscar/graphics/texture_dimensionality.h
>
5
#include <
liboscar/maths/vector.h
>
6
7
#include <memory>
8
9
namespace
osc
{
struct
ColorRenderBufferParams; }
10
11
namespace
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.
48
class
SharedColorRenderBuffer
final
{
49
public
:
50
explicit
SharedColorRenderBuffer
();
51
explicit
SharedColorRenderBuffer
(
const
ColorRenderBufferParams
&);
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
56
SharedColorRenderBuffer
clone
()
const
;
57
58
// Returns the dimensions of the buffer in physical pixels.
59
Vector2i
pixel_dimensions
()
const
;
60
TextureDimensionality
dimensionality
()
const
;
61
AntiAliasingLevel
anti_aliasing_level
()
const
;
62
63
class
ColorRenderBuffer
;
64
const
ColorRenderBuffer
&
impl
()
const
{
return
*impl_; }
65
private
:
66
friend
class
Camera
;
67
friend
class
GraphicsBackend
;
68
friend
class
RenderTexture
;
69
70
explicit
SharedColorRenderBuffer
(
const
ColorRenderBuffer
&);
71
72
bool
has_been_rendered_to()
const
;
73
74
std::shared_ptr<ColorRenderBuffer> impl_;
75
};
76
}
anti_aliasing_level.h
osc::AntiAliasingLevel
Definition
anti_aliasing_level.h:11
osc::Camera
Definition
camera.h:27
osc::RenderTexture
Definition
render_texture.h:18
osc::SharedColorRenderBuffer
Definition
shared_color_render_buffer.h:48
osc::SharedColorRenderBuffer::SharedColorRenderBuffer
SharedColorRenderBuffer()
osc::SharedColorRenderBuffer::impl
const ColorRenderBuffer & impl() const
Definition
shared_color_render_buffer.h:64
osc::SharedColorRenderBuffer::GraphicsBackend
friend class GraphicsBackend
Definition
shared_color_render_buffer.h:67
osc::SharedColorRenderBuffer::clone
SharedColorRenderBuffer clone() const
osc::SharedColorRenderBuffer::pixel_dimensions
Vector2i pixel_dimensions() const
osc::SharedColorRenderBuffer::dimensionality
TextureDimensionality dimensionality() const
osc::SharedColorRenderBuffer::operator==
friend bool operator==(const SharedColorRenderBuffer &, const SharedColorRenderBuffer &)=default
osc::SharedColorRenderBuffer::SharedColorRenderBuffer
SharedColorRenderBuffer(const ColorRenderBufferParams &)
osc::SharedColorRenderBuffer::anti_aliasing_level
AntiAliasingLevel anti_aliasing_level() const
osc::Vector< int, 2 >
osc
Definition
custom_decoration_generator.h:5
osc::to
constexpr U to(T &&value)
Definition
conversion.h:56
osc::TextureDimensionality
TextureDimensionality
Definition
texture_dimensionality.h:5
osc::ColorRenderBufferParams
Definition
color_render_buffer_params.h:10
texture_dimensionality.h
vector.h
Generated by
1.9.8