From: Brian Paul Date: Thu, 13 Apr 2006 19:45:42 +0000 (+0000) Subject: If the image file is RGB, convert to RGBA (fixes segfault). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1d886a81add08536f18d2453ae38fcac79f0b806;p=mesa.git If the image file is RGB, convert to RGBA (fixes segfault). Added CheckError() calls. Remove -ci option. --- diff --git a/progs/tests/pbo.c b/progs/tests/pbo.c index a74e8e148b3..b31b36cc121 100644 --- a/progs/tests/pbo.c +++ b/progs/tests/pbo.c @@ -32,11 +32,20 @@ static GLboolean Benchmark = GL_FALSE; static GLuint DrawPBO, TempPBO; -static GLenum ReadFormat = GL_RGBA; -static GLenum ReadType = GL_UNSIGNED_BYTE; +static GLenum ReadFormat = GL_BGRA; +static GLenum ReadType = GL_UNSIGNED_INT_8_8_8_8_REV; +static void +CheckError(int line) +{ + GLenum err = glGetError(); + if (err) { + printf("GL Error 0x%x at line %d\n", (int) err, line); + } +} + static void Reset( void ) @@ -85,6 +94,8 @@ 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); @@ -105,12 +116,15 @@ Display( void ) 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; @@ -133,14 +147,20 @@ Display( void ) 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"); @@ -149,6 +169,8 @@ Display( void ) SetupPixelTransfer(ScaleAndBias); glCopyPixels(APosX, APosY, ImgWidth, ImgHeight, GL_COLOR); + CheckError(__LINE__); + if (!DrawFront) glutSwapBuffers(); else @@ -201,7 +223,7 @@ Key( unsigned char key, int x, int y ) static void -Init( GLboolean ciMode ) +Init(void) { printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); @@ -217,26 +239,24 @@ Init( GLboolean ciMode ) exit(0); } - if (ciMode) { - /* Convert RGB image to grayscale */ - GLubyte *indexImage = (GLubyte *) malloc( ImgWidth * ImgHeight ); - GLint i; - for (i=0; i 1 && strcmp(argv[1], "-ci")==0) { - ciMode = GL_TRUE; - } glutInit( &argc, argv ); glutInitWindowPosition( 0, 0 ); glutInitWindowSize( 750, 250 ); - if (ciMode) - glutInitDisplayMode( GLUT_INDEX | GLUT_DOUBLE ); - else - glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow(argv[0]); - Init(ciMode); + Init(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display );