From http://www.jwz.org/xscreensaver/xscreensaver-5.31.tar.gz
[xscreensaver] / OSX / XScreenSaverGLView.m
index 7ec10090624b18cb61f76bb24c018ffb38c5ab23..7af44038bc7c900eacd57a184f1b7657240c0939 100644 (file)
@@ -1,13 +1,13 @@
-/* xscreensaver, Copyright (c) 2006-2013 Jamie Zawinski <jwz@jwz.org>
-*
-* Permission to use, copy, modify, distribute, and sell this software and its
-* documentation for any purpose is hereby granted without fee, provided that
-* the above copyright notice appear in all copies and that both that
-* copyright notice and this permission notice appear in supporting
-* documentation.  No representations are made about the suitability of this
-* software for any purpose.  It is provided "as is" without express or 
-* implied warranty.
-*/
+/* xscreensaver, Copyright (c) 2006-2014 Jamie Zawinski <jwz@jwz.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation.  No representations are made about the suitability of this
+ * software for any purpose.  It is provided "as is" without express or 
+ * implied warranty.
+ */
 
 /* This is a subclass of Apple's ScreenSaverView that knows how to run
    xscreensaver programs without X11 via the dark magic of the "jwxyz"
@@ -223,26 +223,15 @@ extern void check_gl_error (const char *type);
    and discarded.  That's ok, though, because mostly it's just calls to
    XClearWindow and housekeeping stuff like that.  So we make a tiny one.
  */
-- (void) createBackbuffer
+- (void) createBackbuffer:(CGSize)new_size
 {
-  // Don't resize the X11 window to match rotation. 
-  // Rotation and scaling are handled in GL.
-  //
-# ifdef USE_IPHONE
-  double s = [self hackedContentScaleFactor];
-# else
-  double s = 1;
-# endif
-  // Store a realistic size in backbuffer_size, though the buffer is minimal.
-  NSRect f = [self bounds];
-  backbuffer_size.width  = (int) (s * f.size.width);
-  backbuffer_size.height = (int) (s * f.size.height);
+  backbuffer_size = new_size;
 
   if (! backbuffer) {
     CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
     int w = 8;
     int h = 8;
-    backbuffer = CGBitmapContextCreate (NULL, w, h,
+    backbuffer = CGBitmapContextCreate (NULL, w, h,   // yup, only 8px x 8px.
                                         8, w*4, cs,
                                         kCGImageAlphaPremultipliedLast);
     CGColorSpaceRelease (cs);
@@ -251,6 +240,16 @@ extern void check_gl_error (const char *type);
 # endif // USE_BACKBUFFER
 
 
+/* When changing the device orientation, leave the X11 Window and glViewport
+   in portrait configuration.  OpenGL hacks examine current_device_rotation()
+   within the scene as needed.
+ */
+- (BOOL)reshapeRotatedWindow
+{
+  return NO;
+}
+
+
 - (void)dealloc {
   // ogl_ctx
   // gl_framebuffer
@@ -415,8 +414,21 @@ init_GL (ModeInfo *mi)
 
   check_gl_error ("OES_init");
 
+  jwzgles_reset ();
+  
 # endif // USE_IPHONE
 
+  // I don't know why this is necessary, but it beats randomly having some
+  // textures be upside down.
+  //
+  glMatrixMode(GL_TEXTURE);
+  glLoadIdentity();
+  glMatrixMode(GL_PROJECTION);
+  glLoadIdentity();
+  glMatrixMode(GL_MODELVIEW);
+  glLoadIdentity();
+
+
   // Caller expects a pointer to an opaque struct...  which it dereferences.
   // Don't ask me, it's historical...
   static int blort = -1;