2008-03-11 21:29:12 +08:00
|
|
|
/* -*-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>
|
2008-03-13 04:15:28 +08:00
|
|
|
#include <osg/GLU>
|
2008-03-11 21:29:12 +08:00
|
|
|
|
|
|
|
#include <osgUtil/Export>
|
|
|
|
|
|
|
|
namespace osgUtil {
|
|
|
|
|
|
|
|
/** A simplifier for reducing the number of traingles in osg::Geometry.
|
|
|
|
*/
|
|
|
|
class OSGUTIL_EXPORT SceneGraphBuilder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
SceneGraphBuilder();
|
|
|
|
|
2008-03-13 04:15:28 +08:00
|
|
|
//
|
|
|
|
// OpenGL 1.0 style building methods
|
|
|
|
//
|
2008-03-11 21:29:12 +08:00
|
|
|
void glPushMatrix();
|
|
|
|
void glPopMatrix();
|
|
|
|
void glLoadIdentity();
|
|
|
|
void glLoadMatrixd(const GLdouble* m);
|
|
|
|
void glMultMatrixd(const GLdouble* m);
|
|
|
|
void glTranslated(GLdouble x, GLdouble y, GLdouble z);
|
|
|
|
void glScaled(GLdouble x, GLdouble y, GLdouble z);
|
|
|
|
void glRotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
|
|
|
|
|
|
|
|
void glBlendFunc(GLenum srcFactor, GLenum dstFactor);
|
|
|
|
void glCullFace(GLenum mode);
|
|
|
|
void glDepthFunc(GLenum mode);
|
|
|
|
void glFrontFace(GLenum mode);
|
|
|
|
void glLineStipple(GLint factor, GLushort pattern);
|
|
|
|
void glLineWidth(GLfloat lineWidth);
|
|
|
|
void glPointSize(GLfloat pointSize);
|
|
|
|
void glPolygonMode(GLenum face, GLenum mode);
|
|
|
|
void glPolygonOffset(GLfloat factor, GLfloat units);
|
2008-03-13 04:15:28 +08:00
|
|
|
void glPolygonStipple(const GLubyte* mask);
|
2008-03-11 21:29:12 +08:00
|
|
|
void glShadeModel(GLenum mode);
|
|
|
|
|
|
|
|
void glEnable(GLenum mode);
|
|
|
|
void glDisable(GLenum mode);
|
|
|
|
|
|
|
|
void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
|
2008-03-13 04:15:28 +08:00
|
|
|
void glColor4fv(GLfloat* c) { glColor4f(c[0], c[1], c[2], c[3]); }
|
|
|
|
|
2008-03-11 21:29:12 +08:00
|
|
|
void glVertex3f(GLfloat x, GLfloat y, GLfloat z);
|
2008-03-13 04:15:28 +08:00
|
|
|
void glVertex3fv(GLfloat* v) { glVertex3f(v[0], v[1], v[2]); }
|
|
|
|
|
2008-03-11 21:29:12 +08:00
|
|
|
void glNormal3f(GLfloat x, GLfloat y, GLfloat z);
|
2008-03-13 04:15:28 +08:00
|
|
|
void glNormal3fv(GLfloat* n) { glNormal3f(n[0], n[1], n[2]); }
|
2008-03-11 21:29:12 +08:00
|
|
|
|
|
|
|
void glTexCoord1f(GLfloat x);
|
2008-03-13 04:15:28 +08:00
|
|
|
void glTexCoord1fv(GLfloat* tc) { glTexCoord1f(tc[0]); }
|
|
|
|
|
2008-03-11 21:29:12 +08:00
|
|
|
void glTexCoord2f(GLfloat x, GLfloat y);
|
2008-03-13 04:15:28 +08:00
|
|
|
void glTexCoord2fv(GLfloat* tc) { glTexCoord2f(tc[0],tc[1]); }
|
|
|
|
|
2008-03-11 21:29:12 +08:00
|
|
|
void glTexCoord3f(GLfloat x, GLfloat y, GLfloat z);
|
2008-03-13 04:15:28 +08:00
|
|
|
void glTexCoord3fv(GLfloat* tc) { glTexCoord3f(tc[0], tc[1], tc[2]); }
|
|
|
|
|
2008-03-11 21:29:12 +08:00
|
|
|
void glTexCoord4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w);
|
2008-03-13 04:15:28 +08:00
|
|
|
void glTexCoord4fv(GLfloat* tc) { glTexCoord4f(tc[0], tc[1], tc[2], tc[3]); }
|
2008-03-11 21:29:12 +08:00
|
|
|
|
|
|
|
void glBegin(GLenum mode);
|
|
|
|
void glEnd();
|
|
|
|
|
2008-03-13 04:15:28 +08:00
|
|
|
//
|
|
|
|
// glu style building methods
|
|
|
|
//
|
|
|
|
void gluQuadricDrawStyle(GLenum aDrawStyle);
|
|
|
|
void gluQuadricNormals(GLenum aNormals);
|
|
|
|
void gluQuadricOrientation(GLenum aOrientation);
|
|
|
|
void gluQuadricTexture(GLboolean aTexture);
|
|
|
|
|
|
|
|
void gluCylinder(GLfloat aBase,
|
|
|
|
GLfloat aTop,
|
|
|
|
GLfloat aHeight,
|
|
|
|
GLint aSlices,
|
|
|
|
GLint aStacks);
|
|
|
|
|
|
|
|
void gluDisk(GLfloat aInner,
|
|
|
|
GLfloat aOuter,
|
|
|
|
GLint aSlices,
|
|
|
|
GLint aLoops);
|
|
|
|
|
|
|
|
void gluPartialDisk(GLfloat aInner,
|
|
|
|
GLfloat aOuter,
|
|
|
|
GLint aSlices,
|
|
|
|
GLint aLoops,
|
|
|
|
GLfloat aStart,
|
|
|
|
GLfloat aSweep);
|
|
|
|
|
|
|
|
void gluSphere(GLfloat aRadius,
|
|
|
|
GLint aSlices,
|
|
|
|
GLint aStacks);
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// methods for obtaining the built scene graph
|
|
|
|
//
|
2008-03-11 21:29:12 +08:00
|
|
|
osg::Node* getScene();
|
|
|
|
osg::Node* takeScene();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
typedef std::vector<osg::Matrixd> Matrices;
|
2008-03-13 04:15:28 +08:00
|
|
|
|
|
|
|
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);
|
2008-03-11 21:29:12 +08:00
|
|
|
void newGeometry();
|
|
|
|
|
2008-03-13 04:15:28 +08:00
|
|
|
void allocateGeometry();
|
|
|
|
void completeGeometry();
|
|
|
|
|
|
|
|
void allocateStateSet();
|
|
|
|
|
2008-03-11 21:29:12 +08:00
|
|
|
Matrices _matrixStack;
|
2008-03-13 04:15:28 +08:00
|
|
|
osg::ref_ptr<osg::StateSet> _stateset;
|
2008-03-13 21:44:34 +08:00
|
|
|
bool _statesetAssigned;
|
2008-03-11 21:29:12 +08:00
|
|
|
|
2008-03-13 04:15:28 +08:00
|
|
|
bool _normalSet;
|
2008-03-11 21:29:12 +08:00
|
|
|
osg::Vec3f _normal;
|
2008-03-13 04:15:28 +08:00
|
|
|
|
|
|
|
bool _colorSet;
|
2008-03-11 21:29:12 +08:00
|
|
|
osg::Vec4f _color;
|
2008-03-13 04:15:28 +08:00
|
|
|
|
|
|
|
unsigned int _maxNumTexCoordComponents;
|
2008-03-11 21:29:12 +08:00
|
|
|
osg::Vec4f _texCoord;
|
2008-03-13 04:15:28 +08:00
|
|
|
|
|
|
|
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;
|
2008-03-11 21:29:12 +08:00
|
|
|
|
2008-03-13 04:15:28 +08:00
|
|
|
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;
|
2008-03-11 21:29:12 +08:00
|
|
|
osg::ref_ptr<osg::Group> _group;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|