@@ -46,11 +46,6 @@ GlyphGeom::GlyphGeom() : numVBOElements_(0), lineIndex_(0)
4646void GlyphGeom::buildObject (GeometryObjectSpire& geom, const std::string& uniqueNodeID, const bool isTransparent, const double transparencyValue,
4747 const ColorScheme& colorScheme, RenderState state, const SpireIBO::PRIMITIVE& primIn, const BBox& bbox, const Core::Datatypes::ColorMapHandle colorMap)
4848{
49- std::string vboName = uniqueNodeID + " VBO" ;
50- std::string iboName = uniqueNodeID + " IBO" ;
51- std::string passName = uniqueNodeID + " Pass" ;
52-
53- bool useTriangles = primIn == SpireIBO::PRIMITIVE::TRIANGLES;
5449 bool useColor = colorScheme == ColorScheme::COLOR_IN_SITU || colorScheme == ColorScheme::COLOR_MAP;
5550 bool useNormals = normals_.size () == points_.size ();
5651 int numAttributes = 3 ;
@@ -98,81 +93,98 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique
9893
9994 if (isTransparent) uniforms.push_back (SpireSubPass::Uniform (" uTransparency" , static_cast <float >(transparencyValue)));
10095
101- size_t vboSize = static_cast <size_t >(points_.size ()) * numAttributes * sizeof (float );
102- size_t iboSize = static_cast <size_t >(indices_.size ()) * sizeof (uint32_t );
103- std::shared_ptr<spire::VarBuffer> iboBufferSPtr (new spire::VarBuffer (iboSize));
104- std::shared_ptr<spire::VarBuffer> vboBufferSPtr (new spire::VarBuffer (vboSize));
105- auto iboBuffer = iboBufferSPtr.get ();
106- auto vboBuffer = vboBufferSPtr.get ();
107-
108- // write to the IBO/VBOs
109- for (auto a : indices_)
110- iboBuffer->write (a);
111-
112- BBox newBBox;
113- for (size_t i = 0 ; i < points_.size (); i++)
96+ size_t pointsLeft = points_.size ();
97+ size_t startOfPass = 0 ;
98+ int passNumber = 0 ;
99+ while (pointsLeft > 0 )
114100 {
115- newBBox.extend (Point (points_.at (i).x (), points_.at (i).y (), points_.at (i).z ()));
116- vboBuffer->write (static_cast <float >(points_.at (i).x ()));
117- vboBuffer->write (static_cast <float >(points_.at (i).y ()));
118- vboBuffer->write (static_cast <float >(points_.at (i).z ()));
119-
120- if (useNormals)
101+ std::string passID = uniqueNodeID + " _" + std::to_string (passNumber++);
102+ std::string vboName = passID + " VBO" ;
103+ std::string iboName = passID + " IBO" ;
104+ std::string passName = passID + " Pass" ;
105+
106+ const static size_t maxPointsPerPass = 3 << 24 ;
107+ uint32_t pointsInThisPass = std::min (pointsLeft, maxPointsPerPass);
108+ size_t endOfPass = startOfPass + pointsInThisPass;
109+ pointsLeft -= pointsInThisPass;
110+
111+ size_t vboSize = static_cast <size_t >(pointsInThisPass) * numAttributes * sizeof (float );
112+ size_t iboSize = static_cast <size_t >(pointsInThisPass) * sizeof (uint32_t );
113+ std::shared_ptr<spire::VarBuffer> iboBufferSPtr (new spire::VarBuffer (iboSize));
114+ std::shared_ptr<spire::VarBuffer> vboBufferSPtr (new spire::VarBuffer (vboSize));
115+ auto iboBuffer = iboBufferSPtr.get ();
116+ auto vboBuffer = vboBufferSPtr.get ();
117+
118+ for (auto a : indices_) if (a >= startOfPass && a < endOfPass)
119+ iboBuffer->write (static_cast <uint32_t >(a - startOfPass));
120+
121+ BBox newBBox;
122+ for (size_t i = startOfPass; i < endOfPass; ++i)
121123 {
122- vboBuffer-> write ( static_cast < float >(normals_ .at (i).x ()));
123- vboBuffer->write (static_cast <float >(normals_ .at (i).y ()));
124- vboBuffer->write (static_cast <float >(normals_ .at (i).z ()));
125- }
124+ newBBox. extend ( Point (points_ .at (i).x (), points_. at (i). y (), points_. at (i). z ()));
125+ vboBuffer->write (static_cast <float >(points_ .at (i).x ()));
126+ vboBuffer->write (static_cast <float >(points_ .at (i).y ()));
127+ vboBuffer-> write ( static_cast < float >(points_. at (i). z ()));
126128
127- if (useColor)
128- {
129- if (!colorMap)
129+ if (useNormals)
130130 {
131- vboBuffer->write (static_cast <float >(colors_.at (i).r ()));
132- vboBuffer->write (static_cast <float >(colors_.at (i).g ()));
133- vboBuffer->write (static_cast <float >(colors_.at (i).b ()));
134- vboBuffer->write (static_cast <float >(colors_.at (i).a ()));
131+ vboBuffer->write (static_cast <float >(normals_.at (i).x ()));
132+ vboBuffer->write (static_cast <float >(normals_.at (i).y ()));
133+ vboBuffer->write (static_cast <float >(normals_.at (i).z ()));
135134 }
136- else
135+
136+ if (useColor)
137137 {
138- vboBuffer->write (static_cast <float >(colors_.at (i).r ()));
139- vboBuffer->write (static_cast <float >(colors_.at (i).r ()));
138+ if (!colorMap)
139+ {
140+ vboBuffer->write (static_cast <float >(colors_.at (i).r ()));
141+ vboBuffer->write (static_cast <float >(colors_.at (i).g ()));
142+ vboBuffer->write (static_cast <float >(colors_.at (i).b ()));
143+ vboBuffer->write (static_cast <float >(colors_.at (i).a ()));
144+ }
145+ else
146+ {
147+ vboBuffer->write (static_cast <float >(colors_.at (i).r ()));
148+ vboBuffer->write (static_cast <float >(colors_.at (i).r ()));
149+ }
140150 }
141151 }
142- }
143- if (!bbox.valid ()) newBBox.reset ();
152+ if (!bbox.valid ()) newBBox.reset ();
144153
145- SpireVBO geomVBO (vboName, attribs, vboBufferSPtr, numVBOElements_, newBBox, true );
146- SpireIBO geomIBO (iboName, primIn, sizeof (uint32_t ), iboBufferSPtr);
154+ startOfPass = endOfPass;
147155
148- state. set (RenderState::IS_ON , true );
149- state. set (RenderState::HAS_DATA, true );
156+ SpireVBO geomVBO (vboName, attribs, vboBufferSPtr, numVBOElements_, newBBox , true );
157+ SpireIBO geomIBO (iboName, primIn, sizeof ( uint32_t ), iboBufferSPtr );
150158
151- SpireTexture2D texture ;
152- if (colorMap)
153- {
154- const static int colorMapResolution = 256 ;
155- for ( int i = 0 ; i < colorMapResolution; ++i )
159+ state. set (RenderState::IS_ON, true ) ;
160+ state. set (RenderState::HAS_DATA, true );
161+
162+ SpireTexture2D texture ;
163+ if (colorMap )
156164 {
157- ColorRGB color = colorMap->valueToColor (static_cast <float >(i)/colorMapResolution * 2.0 - 1.0 );
158- texture.bitmap .push_back (color.r ()*255 );
159- texture.bitmap .push_back (color.g ()*255 );
160- texture.bitmap .push_back (color.b ()*255 );
161- texture.bitmap .push_back (255 );
165+ const static int colorMapResolution = 256 ;
166+ for (int i = 0 ; i < colorMapResolution; ++i)
167+ {
168+ ColorRGB color = colorMap->valueToColor (static_cast <float >(i)/colorMapResolution * 2.0 - 1.0 );
169+ texture.bitmap .push_back (color.r ()*255 );
170+ texture.bitmap .push_back (color.g ()*255 );
171+ texture.bitmap .push_back (color.b ()*255 );
172+ texture.bitmap .push_back (255 );
173+ }
174+ texture.name = " ColorMap" ;
175+ texture.height = 1 ;
176+ texture.width = colorMapResolution;
162177 }
163- texture.name = " ColorMap" ;
164- texture.height = 1 ;
165- texture.width = colorMapResolution;
166- }
167178
168- SpireText text;
169- SpireSubPass pass (passName, vboName, iboName, shader, colorScheme, state, renderType, geomVBO, geomIBO, text, texture);
179+ SpireText text;
180+ SpireSubPass pass (passName, vboName, iboName, shader, colorScheme, state, renderType, geomVBO, geomIBO, text, texture);
170181
171- for (const auto & uniform : uniforms) { pass.addUniform (uniform); }
182+ for (const auto & uniform : uniforms) pass.addUniform (uniform);
172183
173- geom.vbos ().push_back (geomVBO);
174- geom.ibos ().push_back (geomIBO);
175- geom.passes ().push_back (pass);
184+ geom.vbos ().push_back (geomVBO);
185+ geom.ibos ().push_back (geomIBO);
186+ geom.passes ().push_back (pass);
187+ }
176188}
177189
178190void GlyphGeom::addArrow (const Point& p1, const Point& p2, double radius, double ratio, int resolution,
0 commit comments