2
0
David Rose 16 жил өмнө
parent
commit
a5e0de3988
30 өөрчлөгдсөн 541 нэмэгдсэн , 80 устгасан
  1. 2 2
      dtool/pptempl/PostConfig.pp
  2. 2 0
      panda/src/event/pythonTask.cxx
  3. 4 10
      panda/src/iphone/Sources.pp
  4. 2 5
      panda/src/iphone/config_iphone.h
  5. 1 37
      panda/src/iphone/config_iphone.mm
  6. 78 0
      panda/src/iphone/ipfreeze.py
  7. 227 0
      panda/src/iphone/iphone_runappmf_src.mm
  8. 44 0
      panda/src/iphone/provision.py
  9. 2 2
      panda/src/iphone/pview_delegate.h
  10. 11 3
      panda/src/iphone/pview_delegate.mm
  11. 2 6
      panda/src/iphone/pview_main.mm
  12. 34 0
      panda/src/iphonedisplay/Sources.pp
  13. 30 0
      panda/src/iphonedisplay/config_iphonedisplay.h
  14. 77 0
      panda/src/iphonedisplay/config_iphonedisplay.mm
  15. 0 0
      panda/src/iphonedisplay/eaglView.h
  16. 0 0
      panda/src/iphonedisplay/eaglView.mm
  17. 0 0
      panda/src/iphonedisplay/glesext_shadow.h
  18. 5 5
      panda/src/iphonedisplay/glesgsg.h
  19. 0 0
      panda/src/iphonedisplay/glesgsg.mm
  20. 1 1
      panda/src/iphonedisplay/iPhoneGraphicsPipe.h
  21. 1 1
      panda/src/iphonedisplay/iPhoneGraphicsPipe.mm
  22. 0 0
      panda/src/iphonedisplay/iPhoneGraphicsStateGuardian.h
  23. 1 1
      panda/src/iphonedisplay/iPhoneGraphicsStateGuardian.mm
  24. 0 0
      panda/src/iphonedisplay/iPhoneGraphicsWindow.I
  25. 0 0
      panda/src/iphonedisplay/iPhoneGraphicsWindow.h
  26. 5 6
      panda/src/iphonedisplay/iPhoneGraphicsWindow.mm
  27. 0 0
      panda/src/iphonedisplay/viewController.h
  28. 1 1
      panda/src/iphonedisplay/viewController.mm
  29. 9 0
      panda/src/pipeline/thread.cxx
  30. 2 0
      panda/src/putil/pythonCallbackObject.cxx

+ 2 - 2
dtool/pptempl/PostConfig.pp

@@ -9,12 +9,12 @@
   
   
   #if $[eq $[IPH_PLATFORM], iPhoneOS]
   #if $[eq $[IPH_PLATFORM], iPhoneOS]
     #define ARCH_FLAGS -arch armv6 -mcpu=arm1176jzf-s
     #define ARCH_FLAGS -arch armv6 -mcpu=arm1176jzf-s
-    #define osflags -fpascal-strings -fasm-blocks -fvisibility=hidden -fvisibility-inlines-hidden -miphoneos-version-min=2.0
+    #define osflags -fpascal-strings -fasm-blocks -miphoneos-version-min=2.0
     #define DEBUGFLAGS -gdwarf-2
     #define DEBUGFLAGS -gdwarf-2
     //#define DEBUGFLAGS
     //#define DEBUGFLAGS
   #elif $[eq $[IPH_PLATFORM], iPhoneSimulator]
   #elif $[eq $[IPH_PLATFORM], iPhoneSimulator]
     #define ARCH_FLAGS -arch i386
     #define ARCH_FLAGS -arch i386
-    #define osflags -fpascal-strings -fasm-blocks -fvisibility=hidden -fvisibility-inlines-hidden -mmacosx-version-min=10.5
+    #define osflags -fpascal-strings -fasm-blocks -mmacosx-version-min=10.5
     #define DEBUGFLAGS -gdwarf-2
     #define DEBUGFLAGS -gdwarf-2
   #else
   #else
     #error Inappropriate value for BUILD_IPHONE.
     #error Inappropriate value for BUILD_IPHONE.

+ 2 - 0
panda/src/event/pythonTask.cxx

@@ -49,8 +49,10 @@ PythonTask(PyObject *function, const string &name) :
 #ifndef SIMPLE_THREADS
 #ifndef SIMPLE_THREADS
   // Ensure that the Python threading system is initialized and ready
   // Ensure that the Python threading system is initialized and ready
   // to go.
   // to go.
+#ifdef WITH_THREAD  // This symbol defined within Python.h
   PyEval_InitThreads();
   PyEval_InitThreads();
 #endif
 #endif
+#endif
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 4 - 10
panda/src/iphone/Sources.pp

@@ -4,26 +4,20 @@
                    dtoolutil:c dtoolbase:c dtool:m prc:c 
                    dtoolutil:c dtoolbase:c dtool:m prc:c 
 
 
 #define OSX_SYS_FRAMEWORKS Foundation QuartzCore UIKit OpenGLES
 #define OSX_SYS_FRAMEWORKS Foundation QuartzCore UIKit OpenGLES
