http://www.jwz.org/xscreensaver/xscreensaver-5.07.tar.gz
[xscreensaver] / hacks / xlockmoreI.h
1 /* xlockmore.h --- xscreensaver compatibility layer for xlockmore modules.
2  * xscreensaver, Copyright (c) 1997-2008 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
69
70 /* Compatibility with the xlockmore RNG API
71    (note that the xlockmore hacks never expect negative numbers.)
72  */
73 #define LRAND()                 ((long) (random() & 0x7fffffff))
74 #define NRAND(n)                ((int) (LRAND() % (n)))
75 #define MAXRAND                 (2147483648.0) /* unsigned 1<<31 as a float */
76 #define SRAND(n)                /* already seeded by screenhack.c */
77
78
79 struct ModeInfo {
80   struct xlockmore_function_table *xlmft;
81   Display *dpy;
82   Window window;
83   Bool root_p;
84   int num_screens;
85   int screen_number;
86   int npixels;
87   unsigned long *pixels;
88   XColor *colors;
89   Bool writable_p;
90   unsigned long white;
91   unsigned long black;
92   XWindowAttributes xgwa;
93   GC gc;
94   long pause;
95   Bool fullrandom;
96   long cycles;
97   long batchcount;
98   long size;
99   Bool threed;
100   long threed_left_color;
101   long threed_right_color;
102   long threed_both_color;
103   long threed_none_color;
104   long threed_delta;
105   Bool wireframe_p;
106   Bool is_drawn;
107
108   /* Used only by OpenGL programs, since FPS is tricky there. */
109   fps_state *fpst;
110   Bool fps_p;
111   unsigned long polygon_count;
112
113 #ifdef HAVE_XSHM_EXTENSION
114   Bool use_shm;
115   XShmSegmentInfo shm_info;
116 #endif
117 };
118
119 typedef enum {  t_String, t_Float, t_Int, t_Bool } xlockmore_type;
120
121 typedef struct {
122   void *var;
123   char *name;
124   char *classname;
125   char *def;
126   xlockmore_type type;
127 } argtype;
128
129 typedef struct {
130   char *opt;
131   char *desc;
132 } OptionStruct;
133
134 typedef struct {
135   int numopts;
136   XrmOptionDescRec *opts;
137   int numvarsdesc;
138   argtype *vars;
139   OptionStruct *desc;
140 } ModeSpecOpt;
141
142 struct xlockmore_function_table {
143   const char *progclass;
144   const char *defaults;
145   Bool want_writable_colors;
146   enum { color_scheme_default, color_scheme_uniform, 
147          color_scheme_smooth, color_scheme_bright }
148     desired_color_scheme;
149   void (*hack_init) (ModeInfo *);
150   void (*hack_draw) (ModeInfo *);
151   void (*hack_reshape) (ModeInfo *, int, int);
152   void (*hack_refresh) (ModeInfo *);
153   void (*hack_free) (ModeInfo *);
154   Bool (*hack_handle_events) (ModeInfo *, XEvent *);
155   ModeSpecOpt *opts;
156 };
157
158 #endif /* __XLOCKMORE_INTERNAL_H__ */