FreeWRL / FreeX3D 4.3.0
iglobal.h
1/*
2The globals have 'private' and 'public' facilities
31. if the variables are used only in one source file, they go
4 in a ppFileName struct in Filename.c
52. if the variables are used in other source files (via extern) then either:
62a. add getter and setter functions and keep private, or
72b. add directly to iiglobal struct in iglobal.h, in the struct tFileName sub-struct
82bi. in this case if its a pointer to a complex type, put as void* in iglobal and
9 add casting to the code (so iglobal.h doesn't have to #include a bunch of headers)
10
11Variable initialization:
121. for private: in a //private section in FileName_init(..) p->variable = const value
132. for public: in a //public section in FileName_init(..) t->variable = const value
14
15Variable use:
161. for private: ppFileName p = (ppFileName)gglobal()->FileName.prv;
17-- p->variable = ...
182. for public: gglobal()->FileName.variable = ...
19
20*/
21
22#ifndef INSTANCEGLOBAL
23//#include "display.h" //for opengl_utils.h which is for rdr_caps
24//#include "opengl/OpenGL_Utils.h" //for rdr_caps
25#include "list.h"
26#ifdef DISABLER
27#include "dbl_list.h"
28#endif
29#include <system.h>
30//#include <libFreeWRL.h>
31#include <pthread.h>
32#include <threads.h> //for threads
33//#define GLenum int
34//#define GLuint unsigned int
35//#include "vrml_parser/Structs.h" //for SFColor
36//#include "x3d_parser/X3DParser.h" //for PARENTSTACKSIZE
37//#include "ui/common.h" // for ppcommon
38
39
40#define IBOOL int
41
42typedef struct iiglobal //InstanceGlobal
43{
44
45
46 struct tdisplay{
47 void *params; //freewrl_params_t
48 int _global_gl_err; //GLenum
49 IBOOL display_initialized;// = FALSE;
50 int screenWidth;// = 0; /* screen */
51 int screenHeight;// = 0;
52 char *window_title;// = NULL;
53 int shutterGlasses;// = 0; /* stereo shutter glasses */
54 void *rdr_caps; //s_renderer_capabilities_t
55 void *prv;
56 }display;
57 struct tinternalc {
58 IBOOL global_strictParsing;// = FALSE;
59 IBOOL global_plugin_print;// = FALSE;
60 IBOOL global_occlusion_disable;// = FALSE;
61 unsigned user_request_texture_size;// = 0;
62 IBOOL global_print_opengl_errors;// = FALSE;
63 IBOOL global_trace_threads;// = FALSE;
64 void *prv;
65 } internalc;
66 //struct tio_http {
67 // void *prv;
68 //} io_http;
69 struct tresources {
70 //resource_item_t *root_res; // = NULL;
71 void *root_res;
72 void *prv;
73 } resources;
74 struct tthreads {
75 pthread_t disposeThread;
76 pthread_t mainThread; /* main (default) thread */
77 pthread_t DispThrd; /*DEF_THREAD(DispThrd); display thread */
78 pthread_t PCthread; /* DEF_THREAD(PCthread)parser thread */
79 pthread_t loadThread; /* DEF_THREAD(pthread_t loadThread)texture thread */
80 /* Synchronize / exclusion root_res and below */
81 pthread_mutex_t mutex_resource_tree; // = PTHREAD_MUTEX_INITIALIZER;
82
83 /* Synchronize / exclusion : resource queue for parser */
84 pthread_mutex_t mutex_resource_list; // = PTHREAD_MUTEX_INITIALIZER;
85 pthread_cond_t resource_list_condition; // = PTHREAD_COND_INITIALIZER;
86
87 pthread_mutex_t mutex_frontend_list; // = PTHREAD_MUTEX_INITIALIZER;
88
89 /* Synchronize / exclusion (main<=>texture) */
90 pthread_mutex_t mutex_texture_list; // = PTHREAD_MUTEX_INITIALIZER;
91 pthread_cond_t texture_list_condition; // = PTHREAD_COND_INITIALIZER;
92
93 IBOOL ResourceThreadRunning;
94 IBOOL TextureThreadRunning;
95 IBOOL ResourceThreadWaiting;
96 IBOOL TextureThreadWaiting;
97 IBOOL flushing;
98 int MainLoopQuit;
99 void *prv;
100 } threads;
101
102 struct tSnapshot {
103 IBOOL doSnapshot;
104 IBOOL doPrintshot;
105 int snapGoodCount;
106 void *prv;
107 } Snapshot;
109 int eaiverbose;// = FALSE;
110 void *prv;
111 } EAI_C_CommonFunctions;
113 void *prv;
114 } EAIEventsIn;
116 char *outBuffer;
117 int outBufferLen;
118 void *prv;
119 } EAIHelpers;
120 struct tEAICore{
121 /* EAI input buffer */
122 char *EAIbuffer;
123 int EAIbufcount; /* pointer into buffer*/
124 int EAIbufpos;
125 int EAIbufsize; /* current size in bytes of input buffer*/
126 void *prv;
127 } EAICore;
129 void *prv;
130 } SensInterps;
132 int consMsgCount;
133 int Console_writeToHud;
134 void *prv;
135 } ConsoleMessage;
136 struct tMainloop{
137 float gl_linewidth;
138 /* what kind of file was just parsed? */
139 int currentFileVersion;
140 double TickTime;
141 double lastTime;
142 double BrowserFPS;// = 100.0; /* calculated FPS */
143 double BrowserSpeed;// = 0.0; /* calculated movement speed */
144 const char *BrowserDescription;
145 int HaveSensitive;// = FALSE;
146 int AllowNavDrag;
147 int trisThisLoop;
148 int clipPlane;// = 0;
149 int SHIFT; //state of shift key up = 0, down = 1
150 int CTRL; //state of ctrl key up = 0, down = 1
151 //int currentX[20], currentY[20]; /* current mouse position.*/
152 void *prv;
153 char *tmpFileLocation;
154 char *url;
155 char *scene_name; //null or take from url
156 char *scene_suff; //null or wrl or x3d
157 int scene_profile; //from parser (or capabilities handler) used in js scene.profile
158 int *scene_components;
159 char *replaceWorldRequest;
160 void *replaceWorldRequestMulti; //will be struct multi-string
161 void *_vportstack; //Stack for viewports
162 void *_stagestack; //stack for stage ID
163 void *_framebufferstack; //stack for backbuffers, usually GL_BACK, or can be FBO
164 int screenOrientation2;
165 int pickray_x;
166 int pickray_y;
167 float fieldOfView; //set in setup_projection, used in volumeRendering
168 } Mainloop;
169 struct tProdCon{
170 struct Vector *viewpointNodes;// = NULL;
171 int currboundvpno;//=0;
172 /* bind nodes in display loop, NOT in parsing threadthread */
173 struct X3D_Node *setViewpointBindInRender;// = NULL;
174 struct X3D_Node *setFogBindInRender;// = NULL;
175 struct X3D_Node *setBackgroundBindInRender;// = NULL;
176 struct X3D_Node *setNavigationBindInRender;// = NULL;
177 void *savedParser; //struct VRMLParser* savedParser;
178 void *prv;
179 } ProdCon;
180 #if defined (INCLUDE_NON_WEB3D_FORMATS)
181 struct tColladaParser{
182 void *prv;
183 }ColladaParser;
184 #endif //INCLUDE_NON_WEB3D_FORMATS
185
186 #if defined (INCLUDE_STL_FILES)
187 struct tSTLHandler {
188 void *prv;
189 }STLHandler;
190 #endif // INCLUDE_STL_FILES
191
192
193 struct tFrustum{
194 int OccFailed;//. = FALSE;
195 void *prv;
196 } Frustum;
198 /* is the texture thread up and running yet? */
199 //int TextureThreadInitialized;// = FALSE;
200 void *prv;
201 }LoadTextures;
203 /* is this 24 bit depth? 16? 8?? Assume 24, unless set on opening */
204 int displayDepth;// = 24;
205 //static float cc_red = 0.0f, cc_green = 0.0f, cc_blue = 0.0f, cc_alpha = 1.0f;
206 int cc_changed;// = FALSE;
207 void *prv;
208 }OpenGL_Utils;
209
210#ifdef HAVE_OPENCL
211 struct tOpenCL_Utils{
212 IBOOL OpenCL_Initialized; // = FALSE;
213 IBOOL OpenCL_OK; // = FALSE
214 void *prv;
215 }OpenCL_Utils;
216#endif //HAVE_OPENCL
217
218#ifdef STATUSBAR_STD
219 struct tRasterFont{
220 void *prv;
221 }RasterFont;
222#endif
224 //struct multiTexParams textureParameterStack[MAX_MULTITEXTURE];
225 void *textureParameterStack;
226 void *prv;
227 }RenderTextures;
228 struct tTextures{
229 /* for texture remapping in TextureCoordinate nodes */
230 //GLuint *global_tcin;
231 unsigned int *global_tcin;
232 int global_tcin_count;
233 void *global_tcin_lastParent;
234 //GLuint defaultBlankTexture;
235 unsigned int defaultBlankTexture;
236 void *prv;
237 }Textures;
239 /*
240 GLint _projTexGenMatCam0_Location;
241 GLint _MultiprojTexGenMatCam_Location[4];
242 GLint _projTexCoord_Location;
243 GLint _projViewMat_Location;
244 GLint _projMap_forCam1_Location;
245 //struct projective_Texdata data[4];
246 */
247 //void *data;
248 //bool ProjActive;
249 int globalProjector;
250 void *prv;
251 }Component_PTM;
253 void *prv;
254 }PluginSocket;
256 void *prv;
257 }pluginUtils;
259 void *prv;
260 }collision;
262 void *prv;
263 }Component_CubeMapTexturing;
265 void *prv;
266 }Component_EnvironSensor;
268 void *prv;
269 }Component_Geometry3D;
271 void *prv;
272 }Component_Geospatial;
274 void *prv;
275 }Component_HAnim;
277 void *prv;
278 }Component_Layering;
280 void *prv;
281 }Component_Layout;
283 void *prv;
284 }Component_NURBS;
286 void *prv;
287 }Component_ParticleSystems;
289 void *prv;
290 }Component_ProgrammableShaders;
292 void *prv;
293 }Component_RigidBodyPhysics;
295 void *prv;
296 }Component_Followers;
298 void *prv;
299 }Component_KeyDevice;
300
301#ifdef OLDCODE
302iOLDCODE struct tComponent_Networking{
303iOLDCODE void *ReWireNamenames;
304iOLDCODE int ReWireNametableSize;
305iOLDCODE void *ReWireDevices;
306iOLDCODE int ReWireDevicetableSize;
307iOLDCODE void *prv;
308iOLDCODE }Component_Networking;
309#endif // OLDCODE
310
312 void *prv;
313 }Component_Picking;
315 void *prv;
316 }Component_Rendering;
318 void *prv;
319 }Component_Shape;
321 int sound_from_audioclip;// = 0;
322 /* is the sound engine started yet? */
323 int SoundEngineStarted;// = FALSE;
324 void *prv;
325 }Component_Sound;
327 void *prv;
328 }Component_Text;
330 void *prv;
331 }Component_VRML1;
333 void *prv;
334 }Component_VolumeRendering;
336 #ifdef OLDCODE
337 OLDCODE char *OSX_last_world_url_for_reload;
338 OLDCODE char *OSX_replace_world_from_console;
339 #endif //OLDCODE
340
341 /* Any action for the Browser to do? */
342 int BrowserAction;// = FALSE;
343 double hitPointDist; /* distance in ray: 0 = r1, 1 = r2, 2 = 2*r2-r1... */
344 /* used to save rayhit and hyperhit for later use by C functions */
345 //struct SFColor hyp_save_posn, hyp_save_norm, ray_save_posn;
346 float hyp_save_posn[3];
347 float hyp_save_norm[3];
348 float ray_save_posn[3]; //getRayHit() > last intersection of pickray/bearing with geometry, transformed into the coordinates of the geometry
349 float camera_axis[3];
350 void *hypersensitive;//= 0;
351 int hyperhit;// = 0;
352 //struct point_XYZ hp;
353 void *hp;
354 void *rayHit;
355 //void *rayHitHyper;
356 //struct point_XYZ t_r1,t_r2,t_r3; /* transformed ray */
357 //void *t_r123; /* transformed ray */
358 int lightingOn; /* do we need to restore lighting in Shape? */
359 int have_transparency;//=FALSE;/* did any Shape have transparent material? */
360 /* material node usage depends on texture depth; if rgb (depth1) we blend color field
361 and diffusecolor with texture, else, we dont bother with material colors */
362 int last_texture_type;// = NOTEXTURE;
363 /* texture stuff - see code. Need array because of MultiTextures */
364 //GLuint boundTextureStack[10];//MAX_MULTITEXTURE];
365 unsigned int boundTextureStack[10];//MAX_MULTITEXTURE];
366 int textureStackTop;
367 void *texturenode;
368 void *shapenode;
369 void *prv;
370 }RenderFuncs;
372 void *prv;
373 }StreamPoly;
374 struct tTess{
375 int *global_IFS_Coords;
376 int global_IFS_Coord_count;//=0;
377 //GLUtriangulatorObj *global_tessobj;
378 void *global_tessobj;
379 int *text_IFS_Coords;
380 int text_IFS_Coord_count;//=0;
381 //GLUtriangulatorObj *global_tessobj;
382 void *text_tessobj;
383 void *prv;
384 }Tess;
385 struct tViewer{
386 int stereotype;
387 void *prv;
388 }Viewer;
390 void *prv;
391 }statusbar;
392 struct tCParse{
393 void* globalParser;
394 void *prv;
395 }CParse;
397 void *prv;
398 }CParseParser;
399 struct tCRoutes{
400 /* EAI needs the extra parameter, so we put it globally when a RegisteredListener is clicked. */
401 void *CRoutesExtra;// = 0;
402 //jsval JSglobal_return_val;
403 void *JSSFpointer;
404 int max_script_found;// = -1; /* the maximum script number found */
405 int max_script_found_and_initialized;// = -1; /* the maximum script number found */
406 int jsnameindex; //= -1;
407 int MAXJSparamNames;// = 0;
408
409 void *prv;
410 }CRoutes;
411 struct tCScripts{
412 void *prv;
413 }CScripts;
414#ifdef JAVASCRIPT_SM
415 struct tJScript{
416 void * JSglobal_return_val;
417 void *prv;
418 }JScript;
419 struct tjsUtils{
420 void *prv;
421 }jsUtils;
422 struct tjsVRMLBrowser{
423 /* for setting field values to the output of a CreateVrml style of call */
424 /* it is kept at zero, unless it has been used. Then it is reset to zero */
425 void * JSCreate_global_return_val;
426 void *prv;
427 }jsVRMLBrowser;
428 struct tjsVRMLClasses{
429 void *prv;
430 }jsVRMLClasses;
431#endif
432#ifdef JAVASCRIPT_DUK
433 struct tJScript_duk{
434 void * JSglobal_return_val;
435 void *prv;
436 }JScript_duk;
437#endif
438 struct tBindable{
439 //struct sNaviInfo naviinfo;
440 // struct Vector *background_stack;
441 // struct Vector *viewpoint_stack;
442 // struct Vector *navigation_stack;
443 // struct Vector *fog_stack;
444 void *naviinfo;
445 //void *background_stack;
446 //void *viewpoint_stack;
447 //void *navigation_stack;
448 //void *fog_stack;
449 int activeLayer;
450 void *bstacks;
451 void *prv;
452 }Bindable;
454 int parentIndex;// = -1;
455 //struct X3D_Node *parentStack[PARENTSTACKSIZE];
456 char *CDATA_Text;// = NULL;
457 int CDATA_Text_curlen;// = 0;
458 void *prv;
459 }X3DParser;
460 struct tcommon{
461 void *prv;
462 }common;
464 void *prv;
465 }CursorDraw;
466#ifdef DISABLER
467#if defined(WRAP_MALLOC) || defined(DEBUG_MALLOC)
468 pthread_mutex_t __memTableGlobalLock;
469 IBOOL __memTable_CheckInit;
470 IBOOL __memTable_ShouldRegisterAllocation;
471 dbl_list_t *__memTable;
472#endif
473#endif
474} * ttglobal;
475#define INSTANCEGLOBAL 1
476#endif
477ttglobal iglobal_constructor();
478void iglobal_destructor(ttglobal);
479//void set_thread2global(ttglobal fwl, pthread_t any , char *desc);
480void resetGGlobal();
481ttglobal gglobal(); //gets based on threadID, errors out if no threadID
482//ppcommon gglobal_common(); // lets the front end get the myMenuStatus without hassle. dug9 Mar2014: poll for the values with get_status, get_... in common.c
483ttglobal gglobal0(); //will return null if thread not yet initialized
484//ttglobal gglobalH(void *handle); //use window handle
485//ttglobal gglobalH0(void *handle); //test if window handle is in thetable yet