-#define BUILDING_DLL BUILDING_PANDAGL
 
 
 #begin bin_target
 #begin bin_target
   #define TARGET iphone_pview
   #define TARGET iphone_pview
+
+  #define OTHER_LIBS $[OTHER_LIBS] pystub
   #define LOCAL_LIBS \
   #define LOCAL_LIBS \
+    iphonedisplay \
     framework putil collide pgraph chan text \
     framework putil collide pgraph chan text \
     pnmimage pnmimagetypes event effects gobj display \
     pnmimage pnmimagetypes event effects gobj display \
     mathutil putil express dgraph device tform \
     mathutil putil express dgraph device tform \
     linmath pstatclient panda glstuff
     linmath pstatclient panda glstuff
 
 
   #define SOURCES \
   #define SOURCES \
-    config_iphone.h config_iphone.mm \
     pview_delegate.h pview_delegate.mm \
     pview_delegate.h pview_delegate.mm \
-    viewController.h viewController.mm \
-    eaglView.h eaglView.mm \
-    glesext_shadow.h \
-    glesgsg.h glesgsg.mm \
-    iPhoneGraphicsPipe.h iPhoneGraphicsPipe.mm \
-    iPhoneGraphicsStateGuardian.h iPhoneGraphicsStateGuardian.mm \
-    iPhoneGraphicsWindow.h iPhoneGraphicsWindow.I iPhoneGraphicsWindow.mm \
-    main.mm
+    pview_main.mm
 
 
 #end bin_target
 #end bin_target

+ 2 - 5
panda/src/iphone/config_iphone.h

@@ -17,11 +17,8 @@
 #include "configVariableBool.h"
 #include "configVariableBool.h"
 #include "configVariableInt.h"
 #include "configVariableInt.h"
 
 
-NotifyCategoryDecl(iphone, EXPCL_PANDAGL, EXPTP_PANDAGL);
+NotifyCategoryDecl(iphone, EXPCL_MISC, EXPTP_MISC);
 
 
-extern ConfigVariableBool iphone_autorotate_view;
-
-extern EXPCL_PANDAGL void init_libiphone();
-extern "C" EXPCL_PANDAGL int get_pipe_type_iphone();
+extern EXPCL_MISC void init_libiphone();
 
 
 #endif  // CONFIG_IPHONE_H
 #endif  // CONFIG_IPHONE_H

+ 1 - 37
panda/src/iphone/config_iphone.mm

@@ -13,29 +13,16 @@
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 
 
 #include "config_iphone.h"
 #include "config_iphone.h"
-#include "iPhoneGraphicsPipe.h"
-#include "iPhoneGraphicsStateGuardian.h"
-#include "iPhoneGraphicsWindow.h"
-
-#include "graphicsPipeSelection.h"
 #include "dconfig.h"
 #include "dconfig.h"
-#include "pandaSystem.h"
-
 
 
 Configure(config_iphone);
 Configure(config_iphone);
 
 
-NotifyCategoryDef(iphone, "display");
+NotifyCategoryDef(iphone, "");
 
 
 ConfigureFn(config_iphone) {
 ConfigureFn(config_iphone) {
   init_libiphone();
   init_libiphone();
 }
 }
 
 
-ConfigVariableBool iphone_autorotate_view
-("iphone-autorotate-view", true,
- PRC_DESC("Set this true to enable the iphone application to rotate its "
-          "view automatically according to the phone's orientation, or "
-          "false for its view to remain fixed."));
-
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: init_libiphone
 //     Function: init_libiphone
 //  Description: Initializes the library.  This must be called at
 //  Description: Initializes the library.  This must be called at
@@ -51,27 +38,4 @@ init_libiphone() {
     return;
     return;
   }
   }
   initialized = true;
   initialized = true;
-
-  IPhoneGraphicsPipe::init_type();
-  IPhoneGraphicsWindow::init_type();
-  IPhoneGraphicsStateGuardian::init_type();
-
-  GraphicsPipeSelection *selection = GraphicsPipeSelection::get_global_ptr();
-  selection->add_pipe_type(IPhoneGraphicsPipe::get_class_type(), IPhoneGraphicsPipe::pipe_constructor);
-
-  PandaSystem *ps = PandaSystem::get_global_ptr();
-  ps->set_system_tag("OpenGL", "window_system", "IPhone");
-  ps->set_system_tag("OpenGL ES", "window_system", "IPhone");
-
-  GLESinit_classes();
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: get_pipe_type_iphone
-//  Description: Returns the TypeHandle index of the recommended
-//               graphics pipe type defined by this module.
-////////////////////////////////////////////////////////////////////
-int
-get_pipe_type_iphone() {
-  return IPhoneGraphicsPipe::get_class_type().get_index();
 }
 }

+ 78 - 0
panda/src/iphone/ipfreeze.py

