Commit d67e9bab authored by Martin Schultz's avatar Martin Schultz

* commented out compatibility calls in the volumeMeshNode picking

implementation for core profiles.
* Implemented first variant for picking volumeḾeshvertices in core
profiles.
parent 52c09c83
......@@ -61,6 +61,8 @@
#include <ACG/GL/RenderObject.hh>
#include <ACG/GL/VertexDeclaration.hh>
#include <ACG/GL/IRenderer.hh>
#include <ACG/ShaderUtils/GLSLShader.hh>
#include <ACG/GL/ShaderCache.hh>
#include <OpenVolumeMesh/Mesh/HexahedralMesh.hh>
......@@ -1110,132 +1112,102 @@ void VolumeMeshNodeT<VolumeMeshT>::getRenderObjects(IRenderer* _renderer, GLStat
template<class VolumeMeshT>
void VolumeMeshNodeT<VolumeMeshT>::pick(GLState& _state, PickTarget _target) {
// save state
bool clientStateEnabledVertexArray = GLState::isClientStateEnabled(GL_VERTEX_ARRAY);
bool clientStateEnabledColorArray = GLState::isClientStateEnabled(GL_COLOR_ARRAY);
bool clientStateEnabledNormalArray = GLState::isClientStateEnabled(GL_NORMAL_ARRAY);
bool clientStateEnabledTexCoordArray = GLState::isClientStateEnabled(GL_TEXTURE_COORD_ARRAY);
if(_state.compatibilityProfile())
pickCompat(_state, _target);
else
{
GLState::depthRange(0.01, 1.0);
if (lastCellDrawMode_)
{
//draw cells so the user cannot pick invisible stuff
GLState::depthRange(0.01, 1.0);
if (lastCellDrawMode_)
{
//draw cells so the user cannot pick invisible stuff
GLState::bindBuffer(GL_ARRAY_BUFFER, cellsBufferManager_.getBuffer());
GLState::bindBuffer(GL_ARRAY_BUFFER, cellsBufferManager_.getBuffer());
GLState::enableClientState(GL_VERTEX_ARRAY);
GLState::vertexPointer(3, GL_FLOAT, cellsBufferManager_.getStride(), reinterpret_cast<GLvoid*>(0));
GLState::vertexPointer(3, GL_FLOAT, cellsBufferManager_.getStride(), reinterpret_cast<GLvoid*>(0));
GLState::disableClientState(GL_NORMAL_ARRAY);
GLState::disableClientState(GL_COLOR_ARRAY);
Vec4f bc = _state.specular_color();
_state.set_color(Vec4f(0.0,0.0,0.0,0.0));
Vec4f bc = _state.specular_color();
_state.set_color(Vec4f(0.0,0.0,0.0,0.0));
glDrawArrays(GL_TRIANGLES, 0, cellsBufferManager_.getNumOfVertices());
glDrawArrays(GL_TRIANGLES, 0, cellsBufferManager_.getNumOfVertices());
_state.set_color(bc);
GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
}
_state.set_color(bc);
GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
}
if (lastFaceDrawMode_)
{
//draw faces so the user cannot pick invisible stuff
if (lastFaceDrawMode_)
{
//draw faces so the user cannot pick invisible stuff
GLState::bindBuffer(GL_ARRAY_BUFFER, facesBufferManager_.getBuffer());
GLState::vertexPointer(3, GL_FLOAT, facesBufferManager_.getStride(), reinterpret_cast<GLvoid*>(0));
GLState::bindBuffer(GL_ARRAY_BUFFER, facesBufferManager_.getBuffer());
GLState::enableClientState(GL_VERTEX_ARRAY);
GLState::vertexPointer(3, GL_FLOAT, facesBufferManager_.getStride(), reinterpret_cast<GLvoid*>(0));
Vec4f bc = _state.specular_color();
_state.set_color(Vec4f(0.0,0.0,0.0,0.0));
GLState::disableClientState(GL_NORMAL_ARRAY);
GLState::disableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_TRIANGLES, 0, facesBufferManager_.getNumOfVertices());
Vec4f bc = _state.specular_color();
_state.set_color(Vec4f(0.0,0.0,0.0,0.0));
_state.set_color(bc);
GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
}
glDrawArrays(GL_TRIANGLES, 0, facesBufferManager_.getNumOfVertices());
GLenum oldDepthFunc = _state.depthFunc();
_state.set_color(bc);
GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
}
GLenum oldDepthFunc = _state.depthFunc();
GLState::depthRange(0.0, 1.0);
GLState::depthRange(0.0, 1.0);
_state.set_depthFunc(GL_LEQUAL);
_state.set_depthFunc(GL_LEQUAL);
switch (_target) {
case PICK_VERTEX: {
if (lastPickTarget_ != PICK_VERTEX)
vertexPickBufferManager_.invalidateColors();
_state.pick_set_maximum(mesh_.n_vertices());
pickVertices(_state);
break;
}
switch (_target) {
case PICK_VERTEX: {
if (lastPickTarget_ != PICK_VERTEX)
vertexPickBufferManager_.invalidateColors();
_state.pick_set_maximum(mesh_.n_vertices());
pickVertices(_state);
break;
}
case PICK_EDGE: {
_state.pick_set_maximum(mesh_.n_edges());
pickEdges(_state, 0);
break;
}
case PICK_EDGE: {
_state.pick_set_maximum(mesh_.n_edges());
pickEdges(_state, 0);
break;
}
case PICK_FACE: {
_state.pick_set_maximum(mesh_.n_faces());
pickFaces(_state, 0);
break;
}
case PICK_FACE: {
_state.pick_set_maximum(mesh_.n_faces());
pickFaces(_state, 0);
break;
}
case PICK_CELL: {
_state.pick_set_maximum(mesh_.n_cells());
pickCells(_state, 0);
break;
}
case PICK_CELL: {
_state.pick_set_maximum(mesh_.n_cells());
pickCells(_state, 0);
break;
}
case PICK_ANYTHING: {
if (lastPickTarget_ != PICK_ANYTHING)
vertexPickBufferManager_.invalidateColors();
int nv = mesh_.n_vertices();
int ne = mesh_.n_edges();
int nf = mesh_.n_faces();
int nc = mesh_.n_cells();
_state.pick_set_maximum(nv + ne + nf + nc);
pickVertices(_state);
pickEdges(_state, nv);
pickFaces(_state, nv + ne);
pickCells(_state, nv + ne + nf);
break;
}
case PICK_ANYTHING: {
if (lastPickTarget_ != PICK_ANYTHING)
vertexPickBufferManager_.invalidateColors();
default:
break;
}
int nv = mesh_.n_vertices();
int ne = mesh_.n_edges();
int nf = mesh_.n_faces();
int nc = mesh_.n_cells();
_state.set_depthFunc(oldDepthFunc);
_state.pick_set_maximum(nv + ne + nf + nc);
pickVertices(_state);
pickEdges(_state, nv);
pickFaces(_state, nv + ne);
pickCells(_state, nv + ne + nf);
break;
}
lastPickTarget_ = _target;
default:
break;
}
// restore state
if (clientStateEnabledVertexArray)
GLState::enableClientState(GL_VERTEX_ARRAY);
else
GLState::disableClientState(GL_VERTEX_ARRAY);
if (clientStateEnabledColorArray)
GLState::enableClientState(GL_COLOR_ARRAY);
else
GLState::disableClientState(GL_COLOR_ARRAY);
if (clientStateEnabledNormalArray)
GLState::enableClientState(GL_NORMAL_ARRAY);
else
GLState::disableClientState(GL_NORMAL_ARRAY);
if (clientStateEnabledTexCoordArray)
GLState::enableClientState(GL_TEXTURE_COORD_ARRAY);
else
GLState::disableClientState(GL_TEXTURE_COORD_ARRAY);
_state.set_depthFunc(oldDepthFunc);
lastPickTarget_ = _target;
}
}
template<class VolumeMeshT>
......@@ -1274,27 +1246,35 @@ void VolumeMeshNodeT<VolumeMeshT>::pickVertices(GLState& _state) {
vertexPickBufferManager_.disableNormals();
vertexPickBufferManager_.enablePickColors();
int pickVertexMethod_ = 0;
static GLSL::Program* pickVertexShader_;
// load from cache
if (pickVertexMethod_ == 0)
pickVertexShader_ = ShaderCache::getInstance()->getProgram("Picking/pick_vertices_vs.glsl", "Picking/pick_vertices_fs.glsl", 0, false);
else
pickVertexShader_ = ShaderCache::getInstance()->getProgram("Picking/vertex.glsl", "Picking/pick_vertices_fs2.glsl", 0, false);
// check link status
if(!( pickVertexShader_ && pickVertexShader_->isLinked()))
return;
GLState::bindBuffer(GL_ARRAY_BUFFER, vertexPickBufferManager_.getPickBuffer(_state, 0));
pickVertexShader_->use();
vertexPickBufferManager_.getVertexDeclaration()->activateShaderPipeline(pickVertexShader_);
GLState::enableClientState(GL_VERTEX_ARRAY);
GLState::vertexPointer(3, GL_FLOAT, vertexPickBufferManager_.getStride(), reinterpret_cast<GLvoid*>(0));
GLState::enableClientState(GL_COLOR_ARRAY);
GLState::colorPointer(4, GL_UNSIGNED_BYTE, vertexPickBufferManager_.getStride(), reinterpret_cast<GLvoid*>(vertexPickBufferManager_.getColorOffset()));
GLState::shadeModel(GL_SMOOTH);
GLState::disable(GL_LIGHTING);
pickVertexShader_->setUniform("pickVertexOffset", static_cast<GLint>(_state.pick_current_index()));//vertexPickBufferManager_.getColorOffset()) );
pickVertexShader_->setUniform("mWVP", _state.projection() * _state.modelview());
float oldPointSize = _state.point_size();
_state.set_point_size(1.5*_state.point_size());
glDrawArrays(GL_POINTS, 0, vertexPickBufferManager_.getNumOfVertices());
vertexPickBufferManager_.getVertexDeclaration()->deactivateShaderPipeline(pickVertexShader_);
pickVertexShader_->disable();
_state.set_point_size(oldPointSize);
GLState::disableClientState(GL_COLOR_ARRAY);
GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
}
......@@ -1315,14 +1295,14 @@ void VolumeMeshNodeT<VolumeMeshT>::pickEdges(GLState& _state, unsigned int _offs
GLState::bindBuffer(GL_ARRAY_BUFFER, edgePickBufferManager_.getPickBuffer(_state, _offset));
GLState::enableClientState(GL_VERTEX_ARRAY);
GLState::vertexPointer(3, GL_FLOAT, edgePickBufferManager_.getStride(), reinterpret_cast<GLvoid*>(0));
//GLState::enableClientState(GL_VERTEX_ARRAY);
//GLState::vertexPointer(3, GL_FLOAT, edgePickBufferManager_.getStride(), reinterpret_cast<GLvoid*>(0));
GLState::enableClientState(GL_COLOR_ARRAY);
GLState::colorPointer(4, GL_UNSIGNED_BYTE, edgePickBufferManager_.getStride(), reinterpret_cast<GLvoid*>(edgePickBufferManager_.getColorOffset()));
//GLState::enableClientState(GL_COLOR_ARRAY);
//GLState::colorPointer(4, GL_UNSIGNED_BYTE, edgePickBufferManager_.getStride(), reinterpret_cast<GLvoid*>(edgePickBufferManager_.getColorOffset()));
GLState::shadeModel(GL_SMOOTH);
GLState::disable(GL_LIGHTING);
//GLState::shadeModel(GL_SMOOTH);
//GLState::disable(GL_LIGHTING);
float oldLineWidth = _state.line_width();
_state.set_line_width(4.0*_state.line_width());
......@@ -1331,7 +1311,7 @@ void VolumeMeshNodeT<VolumeMeshT>::pickEdges(GLState& _state, unsigned int _offs
_state.set_line_width(oldLineWidth);
GLState::disableClientState(GL_COLOR_ARRAY);
//GLState::disableClientState(GL_COLOR_ARRAY);
GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
}
......@@ -1354,18 +1334,18 @@ void VolumeMeshNodeT<VolumeMeshT>::pickFaces(GLState& _state, unsigned int _offs
GLState::bindBuffer(GL_ARRAY_BUFFER, facePickBufferManager_.getPickBuffer(_state, _offset));
GLState::enableClientState(GL_VERTEX_ARRAY);
GLState::vertexPointer(3, GL_FLOAT, facePickBufferManager_.getStride(), reinterpret_cast<GLvoid*>(0));
//GLState::enableClientState(GL_VERTEX_ARRAY);
//GLState::vertexPointer(3, GL_FLOAT, facePickBufferManager_.getStride(), reinterpret_cast<GLvoid*>(0));
GLState::enableClientState(GL_COLOR_ARRAY);
GLState::colorPointer(4, GL_UNSIGNED_BYTE, facePickBufferManager_.getStride(), reinterpret_cast<GLvoid*>(facePickBufferManager_.getColorOffset()));
//GLState::enableClientState(GL_COLOR_ARRAY);
//GLState::colorPointer(4, GL_UNSIGNED_BYTE, facePickBufferManager_.getStride(), reinterpret_cast<GLvoid*>(facePickBufferManager_.getColorOffset()));
GLState::shadeModel(GL_SMOOTH);
GLState::disable(GL_LIGHTING);
//GLState::shadeModel(GL_SMOOTH);
//GLState::disable(GL_LIGHTING);
glDrawArrays(GL_TRIANGLES, 0, facePickBufferManager_.getNumOfVertices());
GLState::disableClientState(GL_COLOR_ARRAY);
//GLState::disableClientState(GL_COLOR_ARRAY);
GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
}
......@@ -1381,18 +1361,18 @@ void VolumeMeshNodeT<VolumeMeshT>::pickCells(GLState& _state, unsigned int _offs
GLState::bindBuffer(GL_ARRAY_BUFFER, cellPickBufferManager_.getPickBuffer(_state, _offset));
GLState::enableClientState(GL_VERTEX_ARRAY);
GLState::vertexPointer(3, GL_FLOAT, cellPickBufferManager_.getStride(), reinterpret_cast<GLvoid*>(0));
//GLState::enableClientState(GL_VERTEX_ARRAY);
//GLState::vertexPointer(3, GL_FLOAT, cellPickBufferManager_.getStride(), reinterpret_cast<GLvoid*>(0));
GLState::enableClientState(GL_COLOR_ARRAY);
GLState::colorPointer(4, GL_UNSIGNED_BYTE, cellPickBufferManager_.getStride(), reinterpret_cast<GLvoid*>(cellPickBufferManager_.getColorOffset()));
//GLState::enableClientState(GL_COLOR_ARRAY);
//GLState::colorPointer(4, GL_UNSIGNED_BYTE, cellPickBufferManager_.getStride(), reinterpret_cast<GLvoid*>(cellPickBufferManager_.getColorOffset()));
GLState::shadeModel(GL_SMOOTH);
GLState::disable(GL_LIGHTING);
//GLState::shadeModel(GL_SMOOTH);
//GLState::disable(GL_LIGHTING);
glDrawArrays(GL_TRIANGLES, 0, cellPickBufferManager_.getNumOfVertices());
GLState::disableClientState(GL_COLOR_ARRAY);
//GLState::disableClientState(GL_COLOR_ARRAY);
GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
}
......
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