void SimObjectRenderer::init(bool hasSharedDisplayLists) { #ifdef MACOS CGLContextObj ctx = CGLGetCurrentContext(); VERIFY(CGLEnable(ctx, kCGLCEMPEngine) == kCGLNoError); #endif Simulation::simulation->scene->createGraphics(hasSharedDisplayLists); }
void HeadlessView::createContext() { if (!display) { throw std::runtime_error("Display is not set"); } #if MBGL_USE_CGL CGLError error = CGLCreateContext(display->pixelFormat, NULL, &glContext); if (error != kCGLNoError) { throw std::runtime_error(std::string("Error creating GL context object:") + CGLErrorString(error) + "\n"); } error = CGLEnable(glContext, kCGLCEMPEngine); if (error != kCGLNoError) { throw std::runtime_error(std::string("Error enabling OpenGL multithreading:") + CGLErrorString(error) + "\n"); } #endif #if MBGL_USE_GLX xDisplay = display->xDisplay; fbConfigs = display->fbConfigs; if (!glContext) { // Try to create a legacy context glContext = glXCreateNewContext(xDisplay, fbConfigs[0], GLX_RGBA_TYPE, None, True); if (glContext) { if (!glXIsDirect(xDisplay, glContext)) { Log::Error(Event::OpenGL, "failed to create direct OpenGL Legacy context"); glXDestroyContext(xDisplay, glContext); glContext = 0; } } } if (glContext == 0) { throw std::runtime_error("Error creating GL context object."); } // Create a dummy pbuffer. We will render to framebuffers anyway, but we need a pbuffer to // activate the context. int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, 8, GLX_PBUFFER_HEIGHT, 8, None }; glxPbuffer = glXCreatePbuffer(xDisplay, fbConfigs[0], pbufferAttributes); #endif }
PPDisplayDeviceOGL::PPDisplayDeviceOGL(pp_int32 width, pp_int32 height, pp_int32 scaleFactor, pp_int32 bpp, bool fullScreen, Orientations theOrientation/* = ORIENTATION_NORMAL*/, bool swapRedBlue/* = false*/) : PPDisplayDevice(width, height, bpp, scaleFactor, fullScreen, theOrientation) { /* Set a video mode */ theWindow = CreateWindow(width, height, bpp, SDL_WINDOW_OPENGL | (bFullScreen==true ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)); if (theWindow == NULL) { fprintf(stderr, "SDL: Could not create window: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } /* Get SDL OpenGL context */ glContext = SDL_GL_CreateContext(theWindow); if (glContext == NULL) { fprintf(stderr, "SDL: Could not create OpenGL context: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } /* Sets up OpenGL double buffering */ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); /* Use immediate updates; don't wait for Vblank */ SDL_GL_SetSwapInterval(0); #if 0 CGLError err; CGLContextObj ctx = CGLGetCurrentContext(); // Enable the multi-threading err = CGLEnable( ctx, kCGLCEMPEngine); if (err != kCGLNoError ) { exit(EXIT_FAILURE); } #endif currentGraphics = new PPGraphics_OGL(width, height); currentGraphics->lock = true; }
void HeadlessBackend::createContext() { assert(!hasContext()); CGLContextObj glContext = nullptr; CGLError error = CGLCreateContext(display->attribute<CGLPixelFormatObj>(), nullptr, &glContext); if (error != kCGLNoError) { throw std::runtime_error(std::string("Error creating GL context object:") + CGLErrorString(error) + "\n"); } error = CGLEnable(glContext, kCGLCEMPEngine); if (error != kCGLNoError) { throw std::runtime_error(std::string("Error enabling OpenGL multithreading:") + CGLErrorString(error) + "\n"); } impl.reset(new CGLImpl(glContext)); }
void TGen::OpenGL::Renderer::readCaps() { GLint viewportDims[2]; glGetIntegerv(GL_MAX_TEXTURE_UNITS , reinterpret_cast<GLint *>(&caps.maxTextureUnits)); glGetIntegerv(GL_MAX_LIGHTS, reinterpret_cast<GLint *>(&caps.maxActiveLights)); glGetIntegerv(GL_MAX_CLIP_PLANES, reinterpret_cast<GLint *>(&caps.maxClipPlanes)); glGetIntegerv(GL_MAX_ELEMENTS_INDICES, reinterpret_cast<GLint *>(&caps.maxIndexBufferIndicies)); glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, reinterpret_cast<GLint *>(&caps.maxVertexBufferVertices)); glGetIntegerv(GL_MAX_TEXTURE_SIZE, reinterpret_cast<GLint *>(&caps.maxTextureSize)); glGetIntegerv(GL_MAX_VIEWPORT_DIMS, viewportDims); glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, reinterpret_cast<GLint *>(&caps.maxFrameBufferColorAttachments)); glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT, reinterpret_cast<GLint *>(&caps.maxGeometryVerticesOutput)); #if 0 //defined(_PLATFORM_OSX) glClear(GL_COLOR_BUFFER_BIT); CGLError err; CGLContextObj ctx = CGLGetCurrentContext(); err = CGLEnable(ctx, kCGLCEMPEngine); // TODO: disable/enable mt ogl engine caps.multithreadable = (err == kCGLNoError); #else caps.multithreadable = false; #endif caps.maxViewportSize = TGen::Rectangle(viewportDims[0], viewportDims[1]); if (glGetString(GL_SHADING_LANGUAGE_VERSION)) caps.shadingLanguageVersion = (char *)(glGetString(GL_SHADING_LANGUAGE_VERSION)); else caps.shadingLanguageVersion = "N/A"; caps.driverName = "OpenGL "; caps.driverName += (char *)glGetString(GL_VERSION); caps.rendererName = (char *)glGetString(GL_RENDERER); caps.driverVendor = (char *)glGetString(GL_VENDOR); caps.vertexShader = isExtensionAvailable("GL_ARB_vertex_shader"); caps.fragmentShader = isExtensionAvailable("GL_ARB_fragment_shader"); caps.geometryShader = isExtensionAvailable("GL_EXT_geometry_shader4"); caps.framebuffer = isExtensionAvailable("GL_EXT_framebuffer_object"); caps.multitexturing = isExtensionAvailable("GL_ARB_multitexture"); caps.rectTexture = isExtensionAvailable("GL_ARB_texture_rectangle"); caps.cubeMaps = isExtensionAvailable("GL_ARB_texture_cube_map"); }
bool gl_initialize(int screen_wid,int screen_high,bool lock_fps_refresh,int fsaa_mode,bool reset,char *err_str) { GLint ntxtunit,ntxtsize; #ifdef D3_OS_MAC long swapint,rect[4]; CGLContextObj current_ctx; CFDictionaryRef mode_info; CFNumberRef cf_rate; #else GLenum glew_error; #endif // setup rendering sizes setup.screen.x_sz=screen_wid; setup.screen.y_sz=screen_high; // normal attributes SDL_GL_SetAttribute(SDL_GL_RED_SIZE,8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,16); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,8); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); // full screen anti-aliasing attributes switch (fsaa_mode) { case fsaa_mode_low: SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,2); break; case fsaa_mode_medium: SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,4); break; case fsaa_mode_high: SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,6); break; } // start window or full screen if (gl_in_window_mode()) { surface=SDL_SetVideoMode(setup.screen.x_sz,setup.screen.y_sz,32,SDL_OPENGL|SDL_HWSURFACE); SDL_WM_SetCaption("dim3",NULL); } else { surface=SDL_SetVideoMode(setup.screen.x_sz,setup.screen.y_sz,32,SDL_OPENGL|SDL_FULLSCREEN); } if (surface==NULL) { sprintf(err_str,"SDL: Could not set video mode (Error: %s)",SDL_GetError()); return(FALSE); } // work around the dock losing minimize buttons because // of SDL luncancy #ifdef D3_OS_MAC if (!gl_in_window_mode()) SetSystemUIMode(kUIModeContentSuppressed,0); #endif // use glew on linux and windows #ifndef D3_OS_MAC glew_error=glewInit(); if (glew_error!=GL_NO_ERROR) { strcpy(err_str,glewGetErrorString(glew_error)); return(FALSE); } #endif // grab openGL attributes strncpy(render_info.name,(char*)glGetString(GL_RENDERER),64); render_info.name[63]=0x0; strncpy(render_info.ext_string,(char*)glGetString(GL_EXTENSIONS),8192); render_info.ext_string[8191]=0x0; glGetIntegerv(GL_MAX_TEXTURE_UNITS,&ntxtunit); render_info.texture_unit_count=(int)ntxtunit; glGetIntegerv(GL_MAX_TEXTURE_SIZE,&ntxtsize); render_info.texture_max_size=(int)ntxtsize; // in case screen is bigger than desired drawing surface render_info.monitor_x_sz=surface->w; render_info.monitor_y_sz=surface->h; render_info.view_x=(render_info.monitor_x_sz-setup.screen.x_sz)>>1; render_info.view_y=(render_info.monitor_y_sz-setup.screen.y_sz)>>1; // determine the referesh rate render_info.monitor_refresh_rate=60; // windows XP has a stuck refresh rate of 60 #ifdef D3_OS_MAC mode_info=CGDisplayCurrentMode(CGMainDisplayID()); if (mode_info!=NULL) { cf_rate=(CFNumberRef)CFDictionaryGetValue(mode_info,kCGDisplayRefreshRate); if (cf_rate) { CFNumberGetValue(cf_rate,kCFNumberIntType,&render_info.monitor_refresh_rate); if (render_info.monitor_refresh_rate==0) render_info.monitor_refresh_rate=60; } } #endif // clear the entire window so it doesn't flash glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT); SDL_GL_SwapBuffers(); // setup renderer #ifdef D3_OS_MAC current_ctx=CGLGetCurrentContext(); rect[0]=render_info.view_x; rect[1]=render_info.view_y; rect[2]=setup.screen.x_sz; rect[3]=setup.screen.y_sz; CGLSetParameter(current_ctx,kCGLCPSwapRectangle,rect); CGLEnable(current_ctx,kCGLCESwapRectangle); if (lock_fps_refresh) { swapint=1; CGLSetParameter(current_ctx,kCGLCPSwapInterval,&swapint); } #endif glViewport(render_info.view_x,render_info.view_y,setup.screen.x_sz,setup.screen.y_sz); // perspective correction glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); // smoothing and anti-aliasing glDisable(GL_DITHER); glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH_HINT,GL_NICEST); if (fsaa_mode!=fsaa_mode_none) glEnable(GL_MULTISAMPLE); // texture compression glHint(GL_TEXTURE_COMPRESSION_HINT,GL_NICEST); glHint(GL_GENERATE_MIPMAP_HINT,GL_NICEST); // all alphas by 8 bit component glDisable(GL_ALPHA_TEST); // texture utility initialize gl_texture_initialize(); // do an initial draw if (!reset) { glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT); SDL_GL_SwapBuffers(); } return(TRUE); }
BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL disable_vsync) { BOOL glNeedsInit = FALSE; mFullscreen = fullscreen; if (mWindow == NULL) { mWindow = getMainAppWindow(); } if(mContext == NULL) { // Our OpenGL view is already defined within SecondLife.xib. // Get the view instead. mGLView = createOpenGLView(mWindow, mFSAASamples, !disable_vsync); mContext = getCGLContextObj(mGLView); // Since we just created the context, it needs to be set up. glNeedsInit = TRUE; gGLManager.mVRAM = getVramSize(mGLView); } // This sets up our view to recieve text from our non-inline text input window. setupInputWindow(mWindow, mGLView); // Hook up the context to a drawable if(mContext != NULL) { // <FS:CR> Mac OpenGL //U32 err = CGLSetCurrentContext(mContext); CGLError err = CGLSetCurrentContext(mContext); if (err != kCGLNoError) { setupFailure("Can't activate GL rendering context", "Error", OSMB_OK); return FALSE; } } // Disable vertical sync for swap GLint frames_per_swap = 0; if (disable_vsync) { frames_per_swap = 0; } else { frames_per_swap = 1; } CGLSetParameter(mContext, kCGLCPSwapInterval, &frames_per_swap); //enable multi-threaded OpenGL if (sUseMultGL) { CGLError cgl_err; CGLContextObj ctx = CGLGetCurrentContext(); cgl_err = CGLEnable( ctx, kCGLCEMPEngine); if (cgl_err != kCGLNoError ) { LL_DEBUGS("GLInit") << "Multi-threaded OpenGL not available." << LL_ENDL; } else { LL_DEBUGS("GLInit") << "Multi-threaded OpenGL enabled." << LL_ENDL; } } makeFirstResponder(mWindow, mGLView); return TRUE; }