QEGLPbuffer::~QEGLPbuffer() { eglDestroySurface(m_display, m_pbuffer); }
int main(int argc, char *argv[]) { const int winWidth = 800, winHeight = 600; Display *x_dpy; Window win; EGLSurface egl_surf; EGLContext egl_ctx; EGLDisplay egl_dpy; char *dpyName = NULL; GLboolean printInfo = GL_FALSE; EGLint egl_major, egl_minor; const char *s; if (!InitTest(argc, argv)) { return -1; } x_dpy = XOpenDisplay(dpyName); if (!x_dpy) { printf("Error: couldn't open display %s\n", dpyName ? dpyName : getenv("DISPLAY")); return -1; } egl_dpy = eglGetDisplay(x_dpy); if (!egl_dpy) { printf("Error: eglGetDisplay() failed\n"); return -1; } if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) { printf("Error: eglInitialize() failed\n"); return -1; } s = eglQueryString(egl_dpy, EGL_VERSION); printf("EGL_VERSION = %s\n", s); s = eglQueryString(egl_dpy, EGL_VENDOR); printf("EGL_VENDOR = %s\n", s); s = eglQueryString(egl_dpy, EGL_EXTENSIONS); printf("EGL_EXTENSIONS = %s\n", s); s = eglQueryString(egl_dpy, EGL_CLIENT_APIS); printf("EGL_CLIENT_APIS = %s\n", s); make_x_window(x_dpy, egl_dpy, "OpenGL ES 2.x tri", 0, 0, winWidth, winHeight, &win, &egl_ctx, &egl_surf); XMapWindow(x_dpy, win); if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) { printf("Error: eglMakeCurrent() failed\n"); return -1; } if (printInfo) { printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); } InitRendering(); LoadDefaultData(); // render once testHelper->app()->resizeView(winWidth, winHeight); testHelper->app()->resetView(); testHelper->app()->render(); eglSwapBuffers(egl_dpy, egl_surf); // begin the event loop if not in testing mode bool testPassed = true; if (!testHelper->isTesting()) { event_loop(x_dpy, win, egl_dpy, egl_surf); } else { testPassed = DoTesting(); } FinalizeTest(); eglDestroyContext(egl_dpy, egl_ctx); eglDestroySurface(egl_dpy, egl_surf); eglTerminate(egl_dpy); XDestroyWindow(x_dpy, win); XCloseDisplay(x_dpy); return testPassed ? 0 : 1; }
void test_triangle_smoothed(GLenum mode) { GLint width, height; GLfloat vVertices[] = { 0.0f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f }; GLfloat vColors[] = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f}; EGLSurface surface; RD_START("triangle-smoothed", ""); display = get_display(); /* get an appropriate EGL frame buffer configuration */ ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config)); DEBUG_MSG("num_config: %d", num_config); /* create an EGL rendering context */ ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list)); surface = make_window(display, config, 400, 240); ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width)); ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height)); DEBUG_MSG("Buffer: %dx%d", width, height); /* connect the context to the surface */ ECHK(eglMakeCurrent(display, surface, surface, context)); program = get_program(vertex_shader_source, fragment_shader_source); GCHK(glBindAttribLocation(program, 0, "aPosition")); GCHK(glBindAttribLocation(program, 1, "aColor")); link_program(program); GCHK(glViewport(0, 0, width, height)); GCHK(glFrontFace(mode)); /* clear the color buffer */ GCHK(glClearColor(0.0, 0.0, 0.0, 1.0)); GCHK(glClear(GL_COLOR_BUFFER_BIT)); GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices)); GCHK(glEnableVertexAttribArray(0)); GCHK(glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, vColors)); GCHK(glEnableVertexAttribArray(1)); GCHK(glDrawArrays(GL_TRIANGLES, 0, 3)); ECHK(eglSwapBuffers(display, surface)); GCHK(glFlush()); ECHK(eglDestroySurface(display, surface)); ECHK(eglTerminate(display)); RD_END(); }
void EGLPlatformContext::destroyTemporaryOffscreenSurface(EGLSurface surface) { eglDestroySurface(m_eglDisplay, surface); }
~SwapChainGL() { eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroyContext(m_display, m_context); eglDestroySurface(m_display, m_surface); }
cairo_device_t * cairo_egl_device_create (EGLDisplay dpy, EGLContext egl) { cairo_egl_context_t *ctx; cairo_status_t status; int attribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE, }; EGLConfig config; EGLint numConfigs; ctx = calloc (1, sizeof (cairo_egl_context_t)); if (unlikely (ctx == NULL)) return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY); ctx->display = dpy; ctx->context = egl; ctx->base.acquire = _egl_acquire; ctx->base.release = _egl_release; ctx->base.make_current = _egl_make_current; ctx->base.swap_buffers = _egl_swap_buffers; ctx->base.destroy = _egl_destroy; /* We are about the change the current state of EGL, so we should * query the pre-existing surface now instead of later. */ _egl_query_current_state (ctx); if (!_egl_make_current_surfaceless (ctx)) { /* Fall back to dummy surface, meh. */ EGLint config_attribs[] = { EGL_CONFIG_ID, 0, EGL_NONE }; /* * In order to be able to make an egl context current when using a * pbuffer surface, that surface must have been created with a config * that is compatible with the context config. For Mesa, this means * that the configs must be the same. */ eglQueryContext (dpy, egl, EGL_CONFIG_ID, &config_attribs[1]); eglChooseConfig (dpy, config_attribs, &config, 1, &numConfigs); ctx->dummy_surface = eglCreatePbufferSurface (dpy, config, attribs); if (ctx->dummy_surface == NULL) { free (ctx); return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY); } if (!eglMakeCurrent (dpy, ctx->dummy_surface, ctx->dummy_surface, egl)) { free (ctx); return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY); } } status = _cairo_gl_dispatch_init (&ctx->base.dispatch, eglGetProcAddress); if (unlikely (status)) { free (ctx); return _cairo_gl_context_create_in_error (status); } status = _cairo_gl_context_init (&ctx->base); if (unlikely (status)) { if (ctx->dummy_surface != EGL_NO_SURFACE) eglDestroySurface (dpy, ctx->dummy_surface); free (ctx); return _cairo_gl_context_create_in_error (status); } eglMakeCurrent (dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); return &ctx->base.base; }