Test case for bugzilla #3050.
[mesa.git] / progs / tests / bug_3050.c
1 /*
2 * (C) Copyright IBM Corporation 2006
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /**
26 * \file bug_3050.c
27 *
28 * Simple regression test for bug #3050. Create a texture and make a few
29 * calls to \c glGetTexLevelParameteriv. If the bug still exists, trying
30 * to get \c GL_TEXTURE_WITDH will cause a protocol error.
31 *
32 * This test \b only applies to indirect-rendering. This may mean that the
33 * test needs to be run with the environment variable \c LIBGL_ALWAYS_INDIRECT
34 * set to a non-zero value.
35 *
36 * \author Ian Romanick <idr@us.ibm.com>
37 */
38
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <GL/glut.h>
43
44 static int Width = 400;
45 static int Height = 200;
46 static const GLfloat Near = 5.0, Far = 25.0;
47
48
49 static void Display( void )
50 {
51 }
52
53
54 static void Reshape( int width, int height )
55 {
56 }
57
58
59 static void Key( unsigned char key, int x, int y )
60 {
61 (void) x;
62 (void) y;
63 switch (key) {
64 case 27:
65 exit(0);
66 break;
67 }
68 glutPostRedisplay();
69 }
70
71
72 static void Init( void )
73 {
74 GLint temp[ 256 ];
75 unsigned i;
76 static const GLenum pnames[] = {
77 GL_TEXTURE_RED_SIZE,
78 GL_TEXTURE_GREEN_SIZE,
79 GL_TEXTURE_BLUE_SIZE,
80 GL_TEXTURE_ALPHA_SIZE,
81 GL_TEXTURE_LUMINANCE_SIZE,
82 GL_TEXTURE_INTENSITY_SIZE,
83 GL_TEXTURE_BORDER,
84 GL_TEXTURE_INTERNAL_FORMAT,
85 GL_TEXTURE_WIDTH,
86 GL_TEXTURE_HEIGHT,
87 GL_TEXTURE_DEPTH,
88 ~0
89 };
90
91
92 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
93 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
94
95 printf("\nThis program should log some data about a texture and exit.\n");
96 printf("This is a regression test for bug #3050. If the bug still\n");
97 printf("exists, a GLX protocol error will be generated.\n");
98 printf("https://bugs.freedesktop.org/show_bug.cgi?id=3050\n\n");
99
100
101 if ( ! glutExtensionSupported( "GL_NV_texture_rectangle" )
102 && ! glutExtensionSupported( "GL_EXT_texture_rectangle" )
103 && ! glutExtensionSupported( "GL_ARB_texture_rectangle" ) ) {
104 printf( "This test requires one of GL_ARB_texture_rectangle, GL_EXT_texture_rectangle,\n"
105 "or GL_NV_texture_rectangle be supported\n." );
106 exit( 1 );
107 }
108
109
110 (void) memset( temp, 0x00, sizeof( temp ) );
111 glBindTexture( GL_PROXY_TEXTURE_RECTANGLE_NV, 1 );
112 glTexImage2D( GL_PROXY_TEXTURE_RECTANGLE_NV, 0, GL_RGBA, 8, 8, 0,
113 GL_RGBA, GL_UNSIGNED_BYTE, temp );
114
115 for ( i = 0 ; pnames[i] != ~0 ; i++ ) {
116 GLint param_i;
117 GLfloat param_f;
118 GLenum err;
119
120 glGetTexLevelParameteriv( GL_PROXY_TEXTURE_RECTANGLE_NV, 0, pnames[i], & param_i );
121 err = glGetError();
122
123 if ( err ) {
124 printf("glGetTexLevelParameteriv(GL_PROXY_TEXTURE_RECTANGLE_NV, 0, 0x%04x, & param) generated a GL\n"
125 "error of 0x%04x!",
126 pnames[i], err );
127 exit( 1 );
128 }
129 else {
130 printf("glGetTexLevelParameteriv(GL_PROXY_TEXTURE_RECTANGLE_NV, 0, 0x%04x, & param) = 0x%04x\n",
131 pnames[i], param_i );
132 }
133
134
135 glGetTexLevelParameterfv( GL_PROXY_TEXTURE_RECTANGLE_NV, 0, pnames[i], & param_f );
136 err = glGetError();
137
138 if ( err ) {
139 printf("glGetTexLevelParameterfv(GL_PROXY_TEXTURE_RECTANGLE_NV, 0, 0x%04x, & param) generated a GL\n"
140 "error of 0x%04x!",
141 pnames[i], err );
142 exit( 1 );
143 }
144 else {
145 printf("glGetTexLevelParameterfv(GL_PROXY_TEXTURE_RECTANGLE_NV, 0, 0x%04x, & param) = %.1f (0x%04x)\n",
146 pnames[i], param_f, (GLint) param_f );
147 }
148 }
149 }
150
151
152 int main( int argc, char *argv[] )
153 {
154 glutInit( &argc, argv );
155 glutInitWindowPosition( 0, 0 );
156 glutInitWindowSize( Width, Height );
157 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
158 glutCreateWindow( "Bug #3050 Test" );
159 glutReshapeFunc( Reshape );
160 glutKeyboardFunc( Key );
161 glutDisplayFunc( Display );
162 Init();
163 return 0;
164 }