@@ -0,0 +1,78 @@
+#! /usr/bin/env python
+
+"""
+
+This script is used to generate a self-contained IPhone executable
+that will run an app multifile.  Still experimental.
+
+Usage:
+
+  ipfreeze.py [opts]
+
+"""
+
+import getopt
+import sys
+import os
+from direct.showutil import FreezeTool
+
+def usage(code, msg = ''):
+    print >> sys.stderr, __doc__
+    print >> sys.stderr, msg
+    sys.exit(code)
+
+if __name__ == '__main__':
+    freezer = FreezeTool.Freezer()
+
+    basename = 'iphone_runappmf'
+    
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], 'h')
+    except getopt.error, msg:
+        usage(1, msg)
+
+    for opt, arg in opts:
+        if opt == '-h':
+            usage(0)
+
+    main = open('iphone_runappmf_src.mm', 'r').read()
+    freezer.mainInitCode = main
+
+    #target = 'sim'
+    target = 'phone'
+
+    if target == 'sim':
+        platform = 'IPhoneSimulator'
+    else:
+        platform = 'IPhoneOS'
+    
+    version = '2.0'
+    dev = '/Developer/Platforms/%s.platform/Developer' % (platform)
+    env = 'env MACOSX_DEPLOYMENT_TARGET=10.5 PATH="%s/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"' % (dev)
+    cc = '%s %s/usr/bin/g++-4.0' % (env, dev)
+    sysroot = '-isysroot %s/SDKs/%s%s.sdk' % (dev, platform, version)
+    cflags = '-D__IPHONE_OS_VERSION_MIN_REQUIRED=20000 %s' % (sysroot)
+    arch = ''
+    if target == 'phone':
+        arch = ' -arch armv6 -mcpu=arm1176jzf-s -miphoneos-version-min=2.0'
+    lflags = sysroot
+
+    ipath = '-I/Users/drose/Python-2.5.4.%s/Include -I/Users/drose/Python-2.5.4.%s -I/usr/local/panda/%s/include' % (target, target, target)
+    lpath = '-L/Users/drose/Python-2.5.4.%s -L/usr/local/panda/%s/lib' % (target, target)
+    libs = '-lframework -lputil -lcollide -lpgraph -lchan -ltext -lpnmimage -lpnmimagetypes -levent -leffects -lgobj -ldisplay -lmathutil -lexpress -ldgraph -ldevice -ltform -llinmath -lpstatclient -lpanda -lglstuff -lrecorder -lpgui -lchar -lpipeline -lpandabase -llerp -lgsgbase -ldownloader -lparametrics -lpgraphnodes -lcull -lgrutil -lnet -lmovies -lnativenet -laudio -linterrogatedb -ldconfig -ldtoolutil -ldtoolbase -lprc -liphonedisplay -lpandaexpress -lpanda'
+    libs += ' -lphysics -lparticlesystem -lpandaphysics'
+    libs += ' -ldistort -leffects -lpandafx'
+    libs += ' -ldirectbase -ldcparser -ldeadrec -ldistributed -lhttp -lshowbase -linterval -lmotiontrail -ldirect'
+    libs += ' -lpython2.5'
+    libs += ' -framework Foundation -framework QuartzCore -framework UIKit -framework OpenGLES'
+
+    freezer.sourceExtension = '.mm'
+    freezer.compileObj = '%s -c %s %s -o %%(basename)s.o %s %%(filename)s' % (cc, arch, cflags, ipath)
+    freezer.linkExe = "%s %s %s -o %%(basename)s %s %s %%(basename)s.o" % (cc, arch, lflags, lpath, libs)
+
+    freezer.addModule('direct.*.*')
+    freezer.excludeModule('direct.extensions.*')
+    freezer.compileToExe = True
+    freezer.done()
+
+    freezer.generateCode(basename)

+ 227 - 0
panda/src/iphone/iphone_runappmf_src.mm

