Permalink
Browse files

From Stephan Huber, "* imageio: removed ReaderWriterImageIO_IOS.cpp, …

…refactored ReaderWriterImageIO to work on OS X and IOS

* avfoundation: added support for IOS (CoreVideo-support is still in development, works only for SDK >= 6.0, set IPHONE_SDKVER in cMake accordingly)
* zeroconf: added ZeroConf-device-plugin (Mac/Win only, linux implementation missing) to advertise and discover services via ZeroConf/Bonjour, on windows you'll need the Bonjour SDK from Apple
* osgosc: modified the example to demonstrate the usage of the ZeroConf-plugin (start the example with the command-line-argument --zeroconf)
* SlideShowConstructor: enable/disable CoreVideo via a environment variable (P3D_ENABLE_CORE_VIDEO)
* RestHttp: mouse-motion-events get interpolated
* RestHttp: unhandled http-requests get sent as an user-event to the event-queue, all arguments get attached as user-values to the event
* modified some CMakeModules to work correctly when compiling for IOS
* fixed a compile-error for IOS in GraphicsWindowIOS
* some minor bugfixes"
  • Loading branch information...
1 parent 8e1543d commit 5030175f0d2bdf68cc739184adb4d75b34b2d696 @osg-training-guest osg-training-guest committed Dec 5, 2012
View
@@ -233,7 +233,7 @@ IF(APPLE)
IF(OSG_BUILD_PLATFORM_IPHONE OR OSG_BUILD_PLATFORM_IPHONE_SIMULATOR)
#you need to manually set the default sdk version here
- SET (IPHONE_SDKVER "5.1")
+ SET (IPHONE_SDKVER "5.1" CACHE STRING "IOS SDK-Version")
#the below is taken from ogre, it states the gcc stuff needs to happen before PROJECT() is called. I've no clue if we even need it
# Force gcc <= 4.2 on iPhone
@@ -517,6 +517,7 @@ ELSE()
FIND_PACKAGE(DirectInput)
FIND_PACKAGE(NVTT)
FIND_PACKAGE(Asio)
+ FIND_PACKAGE(ZeroConf)
ENDIF()
IF(CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION LESS 8)
@@ -584,7 +585,6 @@ IF(NOT ANDROID)
FIND_PACKAGE(JPEG)
FIND_PACKAGE(PNG)
FIND_PACKAGE(TIFF)
-
# QuickTime is required for OS X, but optional for Windows.
IF(WIN32)
FIND_PACKAGE(QuickTime)
@@ -9,8 +9,6 @@
#
# Created by Stephan Maximilian Huber
-# QTKit on OS X looks different than QTKit for Windows,
-# so I am going to case the two.
IF(APPLE)
FIND_PATH(AV_FOUNDATION_INCLUDE_DIR AVFoundation/AVFoundation.h)
@@ -23,19 +21,22 @@ IF(AV_FOUNDATION_LIBRARY AND AV_FOUNDATION_INCLUDE_DIR)
ENDIF()
IF(OSG_BUILD_PLATFORM_IPHONE OR OSG_BUILD_PLATFORM_IPHONE_SIMULATOR)
- # TODO, AVFoundation exists ON iOS, too
- SET(AV_FOUNDATION_FOUND "NO")
-ENDIF()
-
-IF(APPLE)
- # AVFoundation exists since 10.7, but only 10.8 has all features necessary for OSG
- # so check the SDK-setting
-
- IF(${OSG_OSX_SDK_NAME} STREQUAL "macosx10.8")
- # nothing special here ;-)
+ # AVFoundation exists ON iOS, too -- good support for SDK 6.0 and greater
+ IF(${IPHONE_SDKVER} LESS "6.0")
+ SET(AV_FOUNDATION_FOUND "NO")
ELSE()
- MESSAGE("AVFoundation disabled for SDK < 10.8")
- SET(AV_FOUNDATION_FOUND "NO")
+ SET(AV_FOUNDATION_FOUND "YES")
ENDIF()
-ENDIF()
+ELSE()
+ IF(APPLE)
+ # AVFoundation exists since 10.7, but only 10.8 has all features necessary for OSG
+ # so check the SDK-setting
+ IF(${OSG_OSX_SDK_NAME} STREQUAL "macosx10.8")
+ # nothing special here ;-)
+ ELSE()
+ MESSAGE("AVFoundation disabled for SDK < 10.8")
+ SET(AV_FOUNDATION_FOUND "NO")
+ ENDIF()
+ ENDIF()
+ENDIF()
@@ -49,24 +49,24 @@ ENDIF()
IF(OSG_BUILD_PLATFORM_IPHONE OR OSG_BUILD_PLATFORM_IPHONE_SIMULATOR)
SET(QUICKTIME_FOUND "NO")
-ENDIF()
-
-IF(APPLE)
- #Quicktime is not supported under 64bit OSX build so we need to detect it and disable it.
- #First check to see if we are running with a native 64-bit compiler (10.6 default) and implicit arch
- IF(NOT CMAKE_OSX_ARCHITECTURES AND CMAKE_SIZEOF_VOID_P EQUAL 8)
- SET(QUICKTIME_FOUND "NO")
- ELSE()
- #Otherwise check to see if 64-bit is explicitly called for.
- LIST(FIND CMAKE_OSX_ARCHITECTURES "x86_64" has64Compile)
- IF(NOT has64Compile EQUAL -1)
- SET(QUICKTIME_FOUND "NO")
- ENDIF()
- ENDIF()
- # Disable quicktime for >= 10.7, as it's officially deprecated
-
- IF(${OSG_OSX_SDK_NAME} STREQUAL "macosx10.7" OR ${OSG_OSX_SDK_NAME} STREQUAL "macosx10.8" OR ${OSG_OSX_SDK_NAME} STREQUAL "macosx10.9")
- MESSAGE("disabling quicktime because it's not supported by the selected SDK ${OSG_OSX_SDK_NAME}")
- SET(QUICKTIME_FOUND "NO")
- ENDIF()
+ELSE()
+ IF(APPLE)
+ #Quicktime is not supported under 64bit OSX build so we need to detect it and disable it.
+ #First check to see if we are running with a native 64-bit compiler (10.6 default) and implicit arch
+ IF(NOT CMAKE_OSX_ARCHITECTURES AND CMAKE_SIZEOF_VOID_P EQUAL 8)
+ SET(QUICKTIME_FOUND "NO")
+ ELSE()
+ #Otherwise check to see if 64-bit is explicitly called for.
+ LIST(FIND CMAKE_OSX_ARCHITECTURES "x86_64" has64Compile)
+ IF(NOT has64Compile EQUAL -1)
+ SET(QUICKTIME_FOUND "NO")
+ ENDIF()
+ ENDIF()
+ # Disable quicktime for >= 10.7, as it's officially deprecated
+
+ IF(${OSG_OSX_SDK_NAME} STREQUAL "macosx10.7" OR ${OSG_OSX_SDK_NAME} STREQUAL "macosx10.8" OR ${OSG_OSX_SDK_NAME} STREQUAL "macosx10.9")
+ MESSAGE("disabling quicktime because it's not supported by the selected SDK ${OSG_OSX_SDK_NAME}")
+ SET(QUICKTIME_FOUND "NO")
+ ENDIF()
+ ENDIF()
ENDIF()
@@ -0,0 +1,47 @@
+# Locate ZeroConf / Bonjour
+# This module defines
+# ZEROCONF_LIBRARY
+# ZEROCONF_FOUND, if false, do not try to link to gdal
+# ZEROCONF_INCLUDE_DIR, where to find the headers
+#
+# $ZEROCONF_DIR is an environment variable that would
+# correspond to the ./configure --prefix=$ZEROCONF_DIR
+
+# Created by Stephan Maximilian Huber
+
+SET(ZEROCONF_FOUND "NO")
+
+IF(APPLE)
+ # bonjour is part of the system on os x / ios
+ SET(ZEROCONF_FOUND "YES")
+ELSE()
+ IF(WIN32)
+ # find the Bonjour SDK
+ FIND_PATH(ZEROCONF_INCLUDE_DIR dnssd.h
+ $ENV{ZEROCONF_DIR}/include
+ $ENV{ZEROCONF_DIR}
+ NO_DEFAULT_PATH
+ )
+ FIND_PATH(ZEROCONF_INCLUDE_DIR dnssd.h
+ PATHS ${CMAKE_PREFIX_PATH} # Unofficial: We are proposing this.
+ NO_DEFAULT_PATH
+ PATH_SUFFIXES include
+ )
+ FIND_PATH(ZEROCONF_INCLUDE_DIR dnssd.h)
+
+ FIND_LIBRARY(ZEROCONF_LIBRARY dnssd
+ PATHS ${CMAKE_PREFIX_PATH} # Unofficial: We are proposing this.
+ NO_DEFAULT_PATH
+ PATH_SUFFIXES lib64 lib
+ )
+ FIND_LIBRARY(ZEROCONF_LIBRARY dnssd)
+
+ SET(ZEROCONF_FOUND "NO")
+ IF(ZEROCONF_LIBRARY AND ZEROCONF_INCLUDE_DIR)
+ SET(ZEROCONF_FOUND "YES")
+ ENDIF()
+
+ ELSE()
+ # TODO find AVAHI on linux
+ ENDIF()
+ENDIF()
@@ -303,6 +303,25 @@ void processLoadedModel(osg::ref_ptr<osg::Node>& loadedModel, int optimizer_opti
}
}
+void addDeviceTo(osgViewer::Viewer& viewer, const std::string& device_name)
+{
+ osg::ref_ptr<osgGA::Device> dev = osgDB::readFile<osgGA::Device>(device_name);
+ if (dev.valid())
+ {
+ OSG_INFO << "Adding Device : " << device_name << std::endl;
+ if (dev->getCapabilities() & osgGA::Device::RECEIVE_EVENTS)
+ viewer.addDevice(dev.get());
+
+ if (dev->getCapabilities() & osgGA::Device::SEND_EVENTS)
+ viewer.getEventHandlers().push_front(new ForwardToDeviceEventHandler(dev.get()));
+ }
+ else
+ {
+ OSG_WARN << "could not open device: " << device_name << std::endl;
+ }
+}
+
+
int main( int argc, char **argv )
{
// use an ArgumentParser object to manage the program arguments.
@@ -434,27 +453,15 @@ int main( int argc, char **argv )
const char* p3dDevice = getenv("P3D_DEVICE");
if (p3dDevice)
{
- osg::ref_ptr<osgGA::Device> dev = osgDB::readFile<osgGA::Device>(p3dDevice);
- if (dev.valid())
- {
- viewer.addDevice(dev.get());
- }
+ addDeviceTo(viewer, p3dDevice);
+
}
std::string device;
while (arguments.read("--device", device))
{
- osg::ref_ptr<osgGA::Device> dev = osgDB::readFile<osgGA::Device>(device);
- if (dev.valid())
- {
- OSG_NOTICE<<"Adding Device : "<<device<<std::endl;
- if (dev->getCapabilities() & osgGA::Device::RECEIVE_EVENTS)
- viewer.addDevice(dev.get());
-
- if (dev->getCapabilities() & osgGA::Device::SEND_EVENTS)
- viewer.getEventHandlers().push_front(new ForwardToDeviceEventHandler(dev.get()));
- }
+ addDeviceTo(viewer, device);
}
@@ -356,15 +356,53 @@ class ForwardToDeviceEventHandler : public osgGA::GUIEventHandler {
return false;
}
-private:
+protected:
osg::ref_ptr<osgGA::Device> _device;
};
+class OscServiceDiscoveredEventHandler: public ForwardToDeviceEventHandler {
+public:
+ OscServiceDiscoveredEventHandler() : ForwardToDeviceEventHandler(NULL) {}
+
+ virtual bool handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa, osg::Object *o, osg::NodeVisitor *nv)
+ {
+ if (_device.valid())
+ return ForwardToDeviceEventHandler::handle(ea, aa, o, nv);
+
+ if (ea.getEventType() == osgGA::GUIEventAdapter::USER)
+ {
+ if (ea.getName() == "/zeroconf/service-added")
+ {
+ std::string host;
+ unsigned int port;
+ ea.getUserValue("host", host);
+ ea.getUserValue("port", port);
+
+ OSG_ALWAYS << "new osc-service discovered: " << host << ":" << port << std::endl;
+
+ std::ostringstream ss ;
+ ss << host << ":" << port << ".sender.osc";
+ _device = osgDB::readFile<osgGA::Device>(ss.str());
+
+ osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
+ if (view)
+ view->addEventHandler(new PickHandler(_device));
+ return true;
+ }
+ }
+ return false;
+ }
+
+};
+
int main( int argc, char **argv )
{
// use an ArgumentParser object to manage the program arguments.
osg::ArgumentParser arguments(&argc,argv);
+
+ arguments.getApplicationUsage()->addCommandLineOption("--zeroconf","uses zeroconf to advertise the osc-plugin and to discover it");
+
// read the scene from the list of file specified commandline args.
osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments);
@@ -374,6 +412,9 @@ int main( int argc, char **argv )
std::cout << argv[0] << ": requires filename argument." << std::endl;
return 1;
}
+
+ bool use_zeroconf(false);
+ if(arguments.find("--zeroconf") > 0) { use_zeroconf = true; }
// construct the viewer.
osgViewer::CompositeViewer viewer(arguments);
@@ -418,10 +459,20 @@ int main( int argc, char **argv )
view->addEventHandler( new osgViewer::StatsHandler );
view->addEventHandler( new UserEventHandler(text) );
- osg::ref_ptr<osgGA::Device> device = osgDB::readFile<osgGA::Device>("localhost:9000.receiver.osc");
+ osg::ref_ptr<osgGA::Device> device = osgDB::readFile<osgGA::Device>("0.0.0.0:9000.receiver.osc");
if (device.valid() && (device->getCapabilities() & osgGA::Device::RECEIVE_EVENTS))
{
view->addDevice(device);
+
+ // add a zeroconf device, advertising the osc-device
+ if(use_zeroconf)
+ {
+ osgGA::Device* zeroconf_device = osgDB::readFile<osgGA::Device>("_osc._udp:9000.advertise.zeroconf");
+ if (zeroconf_device)
+ {
+ view->addDevice(zeroconf_device);
+ }
+ }
}
else {
OSG_WARN << "could not open osc-device, receiving will not work" << std::endl;
@@ -463,19 +514,29 @@ int main( int argc, char **argv )
view->addEventHandler( statesetManipulator.get() );
view->addEventHandler( new osgViewer::StatsHandler );
- // get device
-
- osg::ref_ptr<osgGA::Device> device = osgDB::readFile<osgGA::Device>("localhost:9000.sender.osc");
- if (device.valid() && (device->getCapabilities() & osgGA::Device::SEND_EVENTS))
+ if (use_zeroconf)
{
- // add as first event handler, so it gets ALL events ...
- view->getEventHandlers().push_front(new ForwardToDeviceEventHandler(device));
-
- // add the demo-pick-event-handler
- view->addEventHandler(new PickHandler(device));
+ osgGA::Device* zeroconf_device = osgDB::readFile<osgGA::Device>("_osc._udp.discover.zeroconf");
+ if(zeroconf_device) {
+ view->addDevice(zeroconf_device);
+ view->getEventHandlers().push_front(new OscServiceDiscoveredEventHandler());
+
+ }
}
- else {
- OSG_WARN << "could not open osc-device, sending will not work" << std::endl;
+ else
+ {
+ osg::ref_ptr<osgGA::Device> device = osgDB::readFile<osgGA::Device>("localhost:9000.sender.osc");
+ if (device.valid() && (device->getCapabilities() & osgGA::Device::SEND_EVENTS))
+ {
+ // add as first event handler, so it gets ALL events ...
+ view->getEventHandlers().push_front(new ForwardToDeviceEventHandler(device));
+
+ // add the demo-pick-event-handler
+ view->addEventHandler(new PickHandler(device));
+ }
+ else {
+ OSG_WARN << "could not open osc-device, sending will not work" << std::endl;
+ }
}
}
@@ -148,7 +148,8 @@ class GraphicsWindowIOS : public osgViewer::GraphicsWindow
WindowData(UIView* window_or_view = NULL, DeviceOrientationFlags orientationFlags = ALL_ORIENTATIONS, float scaleFactor = -1.0f)
: _windowOrView(window_or_view),
_deviceOrientationFlags(orientationFlags),
- _viewContentScaleFactor(scaleFactor)
+ _viewContentScaleFactor(scaleFactor),
+ _createTransparentView(false)
{
}
@@ -157,11 +158,15 @@ class GraphicsWindowIOS : public osgViewer::GraphicsWindow
void setViewContentScaleFactor(float scaleFactor) { _viewContentScaleFactor = scaleFactor; }
UIView* getWindowOrParentView() const { return _windowOrView; }
+
+ bool getCreateTransparentView() { return _createTransparentView; }
+ void setCreateTransparentView(bool b) { _createTransparentView = b; }
private:
UIView* _windowOrView;
DeviceOrientationFlags _deviceOrientationFlags;
float _viewContentScaleFactor;
+ bool _createTransparentView;
friend class GraphicsWindowIOS;
View
@@ -2745,7 +2745,19 @@ Geometry* osg::createTexturedQuadGeometry(const Vec3& corner,const Vec3& widthVe
geom->setNormalArray(normals);
geom->setNormalBinding(Geometry::BIND_OVERALL);
+#if defined(OSG_GLES1_AVAILABLE) || !defined(OSG_GLES2_AVAILABLE)
+ DrawElementsUByte* elems = new DrawElementsUByte(PrimitiveSet::TRIANGLES);
+ elems->push_back(0);
+ elems->push_back(1);
+ elems->push_back(2);
+
+ elems->push_back(2);
+ elems->push_back(3);
+ elems->push_back(0);
+ geom->addPrimitiveSet(elems);
+#else
geom->addPrimitiveSet(new DrawArrays(PrimitiveSet::QUADS,0,4));
+#endif
return geom;
}
Oops, something went wrong.

0 comments on commit 5030175

Please sign in to comment.