Пример #1
0
static void
Display( void )
{
    glClearColor(.3, .3, .3, 1);
    glClear( GL_COLOR_BUFFER_BIT );

    glRasterPos2i(5, ImgHeight+25);
    PrintString("f = toggle front/back  s = toggle scale/bias  b = benchmark");

    /* draw original image */
    glRasterPos2i(APosX, 5);
    PrintString("Original");
    glRasterPos2i(APosX, APosY);
    glEnable(GL_DITHER);
    SetupPixelTransfer(GL_FALSE);
    glDrawPixels(ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image);

    /* do readpixels, drawpixels */
    glRasterPos2i(BPosX, 5);
    PrintString("Read/DrawPixels");
    SetupPixelTransfer(ScaleAndBias);
    if (Benchmark) {
        GLint reads = 0;
        GLint endTime;
        GLint startTime = glutGet(GLUT_ELAPSED_TIME);
        GLdouble seconds, pixelsPerSecond;
        printf("Benchmarking...\n");
        do {
            glReadPixels(APosX, APosY, ImgWidth, ImgHeight,
                         ReadFormat, ReadType, TempImage);
            reads++;
            endTime = glutGet(GLUT_ELAPSED_TIME);
        } while (endTime - startTime < 4000);   /* 4 seconds */
        seconds = (double) (endTime - startTime) / 1000.0;
        pixelsPerSecond = reads * ImgWidth * ImgHeight / seconds;
        printf("Result:  %d reads in %f seconds = %f pixels/sec\n",
               reads, seconds, pixelsPerSecond);
        Benchmark = GL_FALSE;
    }
    else {
        /* clear the temporary image to white (helpful for debugging */
        memset(TempImage, 255, ImgWidth * ImgHeight * 4);
        glReadPixels(APosX, APosY, ImgWidth, ImgHeight,
                     ReadFormat, ReadType, TempImage);
    }
    glRasterPos2i(BPosX, BPosY);
    glDisable(GL_DITHER);
    SetupPixelTransfer(GL_FALSE);
    glDrawPixels(ImgWidth, ImgHeight, ReadFormat, ReadType, TempImage);

    /* do copypixels */
    glRasterPos2i(CPosX, 5);
    PrintString("CopyPixels");
    glRasterPos2i(CPosX, CPosY);
    glDisable(GL_DITHER);
    SetupPixelTransfer(ScaleAndBias);
    glCopyPixels(APosX, APosY, ImgWidth, ImgHeight, GL_COLOR);

    if (!DrawFront)
        glutSwapBuffers();
    else
        glFinish();
}
Пример #2
0
Файл: pbo.c Проект: aosm/X11apps
static void
Display( void )
{
   glClearColor(.3, .3, .3, 1);
   glClear( GL_COLOR_BUFFER_BIT );

   CheckError(__LINE__);

   /** Unbind UNPACK pixel buffer before calling glBitmap */
   glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);

   glRasterPos2i(5, ImgHeight+25);
   PrintString("f = toggle front/back  s = toggle scale/bias  b = benchmark");

   glRasterPos2i(5, ImgHeight+40);
   PrintString("GL_EXT_pixel_buffer_object test");

   /* draw original image */
   glRasterPos2i(APosX, 5);
   PrintString("Original");
   glRasterPos2i(APosX, APosY);
   glEnable(GL_DITHER);
   SetupPixelTransfer(GL_FALSE);
   /*** Draw from the DrawPBO */
   glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, DrawPBO);
   glDrawPixels(ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, 0);
   glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);

   CheckError(__LINE__);

   /* do readpixels, drawpixels */
   glRasterPos2i(BPosX, 5);
   PrintString("Read/DrawPixels");
   SetupPixelTransfer(ScaleAndBias);
   /*** read into the Temp PBO */
   glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, TempPBO);
   CheckError(__LINE__);
   if (Benchmark) {
      GLint reads = 0;
      GLint endTime;
      GLint startTime = glutGet(GLUT_ELAPSED_TIME);
      GLdouble seconds, pixelsPerSecond;
      printf("Benchmarking...\n");
      do {
         glReadPixels(APosX, APosY, ImgWidth, ImgHeight,
                      ReadFormat, ReadType, 0);
         reads++;
         endTime = glutGet(GLUT_ELAPSED_TIME);
      } while (endTime - startTime < 4000);   /* 4 seconds */
      seconds = (double) (endTime - startTime) / 1000.0;
      pixelsPerSecond = reads * ImgWidth * ImgHeight / seconds;
      printf("Result:  %d reads in %f seconds = %f pixels/sec\n",
             reads, seconds, pixelsPerSecond);
      Benchmark = GL_FALSE;
   }
   else {
      glReadPixels(APosX, APosY, ImgWidth, ImgHeight,
                   ReadFormat, ReadType, 0);
   }
   CheckError(__LINE__);
   glRasterPos2i(BPosX, BPosY);
   glDisable(GL_DITHER);
   SetupPixelTransfer(GL_FALSE);

   CheckError(__LINE__);

   /*** draw from the Temp PBO */
   glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, TempPBO);
   glDrawPixels(ImgWidth, ImgHeight, ReadFormat, ReadType, 0);
   glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);

   CheckError(__LINE__);

   /* do copypixels */
   glRasterPos2i(CPosX, 5);
   PrintString("CopyPixels");
   glRasterPos2i(CPosX, CPosY);
   glDisable(GL_DITHER);
   SetupPixelTransfer(ScaleAndBias);
   glCopyPixels(APosX, APosY, ImgWidth, ImgHeight, GL_COLOR);

   CheckError(__LINE__);

   if (!DrawFront)
      glutSwapBuffers();
   else
      glFinish();
}
Пример #3
0
static void
Display( void )
{
   glClearColor(.3, .3, .3, 1);
   glClear( GL_COLOR_BUFFER_BIT );

   glRasterPos2i(5, ImgHeight+25);
   PrintString("f = toggle front/back  s = toggle scale/bias  b = benchmark");

   /* draw original image */
   glRasterPos2i(APosX, 5);
   PrintString("Original");
   if (!Triangle) {
      glRasterPos2i(APosX, APosY);
      glEnable(GL_DITHER);
      SetupPixelTransfer(GL_FALSE);
      glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
      glDrawPixels(ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image);
   }
   else {
      float z = 0;

      glViewport(APosX, APosY, ImgWidth, ImgHeight);
      glMatrixMode( GL_PROJECTION );
      glLoadIdentity();
      glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
      glDisable(GL_CULL_FACE);

      /* Red should never be seen
       */
      glBegin(GL_POLYGON);
      glColor3f(1,0,0); 
      glVertex3f(-2, -2, z);
      glVertex3f(-2, 2, z);
      glVertex3f(2, 2, z);
      glVertex3f(2, -2, z);
      glEnd();

      /* Blue background
       */
      glBegin(GL_POLYGON);
      glColor3f(.5,.5,1); 
      glVertex3f(-1, -1, z);
      glVertex3f(-1, 1, z);
      glVertex3f(1, 1, z);
      glVertex3f(1, -1, z);
      glEnd();

      /* Triangle
       */
      glBegin(GL_TRIANGLES);
      glColor3f(.8,0,0); 
      glVertex3f(-0.9, -0.9, z);
      glColor3f(0,.9,0); 
      glVertex3f( 0.9, -0.9, z);
      glColor3f(0,0,.7); 
      glVertex3f( 0.0,  0.9, z);
      glEnd();
      
      glColor3f(1,1,1);

      glViewport( 0, 0, WinWidth, WinHeight );
      glMatrixMode( GL_PROJECTION );
      glLoadIdentity();
      glOrtho( 0.0, WinWidth, 0.0, WinHeight, -1.0, 1.0 );
   }

   /* might try alignment=4 here for testing */
   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   glPixelStorei(GL_PACK_ALIGNMENT, 1);

   /* do readpixels, drawpixels */
   glRasterPos2i(BPosX, 5);
   PrintString("Read/DrawPixels");
   SetupPixelTransfer(ScaleAndBias);
   if (Benchmark) {
      GLint reads = 0;
      GLint endTime;
      GLint startTime = glutGet(GLUT_ELAPSED_TIME);
      GLdouble seconds, mpixels, mpixelsPerSecond;
      printf("Benchmarking...\n");
      do {
         glReadPixels(APosX, APosY, ImgWidth, ImgHeight,
                      ReadFormat, ReadType, TempImage);
         reads++;
         endTime = glutGet(GLUT_ELAPSED_TIME);
      } while (endTime - startTime < 4000);   /* 4 seconds */
      seconds = (double) (endTime - startTime) / 1000.0;
      mpixels = reads * (ImgWidth * ImgHeight / (1000.0 * 1000.0));
      mpixelsPerSecond = mpixels / seconds;
      printf("Result:  %d reads in %f seconds = %f Mpixels/sec\n",
             reads, seconds, mpixelsPerSecond);
      Benchmark = GL_FALSE;
   }
   else {
      /* clear the temporary image to white (helpful for debugging */
      memset(TempImage, 255, ImgWidth * ImgHeight * 4);
#if 1
      glReadPixels(APosX, APosY, ImgWidth, ImgHeight,
                   ReadFormat, ReadType, TempImage);
      (void) ComplexReadPixels;
#else
      /* you might use this when debugging */
      ComplexReadPixels(APosX, APosY, ImgWidth, ImgHeight,
                        ReadFormat, ReadType, TempImage);
#endif
   }
   glRasterPos2i(BPosX, BPosY);
   glDisable(GL_DITHER);
   SetupPixelTransfer(GL_FALSE);
   glDrawPixels(ImgWidth, ImgHeight, ReadFormat, ReadType, TempImage);

   /* do copypixels */
   glRasterPos2i(CPosX, 5);
   PrintString("CopyPixels");
   glRasterPos2i(CPosX, CPosY);
   glDisable(GL_DITHER);
   SetupPixelTransfer(ScaleAndBias);
   glCopyPixels(APosX, APosY, ImgWidth, ImgHeight, GL_COLOR);

   if (!DrawFront)
      glutSwapBuffers();
   else
      glFinish();
}