Panda3D
Loading...
Searching...
No Matches
geomTrianglesAdjacency.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 geomTrianglesAdjacency.cxx
10 * @author rdb
11 * @date 2018-03-01
12 */
13
15#include "geomVertexRewriter.h"
16#include "pStatTimer.h"
17#include "bamReader.h"
18#include "bamWriter.h"
20
21TypeHandle GeomTrianglesAdjacency::_type_handle;
22
23/**
24 *
25 */
26GeomTrianglesAdjacency::
27GeomTrianglesAdjacency(GeomTrianglesAdjacency::UsageHint usage_hint) :
28 GeomPrimitive(usage_hint)
29{
30}
31
32/**
33 *
34 */
35GeomTrianglesAdjacency::
36GeomTrianglesAdjacency(const GeomTrianglesAdjacency &copy) :
37 GeomPrimitive(copy)
38{
39}
40
41/**
42 *
43 */
44GeomTrianglesAdjacency::
45~GeomTrianglesAdjacency() {
46}
47
48/**
49 *
50 */
51PT(GeomPrimitive) GeomTrianglesAdjacency::
52make_copy() const {
53 return new GeomTrianglesAdjacency(*this);
54}
55
56/**
57 * Returns the fundamental rendering type of this primitive: whether it is
58 * points, lines, or polygons.
59 *
60 * This is used to set up the appropriate antialiasing settings when
61 * AntialiasAttrib::M_auto is in effect; it also implies the type of primitive
62 * that will be produced when decompose() is called.
63 */
64GeomPrimitive::PrimitiveType GeomTrianglesAdjacency::
65get_primitive_type() const {
66 return PT_polygons;
67}
68
69/**
70 * Returns the set of GeomRendering bits that represent the rendering
71 * properties required to properly render this primitive.
72 */
73int GeomTrianglesAdjacency::
74get_geom_rendering() const {
75 return GeomPrimitive::get_geom_rendering() | GR_adjacency;
76}
77
78/**
79 * If the primitive type is a simple type in which all primitives have the
80 * same number of vertices, like triangles, returns the number of vertices per
81 * primitive. If the primitive type is a more complex type in which different
82 * primitives might have different numbers of vertices, for instance a
83 * triangle strip, returns 0.
84 */
85int GeomTrianglesAdjacency::
86get_num_vertices_per_primitive() const {
87 return 6;
88}
89
90/**
91 * Calls the appropriate method on the GSG to draw the primitive.
92 */
93bool GeomTrianglesAdjacency::
95 bool force) const {
96 return gsg->draw_triangles_adj(reader, force);
97}
98
99/**
100 * The virtual implementation of doubleside().
101 */
102CPT(GeomPrimitive) GeomTrianglesAdjacency::
103doubleside_impl() const {
104 Thread *current_thread = Thread::get_current_thread();
105 PT(GeomTrianglesAdjacency) reversed = new GeomTrianglesAdjacency(*this);
106
107 GeomPrimitivePipelineReader from(this, current_thread);
108
109 // This is like reverse(), except we don't clear the vertices first. That
110 // way we double the vertices up.
111
112 // First, rotate the original copy, if necessary, so the flat-firstflat-last
113 // nature of the vertices is consistent throughout the primitive.
114 bool needs_rotate = false;
115 switch (from.get_shade_model()) {
116 case SM_flat_first_vertex:
117 case SM_flat_last_vertex:
118 reversed = (GeomTrianglesAdjacency *)DCAST(GeomTrianglesAdjacency, reversed->rotate());
119 needs_rotate = true;
120
121 default:
122 break;
123 }
124
125 // Now append all the new vertices, in reverse order.
126 for (int i = from.get_num_vertices() - 1; i >= 0; --i) {
127 reversed->add_vertex(from.get_vertex(i));
128 }
129
130 // Finally, re-rotate the whole thing to get back to the original shade
131 // model.
132 if (needs_rotate) {
133 reversed = (GeomTrianglesAdjacency *)DCAST(GeomTrianglesAdjacency, reversed->rotate());
134 }
135
136 return reversed;
137}
138
139/**
140 * The virtual implementation of reverse().
141 */
142CPT(GeomPrimitive) GeomTrianglesAdjacency::
143reverse_impl() const {
144 Thread *current_thread = Thread::get_current_thread();
145 PT(GeomTrianglesAdjacency) reversed = new GeomTrianglesAdjacency(*this);
146
147 GeomPrimitivePipelineReader from(this, current_thread);
148 reversed->clear_vertices();
149
150 for (int i = from.get_num_vertices() - 1; i >= 0; --i) {
151 reversed->add_vertex(from.get_vertex(i));
152 }
153
154 switch (from.get_shade_model()) {
155 case SM_flat_first_vertex:
156 reversed->set_shade_model(SM_flat_last_vertex);
157 reversed = (GeomTrianglesAdjacency *)DCAST(GeomTrianglesAdjacency, reversed->rotate());
158 break;
159
160 case SM_flat_last_vertex:
161 reversed->set_shade_model(SM_flat_first_vertex);
162 reversed = (GeomTrianglesAdjacency *)DCAST(GeomTrianglesAdjacency, reversed->rotate());
163 break;
164
165 default:
166 break;
167 }
168
169 return reversed;
170}
171
172/**
173 * Tells the BamReader how to create objects of type Geom.
174 */
175void GeomTrianglesAdjacency::
176register_with_read_factory() {
177 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
178}
179
180/**
181 * This function is called by the BamReader's factory when a new object of
182 * type Geom is encountered in the Bam file. It should create the Geom and
183 * extract its information from the file.
184 */
185TypedWritable *GeomTrianglesAdjacency::
186make_from_bam(const FactoryParams &params) {
187 GeomTrianglesAdjacency *object = new GeomTrianglesAdjacency(UH_unspecified);
188 DatagramIterator scan;
189 BamReader *manager;
190
191 parse_params(params, scan, manager);
192 object->fillin(scan, manager);
193
194 return object;
195}
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
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
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.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
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
Encapsulates the data from a GeomPrimitive, pre-fetched for one stage of the pipeline.
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
get_geom_rendering
Returns the set of GeomRendering bits that represent the rendering properties required to properly re...
Defines a series of disconnected triangles, with adjacency information.
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
A thread; that is, a lightweight process.
Definition thread.h:46
get_current_thread
Returns a pointer to the currently-executing Thread object.
Definition thread.h:109
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
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.