예제 #1
0
static void
init_kms(void)
{
   EGLModeMESA modes[MAX_MODES];
   EGLint num_screens, num_modes;
   EGLint width, height, best_mode;
   EGLint i;

   if (!eglGetScreensMESA(_eglut->dpy, &kms_screen, 1, &num_screens) ||
         !num_screens)
      _eglutFatal("eglGetScreensMESA failed\n");

   if (!eglGetModesMESA(_eglut->dpy, kms_screen,
            modes, MAX_MODES, &num_modes) || !num_modes)
      _eglutFatal("eglGetModesMESA failed!\n");

   printf("Found %d modes:\n", num_modes);

   best_mode = 0;
   width = 0;
   height = 0;
   for (i = 0; i < num_modes; i++) {
      EGLint w, h;
      eglGetModeAttribMESA(_eglut->dpy, modes[i], EGL_WIDTH, &w);
      eglGetModeAttribMESA(_eglut->dpy, modes[i], EGL_HEIGHT, &h);
      printf("%3d: %d x %d\n", i, w, h);
      if (w > width && h > height) {
         width = w;
         height = h;
         best_mode = i;
      }
   }

   printf("Will use screen size: %d x %d\n", width, height);

   kms_mode = modes[best_mode];
   kms_width = width;
   kms_height = height;
}
예제 #2
0
파일: demo3.c 프로젝트: aosm/X11apps
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;
}