home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / voglw.zip / buffer.c < prev    next >
C/C++ Source or Header  |  1997-02-13  |  2KB  |  141 lines

  1. #include "vogl.h"
  2.  
  3. static    int    sync = 1;
  4. /*
  5.  * backbuffer
  6.  *
  7.  *    swap drawing to backbuffer - returns -1 if no
  8.  * backbuffer is available.
  9.  */
  10. void
  11. backbuffer(yes)
  12.     int    yes;
  13. {
  14.     Token    *tok;
  15.  
  16.     if (!vdevice.initialised)
  17.         verror("backbuffer: vogl not initialised.");
  18.  
  19.     if (vdevice.inobject) {
  20.         tok = newtokens(2);
  21.         tok[0].i = BACKBUFFER;
  22.         tok[1].i = yes;
  23.         return;
  24.     }
  25.  
  26.     if (vdevice.attr->a.mode == SINGLE)
  27.         return;
  28.  
  29.     if (yes) {
  30.         if ((*vdevice.dev.Vbackb)() < 0)
  31.             verror("device doesn't support double buffering\n");
  32.         
  33.         vdevice.inbackbuffer = 1;
  34.         vdevice.sync = 0;
  35.     } else
  36.         vdevice.inbackbuffer = 0;
  37.     
  38. }
  39.  
  40. /*
  41.  * frontbuffer
  42.  *
  43.  *    start drawing in the front buffer again. This
  44.  * will always work!
  45.  */
  46. void
  47. frontbuffer(yes)
  48.     int    yes;
  49. {
  50.     Token    *tok;
  51.  
  52.     if (!vdevice.initialised)
  53.         verror("frontbuffer: vogl not initialised.");
  54.  
  55.     if (vdevice.inobject) {
  56.         tok = newtokens(2);
  57.         tok[0].i = FRONTBUFFER;
  58.         tok[1].i = yes;
  59.         return;
  60.     }
  61.  
  62.     if (vdevice.attr->a.mode == SINGLE)
  63.         return;
  64.  
  65.     if (yes) {
  66.         (*vdevice.dev.Vfrontb)();
  67.         vdevice.inbackbuffer = 0;
  68.         vdevice.sync = sync;
  69.     } else
  70.         backbuffer(1);
  71. }
  72.  
  73. /*
  74.  * swapbuffers
  75.  *
  76.  *    swap the back and front buffers - returns -1 if
  77.  * no backbuffer is available.
  78.  */
  79. void
  80. swapbuffers()
  81. {
  82.     Token    *tok;
  83.  
  84.     if (vdevice.inobject) {
  85.         tok = newtokens(1);
  86.         tok[0].i = SWAPBUFFERS;
  87.         return;
  88.     }
  89.  
  90.     if (!vdevice.initialised)
  91.         verror("swapbuffers: vogl not initialised.");
  92.  
  93. /* TEST HACK
  94.     if (vdevice.inbackbuffer != 1)
  95.         verror("swapbuffers: double buffering not initialised.\n");
  96. */
  97.  
  98.     if ((*vdevice.dev.Vswapb)() < 0)
  99.         verror("swapbuffers device doesn't support double buffering\n");
  100.  
  101. }
  102.  
  103. /*
  104.  * doublebuffer()
  105.  *
  106.  *    Flags our intention to do double buffering....
  107.  *    tries to set it up etc etc...
  108.  */
  109. void
  110. doublebuffer()
  111. {
  112.     if (!vdevice.initialised)
  113.         verror("doublebuffer: vogl not initialised.");
  114.  
  115.     if ((*vdevice.dev.Vbackb)() < 0)
  116.         verror("device doesn't support double buffering\n");
  117.  
  118.     vdevice.inbackbuffer = 1;
  119.     sync = vdevice.sync;
  120.     vdevice.sync = 0;
  121. }
  122.  
  123. /*
  124.  * singlebuffer()
  125.  *
  126.  *    Goes back to singlebuffer mode....(crock)
  127.  */
  128. void
  129. singlebuffer()
  130.     if (vdevice.attr->a.mode == SINGLE)
  131.         return;
  132.  
  133.     (*vdevice.dev.Vfrontb)();
  134.  
  135.     vdevice.inbackbuffer = 0;
  136.  
  137.     if (sync)
  138.         vdevice.sync = 1;
  139. }
  140.