VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
renderTarget.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: Apache-2.0
2
// Copyright 2025-2026 Arnis Lektauers
3
//
4
// Created by Arnis Lektauers on 12.09.2025.
5
//
6
#pragma once
7
8
#include <unordered_set>
9
10
#include "
texture.h
"
11
12
namespace
visutwin::canvas
13
{
14
struct
RenderTargetOptions
15
{
16
GraphicsDevice
*
graphicsDevice
=
nullptr
;
17
18
Texture
*
colorBuffer
=
nullptr
;
19
20
std::vector<Texture*>
colorBuffers
;
21
22
Texture
*
depthBuffer
=
nullptr
;
23
24
bool
depth
=
false
;
25
26
int
face
= 0;
27
28
int
samples
= 1;
29
30
bool
stencil
=
false
;
31
32
bool
autoResolve
=
false
;
33
34
std::string
name
;
35
36
int
mipLevel
= 0;
37
38
bool
flipY
;
39
};
40
41
/*
42
* A render target is a rectangular rendering surface
43
*/
44
class
RenderTarget
45
{
46
public
:
47
explicit
RenderTarget
(
const
RenderTargetOptions
& options = {});
48
49
virtual
~RenderTarget
();
50
51
// Width of the render target in pixels
52
int
width
()
const
;
53
54
int
height
()
const
;
55
56
void
resize
(
int
width
,
int
height
);
57
58
Texture
*
colorBuffer
()
const
{
return
_colorBuffer; }
59
60
int
samples
()
const
{
return
_samples; }
61
62
bool
hasDepthBuffer
()
const
{
return
_depthBuffer !=
nullptr
; }
63
bool
hasDepth
()
const
{
return
_depth; }
64
65
int
colorBufferCount
()
const
{
return
_colorBuffers.size(); }
66
67
bool
hasMipmaps
()
const
{
return
_mipmaps; }
68
69
Texture
*
getColorBuffer
(
size_t
index)
const
;
70
71
bool
hasStencil
()
const
{
return
_stencil; }
72
73
int
mipLevel
()
const
{
return
_mipLevel; }
74
75
const
std::string&
name
()
const
{
return
_name; }
76
77
Texture
*
depthBuffer
()
const
{
return
_depthBuffer; }
78
bool
autoResolve
()
const
{
return
_autoResolve; }
79
80
// Cubemap face index (0-5). Used when rendering to a specific face of a cubemap texture.
81
int
face
()
const
{
return
_face; }
82
83
int
key
()
const
{
return
_id; }
84
85
protected
:
86
GraphicsDevice
*
device
()
const
{
return
_device; }
87
88
// Validates that all MRT color buffers have the same dimensions and settings
89
void
validateMrt
();
90
91
virtual
void
destroyFrameBuffers
() = 0;
92
virtual
void
createFrameBuffers
() = 0;
93
94
private
:
95
GraphicsDevice
* _device;
96
97
int
_mipLevel;
98
99
Texture
* _colorBuffer =
nullptr
;
100
101
std::vector<Texture*> _colorBuffers;
102
103
Texture
* _depthBuffer =
nullptr
;
104
105
int
_samples = 1;
106
107
bool
_mipmaps =
true
;
108
109
bool
_stencil;
110
111
std::string _name;
112
113
int
_id;
114
115
bool
_depth;
116
117
int
_face;
118
119
bool
_autoResolve;
120
121
bool
_flipY;
122
};
123
}
visutwin::canvas::GraphicsDevice
Abstract GPU interface for resource creation, state management, and draw submission.
Definition
graphicsDevice.h:239
visutwin::canvas::RenderTarget::height
int height() const
Definition
renderTarget.cpp:139
visutwin::canvas::RenderTarget::getColorBuffer
Texture * getColorBuffer(size_t index) const
Definition
renderTarget.cpp:178
visutwin::canvas::RenderTarget::device
GraphicsDevice * device() const
Definition
renderTarget.h:86
visutwin::canvas::RenderTarget::~RenderTarget
virtual ~RenderTarget()
Definition
renderTarget.cpp:117
visutwin::canvas::RenderTarget::destroyFrameBuffers
virtual void destroyFrameBuffers()=0
visutwin::canvas::RenderTarget::hasStencil
bool hasStencil() const
Definition
renderTarget.h:71
visutwin::canvas::RenderTarget::hasDepth
bool hasDepth() const
Definition
renderTarget.h:63
visutwin::canvas::RenderTarget::key
int key() const
Definition
renderTarget.h:83
visutwin::canvas::RenderTarget::validateMrt
void validateMrt()
Definition
renderTarget.cpp:186
visutwin::canvas::RenderTarget::colorBufferCount
int colorBufferCount() const
Definition
renderTarget.h:65
visutwin::canvas::RenderTarget::resize
void resize(int width, int height)
Definition
renderTarget.cpp:148
visutwin::canvas::RenderTarget::RenderTarget
RenderTarget(const RenderTargetOptions &options={})
Definition
renderTarget.cpp:17
visutwin::canvas::RenderTarget::depthBuffer
Texture * depthBuffer() const
Definition
renderTarget.h:77
visutwin::canvas::RenderTarget::samples
int samples() const
Definition
renderTarget.h:60
visutwin::canvas::RenderTarget::mipLevel
int mipLevel() const
Definition
renderTarget.h:73
visutwin::canvas::RenderTarget::autoResolve
bool autoResolve() const
Definition
renderTarget.h:78
visutwin::canvas::RenderTarget::createFrameBuffers
virtual void createFrameBuffers()=0
visutwin::canvas::RenderTarget::hasMipmaps
bool hasMipmaps() const
Definition
renderTarget.h:67
visutwin::canvas::RenderTarget::name
const std::string & name() const
Definition
renderTarget.h:75
visutwin::canvas::RenderTarget::hasDepthBuffer
bool hasDepthBuffer() const
Definition
renderTarget.h:62
visutwin::canvas::RenderTarget::width
int width() const
Definition
renderTarget.cpp:130
visutwin::canvas::RenderTarget::face
int face() const
Definition
renderTarget.h:81
visutwin::canvas::RenderTarget::colorBuffer
Texture * colorBuffer() const
Definition
renderTarget.h:58
visutwin::canvas::Texture
GPU texture resource supporting 2D, cubemap, volume, and array formats with mipmap management.
Definition
texture.h:57
visutwin::canvas
Definition
eventHandler.cpp:9
visutwin::canvas::RenderTargetOptions
Definition
renderTarget.h:15
visutwin::canvas::RenderTargetOptions::stencil
bool stencil
Definition
renderTarget.h:30
visutwin::canvas::RenderTargetOptions::depth
bool depth
Definition
renderTarget.h:24
visutwin::canvas::RenderTargetOptions::name
std::string name
Definition
renderTarget.h:34
visutwin::canvas::RenderTargetOptions::colorBuffer
Texture * colorBuffer
Definition
renderTarget.h:18
visutwin::canvas::RenderTargetOptions::colorBuffers
std::vector< Texture * > colorBuffers
Definition
renderTarget.h:20
visutwin::canvas::RenderTargetOptions::mipLevel
int mipLevel
Definition
renderTarget.h:36
visutwin::canvas::RenderTargetOptions::autoResolve
bool autoResolve
Definition
renderTarget.h:32
visutwin::canvas::RenderTargetOptions::flipY
bool flipY
Definition
renderTarget.h:38
visutwin::canvas::RenderTargetOptions::face
int face
Definition
renderTarget.h:26
visutwin::canvas::RenderTargetOptions::samples
int samples
Definition
renderTarget.h:28
visutwin::canvas::RenderTargetOptions::depthBuffer
Texture * depthBuffer
Definition
renderTarget.h:22
visutwin::canvas::RenderTargetOptions::graphicsDevice
GraphicsDevice * graphicsDevice
Definition
renderTarget.h:16
texture.h
platform
graphics
renderTarget.h
Generated by
1.16.1