Added proper implementations of OpenGL 1.0 calls to OSG object representation methods in SceneGraphBuilder.

This commit is contained in:
Robert Osfield
2008-03-12 20:15:28 +00:00
parent eb9f7428bc
commit db256b962c
2 changed files with 397 additions and 24 deletions

View File

@@ -14,10 +14,10 @@
#ifndef OSGUTIL_SCENEGRAPHBUILDER
#define OSGUTIL_SCENEGRAPHBUILDER 1
#include <osg/NodeVisitor>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/MatrixTransform>
#include <osg/GLU>
#include <osgUtil/Export>
@@ -31,6 +31,9 @@ class OSGUTIL_EXPORT SceneGraphBuilder
SceneGraphBuilder();
//
// OpenGL 1.0 style building methods
//
void glPushMatrix();
void glPopMatrix();
void glLoadIdentity();
@@ -49,43 +52,129 @@ class OSGUTIL_EXPORT SceneGraphBuilder
void glPointSize(GLfloat pointSize);
void glPolygonMode(GLenum face, GLenum mode);
void glPolygonOffset(GLfloat factor, GLfloat units);
void glPolygonStipple(GLubyte* mask);
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();
Matrices _matrixStack;
osg::ref_ptr<osg::StateSet> _stateSet;
void allocateGeometry();
void completeGeometry();
void allocateStateSet();
Matrices _matrixStack;
osg::ref_ptr<osg::StateSet> _stateset;
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;
osg::ref_ptr<osg::Geometry> _currentGeometry;
osg::ref_ptr<osg::Geode> _currentGeode;
osg::ref_ptr<osg::MatrixTransform> _currentTransform;
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;
};