Panda3D
Loading...
Searching...
No Matches
texMatrixAttrib.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 texMatrixAttrib.h
10 * @author drose
11 * @date 2002-03-14
12 */
13
14#ifndef TEXMATRIXATTRIB_H
15#define TEXMATRIXATTRIB_H
16
17#include "pandabase.h"
18
19#include "geom.h"
20#include "renderAttrib.h"
21#include "textureStage.h"
22#include "transformState.h"
23#include "pointerTo.h"
24
25class FactoryParams;
26
27/**
28 * Applies a transform matrix to UV's before they are rendered.
29 */
30class EXPCL_PANDA_PGRAPH TexMatrixAttrib : public RenderAttrib {
31protected:
32 INLINE TexMatrixAttrib();
33 INLINE TexMatrixAttrib(const TexMatrixAttrib &copy);
34
35public:
36 virtual ~TexMatrixAttrib();
37
38PUBLISHED:
39 static CPT(RenderAttrib) make();
40 static CPT(RenderAttrib) make(const LMatrix4 &mat);
41 static CPT(RenderAttrib) make(TextureStage *stage, const TransformState *transform);
42 static CPT(RenderAttrib) make_default();
43
44 CPT(RenderAttrib) add_stage(TextureStage *stage, const TransformState *transform, int override = 0) const;
45 CPT(RenderAttrib) remove_stage(TextureStage *stage) const;
46
47 bool is_empty() const;
48 bool has_stage(TextureStage *stage) const;
49
50 int get_num_stages() const;
51 TextureStage *get_stage(int n) const;
52 MAKE_SEQ(get_stages, get_num_stages, get_stage);
53
54 const LMatrix4 &get_mat() const;
55 const LMatrix4 &get_mat(TextureStage *stage) const;
56
57 CPT(TransformState) get_transform(TextureStage *stage) const;
58 INLINE int get_override(TextureStage *stage) const;
59
60 INLINE int get_geom_rendering(int geom_rendering) const;
61
62public:
63 virtual void output(std::ostream &out) const;
64
65protected:
66 virtual int compare_to_impl(const RenderAttrib *other) const;
67 virtual size_t get_hash_impl() const;
68 virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
69 virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
70
71private:
72 INLINE void check_stage_list() const;
73 void rebuild_stage_list();
74
75private:
76 class StageNode {
77 public:
78 INLINE StageNode(const TextureStage *stage);
79
80 INLINE bool operator < (const StageNode &other) const;
81
82 PT(TextureStage) _stage;
83 CPT(TransformState) _transform;
84 int _override;
85 };
86
87 class CompareTextureStagePointer {
88 public:
89 INLINE bool operator () (const TexMatrixAttrib::StageNode &a, const TexMatrixAttrib::StageNode &b) const;
90 };
91
92 typedef ov_set<StageNode, CompareTextureStagePointer> Stages;
93 Stages _stages;
94
95 static CPT(RenderAttrib) _empty_attrib;
96
97PUBLISHED:
98 static int get_class_slot() {
99 return _attrib_slot;
100 }
101 virtual int get_slot() const {
102 return get_class_slot();
103 }
104 MAKE_PROPERTY(class_slot, get_class_slot);
105
106public:
107 static void register_with_read_factory();
108 virtual void write_datagram(BamWriter *manager, Datagram &dg);
109 virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
110
111protected:
112 static TypedWritable *make_from_bam(const FactoryParams &params);
113 void fillin(DatagramIterator &scan, BamReader *manager);
114
115public:
116 static TypeHandle get_class_type() {
117 return _type_handle;
118 }
119 static void init_type() {
120 RenderAttrib::init_type();
121 register_type(_type_handle, "TexMatrixAttrib",
122 RenderAttrib::get_class_type());
123 _attrib_slot = register_slot(_type_handle, 100, new TexMatrixAttrib);
124 }
125 virtual TypeHandle get_type() const {
126 return get_class_type();
127 }
128 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
129
130private:
131 static TypeHandle _type_handle;
132 static int _attrib_slot;
133};
134
135#include "texMatrixAttrib.I"
136
137#endif
An instance of this class is passed to the Factory when requesting it to do its business and construc...
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 ...
bool is_empty() const
Returns true if no stages are defined in the TexMatrixAttrib, false if at least one is.
ConstPointerTo< TransformState > get_transform(TextureStage *stage) const
Returns the transformation associated with the indicated texture stage, or identity matrix if nothing...
static ConstPointerTo< RenderAttrib > make()
Constructs a TexMatrixAttrib that applies no stages at all.
const LMatrix4 & get_mat() const
Returns the transformation matrix associated with the default texture stage.
ConstPointerTo< RenderAttrib > add_stage(TextureStage *stage, const TransformState *transform, int override=0) const
Returns a new TexMatrixAttrib just like this one, with the indicated transform for the given stage.
ConstPointerTo< RenderAttrib > remove_stage(TextureStage *stage) const
Returns a new TexMatrixAttrib just like this one, with the indicated stage removed.
bool has_stage(TextureStage *stage) const
Returns true if there is a transform associated with the indicated stage, or false otherwise (in whic...
get_num_stages
Returns the number of stages that are represented by this attrib.
int get_override(TextureStage *stage) const
Returns the override value associated with the indicated stage.
static ConstPointerTo< RenderAttrib > make_default()
Returns a RenderAttrib that corresponds to whatever the standard default properties for render attrib...
int get_geom_rendering(int geom_rendering) const
Returns the union of the Geom::GeomRendering bits that will be required once this TexMatrixAttrib is ...
get_stage
Returns the nth stage that is represented by this attrib.
Defines the properties of a named stage of the multitexture pipeline.
Indicates a coordinate-system transform on vertices.
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.