Debian Codegraph @

modules/gltf/structures/gltf_texture_sampler.h

raw symbols SCIP
1 /**************************************************************************/
2 /* gltf_texture_sampler.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "scene/resources/material.h"
34
35 class GLTFTextureSampler : public Resource {
36 GDCLASS(GLTFTextureSampler, Resource);
37
38 public:
39 enum FilterMode {
40 NEAREST = 9728,
41 LINEAR = 9729,
42 NEAREST_MIPMAP_NEAREST = 9984,
43 LINEAR_MIPMAP_NEAREST = 9985,
44 NEAREST_MIPMAP_LINEAR = 9986,
45 LINEAR_MIPMAP_LINEAR = 9987
46 };
47
48 enum WrapMode {
49 CLAMP_TO_EDGE = 33071,
50 MIRRORED_REPEAT = 33648,
51 REPEAT = 10497,
52 DEFAULT = REPEAT
53 };
54
55 int get_mag_filter() const {
56 return mag_filter;
57 }
58
59 void set_mag_filter(const int filter_mode) {
60 mag_filter = (FilterMode)filter_mode;
61 }
62
63 int get_min_filter() const {
64 return min_filter;
65 }
66
67 void set_min_filter(const int filter_mode) {
68 min_filter = (FilterMode)filter_mode;
69 }
70
71 int get_wrap_s() const {
72 return wrap_s;
73 }
74
75 void set_wrap_s(const int wrap_mode) {
76 wrap_s = (WrapMode)wrap_mode;
77 }
78
79 int get_wrap_t() const {
80 return wrap_t;
81 }
82
83 void set_wrap_t(const int wrap_mode) {
84 wrap_s = (WrapMode)wrap_mode;
85 }
86
87 StandardMaterial3D::TextureFilter get_filter_mode() const {
88 using TextureFilter = StandardMaterial3D::TextureFilter;
89
90 switch (min_filter) {
91 case NEAREST:
92 return TextureFilter::TEXTURE_FILTER_NEAREST;
93 case LINEAR:
94 return TextureFilter::TEXTURE_FILTER_LINEAR;
95 case NEAREST_MIPMAP_NEAREST:
96 case NEAREST_MIPMAP_LINEAR:
97 return TextureFilter::TEXTURE_FILTER_NEAREST_WITH_MIPMAPS;
98 case LINEAR_MIPMAP_NEAREST:
99 case LINEAR_MIPMAP_LINEAR:
100 default:
101 return TextureFilter::TEXTURE_FILTER_LINEAR_WITH_MIPMAPS;
102 }
103 }
104
105 void set_filter_mode(StandardMaterial3D::TextureFilter mode) {
106 using TextureFilter = StandardMaterial3D::TextureFilter;
107
108 switch (mode) {
109 case TextureFilter::TEXTURE_FILTER_NEAREST:
110 min_filter = FilterMode::NEAREST;
111 mag_filter = FilterMode::NEAREST;
112 break;
113 case TextureFilter::TEXTURE_FILTER_LINEAR:
114 min_filter = FilterMode::LINEAR;
115 mag_filter = FilterMode::LINEAR;
116 break;
117 case TextureFilter::TEXTURE_FILTER_NEAREST_WITH_MIPMAPS:
118 case TextureFilter::TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC:
119 min_filter = FilterMode::NEAREST_MIPMAP_LINEAR;
120 mag_filter = FilterMode::NEAREST;
121 break;
122 case TextureFilter::TEXTURE_FILTER_LINEAR_WITH_MIPMAPS:
123 case TextureFilter::TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC:
124 default:
125 min_filter = FilterMode::LINEAR_MIPMAP_LINEAR;
126 mag_filter = FilterMode::LINEAR;
127 break;
128 }
129 }
130
131 bool get_wrap_mode() const {
132 // BaseMaterial3D presents wrapping as a boolean property. Either the texture is repeated
133 // in both dimensions, non-mirrored, or it isn't repeated at all. This will cause oddities
134 // when people import models having other wrapping mode combinations.
135 return (wrap_s == WrapMode::REPEAT) && (wrap_t == WrapMode::REPEAT);
136 }
137
138 void set_wrap_mode(bool mat_repeats) {
139 if (mat_repeats) {
140 wrap_s = WrapMode::REPEAT;
141 wrap_t = WrapMode::REPEAT;
142 } else {
143 wrap_s = WrapMode::CLAMP_TO_EDGE;
144 wrap_t = WrapMode::CLAMP_TO_EDGE;
145 }
146 }
147
148 protected:
149 static void _bind_methods();
150
151 private:
152 FilterMode mag_filter = FilterMode::LINEAR;
153 FilterMode min_filter = FilterMode::LINEAR_MIPMAP_LINEAR;
154 WrapMode wrap_s = WrapMode::REPEAT;
155 WrapMode wrap_t = WrapMode::REPEAT;
156 };
157
158 VARIANT_ENUM_CAST(GLTFTextureSampler::FilterMode);
159 VARIANT_ENUM_CAST(GLTFTextureSampler::WrapMode);