VTK  9.4.20241218
FrameBuffer.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3#pragma once
4
5#include "../Types.h"
6
7#include "vtkLogger.h"
8
9#include <VisRTX.h>
10#include <cassert>
11
12namespace RTW
13{
14VTK_ABI_NAMESPACE_BEGIN
15 class FrameBuffer : public Object
16 {
17 friend class Renderer;
18
19 public:
20 FrameBuffer(const rtw::vec2i &size, const RTWFrameBufferFormat format, const uint32_t frameBufferChannels)
22 {
23 VisRTX::Context* rtx = VisRTX_GetContext();
24
25 if (format == RTW_FB_RGBA8)
26 this->frameBuffer = rtx->CreateFrameBuffer(VisRTX::FrameBufferFormat::RGBA8, VisRTX::Vec2ui(size.x, size.y));
27 else if (format == RTW_FB_RGBA32F)
28 this->frameBuffer = rtx->CreateFrameBuffer(VisRTX::FrameBufferFormat::RGBA32F, VisRTX::Vec2ui(size.x, size.y));
29 else
30 assert(false);
31
32 this->format = format;
33 this->channels = frameBufferChannels;
34 }
35
37 {
38 this->frameBuffer->Release();
39 }
40
41 void Commit() override
42 {
43 }
44
45 void Clear()
46 {
47 this->frameBuffer->Clear();
48 }
49
50 const void* Map(const RTWFrameBufferChannel channel)
51 {
52 if (channel == RTW_FB_COLOR)
53 return this->frameBuffer->MapColorBuffer();
54 if (channel == RTW_FB_DEPTH)
55 return this->frameBuffer->MapDepthBuffer();
56
57 assert(false);
58 return nullptr;
59 }
60
61 void Unmap(const void *mapped)
62 {
63 this->frameBuffer->Unmap(mapped);
64 }
65
66 void SetDepthNormalizationGL(float clipMin, float clipMax)
67 {
68 this->frameBuffer->SetDepthNormalization(clipMin, clipMax);
69 }
70
72 {
73 try
74 {
75 return this->frameBuffer->GetColorTextureGL();
76 }
77 catch(const VisRTX::Exception& e)
78 {
79 vtkLogF(ERROR, "VISRTX Error: Could not get color texture.");
80 return 0;
81 }
82 }
83
85 {
86 try
87 {
88 return this->frameBuffer->GetDepthTextureGL();
89 }
90 catch(const VisRTX::Exception& e)
91 {
92 vtkLogF(ERROR, "VISRTX Error: Could not get depth texture.");
93 return 0;
94 }
95 }
96
97 private:
98 VisRTX::FrameBuffer* frameBuffer = nullptr;
100 uint32_t channels;
101 };
102VTK_ABI_NAMESPACE_END
103}
RTWFrameBufferFormat
Definition Types.h:22
@ RTW_FB_RGBA8
Definition Types.h:24
@ RTW_FB_RGBA32F
Definition Types.h:26
@ RTW_FRAMEBUFFER
Definition Types.h:140
RTWFrameBufferChannel
Definition Types.h:30
@ RTW_FB_COLOR
Definition Types.h:31
@ RTW_FB_DEPTH
Definition Types.h:32
int GetColorTextureGL()
Definition FrameBuffer.h:71
void Commit() override
Definition FrameBuffer.h:41
void SetDepthNormalizationGL(float clipMin, float clipMax)
Definition FrameBuffer.h:66
FrameBuffer(const rtw::vec2i &size, const RTWFrameBufferFormat format, const uint32_t frameBufferChannels)
Definition FrameBuffer.h:20
int GetDepthTextureGL()
Definition FrameBuffer.h:84
void Unmap(const void *mapped)
Definition FrameBuffer.h:61
const void * Map(const RTWFrameBufferChannel channel)
Definition FrameBuffer.h:50
Definition Backend.h:8
#define vtkLogF(verbosity_name,...)
Add to log given the verbosity level.
Definition vtkLogger.h:499