Panda3D

texGenAttrib.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 texGenAttrib.h
10 * @author masad
11 * @date 2004-06-21
12 */
13
14 #ifndef TEXGENATTRIB_H
15 #define TEXGENATTRIB_H
16
17 #include "pandabase.h"
18
19 #include "geom.h"
20 #include "renderAttrib.h"
21 #include "textureStage.h"
22 #include "texture.h"
23 #include "pointerTo.h"
24 #include "nodePath.h"
25
26 /**
27 * Computes texture coordinates for geometry automatically based on vertex
28 * position and/or normal. This can be used to implement reflection and/or
29 * refraction maps, for instance to make shiny surfaces, as well as other
30 * special effects such as projective texturing.
31 */
32 class EXPCL_PANDA_PGRAPH TexGenAttrib : public RenderAttrib {
33 PUBLISHED:
34 // We inherit the definition of our Mode enumerated type from RenderAttrib.
35 // Normally, Mode would be defined here, but we define it in the base class
36 // instead as a hack to avoid a problem with circular includes.
37 typedef RenderAttrib::TexGenMode Mode;
38
39 protected:
40 INLINE TexGenAttrib();
41 INLINE TexGenAttrib(const TexGenAttrib &copy);
42
43 public:
44 virtual ~TexGenAttrib();
45
46 PUBLISHED:
47 static CPT(RenderAttrib) make();
48 static CPT(RenderAttrib) make(TextureStage *stage, Mode mode);
49 static CPT(RenderAttrib) make_default();
50
51 CPT(RenderAttrib) add_stage(TextureStage *stage, Mode mode) const;
52 CPT(RenderAttrib) add_stage(TextureStage *stage, Mode mode, const LTexCoord3 &constant_value) const;
53 CPT(RenderAttrib) remove_stage(TextureStage *stage) const;
54
55 bool is_empty() const;
56 bool has_stage(TextureStage *stage) const;
57 Mode get_mode(TextureStage *stage) const;
58 bool has_gen_texcoord_stage(TextureStage *stage) const;
59 const LTexCoord3 &get_constant_value(TextureStage *stage) const;
60
61 INLINE int get_geom_rendering(int geom_rendering) const;
62
63 public:
64 virtual void output(std::ostream &out) const;
65
66 protected:
67 virtual int compare_to_impl(const RenderAttrib *other) const;
68 virtual size_t get_hash_impl() const;
69 virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
70 virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
71
72 private:
73 class ModeDef;
74 void filled_stages();
75 void record_stage(TextureStage *stage, ModeDef &mode_def);
76
77 class ModeDef {
78 public:
79 INLINE ModeDef();
80 INLINE int compare_to(const ModeDef &other) const;
81 Mode _mode;
82 std::string _source_name;
83 NodePath _light;
84 LTexCoord3 _constant_value;
85 };
86 typedef pmap<PT(TextureStage), ModeDef> Stages;
87 Stages _stages;
88
89 // This is a set of TextureStage pointers for which texture coordinates will
90 // not be needed from the Geom. It's redundant; it's almost the same set
91 // that is listed in _stages, above. It's just here as an optimization
92 // during rendering.
93 typedef pset<TextureStage *> NoTexCoordStages;
94 NoTexCoordStages _no_texcoords;
95
96 // This element is only used during reading from a bam file. It has no
97 // meaningful value any other time.
98 pvector<Mode> _read_modes;
99
100 int _num_point_sprites;
101
102 // _point_geom_rendering is the GeomRendering bits that are added by the
103 // TexGenAttrib if there are any points in the Geom. _geom_rendering is the
104 // GeomRendering bits that are added regardless of the kind of Geom it is.
105 int _point_geom_rendering;
106 int _geom_rendering;
107
108 static CPT(RenderAttrib) _empty_attrib;
109
110 PUBLISHED:
111 static int get_class_slot() {
112 return _attrib_slot;
113 }
114 virtual int get_slot() const {
115 return get_class_slot();
116 }
117 MAKE_PROPERTY(class_slot, get_class_slot);
118
119 public:
120 static void register_with_read_factory();
121 virtual void write_datagram(BamWriter *manager, Datagram &dg);
122 virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
123
124 protected:
125 static TypedWritable *make_from_bam(const FactoryParams &params);
126 void fillin(DatagramIterator &scan, BamReader *manager);
127
128 public:
129 static TypeHandle get_class_type() {
130 return _type_handle;
131 }
132 static void init_type() {
133 RenderAttrib::init_type();
134 register_type(_type_handle, "TexGenAttrib",
135 RenderAttrib::get_class_type());
136 _attrib_slot = register_slot(_type_handle, 100, new TexGenAttrib);
137 }
138 virtual TypeHandle get_type() const {
139 return get_class_type();
140 }
141 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
142
143 private:
144 static TypeHandle _type_handle;
145 static int _attrib_slot;
146 };
147
148 #include "texGenAttrib.I"
149
150 #endif
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
BamWriter
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition: datagramIterator.h:27
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
NodePath
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:159
RenderAttrib
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:51
RenderAttrib::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: renderAttrib.cxx:527
RenderAttrib::register_slot
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 ...
Definition: renderAttrib.I:101
TexGenAttrib
Computes texture coordinates for geometry automatically based on vertex position and/or normal.
Definition: texGenAttrib.h:32
TextureStage
Defines the properties of a named stage of the multitexture pipeline.
Definition: textureStage.h:35
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
TypedWritable::complete_pointers
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().
Definition: typedWritable.cxx:81
compare_to
An STL function object class, this is intended to be used on any ordered collection of class objects ...
Definition: stl_compares.h:73
plist
This is our own Panda specialization on the default STL list.
Definition: plist.h:35
pmap
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
pset< TextureStage * >
pvector< Mode >
geom.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
nodePath.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
renderAttrib.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
texGenAttrib.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
textureStage.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
texture.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.