Skip to content

Commit 2fa7929

Browse files
committed
dynamic TextFont; scene graph improvements to support this
1 parent 8e63f99 commit 2fa7929

18 files changed

+1004
-612
lines changed

panda/src/pgraph/Sources.pp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define TARGET pgraph
99

1010
#define SOURCES \
11+
accumulatedAttribs.I accumulatedAttribs.h \
1112
alphaTestAttrib.I alphaTestAttrib.h \
1213
ambientLight.I ambientLight.h \
1314
bamFile.I bamFile.h \
@@ -91,6 +92,7 @@
9192

9293
#define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx
9394
#define INCLUDED_SOURCES \
95+
accumulatedAttribs.cxx \
9496
alphaTestAttrib.cxx \
9597
ambientLight.cxx \
9698
bamFile.cxx \
@@ -173,6 +175,7 @@
173175
workingNodePath.cxx
174176

175177
#define INSTALL_HEADERS \
178+
accumulatedAttribs.I accumulatedAttribs.h \
176179
alphaTestAttrib.I alphaTestAttrib.h \
177180
ambientLight.I ambientLight.h \
178181
bamFile.I bamFile.h \
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Filename: accumulatedAttribs.I
2+
// Created by: drose (30Jan03)
3+
//
4+
////////////////////////////////////////////////////////////////////
5+
//
6+
// PANDA 3D SOFTWARE
7+
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
8+
//
9+
// All use of this software is subject to the terms of the Panda 3d
10+
// Software license. You should have received a copy of this license
11+
// along with this source code; you will also find a current copy of
12+
// the license at http://www.panda3d.org/license.txt .
13+
//
14+
// To contact the maintainers of this program write to
15+
// panda3d@yahoogroups.com .
16+
//
17+
////////////////////////////////////////////////////////////////////
18+
19+
20+
////////////////////////////////////////////////////////////////////
21+
// Function: AccumulatedAttribs::Constructor
22+
// Access: Public
23+
// Description:
24+
////////////////////////////////////////////////////////////////////
25+
INLINE AccumulatedAttribs::
26+
AccumulatedAttribs() {
27+
_transform = TransformState::make_identity();
28+
_other = RenderState::make_empty();
29+
}
30+
31+
////////////////////////////////////////////////////////////////////
32+
// Function: AccumulatedAttribs::Copy Constructor
33+
// Access: Public
34+
// Description:
35+
////////////////////////////////////////////////////////////////////
36+
INLINE AccumulatedAttribs::
37+
AccumulatedAttribs(const AccumulatedAttribs &copy) :
38+
_transform(copy._transform),
39+
_color(copy._color),
40+
_color_scale(copy._color_scale),
41+
_tex_matrix(copy._tex_matrix),
42+
_other(copy._other)
43+
{
44+
}
45+
46+
////////////////////////////////////////////////////////////////////
47+
// Function: AccumulatedAttribs::Copy Assignment
48+
// Access: Public
49+
// Description:
50+
////////////////////////////////////////////////////////////////////
51+
INLINE void AccumulatedAttribs::
52+
operator = (const AccumulatedAttribs &copy) {
53+
_transform = copy._transform;
54+
_color = copy._color;
55+
_color_scale = copy._color_scale;
56+
_tex_matrix = copy._tex_matrix;
57+
_other = copy._other;
58+
}
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
// Filename: accumulatedAttribs.cxx
2+
// Created by: drose (30Jan03)
3+
//
4+
////////////////////////////////////////////////////////////////////
5+
//
6+
// PANDA 3D SOFTWARE
7+
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
8+
//
9+
// All use of this software is subject to the terms of the Panda 3d
10+
// Software license. You should have received a copy of this license
11+
// along with this source code; you will also find a current copy of
12+
// the license at http://www.panda3d.org/license.txt .
13+
//
14+
// To contact the maintainers of this program write to
15+
// panda3d@yahoogroups.com .
16+
//
17+
////////////////////////////////////////////////////////////////////
18+
19+
#include "accumulatedAttribs.h"
20+
#include "sceneGraphReducer.h"
21+
#include "geomTransformer.h"
22+
#include "pandaNode.h"
23+
#include "colorAttrib.h"
24+
#include "colorScaleAttrib.h"
25+
#include "texMatrixAttrib.h"
26+
#include "config_pgraph.h"
27+
28+
29+
////////////////////////////////////////////////////////////////////
30+
// Function: AccumulatedAttribs::write
31+
// Access: Public
32+
// Description:
33+
////////////////////////////////////////////////////////////////////
34+
void AccumulatedAttribs::
35+
write(ostream &out, int attrib_types, int indent_level) const {
36+
if ((attrib_types & SceneGraphReducer::TT_transform) != 0) {
37+
_transform->write(out, indent_level);
38+
}
39+
if ((attrib_types & SceneGraphReducer::TT_color) != 0) {
40+
if (_color == (const RenderAttrib *)NULL) {
41+
indent(out, indent_level) << "no color\n";
42+
} else {
43+
_color->write(out, indent_level);
44+
}
45+
}
46+
if ((attrib_types & SceneGraphReducer::TT_color_scale) != 0) {
47+
if (_color_scale == (const RenderAttrib *)NULL) {
48+
indent(out, indent_level) << "no color scale\n";
49+
} else {
50+
_color_scale->write(out, indent_level);
51+
}
52+
}
53+
if ((attrib_types & SceneGraphReducer::TT_tex_matrix) != 0) {
54+
if (_tex_matrix == (const RenderAttrib *)NULL) {
55+
indent(out, indent_level) << "no tex matrix\n";
56+
} else {
57+
_tex_matrix->write(out, indent_level);
58+
}
59+
}
60+
if ((attrib_types & SceneGraphReducer::TT_other) != 0) {
61+
_other->write(out, indent_level);
62+
}
63+
}
64+
65+
////////////////////////////////////////////////////////////////////
66+
// Function: AccumulatedAttribs::collect
67+
// Access: Public
68+
// Description: Collects the state and transform from the indicated
69+
// node and adds it to the accumulator, removing it from
70+
// the node.
71+
////////////////////////////////////////////////////////////////////
72+
void AccumulatedAttribs::
73+
collect(PandaNode *node, int attrib_types) {
74+
if ((attrib_types & SceneGraphReducer::TT_transform) != 0) {
75+
// Collect the node's transform.
76+
nassertv(_transform != (TransformState *)NULL);
77+
_transform = _transform->compose(node->get_transform());
78+
node->set_transform(TransformState::make_identity());
79+
}
80+
81+
if ((attrib_types & SceneGraphReducer::TT_color) != 0) {
82+
const RenderAttrib *node_attrib =
83+
node->get_attrib(ColorAttrib::get_class_type());
84+
if (node_attrib != (const RenderAttrib *)NULL) {
85+
// The node has a color attribute; apply it.
86+
if (_color == (const RenderAttrib *)NULL) {
87+
_color = node_attrib;
88+
} else {
89+
_color = _color->compose(node_attrib);
90+
}
91+
node->clear_attrib(ColorAttrib::get_class_type());
92+
}
93+
}
94+
95+
if ((attrib_types & SceneGraphReducer::TT_color_scale) != 0) {
96+
const RenderAttrib *node_attrib =
97+
node->get_attrib(ColorScaleAttrib::get_class_type());
98+
if (node_attrib != (const RenderAttrib *)NULL) {
99+
// The node has a color scale attribute; apply it.
100+
if (_color_scale == (const RenderAttrib *)NULL) {
101+
_color_scale = node_attrib;
102+
} else {
103+
_color_scale = _color_scale->compose(node_attrib);
104+
}
105+
node->clear_attrib(ColorScaleAttrib::get_class_type());
106+
}
107+
}
108+
109+
if ((attrib_types & SceneGraphReducer::TT_tex_matrix) != 0) {
110+
const RenderAttrib *node_attrib =
111+
node->get_attrib(TexMatrixAttrib::get_class_type());
112+
if (node_attrib != (const RenderAttrib *)NULL) {
113+
// The node has a tex matrix attribute; apply it.
114+
if (_tex_matrix == (const RenderAttrib *)NULL) {
115+
_tex_matrix = node_attrib;
116+
} else {
117+
_tex_matrix = _tex_matrix->compose(node_attrib);
118+
}
119+
node->clear_attrib(TexMatrixAttrib::get_class_type());
120+
}
121+
}
122+
123+
if ((attrib_types & SceneGraphReducer::TT_transform) != 0) {
124+
// Collect everything else.
125+
nassertv(_other != (RenderState *)NULL);
126+
_other = _other->compose(node->get_state());
127+
node->set_state(RenderState::make_empty());
128+
}
129+
}
130+
131+
////////////////////////////////////////////////////////////////////
132+
// Function: AccumulatedAttribs::apply_to_node
133+
// Access: Public
134+
// Description: Stores the indicated attributes in the node's
135+
// transform and state information; does not attempt to
136+
// apply the properties to the vertices. Clears the
137+
// attributes from the accumulator for future
138+
// traversals.
139+
////////////////////////////////////////////////////////////////////
140+
void AccumulatedAttribs::
141+
apply_to_node(PandaNode *node, int attrib_types) {
142+
if ((attrib_types & SceneGraphReducer::TT_transform) != 0) {
143+
node->set_transform(_transform->compose(node->get_transform()));
144+
_transform = TransformState::make_identity();
145+
}
146+
147+
if ((attrib_types & SceneGraphReducer::TT_color) != 0) {
148+
if (_color != (RenderAttrib *)NULL) {
149+
const RenderAttrib *node_attrib =
150+
node->get_attrib(ColorAttrib::get_class_type());
151+
if (node_attrib != (RenderAttrib *)NULL) {
152+
node->set_attrib(_color->compose(node_attrib));
153+
} else {
154+
node->set_attrib(_color);
155+
}
156+
_color = (RenderAttrib *)NULL;
157+
}
158+
}
159+
160+
if ((attrib_types & SceneGraphReducer::TT_color_scale) != 0) {
161+
if (_color_scale != (RenderAttrib *)NULL) {
162+
const RenderAttrib *node_attrib =
163+
node->get_attrib(ColorScaleAttrib::get_class_type());
164+
if (node_attrib != (RenderAttrib *)NULL) {
165+
node->set_attrib(_color_scale->compose(node_attrib));
166+
} else {
167+
node->set_attrib(_color_scale);
168+
}
169+
_color_scale = (RenderAttrib *)NULL;
170+
}
171+
}
172+
173+
if ((attrib_types & SceneGraphReducer::TT_tex_matrix) != 0) {
174+
if (_tex_matrix != (RenderAttrib *)NULL) {
175+
const RenderAttrib *node_attrib =
176+
node->get_attrib(TexMatrixAttrib::get_class_type());
177+
if (node_attrib != (RenderAttrib *)NULL) {
178+
node->set_attrib(_tex_matrix->compose(node_attrib));
179+
} else {
180+
node->set_attrib(_tex_matrix);
181+
}
182+
_tex_matrix = (RenderAttrib *)NULL;
183+
}
184+
}
185+
186+
if ((attrib_types & SceneGraphReducer::TT_other) != 0) {
187+
node->set_state(_other->compose(node->get_state()));
188+
_other = RenderState::make_empty();
189+
}
190+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Filename: accumulatedAttribs.h
2+
// Created by: drose (30Jan03)
3+
//
4+
////////////////////////////////////////////////////////////////////
5+
//
6+
// PANDA 3D SOFTWARE
7+
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
8+
//
9+
// All use of this software is subject to the terms of the Panda 3d
10+
// Software license. You should have received a copy of this license
11+
// along with this source code; you will also find a current copy of
12+
// the license at http://www.panda3d.org/license.txt .
13+
//
14+
// To contact the maintainers of this program write to
15+
// panda3d@yahoogroups.com .
16+
//
17+
////////////////////////////////////////////////////////////////////
18+
19+
#ifndef ACCUMULATEDATTRIBS_H
20+
#define ACCUMULATEDATTRIBS_H
21+
22+
#include "pandabase.h"
23+
#include "transformState.h"
24+
#include "renderAttrib.h"
25+
#include "renderState.h"
26+
#include "pointerTo.h"
27+
28+
class PandaNode;
29+
30+
///////////////////////////////////////////////////////////////////
31+
// Class : AccumulatedAttribs
32+
// Description : This class is used by the SceneGraphReducer to
33+
// maintain and accumulate the set of attributes we have
34+
// encountered on each node that might eventually be
35+
// applied to the vertices at the leaves.
36+
////////////////////////////////////////////////////////////////////
37+
class EXPCL_PANDA AccumulatedAttribs {
38+
public:
39+
INLINE AccumulatedAttribs();
40+
INLINE AccumulatedAttribs(const AccumulatedAttribs &copy);
41+
INLINE void operator = (const AccumulatedAttribs &copy);
42+
43+
void write(ostream &out, int attrib_types, int indent_level) const;
44+
45+
void collect(PandaNode *node, int attrib_types);
46+
void apply_to_node(PandaNode *node, int attrib_types);
47+
48+
CPT(TransformState) _transform;
49+
CPT(RenderAttrib) _color;
50+
CPT(RenderAttrib) _color_scale;
51+
CPT(RenderAttrib) _tex_matrix;
52+
CPT(RenderState) _other;
53+
};
54+
55+
#include "accumulatedAttribs.I"
56+
57+
#endif
58+
59+

0 commit comments

Comments
 (0)