Commit c414789d authored by Jan Möbius's avatar Jan Möbius

Dennis: New-interface-to-mark-objects via stencil buffer

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@6636 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 59f87526
......@@ -86,6 +86,19 @@ static SeparatorNode* sceneGraph_root_node_;
*/
static Viewer::ViewerProperties dummyProperties;
/** \brief DONT USE DIRECTLY!!
*
* This pointer is used internally
*/
static ViewObjectMarker* defaultMarker_ = 0;
/** \brief DONT USE DIRECTLY!!
*
* This pointer is used internally
*/
static ViewObjectMarker* currentMarker_ = 0;
void setDataRoot( BaseObject* _root ) {
objectRoot_ = _root;
}
......@@ -334,6 +347,8 @@ const std::string pickMode () {
}
void pickMode ( std::string _mode) {
// switch to default marker
setViewObjectMarker (defaultViewObjectMarker ());
viewerProperties().pickMode(_mode);
}
......@@ -564,6 +579,27 @@ ACG::Vec3d upVector(int _viewer) {
}
void setViewObjectMarker(ViewObjectMarker * _marker)
{
currentMarker_ = _marker;
}
ViewObjectMarker * currentViewObjectMarker()
{
return currentMarker_;
}
void setDefaultViewObjectMarker(ViewObjectMarker * _marker)
{
defaultMarker_ = _marker;
}
ViewObjectMarker * defaultViewObjectMarker()
{
return defaultMarker_;
}
ACG::SceneGraph::BaseNode* getSceneGraphRootNode() {
return PluginFunctions::sceneGraph_root_node_;
}
......
......@@ -54,6 +54,8 @@
#include <ACG/Scenegraph/SceneGraph.hh>
#include <OpenFlipper/BasePlugin/PluginFunctionsViewControls.hh>
//== FORWARDDECLARATIONS ======================================================
class ViewObjectMarker;
/** The Namespace PluginFunctions contains functions for all plugins. These functions should be used to get the
* objects to work on or to set modes in the examiner widget. */
......@@ -292,6 +294,28 @@ QPoint mapToGlobal( const QPoint _point );
DLLEXPORT
QPoint mapToLocal( const QPoint _point );
/** Set current ViewObjectMarker (will be reseted to default on pick mode change)
*
* @param _marker Object marker
*/
DLLEXPORT
void setViewObjectMarker (ViewObjectMarker *_marker);
/// Get the current ViewObjectMarker
DLLEXPORT
ViewObjectMarker* currentViewObjectMarker ();
/** Set the default ViewObjectMarker
*
* @param _marker Object marker
*/
DLLEXPORT
void setDefaultViewObjectMarker (ViewObjectMarker *_marker);
/// Get the default ViewObjectMarker
DLLEXPORT
ViewObjectMarker* defaultViewObjectMarker ();
/** @} */
......
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// OpenFlipper is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: $
// $Author: $
// $Date: $
//
//=============================================================================
#ifndef VIEWOBJECTMARKER_HH
#define VIEWOBJECTMARKER_HH
//== INCLUDES =================================================================
#include <ACG/Math/VectorT.hh>
//== FORWARDDECLARATIONS ======================================================
class BaseObject;
//== CLASS DEFINITION =========================================================
/** \class ViewObjectMarker ViewObjectMarker.hh <OpenFlipper/BasePlugin/ViewObjectMarker.hh>
Abstract base class to mark objects with help of the stencil buffer
**/
class DLLEXPORT ViewObjectMarker
{
//-------------------------------------------------------------- public methods
public:
//--------------------------------------------------- destructor
/// Blending type for this marker
enum Type {
/// Mark per returned reference
PerNumber,
/// Mark per returned reference bits
PerBit
};
/// Destructor.
virtual ~ViewObjectMarker () {};
virtual Type type () { return PerNumber; };
/** Get stencil reference for object
@param _obj Object
@param _reference stencil reference for object painting
@return should the reference be used
*/
virtual bool stencilRefForObject (BaseObject *_obj, GLuint &_reference) = 0;
/** Per reference number blending values
@param _reference stencil reference for blending
@param _src sfactor parameter for glBlendFunc function
@param _dst dfactor parameter for glBlendFunc function
@param _color color used for blending
@return should blending be berformed for this reference
*/
virtual bool blendForStencilRefNumber (GLuint _reference, GLenum &_src, GLenum &_dst, ACG::Vec4f &_color) { return false; };
/** Per reference bit blending values
@param _refbit stencil reference bit for blending
@param _src sfactor parameter for glBlendFunc function
@param _dst dfactor parameter for glBlendFunc function
@param _color color used for blending
@return should blending be berformed for this reference
*/
virtual bool blendForStencilRefBit (GLuint _refbit, GLenum &_src, GLenum &_dst, ACG::Vec4f &_color) { return false; };
};
#endif
\ No newline at end of file
......@@ -101,6 +101,7 @@
#endif
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/BasePlugin/ViewObjectMarker.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
......@@ -514,6 +515,38 @@ void glViewer::drawScene_mono()
if (sceneGraphRoot_)
{
if (! properties_.renderPicking() ) {
ViewObjectMarker *oM = PluginFunctions::currentViewObjectMarker ();
GLuint refBits = 0;
QSet<GLuint> references;
if (oM)
{
glClear (GL_STENCIL_BUFFER_BIT);
glEnable (GL_STENCIL_TEST);
glStencilOp (GL_KEEP, GL_KEEP, GL_ZERO);
glStencilFunc (GL_ALWAYS, 0, ~0);
for (PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS, DATA_ALL) ;
o_it != PluginFunctions::objectsEnd(); ++o_it)
{
bool ok;
GLuint ref;
ok = oM->stencilRefForObject(*o_it, ref);
if (ok)
{
o_it->stencilRefNode ()->setReference (ref);
o_it->stencilRefNode ()->show ();
refBits |= ref;
references << ref;
}
else
o_it->stencilRefNode ()->hide ();
}
}
ACG::SceneGraph::DrawAction action( properties_.drawMode() , false);
ACG::SceneGraph::traverse(sceneGraphRoot_, action, *glstate_, properties_.drawMode() );
......@@ -522,6 +555,78 @@ void glViewer::drawScene_mono()
ACG::SceneGraph::DrawAction action(properties_.drawMode(), true);
ACG::SceneGraph::traverse(sceneGraphRoot_, action, *glstate_, properties_.drawMode());
}
if (oM)
{
if (oM->type() == ViewObjectMarker::PerBit)
{
references.clear ();
for (unsigned int i = 0; i < sizeof (GLuint) * 8; i++)
if (refBits & (1 << i))
references << (1 << i);
}
glPushAttrib(GL_ALL_ATTRIB_BITS);
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glDisable(GL_DITHER);
int vp_l, vp_b, vp_w, vp_h;
glstate_->get_viewport (vp_l, vp_b, vp_w, vp_h);
glMatrixMode(GL_PROJECTION);
glPushMatrix ();
glLoadIdentity();
glOrtho(0, vp_w, vp_h, 0, 0, 1.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix ();
glLoadIdentity();
glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
foreach (unsigned int ref, references)
{
bool ok;
GLenum sfactor;
GLenum dfactor;
ACG::Vec4f color;
unsigned int mask = ~0;
if (oM->type() == ViewObjectMarker::PerBit)
{
ok = oM->blendForStencilRefBit (ref, sfactor, dfactor, color);
mask = ref;
}
else
ok = oM->blendForStencilRefNumber (ref, sfactor, dfactor, color);
if (!ok)
continue;
glStencilFunc (GL_EQUAL, ref, mask);
glBlendFunc (sfactor, dfactor);
glColor4f (color[0], color [1], color [2], color[3]);
glBegin (GL_QUADS);
glVertex2i(0, 0);
glVertex2i(0, vp_h);
glVertex2i(vp_w, vp_h);
glVertex2i(vp_w, 0);
glEnd ();
}
glMatrixMode(GL_PROJECTION);
glPopMatrix ();
glMatrixMode(GL_MODELVIEW);
glPopMatrix ();
glPopAttrib ();
glDisable (GL_STENCIL_TEST);
}
} else {
// prepare GL state
......
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