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