FreeWRL / FreeX3D 4.3.0
display.h
1/*
2
3 FreeWRL support library.
4
5Purpose:
6 Handle platform specific includes about windowing systems and OpenGL.
7 Try to present a generic interface to the rest of FreeWRL library.
8
9Data:
10
11Functions:
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
67 #ifdef IPHONE
68 #include <OpenGLES/ES2/gl.h>
69 #include <OpenGLES/ES2/glext.h>
70 #include <OpenGLES/ES3/gl.h>
71 #include <OpenGLES/ES3/glext.h>
72 #else
73
74 #include <OpenGL/OpenGL.h>
75 #include <OpenGL/CGLTypes.h>
76
77 #include <AGL/AGL.h>
78 #endif /* defined IPHONE */
79#endif /* defined TARGET_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
88GLEWContext * 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 (TARGET_AQUA) || 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
327void fv_setScreenDim(int wi, int he);
328
329int fv_open_display();
330int fv_display_initialize(void);
331int fv_display_initialize_desktop(void);
332int fv_create_main_window(freewrl_params_t *d); //int argc, char *argv[]);
333int fv_create_main_window2(freewrl_params_t *d, freewrl_params_t *share);
334bool fv_create_GLcontext();
335bool fv_bind_GLcontext();
336void fv_swapbuffers(freewrl_params_t *d);
337int fv_create_window_and_context(freewrl_params_t *params, freewrl_params_t *share);
338void fv_change_GLcontext(freewrl_params_t* d);
339/* end of "virtual" functions */
340
341/* OpenGL renderer capabilities */
342
343
344/* Location Information of Shader Valuation */
346 GLint compiledOK;
347 GLuint myShaderProgram;
348
349 GLint myMaterialAmbient;
350 GLint myMaterialDiffuse;
351 GLint myMaterialSpecular;
352 GLint myMaterialShininess;
353 GLint myMaterialEmission;
354
355 GLint myMaterialBackAmbient;
356 GLint myMaterialBackDiffuse;
357 GLint myMaterialBackSpecular;
358 GLint myMaterialBackShininess;
359 GLint myMaterialBackEmission;
360
361 GLint myPointSize;
362
363 // do we need to send down light information?
364 bool haveLightInShader;
365
366 GLint lightcount;
367 //GLint lightType;
368 GLint lightType[MAX_LIGHTS];
369 GLint lightAmbient[MAX_LIGHTS];
370 GLint lightDiffuse[MAX_LIGHTS];
371 GLint lightSpecular[MAX_LIGHTS];
372 GLint lightPosition[MAX_LIGHTS];
373 GLint lightSpotDir[MAX_LIGHTS];
374 GLint lightAtten[MAX_LIGHTS];
375 //GLint lightConstAtten[MAX_LIGHTS];
376 //GLint lightLinAtten[MAX_LIGHTS];
377 //GLint lightQuadAtten[MAX_LIGHTS];
378 GLint lightSpotCutoffAngle[MAX_LIGHTS];
379 GLint lightSpotBeamWidth[MAX_LIGHTS];
380 //GLint lightRadius;
381 GLint lightRadius[MAX_LIGHTS];
382
383 GLint ModelViewMatrix;
384 GLint ProjectionMatrix;
385 GLint NormalMatrix;
386 GLint ModelViewInverseMatrix;
387 GLint TextureMatrix[MAX_MULTITEXTURE];
388 GLint Vertices;
389 GLint Normals;
390 GLint Colours;
391 GLint TexCoords[MAX_MULTITEXTURE];
392 GLint FogCoords; //Aug 2016
393
394 /* Projective Texture */
395 GLint textureUnit[4];
396 GLint projTexGenMatCam[16];
397 GLint pbackCull[16];
398 GLint ntdesc[16];
399 GLint pCount;
400 GLint tunits[16];
401 GLint modes[16];
402 GLint sources[16];
403 GLint funcs[16];
404
405
406 GLint TextureUnit[MAX_MULTITEXTURE];
407 GLint TextureMode[MAX_MULTITEXTURE];
408 GLint TextureSource[MAX_MULTITEXTURE];
409 GLint TextureFunction[MAX_MULTITEXTURE];
410 GLint textureCount;
411 GLint multitextureColor;
412
413 /* texture3D */
414 GLint tex3dTiles; //int[2] nx, ny number of tiles in x, y
415 GLint tex3dUseVertex; //bool flag when no 3D texture coords supplied, vertex shader should use vertex
416 GLint repeatSTR;
417 GLint magFilter;
418
419 /* fill properties */
420 GLint hatchColour;
421 GLint hatchPercent;
422 GLint hatchScale;
423 GLint filledBool;
424 GLint hatchedBool;
425 GLint algorithm;
426
427 /* TextureCoordinateGenerator type */
428 GLint texCoordGenType;
429
430 GLint fogColor; //Aug 2016
431 GLint fogvisibilityRange;
432 GLint fogScale;
433 GLint fogType;
434 GLint fogHaveCoords;
435
436 GLint clipplanes; //Sept 2016
437 GLint nclipplanes;
438
439/* attributes - reduce redundant state chage calls on GPU */
440/*
441 need to ensure that all calls to glEnableVertexAttribArray
442 are tagged for redundancy - eg, in statusbarHud.c, etc.
443 before trying to reduce the glEnableVertexAttribArray and
444 glDisableVertexAttribArray calls.
445
446 bool vertexAttribEnabled;
447 bool texCoordAttribEnabled;
448 bool colourAttribEnabled;
449 bool normalAttribEnabled;
450*/
451
453
454typedef struct {
455
456 const char *renderer; /* replace GL_REN */
457 const char *version;
458 const char *vendor;
459 const char *extensions;
460 float versionf;
461 bool have_GL_VERSION_1_1;
462 bool have_GL_VERSION_1_2;
463 bool have_GL_VERSION_1_3;
464 bool have_GL_VERSION_1_4;
465 bool have_GL_VERSION_1_5;
466 bool have_GL_VERSION_2_0;
467 bool have_GL_VERSION_2_1;
468 bool have_GL_VERSION_3_0;
469
470 bool av_multitexture; /* Multi textures available ? */
471 bool av_npot_texture; /* Non power of 2 textures available ? */
472 bool av_texture_rect; /* Rectangle textures available ? */
473 bool av_occlusion_q; /* Occlusion query available ? */
474
475 int texture_units;
476 int runtime_max_texture_size;
477 int system_max_texture_size;
478 float anisotropicDegree;
479
480 GLboolean quadBuffer; /* does platform support quadbuffer? */
481
483
484// JAS extern s_renderer_capabilities_t rdr_caps;
485
486bool initialize_rdr_caps();
487void initialize_rdr_functions();
488void rdr_caps_dump(s_renderer_capabilities_t *rdr_caps);
489
490
491#ifdef TARGET_AQUA /* OLD_IPHONE_AQUA */
492/*
493OLD_IPHONE_AQUA #ifndef IPHONE
494OLD_IPHONE_AQUA
495OLD_IPHONE_AQUA extern int ccurse;
496OLD_IPHONE_AQUA extern int ocurse;
497OLD_IPHONE_AQUA
498OLD_IPHONE_AQUA //#define SCURSE 1
499OLD_IPHONE_AQUA //#define ACURSE 0
500OLD_IPHONE_AQUA
501OLD_IPHONE_AQUA // for handling Safari window changes at the top of the display event loop
502OLD_IPHONE_AQUA extern int PaneClipnpx;
503OLD_IPHONE_AQUA extern int PaneClipnpy;
504OLD_IPHONE_AQUA
505OLD_IPHONE_AQUA extern int PaneClipct;
506OLD_IPHONE_AQUA extern int PaneClipcb;
507OLD_IPHONE_AQUA extern int PaneClipcr;
508OLD_IPHONE_AQUA extern int PaneClipcl;
509OLD_IPHONE_AQUA extern int PaneClipwidth;
510OLD_IPHONE_AQUA extern int PaneClipheight;
511OLD_IPHONE_AQUA extern int PaneClipChanged;
512OLD_IPHONE_AQUA
513OLD_IPHONE_AQUA #include "OpenGL/glu.h"
514OLD_IPHONE_AQUA #endif
515 */
516#endif /* OLD_IPHONE_AQUA TARGET_AQUA */
517
521#if defined(TARGET_X11) || defined(TARGET_MOTIF)
522
527# include <X11/Xlib.h>
528# include <X11/Xutil.h>
529# include <X11/keysym.h>
530
531
532extern GLXContext GLcx;
533
534extern XEvent event;
535extern long event_mask;
536extern Display *Xdpy;
537extern int Xscreen;
538extern Window Xroot_window;
539extern XVisualInfo *Xvi;
540extern Colormap colormap;
541extern Window Xwin;
542extern Window GLwin;
543extern XSetWindowAttributes attr;
544extern unsigned long mask;
545extern Atom WM_DELETE_WINDOW;
546
547void handle_Xevents(XEvent event);
548
549# ifdef HAVE_XF86_VMODE
550# include <X11/extensions/xf86vmode.h>
551extern int vmode_nb_modes;
552extern XF86VidModeModeInfo **vmode_modes;
553extern int vmode_mode_selected;
554# endif /* HAVE_XF86_VMODE */
555
556# if defined(TARGET_MOTIF)
557
561# include <X11/Intrinsic.h>
562# include <Xm/Xm.h>
563
564extern XtAppContext Xtcx;
565
566void getMotifWindowedGLwin(Window *win);
567# define GET_GLWIN getMotifWindowedGLwin(&GLwin)
568
569# else /* defined(TARGET_MOTIF) */
570
574# define GET_GLWIN getBareWindowedGLwin(&GLwin)
575
576# endif /* defined(TARGET_MOTIF) */
577
578#endif /* defined(TARGET_X11) || defined(TARGET_MOTIF) */
579
584#if defined (FW_DEBUG)
585
586 #if defined(_ANDROID)
587 #define PRINT_GL_ERROR_IF_ANY(_where) { \
588 GLenum _global_gl_err = glGetError(); \
589 while (_global_gl_err != GL_NO_ERROR) { \
590 if (_global_gl_err == GL_INVALID_ENUM) {DROIDDEBUG ("GL_INVALID_ENUM"); } \
591 else if (_global_gl_err == GL_INVALID_VALUE) {DROIDDEBUG("GL_INVALID_VALUE"); } \
592 else if (_global_gl_err == GL_INVALID_OPERATION) {DROIDDEBUG("GL_INVALID_OPERATION"); } \
593 else if (_global_gl_err == GL_OUT_OF_MEMORY) {DROIDDEBUG("GL_OUT_OF_MEMORY"); } \
594 else DROIDDEBUG("unknown error"); \
595 DROIDDEBUG(" here: %s (%s:%d)\n", _where,__FILE__,__LINE__); \
596 _global_gl_err = glGetError(); \
597 } \
598 }
599
600 #else
601 #define PRINT_GL_ERROR_IF_ANY(_where) { \
602 GLenum _global_gl_err = glGetError(); \
603 while (_global_gl_err != GL_NO_ERROR) { \
604 if (_global_gl_err == GL_INVALID_ENUM) {printf ("GL_INVALID_ENUM"); } \
605 else if (_global_gl_err == GL_INVALID_VALUE) {printf ("GL_INVALID_VALUE"); } \
606 else if (_global_gl_err == GL_INVALID_OPERATION) {printf ("GL_INVALID_OPERATION"); } \
607 else if (_global_gl_err == GL_OUT_OF_MEMORY) {printf ("GL_OUT_OF_MEMORY"); } \
608 else printf ("unknown error"); \
609 printf(" here: %s (%s:%d)\n", _where,__FILE__,__LINE__); \
610 _global_gl_err = glGetError(); \
611 } \
612 }
613 #endif
614
615#else // FW_DEBUG
616 #define PRINT_GL_ERROR_IF_ANY(_where) /* do nothing */
617#endif
618
619#define GL_ERROR_MSG (\
620 (glGetError() == GL_NO_ERROR)?"":\
621 (glGetError() == GL_INVALID_ENUM)?"GL_INVALID_ENUM":\
622 (glGetError() == GL_INVALID_VALUE)?"GL_INVALID_VALUE":\
623 (glGetError() == GL_INVALID_OPERATION)?"GL_INVALID_OPERATION":\
624 (glGetError() == GL_OUT_OF_MEMORY)?"GL_OUT_OF_MEMORY":\
625 "unknown GL_ERROR")
626
627void resetGeometry();
628/* void setScreenDim(int wi, int he); */
629
630/* GLSL variables */
631/* Versions 1.5 and above have shaders */
632#ifdef GL_VERSION_2_0
633 #define VERTEX_SHADER GL_VERTEX_SHADER
634 #define FRAGMENT_SHADER GL_FRAGMENT_SHADER
635 #define SHADER_SOURCE glShaderSource
636 #define COMPILE_SHADER glCompileShader
637 #define CREATE_PROGRAM glCreateProgram();
638 #define CREATE_SHADER glCreateShader
639 #define ATTACH_SHADER glAttachShader
640 #define LINK_SHADER glLinkProgram
641 #define DELETE_SHADER glDeleteShader
642 #define DELETE_PROGRAM glDeleteProgram
643 #define USE_SHADER(aaa) glUseProgram(aaa)
644 #define GET_SHADER_INFO glGetShaderiv
645 #define LINK_STATUS GL_LINK_STATUS
646 #define COMPILE_STATUS GL_COMPILE_STATUS
647 #define GET_UNIFORM(aaa,bbb) glGetUniformLocation(aaa,bbb)
648 #define GET_ATTRIB(aaa,bbb) glGetAttribLocation(aaa,bbb)
649 #define GLUNIFORM1I glUniform1i
650 #define GLUNIFORM1F glUniform1f
651 #define GLUNIFORM2F glUniform2f
652 #define GLUNIFORM3F glUniform3f
653 #define GLUNIFORM4F glUniform4f
654 #define GLUNIFORM1IV glUniform1iv
655 #define GLUNIFORM1FV glUniform1fv
656 #define GLUNIFORM2FV glUniform2fv
657 #define GLUNIFORM3FV glUniform3fv
658 #define GLUNIFORM4FV glUniform4fv
659 #define GLUNIFORMMATRIX4FV glUniformMatrix4fv
660 #define GLUNIFORMMATRIX3FV glUniformMatrix3fv
661
662#else
663#ifdef GL_VERSION_1_5
664 #define VERTEX_SHADER GL_VERTEX_SHADER_ARB
665 #define FRAGMENT_SHADER GL_FRAGMENT_SHADER_ARB
666 #define SHADER_SOURCE glShaderSourceARB
667 #define COMPILE_SHADER glCompileShaderARB
668 #define CREATE_PROGRAM glCreateProgramObjectARB();
669 #define CREATE_SHADER glCreateShaderARB
670 #define ATTACH_SHADER glAttachObjectARB
671 #define LINK_SHADER glLinkProgramARB
672 #define DELETE_SHADER glDeleteShaderARB
673 #define DELETE_PROGRAM glDeleteProgramARB
674 #define USE_SHADER(aaa) glUseProgramObjectARB(aaa)
675 #define CREATE_SHADER glCreateShaderObjectARB
676 #define GET_SHADER_INFO glGetObjectParameterivARB
677 #define LINK_STATUS GL_OBJECT_LINK_STATUS_ARB
678 #define COMPILE_STATUS GL_OBJECT_COMPILE_STATUS_ARB
679 #define GET_UNIFORM(aaa,bbb) glGetUniformLocationARB(aaa,bbb)
680 #define GET_ATTRIB(aaa,bbb) glGetAttribLocationARB(aaa,bbb)
681 #define GLUNIFORM1F glUniform1fARB
682 #define GLUNIFORM1I glUniform1iARB
683 #define GLUNIFORM2F glUniform2fARB
684 #define GLUNIFORM3F glUniform3fARB
685 #define GLUNIFORM4F glUniform4fARB
686 #define GLUNIFORM1IV glUniform1ivARB
687 #define GLUNIFORM1FV glUniform1fvARB
688 #define GLUNIFORM2FV glUniform2fvARB
689 #define GLUNIFORM3FV glUniform3fvARB
690 #define GLUNIFORM4FV glUniform4fvARB
691 #define GLUNIFORMMATRIX4FV glUniformMatrix4fvARB
692 #define GLUNIFORMMATRIX3FV glUniformMatrix3fvARB
693#endif
694#endif
695
696/* OpenGL-2.x and OpenGL-3.x "desktop" systems calls */
697 /****************************************************************/
698 /* First - any platform specifics to do? */
699 /****************************************************************/
700
701 #if defined(_MSC_VER)
702 void fwMessageLoop();
703 #define FW_GL_SWAPBUFFERS fv_swapbuffers(gglobal()->display.params); //SwapBuffers(wglGetCurrentDC());
704 #endif
705
706#if KEEP_X11_INLIB
707 #if defined (TARGET_X11) || defined (TARGET_MOTIF)
708 #define FW_GL_SWAPBUFFERS fv_swapbuffers(gglobal()->display.params);
709 #endif
710#endif
711
712#ifndef FW_GL_SWAPBUFFERS
713#define FW_GL_SWAPBUFFERS /* nothing */
714#endif
715
716
717 /****************************************************************/
718 /* Second - things that might be specific to one platform; */
719 /* this is the "catch for other OS" here */
720 /****************************************************************/
721 /* nothing here */
722
723 /****************************************************************/
724 /* Third - common across all platforms */
725 /****************************************************************/
726
727
728 /* GLU replacement - needs local matrix stacks, plus more code */
729 #define FW_GLU_PERSPECTIVE(aaa,bbb,ccc,ddd) fw_gluPerspective(aaa,bbb,ccc,ddd)
730 #define FW_GLU_UNPROJECT(aaa, bbb, ccc, ddd, eee, fff, ggg, hhh, iii) fw_gluUnProject(aaa, bbb, ccc, ddd, eee, fff, ggg, hhh, iii)
731 #define FW_GLU_PROJECT(aaa, bbb, ccc, ddd, eee, fff, ggg, hhh, iii) fw_gluProject(aaa, bbb, ccc, ddd, eee, fff, ggg, hhh, iii)
732 #define FW_GLU_PICK_MATRIX(aaa, bbb, ccc, ddd, eee) fw_gluPickMatrix(aaa, bbb, ccc, ddd, eee)
733
734 /* GLU replacement -these still need doing */
735 #define FW_GLU_DELETETESS(aaa) gluDeleteTess(aaa)
736 #define FW_GLU_NEW_TESS gluNewTess
737 #define FW_GLU_END_POLYGON(aaa) gluEndPolygon(aaa)
738 #define FW_GLU_BEGIN_POLYGON(aaa) gluBeginPolygon(aaa)
739 #define FW_GLU_TESS_VERTEX(aaa, bbb, ccc) gluTessVertex(aaa, bbb, ccc)
740 #define FW_GLU_TESS_CALLBACK(aaa, bbb, ccc) gluTessCallback(aaa,bbb,ccc);
741 #define FW_GLU_NEXT_CONTOUR(aaa, bbb) gluNextContour(aaa,bbb)
742
743
744 #define FW_GL_GETDOUBLEV(aaa,bbb) fw_glGetDoublev(aaa,bbb);
745 #define FW_GL_SETDOUBLEV(aaa,bbb) fw_glSetDoublev(aaa,bbb);
746 #define FW_GL_LOAD_IDENTITY fw_glLoadIdentity
747 #define FW_GL_LOAD_MATRIX_D(mat16) fw_glLoadMatrixd(mat16)
748 #define FW_GL_POP_MATRIX() fw_glPopMatrix()
749 #define FW_GL_PUSH_MATRIX() fw_glPushMatrix()
750
751 #define FW_GL_TRANSLATE_F(xxx,yyy,zzz) fw_glTranslatef(xxx,yyy,zzz)
752 #define FW_GL_TRANSLATE_D(xxx,yyy,zzz) fw_glTranslated(xxx,yyy,zzz)
753 #define FW_GL_TRANSFORM_D(mat16) fw_glTransformd(mat16)
754 #define FW_GL_MULTMATRIX_D(mat16) fw_glMultMatrixd(mat16)
755 #define FW_GL_ROTATE_F(aaa,xxx,yyy,zzz) fw_glRotatef(aaa,xxx,yyy,zzz)
756 #define FW_GL_ROTATE_D(aaa,xxx,yyy,zzz) fw_glRotated(aaa,xxx,yyy,zzz)
757 #define FW_GL_ROTATE_RADIANS(aaa,xxx,yyy,zzz) fw_glRotateRad(aaa,xxx,yyy,zzz)
758 #define FW_GL_SCALE_F(xxx,yyy,zzz) fw_glScalef(xxx,yyy,zzz)
759 #define FW_GL_SCALE_D(xxx,yyy,zzz) fw_glScaled(xxx,yyy,zzz)
760 #define FW_GL_PUSH_ATTRIB(aaa) glPushAttrib(aaa);
761 #define FW_GL_POP_ATTRIB() glPopAttrib();
762 #define FW_GL_MATRIX_MODE(aaa) fw_glMatrixMode(aaa)
763 #define FW_GL_ORTHO(aaa,bbb,ccc,ddd,eee,fff) fw_Ortho(aaa,bbb,ccc,ddd,eee,fff);
764
765
766 /* geometry rendering - varies on whether we are using appearance shaders, etc */
767 #define FW_VERTEX_POINTER_TYPE 44354
768 #define FW_NORMAL_POINTER_TYPE 5434
769 #define FW_FOG_POINTER_TYPE 33888 //?? how geenerate these numbers
770 #define FW_COLOR_POINTER_TYPE 12453
771 #define FW_TEXCOORD_POINTER_TYPE 67655
772 //void sendAttribToGPU(int myType, int dataSize, int dataType, int normalized, int stride, float *pointer, int texID, char *file, int line);
773 // datasize, dataType, stride, pointer
774 #define FW_GL_VERTEX_POINTER(dataSize, dataType, stride, pointer) {sendAttribToGPU(FW_VERTEX_POINTER_TYPE, dataSize, dataType, GL_FALSE, stride, pointer,0,__FILE__,__LINE__); }
775
776 #define FW_GL_COLOR_POINTER(dataSize, dataType, stride, pointer) {sendAttribToGPU(FW_COLOR_POINTER_TYPE, dataSize, dataType, GL_FALSE, stride, pointer,0,__FILE__,__LINE__); }
777 #define FW_GL_NORMAL_POINTER(dataType, stride, pointer) {sendAttribToGPU(FW_NORMAL_POINTER_TYPE, 0, dataType, GL_FALSE, stride, pointer,0,__FILE__,__LINE__); }
778 #define FW_GL_FOG_POINTER(dataType, stride, pointer) {sendAttribToGPU(FW_FOG_POINTER_TYPE, 0, dataType, GL_FALSE, stride, pointer,0,__FILE__,__LINE__); }
779 #define FW_GL_TEXCOORD_POINTER(dataSize, dataType, stride, pointer, texID) {sendAttribToGPU(FW_TEXCOORD_POINTER_TYPE, dataSize, dataType, GL_FALSE, stride, pointer,texID,__FILE__,__LINE__); }
780 #define FW_GL_BINDBUFFER(target,buffer) {sendBindBufferToGPU(target,buffer,__FILE__,__LINE__); }
781
782
783
784 #define FW_GL_VIEWPORT(aaa,bbb,ccc,ddd) glViewport(aaa,bbb,ccc,ddd);
785 #define FW_GL_CLEAR_COLOR(aaa,bbb,ccc,ddd) glClearColor(aaa,bbb,ccc,ddd);
786 #define FW_GL_DEPTHMASK(aaa) glDepthMask(aaa);
787 #define FW_GL_SCISSOR(aaa,bbb,ccc,ddd) glScissor(aaa,bbb,ccc,ddd);
788 #define FW_GL_WINDOWPOS2I(aaa,bbb) glWindowPos2i(aaa,bbb);
789 #define FW_GL_FLUSH glFlush
790 #define FW_GL_RASTERPOS2I(aaa,bbb) glRasterPos2i(aaa,bbb);
791 #define FW_GL_LIGHTMODELI(aaa,bbb) glLightModeli(aaa,bbb);
792 #define FW_GL_LIGHTMODELFV(aaa,bbb) glLightModelfv(aaa,bbb);
793 #define FW_GL_BLENDFUNC(aaa,bbb) glBlendFunc(aaa,bbb);
794 #define FW_GL_LIGHTFV(aaa,bbb,ccc) fwglLightfv(aaa,bbb,ccc);
795 #define FW_GL_LIGHTF(aaa,bbb,ccc) fwglLightf(aaa,bbb,ccc);
796 #define FW_GL_CLEAR(zzz) glClear(zzz);
797 #define FW_GL_DEPTHFUNC(zzz) glDepthFunc(zzz);
798 #define FW_GL_SHADEMODEL(aaa) glShadeModel(aaa);
799 #define FW_GL_PIXELSTOREI(aaa,bbb) glPixelStorei(aaa,bbb);
800
801#ifndef GL_FOG
802#define GL_FOG 0x0B60
803#endif
804 #define FW_GL_FOGFV(aaa, bbb) glFogfv(aaa, bbb)
805 #define FW_GL_FOGF(aaa, bbb) glFogf(aaa, bbb)
806 #define FW_GL_FOGI(aaa, bbb) glFogi(aaa, bbb)
807 #define FW_GL_BEGIN_QUERY(aaa, bbb) glBeginQuery(aaa, bbb)
808 #define FW_GL_END_QUERY(aaa) glEndQuery(aaa)
809 #define FW_GL_LINE_STIPPLE(aaa, bbb) glLineStipple(aaa, bbb)
810 #define FW_GL_VERTEX3D(aaa, bbb, ccc) glVertex3d(aaa, bbb, ccc)
811
812
813 //#define SET_TEXTURE_UNIT(aaa) { glActiveTexture(GL_TEXTURE0+aaa); glClientActiveTexture(GL_TEXTURE0+aaa); }
814
815 #define FW_GL_GETSTRING(aaa) glGetString(aaa)
816 #define FW_GL_DELETETEXTURES(aaa,bbb) glDeleteTextures(aaa,bbb);
817 #define FW_GL_GETINTEGERV(aaa,bbb) glGetIntegerv(aaa,bbb);
818 #define FW_GL_GETFLOATV(aaa,bbb) glGetFloatv(aaa,bbb);
819
820
821 #define FW_GL_FRONTFACE(aaa) glFrontFace(aaa);
822 #define FW_GL_GENLISTS(aaa) glGenLists(aaa)
823 #define FW_GL_GENTEXTURES(aaa,bbb) glGenTextures(aaa,bbb)
824 #define FW_GL_GETBOOLEANV(aaa,bbb) glGetBooleanv(aaa,bbb)
825 #define FW_GL_NEWLIST(aaa,bbb) glNewList(aaa,bbb)
826 #define FW_GL_NORMAL3F(aaa,bbb,ccc) glNormal3f(aaa,bbb,ccc)
827
828 #define FW_GL_READPIXELS(aaa,bbb,ccc,ddd,eee,fff,ggg) glReadPixels(aaa,bbb,ccc,ddd,eee,fff,ggg)
829 #define FW_GL_TEXIMAGE2D(aaa,bbb,ccc,ddd,eee,fff,ggg,hhh,iii) glTexImage2D(aaa,bbb,ccc,ddd,eee,fff,ggg,hhh,iii)
830 #define FW_GL_TEXPARAMETERF(aaa,bbb,ccc) glTexParameterf(aaa,bbb,ccc)
831 #define FW_GL_TEXPARAMETERI(aaa,bbb,ccc) glTexParameteri(aaa,bbb,ccc)
832 #define FW_GL_TEXPARAMETERFV(aaa,bbb,ccc) glTexParameterfv(aaa,bbb,ccc)
833 #define FW_GL_GETQUERYOBJECTIV(aaa,bbb,ccc) glGetQueryObjectiv(aaa,bbb,ccc)
834
835 /*apr 6 2010 checkout win32 was missing the following macros */
836 #define FW_GL_DRAWBUFFER(aaa) glDrawBuffer(aaa)
837 #define FW_GL_ENDLIST() glEndList()
838 #define FW_GL_BITMAP(aaa,bbb,ccc,ddd,eee,fff,ggg) glBitmap(aaa,bbb,ccc,ddd,eee,fff,ggg)
839 #define FW_GL_CALLLISTS(aaa,bbb,ccc) glCallLists(aaa,bbb,ccc)
840 #define FW_GL_LISTBASE(aaa) glListBase(aaa)
841 #define FW_GL_DRAWPIXELS(aaa,bbb,ccc,ddd,eee) glDrawPixels(aaa,bbb,ccc,ddd,eee)
842
843#endif /* __LIBFREEWRL_DISPLAY_H__ */
Initialization.
Definition libFreeWRL.h:72