Panda3D
Loading...
Searching...
No Matches
textureStage.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 textureStage.h
10 * @author drose
11 * @date 2004-07-14
12 */
13
14#ifndef TEXTURESTAGE_H
15#define TEXTURESTAGE_H
16
17#include "pandabase.h"
18
19#include "internalName.h"
20#include "pointerTo.h"
22#include "updateSeq.h"
23#include "luse.h"
25
26class FactoryParams;
27
28/**
29 * Defines the properties of a named stage of the multitexture pipeline. The
30 * TextureAttrib will associated a number of these stages with Texture
31 * objects, and the GSG will render geometry by sorting all of the currently
32 * active TextureStages in order and then issuing the appropriate rendering
33 * calls to activate them.
34 */
35class EXPCL_PANDA_GOBJ TextureStage : public TypedWritableReferenceCount {
36PUBLISHED:
37 explicit TextureStage(const std::string &name);
38 INLINE TextureStage(const TextureStage &copy);
39 void operator = (const TextureStage &copy);
40
41 virtual ~TextureStage();
42
43 enum Mode {
44 // Modes that pertain to the fixed-function pipeline.
45
46 M_modulate,
47 M_decal,
48 M_blend,
49 M_replace,
50 M_add,
51 M_combine,
52 M_blend_color_scale,
53
54 M_modulate_glow, // When fixed-function, equivalent to modulate.
55 M_modulate_gloss, // When fixed-function, equivalent to modulate.
56
57 // Modes that are only relevant to shader-based rendering.
58
59 M_normal,
60 M_normal_height,
61 M_glow, // Rarely used: modulate_glow is more efficient.
62 M_gloss, // Rarely used: modulate_gloss is more efficient.
63 M_height, // Rarely used: normal_height is more efficient.
64 M_selector,
65 M_normal_gloss,
66
67 M_emission,
68
69 // Forward compatibility alias.
70 M_metallic_roughness = M_selector,
71 };
72
73 enum CombineMode {
74 CM_undefined,
75 CM_replace,
76 CM_modulate,
77 CM_add,
78 CM_add_signed,
79 CM_interpolate,
80 CM_subtract,
81
82 // The following are valid only for combine_rgb, not combine_alpha.
83 CM_dot3_rgb,
84 CM_dot3_rgba,
85 };
86
87 enum CombineSource {
88 CS_undefined,
89 CS_texture,
90 CS_constant,
91 CS_primary_color,
92 CS_previous,
93 CS_constant_color_scale,
94 CS_last_saved_result,
95 };
96
97 enum CombineOperand {
98 CO_undefined,
99 CO_src_color,
100 CO_one_minus_src_color,
101 CO_src_alpha,
102 CO_one_minus_src_alpha,
103 };
104
105 INLINE void set_name(const std::string &name);
106 INLINE const std::string &get_name() const;
107
108 INLINE void set_sort(int sort);
109 INLINE int get_sort() const;
110
111 INLINE void set_priority(int priority);
112 INLINE int get_priority() const;
113
114 INLINE void set_texcoord_name(InternalName *name);
115 INLINE void set_texcoord_name(const std::string &texcoord_name);
116 INLINE InternalName *get_texcoord_name() const;
117 INLINE InternalName *get_tangent_name() const;
118 INLINE InternalName *get_binormal_name() const;
119
120 INLINE void set_mode(Mode mode);
121 INLINE Mode get_mode() const;
122
123 INLINE bool is_fixed_function() const;
124
125 INLINE void set_color(const LColor &color);
126 INLINE LColor get_color() const;
127
128 INLINE void set_rgb_scale(int rgb_scale);
129 INLINE int get_rgb_scale() const;
130
131 INLINE void set_alpha_scale(int alpha_scale);
132 INLINE int get_alpha_scale() const;
133
134 INLINE void set_saved_result(bool saved_result);
135 INLINE bool get_saved_result() const;
136
137 INLINE void set_tex_view_offset(int tex_view_offset);
138 INLINE int get_tex_view_offset() const;
139
140 INLINE void set_combine_rgb(CombineMode mode,
141 CombineSource source0, CombineOperand operand0);
142 INLINE void set_combine_rgb(CombineMode mode,
143 CombineSource source0, CombineOperand operand0,
144 CombineSource source1, CombineOperand operand1);
145 INLINE void set_combine_rgb(CombineMode mode,
146 CombineSource source0, CombineOperand operand0,
147 CombineSource source1, CombineOperand operand1,
148 CombineSource source2, CombineOperand operand2);
149 INLINE CombineMode get_combine_rgb_mode() const;
150 INLINE int get_num_combine_rgb_operands() const;
151 INLINE CombineSource get_combine_rgb_source0() const;
152 INLINE CombineOperand get_combine_rgb_operand0() const;
153 INLINE CombineSource get_combine_rgb_source1() const;
154 INLINE CombineOperand get_combine_rgb_operand1() const;
155 INLINE CombineSource get_combine_rgb_source2() const;
156 INLINE CombineOperand get_combine_rgb_operand2() const;
157
158 INLINE void set_combine_alpha(CombineMode mode,
159 CombineSource source0, CombineOperand operand0);
160 INLINE void set_combine_alpha(CombineMode mode,
161 CombineSource source0, CombineOperand operand0,
162 CombineSource source1, CombineOperand operand1);
163 INLINE void set_combine_alpha(CombineMode mode,
164 CombineSource source0, CombineOperand operand0,
165 CombineSource source1, CombineOperand operand1,
166 CombineSource source2, CombineOperand operand2);
167 INLINE CombineMode get_combine_alpha_mode() const;
168 INLINE int get_num_combine_alpha_operands() const;
169 INLINE CombineSource get_combine_alpha_source0() const;
170 INLINE CombineOperand get_combine_alpha_operand0() const;
171 INLINE CombineSource get_combine_alpha_source1() const;
172 INLINE CombineOperand get_combine_alpha_operand1() const;
173 INLINE CombineSource get_combine_alpha_source2() const;
174 INLINE CombineOperand get_combine_alpha_operand2() const;
175
176 INLINE bool involves_color_scale() const;
177 INLINE bool uses_color() const;
178 INLINE bool uses_primary_color() const;
179 INLINE bool uses_last_saved_result() const;
180
181 INLINE bool operator == (const TextureStage &other) const;
182 INLINE bool operator != (const TextureStage &other) const;
183 INLINE bool operator < (const TextureStage &other) const;
184
185 int compare_to(const TextureStage &other) const;
186
187 void write(std::ostream &out) const;
188 void write(std::ostream &out, int indent_level) const;
189 void output(std::ostream &out) const;
190
191 INLINE static TextureStage *get_default();
192
193PUBLISHED:
194 MAKE_PROPERTY(name, get_name, set_name);
195 MAKE_PROPERTY(sort, get_sort, set_sort);
196 MAKE_PROPERTY(priority, get_priority, set_priority);
197
198 MAKE_PROPERTY(texcoord_name, get_texcoord_name, set_texcoord_name);
199 MAKE_PROPERTY(tangent_name, get_tangent_name);
200 MAKE_PROPERTY(binormal_name, get_binormal_name);
201
202 MAKE_PROPERTY(mode, get_mode, set_mode);
203
204 MAKE_PROPERTY(color, get_color, set_color);
205 MAKE_PROPERTY(rgb_scale, get_rgb_scale, set_rgb_scale);
206 MAKE_PROPERTY(alpha_scale, get_alpha_scale, set_alpha_scale);
207 MAKE_PROPERTY(saved_result, get_saved_result, set_saved_result);
208
209 MAKE_PROPERTY(tex_view_offset, get_tex_view_offset, set_tex_view_offset);
210
211 MAKE_PROPERTY(default, get_default);
212
213public:
214 INLINE static UpdateSeq get_sort_seq();
215
216 INLINE void mark_used_by_auto_shader() const;
217
218private:
219 INLINE void update_color_flags();
220
221 static int get_expected_num_combine_operands(CombineMode cm);
222 static bool operand_valid_for_rgb(CombineOperand co);
223 static bool operand_valid_for_alpha(CombineOperand co);
224
225 std::string _name;
226 int _sort;
227 int _priority;
228 PT(InternalName) _texcoord_name;
229 Mode _mode;
230 LColor _color;
231 int _rgb_scale;
232 int _alpha_scale;
233 bool _saved_result;
234 int _tex_view_offset;
235 bool _involves_color_scale;
236 bool _uses_color;
237 bool _uses_primary_color;
238 bool _uses_last_saved_result;
239
240 CombineMode _combine_rgb_mode;
241 int _num_combine_rgb_operands;
242 CombineSource _combine_rgb_source0;
243 CombineOperand _combine_rgb_operand0;
244 CombineSource _combine_rgb_source1;
245 CombineOperand _combine_rgb_operand1;
246 CombineSource _combine_rgb_source2;
247 CombineOperand _combine_rgb_operand2;
248
249 CombineMode _combine_alpha_mode;
250 int _num_combine_alpha_operands;
251 CombineSource _combine_alpha_source0;
252 CombineOperand _combine_alpha_operand0;
253 CombineSource _combine_alpha_source1;
254 CombineOperand _combine_alpha_operand1;
255 CombineSource _combine_alpha_source2;
256 CombineOperand _combine_alpha_operand2;
257
258 static PT(TextureStage) _default_stage;
259 static UpdateSeq _sort_seq;
260
261 mutable bool _used_by_auto_shader;
262
263public:
264 // Datagram stuff
265 static void register_with_read_factory();
266 virtual void write_datagram(BamWriter *manager, Datagram &me);
267 virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
268
269 static TypedWritable *make_TextureStage(const FactoryParams &params);
270
271protected:
272 void fillin(DatagramIterator& scan, BamReader* manager);
273
274public:
275 static TypeHandle get_class_type() {
276 return _type_handle;
277 }
278 static void init_type() {
279 TypedWritableReferenceCount::init_type();
280 register_type(_type_handle, "TextureStage",
281 TypedWritableReferenceCount::get_class_type());
282 }
283 virtual TypeHandle get_type() const {
284 return get_class_type();
285 }
286 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
287
288private:
289 static TypeHandle _type_handle;
290};
291
292INLINE std::ostream &operator << (std::ostream &out, const TextureStage &ts);
293
294EXPCL_PANDA_GOBJ std::ostream &operator << (std::ostream &out, TextureStage::Mode mode);
295EXPCL_PANDA_GOBJ std::ostream &operator << (std::ostream &out, TextureStage::CombineMode cm);
296EXPCL_PANDA_GOBJ std::ostream &operator << (std::ostream &out, TextureStage::CombineSource cs);
297EXPCL_PANDA_GOBJ std::ostream &operator << (std::ostream &out, TextureStage::CombineOperand co);
298
299
300#include "textureStage.I"
301
302#endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Encodes a string name in a hash table, mapping it to a pointer.
Defines the properties of a named stage of the multitexture pipeline.
bool uses_primary_color() const
Returns true if the TextureStage makes use of the CS_primary_color combine source.
get_default
Returns the default TextureStage that will be used for all texturing that does not name a particular ...
int compare_to(const TextureStage &other) const
Returns a number less than zero if this TextureStage sorts before the other one, greater than zero if...
get_binormal_name
Returns the set of binormals this texture stage will use.
CombineMode get_combine_alpha_mode() const
Get combine_alpha_mode.
set_sort
Changes the order in which the texture associated with this stage is rendered relative to the other t...
get_saved_result
Returns the current setting of the saved_result flag.
get_name
Returns the name of this texture stage.
CombineOperand get_combine_rgb_operand2() const
Get operand2 of combine_rgb_mode.
set_tex_view_offset
Sets the tex_view_offset value.
CombineSource get_combine_alpha_source1() const
Get source1 of combine_alpha_mode.
void write(std::ostream &out) const
Writes the details of this stage.
void output(std::ostream &out) const
Just a single line output.
TextureStage(const std::string &name)
Initialize the texture stage at construction.
static void register_with_read_factory()
Factory method to generate a TextureStage object.
CombineMode get_combine_rgb_mode() const
Get the combine_rgb_mode.
CombineSource get_combine_rgb_source1() const
Get source1 of combine_rgb_mode.
bool is_fixed_function() const
Returns true if the TextureStage is relevant to the classic fixed function pipeline.
bool involves_color_scale() const
Returns true if the TextureStage is affected by the setting of the current ColorScaleAttrib,...
CombineOperand get_combine_alpha_operand0() const
Get operand0 of combine_alpha_mode.
set_color
Set the color for this stage.
get_priority
Returns the priority associated with this stage.
CombineOperand get_combine_rgb_operand1() const
Get operand1 of combine_rgb_mode.
CombineSource get_combine_alpha_source0() const
Get source0 of combine_alpha_mode.
get_rgb_scale
See set_rgb_scale().
set_name
Changes the name of this texture stage.
get_alpha_scale
See set_alpha_scale().
set_mode
Set the mode of this texture stage.
get_sort
Returns the sort order of this texture stage.
int get_num_combine_rgb_operands() const
Returns the number of meaningful operands that may be retrieved via get_combine_rgb_sourceN() and get...
static TypedWritable * make_TextureStage(const FactoryParams &params)
Factory method to generate a TextureStage object.
CombineOperand get_combine_alpha_operand1() const
Get operand1 of combine_alpha_mode.
get_color
return the color for this stage
get_tex_view_offset
Returns the current setting of the tex_view_offset.
void mark_used_by_auto_shader() const
Marks this TextureStage as having been used by the auto shader.
CombineSource get_combine_rgb_source0() const
Get source0 of combine_rgb_mode.
CombineSource get_combine_rgb_source2() const
Get source2 of combine_rgb_mode.
get_mode
Return the mode of this stage.
void set_combine_rgb(CombineMode mode, CombineSource source0, CombineOperand operand0)
Specifies any of the CombineMode values that represent a one-parameter operation.
static UpdateSeq get_sort_seq()
Returns a global sequence number that is incremented any time any TextureStage in the world changes s...
set_priority
Changes the relative importance of the texture associated with this stage relative to the other textu...
bool uses_color() const
Returns true if the TextureStage makes use of whatever color is specified in set_color(),...
int get_num_combine_alpha_operands() const
Returns the number of meaningful operands that may be retrieved via get_combine_alpha_sourceN() and g...
CombineOperand get_combine_rgb_operand0() const
Get operand0 of combine_rgb_mode.
CombineSource get_combine_alpha_source2() const
Get source2 of combine_alpha_mode.
void set_combine_alpha(CombineMode mode, CombineSource source0, CombineOperand operand0)
Specifies any of the CombineMode values that represent a one-parameter operation.
get_texcoord_name
See set_texcoord_name.
set_alpha_scale
Sets an additional factor that will scale the alpha component after the texture has been applied.
bool uses_last_saved_result() const
Returns true if the TextureStage makes use of the CS_primary_color combine source.
set_rgb_scale
Sets an additional factor that will scale all three r, g, b components after the texture has been app...
get_tangent_name
Returns the set of tangents this texture stage will use.
set_saved_result
Sets the saved_result flag.
set_texcoord_name
Indicate which set of UV's this texture stage will use.
CombineOperand get_combine_alpha_operand2() const
Get operand2 of combine_alpha_mode.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
This is a sequence number that increments monotonically.
Definition updateSeq.h:37
This is our own Panda specialization on the default STL list.
Definition plist.h:35
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(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.