@@ -0,0 +1,227 @@
+// Filename: iphone_runappmf_src.mm
+// Created by:  drose (26Apr09)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+#include "pandabase.h"
+
+#import <UIKit/UIKit.h> 
+    
+#import "viewController.h"
+#include "dcast.h"
+#include "config_iphonedisplay.h"
+
+#ifdef LINK_ALL_STATIC
+extern "C" void initlibpandaexpress();
+extern "C" void initlibpanda();
+extern "C" void initlibpandaphysics();
+extern "C" void initlibpandafx();
+extern "C" void initlibdirect();
+#endif  // LINK_ALL_STATIC
+
+@class AppMFViewController; 
+@interface AppMFAppDelegate : NSObject <UIApplicationDelegate> { 
+  NSTimer *animationTimer;
+  NSTimeInterval animationInterval;
+} 
+@property (nonatomic, assign) NSTimer *animationTimer;
+@property NSTimeInterval animationInterval;
+
+- (void)startAnimation;
+- (void)stopAnimation;
+- (void)drawView;
+
+@end 
+
+@implementation AppMFAppDelegate 
+
+@synthesize animationTimer;
+@synthesize animationInterval;
+
+int startup = 0;
+
+- (void)applicationDidFinishLaunching: (UIApplication *)application { 
+  // Ensure the IPhoneDisplay is available.
+  init_libiphonedisplay();
+
+  ConfigVariableDouble timer_fps("timer-fps", 60.0);
+  animationInterval = 1.0 / timer_fps;
+  [self startAnimation];
+} 
+
+- (void)applicationDidReceiveMemoryWarning: (UIApplication *)application { 
+  nout << "applicationDidReceiveMemoryWarning\n";
+}
+
+- (void)startAnimation {
+    self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(drawView) userInfo:nil repeats:YES];
+}
+
+
+- (void)stopAnimation {
+    self.animationTimer = nil;
+}
+
+
+- (void)setAnimationTimer:(NSTimer *)newTimer {
+    [animationTimer invalidate];
+    animationTimer = newTimer;
+}
+
+
+- (void)setAnimationInterval:(NSTimeInterval)interval {
+    
+    animationInterval = interval;
+    if (animationTimer) {
+        [self stopAnimation];
+        [self startAnimation];
+    }
+}
+
+- (void)drawView {
+  if (startup == 0) {
+    // We are still just initializing the app.  Initialize Python now.
+    // We have this funny deferred-window technique, so SpringBoard
+    // will see that the app has fully initialized and won't kill us
+    // if we take a while starting up.
+
+    Py_FrozenFlag = 1; /* Suppress errors from getpath.c */
+    Filename app_pathname(Filename::get_app_directory(), "iphone_runmf");
+    Py_SetProgramName((char *)app_pathname.c_str());
+    Py_Initialize();
+
+    int argv = 1;
+    Filename script_pathname(Filename::get_app_directory(), "iphone.mf");
+    char *argc[] = { (char *)script_pathname.c_str(), NULL };
+    PySys_SetArgv(argv, argc);
+    Py_SetPythonHome((char *)Filename::get_app_directory().c_str());
+
+#ifdef LINK_ALL_STATIC
+    // Construct the Python modules for the interrogate-generated data
+    // we know we've already linked in.
+    initlibpandaexpress();
+    initlibpanda();
+    initlibpandaphysics();
+    initlibpandafx();
+    initlibdirect();
+#endif  // LINK_ALL_STATIC
+
+    /*
+    PyImport_ImportFrozenModule("direct");
+    PyImport_ImportFrozenModule("direct.showbase");
+    int n = PyImport_ImportFrozenModule("direct.showbase.RunAppMF");
+    if (n == 0) {
+      cerr << "RunAppMF not frozen in binary\n";
+      Py_Finalize();
+      exit(1);
+    } else if (n < 0) {
+      PyErr_Print();
+      Py_Finalize();
+      exit(1);
+    }
+    */
+
+    PyObject *module = PyImport_ImportModule("direct");
+    if (module == (PyObject *)NULL) {
+      cerr << "direct not importable\n";
+      Py_Finalize();
+      exit(1);
+    }
+    Py_DECREF(module);
+
+    module = PyImport_ImportModule("direct.showbase");
+    if (module == (PyObject *)NULL) {
+      cerr << "direct.showbase not importable\n";
+      Py_Finalize();
+      exit(1);
+    }
+    Py_DECREF(module);
+
+    module = PyImport_ImportModule("direct.showbase.RunAppMF");
+    if (module == (PyObject *)NULL) {
+      cerr << "RunAppMF not importable\n";
+      Py_Finalize();
+      exit(1);
+    }
+    Py_DECREF(module);
+
+    startup = 1;
+
+  } else if (startup == 1) {
+    // Now that Python is initialized, call the startup function.
+    PyObject *module = PyImport_ImportModule("direct.showbase.RunAppMF");
+    if (module != (PyObject *)NULL) {
+      PyObject *func = PyObject_GetAttrString(module, "runPackedApp");
+      if (func != (PyObject *)NULL) {
+        Filename script_pathname(Filename::get_app_directory(), "iphone.mf");
+        PyObject *result = PyObject_CallFunction(func, "([s])", script_pathname.c_str());
+        Py_XDECREF(result);
+        Py_DECREF(func);
+      }
+      Py_DECREF(module);
+    }
+
+    if (PyErr_Occurred()) {
+      PyErr_Print();
+      Py_Finalize();
+      exit(1);
+    }
+
+    startup = 2;
+
+  } else {
+    // We are fully initialized and running.  Run taskMgr.step() once
+    // each frame.
+    PyObject *module = PyImport_ImportModule("__builtin__");
+    if (module != (PyObject *)NULL) {
+      PyObject *taskMgr = PyObject_GetAttrString(module, "taskMgr");
+      if (taskMgr != (PyObject *)NULL) {
+        PyObject *result = PyObject_CallMethod(taskMgr, "step", "()");
+        Py_XDECREF(result);
+        Py_DECREF(taskMgr);
+      }
+      Py_DECREF(module);
+    }
+
+    if (PyErr_Occurred()) {
+      PyErr_Print();
+      Py_Finalize();
+      exit(1);
+    }
+  }
+}
+
+- (void)applicationWillTerminate:
+(UIApplication *)application
+{
+  [self stopAnimation];
+  Py_Finalize();
+}
+
+- (void)dealloc { 
+  [super dealloc]; 
+} 
+
+@end 
+
+extern "C" int main(int argc, char *argv[]);
+
+int
+main(int argc, char *argv[]) { 
+  PyImport_FrozenModules = _PyImport_FrozenModules;
+  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
+
+  /* Call with the name of our application delegate class */ 
+  int retVal = UIApplicationMain(argc, argv, nil, @"AppMFAppDelegate"); 
+  [pool release]; 
+  return retVal; 
+} 

