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