Panda3D
geomTristripsAdjacency.cxx
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 geomTristripsAdjacency.cxx
10  * @author rdb
11  * @date 2018-03-01
12  */
13 
14 #include "geomTristripsAdjacency.h"
15 #include "geomTriangles.h"
16 #include "geomVertexRewriter.h"
17 #include "pStatTimer.h"
18 #include "bamReader.h"
19 #include "bamWriter.h"
21 
22 TypeHandle GeomTristripsAdjacency::_type_handle;
23 
24 /**
25  *
26  */
27 GeomTristripsAdjacency::
28 GeomTristripsAdjacency(GeomTristripsAdjacency::UsageHint usage_hint) :
29  GeomPrimitive(usage_hint)
30 {
31 }
32 
33 /**
34  *
35  */
36 GeomTristripsAdjacency::
37 GeomTristripsAdjacency(const GeomTristripsAdjacency &copy) :
38  GeomPrimitive(copy)
39 {
40 }
41 
42 /**
43  *
44  */
45 GeomTristripsAdjacency::
46 ~GeomTristripsAdjacency() {
47 }
48 
49 /**
50  *
51  */
52 PT(GeomPrimitive) GeomTristripsAdjacency::
53 make_copy() const {
54  return new GeomTristripsAdjacency(*this);
55 }
56 
57 /**
58  * Returns the fundamental rendering type of this primitive: whether it is
59  * points, lines, or polygons.
60  *
61  * This is used to set up the appropriate antialiasing settings when
62  * AntialiasAttrib::M_auto is in effect; it also implies the type of primitive
63  * that will be produced when decompose() is called.
64  */
65 GeomPrimitive::PrimitiveType GeomTristripsAdjacency::
66 get_primitive_type() const {
67  return PT_polygons;
68 }
69 
70 /**
71  * Returns the set of GeomRendering bits that represent the rendering
72  * properties required to properly render this primitive.
73  */
74 int GeomTristripsAdjacency::
75 get_geom_rendering() const {
76  if (is_indexed()) {
77  if (get_num_primitives() > 1) {
78  return GR_triangle_strip | GR_indexed_other | GR_strip_cut_index | GR_adjacency;
79  } else {
80  return GR_triangle_strip | GR_indexed_other | GR_adjacency;
81  }
82  } else {
83  return GR_triangle_strip | GR_adjacency;
84  }
85 }
86 
87 /**
88  * Returns the minimum number of vertices that must be added before
89  * close_primitive() may legally be called.
90  */
91 int GeomTristripsAdjacency::
92 get_min_num_vertices_per_primitive() const {
93  return 6;
94 }
95 
96 /**
97  * Returns the number of vertices that are added between primitives that
98  * aren't, strictly speaking, part of the primitives themselves. This is
99  * used, for instance, to define degenerate triangles to connect otherwise
100  * disconnected triangle strips.
101  */
102 int GeomTristripsAdjacency::
103 get_num_unused_vertices_per_primitive() const {
104  return 1;
105 }
106 
107 /**
108  * Calls the appropriate method on the GSG to draw the primitive.
109  */
110 bool GeomTristripsAdjacency::
112  bool force) const {
113  return gsg->draw_tristrips_adj(reader, force);
114 }
115 
116 /**
117  * Should be redefined to return true in any primitive that implements
118  * append_unused_vertices().
119  */
120 bool GeomTristripsAdjacency::
121 requires_unused_vertices() const {
122  return true;
123 }
124 
125 /**
126  * Called when a new primitive is begun (other than the first primitive), this
127  * should add some degenerate vertices between primitives, if the primitive
128  * type requires that. The second parameter is the first vertex that begins
129  * the new primitive.
130  */
131 void GeomTristripsAdjacency::
132 append_unused_vertices(GeomVertexArrayData *vertices, int vertex) {
133  GeomVertexWriter to(vertices, 0);
134  to.set_row_unsafe(vertices->get_num_rows());
135  to.add_data1i(get_strip_cut_index());
136 }
137 
138 /**
139  * Tells the BamReader how to create objects of type Geom.
140  */
143  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
144 }
145 
146 /**
147  * This function is called by the BamReader's factory when a new object of
148  * type Geom is encountered in the Bam file. It should create the Geom and
149  * extract its information from the file.
150  */
151 TypedWritable *GeomTristripsAdjacency::
152 make_from_bam(const FactoryParams &params) {
153  GeomTristripsAdjacency *object = new GeomTristripsAdjacency(UH_unspecified);
154  DatagramIterator scan;
155  BamReader *manager;
156 
157  parse_params(params, scan, manager);
158  object->fillin(scan, manager);
159 
160  return object;
161 }
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
Definition: geomPrimitive.h:56
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void parse_params(const FactoryParams &params, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
Definition: bamReader.I:275
Defines a series of triangle strips with adjacency information.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:73
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_strip_cut_index
Returns the index of the indicated type that is reserved for use as a strip cut index,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static void register_with_read_factory()
Tells the BamReader how to create objects of type Geom.
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
int get_num_rows() const
Returns the number of rows stored in the array, based on the number of bytes and the stride.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:177
int get_num_primitives() const
Returns the number of individual primitives stored within this object.
PT(GeomPrimitive) GeomTristripsAdjacency
Returns the fundamental rendering type of this primitive: whether it is points, lines,...
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:81
Encapsulates the data from a GeomPrimitive, pre-fetched for one stage of the pipeline.
bool is_indexed() const
Returns true if the primitive is indexed, false otherwise.
Definition: geomPrimitive.I:86
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the data for one array of a GeomVertexData structure.