+ 44 - 0
panda/src/iphone/provision.py

@@ -0,0 +1,44 @@
+#! /usr/bin/env python
+
+import shutil
+import os
+
+identity="iPhone Developer: David Rose"
+library='/Users/drose/Library'
+profile="31FDB595-E85E-41D8-BE12-7C67B777B6C3"
+appPrefix="VGEKRBUPUE"
+appId="com.ddrose.iphone.pview"
+entitlements="/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.1.sdk/Entitlements.plist"
+app="/tmp/iphone/pview.app"
+xcent="/tmp/file.xcent"
+
+
+sourceFilename = '%s/MobileDevice/Provisioning Profiles/%s.mobileprovision' % (library, profile)
+targetFilename = '%s/embedded.mobileprovision' % (app)
+shutil.copyfile(sourceFilename, targetFilename)
+
+origtext = open(entitlements, 'r').read()
+dict = origtext.find('<dict>')
+newtext = origtext[:dict + 6] + '\n<key>application-identifier</key>\n<string>%s.%s</string>' % (appPrefix, appId) + origtext[dict + 6:]
+
+# Some kind of crazy binary header on the xcent file.  The second
+# group of four bytes is the file length.
+header = '\xfa\xde\x71\x71'
+length = len(header) + 4 + len(newtext)
+lengthstr = chr(length >> 24) + chr((length >> 16) & 0xff) + chr((length >> 8) & 0xff) + chr(length & 0xff)
+open(xcent, 'w').write(header + lengthstr + newtext)
+
+command = 'env CODESIGN_ALLOCATE="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate" PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /usr/bin/codesign -f -s "%(identity)s" --resource-rules="%(app)s/ResourceRules.plist" --entitlements "%(xcent)s" "%(app)s"' % {
+    'identity' : identity,
+    'app' : app,
+    'xcent' : xcent,
+    }    
+
+print command
+result = os.system(command)
+if result != 0:
+    raise StandardError
+
+os.unlink(xcent)
+
+

+ 2 - 2
panda/src/iphone/pview_delegate.h

@@ -14,8 +14,8 @@
 
 
 #import <UIKit/UIKit.h> 
 #import <UIKit/UIKit.h> 
 
 
-@class ControllerDemoViewController; 
-@interface ControllerDemoAppDelegate : NSObject <UIApplicationDelegate> { 
+@class PviewViewController; 
+@interface PviewAppDelegate : NSObject <UIApplicationDelegate> { 
   NSTimer *animationTimer;
   NSTimer *animationTimer;
   NSTimeInterval animationInterval;
   NSTimeInterval animationInterval;
 } 
 } 

+ 11 - 3
panda/src/iphone/pview_delegate.mm

@@ -14,11 +14,11 @@
     
     
 #import "pview_delegate.h" 
 #import "pview_delegate.h" 
 #import "viewController.h"
 #import "viewController.h"
-#include "config_iphone.h"
 #include "dcast.h"
 #include "dcast.h"
 #include "pandaFramework.h"
 #include "pandaFramework.h"
+#include "config_iphonedisplay.h"
 
 
-@implementation ControllerDemoAppDelegate 
+@implementation PviewAppDelegate 
 
 
 @synthesize animationTimer;
 @synthesize animationTimer;
 @synthesize animationInterval;
 @synthesize animationInterval;
@@ -65,6 +65,9 @@ signal_handler(int i) {
   }
   }
   argv[argc] = NULL;
   argv[argc] = NULL;
 
 
+  // Ensure the IPhoneDisplay is available.
+  init_libiphonedisplay();
+  
   framework.open_framework(argc, argv);
   framework.open_framework(argc, argv);
   startup = 0;
   startup = 0;
 
 
@@ -108,7 +111,12 @@ signal_handler(int i) {
     // load the models.  We have this funny deferred-window technique,
     // load the models.  We have this funny deferred-window technique,
     // so SpringBoard will see that the app has fully initialized and
     // so SpringBoard will see that the app has fully initialized and
     // won't kill us if we take a while loading models.
     // won't kill us if we take a while loading models.
-    framework.open_window();
+    WindowFramework *window = framework.open_window();
+    if (window == (WindowFramework *)NULL) {
+      // Couldn't get a window.
+      framework.close_framework();
+      exit(0);
+    }
     startup = 1;
     startup = 1;
 
 
   } else if (startup == 1) {
   } else if (startup == 1) {

+ 2 - 6
panda/src/iphone/main.mm → panda/src/iphone/pview_main.mm

@@ -1,4 +1,4 @@
-// Filename: main.mm
+// Filename: pview_main.mm
 // Created by:  drose (10Apr09)
 // Created by:  drose (10Apr09)
 //
 //
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -14,10 +14,6 @@
 
 
 #import <UIKit/UIKit.h>
 #import <UIKit/UIKit.h>
 
 
-#include <mach-o/dyld.h>
-#include <dlfcn.h>
-#include <iostream>
-
 extern "C" int main(int argc, char *argv[]);
 extern "C" int main(int argc, char *argv[]);
 
 
 int
 int
@@ -25,7 +21,7 @@ main(int argc, char *argv[]) {
   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
 
 
   /* Call with the name of our application delegate class */ 
   /* Call with the name of our application delegate class */ 
-  int retVal = UIApplicationMain(argc, argv, nil, @"ControllerDemoAppDelegate"); 
+  int retVal = UIApplicationMain(argc, argv, nil, @"PviewAppDelegate"); 
   [pool release]; 
   [pool release]; 
   return retVal; 
   return retVal; 
 } 
 } 

