2 * (C) Copyright IBM Corporation 2006
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:
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
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 * IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
26 * \file prog_parameter.c
28 * Test various aspects of setting (and getting) low-level program parameters.
29 * This is primarilly intended as a test for GL_EXT_gpu_program_parameters,
30 * but it turns out that it hits some other functionality along the way.
32 * \author Ian Romanick <idr@us.ibm.com>
41 #ifndef GL_EXT_gpu_program_parameters
42 typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERS4FVEXTPROC
)(GLenum
,
43 GLuint
, GLsizei
, const GLfloat
*);
44 typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERS4FVEXTPROC
)(GLenum
,
45 GLuint
, GLsizei
, const GLfloat
*);
48 static PFNGLPROGRAMLOCALPARAMETER4FVARBPROC program_local_parameter4fv
= NULL
;
49 static PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC get_program_local_parameterfv
= NULL
;
50 static PFNGLPROGRAMENVPARAMETER4FVARBPROC program_env_parameter4fv
= NULL
;
51 static PFNGLGETPROGRAMENVPARAMETERFVARBPROC get_program_env_parameterfv
= NULL
;
52 static PFNGLBINDPROGRAMARBPROC bind_program
= NULL
;
53 static PFNGLGETPROGRAMIVARBPROC get_program
= NULL
;
55 static PFNGLPROGRAMLOCALPARAMETERS4FVEXTPROC program_local_parameters4fv
= NULL
;
56 static PFNGLPROGRAMENVPARAMETERS4FVEXTPROC program_env_parameters4fv
= NULL
;
58 static int Width
= 400;
59 static int Height
= 200;
60 static const GLfloat Near
= 5.0, Far
= 25.0;
63 static void Display( void )
68 static void Idle( void )
73 static void Visible( int vis
)
75 if ( vis
== GLUT_VISIBLE
) {
82 static void Reshape( int width
, int height
)
84 GLfloat ar
= (float) width
/ (float) height
;
87 glViewport( 0, 0, width
, height
);
88 glMatrixMode( GL_PROJECTION
);
90 glFrustum( -ar
, ar
, -1.0, 1.0, Near
, Far
);
94 static void Key( unsigned char key
, int x
, int y
)
107 static int set_parameter_batch( GLsizei count
, GLfloat
* param
,
109 PFNGLPROGRAMLOCALPARAMETER4FVARBPROC set_parameter
,
110 PFNGLPROGRAMLOCALPARAMETERS4FVEXTPROC set_parameters
,
111 PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC get_parameter
118 for ( i
= 0 ; i
< (4 * count
) ; i
++ ) {
119 param
[i
] = (GLfloat
) rand() / (GLfloat
) rand();
122 /* Try using the "classic" interface.
124 printf("Testing glProgram%sParameter4fvARB (count = %u)...\n", name
, count
);
125 for ( i
= 0 ; i
< count
; i
++ ) {
126 (*set_parameter
)(GL_VERTEX_PROGRAM_ARB
, i
, & param
[i
* 4]);
129 for ( i
= 0 ; i
< count
; i
++ ) {
132 (*get_parameter
)(GL_VERTEX_PROGRAM_ARB
, i
, temp
);
134 if ( (temp
[0] != param
[(i
* 4) + 0])
135 || (temp
[1] != param
[(i
* 4) + 1])
136 || (temp
[2] != param
[(i
* 4) + 2])
137 || (temp
[3] != param
[(i
* 4) + 3]) ) {
138 printf("Mismatch in glProgram%sParameter4fvARB index %u!\n", name
, i
);
139 printf("Got { %f, %f, %f, %f }, expected { %f, %f, %f, %f }!\n",
142 param
[(i
* 4) + 0], param
[(i
* 4) + 1],
143 param
[(i
* 4) + 2], param
[(i
* 4) + 3]);
150 if ( set_parameters
== NULL
) {
155 for ( i
= 0 ; i
< (4 * count
) ; i
++ ) {
156 param
[i
] = (GLfloat
) rand() / (GLfloat
) rand();
159 printf("Testing glProgram%sParameters4fvEXT (count = %u)...\n", name
, count
);
160 (*set_parameters
)(GL_VERTEX_PROGRAM_ARB
, 0, count
, param
);
162 for ( i
= 0 ; i
< count
; i
++ ) {
165 (*get_parameter
)(GL_VERTEX_PROGRAM_ARB
, i
, temp
);
167 if ( (temp
[0] != param
[(i
* 4) + 0])
168 || (temp
[1] != param
[(i
* 4) + 1])
169 || (temp
[2] != param
[(i
* 4) + 2])
170 || (temp
[3] != param
[(i
* 4) + 3]) ) {
171 printf("Mismatch in glProgram%sParameters4fvEXT index %u!\n", name
, i
);
172 printf("Got { %f, %f, %f, %f }, expected { %f, %f, %f, %f }!\n",
175 param
[(i
* 4) + 0], param
[(i
* 4) + 1],
176 param
[(i
* 4) + 2], param
[(i
* 4) + 3]);
187 static void Init( void )
189 const char * const ver_string
= (const char * const)
190 glGetString( GL_VERSION
);
193 GLint max_program_env_parameters
;
194 GLint max_program_local_parameters
;
198 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
199 printf("GL_VERSION = %s\n\n", ver_string
);
201 if ( !glutExtensionSupported("GL_ARB_vertex_program") ) {
202 printf("Sorry, this program requires GL_ARB_vertex_program\n");
207 program_local_parameter4fv
= (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC
) glutGetProcAddress( "glProgramLocalParameter4fvARB" );
208 program_env_parameter4fv
= (PFNGLPROGRAMENVPARAMETER4FVARBPROC
) glutGetProcAddress( "glProgramEnvParameter4fvARB" );
210 get_program_local_parameterfv
= (PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC
) glutGetProcAddress( "glGetProgramLocalParameterfvARB" );
211 get_program_env_parameterfv
= (PFNGLGETPROGRAMENVPARAMETERFVARBPROC
) glutGetProcAddress( "glGetProgramEnvParameterfvARB" );
213 bind_program
= (PFNGLBINDPROGRAMARBPROC
) glutGetProcAddress( "glBindProgramARB" );
214 get_program
= (PFNGLGETPROGRAMIVARBPROC
) glutGetProcAddress( "glGetProgramivARB" );
216 if ( glutExtensionSupported("GL_EXT_gpu_program_parameters") ) {
217 printf("GL_EXT_gpu_program_parameters available, testing that path.\n");
219 program_local_parameters4fv
= (PFNGLPROGRAMLOCALPARAMETERS4FVEXTPROC
) glutGetProcAddress( "glProgramLocalParameters4fvEXT" );
220 program_env_parameters4fv
= (PFNGLPROGRAMENVPARAMETERS4FVEXTPROC
) glutGetProcAddress( "glProgramEnvParameters4fvEXT" );
223 printf("GL_EXT_gpu_program_parameters not available.\n");
225 program_local_parameters4fv
= NULL
;
226 program_env_parameters4fv
= NULL
;
231 /* Since the test sets program local parameters, a program must be bound.
232 * Program source, however, is not needed.
234 (*bind_program
)(GL_VERTEX_PROGRAM_ARB
, 1);
237 (*get_program
)(GL_VERTEX_PROGRAM_ARB
, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB
,
238 & max_program_env_parameters
);
240 params
= malloc(max_program_env_parameters
* 4 * sizeof(GLfloat
));
242 for (i
= 0; i
< max_program_env_parameters
* 4; i
++) {
246 pass
&= set_parameter_batch(max_program_env_parameters
, params
, "Env",
247 program_env_parameter4fv
,
248 program_env_parameters4fv
,
249 get_program_env_parameterfv
);
252 (*get_program
)(GL_VERTEX_PROGRAM_ARB
, GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB
,
253 & max_program_local_parameters
);
255 if (max_program_local_parameters
> max_program_env_parameters
) {
256 params
= realloc(params
,
257 max_program_local_parameters
* 4 * sizeof(GLfloat
));
260 pass
&= set_parameter_batch(max_program_local_parameters
, params
, "Local",
261 program_local_parameter4fv
,
262 program_local_parameters4fv
,
263 get_program_local_parameterfv
);
276 int main( int argc
, char *argv
[] )
278 glutInit( &argc
, argv
);
279 glutInitWindowPosition( 0, 0 );
280 glutInitWindowSize( Width
, Height
);
281 glutInitDisplayMode( GLUT_RGB
);
282 glutCreateWindow( "Program Parameters Test" );
284 glutReshapeFunc( Reshape
);
285 glutKeyboardFunc( Key
);
286 glutDisplayFunc( Display
);
287 glutVisibilityFunc( Visible
);