60 #include <ACG/GL/acg_glew.hh>
61 #include "LineNode.hh"
62 #include <ACG/GL/IRenderer.hh>
67 namespace SceneGraph {
75 picking_line_width_(
std::numeric_limits<float>::infinity()),
77 draw_always_on_top (false),
90 glDeleteBuffersARB(1, &vbo_);
140 (
char) (((
int) _c[1]) * 255),
141 (
char) (((
int) _c[2]) * 255)));
149 points_.push_back(_v);
170 colors_.push_back(_c);
180 colors4f_.push_back(_c);
192 ConstPointIter p_it=points_.begin(), p_end=points_.end();
193 for (; p_it!=p_end; ++p_it)
195 _bbMax.maximize(*p_it);
196 _bbMin.minimize(*p_it);
246 if (line_mode_ == LineSegmentsMode)
249 if( (points_.size()/2 == colors4f_.size()) )
253 glGetBooleanv( GL_BLEND, &blendb);
256 GLboolean depthmaskb;
257 glGetBooleanv( GL_DEPTH_WRITEMASK, &depthmaskb);
258 glDepthMask(GL_FALSE);
262 ConstPointIter p_it=points_.begin(), p_end=points_.end();
263 ConstColor4fIter c_it=colors4f_.begin();
265 Color4f c(1.0f,1.0f,1.0f,1.0f);
266 if(c_it != colors4f_.end()) {
271 for (; p_it!=p_end; ++p_it)
273 if ((cnt > 0) && (cnt % 2 == 0) && (c_it+1) != colors4f_.end()) {
287 if( blendb == GL_FALSE )
291 if( depthmaskb == GL_TRUE )
292 glDepthMask(GL_TRUE);
295 else if ((line_mode_ == LineSegmentsMode) && (points_.size()/2 == colors_.size()) )
298 ConstPointIter p_it=points_.begin(), p_end=points_.end();
299 ConstColorIter c_it=colors_.begin();
301 Color c((
char)255, (
char)255, (
char)255);
302 if(c_it != colors_.end()) {
307 for (; p_it!=p_end; ++p_it)
309 if ((cnt > 0) && (cnt % 2 == 0) && (c_it+1) != colors_.end()) {
325 ConstPointIter p_it=points_.begin(), p_end=points_.end();
327 for (; p_it!=p_end; ++p_it)
338 glBegin(GL_LINE_STRIP);
339 ConstPointIter p_it=points_.begin(), p_end=points_.end();
340 for (; p_it!=p_end; ++p_it)
375 const unsigned int n_edges =
n_points() - 1;
382 pick_edges(_state, 0);
389 pick_edges(_state, 0);
403 void LineNode::pick_edges(
GLState& _state,
unsigned int _offset)
409 const float line_width_old = _state.
line_width();
413 glDepthRange(0.0, 0.99);
415 if (line_mode_ == PolygonMode)
417 const unsigned int n_edges =
n_points() - 1;
418 for (
unsigned int i = 0; i < n_edges; ++i)
423 glArrayElement(i + 1);
427 else if (line_mode_ == LineSegmentsMode)
429 const unsigned int n_edges =
n_points() / 2;
430 for (
unsigned int i = 0; i < n_edges; ++i)
435 glArrayElement(2*i + 1);
440 glDepthRange(0.0, 1.0);
454 glGenBuffersARB(1, &vbo_);
460 std::vector<float> vboData(3*points_.size(),0.f);
462 if (line_mode_ == LineSegmentsMode)
464 if( (points_.size()/2 == colors4f_.size()) )
468 vboData.resize(vboData.size() + 4 * points_.size());
469 float* vboPtr = &vboData[0];
471 ConstPointIter p_it=points_.begin(), p_end=points_.end();
472 ConstColor4fIter c_it=colors4f_.begin();
474 Color4f c(1.0f,1.0f,1.0f,1.0f);
475 if(c_it != colors4f_.end()) {
480 for (; p_it!=p_end; ++p_it)
482 if ((cnt > 0) && (cnt % 2 == 0) && (c_it+1) != colors4f_.end()) {
487 *(vboPtr++) = (*p_it)[0];
488 *(vboPtr++) = (*p_it)[1];
489 *(vboPtr++) = (*p_it)[2];
501 }
else if ( points_.size()/2 == colors_.size() )
506 vboData.resize(vboData.size() + 4 * points_.size());
507 float* vboPtr = &vboData[0];
509 ConstPointIter p_it=points_.begin(), p_end=points_.end();
510 ConstColorIter c_it=colors_.begin();
512 Color c((
char)255, (
char)255, (
char)255);
513 if(c_it != colors_.end()) {
518 for (; p_it!=p_end; ++p_it)
520 if ((cnt > 0) && (cnt % 2 == 0) && (c_it+1) != colors_.end()) {
526 *(vboPtr++) = (*p_it)[0];
527 *(vboPtr++) = (*p_it)[1];
528 *(vboPtr++) = (*p_it)[2];
531 *(vboPtr++) = c[0]/255.f;
532 *(vboPtr++) = c[1]/255.f;
533 *(vboPtr++) = c[2]/255.f;
543 ConstPointIter p_it=points_.begin(), p_end=points_.end();
544 float* vboPtr = &vboData[0];
546 for (; p_it!=p_end; ++p_it)
548 *(vboPtr++) = (*p_it)[0];
549 *(vboPtr++) = (*p_it)[1];
550 *(vboPtr++) = (*p_it)[2];
561 float* pPoints = &vboData[0];
564 for (
unsigned int i = 0 ; i < points_.size(); ++i) {
565 for (
unsigned int j = 0 ; j < 3 ; ++j) {
566 *(pPoints++) = points_[i][j];
571 glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_);
572 glBufferDataARB(GL_ARRAY_BUFFER_ARB, vboData.size()*
sizeof(float) , &vboData[0] , GL_STATIC_DRAW_ARB);
590 ro.setMaterial(_mat);
592 lineNodeName_ = std::string(
"LineNode: ")+
name();
593 ro.debugName = lineNodeName_.c_str();
596 if (draw_always_on_top)
599 ro.depthTest =
false;
600 ro.depthWrite =
false;
605 ro.depthWrite =
true;
609 if ((line_mode_ == LineSegmentsMode) && (points_.size()/2 == colors4f_.size()))
612 ro.blendSrc = GL_SRC_ALPHA;
618 geomTemplate +=
"Wireframe/geom_line2quad.tpl";
620 ro.
shaderDesc.geometryTemplateFile = geomTemplate;
635 if (line_mode_ == LineSegmentsMode)
636 ro.glDrawArrays(GL_LINES, 0,
int( points_.size() ));
638 ro.glDrawArrays(GL_LINE_STRIP, 0,
int(points_.size()) );
VectorT< float, 2 > Vec2f
ShaderGenDesc shaderDesc
Drawmode and other shader params.
Namespace providing different geometric functions concerning angles.
void add_point(const Vec3d &_v)
add point (for LineMode == PolygonMode)
static void disableClientState(GLenum _cap)
replaces glDisableClientState, supports locking
std::string name() const
Returns: name of node (needs not be unique)
void pick_set_name(unsigned int _idx)
sets the current name/color (like glLoadName(_idx))
PickTarget
What target to use for picking.
void clear_points()
clear points/lines
static void disable(GLenum _cap)
replaces glDisable, but supports locking
void leave(GLState &_state, const DrawModes::DrawMode &_drawMode)
reset depth function to what it was before enter()
bool pick_set_maximum(unsigned int _idx)
Set the maximal number of primitives/components of your object.
pick any of the prior targets (should be implemented for all nodes)
Interface class between scenegraph and renderer.
GLenum blendDest
glBlendFunc: GL_SRC_ALPHA, GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA ...
void set_depthFunc(const GLenum &_depth_func)
Call glDepthFunc() to actually change the depth comparison function, and store the new value in this ...
void pick(GLState &_state, PickTarget _target)
Draw the line using the GL picking name stack.
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
void setUniform(const char *_name, GLint _value)
set values for int uniforms
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const ACG::SceneGraph::Material *_mat)
Add the objects to the given renderer.
void addElement(const VertexElement *_pElement)
void glColor(const Vec3f &_v)
Wrapper: glColor for Vec3f.
size_t n_points() const
number of points
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) ...
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
picks edges (may not be implemented for all nodes)
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
LineNode(LineMode _mode, BaseNode *_parent=0, std::string _name="<LineNode>")
default constructor
static void bindBuffer(GLenum _target, GLuint _buffer)
replaces glBindBuffer, supports locking
int viewport_width() const
get viewport width
void set_color(const Vec4f &_c)
set color (base, ambient, diffuse, specular) based on _c
void set_color(const Vec4f &_col)
set color
float line_width() const
get line width
void createVBO()
creates the vbo only if update was requested
void clear()
clear points/lines and colors
void leave(GLState &_state, const DrawModes::DrawMode &_drawmode)
restores original GL-color and GL-material
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
unsigned int getNumElements() const
float picking_line_width() const
get line width used by the picking renderer. Defaults to line_width().
void clear_colors()
clear colors
DrawModes::DrawMode availableDrawModes() const
return available draw modes
static void vertexPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glVertexPointer, supports locking
DrawMode WIREFRAME
draw wireframe
bool & alwaysOnTop()
get and set always on top
void set_line_width(float _f)
set line width
void enter(GLState &_state, const DrawModes::DrawMode &_drawmode)
set current GL-color and GL-material
void set_color(const Vec4f &_c)
Override material node's set color function in order to locally add color.
static void enableClientState(GLenum _cap)
replaces glEnableClientState, supports locking
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
void add_line(const Vec3d &_v0, const Vec3d &_v1)
add line (for LineMode == LineSegmentsMode)
int priority
Priority to allow sorting of objects.
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
draw lines and normals
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
update bounding box
void set_line_mode(LineMode _mode)
set line mode (see LineNode::LineMode)
const Vec4f & base_color() const
get base color (used when lighting is off)
void glVertex(const Vec2i &_v)
Wrapper: glVertex for Vec2i.
LineMode
Line mode: draw line segments (every 2 points) or ONE polyline.
static QString getShaderDir()
int viewport_height() const
get viewport height
void add_color(const ACG::Vec3uc &_c)
add color (only for LineMode == LineSegmentsMode)