diff --git a/include/osg/GLBeginEndAdapter b/include/osg/GLBeginEndAdapter deleted file mode 100644 index 2cee4eeea..000000000 --- a/include/osg/GLBeginEndAdapter +++ /dev/null @@ -1,174 +0,0 @@ -/* -*-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 OSG_GLBeginEndAdapter -#define OSG_GLBeginEndAdapter 1 - -#include -#include -#include - -#ifndef GL_TEXTURE0 -#define GL_TEXTURE0 0x84C0 -#endif - -namespace osg { - -// forward declare -class State; - -/** A class adapting OpenGL 1.0 glBegin()/glEnd() style code to vertex array based code */ -class OSG_EXPORT GLBeginEndAdapter -{ - public: - - GLBeginEndAdapter(State* state=0); - - void setState(State* state) { _state = state; } - State* getState() { return _state; } - const State* getState() const { return _state; } - - enum MatrixMode - { - APPLY_LOCAL_MATRICES_TO_VERTICES, - APPLY_LOCAL_MATRICES_TO_MODELVIEW - }; - - void setMatrixMode(MatrixMode mode) { _mode = mode; } - MatrixMode setMatrixMode() const { return _mode; } - - void PushMatrix(); - void PopMatrix(); - - void LoadIdentity(); - void LoadMatrixd(const GLdouble* m); - void MultMatrixd(const GLdouble* m); - - void Translatef(GLfloat x, GLfloat y, GLfloat z) { Translated(x,y,z); } - void Scalef(GLfloat x, GLfloat y, GLfloat z) { Scaled(x,y,z); } - void Rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) { Rotated(angle,x,y,z); } - - 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 Vertex3f(GLfloat x, GLfloat y, GLfloat z); - void Vertex3fv(const GLfloat* v) { Vertex3f(v[0], v[1], v[2]); } - - void Vertex3dv(GLdouble x, GLdouble y, GLdouble z) { Vertex3f(x,y,z); } - void Vertex3dv(const GLdouble* v) { Vertex3f(v[0], v[1], v[2]); } - - void Color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) - { - _overallColorAssigned = true; - _colorAssigned = true; - _color.set(red,green,blue,alpha); - } - - void Color3fv(const GLfloat* c) { Color4f(c[0], c[1], c[2], 1); } - void Color4fv(const GLfloat* c) { Color4f(c[0], c[1], c[2], c[3]); } - void Color4ubv(const GLubyte* c) { const float div = 1.0f/255.0f; Color4f(float(c[0])*div, float(c[1])*div, float(c[2])*div, float(c[3])*div); } - - void Normal3f(GLfloat x, GLfloat y, GLfloat z) - { - _overallNormalAssigned = true; - _normalAssigned = true; - _normal.set(x,y,z); - } - - void Normal3fv(const GLfloat* n) { Normal3f(n[0], n[1], n[2]); } - - void TexCoord1f(GLfloat x) { MultiTexCoord4f(GL_TEXTURE0, x, 0.0f, 0.0f, 1.0f); } - void TexCoord1fv(const GLfloat* tc) { MultiTexCoord4f(GL_TEXTURE0, tc[0], 0.0f, 0.0f, 1.0f); } - - void TexCoord2f(GLfloat x, GLfloat y) { MultiTexCoord4f(GL_TEXTURE0, x, y, 0.0f, 1.0f); } - void TexCoord2fv(const GLfloat* tc) { MultiTexCoord4f(GL_TEXTURE0, tc[0], tc[1], 0.0f, 1.0f); } - - void TexCoord3f(GLfloat x, GLfloat y, GLfloat z) { MultiTexCoord4f(GL_TEXTURE0, x, y, z, 1.0f); } - void TexCoord3fv(const GLfloat* tc) { MultiTexCoord4f(GL_TEXTURE0, tc[0], tc[1], tc[2], 1.0f); } - - void TexCoord4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w) { MultiTexCoord4f(GL_TEXTURE0, x, y, z, w); } - void TexCoord4fv(const GLfloat* tc) { MultiTexCoord4f(GL_TEXTURE0, tc[0], tc[1], tc[2], tc[3]); } - - void MultiTexCoord1f(GLenum target, GLfloat x) { MultiTexCoord4f(target, x, 0.0f, 0.0f, 1.0f); } - void MultiTexCoord1fv(GLenum target, const GLfloat* tc) { MultiTexCoord4f(target, tc[0], 0.0f, 0.0f, 1.0f); } - - void MultiTexCoord2f(GLenum target, GLfloat x, GLfloat y) { MultiTexCoord4f(target, x, y, 0.0f, 1.0f); } - void MultiTexCoord2fv(GLenum target, const GLfloat* tc) { MultiTexCoord4f(target, tc[0],tc[1], 0.0f, 1.0f); } - - void MultiTexCoord3f(GLenum target, GLfloat x, GLfloat y, GLfloat z) {MultiTexCoord4f(target, x, y, z, 1.0f); } - void MultiTexCoord3fv(GLenum target, const GLfloat* tc) { MultiTexCoord4f(target, tc[0], tc[1], tc[2], 1.0f); } - - void MultiTexCoord4f(GLenum target, GLfloat x, GLfloat y, GLfloat z, GLfloat w); - void MultiTexCoord4fv(GLenum target, const GLfloat* tc) { MultiTexCoord4f(target, tc[0], tc[1], tc[2], tc[3]); } - - void VertexAttrib1f(GLuint unit, GLfloat x) { VertexAttrib4f(unit, x, 0.0f, 0.0f, 0.0f); } - void VertexAttrib1fv(GLuint unit, const GLfloat* tc) { VertexAttrib4f(unit, tc[0], 0.0f, 0.0f, 0.0f); } - - void VertexAttrib2f(GLuint unit, GLfloat x, GLfloat y) { VertexAttrib4f(unit, x, y, 0.0f, 0.0f); } - void VertexAttrib2fv(GLuint unit, const GLfloat* tc) { VertexAttrib4f(unit, tc[0],tc[1], 0.0f, 0.0f); } - - void VertexAttrib3f(GLuint unit, GLfloat x, GLfloat y, GLfloat z) {VertexAttrib4f(unit, x, y, z, 0.0f); } - void VertexAttrib3fv(GLuint unit, const GLfloat* tc) { VertexAttrib4f(unit, tc[0], tc[1], tc[2], 0.0f); } - - void VertexAttrib4f(GLuint unit, GLfloat x, GLfloat y, GLfloat z, GLfloat w); - void VertexAttrib4fv(GLuint unit, const GLfloat* tc) { VertexAttrib4f(unit, tc[0], tc[1], tc[2], tc[3]); } - - void Begin(GLenum mode); - void End(); - - void reset(); - - protected: - - State* _state; - - MatrixMode _mode; - - typedef std::list MatrixStack; - MatrixStack _matrixStack; - - bool _normalAssigned; - osg::Vec3f _normal; - - bool _colorAssigned; - osg::Vec4f _color; - - bool _overallNormalAssigned; - bool _overallColorAssigned; - osg::Vec3f _overallNormal; - osg::Vec4f _overallColor; - - typedef std::vector AssignedList; - typedef std::vector VertexList; - - AssignedList _texCoordAssignedList; - VertexList _texCoordList; - - AssignedList _vertexAttribAssignedList; - VertexList _vertexAttribList; - - - typedef std::vector< osg::ref_ptr > VertexArrayList; - - GLenum _primitiveMode; - osg::ref_ptr _vertices; - osg::ref_ptr _normals; - osg::ref_ptr _colors; - VertexArrayList _texCoordsList; - VertexArrayList _vertexAttribsList; -}; - -} - -#endif diff --git a/include/osg/State b/include/osg/State index a0faabd14..b84575cb9 100644 --- a/include/osg/State +++ b/include/osg/State @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -877,9 +876,6 @@ class OSG_EXPORT State : public Referenced /** Initialize extension used by osg::State.*/ void initializeExtensionProcs(); - /** Get the GL adapter object used to map OpenGL 1.0 glBegin/glEnd usage to vertex arrays.*/ - inline GLBeginEndAdapter& getGLBeginEndAdapter() { return _glBeginEndAdapter; } - /** Get the helper class for dispatching osg::Arrays as OpenGL attribute data.*/ inline ArrayDispatchers& getArrayDispatchers() { return _arrayDispatchers; } @@ -1345,7 +1341,6 @@ class OSG_EXPORT State : public Referenced unsigned int _dynamicObjectCount; osg::ref_ptr _completeDynamicObjectRenderingCallback; - GLBeginEndAdapter _glBeginEndAdapter; ArrayDispatchers _arrayDispatchers; osg::ref_ptr _graphicsCostEstimator; diff --git a/src/osg/CMakeLists.txt b/src/osg/CMakeLists.txt index 6246a232f..2f2817358 100644 --- a/src/osg/CMakeLists.txt +++ b/src/osg/CMakeLists.txt @@ -83,7 +83,6 @@ SET(TARGET_H ${HEADER_PATH}/GL2Extensions ${HEADER_PATH}/GLDefines ${HEADER_PATH}/GLExtensions - ${HEADER_PATH}/GLBeginEndAdapter ${HEADER_PATH}/GLObjects ${HEADER_PATH}/GLU ${HEADER_PATH}/GraphicsCostEstimator @@ -291,7 +290,6 @@ SET(TARGET_SRC Geode.cpp Geometry.cpp GLExtensions.cpp - GLBeginEndAdapter.cpp GLObjects.cpp GLStaticLibrary.h GLStaticLibrary.cpp diff --git a/src/osg/GLBeginEndAdapter.cpp b/src/osg/GLBeginEndAdapter.cpp deleted file mode 100644 index 5e9f6037a..000000000 --- a/src/osg/GLBeginEndAdapter.cpp +++ /dev/null @@ -1,310 +0,0 @@ -/* -*-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 - -using namespace osg; - -GLBeginEndAdapter::GLBeginEndAdapter(State* state): - _state(state), - _mode(APPLY_LOCAL_MATRICES_TO_VERTICES), - _normalAssigned(false), - _normal(0.0f,0.0f,1.0f), - _colorAssigned(false), - _color(1.0f,1.0f,1.0f,1.0f), - _overallNormalAssigned(false), - _overallColorAssigned(false), - _primitiveMode(0) -{ -} - -void GLBeginEndAdapter::PushMatrix() -{ - if (_matrixStack.empty()) - { - if (_mode==APPLY_LOCAL_MATRICES_TO_VERTICES) _matrixStack.push_back(Matrixd()); - else _matrixStack.push_back(_state->getModelViewMatrix()); - } - else _matrixStack.push_back(_matrixStack.back()); -} - -void GLBeginEndAdapter::PopMatrix() -{ - if (!_matrixStack.empty()) _matrixStack.pop_back(); -} - - -void GLBeginEndAdapter::LoadIdentity() -{ - if (_matrixStack.empty()) _matrixStack.push_back(Matrixd::identity()); - else _matrixStack.back().makeIdentity(); -} - -void GLBeginEndAdapter::LoadMatrixd(const GLdouble* m) -{ - if (_matrixStack.empty()) _matrixStack.push_back(Matrixd(m)); - else _matrixStack.back().set(m); -} - -void GLBeginEndAdapter::MultMatrixd(const GLdouble* m) -{ - if (_matrixStack.empty()) - { - if (_mode==APPLY_LOCAL_MATRICES_TO_VERTICES) _matrixStack.push_back(Matrixd()); - else _matrixStack.push_back(_state->getModelViewMatrix()); - } - _matrixStack.back().preMult(Matrixd(m)); -} - - -void GLBeginEndAdapter::Translated(GLdouble x, GLdouble y, GLdouble z) -{ - if (_matrixStack.empty()) - { - if (_mode==APPLY_LOCAL_MATRICES_TO_VERTICES) _matrixStack.push_back(Matrixd()); - else _matrixStack.push_back(_state->getModelViewMatrix()); - } - _matrixStack.back().preMultTranslate(Vec3d(x,y,z)); -} - -void GLBeginEndAdapter::Scaled(GLdouble x, GLdouble y, GLdouble z) -{ - if (_matrixStack.empty()) - { - if (_mode==APPLY_LOCAL_MATRICES_TO_VERTICES) _matrixStack.push_back(Matrixd()); - else _matrixStack.push_back(_state->getModelViewMatrix()); - } - _matrixStack.back().preMultScale(Vec3d(x,y,z)); -} - -void GLBeginEndAdapter::Rotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z) -{ - if (_matrixStack.empty()) - { - if (_mode==APPLY_LOCAL_MATRICES_TO_VERTICES) _matrixStack.push_back(Matrixd()); - else _matrixStack.push_back(_state->getModelViewMatrix()); - } - _matrixStack.back().preMultRotate(Quat(DegreesToRadians(angle), Vec3d(x,y,z))); -} - -void GLBeginEndAdapter::MultiTexCoord4f(GLenum target, GLfloat x, GLfloat y, GLfloat z, GLfloat w) -{ - unsigned int unit = static_cast(target-GL_TEXTURE0); - - if (unit>=_texCoordAssignedList.size()) _texCoordAssignedList.resize(unit+1, false); - if (unit>=_texCoordList.size()) _texCoordList.resize(unit+1, osg::Vec4(0.0f,0.0f,0.0f,0.0f)); - - _texCoordAssignedList[unit] = true; - _texCoordList[unit].set(x,y,z,w); -} - -void GLBeginEndAdapter::VertexAttrib4f(GLuint unit, GLfloat x, GLfloat y, GLfloat z, GLfloat w) -{ - if (unit>=_vertexAttribAssignedList.size()) _vertexAttribAssignedList.resize(unit+1, false); - if (unit>=_vertexAttribList.size()) _vertexAttribList.resize(unit+1, osg::Vec4(0.0f,0.0f,0.0f,0.0f)); - - _vertexAttribAssignedList[unit] = true; - _vertexAttribList[unit].set(x,y,z,w); -} - -void GLBeginEndAdapter::Vertex3f(GLfloat x, GLfloat y, GLfloat z) -{ - osg::Vec3 vertex(x,y,z); - - if (!_vertices) _vertices = new osg::Vec3Array; - - if (_normalAssigned) - { - if (!_normals) _normals = new osg::Vec3Array; - if (_normals->size()<_vertices->size()) _normals->resize(_vertices->size(), _overallNormal); - - _normals->push_back(_normal); - } - - if (_colorAssigned) - { - if (!_colors) _colors = new osg::Vec4Array; - if (_colors->size()<_vertices->size()) _colors->resize(_vertices->size(), _overallColor); - - _colors->push_back(_color); - } - - if (!_texCoordAssignedList.empty()) - { - for(unsigned int unit=0; unit<_texCoordAssignedList.size(); ++unit) - { - if (_texCoordAssignedList[unit]) - { - if (unit>=_texCoordsList.size()) _texCoordsList.resize(unit+1); - if (!_texCoordsList[unit]) _texCoordsList[unit] = new osg::Vec4Array; - if (_texCoordsList[unit]->size()<_vertices->size()) _texCoordsList[unit]->resize(_vertices->size(), osg::Vec4(0.0,0.0f,0.0f,0.0f)); - - _texCoordsList[unit]->push_back(_texCoordList[unit]); - } - } - } - - - if (!_vertexAttribAssignedList.empty()) - { - for(unsigned int unit=0; unit<_vertexAttribAssignedList.size(); ++unit) - { - if (_vertexAttribAssignedList[unit]) - { - if (unit>=_vertexAttribsList.size()) _vertexAttribsList.resize(unit+1); - if (!_vertexAttribsList[unit]) _vertexAttribsList[unit] = new osg::Vec4Array; - if (_vertexAttribsList[unit]->size()<_vertices->size()) _vertexAttribsList[unit]->resize(_vertices->size(), osg::Vec4(0.0,0.0f,0.0f,0.0f)); - - _vertexAttribsList[unit]->push_back(_vertexAttribList[unit]); - } - } - } - - _vertices->push_back(vertex); -} - -void GLBeginEndAdapter::Begin(GLenum mode) -{ - _overallNormal = _normal; - _overallColor = _color; - - // reset geometry - _primitiveMode = mode; - if (_vertices.valid()) { _vertices->clear(); _vertices->dirty(); } - - _normalAssigned = false; - if (_normals.valid()) { _normals->clear(); _normals->dirty(); } - - _colorAssigned = false; - if (_colors.valid()) { _colors->clear(); _colors->dirty(); } - - _texCoordAssignedList.clear(); - _texCoordList.clear(); - for(VertexArrayList::iterator itr = _texCoordsList.begin(); - itr != _texCoordsList.end(); - ++itr) - { - if (itr->valid()) { (*itr)->clear(); (*itr)->dirty(); } - } - - _vertexAttribAssignedList.clear(); - _vertexAttribList.clear(); -} - -void GLBeginEndAdapter::End() -{ - if (!_vertices || _vertices->empty()) return; - - if (!_matrixStack.empty()) - { - const osg::Matrixd& matrix = _matrixStack.back(); - if (_mode==APPLY_LOCAL_MATRICES_TO_VERTICES) - { - osg::Matrix inverse; - inverse.invert(matrix); - - for(Vec3Array::iterator itr = _vertices->begin(); - itr != _vertices->end(); - ++itr) - { - *itr = *itr * matrix; - } - - if (_normalAssigned && _normals.valid()) - { - for(Vec3Array::iterator itr = _normals->begin(); - itr != _normals->end(); - ++itr) - { - *itr = osg::Matrixd::transform3x3(inverse, *itr); - (*itr).normalize(); - } - } - else - { - _overallNormal = osg::Matrixd::transform3x3(inverse, _overallNormal); - _overallNormal.normalize(); - } - } - else - { - _state->applyModelViewMatrix(new RefMatrix(matrix)); - } - } - - _state->lazyDisablingOfVertexAttributes(); - _state->unbindVertexBufferObject(); - _state->unbindElementBufferObject(); - - if (_colorAssigned) - { - _state->setColorPointer(_colors.get()); - } - else if (_overallColorAssigned) - { - _state->Color(_overallColor.r(), _overallColor.g(), _overallColor.b(), _overallColor.a()); - } - - if (_normalAssigned) - { - _state->setNormalPointer(_normals.get()); - } - else if (_overallNormalAssigned) - { - _state->Normal(_overallNormal.x(), _overallNormal.y(), _overallNormal.z()); - } - - for(unsigned int unit=0; unit<_texCoordAssignedList.size(); ++unit) - { - if (_texCoordAssignedList[unit] && _texCoordsList[unit].valid()) - { - _state->setTexCoordPointer(unit, _texCoordsList[unit].get()); - } - } - - - for(unsigned int unit=0; unit<_vertexAttribAssignedList.size(); ++unit) - { - if (_vertexAttribAssignedList[unit] && _vertexAttribsList[unit].valid()) - { - _state->setVertexAttribPointer(unit, _vertexAttribsList[unit].get()); - } - } - - _state->setVertexPointer(_vertices.get()); - - _state->applyDisablingOfVertexAttributes(); - - - - if (_primitiveMode==GL_QUADS) - { - _state->drawQuads(0, _vertices->size()); - } - else if (_primitiveMode==GL_QUAD_STRIP) - { - // will the winding be wrong? Do we need to swap it? - glDrawArrays(GL_TRIANGLE_STRIP, 0, _vertices->size()); - } - else if (_primitiveMode==GL_POLYGON) glDrawArrays(GL_TRIANGLE_FAN, 0, _vertices->size()); - else glDrawArrays(_primitiveMode, 0, _vertices->size()); -} - -void GLBeginEndAdapter::reset() -{ - _overallNormalAssigned = false; - _overallColorAssigned = false; -} diff --git a/src/osg/State.cpp b/src/osg/State.cpp index 83ee84c0c..82758fc6c 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -125,7 +125,6 @@ State::State(): _maxTexturePoolSize = 0; _maxBufferObjectPoolSize = 0; - _glBeginEndAdapter.setState(this); _arrayDispatchers.setState(this); _graphicsCostEstimator = new GraphicsCostEstimator;