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