Commit 767a85df authored by Jan Möbius's avatar Jan Möbius

Get material for the new renderers from the last material node.

refs #901

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15757 383ad7c9-94d9-4d36-a494-682f7c89f535
parent aa4f2a31
......@@ -52,7 +52,7 @@
#include <ACG/GL/VertexDeclaration.hh>
#include <ACG/GL/GLState.hh>
#include <ACG/Scenegraph/DrawModes.hh>
#include <ACG/Scenegraph/MaterialNode.hh>
namespace ACG
{
......@@ -141,6 +141,20 @@ void RenderObject::setupShaderGenFromDrawmode( const DrawModes::DrawModeProperti
}
}
void RenderObject::setMaterial( const SceneGraph::Material* _mat )
{
for (int i = 0; i < 3; ++i)
{
diffuse[i] = _mat->diffuseColor()[i];
ambient[i] = _mat->ambientColor()[i];
specular[i] = _mat->specularColor()[i];
emissive[i] = _mat->baseColor()[i];
}
shininess = _mat->shininess();
alpha = _mat->diffuseColor()[3];
}
RenderObject::RenderObject()
{
memset(this, 0, sizeof(RenderObject));
......
......@@ -59,6 +59,7 @@ namespace SceneGraph {
namespace DrawModes {
class DrawModeProperties;
}
class Material;
}
......@@ -260,6 +261,8 @@ struct ACGDLLEXPORT RenderObject
*/
void initFromState(GLState* _glState);
void setMaterial(const SceneGraph::Material* _mat);
/** \brief Fills out ShaderGenDesc parameters based on Drawmode properties
*/
void setupShaderGenFromDrawmode(const SceneGraph::DrawModes::DrawModeProperties* _props);
......
......@@ -71,7 +71,6 @@
#include <iostream>
#include <ACG/Scenegraph/DrawModes.hh>
//== NAMESPACES ===============================================================
......@@ -81,6 +80,8 @@ class IRenderer;
namespace SceneGraph {
// prototype declaration to avoid include-loop
class Material;
//== CLASS DEFINITION =========================================================
......@@ -189,9 +190,12 @@ public:
*
* Add any renderable geometry to the renderer via _renderer->addRenderObject()
*
* The material is fetched from the last active material node and may be used to setup Renderobjects,
* but may as well be ignored.
*
* \note You should not draw anything yourself in this function.
*/
virtual void getRenderObjects(IRenderer* /*_renderer*/, GLState& /* _state */, const DrawModes::DrawMode& /* _drawMode */) {}
virtual void getRenderObjects(IRenderer* /*_renderer*/, GLState& /* _state */, const DrawModes::DrawMode& /* _drawMode */, const Material* /*_mat*/) {}
/** The leave function is used to restore GL states the have been changed.
This function must restore the status before enter() !
......
......@@ -425,7 +425,7 @@ draw(GLState& _state , const DrawModes::DrawMode& /*_drawMode*/)
void CoordsysNode::getRenderObjects( IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode )
void CoordsysNode::getRenderObjects( IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat )
{
// Init state - changes when mode_ != POSITION
Vec3d pos3D(0.0,0.0,0.0);
......@@ -437,6 +437,7 @@ void CoordsysNode::getRenderObjects( IRenderer* _renderer, GLState& _state, cons
RenderObject ro;
memset(&ro, 0, sizeof(RenderObject));
ro.initFromState(&_state);
ro.setMaterial(_mat);
ro.depthTest = true;
......
......@@ -122,7 +122,7 @@ public:
void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
/// add renderobjects for shader pipeline renderer
void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode);
void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
/// draw Coordsys for object picking
void pick(GLState& _state, PickTarget _target);
......
......@@ -579,7 +579,7 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode) {
template <class Mesh>
void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode )
void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat )
{
RenderObject ro;
ro.initFromState(&_state);
......@@ -596,6 +596,7 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G
ro.depthTest = true; // some previous node disabled depth testing
ro.depthWrite = true;
ro.depthFunc = GL_LESS;
ro.setMaterial(_mat);
// ------------------------
......@@ -666,6 +667,9 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G
ro.shaderDesc.shadeMode = SG_SHADE_UNLIT;
drawMesh_->disableColors();
// use specular color for lines
ro.emissive = ro.specular;
add_line_RenderObjects(_renderer, &ro);
}
......@@ -705,6 +709,9 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G
ro.depthRange = Vec2f(0.0f, 1.0f);
// use specular color for lines
ro.emissive = ro.specular;
add_line_RenderObjects(_renderer, &ro);
}
......@@ -717,6 +724,9 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G
ro.vertexDecl = drawMesh_->getEdgeColoredVertexDeclaration();
ro.glDrawArrays(GL_LINES, 0, mesh_.n_edges() * 2);
// use specular color for lines
ro.emissive = ro.specular;
_renderer->addRenderObject(&ro);
// skip other edge primitives for this drawmode layer
......@@ -733,6 +743,9 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G
else
ro.vertexDecl = drawMesh_->getHalfedgeColoredVertexDeclaration();
// use specular color for lines
ro.emissive = ro.specular;
ro.glDrawArrays(GL_LINES, 0, mesh_.n_halfedges() * 2);
_renderer->addRenderObject(&ro);
......@@ -747,7 +760,12 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G
switch (props->primitive())
{
case DrawModes::PRIMITIVE_POINT: add_point_RenderObjects(_renderer, &ro); break;
case DrawModes::PRIMITIVE_EDGE: add_line_RenderObjects(_renderer, &ro); break;
case DrawModes::PRIMITIVE_EDGE:
{
// use specular color for lines
ro.emissive = ro.specular;
add_line_RenderObjects(_renderer, &ro);
} break;
case DrawModes::PRIMITIVE_POLYGON: add_face_RenderObjects(_renderer, &ro); break;
default: break;
}
......
......@@ -272,7 +272,7 @@ public:
/** \brief Draws the object deferred
*
*/
void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode);
void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
/** \brief return available draw modes
*
......
......@@ -770,7 +770,8 @@ GLMatrixd TranslationManipulatorNode::computeWorldMatrix()
void TranslationManipulatorNode::getRenderObjects(IRenderer* _renderer,
GLState& _state,
const DrawModes::DrawMode& _drawMode)
const DrawModes::DrawMode& _drawMode,
const Material* _mat)
{
if (draw_manipulator_)
{
......
......@@ -195,7 +195,7 @@ public:
void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
/// create renderobjects for shaderpipeline renderer
void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode);
void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
/// computes world matrix, transforms from model to world space
GLMatrixd computeWorldMatrix();
......
......@@ -754,7 +754,8 @@ bool SkeletonNodeT<SkeletonType>::coordFramesVisible()
template <class SkeletonType>
void SkeletonNodeT<SkeletonType>::getRenderObjects(IRenderer* _renderer,
GLState& _state,
const DrawModes::DrawMode& _drawMode)
const DrawModes::DrawMode& _drawMode,
const Material* _mat)
{
RenderObject ro;
ro.initFromState(&_state);
......@@ -772,18 +773,82 @@ void SkeletonNodeT<SkeletonType>::getRenderObjects(IRenderer* _renderer,
typename SkeletonType::Iterator it;
Vec4f jointColor;
getJointColor(_state.base_color(), jointColor);
// draw bones
//
// if ( (_drawMode == DrawModes::WIREFRAME)
// || (_drawMode == DrawModes::SOLID_FLAT_SHADED)
// || (_drawMode == DrawModes::SOLID_FACES_COLORED)
// || (_drawMode == DrawModes::SOLID_FACES_COLORED_FLAT_SHADED) )
// draw points
for (unsigned int i = 0; i < _drawMode.getNumLayers(); ++i)
{
const DrawModes::DrawModeProperties* props = _drawMode.getLayer(i);
Vec4f baseColor = _state.base_color();
ro.setupShaderGenFromDrawmode(props);
switch (props->primitive())
{
case DrawModes::PRIMITIVE_POINT:
{
Vec3f oldSpecular = ro.specular;
Vec3f oldDiffuse = ro.diffuse;
for(it = skeleton_.begin(); it != skeleton_.end(); ++it)
{
// If the vertex is selected, it will be always red
// If it is not selected,
if ( (*it)->selected() )
{
ro.diffuse = Vec3f(1.0f, 0.0f, 0.0f);
ro.specular = Vec3f(1.0f, 0.0f, 0.0f);
}
else {
// If it is the root joint, it will get some kind of orange color
// Otherwise the the Base color is used
if ( (*it)->isRoot() )
{
ro.diffuse = Vec3f(1.0f, 0.66f, 0.0f);
ro.specular = Vec3f(1.0f, 0.66f, 0.0f);
}
else {
ro.diffuse = Vec3f(jointColor[0], jointColor[1] , jointColor[2]);
ro.specular = Vec3f(jointColor[0], jointColor[1] , jointColor[2]);
}
}
ro.setupShaderGenFromDrawmode(_drawMode.getDrawModeProperties());
//---------------------------------------------------
// Simulate glPointSize(12) with a sphere
//---------------------------------------------------
// 1. Project point to screen
ACG::Vec3d projected = _state.project( pose->globalTranslation( (*it)->id() ) );
// 2. Shift it by the requested point size
// glPointSize defines the diameter but we want the radius, so we divide it by two
ACG::Vec3d shifted = projected;
shifted[0] = shifted[0] + (double)_state.point_size() / 2.0 ;
// 3. un-project into 3D
ACG::Vec3d unProjectedShifted = _state.unproject( shifted );
// 4. The difference vector defines the radius in 3D for the sphere
ACG::Vec3d difference = unProjectedShifted - pose->globalTranslation( (*it)->id() );
const double sphereSize = difference.norm();
sphere_->addToRenderer(_renderer, &ro, sphereSize, ACG::Vec3f(pose->globalTranslation( (*it)->id() )));
}
// reset material colors in case skeleton polygons are rendered later
ro.specular = oldSpecular;
ro.diffuse = oldDiffuse;
} break;
default:
{
Vec4f baseColor = _state.base_color();
// draw the bones
for(it = skeleton_.begin(); it != skeleton_.end(); ++it) {
......@@ -808,34 +873,11 @@ void SkeletonNodeT<SkeletonType>::getRenderObjects(IRenderer* _renderer,
addBoneToRenderer(_renderer, ro, parentPos, boneVector);
}
//
// // draw the local coordinate frames
// if(bCoordFramesVisible_)
// {
// ACG::GLState::disable(GL_COLOR_MATERIAL);
// ACG::GLState::disable(GL_LIGHTING);
//
// glLineWidth(3.0);
// glBegin(GL_LINES);
// for(it = skeleton_.begin(); it != skeleton_.end(); ++it)
// {
// unsigned int index = (*it)->id();
// typename SkeletonType::Matrix global = pose->globalMatrix(index);
// NormalizeCoordinateFrame(global);
// glColor3f(0.8, 0.2, 0.2);
// glVertex( pose->globalTranslation(index));
// glVertex( global.transform_point(Point(fFrameSize_, 0, 0)) );
// glColor3f(0.2, 0.8, 0.2);
// glVertex( pose->globalTranslation(index));
// glVertex( global.transform_point(Point(0, fFrameSize_, 0)) );
// glColor3f(0.2, 0.2, 0.8);
// glVertex( pose->globalTranslation(index));
// glVertex( global.transform_point(Point(0, 0, fFrameSize_)) );
// }
// glEnd();
// glLineWidth(_state.line_width());
// }
}
}
}
}
......
......@@ -105,7 +105,7 @@ public:
void pick(GLState& _state, PickTarget _target);
/// Adds renderobjects to renderer for flexible shader pipeline
void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode);
void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
/// Set the pose which should be rendered
void setActivePose(const AnimationHandle &_hAni);
......
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