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>
40 #ifndef GL_EXT_gpu_program_parameters
41 typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERS4FVEXTPROC
)(GLenum
,
42 GLuint
, GLsizei
, const GLfloat
*);
43 typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERS4FVEXTPROC
)(GLenum
,
44 GLuint
, GLsizei
, const GLfloat
*);
47 static PFNGLPROGRAMLOCALPARAMETER4FVARBPROC program_local_parameter4fv
= NULL
;
48 static PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC get_program_local_parameterfv
= NULL
;
49 static PFNGLPROGRAMENVPARAMETER4FVARBPROC program_env_parameter4fv
= NULL
;
50 static PFNGLGETPROGRAMENVPARAMETERFVARBPROC get_program_env_parameterfv
= NULL
;
51 static PFNGLBINDPROGRAMARBPROC bind_program
= NULL
;
52 static PFNGLGETPROGRAMIVARBPROC get_program
= NULL
;
54 static PFNGLPROGRAMLOCALPARAMETERS4FVEXTPROC program_local_parameters4fv
= NULL
;
55 static PFNGLPROGRAMENVPARAMETERS4FVEXTPROC program_env_parameters4fv
= NULL
;
57 static int Width
= 400;
58 static int Height
= 200;
59 static const GLfloat Near
= 5.0, Far
= 25.0;
62 static void Display( void )
67 static void Idle( void )
72 static void Visible( int vis
)
74 if ( vis
== GLUT_VISIBLE
) {
81 static void Reshape( int width
, int height
)
83 GLfloat ar
= (float) width
/ (float) height
;
86 glViewport( 0, 0, width
, height
);
87 glMatrixMode( GL_PROJECTION
);
89 glFrustum( -ar
, ar
, -1.0, 1.0, Near
, Far
);
93 static void Key( unsigned char key
, int x
, int y
)
106 static int set_parameter_batch( GLsizei count
, GLfloat
* param
,
108 PFNGLPROGRAMLOCALPARAMETER4FVARBPROC set_parameter
,
109 PFNGLPROGRAMLOCALPARAMETERS4FVEXTPROC set_parameters
,
110 PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC get_parameter
117 for ( i
= 0 ; i
< (4 * count
) ; i
++ ) {
118 param
[i
] = (GLfloat
) random() / (GLfloat
) random();
121 /* Try using the "classic" interface.
123 printf("Testing glProgram%sParameter4fvARB (count = %u)...\n", name
, count
);
124 for ( i
= 0 ; i
< count
; i
++ ) {
125 (*set_parameter
)(GL_VERTEX_PROGRAM_ARB
, i
, & param
[i
* 4]);
128 for ( i
= 0 ; i
< count
; i
++ ) {
131 (*get_parameter
)(GL_VERTEX_PROGRAM_ARB
, i
, temp
);
133 if ( (temp
[0] != param
[(i
* 4) + 0])
134 || (temp
[1] != param
[(i
* 4) + 1])
135 || (temp
[2] != param
[(i
* 4) + 2])
136 || (temp
[3] != param
[(i
* 4) + 3]) ) {
137 printf("Mismatch in glProgram%sParameter4fvARB index %u!\n", name
, i
);
138 printf("Got { %f, %f, %f, %f }, expected { %f, %f, %f, %f }!\n",
141 param
[(i
* 4) + 0], param
[(i
* 4) + 1],
142 param
[(i
* 4) + 2], param
[(i
* 4) + 3]);
149 if ( set_parameters
== NULL
) {
154 for ( i
= 0 ; i
< (4 * count
) ; i
++ ) {
155 param
[i
] = (GLfloat
) random() / (GLfloat
) random();
158 printf("Testing glProgram%sParameters4fvEXT (count = %u)...\n", name
, count
);
159 (*set_parameters
)(GL_VERTEX_PROGRAM_ARB
, 0, count
, param
);
161 for ( i
= 0 ; i
< count
; i
++ ) {
164 (*get_parameter
)(GL_VERTEX_PROGRAM_ARB
, i
, temp
);
166 if ( (temp
[0] != param
[(i
* 4) + 0])
167 || (temp
[1] != param
[(i
* 4) + 1])
168 || (temp
[2] != param
[(i
* 4) + 2])
169 || (temp
[3] != param
[(i
* 4) + 3]) ) {
170 printf("Mismatch in glProgram%sParameters4fvEXT index %u!\n", name
, i
);
171 printf("Got { %f, %f, %f, %f }, expected { %f, %f, %f, %f }!\n",
174 param
[(i
* 4) + 0], param
[(i
* 4) + 1],
175 param
[(i
* 4) + 2], param
[(i
* 4) + 3]);
186 static void Init( void )
188 const char * const ver_string
= (const char * const)
189 glGetString( GL_VERSION
);
192 GLint max_program_env_parameters
;
193 GLint max_program_local_parameters
;
196 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
197 printf("GL_VERSION = %s\n\n", ver_string
);
199 if ( !glutExtensionSupported("GL_ARB_vertex_program") ) {
200 printf("Sorry, this program requires GL_ARB_vertex_program\n");
205 program_local_parameter4fv
= glutGetProcAddress( "glProgramLocalParameter4fvARB" );
206 program_env_parameter4fv
= glutGetProcAddress( "glProgramEnvParameter4fvARB" );
208 get_program_local_parameterfv
= glutGetProcAddress( "glGetProgramLocalParameterfvARB" );
209 get_program_env_parameterfv
= glutGetProcAddress( "glGetProgramEnvParameterfvARB" );
211 bind_program
= glutGetProcAddress( "glBindProgramARB" );
212 get_program
= glutGetProcAddress( "glGetProgramivARB" );
214 if ( glutExtensionSupported("GL_EXT_gpu_program_parameters") ) {
215 printf("GL_EXT_gpu_program_parameters available, testing that path.\n");
217 program_local_parameters4fv
= glutGetProcAddress( "glProgramLocalParameters4fvEXT" );
218 program_env_parameters4fv
= glutGetProcAddress( "glProgramEnvParameters4fvEXT" );
221 printf("GL_EXT_gpu_program_parameters not available.\n");
223 program_local_parameters4fv
= NULL
;
224 program_env_parameters4fv
= NULL
;
229 /* Since the test sets program local parameters, a program must be bound.
230 * Program source, however, is not needed.
232 (*bind_program
)(GL_VERTEX_PROGRAM_ARB
, 1);
235 (*get_program
)(GL_VERTEX_PROGRAM_ARB
, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB
,
236 & max_program_env_parameters
);
238 params
= malloc(max_program_env_parameters
* 4 * sizeof(GLfloat
));
240 pass
&= set_parameter_batch(max_program_env_parameters
, params
, "Env",
241 program_env_parameter4fv
,
242 program_env_parameters4fv
,
243 get_program_env_parameterfv
);
246 (*get_program
)(GL_VERTEX_PROGRAM_ARB
, GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB
,
247 & max_program_local_parameters
);
249 if (max_program_local_parameters
> max_program_env_parameters
) {
250 params
= realloc(params
,
251 max_program_local_parameters
* 4 * sizeof(GLfloat
));
254 pass
&= set_parameter_batch(max_program_local_parameters
, params
, "Local",
255 program_local_parameter4fv
,
256 program_local_parameters4fv
,
257 get_program_local_parameterfv
);
270 int main( int argc
, char *argv
[] )
272 glutInit( &argc
, argv
);
273 glutInitWindowPosition( 0, 0 );
274 glutInitWindowSize( Width
, Height
);
275 glutInitDisplayMode( GLUT_RGB
);
276 glutCreateWindow( "Program Parameters Test" );
277 glutReshapeFunc( Reshape
);
278 glutKeyboardFunc( Key
);
279 glutDisplayFunc( Display
);
280 glutVisibilityFunc( Visible
);