VTK  9.1.0
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
9namespace 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
24 return VisRTX::TextureFormat::RGBA8;
25 case RTW_TEXTURE_SRGB: // no support for sRGB textures in VisRTX
27 return VisRTX::TextureFormat::RGB8;
29 return VisRTX::TextureFormat::RGBA32F;
31 return VisRTX::TextureFormat::RGB32F;
32 case RTW_TEXTURE_R8:
33 return VisRTX::TextureFormat::R8;
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
75 this->texture->SetFiltering(VisRTX::TextureFiltering::NEAREST, VisRTX::TextureFiltering::NEAREST);
76 }
77
78
79 private:
80 VisRTX::Texture* texture = nullptr;
81 };
82}
RTWTextureFormat
Definition: Types.h:94
@ RTW_TEXTURE_R32F
Definition: Types.h:102
@ RTW_TEXTURE_RGBA32F
Definition: Types.h:97
@ RTW_TEXTURE_SRGB
Definition: Types.h:99
@ RTW_TEXTURE_RGB8
Definition: Types.h:98
@ RTW_TEXTURE_R8
Definition: Types.h:101
@ RTW_TEXTURE_RGBA8
Definition: Types.h:95
@ RTW_TEXTURE_RGB32F
Definition: Types.h:100
@ RTW_TEXTURE_SRGBA
Definition: Types.h:96
@ RTW_TEXTURE_FILTER_NEAREST
Definition: Types.h:116
@ RTW_TEXTURE
Definition: Types.h:146
Definition: Data.h:10
int32_t GetInt(const std::vector< std::string > &ids, int32_t defaultValue=0, bool *found=nullptr) const
Definition: Object.h:116
Texture(const char *)
Definition: Texture.h:45
void Commit() override
Definition: Texture.h:56
Definition: Backend.h:6
OSPFrameBufferFormat convert(RTWFrameBufferFormat format)
Definition: OSPRayBackend.h:17
@ type
Definition: vtkX3D.h:522
@ size
Definition: vtkX3D.h:259
@ data
Definition: vtkX3D.h:321
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)