VTK  9.2.6
Texture.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../Types.h"
4 
5 #include <VisRTX.h>
6 #include <algorithm>
7 #include <cassert>
8 
9 namespace RTW
10 {
11  class Texture : public Object
12  {
13  friend class Renderer;
14  friend class Material;
15  friend class Light;
16 
17  private:
18  VisRTX::TextureFormat convert(RTWTextureFormat format) const
19  {
20  switch (format)
21  {
22  case RTW_TEXTURE_SRGBA: // no support for sRGB textures in VisRTX
23  case RTW_TEXTURE_RGBA8:
24  return VisRTX::TextureFormat::RGBA8;
25  case RTW_TEXTURE_SRGB: // no support for sRGB textures in VisRTX
26  case RTW_TEXTURE_RGB8:
27  return VisRTX::TextureFormat::RGB8;
29  return VisRTX::TextureFormat::RGBA32F;
30  case RTW_TEXTURE_RGB32F:
31  return VisRTX::TextureFormat::RGB32F;
32  case RTW_TEXTURE_R8:
33  return VisRTX::TextureFormat::R8;
34  case RTW_TEXTURE_R32F:
35  return VisRTX::TextureFormat::R32F;
36  default:
37  break;
38  }
39 
40  assert(false);
41  return VisRTX::TextureFormat::RGBA8;
42  }
43 
44  public:
45  Texture(const char* /*type*/)
47  {
48  }
49 
51  {
52  if (this->texture)
53  this->texture->Release();
54  }
55 
56  void Commit() override
57  {
58  int type = this->GetInt({ "format" });
59  int flags = this->GetInt({ "filter" });
60 
61  void* source = nullptr;
62  Data* data = this->GetObject<Data>({ "data" });
63  VisRTX::Vec2i size = VisRTX::Vec2i(data->GetWidth(), data->GetHeight());
64  if (data)
65  source = data->GetData();
66 
67  VisRTX::Context* rtx = VisRTX_GetContext();
68 
69  if (!this->texture)
70  this->texture = rtx->CreateTexture(VisRTX::Vec2ui(size.x, size.y), convert((RTWTextureFormat)type), source);
71  else
72  this->texture->SetPixels(VisRTX::Vec2ui(size.x, size.y), convert((RTWTextureFormat)type), source);
73 
74  if (flags & RTW_TEXTURE_FILTER_NEAREST)
75  this->texture->SetFiltering(VisRTX::TextureFiltering::NEAREST, VisRTX::TextureFiltering::NEAREST);
76  }
77 
78 
79  private:
80  VisRTX::Texture* texture = nullptr;
81  };
82 }
int32_t GetInt(const std::vector< std::string > &ids, int32_t defaultValue=0, bool *found=nullptr) const
Definition: Object.h:116
void * GetData() const
Definition: Data.h:146
Definition: Data.h:9
RTWTextureFormat
Definition: Types.h:93
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
size_t GetHeight() const
Definition: Data.h:126
Definition: Backend.h:5
OSPFrameBufferFormat convert(RTWFrameBufferFormat format)
Definition: OSPRayBackend.h:17
void Commit() override
Definition: Texture.h:56
size_t GetWidth() const
Definition: Data.h:121
Texture(const char *)
Definition: Texture.h:45