VTK: Rendering/RayTracing/RTWrapper/VisRTX/Texture.h Source File

| VTK 9.3.1

Texture.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 <VisRTX.h>
8 #include <algorithm>
9 #include <cassert>
10
11 namespace RTW
12 {
13 VTK_ABI_NAMESPACE_BEGIN
14 class Texture : public Object
15 {
16 friend class Renderer;
17 friend class Material;
18 friend class Light;
19
20 private:
21 VisRTX::TextureFormat convert(RTWTextureFormat format) const
22 {
23 switch (format)
24 {
25 case RTW_TEXTURE_SRGBA: // no support for sRGB textures in VisRTX
26 case RTW_TEXTURE_RGBA8:
27 return VisRTX::TextureFormat::RGBA8;
28 case RTW_TEXTURE_SRGB: // no support for sRGB textures in VisRTX
29 case RTW_TEXTURE_RGB8:
30 return VisRTX::TextureFormat::RGB8;
31 case RTW_TEXTURE_RGBA32F:
32 return VisRTX::TextureFormat::RGBA32F;
33 case RTW_TEXTURE_RGB32F:
34 return VisRTX::TextureFormat::RGB32F;
35 case RTW_TEXTURE_R8:
36 return VisRTX::TextureFormat::R8;
37 case RTW_TEXTURE_R32F:
38 return VisRTX::TextureFormat::R32F;
39 default:
40 break;
41 }
42
43 assert(false);
44 return VisRTX::TextureFormat::RGBA8;
45 }
46
47 public:
48 Texture(const char* /*type*/)
49 : Object(RTW_TEXTURE)
50 {
51 }
52
53 ~Texture()
54 {
55 if (this->texture)
56 this->texture->Release();
57 }
58
59 void Commit() override
60 {
61 int type = this->GetInt({ "format" });
62 int flags = this->GetInt({ "filter" });
63
64 void* source = nullptr;
65 Data* data = this->GetObject<Data>({ "data" });
66 VisRTX::Vec2i size = VisRTX::Vec2i(data->GetWidth(), data->GetHeight());
67 if (data)
68 source = data->GetData();
69
70 VisRTX::Context* rtx = VisRTX_GetContext();
71
72 if (!this->texture)
73 this->texture = rtx->CreateTexture(VisRTX::Vec2ui(size.x, size.y), convert((RTWTextureFormat)type), source);
74 else
75 this->texture->SetPixels(VisRTX::Vec2ui(size.x, size.y), convert((RTWTextureFormat)type), source);
76
77 if (flags & RTW_TEXTURE_FILTER_NEAREST)
78 this->texture->SetFiltering(VisRTX::TextureFiltering::NEAREST, VisRTX::TextureFiltering::NEAREST);
79 }
80
81
82 private:
83 VisRTX::Texture* texture = nullptr;
84 };
85 VTK_ABI_NAMESPACE_END
86 }
RTWTextureFormat
RTWTextureFormat
Definition: Types.h:98
RTW_TEXTURE_R32F
@ RTW_TEXTURE_R32F
Definition: Types.h:106
RTW_TEXTURE_RGBA32F
@ RTW_TEXTURE_RGBA32F
Definition: Types.h:101
RTW_TEXTURE_SRGB
@ RTW_TEXTURE_SRGB
Definition: Types.h:103
RTW_TEXTURE_RGB8
@ RTW_TEXTURE_RGB8
Definition: Types.h:102
RTW_TEXTURE_R8
@ RTW_TEXTURE_R8
Definition: Types.h:105
RTW_TEXTURE_RGBA8
@ RTW_TEXTURE_RGBA8
Definition: Types.h:99
RTW_TEXTURE_RGB32F
@ RTW_TEXTURE_RGB32F
Definition: Types.h:104
RTW_TEXTURE_SRGBA
@ RTW_TEXTURE_SRGBA
Definition: Types.h:100
RTW_TEXTURE_FILTER_NEAREST
@ RTW_TEXTURE_FILTER_NEAREST
Definition: Types.h:120
RTW_TEXTURE
@ RTW_TEXTURE
Definition: Types.h:150
RTW::Data
Definition: Data.h:13
RTW::Light
Definition: Light.h:18
RTW::Material
Definition: Material.h:21
RTW::Object
Definition: Object.h:22
RTW::Object::GetInt
int32_t GetInt(const std::vector< std::string > &ids, int32_t defaultValue=0, bool *found=nullptr) const
Definition: Object.h:119
RTW::Renderer
Definition: Renderer.h:23
RTW::Texture
Definition: Texture.h:15
RTW::Texture::Texture
Texture(const char *)
Definition: Texture.h:48
RTW::Texture::~Texture
~Texture()
Definition: Texture.h:53
RTW::Texture::Commit
void Commit() override
Definition: Texture.h:59
RTW
Definition: Backend.h:8
RTW::convert
OSPFrameBufferFormat convert(RTWFrameBufferFormat format)
Definition: OSPRayBackend.h:20
vtkX3D::type
@ type
Definition: vtkX3D.h:516
vtkX3D::size
@ size
Definition: vtkX3D.h:253
vtkX3D::data
@ data
Definition: vtkX3D.h:315
source
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Definition: vtkBoostGraphAdapter.h:964