VTK  9.4.20241118
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
11namespace RTW
12{
13VTK_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
27 return VisRTX::TextureFormat::RGBA8;
28 case RTW_TEXTURE_SRGB: // no support for sRGB textures in VisRTX
30 return VisRTX::TextureFormat::RGB8;
32 return VisRTX::TextureFormat::RGBA32F;
34 return VisRTX::TextureFormat::RGB32F;
35 case RTW_TEXTURE_R8:
36 return VisRTX::TextureFormat::R8;
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*/)
50 {
51 }
52
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
78 this->texture->SetFiltering(VisRTX::TextureFiltering::NEAREST, VisRTX::TextureFiltering::NEAREST);
79 }
80
81
82 private:
83 VisRTX::Texture* texture = nullptr;
84 };
85VTK_ABI_NAMESPACE_END
86}
RTWTextureFormat
Definition Types.h:98
@ RTW_TEXTURE_R32F
Definition Types.h:106
@ RTW_TEXTURE_RGBA32F
Definition Types.h:101
@ RTW_TEXTURE_SRGB
Definition Types.h:103
@ RTW_TEXTURE_RGB8
Definition Types.h:102
@ RTW_TEXTURE_R8
Definition Types.h:105
@ RTW_TEXTURE_RGBA8
Definition Types.h:99
@ RTW_TEXTURE_RGB32F
Definition Types.h:104
@ RTW_TEXTURE_SRGBA
Definition Types.h:100
@ RTW_TEXTURE_FILTER_NEAREST
Definition Types.h:120
@ RTW_TEXTURE
Definition Types.h:150
int32_t GetInt(const std::vector< std::string > &ids, int32_t defaultValue=0, bool *found=nullptr) const
Definition Object.h:119
Texture(const char *)
Definition Texture.h:48
void Commit() override
Definition Texture.h:59
Definition Backend.h:8
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)