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()) );
DrawModes::DrawMode availableDrawModes() const override
return available draw modes
static QString getShaderDir()
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
void setUniform(const char *_name, GLint _value)
set values for int uniforms
picks edges (may not be implemented for all nodes)
void set_line_mode(LineMode _mode)
set line mode (see LineNode::LineMode)
void leave(GLState &_state, const DrawModes::DrawMode &_drawMode) override
reset depth function to what it was before enter()
void set_color(const Vec4f &_c)
Override material node's set color function in order to locally add color.
unsigned int getNumElements() const
void clear_colors()
clear colors
int viewport_width() const
get viewport width
VectorT< float, 2 > Vec2f
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
std::string name() const
Returns: name of node (needs not be unique)
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode) override
draw lines and normals
Namespace providing different geometric functions concerning angles.
size_t n_points() const
number of points
void add_line(const Vec3d &_v0, const Vec3d &_v1)
add line (for LineMode == LineSegmentsMode)
void pick(GLState &_state, PickTarget _target) override
Draw the line using the GL picking name stack.
ShaderGenDesc shaderDesc
Drawmode and other shader params.
void clear()
clear points/lines and colors
void add_point(const Vec3d &_v)
add point (for LineMode == PolygonMode)
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
void clear_points()
clear points/lines
PickTarget
What target to use for picking.
void leave(GLState &_state, const DrawModes::DrawMode &_drawmode) override
restores original GL-color and GL-material
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const ACG::SceneGraph::Material *_mat) override
Add the objects to the given renderer.
void addElement(const VertexElement *_pElement)
pick any of the prior targets (should be implemented for all nodes)
bool pick_set_maximum(size_t _idx)
Set the maximal number of primitives/components of your object.
int viewport_height() const
get viewport height
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
void createVBO()
creates the vbo only if update was requested
LineNode(LineMode _mode, BaseNode *_parent=0, std::string _name="<LineNode>")
default constructor
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax) override
update bounding box
LineMode
Line mode: draw line segments (every 2 points) or ONE polyline.
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
bool & alwaysOnTop()
get and set always on top
int priority
Priority to allow sorting of objects.
DrawMode WIREFRAME
draw wireframe
float line_width() const
get line width
void enter(GLState &_state, const DrawModes::DrawMode &_drawmode) override
set current GL-color and GL-material
void set_depthFunc(const GLenum &_depth_func)
Call glDepthFunc() to actually change the depth comparison function, and store the new value in this ...
GLenum blendDest
glBlendFunc: GL_SRC_ALPHA, GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA ...
void add_color(const ACG::Vec3uc &_c)
add color (only for LineMode == LineSegmentsMode)
Interface class between scenegraph and renderer.
static void bindBuffer(GLenum _target, GLuint _buffer)
replaces glBindBuffer, supports locking
void enter(GLState &_state, const DrawModes::DrawMode &_drawMode) override
set depth function (needed for lasso selection so that the line can be draw in pseudo-2D) ...
void set_color(const Vec4f &_c)
set color (base, ambient, diffuse, specular) based on _c