Commit 01745b28 authored by Jan Möbius's avatar Jan Möbius
Browse files

First try of render objects for line node. results in gl errors.refs #1286

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15840 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 4859403c
......@@ -52,8 +52,9 @@
//== INCLUDES =================================================================
#include "LineNode.hh"
#include "../GL/gl.hh"
#include <ACG/GL/gl.hh>
#include <ACG/GL/IRenderer.hh>
#include <ACG/GL/VertexDeclaration.hh>
//== NAMESPACES ===============================================================
......@@ -249,6 +250,75 @@ leave(GLState& _state , const DrawModes::DrawMode& _drawMode)
MaterialNode::leave(_state, _drawMode);
}
//----------------------------------------------------------------------------
void
LineNode::
getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const ACG::SceneGraph::Material* _mat) {
// TODO: Implement in Line Node
// init base render object
RenderObject ro;
memset(&ro, 0, sizeof(RenderObject));
ro.initFromState(&_state);
ro.setMaterial(_mat);
if (line_mode_ == LineSegmentsMode)
{
if( (points_.size()/2 == colors4f_.size()) ) {
// One color entry per line segment (alpha channel available
} else if ((line_mode_ == LineSegmentsMode) && (points_.size()/2 == colors_.size()) ) {
// One color entry per line segment (no alpha channel available and uchars as colors)
} else {
// No colors. Just draw the segments
}
} else {
// No colors (Use material) and one continuous line
// create vbo
if (!vbo_)
glGenBuffersARB(1, &vbo_);
if ( vboData_) {
delete vboData_;
vboData_ = 0;
}
vboData_ = new float[3 * points_.size() * 4];
float* pPoints = &vboData_[0];
for (unsigned int i = 0 ; i < points_.size(); ++i) {
for ( unsigned int j = 0 ; j < 3 ; ++j) {
*(pPoints++) = points_[i][j];
}
}
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, 3 * points_.size() * 4 , vboData_ , GL_STATIC_DRAW_ARB);
ro.vertexBuffer = vbo_;
VertexDeclaration vertexDecl;
vertexDecl.addElement(GL_FLOAT, 3, VERTEX_USAGE_POSITION);
ro.vertexDecl = &vertexDecl;
ro.glDrawArrays(GL_LINE_STRIP, 0, points_.size() );
_renderer->addRenderObject(&ro);
}
}
//=============================================================================
} // namespace SceneGraph
......
......@@ -56,7 +56,7 @@
//== INCLUDES =================================================================
#include "MaterialNode.hh"
#include <ACG/Scenegraph/MaterialNode.hh>
#include "DrawModes.hh"
#include <vector>
......@@ -110,13 +110,21 @@ public:
MaterialNode::LineWidth),
line_mode_(_mode),
draw_always_on_top (false),
prev_depth_(GL_LESS)
prev_depth_(GL_LESS),
vbo_(0),
vboData_(0)
{
drawMode(DrawModes::WIREFRAME);
}
/// destructor
~LineNode() {}
~LineNode() {
if (vbo_)
glDeleteBuffersARB(1, &vbo_);
if ( vboData_)
delete vboData_;
}
/// set line mode (see LineNode::LineMode)
......@@ -197,6 +205,14 @@ public:
typedef Vec3d& reference;
typedef const Vec3d& const_reference;
/** \brief Add the objects to the given renderer
*
* @param _renderer The renderer which will be used. Add your geometry into this class
* @param _state The current GL State when this object is called
* @param _drawMode The active draw mode
* @param _mat Current material
*/
void getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const ACG::SceneGraph::Material* _mat);
protected:
......@@ -208,6 +224,10 @@ protected:
bool draw_always_on_top;
GLint prev_depth_;
unsigned int vbo_;
float* vboData_;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment