Introduced optional build against the GLU library, using optional compile paths to enable/disable GLU related function.

To toggle the use of the GLU library adjust the OSG_GLU_AVAILABLE variable via ccmake . or CMakeSetup.
This commit is contained in:
Robert Osfield 2009-10-07 19:42:32 +00:00
parent 6992e8eedf
commit 2d26cbe7ab
15 changed files with 299 additions and 179 deletions

View File

@ -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

View File

@ -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)

View File

@ -14,6 +14,10 @@
#ifndef OSG_GLU
#define OSG_GLU 1
#include <osg/Config>
#ifdef OSG_GLU_AVAILABLE
#include <osg/GL>
#if defined(__APPLE__) || \
@ -29,4 +33,6 @@
typedef void (APIENTRY *GLU_TESS_CALLBACK)();
#endif
#endif
#endif // __osgGLU_h

View File

@ -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

View File

@ -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<NewVertex> NewVertexList;
typedef std::vector<Vec3d*> Vec3dList;
#ifdef OSG_GLU_AVAILABLE
GLUtesselator* _tobj;
#else
void* _tobj;
#endif
PrimList _primList;
Vec3dList _coordData;
NewVertexList _newVertexList;

View File

@ -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

View File

@ -235,7 +235,7 @@ std::string& osg::getGLExtensionDisableString()
return s_GLExtensionDisableString;
}
#ifdef OSG_GLU_AVAILABLE
bool osg::isGLUExtensionSupported(unsigned int contextID, const char *extension)
{
ExtensionSet& extensionSet = s_gluExtensionSetList[contextID];
@ -282,6 +282,14 @@ bool osg::isGLUExtensionSupported(unsigned int contextID, const char *extension)
return result;
}
#else
bool osg::isGLUExtensionSupported(unsigned int, const char *)
{
return false;
}
#endif
#if defined(WIN32)
#define WIN32_LEAN_AND_MEAN

View File

