29 #include <system_threads.h>
33 #include <libFreeWRL.h>
35 #include "vrml_parser/Structs.h"
36 #include "opengl/RasterFont.h"
37 #include "opengl/OpenGL_Utils.h"
38 #include "opengl/Textures.h"
41 #include "ui/common.h"
43 #if defined(FREEWRL_PLUGIN) && (defined(TARGET_X11) || defined(TARGET_MOTIF))
44 #include "plugin/pluginUtils.h"
65 typedef struct ivec4 {
int X;
int Y;
int W;
int H;}
ivec4;
67 ivec4 ivec4_init(
int x,
int y,
int w,
int h){
69 ret.X = x, ret.Y = y; ret.W = w; ret.H = h;
73 ivec2 ivec2_init(
int x,
int y){
83 char myMenuStatus[MAXSTAT];
84 int multi_window_capable;
86 void *display_constructor(){
87 void *v = MALLOCV(
sizeof(
struct pdisplay));
91 void display_init(
struct tdisplay* t)
96 t->display_initialized = FALSE;
100 t->window_title = NULL;
102 t->shutterGlasses = 0;
103 t->prv = display_constructor();
107 t->rdr_caps = &p->rdr_caps;
118 #if defined(ANGLEPROJECT) || defined(_ANDROID) || defined(QNX)
119 p->multi_window_capable = 0;
121 p->multi_window_capable = 1;
123 t->params = (
void*)&p->params;
133 int fv_display_initialize()
135 struct tdisplay* d = &gglobal()->display;
137 struct tOpenCL_Utils *cl = &gglobal()->OpenCL_Utils;
142 if (d->display_initialized) {
147 if (!fwl_initialize_GL()) {
152 d->display_initialized = TRUE;
156 if (!cl->OpenCL_Initialized) {
157 printf (
"doing fwl_OpenCL_startup here in fv_display_inintialize\n");
158 fwl_OpenCL_startup(cl);
163 PRINT_GL_ERROR_IF_ANY (
"end of fv_display_initialize");
181 #if defined(WINRT) || defined(_ANDROID) || defined(ANDROIDNDK) || defined(IOS)
187 #elif __linux__ //LINUX
203 #if !defined(_ANDROID) && !defined(ANDROIDNDK) && !defined(WINRT)
233 if (!fv_create_main_window2(params,share)){
269 int fv_display_initialize_desktop(){
279 if(dp->frontend_handles_display_thread){
285 return fv_display_initialize();
289 if(!p->multi_window_capable) nwindows = 1;
291 if(!fv_create_window_and_context(dp, NULL)){
294 d->display_initialized = fwl_initialize_GL();
295 targetwindow_set_params(0,dp);
299 dp->winToEmbedInto = -1;
300 p0 = targetwindow_get_params(0);
301 if(!fv_create_window_and_context(dp,p0)){
304 targetwindow_set_params(1,dp);
309 dp->winToEmbedInto = -1;
310 p1 = targetwindow_get_params(1);
311 if(!fv_create_window_and_context(dp, p1)){
314 targetwindow_set_params(2,dp);
320 #if defined(TARGET_X11) || defined(TARGET_MOTIF)
324 gglobal()->display.display_initialized = d->display_initialized;
326 DEBUG_MSG(
"FreeWRL: running as a plugin: %s\n", BOOL_STR(isBrowserPlugin));
328 PRINT_GL_ERROR_IF_ANY (
"end of fv_display_initialize");
331 #if !(defined(_MSC_VER) || defined(_ANDROID))
333 if (RUNNINGASPLUGIN) {
334 #if defined(FREEWRL_PLUGIN) && (defined(TARGET_X11) || defined(TARGET_MOTIF))
338 XMapWindow(Xdpy, Xwin);
350 int fwl_parse_geometry_string(
const char *geometry,
int *out_width,
int *out_height,
351 int *out_xpos,
int *out_ypos)
353 int width, height, xpos, ypos;
356 width = height = xpos = ypos = 0;
358 c = sscanf(geometry,
"%dx%d+%d+%d",
359 &width, &height, &xpos, &ypos);
361 if (out_width) *out_width = width;
362 if (out_height) *out_height = height;
363 if (out_xpos) *out_xpos = xpos;
364 if (out_ypos) *out_ypos = ypos;
371 void fv_setScreenDim(
int wi,
int he) { fwl_setScreenDim(wi,he); }
373 void fwl_setScreenDim1(
int wi,
int he,
int windex);
374 void fwl_setScreenDim0(
int wi,
int he)
380 tg->display.screenWidth = wi;
381 tg->display.screenHeight = he;
386 void fwl_setScreenDim(
int wi,
int he)
391 fwl_setScreenDim0(wi,he);
392 fwl_setScreenDim1(wi,he,0);
394 double display_screenRatio(){
397 if (tg->display.screenHeight != 0) ratio = (double) tg->display.screenWidth/(
double) tg->display.screenHeight;
400 void fwl_setClipPlane(
int height)
404 gglobal()->Mainloop.clipPlane = height;
409 GLvoid resize_GL(GLsizei width, GLsizei height)
411 FW_GL_VIEWPORT( 0, 0, width, height );
412 printf(
"resize_GL\n");
415 void fwl_updateScreenDim(
int wi,
int he)
417 fwl_setScreenDim(wi, he);
428 bool initialize_rdr_caps()
435 #if defined(HAVE_GLEW_H) && !defined(ANGLEPROJECT)
440 if (GLEW_OK != err) {
442 ERROR_MSG(
"GLEW initialization error: %s\n", glewGetErrorString(err));
445 TRACE_MSG(
"GLEW initialization: version %s\n", glewGetString(GLEW_VERSION));
451 p->rdr_caps.renderer = (
char *) FW_GL_GETSTRING(GL_RENDERER);
452 p->rdr_caps.version = (
char *) FW_GL_GETSTRING(GL_VERSION);
453 p->rdr_caps.vendor = (
char *) FW_GL_GETSTRING(GL_VENDOR);
454 p->rdr_caps.extensions = (
char *) FW_GL_GETSTRING(GL_EXTENSIONS);
455 FW_GL_GETBOOLEANV(GL_STEREO,&(p->rdr_caps.quadBuffer));
457 ConsoleMessage(
"openGL version %s\n",p->rdr_caps.version);
460 if (p->rdr_caps.version)
461 p->rdr_caps.versionf = (float) atof(p->rdr_caps.version);
462 if (p->rdr_caps.versionf == 0)
464 const char *openGLPrefix =
"OpenGL ES ";
465 if (NULL != p->rdr_caps.version && strstr(p->rdr_caps.version, openGLPrefix))
467 char version[256], *versionPTR;
468 sprintf(version,
"%s", p->rdr_caps.version);
469 versionPTR = version + strlen(openGLPrefix);
470 p->rdr_caps.versionf = (float) atof(versionPTR);
473 #if defined(GL_ES_VERSION_2_0) && !defined(ANGLEPROJECT)
474 if (0 == p->rdr_caps.version)
477 GLint major = 0, minor = 0;
478 #if defined(GL_MAJOR_VERSION) && defined(GL_MINOR_VERSION)
479 FW_GL_GETINTEGERV(GL_MAJOR_VERSION, &major);
480 FW_GL_GETINTEGERV(GL_MINOR_VERSION, &minor);
486 asprintf(&version,
"%d.%d", major, minor);
487 p->rdr_caps.version = version;
488 p->rdr_caps.versionf = (float) atof(p->rdr_caps.version);
494 p->rdr_caps.have_GL_VERSION_1_1 = p->rdr_caps.versionf >= 1.1f;
495 p->rdr_caps.have_GL_VERSION_1_2 = p->rdr_caps.versionf >= 1.2f;
496 p->rdr_caps.have_GL_VERSION_1_3 = p->rdr_caps.versionf >= 1.3f;
497 p->rdr_caps.have_GL_VERSION_1_4 = p->rdr_caps.versionf >= 1.4f;
498 p->rdr_caps.have_GL_VERSION_1_5 = p->rdr_caps.versionf >= 1.5f;
499 p->rdr_caps.have_GL_VERSION_2_0 = p->rdr_caps.versionf >= 2.0f;
500 p->rdr_caps.have_GL_VERSION_2_1 = p->rdr_caps.versionf >= 2.1f;
501 p->rdr_caps.have_GL_VERSION_3_0 = p->rdr_caps.versionf >= 3.0f;
507 if (p->rdr_caps.extensions){
508 p->rdr_caps.av_multitexture = (strstr(p->rdr_caps.extensions,
"GL_ARB_multitexture") != 0);
511 p->rdr_caps.av_occlusion_q = ((strstr(p->rdr_caps.extensions,
"GL_ARB_occlusion_query") != 0) ||
512 (strstr(p->rdr_caps.extensions,
"GL_EXT_occlusion_query_boolean") != 0) ||
513 p->rdr_caps.have_GL_VERSION_3_0);
517 p->rdr_caps.av_npot_texture = (strstr(p->rdr_caps.extensions,
"GL_ARB_texture_non_power_of_two") != 0);
520 p->rdr_caps.av_texture_rect = (strstr(p->rdr_caps.extensions,
"GL_ARB_texture_rectangle") != 0);
523 p->rdr_caps.av_npot_texture=FALSE;
526 p->rdr_caps.av_multitexture = 1;
528 FW_GL_GETINTEGERV(GL_MAX_TEXTURE_SIZE, &tmp);
529 p->rdr_caps.runtime_max_texture_size = (int) tmp;
530 p->rdr_caps.system_max_texture_size = (int) tmp;
536 #if defined (GL_MAX_TEXTURE_IMAGE_UNITS)
537 FW_GL_GETINTEGERV(GL_MAX_TEXTURE_IMAGE_UNITS, &tmp);
539 FW_GL_GETINTEGERV(GL_MAX_TEXTURE_UNITS, &tmp);
542 p->rdr_caps.texture_units = (int) tmp;
545 #ifdef GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
546 FW_GL_GETFLOATV (GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &p->rdr_caps.anisotropicDegree);
551 if (gglobal()->internalc.user_request_texture_size > 0) {
552 DEBUG_MSG(
"Environment set texture size: %d", gglobal()->internalc.user_request_texture_size);
553 p->rdr_caps.runtime_max_texture_size = gglobal()->internalc.user_request_texture_size;
557 if (p->rdr_caps.renderer)
559 strstr(p->rdr_caps.renderer,
"Intel GMA 9") != NULL ||
560 strstr(p->rdr_caps.renderer,
"Intel(R) 9") != NULL ||
561 strstr(p->rdr_caps.renderer,
"i915") != NULL ||
562 strstr(p->rdr_caps.renderer,
"NVIDIA GeForce2") != NULL
564 if (p->rdr_caps.runtime_max_texture_size > 1024) p->rdr_caps.runtime_max_texture_size = 1024;
568 rdr_caps_dump(&p->rdr_caps);
575 void initialize_rdr_functions()
596 p = pp = STRDUP(rdr_caps->extensions);
597 while (*pp !=
'\0') {
598 if (*pp ==
' ') *pp =
'\n';
601 DEBUG_MSG (
"OpenGL extensions : %s\n", p);
606 DEBUG_MSG (
"Multitexture support: %s\n", BOOL_STR(rdr_caps->av_multitexture));
607 DEBUG_MSG (
"Occlusion support: %s\n", BOOL_STR(rdr_caps->av_occlusion_q));
608 DEBUG_MSG (
"Max texture size %d\n", rdr_caps->runtime_max_texture_size);
609 DEBUG_MSG (
"Max texture size %d\n", rdr_caps->system_max_texture_size);
610 DEBUG_MSG (
"Texture units %d\n", rdr_caps->texture_units);