2 * Copyright (C) 2000 Brian Paul All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Simple regression test for bug #3195. A bug in the i180 driver caused
26 * a segfault (inside the driver) when the LOD bias is adjusted and no texture
27 * is enabled. This test, which is based on progs/demos/lodbias.c, sets up
28 * all the texturing, disables all textures, adjusts the LOD bias, then
29 * re-enables \c GL_TEXTURE_2D.
32 * \author Ian Romanick <idr@us.ibm.com>
44 #define TEXTURE_FILE "../images/girl.rgb"
46 static GLfloat Xrot
= 0, Yrot
= -30, Zrot
= 0;
47 static GLint Bias
= 0, BiasStepSign
= +1; /* ints avoid fp precision problem */
48 static GLint BiasMin
= -400, BiasMax
= 400;
53 PrintString(const char *s
)
56 glutBitmapCharacter(GLUT_BITMAP_8_BY_13
, (int) *s
);
61 static void Idle( void )
63 static int lastTime
= 0;
64 int time
= glutGet(GLUT_ELAPSED_TIME
);
69 else if (time
- lastTime
< 10)
72 step
= (time
- lastTime
) / 10 * BiasStepSign
;
79 else if (Bias
> BiasMax
) {
88 static void Display( void )
92 glClear( GL_COLOR_BUFFER_BIT
);
94 glMatrixMode( GL_PROJECTION
);
96 glOrtho(-1, 1, -1, 1, -1, 1);
97 glMatrixMode( GL_MODELVIEW
);
100 glDisable(GL_TEXTURE_2D
);
102 glRasterPos3f(-0.9, -0.9, 0.0);
103 sprintf(str
, "Texture LOD Bias = %4.1f", Bias
* 0.01);
106 glMatrixMode( GL_PROJECTION
);
108 glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
109 glMatrixMode( GL_MODELVIEW
);
111 glTranslatef( 0.0, 0.0, -8.0 );
114 glRotatef(Xrot
, 1, 0, 0);
115 glRotatef(Yrot
, 0, 1, 0);
116 glRotatef(Zrot
, 0, 0, 1);
118 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
, GL_TEXTURE_LOD_BIAS_EXT
, 0.01 * Bias
);
119 glEnable(GL_TEXTURE_2D
);
122 glTexCoord2f(0, 0); glVertex2f(-1, -1);
123 glTexCoord2f(2, 0); glVertex2f( 1, -1);
124 glTexCoord2f(2, 2); glVertex2f( 1, 1);
125 glTexCoord2f(0, 2); glVertex2f(-1, 1);
134 static void Reshape( int width
, int height
)
136 glViewport( 0, 0, width
, height
);
140 static void Key( unsigned char key
, int x
, int y
)
153 static void SpecialKey( int key
, int x
, int y
)
155 const GLfloat step
= 3.0;
176 static void Init( void )
179 const char * const ver_string
= (const char * const)
180 glGetString( GL_VERSION
);
182 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
183 printf("GL_VERSION = %s\n", ver_string
);
185 printf("\nThis program should function nearly identically to Mesa's lodbias demo.\n"
186 "It should cycle through the complet LOD bias range once and exit. If bug\n"
187 "#3195 still exists, the demo should crash almost immediatly.\n");
188 printf("This is a regression test for bug #3195.\n");
189 printf("https://bugs.freedesktop.org/show_bug.cgi?id=3195\n");
191 if (!glutExtensionSupported("GL_EXT_texture_lod_bias")) {
192 printf("Sorry, GL_EXT_texture_lod_bias not supported by this renderer.\n");
196 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
198 if (glutExtensionSupported("GL_SGIS_generate_mipmap")) {
199 /* test auto mipmap generation */
200 GLint width
, height
, i
;
202 GLubyte
*image
= LoadRGBImage(TEXTURE_FILE
, &width
, &height
, &format
);
204 printf("Error: could not load texture image %s\n", TEXTURE_FILE
);
207 /* resize to 256 x 256 */
208 if (width
!= 256 || height
!= 256) {
209 GLubyte
*newImage
= malloc(256 * 256 * 4);
210 gluScaleImage(format
, width
, height
, GL_UNSIGNED_BYTE
, image
,
211 256, 256, GL_UNSIGNED_BYTE
, newImage
);
215 printf("Using GL_SGIS_generate_mipmap\n");
216 glTexParameteri(GL_TEXTURE_2D
, GL_GENERATE_MIPMAP_SGIS
, GL_TRUE
);
217 glTexImage2D(GL_TEXTURE_2D
, 0, format
, 256, 256, 0,
218 format
, GL_UNSIGNED_BYTE
, image
);
221 /* make sure mipmap was really generated correctly */
222 width
= height
= 256;
223 for (i
= 0; i
< 9; i
++) {
225 glGetTexLevelParameteriv(GL_TEXTURE_2D
, i
, GL_TEXTURE_WIDTH
, &w
);
226 glGetTexLevelParameteriv(GL_TEXTURE_2D
, i
, GL_TEXTURE_HEIGHT
, &h
);
227 printf("Level %d size: %d x %d\n", i
, w
, h
);
235 else if (!LoadRGBMipmaps(TEXTURE_FILE
, GL_RGB
)) {
236 printf("Error: could not load texture image %s\n", TEXTURE_FILE
);
240 /* mipmapping required for this extension */
241 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR_MIPMAP_LINEAR
);
242 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
243 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
245 glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS_EXT
, &maxBias
);
246 printf("LOD bias range: [%g, %g]\n", -maxBias
, maxBias
);
247 BiasMin
= -100 * maxBias
;
248 BiasMax
= 100 * maxBias
;
250 /* Since we have (about) 8 mipmap levels, no need to bias beyond
251 * the range [-1, +8].
260 int main( int argc
, char *argv
[] )
262 glutInit( &argc
, argv
);
263 glutInitWindowPosition( 0, 0 );
264 glutInitWindowSize( 350, 350 );
265 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
266 glutCreateWindow( "Bug #3195 Test" );
268 glutReshapeFunc( Reshape
);
269 glutKeyboardFunc( Key
);
270 glutSpecialFunc( SpecialKey
);
271 glutDisplayFunc( Display
);