diff --git a/CMakeLists.txt b/CMakeLists.txt index 7411f1723..31bbf2b3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -280,6 +280,9 @@ MARK_AS_ADVANCED(OSG_DISABLE_MSVC_WARNINGS) OPTION(OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION "Set to ON to use the ref_ptr<> T* operator() output conversion. " ON) +OPTION(OSG_GLU_AVAILABLE "Set to OFF to disable use of OpenGL GLU library." ${OPENGL_GLU_FOUND}) +MARK_AS_ADVANCED(OSG_GLU_AVAILABLE) + ################################################################################ # Set Config file diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 3fb72d829..3abccdcee 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -71,7 +71,6 @@ IF(DYNAMIC_OPENSCENEGRAPH) ADD_SUBDIRECTORY(osgparametric) ADD_SUBDIRECTORY(osgparticle) ADD_SUBDIRECTORY(osgparticleeffects) - ADD_SUBDIRECTORY(osgphotoalbum) ADD_SUBDIRECTORY(osgpick) ADD_SUBDIRECTORY(osgplanets) ADD_SUBDIRECTORY(osgpoints) @@ -103,7 +102,6 @@ IF(DYNAMIC_OPENSCENEGRAPH) ADD_SUBDIRECTORY(osgstereomatch) ADD_SUBDIRECTORY(osgteapot) ADD_SUBDIRECTORY(osgterrain) - ADD_SUBDIRECTORY(osgtessellate) ADD_SUBDIRECTORY(osgtext) ADD_SUBDIRECTORY(osgtext3D) ADD_SUBDIRECTORY(osgtexture1D) @@ -140,6 +138,11 @@ IF(DYNAMIC_OPENSCENEGRAPH) ADD_SUBDIRECTORY(osgwidgettable) ADD_SUBDIRECTORY(osgwidgetwindow) +IF(OSG_GLU_AVAILABLE) + ADD_SUBDIRECTORY(osgphotoalbum) + ADD_SUBDIRECTORY(osgtessellate) +ENDIF() + ADD_SUBDIRECTORY(osgpdf) IF (BUILD_OSG_WRAPPERS) diff --git a/include/osg/GLU b/include/osg/GLU index d562704a5..4f542ac27 100644 --- a/include/osg/GLU +++ b/include/osg/GLU @@ -14,19 +14,25 @@ #ifndef OSG_GLU #define OSG_GLU 1 -#include +#include -#if defined(__APPLE__) || \ - (defined (_AIX) && !defined (_AIX51)) - #include -#else - #include -#endif +#ifdef OSG_GLU_AVAILABLE + + #include + + #if defined(__APPLE__) || \ + (defined (_AIX) && !defined (_AIX51)) + #include + #else + #include + #endif + + #if defined(GLU_TESS_CALLBACK_TRIPLEDOT) + typedef void (APIENTRY *GLU_TESS_CALLBACK)(...); + #else + typedef void (APIENTRY *GLU_TESS_CALLBACK)(); + #endif -#if defined(GLU_TESS_CALLBACK_TRIPLEDOT) - typedef void (APIENTRY *GLU_TESS_CALLBACK)(...); -#else - typedef void (APIENTRY *GLU_TESS_CALLBACK)(); #endif #endif // __osgGLU_h diff --git a/include/osgUtil/SceneGraphBuilder b/include/osgUtil/SceneGraphBuilder index 24a15915b..e95580a22 100644 --- a/include/osgUtil/SceneGraphBuilder +++ b/include/osgUtil/SceneGraphBuilder @@ -23,6 +23,19 @@ namespace osgUtil { +#ifndef OSG_GLU_AVAILABLE + // as we have no GLU we'll just define the required enum values + #define GLU_FALSE 0 + #define GLU_FILL 100012 + #define GLU_SMOOTH 100000 + #define GLU_OUTSIDE 100020 + #define GLU_NONE 100002 + #define GLU_POINT 100010 + #define GLU_LINE 100011 + #define GLU_FILL 100012 + #define GLU_SILHOUETTE 100013 +#endif + /** A class for assisting the building ascene graphs that is equivilant to OpenGL 1.0 style calls. */ class OSGUTIL_EXPORT SceneGraphBuilder diff --git a/include/osgUtil/Tessellator b/include/osgUtil/Tessellator index ee7dd8552..57a328492 100644 --- a/include/osgUtil/Tessellator +++ b/include/osgUtil/Tessellator @@ -42,6 +42,7 @@ class OSGUTIL_EXPORT Tessellator : public osg::Referenced ~Tessellator(); /** The winding rule, see red book ch 11. */ +#ifdef OSG_GLU_AVAILABLE enum WindingType{ TESS_WINDING_ODD = GLU_TESS_WINDING_ODD, TESS_WINDING_NONZERO = GLU_TESS_WINDING_NONZERO , @@ -49,7 +50,15 @@ class OSGUTIL_EXPORT Tessellator : public osg::Referenced TESS_WINDING_NEGATIVE = GLU_TESS_WINDING_NEGATIVE , TESS_WINDING_ABS_GEQ_TWO = GLU_TESS_WINDING_ABS_GEQ_TWO } ; - +#else + enum WindingType{ + TESS_WINDING_ODD, + TESS_WINDING_NONZERO, + TESS_WINDING_POSITIVE, + TESS_WINDING_NEGATIVE, + TESS_WINDING_ABS_GEQ_TWO + } ; +#endif /** we interpret all contours in the geometry as a single set to be tessellated or * each separate drawable's contours needs to be tessellated. */ enum TessellationType { @@ -211,7 +220,11 @@ class OSGUTIL_EXPORT Tessellator : public osg::Referenced typedef std::vector NewVertexList; typedef std::vector Vec3dList; +#ifdef OSG_GLU_AVAILABLE GLUtesselator* _tobj; +#else + void* _tobj; +#endif PrimList _primList; Vec3dList _coordData; NewVertexList _newVertexList; diff --git a/src/osg/Config.in b/src/osg/Config.in index 88aa642fa..905e641bb 100644 --- a/src/osg/Config.in +++ b/src/osg/Config.in @@ -30,6 +30,6 @@ #cmakedefine OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION #cmakedefine OSG_USE_UTF8_FILENAME #cmakedefine OSG_DISABLE_MSVC_WARNINGS - +#cmakedefine OSG_GLU_AVAILABLE #endif diff --git a/src/osg/GLExtensions.cpp b/src/osg/GLExtensions.cpp index 3a8fd4994..a77b99540 100644 --- a/src/osg/GLExtensions.cpp +++ b/src/osg/GLExtensions.cpp @@ -235,53 +235,61 @@ std::string& osg::getGLExtensionDisableString() return s_GLExtensionDisableString; } - -bool osg::isGLUExtensionSupported(unsigned int contextID, const char *extension) -{ - ExtensionSet& extensionSet = s_gluExtensionSetList[contextID]; - std::string& rendererString = s_gluRendererList[contextID]; - - // if not already set up, initialize all the per graphic context values. - if (!s_gluInitializedList[contextID]) +#ifdef OSG_GLU_AVAILABLE + bool osg::isGLUExtensionSupported(unsigned int contextID, const char *extension) { - s_gluInitializedList[contextID] = 1; - - // set up the renderer - const GLubyte* renderer = glGetString(GL_RENDERER); - rendererString = renderer ? (const char*)renderer : ""; + ExtensionSet& extensionSet = s_gluExtensionSetList[contextID]; + std::string& rendererString = s_gluRendererList[contextID]; - // get the extension list from OpenGL. - const char* extensions = (const char*)gluGetString(GLU_EXTENSIONS); - if (extensions==NULL) return false; + // if not already set up, initialize all the per graphic context values. + if (!s_gluInitializedList[contextID]) + { + s_gluInitializedList[contextID] = 1; + + // set up the renderer + const GLubyte* renderer = glGetString(GL_RENDERER); + rendererString = renderer ? (const char*)renderer : ""; + + // get the extension list from OpenGL. + const char* extensions = (const char*)gluGetString(GLU_EXTENSIONS); + if (extensions==NULL) return false; + + // insert the ' ' delimiated extensions words into the extensionSet. + const char *startOfWord = extensions; + const char *endOfWord; + while ((endOfWord = strchr(startOfWord,' '))!=NULL) + { + extensionSet.insert(std::string(startOfWord,endOfWord)); + startOfWord = endOfWord+1; + } + if (*startOfWord!=0) extensionSet.insert(std::string(startOfWord)); + + osg::notify(INFO)<<"OpenGL extensions supported by installed OpenGL drivers are:"<s(),t_offset+source->t(),r_offset+source->r(), + source->getPixelFormat(),source->getDataType(), + source->getPacking()); + } + + if (s_offset>=_s || t_offset>=_t || r_offset>=_r) + { + notify(WARN)<<"Warning: offsets passed to Image::copySubImage(..) outside destination image, operation ignored."<getPixelFormat()) + { + notify(WARN)<<"Warning: image with an incompatible pixel formats passed to Image::copySubImage(..), operation ignored."<getPacking()); + glPixelStorei(GL_PACK_ROW_LENGTH,_s); + + glPixelStorei(GL_UNPACK_ALIGNMENT,_packing); + + GLint status = gluScaleImage(_pixelFormat, + source->s(), + source->t(), + source->getDataType(), + source->data(), + source->s(), + source->t(), + _dataType, + data_destination); + + glPixelStorei(GL_PACK_ROW_LENGTH,0); + + if (status!=0) + { + notify(WARN) << "Error Image::scaleImage() do not succeed : errorString = "<s(),t_offset+source->t(),r_offset+source->r(), - source->getPixelFormat(),source->getDataType(), - source->getPacking()); - } - - if (s_offset>=_s || t_offset>=_t || r_offset>=_r) - { - notify(WARN)<<"Warning: offsets passed to Image::copySubImage(..) outside destination image, operation ignored."<getPixelFormat()) - { - notify(WARN)<<"Warning: image with an incompatible pixel formats passed to Image::copySubImage(..), operation ignored."<getPacking()); - glPixelStorei(GL_PACK_ROW_LENGTH,_s); - - glPixelStorei(GL_UNPACK_ALIGNMENT,_packing); - - GLint status = gluScaleImage(_pixelFormat, - source->s(), - source->t(), - source->getDataType(), - source->data(), - source->s(), - source->t(), - _dataType, - data_destination); - - glPixelStorei(GL_PACK_ROW_LENGTH,0); - - if (status!=0) - { - notify(WARN) << "Error Image::scaleImage() do not succeed : errorString = "<className()<<" "<className()<<" "<className()<<" "<s() || inheight!=image->t(); if (needImageRescale) { - +#ifdef OSG_GLU_AVAILABLE // resize the image to power of two. if (image->isMipmap()) @@ -1778,8 +1778,11 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima gluScaleImage(image->getPixelFormat(), image->s(),image->t(),image->getDataType(),image->data(), inwidth,inheight,image->getDataType(),dataPtr); - - } +#else + osg::notify(osg::NOTICE)<<"Warning: gluScaleImage(..) not supported, cannot subload image."<isMipmap() && isHardwareMipmapGenerationEnabled(state)); @@ -1891,7 +1894,7 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima if ( !compressed_image) { numMipmapLevels = 0; - +#ifdef OSG_GLU_AVAILABLE gluBuild2DMipmaps( target, _internalFormat, inwidth,inheight, (GLenum)image->getPixelFormat(), (GLenum)image->getDataType(), @@ -1904,6 +1907,9 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima width >>= 1; height >>= 1; } +#else + osg::notify(osg::NOTICE)<<"Warning:: gluBuild2DMipMaps(..) not supported."<s() || inheight!=image->t(); if (needImageRescale) { - +#ifdef OSG_GLU_AVAILABLE // resize the image to power of two. - if (image->isMipmap()) { notify(WARN)<<"Warning:: Mipmapped osg::Image not a power of two, cannot apply to texture."<getPixelFormat(),image->getDataType(),image->getPacking())*inheight; data = new unsigned char [newTotalSize]; - + if (!data) { notify(WARN)<<"Warning:: Not enough memory to resize image, cannot apply to texture."<getPixelFormat(), image->s(),image->t(),image->getDataType(),image->data(), inwidth,inheight,image->getDataType(),data); +#else + osg::notify(osg::NOTICE)<<"Warning: gluScaleImage(..) not supported, cannot subload image."<s(), (GLenum)image->getPixelFormat(), (GLenum)image->getDataType(), image->data() ); +#else + osg::notify(osg::NOTICE)<<"Warning: gluBuild1DMipmaps(..) not supported."<glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); diff --git a/src/osgUtil/Tessellator.cpp b/src/osgUtil/Tessellator.cpp index 38e76e561..ccacd0e39 100644 --- a/src/osgUtil/Tessellator.cpp +++ b/src/osgUtil/Tessellator.cpp @@ -28,6 +28,10 @@ Tessellator::Tessellator() : _tobj = 0; _errorCode = 0; _index=0; + +#ifndef OSG_GLU_AVAILABLE + osg::notify(osg::NOTICE)<<"Warning: gluTesselation not supported."<0.0) gluTessNormal(_tobj, tessNormal.x(), tessNormal.y(), tessNormal.z()); gluTessBeginPolygon(_tobj,this); +#else + osg::notify(osg::NOTICE)<<"Warning: gluTesselation not supported."<_v,vertex); } +#endif } void Tessellator::endContour() { +#ifdef OSG_GLU_AVAILABLE if (_tobj) { gluTessEndContour(_tobj); } +#endif } void Tessellator::endTessellation() { +#ifdef OSG_GLU_AVAILABLE if (_tobj) { gluTessEndPolygon(_tobj); @@ -94,15 +109,18 @@ void Tessellator::endTessellation() osg::notify(osg::WARN)<<"Tessellation Error: "<(geom.getVertexArray()); @@ -284,6 +303,7 @@ void Tessellator::retessellatePolygons(osg::Geometry &geom) collectTessellation(geom, 0); } +#endif } void Tessellator::addContour(GLenum mode, unsigned int first, unsigned int last, osg::Vec3Array* vertices)