SceneGraphBuilder
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library 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
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGUTIL_SCENEGRAPHBUILDER
#define OSGUTIL_SCENEGRAPHBUILDER 1
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/MatrixTransform>
#include <osg/GLU>
#include <osgUtil/Export>
namespace osgUtil {
class OSGUTIL_EXPORT SceneGraphBuilder
{
public:
SceneGraphBuilder();
//
// OpenGL 1.0 style building methods
//
void PushMatrix();
void PopMatrix();
void LoadIdentity();
void LoadMatrixd(const GLdouble* m);
void MultMatrixd(const GLdouble* m);
void Translated(GLdouble x, GLdouble y, GLdouble z);
void Scaled(GLdouble x, GLdouble y, GLdouble z);
void Rotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
void BlendFunc(GLenum srcFactor, GLenum dstFactor);
void CullFace(GLenum mode);
void DepthFunc(GLenum mode);
void FrontFace(GLenum mode);
void LineStipple(GLint factor, GLushort pattern);
void LineWidth(GLfloat lineWidth);
void PointSize(GLfloat pointSize);
void PolygonMode(GLenum face, GLenum mode);
void PolygonOffset(GLfloat factor, GLfloat units);
void PolygonStipple(const GLubyte* mask);
void ShadeModel(GLenum mode);
void Enable(GLenum mode);
void Disable(GLenum mode);
void Color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
void Color4fv(GLfloat* c) { Color4f(c[0], c[1], c[2], c[3]); }
void Vertex3f(GLfloat x, GLfloat y, GLfloat z);
void Vertex3fv(GLfloat* v) { Vertex3f(v[0], v[1], v[2]); }
void Normal3f(GLfloat x, GLfloat y, GLfloat z);
void Normal3fv(GLfloat* n) { Normal3f(n[0], n[1], n[2]); }
void TexCoord1f(GLfloat x);
void TexCoord1fv(GLfloat* tc) { TexCoord1f(tc[0]); }
void TexCoord2f(GLfloat x, GLfloat y);
void TexCoord2fv(GLfloat* tc) { TexCoord2f(tc[0],tc[1]); }
void TexCoord3f(GLfloat x, GLfloat y, GLfloat z);
void TexCoord3fv(GLfloat* tc) { TexCoord3f(tc[0], tc[1], tc[2]); }
void TexCoord4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w);
void TexCoord4fv(GLfloat* tc) { TexCoord4f(tc[0], tc[1], tc[2], tc[3]); }
void Begin(GLenum mode);
void End();
//
// glu style building methods
//
void QuadricDrawStyle(GLenum aDrawStyle);
void QuadricNormals(GLenum aNormals);
void QuadricOrientation(GLenum aOrientation);
void QuadricTexture(GLboolean aTexture);
void Cylinder(GLfloat base,
GLfloat top,
GLfloat height,
GLint slices,
GLint stacks);
void Disk(GLfloat inner,
GLfloat outer,
GLint slices,
GLint loops);
void PartialDisk(GLfloat inner,
GLfloat outer,
GLint slices,
GLint loops,
GLfloat start,
GLfloat sweep);
void Sphere(GLfloat radius,
GLint slices,
GLint stacks);
//
// methods for obtaining the built scene graph
//
osg::Node* getScene();
osg::Node* takeScene();
protected:
typedef std::vector<osg::Matrixd> Matrices;
void matrixChanged();
void addAttribute(osg::StateAttribute* attribute);
void addMode(GLenum mode, bool enabled);
void addTextureAttribute(unsigned int unit, osg::StateAttribute* attribute);
void addTextureMode(unsigned int unit, GLenum mode, bool enabled);
void addShape(osg::Shape* shape);
void addDrawable(osg::Drawable* drawable);
void newGeometry();
void allocateGeometry();
void completeGeometry();
void allocateStateSet();
Matrices _matrixStack;
osg::ref_ptr<osg::StateSet> _stateset;
bool _statesetAssigned;
bool _normalSet;
osg::Vec3f _normal;
bool _colorSet;
osg::Vec4f _color;
unsigned int _maxNumTexCoordComponents;
osg::Vec4f _texCoord;
GLenum _primitiveMode;
osg::ref_ptr<osg::Vec3Array> _vertices;
osg::ref_ptr<osg::Vec3Array> _normals;
osg::ref_ptr<osg::Vec4Array> _colors;
osg::ref_ptr<osg::Vec4Array> _texCoords;
struct QuadricState
{
QuadricState():
_drawStyle(GLU_FILL),
_normals(GLU_SMOOTH),
_orientation(GLU_OUTSIDE),
_texture(GLU_FALSE) {}
GLenum _drawStyle;
GLenum _normals;
GLenum _orientation;
GLboolean _texture;
};
QuadricState _quadricState;
osg::ref_ptr<osg::Geometry> _geometry;
osg::ref_ptr<osg::Geode> _geode;
osg::ref_ptr<osg::MatrixTransform> _transform;
osg::ref_ptr<osg::Group> _group;
};
}
#endif
GLU
GLU_OUTSIDE
#define GLU_OUTSIDE
Definition GLU:105
GLU_SMOOTH
#define GLU_SMOOTH
Definition GLU:100
GLU_FALSE
#define GLU_FALSE
Definition GLU:87
GLU_FILL
#define GLU_FILL
Definition GLU:93
Geode
Geometry
MatrixTransform
osgUtil::SceneGraphBuilder::QuadricDrawStyle
void QuadricDrawStyle(GLenum aDrawStyle)
osgUtil::SceneGraphBuilder::MultMatrixd
void MultMatrixd(const GLdouble *m)
osgUtil::SceneGraphBuilder::Disk
void Disk(GLfloat inner, GLfloat outer, GLint slices, GLint loops)
osgUtil::SceneGraphBuilder::_color
osg::Vec4f _color
Definition SceneGraphBuilder:148
osgUtil::SceneGraphBuilder::DepthFunc
void DepthFunc(GLenum mode)
osgUtil::SceneGraphBuilder::PolygonOffset
void PolygonOffset(GLfloat factor, GLfloat units)
osgUtil::SceneGraphBuilder::QuadricNormals
void QuadricNormals(GLenum aNormals)
osgUtil::SceneGraphBuilder::allocateStateSet
void allocateStateSet()
osgUtil::SceneGraphBuilder::_geometry
osg::ref_ptr< osg::Geometry > _geometry
Definition SceneGraphBuilder:176
osgUtil::SceneGraphBuilder::Enable
void Enable(GLenum mode)
osgUtil::SceneGraphBuilder::_vertices
osg::ref_ptr< osg::Vec3Array > _vertices
Definition SceneGraphBuilder:154
osgUtil::SceneGraphBuilder::TexCoord2f
void TexCoord2f(GLfloat x, GLfloat y)
osgUtil::SceneGraphBuilder::Begin
void Begin(GLenum mode)
osgUtil::SceneGraphBuilder::_colors
osg::ref_ptr< osg::Vec4Array > _colors
Definition SceneGraphBuilder:156
osgUtil::SceneGraphBuilder::Vertex3f
void Vertex3f(GLfloat x, GLfloat y, GLfloat z)
osgUtil::SceneGraphBuilder::LoadMatrixd
void LoadMatrixd(const GLdouble *m)
osgUtil::SceneGraphBuilder::Normal3f
void Normal3f(GLfloat x, GLfloat y, GLfloat z)
osgUtil::SceneGraphBuilder::_maxNumTexCoordComponents
unsigned int _maxNumTexCoordComponents
Definition SceneGraphBuilder:150
osgUtil::SceneGraphBuilder::_normalSet
bool _normalSet
Definition SceneGraphBuilder:144
osgUtil::SceneGraphBuilder::getScene
osg::Node * getScene()
osgUtil::SceneGraphBuilder::Vertex3fv
void Vertex3fv(GLfloat *v)
Definition SceneGraphBuilder:65
osgUtil::SceneGraphBuilder::Scaled
void Scaled(GLdouble x, GLdouble y, GLdouble z)
osgUtil::SceneGraphBuilder::SceneGraphBuilder
SceneGraphBuilder()
osgUtil::SceneGraphBuilder::QuadricTexture
void QuadricTexture(GLboolean aTexture)
osgUtil::SceneGraphBuilder::_normals
osg::ref_ptr< osg::Vec3Array > _normals
Definition SceneGraphBuilder:155
osgUtil::SceneGraphBuilder::LoadIdentity
void LoadIdentity()
osgUtil::SceneGraphBuilder::PolygonStipple
void PolygonStipple(const GLubyte *mask)
osgUtil::SceneGraphBuilder::Matrices
std::vector< osg::Matrixd > Matrices
Definition SceneGraphBuilder:124
osgUtil::SceneGraphBuilder::TexCoord3f
void TexCoord3f(GLfloat x, GLfloat y, GLfloat z)
osgUtil::SceneGraphBuilder::LineStipple
void LineStipple(GLint factor, GLushort pattern)
osgUtil::SceneGraphBuilder::_matrixStack
Matrices _matrixStack
Definition SceneGraphBuilder:140
osgUtil::SceneGraphBuilder::Rotated
void Rotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z)
osgUtil::SceneGraphBuilder::Cylinder
void Cylinder(GLfloat base, GLfloat top, GLfloat height, GLint slices, GLint stacks)
osgUtil::SceneGraphBuilder::TexCoord2fv
void TexCoord2fv(GLfloat *tc)
Definition SceneGraphBuilder:74
osgUtil::SceneGraphBuilder::Sphere
void Sphere(GLfloat radius, GLint slices, GLint stacks)
osgUtil::SceneGraphBuilder::TexCoord1fv
void TexCoord1fv(GLfloat *tc)
Definition SceneGraphBuilder:71
osgUtil::SceneGraphBuilder::TexCoord4f
void TexCoord4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
osgUtil::SceneGraphBuilder::CullFace
void CullFace(GLenum mode)
osgUtil::SceneGraphBuilder::matrixChanged
void matrixChanged()
osgUtil::SceneGraphBuilder::_normal
osg::Vec3f _normal
Definition SceneGraphBuilder:145
osgUtil::SceneGraphBuilder::Color4f
void Color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
osgUtil::SceneGraphBuilder::TexCoord1f
void TexCoord1f(GLfloat x)
osgUtil::SceneGraphBuilder::FrontFace
void FrontFace(GLenum mode)
osgUtil::SceneGraphBuilder::PointSize
void PointSize(GLfloat pointSize)
osgUtil::SceneGraphBuilder::Disable
void Disable(GLenum mode)
osgUtil::SceneGraphBuilder::Normal3fv
void Normal3fv(GLfloat *n)
Definition SceneGraphBuilder:68
osgUtil::SceneGraphBuilder::TexCoord3fv
void TexCoord3fv(GLfloat *tc)
Definition SceneGraphBuilder:77
osgUtil::SceneGraphBuilder::_texCoord
osg::Vec4f _texCoord
Definition SceneGraphBuilder:151
osgUtil::SceneGraphBuilder::_texCoords
osg::ref_ptr< osg::Vec4Array > _texCoords
Definition SceneGraphBuilder:157
osgUtil::SceneGraphBuilder::addAttribute
void addAttribute(osg::StateAttribute *attribute)
osgUtil::SceneGraphBuilder::addDrawable
void addDrawable(osg::Drawable *drawable)
osgUtil::SceneGraphBuilder::ShadeModel
void ShadeModel(GLenum mode)
osgUtil::SceneGraphBuilder::_colorSet
bool _colorSet
Definition SceneGraphBuilder:147
osgUtil::SceneGraphBuilder::Translated
void Translated(GLdouble x, GLdouble y, GLdouble z)
osgUtil::SceneGraphBuilder::PartialDisk
void PartialDisk(GLfloat inner, GLfloat outer, GLint slices, GLint loops, GLfloat start, GLfloat sweep)
osgUtil::SceneGraphBuilder::addShape
void addShape(osg::Shape *shape)
osgUtil::SceneGraphBuilder::_statesetAssigned
bool _statesetAssigned
Definition SceneGraphBuilder:142
osgUtil::SceneGraphBuilder::addTextureAttribute
void addTextureAttribute(unsigned int unit, osg::StateAttribute *attribute)
osgUtil::SceneGraphBuilder::TexCoord4fv
void TexCoord4fv(GLfloat *tc)
Definition SceneGraphBuilder:80
osgUtil::SceneGraphBuilder::QuadricOrientation
void QuadricOrientation(GLenum aOrientation)
osgUtil::SceneGraphBuilder::addTextureMode
void addTextureMode(unsigned int unit, GLenum mode, bool enabled)
osgUtil::SceneGraphBuilder::addMode
void addMode(GLenum mode, bool enabled)
osgUtil::SceneGraphBuilder::PopMatrix
void PopMatrix()
osgUtil::SceneGraphBuilder::_geode
osg::ref_ptr< osg::Geode > _geode
Definition SceneGraphBuilder:177
osgUtil::SceneGraphBuilder::_stateset
osg::ref_ptr< osg::StateSet > _stateset
Definition SceneGraphBuilder:141
osgUtil::SceneGraphBuilder::_primitiveMode
GLenum _primitiveMode
Definition SceneGraphBuilder:153
osgUtil::SceneGraphBuilder::newGeometry
void newGeometry()
osgUtil::SceneGraphBuilder::LineWidth
void LineWidth(GLfloat lineWidth)
osgUtil::SceneGraphBuilder::BlendFunc
void BlendFunc(GLenum srcFactor, GLenum dstFactor)
osgUtil::SceneGraphBuilder::_group
osg::ref_ptr< osg::Group > _group
Definition SceneGraphBuilder:179
osgUtil::SceneGraphBuilder::PushMatrix
void PushMatrix()
osgUtil::SceneGraphBuilder::_transform
osg::ref_ptr< osg::MatrixTransform > _transform
Definition SceneGraphBuilder:178
osgUtil::SceneGraphBuilder::Color4fv
void Color4fv(GLfloat *c)
Definition SceneGraphBuilder:62
osgUtil::SceneGraphBuilder::PolygonMode
void PolygonMode(GLenum face, GLenum mode)
osgUtil::SceneGraphBuilder::takeScene
osg::Node * takeScene()
osgUtil::SceneGraphBuilder::allocateGeometry
void allocateGeometry()
osgUtil::SceneGraphBuilder::End
void End()
osgUtil::SceneGraphBuilder::completeGeometry
void completeGeometry()
osgUtil::SceneGraphBuilder::_quadricState
QuadricState _quadricState
Definition SceneGraphBuilder:173
osg::Drawable
Definition Drawable:89
osg::Node
Definition Node:72
osg::Shape
Definition Shape:49
osg::StateAttribute
Definition StateAttribute:77
osg::Vec3f
Definition Vec3f:29
osg::Vec4f
Definition Vec4f:28
osg::ref_ptr
Definition ref_ptr:32
osgUtil
Definition NodeVisitor:25
Export
OSGUTIL_EXPORT
#define OSGUTIL_EXPORT
Definition osgUtil/Export:40
osgUtil::SceneGraphBuilder::QuadricState
Definition SceneGraphBuilder:160
osgUtil::SceneGraphBuilder::QuadricState::_drawStyle
GLenum _drawStyle
Definition SceneGraphBuilder:167
osgUtil::SceneGraphBuilder::QuadricState::_normals
GLenum _normals
Definition SceneGraphBuilder:168
osgUtil::SceneGraphBuilder::QuadricState::_texture
GLboolean _texture
Definition SceneGraphBuilder:170
osgUtil::SceneGraphBuilder::QuadricState::_orientation
GLenum _orientation
Definition SceneGraphBuilder:169
osgUtil::SceneGraphBuilder::QuadricState::QuadricState
QuadricState()
Definition SceneGraphBuilder:161