Merge remote-tracking branch 'upstream/master' into OpenSceneGraph_serializers
This commit is contained in:
39
.travis.yml
39
.travis.yml
@@ -4,6 +4,9 @@ env:
|
||||
# via the "travis encrypt" command using the project repo's public key
|
||||
- secure: "0ROQiFbsZo33ce2v5VjBxNljemh/HU70ntSSPygYwaDFymubts/62SixXVkbKNIFdrs3uYD6qeA/eMmpqXxLcs+PXNq5NrH7eSWw9oDIKMhq3NQH/IZLdRfXwihHimZ1qEs/TXyWlT2aC4rpBi1py3cJeTh1aBMlz4V/nm16iRAgc596ThNTuPDHa0F9/gZnwccI/Rr9VpiYn7vEBbuY9lYr43D0G3NuuQyvvlHShroH09fh6KyFOWIY38AQtnuVGNC1fIiAUk7TUqDqSBwhIrUV5saHbP0kca6DP32REkv//h4JwM76UHv+ntVEoK/UiztJHMkrw71gXYTyvIvlDBpT+IDoeIwUW2QFNQ5zJZI7FM8k0+oeK+F7k/mkffDzr1zww/PQoxqFBF0PoxAni/L9qkA4X2o1A6mRDbe9besp2LQG6Vniwj3bHpCId2QiiMrANVg0EAqkcL2mVFEaqZsh90qCkr1UDq4WQoYbXh0Fy3UnQpbuxDvCME8u03lwuv6ds/SBxc5cgKv7oWXgezaDg7/OCR+0lIAGuLqmNRD8Xw7a0WZGmSbYCHIZmeyFja2KuUvMiVCt8+QsyZr3e523DwBwnSj1BIYFRstMaSEJgu9B8rfTRRllOOKJXCQtdFVuGu8VI6PniSAkI6c535yOWzsuS8HwIkN2ll+Wn7E="
|
||||
|
||||
language: cpp
|
||||
cache: ccache
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
@@ -12,14 +15,13 @@ matrix:
|
||||
dist: trusty
|
||||
language: cpp
|
||||
env:
|
||||
# - CMAKECMD_ARGS="-DBUILD_OSG_EXAMPLES=ON -DBUILD_OSG_PLUGINS_BY_DEFAULT=ON -DBUILD_OSG_APPLICATIONS=ON"
|
||||
- CMAKECMD_ARGS="-DBUILD_OSG_EXAMPLES=OFF -DBUILD_OSG_PLUGINS_BY_DEFAULT=ON -DBUILD_OSG_APPLICATIONS=ON"
|
||||
- CMAKECMD_ARGS="-DBUILD_OSG_EXAMPLES=ON -DBUILD_OSG_PLUGINS_BY_DEFAULT=ON -DBUILD_OSG_APPLICATIONS=ON"
|
||||
# - CMAKECMD_ARGS="-DBUILD_OSG_EXAMPLES=OFF -DBUILD_OSG_PLUGINS_BY_DEFAULT=ON -DBUILD_OSG_APPLICATIONS=ON"
|
||||
#- LLVM_VERSION=3.8
|
||||
sudo: false
|
||||
cache:
|
||||
apt: true
|
||||
directories:
|
||||
- $HOME/.ccache
|
||||
ccache: true
|
||||
compiler:
|
||||
#- clang
|
||||
- gcc
|
||||
@@ -29,8 +31,8 @@ matrix:
|
||||
name: "openscenegraph/OpenSceneGraph"
|
||||
description: "OpenSceneGraph build"
|
||||
notification_email: robert@openscenegraph.com
|
||||
build_command_prepend: "cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_OSG_DEPRECATED_SERIALIZERS=OFF ."
|
||||
build_command: "make -j 3"
|
||||
build_command_prepend: "cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_OSG_DEPRECATED_SERIALIZERS=OFF -DBUILD_OSG_EXAMPLES=OFF ."
|
||||
build_command: "make -j 4"
|
||||
branch_pattern: coverity_scan
|
||||
apt:
|
||||
sources:
|
||||
@@ -43,20 +45,23 @@ matrix:
|
||||
|
||||
# OSX build
|
||||
- os: osx
|
||||
language: cpp
|
||||
before_install:
|
||||
- brew update
|
||||
install:
|
||||
- brew install ccache
|
||||
- export PATH="/usr/local/opt/ccache/libexec:$PATH"
|
||||
env:
|
||||
- CMAKECMD_ARGS="-DBUILD_OSG_EXAMPLES=OFF -DBUILD_OSG_PLUGINS_BY_DEFAULT=ON -DBUILD_OSG_APPLICATIONS=ON"
|
||||
- os: osx
|
||||
language: cpp
|
||||
env:
|
||||
- CMAKECMD_ARGS="-DBUILD_OSG_EXAMPLES=ON -DBUILD_OSG_PLUGINS_BY_DEFAULT=OFF -DBUILD_OSG_APPLICATIONS=OFF"
|
||||
|
||||
# script:
|
||||
# - mkdir build
|
||||
# - cd build
|
||||
# - travis_wait 60 cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../product -DBUILD_OSG_EXAMPLES=ON ..
|
||||
# - make install -j 3
|
||||
- os: osx
|
||||
before_install:
|
||||
- brew update
|
||||
install:
|
||||
- brew install ccache
|
||||
- export PATH="/usr/local/opt/ccache/libexec:$PATH"
|
||||
env:
|
||||
- CMAKECMD_ARGS="-DBUILD_OSG_EXAMPLES=ON -DBUILD_OSG_PLUGINS_BY_DEFAULT=OFF -DBUILD_OSG_APPLICATIONS=OFF -DBUILD_OSG_DEPRECATED_SERIALIZERS=OFF"
|
||||
|
||||
script:
|
||||
- if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then mkdir build && cd build && travis_wait 60 cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../product $CMAKECMD_ARGS ../ ; fi
|
||||
- if [ -f CMakeCache.txt ]; then make -j3 ; fi
|
||||
- if [ -f CMakeCache.txt ]; then make -j4 ; fi
|
||||
|
||||
16
AUTHORS.txt
16
AUTHORS.txt
@@ -1,6 +1,6 @@
|
||||
OpenSceneGraph Library 3.5.7
|
||||
OpenSceneGraph Library 3.5.10
|
||||
|
||||
566 Contributors:
|
||||
568 Contributors:
|
||||
|
||||
Firstname Surname
|
||||
-----------------
|
||||
@@ -9,9 +9,9 @@ Stephan Huber
|
||||
Paul Martz
|
||||
Farshid Lashkari
|
||||
Mathias Fr<46>hlich
|
||||
Laurens Voerman
|
||||
Marco Jez
|
||||
Wang Rui
|
||||
Laurens Voerman
|
||||
Jean-S<>bastien Guay
|
||||
Ulrich Hertlein
|
||||
Mike Weiblen
|
||||
@@ -48,6 +48,7 @@ Magnus Kessler
|
||||
David Fries
|
||||
Tom Jolley
|
||||
Paul Melis
|
||||
Jordi Torres
|
||||
Luc Frauciel
|
||||
Aurelien Albert
|
||||
Torben Dannhauer
|
||||
@@ -94,7 +95,6 @@ Fabien Lavignotte
|
||||
Thomas Hogarth
|
||||
Riccardo Corsi
|
||||
Melchior Franz
|
||||
Jordi Torres
|
||||
Johannes Baeuerle
|
||||
Neil Hughes
|
||||
Martin Beckett
|
||||
@@ -111,6 +111,7 @@ Sondra Iverson
|
||||
Simon Julier
|
||||
Rune Schmidt Jensen
|
||||
Ravi Mathur
|
||||
Ralf Habacker
|
||||
Rainer Oder
|
||||
Nico Kruithof
|
||||
Martin Aumueller
|
||||
@@ -126,7 +127,6 @@ Alexander Sinditskiy
|
||||
Vladimir Chebaev
|
||||
Thibault Genessay
|
||||
Sasa Bistrovic
|
||||
Ralf Habacker
|
||||
Neil Groves
|
||||
Mikhail Izmestev
|
||||
Markus Trenkwalder
|
||||
@@ -145,6 +145,7 @@ Tanguy Fautr
|
||||
Sean Spicer
|
||||
Ryan Kawicki
|
||||
Richard Schmidt
|
||||
Raymond de Vries
|
||||
Peter Hrenka
|
||||
Paul de Repentigny
|
||||
Nikolaus Hanekamp
|
||||
@@ -175,6 +176,7 @@ John Ivar
|
||||
Gustav Haapalahti
|
||||
Erik den Dekker
|
||||
Emmanuel Roche
|
||||
Don Burns
|
||||
Domenico Mangieri
|
||||
Daniel Larimer
|
||||
Colin Dunlop
|
||||
@@ -226,7 +228,6 @@ Fabio Mierlo
|
||||
Doug McCorkle
|
||||
Donald Cipperly
|
||||
Don Leich
|
||||
Don Burns
|
||||
Dietmar Funck
|
||||
Colin Cochran
|
||||
Christian Ruzicka
|
||||
@@ -254,7 +255,6 @@ Stephan Eilemann
|
||||
Stanislav Blinov
|
||||
Sergey Polischuk
|
||||
Roni Zanolli
|
||||
Raymond de Vries
|
||||
Ralf Kern
|
||||
Piotr Gwiazdowski
|
||||
Pierre Haritchabalet
|
||||
@@ -362,6 +362,7 @@ Shuxing Xiao
|
||||
Shane Arnott
|
||||
Sergey Kurdakov
|
||||
Sebastien Kuntz
|
||||
Sandro Mani
|
||||
Ruth Lang
|
||||
Ruben The
|
||||
Ruben Smelik
|
||||
@@ -538,6 +539,7 @@ Christian Noon
|
||||
Christian Kaser
|
||||
Christian Ehrlicher
|
||||
Chris McGlone
|
||||
Chris Djali
|
||||
Carlos Garcea
|
||||
Bryce Eldridge
|
||||
Bruno Herbelin
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
#
|
||||
# OpenSceneGraph CMake build file
|
||||
#
|
||||
SET(OPENSCENEGRAPH_MAJOR_VERSION 3)
|
||||
SET(OPENSCENEGRAPH_MINOR_VERSION 5)
|
||||
SET(OPENSCENEGRAPH_PATCH_VERSION 10)
|
||||
SET(OPENSCENEGRAPH_SOVERSION 153)
|
||||
|
||||
|
||||
# set to 0 when not a release candidate, non zero means that any generated
|
||||
# git tags will be treated as release candidates of given number
|
||||
SET(OPENSCENEGRAPH_RELEASE_CANDIDATE 0)
|
||||
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
|
||||
@@ -113,15 +125,6 @@ ENDIF()
|
||||
|
||||
PROJECT(OpenSceneGraph)
|
||||
|
||||
SET(OPENSCENEGRAPH_MAJOR_VERSION 3)
|
||||
SET(OPENSCENEGRAPH_MINOR_VERSION 5)
|
||||
SET(OPENSCENEGRAPH_PATCH_VERSION 7)
|
||||
SET(OPENSCENEGRAPH_SOVERSION 150)
|
||||
|
||||
# set to 0 when not a release candidate, non zero means that any generated
|
||||
# git tags will be treated as release candidates of given number
|
||||
SET(OPENSCENEGRAPH_RELEASE_CANDIDATE 0)
|
||||
|
||||
SET(OPENSCENEGRAPH_VERSION ${OPENSCENEGRAPH_MAJOR_VERSION}.${OPENSCENEGRAPH_MINOR_VERSION}.${OPENSCENEGRAPH_PATCH_VERSION})
|
||||
|
||||
SET(OSG_PLUGINS osgPlugins-${OPENSCENEGRAPH_VERSION})
|
||||
@@ -341,6 +344,10 @@ ENDIF()
|
||||
|
||||
|
||||
IF(WIN32 AND NOT ANDROID)
|
||||
# Check window version
|
||||
INCLUDE (OsgDetermineWinVersion)
|
||||
get_WIN32_WINNT(WIN_VERSION)
|
||||
ADD_DEFINITIONS(-D_WIN32_WINNT=${WIN_VERSION})
|
||||
|
||||
IF(MSVC)
|
||||
# This option is to enable the /MP switch for Visual Studio 2005 and above compilers
|
||||
@@ -468,6 +475,10 @@ OPTION(OSG_PROVIDE_READFILE "Set to ON for include/osgDB/ReadFile to provide the
|
||||
OPTION(OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION "Set to ON to use the ref_ptr<> T* operator() output conversion. " ON)
|
||||
OPTION(OSG_USE_REF_PTR_SAFE_DEREFERENCE "Set to ON to throw an exception whenever ref_ptr<> is dereferenced or called. " OFF)
|
||||
|
||||
OPTION(OSG_ENVVAR_SUPPORTED "Set to ON to build OpenSceneGraph with the OSG_ENVVAR_SUPPOERTED #define enabled to enable use of getenv() related functions." ON)
|
||||
|
||||
|
||||
|
||||
# Map the OPENGL_PROFILE to OSG_GL*_AVAILABLE settings
|
||||
SET(OPENGL_PROFILE "GL2" CACHE STRING "OpenGL Profile to use, choose from GL1, GL2, GL3, GLES1, GLES2, GLES3")
|
||||
|
||||
@@ -738,6 +749,7 @@ IF(ANDROID)
|
||||
ELSE()
|
||||
# Common to all platforms except android:
|
||||
FIND_PACKAGE(Freetype)
|
||||
FIND_PACKAGE(ilmbase)
|
||||
FIND_PACKAGE(Inventor)
|
||||
FIND_PACKAGE(Jasper)
|
||||
FIND_PACKAGE(OpenEXR)
|
||||
|
||||
@@ -60,9 +60,13 @@ SET(FBX_LIBNAME_DEBUG ${FBX_LIBNAME}d)
|
||||
|
||||
SET( FBX_SEARCH_PATHS
|
||||
$ENV{FBX_DIR}
|
||||
"$ENV{ProgramW6432}/Autodesk/FBX/FBX SDK/2018.1.1"
|
||||
"$ENV{PROGRAMFILES}/Autodesk/FBX/FBX SDK/2018.1.1"
|
||||
"$ENV{ProgramW6432}/Autodesk/FBX/FBX SDK/2017.1"
|
||||
"$ENV{PROGRAMFILES}/Autodesk/FBX/FBX SDK/2017.1"
|
||||
"/Applications/Autodesk/FBX SDK/2017.1"
|
||||
"$ENV{ProgramW6432}/Autodesk/FBX/FBX SDK/2016.1.2"
|
||||
"$ENV{PROGRAMFILES}/Autodesk/FBX/FBX SDK/2016.1.2"
|
||||
"$ENV{ProgramW6432}/Autodesk/FBX/FBX SDK/2016.1.1"
|
||||
"$ENV{PROGRAMFILES}/Autodesk/FBX/FBX SDK/2016.1.1"
|
||||
"$ENV{ProgramW6432}/Autodesk/FBX/FBX SDK/2015.1"
|
||||
|
||||
@@ -94,14 +94,12 @@ macro(FIND_LIBLAS_LIBRARY MYLIBRARY MYLIBRARYNAME)
|
||||
endmacro(FIND_LIBLAS_LIBRARY LIBRARY LIBRARYNAME)
|
||||
|
||||
FIND_LIBLAS_LIBRARY(LIBLAS_LIBRARY las)
|
||||
FIND_LIBLAS_LIBRARY(LIBLASC_LIBRARY las_c)
|
||||
|
||||
set(LIBLAS_FOUND "NO")
|
||||
if(LIBLAS_LIBRARY AND LIBLASC_LIBRARY AND LIBLAS_INCLUDE_DIR)
|
||||
|
||||
if(LIBLAS_LIBRARY AND LIBLAS_INCLUDE_DIR)
|
||||
FIND_PACKAGE(Boost) # used by LIBLAS
|
||||
if(Boost_FOUND)
|
||||
set(LIBLAS_LIBRARIES ${LIBLAS_LIBRARY} ${LIBLASC_LIBRARY} )
|
||||
set(LIBLAS_LIBRARIES ${LIBLAS_LIBRARY} )
|
||||
set(LIBLAS_FOUND "YES")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -28,7 +28,7 @@ FIND_PATH(OPENEXR_INCLUDE_DIR OpenEXR/ImfIO.h
|
||||
# example: OPENEXR_FIND_VAR(OPENEXR_IlmImf_LIBRARY IlmImf)
|
||||
MACRO(OPENEXR_FIND_VAR varname libname)
|
||||
FIND_LIBRARY( ${varname}
|
||||
NAMES ${libname}
|
||||
NAMES ${libname} ${libname}-2_1 ${libname}-2_2
|
||||
PATHS
|
||||
$ENV{OPENEXR_DIR}/lib
|
||||
$ENV{OPENEXR_DIR}
|
||||
@@ -52,13 +52,10 @@ MACRO(OPENEXR_FIND libname)
|
||||
ENDMACRO(OPENEXR_FIND)
|
||||
|
||||
OPENEXR_FIND(IlmImf)
|
||||
OPENEXR_FIND(IlmThread)
|
||||
OPENEXR_FIND(Iex)
|
||||
OPENEXR_FIND(Half)
|
||||
|
||||
SET(OPENEXR_FOUND "NO")
|
||||
IF(OPENEXR_INCLUDE_DIR AND OPENEXR_IlmImf_LIBRARY AND OPENEXR_IlmThread_LIBRARY AND OPENEXR_Iex_LIBRARY AND OPENEXR_Half_LIBRARY)
|
||||
SET(OPENEXR_LIBRARIES ${OPENEXR_IlmImf_LIBRARY} ${OPENEXR_IlmThread_LIBRARY} ${OPENEXR_Half_LIBRARY} ${OPENEXR_Iex_LIBRARY} )
|
||||
SET(OPENEXR_LIBRARIES_VARS OPENEXR_IlmImf_LIBRARY OPENEXR_IlmThread_LIBRARY OPENEXR_Half_LIBRARY OPENEXR_Iex_LIBRARY )
|
||||
IF(OPENEXR_INCLUDE_DIR AND OPENEXR_IlmImf_LIBRARY)
|
||||
SET(OPENEXR_LIBRARIES ${OPENEXR_IlmImf_LIBRARY} )
|
||||
SET(OPENEXR_LIBRARIES_VARS OPENEXR_IlmImf_LIBRARY )
|
||||
SET(OPENEXR_FOUND "YES")
|
||||
ENDIF(OPENEXR_INCLUDE_DIR AND OPENEXR_IlmImf_LIBRARY AND OPENEXR_IlmThread_LIBRARY AND OPENEXR_Iex_LIBRARY AND OPENEXR_Half_LIBRARY)
|
||||
ENDIF(OPENEXR_INCLUDE_DIR AND OPENEXR_IlmImf_LIBRARY)
|
||||
|
||||
63
CMakeModules/Findilmbase.cmake
Normal file
63
CMakeModules/Findilmbase.cmake
Normal file
@@ -0,0 +1,63 @@
|
||||
# Locate ILMBASE
|
||||
# This module defines
|
||||
# ILMBASE_LIBRARY
|
||||
# ILMBASE_FOUND, if false, do not try to link to ILMBASE
|
||||
# ILMBASE_INCLUDE_DIR, where to find the headers
|
||||
#
|
||||
# $ILMBASE_DIR is an environment variable that would
|
||||
# correspond to the ./configure --prefix=$ILMBASE_DIR
|
||||
#
|
||||
# Created by Robert Osfield.
|
||||
|
||||
|
||||
FIND_PATH(ILMBASE_INCLUDE_DIR OpenEXR/ImathVec.h
|
||||
$ENV{ILMBASE_DIR}/include
|
||||
$ENV{ILMBASE_DIR}
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local/include
|
||||
/usr/include
|
||||
/sw/include # Fink
|
||||
/opt/local/include # DarwinPorts
|
||||
/opt/csw/include # Blastwave
|
||||
/opt/include
|
||||
/usr/freeware/include
|
||||
)
|
||||
|
||||
# Macro to find ilmbase libraries
|
||||
# example: ILMBASE_FIND_VAR(OPENEXR_IlmThread_LIBRARY IlmThread)
|
||||
MACRO(ILMBASE_FIND_VAR varname libname)
|
||||
FIND_LIBRARY( ${varname}
|
||||
NAMES ${libname} ${libname}-2_1 ${libname}-2_2
|
||||
PATHS
|
||||
$ENV{ILMBASE_DIR}/lib
|
||||
$ENV{ILMBASE_DIR}
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local/lib
|
||||
/usr/lib
|
||||
/sw/lib
|
||||
/opt/local/lib
|
||||
/opt/csw/lib
|
||||
/opt/lib
|
||||
/usr/freeware/lib64
|
||||
)
|
||||
ENDMACRO(ILMBASE_FIND_VAR)
|
||||
|
||||
# Macro to find exr libraries (and debug versions)
|
||||
# example: ILMBASE_FIND(OPENEXR_IlmThread_LIBRARY IlmThread)
|
||||
MACRO(ILMBASE_FIND libname)
|
||||
ILMBASE_FIND_VAR(ILMBASE_${libname}_LIBRARY ${libname})
|
||||
ILMBASE_FIND_VAR(ILMBASE_${libname}_LIBRARY_DEBUG ${libname}d)
|
||||
ENDMACRO(ILMBASE_FIND)
|
||||
|
||||
ILMBASE_FIND(IlmThread)
|
||||
ILMBASE_FIND(Iex)
|
||||
ILMBASE_FIND(Half)
|
||||
|
||||
SET(ILMBASE_FOUND "NO")
|
||||
IF(ILMBASE_INCLUDE_DIR AND ILMBASE_IlmThread_LIBRARY AND ILMBASE_Iex_LIBRARY AND ILMBASE_Half_LIBRARY)
|
||||
SET(ILMBASE_LIBRARIES ${ILMBASE_IlmThread_LIBRARY} ${ILMBASE_Half_LIBRARY} ${ILMBASE_Iex_LIBRARY} )
|
||||
SET(ILMBASE_LIBRARIES_VARS ILMBASE_IlmThread_LIBRARY ILMBASE_Half_LIBRARY ILMBASE_Iex_LIBRARY )
|
||||
SET(ILMBASE_FOUND "YES")
|
||||
ENDIF(ILMBASE_INCLUDE_DIR AND ILMBASE_IlmThread_LIBRARY AND ILMBASE_Iex_LIBRARY AND ILMBASE_Half_LIBRARY)
|
||||
22
CMakeModules/OsgDetermineWinVersion.cmake
Normal file
22
CMakeModules/OsgDetermineWinVersion.cmake
Normal file
@@ -0,0 +1,22 @@
|
||||
# - If Windows is used, this script sets the variable WIN32_WINNT to the corresponding windows version
|
||||
|
||||
if (WIN32)
|
||||
message(STATUS "Checking windows version...")
|
||||
macro(get_WIN32_WINNT version)
|
||||
if (CMAKE_SYSTEM_VERSION)
|
||||
set(ver ${CMAKE_SYSTEM_VERSION})
|
||||
string(REGEX MATCH "^([0-9]+).([0-9])" ver ${ver})
|
||||
string(REGEX MATCH "^([0-9]+)" verMajor ${ver})
|
||||
# Check for Windows 10, b/c we'll need to convert to hex 'A'.
|
||||
if ("${verMajor}" MATCHES "10")
|
||||
set(verMajor "A")
|
||||
string(REGEX REPLACE "^([0-9]+)" ${verMajor} ver ${ver})
|
||||
endif ("${verMajor}" MATCHES "10")
|
||||
# Remove all remaining '.' characters.
|
||||
string(REPLACE "." "" ver ${ver})
|
||||
# Prepend each digit with a zero.
|
||||
string(REGEX REPLACE "([0-9A-Z])" "0\\1" ver ${ver})
|
||||
set(${version} "0x${ver}")
|
||||
endif(CMAKE_SYSTEM_VERSION)
|
||||
endmacro(get_WIN32_WINNT)
|
||||
endif(WIN32)
|
||||
@@ -740,7 +740,7 @@ int main( int argc, char **argv )
|
||||
while(arguments.read("--addMissingColours") || arguments.read("--addMissingColors")) { addMissingColours = true; }
|
||||
|
||||
bool do_overallNormal = false;
|
||||
while(arguments.read("--overallNormal") || arguments.read("--overallNormal")) { do_overallNormal = true; }
|
||||
while(arguments.read("--overallNormal")) { do_overallNormal = true; }
|
||||
|
||||
bool enableObjectCache = false;
|
||||
while(arguments.read("--enable-object-cache")) { enableObjectCache = true; }
|
||||
|
||||
@@ -275,7 +275,12 @@ const char* invalidNames[] =
|
||||
"I",
|
||||
"TriangleFunctor",
|
||||
"PrimitiveFunctor",
|
||||
"OpenMW"
|
||||
"OpenMW",
|
||||
"StreamOperator",
|
||||
"SceneLoader",
|
||||
"OpenGL",
|
||||
"FindLIBLAS",
|
||||
"MinGW"
|
||||
};
|
||||
|
||||
|
||||
@@ -699,7 +704,9 @@ NameCorrection nameCorrections[] =
|
||||
{"WeSee", "",
|
||||
"Alois", "Wismer"},
|
||||
{"We", "See",
|
||||
"Alois", "Wismer"}
|
||||
"Alois", "Wismer"},
|
||||
{"AnyOldName3", "",
|
||||
"Chris", "Djali"}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -74,14 +74,10 @@ int main(int argc, char** argv)
|
||||
std::string url, username, password;
|
||||
while(arguments.read("--login",url, username, password))
|
||||
{
|
||||
if (!osgDB::Registry::instance()->getAuthenticationMap())
|
||||
{
|
||||
osgDB::Registry::instance()->setAuthenticationMap(new osgDB::AuthenticationMap);
|
||||
osgDB::Registry::instance()->getAuthenticationMap()->addAuthenticationDetails(
|
||||
url,
|
||||
new osgDB::AuthenticationDetails(username, password)
|
||||
);
|
||||
}
|
||||
osgDB::Registry::instance()->getOrCreateAuthenticationMap()->addAuthenticationDetails(
|
||||
url,
|
||||
new osgDB::AuthenticationDetails(username, password)
|
||||
);
|
||||
}
|
||||
|
||||
std::string device;
|
||||
|
||||
@@ -256,7 +256,7 @@ osg::ref_ptr<osg::Node> p3d::readShowFiles(osg::ArgumentParser& arguments,const
|
||||
nodeList.push_back(node);
|
||||
|
||||
// make sure that this presentation isn't cached
|
||||
osgDB::Registry::instance()->removeFromObjectCache( arguments[pos] );
|
||||
osgDB::Registry::instance()->removeFromObjectCache( arguments[pos], local_options.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,14 +336,10 @@ int main( int argc, char **argv )
|
||||
std::string url, username, password;
|
||||
while(arguments.read("--login",url, username, password))
|
||||
{
|
||||
if (!osgDB::Registry::instance()->getAuthenticationMap())
|
||||
{
|
||||
osgDB::Registry::instance()->setAuthenticationMap(new osgDB::AuthenticationMap);
|
||||
osgDB::Registry::instance()->getAuthenticationMap()->addAuthenticationDetails(
|
||||
url,
|
||||
new osgDB::AuthenticationDetails(username, password)
|
||||
);
|
||||
}
|
||||
osgDB::Registry::instance()->getOrCreateAuthenticationMap()->addAuthenticationDetails(
|
||||
url,
|
||||
new osgDB::AuthenticationDetails(username, password)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ void OsgMainApp::loadModels(){
|
||||
newModel = _vModelsToLoad[i];
|
||||
osg::notify(osg::ALWAYS)<<"Loading: "<<newModel.filename<<std::endl;
|
||||
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile(newModel.filename);
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFile(newModel.filename);
|
||||
if (loadedModel == 0) {
|
||||
osg::notify(osg::ALWAYS)<<"Model not loaded"<<std::endl;
|
||||
} else {
|
||||
|
||||
@@ -23,7 +23,7 @@ void OsgMainApp::loadModels(){
|
||||
newModel = _vModelsToLoad[i];
|
||||
osg::notify(osg::ALWAYS)<<"Loading: "<<newModel.filename<<std::endl;
|
||||
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile(newModel.filename);
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFile(newModel.filename);
|
||||
if (loadedModel == 0) {
|
||||
osg::notify(osg::ALWAYS)<<"Model not loaded"<<std::endl;
|
||||
} else {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <osg/StateAttributeCallback>
|
||||
#include <osg/Texture2D>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Geode>
|
||||
#include <osg/ComputeDispatch>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgGA/StateSetManipulator>
|
||||
#include <osgViewer/Viewer>
|
||||
@@ -167,6 +167,7 @@ class ComputeNode : public osg::PositionAttitudeTransform
|
||||
|
||||
public:
|
||||
|
||||
osg::ref_ptr<osg::ComputeDispatch> _computeDispatch;
|
||||
osg::ref_ptr<osg::Program> _computeProgram;
|
||||
osg::ref_ptr<osg::Shader> _computeShader; //compute and write position data in SSBO
|
||||
|
||||
@@ -200,15 +201,12 @@ public:
|
||||
|
||||
ComputeNode()
|
||||
{
|
||||
const char* envOsgFilePath = getenv("OSG_FILE_PATH");
|
||||
std::stringstream computeshaderpath; computeshaderpath << envOsgFilePath << "/shaders/osgssboComputeShader.cs";
|
||||
_computeShaderSourcePath = computeshaderpath.str();
|
||||
std::stringstream vertexshaderpath; vertexshaderpath << envOsgFilePath << "/shaders/osgssboVertexShader.vs";
|
||||
_vertexShaderSourcePath = vertexshaderpath.str();
|
||||
std::stringstream geometryshaderpath; geometryshaderpath << envOsgFilePath << "/shaders/osgssboGeometryShader.gs";
|
||||
_geometryShaderSourcePath = geometryshaderpath.str();
|
||||
std::stringstream fragmentshaderpath; fragmentshaderpath << envOsgFilePath << "/shaders/osgssboFragmentShader.fs";
|
||||
_fragmentShaderSourcePath = fragmentshaderpath.str();
|
||||
_computeShaderSourcePath = "shaders/osgssboComputeShader.cs";
|
||||
_vertexShaderSourcePath = "shaders/osgssboVertexShader.vs";
|
||||
_geometryShaderSourcePath = "shaders/osgssboGeometryShader.gs";
|
||||
_fragmentShaderSourcePath = "shaders/osgssboFragmentShader.fs";
|
||||
_computeDispatch=new osg::ComputeDispatch();
|
||||
addChild(_computeDispatch);
|
||||
}
|
||||
|
||||
};
|
||||
@@ -243,7 +241,7 @@ public:
|
||||
if (_computeNode->_computeShader.valid())
|
||||
{
|
||||
runningSource = _computeNode->_computeShader->getShaderSource();
|
||||
reloadedshader = osg::Shader::readShaderFile(osg::Shader::COMPUTE, _computeNode->_computeShaderSourcePath);
|
||||
reloadedshader = osgDB::readRefShaderFile(osg::Shader::COMPUTE, _computeNode->_computeShaderSourcePath);
|
||||
|
||||
reloadedstring = reloadedshader->getShaderSource();
|
||||
if (!osgDB::equalCaseInsensitive(runningSource.c_str(), reloadedstring.c_str()))
|
||||
@@ -258,7 +256,7 @@ public:
|
||||
{
|
||||
|
||||
runningSource = _computeNode->_vertexShader->getShaderSource();
|
||||
reloadedshader = osg::Shader::readShaderFile(osg::Shader::VERTEX, _computeNode->_vertexShaderSourcePath);
|
||||
reloadedshader = osgDB::readRefShaderFile(osg::Shader::VERTEX, _computeNode->_vertexShaderSourcePath);
|
||||
|
||||
reloadedstring = reloadedshader->getShaderSource();
|
||||
if (!osgDB::equalCaseInsensitive(runningSource.c_str(), reloadedstring.c_str()))
|
||||
@@ -274,7 +272,7 @@ public:
|
||||
if (_computeNode->_geometryShader.valid())
|
||||
{
|
||||
runningSource = _computeNode->_geometryShader->getShaderSource();
|
||||
reloadedshader = osg::Shader::readShaderFile(osg::Shader::GEOMETRY, _computeNode->_geometryShaderSourcePath);
|
||||
reloadedshader = osgDB::readRefShaderFile(osg::Shader::GEOMETRY, _computeNode->_geometryShaderSourcePath);
|
||||
|
||||
reloadedstring = reloadedshader->getShaderSource();
|
||||
if (!osgDB::equalCaseInsensitive(runningSource.c_str(), reloadedstring.c_str()))
|
||||
@@ -288,7 +286,7 @@ public:
|
||||
if (_computeNode->_fragmentShader.valid())
|
||||
{
|
||||
runningSource = _computeNode->_fragmentShader->getShaderSource();
|
||||
reloadedshader = osg::Shader::readShaderFile(osg::Shader::FRAGMENT, _computeNode->_fragmentShaderSourcePath);
|
||||
reloadedshader = osgDB::readRefShaderFile(osg::Shader::FRAGMENT, _computeNode->_fragmentShaderSourcePath);
|
||||
|
||||
reloadedstring = reloadedshader->getShaderSource();
|
||||
if (!osgDB::equalCaseInsensitive(runningSource.c_str(), reloadedstring.c_str()))
|
||||
@@ -473,7 +471,6 @@ void ComputeNode::addDataMonitor(osg::Vec3 placement, osg::Vec3 relativePlacemen
|
||||
pat->setName(labelCaption);
|
||||
text->setText(pat->getName());
|
||||
text->setBackdropType(osgText::Text::OUTLINE);
|
||||
text->setBackdropImplementation(osgText::Text::POLYGON_OFFSET);
|
||||
text->setBackdropOffset(0.05f);
|
||||
text->setBackdropColor(osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
|
||||
@@ -518,13 +515,13 @@ void ComputeNode::addComputationResultsRenderTree()
|
||||
|
||||
_computationResultsRenderProgram = new osg::Program;
|
||||
|
||||
_vertexShader = osg::Shader::readShaderFile(osg::Shader::VERTEX, _vertexShaderSourcePath);
|
||||
_vertexShader = osgDB::readRefShaderFile(osg::Shader::VERTEX, _vertexShaderSourcePath);
|
||||
_computationResultsRenderProgram->addShader(_vertexShader.get());
|
||||
|
||||
_geometryShader = osg::Shader::readShaderFile(osg::Shader::GEOMETRY, _geometryShaderSourcePath);
|
||||
_geometryShader = osgDB::readRefShaderFile(osg::Shader::GEOMETRY, _geometryShaderSourcePath);
|
||||
_computationResultsRenderProgram->addShader(_geometryShader.get());
|
||||
|
||||
_fragmentShader = osg::Shader::readShaderFile(osg::Shader::FRAGMENT, _fragmentShaderSourcePath);
|
||||
_fragmentShader = osgDB::readRefShaderFile(osg::Shader::FRAGMENT, _fragmentShaderSourcePath);
|
||||
_computationResultsRenderProgram->addShader(_fragmentShader.get());
|
||||
|
||||
|
||||
@@ -628,8 +625,8 @@ void ComputeNode::initComputingSetup()
|
||||
{
|
||||
|
||||
_computeProgram = new osg::Program;
|
||||
_computeProgram->setComputeGroups((NUM_ELEMENTS_X / WORK_GROUP_SIZE) <= 1 ? 1 : (NUM_ELEMENTS_X / WORK_GROUP_SIZE), (NUM_ELEMENTS_Y / WORK_GROUP_SIZE) <= 1 ? 1 : (NUM_ELEMENTS_Y / WORK_GROUP_SIZE), 1);
|
||||
_computeShader = osg::Shader::readShaderFile(osg::Shader::COMPUTE, _computeShaderSourcePath);
|
||||
_computeDispatch->setComputeGroups((NUM_ELEMENTS_X / WORK_GROUP_SIZE) <= 1 ? 1 : (NUM_ELEMENTS_X / WORK_GROUP_SIZE), (NUM_ELEMENTS_Y / WORK_GROUP_SIZE) <= 1 ? 1 : (NUM_ELEMENTS_Y / WORK_GROUP_SIZE), 1);
|
||||
_computeShader = osgDB::readRefShaderFile(osg::Shader::COMPUTE, _computeShaderSourcePath);
|
||||
_computeProgram->addShader(_computeShader.get());
|
||||
|
||||
setDataVariance(osg::Object::DYNAMIC);
|
||||
@@ -773,7 +770,7 @@ void ComputeNode::initComputingSetup()
|
||||
_dataArray->setBufferObject(_ssbo.get());
|
||||
|
||||
|
||||
_ssbb = new osg::ShaderStorageBufferBinding(0, _dataArray, 0, blockSize);
|
||||
_ssbb = new osg::ShaderStorageBufferBinding(0, _dataArray.get(), 0, blockSize);
|
||||
statesetComputation->setAttributeAndModes(_ssbb.get(), osg::StateAttribute::ON);
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include <osgAnimation/BasicAnimationManager>
|
||||
#include <osgAnimation/RigGeometry>
|
||||
#include <osgAnimation/RigTransformHardware>
|
||||
#include <osgAnimation/MorphGeometry>
|
||||
#include <osgAnimation/MorphTransformHardware>
|
||||
#include <osgAnimation/AnimationManagerBase>
|
||||
#include <osgAnimation/BoneMapVisitor>
|
||||
|
||||
@@ -40,89 +42,100 @@ static unsigned int getRandomValueinRange(unsigned int v)
|
||||
}
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Program> program;
|
||||
osg::ref_ptr<osg::Program> CommonProgram;
|
||||
// show how to override the default RigTransformHardware for customized usage
|
||||
struct MyRigTransformHardware : public osgAnimation::RigTransformHardware
|
||||
{
|
||||
|
||||
void operator()(osgAnimation::RigGeometry& geom)
|
||||
int _maxmatrix;
|
||||
MyRigTransformHardware() : _maxmatrix(99){}
|
||||
virtual bool init(osgAnimation::RigGeometry& rig)
|
||||
{
|
||||
if (_needInit)
|
||||
if (!init(geom))
|
||||
return;
|
||||
computeMatrixPaletteUniform(geom.getMatrixFromSkeletonToGeometry(), geom.getInvMatrixFromSkeletonToGeometry());
|
||||
}
|
||||
|
||||
bool init(osgAnimation::RigGeometry& geom)
|
||||
{
|
||||
osg::Vec3Array* pos = dynamic_cast<osg::Vec3Array*>(geom.getVertexArray());
|
||||
if (!pos) {
|
||||
osg::notify(osg::WARN) << "RigTransformHardware no vertex array in the geometry " << geom.getName() << std::endl;
|
||||
if(_perVertexInfluences.empty())
|
||||
{
|
||||
prepareData(rig);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!geom.getSkeleton()) {
|
||||
osg::notify(osg::WARN) << "RigTransformHardware no skeleting set in geometry " << geom.getName() << std::endl;
|
||||
if(!rig.getSkeleton())
|
||||
return false;
|
||||
}
|
||||
|
||||
osgAnimation::BoneMapVisitor mapVisitor;
|
||||
geom.getSkeleton()->accept(mapVisitor);
|
||||
osgAnimation::BoneMap bm = mapVisitor.getBoneMap();
|
||||
rig.getSkeleton()->accept(mapVisitor);
|
||||
osgAnimation::BoneMap boneMap = mapVisitor.getBoneMap();
|
||||
|
||||
if (!createPalette(pos->size(),bm, geom.getVertexInfluenceSet().getVertexToBoneList()))
|
||||
if (!buildPalette(boneMap,rig) )
|
||||
return false;
|
||||
|
||||
int attribIndex = 11;
|
||||
int nbAttribs = getNumVertexAttrib();
|
||||
osg::Geometry& source = *rig.getSourceGeometry();
|
||||
osg::Vec3Array* positionSrc = dynamic_cast<osg::Vec3Array*>(source.getVertexArray());
|
||||
|
||||
// use a global program for all avatar
|
||||
if (!program.valid()) {
|
||||
program = new osg::Program;
|
||||
program->setName("HardwareSkinning");
|
||||
if (!_shader.valid())
|
||||
_shader = osg::Shader::readShaderFile(osg::Shader::VERTEX,"shaders/skinning.vert");
|
||||
if (!positionSrc)
|
||||
{
|
||||
OSG_WARN << "RigTransformHardware no vertex array in the geometry " << rig.getName() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_shader.valid()) {
|
||||
osg::notify(osg::WARN) << "RigTransformHardware can't load VertexShader" << std::endl;
|
||||
// copy shallow from source geometry to rig
|
||||
rig.copyFrom(source);
|
||||
|
||||
osg::ref_ptr<osg::Shader> vertexshader;
|
||||
osg::ref_ptr<osg::StateSet> stateset = rig.getOrCreateStateSet();
|
||||
if(!CommonProgram.valid())
|
||||
{
|
||||
CommonProgram = new osg::Program;
|
||||
CommonProgram->setName("HardwareSkinning");
|
||||
|
||||
//set default source if _shader is not user setted
|
||||
if (!vertexshader.valid())
|
||||
{
|
||||
vertexshader = osgDB::readRefShaderFile(osg::Shader::VERTEX,"skinning.vert");
|
||||
}
|
||||
|
||||
if (!vertexshader.valid())
|
||||
{
|
||||
OSG_WARN << "RigTransformHardware can't load VertexShader" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// replace max matrix by the value from uniform
|
||||
{
|
||||
std::string str = _shader->getShaderSource();
|
||||
std::string str = vertexshader->getShaderSource();
|
||||
std::string toreplace = std::string("MAX_MATRIX");
|
||||
std::size_t start = str.find(toreplace);
|
||||
std::stringstream ss;
|
||||
ss << getMatrixPaletteUniform()->getNumElements();
|
||||
str.replace(start, toreplace.size(), ss.str());
|
||||
_shader->setShaderSource(str);
|
||||
osg::notify(osg::INFO) << "Shader " << str << std::endl;
|
||||
}
|
||||
|
||||
program->addShader(_shader.get());
|
||||
|
||||
for (int i = 0; i < nbAttribs; i++)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "boneWeight" << i;
|
||||
program->addBindAttribLocation(ss.str(), attribIndex + i);
|
||||
|
||||
osg::notify(osg::INFO) << "set vertex attrib " << ss.str() << std::endl;
|
||||
if (std::string::npos != start)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << _maxmatrix;//getMatrixPaletteUniform()->getNumElements();
|
||||
str.replace(start, toreplace.size(), ss.str());
|
||||
vertexshader->setShaderSource(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_WARN<< "MAX_MATRIX not found in Shader! " << str << std::endl;
|
||||
}
|
||||
OSG_INFO << "Shader " << str << std::endl;
|
||||
}
|
||||
CommonProgram->addShader(vertexshader.get());
|
||||
}
|
||||
for (int i = 0; i < nbAttribs; i++)
|
||||
|
||||
unsigned int nbAttribs = getNumVertexAttrib();
|
||||
for (unsigned int i = 0; i < nbAttribs; i++)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "boneWeight" << i;
|
||||
geom.setVertexAttribArray(attribIndex + i, getVertexAttrib(i));
|
||||
CommonProgram->addBindAttribLocation(ss.str(), _minAttribIndex + i);
|
||||
rig.setVertexAttribArray(_minAttribIndex + i, getVertexAttrib(i));
|
||||
OSG_INFO << "set vertex attrib " << ss.str() << std::endl;
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::StateSet> ss = new osg::StateSet;
|
||||
ss->addUniform(getMatrixPaletteUniform());
|
||||
ss->addUniform(new osg::Uniform("nbBonesPerVertex", getNumBonesPerVertex()));
|
||||
ss->setAttributeAndModes(program.get());
|
||||
geom.setStateSet(ss.get());
|
||||
|
||||
stateset->removeUniform("nbBonesPerVertex");
|
||||
stateset->addUniform(new osg::Uniform("nbBonesPerVertex",_bonesPerVertex));
|
||||
|
||||
stateset->removeUniform("matrixPalette");
|
||||
stateset->addUniform(_uniformMatrixPalette);
|
||||
|
||||
stateset->setAttribute(CommonProgram.get());
|
||||
|
||||
_needInit = false;
|
||||
return true;
|
||||
}
|
||||
@@ -133,6 +146,7 @@ struct MyRigTransformHardware : public osgAnimation::RigTransformHardware
|
||||
struct SetupRigGeometry : public osg::NodeVisitor
|
||||
{
|
||||
bool _hardware;
|
||||
|
||||
SetupRigGeometry( bool hardware = true) : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), _hardware(hardware) {}
|
||||
|
||||
void apply(osg::Geode& geode)
|
||||
@@ -142,10 +156,15 @@ struct SetupRigGeometry : public osg::NodeVisitor
|
||||
}
|
||||
void apply(osg::Drawable& geom)
|
||||
{
|
||||
if (_hardware) {
|
||||
if (_hardware)
|
||||
{
|
||||
osgAnimation::RigGeometry* rig = dynamic_cast<osgAnimation::RigGeometry*>(&geom);
|
||||
if (rig)
|
||||
{
|
||||
rig->setRigTransformImplementation(new MyRigTransformHardware);
|
||||
osgAnimation::MorphGeometry *morph=dynamic_cast<osgAnimation::MorphGeometry*>(rig->getSourceGeometry());
|
||||
if(morph)morph->setMorphTransformImplementation(new osgAnimation::MorphTransformHardware);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -169,7 +188,8 @@ osg::Group* createCharacterInstance(osg::Group* character, bool hardware)
|
||||
osgAnimation::BasicAnimationManager* anim = dynamic_cast<osgAnimation::BasicAnimationManager*>(animationManager);
|
||||
const osgAnimation::AnimationList& list = animationManager->getAnimationList();
|
||||
int v = getRandomValueinRange(list.size());
|
||||
if (list[v]->getName() == std::string("MatIpo_ipo")) {
|
||||
if (list[v]->getName() == std::string("MatIpo_ipo"))
|
||||
{
|
||||
anim->playAnimation(list[v].get());
|
||||
v = (v + 1)%list.size();
|
||||
}
|
||||
@@ -193,7 +213,10 @@ int main (int argc, char* argv[])
|
||||
|
||||
bool hardware = true;
|
||||
int maxChar = 10;
|
||||
while (psr.read("--software")) { hardware = false; }
|
||||
while (psr.read("--software"))
|
||||
{
|
||||
hardware = false;
|
||||
}
|
||||
while (psr.read("--number", maxChar)) {}
|
||||
|
||||
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFiles(psr);
|
||||
@@ -243,9 +266,10 @@ int main (int argc, char* argv[])
|
||||
|
||||
double xChar = maxChar;
|
||||
double yChar = xChar * 9.0/16;
|
||||
for (double i = 0.0; i < xChar; i++) {
|
||||
for (double j = 0.0; j < yChar; j++) {
|
||||
|
||||
for (double i = 0.0; i < xChar; i++)
|
||||
{
|
||||
for (double j = 0.0; j < yChar; j++)
|
||||
{
|
||||
osg::ref_ptr<osg::Group> c = createCharacterInstance(root.get(), hardware);
|
||||
osg::MatrixTransform* tr = new osg::MatrixTransform;
|
||||
tr->setMatrix(osg::Matrix::translate( 2.0 * (i - xChar * .5),
|
||||
@@ -257,7 +281,6 @@ int main (int argc, char* argv[])
|
||||
}
|
||||
std::cout << "created " << xChar * yChar << " instance" << std::endl;
|
||||
|
||||
|
||||
return viewer.run();
|
||||
}
|
||||
|
||||
|
||||
@@ -134,13 +134,10 @@ void initVertexMap(osgAnimation::Bone* b0,
|
||||
osgAnimation::RigGeometry* geom,
|
||||
osg::Vec3Array* array)
|
||||
{
|
||||
osgAnimation::VertexInfluenceSet vertexesInfluences;
|
||||
osgAnimation::VertexInfluenceMap* vim = new osgAnimation::VertexInfluenceMap;
|
||||
|
||||
(*vim)[b0->getName()].setName(b0->getName());
|
||||
(*vim)[b1->getName()].setName(b1->getName());
|
||||
(*vim)[b2->getName()].setName(b2->getName());
|
||||
|
||||
for (int i = 0; i < (int)array->size(); i++)
|
||||
{
|
||||
float val = (*array)[i][0];
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
// This example can work only if GL version is 4.3 or greater
|
||||
|
||||
#include <osg/Texture2D>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/ComputeDispatch>
|
||||
#include <osg/Geode>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgGA/StateSetManipulator>
|
||||
@@ -57,14 +57,12 @@ int main( int argc, char** argv )
|
||||
// The compute shader can't work with other kinds of shaders
|
||||
// It also requires the work group numbers. Setting them to 0 will disable the compute shader
|
||||
osg::ref_ptr<osg::Program> computeProg = new osg::Program;
|
||||
computeProg->setComputeGroups( 512/16, 512/16, 1 );
|
||||
computeProg->addShader( new osg::Shader(osg::Shader::COMPUTE, computeSrc) );
|
||||
|
||||
// Create a node for outputting to the texture.
|
||||
// It is OK to have just an empty node here, but seems inbuilt uniforms like osg_FrameTime won't work then.
|
||||
// TODO: maybe we can have a custom drawable which also will implement glMemoryBarrier?
|
||||
osg::ref_ptr<osg::Node> sourceNode = osgDB::readRefNodeFile("axes.osgt");
|
||||
if ( !sourceNode ) sourceNode = new osg::Node;
|
||||
osg::ref_ptr<osg::Node> sourceNode = new osg::ComputeDispatch(512/16, 512/16, 1 );
|
||||
sourceNode->setDataVariance( osg::Object::DYNAMIC );
|
||||
sourceNode->getOrCreateStateSet()->setAttributeAndModes( computeProg.get() );
|
||||
sourceNode->getOrCreateStateSet()->addUniform( new osg::Uniform("targetTex", (int)0) );
|
||||
|
||||
@@ -188,12 +188,12 @@ osg::ref_ptr<osg::Group> createSceneRoom()
|
||||
{
|
||||
// Room.
|
||||
osg::ref_ptr<osg::MatrixTransform> room = new osg::MatrixTransform;
|
||||
osg::ref_ptr<osg::Node> roomModel = osgDB::readNodeFile("simpleroom.osgt");
|
||||
osg::ref_ptr<osg::Node> roomModel = osgDB::readRefNodeFile("simpleroom.osgt");
|
||||
room->addChild(roomModel);
|
||||
room->setMatrix(osg::Matrix::translate(0, 0, 1));
|
||||
// Torus.
|
||||
osg::ref_ptr<osg::MatrixTransform> torus = new osg::MatrixTransform;
|
||||
osg::ref_ptr<osg::Node> torusModel = osgDB::readNodeFile("torus.osgt");
|
||||
osg::ref_ptr<osg::Node> torusModel = osgDB::readRefNodeFile("torus.osgt");
|
||||
torus->addChild(torusModel);
|
||||
setAnimationPath(torus, osg::Vec3(0, 0, 15), 6, 16);
|
||||
// Torus2.
|
||||
@@ -240,7 +240,7 @@ osg::Geode *createScreenQuad(float width,
|
||||
osg::Texture2D *createTexture(const std::string &fileName)
|
||||
{
|
||||
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
|
||||
texture->setImage(osgDB::readImageFile(fileName));
|
||||
texture->setImage(osgDB::readRefImageFile(fileName));
|
||||
texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT);
|
||||
texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT);
|
||||
texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
|
||||
@@ -292,8 +292,8 @@ osg::ref_ptr<osg::StateSet> setShaderProgram(osg::ref_ptr<osg::Camera> pass,
|
||||
const std::string& frag)
|
||||
{
|
||||
osg::ref_ptr<osg::Program> program = new osg::Program;
|
||||
program->addShader(osgDB::readShaderFile(vert));
|
||||
program->addShader(osgDB::readShaderFile(frag));
|
||||
program->addShader(osgDB::readRefShaderFile(vert));
|
||||
program->addShader(osgDB::readRefShaderFile(frag));
|
||||
osg::ref_ptr<osg::StateSet> ss = pass->getOrCreateStateSet();
|
||||
ss->setAttributeAndModes(
|
||||
program.get(),
|
||||
@@ -313,7 +313,7 @@ int main()
|
||||
// Shadowed scene.
|
||||
osg::ref_ptr<osgShadow::SoftShadowMap> shadowMap = new osgShadow::SoftShadowMap;
|
||||
shadowMap->setJitteringScale(16);
|
||||
shadowMap->addShader(osgDB::readShaderFile("shaders/pass1Shadow.frag"));
|
||||
shadowMap->addShader(osgDB::readRefShaderFile("shaders/pass1Shadow.frag"));
|
||||
shadowMap->setLight(light.get());
|
||||
osg::ref_ptr<osgShadow::ShadowedScene> shadowedScene = new osgShadow::ShadowedScene;
|
||||
shadowedScene->setShadowTechnique(shadowMap.get());
|
||||
|
||||
@@ -121,10 +121,70 @@ osg::Node* createFadeText(osg::EllipsoidModel* ellipsoid)
|
||||
}
|
||||
|
||||
|
||||
int main(int, char**)
|
||||
class TextSettings : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
TextSettings(osg::ArgumentParser& arguments):
|
||||
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
||||
_backdropTypeSet(false),
|
||||
_backdropType(osgText::Text::NONE),
|
||||
_shaderTechniqueSet(false),
|
||||
_shaderTechnique(osgText::GREYSCALE)
|
||||
{
|
||||
if (arguments.read("--outline"))
|
||||
{
|
||||
_backdropTypeSet = true;
|
||||
_backdropType = osgText::Text::OUTLINE;
|
||||
}
|
||||
if (arguments.read("--sdf"))
|
||||
{
|
||||
_shaderTechniqueSet = true;
|
||||
_shaderTechnique = osgText::SIGNED_DISTANCE_FIELD;
|
||||
}
|
||||
if (arguments.read("--all"))
|
||||
{
|
||||
_shaderTechniqueSet = true;
|
||||
_shaderTechnique = osgText::ALL_FEATURES;
|
||||
}
|
||||
if (arguments.read("--greyscale"))
|
||||
{
|
||||
_shaderTechniqueSet = true;
|
||||
_shaderTechnique = osgText::GREYSCALE;
|
||||
}
|
||||
if (arguments.read("--no-shader"))
|
||||
{
|
||||
_shaderTechniqueSet = true;
|
||||
_shaderTechnique = osgText::NO_TEXT_SHADER;
|
||||
}
|
||||
}
|
||||
|
||||
void apply(osg::Drawable& drawable)
|
||||
{
|
||||
osgText::Text* text = dynamic_cast<osgText::Text*>(&drawable);
|
||||
if (text)
|
||||
{
|
||||
if (_backdropTypeSet)
|
||||
{
|
||||
text->setBackdropType(_backdropType);
|
||||
text->setBackdropOffset(0.1f);
|
||||
text->setBackdropColor(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
|
||||
}
|
||||
if (_shaderTechniqueSet) text->setShaderTechnique(_shaderTechnique);
|
||||
}
|
||||
}
|
||||
|
||||
bool _backdropTypeSet;
|
||||
osgText::Text::BackdropType _backdropType;
|
||||
bool _shaderTechniqueSet;
|
||||
osgText::ShaderTechnique _shaderTechnique;
|
||||
};
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
osg::ArgumentParser arguments(&argc, argv);
|
||||
|
||||
// construct the viewer.
|
||||
osgViewer::Viewer viewer;
|
||||
osgViewer::Viewer viewer(arguments);
|
||||
|
||||
viewer.getCamera()->setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES);
|
||||
viewer.getCamera()->setNearFarRatio(0.00001f);
|
||||
@@ -144,6 +204,12 @@ int main(int, char**)
|
||||
csn->addChild(createFadeText(csn->getEllipsoidModel()));
|
||||
}
|
||||
|
||||
if (arguments.argc()>1)
|
||||
{
|
||||
TextSettings textSettings(arguments);
|
||||
root->accept(textSettings);
|
||||
}
|
||||
|
||||
viewer.setCameraManipulator(new osgGA::TerrainManipulator);
|
||||
|
||||
return viewer.run();
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
#include <osg/io_utils>
|
||||
#include <osg/ArgumentParser>
|
||||
#include <osg/Geode>
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/WriteFile>
|
||||
#include <osgViewer/Viewer>
|
||||
#include <osgViewer/ViewerEventHandlers>
|
||||
#include <osgGA/StateSetManipulator>
|
||||
@@ -56,80 +59,367 @@ osg::Camera* createOrthoCamera(double width, double height)
|
||||
return camera;
|
||||
}
|
||||
|
||||
osgText::Text* createLabel(const std::string& l, const char* f, unsigned int size)
|
||||
typedef std::list<unsigned int> Sizes;
|
||||
|
||||
struct TextSettings
|
||||
{
|
||||
static osg::Vec3 pos(10.0f, 10.0f, 0.0f);
|
||||
TextSettings():
|
||||
fontFilename("fonts/arial.ttf"),
|
||||
minFilter(osg::Texture::LINEAR_MIPMAP_LINEAR),
|
||||
magFilter(osg::Texture::LINEAR),
|
||||
maxAnisotropy(16.0f),
|
||||
shaderTechnique(osgText::GREYSCALE),
|
||||
textColor(1.0f, 1.0f, 1.0f, 1.0f),
|
||||
backdropType(osgText::Text::NONE),
|
||||
backdropOffset(0.07f, 0.07f),
|
||||
backdropColor(0.0f, 0.0f, 0.0f, 1.0f),
|
||||
scaleFontSizeToFontResolution(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void readFilterMode(const std::string& value, osg::Texture::FilterMode& filterMode)
|
||||
{
|
||||
if (value=="LINEAR") filterMode = osg::Texture::LINEAR;
|
||||
else if (value=="NEAREST") filterMode = osg::Texture::NEAREST;
|
||||
else if (value=="LINEAR_MIPMAP_LINEAR") filterMode = osg::Texture::LINEAR_MIPMAP_LINEAR;
|
||||
}
|
||||
|
||||
void read(osg::ArgumentParser& arguments)
|
||||
{
|
||||
if (arguments.read("--test"))
|
||||
{
|
||||
backgroundColor = osg::Vec4(1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
fontFilename = "fonts/arialbd.ttf";
|
||||
backdropType = osgText::Text::OUTLINE;
|
||||
|
||||
sizes.clear();
|
||||
sizes.push_back(8);
|
||||
sizes.push_back(16);
|
||||
sizes.push_back(32);
|
||||
sizes.push_back(64);
|
||||
sizes.push_back(128);
|
||||
}
|
||||
|
||||
if (arguments.read("--GREYSCALE")) { shaderTechnique = osgText::GREYSCALE; }
|
||||
if (arguments.read("--SIGNED_DISTANCE_FIELD")) { shaderTechnique = osgText::SIGNED_DISTANCE_FIELD; }
|
||||
if (arguments.read("--ALL_FEATURES")) { shaderTechnique = osgText::ALL_FEATURES; }
|
||||
|
||||
if (arguments.read("--font",fontFilename)) {}
|
||||
|
||||
std::string value;
|
||||
if (arguments.read("--min", value)) { readFilterMode(value, minFilter); }
|
||||
if (arguments.read("--mag", value)) { readFilterMode(value, magFilter); }
|
||||
|
||||
if (arguments.read("--anisotropy",maxAnisotropy)) {}
|
||||
|
||||
|
||||
if (arguments.read("--outline")) backdropType = osgText::Text::OUTLINE;
|
||||
if (arguments.read("--shadow")) backdropType = osgText::Text::DROP_SHADOW_BOTTOM_RIGHT;
|
||||
if (arguments.read("--shadow-br")) backdropType = osgText::Text::DROP_SHADOW_BOTTOM_RIGHT;
|
||||
if (arguments.read("--shadow-cr")) backdropType = osgText::Text::DROP_SHADOW_CENTER_RIGHT;
|
||||
if (arguments.read("--shadow-tr")) backdropType = osgText::Text::DROP_SHADOW_TOP_RIGHT;
|
||||
if (arguments.read("--shadow-bc")) backdropType = osgText::Text::DROP_SHADOW_BOTTOM_CENTER;
|
||||
if (arguments.read("--shadow-tc")) backdropType = osgText::Text::DROP_SHADOW_TOP_CENTER;
|
||||
if (arguments.read("--shadow-bl")) backdropType = osgText::Text::DROP_SHADOW_BOTTOM_LEFT;
|
||||
if (arguments.read("--shadow-cl")) backdropType = osgText::Text::DROP_SHADOW_CENTER_LEFT;
|
||||
if (arguments.read("--shadow-tl")) backdropType = osgText::Text::DROP_SHADOW_TOP_LEFT;
|
||||
|
||||
|
||||
|
||||
float offset;
|
||||
if (arguments.read("--offset", offset)) backdropOffset.set(offset, offset);
|
||||
|
||||
if (arguments.read("--text-color", textColor.r(), textColor.g(), textColor.b(), textColor.a())) {}
|
||||
if (arguments.read("--bd-color", backdropColor.r(), backdropColor.g(), backdropColor.b(), backdropColor.a())) {}
|
||||
if (arguments.read("--bg-color", backgroundColor.r(), backgroundColor.g(), backgroundColor.b(), backgroundColor.a())) {}
|
||||
|
||||
if (arguments.read("--constant-size")) scaleFontSizeToFontResolution = false;
|
||||
if (arguments.read("--scale-size")) scaleFontSizeToFontResolution = true;
|
||||
|
||||
}
|
||||
|
||||
void setText(osgText::Text& text)
|
||||
{
|
||||
OSG_NOTICE<<"Settings::setText()"<<std::endl;
|
||||
|
||||
osg::ref_ptr<osgText::Font> font;
|
||||
|
||||
if (fontFilename!="default") font = osgText::readRefFontFile(fontFilename);
|
||||
|
||||
if (!font) font = osgText::Font::getDefaultFont();
|
||||
|
||||
font->setMinFilterHint(minFilter);
|
||||
font->setMagFilterHint(magFilter);
|
||||
font->setMaxAnisotropy(maxAnisotropy);
|
||||
|
||||
text.setColor(textColor);
|
||||
text.setBackdropType(backdropType);
|
||||
text.setBackdropOffset(backdropOffset.x(), backdropOffset.y());
|
||||
text.setBackdropColor(backdropColor);
|
||||
text.setShaderTechnique(shaderTechnique);
|
||||
|
||||
text.setFont(font.get());
|
||||
|
||||
}
|
||||
|
||||
std::string fontFilename;
|
||||
osg::Texture::FilterMode minFilter;
|
||||
osg::Texture::FilterMode magFilter;
|
||||
float maxAnisotropy;
|
||||
osgText::ShaderTechnique shaderTechnique;
|
||||
|
||||
osg::Vec4 textColor;
|
||||
osgText::Text::BackdropType backdropType;
|
||||
osg::Vec2 backdropOffset;
|
||||
osg::Vec4 backdropColor;
|
||||
osg::Vec4 backgroundColor;
|
||||
Sizes sizes;
|
||||
bool scaleFontSizeToFontResolution;
|
||||
};
|
||||
|
||||
osgText::Text* createLabel(const std::string& l, TextSettings& settings, unsigned int size, osg::Vec3& pos)
|
||||
{
|
||||
osgText::Text* label = new osgText::Text();
|
||||
osg::ref_ptr<osgText::Font> font = osgText::readRefFontFile(f);
|
||||
|
||||
label->setFont(font);
|
||||
label->setCharacterSize(size);
|
||||
settings.setText(*label);
|
||||
|
||||
if (settings.scaleFontSizeToFontResolution)
|
||||
{
|
||||
label->setCharacterSize(size);
|
||||
}
|
||||
|
||||
label->setFontResolution(size, size);
|
||||
label->setColor(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
label->setPosition(pos);
|
||||
label->setAlignment(osgText::Text::LEFT_BOTTOM);
|
||||
|
||||
// It seems to be important we do this last to get best results?
|
||||
label->setText(l);
|
||||
|
||||
textInfo(label);
|
||||
// textInfo(label);
|
||||
|
||||
pos.y() += size + 10.0f;
|
||||
pos.y() += label->getCharacterHeight()*2.0;
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
typedef std::list<unsigned int> Sizes;
|
||||
class KeyHandler : public osgGA::GUIEventHandler
|
||||
{
|
||||
public:
|
||||
|
||||
KeyHandler() {}
|
||||
|
||||
~KeyHandler() {}
|
||||
|
||||
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
|
||||
{
|
||||
osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
|
||||
if (!view) return false;
|
||||
|
||||
#if 1
|
||||
osg::StateSet* stateset = view->getSceneData()->getOrCreateStateSet();
|
||||
#else
|
||||
osg::StateSet* stateset = view->getCamera()->getOrCreateStateSet();
|
||||
#endif
|
||||
switch(ea.getEventType())
|
||||
{
|
||||
case(osgGA::GUIEventAdapter::KEYUP):
|
||||
{
|
||||
if (ea.getKey()=='d')
|
||||
{
|
||||
toggleDefine(stateset, "SIGNED_DISTANCE_FIELD");
|
||||
return true;
|
||||
}
|
||||
else if (ea.getKey()=='o')
|
||||
{
|
||||
toggleDefine(stateset, "OUTLINE");
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void toggleDefine(osg::StateSet* stateset, const std::string& define)
|
||||
{
|
||||
osg::StateSet::DefinePair* dp = stateset->getDefinePair(define);
|
||||
if (dp)
|
||||
{
|
||||
OSG_NOTICE<<"Disabling "<<define<<std::endl;
|
||||
stateset->removeDefine(define);
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<"Enabling "<<define<<std::endl;
|
||||
stateset->setDefine(define);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
osgViewer::Viewer viewer;
|
||||
osg::ArgumentParser args(&argc, argv);
|
||||
|
||||
// Make sure we have the minimum args...
|
||||
if(argc <= 2)
|
||||
{
|
||||
osg::notify(osg::FATAL) << "usage: " << args[0] << " fontfile size1 [size2 ...]" << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
osgViewer::Viewer viewer(args);
|
||||
|
||||
|
||||
viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
|
||||
viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
|
||||
viewer.addEventHandler(new osgViewer::StatsHandler());
|
||||
viewer.addEventHandler(new osgViewer::WindowSizeHandler());
|
||||
viewer.addEventHandler(new KeyHandler());
|
||||
|
||||
osg::Group* group = new osg::Group();
|
||||
osg::Camera* camera = createOrthoCamera(1280.0f, 1024.0f);
|
||||
TextSettings settings;
|
||||
settings.backgroundColor = viewer.getCamera()->getClearColor();
|
||||
|
||||
// Create the list of desired sizes.
|
||||
Sizes sizes;
|
||||
settings.read(args);
|
||||
|
||||
for(int i = 2; i < argc; i++)
|
||||
viewer.getCamera()->setClearColor(settings.backgroundColor);
|
||||
|
||||
osg::ref_ptr<osg::Group> root = new osg::Group;
|
||||
|
||||
bool split_screen = args.read("--split");
|
||||
|
||||
if (split_screen)
|
||||
{
|
||||
if(!args.isNumber(i)) continue;
|
||||
viewer.realize();
|
||||
|
||||
sizes.push_back(std::atoi(args[i]));
|
||||
// quite an dirty divusion of the master Camera's window if one is assigned.
|
||||
if (viewer.getCamera()->getGraphicsContext())
|
||||
{
|
||||
viewer.stopThreading();
|
||||
|
||||
osg::ref_ptr<osg::GraphicsContext> gc = viewer.getCamera()->getGraphicsContext();
|
||||
osg::ref_ptr<const osg::GraphicsContext::Traits> traits = gc->getTraits();
|
||||
|
||||
// left half
|
||||
{
|
||||
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
||||
camera->setCullMask(0x1);
|
||||
camera->setGraphicsContext(gc.get());
|
||||
camera->setViewport(new osg::Viewport(0,0, traits->width/2, traits->height));
|
||||
viewer.addSlave(camera.get(), osg::Matrixd::translate(1.0,0.0,0.0), osg::Matrixd::scale(2.0, 1.0, 1.0));
|
||||
}
|
||||
|
||||
{
|
||||
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
||||
camera->setCullMask(0x2);
|
||||
camera->setGraphicsContext(gc.get());
|
||||
camera->setViewport(new osg::Viewport(traits->width/2+2,0, traits->width/2, traits->height));
|
||||
viewer.addSlave(camera.get(), osg::Matrixd::translate(-1.0,0.0,0.0), osg::Matrixd::scale(2.0, 1.0, 1.0));
|
||||
}
|
||||
|
||||
viewer.getCamera()->setGraphicsContext(0);
|
||||
|
||||
viewer.startThreading();
|
||||
}
|
||||
else
|
||||
{
|
||||
split_screen = false;
|
||||
}
|
||||
}
|
||||
|
||||
osg::Geode* geode = new osg::Geode();
|
||||
osg::ref_ptr<osg::MatrixTransform> transform = new osg::MatrixTransform;
|
||||
transform->setMatrix(osg::Matrixd::rotate(osg::DegreesToRadians(90.0), 1.0, 0.0, 0.0));
|
||||
root->addChild(transform.get());
|
||||
root = transform;
|
||||
|
||||
osg::ref_ptr<osg::Program> program = new osg::Program;
|
||||
std::string shaderFilename;
|
||||
while(args.read("--shader", shaderFilename))
|
||||
{
|
||||
osg::ref_ptr<osg::Shader> shader = osgDB::readRefShaderFile(shaderFilename);
|
||||
if (shader.get())
|
||||
{
|
||||
OSG_NOTICE<<"Loading shader "<<shaderFilename<<std::endl;
|
||||
program->addShader(shader.get());
|
||||
}
|
||||
}
|
||||
|
||||
if (program->getNumShaders()>0)
|
||||
{
|
||||
OSG_NOTICE<<"Using shaders"<<std::endl;
|
||||
root->getOrCreateStateSet()->setAttribute(program.get(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
|
||||
root->getOrCreateStateSet()->addUniform(new osg::Uniform("glyphTexture", 0));
|
||||
|
||||
settings.shaderTechnique = osgText::ALL_FEATURES;
|
||||
}
|
||||
|
||||
|
||||
std::string outputFilename;
|
||||
if (args.read("-o", outputFilename)) {}
|
||||
|
||||
if (args.argc() > 1)
|
||||
{
|
||||
settings.fontFilename = argv[1];
|
||||
|
||||
// Create the list of desired sizes.
|
||||
for(int i = 2; i < args.argc(); i++)
|
||||
{
|
||||
if(!args.isNumber(i)) continue;
|
||||
|
||||
settings.sizes.push_back(std::atoi(args[i]));
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.sizes.empty())
|
||||
{
|
||||
settings.sizes.push_back(8);
|
||||
settings.sizes.push_back(16);
|
||||
settings.sizes.push_back(32);
|
||||
settings.sizes.push_back(64);
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Geode> geode = new osg::Geode();
|
||||
|
||||
osg::Vec3 pos(0.0f, 0.0f, 0.0f);
|
||||
|
||||
// Add all of our osgText drawables.
|
||||
for(Sizes::const_iterator i = sizes.begin(); i != sizes.end(); i++)
|
||||
for(Sizes::const_iterator i = settings.sizes.begin(); i != settings.sizes.end(); i++)
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << *i << " 1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
geode->addDrawable(createLabel(ss.str(), args[1], *i));
|
||||
geode->addDrawable(createLabel(ss.str(), settings, *i, pos));
|
||||
}
|
||||
|
||||
camera->addChild(geode);
|
||||
root->addChild(geode.get());
|
||||
|
||||
group->addChild(camera);
|
||||
if (split_screen)
|
||||
{
|
||||
geode->setNodeMask(0x1);
|
||||
|
||||
viewer.setSceneData(group);
|
||||
osg::ref_ptr<osg::Geode> right_geode = new osg::Geode;
|
||||
right_geode->setNodeMask(0x2);
|
||||
|
||||
settings.shaderTechnique = osgText::GREYSCALE;
|
||||
|
||||
pos.set(0.0f, 0.0f, 0.0f);
|
||||
|
||||
for(Sizes::const_iterator i = settings.sizes.begin(); i != settings.sizes.end(); i++)
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << *i << " 1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
right_geode->addDrawable(createLabel(ss.str(), settings, *i, pos));
|
||||
}
|
||||
|
||||
root->addChild(right_geode);
|
||||
}
|
||||
|
||||
|
||||
if (!outputFilename.empty())
|
||||
{
|
||||
osgDB::writeNodeFile(*root, outputFilename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
viewer.setSceneData(root.get());
|
||||
|
||||
return viewer.run();
|
||||
}
|
||||
|
||||
@@ -196,7 +196,11 @@ int main( int argc, char **argv )
|
||||
newCameraProperty = true;
|
||||
cp = new gsc::CameraProperty;
|
||||
|
||||
osg::ref_ptr<osg::Node> node = fc->getInputFileName().empty() ? 0 : osgDB::readNodeFile(fc->getInputFileName());
|
||||
osg::ref_ptr<osg::Node> node;
|
||||
if (!fc->getInputFileName().empty())
|
||||
{
|
||||
osgDB::readRefNodeFile(fc->getInputFileName());
|
||||
}
|
||||
if (node.valid())
|
||||
{
|
||||
cp->setToModel(node.get());
|
||||
@@ -522,7 +526,7 @@ int main( int argc, char **argv )
|
||||
gsc::CaptureSettings* fc = itr->get();
|
||||
screenShot->_frameCapture = fc;
|
||||
|
||||
osg::ref_ptr<osg::Node> model = osgDB::readNodeFile(fc->getInputFileName());
|
||||
osg::ref_ptr<osg::Node> model = osgDB::readRefNodeFile(fc->getInputFileName());
|
||||
if (!model) break;
|
||||
|
||||
viewer.setSceneData(model.get());
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "GameOfLifePass.h"
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <iostream>
|
||||
|
||||
ProcessPass::ProcessPass(osg::TextureRectangle *in_tex,
|
||||
@@ -110,16 +111,13 @@ void ProcessPass::setupCamera()
|
||||
|
||||
void ProcessPass::setShader(std::string filename)
|
||||
{
|
||||
std::string foundFile = osgDB::findDataFile(filename);
|
||||
if (foundFile.empty())
|
||||
osg::ref_ptr<osg::Shader> fshader = osgDB::readRefShaderFile(osg::Shader::FRAGMENT, filename);
|
||||
if (!fshader)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Could not file shader file: "<<filename<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Shader> fshader = new osg::Shader( osg::Shader::FRAGMENT );
|
||||
fshader->loadShaderSourceFromFile(foundFile);
|
||||
|
||||
_FragmentProgram = 0;
|
||||
_FragmentProgram = new osg::Program;
|
||||
|
||||
|
||||
@@ -13,6 +13,137 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/** osggpucull example.
|
||||
|
||||
A geometry instancing rendering algorithm consisting of two consequent phases :
|
||||
|
||||
- first phase is a GLSL shader performing object culling and LOD picking ( a culling shader ).
|
||||
Every culled object is represented as GL_POINT in the input osg::Geometry.
|
||||
The output of the culling shader is a set of object LODs that need to be rendered.
|
||||
The output is stored in texture buffer objects. No pixel is drawn to the screen
|
||||
because GL_RASTERIZER_DISCARD mode is used.
|
||||
|
||||
- second phase draws osg::Geometry containing merged LODs using glDrawArraysIndirect()
|
||||
function. Information about quantity of instances to render, its positions and other
|
||||
parameters is sourced from texture buffer objects filled in the first phase.
|
||||
|
||||
The example uses various OpenGL 4.2 features such as texture buffer objects,
|
||||
atomic counters, image units and functions defined in GL_ARB_shader_image_load_store
|
||||
extension to achieve its goal and thus will not work on graphic cards with older OpenGL
|
||||
versions.
|
||||
|
||||
The example was tested on Linux and Windows with NVidia 570 and 580 cards.
|
||||
The tests on AMD cards were not conducted ( due to lack of it ).
|
||||
The tests were performed using OSG revision 14088.
|
||||
|
||||
The main advantages of this rendering method :
|
||||
- instanced rendering capable of drawing thousands of different objects with
|
||||
almost no CPU intervention ( cull and draw times are close to 0 ms ).
|
||||
- input objects may be sourced from any OSG graph ( for example - information about
|
||||
object points may be stored in a PagedLOD graph. This way we may cover the whole
|
||||
countries with trees, buildings and other objects ).
|
||||
Furthermore if we create osgDB plugins that generate data on the fly, we may
|
||||
generate information for every grass blade for that country.
|
||||
- every object may have its own parameters and thus may be distinct from other objects
|
||||
of the same type.
|
||||
- relatively low memory footprint ( single object information is stored in a few
|
||||
vertex attributes ).
|
||||
- no GPU->CPU roundtrip typical for such methods ( method uses atomic counters
|
||||
and glDrawArraysIndirect() function instead of OpenGL queries. This way
|
||||
information about quantity of rendered objects never goes back to CPU.
|
||||
The typical GPU->CPU roundtrip cost is about 2 ms ).
|
||||
- this example also shows how to render dynamic objects ( objects that may change
|
||||
its position ) with moving parts ( like car wheels or airplane propellers ) .
|
||||
The obvious extension to that dynamic method would be the animated crowd rendering.
|
||||
- rendered objects may be easily replaced ( there is no need to process the whole
|
||||
OSG graphs, because these graphs store only positional information ).
|
||||
|
||||
The main disadvantages of a method :
|
||||
- the maximum quantity of objects to render must be known beforehand
|
||||
( because texture buffer objects holding data between phases have constant size ).
|
||||
- OSG statistics are flawed ( they don't know anymore how many objects are drawn ).
|
||||
- osgUtil::Intersection does not work
|
||||
|
||||
Example application may be used to make some performance tests, so below you
|
||||
will find some extended parameter description :
|
||||
--skip-dynamic - skip rendering of dynamic objects if you only want to
|
||||
observe static object statistics
|
||||
--skip-static - the same for static objects
|
||||
--dynamic-area-size - size of the area for dynamic rendering. Default = 1000 meters
|
||||
( square 1000m x 1000m ). Along with density defines
|
||||
how many dynamic objects is there in the example.
|
||||
--static-area-size - the same for static objects. Default = 2000 meters
|
||||
( square 2000m x 2000m ).
|
||||
|
||||
Example application defines some parameters (density, LOD ranges, object's triangle count).
|
||||
You may manipulate its values using below described modifiers:
|
||||
--density-modifier - density modifier in percent. Default = 100%.
|
||||
Density ( along with LOD ranges ) defines maximum
|
||||
quantity of rendered objects. registerType() function
|
||||
accepts maximum density ( in objects per square kilometer )
|
||||
as its parameter.
|
||||
--lod-modifier - defines the LOD ranges. Default = 100%.
|
||||
--triangle-modifier - defines the number of triangles in finally rendered objects.
|
||||
Default = 100 %.
|
||||
--instances-per-cell - for static rendering the application builds OSG graph using
|
||||
InstanceCell class ( this class is a modified version of Cell class
|
||||
from osgforest example - it builds simple quadtree from a list
|
||||
of static instances ). This parameter defines maximum number
|
||||
of instances in a single osg::Group in quadtree.
|
||||
If, for example, you modify it to value=100, you will see
|
||||
really big cull time in OSG statistics ( because resulting
|
||||
tree generated by InstanceCell will be very deep ).
|
||||
Default value = 4096 .
|
||||
--export-objects - write object geometries and quadtree of instances to osgt files
|
||||
for later analysis.
|
||||
--use-multi-draw - use glMultiDrawArraysIndirect() instead of glDrawArraysIndirect() in a
|
||||
draw shader. Thanks to this we may render all ( different ) objects
|
||||
using only one draw call. Requires OpenGL version 4.3.
|
||||
|
||||
This application is inspired by Daniel Rákos work : "GPU based dynamic geometry LOD" that
|
||||
may be found under this address : http://rastergrid.com/blog/2010/10/gpu-based-dynamic-geometry-lod/
|
||||
There are however some differences :
|
||||
- Daniel Rákos uses GL queries to count objects to render, while this example
|
||||
uses atomic counters ( no GPU->CPU roundtrip )
|
||||
- this example does not use transform feedback buffers to store intermediate data
|
||||
( it uses texture buffer objects instead ).
|
||||
- I use only the vertex shader to cull objects, whereas Daniel Rákos uses vertex shader
|
||||
and geometry shader ( because only geometry shader can send more than one primitive
|
||||
to transform feedback buffers ).
|
||||
- objects in the example are drawn using glDrawArraysIndirect() function,
|
||||
instead of glDrawElementsInstanced().
|
||||
|
||||
Finally there are some things to consider/discuss :
|
||||
- the whole algorithm exploits nice OpenGL feature that any GL buffer
|
||||
may be bound as any type of buffer ( in our example a buffer is once bound
|
||||
as a texture buffer object, and later is bound as GL_DRAW_INDIRECT_BUFFER ).
|
||||
osg::TextureBuffer class has one handy method to do that trick ( bindBufferAs() ),
|
||||
and new primitive sets use osg::TextureBuffer as input.
|
||||
For now I added new primitive sets to example ( DrawArraysIndirect and
|
||||
MultiDrawArraysIndirect defined in examples/osggpucull/DrawIndirectPrimitiveSet.h ),
|
||||
but if Robert will accept its current implementations ( I mean - primitive
|
||||
sets that have osg::TextureBuffer in constructor ), I may add it to
|
||||
osg/include/PrimitiveSet header.
|
||||
- I used BufferTemplate class writen and published by Aurelien in submission forum
|
||||
some time ago. For some reason this class never got into osg/include, but is
|
||||
really needed during creation of UBOs, TBOs, and possibly SSBOs in the future.
|
||||
I added std::vector specialization to that template class.
|
||||
- I needed to create similar osg::Geometries with variable number of vertices
|
||||
( to create different LODs in my example ). For this reason I've written
|
||||
some code allowing me to create osg::Geometries from osg::Shape descendants.
|
||||
This code may be found in ShapeToGeometry.* files. Examples of use are in
|
||||
osggpucull.cpp . The question is : should this code stay in example, or should
|
||||
it be moved to osgUtil ?
|
||||
- this remark is important for NVidia cards on Linux and Windows : if
|
||||
you have "Sync to VBlank" turned ON in nvidia-settings and you want to see
|
||||
real GPU times in OSG statistics window, you must set the power management
|
||||
settings to "Prefer maximum performance", because when "Adaptive mode" is used,
|
||||
the graphic card's clock may be slowed down by the driver during program execution
|
||||
( On Linux when OpenGL application starts in adaptive mode, clock should work
|
||||
as fast as possible, but after one minute of program execution, the clock slows down ).
|
||||
This happens when GPU time in OSG statistics window is shorter than 3 ms.
|
||||
*/
|
||||
|
||||
#include <osg/Vec4i>
|
||||
#include <osg/Quat>
|
||||
#include <osg/Geometry>
|
||||
@@ -188,7 +319,7 @@ struct IndirectTarget
|
||||
}
|
||||
void endRegister(unsigned int index, unsigned int rowsPerInstance, GLenum pixelFormat, GLenum type, GLint internalFormat, bool useMultiDrawArraysIndirect )
|
||||
{
|
||||
indirectCommandTextureBuffer = new osg::TextureBuffer(indirectCommands);
|
||||
indirectCommandTextureBuffer = new osg::TextureBuffer(indirectCommands.get());
|
||||
indirectCommandTextureBuffer->setInternalFormat( GL_R32I );
|
||||
indirectCommandTextureBuffer->bindToImageUnit(index, osg::Texture::READ_WRITE);
|
||||
indirectCommandTextureBuffer->setUnRefImageDataAfterApply(false);
|
||||
@@ -199,11 +330,12 @@ struct IndirectTarget
|
||||
{
|
||||
std::vector<osg::DrawArraysIndirect*> newPrimitiveSets;
|
||||
|
||||
for(unsigned int j=0;j<indirectCommands->size(); ++j){
|
||||
for(unsigned int j=0;j<indirectCommands->size(); ++j)
|
||||
{
|
||||
osg::DrawArraysIndirect *ipr=new osg::DrawArraysIndirect( GL_TRIANGLES, j );
|
||||
ipr->setIndirectCommandArray( indirectCommands);
|
||||
ipr->setIndirectCommandArray( indirectCommands.get());
|
||||
newPrimitiveSets.push_back(ipr);
|
||||
}
|
||||
}
|
||||
|
||||
geometryAggregator->getAggregatedGeometry()->removePrimitiveSet(0,geometryAggregator->getAggregatedGeometry()->getNumPrimitiveSets() );
|
||||
|
||||
@@ -215,7 +347,7 @@ struct IndirectTarget
|
||||
else // use glMultiDrawArraysIndirect()
|
||||
{
|
||||
osg::MultiDrawArraysIndirect *ipr=new osg::MultiDrawArraysIndirect( GL_TRIANGLES );
|
||||
ipr->setIndirectCommandArray( indirectCommands );
|
||||
ipr->setIndirectCommandArray( indirectCommands.get() );
|
||||
geometryAggregator->getAggregatedGeometry()->removePrimitiveSet(0,geometryAggregator->getAggregatedGeometry()->getNumPrimitiveSets() );
|
||||
geometryAggregator->getAggregatedGeometry()->addPrimitiveSet( ipr );
|
||||
}
|
||||
@@ -236,6 +368,7 @@ struct IndirectTarget
|
||||
instanceTarget->bindToImageUnit(OSGGPUCULL_MAXIMUM_INDIRECT_TARGET_NUMBER+index, osg::Texture::READ_WRITE);
|
||||
|
||||
}
|
||||
|
||||
void addIndirectCommandData( const std::string& uniformNamePrefix, int index, osg::StateSet* stateset )
|
||||
{
|
||||
std::string uniformName = uniformNamePrefix + char( '0' + index );
|
||||
@@ -245,6 +378,7 @@ struct IndirectTarget
|
||||
|
||||
|
||||
}
|
||||
|
||||
void addIndirectTargetData( bool cullPhase, const std::string& uniformNamePrefix, int index, osg::StateSet* stateset )
|
||||
{
|
||||
std::string uniformName;
|
||||
@@ -257,6 +391,7 @@ struct IndirectTarget
|
||||
stateset->addUniform( uniform );
|
||||
stateset->setTextureAttribute( OSGGPUCULL_MAXIMUM_INDIRECT_TARGET_NUMBER+index, instanceTarget.get() );
|
||||
}
|
||||
|
||||
void addDrawProgram( const std::string& uniformBlockName, osg::StateSet* stateset )
|
||||
{
|
||||
drawProgram->addBindUniformBlock(uniformBlockName, 1);
|
||||
@@ -286,6 +421,7 @@ struct GPUCullData
|
||||
instanceTypesUBB = new osg::UniformBufferBinding(1, instanceTypes.get(), 0, 0);
|
||||
|
||||
}
|
||||
|
||||
void setUseMultiDrawArraysIndirect( bool value )
|
||||
{
|
||||
useMultiDrawArraysIndirect = value;
|
||||
@@ -297,6 +433,7 @@ struct GPUCullData
|
||||
return;
|
||||
targets[index] = IndirectTarget( agv, targetDrawProgram );
|
||||
}
|
||||
|
||||
bool registerType(unsigned int typeID, unsigned int targetID, osg::Node* node, const osg::Vec4& lodDistances, float maxDensityPerSquareKilometer )
|
||||
{
|
||||
if( typeID >= instanceTypes->getData().size() )
|
||||
@@ -328,6 +465,7 @@ struct GPUCullData
|
||||
target->second.maxTargetQuantity += maxQuantity;
|
||||
return true;
|
||||
}
|
||||
|
||||
// endRegister() method is called after all indirect targets and instance types are registered.
|
||||
// It creates indirect targets with pixel format and data type provided by user ( indirect targets may hold
|
||||
// different information about single instance depending on user's needs ( in our example : static rendering
|
||||
@@ -388,10 +526,12 @@ struct StaticInstance
|
||||
: position(m), extraParams(params), idParams(typeID,id,0,0)
|
||||
{
|
||||
}
|
||||
|
||||
osg::Vec3d getPosition() const
|
||||
{
|
||||
return position.getTrans();
|
||||
}
|
||||
|
||||
osg::Matrixf position;
|
||||
osg::Vec4f extraParams;
|
||||
osg::Vec4i idParams;
|
||||
@@ -705,10 +845,12 @@ struct ResetTexturesCallback : public osg::StateSet::Callback
|
||||
ResetTexturesCallback()
|
||||
{
|
||||
}
|
||||
|
||||
void addTextureDirty( unsigned int texUnit )
|
||||
{
|
||||
texUnitsDirty.push_back(texUnit);
|
||||
}
|
||||
|
||||
void addTextureDirtyParams( unsigned int texUnit )
|
||||
{
|
||||
texUnitsDirtyParams.push_back(texUnit);
|
||||
@@ -748,6 +890,7 @@ struct InvokeMemoryBarrier : public osg::Drawable::DrawCallback
|
||||
: _barriers(barriers)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void drawImplementation(osg::RenderInfo& renderInfo,const osg::Drawable* drawable) const
|
||||
{
|
||||
//DrawIndirectGLExtensions *ext = DrawIndirectGLExtensions::getExtensions( renderInfo.getContextID(), true );
|
||||
@@ -836,11 +979,13 @@ osg::Group* createSimpleHouse( float detailRatio, const osg::Vec4& buildingColor
|
||||
osg::ref_ptr<osg::Geode> chimneyGeode = convertShapeToGeode( *chimney.get(), tessHints.get(), chimneyColor );
|
||||
root->addChild( chimneyGeode.get() );
|
||||
}
|
||||
|
||||
{
|
||||
osg::ref_ptr<osg::Cylinder> chimney = new osg::Cylinder( osg::Vec3( -5.5, 3.0, 16.5 ), 0.1, 1.0 );
|
||||
osg::ref_ptr<osg::Geode> chimneyGeode = convertShapeToGeode( *chimney.get(), tessHints.get(), chimneyColor );
|
||||
root->addChild( chimneyGeode.get() );
|
||||
}
|
||||
|
||||
{
|
||||
osg::ref_ptr<osg::Cylinder> chimney = new osg::Cylinder( osg::Vec3( -5.0, 3.0, 16.25 ), 0.1, 0.5 );
|
||||
osg::ref_ptr<osg::Geode> chimneyGeode = convertShapeToGeode( *chimney.get(), tessHints.get(), chimneyColor );
|
||||
@@ -1183,6 +1328,7 @@ struct AnimateObjectsCallback : public osg::DrawableUpdateCallback
|
||||
for(; i<3*_quantityPerType; ++i) // speed of airplanes
|
||||
_speed.push_back( random( 10.0, 16.0 ) );
|
||||
}
|
||||
|
||||
virtual void update(osg::NodeVisitor* nv, osg::Drawable* drawable)
|
||||
{
|
||||
if( nv->getVisitorType() != osg::NodeVisitor::UPDATE_VISITOR )
|
||||
@@ -1213,6 +1359,7 @@ struct AnimateObjectsCallback : public osg::DrawableUpdateCallback
|
||||
setRotationUsingRotSpeed( i, 5, osg::Matrix::rotate( osg::DegreesToRadians(90.0), osg::Vec3(0.0,1.0,0.0)) * osg::Matrix::translate(0.0,2.0,-6.0), currentTime, 0.5 );
|
||||
setRotationUsingRotSpeed( i, 6, osg::Matrix::rotate( osg::DegreesToRadians(90.0), osg::Vec3(0.0,1.0,0.0)) * osg::Matrix::translate(0.0,-2.0,-6.0), currentTime, -0.5 );
|
||||
}
|
||||
|
||||
for(;i<2*_quantityPerType;++i) //update cars
|
||||
{
|
||||
nbbox.expandBy( updateObjectPosition( vertexArray, i, deltaTime ) );
|
||||
@@ -1223,6 +1370,7 @@ struct AnimateObjectsCallback : public osg::DrawableUpdateCallback
|
||||
setRotationUsingRotSpeed( i, 3, osg::Matrix::rotate( osg::DegreesToRadians(90.0), osg::Vec3(1.0,0.0,0.0)) * osg::Matrix::translate(2.0,-1.8,1.0), currentTime, wheelRotSpeed );
|
||||
setRotationUsingRotSpeed( i, 4, osg::Matrix::rotate( osg::DegreesToRadians(90.0), osg::Vec3(1.0,0.0,0.0)) * osg::Matrix::translate(-2.0,-1.8,1.0), currentTime, wheelRotSpeed );
|
||||
}
|
||||
|
||||
for(;i<3*_quantityPerType;++i) // update airplanes
|
||||
{
|
||||
nbbox.expandBy( updateObjectPosition( vertexArray, i, deltaTime ) );
|
||||
@@ -1251,6 +1399,7 @@ struct AnimateObjectsCallback : public osg::DrawableUpdateCallback
|
||||
(*vertexArray)[index] = newPosition;
|
||||
return newPosition;
|
||||
}
|
||||
|
||||
void setRotationUsingRotSpeed( unsigned int index, unsigned int boneIndex, const osg::Matrix& zeroMatrix, double currentTime, double rotSpeed )
|
||||
{
|
||||
// setRotationUsingRotSpeed() is a very unoptimally written ( because it uses osg::Matrix::inverse() ),
|
||||
@@ -1473,12 +1622,16 @@ int main( int argc, char **argv )
|
||||
|
||||
if ( arguments.read("--skip-static") )
|
||||
showStaticRendering = false;
|
||||
|
||||
if ( arguments.read("--skip-dynamic") )
|
||||
showDynamicRendering = false;
|
||||
|
||||
if ( arguments.read("--export-objects") )
|
||||
exportInstanceObjects = true;
|
||||
|
||||
if ( arguments.read("--use-multi-draw") )
|
||||
useMultiDrawArraysIndirect = true;
|
||||
|
||||
arguments.read("--instances-per-cell",instancesPerCell);
|
||||
arguments.read("--static-area-size",staticAreaSize);
|
||||
arguments.read("--dynamic-area-size",dynamicAreaSize);
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include <osgGA/TrackballManipulator>
|
||||
|
||||
#include <osgViewer/Viewer>
|
||||
#include <osgViewer/ViewerEventHandlers>
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/FileUtils>
|
||||
@@ -424,6 +425,9 @@ int main( int argc, char **argv )
|
||||
// add the handler for doing the picking
|
||||
viewer.addEventHandler(new PickHandler(&viewer,updateText.get()));
|
||||
|
||||
// add the stats handler
|
||||
viewer.addEventHandler(new osgViewer::StatsHandler);
|
||||
|
||||
osg::Group* root = new osg::Group();
|
||||
|
||||
root->addChild( setupGraph() );
|
||||
|
||||
@@ -41,6 +41,9 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
static bool s_useSDF = false;
|
||||
|
||||
class MyBillboardTransform : public osg::PositionAttitudeTransform
|
||||
{
|
||||
public:
|
||||
@@ -147,6 +150,12 @@ osg:: Node* createTextBelow(const osg::BoundingBox& bb, const std::string& label
|
||||
|
||||
text->setFont(font);
|
||||
text->setFontResolution(64,64);
|
||||
|
||||
if (s_useSDF)
|
||||
{
|
||||
text->setShaderTechnique(osgText::ALL_FEATURES);
|
||||
}
|
||||
|
||||
text->setAlignment(osgText::Text::CENTER_CENTER);
|
||||
text->setAxisAlignment(osgText::Text::XZ_PLANE);
|
||||
text->setPosition(bb.center()-osg::Vec3(0.0f,0.0f,(bb.zMax()-bb.zMin())));
|
||||
@@ -174,48 +183,35 @@ osg:: Node* createTextLeft(const osg::BoundingBox& bb, const std::string& label,
|
||||
|
||||
text->setFont(font);
|
||||
text->setFontResolution(110,120);
|
||||
|
||||
if (s_useSDF)
|
||||
{
|
||||
text->setShaderTechnique(osgText::ALL_FEATURES);
|
||||
}
|
||||
|
||||
text->setAlignment(osgText::Text::RIGHT_CENTER);
|
||||
text->setAxisAlignment(osgText::Text::XZ_PLANE);
|
||||
text->setCharacterSize((bb.zMax()-bb.zMin())*1.0f);
|
||||
|
||||
text->setPosition(bb.center()-osg::Vec3((bb.xMax()-bb.xMin()),-(bb.yMax()-bb.yMin())*0.5f,(bb.zMax()-bb.zMin())*0.1f));
|
||||
//text->setColor(osg::Vec4(0.37f,0.48f,0.67f,1.0f)); // Neil's original OSG colour
|
||||
text->setColor(osg::Vec4(0.20f,0.45f,0.60f,1.0f)); // OGL logo colour
|
||||
text->setText(label);
|
||||
|
||||
#if 1
|
||||
text->setBackdropType(osgText::Text::OUTLINE);
|
||||
// text->setBackdropType(osgText::Text::DROP_SHADOW_BOTTOM_RIGHT);
|
||||
|
||||
text->setBackdropImplementation(osgText::Text::POLYGON_OFFSET);
|
||||
// text->setBackdropImplementation(osgText::Text::NO_DEPTH_BUFFER);
|
||||
// text->setBackdropImplementation(osgText::Text::DEPTH_RANGE);
|
||||
// text->setBackdropImplementation(osgText::Text::STENCIL_BUFFER);
|
||||
|
||||
text->setBackdropOffset(0.05f);
|
||||
text->setBackdropOffset(0.03f);
|
||||
text->setBackdropColor(osg::Vec4(0.0f, 0.0f, 0.5f, 1.0f));
|
||||
#endif
|
||||
|
||||
|
||||
#if 1
|
||||
text->setColorGradientMode(osgText::Text::OVERALL);
|
||||
osg::Vec4 lightblue(0.30f,0.6f,0.90f,1.0f);
|
||||
osg::Vec4 blue(0.10f,0.30f,0.40f,1.0f);
|
||||
text->setColorGradientCorners(lightblue, blue, blue, lightblue);
|
||||
#else
|
||||
text->setColorGradientMode(osgText::Text::OVERALL);
|
||||
osg::Vec4 light = osg::Vec4(0.0f, 1.0f, 1.0f, 1.0f);
|
||||
osg::Vec4 dark = osg::Vec4(0.0f, 0.0f, 0.5f, 1.0f);
|
||||
text->setColorGradientCorners(light, dark, dark, light);
|
||||
// text->setColorGradientCorners(dark, light, light, dark);
|
||||
#endif
|
||||
|
||||
text->setText(label);
|
||||
|
||||
geode->addDrawable( text );
|
||||
|
||||
|
||||
if (!subscript.empty())
|
||||
{
|
||||
//osgText::Text* subscript = new osgText::Text(new osgText::TextureFont(font,45));
|
||||
|
||||
osgText::Text* subscriptText = new osgText::Text;
|
||||
subscriptText->setFont(font);
|
||||
subscriptText->setText(subscript);
|
||||
@@ -353,9 +349,6 @@ osg:: Node* createBoxNo5No2(const osg::BoundingBox& bb,float chordRatio)
|
||||
|
||||
osg:: Node* createBackdrop(const osg::Vec3& corner,const osg::Vec3& top,const osg::Vec3& right)
|
||||
{
|
||||
|
||||
|
||||
|
||||
osg::Geometry* geom = new osg::Geometry;
|
||||
|
||||
osg::Vec3 normal = (corner-top)^(right-corner);
|
||||
@@ -475,6 +468,9 @@ int main( int argc, char **argv )
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
while(arguments.read("--sdf")) { s_useSDF = true; }
|
||||
|
||||
std::string label = "OpenSceneGraph";
|
||||
std::string subscript = "";
|
||||
|
||||
|
||||
@@ -438,7 +438,7 @@ int main(int argc, char** argv)
|
||||
if (arguments.read("-devices") || arguments.read("--devices"))
|
||||
{
|
||||
// Force load QuickTime plugin, probe video capability, exit
|
||||
osgDB::readImageFile("devices.live");
|
||||
osgDB::readRefImageFile("devices.live");
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
#include <osg/Texture2D>
|
||||
#include <osg/Texture3D>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osgUtil/Optimizer>
|
||||
|
||||
#include <osg/Program>
|
||||
@@ -141,10 +140,10 @@ ModelInstance()
|
||||
static void
|
||||
LoadShaderSource( osg::Shader* shader, const std::string& fileName )
|
||||
{
|
||||
std::string fqFileName = osgDB::findDataFile(fileName);
|
||||
if( fqFileName.length() != 0 )
|
||||
osg::ref_ptr<osg::Shader> loaded_shader = osgDB::readRefShaderFile(fileName);
|
||||
if (loaded_shader)
|
||||
{
|
||||
shader->loadShaderSourceFromFile( fqFileName.c_str() );
|
||||
shader->setShaderSource( loaded_shader->getShaderSource() );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -69,10 +69,24 @@ int main( int argc, char**argv )
|
||||
arguments.read("--numX",MAXX);
|
||||
arguments.read("--numY",MAXY);
|
||||
|
||||
bool MDIenable=true;
|
||||
enum PrimtiveSetUsage
|
||||
{
|
||||
MultiDraw,
|
||||
MultiplePrimitiveSets,
|
||||
SinglePrimitiveSet
|
||||
};
|
||||
|
||||
PrimtiveSetUsage usage = MultiDraw;
|
||||
if(arguments.read("--classic"))
|
||||
{ MDIenable=false;
|
||||
OSG_WARN<<"disabling MDI"<<std::endl;
|
||||
{
|
||||
usage = MultiplePrimitiveSets;
|
||||
OSG_WARN<<"disabling MDI, using multiple PrimitiveSet"<<std::endl;
|
||||
}
|
||||
|
||||
if(arguments.read("--single"))
|
||||
{
|
||||
usage = SinglePrimitiveSet;
|
||||
OSG_WARN<<"disabling MDI, using single PrimitiveSet"<<std::endl;
|
||||
}
|
||||
|
||||
osg::Geode* root( new osg::Geode );
|
||||
@@ -86,6 +100,7 @@ int main( int argc, char**argv )
|
||||
|
||||
osg::ref_ptr<osg::Geometry> geom=new osg::Geometry();
|
||||
geom->setUseVertexBufferObjects(true);
|
||||
|
||||
osg::BoundingBox bb;
|
||||
bb.set(0,0,0,MAXX,0,MAXY);
|
||||
//set bounds by hand cause of the lack of support of basevertex in PrimitiveFunctors
|
||||
@@ -104,10 +119,10 @@ int main( int argc, char**argv )
|
||||
|
||||
osg::Vec3Array * verts=new osg::Vec3Array();
|
||||
|
||||
|
||||
for(int j =0 ; j<MAXY; ++j) {
|
||||
for(int i =0 ; i<MAXX; ++i) {
|
||||
|
||||
for(int j =0 ; j<MAXY; ++j)
|
||||
{
|
||||
for(int i =0 ; i<MAXX; ++i)
|
||||
{
|
||||
///create indirect command
|
||||
osg::DrawElementsIndirectCommand cmd;
|
||||
cmd.count=4;
|
||||
@@ -116,24 +131,58 @@ int main( int argc, char**argv )
|
||||
cmd.baseVertex=verts->size();
|
||||
mdicommands->push_back(cmd);
|
||||
|
||||
for(int z=0; z<4; z++) {
|
||||
for(int z=0; z<4; z++)
|
||||
{
|
||||
verts->push_back(osg::Vec3(i,0,j)+myCoords[z]);
|
||||
mdi->addElement(myIndices[z]);
|
||||
}
|
||||
}
|
||||
}
|
||||
geom->setVertexArray(verts);
|
||||
if(MDIenable) {
|
||||
geom->addPrimitiveSet(mdi);
|
||||
|
||||
} else
|
||||
for(int i=0; i<MAXY*MAXX; ++i) {
|
||||
osg::DrawElementsUInt *dre=new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLE_STRIP,4,myIndicesUI) ;
|
||||
dre->setElementBufferObject(ebo);
|
||||
geom->addPrimitiveSet(dre);
|
||||
for(int z=0; z<4; z++)myIndicesUI[z]+=4;
|
||||
geom->setVertexArray(verts);
|
||||
|
||||
switch(usage)
|
||||
{
|
||||
case(MultiDraw):
|
||||
{
|
||||
geom->addPrimitiveSet(mdi);
|
||||
break;
|
||||
|
||||
}
|
||||
case(MultiplePrimitiveSets):
|
||||
{
|
||||
for(int i=0; i<MAXY*MAXX; ++i)
|
||||
{
|
||||
osg::ref_ptr<osg::DrawElementsUInt> dre = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLE_STRIP,4,myIndicesUI);
|
||||
dre->setElementBufferObject(ebo.get());
|
||||
geom->addPrimitiveSet(dre.get());
|
||||
for(int z=0; z<4; z++) myIndicesUI[z]+=4;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(SinglePrimitiveSet):
|
||||
{
|
||||
osg::ref_ptr<osg::DrawElementsUInt> primitives = new osg::DrawElementsUInt(GL_TRIANGLES);
|
||||
primitives->setElementBufferObject(ebo.get());
|
||||
geom->addPrimitiveSet(primitives.get());
|
||||
|
||||
unsigned int vi = 0;
|
||||
for(int i=0; i<MAXY*MAXX; ++i)
|
||||
{
|
||||
primitives->push_back(vi);
|
||||
primitives->push_back(vi+2);
|
||||
primitives->push_back(vi+1);
|
||||
primitives->push_back(vi+1);
|
||||
primitives->push_back(vi+2);
|
||||
primitives->push_back(vi+3);
|
||||
vi += 4;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
root->addChild(geom);
|
||||
|
||||
osgViewer::Viewer viewer;
|
||||
viewer.addEventHandler(new osgViewer::StatsHandler);
|
||||
viewer.setSceneData( root );
|
||||
|
||||
@@ -170,7 +170,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
// load the data
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
if (!loadedModel)
|
||||
{
|
||||
std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "StereoMultipass.h"
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <iostream>
|
||||
|
||||
SubtractPass::SubtractPass(osg::TextureRectangle *left_tex,
|
||||
@@ -132,8 +132,12 @@ void SubtractPass::createOutputTextures()
|
||||
|
||||
void SubtractPass::setShader(std::string filename)
|
||||
{
|
||||
osg::ref_ptr<osg::Shader> fshader = new osg::Shader( osg::Shader::FRAGMENT );
|
||||
fshader->loadShaderSourceFromFile(osgDB::findDataFile(filename));
|
||||
osg::ref_ptr<osg::Shader> fshader = osgDB::readRefShaderFile( osg::Shader::FRAGMENT, filename);
|
||||
if (!fshader)
|
||||
{
|
||||
OSG_NOTICE<<"Warning: could not file shader file : "<<filename<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
_FragmentProgram = 0;
|
||||
_FragmentProgram = new osg::Program;
|
||||
@@ -259,8 +263,12 @@ void AggregatePass::setupCamera()
|
||||
|
||||
void AggregatePass::setShader(std::string filename)
|
||||
{
|
||||
osg::ref_ptr<osg::Shader> fshader = new osg::Shader( osg::Shader::FRAGMENT );
|
||||
fshader->loadShaderSourceFromFile(osgDB::findDataFile(filename));
|
||||
osg::ref_ptr<osg::Shader> fshader = osgDB::readRefShaderFile( osg::Shader::FRAGMENT, filename);
|
||||
if (!fshader)
|
||||
{
|
||||
OSG_NOTICE<<"Warning: could not file shader file : "<<filename<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
_FragmentProgram = 0;
|
||||
_FragmentProgram = new osg::Program;
|
||||
@@ -375,8 +383,12 @@ void SelectPass::createOutputTextures()
|
||||
|
||||
void SelectPass::setShader(std::string filename)
|
||||
{
|
||||
osg::ref_ptr<osg::Shader> fshader = new osg::Shader( osg::Shader::FRAGMENT );
|
||||
fshader->loadShaderSourceFromFile(osgDB::findDataFile(filename));
|
||||
osg::ref_ptr<osg::Shader> fshader = osgDB::readRefShaderFile( osg::Shader::FRAGMENT, filename);
|
||||
if (!fshader)
|
||||
{
|
||||
OSG_NOTICE<<"Warning: could not file shader file : "<<filename<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
_FragmentProgram = 0;
|
||||
_FragmentProgram = new osg::Program;
|
||||
@@ -524,8 +536,12 @@ void StereoMultipass::createOutputTextures()
|
||||
|
||||
void StereoMultipass::setShader(std::string filename)
|
||||
{
|
||||
osg::ref_ptr<osg::Shader> fshader = new osg::Shader( osg::Shader::FRAGMENT );
|
||||
fshader->loadShaderSourceFromFile(osgDB::findDataFile(filename));
|
||||
osg::ref_ptr<osg::Shader> fshader = osgDB::readRefShaderFile( osg::Shader::FRAGMENT, filename);
|
||||
if (!fshader)
|
||||
{
|
||||
OSG_NOTICE<<"Warning: could not file shader file : "<<filename<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
_FragmentProgram = 0;
|
||||
_FragmentProgram = new osg::Program;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "StereoPass.h"
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <iostream>
|
||||
|
||||
StereoPass::StereoPass(osg::TextureRectangle *left_tex,
|
||||
@@ -129,8 +129,12 @@ void StereoPass::createOutputTextures()
|
||||
|
||||
void StereoPass::setShader(std::string filename)
|
||||
{
|
||||
osg::ref_ptr<osg::Shader> fshader = new osg::Shader( osg::Shader::FRAGMENT );
|
||||
fshader->loadShaderSourceFromFile(osgDB::findDataFile(filename));
|
||||
osg::ref_ptr<osg::Shader> fshader = osgDB::readRefShaderFile( osg::Shader::FRAGMENT, filename);
|
||||
if (!fshader)
|
||||
{
|
||||
OSG_NOTICE<<"Warning: could not file shader file : "<<filename<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
_FragmentProgram = 0;
|
||||
_FragmentProgram = new osg::Program;
|
||||
|
||||
@@ -621,8 +621,8 @@ struct TextCounterCallback : public osg::NodeCallback
|
||||
if (text)
|
||||
{
|
||||
std::stringstream str;
|
||||
str <<"Text Counter "<<_textCounter<<std::endl;
|
||||
OSG_NOTICE<<"Udating text"<<str.str()<<std::endl;
|
||||
str <<"Text Counter "<<_textCounter;
|
||||
OSG_NOTICE<<"Updating text : "<<str.str()<<std::endl;
|
||||
|
||||
text->setText(str.str());
|
||||
|
||||
@@ -670,7 +670,7 @@ int main(int argc, char** argv)
|
||||
text->setUpdateCallback(new TextCounterCallback());
|
||||
text->setFont("fonts/times.ttf");
|
||||
text->setAxisAlignment(osgText::Text::XZ_PLANE);
|
||||
text->setText("This is a counter test");
|
||||
text->setText("Text Counter :");
|
||||
|
||||
viewer.setSceneData(text.get());
|
||||
}
|
||||
|
||||
@@ -250,7 +250,9 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
if (arguments.read("--add-axes"))
|
||||
group->addChild(osgDB::readNodeFile("axes.osgt"));
|
||||
{
|
||||
group->addChild(osgDB::readRefNodeFile("axes.osgt"));
|
||||
}
|
||||
|
||||
std::string mode;
|
||||
if (arguments.read("--character-size-mode", mode))
|
||||
|
||||
@@ -407,13 +407,12 @@ int main(int argc, char ** argv)
|
||||
osg::ArgumentParser arguments(&argc, argv);
|
||||
|
||||
#if 0
|
||||
|
||||
osg::ref_ptr<MyClass> myobject = new MyClass;
|
||||
myobject->getOrCreateUserDataContainer()->addUserObject(new osg::CallbackObject("myMethod"));
|
||||
myobject->myMethod();
|
||||
|
||||
osg::ref_ptr<osg::ScriptEngine> se = osgDB::readFile<osg::ScriptEngine>("ScriptEngine.lua");
|
||||
osg::ref_ptr<osg::Script> script = osgDB::readFile<osg::Script>("script.lua");
|
||||
osg::ref_ptr<osg::ScriptEngine> se = osgDB::readRefFile<osg::ScriptEngine>("ScriptEngine.lua");
|
||||
osg::ref_ptr<osg::Script> script = osgDB::readRefFile<osg::Script>("script.lua");
|
||||
|
||||
osg::ref_ptr<MyClass> copyobject = new MyClass;
|
||||
copyobject->getOrCreateUserDataContainer()->addUserObject(new MyScriptCallback(se.get(), script.get(), "myMethod"));
|
||||
@@ -421,7 +420,7 @@ int main(int argc, char ** argv)
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
osg::ref_ptr<osg::Object> object = osgDB::readNodeFile("load.lua");
|
||||
osg::ref_ptr<osg::Object> object = osgDB::readRefNodeFile("load.lua");
|
||||
if (object.valid())
|
||||
{
|
||||
osg::CallbackObject* co = osg::getCallbackObject(object.get(), "method");
|
||||
|
||||
@@ -432,7 +432,6 @@ static void Internal_SetAlpha(NSBitmapImageRep *imageRep, unsigned char alpha_va
|
||||
|
||||
default_text->setAlignment(osgText::Text::CENTER_CENTER);
|
||||
default_text->setBackdropType(osgText::Text::OUTLINE);
|
||||
// default_text->setBackdropImplementation(osgText::Text::POLYGON_OFFSET);
|
||||
default_text->setColor(osg::Vec4(1.0, 1.0, 0.0, 1.0));
|
||||
default_text->setBackdropColor(osg::Vec4(0.0, 0.0, 0.0, 1.0));
|
||||
default_text->setAxisAlignment(osgText::Text::XZ_PLANE);
|
||||
@@ -1194,7 +1193,7 @@ A -respondsToSelector: check has been used to provide compatibility with previou
|
||||
// int number_of_files = [file_names count];
|
||||
// Exercise for the reader: Try loading all files in the array
|
||||
NSString* single_file = [file_names objectAtIndex:0];
|
||||
osg::ref_ptr<osg::Node> loaded_model = osgDB::readNodeFile([single_file fileSystemRepresentation]);
|
||||
osg::ref_ptr<osg::Node> loaded_model = osgDB::readRefNodeFile([single_file fileSystemRepresentation]);
|
||||
if(!loaded_model)
|
||||
{
|
||||
NSLog(@"File: %@ failed to load", single_file);
|
||||
@@ -1213,7 +1212,7 @@ A -respondsToSelector: check has been used to provide compatibility with previou
|
||||
return NO;
|
||||
}
|
||||
NSString* file_path = [file_url path];
|
||||
osg::ref_ptr<osg::Node> loaded_model = osgDB::readNodeFile([file_path fileSystemRepresentation]);
|
||||
osg::ref_ptr<osg::Node> loaded_model = osgDB::readRefNodeFile([file_path fileSystemRepresentation]);
|
||||
if(!loaded_model)
|
||||
{
|
||||
NSLog(@"URL: %@ failed to load, %@", file_url, file_path);
|
||||
|
||||
@@ -140,7 +140,7 @@ int main( int argc, char **argv )
|
||||
osg::ArgumentParser arguments(&argc, argv);
|
||||
|
||||
// load the scene.
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
|
||||
if (!loadedModel)
|
||||
{
|
||||
std::cout << argv[0] <<": No data loaded." << std::endl;
|
||||
|
||||
@@ -39,7 +39,7 @@ FOX_OSG_MDIView::FOX_OSG_MDIView(FXMDIClient *p, const FXString &name,
|
||||
viewer->setKeyEventSetsDone(0);
|
||||
|
||||
// load the scene.
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile("cow.osgt");
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFile("cow.osgt");
|
||||
if (!loadedModel)
|
||||
{
|
||||
return ;
|
||||
|
||||
@@ -69,7 +69,7 @@ class ExampleOSGGTKDrawingArea : public OSGGTKDrawingArea {
|
||||
if(gtk_dialog_run(GTK_DIALOG(of)) == GTK_RESPONSE_ACCEPT) {
|
||||
char* file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(of));
|
||||
|
||||
osg::ref_ptr<osg::Node> model = osgDB::readNodeFile(file);
|
||||
osg::ref_ptr<osg::Node> model = osgDB::readRefNodeFile(file);
|
||||
|
||||
if(model.valid()) {
|
||||
setSceneData(model.get());
|
||||
@@ -170,7 +170,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
if(da.createWidget(640, 480)) {
|
||||
if(argc >= 2) {
|
||||
osg::ref_ptr<osg::Node> model = osgDB::readNodeFile(argv[1]);
|
||||
osg::ref_ptr<osg::Node> model = osgDB::readRefNodeFile(argv[1]);
|
||||
|
||||
if(model.valid()) da.setSceneData(model.get());
|
||||
}
|
||||
|
||||
@@ -337,7 +337,7 @@ private:
|
||||
_root->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
|
||||
|
||||
//load and attach scene model
|
||||
osg::ref_ptr<osg::Node> model = osgDB::readNodeFile(osgDB::findDataFile("lz.osg"));
|
||||
osg::ref_ptr<osg::Node> model = osgDB::readRefNodeFile(osgDB::findDataFile("lz.osg"));
|
||||
if (!model) {
|
||||
osg::Geode* geode = new osg::Geode();
|
||||
osg::ShapeDrawable* drawable = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0,0,0), 1));
|
||||
|
||||
@@ -69,7 +69,7 @@ bool wxOsgApp::OnInit()
|
||||
|
||||
// load the scene.
|
||||
wxString fname(argv[1]);
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile(std::string(fname.mb_str()));
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFile(std::string(fname.mb_str()));
|
||||
if (!loadedModel)
|
||||
{
|
||||
std::cout << argv[0] <<": No data loaded." << std::endl;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
class EscapeHandler : public osgGA::GUIEventHandler
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
EscapeHandler() {}
|
||||
|
||||
bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
|
||||
@@ -22,7 +22,7 @@ class EscapeHandler : public osgGA::GUIEventHandler
|
||||
{
|
||||
osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
|
||||
if (view) view->getViewerBase()->setDone(true);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,8 @@ class EscapeHandler : public osgGA::GUIEventHandler
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
osg::ArgumentParser arguments(&argc, argv);
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--login <url> <username> <password>", "Provide authentication information for http file access.");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--password <password>", "Provide password for any vnc url on command line not mentioned in --login.");
|
||||
osgViewer::Viewer viewer(arguments);
|
||||
|
||||
osgWidget::GeometryHints hints(osg::Vec3(0.0f,0.0f,0.0f),
|
||||
@@ -52,6 +54,15 @@ int main(int argc,char** argv)
|
||||
{
|
||||
}
|
||||
|
||||
std::string url, username;
|
||||
while (arguments.read("--login", url, username, password))
|
||||
{
|
||||
osgDB::Registry::instance()->getOrCreateAuthenticationMap()->addAuthenticationDetails(
|
||||
url,
|
||||
new osgDB::AuthenticationDetails(username, password)
|
||||
);
|
||||
}
|
||||
|
||||
for(int i=1; i<arguments.argc(); ++i)
|
||||
{
|
||||
if (!arguments.isOption(i))
|
||||
@@ -60,15 +71,19 @@ int main(int argc,char** argv)
|
||||
|
||||
if (!password.empty())
|
||||
{
|
||||
if (!osgDB::Registry::instance()->getAuthenticationMap()) osgDB::Registry::instance()->setAuthenticationMap(new osgDB::AuthenticationMap);
|
||||
osgDB::Registry::instance()->getAuthenticationMap()->addAuthenticationDetails(hostname, new osgDB::AuthenticationDetails("", password));
|
||||
osgDB::AuthenticationMap* authenticationMap = osgDB::Registry::instance()->getOrCreateAuthenticationMap();
|
||||
const osgDB::AuthenticationDetails* details = authenticationMap->getAuthenticationDetails(hostname);
|
||||
if (details == NULL)
|
||||
{
|
||||
authenticationMap->addAuthenticationDetails(hostname, new osgDB::AuthenticationDetails("", password));
|
||||
}
|
||||
}
|
||||
|
||||
osg::ref_ptr<osgWidget::VncClient> vncClient = new osgWidget::VncClient;
|
||||
if (vncClient->connect(arguments[i], hints))
|
||||
{
|
||||
{
|
||||
group->addChild(vncClient.get());
|
||||
|
||||
|
||||
hints.position.x() += 1.1f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,12 +30,6 @@ osgWidget::Label* createLabel(const std::string& l, unsigned int size=13) {
|
||||
label->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
label->setLabel(l);
|
||||
|
||||
/*
|
||||
text->setBackdropType(osgText::Text::DROP_SHADOW_BOTTOM_RIGHT);
|
||||
text->setBackdropImplementation(osgText::Text::NO_DEPTH_BUFFER);
|
||||
text->setBackdropOffset(0.2f);
|
||||
*/
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
|
||||
// $Id: osgwidgetshader.cpp 28 2008-03-26 15:26:48Z cubicool $
|
||||
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgWidget/Util>
|
||||
#include <osgWidget/WindowManager>
|
||||
#include <osgWidget/Canvas>
|
||||
@@ -60,15 +60,9 @@ int main(int, char**)
|
||||
|
||||
osg::Program* program = new osg::Program();
|
||||
|
||||
program->addShader(osg::Shader::readShaderFile(
|
||||
osg::Shader::VERTEX,
|
||||
osgDB::findDataFile("osgWidget/osgwidgetshader-vert.glsl")
|
||||
));
|
||||
|
||||
program->addShader(osg::Shader::readShaderFile(
|
||||
osg::Shader::FRAGMENT,
|
||||
osgDB::findDataFile("osgWidget/osgwidgetshader-frag.glsl")
|
||||
));
|
||||
program->addShader(osgDB::readRefShaderFile( osg::Shader::VERTEX, "osgWidget/osgwidgetshader-vert.glsl" ) );
|
||||
program->addShader(osgDB::readRefShaderFile( osg::Shader::FRAGMENT, "osgWidget/osgwidgetshader-frag.glsl" ) );
|
||||
|
||||
canvas->getGeode()->getOrCreateStateSet()->setAttribute(program);
|
||||
|
||||
|
||||
55
include/osg/ComputeDispatch
Normal file
55
include/osg/ComputeDispatch
Normal file
@@ -0,0 +1,55 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 Robert Osfield
|
||||
* Copyright (C) 2017 Julien Valentin
|
||||
*
|
||||
* 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_COMPUTEDISPATCH
|
||||
#define OSG_COMPUTEDISPATCH 1
|
||||
|
||||
#include <osg/Export>
|
||||
|
||||
#include <osg/Geometry>
|
||||
|
||||
namespace osg{
|
||||
class OSG_EXPORT ComputeDispatch : public osg::Drawable
|
||||
{
|
||||
public:
|
||||
ComputeDispatch(GLint numGroupsX=0, GLint numGroupsY=0, GLint numGroupsZ=0):
|
||||
Drawable(),
|
||||
_numGroupsX(numGroupsX),
|
||||
_numGroupsY(numGroupsY),
|
||||
_numGroupsZ(numGroupsZ)
|
||||
{}
|
||||
|
||||
ComputeDispatch(const ComputeDispatch&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Node(osg, ComputeDispatch);
|
||||
|
||||
virtual void compileGLObjects(RenderInfo&) const {}
|
||||
|
||||
virtual VertexArrayState* createVertexArrayStateImplememtation(RenderInfo&) const { return 0; }
|
||||
|
||||
virtual void drawImplementation(RenderInfo& renderInfo) const;
|
||||
|
||||
/** Set compute shader work groups */
|
||||
void setComputeGroups( GLint numGroupsX, GLint numGroupsY, GLint numGroupsZ ) { _numGroupsX=numGroupsX; _numGroupsY=numGroupsY; _numGroupsZ=numGroupsZ; }
|
||||
|
||||
/** Get compute shader work groups */
|
||||
void getComputeGroups( GLint& numGroupsX, GLint& numGroupsY, GLint& numGroupsZ ) const{ numGroupsX=_numGroupsX; numGroupsY=_numGroupsY; numGroupsZ=_numGroupsZ; }
|
||||
|
||||
protected:
|
||||
GLint _numGroupsX, _numGroupsY, _numGroupsZ;
|
||||
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -319,9 +320,15 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced
|
||||
SHADER_GLES3
|
||||
};
|
||||
|
||||
void setShaderHint(ShaderHint hint) { _shaderHint = hint; }
|
||||
/** set the ShaderHint to tells shader generating cdoes version to create.
|
||||
* By default also OSG_GLSL_VERSION and OSG_PRECISION_FLOAT values that can get use directly in shaders using $OSG_GLSL_VERSION and $OSG_PRECISION_FLOAT respectively.*/
|
||||
void setShaderHint(ShaderHint hint, bool setShaderValues=true);
|
||||
ShaderHint getShaderHint() const { return _shaderHint; }
|
||||
|
||||
/** Set the TextShaderTechnique that is used in the Text default constructor to choose which osgText::ShaderTechnique to use.*/
|
||||
void setTextShaderTechnique(const std::string& str) { _textShaderTechnique = str; }
|
||||
const std::string& getTextShaderTechnique() const { return _textShaderTechnique; }
|
||||
|
||||
|
||||
void setKeystoneHint(bool enabled) { _keystoneHint = enabled; }
|
||||
bool getKeystoneHint() const { return _keystoneHint; }
|
||||
@@ -358,6 +365,11 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced
|
||||
/** helper function for computing the right eye view matrix.*/
|
||||
virtual osg::Matrixd computeRightEyeViewImplementation(const osg::Matrixd& view, double eyeSeperationScale=1.0) const;
|
||||
|
||||
|
||||
void setValue(const std::string& name, const std::string& value);
|
||||
|
||||
bool getValue(const std::string& name, std::string& value, bool use_getenv_fallback=true) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~DisplaySettings();
|
||||
@@ -415,6 +427,7 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced
|
||||
|
||||
VertexBufferHint _vertexBufferHint;
|
||||
ShaderHint _shaderHint;
|
||||
std::string _textShaderTechnique;
|
||||
|
||||
bool _keystoneHint;
|
||||
FileNames _keystoneFileNames;
|
||||
@@ -422,6 +435,11 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced
|
||||
|
||||
OSXMenubarBehavior _OSXMenubarBehavior;
|
||||
|
||||
typedef std::map<std::string, std::string> ValueMap;
|
||||
|
||||
mutable OpenThreads::Mutex _valueMapMutex;
|
||||
mutable ValueMap _valueMap;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -278,7 +278,53 @@ class OSG_EXPORT Drawable : public Node
|
||||
*/
|
||||
virtual void compileGLObjects(RenderInfo& renderInfo) const;
|
||||
|
||||
virtual VertexArrayState* createVertexArrayState(RenderInfo& renderInfo) const;
|
||||
|
||||
/** Callback class for overriding the default Drawable::createCreateVertexArrayStateImplementation().*/
|
||||
struct CreateVertexArrayStateCallback : public virtual osg::Object
|
||||
{
|
||||
CreateVertexArrayStateCallback() {}
|
||||
|
||||
CreateVertexArrayStateCallback(const CreateVertexArrayStateCallback& rhs,const CopyOp& copyop):
|
||||
Object(rhs, copyop) {}
|
||||
|
||||
META_Object(osg, CreateVertexArrayStateCallback);
|
||||
|
||||
/** do customized createVertexArrayState .*/
|
||||
virtual osg::VertexArrayState* createVertexArrayStateImplementation(osg::RenderInfo& renderInfo, const osg::Drawable* drawable) const
|
||||
{
|
||||
return drawable->createVertexArrayStateImplementation(renderInfo);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** Set the callback to override the default Drawable::createCreateVertexArrayStateImplementation().*/
|
||||
void setCreateVertexArrayStateCallback(CreateVertexArrayStateCallback* cb) { _createVertexArrayStateCallback = cb; }
|
||||
|
||||
/** Get the callback that overrides the default Drawable::createCreateVertexArrayStateImplementation().*/
|
||||
CreateVertexArrayStateCallback* getCreateVertexArrayStateCallback() { return _createVertexArrayStateCallback.get(); }
|
||||
|
||||
/** Get the const callback that overrides the default Drawable::createCreateVertexArrayStateImplementation().*/
|
||||
const CreateVertexArrayStateCallback* getCreateVertexArrayStateCallback() const { return _createVertexArrayStateCallback.get(); }
|
||||
|
||||
|
||||
/** Craeate tje VertexArrayState object used to track vertex array and vertex array object state. This method will be called automatically during rendering setup so users should not call this themselves.*/
|
||||
inline VertexArrayState* createVertexArrayState(RenderInfo& renderInfo) const
|
||||
{
|
||||
if (_createVertexArrayStateCallback.valid()) return _createVertexArrayStateCallback->createVertexArrayStateImplementation(renderInfo, this);
|
||||
else return createVertexArrayStateImplementation(renderInfo);
|
||||
}
|
||||
|
||||
/** Implementaion of Craeate tje VertexArrayState object.*/
|
||||
virtual VertexArrayState* createVertexArrayStateImplementation(RenderInfo& renderInfo) const;
|
||||
|
||||
typedef buffered_object< osg::ref_ptr<VertexArrayState> > VertexArrayStateList;
|
||||
|
||||
void setVertexArrayStateList(VertexArrayStateList& vasl) { _vertexArrayStateList = vasl; }
|
||||
|
||||
VertexArrayStateList& getVertexArrayStateList() { return _vertexArrayStateList; }
|
||||
|
||||
const VertexArrayStateList& getVertexArrayStateList() const { return _vertexArrayStateList; }
|
||||
|
||||
|
||||
|
||||
/** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/
|
||||
@@ -491,10 +537,10 @@ class OSG_EXPORT Drawable : public Node
|
||||
typedef osg::buffered_value<GLuint> GLObjectList;
|
||||
mutable GLObjectList _globjList;
|
||||
|
||||
typedef buffered_object< osg::ref_ptr<VertexArrayState> > VertexArrayStateList;
|
||||
mutable VertexArrayStateList _vertexArrayStateList;
|
||||
|
||||
ref_ptr<DrawCallback> _drawCallback;
|
||||
ref_ptr<CreateVertexArrayStateCallback> _createVertexArrayStateCallback;
|
||||
};
|
||||
|
||||
#ifdef INLINE_DRAWABLE_DRAW
|
||||
|
||||
118
include/osg/EnvVar
Normal file
118
include/osg/EnvVar
Normal file
@@ -0,0 +1,118 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2017 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_EnvVar
|
||||
#define OSG_EnvVar 1
|
||||
|
||||
#include <osg/Config>
|
||||
|
||||
#ifdef OSG_ENVVAR_SUPPORTED
|
||||
#include <stdlib.h>
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
namespace osg {
|
||||
|
||||
inline unsigned int getClampedLength(const char* str, unsigned int maxNumChars=4096)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
while(i<maxNumChars && str[i]!=0) { ++i; }
|
||||
return i;
|
||||
}
|
||||
|
||||
inline std::string getEnvVar(const char* name)
|
||||
{
|
||||
std::string value;
|
||||
const char* ptr = getenv(name);
|
||||
if (ptr) value.assign(ptr, getClampedLength(ptr));
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline bool getEnvVar(const char* name, T& value)
|
||||
{
|
||||
#ifdef OSG_ENVVAR_SUPPORTED
|
||||
const char* ptr = getenv(name);
|
||||
if (!ptr) return false;
|
||||
|
||||
std::istringstream str(std::string(ptr, getClampedLength(ptr)));
|
||||
str >> value;
|
||||
return !str.fail();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
template<>
|
||||
inline bool getEnvVar(const char* name, std::string& value)
|
||||
{
|
||||
#ifdef OSG_ENVVAR_SUPPORTED
|
||||
const char* ptr = getenv(name);
|
||||
if (!ptr) return false;
|
||||
|
||||
value.assign(ptr, getClampedLength(ptr));
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
inline bool getEnvVar(const char* name, T1& value1, T2& value2)
|
||||
{
|
||||
#ifdef OSG_ENVVAR_SUPPORTED
|
||||
const char* ptr = getenv(name);
|
||||
if (!ptr) return false;
|
||||
|
||||
std::istringstream str(std::string(ptr, getClampedLength(ptr)));
|
||||
str >> value1 >> value2;
|
||||
return !str.fail();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3>
|
||||
inline bool getEnvVar(const char* name, T1& value1, T2& value2, T3& value3)
|
||||
{
|
||||
#ifdef OSG_ENVVAR_SUPPORTED
|
||||
const char* ptr = getenv(name);
|
||||
if (!ptr) return false;
|
||||
|
||||
std::istringstream str(std::string(ptr, getClampedLength(ptr)));
|
||||
str >> value1 >> value2 >> value3;
|
||||
return !str.fail();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T1, typename T2, typename T3, typename T4>
|
||||
inline bool getEnvVar(const char* name, T1& value1, T2& value2, T3& value3, T4& value4)
|
||||
{
|
||||
#ifdef OSG_ENVVAR_SUPPORTED
|
||||
const char* ptr = getenv(name);
|
||||
if (!ptr) return false;
|
||||
|
||||
std::istringstream str(std::string(ptr, getClampedLength(ptr)));
|
||||
str >> value1 >> value2 >> value3 >> value4;
|
||||
return !str.fail();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
# endif
|
||||
@@ -233,7 +233,7 @@ class OSG_EXPORT Geometry : public Drawable
|
||||
|
||||
bool _containsDeprecatedData;
|
||||
|
||||
virtual VertexArrayState* createVertexArrayState(RenderInfo& renderInfo) const;
|
||||
virtual VertexArrayState* createVertexArrayStateImplementation(RenderInfo& renderInfo) const;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <osg/BufferObject>
|
||||
#include <osg/Vec2>
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Vec3i>
|
||||
#include <osg/Vec4>
|
||||
#include <osg/FrameStamp>
|
||||
#include <osg/StateAttribute>
|
||||
@@ -68,6 +69,10 @@
|
||||
#endif
|
||||
|
||||
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE) || defined(OSG_GL3_AVAILABLE)
|
||||
#define GL_ALPHA4 0x803B
|
||||
#define GL_ALPHA8 0x803C
|
||||
#define GL_ALPHA12 0x803D
|
||||
#define GL_ALPHA16 0x803E
|
||||
#define GL_BITMAP 0x1A00
|
||||
#define GL_COLOR_INDEX 0x1900
|
||||
#define GL_INTENSITY12 0x804C
|
||||
@@ -114,6 +119,38 @@
|
||||
#define GL_COMPRESSED_SIGNED_RG11_EAC 0x9273
|
||||
#endif
|
||||
|
||||
#ifndef GL_KHR_texture_compression_astc_hdr
|
||||
#define GL_KHR_texture_compression_astc_hdr 1
|
||||
#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0
|
||||
#define GL_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1
|
||||
#define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2
|
||||
#define GL_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3
|
||||
#define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4
|
||||
#define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5
|
||||
#define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6
|
||||
#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7
|
||||
#define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8
|
||||
#define GL_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9
|
||||
#define GL_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA
|
||||
#define GL_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB
|
||||
#define GL_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC
|
||||
#define GL_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD
|
||||
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0
|
||||
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1
|
||||
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2
|
||||
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3
|
||||
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4
|
||||
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5
|
||||
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6
|
||||
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7
|
||||
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8
|
||||
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9
|
||||
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA
|
||||
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB
|
||||
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC
|
||||
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD
|
||||
#endif /* GL_KHR_texture_compression_astc_hdr */
|
||||
|
||||
#ifndef GL_DEPTH_COMPONENT
|
||||
#define GL_DEPTH_COMPONENT 0x1902
|
||||
#endif
|
||||
@@ -404,11 +441,17 @@ class OSG_EXPORT Image : public BufferData
|
||||
static bool isPackedType(GLenum type);
|
||||
static GLenum computePixelFormat(GLenum pixelFormat);
|
||||
static GLenum computeFormatDataType(GLenum pixelFormat);
|
||||
|
||||
/** return the dimensions of a block of compressed pixels */
|
||||
static osg::Vec3i computeBlockFootprint(GLenum pixelFormat);
|
||||
|
||||
/** return the size in bytes of a block of compressed pixels */
|
||||
static unsigned int computeBlockSize(GLenum pixelFormat, GLenum packing);
|
||||
static unsigned int computeNumComponents(GLenum pixelFormat);
|
||||
static unsigned int computePixelSizeInBits(GLenum pixelFormat,GLenum type);
|
||||
static unsigned int computeRowWidthInBytes(int width,GLenum pixelFormat,GLenum type,int packing);
|
||||
static unsigned int computeImageSizeInBytes(int width,int height, int depth, GLenum pixelFormat, GLenum type, int packing = 1, int slice_packing = 1, int image_packing = 1);
|
||||
static int roudUpToMultiple(int s, int pack);
|
||||
static int computeNearestPowerOfTwo(int s,float bias=0.5f);
|
||||
static int computeNumberOfMipmapLevels(int s,int t = 1, int r = 1);
|
||||
|
||||
|
||||
@@ -168,8 +168,8 @@ public:
|
||||
}
|
||||
|
||||
/// get command array of this indirect primitive set
|
||||
inline IndirectCommandDrawElements* getIndirectCommandArray() { return _indirectCommandArray; }
|
||||
inline const IndirectCommandDrawElements* getIndirectCommandArray() const { return _indirectCommandArray; }
|
||||
inline IndirectCommandDrawElements* getIndirectCommandArray() { return _indirectCommandArray.get(); }
|
||||
inline const IndirectCommandDrawElements* getIndirectCommandArray() const { return _indirectCommandArray.get(); }
|
||||
|
||||
///Further methods are for advanced DI when you plan to use your own IndirectCommandElement (stride)
|
||||
///or if you want to draw a particular command index of the IndirectCommandElement(FirstCommandToDraw)
|
||||
@@ -415,31 +415,48 @@ class OSG_EXPORT MultiDrawElementsIndirectUShort : public DrawElementsIndirectUS
|
||||
{
|
||||
public:
|
||||
MultiDrawElementsIndirectUShort(GLenum mode = 0/*,unsigned int firstCommand = 0, GLsizei stride = 0*/) :
|
||||
DrawElementsIndirectUShort(mode),_count(0) { _primitiveType=(Type(MultiDrawElementsUShortIndirectPrimitiveType)); }
|
||||
DrawElementsIndirectUShort(mode),
|
||||
_count(0)
|
||||
{
|
||||
_primitiveType=(Type(MultiDrawElementsUShortIndirectPrimitiveType));
|
||||
}
|
||||
|
||||
MultiDrawElementsIndirectUShort(const MultiDrawElementsIndirectUShort& mdi,const CopyOp& copyop=CopyOp::SHALLOW_COPY) :
|
||||
DrawElementsIndirectUShort(mdi,copyop),_count(mdi._count) {}
|
||||
DrawElementsIndirectUShort(mdi,copyop),
|
||||
_count(mdi._count)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* \param mode One of osg::PrimitiveSet::Mode. Determines the type of primitives used.
|
||||
* \param no Number of intended elements. This will be the size of the underlying vector.
|
||||
* \param ptr Pointer to a GLunsigned int to copy index data from.
|
||||
*/
|
||||
MultiDrawElementsIndirectUShort(GLenum mode, unsigned int no, const GLushort* ptr) :
|
||||
DrawElementsIndirectUShort(mode,no,ptr)
|
||||
{_primitiveType=(Type(MultiDrawElementsUShortIndirectPrimitiveType));}
|
||||
DrawElementsIndirectUShort(mode,no,ptr),
|
||||
_count(0)
|
||||
{
|
||||
_primitiveType=(Type(MultiDrawElementsUShortIndirectPrimitiveType));
|
||||
}
|
||||
|
||||
/**
|
||||
* \param mode One of osg::PrimitiveSet::Mode. Determines the type of primitives used.
|
||||
* \param no Number of intended elements. This will be the size of the underlying vector.
|
||||
*/
|
||||
MultiDrawElementsIndirectUShort(GLenum mode, unsigned int no) :
|
||||
DrawElementsIndirectUShort(mode,no)
|
||||
{_primitiveType=(Type(MultiDrawElementsUShortIndirectPrimitiveType));}
|
||||
DrawElementsIndirectUShort(mode,no),
|
||||
_count(0)
|
||||
{
|
||||
_primitiveType=(Type(MultiDrawElementsUShortIndirectPrimitiveType));
|
||||
}
|
||||
|
||||
template <class InputIterator>
|
||||
MultiDrawElementsIndirectUShort(GLenum mode, InputIterator first,InputIterator last) :
|
||||
DrawElementsIndirectUShort(mode,first,last)
|
||||
{_primitiveType=(Type(MultiDrawElementsUShortIndirectPrimitiveType));}
|
||||
DrawElementsIndirectUShort(mode,first,last),
|
||||
_count(0)
|
||||
{
|
||||
_primitiveType=(Type(MultiDrawElementsUShortIndirectPrimitiveType));
|
||||
}
|
||||
|
||||
virtual osg::Object* cloneType() const { return new MultiDrawElementsIndirectUShort(); }
|
||||
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new MultiDrawElementsIndirectUShort(*this,copyop); }
|
||||
@@ -467,31 +484,49 @@ class OSG_EXPORT MultiDrawElementsIndirectUByte : public DrawElementsIndirectUBy
|
||||
{
|
||||
public:
|
||||
MultiDrawElementsIndirectUByte(GLenum mode = 0) :
|
||||
DrawElementsIndirectUByte(mode),_count(0) { _primitiveType=(Type(MultiDrawElementsUByteIndirectPrimitiveType)); }
|
||||
DrawElementsIndirectUByte(mode),
|
||||
_count(0)
|
||||
{
|
||||
_primitiveType=(Type(MultiDrawElementsUByteIndirectPrimitiveType));
|
||||
|
||||
}
|
||||
|
||||
MultiDrawElementsIndirectUByte(const MultiDrawElementsIndirectUByte& mdi,const CopyOp& copyop=CopyOp::SHALLOW_COPY) :
|
||||
DrawElementsIndirectUByte(mdi,copyop),_count(mdi._count) {}
|
||||
DrawElementsIndirectUByte(mdi,copyop),
|
||||
_count(mdi._count)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* \param mode One of osg::PrimitiveSet::Mode. Determines the type of primitives used.
|
||||
* \param no Number of intended elements. This will be the size of the underlying vector.
|
||||
* \param ptr Pointer to a GLunsigned int to copy index data from.
|
||||
*/
|
||||
MultiDrawElementsIndirectUByte(GLenum mode, unsigned int no, const GLubyte* ptr) :
|
||||
DrawElementsIndirectUByte(mode,no,ptr)
|
||||
{_primitiveType=(Type(MultiDrawElementsUByteIndirectPrimitiveType));}
|
||||
DrawElementsIndirectUByte(mode,no,ptr),
|
||||
_count(0)
|
||||
{
|
||||
_primitiveType=(Type(MultiDrawElementsUByteIndirectPrimitiveType));
|
||||
}
|
||||
|
||||
/**
|
||||
* \param mode One of osg::PrimitiveSet::Mode. Determines the type of primitives used.
|
||||
* \param no Number of intended elements. This will be the size of the underlying vector.
|
||||
*/
|
||||
MultiDrawElementsIndirectUByte(GLenum mode, unsigned int no) :
|
||||
DrawElementsIndirectUByte(mode,no)
|
||||
{_primitiveType=(Type(MultiDrawElementsUByteIndirectPrimitiveType));}
|
||||
DrawElementsIndirectUByte(mode,no),
|
||||
_count(0)
|
||||
{
|
||||
_primitiveType=(Type(MultiDrawElementsUByteIndirectPrimitiveType));
|
||||
}
|
||||
|
||||
template <class InputIterator>
|
||||
MultiDrawElementsIndirectUByte(GLenum mode, InputIterator first,InputIterator last) :
|
||||
DrawElementsIndirectUByte(mode,first,last)
|
||||
{_primitiveType=(Type(MultiDrawElementsUByteIndirectPrimitiveType));}
|
||||
DrawElementsIndirectUByte(mode,first,last),
|
||||
_count(0)
|
||||
{
|
||||
_primitiveType=(Type(MultiDrawElementsUByteIndirectPrimitiveType));
|
||||
}
|
||||
|
||||
virtual osg::Object* cloneType() const { return new MultiDrawElementsIndirectUByte(); }
|
||||
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new MultiDrawElementsIndirectUByte(*this,copyop); }
|
||||
@@ -517,31 +552,47 @@ class OSG_EXPORT MultiDrawElementsIndirectUInt : public DrawElementsIndirectUInt
|
||||
{
|
||||
public:
|
||||
MultiDrawElementsIndirectUInt(GLenum mode = 0) :
|
||||
DrawElementsIndirectUInt(mode),_count(0) { _primitiveType=(Type(MultiDrawElementsUIntIndirectPrimitiveType)); }
|
||||
DrawElementsIndirectUInt(mode),
|
||||
_count(0)
|
||||
{
|
||||
_primitiveType=(Type(MultiDrawElementsUIntIndirectPrimitiveType));
|
||||
}
|
||||
|
||||
MultiDrawElementsIndirectUInt(const MultiDrawElementsIndirectUInt& mdi,const CopyOp& copyop=CopyOp::SHALLOW_COPY) :
|
||||
DrawElementsIndirectUInt(mdi,copyop),_count(mdi._count) {}
|
||||
DrawElementsIndirectUInt(mdi,copyop),
|
||||
_count(mdi._count)
|
||||
{}
|
||||
|
||||
/**
|
||||
* \param mode One of osg::PrimitiveSet::Mode. Determines the type of primitives used.
|
||||
* \param no Number of intended elements. This will be the size of the underlying vector.
|
||||
* \param ptr Pointer to a GLunsigned int to copy index data from.
|
||||
*/
|
||||
MultiDrawElementsIndirectUInt(GLenum mode, unsigned int no, const GLuint* ptr) :
|
||||
DrawElementsIndirectUInt(mode,no,ptr)
|
||||
{_primitiveType=(Type(MultiDrawElementsUIntIndirectPrimitiveType));}
|
||||
DrawElementsIndirectUInt(mode,no,ptr),
|
||||
_count(0)
|
||||
{
|
||||
_primitiveType=(Type(MultiDrawElementsUIntIndirectPrimitiveType));
|
||||
}
|
||||
|
||||
/**
|
||||
* \param mode One of osg::PrimitiveSet::Mode. Determines the type of primitives used.
|
||||
* \param no Number of intended elements. This will be the size of the underlying vector.
|
||||
*/
|
||||
MultiDrawElementsIndirectUInt(GLenum mode, unsigned int no) :
|
||||
DrawElementsIndirectUInt(mode,no)
|
||||
{_primitiveType=(Type(MultiDrawElementsUIntIndirectPrimitiveType));}
|
||||
DrawElementsIndirectUInt(mode,no),
|
||||
_count(0)
|
||||
{
|
||||
_primitiveType=(Type(MultiDrawElementsUIntIndirectPrimitiveType));
|
||||
}
|
||||
|
||||
template <class InputIterator>
|
||||
MultiDrawElementsIndirectUInt(GLenum mode, InputIterator first,InputIterator last) :
|
||||
DrawElementsIndirectUInt(mode,first,last)
|
||||
{_primitiveType=(Type(MultiDrawElementsUIntIndirectPrimitiveType));}
|
||||
DrawElementsIndirectUInt(mode,first,last),
|
||||
_count(0)
|
||||
{
|
||||
_primitiveType=(Type(MultiDrawElementsUIntIndirectPrimitiveType));
|
||||
}
|
||||
|
||||
virtual osg::Object* cloneType() const { return new MultiDrawElementsIndirectUInt(); }
|
||||
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new MultiDrawElementsIndirectUInt(*this,copyop); }
|
||||
@@ -572,13 +623,19 @@ public:
|
||||
|
||||
DrawArraysIndirect(GLenum mode=0, unsigned int firstcommand = 0, GLsizei stride = 0) :
|
||||
osg::PrimitiveSet(Type(DrawArraysIndirectPrimitiveType), mode),
|
||||
_firstCommand(firstcommand), _stride(stride) { setIndirectCommandArray(new DefaultIndirectCommandDrawArrays); }
|
||||
_firstCommand(firstcommand),
|
||||
_stride(stride)
|
||||
{
|
||||
setIndirectCommandArray(new DefaultIndirectCommandDrawArrays);
|
||||
}
|
||||
|
||||
DrawArraysIndirect(const DrawArraysIndirect& dal,const CopyOp& copyop=CopyOp::SHALLOW_COPY) :
|
||||
osg::PrimitiveSet(dal,copyop),
|
||||
_firstCommand(dal._firstCommand),
|
||||
_stride(dal._stride),
|
||||
_indirectCommandArray((DefaultIndirectCommandDrawArrays*)copyop( dal._indirectCommandArray.get())) {}
|
||||
_indirectCommandArray((DefaultIndirectCommandDrawArrays*)copyop( dal._indirectCommandArray.get()))
|
||||
{
|
||||
}
|
||||
|
||||
virtual osg::Object* cloneType() const { return new DrawArraysIndirect(); }
|
||||
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new DrawArraysIndirect(*this,copyop); }
|
||||
@@ -616,8 +673,8 @@ public:
|
||||
if(!dynamic_cast<DrawIndirectBufferObject* >(_indirectCommandArray->getBufferObject()))
|
||||
_indirectCommandArray->setBufferObject(new DrawIndirectBufferObject());
|
||||
}
|
||||
inline const IndirectCommandDrawArrays* getIndirectCommandArray() const { return _indirectCommandArray; }
|
||||
inline IndirectCommandDrawArrays* getIndirectCommandArray() { return _indirectCommandArray; }
|
||||
inline const IndirectCommandDrawArrays* getIndirectCommandArray() const { return _indirectCommandArray.get(); }
|
||||
inline IndirectCommandDrawArrays* getIndirectCommandArray() { return _indirectCommandArray.get(); }
|
||||
|
||||
protected:
|
||||
|
||||
@@ -635,10 +692,16 @@ class OSG_EXPORT MultiDrawArraysIndirect : public DrawArraysIndirect
|
||||
public:
|
||||
|
||||
MultiDrawArraysIndirect(GLenum mode=0, unsigned int firstcommand = 0, unsigned int count = 0, GLsizei stride = 0) :
|
||||
osg::DrawArraysIndirect(mode, firstcommand, stride), _count(count) { _primitiveType=Type(MultiDrawArraysIndirectPrimitiveType); }
|
||||
osg::DrawArraysIndirect(mode, firstcommand, stride),
|
||||
_count(count)
|
||||
{
|
||||
_primitiveType=Type(MultiDrawArraysIndirectPrimitiveType);
|
||||
}
|
||||
|
||||
MultiDrawArraysIndirect(const MultiDrawArraysIndirect& dal,const CopyOp& copyop=CopyOp::SHALLOW_COPY) :
|
||||
osg::DrawArraysIndirect(dal,copyop), _count(dal._count) {}
|
||||
osg::DrawArraysIndirect(dal,copyop),
|
||||
_count(dal._count)
|
||||
{}
|
||||
|
||||
virtual osg::Object* cloneType() const { return new MultiDrawArraysIndirect(); }
|
||||
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new MultiDrawArraysIndirect(*this,copyop); }
|
||||
|
||||
@@ -103,10 +103,6 @@ class OSG_EXPORT Program : public osg::StateAttribute
|
||||
void setParameter( GLenum pname, GLint value );
|
||||
GLint getParameter( GLenum pname ) const;
|
||||
|
||||
/** Set/get compute shader work groups */
|
||||
void setComputeGroups( GLint numGroupsX, GLint numGroupsY, GLint numGroupsZ );
|
||||
void getComputeGroups( GLint& numGroupsX, GLint& numGroupsY, GLint& numGroupsZ ) const;
|
||||
|
||||
/** Add an attribute location binding. */
|
||||
void addBindAttribLocation( const std::string& name, GLuint index );
|
||||
|
||||
@@ -439,12 +435,6 @@ class OSG_EXPORT Program : public osg::StateAttribute
|
||||
GLint _geometryInputType;
|
||||
GLint _geometryOutputType;
|
||||
|
||||
|
||||
/** Parameter maintained with glDispatchCompute */
|
||||
GLint _numGroupsX;
|
||||
GLint _numGroupsY;
|
||||
GLint _numGroupsZ;
|
||||
|
||||
/**TransformFeedBack**/
|
||||
GLenum _feedbackmode;
|
||||
std::vector<std::string> _feedbackout;
|
||||
|
||||
@@ -162,14 +162,13 @@ class OSG_EXPORT Shader : public osg::Object
|
||||
/** Get the const Shader's ShaderBinary, return NULL if none is assigned. */
|
||||
const ShaderBinary* getShaderBinary() const { return _shaderBinary.get(); }
|
||||
|
||||
|
||||
/** Read shader source from file and then constructor shader of specified type.
|
||||
* Return the resulting Shader or 0 if no valid shader source could be read.*/
|
||||
#ifdef OSG_USE_DEPRECATED_API
|
||||
/** Deorecated use osgDB::readRefShaderFile().*/
|
||||
static Shader* readShaderFile( Type type, const std::string& fileName );
|
||||
|
||||
/** Load the Shader's source code text from a file. */
|
||||
/** Deorecated use osgDB::readRefShaderFile(). */
|
||||
bool loadShaderSourceFromFile( const std::string& fileName );
|
||||
|
||||
#endif
|
||||
|
||||
/** The code injection map used when generating the main shader during main shader composition.*/
|
||||
typedef std::multimap<float, std::string> CodeInjectionMap;
|
||||
|
||||
@@ -823,9 +823,12 @@ class OSG_EXPORT State : public Referenced
|
||||
* during rendering. */
|
||||
inline void setDisplaySettings(DisplaySettings* vs) { _displaySettings = vs; }
|
||||
|
||||
/** Get the DisplaySettings */
|
||||
/** Get the const DisplaySettings */
|
||||
inline const DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
|
||||
|
||||
/** Get the const DisplaySettings that is current active DisplaySettings to be used by osg::State, - if DisplaySettings is not directly assigned then fallback to DisplaySettings::instance(). */
|
||||
inline const DisplaySettings* getActiveDisplaySettings() const { return _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance().get(); }
|
||||
|
||||
|
||||
|
||||
/** Set flag for early termination of the draw traversal.*/
|
||||
|
||||
@@ -34,6 +34,8 @@ public:
|
||||
modifiedCount(0xffffffff),
|
||||
active(false) {}
|
||||
|
||||
virtual const char* className() const = 0; // { return "ArrayDispatch"; }
|
||||
|
||||
virtual void enable_and_dispatch(osg::State& /*state*/, const osg::Array* /*new_array*/) {} // = 0;
|
||||
|
||||
virtual void enable_and_dispatch(osg::State& /*state*/, const osg::Array* /*new_array*/, const osg::GLBufferObject* /*vbo*/) {} // = 0;
|
||||
|
||||
@@ -50,6 +50,7 @@ class OSG_EXPORT VertexAttribDivisor : public StateAttribute
|
||||
COMPARE_StateAttribute_Types(VertexAttribDivisor,sa)
|
||||
|
||||
// compare each parameter in turn against the rhs.
|
||||
COMPARE_StateAttribute_Parameter(_index)
|
||||
COMPARE_StateAttribute_Parameter(_divisor)
|
||||
|
||||
return 0; // passed all the above comparison macros, must be equal.
|
||||
|
||||
@@ -42,6 +42,17 @@ namespace osgAnimation
|
||||
const AnimationList& getAnimationList() const { return _animations;}
|
||||
AnimationList& getAnimationList() { return _animations;}
|
||||
|
||||
//uniformisation of the API
|
||||
inline Animation * getRegisteredAnimation(unsigned int i) { return _animations[i].get();}
|
||||
inline unsigned int getNumRegisteredAnimations() const { return _animations.size();}
|
||||
inline void addRegisteredAnimation(Animation* animation)
|
||||
{
|
||||
_needToLink = true;
|
||||
_animations.push_back(animation);
|
||||
buildTargetReference();
|
||||
}
|
||||
void removeRegisteredAnimation(Animation* animation);
|
||||
|
||||
/** Callback method called by the NodeVisitor when visiting a node.*/
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
||||
|
||||
@@ -49,7 +60,6 @@ namespace osgAnimation
|
||||
this Operation must be done each frame */
|
||||
void clearTargets();
|
||||
|
||||
|
||||
LinkVisitor* getOrCreateLinkVisitor();
|
||||
void setLinkVisitor(LinkVisitor*);
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/AnimationUpdateCallback>
|
||||
#include <osgAnimation/MorphTransformSoftware>
|
||||
#include <osg/Geometry>
|
||||
#include <algorithm>
|
||||
|
||||
@@ -28,7 +29,8 @@ namespace osgAnimation
|
||||
|
||||
public:
|
||||
|
||||
enum Method {
|
||||
enum Method
|
||||
{
|
||||
NORMALIZED,
|
||||
RELATIVE
|
||||
};
|
||||
@@ -59,18 +61,45 @@ namespace osgAnimation
|
||||
virtual const char* libraryName() const { return "osgAnimation"; }
|
||||
virtual const char* className() const { return "MorphGeometry"; }
|
||||
|
||||
virtual void transformSoftwareMethod();
|
||||
// set implementation of rig method
|
||||
inline void setMorphTransformImplementation(MorphTransform*mt) { _morphTransformImplementation=mt; }
|
||||
inline MorphTransform* getMorphTransformImplementation() { return _morphTransformImplementation.get(); }
|
||||
inline const MorphTransform* getMorphTransformImplementation() const { return _morphTransformImplementation.get(); }
|
||||
|
||||
/** Set the morphing method. */
|
||||
void setMethod(Method method) { _method = method; }
|
||||
inline void setMethod(Method method) { _method = method; }
|
||||
/** Get the morphing method. */
|
||||
inline Method getMethod() const { return _method; }
|
||||
|
||||
/** Set flag for morphing normals. */
|
||||
void setMorphNormals(bool morphNormals) { _morphNormals = morphNormals; }
|
||||
inline void setMorphNormals(bool morphNormals) { _morphNormals = morphNormals; }
|
||||
/** Get the flag for morphing normals. */
|
||||
inline bool getMorphNormals() const { return _morphNormals; }
|
||||
|
||||
/** Get the list of MorphTargets.*/
|
||||
inline const MorphTargetList& getMorphTargetList() const { return _morphTargets; }
|
||||
|
||||
/** Get the list of MorphTargets. Warning if you modify this array you will have to call dirty() */
|
||||
inline MorphTargetList& getMorphTargetList() { return _morphTargets; }
|
||||
|
||||
/** Return the \c MorphTarget at position \c i.*/
|
||||
inline const MorphTarget& getMorphTarget( unsigned int i ) const { return _morphTargets[i]; }
|
||||
|
||||
/** Return the \c MorphTarget at position \c i.*/
|
||||
inline MorphTarget& getMorphTarget( unsigned int i ) { return _morphTargets[i]; }
|
||||
|
||||
/** Set source of vertices for this morph geometry */
|
||||
inline void setVertexSource(osg::Vec3Array *v) { _positionSource=v; }
|
||||
|
||||
/** Get source of vertices for this morph geometry */
|
||||
inline osg::Vec3Array * getVertexSource() const { return _positionSource.get(); }
|
||||
|
||||
/** Set source of normals for this morph geometry */
|
||||
inline void setNormalSource(osg::Vec3Array *n) { _normalSource=n; }
|
||||
|
||||
/** Get source of normals for this morph geometry */
|
||||
inline osg::Vec3Array * getNormalSource() const { return _normalSource.get(); }
|
||||
|
||||
/** Add a \c MorphTarget to the \c MorphGeometry.
|
||||
* If \c MorphTarget is not \c NULL and is not contained in the \c MorphGeometry
|
||||
* then increment its reference count, add it to the MorphTargets list and
|
||||
@@ -80,20 +109,30 @@ namespace osgAnimation
|
||||
* @param weight The weight to be added to the \c MorphGeometry.
|
||||
* @return \c true for success; \c false otherwise.
|
||||
*/
|
||||
virtual void addMorphTarget( osg::Geometry *morphTarget, float weight = 1.0 ) { _morphTargets.push_back(MorphTarget(morphTarget, weight)); _dirty = true; }
|
||||
virtual void addMorphTarget( osg::Geometry *morphTarget, float weight = 1.0 )
|
||||
{
|
||||
_morphTargets.push_back(MorphTarget(morphTarget, weight));
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
virtual void removeMorphTarget( osg::Geometry *morphTarget ) {
|
||||
for(MorphTargetList::iterator iterator = _morphTargets.begin() ; iterator != _morphTargets.end() ; ++ iterator) {
|
||||
if(iterator->getGeometry() == morphTarget) {
|
||||
virtual void removeMorphTarget( osg::Geometry *morphTarget )
|
||||
{
|
||||
for(MorphTargetList::iterator iterator = _morphTargets.begin() ; iterator != _morphTargets.end() ; ++ iterator)
|
||||
{
|
||||
if(iterator->getGeometry() == morphTarget)
|
||||
{
|
||||
_morphTargets.erase(iterator);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void removeMorphTarget( const std::string& name ) {
|
||||
for(MorphTargetList::iterator iterator = _morphTargets.begin() ; iterator != _morphTargets.end() ; ++ iterator) {
|
||||
if(iterator->getGeometry() && iterator->getGeometry()->getName() == name) {
|
||||
virtual void removeMorphTarget( const std::string& name )
|
||||
{
|
||||
for(MorphTargetList::iterator iterator = _morphTargets.begin() ; iterator != _morphTargets.end() ; ++ iterator)
|
||||
{
|
||||
if(iterator->getGeometry() && iterator->getGeometry()->getName() == name)
|
||||
{
|
||||
_morphTargets.erase(iterator);
|
||||
break;
|
||||
}
|
||||
@@ -101,7 +140,8 @@ namespace osgAnimation
|
||||
|
||||
}
|
||||
|
||||
void setWeight(unsigned int index, float morphWeight)
|
||||
/** update a morph target at index setting its current weight to morphWeight */
|
||||
inline void setWeight(unsigned int index, float morphWeight)
|
||||
{
|
||||
if (index < _morphTargets.size())
|
||||
{
|
||||
@@ -111,29 +151,22 @@ namespace osgAnimation
|
||||
}
|
||||
|
||||
/** Set the MorphGeometry dirty.*/
|
||||
void dirty() { _dirty = true; }
|
||||
inline void dirty(bool b=true) { _dirty = b; }
|
||||
inline bool isDirty() const { return _dirty; }
|
||||
|
||||
/** Get the list of MorphTargets.*/
|
||||
const MorphTargetList& getMorphTargetList() const { return _morphTargets; }
|
||||
|
||||
/** Get the list of MorphTargets. Warning if you modify this array you will have to call dirty() */
|
||||
MorphTargetList& getMorphTargetList() { return _morphTargets; }
|
||||
|
||||
/** Return the \c MorphTarget at position \c i.*/
|
||||
inline const MorphTarget& getMorphTarget( unsigned int i ) const { return _morphTargets[i]; }
|
||||
|
||||
/** Return the \c MorphTarget at position \c i.*/
|
||||
inline MorphTarget& getMorphTarget( unsigned int i ) { return _morphTargets[i]; }
|
||||
/** for retrocompatibility */
|
||||
void transformSoftwareMethod() { (*_morphTransformImplementation.get())(*this); }
|
||||
|
||||
protected:
|
||||
osg::ref_ptr<MorphTransform> _morphTransformImplementation;
|
||||
/// Do we need to recalculate the morphed geometry?
|
||||
bool _dirty;
|
||||
|
||||
Method _method;
|
||||
MorphTargetList _morphTargets;
|
||||
|
||||
std::vector<osg::Vec3> _positionSource;
|
||||
std::vector<osg::Vec3> _normalSource;
|
||||
osg::ref_ptr<osg::Vec3Array> _positionSource;
|
||||
osg::ref_ptr<osg::Vec3Array> _normalSource;
|
||||
|
||||
/// Do we also morph between normals?
|
||||
bool _morphNormals;
|
||||
@@ -153,7 +186,8 @@ namespace osgAnimation
|
||||
void addTarget(const std::string& name) { _targetNames.push_back(name); }
|
||||
unsigned int getNumTarget() const { return _targetNames.size(); }
|
||||
const std::string& getTargetName(unsigned int index) { return _targetNames[index]; }
|
||||
void removeTarget(const std::string& name) {
|
||||
void removeTarget(const std::string& name)
|
||||
{
|
||||
TargetNames::iterator found = std::find(_targetNames.begin(), _targetNames.end(), name);
|
||||
if(found != _targetNames.end())
|
||||
_targetNames.erase(found);
|
||||
@@ -163,9 +197,7 @@ namespace osgAnimation
|
||||
const std::vector<std::string>& getTargetNames() const { return _targetNames; }
|
||||
std::vector<std::string>& getTargetNames() { return _targetNames; }
|
||||
|
||||
void setTargetNames(const TargetNames& targetNames) {
|
||||
_targetNames.assign(targetNames.begin(), targetNames.end());
|
||||
}
|
||||
void setTargetNames(const TargetNames& targetNames) { _targetNames.assign(targetNames.begin(), targetNames.end()); }
|
||||
|
||||
/** Callback method called by the NodeVisitor when visiting a node.*/
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
||||
@@ -195,11 +227,15 @@ namespace osgAnimation
|
||||
if (!geom)
|
||||
return;
|
||||
|
||||
geom->transformSoftwareMethod();
|
||||
if (!geom->getMorphTransformImplementation())
|
||||
{
|
||||
geom->setMorphTransformImplementation( new MorphTransformSoftware);
|
||||
}
|
||||
|
||||
MorphTransform& implementation = *geom->getMorphTransformImplementation();
|
||||
(implementation)(*geom);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
65
include/osgAnimation/MorphTransformHardware
Normal file
65
include/osgAnimation/MorphTransformHardware
Normal file
@@ -0,0 +1,65 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2017 Julien Valentin <mp3butcher@hotmail.com>
|
||||
*
|
||||
* 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 OSGANIMATION_MORPH_TRANSFORM_HARDWARE
|
||||
#define OSGANIMATION_MORPH_TRANSFORM_HARDWARE 1
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/RigTransform>
|
||||
#include <osgAnimation/VertexInfluence>
|
||||
#include <osgAnimation/Bone>
|
||||
#include <osg/Matrix>
|
||||
#include <osg/Array>
|
||||
|
||||
///texture unit reserved for morphtarget TBO
|
||||
#define MORPHTRANSHW_DEFAULTMORPHTEXTUREUNIT 7
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
class MorphGeometry;
|
||||
|
||||
/// This class manage format for hardware morphing
|
||||
class OSGANIMATION_EXPORT MorphTransformHardware : public MorphTransform
|
||||
{
|
||||
public:
|
||||
|
||||
MorphTransformHardware();
|
||||
|
||||
MorphTransformHardware(const MorphTransformHardware& rth, const osg::CopyOp& copyop);
|
||||
|
||||
META_Object(osgAnimation,MorphTransformHardware);
|
||||
|
||||
virtual void operator()(MorphGeometry&);
|
||||
|
||||
inline void setShader( osg::Shader*s ) { _shader=s; }
|
||||
inline const osg::Shader * getShader() const { return _shader.get(); }
|
||||
inline osg::Shader * getShader() { return _shader.get(); }
|
||||
|
||||
///texture unit reserved for morphtarget TBO default is 7
|
||||
void setReservedTextureUnit(unsigned int t) { _reservedTextureUnit=t; }
|
||||
unsigned int getReservedTextureUnit() const { return _reservedTextureUnit; }
|
||||
|
||||
protected:
|
||||
|
||||
bool init(MorphGeometry&);
|
||||
|
||||
osg::ref_ptr<osg::Uniform> _uniformTargetsWeight;
|
||||
osg::ref_ptr<osg::Shader> _shader;
|
||||
|
||||
bool _needInit;
|
||||
unsigned int _reservedTextureUnit;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
46
include/osgAnimation/MorphTransformSoftware
Normal file
46
include/osgAnimation/MorphTransformSoftware
Normal file
@@ -0,0 +1,46 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 Cedric Pinson <cedric.pinson@plopbyte.net>
|
||||
*
|
||||
* 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 OSGANIMATION_MORPHTRANSFORM_SOFTWARE
|
||||
#define OSGANIMATION_MORPHTRANSFORM_SOFTWARE 1
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/RigTransform>
|
||||
#include <osgAnimation/Bone>
|
||||
#include <osg/observer_ptr>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class MorphGeometry;
|
||||
|
||||
/// This class manage format for software morphing
|
||||
class OSGANIMATION_EXPORT MorphTransformSoftware : public MorphTransform
|
||||
{
|
||||
public:
|
||||
MorphTransformSoftware():_needInit(true) {}
|
||||
MorphTransformSoftware(const MorphTransformSoftware& rts,const osg::CopyOp& copyop): MorphTransform(rts, copyop), _needInit(true) {}
|
||||
|
||||
META_Object(osgAnimation,MorphTransformSoftware)
|
||||
|
||||
bool init(MorphGeometry&);
|
||||
virtual void operator()(MorphGeometry&);
|
||||
|
||||
protected:
|
||||
bool _needInit;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
// The idea is to compute a bounding box with a factor x of the first step we compute the bounding box
|
||||
class OSGANIMATION_EXPORT RigComputeBoundingBoxCallback : public osg::Drawable::ComputeBoundingBoxCallback
|
||||
{
|
||||
@@ -37,8 +36,8 @@ namespace osgAnimation
|
||||
|
||||
META_Object(osgAnimation, RigComputeBoundingBoxCallback);
|
||||
|
||||
|
||||
void reset() { _computed = false; }
|
||||
|
||||
virtual osg::BoundingBox computeBound(const osg::Drawable& drawable) const;
|
||||
protected:
|
||||
mutable bool _computed;
|
||||
@@ -57,40 +56,36 @@ namespace osgAnimation
|
||||
|
||||
META_Object(osgAnimation, RigGeometry);
|
||||
|
||||
void setInfluenceMap(VertexInfluenceMap* vertexInfluenceMap) { _vertexInfluenceMap = vertexInfluenceMap; }
|
||||
const VertexInfluenceMap* getInfluenceMap() const { return _vertexInfluenceMap.get();}
|
||||
VertexInfluenceMap* getInfluenceMap() { return _vertexInfluenceMap.get();}
|
||||
inline void setInfluenceMap(VertexInfluenceMap* vertexInfluenceMap) { _vertexInfluenceMap = vertexInfluenceMap; }
|
||||
inline const VertexInfluenceMap* getInfluenceMap() const { return _vertexInfluenceMap.get(); }
|
||||
inline VertexInfluenceMap* getInfluenceMap() { return _vertexInfluenceMap.get(); }
|
||||
|
||||
const Skeleton* getSkeleton() const;
|
||||
Skeleton* getSkeleton();
|
||||
inline const Skeleton* getSkeleton() const { return _root.get(); }
|
||||
inline Skeleton* getSkeleton() { return _root.get(); }
|
||||
// will be used by the update callback to init correctly the rig mesh
|
||||
void setSkeleton(Skeleton*);
|
||||
inline void setSkeleton(Skeleton* root) { _root = root; }
|
||||
|
||||
void setNeedToComputeMatrix(bool state) { _needToComputeMatrix = state;}
|
||||
bool getNeedToComputeMatrix() const { return _needToComputeMatrix;}
|
||||
|
||||
|
||||
// this build the internal database about vertex influence and bones
|
||||
void buildVertexInfluenceSet();
|
||||
const VertexInfluenceSet& getVertexInfluenceSet() const;
|
||||
void setNeedToComputeMatrix(bool state) { _needToComputeMatrix = state; }
|
||||
bool getNeedToComputeMatrix() const { return _needToComputeMatrix; }
|
||||
|
||||
void computeMatrixFromRootSkeleton();
|
||||
|
||||
|
||||
// set implementation of rig method
|
||||
void setRigTransformImplementation(RigTransform*);
|
||||
RigTransform* getRigTransformImplementation();
|
||||
const RigTransform* getRigTransformImplementation() const { return _rigTransformImplementation.get(); }
|
||||
inline RigTransform* getRigTransformImplementation() { return _rigTransformImplementation.get(); }
|
||||
inline void setRigTransformImplementation(RigTransform* rig) { _rigTransformImplementation = rig; }
|
||||
inline const RigTransform* getRigTransformImplementation() const { return _rigTransformImplementation.get(); }
|
||||
|
||||
virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
|
||||
void update();
|
||||
|
||||
void buildVertexInfluenceSet() { _rigTransformImplementation->prepareData(*this); }
|
||||
|
||||
const osg::Matrix& getMatrixFromSkeletonToGeometry() const;
|
||||
|
||||
const osg::Matrix& getInvMatrixFromSkeletonToGeometry() const;
|
||||
|
||||
osg::Geometry* getSourceGeometry();
|
||||
const osg::Geometry* getSourceGeometry() const;
|
||||
void setSourceGeometry(osg::Geometry* geometry);
|
||||
inline osg::Geometry* getSourceGeometry() { return _geometry.get(); }
|
||||
inline const osg::Geometry* getSourceGeometry() const { return _geometry.get(); }
|
||||
inline void setSourceGeometry(osg::Geometry* geometry) { _geometry = geometry; }
|
||||
|
||||
void copyFrom(osg::Geometry& from);
|
||||
|
||||
@@ -111,8 +106,6 @@ namespace osgAnimation
|
||||
|
||||
osg::ref_ptr<osg::Geometry> _geometry;
|
||||
osg::ref_ptr<RigTransform> _rigTransformImplementation;
|
||||
|
||||
VertexInfluenceSet _vertexInfluenceSet;
|
||||
osg::ref_ptr<VertexInfluenceMap> _vertexInfluenceMap;
|
||||
|
||||
osg::Matrix _matrixFromSkeletonToGeometry;
|
||||
@@ -120,8 +113,7 @@ namespace osgAnimation
|
||||
osg::observer_ptr<Skeleton> _root;
|
||||
bool _needToComputeMatrix;
|
||||
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct UpdateRigGeometry : public osg::Drawable::UpdateCallback
|
||||
@@ -135,7 +127,8 @@ namespace osgAnimation
|
||||
|
||||
META_Object(osgAnimation, UpdateRigGeometry);
|
||||
|
||||
virtual void update(osg::NodeVisitor* nv, osg::Drawable* drw) {
|
||||
virtual void update(osg::NodeVisitor* nv, osg::Drawable* drw)
|
||||
{
|
||||
RigGeometry* geom = dynamic_cast<RigGeometry*>(drw);
|
||||
if(!geom)
|
||||
return;
|
||||
@@ -151,7 +144,7 @@ namespace osgAnimation
|
||||
osg::notify(osg::WARN) << "A RigGeometry did not find a parent skeleton for RigGeometry ( " << geom->getName() << " )" << std::endl;
|
||||
return;
|
||||
}
|
||||
geom->buildVertexInfluenceSet();
|
||||
geom->getRigTransformImplementation()->prepareData(*geom);
|
||||
geom->setSkeleton(finder._root.get());
|
||||
}
|
||||
|
||||
@@ -161,7 +154,8 @@ namespace osgAnimation
|
||||
if(geom->getNeedToComputeMatrix())
|
||||
geom->computeMatrixFromRootSkeleton();
|
||||
|
||||
if(geom->getSourceGeometry()) {
|
||||
if(geom->getSourceGeometry())
|
||||
{
|
||||
osg::Drawable::UpdateCallback * up = dynamic_cast<osg::Drawable::UpdateCallback*>(geom->getSourceGeometry()->getUpdateCallback());
|
||||
if(up)
|
||||
up->update(nv, geom->getSourceGeometry());
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 Cedric Pinson <cedric.pinson@plopbyte.net>
|
||||
*
|
||||
* 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.
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 Cedric Pinson <cedric.pinson@plopbyte.net>
|
||||
*
|
||||
* 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 OSGANIMATION_RIGTRANSFORM
|
||||
@@ -33,10 +33,31 @@ namespace osgAnimation
|
||||
|
||||
virtual void operator()(RigGeometry&) {}
|
||||
|
||||
/// to call manually when a skeleton is reacheable from the rig
|
||||
/// in order to prepare technic data before rendering
|
||||
virtual bool prepareData(RigGeometry&) { return true; }
|
||||
|
||||
protected:
|
||||
virtual ~RigTransform() {}
|
||||
|
||||
};
|
||||
class MorphGeometry;
|
||||
|
||||
class MorphTransform : public osg::Object
|
||||
{
|
||||
public:
|
||||
MorphTransform() {}
|
||||
MorphTransform(const MorphTransform& org, const osg::CopyOp& copyop):
|
||||
osg::Object(org, copyop) {}
|
||||
|
||||
META_Object(osgAnimation,MorphTransform)
|
||||
|
||||
virtual void operator()(MorphGeometry&) {}
|
||||
|
||||
protected:
|
||||
virtual ~MorphTransform() {}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 Cedric Pinson <cedric.pinson@plopbyte.net>
|
||||
* Copyright (C) 2017 Julien Valentin <mp3butcher@hotmail.com>
|
||||
*
|
||||
* 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
|
||||
@@ -22,6 +23,8 @@
|
||||
#include <osg/Matrix>
|
||||
#include <osg/Array>
|
||||
|
||||
#define RIGTRANSHW_DEFAULT_FIRST_VERTATTRIB_TARGETTED 11
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
class RigGeometry;
|
||||
@@ -37,54 +40,42 @@ namespace osgAnimation
|
||||
|
||||
META_Object(osgAnimation,RigTransformHardware);
|
||||
|
||||
typedef osg::Matrix MatrixType;
|
||||
typedef osgAnimation::Bone BoneType;
|
||||
typedef std::vector<osg::ref_ptr<osg::Vec4Array> > BoneWeightAttribList;
|
||||
typedef std::vector<osg::ref_ptr<BoneType> > BonePalette;
|
||||
typedef std::map<std::string, int> BoneNamePaletteIndex;
|
||||
|
||||
typedef std::vector<osg::ref_ptr<Bone> > BonePalette;
|
||||
typedef std::map<std::string, unsigned int> BoneNamePaletteIndex;
|
||||
typedef std::vector<osg::Matrix> MatrixPalette;
|
||||
struct IndexWeightEntry
|
||||
{
|
||||
int _boneIndex;
|
||||
float _boneWeight;
|
||||
IndexWeightEntry() { _boneIndex = 0; _boneWeight = 0;}
|
||||
IndexWeightEntry(int index, float weight) { _boneIndex = index; _boneWeight = weight;}
|
||||
int getIndex() const { return _boneIndex; }
|
||||
float getWeight() const { return _boneWeight; }
|
||||
};
|
||||
typedef std::vector<std::vector<IndexWeightEntry> > VertexIndexWeightList;
|
||||
|
||||
///set the first Vertex Attribute Array index of the rig generated by this technic (default:11)
|
||||
void setFirstVertexAttributeTarget(unsigned int i) { _minAttribIndex=i; }
|
||||
unsigned int getFirstVertexAttributeTarget()const { return _minAttribIndex; }
|
||||
|
||||
void setShader(osg::Shader* shader) { _shader = shader; }
|
||||
const osg::Shader* getShader() const { return _shader.get(); }
|
||||
osg::Shader* getShader() { return _shader.get(); }
|
||||
|
||||
osg::Vec4Array* getVertexAttrib(int index);
|
||||
int getNumVertexAttrib();
|
||||
osg::Vec4Array* getVertexAttrib(unsigned int index);
|
||||
unsigned int getNumVertexAttrib() const { return _boneWeightAttribArrays.size(); }
|
||||
|
||||
const unsigned int &getNumBonesPerVertex() const { return _bonesPerVertex; }
|
||||
const unsigned int &getNumVertexes() const { return _nbVertices; }
|
||||
|
||||
const BoneNamePaletteIndex& getBoneNameToPalette() { return _boneNameToPalette; }
|
||||
const BonePalette& getBonePalette() { return _bonePalette; }
|
||||
osg::Uniform* getMatrixPaletteUniform() { return _uniformMatrixPalette.get(); }
|
||||
|
||||
osg::Uniform* getMatrixPaletteUniform();
|
||||
void computeMatrixPaletteUniform(const osg::Matrix& transformFromSkeletonToGeometry, const osg::Matrix& invTransformFromSkeletonToGeometry);
|
||||
|
||||
int getNumBonesPerVertex() const;
|
||||
int getNumVertexes() const;
|
||||
|
||||
bool createPalette(int nbVertexes, BoneMap boneMap, const VertexInfluenceSet::VertexIndexToBoneWeightMap& vertexIndexToBoneWeightMap);
|
||||
|
||||
// update rig if needed
|
||||
virtual void operator()(RigGeometry&);
|
||||
void setShader(osg::Shader*);
|
||||
|
||||
const BoneNamePaletteIndex& getBoneNameToPalette() {
|
||||
return _boneNameToPalette;
|
||||
}
|
||||
// init/reset animations data
|
||||
virtual bool prepareData(RigGeometry& );
|
||||
|
||||
protected:
|
||||
|
||||
bool init(RigGeometry&);
|
||||
unsigned int _bonesPerVertex;
|
||||
unsigned int _nbVertices;
|
||||
|
||||
BoneWeightAttribList createVertexAttribList();
|
||||
osg::Uniform* createVertexUniform();
|
||||
|
||||
int _bonesPerVertex;
|
||||
int _nbVertexes;
|
||||
VertexIndexWeightList _vertexIndexMatrixWeightList;
|
||||
BonePalette _bonePalette;
|
||||
BoneNamePaletteIndex _boneNameToPalette;
|
||||
BoneWeightAttribList _boneWeightAttribArrays;
|
||||
@@ -92,6 +83,13 @@ namespace osgAnimation
|
||||
osg::ref_ptr<osg::Shader> _shader;
|
||||
|
||||
bool _needInit;
|
||||
unsigned int _minAttribIndex;
|
||||
bool buildPalette(const BoneMap& boneMap,const RigGeometry& rig);
|
||||
|
||||
//on first update
|
||||
virtual bool init(RigGeometry& );
|
||||
|
||||
std::vector<IndexWeightList> _perVertexInfluences;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 Cedric Pinson <cedric.pinson@plopbyte.net>
|
||||
* Copyright (C) 2017 Julien Valentin <mp3butcher@hotmail.com>
|
||||
*
|
||||
* 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
|
||||
@@ -36,36 +37,49 @@ namespace osgAnimation
|
||||
META_Object(osgAnimation,RigTransformSoftware)
|
||||
|
||||
virtual void operator()(RigGeometry&);
|
||||
//to call when a skeleton is reacheable from the rig to prepare technic data
|
||||
virtual bool prepareData(RigGeometry&);
|
||||
|
||||
class BoneWeight
|
||||
typedef std::pair<unsigned int, float> LocalBoneIDWeight;
|
||||
class BonePtrWeight: LocalBoneIDWeight
|
||||
{
|
||||
public:
|
||||
BoneWeight(Bone* bone, float weight) : _bone(bone), _weight(weight) {}
|
||||
const Bone* getBone() const { return _bone.get(); }
|
||||
float getWeight() const { return _weight; }
|
||||
void setWeight(float w) { _weight = w; }
|
||||
BonePtrWeight(unsigned int id,float weight, Bone*bone=0 ): LocalBoneIDWeight(id,weight), _boneptr(bone) {}
|
||||
BonePtrWeight(const BonePtrWeight &bw2): LocalBoneIDWeight(bw2.getBoneID(),bw2.getWeight()), _boneptr(bw2._boneptr.get()) {}
|
||||
inline const float & getWeight() const { return second; }
|
||||
inline void setWeight(float b) { second=b; }
|
||||
inline const unsigned int & getBoneID() const { return first; }
|
||||
inline void setBoneID(unsigned int b) { first=b; }
|
||||
inline bool operator< (const BonePtrWeight &b1) const {
|
||||
if (second > b1.second) return true;
|
||||
if (second < b1.second) return false;
|
||||
return (first > b1.first);
|
||||
}
|
||||
///set Bone pointer
|
||||
inline const Bone * getBonePtr() const { return _boneptr.get(); }
|
||||
inline void setBonePtr(Bone*b) { _boneptr=b; }
|
||||
protected:
|
||||
osg::observer_ptr<Bone> _bone;
|
||||
float _weight;
|
||||
osg::observer_ptr< Bone > _boneptr;
|
||||
};
|
||||
|
||||
typedef std::vector<BoneWeight> BoneWeightList;
|
||||
typedef std::vector<int> VertexList;
|
||||
typedef std::vector<BonePtrWeight> BonePtrWeightList;
|
||||
|
||||
class UniqBoneSetVertexSet
|
||||
/// map a set of boneinfluence to a list of vertex indices sharing this set
|
||||
class VertexGroup
|
||||
{
|
||||
public:
|
||||
BoneWeightList& getBones() { return _bones; }
|
||||
VertexList& getVertexes() { return _vertexes; }
|
||||
inline BonePtrWeightList& getBoneWeights() { return _boneweights; }
|
||||
|
||||
void resetMatrix()
|
||||
inline IndexList& getVertices() { return _vertexes; }
|
||||
|
||||
inline void resetMatrix()
|
||||
{
|
||||
_result.set(0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
void accummulateMatrix(const osg::Matrix& invBindMatrix, const osg::Matrix& matrix, osg::Matrix::value_type weight)
|
||||
inline void accummulateMatrix(const osg::Matrix& invBindMatrix, const osg::Matrix& matrix, osg::Matrix::value_type weight)
|
||||
{
|
||||
osg::Matrix m = invBindMatrix * matrix;
|
||||
osg::Matrix::value_type* ptr = m.ptr();
|
||||
@@ -86,20 +100,19 @@ namespace osgAnimation
|
||||
ptrresult[13] += ptr[13] * weight;
|
||||
ptrresult[14] += ptr[14] * weight;
|
||||
}
|
||||
void computeMatrixForVertexSet()
|
||||
inline void computeMatrixForVertexSet()
|
||||
{
|
||||
if (_bones.empty())
|
||||
if (_boneweights.empty())
|
||||
{
|
||||
osg::notify(osg::WARN) << this << " RigTransformSoftware::UniqBoneSetVertexSet no bones found" << std::endl;
|
||||
osg::notify(osg::WARN) << this << " RigTransformSoftware::VertexGroup no bones found" << std::endl;
|
||||
_result = osg::Matrix::identity();
|
||||
return;
|
||||
}
|
||||
resetMatrix();
|
||||
|
||||
int size = _bones.size();
|
||||
for (int i = 0; i < size; i++)
|
||||
for(BonePtrWeightList::iterator bwit=_boneweights.begin(); bwit!=_boneweights.end(); ++bwit )
|
||||
{
|
||||
const Bone* bone = _bones[i].getBone();
|
||||
const Bone* bone = bwit->getBonePtr();
|
||||
if (!bone)
|
||||
{
|
||||
osg::notify(osg::WARN) << this << " RigTransformSoftware::computeMatrixForVertexSet Warning a bone is null, skip it" << std::endl;
|
||||
@@ -107,68 +120,67 @@ namespace osgAnimation
|
||||
}
|
||||
const osg::Matrix& invBindMatrix = bone->getInvBindMatrixInSkeletonSpace();
|
||||
const osg::Matrix& matrix = bone->getMatrixInSkeletonSpace();
|
||||
osg::Matrix::value_type w = _bones[i].getWeight();
|
||||
osg::Matrix::value_type w = bwit->getWeight();
|
||||
accummulateMatrix(invBindMatrix, matrix, w);
|
||||
}
|
||||
}
|
||||
const osg::Matrix& getMatrix() const { return _result;}
|
||||
void normalize();
|
||||
inline const osg::Matrix& getMatrix() const { return _result; }
|
||||
protected:
|
||||
BoneWeightList _bones;
|
||||
VertexList _vertexes;
|
||||
BonePtrWeightList _boneweights;
|
||||
IndexList _vertexes;
|
||||
osg::Matrix _result;
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <class V> void compute(const osg::Matrix& transform, const osg::Matrix& invTransform, const V* src, V* dst)
|
||||
template <class V>
|
||||
inline void compute(const osg::Matrix& transform, const osg::Matrix& invTransform, const V* src, V* dst)
|
||||
{
|
||||
// the result of matrix mult should be cached to be used for vertexes transform and normal transform and maybe other computation
|
||||
int size = _boneSetVertexSet.size();
|
||||
for (int i = 0; i < size; i++)
|
||||
for(VertexGroupList::iterator itvg=_uniqVertexGroupList.begin(); itvg!=_uniqVertexGroupList.end(); ++itvg)
|
||||
{
|
||||
UniqBoneSetVertexSet& uniq = _boneSetVertexSet[i];
|
||||
VertexGroup& uniq = *itvg;
|
||||
uniq.computeMatrixForVertexSet();
|
||||
osg::Matrix matrix = transform * uniq.getMatrix() * invTransform;
|
||||
|
||||
const VertexList& vertexes = uniq.getVertexes();
|
||||
int vertexSize = vertexes.size();
|
||||
for (int j = 0; j < vertexSize; j++)
|
||||
const IndexList& vertexes = uniq.getVertices();
|
||||
for(IndexList::const_iterator vertIDit=vertexes.begin(); vertIDit!=vertexes.end(); ++vertIDit)
|
||||
{
|
||||
int idx = vertexes[j];
|
||||
dst[idx] = src[idx] * matrix;
|
||||
dst[*vertIDit] = src[*vertIDit] * matrix;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class V> void computeNormal(const osg::Matrix& transform, const osg::Matrix& invTransform, const V* src, V* dst)
|
||||
template <class V>
|
||||
inline void computeNormal(const osg::Matrix& transform, const osg::Matrix& invTransform, const V* src, V* dst)
|
||||
{
|
||||
int size = _boneSetVertexSet.size();
|
||||
for (int i = 0; i < size; i++)
|
||||
for(VertexGroupList::iterator itvg=_uniqVertexGroupList.begin(); itvg!=_uniqVertexGroupList.end(); ++itvg)
|
||||
{
|
||||
UniqBoneSetVertexSet& uniq = _boneSetVertexSet[i];
|
||||
VertexGroup& uniq = *itvg;
|
||||
uniq.computeMatrixForVertexSet();
|
||||
osg::Matrix matrix = transform * uniq.getMatrix() * invTransform;
|
||||
|
||||
const VertexList& vertexes = uniq.getVertexes();
|
||||
int vertexSize = vertexes.size();
|
||||
for (int j = 0; j < vertexSize; j++)
|
||||
const IndexList& vertexes = uniq.getVertices();
|
||||
for(IndexList::const_iterator vertIDit=vertexes.begin(); vertIDit!=vertexes.end(); ++vertIDit)
|
||||
{
|
||||
int idx = vertexes[j];
|
||||
dst[idx] = osg::Matrix::transform3x3(src[idx],matrix);
|
||||
dst[*vertIDit] = osg::Matrix::transform3x3(src[*vertIDit],matrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
bool init(RigGeometry&);
|
||||
void initVertexSetFromBones(const BoneMap& map, const VertexInfluenceSet::UniqVertexSetToBoneSetList& influence);
|
||||
std::vector<UniqBoneSetVertexSet> _boneSetVertexSet;
|
||||
|
||||
bool _needInit;
|
||||
|
||||
virtual bool init(RigGeometry&);
|
||||
|
||||
std::map<std::string,bool> _invalidInfluence;
|
||||
|
||||
typedef std::vector<VertexGroup> VertexGroupList;
|
||||
VertexGroupList _uniqVertexGroupList;
|
||||
|
||||
void buildMinimumUpdateSet(const RigGeometry&rig );
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
|
||||
* Copyright (C) 2017 Julien Valentin <mp3butcher@hotmail.com>
|
||||
*
|
||||
* 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
|
||||
@@ -23,22 +24,31 @@
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
class Skeleton;
|
||||
|
||||
// first is vertex index, and second the weight, the
|
||||
typedef std::pair<int, float> VertexIndexWeight;
|
||||
typedef std::vector<VertexIndexWeight> VertexList;
|
||||
class OSGANIMATION_EXPORT VertexInfluence : public VertexList
|
||||
// first is bonename, and second the weight
|
||||
typedef std::pair<std::string, float> BoneWeight;
|
||||
// first is vertex index, and second the weight
|
||||
typedef std::pair<unsigned int, float> VertexIndexWeight;
|
||||
// list of IndexWeight
|
||||
typedef std::vector<VertexIndexWeight> IndexWeightList;
|
||||
// list of IndexWeight
|
||||
typedef std::vector<BoneWeight> BoneWeightList;
|
||||
// list of Index
|
||||
typedef std::vector<unsigned int> IndexList;
|
||||
|
||||
//Bone influence list
|
||||
class OSGANIMATION_EXPORT VertexInfluence : public IndexWeightList
|
||||
{
|
||||
public:
|
||||
const std::string& getName() const { return _name;}
|
||||
void setName(const std::string& name) { _name = name;}
|
||||
|
||||
const std::string& getName() const { return _name; }
|
||||
void setName(const std::string& name) { _name = name; }
|
||||
protected:
|
||||
// the name is the bone to link to
|
||||
std::string _name;
|
||||
};
|
||||
|
||||
class VertexInfluenceMap : public std::map<std::string, VertexInfluence> , public osg::Object
|
||||
class VertexInfluenceMap : public std::map<std::string, VertexInfluence>, public osg::Object
|
||||
{
|
||||
public:
|
||||
META_Object(osgAnimation, VertexInfluenceMap);
|
||||
@@ -46,61 +56,32 @@ namespace osgAnimation
|
||||
VertexInfluenceMap() {}
|
||||
VertexInfluenceMap(const osgAnimation::VertexInfluenceMap& org, const osg::CopyOp& copyop):
|
||||
std::map<std::string, VertexInfluence>(org),
|
||||
osg::Object(org, copyop)
|
||||
{}
|
||||
};
|
||||
osg::Object(org, copyop) {}
|
||||
|
||||
///normalize per vertex weights given numvert of the attached mesh
|
||||
void normalize(unsigned int numvert);
|
||||
|
||||
// this class manage VertexInfluence database by mesh
|
||||
// reference bones per vertex ...
|
||||
class OSGANIMATION_EXPORT VertexInfluenceSet
|
||||
{
|
||||
public:
|
||||
typedef std::vector<VertexInfluence> BoneToVertexList;
|
||||
///remove weakest influences in order to fit targetted numbonepervertex
|
||||
void cullInfluenceCountPerVertex(unsigned int maxnumbonepervertex, float minweight=0, bool renormalize=true);
|
||||
|
||||
class BoneWeight
|
||||
//compute PerVertexInfluenceList
|
||||
void computePerVertexInfluenceList(std::vector<BoneWeightList>& perVertexInfluenceList, unsigned int numvert) const;
|
||||
|
||||
/// map a set of boneinfluence to a list of vertex indices sharing this set
|
||||
class VertexGroup: public std::pair<BoneWeightList, IndexList>
|
||||
{
|
||||
public:
|
||||
BoneWeight(const std::string& name, float weight) : _boneName(name), _weight(weight) {}
|
||||
const std::string& getBoneName() const { return _boneName; }
|
||||
float getWeight() const { return _weight; }
|
||||
void setWeight(float weight) { _weight = weight; }
|
||||
bool operator==(const BoneWeight& b) const { return (_boneName == b.getBoneName() && _weight == b.getWeight()); }
|
||||
protected:
|
||||
std::string _boneName;
|
||||
float _weight;
|
||||
inline const BoneWeightList& getBoneWeights() const { return first; }
|
||||
inline void setBoneWeights( BoneWeightList& o ) { first=o; }
|
||||
inline IndexList& vertIDs() { return second; }
|
||||
};
|
||||
|
||||
typedef std::vector<BoneWeight> BoneWeightList;
|
||||
typedef std::map<int,BoneWeightList> VertexIndexToBoneWeightMap;
|
||||
/// compute the minimal VertexGroup Set in which vertices shares the same influence set
|
||||
void computeMinimalVertexGroupList(std::vector<VertexGroup>&uniqVertexGroupList, unsigned int numvert) const;
|
||||
|
||||
class UniqVertexSetToBoneSet
|
||||
{
|
||||
public:
|
||||
void setBones(BoneWeightList& bones) { _bones = bones;}
|
||||
const BoneWeightList& getBones() const { return _bones;}
|
||||
std::vector<int>& getVertexes() { return _vertexes;}
|
||||
const std::vector<int>& getVertexes() const { return _vertexes;}
|
||||
protected:
|
||||
std::vector<int> _vertexes;
|
||||
BoneWeightList _bones; // here we could limit matrix operation by caching (weight * matrix)
|
||||
};
|
||||
|
||||
typedef std::vector<UniqVertexSetToBoneSet> UniqVertexSetToBoneSetList;
|
||||
|
||||
const UniqVertexSetToBoneSetList& getUniqVertexSetToBoneSetList() const { return _uniqVertexSetToBoneSet;}
|
||||
void addVertexInfluence(const VertexInfluence& v);
|
||||
void buildVertex2BoneList();
|
||||
void buildUniqVertexSetToBoneSetList();
|
||||
void clear();
|
||||
|
||||
const VertexIndexToBoneWeightMap& getVertexToBoneList() const;
|
||||
protected:
|
||||
BoneToVertexList _bone2Vertexes;
|
||||
VertexIndexToBoneWeightMap _vertex2Bones;
|
||||
UniqVertexSetToBoneSetList _uniqVertexSetToBoneSet;
|
||||
//Experimental removal of unexpressed bone from the skeleton
|
||||
void removeUnexpressedBones(Skeleton &skel) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -134,7 +134,7 @@ public:
|
||||
: _name(copy._name), _indentDelta(copy._indentDelta) {}
|
||||
|
||||
void set( const char* name, int delta=0 )
|
||||
{ _name = name, _indentDelta = delta; }
|
||||
{ _name = name; _indentDelta = delta; }
|
||||
|
||||
std::string _name;
|
||||
int _indentDelta;
|
||||
|
||||
@@ -366,6 +366,13 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
||||
/** Set the password map to be used by plugins when access files from secure locations.*/
|
||||
void setAuthenticationMap(AuthenticationMap* authenticationMap) { _authenticationMap = authenticationMap; }
|
||||
|
||||
/** Get the password map to be used by plugins when access files from secure locations. Create a AuthenticationMap if one isn't already assigned.*/
|
||||
AuthenticationMap* getOrCreateAuthenticationMap()
|
||||
{
|
||||
if (!_authenticationMap) _authenticationMap = new AuthenticationMap;
|
||||
return _authenticationMap.get();
|
||||
}
|
||||
|
||||
/** Get the password map to be used by plugins when access files from secure locations.*/
|
||||
AuthenticationMap* getAuthenticationMap() { return _authenticationMap.get(); }
|
||||
|
||||
|
||||
@@ -265,7 +265,7 @@ namespace osgParticle
|
||||
* for all graphics contexts. */
|
||||
virtual void releaseGLObjects(osg::State* state=0) const;
|
||||
|
||||
virtual osg::VertexArrayState* createVertexArrayState(osg::RenderInfo& renderInfo) const;
|
||||
virtual osg::VertexArrayState* createVertexArrayStateImplemenation(osg::RenderInfo& renderInfo) const;
|
||||
|
||||
void adjustEstimatedMaxNumOfParticles(int delta) { _estimatedMaxNumOfParticles += delta; }
|
||||
|
||||
|
||||
@@ -68,6 +68,8 @@ class OSGSHADOW_EXPORT ShadowMap : public ShadowTechnique
|
||||
/** Add a shader to internal list, will be used instead of the default ones */
|
||||
inline void addShader(osg::Shader* shader) { _shaderList.push_back(shader); }
|
||||
|
||||
template<class T> void addShader( const osg::ref_ptr<T>& shader ) { addShader(shader.get()); }
|
||||
|
||||
/** Reset internal shader list */
|
||||
inline void clearShaderList() { _shaderList.clear(); }
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ class OSGTERRAIN_EXPORT SharedGeometry : public osg::Drawable
|
||||
const VertexToHeightFieldMapping& getVertexToHeightFieldMapping() const { return _vertexToHeightFieldMapping; }
|
||||
|
||||
|
||||
osg::VertexArrayState* createVertexArrayState(osg::RenderInfo& renderInfo) const;
|
||||
osg::VertexArrayState* createVertexArrayStateImplementation(osg::RenderInfo& renderInfo) const;
|
||||
|
||||
void compileGLObjects(osg::RenderInfo& renderInfo) const;
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace osgText {
|
||||
|
||||
// forward declare Font
|
||||
class Font;
|
||||
class TextBase;
|
||||
|
||||
#ifdef OSG_PROVIDE_READFILE
|
||||
/** Read a font from specified file. The filename may contain a path.
|
||||
@@ -84,13 +85,9 @@ public:
|
||||
|
||||
static osg::ref_ptr<Font>& getDefaultFont();
|
||||
|
||||
void setTexEnv(osg::TexEnv* texenv) { if (texenv) _texenv = texenv; }
|
||||
inline osg::TexEnv* getTexEnv() { return _texenv.get(); }
|
||||
inline const osg::TexEnv* getTexEnv() const { return _texenv.get(); }
|
||||
|
||||
void setStateSet(osg::StateSet* stateset) { _stateset = stateset; }
|
||||
osg::StateSet* getStateSet() { return _stateset.get(); }
|
||||
const osg::StateSet* getStateSet() const { return _stateset.get(); }
|
||||
typedef std::vector< osg::ref_ptr<osg::StateSet> > StateSets;
|
||||
StateSets& getCachedStateSets() { return _statesets; }
|
||||
const StateSets& getCachedStateSets() const { return _statesets; }
|
||||
|
||||
|
||||
/** Get a kerning (adjustment of spacing of two adjacent character) for specified charcodes and a font resolution.*/
|
||||
@@ -110,19 +107,6 @@ public:
|
||||
* return true on success, return false when not supported.*/
|
||||
virtual bool getVerticalSize(float& ascender, float& descender) const { return _implementation ? _implementation->getVerticalSize(ascender, descender) : false; }
|
||||
|
||||
/** Set the margin around each glyph,
|
||||
* to ensure that texture filtering doesn't bleed adjacent glyph's into each other.
|
||||
* Default margin is 1 texels.*/
|
||||
void setGlyphImageMargin(unsigned int margin);
|
||||
unsigned int getGlyphImageMargin() const;
|
||||
|
||||
/** Set the margin ratio around each glyph, relative to the glyph's size.
|
||||
* to ensure that texture filtering doesn't bleed adjacent glyph's into each other.
|
||||
* Default margin is 0.05.*/
|
||||
void setGlyphImageMarginRatio(float margin);
|
||||
float getGlyphImageMarginRatio() const;
|
||||
|
||||
|
||||
/** Set the size of texture to create to store the glyph images when rendering.
|
||||
* Note, this doesn't affect already created Texture Glhph's.*/
|
||||
void setTextureSizeHint(unsigned int width,unsigned int height);
|
||||
@@ -140,6 +124,9 @@ public:
|
||||
void setMagFilterHint(osg::Texture::FilterMode mode);
|
||||
osg::Texture::FilterMode getMagFilterHint() const;
|
||||
|
||||
void setMaxAnisotropy(float anis) { _maxAnisotropy = anis; }
|
||||
float getMaxAnisotropy() const { return _maxAnisotropy; }
|
||||
|
||||
unsigned int getFontDepth() const { return _depth; }
|
||||
|
||||
void setNumberCurveSamples(unsigned int numSamples) { _numCurveSamples = numSamples; }
|
||||
@@ -170,13 +157,14 @@ public:
|
||||
typedef std::vector< osg::ref_ptr<GlyphTexture> > GlyphTextureList;
|
||||
GlyphTextureList& getGlyphTextureList() { return _glyphTextureList; }
|
||||
|
||||
void assignGlyphToGlyphTexture(Glyph* glyph, ShaderTechnique shaderTechnique);
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Font();
|
||||
|
||||
void addGlyph(const FontResolution& fontRes, unsigned int charcode, Glyph* glyph);
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osg::StateSet> > StateSetList;
|
||||
typedef std::map< unsigned int, osg::ref_ptr<Glyph> > GlyphMap;
|
||||
typedef std::map< unsigned int, osg::ref_ptr<Glyph3D> > Glyph3DMap;
|
||||
|
||||
@@ -185,8 +173,7 @@ protected:
|
||||
|
||||
mutable OpenThreads::Mutex _glyphMapMutex;
|
||||
|
||||
osg::ref_ptr<osg::TexEnv> _texenv;
|
||||
osg::ref_ptr<osg::StateSet> _stateset;
|
||||
StateSets _statesets;
|
||||
FontSizeGlyphMap _sizeGlyphMap;
|
||||
GlyphTextureList _glyphTextureList;
|
||||
|
||||
@@ -195,13 +182,12 @@ protected:
|
||||
|
||||
// current active size of font
|
||||
FontResolution _fontSize;
|
||||
unsigned int _margin;
|
||||
float _marginRatio;
|
||||
|
||||
unsigned int _textureWidthHint;
|
||||
unsigned int _textureHeightHint;
|
||||
osg::Texture::FilterMode _minFilterHint;
|
||||
osg::Texture::FilterMode _magFilterHint;
|
||||
float _maxAnisotropy;
|
||||
|
||||
unsigned int _depth;
|
||||
unsigned int _numCurveSamples;
|
||||
@@ -247,8 +233,6 @@ public:
|
||||
virtual bool getVerticalSize(float & /*ascender*/, float & /*descender*/) const { return false; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -30,15 +30,6 @@
|
||||
|
||||
#include <OpenThreads/Mutex>
|
||||
|
||||
// GL_ALPHA is deprecated in GL3/GL4 core profile, use GL_RED and a shader in this case. See osgText example.
|
||||
#if defined(OSG_GL3_AVAILABLE) && !defined(OSG_GL2_AVAILABLE) && !defined(OSG_GL1_AVAILABLE)
|
||||
#define OSGTEXT_GLYPH_FORMAT GL_RED
|
||||
#define OSGTEXT_GLYPH_INTERNALFORMAT GL_R8
|
||||
#else
|
||||
#define OSGTEXT_GLYPH_FORMAT GL_ALPHA
|
||||
#define OSGTEXT_GLYPH_INTERNALFORMAT GL_ALPHA
|
||||
#endif
|
||||
|
||||
namespace osgText {
|
||||
|
||||
class Font;
|
||||
@@ -47,6 +38,14 @@ class Glyph3D;
|
||||
class GlyphGeometry;
|
||||
class GlyphTexture;
|
||||
|
||||
enum ShaderTechnique
|
||||
{
|
||||
NO_TEXT_SHADER = 0x0,
|
||||
GREYSCALE = 0x1,
|
||||
SIGNED_DISTANCE_FIELD = 0x2,
|
||||
ALL_FEATURES = GREYSCALE | SIGNED_DISTANCE_FIELD
|
||||
};
|
||||
|
||||
class OSGTEXT_EXPORT Glyph : public osg::Image
|
||||
{
|
||||
public:
|
||||
@@ -58,6 +57,9 @@ public:
|
||||
|
||||
unsigned int getGlyphCode() const { return _glyphCode; }
|
||||
|
||||
void setFontResolution(const FontResolution& fontRes) { _fontResolution = fontRes; }
|
||||
const FontResolution& getFontResolution() const { return _fontResolution; }
|
||||
|
||||
void setWidth(float width) { _width = width; }
|
||||
float getWidth() const { return _width; }
|
||||
|
||||
@@ -76,21 +78,33 @@ public:
|
||||
void setVerticalAdvance(float advance);
|
||||
float getVerticalAdvance() const;
|
||||
|
||||
void setTexture(GlyphTexture* texture);
|
||||
GlyphTexture* getTexture();
|
||||
const GlyphTexture* getTexture() const;
|
||||
struct TextureInfo : public osg::Referenced
|
||||
{
|
||||
TextureInfo():
|
||||
texture(0),
|
||||
texelMargin(0.0f) {}
|
||||
|
||||
void setTexturePosition(int posX,int posY);
|
||||
int getTexturePositionX() const;
|
||||
int getTexturePositionY() const;
|
||||
TextureInfo(GlyphTexture* tex, int x, int y, const osg::Vec2& mintc, const osg::Vec2& maxtc, float margin):
|
||||
texture(tex),
|
||||
texturePositionX(x),
|
||||
texturePositionY(y),
|
||||
minTexCoord(mintc),
|
||||
maxTexCoord(maxtc),
|
||||
texelMargin(margin) {}
|
||||
|
||||
void setMinTexCoord(const osg::Vec2& coord);
|
||||
const osg::Vec2& getMinTexCoord() const;
|
||||
GlyphTexture* texture;
|
||||
int texturePositionX;
|
||||
int texturePositionY;
|
||||
osg::Vec2 minTexCoord;
|
||||
osg::Vec2 maxTexCoord;
|
||||
float texelMargin;
|
||||
};
|
||||
|
||||
void setMaxTexCoord(const osg::Vec2& coord);
|
||||
const osg::Vec2& getMaxTexCoord() const;
|
||||
void setTextureInfo(ShaderTechnique technique, TextureInfo* info);
|
||||
|
||||
void subload() const;
|
||||
const TextureInfo* getTextureInfo(ShaderTechnique technique) const;
|
||||
|
||||
TextureInfo* getOrCreateTextureInfo(ShaderTechnique technique);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -99,6 +113,8 @@ protected:
|
||||
Font* _font;
|
||||
unsigned int _glyphCode;
|
||||
|
||||
FontResolution _fontResolution;
|
||||
|
||||
float _width;
|
||||
float _height;
|
||||
|
||||
@@ -108,15 +124,8 @@ protected:
|
||||
osg::Vec2 _verticalBearing;
|
||||
float _verticalAdvance;
|
||||
|
||||
GlyphTexture* _texture;
|
||||
int _texturePosX;
|
||||
int _texturePosY;
|
||||
osg::Vec2 _minTexCoord;
|
||||
osg::Vec2 _maxTexCoord;
|
||||
|
||||
typedef osg::buffered_value<GLuint> GLObjectList;
|
||||
mutable GLObjectList _globjList;
|
||||
|
||||
typedef std::vector< osg::ref_ptr<TextureInfo> > TextureInfoList;
|
||||
TextureInfoList _textureInfoList;
|
||||
};
|
||||
|
||||
class OSGTEXT_EXPORT GlyphGeometry : public osg::Referenced
|
||||
@@ -253,12 +262,13 @@ public:
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const osg::StateAttribute& rhs) const;
|
||||
|
||||
/** Set the margin around each glyph, to ensure that texture filtering doesn't bleed adjacent glyph's into each other.*/
|
||||
void setGlyphImageMargin(unsigned int margin) { _margin = margin; }
|
||||
unsigned int getGlyphImageMargin() const { return _margin; }
|
||||
void setShaderTechnique(ShaderTechnique technique) { _shaderTechnique = technique; }
|
||||
|
||||
void setGlyphImageMarginRatio(float margin) { _marginRatio = margin; }
|
||||
float getGlyphImageMarginRatio() const { return _marginRatio; }
|
||||
ShaderTechnique getShaderTechnique() const { return _shaderTechnique; }
|
||||
|
||||
|
||||
int getEffectMargin(const Glyph* glyph);
|
||||
int getTexelMargin(const Glyph* glyph);
|
||||
|
||||
bool getSpaceForGlyph(Glyph* glyph, int& posX, int& posY);
|
||||
|
||||
@@ -277,14 +287,13 @@ protected:
|
||||
|
||||
virtual ~GlyphTexture();
|
||||
|
||||
void copyGlyphImage(Glyph* glyph, Glyph::TextureInfo* info);
|
||||
|
||||
// parameter used to compute the size and position of empty space
|
||||
// in the texture which could accommodate new glyphs.
|
||||
int _margin;
|
||||
float _marginRatio;
|
||||
int _usedY;
|
||||
int _partUsedX;
|
||||
int _partUsedY;
|
||||
ShaderTechnique _shaderTechnique;
|
||||
|
||||
int _usedY;
|
||||
int _partUsedX;
|
||||
int _partUsedY;
|
||||
|
||||
typedef std::vector< osg::ref_ptr<Glyph> > GlyphRefList;
|
||||
typedef std::vector< const Glyph* > GlyphPtrList;
|
||||
|
||||
@@ -36,15 +36,12 @@ public:
|
||||
virtual const char* className() const { return "Text"; }
|
||||
virtual const char* libraryName() const { return "osgText"; }
|
||||
|
||||
virtual void setFont(Font* font=0) { setFont(osg::ref_ptr<Font>(font)); };
|
||||
/** Set the ShaderTechnique hint to specify what fatures in the text shaders to enable.*/
|
||||
void setShaderTechnique(ShaderTechnique technique);
|
||||
|
||||
/** Set the Font to use to render the text.*/
|
||||
virtual void setFont(osg::ref_ptr<Font> font);
|
||||
/** Get the ShaderTechnique hint.*/
|
||||
ShaderTechnique getShaderTechnique() { return _shaderTechnique; }
|
||||
|
||||
/** Set the font, loaded from the specified front file, to use to render the text,
|
||||
* setFont("") sets the use of the default font.
|
||||
* See the osgText::readFontFile function for how the font file will be located. */
|
||||
virtual void setFont(const std::string& fontfile) { TextBase::setFont(fontfile); }
|
||||
|
||||
/**
|
||||
* Turns off writing to the depth buffer when rendering text. This only affects text
|
||||
@@ -70,31 +67,6 @@ public:
|
||||
NONE
|
||||
};
|
||||
|
||||
enum BackdropImplementation
|
||||
{
|
||||
/* No longer supported, naps to DELAYED_DEPTH_WRITES.*/
|
||||
POLYGON_OFFSET = 0,
|
||||
|
||||
/* No longer supported, naps to DELAYED_DEPTH_WRITES.*/
|
||||
NO_DEPTH_BUFFER,
|
||||
|
||||
/* No longer supported, naps to DELAYED_DEPTH_WRITES.*/
|
||||
DEPTH_RANGE,
|
||||
|
||||
/* No longer supported, naps to DELAYED_DEPTH_WRITES.*/
|
||||
STENCIL_BUFFER,
|
||||
|
||||
/* DELAYED_DEPTH_WRITES
|
||||
* This mode renders all text with depth writes turned off, then
|
||||
* again with depth writes on, but with the color buffer disabled.
|
||||
* This should render text accurately for all graphics cards. The
|
||||
* only downside is the additional pass to render to the depth
|
||||
* buffer. But if you don't need the depth buffer updated for
|
||||
* your, this extra pass can be disabled by calling
|
||||
* enableDepthWrites(false).*/
|
||||
DELAYED_DEPTH_WRITES
|
||||
};
|
||||
|
||||
/**
|
||||
* BackdropType gives you a background shadow text behind your regular
|
||||
* text. This helps give text extra contrast which can be useful when
|
||||
@@ -149,18 +121,6 @@ public:
|
||||
|
||||
const osg::Vec4& getBackdropColor() const { return _backdropColor; }
|
||||
|
||||
/**
|
||||
* This specifies the underlying backdrop rendering implementation.
|
||||
* Unfortunately, at this time, there is no "perfect" rendering solution
|
||||
* so this function is provided to let you 'pick your poison'. Each
|
||||
* implementation has trade-offs. See BackdropImplementation enum
|
||||
* docs for details.*/
|
||||
void setBackdropImplementation(BackdropImplementation implementation);
|
||||
|
||||
BackdropImplementation getBackdropImplementation() const { return _backdropImplementation; }
|
||||
|
||||
|
||||
|
||||
enum ColorGradientMode
|
||||
{
|
||||
SOLID = 0, // a.k.a. ColorGradients off
|
||||
@@ -222,9 +182,13 @@ public:
|
||||
virtual void accept(osg::PrimitiveFunctor& pf) const;
|
||||
|
||||
|
||||
/** Get the coordinates of the character corners in local coordinates. Use Text::getMatrix() or Text::computeMatrix(..) to get the transform into model coordinates (see TextBase header.) */
|
||||
bool getCharacterCorners(unsigned int index, osg::Vec3& bottomLeft, osg::Vec3& bottomRight, osg::Vec3& topLeft, osg::Vec3& topRight) const;
|
||||
|
||||
/** Resize any per context GLObject buffers to specified size. */
|
||||
virtual void resizeGLObjectBuffers(unsigned int maxSize);
|
||||
|
||||
|
||||
/** If State is non-zero, this function releases OpenGL objects for
|
||||
* the specified graphics context. Otherwise, releases OpenGL objexts
|
||||
* for all graphics contexts. */
|
||||
@@ -232,6 +196,20 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
/** deprecated, value ignored.*/
|
||||
enum BackdropImplementation
|
||||
{
|
||||
POLYGON_OFFSET = 0,
|
||||
NO_DEPTH_BUFFER,
|
||||
DEPTH_RANGE,
|
||||
STENCIL_BUFFER,
|
||||
DELAYED_DEPTH_WRITES
|
||||
};
|
||||
|
||||
/** deprecated, value ignored.*/
|
||||
void setBackdropImplementation(BackdropImplementation) {}
|
||||
/** deprecated, value should be ignored.*/
|
||||
BackdropImplementation getBackdropImplementation() const { return DELAYED_DEPTH_WRITES; }
|
||||
|
||||
// internal structures, variable and methods used for rendering of characters.
|
||||
struct OSGTEXT_EXPORT GlyphQuads
|
||||
@@ -239,7 +217,7 @@ public:
|
||||
typedef std::vector<Glyph*> Glyphs;
|
||||
|
||||
Glyphs _glyphs;
|
||||
Primitives _primitives;
|
||||
osg::ref_ptr<osg::DrawElements> _primitives;
|
||||
|
||||
GlyphQuads();
|
||||
GlyphQuads(const GlyphQuads& gq);
|
||||
@@ -284,6 +262,8 @@ protected:
|
||||
|
||||
virtual ~Text();
|
||||
|
||||
virtual osg::StateSet* createStateSet();
|
||||
|
||||
Font* getActiveFont();
|
||||
const Font* getActiveFont() const;
|
||||
|
||||
@@ -302,7 +282,6 @@ protected:
|
||||
|
||||
virtual void computePositionsImplementation();
|
||||
|
||||
void computeBackdropPositions();
|
||||
void computeBackdropBoundingBox();
|
||||
void computeBoundingBoxMargin();
|
||||
|
||||
@@ -314,10 +293,10 @@ protected:
|
||||
|
||||
void drawImplementationSinglePass(osg::State& state, const osg::Vec4& colorMultiplier) const;
|
||||
|
||||
ShaderTechnique _shaderTechnique;
|
||||
bool _enableDepthWrites;
|
||||
|
||||
BackdropType _backdropType;
|
||||
BackdropImplementation _backdropImplementation;
|
||||
|
||||
float _backdropHorizontalOffset;
|
||||
float _backdropVerticalOffset;
|
||||
|
||||
@@ -53,6 +53,9 @@ public:
|
||||
virtual void setFont(const std::string& fontfile);
|
||||
|
||||
/** Get the font. Return 0 if default is being used.*/
|
||||
Font* getFont() { return _font.get(); }
|
||||
|
||||
/** Get the const font. Return 0 if default is being used.*/
|
||||
const Font* getFont() const { return _font.get(); }
|
||||
|
||||
|
||||
@@ -276,19 +279,23 @@ public:
|
||||
void getCoord(unsigned int i, osg::Vec2& c) const { c.set((*_coords)[i].x(), (*_coords)[i].y()); }
|
||||
void getCoord(unsigned int i, osg::Vec3& c) const { c = (*_coords)[i]; }
|
||||
|
||||
|
||||
/** Get the internal matrix used to provide positioning of text.*/
|
||||
/** Get the cached internal matrix used to provide positioning of text. The cached matrix is originally computed by computeMatrix(..). */
|
||||
const osg::Matrix& getMatrix() const { return _matrix; }
|
||||
|
||||
/** compute the matrix that positions the text in model space for the given viewpoint.*/
|
||||
bool computeMatrix(osg::Matrix& matrix, osg::State* state=0) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~TextBase();
|
||||
|
||||
virtual osg::StateSet* createStateSet();
|
||||
|
||||
virtual void assignStateSet();
|
||||
|
||||
void initArraysAndBuffers();
|
||||
|
||||
osg::VertexArrayState* createVertexArrayState(osg::RenderInfo& renderInfo) const;
|
||||
|
||||
bool computeMatrix(osg::Matrix& matrix, osg::State* state=0) const;
|
||||
osg::VertexArrayState* createVertexArrayStateImplementation(osg::RenderInfo& renderInfo) const;
|
||||
|
||||
void positionCursor(const osg::Vec2 & endOfLine_coords, osg::Vec2 & cursor, unsigned int linelength);
|
||||
String::iterator computeLastCharacterOnLine(osg::Vec2& cursor, String::iterator first,String::iterator last);
|
||||
|
||||
@@ -91,22 +91,33 @@ class OSGUTIL_EXPORT GLObjectsVisitor : public osg::NodeVisitor
|
||||
return _renderInfo;
|
||||
}
|
||||
|
||||
/** Set whether and how often OpenGL errors should be checked for, defaults to osg::State::ONCE_PER_ATTRIBUTE. */
|
||||
void setCheckForGLErrors(osg::State::CheckForGLErrors check) { _checkGLErrors = check; }
|
||||
|
||||
/** Get whether and how often OpenGL errors should be checked for.*/
|
||||
osg::State::CheckForGLErrors getCheckForGLErrors() const { return _checkGLErrors; }
|
||||
|
||||
/** Simply traverse using standard NodeVisitor traverse method.*/
|
||||
virtual void apply(osg::Node& node);
|
||||
|
||||
void apply(osg::Drawable& drawable);
|
||||
void apply(osg::StateSet& stateset);
|
||||
|
||||
/** Do a compile traversal and then reset any state,*/
|
||||
void compile(osg::Node& node);
|
||||
|
||||
protected:
|
||||
|
||||
typedef std::set<osg::Drawable*> DrawableAppliedSet;
|
||||
typedef std::set<osg::StateSet*> StatesSetAppliedSet;
|
||||
|
||||
Mode _mode;
|
||||
osg::RenderInfo _renderInfo;
|
||||
DrawableAppliedSet _drawablesAppliedSet;
|
||||
StatesSetAppliedSet _stateSetAppliedSet;
|
||||
osg::ref_ptr<osg::Program> _lastCompiledProgram;
|
||||
Mode _mode;
|
||||
osg::RenderInfo _renderInfo;
|
||||
osg::State::CheckForGLErrors _checkGLErrors;
|
||||
|
||||
DrawableAppliedSet _drawablesAppliedSet;
|
||||
StatesSetAppliedSet _stateSetAppliedSet;
|
||||
osg::ref_ptr<osg::Program> _lastCompiledProgram;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -52,8 +52,8 @@ class OSGUTIL_EXPORT RenderLeaf : public osg::Referenced
|
||||
{
|
||||
_parent = 0;
|
||||
_drawable = drawable;
|
||||
_projection = projection,
|
||||
_modelview = modelview,
|
||||
_projection = projection;
|
||||
_modelview = modelview;
|
||||
_depth = depth;
|
||||
_dynamic = (drawable->getDataVariance()==osg::Object::DYNAMIC);
|
||||
_traversalNumber = traversalNumber;
|
||||
|
||||
@@ -16,8 +16,17 @@
|
||||
|
||||
#include <osgViewer/Export>
|
||||
|
||||
// Fallback if not correctly detected in CMake macro
|
||||
#ifndef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0500
|
||||
//#define _WIN32_WINNT 0x0A00 // Windows 10
|
||||
//#define _WIN32_WINNT 0x0603 // Windows 8.1
|
||||
//#define _WIN32_WINNT 0x0602 // Windows 8
|
||||
//#define _WIN32_WINNT 0x0601 // Windows 7
|
||||
//#define _WIN32_WINNT 0x0600 // Windows Server 2008
|
||||
//#define _WIN32_WINNT 0x0600 // Windows Vista
|
||||
//#define _WIN32_WINNT 0x0502 // Windows Server 2003 with SP1, Windows XP with SP2
|
||||
//#define _WIN32_WINNT 0x0501 // Windows Server 2003, Windows XP
|
||||
#define _WIN32_WINNT 0x0500 // Windows NT
|
||||
#endif
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
@@ -37,10 +37,11 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow, pub
|
||||
_parent(0),
|
||||
_window(0),
|
||||
_visualInfo(0),
|
||||
_fbConfig(0),
|
||||
#ifdef OSG_USE_EGL
|
||||
_eglDisplay(0),
|
||||
_eglSurface(0),
|
||||
#else
|
||||
_fbConfig(0),
|
||||
#endif
|
||||
_currentCursor(0),
|
||||
_initialized(false),
|
||||
@@ -54,7 +55,7 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow, pub
|
||||
memset(_keyMap, 0, 32);
|
||||
|
||||
init();
|
||||
|
||||
|
||||
if (valid())
|
||||
{
|
||||
setState( new osg::State );
|
||||
@@ -72,7 +73,7 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow, pub
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const GraphicsWindowX11*>(object)!=0; }
|
||||
virtual const char* libraryName() const { return "osgViewer"; }
|
||||
virtual const char* className() const { return "GraphicsWindowX11"; }
|
||||
@@ -129,35 +130,35 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow, pub
|
||||
{
|
||||
WindowData(Window window):
|
||||
_window(window) {}
|
||||
|
||||
|
||||
Window _window;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
|
||||
// X11 specific access functions
|
||||
|
||||
Display* getEventDisplay() const { return _eventDisplay; }
|
||||
Display* getDisplayToUse() const ;
|
||||
|
||||
|
||||
|
||||
Window& getParent() { return _parent; }
|
||||
Window& getWindow() { return _window; }
|
||||
|
||||
Cursor getCurrentCursor() { return _currentCursor; }
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
~GraphicsWindowX11();
|
||||
|
||||
|
||||
Cursor getOrCreateCursor(MouseCursor mouseShape);
|
||||
|
||||
|
||||
bool createVisualInfo();
|
||||
|
||||
bool createWindow();
|
||||
|
||||
bool setWindow(Window window);
|
||||
|
||||
|
||||
void init();
|
||||
|
||||
bool checkAndSendEventFullScreenIfNeeded(Display* display, int x, int y, int width, int height, bool windowDecoration);
|
||||
@@ -171,23 +172,24 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow, pub
|
||||
int getModifierMask() const;
|
||||
void syncLocks();
|
||||
void flushKeyEvents();
|
||||
|
||||
|
||||
bool _valid;
|
||||
Display* _eventDisplay;
|
||||
Window _parent;
|
||||
Window _window;
|
||||
XVisualInfo* _visualInfo;
|
||||
GLXFBConfig _fbConfig;
|
||||
|
||||
#ifdef OSG_USE_EGL
|
||||
EGLDisplay _eglDisplay;
|
||||
EGLSurface _eglSurface;
|
||||
#else
|
||||
GLXFBConfig _fbConfig;
|
||||
#endif
|
||||
|
||||
Cursor _currentCursor;
|
||||
|
||||
Atom _deleteWindow;
|
||||
|
||||
|
||||
bool _initialized;
|
||||
bool _realized;
|
||||
bool _ownsWindow;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <osg/ApplicationUsage>
|
||||
#include <osg/Object>
|
||||
#include <osg/Math>
|
||||
#include <osg/EnvVar>
|
||||
#include <osg/ref_ptr>
|
||||
|
||||
#include <sstream>
|
||||
@@ -317,10 +318,16 @@ void ApplicationUsage::writeEnvironmentSettings(std::ostream& output)
|
||||
std::string::size_type len = citr->first.find_first_of("\n\r\t ");
|
||||
if (len == std::string::npos) len = citr->first.size();
|
||||
line.replace(optionPos,len,citr->first.substr(0,len));
|
||||
const char *cp = getenv(citr->first.substr(0, len).c_str());
|
||||
if (!cp) cp = "[not set]";
|
||||
else if (!*cp) cp = "[set]";
|
||||
line += std::string(cp) + "\n";
|
||||
|
||||
std::string value;
|
||||
if (getEnvVar(citr->first.substr(0, len).c_str(), value))
|
||||
{
|
||||
line += "[set]\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
line += "[not set]\n";
|
||||
}
|
||||
|
||||
output << line;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ SET(TARGET_H
|
||||
${HEADER_PATH}/ColorMaski
|
||||
${HEADER_PATH}/ColorMatrix
|
||||
${HEADER_PATH}/ComputeBoundsVisitor
|
||||
${HEADER_PATH}/ComputeDispatch
|
||||
${HEADER_PATH}/ContextData
|
||||
${HEADER_PATH}/ConvexPlanarOccluder
|
||||
${HEADER_PATH}/ConvexPlanarPolygon
|
||||
@@ -267,6 +268,7 @@ SET(TARGET_SRC
|
||||
ColorMaski.cpp
|
||||
ColorMatrix.cpp
|
||||
ComputeBoundsVisitor.cpp
|
||||
ComputeDispatch.cpp
|
||||
ContextData.cpp
|
||||
ConvexPlanarOccluder.cpp
|
||||
ConvexPlanarPolygon.cpp
|
||||
|
||||
16
src/osg/ComputeDispatch.cpp
Normal file
16
src/osg/ComputeDispatch.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <osg/ComputeDispatch>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
ComputeDispatch::ComputeDispatch(const ComputeDispatch&o,const osg::CopyOp& copyop):
|
||||
Drawable(o,copyop),
|
||||
_numGroupsX(o._numGroupsX),
|
||||
_numGroupsY(o._numGroupsY),
|
||||
_numGroupsZ(o._numGroupsZ)
|
||||
{
|
||||
}
|
||||
|
||||
void ComputeDispatch::drawImplementation(RenderInfo& renderInfo) const
|
||||
{
|
||||
renderInfo.getState()->get<GLExtensions>()->glDispatchCompute(_numGroupsX, _numGroupsY, _numGroupsZ);
|
||||
}
|
||||
@@ -34,5 +34,6 @@
|
||||
#cmakedefine OSG_DISABLE_MSVC_WARNINGS
|
||||
#cmakedefine OSG_PROVIDE_READFILE
|
||||
#cmakedefine OSG_USE_DEPRECATED_API
|
||||
#cmakedefine OSG_ENVVAR_SUPPORTED
|
||||
|
||||
#endif
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <osg/CullSettings>
|
||||
#include <osg/ArgumentParser>
|
||||
#include <osg/ApplicationUsage>
|
||||
#include <osg/EnvVar>
|
||||
|
||||
#include <osg/Notify>
|
||||
|
||||
@@ -97,25 +98,21 @@ void CullSettings::readEnvironmentalVariables()
|
||||
{
|
||||
OSG_INFO<<"CullSettings::readEnvironmentalVariables()"<<std::endl;
|
||||
|
||||
char *ptr;
|
||||
|
||||
if ((ptr = getenv("OSG_COMPUTE_NEAR_FAR_MODE")) != 0)
|
||||
std::string value;
|
||||
if (getEnvVar("OSG_COMPUTE_NEAR_FAR_MODE", value))
|
||||
{
|
||||
if (strcmp(ptr,"DO_NOT_COMPUTE_NEAR_FAR")==0) _computeNearFar = DO_NOT_COMPUTE_NEAR_FAR;
|
||||
else if (strcmp(ptr,"COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES")==0) _computeNearFar = COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES;
|
||||
else if (strcmp(ptr,"COMPUTE_NEAR_FAR_USING_PRIMITIVES")==0) _computeNearFar = COMPUTE_NEAR_FAR_USING_PRIMITIVES;
|
||||
if (value=="DO_NOT_COMPUTE_NEAR_FAR") _computeNearFar = DO_NOT_COMPUTE_NEAR_FAR;
|
||||
else if (value=="COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES") _computeNearFar = COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES;
|
||||
else if (value=="COMPUTE_NEAR_FAR_USING_PRIMITIVES") _computeNearFar = COMPUTE_NEAR_FAR_USING_PRIMITIVES;
|
||||
|
||||
OSG_INFO<<"Set compute near far mode to "<<_computeNearFar<<std::endl;
|
||||
|
||||
}
|
||||
|
||||
if ((ptr = getenv("OSG_NEAR_FAR_RATIO")) != 0)
|
||||
if (getEnvVar("OSG_NEAR_FAR_RATIO", _nearFarRatio))
|
||||
{
|
||||
_nearFarRatio = osg::asciiToDouble(ptr);
|
||||
|
||||
OSG_INFO<<"Set near/far ratio to "<<_nearFarRatio<<std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CullSettings::readCommandLine(ArgumentParser& arguments)
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <osg/Math>
|
||||
#include <osg/Notify>
|
||||
#include <osg/GL>
|
||||
#include <osg/EnvVar>
|
||||
#include <osg/ref_ptr>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -118,7 +119,8 @@ void DisplaySettings::setDisplaySettings(const DisplaySettings& vs)
|
||||
_swapMethod = vs._swapMethod;
|
||||
|
||||
_vertexBufferHint = vs._vertexBufferHint;
|
||||
_shaderHint = vs._shaderHint;
|
||||
|
||||
setShaderHint(_shaderHint);
|
||||
|
||||
_keystoneHint = vs._keystoneHint;
|
||||
_keystoneFileNames = vs._keystoneFileNames;
|
||||
@@ -250,23 +252,17 @@ void DisplaySettings::setDefaults()
|
||||
// _vertexBufferHint = VERTEX_ARRAY_OBJECT;
|
||||
|
||||
#if defined(OSG_GLES3_AVAILABLE)
|
||||
_shaderHint = SHADER_GLES3;
|
||||
OSG_INFO<<"DisplaySettings::SHADER_GLES3"<<std::endl;
|
||||
setShaderHint(SHADER_GLES3);
|
||||
#elif defined(OSG_GLES2_AVAILABLE)
|
||||
_shaderHint = SHADER_GLES2;
|
||||
OSG_INFO<<"DisplaySettings::SHADER_GLES2"<<std::endl;
|
||||
setShaderHint(SHADER_GLES2);
|
||||
#elif defined(OSG_GL3_AVAILABLE)
|
||||
_shaderHint = SHADER_GL3;
|
||||
OSG_INFO<<"DisplaySettings::SHADER_GL3"<<std::endl;
|
||||
setShaderHint(SHADER_GL3);
|
||||
#elif defined(OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE)
|
||||
OSG_INFO<<"DisplaySettings::SHADER_NONE"<<std::endl;
|
||||
_shaderHint = SHADER_NONE;
|
||||
setShaderHint(SHADER_NONE);
|
||||
#else
|
||||
OSG_INFO<<"DisplaySettings::SHADER_GL2"<<std::endl;
|
||||
_shaderHint = SHADER_GL2;
|
||||
setShaderHint(SHADER_GL2);
|
||||
#endif
|
||||
|
||||
|
||||
_keystoneHint = false;
|
||||
|
||||
_OSXMenubarBehavior = MENUBAR_AUTO_HIDE;
|
||||
@@ -390,225 +386,188 @@ static ApplicationUsageProxy DisplaySetting_e31(ApplicationUsage::ENVIRONMENTAL_
|
||||
static ApplicationUsageProxy DisplaySetting_e32(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
|
||||
"OSG_VERTEX_BUFFER_HINT <value>",
|
||||
"Set the hint to what backend osg::Geometry implementation to use. NO_PREFERENCE | VERTEX_BUFFER_OBJECT | VERTEX_ARRAY_OBJECT");
|
||||
static ApplicationUsageProxy DisplaySetting_e33(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
|
||||
"OSG_TEXT_SHADER_TECHNIQUE <value>",
|
||||
"Set the defafult osgText::ShaderTechnique. ALL_FEATURES | ALL | GREYSCALE | SIGNED_DISTANCE_FIELD | SDF | NO_TEXT_SHADER | NONE");
|
||||
|
||||
void DisplaySettings::readEnvironmentalVariables()
|
||||
{
|
||||
const char* ptr = 0;
|
||||
|
||||
if ((ptr = getenv("OSG_DISPLAY_TYPE")) != 0)
|
||||
std::string value;
|
||||
if (getEnvVar("OSG_DISPLAY_TYPE", value))
|
||||
{
|
||||
if (strcmp(ptr,"MONITOR")==0)
|
||||
if (value=="MONITOR")
|
||||
{
|
||||
_displayType = MONITOR;
|
||||
}
|
||||
else
|
||||
if (strcmp(ptr,"POWERWALL")==0)
|
||||
if (value=="POWERWALL")
|
||||
{
|
||||
_displayType = POWERWALL;
|
||||
}
|
||||
else
|
||||
if (strcmp(ptr,"REALITY_CENTER")==0)
|
||||
if (value=="REALITY_CENTER")
|
||||
{
|
||||
_displayType = REALITY_CENTER;
|
||||
}
|
||||
else
|
||||
if (strcmp(ptr,"HEAD_MOUNTED_DISPLAY")==0)
|
||||
if (value=="HEAD_MOUNTED_DISPLAY")
|
||||
{
|
||||
_displayType = HEAD_MOUNTED_DISPLAY;
|
||||
}
|
||||
}
|
||||
|
||||
if( (ptr = getenv("OSG_STEREO_MODE")) != 0)
|
||||
if (getEnvVar("OSG_STEREO_MODE", value))
|
||||
{
|
||||
if (strcmp(ptr,"QUAD_BUFFER")==0)
|
||||
if (value=="QUAD_BUFFER")
|
||||
{
|
||||
_stereoMode = QUAD_BUFFER;
|
||||
}
|
||||
else if (strcmp(ptr,"ANAGLYPHIC")==0)
|
||||
else if (value=="ANAGLYPHIC")
|
||||
{
|
||||
_stereoMode = ANAGLYPHIC;
|
||||
}
|
||||
else if (strcmp(ptr,"HORIZONTAL_SPLIT")==0)
|
||||
else if (value=="HORIZONTAL_SPLIT")
|
||||
{
|
||||
_stereoMode = HORIZONTAL_SPLIT;
|
||||
}
|
||||
else if (strcmp(ptr,"VERTICAL_SPLIT")==0)
|
||||
else if (value=="VERTICAL_SPLIT")
|
||||
{
|
||||
_stereoMode = VERTICAL_SPLIT;
|
||||
}
|
||||
else if (strcmp(ptr,"LEFT_EYE")==0)
|
||||
else if (value=="LEFT_EYE")
|
||||
{
|
||||
_stereoMode = LEFT_EYE;
|
||||
}
|
||||
else if (strcmp(ptr,"RIGHT_EYE")==0)
|
||||
else if (value=="RIGHT_EYE")
|
||||
{
|
||||
_stereoMode = RIGHT_EYE;
|
||||
}
|
||||
else if (strcmp(ptr,"HORIZONTAL_INTERLACE")==0)
|
||||
else if (value=="HORIZONTAL_INTERLACE")
|
||||
{
|
||||
_stereoMode = HORIZONTAL_INTERLACE;
|
||||
}
|
||||
else if (strcmp(ptr,"VERTICAL_INTERLACE")==0)
|
||||
else if (value=="VERTICAL_INTERLACE")
|
||||
{
|
||||
_stereoMode = VERTICAL_INTERLACE;
|
||||
}
|
||||
else if (strcmp(ptr,"CHECKERBOARD")==0)
|
||||
else if (value=="CHECKERBOARD")
|
||||
{
|
||||
_stereoMode = CHECKERBOARD;
|
||||
}
|
||||
}
|
||||
|
||||
if( (ptr = getenv("OSG_STEREO")) != 0)
|
||||
if (getEnvVar("OSG_STEREO", value))
|
||||
{
|
||||
if (strcmp(ptr,"OFF")==0)
|
||||
if (value=="OFF")
|
||||
{
|
||||
_stereo = false;
|
||||
}
|
||||
else
|
||||
if (strcmp(ptr,"ON")==0)
|
||||
if (value=="ON")
|
||||
{
|
||||
_stereo = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( (ptr = getenv("OSG_EYE_SEPARATION")) != 0)
|
||||
{
|
||||
_eyeSeparation = osg::asciiToFloat(ptr);
|
||||
}
|
||||
getEnvVar("OSG_EYE_SEPARATION", _eyeSeparation);
|
||||
getEnvVar("OSG_SCREEN_WIDTH", _screenWidth);
|
||||
getEnvVar("OSG_SCREEN_HEIGHT", _screenHeight);
|
||||
getEnvVar("OSG_SCREEN_DISTANCE", _screenDistance);
|
||||
|
||||
if( (ptr = getenv("OSG_SCREEN_WIDTH")) != 0)
|
||||
if (getEnvVar("OSG_SPLIT_STEREO_HORIZONTAL_EYE_MAPPING", value))
|
||||
{
|
||||
_screenWidth = osg::asciiToFloat(ptr);
|
||||
}
|
||||
|
||||
if( (ptr = getenv("OSG_SCREEN_HEIGHT")) != 0)
|
||||
{
|
||||
_screenHeight = osg::asciiToFloat(ptr);
|
||||
}
|
||||
|
||||
if( (ptr = getenv("OSG_SCREEN_DISTANCE")) != 0)
|
||||
{
|
||||
_screenDistance = osg::asciiToFloat(ptr);
|
||||
}
|
||||
|
||||
if( (ptr = getenv("OSG_SPLIT_STEREO_HORIZONTAL_EYE_MAPPING")) != 0)
|
||||
{
|
||||
if (strcmp(ptr,"LEFT_EYE_LEFT_VIEWPORT")==0)
|
||||
if (value=="LEFT_EYE_LEFT_VIEWPORT")
|
||||
{
|
||||
_splitStereoHorizontalEyeMapping = LEFT_EYE_LEFT_VIEWPORT;
|
||||
}
|
||||
else
|
||||
if (strcmp(ptr,"LEFT_EYE_RIGHT_VIEWPORT")==0)
|
||||
if (value=="LEFT_EYE_RIGHT_VIEWPORT")
|
||||
{
|
||||
_splitStereoHorizontalEyeMapping = LEFT_EYE_RIGHT_VIEWPORT;
|
||||
}
|
||||
}
|
||||
|
||||
if( (ptr = getenv("OSG_SPLIT_STEREO_HORIZONTAL_SEPARATION")) != 0)
|
||||
{
|
||||
_splitStereoHorizontalSeparation = atoi(ptr);
|
||||
}
|
||||
getEnvVar("OSG_SPLIT_STEREO_HORIZONTAL_SEPARATION", _splitStereoHorizontalSeparation);
|
||||
|
||||
|
||||
if( (ptr = getenv("OSG_SPLIT_STEREO_VERTICAL_EYE_MAPPING")) != 0)
|
||||
if (getEnvVar("OSG_SPLIT_STEREO_VERTICAL_EYE_MAPPING", value))
|
||||
{
|
||||
if (strcmp(ptr,"LEFT_EYE_TOP_VIEWPORT")==0)
|
||||
if (value=="LEFT_EYE_TOP_VIEWPORT")
|
||||
{
|
||||
_splitStereoVerticalEyeMapping = LEFT_EYE_TOP_VIEWPORT;
|
||||
}
|
||||
else
|
||||
if (strcmp(ptr,"LEFT_EYE_BOTTOM_VIEWPORT")==0)
|
||||
if (value=="LEFT_EYE_BOTTOM_VIEWPORT")
|
||||
{
|
||||
_splitStereoVerticalEyeMapping = LEFT_EYE_BOTTOM_VIEWPORT;
|
||||
}
|
||||
}
|
||||
|
||||
if( (ptr = getenv("OSG_SPLIT_STEREO_AUTO_ADJUST_ASPECT_RATIO")) != 0)
|
||||
if (getEnvVar("OSG_SPLIT_STEREO_AUTO_ADJUST_ASPECT_RATIO", value))
|
||||
{
|
||||
if (strcmp(ptr,"OFF")==0)
|
||||
if (value=="OFF")
|
||||
{
|
||||
_splitStereoAutoAdjustAspectRatio = false;
|
||||
}
|
||||
else
|
||||
if (strcmp(ptr,"ON")==0)
|
||||
if (value=="ON")
|
||||
{
|
||||
_splitStereoAutoAdjustAspectRatio = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( (ptr = getenv("OSG_SPLIT_STEREO_VERTICAL_SEPARATION")) != 0)
|
||||
{
|
||||
_splitStereoVerticalSeparation = atoi(ptr);
|
||||
}
|
||||
getEnvVar("OSG_SPLIT_STEREO_VERTICAL_SEPARATION", _splitStereoVerticalSeparation);
|
||||
|
||||
if( (ptr = getenv("OSG_MAX_NUMBER_OF_GRAPHICS_CONTEXTS")) != 0)
|
||||
{
|
||||
_maxNumOfGraphicsContexts = atoi(ptr);
|
||||
}
|
||||
getEnvVar("OSG_MAX_NUMBER_OF_GRAPHICS_CONTEXTS", _maxNumOfGraphicsContexts);
|
||||
|
||||
if( (ptr = getenv("OSG_COMPILE_CONTEXTS")) != 0)
|
||||
if (getEnvVar("OSG_COMPILE_CONTEXTS", value))
|
||||
{
|
||||
if (strcmp(ptr,"OFF")==0)
|
||||
if (value=="OFF")
|
||||
{
|
||||
_compileContextsHint = false;
|
||||
}
|
||||
else
|
||||
if (strcmp(ptr,"ON")==0)
|
||||
if (value=="ON")
|
||||
{
|
||||
_compileContextsHint = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( (ptr = getenv("OSG_SERIALIZE_DRAW_DISPATCH")) != 0)
|
||||
if (getEnvVar("OSG_SERIALIZE_DRAW_DISPATCH", value))
|
||||
{
|
||||
if (strcmp(ptr,"OFF")==0)
|
||||
if (value=="OFF")
|
||||
{
|
||||
_serializeDrawDispatch = false;
|
||||
}
|
||||
else
|
||||
if (strcmp(ptr,"ON")==0)
|
||||
if (value=="ON")
|
||||
{
|
||||
_serializeDrawDispatch = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( (ptr = getenv("OSG_USE_SCENEVIEW_FOR_STEREO")) != 0)
|
||||
if (getEnvVar("OSG_USE_SCENEVIEW_FOR_STEREO", value))
|
||||
{
|
||||
if (strcmp(ptr,"OFF")==0)
|
||||
if (value=="OFF")
|
||||
{
|
||||
_useSceneViewForStereoHint = false;
|
||||
}
|
||||
else
|
||||
if (strcmp(ptr,"ON")==0)
|
||||
if (value=="ON")
|
||||
{
|
||||
_useSceneViewForStereoHint = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( (ptr = getenv("OSG_NUM_DATABASE_THREADS")) != 0)
|
||||
{
|
||||
_numDatabaseThreadsHint = atoi(ptr);
|
||||
}
|
||||
getEnvVar("OSG_NUM_DATABASE_THREADS", _numDatabaseThreadsHint);
|
||||
|
||||
if( (ptr = getenv("OSG_NUM_HTTP_DATABASE_THREADS")) != 0)
|
||||
{
|
||||
_numHttpDatabaseThreadsHint = atoi(ptr);
|
||||
}
|
||||
getEnvVar("OSG_NUM_HTTP_DATABASE_THREADS", _numHttpDatabaseThreadsHint);
|
||||
|
||||
if( (ptr = getenv("OSG_MULTI_SAMPLES")) != 0)
|
||||
{
|
||||
_numMultiSamples = atoi(ptr);
|
||||
}
|
||||
getEnvVar("OSG_MULTI_SAMPLES", _numMultiSamples);
|
||||
|
||||
if( (ptr = getenv("OSG_TEXTURE_POOL_SIZE")) != 0)
|
||||
{
|
||||
_maxTexturePoolSize = atoi(ptr);
|
||||
}
|
||||
getEnvVar("OSG_TEXTURE_POOL_SIZE", _maxTexturePoolSize);
|
||||
|
||||
if( (ptr = getenv("OSG_BUFFER_OBJECT_POOL_SIZE")) != 0)
|
||||
{
|
||||
_maxBufferObjectPoolSize = atoi(ptr);
|
||||
}
|
||||
getEnvVar("OSG_BUFFER_OBJECT_POOL_SIZE", _maxBufferObjectPoolSize);
|
||||
|
||||
|
||||
{ // Read implicit buffer attachments combinations for both render and resolve mask
|
||||
@@ -624,143 +583,141 @@ void DisplaySettings::readEnvironmentalVariables()
|
||||
|
||||
for( unsigned int n = 0; n < sizeof( variable ) / sizeof( variable[0] ); n++ )
|
||||
{
|
||||
const char* env = getenv( variable[n] );
|
||||
if ( !env ) continue;
|
||||
std::string str(env);
|
||||
std::string str;
|
||||
if (getEnvVar(variable[n], str))
|
||||
{
|
||||
if(str.find("OFF")!=std::string::npos) *mask[n] = 0;
|
||||
|
||||
if(str.find("OFF")!=std::string::npos) *mask[n] = 0;
|
||||
if(str.find("~DEFAULT")!=std::string::npos) *mask[n] ^= DEFAULT_IMPLICIT_BUFFER_ATTACHMENT;
|
||||
else if(str.find("DEFAULT")!=std::string::npos) *mask[n] |= DEFAULT_IMPLICIT_BUFFER_ATTACHMENT;
|
||||
|
||||
if(str.find("~DEFAULT")!=std::string::npos) *mask[n] ^= DEFAULT_IMPLICIT_BUFFER_ATTACHMENT;
|
||||
else if(str.find("DEFAULT")!=std::string::npos) *mask[n] |= DEFAULT_IMPLICIT_BUFFER_ATTACHMENT;
|
||||
if(str.find("~COLOR")!=std::string::npos) *mask[n] ^= IMPLICIT_COLOR_BUFFER_ATTACHMENT;
|
||||
else if(str.find("COLOR")!=std::string::npos) *mask[n] |= IMPLICIT_COLOR_BUFFER_ATTACHMENT;
|
||||
|
||||
if(str.find("~COLOR")!=std::string::npos) *mask[n] ^= IMPLICIT_COLOR_BUFFER_ATTACHMENT;
|
||||
else if(str.find("COLOR")!=std::string::npos) *mask[n] |= IMPLICIT_COLOR_BUFFER_ATTACHMENT;
|
||||
if(str.find("~DEPTH")!=std::string::npos) *mask[n] ^= IMPLICIT_DEPTH_BUFFER_ATTACHMENT;
|
||||
else if(str.find("DEPTH")!=std::string::npos) *mask[n] |= (int)IMPLICIT_DEPTH_BUFFER_ATTACHMENT;
|
||||
|
||||
if(str.find("~DEPTH")!=std::string::npos) *mask[n] ^= IMPLICIT_DEPTH_BUFFER_ATTACHMENT;
|
||||
else if(str.find("DEPTH")!=std::string::npos) *mask[n] |= (int)IMPLICIT_DEPTH_BUFFER_ATTACHMENT;
|
||||
|
||||
if(str.find("~STENCIL")!=std::string::npos) *mask[n] ^= (int)IMPLICIT_STENCIL_BUFFER_ATTACHMENT;
|
||||
else if(str.find("STENCIL")!=std::string::npos) *mask[n] |= (int)IMPLICIT_STENCIL_BUFFER_ATTACHMENT;
|
||||
if(str.find("~STENCIL")!=std::string::npos) *mask[n] ^= (int)IMPLICIT_STENCIL_BUFFER_ATTACHMENT;
|
||||
else if(str.find("STENCIL")!=std::string::npos) *mask[n] |= (int)IMPLICIT_STENCIL_BUFFER_ATTACHMENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( (ptr = getenv("OSG_GL_VERSION")) != 0 || (ptr = getenv("OSG_GL_CONTEXT_VERSION")) != 0)
|
||||
if (getEnvVar("OSG_GL_VERSION", value) || getEnvVar("OSG_GL_CONTEXT_VERSION", value))
|
||||
{
|
||||
_glContextVersion = ptr;
|
||||
_glContextVersion = value;
|
||||
}
|
||||
|
||||
if( (ptr = getenv("OSG_GL_CONTEXT_FLAGS")) != 0)
|
||||
{
|
||||
_glContextFlags = atoi(ptr);
|
||||
}
|
||||
getEnvVar("OSG_GL_CONTEXT_FLAGS", _glContextFlags);
|
||||
|
||||
if( (ptr = getenv("OSG_GL_CONTEXT_PROFILE_MASK")) != 0)
|
||||
{
|
||||
_glContextProfileMask = atoi(ptr);
|
||||
}
|
||||
getEnvVar("OSG_GL_CONTEXT_PROFILE_MASK", _glContextProfileMask);
|
||||
|
||||
if ((ptr = getenv("OSG_SWAP_METHOD")) != 0)
|
||||
if (getEnvVar("OSG_SWAP_METHOD", value))
|
||||
{
|
||||
if (strcmp(ptr,"DEFAULT")==0)
|
||||
if (value=="DEFAULT")
|
||||
{
|
||||
_swapMethod = SWAP_DEFAULT;
|
||||
}
|
||||
else
|
||||
if (strcmp(ptr,"EXCHANGE")==0)
|
||||
if (value=="EXCHANGE")
|
||||
{
|
||||
_swapMethod = SWAP_EXCHANGE;
|
||||
}
|
||||
else
|
||||
if (strcmp(ptr,"COPY")==0)
|
||||
if (value=="COPY")
|
||||
{
|
||||
_swapMethod = SWAP_COPY;
|
||||
}
|
||||
else
|
||||
if (strcmp(ptr,"UNDEFINED")==0)
|
||||
if (value=="UNDEFINED")
|
||||
{
|
||||
_swapMethod = SWAP_UNDEFINED;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ((ptr = getenv("OSG_SYNC_SWAP_BUFFERS")) != 0)
|
||||
if (getEnvVar("OSG_SYNC_SWAP_BUFFERS", value))
|
||||
{
|
||||
if (strcmp(ptr,"OFF")==0)
|
||||
if (value=="OFF")
|
||||
{
|
||||
_syncSwapBuffers = 0;
|
||||
}
|
||||
else
|
||||
if (strcmp(ptr,"ON")==0)
|
||||
if (value=="ON")
|
||||
{
|
||||
_syncSwapBuffers = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_syncSwapBuffers = atoi(ptr);
|
||||
_syncSwapBuffers = atoi(value.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ((ptr = getenv("OSG_VERTEX_BUFFER_HINT")) != 0)
|
||||
if (getEnvVar("OSG_VERTEX_BUFFER_HINT", value))
|
||||
{
|
||||
if (strcmp(ptr,"VERTEX_BUFFER_OBJECT")==0 || strcmp(ptr,"VBO")==0)
|
||||
if (value=="VERTEX_BUFFER_OBJECT" || value=="VBO")
|
||||
{
|
||||
OSG_NOTICE<<"OSG_VERTEX_BUFFER_HINT set to VERTEX_BUFFER_OBJECT"<<std::endl;
|
||||
OSG_INFO<<"OSG_VERTEX_BUFFER_HINT set to VERTEX_BUFFER_OBJECT"<<std::endl;
|
||||
_vertexBufferHint = VERTEX_BUFFER_OBJECT;
|
||||
}
|
||||
else if (strcmp(ptr,"VERTEX_ARRAY_OBJECT")==0 || strcmp(ptr,"VAO")==0)
|
||||
else if (value=="VERTEX_ARRAY_OBJECT" || value=="VAO")
|
||||
{
|
||||
OSG_NOTICE<<"OSG_VERTEX_BUFFER_HINT set to VERTEX_ARRAY_OBJECT"<<std::endl;
|
||||
OSG_INFO<<"OSG_VERTEX_BUFFER_HINT set to VERTEX_ARRAY_OBJECT"<<std::endl;
|
||||
_vertexBufferHint = VERTEX_ARRAY_OBJECT;
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<"OSG_VERTEX_BUFFER_HINT set to NO_PREFERENCE"<<std::endl;
|
||||
OSG_INFO<<"OSG_VERTEX_BUFFER_HINT set to NO_PREFERENCE"<<std::endl;
|
||||
_vertexBufferHint = NO_PREFERENCE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ((ptr = getenv("OSG_SHADER_HINT")) != 0)
|
||||
if (getEnvVar("OSG_SHADER_HINT", value))
|
||||
{
|
||||
if (strcmp(ptr,"GL2")==0)
|
||||
if (value=="GL2")
|
||||
{
|
||||
_shaderHint = SHADER_GL2;
|
||||
setShaderHint(SHADER_GL2);
|
||||
}
|
||||
else if (strcmp(ptr,"GL3")==0)
|
||||
else if (value=="GL3")
|
||||
{
|
||||
_shaderHint = SHADER_GL3;
|
||||
setShaderHint(SHADER_GL3);
|
||||
}
|
||||
else if (strcmp(ptr,"GLES2")==0)
|
||||
else if (value=="GLES2")
|
||||
{
|
||||
_shaderHint = SHADER_GLES2;
|
||||
setShaderHint(SHADER_GLES2);
|
||||
}
|
||||
else if (strcmp(ptr,"GLES3")==0)
|
||||
else if (value=="GLES3")
|
||||
{
|
||||
_shaderHint = SHADER_GLES3;
|
||||
setShaderHint(SHADER_GLES3);
|
||||
}
|
||||
else if (strcmp(ptr,"NONE")==0)
|
||||
else if (value=="NONE")
|
||||
{
|
||||
_shaderHint = SHADER_NONE;
|
||||
setShaderHint(SHADER_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( (ptr = getenv("OSG_KEYSTONE")) != 0)
|
||||
if (getEnvVar("OSG_TEXT_SHADER_TECHNIQUE", value))
|
||||
{
|
||||
if (strcmp(ptr,"OFF")==0)
|
||||
setTextShaderTechnique(value);
|
||||
}
|
||||
|
||||
if (getEnvVar("OSG_KEYSTONE", value))
|
||||
{
|
||||
if (value=="OFF")
|
||||
{
|
||||
_keystoneHint = false;
|
||||
}
|
||||
else
|
||||
if (strcmp(ptr,"ON")==0)
|
||||
if (value=="ON")
|
||||
{
|
||||
_keystoneHint = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ((ptr = getenv("OSG_KEYSTONE_FILES")) != 0)
|
||||
if (getEnvVar("OSG_KEYSTONE_FILES", value))
|
||||
{
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
char delimitor = ';';
|
||||
@@ -768,7 +725,7 @@ void DisplaySettings::readEnvironmentalVariables()
|
||||
char delimitor = ':';
|
||||
#endif
|
||||
|
||||
std::string paths(ptr);
|
||||
std::string paths(value);
|
||||
if (!paths.empty())
|
||||
{
|
||||
std::string::size_type start = 0;
|
||||
@@ -785,27 +742,28 @@ void DisplaySettings::readEnvironmentalVariables()
|
||||
}
|
||||
}
|
||||
|
||||
if( (ptr = getenv("OSG_MENUBAR_BEHAVIOR")) != 0)
|
||||
if (getEnvVar("OSG_MENUBAR_BEHAVIOR", value))
|
||||
{
|
||||
if (strcmp(ptr,"AUTO_HIDE")==0)
|
||||
if (value=="AUTO_HIDE")
|
||||
{
|
||||
_OSXMenubarBehavior = MENUBAR_AUTO_HIDE;
|
||||
}
|
||||
else
|
||||
if (strcmp(ptr,"FORCE_HIDE")==0)
|
||||
if (value=="FORCE_HIDE")
|
||||
{
|
||||
_OSXMenubarBehavior = MENUBAR_FORCE_HIDE;
|
||||
}
|
||||
else
|
||||
if (strcmp(ptr,"FORCE_SHOW")==0)
|
||||
if (value=="FORCE_SHOW")
|
||||
{
|
||||
_OSXMenubarBehavior = MENUBAR_FORCE_SHOW;
|
||||
}
|
||||
}
|
||||
|
||||
if( (ptr = getenv("OSG_NvOptimusEnablement")) != 0)
|
||||
int enable = 0;
|
||||
if (getEnvVar("OSG_NvOptimusEnablement", enable))
|
||||
{
|
||||
setNvOptimusEnablement(atoi(ptr));
|
||||
setNvOptimusEnablement(enable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1098,3 +1056,84 @@ osg::Matrixd DisplaySettings::computeRightEyeViewImplementation(const osg::Matri
|
||||
0.0,0.0,1.0,0.0,
|
||||
-es,0.0,0.0,1.0);
|
||||
}
|
||||
|
||||
void DisplaySettings::setShaderHint(ShaderHint hint, bool setShaderValues)
|
||||
{
|
||||
_shaderHint = hint;
|
||||
if (setShaderValues)
|
||||
{
|
||||
switch(_shaderHint)
|
||||
{
|
||||
case(SHADER_GLES3) :
|
||||
setValue("OSG_GLSL_VERSION", "#version 300 es");
|
||||
setValue("OSG_PRECISION_FLOAT", "precision highp float;");
|
||||
setValue("OSG_VARYING_IN", "in");
|
||||
setValue("OSG_VARYING_OUT", "out");
|
||||
OSG_NOTICE<<"DisplaySettings::SHADER_GLES3"<<std::endl;
|
||||
break;
|
||||
case(SHADER_GLES2) :
|
||||
setValue("OSG_GLSL_VERSION", "");
|
||||
setValue("OSG_PRECISION_FLOAT", "precision highp float;");
|
||||
setValue("OSG_VARYING_IN", "varying");
|
||||
setValue("OSG_VARYING_OUT", "varying");
|
||||
OSG_NOTICE<<"DisplaySettings::SHADER_GLES2"<<std::endl;
|
||||
break;
|
||||
case(SHADER_GL3) :
|
||||
setValue("OSG_GLSL_VERSION", "#version 330");
|
||||
setValue("OSG_PRECISION_FLOAT", "");
|
||||
setValue("OSG_VARYING_IN", "in");
|
||||
setValue("OSG_VARYING_OUT", "out");
|
||||
OSG_NOTICE<<"DisplaySettings::SHADER_GL3"<<std::endl;
|
||||
break;
|
||||
case(SHADER_GL2) :
|
||||
setValue("OSG_GLSL_VERSION", "");
|
||||
setValue("OSG_PRECISION_FLOAT", "");
|
||||
setValue("OSG_VARYING_IN", "varying");
|
||||
setValue("OSG_VARYING_OUT", "varying");
|
||||
OSG_NOTICE<<"DisplaySettings::SHADER_GL2"<<std::endl;
|
||||
break;
|
||||
case(SHADER_NONE) :
|
||||
setValue("OSG_GLSL_VERSION", "");
|
||||
setValue("OSG_PRECISION_FLOAT", "");
|
||||
setValue("OSG_VARYING_IN", "varying");
|
||||
setValue("OSG_VARYING_OUT", "varying");
|
||||
OSG_INFO<<"DisplaySettings::NONE"<<std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DisplaySettings::setValue(const std::string& name, const std::string& value)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_valueMapMutex);
|
||||
|
||||
_valueMap[name] = value;
|
||||
}
|
||||
|
||||
bool DisplaySettings::getValue(const std::string& name, std::string& value, bool use_env_fallback) const
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_valueMapMutex);
|
||||
|
||||
ValueMap::iterator itr = _valueMap.find(name);
|
||||
if (itr!=_valueMap.end())
|
||||
{
|
||||
value = itr->second;
|
||||
OSG_INFO<<"DisplaySettings::getValue("<<name<<") found existing value = ["<<value<<"]"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!use_env_fallback) return false;
|
||||
|
||||
std::string str;
|
||||
if (getEnvVar(name.c_str(), str))
|
||||
{
|
||||
OSG_INFO<<"DisplaySettings::getValue("<<name<<") found getEnvVar value = ["<<value<<"]"<<std::endl;
|
||||
_valueMap[name] = value = str;
|
||||
return true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,7 +249,8 @@ Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop):
|
||||
_supportsVertexBufferObjects(drawable._supportsVertexBufferObjects),
|
||||
_useVertexBufferObjects(drawable._useVertexBufferObjects),
|
||||
_useVertexArrayObject(drawable._useVertexArrayObject),
|
||||
_drawCallback(drawable._drawCallback)
|
||||
_drawCallback(drawable._drawCallback),
|
||||
_createVertexArrayStateCallback(drawable._createVertexArrayStateCallback)
|
||||
{
|
||||
setStateSet(copyop(drawable._stateset.get()));
|
||||
}
|
||||
@@ -696,8 +697,9 @@ void Drawable::draw(RenderInfo& renderInfo) const
|
||||
|
||||
#endif
|
||||
|
||||
VertexArrayState* Drawable::createVertexArrayState(RenderInfo& renderInfo) const
|
||||
VertexArrayState* Drawable::createVertexArrayStateImplementation(RenderInfo& renderInfo) const
|
||||
{
|
||||
OSG_NOTICE<<"VertexArrayState* Drawable::createVertexArrayStateImplementation(RenderInfo& renderInfo) const "<<this<<std::endl;
|
||||
VertexArrayState* vos = new osg::VertexArrayState(renderInfo.getState());
|
||||
vos->assignAllDispatchers();
|
||||
return vos;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include <osg/Notify>
|
||||
#include <osg/Math>
|
||||
#include <osg/buffered_value>
|
||||
#include <osg/EnvVar>
|
||||
#include <osg/ApplicationUsage>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -65,6 +67,9 @@ static osg::buffered_object<ExtensionSet> s_gluExtensionSetList;
|
||||
static osg::buffered_object<std::string> s_gluRendererList;
|
||||
static osg::buffered_value<int> s_gluInitializedList;
|
||||
|
||||
static ApplicationUsageProxy GLEXtension_e0(ApplicationUsage::ENVIRONMENTAL_VARIABLE, "OSG_GL_EXTENSION_DISABLE <value>", "Use space deliminarted list of GL extensions to disable associated GL extensions");
|
||||
static ApplicationUsageProxy GLEXtension_e1(ApplicationUsage::ENVIRONMENTAL_VARIABLE, "OSG_MAX_TEXTURE_SIZE <value>", "Clamp the maximum GL texture size to specified value.");
|
||||
|
||||
float osg::getGLVersionNumber()
|
||||
{
|
||||
// needs to be extended to do proper things with subversions like 1.5.1, etc.
|
||||
@@ -308,8 +313,7 @@ void osg::setGLExtensionDisableString(const std::string& disableString)
|
||||
|
||||
std::string& osg::getGLExtensionDisableString()
|
||||
{
|
||||
static const char* envVar = getenv("OSG_GL_EXTENSION_DISABLE");
|
||||
static std::string s_GLExtensionDisableString(envVar?envVar:"Nothing defined");
|
||||
static std::string s_GLExtensionDisableString(getEnvVar("OSG_GL_EXTENSION_DISABLE"));
|
||||
|
||||
return s_GLExtensionDisableString;
|
||||
}
|
||||
@@ -464,13 +468,13 @@ GLExtensions::GLExtensions(unsigned int in_contextID):
|
||||
isVertexShaderSupported = validContext && (shadersBuiltIn || osg::isGLExtensionSupported(contextID,"GL_ARB_vertex_shader"));
|
||||
isFragmentShaderSupported = validContext && (shadersBuiltIn || osg::isGLExtensionSupported(contextID,"GL_ARB_fragment_shader"));
|
||||
isLanguage100Supported = validContext && (shadersBuiltIn || osg::isGLExtensionSupported(contextID,"GL_ARB_shading_language_100"));
|
||||
isGeometryShader4Supported = validContext && (osg::isGLExtensionSupported(contextID,"GL_EXT_geometry_shader4") || osg::isGLExtensionSupported(contextID,"GL_OES_geometry_shader"));
|
||||
isGpuShader4Supported = validContext && osg::isGLExtensionSupported(contextID,"GL_EXT_gpu_shader4");
|
||||
areTessellationShadersSupported = validContext && (osg::isGLExtensionSupported(contextID, "GL_ARB_tessellation_shader") || osg::isGLExtensionSupported(contextID,"GL_OES_tessellation_shader"));
|
||||
isUniformBufferObjectSupported = validContext && osg::isGLExtensionSupported(contextID,"GL_ARB_uniform_buffer_object");
|
||||
isGetProgramBinarySupported = validContext && osg::isGLExtensionSupported(contextID,"GL_ARB_get_program_binary");
|
||||
isGpuShaderFp64Supported = validContext && osg::isGLExtensionSupported(contextID,"GL_ARB_gpu_shader_fp64");
|
||||
isShaderAtomicCountersSupported = validContext && osg::isGLExtensionSupported(contextID,"GL_ARB_shader_atomic_counters");
|
||||
isGeometryShader4Supported = validContext && (osg::isGLExtensionSupported(contextID,"GL_EXT_geometry_shader4") || osg::isGLExtensionSupported(contextID,"GL_OES_geometry_shader") || osg::isGLExtensionOrVersionSupported(contextID,"GL_ARB_geometry_shader4", 3.2f));
|
||||
isGpuShader4Supported = validContext && osg::isGLExtensionOrVersionSupported(contextID,"GL_EXT_gpu_shader4", 3.0f);
|
||||
areTessellationShadersSupported = validContext && (osg::isGLExtensionOrVersionSupported(contextID, "GL_ARB_tessellation_shader", 4.0f) || osg::isGLExtensionSupported(contextID,"GL_OES_tessellation_shader"));
|
||||
isUniformBufferObjectSupported = validContext && osg::isGLExtensionOrVersionSupported(contextID,"GL_ARB_uniform_buffer_object", 3.1f);
|
||||
isGetProgramBinarySupported = validContext && osg::isGLExtensionOrVersionSupported(contextID,"GL_ARB_get_program_binary", 4.1f);
|
||||
isGpuShaderFp64Supported = validContext && osg::isGLExtensionOrVersionSupported(contextID,"GL_ARB_gpu_shader_fp64", 4.0f);
|
||||
isShaderAtomicCountersSupported = validContext && osg::isGLExtensionOrVersionSupported(contextID,"GL_ARB_shader_atomic_counters", 4.2f);
|
||||
|
||||
isRectangleSupported = validContext &&
|
||||
(OSG_GL3_FEATURES ||
|
||||
@@ -900,16 +904,10 @@ GLExtensions::GLExtensions(unsigned int in_contextID):
|
||||
maxTextureSize=0;
|
||||
if (validContext) glGetIntegerv(GL_MAX_TEXTURE_SIZE,&maxTextureSize);
|
||||
|
||||
char *ptr;
|
||||
if( (ptr = getenv("OSG_MAX_TEXTURE_SIZE")) != 0)
|
||||
GLint osg_max_size = maxTextureSize;
|
||||
if( (getEnvVar("OSG_MAX_TEXTURE_SIZE", osg_max_size)) && osg_max_size<maxTextureSize)
|
||||
{
|
||||
GLint osg_max_size = atoi(ptr);
|
||||
|
||||
if (osg_max_size<maxTextureSize)
|
||||
{
|
||||
|
||||
maxTextureSize = osg_max_size;
|
||||
}
|
||||
maxTextureSize = osg_max_size;
|
||||
}
|
||||
|
||||
setGLExtensionFuncPtr(glTexStorage2D,"glTexStorage2D","glTexStorage2DARB", validContext);
|
||||
@@ -926,12 +924,16 @@ GLExtensions::GLExtensions(unsigned int in_contextID):
|
||||
isTextureMaxLevelSupported = (glVersion >= 1.2f);
|
||||
|
||||
isTextureStorageEnabled = validContext && ((glVersion >= 4.2f) || isGLExtensionSupported(contextID, "GL_ARB_texture_storage"));
|
||||
if ( (ptr = getenv("OSG_GL_TEXTURE_STORAGE")) != 0 && isTextureStorageEnabled)
|
||||
{
|
||||
if (strcmp(ptr,"OFF")==0 || strcmp(ptr,"DISABLE")==0 ) isTextureStorageEnabled = false;
|
||||
else isTextureStorageEnabled = true;
|
||||
}
|
||||
|
||||
if (isTextureStorageEnabled)
|
||||
{
|
||||
std::string value;
|
||||
if (getEnvVar("OSG_GL_TEXTURE_STORAGE", value))
|
||||
{
|
||||
if (value=="OFF" || value=="DISABLE") isTextureStorageEnabled = false;
|
||||
else isTextureStorageEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Texture3D extensions
|
||||
isTexture3DFast = validContext && (OSG_GL3_FEATURES || isGLExtensionSupported(contextID,"GL_EXT_texture3D"));
|
||||
@@ -946,6 +948,10 @@ GLExtensions::GLExtensions(unsigned int in_contextID):
|
||||
setGLExtensionFuncPtr(glTexSubImage3D, "glTexSubImage3D","glTexSubImage3DEXT", validContext);
|
||||
setGLExtensionFuncPtr(glCompressedTexImage3D, "glCompressedTexImage3D","glCompressedTexImage3DARB", validContext);
|
||||
setGLExtensionFuncPtr(glCompressedTexSubImage3D, "glCompressedTexSubImage3D","glCompressedTexSubImage3DARB", validContext);
|
||||
|
||||
setGLExtensionFuncPtr(glTexImage3DMultisample, "glTexImage3DMultisample", validContext);
|
||||
setGLExtensionFuncPtr(glGetMultisamplefv, "glGetMultisamplefv", validContext);
|
||||
|
||||
setGLExtensionFuncPtr(glCopyTexSubImage3D, "glCopyTexSubImage3D","glCopyTexSubImage3DEXT", validContext);
|
||||
setGLExtensionFuncPtr(glBeginConditionalRender, "glBeginConditionalRender", "glBeginConditionalRenderARB");
|
||||
setGLExtensionFuncPtr(glEndConditionalRender, "glEndConditionalRender", "glEndConditionalRenderARB");
|
||||
|
||||
@@ -570,16 +570,11 @@ void Geometry::setUseVertexBufferObjects(bool flag)
|
||||
DrawElementsList drawElementsList;
|
||||
getDrawElementsList(drawElementsList);
|
||||
|
||||
typedef std::vector<osg::VertexBufferObject*> VertexBufferObjectList;
|
||||
typedef std::vector<osg::ElementBufferObject*> ElementBufferObjectList;
|
||||
|
||||
/*if (_useVertexBufferObjects)*/
|
||||
{
|
||||
if (!arrayList.empty())
|
||||
{
|
||||
|
||||
VertexBufferObjectList vboList;
|
||||
|
||||
osg::ref_ptr<osg::VertexBufferObject> vbo;
|
||||
|
||||
ArrayList::iterator vitr;
|
||||
@@ -604,8 +599,6 @@ void Geometry::setUseVertexBufferObjects(bool flag)
|
||||
|
||||
if (!drawElementsList.empty())
|
||||
{
|
||||
ElementBufferObjectList eboList;
|
||||
|
||||
osg::ref_ptr<osg::ElementBufferObject> ebo;
|
||||
|
||||
DrawElementsList::iterator deitr;
|
||||
@@ -720,7 +713,7 @@ void Geometry::releaseGLObjects(State* state) const
|
||||
|
||||
}
|
||||
|
||||
VertexArrayState* Geometry::createVertexArrayState(RenderInfo& renderInfo) const
|
||||
VertexArrayState* Geometry::createVertexArrayStateImplementation(RenderInfo& renderInfo) const
|
||||
{
|
||||
State& state = *renderInfo.getState();
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <osg/View>
|
||||
#include <osg/GLObjects>
|
||||
#include <osg/ContextData>
|
||||
#include <osg/EnvVar>
|
||||
|
||||
#include <osg/FrameBufferObject>
|
||||
#include <osg/Program>
|
||||
@@ -153,10 +154,10 @@ std::string GraphicsContext::ScreenIdentifier::displayName() const
|
||||
|
||||
void GraphicsContext::ScreenIdentifier::readDISPLAY()
|
||||
{
|
||||
const char* ptr = 0;
|
||||
if ((ptr=getenv("DISPLAY")) != 0)
|
||||
std::string str;
|
||||
if (getEnvVar("DISPLAY", str))
|
||||
{
|
||||
setScreenIdentifier(ptr);
|
||||
setScreenIdentifier(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -241,11 +241,17 @@ Image::Image(const Image& image,const CopyOp& copyop):
|
||||
{
|
||||
unsigned int size = image.getTotalSizeInBytesIncludingMipmaps();
|
||||
setData(new unsigned char [size],USE_NEW_DELETE);
|
||||
unsigned char* dest_ptr = _data;
|
||||
for(DataIterator itr(&image); itr.valid(); ++itr)
|
||||
if (unsigned char* dest_ptr = _data)
|
||||
{
|
||||
memcpy(dest_ptr, itr.data(), itr.size());
|
||||
dest_ptr += itr.size();
|
||||
for(DataIterator itr(&image); itr.valid(); ++itr)
|
||||
{
|
||||
memcpy(dest_ptr, itr.data(), itr.size());
|
||||
dest_ptr += itr.size();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_WARN<<"Warning: Image::Image(const Image&, const CopyOp&) out of memory, no image copy made."<<std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -602,7 +608,36 @@ unsigned int Image::computeNumComponents(GLenum pixelFormat)
|
||||
case(GL_BGRA_INTEGER_EXT): return 4;
|
||||
case(GL_LUMINANCE_INTEGER_EXT): return 1;
|
||||
case(GL_LUMINANCE_ALPHA_INTEGER_EXT): return 2;
|
||||
|
||||
case(GL_SRGB8) : return 3;
|
||||
case(GL_SRGB8_ALPHA8) : return 4;
|
||||
case (GL_COMPRESSED_RGBA_ASTC_4x4_KHR) : return 4;
|
||||
case (GL_COMPRESSED_RGBA_ASTC_5x4_KHR) : return 4;
|
||||
case (GL_COMPRESSED_RGBA_ASTC_5x5_KHR) : return 4;
|
||||
case (GL_COMPRESSED_RGBA_ASTC_6x5_KHR) : return 4;
|
||||
case (GL_COMPRESSED_RGBA_ASTC_6x6_KHR) : return 4;
|
||||
case (GL_COMPRESSED_RGBA_ASTC_8x5_KHR) : return 4;
|
||||
case (GL_COMPRESSED_RGBA_ASTC_8x6_KHR) : return 4;
|
||||
case (GL_COMPRESSED_RGBA_ASTC_8x8_KHR) : return 4;
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x5_KHR) : return 4;
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x6_KHR) : return 4;
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x8_KHR) : return 4;
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x10_KHR) : return 4;
|
||||
case (GL_COMPRESSED_RGBA_ASTC_12x10_KHR) : return 4;
|
||||
case (GL_COMPRESSED_RGBA_ASTC_12x12_KHR) : return 4;
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR) : return 4;
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR) : return 4;
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR) : return 4;
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR) : return 4;
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR) : return 4;
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR) : return 4;
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR) : return 4;
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR) : return 4;
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR) : return 4;
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR) : return 4;
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR) : return 4;
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR) : return 4;
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR) : return 4;
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR) : return 4;
|
||||
default:
|
||||
{
|
||||
OSG_WARN<<"error pixelFormat = "<<std::hex<<pixelFormat<<std::dec<<std::endl;
|
||||
@@ -665,6 +700,51 @@ unsigned int Image::computePixelSizeInBits(GLenum format,GLenum type)
|
||||
return 0;
|
||||
default: break;
|
||||
}
|
||||
switch (format)
|
||||
{//handle GL_KHR_texture_compression_astc_hdr
|
||||
case (GL_COMPRESSED_RGBA_ASTC_4x4_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_5x4_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_5x5_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_6x5_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_6x6_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_8x5_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_8x6_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_8x8_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x5_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x6_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x8_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x10_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_12x10_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_12x12_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR) :
|
||||
{
|
||||
osg::Vec3i footprint = computeBlockFootprint(format);
|
||||
unsigned int pixelsPerBlock = footprint.x() * footprint.y();
|
||||
unsigned int bitsPerBlock = computeBlockSize(format, 0);//16 x 8 = 128
|
||||
unsigned int bitsPerPixel = bitsPerBlock / pixelsPerBlock;
|
||||
if (bitsPerBlock == bitsPerPixel * pixelsPerBlock) {
|
||||
OSG_WARN << "Image::computePixelSizeInBits(format,type) : bits per pixel (" << bitsPerPixel << ") is not an integer for GL_KHR_texture_compression_astc_hdr sizes other than 4x4 and 8x8." << std::endl;
|
||||
return bitsPerPixel;
|
||||
} else {
|
||||
OSG_WARN << "Image::computePixelSizeInBits(format,type) : bits per pixel (" << bitsPerBlock << "/" << pixelsPerBlock << ") is not an integer for GL_KHR_texture_compression_astc_hdr size" << footprint.x() << "x" << footprint.y() << "." << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
|
||||
switch(format)
|
||||
{
|
||||
@@ -725,6 +805,71 @@ unsigned int Image::computePixelSizeInBits(GLenum format,GLenum type)
|
||||
|
||||
}
|
||||
|
||||
osg::Vec3i Image::computeBlockFootprint(GLenum pixelFormat) {
|
||||
switch (pixelFormat)
|
||||
{
|
||||
case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT) :
|
||||
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) :
|
||||
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT) :
|
||||
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) :
|
||||
return osg::Vec3i(4,4,4);//opengl 3d dxt: r value means (max)4 consecutive blocks in r direction packed into a slab.
|
||||
|
||||
case(GL_COMPRESSED_SIGNED_RED_RGTC1_EXT) :
|
||||
case(GL_COMPRESSED_RED_RGTC1_EXT) :
|
||||
case(GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT) :
|
||||
case(GL_COMPRESSED_RED_GREEN_RGTC2_EXT) :
|
||||
case(GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG) :
|
||||
case(GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG) :
|
||||
case(GL_ETC1_RGB8_OES) :
|
||||
case(GL_COMPRESSED_RGB8_ETC2) :
|
||||
case(GL_COMPRESSED_SRGB8_ETC2) :
|
||||
case(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2) :
|
||||
case(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2) :
|
||||
case(GL_COMPRESSED_RGBA8_ETC2_EAC) :
|
||||
case(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC) :
|
||||
case(GL_COMPRESSED_R11_EAC) :
|
||||
case(GL_COMPRESSED_SIGNED_R11_EAC) :
|
||||
case(GL_COMPRESSED_RG11_EAC) :
|
||||
case(GL_COMPRESSED_SIGNED_RG11_EAC) :
|
||||
return osg::Vec3i(4, 4, 1);//not sure about r
|
||||
case(GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG) :
|
||||
case(GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG) :
|
||||
return osg::Vec3i(8, 4, 1);//no 3d texture support in pvrtc at all
|
||||
case (GL_COMPRESSED_RGBA_ASTC_4x4_KHR) : return osg::Vec3i(4, 4, 1);
|
||||
case (GL_COMPRESSED_RGBA_ASTC_5x4_KHR) : return osg::Vec3i(5, 4, 1);
|
||||
case (GL_COMPRESSED_RGBA_ASTC_5x5_KHR) : return osg::Vec3i(5, 5, 1);
|
||||
case (GL_COMPRESSED_RGBA_ASTC_6x5_KHR) : return osg::Vec3i(6, 5, 1);
|
||||
case (GL_COMPRESSED_RGBA_ASTC_6x6_KHR) : return osg::Vec3i(6, 6, 1);
|
||||
case (GL_COMPRESSED_RGBA_ASTC_8x5_KHR) : return osg::Vec3i(8, 5, 1);
|
||||
case (GL_COMPRESSED_RGBA_ASTC_8x6_KHR) : return osg::Vec3i(8, 6, 1);
|
||||
case (GL_COMPRESSED_RGBA_ASTC_8x8_KHR) : return osg::Vec3i(8, 8, 1);
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x5_KHR) : return osg::Vec3i(10, 5, 1);
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x6_KHR) : return osg::Vec3i(10, 6, 1);
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x8_KHR) : return osg::Vec3i(10, 8, 1);
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x10_KHR) : return osg::Vec3i(10, 10, 1);
|
||||
case (GL_COMPRESSED_RGBA_ASTC_12x10_KHR) : return osg::Vec3i(12, 10, 1);
|
||||
case (GL_COMPRESSED_RGBA_ASTC_12x12_KHR) : return osg::Vec3i(12, 12, 1);
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR) : return osg::Vec3i(4, 4, 1);
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR) : return osg::Vec3i(5, 4, 1);
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR) : return osg::Vec3i(5, 5, 1);
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR) : return osg::Vec3i(6, 5, 1);
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR) : return osg::Vec3i(6, 6, 1);
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR) : return osg::Vec3i(8, 5, 1);
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR) : return osg::Vec3i(8, 6, 1);
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR) : return osg::Vec3i(8, 8, 1);
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR) : return osg::Vec3i(10, 5, 1);
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR) : return osg::Vec3i(10, 6, 1);
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR) : return osg::Vec3i(10, 8, 1);
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR) : return osg::Vec3i(10, 10, 1);
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR) : return osg::Vec3i(12, 10, 1);
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR) : return osg::Vec3i(12, 12, 1);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return osg::Vec3i(1,1,1);
|
||||
}
|
||||
//returns the max(size of a 2D block in bytes,packing)
|
||||
unsigned int Image::computeBlockSize(GLenum pixelFormat, GLenum packing)
|
||||
{
|
||||
switch(pixelFormat)
|
||||
@@ -761,6 +906,35 @@ unsigned int Image::computeBlockSize(GLenum pixelFormat, GLenum packing)
|
||||
case(GL_COMPRESSED_RG11_EAC):
|
||||
case(GL_COMPRESSED_SIGNED_RG11_EAC):
|
||||
return osg::maximum(16u,packing); // block size of 16
|
||||
case (GL_COMPRESSED_RGBA_ASTC_4x4_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_5x4_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_5x5_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_6x5_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_6x6_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_8x5_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_8x6_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_8x8_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x5_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x6_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x8_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x10_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_12x10_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_12x12_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR) :
|
||||
return osg::maximum(16u, packing); // block size of 16
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -780,29 +954,18 @@ unsigned int Image::computeImageSizeInBytes(int width,int height, int depth, GLe
|
||||
{
|
||||
if (width<=0 || height<=0 || depth<=0) return 0;
|
||||
|
||||
// Taking advantage of the fact that
|
||||
// DXT formats are defined as 4 successive numbers:
|
||||
// GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
|
||||
// GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
|
||||
// GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
|
||||
// GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
|
||||
if( pixelFormat >= GL_COMPRESSED_RGB_S3TC_DXT1_EXT &&
|
||||
pixelFormat <= GL_COMPRESSED_RGBA_S3TC_DXT5_EXT )
|
||||
{
|
||||
width = (width + 3) & ~3;
|
||||
height = (height + 3) & ~3;
|
||||
}
|
||||
|
||||
// 3dc ATI formats
|
||||
// GL_COMPRESSED_RED_RGTC1_EXT 0x8DBB
|
||||
// GL_COMPRESSED_SIGNED_RED_RGTC1_EXT 0x8DBC
|
||||
// GL_COMPRESSED_RED_GREEN_RGTC2_EXT 0x8DBD
|
||||
// GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT 0x8DBE
|
||||
if( pixelFormat >= GL_COMPRESSED_RED_RGTC1_EXT &&
|
||||
pixelFormat <= GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT )
|
||||
{
|
||||
width = (width + 3) & ~3;
|
||||
height = (height + 3) & ~3;
|
||||
int blockSize = computeBlockSize(pixelFormat, 0);
|
||||
if (blockSize > 0) {
|
||||
osg::Vec3i footprint = computeBlockFootprint(pixelFormat);
|
||||
width = (width + footprint.x() - 1) / footprint.x();
|
||||
height = (height + footprint.y() - 1) / footprint.y();
|
||||
unsigned int size = blockSize * width;
|
||||
size = roudUpToMultiple(size, packing);
|
||||
size *= height;
|
||||
size = roudUpToMultiple(size, slice_packing);
|
||||
size *= depth;
|
||||
size = roudUpToMultiple(size, image_packing);
|
||||
return size;
|
||||
}
|
||||
|
||||
// compute size of one row
|
||||
@@ -821,6 +984,13 @@ unsigned int Image::computeImageSizeInBytes(int width,int height, int depth, GLe
|
||||
return osg::maximum( size, computeBlockSize(pixelFormat, packing) );
|
||||
}
|
||||
|
||||
int Image::roudUpToMultiple(int s, int pack) {
|
||||
if (pack < 2) return s;
|
||||
s += pack - 1;
|
||||
s -= s % pack;
|
||||
return s;
|
||||
}
|
||||
|
||||
int Image::computeNearestPowerOfTwo(int s,float bias)
|
||||
{
|
||||
if ((s & (s-1))!=0)
|
||||
@@ -880,6 +1050,34 @@ bool Image::isCompressed() const
|
||||
case(GL_COMPRESSED_SIGNED_R11_EAC):
|
||||
case(GL_COMPRESSED_RG11_EAC):
|
||||
case(GL_COMPRESSED_SIGNED_RG11_EAC):
|
||||
case (GL_COMPRESSED_RGBA_ASTC_4x4_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_5x4_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_5x5_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_6x5_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_6x6_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_8x5_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_8x6_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_8x8_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x5_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x6_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x8_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_10x10_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_12x10_KHR) :
|
||||
case (GL_COMPRESSED_RGBA_ASTC_12x12_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR) :
|
||||
case (GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR) :
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@@ -1189,7 +1387,7 @@ void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMaps
|
||||
unsigned char* data = new unsigned char[total_size];
|
||||
if (!data)
|
||||
{
|
||||
OSG_WARN<<"Warning: Image::readImageFromCurrentTexture(..) out of memory, now image read."<<std::endl;
|
||||
OSG_WARN<<"Warning: Image::readImageFromCurrentTexture(..) out of memory, no image read."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1256,7 +1454,7 @@ void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMaps
|
||||
unsigned char* data = new unsigned char[total_size];
|
||||
if (!data)
|
||||
{
|
||||
OSG_WARN<<"Warning: Image::readImageFromCurrentTexture(..) out of memory, now image read."<<std::endl;
|
||||
OSG_WARN<<"Warning: Image::readImageFromCurrentTexture(..) out of memory, no image read."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1409,8 +1607,38 @@ void Image::copySubImage(int s_offset, int t_offset, int r_offset, const osg::Im
|
||||
return;
|
||||
}
|
||||
|
||||
void* data_destination = data(s_offset,t_offset,r_offset);
|
||||
|
||||
unsigned char* data_destination = data(s_offset, t_offset, r_offset);
|
||||
if (isCompressed())
|
||||
{
|
||||
osg::Vec3i footprint = computeBlockFootprint(_pixelFormat);
|
||||
if (footprint.x() == 4 && footprint.y() == 4) {
|
||||
if ((source->s() & 0x3) || (source->t() & 0x3) || (s_offset & 0x3) || (t_offset & 0x3))
|
||||
{
|
||||
OSG_WARN << "Error Image::copySubImage() did not succeed : size " << source->s() << "x" << source->t() << " or offset " << s_offset<< "," << t_offset << " not multiple of 4." << std::endl;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if ((source->s() % footprint.x()) || (source->t() % footprint.y()) || (s_offset % footprint.x()) || (t_offset% footprint.y()))
|
||||
{
|
||||
OSG_WARN << "Error Image::copySubImage() did not succeed : size " << source->s() << "x" << source->t() << " or offset " << s_offset << "," << t_offset << " not multiple of footprint " << footprint.x() << "x" << footprint.y() << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
unsigned int rowWidthInBlocks = (_s + footprint.x() - 1) / footprint.x();
|
||||
unsigned int blockSize = computeBlockSize(_pixelFormat, 0);
|
||||
data_destination = _data + blockSize * (rowWidthInBlocks * t_offset + (s_offset / footprint.x()));
|
||||
unsigned int copy_width = (osg::minimum(source->s(), _s - s_offset) + footprint.x() - 1) / footprint.x();
|
||||
unsigned int copy_height = (osg::minimum(source->t(), _t - t_offset) + footprint.y() - 1) / footprint.y();
|
||||
unsigned int dstRowStep = blockSize * rowWidthInBlocks;
|
||||
unsigned int srcRowStep = blockSize * (source->_s + footprint.x() - 1) / footprint.x();
|
||||
const unsigned char* data_source = source->data(0, 0, 0);
|
||||
for (unsigned int row = 0; row < copy_height; row += 1) { //copy blocks in a row, footprint.y() rows at a time
|
||||
memcpy(data_destination, data_source, copy_width * blockSize);
|
||||
data_source += srcRowStep;
|
||||
data_destination += dstRowStep;
|
||||
}
|
||||
return;
|
||||
}
|
||||
PixelStorageModes psm;
|
||||
psm.pack_alignment = _packing;
|
||||
psm.pack_row_length = _rowLength!=0 ? _rowLength : _s;
|
||||
@@ -1719,7 +1947,7 @@ bool Image::isImageTranslucent() const
|
||||
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT):
|
||||
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT):
|
||||
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT):
|
||||
return dxtc_tool::CompressedImageTranslucent(_s, _t, _pixelFormat, _data);
|
||||
return dxtc_tool::isCompressedImageTranslucent(_s, _t, _pixelFormat, _data);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -1919,18 +2147,29 @@ Vec4 _readColor(GLenum pixelFormat, T* data,float scale)
|
||||
|
||||
Vec4 Image::getColor(unsigned int s,unsigned t,unsigned r) const
|
||||
{
|
||||
const unsigned char* ptr = data(s,t,r);
|
||||
|
||||
switch(_dataType)
|
||||
if (isCompressed())
|
||||
{
|
||||
case(GL_BYTE): return _readColor(_pixelFormat, (char*)ptr, 1.0f/128.0f);
|
||||
case(GL_UNSIGNED_BYTE): return _readColor(_pixelFormat, (unsigned char*)ptr, 1.0f/255.0f);
|
||||
case(GL_SHORT): return _readColor(_pixelFormat, (short*)ptr, 1.0f/32768.0f);
|
||||
case(GL_UNSIGNED_SHORT): return _readColor(_pixelFormat, (unsigned short*)ptr, 1.0f/65535.0f);
|
||||
case(GL_INT): return _readColor(_pixelFormat, (int*)ptr, 1.0f/2147483648.0f);
|
||||
case(GL_UNSIGNED_INT): return _readColor(_pixelFormat, (unsigned int*)ptr, 1.0f/4294967295.0f);
|
||||
case(GL_FLOAT): return _readColor(_pixelFormat, (float*)ptr, 1.0f);
|
||||
case(GL_DOUBLE): return _readColor(_pixelFormat, (double*)ptr, 1.0f);
|
||||
if (dxtc_tool::isDXTC(_pixelFormat)) {
|
||||
unsigned char color[4];
|
||||
if (dxtc_tool::CompressedImageGetColor(color, s, t, r, _s, _t, _r, _pixelFormat, _data)) {
|
||||
return Vec4(((float)color[0]) / 255.0f, ((float)color[1]) / 255.0f, ((float)color[2]) / 255.0f, ((float)color[3]) / 255.0f );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const unsigned char* ptr = data(s,t,r);
|
||||
switch(_dataType)
|
||||
{
|
||||
case(GL_BYTE): return _readColor(_pixelFormat, (char*)ptr, 1.0f/128.0f);
|
||||
case(GL_UNSIGNED_BYTE): return _readColor(_pixelFormat, (unsigned char*)ptr, 1.0f/255.0f);
|
||||
case(GL_SHORT): return _readColor(_pixelFormat, (short*)ptr, 1.0f/32768.0f);
|
||||
case(GL_UNSIGNED_SHORT): return _readColor(_pixelFormat, (unsigned short*)ptr, 1.0f/65535.0f);
|
||||
case(GL_INT): return _readColor(_pixelFormat, (int*)ptr, 1.0f/2147483648.0f);
|
||||
case(GL_UNSIGNED_INT): return _readColor(_pixelFormat, (unsigned int*)ptr, 1.0f/4294967295.0f);
|
||||
case(GL_FLOAT): return _readColor(_pixelFormat, (float*)ptr, 1.0f);
|
||||
case(GL_DOUBLE): return _readColor(_pixelFormat, (double*)ptr, 1.0f);
|
||||
}
|
||||
}
|
||||
return Vec4(1.0f,1.0f,1.0f,1.0f);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include <osg/Notify>
|
||||
#include <osg/io_utils>
|
||||
#include "dxtctool.h"
|
||||
|
||||
namespace osg
|
||||
{
|
||||
@@ -716,6 +717,49 @@ OSG_EXPORT osg::Image* createImageWithOrientationConversion(const osg::Image* sr
|
||||
unsigned int pixelSizeInBits = srcImage->getPixelSizeInBits();
|
||||
unsigned int pixelSizeInBytes = pixelSizeInBits/8;
|
||||
unsigned int pixelSizeRemainder = pixelSizeInBits%8;
|
||||
if (dxtc_tool::isDXTC(srcImage->getPixelFormat()))
|
||||
{
|
||||
unsigned int DXTblockSize = 8;
|
||||
if ((srcImage->getPixelFormat() == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT) || (srcImage->getPixelFormat() == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)) DXTblockSize = 16;
|
||||
unsigned int DXTblocksWidht = (srcImage->s() + 3) / 4;//width in 4x4 blocks
|
||||
unsigned int DXTblocksHeight = (srcImage->t() + 3) / 4;//height in 4x4 blocks
|
||||
unsigned int dst_DXTblocksWidht = (width + 3) / 4;//width in 4x4 blocks
|
||||
unsigned int dst_DXTblocksHeight = (height + 3) / 4;//height in 4x4 blocks
|
||||
|
||||
dstImage->allocateImage(width, height, depth, srcImage->getPixelFormat(), srcImage->getDataType());
|
||||
// copy across the pixels from the source image to the destination image.
|
||||
if (depth != 1)
|
||||
{
|
||||
OSG_NOTICE << "Warning: createImageWithOrientationConversion(..) cannot handle dxt-compressed images with depth." << std::endl;
|
||||
return const_cast<osg::Image*>(srcImage);
|
||||
}
|
||||
for (int l = 0; l<depth; l+=4)
|
||||
{
|
||||
for (int r = 0; r<height; r+=4)
|
||||
{
|
||||
osg::Vec3i cp(srcOrigin.x() + columnDelta.x()*r + layerDelta.x()*l,
|
||||
srcOrigin.y() + columnDelta.y()*r + layerDelta.y()*l,
|
||||
srcOrigin.z() + columnDelta.z()*r + layerDelta.z()*l);
|
||||
for (int c = 0; c<width; c+=4)
|
||||
{
|
||||
unsigned int src_blockIndex = (cp.x() >> 2) + DXTblocksWidht * ((cp.y() >> 2) + (cp.z() >> 2) * DXTblocksHeight);
|
||||
const unsigned char *src_block = srcImage->data() + src_blockIndex * DXTblockSize;
|
||||
|
||||
unsigned int dst_blockIndex = (c >> 2) + dst_DXTblocksWidht * ((r >> 2) + (l >> 2) * dst_DXTblocksHeight);
|
||||
unsigned char *dst_block = dstImage->data() + dst_blockIndex * DXTblockSize;
|
||||
|
||||
memcpy((void *)dst_block, (void *)src_block, DXTblockSize);
|
||||
osg::Vec3i srcSubOrigin(cp.x() & 0x7, cp.y() & 0x7, cp.z() & 0x7);
|
||||
dxtc_tool::compressedBlockOrientationConversion(srcImage->getPixelFormat(),src_block, dst_block, srcSubOrigin, rowDelta, columnDelta);
|
||||
|
||||
cp.x() += 4 * rowDelta.x();
|
||||
cp.y() += 4 * rowDelta.y();
|
||||
cp.z() += 4 * rowDelta.z();
|
||||
}
|
||||
}
|
||||
}
|
||||
return dstImage.release();
|
||||
}
|
||||
if (pixelSizeRemainder!=0)
|
||||
{
|
||||
OSG_NOTICE<<"Warning: createImageWithOrientationConversion(..) cannot handle non byte aligned pixel formats."<<std::endl;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
#include <osg/Notify>
|
||||
#include <osg/ApplicationUsage>
|
||||
#include <osg/EnvVar>
|
||||
#include <osg/ref_ptr>
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
@@ -140,9 +141,8 @@ struct NotifySingleton
|
||||
|
||||
_notifyLevel = osg::NOTICE; // Default value
|
||||
|
||||
char* OSGNOTIFYLEVEL=getenv("OSG_NOTIFY_LEVEL");
|
||||
if (!OSGNOTIFYLEVEL) OSGNOTIFYLEVEL=getenv("OSGNOTIFYLEVEL");
|
||||
if(OSGNOTIFYLEVEL)
|
||||
std::string OSGNOTIFYLEVEL;
|
||||
if(getEnvVar("OSG_NOTIFY_LEVEL", OSGNOTIFYLEVEL) || getEnvVar("OSGNOTIFYLEVEL", OSGNOTIFYLEVEL))
|
||||
{
|
||||
|
||||
std::string stringOSGNOTIFYLEVEL(OSGNOTIFYLEVEL);
|
||||
|
||||
@@ -92,8 +92,7 @@ void Program::ProgramBinary::assign(unsigned int size, const unsigned char* data
|
||||
|
||||
Program::Program() :
|
||||
_geometryVerticesOut(1), _geometryInputType(GL_TRIANGLES),
|
||||
_geometryOutputType(GL_TRIANGLE_STRIP),
|
||||
_numGroupsX(0), _numGroupsY(0), _numGroupsZ(0), _feedbackmode(GL_SEPARATE_ATTRIBS)
|
||||
_geometryOutputType(GL_TRIANGLE_STRIP), _feedbackmode(GL_SEPARATE_ATTRIBS)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -133,10 +132,6 @@ Program::Program(const Program& rhs, const osg::CopyOp& copyop):
|
||||
_geometryInputType = rhs._geometryInputType;
|
||||
_geometryOutputType = rhs._geometryOutputType;
|
||||
|
||||
_numGroupsX = rhs._numGroupsX;
|
||||
_numGroupsY = rhs._numGroupsY;
|
||||
_numGroupsZ = rhs._numGroupsZ;
|
||||
|
||||
_feedbackmode=rhs._feedbackmode;
|
||||
_feedbackout=rhs._feedbackout;
|
||||
}
|
||||
@@ -173,15 +168,6 @@ int Program::compare(const osg::StateAttribute& sa) const
|
||||
if( _geometryOutputType < rhs._geometryOutputType ) return -1;
|
||||
if( rhs._geometryOutputType < _geometryOutputType ) return 1;
|
||||
|
||||
if( _numGroupsX < rhs._numGroupsX ) return -1;
|
||||
if( rhs._numGroupsX < _numGroupsX ) return 1;
|
||||
|
||||
if( _numGroupsY < rhs._numGroupsY ) return -1;
|
||||
if( rhs._numGroupsY < _numGroupsY ) return 1;
|
||||
|
||||
if( _numGroupsZ < rhs._numGroupsZ ) return -1;
|
||||
if( rhs._numGroupsZ < _numGroupsZ ) return 1;
|
||||
|
||||
if(_feedbackout<rhs._feedbackout) return -1;
|
||||
if(_feedbackmode<rhs._feedbackmode) return -1;
|
||||
|
||||
@@ -386,20 +372,6 @@ GLint Program::getParameter( GLenum pname ) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Program::setComputeGroups( GLint numGroupsX, GLint numGroupsY, GLint numGroupsZ )
|
||||
{
|
||||
_numGroupsX = numGroupsX;
|
||||
_numGroupsY = numGroupsY;
|
||||
_numGroupsZ = numGroupsZ;
|
||||
}
|
||||
|
||||
void Program::getComputeGroups( GLint& numGroupsX, GLint& numGroupsY, GLint& numGroupsZ ) const
|
||||
{
|
||||
numGroupsX = _numGroupsX;
|
||||
numGroupsY = _numGroupsY;
|
||||
numGroupsZ = _numGroupsZ;
|
||||
}
|
||||
|
||||
void Program::addBindAttribLocation( const std::string& name, GLuint index )
|
||||
{
|
||||
_attribBindingList[name] = index;
|
||||
@@ -516,7 +488,6 @@ void Program::apply( osg::State& state ) const
|
||||
{
|
||||
// for shader debugging: to minimize performance impact,
|
||||
// optionally validate based on notify level.
|
||||
// TODO: enable this using notify level, or perhaps its own getenv()?
|
||||
#ifndef __APPLE__
|
||||
if( osg::isNotifyEnabled(osg::INFO) )
|
||||
pcp->validateProgram();
|
||||
@@ -1109,8 +1080,4 @@ Program::ProgramBinary* Program::PerContextProgram::compileProgramBinary(osg::St
|
||||
void Program::PerContextProgram::useProgram() const
|
||||
{
|
||||
_extensions->glUseProgram( _glProgramHandle );
|
||||
if ( _program->_numGroupsX>0 && _program->_numGroupsY>0 && _program->_numGroupsZ>0 )
|
||||
{
|
||||
_extensions->glDispatchCompute( _program->_numGroupsX, _program->_numGroupsY, _program->_numGroupsZ );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +89,19 @@ struct NoneOf
|
||||
const char* _str;
|
||||
};
|
||||
|
||||
// Replaces all occurrences of "from" with the contents of "to"
|
||||
// It does only one pass, i.e. new matches created in a position before the current match are not replaced
|
||||
void replaceAll(std::string& str, const std::string& from, const std::string& to)
|
||||
{
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = str.find(from, pos)) != std::string::npos)
|
||||
{
|
||||
str.replace(pos, from.length(), to);
|
||||
|
||||
pos += to.length();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using namespace osg;
|
||||
@@ -301,7 +314,7 @@ void Shader::setShaderSource( const std::string& sourceText )
|
||||
dirtyShader();
|
||||
}
|
||||
|
||||
|
||||
#ifdef OSG_USE_DEPRECATED_API
|
||||
Shader* Shader::readShaderFile( Type type, const std::string& fileName )
|
||||
{
|
||||
ref_ptr<Shader> shader = new Shader(type);
|
||||
@@ -335,7 +348,7 @@ bool Shader::loadShaderSourceFromFile( const std::string& fileName )
|
||||
delete [] text;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
const char* Shader::getTypename() const
|
||||
{
|
||||
@@ -618,30 +631,32 @@ void Shader::PerContextShader::compileShader(osg::State& state)
|
||||
#endif
|
||||
|
||||
std::string source = _shader->getShaderSource();
|
||||
if (_shader->getType()==osg::Shader::VERTEX && (state.getUseVertexAttributeAliasing() || state.getUseModelViewAndProjectionUniforms()))
|
||||
// if (_shader->getType()==osg::Shader::VERTEX && (state.getUseVertexAttributeAliasing() || state.getUseModelViewAndProjectionUniforms()))
|
||||
{
|
||||
state.convertVertexShaderSourceToOsgBuiltIns(source);
|
||||
}
|
||||
|
||||
|
||||
if (osg::getNotifyLevel()>=osg::INFO)
|
||||
{
|
||||
std::string sourceWithLineNumbers = insertLineNumbers(source);
|
||||
OSG_INFO << "\nCompiling " << _shader->getTypename()
|
||||
<< " source:\n" << sourceWithLineNumbers << std::endl;
|
||||
}
|
||||
|
||||
GLint compiled = GL_FALSE;
|
||||
|
||||
// OSG_NOTICE<<"Compiling PerContextShader "<<this<<" ShaderDefine="<<getDefineString()<<std::endl;
|
||||
// OSG_NOTICE<<"Compiling PerContextShader "<<this<<" DefineString="<<getDefineString()<<std::endl;
|
||||
|
||||
if (_defineStr.empty())
|
||||
{
|
||||
const GLchar* sourceText = reinterpret_cast<const GLchar*>(source.c_str());
|
||||
_extensions->glShaderSource( _glShaderHandle, 1, &sourceText, NULL );
|
||||
|
||||
if (osg::getNotifyLevel()>=osg::INFO)
|
||||
{
|
||||
std::string sourceWithLineNumbers = insertLineNumbers(source);
|
||||
OSG_INFO << "\nCompiling A :" << _shader->getTypename()
|
||||
<< " source:\n" << sourceWithLineNumbers << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Convert all windows line endings to \n
|
||||
replaceAll(source, "\r\n", " \n");
|
||||
|
||||
std::string versionLine;
|
||||
unsigned int lineNum = 0;
|
||||
@@ -675,21 +690,40 @@ void Shader::PerContextShader::compileShader(osg::State& state)
|
||||
|
||||
if (!versionLine.empty())
|
||||
{
|
||||
// OSG_NOTICE<<"Shader::PerContextShader::compileShader() : Found #version, lineNum = "<<lineNum<<" ["<<versionLine<<"] new source = ["<<source<<"]"<<std::endl;
|
||||
const GLchar* sourceText[3];
|
||||
//OSG_NOTICE<<"glShaderSource() ["<<versionLine<<"] "<<std::endl<<"["<<_defineStr<<"], ["<<sourceText<<"]"<<std::endl;
|
||||
sourceText[0] = reinterpret_cast<const GLchar*>(versionLine.c_str());
|
||||
sourceText[1] = reinterpret_cast<const GLchar*>(_defineStr.c_str());
|
||||
sourceText[2] = reinterpret_cast<const GLchar*>(source.c_str());
|
||||
_extensions->glShaderSource( _glShaderHandle, 3, sourceText, NULL );
|
||||
|
||||
if (osg::getNotifyLevel()>=osg::INFO)
|
||||
{
|
||||
std::string sourceWithLineNumbers = insertLineNumbers(versionLine+_defineStr+source);
|
||||
OSG_INFO << "\nCompiling B: " << _shader->getTypename()
|
||||
<< " source:\n" << sourceWithLineNumbers << std::endl;
|
||||
}
|
||||
|
||||
// OSG_NOTICE<<" Version Line : ["<<std::endl<<versionLine<<"]"<<std::endl;
|
||||
// OSG_NOTICE<<" DefineStr : ["<<std::endl<<_defineStr<<"]"<<std::endl;
|
||||
// OSG_NOTICE<<" Source : ["<<std::endl<<source<<"]"<<std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
const GLchar* sourceText[2];
|
||||
//OSG_NOTICE<<"glShaderSource() ["<<_defineStr<<"], ["<<sourceText<<"]"<<std::endl;
|
||||
sourceText[0] = reinterpret_cast<const GLchar*>(_defineStr.c_str());
|
||||
sourceText[1] = reinterpret_cast<const GLchar*>(source.c_str());
|
||||
_extensions->glShaderSource( _glShaderHandle, 2, sourceText, NULL );
|
||||
|
||||
|
||||
if (osg::getNotifyLevel()>=osg::INFO)
|
||||
{
|
||||
std::string sourceWithLineNumbers = insertLineNumbers(_defineStr+source);
|
||||
OSG_INFO << "\nCompiling C: " << _shader->getTypename()
|
||||
<< " source:\n" << sourceWithLineNumbers << std::endl;
|
||||
}
|
||||
|
||||
// OSG_NOTICE<<" DefineStr : ["<<std::endl<<_defineStr<<"]"<<std::endl;
|
||||
// OSG_NOTICE<<" Source : ["<<std::endl<<source<<"]"<<std::endl;
|
||||
}
|
||||
}
|
||||
_extensions->glCompileShader( _glShaderHandle );
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <osg/Drawable>
|
||||
#include <osg/ApplicationUsage>
|
||||
#include <osg/ContextData>
|
||||
#include <osg/EnvVar>
|
||||
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
@@ -75,14 +76,17 @@ State::State():
|
||||
|
||||
_checkGLErrors = ONCE_PER_FRAME;
|
||||
|
||||
const char* str = getenv("OSG_GL_ERROR_CHECKING");
|
||||
if (str && (strcmp(str,"ONCE_PER_ATTRIBUTE")==0 || strcmp(str,"ON")==0 || strcmp(str,"on")==0))
|
||||
std::string str;
|
||||
if (getEnvVar("OSG_GL_ERROR_CHECKING", str))
|
||||
{
|
||||
_checkGLErrors = ONCE_PER_ATTRIBUTE;
|
||||
}
|
||||
else if(str && (strcmp(str, "OFF") == 0 || strcmp(str, "off") == 0))
|
||||
{
|
||||
_checkGLErrors = NEVER_CHECK_GL_ERRORS;
|
||||
if (str=="ONCE_PER_ATTRIBUTE" || str=="ON" || str=="on")
|
||||
{
|
||||
_checkGLErrors = ONCE_PER_ATTRIBUTE;
|
||||
}
|
||||
else if (str=="OFF" || str=="off")
|
||||
{
|
||||
_checkGLErrors = NEVER_CHECK_GL_ERRORS;
|
||||
}
|
||||
}
|
||||
|
||||
_currentActiveTextureUnit=0;
|
||||
@@ -198,8 +202,8 @@ void State::initializeExtensionProcs()
|
||||
_forceVertexArrayObject = true;
|
||||
}
|
||||
|
||||
OSG_NOTICE<<"_forceVertexArrayObject = "<<_forceVertexArrayObject<<std::endl;
|
||||
OSG_NOTICE<<"_forceVertexBufferObject = "<<_forceVertexBufferObject<<std::endl;
|
||||
OSG_INFO<<"osg::State::initializeExtensionProcs() _forceVertexArrayObject = "<<_forceVertexArrayObject<<std::endl;
|
||||
OSG_INFO<<" _forceVertexBufferObject = "<<_forceVertexBufferObject<<std::endl;
|
||||
|
||||
|
||||
// Set up up global VertexArrayState object
|
||||
@@ -1216,13 +1220,73 @@ namespace State_Utils
|
||||
source.insert(declPos, qualifier + declarationPrefix + newStr + std::string(";\n"));
|
||||
}
|
||||
}
|
||||
|
||||
void replaceVar(const osg::State& state, std::string& str, std::string::size_type start_pos, std::string::size_type num_chars)
|
||||
{
|
||||
std::string var_str(str.substr(start_pos+1, num_chars-1));
|
||||
std::string value;
|
||||
if (state.getActiveDisplaySettings()->getValue(var_str, value))
|
||||
{
|
||||
str.replace(start_pos, num_chars, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
str.erase(start_pos, num_chars);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void substitudeEnvVars(const osg::State& state, std::string& str)
|
||||
{
|
||||
std::string::size_type pos = 0;
|
||||
while (pos<str.size() && ((pos=str.find_first_of("$'\"", pos)) != std::string::npos))
|
||||
{
|
||||
if (pos==str.size())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (str[pos]=='"' || str[pos]=='\'')
|
||||
{
|
||||
std::string::size_type start_quote = pos;
|
||||
++pos; // skip over first quote
|
||||
pos = str.find(str[start_quote], pos);
|
||||
|
||||
if (pos!=std::string::npos)
|
||||
{
|
||||
++pos; // skip over second quote
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string::size_type start_var = pos;
|
||||
++pos;
|
||||
pos = str.find_first_not_of("ABCDEFGHIJKLMNOPQRTSUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_", pos);
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
|
||||
replaceVar(state, str, start_var, pos-start_var);
|
||||
pos = start_var;
|
||||
}
|
||||
else
|
||||
{
|
||||
replaceVar(state, str, start_var, str.size()-start_var);
|
||||
pos = start_var;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool State::convertVertexShaderSourceToOsgBuiltIns(std::string& source) const
|
||||
{
|
||||
OSG_INFO<<"State::convertShaderSourceToOsgBuiltIns()"<<std::endl;
|
||||
OSG_DEBUG<<"State::convertShaderSourceToOsgBuiltIns()"<<std::endl;
|
||||
|
||||
OSG_DEBUG<<"++Before Converted source "<<std::endl<<source<<std::endl<<"++++++++"<<std::endl;
|
||||
|
||||
|
||||
State_Utils::substitudeEnvVars(*this, source);
|
||||
|
||||
OSG_INFO<<"++Before Converted source "<<std::endl<<source<<std::endl<<"++++++++"<<std::endl;
|
||||
|
||||
std::string attributeQualifier("attribute ");
|
||||
|
||||
@@ -1279,7 +1343,7 @@ bool State::convertVertexShaderSourceToOsgBuiltIns(std::string& source) const
|
||||
}
|
||||
}
|
||||
|
||||
OSG_INFO<<"-------- Converted source "<<std::endl<<source<<std::endl<<"----------------"<<std::endl;
|
||||
OSG_DEBUG<<"-------- Converted source "<<std::endl<<source<<std::endl<<"----------------"<<std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2286,7 +2286,17 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima
|
||||
|
||||
if(useTexStorrage)
|
||||
{
|
||||
extensions->glTexStorage2D(target, numMipmapLevels, sizedInternalFormat, width, height);
|
||||
if (getTextureTarget()==GL_TEXTURE_CUBE_MAP)
|
||||
{
|
||||
if (target==GL_TEXTURE_CUBE_MAP_POSITIVE_X)
|
||||
{
|
||||
extensions->glTexStorage2D(GL_TEXTURE_CUBE_MAP, numMipmapLevels, sizedInternalFormat, width, height);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
extensions->glTexStorage2D(target, numMipmapLevels, sizedInternalFormat, width, height);
|
||||
}
|
||||
|
||||
if( !compressed_image )
|
||||
{
|
||||
|
||||
@@ -168,10 +168,10 @@ void Texture1D::apply(State& state) const
|
||||
}
|
||||
else if (_image.valid() && getModifiedCount(contextID) != _image->getModifiedCount())
|
||||
{
|
||||
applyTexImage1D(GL_TEXTURE_1D,_image.get(),state, _textureWidth, _numMipmapLevels);
|
||||
|
||||
// update the modified count to show that it is up to date.
|
||||
getModifiedCount(contextID) = _image->getModifiedCount();
|
||||
|
||||
applyTexImage1D(GL_TEXTURE_1D,_image.get(),state, _textureWidth, _numMipmapLevels);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -206,13 +206,13 @@ void Texture1D::apply(State& state) const
|
||||
|
||||
applyTexParameters(GL_TEXTURE_1D,state);
|
||||
|
||||
// update the modified count to show that it is upto date.
|
||||
getModifiedCount(contextID) = _image->getModifiedCount();
|
||||
|
||||
applyTexImage1D(GL_TEXTURE_1D,_image.get(),state, _textureWidth, _numMipmapLevels);
|
||||
|
||||
textureObject->setAllocated(_numMipmapLevels,_internalFormat,_textureWidth,1,1,0);
|
||||
|
||||
// update the modified count to show that it is up to date.
|
||||
getModifiedCount(contextID) = _image->getModifiedCount();
|
||||
|
||||
_textureObjectBuffer[contextID] = textureObject;
|
||||
|
||||
// unref image data?
|
||||
|
||||
@@ -202,12 +202,11 @@ void Texture2D::apply(State& state) const
|
||||
}
|
||||
else if (_image.valid() && getModifiedCount(contextID) != _image->getModifiedCount())
|
||||
{
|
||||
applyTexImage2D_subload(state,GL_TEXTURE_2D,_image.get(),
|
||||
_textureWidth, _textureHeight, _internalFormat, _numMipmapLevels);
|
||||
|
||||
// update the modified tag to show that it is up to date.
|
||||
getModifiedCount(contextID) = _image->getModifiedCount();
|
||||
|
||||
applyTexImage2D_subload(state,GL_TEXTURE_2D,_image.get(),
|
||||
_textureWidth, _textureHeight, _internalFormat, _numMipmapLevels);
|
||||
}
|
||||
else if (_readPBuffer.valid())
|
||||
{
|
||||
@@ -224,6 +223,8 @@ void Texture2D::apply(State& state) const
|
||||
|
||||
applyTexParameters(GL_TEXTURE_2D,state);
|
||||
|
||||
if (_image.valid()) getModifiedCount(contextID) = _image->getModifiedCount();
|
||||
|
||||
_subloadCallback->load(*this,state);
|
||||
|
||||
textureObject->setAllocated(_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,_borderWidth);
|
||||
@@ -235,7 +236,6 @@ void Texture2D::apply(State& state) const
|
||||
//glBindTexture( GL_TEXTURE_2D, handle );
|
||||
|
||||
// update the modified tag to show that it is up to date.
|
||||
if (_image.valid()) getModifiedCount(contextID) = _image->getModifiedCount();
|
||||
}
|
||||
else if (_image.valid() && _image->data())
|
||||
{
|
||||
@@ -255,6 +255,9 @@ void Texture2D::apply(State& state) const
|
||||
|
||||
applyTexParameters(GL_TEXTURE_2D,state);
|
||||
|
||||
// update the modified tag to show that it is up to date.
|
||||
getModifiedCount(contextID) = image->getModifiedCount();
|
||||
|
||||
if (textureObject->isAllocated() && image->supportsTextureSubloading())
|
||||
{
|
||||
//OSG_NOTICE<<"Reusing texture object"<<std::endl;
|
||||
@@ -270,9 +273,6 @@ void Texture2D::apply(State& state) const
|
||||
textureObject->setAllocated(true);
|
||||
}
|
||||
|
||||
// update the modified tag to show that it is up to date.
|
||||
getModifiedCount(contextID) = image->getModifiedCount();
|
||||
|
||||
// unref image data?
|
||||
if (isSafeToUnrefImageData(state) && image->getDataVariance()==STATIC)
|
||||
{
|
||||
|
||||
@@ -297,8 +297,8 @@ void Texture2DArray::apply(State& state) const
|
||||
{
|
||||
if (getModifiedCount(n,contextID) != image->getModifiedCount())
|
||||
{
|
||||
applyTexImage2DArray_subload(state, image, n, _textureWidth, _textureHeight, image->r(), _internalFormat, _numMipmapLevels);
|
||||
getModifiedCount(n,contextID) = image->getModifiedCount();
|
||||
applyTexImage2DArray_subload(state, image, n, _textureWidth, _textureHeight, image->r(), _internalFormat, _numMipmapLevels);
|
||||
}
|
||||
n += image->r();
|
||||
}
|
||||
@@ -380,8 +380,8 @@ void Texture2DArray::apply(State& state) const
|
||||
{
|
||||
if (getModifiedCount(n,contextID) != image->getModifiedCount())
|
||||
{
|
||||
applyTexImage2DArray_subload(state, image, n, _textureWidth, _textureHeight, image->r(), _internalFormat, _numMipmapLevels);
|
||||
getModifiedCount(n,contextID) = image->getModifiedCount();
|
||||
applyTexImage2DArray_subload(state, image, n, _textureWidth, _textureHeight, image->r(), _internalFormat, _numMipmapLevels);
|
||||
}
|
||||
n += image->r();
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user