├── CMakeLists.txt ├── CMakeModules ├── FindOSG.cmake ├── ModuleInstall.cmake ├── OsgDetermineCompiler.cmake ├── OsgPPUCPack.cmake ├── OsgPPUCPackConfig.cmake.in ├── OsgPPUMacroUtils.cmake ├── cmake_uninstall.cmake.in └── cuda │ ├── CudaDependency.cmake │ ├── FindCuda.cmake │ ├── empty.depend.in │ ├── make2cmake.cmake │ └── parse_cubin.cmake ├── CONTRIBUTORS.txt ├── ChangeLog ├── Data ├── CMakeLists.txt ├── Images │ ├── CMakeLists.txt │ ├── lenna.rgb │ ├── lenna_noise.rgb │ ├── lz.rgb │ ├── reflect.rgb │ ├── skymap.jpg │ ├── tank.rgb │ └── video.avi ├── bypass.ppu ├── cessnafire.osg ├── cow.osg ├── cuda.ppu ├── dof.ppu ├── glsl │ ├── CMakeLists.txt │ ├── brightpass_fp.glsl │ ├── bypass_fp.glsl │ ├── depth_of_field_fp.glsl │ ├── gauss_convolution_1Dx_fp.glsl │ ├── gauss_convolution_1Dy_fp.glsl │ ├── gauss_convolution_vp.glsl │ ├── luminance_adapted_fp.glsl │ ├── luminance_fp.glsl │ ├── luminance_mipmap_fp.glsl │ ├── ssao_fp.glsl │ ├── ssao_renderscene_fp.glsl │ ├── ssao_renderscene_vp.glsl │ ├── ssao_vp.glsl │ └── tonemap_hdr_fp.glsl ├── hdr.ppu ├── motionblur.ppu └── temple.ive ├── LICENSE.txt ├── README.txt ├── doc ├── Makefile ├── config.doxy ├── createChangelog.sh ├── footer.html └── scripts │ └── svn2cl.xsl ├── include └── osgPPU │ ├── BarrierNode.h │ ├── Camera.h │ ├── ColorAttribute.h │ ├── Export.h │ ├── Processor.h │ ├── ShaderAttribute.h │ ├── Unit.h │ ├── UnitBypass.h │ ├── UnitCamera.h │ ├── UnitCameraAttachmentBypass.h │ ├── UnitDepthbufferBypass.h │ ├── UnitInHistoryOut.h │ ├── UnitInMipmapOut.h │ ├── UnitInOut.h │ ├── UnitInOutModule.h │ ├── UnitInOutRepeat.h │ ├── UnitInResampleOut.h │ ├── UnitMipmapInMipmapOut.h │ ├── UnitOut.h │ ├── UnitOutCapture.h │ ├── UnitText.h │ ├── UnitTexture.h │ ├── Utility.h │ └── Visitor.h └── src ├── CMakeLists.txt ├── example ├── CMakeLists.txt ├── blurScene │ ├── CMakeLists.txt │ └── blurScene.cpp ├── cubemap │ ├── CMakeLists.txt │ └── cubemap.cpp ├── cuda │ ├── BlurKernelWrapper.h │ ├── CMakeLists.txt │ ├── Export.h │ ├── ProcessingModule.cpp │ ├── cuda.cpp │ ├── cutil.h │ ├── kernel.cu │ └── osgteapot.h ├── diffusion │ ├── CMakeLists.txt │ ├── diffusion.cpp │ ├── osgteapot.h │ └── simple.h ├── dof │ ├── CMakeLists.txt │ ├── dofppu.cpp │ ├── dofppu.h │ └── osgteapot.h ├── glow │ ├── CMakeLists.txt │ └── glow.cpp ├── hdr │ ├── CMakeLists.txt │ ├── hdrppu.h │ ├── osgppu.cpp │ └── osgteapot.h ├── motionblur │ ├── CMakeLists.txt │ ├── osgteapot.h │ └── view.cpp ├── ssao │ ├── CMakeLists.txt │ ├── osgteapot.h │ ├── simple.h │ └── ssao.cpp ├── texture3D │ ├── CMakeLists.txt │ └── texture3D.cpp ├── video │ ├── CMakeLists.txt │ └── video.cpp └── viewer │ ├── CMakeLists.txt │ ├── osgteapot.h │ └── view.cpp ├── osgPPU ├── CMakeLists.txt ├── Camera.cpp ├── ColorAttribute.cpp ├── Config.in ├── Processor.cpp ├── ShaderAttribute.cpp ├── Unit.cpp ├── UnitBypass.cpp ├── UnitCamera.cpp ├── UnitCameraAttachmentBypass.cpp ├── UnitDepthbufferBypass.cpp ├── UnitInHistoryOut.cpp ├── UnitInMipmapOut.cpp ├── UnitInOut.cpp ├── UnitInOutModule.cpp ├── UnitInOutRepeat.cpp ├── UnitInResampleOut.cpp ├── UnitMipmapInMipmapOut.cpp ├── UnitOut.cpp ├── UnitOutCapture.cpp ├── UnitText.cpp ├── UnitTexture.cpp ├── Utility.cpp └── Visitor.cpp └── osgPlugins ├── CMakeLists.txt └── osgPPU ├── Base.cpp ├── Base.h ├── CMakeLists.txt ├── IO_Unit.cpp └── ReaderWriterPPU.cpp /CMakeModules/FindOSG.cmake: -------------------------------------------------------------------------------- 1 | # This module defines 2 | 3 | # OSG_LIBRARY 4 | # OSG_FOUND, if false, do not try to link to osg 5 | # OSG_INCLUDE_DIRS, where to find the headers 6 | # OSG_INCLUDE_DIR, where to find the source headers 7 | # OSG_GEN_INCLUDE_DIR, where to find the generated headers 8 | 9 | # to use this module, set variables to point to the osg build 10 | # directory, and source directory, respectively 11 | # OSGDIR or OSG_SOURCE_DIR: osg source directory, typically OpenSceneGraph 12 | # OSG_DIR or OSG_BUILD_DIR: osg build directory, place in which you've 13 | # built osg via cmake 14 | 15 | # Header files are presumed to be included like 16 | # #include 17 | # #include 18 | 19 | ###### headers ###### 20 | 21 | SET( CMAKE_DEBUG_POSTFIX d ) 22 | 23 | MACRO( FIND_OSG_INCLUDE THIS_OSG_INCLUDE_DIR THIS_OSG_INCLUDE_FILE ) 24 | 25 | # configure matched pair of include / library search paths 26 | SET( OSG_SEARCH_PATHS 27 | $ENV{OSG_SOURCE_DIR} 28 | $ENV{OSG_BUILD_DIR} 29 | ${OSGDIR} 30 | $ENV{OSGDIR} 31 | ${OSG_DIR} 32 | $ENV{OSG_DIR} 33 | ${OSG_ROOT} 34 | $ENV{OSG_ROOT} 35 | ${OSG_ROOT_DEBUG} 36 | $ENV{OSG_ROOT_DEBUG} 37 | ${CMAKE_INSTALL_PREFIX} 38 | ${CMAKE_PREFIX_PATH} 39 | /usr/local 40 | /usr/local/lib64 41 | /usr 42 | /sw # Fink 43 | /opt/local # DarwinPorts 44 | /opt/csw # Blastwave 45 | /opt 46 | /usr/freeware 47 | [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/ 48 | ~/Library/Frameworks 49 | /Library/Frameworks 50 | "C:\\Program Files\\OpenSceneGraph" 51 | "C:\\Program Files (x86)\\OpenSceneGraph" 52 | ) 53 | 54 | FIND_PATH( ${THIS_OSG_INCLUDE_DIR} ${THIS_OSG_INCLUDE_FILE} 55 | PATHS ${OSG_SEARCH_PATHS} 56 | PATH_SUFFIXES include build/include Build/include 57 | ) 58 | 59 | ENDMACRO(FIND_OSG_INCLUDE THIS_OSG_INCLUDE_DIR THIS_OSG_INCLUDE_FILE) 60 | 61 | #FIND_OSG_INCLUDE( OSG_GEN_INCLUDE_DIR osg/Config ) 62 | FIND_OSG_INCLUDE( OSG_INCLUDE_DIR osg/Node ) 63 | 64 | ###### libraries ###### 65 | 66 | MACRO(FIND_OSG_LIBRARY MYLIBRARY MYLIBRARYNAME) 67 | 68 | FIND_LIBRARY(${MYLIBRARY} 69 | NAMES ${MYLIBRARYNAME} 70 | PATHS ${OSG_SEARCH_PATHS} 71 | PATH_SUFFIXES lib build/lib Build/lib 72 | ) 73 | 74 | ENDMACRO(FIND_OSG_LIBRARY MYLIBRARY MYLIBRARYNAME) 75 | 76 | SET( TMP_LIBRARY_LIST 77 | OpenThreads osg osgGA osgUtil osgDB osgText osgViewer ) 78 | 79 | FOREACH(LIBRARY ${TMP_LIBRARY_LIST}) 80 | STRING( TOUPPER ${LIBRARY} UPPPERLIBRARY ) 81 | FIND_OSG_LIBRARY( ${UPPPERLIBRARY}_LIBRARY_RELEASE ${LIBRARY} ) 82 | FIND_OSG_LIBRARY( ${UPPPERLIBRARY}_LIBRARY_DEBUG ${LIBRARY}${CMAKE_DEBUG_POSTFIX} ) 83 | LIST( APPEND OSG_LIBRARIES debug ${${UPPPERLIBRARY}_LIBRARY_DEBUG} optimized ${${UPPPERLIBRARY}_LIBRARY_RELEASE} ) 84 | ENDFOREACH(LIBRARY ${TMP_LIBRARY_LIST}) 85 | 86 | SET( OSG_FOUND "NO" ) 87 | #IF(OSG_LIBRARY_RELEASE OR OSG_LIBRARY_DEBUG AND OSG_INCLUDE_DIR AND OSG_GEN_INCLUDE_DIR) 88 | # SET( OSG_FOUND "YES" ) 89 | # SET( OSG_INCLUDE_DIRS ${OSG_INCLUDE_DIR} ${OSG_GEN_INCLUDE_DIR} ) 90 | # GET_FILENAME_COMPONENT( OSG_LIBRARY_DIR_RELEASE ${OSG_LIBRARY_RELEASE} PATH ) 91 | # GET_FILENAME_COMPONENT( OSG_LIBRARY_DIR_DEBUG ${OSG_LIBRARY_DEBUG} PATH ) 92 | # SET( OSG_LIBRARY_DIRS ${OSG_LIBRARY_DIR_RELEASE} ${OSG_LIBRARY_DIR_DEBUG} ) 93 | #ENDIF(OSG_LIBRARY_RELEASE OR OSG_LIBRARY_DEBUG AND OSG_INCLUDE_DIR AND OSG_GEN_INCLUDE_DIR) 94 | 95 | 96 | IF(OSG_LIBRARY_RELEASE OR OSG_LIBRARY_DEBUG AND OSG_INCLUDE_DIR) 97 | SET( OSG_FOUND "YES" ) 98 | SET( OSG_INCLUDE_DIRS ${OSG_INCLUDE_DIR} ) 99 | GET_FILENAME_COMPONENT( OSG_LIBRARY_DIR_RELEASE ${OSG_LIBRARY_RELEASE} PATH ) 100 | GET_FILENAME_COMPONENT( OSG_LIBRARY_DIR_DEBUG ${OSG_LIBRARY_DEBUG} PATH ) 101 | SET( OSG_LIBRARY_DIRS ${OSG_LIBRARY_DIR_RELEASE} ${OSG_LIBRARY_DIR_DEBUG} ) 102 | ENDIF(OSG_LIBRARY_RELEASE OR OSG_LIBRARY_DEBUG AND OSG_INCLUDE_DIR) 103 | -------------------------------------------------------------------------------- /CMakeModules/ModuleInstall.cmake: -------------------------------------------------------------------------------- 1 | # INSTALL and SOURCE_GROUP commands for osgPPU 2 | 3 | # Required Vars: 4 | # ${LIB_NAME} 5 | # ${LIB_PUBLIC_HEADERS} 6 | 7 | # -------------------------------------------------- 8 | # Setup destination directories 9 | # -------------------------------------------------- 10 | SET(INSTALL_INCDIR include) 11 | SET(INSTALL_BINDIR bin) 12 | SET(INSTALL_SRCDIR src) 13 | IF(WIN32) 14 | SET(INSTALL_LIBDIR bin) 15 | SET(INSTALL_ARCHIVEDIR lib${LIB_POSTFIX}) 16 | ELSE(WIN32) 17 | SET(INSTALL_LIBDIR lib${LIB_POSTFIX}) 18 | SET(INSTALL_ARCHIVEDIR lib${LIB_POSTFIX}) 19 | ENDIF(WIN32) 20 | 21 | IF(MSVC) 22 | HANDLE_MSVC_DLL() 23 | ENDIF(MSVC) 24 | 25 | INSTALL( 26 | TARGETS ${LIB_NAME} 27 | RUNTIME DESTINATION ${INSTALL_BINDIR} 28 | LIBRARY DESTINATION ${INSTALL_LIBDIR} 29 | ARCHIVE DESTINATION ${INSTALL_ARCHIVEDIR} 30 | ) 31 | 32 | 33 | # -------------------------------------------------- 34 | # Setup header file group for Visual Studio 35 | # -------------------------------------------------- 36 | SET(HEADERS_GROUP "Header Files") 37 | SOURCE_GROUP( 38 | ${HEADERS_GROUP} 39 | FILES ${LIB_PUBLIC_HEADERS} 40 | ) 41 | 42 | # -------------------------------------------------- 43 | # Setup source file group for Visual Studio 44 | # -------------------------------------------------- 45 | SET(SRC_GROUP "Source Files") 46 | SOURCE_GROUP( 47 | ${SRC_GROUP} 48 | FILES ${LIB_SRC_FILES} 49 | ) 50 | 51 | 52 | # -------------------------------------------------- 53 | # Install routines for differnet components 54 | # FIXME: Do not run for OS X framework 55 | # -------------------------------------------------- 56 | INSTALL( 57 | FILES ${LIB_PUBLIC_HEADERS} 58 | DESTINATION ${INSTALL_INCDIR}/${LIB_NAME} 59 | # COMPONENT ${PACKAGE_HEADERS} 60 | ) 61 | 62 | #INSTALL( 63 | # FILES ${LIB_SRC_FILES} 64 | # DESTINATION ${INSTALL_SRCDIR}/${LIB_NAME} 65 | # COMPONENT ${PACKAGE_SRC} 66 | #) 67 | 68 | #----------------------------------------------------------- 69 | # Include the build system parts to the source package 70 | #----------------------------------------------------------- 71 | #INSTALL ( 72 | # FILES 73 | # ${PROJECT_SOURCE_DIR}/CMakeLists.txt 74 | # ${PROJECT_SOURCE_DIR}/ChangeLog 75 | # ${PROJECT_SOURCE_DIR}/CONTRIBUTORS.txt 76 | # ${PROJECT_SOURCE_DIR}/LICENSE.txt 77 | # DESTINATION ./ 78 | # COMPONENT ${PACKAGE_SRC} 79 | #) 80 | 81 | #INSTALL ( 82 | # FILES 83 | # ${PROJECT_SOURCE_DIR}/src/CMakeLists.txt 84 | # DESTINATION src 85 | # COMPONENT ${PACKAGE_SRC} 86 | #) 87 | 88 | #INSTALL ( 89 | # FILES 90 | # ${PROJECT_SOURCE_DIR}/src/osgPlugins/CMakeLists.txt 91 | # DESTINATION src/osgPlugins 92 | # COMPONENT ${PACKAGE_SRC} 93 | #) 94 | -------------------------------------------------------------------------------- /CMakeModules/OsgDetermineCompiler.cmake: -------------------------------------------------------------------------------- 1 | # - Figure out what compiler (and version) cmake is generating for 2 | # Once done this will define: 3 | # 4 | # Variable: 5 | # OSG_COMPILER 6 | # 7 | 8 | IF(CMAKE_COMPILER_IS_GNUCXX) 9 | 10 | EXEC_PROGRAM( 11 | ${CMAKE_CXX_COMPILER} 12 | ARGS ${CMAKE_CXX_COMPILER_ARG1} -dumpversion 13 | OUTPUT_VARIABLE gcc_compiler_version 14 | ) 15 | #MESSAGE("GCC Version: ${gcc_compiler_version}") 16 | SET(OSG_COMPILER "gcc-${gcc_compiler_version}") 17 | 18 | ELSE(CMAKE_COMPILER_IS_GNUCXX) 19 | IF(MSVC) 20 | IF(MSVC60) 21 | SET(OSG_COMPILER "vc60") 22 | ENDIF(MSVC60) 23 | IF(MSVC70) 24 | SET(OSG_COMPILER "vc70") 25 | ENDIF(MSVC70) 26 | IF(MSVC71) 27 | SET(OSG_COMPILER "vc71") 28 | ENDIF(MSVC71) 29 | IF(MSVC80) 30 | SET(OSG_COMPILER "vc80") 31 | ENDIF(MSVC80) 32 | IF(MSVC90) 33 | SET(OSG_COMPILER "vc90") 34 | ENDIF(MSVC90) 35 | 36 | IF(MSVC80) 37 | MESSAGE(STATUS "Checking if compiler has service pack 1 installed...") 38 | FILE(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx" "int main() {return 0;}\n") 39 | 40 | TRY_COMPILE(_TRY_RESULT 41 | ${CMAKE_BINARY_DIR} 42 | ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx 43 | CMAKE_FLAGS -D CMAKE_VERBOSE_MAKEFILE=ON 44 | OUTPUT_VARIABLE OUTPUT 45 | ) 46 | 47 | IF(_TRY_RESULT) 48 | # parse for exact compiler version 49 | STRING(REGEX MATCH "Compiler Version [0-9]+.[0-9]+.[0-9]+.[0-9]+" vc_compiler_version "${OUTPUT}") 50 | IF(vc_compiler_version) 51 | #MESSAGE("${vc_compiler_version}") 52 | STRING(REGEX MATCHALL "[0-9]+" CL_VERSION_LIST "${vc_compiler_version}") 53 | LIST(GET CL_VERSION_LIST 0 CL_MAJOR_VERSION) 54 | LIST(GET CL_VERSION_LIST 1 CL_MINOR_VERSION) 55 | LIST(GET CL_VERSION_LIST 2 CL_PATCH_VERSION) 56 | LIST(GET CL_VERSION_LIST 3 CL_EXTRA_VERSION) 57 | ENDIF(vc_compiler_version) 58 | 59 | # Standard vc80 is 14.00.50727.42, sp1 14.00.50727.762, sp2? 60 | # Standard vc90 is 9.0.30729.1, sp1 ? 61 | IF(CL_EXTRA_VERSION EQUAL 762) 62 | SET(OSG_COMPILER "vc80sp1") 63 | ELSE(CL_EXTRA_VERSION EQUAL 762) 64 | SET(OSG_COMPILER "vc80") 65 | ENDIF(CL_EXTRA_VERSION EQUAL 762) 66 | 67 | # parse for exact visual studio version 68 | #IF(MSVC_IDE) 69 | # string(REGEX MATCH "Visual Studio Version [0-9]+.[0-9]+.[0-9]+.[0-9]+" vs_version "${OUTPUT}") 70 | # IF(vs_version) 71 | # MESSAGE("${vs_version}") 72 | # string(REGEX MATCHALL "[0-9]+" VS_VERSION_LIST "${vs_version}") 73 | # list(GET VS_VERSION_LIST 0 VS_MAJOR_VERSION) 74 | # list(GET VS_VERSION_LIST 1 VS_MINOR_VERSION) 75 | # list(GET VS_VERSION_LIST 2 VS_PATCH_VERSION) 76 | # list(GET VS_VERSION_LIST 3 VS_EXTRA_VERSION) 77 | # ENDIF(vs_version) 78 | #ENDIF(MSVC_IDE) 79 | ENDIF(_TRY_RESULT) 80 | ENDIF(MSVC80) 81 | ENDIF(MSVC) 82 | ENDIF(CMAKE_COMPILER_IS_GNUCXX) 83 | -------------------------------------------------------------------------------- /CMakeModules/OsgPPUCPackConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # This file will be configured to contain variables for CPack. These variables 2 | # should be set in the CMake list file of the project before CPack module is 3 | # included. Example variables are: 4 | # CPACK_GENERATOR - Generator used to create package 5 | # CPACK_INSTALL_CMAKE_PROJECTS - For each project (path, name, component) 6 | # CPACK_CMAKE_GENERATOR - CMake Generator used for the projects 7 | # CPACK_INSTALL_COMMANDS - Extra commands to install components 8 | # CPACK_INSTALL_DIRECTORIES - Extra directories to install 9 | # CPACK_PACKAGE_DESCRIPTION_FILE - Description file for the package 10 | # CPACK_PACKAGE_DESCRIPTION_SUMMARY - Summary of the package 11 | # CPACK_PACKAGE_EXECUTABLES - List of pairs of executables and labels 12 | # CPACK_PACKAGE_FILE_NAME - Name of the package generated 13 | # CPACK_PACKAGE_ICON - Icon used for the package 14 | # CPACK_PACKAGE_INSTALL_DIRECTORY - Name of directory for the installer 15 | # CPACK_PACKAGE_NAME - Package project name 16 | # CPACK_PACKAGE_VENDOR - Package project vendor 17 | # CPACK_PACKAGE_VERSION - Package project version 18 | # CPACK_PACKAGE_VERSION_MAJOR - Package project version (major) 19 | # CPACK_PACKAGE_VERSION_MINOR - Package project version (minor) 20 | # CPACK_PACKAGE_VERSION_PATCH - Package project version (patch) 21 | 22 | # There are certain generator specific ones 23 | 24 | # NSIS Generator: 25 | # CPACK_PACKAGE_INSTALL_REGISTRY_KEY - Name of the registry key for the installer 26 | # CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS - Extra commands used during uninstall 27 | # CPACK_NSIS_EXTRA_INSTALL_COMMANDS - Extra commands used during install 28 | 29 | 30 | SET(CPACK_GENERATOR "${CPACK_GENERATOR}") 31 | SET(CPACK_BINARY_BUNDLE "${CPACK_BINARY_BUNDLE}") 32 | SET(CPACK_BINARY_CYGWIN "${CPACK_BINARY_CYGWIN}") 33 | SET(CPACK_BINARY_DEB "${CPACK_BINARY_DEB}") 34 | SET(CPACK_BINARY_NSIS "${CPACK_BINARY_NSIS}") 35 | SET(CPACK_BINARY_OSXX11 "${CPACK_BINARY_OSXX11}") 36 | SET(CPACK_BINARY_PACKAGEMAKER "${CPACK_BINARY_PACKAGEMAKER}") 37 | SET(CPACK_BINARY_RPM "${CPACK_BINARY_RPM}") 38 | SET(CPACK_BINARY_STGZ "${CPACK_BINARY_STGZ}") 39 | SET(CPACK_BINARY_TGZ "${CPACK_BINARY_GENERATOR}") 40 | SET(CPACK_CMAKE_GENERATOR "${CMAKE_GENERATOR}") 41 | SET(CPACK_SOURCE_IGNORE_FILES "${CPACK_SOURCE_IGNORE_FILES};/CVS/;/\\.svn/;\\.swp$;") 42 | SET(CPACK_SOURCE_GENERATOR "${CPACK_SOURCE_GENERATOR}") 43 | SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}") 44 | 45 | SET(CPACK_COMPONENTS_ALL "${CPACK_COMPONENTS_ALL}") 46 | SET(CPACK_COMPONENT_UNSPECIFIED_HIDDEN "TRUE") 47 | SET(CPACK_COMPONENT_UNSPECIFIED_REQUIRED "TRUE") 48 | 49 | 50 | #SET(CPACK_INSTALL_CMAKE_PROJECTS "${PROJECT_BINARY_DIR};${PROJECT_NAME};${OSGPPU_CPACK_COMPONENT};/") 51 | SET(CPACK_INSTALL_CMAKE_PROJECTS "${CPACK_INSTALL_CMAKE_PROJECTS}") 52 | SET(CPACK_INSTALL_PREFIX "${CPACK_INSTALL_PREFIX}") 53 | SET(CPACK_MODULE_PATH "${osgPPU_SOURCE_DIR}/CMakeModules;") 54 | SET(CPACK_NSIS_DISPLAY_NAME "${CMAKE_PROJECT_NAME} ${OSGPPU_VERSION}") 55 | SET(CPACK_NSIS_INSTALLER_ICON_CODE "") 56 | SET(CPACK_NSIS_INSTALLER_MUI_ICON_CODE "") 57 | SET(CPACK_OUTPUT_CONFIG_FILE "${PROJECT_BINARY_DIR}/CPackConfig-${OSGPPU_CPACK_COMPONENT}.cmake") 58 | SET(CPACK_PACKAGE_DEFAULT_LOCATION "/") 59 | SET(CPACK_PACKAGE_DESCRIPTION_FILE "${osgPPU_SOURCE_DIR}/README.txt") 60 | SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "osgPPU is an open source NodeKit for OpenSceneGraph to easy implement of various post procesing effects and offline GPGPU computations.") 61 | SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}") 62 | SET(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_INSTALL_DIRECTORY}") 63 | SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "${CMAKE_PROJECT_NAME}-${OSGPPU_VERSION}") 64 | SET(CPACK_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") 65 | SET(CPACK_PACKAGE_RELOCATABLE "true") 66 | SET(CPACK_PACKAGE_VENDOR "The osgPPU developed by Art Tevs, see http://projects.tevs.eu/osgppu") 67 | SET(CPACK_PACKAGE_VERSION "${OSGPPU_VERSION}") 68 | SET(CPACK_PACKAGE_VERSION_MAJOR "${OSGPPU_MAJOR_VERSION}") 69 | SET(CPACK_PACKAGE_VERSION_MINOR "${OSGPPU_MINOR_VERSION}") 70 | SET(CPACK_PACKAGE_VERSION_PATCH "${OSGPPU_PATCH_VERSION}") 71 | SET(CPACK_RESOURCE_FILE_LICENSE "${osgPPU_SOURCE_DIR}/LICENSE.txt") 72 | SET(CPACK_RESOURCE_FILE_README "${osgPPU_SOURCE_DIR}/README.txt") 73 | #SET(CPACK_RESOURCE_FILE_WELCOME "${osgPPU_SOURCE_DIR}/NEWS.txt") 74 | SET(CPACK_SET_DESTDIR "OFF") 75 | SET(CPACK_STRIP_FILES "ON") 76 | -------------------------------------------------------------------------------- /CMakeModules/cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 2 | MESSAGE(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") 3 | ENDIF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 4 | 5 | FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) 6 | STRING(REGEX REPLACE "\n" ";" files "${files}") 7 | FOREACH(file ${files}) 8 | MESSAGE(STATUS "Uninstalling \"${file}\"") 9 | IF(EXISTS "${file}") 10 | EXEC_PROGRAM( 11 | "@CMAKE_COMMAND@" ARGS "-E remove \"${file}\"" 12 | OUTPUT_VARIABLE rm_out 13 | RETURN_VALUE rm_retval 14 | ) 15 | IF("${rm_retval}" STREQUAL 0) 16 | ELSE("${rm_retval}" STREQUAL 0) 17 | MESSAGE(FATAL_ERROR "Problem when removing \"${file}\"") 18 | ENDIF("${rm_retval}" STREQUAL 0) 19 | ELSE(EXISTS "${file}") 20 | MESSAGE(STATUS "File \"${file}\" does not exist.") 21 | ENDIF(EXISTS "${file}") 22 | ENDFOREACH(file) -------------------------------------------------------------------------------- /CMakeModules/cuda/CudaDependency.cmake: -------------------------------------------------------------------------------- 1 | 2 | # For more information, please see: http://software.sci.utah.edu 3 | # 4 | # The MIT License 5 | # 6 | # Copyright (c) 2007 7 | # Scientific Computing and Imaging Institute, University of Utah 8 | # 9 | # License for the specific language governing rights and limitations under 10 | # Permission is hereby granted, free of charge, to any person obtaining a 11 | # copy of this software and associated documentation files (the "Software"), 12 | # to deal in the Software without restriction, including without limitation 13 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 14 | # and/or sell copies of the Software, and to permit persons to whom the 15 | # Software is furnished to do so, subject to the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be included 18 | # in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 21 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 23 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | # DEALINGS IN THE SOFTWARE. 27 | 28 | # This code is based on the Manta swig/python wrapper dependency checking code. 29 | # -- Abe Stephens 30 | 31 | ##################################################################### 32 | ## CUDA_INCLUDE_NVCC_DEPENDENCIES 33 | ## 34 | 35 | # So we want to try and include the dependency file if it exists. If 36 | # it doesn't exist then we need to create an empty one, so we can 37 | # include it. 38 | 39 | # If it does exist, then we need to check to see if all the files it 40 | # depends on exist. If they don't then we should clear the dependency 41 | # file and regenerate it later. This covers the case where a header 42 | # file has disappeared or moved. 43 | 44 | MACRO(CUDA_INCLUDE_NVCC_DEPENDENCIES dependency_file) 45 | SET(CUDA_NVCC_DEPEND) 46 | SET(CUDA_NVCC_DEPEND_REGENERATE) 47 | 48 | # Include the dependency file. Create it first if it doesn't exist 49 | # for make files except for IDEs (see below). The INCLUDE puts a 50 | # dependency that will force CMake to rerun and bring in the new info 51 | # when it changes. DO NOT REMOVE THIS (as I did and spent a few hours 52 | # figuring out why it didn't work. 53 | IF(${CMAKE_MAKE_PROGRAM} MATCHES "make") 54 | IF(NOT EXISTS ${dependency_file}) 55 | CONFIGURE_FILE( 56 | ${CMAKE_SOURCE_DIR}/CMakeModules/cuda/empty.depend.in 57 | ${dependency_file} IMMEDIATE) 58 | ENDIF(NOT EXISTS ${dependency_file}) 59 | # Always include this file to force CMake to run again next 60 | # invocation and rebuild the dependencies. 61 | INCLUDE(${dependency_file}) 62 | ELSE(${CMAKE_MAKE_PROGRAM} MATCHES "make") 63 | # for IDE generators like MS dev only include the depend files 64 | # if they exist. This is to prevent ecessive reloading of 65 | # workspaces after each build. This also means 66 | # that the depends will not be correct until cmake 67 | # is run once after the build has completed once. 68 | # the depend files are created in the wrap tcl/python sections 69 | # when the .xml file is parsed. 70 | INCLUDE(${dependency_file} OPTIONAL) 71 | ENDIF(${CMAKE_MAKE_PROGRAM} MATCHES "make") 72 | 73 | # Now we need to verify the existence of all the included files 74 | # here. If they aren't there we need to just blank this variable and 75 | # make the file regenerate again. 76 | IF(CUDA_NVCC_DEPEND) 77 | FOREACH(f ${CUDA_NVCC_DEPEND}) 78 | IF(EXISTS ${f}) 79 | ELSE(EXISTS ${f}) 80 | SET(CUDA_NVCC_DEPEND_REGENERATE 1) 81 | ENDIF(EXISTS ${f}) 82 | ENDFOREACH(f) 83 | ELSE(CUDA_NVCC_DEPEND) 84 | # No dependencies, so regenerate the file. 85 | SET(CABLE_NVCC_DEPEND_REGENERATE 1) 86 | ENDIF(CUDA_NVCC_DEPEND) 87 | 88 | # No incoming dependencies, so we need to generate them. Make the 89 | # output depend on the dependency file itself, which should cause the 90 | # rule to re-run. 91 | IF(CUDA_NVCC_DEPEND_REGENERATE) 92 | SET(CUDA_NVCC_DEPEND ${dependency_file}) 93 | # Force CMake to run again next build 94 | CONFIGURE_FILE( 95 | ${CMAKE_SOURCE_DIR}/CMakeModules/cuda/empty.depend.in 96 | ${dependency_file} IMMEDIATE) 97 | ENDIF(CUDA_NVCC_DEPEND_REGENERATE) 98 | 99 | ENDMACRO(CUDA_INCLUDE_NVCC_DEPENDENCIES) -------------------------------------------------------------------------------- /CMakeModules/cuda/empty.depend.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cgart/osgPPU/cb65b6b18ba23cb34fe9a939f44113c24a412422/CMakeModules/cuda/empty.depend.in -------------------------------------------------------------------------------- /CMakeModules/cuda/make2cmake.cmake: -------------------------------------------------------------------------------- 1 | 2 | # For more information, please see: http://software.sci.utah.edu 3 | # 4 | # The MIT License 5 | # 6 | # Copyright (c) 2007 7 | # Scientific Computing and Imaging Institute, University of Utah 8 | # 9 | # License for the specific language governing rights and limitations under 10 | # Permission is hereby granted, free of charge, to any person obtaining a 11 | # copy of this software and associated documentation files (the "Software"), 12 | # to deal in the Software without restriction, including without limitation 13 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 14 | # and/or sell copies of the Software, and to permit persons to whom the 15 | # Software is furnished to do so, subject to the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be included 18 | # in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 21 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 23 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | # DEALINGS IN THE SOFTWARE. 27 | 28 | # Make2cmake CMake Script 29 | # Abe Stephens and James Bigler 30 | # (c) 2007 Scientific Computing and Imaging Institute, University of Utah 31 | # Note that the REGEX expressions may need to be tweaked for different dependency generators. 32 | 33 | FILE(READ ${input_file} depend_text) 34 | 35 | IF (${depend_text} MATCHES ".+") 36 | 37 | # MESSAGE("FOUND DEPENDS") 38 | 39 | # Remember, four backslashes is escaped to one backslash in the string. 40 | STRING(REGEX REPLACE "\\\\ " " " depend_text ${depend_text}) 41 | 42 | # This works for the nvcc -M generated dependency files. 43 | STRING(REGEX REPLACE "^.* : " "" depend_text ${depend_text}) 44 | STRING(REGEX REPLACE "[ \\\\]*\n" ";" depend_text ${depend_text}) 45 | 46 | FOREACH(file ${depend_text}) 47 | 48 | STRING(REGEX REPLACE "^ +" "" file ${file}) 49 | 50 | # IF (EXISTS ${file}) 51 | # MESSAGE("DEPEND = ${file}") 52 | # ELSE (EXISTS ${file}) 53 | # MESSAGE("ERROR = ${file}") 54 | # ENDIF(EXISTS ${file}) 55 | 56 | SET(cuda_nvcc_depend "${cuda_nvcc_depend} \"${file}\"\n") 57 | 58 | ENDFOREACH(file) 59 | 60 | ELSE(${depend_text} MATCHES ".+") 61 | # MESSAGE("FOUND NO DEPENDS") 62 | ENDIF(${depend_text} MATCHES ".+") 63 | 64 | 65 | FILE(WRITE ${output_file} "# Generated by: make2cmake.cmake\nSET(CUDA_NVCC_DEPEND\n ${cuda_nvcc_depend})\n\n") 66 | -------------------------------------------------------------------------------- /CMakeModules/cuda/parse_cubin.cmake: -------------------------------------------------------------------------------- 1 | # For more information, please see: http://software.sci.utah.edu 2 | # 3 | # The MIT License 4 | # 5 | # Copyright (c) 2007 6 | # Scientific Computing and Imaging Institute, University of Utah 7 | # 8 | # License for the specific language governing rights and limitations under 9 | # Permission is hereby granted, free of charge, to any person obtaining a 10 | # copy of this software and associated documentation files (the "Software"), 11 | # to deal in the Software without restriction, including without limitation 12 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | # and/or sell copies of the Software, and to permit persons to whom the 14 | # Software is furnished to do so, subject to the following conditions: 15 | # 16 | # The above copyright notice and this permission notice shall be included 17 | # in all copies or substantial portions of the Software. 18 | # 19 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | # DEALINGS IN THE SOFTWARE. 26 | 27 | # .cubin Parsing CMake Script 28 | # Abe Stephens 29 | # (c) 2007 Scientific Computing and Imaging Institute, University of Utah 30 | 31 | FILE(READ ${input_file} file_text) 32 | 33 | IF (${file_text} MATCHES ".+") 34 | 35 | # Remember, four backslashes is escaped to one backslash in the string. 36 | STRING(REGEX REPLACE ";" "\\\\;" file_text ${file_text}) 37 | STRING(REGEX REPLACE "\ncode" ";code" file_text ${file_text}) 38 | 39 | LIST(LENGTH file_text len) 40 | 41 | FOREACH(line ${file_text}) 42 | 43 | # Only look at "code { }" blocks. 44 | IF(line MATCHES "^code") 45 | 46 | # Break into individual lines. 47 | STRING(REGEX REPLACE "\n" ";" line ${line}) 48 | 49 | FOREACH(entry ${line}) 50 | 51 | # Extract kernel names. 52 | IF (${entry} MATCHES "[^g]name = ([^ ]+)") 53 | STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry}) 54 | 55 | # Check to see if the kernel name starts with "_" 56 | SET(skip FALSE) 57 | # IF (${entry} MATCHES "^_") 58 | # Skip the rest of this block. 59 | # MESSAGE("Skipping ${entry}") 60 | # SET(skip TRUE) 61 | # ELSE (${entry} MATCHES "^_") 62 | MESSAGE("Kernel: ${entry}") 63 | # ENDIF (${entry} MATCHES "^_") 64 | 65 | ENDIF(${entry} MATCHES "[^g]name = ([^ ]+)") 66 | 67 | # Skip the rest of the block if necessary 68 | IF(NOT skip) 69 | 70 | # Registers 71 | IF (${entry} MATCHES "reg = ([^ ]+)") 72 | STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry}) 73 | MESSAGE("Registers: ${entry}") 74 | ENDIF(${entry} MATCHES "reg = ([^ ]+)") 75 | 76 | # Local memory 77 | IF (${entry} MATCHES "lmem = ([^ ]+)") 78 | STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry}) 79 | MESSAGE("Local: ${entry}") 80 | ENDIF(${entry} MATCHES "lmem = ([^ ]+)") 81 | 82 | # Shared memory 83 | IF (${entry} MATCHES "smem = ([^ ]+)") 84 | STRING(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry}) 85 | MESSAGE("Shared: ${entry}") 86 | ENDIF(${entry} MATCHES "smem = ([^ ]+)") 87 | 88 | IF (${entry} MATCHES "^}") 89 | MESSAGE("") 90 | ENDIF(${entry} MATCHES "^}") 91 | 92 | ENDIF(NOT skip) 93 | 94 | 95 | ENDFOREACH(entry) 96 | 97 | ENDIF(line MATCHES "^code") 98 | 99 | ENDFOREACH(line) 100 | 101 | ELSE(${depend_text} MATCHES ".+") 102 | # MESSAGE("FOUND NO DEPENDS") 103 | ENDIF(${depend_text} MATCHES ".+") 104 | 105 | 106 | -------------------------------------------------------------------------------- /CONTRIBUTORS.txt: -------------------------------------------------------------------------------- 1 | This is a list of all contributors to the osgPPU library. 2 | Currently the list is not sorted in any manner (ok maybe 3 | in the time when a patch was submitted ;-) ). 4 | 5 | 6 | 7 | 8 Contributors: 8 | 9 | Firstname Surname 10 | ---------------------------- 11 | Art Tevs 12 | Stephane Lamoliatte 13 | Bob Kuhne 14 | Christian Heine 15 | Sean Carmody 16 | Doug McCorkle 17 | Valery Bickov 18 | Oleg Dedkow 19 | J.P. Delport 20 | Paul Martz 21 | Bryan Thrall 22 | Christian Richardt 23 | Allen Saucier 24 | Alexander Irion 25 | -------------------------------------------------------------------------------- /Data/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------- 2 | # Here we will setup all Data files which 3 | # has to be provided with the library 4 | # -------------------------------------------------- 5 | SET(LIB_NAME ${PROJECT_NAME}) 6 | 7 | OPTION(INSTALL_DATA "Should data from Data/ directory be also installed" OFF) 8 | SET(INSTALL_DATADIR "share/${LIB_NAME}" CACHE STRING "Relative path where data will be installed.") 9 | 10 | SET(DATA_PATH ${osgPPU_SOURCE_DIR}/Data) 11 | 12 | SET(LIB_DATA_FILES 13 | 14 | ${DATA_PATH}/bypass.ppu 15 | ${DATA_PATH}/cessnafire.osg 16 | ${DATA_PATH}/cow.osg 17 | ${DATA_PATH}/cuda.ppu 18 | ${DATA_PATH}/dof.ppu 19 | ${DATA_PATH}/hdr.ppu 20 | ${DATA_PATH}/motionblur.ppu 21 | ${DATA_PATH}/temple.ive 22 | ${DATA_PATH}/CMakeLists.txt 23 | ) 24 | 25 | # -------------------------------------------------- 26 | # Setup how the files should be installed 27 | # -------------------------------------------------- 28 | IF (INSTALL_DATA) 29 | INSTALL( 30 | FILES ${LIB_DATA_FILES} 31 | DESTINATION ${INSTALL_DATADIR} 32 | # COMPONENT ${PACKAGE_DATA} 33 | ) 34 | ENDIF(INSTALL_DATA) 35 | 36 | # -------------------------------------------------- 37 | # Do the same for all subdirectories 38 | # -------------------------------------------------- 39 | ADD_SUBDIRECTORY(glsl) 40 | ADD_SUBDIRECTORY(Images) 41 | 42 | 43 | # -------------------------------------------------- 44 | # Setup file group for Visual Studio 45 | # -------------------------------------------------- 46 | SET(DATA_GROUP "Data Files") 47 | SOURCE_GROUP( 48 | ${DATA_GROUP} 49 | FILES ${LIB_DATA_FILES} ${LIB_DATA_GLSL_FILES} ${LIB_DATA_IMAGES_FILES} 50 | ) 51 | -------------------------------------------------------------------------------- /Data/Images/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------- 2 | # Here we will setup all Data files which 3 | # has to be provided with the library 4 | # -------------------------------------------------- 5 | SET(LIB_DATA_IMAGES_FILES 6 | ${DATA_PATH}/Images/lz.rgb 7 | ${DATA_PATH}/Images/reflect.rgb 8 | ${DATA_PATH}/Images/skymap.jpg 9 | ${DATA_PATH}/Images/tank.rgb 10 | ${DATA_PATH}/Images/video.avi 11 | ${DATA_PATH}/Images/CMakeLists.txt 12 | ) 13 | 14 | # -------------------------------------------------- 15 | # Setup how the files should be installed 16 | # -------------------------------------------------- 17 | IF (INSTALL_DATA) 18 | INSTALL( 19 | FILES ${LIB_DATA_IMAGES_FILES} 20 | DESTINATION ${INSTALL_DATADIR}/Images 21 | # COMPONENT ${PACKAGE_DATA} 22 | ) 23 | ENDIF(INSTALL_DATA) 24 | 25 | -------------------------------------------------------------------------------- /Data/Images/lenna.rgb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cgart/osgPPU/cb65b6b18ba23cb34fe9a939f44113c24a412422/Data/Images/lenna.rgb -------------------------------------------------------------------------------- /Data/Images/lenna_noise.rgb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cgart/osgPPU/cb65b6b18ba23cb34fe9a939f44113c24a412422/Data/Images/lenna_noise.rgb -------------------------------------------------------------------------------- /Data/Images/lz.rgb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cgart/osgPPU/cb65b6b18ba23cb34fe9a939f44113c24a412422/Data/Images/lz.rgb -------------------------------------------------------------------------------- /Data/Images/reflect.rgb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cgart/osgPPU/cb65b6b18ba23cb34fe9a939f44113c24a412422/Data/Images/reflect.rgb -------------------------------------------------------------------------------- /Data/Images/skymap.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cgart/osgPPU/cb65b6b18ba23cb34fe9a939f44113c24a412422/Data/Images/skymap.jpg -------------------------------------------------------------------------------- /Data/Images/tank.rgb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cgart/osgPPU/cb65b6b18ba23cb34fe9a939f44113c24a412422/Data/Images/tank.rgb -------------------------------------------------------------------------------- /Data/Images/video.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cgart/osgPPU/cb65b6b18ba23cb34fe9a939f44113c24a412422/Data/Images/video.avi -------------------------------------------------------------------------------- /Data/bypass.ppu: -------------------------------------------------------------------------------- 1 | osgPPU::Processor { 2 | osgPPU::UnitBypass { 3 | UniqueID UnitBypass_0 4 | name "Bypass" 5 | isActive 1 6 | isOffline 0 7 | inputTextureIndexForViewportReference -1 8 | 9 | PPUOutput { 10 | PPU UnitOut_1 11 | } 12 | } 13 | osgPPU::UnitOut { 14 | UniqueID UnitOut_1 15 | name "PipelineResult" 16 | isActive 1 17 | isOffline 0 18 | inputTextureIndexForViewportReference -1 19 | 20 | PPUOutput { 21 | } 22 | } 23 | name Processor 24 | PPUOutput { 25 | PPU UnitBypass_0 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Data/cuda.ppu: -------------------------------------------------------------------------------- 1 | osgPPU::Processor { 2 | osgPPU::UnitBypass { 3 | UniqueID UnitBypass_0 4 | name "ColorBypass" 5 | isActive 1 6 | inputTextureIndexForViewportReference 0 7 | 8 | PPUOutput { 9 | PPU UnitInOutModule_1 10 | } 11 | 12 | Viewport { 13 | UniqueID Viewport_2 14 | x 0 15 | y 0 16 | width 640 17 | height 480 18 | } 19 | 20 | osgPPU::ColorAttribute { 21 | UniqueID ColorAttribute_3 22 | DataVariance DYNAMIC 23 | UpdateCallback { 24 | } 25 | startTime 0 26 | endTime 0 27 | startColor 1 1 1 1 28 | endColor 1 1 1 1 29 | } 30 | } 31 | osgPPU::UnitInOutModule { 32 | UniqueID UnitInOutModule_1 33 | name "CUDA-PPU" 34 | isActive 1 35 | inputTextureIndexForViewportReference 0 36 | 37 | PPUOutput { 38 | PPU UnitOut_4 39 | } 40 | 41 | Viewport { 42 | UniqueID Viewport_5 43 | x 0 44 | y 0 45 | width 640 46 | height 480 47 | } 48 | 49 | osgPPU::ColorAttribute { 50 | UniqueID ColorAttribute_6 51 | DataVariance DYNAMIC 52 | UpdateCallback { 53 | } 54 | startTime 0 55 | endTime 0 56 | startColor 1 1 1 1 57 | endColor 1 1 1 1 58 | } 59 | inputBypass -1 60 | outputInternalFormat GL_RGBA16F_ARB 61 | outputTextureType TEXTURE_2D 62 | outputFace 0 63 | outputDepth 1 64 | module "../lib/osgppu_cudakernel.so" 65 | } 66 | osgPPU::UnitOut { 67 | UniqueID UnitOut_4 68 | name "Output" 69 | isActive 1 70 | inputTextureIndexForViewportReference 0 71 | 72 | PPUOutput { 73 | } 74 | 75 | Viewport { 76 | UniqueID Viewport_7 77 | x 0 78 | y 0 79 | width 640 80 | height 480 81 | } 82 | 83 | osgPPU::ColorAttribute { 84 | UniqueID ColorAttribute_8 85 | DataVariance DYNAMIC 86 | UpdateCallback { 87 | } 88 | startTime 0 89 | endTime 0 90 | startColor 1 1 1 1 91 | endColor 1 1 1 1 92 | } 93 | } 94 | name Processor 95 | PPUOutput { 96 | PPU UnitBypass_0 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Data/glsl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------- 2 | # Here we will setup all Data files which 3 | # has to be provided with the library 4 | # -------------------------------------------------- 5 | SET(LIB_DATA_GLSL_FILES 6 | ${DATA_PATH}/glsl/brightpass_fp.glsl 7 | ${DATA_PATH}/glsl/depth_of_field_fp.glsl 8 | ${DATA_PATH}/glsl/gauss_convolution_1Dy_fp.glsl 9 | ${DATA_PATH}/glsl/luminance_adapted_fp.glsl 10 | ${DATA_PATH}/glsl/luminance_mipmap_fp.glsl 11 | ${DATA_PATH}/glsl/ssao_renderscene_fp.glsl 12 | ${DATA_PATH}/glsl/ssao_vp.glsl 13 | ${DATA_PATH}/glsl/bypass_fp.glsl 14 | ${DATA_PATH}/glsl/gauss_convolution_1Dx_fp.glsl 15 | ${DATA_PATH}/glsl/gauss_convolution_vp.glsl 16 | ${DATA_PATH}/glsl/luminance_fp.glsl 17 | ${DATA_PATH}/glsl/ssao_fp.glsl 18 | ${DATA_PATH}/glsl/ssao_renderscene_vp.glsl 19 | ${DATA_PATH}/glsl/tonemap_hdr_fp.glsl 20 | ${DATA_PATH}/glsl/CMakeLists.txt 21 | ) 22 | 23 | # -------------------------------------------------- 24 | # Setup how the files should be installed 25 | # -------------------------------------------------- 26 | IF (INSTALL_DATA) 27 | INSTALL( 28 | FILES ${LIB_DATA_GLSL_FILES} 29 | DESTINATION ${INSTALL_DATADIR}/glsl 30 | # COMPONENT ${PACKAGE_DATA} 31 | ) 32 | ENDIF(INSTALL_DATA) 33 | 34 | -------------------------------------------------------------------------------- /Data/glsl/brightpass_fp.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Pass only values which are over a bright treshold. 3 | * see http://msdn2.microsoft.com/en-us/library/bb173484(VS.85).aspx 4 | */ 5 | 6 | // ------------------------------------------------------- 7 | // Texture units used for texturing 8 | // ------------------------------------------------------- 9 | 10 | // Original hdr input 11 | uniform sampler2D hdrInput; 12 | 13 | // Luminance input containing luminance values (mipmapped) 14 | uniform sampler2D lumInput; 15 | 16 | // input texture containing the adpted luminance 17 | uniform sampler2D texAdaptedLuminance; 18 | 19 | // this gives us middle gray value 20 | uniform float g_fMiddleGray; 21 | 22 | /** 23 | * Scale luminance value according to the settings 24 | * @param lum Current luminance value 25 | * @param avg Acerage luminance value 26 | **/ 27 | float computeScaledLuminance(float avg, float lum) 28 | { 29 | // compute scaled luminance 30 | float scaledLum = lum * (g_fMiddleGray / (avg + 0.001)); 31 | 32 | // clamp to fp16 value 33 | scaledLum = min(scaledLum, 65504.0); 34 | 35 | // compute new luminance for the color 36 | return scaledLum / (1.0 + scaledLum); 37 | } 38 | 39 | /** 40 | * Perform passing of bright values. The bright values 41 | * will then be scaled according to the adapted luminance. 42 | **/ 43 | void main(void) 44 | { 45 | const float BRIGHT_PASS_THRESHOLD = 0.9; 46 | const float BRIGHT_PASS_OFFSET = 1.0; 47 | 48 | // get luminance and average (adapted) luminance value 49 | float fLuminance = texture2D(lumInput, gl_TexCoord[0].st).r; 50 | float fAdaptedLum = texture2D(texAdaptedLuminance, vec2(0.5,0.5)).w; 51 | float fScaledLum = computeScaledLuminance(fAdaptedLum, fLuminance); 52 | 53 | // get color of the pixel 54 | vec3 vSample = texture2D(hdrInput, gl_TexCoord[0].st).rgb; 55 | 56 | // Determine what the pixel's value will be after tone mapping occurs 57 | vSample *= fScaledLum; 58 | //vSample.rgb *= g_fMiddleGray/(fScaledLum + 0.001); 59 | 60 | // Subtract out dark pixels 61 | vSample -= BRIGHT_PASS_THRESHOLD; 62 | 63 | // Clamp to 0 64 | vSample = max(vSample, vec3(0.0, 0.0, 0.0)); 65 | 66 | // Map the resulting value into the 0 to 1 range. Higher values for 67 | // BRIGHT_PASS_OFFSET will isolate lights from illuminated scene 68 | // objects. 69 | vSample /= (BRIGHT_PASS_OFFSET + vSample); 70 | 71 | // resulting color 72 | gl_FragColor.rgb = vSample; 73 | gl_FragColor.a = fAdaptedLum; 74 | } 75 | -------------------------------------------------------------------------------- /Data/glsl/bypass_fp.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Reimplement fixed function pipeline of OpenGL 3 | * So bypass all the data. 4 | */ 5 | 6 | // ------------------------------------------------------- 7 | // Texture units used for texturing 8 | // ------------------------------------------------------- 9 | uniform sampler2D texUnit0; 10 | 11 | 12 | /** 13 | * Reimplement fixed pipeline 14 | **/ 15 | void main(void) 16 | { 17 | // get color from the texture 18 | vec4 texColor0 = texture2D(texUnit0, gl_TexCoord[0].st); 19 | 20 | // combine texture color with the vertex color 21 | gl_FragData[0] = texColor0; 22 | } 23 | -------------------------------------------------------------------------------- /Data/glsl/depth_of_field_fp.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Create Depth-Of-Filed effect by combining the depth map within the image map. 3 | */ 4 | 5 | // ------------------------------------------------------- 6 | // Texture units used for texturing 7 | // ------------------------------------------------------- 8 | // Texture containing the scene (color map) 9 | uniform sampler2D texColorMap; 10 | 11 | // Colormap of the scene blurred 12 | uniform sampler2D texBlurredColorMap; 13 | 14 | // Colormap of the scene blurred 15 | uniform sampler2D texStrongBlurredColorMap; 16 | 17 | // Depth map containing depth values of the image map 18 | uniform sampler2D texDepthMap; 19 | 20 | // Focal length of the camear 21 | uniform float focalLength; 22 | 23 | // Focal range of the camera 24 | uniform float focalRange; 25 | 26 | // zNear and zFar values 27 | uniform float zNear; 28 | uniform float zFar; 29 | 30 | float convertZ( in float near, in float far, in float depthBufferValue ) 31 | { 32 | float clipZ = ( depthBufferValue - 0.5 ) * 2.0; 33 | return -(2.0 * far * near) / ( clipZ * ( far - near ) - ( far + near )); 34 | } 35 | 36 | /** 37 | **/ 38 | void main(void) 39 | { 40 | vec2 inTex = gl_TexCoord[0].st; 41 | 42 | // compute distance to the viewer 43 | float a = zFar / ( zFar - zNear ); 44 | float b = zFar * zNear / ( zNear - zFar ); 45 | 46 | float depth = texture2D( texDepthMap, inTex ).x; 47 | float dist = b / ( depth - a ); 48 | 49 | // get color map and blurred color map values 50 | vec4 colorValue = texture2D (texColorMap, inTex).rgba; 51 | vec4 blurredValue1 = texture2D ( texBlurredColorMap, inTex).rgba; 52 | vec4 blurredValue2 = texture2D ( texStrongBlurredColorMap, inTex).rgba; 53 | 54 | // now compute the bluriness value 55 | float blur = clamp(abs(dist - focalLength) / focalRange, 0.0, 1.0); 56 | float factor1 = 1.0; 57 | float factor2 = 0.0; 58 | 59 | // compute blend factors 60 | if (blur > 0.5) 61 | factor2 = (blur - 0.5) * 2.0; 62 | else 63 | factor1 = blur * 2.0; 64 | 65 | 66 | // the resulting color value is the combination of blurred and non-blurred map 67 | vec4 result = mix(colorValue, blurredValue1, factor1); 68 | gl_FragColor = mix(result, blurredValue2, factor2); 69 | 70 | } 71 | -------------------------------------------------------------------------------- /Data/glsl/gauss_convolution_1Dx_fp.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Apply convolution of variable size onto the pixels. 3 | * The convolution is done in 1D 4 | */ 5 | 6 | // ------------------------------------------------------- 7 | // Texture units used for texturing 8 | // ------------------------------------------------------- 9 | uniform sampler2D texUnit0; 10 | 11 | //! Size of the gaussian kernel (size = radius * 2) 12 | uniform float radius; 13 | 14 | //! Sigam value for the gaussian kernel 15 | uniform float sigma; 16 | 17 | // Varyings 18 | varying float sigma2; 19 | varying float c; 20 | 21 | // width of the input texture 22 | uniform float osgppu_ViewportWidth; 23 | 24 | // height of the input texture 25 | uniform float osgppu_ViewportHeight; 26 | 27 | /** 28 | **/ 29 | void main(void) 30 | { 31 | // store here resulting color 32 | vec4 color = vec4(0.0); 33 | float totalWeigth = 0.0; 34 | float inputTexTexelWidth = 1.0 / osgppu_ViewportWidth; 35 | 36 | // convolve by applying nsamples-time the texture lookup 37 | for (float i=-radius; i < radius; i += 1.0) 38 | { 39 | // compute weight for the pixel 40 | float weight = c * exp((i*i) / (-sigma2)); 41 | totalWeigth += weight; 42 | 43 | // combine now the sum as all values multiplied by the weight 44 | color += texture2D(texUnit0, gl_TexCoord[0].xy + vec2(i * inputTexTexelWidth, 0) ) * weight; 45 | } 46 | color /= totalWeigth; 47 | 48 | gl_FragColor = color; 49 | } 50 | -------------------------------------------------------------------------------- /Data/glsl/gauss_convolution_1Dy_fp.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Apply convolution of variable size onto the pixels. 3 | * The convolution is done in 1D 4 | */ 5 | 6 | // ------------------------------------------------------- 7 | // Texture units used for texturing 8 | // ------------------------------------------------------- 9 | uniform sampler2D texUnit0; 10 | 11 | //! Size of the gaussian kernel (size = radius * 2) 12 | uniform float radius; 13 | 14 | //! Sigam value for the gaussian kernel 15 | uniform float sigma; 16 | 17 | // Varyings 18 | varying float sigma2; 19 | varying float c; 20 | 21 | // width of the input texture 22 | uniform float osgppu_ViewportWidth; 23 | 24 | // height of the input texture 25 | uniform float osgppu_ViewportHeight; 26 | 27 | /** 28 | **/ 29 | void main(void) 30 | { 31 | 32 | // store here resulting color 33 | vec4 color = vec4(0.0); 34 | float totalWeigth = 0.0; 35 | float inputTexTexelWidth = 1.0 / osgppu_ViewportHeight; 36 | 37 | // convolve by applying nsamples-time the texture lookup 38 | for (float i=-radius; i < radius; i += 1.0) 39 | { 40 | // compute weight for the pixel 41 | float weight = c * exp((i*i) / (-sigma2)); 42 | totalWeigth += weight; 43 | 44 | // combine now the sum as all values multiplied by the weight 45 | color += texture2D(texUnit0, gl_TexCoord[0].xy + vec2(0, i * inputTexTexelWidth) ) * weight; 46 | } 47 | color /= totalWeigth; 48 | 49 | gl_FragColor = color; 50 | } 51 | -------------------------------------------------------------------------------- /Data/glsl/gauss_convolution_vp.glsl: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Reimplement fixed function pipeline of OpenGL 4 | * So bypass all the data. 5 | * Precompute some constants which are needed for the convolution computation 6 | */ 7 | 8 | //! Sigma value for the gaussian kernel 9 | uniform float sigma; 10 | 11 | const float PI = 3.1415926535897; 12 | 13 | // Varyings 14 | varying float sigma2; 15 | varying float c; 16 | 17 | /** 18 | * Reimplement fixed pipeline 19 | **/ 20 | void main(void) 21 | { 22 | // bypass the texture coordinate data 23 | gl_TexCoord[0] = gl_MultiTexCoord0; 24 | 25 | // compute position of the pixel 26 | gl_Position = ftransform(); 27 | 28 | // bypass color data 29 | gl_FrontColor = gl_Color; 30 | 31 | // precompute constants 32 | sigma2 = 2.0 * sigma * sigma; 33 | c = sqrt((1.0 / (sigma2 * PI))); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /Data/glsl/luminance_adapted_fp.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Compute adapted luminance based on the data from the previous frames. 3 | * see http://msdn2.microsoft.com/en-us/library/bb173484(VS.85).aspx 4 | */ 5 | 6 | // ------------------------------------------------------- 7 | // Texture units used for texturing 8 | // ------------------------------------------------------- 9 | // input texture containing the average luminance 10 | uniform sampler2D texLuminance; 11 | 12 | // input texture containing the current adapted luminance 13 | uniform sampler2D texAdaptedLuminance; 14 | 15 | // max and min possible luminance 16 | uniform float maxLuminance; 17 | uniform float minLuminance; 18 | 19 | // time interval between two frames 20 | uniform float invFrameTime; 21 | 22 | // scaling factor which decides how fast to adapt for new luminance 23 | uniform float adaptScaleFactor; 24 | 25 | const float TauCone = 0.01; 26 | const float TauRod = 0.04; 27 | 28 | /** 29 | * Compute adapted luminance value. 30 | * @param current Is the current luminance value 31 | * @param old Adapted luminance value from the previous frame 32 | **/ 33 | void main(void) 34 | { 35 | // get current luminance, this one is stored in the last mipmap level 36 | float current = texture2D(texLuminance, vec2(0.5,0.5), 100.0).x; 37 | 38 | // get old adapted luminance value 39 | float old = texture2D(texAdaptedLuminance, vec2(0.5,0.5)).w; 40 | 41 | //determin if rods or cones are active 42 | //Perceptual Effects in Real-time Tone Mapping: Equ(7) 43 | float sigma = clamp(0.4/(0.04+current),0.0,1.0); 44 | 45 | //interpolate tau from taurod and taucone depending on lum 46 | //Perceptual Effects in Real-time Tone Mapping: Equ(12) 47 | float Tau = mix(TauCone,TauRod,sigma) / adaptScaleFactor; 48 | 49 | // compute new adapted value 50 | //float lum = old + (current - old) * (1.0 - pow(0.98, adaptScaleFactor * invFrameTime)); 51 | 52 | // clamp and return back 53 | //gl_FragData[0].xyzw = lum;//clamp(lum, minLuminance, maxLuminance); 54 | //gl_FragData[0].a = 1.0; 55 | 56 | 57 | 58 | 59 | 60 | //calculate adaption 61 | //Perceptual Effects in Real-time Tone Mapping: Equ(5) 62 | float lum = old + (current - old) * (1.0 - exp(-(invFrameTime)/Tau)); 63 | //gl_FragData[0].x = current; 64 | //gl_FragData[0].y = old; 65 | //gl_FragData[0].z = (1.0 - exp(-(invFrameTime)/Tau)); 66 | gl_FragData[0].xyzw = vec4( clamp(lum, minLuminance, maxLuminance) ); 67 | } 68 | -------------------------------------------------------------------------------- /Data/glsl/luminance_fp.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Compute luminance values of the input texture. 3 | * So result will contain only luminance values per pixel. 4 | */ 5 | 6 | // ------------------------------------------------------- 7 | // Texture units used for texturing 8 | // ------------------------------------------------------- 9 | uniform sampler2D texUnit0; 10 | 11 | 12 | /** 13 | **/ 14 | void main(void) 15 | { 16 | // get color from the texture 17 | vec4 texColor0 = texture2D(texUnit0, gl_TexCoord[0].st); 18 | 19 | // compute luminance and output 20 | gl_FragColor.xyz = vec3( texColor0.r * 0.2125 + texColor0.g * 0.7154 + texColor0.b * 0.0721 ); 21 | gl_FragColor.a = texColor0.a; 22 | } 23 | -------------------------------------------------------------------------------- /Data/glsl/luminance_mipmap_fp.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Compute logarithmic luminance for next mipmap level. 3 | * see http://msdn2.microsoft.com/en-us/library/bb173484(VS.85).aspx 4 | */ 5 | 6 | // ------------------------------------------------------- 7 | // Texture units used for texturing 8 | // ------------------------------------------------------- 9 | // just input texture from the previous stage 10 | uniform sampler2D texUnit0; 11 | 12 | // width of the input texture 13 | uniform float osgppu_ViewportWidth; 14 | 15 | // height of the input texture 16 | uniform float osgppu_ViewportHeight; 17 | 18 | // current mipmap level where we render the output 19 | uniform float osgppu_MipmapLevel; 20 | 21 | // number of mipmap levels available (needed for Shader Model 3.0 hardware) 22 | uniform float osgppu_MipmapLevelNum; 23 | 24 | 25 | /** 26 | * Do compute current luminance value. If we are in the last mipmap level 27 | * then do compute the exponent and adapted luminance value. 28 | **/ 29 | void main(void) 30 | { 31 | // just some variables 32 | const float epsilon = 0.001; 33 | float res = 0.0; 34 | float c[4]; 35 | 36 | // get texture sizes of the previous level 37 | vec2 size = vec2(osgppu_ViewportWidth, osgppu_ViewportHeight) * 2.0; 38 | 39 | // this is our starting sampling coordinate 40 | vec2 iCoord = gl_TexCoord[0].st; 41 | 42 | // this represent the step size to sample the pixels from previous mipmap level 43 | vec2 texel = vec2(1.0, 1.0) / (size); 44 | vec2 halftexel = vec2(0.5, 0.5) / size; 45 | 46 | // create offset for the texel sampling (TODO check why -1 seems to be correct) 47 | vec2 st[4]; 48 | st[0] = iCoord - halftexel + vec2(0,0); 49 | st[1] = iCoord - halftexel + vec2(texel.x,0); 50 | st[2] = iCoord - halftexel + vec2(0,texel.y); 51 | st[3] = iCoord - halftexel + vec2(texel.x,texel.y); 52 | 53 | // retrieve 4 texels from the previous mipmap level 54 | for (int i=0; i < 4; i++) 55 | { 56 | // map texels coordinates, such that they do stay in defined space 57 | st[i] = clamp(st[i], vec2(0,0), vec2(1,1)); 58 | 59 | // get texel from the previous mipmap level 60 | //c[i] = texelFetch2D(texUnit0, ivec2(size * st[i]), (int)osgppu_MipmapLevel - 1).r; 61 | c[i] = texture2D(texUnit0, st[i], osgppu_MipmapLevel - 1.0).r; 62 | } 63 | 64 | // if we compute the first mipmap level, then just compute the sum 65 | // of the log values 66 | if (abs(osgppu_MipmapLevel - 1.0) < 0.00001) 67 | { 68 | res += log(epsilon + c[0]); 69 | res += log(epsilon + c[1]); 70 | res += log(epsilon + c[2]); 71 | res += log(epsilon + c[3]); 72 | 73 | // for the rest we just compute the sum of underlying values 74 | }else 75 | { 76 | res += c[0]; 77 | res += c[1]; 78 | res += c[2]; 79 | res += c[3]; 80 | } 81 | 82 | // normalize result 83 | res *= 0.25; 84 | 85 | // if we are in the last mipmap level 86 | if (osgppu_MipmapLevelNum - osgppu_MipmapLevel < 2.0) 87 | { 88 | // exponentiate 89 | res = exp(res); 90 | } 91 | 92 | // result 93 | gl_FragData[0].rgba = vec4( min(res, 65504.0) ); 94 | //gl_FragData[0].a = 1.0; 95 | } 96 | -------------------------------------------------------------------------------- /Data/glsl/ssao_renderscene_fp.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Just render the scene in an ususal way. Output linear z-depth values 3 | * in the second texture coordiantes. 4 | */ 5 | 6 | // zNear and zFar values 7 | uniform float zNear; 8 | uniform float zFar; 9 | 10 | /** 11 | **/ 12 | void main(void) 13 | { 14 | // compute simple diffuse lighting, so that the scene get more pleasant 15 | vec3 eyeToLight = normalize(-gl_TexCoord[2]); 16 | vec4 diffuse = gl_Color * max(dot(eyeToLight, normalize(gl_TexCoord[0].xyz)), 0.0) ; 17 | gl_FragData[0].rgb = diffuse; 18 | 19 | 20 | // Use face normals instead of interpolated normals to make sure that the tangent planes 21 | // associated with the normals are actually tangent to the surface 22 | gl_FragData[1].xyz = normalize(cross(ddx(gl_TexCoord[1].xyz), ddy(gl_TexCoord[1].xyz))); 23 | 24 | // compute linear z-depth value 25 | gl_FragData[1].w = gl_TexCoord[0].w / zFar; 26 | } 27 | -------------------------------------------------------------------------------- /Data/glsl/ssao_renderscene_vp.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Just render the scene in an ususal way. Output linear z-depth values 3 | * and normal in the second texture coordiantes. 4 | * Precompute simple lighting model. 5 | */ 6 | 7 | 8 | /** 9 | **/ 10 | void main(void) 11 | { 12 | // compute position of the pixel 13 | gl_Position = ftransform(); 14 | 15 | // bypass color data 16 | gl_FrontColor = gl_Color; 17 | 18 | // compute normal and depth 19 | gl_TexCoord[0].xyz = normalize(gl_NormalMatrix * gl_Normal); 20 | 21 | // compute linear depth value 22 | // this is just a simple matrix multiplication 23 | // the difference is that this value is not divided by the consecutive 24 | // pipeline as for gl_Position, hence giving us what we have looked for 25 | gl_TexCoord[0].w = (gl_ModelViewProjectionMatrix * gl_Vertex).z; 26 | 27 | // store here the eye position of the vertex 28 | gl_TexCoord[1] = gl_ModelViewMatrix * vec4(gl_Vertex.xyz,1); 29 | 30 | // Transform the global lights to eye space 31 | gl_TexCoord[2] = gl_ModelViewMatrix * vec4(0.0, 1.0, 0.0, 1.0); 32 | } 33 | -------------------------------------------------------------------------------- /Data/glsl/ssao_vp.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * SSAO - Technique. 3 | * This shader is applied on the screen sized quad with scene rendered before as input. 4 | */ 5 | 6 | 7 | /** 8 | **/ 9 | void main(void) 10 | { 11 | // bypass the texture coordinate data 12 | gl_TexCoord[0] = gl_MultiTexCoord0; 13 | 14 | // compute position of the pixel 15 | gl_Position = ftransform(); 16 | 17 | // this is the eyeview vector (just as if the scene were raytraced ;) 18 | // in eye coordinates 19 | gl_TexCoord[1] = gl_ModelViewMatrix * gl_Vertex; 20 | } 21 | -------------------------------------------------------------------------------- /Data/glsl/tonemap_hdr_fp.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Combine input texture with a given hdr texture by applying 3 | * tonemapping algorithm found in 4 | * http://www.mpi-inf.mpg.de/resources/hdr/peffects/krawczyk05sccg.pdf 5 | */ 6 | 7 | // ------------------------------------------------------- 8 | // Texture units used for texturing 9 | // ------------------------------------------------------- 10 | // blurred texture of the brightpassed data 11 | uniform sampler2D blurInput; 12 | 13 | // hdr texture containing the scene 14 | uniform sampler2D hdrInput; 15 | 16 | // Luminance input 17 | uniform sampler2D lumInput; 18 | 19 | // input texture containing the adpted luminance 20 | uniform sampler2D texAdaptedLuminance; 21 | 22 | // how much to use blurred 23 | uniform float fBlurFactor; 24 | 25 | // this gives us middle gray value 26 | uniform float g_fMiddleGray; 27 | 28 | 29 | /** 30 | * Scale luminance value according to the settings 31 | * @param lum Current luminance value 32 | * @param avg Acerage luminance value 33 | **/ 34 | float computeScaledLuminance(float avg, float lum) 35 | { 36 | // compute scaled luminance 37 | float scaledLum = lum * (g_fMiddleGray / (avg + 0.001)); 38 | 39 | // clamp to fp16 value 40 | scaledLum = min(scaledLum, 65504.0); 41 | 42 | // compute new luminance for the color 43 | return scaledLum / (1.0 + scaledLum); 44 | } 45 | 46 | 47 | /** 48 | **/ 49 | void main(void) 50 | { 51 | vec2 inTex = gl_TexCoord[0].st; 52 | 53 | // get color from the texture blurred texture 54 | vec4 blurColor = texture2D(blurInput, inTex); 55 | 56 | // get color from the input texture 57 | vec4 hdrColor = texture2D(hdrInput, inTex); 58 | 59 | // get adapted, normal and scaled luminance 60 | float fLuminance = texture2D(lumInput, inTex).r; 61 | float fAdaptedLum = texture2D(texAdaptedLuminance, vec2(0.5,0.5)).w; 62 | float fScaledLum = computeScaledLuminance(fAdaptedLum, fLuminance); 63 | 64 | // resulting color is the hdr color multiplied by the scaled luminance 65 | vec4 color = hdrColor * fScaledLum; 66 | 67 | // gamma correction 68 | gl_FragColor.rgb = blurColor.rgb * fBlurFactor + color.rgb; 69 | gl_FragColor.a = 1.0; 70 | } 71 | -------------------------------------------------------------------------------- /Data/motionblur.ppu: -------------------------------------------------------------------------------- 1 | osgPPU::Processor { 2 | osgPPU::UnitBypass { 3 | UniqueID UnitBypass_0 4 | name "CameraBypass" 5 | isActive 1 6 | isOffline 0 7 | inputTextureIndexForViewportReference -1 8 | 9 | PPUOutput { 10 | PPU UnitInOut_2 11 | } 12 | } 13 | 14 | osgPPU::UnitInOut { 15 | UniqueID UnitInOut_2 16 | name "MotionBlur" 17 | isActive 1 18 | isOffline 0 19 | inputTextureIndexForViewportReference 0 20 | outputInternalFormat GL_RGBA16F_ARB 21 | 22 | InputToUniformMap { 23 | UnitBypass_0 Next 24 | UnitInOut_4 Prev 25 | } 26 | 27 | PPUOutput { 28 | PPU UnitInOut_4 29 | } 30 | 31 | osgPPU::ShaderAttribute { 32 | RefUniformPair { 33 | Uniform { 34 | name "fMotionBlurFactor" 35 | type float 1 FloatArray 1 36 | { 37 | 0.85548 38 | } 39 | } 40 | StateAttribute PROTECTED|OVERRIDE|ON 41 | } 42 | num_shaders 1 43 | Shader { 44 | type FRAGMENT 45 | code { 46 | "// Texture containing the scene (color map)" 47 | "uniform sampler2D Next;" 48 | "" 49 | "// Colormap of the view before" 50 | "uniform sampler2D Prev;" 51 | "" 52 | "// Motion blur factor" 53 | "uniform float fMotionBlurFactor;" 54 | "" 55 | "void main(void)" 56 | "{" 57 | " vec2 texCoords = gl_TexCoord[0].st;" 58 | "" 59 | " // get color values" 60 | " vec4 currentValue = texture2D (Next, texCoords).rgba;" 61 | " vec4 lastValue = texture2D (Prev, texCoords).rgba;" 62 | " " 63 | " // the resulting color value is the combination of blurred and non-blurred map " 64 | " gl_FragColor = mix(currentValue, lastValue, fMotionBlurFactor);" 65 | "" 66 | "}" 67 | } 68 | } 69 | } 70 | inputBypass -1 71 | } 72 | 73 | osgPPU::UnitInOut { 74 | UniqueID UnitInOut_4 75 | name "ShowBypass" 76 | isActive 1 77 | isOffline 0 78 | inputTextureIndexForViewportReference 0 79 | outputInternalFormat GL_RGBA16F_ARB 80 | 81 | PPUOutput { 82 | PPU UnitInOut_2 83 | PPU UnitOut_1 84 | } 85 | InputToUniformMap { 86 | UnitInOut_2 tex 87 | } 88 | 89 | osgPPU::ShaderAttribute { 90 | num_shaders 1 91 | Shader { 92 | type FRAGMENT 93 | code { 94 | "// Simple bypass shader which do nothing then bypass data" 95 | "uniform sampler2D tex;" 96 | "void main(void)" 97 | "{" 98 | " gl_FragColor = texture2D (tex, gl_TexCoord[0].st).rgba;" 99 | "" 100 | "}" 101 | } 102 | } 103 | } 104 | 105 | inputBypass -1 106 | } 107 | 108 | 109 | osgPPU::UnitOut { 110 | UniqueID UnitOut_1 111 | name "PipelineResult" 112 | isActive 1 113 | isOffline 0 114 | inputTextureIndexForViewportReference -1 115 | 116 | PPUOutput { 117 | } 118 | } 119 | 120 | name Processor 121 | PPUOutput { 122 | PPU UnitBypass_0 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Data/temple.ive: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cgart/osgPPU/cb65b6b18ba23cb34fe9a939f44113c24a412422/Data/temple.ive -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | Note: osgPPU is not developed further. The repository has moved to read-only state. 2 | 3 | How to use examples 4 | =============================== 5 | 6 | ATTENTION: 7 | Examples do load .ppu and .glsl files out of the Data directory, which can 8 | be found in the main direcotry of osgPPU. In order that this files are found 9 | you have to setup the OSG_FILE_PATH environment variable accordingly. 10 | Hence on Unix systems do following: 11 | export OSG_FILE_PATH=$OSG_FILE_PATH:/path/were/osgPPU/is/installed/ 12 | 13 | Other solution would be just to copy the Data/ directory under your bin/ 14 | directory to let examnple run 15 | 16 | 17 | The Data/ irectory does contain some examples and tools coming together 18 | witht the osgPPU package. Use them to see how all the things are setted up. 19 | Use the viewer to see the .ppu files which you can find in the bin/Data/ 20 | directory. 21 | For example: 22 | cd bin 23 | ./viewer Data/motionblur.ppu 24 | will show you how the motionblur effect can be realized with the osgPPU. 25 | The corresponding .ppu file does contain a main setup for the correct 26 | effect pipeline. 27 | 28 | 29 | 30 | 31 | How to build the osgPPU 32 | =============================== 33 | 34 | The osgPPU uses the CMake build system to generate a 35 | platform-specific build environment. This build system 36 | was choosen since OpenSceneGraph is also based on it. 37 | 38 | If you don't already have CMake installed on your system you can grab 39 | it from http://www.cmake.org, use version 2.4.6 or later. Details on the 40 | OpenSceneGraph's CMake build can be found at: 41 | 42 | http://www.openscenegraph.org/projects/osg/wiki/Build/CMake 43 | 44 | Under unices (i.e. Linux, IRIX, Solaris, Free-BSD, HP-Ux, AIX, OSX) 45 | use the cmake or ccmake command-line utils. To compile osgPPU type following: 46 | 47 | cd osgPPU 48 | cmake . -DCMAKE_BUILD_TYPE=Release 49 | make 50 | sudo make install 51 | 52 | Alternatively, you can create an out-of-source build directory and run 53 | cmake or ccmake from there. The advantage to this approach is that the 54 | temporary files created by CMake won't clutter the osgPPU 55 | source directory, and also makes it possible to have multiple 56 | independent build targets by creating multiple build directories. In a 57 | directory alongside the OpenSceneGraph use: 58 | 59 | mkdir build 60 | cd build 61 | cmake ../ -DCMAKE_BUILD_TYPE=Release 62 | make 63 | sudo make install 64 | 65 | If you would like to install the library somehwere else than the default 66 | install location, so type in the main directory of osgPPU the following: 67 | 68 | cmake . -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/path/to/install 69 | make install 70 | 71 | Under Windows use the GUI tool CMakeSetup to build your VisualStudio 72 | files. The following page on OpenSceneGraph's wiki dedicated to the CMake build 73 | system should help guide you through the process: 74 | 75 | http://www.openscenegraph.org/projects/osg/wiki/Support/PlatformSpecifics/VisualStudio 76 | 77 | 78 | 79 | 80 | How to build osg plugin osgdb_ppu 81 | =============================== 82 | The plugin is build together with the complete library. 83 | However to install the library file in correct plugin 84 | directory you have to specify the version of osg with: 85 | 86 | cmake . -DOSG_VERSION=2.5.x 87 | 88 | The consecutive call of "make install" would install 89 | the ppu plugin under PREFIX/lib/osgPlugins-2.5.x/. 90 | If no version was specified then the installation path 91 | is PREFIX/lib/osgPlugins-2.4.0/ 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | doxygen config.doxy 3 | 4 | install: 5 | 6 | clean: 7 | rm -rf doxy 8 | rm -rf *~ 9 | -------------------------------------------------------------------------------- /doc/createChangelog.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | svn up ../ 4 | svn log --xml --verbose ../ | xsltproc scripts/svn2cl.xsl - > ../ChangeLog 5 | -------------------------------------------------------------------------------- /doc/footer.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | Back to Homepage of osgPPU
4 |

