From http://www.jwz.org/xscreensaver/xscreensaver-5.38.tar.gz
[xscreensaver] / hacks / xlockmoreI.h
1 /* xlockmore.h --- xscreensaver compatibility layer for xlockmore modules.
2  * xscreensaver, Copyright (c) 1997-2017 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 #include "erase.h"
22
23
24 typedef struct ModeInfo ModeInfo;
25
26 #ifdef HAVE_GL
27
28 /* I'm told that the Sun version of OpenGL needs to have the constant
29    SUN_OGL_NO_VERTEX_MACROS defined in order for morph3d to compile
30    (the number of arguments to the glNormal3f macro changes...)
31    Verified with gcc 2.7.2.2 and Sun cc 4.2 with OpenGL 1.1.1 dev 4
32    on Solaris 2.5.1.
33  */
34 # ifndef HAVE_MESA_GL
35 #  if defined(__sun) && defined(__SVR4) /* Solaris */
36 #   define SUN_OGL_NO_VERTEX_MACROS 1
37 #  endif /* Solaris */
38 # endif /* !HAVE_MESA_GL */
39
40 # ifdef HAVE_COCOA
41 #  ifndef USE_IPHONE
42 #   include <OpenGL/gl.h>
43 #   include <OpenGL/glu.h>
44 #  endif
45 # elif defined(HAVE_ANDROID)
46 #  include <GLES/gl.h>
47 # else
48 #  include <GL/gl.h>
49 #  include <GL/glu.h>
50 #  include <GL/glx.h>
51 # endif
52
53 # ifdef HAVE_JWZGLES
54 #  include "jwzgles.h"
55 # endif /* HAVE_JWZGLES */
56 #endif /* HAVE_GL */
57
58
59 #ifdef USE_GL
60
61   extern GLXContext *init_GL (ModeInfo *);
62   extern void xlockmore_reset_gl_state(void);
63   extern void clear_gl_error (void);
64   extern void check_gl_error (const char *type);
65
66   extern Visual *xlockmore_pick_gl_visual (Screen *);
67   extern Bool xlockmore_validate_gl_visual (Screen *, const char *, Visual *);
68
69 #endif /* USE_GL */
70
71 /* These are only used in GL mode, but I don't understand why XCode
72    isn't seeing the prototypes for them in glx/fps-gl.c... */
73 extern void do_fps (ModeInfo *);
74 extern void xlockmore_gl_compute_fps (Display *, Window, fps_state *, void *);
75 extern void xlockmore_gl_draw_fps (ModeInfo *);
76 # define do_fps xlockmore_gl_draw_fps
77
78
79 extern void xlockmore_setup (struct xscreensaver_function_table *, void *);
80 extern void xlockmore_do_fps (Display *, Window, fps_state *, void *);
81 extern void xlockmore_mi_init (ModeInfo *, size_t, void **);
82 extern Bool xlockmore_no_events (ModeInfo *, XEvent *);
83
84
85 /* The xlockmore RNG API is implemented in utils/yarandom.h. */
86
87
88 struct ModeInfo {
89   struct xlockmore_function_table *xlmft;
90   Display *dpy;
91   Window window;
92   Bool root_p;
93   int screen_number;
94   int npixels;
95   unsigned long *pixels;
96   XColor *colors;
97   Bool writable_p;
98   unsigned long white;
99   unsigned long black;
100   XWindowAttributes xgwa;
101   GC gc;
102   long pause;
103   Bool fullrandom;
104   long cycles;
105   long batchcount;
106   long size;
107   Bool threed;
108   long threed_left_color;
109   long threed_right_color;
110   long threed_both_color;
111   long threed_none_color;
112   long threed_delta;
113   Bool wireframe_p;
114   Bool is_drawn;
115   eraser_state *eraser;
116   Bool needs_clear;
117
118   /* Used only by OpenGL programs, since FPS is tricky there. */
119   fps_state *fpst;
120   Bool fps_p;
121   unsigned long polygon_count;  /* These values are for -fps display only */
122   double recursion_depth;
123 #if !defined HAVE_JWXYZ && defined HAVE_GL
124   GLXContext glx_context;
125 #endif
126 };
127
128 typedef enum {  t_String, t_Float, t_Int, t_Bool } xlockmore_type;
129
130 typedef struct {
131   void *var;
132   char *name;
133   char *classname;
134   char *def;
135   xlockmore_type type;
136 } argtype;
137
138 typedef struct {
139   char *opt;
140   char *desc;
141 } OptionStruct;
142
143 typedef struct {
144   int numopts;
145   XrmOptionDescRec *opts;
146   int numvarsdesc;
147   argtype *vars;
148   OptionStruct *desc;
149 } ModeSpecOpt;
150
151 struct xlockmore_function_table {
152   const char *progclass;
153   const char *defaults;
154   Bool want_writable_colors;
155   enum { color_scheme_default, color_scheme_uniform, 
156          color_scheme_smooth, color_scheme_bright }
157     desired_color_scheme;
158   void (*hack_init) (ModeInfo *);
159   void (*hack_draw) (ModeInfo *);
160   void (*hack_reshape) (ModeInfo *, int, int);
161   void (*hack_release) (ModeInfo *);
162   void (*hack_free) (ModeInfo *);
163   Bool (*hack_handle_events) (ModeInfo *, XEvent *);
164   ModeSpecOpt *opts;
165
166   void **state_array;
167   unsigned long live_displays, got_init;
168 };
169
170 #ifdef HAVE_JWXYZ
171 # define XLOCKMORE_NUM_SCREENS  \
172   (sizeof(((struct xlockmore_function_table *)0)->live_displays) * 8)
173 #else
174 # define XLOCKMORE_NUM_SCREENS  2 /* For DEBUG_PAIR. */
175 #endif
176
177 #endif /* __XLOCKMORE_INTERNAL_H__ */