GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
texture_map.h
Go to the documentation of this file.
1// Copyright 2021 The Draco Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15#ifndef DRACO_TEXTURE_TEXTURE_MAP_H_
16#define DRACO_TEXTURE_TEXTURE_MAP_H_
17
19
20#ifdef DRACO_TRANSCODER_SUPPORTED
21#include <memory>
22
25
26namespace draco {
27
28// Class representing mapping of one texture to a mesh. A texture map
29// specifies the mesh attribute that contains texture coordinates used by the
30// texture. The class also defines an intended use of the texture as a so called
31// mapping type (COLOR, NORMAL_TANGENT_SPACE, etc..). Mapping types are roughly
32// based on GLTF 2.0 material spec that describes a metallic-roughness PBR
33// material model. More details can be found here:
34// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#materials
35class TextureMap {
36 public:
37 enum Type {
38 // Generic purpose texture (not GLTF compliant).
39 GENERIC = 0,
40 // Color data with optional alpha channel for transparency (GLTF compliant).
41 COLOR = 1,
42 // Dedicated texture for storing transparency (not GLTF compliant).
43 OPACITY = 2,
44 // Dedicated texture for storing metallic property (not GLTF compliant).
45 METALLIC = 3,
46 // Dedicated texture for storing roughness property (not GLTF compliant).
47 ROUGHNESS = 4,
48 // Combined texture for storing metallic and roughness properties.
49 // B == metallic, G == roughness (GLTF compliant).
50 METALLIC_ROUGHNESS = 5,
51 // Normal map defined in the object space of the mesh (not GLTF compliant).
52 NORMAL_OBJECT_SPACE = 6,
53 // Normal map defined in the tangent space of the mesh (GLTF compliant).
54 NORMAL_TANGENT_SPACE = 7,
55 // Precomputed ambient occlusion on the surface (GLTF compliant).
56 AMBIENT_OCCLUSION = 8,
57 // Emissive color (GLTF compliant).
58 EMISSIVE = 9,
59 // Texture types of glTF material extension KHR_materials_sheen.
60 SHEEN_COLOR = 10,
61 SHEEN_ROUGHNESS = 11,
62 // Texture types of glTF material extension KHR_materials_transmission.
63 TRANSMISSION = 12,
64 // Texture types of glTF material extension KHR_materials_clearcoat.
65 CLEARCOAT = 13,
66 CLEARCOAT_ROUGHNESS = 14,
67 CLEARCOAT_NORMAL = 15,
68 // Texture types of glTF material extension KHR_materials_volume.
69 THICKNESS = 16,
70 // Texture types of glTF material extension KHR_materials_specular.
71 SPECULAR = 17,
72 SPECULAR_COLOR = 18,
73 // The number of texture types.
74 TEXTURE_TYPES_COUNT
75 };
76
77 enum AxisWrappingMode {
78 // Out of bounds access along a texture axis should be clamped to the
79 // nearest edge (default).
80 CLAMP_TO_EDGE = 0,
81 // Texture is repeated along a texture axis in a mirrored pattern.
82 MIRRORED_REPEAT,
83 // Texture is repeated along a texture axis (tiled textures).
84 REPEAT
85 };
86
87 struct WrappingMode {
88 explicit WrappingMode(AxisWrappingMode mode) : WrappingMode(mode, mode) {}
89 WrappingMode(AxisWrappingMode s, AxisWrappingMode t) : s(s), t(t) {}
90 AxisWrappingMode s;
91 AxisWrappingMode t;
92 };
93
94 // Filter types are roughly based on glTF 2.0 samplers spec.
95 // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#samplers
96 enum FilterType {
97 UNSPECIFIED = 0,
98 NEAREST,
99 LINEAR,
100 NEAREST_MIPMAP_NEAREST,
101 LINEAR_MIPMAP_NEAREST,
102 NEAREST_MIPMAP_LINEAR,
103 LINEAR_MIPMAP_LINEAR
104 };
105
106 TextureMap();
107 TextureMap(TextureMap &&) = default;
108
109 // Copies texture map data from the |src| texture map to this texture map.
110 void Copy(const TextureMap &src);
111
112 // Sets the mapping information between the texture and the target mesh.
113 // |tex_coord_index| is the local index of the texture coordinates that is
114 // used to map the texture on the mesh.
115 void SetProperties(Type type);
116 void SetProperties(Type type, int tex_coord_index);
117 void SetProperties(Type type, WrappingMode wrapping_mode,
118 int tex_coord_index);
119 void SetProperties(Type type, WrappingMode wrapping_mode, int tex_coord_index,
120 FilterType min_filter, FilterType mag_filter);
121
122 // Set texture and transfer its ownership to the TextureMap object.
123 //
124 // Note that this should not be used if this TextureMap is part of a
125 // MaterialLibrary. For such cases, the TextureMap's texture should refer to
126 // an entry in the MaterialLibrary's TextureLibrary.
127 void SetTexture(std::unique_ptr<Texture> texture);
128
129 // Set texture and without transferring the ownership. The caller needs to
130 // ensure the texture is valid during the lifetime of the TextureMap object.
131 void SetTexture(Texture *texture);
132
133 void SetTransform(const TextureTransform &transform);
134 const TextureTransform &texture_transform() const {
135 return texture_transform_;
136 }
137
138 const Texture *texture() const { return texture_; }
139 Texture *texture() { return texture_; }
140 Type type() const { return type_; }
141 WrappingMode wrapping_mode() const { return wrapping_mode_; }
142 int tex_coord_index() const { return tex_coord_index_; }
143 FilterType min_filter() const { return min_filter_; }
144 FilterType mag_filter() const { return mag_filter_; }
145
146 TextureMap &operator=(TextureMap &&) = default;
147
148 private:
149 Type type_;
150 WrappingMode wrapping_mode_;
151
152 // Local index of the texture coordinates that is used to map the texture on
153 // the mesh. For example, |tex_coord_index_ == 0| would correspond to the
154 // first TEX_COORD attribute of the mesh.
155 int tex_coord_index_;
156
157 FilterType min_filter_;
158 FilterType mag_filter_;
159
160 // Used when the texture object is owned by TextureMap, otherwise set to
161 // nullptr.
162 std::unique_ptr<Texture> owned_texture_;
163
164 // Either raw pointer owned by |owned_texture_| or a pointer to a user
165 // specified texture in case |owned_texture_| is nullptr.
166 Texture *texture_;
167
168 // Transformation values of the texture map.
169 TextureTransform texture_transform_;
170};
171
172} // namespace draco
173
174#endif // DRACO_TRANSCODER_SUPPORTED
175#endif // DRACO_TEXTURE_TEXTURE_MAP_H_
Type
Definition Database.hh:9
tag src
Definition meshpage.php:1786
Definition attribute_octahedron_transform.cc:21