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