Panda3D
geomPoints.cxx
1 // Filename: geomPoints.cxx
2 // Created by: drose (22Mar05)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "geomPoints.h"
16 #include "pStatTimer.h"
17 #include "bamReader.h"
18 #include "bamWriter.h"
19 #include "graphicsStateGuardianBase.h"
20 
21 TypeHandle GeomPoints::_type_handle;
22 
23 ////////////////////////////////////////////////////////////////////
24 // Function: GeomPoints::Constructor
25 // Access: Published
26 // Description:
27 ////////////////////////////////////////////////////////////////////
28 GeomPoints::
29 GeomPoints(GeomPoints::UsageHint usage_hint) :
30  GeomPrimitive(usage_hint)
31 {
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: GeomPoints::Copy Constructor
36 // Access: Published
37 // Description:
38 ////////////////////////////////////////////////////////////////////
39 GeomPoints::
40 GeomPoints(const GeomPoints &copy) :
41  GeomPrimitive(copy)
42 {
43 }
44 
45 ////////////////////////////////////////////////////////////////////
46 // Function: GeomPoints::Destructor
47 // Access: Published, Virtual
48 // Description:
49 ////////////////////////////////////////////////////////////////////
50 GeomPoints::
51 ~GeomPoints() {
52 }
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function: GeomPoints::make_copy
56 // Access: Public, Virtual
57 // Description:
58 ////////////////////////////////////////////////////////////////////
59 PT(GeomPrimitive) GeomPoints::
60 make_copy() const {
61  return new GeomPoints(*this);
62 }
63 
64 ////////////////////////////////////////////////////////////////////
65 // Function: GeomPoints::get_primitive_type
66 // Access: Public, Virtual
67 // Description: Returns the fundamental rendering type of this
68 // primitive: whether it is points, lines, or polygons.
69 //
70 // This is used to set up the appropriate antialiasing
71 // settings when AntialiasAttrib::M_auto is in effect;
72 // it also implies the type of primitive that will be
73 // produced when decompose() is called.
74 ////////////////////////////////////////////////////////////////////
75 GeomPrimitive::PrimitiveType GeomPoints::
76 get_primitive_type() const {
77  return PT_points;
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: GeomPoints::get_geom_rendering
82 // Access: Published, Virtual
83 // Description: Returns the set of GeomRendering bits that represent
84 // the rendering properties required to properly render
85 // this primitive.
86 ////////////////////////////////////////////////////////////////////
87 int GeomPoints::
88 get_geom_rendering() const {
89  // Fancy point attributes, if any, are based on whether the
90  // appropriate columns are defined in the associated GeomVertexData;
91  // these bits will be added by Geom::get_geom_rendering().
92  if (is_indexed()) {
93  return GR_point | GR_indexed_point;
94  } else {
95  return GR_point;
96  }
97 }
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function: GeomPoints::get_num_vertices_per_primitive
101 // Access: Public, Virtual
102 // Description: If the primitive type is a simple type in which all
103 // primitives have the same number of vertices, like
104 // points, returns the number of vertices per
105 // primitive. If the primitive type is a more complex
106 // type in which different primitives might have
107 // different numbers of vertices, for instance a
108 // point strip, returns 0.
109 ////////////////////////////////////////////////////////////////////
110 int GeomPoints::
112  return 1;
113 }
114 
115 ////////////////////////////////////////////////////////////////////
116 // Function: GeomPoints::get_min_num_vertices_per_primitive
117 // Access: Public, Virtual
118 // Description: Returns the minimum number of vertices that must be
119 // added before close_primitive() may legally be called.
120 ////////////////////////////////////////////////////////////////////
121 int GeomPoints::
123  return 1;
124 }
125 
126 ////////////////////////////////////////////////////////////////////
127 // Function: GeomPoints::draw
128 // Access: Public, Virtual
129 // Description: Calls the appropriate method on the GSG to draw the
130 // primitive.
131 ////////////////////////////////////////////////////////////////////
132 bool GeomPoints::
134  bool force) const {
135  return gsg->draw_points(reader, force);
136 }
137 
138 ////////////////////////////////////////////////////////////////////
139 // Function: GeomPoints::register_with_read_factory
140 // Access: Public, Static
141 // Description: Tells the BamReader how to create objects of type
142 // Geom.
143 ////////////////////////////////////////////////////////////////////
144 void GeomPoints::
145 register_with_read_factory() {
146  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
147 }
148 
149 ////////////////////////////////////////////////////////////////////
150 // Function: GeomPoints::make_from_bam
151 // Access: Protected, Static
152 // Description: This function is called by the BamReader's factory
153 // when a new object of type Geom is encountered
154 // in the Bam file. It should create the Geom
155 // and extract its information from the file.
156 ////////////////////////////////////////////////////////////////////
157 TypedWritable *GeomPoints::
158 make_from_bam(const FactoryParams &params) {
159  GeomPoints *object = new GeomPoints(UH_unspecified);
160  DatagramIterator scan;
161  BamReader *manager;
162 
163  parse_params(params, scan, manager);
164  object->fillin(scan, manager);
165 
166  return object;
167 }
virtual int get_min_num_vertices_per_primitive() const
Returns the minimum number of vertices that must be added before close_primitive() may legally be cal...
Defines a series of disconnected points.
Definition: geomPoints.h:25
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
Definition: geomPrimitive.h:63
virtual int get_geom_rendering() const
Returns the set of GeomRendering bits that represent the rendering properties required to properly re...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:90
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:213
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
Encapsulates the data from a GeomPrimitive, pre-fetched for one stage of the pipeline.
virtual int get_num_vertices_per_primitive() const
If the primitive type is a simple type in which all primitives have the same number of vertices...
bool is_indexed() const
Returns true if the primitive is indexed, false otherwise.