Panda3D
Loading...
Searching...
No Matches
eggTexture.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file eggTexture.h
10 * @author drose
11 * @date 1999-01-18
12 */
13
14#ifndef EGGTEXTURE_H
15#define EGGTEXTURE_H
16
17#include "pandabase.h"
18
19#include "eggRenderMode.h"
20#include "eggFilenameNode.h"
21#include "eggTransform.h"
22
23#include "pset.h"
24#include "luse.h"
25
26
27/**
28 * Defines a texture map that may be applied to geometry.
29 */
30class EXPCL_PANDA_EGG EggTexture : public EggFilenameNode, public EggRenderMode, public EggTransform {
31PUBLISHED:
32 explicit EggTexture(const std::string &tref_name, const Filename &filename);
33 EggTexture(const EggTexture &copy);
34 EggTexture &operator = (const EggTexture &copy);
35 virtual ~EggTexture();
36
37 virtual void write(std::ostream &out, int indent_level) const;
38
39 enum Equivalence {
40 E_basename = 0x001,
41 E_extension = 0x002,
42 E_dirname = 0x004,
43 E_complete_filename = 0x007,
44 E_transform = 0x008,
45 E_attributes = 0x010,
46 E_tref_name = 0x020,
47 };
48
49 bool is_equivalent_to(const EggTexture &other, int eq) const;
50 bool sorts_less_than(const EggTexture &other, int eq) const;
51
52 bool has_alpha_channel(int num_components) const;
53
54 enum TextureType {
55 TT_unspecified, TT_1d_texture,
56 TT_2d_texture, TT_3d_texture, TT_cube_map
57 };
58 enum Format {
59 F_unspecified,
60 F_rgba, F_rgbm, F_rgba12, F_rgba8, F_rgba4, F_rgba5,
61 F_rgb, F_rgb12, F_rgb8, F_rgb5, F_rgb332,
62 F_red, F_green, F_blue, F_alpha, F_luminance,
63 F_luminance_alpha, F_luminance_alphamask,
64
65 // Only for compatibility with .bam, use is discouraged!
66 F_srgb, F_srgb_alpha
67 };
68 enum CompressionMode {
69 CM_default, CM_off, CM_on,
70 CM_fxt1, CM_dxt1, CM_dxt2, CM_dxt3, CM_dxt4, CM_dxt5,
71 };
72 enum WrapMode {
73 WM_unspecified, WM_clamp, WM_repeat,
74 WM_mirror, WM_mirror_once, WM_border_color
75 };
76 enum FilterType {
77 // Note that these type values match up, name-for-name, with a similar
78 // enumerated type in Panda's Texture object. However, they do *not*
79 // match up numerically. You must convert between them using a switch
80 // statement.
81 FT_unspecified,
82
83 // Mag Filter and Min Filter
84 FT_nearest,
85 FT_linear,
86
87 // Min Filter Only
88 FT_nearest_mipmap_nearest, // "mipmap point"
89 FT_linear_mipmap_nearest, // "mipmap linear"
90 FT_nearest_mipmap_linear, // "mipmap bilinear"
91 FT_linear_mipmap_linear, // "mipmap trilinear"
92 };
93 enum EnvType {
94 ET_unspecified,
95 ET_modulate,
96 ET_decal,
97 ET_blend,
98 ET_replace,
99 ET_add,
100 ET_blend_color_scale,
101 ET_modulate_glow,
102 ET_modulate_gloss,
103 ET_normal,
104 ET_normal_height,
105 ET_glow,
106 ET_gloss,
107 ET_height,
108 ET_selector,
109 ET_normal_gloss,
110 ET_emission,
111 };
112 enum CombineMode {
113 CM_unspecified,
114 CM_replace,
115 CM_modulate,
116 CM_add,
117 CM_add_signed,
118 CM_interpolate,
119 CM_subtract,
120 CM_dot3_rgb,
121 CM_dot3_rgba,
122 };
123 enum CombineChannel {
124 CC_rgb = 0,
125 CC_alpha = 1,
126 CC_num_channels = 2,
127 };
128 enum CombineIndex {
129 CI_num_indices = 3
130 };
131 enum CombineSource {
132 CS_unspecified,
133 CS_texture,
134 CS_constant,
135 CS_primary_color,
136 CS_previous,
137 CS_constant_color_scale,
138 CS_last_saved_result,
139 };
140 enum CombineOperand {
141 CO_unspecified,
142 CO_src_color,
143 CO_one_minus_src_color,
144 CO_src_alpha,
145 CO_one_minus_src_alpha,
146 };
147 enum TexGen {
148 TG_unspecified,
149
150 TG_eye_sphere_map,
151
152 TG_world_cube_map,
153 TG_eye_cube_map,
154
155 TG_world_normal,
156 TG_eye_normal,
157
158 TG_world_position,
159 TG_eye_position,
160
161 TG_point_sprite,
162 };
163 enum QualityLevel {
164 QL_unspecified,
165 QL_default,
166 QL_fastest,
167 QL_normal,
168 QL_best,
169 };
170
171 INLINE void set_texture_type(TextureType texture_type);
172 INLINE TextureType get_texture_type() const;
173
174 INLINE void set_format(Format format);
175 INLINE Format get_format() const;
176
177 INLINE void set_compression_mode(CompressionMode mode);
178 INLINE CompressionMode get_compression_mode() const;
179
180 INLINE void set_wrap_mode(WrapMode mode);
181 INLINE WrapMode get_wrap_mode() const;
182
183 INLINE void set_wrap_u(WrapMode mode);
184 INLINE WrapMode get_wrap_u() const;
185 INLINE WrapMode determine_wrap_u() const;
186
187 INLINE void set_wrap_v(WrapMode mode);
188 INLINE WrapMode get_wrap_v() const;
189 INLINE WrapMode determine_wrap_v() const;
190
191 INLINE void set_wrap_w(WrapMode mode);
192 INLINE WrapMode get_wrap_w() const;
193 INLINE WrapMode determine_wrap_w() const;
194
195 INLINE void set_minfilter(FilterType type);
196 INLINE FilterType get_minfilter() const;
197
198 INLINE void set_magfilter(FilterType type);
199 INLINE FilterType get_magfilter() const;
200
201 INLINE void set_anisotropic_degree(int anisotropic_degree);
202 INLINE void clear_anisotropic_degree();
203 INLINE bool has_anisotropic_degree() const;
204 INLINE int get_anisotropic_degree() const;
205
206 INLINE void set_env_type(EnvType type);
207 INLINE EnvType get_env_type() const;
208 bool affects_polygon_alpha() const;
209
210 INLINE void set_combine_mode(CombineChannel channel, CombineMode cm);
211 INLINE CombineMode get_combine_mode(CombineChannel channel) const;
212 INLINE void set_combine_source(CombineChannel channel, int n, CombineSource cs);
213 INLINE CombineSource get_combine_source(CombineChannel channel, int n) const;
214 INLINE void set_combine_operand(CombineChannel channel, int n, CombineOperand co);
215 INLINE CombineOperand get_combine_operand(CombineChannel channel, int n) const;
216
217 INLINE void set_saved_result(bool saved_result);
218 INLINE bool get_saved_result() const;
219
220 INLINE void set_tex_gen(TexGen tex_gen);
221 INLINE TexGen get_tex_gen() const;
222
223 INLINE void set_quality_level(QualityLevel quality_level);
224 INLINE QualityLevel get_quality_level() const;
225
226 INLINE void set_stage_name(const std::string &stage_name);
227 INLINE void clear_stage_name();
228 INLINE bool has_stage_name() const;
229 INLINE const std::string &get_stage_name() const;
230
231 INLINE void set_priority(int priority);
232 INLINE void clear_priority();
233 INLINE bool has_priority() const;
234 INLINE int get_priority() const;
235
236 INLINE void set_color(const LColor &color);
237 INLINE void clear_color();
238 INLINE bool has_color() const;
239 INLINE const LColor &get_color() const;
240
241 INLINE void set_border_color(const LColor &border_color);
242 INLINE void clear_border_color();
243 INLINE bool has_border_color() const;
244 INLINE const LColor &get_border_color() const;
245
246 INLINE void set_uv_name(const std::string &uv_name);
247 INLINE void clear_uv_name();
248 INLINE bool has_uv_name() const;
249 INLINE const std::string &get_uv_name() const;
250
251 INLINE void set_rgb_scale(int rgb_scale);
252 INLINE void clear_rgb_scale();
253 INLINE bool has_rgb_scale() const;
254 INLINE int get_rgb_scale() const;
255
256 INLINE void set_alpha_scale(int alpha_scale);
257 INLINE void clear_alpha_scale();
258 INLINE bool has_alpha_scale() const;
259 INLINE int get_alpha_scale() const;
260
261 INLINE void set_alpha_filename(const Filename &filename);
262 INLINE void clear_alpha_filename();
263 INLINE bool has_alpha_filename() const;
264 INLINE const Filename &get_alpha_filename() const;
265
266 INLINE void set_alpha_fullpath(const Filename &fullpath);
267 INLINE const Filename &get_alpha_fullpath() const;
268
269 INLINE void set_alpha_file_channel(int alpha_file_channel);
270 INLINE void clear_alpha_file_channel();
271 INLINE bool has_alpha_file_channel() const;
272 INLINE int get_alpha_file_channel() const;
273
274 INLINE void set_multiview(bool multiview);
275 INLINE bool get_multiview() const;
276
277 INLINE void set_num_views(int num_views);
278 INLINE void clear_num_views();
279 INLINE bool has_num_views() const;
280 INLINE int get_num_views() const;
281
282 INLINE void set_read_mipmaps(bool read_mipmaps);
283 INLINE bool get_read_mipmaps() const;
284
285 INLINE void set_min_lod(double min_lod);
286 INLINE void clear_min_lod();
287 INLINE bool has_min_lod() const;
288 INLINE double get_min_lod() const;
289
290 INLINE void set_max_lod(double max_lod);
291 INLINE void clear_max_lod();
292 INLINE bool has_max_lod() const;
293 INLINE double get_max_lod() const;
294
295 INLINE void set_lod_bias(double lod_bias);
296 INLINE void clear_lod_bias();
297 INLINE bool has_lod_bias() const;
298 INLINE double get_lod_bias() const;
299
300 void clear_multitexture();
301 bool multitexture_over(EggTexture *other);
302 INLINE int get_multitexture_sort() const;
303
304 static TextureType string_texture_type(const std::string &string);
305 static Format string_format(const std::string &string);
306 static CompressionMode string_compression_mode(const std::string &string);
307 static WrapMode string_wrap_mode(const std::string &string);
308 static FilterType string_filter_type(const std::string &string);
309 static EnvType string_env_type(const std::string &string);
310 static CombineMode string_combine_mode(const std::string &string);
311 static CombineSource string_combine_source(const std::string &string);
312 static CombineOperand string_combine_operand(const std::string &string);
313 static TexGen string_tex_gen(const std::string &string);
314 static QualityLevel string_quality_level(const std::string &string);
315
316PUBLISHED:
317 MAKE_PROPERTY(texture_type, get_texture_type, set_texture_type);
318 MAKE_PROPERTY(format, get_format, set_format);
319 MAKE_PROPERTY(compression_mode, get_compression_mode, set_compression_mode);
320 MAKE_PROPERTY(wrap_mode, get_wrap_mode, set_wrap_mode);
321 MAKE_PROPERTY(wrap_u, get_wrap_u, set_wrap_u);
322 MAKE_PROPERTY(wrap_v, get_wrap_v, set_wrap_v);
323 MAKE_PROPERTY(wrap_w, get_wrap_w, set_wrap_w);
324 MAKE_PROPERTY(minfilter, get_minfilter, set_minfilter);
325 MAKE_PROPERTY(magfilter, get_magfilter, set_magfilter);
326 MAKE_PROPERTY2(anisotropic_degree, has_anisotropic_degree, get_anisotropic_degree,
327 set_anisotropic_degree, clear_anisotropic_degree);
328 MAKE_PROPERTY(env_type, get_env_type, set_env_type);
329 MAKE_PROPERTY(saved_result, get_saved_result, set_saved_result);
330 MAKE_PROPERTY(tex_gen, get_tex_gen, set_tex_gen);
331 MAKE_PROPERTY(quality_level, get_quality_level, set_quality_level);
332 MAKE_PROPERTY2(stage_name, has_stage_name, get_stage_name,
333 set_stage_name, clear_stage_name);
334 MAKE_PROPERTY2(priority, has_priority, get_priority,
335 set_priority, clear_priority);
336 MAKE_PROPERTY2(color, has_color, get_color,
337 set_color, clear_color);
338 MAKE_PROPERTY2(border_color, has_border_color, get_border_color,
339 set_border_color, clear_border_color);
340 MAKE_PROPERTY2(uv_name, has_uv_name, get_uv_name,
341 set_uv_name, clear_uv_name);
342 MAKE_PROPERTY2(rgb_scale, has_rgb_scale, get_rgb_scale,
343 set_rgb_scale, clear_rgb_scale);
344 MAKE_PROPERTY2(alpha_scale, has_alpha_scale, get_alpha_scale,
345 set_alpha_scale, clear_alpha_scale);
346 MAKE_PROPERTY2(alpha_filename, has_alpha_filename, get_alpha_filename,
347 set_alpha_filename, clear_alpha_filename);
348 MAKE_PROPERTY(alpha_fullpath, get_alpha_fullpath, set_alpha_fullpath);
349 MAKE_PROPERTY2(alpha_file_channel, has_alpha_file_channel, get_alpha_file_channel,
350 set_alpha_file_channel, clear_alpha_file_channel);
351 MAKE_PROPERTY(multiview, get_multiview, set_multiview);
352 MAKE_PROPERTY2(num_views, has_num_views, get_num_views,
353 set_num_views, clear_num_views);
354 MAKE_PROPERTY(read_mipmaps, get_read_mipmaps, set_read_mipmaps);
355 MAKE_PROPERTY2(min_lod, has_min_lod, get_min_lod,
356 set_min_lod, clear_min_lod);
357 MAKE_PROPERTY2(max_lod, has_max_lod, get_max_lod,
358 set_max_lod, clear_max_lod);
359 MAKE_PROPERTY2(lod_bias, has_lod_bias, get_lod_bias,
360 set_lod_bias, clear_lod_bias);
361
362 MAKE_PROPERTY(multitexture_sort, get_multitexture_sort);
363
364public:
365 virtual EggTransform *as_transform();
366
367protected:
368 virtual bool egg_start_parse_body();
369
370private:
372 bool r_min_multitexture_sort(int sort, MultiTextures &cycle_detector);
373
374 enum Flags {
375 F_has_alpha_filename = 0x0002,
376 F_has_anisotropic_degree = 0x0004,
377 F_has_alpha_file_channel = 0x0008,
378 F_has_stage_name = 0x0010,
379 F_has_uv_name = 0x0020,
380 F_has_priority = 0x0040,
381 F_has_color = 0x0080,
382 F_has_rgb_scale = 0x0100,
383 F_has_alpha_scale = 0x0200,
384 F_has_border_color = 0x0400,
385 F_has_num_views = 0x0800,
386 F_has_min_lod = 0x1000,
387 F_has_max_lod = 0x2000,
388 F_has_lod_bias = 0x4000,
389 };
390
391 TextureType _texture_type;
392 Format _format;
393 CompressionMode _compression_mode;
394 WrapMode _wrap_mode, _wrap_u, _wrap_v, _wrap_w;
395 FilterType _minfilter, _magfilter;
396 int _anisotropic_degree;
397 EnvType _env_type;
398 bool _saved_result;
399 bool _multiview;
400 int _num_views;
401 TexGen _tex_gen;
402 QualityLevel _quality_level;
403 std::string _stage_name;
404 int _priority;
405 LColor _color;
406 LColor _border_color;
407 std::string _uv_name;
408 int _rgb_scale;
409 int _alpha_scale;
410 int _flags;
411 Filename _alpha_filename;
412 Filename _alpha_fullpath;
413 int _alpha_file_channel;
414 bool _read_mipmaps;
415 int _multitexture_sort;
416 double _min_lod;
417 double _max_lod;
418 double _lod_bias;
419
420 class SourceAndOperand {
421 public:
422 INLINE SourceAndOperand();
423 CombineSource _source;
424 CombineOperand _operand;
425 };
426
427 class Combiner {
428 public:
429 INLINE Combiner();
430 CombineMode _mode;
431 SourceAndOperand _ops[CI_num_indices];
432 };
433
434 Combiner _combiner[CC_num_channels];
435
436 // This is the set of all of the textures that are multitextured on top of
437 // (and under) this one. This is filled in by multitexture_over().
438 MultiTextures _over_textures, _under_textures;
439
440public:
441 static TypeHandle get_class_type() {
442 return _type_handle;
443 }
444 static void init_type() {
445 EggFilenameNode::init_type();
446 EggRenderMode::init_type();
447 register_type(_type_handle, "EggTexture",
448 EggFilenameNode::get_class_type(),
449 EggRenderMode::get_class_type());
450 }
451 virtual TypeHandle get_type() const {
452 return get_class_type();
453 }
454 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
455
456private:
457 static TypeHandle _type_handle;
458};
459
460/**
461 * An STL function object for sorting textures into order by properties.
462 * Returns true if the two referenced EggTexture pointers are in sorted order,
463 * false otherwise.
464 */
465class EXPCL_PANDA_EGG UniqueEggTextures {
466public:
467 INLINE UniqueEggTextures(int eq = ~0);
468 INLINE bool operator ()(const EggTexture *t1, const EggTexture *t2) const;
469
470 int _eq;
471};
472
473INLINE std::ostream &operator << (std::ostream &out, const EggTexture &n) {
474 return out << n.get_filename();
475}
476
477EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::TextureType texture_type);
478EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::Format format);
479EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::CompressionMode mode);
480EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::WrapMode mode);
481EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::FilterType type);
482EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::EnvType type);
483EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::CombineMode cm);
484EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::CombineChannel cc);
485EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::CombineSource cs);
486EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::CombineOperand co);
487EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::TexGen tex_gen);
488EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::QualityLevel quality_level);
489
490#include "eggTexture.I"
491
492#endif
This is an egg node that contains a filename.
const Filename & get_filename() const
Returns a nonmodifiable reference to the filename.
virtual EggTransform * as_transform()
Returns this object cross-cast to an EggTransform pointer, if it inherits from EggTransform,...
This class stores miscellaneous rendering properties that is associated with geometry,...
void write(std::ostream &out, int indent_level) const
Writes the attributes to the indicated output stream in Egg format.
Defines a texture map that may be applied to geometry.
Definition eggTexture.h:30
This represents the <Transform> entry of a group or texture node: a list of component transform opera...
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
An STL function object for sorting textures into order by properties.
Definition eggTexture.h:465
This is our own Panda specialization on the default STL set.
Definition pset.h:49
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...