Merge branch 'nouveau-import'
[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 unsigned i;
75 static const GLenum pnames[] = {
76 GL_TEXTURE_RED_SIZE,
77 GL_TEXTURE_GREEN_SIZE,
78 GL_TEXTURE_BLUE_SIZE,
79 GL_TEXTURE_ALPHA_SIZE,
80 GL_TEXTURE_LUMINANCE_SIZE,
81 GL_TEXTURE_INTENSITY_SIZE,
82 GL_TEXTURE_BORDER,
83 GL_TEXTURE_INTERNAL_FORMAT,
84 GL_TEXTURE_WIDTH,
85 GL_TEXTURE_HEIGHT,
86 GL_TEXTURE_DEPTH,
87 ~0
88 };
89
90
91 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
92 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
93
94 printf("\nThis program should log some data about a texture and exit.\n");
95 printf("This is a regression test for bug #3050. If the bug still\n");
96 printf("exists, a GLX protocol error will be generated.\n");
97 printf("https://bugs.freedesktop.org/show_bug.cgi?id=3050\n\n");
98
99
100 if ( ! glutExtensionSupported( "GL_NV_texture_rectangle" )
101 && ! glutExtensionSupported( "GL_EXT_texture_rectangle" )
102 && ! glutExtensionSupported( "GL_ARB_texture_rectangle" ) ) {
103 printf( "This test requires one of GL_ARB_texture_rectangle, GL_EXT_texture_rectangle,\n"
104 "or GL_NV_texture_rectangle be supported\n." );
105 exit( 1 );
106 }
107
108
109 glBindTexture( GL_TEXTURE_RECTANGLE_NV, 1 );
110 glTexImage2D( GL_PROXY_TEXTURE_RECTANGLE_NV, 0, GL_RGBA, 8, 8, 0,
111 GL_RGBA, GL_UNSIGNED_BYTE, NULL );
112
113 for ( i = 0 ; pnames[i] != ~0 ; i++ ) {
114 GLint param_i;
115 GLfloat param_f;
116 GLenum err;
117
118 glGetTexLevelParameteriv( GL_PROXY_TEXTURE_RECTANGLE_NV, 0, pnames[i], & param_i );
119 err = glGetError();
120
121 if ( err ) {
122 printf("glGetTexLevelParameteriv(GL_PROXY_TEXTURE_RECTANGLE_NV, 0, 0x%04x, & param) generated a GL\n"
123 "error of 0x%04x!",
124 pnames[i], err );
125 exit( 1 );
126 }
127 else {
128 printf("glGetTexLevelParameteriv(GL_PROXY_TEXTURE_RECTANGLE_NV, 0, 0x%04x, & param) = 0x%04x\n",
129 pnames[i], param_i );
130 }
131
132
133 glGetTexLevelParameterfv( GL_PROXY_TEXTURE_RECTANGLE_NV, 0, pnames[i], & param_f );
134 err = glGetError();
135
136 if ( err ) {
137 printf("glGetTexLevelParameterfv(GL_PROXY_TEXTURE_RECTANGLE_NV, 0, 0x%04x, & param) generated a GL\n"
138 "error of 0x%04x!\n",
139 pnames[i], err );
140 exit( 1 );
141 }
142 else {
143 printf("glGetTexLevelParameterfv(GL_PROXY_TEXTURE_RECTANGLE_NV, 0, 0x%04x, & param) = %.1f (0x%04x)\n",
144 pnames[i], param_f, (GLint) param_f );
145 }
146 }
147 }
148
149
150 int main( int argc, char *argv[] )
151 {
152 glutInit( &argc, argv );
153 glutInitWindowPosition( 0, 0 );
154 glutInitWindowSize( Width, Height );
155 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
156 glutCreateWindow( "Bug #3050 Test" );
157 glutReshapeFunc( Reshape );
158 glutKeyboardFunc( Key );
159 glutDisplayFunc( Display );
160 Init();
161 return 0;
162 }