Пример #1
0
void
_eglutNativeInitWindow(struct eglut_window *win, const char *title,
                       int x, int y, int w, int h)
{
   EGLint surf_attribs[16];
   EGLint i;
   const char *exts;

   exts = eglQueryString(_eglut->dpy, EGL_EXTENSIONS);
   if (!exts || !strstr(exts, "EGL_MESA_screen_surface"))
      _eglutFatal("EGL_MESA_screen_surface is not supported\n");

   init_kms();

   i = 0;
   surf_attribs[i++] = EGL_WIDTH;
   surf_attribs[i++] = kms_width;
   surf_attribs[i++] = EGL_HEIGHT;
   surf_attribs[i++] = kms_height;
   surf_attribs[i++] = EGL_NONE;

   /* create surface */
   win->native.u.surface = eglCreateScreenSurfaceMESA(_eglut->dpy,
         win->config, surf_attribs);
   if (win->native.u.surface == EGL_NO_SURFACE)
      _eglutFatal("eglCreateScreenSurfaceMESA failed\n");

   if (!eglShowScreenSurfaceMESA(_eglut->dpy, kms_screen,
            win->native.u.surface, kms_mode))
      _eglutFatal("eglShowScreenSurfaceMESA failed\n");

   win->native.width = kms_width;
   win->native.height = kms_height;
}
Пример #2
0
void
_eglutNativeFiniWindow(struct eglut_window *win)
{
   eglShowScreenSurfaceMESA(_eglut->dpy,
         kms_screen, EGL_NO_SURFACE, 0);
   eglDestroySurface(_eglut->dpy, win->native.u.surface);
}
Пример #3
0
static Bool
xeglScreenInit (int	  index,
                ScreenPtr pScreen,
                int	  argc,
                char	  **argv)
{
    EGLSurface		    eSurface;
    EGLModeMESA		    mode;
    int			    count;
    xeglScreenPtr	    pScreenPriv;
    glitz_drawable_format_t *format;
    glitz_drawable_t	    *drawable;
    EGLint screenAttribs[] = {
        EGL_WIDTH, 1024,
        EGL_HEIGHT, 768,
        EGL_NONE
    };

    if (xglScreenInfo.width == 0 || xglScreenInfo.height == 0)
    {
        xglScreenInfo.width = XEGL_DEFAULT_SCREEN_WIDTH;
        xglScreenInfo.height = XEGL_DEFAULT_SCREEN_HEIGHT;

    }

    screenAttribs[1] = xglScreenInfo.width;
    screenAttribs[3] = xglScreenInfo.height;

    format = xglVisuals[0].format;

    if (!xeglAllocatePrivates (pScreen))
        return FALSE;

    currentScreen = pScreen;

    pScreenPriv = XEGL_GET_SCREEN_PRIV (pScreen);

    if (xglScreenInfo.width == 0 || xglScreenInfo.height == 0)
    {
        xglScreenInfo.width  = XEGL_DEFAULT_SCREEN_WIDTH;
        xglScreenInfo.height = XEGL_DEFAULT_SCREEN_HEIGHT;
    }

    eglGetModesMESA (eDisplay, eScreen, &mode, 1, &count);

    eSurface = eglCreateScreenSurfaceMESA (eDisplay, format->id, screenAttribs);
    if (eSurface == EGL_NO_SURFACE)
    {
        ErrorF ("failed to create screen surface\n");
        return FALSE;
    }

    eglShowScreenSurfaceMESA (eDisplay, eScreen, eSurface, mode);

    drawable = glitz_egl_create_surface (eDisplay, eScreen, format, eSurface,
                                         xglScreenInfo.width,
                                         xglScreenInfo.height);
    if (!drawable)
    {
        ErrorF ("[%d] couldn't create glitz drawable for window\n", index);
        return FALSE;
    }

    xglScreenInfo.drawable = drawable;

    if (!xglScreenInit (pScreen))
        return FALSE;

#ifdef GLXEXT
    if (!xglInitVisualConfigs (pScreen))
        return FALSE;
#endif

    XGL_SCREEN_WRAP (CloseScreen, xeglCloseScreen);

    miDCInitialize (pScreen, &kdPointerScreenFuncs);
    miCreateDefColormap(pScreen);

    if (!xglFinishScreenInit (pScreen))
        return FALSE;

    return TRUE;
}
Пример #4
0
int
main(int argc, char *argv[])
{
   int maj, min;
   EGLContext ctx;
   EGLSurface screen_surf;
   EGLConfig configs[10];
   EGLScreenMESA screen;
   EGLModeMESA mode;
   EGLint numConfigs, count;
   EGLBoolean b;
   const GLubyte *bitmap;
   EGLint screenAttribs[32];
   EGLint i;

   EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
   assert(d);

   if (!eglInitialize(d, &maj, &min)) {
      printf("demo: eglInitialize failed\n");
      exit(1);
   }

   printf("EGL version = %d.%d\n", maj, min);
   printf("EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR));
   if (!strstr(eglQueryString(d, EGL_EXTENSIONS),
               "EGL_MESA_screen_surface")) {
      printf("EGL_MESA_screen_surface is not supported\n");
      exit(1);
   }

   eglGetConfigs(d, configs, 10, &numConfigs);
   eglGetScreensMESA(d, &screen, 1, &count);
   eglGetModesMESA(d, screen, &mode, 1, &count);

   eglBindAPI(EGL_OPENGL_API);
   ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL);
   if (ctx == EGL_NO_CONTEXT) {
      printf("failed to create context\n");
      return 0;
   }

   i = 0;
   screenAttribs[i++] = EGL_WIDTH;
   eglGetModeAttribMESA(d, mode, EGL_WIDTH, &screenAttribs[i++]);
   screenAttribs[i++] = EGL_HEIGHT;
   eglGetModeAttribMESA(d, mode, EGL_HEIGHT, &screenAttribs[i++]);
   screenAttribs[i] = EGL_NONE;

   screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs);
   if (screen_surf == EGL_NO_SURFACE) {
      printf("failed to create screen surface\n");
      return 0;
   }

   eglShowScreenSurfaceMESA(d, screen, screen_surf, mode);

   b = eglMakeCurrent(d, screen_surf, screen_surf, ctx);
   if (!b) {
      printf("make current failed\n");
      return 0;
   }
   glViewport(0, 0, 1024, 768);


   Init();
   Reshape(1024, 768);

   /* some drivers crash when rendering to front buffer */
#if 0
   glDrawBuffer( GL_FRONT );
   glClearColor( 0, 1.0, 0, 1);

   glClear( GL_COLOR_BUFFER_BIT );
#endif

   doubleBuffer = 1;
   glDrawBuffer( GL_BACK );

   Draw(d, screen_surf);
   sleep(2);

   /* TODO EGL_KHR_lock_surface */
   bitmap = NULL;
   if (bitmap)
      write_ppm("dump.ppm", bitmap, 1024, 768);

   eglDestroySurface(d, screen_surf);
   eglDestroyContext(d, ctx);
   eglTerminate(d);

   return 0;
}