diff --git a/include/osgUtil/SceneGraphBuilder b/include/osgUtil/SceneGraphBuilder new file mode 100644 index 000000000..36872fd99 --- /dev/null +++ b/include/osgUtil/SceneGraphBuilder @@ -0,0 +1,96 @@ +/* -*-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 +#include +#include +#include + +#include + +namespace osgUtil { + +/** A simplifier for reducing the number of traingles in osg::Geometry. + */ +class OSGUTIL_EXPORT SceneGraphBuilder +{ + public: + + SceneGraphBuilder(); + + 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(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 glVertex3f(GLfloat x, GLfloat y, GLfloat z); + void glNormal3f(GLfloat x, GLfloat y, GLfloat z); + + void glTexCoord1f(GLfloat x); + void glTexCoord2f(GLfloat x, GLfloat y); + void glTexCoord3f(GLfloat x, GLfloat y, GLfloat z); + void glTexCoord4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w); + + void glBegin(GLenum mode); + void glEnd(); + + osg::Node* getScene(); + osg::Node* takeScene(); + + protected: + + typedef std::vector Matrices; + + void newGeometry(); + + Matrices _matrixStack; + osg::ref_ptr _stateSet; + + osg::Vec3f _normal; + osg::Vec4f _color; + osg::Vec4f _texCoord; + + osg::ref_ptr _currentGeometry; + osg::ref_ptr _currentGeode; + osg::ref_ptr _currentTransform; + osg::ref_ptr _group; + +}; + + +} + +#endif diff --git a/src/osgUtil/CMakeLists.txt b/src/osgUtil/CMakeLists.txt index c84daea9c..c79cbe5d2 100644 --- a/src/osgUtil/CMakeLists.txt +++ b/src/osgUtil/CMakeLists.txt @@ -34,6 +34,7 @@ SET(LIB_PUBLIC_HEADERS ${HEADER_PATH}/RenderStage ${HEADER_PATH}/ReversePrimitiveFunctor ${HEADER_PATH}/SceneView + ${HEADER_PATH}/SceneGraphBuilder ${HEADER_PATH}/Simplifier ${HEADER_PATH}/SmoothingVisitor ${HEADER_PATH}/StateGraph @@ -73,6 +74,7 @@ ADD_LIBRARY(${LIB_NAME} SceneView.cpp Simplifier.cpp SmoothingVisitor.cpp + SceneGraphBuilder.cpp StateGraph.cpp Statistics.cpp TangentSpaceGenerator.cpp diff --git a/src/osgUtil/SceneGraphBuilder.cpp b/src/osgUtil/SceneGraphBuilder.cpp new file mode 100644 index 000000000..6f24da828 --- /dev/null +++ b/src/osgUtil/SceneGraphBuilder.cpp @@ -0,0 +1,165 @@ +/* -*-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. +*/ +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace osgUtil; + +SceneGraphBuilder::SceneGraphBuilder(): + _normal(0.0f,0.0f,1.0f), + _color(1.0f,1.0f,1.0f,1.0f), + _texCoord(0.f,0.0f,0.0f,0.0f) +{ +} + +void SceneGraphBuilder::glPushMatrix() +{ + if (_matrixStack.empty()) _matrixStack.push_back(osg::Matrixd()); + else _matrixStack.push_back(_matrixStack.back()); +} + +void SceneGraphBuilder::glPopMatrix() +{ + if (!_matrixStack.empty()) _matrixStack.pop_back(); +} + +void SceneGraphBuilder::glLoadIdentity() +{ + if (_matrixStack.empty()) _matrixStack.push_back(osg::Matrixd()); + + _matrixStack.back().makeIdentity(); +} + +void SceneGraphBuilder::glLoadMatrixd(const GLdouble* m) +{ + +} + +void SceneGraphBuilder::glMultMatrixd(const GLdouble* m) +{ +} + +void SceneGraphBuilder::glTranslated(GLdouble x, GLdouble y, GLdouble z) +{ +} + +void SceneGraphBuilder::glScaled(GLdouble x, GLdouble y, GLdouble z) +{ +} + +void SceneGraphBuilder::glRotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z) +{ +} +void SceneGraphBuilder::glBlendFunc(GLenum srcFactor, GLenum dstFactor) +{ +} + +void SceneGraphBuilder::glCullFace(GLenum mode) +{ +} + +void SceneGraphBuilder::glDepthFunc(GLenum mode) +{ +} + +void SceneGraphBuilder::glFrontFace(GLenum mode) +{ +} + +void SceneGraphBuilder::glLineStipple(GLint factor, GLushort pattern) +{ +} + +void SceneGraphBuilder::glLineWidth(GLfloat lineWidth) +{ +} + +void SceneGraphBuilder::glPointSize(GLfloat pointSize) +{ +} + +void SceneGraphBuilder::glPolygonMode(GLenum face, GLenum mode) +{ +} + +void SceneGraphBuilder::glPolygonOffset(GLfloat factor, GLfloat units) +{ +} + +void SceneGraphBuilder::glPolygonStipple(GLubyte* mask) +{ +} + +void SceneGraphBuilder::glShadeModel(GLenum mode) +{ +} +void SceneGraphBuilder::glEnable(GLenum mode) +{ +} + +void SceneGraphBuilder::glDisable(GLenum mode) +{ +} +void SceneGraphBuilder::glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) +{ +} + +void SceneGraphBuilder::glVertex3f(GLfloat x, GLfloat y, GLfloat z) +{ +} + +void SceneGraphBuilder::glNormal3f(GLfloat x, GLfloat y, GLfloat z) +{ +} +void SceneGraphBuilder::glTexCoord1f(GLfloat x) +{ +} + +void SceneGraphBuilder::glTexCoord2f(GLfloat x, GLfloat y) +{ +} + +void SceneGraphBuilder::glTexCoord3f(GLfloat x, GLfloat y, GLfloat z) +{ +} + +void SceneGraphBuilder::glTexCoord4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w) +{ +} +void SceneGraphBuilder::glBegin(GLenum mode) +{ +} + +void SceneGraphBuilder::glEnd() +{ +} + +osg::Node* SceneGraphBuilder::getScene() +{ +} + +osg::Node* SceneGraphBuilder::takeScene() +{ +}