Developer Documentation
PolyLineCollectionNodeT_impl.hh
1/*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40\*===========================================================================*/
41
42
43
44
45
46
47//=============================================================================
48//
49// CLASS PolyLineNodeT - IMPLEMENTATION
50//
51//=============================================================================
52
53#include "ACG/GL/GLError.hh"
54#define ACG_POLYLINECOLLECTIONNODET_C
55
56//== INCLUDES =================================================================
57
58
59
60#include "PolyLineCollectionNodeT.hh"
61#include <ACG/GL/gl.hh>
62#include <ACG/Utils/VSToolsT.hh>
63#include <vector>
64#include <OpenMesh/Core/Utils/vector_cast.hh>
65
66#ifdef _WIN32
67#include <cstdint>
68#else
69#include <stdint.h>
70#endif
71
72//== NAMESPACES ===============================================================
73
74namespace ACG {
75namespace SceneGraph {
76
77//== IMPLEMENTATION ==========================================================
78
80template <class PolyLineCollection>
82 BaseNode(_parent, _name),
83 polyline_collection_(_pl),
84 updateVBO_(true),
85 sphere_(0),
86 total_vertex_count_(0),
87 total_segment_count_(0)
88
89{
90 // Initial default draw mode
92}
93
94//----------------------------------------------------------------------------
96template <class PolyLineCollection>
99 for (size_t i = 0; i < polylineNodes_.size(); ++i)
100 delete polylineNodes_[i];
102
103//----------------------------------------------------------------------------
105template <class PolyLineCollection>
106void
108boundingBox(Vec3d& _bbMin, Vec3d& _bbMax)
109{
110 for(typename PolyLineCollection::iterator it = polyline_collection_.iter(); it; ++it){
111 typename PolyLineCollection::PolyLine* polyline = *it;
112
113 if(polyline){
114 for (unsigned int i=0; i< polyline->n_vertices(); ++i)
115 {
116 _bbMin.minimize(polyline->point(i));
117 _bbMax.maximize(polyline->point(i));
118 }
119 }
120 }
121}
122
123
124//----------------------------------------------------------------------------
125
126
127template <class PolyLineCollection>
128DrawModes::DrawMode
130availableDrawModes() const
131{
133}
134
135
136//----------------------------------------------------------------------------
138
139template <class PolyLineCollection>
140void
142draw(GLState& _state, const DrawModes::DrawMode& _drawMode)
143{
144 // Block if we do not have any polylines
145 if ( polyline_collection_.n_polylines() == 0 )
146 return;
147
148 // Update the vbo only if required.
149 if ( updateVBO_ )
150 updateVBO();
151
152 ACG::GLState::disable(GL_LIGHTING);
153 ACG::GLState::disable(GL_TEXTURE_2D);
154
155 // Bind the vertex array
156 vbo_.bind();
157 vertexDecl_.activateFixedFunction();
158
159 ACG::Vec4f color = _state.ambient_color() + _state.diffuse_color();
160
161 bool vertexColors = _drawMode & DrawModes::POINTS_COLORED;
162
163 // draw points
164 if (_drawMode & DrawModes::POINTS || vertexColors)
165 {
166 _state.set_color( color );
167
168 if (vertexColors) {
169 vertexDecl_.deactivateFixedFunction();
170 vertexDeclVColor_.activateFixedFunction();
171 }
172
173 // Draw all vertices (don't care about selection)
174 glDrawArrays(GL_POINTS, 0, total_vertex_count_);
175
176 if (vertexColors) {
177 vertexDeclVColor_.deactivateFixedFunction();
178 vertexDecl_.activateFixedFunction();
179 }
180
181
182 float point_size_old = _state.point_size();
183 _state.set_point_size(point_size_old+4.0f);
184
185 _state.set_color( Vec4f(1.0f,0.0f,0.0f,1.0f) );
186
187 // Draw selected polylines
188 for(typename PolyLineCollection::index_iterator it = polyline_collection_.selected_iter(); it; ++it){
189 typename PolyLineCollection::PolyLine* polyline = *it;
190
191 if(polyline && polyline->n_vertices() > 0){
192 glDrawArrays(GL_POINTS, offsets_[it.idx()].first, offsets_[it.idx()].second-1);
193 }
194 }
195
196 _state.set_point_size(point_size_old);
197
198 }
199
200
201 bool edgeColors = _drawMode & DrawModes::EDGES_COLORED;
202
203 // draw line segments
204 if (_drawMode & DrawModes::WIREFRAME || edgeColors) {
205
206 _state.set_color( color );
207
208 if (edgeColors) {
209 vertexDecl_.deactivateFixedFunction();
210 vertexDeclEColor_.activateFixedFunction();
211 }
212
213 ibo_.bind();
214 glDrawElements(GL_LINES, total_segment_count_ * 2, GL_UNSIGNED_INT, 0);
215 ibo_.unbind();
216
217 if (edgeColors) {
218 vertexDeclEColor_.deactivateFixedFunction();
219 vertexDecl_.activateFixedFunction();
220 }
221
222 float line_width_old = _state.line_width();
223 _state.set_color(Vec4f(1, 0, 0, 1));
224 _state.set_line_width(2 * line_width_old);
225
226 for(typename PolyLineCollection::index_iterator it = polyline_collection_.selected_iter(); it; ++it){
227 typename PolyLineCollection::PolyLine* polyline = *it;
228
229 if(polyline && polyline->n_vertices() > 0){
230 if ( polyline->is_closed() ){
231 glDrawArrays(GL_LINE_STRIP, offsets_[it.idx()].first, offsets_[it.idx()].second);
232 }else{
233 glDrawArrays(GL_LINE_STRIP, offsets_[it.idx()].first, offsets_[it.idx()].second-1);
234 }
235
236 //offset += polyline->n_vertices() + 1;
237 }
238 }
239
240 // Draw selected edges
241 std::vector<int> selected_indices;
242 for(typename PolyLineCollection::index_iterator it = polyline_collection_.visible_iter(); it; ++it){
243 typename PolyLineCollection::PolyLine* polyline = *it;
244
245
246 if(polyline){
247 int offset = offsets_[it.idx()].first;
248 for(size_t i = 0; i < polyline->n_vertices(); ++i){
249 if(!polyline->is_closed() && i == polyline->n_vertices() - 1){
250 continue;
251 }
252 if(polyline->edge_selected(i)){
253 selected_indices.push_back(offset + i);
254 selected_indices.push_back(offset + i + 1);
255 }
256 }
257 }
258 }
259
260 if(selected_indices.size() > 0){
261 glDrawElements(GL_LINES, selected_indices.size(), GL_UNSIGNED_INT, selected_indices.data());
262 }
263
264 _state.set_line_width(line_width_old);
265
266 }
267
268 vertexDecl_.deactivateFixedFunction();
269 ACG::GLState::bindBuffer(GL_ARRAY_BUFFER_ARB, 0);
270}
271
272//----------------------------------------------------------------------------
273
274
275template <class PolyLineCollection>
276void
278pick(GLState& _state, PickTarget _target)
279{
280 size_t numPolyLines = polyline_collection_.n_polylines();
281
282 if ( numPolyLines == 0 )
283 return;
284
285
286 switch (_target)
287 {
288 case PICK_VERTEX:
289 {
290 size_t numPickIDs = 0;
291
292 for (size_t i = 0; i < numPolyLines; ++i)
293 {
294 typename PolyLineCollection::PolyLine* line = polyline_collection_.polyline(i);
295
296 if (line)
297 numPickIDs += line->n_vertices();
298 }
299
300 _state.pick_set_maximum (numPickIDs);
301 pick_vertices( _state);
302 break;
303 }
304
305 case PICK_EDGE:
306 {
307 size_t numPickIDs = 0;
308
309 for (size_t i = 0; i < numPolyLines; ++i)
310 {
311 typename PolyLineCollection::PolyLine* line = polyline_collection_.polyline(i);
312
313 if (line)
314 numPickIDs += line->n_edges();
315 }
316
317 _state.pick_set_maximum (numPickIDs);
318 pick_edges(_state, 0);
319 break;
320 }
321
322 case PICK_ANYTHING:
323 {
324 size_t numPickVertices = 0;
325 size_t numPickIDs = 0;
326
327 for (size_t i = 0; i < numPolyLines; ++i)
328 {
329 typename PolyLineCollection::PolyLine* line = polyline_collection_.polyline(i);
330
331 if (line)
332 {
333 numPickIDs += line->n_vertices();
334 numPickIDs += line->n_edges();
335
336 numPickVertices += line->n_vertices();
337 }
338 }
339
340 _state.pick_set_maximum (numPickIDs);
341
342
343 pick_vertices( _state);
344 pick_edges( _state, static_cast<unsigned int>(numPickVertices));
345 break;
346 }
347
348 default:
349 break;
350 }
351}
352
353//----------------------------------------------------------------------------
354
355template <class PolyLineCollection>
356void
358pick_vertices(GLState &_state)
359{
360 size_t numPolyLines = polyline_collection_.n_polylines();
361
362 // draw vertex pick IDs
363
364 float point_size_old = _state.point_size();
365 glPointSize(point_size_old+3.0f);
366
367 static ShaderGenDesc desc;
368 desc.vertexTemplateFile = "Picking/pick_vertices_vs.glsl";
369 desc.fragmentTemplateFile = "Picking/pick_vertices_fs.glsl";
370 GLSL::Program* pickVertexShader = ACG::ShaderCache::getInstance()->getProgram(&desc, nullptr);
371
372 if (pickVertexShader && pickVertexShader->isLinked())
373 {
374 // shader needs picking ID offset and transform matrix
375 int pickVertexOffset = int(_state.pick_current_index());
376 GLMatrixf mWVP = _state.projection() * _state.modelview();
377
378 pickVertexShader->use();
379
380 pickVertexShader->setUniform("mWVP", mWVP);
381
382 vbo_.bind();
383
384 vertexDecl_.activateShaderPipeline(pickVertexShader);
385
386
387 for (size_t i = 0; i < numPolyLines; ++i)
388 {
389 typename PolyLineCollection::PolyLine* line = polyline_collection_.polyline(i);
390
391 if (line && line->n_vertices() > 0)
392 {
393 pickVertexShader->setUniform("pickVertexOffset", pickVertexOffset);
394
395 glDrawArrays(GL_POINTS, offsets_[i].first, offsets_[i].second-1);
396
397 pickVertexOffset += int(offsets_[i].second - 1);
398 }
399 }
400
401 vertexDecl_.deactivateShaderPipeline(pickVertexShader);
402
403 vbo_.unbind();
404
405 pickVertexShader->disable();
406 }
407 else
408 {
409 // fallback implementation: draw picking ids without shader
410 glBegin(GL_POINTS);
411
412 size_t curPickID = 0;
413
414 for (size_t i = 0; i < numPolyLines; ++i)
415 {
416 typename PolyLineCollection::PolyLine* line = polyline_collection_.polyline(i);
417
418 if (line && line->n_vertices() > 0)
419 {
420 for (size_t v = 0; v < line->n_vertices(); ++v)
421 {
422 _state.pick_set_name(curPickID++);
423
424 glVertex3d(line->point(v)[0], line->point(v)[1], line->point(v)[2]);
425 }
426 }
427 }
428
429 glEnd();
430 }
431
432 glPointSize(point_size_old);
433}
434
435//----------------------------------------------------------------------------
436
437template <class PolyLineCollection>
438void
439PolyLineCollectionNodeT<PolyLineCollection>::
440pick_edges(GLState &_state, unsigned int _offset)
441{
442 size_t numPolyLines = polyline_collection_.n_polylines();
443 // draw edge picking IDs
444 float line_width_old = _state.line_width();
445 _state.set_line_width(line_width_old + 3.0f);
446
447 static ShaderGenDesc desc;
449 {
450 desc.vertexTemplateFile = "Picking/vertex.glsl";
451 desc.fragmentTemplateFile = "Picking/pick_vertices_fs2.glsl";
452 }
453 else
454 {
455 desc.vertexTemplateFile = "Picking/pick_vertices_vs.glsl";
456 desc.fragmentTemplateFile = "Picking/pick_vertices_fs.glsl";
457 }
458
459 GLSL::Program* pickEdgeShader = ACG::ShaderCache::getInstance()->getProgram(&desc, nullptr);
460
461 if (pickEdgeShader && pickEdgeShader->isLinked())
462 {
463 // shader needs picking ID offset and transform matrix
464 int pickVertexOffset = int(_state.pick_current_index() + _offset);
465 GLMatrixf mWVP = _state.projection() * _state.modelview();
466
467 pickEdgeShader->use();
468
469 pickEdgeShader->setUniform("mWVP", mWVP);
470
471 vbo_.bind();
472
473 vertexDecl_.activateShaderPipeline(pickEdgeShader);
474
475 for (size_t i = 0; i < numPolyLines; ++i)
476 {
477 typename PolyLineCollection::PolyLine* line = polyline_collection_.polyline(i);
478
479 if (line && line->n_vertices() > 0)
480 {
481 pickEdgeShader->setUniform("pickVertexOffset", pickVertexOffset);
482
483 size_t numIndices = line->is_closed() ? offsets_[i].second : offsets_[i].second - 1;
484 glDrawArrays(GL_LINE_STRIP, offsets_[i].first, numIndices);
485
486 pickVertexOffset += int(line->n_edges());
487 }
488 }
489
490 vertexDecl_.deactivateShaderPipeline(pickEdgeShader);
491
492 vbo_.unbind();
493
494 pickEdgeShader->disable();
495 }
496 else
497 {
498 // fallback implementation: draw picking ids without shader
499 glBegin(GL_LINES);
500
501 size_t curPickID = _offset;
502
503 for (size_t i = 0; i < numPolyLines; ++i)
504 {
505 typename PolyLineCollection::PolyLine* line = polyline_collection_.polyline(i);
506
507 if (line)
508 {
509 size_t nv = line->n_vertices();
510
511 for (size_t v = 0; v < line->n_edges(); ++v)
512 {
513 _state.pick_set_name(curPickID++);
514
515 glVertex3d(line->point(v)[0], line->point(v)[1], line->point(v)[2]);
516
517 size_t e = (v+1)%nv;
518 glVertex3d(line->point(e)[0], line->point(e)[1], line->point(e)[2]);
519 }
520 }
521 }
522
523 glEnd();
524 }
525
526 _state.set_line_width(line_width_old);
527
528}
529
530//----------------------------------------------------------------------------
531
532template <class PolyLineCollection>
533void
535updateVBO() {
536
537 bool lines_did_change = false;
538
539 if( offsets_.size() != polyline_collection_.n_polylines() ){
540 offsets_.resize(polyline_collection_.n_polylines());
541 lines_did_change = true;
542 }
543
544 int offset = 0;
545 total_vertex_count_ = 0;
546 total_segment_count_ = 0;
547 for(typename PolyLineCollection::iterator it = polyline_collection_.iter(); it; ++it){
548 std::pair<size_t, size_t> current_offset;
549 current_offset.first = offset;
550 if(*it){
551 current_offset.second = it->n_vertices() + 1;
552 }else{
553 current_offset.second = 0;
554 }
555
556 if(current_offset != offsets_[it.idx()]){
557 lines_did_change = true;
558 }
559
560 offsets_[it.idx()] = current_offset;
561 total_vertex_count_ += current_offset.second;
562 total_segment_count_ += it->n_edges();
563
564 offset += current_offset.second;
565 }
566
567 if(lines_did_change){
568
569
570 // update internal line node
571 // these are used exclusively used to fill the vertex buffer
572
573
574 size_t prevLineCount = polylineNodes_.size();
575 size_t curLineCount = polyline_collection_.n_polylines();
576
577
578 // free memory for removed lines
579 if (curLineCount < prevLineCount)
580 {
581 for (size_t i = curLineCount; i < prevLineCount; ++i)
582 delete polylineNodes_[i];
583 }
584
585 polylineNodes_.resize(curLineCount);
586
587
588 for(size_t i = 0; i < curLineCount; ++i) {
589 typename PolyLineCollection::PolyLine* polyline = polyline_collection_.polyline(i);
590 polylineNodes_[i] = new PolyLineNodeT<typename PolyLineCollection::PolyLine>(*polyline);
591 }
592
593
594
595 // Update the vertex declaration based on the input data:
596 vertexDecl_.clear();
597 vertexDeclVColor_.clear();
598 vertexDeclEColor_.clear();
599
600
601 if (curLineCount > 0) {
602 polylineNodes_[0]->setupVertexDeclaration(&vertexDecl_, 0);
603 polylineNodes_[0]->setupVertexDeclaration(&vertexDeclVColor_, 1);
604 polylineNodes_[0]->setupVertexDeclaration(&vertexDeclEColor_, 2);
605
606
607 // make sure that all polylines have the same vertex format
608 bool equalVertexFormat = true;
609
610 for (size_t i = 1; i < curLineCount; ++i) {
611
612 VertexDeclaration decl[3];
613
614 for (int k = 0; k < 3; ++k)
615 polylineNodes_[i]->setupVertexDeclaration(&decl[k], k);
616
617 if (decl[0] != vertexDecl_ ||
618 decl[1] != vertexDeclVColor_ ||
619 decl[2] != vertexDeclEColor_)
620 equalVertexFormat = false;
621 }
622
623
624 if (!equalVertexFormat)
625 std::cerr << "PolyLineCollection error: polylines do not have the same vertex format, so the collection vbo could not be created" << std::endl;
626 else {
627
628 // size in bytes of vbo, create additional vertex for closed loop indexing
629 size_t stride = vertexDecl_.getVertexStride();
630 size_t bufferSize = stride * offset;
631
632 if (bufferSize > 0) {
633 std::vector<char> vboData(bufferSize);
634 std::vector<unsigned int> iboData(total_segment_count_ * 2);
635
636 size_t offsetSegment = 0;
637
638 for(size_t i = 0; i < curLineCount; ++i) {
639 typename PolyLineCollection::PolyLine* polyline = polyline_collection_.polyline(i);
640
641
642 if (polyline && polylineNodes_[i] && polyline->n_vertices() > 0) {
643
644 // fill vertex buffer data
645 size_t offset = offsets_[i].first;
646
647 polylineNodes_[i]->fillVertexBuffer(&vboData[(offset) * stride], bufferSize, true);
648
649 // fill index buffer data
650 for (size_t k = 0; k < polyline->n_edges(); ++k) {
651 iboData[(offsetSegment + k) * 2] = offset + k;
652 iboData[(offsetSegment + k) * 2 + 1] = offset + (k + 1) % polyline->n_vertices();
653 }
654 offsetSegment += polyline->n_edges();
655
656 }
657
658 }
659
660 // Move data to the buffer in gpu memory
661 vbo_.upload(vboData.size() * sizeof(vboData[0]), &vboData[0], GL_STATIC_DRAW);
662 vbo_.unbind();
663
664 ibo_.upload(iboData.size() * sizeof(iboData[0]), &iboData[0], GL_STATIC_DRAW);
665 ibo_.unbind();
666 }
667
668 }
669
670 }
671 }
672
673
674
675 // Update done.
676 updateVBO_ = false;
677}
678
679//----------------------------------------------------------------------------
680
681template <class PolyLineCollection>
682void
685
686 // Block if we do not have any vertices
687 if ( polyline_collection_.n_polylines() == 0 )
688 return;
689
690 // init base render object
692 ro.initFromState(&_state);
693
694 ro.setMaterial(_mat);
695
696 // draw after scene-meshes
697 ro.priority = 1;
698
699 // Update the vbo only if required.
700 if ( updateVBO_ )
701 updateVBO();
702
703 // Set to the right vbo
704 ro.vertexBuffer = vbo_.id();
705
706 // Set style
707 ro.debugName = "PolyLineCollection";
708 ro.blending = false;
709 ro.depthTest = true;
710
711 // Default color
712 ACG::Vec4f defaultColor = _state.ambient_color() + _state.diffuse_color();
713 ACG::Vec4f selectionColor = ACG::Vec4f(1.0,0.0,0.0,1.0);
714
715 // Viewport size
716 ACG::Vec2f screenSize(float(_state.viewport_width()), float(_state.viewport_height()));
717
718 for (size_t i = 0; i < _drawMode.getNumLayers(); ++i) {
719 ACG::SceneGraph::Material localMaterial = *_mat;
720
722
724 ro.shaderDesc.shadeMode = SG_SHADE_UNLIT;
725
726
727 if (props->colored())
728 {
729 if (props->colorSource() == ACG::SceneGraph::DrawModes::COLOR_PER_EDGE)
730 {
731 ro.vertexDecl = &vertexDeclEColor_;
733 }
734 else
735 {
736 ro.vertexDecl = &vertexDeclVColor_;
738 }
739
740 ro.shaderDesc.vertexColors = true;
741 }
742 else
743 {
744 ro.vertexDecl = &vertexDecl_;
745 ro.shaderDesc.vertexColors = false;
746 }
747
748 //---------------------------------------------------
749 // No lighting!
750 // Therefore we need some emissive color
751 //---------------------------------------------------
752 localMaterial.baseColor(defaultColor);
753 ro.setMaterial(&localMaterial);
754
755
756 if(props->primitive() == ACG::SceneGraph::DrawModes::PRIMITIVE_POINT){
757 // Render all vertices which are selected via an index buffer
758 ro.debugName = "polyline.Points.selected";
759 localMaterial.baseColor(selectionColor);
760 ro.setMaterial(&localMaterial);
761
762 // Point Size geometry shader
763 ro.setupPointRendering(_mat->pointSize(), screenSize);
764
765 // Render all vertices (ignore selection here!)
766 ro.debugName = "polylinecollection.Points";
767 localMaterial.baseColor(defaultColor);
768 ro.setMaterial(&localMaterial);
769
770
771 // Point Size geometry shader
772 ro.setupPointRendering(_mat->pointSize(), screenSize);
773
774 // apply user settings
775 applyRenderObjectSettings(props->primitive(), &ro);
776
777
778 ro.glDrawArrays(GL_POINTS, 0, total_vertex_count_);
779 _renderer->addRenderObject(&ro);
780
781 }else if(props->primitive() == ACG::SceneGraph::DrawModes::PRIMITIVE_WIREFRAME ||
782 props->primitive() == ACG::SceneGraph::DrawModes::PRIMITIVE_EDGE){
783 // Render all edges which are selected via an index buffer
784 ro.debugName = "polyline.Wireframe.selected";
785 localMaterial.baseColor(selectionColor);
786 ro.setMaterial(&localMaterial);
787
788 // Line Width geometry shader
789 ro.setupLineRendering(_state.line_width(), screenSize);
790
791 ro.debugName = "polylinecollection.Wireframe";
792 localMaterial.baseColor(defaultColor);
793 ro.setMaterial(&localMaterial);
794 // The first point is mapped to an additional last point in buffer, so we can
795 // just Render one point more to get a closed line
796
797
798 // Line Width geometry shader
799 ro.setupLineRendering(_state.line_width(), screenSize);
800
801 // apply user settings
802 applyRenderObjectSettings(props->primitive(), &ro);
803
804
805 ro.indexBuffer = ibo_.id();
806 ro.glDrawElements(GL_LINES, total_segment_count_ * 2, GL_UNSIGNED_INT, 0);
807
808 _renderer->addRenderObject(&ro);
809 ro.indexBuffer = 0;
810
811 }
812 }
813
814}
815
816//=============================================================================
817} // namespace SceneGraph
818} // namespace ACG
819//=============================================================================
const GLMatrixd & modelview() const
get modelview matrix
Definition: GLState.hh:816
int viewport_width() const
get viewport width
Definition: GLState.hh:847
void pick_set_name(size_t _idx)
sets the current name/color (like glLoadName(_idx))
Definition: GLState.cc:1061
bool pick_set_maximum(size_t _idx)
Set the maximal number of primitives/components of your object.
Definition: GLState.cc:1051
const GLMatrixd & projection() const
get projection matrix
Definition: GLState.hh:811
void set_color(const Vec4f &_col)
set color
Definition: GLState.cc:691
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
Definition: GLState.cc:1527
void set_line_width(float _f)
set line width
Definition: GLState.cc:791
const Vec4f & ambient_color() const
get ambient color
Definition: GLState.hh:956
void set_point_size(float _f)
set point size
Definition: GLState.cc:776
size_t pick_current_index() const
Returns the current color picking index (can be used for caching)
Definition: GLState.cc:1131
int viewport_height() const
get viewport height
Definition: GLState.hh:849
float line_width() const
get line width
Definition: GLState.hh:1000
const Vec4f & diffuse_color() const
get diffuse color
Definition: GLState.hh:961
static void bindBuffer(GLenum _target, GLuint _buffer)
replaces glBindBuffer, supports locking
Definition: GLState.cc:1820
float point_size() const
get point size
Definition: GLState.hh:995
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
Definition: IRenderer.cc:104
size_t n_vertices() const
Get number of vertices.
Definition: PolyLineT.hh:119
Point & point(unsigned int _i)
Get a point of the polyline.
Definition: PolyLineT.hh:145
size_t n_edges() const
Get number of edges.
bool is_closed() const
Check if the polyline is marked as closed.
Definition: PolyLineT.hh:110
DrawModeProperties stores a set of properties that defines, how to render an object.
Definition: DrawModes.hh:177
bool colored() const
Are colors used?
Definition: DrawModes.hh:222
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
Definition: DrawModes.cc:525
size_t getNumLayers() const
returns the layer count
Definition: DrawModes.cc:521
void baseColor(const Vec4f &_c)
set the base color (Sets the baseColor which is the same as the emission(const Vec4f& _c) )
void pointSize(float _sz)
set point size (default: 1.0)
DrawModes::DrawMode availableDrawModes() const override
return available draw modes
void pick(GLState &_state, PickTarget _target) override
picking
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax) override
update bounding box
PolyLineCollectionNodeT(PolyLineCollection &_pl, BaseNode *_parent=0, std::string _name="<PolyLineCollectionNode>")
Constructor.
void getRenderObjects(ACG::IRenderer *_renderer, ACG::GLState &_state, const ACG::SceneGraph::DrawModes::DrawMode &_drawMode, const ACG::SceneGraph::Material *_mat) override
Add the objects to the given renderer.
void draw(GLState &, const DrawModes::DrawMode &_drawMode) override
draw lines and normals
static ShaderCache * getInstance()
Return instance of the ShaderCache singleton.
Definition: ShaderCache.cc:84
GLSL::Program * getProgram(const ShaderGenDesc *_desc, const std::vector< unsigned int > &_mods)
Query a dynamically generated program from cache.
Definition: ShaderCache.cc:102
QString vertexColorsInterpolator
interpolation qualifier for input vertex colors: "flat", "smooth", "noperspective"
Class to define the vertex input layout.
unsigned int getVertexStride(unsigned int i=0) const
GLSL program class.
Definition: GLSLShader.hh:211
bool isLinked()
Returns if the program object has been succesfully linked.
Definition: GLSLShader.cc:370
void disable()
Resets to standard rendering pipeline.
Definition: GLSLShader.cc:355
void use()
Enables the program object for using.
Definition: GLSLShader.cc:345
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
Definition: GLSLShader.cc:385
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Definition: Vector11T.hh:588
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
Definition: Vector11T.hh:560
DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
Definition: DrawModes.cc:74
DrawMode WIREFRAME
draw wireframe
Definition: DrawModes.cc:78
DrawMode POINTS
draw unlighted points using the default base color
Definition: DrawModes.cc:73
DrawMode EDGES_COLORED
draw edges with colors (without shading)
Definition: DrawModes.cc:77
PickTarget
What target to use for picking.
Definition: PickTarget.hh:74
@ PICK_EDGE
picks edges (may not be implemented for all nodes)
Definition: PickTarget.hh:80
@ PICK_ANYTHING
pick any of the prior targets (should be implemented for all nodes)
Definition: PickTarget.hh:84
@ PICK_VERTEX
picks verices (may not be implemented for all nodes)
Definition: PickTarget.hh:82
Namespace providing different geometric functions concerning angles.
GLMatrixT< float > GLMatrixf
typedef
Definition: GLMatrixT.hh:322
VectorT< float, 4 > Vec4f
Definition: VectorT.hh:138
bool ACGDLLEXPORT openGLVersionTest(const int _major, const int _minor)
Definition: gl.hh:275
Interface class between scenegraph and renderer.
Definition: RenderObject.hh:99
ShaderGenDesc shaderDesc
Drawmode and other shader params.
void setupLineRendering(float _lineWidth, const Vec2f &_screenSize)
Setup rendering of thick lines.
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
void setupShaderGenFromDrawmode(const SceneGraph::DrawModes::DrawModeProperties *_props)
Fills out ShaderGenDesc parameters based on Drawmode properties.
GLuint indexBuffer
Use vertex array object.
int priority
Priority to allow sorting of objects.
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
Definition: RenderObject.cc:61
void setupPointRendering(float _pointSize, const Vec2f &_screenSize)
Setup rendering of circle points.