+ 34 - 0
panda/src/iphonedisplay/Sources.pp

@@ -0,0 +1,34 @@
+#define BUILD_DIRECTORY $[BUILD_IPHONE]
+
+#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \
+                   dtoolutil:c dtoolbase:c dtool:m prc:c 
+
+#define OSX_SYS_FRAMEWORKS Foundation QuartzCore UIKit OpenGLES
+
+#begin lib_target
+  #define TARGET iphonedisplay
+
+  #define LOCAL_LIBS \
+    framework putil collide pgraph chan text \
+    pnmimage pnmimagetypes event effects gobj display \
+    mathutil putil express dgraph device tform \
+    linmath pstatclient panda glstuff
+
+  #define SOURCES \
+    config_iphonedisplay.h config_iphonedisplay.mm \
+    viewController.h viewController.mm \
+    eaglView.h eaglView.mm \
+    glesext_shadow.h \
+    glesgsg.h glesgsg.mm \
+    iPhoneGraphicsPipe.h iPhoneGraphicsPipe.mm \
+    iPhoneGraphicsStateGuardian.h iPhoneGraphicsStateGuardian.mm \
+    iPhoneGraphicsWindow.h iPhoneGraphicsWindow.I iPhoneGraphicsWindow.mm
+
+  #define INSTALL_HEADERS \
+    config_iphonedisplay.h \
+    viewController.h \
+    iPhoneGraphicsPipe.h \
+    iPhoneGraphicsStateGuardian.h \
+    iPhoneGraphicsWindow.h iPhoneGraphicsWindow.I
+
+#end lib_target

+ 30 - 0
panda/src/iphonedisplay/config_iphonedisplay.h

@@ -0,0 +1,30 @@
+// Filename: config_iphonedisplay.h
+// Created by:  drose (08Apr09)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef CONFIG_IPHONEDISPLAY_H
+#define CONFIG_IPHONEDISPLAY_H
+
+#include "pandabase.h"
+#include "notifyCategoryProxy.h"
+#include "configVariableBool.h"
+#include "configVariableInt.h"
+
+NotifyCategoryDecl(iphonedisplay, EXPCL_MISC, EXPTP_MISC);
+
+extern ConfigVariableBool iphone_autorotate_view;
+
+extern EXPCL_MISC void init_libiphonedisplay();
+extern "C" EXPCL_MISC int get_pipe_type_iphonedisplay();
+
+#endif  // CONFIG_IPHONEDISPLAY_H

+ 77 - 0
panda/src/iphonedisplay/config_iphonedisplay.mm

