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>
45 #define TEXTURE_FILE "../images/girl.rgb"
47 static GLfloat Xrot
= 0, Yrot
= -30, Zrot
= 0;
48 static GLint Bias
= 0, BiasStepSign
= +1; /* ints avoid fp precision problem */
49 static GLint BiasMin
= -400, BiasMax
= 400;
54 PrintString(const char *s
)
57 glutBitmapCharacter(GLUT_BITMAP_8_BY_13
, (int) *s
);
62 static void Idle( void )
64 static int lastTime
= 0;
65 int time
= glutGet(GLUT_ELAPSED_TIME
);
70 else if (time
- lastTime
< 10)
73 step
= (time
- lastTime
) / 10 * BiasStepSign
;
80 else if (Bias
> BiasMax
) {
89 static void Display( void )
93 glClear( GL_COLOR_BUFFER_BIT
);
95 glMatrixMode( GL_PROJECTION
);
97 glOrtho(-1, 1, -1, 1, -1, 1);
98 glMatrixMode( GL_MODELVIEW
);
101 glDisable(GL_TEXTURE_2D
);
103 glRasterPos3f(-0.9, -0.9, 0.0);
104 sprintf(str
, "Texture LOD Bias = %4.1f", Bias
* 0.01);
107 glMatrixMode( GL_PROJECTION
);
109 glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
110 glMatrixMode( GL_MODELVIEW
);
112 glTranslatef( 0.0, 0.0, -8.0 );
115 glRotatef(Xrot
, 1, 0, 0);
116 glRotatef(Yrot
, 0, 1, 0);
117 glRotatef(Zrot
, 0, 0, 1);
119 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT
, GL_TEXTURE_LOD_BIAS_EXT
, 0.01 * Bias
);
120 glEnable(GL_TEXTURE_2D
);
123 glTexCoord2f(0, 0); glVertex2f(-1, -1);
124 glTexCoord2f(2, 0); glVertex2f( 1, -1);
125 glTexCoord2f(2, 2); glVertex2f( 1, 1);
126 glTexCoord2f(0, 2); glVertex2f(-1, 1);
135 static void Reshape( int width
, int height
)
137 glViewport( 0, 0, width
, height
);
141 static void Key( unsigned char key
, int x
, int y
)
154 static void SpecialKey( int key
, int x
, int y
)
156 const GLfloat step
= 3.0;
177 static void Init( void )
180 const char * const ver_string
= (const char * const)
181 glGetString( GL_VERSION
);
183 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
184 printf("GL_VERSION = %s\n", ver_string
);
186 printf("\nThis program should function nearly identically to Mesa's lodbias demo.\n"
187 "It should cycle through the complet LOD bias range once and exit. If bug\n"
188 "#3195 still exists, the demo should crash almost immediatly.\n");
189 printf("This is a regression test for bug #3195.\n");
190 printf("https://bugs.freedesktop.org/show_bug.cgi?id=3195\n");
192 if (!glutExtensionSupported("GL_EXT_texture_lod_bias")) {
193 printf("Sorry, GL_EXT_texture_lod_bias not supported by this renderer.\n");
197 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
199 if (glutExtensionSupported("GL_SGIS_generate_mipmap")) {
200 /* test auto mipmap generation */
201 GLint width
, height
, i
;
203 GLubyte
*image
= LoadRGBImage(TEXTURE_FILE
, &width
, &height
, &format
);
205 printf("Error: could not load texture image %s\n", TEXTURE_FILE
);
208 /* resize to 256 x 256 */
209 if (width
!= 256 || height
!= 256) {
210 GLubyte
*newImage
= malloc(256 * 256 * 4);
211 gluScaleImage(format
, width
, height
, GL_UNSIGNED_BYTE
, image
,
212 256, 256, GL_UNSIGNED_BYTE
, newImage
);
216 printf("Using GL_SGIS_generate_mipmap\n");
217 glTexParameteri(GL_TEXTURE_2D
, GL_GENERATE_MIPMAP_SGIS
, GL_TRUE
);
218 glTexImage2D(GL_TEXTURE_2D
, 0, format
, 256, 256, 0,
219 format
, GL_UNSIGNED_BYTE
, image
);
222 /* make sure mipmap was really generated correctly */
223 width
= height
= 256;
224 for (i
= 0; i
< 9; i
++) {
226 glGetTexLevelParameteriv(GL_TEXTURE_2D
, i
, GL_TEXTURE_WIDTH
, &w
);
227 glGetTexLevelParameteriv(GL_TEXTURE_2D
, i
, GL_TEXTURE_HEIGHT
, &h
);
228 printf("Level %d size: %d x %d\n", i
, w
, h
);
236 else if (!LoadRGBMipmaps(TEXTURE_FILE
, GL_RGB
)) {
237 printf("Error: could not load texture image %s\n", TEXTURE_FILE
);
241 /* mipmapping required for this extension */
242 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR_MIPMAP_LINEAR
);
243 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
244 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
246 glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS_EXT
, &maxBias
);
247 printf("LOD bias range: [%g, %g]\n", -maxBias
, maxBias
);
248 BiasMin
= -100 * maxBias
;
249 BiasMax
= 100 * maxBias
;
251 /* Since we have (about) 8 mipmap levels, no need to bias beyond
252 * the range [-1, +8].
261 int main( int argc
, char *argv
[] )
263 glutInit( &argc
, argv
);
264 glutInitWindowPosition( 0, 0 );
265 glutInitWindowSize( 350, 350 );
266 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
267 glutCreateWindow( "Bug #3195 Test" );
269 glutReshapeFunc( Reshape
);
270 glutKeyboardFunc( Key
);
271 glutSpecialFunc( SpecialKey
);
272 glutDisplayFunc( Display
);