diff --git a/CMakeLists.txt b/CMakeLists.txt index 2506a7ad8..6d81cd5e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -287,6 +287,8 @@ OPTION(OSG_GL3_AVAILABLE "Set to OFF to disable use of OpenGL 3.x functions libr OPTION(OSG_GLES1_AVAILABLE "Set to OFF to disable use of OpenGL ES 1.x functions library." OFF) OPTION(OSG_GLES2_AVAILABLE "Set to OFF to disable use of OpenGL ES 2.x functions library." OFF) +SET(OPENGL_egl_LIBRARY CACHE STRING "Set the OpenGL egl library.") + # SET(OSG_GL_DISPLAYLISTS_AVAILABLE ${OSG_GL1_AVAILABLE}) # SET(OSG_GL_MATRICES_AVAILABLE ${OSG_GL1_AVAILABLE}) # SET(OSG_GL_VERTEX_FUNCS_AVAILABLE ${OSG_GL1_AVAILABLE}) diff --git a/CMakeModules/OsgMacroUtils.cmake b/CMakeModules/OsgMacroUtils.cmake index b34bedfd0..77e379567 100644 --- a/CMakeModules/OsgMacroUtils.cmake +++ b/CMakeModules/OsgMacroUtils.cmake @@ -51,7 +51,12 @@ ENDMACRO(LINK_EXTERNAL TRGTNAME) ####################################################################################################### MACRO(LINK_CORELIB_DEFAULT CORELIB_NAME) - LINK_EXTERNAL(${CORELIB_NAME} ${OPENGL_LIBRARIES}) + SET(ALL_GL_LIBRARIES ${OPENGL_LIBRARIES}) + IF (OSG_GLES1_AVAILABLE OR OSG_GLES2_AVAILABLE) + SET(ALL_GL_LIBRARIES ${ALL_GL_LIBRARIES} ${OPENGL_egl_LIBRARY}) + ENDIF() + + LINK_EXTERNAL(${CORELIB_NAME} ${ALL_GL_LIBRARIES}) LINK_WITH_VARIABLES(${CORELIB_NAME} OPENTHREADS_LIBRARY) IF(OPENSCENEGRAPH_SONAMES) SET_TARGET_PROPERTIES(${CORELIB_NAME} PROPERTIES VERSION ${OPENSCENEGRAPH_VERSION} SOVERSION ${OPENSCENEGRAPH_SOVERSION}) @@ -95,6 +100,11 @@ MACRO(SETUP_LINK_LIBRARIES) ENDIF(TO_INSERT) ENDFOREACH(LINKLIB) + SET(ALL_GL_LIBRARIES ${OPENGL_LIBRARIES}) + IF (OSG_GLES1_AVAILABLE OR OSG_GLES2_AVAILABLE) + SET(ALL_GL_LIBRARIES ${ALL_GL_LIBRARIES} ${OPENGL_egl_LIBRARY}) + ENDIF() + # FOREACH(LINKLIB ${TARGET_LIBRARIES}) # TARGET_LINK_LIBRARIES(${TARGET_TARGETNAME} optimized ${LINKLIB} debug "${LINKLIB}${CMAKE_DEBUG_POSTFIX}") # ENDFOREACH(LINKLIB) @@ -107,7 +117,7 @@ MACRO(SETUP_LINK_LIBRARIES) ENDIF(TARGET_LIBRARIES_VARS) IF(MSVC AND OSG_MSVC_VERSIONED_DLL) #when using full path name to specify linkage, it seems that already linked libs must be specified - LINK_EXTERNAL(${TARGET_TARGETNAME} ${OPENGL_LIBRARIES}) + LINK_EXTERNAL(${TARGET_TARGETNAME} ${ALL_GL_LIBRARIES}) ENDIF(MSVC AND OSG_MSVC_VERSIONED_DLL) ENDMACRO(SETUP_LINK_LIBRARIES) diff --git a/include/osg/ClipPlane b/include/osg/ClipPlane index 4ebdf73be..207d13f17 100644 --- a/include/osg/ClipPlane +++ b/include/osg/ClipPlane @@ -20,6 +20,11 @@ #ifndef GL_CLIP_PLANE0 #define GL_CLIP_PLANE0 0x3000 + #define GL_CLIP_PLANE1 0x3001 + #define GL_CLIP_PLANE2 0x3002 + #define GL_CLIP_PLANE3 0x3003 + #define GL_CLIP_PLANE4 0x3004 + #define GL_CLIP_PLANE5 0x3005 #endif namespace osg { diff --git a/include/osg/GL2Extensions b/include/osg/GL2Extensions index 63ff7433d..d13f8c283 100644 --- a/include/osg/GL2Extensions +++ b/include/osg/GL2Extensions @@ -36,6 +36,11 @@ typedef char GLchar; #endif +#if !defined(GL_VERSION_2_0) + #define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642 + #define GL_VERTEX_PROGRAM_TWO_SIDE 0x8643 +#endif + #if !defined(GL_VERSION_2_0) && !defined(GL_ES_VERSION_2_0) #define GL_VERSION_2_0 1 #define GL_BLEND_EQUATION_RGB GL_BLEND_EQUATION @@ -44,8 +49,6 @@ typedef char GLchar; #define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 #define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 #define GL_CURRENT_VERTEX_ATTRIB 0x8626 -#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642 -#define GL_VERTEX_PROGRAM_TWO_SIDE 0x8643 #define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 #define GL_STENCIL_BACK_FUNC 0x8800 #define GL_STENCIL_BACK_FAIL 0x8801 diff --git a/include/osg/Light b/include/osg/Light index ac6984eae..7cf15c9d2 100644 --- a/include/osg/Light +++ b/include/osg/Light @@ -20,6 +20,13 @@ #ifndef GL_LIGHT0 #define GL_LIGHT0 0x4000 + #define GL_LIGHT1 0x4001 + #define GL_LIGHT2 0x4002 + #define GL_LIGHT3 0x4003 + #define GL_LIGHT4 0x4004 + #define GL_LIGHT5 0x4005 + #define GL_LIGHT6 0x4006 + #define GL_LIGHT7 0x4007 #endif #ifndef GL_LIGHTING diff --git a/include/osg/Transform b/include/osg/Transform index b7cb6c075..dccb2e45e 100644 --- a/include/osg/Transform +++ b/include/osg/Transform @@ -18,7 +18,11 @@ #include #ifndef GL_RESCALE_NORMAL -#define GL_RESCALE_NORMAL 0x803A +#define GL_RESCALE_NORMAL 0x803A +#endif + +#ifndef GL_NORMALIZE +#define GL_NORMALIZE 0x0BA1 #endif namespace osg { diff --git a/include/osgViewer/api/X11/GraphicsWindowX11 b/include/osgViewer/api/X11/GraphicsWindowX11 index 3642aedaa..068f79cea 100644 --- a/include/osgViewer/api/X11/GraphicsWindowX11 +++ b/include/osgViewer/api/X11/GraphicsWindowX11 @@ -24,7 +24,17 @@ #define GLX_GLXEXT_PROTOTYPES 1 #include -#include +#include +#include + +#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) + #define OSG_USE_EGL + #include +#else + #include +#endif + + #include namespace osgViewer @@ -41,7 +51,10 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow _parent(0), _window(0), _visualInfo(0), - _glxContext(0), + _context(0), + #ifdef OSG_USE_EGL + _surface(0), + #endif _currentCursor(0), _initialized(false), _realized(false), @@ -144,7 +157,15 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow Window& getParent() { return _parent; } Window& getWindow() { return _window; } - GLXContext& getGLXContext() { return _glxContext; } + + + #ifdef OSG_USE_EGL + typedef EGLContext Context; + #else + typedef GLXContext Context; + #endif + + Context& getContext() { return _context; } Cursor getCurrentCursor() { return _currentCursor; } @@ -180,7 +201,11 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow Window _parent; Window _window; XVisualInfo* _visualInfo; - GLXContext _glxContext; + Context _context; + + #ifdef OSG_USE_EGL + EGLSurface _surface; + #endif Cursor _currentCursor; diff --git a/include/osgViewer/api/X11/PixelBufferX11 b/include/osgViewer/api/X11/PixelBufferX11 index fa0f5c847..346a064f4 100644 --- a/include/osgViewer/api/X11/PixelBufferX11 +++ b/include/osgViewer/api/X11/PixelBufferX11 @@ -19,19 +19,14 @@ #ifndef OSGVIEWER_PIXELBUFFERX11 #define OSGVIEWER_PIXELBUFFERX11 1 -#include -#include +#include -#define GLX_GLXEXT_PROTOTYPES 1 - -#include -#include - -#ifndef GLX_VERSION_1_3 - typedef XID GLXPbuffer; +#ifndef OSG_USE_EGL + #ifndef GLX_VERSION_1_3 + typedef XID GLXPbuffer; + #endif #endif - namespace osgViewer { @@ -77,8 +72,16 @@ class OSGVIEWER_EXPORT PixelBufferX11 : public osg::GraphicsContext Display* getDisplay() const { return _display; } - GLXPbuffer& getPbuffer() { return _pbuffer; } - GLXContext& getGLXContext() { return _glxContext; } + #ifdef OSG_USE_EGL + typedef EGLContext Context; + typedef EGLSurface Pbuffer; + #else + typedef GLXContext Context; + typedef GLXPbuffer Pbuffer; + #endif + + Pbuffer& getPbuffer() { return _pbuffer; } + Context& getContext() { return _context; } protected: @@ -90,9 +93,9 @@ class OSGVIEWER_EXPORT PixelBufferX11 : public osg::GraphicsContext bool _valid; Display* _display; - GLXPbuffer _pbuffer; + Pbuffer _pbuffer; XVisualInfo* _visualInfo; - GLXContext _glxContext; + Context _context; bool _initialized; bool _realized; diff --git a/src/osgPlugins/osg/StateSet.cpp b/src/osgPlugins/osg/StateSet.cpp index 5bc7ae502..b8eb2893f 100644 --- a/src/osgPlugins/osg/StateSet.cpp +++ b/src/osgPlugins/osg/StateSet.cpp @@ -6,6 +6,13 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include #include #include diff --git a/src/osgPlugins/scale/ReaderWriterSCALE.cpp b/src/osgPlugins/scale/ReaderWriterSCALE.cpp index df6401943..127aca04b 100644 --- a/src/osgPlugins/scale/ReaderWriterSCALE.cpp +++ b/src/osgPlugins/scale/ReaderWriterSCALE.cpp @@ -165,10 +165,12 @@ public: xform->setMatrix( osg::Matrix::scale( sx, sy, sz ) ); xform->addChild( node ); - // turn on GL_NORMALIZE to prevent problems with scaled normals - osg::StateSet* ss = xform->getOrCreateStateSet(); - ss->setMode( GL_NORMALIZE, osg::StateAttribute::ON ); - + #ifndef OSG_GLES2_AVAILABLE + // turn on GL_NORMALIZE to prevent problems with scaled normals + osg::StateSet* ss = xform->getOrCreateStateSet(); + ss->setMode( GL_NORMALIZE, osg::StateAttribute::ON ); + #endif + return xform; } }; diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index 21f8ada34..2bfe5c24e 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -904,4 +904,4 @@ void Font::Glyph::subload() const "\t 0x"<<(GLenum)getDataType()<screenNum ); + if (XMatchVisualInfo( _display, _traits->screenNum, depth, TrueColor, _visualInfo )==0) + { + osg::notify(osg::NOTICE)<<"GraphicsWindowX11::createVisualInfo() failed."< Attributes; Attributes attributes; @@ -297,12 +308,12 @@ bool GraphicsWindowX11::createVisualInfo() if (_traits->stencil) { attributes.push_back(GLX_STENCIL_SIZE); attributes.push_back(_traits->stencil); } - #if defined(GLX_SAMPLE_BUFFERS) && defined (GLX_SAMPLES) - - if (_traits->sampleBuffers) { attributes.push_back(GLX_SAMPLE_BUFFERS); attributes.push_back(_traits->sampleBuffers); } - if (_traits->sampleBuffers) { attributes.push_back(GLX_SAMPLES); attributes.push_back(_traits->samples); } - - #endif + #if defined(GLX_SAMPLE_BUFFERS) && defined (GLX_SAMPLES) + + if (_traits->sampleBuffers) { attributes.push_back(GLX_SAMPLE_BUFFERS); attributes.push_back(_traits->sampleBuffers); } + if (_traits->sampleBuffers) { attributes.push_back(GLX_SAMPLES); attributes.push_back(_traits->samples); } + + #endif // TODO // GLX_AUX_BUFFERS // GLX_ACCUM_RED_SIZE @@ -313,6 +324,7 @@ bool GraphicsWindowX11::createVisualInfo() attributes.push_back(None); _visualInfo = glXChooseVisual( _display, _traits->screenNum, &(attributes.front()) ); + #endif } return _visualInfo != 0; @@ -602,8 +614,6 @@ void GraphicsWindowX11::init() _ownsWindow = windowHandle == 0; - - _display = XOpenDisplay(_traits->displayName().c_str()); if (!_display) @@ -613,18 +623,37 @@ void GraphicsWindowX11::init() return; } - // Query for GLX extension - int errorBase, eventBase; - if( glXQueryExtension( _display, &errorBase, &eventBase) == False ) - { - osg::notify(osg::NOTICE)<<"Error: " << XDisplayName(_traits->displayName().c_str()) <<" has no GLX extension." << std::endl; + #ifdef OSG_USE_EGL - XCloseDisplay( _display ); - _display = 0; - _valid = false; - return; - } + EGLDisplay eglDisplay = eglGetDisplay((EGLNativeDisplayType)_display); + EGLint eglMajorVersion, eglMinorVersion; + if (!eglInitialize(eglDisplay, &eglMajorVersion, &eglMinorVersion)) + { + osg::notify(osg::NOTICE)<<"GraphicsWindowX11::init() - eglInitialize() failed."<displayName().c_str()) <<" has no GLX extension." << std::endl; + + XCloseDisplay( _display ); + _display = 0; + _valid = false; + return; + } + #endif + // osg::notify(osg::NOTICE)<<"GLX extension, errorBase="<