[brlcad-commits] SF.net SVN: brlcad:[60421] brlcad/branches/openscenegraph
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <sta...@us...> - 2014-04-10 19:42:46
|
Revision: 60421 http://sourceforge.net/p/brlcad/code/60421 Author: starseeker Date: 2014-04-10 19:42:39 +0000 (Thu, 10 Apr 2014) Log Message: ----------- Got the glfw version of this to interactively update - had forgotten the code to free the context for writing by other threads. Will try to do this with osgViewer, if possible, to avoid needing to keep glfw, but definitely checkpoint this working state for reference. Modified Paths: -------------- brlcad/branches/openscenegraph/INSTALL brlcad/branches/openscenegraph/configure brlcad/branches/openscenegraph/misc/CMake/BRLCAD_CMakeFiles.cmake brlcad/branches/openscenegraph/misc/CMake/FindX11.cmake brlcad/branches/openscenegraph/src/libdm/dm-osg.cpp brlcad/branches/openscenegraph/src/libfb/CMakeLists.txt brlcad/branches/openscenegraph/src/libfb/if_osg.cpp brlcad/branches/openscenegraph/src/other/CMakeLists.txt Added Paths: ----------- brlcad/branches/openscenegraph/src/other/glfw/ brlcad/branches/openscenegraph/src/other/glfw/CMake/ brlcad/branches/openscenegraph/src/other/glfw/CMake/amd64-mingw32msvc.cmake brlcad/branches/openscenegraph/src/other/glfw/CMake/i586-mingw32msvc.cmake brlcad/branches/openscenegraph/src/other/glfw/CMake/i686-pc-mingw32.cmake brlcad/branches/openscenegraph/src/other/glfw/CMake/i686-w64-mingw32.cmake brlcad/branches/openscenegraph/src/other/glfw/CMake/modules/ brlcad/branches/openscenegraph/src/other/glfw/CMake/modules/FindEGL.cmake brlcad/branches/openscenegraph/src/other/glfw/CMake/modules/FindGLESv1.cmake brlcad/branches/openscenegraph/src/other/glfw/CMake/modules/FindGLESv2.cmake brlcad/branches/openscenegraph/src/other/glfw/CMake/x86_64-w64-mingw32.cmake brlcad/branches/openscenegraph/src/other/glfw/CMakeLists.txt brlcad/branches/openscenegraph/src/other/glfw/COPYING.txt brlcad/branches/openscenegraph/src/other/glfw/README.md brlcad/branches/openscenegraph/src/other/glfw/cmake_uninstall.cmake.in brlcad/branches/openscenegraph/src/other/glfw/deps/ brlcad/branches/openscenegraph/src/other/glfw/deps/EGL/ brlcad/branches/openscenegraph/src/other/glfw/deps/EGL/eglext.h brlcad/branches/openscenegraph/src/other/glfw/deps/GL/ brlcad/branches/openscenegraph/src/other/glfw/deps/GL/glext.h brlcad/branches/openscenegraph/src/other/glfw/deps/GL/glxext.h brlcad/branches/openscenegraph/src/other/glfw/deps/GL/wglext.h brlcad/branches/openscenegraph/src/other/glfw/deps/getopt.c brlcad/branches/openscenegraph/src/other/glfw/deps/getopt.h brlcad/branches/openscenegraph/src/other/glfw/deps/tinycthread.c brlcad/branches/openscenegraph/src/other/glfw/deps/tinycthread.h brlcad/branches/openscenegraph/src/other/glfw/examples/ brlcad/branches/openscenegraph/src/other/glfw/examples/CMakeLists.txt brlcad/branches/openscenegraph/src/other/glfw/examples/boing.c brlcad/branches/openscenegraph/src/other/glfw/examples/gears.c brlcad/branches/openscenegraph/src/other/glfw/examples/heightmap.c brlcad/branches/openscenegraph/src/other/glfw/examples/simple.c brlcad/branches/openscenegraph/src/other/glfw/examples/splitview.c brlcad/branches/openscenegraph/src/other/glfw/examples/wave.c brlcad/branches/openscenegraph/src/other/glfw/include/ brlcad/branches/openscenegraph/src/other/glfw/include/GLFW/ brlcad/branches/openscenegraph/src/other/glfw/include/GLFW/glfw3.h brlcad/branches/openscenegraph/src/other/glfw/include/GLFW/glfw3native.h brlcad/branches/openscenegraph/src/other/glfw/src/ brlcad/branches/openscenegraph/src/other/glfw/src/CMakeLists.txt brlcad/branches/openscenegraph/src/other/glfw/src/clipboard.c brlcad/branches/openscenegraph/src/other/glfw/src/cocoa_clipboard.m brlcad/branches/openscenegraph/src/other/glfw/src/cocoa_gamma.c brlcad/branches/openscenegraph/src/other/glfw/src/cocoa_init.m brlcad/branches/openscenegraph/src/other/glfw/src/cocoa_joystick.m brlcad/branches/openscenegraph/src/other/glfw/src/cocoa_monitor.m brlcad/branches/openscenegraph/src/other/glfw/src/cocoa_platform.h brlcad/branches/openscenegraph/src/other/glfw/src/cocoa_time.c brlcad/branches/openscenegraph/src/other/glfw/src/cocoa_window.m brlcad/branches/openscenegraph/src/other/glfw/src/context.c brlcad/branches/openscenegraph/src/other/glfw/src/egl_context.c brlcad/branches/openscenegraph/src/other/glfw/src/egl_platform.h brlcad/branches/openscenegraph/src/other/glfw/src/gamma.c brlcad/branches/openscenegraph/src/other/glfw/src/glfw3.pc.in brlcad/branches/openscenegraph/src/other/glfw/src/glfwConfig.cmake.in brlcad/branches/openscenegraph/src/other/glfw/src/glfwConfigVersion.cmake.in brlcad/branches/openscenegraph/src/other/glfw/src/glfw_config.h.in brlcad/branches/openscenegraph/src/other/glfw/src/glx_context.c brlcad/branches/openscenegraph/src/other/glfw/src/glx_platform.h brlcad/branches/openscenegraph/src/other/glfw/src/init.c brlcad/branches/openscenegraph/src/other/glfw/src/input.c brlcad/branches/openscenegraph/src/other/glfw/src/internal.h brlcad/branches/openscenegraph/src/other/glfw/src/joystick.c brlcad/branches/openscenegraph/src/other/glfw/src/monitor.c brlcad/branches/openscenegraph/src/other/glfw/src/nsgl_context.m brlcad/branches/openscenegraph/src/other/glfw/src/nsgl_platform.h brlcad/branches/openscenegraph/src/other/glfw/src/time.c brlcad/branches/openscenegraph/src/other/glfw/src/wgl_context.c brlcad/branches/openscenegraph/src/other/glfw/src/wgl_platform.h brlcad/branches/openscenegraph/src/other/glfw/src/win32_clipboard.c brlcad/branches/openscenegraph/src/other/glfw/src/win32_gamma.c brlcad/branches/openscenegraph/src/other/glfw/src/win32_init.c brlcad/branches/openscenegraph/src/other/glfw/src/win32_joystick.c brlcad/branches/openscenegraph/src/other/glfw/src/win32_monitor.c brlcad/branches/openscenegraph/src/other/glfw/src/win32_platform.h brlcad/branches/openscenegraph/src/other/glfw/src/win32_time.c brlcad/branches/openscenegraph/src/other/glfw/src/win32_window.c brlcad/branches/openscenegraph/src/other/glfw/src/window.c brlcad/branches/openscenegraph/src/other/glfw/src/x11_clipboard.c brlcad/branches/openscenegraph/src/other/glfw/src/x11_gamma.c brlcad/branches/openscenegraph/src/other/glfw/src/x11_init.c brlcad/branches/openscenegraph/src/other/glfw/src/x11_joystick.c brlcad/branches/openscenegraph/src/other/glfw/src/x11_monitor.c brlcad/branches/openscenegraph/src/other/glfw/src/x11_platform.h brlcad/branches/openscenegraph/src/other/glfw/src/x11_time.c brlcad/branches/openscenegraph/src/other/glfw/src/x11_unicode.c brlcad/branches/openscenegraph/src/other/glfw/src/x11_window.c brlcad/branches/openscenegraph/src/other/glfw/tests/ brlcad/branches/openscenegraph/src/other/glfw/tests/CMakeLists.txt brlcad/branches/openscenegraph/src/other/glfw/tests/accuracy.c brlcad/branches/openscenegraph/src/other/glfw/tests/clipboard.c brlcad/branches/openscenegraph/src/other/glfw/tests/defaults.c brlcad/branches/openscenegraph/src/other/glfw/tests/events.c brlcad/branches/openscenegraph/src/other/glfw/tests/fsaa.c brlcad/branches/openscenegraph/src/other/glfw/tests/gamma.c brlcad/branches/openscenegraph/src/other/glfw/tests/glfwinfo.c brlcad/branches/openscenegraph/src/other/glfw/tests/iconify.c brlcad/branches/openscenegraph/src/other/glfw/tests/joysticks.c brlcad/branches/openscenegraph/src/other/glfw/tests/modes.c brlcad/branches/openscenegraph/src/other/glfw/tests/peter.c brlcad/branches/openscenegraph/src/other/glfw/tests/reopen.c brlcad/branches/openscenegraph/src/other/glfw/tests/sharing.c brlcad/branches/openscenegraph/src/other/glfw/tests/tearing.c brlcad/branches/openscenegraph/src/other/glfw/tests/threads.c brlcad/branches/openscenegraph/src/other/glfw/tests/title.c brlcad/branches/openscenegraph/src/other/glfw/tests/windows.c Removed Paths: ------------- brlcad/branches/openscenegraph/src/other/glfw/CMake/ brlcad/branches/openscenegraph/src/other/glfw/CMake/amd64-mingw32msvc.cmake brlcad/branches/openscenegraph/src/other/glfw/CMake/i586-mingw32msvc.cmake brlcad/branches/openscenegraph/src/other/glfw/CMake/i686-pc-mingw32.cmake brlcad/branches/openscenegraph/src/other/glfw/CMake/i686-w64-mingw32.cmake brlcad/branches/openscenegraph/src/other/glfw/CMake/modules/ brlcad/branches/openscenegraph/src/other/glfw/CMake/modules/FindEGL.cmake brlcad/branches/openscenegraph/src/other/glfw/CMake/modules/FindGLESv1.cmake brlcad/branches/openscenegraph/src/other/glfw/CMake/modules/FindGLESv2.cmake brlcad/branches/openscenegraph/src/other/glfw/CMake/x86_64-w64-mingw32.cmake brlcad/branches/openscenegraph/src/other/glfw/CMakeLists.txt brlcad/branches/openscenegraph/src/other/glfw/COPYING.txt brlcad/branches/openscenegraph/src/other/glfw/README.md brlcad/branches/openscenegraph/src/other/glfw/cmake_uninstall.cmake.in brlcad/branches/openscenegraph/src/other/glfw/deps/ brlcad/branches/openscenegraph/src/other/glfw/deps/EGL/ brlcad/branches/openscenegraph/src/other/glfw/deps/EGL/eglext.h brlcad/branches/openscenegraph/src/other/glfw/deps/GL/ brlcad/branches/openscenegraph/src/other/glfw/deps/GL/glext.h brlcad/branches/openscenegraph/src/other/glfw/deps/GL/glxext.h brlcad/branches/openscenegraph/src/other/glfw/deps/GL/wglext.h brlcad/branches/openscenegraph/src/other/glfw/deps/getopt.c brlcad/branches/openscenegraph/src/other/glfw/deps/getopt.h brlcad/branches/openscenegraph/src/other/glfw/deps/tinycthread.c brlcad/branches/openscenegraph/src/other/glfw/deps/tinycthread.h brlcad/branches/openscenegraph/src/other/glfw/examples/ brlcad/branches/openscenegraph/src/other/glfw/examples/CMakeLists.txt brlcad/branches/openscenegraph/src/other/glfw/examples/boing.c brlcad/branches/openscenegraph/src/other/glfw/examples/gears.c brlcad/branches/openscenegraph/src/other/glfw/examples/heightmap.c brlcad/branches/openscenegraph/src/other/glfw/examples/simple.c brlcad/branches/openscenegraph/src/other/glfw/examples/splitview.c brlcad/branches/openscenegraph/src/other/glfw/examples/wave.c brlcad/branches/openscenegraph/src/other/glfw/include/ brlcad/branches/openscenegraph/src/other/glfw/include/GLFW/ brlcad/branches/openscenegraph/src/other/glfw/include/GLFW/glfw3.h brlcad/branches/openscenegraph/src/other/glfw/include/GLFW/glfw3native.h brlcad/branches/openscenegraph/src/other/glfw/src/ brlcad/branches/openscenegraph/src/other/glfw/src/CMakeLists.txt brlcad/branches/openscenegraph/src/other/glfw/src/clipboard.c brlcad/branches/openscenegraph/src/other/glfw/src/cocoa_clipboard.m brlcad/branches/openscenegraph/src/other/glfw/src/cocoa_gamma.c brlcad/branches/openscenegraph/src/other/glfw/src/cocoa_init.m brlcad/branches/openscenegraph/src/other/glfw/src/cocoa_joystick.m brlcad/branches/openscenegraph/src/other/glfw/src/cocoa_monitor.m brlcad/branches/openscenegraph/src/other/glfw/src/cocoa_platform.h brlcad/branches/openscenegraph/src/other/glfw/src/cocoa_time.c brlcad/branches/openscenegraph/src/other/glfw/src/cocoa_window.m brlcad/branches/openscenegraph/src/other/glfw/src/context.c brlcad/branches/openscenegraph/src/other/glfw/src/egl_context.c brlcad/branches/openscenegraph/src/other/glfw/src/egl_platform.h brlcad/branches/openscenegraph/src/other/glfw/src/gamma.c brlcad/branches/openscenegraph/src/other/glfw/src/glfw3.pc.in brlcad/branches/openscenegraph/src/other/glfw/src/glfwConfig.cmake.in brlcad/branches/openscenegraph/src/other/glfw/src/glfwConfigVersion.cmake.in brlcad/branches/openscenegraph/src/other/glfw/src/glfw_config.h.in brlcad/branches/openscenegraph/src/other/glfw/src/glx_context.c brlcad/branches/openscenegraph/src/other/glfw/src/glx_platform.h brlcad/branches/openscenegraph/src/other/glfw/src/init.c brlcad/branches/openscenegraph/src/other/glfw/src/input.c brlcad/branches/openscenegraph/src/other/glfw/src/internal.h brlcad/branches/openscenegraph/src/other/glfw/src/joystick.c brlcad/branches/openscenegraph/src/other/glfw/src/monitor.c brlcad/branches/openscenegraph/src/other/glfw/src/nsgl_context.m brlcad/branches/openscenegraph/src/other/glfw/src/nsgl_platform.h brlcad/branches/openscenegraph/src/other/glfw/src/time.c brlcad/branches/openscenegraph/src/other/glfw/src/wgl_context.c brlcad/branches/openscenegraph/src/other/glfw/src/wgl_platform.h brlcad/branches/openscenegraph/src/other/glfw/src/win32_clipboard.c brlcad/branches/openscenegraph/src/other/glfw/src/win32_gamma.c brlcad/branches/openscenegraph/src/other/glfw/src/win32_init.c brlcad/branches/openscenegraph/src/other/glfw/src/win32_joystick.c brlcad/branches/openscenegraph/src/other/glfw/src/win32_monitor.c brlcad/branches/openscenegraph/src/other/glfw/src/win32_platform.h brlcad/branches/openscenegraph/src/other/glfw/src/win32_time.c brlcad/branches/openscenegraph/src/other/glfw/src/win32_window.c brlcad/branches/openscenegraph/src/other/glfw/src/window.c brlcad/branches/openscenegraph/src/other/glfw/src/x11_clipboard.c brlcad/branches/openscenegraph/src/other/glfw/src/x11_gamma.c brlcad/branches/openscenegraph/src/other/glfw/src/x11_init.c brlcad/branches/openscenegraph/src/other/glfw/src/x11_joystick.c brlcad/branches/openscenegraph/src/other/glfw/src/x11_monitor.c brlcad/branches/openscenegraph/src/other/glfw/src/x11_platform.h brlcad/branches/openscenegraph/src/other/glfw/src/x11_time.c brlcad/branches/openscenegraph/src/other/glfw/src/x11_unicode.c brlcad/branches/openscenegraph/src/other/glfw/src/x11_window.c brlcad/branches/openscenegraph/src/other/glfw/tests/ brlcad/branches/openscenegraph/src/other/glfw/tests/CMakeLists.txt brlcad/branches/openscenegraph/src/other/glfw/tests/accuracy.c brlcad/branches/openscenegraph/src/other/glfw/tests/clipboard.c brlcad/branches/openscenegraph/src/other/glfw/tests/defaults.c brlcad/branches/openscenegraph/src/other/glfw/tests/events.c brlcad/branches/openscenegraph/src/other/glfw/tests/fsaa.c brlcad/branches/openscenegraph/src/other/glfw/tests/gamma.c brlcad/branches/openscenegraph/src/other/glfw/tests/glfwinfo.c brlcad/branches/openscenegraph/src/other/glfw/tests/iconify.c brlcad/branches/openscenegraph/src/other/glfw/tests/joysticks.c brlcad/branches/openscenegraph/src/other/glfw/tests/modes.c brlcad/branches/openscenegraph/src/other/glfw/tests/peter.c brlcad/branches/openscenegraph/src/other/glfw/tests/reopen.c brlcad/branches/openscenegraph/src/other/glfw/tests/sharing.c brlcad/branches/openscenegraph/src/other/glfw/tests/tearing.c brlcad/branches/openscenegraph/src/other/glfw/tests/threads.c brlcad/branches/openscenegraph/src/other/glfw/tests/title.c brlcad/branches/openscenegraph/src/other/glfw/tests/windows.c Modified: brlcad/branches/openscenegraph/INSTALL =================================================================== --- brlcad/branches/openscenegraph/INSTALL 2014-04-10 14:34:07 UTC (rev 60420) +++ brlcad/branches/openscenegraph/INSTALL 2014-04-10 19:42:39 UTC (rev 60421) @@ -702,6 +702,16 @@ Aliases: ENABLE_OPENSCENEGRAPH +--- BRLCAD_GLFW --- + +Option for enabling and disabling compilation of the GLFW +libraries provided with BRL-CAD's source code. Default is AUTO, responsive to +the toplevel BRLCAD_BUNDLED_LIBS option and testing first for a system +version if BRLCAD_BUNDLED_LIBS is also AUTO. + +Aliases: ENABLE_OPENSCENEGRAPH + + --- BRLCAD_GDIAM --- Option for enabling and disabling compilation of the libgdiam approximate Modified: brlcad/branches/openscenegraph/configure =================================================================== --- brlcad/branches/openscenegraph/configure 2014-04-10 14:34:07 UTC (rev 60420) +++ brlcad/branches/openscenegraph/configure 2014-04-10 19:42:39 UTC (rev 60421) @@ -190,6 +190,10 @@ shift;; --disable-openscenegraph) options="$options -DBRLCAD_OSG=SYSTEM"; shift;; + --enable-openscenegraph) options="$options -DBRLCAD_GLFW=BUNDLED"; + shift;; + --disable-openscenegraph) options="$options -DBRLCAD_GLFW=SYSTEM"; + shift;; --enable-gdiam) options="$options -DBRLCAD_GDIAM=BUNDLED"; shift;; --disable-gdiam) options="$options -DBRLCAD_GDIAM=SYSTEM"; Modified: brlcad/branches/openscenegraph/misc/CMake/BRLCAD_CMakeFiles.cmake =================================================================== --- brlcad/branches/openscenegraph/misc/CMake/BRLCAD_CMakeFiles.cmake 2014-04-10 14:34:07 UTC (rev 60420) +++ brlcad/branches/openscenegraph/misc/CMake/BRLCAD_CMakeFiles.cmake 2014-04-10 19:42:39 UTC (rev 60421) @@ -65,7 +65,7 @@ # make sure the file is there. Normally attempting to ignore # a non-existent file is a fatal error, but these keywords # don't necessarily refer to files. - set(TARGET_FLAGS SHARED STATIC OBJECT WIN32 UNKNOWN IMPORTED MODULE) + set(TARGET_FLAGS SHARED STATIC OBJECT WIN32 MACOSX_BUNDLE UNKNOWN IMPORTED MODULE) foreach(TARGET_FLAG ${TARGET_FLAGS}) if("${TARGET_FLAG}" STREQUAL "${ITEM}") if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${ITEM}) Modified: brlcad/branches/openscenegraph/misc/CMake/FindX11.cmake =================================================================== --- brlcad/branches/openscenegraph/misc/CMake/FindX11.cmake 2014-04-10 14:34:07 UTC (rev 60420) +++ brlcad/branches/openscenegraph/misc/CMake/FindX11.cmake 2014-04-10 19:42:39 UTC (rev 60421) @@ -257,6 +257,7 @@ X11_FIND_LIB_PATH(Xft Xft) X11_FIND_LIB_PATH(Xi Xi) X11_FIND_LIB_PATH(Xinerama Xinerama) + X11_FIND_LIB_PATH(Xinput Xi) X11_FIND_LIB_PATH(Xpm Xpm) X11_FIND_LIB_PATH(Xrandr Xrandr) X11_FIND_LIB_PATH(Xrender Xrender) Modified: brlcad/branches/openscenegraph/src/libdm/dm-osg.cpp =================================================================== --- brlcad/branches/openscenegraph/src/libdm/dm-osg.cpp 2014-04-10 14:34:07 UTC (rev 60420) +++ brlcad/branches/openscenegraph/src/libdm/dm-osg.cpp 2014-04-10 19:42:39 UTC (rev 60421) @@ -760,7 +760,9 @@ // Although we are not making direct use of osgViewer currently, we need its // initialization to make sure we have all the libraries we need loaded and - // ready. + // ready. TODO Investigate whether GraphicsWindowEmbedded (specifically the version + // that takes osg::GraphicsContext::Traits *traits as an argument) would work + // better than a raw createGraphicsContext. osgViewer::Viewer *viewer = new osgViewer::Viewer(); delete viewer; Modified: brlcad/branches/openscenegraph/src/libfb/CMakeLists.txt =================================================================== --- brlcad/branches/openscenegraph/src/libfb/CMakeLists.txt 2014-04-10 14:34:07 UTC (rev 60420) +++ brlcad/branches/openscenegraph/src/libfb/CMakeLists.txt 2014-04-10 19:42:39 UTC (rev 60421) @@ -11,6 +11,7 @@ ${OPENNURBS_INCLUDE_DIR} ${OPENTHREADS_INCLUDE_DIR} ${OSG_INCLUDE_DIR} + ${GLFW_INCLUDE_DIR} ) BRLCAD_LIB_INCLUDE_DIRS(fb FB_INCLUDE_DIRS "") @@ -42,6 +43,7 @@ set(FBOSGDEFS "-DIF_OSG") set(OSG_LIBRARIES ${OSGVIEWER_LIBRARY} + ${GLFW_LIBRARY} ) set(LINKLIBS ${LINKLIBS} ${OSG_LIBRARIES}) set(fbosg_srcs if_osg.cpp) Modified: brlcad/branches/openscenegraph/src/libfb/if_osg.cpp =================================================================== --- brlcad/branches/openscenegraph/src/libfb/if_osg.cpp 2014-04-10 14:34:07 UTC (rev 60420) +++ brlcad/branches/openscenegraph/src/libfb/if_osg.cpp 2014-04-10 19:42:39 UTC (rev 60421) @@ -1,7 +1,7 @@ -/* I F _ O S G . C P P +/* I F _ O S G . C P P * BRL-CAD * - * Copyright (c) 2004-2014 United States Government as represented by + * Copyright (c) 1989-2014 United States Government as represented by * the U.S. Army Research Laboratory. * * This library is free software; you can redistribute it and/or @@ -21,1343 +21,70 @@ /** @{ */ /** @file if_osg.cpp * - * Frame Buffer Library interface for OpenSceneGraph. + * A OpenSceneGraph Frame Buffer. * - * There are several different Frame Buffer modes supported. Set your - * environment FB_FILE to the appropriate type. - * - * (see the modeflag definitions below). /dev/osg[options] - * - * This code is basically a port of the 4d Framebuffer interface from - * IRIS GL to OpenGL. - * */ /** @} */ #include "common.h" -#ifdef IF_OSG - -#ifdef HAVE_SYS_TYPES_H -# include <sys/types.h> -#endif - -#ifdef HAVE_SYS_SHM_H -# include <sys/ipc.h> -# include <sys/shm.h> -#endif - -#include <string.h> #include <stdlib.h> -#include <ctype.h> -#include <signal.h> -#include <errno.h> +#include <stdio.h> +#include "bu/log.h" +#include "bu/str.h" +#include "fb.h" #include <osg/GraphicsContext> -#include <osg/Timer> - #include <osgViewer/Viewer> -#if defined(_WIN32) -# include <osgViewer/api/Win32/GraphicsWindowWin32> -#else -# include <osgViewer/api/X11/GraphicsWindowX11> -#endif +#include <GLFW/glfw3.h> -#include <osgText/Font> -#include <osgText/Text> - -#ifdef HAVE_UNISTD_H -# include <unistd.h> /* for getpagesize and sysconf */ -#endif - -#ifdef HAVE_SYS_WAIT_H -# include <sys/wait.h> -#endif -#include "tcl.h" -#include "tk.h" -#include "tkPlatDecls.h" -#include "bio.h" - -#include "bu.h" -extern "C" { -#include "fb.h" -} - - -#define CJDEBUG 0 -#define DIRECT_COLOR_VISUAL_ALLOWED 0 - -/* XXX - arbitrary upper bound */ -#define XMAXSCREEN 16383 -#define YMAXSCREEN 16383 - -HIDDEN int osg_nwindows = 0; /* number of open windows */ -HIDDEN XColor osg_color_cell[256]; /* used to set colormap */ - - -/* - * Structure of color map in shared memory region. Has exactly the - * same format as the SGI hardware "gammaramp" map Note that only the - * lower 8 bits are significant. - */ -struct osg_cmap { - short cmr[256]; - short cmg[256]; - short cmb[256]; -}; - - -/* - * This defines the format of the in-memory framebuffer copy. The - * alpha component and reverse order are maintained for compatibility - * with /dev/sgi - */ -struct osg_pixel { - unsigned char blue; - unsigned char green; - unsigned char red; - unsigned char alpha; -}; - - -/* Clipping structure for zoom/pan operations */ -struct osg_clip { - int xpixmin; /* view clipping planes clipped to pixel memory space*/ - int xpixmax; - int ypixmin; - int ypixmax; - int xscrmin; /* view clipping planes */ - int xscrmax; - int yscrmin; - int yscrmax; - double oleft; /* glOrtho parameters */ - double oright; - double otop; - double obottom; - -}; - - -/* - * Per window state information, overflow area. - */ -struct sgiinfo { - short mi_curs_on; - short mi_cmap_flag; /* enabled when there is a non-linear map in memory */ - int mi_shmid; - int mi_memwidth; /* width of scanline in if_mem */ - short mi_xoff; /* X viewport offset, rel. window*/ - short mi_yoff; /* Y viewport offset, rel. window*/ - int mi_pid; /* for multi-cpu check */ - int mi_parent; /* PID of linger-mode process */ - int mi_doublebuffer; /* 0=singlebuffer 1=doublebuffer */ - struct osg_pixel mi_scanline[XMAXSCREEN+1]; /* one scanline */ -}; - - -/* - * Per window state information particular to the OpenGL interface - */ struct osginfo { - osg::ref_ptr<osg::GraphicsContext> graphicsContext; - Display *dispp; /* pointer to X display connection */ - Window wind; /* Window identifier */ - Tcl_Interp *fbinterp; - Tk_Window xtkwin; /* Window identifier */ - int firstTime; - int alive; - long event_mask; /* event types to be received */ - short front_flag; /* front buffer being used (b-mode) */ - short copy_flag; /* pan and zoom copied from backbuffer */ - short soft_cmap_flag; /* use software colormapping */ - int cmap_size; /* hardware colormap size */ - int win_width; /* actual window width */ - int win_height; /* actual window height */ - int vp_width; /* actual viewport width */ - int vp_height; /* actual viewport height */ - struct osg_clip clip; /* current view clipping */ - Window cursor; - Colormap xcmap; /* xstyle color map */ - int use_ext_ctrl; /* for controlling the Ogl graphics engine externally */ + GLFWwindow *glfw; GLuint texture_name; void *texture_data; }; - -#define SGI(ptr) ((struct sgiinfo *)((ptr)->u1.p)) -#define SGIL(ptr) ((ptr)->u1.p) /* left hand side version */ #define OSG(ptr) ((struct osginfo *)((ptr)->u6.p)) -#define OSGL(ptr) ((ptr)->u6.p) /* left hand side version */ -#define if_mem u2.p /* shared memory pointer */ -#define if_cmap u3.p /* color map in shared memory */ -#define CMR(x) ((struct osg_cmap *)((x)->if_cmap))->cmr -#define CMG(x) ((struct osg_cmap *)((x)->if_cmap))->cmg -#define CMB(x) ((struct osg_cmap *)((x)->if_cmap))->cmb -#define if_zoomflag u4.l /* zoom > 1 */ -#define if_mode u5.l /* see MODE_* defines */ -#define MARGIN 4 /* # pixels margin to screen edge */ - -#define CLIP_XTRA 1 - -#define WIN_L (ifp->if_max_width - ifp->if_width - MARGIN) -#define WIN_T (ifp->if_max_height - ifp->if_height - MARGIN) - -/* - * The mode has several independent bits: - * - * SHARED -vs- MALLOC'ed memory for the image - * TRANSIENT -vs- LINGERING windows - * Windowed -vs- Centered Full screen - * Suppress dither -vs- dither - * Double -vs- Single buffered - * DrawPixels -vs- CopyPixels - */ -#define MODE_1MASK (1<<0) -#define MODE_1SHARED (0<<0) /* Use Shared memory */ -#define MODE_1MALLOC (1<<0) /* Use malloc memory */ - -#define MODE_2MASK (1<<1) -#define MODE_2TRANSIENT (0<<1) -#define MODE_2LINGERING (1<<1) /* leave window up after closing*/ - -#define MODE_4MASK (1<<3) -#define MODE_4NORMAL (0<<3) /* dither if it seems necessary */ -#define MODE_4NODITH (1<<3) /* suppress any dithering */ - -#define MODE_7MASK (1<<6) -#define MODE_7NORMAL (0<<6) /* install colormap in hardware if possible*/ -#define MODE_7SWCMAP (1<<6) /* use software colormapping */ - -#define MODE_9MASK (1<<8) -#define MODE_9NORMAL (0<<8) /* doublebuffer if possible */ -#define MODE_9SINGLEBUF (1<<8) /* singlebuffer only */ - -#define MODE_11MASK (1<<10) -#define MODE_11NORMAL (0<<10) /* always draw from mem. to window*/ -#define MODE_11COPY (1<<10) /* keep full image on back buffer */ - -#define MODE_12MASK (1<<11) -#define MODE_12NORMAL (0<<11) -#define MODE_12DELAY_WRITES_TILL_FLUSH (1<<11) -/* and copy current view to front */ -#define MODE_15MASK (1<<14) -#define MODE_15NORMAL (0<<14) -#define MODE_15ZAP (1<<14) /* zap the shared memory segment */ - -HIDDEN struct osg_modeflags { - char c; - long mask; - long value; - const char *help; -} osg_modeflags[] = { - { 'p', MODE_1MASK, MODE_1MALLOC, - "Private memory - else shared" }, - { 'l', MODE_2MASK, MODE_2LINGERING, - "Lingering window" }, - { 't', MODE_2MASK, MODE_2TRANSIENT, - "Transient window" }, - { 'd', MODE_4MASK, MODE_4NODITH, - "Suppress dithering - else dither if not 24-bit buffer" }, - { 'c', MODE_7MASK, MODE_7SWCMAP, - "Perform software colormap - else use hardware colormap if possible" }, - { 's', MODE_9MASK, MODE_9SINGLEBUF, - "Single buffer - else double buffer if possible" }, - { 'b', MODE_11MASK, MODE_11COPY, - "Fast pan and zoom using backbuffer copy - else normal " }, - { 'D', MODE_12DELAY_WRITES_TILL_FLUSH, MODE_12DELAY_WRITES_TILL_FLUSH, - "Don't update screen until fb_flush() is called. (Double buffer sim)" }, - { 'z', MODE_15MASK, MODE_15ZAP, - "Zap (free) shared memory. Can also be done with fbfree command" }, - { '\0', 0, 0, "" } -}; - - -HIDDEN void -sigkid(int UNUSED(pid)) -{ - exit(0); -} - - -/* BACKBUFFER_TO_SCREEN - copy pixels from copy on the backbuffer to - * the front buffer. Do one scanline specified by one_y, or whole - * screen if one_y equals -1. - */ -HIDDEN void -backbuffer_to_screen(register FBIO *ifp, int one_y) -{ - struct osg_clip *clp; - - if (!(OSG(ifp)->front_flag)) { - OSG(ifp)->front_flag = 1; - glDrawBuffer(GL_FRONT); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glPixelZoom((float) ifp->if_xzoom, (float) ifp->if_yzoom); - } - - clp = &(OSG(ifp)->clip); - - if (one_y > clp->ypixmax) { - return; - } else if (one_y < 0) { - /* do whole visible screen */ - - /* Blank out area left of image */ - glColor3b(0, 0, 0); - if (clp->xscrmin < 0) glRecti(clp->xscrmin - CLIP_XTRA, - clp->yscrmin - CLIP_XTRA, - CLIP_XTRA, - clp->yscrmax + CLIP_XTRA); - - /* Blank out area below image */ - if (clp->yscrmin < 0) glRecti(clp->xscrmin - CLIP_XTRA, - clp->yscrmin - CLIP_XTRA, - clp->xscrmax + CLIP_XTRA, - CLIP_XTRA); - - /* We are in copy mode, so we use vp_width rather - * than if_width - */ - /* Blank out area right of image */ - if (clp->xscrmax >= OSG(ifp)->vp_width) glRecti(ifp->if_width - CLIP_XTRA, - clp->yscrmin - CLIP_XTRA, - clp->xscrmax + CLIP_XTRA, - clp->yscrmax + CLIP_XTRA); - - /* Blank out area above image */ - if (clp->yscrmax >= OSG(ifp)->vp_height) glRecti(clp->xscrmin - CLIP_XTRA, - OSG(ifp)->vp_height - CLIP_XTRA, - clp->xscrmax + CLIP_XTRA, - clp->yscrmax + CLIP_XTRA); - - /* copy image from backbuffer */ - glRasterPos2i(clp->xpixmin, clp->ypixmin); - glCopyPixels(SGI(ifp)->mi_xoff + clp->xpixmin, - SGI(ifp)->mi_yoff + clp->ypixmin, - clp->xpixmax - clp->xpixmin +1, - clp->ypixmax - clp->ypixmin +1, - GL_COLOR); - - - } else if (one_y < clp->ypixmin) { - return; - } else { - /* draw one scanline */ - glRasterPos2i(clp->xpixmin, one_y); - glCopyPixels(SGI(ifp)->mi_xoff + clp->xpixmin, - SGI(ifp)->mi_yoff + one_y, - clp->xpixmax - clp->xpixmin +1, - 1, - GL_COLOR); - } -} - - -/* - * Note: unlike sgi_xmit_scanlines, this function updates an arbitrary - * rectangle of the frame buffer - */ -HIDDEN void -osg_xmit_scanlines(register FBIO *ifp, int UNUSED(ybase), int UNUSED(nlines), int UNUSED(xbase), int UNUSED(npix)) -{ -#if 0 - register int y; - register int n; - int sw_cmap; /* !0 => needs software color map */ - struct osg_clip *clp; - - /* Caller is expected to handle attaching context, etc. */ - - clp = &(OSG(ifp)->clip); - - if (OSG(ifp)->soft_cmap_flag && SGI(ifp)->mi_cmap_flag) { - sw_cmap = 1; - } else { - sw_cmap = 0; - } - - if (xbase > clp->xpixmax || ybase > clp->ypixmax) - return; - if (xbase < clp->xpixmin) - xbase = clp->xpixmin; - if (ybase < clp->ypixmin) - ybase = clp->ypixmin; - - if ((xbase + npix -1) > clp->xpixmax) - npix = clp->xpixmax - xbase + 1; - if ((ybase + nlines - 1) > clp->ypixmax) - nlines = clp->ypixmax - ybase + 1; - - if (!OSG(ifp)->use_ext_ctrl) { - if (!OSG(ifp)->copy_flag) { - /* - * Blank out areas of the screen around the image, if - * exposed. In COPY mode, this is done in - * backbuffer_to_screen(). - */ - - /* Blank out area left of image */ - glColor3b(0, 0, 0); - if (clp->xscrmin < 0) glRecti(clp->xscrmin - CLIP_XTRA, - clp->yscrmin - CLIP_XTRA, - CLIP_XTRA, - clp->yscrmax + CLIP_XTRA); - - /* Blank out area below image */ - if (clp->yscrmin < 0) glRecti(clp->xscrmin - CLIP_XTRA, - clp->yscrmin - CLIP_XTRA, - clp->xscrmax + CLIP_XTRA, - CLIP_XTRA); - - /* Blank out area right of image */ - if (clp->xscrmax >= ifp->if_width) glRecti(ifp->if_width - CLIP_XTRA, - clp->yscrmin - CLIP_XTRA, - clp->xscrmax + CLIP_XTRA, - clp->yscrmax + CLIP_XTRA); - - /* Blank out area above image */ - if (clp->yscrmax >= ifp->if_height) glRecti(clp->xscrmin - CLIP_XTRA, - ifp->if_height- CLIP_XTRA, - clp->xscrmax + CLIP_XTRA, - clp->yscrmax + CLIP_XTRA); - - } else if (OSG(ifp)->front_flag) { - /* in COPY mode, always draw full sized image into backbuffer. - * backbuffer_to_screen() is used to update the front buffer - */ - glDrawBuffer(GL_BACK); - OSG(ifp)->front_flag = 0; - glMatrixMode(GL_PROJECTION); - glPushMatrix(); /* store current view clipping matrix*/ - glLoadIdentity(); - glOrtho(-0.25, ((GLdouble) OSG(ifp)->vp_width)-0.25, - -0.25, ((GLdouble) OSG(ifp)->vp_height)-0.25, - -1.0, 1.0); - glPixelZoom(1.0, 1.0); - } - } - - if (sw_cmap) { - /* Software colormap each line as it's transmitted */ - register int x; - register struct osg_pixel *osgp; - register struct osg_pixel *op; - - y = ybase; - if (CJDEBUG) printf("Doing sw colormap xmit\n"); - /* Perform software color mapping into temp scanline */ - op = SGI(ifp)->mi_scanline; - for (n=nlines; n>0; n--, y++) { - osgp = (struct osg_pixel *)&ifp->if_mem[ - (y*SGI(ifp)->mi_memwidth)* - sizeof(struct osg_pixel) ]; - for (x=xbase+npix-1; x>=xbase; x--) { - op[x].red = CMR(ifp)[osgp[x].red]; - op[x].green = CMG(ifp)[osgp[x].green]; - op[x].blue = CMB(ifp)[osgp[x].blue]; - } - - glPixelStorei(GL_UNPACK_SKIP_PIXELS, xbase); - glRasterPos2i(xbase, y); - glDrawPixels(npix, 1, GL_BGRA_EXT, GL_UNSIGNED_BYTE, - (const GLvoid *) op); - - } - - } else { - /* No need for software colormapping */ - - glPixelStorei(GL_UNPACK_ROW_LENGTH, SGI(ifp)->mi_memwidth); - glPixelStorei(GL_UNPACK_SKIP_PIXELS, xbase); - glPixelStorei(GL_UNPACK_SKIP_ROWS, ybase); - - glRasterPos2i(xbase, ybase); - glDrawPixels(npix, nlines, GL_BGRA_EXT, GL_UNSIGNED_BYTE, - (const GLvoid *) ifp->if_mem); - } -#endif - - glBindTexture(GL_TEXTURE_2D, OSG(ifp)->texture_name); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, ifp->if_width, ifp->if_height, GL_RGB, GL_UNSIGNED_BYTE, OSG(ifp)->texture_data); - - glBegin(GL_TRIANGLE_STRIP); - - glTexCoord2d(0, 0); - glVertex3f(0, 0, 0); - glTexCoord2d(0, 1); - glVertex3f(0, ifp->if_height, 0); - glTexCoord2d(1, 0); - glVertex3f(ifp->if_width, -1, 0); - glTexCoord2d(1, 1); - glVertex3f(ifp->if_width, ifp->if_height, 0); - - glEnd(); - - -} - - -HIDDEN void -osg_cminit(register FBIO *ifp) -{ - register int i; - - for (i = 0; i < 256; i++) { - CMR(ifp)[i] = i; - CMG(ifp)[i] = i; - CMB(ifp)[i] = i; - } -} - - -/************************************************************************/ -/******************* Shared Memory Support ******************************/ -/************************************************************************/ - -/** - * not changed from sgi_getmem. - * - * Because there is no hardware zoom or pan, we need to repaint the - * screen (with big pixels) to implement these operations. This means - * that the actual "contents" of the frame buffer need to be stored - * somewhere else. If possible, we allocate a shared memory segment - * to contain that image. This has several advantages, the most - * important being that when operating the display in 12-bit output - * mode, pixel-readbacks still give the full 24-bits of color. System - * V shared memory persists until explicitly killed, so this also - * means that in MEX mode, the previous contents of the frame buffer - * still exist, and can be again accessed, even though the MEX windows - * are transient, per-process. - * - * There are a few oddities, however. The worst is that System V will - * not allow the break (see sbrk(2)) to be set above a shared memory - * segment, and shmat(2) does not seem to allow the selection of any - * reasonable memory address (like 6 Mbytes up) for the shared memory. - * In the initial version of this routine, that prevented subsequent - * calls to malloc() from succeeding, quite a drawback. The - * work-around used here is to increase the current break to a large - * value, attach to the shared memory, and then return the break to - * its original value. This should allow most reasonable requests for - * memory to be satisfied. In special cases, the values used here - * might need to be increased. - */ HIDDEN int -osg_getmem(FBIO *ifp) +osg_open(FBIO *ifp, const char *UNUSED(file), int width, int height) { -#define SHMEM_KEY 42 - int pixsize; - int size; -#if defined(HAVE_SYSCONF) && defined(HAVE_SHMDT) && defined(HAVE_SHMCTL) && defined(HAVE_SHMGET) && defined(HAVE_SHMAT) - long psize = sysconf(_SC_PAGESIZE); -#else - long psize = -1; -#endif - int i; - char *sp; - int new_mem = 0; - - errno = 0; - - if ((ifp->if_mode & MODE_1MASK) == MODE_1MALLOC || psize == -1) { - /* - * In this mode, only malloc as much memory as is needed. - */ - SGI(ifp)->mi_memwidth = ifp->if_width; - pixsize = ifp->if_height * ifp->if_width * sizeof(struct osg_pixel); - size = pixsize + sizeof(struct osg_cmap); - - sp = (char *)calloc(1, size); - if (sp == 0) { - fb_log("osg_getmem: frame buffer memory malloc failed\n"); - goto fail; - } - new_mem = 1; - goto success; - } - -#if defined(HAVE_SYSCONF) && defined(HAVE_SHMDT) && defined(HAVE_SHMCTL) && defined(HAVE_SHMGET) && defined(HAVE_SHMAT) - /* The shared memory section never changes size */ - SGI(ifp)->mi_memwidth = ifp->if_max_width; - - /* - * On some platforms lrectwrite() runs off the end! So, provide a - * pad area of 2 scanlines. (1 line is enough, but this avoids - * risk of damage to colormap table.) - */ - pixsize = (ifp->if_max_height+2) * ifp->if_max_width * - sizeof(struct osg_pixel); - - size = pixsize + sizeof(struct osg_cmap); - - /* make more portable - size = (size + getpagesize()-1) & ~(getpagesize()-1); - */ - size = (size + psize - 1) & ~(psize - 1); - - /* First try to attach to an existing one */ - if ((SGI(ifp)->mi_shmid = shmget(SHMEM_KEY, size, 0)) < 0) { - /* No existing one, create a new one */ - if ((SGI(ifp)->mi_shmid = shmget( - SHMEM_KEY, size, IPC_CREAT|0666)) < 0) { - fb_log("osg_getmem: shmget failed, errno=%d\n", errno); - goto fail; - } - new_mem = 1; - } - - /* WWW this is unnecessary in this version? */ - /* Open the segment Read/Write */ - /* This gets mapped to a high address on some platforms, so no problem. */ - if ((sp = (char *)shmat(SGI(ifp)->mi_shmid, 0, 0)) == (char *)(-1L)) { - fb_log("osg_getmem: shmat returned x%x, errno=%d\n", sp, errno); - goto fail; - } -#endif - -success: - ifp->if_mem = sp; - ifp->if_cmap = sp + pixsize; /* cmap at end of area */ - i = CMB(ifp)[255]; /* try to deref last word */ - CMB(ifp)[255] = i; - - /* Provide non-black colormap on creation of new shared mem */ - if (new_mem) - osg_cminit(ifp); - return 0; -fail: - fb_log("osg_getmem: Unable to attach to shared memory.\n"); - if ((sp = (char *)calloc(1, size)) == NULL) { - fb_log("osg_getmem: malloc failure\n"); - return -1; - } - new_mem = 1; - goto success; -} - - -void -osg_zapmem(void) -{ -#if defined(HAVE_SYSCONF) && defined(HAVE_SHMDT) && defined(HAVE_SHMCTL) && defined(HAVE_SHMGET) && defined(HAVE_SHMAT) - int i; - int shmid; - if ((shmid = shmget(SHMEM_KEY, 0, 0)) < 0) { - fb_log("osg_zapmem shmget failed, errno=%d\n", errno); - return; - } - - i = shmctl(shmid, IPC_RMID, 0); - if (i < 0) { - fb_log("osg_zapmem shmctl failed, errno=%d\n", errno); - return; - } -#endif - fb_log("if_osg: shared memory released\n"); -} - - -/** - * Given:- the size of the viewport in pixels (vp_width, vp_height) - * - the size of the framebuffer image (if_width, if_height) - * - the current view center (if_xcenter, if_ycenter) - * - the current zoom (if_xzoom, if_yzoom) - * Calculate: - * - the position of the viewport in image space - * (xscrmin, xscrmax, yscrmin, yscrmax) - * - the portion of the image which is visible in the viewport - * (xpixmin, xpixmax, ypixmin, ypixmax) - */ -void -osg_clipper(register FBIO *ifp) -{ - register struct osg_clip *clp; - register int i; - double pixels; - - clp = &(OSG(ifp)->clip); - - i = OSG(ifp)->vp_width/(2*ifp->if_xzoom); - clp->xscrmin = ifp->if_xcenter - i; - i = OSG(ifp)->vp_width/ifp->if_xzoom; - clp->xscrmax = clp->xscrmin + i; - pixels = (double) i; - clp->oleft = ((double) clp->xscrmin) - 0.25*pixels/((double) OSG(ifp)->vp_width); - clp->oright = clp->oleft + pixels; - - i = OSG(ifp)->vp_height/(2*ifp->if_yzoom); - clp->yscrmin = ifp->if_ycenter - i; - i = OSG(ifp)->vp_height/ifp->if_yzoom; - clp->yscrmax = clp->yscrmin + i; - pixels = (double) i; - clp->obottom = ((double) clp->yscrmin) - 0.25*pixels/((double) OSG(ifp)->vp_height); - clp->otop = clp->obottom + pixels; - - clp->xpixmin = clp->xscrmin; - clp->xpixmax = clp->xscrmax; - clp->ypixmin = clp->yscrmin; - clp->ypixmax = clp->yscrmax; - - if (clp->xpixmin < 0) { - clp->xpixmin = 0; - } - - if (clp->ypixmin < 0) { - clp->ypixmin = 0; - } - - /* In copy mode, the backbuffer copy image is limited - * to the viewport size; use that for clipping. - * Otherwise, use size of framebuffer memory segment - */ - if (OSG(ifp)->copy_flag) { - if (clp->xpixmax > OSG(ifp)->vp_width-1) { - clp->xpixmax = OSG(ifp)->vp_width-1; - } - if (clp->ypixmax > OSG(ifp)->vp_height-1) { - clp->ypixmax = OSG(ifp)->vp_height-1; - } - } else { - if (clp->xpixmax > ifp->if_width-1) { - clp->xpixmax = ifp->if_width-1; - } - if (clp->ypixmax > ifp->if_height-1) { - clp->ypixmax = ifp->if_height-1; - } - } - -} - - -HIDDEN void -expose_callback(FBIO *ifp) -{ - struct osg_clip *clp; - - if (CJDEBUG) fb_log("entering expose_callback()\n"); - OSG(ifp)->graphicsContext->makeCurrent(); - if (OSG(ifp)->firstTime) { - - OSG(ifp)->firstTime = 0; - - /* just in case the configuration is double buffered but - * we want to pretend it's not - */ - - if (!SGI(ifp)->mi_doublebuffer) { - glDrawBuffer(GL_FRONT_AND_BACK); - } - - if ((ifp->if_mode & MODE_4MASK) == MODE_4NODITH) { - glDisable(GL_DITHER); - } - - /* set copy mode if possible and requested */ - if (SGI(ifp)->mi_doublebuffer && - ((ifp->if_mode & MODE_11MASK)==MODE_11COPY)) { - /* Copy mode only works if there are two - * buffers to use. It conflicts with - * double buffering - */ - OSG(ifp)->copy_flag = 1; - SGI(ifp)->mi_doublebuffer = 0; - OSG(ifp)->front_flag = 1; - glDrawBuffer(GL_FRONT); - } else { - OSG(ifp)->copy_flag = 0; - } - - OSG(ifp)->win_width = Tk_Width(OSG(ifp)->xtkwin); - OSG(ifp)->win_height = Tk_Height(OSG(ifp)->xtkwin); - - /* clear entire window */ - glViewport(0, 0, OSG(ifp)->win_width, OSG(ifp)->win_height); - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT); - - /* Set normal viewport size to minimum of actual window - * size and requested framebuffer size - */ - OSG(ifp)->vp_width = (OSG(ifp)->win_width < ifp->if_width) ? - OSG(ifp)->win_width : ifp->if_width; - OSG(ifp)->vp_height = (OSG(ifp)->win_height < ifp->if_height) ? - OSG(ifp)->win_height : ifp->if_height; - ifp->if_xcenter = OSG(ifp)->vp_width/2; - ifp->if_ycenter = OSG(ifp)->vp_height/2; - - /* center viewport in window */ - SGI(ifp)->mi_xoff=(OSG(ifp)->win_width-OSG(ifp)->vp_width)/2; - SGI(ifp)->mi_yoff=(OSG(ifp)->win_height-OSG(ifp)->vp_height)/2; - glViewport(SGI(ifp)->mi_xoff, - SGI(ifp)->mi_yoff, - OSG(ifp)->vp_width, - OSG(ifp)->vp_height); - /* initialize clipping planes and zoom */ - osg_clipper(ifp); - clp = &(OSG(ifp)->clip); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(clp->oleft, clp->oright, clp->obottom, clp->otop, - -1.0, 1.0); - glPixelZoom((float) ifp->if_xzoom, (float) ifp->if_yzoom); - } else if ((OSG(ifp)->win_width > ifp->if_width) || - (OSG(ifp)->win_height > ifp->if_height)) { - /* clear whole buffer if window larger than framebuffer */ - if (OSG(ifp)->copy_flag && !OSG(ifp)->front_flag) { - glDrawBuffer(GL_FRONT); - glViewport(0, 0, OSG(ifp)->win_width, - OSG(ifp)->win_height); - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT); - glDrawBuffer(GL_BACK); - } else { - glViewport(0, 0, OSG(ifp)->win_width, - OSG(ifp)->win_height); - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT); - } - /* center viewport */ - glViewport(SGI(ifp)->mi_xoff, - SGI(ifp)->mi_yoff, - OSG(ifp)->vp_width, - OSG(ifp)->vp_height); - } - - /* repaint entire image */ - osg_xmit_scanlines(ifp, 0, ifp->if_height, 0, ifp->if_width); - - /* unattach context for other threads to use */ - OSG(ifp)->graphicsContext->releaseContext(); -} - - -extern "C" void -osg_configureWindow(FBIO *ifp, int width, int height) -{ - if (width == OSG(ifp)->win_width && - height == OSG(ifp)->win_height) - return; - - ifp->if_width = ifp->if_max_width = width; - ifp->if_height = ifp->if_max_height = height; - - OSG(ifp)->win_width = OSG(ifp)->vp_width = width; - OSG(ifp)->win_height = OSG(ifp)->vp_height = height; - - ifp->if_zoomflag = 0; - ifp->if_xzoom = 1; - ifp->if_yzoom = 1; - ifp->if_xcenter = width/2; - ifp->if_ycenter = height/2; - - osg_getmem(ifp); - osg_clipper(ifp); -} - - -HIDDEN void -osg_do_event(FBIO *ifp) -{ - Tcl_DoOneEvent(TCL_ALL_EVENTS|TCL_DONT_WAIT); - - if (BU_STR_EQUAL(Tcl_GetVar(OSG(ifp)->fbinterp, "WM_DELETE_WINDOW", 0), "1")) { - OSG(ifp)->alive = 0; - printf("Close Window event\n"); - } - -#if 0 - XEvent event; - - while (XCheckWindowEvent(OSG(ifp)->dispp, OSG(ifp)->wind, - OSG(ifp)->event_mask, &event)) { - switch (event.type) { - case Expose: - if (!OSG(ifp)->use_ext_ctrl) - expose_callback(ifp); - break; - case ButtonPress: - { - int button = (int) event.xbutton.button; - if (button == Button1) { - /* Check for single button mouse remap. - * ctrl-1 => 2 - * meta-1 => 3 - * cmdkey => 3 - */ - if (event.xbutton.state & ControlMask) { - button = Button2; - } else if (event.xbutton.state & Mod1Mask) { - button = Button3; - } else if (event.xbutton.state & Mod2Mask) { - button = Button3; - } - } - - switch (button) { - case Button1: - break; - case Button2: - { - int x, y; - register struct osg_pixel *osgp; - - x = event.xbutton.x; - y = ifp->if_height - event.xbutton.y - 1; - - if (x < 0 || y < 0) { - fb_log("No RGB (outside image viewport)\n"); - break; - } - - osgp = (struct osg_pixel *)&ifp->if_mem[ - (y*SGI(ifp)->mi_memwidth)* - sizeof(struct osg_pixel) ]; - - fb_log("At image (%d, %d), real RGB=(%3d %3d %3d)\n", - x, y, (int)osgp[x].red, (int)osgp[x].green, (int)osgp[x].blue); - - break; - } - case Button3: - OSG(ifp)->alive = 0; - break; - default: - fb_log("unhandled mouse event\n"); - break; - } - break; - } - case ConfigureNotify: - { - XConfigureEvent *conf = (XConfigureEvent *)&event; - - if (conf->width == OSG(ifp)->win_width && - conf->height == OSG(ifp)->win_height) - return; - - osg_configureWindow(ifp, conf->width, conf->height); - } - default: - break; - } - } -#endif - if (0 < OSG(ifp)->alive && BU_STR_EQUAL(Tcl_GetVar(OSG(ifp)->fbinterp, "WM_EXPOSE_EVENT", 0), "1")) { - Tcl_SetVar(OSG(ifp)->fbinterp, "WM_EXPOSE_EVENT", "0", 0); - } - expose_callback(ifp); -} - -#if 0 -/** - * Select an appropriate visual, and set flags. - * - * The user requires support for: - * -OpenGL rendering in RGBA mode - * - * The user may desire support for: - * -a single-buffered OpenGL context - * -a double-buffered OpenGL context - * -hardware colormapping (DirectColor) - * - * We first try to satisfy all requirements and desires. If that - * fails, we remove the desires one at a time until we succeed or - * until only requirements are left. If at any stage more than one - * visual meets the current criteria, the visual with the greatest - * depth is chosen. - * - * The following flags are set: - * SGI(ifp)->mi_doublebuffer - * OSG(ifp)->soft_cmap_flag - * - * Return NULL on failure. - */ -HIDDEN XVisualInfo * -fb_osg_choose_visual(FBIO *ifp) -{ - - XVisualInfo *vip, *vibase, *maxvip, _template; -#define NGOOD 200 - int good[NGOOD]; - int num, i, j; - int m_hard_cmap, m_sing_buf, m_doub_buf; - int use, rgba, dbfr; - - m_hard_cmap = ((ifp->if_mode & MODE_7MASK)==MODE_7NORMAL); - m_sing_buf = ((ifp->if_mode & MODE_9MASK)==MODE_9SINGLEBUF); - m_doub_buf = !m_sing_buf; - - memset((void *)&_template, 0, sizeof(XVisualInfo)); - - /* get a list of all visuals on this display */ - vibase = XGetVisualInfo(OSG(ifp)->dispp, 0, &_template, &num); - while (1) { - - /* search for all visuals matching current criteria */ - for (i = 0, j = 0, vip=vibase; i < num; i++, vip++) { - /* requirements */ - glXGetConfig(OSG(ifp)->dispp, vip, GLX_USE_GL, &use); - if (!use) { - continue; - } - glXGetConfig(OSG(ifp)->dispp, vip, GLX_RGBA, &rgba); - if (!rgba) { - continue; - } - /* desires */ - /* X_CreateColormap needs a DirectColor visual */ - /* There should be some way of handling this with TrueColor, - * for example: - visual id: 0x50 - class: TrueColor - depth: 24 planes - available colormap entries: 256 per subfield - red, green, blue masks: 0xff0000, 0xff00, 0xff - significant bits in color specification: 8 bits - */ - if ((m_hard_cmap) && (vip->class != DirectColor)) { - continue; - } - if ((m_hard_cmap) && (vip->colormap_size < 256)) { - continue; - } - glXGetConfig(OSG(ifp)->dispp, vip, GLX_DOUBLEBUFFER, &dbfr); - if ((m_doub_buf) && (!dbfr)) { - continue; - } - if ((m_sing_buf) && (dbfr)) { - continue; - } - - /* this visual meets criteria */ - if (j >= NGOOD-1) { - fb_log("fb_osg_open: More than %d candidate visuals!\n", NGOOD); - break; - } - good[j++] = i; - } - - /* from list of acceptable visuals, - * choose the visual with the greatest depth */ - if (j >= 1) { - maxvip = vibase + good[0]; - for (i = 1; i < j; i++) { - vip = vibase + good[i]; - if (vip->depth > maxvip->depth) { - maxvip = vip; - } - } - /* set flags and return choice */ - OSG(ifp)->soft_cmap_flag = !m_hard_cmap; - SGI(ifp)->mi_doublebuffer = m_doub_buf; - return maxvip; - } - - /* if no success at this point, - * relax one of the criteria and try again. - */ - if (m_hard_cmap) { - /* relax hardware colormap requirement */ - m_hard_cmap = 0; - fb_log("fb_osg_open: hardware colormapping not available. Using software colormap.\n"); - } else if (m_sing_buf) { - /* relax single buffering requirement. - * no need for any warning - we'll just use - * the front buffer - */ - m_sing_buf = 0; - } else if (m_doub_buf) { - /* relax double buffering requirement. */ - m_doub_buf = 0; - fb_log("fb_osg_open: double buffering not available. Using single buffer.\n"); - } else { - /* nothing else to relax */ - return NULL; - } - - } - -} -#endif - -/** - * Check for a color map being linear in R, G, and B. Returns 1 for - * linear map, 0 for non-linear map (i.e., non-identity map). - */ -HIDDEN int -is_linear_cmap(register FBIO *ifp) -{ - register int i; - - for (i = 0; i < 256; i++) { - if (CMR(ifp)[i] != i) return 0; - if (CMG(ifp)[i] != i) return 0; - if (CMB(ifp)[i] != i) return 0; - } - return 1; -} - - -HIDDEN int -fb_osg_open(FBIO *ifp, const char *file, int width, int height) -{ - static char title[128]; - int mode; - //int i, direct; - //long valuemask; - //XSetWindowAttributes swa; - FB_CK_FBIO(ifp); - /* - * First, attempt to determine operating mode for this open, - * based upon the "unit number" or flags. - * file = "/dev/osg###" - */ - mode = MODE_2LINGERING; - - if (file != NULL) { - const char *cp; - char modebuf[80]; - char *mp; - int alpha; - struct osg_modeflags *mfp; - - if (bu_strncmp(file, ifp->if_name, strlen(ifp->if_name))) { - /* How did this happen? */ - mode = 0; - } else { - /* Parse the options */ - alpha = 0; - mp = &modebuf[0]; - cp = &file[8]; - while (*cp != '\0' && !isspace((int)(*cp))) { - *mp++ = *cp; /* copy it to buffer */ - if (isdigit((int)(*cp))) { - cp++; - continue; - } - alpha++; - for (mfp = osg_modeflags; mfp->c != '\0'; mfp++) { - if (mfp->c == *cp) { - mode = (mode&~mfp->mask)|mfp->value; - break; - } - } - if (mfp->c == '\0' && *cp != '-') { - fb_log("if_osg: unknown option '%c' ignored\n", *cp); - } - cp++; - } - *mp = '\0'; - if (!alpha) { - mode |= atoi(modebuf); - } - } - - if ((mode & MODE_15MASK) == MODE_15ZAP) { - /* Only task: Attempt to release shared memory segment */ - osg_zapmem(); - return -1; - } - } -#if DIRECT_COLOR_VISUAL_ALLOWED - ifp->if_mode = mode; -#else - ifp->if_mode = mode|MODE_7SWCMAP; -#endif - - /* - * Allocate extension memory sections, - * addressed by SGI(ifp)->mi_xxx and OSG(ifp)->xxx - */ - - if ((SGIL(ifp) = (char *)calloc(1, sizeof(struct sgiinfo))) == NULL) { - fb_log("fb_osg_open: sgiinfo malloc failed\n"); - return -1; - } - if ((OSGL(ifp) = (char *)calloc(1, sizeof(struct osginfo))) == NULL) { + /* Get some memory for the osg specific stuff */ + if ((ifp->u6.p = (char *)calloc(1, sizeof(struct osginfo))) == NULL) { fb_log("fb_osg_open: osginfo malloc failed\n"); return -1; } - SGI(ifp)->mi_shmid = -1; /* indicate no shared memory */ + if (width > 0) + ifp->if_width = width; + if (height > 0) + ifp->if_height = height; - /* the Silicon Graphics Library Window management routines use - * shared memory. This causes lots of problems when you want to - * pass a window structure to a child process. One hack to get - * around this is to immediately fork and create a child process - * and sleep until the child sends a kill signal to the parent - * process. (in FBCLOSE) This allows us to use the traditional fb - * utility programs as well as allow the frame buffer window to - * remain around until killed by the menu subsystem. - */ - -#if defined(HAVE_SYSCONF) && defined(HAVE_SHMDT) && defined(HAVE_SHMCTL) && defined(HAVE_SHMGET) && defined(HAVE_SHMAT) - if ((ifp->if_mode & MODE_2MASK) == MODE_2LINGERING) { - /* save parent pid for later signalling */ - SGI(ifp)->mi_parent = bu_process_id(); - - signal(SIGUSR1, sigkid); - } -#endif - - /* use defaults if invalid width and height specified */ - if (width <= 0) - width = ifp->if_width; - if (height <= 0) - height = ifp->if_height; - /* use max values if width and height are greater */ - if (width > ifp->if_max_width) - width = ifp->if_max_width; - if (height > ifp->if_max_height) - height = ifp->if_max_height; - - ifp->if_width = width; - ifp->if_height = height; - - SGI(ifp)->mi_curs_on = 1; - - /* Build a descriptive window title bar */ - (void)snprintf(title, 128, "BRL-CAD /dev/osg %s, %s", - ((ifp->if_mode & MODE_2MASK) == MODE_2TRANSIENT) ? - "Transient Win": - "Lingering Win", - ((ifp->if_mode & MODE_1MASK) == MODE_1MALLOC) ? - "Private Mem" : - "Shared Mem"); - - /* initialize window state variables before calling osg_getmem */ - ifp->if_zoomflag = 0; - ifp->if_xzoom = 1; /* for zoom fakeout */ - ifp->if_yzoom = 1; /* for zoom fakeout */ - ifp->if_xcenter = width/2; - ifp->if_ycenter = height/2; - SGI(ifp)->mi_pid = bu_process_id(); - - /* Attach to shared memory, potentially with a screen repaint */ - if (osg_getmem(ifp) < 0) - return -1; -#if 0 - /* Open an X connection to the display. Sending NULL to XOpenDisplay - tells it to use the DISPLAY environment variable. */ - if ((OSG(ifp)->dispp = XOpenDisplay(NULL)) == NULL) { - fb_log("fb_osg_open: Failed to open display. Check DISPLAY environment variable.\n"); - return -1; - } - ifp->if_selfd = ConnectionNumber(OSG(ifp)->dispp); - if (CJDEBUG) { - printf("Connection opened to X display on fd %d.\n", - ConnectionNumber(OSG(ifp)->dispp)); - } -#endif - /* Choose an appropriate visual. */ - //if ((OSG(ifp)->vip = fb_osg_choose_visual(ifp)) == NULL) { - // fb_log("fb_osg_open: Couldn't find an appropriate visual. Exiting.\n"); -// return -1; - //} - -#if 0 - /* Open an OpenGL context with this visual*/ - OSG(ifp)->glxc = glXCreateContext(OSG(ifp)->dispp, OSG(ifp)->vip, 0, GL_TRUE /* direct context */); - if (OSG(ifp)->glxc == NULL) { - fb_log("ERROR: Couldn't create an OpenGL context!\n"); - return -1; - } - - direct = glXIsDirect(OSG(ifp)->dispp, OSG(ifp)->glxc); - if (CJDEBUG) { - fb_log("Framebuffer drawing context is %s.\n", direct ? "direct" : "indirect"); - } -#endif - - - // TODO - replace X window creation below with Tk window creation here. See osg_open in - // libdm for pointers. - - struct bu_vls if_pathName; - struct bu_vls if_tkName; - struct bu_vls if_dName; - bu_vls_init(&if_pathName); - bu_vls_init(&if_tkName); - bu_vls_init(&if_dName); - Tk_Window tkwin = (Tk_Window)NULL; - - bu_vls_sprintf(&if_pathName, ".if_osg%d", osg_nwindows); - osg_nwindows++; - bu_vls_strcpy(&if_dName, ":0.0"); - - OSG(ifp)->fbinterp = Tcl_CreateInterp(); - Tcl_Init(OSG(ifp)->fbinterp); - Tcl_Eval(OSG(ifp)->fbinterp, "package require Tk"); - - tkwin = Tk_MainWindow(OSG(ifp)->fbinterp); - - //OSG(ifp)->xtkwin = Tk_CreateWindowFromPath(OSG(ifp)->fbinterp, tkwin, bu_vls_addr(&if_pathName), bu_vls_addr(&if_dName)); - OSG(ifp)->xtkwin = tkwin; - - bu_vls_printf(&if_tkName, "%s", (char *)Tk_Name(OSG(ifp)->xtkwin)); - - OSG(ifp)->dispp = Tk_Display(tkwin); - - Tk_GeometryRequest(OSG(ifp)->xtkwin, width, height); - - Tk_MakeWindowExist(OSG(ifp)->xtkwin); - - OSG(ifp)->wind = Tk_WindowId(OSG(ifp)->xtkwin); - - Tk_MapWindow(OSG(ifp)->xtkwin); - - /* Set Tk variables to handle Window behavior */ - Tcl_SetVar(OSG(ifp)->fbinterp, "WM_DELETE_WINDOW", "0", 0); - Tcl_Eval(OSG(ifp)->fbinterp, "wm protocol . WM_DELETE_WINDOW {set WM_DELETE_WINDOW \"1\"}"); - Tcl_Eval(OSG(ifp)->fbinterp, "bind . <Button-3> {set WM_DELETE_WINDOW \"1\"}"); - Tcl_Eval(OSG(ifp)->fbinterp, "bind . <Expose> {set WM_EXPOSE_EVENT \"1\"}"); - Tcl_Eval(OSG(ifp)->fbinterp, "bind . <Motion> {set WM_EXPOSE_EVENT \"1\"}"); - - while (Tcl_DoOneEvent(TCL_ALL_EVENTS|TCL_DONT_WAIT)); - - // Init the Windata Variable that holds the handle for the Window to display OSG in. - // Check the QOSGWidget.cpp example for more logic relevant to this. Need to find - // something showing how to handle Cocoa for the Mac, if that's possible - osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; -#if defined(_WIN32) - osg::ref_ptr<osg::Referenced> windata = new osgViewer::GraphicsWindowWin32::WindowData(Tk_GetHWND(OSG(ifp)->wind)); -#else - osg::ref_ptr<osg::Referenced> windata = new osgViewer::GraphicsWindowX11::WindowData(OSG(ifp)->wind); -#endif - // Although we are not making direct use of osgViewer currently, we need its // initialization to make sure we have all the libraries we need loaded and // ready. osgViewer::Viewer *viewer = new osgViewer::Viewer(); delete viewer; - // Setup the traits parameters - traits->x = 0; - traits->y = 0; - traits->width = width; - traits->height = height; - traits->depth = 24; - traits->windowDecoration = false; - traits->doubleBuffer = true; - traits->sharedContext = 0; - traits->setInheritedWindowPixelFormat = true; - traits->inheritedWindowData = windata; + /* Initialize GLFW Window. TODO - this will eventually become an + * osgViewer setup, once the initial dev work is done. */ + glfwInit(); + GLFWwindow *glfw = glfwCreateWindow(width, height, "osg", N... [truncated message content] |