// --------------------------------------------------------- // CRollerCoasterContainer::ConstructL(const TRect& aRect) // EPOC two phased constructor // --------------------------------------------------------- // void CRollerCoasterContainer::ConstructL(const TRect& /*aRect*/) { iIsGenerating = ETrue; CreateWindowL(); // Make the window fullscreen SetExtentToWholeScreen(); ActivateL(); EGLConfig Config; // Get the display for drawing graphics iEglDisplay = eglGetDisplay( EGL_DEFAULT_DISPLAY ); if( iEglDisplay == NULL ) { _LIT(KGetDisplayFailed, "eglGetDisplay failed"); User::Panic( KGetDisplayFailed, 0 ); } // Initialize display if( eglInitialize( iEglDisplay, NULL, NULL ) == EGL_FALSE ) { _LIT(KInitializeFailed, "eglInitialize failed"); User::Panic( KInitializeFailed, 0 ); } EGLConfig *configList = NULL; EGLint numOfConfigs = 0; EGLint configSize = 0; // Get the number of possible EGLConfigs if( eglGetConfigs(iEglDisplay, configList, configSize, &numOfConfigs) == EGL_FALSE ) { _LIT(KGetConfigsFailed, "eglGetConfigs failed"); User::Panic( KGetConfigsFailed, 0 ); } configSize = numOfConfigs; // Allocate memory for the configList configList = (EGLConfig*) User::Alloc( sizeof(EGLConfig)*configSize ); if( configList == NULL ) { _LIT(KConfigAllocFailed, "config alloc failed"); User::Panic( KConfigAllocFailed, 0 ); } /* Define properties for the wanted EGLSurface. To get the best possible performance, choose an EGLConfig with a buffersize matching the current window's display mode*/ TDisplayMode DMode = Window().DisplayMode(); TInt BufferSize = 0; switch( DMode ) { case(EColor4K): BufferSize = 12; break; case(EColor64K): BufferSize = 16; break; case(EColor16M): BufferSize = 24; break; default: _LIT(KDModeError, "unsupported displaymode"); User::Panic( KDModeError, 0 ); break; } // Define properties for the wanted EGLSurface const EGLint attrib_list[] = {EGL_BUFFER_SIZE, BufferSize, EGL_DEPTH_SIZE, 16, EGL_NONE}; // Choose an EGLConfig that best matches to the properties in attrib_list if( eglChooseConfig(iEglDisplay, attrib_list, configList, configSize, &numOfConfigs) == EGL_FALSE ) { _LIT(KChooseConfigFailed, "eglChooseConfig failed"); User::Panic( KChooseConfigFailed, 0 ); } Config = configList[0]; User::Free( configList ); // Create a window where the graphics are blitted iEglSurface = eglCreateWindowSurface( iEglDisplay, Config, &Window(), NULL ); if( iEglSurface == NULL ) { _LIT(KCreateWindowSurfaceFailed, "eglCreateWindowSurface failed"); User::Panic( KCreateWindowSurfaceFailed, 0 ); } // Create a rendering context iEglContext = eglCreateContext( iEglDisplay, Config, NULL, NULL ); if( iEglContext == NULL ) { _LIT(KCreateContextFailed, "eglCreateContext failed"); User::Panic( KCreateContextFailed, 0 ); } // Make the context current. Binds context to the current rendering thread and surface. if( eglMakeCurrent(iEglDisplay, iEglSurface, iEglSurface, iEglContext) == EGL_FALSE ) { _LIT(KMakeCurrentFailed, "eglMakeCurrent failed"); User::Panic( KMakeCurrentFailed, 0 ); } TSize size; size = this->Size(); iRollerCoaster = CRollerCoaster::NewL( size.iWidth, size.iHeight ); iRollerCoaster->AppInit(); iIsGenerating = EFalse; // Create an active object for animating the scene iPeriodic = CPeriodic::NewL( CActive::EPriorityIdle ); iPeriodic->Start( 100, 100, TCallBack(CRollerCoasterContainer::DrawCallBack, this) ); //for(int i = 0 ; i < 200000000 ; i++) i += CountComponentControls(); }
void maemoGLinit() { printf ("GL init\n"); EGLint numConfigs; EGLint majorVersion; EGLint minorVersion; #if defined(USE_X11) enum { _NET_WM_STATE_REMOVE =0, _NET_WM_STATE_ADD = 1, _NET_WM_STATE_TOGGLE =2 }; Window sRootWindow; XSetWindowAttributes sWA; unsigned int ui32Mask; int i32Depth; #endif EGLint *attribList = NULL; if (use_fsaa) { printf( "GLES: Using Full Scene Antialiasing\n" ); attribList = attrib_list_fsaa; } else { attribList = attrib_list; } #if defined(USE_X11) pandora_driver_mode = MODE_X11; // TODO make configurable #else pandora_driver_mode = MODE_RAW; // TODO make configurable #endif switch(pandora_driver_mode) { #if defined(USE_X11) case MODE_X11: // Initializes the display and screen x11Display = XOpenDisplay( ":0" ); if (!x11Display) { printf("GLES Error: Unable to open X display\n"); } x11Screen = XDefaultScreen( x11Display ); // Gets the display parameters so we can pass the same parameters to the window to be created. sRootWindow = RootWindow(x11Display, x11Screen); i32Depth = DefaultDepth(x11Display, x11Screen); px11Visual = &x11Visual; XMatchVisualInfo( x11Display, x11Screen, i32Depth, TrueColor, px11Visual); if (!px11Visual) { printf("GLES Error: Unable to acquire visual\n"); } // Colormap of the specified visual type for the display. x11Colormap = XCreateColormap( x11Display, sRootWindow, px11Visual->visual, AllocNone ); sWA.colormap = x11Colormap; // List of events to be handled by the application. Add to these for handling other events. sWA.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask; // Display capabilities list. ui32Mask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap; // Creates the X11 window x11Window = XCreateWindow( x11Display, RootWindow(x11Display, x11Screen), 0, 0, iResX, iResY, 0, CopyFromParent, InputOutput, CopyFromParent, ui32Mask, &sWA); // Make the window viewable and flush the output buffer. XMapWindow(x11Display, x11Window); XFlush(x11Display); // Make the window fullscreen unsigned char fullScreen = 1; Atom wmState = XInternAtom(x11Display, "_NET_WM_STATE", False); Atom wmFullScreen = XInternAtom(x11Display,"_NET_WM_STATE_FULLSCREEN", False); XEvent xev; xev.xclient.type = ClientMessage; xev.xclient.serial = 0; xev.xclient.send_event = True; xev.xclient.window = x11Window; xev.xclient.message_type = wmState; xev.xclient.format = 32; xev.xclient.data.l[0] = (fullScreen ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE); xev.xclient.data.l[1] = wmFullScreen; xev.xclient.data.l[2] = 0; XSendEvent(x11Display, DefaultRootWindow(x11Display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); display = eglGetDisplay( (EGLNativeDisplayType)x11Display ); break; #endif case MODE_RAW: default: display = eglGetDisplay( (EGLNativeDisplayType)0 ); break; } if( display == EGL_NO_DISPLAY ) { printf( "GLES EGL Error: GL No Display\n" ); } if( !eglInitialize( display, &majorVersion, &minorVersion ) ) { printf( "GLES EGL Error: eglInitialize failed\n" ); } if( !eglChooseConfig( display, attribList, &config, 1, &numConfigs ) ) { printf( "GLES EGL Error: eglChooseConfig failed\n" ); } context = eglCreateContext( display, config, NULL, NULL ); if( context==0 ) { printf( "GLES EGL Error: eglCreateContext failed\n" ); } switch(pandora_driver_mode) { #if defined(USE_X11) case MODE_X11: surface = eglCreateWindowSurface( display, config, (EGLNativeDisplayType)x11Window, NULL ); break; #endif case MODE_RAW: default: surface = eglCreateWindowSurface( display, config, (EGLNativeDisplayType)0, NULL ); break; } eglMakeCurrent( display, surface, surface, context ); if (!TestEGLError("eglMakeCurrent")) printf("error eglMakeCurrent"); else printf("GLES Window Opened\n"); }
static Bool make_x_window(struct app_data *data, const char *name, int x, int y, int width, int height) { static const EGLint attribs[] = { EGL_RED_SIZE, 1, EGL_GREEN_SIZE, 1, EGL_BLUE_SIZE, 1, EGL_DEPTH_SIZE, 1, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, EGL_NONE }; static const EGLint ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE }; int scrnum; XSetWindowAttributes attr; unsigned long mask; Window root; Window win; XVisualInfo *visInfo, visTemplate; int num_visuals; EGLConfig config; EGLint num_configs; EGLint vid; scrnum = DefaultScreen( data->xdpy ); root = RootWindow( data->xdpy, scrnum ); if (!eglChooseConfig( data->dpy, attribs, &config, 1, &num_configs)) { printf("Error: couldn't get an EGL visual config\n"); exit(1); } assert(config); assert(num_configs > 0); if (!eglGetConfigAttrib(data->dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) { printf("Error: eglGetConfigAttrib() failed\n"); exit(1); } /* The X window visual must match the EGL config */ visTemplate.visualid = vid; visInfo = XGetVisualInfo(data->xdpy, VisualIDMask, &visTemplate, &num_visuals); if (!visInfo) { printf("Error: couldn't get X visual\n"); exit(1); } /* window attributes */ attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap( data->xdpy, root, visInfo->visual, AllocNone); attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask | ButtonPressMask | ButtonMotionMask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; win = XCreateWindow( data->xdpy, root, 0, 0, width * 2, height, 0, visInfo->depth, InputOutput, visInfo->visual, mask, &attr ); /* set hints and properties */ { XSizeHints sizehints; sizehints.x = x; sizehints.y = y; sizehints.width = width; sizehints.height = height; sizehints.flags = USSize | USPosition; XSetNormalHints(data->xdpy, win, &sizehints); XSetStandardProperties(data->xdpy, win, name, name, None, (char **)NULL, 0, &sizehints); } data->canvas = win; attr.event_mask = 0x0; win = XCreateWindow( data->xdpy, win, width, 0, width, height, 0, visInfo->depth, InputOutput, visInfo->visual, mask, &attr ); data->cube = win; eglBindAPI(EGL_OPENGL_ES_API); data->ctx = eglCreateContext(data->dpy, config, EGL_NO_CONTEXT, ctx_attribs ); if (!data->ctx) { printf("Error: eglCreateContext failed\n"); exit(1); } data->surf = eglCreateWindowSurface(data->dpy, config, data->cube, NULL); if (!data->surf) { printf("Error: eglCreateWindowSurface failed\n"); exit(1); } XFree(visInfo); return (data->canvas && data->cube && data->ctx && data->surf); }
void AppLocal::CreateWindowSurface() { LOG( "AppLocal::CreateWindowSurface()" ); // Optionally force the window to a different resolution, which // will be automatically scaled up by the HWComposer. // // Useful for checking operation, but note that the "frame" is always in full // display resolution, while the source crop can be shrunk down: // adb shell dumpsys SurfaceFlinger // // Strangely, setting the format here doesn't actually change the window bit depth. // The window bit depth seems to be determined solely by the EGL config, presumably // on eglMakeCurrent. // // That also means that it can't be changed by localparms between leave / enter vr mode, // you need to quit all the way out to get the new value. if ( VrSettings.Use16BitFramebuffer ) { const int displayPixelsWide = vrapi_GetSystemPropertyInt( &Java, VRAPI_SYS_PROP_DISPLAY_PIXELS_WIDE ); const int displayPixelsHigh = vrapi_GetSystemPropertyInt( &Java, VRAPI_SYS_PROP_DISPLAY_PIXELS_HIGH ); LOG( "ANativeWindow_setBuffersGeometry( %i, %i, %s )", displayPixelsWide, displayPixelsHigh, VrSettings.Use16BitFramebuffer ? "5:6:5" : "8:8:8:8" ); ANativeWindow_setBuffersGeometry( nativeWindow, displayPixelsWide, displayPixelsHigh, VrSettings.Use16BitFramebuffer ? WINDOW_FORMAT_RGB_565 : WINDOW_FORMAT_RGBA_8888 ); } EGLint attribs[16]; int numAttribs = 0; // Set the colorspace on the window if ( VrSettings.UseSrgbFramebuffer ) { attribs[numAttribs++] = EGL_GL_COLORSPACE_KHR; attribs[numAttribs++] = EGL_GL_COLORSPACE_SRGB_KHR; } attribs[numAttribs++] = EGL_NONE; // Android doesn't let the non-standard extensions show up in the // extension string, so we need to try it blind. windowSurface = eglCreateWindowSurface( glSetup.display, glSetup.config, nativeWindow, attribs ); if ( windowSurface == EGL_NO_SURFACE ) { const EGLint attribs2[] = { EGL_NONE }; windowSurface = eglCreateWindowSurface( glSetup.display, glSetup.config, nativeWindow, attribs2 ); if ( windowSurface == EGL_NO_SURFACE ) { FAIL( "eglCreateWindowSurface failed: %s", GL_GetErrorString() ); } FramebufferIsSrgb = false; } else { FramebufferIsSrgb = VrSettings.UseSrgbFramebuffer; } LOG( "nativeWindow %p gives surface %p", nativeWindow, windowSurface ); if ( eglMakeCurrent( glSetup.display, windowSurface, windowSurface, glSetup.context ) == EGL_FALSE ) { FAIL( "eglMakeCurrent failed: %s", GL_GetErrorString() ); } }
//----------------------------------------------------------------------------// int main(int argc, char* argv[]) { // Create X11 window. Display* dpy = XOpenDisplay(0); int scn = DefaultScreen(dpy); Window wnd = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 50, 50, 480, 320, 1, BlackPixel(dpy, scn), WhitePixel(dpy, scn)); XSelectInput(dpy, wnd, StructureNotifyMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask); XMapWindow(dpy, wnd); XEvent evt; while (true) { XNextEvent(dpy, &evt); if (evt.type == MapNotify) break; } // EGL setup EGLDisplay egldpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); EGLint majVer, minVer; eglInitialize(egldpy, &majVer, &minVer); EGLint attrs[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE }; EGLConfig config; EGLint numconfigs; eglChooseConfig(egldpy, attrs, &config, 1, &numconfigs); EGLSurface surface = eglCreateWindowSurface(egldpy, config, (NativeWindowType)wnd, 0); EGLContext ctx = eglCreateContext(egldpy, config, 0, 0); eglMakeCurrent(egldpy, surface, surface, ctx); eglBindAPI(EGL_OPENGL_ES_API); // basic gl state setup; glViewport(0, 0, 480, 320); glClearColor(0.2, 0.2, 0.2, 1); // CEGUI setup CEGUI::OpenGLESRenderer::bootstrapSystem(); initialiseResourceGroupDirectories(); initialiseDefaultResourceGroups(); CEGUI::SchemeManager::getSingleton().createFromFile("TaharezLook.scheme"); CEGUI::System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage("TaharezLook/MouseArrow"); CEGUI::WindowManager& winMgr(CEGUI::WindowManager::getSingleton()); CEGUI::Window* root = winMgr.createWindow("DefaultWindow", "root"); CEGUI::Window* fw = root->createChild("TaharezLook/FrameWindow"); fw->setPosition(CEGUI::UVector2(CEGUI::UDim(0.25, 0), CEGUI::UDim(0.25, 0))); fw->setSize(CEGUI::USize(CEGUI::UDim(0.5, 0), CEGUI::UDim(0.5, 0))); fw->setText("OpenGL ES 1 Test"); CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(root); // Main looop bool running = true; while (running) { while (XPending(dpy)) { XNextEvent(dpy, &evt); switch (evt.type) { case KeyPress: { int kspkcr; KeySym* ks = XGetKeyboardMapping(dpy, evt.xkey.keycode, 1, &kspkcr); if (ks[0] == XK_Escape) running = false; break; } case MotionNotify: CEGUI::System::getSingleton().getDefaultGUIContext().injectMousePosition(evt.xmotion.x, evt.xmotion.y); break; case ButtonPress: { CEGUI::MouseButton btn; if (evt.xbutton.button == Button1) btn = CEGUI::LeftButton; else if (evt.xbutton.button == Button2) btn = CEGUI::RightButton; else break; CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonDown(btn); break; } case ButtonRelease: { CEGUI::MouseButton btn; if (evt.xbutton.button == Button1) btn = CEGUI::LeftButton; else if (evt.xbutton.button == Button2) btn = CEGUI::RightButton; else break; CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonUp(btn); break; } } } glClear(GL_COLOR_BUFFER_BIT); CEGUI::System::getSingleton().renderAllGUIContexts(); eglSwapBuffers(egldpy, surface); } // cleanup CEGUI::OpenGLESRenderer::destroySystem(); eglMakeCurrent(egldpy, 0, 0, 0); eglDestroyContext(egldpy, ctx); eglDestroySurface(egldpy, surface); eglTerminate(dpy); eglReleaseThread(); XCloseDisplay(dpy); return 0; }
static int angle_init(struct MPGLContext *ctx, int flags) { struct priv *p = ctx->priv; struct vo *vo = ctx->vo; if (!vo_w32_init(vo)) goto fail; HDC dc = GetDC(vo_w32_hwnd(vo)); if (!dc) { MP_FATAL(vo, "Couldn't get DC\n"); goto fail; } PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT = (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT"); if (!eglGetPlatformDisplayEXT) { MP_FATAL(vo, "Missing EGL_EXT_platform_base\n"); goto fail; } EGLint d3d_types[] = {EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE}; for (int i = 0; i < MP_ARRAY_SIZE(d3d_types); i++) { EGLint display_attributes[] = { EGL_PLATFORM_ANGLE_TYPE_ANGLE, d3d_types[i], EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE, EGL_NONE, }; p->egl_display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, dc, display_attributes); if (p->egl_display != EGL_NO_DISPLAY) break; } if (p->egl_display == EGL_NO_DISPLAY) { MP_FATAL(vo, "Couldn't get display\n"); goto fail; } if (!eglInitialize(p->egl_display, NULL, NULL)) { MP_FATAL(vo, "Couldn't initialize EGL\n"); goto fail; } eglBindAPI(EGL_OPENGL_ES_API); if (eglGetError() != EGL_SUCCESS) { MP_FATAL(vo, "Couldn't bind GLES API\n"); goto fail; } EGLConfig config = select_fb_config_egl(ctx); if (!config) goto fail; p->egl_surface = eglCreateWindowSurface(p->egl_display, config, vo_w32_hwnd(vo), NULL); if (p->egl_surface == EGL_NO_SURFACE) { MP_FATAL(ctx->vo, "Could not create EGL surface!\n"); goto fail; } if (!create_context_egl(ctx, config, 3) && !create_context_egl(ctx, config, 2)) { MP_FATAL(ctx->vo, "Could not create EGL context!\n"); goto fail; } mpgl_load_functions(ctx->gl, get_proc_address, NULL, vo->log); return 0; fail: angle_uninit(ctx); return -1; }
static bool gfx_ctx_xegl_set_video_mode(void *data, unsigned width, unsigned height, bool fullscreen) { EGLint egl_attribs[16]; EGLint *attr; EGLint vid, num_visuals; bool windowed_full; bool true_full = false; int x_off = 0; int y_off = 0; struct sigaction sa = {{0}}; XVisualInfo temp = {0}; XSetWindowAttributes swa = {0}; XVisualInfo *vi = NULL; driver_t *driver = driver_get_ptr(); settings_t *settings = config_get_ptr(); int (*old_handler)(Display*, XErrorEvent*) = NULL; XEvent event; sa.sa_handler = egl_sighandler; sa.sa_flags = SA_RESTART; sigemptyset(&sa.sa_mask); sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); windowed_full = settings->video.windowed_fullscreen; true_full = false; attr = egl_attribs; attr = xegl_fill_attribs(attr); if (!eglGetConfigAttrib(g_egl_dpy, g_egl_config, EGL_NATIVE_VISUAL_ID, &vid)) goto error; temp.visualid = vid; vi = XGetVisualInfo(g_dpy, VisualIDMask, &temp, &num_visuals); if (!vi) goto error; swa.colormap = g_cmap = XCreateColormap(g_dpy, RootWindow(g_dpy, vi->screen), vi->visual, AllocNone); swa.event_mask = StructureNotifyMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask | KeyReleaseMask; swa.override_redirect = fullscreen ? True : False; if (fullscreen && !windowed_full) { if (x11_enter_fullscreen(g_dpy, width, height, &g_desktop_mode)) { g_should_reset_mode = true; true_full = true; } else RARCH_ERR("[X/EGL]: Entering true fullscreen failed. Will attempt windowed mode.\n"); } if (settings->video.monitor_index) g_screen = settings->video.monitor_index - 1; #ifdef HAVE_XINERAMA if (fullscreen || g_screen != 0) { unsigned new_width = width; unsigned new_height = height; if (x11_get_xinerama_coord(g_dpy, g_screen, &x_off, &y_off, &new_width, &new_height)) RARCH_LOG("[X/EGL]: Using Xinerama on screen #%u.\n", g_screen); else RARCH_LOG("[X/EGL]: Xinerama is not active on screen.\n"); if (fullscreen) { width = new_width; height = new_height; } } #endif RARCH_LOG("[X/EGL]: X = %d, Y = %d, W = %u, H = %u.\n", x_off, y_off, width, height); g_win = XCreateWindow(g_dpy, RootWindow(g_dpy, vi->screen), x_off, y_off, width, height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask | (true_full ? CWOverrideRedirect : 0), &swa); XSetWindowBackground(g_dpy, g_win, 0); g_egl_ctx = eglCreateContext(g_egl_dpy, g_egl_config, EGL_NO_CONTEXT, attr != egl_attribs ? egl_attribs : NULL); RARCH_LOG("[X/EGL]: Created context: %p.\n", (void*)g_egl_ctx); if (g_egl_ctx == EGL_NO_CONTEXT) goto error; if (g_use_hw_ctx) { g_egl_hw_ctx = eglCreateContext(g_egl_dpy, g_egl_config, g_egl_ctx, attr != egl_attribs ? egl_attribs : NULL); RARCH_LOG("[X/EGL]: Created shared context: %p.\n", (void*)g_egl_hw_ctx); if (g_egl_hw_ctx == EGL_NO_CONTEXT) goto error; } g_egl_surf = eglCreateWindowSurface(g_egl_dpy, g_egl_config, (EGLNativeWindowType)g_win, NULL); if (!g_egl_surf) goto error; if (!eglMakeCurrent(g_egl_dpy, g_egl_surf, g_egl_surf, g_egl_ctx)) goto error; RARCH_LOG("[X/EGL]: Current context: %p.\n", (void*)eglGetCurrentContext()); x11_set_window_attr(g_dpy, g_win); if (fullscreen) x11_show_mouse(g_dpy, g_win, false); if (true_full) { RARCH_LOG("[X/EGL]: Using true fullscreen.\n"); XMapRaised(g_dpy, g_win); } else if (fullscreen) { /* We attempted true fullscreen, but failed. * Attempt using windowed fullscreen. */ XMapRaised(g_dpy, g_win); RARCH_LOG("[X/EGL]: Using windowed fullscreen.\n"); /* We have to move the window to the screen we * want to go fullscreen on first. * x_off and y_off usually get ignored in XCreateWindow(). */ x11_move_window(g_dpy, g_win, x_off, y_off, width, height); x11_windowed_fullscreen(g_dpy, g_win); } else { XMapWindow(g_dpy, g_win); /* If we want to map the window on a different screen, * we'll have to do it by force. * * Otherwise, we should try to let the window manager sort it out. * x_off and y_off usually get ignored in XCreateWindow(). */ if (g_screen) x11_move_window(g_dpy, g_win, x_off, y_off, width, height); } XIfEvent(g_dpy, &event, egl_wait_notify, NULL); g_quit_atom = XInternAtom(g_dpy, "WM_DELETE_WINDOW", False); if (g_quit_atom) XSetWMProtocols(g_dpy, g_win, &g_quit_atom, 1); gfx_ctx_xegl_swap_interval(data, g_interval); /* This can blow up on some drivers. It's not fatal, * so override errors for this call. */ old_handler = XSetErrorHandler(egl_nul_handler); XSetInputFocus(g_dpy, g_win, RevertToNone, CurrentTime); XSync(g_dpy, False); XSetErrorHandler(old_handler); XFree(vi); g_has_focus = true; g_inited = true; if (!x11_create_input_context(g_dpy, g_win, &g_xim, &g_xic)) goto error; driver->display_type = RARCH_DISPLAY_X11; driver->video_display = (uintptr_t)g_dpy; driver->video_window = (uintptr_t)g_win; g_true_full = true_full; return true; error: if (vi) XFree(vi); gfx_ctx_xegl_destroy(data); return false; }
static void init_ogl( void ) { int32_t success; static EGL_DISPMANX_WINDOW_T nativewindow; DISPMANX_ELEMENT_HANDLE_T dispman_element; DISPMANX_DISPLAY_HANDLE_T dispman_display; DISPMANX_UPDATE_HANDLE_T dispman_update; VC_RECT_T dst_rect; VC_RECT_T src_rect; EGLBoolean result; // Change this to get without alpha to save some resources. static const EGLint attribute_list[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 0, // was 8 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE }; static const EGLint context_attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; EGLConfig config; EGLint num_config; bcm_host_init(); // get an EGL display connection display = eglGetDisplay(EGL_DEFAULT_DISPLAY); assert( display!=EGL_NO_DISPLAY ); // initialize the EGL display connection result = eglInitialize( display, NULL, NULL); assert(EGL_FALSE != result); // get an appropriate EGL frame buffer configuration result = eglChooseConfig( display, attribute_list, &config, 1, &num_config); assert(EGL_FALSE != result); // get an appropriate EGL frame buffer configuration result = eglBindAPI(EGL_OPENGL_ES_API); assert(EGL_FALSE != result); // create an EGL rendering context context = eglCreateContext( display, config, EGL_NO_CONTEXT, context_attributes ); assert( context != EGL_NO_CONTEXT ); // create an EGL window surface success = graphics_get_display_size(0 /* LCD */, &screenWidth, &screenHeight); assert( success >= 0 ); printf( "Screen size: %d x %d pixels\n", screenWidth, screenHeight ); dst_rect.x = 0; dst_rect.y = 0; dst_rect.width = screenWidth; dst_rect.height = screenHeight; src_rect.x = 0; src_rect.y = 0; src_rect.width = screenWidth << 16; src_rect.height = screenHeight << 16; dispman_display = vc_dispmanx_display_open( 0 /* LCD */); dispman_update = vc_dispmanx_update_start( 0 ); dispman_element = vc_dispmanx_element_add ( dispman_update, dispman_display, 0/*layer*/, &dst_rect, 0/*src*/, &src_rect, DISPMANX_PROTECTION_NONE, 0 /*alpha*/, 0/*clamp*/, 0/*transform*/); nativewindow.element = dispman_element; nativewindow.width = screenWidth; nativewindow.height = screenHeight; vc_dispmanx_update_submit_sync( dispman_update ); surface = eglCreateWindowSurface( display, config, &nativewindow, NULL ); assert(surface != EGL_NO_SURFACE); // connect the context to the surface result = eglMakeCurrent( display, surface, surface, context); assert(EGL_FALSE != result); }
static int _egl_init (s52engine *engine) { g_print("s52egl:_egl_init(): starting ..\n"); if ((NULL!=engine->eglDisplay) && (EGL_NO_DISPLAY!=engine->eglDisplay)) { g_print("_egl_init(): EGL is already up .. skipped!\n"); return FALSE; } // EGL Error code - // #define EGL_SUCCESS 0x3000 // #define EGL_NOT_INITIALIZED 0x3001 // #define EGL_BAD_ACCESS 0x3002 // #define EGL_BAD_ALLOC 0x3003 // #define EGL_BAD_ATTRIBUTE 0x3004 // #define EGL_BAD_CONFIG 0x3005 // #define EGL_BAD_CONTEXT 0x3006 // #define EGL_BAD_CURRENT_SURFACE 0x3007 // #define EGL_BAD_DISPLAY 0x3008 // #define EGL_BAD_MATCH 0x3009 // #define EGL_BAD_NATIVE_PIXMAP 0x300A // #define EGL_BAD_NATIVE_WINDOW 0x300B // #define EGL_BAD_PARAMETER 0x300C // #define EGL_BAD_SURFACE 0x300D // #define EGL_CONTEXT_LOST 0x300E EGLNativeWindowType eglWindow = 0; EGLDisplay eglDisplay = EGL_NO_DISPLAY; EGLSurface eglSurface = EGL_NO_SURFACE; EGLContext eglContext = EGL_NO_CONTEXT; EGLBoolean ret = eglBindAPI(EGL_OPENGL_ES_API); if (EGL_TRUE != ret) g_print("eglBindAPI() failed. [0x%x]\n", eglGetError()); eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (EGL_NO_DISPLAY == eglDisplay) g_print("eglGetDisplay() failed. [0x%x]\n", eglGetError()); EGLint major = 2; EGLint minor = 0; if (EGL_FALSE == eglInitialize(eglDisplay, &major, &minor) || EGL_SUCCESS != eglGetError()) g_print("eglInitialize() failed. [0x%x]\n", eglGetError()); g_print("EGL Version :%s\n", eglQueryString(eglDisplay, EGL_VERSION)); g_print("EGL Vendor :%s\n", eglQueryString(eglDisplay, EGL_VENDOR)); g_print("EGL Extensions:%s\n", eglQueryString(eglDisplay, EGL_EXTENSIONS)); // Here, the application chooses the configuration it desires. In this // sample, we have a very simplified selection process, where we pick // the first EGLConfig that matches our criteria EGLint eglNumConfigs = 0; EGLConfig eglConfig; eglGetConfigs(eglDisplay, NULL, 0, &eglNumConfigs); g_print("eglNumConfigs = %i\n", eglNumConfigs); /* int i = 0; for (i = 0; i<eglNumConfigs; ++i) { EGLint samples = 0; //if (EGL_FALSE == eglGetConfigAttrib(eglDisplay, eglConfig[i], EGL_SAMPLES, &samples)) // printf("eglGetConfigAttrib in loop for an EGL_SAMPLES fail at i = %i\n", i); if (EGL_FALSE == eglGetConfigAttrib(eglDisplay, eglConfig[i], EGL_SAMPLE_BUFFERS, &samples)) printf("eglGetConfigAttrib in loop for an EGL_SAMPLE_BUFFERS fail at i = %i\n", i); if (samples > 0) printf("sample found: %i\n", samples); } eglGetConfigs(eglDisplay, configs, num_config[0], num_config)) */ // Here specify the attributes of the desired configuration. // Below, we select an EGLConfig with at least 8 bits per color // component compatible with on-screen windows const EGLint eglConfigList[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_NONE }; if (EGL_FALSE == eglChooseConfig(eglDisplay, eglConfigList, &eglConfig, 1, &eglNumConfigs)) g_print("eglChooseConfig() failed. [0x%x]\n", eglGetError()); if (0 == eglNumConfigs) g_print("eglChooseConfig() eglNumConfigs no matching config [0x%x]\n", eglGetError()); eglWindow = (EGLNativeWindowType) gtk_widget_get_window(engine->window); if (FALSE == eglWindow) { g_print("ERROR: EGLNativeWindowType is NULL (can't draw)\n"); g_assert(0); } g_print("DEBUG: eglDisplay =0X%X\n", (guint)eglDisplay); g_print("DEBUG: eglConfig =0X%X\n", (guint)eglConfig); g_print("DEBUG: eglWindowXID=0X%X\n", (guint)GDK_WINDOW_XID(eglWindow)); eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, GDK_WINDOW_XID(gtk_widget_get_window(engine->window)), NULL); if (EGL_NO_SURFACE == eglSurface || EGL_SUCCESS != eglGetError()) g_print("eglCreateWindowSurface() failed. EGL_NO_SURFACE [0x%x]\n", eglGetError()); // Then we can create the context and set it current: EGLint eglContextList[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; eglContext = eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, eglContextList); if (EGL_NO_CONTEXT == eglContext || EGL_SUCCESS != eglGetError()) g_print("eglCreateContext() failed. [0x%x]\n", eglGetError()); if (EGL_FALSE == eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) g_print("Unable to eglMakeCurrent()\n"); engine->eglDisplay = eglDisplay; engine->eglContext = eglContext; engine->eglSurface = eglSurface; engine->eglWindow = eglWindow; g_print("s52egl:_egl_init(): end ..\n"); return 1; }
OGLESRenderWindow::OGLESRenderWindow(std::string const & name, RenderSettings const & settings) : OGLESFrameBuffer(false) { // Store info name_ = name; width_ = settings.width; height_ = settings.height; isFullScreen_ = settings.full_screen; color_bits_ = NumFormatBits(settings.color_fmt); WindowPtr const & main_wnd = Context::Instance().AppInstance().MainWnd(); on_paint_connect_ = main_wnd->OnPaint().connect(bind(&OGLESRenderWindow::OnPaint, this, placeholders::_1)); on_exit_size_move_connect_ = main_wnd->OnExitSizeMove().connect(bind(&OGLESRenderWindow::OnExitSizeMove, this, placeholders::_1)); on_size_connect_ = main_wnd->OnSize().connect(bind(&OGLESRenderWindow::OnSize, this, placeholders::_1, placeholders::_2)); on_close_connect_ = main_wnd->OnClose().connect(bind(&OGLESRenderWindow::OnClose, this, placeholders::_1)); if (isFullScreen_) { left_ = 0; top_ = 0; } else { top_ = settings.top; left_ = settings.left; } display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY); int r_size, g_size, b_size, a_size, d_size, s_size; switch (settings.color_fmt) { case EF_ARGB8: case EF_ABGR8: r_size = 8; g_size = 8; b_size = 8; a_size = 8; break; case EF_A2BGR10: r_size = 10; g_size = 10; b_size = 10; a_size = 2; break; default: BOOST_ASSERT(false); break; } switch (settings.depth_stencil_fmt) { case EF_D16: d_size = 16; s_size = 0; break; case EF_D24S8: d_size = 24; s_size = 8; break; case EF_D32F: d_size = 32; s_size = 0; break; default: d_size = 0; s_size = 0; break; } std::vector<EGLint> visual_attr; visual_attr.push_back(EGL_RENDERABLE_TYPE); visual_attr.push_back(EGL_OPENGL_ES3_BIT_KHR); visual_attr.push_back(EGL_RED_SIZE); visual_attr.push_back(r_size); visual_attr.push_back(EGL_GREEN_SIZE); visual_attr.push_back(g_size); visual_attr.push_back(EGL_BLUE_SIZE); visual_attr.push_back(b_size); visual_attr.push_back(EGL_ALPHA_SIZE); visual_attr.push_back(a_size); if (d_size > 0) { visual_attr.push_back(EGL_DEPTH_SIZE); visual_attr.push_back(d_size); } if (s_size > 0) { visual_attr.push_back(EGL_STENCIL_SIZE); visual_attr.push_back(s_size); } if (settings.sample_count > 1) { visual_attr.push_back(EGL_SAMPLES); visual_attr.push_back(settings.sample_count); } visual_attr.push_back(EGL_NONE); // end of list EGLint major_ver, minor_ver; EGLint num_cfgs; eglInitialize(display_, &major_ver, &minor_ver); eglGetConfigs(display_, nullptr, 0, &num_cfgs); #if !defined(KLAYGE_PLATFORM_ANDROID) || (__ANDROID_API__ >= 18) if (!eglChooseConfig(display_, &visual_attr[0], &cfg_, 1, &num_cfgs)) #endif { visual_attr[1] = EGL_OPENGL_ES2_BIT; eglChooseConfig(display_, &visual_attr[0], &cfg_, 1, &num_cfgs); } NativeWindowType wnd; #if defined KLAYGE_PLATFORM_WINDOWS wnd = hWnd_ = main_wnd->HWnd(); hDC_ = ::GetDC(hWnd_); #elif defined KLAYGE_PLATFORM_LINUX wnd = x_window_ = main_wnd->XWindow(); #elif defined KLAYGE_PLATFORM_ANDROID wnd = a_window_ = main_wnd->AWindow(); EGLint format; eglGetConfigAttrib(display_, cfg_, EGL_NATIVE_VISUAL_ID, &format); ANativeWindow_setBuffersGeometry(wnd, 0, 0, format); #endif surf_ = eglCreateWindowSurface(display_, cfg_, wnd, nullptr); EGLint ctx_attr[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE }; #if !defined(KLAYGE_PLATFORM_ANDROID) || (__ANDROID_API__ >= 18) context_ = eglCreateContext(display_, cfg_, EGL_NO_CONTEXT, ctx_attr); if (nullptr == context_) #endif { ctx_attr[1] = 2; context_ = eglCreateContext(display_, cfg_, EGL_NO_CONTEXT, ctx_attr); } eglMakeCurrent(display_, surf_, surf_, context_); if (!glloader_GLES_VERSION_2_0()) { THR(errc::function_not_supported); } eglSwapInterval(display_, 0); glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); viewport_->left = 0; viewport_->top = 0; viewport_->width = width_; viewport_->height = height_; std::wstring vendor, renderer, version; Convert(vendor, reinterpret_cast<char const *>(glGetString(GL_VENDOR))); Convert(renderer, reinterpret_cast<char const *>(glGetString(GL_RENDERER))); Convert(version, reinterpret_cast<char const *>(glGetString(GL_VERSION))); std::wostringstream oss; oss << vendor << L" " << renderer << L" " << version; if (settings.sample_count > 1) { oss << L" (" << settings.sample_count << L"x AA)"; } description_ = oss.str(); }
void EGLRuntime::initializeEGL(OpenGLESVersion requestedAPIVersion) { Platform* platform = Platform::getInstance(); EGLBoolean success = EGL_FALSE; #if defined(_WIN32) /* Win32 */ display = eglGetDisplay(platform->deviceContext); #elif defined(__arm__) /* Linux on ARM */ display = eglGetDisplay(EGL_DEFAULT_DISPLAY); #else /* Desktop Linux */ platform->display = XOpenDisplay(NULL); display = eglGetDisplay(platform->display); #endif if(display == EGL_NO_DISPLAY) { EGLint error = eglGetError(); LOGE("eglGetError(): %i (0x%.4x)\n", (int)error, (int)error); LOGE("No EGL Display available at %s:%i\n", __FILE__, __LINE__); exit(1); } /* Initialize EGL. */ success = eglInitialize(display, NULL, NULL); if(success != EGL_TRUE) { EGLint error = eglGetError(); LOGE("eglGetError(): %i (0x%.4x)\n", (int)error, (int)error); LOGE("Failed to initialize EGL at %s:%i\n", __FILE__, __LINE__); exit(1); } /* Depending on app-requested EGL attributes, tweak the attributes we pass to EGL. */ if(requestedAPIVersion == OPENGLES1) { configAttributes[15] = EGL_OPENGL_ES_BIT; contextAttributes[1] = 1; } else if(requestedAPIVersion == OPENGLES2) { configAttributes[15] = EGL_OPENGL_ES2_BIT; contextAttributes[1] = 2; } /* * Despite the fact an OpenGL ES 3.0 config is required, we request configs using the OpenGL_ES2_BIT. * At the time of writing there is no OpenGL_ES3_BIT, and so platforms return * OpenGL ES 3.0 configs with the OpenGL_ES2_BIT set. * We request a context with EGL_CONTEXT_CLIENT_VERSION of 3 (OpenGL ES 3.0) which will ensure that * OpenGL ES 3.0 features are supported. */ else if (requestedAPIVersion == OPENGLES3) { configAttributes[15] = EGL_OPENGL_ES2_BIT; contextAttributes[1] = 3; } /* * Find a matching config and store it in our static variable. * On ARM devices perform a strict match to ensure we get the best performance. * On desktop devices perform a loose match to ensure greatest compatability. */ #if defined(__arm__) config = findConfig(true); #else config = findConfig(false); #endif #if defined(__linux__) && !defined(__arm__) ((DesktopLinuxPlatform*)(platform))->createX11Window(); #endif /* Create a surface. */ surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType)(platform->window), windowAttributes); if(surface == EGL_NO_SURFACE) { EGLint error = eglGetError(); LOGE("eglGetError(): %i (0x%.4x)\n", (int)error, (int)error); LOGE("Failed to create EGL surface at %s:%i\n", __FILE__, __LINE__); exit(1); } /* Unconditionally bind to OpenGL ES API as we exit this function, since it's the default. */ eglBindAPI(EGL_OPENGL_ES_API); context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttributes); if(context == EGL_NO_CONTEXT) { EGLint error = eglGetError(); LOGE("eglGetError(): %i (0x%.4x)\n", (int)error, (int)error); LOGE("Failed to create EGL context at %s:%i\n", __FILE__, __LINE__); exit(1); } }
static bool gfx_ctx_set_video_mode( unsigned width, unsigned height, bool fullscreen) { if (g_inited) return false; int ret = 0; struct drm_fb *fb = NULL; struct sigaction sa = {{0}}; sa.sa_handler = sighandler; sa.sa_flags = SA_RESTART; sigemptyset(&sa.sa_mask); sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); #define EGL_ATTRIBS_BASE \ EGL_SURFACE_TYPE, EGL_WINDOW_BIT, \ EGL_RED_SIZE, 0, \ EGL_GREEN_SIZE, 0, \ EGL_BLUE_SIZE, 0, \ EGL_DEPTH_SIZE, 0, \ EGL_STENCIL_SIZE, 0 static const EGLint egl_attribs_gl[] = { EGL_ATTRIBS_BASE, EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, EGL_NONE, }; static const EGLint egl_attribs_gles[] = { EGL_ATTRIBS_BASE, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE, }; static const EGLint egl_attribs_vg[] = { EGL_ATTRIBS_BASE, EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT, EGL_NONE, }; // GLES 2.0. Don't use for any other API. static const EGLint gles_context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; const EGLint *attrib_ptr; switch (g_api) { case GFX_CTX_OPENGL_API: attrib_ptr = egl_attribs_gl; break; case GFX_CTX_OPENGL_ES_API: attrib_ptr = egl_attribs_gles; break; case GFX_CTX_OPENVG_API: attrib_ptr = egl_attribs_vg; break; default: attrib_ptr = NULL; } g_egl_dpy = eglGetDisplay((EGLNativeDisplayType)g_gbm_dev); if (!g_egl_dpy) { RARCH_ERR("[KMS/EGL]: Couldn't get EGL display.\n"); goto error; } EGLint major, minor; if (!eglInitialize(g_egl_dpy, &major, &minor)) goto error; EGLint n; if (!eglChooseConfig(g_egl_dpy, attrib_ptr, &g_config, 1, &n) || n != 1) goto error; g_egl_ctx = eglCreateContext(g_egl_dpy, g_config, EGL_NO_CONTEXT, (g_api == GFX_CTX_OPENGL_ES_API) ? gles_context_attribs : NULL); if (!g_egl_ctx) goto error; g_egl_surf = eglCreateWindowSurface(g_egl_dpy, g_config, (EGLNativeWindowType)g_gbm_surface, NULL); if (!g_egl_surf) goto error; if (!eglMakeCurrent(g_egl_dpy, g_egl_surf, g_egl_surf, g_egl_ctx)) goto error; glClear(GL_COLOR_BUFFER_BIT); eglSwapBuffers(g_egl_dpy, g_egl_surf); g_bo = gbm_surface_lock_front_buffer(g_gbm_surface); fb = drm_fb_get_from_bo(g_bo); ret = drmModeSetCrtc(g_drm_fd, g_crtc_id, fb->fb_id, 0, 0, &g_connector_id, 1, g_drm_mode); if (ret < 0) goto error; g_inited = true; return true; error: gfx_ctx_destroy(); return false; }
// Init the device void Device::InitWindow(int width, int height) { this->width = width; this->height = height; Logger::Info("Device", "Init Windows (%d - %d)", width, height); #ifdef WIN32 windowHandler = CreateWin("OpenGLES Window", (int) (width * WINDOW_SCALE), (int) (height * WINDOW_SCALE)); EGLint attribList[] = { EGL_RED_SIZE, 5, EGL_GREEN_SIZE, 6, EGL_BLUE_SIZE, 5, EGL_ALPHA_SIZE, EGL_DONT_CARE, EGL_DEPTH_SIZE, 8, EGL_STENCIL_SIZE, EGL_DONT_CARE, EGL_SAMPLE_BUFFERS, 0, EGL_NONE }; EGLint numConfigs; EGLint majorVersion; EGLint minorVersion; EGLConfig config; EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE }; // Get Display display = eglGetDisplay(GetDC(windowHandler)); if ( display == EGL_NO_DISPLAY ) { Logger::Error("OpenGLESDevice", "Couldn't Get Display"); return; } // Initialize EGL if ( !eglInitialize(display, &majorVersion, &minorVersion) ) { Logger::Error("OpenGLESDevice", "Couldn't Initialize Display"); return; } // Get configs if ( !eglGetConfigs(display, NULL, 0, &numConfigs) ) { Logger::Error("OpenGLESDevice", "Couldn't Get Config"); return; } // Choose config if ( !eglChooseConfig(display, attribList, &config, 1, &numConfigs) ) { Logger::Error("OpenGLESDevice", "Couldn't Choose Config"); return; } // Create a surface surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType) windowHandler, NULL); if ( surface == EGL_NO_SURFACE ) { Logger::Error("OpenGLESDevice", "Couldn't Create Window Surface"); return; } // Create a GL context context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs ); if ( context == EGL_NO_CONTEXT ) { Logger::Error("OpenGLESDevice", "Couldn't Get Context"); return; } // Make the context current if ( !eglMakeCurrent(display, surface, surface, context) ) { Logger::Error("OpenGLESDevice", "Couldn't Make Current Display"); return; } #endif // if WIN32 graphics = new Graphics(width, height); }
bool AndroidWindow::CreateGLContext(unsigned int major, unsigned int minor) { EGLConfig config; EGLint eglMajor; EGLint eglMinor; EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; if (!eglInitialize(mDisplay, &eglMajor, &eglMinor)) { LogError("Unable to initialize EGL", 0); return false; } EGLint numConfigs = 0; EGLint attribList[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, (mParameters.ColorBits == 32) ? 8 : EGL_DONT_CARE, EGL_DEPTH_SIZE, (mParameters.DepthBits > 0) ? mParameters.DepthBits : EGL_DONT_CARE, EGL_STENCIL_SIZE, (mParameters.StencilBits > 0) ? mParameters.StencilBits : EGL_DONT_CARE, EGL_SAMPLE_BUFFERS, (mParameters.MSAA > 0) ? mParameters.MSAA : 0, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE }; if (!eglChooseConfig(mDisplay, attribList, &config, 1, &numConfigs)) { LogError("Unable to choose EGL Config", 0); return false; } if (numConfigs < 1) { LogError("No valid EGL config found", 0); return false; } EGLint format = 0; eglGetConfigAttrib(mDisplay, config, EGL_NATIVE_VISUAL_ID, &format); ANativeWindow_setBuffersGeometry(mNativeWindow, 0, 0, format); mSurface = eglCreateWindowSurface(mDisplay, config, mNativeWindow, NULL); if (mSurface == EGL_NO_SURFACE) { LogError("Unable to create EGL window surface", 0); return false; } mContext = eglCreateContext(mDisplay, config, EGL_NO_CONTEXT, contextAttribs); if (mContext == EGL_NO_CONTEXT) { LogError("Unable to create EGL context", 0); return false; } if (!eglMakeCurrent(mDisplay, mSurface, mSurface, mContext)) { LogError("Unable to make EGL context current", 0); return false; } return true; }
static bool gfx_ctx_emscripten_init(void *data) { EGLint width, height, num_config; static const EGLint attribute_list[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE }; static const EGLint context_attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; (void)data; RARCH_LOG("[EMSCRIPTEN/EGL]: Initializing...\n"); if (g_inited) { RARCH_LOG("[EMSCRIPTEN/EGL]: Attempted to re-initialize driver.\n"); return true; } /* Get an EGL display connection. */ g_egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (!g_egl_dpy) goto error; /* Initialize the EGL display connection. */ if (!eglInitialize(g_egl_dpy, NULL, NULL)) goto error; /* Get an appropriate EGL frame buffer configuration. */ if (!eglChooseConfig(g_egl_dpy, attribute_list, &g_egl_config, 1, &num_config)) goto error; /* Create an EGL rendering context. */ g_egl_ctx = eglCreateContext(g_egl_dpy, g_egl_config, EGL_NO_CONTEXT, context_attributes); if (!g_egl_ctx) goto error; /* create an EGL window surface. */ g_egl_surf = eglCreateWindowSurface(g_egl_dpy, g_egl_config, 0, NULL); if (!g_egl_surf) goto error; /* Connect the context to the surface. */ if (!eglMakeCurrent(g_egl_dpy, g_egl_surf, g_egl_surf, g_egl_ctx)) goto error; eglQuerySurface(g_egl_dpy, g_egl_surf, EGL_WIDTH, &width); eglQuerySurface(g_egl_dpy, g_egl_surf, EGL_HEIGHT, &height); g_fb_width = width; g_fb_height = height; RARCH_LOG("[EMSCRIPTEN/EGL]: Dimensions: %ux%u\n", width, height); return true; error: gfx_ctx_emscripten_destroy(data); return false; }
bool CompoGraphicsContext::init( void *surfacePtr ) { JNIEnv *env; JavaVM *vm = CompoBridge->getVM(); CompoScopedJNI(vm, &env); ANativeWindow *window = ANativeWindow_fromSurface(env, (jobject) surfacePtr); LOGI("-- Initializing OpenGL Context --"); if ((mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY) { LOGE("eglGetDisplay returned error %d", eglGetError()); return false; } else { LOGI("eglGetDisplay SUCCEDED [0x%X]", (unsigned) mDisplay); } const EGLint attributes [] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_DEPTH_SIZE, 16, EGL_NONE }; if (!eglInitialize(mDisplay, 0, 0)) { LOGE("eglInitialze returned error %d", eglGetError()); return false; } EGLint numConfigs; EGLint format; if (!eglChooseConfig(mDisplay, attributes, &mConfig, 1, &numConfigs)) { LOGE("eglChooseConfig() returned error %d", eglGetError()); this->destroy(); return false; } if (!eglGetConfigAttrib(mDisplay, mConfig, EGL_NATIVE_VISUAL_ID, &format)) { LOGE("eglGetConfigAttrib returned error %d", eglGetError()); this->destroy(); return false; } ANativeWindow_setBuffersGeometry(window, 0, 0, format); if ((mSurface = eglCreateWindowSurface(mDisplay, mConfig, window, 0)) == EGL_NO_SURFACE) { LOGE("eglCreateWindowSurface returned error %d", eglGetError()); this->destroy(); return false; } EGLint contextAttributes [] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; if ((mContext = eglCreateContext(mDisplay, mConfig, 0, contextAttributes)) == EGL_NO_CONTEXT) { LOGE("eglCreateContext returned error %d", eglGetError()); this->destroy(); return false; } else { LOGI("eglCreateContext create [0x%X]", (unsigned) mContext); } if (!eglMakeCurrent(mDisplay, mSurface, mSurface, mContext)) { LOGE("eglMakeCurrent() returned error %d", eglGetError()); this->destroy(); return false; } EGLint width, height; if (!eglQuerySurface(mDisplay, mSurface, EGL_WIDTH, &width) || !eglQuerySurface(mDisplay, mSurface, EGL_HEIGHT, &height)) { LOGE("eglQuerySurface() returned error %d", eglGetError()); this->destroy(); return false; } else { mWidth = width; mHeight = height; LOGI("Surface Initialized %dx%d", width, height); } glDisable(GL_DITHER); glClearColor(1.0f, 0.0f, 0.0f, 1.0f); glClearDepthf(1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); return false; }
void AndroidEGL::CreateEGLSurface(ANativeWindow* InWindow) { // due to possible early initialization, don't redo this if (PImplData->eglSurface != EGL_NO_SURFACE) { return; } //need ANativeWindow PImplData->eglSurface = eglCreateWindowSurface(PImplData->eglDisplay, PImplData->eglConfigParam,InWindow, NULL); if(PImplData->eglSurface == EGL_NO_SURFACE ) { checkf(PImplData->eglSurface != EGL_NO_SURFACE, TEXT("eglCreateWindowSurface error : 0x%x"), eglGetError()); ResetInternal(); } // On some Android devices, eglChooseConfigs will lie about valid configurations (specifically 32-bit color) /* if (eglGetError() == EGL10.EGL_BAD_MATCH) { Logger.LogOut("eglCreateWindowSurface FAILED, retrying with more restricted context"); // Dump what's already been initialized cleanupEGL(); // Reduce target color down to 565 eglAttemptedParams.redSize = 5; eglAttemptedParams.greenSize = 6; eglAttemptedParams.blueSize = 5; eglAttemptedParams.alphaSize = 0; initEGL(eglAttemptedParams); // try again eglSurface = eglCreateWindowSurface(PImplData->eglDisplay, eglConfig, surface, null); } */ EGLBoolean result = EGL_FALSE; if (!( result = ( eglQuerySurface(PImplData->eglDisplay, PImplData->eglSurface, EGL_WIDTH, &PImplData->eglWidth) && eglQuerySurface(PImplData->eglDisplay, PImplData->eglSurface, EGL_HEIGHT, &PImplData->eglHeight) ) ) ) { ResetInternal(); } checkf(result == EGL_TRUE, TEXT("eglQuerySurface error : 0x%x"), eglGetError()); EGLint pbufferAttribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_TEXTURE_TARGET, EGL_NO_TEXTURE, EGL_TEXTURE_FORMAT, EGL_NO_TEXTURE, EGL_NONE }; pbufferAttribs[1] = PImplData->eglWidth; pbufferAttribs[3] = PImplData->eglHeight; PImplData->auxSurface = eglCreatePbufferSurface(PImplData->eglDisplay, PImplData->eglConfigParam, pbufferAttribs); if(PImplData->auxSurface== EGL_NO_SURFACE ) { checkf(PImplData->auxSurface != EGL_NO_SURFACE, TEXT("eglCreatePbufferSurface error : 0x%x"), eglGetError()); ResetInternal(); } }
bool SkOSWindow::attach(SkBackEndTypes attachType, int /*msaaSampleCount*/, AttachmentInfo* info) { static const EGLint kEGLContextAttribsForOpenGL[] = { EGL_NONE }; static const EGLint kEGLContextAttribsForOpenGLES[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; static const struct { const EGLint* fContextAttribs; EGLenum fAPI; EGLint fRenderableTypeBit; } kAPIs[] = { { // OpenGL kEGLContextAttribsForOpenGL, EGL_OPENGL_API, EGL_OPENGL_BIT, }, { // OpenGL ES. This seems to work for both ES2 and 3 (when available). kEGLContextAttribsForOpenGLES, EGL_OPENGL_ES_API, EGL_OPENGL_ES2_BIT, }, }; EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (EGL_NO_DISPLAY == display) { return false; } EGLint majorVersion; EGLint minorVersion; if (!eglInitialize(display, &majorVersion, &minorVersion)) { return false; } for (size_t api = 0; api < SK_ARRAY_COUNT(kAPIs); ++api) { if (!eglBindAPI(kAPIs[api].fAPI)) { continue; } #if 0 SkDebugf("VENDOR: %s\n", eglQueryString(fDisplay, EGL_VENDOR)); SkDebugf("APIS: %s\n", eglQueryString(fDisplay, EGL_CLIENT_APIS)); SkDebugf("VERSION: %s\n", eglQueryString(fDisplay, EGL_VERSION)); SkDebugf("EXTENSIONS %s\n", eglQueryString(fDisplay, EGL_EXTENSIONS)); #endif const EGLint configAttribs[] = { EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, EGL_RENDERABLE_TYPE, kAPIs[api].fRenderableTypeBit, EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_NONE }; EGLint format; EGLint numConfigs; EGLConfig config; EGLSurface surface; EGLContext context; /* Here, the application chooses the configuration it desires. In this * sample, we have a very simplified selection process, where we pick * the first EGLConfig that matches our criteria */ if (!eglChooseConfig(display, configAttribs, &config, 1, &numConfigs) || numConfigs != 1) { continue; } /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is * guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). * As soon as we picked a EGLConfig, we can safely reconfigure the * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ if (!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format)) { continue; } ANativeWindow_setBuffersGeometry(fNativeWindow, 0, 0, format); surface = eglCreateWindowSurface(display, config, fNativeWindow, nullptr); if (EGL_NO_SURFACE == surface) { SkDebugf("eglCreateWindowSurface failed. EGL Error: 0x%08x\n", eglGetError()); continue; } context = eglCreateContext(display, config, nullptr, kAPIs[api].fContextAttribs); if (EGL_NO_CONTEXT == context) { SkDebugf("eglCreateContext failed. EGL Error: 0x%08x\n", eglGetError()); eglDestroySurface(display, surface); continue; } if (!eglMakeCurrent(display, surface, surface, context)) { SkDebugf("eglMakeCurrent failed. EGL Error: 0x%08x\n", eglGetError()); eglDestroyContext(display, context); eglDestroySurface(display, surface); continue; } fWindow.fDisplay = display; fWindow.fContext = context; fWindow.fSurface = surface; break; } if (fWindow.fDisplay && fWindow.fContext && fWindow.fSurface) { EGLint w, h; eglQuerySurface(fWindow.fDisplay, fWindow.fSurface, EGL_WIDTH, &w); eglQuerySurface(fWindow.fDisplay, fWindow.fSurface, EGL_HEIGHT, &h); glViewport(0, 0, w, h); glClearColor(0.0, 0, 0, 0.0); glClearStencil(0); glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // We retrieve the fullscreen width and height this->setSize((SkScalar)w, (SkScalar)h); return true; } else { return false; } }
/** * Initialize an EGL context for the current display. */ static int engine_init_display(struct engine* engine) { LOGI("from engine_init_display \n"); // initialize OpenGL ES and EGL /* * Here specify the attributes of the desired configuration. * Below, we select an EGLConfig with at least 8 bits per color * component compatible with on-screen windows */ const EGLint attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; EGLint w, h, dummy, format; EGLint numConfigs; EGLConfig config; EGLSurface surface; EGLContext context; EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglInitialize(display, 0, 0); /* Here, the application chooses the configuration it desires. In this * sample, we have a very simplified selection process, where we pick * the first EGLConfig that matches our criteria */ eglChooseConfig(display, attribs, &config, 1, &numConfigs); LOGI("number of configurations returned %d \n", numConfigs); /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is * guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). * As soon as we picked a EGLConfig, we can safely reconfigure the * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format); ANativeWindow_setBuffersGeometry(engine->app->window, 0, 0, format); surface = eglCreateWindowSurface(display, config, engine->app->window, NULL); context = eglCreateContext(display, config, EGL_NO_CONTEXT, attribs); if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) { LOGW("Unable to eglMakeCurrent"); return -1; } eglQuerySurface(display, surface, EGL_WIDTH, &w); eglQuerySurface(display, surface, EGL_HEIGHT, &h); engine->display = display; engine->context = context; engine->surface = surface; engine->width = w; engine->height = h; engine->state.angle = 0; // Initialize GL state. glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); glEnable(GL_CULL_FACE); glShadeModel(GL_SMOOTH); glDisable(GL_DEPTH_TEST); return 0; }
int main(int argc, char **argv) { EGLDisplay display; EGLConfig ecfg; EGLint num_config; EGLint attr[] = { // some attributes to set up our egl-interface EGL_BUFFER_SIZE, 32, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE }; EGLSurface surface; EGLint ctxattr[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; EGLContext context; EGLBoolean rv; int err; hw_module_t *hwcModule = 0; hwc_composer_device_1_t *hwcDevicePtr = 0; err = hw_get_module(HWC_HARDWARE_MODULE_ID, (const hw_module_t **) &hwcModule); assert(err == 0); err = hwc_open_1(hwcModule, &hwcDevicePtr); assert(err == 0); hwcDevicePtr->blank(hwcDevicePtr, 0, 0); uint32_t configs[5]; size_t numConfigs = 5; err = hwcDevicePtr->getDisplayConfigs(hwcDevicePtr, 0, configs, &numConfigs); assert (err == 0); int32_t attr_values[2]; uint32_t attributes[] = { HWC_DISPLAY_WIDTH, HWC_DISPLAY_HEIGHT, HWC_DISPLAY_NO_ATTRIBUTE }; hwcDevicePtr->getDisplayAttributes(hwcDevicePtr, 0, configs[0], attributes, attr_values); printf("width: %i height: %i\n", attr_values[0], attr_values[1]); HWComposerNativeWindow *win = new HWComposerNativeWindow(attr_values[0], attr_values[1], HAL_PIXEL_FORMAT_RGBA_8888); display = eglGetDisplay(NULL); assert(eglGetError() == EGL_SUCCESS); assert(display != EGL_NO_DISPLAY); rv = eglInitialize(display, 0, 0); assert(eglGetError() == EGL_SUCCESS); assert(rv == EGL_TRUE); eglChooseConfig((EGLDisplay) display, attr, &ecfg, 1, &num_config); assert(eglGetError() == EGL_SUCCESS); assert(rv == EGL_TRUE); surface = eglCreateWindowSurface((EGLDisplay) display, ecfg, (EGLNativeWindowType) static_cast<ANativeWindow *> (win), NULL); assert(eglGetError() == EGL_SUCCESS); assert(surface != EGL_NO_SURFACE); context = eglCreateContext((EGLDisplay) display, ecfg, EGL_NO_CONTEXT, ctxattr); assert(eglGetError() == EGL_SUCCESS); assert(context != EGL_NO_CONTEXT); assert(eglMakeCurrent((EGLDisplay) display, surface, surface, context) == EGL_TRUE); const char *version = (const char *)glGetString(GL_VERSION); assert(version); printf("%s\n",version); size_t size = sizeof(hwc_display_contents_1_t) + 2 * sizeof(hwc_layer_1_t); hwc_display_contents_1_t *list = (hwc_display_contents_1_t *) malloc(size); hwc_display_contents_1_t **mList = (hwc_display_contents_1_t **) malloc(HWC_NUM_DISPLAY_TYPES * sizeof(hwc_display_contents_1_t *)); const hwc_rect_t r = { 0, 0, attr_values[0], attr_values[1] }; int counter = 0; for (; counter < HWC_NUM_DISPLAY_TYPES; counter++) mList[counter] = list; hwc_layer_1_t *layer = &list->hwLayers[0]; memset(layer, 0, sizeof(hwc_layer_1_t)); layer->compositionType = HWC_FRAMEBUFFER; layer->hints = 0; layer->flags = 0; layer->handle = 0; layer->transform = 0; layer->blending = HWC_BLENDING_NONE; layer->sourceCrop = r; layer->displayFrame = r; layer->visibleRegionScreen.numRects = 1; layer->visibleRegionScreen.rects = &layer->displayFrame; layer->acquireFenceFd = -1; layer->releaseFenceFd = -1; layer = &list->hwLayers[1]; memset(layer, 0, sizeof(hwc_layer_1_t)); layer->compositionType = HWC_FRAMEBUFFER_TARGET; layer->hints = 0; layer->flags = 0; layer->handle = 0; layer->transform = 0; layer->blending = HWC_BLENDING_NONE; layer->sourceCrop = r; layer->displayFrame = r; layer->visibleRegionScreen.numRects = 1; layer->visibleRegionScreen.rects = &layer->displayFrame; layer->acquireFenceFd = -1; layer->releaseFenceFd = -1; list->retireFenceFd = -1; list->flags = HWC_GEOMETRY_CHANGED; list->numHwLayers = 2; GLuint vertexShader = load_shader ( vertex_src , GL_VERTEX_SHADER ); // load vertex shader GLuint fragmentShader = load_shader ( fragment_src , GL_FRAGMENT_SHADER ); // load fragment shader GLuint shaderProgram = glCreateProgram (); // create program object glAttachShader ( shaderProgram, vertexShader ); // and attach both... glAttachShader ( shaderProgram, fragmentShader ); // ... shaders to it glLinkProgram ( shaderProgram ); // link the program glUseProgram ( shaderProgram ); // and select it for usage //// now get the locations (kind of handle) of the shaders variables position_loc = glGetAttribLocation ( shaderProgram , "position" ); phase_loc = glGetUniformLocation ( shaderProgram , "phase" ); offset_loc = glGetUniformLocation ( shaderProgram , "offset" ); if ( position_loc < 0 || phase_loc < 0 || offset_loc < 0 ) { return 1; } //glViewport ( 0 , 0 , 800, 600); // commented out so it uses the initial window dimensions glClearColor ( 1. , 1. , 1. , 1.); // background color float phase = 0; int i, oldretire = -1, oldrelease = -1, oldrelease2 = -1; for (i=0; i<1020*60; ++i) { glClear(GL_COLOR_BUFFER_BIT); glUniform1f ( phase_loc , phase ); // write the value of phase to the shaders phase phase = fmodf ( phase + 0.5f , 2.f * 3.141f ); // and update the local variable glUniform4f ( offset_loc , offset_x , offset_y , 0.0 , 0.0 ); glVertexAttribPointer ( position_loc, 3, GL_FLOAT, GL_FALSE, 0, vertexArray ); glEnableVertexAttribArray ( position_loc ); glDrawArrays ( GL_TRIANGLE_STRIP, 0, 5 ); eglSwapBuffers ( (EGLDisplay) display, surface ); // get the rendered buffer to the screen HWComposerNativeWindowBuffer *front; win->lockFrontBuffer(&front); mList[0]->hwLayers[1].handle = front->handle; mList[0]->hwLayers[0].handle = NULL; mList[0]->hwLayers[0].flags = HWC_SKIP_LAYER; oldretire = mList[0]->retireFenceFd; oldrelease = mList[0]->hwLayers[1].releaseFenceFd; oldrelease2 = mList[0]->hwLayers[0].releaseFenceFd; int err = hwcDevicePtr->prepare(hwcDevicePtr, HWC_NUM_DISPLAY_TYPES, mList); assert(err == 0); err = hwcDevicePtr->set(hwcDevicePtr, HWC_NUM_DISPLAY_TYPES, mList); assert(err == 0); assert(mList[0]->hwLayers[0].releaseFenceFd == -1); win->unlockFrontBuffer(front); if (oldrelease != -1) { sync_wait(oldrelease, -1); close(oldrelease); } if (oldrelease2 != -1) { sync_wait(oldrelease2, -1); close(oldrelease2); } if (oldretire != -1) { sync_wait(oldretire, -1); close(oldretire); } } printf("stop\n"); #if 0 (*egldestroycontext)((EGLDisplay) display, context); printf("destroyed context\n"); (*egldestroysurface)((EGLDisplay) display, surface); printf("destroyed surface\n"); (*eglterminate)((EGLDisplay) display); printf("terminated\n"); android_dlclose(baz); #endif }
bool create_ANGLE(EGLNativeWindowType hWnd, int msaaSampleCount, EGLDisplay* eglDisplay, EGLContext* eglContext, EGLSurface* eglSurface, EGLConfig* eglConfig) { static const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE }; static const EGLint configAttribList[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_DEPTH_SIZE, 8, EGL_STENCIL_SIZE, 8, EGL_NONE }; static const EGLint surfaceAttribList[] = { EGL_NONE, EGL_NONE }; EGLDisplay display = SkANGLEGLContext::GetD3DEGLDisplay(GetDC(hWnd)); if (EGL_NO_DISPLAY == display) { SkDebugf("Could not create ANGLE egl display!\n"); return false; } // Initialize EGL EGLint majorVersion, minorVersion; if (!eglInitialize(display, &majorVersion, &minorVersion)) { return false; } EGLint numConfigs; if (!eglGetConfigs(display, NULL, 0, &numConfigs)) { return false; } // Choose config bool foundConfig = false; if (msaaSampleCount) { static const int kConfigAttribListCnt = SK_ARRAY_COUNT(configAttribList); EGLint msaaConfigAttribList[kConfigAttribListCnt + 4]; memcpy(msaaConfigAttribList, configAttribList, sizeof(configAttribList)); SkASSERT(EGL_NONE == msaaConfigAttribList[kConfigAttribListCnt - 1]); msaaConfigAttribList[kConfigAttribListCnt - 1] = EGL_SAMPLE_BUFFERS; msaaConfigAttribList[kConfigAttribListCnt + 0] = 1; msaaConfigAttribList[kConfigAttribListCnt + 1] = EGL_SAMPLES; msaaConfigAttribList[kConfigAttribListCnt + 2] = msaaSampleCount; msaaConfigAttribList[kConfigAttribListCnt + 3] = EGL_NONE; if (eglChooseConfig(display, configAttribList, eglConfig, 1, &numConfigs)) { SkASSERT(numConfigs > 0); foundConfig = true; } } if (!foundConfig) { if (!eglChooseConfig(display, configAttribList, eglConfig, 1, &numConfigs)) { return false; } } // Create a surface EGLSurface surface = eglCreateWindowSurface(display, *eglConfig, (EGLNativeWindowType)hWnd, surfaceAttribList); if (surface == EGL_NO_SURFACE) { return false; } // Create a GL context EGLContext context = eglCreateContext(display, *eglConfig, EGL_NO_CONTEXT, contextAttribs ); if (context == EGL_NO_CONTEXT ) { return false; } // Make the context current if (!eglMakeCurrent(display, surface, surface, context)) { return false; } *eglDisplay = display; *eglContext = context; *eglSurface = surface; return true; }
static bool android_init(struct ra_ctx *ctx) { struct priv *p = ctx->priv = talloc_zero(ctx, struct priv); jobject surface = (jobject)(intptr_t)ctx->vo->opts->WinID; JavaVM *vm = (JavaVM *)av_jni_get_java_vm(NULL); JNIEnv *env; int ret = (*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6); if (ret == JNI_EDETACHED) { if ((*vm)->AttachCurrentThread(vm, &env, NULL) != 0) { MP_FATAL(ctx, "Could not attach java VM.\n"); goto fail; } } p->native_window = ANativeWindow_fromSurface(env, surface); (*vm)->DetachCurrentThread(vm); p->egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (!eglInitialize(p->egl_display, NULL, NULL)) { MP_FATAL(ctx, "EGL failed to initialize.\n"); goto fail; } EGLConfig config; if (!mpegl_create_context(ctx, p->egl_display, &p->egl_context, &config)) goto fail; EGLint format; eglGetConfigAttrib(p->egl_display, config, EGL_NATIVE_VISUAL_ID, &format); ANativeWindow_setBuffersGeometry(p->native_window, 0, 0, format); p->egl_surface = eglCreateWindowSurface(p->egl_display, config, (EGLNativeWindowType)p->native_window, NULL); if (p->egl_surface == EGL_NO_SURFACE) { MP_FATAL(ctx, "Could not create EGL surface!\n"); goto fail; } if (!eglMakeCurrent(p->egl_display, p->egl_surface, p->egl_surface, p->egl_context)) { MP_FATAL(ctx, "Failed to set context!\n"); goto fail; } if (!eglQuerySurface(p->egl_display, p->egl_surface, EGL_WIDTH, &p->w) || !eglQuerySurface(p->egl_display, p->egl_surface, EGL_HEIGHT, &p->h)) { MP_FATAL(ctx, "Failed to get height and width!\n"); goto fail; } mpegl_load_functions(&p->gl, ctx->log); struct ra_gl_ctx_params params = { .swap_buffers = android_swap_buffers, }; if (!ra_gl_ctx_init(ctx, &p->gl, params)) goto fail; return true; fail: android_uninit(ctx); return false; }
EGLContextType *eglInit(Display *x11Display, XID x11Window, uint32_t fourcc) { EGLContextType *context = NULL; GLProgram *glProgram = NULL; context = calloc(1, sizeof(EGLContextType)); EGLDisplay eglDisplay = eglGetDisplay(x11Display); if (eglDisplay == EGL_NO_DISPLAY) { ERROR("eglGetDisplay fail"); } CHECK_HANDLE_RET(eglDisplay, EGL_NO_DISPLAY, "eglGetDisplay", NULL); context->eglContext.display = eglDisplay; EGLint major, minor; EGLBoolean result = eglInitialize(eglDisplay, &major, &minor); if (result != EGL_TRUE) { ERROR("eglInitialize fail"); } EGL_CHECK_RESULT_RET(result, "eglInitialize", NULL); // eglBindAPI(EGL_OPENGL_ES_API); // gles is the default one EGLint const eglConfigAttribs[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_DEPTH_SIZE, 8, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE }; EGLConfig eglConfig; EGLint eglConfigCount; result = eglChooseConfig(eglDisplay, eglConfigAttribs, &eglConfig, 1, &eglConfigCount); EGL_CHECK_RESULT_RET(result, "eglChooseConfig", NULL); context->eglContext.config = eglConfig; EGLSurface eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, x11Window, NULL); CHECK_HANDLE_RET(eglSurface, EGL_NO_SURFACE, "eglCreateWindowSurface", NULL); context->eglContext.surface = eglSurface; EGLint const eglContextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; EGLContext eglContext = eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, eglContextAttribs); CHECK_HANDLE_RET(eglContext, EGL_NO_CONTEXT, "eglCreateContext", NULL); context->eglContext.context = eglContext; result = eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext); EGL_CHECK_RESULT_RET(result, "eglMakeCurrent", NULL); const unsigned char* glVersion = glGetString(GL_VERSION); INFO("Runing GL version: %s, please make sure it support GL 2.0 API", glVersion); // clear to middle blue glClearColor(0.0, 0.0, 0.5, 0.0); glEnable(GL_DEPTH_TEST); glClearDepthf(1.0f); { int width, height; Window root; int x, y, borderWidth, depth; XGetGeometry(x11Display, x11Window, &root, &x, &y, &width, &height, &borderWidth, &depth); glViewport(0, 0, width, height); } glProgram = createShaders(vertexShaderText_rgba, fragShaderText_rgba, 1); CHECK_HANDLE_RET(glProgram, NULL, "createShaders", NULL); context->glProgram = glProgram; return context; }
int main(int argc, char** argv) { setenv("EGL_DRIVER", "egl_glx", 0); EGLNativeDisplayType native_display = XOpenDisplay(NULL); EGLDisplay display = eglGetDisplay(native_display); EGLint major; EGLint minor; eglInitialize(display, &major, &minor); std::cout << "EGL_CLIENT_APIS: " << eglQueryString(display, EGL_CLIENT_APIS) << std::endl; std::cout << "EGL_EXTENSIONS: " << eglQueryString(display, EGL_EXTENSIONS) << std::endl; std::cout << "EGL_VENDOR: " << eglQueryString(display, EGL_VENDOR) << std::endl; std::cout << "EGL_VERSION: " << eglQueryString(display, EGL_VERSION) << std::endl; EGLint config_count; eglGetConfigs(display, NULL, 0, &config_count); EGLConfig* configs = new EGLConfig[config_count]; eglGetConfigs(display, configs, config_count, &config_count); EGLint attributes[] = { EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE }; eglChooseConfig(display, attributes, configs, config_count, &config_count); std::cout << "BUF_SZ RED_SZ GRE_SZ BLU_SZ LUM_SZ ALP_SZ AMS_SZ T_RGB T_RGBA COL_BF CAVEAT ID CONFMT DEP_SZ LEVEL M_PB_W M_PB_H M_PB_P MX_SWP MN_SWP NTV_RD NTV_VI NTV_VT RDR_T SM_BUF SM_NUM STC_SZ SURF_T TS_TYP TS_RED TS_GRE TS_BLU\n"; for (size_t i = 0; i < config_count; ++i) { EGLConfig& config = configs[i]; EGLint value; print_config_attrib< EGL_BUFFER_SIZE >(display, config); print_config_attrib< EGL_RED_SIZE >(display, config); print_config_attrib< EGL_GREEN_SIZE >(display, config); print_config_attrib< EGL_BLUE_SIZE >(display, config); print_config_attrib< EGL_LUMINANCE_SIZE >(display, config); print_config_attrib< EGL_ALPHA_SIZE >(display, config); print_config_attrib< EGL_ALPHA_MASK_SIZE >(display, config); print_config_attrib< EGL_BIND_TO_TEXTURE_RGB >(display, config); print_config_attrib< EGL_BIND_TO_TEXTURE_RGBA >(display, config); print_config_attrib< EGL_COLOR_BUFFER_TYPE >(display, config); print_config_attrib< EGL_CONFIG_CAVEAT >(display, config); print_config_attrib< EGL_CONFIG_ID >(display, config); print_config_attrib< EGL_CONFORMANT >(display, config); print_config_attrib< EGL_DEPTH_SIZE >(display, config); print_config_attrib< EGL_LEVEL >(display, config); print_config_attrib< EGL_MAX_PBUFFER_WIDTH >(display, config); print_config_attrib< EGL_MAX_PBUFFER_HEIGHT >(display, config); print_config_attrib< EGL_MAX_PBUFFER_PIXELS >(display, config); print_config_attrib< EGL_MAX_SWAP_INTERVAL >(display, config); print_config_attrib< EGL_MIN_SWAP_INTERVAL >(display, config); print_config_attrib< EGL_NATIVE_RENDERABLE >(display, config); print_config_attrib< EGL_NATIVE_VISUAL_ID >(display, config); print_config_attrib< EGL_NATIVE_VISUAL_TYPE >(display, config); print_config_attrib< EGL_RENDERABLE_TYPE >(display, config); print_config_attrib< EGL_SAMPLE_BUFFERS >(display, config); print_config_attrib< EGL_SAMPLES >(display, config); print_config_attrib< EGL_STENCIL_SIZE >(display, config); print_config_attrib< EGL_SURFACE_TYPE >(display, config); print_config_attrib< EGL_TRANSPARENT_TYPE >(display, config); print_config_attrib< EGL_TRANSPARENT_RED_VALUE >(display, config); print_config_attrib< EGL_TRANSPARENT_GREEN_VALUE >(display, config); print_config_attrib< EGL_TRANSPARENT_BLUE_VALUE >(display, config); std::cout << "\n"; } XSync(native_display, false); eglCreateWindowSurface(display, configs[0], DefaultRootWindow(native_display), NULL); delete[] configs; eglTerminate(display); } // main
static bool pi_create_display(ALLEGRO_DISPLAY *display) { ALLEGRO_DISPLAY_RASPBERRYPI *d = (void *)display; ALLEGRO_EXTRA_DISPLAY_SETTINGS *eds = _al_get_new_display_settings(); egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (egl_display == EGL_NO_DISPLAY) { return false; } int major, minor; if (!eglInitialize(egl_display, &major, &minor)) { return false; } static EGLint attrib_list[] = { EGL_DEPTH_SIZE, 0, EGL_STENCIL_SIZE, 0, EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE }; attrib_list[1] = eds->settings[ALLEGRO_DEPTH_SIZE]; attrib_list[3] = eds->settings[ALLEGRO_STENCIL_SIZE]; if (eds->settings[ALLEGRO_RED_SIZE] || eds->settings[ALLEGRO_GREEN_SIZE] || eds->settings[ALLEGRO_BLUE_SIZE] || eds->settings[ALLEGRO_ALPHA_SIZE]) { attrib_list[5] = eds->settings[ALLEGRO_RED_SIZE]; attrib_list[7] = eds->settings[ALLEGRO_GREEN_SIZE]; attrib_list[9] = eds->settings[ALLEGRO_BLUE_SIZE]; attrib_list[11] = eds->settings[ALLEGRO_ALPHA_SIZE]; } else if (eds->settings[ALLEGRO_COLOR_SIZE] == 16) { attrib_list[5] = 5; attrib_list[7] = 6; attrib_list[9] = 5; attrib_list[11] = 0; } EGLConfig config; int num_configs; if (!eglChooseConfig(egl_display, attrib_list, &config, 1, &num_configs)) { return false; } eglBindAPI(EGL_OPENGL_ES_API); int es_ver = (display->flags & ALLEGRO_PROGRAMMABLE_PIPELINE) ? 2 : 1; static EGLint ctxattr[3] = { EGL_CONTEXT_CLIENT_VERSION, 0xDEADBEEF, EGL_NONE }; ctxattr[1] = es_ver; egl_context = eglCreateContext(egl_display, config, EGL_NO_CONTEXT, ctxattr); if (egl_context == EGL_NO_CONTEXT) { return false; } static EGL_DISPMANX_WINDOW_T nativewindow; DISPMANX_ELEMENT_HANDLE_T dispman_element; int dx, dy, screen_width, screen_height; _al_raspberrypi_get_screen_info(&dx, &dy, &screen_width, &screen_height); d->cursor_offset_x = dx; d->cursor_offset_y = dy; dst_rect.x = dx; dst_rect.y = dy; dst_rect.width = screen_width; dst_rect.height = screen_height; d->screen_width = screen_width; d->screen_height = screen_height; src_rect.x = 0; src_rect.y = 0; src_rect.width = display->w << 16; src_rect.height = display->h << 16; dispman_display = vc_dispmanx_display_open(0 /* LCD */); dispman_update = vc_dispmanx_update_start(0); dispman_element = vc_dispmanx_element_add ( dispman_update, dispman_display, 0/*layer*/, &dst_rect, 0/*src*/, &src_rect, DISPMANX_PROTECTION_NONE, 0 /*alpha*/, 0/*clamp*/, DISPMANX_NO_ROTATE/*transform*/ ); nativewindow.element = dispman_element; nativewindow.width = display->w; nativewindow.height = display->h; vc_dispmanx_update_submit_sync(dispman_update); egl_window = eglCreateWindowSurface( egl_display, config, &nativewindow, NULL); if (egl_window == EGL_NO_SURFACE) { return false; } if (!eglMakeCurrent(egl_display, egl_window, egl_window, egl_context)) { return false; } return true; }
int bbutil_init_egl(screen_context_t ctx) { int usage; int format = SCREEN_FORMAT_RGBX8888; EGLint interval = 1; int rc, num_configs; EGLint attrib_list[]= { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_DEPTH_SIZE, 24, EGL_NONE}; #ifdef USING_GL11 usage = SCREEN_USAGE_OPENGL_ES1 | SCREEN_USAGE_ROTATION; attrib_list[9] = EGL_OPENGL_ES_BIT; #elif defined(USING_GL20) usage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION; //attrib_list[9] = EGL_OPENGL_ES2_BIT; EGLint attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; #else fprintf(stderr, "bbutil should be compiled with either USING_GL11 or USING_GL20 -D flags\n"); return EXIT_FAILURE; #endif //Simple egl initialization screen_cxt = ctx; egl_disp = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (egl_disp == EGL_NO_DISPLAY) { bbutil_egl_perror("eglGetDisplay"); bbutil_terminate(); return EXIT_FAILURE; } rc = eglInitialize(egl_disp, NULL, NULL); if (rc != EGL_TRUE) { bbutil_egl_perror("eglInitialize"); bbutil_terminate(); return EXIT_FAILURE; } rc = eglBindAPI(EGL_OPENGL_ES_API); if (rc != EGL_TRUE) { bbutil_egl_perror("eglBindApi"); bbutil_terminate(); return EXIT_FAILURE; } if(!eglChooseConfig(egl_disp, attrib_list, &egl_conf, 1, &num_configs)) { bbutil_terminate(); return EXIT_FAILURE; } #ifdef USING_GL20 egl_ctx = eglCreateContext(egl_disp, egl_conf, EGL_NO_CONTEXT, attributes); #elif defined(USING_GL11) egl_ctx = eglCreateContext(egl_disp, egl_conf, EGL_NO_CONTEXT, NULL); #endif if (egl_ctx == EGL_NO_CONTEXT) { bbutil_egl_perror("eglCreateContext"); bbutil_terminate(); return EXIT_FAILURE; } rc = screen_create_window(&screen_win, screen_cxt); if (rc) { perror("screen_create_window"); bbutil_terminate(); return EXIT_FAILURE; } rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_FORMAT, &format); if (rc) { perror("screen_set_window_property_iv(SCREEN_PROPERTY_FORMAT)"); bbutil_terminate(); return EXIT_FAILURE; } rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage); if (rc) { perror("screen_set_window_property_iv(SCREEN_PROPERTY_USAGE)"); bbutil_terminate(); return EXIT_FAILURE; } rc = screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&screen_disp); if (rc) { perror("screen_get_window_property_pv"); bbutil_terminate(); return EXIT_FAILURE; } int screen_resolution[2]; rc = screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution); if (rc) { perror("screen_get_display_property_iv"); bbutil_terminate(); return EXIT_FAILURE; } int angle = atoi(getenv("ORIENTATION")); screen_display_mode_t screen_mode; rc = screen_get_display_property_pv(screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode); if (rc) { perror("screen_get_display_property_pv"); bbutil_terminate(); return EXIT_FAILURE; } int size[2]; rc = screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size); if (rc) { perror("screen_get_window_property_iv"); bbutil_terminate(); return EXIT_FAILURE; } int buffer_size[2] = {size[0], size[1]}; if ((angle == 0) || (angle == 180)) { if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) || ((screen_mode.width < screen_mode.height) && (size[0] > size[1]))) { buffer_size[1] = size[0]; buffer_size[0] = size[1]; } } else if ((angle == 90) || (angle == 270)){ if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) || ((screen_mode.width < screen_mode.height && size[0] < size[1]))) { buffer_size[1] = size[0]; buffer_size[0] = size[1]; } } else { fprintf(stderr, "Navigator returned an unexpected orientation angle.\n"); bbutil_terminate(); return EXIT_FAILURE; } rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size); if (rc) { perror("screen_set_window_property_iv"); bbutil_terminate(); return EXIT_FAILURE; } rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &angle); if (rc) { perror("screen_set_window_property_iv"); bbutil_terminate(); return EXIT_FAILURE; } rc = screen_create_window_buffers(screen_win, nbuffers); if (rc) { perror("screen_create_window_buffers"); bbutil_terminate(); return EXIT_FAILURE; } egl_surf = eglCreateWindowSurface(egl_disp, egl_conf, screen_win, NULL); if (egl_surf == EGL_NO_SURFACE) { bbutil_egl_perror("eglCreateWindowSurface"); bbutil_terminate(); return EXIT_FAILURE; } rc = eglMakeCurrent(egl_disp, egl_surf, egl_surf, egl_ctx); if (rc != EGL_TRUE) { bbutil_egl_perror("eglMakeCurrent"); bbutil_terminate(); return EXIT_FAILURE; } rc = eglSwapInterval(egl_disp, interval); if (rc != EGL_TRUE) { bbutil_egl_perror("eglSwapInterval"); bbutil_terminate(); return EXIT_FAILURE; } initialized = 1; return EXIT_SUCCESS; }
EGLSurface QEgl::createSurface(QPaintDevice *device, EGLConfig cfg, const QEglProperties *properties) { // Create the native drawable for the paint device. int devType = device->devType(); EGLNativePixmapType pixmapDrawable = 0; EGLNativeWindowType windowDrawable = 0; bool ok; if (devType == QInternal::Pixmap) { pixmapDrawable = nativePixmap(static_cast<QPixmap *>(device)); ok = (pixmapDrawable != 0); } else if (devType == QInternal::Widget) { windowDrawable = nativeWindow(static_cast<QWidget *>(device)); ok = (windowDrawable != 0); } else { ok = false; } if (!ok) { qWarning("QEglContext::createSurface(): Cannot create the native EGL drawable"); return EGL_NO_SURFACE; } // Create the EGL surface to draw into, based on the native drawable. const int *props; if (properties) props = properties->properties(); else props = 0; EGLSurface surf = EGL_NO_SURFACE; #ifdef Q_OS_SYMBIAN // On Symbian there might be situations (especially on 32MB GPU devices) // where Qt is trying to create EGL surface while some other application // is still holding all available GPU memory but is about to release it // soon. For an example when exiting native video recorder and going back to // Qt application behind it. Video stack tear down takes some time and Qt // app might be too quick in reserving its EGL surface and thus running out // of GPU memory right away. So if EGL surface creation fails due to bad // alloc, let's try recreating it four times within ~1 second if needed. // This strategy gives some time for video recorder to tear down its stack // and a chance to Qt for creating a valid surface. // If the surface is still failing however, we don't keep the app blocked. static int tries = 4; if (tries <= 0) tries = 1; while (tries-- > 0) { if (devType == QInternal::Widget) surf = eglCreateWindowSurface(QEgl::display(), cfg, windowDrawable, props); else surf = eglCreatePixmapSurface(QEgl::display(), cfg, pixmapDrawable, props); if (surf == EGL_NO_SURFACE) { EGLint error = eglGetError(); if (error == EGL_BAD_ALLOC) { if (tries > 0) { User::After(1000 * 250); // 250ms continue; } } qWarning("QEglContext::createSurface(): Unable to create EGL surface, error = 0x%x", error); S60->eglSurfaceCreationError = true; } else { tries = 4; break; } } #else if (devType == QInternal::Widget) surf = eglCreateWindowSurface(QEgl::display(), cfg, windowDrawable, props); else surf = eglCreatePixmapSurface(QEgl::display(), cfg, pixmapDrawable, props); if (surf == EGL_NO_SURFACE) { qWarning("QEglContext::createSurface(): Unable to create EGL surface, error = 0x%x", eglGetError()); } #endif return surf; }
int bbutil_rotate_screen_surface(int angle) { int rc, rotation, skip = 1, temp;; EGLint interval = 1; int size[2]; if ((angle != 0) && (angle != 90) && (angle != 180) && (angle != 270)) { fprintf(stderr, "Invalid angle\n"); return EXIT_FAILURE; } rc = screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &rotation); if (rc) { perror("screen_set_window_property_iv"); return EXIT_FAILURE; } rc = screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size); if (rc) { perror("screen_set_window_property_iv"); return EXIT_FAILURE; } switch (angle - rotation) { case -270: case -90: case 90: case 270: temp = size[0]; size[0] = size[1]; size[1] = temp; skip = 0; break; } if (!skip) { rc = eglMakeCurrent(egl_disp, NULL, NULL, NULL); if (rc != EGL_TRUE) { bbutil_egl_perror("eglMakeCurrent"); return EXIT_FAILURE; } rc = eglDestroySurface(egl_disp, egl_surf); if (rc != EGL_TRUE) { bbutil_egl_perror("eglMakeCurrent"); return EXIT_FAILURE; } rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_SOURCE_SIZE, size); if (rc) { perror("screen_set_window_property_iv"); return EXIT_FAILURE; } rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size); if (rc) { perror("screen_set_window_property_iv"); return EXIT_FAILURE; } egl_surf = eglCreateWindowSurface(egl_disp, egl_conf, screen_win, NULL); if (egl_surf == EGL_NO_SURFACE) { bbutil_egl_perror("eglCreateWindowSurface"); return EXIT_FAILURE; } rc = eglMakeCurrent(egl_disp, egl_surf, egl_surf, egl_ctx); if (rc != EGL_TRUE) { bbutil_egl_perror("eglMakeCurrent"); return EXIT_FAILURE; } rc = eglSwapInterval(egl_disp, interval); if (rc != EGL_TRUE) { bbutil_egl_perror("eglSwapInterval"); return EXIT_FAILURE; } } rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &angle); if (rc) { perror("screen_set_window_property_iv"); return EXIT_FAILURE; } return EXIT_SUCCESS; }
static bool _cg_winsys_egl_onscreen_init(cg_onscreen_t *onscreen, EGLConfig egl_config, cg_error_t **error) { cg_framebuffer_t *framebuffer = CG_FRAMEBUFFER(onscreen); cg_device_t *dev = framebuffer->dev; cg_display_t *display = dev->display; cg_renderer_t *renderer = display->renderer; cg_renderer_egl_t *egl_renderer = renderer->winsys; cg_xlib_renderer_t *xlib_renderer = _cg_xlib_renderer_get_data(renderer); cg_onscreen_xlib_t *xlib_onscreen; cg_onscreen_egl_t *egl_onscreen = onscreen->winsys; Window xwin; /* FIXME: We need to explicitly Select for ConfigureNotify events. * For foreign windows we need to be careful not to mess up any * existing event mask. * We need to document that for windows we create then toolkits * must be careful not to clear event mask bits that we select. */ /* XXX: Note we ignore the user's original width/height when * given a foreign X window. */ if (onscreen->foreign_xid) { Status status; cg_xlib_trap_state_t state; XWindowAttributes attr; int xerror; xwin = onscreen->foreign_xid; _cg_xlib_renderer_trap_errors(display->renderer, &state); status = XGetWindowAttributes(xlib_renderer->xdpy, xwin, &attr); xerror = _cg_xlib_renderer_untrap_errors(display->renderer, &state); if (status == 0 || xerror) { char message[1000]; XGetErrorText( xlib_renderer->xdpy, xerror, message, sizeof(message)); _cg_set_error(error, CG_WINSYS_ERROR, CG_WINSYS_ERROR_CREATE_ONSCREEN, "Unable to query geometry of foreign " "xid 0x%08lX: %s", xwin, message); return false; } _cg_framebuffer_winsys_update_size( framebuffer, attr.width, attr.height); /* Make sure the app selects for the events we require... */ onscreen->foreign_update_mask_callback( onscreen, CG_ONSCREEN_X11_EVENT_MASK, onscreen->foreign_update_mask_data); } else { int width; int height; cg_xlib_trap_state_t state; XVisualInfo *xvisinfo; XSetWindowAttributes xattr; unsigned long mask; int xerror; width = cg_framebuffer_get_width(framebuffer); height = cg_framebuffer_get_height(framebuffer); _cg_xlib_renderer_trap_errors(display->renderer, &state); xvisinfo = get_visual_info(display, egl_config); if (xvisinfo == NULL) { _cg_set_error(error, CG_WINSYS_ERROR, CG_WINSYS_ERROR_CREATE_ONSCREEN, "Unable to retrieve the X11 visual of context's " "fbconfig"); return false; } /* window attributes */ xattr.background_pixel = WhitePixel(xlib_renderer->xdpy, DefaultScreen(xlib_renderer->xdpy)); xattr.border_pixel = 0; /* XXX: is this an X resource that we are leaking‽... */ xattr.colormap = XCreateColormap(xlib_renderer->xdpy, DefaultRootWindow(xlib_renderer->xdpy), xvisinfo->visual, AllocNone); xattr.event_mask = CG_ONSCREEN_X11_EVENT_MASK; mask = CWBorderPixel | CWColormap | CWEventMask; xwin = XCreateWindow(xlib_renderer->xdpy, DefaultRootWindow(xlib_renderer->xdpy), 0, 0, width, height, 0, xvisinfo->depth, InputOutput, xvisinfo->visual, mask, &xattr); XFree(xvisinfo); XSync(xlib_renderer->xdpy, False); xerror = _cg_xlib_renderer_untrap_errors(display->renderer, &state); if (xerror) { char message[1000]; XGetErrorText( xlib_renderer->xdpy, xerror, message, sizeof(message)); _cg_set_error(error, CG_WINSYS_ERROR, CG_WINSYS_ERROR_CREATE_ONSCREEN, "X error while creating Window for cg_onscreen_t: %s", message); return false; } } xlib_onscreen = c_slice_new(cg_onscreen_xlib_t); egl_onscreen->platform = xlib_onscreen; xlib_onscreen->xwin = xwin; xlib_onscreen->is_foreign_xwin = onscreen->foreign_xid ? true : false; egl_onscreen->egl_surface = eglCreateWindowSurface(egl_renderer->edpy, egl_config, (NativeWindowType)xlib_onscreen->xwin, NULL); return true; }
/*********************************************************** * Name: init_ogl * * Arguments: * CUBE_STATE_T *state - holds OGLES model info * * Description: Sets the display, OpenGL|ES context and screen stuff * * Returns: void * ***********************************************************/ static void init_ogl(CUBE_STATE_T *state) { int32_t success = 0; EGLBoolean result; EGLint num_config; static EGL_DISPMANX_WINDOW_T nativewindow; DISPMANX_ELEMENT_HANDLE_T dispman_element; DISPMANX_DISPLAY_HANDLE_T dispman_display; DISPMANX_UPDATE_HANDLE_T dispman_update; VC_RECT_T dst_rect; VC_RECT_T src_rect; static const EGLint attribute_list[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE }; EGLConfig config; // get an EGL display connection state->display = eglGetDisplay(EGL_DEFAULT_DISPLAY); assert(state->display!=EGL_NO_DISPLAY); // initialize the EGL display connection result = eglInitialize(state->display, NULL, NULL); assert(EGL_FALSE != result); // get an appropriate EGL frame buffer configuration result = eglChooseConfig(state->display, attribute_list, &config, 1, &num_config); assert(EGL_FALSE != result); // create an EGL rendering context state->context = eglCreateContext(state->display, config, EGL_NO_CONTEXT, NULL); assert(state->context!=EGL_NO_CONTEXT); // create an EGL window surface success = graphics_get_display_size(0 /* LCD */, &state->screen_width, &state->screen_height); assert( success >= 0 ); dst_rect.x = 0; dst_rect.y = 0; dst_rect.width = state->screen_width; dst_rect.height = state->screen_height; src_rect.x = 0; src_rect.y = 0; src_rect.width = state->screen_width << 16; src_rect.height = state->screen_height << 16; dispman_display = vc_dispmanx_display_open( 0 /* LCD */); dispman_update = vc_dispmanx_update_start( 0 ); dispman_element = vc_dispmanx_element_add ( dispman_update, dispman_display, 0/*layer*/, &dst_rect, 0/*src*/, &src_rect, DISPMANX_PROTECTION_NONE, 0 /*alpha*/, 0/*clamp*/, 0/*transform*/); nativewindow.element = dispman_element; nativewindow.width = state->screen_width; nativewindow.height = state->screen_height; vc_dispmanx_update_submit_sync( dispman_update ); state->surface = eglCreateWindowSurface( state->display, config, &nativewindow, NULL ); assert(state->surface != EGL_NO_SURFACE); // connect the context to the surface result = eglMakeCurrent(state->display, state->surface, state->surface, state->context); assert(EGL_FALSE != result); // Set background color and clear buffers glClearColor(0.15f, 0.25f, 0.35f, 1.0f); // Enable back face culling. glEnable(GL_CULL_FACE); glMatrixMode(GL_MODELVIEW); }