@ -875,7 +875,7 @@ void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMaps
}
}
#ifdef OSG_GLU_AVAILABLE
void Image::scaleImage(int s,int t,int r, GLenum newDataType)
{
if (_s==s && _t==t && _r==r) return;
@ -936,7 +936,14 @@ void Image::scaleImage(int s,int t,int r, GLenum newDataType)
dirty();
}
#else
void Image::scaleImage(int,int,int, GLenum)
{
osg::notify(osg::NOTICE)<<"Warning: Image::scaleImage(int s,int t,int r, GLenum newDataType) not supported."<<std::endl;
}
#endif
#ifdef OSG_GLU_AVAILABLE
void Image::copySubImage(int s_offset, int t_offset, int r_offset, const osg::Image* source)
{
if (!source) return;
@ -990,9 +997,13 @@ void Image::copySubImage(int s_offset, int t_offset, int r_offset, const osg::Im
{
notify(WARN) << "Error Image::scaleImage() do not succeed : errorString = "<<gluErrorString((GLenum)status)<<std::endl;
}
}
#else
void Image::copySubImage(int, int, int, const osg::Image*)
{
osg::notify(osg::NOTICE)<<"Warning: Image::copySubImage(int, int, int, const osg::Image*)) not supported."<<std::endl;
}
#endif
void Image::flipHorizontal()
{

View File

@ -982,10 +982,13 @@ bool State::checkGLErrors(const char* str) const
GLenum errorNo = glGetError();
if (errorNo!=GL_NO_ERROR)
{
#ifdef OSG_GLU_AVAILABLE
const char* error = (char*)gluErrorString(errorNo);
if (error) osg::notify(WARN)<<"Warning: detected OpenGL error '" << error<<"'";
else osg::notify(WARN)<<"Warning: detected OpenGL error number 0x" << std::hex << errorNo << std::dec;
#else
osg::notify(WARN)<<"Warning: detected OpenGL error number 0x" << std::hex << errorNo << std::dec;
#endif
if (str) osg::notify(WARN)<<" at "<<str<< std::endl;
else osg::notify(WARN)<<" in osg::State."<< std::endl;
@ -999,10 +1002,13 @@ bool State::checkGLErrors(StateAttribute::GLMode mode) const
GLenum errorNo = glGetError();
if (errorNo!=GL_NO_ERROR)
{
#ifdef OSG_GLU_AVAILABLE
const char* error = (char*)gluErrorString(errorNo);
if (error) osg::notify(WARN)<<"Warning: detected OpenGL error '"<< error <<"' after applying GLMode 0x"<<hex<<mode<<dec<< std::endl;
else osg::notify(WARN)<<"Warning: detected OpenGL error number 0x"<< std::hex << errorNo <<" after applying GLMode 0x"<<hex<<mode<<dec<< std::endl;
#else
osg::notify(WARN)<<"Warning: detected OpenGL error number 0x"<< std::hex << errorNo <<" after applying GLMode 0x"<<hex<<mode<<dec<< std::endl;
#endif
return true;
}
return false;
@ -1013,9 +1019,13 @@ bool State::checkGLErrors(const StateAttribute* attribute) const
GLenum errorNo = glGetError();
if (errorNo!=GL_NO_ERROR)
{
#ifdef OSG_GLU_AVAILABLE
const char* error = (char*)gluErrorString(errorNo);
if (error) osg::notify(WARN)<<"Warning: detected OpenGL error '"<< error <<"' after applying attribute "<<attribute->className()<<" "<<attribute<< std::endl;
else osg::notify(WARN)<<"Warning: detected OpenGL error number 0x"<< std::hex << errorNo <<" after applying attribute "<<attribute->className()<<" "<<attribute<< std::dec << std::endl;
#else
osg::notify(WARN)<<"Warning: detected OpenGL error number 0x"<< std::hex << errorNo <<" after applying attribute "<<attribute->className()<<" "<<attribute<< std::dec << std::endl;
#endif
return true;
}

View File

@ -1747,7 +1747,7 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima
bool needImageRescale = inwidth!=image->s() || inheight!=image->t();
if (needImageRescale)
{
#ifdef OSG_GLU_AVAILABLE
// resize the image to power of two.
if (image->isMipmap())
@ -1778,7 +1778,10 @@ 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."<<std::endl;
return;
#endif
}
bool mipmappingRequired = _min_filter != LINEAR && _min_filter != NEAREST;
@ -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."<<std::endl;
#endif
}
else
{
@ -1989,9 +1995,8 @@ void Texture::applyTexImage2D_subload(State& state, GLenum target, const Image*
bool needImageRescale = inwidth!=image->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."<<std::endl;
@ -2020,6 +2025,10 @@ void Texture::applyTexImage2D_subload(State& state, GLenum target, const Image*
gluScaleImage(image->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."<<std::endl;
return;
#endif
}

View File

@ -299,10 +299,14 @@ void Texture1D::applyTexImage1D(GLenum target, Image* image, State& state, GLsiz
numMipmapLevels = 1;
#ifdef OSG_GLU_AVAILABLE
gluBuild1DMipmaps( target, _internalFormat,
image->s(),
(GLenum)image->getPixelFormat(), (GLenum)image->getDataType(),
image->data() );
#else
osg::notify(osg::NOTICE)<<"Warning: gluBuild1DMipmaps(..) not supported."<<std::endl;
#endif
}
else

View File

@ -157,10 +157,13 @@ IF(COLLADA_FOUND)
ADD_SUBDIRECTORY(dae)
ENDIF()
IF(OSG_GLU_AVAILABLE)
ADD_SUBDIRECTORY(lwo)
ADD_SUBDIRECTORY(dw)
ENDIF()
ADD_SUBDIRECTORY(bvh)
ADD_SUBDIRECTORY(x)
ADD_SUBDIRECTORY(dw)
ADD_SUBDIRECTORY(ply)
ADD_SUBDIRECTORY(dxf)
ADD_SUBDIRECTORY(OpenFlight)

View File

@ -860,7 +860,13 @@ void Font::Glyph::subload() const
GLenum errorNo = glGetError();
if (errorNo!=GL_NO_ERROR)
{
osg::notify(osg::WARN)<<"before Font::Glyph::subload(): detected OpenGL error '"<<gluErrorString(errorNo)<<std::endl;
#ifdef OSG_GLU_AVAILABLE
const GLubyte* msg = gluErrorString(errorNo);
if (msg) osg::notify(osg::WARN)<<"before Font::Glyph::subload(): detected OpenGL error: "<<msg<<std::endl;
else osg::notify(osg::WARN)<<"before Font::Glyph::subload(): detected OpenGL error number: "<<errorNo<<std::endl;
#else
osg::notify(osg::WARN)<<"before Font::Glyph::subload(): detected OpenGL error number: "<<errorNo<<std::endl;
#endif
}
if(s() <= 0 || t() <= 0)
@ -882,7 +888,15 @@ void Font::Glyph::subload() const
if (errorNo!=GL_NO_ERROR)
{
osg::notify(osg::WARN)<<"after Font::Glyph::subload() : detected OpenGL error '"<<gluErrorString(errorNo)<<"'"<<std::endl;
#ifdef OSG_GLU_AVAILABLE
const GLubyte* msg = gluErrorString(errorNo);
if (msg) osg::notify(osg::WARN)<<"after Font::Glyph::subload() : detected OpenGL error: "<<msg<<std::endl;
else osg::notify(osg::WARN)<<"after Font::Glyph::subload() : detected OpenGL error number: "<<errorNo<<std::endl;
#else
osg::notify(osg::WARN)<<"after Font::Glyph::subload() : detected OpenGL error number: "<<errorNo<<std::endl;
#endif
osg::notify(osg::WARN)<< "\tglTexSubImage2D(0x"<<hex<<GL_TEXTURE_2D<<dec<<" ,"<<0<<"\t"<<std::endl<<
"\t "<<_texturePosX<<" ,"<<_texturePosY<<std::endl<<
"\t "<<s()<<" ,"<<t()<<std::endl<<hex<<

View File

@ -881,10 +881,13 @@ void RenderStage::drawInner(osg::RenderInfo& renderInfo,RenderLeaf*& previous, b
GLenum errorNo = glGetError();
if (errorNo!=GL_NO_ERROR)
{
#ifdef OSG_GLU_AVAILABLE
const char* error = (char*)gluErrorString(errorNo);
if (error) osg::notify(osg::NOTICE)<<"Warning: detected OpenGL error '"<<error<<"' after RenderBin::draw(,)"<<std::endl;
else osg::notify(osg::NOTICE)<<"Warning: detected OpenGL errorNo= 0x"<<std::hex<<errorNo<<" after RenderBin::draw(,)"<<std::dec<<std::endl;
#else
osg::notify(osg::NOTICE)<<"Warning: detected OpenGL errorNo= 0x"<<std::hex<<errorNo<<" after RenderBin::draw(,)"<<std::dec<<std::endl;
#endif
if ( fbo_ext )
{
GLenum fbstatus = fbo_ext->glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);

View File

@ -28,6 +28,10 @@ Tessellator::Tessellator() :
_tobj = 0;
_errorCode = 0;
_index=0;
#ifndef OSG_GLU_AVAILABLE
osg::notify(osg::NOTICE)<<"Warning: gluTesselation not supported."<<std::endl;
#endif
}
Tessellator::~Tessellator()
@ -39,6 +43,7 @@ void Tessellator::beginTessellation()
{
reset();
#ifdef OSG_GLU_AVAILABLE
if (!_tobj) _tobj = gluNewTess();
gluTessCallback(_tobj, GLU_TESS_VERTEX_DATA, (GLU_TESS_CALLBACK) vertexCallback);
@ -49,18 +54,24 @@ void Tessellator::beginTessellation()
if (tessNormal.length()>0.0) gluTessNormal(_tobj, tessNormal.x(), tessNormal.y(), tessNormal.z());
gluTessBeginPolygon(_tobj,this);
#else
osg::notify(osg::NOTICE)<<"Warning: gluTesselation not supported."<<std::endl;
#endif
}
void Tessellator::beginContour()
{
#ifdef OSG_GLU_AVAILABLE
if (_tobj)
{
gluTessBeginContour(_tobj);
}
#endif
}
void Tessellator::addVertex(osg::Vec3* vertex)
{
#ifdef OSG_GLU_AVAILABLE
if (_tobj)
{
Vec3d* data = new Vec3d;
@ -70,18 +81,22 @@ void Tessellator::addVertex(osg::Vec3* vertex)
(*data)._v[2]=(*vertex)[2];
gluTessVertex(_tobj,data->_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: "<<estring<< std::endl;
}
}
#endif
}
void Tessellator::reset()
{
#ifdef OSG_GLU_AVAILABLE
if (_tobj)
{
gluDeleteTess(_tobj);
_tobj = 0;
}
#endif
for (Vec3dList::iterator i = _coordData.begin(); i != _coordData.end(); ++i)
{
@ -166,6 +184,7 @@ class InsertNewVertices : public osg::ArrayVisitor
void Tessellator::retessellatePolygons(osg::Geometry &geom)
{
#ifdef OSG_GLU_AVAILABLE
// turn the contour list into primitives, a little like Tessellator does but more generally
osg::Vec3Array* vertices = dynamic_cast<osg::Vec3Array*>(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)