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

Switch available drawmodes function from const to non const as nodes may...

Switch available drawmodes function from const to non const as nodes may dynamically change the supported drawmodes depending on the data they have

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@12533 383ad7c9-94d9-4d36-a494-682f7c89f535
parent d14e079a
......@@ -158,7 +158,7 @@ boundingBox(Vec3d& _bbMin, Vec3d& _bbMax)
template<class Mesh>
DrawModes::DrawMode
MeshNodeT<Mesh>::
availableDrawModes() const
availableDrawModes()
{
DrawModes::DrawMode drawModes(DrawModes::NONE);
......
......@@ -102,7 +102,7 @@ public:
/// return available draw modes
DrawModes::DrawMode availableDrawModes() const;
DrawModes::DrawMode availableDrawModes();
/// update bounding box
void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
/// drawing
......
......@@ -93,7 +93,7 @@ boundingBox(Vec3d& _bbMin, Vec3d& _bbMax)
DrawModes::DrawMode
OBJNode::
availableDrawModes() const
availableDrawModes()
{
return ( DrawModes::POINTS |
DrawModes::WIREFRAME |
......
......@@ -95,7 +95,7 @@ public:
/// return available draw modes
DrawModes::DrawMode availableDrawModes() const;
DrawModes::DrawMode availableDrawModes();
/// update bounding box
void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
......
......@@ -79,7 +79,7 @@ void PlaneNode::boundingBox(Vec3d& _bbMin, Vec3d& _bbMax)
//----------------------------------------------------------------------------
DrawModes::DrawMode
PlaneNode::availableDrawModes() const
PlaneNode::availableDrawModes()
{
return ( DrawModes::POINTS |
DrawModes::POINTS_SHADED |
......
......@@ -86,7 +86,7 @@ class ACGDLLEXPORT PlaneNode : public BaseNode
ACG_CLASSNAME(PlaneNode);
/// return available draw modes
DrawModes::DrawMode availableDrawModes() const;
DrawModes::DrawMode availableDrawModes();
/// update bounding box
void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
......
......@@ -81,7 +81,7 @@ boundingBox(Vec3d& _bbMin, Vec3d& _bbMax)
DrawModes::DrawMode
PointNode::
availableDrawModes() const
availableDrawModes()
{
return ( DrawModes::POINTS |
DrawModes::POINTS_SHADED |
......
......@@ -103,7 +103,7 @@ public:
ACG_CLASSNAME(PointNode);
/// return available draw modes
DrawModes::DrawMode availableDrawModes() const;
DrawModes::DrawMode availableDrawModes();
/// update bounding box
void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
......
......@@ -112,7 +112,7 @@ QuadNode::boundingBox( Vec3d & _bbMin, Vec3d & _bbMax )
DrawModes::DrawMode
QuadNode::
availableDrawModes() const
availableDrawModes()
{
DrawModes::DrawMode drawModes(DrawModes::NONE);
......
......@@ -79,7 +79,7 @@ public:
ACG_CLASSNAME(QuadNode);
DrawModes::DrawMode availableDrawModes() const;
DrawModes::DrawMode availableDrawModes();
void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
......
......@@ -200,7 +200,7 @@ ShaderNode::fragmentShaderName(DrawModes::DrawMode _drawmode, bool _pick) {
void ShaderNode::leave(GLState& /*_state*/, const DrawModes::DrawMode& _drawmode )
{
for ( std::map<unsigned int,ShaderInfo>::iterator it = shaders.begin(); it != shaders.end(); ++it)
for ( std::map<unsigned int,ShaderInfo>::iterator it = shaders.begin(); it != shaders.end(); ++it)
if ( _drawmode.containsAtomicDrawMode(it->first) && it->second.initialized )
it->second.program->disable();
}
......@@ -210,7 +210,7 @@ void ShaderNode::leave(GLState& /*_state*/, const DrawModes::DrawMode& _drawmode
void ShaderNode::leavePick(GLState& /*_state*/, PickTarget /*_target*/, const DrawModes::DrawMode& _drawmode )
{
for ( std::map<unsigned int,ShaderInfo>::iterator it = pickShaders.begin(); it != pickShaders.end(); ++it)
for ( std::map<unsigned int,ShaderInfo>::iterator it = pickShaders.begin(); it != pickShaders.end(); ++it)
if ( _drawmode.containsAtomicDrawMode(it->first) && it->second.initialized )
it->second.program->disable();
}
......@@ -262,21 +262,27 @@ void
ShaderNode::
disableShader (DrawModes::DrawMode _drawmode) {
unsigned int index = _drawmode.getIndex();
// Cleanup old shaders for this mode, if they exist
if ( shaders[index].initialized ) {
if ( shaders[index].program != 0 )
delete shaders[index].program;
if ( !_drawmode.isAtomic() ) {
std::cerr << "disableShader: Error, draw mode not atomic!" << std::endl;
return;
}
unsigned int index = _drawmode.getIndex();
if ( shaders[index].vertexShader != 0 )
delete shaders[index].vertexShader;
// Cleanup old shaders for this mode, if they exist
if ( shaders[index].initialized ) {
if ( shaders[index].program != 0 )
delete shaders[index].program;
if ( shaders[index].fragmentShader != 0 )
delete shaders[index].fragmentShader;
if ( shaders[index].vertexShader != 0 )
delete shaders[index].vertexShader;
shaders[index].initialized = false;
}
if ( shaders[index].fragmentShader != 0 )
delete shaders[index].fragmentShader;
shaders[index].initialized = false;
}
}
//----------------------------------------------------------------------------
......@@ -299,9 +305,16 @@ setShader( DrawModes::DrawMode _drawmode ,
return;
}
if ( !_drawmode.isAtomic() ) {
std::cerr << "setShader: Error, draw mode not atomic!" << std::endl;
return;
}
disableShader (_drawmode);
unsigned int index = _drawmode.getIndex();
std::cerr << "Added shader for mode : " << index << std::endl;
shaders[index].vertexShaderFile = shaderDir_ + _vertexShader;
shaders[index].fragmentShaderFile = shaderDir_ + _fragmentShader;
......@@ -385,13 +398,17 @@ setShaderDir( std::string _shaderDir) {
DrawModes::DrawMode
ShaderNode::
availableDrawModes() const
availableDrawModes()
{
DrawModes::DrawMode drawModes(DrawModes::NONE);
drawModes |= DrawModes::SOLID_PHONG_SHADED;
drawModes |= DrawModes::SOLID_SHADER;
for ( std::map<unsigned int,ShaderInfo>::iterator it = shaders.begin(); it != shaders.end(); ++it) {
// If the shader for this drawmode is initialized, this node supports the given draw mode.
// Then we add it to the list of supported draw modes
if ( it->second.initialized) {
drawModes |= DrawModes::DrawMode(it->first);
}
}
return drawModes;
......
......@@ -134,7 +134,7 @@ public:
bool hasShader( DrawModes::DrawMode _drawmode, bool _pick = false);
/// return available draw modes
DrawModes::DrawMode availableDrawModes() const;
DrawModes::DrawMode availableDrawModes();
private :
// Path to the shaders ( if set ). If empty shaders will not be used.
......
......@@ -104,7 +104,7 @@ SliceNode::boundingBox( Vec3d & _bbMin, Vec3d & _bbMax )
DrawModes::DrawMode
SliceNode::availableDrawModes() const
SliceNode::availableDrawModes()
{
return 0;
return ( DrawModes::POINTS |
......
......@@ -90,7 +90,7 @@ public:
ACG_CLASSNAME( SliceNode );
DrawModes::DrawMode availableDrawModes() const;
DrawModes::DrawMode availableDrawModes();
void boundingBox( Vec3d & _bbMin, Vec3d & _bbMax );
......
......@@ -107,7 +107,7 @@ boundingBox(Vec3d& _bbMin, Vec3d& _bbMax)
template <class Mesh, class Mod>
DrawModes::DrawMode
StatusNodeT<Mesh, Mod>::
availableDrawModes() const
availableDrawModes()
{
return (DrawModes::POINTS |
DrawModes::WIREFRAME |
......
......@@ -109,7 +109,7 @@ public:
void updateSelection();
DrawModes::DrawMode availableDrawModes() const;
DrawModes::DrawMode availableDrawModes();
void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
void pick(GLState& /* _state */ , PickTarget /* _target */ ) {}
......
......@@ -97,7 +97,7 @@ boundingBox(Vec3d& /*_bbMin*/, Vec3d& /*_bbMax*/)
DrawModes::DrawMode
TextNode::
availableDrawModes() const
availableDrawModes()
{
return ( DrawModes::POINTS |
DrawModes::POINTS_SHADED |
......
......@@ -111,7 +111,7 @@ public:
ACG_CLASSNAME(TextNode);
/// return available draw modes
DrawModes::DrawMode availableDrawModes() const;
DrawModes::DrawMode availableDrawModes();
/// update bounding box
void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
......
......@@ -112,7 +112,7 @@ TriangleNode::boundingBox( Vec3d & _bbMin, Vec3d & _bbMax )
DrawModes::DrawMode
TriangleNode::
availableDrawModes() const
availableDrawModes()
{
DrawModes::DrawMode drawModes(DrawModes::NONE);
......
......@@ -80,7 +80,7 @@ public:
ACG_CLASSNAME(TriangleNode);
DrawModes::DrawMode availableDrawModes() const;
DrawModes::DrawMode availableDrawModes();
void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
......
Supports Markdown
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