@@ -0,0 +1,77 @@
+// Filename: config_iphonedisplay.cxx
+// Created by:  drose (08Apr09)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+#include "config_iphonedisplay.h"
+#include "iPhoneGraphicsPipe.h"
+#include "iPhoneGraphicsStateGuardian.h"
+#include "iPhoneGraphicsWindow.h"
+
+#include "graphicsPipeSelection.h"
+#include "dconfig.h"
+#include "pandaSystem.h"
+
+
+Configure(config_iphonedisplay);
+
+NotifyCategoryDef(iphonedisplay, "display");
+
+ConfigureFn(config_iphonedisplay) {
+  init_libiphonedisplay();
+}
+
+ConfigVariableBool iphone_autorotate_view
+("iphone-autorotate-view", true,
+ PRC_DESC("Set this true to enable the iphone application to rotate its "
+          "view automatically according to the phone's orientation, or "
+          "false for its view to remain fixed."));
+
+////////////////////////////////////////////////////////////////////
+//     Function: init_libiphonedisplay
+//  Description: Initializes the library.  This must be called at
+//               least once before any of the functions or classes in
+//               this library can be used.  Normally it will be
+//               called by the static initializers and need not be
+//               called explicitly, but special cases exist.
+////////////////////////////////////////////////////////////////////
+void
+init_libiphonedisplay() {
+  static bool initialized = false;
+  if (initialized) {
+    return;
+  }
+  initialized = true;
+
+  IPhoneGraphicsPipe::init_type();
+  IPhoneGraphicsWindow::init_type();
+  IPhoneGraphicsStateGuardian::init_type();
+
+  GraphicsPipeSelection *selection = GraphicsPipeSelection::get_global_ptr();
+  selection->add_pipe_type(IPhoneGraphicsPipe::get_class_type(), IPhoneGraphicsPipe::pipe_constructor);
+
+  PandaSystem *ps = PandaSystem::get_global_ptr();
+  ps->set_system_tag("OpenGL", "window_system", "IPhone");
+  ps->set_system_tag("OpenGL ES", "window_system", "IPhone");
+
+  GLESinit_classes();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: get_pipe_type_iphonedisplay
+//  Description: Returns the TypeHandle index of the recommended
+//               graphics pipe type defined by this module.
+////////////////////////////////////////////////////////////////////
+int
+get_pipe_type_iphonedisplay() {
+  return IPhoneGraphicsPipe::get_class_type().get_index();
+}

+ 0 - 0
panda/src/iphone/eaglView.h → panda/src/iphonedisplay/eaglView.h


+ 0 - 0
panda/src/iphone/eaglView.mm → panda/src/iphonedisplay/eaglView.mm


+ 0 - 0
panda/src/iphone/glesext_shadow.h → panda/src/iphonedisplay/glesext_shadow.h


+ 5 - 5
panda/src/iphone/glesgsg.h → panda/src/iphonedisplay/glesgsg.h

@@ -19,7 +19,7 @@
 // that is OpenGL ES.
 // that is OpenGL ES.
 
 
 #include "pandabase.h"
 #include "pandabase.h"
-#include "config_iphone.h"
+#include "config_iphonedisplay.h"
 
 
 #define GLP(name) gl##name
 #define GLP(name) gl##name
 #define GLUP(name) glu##name
 #define GLUP(name) glu##name
@@ -27,10 +27,10 @@
 #define GLPREFIX_QUOTED "gl"
 #define GLPREFIX_QUOTED "gl"
 #define CLASSPREFIX_QUOTED "GLES"
 #define CLASSPREFIX_QUOTED "GLES"
 #define GLSYSTEM_NAME "OpenGL ES"
 #define GLSYSTEM_NAME "OpenGL ES"
-#define CONFIGOBJ config_iphone
-#define GLCAT iphone_cat
-#define EXPCL_GL EXPCL_PANDAGL
-#define EXPTP_GL EXPTP_PANDAGL
+#define CONFIGOBJ config_iphonedisplay
+#define GLCAT iphonedisplay_cat
+#define EXPCL_GL EXPCL_MISC
+#define EXPTP_GL EXPTP_MISC
 #define OPENGLES_1
 #define OPENGLES_1
 #undef HAVE_GLU
 #undef HAVE_GLU
 
 

+ 0 - 0
panda/src/iphone/glesgsg.mm → panda/src/iphonedisplay/glesgsg.mm


+ 1 - 1
panda/src/iphone/iPhoneGraphicsPipe.h → panda/src/iphonedisplay/iPhoneGraphicsPipe.h

@@ -31,7 +31,7 @@ class PNMImage;
 //               creating OpenGL graphics windows on the various
 //               creating OpenGL graphics windows on the various
 //               IPHONE's.
 //               IPHONE's.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-class EXPCL_PANDAGL IPhoneGraphicsPipe : public GraphicsPipe {
+class EXPCL_MISC IPhoneGraphicsPipe : public GraphicsPipe {
 public:
 public:
   IPhoneGraphicsPipe();
   IPhoneGraphicsPipe();
   virtual ~IPhoneGraphicsPipe();
   virtual ~IPhoneGraphicsPipe();

+ 1 - 1
panda/src/iphone/iPhoneGraphicsPipe.mm → panda/src/iphonedisplay/iPhoneGraphicsPipe.mm

@@ -13,7 +13,7 @@
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 
 
 #include "iPhoneGraphicsPipe.h"
 #include "iPhoneGraphicsPipe.h"
-#include "config_iphone.h"
+#include "config_iphonedisplay.h"
 #include "iPhoneGraphicsWindow.h"
 #include "iPhoneGraphicsWindow.h"
 #include "iPhoneGraphicsStateGuardian.h"
 #include "iPhoneGraphicsStateGuardian.h"
 #include "pnmImage.h"
 #include "pnmImage.h"

+ 0 - 0
panda/src/iphone/iPhoneGraphicsStateGuardian.h → panda/src/iphonedisplay/iPhoneGraphicsStateGuardian.h


+ 1 - 1
panda/src/iphone/iPhoneGraphicsStateGuardian.mm → panda/src/iphonedisplay/iPhoneGraphicsStateGuardian.mm

@@ -14,7 +14,7 @@
 
 
 #include "iPhoneGraphicsStateGuardian.h"
 #include "iPhoneGraphicsStateGuardian.h"
 #include "string_utils.h"
 #include "string_utils.h"
-#include "config_iphone.h"
+#include "config_iphonedisplay.h"
 #include "depthWriteAttrib.h"
 #include "depthWriteAttrib.h"
 #include "depthTestAttrib.h"
 #include "depthTestAttrib.h"
 #include "textureAttrib.h"
 #include "textureAttrib.h"

+ 0 - 0
panda/src/iphone/iPhoneGraphicsWindow.I → panda/src/iphonedisplay/iPhoneGraphicsWindow.I


+ 0 - 0
panda/src/iphone/iPhoneGraphicsWindow.h → panda/src/iphonedisplay/iPhoneGraphicsWindow.h


+ 5 - 6
panda/src/iphone/iPhoneGraphicsWindow.mm → panda/src/iphonedisplay/iPhoneGraphicsWindow.mm

@@ -21,7 +21,7 @@
 
 
 #include "iPhoneGraphicsWindow.h"
 #include "iPhoneGraphicsWindow.h"
 #include "dcast.h"
 #include "dcast.h"
-#include "config_iphone.h"
+#include "config_iphonedisplay.h"
 #include "iPhoneGraphicsPipe.h"
 #include "iPhoneGraphicsPipe.h"
 #include "pStatTimer.h"
 #include "pStatTimer.h"
 #include "glesgsg.h"
 #include "glesgsg.h"
@@ -92,8 +92,7 @@ begin_frame(FrameMode mode, Thread *current_thread) {
   begin_frame_spam(mode);
   begin_frame_spam(mode);
   if (_gsg == (GraphicsStateGuardian *)NULL) {
   if (_gsg == (GraphicsStateGuardian *)NULL) {
     // not powered up .. just abort..
     // not powered up .. just abort..
-    iphone_cat.info() << "no gsg\n";
-    return false;
+   return false;
   }
   }
 
 
   _gsg->reset_if_new();
   _gsg->reset_if_new();
@@ -180,10 +179,10 @@ process_events() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void IPhoneGraphicsWindow::
 void IPhoneGraphicsWindow::
 set_properties_now(WindowProperties &properties) {
 set_properties_now(WindowProperties &properties) {
-  if (iphone_cat.is_debug()) {
-    iphone_cat.debug()
+  if (iphonedisplay_cat.is_debug()) {
+    iphonedisplay_cat.debug()
       << "------------------------------------------------------\n";
       << "------------------------------------------------------\n";
-    iphone_cat.debug()
+    iphonedisplay_cat.debug()
       << "set_properties_now " << properties << "\n";
       << "set_properties_now " << properties << "\n";
   }
   }
  
  

+ 0 - 0
panda/src/iphone/viewController.h → panda/src/iphonedisplay/viewController.h


+ 1 - 1
panda/src/iphone/viewController.mm → panda/src/iphonedisplay/viewController.mm

@@ -15,7 +15,7 @@
 #import "viewController.h" 
 #import "viewController.h" 
 #include "pnotify.h"
 #include "pnotify.h"
 #include "iPhoneGraphicsPipe.h"
 #include "iPhoneGraphicsPipe.h"
-#include "config_iphone.h"
+#include "config_iphonedisplay.h"
 
 
 @implementation ControllerDemoViewController 
 @implementation ControllerDemoViewController 
 
 

+ 9 - 0
panda/src/pipeline/thread.cxx

@@ -68,8 +68,10 @@ Thread(const string &name, const string &sync_name) :
 #if defined(HAVE_PYTHON) && !defined(SIMPLE_THREADS)
 #if defined(HAVE_PYTHON) && !defined(SIMPLE_THREADS)
   // Ensure that the Python threading system is initialized and ready
   // Ensure that the Python threading system is initialized and ready
   // to go.
   // to go.
+#ifdef WITH_THREAD  // This symbol defined within Python.h
   PyEval_InitThreads();
   PyEval_InitThreads();
 #endif
 #endif
+#endif
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -315,6 +317,12 @@ call_python_func(PyObject *function, PyObject *args) {
     }
     }
 
 
   } else {
   } else {
+#ifndef HAVE_THREADS
+    // Shouldn't be possible to come here without having some kind of
+    // threading support enabled.
+    nassertr(false, NULL);
+#else
+
 #ifdef SIMPLE_THREADS
 #ifdef SIMPLE_THREADS
     // We can't use the PyGILState interface, which assumes we are
     // We can't use the PyGILState interface, which assumes we are
     // using true OS-level threading.  PyGILState enforces policies
     // using true OS-level threading.  PyGILState enforces policies
@@ -397,6 +405,7 @@ call_python_func(PyObject *function, PyObject *args) {
     
     
 
 
 #endif  // SIMPLE_THREADS
 #endif  // SIMPLE_THREADS
+#endif  // HAVE_THREADS
   }
   }
 
 
   return result;
   return result;

+ 2 - 0
panda/src/putil/pythonCallbackObject.cxx

@@ -40,8 +40,10 @@ PythonCallbackObject(PyObject *function) {
 #ifndef SIMPLE_THREADS
 #ifndef SIMPLE_THREADS
   // Ensure that the Python threading system is initialized and ready
   // Ensure that the Python threading system is initialized and ready
   // to go.
   // to go.
+#ifdef WITH_THREAD  // This symbol defined within Python.h
   PyEval_InitThreads();
   PyEval_InitThreads();
 #endif
 #endif
+#endif
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////