54 #include <ACG/GL/acg_glew.hh> 55 #include "LineNode.hh" 56 #include <ACG/GL/IRenderer.hh> 69 picking_line_width_(
std::numeric_limits<float>::infinity()),
71 draw_always_on_top (false),
84 glDeleteBuffers(1, &vbo_);
134 (
char) (((
int) _c[1]) * 255),
135 (
char) (((
int) _c[2]) * 255)));
143 points_.push_back(_v);
164 colors_.push_back(_c);
174 colors4f_.push_back(_c);
186 ConstPointIter p_it=points_.begin(), p_end=points_.end();
187 for (; p_it!=p_end; ++p_it)
229 if(_state.compatibilityProfile())
230 drawCompat(_state, _drawMode);
367 if(_state.compatibilityProfile())
368 pickCompat(_state, _target);
377 const size_t n_edges =
n_points() - 1;
384 pick_edges(_state, 0);
391 pick_edges(_state, 0);
403 void LineNode::pick_edges(
GLState& _state,
unsigned int _offset)
417 glGenBuffers(1, &vbo_);
423 std::vector<float> vboData(3*points_.size(),0.f);
425 if (line_mode_ == LineSegmentsMode)
427 if( (points_.size()/2 == colors4f_.size()) )
431 vboData.resize(vboData.size() + 4 * points_.size());
432 float* vboPtr = &vboData[0];
434 ConstPointIter p_it=points_.begin(), p_end=points_.end();
435 ConstColor4fIter c_it=colors4f_.begin();
437 Color4f c(1.0f,1.0f,1.0f,1.0f);
438 if(c_it != colors4f_.end()) {
443 for (; p_it!=p_end; ++p_it)
445 if ((cnt > 0) && (cnt % 2 == 0) && (c_it+1) != colors4f_.end()) {
450 *(vboPtr++) = (*p_it)[0];
451 *(vboPtr++) = (*p_it)[1];
452 *(vboPtr++) = (*p_it)[2];
464 }
else if ( points_.size()/2 == colors_.size() )
469 vboData.resize(vboData.size() + 4 * points_.size());
470 float* vboPtr = &vboData[0];
472 ConstPointIter p_it=points_.begin(), p_end=points_.end();
473 ConstColorIter c_it=colors_.begin();
475 Color c((
char)255, (
char)255, (
char)255);
476 if(c_it != colors_.end()) {
481 for (; p_it!=p_end; ++p_it)
483 if ((cnt > 0) && (cnt % 2 == 0) && (c_it+1) != colors_.end()) {
489 *(vboPtr++) = (*p_it)[0];
490 *(vboPtr++) = (*p_it)[1];
491 *(vboPtr++) = (*p_it)[2];
494 *(vboPtr++) = c[0]/255.f;
495 *(vboPtr++) = c[1]/255.f;
496 *(vboPtr++) = c[2]/255.f;
506 ConstPointIter p_it=points_.begin(), p_end=points_.end();
507 float* vboPtr = &vboData[0];
509 for (; p_it!=p_end; ++p_it)
511 *(vboPtr++) = (*p_it)[0];
512 *(vboPtr++) = (*p_it)[1];
513 *(vboPtr++) = (*p_it)[2];
524 float* pPoints = &vboData[0];
527 for (
unsigned int i = 0 ; i < points_.size(); ++i) {
528 for (
unsigned int j = 0 ; j < 3 ; ++j) {
529 *(pPoints++) = points_[i][j];
534 glBindBuffer(GL_ARRAY_BUFFER_ARB, vbo_);
535 glBufferData(GL_ARRAY_BUFFER_ARB, vboData.size()*
sizeof(float) , &vboData[0] , GL_STATIC_DRAW_ARB);
553 ro.setMaterial(_mat);
555 lineNodeName_ = std::string(
"LineNode: ")+
name();
556 ro.debugName = lineNodeName_;
559 if (draw_always_on_top)
562 ro.depthTest =
false;
563 ro.depthWrite =
false;
568 ro.depthWrite =
true;
572 if ((line_mode_ == LineSegmentsMode) && (points_.size()/2 == colors4f_.size()))
575 ro.blendSrc = GL_SRC_ALPHA;
581 geomTemplate +=
"Wireframe/geom_line2quad.tpl";
583 ro.
shaderDesc.geometryTemplateFile = geomTemplate;
598 if (line_mode_ == LineSegmentsMode)
599 ro.glDrawArrays(GL_LINES, 0,
int( points_.size() ));
601 ro.glDrawArrays(GL_LINE_STRIP, 0,
int(points_.size()) );
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
DrawMode WIREFRAME
draw wireframe
Namespace providing different geometric functions concerning angles.
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
update bounding box
void leave(GLState &_state, const DrawModes::DrawMode &_drawMode)
reset depth function to what it was before enter()
pick any of the prior targets (should be implemented for all nodes)
void createVBO()
creates the vbo only if update was requested
void clear_points()
clear points/lines
void set_color(const Vec4f &_c)
set color (base, ambient, diffuse, specular) based on _c
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
std::string name() const
Returns: name of node (needs not be unique)
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
static void bindBuffer(GLenum _target, GLuint _buffer)
replaces glBindBuffer, supports locking
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const ACG::SceneGraph::Material *_mat)
Add the objects to the given renderer.
void leave(GLState &_state, const DrawModes::DrawMode &_drawmode)
restores original GL-color and GL-material
void enter(GLState &_state, const DrawModes::DrawMode &_drawmode)
set current GL-color and GL-material
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
int viewport_width() const
get viewport width
float line_width() const
get line width
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
draw lines and normals
unsigned int getNumElements() const
void set_depthFunc(const GLenum &_depth_func)
Call glDepthFunc() to actually change the depth comparison function, and store the new value in this ...
Interface class between scenegraph and renderer.
void add_point(const Vec3d &_v)
add point (for LineMode == PolygonMode)
void pick(GLState &_state, PickTarget _target)
Draw the line using the GL picking name stack.
void enter(GLState &_state, const DrawModes::DrawMode &_drawMode)
set depth function (needed for lasso selection so that the line can be draw in pseudo-2D) ...
LineMode
Line mode: draw line segments (every 2 points) or ONE polyline.
VectorT< float, 2 > Vec2f
LineNode(LineMode _mode, BaseNode *_parent=0, std::string _name="<LineNode>")
default constructor
void add_line(const Vec3d &_v0, const Vec3d &_v1)
add line (for LineMode == LineSegmentsMode)
void addElement(const VertexElement *_pElement)
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
int viewport_height() const
get viewport height
void setUniform(const char *_name, GLint _value)
set values for int uniforms
DrawModes::DrawMode availableDrawModes() const
return available draw modes
picks edges (may not be implemented for all nodes)
void clear_colors()
clear colors
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
static QString getShaderDir()
void clear()
clear points/lines and colors
ShaderGenDesc shaderDesc
Drawmode and other shader params.
size_t n_points() const
number of points
PickTarget
What target to use for picking.
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
void set_color(const Vec4f &_c)
Override material node's set color function in order to locally add color.
GLenum blendDest
glBlendFunc: GL_SRC_ALPHA, GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA ...
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
void add_color(const ACG::Vec3uc &_c)
add color (only for LineMode == LineSegmentsMode)
bool & alwaysOnTop()
get and set always on top
bool pick_set_maximum(size_t _idx)
Set the maximal number of primitives/components of your object.
void set_line_mode(LineMode _mode)
set line mode (see LineNode::LineMode)
int priority
Priority to allow sorting of objects.