Copyright (C) 2008 by Art Tevs (LGPL)

5 | -------------------------------------------------------------------------------- /include/osgPPU/BarrierNode.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2009 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | #ifndef _C_BARRIER__H_ 17 | #define _C_BARRIER__H_ 18 | 19 | //------------------------------------------------------------------------- 20 | // Includes 21 | //------------------------------------------------------------------------- 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace osgPPU 28 | { 29 | /** 30 | * Helper class to block cycle traversion throught the nodes 31 | **/ 32 | class BarrierNode : public osg::Node 33 | { 34 | public: 35 | BarrierNode() : osg::Node() {} 36 | ~BarrierNode(){} 37 | 38 | //! The barrier node do just block the traversion, hence childs are not traversed 39 | void traverse (osg::NodeVisitor &nv){} 40 | 41 | //! The barrier node do just block the traversion, hence childs are not traversed 42 | void ascend (osg::NodeVisitor &nv){} 43 | 44 | //! Since traversion is blocked, we should allow the computation of bounding sphere 45 | inline osg::BoundingSphere computeBound() const {return osg::BoundingSphere();} 46 | 47 | //! Get the node, which was previously the child 48 | inline osg::Node* getBlockedChild() { return _child; } 49 | inline const osg::Node* getBlockedChild() const { return _child; } 50 | 51 | //! Set child which is now blocked 52 | inline void setBlockedChild(osg::Node* child) { _child = child; } 53 | 54 | //! Get the node, which was previously the parent 55 | inline osg::Group* getBlockedParent() {return _parent;} 56 | 57 | //! Set parent which is now blocked 58 | inline void setBlockedParent(osg::Group* parent){_parent = parent;} 59 | 60 | private: 61 | osg::Node* _child; 62 | osg::Group* _parent; 63 | }; 64 | 65 | }; // end namespace 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /include/osgPPU/Camera.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2010 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | #ifndef _C_OSGPPU_CAMERA__H_ 17 | #define _C_OSGPPU_CAMERA__H_ 18 | 19 | //------------------------------------------------------------------------- 20 | // Includes 21 | //------------------------------------------------------------------------- 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace osgPPU 28 | { 29 | 30 | //! Camera class which can be used with osgPPU 31 | /** 32 | * A camera class which acts as a wrapper for standard osg::Camera 33 | * and includes useful methods for proper use of osgPPU. 34 | * 35 | * NOTE: You do not have to use this class, this is just a wrapper for simple usage. 36 | **/ 37 | class OSGPPU_EXPORT Camera : public osg::Camera 38 | { 39 | public: 40 | 41 | /** 42 | * Resize camera's viewport. This will also resize camera's attachments if such exists. 43 | * Call this method when you have resized your window and wish to update the camera to 44 | * the new size. 45 | **/ 46 | static void resizeViewport(int x, int y, int width, int height, osg::Camera* camera); 47 | }; 48 | 49 | //! Derived class from osg's FBO implementation in order to allow marking FBO as dirty 50 | /** 51 | * This is a workaround implementation of osg::FrameBufferObject giving a possibility 52 | * to mark the FBO as dirty. This is required when you made changes to FBOs attachments 53 | * and you want to propagate them to the FBO. 54 | */ 55 | class OSGPPU_EXPORT FrameBufferObject : public osg::FrameBufferObject 56 | { 57 | public: 58 | void dirty() { dirtyAll(); } 59 | }; 60 | 61 | }; 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /include/osgPPU/ColorAttribute.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #ifndef _C_COLORATTRIBUTE_H_ 18 | #define _C_COLORATTRIBUTE_H_ 19 | 20 | 21 | //------------------------------------------------------------------------- 22 | // Includes 23 | //------------------------------------------------------------------------- 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | namespace osgPPU 32 | { 33 | 34 | //! Stateattribute to work with blending. Can be used for animated blending operations (fadein, fadeout) 35 | /** 36 | * This is a class derived from StateAttirbute. It allows to specify blending colors based 37 | * on the reference time provided with the corresponding node visitor. This class is also 38 | * used to setup any unit's geometry to default color (1,1,1,1) which is required for 39 | * proper rendering. 40 | **/ 41 | class OSGPPU_EXPORT ColorAttribute : public osg::StateAttribute 42 | { 43 | public: 44 | META_StateAttribute(osgPPU, ColorAttribute, MATERIAL); 45 | 46 | ColorAttribute(); 47 | ColorAttribute(const ColorAttribute& bm, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 48 | ~ColorAttribute(); 49 | 50 | /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */ 51 | int compare(const osg::StateAttribute& sa) const 52 | { 53 | // Check for equal types, then create the rhs variable 54 | // used by the COMPARE_StateAttribute_Paramter macros below. 55 | COMPARE_StateAttribute_Types(ColorAttribute, sa) 56 | 57 | // Compare each parameter in turn against the rhs. 58 | COMPARE_StateAttribute_Parameter(mColor) 59 | COMPARE_StateAttribute_Parameter(mStartColor) 60 | COMPARE_StateAttribute_Parameter(mEndColor) 61 | COMPARE_StateAttribute_Parameter(mStartTime) 62 | COMPARE_StateAttribute_Parameter(mEndTime) 63 | COMPARE_StateAttribute_Parameter(mTime) 64 | 65 | return 0; // Passed all the above comparison macros, so must be equal. 66 | } 67 | 68 | /** 69 | * Apply attribute to the state. This will just call the glColor() function with appropriate 70 | * values. The corresponding time is updated during the update traversion. 71 | **/ 72 | void apply(osg::State& state) const; 73 | 74 | /** 75 | * Set to use GL_BLEND mode, because it is required for this attribute 76 | **/ 77 | bool getModeUsage(osg::StateAttribute::ModeUsage& usage) const 78 | { 79 | usage.usesMode(GL_BLEND); 80 | return true; 81 | } 82 | 83 | /** Set start time for the interpolationm operation **/ 84 | void setStartTime(double time) { mStartTime = time; } 85 | 86 | /** Get start interpolation time **/ 87 | double getStartTime() const { return mStartTime; } 88 | 89 | /** Set end time for the interpolationm operation **/ 90 | void setEndTime(double time) { mEndTime = time; } 91 | 92 | /** Get end interpolation time **/ 93 | double getEndTime() const { return mEndTime; } 94 | 95 | /** Set start value of the interpolationm operation **/ 96 | void setStartColor(const osg::Vec4& color) { mStartColor = color; } 97 | 98 | /** Get start interpolation time **/ 99 | const osg::Vec4& getStartColor() const { return mStartColor; } 100 | 101 | /** Set end value of the interpolationm operation **/ 102 | void setEndColor(const osg::Vec4& color) { mEndColor = color; } 103 | 104 | /** Get end interpolation time **/ 105 | const osg::Vec4& getEndColor() const { return mEndColor; } 106 | 107 | private: 108 | 109 | /** 110 | * Update method to update the color based on the data 111 | **/ 112 | class UpdateCallback : public osg::StateAttribute::Callback 113 | { 114 | void operator()(osg::StateAttribute* sa, osg::NodeVisitor* nv); 115 | }; 116 | 117 | //! Current color in use (default 1,1,1,1) 118 | osg::Vec4 mColor; 119 | 120 | //! Current time 121 | double mTime; 122 | 123 | //! Start time of the alpha transition animation 124 | double mStartTime; 125 | 126 | //! End time of the alpha transition animation 127 | double mEndTime; 128 | 129 | //! Start value of the color animation 130 | osg::Vec4 mStartColor; 131 | 132 | //! End color of the color transition animation 133 | osg::Vec4 mEndColor; 134 | 135 | }; 136 | 137 | }; 138 | 139 | #endif 140 | 141 | -------------------------------------------------------------------------------- /include/osgPPU/Export.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #ifndef _C_OSGPPU_EXPORT_H_ 18 | #define _C_OSGPPU_EXPORT_H_ 19 | 20 | #if defined(_MSC_VER) 21 | #pragma warning( disable : 4244 ) 22 | #pragma warning( disable : 4251 ) 23 | #pragma warning( disable : 4267 ) 24 | #pragma warning( disable : 4275 ) 25 | #pragma warning( disable : 4290 ) 26 | #pragma warning( disable : 4786 ) 27 | #pragma warning( disable : 4305 ) 28 | #pragma warning( disable : 4996 ) 29 | 30 | #endif 31 | 32 | #if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) 33 | # if defined( OSGPPU_LIBRARY_STATIC ) 34 | # define OSGPPU_EXPORT 35 | # elif defined( OSGPPU_LIBRARY ) 36 | # define OSGPPU_EXPORT __declspec(dllexport) 37 | # else 38 | # define OSGPPU_EXPORT __declspec(dllimport) 39 | # endif 40 | #else 41 | # define OSGPPU_EXPORT 42 | #endif 43 | 44 | // set up define for whether member templates are supported by VisualStudio compilers. 45 | #ifdef _MSC_VER 46 | # if (_MSC_VER >= 1300) 47 | # define __STL_MEMBER_TEMPLATES 48 | # endif 49 | #endif //_MSC_VER 50 | 51 | /* Define NULL pointer value */ 52 | 53 | #ifndef NULL 54 | #ifdef __cplusplus 55 | #define NULL 0 56 | #else 57 | #define NULL ((void *)0) 58 | #endif 59 | #endif //NULL 60 | 61 | #endif //_C_OSGPPU_EXPORT_H_ 62 | -------------------------------------------------------------------------------- /include/osgPPU/UnitBypass.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #ifndef _C_UNIT_BYPASS_H_ 18 | #define _C_UNIT_BYPASS_H_ 19 | 20 | 21 | //------------------------------------------------------------------------- 22 | // Includes 23 | //------------------------------------------------------------------------- 24 | #include 25 | #include 26 | 27 | namespace osgPPU 28 | { 29 | //! Unit which do simply bypass input to the output 30 | /** 31 | * The result of this ppu is similar to Unit::setOutputTextreMap(Unit::getInputTextureMap()); 32 | **/ 33 | class OSGPPU_EXPORT UnitBypass : public Unit { 34 | public: 35 | META_Node(osgPPU,UnitBypass); 36 | 37 | UnitBypass(); 38 | UnitBypass(const UnitBypass& u, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 39 | 40 | virtual ~UnitBypass(); 41 | 42 | protected: 43 | virtual void setupInputsFromParents(); 44 | virtual bool noticeBeginRendering (osg::RenderInfo&, const osg::Drawable* ) { return false; } 45 | virtual void traverse(osg::NodeVisitor& nv) { return Unit::traverse(nv); } 46 | }; 47 | }; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /include/osgPPU/UnitCamera.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #ifndef _C_UNIT_CAMERA_H_ 18 | #define _C_UNIT_CAMERA_H_ 19 | 20 | 21 | //------------------------------------------------------------------------- 22 | // Includes 23 | //------------------------------------------------------------------------- 24 | #include 25 | #include 26 | 27 | namespace osgPPU 28 | { 29 | //! Put camera into unit pipeline 30 | /** 31 | * This unit is very useful when you want to include camera directly into the unit pipeline. 32 | * Camera is attached to this unit and its output can be accessed through UnitCameraAttachmentBypass 33 | * unit. This allows direct including of multiple camera's outputs into the unit pipeline. 34 | **/ 35 | class OSGPPU_EXPORT UnitCamera : public UnitBypass { 36 | public: 37 | META_Node(osgPPU, UnitCamera); 38 | 39 | UnitCamera(); 40 | UnitCamera(const UnitCamera& u, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 41 | 42 | virtual ~UnitCamera(); 43 | 44 | /** 45 | * Set camera which output is to be included into the pipeline. 46 | * @param camera Camera pointer 47 | * @param addAsChild If true camera will be added as child of this unit, 48 | * which give the possibility to traversals also on the camera object 49 | * without need of including the camera somehwere else in the scene graph. 50 | **/ 51 | void setCamera(osg::Camera* camera, bool addAsChild = false); 52 | 53 | //! Get camera object used 54 | osg::Camera* getCamera() { return mCamera.get(); } 55 | 56 | protected: 57 | osg::ref_ptr mCamera; 58 | bool mUseCameraAsChild; 59 | }; 60 | 61 | }; 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /include/osgPPU/UnitCameraAttachmentBypass.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #ifndef _C_UNIT_CAMERABUFFER_BYPASS_H_ 18 | #define _C_UNIT_CAMERABUFFER_BYPASS_H_ 19 | 20 | 21 | //------------------------------------------------------------------------- 22 | // Includes 23 | //------------------------------------------------------------------------- 24 | #include 25 | 26 | namespace osgPPU 27 | { 28 | //! Bypass a specified camera attacment into the pipeline 29 | /** 30 | * This unit do not perform any rendering, however it do 31 | * bypass any camera attachment of camera of the parent processor or unit 32 | * to its output texture. 33 | * Per default the unit do bypass the color buffer attachment. 34 | * 35 | * This unit has to be placed directly under the processor, so that the unit 36 | * get access to the processor's attachments. 37 | * 38 | * This unit can also bypass a camera attachment of UnitCamera parent unit. 39 | * For this purpose the unit has to be placed directly under UnitCamera. Camera 40 | * output will then be bypassed. 41 | **/ 42 | class OSGPPU_EXPORT UnitCameraAttachmentBypass : public UnitBypass { 43 | public: 44 | META_Node(osgPPU,UnitCameraAttachmentBypass); 45 | 46 | UnitCameraAttachmentBypass(); 47 | UnitCameraAttachmentBypass(const UnitCameraAttachmentBypass& u, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 48 | 49 | virtual ~UnitCameraAttachmentBypass(); 50 | 51 | virtual void init(); 52 | 53 | /** 54 | * Setup the buffer component which has to be bypassed. 55 | **/ 56 | void setBufferComponent(osg::Camera::BufferComponent c); 57 | 58 | /** 59 | * Get current buffer component 60 | **/ 61 | const osg::Camera::BufferComponent getBufferComponent() const { return _bufferComponent; } 62 | 63 | protected: 64 | virtual void setupInputsFromParents(); 65 | osg::Camera::BufferComponent _bufferComponent; 66 | 67 | }; 68 | }; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /include/osgPPU/UnitDepthbufferBypass.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #ifndef _C_UNIT_DEPTHBUFFER_BYPASS_H_ 18 | #define _C_UNIT_DEPTHBUFFER_BYPASS_H_ 19 | 20 | 21 | //------------------------------------------------------------------------- 22 | // Includes 23 | //------------------------------------------------------------------------- 24 | #include 25 | 26 | namespace osgPPU 27 | { 28 | //! Bypass the depthbuffer attachment of the camera to the output 29 | /** 30 | * Just a wrapper for the UnitCameraAttachmentBypass. @see UnitCameraAttachmentBypass 31 | **/ 32 | class OSGPPU_EXPORT UnitDepthbufferBypass : public UnitCameraAttachmentBypass { 33 | public: 34 | META_Node(osgPPU, UnitDepthbufferBypass); 35 | 36 | UnitDepthbufferBypass(); 37 | UnitDepthbufferBypass(const UnitDepthbufferBypass& u, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 38 | 39 | ~UnitDepthbufferBypass(); 40 | }; 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /include/osgPPU/UnitInHistoryOut.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2009 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #ifndef _C_UNIT_INHISTORYOUT_H_ 18 | #define _C_UNIT_INHISTORYOUT_H_ 19 | 20 | 21 | //------------------------------------------------------------------------- 22 | // Includes 23 | //------------------------------------------------------------------------- 24 | #include 25 | #include 26 | #include 27 | 28 | namespace osgPPU 29 | { 30 | //! NOT IMPLEMENTED (Implementation of history buffer) 31 | /** 32 | * NOTE: CURRENTLY NOT IMPLEMENTED 33 | * 34 | * A simple implementation of history buffer. Inputs are stored in a ring 35 | * buffer in an texture array. Output is the texture array and current index and 36 | * everything neccessary to use the data. 37 | **/ 38 | class OSGPPU_EXPORT UnitInHistoryOut : public UnitInOut { 39 | public: 40 | META_Node(osgPPU,UnitInHistoryOut); 41 | 42 | //! Create default ppfx 43 | UnitInHistoryOut(); 44 | UnitInHistoryOut(const UnitInHistoryOut&, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 45 | 46 | //! Release it and used memory 47 | virtual ~UnitInHistoryOut(); 48 | 49 | /** 50 | * Setup the number of elements in the history buffer. 51 | * Input frames are stored consecutively in the ring buffer 52 | * of the given size. 53 | **/ 54 | inline void setHistorySize(unsigned size) { if (size != _historySize) dirty(); _historySize = size; } 55 | 56 | /** 57 | * Initialize history buffer implementation. 58 | **/ 59 | virtual void init(); 60 | 61 | /** 62 | * Update the unit. Ringbuffer is updated and corresponding fbo's are set properly 63 | **/ 64 | virtual void update(); 65 | 66 | /** 67 | * Return output texture for the specified MRT index. 68 | * If no such exists, then it will be allocated. 69 | **/ 70 | virtual osg::Texture* getOrCreateOutputTexture(int mrt = 0); 71 | 72 | protected: 73 | //! Reassign fbo if output textures changes 74 | virtual void assignOutputTexture(); 75 | 76 | unsigned _historySize; 77 | std::map > > _fboMap; 78 | 79 | }; 80 | 81 | }; 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /include/osgPPU/UnitInMipmapOut.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #ifndef _C_UNIT_INMIPMAPOUT_H_ 18 | #define _C_UNIT_INMIPMAPOUT_H_ 19 | 20 | 21 | //------------------------------------------------------------------------- 22 | // Includes 23 | //------------------------------------------------------------------------- 24 | #include 25 | #include 26 | 27 | namespace osgPPU 28 | { 29 | //! Compute mipmapped output texture based on the input data 30 | /** 31 | * UnitInMipmapOut do generate mipmap levels of an output texture 32 | * by applying the shader to the input data. To generate the mipmapped 33 | * output the input texture has to be reused. Therefore the output texture 34 | * will be applied as an input texture. If input textures are already exists 35 | * the output texture will be applied to the next free slot. 36 | * Use this Unit to generate mipmaps of an input texture. 37 | * The shader has to be able to generate correct mipmap levels out of 38 | * the input data and/or previous levels. 39 | * 40 | * You can also setup this unit in that way, that it do generate 41 | * the mipmaps for the input texture and hence do not use any other output texture, 42 | * which of course save some memory. 43 | **/ 44 | class OSGPPU_EXPORT UnitInMipmapOut : public UnitInOut { 45 | public: 46 | META_Node(osgPPU,UnitInMipmapOut); 47 | 48 | //! Create default ppfx 49 | UnitInMipmapOut(); 50 | UnitInMipmapOut(const UnitInMipmapOut&, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 51 | 52 | //! Release it and used memory 53 | virtual ~UnitInMipmapOut(); 54 | 55 | /** 56 | * Initialize the UnitInMipmapOut. 57 | * This will check if the unit is marked as dirty 58 | * and will therefor setup the input and output texture properly. 59 | **/ 60 | virtual void init(); 61 | 62 | /** 63 | * Specify the index of the input texture for which the mipmaps should 64 | * be generated. Set to -1 if you would like to create an independent 65 | * output texture in which the input texture incl. mipmaps will be stored. 66 | **/ 67 | inline void setGenerateMipmapForInputTexture(int index) 68 | { 69 | mGenerateMipmapInputIndex = index; 70 | dirty(); 71 | } 72 | 73 | /** 74 | * Get index of an input texture for which the mipmaps are generated. If returns 75 | * -1 then the output texture is unequal input texture. 76 | **/ 77 | int getGenerateMipmapForInputTextureIndex() const { return mGenerateMipmapInputIndex; } 78 | 79 | /** 80 | * Enable or disable the shader for the mipmap generation. 81 | * If the shader is disabled then the glGenerateMipmapEXT function 82 | * will be used to generate the mipmaps. Otehrwise the shader is used. 83 | **/ 84 | void setUseShader(bool use) { if (mUseShader != use) dirty(); mUseShader = use; } 85 | 86 | /** 87 | * Get a flag if a shader is used to generate mipmaps. If returns false, 88 | * then the hardware mipmap generation is enabled. 89 | **/ 90 | bool getUseShader() const { return mUseShader; } 91 | 92 | protected: 93 | 94 | void enableMipmapGeneration(); 95 | bool noticeBeginRendering (osg::RenderInfo&, const osg::Drawable* ); 96 | void noticeFinishRendering(osg::RenderInfo &renderInfo, const osg::Drawable* drawable); 97 | void createAndAttachFBOs(osg::Texture* output, int mrt); 98 | 99 | std::vector > mMipmapFBO; 100 | std::vector > mMipmapViewport; 101 | std::vector > mMipmapDrawable; 102 | 103 | osg::ref_ptr mProjectionMatrix; 104 | osg::ref_ptr mModelviewMatrix; 105 | 106 | int mNumLevels; 107 | int mGenerateMipmapInputIndex; 108 | bool mUseShader; 109 | 110 | int mOutputWidth; 111 | int mOutputHeight; 112 | }; 113 | 114 | }; 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /include/osgPPU/UnitInOutModule.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #ifndef _C_UNIT_INOUT_MODULE_H_ 18 | #define _C_UNIT_INOUT_MODULE_H_ 19 | 20 | 21 | //------------------------------------------------------------------------- 22 | // Includes 23 | //------------------------------------------------------------------------- 24 | #include 25 | #include 26 | #include 27 | 28 | //! Name of the function which is the entry point of the module 29 | #define OSGPPU_MODULE_ENTRY osgppuInitModule 30 | #define OSGPPU_MODULE_ENTRY_STR "osgppuInitModule" 31 | 32 | namespace osgPPU 33 | { 34 | //! Apply some loaded module on the input texture to compute the output 35 | /** 36 | * UnitInOutModule does load a module from a dynamic library which is capable 37 | * of doing processing operations on the input data. Such a module could be for 38 | * example a cuda processing module which process the input by cuda. 39 | **/ 40 | class OSGPPU_EXPORT UnitInOutModule : public UnitInOut 41 | { 42 | public: 43 | META_Node(osgPPU, UnitInOutModule); 44 | 45 | UnitInOutModule(); 46 | UnitInOutModule(const UnitInOutModule&, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 47 | 48 | //! Release it and used memory 49 | virtual ~UnitInOutModule(); 50 | 51 | /** 52 | * Interface class of a module which can be used with this unit to process the input 53 | * data. 54 | **/ 55 | class Module : public osg::Referenced 56 | { 57 | public: 58 | //! Default constructor of the module 59 | Module(UnitInOutModule* parent) : _parent(parent) {} 60 | 61 | virtual ~Module(){} 62 | 63 | /** 64 | * Let the module initiaize. Overwrite the method with proper initialization routines. 65 | * @return If false is given back the module will not be used and will be unloaded. 66 | **/ 67 | virtual bool init() {return true;} 68 | 69 | //! This method will be called whenever the rendering has began. (@see noticeBeginRendering()) 70 | virtual bool beginAndProcess() { return false; } 71 | 72 | //! End rendering (@see noticeFinishRendering()) 73 | virtual void end() { } 74 | 75 | protected: 76 | UnitInOutModule* _parent; 77 | 78 | }; 79 | 80 | typedef bool (*OSGPPU_MODULE_ENTRY)(UnitInOutModule*); 81 | 82 | /** 83 | * Specify the file name of a dynamic libray containg the module. 84 | * A method "osgppuInitModule" has to be present in the library. 85 | * To the method pointer of this unit will be passed to let it 86 | * setup himself properly. 87 | * @return true if loading was successful 88 | **/ 89 | virtual bool loadModule(const std::string& moduleFile); 90 | 91 | /** 92 | * Set module which will be used to process the input data. 93 | **/ 94 | virtual void setModule(Module* module); 95 | 96 | //! Remove currently used module. 97 | virtual void removeModule(); 98 | 99 | //! Get last loaded module file name 100 | const std::string& getModuleFile() const { return _moduleFile; } 101 | 102 | //! Get currently loaded module 103 | Module* getModule() { return _module.get(); } 104 | const Module* getModule() const { return _module.get(); } 105 | 106 | protected: 107 | 108 | //! Start cuda kernel running over the input textures 109 | virtual bool noticeBeginRendering(osg::RenderInfo &, const osg::Drawable* ); 110 | 111 | //! Stop cuda kernel execution and write results to the output textures 112 | virtual void noticeFinishRendering(osg::RenderInfo &, const osg::Drawable* ); 113 | 114 | bool _moduleDirty; 115 | osg::ref_ptr _module; 116 | osg::ref_ptr _moduleLib; 117 | std::string _moduleFile; 118 | }; 119 | 120 | }; 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /include/osgPPU/UnitInOutRepeat.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2009 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #ifndef _C_UNIT_BYPASS_REPEAT_H_ 18 | #define _C_UNIT_BYPASS_REPEAT_H_ 19 | 20 | 21 | //------------------------------------------------------------------------- 22 | // Includes 23 | //------------------------------------------------------------------------- 24 | #include 25 | #include 26 | 27 | namespace osgPPU 28 | { 29 | //! Implementation of repeatable UnitInOut (rendering several iterations) 30 | /** 31 | * A repeatable unit is an unit, which runs for several iterations. The unit subgraph 32 | * which parent this unit is, is rendered several times. So on the first call 33 | * parent of a repeatable unit is used as input to the subgraph. After full computation of 34 | * the subgraph the output of the last unit is set as input to the repeatable unit. 35 | * Then the subgraph is iterated until numIterations-1 is reached. 36 | * After all iterations the child of a last unit is executed with the output of the last unit in 37 | * the repeatable subgraph. 38 | * 39 | * This unit is derived from UnitInOut. Per default the data is just bypassed without any shader processing. 40 | * You can specify your own shader to use the iteration unit as processing unit too. However, notice, 41 | * that at least one child has to exists, otherwise the unit will write to itself, which is forbidden. 42 | * Having at least one child makes sure, that the output of that child can be reused as input to the repeatable subgraph. 43 | * One can use this to implement Ping-Ponging or similar techniques. 44 | * 45 | * NOTE: Currently only 1 input to the repeat unit is supported! 46 | * Please check that last node (which output is reused) has also only 1 output specified! 47 | **/ 48 | class OSGPPU_EXPORT UnitInOutRepeat : public UnitInOut { 49 | public: 50 | META_Node(osgPPU,UnitInOutRepeat); 51 | 52 | UnitInOutRepeat(); 53 | UnitInOutRepeat(const UnitInOutRepeat&, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 54 | 55 | virtual ~UnitInOutRepeat(); 56 | 57 | /** 58 | * Set child unit, which is used as last/output unit in the iterative unit subgraph. 59 | * After the first iteration the output of this unit is used as input to the iterative subgraph. 60 | * After last iteration the execution is passed to the children of this unit, so the unit 61 | * execution continues on the child of a last unit of iterative subgraph. 62 | * @param node Node in the scenegraph which is a last unit in the iterative subgraph 63 | **/ 64 | void setLastNode(Unit* node); 65 | inline Unit* getLastNode() { return _lastNode.get(); } 66 | inline const Unit* getLastNode() const { return _lastNode.get(); } 67 | 68 | /** 69 | * Set the amount of iterations (default 1). 70 | **/ 71 | inline void setNumIterations(int num) { _numIterations = num; dirty(); } 72 | inline int getNumIterations() const { return _numIterations; } 73 | 74 | /** 75 | * If last node in the iterative subgraph has more than one output (MRT), then 76 | * specify here the mrt index of the output you would like to use while iterating. 77 | * (default is 0) 78 | **/ 79 | inline void setLastNodeOutputIndex(unsigned index) { _lastNodeOutputIndex = index; dirty(); } 80 | inline unsigned getLastNodeOutputIndex() const { return _lastNodeOutputIndex; } 81 | 82 | protected: 83 | //! Overriden method from the base class 84 | virtual void init(); 85 | 86 | //! Special treatment for traversing repeatable subgraph 87 | virtual void traverse(osg::NodeVisitor& nv); 88 | 89 | int _numIterations; 90 | unsigned _lastNodeOutputIndex; 91 | osg::ref_ptr _lastNode; 92 | }; 93 | 94 | }; 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /include/osgPPU/UnitInResampleOut.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #ifndef _C_UNIT_INRESAMPLEOUT_H_ 18 | #define _C_UNIT_INRESAMPLEOUT_H_ 19 | 20 | 21 | //------------------------------------------------------------------------- 22 | // Includes 23 | //------------------------------------------------------------------------- 24 | #include 25 | #include 26 | 27 | namespace osgPPU 28 | { 29 | //! Same as UnitInOut but do resampling inbetween 30 | /** 31 | * Resample the input. This PPU will 32 | * render the input data resampled to the output. Next PPU will work 33 | * on the resampled one. NOTE: You loose information in your data after 34 | * appling this PPU. 35 | **/ 36 | class OSGPPU_EXPORT UnitInResampleOut : public UnitInOut { 37 | public: 38 | META_Node(osgPPU,UnitInResampleOut); 39 | 40 | //! Create default ppfx 41 | UnitInResampleOut(); 42 | UnitInResampleOut(const UnitInResampleOut&, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 43 | 44 | //! Release it and used memory 45 | virtual ~UnitInResampleOut(); 46 | 47 | //! Set resampling factor 48 | void setFactorX(float x); 49 | 50 | //! Set resampling factor 51 | void setFactorY(float Y); 52 | 53 | //! Get resampling factor 54 | float getFactorX() const { return mWidthFactor; } 55 | 56 | //! Get resampling factor 57 | float getFactorY() const { return mHeightFactor; } 58 | 59 | void init(); 60 | void dirty(); 61 | 62 | protected: 63 | float mWidthFactor, mHeightFactor; 64 | bool mDirtyFactor; 65 | }; 66 | 67 | }; 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /include/osgPPU/UnitMipmapInMipmapOut.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #ifndef _C_UNIT_MIPMAPINOUT_H_ 18 | #define _C_UNIT_MIPMAPINOUT_H_ 19 | 20 | 21 | //------------------------------------------------------------------------- 22 | // Includes 23 | //------------------------------------------------------------------------- 24 | #include 25 | #include 26 | 27 | namespace osgPPU 28 | { 29 | //! Same as UnitInOut however do bypass also mipmap levels 30 | /** 31 | * The functionality of this unit is similar to the UnitInOut. However this 32 | * unit is also capable to bypass mipmap levels. This means that the output texture 33 | * will be switched in a mipmap mode and the input textures are passed levelwise 34 | * to the output texture. 35 | * 36 | * In order that this unit work correctly the input texture and the output should be of the 37 | * same dimensions, otherwise non 1:1 matching of mipmap levels is possible. 38 | **/ 39 | class OSGPPU_EXPORT UnitMipmapInMipmapOut : public UnitInOut { 40 | public: 41 | META_Node(osgPPU,UnitMipmapInMipmapOut); 42 | 43 | UnitMipmapInMipmapOut(); 44 | UnitMipmapInMipmapOut(const UnitMipmapInMipmapOut&, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 45 | 46 | //! Release it and used memory 47 | virtual ~UnitMipmapInMipmapOut(); 48 | 49 | //! Initialze the Processoring unit 50 | virtual void init(); 51 | 52 | protected: 53 | 54 | //! regenerate io mapmapped data structures 55 | void checkIOMipmappedData(); 56 | 57 | bool noticeBeginRendering (osg::RenderInfo&, const osg::Drawable* ); 58 | 59 | std::vector > mIOMipmapFBO; 60 | std::vector > mIOMipmapViewport; 61 | std::vector > mIOMipmapDrawable; 62 | 63 | osg::ref_ptr mProjectionMatrix; 64 | osg::ref_ptr mModelviewMatrix; 65 | }; 66 | 67 | }; 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /include/osgPPU/UnitOut.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #ifndef _C_UNIT_OUT_IO_H_ 18 | #define _C_UNIT_OUT_IO_H_ 19 | 20 | 21 | //------------------------------------------------------------------------- 22 | // Includes 23 | //------------------------------------------------------------------------- 24 | #include 25 | #include 26 | 27 | namespace osgPPU 28 | { 29 | //! Output the input to the frame buffer instead to the output texture 30 | /** 31 | * Pass input texture to the frame buffer. Use this ppu 32 | * to render results of the previous ppus into the framebuffer. So it is usual that 33 | * this ppu is applied at the end of the pipeline 34 | **/ 35 | class OSGPPU_EXPORT UnitOut : public Unit { 36 | public: 37 | META_Node(osgPPU,UnitOut); 38 | 39 | UnitOut(); 40 | UnitOut(const UnitOut&, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 41 | 42 | //! Release it and used memory 43 | virtual ~UnitOut(); 44 | 45 | //! Initialze the default Processoring unit 46 | virtual void init(); 47 | 48 | protected: 49 | /** 50 | * Since UnitOut forces to use no FBO, here we will disable the used FBO. 51 | * Derived classes has to take care abou that step 52 | **/ 53 | virtual bool noticeBeginRendering (osg::RenderInfo&, const osg::Drawable* ) ; 54 | 55 | /** 56 | * Disabled FBO will be restored back. 57 | **/ 58 | virtual void noticeFinishRendering(osg::RenderInfo &renderInfo, const osg::Drawable*); 59 | 60 | //! Viewport changed 61 | virtual void noticeChangeViewport(osg::RenderInfo&) {} 62 | 63 | //! Default FBO instance, so when apply this it FBO with id 0 will be applied 64 | osg::ref_ptr mDefaultFBO; 65 | }; 66 | }; 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /include/osgPPU/UnitOutCapture.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #ifndef _C_UNIT_CAPTURE__H_ 18 | #define _C_UNIT_CAPTURE__H_ 19 | 20 | 21 | //------------------------------------------------------------------------- 22 | // Includes 23 | //------------------------------------------------------------------------- 24 | #include 25 | #include 26 | 27 | namespace osgPPU 28 | { 29 | //! Capture the content of the input texture to a file 30 | /** 31 | * Screen capturing ppu. The input texture is captured into a file. 32 | * This ppu allows to render out in higher resolution than your 33 | * monitor supports. This can be only achieved if your rendering 34 | * is going completely through ppu pipeline, so renderer in offscreen mode. 35 | **/ 36 | class OSGPPU_EXPORT UnitOutCapture : public UnitOut { 37 | public: 38 | META_Node(osgPPU,UnitOutCapture); 39 | 40 | //! Create default ppfx 41 | UnitOutCapture(); 42 | UnitOutCapture(const UnitOutCapture&, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 43 | 44 | //! Release it and used memory 45 | virtual ~UnitOutCapture(); 46 | 47 | //! Set path were to store the screenshots 48 | void setPath(const std::string& path) { mPath = path; } 49 | 50 | //! set extension 51 | void setFileExtension(const std::string& ext) { mExtension = ext; } 52 | 53 | //! get currently used path 54 | inline const std::string& getPath() const { return mPath; } 55 | 56 | //! get currently used extension 57 | inline const std::string& getFileExtension() const { return mExtension; } 58 | 59 | /** 60 | * Set if the output should be generated only once. 61 | * The unit will be activated only for one frame. 62 | * You will need to reactivate the unit, if you would like to have continous frame capturing 63 | * after one frame shot. 64 | **/ 65 | inline void setShotOnce(bool b) { mShotOnce = b; if (b) setActive(true); } 66 | 67 | //! Check if the unit will shot once on the next traversion 68 | inline bool getShotOnce() { return mShotOnce; } 69 | 70 | //! Direct function, which can be used to take a screenshot. 71 | virtual void captureInput(osg::State* state); 72 | 73 | //! Initialze the default Processoring unit 74 | virtual void init(); 75 | 76 | protected: 77 | 78 | //! path were to store the files 79 | std::string mPath; 80 | 81 | //! Current number of the capture file 82 | std::map mCaptureNumber; 83 | 84 | //! file extensions 85 | std::string mExtension; 86 | 87 | bool mShotOnce; 88 | }; 89 | 90 | }; 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /include/osgPPU/UnitText.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #ifndef _C_UNITS_TEXT_HUD_H_ 18 | #define _C_UNITS_TEXT_HUD_H_ 19 | 20 | 21 | //------------------------------------------------------------------------- 22 | // Includes 23 | //------------------------------------------------------------------------- 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | namespace osgPPU 30 | { 31 | //! Same as UnitInOut but renders text onto the output. 32 | /** 33 | * The text is displayed in 2D ortho mode. This class is wrapper for the 34 | * osgText::Text class, so check it for more information about the text support. 35 | **/ 36 | class OSGPPU_EXPORT UnitText : public UnitInOut 37 | { 38 | public: 39 | META_Node(osgPPU, UnitText); 40 | 41 | //! Create default ppfx 42 | UnitText(); 43 | UnitText(const UnitText&, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 44 | 45 | //! Release it and used memory 46 | virtual ~UnitText(); 47 | 48 | //! Initialze the default postprocessing unit 49 | virtual void init(); 50 | 51 | //! Set size of the characters (relative to viewport.width / 640) 52 | inline void setSize(float size) 53 | { 54 | mSize= size; 55 | if (getViewport()) 56 | mText->setCharacterSize(mSize * (float(getViewport()->width()) / 640.0), 1.0); 57 | } 58 | inline float getSize() const { return mSize; } 59 | 60 | //! Set text position in 2D coordinates 61 | inline void setPosition(float x, float y) { mText->setPosition(osg::Vec3(x,y,0)); } 62 | 63 | //! Text Unit does work as a simple bypass, hence return here always the input 64 | inline osg::Texture* getOrCreateOutputTexture(int mrt = 0) { return mInputTex[mrt].get(); } 65 | 66 | //! Get text assigned with this unit 67 | osgText::Text& getText() { return *mText; } 68 | const osgText::Text& getText() const { return *mText; } 69 | 70 | //! Set string drawed by the text 71 | void setText(const std::string& txt) { mText->setText(txt); } 72 | 73 | //! Set the text pointer used for the rendering 74 | void setText(osgText::Text* text); 75 | 76 | protected: 77 | 78 | //! Text class holder 79 | osg::ref_ptr mText; 80 | 81 | //! Size of the font 82 | float mSize; 83 | 84 | virtual bool noticeBeginRendering (osg::RenderInfo&, const osg::Drawable* ) ; 85 | 86 | 87 | }; 88 | 89 | }; // end namespace 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /include/osgPPU/UnitTexture.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #ifndef _C_UNIT_TEXTURE_H_ 18 | #define _C_UNIT_TEXTURE_H_ 19 | 20 | 21 | //------------------------------------------------------------------------- 22 | // Includes 23 | //------------------------------------------------------------------------- 24 | #include 25 | #include 26 | 27 | namespace osgPPU 28 | { 29 | //! Texture unit is used to include external textures in the unit graph 30 | /** 31 | * If you like to have an external texture as input to any unit in the unit graph, 32 | * then you have to setup this behaviour with the help of this unit. The unit should be placed 33 | * directly under processor. Unit works as a simple bypass, by passing specified texture to the output. 34 | **/ 35 | class OSGPPU_EXPORT UnitTexture : public UnitBypass { 36 | public: 37 | META_Node(osgPPU,UnitTexture); 38 | 39 | UnitTexture(); 40 | UnitTexture(const UnitTexture& u, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 41 | UnitTexture(osg::Texture* tex); 42 | 43 | virtual ~UnitTexture(); 44 | 45 | /** 46 | * Set a texture which is used as output of this unit. 47 | * The children will get this texture as input automatically. 48 | **/ 49 | virtual void setTexture(osg::Texture* tex); 50 | 51 | /** 52 | * Get texture which is used as output of this unit. 53 | **/ 54 | inline osg::Texture* getTexture() { return _externTexture; } 55 | 56 | private: 57 | virtual void setupInputsFromParents(); 58 | osg::ref_ptr _externTexture; 59 | }; 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /include/osgPPU/Utility.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #ifndef _C_OSGPPU__H_ 18 | #define _C_OSGPPU__H_ 19 | 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | /** 27 | * \namespace osgPPU 28 | * osgPPU module 29 | **/ 30 | namespace osgPPU 31 | { 32 | /** 33 | * Utility function to derive source texture format from the internal format. 34 | * For example GL_RGB16F_ARB corresponds to GL_RGB 35 | **/ 36 | OSGPPU_EXPORT GLenum createSourceTextureFormat(GLenum internalFormat); 37 | 38 | /** 39 | * Utility function to derive uniform type based on the given texture. 40 | **/ 41 | OSGPPU_EXPORT osg::Uniform::Type convertTextureToUniformType(osg::Texture* tex); 42 | 43 | /** 44 | * Compute memory size in bytes, which is allocated by the texture. 45 | **/ 46 | OSGPPU_EXPORT unsigned int computeTextureSizeInBytes(osg::Texture* tex); 47 | 48 | }; 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_SUBDIRECTORY(example) 2 | ADD_SUBDIRECTORY(osgPPU) 3 | ADD_SUBDIRECTORY(osgPlugins) 4 | 5 | -------------------------------------------------------------------------------- /src/example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_SUBDIRECTORY(hdr) 2 | ADD_SUBDIRECTORY(viewer) 3 | ADD_SUBDIRECTORY(dof) 4 | ADD_SUBDIRECTORY(cubemap) 5 | ADD_SUBDIRECTORY(texture3D) 6 | ADD_SUBDIRECTORY(video) 7 | ADD_SUBDIRECTORY(ssao) 8 | ADD_SUBDIRECTORY(glow) 9 | ADD_SUBDIRECTORY(diffusion) 10 | ADD_SUBDIRECTORY(motionblur) 11 | ADD_SUBDIRECTORY(blurScene) 12 | 13 | #if CUDA found, then build cuda example 14 | IF(CUDA_BUILD_EXAMPLES AND CUDA_NVCC) 15 | ADD_SUBDIRECTORY(cuda) 16 | ENDIF(CUDA_BUILD_EXAMPLES AND CUDA_NVCC) 17 | 18 | #----------------------------------------------- 19 | # Add the file to the install target 20 | #----------------------------------------------- 21 | #INSTALL ( 22 | # FILES 23 | # CMakeLists.txt 24 | # DESTINATION src/examples 25 | # COMPONENT ${PACKAGE_EXAMPLES} 26 | #) 27 | 28 | ################################################################################ 29 | # Copy data files out from src/examples into the build bin directory 30 | ################################################################################ 31 | #FILE(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/bin/Data" "${CMAKE_BINARY_DIR}/bin/Data/glsl" "${CMAKE_BINARY_DIR}/bin/Data/Images") 32 | #CONFIGURE_FILE("${SOURCE_DIR}/src/example/Data/dof.ppu" "${CMAKE_BINARY_DIR}/bin/Data/" COPYONLY) 33 | #CONFIGURE_FILE("${SOURCE_DIR}/src/example/Data/hdr.ppu" "${CMAKE_BINARY_DIR}/bin/Data/" COPYONLY) 34 | #CONFIGURE_FILE("${SOURCE_DIR}/src/example/Data/motionblur.ppu" "${CMAKE_BINARY_DIR}/bin/Data/" COPYONLY) 35 | #CONFIGURE_FILE("${SOURCE_DIR}/src/example/Data/bypass.ppu" "${CMAKE_BINARY_DIR}/bin/Data/" COPYONLY) 36 | #CONFIGURE_FILE("${SOURCE_DIR}/src/example/Data/cow.osg" "${CMAKE_BINARY_DIR}/bin/Data/" COPYONLY) 37 | #CONFIGURE_FILE("${SOURCE_DIR}/src/example/Data/cessnafire.osg" "${CMAKE_BINARY_DIR}/bin/Data/" COPYONLY) 38 | #CONFIGURE_FILE("${SOURCE_DIR}/src/example/Data/Images/reflect.rgb" "${CMAKE_BINARY_DIR}/bin/Data/Images/" COPYONLY) 39 | 40 | #CONFIGURE_FILE("${SOURCE_DIR}/src/example/Data/glsl/brightpass_fp.glsl" "${CMAKE_BINARY_DIR}/bin/Data/glsl/" COPYONLY) 41 | #CONFIGURE_FILE("${SOURCE_DIR}/src/example/Data/glsl/bypass_fp.glsl" "${CMAKE_BINARY_DIR}/bin/Data/glsl/" COPYONLY) 42 | #CONFIGURE_FILE("${SOURCE_DIR}/src/example/Data/glsl/depth_of_field_fp.glsl" "${CMAKE_BINARY_DIR}/bin/Data/glsl/" COPYONLY) 43 | #CONFIGURE_FILE("${SOURCE_DIR}/src/example/Data/glsl/gauss_convolution_1Dy_fp.glsl" "${CMAKE_BINARY_DIR}/bin/Data/glsl/" COPYONLY) 44 | #CONFIGURE_FILE("${SOURCE_DIR}/src/example/Data/glsl/gauss_convolution_1Dx_fp.glsl" "${CMAKE_BINARY_DIR}/bin/Data/glsl/" COPYONLY) 45 | #CONFIGURE_FILE("${SOURCE_DIR}/src/example/Data/glsl/gauss_convolution_vp.glsl" "${CMAKE_BINARY_DIR}/bin/Data/glsl/" COPYONLY) 46 | #CONFIGURE_FILE("${SOURCE_DIR}/src/example/Data/glsl/luminance_adapted_fp.glsl" "${CMAKE_BINARY_DIR}/bin/Data/glsl/" COPYONLY) 47 | #CONFIGURE_FILE("${SOURCE_DIR}/src/example/Data/glsl/luminance_fp.glsl" "${CMAKE_BINARY_DIR}/bin/Data/glsl/" COPYONLY) 48 | #CONFIGURE_FILE("${SOURCE_DIR}/src/example/Data/glsl/luminance_mipmap_fp.glsl" "${CMAKE_BINARY_DIR}/bin/Data/glsl/" COPYONLY) 49 | #CONFIGURE_FILE("${SOURCE_DIR}/src/example/Data/glsl/tonemap_hdr_fp.glsl" "${CMAKE_BINARY_DIR}/bin/Data/glsl/" COPYONLY) 50 | 51 | 52 | -------------------------------------------------------------------------------- /src/example/blurScene/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(TARGET_TARGETNAME 2 | ${EXAMPLE_PREFIX}blurscene 3 | ) 4 | 5 | SET(TARGET_SRC 6 | blurScene.cpp 7 | ) 8 | #SET(TARGET_H 9 | # osgteapot.h 10 | #) 11 | 12 | ADD_EXECUTABLE(${TARGET_TARGETNAME} ${TARGET_SRC} ${TARGET_H}) 13 | LINK_INTERNAL(${TARGET_TARGETNAME} osgPPU) 14 | LINK_WITH_VARIABLES(${TARGET_TARGETNAME} 15 | OSGVIEWER_LIBRARY 16 | OSGDB_LIBRARY 17 | OSGGA_LIBRARY 18 | OSGTEXT_LIBRARY 19 | OSGUTIL_LIBRARY 20 | OSG_LIBRARY 21 | OPENTHREADS_LIBRARY 22 | ) 23 | 24 | LINK_EXTERNAL(${TARGET_TARGETNAME} ${OPENGL_LIBRARIES}) 25 | 26 | IF (NOT DYNAMIC_OSGPPU) 27 | LINK_EXTERNAL(${TARGET_TARGETNAME} pthread) 28 | ENDIF(NOT DYNAMIC_OSGPPU) 29 | 30 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES DEBUG_POSTFIX "d") 31 | if(MSVC) 32 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "../") 33 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PROJECT_LABEL "Example ${TARGET_TARGETNAME}") 34 | endif(MSVC) 35 | 36 | -------------------------------------------------------------------------------- /src/example/cubemap/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(TARGET_TARGETNAME 2 | ${EXAMPLE_PREFIX}cubemap 3 | ) 4 | 5 | SET(TARGET_SRC 6 | cubemap.cpp 7 | ) 8 | 9 | ADD_EXECUTABLE(${TARGET_TARGETNAME} ${TARGET_SRC} ${TARGET_H}) 10 | LINK_INTERNAL(${TARGET_TARGETNAME} osgPPU) 11 | LINK_WITH_VARIABLES(${TARGET_TARGETNAME} 12 | OSGVIEWER_LIBRARY 13 | OSGDB_LIBRARY 14 | OSGGA_LIBRARY 15 | OSGTEXT_LIBRARY 16 | OSGUTIL_LIBRARY 17 | OSG_LIBRARY 18 | OPENTHREADS_LIBRARY 19 | ) 20 | 21 | LINK_EXTERNAL(${TARGET_TARGETNAME} ${OPENGL_LIBRARIES}) 22 | 23 | IF (NOT DYNAMIC_OSGPPU) 24 | LINK_EXTERNAL(${TARGET_TARGETNAME} pthread) 25 | ENDIF(NOT DYNAMIC_OSGPPU) 26 | 27 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES DEBUG_POSTFIX "d") 28 | if(MSVC) 29 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "../") 30 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PROJECT_LABEL "Example ${TARGET_TARGETNAME}") 31 | endif(MSVC) 32 | 33 | 34 | #----------------------------------------------- 35 | # Add the file to the install target 36 | #----------------------------------------------- 37 | #INSTALL ( 38 | # FILES 39 | # CMakeLists.txt 40 | # ${TARGET_SRC} 41 | # DESTINATION src/examples/cubemap 42 | # COMPONENT ${PACKAGE_EXAMPLES} 43 | #) 44 | -------------------------------------------------------------------------------- /src/example/cuda/BlurKernelWrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef _BLUR_KERNEL_WRAPPER_ 2 | #define _BLUR_KERNEL_WRAPPER_ 3 | 4 | 5 | #include 6 | #include 7 | 8 | 9 | extern "C" void blurKernelWrapper(float4* in_data, float4* out_data, int width, int height, int radius, float threshold, float highlight); 10 | 11 | 12 | #endif // _CUDA_KERNEL_WRAPPER_ 13 | -------------------------------------------------------------------------------- /src/example/cuda/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #--------------------------------------- 2 | # CUDA Module build for the exmaple 3 | #--------------------------------------- 4 | # Add current directory to the nvcc include line. 5 | CUDA_INCLUDE_DIRECTORIES( 6 | ${OPENGL_INCLUDE_DIR} 7 | ${OSG_INCLUDE_DIRS} 8 | ${SOURCE_DIR}/include 9 | ) 10 | 11 | # Setup the prefix of the generated cuda file 12 | SET(CMAKE_SHARED_MODULE_PREFIX "osgppu_") 13 | 14 | # Setup header files for the cuda library 15 | SET(CUDA_MODULE_HEADERS 16 | Export.h 17 | ) 18 | 19 | # Link cuda code in a library to something else. 20 | SET(CUDA_MODULE_SRC 21 | kernel.cu 22 | ProcessingModule.cpp 23 | Export.h 24 | BlurKernelWrapper.h 25 | osgteapot.h 26 | ) 27 | CUDA_ADD_LIBRARY(cudakernel 28 | ${CUDA_MODULE_SRC} 29 | ) 30 | 31 | # Link with osgPPU 32 | LINK_INTERNAL(cudakernel osgPPU) 33 | 34 | # Link with other libraries 35 | LINK_WITH_VARIABLES(cudakernel 36 | OSG_LIBRARY 37 | OPENTHREADS_LIBRARY 38 | ) 39 | 40 | # Link with OpenGL 41 | LINK_EXTERNAL(cudakernel ${OPENGL_LIBRARIES}) 42 | 43 | 44 | #--------------------------------------- 45 | # Example build 46 | #--------------------------------------- 47 | SET(TARGET_TARGETNAME 48 | ${EXAMPLE_PREFIX}cuda 49 | ) 50 | 51 | SET(TARGET_SRC 52 | cuda.cpp 53 | ) 54 | SET(TARGET_H 55 | osgteapot.h 56 | ) 57 | 58 | 59 | ADD_EXECUTABLE(${TARGET_TARGETNAME} ${TARGET_SRC} ${TARGET_H}) 60 | LINK_INTERNAL(${TARGET_TARGETNAME} osgPPU) 61 | LINK_WITH_VARIABLES(${TARGET_TARGETNAME} 62 | OSGVIEWER_LIBRARY 63 | OSGDB_LIBRARY 64 | OSGGA_LIBRARY 65 | OSGTEXT_LIBRARY 66 | OSGUTIL_LIBRARY 67 | OSG_LIBRARY 68 | OPENTHREADS_LIBRARY 69 | ) 70 | 71 | LINK_EXTERNAL(${TARGET_TARGETNAME} ${OPENGL_LIBRARIES}) 72 | 73 | IF (NOT DYNAMIC_OSGPPU) 74 | LINK_EXTERNAL(${TARGET_TARGETNAME} pthread) 75 | ENDIF(NOT DYNAMIC_OSGPPU) 76 | 77 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES DEBUG_POSTFIX "d") 78 | if(MSVC) 79 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "../") 80 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PROJECT_LABEL "Example ${TARGET_TARGETNAME}") 81 | endif(MSVC) 82 | 83 | #----------------------------------------------- 84 | # Add the file to the install target 85 | #----------------------------------------------- 86 | #INSTALL ( 87 | # FILES 88 | # CMakeLists.txt 89 | # ${TARGET_SRC} 90 | # ${TARGET_H} 91 | # ${CUDA_MODULE_HEADERS} 92 | # ${CUDA_MODULE_SRC} 93 | # DESTINATION src/examples/cuda 94 | # COMPONENT ${PACKAGE_EXAMPLES} 95 | #) 96 | -------------------------------------------------------------------------------- /src/example/cuda/Export.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #ifndef _C_OSGPPU_CUDAKERNEL_EXPORT_H_ 18 | #define _C_OSGPPU_CUDAKERNEL_EXPORT_H_ 19 | 20 | #if defined(_MSC_VER) 21 | #pragma warning( disable : 4244 ) 22 | #pragma warning( disable : 4251 ) 23 | #pragma warning( disable : 4267 ) 24 | #pragma warning( disable : 4275 ) 25 | #pragma warning( disable : 4290 ) 26 | #pragma warning( disable : 4786 ) 27 | #pragma warning( disable : 4305 ) 28 | #pragma warning( disable : 4996 ) 29 | 30 | #endif 31 | 32 | #if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) 33 | # if defined( OSGPPU_CUDAKERNEL_LIBRARY_STATIC ) 34 | # define OSGPPU_EXPORT 35 | # elif defined( cudakernel_EXPORTS ) 36 | # define OSGPPU_CUDAK_EXPORT __declspec(dllexport) 37 | # else 38 | # define OSGPPU_CUDAK_EXPORT __declspec(dllimport) 39 | # endif 40 | #else 41 | # define OSGPPU_CUDAK_EXPORT 42 | #endif 43 | 44 | // set up define for whether member templates are supported by VisualStudio compilers. 45 | #ifdef _MSC_VER 46 | # if (_MSC_VER >= 1300) 47 | # define __STL_MEMBER_TEMPLATES 48 | # endif 49 | #endif //_MSC_VER 50 | 51 | /* Define NULL pointer value */ 52 | 53 | #ifndef NULL 54 | #ifdef __cplusplus 55 | #define NULL 0 56 | #else 57 | #define NULL ((void *)0) 58 | #endif 59 | #endif //NULL 60 | 61 | #endif //_C_OSGPPU_CUDAKERNEL_EXPORT_H_ 62 | -------------------------------------------------------------------------------- /src/example/cuda/kernel.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * Demonstration of an osgPPU Module which using a CUDA-Kernel to blur the input texture. 3 | */ 4 | 5 | #ifndef __KERNEL_H_ 6 | #define __KERNEL_H_ 7 | 8 | #include 9 | 10 | //#define _DEBUG 11 | 12 | //----------------------------------------------------------------------------- 13 | // clamp x to range [a, b] 14 | // GPU code 15 | //----------------------------------------------------------------------------- 16 | __device__ float clamp(float x, float a, float b) 17 | { 18 | return max(a, min(b, x)); 19 | } 20 | 21 | //----------------------------------------------------------------------------- 22 | // get pixel from 2D image, with clamping to border 23 | // GPU code 24 | //----------------------------------------------------------------------------- 25 | __device__ float4 getPixel(float4 *data, int x, int y, int width, int height) 26 | { 27 | x = clamp(x, 0, width-1); 28 | y = clamp(y, 0, height-1); 29 | return data[y*width+x]; 30 | } 31 | 32 | // macros to make indexing shared memory easier 33 | #define SMEM(X, Y) sdata[(Y)*tilew+(X)] 34 | 35 | //----------------------------------------------------------------------------- 36 | // CUDA kernel to do a simple blurring 37 | //----------------------------------------------------------------------------- 38 | __global__ void blurKernel(float4* g_data, float4* g_odata, int imgw, int imgh, int tilew, int r) 39 | { 40 | extern __shared__ float4 sdata[]; 41 | 42 | int tx = threadIdx.x; 43 | int ty = threadIdx.y; 44 | int bw = blockDim.x; 45 | int bh = blockDim.y; 46 | int x = blockIdx.x*bw + tx; 47 | int y = blockIdx.y*bh + ty; 48 | 49 | // copy tile to shared memory 50 | // center region 51 | SMEM(r + tx, r + ty) = getPixel(g_data, x, y, imgw, imgh); 52 | 53 | // borders 54 | if (threadIdx.x < r) { 55 | // left 56 | SMEM(tx, r + ty) = getPixel(g_data, x - r, y, imgw, imgh); 57 | // right 58 | SMEM(r + bw + tx, r + ty) = getPixel(g_data, x + bw, y, imgw, imgh); 59 | } 60 | if (threadIdx.y < r) { 61 | // top 62 | SMEM(r + tx, ty) = getPixel(g_data, x, y - r, imgw, imgh); 63 | // bottom 64 | SMEM(r + tx, r + bh + ty) = getPixel(g_data, x, y + bh, imgw, imgh); 65 | } 66 | 67 | // load corners 68 | if ((threadIdx.x < r) && (threadIdx.y < r)) { 69 | // tl 70 | SMEM(tx, ty) = getPixel(g_data, x - r, y - r, imgw, imgh); 71 | // bl 72 | SMEM(tx, r + bh + ty) = getPixel(g_data, x - r, y + bh, imgw, imgh); 73 | // tr 74 | SMEM(r + bw + tx, ty) = getPixel(g_data, x + bh, y - r, imgw, imgh); 75 | // br 76 | SMEM(r + bw + tx, r + bh + ty) = getPixel(g_data, x + bw, y + bh, imgw, imgh); 77 | } 78 | 79 | // wait for loads to complete 80 | __syncthreads(); 81 | 82 | // perform convolution 83 | float samples = 0.0; 84 | float3 pixelSum = make_float3(0,0,0); 85 | 86 | for(int dy=-r; dy<=r; dy++) { 87 | for(int dx=-r; dx<=r; dx++) { 88 | #if 0 89 | // try this to see the benefit of using shared memory 90 | float4 pixel = getPixel(g_data, x+dx, y+dy, imgw, imgh); 91 | #else 92 | float4 pixel = SMEM(r+tx+dx, r+ty+dy); 93 | #endif 94 | // only sum pixels within disc-shaped kernel 95 | float l = dx*dx + dy*dy; 96 | if (l <= r*r) 97 | { 98 | pixelSum.x += pixel.x; 99 | pixelSum.y += pixel.y; 100 | pixelSum.z += pixel.z; 101 | samples += 1.0; 102 | } 103 | } 104 | } 105 | 106 | // normalize 107 | pixelSum.x /= samples; 108 | pixelSum.y /= samples; 109 | pixelSum.z /= samples; 110 | 111 | g_odata[y*imgw+x] = make_float4(pixelSum.x, pixelSum.y, pixelSum.z, 1.0); 112 | } 113 | 114 | 115 | void blurKernelWrapper(float4* in_data, float4* out_data, int width, int height, int radius) 116 | { 117 | // run CUDA Kernel on the loaded data 118 | 119 | // specifies the number of threads per block (here 16*16*1=256 threads) 120 | dim3 block(16, 16, 1); 121 | 122 | // specifies the number of blocks used 123 | dim3 grid(width/block.x, height/block.y, 1); 124 | 125 | // size of the shared memory (memory used by each block) reflects the size of sampling points around 126 | int sbytes = (block.x+(2*radius))*(block.y+(2*radius)) * sizeof(float4); 127 | 128 | // run kernel with the specified parameters 129 | blurKernel<<< grid, block, sbytes>>>(in_data, out_data, width, height, block.x+(2*radius), radius); 130 | } 131 | 132 | #endif // __KERNEL_H_ 133 | -------------------------------------------------------------------------------- /src/example/diffusion/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(TARGET_TARGETNAME 2 | ${EXAMPLE_PREFIX}diffusion 3 | ) 4 | 5 | SET(TARGET_SRC 6 | diffusion.cpp 7 | ) 8 | 9 | ADD_EXECUTABLE(${TARGET_TARGETNAME} ${TARGET_SRC} ${TARGET_H}) 10 | LINK_INTERNAL(${TARGET_TARGETNAME} osgPPU) 11 | LINK_WITH_VARIABLES(${TARGET_TARGETNAME} 12 | OSGVIEWER_LIBRARY 13 | OSGDB_LIBRARY 14 | OSGGA_LIBRARY 15 | OSGTEXT_LIBRARY 16 | OSGUTIL_LIBRARY 17 | OSG_LIBRARY 18 | OPENTHREADS_LIBRARY 19 | ) 20 | 21 | LINK_EXTERNAL(${TARGET_TARGETNAME} ${OPENGL_LIBRARIES}) 22 | 23 | IF (NOT DYNAMIC_OSGPPU) 24 | LINK_EXTERNAL(${TARGET_TARGETNAME} pthread) 25 | ENDIF(NOT DYNAMIC_OSGPPU) 26 | 27 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES DEBUG_POSTFIX "d") 28 | if(MSVC) 29 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "../") 30 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PROJECT_LABEL "Example ${TARGET_TARGETNAME}") 31 | endif(MSVC) 32 | -------------------------------------------------------------------------------- /src/example/dof/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(TARGET_TARGETNAME 2 | ${EXAMPLE_PREFIX}dof 3 | ) 4 | 5 | SET(TARGET_SRC 6 | dofppu.cpp 7 | ) 8 | SET(TARGET_H 9 | dofppu.h 10 | osgteapot.h 11 | ) 12 | 13 | ADD_EXECUTABLE(${TARGET_TARGETNAME} ${TARGET_SRC} ${TARGET_H}) 14 | LINK_INTERNAL(${TARGET_TARGETNAME} osgPPU) 15 | LINK_WITH_VARIABLES(${TARGET_TARGETNAME} 16 | OSGVIEWER_LIBRARY 17 | OSGDB_LIBRARY 18 | OSGGA_LIBRARY 19 | OSGTEXT_LIBRARY 20 | OSGUTIL_LIBRARY 21 | OSG_LIBRARY 22 | OPENTHREADS_LIBRARY 23 | ) 24 | 25 | LINK_EXTERNAL(${TARGET_TARGETNAME} ${OPENGL_LIBRARIES}) 26 | 27 | IF (NOT DYNAMIC_OSGPPU) 28 | LINK_EXTERNAL(${TARGET_TARGETNAME} pthread) 29 | ENDIF(NOT DYNAMIC_OSGPPU) 30 | 31 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES DEBUG_POSTFIX "d") 32 | if(MSVC) 33 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "../") 34 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PROJECT_LABEL "Example ${TARGET_TARGETNAME}") 35 | endif(MSVC) 36 | 37 | 38 | 39 | #----------------------------------------------- 40 | # Add the file to the install target 41 | #----------------------------------------------- 42 | #INSTALL ( 43 | # FILES 44 | # CMakeLists.txt 45 | # ${TARGET_SRC} 46 | # ${TARGET_H} 47 | # DESTINATION src/examples/dof 48 | # COMPONENT ${PACKAGE_EXAMPLES} 49 | #) 50 | -------------------------------------------------------------------------------- /src/example/glow/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(TARGET_TARGETNAME 2 | ${EXAMPLE_PREFIX}glow 3 | ) 4 | 5 | SET(TARGET_SRC 6 | glow.cpp 7 | ) 8 | 9 | 10 | ADD_EXECUTABLE(${TARGET_TARGETNAME} ${TARGET_SRC} ${TARGET_H}) 11 | LINK_INTERNAL(${TARGET_TARGETNAME} osgPPU) 12 | LINK_WITH_VARIABLES(${TARGET_TARGETNAME} 13 | OSGVIEWER_LIBRARY 14 | OSGDB_LIBRARY 15 | OSGGA_LIBRARY 16 | OSGTEXT_LIBRARY 17 | OSGUTIL_LIBRARY 18 | OSG_LIBRARY 19 | OPENTHREADS_LIBRARY 20 | ) 21 | 22 | LINK_EXTERNAL(${TARGET_TARGETNAME} ${OPENGL_LIBRARIES}) 23 | 24 | IF (NOT DYNAMIC_OSGPPU) 25 | LINK_EXTERNAL(${TARGET_TARGETNAME} pthread) 26 | ENDIF(NOT DYNAMIC_OSGPPU) 27 | 28 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES DEBUG_POSTFIX "d") 29 | if(MSVC) 30 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "../") 31 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PROJECT_LABEL "Example ${TARGET_TARGETNAME}") 32 | endif(MSVC) 33 | 34 | 35 | #----------------------------------------------- 36 | # Add the file to the install target 37 | #----------------------------------------------- 38 | #INSTALL ( 39 | # FILES 40 | # CMakeLists.txt 41 | # ${TARGET_SRC} 42 | # ${TARGET_H} 43 | # DESTINATION src/examples/glow 44 | # COMPONENT ${PACKAGE_EXAMPLES} 45 | #) 46 | -------------------------------------------------------------------------------- /src/example/hdr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(TARGET_TARGETNAME 2 | ${EXAMPLE_PREFIX}hdr 3 | ) 4 | 5 | SET(TARGET_SRC 6 | osgppu.cpp 7 | ) 8 | SET(TARGET_H 9 | hdrppu.h 10 | osgteapot.h 11 | ) 12 | 13 | ADD_EXECUTABLE(${TARGET_TARGETNAME} ${TARGET_SRC} ${TARGET_H}) 14 | LINK_INTERNAL(${TARGET_TARGETNAME} osgPPU) 15 | LINK_WITH_VARIABLES(${TARGET_TARGETNAME} 16 | OSGVIEWER_LIBRARY 17 | OSGDB_LIBRARY 18 | OSGGA_LIBRARY 19 | OSGTEXT_LIBRARY 20 | OSGUTIL_LIBRARY 21 | OSG_LIBRARY 22 | OPENTHREADS_LIBRARY 23 | ) 24 | 25 | LINK_EXTERNAL(${TARGET_TARGETNAME} ${OPENGL_LIBRARIES}) 26 | 27 | IF (NOT DYNAMIC_OSGPPU) 28 | LINK_EXTERNAL(${TARGET_TARGETNAME} pthread) 29 | ENDIF(NOT DYNAMIC_OSGPPU) 30 | 31 | 32 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES DEBUG_POSTFIX "d") 33 | if(MSVC) 34 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "../") 35 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PROJECT_LABEL "Example ${TARGET_TARGETNAME}") 36 | endif(MSVC) 37 | 38 | 39 | #----------------------------------------------- 40 | # Add the file to the install target 41 | #----------------------------------------------- 42 | #INSTALL ( 43 | # FILES 44 | # CMakeLists.txt 45 | # ${TARGET_SRC} 46 | # ${TARGET_H} 47 | # DESTINATION src/examples/hdr 48 | # COMPONENT ${PACKAGE_EXAMPLES} 49 | #) 50 | -------------------------------------------------------------------------------- /src/example/motionblur/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(TARGET_TARGETNAME 2 | ${EXAMPLE_PREFIX}motionblur 3 | ) 4 | 5 | SET(TARGET_SRC 6 | view.cpp 7 | ) 8 | SET(TARGET_H 9 | osgteapot.h 10 | ) 11 | 12 | ADD_EXECUTABLE(${TARGET_TARGETNAME} ${TARGET_SRC} ${TARGET_H}) 13 | LINK_INTERNAL(${TARGET_TARGETNAME} osgPPU) 14 | LINK_WITH_VARIABLES(${TARGET_TARGETNAME} 15 | OSGVIEWER_LIBRARY 16 | OSGDB_LIBRARY 17 | OSGGA_LIBRARY 18 | OSGTEXT_LIBRARY 19 | OSGUTIL_LIBRARY 20 | OSG_LIBRARY 21 | OPENTHREADS_LIBRARY 22 | ) 23 | 24 | LINK_EXTERNAL(${TARGET_TARGETNAME} ${OPENGL_LIBRARIES}) 25 | 26 | IF (NOT DYNAMIC_OSGPPU) 27 | LINK_EXTERNAL(${TARGET_TARGETNAME} pthread) 28 | ENDIF(NOT DYNAMIC_OSGPPU) 29 | 30 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES DEBUG_POSTFIX "d") 31 | if(MSVC) 32 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "../") 33 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PROJECT_LABEL "Example ${TARGET_TARGETNAME}") 34 | endif(MSVC) 35 | 36 | -------------------------------------------------------------------------------- /src/example/ssao/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(TARGET_TARGETNAME 2 | ${EXAMPLE_PREFIX}ssao 3 | ) 4 | 5 | SET(TARGET_H 6 | simple.h 7 | osgteapot.h 8 | ) 9 | 10 | SET(TARGET_SRC 11 | ssao.cpp 12 | ) 13 | 14 | ADD_EXECUTABLE(${TARGET_TARGETNAME} ${TARGET_SRC} ${TARGET_H}) 15 | LINK_INTERNAL(${TARGET_TARGETNAME} osgPPU) 16 | LINK_WITH_VARIABLES(${TARGET_TARGETNAME} 17 | OSGVIEWER_LIBRARY 18 | OSGDB_LIBRARY 19 | OSGGA_LIBRARY 20 | OSGTEXT_LIBRARY 21 | OSGUTIL_LIBRARY 22 | OSG_LIBRARY 23 | OPENTHREADS_LIBRARY 24 | ) 25 | 26 | LINK_EXTERNAL(${TARGET_TARGETNAME} ${OPENGL_LIBRARIES}) 27 | 28 | IF (NOT DYNAMIC_OSGPPU) 29 | LINK_EXTERNAL(${TARGET_TARGETNAME} pthread) 30 | ENDIF(NOT DYNAMIC_OSGPPU) 31 | 32 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES DEBUG_POSTFIX "d") 33 | if(MSVC) 34 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "../") 35 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PROJECT_LABEL "Example ${TARGET_TARGETNAME}") 36 | endif(MSVC) 37 | 38 | 39 | #----------------------------------------------- 40 | # Add the file to the install target 41 | #----------------------------------------------- 42 | #INSTALL ( 43 | # FILES 44 | # CMakeLists.txt 45 | # ${TARGET_SRC} 46 | # ${TARGET_H} 47 | # DESTINATION src/examples/ssao 48 | # COMPONENT ${PACKAGE_EXAMPLES} 49 | #) 50 | -------------------------------------------------------------------------------- /src/example/texture3D/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(TARGET_TARGETNAME 2 | ${EXAMPLE_PREFIX}texture3D 3 | ) 4 | 5 | SET(TARGET_SRC 6 | texture3D.cpp 7 | ) 8 | 9 | ADD_EXECUTABLE(${TARGET_TARGETNAME} ${TARGET_SRC} ${TARGET_H}) 10 | LINK_INTERNAL(${TARGET_TARGETNAME} osgPPU) 11 | LINK_WITH_VARIABLES(${TARGET_TARGETNAME} 12 | OSGVIEWER_LIBRARY 13 | OSGDB_LIBRARY 14 | OSGGA_LIBRARY 15 | OSGTEXT_LIBRARY 16 | OSGUTIL_LIBRARY 17 | OSG_LIBRARY 18 | OPENTHREADS_LIBRARY 19 | ) 20 | 21 | LINK_EXTERNAL(${TARGET_TARGETNAME} ${OPENGL_LIBRARIES}) 22 | 23 | IF (NOT DYNAMIC_OSGPPU) 24 | LINK_EXTERNAL(${TARGET_TARGETNAME} pthread) 25 | ENDIF(NOT DYNAMIC_OSGPPU) 26 | 27 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES DEBUG_POSTFIX "d") 28 | if(MSVC) 29 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "../") 30 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PROJECT_LABEL "Example ${TARGET_TARGETNAME}") 31 | endif(MSVC) 32 | 33 | #----------------------------------------------- 34 | # Add the file to the install target 35 | #----------------------------------------------- 36 | #INSTALL ( 37 | # FILES 38 | # CMakeLists.txt 39 | # ${TARGET_SRC} 40 | # DESTINATION src/examples/texture3D 41 | # COMPONENT ${PACKAGE_EXAMPLES} 42 | #) 43 | -------------------------------------------------------------------------------- /src/example/video/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(TARGET_TARGETNAME 2 | ${EXAMPLE_PREFIX}video 3 | ) 4 | 5 | SET(TARGET_SRC 6 | video.cpp 7 | ) 8 | 9 | ADD_EXECUTABLE(${TARGET_TARGETNAME} ${TARGET_SRC} ${TARGET_H}) 10 | LINK_INTERNAL(${TARGET_TARGETNAME} osgPPU) 11 | LINK_WITH_VARIABLES(${TARGET_TARGETNAME} 12 | OSGVIEWER_LIBRARY 13 | OSGDB_LIBRARY 14 | OSGGA_LIBRARY 15 | OSGTEXT_LIBRARY 16 | OSGUTIL_LIBRARY 17 | OSG_LIBRARY 18 | OPENTHREADS_LIBRARY 19 | ) 20 | 21 | LINK_EXTERNAL(${TARGET_TARGETNAME} ${OPENGL_LIBRARIES}) 22 | 23 | IF (NOT DYNAMIC_OSGPPU) 24 | LINK_EXTERNAL(${TARGET_TARGETNAME} pthread) 25 | ENDIF(NOT DYNAMIC_OSGPPU) 26 | 27 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES DEBUG_POSTFIX "d") 28 | if(MSVC) 29 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "../") 30 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PROJECT_LABEL "Example ${TARGET_TARGETNAME}") 31 | endif(MSVC) 32 | 33 | #----------------------------------------------- 34 | # Add the file to the install target 35 | #----------------------------------------------- 36 | #INSTALL ( 37 | # FILES 38 | # CMakeLists.txt 39 | # ${TARGET_SRC} 40 | # DESTINATION src/examples/video 41 | # COMPONENT ${PACKAGE_EXAMPLES} 42 | #) 43 | -------------------------------------------------------------------------------- /src/example/viewer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(TARGET_TARGETNAME 2 | ${EXAMPLE_PREFIX}viewer 3 | ) 4 | 5 | SET(TARGET_SRC 6 | view.cpp 7 | ) 8 | SET(TARGET_H 9 | osgteapot.h 10 | ) 11 | 12 | ADD_EXECUTABLE(${TARGET_TARGETNAME} ${TARGET_SRC} ${TARGET_H}) 13 | LINK_INTERNAL(${TARGET_TARGETNAME} osgPPU) 14 | LINK_WITH_VARIABLES(${TARGET_TARGETNAME} 15 | OSGVIEWER_LIBRARY 16 | OSGDB_LIBRARY 17 | OSGGA_LIBRARY 18 | OSGTEXT_LIBRARY 19 | OSGUTIL_LIBRARY 20 | OSG_LIBRARY 21 | OPENTHREADS_LIBRARY 22 | ) 23 | 24 | LINK_EXTERNAL(${TARGET_TARGETNAME} ${OPENGL_LIBRARIES}) 25 | 26 | IF (NOT DYNAMIC_OSGPPU) 27 | LINK_EXTERNAL(${TARGET_TARGETNAME} pthread) 28 | ENDIF(NOT DYNAMIC_OSGPPU) 29 | 30 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES DEBUG_POSTFIX "d") 31 | if(MSVC) 32 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "../") 33 | SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PROJECT_LABEL "Example ${TARGET_TARGETNAME}") 34 | endif(MSVC) 35 | 36 | 37 | #----------------------------------------------- 38 | # Add the file to the install target 39 | #----------------------------------------------- 40 | #INSTALL ( 41 | # FILES 42 | # CMakeLists.txt 43 | # ${TARGET_SRC} 44 | # ${TARGET_H} 45 | # DESTINATION src/examples/viewer 46 | # COMPONENT ${PACKAGE_EXAMPLES} 47 | #) 48 | -------------------------------------------------------------------------------- /src/osgPPU/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | IF(DYNAMIC_OSGPPU) 2 | ADD_DEFINITIONS(-DOSGPPU_LIBRARY) 3 | ELSE(DYNAMIC_OSGPPU) 4 | ADD_DEFINITIONS(-DOSGPPU_LIBRARY_STATIC) 5 | ENDIF(DYNAMIC_OSGPPU) 6 | 7 | SET(LIB_NAME ${PROJECT_NAME}) 8 | SET(HEADER_PATH ${osgPPU_SOURCE_DIR}/include/${LIB_NAME}) 9 | 10 | #----------------------------------- 11 | # Setup headers 12 | #----------------------------------- 13 | SET(LIB_PUBLIC_HEADERS 14 | ${HEADER_PATH}/Export.h 15 | ${HEADER_PATH}/UnitText.h 16 | ${HEADER_PATH}/UnitInOut.h 17 | ${HEADER_PATH}/UnitInResampleOut.h 18 | ${HEADER_PATH}/UnitInMipmapOut.h 19 | ${HEADER_PATH}/UnitMipmapInMipmapOut.h 20 | ${HEADER_PATH}/UnitOut.h 21 | ${HEADER_PATH}/UnitOutCapture.h 22 | ${HEADER_PATH}/Processor.h 23 | ${HEADER_PATH}/Unit.h 24 | ${HEADER_PATH}/UnitBypass.h 25 | ${HEADER_PATH}/UnitDepthbufferBypass.h 26 | ${HEADER_PATH}/UnitCameraAttachmentBypass.h 27 | ${HEADER_PATH}/UnitTexture.h 28 | ${HEADER_PATH}/Visitor.h 29 | ${HEADER_PATH}/BarrierNode.h 30 | ${HEADER_PATH}/Utility.h 31 | ${HEADER_PATH}/ColorAttribute.h 32 | ${HEADER_PATH}/ShaderAttribute.h 33 | ${HEADER_PATH}/UnitCamera.h 34 | ${HEADER_PATH}/UnitInHistoryOut.h 35 | ${HEADER_PATH}/UnitInOutModule.h 36 | ${HEADER_PATH}/UnitInOutRepeat.h 37 | ${HEADER_PATH}/Camera.h 38 | ${OSGPPU_CONFIG_HEADER} 39 | ) 40 | 41 | #----------------------------------- 42 | # Setup source files 43 | #----------------------------------- 44 | SET(LIB_SRC_FILES 45 | Unit.cpp 46 | UnitBypass.cpp 47 | UnitDepthbufferBypass.cpp 48 | UnitCameraAttachmentBypass.cpp 49 | UnitTexture.cpp 50 | UnitOut.cpp 51 | UnitOutCapture.cpp 52 | UnitInOut.cpp 53 | UnitText.cpp 54 | UnitInResampleOut.cpp 55 | UnitInMipmapOut.cpp 56 | UnitMipmapInMipmapOut.cpp 57 | Processor.cpp 58 | Visitor.cpp 59 | Utility.cpp 60 | ColorAttribute.cpp 61 | ShaderAttribute.cpp 62 | UnitCamera.cpp 63 | UnitInOutModule.cpp 64 | CMakeLists.txt 65 | UnitInHistoryOut.cpp 66 | UnitInOutRepeat.cpp 67 | Camera.cpp 68 | ) 69 | 70 | 71 | #----------------------------------- 72 | # Create library command, combines headers and sources 73 | #----------------------------------- 74 | ADD_LIBRARY(${LIB_NAME} 75 | ${OSGPPU_USER_DEFINED_DYNAMIC_OR_STATIC} 76 | ${LIB_PUBLIC_HEADERS} 77 | ${LIB_SRC_FILES} 78 | ) 79 | 80 | 81 | #----------------------------------- 82 | # Link other libraries 83 | #----------------------------------- 84 | LINK_WITH_VARIABLES(${LIB_NAME} 85 | OSG_LIBRARY 86 | OSGDB_LIBRARY 87 | OSGTEXT_LIBRARY 88 | OSGUTIL_LIBRARY 89 | OSGVIEWER_LIBRARY 90 | OPENTHREADS_LIBRARY 91 | ) 92 | LINK_EXTERNAL(${LIB_NAME} ${OPENGL_LIBRARIES}) 93 | LINK_CORELIB_DEFAULT(${LIB_NAME}) 94 | 95 | #----------------------------------- 96 | # Some definitions for debug and msvc 97 | #----------------------------------- 98 | SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES DEBUG_POSTFIX "d") 99 | if(MSVC) 100 | SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "../") 101 | SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES IMPORT_PREFIX "../") 102 | endif(MSVC) 103 | 104 | 105 | #----------------------------------- 106 | # Include install module 107 | #----------------------------------- 108 | INCLUDE(ModuleInstall OPTIONAL) 109 | -------------------------------------------------------------------------------- /src/osgPPU/Camera.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2010 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace osgPPU 27 | { 28 | //------------------------------------------------------------------------------ 29 | void Camera::resizeViewport(int x, int y, int width, int height, osg::Camera* camera) 30 | { 31 | // reset viewport 32 | osg::Viewport* vp = new osg::Viewport(x,y,width,height); 33 | camera->setViewport(vp); 34 | 35 | // reset renderer for proper update of the FBO on the next apply 36 | osgViewer::Renderer* renderer = (osgViewer::Renderer*)camera->getRenderer(); 37 | renderer->getSceneView(0)->getRenderStage()->setCameraRequiresSetUp(true); 38 | renderer->getSceneView(0)->getRenderStage()->setFrameBufferObject(NULL); 39 | 40 | // resize texture attachments of the camera 41 | for(osg::Camera::BufferAttachmentMap::iterator it = camera->getBufferAttachmentMap().begin(); it != camera->getBufferAttachmentMap().end(); it++) 42 | { 43 | osg::Texture* texture = it->second._texture.get(); 44 | 45 | if (texture == NULL) continue; 46 | 47 | // if texture type is a 2d texture 48 | if (dynamic_cast(texture) != NULL) 49 | { 50 | // change size 51 | osg::Texture2D* tex = dynamic_cast(texture); 52 | tex->setTextureSize(int(vp->width()), int(vp->height()) ); 53 | tex->dirtyTextureObject(); 54 | } 55 | // if texture type is rectangle 56 | else if (dynamic_cast(texture) != NULL) 57 | { 58 | // change size 59 | osg::TextureRectangle* tex = dynamic_cast(texture); 60 | tex->setTextureSize(int(vp->width()), int(vp->height()) ); 61 | tex->dirtyTextureObject(); 62 | } 63 | // if texture type is a cubemap texture 64 | else if (dynamic_cast(texture) != NULL) 65 | { 66 | // change size 67 | osg::TextureCubeMap* tex = dynamic_cast(texture); 68 | tex->setTextureSize(int(vp->width()), int(vp->height()) ); 69 | tex->dirtyTextureObject(); 70 | } 71 | // if texture type is a 3d texture 72 | else if (dynamic_cast(texture) != NULL) 73 | { 74 | // change size 75 | osg::Texture3D* tex = dynamic_cast(texture); 76 | tex->setTextureSize(int(vp->width()), int(vp->height()), tex->getTextureDepth() ); 77 | tex->dirtyTextureObject(); 78 | } 79 | // if texture type is a 2d array 80 | else if (dynamic_cast(texture) != NULL) 81 | { 82 | // change size 83 | osg::Texture2DArray* tex = dynamic_cast(texture); 84 | tex->setTextureSize(int(vp->width()), int(vp->height()), tex->getTextureDepth() ); 85 | tex->dirtyTextureObject(); 86 | } 87 | // unknown textue 88 | else 89 | { 90 | osg::notify(osg::WARN) << "osgPPU::Camera::resizeViewport() - non-supported texture type specified!" << std::endl; 91 | } 92 | } 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/osgPPU/ColorAttribute.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | namespace osgPPU 21 | { 22 | 23 | //------------------------------------------------------------------------------ 24 | ColorAttribute::ColorAttribute() : 25 | osg::StateAttribute(), 26 | mColor(osg::Vec4(1,1,1,1)), 27 | mTime(0), 28 | mStartTime(0), 29 | mEndTime(0), 30 | mStartColor(osg::Vec4(1,1,1,1)), 31 | mEndColor(osg::Vec4(1,1,1,1)) 32 | { 33 | setUpdateCallback(new UpdateCallback()); 34 | } 35 | 36 | //------------------------------------------------------------------------------ 37 | ColorAttribute::ColorAttribute(const ColorAttribute& bm, const osg::CopyOp& copyop) : 38 | osg::StateAttribute(bm, copyop), 39 | mColor(bm.mColor), 40 | mTime(bm.mTime), 41 | mStartTime(bm.mStartTime), 42 | mEndTime(bm.mEndTime), 43 | mStartColor(bm.mStartColor), 44 | mEndColor(bm.mEndColor) 45 | { 46 | 47 | } 48 | 49 | //------------------------------------------------------------------------------ 50 | ColorAttribute::~ColorAttribute() 51 | { 52 | 53 | } 54 | 55 | //------------------------------------------------------------------------------ 56 | void ColorAttribute::apply(osg::State& state) const 57 | { 58 | glColor4fv(mColor.ptr()); 59 | } 60 | 61 | 62 | //------------------------------------------------------------------------------ 63 | void ColorAttribute::UpdateCallback::operator()(osg::StateAttribute* sa, osg::NodeVisitor* nv) 64 | { 65 | // the given parameter must be of type ColorAttribute 66 | ColorAttribute* bm = dynamic_cast(sa); 67 | 68 | // if given right values and end time is bigger then 0 69 | if (bm && nv && bm->mEndTime > 0.00001) 70 | { 71 | bm->mTime = nv->getFrameStamp()->getReferenceTime(); 72 | 73 | // if current time is passed the start time 74 | if (bm->mStartTime <= bm->mTime && bm->mEndTime > bm->mTime) 75 | { 76 | // compute interpolation factors 77 | float factor = (bm->mTime - bm->mStartTime) / (bm->mEndTime - bm->mStartTime); 78 | 79 | // compute linear interpolated color 80 | bm->mColor = bm->mStartColor * (1.0 - factor) + bm->mEndColor * factor; 81 | } 82 | 83 | // if current time has passed the end time, then just fix the values 84 | if (bm->mEndTime <= bm->mTime) 85 | { 86 | bm->mColor = bm->mEndColor; 87 | } 88 | 89 | // if the end time is specified as 0, then set to start value 90 | if (bm->mEndTime < 0.00001) 91 | { 92 | bm->mColor = bm->mStartColor; 93 | } 94 | 95 | } 96 | } 97 | 98 | }; 99 | -------------------------------------------------------------------------------- /src/osgPPU/Config.in: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | /**************************************************************************** 18 | * THIS FILE IS AUTOGENERATED BY CMAKE. DO NOT EDIT! 19 | ****************************************************************************/ 20 | 21 | /* Changes to the configuration reflected here can be made with ccmake on 22 | * unix or with cmake-gui on windows. Alternatively you can use cmake's -D 23 | * or -P switches to set some configuration values at cmake configuration time. 24 | */ 25 | 26 | #ifndef OSGPPU_CONFIG 27 | #define OSGPPU_CONFIG 1 28 | 29 | #cmakedefine CUDA_FOUND 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/osgPPU/UnitBypass.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | namespace osgPPU 22 | { 23 | 24 | //------------------------------------------------------------------------------ 25 | UnitBypass::UnitBypass() : Unit() 26 | { 27 | } 28 | 29 | //------------------------------------------------------------------------------ 30 | UnitBypass::UnitBypass(const UnitBypass& u, const osg::CopyOp& copyop) : 31 | Unit(u, copyop) 32 | { 33 | 34 | } 35 | 36 | //------------------------------------------------------------------------------ 37 | UnitBypass::~UnitBypass() 38 | { 39 | 40 | } 41 | 42 | //------------------------------------------------------------------------------ 43 | void UnitBypass::setupInputsFromParents() 44 | { 45 | // same as normal unit 46 | Unit::setupInputsFromParents(); 47 | 48 | // now do set the output texture equal to the input 49 | mOutputTex = mInputTex; 50 | } 51 | 52 | }; // end namespace 53 | -------------------------------------------------------------------------------- /src/osgPPU/UnitCamera.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | namespace osgPPU 22 | { 23 | 24 | //------------------------------------------------------------------------------ 25 | UnitCamera::UnitCamera() : UnitBypass() 26 | { 27 | mUseCameraAsChild = false; 28 | } 29 | 30 | //------------------------------------------------------------------------------ 31 | UnitCamera::UnitCamera(const UnitCamera& u, const osg::CopyOp& copyop) : 32 | UnitBypass(u, copyop), 33 | mCamera(u.mCamera), 34 | mUseCameraAsChild(u.mUseCameraAsChild) 35 | { 36 | if (mUseCameraAsChild) addChild(mCamera.get()); 37 | } 38 | 39 | //------------------------------------------------------------------------------ 40 | UnitCamera::~UnitCamera() 41 | { 42 | 43 | } 44 | 45 | //------------------------------------------------------------------------------ 46 | void UnitCamera::setCamera(osg::Camera* camera, bool addAsChild) 47 | { 48 | if (addAsChild) addChild(camera); 49 | mCamera = camera; 50 | mUseCameraAsChild = addAsChild; 51 | } 52 | 53 | }; // end namespace 54 | -------------------------------------------------------------------------------- /src/osgPPU/UnitCameraAttachmentBypass.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | namespace osgPPU 23 | { 24 | 25 | //------------------------------------------------------------------------------ 26 | UnitCameraAttachmentBypass::UnitCameraAttachmentBypass() : UnitBypass() 27 | { 28 | _bufferComponent = osg::Camera::COLOR_BUFFER; 29 | } 30 | 31 | //------------------------------------------------------------------------------ 32 | UnitCameraAttachmentBypass::UnitCameraAttachmentBypass(const UnitCameraAttachmentBypass& u, const osg::CopyOp& copyop) : 33 | UnitBypass(u, copyop), 34 | _bufferComponent(u._bufferComponent) 35 | { 36 | 37 | } 38 | 39 | //------------------------------------------------------------------------------ 40 | UnitCameraAttachmentBypass::~UnitCameraAttachmentBypass() 41 | { 42 | 43 | } 44 | 45 | //------------------------------------------------------------------------------ 46 | void UnitCameraAttachmentBypass::setBufferComponent(osg::Camera::BufferComponent c) 47 | { 48 | _bufferComponent = c; 49 | dirty(); 50 | } 51 | 52 | //------------------------------------------------------------------------------ 53 | void UnitCameraAttachmentBypass::init() 54 | { 55 | UnitBypass::init(); 56 | } 57 | 58 | //------------------------------------------------------------------------------ 59 | void UnitCameraAttachmentBypass::setupInputsFromParents() 60 | { 61 | // scan all parents and look for the processor 62 | Processor* proc = NULL; 63 | UnitCamera* unitCam = NULL; 64 | for (unsigned int i=0; i < getNumParents(); i++) 65 | { 66 | proc = dynamic_cast(getParent(i)); 67 | if (proc) break; 68 | unitCam = dynamic_cast(getParent(i)); 69 | if (unitCam) break; 70 | } 71 | if (proc || unitCam) 72 | { 73 | osg::Camera* camera = NULL; 74 | if (proc) camera = proc->getCamera(); 75 | if (unitCam) camera = unitCam->getCamera(); 76 | if (camera) 77 | { 78 | osg::Camera::BufferAttachmentMap& map = camera->getBufferAttachmentMap(); 79 | osg::Texture* input = map[_bufferComponent]._texture.get(); 80 | 81 | if (!input) 82 | osg::notify(osg::WARN) << "osgPPU::UnitCameraAttachmentBypass::setupInputsFromParents() - parent's camera has no specified buffer attachment" << std::endl; 83 | else 84 | { 85 | // set the input texture 86 | mInputTex.clear(); 87 | mInputTex[0] = input; 88 | noticeChangeInput(); 89 | 90 | // the viewport should be retrieved from the input texture 91 | setInputTextureIndexForViewportReference(0); 92 | mOutputTex = mInputTex; 93 | } 94 | }else 95 | osg::notify(osg::WARN) << "osgPPU::UnitCameraAttachmentBypass::setupInputsFromParents() - no camera found" << std::endl; 96 | 97 | }else 98 | { 99 | osg::notify(osg::WARN) << "osgPPU::UnitCameraAttachmentBypass::setupInputsFromParents() - unit is not a direct child of Processor or UnitCamera" << std::endl; 100 | } 101 | 102 | // setup eventually blocked children 103 | setupBlockedChildren(); 104 | } 105 | 106 | }; // end namespace 107 | -------------------------------------------------------------------------------- /src/osgPPU/UnitDepthbufferBypass.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | namespace osgPPU 22 | { 23 | 24 | //------------------------------------------------------------------------------ 25 | UnitDepthbufferBypass::UnitDepthbufferBypass() : UnitCameraAttachmentBypass() 26 | { 27 | setBufferComponent(osg::Camera::DEPTH_BUFFER); 28 | } 29 | 30 | //------------------------------------------------------------------------------ 31 | UnitDepthbufferBypass::UnitDepthbufferBypass(const UnitDepthbufferBypass& u, const osg::CopyOp& copyop) : 32 | UnitCameraAttachmentBypass(u, copyop) 33 | { 34 | 35 | } 36 | 37 | //------------------------------------------------------------------------------ 38 | UnitDepthbufferBypass::~UnitDepthbufferBypass() 39 | { 40 | 41 | } 42 | 43 | 44 | }; // end namespace 45 | -------------------------------------------------------------------------------- /src/osgPPU/UnitInHistoryOut.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2009 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | namespace osgPPU 21 | { 22 | //------------------------------------------------------------------------------ 23 | UnitInHistoryOut::UnitInHistoryOut(const UnitInHistoryOut& unit, const osg::CopyOp& copyop) : 24 | UnitInOut(unit, copyop), 25 | _historySize(1) 26 | { 27 | setOutputTextureType(UnitInOut::TEXTURE_2D_ARRAY); 28 | } 29 | 30 | //------------------------------------------------------------------------------ 31 | UnitInHistoryOut::UnitInHistoryOut() : UnitInOut() 32 | { 33 | osg::notify(osg::FATAL) << "UnitInHistoryOut is currently not implemented!!!" << std::endl; 34 | } 35 | 36 | //------------------------------------------------------------------------------ 37 | UnitInHistoryOut::~UnitInHistoryOut() 38 | { 39 | 40 | } 41 | 42 | //------------------------------------------------------------------------------ 43 | void UnitInHistoryOut::init() 44 | { 45 | UnitInOut::init(); 46 | 47 | } 48 | 49 | //------------------------------------------------------------------------------ 50 | void UnitInHistoryOut::update() 51 | { 52 | UnitInOut::update(); 53 | 54 | } 55 | 56 | //------------------------------------------------------------------------------ 57 | osg::Texture* UnitInHistoryOut::getOrCreateOutputTexture(int mrt) 58 | { 59 | osg::notify(osg::FATAL) << "UnitInHistoryOut is currently not implemented!!!" << std::endl; 60 | return NULL; 61 | } 62 | 63 | //------------------------------------------------------------------------------ 64 | void UnitInHistoryOut::assignOutputTexture() 65 | { 66 | 67 | } 68 | 69 | 70 | }; // end namespace 71 | -------------------------------------------------------------------------------- /src/osgPPU/UnitInOutModule.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | namespace osgPPU 23 | { 24 | 25 | //------------------------------------------------------------------------- 26 | UnitInOutModule::UnitInOutModule() : UnitInOut(), 27 | _moduleDirty(false) 28 | { 29 | } 30 | 31 | //------------------------------------------------------------------------- 32 | UnitInOutModule::UnitInOutModule(const UnitInOutModule& unit, const osg::CopyOp& copyop) : 33 | UnitInOut(unit, copyop), 34 | _moduleDirty(unit._moduleDirty), 35 | _module(unit._module), 36 | _moduleLib(unit._moduleLib) 37 | { 38 | 39 | } 40 | 41 | //------------------------------------------------------------------------- 42 | UnitInOutModule::~UnitInOutModule() 43 | { 44 | // first remove the module and then close the dynamic library 45 | removeModule(); 46 | _moduleLib = NULL; 47 | } 48 | 49 | //------------------------------------------------------------------------- 50 | bool UnitInOutModule::loadModule(const std::string& moduleFile) 51 | { 52 | _moduleLib = osgDB::DynamicLibrary::loadLibrary(moduleFile); 53 | 54 | if (!_moduleLib.valid()) 55 | { 56 | osg::notify(osg::FATAL) << "osgPPU::UnitInOutModule - cannot load module from " << moduleFile << std::endl; 57 | return false; 58 | } 59 | 60 | // try to find the main process 61 | osgppuInitModule entry = (osgppuInitModule)_moduleLib->getProcAddress(OSGPPU_MODULE_ENTRY_STR); 62 | if (entry == NULL) 63 | { 64 | osg::notify(osg::FATAL) << "osgPPU::UnitInOutModule - no entry point " << OSGPPU_MODULE_ENTRY_STR << " in the module " << moduleFile << " was found" << std::endl; 65 | return false; 66 | } 67 | _moduleFile = moduleFile; 68 | 69 | // call the entry point, so that the module register himself by this unit 70 | return entry(this); 71 | } 72 | 73 | //------------------------------------------------------------------------- 74 | void UnitInOutModule::setModule(Module* module) 75 | { 76 | if (module == NULL) return; 77 | if (module == _module.get()) return; 78 | 79 | _module = module; 80 | if (_module->init() == false) 81 | removeModule(); 82 | _moduleDirty = false; 83 | } 84 | 85 | //------------------------------------------------------------------------- 86 | void UnitInOutModule::removeModule() 87 | { 88 | _module = NULL; 89 | } 90 | 91 | //------------------------------------------------------------------------- 92 | bool UnitInOutModule::noticeBeginRendering(osg::RenderInfo& ri, const osg::Drawable*) 93 | { 94 | if (!_module.get()) return false; 95 | if (_moduleDirty) setModule(_module.get()); 96 | 97 | return _module->beginAndProcess(); 98 | } 99 | 100 | //------------------------------------------------------------------------- 101 | void UnitInOutModule::noticeFinishRendering(osg::RenderInfo& ri, const osg::Drawable*) 102 | { 103 | if (!_module.get()) return; 104 | _module->end(); 105 | } 106 | 107 | 108 | } 109 | 110 | -------------------------------------------------------------------------------- /src/osgPPU/UnitInResampleOut.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | namespace osgPPU 21 | { 22 | //------------------------------------------------------------------------------ 23 | UnitInResampleOut::UnitInResampleOut(const UnitInResampleOut& unit, const osg::CopyOp& copyop) : 24 | UnitInOut(unit, copyop), 25 | mWidthFactor(unit.mWidthFactor), 26 | mHeightFactor(unit.mHeightFactor), 27 | mDirtyFactor(unit.mDirtyFactor) 28 | { 29 | } 30 | 31 | //------------------------------------------------------------------------------ 32 | UnitInResampleOut::UnitInResampleOut() : UnitInOut() 33 | { 34 | // setup default values 35 | mWidthFactor = 1.0; 36 | mHeightFactor = 1.0; 37 | mDirtyFactor = true; 38 | } 39 | 40 | //------------------------------------------------------------------------------ 41 | UnitInResampleOut::~UnitInResampleOut() 42 | { 43 | 44 | } 45 | 46 | //------------------------------------------------------------------------------ 47 | void UnitInResampleOut::setFactorX(float w) 48 | { 49 | mWidthFactor = w; 50 | mDirtyFactor = true; 51 | } 52 | 53 | //------------------------------------------------------------------------------ 54 | void UnitInResampleOut::setFactorY(float h) 55 | { 56 | mHeightFactor = h; 57 | mDirtyFactor = true; 58 | } 59 | 60 | //------------------------------------------------------------------------------ 61 | void UnitInResampleOut::dirty() 62 | { 63 | UnitInOut::dirty(); 64 | mDirtyFactor = true; 65 | } 66 | 67 | //------------------------------------------------------------------------------ 68 | void UnitInResampleOut::init() 69 | { 70 | // do initialize as usual 71 | UnitInOut::init(); 72 | 73 | // if we have to reset the resampling factor 74 | if (mDirtyFactor) 75 | { 76 | mDirtyFactor = false; 77 | float width = (float)mViewport->width(); 78 | float height = (float)mViewport->height(); 79 | 80 | // force new viewport to be used 81 | osg::ref_ptr oldVp = new osg::Viewport(*mViewport); 82 | osg::ref_ptr newVp = new osg::Viewport(oldVp->x(), oldVp->y(), oldVp->width() * mWidthFactor, oldVp->height() * mHeightFactor); 83 | 84 | mViewport = newVp; 85 | assignViewport(); 86 | mViewport = oldVp; 87 | 88 | noticeChangeViewport(newVp); 89 | } 90 | } 91 | 92 | }; // end namespace 93 | -------------------------------------------------------------------------------- /src/osgPPU/UnitOut.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | namespace osgPPU 23 | { 24 | //------------------------------------------------------------------------------ 25 | UnitOut::UnitOut() 26 | { 27 | mDefaultFBO = new osg::FrameBufferObject(); 28 | } 29 | 30 | //------------------------------------------------------------------------------ 31 | UnitOut::UnitOut(const UnitOut& unit, const osg::CopyOp& copyop) : 32 | Unit(unit, copyop), 33 | mDefaultFBO(unit.mDefaultFBO) 34 | { 35 | } 36 | 37 | //------------------------------------------------------------------------------ 38 | UnitOut::~UnitOut() 39 | { 40 | 41 | } 42 | 43 | //------------------------------------------------------------------------------ 44 | void UnitOut::init() 45 | { 46 | // init default 47 | Unit::init(); 48 | 49 | // create a quad geometry 50 | mDrawable = createTexturedQuadDrawable(); 51 | mGeode->removeDrawables(0, mGeode->getNumDrawables()); 52 | mGeode->addDrawable(mDrawable.get()); 53 | } 54 | 55 | //------------------------------------------------------------------------------ 56 | bool UnitOut::noticeBeginRendering (osg::RenderInfo& info, const osg::Drawable* ) 57 | { 58 | pushFrameBufferObject(*info.getState()); 59 | 60 | mDefaultFBO->apply(*info.getState()); 61 | 62 | return true; 63 | } 64 | 65 | //------------------------------------------------------------------------------ 66 | void UnitOut::noticeFinishRendering(osg::RenderInfo& info, const osg::Drawable* ) 67 | { 68 | popFrameBufferObject(*info.getState()); 69 | } 70 | 71 | }; // end namespace 72 | -------------------------------------------------------------------------------- /src/osgPPU/UnitOutCapture.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | namespace osgPPU 27 | { 28 | //------------------------------------------------------------------------------ 29 | // Helper class to have own capture callbacks 30 | //------------------------------------------------------------------------------ 31 | struct CaptureDrawCallback : public osg::Drawable::DrawCallback 32 | { 33 | CaptureDrawCallback(UnitOutCapture* parent) : osg::Drawable::DrawCallback(), _parent(parent) {} 34 | ~CaptureDrawCallback() {} 35 | 36 | void drawImplementation (osg::RenderInfo& ri, const osg::Drawable* dr) const 37 | { 38 | if (_parent->getActive() && ri.getState()) 39 | { 40 | _parent->captureInput(ri.getState()); 41 | } 42 | 43 | if (_parent->getActive() && _parent->getShotOnce()) 44 | _parent->setActive(false); 45 | } 46 | 47 | UnitOutCapture* _parent; 48 | }; 49 | 50 | //------------------------------------------------------------------------------ 51 | UnitOutCapture::UnitOutCapture(const UnitOutCapture& unit, const osg::CopyOp& copyop) : 52 | UnitOut(unit, copyop), 53 | mPath(unit.mPath), 54 | mExtension(unit.mExtension), 55 | mShotOnce(unit.mShotOnce) 56 | { 57 | 58 | } 59 | //------------------------------------------------------------------------------ 60 | UnitOutCapture::UnitOutCapture() : UnitOut() 61 | { 62 | mPath = "."; 63 | mExtension = "png"; 64 | mShotOnce = false; 65 | } 66 | 67 | //------------------------------------------------------------------------------ 68 | UnitOutCapture::~UnitOutCapture() 69 | { 70 | } 71 | 72 | //------------------------------------------------------------------------------ 73 | void UnitOutCapture::init() 74 | { 75 | // init default 76 | Unit::init(); 77 | 78 | // create a quad geometry 79 | mDrawable = createTexturedQuadDrawable(); 80 | mDrawable->setDrawCallback(new CaptureDrawCallback(this)); 81 | mGeode->removeDrawables(0, mGeode->getNumDrawables()); 82 | mGeode->addDrawable(mDrawable.get()); 83 | } 84 | 85 | 86 | //------------------------------------------------------------------------------ 87 | void UnitOutCapture::captureInput(osg::State* state) 88 | { 89 | // for each input texture do 90 | for (unsigned int i=0; i < mInputTex.size(); i++) 91 | { 92 | // create file name (allocate memory big enough to be just safe) 93 | char* filename = (char*)malloc(sizeof(char) * (mPath.length() + mExtension.length() + 32)); 94 | sprintf( filename, "%s/%d_%04d.%s", mPath.c_str(), i, mCaptureNumber[i], mExtension.c_str()); 95 | osg::notify(osg::WARN) << "osgPPU::UnitOutCapture::Capture " << mCaptureNumber[i] << " frame to " << filename << " ..."; 96 | osg::notify(osg::WARN).flush(); 97 | 98 | mCaptureNumber[i]++; 99 | 100 | // input texture 101 | osg::Texture* input = getInputTexture(i); 102 | 103 | // bind input texture, so that we can get image from it 104 | if (input != NULL) 105 | state->applyTextureAttribute(0, input); 106 | 107 | // retrieve texture content 108 | osg::ref_ptr img = new osg::Image(); 109 | img->readImageFromCurrentTexture(state->getContextID(), false, osg::Image::computeFormatDataType(input->getInternalFormat())); 110 | osgDB::ReaderWriter::WriteResult res = osgDB::Registry::instance()->writeImage(*img, filename, NULL); 111 | if (res.success()) 112 | osg::notify(osg::WARN) << " OK" << std::endl; 113 | else 114 | osg::notify(osg::WARN) << " failed! (" << res.message() << ")" << std::endl; 115 | 116 | // release character memory 117 | free(filename); 118 | } 119 | 120 | } 121 | 122 | }; // end namespace 123 | -------------------------------------------------------------------------------- /src/osgPPU/UnitText.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | namespace osgPPU 21 | { 22 | //------------------------------------------------------------------------------ 23 | UnitText::UnitText(const UnitText& unit, const osg::CopyOp& copyop) : 24 | UnitInOut(unit, copyop), 25 | mText(unit.mText), 26 | mSize(unit.mSize) 27 | { 28 | } 29 | 30 | //------------------------------------------------------------------------------ 31 | UnitText::UnitText() : osgPPU::UnitInOut() 32 | { 33 | mSize = 26.0; 34 | 35 | // initialize text 36 | mText = new osgText::Text(); 37 | mText->setFont(); 38 | mText->setColor(osg::Vec4(1,1,1,1)); 39 | mText->setAxisAlignment(osgText::Text::SCREEN); 40 | 41 | // setup some defaults parameters 42 | mText->setLayout(osgText::Text::LEFT_TO_RIGHT); 43 | mText->setCharacterSizeMode(osgText::Text::SCREEN_COORDS); 44 | 45 | // setup stateset so that the text is rendered in unit's renderbin 46 | mText->getOrCreateStateSet()->setRenderBinToInherit(); 47 | } 48 | 49 | //------------------------------------------------------------------------------ 50 | UnitText::~UnitText() 51 | { 52 | 53 | } 54 | 55 | //------------------------------------------------------------------------------ 56 | void UnitText::setText(osgText::Text* text) 57 | { 58 | mText = text; 59 | dirty(); 60 | } 61 | 62 | //------------------------------------------------------------------------------ 63 | void UnitText::init() 64 | { 65 | UnitInOut::init(); 66 | 67 | setOutputTextureMap(getInputTextureMap()); 68 | 69 | //mGeode->removeDrawables(0, mGeode->getNumDrawables()); 70 | //mGeode->addDrawable(mText.get()); 71 | 72 | //mText->setDrawCallback(new Unit::DrawCallback(this)); 73 | 74 | // we take the width 640 as reference width for the size of characters 75 | mText->setCharacterSize(mSize * (float(getViewport()->width()) / 640.0), 1.0); 76 | } 77 | 78 | //------------------------------------------------------------------------------ 79 | bool UnitText::noticeBeginRendering (osg::RenderInfo& ri, const osg::Drawable* dr) 80 | { 81 | UnitInOut::noticeBeginRendering(ri, dr); 82 | 83 | // set matricies used for the unit 84 | ri.getState()->applyProjectionMatrix(sProjectionMatrix.get()); 85 | ri.getState()->applyModelViewMatrix(sModelviewMatrix.get()); 86 | 87 | // notice that we will start rendering soon 88 | if (getBeginDrawCallback()) 89 | (*getBeginDrawCallback())(ri, this); 90 | 91 | mText->draw(ri); 92 | 93 | // notice that we will start rendering soon 94 | if (getEndDrawCallback()) 95 | (*getEndDrawCallback())(ri, this); 96 | 97 | return false; 98 | } 99 | 100 | }; // end namespace 101 | 102 | -------------------------------------------------------------------------------- /src/osgPPU/UnitTexture.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace osgPPU 27 | { 28 | //------------------------------------------------------------------------------ 29 | UnitTexture::UnitTexture() : UnitBypass() 30 | { 31 | } 32 | 33 | //------------------------------------------------------------------------------ 34 | UnitTexture::UnitTexture(const UnitTexture& u, const osg::CopyOp& copyop) : 35 | UnitBypass(u, copyop), 36 | _externTexture(u._externTexture) 37 | { 38 | } 39 | 40 | //------------------------------------------------------------------------------ 41 | UnitTexture::UnitTexture(osg::Texture* tex) 42 | { 43 | setTexture(tex); 44 | } 45 | 46 | //------------------------------------------------------------------------------ 47 | UnitTexture::~UnitTexture() 48 | { 49 | 50 | } 51 | 52 | //------------------------------------------------------------------------------ 53 | void UnitTexture::setupInputsFromParents() 54 | { 55 | mInputTex[0] = _externTexture; 56 | mOutputTex = mInputTex; 57 | } 58 | 59 | 60 | //------------------------------------------------------------------------------ 61 | void UnitTexture::setTexture(osg::Texture* tex) 62 | { 63 | if (tex == getTexture() || tex == NULL) return; 64 | 65 | _externTexture = tex; 66 | dirty(); 67 | 68 | // force texture size, helps if texture was not loaded before 69 | if (!_externTexture->areAllTextureObjectsLoaded() && _externTexture->getImage(0)) 70 | { 71 | osg::Texture1D* tex1D = dynamic_cast(_externTexture.get()); 72 | osg::Texture2D* tex2D = dynamic_cast(_externTexture.get()); 73 | osg::Texture2DArray* tex2DArray = dynamic_cast(_externTexture.get()); 74 | osg::Texture3D* tex3D = dynamic_cast(_externTexture.get()); 75 | osg::TextureCubeMap* texCube = dynamic_cast(_externTexture.get()); 76 | osg::TextureRectangle* texRectangle = dynamic_cast(_externTexture.get()); 77 | 78 | if (tex1D) 79 | { 80 | tex1D->setTextureWidth(_externTexture->getImage(0)->s()); 81 | }else if (tex2D) 82 | { 83 | tex2D->setTextureSize(_externTexture->getImage(0)->s(), _externTexture->getImage(0)->t()); 84 | }else if (tex2DArray) 85 | { 86 | tex2DArray->setTextureSize(_externTexture->getImage(0)->s(), _externTexture->getImage(0)->t(), _externTexture->getImage(0)->r()); 87 | }else if (tex3D) 88 | { 89 | tex3D->setTextureSize(_externTexture->getImage(0)->s(), _externTexture->getImage(0)->t(), _externTexture->getImage(0)->r()); 90 | }else if (texCube) 91 | { 92 | texCube->setTextureSize(_externTexture->getImage(0)->s(), _externTexture->getImage(0)->t()); 93 | }else if (texRectangle) 94 | { 95 | texRectangle->setTextureSize(_externTexture->getImage(0)->s(), _externTexture->getImage(0)->t()); 96 | }else 97 | { 98 | osg::notify(osg::FATAL) << "osgPPU::UnitTexture::setTexture() - " << getName() << " non-supported texture type specified!" << std::endl; 99 | } 100 | } 101 | 102 | // if no viewport, so create it 103 | if (mViewport == NULL) 104 | mViewport = new osg::Viewport(0,0,0,0); 105 | 106 | // change viewport sizes 107 | mViewport->width() = (osg::Viewport::value_type)_externTexture->getTextureWidth(); 108 | mViewport->height() = (osg::Viewport::value_type)_externTexture->getTextureHeight(); 109 | 110 | // just notice that the viewport size has changed 111 | noticeChangeViewport(mViewport); 112 | } 113 | 114 | 115 | }; // end namespace 116 | -------------------------------------------------------------------------------- /src/osgPPU/Utility.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace osgPPU 27 | { 28 | //-------------------------------------------------------------------------- 29 | GLenum createSourceTextureFormat(GLenum internalFormat) 30 | { 31 | switch (internalFormat) 32 | { 33 | case GL_LUMINANCE32F_ARB: 34 | case GL_LUMINANCE16F_ARB: return GL_LUMINANCE; 35 | 36 | case GL_LUMINANCE_ALPHA32F_ARB: 37 | case GL_LUMINANCE_ALPHA16F_ARB: return GL_LUMINANCE_ALPHA; 38 | 39 | case GL_RGB32F_ARB: 40 | case GL_RGB16F_ARB: return GL_RGB; 41 | 42 | case GL_RGBA32F_ARB: 43 | case GL_RGBA16F_ARB: return GL_RGBA; 44 | 45 | case GL_LUMINANCE32UI_EXT: 46 | case GL_LUMINANCE32I_EXT: 47 | case GL_LUMINANCE16UI_EXT: 48 | case GL_LUMINANCE16I_EXT: 49 | case GL_LUMINANCE8UI_EXT: 50 | case GL_LUMINANCE8I_EXT: return GL_LUMINANCE_INTEGER_EXT; 51 | 52 | case GL_LUMINANCE_ALPHA32UI_EXT: 53 | case GL_LUMINANCE_ALPHA32I_EXT: 54 | case GL_LUMINANCE_ALPHA16UI_EXT: 55 | case GL_LUMINANCE_ALPHA16I_EXT: 56 | case GL_LUMINANCE_ALPHA8UI_EXT: 57 | case GL_LUMINANCE_ALPHA8I_EXT: return GL_LUMINANCE_ALPHA_INTEGER_EXT; 58 | 59 | case GL_RGB32UI_EXT: 60 | case GL_RGB32I_EXT: 61 | case GL_RGB16UI_EXT: 62 | case GL_RGB16I_EXT: 63 | case GL_RGB8UI_EXT: 64 | case GL_RGB8I_EXT: return GL_RGB_INTEGER_EXT; 65 | 66 | case GL_RGBA32UI_EXT: 67 | case GL_RGBA32I_EXT: 68 | case GL_RGBA16UI_EXT: 69 | case GL_RGBA16I_EXT: 70 | case GL_RGBA8UI_EXT: 71 | case GL_RGBA8I_EXT: return GL_RGBA_INTEGER_EXT; 72 | 73 | default: return internalFormat; 74 | } 75 | } 76 | 77 | //-------------------------------------------------------------------------- 78 | osg::Uniform::Type convertTextureToUniformType(osg::Texture* tex) 79 | { 80 | 81 | if (dynamic_cast(tex)) return osg::Uniform::SAMPLER_1D; 82 | if (dynamic_cast(tex)) return osg::Uniform::SAMPLER_2D; 83 | if (dynamic_cast(tex)) return osg::Uniform::SAMPLER_3D; 84 | if (dynamic_cast(tex)) return osg::Uniform::SAMPLER_CUBE; 85 | if (dynamic_cast(tex)) return osg::Uniform::SAMPLER_2D; 86 | if (dynamic_cast(tex)) return osg::Uniform::SAMPLER_2D_ARRAY; 87 | 88 | return osg::Uniform::UNDEFINED; 89 | 90 | } 91 | 92 | //-------------------------------------------------------------------------- 93 | unsigned int computeTextureSizeInBytes(osg::Texture* tex) 94 | { 95 | if (tex == NULL) return 0; 96 | 97 | int w = tex->getTextureWidth(); 98 | int h = tex->getTextureHeight(); 99 | int d = tex->getTextureDepth(); 100 | if (d == 0) d = 1; 101 | if (h == 0) h = 1; 102 | 103 | GLint intFormat = tex->getInternalFormat(); 104 | GLenum type = osg::Image::computeFormatDataType(intFormat); 105 | unsigned int rowWidth = osg::Image::computeRowWidthInBytes(w, intFormat, type, 1); 106 | 107 | return rowWidth*h*d; 108 | } 109 | 110 | 111 | }; //end namespace 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /src/osgPlugins/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_SUBDIRECTORY(osgPPU) 2 | 3 | 4 | #INSTALL ( 5 | # FILES 6 | # CMakeLists.txt 7 | # DESTINATION src/osgPlugins 8 | # COMPONENT ${PACKAGE_SRC} 9 | #) 10 | -------------------------------------------------------------------------------- /src/osgPlugins/osgPPU/Base.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2008 Art Tevs * 3 | * * 4 | * This library is free software; you can redistribute it and/or modify * 5 | * it under the terms of the GNU Lesser General Public License as * 6 | * published by the Free Software Foundation; either version 3 of * 7 | * the License, or (at your option) any later version. * 8 | * * 9 | * This library is distributed in the hope that it will be useful, * 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 | * GNU Lesse General Public License for more details. * 13 | * * 14 | * The full license is in LICENSE file included with this distribution. * 15 | ***************************************************************************/ 16 | #ifndef _BASE_H_ 17 | #define _BASE_H_ 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | 30 | //! Read options to store connection between unit and its input 31 | class ListReadOptions : public osgDB::ReaderWriter::Options 32 | { 33 | public: 34 | typedef std::map > List; 35 | typedef std::map > UniformInputMap; 36 | 37 | void setList(const List& l) { mList = l;} 38 | List& getList() { return mList; } 39 | 40 | void setUniformInputMap(const UniformInputMap& l) { mUniformInputMap = l;} 41 | UniformInputMap& getUniformInputMap() { return mUniformInputMap; } 42 | 43 | ListReadOptions() : osgDB::ReaderWriter::Options() 44 | {} 45 | 46 | ~ListReadOptions() 47 | {} 48 | 49 | private: 50 | 51 | List mList; 52 | UniformInputMap mUniformInputMap; 53 | }; 54 | 55 | 56 | extern bool ppu_StateSet_matchModeStr(const char* str,osg::StateAttribute::GLModeValue& mode); 57 | extern const char* ppu_StateSet_getModeStr(osg::StateAttribute::GLModeValue value); 58 | extern bool ppu_Texture_matchInternalFormatStr(const char* str,int& value); 59 | extern const char* ppu_Texture_getInternalFormatStr(int value); 60 | extern bool ppu_Texture_matchOutputTypeStr(const char* str,osgPPU::UnitInOut::TextureType& value); 61 | extern const char* ppu_Texture_getOutputTextureTypeStr(osgPPU::UnitInOut::TextureType value); 62 | 63 | 64 | #endif 65 | 66 | -------------------------------------------------------------------------------- /src/osgPlugins/osgPPU/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | PROJECT(OSG_PLUGINS_MASTER) 2 | 3 | ####################################### 4 | # Plugin prefix 5 | ####################################### 6 | SET(OSG_PLUGIN_PREFIX "") 7 | IF (CYGWIN) 8 | SET(OSG_PLUGIN_PREFIX "cygwin_") 9 | ENDIF(CYGWIN) 10 | IF(MINGW) 11 | SET(OSG_PLUGIN_PREFIX "mingw_") 12 | ENDIF(MINGW) 13 | 14 | 15 | ########################################### 16 | # Settings for plugin 17 | ########################################### 18 | IF(NOT MSVC) 19 | SET(LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH}/${OSG_PLUGINS}") 20 | ENDIF(NOT MSVC) 21 | 22 | IF(MSVC80) 23 | IF(NOT OSG_MSVC_GENERATE_PLUGINS_AND_WRAPPERS_MANIFESTS) 24 | SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /MANIFEST:NO") 25 | ENDIF(NOT OSG_MSVC_GENERATE_PLUGINS_AND_WRAPPERS_MANIFESTS) 26 | ENDIF(MSVC80) 27 | 28 | SET(CMAKE_SHARED_MODULE_PREFIX ${OSG_PLUGIN_PREFIX}) 29 | SET(TARGET_DEFAULT_PREFIX "osgdb_") 30 | SET(TARGET_DEFAULT_LABEL_PREFIX "Plugins") 31 | 32 | 33 | 34 | ########################################### 35 | # Generate plugin 36 | ########################################### 37 | SET(TARGET_SRC 38 | ReaderWriterPPU.cpp 39 | IO_Unit.cpp 40 | Base.cpp 41 | Base.h 42 | ) 43 | 44 | SET(TARGET_ADDED_LIBRARIES 45 | osgPPU 46 | ${OSG_LIBRARY} 47 | ${OSGDB_LIBRARY} 48 | ) 49 | SETUP_PLUGIN(ppu) 50 | 51 | 52 | #----------------------------------------------- 53 | # Add the file to the install target 54 | #----------------------------------------------- 55 | #INSTALL ( 56 | # FILES 57 | # CMakeLists.txt 58 | # ${TARGET_SRC} 59 | # DESTINATION src/osgPlugins/osgPPU 60 | # COMPONENT ${PACKAGE_SRC} 61 | #) 62 | 63 | 64 | 65 | 66 | --------------------------------------------------------------------------------