~ubuntu-branches/ubuntu/jaunty/mesa/jaunty-proposed

« back to all changes in this revision

Viewing changes to progs/xdemos/glxgears.c

  • Committer: Bazaar Package Importer
  • Author(s): Timo Aaltonen
  • Date: 2009-04-03 12:42:06 UTC
  • mfrom: (1.3.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 70.
  • Revision ID: james.westby@ubuntu.com-20090403124206-vulvbgrn29zpeb2m
Tags: upstream-7.4
ImportĀ upstreamĀ versionĀ 7.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include <GL/gl.h>
40
40
#include <GL/glx.h>
41
41
 
 
42
static int is_glx_extension_supported(Display *dpy, const char *query);
 
43
 
 
44
static void query_vsync(Display *dpy);
42
45
 
43
46
#define BENCHMARK
44
47
 
561
564
 
562
565
 
563
566
/**
 
567
 * Determine whether or not a GLX extension is supported.
 
568
 */
 
569
int
 
570
is_glx_extension_supported(Display *dpy, const char *query)
 
571
{
 
572
   const int scrnum = DefaultScreen(dpy);
 
573
   const char *glx_extensions = NULL;
 
574
   const size_t len = strlen(query);
 
575
   const char *ptr;
 
576
 
 
577
   if (glx_extensions == NULL) {
 
578
      glx_extensions = glXQueryExtensionsString(dpy, scrnum);
 
579
   }
 
580
 
 
581
   ptr = strstr(glx_extensions, query);
 
582
   return ((ptr != NULL) && ((ptr[len] == ' ') || (ptr[len] == '\0')));
 
583
}
 
584
 
 
585
 
 
586
/**
 
587
 * Attempt to determine whether or not the display is synched to vblank.
 
588
 */
 
589
void
 
590
query_vsync(Display *dpy)
 
591
{
 
592
   int interval = 0;
 
593
 
 
594
 
 
595
#ifdef GLX_MESA_swap_control
 
596
   if ((interval <= 0)
 
597
       && is_glx_extension_supported(dpy, "GLX_MESA_swap_control")) {
 
598
      PFNGLXGETSWAPINTERVALMESAPROC pglXGetSwapIntervalMESA =
 
599
          (PFNGLXGETSWAPINTERVALMESAPROC)
 
600
          glXGetProcAddressARB((const GLubyte *) "glXGetSwapIntervalMESA");
 
601
 
 
602
      interval = (*pglXGetSwapIntervalMESA)();
 
603
   }
 
604
#endif
 
605
 
 
606
 
 
607
#ifdef GLX_SGI_video_sync
 
608
   if ((interval <= 0)
 
609
       && is_glx_extension_supported(dpy, "GLX_SGI_video_sync")) {
 
610
      PFNGLXGETVIDEOSYNCSGIPROC pglXGetVideoSyncSGI =
 
611
          (PFNGLXGETVIDEOSYNCSGIPROC)
 
612
          glXGetProcAddressARB((const GLubyte *) "glXGetVideoSyncSGI");
 
613
      unsigned count;
 
614
 
 
615
      if ((*pglXGetVideoSyncSGI)(& count) == 0) {
 
616
         interval = (int) count;
 
617
      }
 
618
   }
 
619
#endif
 
620
 
 
621
 
 
622
   if (interval > 0) {
 
623
      printf("Running synchronized to the vertical refresh.  The framerate should be\n");
 
624
      if (interval == 1) {
 
625
         printf("approximately the same as the monitor refresh rate.\n");
 
626
      } else if (interval > 1) {
 
627
         printf("approximately 1/%d the monitor refresh rate.\n",
 
628
                interval);
 
629
      }
 
630
   }
 
631
}
 
632
 
 
633
/**
564
634
 * Handle one X event.
565
635
 * \return NOP, EXIT or DRAW
566
636
 */
567
637
static int
568
638
handle_event(Display *dpy, Window win, XEvent *event)
569
639
{
 
640
   (void) dpy;
 
641
   (void) win;
 
642
 
570
643
   switch (event->type) {
571
644
   case Expose:
572
645
      return DRAW;
686
759
   make_window(dpy, "glxgears", x, y, winWidth, winHeight, &win, &ctx);
687
760
   XMapWindow(dpy, win);
688
761
   glXMakeCurrent(dpy, win, ctx);
 
762
   query_vsync(dpy);
689
763
 
690
764
   if (printInfo) {
691
765
      printf("GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));