Commit cf85089f authored by Matthias Möller's avatar Matthias Möller

implements lineSegment mode for the new renderer

refs #1305

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@16842 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 30ba35cd
......@@ -71,7 +71,8 @@ LineNode::LineNode( LineMode _mode,
draw_always_on_top (false),
prev_depth_(GL_LESS),
vbo_(0),
updateVBO_(true)
updateVBO_(true),
colored_(false)
{
drawMode(DrawModes::WIREFRAME);
}
......@@ -366,96 +367,190 @@ leave(GLState& _state , const DrawModes::DrawMode& _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;
ro.initFromState(&_state);
ro.setMaterial(_mat);
void LineNode::createVBO()
{
if (!updateVBO_)
return;
ro.debugName = "LineNode";
// create vbo if it does not exist
if (!vbo_)
glGenBuffersARB(1, &vbo_);
// draw after scene-meshes
ro.priority = 1;
//3 coordinates per vertex
std::vector<float> vboData(3*points_.size(),0.f);
if (line_mode_ == LineSegmentsMode)
{
if( (points_.size()/2 == colors4f_.size()) )
{
// === One color entry per line segment (alpha channel available ) ===
colored_ = true;
if( (points_.size()/2 == colors4f_.size()) ) {
// One color entry per line segment (alpha channel available )
// TODO : Implement this mode
} else if ( points_.size()/2 == colors_.size() ) {
// One color entry per line segment (no alpha channel available and uchars as colors)
vboData.resize(vboData.size() + 4 * points_.size());
float* vboPtr = &vboData[0];
std::cerr << "Todo with old style colors" <<std::endl;
// TODO : Implement this mode
} else {
// No colors. Just draw the segments
ConstPointIter p_it=points_.begin(), p_end=points_.end();
ConstColor4fIter c_it=colors4f_.begin();
std::cerr << "Todo without colors" <<std::endl;
Color4f c(1.0f,1.0f,1.0f,1.0f);
if(c_it != colors4f_.end()) {
c = *c_it;
}
// TODO : Implement this mode
}
int cnt = 0;
for (; p_it!=p_end; ++p_it)
{
if ((cnt > 0) && (cnt % 2 == 0) && (c_it+1) != colors4f_.end()) {
++c_it;
c = *c_it;
}
//add position information
*(vboPtr++) = (*p_it)[0];
*(vboPtr++) = (*p_it)[1];
*(vboPtr++) = (*p_it)[2];
//add color information
*(vboPtr++) = c[0];
*(vboPtr++) = c[1];
*(vboPtr++) = c[2];
*(vboPtr++) = c[3];
++cnt;
}
//====================
} else if ( points_.size()/2 == colors_.size() )
{
//=== One color entry per line segment (no alpha channel available and uchars as colors) ===
colored_ = true;
//add 4 colors for each vertex
vboData.resize(vboData.size() + 4 * points_.size());
float* vboPtr = &vboData[0];
} else {
// No colors (Use material) and one continuous line
ConstPointIter p_it=points_.begin(), p_end=points_.end();
ConstColorIter c_it=colors_.begin();
Color c((char)255, (char)255, (char)255);
if(c_it != colors_.end()) {
c = *c_it;
}
// create vbo if it does not exist
if (!vbo_)
glGenBuffersARB(1, &vbo_);
int cnt = 0;
for (; p_it!=p_end; ++p_it)
{
if ((cnt > 0) && (cnt % 2 == 0) && (c_it+1) != colors_.end()) {
++c_it;
c = *c_it;
}
float* vboData_ = NULL;
//add position information
*(vboPtr++) = (*p_it)[0];
*(vboPtr++) = (*p_it)[1];
*(vboPtr++) = (*p_it)[2];
// Update the vbo only if required.
if ( updateVBO_ ) {
//add color information
*(vboPtr++) = c[0]/255.f;
*(vboPtr++) = c[1]/255.f;
*(vboPtr++) = c[2]/255.f;
*(vboPtr++) = 1.f;
// Create the required array
vboData_ = new float[3 * points_.size() * 4];
++cnt;
}
// Pointer to it for easier copy operation
float* pPoints = &vboData_[0];
//===========
} else
{
//=== No colors. Just draw the segments ===
colored_ = false;
ConstPointIter p_it=points_.begin(), p_end=points_.end();
float* vboPtr = &vboData[0];
// Copy from internal storage to vbo in memory
for (unsigned int i = 0 ; i < points_.size(); ++i) {
for ( unsigned int j = 0 ; j < 3 ; ++j) {
*(pPoints++) = points_[i][j];
}
for (; p_it!=p_end; ++p_it)
{
*(vboPtr++) = (*p_it)[0];
*(vboPtr++) = (*p_it)[1];
*(vboPtr++) = (*p_it)[2];
}
//===========
}
// Move data to the buffer
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, 3 * points_.size() * 4 , vboData_ , GL_STATIC_DRAW_ARB);
// Remove the local storage
delete[] vboData_;
}
else
{
// === No colors (Use material) and one continuous line ===
colored_ = false;
// Update done.
updateVBO_ = false;
// Pointer to it for easier copy operation
float* pPoints = &vboData[0];
// Copy from internal storage to vbo in memory
for (unsigned int i = 0 ; i < points_.size(); ++i) {
for ( unsigned int j = 0 ; j < 3 ; ++j) {
*(pPoints++) = points_[i][j];
}
}
}
ro.vertexBuffer = vbo_;
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, vboData.size()*sizeof(float) , &vboData[0] , GL_STATIC_DRAW_ARB);
// decl must be static or member, renderer does not make a copy
static VertexDeclaration vertexDecl;
vertexDecl.clear();
vertexDecl.addElement(GL_FLOAT, 3, VERTEX_USAGE_POSITION);
// Update done.
updateVBO_ = false;
ro.vertexDecl = &vertexDecl;
}
ro.glDrawArrays(GL_LINE_STRIP, 0, points_.size() );
void
LineNode::
getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const ACG::SceneGraph::Material* _mat) {
_renderer->addRenderObject(&ro);
if (!points_.size())
return;
// init base render object
RenderObject ro;
ro.initFromState(&_state);
ro.setMaterial(_mat);
ro.debugName = (std::string("LineNode: ")+name()).c_str();
// draw after scene-meshes
if (draw_always_on_top)
ro.priority = 1;
//set blending
if ((line_mode_ == LineSegmentsMode) && (points_.size()/2 == colors4f_.size()))
{
ro.blending = true;
ro.blendSrc = GL_SRC_ALPHA;
ro.blendDest = GL_ONE_MINUS_SRC_ALPHA;
}
createVBO();
ro.vertexBuffer = vbo_;
// decl must be static or member, renderer does not make a copy
static VertexDeclaration vertexDecl;
vertexDecl.clear();
vertexDecl.addElement(GL_FLOAT, 3, VERTEX_USAGE_POSITION);
if (colored_)
{
vertexDecl.addElement(GL_FLOAT, 4, VERTEX_USAGE_COLOR);
ro.shaderDesc.vertexColors = true;
}
ro.vertexDecl = &vertexDecl;
_state.set_line_width(_mat->lineWidth());
if (line_mode_ == LineSegmentsMode)
ro.glDrawArrays(GL_LINES, 0, points_.size());
else
ro.glDrawArrays(GL_LINE_STRIP, 0, points_.size());
_renderer->addRenderObject(&ro);
}
//=============================================================================
......
......@@ -199,6 +199,8 @@ public:
void getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const ACG::SceneGraph::Material* _mat);
protected:
/// creates the vbo only if update was requested
void createVBO();
PointVector points_;
ColorVector colors_;
......@@ -214,6 +216,10 @@ protected:
// True if points changed and the vbo has to be updated
bool updateVBO_;
//True if color information are saved inside the vbo
bool colored_;
};
......
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