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
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 is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
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,...
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...
This is the base class for a number of render attributes (other than transform) that may be set on sc...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
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.
Indicates the set of TextureStages and their associated Textures that should be applied to (or remove...
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 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...
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
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
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
A specialization of ordered_vector that emulates a standard STL set: one copy of each element is allo...
This is our own Panda specialization on the default STL list.
Definition plist.h:35
This is our own Panda specialization on the default STL map.
Definition pmap.h:49
This is our own Panda specialization on the default STL vector.
Definition pvector.h:42
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.