/* setup routine */ void zl_3Dcontext_glx_setup(void) { /* open display: the first display on the local machine is opened, not DISPLAY. since pdp_opengl is all about direct rendering, and there is no way to specify another display, or even close it and open it again, this seems to be the "least surprise" solution. it enables the pd interface to be displayed on another display, using the DISPLAY environment variable. */ const char *display = ":0"; if (NULL == (glx_env.xdisplay = zl_xdisplay_new(display))){ ZL_LOG("3DContext: Can't open display %s\n", display); goto init_failed; } if (NULL == (glx_env.glx = zl_glx_new())) { ZL_LOG("3DContext: Can't create glx object\n"); goto init_failed; } return; init_failed: // This is a bit drastic.. exit(1); }
void zl_glx_vsync(zl_glx *x, bool sync) { #ifdef TARGET_WIN32 if (sync) { if (GLEE_WGL_EXT_swap_control) wglSwapIntervalEXT (1); } else { if (GLEE_WGL_EXT_swap_control) wglSwapIntervalEXT (0); } #endif #ifdef TARGET_OSX long sync = sync ? 1 : 0; CGLSetParameter (CGLGetCurrentContext(), kCGLCPSwapInterval, &sync); #endif #ifdef TARGET_LINUX int interval = sync ? 2 : 0; glXSwapIntervalSGIFunc glXSwapIntervalSGI = 0; glXSwapIntervalMESAFunc glXSwapIntervalMESA = 0; if (GLXExtensionSupported(x->xdpy->dpy, "GLX_MESA_swap_control")) { glXSwapIntervalMESA = (glXSwapIntervalMESAFunc) glXGetProcAddressARB((const GLubyte *)"glXSwapIntervalMESA"); if (glXSwapIntervalMESA) { ZL_LOG("glXSwapIntervalMESA(%d)", interval); glXSwapIntervalMESA (interval); } else { ZL_LOG("Could not get glXSwapIntervalMESA()\n"); } } else if (GLXExtensionSupported(x->xdpy->dpy, "GLX_SGI_swap_control")) { glXSwapIntervalSGI = (glXSwapIntervalSGIFunc) glXGetProcAddressARB((const GLubyte *)"glXSwapIntervalSGI"); if (glXSwapIntervalSGI) { ZL_LOG("glXSwapIntervalSGI(%d)", interval, glXSwapIntervalSGI); glXSwapIntervalSGI (interval); } else { ZL_LOG("Could not get glXSwapIntervalSGI()\n"); } } else { ZL_LOG("can't change vblank settings"); } #endif }
/* des */ void zl_glx_cleanup(zl_glx* x) { // XEvent e; if (x->initialized){ ZL_LOG("glXDestroyContext()\n"); glXDestroyContext(x->xdpy->dpy, x->glx_context); x->xdpy = 0; x->initialized = 0; } }
// WINDOW bool ZL_CreateWindow(const char*, int width, int height, int displayflags) { ZL_LOG("NACL", "ZL_CreateWindow - Code Window Size: %d / %d - Requested Size: %d / %d - Current View Size: %d / %d", width, height, NACL_Width, NACL_Height, recView.size.width, recView.size.height); //Window size if (NACL_Width > 0 && NACL_Height > 0) { } //use as is else if (NACL_Width > 0) NACL_Height = NACL_Width*height/width; else if (NACL_Height > 0) NACL_Width = NACL_Height*width/height; else if (recView.size.width < 2 && recView.size.height < 2) NACL_Width = width, NACL_Height = height; else NACL_Height = recView.size.width, NACL_Height = recView.size.height; recView.size.width = NACL_Width, recView.size.height = NACL_Height; if (!context3d) { //Create context int32_t attribs[] = { PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 0, PP_GRAPHICS3DATTRIB_DEPTH_SIZE, (displayflags & ZL_DISPLAY_DEPTHBUFFER ? 16 : 0), PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 0, PP_GRAPHICS3DATTRIB_SAMPLES, 4, PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 1, PP_GRAPHICS3DATTRIB_WIDTH, NACL_Width, PP_GRAPHICS3DATTRIB_HEIGHT, NACL_Height, PP_GRAPHICS3DATTRIB_NONE }; if (!(context3d = ppb_graphics3d_interface->Create(instance_, NULL, attribs)) || !ppb_instance_interface->BindGraphics(instance_, context3d)) { ZL_LOG0("NACL", "Failed to start graphics - No OpenGL available"); if (ppb_messaging_interface) ppb_messaging_interface->PostMessage(instance_, ppb_var_interface->VarFromUtf8("NOG", 3)); return false; } glSetCurrentContextPPAPI(context3d); } //WIN = Window created char msgmsg[1024]; uint32_t msgmsglen = sprintf(msgmsg, "WIN%d,%d", NACL_Width, NACL_Height); if (ppb_messaging_interface) ppb_messaging_interface->PostMessage(instance_, ppb_var_interface->VarFromUtf8(msgmsg, msgmsglen)); //PrepareOpenGL ZLGLSL::CreateShaders(); glClearColor(1, 0, 0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //WindowFlags pZL_WindowFlags = &NACL_WindowFlags; return true; }
void ZL_SetFullscreen(bool toFullscreen) { ZL_LOG("NACL", "SetFullscreen - To Status: %d - Interface: %d - Instance: %d", toFullscreen, (int)ppb_fullscreen_interface, (int)instance_); ppb_fullscreen_interface->SetFullscreen(instance_, (PP_Bool)toFullscreen); }