diff --git a/build/PlatformSpecifics/Windows/OpenSceneGraphVersionInfo.rc b/build/PlatformSpecifics/Windows/OpenSceneGraphVersionInfo.rc new file mode 100644 index 00000000000..c2073ff7960 --- /dev/null +++ b/build/PlatformSpecifics/Windows/OpenSceneGraphVersionInfo.rc @@ -0,0 +1,31 @@ +1 VERSIONINFO + FILEVERSION 3, 6, 5, 162 + PRODUCTVERSION 3, 6, 5, 162 + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x0L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "OpenSceneGraph Binary" + VALUE "FileVersion", "3, 6, 5, 162" + VALUE "InternalName", "OSG" + VALUE "LegalCopyright", "Copyright (C) 2009" + VALUE "OriginalFilename", "" + VALUE "ProductName", "OpenSceneGraph" + VALUE "ProductVersion", "3, 6, 5, 162" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END diff --git a/build/PlatformSpecifics/Windows/OpenThreadsVersionInfo.rc b/build/PlatformSpecifics/Windows/OpenThreadsVersionInfo.rc new file mode 100644 index 00000000000..205ba181caf --- /dev/null +++ b/build/PlatformSpecifics/Windows/OpenThreadsVersionInfo.rc @@ -0,0 +1,31 @@ +1 VERSIONINFO + FILEVERSION 3, 3, 1, 21 + PRODUCTVERSION 3, 3, 1, 21 + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x0L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "OPENTHREADS Binary" + VALUE "FileVersion", "3, 3, 1, 21" + VALUE "InternalName", "OSG" + VALUE "LegalCopyright", "Copyright (C) 2009" + VALUE "OriginalFilename", "" + VALUE "ProductName", "OPENTHREADS" + VALUE "ProductVersion", "3, 3, 1, 21" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END diff --git a/build/include/OpenThreads/Config b/build/include/OpenThreads/Config new file mode 100644 index 00000000000..713905d64c1 --- /dev/null +++ b/build/include/OpenThreads/Config @@ -0,0 +1,34 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 2008 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. +*/ + +/**************************************************************************** + * THIS FILE IS AUTOGENERATED BY CMAKE. DO NOT EDIT! + ****************************************************************************/ + +/* Changes to the configuration reflected here can be made with ccmake on + * unix or with cmake-gui on windows. Alternatively you can use cmake's -D + * or -P switches to set some configuration values at cmake configuration time. + */ + +#ifndef _OPENTHREADS_CONFIG +#define _OPENTHREADS_CONFIG + +/* #undef _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS */ +/* #undef _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS */ +/* #undef _OPENTHREADS_ATOMIC_USE_SUN */ +#define _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED +/* #undef _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC */ +/* #undef _OPENTHREADS_ATOMIC_USE_MUTEX */ +/* #undef OT_LIBRARY_STATIC */ + +#endif diff --git a/build/include/OpenThreads/Version b/build/include/OpenThreads/Version new file mode 100644 index 00000000000..1381595fd85 --- /dev/null +++ b/build/include/OpenThreads/Version @@ -0,0 +1,38 @@ +/* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007 The Open Thread Group + * + * 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 OPENTHREADS_VERSION +#define OPENTHREADS_VERSION 1 + +#include + +extern "C" { + +#define OPENTHREADS_MAJOR_VERSION 3 +#define OPENTHREADS_MINOR_VERSION 3 +#define OPENTHREADS_PATCH_VERSION 1 +#define OPENTHREADS_SOVERSION 21 + +/** OpenThreadsGetVersion() returns the library version number. + * Numbering convention : OpenThreads-1.0 will return 1.0 from OpenThreadsGetVersion. */ +extern OPENTHREAD_EXPORT_DIRECTIVE const char* OpenThreadsGetVersion(); + +/** The OpenThreadsGetSOVersion() method returns the OpenSceneGraph soversion number. */ +extern OPENTHREAD_EXPORT_DIRECTIVE const char* OpenThreadsGetSOVersion(); + +/** The OpenThreadsGetLibraryName() method returns the library name in human-friendly form. */ +extern OPENTHREAD_EXPORT_DIRECTIVE const char* OpenThreadsGetLibraryName(); + +} + +#endif diff --git a/build/include/osg/Config b/build/include/osg/Config new file mode 100644 index 00000000000..d5e0300f065 --- /dev/null +++ b/build/include/osg/Config @@ -0,0 +1,42 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 2008-2009 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. +*/ + +/**************************************************************************** + * THIS FILE IS AUTOGENERATED BY CMAKE. DO NOT EDIT! + ****************************************************************************/ + +/* Changes to the configuration reflected here can be made with ccmake on + * unix or with cmake-gui on windows. Alternatively you can use cmake's -D + * or -P switches to set some configuration values at cmake configuration time. + */ + +#ifndef OSG_CONFIG +#define OSG_CONFIG 1 + +/* #undef OSG_NOTIFY_DISABLED */ +/* #undef OSG_USE_FLOAT_MATRIX */ +/* #undef OSG_USE_FLOAT_PLANE */ +#define OSG_USE_FLOAT_BOUNDINGSPHERE +#define OSG_USE_FLOAT_BOUNDINGBOX +/* #undef OSG_USE_FLOAT_QUAT */ +#define OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION +/* #undef OSG_USE_REF_PTR_SAFE_DEREFERENCE */ +/* #undef OSG_USE_UTF8_FILENAME */ +#define OSG_DISABLE_MSVC_WARNINGS +#define OSG_PROVIDE_READFILE +#define OSG_USE_DEPRECATED_API +#define OSG_ENVVAR_SUPPORTED +/* #undef OSG_WINDOWING_SYSTEM_CARBON */ +/* #undef OSG_WINDOWING_SYSTEM_NONE */ + +#endif diff --git a/build/include/osg/GL b/build/include/osg/GL new file mode 100644 index 00000000000..f678ba46342 --- /dev/null +++ b/build/include/osg/GL @@ -0,0 +1,194 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 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_OPENGL +#define OSG_OPENGL 1 + +#include +#include +#include + +#define OSG_GL1_AVAILABLE +#define OSG_GL2_AVAILABLE +/* #undef OSG_GL3_AVAILABLE */ +/* #undef OSG_GLES1_AVAILABLE */ +/* #undef OSG_GLES2_AVAILABLE */ +/* #undef OSG_GLES3_AVAILABLE */ +/* #undef OSG_GL_LIBRARY_STATIC */ +#define OSG_GL_DISPLAYLISTS_AVAILABLE +#define OSG_GL_MATRICES_AVAILABLE +#define OSG_GL_VERTEX_FUNCS_AVAILABLE +#define OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE +#define OSG_GL_FIXED_FUNCTION_AVAILABLE +/* #undef GL_HEADER_HAS_GLINT64 */ +/* #undef GL_HEADER_HAS_GLUINT64 */ + +#define OSG_GL1_FEATURES 1 +#define OSG_GL2_FEATURES 1 +#define OSG_GL3_FEATURES 0 +#define OSG_GLES1_FEATURES 0 +#define OSG_GLES2_FEATURES 0 +#define OSG_GLES3_FEATURES 0 +#define OSG_GL_CONTEXT_VERSION "1.0" + + +#ifndef _WIN32 + + // Required for compatibility with glext.h style function definitions of + // OpenGL extensions, such as in src/osg/Point.cpp. + #ifndef APIENTRY + #define APIENTRY + #endif + +#else // _WIN32 + + #if defined(__CYGWIN__) || defined(__MINGW32__) + + #ifndef APIENTRY + #define GLUT_APIENTRY_DEFINED + #define APIENTRY __stdcall + #endif + // XXX This is from Win32's + #ifndef CALLBACK + #define CALLBACK __stdcall + #endif + + #else // ! __CYGWIN__ + + // Under Windows avoid including + // to avoid name space pollution, but Win32's + // needs APIENTRY and WINGDIAPI defined properly. + // XXX This is from Win32's + #ifndef APIENTRY + #define GLUT_APIENTRY_DEFINED + #if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) + #define WINAPI __stdcall + #define APIENTRY WINAPI + #else + #define APIENTRY + #endif + #endif + + // XXX This is from Win32's + #ifndef CALLBACK + #if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) + #define CALLBACK __stdcall + #else + #define CALLBACK + #endif + #endif + + #endif // __CYGWIN__ + + // XXX This is from Win32's and + #ifndef WINGDIAPI + #define GLUT_WINGDIAPI_DEFINED + #define DECLSPEC_IMPORT __declspec(dllimport) + #define WINGDIAPI DECLSPEC_IMPORT + #endif + + // XXX This is from Win32's + #if !defined(_WCHAR_T_DEFINED) && !(defined(__GNUC__)&&(__GNUC__ > 2)) + typedef unsigned short wchar_t; + #define _WCHAR_T_DEFINED + #endif + +#endif // _WIN32 + +#if defined(OSG_GL3_AVAILABLE) + #define GL3_PROTOTYPES 1 + #define GL_GLEXT_PROTOTYPES 1 +#endif + + +#include + + + +#ifndef GL_APIENTRY + #define GL_APIENTRY APIENTRY +#endif // GL_APIENTRY + + +#ifndef GL_HEADER_HAS_GLINT64 + typedef int64_t GLint64; +#endif + +#ifndef GL_HEADER_HAS_GLUINT64 + typedef uint64_t GLuint64; +#endif + +#ifdef OSG_GL_MATRICES_AVAILABLE + + inline void glLoadMatrix(const float* mat) { glLoadMatrixf(static_cast(mat)); } + inline void glMultMatrix(const float* mat) { glMultMatrixf(static_cast(mat)); } + + #ifdef OSG_GLES1_AVAILABLE + inline void glLoadMatrix(const double* mat) + { + GLfloat flt_mat[16]; + for(unsigned int i=0;i<16;++i) flt_mat[i] = mat[i]; + glLoadMatrixf(flt_mat); + } + + inline void glMultMatrix(const double* mat) + { + GLfloat flt_mat[16]; + for(unsigned int i=0;i<16;++i) flt_mat[i] = mat[i]; + glMultMatrixf(flt_mat); + } + + #else + inline void glLoadMatrix(const double* mat) { glLoadMatrixd(static_cast(mat)); } + inline void glMultMatrix(const double* mat) { glMultMatrixd(static_cast(mat)); } + #endif +#endif + +// add defines for OpenGL targets that don't define them, just to ease compatibility across targets +#ifndef GL_DOUBLE + #define GL_DOUBLE 0x140A + typedef double GLdouble; +#endif + +#ifndef GL_INT + #define GL_INT 0x1404 +#endif + +#ifndef GL_UNSIGNED_INT + #define GL_UNSIGNED_INT 0x1405 +#endif + +#ifndef GL_NONE + // OpenGL ES1 doesn't provide GL_NONE + #define GL_NONE 0x0 +#endif + +#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE) + //GLES defines (OES) + #define GL_RGB8_OES 0x8051 + #define GL_RGBA8_OES 0x8058 +#endif + +#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE) || defined(OSG_GL3_AVAILABLE) + #define GL_POLYGON 0x0009 + #define GL_QUADS 0x0007 + #define GL_QUAD_STRIP 0x0008 +#endif + +#if defined(OSG_GL3_AVAILABLE) + #define GL_LUMINANCE 0x1909 + #define GL_LUMINANCE_ALPHA 0x190A +#endif + + +#endif diff --git a/build/include/osg/Version b/build/include/osg/Version new file mode 100644 index 00000000000..def75985126 --- /dev/null +++ b/build/include/osg/Version @@ -0,0 +1,73 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 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_VERSION +#define OSG_VERSION 1 + +#include + +extern "C" { + +#define OPENSCENEGRAPH_MAJOR_VERSION 3 +#define OPENSCENEGRAPH_MINOR_VERSION 6 +#define OPENSCENEGRAPH_PATCH_VERSION 5 +#define OPENSCENEGRAPH_SOVERSION 162 + +/* Convenience macro that can be used to decide whether a feature is present or not i.e. + * #if OSG_MIN_VERSION_REQUIRED(2,9,5) + * your code here + * #endif + */ +#define OSG_MIN_VERSION_REQUIRED(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION>MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION>MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION>=PATCH)))) +#define OSG_VERSION_LESS_THAN(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSIONMAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION>MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION>PATCH)))) +#define OSG_VERSION_GREATER_OR_EQUAL(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION>MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION>MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION>=PATCH)))) + + +/** + * osgGetVersion() returns the library version number. + * Numbering convention : OpenSceneGraph-1.0 will return 1.0 from osgGetVersion. + * + * This C function can be also used to check for the existence of the OpenSceneGraph + * library using autoconf and its m4 macro AC_CHECK_LIB. + * + * Here is the code to add to your configure.in: + \verbatim + # + # Check for the OpenSceneGraph (OSG) library + # + AC_CHECK_LIB(osg, osgGetVersion, , + [AC_MSG_ERROR(OpenSceneGraph library not found. See http://www.openscenegraph.org)],) + \endverbatim +*/ +extern OSG_EXPORT const char* osgGetVersion(); + +/** The osgGetSOVersion() method returns the OpenSceneGraph shared object version number. */ +extern OSG_EXPORT const char* osgGetSOVersion(); + +/** The osgGetLibraryName() method returns the library name in human-friendly form. */ +extern OSG_EXPORT const char* osgGetLibraryName(); + +// old defines for backwards compatibility. +#define OSG_VERSION_MAJOR OPENSCENEGRAPH_MAJOR_VERSION +#define OSG_VERSION_MINOR OPENSCENEGRAPH_MINOR_VERSION +#define OSG_VERSION_PATCH OPENSCENEGRAPH_PATCH_VERSION + +#define OSG_VERSION_RELEASE OSG_VERSION_PATCH +#define OSG_VERSION_REVISION 0 + + +} + +#endif diff --git a/build2019/PlatformSpecifics/Windows/OpenSceneGraphVersionInfo.rc b/build2019/PlatformSpecifics/Windows/OpenSceneGraphVersionInfo.rc new file mode 100644 index 00000000000..c2073ff7960 --- /dev/null +++ b/build2019/PlatformSpecifics/Windows/OpenSceneGraphVersionInfo.rc @@ -0,0 +1,31 @@ +1 VERSIONINFO + FILEVERSION 3, 6, 5, 162 + PRODUCTVERSION 3, 6, 5, 162 + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x0L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "OpenSceneGraph Binary" + VALUE "FileVersion", "3, 6, 5, 162" + VALUE "InternalName", "OSG" + VALUE "LegalCopyright", "Copyright (C) 2009" + VALUE "OriginalFilename", "" + VALUE "ProductName", "OpenSceneGraph" + VALUE "ProductVersion", "3, 6, 5, 162" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END diff --git a/build2019/PlatformSpecifics/Windows/OpenThreadsVersionInfo.rc b/build2019/PlatformSpecifics/Windows/OpenThreadsVersionInfo.rc new file mode 100644 index 00000000000..205ba181caf --- /dev/null +++ b/build2019/PlatformSpecifics/Windows/OpenThreadsVersionInfo.rc @@ -0,0 +1,31 @@ +1 VERSIONINFO + FILEVERSION 3, 3, 1, 21 + PRODUCTVERSION 3, 3, 1, 21 + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x0L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "OPENTHREADS Binary" + VALUE "FileVersion", "3, 3, 1, 21" + VALUE "InternalName", "OSG" + VALUE "LegalCopyright", "Copyright (C) 2009" + VALUE "OriginalFilename", "" + VALUE "ProductName", "OPENTHREADS" + VALUE "ProductVersion", "3, 3, 1, 21" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END diff --git a/build2019/include/OpenThreads/Config b/build2019/include/OpenThreads/Config new file mode 100644 index 00000000000..713905d64c1 --- /dev/null +++ b/build2019/include/OpenThreads/Config @@ -0,0 +1,34 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 2008 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. +*/ + +/**************************************************************************** + * THIS FILE IS AUTOGENERATED BY CMAKE. DO NOT EDIT! + ****************************************************************************/ + +/* Changes to the configuration reflected here can be made with ccmake on + * unix or with cmake-gui on windows. Alternatively you can use cmake's -D + * or -P switches to set some configuration values at cmake configuration time. + */ + +#ifndef _OPENTHREADS_CONFIG +#define _OPENTHREADS_CONFIG + +/* #undef _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS */ +/* #undef _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS */ +/* #undef _OPENTHREADS_ATOMIC_USE_SUN */ +#define _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED +/* #undef _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC */ +/* #undef _OPENTHREADS_ATOMIC_USE_MUTEX */ +/* #undef OT_LIBRARY_STATIC */ + +#endif diff --git a/build2019/include/OpenThreads/Version b/build2019/include/OpenThreads/Version new file mode 100644 index 00000000000..1381595fd85 --- /dev/null +++ b/build2019/include/OpenThreads/Version @@ -0,0 +1,38 @@ +/* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007 The Open Thread Group + * + * 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 OPENTHREADS_VERSION +#define OPENTHREADS_VERSION 1 + +#include + +extern "C" { + +#define OPENTHREADS_MAJOR_VERSION 3 +#define OPENTHREADS_MINOR_VERSION 3 +#define OPENTHREADS_PATCH_VERSION 1 +#define OPENTHREADS_SOVERSION 21 + +/** OpenThreadsGetVersion() returns the library version number. + * Numbering convention : OpenThreads-1.0 will return 1.0 from OpenThreadsGetVersion. */ +extern OPENTHREAD_EXPORT_DIRECTIVE const char* OpenThreadsGetVersion(); + +/** The OpenThreadsGetSOVersion() method returns the OpenSceneGraph soversion number. */ +extern OPENTHREAD_EXPORT_DIRECTIVE const char* OpenThreadsGetSOVersion(); + +/** The OpenThreadsGetLibraryName() method returns the library name in human-friendly form. */ +extern OPENTHREAD_EXPORT_DIRECTIVE const char* OpenThreadsGetLibraryName(); + +} + +#endif diff --git a/build2019/include/osg/Config b/build2019/include/osg/Config new file mode 100644 index 00000000000..74b19b18889 --- /dev/null +++ b/build2019/include/osg/Config @@ -0,0 +1,42 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 2008-2009 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. +*/ + +/**************************************************************************** + * THIS FILE IS AUTOGENERATED BY CMAKE. DO NOT EDIT! + ****************************************************************************/ + +/* Changes to the configuration reflected here can be made with ccmake on + * unix or with cmake-gui on windows. Alternatively you can use cmake's -D + * or -P switches to set some configuration values at cmake configuration time. + */ + +#ifndef OSG_CONFIG +#define OSG_CONFIG 1 + +/* #undef OSG_NOTIFY_DISABLED */ +#define OSG_USE_FLOAT_MATRIX +#define OSG_USE_FLOAT_PLANE +#define OSG_USE_FLOAT_BOUNDINGSPHERE +#define OSG_USE_FLOAT_BOUNDINGBOX +#define OSG_USE_FLOAT_QUAT +#define OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION +/* #undef OSG_USE_REF_PTR_SAFE_DEREFERENCE */ +/* #undef OSG_USE_UTF8_FILENAME */ +#define OSG_DISABLE_MSVC_WARNINGS +#define OSG_PROVIDE_READFILE +#define OSG_USE_DEPRECATED_API +#define OSG_ENVVAR_SUPPORTED +/* #undef OSG_WINDOWING_SYSTEM_CARBON */ +/* #undef OSG_WINDOWING_SYSTEM_NONE */ + +#endif diff --git a/build2019/include/osg/GL b/build2019/include/osg/GL new file mode 100644 index 00000000000..f678ba46342 --- /dev/null +++ b/build2019/include/osg/GL @@ -0,0 +1,194 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 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_OPENGL +#define OSG_OPENGL 1 + +#include +#include +#include + +#define OSG_GL1_AVAILABLE +#define OSG_GL2_AVAILABLE +/* #undef OSG_GL3_AVAILABLE */ +/* #undef OSG_GLES1_AVAILABLE */ +/* #undef OSG_GLES2_AVAILABLE */ +/* #undef OSG_GLES3_AVAILABLE */ +/* #undef OSG_GL_LIBRARY_STATIC */ +#define OSG_GL_DISPLAYLISTS_AVAILABLE +#define OSG_GL_MATRICES_AVAILABLE +#define OSG_GL_VERTEX_FUNCS_AVAILABLE +#define OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE +#define OSG_GL_FIXED_FUNCTION_AVAILABLE +/* #undef GL_HEADER_HAS_GLINT64 */ +/* #undef GL_HEADER_HAS_GLUINT64 */ + +#define OSG_GL1_FEATURES 1 +#define OSG_GL2_FEATURES 1 +#define OSG_GL3_FEATURES 0 +#define OSG_GLES1_FEATURES 0 +#define OSG_GLES2_FEATURES 0 +#define OSG_GLES3_FEATURES 0 +#define OSG_GL_CONTEXT_VERSION "1.0" + + +#ifndef _WIN32 + + // Required for compatibility with glext.h style function definitions of + // OpenGL extensions, such as in src/osg/Point.cpp. + #ifndef APIENTRY + #define APIENTRY + #endif + +#else // _WIN32 + + #if defined(__CYGWIN__) || defined(__MINGW32__) + + #ifndef APIENTRY + #define GLUT_APIENTRY_DEFINED + #define APIENTRY __stdcall + #endif + // XXX This is from Win32's + #ifndef CALLBACK + #define CALLBACK __stdcall + #endif + + #else // ! __CYGWIN__ + + // Under Windows avoid including + // to avoid name space pollution, but Win32's + // needs APIENTRY and WINGDIAPI defined properly. + // XXX This is from Win32's + #ifndef APIENTRY + #define GLUT_APIENTRY_DEFINED + #if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) + #define WINAPI __stdcall + #define APIENTRY WINAPI + #else + #define APIENTRY + #endif + #endif + + // XXX This is from Win32's + #ifndef CALLBACK + #if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) + #define CALLBACK __stdcall + #else + #define CALLBACK + #endif + #endif + + #endif // __CYGWIN__ + + // XXX This is from Win32's and + #ifndef WINGDIAPI + #define GLUT_WINGDIAPI_DEFINED + #define DECLSPEC_IMPORT __declspec(dllimport) + #define WINGDIAPI DECLSPEC_IMPORT + #endif + + // XXX This is from Win32's + #if !defined(_WCHAR_T_DEFINED) && !(defined(__GNUC__)&&(__GNUC__ > 2)) + typedef unsigned short wchar_t; + #define _WCHAR_T_DEFINED + #endif + +#endif // _WIN32 + +#if defined(OSG_GL3_AVAILABLE) + #define GL3_PROTOTYPES 1 + #define GL_GLEXT_PROTOTYPES 1 +#endif + + +#include + + + +#ifndef GL_APIENTRY + #define GL_APIENTRY APIENTRY +#endif // GL_APIENTRY + + +#ifndef GL_HEADER_HAS_GLINT64 + typedef int64_t GLint64; +#endif + +#ifndef GL_HEADER_HAS_GLUINT64 + typedef uint64_t GLuint64; +#endif + +#ifdef OSG_GL_MATRICES_AVAILABLE + + inline void glLoadMatrix(const float* mat) { glLoadMatrixf(static_cast(mat)); } + inline void glMultMatrix(const float* mat) { glMultMatrixf(static_cast(mat)); } + + #ifdef OSG_GLES1_AVAILABLE + inline void glLoadMatrix(const double* mat) + { + GLfloat flt_mat[16]; + for(unsigned int i=0;i<16;++i) flt_mat[i] = mat[i]; + glLoadMatrixf(flt_mat); + } + + inline void glMultMatrix(const double* mat) + { + GLfloat flt_mat[16]; + for(unsigned int i=0;i<16;++i) flt_mat[i] = mat[i]; + glMultMatrixf(flt_mat); + } + + #else + inline void glLoadMatrix(const double* mat) { glLoadMatrixd(static_cast(mat)); } + inline void glMultMatrix(const double* mat) { glMultMatrixd(static_cast(mat)); } + #endif +#endif + +// add defines for OpenGL targets that don't define them, just to ease compatibility across targets +#ifndef GL_DOUBLE + #define GL_DOUBLE 0x140A + typedef double GLdouble; +#endif + +#ifndef GL_INT + #define GL_INT 0x1404 +#endif + +#ifndef GL_UNSIGNED_INT + #define GL_UNSIGNED_INT 0x1405 +#endif + +#ifndef GL_NONE + // OpenGL ES1 doesn't provide GL_NONE + #define GL_NONE 0x0 +#endif + +#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE) + //GLES defines (OES) + #define GL_RGB8_OES 0x8051 + #define GL_RGBA8_OES 0x8058 +#endif + +#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE) || defined(OSG_GL3_AVAILABLE) + #define GL_POLYGON 0x0009 + #define GL_QUADS 0x0007 + #define GL_QUAD_STRIP 0x0008 +#endif + +#if defined(OSG_GL3_AVAILABLE) + #define GL_LUMINANCE 0x1909 + #define GL_LUMINANCE_ALPHA 0x190A +#endif + + +#endif diff --git a/build2019/include/osg/Version b/build2019/include/osg/Version new file mode 100644 index 00000000000..def75985126 --- /dev/null +++ b/build2019/include/osg/Version @@ -0,0 +1,73 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 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_VERSION +#define OSG_VERSION 1 + +#include + +extern "C" { + +#define OPENSCENEGRAPH_MAJOR_VERSION 3 +#define OPENSCENEGRAPH_MINOR_VERSION 6 +#define OPENSCENEGRAPH_PATCH_VERSION 5 +#define OPENSCENEGRAPH_SOVERSION 162 + +/* Convenience macro that can be used to decide whether a feature is present or not i.e. + * #if OSG_MIN_VERSION_REQUIRED(2,9,5) + * your code here + * #endif + */ +#define OSG_MIN_VERSION_REQUIRED(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION>MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION>MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION>=PATCH)))) +#define OSG_VERSION_LESS_THAN(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSIONMAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION>MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION>PATCH)))) +#define OSG_VERSION_GREATER_OR_EQUAL(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION>MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION>MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION>=PATCH)))) + + +/** + * osgGetVersion() returns the library version number. + * Numbering convention : OpenSceneGraph-1.0 will return 1.0 from osgGetVersion. + * + * This C function can be also used to check for the existence of the OpenSceneGraph + * library using autoconf and its m4 macro AC_CHECK_LIB. + * + * Here is the code to add to your configure.in: + \verbatim + # + # Check for the OpenSceneGraph (OSG) library + # + AC_CHECK_LIB(osg, osgGetVersion, , + [AC_MSG_ERROR(OpenSceneGraph library not found. See http://www.openscenegraph.org)],) + \endverbatim +*/ +extern OSG_EXPORT const char* osgGetVersion(); + +/** The osgGetSOVersion() method returns the OpenSceneGraph shared object version number. */ +extern OSG_EXPORT const char* osgGetSOVersion(); + +/** The osgGetLibraryName() method returns the library name in human-friendly form. */ +extern OSG_EXPORT const char* osgGetLibraryName(); + +// old defines for backwards compatibility. +#define OSG_VERSION_MAJOR OPENSCENEGRAPH_MAJOR_VERSION +#define OSG_VERSION_MINOR OPENSCENEGRAPH_MINOR_VERSION +#define OSG_VERSION_PATCH OPENSCENEGRAPH_PATCH_VERSION + +#define OSG_VERSION_RELEASE OSG_VERSION_PATCH +#define OSG_VERSION_REVISION 0 + + +} + +#endif diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 788e5075f5c..d499d05b6c7 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -39,6 +39,7 @@ IF(DYNAMIC_OPENSCENEGRAPH) ADD_SUBDIRECTORY(osgcubemap) ADD_SUBDIRECTORY(osgdeferred) ADD_SUBDIRECTORY(osgcluster) + ADD_SUBDIRECTORY(osgcustompager) ADD_SUBDIRECTORY(osgdatabaserevisions) ADD_SUBDIRECTORY(osgdepthpartition) ADD_SUBDIRECTORY(osgdepthpeeling) @@ -76,7 +77,7 @@ IF(DYNAMIC_OPENSCENEGRAPH) ADD_SUBDIRECTORY(osgmultitexture) ADD_SUBDIRECTORY(osgmultitexturecontrol) ADD_SUBDIRECTORY(osgmultitouch) - ADD_SUBDIRECTORY(osgmultiviewpaging) + ADD_SUBDIRECTORY(osgmultiviewOVR) ADD_SUBDIRECTORY(osgobjectcache) ADD_SUBDIRECTORY(osgoccluder) ADD_SUBDIRECTORY(osgocclusionquery) diff --git a/examples/osgcustompager/CMakeLists.txt b/examples/osgcustompager/CMakeLists.txt new file mode 100644 index 00000000000..7ba22752510 --- /dev/null +++ b/examples/osgcustompager/CMakeLists.txt @@ -0,0 +1,4 @@ +SET(TARGET_SRC osgcustompager.cpp ) + +#### end var setup ### +SETUP_EXAMPLE(osgcustompager) diff --git a/examples/osgmultiviewpaging/osgmultiviewpaging.cpp b/examples/osgcustompager/osgcustompager.cpp similarity index 100% rename from examples/osgmultiviewpaging/osgmultiviewpaging.cpp rename to examples/osgcustompager/osgcustompager.cpp diff --git a/examples/osgmultiviewOVR/CMakeLists.txt b/examples/osgmultiviewOVR/CMakeLists.txt new file mode 100644 index 00000000000..ce8add92a24 --- /dev/null +++ b/examples/osgmultiviewOVR/CMakeLists.txt @@ -0,0 +1,9 @@ +SET(TARGET_SRC + MultiviewOVR.cpp + StandardStereo.cpp + Leia.cpp + osgmultiviewOVR.cpp +) + +#### end var setup ### +SETUP_EXAMPLE(osgmultiviewOVR) diff --git a/examples/osgmultiviewOVR/Leia.cpp b/examples/osgmultiviewOVR/Leia.cpp new file mode 100644 index 00000000000..fc6c98cf06c --- /dev/null +++ b/examples/osgmultiviewOVR/Leia.cpp @@ -0,0 +1,472 @@ +#include "Leia.h" + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace osgViewer; + +#if 0 +// https://docs.leialoft.com/developer/android-sdk/rendering-for-leia + +// https://docs.leialoft.com/developer/android-sdk/rendering-for-leia/leiainitializecameradata +void leiaInitializeCameraData(LeiaCameraData * data, + int num_horizontal_views, + int num_vertical_views, + float system_disparity_in_pixels, + float baseline_scaling, + float convergence_distance, + float vertical_field_of_view_degrees, + float near, float far, + int view_resolution_x_pixels, + int view_resolution_y_pixels); + +// https://docs.leialoft.com/developer/android-sdk/rendering-for-leia/leiacalculateviews +int leiaCalculateViews(LeiaCameraData * data, + LeiaCameraView * out_views, + int len_views_in_x, + int len_views_in_y); + +// https://docs.leialoft.com/developer/android-sdk/rendering-for-leia/leiainitializecameradatafrommatrix +void leiaInitializeCameraDataFromMatrix(float* matrix_4_4, + LeiaCameraData* data, + int num_horizontal_views, + int num_vertical_views, + float system_disparity_in_pixels, + float baseline_scaling, + float convergence_distance, + int view_resolution_x_pixels, + int view_resolution_y_pixels); + +// https://docs.leialoft.com/developer/android-sdk/rendering-for-leia/updating-your-matrices +void leiaSetNumberOfViews(LeiaCameraData* data, + int num_horizontal_views, + int num_vertical_views); +void leiaSetSystemDisparityInPixels(LeiaCameraData* data, + float disparity_in_pixels); +void leiaSetApplicationBaselineScale(LeiaCameraData* data, + float baseline_scaling); +void leiaSetFieldOfView(LeiaCameraData* data, + float fov_in_degrees); +void leiaSetFrustumPlanes(LeiaCameraData* data, + float near, + float focal_distance, + float far); +void leiaSetViewSizeInPixels(LeiaCameraData* data, + int resolution_x, + int resolution_y); + +// shaders +// https://docs.leialoft.com/developer/android-sdk/rendering-for-leia/shaders + +// updating the pipeline +// https://docs.leialoft.com/developer/android-sdk/updating-the-gl-pipeline + + +// Example Shaders in SDK +~/3rdParty/Lumia/LeiaLoft_NativeAndroid_SDK_2018-07-19/Samples/TeapotsWithLeia/classic-teapot/src/main/assets/Shaders + + +#endif + +struct LeiaIntialFrustumCallback : public osg::CullSettings::InitialFrustumCallback +{ + std::vector projectionMatrices; + + bool applyBB = true; + osg::BoundingBoxd bb; + + void toggle() + { + applyBB = !applyBB; + } + + void computeClipSpaceBound(osg::Camera& camera) + { + osg::Matrixd pmv = camera.getProjectionMatrix() * camera.getViewMatrix(); + + size_t numOffsets = projectionMatrices.size(); + + std::vector world_vertices; + world_vertices.reserve(numOffsets*8); + + for(size_t i=0; i cifc; + + bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) + { + if (ea.getHandled()) return false; + + switch(ea.getEventType()) + { + case(osgGA::GUIEventAdapter::KEYUP): + { + if (ea.getKey()=='c') + { + cifc->toggle(); + return true; + } + break; + } + + default: + return false; + } + return false; + } +}; + + +osg::ref_ptr Leia::createLeiaMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector) const +{ + osg::Vec3d center(0.0,0.0,0.0); + osg::Vec3d eye(0.0,0.0,0.0); + + // create the quad to visualize. + osg::Geometry* geometry = new osg::Geometry(); + + geometry->setSupportsDisplayList(false); + + osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES); + osg::Vec3Array* vertices = new osg::Vec3Array; + osg::Vec2Array* texcoords = new osg::Vec2Array; + osg::Vec4Array* colors = new osg::Vec4Array; + colors->push_back(osg::Vec4(1.0, 1.0, 0.0, 1.0)); + + vertices->push_back(origin); + texcoords->push_back(osg::Vec2(0.0f, 0.0f)); + + vertices->push_back(origin + widthVector); + texcoords->push_back(osg::Vec2(1.0f, 0.0f)); + + vertices->push_back(origin + widthVector + heightVector); + texcoords->push_back(osg::Vec2(1.0f, 1.0f)); + + vertices->push_back(origin + heightVector); + texcoords->push_back(osg::Vec2(0.0f, 1.0f)); + + uint16_t base = 0; + elements->push_back(base + 0); + elements->push_back(base + 1); + elements->push_back(base + 2); + elements->push_back(base + 2); + elements->push_back(base + 3); + elements->push_back(base + 0); + + geometry->setVertexArray(vertices); + geometry->setColorArray(colors, osg::Array::BIND_OVERALL); + geometry->setTexCoordArray(0, texcoords); + geometry->addPrimitiveSet(elements); + + return geometry; +} + +osg::ref_ptr Leia::createTexture2DArray(unsigned int width, unsigned int height, unsigned int depth, GLenum format) const +{ + osg::ref_ptr texture = new osg::Texture2DArray; + texture->setTextureSize(width, height, depth); + texture->setInternalFormat(format); + texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); + texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); + texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); + texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); + texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); + return texture; +} + +void Leia::configure(osgViewer::View& view) const +{ + osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); + if (!wsi) + { + OSG_NOTICE<<"Error, no WindowSystemInterface available, cannot create windows."<getScreenResolution(si, width, height); + + osg::ref_ptr traits = new osg::GraphicsContext::Traits; + traits->hostName = si.hostName; + traits->displayNum = si.displayNum; + traits->screenNum = si.screenNum; + traits->x = 0; + traits->y = 0; + traits->width = width; + traits->height = height; + traits->windowDecoration = false; + traits->doubleBuffer = true; + traits->sharedContext = 0; + + osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); + if (!gc) + { + OSG_NOTICE<<"GraphicsWindow has not been created successfully."<getState()->setUseModelViewAndProjectionUniforms(true); + gc->getState()->setUseVertexAttributeAliasing(true); + //osg::DisplaySettings::instance()->setShaderHint(osg::DisplaySettings::SHADER_GL3); + + int tex_width = width; + int tex_height = height; + + int camera_width = tex_width; + int camera_height = tex_height; + + struct TexturePair + { + TexturePair(unsigned int width, unsigned int height, unsigned int rows) + { + color = new osg::Texture2DArray; + color->setTextureSize(width, height, rows); + color->setInternalFormat(GL_RGBA); + color->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); + color->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); + color->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); + color->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); + color->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); + + depth = new osg::Texture2DArray; + depth->setTextureSize(width, height, rows); + depth->setInternalFormat(GL_DEPTH_COMPONENT); + depth->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); + depth->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); + depth->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); + depth->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); + depth->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); + } + + osg::ref_ptr color; + osg::ref_ptr depth; + }; + + typedef std::vector Textures; + Textures textures; + + view.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0); + + osg::ref_ptr ifc = new LeiaIntialFrustumCallback; + + // set up the projection and view matrix uniforms + double delta = 0.2; + for(size_t i=0; i<4; ++i) + { + double y = delta*(static_cast(i)-1.5); + ifc->projectionMatrices.push_back(view.getCamera()->getProjectionMatrix()*osg::Matrixd::translate(-delta*2.0, y, 0.0)); + ifc->projectionMatrices.push_back(view.getCamera()->getProjectionMatrix()*osg::Matrixd::translate(-delta, y, 0.0)); + ifc->projectionMatrices.push_back(view.getCamera()->getProjectionMatrix()*osg::Matrixd::translate(delta, y, 0.0)); + ifc->projectionMatrices.push_back(view.getCamera()->getProjectionMatrix()*osg::Matrixd::translate(delta*2.0, y, 0.0)); + + textures.push_back(TexturePair(tex_width, tex_height, 4)); + } + + ifc->computeClipSpaceBound(*(view.getCamera())); + + view.addEventHandler(new LeiaToggleFrustumHandler(ifc.get())); + + // set up the shaders + osg::ref_ptr multiview_program = new osg::Program(); + { + std::string vsFileName("leia.vert"); + std::string fsFileName("leia.frag"); + + osg::ref_ptr vertexShader = osgDB::readRefShaderFile( osg::Shader::VERTEX, vsFileName) ; + if (vertexShader.get()) multiview_program->addShader( vertexShader.get() ); + + osg::ref_ptr fragmentShader = osgDB::readRefShaderFile( osg::Shader::FRAGMENT, fsFileName) ; + if (fragmentShader.get()) multiview_program->addShader( fragmentShader.get() ); + } + + // left/right eye multiviewOVR camera + for(unsigned int row=0; row camera = new osg::Camera; + camera->setName("multview eye camera"); + camera->setGraphicsContext(gc.get()); + camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); + camera->setDrawBuffer(GL_FRONT); + camera->setReadBuffer(GL_FRONT); + camera->setAllowEventFocus(false); + camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); + + // assign custom frustum callback + camera->setInitialFrustumCallback(ifc.get()); + + // attach the texture and use it as the color buffer, specify that the face is controlled by the multiview extension + camera->attach(osg::Camera::COLOR_BUFFER, texturePair.color, 0, osg::Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER); + camera->attach(osg::Camera::DEPTH_BUFFER, texturePair.depth, 0, osg::Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER); + + view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); + + + // setup state for RTT Camera + osg::StateSet* stateset = camera->getOrCreateStateSet(); + stateset->setAttribute(multiview_program.get(), osg::StateAttribute::ON); + stateset->setDefine("NUM_VIEWS", "4"); + + osg::ref_ptr projectionMatrices_uniform = new osg::Uniform(osg::Uniform::FLOAT_MAT4, "osg_ProjectionMatrices", 4); + stateset->addUniform(projectionMatrices_uniform); + + for(size_t i=0; i<4; ++i) + { + projectionMatrices_uniform->setElement(i, ifc->projectionMatrices[row*4 + i]); + } + } + + + // distortion correction set up. + { + osg::ref_ptr mesh = createLeiaMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f)); + + // new we need to add the texture to the mesh, we do so by creating a + // StateSet to contain the Texture StateAttribute. + osg::StateSet* stateset = mesh->getOrCreateStateSet(); + stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); + + for(size_t row = 0; rowsetTextureAttribute(row, textures[row].color, osg::StateAttribute::ON); + + osg::MakeString uniformName; + uniformName<<"texture_"<addUniform( new osg::Uniform(uniformName.str().c_str(), int(row))); + } + + { + osg::ref_ptr program = new osg::Program(); + stateset->setAttribute(program.get(), osg::StateAttribute::ON); + + osg::MakeString defineValue; + defineValue << width; + stateset->setDefine("WINDOW_WIDTH", defineValue.str()); + + defineValue.clear(); + defineValue << height; + stateset->setDefine("WINDOW_HEIGHT", defineValue.str()); + + std::string vsFileName("leia_interleave.vert"); + std::string fsFileName("leia_interleave.frag"); + + osg::ref_ptr vertexShader = osgDB::readRefShaderFile( osg::Shader::VERTEX, vsFileName) ; + if (vertexShader.get()) program->addShader( vertexShader.get() ); + + osg::ref_ptr fragmentShader = osgDB::readRefShaderFile( osg::Shader::FRAGMENT, fsFileName) ; + if (fragmentShader.get()) program->addShader( fragmentShader.get() ); + + } + + osg::ref_ptr camera = new osg::Camera; + camera->setGraphicsContext(gc.get()); + camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); + camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) ); + camera->setViewport(new osg::Viewport(0, 0, width, height)); + + GLenum window_buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; + camera->setDrawBuffer(window_buffer); + camera->setReadBuffer(window_buffer); + camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); + camera->setAllowEventFocus(true); + camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); + //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); + + camera->setProjectionMatrixAsOrtho2D(0,width,0,height); + camera->setViewMatrix(osg::Matrix::identity()); + + // add subgraph to render + camera->addChild(mesh.get()); + + camera->setName("Row"); + + osgDB::writeNodeFile(*camera, "camera.osgt"); + + view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false); + } + + view.getCamera()->setNearFarRatio(0.0001f); + + if (view.getLightingMode()==osg::View::HEADLIGHT) + { + // set a local light source for headlight to ensure that lighting is consistent across sides of cube. + view.getLight()->setPosition(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); + } +} diff --git a/examples/osgmultiviewOVR/Leia.h b/examples/osgmultiviewOVR/Leia.h new file mode 100644 index 00000000000..c28901a4120 --- /dev/null +++ b/examples/osgmultiviewOVR/Leia.h @@ -0,0 +1,33 @@ +#ifndef OSGVIEWER_Leia +#define OSGVIEWER_Leia 1 + +#include + +/** spherical display using 6 slave cameras rendering the 6 sides of a cube map, and 7th camera doing distortion correction to present on a spherical display.*/ +class Leia : public osgViewer::ViewConfig +{ + public: + + Leia(unsigned int screenNum=0): + _screenNum(screenNum) {} + + Leia(const Leia& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): + ViewConfig(rhs,copyop), + _screenNum(rhs._screenNum) {} + + META_Object(osgViewer, Leia); + + virtual void configure(osgViewer::View& view) const; + + void setScreenNum(unsigned int n) { _screenNum = n; } + unsigned int getScreenNum() const { return _screenNum; } + + protected: + + osg::ref_ptr createTexture2DArray(unsigned int width, unsigned int height, unsigned int depth, GLenum format) const; + osg::ref_ptr createLeiaMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector) const; + + unsigned int _screenNum; +}; + +#endif diff --git a/examples/osgmultiviewOVR/MultiviewOVR.cpp b/examples/osgmultiviewOVR/MultiviewOVR.cpp new file mode 100644 index 00000000000..7749dfc9802 --- /dev/null +++ b/examples/osgmultiviewOVR/MultiviewOVR.cpp @@ -0,0 +1,382 @@ +#include "MultiviewOVR.h" + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace osgViewer; + + +struct CustomIntialFrustumCallback : public osg::CullSettings::InitialFrustumCallback +{ + std::vector projectionOffsets; + std::vector viewOffsets; + + bool applyBB = true; + osg::BoundingBoxd bb; + + void toggle() + { + applyBB = !applyBB; + } + + void computeClipSpaceBound(osg::Camera& camera) + { + osg::Matrixd pmv = camera.getProjectionMatrix() * camera.getViewMatrix(); + + size_t numOffsets = std::min(projectionOffsets.size(), viewOffsets.size()); + + std::vector world_vertices; + world_vertices.reserve(numOffsets*8); + + for(size_t i=0; i cifc; + + bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) + { + if (ea.getHandled()) return false; + + switch(ea.getEventType()) + { + case(osgGA::GUIEventAdapter::KEYUP): + { + if (ea.getKey()=='c') + { + cifc->toggle(); + return true; + } + break; + } + + default: + return false; + } + return false; + } +}; + + +osg::ref_ptr MultiviewOVR::createStereoMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector) const +{ + osg::Vec3d center(0.0,0.0,0.0); + osg::Vec3d eye(0.0,0.0,0.0); + + // create the quad to visualize. + osg::Geometry* geometry = new osg::Geometry(); + + geometry->setSupportsDisplayList(false); + + osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES); + osg::Vec3Array* vertices = new osg::Vec3Array; + osg::Vec3Array* texcoords = new osg::Vec3Array; + osg::Vec4Array* colors = new osg::Vec4Array; + colors->push_back(osg::Vec4(1.0, 1.0, 0.0, 1.0)); + + // left hand side + vertices->push_back(origin); texcoords->push_back(osg::Vec3(0.0f, 0.0f, 0.0f)); + vertices->push_back(origin + widthVector*0.5f); texcoords->push_back(osg::Vec3(1.0f, 0.0f, 0.0f)); + vertices->push_back(origin + widthVector*0.5f +heightVector); texcoords->push_back(osg::Vec3(1.0f, 1.0f, 0.0f)); + vertices->push_back(origin + heightVector); texcoords->push_back(osg::Vec3(0.0f, 1.0f, 0.0f)); + + elements->push_back(0); + elements->push_back(1); + elements->push_back(2); + elements->push_back(2); + elements->push_back(3); + elements->push_back(0); + + // right hand side + vertices->push_back(origin + widthVector*0.5f); texcoords->push_back(osg::Vec3(0.0f, 0.0f, 1.0f)); + vertices->push_back(origin + widthVector); texcoords->push_back(osg::Vec3(1.0f, 0.0f, 1.0f)); + vertices->push_back(origin + widthVector +heightVector); texcoords->push_back(osg::Vec3(1.0f, 1.0f, 1.0f)); + vertices->push_back(origin + widthVector*0.5f + heightVector); texcoords->push_back(osg::Vec3(0.0f, 1.0f, 1.0f)); + + elements->push_back(4); + elements->push_back(5); + elements->push_back(6); + elements->push_back(6); + elements->push_back(7); + elements->push_back(4); + + geometry->setVertexArray(vertices); + geometry->setColorArray(colors, osg::Array::BIND_OVERALL); + geometry->setTexCoordArray(0, texcoords); + geometry->addPrimitiveSet(elements); + + return geometry; +} + +void MultiviewOVR::configure(osgViewer::View& view) const +{ + osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); + if (!wsi) + { + OSG_NOTICE<<"Error, no WindowSystemInterface available, cannot create windows."<getScreenResolution(si, width, height); + + osg::ref_ptr traits = new osg::GraphicsContext::Traits; + traits->hostName = si.hostName; + traits->displayNum = si.displayNum; + traits->screenNum = si.screenNum; + traits->x = 0; + traits->y = 0; + traits->width = width; + traits->height = height; + traits->windowDecoration = false; + traits->doubleBuffer = true; + traits->sharedContext = 0; + + osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); + if (!gc) + { + OSG_NOTICE<<"GraphicsWindow has not been created successfully."<setTextureSize(tex_width, tex_height, 2); + color_texture->setInternalFormat(GL_RGBA); + color_texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); + color_texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); + color_texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); + color_texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); + color_texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); + + osg::Texture2DArray* depth_texture = new osg::Texture2DArray; + + depth_texture->setTextureSize(tex_width, tex_height, 2); + depth_texture->setInternalFormat(GL_DEPTH_COMPONENT); + depth_texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); + depth_texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); + depth_texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); + depth_texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); + depth_texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); + + osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; + GLenum buffer = GL_FRONT; + + + // left/right eye multiviewOVR camera + { + // GL_OVR_multiview2 extensions requires modern versions of GLSL without fixed function fallback + gc->getState()->setUseModelViewAndProjectionUniforms(true); + gc->getState()->setUseVertexAttributeAliasing(true); + //osg::DisplaySettings::instance()->setShaderHint(osg::DisplaySettings::SHADER_GL3); + + osg::ref_ptr camera = new osg::Camera; + camera->setName("multview eye camera"); + camera->setGraphicsContext(gc.get()); + camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); + camera->setDrawBuffer(buffer); + camera->setReadBuffer(buffer); + camera->setAllowEventFocus(false); + + osg::ref_ptr ifc = new CustomIntialFrustumCallback; + + + view.addEventHandler(new ToggleFrustumHandler(ifc.get())); + + // assign custom frustum callback + camera->setInitialFrustumCallback(ifc.get()); + + + // tell the camera to use OpenGL frame buffer object where supported. + camera->setRenderTargetImplementation(renderTargetImplementation); + + // attach the texture and use it as the color buffer, specify that the face is controlled by the multiview extension + camera->attach(osg::Camera::COLOR_BUFFER, color_texture, 0, osg::Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER); + camera->attach(osg::Camera::DEPTH_BUFFER, depth_texture, 0, osg::Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER); + + + view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); + + osg::StateSet* stateset = camera->getOrCreateStateSet(); + { + // set up the projection and view matrix uniforms + ifc->projectionOffsets.push_back(displaySettings->computeLeftEyeProjectionImplementation(osg::Matrixd())); + ifc->viewOffsets.push_back(displaySettings->computeLeftEyeViewImplementation(osg::Matrixd())); + + ifc->projectionOffsets.push_back(displaySettings->computeRightEyeProjectionImplementation(osg::Matrixd())); + ifc->viewOffsets.push_back(displaySettings->computeRightEyeViewImplementation(osg::Matrixd())); + + ifc->computeClipSpaceBound(*camera); + + osg::ref_ptr ovr_viewMatrix_uniform = new osg::Uniform(osg::Uniform::FLOAT_MAT4, "ovr_viewMatrix", ifc->projectionOffsets.size()); + osg::ref_ptr ovr_projectionMatrix_uniform = new osg::Uniform(osg::Uniform::FLOAT_MAT4, "ovr_projectionMatrix", ifc->viewOffsets.size()); + stateset->addUniform(ovr_viewMatrix_uniform); + stateset->addUniform(ovr_projectionMatrix_uniform); + + for(size_t i=0; iprojectionOffsets.size(); ++i) + { + ovr_projectionMatrix_uniform->setElement(i, ifc->projectionOffsets[i]); + } + + for(size_t i=0; iviewOffsets.size(); ++i) + { + ovr_viewMatrix_uniform->setElement(i, ifc->viewOffsets[i]); + } + + // set up the shaders + osg::ref_ptr program = new osg::Program(); + stateset->setAttribute(program.get(), osg::StateAttribute::ON); + + std::string vsFileName("multiviewOVR.vert"); + std::string fsFileName("multiviewOVR.frag"); + + osg::ref_ptr vertexShader = osgDB::readRefShaderFile( osg::Shader::VERTEX, vsFileName) ; + if (vertexShader.get()) program->addShader( vertexShader.get() ); + + osg::ref_ptr fragmentShader = osgDB::readRefShaderFile( osg::Shader::FRAGMENT, fsFileName) ; + if (fragmentShader.get()) program->addShader( fragmentShader.get() ); + } + + } + + view.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0); + + // distortion correction set up. + { + osg::ref_ptr mesh = createStereoMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f)); + + // new we need to add the texture to the mesh, we do so by creating a + // StateSet to contain the Texture StateAttribute. + osg::StateSet* stateset = mesh->getOrCreateStateSet(); + stateset->setTextureAttribute(0, color_texture, osg::StateAttribute::ON); + stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); + + { + osg::ref_ptr program = new osg::Program(); + stateset->setAttribute(program.get(), osg::StateAttribute::ON); + + std::string vsFileName("standard.vert"); + std::string fsFileName("standard.frag"); + + osg::ref_ptr vertexShader = osgDB::readRefShaderFile( osg::Shader::VERTEX, vsFileName) ; + if (vertexShader.get()) program->addShader( vertexShader.get() ); + + osg::ref_ptr fragmentShader = osgDB::readRefShaderFile( osg::Shader::FRAGMENT, fsFileName) ; + if (fragmentShader.get()) program->addShader( fragmentShader.get() ); + } + + osg::ref_ptr camera = new osg::Camera; + camera->setGraphicsContext(gc.get()); + camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); + camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) ); + camera->setViewport(new osg::Viewport(0, 0, width, height)); + + GLenum window_buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; + camera->setDrawBuffer(window_buffer); + camera->setReadBuffer(window_buffer); + camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); + camera->setAllowEventFocus(true); + camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); + //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); + + camera->setProjectionMatrixAsOrtho2D(0,width,0,height); + camera->setViewMatrix(osg::Matrix::identity()); + + // add subgraph to render + camera->addChild(mesh.get()); + + camera->setName("DistortionCorrectionCamera"); + + osgDB::writeNodeFile(*mesh, "mesh.osgt"); + + view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false); + } + + view.getCamera()->setNearFarRatio(0.0001f); + + if (view.getLightingMode()==osg::View::HEADLIGHT) + { + // set a local light source for headlight to ensure that lighting is consistent across sides of cube. + view.getLight()->setPosition(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); + } +} diff --git a/examples/osgmultiviewOVR/MultiviewOVR.h b/examples/osgmultiviewOVR/MultiviewOVR.h new file mode 100644 index 00000000000..59381eaae00 --- /dev/null +++ b/examples/osgmultiviewOVR/MultiviewOVR.h @@ -0,0 +1,32 @@ +#ifndef OSGVIEWER_MultiviewOVR +#define OSGVIEWER_MultiviewOVR 1 + +#include + +/** spherical display using 6 slave cameras rendering the 6 sides of a cube map, and 7th camera doing distortion correction to present on a spherical display.*/ +class MultiviewOVR : public osgViewer::ViewConfig +{ + public: + + MultiviewOVR(unsigned int screenNum=0): + _screenNum(screenNum) {} + + MultiviewOVR(const MultiviewOVR& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): + ViewConfig(rhs,copyop), + _screenNum(rhs._screenNum) {} + + META_Object(osgViewer,MultiviewOVR); + + virtual void configure(osgViewer::View& view) const; + + void setScreenNum(unsigned int n) { _screenNum = n; } + unsigned int getScreenNum() const { return _screenNum; } + + protected: + + osg::ref_ptr createStereoMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector) const; + + unsigned int _screenNum; +}; + +#endif diff --git a/examples/osgmultiviewOVR/StandardStereo.cpp b/examples/osgmultiviewOVR/StandardStereo.cpp new file mode 100644 index 00000000000..b2ec4aaffb9 --- /dev/null +++ b/examples/osgmultiviewOVR/StandardStereo.cpp @@ -0,0 +1,240 @@ +#include "StandardStereo.h" + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace osgViewer; + +osg::ref_ptr StandardStereo::createStereoMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector) const +{ + osg::Vec3d center(0.0,0.0,0.0); + osg::Vec3d eye(0.0,0.0,0.0); + + // create the quad to visualize. + osg::Geometry* geometry = new osg::Geometry(); + + geometry->setSupportsDisplayList(false); + + osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES); + osg::Vec3Array* vertices = new osg::Vec3Array; + osg::Vec3Array* texcoords = new osg::Vec3Array; + osg::Vec4Array* colors = new osg::Vec4Array; + colors->push_back(osg::Vec4(1.0, 1.0, 0.0, 1.0)); + + // left hand side + vertices->push_back(origin); texcoords->push_back(osg::Vec3(0.0f, 0.0f, 0.0f)); + vertices->push_back(origin + widthVector*0.5f); texcoords->push_back(osg::Vec3(1.0f, 0.0f, 0.0f)); + vertices->push_back(origin + widthVector*0.5f +heightVector); texcoords->push_back(osg::Vec3(1.0f, 1.0f, 0.0f)); + vertices->push_back(origin + heightVector); texcoords->push_back(osg::Vec3(0.0f, 1.0f, 0.0f)); + + elements->push_back(0); + elements->push_back(1); + elements->push_back(2); + elements->push_back(2); + elements->push_back(3); + elements->push_back(0); + + // right hand side + vertices->push_back(origin + widthVector*0.5f); texcoords->push_back(osg::Vec3(0.0f, 0.0f, 1.0f)); + vertices->push_back(origin + widthVector); texcoords->push_back(osg::Vec3(1.0f, 0.0f, 1.0f)); + vertices->push_back(origin + widthVector +heightVector); texcoords->push_back(osg::Vec3(1.0f, 1.0f, 1.0f)); + vertices->push_back(origin + widthVector*0.5f + heightVector); texcoords->push_back(osg::Vec3(0.0f, 1.0f, 1.0f)); + + elements->push_back(4); + elements->push_back(5); + elements->push_back(6); + elements->push_back(6); + elements->push_back(7); + elements->push_back(4); + + geometry->setVertexArray(vertices); + geometry->setColorArray(colors, osg::Array::BIND_OVERALL); + geometry->setTexCoordArray(0, texcoords); + geometry->addPrimitiveSet(elements); + + return geometry; +} + +void StandardStereo::configure(osgViewer::View& view) const +{ + osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); + if (!wsi) + { + OSG_NOTICE<<"Error, no WindowSystemInterface available, cannot create windows."<getScreenResolution(si, width, height); + + osg::ref_ptr traits = new osg::GraphicsContext::Traits; + traits->hostName = si.hostName; + traits->displayNum = si.displayNum; + traits->screenNum = si.screenNum; + traits->x = 0; + traits->y = 0; + traits->width = width; + traits->height = height; + traits->windowDecoration = false; + traits->doubleBuffer = true; + traits->sharedContext = 0; + + osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); + if (!gc) + { + OSG_NOTICE<<"GraphicsWindow has not been created successfully."<setTextureSize(tex_width, tex_height, 2); + texture->setInternalFormat(GL_RGBA); + texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); + texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); + texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); + texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); + texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); + + osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; + GLenum buffer = GL_FRONT; + + // left eye + { + osg::ref_ptr camera = new osg::Camera; + camera->setName("Left eye camera"); + camera->setGraphicsContext(gc.get()); + camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); + camera->setDrawBuffer(buffer); + camera->setReadBuffer(buffer); + camera->setAllowEventFocus(false); + + // tell the camera to use OpenGL frame buffer object where supported. + camera->setRenderTargetImplementation(renderTargetImplementation); + + // attach the texture and use it as the color buffer. + camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, 0); + + // set up the projection and view matrices + osg::Matrixd projectionOffset = displaySettings->computeLeftEyeProjectionImplementation(osg::Matrixd()); + osg::Matrixd viewOffset = displaySettings->computeLeftEyeViewImplementation(osg::Matrixd()); + + view.addSlave(camera.get(), projectionOffset, viewOffset); + } + + // right eye + { + osg::ref_ptr camera = new osg::Camera; + camera->setName("Right eyecamera"); + camera->setGraphicsContext(gc.get()); + camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); + camera->setDrawBuffer(buffer); + camera->setReadBuffer(buffer); + camera->setAllowEventFocus(false); + + // tell the camera to use OpenGL frame buffer object where supported. + camera->setRenderTargetImplementation(renderTargetImplementation); + + // attach the texture and use it as the color buffer. + camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, 1); + + // set up the projection and view matrices + osg::Matrixd projectionOffset = displaySettings->computeRightEyeProjectionImplementation(osg::Matrixd()); + osg::Matrixd viewOffset = displaySettings->computeRightEyeViewImplementation(osg::Matrixd()); + + view.addSlave(camera.get(), projectionOffset, viewOffset); + } + + view.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0); + + // distortion correction set up. + { + osg::ref_ptr mesh = createStereoMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f)); + + // new we need to add the texture to the mesh, we do so by creating a + // StateSet to contain the Texture StateAttribute. + osg::StateSet* stateset = mesh->getOrCreateStateSet(); + stateset->setTextureAttribute(0, texture, osg::StateAttribute::ON); + stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); + + { + osg::ref_ptr program = new osg::Program(); + stateset->setAttribute(program.get(), osg::StateAttribute::ON); + + std::string vsFileName("standard.vert"); + std::string fsFileName("standard.frag"); + + osg::ref_ptr vertexShader = osgDB::readRefShaderFile( osg::Shader::VERTEX, vsFileName) ; + if (vertexShader.get()) program->addShader( vertexShader.get() ); + + osg::ref_ptr fragmentShader = osgDB::readRefShaderFile( osg::Shader::FRAGMENT, fsFileName) ; + if (fragmentShader.get()) program->addShader( fragmentShader.get() ); + } + + osg::ref_ptr camera = new osg::Camera; + camera->setGraphicsContext(gc.get()); + camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); + camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) ); + camera->setViewport(new osg::Viewport(0, 0, width, height)); + + GLenum window_buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; + camera->setDrawBuffer(window_buffer); + camera->setReadBuffer(window_buffer); + camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); + camera->setAllowEventFocus(true); + camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); + //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); + + camera->setProjectionMatrixAsOrtho2D(0,width,0,height); + camera->setViewMatrix(osg::Matrix::identity()); + + // add subgraph to render + camera->addChild(mesh.get()); + + camera->setName("DistortionCorrectionCamera"); + + osgDB::writeNodeFile(*mesh, "mesh.osgt"); + + view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false); + } + + view.getCamera()->setNearFarRatio(0.0001f); + + if (view.getLightingMode()==osg::View::HEADLIGHT) + { + // set a local light source for headlight to ensure that lighting is consistent across sides of cube. + view.getLight()->setPosition(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); + } +} diff --git a/examples/osgmultiviewOVR/StandardStereo.h b/examples/osgmultiviewOVR/StandardStereo.h new file mode 100644 index 00000000000..11d92dd2c8a --- /dev/null +++ b/examples/osgmultiviewOVR/StandardStereo.h @@ -0,0 +1,32 @@ +#ifndef OSGVIEWER_StandardStereo +#define OSGVIEWER_StandardStereo 1 + +#include + +/** spherical display using 6 slave cameras rendering the 6 sides of a cube map, and 7th camera doing distortion correction to present on a spherical display.*/ +class StandardStereo : public osgViewer::ViewConfig +{ + public: + + StandardStereo(unsigned int screenNum=0): + _screenNum(screenNum) {} + + StandardStereo(const StandardStereo& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): + ViewConfig(rhs,copyop), + _screenNum(rhs._screenNum) {} + + META_Object(osgViewer,StandardStereo); + + virtual void configure(osgViewer::View& view) const; + + void setScreenNum(unsigned int n) { _screenNum = n; } + unsigned int getScreenNum() const { return _screenNum; } + + protected: + + osg::ref_ptr createStereoMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector) const; + + unsigned int _screenNum; +}; + +#endif diff --git a/examples/osgmultiviewOVR/leia.frag b/examples/osgmultiviewOVR/leia.frag new file mode 100644 index 00000000000..7f4d05d18c0 --- /dev/null +++ b/examples/osgmultiviewOVR/leia.frag @@ -0,0 +1,14 @@ +#version 330 + +uniform sampler2D texture; + +in vec4 color; +in vec2 texcoord; + +out vec4 fragColor; + +void main(void) +{ + fragColor = color * texture2D( texture, texcoord.xy); + if (fragColor.a==0.0) discard; +} diff --git a/examples/osgmultiviewOVR/leia.vert b/examples/osgmultiviewOVR/leia.vert new file mode 100644 index 00000000000..64e90f89397 --- /dev/null +++ b/examples/osgmultiviewOVR/leia.vert @@ -0,0 +1,33 @@ +#version 330 + +#pragma import_defines ( NUM_VIEWS ) + +#ifdef NUM_VIEWS + #extension GL_OVR_multiview2 : enable + + layout(num_views = NUM_VIEWS) in; + + uniform mat4 osg_ProjectionMatrices[NUM_VIEWS]; + #define osg_ProjectionMatrix osg_ProjectionMatrices[gl_ViewID_OVR] +#else + uniform mat4 osg_ProjectionMatrix; +#endif + +uniform mat4 osg_ModelViewMatrix; + +in vec4 osg_Vertex; +in vec4 osg_Color; +in vec4 osg_MultiTexCoord0; + +out vec4 color; +out vec2 texcoord; + +void main(void) +{ + mat4 mvp = osg_ProjectionMatrix * osg_ModelViewMatrix; + + color = osg_Color; + texcoord = osg_MultiTexCoord0.xy; + + gl_Position = mvp * osg_Vertex; +} diff --git a/examples/osgmultiviewOVR/leia_interleave.frag b/examples/osgmultiviewOVR/leia_interleave.frag new file mode 100644 index 00000000000..a425b49a9de --- /dev/null +++ b/examples/osgmultiviewOVR/leia_interleave.frag @@ -0,0 +1,47 @@ +#extension GL_EXT_texture_array : enable + +#pragma import_defines ( WINDOW_WIDTH, WINDOW_HEIGHT, INTERLEAVE ) + +uniform sampler2DArray texture_0; +uniform sampler2DArray texture_1; +uniform sampler2DArray texture_2; +uniform sampler2DArray texture_3; + +varying vec2 texcoord; + +#ifndef WINDOW_WIDTH + #define WINDOW_WIDTH 1920 + #define WINDOW_HEIGHT 1080 +#endif + +#define INTERLEAVE + +void main(void) +{ +#ifdef INTERLEAVE + + float i = mod(gl_FragCoord.x, 4.0); + float j = mod(gl_FragCoord.y, 4.0); + + vec3 tc = vec3(gl_FragCoord.x / WINDOW_WIDTH, gl_FragCoord.y / WINDOW_HEIGHT, i); + + if (j < 1.0) gl_FragColor = texture2DArray( texture_0, tc); + else if (j < 2.0) gl_FragColor = texture2DArray( texture_1, tc); + else if (j < 3.0) gl_FragColor = texture2DArray( texture_2, tc); + else gl_FragColor = texture2DArray( texture_3, tc); + +#else + float cell_width = WINDOW_WIDTH/4.0; + float cell_height = WINDOW_HEIGHT/4.0; + + float i = floor(gl_FragCoord.x / cell_width); + float j = floor(gl_FragCoord.y / cell_height); + + vec3 tc = vec3(gl_FragCoord.x / cell_width - i, gl_FragCoord.y / cell_height - j, i); + + if (j < 1.0) gl_FragColor = texture2DArray( texture_0, tc); + else if (j < 2.0) gl_FragColor = texture2DArray( texture_1, tc); + else if (j < 3.0) gl_FragColor = texture2DArray( texture_2, tc); + else gl_FragColor = texture2DArray( texture_3, tc); +#endif +} diff --git a/examples/osgmultiviewOVR/leia_interleave.vert b/examples/osgmultiviewOVR/leia_interleave.vert new file mode 100644 index 00000000000..2ae4c663591 --- /dev/null +++ b/examples/osgmultiviewOVR/leia_interleave.vert @@ -0,0 +1,7 @@ +varying vec2 texcoord; + +void main(void) +{ + texcoord = gl_MultiTexCoord0.xy; + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; +} diff --git a/examples/osgmultiviewOVR/multiviewOVR.frag b/examples/osgmultiviewOVR/multiviewOVR.frag new file mode 100644 index 00000000000..7f4d05d18c0 --- /dev/null +++ b/examples/osgmultiviewOVR/multiviewOVR.frag @@ -0,0 +1,14 @@ +#version 330 + +uniform sampler2D texture; + +in vec4 color; +in vec2 texcoord; + +out vec4 fragColor; + +void main(void) +{ + fragColor = color * texture2D( texture, texcoord.xy); + if (fragColor.a==0.0) discard; +} diff --git a/examples/osgmultiviewOVR/multiviewOVR.vert b/examples/osgmultiviewOVR/multiviewOVR.vert new file mode 100644 index 00000000000..79e8164dd69 --- /dev/null +++ b/examples/osgmultiviewOVR/multiviewOVR.vert @@ -0,0 +1,29 @@ +#version 330 +#extension GL_OVR_multiview2 : enable + +#define NUM_VIEWS 2 + +layout(num_views = NUM_VIEWS) in; + +uniform mat4 osg_ModelViewMatrix; +uniform mat4 osg_ProjectionMatrix; + +uniform mat4 ovr_projectionMatrix[NUM_VIEWS]; +uniform mat4 ovr_viewMatrix[NUM_VIEWS]; + +in vec4 osg_Vertex; +in vec4 osg_Color; +in vec4 osg_MultiTexCoord0; + +out vec4 color; +out vec2 texcoord; + +void main(void) +{ + mat4 mvp = ovr_projectionMatrix[gl_ViewID_OVR] * osg_ProjectionMatrix * ovr_viewMatrix[gl_ViewID_OVR] * osg_ModelViewMatrix; + + color = osg_Color; + texcoord = osg_MultiTexCoord0.xy; + + gl_Position = mvp * osg_Vertex; +} diff --git a/examples/osgmultiviewOVR/osgmultiviewOVR.cpp b/examples/osgmultiviewOVR/osgmultiviewOVR.cpp new file mode 100644 index 00000000000..a87e9df1f14 --- /dev/null +++ b/examples/osgmultiviewOVR/osgmultiviewOVR.cpp @@ -0,0 +1,64 @@ +// This is public domain software and comes with +// absolutely no warranty. Use of public domain software +// may vary between counties, but in general you are free +// to use and distribute this software for any purpose. + + +// Example: OSG using an OpenGL 3.1 context. +// The comment block at the end of the source describes building OSG +// for use with OpenGL 3.x. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "StandardStereo.h" +#include "MultiviewOVR.h" +#include "Leia.h" + +int main( int argc, char** argv ) +{ + osg::ArgumentParser arguments(&argc, argv); + + osgViewer::Viewer viewer(arguments); + + if (arguments.read("--standard")) + { + viewer.apply(new StandardStereo()); + } + if (arguments.read("--leia")) + { + viewer.apply(new Leia()); + } + else + { + viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); + + viewer.apply(new MultiviewOVR()); + } + + osg::ref_ptr root = osgDB::readRefNodeFiles( arguments ); + if (!root) + { + osg::notify( osg::FATAL ) << "Unable to load model from command line." << std::endl; + return 1; + } + + viewer.setSceneData( root ); + + viewer.addEventHandler(new osgViewer::StatsHandler()); + + + return viewer.run(); +} diff --git a/examples/osgmultiviewOVR/standard.frag b/examples/osgmultiviewOVR/standard.frag new file mode 100644 index 00000000000..d8e1924fd24 --- /dev/null +++ b/examples/osgmultiviewOVR/standard.frag @@ -0,0 +1,9 @@ +#extension GL_EXT_texture_array : enable + +uniform sampler2DArray texture; +varying vec3 texcoord; + +void main(void) +{ + gl_FragColor = texture2DArray( texture, texcoord.xyz); +} diff --git a/examples/osgmultiviewOVR/standard.vert b/examples/osgmultiviewOVR/standard.vert new file mode 100644 index 00000000000..8b1e0892a72 --- /dev/null +++ b/examples/osgmultiviewOVR/standard.vert @@ -0,0 +1,7 @@ +varying vec3 texcoord; + +void main(void) +{ + texcoord = gl_MultiTexCoord0.xyz; + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; +} diff --git a/examples/osgmultiviewpaging/CMakeLists.txt b/examples/osgmultiviewpaging/CMakeLists.txt deleted file mode 100644 index d8d1a8514f0..00000000000 --- a/examples/osgmultiviewpaging/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -SET(TARGET_SRC osgmultiviewpaging.cpp ) - -#### end var setup ### -SETUP_EXAMPLE(osgmultiviewpaging) diff --git a/include/osg/Camera b/include/osg/Camera index b1cfc95dcce..1050ee5e3e7 100644 --- a/include/osg/Camera +++ b/include/osg/Camera @@ -347,6 +347,7 @@ class OSG_EXPORT Camera : public Transform, public CullSettings }; static const unsigned int FACE_CONTROLLED_BY_GEOMETRY_SHADER; + static const unsigned int FACE_CONTROLLED_BY_MULTIVIEW_SHADER; /** Attach a buffer with specified OpenGL internal format.*/ void attach(BufferComponent buffer, GLenum internalFormat); diff --git a/include/osg/CullSettings b/include/osg/CullSettings index c61fe913825..1c3f3a6656a 100644 --- a/include/osg/CullSettings +++ b/include/osg/CullSettings @@ -23,6 +23,7 @@ namespace osg { // forward declare class ArgumentParser; class ApplicationUsage; +class Polytope; class OSG_EXPORT CullSettings { @@ -77,6 +78,7 @@ class OSG_EXPORT CullSettings LIGHT = (0x1 << 16), DRAW_BUFFER = (0x1 << 17), READ_BUFFER = (0x1 << 18), + INITIAL_FRUSTUM_CALLBACK = (0x1 << 19), NO_VARIABLES = 0x00000000, ALL_VARIABLES = 0x7FFFFFFF @@ -243,6 +245,17 @@ class OSG_EXPORT CullSettings const ClampProjectionMatrixCallback* getClampProjectionMatrixCallback() const { return _clampProjectionMatrixCallback.get(); } + /** Callback to override the initial frustum, in clip space, set up at the start of cull traversal prior to projection and view matrices transforming.*/ + struct InitialFrustumCallback : public osg::Referenced + { + virtual void setInitialFrustum(CullStack& cullStack, Polytope& frustum) const = 0; + }; + + void setInitialFrustumCallback(InitialFrustumCallback* ifc) { _initialFrustumCallback = ifc; applyMaskAction(INITIAL_FRUSTUM_CALLBACK); } + InitialFrustumCallback* getInitialFrustumCallback() { return _initialFrustumCallback.get(); } + const InitialFrustumCallback* getInitialFrustumCallback() const { return _initialFrustumCallback.get(); } + + /** Write out internal settings of CullSettings. */ void write(std::ostream& out); @@ -267,7 +280,7 @@ class OSG_EXPORT CullSettings Node::NodeMask _cullMaskLeft; Node::NodeMask _cullMaskRight; - + ref_ptr _initialFrustumCallback; }; template diff --git a/include/osg/FrameBufferObject b/include/osg/FrameBufferObject index 9bcb8e8edf5..fd081d2c2cd 100644 --- a/include/osg/FrameBufferObject +++ b/include/osg/FrameBufferObject @@ -265,6 +265,7 @@ class Texture2D; class Texture2DMultisample; class Texture3D; class Texture2DArray; +class Texture2DMultisampleArray; class TextureCubeMap; class TextureRectangle; @@ -280,6 +281,7 @@ class OSG_EXPORT FrameBufferAttachment explicit FrameBufferAttachment(Texture2DMultisample* target, unsigned int level = 0); explicit FrameBufferAttachment(Texture3D* target, unsigned int zoffset, unsigned int level = 0); explicit FrameBufferAttachment(Texture2DArray* target, unsigned int layer, unsigned int level = 0); + explicit FrameBufferAttachment(Texture2DMultisampleArray* target, unsigned int layer, unsigned int level = 0); explicit FrameBufferAttachment(TextureCubeMap* target, unsigned int face, unsigned int level = 0); explicit FrameBufferAttachment(TextureRectangle* target); explicit FrameBufferAttachment(Camera::Attachment& attachment); @@ -304,6 +306,8 @@ class OSG_EXPORT FrameBufferAttachment unsigned int getTexture3DZOffset() const; unsigned int getTextureArrayLayer() const; + bool isArray() const; + void resizeGLObjectBuffers(unsigned int maxSize); void releaseGLObjects(osg::State* = 0) const; @@ -341,6 +345,7 @@ class OSG_EXPORT FrameBufferObject: public StateAttribute inline const MultipleRenderingTargets& getMultipleRenderingTargets() const { return _drawBuffers; } bool isMultisample() const; + bool isArray() const; int compare(const StateAttribute &sa) const; diff --git a/include/osg/GLExtensions b/include/osg/GLExtensions index 8f047c4ab95..dda2a5ed357 100644 --- a/include/osg/GLExtensions +++ b/include/osg/GLExtensions @@ -691,6 +691,7 @@ class OSG_EXPORT GLExtensions : public osg::Referenced void (GL_APIENTRY * glFramebufferTexture) (GLenum, GLenum, GLint, GLint); void (GL_APIENTRY * glFramebufferTextureLayer) (GLenum, GLenum, GLuint, GLint, GLint); void (GL_APIENTRY * glFramebufferTextureFace)( GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face ); + void (GL_APIENTRY * glFramebufferTextureMultiviewOVR) (GLenum, GLenum, GLenum, GLuint, GLint, GLint); void (GL_APIENTRY * glFramebufferRenderbuffer) (GLenum, GLenum, GLenum, GLuint); void (GL_APIENTRY * glGenerateMipmap) (GLenum); diff --git a/include/osg/Polytope b/include/osg/Polytope index c3dceceb3c9..04a9c35b3a6 100644 --- a/include/osg/Polytope +++ b/include/osg/Polytope @@ -70,15 +70,15 @@ class OSG_EXPORT Polytope } /** Create a Polytope which is a equivalent to BoundingBox.*/ - void setToBoundingBox(const BoundingBox& bb) + void setToBoundingBox(const BoundingBox& bb, bool withNear=true, bool withFar=true) { _planeList.clear(); _planeList.push_back(Plane(1.0,0.0,0.0,-bb.xMin())); // left plane. _planeList.push_back(Plane(-1.0,0.0,0.0,bb.xMax())); // right plane. _planeList.push_back(Plane(0.0,1.0,0.0,-bb.yMin())); // bottom plane. _planeList.push_back(Plane(0.0,-1.0,0.0,bb.yMax())); // top plane. - _planeList.push_back(Plane(0.0,0.0,1.0,-bb.zMin())); // near plane - _planeList.push_back(Plane(0.0,0.0,-1.0,bb.zMax())); // far plane + if (withNear) _planeList.push_back(Plane(0.0,0.0,1.0,-bb.zMin())); // near plane + if (withFar) _planeList.push_back(Plane(0.0,0.0,-1.0,bb.zMax())); // far plane setupMask(); } diff --git a/include/osg/Texture b/include/osg/Texture index f6614633acd..e972db6eb61 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -240,6 +240,10 @@ #define GL_TEXTURE_2D_MULTISAMPLE 0x9100 #endif +#ifndef GL_TEXTURE_2D_MULTISAMPLE_ARRAY + #define GL_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9102 +#endif + // Integer texture extension as in http://www.opengl.org/registry/specs/EXT/texture_integer.txt #ifndef GL_EXT_texture_integer #define GL_RGBA32UI_EXT 0x8D70 @@ -411,6 +415,8 @@ //#define OSG_COLLECT_TEXTURE_APPLIED_STATS 1 +#define OSG_TEXTURE_HAS_SIZED_DEPTH_AND_STENCIL_INTERNAL_FORMATS + namespace osg { diff --git a/include/osg/Texture2DMultisampleArray b/include/osg/Texture2DMultisampleArray new file mode 100644 index 00000000000..983dad4d4f7 --- /dev/null +++ b/include/osg/Texture2DMultisampleArray @@ -0,0 +1,95 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 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_TEXTURE2DMSARRAY +#define OSG_TEXTURE2DMSARRAY 1 + +#include + +namespace osg { + +class OSG_EXPORT Texture2DMultisampleArray : public Texture +{ + public : + + Texture2DMultisampleArray(); + + Texture2DMultisampleArray(GLsizei numSamples, GLboolean fixedsamplelocations); + + Texture2DMultisampleArray(int width, int height, int depth, GLenum internalFormat, GLsizei numSamples, GLboolean fixedsamplelocations); + + /** Copy constructor using CopyOp to manage deep vs shallow copy. */ + Texture2DMultisampleArray(const Texture2DMultisampleArray& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY); + + META_StateAttribute(osg, Texture2DMultisampleArray,TEXTURE); + + /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */ + virtual int compare(const StateAttribute& rhs) const; + + virtual GLenum getTextureTarget() const + { + return GL_TEXTURE_2D_MULTISAMPLE_ARRAY; + } + + /** Texture2DMultisampleArray is related to non fixed pipeline usage only so isn't appropriate to enable/disable.*/ + virtual bool getModeUsage(StateAttribute::ModeUsage&) const { return false; } + + /** Sets the texture width and height. **/ + inline void setTextureSize(int width, int height, int depth) const + { + _textureWidth = width; + _textureHeight = height; + _textureDepth = depth; + } + + inline void setNumSamples( int samples ) { _numSamples = samples; } + GLsizei getNumSamples() const { return _numSamples; } + + // unnecessary for Texture2DMultisampleArray + virtual void setImage(unsigned int /*face*/, Image* /*image*/) {} + virtual Image* getImage(unsigned int /*face*/) { return NULL; } + virtual const Image* getImage(unsigned int /*face*/) const { return NULL; } + virtual unsigned int getNumImages() const {return 0; } + virtual void allocateMipmap(State& /*state*/) const {} + + void setTextureWidth(int width) { _textureWidth=width; } + void setTextureHeight(int height) { _textureHeight=height; } + void setTextureDepth(int depth) { _textureDepth=depth; } + + virtual int getTextureWidth() const { return _textureWidth; } + virtual int getTextureHeight() const { return _textureHeight; } + virtual int getTextureDepth() const { return _textureDepth; } + + /** Bind the texture object. If the texture object hasn't already been + * compiled, create the texture mipmap levels. */ + virtual void apply(State& state) const; + + protected : + + virtual ~Texture2DMultisampleArray(); + + virtual void computeInternalFormat() const; + + /** Subloaded images can have different texture and image sizes. */ + mutable GLsizei _textureWidth, _textureHeight, _textureDepth; + + mutable GLsizei _numSamples; + + mutable GLboolean _fixedsamplelocations; + +}; + +} + +#endif diff --git a/include/osgUtil/RenderStage b/include/osgUtil/RenderStage index 3025ac36b06..04d33cc34e5 100644 --- a/include/osgUtil/RenderStage +++ b/include/osgUtil/RenderStage @@ -167,7 +167,7 @@ class OSGUTIL_EXPORT RenderStage : public RenderBin /** Set a framebuffer object to render into. It is permissible for the * framebuffer object to be multisampled, in which case you should also * set a resolve framebuffer object - see setMultisampleResolveFramebufferObject(). */ - void setFrameBufferObject(osg::FrameBufferObject* fbo) { _fbo = fbo; } + void setFrameBufferObject(osg::FrameBufferObject* fbo); osg::FrameBufferObject* getFrameBufferObject() { return _fbo.get(); } const osg::FrameBufferObject* getFrameBufferObject() const { return _fbo.get(); } @@ -313,6 +313,15 @@ protected: osg::ref_ptr _fbo; osg::ref_ptr _resolveFbo; + + // VRV_PATCH BEGIN + // for resolving individual layers of a multisampled texture 2d array + void runResolveArrayLayersSetup(); + bool _resolveArrayLayersNeedSetup; + std::vector> _arrayLayerFbos; + std::vector> _resolveArrayLayerFbos; + // VRV_PATCH END + osg::ref_ptr _graphicsContext; bool _disableFboAfterRender; diff --git a/src/osg/CMakeLists.txt b/src/osg/CMakeLists.txt index df6f14ad499..9deed7af932 100644 --- a/src/osg/CMakeLists.txt +++ b/src/osg/CMakeLists.txt @@ -182,6 +182,7 @@ SET(TARGET_H ${HEADER_PATH}/Texture2D ${HEADER_PATH}/Texture2DMultisample ${HEADER_PATH}/Texture2DArray + ${HEADER_PATH}/Texture2DMultisampleArray ${HEADER_PATH}/Texture3D ${HEADER_PATH}/TextureBuffer ${HEADER_PATH}/TextureCubeMap @@ -385,6 +386,7 @@ SET(TARGET_SRC TexMat.cpp Texture1D.cpp Texture2DArray.cpp + Texture2DMultisampleArray.cpp Texture2D.cpp Texture2DMultisample.cpp Texture3D.cpp diff --git a/src/osg/Camera.cpp b/src/osg/Camera.cpp index 640efc16556..024a1c22da6 100644 --- a/src/osg/Camera.cpp +++ b/src/osg/Camera.cpp @@ -23,6 +23,7 @@ using namespace osg; const unsigned int Camera::FACE_CONTROLLED_BY_GEOMETRY_SHADER = 0xffffffff; +const unsigned int Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER = 0xfffffff0; Camera::Camera(): _view(0), diff --git a/src/osg/CullSettings.cpp b/src/osg/CullSettings.cpp index 04cf45ad549..0a221890e65 100644 --- a/src/osg/CullSettings.cpp +++ b/src/osg/CullSettings.cpp @@ -70,6 +70,8 @@ void CullSettings::setCullSettings(const CullSettings& rhs) _cullMask = rhs._cullMask; _cullMaskLeft = rhs._cullMaskLeft; _cullMaskRight = rhs._cullMaskRight; + + _initialFrustumCallback = rhs._initialFrustumCallback; } @@ -88,6 +90,7 @@ void CullSettings::inheritCullSettings(const CullSettings& settings, unsigned in if (inheritanceMask & LOD_SCALE) _LODScale = settings._LODScale; if (inheritanceMask & SMALL_FEATURE_CULLING_PIXEL_SIZE) _smallFeatureCullingPixelSize = settings._smallFeatureCullingPixelSize; if (inheritanceMask & CLAMP_PROJECTION_MATRIX_CALLBACK) _clampProjectionMatrixCallback = settings._clampProjectionMatrixCallback; + if (inheritanceMask & INITIAL_FRUSTUM_CALLBACK) _initialFrustumCallback = settings._initialFrustumCallback; } diff --git a/src/osg/CullStack.cpp b/src/osg/CullStack.cpp index a5cad7b98ba..653e3ea3011 100644 --- a/src/osg/CullStack.cpp +++ b/src/osg/CullStack.cpp @@ -162,7 +162,15 @@ void CullStack::pushProjectionMatrix(RefMatrix* matrix) osg::CullingSet& cullingSet = _projectionCullingStack.back(); // set up view frustum. - cullingSet.getFrustum().setToUnitFrustum(((_cullingMode&NEAR_PLANE_CULLING)!=0),((_cullingMode&FAR_PLANE_CULLING)!=0)); + if (_initialFrustumCallback.valid()) + { + _initialFrustumCallback->setInitialFrustum(*this, cullingSet.getFrustum()); + } + else + { + cullingSet.getFrustum().setToUnitFrustum(((_cullingMode&NEAR_PLANE_CULLING)!=0),((_cullingMode&FAR_PLANE_CULLING)!=0)); + } + cullingSet.getFrustum().transformProvidingInverse(*matrix); // set the culling mask ( There should be a more elegant way!) Nikolaus H. diff --git a/src/osg/FrameBufferObject.cpp b/src/osg/FrameBufferObject.cpp index c3988e06743..76f6f6e8735 100644 --- a/src/osg/FrameBufferObject.cpp +++ b/src/osg/FrameBufferObject.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -209,7 +210,8 @@ struct FrameBufferAttachment::Pimpl TEXTURECUBE, TEXTURERECT, TEXTURE2DARRAY, - TEXTURE2DMULTISAMPLE + TEXTURE2DMULTISAMPLE, + TEXTURE2DMULTISAMPLEARRAY }; TargetType targetType; @@ -286,6 +288,13 @@ FrameBufferAttachment::FrameBufferAttachment(Texture2DArray* target, unsigned in _ximpl->zoffset = layer; } +FrameBufferAttachment::FrameBufferAttachment(Texture2DMultisampleArray* target, unsigned int layer, unsigned int level) +{ + _ximpl = new Pimpl(Pimpl::TEXTURE2DMULTISAMPLEARRAY, level); + _ximpl->textureTarget = target; + _ximpl->zoffset = layer; +} + FrameBufferAttachment::FrameBufferAttachment(TextureCubeMap* target, unsigned int face, unsigned int level) { _ximpl = new Pimpl(Pimpl::TEXTURECUBE, level); @@ -347,6 +356,15 @@ FrameBufferAttachment::FrameBufferAttachment(Camera::Attachment& attachment) return; } + osg::Texture2DMultisampleArray* texture2DMSArray = dynamic_cast(texture); + if (texture2DMSArray) + { + _ximpl = new Pimpl(Pimpl::TEXTURE2DMULTISAMPLEARRAY, attachment._level); + _ximpl->textureTarget = texture2DMSArray; + _ximpl->zoffset = attachment._face; + return; + } + osg::TextureCubeMap* textureCubeMap = dynamic_cast(texture); if (textureCubeMap) { @@ -410,6 +428,14 @@ bool FrameBufferAttachment::isMultisample() const { return _ximpl->renderbufferTarget->getSamples() > 0; } + else if(_ximpl->textureTarget.valid()) + { + osg::Texture2DMultisampleArray* tex2DMSArray = dynamic_cast(_ximpl->textureTarget.get()); + if (tex2DMSArray != NULL) + { + return tex2DMSArray->getNumSamples() > 0; + } + } return false; } @@ -492,6 +518,31 @@ void FrameBufferAttachment::attach(State &state, GLenum target, GLenum attachmen case Pimpl::TEXTURE2DARRAY: if (_ximpl->zoffset == Camera::FACE_CONTROLLED_BY_GEOMETRY_SHADER) ext->glFramebufferTexture(target, attachment_point, tobj->id(), _ximpl->level); + else if(_ximpl->zoffset == Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER) + { + if (ext->glFramebufferTextureMultiviewOVR) + { + ext->glFramebufferTextureMultiviewOVR(target, attachment_point, tobj->id(), _ximpl->level, 0, _ximpl->textureTarget->getTextureDepth()); + } + } + else + ext->glFramebufferTextureLayer(target, attachment_point, tobj->id(), _ximpl->level, _ximpl->zoffset); + break; + case Pimpl::TEXTURE2DMULTISAMPLEARRAY: + if (_ximpl->zoffset == Camera::FACE_CONTROLLED_BY_GEOMETRY_SHADER) + { + if (ext->glFramebufferTexture) + { + ext->glFramebufferTexture(target, attachment_point, tobj->id(), _ximpl->level); + } + } + else if (_ximpl->zoffset == Camera::FACE_CONTROLLED_BY_MULTIVIEW_SHADER) + { + if (ext->glFramebufferTextureMultiviewOVR) + { + ext->glFramebufferTextureMultiviewOVR(target, attachment_point, tobj->id(), _ximpl->level, 0, _ximpl->textureTarget->getTextureDepth()); + } + } else ext->glFramebufferTextureLayer(target, attachment_point, tobj->id(), _ximpl->level, _ximpl->zoffset); break; @@ -565,6 +616,11 @@ unsigned int FrameBufferAttachment::getTextureArrayLayer() const return _ximpl->zoffset; } +bool FrameBufferAttachment::isArray() const +{ + return _ximpl->targetType == Pimpl::TEXTURE2DARRAY || _ximpl->targetType == Pimpl::TEXTURE2DMULTISAMPLEARRAY; +} + void FrameBufferAttachment::resizeGLObjectBuffers(unsigned int maxSize) { if (_ximpl->renderbufferTarget.valid()) _ximpl->renderbufferTarget->resizeGLObjectBuffers(maxSize); @@ -800,6 +856,18 @@ bool FrameBufferObject::isMultisample() const return false; } +bool FrameBufferObject::isArray() const +{ + if (_attachments.size()) + { + // If the FBO is correctly set up then all attachments will be either + // arrays or standard types + return _attachments.begin()->second.isArray(); + } + + return false; +} + int FrameBufferObject::compare(const StateAttribute &sa) const { COMPARE_StateAttribute_Types(FrameBufferObject, sa); diff --git a/src/osg/GLExtensions.cpp b/src/osg/GLExtensions.cpp index 5ecf63a5e5f..e8f3eb67d7d 100644 --- a/src/osg/GLExtensions.cpp +++ b/src/osg/GLExtensions.cpp @@ -1119,6 +1119,8 @@ GLExtensions::GLExtensions(unsigned int in_contextID): setGLExtensionFuncPtr(glFramebufferTextureLayer, "glFramebufferTextureLayer", "glFramebufferTextureLayerEXT", "glFramebufferTextureLayerOES", validContext); setGLExtensionFuncPtr(glFramebufferTextureFace, "glFramebufferTextureFace", "glFramebufferTextureFaceEXT", "glFramebufferTextureFaceOES" , validContext); setGLExtensionFuncPtr(glFramebufferRenderbuffer, "glFramebufferRenderbuffer", "glFramebufferRenderbufferEXT", "glFramebufferRenderbufferOES", validContext); + setGLExtensionFuncPtr(glFramebufferTextureMultiviewOVR, "glFramebufferTextureMultiviewOVR", validContext); + //ARB_framebuffer_no_attachments //OpenGL 4.3 setGLExtensionFuncPtr(glFramebufferParameteri, "glFramebufferParameteri", "glFramebufferParameteriARB", "glFramebufferParameteriOES", validContext); diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index d5ef599bcbd..8355bc400b6 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -142,6 +142,7 @@ class TextureGLModeSet _textureModeSet.insert(GL_TEXTURE_RECTANGLE_NV); _textureModeSet.insert(GL_TEXTURE_2D_ARRAY); _textureModeSet.insert(GL_TEXTURE_2D_MULTISAMPLE); + _textureModeSet.insert(GL_TEXTURE_2D_MULTISAMPLE_ARRAY); _textureModeSet.insert(GL_TEXTURE_GEN_Q); _textureModeSet.insert(GL_TEXTURE_GEN_R); diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 2c0bd4b4ebb..4a102e1d3aa 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -54,6 +54,22 @@ #define GL_RGB565 0x8D62 #endif +#ifndef GL_DEPTH32F_STENCIL8 +#define GL_DEPTH32F_STENCIL8 0x8CAD +#endif + +#ifndef GL_FLOAT_32_UNSIGNED_INT_24_8_REV +#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD +#endif + +#ifndef GL_DEPTH24_STENCIL8 +#define GL_DEPTH24_STENCIL8 0x88F0 +#endif + +#ifndef GL_DEPTH_STENCIL_EXT +#define GL_DEPTH_STENCIL_EXT 0x84F9 +#endif + #if 0 #define CHECK_CONSISTENCY checkConsistency(); #else @@ -173,8 +189,8 @@ InternalPixelRelations sizedDepthAndStencilInternalFormats[] = { , { GL_DEPTH_COMPONENT24 , GL_DEPTH_COMPONENT , GL_UNSIGNED_INT } , { GL_DEPTH_COMPONENT32 , GL_DEPTH_COMPONENT , GL_UNSIGNED_INT } , { GL_DEPTH_COMPONENT32F , GL_DEPTH_COMPONENT , GL_FLOAT } - // , { GL_DEPTH24_STENCIL8 , GL_DEPTH_STENCIL , GL_UNSIGNED_INT_24_8 } - // , { GL_DEPTH32F_STENCIL8 , GL_DEPTH_STENCIL , GL_FLOAT_32_UNSIGNED_INT_24_8_REV } + , { GL_DEPTH24_STENCIL8 , GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT } + , { GL_DEPTH32F_STENCIL8 , GL_DEPTH_STENCIL_EXT, GL_FLOAT_32_UNSIGNED_INT_24_8_REV } }; InternalPixelRelations compressedInternalFormats[] = { @@ -236,7 +252,7 @@ InternalPixelRelations compressedInternalFormats[] = { bool isSizedInternalFormat(GLint internalFormat) { - const size_t formatsCount = sizeof(sizedInternalFormats) / sizeof(sizedInternalFormats[0]); + size_t formatsCount = sizeof(sizedInternalFormats) / sizeof(sizedInternalFormats[0]); for (size_t i=0; i < formatsCount; ++i) { @@ -244,6 +260,14 @@ bool isSizedInternalFormat(GLint internalFormat) return true; } + formatsCount = sizeof(sizedDepthAndStencilInternalFormats) / sizeof(sizedDepthAndStencilInternalFormats[0]); + + for (size_t i=0; i < formatsCount; ++i) + { + if((GLenum)internalFormat == sizedDepthAndStencilInternalFormats[i].sizedInternalFormat) + return true; + } + return false; } diff --git a/src/osg/Texture2DArray.cpp b/src/osg/Texture2DArray.cpp index 1ee98df4b4e..bb16976488e 100644 --- a/src/osg/Texture2DArray.cpp +++ b/src/osg/Texture2DArray.cpp @@ -440,26 +440,29 @@ void Texture2DArray::apply(State& state) const // generate texture GLenum texStorageSizedInternalFormat = extensions->isTextureStorageEnabled ? selectSizedInternalFormat() : 0; - textureObject = generateAndAssignTextureObject( - contextID, GL_TEXTURE_2D_ARRAY, _numMipmapLevels, - texStorageSizedInternalFormat!=0 ? texStorageSizedInternalFormat :_internalFormat, - _textureWidth, _textureHeight, _textureDepth, 0); - - textureObject->bind(); - - applyTexParameters(GL_TEXTURE_2D_ARRAY,state); - - if (texStorageSizedInternalFormat!=0 && !textureObject->_allocated) + if (texStorageSizedInternalFormat != 0) { - extensions->glTexStorage3D( GL_TEXTURE_2D_ARRAY, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth); + textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_2D_ARRAY, _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth, 0); + textureObject->bind(); + applyTexParameters(GL_TEXTURE_2D_ARRAY, state); + if (!textureObject->_allocated) + { + extensions->glTexStorage3D(GL_TEXTURE_2D_ARRAY, osg::maximum(_numMipmapLevels, 1), texStorageSizedInternalFormat, + _textureWidth, _textureHeight, _textureDepth); + } } else - extensions->glTexImage3D( GL_TEXTURE_2D_ARRAY, 0, _internalFormat, - _textureWidth, _textureHeight, _textureDepth, - _borderWidth, - _sourceFormat ? _sourceFormat : _internalFormat, - _sourceType ? _sourceType : GL_UNSIGNED_BYTE, - 0); + { + GLenum internalFormat = _sourceFormat ? _sourceFormat : _internalFormat; + textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_2D_ARRAY, _numMipmapLevels, internalFormat, _textureWidth, _textureHeight, _textureDepth, 0); + textureObject->bind(); + applyTexParameters(GL_TEXTURE_2D_ARRAY, state); + extensions->glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, _internalFormat, + _textureWidth, _textureHeight, _textureDepth, _borderWidth, + internalFormat, + _sourceType ? _sourceType : GL_UNSIGNED_BYTE, + 0); + } textureObject->setAllocated(_numMipmapLevels, texStorageSizedInternalFormat!=0 ? texStorageSizedInternalFormat :_internalFormat, _textureWidth, _textureHeight, _textureDepth, 0); } diff --git a/src/osg/Texture2DMultisampleArray.cpp b/src/osg/Texture2DMultisampleArray.cpp new file mode 100644 index 00000000000..35aaa1a1be5 --- /dev/null +++ b/src/osg/Texture2DMultisampleArray.cpp @@ -0,0 +1,156 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 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; + +Texture2DMultisampleArray::Texture2DMultisampleArray(): + _textureWidth(0), + _textureHeight(0), + _textureDepth(0), + _numSamples(1), + _fixedsamplelocations(GL_FALSE) +{ +} + +Texture2DMultisampleArray::Texture2DMultisampleArray(GLsizei numSamples, GLboolean fixedsamplelocations): + _textureWidth(0), + _textureHeight(0), + _textureDepth(0), + _numSamples(numSamples), + _fixedsamplelocations(fixedsamplelocations) +{ +} + +Texture2DMultisampleArray::Texture2DMultisampleArray(int width, int height, int depth, GLenum internalFormat, GLsizei numSamples, GLboolean fixedsamplelocations) : + _textureWidth(width), + _textureHeight(height), + _textureDepth(depth), + _numSamples(numSamples), + _fixedsamplelocations(fixedsamplelocations) +{ + setInternalFormat(internalFormat); +} + +Texture2DMultisampleArray::Texture2DMultisampleArray(const Texture2DMultisampleArray& text,const CopyOp& copyop): + Texture(text,copyop), + _textureWidth(text._textureWidth), + _textureHeight(text._textureHeight), + _textureDepth(text._textureDepth), + _numSamples(text._numSamples), + _fixedsamplelocations(text._fixedsamplelocations) +{ +} + +Texture2DMultisampleArray::~Texture2DMultisampleArray() +{ +} + +int Texture2DMultisampleArray::compare(const StateAttribute& sa) const +{ + // check the types are equal and then create the rhs variable + // used by the COMPARE_StateAttribute_Parameter macros below. + COMPARE_StateAttribute_Types(Texture2DMultisampleArray,sa) + + + int result = compareTexture(rhs); + if (result!=0) return result; + + // compare each parameter in turn against the rhs. + if (_textureWidth != 0 && rhs._textureWidth != 0) + { + COMPARE_StateAttribute_Parameter(_textureWidth) + } + if (_textureHeight != 0 && rhs._textureHeight != 0) + { + COMPARE_StateAttribute_Parameter(_textureHeight) + } + if (_textureDepth != 0 && rhs._textureDepth != 0) + { + COMPARE_StateAttribute_Parameter(_textureDepth) + } + if (_numSamples != 0 && rhs._numSamples != 0) + { + COMPARE_StateAttribute_Parameter(_numSamples) + } + if (_fixedsamplelocations != 0 && rhs._fixedsamplelocations != 0) + { + COMPARE_StateAttribute_Parameter(_fixedsamplelocations) + } + + + return 0; // passed all the above comparison macros, must be equal. +} + +void Texture2DMultisampleArray::apply(State& state) const +{ + // current OpenGL context. + const unsigned int contextID = state.getContextID(); + const GLExtensions* extensions = state.get(); + if (!extensions->isTextureMultisampledSupported) + { + OSG_INFO<<"Texture2DMultisampleArray not supported."<getApplyTime())); + tom->getNumberApplied()++; +#endif + + // get the texture object for the current contextID. + TextureObject* textureObject = getTextureObject(contextID); + + if (textureObject) + { + textureObject->bind(); + } + else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_textureDepth != 0) && (_numSamples!=0) ) + { + textureObject = generateAndAssignTextureObject( + contextID, + getTextureTarget(), + 1, + _internalFormat, + _textureWidth, + _textureHeight, + _textureDepth, + _borderWidth); + + textureObject->bind(); + + extensions->glTexImage3DMultisample( getTextureTarget(), + _numSamples, + _internalFormat, + _textureWidth, + _textureHeight, + _textureDepth, + _fixedsamplelocations ); + } + else + { + glBindTexture( getTextureTarget(), 0 ); + } +} + +void Texture2DMultisampleArray::computeInternalFormat() const +{ + computeInternalFormatType(); +} + diff --git a/src/osgShadow/ParallelSplitShadowMap.cpp b/src/osgShadow/ParallelSplitShadowMap.cpp index e627d8fee63..3c73e9470d9 100644 --- a/src/osgShadow/ParallelSplitShadowMap.cpp +++ b/src/osgShadow/ParallelSplitShadowMap.cpp @@ -609,7 +609,7 @@ void ParallelSplitShadowMap::cull(osgUtil::CullVisitor& cv){ PSSMShadowSplitTextureMap::iterator tm_itr=_PSSMShadowSplitTextureMap.begin(); #else // do traversal of shadow receiving scene which does need to be decorated by the shadow map - for (PSSMShadowSplitTextureMap::iterator tm_itr=_PSSMShadowSplitTextureMap.begin();it!=_PSSMShadowSplitTextureMap.end();it++) + for (PSSMShadowSplitTextureMap::iterator tm_itr=_PSSMShadowSplitTextureMap.begin();tm_itr!=_PSSMShadowSplitTextureMap.end();tm_itr++) #endif { PSSMShadowSplitTexture pssmShadowSplitTexture = tm_itr->second; diff --git a/src/osgUtil/RenderStage.cpp b/src/osgUtil/RenderStage.cpp index f0d23158fad..842d493f1e6 100644 --- a/src/osgUtil/RenderStage.cpp +++ b/src/osgUtil/RenderStage.cpp @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include #include #include @@ -62,6 +64,8 @@ RenderStage::RenderStage(): _imageReadPixelFormat = GL_RGBA; _imageReadPixelDataType = GL_UNSIGNED_BYTE; + + _resolveArrayLayersNeedSetup = false; } RenderStage::RenderStage(SortMode mode): @@ -129,6 +133,69 @@ RenderStage::~RenderStage() { } +void osgUtil::RenderStage::runResolveArrayLayersSetup() +{ + _resolveArrayLayersNeedSetup = false; + + if (!_fbo || !_resolveFbo) return; + + OSG_INFO << "RenderStage::runResolveArrayLayersSetup() " << this << std::endl; + + const osg::FrameBufferObject::AttachmentMap& bufferAttachments = _fbo->getAttachmentMap(); + const osg::FrameBufferObject::AttachmentMap& resolveBufferAttachments = _resolveFbo->getAttachmentMap(); + _resolveArrayLayerFbos.clear(); + _arrayLayerFbos.clear(); + + for (osg::FrameBufferObject::AttachmentMap::const_iterator itr = bufferAttachments.begin(); + itr != bufferAttachments.end(); + ++itr) + { + osg::FrameBufferObject::BufferComponent buffer = itr->first; + if (resolveBufferAttachments.count(buffer) == 0) + continue; + + osg::FrameBufferAttachment msaaAttachment = _fbo->getAttachment(buffer); + osg::FrameBufferAttachment resolveAttachment = _resolveFbo->getAttachment(buffer); + osg::Texture2DMultisampleArray* msaaAttachmentAsTex2dArray = dynamic_cast(msaaAttachment.getTexture()); + osg::Texture2DArray* attachmentAsTex2dArray = dynamic_cast(resolveAttachment.getTexture()); + + int depth = attachmentAsTex2dArray->getTextureDepth(); + + // make a read and draw fbos for each layer so we can resolve later + for (unsigned int i = 0; i < static_cast(depth); i++) + { + osg::ref_ptr layerfbo; + osg::ref_ptr resolvelayerfbo; + + if (static_cast(_arrayLayerFbos.size()) <= i) + { + layerfbo = new osg::FrameBufferObject; + layerfbo->setName(_camera->getName() + "_layer_"); + _arrayLayerFbos.push_back(layerfbo); + } + else + { + layerfbo = _arrayLayerFbos[i]; + } + + if (static_cast(_resolveArrayLayerFbos.size()) <= i) + { + resolvelayerfbo = new osg::FrameBufferObject; + resolvelayerfbo->setName(_camera->getName() + "_resolvelayer_"); + _resolveArrayLayerFbos.push_back(resolvelayerfbo); + } + else + { + resolvelayerfbo = _resolveArrayLayerFbos[i]; + } + + resolvelayerfbo->setAttachment(buffer, osg::FrameBufferAttachment(attachmentAsTex2dArray, i, 0)); + layerfbo->setAttachment(buffer, osg::FrameBufferAttachment(msaaAttachmentAsTex2dArray, i, 0)); + + } + } +} + void RenderStage::reset() { _stageDrawnThisFrame = false; @@ -243,11 +310,14 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) osg::Camera::BufferAttachmentMap& bufferAttachments = _camera->getBufferAttachmentMap(); _bufferAttachmentMap.clear(); + _resolveArrayLayerFbos.clear(); + _arrayLayerFbos.clear(); // compute the required dimensions int width = static_cast(_viewport->x() + _viewport->width()); int height = static_cast(_viewport->y() + _viewport->height()); int depth = 1; + bool isArray = false; for(osg::Camera::BufferAttachmentMap::iterator itr = bufferAttachments.begin(); itr != bufferAttachments.end(); ++itr) @@ -296,6 +366,7 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) osg::Texture3D* texture3D = 0; osg::TextureCubeMap* textureCubeMap = 0; osg::TextureRectangle* textureRectangle = 0; + osg::Texture2DArray* texture2DArray = 0; if (0 != (texture1D=dynamic_cast(texture))) { if (texture1D->getTextureWidth()==0) @@ -339,7 +410,13 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) textureRectangle->setTextureSize(width,height); } } - + else if (0 != (texture2DArray = dynamic_cast(texture))) + { + isArray = true; + //width = texture2DArray->getTextureWidth(); + //height = texture2DArray->getTextureHeight(); + depth = texture2DArray->getTextureDepth(); + } } } @@ -437,10 +514,34 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) break; } } - fbo_multisample->setAttachment(buffer, - osg::FrameBufferAttachment(new osg::RenderBuffer( - width, height, internalFormat, - samples, colorSamples))); + + // VRV_PATCH BEGIN + if(!isArray) + { + fbo_multisample->setAttachment(buffer, + osg::FrameBufferAttachment(new osg::RenderBuffer( + width, height, internalFormat, + samples, colorSamples))); + } + else + { + if(ext->isTextureMultisampledSupported) + { + osg::Texture2DMultisampleArray* multiSampleTexArray = new osg::Texture2DMultisampleArray(width, height, depth, internalFormat, samples, GL_FALSE); + fbo_multisample->setAttachment(buffer, osg::FrameBufferAttachment(multiSampleTexArray, attachment._face, 0)); + + // The default MIN_FILTER is LINEAR_MIPMAP_LINEAR which would cause mipmap generation, which + // does not work for Texture2DMultisampleArray and would throw an error. + multiSampleTexArray->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); + + _resolveArrayLayersNeedSetup = true; + } + else + { + fbo_multisample = NULL; + } + } + // VRV_PATCH END } if (buffer==osg::Camera::DEPTH_BUFFER) depthAttached = true; @@ -540,7 +641,11 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) } else { - setDrawBuffer(GL_NONE, false ); + //OSG_WARN << "Camera '" << _camera->getName() << "' fbo details" << std::endl; + + //dumpFboInfo(fbo); + + setDrawBuffer(GL_NONE, false); setReadBuffer(GL_NONE, false ); _fbo = fbo; @@ -556,6 +661,8 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) "multisample FBO setup failed, FBO status = 0x" << std::hex << status << std::dec << std::endl; + //dumpFboInfo(fbo_multisample); + fbo->apply(state); fbo_multisample = 0; _resolveFbo = 0; @@ -949,6 +1056,8 @@ void RenderStage::drawInner(osg::RenderInfo& renderInfo,RenderLeaf*& previous, b if (fbo_supported && _resolveFbo.valid() && ext->glBlitFramebuffer) { + bool isArray = _resolveFbo->getAttachmentMap().begin()->second.isArray(); // VRV_PATCH + GLbitfield blitMask = 0; bool needToBlitColorBuffers = false; @@ -977,52 +1086,110 @@ void RenderStage::drawInner(osg::RenderInfo& renderInfo,RenderLeaf*& previous, b } } - // Bind the resolve framebuffer to blit into. - _fbo->apply(state, FrameBufferObject::READ_FRAMEBUFFER); - _resolveFbo->apply(state, FrameBufferObject::DRAW_FRAMEBUFFER); - - if (blitMask) + if (!isArray) // VRV_PATCH { - // Blit to the resolve framebuffer. - // Note that (with nvidia 175.16 windows drivers at least) if the read - // framebuffer is multisampled then the dimension arguments are ignored - // and the whole framebuffer is always copied. - ext->glBlitFramebuffer( - static_cast(_viewport->x()), static_cast(_viewport->y()), - static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), - static_cast(_viewport->x()), static_cast(_viewport->y()), - static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), - blitMask, GL_NEAREST); - } -#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GLES3_AVAILABLE) - if (needToBlitColorBuffers) + // Bind the resolve framebuffer to blit into. + _fbo->apply(state, FrameBufferObject::READ_FRAMEBUFFER); + _resolveFbo->apply(state, FrameBufferObject::DRAW_FRAMEBUFFER); + + if (blitMask) + { + // Blit to the resolve framebuffer. + // Note that (with nvidia 175.16 windows drivers at least) if the read + // framebuffer is multisampled then the dimension arguments are ignored + // and the whole framebuffer is always copied. + ext->glBlitFramebuffer( + static_cast(_viewport->x()), static_cast(_viewport->y()), + static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), + static_cast(_viewport->x()), static_cast(_viewport->y()), + static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), + blitMask, GL_NEAREST); + } + +#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) + if (needToBlitColorBuffers) + { + for (FrameBufferObject::AttachmentMap::const_iterator + it = _resolveFbo->getAttachmentMap().begin(), + end =_resolveFbo->getAttachmentMap().end(); it != end; ++it) + { + osg::Camera::BufferComponent attachment = it->first; + if (attachment >= osg::Camera::COLOR_BUFFER0) + { + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + (attachment - osg::Camera::COLOR_BUFFER0)); + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + (attachment - osg::Camera::COLOR_BUFFER0)); + + ext->glBlitFramebuffer( + static_cast(_viewport->x()), static_cast(_viewport->y()), + static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), + static_cast(_viewport->x()), static_cast(_viewport->y()), + static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), + GL_COLOR_BUFFER_BIT, GL_NEAREST); + } + } + // reset the read and draw buffers? will comment out for now with the assumption that + // the buffers will be set explicitly when needed elsewhere. + // glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + // glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + } +#endif + } + else { - for (FrameBufferObject::AttachmentMap::const_iterator - it = _resolveFbo->getAttachmentMap().begin(), - end =_resolveFbo->getAttachmentMap().end(); it != end; ++it) + // VRV_PATCH BEGIN + if (_resolveArrayLayersNeedSetup || _arrayLayerFbos.empty() || _resolveArrayLayerFbos.empty()) + runResolveArrayLayersSetup(); + + for (unsigned int i = 0; i < _resolveArrayLayerFbos.size(); i++) { - osg::Camera::BufferComponent attachment = it->first; - if (attachment >=osg::Camera::COLOR_BUFFER0) + _arrayLayerFbos[i]->apply(state, FrameBufferObject::READ_FRAMEBUFFER); + _resolveArrayLayerFbos[i]->apply(state, FrameBufferObject::DRAW_FRAMEBUFFER); + + if (blitMask) { - state.glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + (attachment - osg::Camera::COLOR_BUFFER0)); - state.glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + (attachment - osg::Camera::COLOR_BUFFER0)); + //_arrayLayerFbos[i]->dirtyAll(); ext->glBlitFramebuffer( static_cast(_viewport->x()), static_cast(_viewport->y()), static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), static_cast(_viewport->x()), static_cast(_viewport->y()), static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), - GL_COLOR_BUFFER_BIT, GL_NEAREST); + blitMask, GL_NEAREST); + } + + +#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) + if (needToBlitColorBuffers) + { + for (FrameBufferObject::AttachmentMap::const_iterator + it = _resolveArrayLayerFbos[i]->getAttachmentMap().begin(), + end = _resolveArrayLayerFbos[i]->getAttachmentMap().end(); it != end; ++it) + { + osg::Camera::BufferComponent attachment = it->first; + if (attachment >= osg::Camera::COLOR_BUFFER0) + { + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + (attachment - osg::Camera::COLOR_BUFFER0)); + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + (attachment - osg::Camera::COLOR_BUFFER0)); + + ext->glBlitFramebuffer( + static_cast(_viewport->x()), static_cast(_viewport->y()), + static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), + static_cast(_viewport->x()), static_cast(_viewport->y()), + static_cast(_viewport->x() + _viewport->width()), static_cast(_viewport->y() + _viewport->height()), + GL_COLOR_BUFFER_BIT, GL_NEAREST); + } + } + // reset the read and draw buffers? will comment out for now with the assumption that + // the buffers will be set explicitly when needed elsewhere. + // glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + // glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); } +#endif } - // reset the read and draw buffers? will comment out for now with the assumption that - // the buffers will be set explicitly when needed elsewhere. - // glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); - // glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + // VRV_PATCH END } -#endif - + apply_read_fbo = true; read_fbo = _resolveFbo.get(); @@ -1482,6 +1649,13 @@ unsigned int RenderStage::computeNumberOfDynamicRenderLeaves() const } +void osgUtil::RenderStage::setFrameBufferObject(osg::FrameBufferObject* fbo) +{ + _fbo = fbo; + if (!_arrayLayerFbos.empty()) + _resolveArrayLayersNeedSetup = true; +} + void RenderStage::setMultisampleResolveFramebufferObject(osg::FrameBufferObject* fbo) { if (fbo && fbo->isMultisample()) @@ -1490,6 +1664,9 @@ void RenderStage::setMultisampleResolveFramebufferObject(osg::FrameBufferObject* " multisampled." << std::endl; } _resolveFbo = fbo; + + if (!_resolveArrayLayerFbos.empty()) + _resolveArrayLayersNeedSetup = true; } void RenderStage::collateReferencesToDependentCameras() diff --git a/src/osgViewer/StatsHandler.cpp b/src/osgViewer/StatsHandler.cpp index c38134f9b12..c9c30ac3205 100644 --- a/src/osgViewer/StatsHandler.cpp +++ b/src/osgViewer/StatsHandler.cpp @@ -434,6 +434,9 @@ void StatsHandler::setWindowSize(int width, int height) if (width <= 0 || height <= 0) return; + _statsWidth = width; + _statsHeight = height; + _camera->setViewport(0, 0, width, height); if (fabs(height*_statsWidth) <= fabs(width*_statsHeight)) {