FreeWRL/FreeX3D  3.0.0
display.h
1 /*
2 
3  FreeWRL support library.
4 
5 Purpose:
6  Handle platform specific includes about windowing systems and OpenGL.
7  Try to present a generic interface to the rest of FreeWRL library.
8 
9 Data:
10 
11 Functions:
12 
13 */
14 
15 /****************************************************************************
16  This file is part of the FreeWRL/FreeX3D Distribution.
17 
18  Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
19 
20  FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
21  it under the terms of the GNU Lesser Public License as published by
22  the Free Software Foundation, either version 3 of the License, or
23  (at your option) any later version.
24 
25  FreeWRL/FreeX3D is distributed in the hope that it will be useful,
26  but WITHOUT ANY WARRANTY; without even the implied warranty of
27  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28  GNU General Public License for more details.
29 
30  You should have received a copy of the GNU General Public License
31  along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
32 ****************************************************************************/
33 
34 #if 1 || defined(HAVE_FV_INLIB)
35 #define KEEP_FV_INLIB 1
36 #define KEEP_X11_INLIB 1
37 #else
38 #define KEEP_FV_INLIB 0
39 #define KEEP_X11_INLIB 0
40 #endif
41 
42 #ifndef __LIBFREEWRL_DISPLAY_H__
43 #define __LIBFREEWRL_DISPLAY_H__
44 
45 /* this is platform-dependent but there is no default so set one here */
46 #ifndef MAX_MULTITEXTURE
47 #define MAX_MULTITEXTURE 4
48 #endif
49 
50 #ifdef GL_ES_VERSION_2_0
51 #define MAX_LIGHTS 6
52 #define STR_MAX_LIGHTS "\n#define MAX_LIGHTS 6\n "
53 #define MAX_LIGHT_STACK 8 //making this larger than MAX_LIGHTS means we can visit all the local lights and use the last one on the stack/most local (or 2 if headlight off)
54 #define HEADLIGHT_LIGHT (MAX_LIGHT_STACK-1)
55 #else
56 #define MAX_LIGHTS 8 //8 lights is 1152bytes transfered to GPU shader per shape draw - 11% of mainloop load on pentium class PC with card in old-style 32bit PCI expansion slot
57 #define STR_MAX_LIGHTS "\n#define MAX_LIGHTS 8\n "
58 #define MAX_LIGHT_STACK 8 //going down the transform stack, up to 7 local lights, with most-local as last
59 #define HEADLIGHT_LIGHT (MAX_LIGHT_STACK-1)
60 #endif
61 
62 #ifdef AQUA // OLD_IPHONE_AQUA
63 OLD_IPHONE_AQUA
66 OLD_IPHONE_AQUA
67 OLD_IPHONE_AQUA #ifdef IPHONE
68 OLD_IPHONE_AQUA #include <OpenGLES/ES2/gl.h>
69 OLD_IPHONE_AQUA #include <OpenGLES/ES2/glext.h>
70 OLD_IPHONE_AQUA #include <OpenGLES/ES3/gl.h>
71 OLD_IPHONE_AQUA #include <OpenGLES/ES3/glext.h>
72 OLD_IPHONE_AQUA #else
73 OLD_IPHONE_AQUA
74 OLD_IPHONE_AQUA #include <OpenGL/OpenGL.h>
75 OLD_IPHONE_AQUA #include <OpenGL/CGLTypes.h>
76 OLD_IPHONE_AQUA
77 OLD_IPHONE_AQUA #include <AGL/AGL.h>
78 OLD_IPHONE_AQUA #endif /* defined IPHONE */
79 #endif /* defined TARGET_AQUA OLD_IPHONE_AQUA */
80 
81 #include <libFreeWRL.h>
82 
83 /* Some Windows-specific stuff */
84 #if defined(_MSC_VER) && defined(HAVE_GLEW_H) && !defined(ANGLEPROJECT)
85 #define GLEW_NO_GLU 1
86 #include <GL/glew.h>
87 #ifdef GLEW_MX
88 GLEWContext * glewGetContext();
89 #endif
90 #define ERROR 0
91 #endif /* TARGET_WIN32 */
92 
93 #if defined(__linux__) && !defined(_ANDROID) && !defined(ANDROIDNDK)
94 # define GL_GLEXT_PROTOTYPES 1
95 # include <GL/gl.h>
96 //JAS # include <GL/glu.h>
97 //JAS # include <GL/glext.h>
98 #include <../libtess/libtess2.h>
99 
100 # include <GL/glx.h>
101 /* original bits that were here; the above was moved from linux-specific section below
102  define GL_GLEXT_PROTOTYPES 1
103  include <GL/gl.h>
104  include <GL/glext.h>
105  include <GL/glx.h> */
106 #endif
107 
108 #if defined (_ANDROID) || defined(ANDROIDNDK) || defined (QNX) || defined(ANGLEPROJECT)
109  #include <GLES2/gl2.h>
110  #include <GLES2/gl2ext.h>
111 // #include <GLES3/gl3.h>
112 // #include <GLES3/gl3ext.h>
113 #endif
114 
115 
116 
117 
118 /* generic - OpenGL ES 2.0 does not have doubles */
119 #ifdef GL_ES_VERSION_2_0
120  #define GLDOUBLE double
121  #define DOUBLE_MAX fmax
122  #define DOUBLE_MIN fmin
123 #else
124  #define GLDOUBLE GLdouble
125  #define DOUBLE_MAX max
126  #define DOUBLE_MIN min
127 #endif
128 
129 
130 /* face culling */
131 #define CULL_FACE(v) /* printf ("nodeSolid %d getAppearanceProperties()->cullFace %d GL_FALSE %d FALSE %d\n",v,getAppearanceProperties()->cullFace,GL_FALSE,FALSE); */ \
132  if (v != getAppearanceProperties()->cullFace) { \
133  getAppearanceProperties()->cullFace = v; \
134  if (getAppearanceProperties()->cullFace == TRUE) {glEnable(GL_CULL_FACE);}\
135  else { glDisable(GL_CULL_FACE);} \
136  }
137  #define CULL_FACE_INITIALIZE getAppearanceProperties()->cullFace=FALSE; glDisable(GL_CULL_FACE);
138 
139 #define DISABLE_CULL_FACE CULL_FACE(FALSE)
140 #define ENABLE_CULL_FACE CULL_FACE(TRUE)
141 
142 #define GL_LIGHT_RADIUS 0xBEEF /* smile - my definition */
143 #define GL_SPOT_BEAMWIDTH 0xF00D /* smile - my definition */
144 #ifdef GL_ES_VERSION_2_0
145 #if !defined(PATH_MAX)
146  #define PATH_MAX 5000
147 #endif
148 
149  /* as we now do our own matrix manipulation, we can change these; note that OpenGL-ES 2.0 does not
150  have these by default */
151  #define GL_MODELVIEW 0x1700
152  #define GL_MODELVIEW_MATRIX 0x0BA6
153  #define GL_PROJECTION 0x1701
154  #define GL_PROJECTION_MATRIX 0x0BA7
155  #define GL_TEXTURE_MATRIX 0x0BA8
156 
157  /* same with material properties - we do our own, but need some constants, so... */
158  #define GL_SHININESS 0x1601
159  #define GL_DIFFUSE 0x1201
160  #define GL_AMBIENT 0x1200
161  #define GL_SPECULAR 0x1202
162  #define GL_EMISSION 0x1600
163  #define GL_ENABLE_BIT 0x00002000
164 
165  #define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8
166  #define GL_SEPARATE_SPECULAR_COLOR 0x81FA
167  #define GL_LIGHT_MODEL_TWO_SIDE 0x0B52
168  #define GL_LIGHT_MODEL_LOCAL_VIEWER 0x0B51
169  #define GL_LIGHT_MODEL_AMBIENT 0x0B53
170  #define GL_LIGHT0 0x4000
171 
172  /* and, one buffer only, not stereo viewing */
173  #define GL_BACK_LEFT GL_BACK
174  #define GL_BACK_RIGHT GL_BACK
175  #define GL_STEREO 0x0C33
176 
177  /* we do not do occlusion queries yet; have to figure this one out */
178  #define GL_QUERY_RESULT 0x8866
179  #define GL_QUERY_RESULT_AVAILABLE 0x8867
180  #define GL_SAMPLES_PASSED 0x8914
181 
182  /* and, we have shaders, but not OpenGL 2.0, so we just put these here */
183  #define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
184  #define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
185  #define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
186  #define GL_RGBA8 0x8058
187  #define GL_RGB8 0x8051
188  #define GL_BGR 0x80E0
189  #define GL_RGB5 0x8050
190 
191 #define GL_EDGE_FLAG_ARRAY 0x8079
192 #define GL_INDEX_ARRAY 0x8077
193 #define GL_FOG_COORD_ARRAY GL_FOG_COORDINATE_ARRAY
194 #define GL_SECONDARY_COLOR_ARRAY 0x845E
195  #define GL_LINE_STIPPLE 0x0B24
196  #define GL_VERTEX_ARRAY 0x8074
197  #define GL_NORMAL_ARRAY 0x8075
198  #define GL_TEXTURE_COORD_ARRAY 0x8078
199  #define GL_COLOR_ARRAY 0x8076
200  #define GL_OBJECT_LINEAR 0x2401
201  #define GL_EYE_LINEAR 0x2400
202  #define GL_REFLECTION_MAP 0x8512
203  #define GL_SPHERE_MAP 0x2402
204  #define GL_NORMAL_MAP 0x8511
205  #define GL_S 0x2000
206  #define GL_TEXTURE_GEN_MODE 0x2500
207  #define GL_T 0x2001
208  #define GL_TEXTURE_GEN_S 0x0C60
209  #define GL_TEXTURE_GEN_T 0x0C61
210  #define GL_TEXTURE_ENV 0x2300
211  #define GL_TEXTURE_ENV_MODE 0x2200
212  #define GL_MODULATE 0x2100
213  #define GL_COMBINE 0x8570
214  #define GL_COMBINE_RGB 0x8571
215  #define GL_SOURCE0_RGB 0x8580
216  #define GL_OPERAND0_RGB 0x8590
217  #define GL_SOURCE1_RGB 0x8581
218  #define GL_OPERAND1_RGB 0x8591
219  #define GL_COMBINE_ALPHA 0x8572
220  #define GL_SOURCE0_ALPHA 0x8588
221  #define GL_OPERAND0_ALPHA 0x8598
222  #define GL_RGB_SCALE 0x8573
223  #define GL_ALPHA_SCALE 0x0D1C
224  #define GL_SOURCE1_ALPHA 0x8589
225  #define GL_OPERAND1_ALPHA 0x8599
226  #define GL_TEXTURE_GEN_S 0x0C60
227  #define GL_TEXTURE_GEN_T 0x0C61
228  #define GL_PREVIOUS 0x8578
229  #define GL_ADD 0x0104
230  #define GL_SUBTRACT 0x84E7
231  #define GL_DOT3_RGB 0x86AE
232  #define GL_ADD_SIGNED 0x8574
233  #define GL_CLAMP 0x2900
234  #define GL_CLAMP_TO_BORDER 0x812D
235  #define GL_TEXTURE_WRAP_R 0x8072
236  #define GL_R 0x2002
237  #define GL_TEXTURE_GEN_R 0x0C62
238  #define GL_GENERATE_MIPMAP 0x8191
239  #define GL_TEXTURE_PRIORITY 0x8066
240  #define GL_TEXTURE_BORDER_COLOR 0x1004
241  #define GL_TEXTURE_INTERNAL_FORMAT 0x1003
242  #define GL_COMPRESSED_RGBA 0x84EE
243  #define GL_TEXTURE_COMPRESSION_HINT 0x84EF
244  #define GL_PROXY_TEXTURE_2D 0x8064
245  #define GL_TEXTURE_WIDTH 0x1000
246  #define GL_TEXTURE_HEIGHT 0x1001
247  #define GL_POSITION 0x1203
248  #define GL_SPOT_DIRECTION 0x1204
249 
250  #define GL_CONSTANT_ATTENUATION 0x1207
251  #define GL_LINEAR_ATTENUATION 0x1208
252  #define GL_QUADRATIC_ATTENUATION 0x1209
253  #define GL_SPOT_CUTOFF 0x1206
254  #define GL_COMPILE 0x1300
255  #define GL_FLAT 0x1D00
256  #define GL_SMOOTH 0x1D01
257  #define GL_LIST_BIT 0x00020000
258 
259  #define VERTEX_SHADER GL_VERTEX_SHADER
260  #define FRAGMENT_SHADER GL_FRAGMENT_SHADER
261  #define SHADER_SOURCE glShaderSource
262  #define COMPILE_SHADER glCompileShader
263  #define CREATE_PROGRAM glCreateProgram();
264  #define CREATE_SHADER glCreateShader
265  #define ATTACH_SHADER glAttachShader
266  #define LINK_SHADER glLinkProgram
267  #define DELETE_SHADER glDeleteShader
268  #define DELETE_PROGRAM glDeleteProgram
269  #define USE_SHADER(aaa) glUseProgram(aaa)
270  #define GET_SHADER_INFO glGetShaderiv
271  #define LINK_STATUS GL_LINK_STATUS
272  #define COMPILE_STATUS GL_COMPILE_STATUS
273  #define GET_UNIFORM(aaa,bbb) glGetUniformLocation(aaa,bbb)
274  #define GET_ATTRIB(aaa,bbb) glGetAttribLocation(aaa,bbb)
275  #define GLUNIFORM1I glUniform1i
276  #define GLUNIFORM1F glUniform1f
277  #define GLUNIFORM2F glUniform2f
278  #define GLUNIFORM3F glUniform3f
279  #define GLUNIFORM4F glUniform4f
280  #define GLUNIFORM1IV glUniform1iv
281  #define GLUNIFORM1FV glUniform1fv
282  #define GLUNIFORM2FV glUniform2fv
283  #define GLUNIFORM3FV glUniform3fv
284  #define GLUNIFORM4FV glUniform4fv
285  #define GLUNIFORMMATRIX4FV glUniformMatrix4fv
286  #define GLUNIFORMMATRIX3FV glUniformMatrix3fv
287 #endif
288 
289 /* OLD_IPHONE_AQUA
290  OLD_IPHONE_AQUA #if defined (_MSC_VER) || defined (TARGET_AQUA) || defined(IPHONE) || defined(_ANDROID) || defined(ANDROIDNDK) || defined(QNX) */
291 #if defined (_MSC_VER) || defined(_ANDROID) || defined(ANDROIDNDK) || defined(QNX) /* not win32, ie linux */
292  #include <libtess2.h>
293 #endif // linux spefcific for now
294 
295 /* Main initialization function */
296 /* int display_initialize(); */
297 #define IS_DISPLAY_INITIALIZED (gglobal()->display.display_initialized==TRUE)
298 
307 /* are we doing Vertex Buffer Objects? (VBOs) for OpenGL? */
308 //#define VERTEX_VBO 0
309 //#define NORMAL_VBO 1
310 //#define TEXTURE_VBO 2
311 //#define INDEX_VBO 3
312 //#define COLOR_VBO 4
313 //#define FOG_VBO 5
314 //#define VBO_COUNT 6
315 #define VERTEX_VBO 0
316 #define NORMAL_VBO 1
317 #define INDEX_VBO 2
318 #define COLOR_VBO 3
319 #define FOG_VBO 4
320 #define TEXTURE_VBO0 5
321 #define TEXTURE_VBO1 6
322 #define TEXTURE_VBO2 7
323 #define TEXTURE_VBO3 8
324 #define VBO_COUNT 9
325 
326 
327 void fv_setScreenDim(int wi, int he);
328 
329 int fv_open_display();
330 int fv_display_initialize(void);
331 int fv_display_initialize_desktop(void);
332 int fv_create_main_window(freewrl_params_t *d); //int argc, char *argv[]);
333 int fv_create_main_window2(freewrl_params_t *d, freewrl_params_t *share);
334 bool fv_create_GLcontext();
335 bool fv_bind_GLcontext();
336 void fv_swapbuffers(freewrl_params_t *d);
337 int fv_create_window_and_context(freewrl_params_t *params, freewrl_params_t *share);
338 void fv_change_GLcontext(freewrl_params_t* d);
339 /* end of "virtual" functions */
340 
341 /* OpenGL renderer capabilities */
342 
343 
344 typedef struct s_shader_capabilities{
345  GLint compiledOK;
346  GLuint myShaderProgram;
347 
348  GLint myMaterialAmbient;
349  GLint myMaterialDiffuse;
350  GLint myMaterialSpecular;
351  GLint myMaterialShininess;
352  GLint myMaterialEmission;
353 
354  GLint myMaterialBackAmbient;
355  GLint myMaterialBackDiffuse;
356  GLint myMaterialBackSpecular;
357  GLint myMaterialBackShininess;
358  GLint myMaterialBackEmission;
359 
360  GLint myPointSize;
361 
362  // do we need to send down light information?
363  bool haveLightInShader;
364 
365  GLint lightcount;
366  //GLint lightType;
367  GLint lightType[MAX_LIGHTS];
368  GLint lightAmbient[MAX_LIGHTS];
369  GLint lightDiffuse[MAX_LIGHTS];
370  GLint lightSpecular[MAX_LIGHTS];
371  GLint lightPosition[MAX_LIGHTS];
372  GLint lightSpotDir[MAX_LIGHTS];
373  GLint lightAtten[MAX_LIGHTS];
374  //GLint lightConstAtten[MAX_LIGHTS];
375  //GLint lightLinAtten[MAX_LIGHTS];
376  //GLint lightQuadAtten[MAX_LIGHTS];
377  GLint lightSpotCutoffAngle[MAX_LIGHTS];
378  GLint lightSpotBeamWidth[MAX_LIGHTS];
379  //GLint lightRadius;
380  GLint lightRadius[MAX_LIGHTS];
381 
382  GLint ModelViewMatrix;
383  GLint ProjectionMatrix;
384  GLint NormalMatrix;
385  GLint ModelViewInverseMatrix;
386  GLint TextureMatrix[MAX_MULTITEXTURE];
387  GLint Vertices;
388  GLint Normals;
389  GLint Colours;
390  GLint TexCoords[MAX_MULTITEXTURE];
391  GLint FogCoords; //Aug 2016
392 
393  GLint TextureUnit[MAX_MULTITEXTURE];
394  GLint TextureMode[MAX_MULTITEXTURE];
395  GLint TextureSource[MAX_MULTITEXTURE];
396  GLint TextureFunction[MAX_MULTITEXTURE];
397  GLint textureCount;
398  GLint multitextureColor;
399 
400  /* texture3D */
401  GLint tex3dTiles; //int[2] nx, ny number of tiles in x, y
402  GLint tex3dUseVertex; //bool flag when no 3D texture coords supplied, vertex shader should use vertex
403  GLint repeatSTR;
404  GLint magFilter;
405 
406  /* fill properties */
407  GLint hatchColour;
408  GLint hatchPercent;
409  GLint hatchScale;
410  GLint filledBool;
411  GLint hatchedBool;
412  GLint algorithm;
413 
414  /* TextureCoordinateGenerator type */
415  GLint texCoordGenType;
416 
417  GLint fogColor; //Aug 2016
418  GLint fogvisibilityRange;
419  GLint fogScale;
420  GLint fogType;
421  GLint fogHaveCoords;
422 
423  GLint clipplanes; //Sept 2016
424  GLint nclipplanes;
425 
426 /* attributes - reduce redundant state chage calls on GPU */
427 /*
428  need to ensure that all calls to glEnableVertexAttribArray
429  are tagged for redundancy - eg, in statusbarHud.c, etc.
430  before trying to reduce the glEnableVertexAttribArray and
431  glDisableVertexAttribArray calls.
432 
433  bool vertexAttribEnabled;
434  bool texCoordAttribEnabled;
435  bool colourAttribEnabled;
436  bool normalAttribEnabled;
437 */
438 
440 
441 typedef struct {
442 
443  const char *renderer; /* replace GL_REN */
444  const char *version;
445  const char *vendor;
446  const char *extensions;
447  float versionf;
448  bool have_GL_VERSION_1_1;
449  bool have_GL_VERSION_1_2;
450  bool have_GL_VERSION_1_3;
451  bool have_GL_VERSION_1_4;
452  bool have_GL_VERSION_1_5;
453  bool have_GL_VERSION_2_0;
454  bool have_GL_VERSION_2_1;
455  bool have_GL_VERSION_3_0;
456 
457  bool av_multitexture; /* Multi textures available ? */
458  bool av_npot_texture; /* Non power of 2 textures available ? */
459  bool av_texture_rect; /* Rectangle textures available ? */
460  bool av_occlusion_q; /* Occlusion query available ? */
461 
462  int texture_units;
463  int runtime_max_texture_size;
464  int system_max_texture_size;
465  float anisotropicDegree;
466 
467  GLboolean quadBuffer; /* does platform support quadbuffer? */
468 
470 
471 // JAS extern s_renderer_capabilities_t rdr_caps;
472 
473 bool initialize_rdr_caps();
474 void initialize_rdr_functions();
475 void rdr_caps_dump(s_renderer_capabilities_t *rdr_caps);
476 
477 
478 #ifdef TARGET_AQUA /* OLD_IPHONE_AQUA */
479 OLD_IPHONE_AQUA #ifndef IPHONE
480 OLD_IPHONE_AQUA
481 OLD_IPHONE_AQUA extern int ccurse;
482 OLD_IPHONE_AQUA extern int ocurse;
483 OLD_IPHONE_AQUA
484 OLD_IPHONE_AQUA //#define SCURSE 1
485 OLD_IPHONE_AQUA //#define ACURSE 0
486 OLD_IPHONE_AQUA
487 OLD_IPHONE_AQUA /* for handling Safari window changes at the top of the display event loop */
488 OLD_IPHONE_AQUA extern int PaneClipnpx;
489 OLD_IPHONE_AQUA extern int PaneClipnpy;
490 OLD_IPHONE_AQUA
491 OLD_IPHONE_AQUA extern int PaneClipct;
492 OLD_IPHONE_AQUA extern int PaneClipcb;
493 OLD_IPHONE_AQUA extern int PaneClipcr;
494 OLD_IPHONE_AQUA extern int PaneClipcl;
495 OLD_IPHONE_AQUA extern int PaneClipwidth;
496 OLD_IPHONE_AQUA extern int PaneClipheight;
497 OLD_IPHONE_AQUA extern int PaneClipChanged;
498 OLD_IPHONE_AQUA
499 OLD_IPHONE_AQUA #include "OpenGL/glu.h"
500 OLD_IPHONE_AQUA #endif
501 #endif /* OLD_IPHONE_AQUA TARGET_AQUA */
502 
506 #if defined(TARGET_X11) || defined(TARGET_MOTIF)
507 
512 # include <X11/Xlib.h>
513 # include <X11/Xutil.h>
514 # include <X11/keysym.h>
515 
516 
517 extern GLXContext GLcx;
518 
519 extern XEvent event;
520 extern long event_mask;
521 extern Display *Xdpy;
522 extern int Xscreen;
523 extern Window Xroot_window;
524 extern XVisualInfo *Xvi;
525 extern Colormap colormap;
526 extern Window Xwin;
527 extern Window GLwin;
528 extern XSetWindowAttributes attr;
529 extern unsigned long mask;
530 extern Atom WM_DELETE_WINDOW;
531 
532 void handle_Xevents(XEvent event);
533 
534 # ifdef HAVE_XF86_VMODE
535 # include <X11/extensions/xf86vmode.h>
536 extern int vmode_nb_modes;
537 extern XF86VidModeModeInfo **vmode_modes;
538 extern int vmode_mode_selected;
539 # endif /* HAVE_XF86_VMODE */
540 
541 # if defined(TARGET_MOTIF)
542 
546 # include <X11/Intrinsic.h>
547 # include <Xm/Xm.h>
548 
549 extern XtAppContext Xtcx;
550 
551 void getMotifWindowedGLwin(Window *win);
552 # define GET_GLWIN getMotifWindowedGLwin(&GLwin)
553 
554 # else /* defined(TARGET_MOTIF) */
555 
559 # define GET_GLWIN getBareWindowedGLwin(&GLwin)
560 
561 # endif /* defined(TARGET_MOTIF) */
562 
563 #endif /* defined(TARGET_X11) || defined(TARGET_MOTIF) */
564 
569 #if defined (FW_DEBUG)
570 
571  #if defined(_ANDROID)
572  #define PRINT_GL_ERROR_IF_ANY(_where) { \
573  GLenum _global_gl_err = glGetError(); \
574  while (_global_gl_err != GL_NO_ERROR) { \
575  if (_global_gl_err == GL_INVALID_ENUM) {DROIDDEBUG ("GL_INVALID_ENUM"); } \
576  else if (_global_gl_err == GL_INVALID_VALUE) {DROIDDEBUG("GL_INVALID_VALUE"); } \
577  else if (_global_gl_err == GL_INVALID_OPERATION) {DROIDDEBUG("GL_INVALID_OPERATION"); } \
578  else if (_global_gl_err == GL_OUT_OF_MEMORY) {DROIDDEBUG("GL_OUT_OF_MEMORY"); } \
579  else DROIDDEBUG("unknown error"); \
580  DROIDDEBUG(" here: %s (%s:%d)\n", _where,__FILE__,__LINE__); \
581  _global_gl_err = glGetError(); \
582  } \
583  }
584 
585  #else
586  #define PRINT_GL_ERROR_IF_ANY(_where) { \
587  GLenum _global_gl_err = glGetError(); \
588  while (_global_gl_err != GL_NO_ERROR) { \
589  if (_global_gl_err == GL_INVALID_ENUM) {printf ("GL_INVALID_ENUM"); } \
590  else if (_global_gl_err == GL_INVALID_VALUE) {printf ("GL_INVALID_VALUE"); } \
591  else if (_global_gl_err == GL_INVALID_OPERATION) {printf ("GL_INVALID_OPERATION"); } \
592  else if (_global_gl_err == GL_OUT_OF_MEMORY) {printf ("GL_OUT_OF_MEMORY"); } \
593  else printf ("unknown error"); \
594  printf(" here: %s (%s:%d)\n", _where,__FILE__,__LINE__); \
595  _global_gl_err = glGetError(); \
596  } \
597  }
598  #endif
599 
600 #else // FW_DEBUG
601  #define PRINT_GL_ERROR_IF_ANY(_where) /* do nothing */
602 #endif
603 
604 #define GL_ERROR_MSG (\
605  (glGetError() == GL_NO_ERROR)?"":\
606  (glGetError() == GL_INVALID_ENUM)?"GL_INVALID_ENUM":\
607  (glGetError() == GL_INVALID_VALUE)?"GL_INVALID_VALUE":\
608  (glGetError() == GL_INVALID_OPERATION)?"GL_INVALID_OPERATION":\
609  (glGetError() == GL_OUT_OF_MEMORY)?"GL_OUT_OF_MEMORY":\
610  "unknown GL_ERROR")
611 
612 void resetGeometry();
613 /* void setScreenDim(int wi, int he); */
614 
615 /* GLSL variables */
616 /* Versions 1.5 and above have shaders */
617 #ifdef GL_VERSION_2_0
618  #define VERTEX_SHADER GL_VERTEX_SHADER
619  #define FRAGMENT_SHADER GL_FRAGMENT_SHADER
620  #define SHADER_SOURCE glShaderSource
621  #define COMPILE_SHADER glCompileShader
622  #define CREATE_PROGRAM glCreateProgram();
623  #define CREATE_SHADER glCreateShader
624  #define ATTACH_SHADER glAttachShader
625  #define LINK_SHADER glLinkProgram
626  #define DELETE_SHADER glDeleteShader
627  #define DELETE_PROGRAM glDeleteProgram
628  #define USE_SHADER(aaa) glUseProgram(aaa)
629  #define GET_SHADER_INFO glGetShaderiv
630  #define LINK_STATUS GL_LINK_STATUS
631  #define COMPILE_STATUS GL_COMPILE_STATUS
632  #define GET_UNIFORM(aaa,bbb) glGetUniformLocation(aaa,bbb)
633  #define GET_ATTRIB(aaa,bbb) glGetAttribLocation(aaa,bbb)
634  #define GLUNIFORM1I glUniform1i
635  #define GLUNIFORM1F glUniform1f
636  #define GLUNIFORM2F glUniform2f
637  #define GLUNIFORM3F glUniform3f
638  #define GLUNIFORM4F glUniform4f
639  #define GLUNIFORM1IV glUniform1iv
640  #define GLUNIFORM1FV glUniform1fv
641  #define GLUNIFORM2FV glUniform2fv
642  #define GLUNIFORM3FV glUniform3fv
643  #define GLUNIFORM4FV glUniform4fv
644  #define GLUNIFORMMATRIX4FV glUniformMatrix4fv
645  #define GLUNIFORMMATRIX3FV glUniformMatrix3fv
646 
647 #else
648 #ifdef GL_VERSION_1_5
649  #define VERTEX_SHADER GL_VERTEX_SHADER_ARB
650  #define FRAGMENT_SHADER GL_FRAGMENT_SHADER_ARB
651  #define SHADER_SOURCE glShaderSourceARB
652  #define COMPILE_SHADER glCompileShaderARB
653  #define CREATE_PROGRAM glCreateProgramObjectARB();
654  #define CREATE_SHADER glCreateShaderARB
655  #define ATTACH_SHADER glAttachObjectARB
656  #define LINK_SHADER glLinkProgramARB
657  #define DELETE_SHADER glDeleteShaderARB
658  #define DELETE_PROGRAM glDeleteProgramARB
659  #define USE_SHADER(aaa) glUseProgramObjectARB(aaa)
660  #define CREATE_SHADER glCreateShaderObjectARB
661  #define GET_SHADER_INFO glGetObjectParameterivARB
662  #define LINK_STATUS GL_OBJECT_LINK_STATUS_ARB
663  #define COMPILE_STATUS GL_OBJECT_COMPILE_STATUS_ARB
664  #define GET_UNIFORM(aaa,bbb) glGetUniformLocationARB(aaa,bbb)
665  #define GET_ATTRIB(aaa,bbb) glGetAttribLocationARB(aaa,bbb)
666  #define GLUNIFORM1F glUniform1fARB
667  #define GLUNIFORM1I glUniform1iARB
668  #define GLUNIFORM2F glUniform2fARB
669  #define GLUNIFORM3F glUniform3fARB
670  #define GLUNIFORM4F glUniform4fARB
671  #define GLUNIFORM1IV glUniform1ivARB
672  #define GLUNIFORM1FV glUniform1fvARB
673  #define GLUNIFORM2FV glUniform2fvARB
674  #define GLUNIFORM3FV glUniform3fvARB
675  #define GLUNIFORM4FV glUniform4fvARB
676  #define GLUNIFORMMATRIX4FV glUniformMatrix4fvARB
677  #define GLUNIFORMMATRIX3FV glUniformMatrix3fvARB
678 #endif
679 #endif
680 
681 /* OpenGL-2.x and OpenGL-3.x "desktop" systems calls */
682  /****************************************************************/
683  /* First - any platform specifics to do? */
684  /****************************************************************/
685 
686  #if defined(_MSC_VER)
687  void fwMessageLoop();
688  #define FW_GL_SWAPBUFFERS fv_swapbuffers(gglobal()->display.params); //SwapBuffers(wglGetCurrentDC());
689  #endif
690 
691 #if KEEP_X11_INLIB
692  #if defined (TARGET_X11) || defined (TARGET_MOTIF)
693  #define FW_GL_SWAPBUFFERS fv_swapbuffers(gglobal()->display.params);
694  #endif
695 #endif
696 
697 #ifndef FW_GL_SWAPBUFFERS
698 #define FW_GL_SWAPBUFFERS /* nothing */
699 #endif
700 
701 
702  /****************************************************************/
703  /* Second - things that might be specific to one platform; */
704  /* this is the "catch for other OS" here */
705  /****************************************************************/
706  /* nothing here */
707 
708  /****************************************************************/
709  /* Third - common across all platforms */
710  /****************************************************************/
711 
712 
713  /* GLU replacement - needs local matrix stacks, plus more code */
714  #define FW_GLU_PERSPECTIVE(aaa,bbb,ccc,ddd) fw_gluPerspective(aaa,bbb,ccc,ddd)
715  #define FW_GLU_UNPROJECT(aaa, bbb, ccc, ddd, eee, fff, ggg, hhh, iii) fw_gluUnProject(aaa, bbb, ccc, ddd, eee, fff, ggg, hhh, iii)
716  #define FW_GLU_PROJECT(aaa, bbb, ccc, ddd, eee, fff, ggg, hhh, iii) fw_gluProject(aaa, bbb, ccc, ddd, eee, fff, ggg, hhh, iii)
717  #define FW_GLU_PICK_MATRIX(aaa, bbb, ccc, ddd, eee) fw_gluPickMatrix(aaa, bbb, ccc, ddd, eee)
718 
719  /* GLU replacement -these still need doing */
720  #define FW_GLU_DELETETESS(aaa) gluDeleteTess(aaa)
721  #define FW_GLU_NEW_TESS gluNewTess
722  #define FW_GLU_END_POLYGON(aaa) gluEndPolygon(aaa)
723  #define FW_GLU_BEGIN_POLYGON(aaa) gluBeginPolygon(aaa)
724  #define FW_GLU_TESS_VERTEX(aaa, bbb, ccc) gluTessVertex(aaa, bbb, ccc)
725  #define FW_GLU_TESS_CALLBACK(aaa, bbb, ccc) gluTessCallback(aaa,bbb,ccc);
726  #define FW_GLU_NEXT_CONTOUR(aaa, bbb) gluNextContour(aaa,bbb)
727 
728 
729  #define FW_GL_GETDOUBLEV(aaa,bbb) fw_glGetDoublev(aaa,bbb);
730  #define FW_GL_SETDOUBLEV(aaa,bbb) fw_glSetDoublev(aaa,bbb);
731  #define FW_GL_LOAD_IDENTITY fw_glLoadIdentity
732  #define FW_GL_POP_MATRIX() fw_glPopMatrix()
733  #define FW_GL_PUSH_MATRIX() fw_glPushMatrix()
734 
735  #define FW_GL_TRANSLATE_F(xxx,yyy,zzz) fw_glTranslatef(xxx,yyy,zzz)
736  #define FW_GL_TRANSLATE_D(xxx,yyy,zzz) fw_glTranslated(xxx,yyy,zzz)
737  #define FW_GL_ROTATE_F(aaa,xxx,yyy,zzz) fw_glRotatef(aaa,xxx,yyy,zzz)
738  #define FW_GL_ROTATE_D(aaa,xxx,yyy,zzz) fw_glRotated(aaa,xxx,yyy,zzz)
739  #define FW_GL_ROTATE_RADIANS(aaa,xxx,yyy,zzz) fw_glRotateRad(aaa,xxx,yyy,zzz)
740  #define FW_GL_SCALE_F(xxx,yyy,zzz) fw_glScalef(xxx,yyy,zzz)
741  #define FW_GL_SCALE_D(xxx,yyy,zzz) fw_glScaled(xxx,yyy,zzz)
742  #define FW_GL_PUSH_ATTRIB(aaa) glPushAttrib(aaa);
743  #define FW_GL_POP_ATTRIB() glPopAttrib();
744  #define FW_GL_MATRIX_MODE(aaa) fw_glMatrixMode(aaa)
745  #define FW_GL_ORTHO(aaa,bbb,ccc,ddd,eee,fff) fw_Ortho(aaa,bbb,ccc,ddd,eee,fff);
746 
747 
748  /* geometry rendering - varies on whether we are using appearance shaders, etc */
749  #define FW_VERTEX_POINTER_TYPE 44354
750  #define FW_NORMAL_POINTER_TYPE 5434
751  #define FW_FOG_POINTER_TYPE 33888 //?? how geenerate these numbers
752  #define FW_COLOR_POINTER_TYPE 12453
753  #define FW_TEXCOORD_POINTER_TYPE 67655
754  //void sendAttribToGPU(int myType, int dataSize, int dataType, int normalized, int stride, float *pointer, int texID, char *file, int line);
755  // datasize, dataType, stride, pointer
756  #define FW_GL_VERTEX_POINTER(aaa, bbb, ccc, ddd) {sendAttribToGPU(FW_VERTEX_POINTER_TYPE, aaa, bbb, GL_FALSE, ccc, ddd,0,__FILE__,__LINE__); }
757  #define FW_GL_COLOR_POINTER(aaa, bbb, ccc, ddd) {sendAttribToGPU(FW_COLOR_POINTER_TYPE, aaa, bbb, GL_FALSE, ccc, ddd,0,__FILE__,__LINE__); }
758  #define FW_GL_NORMAL_POINTER(aaa, bbb, ccc) {sendAttribToGPU(FW_NORMAL_POINTER_TYPE, 0, aaa, GL_FALSE, bbb, ccc,0,__FILE__,__LINE__); }
759  #define FW_GL_FOG_POINTER(aaa, bbb, ccc) {sendAttribToGPU(FW_FOG_POINTER_TYPE, 0, aaa, GL_FALSE, bbb, ccc,0,__FILE__,__LINE__); }
760  #define FW_GL_TEXCOORD_POINTER(aaa, bbb, ccc, ddd, eee) {sendAttribToGPU(FW_TEXCOORD_POINTER_TYPE, aaa, bbb, GL_FALSE, ccc, ddd,eee,__FILE__,__LINE__); }
761  #define FW_GL_BINDBUFFER(xxx,yyy) {sendBindBufferToGPU(xxx,yyy,__FILE__,__LINE__); }
762 
763 
764 
765  #define FW_GL_VIEWPORT(aaa,bbb,ccc,ddd) glViewport(aaa,bbb,ccc,ddd);
766  #define FW_GL_CLEAR_COLOR(aaa,bbb,ccc,ddd) glClearColor(aaa,bbb,ccc,ddd);
767  #define FW_GL_DEPTHMASK(aaa) glDepthMask(aaa);
768  #define FW_GL_SCISSOR(aaa,bbb,ccc,ddd) glScissor(aaa,bbb,ccc,ddd);
769  #define FW_GL_WINDOWPOS2I(aaa,bbb) glWindowPos2i(aaa,bbb);
770  #define FW_GL_FLUSH glFlush
771  #define FW_GL_RASTERPOS2I(aaa,bbb) glRasterPos2i(aaa,bbb);
772  #define FW_GL_LIGHTMODELI(aaa,bbb) glLightModeli(aaa,bbb);
773  #define FW_GL_LIGHTMODELFV(aaa,bbb) glLightModelfv(aaa,bbb);
774  #define FW_GL_BLENDFUNC(aaa,bbb) glBlendFunc(aaa,bbb);
775  #define FW_GL_LIGHTFV(aaa,bbb,ccc) fwglLightfv(aaa,bbb,ccc);
776  #define FW_GL_LIGHTF(aaa,bbb,ccc) fwglLightf(aaa,bbb,ccc);
777  #define FW_GL_CLEAR(zzz) glClear(zzz);
778  #define FW_GL_DEPTHFUNC(zzz) glDepthFunc(zzz);
779  #define FW_GL_SHADEMODEL(aaa) glShadeModel(aaa);
780  #define FW_GL_PIXELSTOREI(aaa,bbb) glPixelStorei(aaa,bbb);
781 
782 #ifndef GL_FOG
783 #define GL_FOG 0x0B60
784 #endif
785  #define FW_GL_FOGFV(aaa, bbb) glFogfv(aaa, bbb)
786  #define FW_GL_FOGF(aaa, bbb) glFogf(aaa, bbb)
787  #define FW_GL_FOGI(aaa, bbb) glFogi(aaa, bbb)
788  #define FW_GL_BEGIN_QUERY(aaa, bbb) glBeginQuery(aaa, bbb)
789  #define FW_GL_END_QUERY(aaa) glEndQuery(aaa)
790  #define FW_GL_LINE_STIPPLE(aaa, bbb) glLineStipple(aaa, bbb)
791  #define FW_GL_VERTEX3D(aaa, bbb, ccc) glVertex3d(aaa, bbb, ccc)
792 
793 
794  //#define SET_TEXTURE_UNIT(aaa) { glActiveTexture(GL_TEXTURE0+aaa); glClientActiveTexture(GL_TEXTURE0+aaa); }
795 
796  #define FW_GL_GETSTRING(aaa) glGetString(aaa)
797  #define FW_GL_DELETETEXTURES(aaa,bbb) glDeleteTextures(aaa,bbb);
798  #define FW_GL_GETINTEGERV(aaa,bbb) glGetIntegerv(aaa,bbb);
799  #define FW_GL_GETFLOATV(aaa,bbb) glGetFloatv(aaa,bbb);
800 
801 
802  #define FW_GL_FRONTFACE(aaa) glFrontFace(aaa);
803  #define FW_GL_GENLISTS(aaa) glGenLists(aaa)
804  #define FW_GL_GENTEXTURES(aaa,bbb) glGenTextures(aaa,bbb)
805  #define FW_GL_GETBOOLEANV(aaa,bbb) glGetBooleanv(aaa,bbb)
806  #define FW_GL_NEWLIST(aaa,bbb) glNewList(aaa,bbb)
807  #define FW_GL_NORMAL3F(aaa,bbb,ccc) glNormal3f(aaa,bbb,ccc)
808 
809  #define FW_GL_READPIXELS(aaa,bbb,ccc,ddd,eee,fff,ggg) glReadPixels(aaa,bbb,ccc,ddd,eee,fff,ggg)
810  #define FW_GL_TEXIMAGE2D(aaa,bbb,ccc,ddd,eee,fff,ggg,hhh,iii) glTexImage2D(aaa,bbb,ccc,ddd,eee,fff,ggg,hhh,iii)
811  #define FW_GL_TEXPARAMETERF(aaa,bbb,ccc) glTexParameterf(aaa,bbb,ccc)
812  #define FW_GL_TEXPARAMETERI(aaa,bbb,ccc) glTexParameteri(aaa,bbb,ccc)
813  #define FW_GL_TEXPARAMETERFV(aaa,bbb,ccc) glTexParameterfv(aaa,bbb,ccc)
814  #define FW_GL_GETQUERYOBJECTIV(aaa,bbb,ccc) glGetQueryObjectiv(aaa,bbb,ccc)
815 
816  /*apr 6 2010 checkout win32 was missing the following macros */
817  #define FW_GL_DRAWBUFFER(aaa) glDrawBuffer(aaa)
818  #define FW_GL_ENDLIST() glEndList()
819  #define FW_GL_BITMAP(aaa,bbb,ccc,ddd,eee,fff,ggg) glBitmap(aaa,bbb,ccc,ddd,eee,fff,ggg)
820  #define FW_GL_CALLLISTS(aaa,bbb,ccc) glCallLists(aaa,bbb,ccc)
821  #define FW_GL_LISTBASE(aaa) glListBase(aaa)
822  #define FW_GL_DRAWPIXELS(aaa,bbb,ccc,ddd,eee) glDrawPixels(aaa,bbb,ccc,ddd,eee)
823 
824 #endif /* __LIBFREEWRL_DISPLAY_H__ */
Initialization.
Definition: libFreeWRL.h:71