From http://www.jwz.org/xscreensaver/xscreensaver-5.35.tar.gz
[xscreensaver] / hacks / glx / grab-ximage.c
index 9fca3c811eccff0e2f1fddabeae93e9f52c6a3a2..f57bd9aa5436ce770f78dbb13cc93db0c785d5f7 100644 (file)
 #include <stdio.h>
 #include <string.h>
 
-#ifdef HAVE_COCOA
+#ifdef HAVE_ANDROID
+#include <GLES/gl.h>
+#endif
+
+#ifdef HAVE_JWXYZ
 # include "jwxyz.h"
-# include <OpenGL/gl.h>
-# include <OpenGL/glu.h>
+# ifndef HAVE_JWZGLES
+#  include <OpenGL/glu.h>
+# endif
 #else
 # include <X11/Xlib.h>
 # include <X11/Xutil.h>
 # include <GL/glx.h>   /* for glXMakeCurrent() */
 #endif
 
+#ifdef HAVE_JWZGLES
+# include "jwzgles.h"
+#endif /* HAVE_JWZGLES */
+
 #include "grab-ximage.h"
 #include "grabscreen.h"
 #include "visual.h"
@@ -65,7 +74,7 @@ extern char *progname;
 
 #include <sys/time.h>
 
-#ifdef HAVE_COCOA
+#ifdef HAVE_JWXYZ
 # include "jwxyz.h"
 #else
 # include <X11/Xutil.h>
@@ -94,7 +103,8 @@ bigendian (void)
 /* Given a bitmask, returns the position and width of the field.
  */
 static void
-decode_mask (unsigned int mask, unsigned int *pos_ret, unsigned int *size_ret)
+decode_mask (unsigned long mask, unsigned long *pos_ret,
+             unsigned long *size_ret)
 {
   int i;
   for (i = 0; i < 32; i++)
@@ -137,11 +147,10 @@ convert_ximage_to_rgba32 (Screen *screen, XImage *image)
   Visual *visual = DefaultVisualOfScreen (screen);
 
   int x, y;
-  unsigned int crpos=0, cgpos=0, cbpos=0, capos=0; /* bitfield positions */
-  unsigned int srpos=0, sgpos=0, sbpos=0;
-  unsigned int srmsk=0, sgmsk=0, sbmsk=0;
-  unsigned int srsiz=0, sgsiz=0, sbsiz=0;
-  int i;
+  unsigned long crpos=0, cgpos=0, cbpos=0, capos=0; /* bitfield positions */
+  unsigned long srpos=0, sgpos=0, sbpos=0;
+  unsigned long srmsk=0, sgmsk=0, sbmsk=0;
+  unsigned long srsiz=0, sgsiz=0, sbsiz=0;
   XColor *colors = 0;
   unsigned char spread_map[3][256];
 
@@ -193,6 +202,7 @@ convert_ximage_to_rgba32 (Screen *screen, XImage *image)
 
   if (colors == 0)  /* truecolor */
     {
+      int i;
       for (i = 0; i < 256; i++)
         {
           spread_map[0][i] = spread_bits (i, srsiz);
@@ -524,15 +534,11 @@ double_time (void)
 
 /* return the next larger power of 2. */
 static int
-to_pow2 (int i)
+to_pow2 (int value)
 {
-  static const unsigned int pow2[] = { 
-    1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 
-    2048, 4096, 8192, 16384, 32768, 65536 };
-  int j;
-  for (j = 0; j < countof(pow2); j++)
-    if (pow2[j] >= i) return pow2[j];
-  abort();  /* too big! */
+  int i = 1;
+  while (i < value) i <<= 1;
+  return i;
 }
 
 
@@ -587,7 +593,7 @@ ximage_to_texture (XImage *ximage,
                  progname, ximage->width, ximage->height,
                  tex_width, tex_height);
 
-      glTexImage2D (GL_TEXTURE_2D, 0, 3, tex_width, tex_height, 0,
+      glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, tex_width, tex_height, 0,
                     format, type, 0);
       err = glGetError();