From http://www.jwz.org/xscreensaver/xscreensaver-5.15.tar.gz
[xscreensaver] / hacks / xlockmoreI.h
1 /* xlockmore.h --- xscreensaver compatibility layer for xlockmore modules.
2  * xscreensaver, Copyright (c) 1997-2011 Jamie Zawinski <jwz@jwz.org>
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation.  No representations are made about the suitability of this
9  * software for any purpose.  It is provided "as is" without express or 
10  * implied warranty.
11  *
12  * See xlockmore.h and xlockmore.c.
13  */
14
15 #ifndef __XLOCKMORE_INTERNAL_H__
16 #define __XLOCKMORE_INTERNAL_H__
17
18 #include <time.h>
19
20 #include "screenhackI.h"
21
22 #ifdef HAVE_XSHM_EXTENSION
23 # include "xshm.h"
24 #endif /* HAVE_XSHM_EXTENSION */
25
26
27 typedef struct ModeInfo ModeInfo;
28
29 #ifdef USE_GL
30
31 /* I'm told that the Sun version of OpenGL needs to have the constant
32    SUN_OGL_NO_VERTEX_MACROS defined in order for morph3d to compile
33    (the number of arguments to the glNormal3f macro changes...)
34    Verified with gcc 2.7.2.2 and Sun cc 4.2 with OpenGL 1.1.1 dev 4
35    on Solaris 2.5.1.
36  */
37 # ifndef HAVE_MESA_GL
38 #  if defined(__sun) && defined(__SVR4) /* Solaris */
39 #   define SUN_OGL_NO_VERTEX_MACROS 1
40 #  endif /* Solaris */
41 # endif /* !HAVE_MESA_GL */
42
43 # ifdef HAVE_COCOA
44 #  include <OpenGL/gl.h>
45 # else
46 #  include <GL/gl.h>
47 #  include <GL/glx.h>
48 # endif
49
50   extern GLXContext *init_GL (ModeInfo *);
51   extern void clear_gl_error (void);
52   extern void check_gl_error (const char *type);
53
54   extern Visual *xlockmore_pick_gl_visual (Screen *);
55   extern Bool xlockmore_validate_gl_visual (Screen *, const char *, Visual *);
56
57 #endif /* !USE_GL */
58
59 /* These are only used in GL mode, but I don't understand why XCode
60    isn't seeing the prototypes for them in glx/fps-gl.c... */
61 extern void do_fps (ModeInfo *);
62 extern void xlockmore_gl_compute_fps (Display *, Window, fps_state *, void *);
63 extern void xlockmore_gl_draw_fps (ModeInfo *);
64 # define do_fps xlockmore_gl_draw_fps
65
66
67 extern void xlockmore_setup (struct xscreensaver_function_table *, void *);
68 extern void xlockmore_do_fps (Display *, Window, fps_state *, void *);
69
70
71 /* Compatibility with the xlockmore RNG API
72    (note that the xlockmore hacks never expect negative numbers.)
73  */
74 #define LRAND()                 ((long) (random() & 0x7fffffff))
75 #define NRAND(n)                ((int) (LRAND() % (n)))
76 #define MAXRAND                 (2147483648.0) /* unsigned 1<<31 as a float */
77 #define SRAND(n)                /* already seeded by screenhack.c */
78
79
80 struct ModeInfo {
81   struct xlockmore_function_table *xlmft;
82   Display *dpy;
83   Window window;
84   Bool root_p;
85   int num_screens;
86   int screen_number;
87   int npixels;
88   unsigned long *pixels;
89   XColor *colors;
90   Bool writable_p;
91   unsigned long white;
92   unsigned long black;
93   XWindowAttributes xgwa;
94   GC gc;
95   long pause;
96   Bool fullrandom;
97   long cycles;
98   long batchcount;
99   long size;
100   Bool threed;
101   long threed_left_color;
102   long threed_right_color;
103   long threed_both_color;
104   long threed_none_color;
105   long threed_delta;
106   Bool wireframe_p;
107   Bool is_drawn;
108
109   /* Used only by OpenGL programs, since FPS is tricky there. */
110   fps_state *fpst;
111   Bool fps_p;
112   unsigned long polygon_count;  /* These values are for -fps display only */
113   double recursion_depth;
114
115 #ifdef HAVE_XSHM_EXTENSION
116   Bool use_shm;
117   XShmSegmentInfo shm_info;
118 #endif
119 };
120
121 typedef enum {  t_String, t_Float, t_Int, t_Bool } xlockmore_type;
122
123 typedef struct {
124   void *var;
125   char *name;
126   char *classname;
127   char *def;
128   xlockmore_type type;
129 } argtype;
130
131 typedef struct {
132   char *opt;
133   char *desc;
134 } OptionStruct;
135
136 typedef struct {
137   int numopts;
138   XrmOptionDescRec *opts;
139   int numvarsdesc;
140   argtype *vars;
141   OptionStruct *desc;
142 } ModeSpecOpt;
143
144 struct xlockmore_function_table {
145   const char *progclass;
146   const char *defaults;
147   Bool want_writable_colors;
148   enum { color_scheme_default, color_scheme_uniform, 
149          color_scheme_smooth, color_scheme_bright }
150     desired_color_scheme;
151   void (*hack_init) (ModeInfo *);
152   void (*hack_draw) (ModeInfo *);
153   void (*hack_reshape) (ModeInfo *, int, int);
154   void (*hack_refresh) (ModeInfo *);
155   void (*hack_free) (ModeInfo *);
156   Bool (*hack_handle_events) (ModeInfo *, XEvent *);
157   ModeSpecOpt *opts;
158 };
159
160 #endif /* __XLOCKMORE_INTERNAL_H__ */