187 lines
6.3 KiB
C++
187 lines
6.3 KiB
C++
/* -*-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 {
|
|
|
|
/** A simplifier for reducing the number of traingles in osg::Geometry.
|
|
*/
|
|
class OSGUTIL_EXPORT SceneGraphBuilder
|
|
{
|
|
public:
|
|
|
|
SceneGraphBuilder();
|
|
|
|
//
|
|
// OpenGL 1.0 style building methods
|
|
//
|
|
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);
|
|
void glPolygonStipple(const GLubyte* mask);
|
|
void glShadeModel(GLenum mode);
|
|
|
|
void glEnable(GLenum mode);
|
|
void glDisable(GLenum mode);
|
|
|
|
void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
|
|
void glColor4fv(GLfloat* c) { glColor4f(c[0], c[1], c[2], c[3]); }
|
|
|
|
void glVertex3f(GLfloat x, GLfloat y, GLfloat z);
|
|
void glVertex3fv(GLfloat* v) { glVertex3f(v[0], v[1], v[2]); }
|
|
|
|
void glNormal3f(GLfloat x, GLfloat y, GLfloat z);
|
|
void glNormal3fv(GLfloat* n) { glNormal3f(n[0], n[1], n[2]); }
|
|
|
|
void glTexCoord1f(GLfloat x);
|
|
void glTexCoord1fv(GLfloat* tc) { glTexCoord1f(tc[0]); }
|
|
|
|
void glTexCoord2f(GLfloat x, GLfloat y);
|
|
void glTexCoord2fv(GLfloat* tc) { glTexCoord2f(tc[0],tc[1]); }
|
|
|
|
void glTexCoord3f(GLfloat x, GLfloat y, GLfloat z);
|
|
void glTexCoord3fv(GLfloat* tc) { glTexCoord3f(tc[0], tc[1], tc[2]); }
|
|
|
|
void glTexCoord4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w);
|
|
void glTexCoord4fv(GLfloat* tc) { glTexCoord4f(tc[0], tc[1], tc[2], tc[3]); }
|
|
|
|
void glBegin(GLenum mode);
|
|
void glEnd();
|
|
|
|
//
|
|
// 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
|
|
//
|
|
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
|