Panda3D
geomPatches.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 geomPatches.cxx
10  * @author drose
11  * @date 2012-04-27
12  */
13 
14 #include "geomPatches.h"
15 #include "geomVertexRewriter.h"
16 #include "pStatTimer.h"
17 #include "bamReader.h"
18 #include "bamWriter.h"
20 
21 TypeHandle GeomPatches::_type_handle;
22 
23 /**
24  * The number of vertices per patch must be specified to the GeomPatches
25  * constructor, and it may not be changed during the lifetime of the
26  * GeomPatches object. Create a new GeomPatches if you need to have a
27  * different value.
28  */
30 GeomPatches(int num_vertices_per_patch, GeomPatches::UsageHint usage_hint) :
31  GeomPrimitive(usage_hint),
32  _num_vertices_per_patch(num_vertices_per_patch)
33 {
34 }
35 
36 /**
37  *
38  */
40 GeomPatches(const GeomPatches &copy) :
41  GeomPrimitive(copy),
42  _num_vertices_per_patch(copy._num_vertices_per_patch)
43 {
44 }
45 
46 /**
47  *
48  */
49 GeomPatches::
50 ~GeomPatches() {
51 }
52 
53 /**
54  *
55  */
56 PT(GeomPrimitive) GeomPatches::
57 make_copy() const {
58  return new GeomPatches(*this);
59 }
60 
61 /**
62  * Returns the fundamental rendering type of this primitive: whether it is
63  * points, lines, or polygons.
64  *
65  * This is used to set up the appropriate antialiasing settings when
66  * AntialiasAttrib::M_auto is in effect; it also implies the type of primitive
67  * that will be produced when decompose() is called.
68  */
69 GeomPrimitive::PrimitiveType GeomPatches::
70 get_primitive_type() const {
71  return PT_patches;
72 }
73 
74 /**
75  * If the primitive type is a simple type in which all primitives have the
76  * same number of vertices, like patches, returns the number of vertices per
77  * primitive. If the primitive type is a more complex type in which different
78  * primitives might have different numbers of vertices, for instance a
79  * triangle strip, returns 0.
80  *
81  * In the case of GeomPatches, this returns the fixed number that was
82  * specified to the constructor.
83  */
84 int GeomPatches::
85 get_num_vertices_per_primitive() const {
86  return _num_vertices_per_patch;
87 }
88 
89 /**
90  * Calls the appropriate method on the GSG to draw the primitive.
91  */
92 bool GeomPatches::
94  bool force) const {
95  return gsg->draw_patches(reader, force);
96 }
97 
98 /**
99  * Tells the BamReader how to create objects of type Geom.
100  */
101 void GeomPatches::
102 register_with_read_factory() {
103  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
104 }
105 
106 /**
107  * Writes the contents of this object to the datagram for shipping out to a
108  * Bam file.
109  */
110 void GeomPatches::
112  GeomPrimitive::write_datagram(manager, dg);
113  dg.add_uint16(_num_vertices_per_patch);
114 }
115 
116 /**
117  * This internal function is called by make_from_bam to read in all of the
118  * relevant data from the BamFile for the new GeomPatches.
119  */
120 void GeomPatches::
121 fillin(DatagramIterator &scan, BamReader *manager) {
122  GeomPrimitive::fillin(scan, manager);
123  _num_vertices_per_patch = scan.get_uint16();
124 }
125 
126 /**
127  * This function is called by the BamReader's factory when a new object of
128  * type Geom is encountered in the Bam file. It should create the Geom and
129  * extract its information from the file.
130  */
131 TypedWritable *GeomPatches::
132 make_from_bam(const FactoryParams &params) {
133  GeomPatches *object = new GeomPatches(0, UH_unspecified);
134  DatagramIterator scan;
135  BamReader *manager;
136 
137  parse_params(params, scan, manager);
138  object->fillin(scan, manager);
139 
140  return object;
141 }
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
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.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
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
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
Definition: datagram.I:85
Defines a series of "patches", fixed-size groupings of vertices that must be processed by a tessellat...
Definition: geomPatches.h:24
PT(GeomPrimitive) GeomPatches
Returns the fundamental rendering type of this primitive: whether it is points, lines,...
Definition: geomPatches.cxx:56
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:177
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.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
GeomPatches(int num_vertices_per_patch, UsageHint usage_hint)
The number of vertices per patch must be specified to the GeomPatches constructor,...
Definition: geomPatches.cxx:30