Panda3D
Loading...
Searching...
No Matches
textureAttrib.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 textureAttrib.h
10 * @author drose
11 * @date 2002-02-21
12 */
13
14#ifndef TEXTUREATTRIB_H
15#define TEXTUREATTRIB_H
16
17#include "pandabase.h"
18
19#include "renderAttrib.h"
20#include "texture.h"
21#include "textureStage.h"
22#include "updateSeq.h"
23#include "ordered_vector.h"
24#include "vector_int.h"
25#include "epvector.h"
26
27/**
28 * Indicates the set of TextureStages and their associated Textures that
29 * should be applied to (or removed from) a node.
30 */
31class EXPCL_PANDA_PGRAPH TextureAttrib : public RenderAttrib {
32protected:
33 INLINE TextureAttrib();
34 INLINE TextureAttrib(const TextureAttrib &copy);
35
36PUBLISHED:
37 // These methods are used to create a simple, single-textured layer. For
38 // multitexture, use the multitexture interfaces, further below.
39 static CPT(RenderAttrib) make(Texture *tex);
40 static CPT(RenderAttrib) make_off();
41 static CPT(RenderAttrib) make_default();
42
43 INLINE bool is_off() const;
44 INLINE Texture *get_texture() const;
45
46 // The following methods define the new multitexture mode for TextureAttrib.
47 // Each TextureAttrib can add or remove individual texture stages from the
48 // complete set of textures that are to be applied; this is similar to the
49 // mechanism of LightAttrib.
50 static CPT(RenderAttrib) make();
51 static CPT(RenderAttrib) make_all_off();
52
53 INLINE int get_num_on_stages() const;
54 INLINE TextureStage *get_on_stage(int n) const;
55 MAKE_SEQ(get_on_stages, get_num_on_stages, get_on_stage);
56 INLINE int get_num_on_ff_stages() const;
57 INLINE TextureStage *get_on_ff_stage(int n) const;
58 MAKE_SEQ(get_on_ff_stages, get_num_on_ff_stages, get_on_ff_stage);
59 INLINE int get_ff_tc_index(int n) const;
60 INLINE bool has_on_stage(TextureStage *stage) const;
61 INLINE Texture *get_on_texture(TextureStage *stage) const;
62 INLINE const SamplerState &get_on_sampler(TextureStage *stage) const;
63 INLINE int get_on_stage_override(TextureStage *stage) const;
64
65 int find_on_stage(const TextureStage *stage) const;
66
67 MAKE_SEQ_PROPERTY(on_stages, get_num_on_stages, get_on_stage);
68
69 MAKE_MAP_PROPERTY(textures, has_on_stage, get_on_texture);
70 MAKE_MAP_KEYS_SEQ(textures, get_num_on_stages, get_on_stage);
71
72 MAKE_MAP_PROPERTY(samplers, has_on_stage, get_on_sampler);
73 MAKE_MAP_KEYS_SEQ(samplers, get_num_on_stages, get_on_stage);
74
75 INLINE int get_num_off_stages() const;
76 INLINE TextureStage *get_off_stage(int n) const;
77 MAKE_SEQ(get_off_stages, get_num_off_stages, get_off_stage);
78 INLINE bool has_off_stage(TextureStage *stage) const;
79 INLINE bool has_all_off() const;
80
81 MAKE_SEQ_PROPERTY(off_stages, get_num_off_stages, get_off_stage);
82
83 INLINE bool is_identity() const;
84
85 CPT(RenderAttrib) add_on_stage(TextureStage *stage, Texture *tex, int override = 0) const;
86 CPT(RenderAttrib) add_on_stage(TextureStage *stage, Texture *tex,
87 const SamplerState &sampler, int override = 0) const;
88 CPT(RenderAttrib) remove_on_stage(TextureStage *stage) const;
89 CPT(RenderAttrib) add_off_stage(TextureStage *stage, int override = 0) const;
90 CPT(RenderAttrib) remove_off_stage(TextureStage *stage) const;
91 CPT(RenderAttrib) unify_texture_stages(TextureStage *stage) const;
92 CPT(RenderAttrib) replace_texture(Texture *tex, Texture *new_tex) const;
93#ifdef CPPPARSER // Let interrogate know this also accepts None
94 CPT(RenderAttrib) replace_texture(Texture *tex, std::nullptr_t new_tex) const;
95#endif
96
97public:
98 CPT(TextureAttrib) filter_to_max(int max_texture_stages) const;
99
100 virtual bool lower_attrib_can_override() const;
101 virtual void output(std::ostream &out) const;
102
103 virtual bool has_cull_callback() const;
104 virtual bool cull_callback(CullTraverser *trav, const CullTraverserData &data) const;
105
106protected:
107 virtual int compare_to_impl(const RenderAttrib *other) const;
108 virtual size_t get_hash_impl() const;
109 virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
110 virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
111
112private:
113 INLINE void check_sorted() const;
114 void sort_on_stages();
115
116private:
117 class StageNode {
118 public:
119 INLINE StageNode(const TextureStage *stage,
120 unsigned int implicit_sort = 0,
121 int override = 0);
122
123 SamplerState _sampler;
124 PT(TextureStage) _stage;
125 PT(Texture) _texture;
126 bool _has_sampler;
127 int _ff_tc_index;
128 unsigned int _implicit_sort;
129 int _override;
130 };
131
132 class CompareTextureStagePriorities {
133 public:
134 INLINE bool operator () (const TextureAttrib::StageNode *a, const TextureAttrib::StageNode *b) const;
135 };
136
137 class CompareTextureStageSort {
138 public:
139 INLINE bool operator () (const TextureAttrib::StageNode *a, const TextureAttrib::StageNode *b) const;
140 };
141
142 class CompareTextureStagePointer {
143 public:
144 INLINE bool operator () (const TextureAttrib::StageNode &a, const TextureAttrib::StageNode &b) const;
145 };
146
147 typedef ov_set<StageNode, CompareTextureStagePointer, epvector<StageNode> > Stages;
148 Stages _on_stages; // set of all "on" stages, indexed by pointer.
149
150 typedef pvector<StageNode *> RenderStages;
151 RenderStages _render_stages; // all "on" stages, sorted in render order.
152 RenderStages _render_ff_stages; // fixed-function stages only, in render order.
153 unsigned int _next_implicit_sort;
154
155 Stages _off_stages;
156 bool _off_all_stages;
157
158 typedef pmap< int, CPT(TextureAttrib) > Filtered;
159 Filtered _filtered;
160
161 UpdateSeq _sort_seq;
162 UpdateSeq _filtered_seq;
163
164 static CPT(RenderAttrib) _empty_attrib;
165 static CPT(RenderAttrib) _all_off_attrib;
166
167PUBLISHED:
168 static int get_class_slot() {
169 return _attrib_slot;
170 }
171 virtual int get_slot() const {
172 return get_class_slot();
173 }
174 MAKE_PROPERTY(class_slot, get_class_slot);
175
176public:
177 static void register_with_read_factory();
178 virtual void write_datagram(BamWriter *manager, Datagram &dg);
179 virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
180
181protected:
182 static TypedWritable *make_from_bam(const FactoryParams &params);
183 void fillin(DatagramIterator &scan, BamReader *manager);
184
185public:
186 static TypeHandle get_class_type() {
187 return _type_handle;
188 }
189 static void init_type() {
190 RenderAttrib::init_type();
191 register_type(_type_handle, "TextureAttrib",
192 RenderAttrib::get_class_type());
193 _attrib_slot = register_slot(_type_handle, 30, new TextureAttrib);
194 }
195 virtual TypeHandle get_type() const {
196 return get_class_type();
197 }
198 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
199
200private:
201 static TypeHandle _type_handle;
202 static int _attrib_slot;
203};
204
205#include "textureAttrib.I"
206
207#endif
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
virtual bool cull_callback(CullTraverser *trav, const CullTraverserData &data) const
If has_cull_callback() returns true, this function will be called during the cull traversal to perfor...
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 bool has_cull_callback() const
Should be overridden by derived classes to return true if cull_callback() has been defined.
virtual bool lower_attrib_can_override() const
Intended to be overridden by derived RenderAttrib types to specify how two consecutive RenderAttrib o...
static int register_slot(TypeHandle type_handle, int sort, RenderAttrib *default_attrib)
Adds the indicated TypeHandle to the registry, if it is not there already, and returns a unique slot ...
Represents a set of settings that indicate how a texture is sampled.
static ConstPointerTo< RenderAttrib > make(Texture *tex)
Constructs a new TextureAttrib object suitable for rendering the indicated texture onto geometry,...
get_num_on_ff_stages
Returns the number of on-stages that are relevant to the classic fixed function pipeline.
ConstPointerTo< TextureAttrib > filter_to_max(int max_texture_stages) const
Returns a new TextureAttrib, very much like this one, but with the number of on_stages reduced to be ...
ConstPointerTo< RenderAttrib > unify_texture_stages(TextureStage *stage) const
Returns a new TextureAttrib, just like this one, but with any included TextureAttribs that happen to ...
get_num_on_stages
Returns the number of stages that are turned on by the attribute.
bool is_identity() const
Returns true if this is an identity attrib: it does not change the set of stages in use.
ConstPointerTo< RenderAttrib > remove_off_stage(TextureStage *stage) const
Returns a new TextureAttrib, just like this one, but with the indicated stage removed from the list o...
has_on_stage
Returns true if the indicated stage is turned on by the attrib, false otherwise.
bool has_off_stage(TextureStage *stage) const
Returns true if the indicated stage is turned off by the attrib, false otherwise.
Texture * get_texture() const
If the TextureAttrib is not an 'off' TextureAttrib, returns the base-level texture that is associated...
get_on_texture
Returns the texture associated with the indicated stage, or NULL if no texture is associated.
int find_on_stage(const TextureStage *stage) const
Returns the index number of the indicated TextureStage within the list of on_stages,...
get_off_stage
Returns the nth stage turned off by the attribute, sorted in arbitrary (pointer) order.
ConstPointerTo< RenderAttrib > add_off_stage(TextureStage *stage, int override=0) const
Returns a new TextureAttrib, just like this one, but with the indicated stage added to the list of st...
bool is_off() const
Returns true if the TextureAttrib is an 'off' TextureAttrib, indicating that it should disable textur...
get_on_stage
Returns the nth stage turned on by the attribute, sorted in render order.
get_on_sampler
Returns the sampler associated with the indicated stage, or the one associated with its texture if no...
static ConstPointerTo< RenderAttrib > make_all_off()
Constructs a new TextureAttrib object that turns off all stages (and hence disables texturing).
static ConstPointerTo< RenderAttrib > make_default()
Returns a RenderAttrib that corresponds to whatever the standard default properties for render attrib...
get_on_ff_stage
Returns the nth stage turned on by the attribute, sorted in render order, including only those releva...
int get_ff_tc_index(int n) const
For each TextureStage listed in get_on_ff_stage(), this returns a unique index number for the texture...
ConstPointerTo< RenderAttrib > replace_texture(Texture *tex, Texture *new_tex) const
Returns a new TextureAttrib, just like this one, but with all references to the given texture replace...
ConstPointerTo< RenderAttrib > add_on_stage(TextureStage *stage, Texture *tex, int override=0) const
Returns a new TextureAttrib, just like this one, but with the indicated stage added to the list of st...
bool has_all_off() const
Returns true if this attrib turns off all stages (although it may also turn some on).
static ConstPointerTo< RenderAttrib > make_off()
Constructs a new TextureAttrib object suitable for rendering untextured geometry.
ConstPointerTo< RenderAttrib > remove_on_stage(TextureStage *stage) const
Returns a new TextureAttrib, just like this one, but with the indicated stage removed from the list o...
get_num_off_stages
Returns the number of stages that are turned off by the attribute.
int get_on_stage_override(TextureStage *stage) const
Returns the override value associated with the indicated stage.
Defines the properties of a named stage of the multitexture pipeline.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition texture.h:72
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().
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.