piglit-shader-gl.c 9.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Copyright © 2010 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

24 25 26 27
#ifndef USE_OPENGL
#	error USE_OPENGL is undefined
#endif

28 29 30 31 32 33 34
#if defined(_MSC_VER)
#include <windows.h>
#endif

#include "piglit-util.h"

PFNGLATTACHSHADERPROC piglit_AttachShader = NULL;
Ian Romanick's avatar
Ian Romanick committed
35
PFNGLBINDATTRIBLOCATIONPROC piglit_BindAttribLocation = NULL;
36 37 38 39 40
PFNGLCOMPILESHADERPROC piglit_CompileShader = NULL;
PFNGLCREATEPROGRAMPROC piglit_CreateProgram = NULL;
PFNGLCREATESHADERPROC piglit_CreateShader = NULL;
PFNGLDELETEPROGRAMPROC piglit_DeleteProgram = NULL;
PFNGLDELETESHADERPROC piglit_DeleteShader = NULL;
41
PFNGLGETACTIVEUNIFORMPROC piglit_GetActiveUniform = NULL;
42
PFNGLGETATTRIBLOCATIONPROC piglit_GetAttribLocation = NULL;
43 44 45 46 47 48 49 50
PFNGLGETPROGRAMINFOLOGPROC piglit_GetProgramInfoLog = NULL;
PFNGLGETPROGRAMIVPROC piglit_GetProgramiv = NULL;
PFNGLGETSHADERINFOLOGPROC piglit_GetShaderInfoLog = NULL;
PFNGLGETSHADERIVPROC piglit_GetShaderiv = NULL;
PFNGLGETUNIFORMLOCATIONPROC piglit_GetUniformLocation = NULL;
PFNGLLINKPROGRAMPROC piglit_LinkProgram = NULL;
PFNGLSHADERSOURCEPROC piglit_ShaderSource = NULL;
PFNGLUSEPROGRAMPROC piglit_UseProgram = NULL;
51 52 53 54
PFNGLUNIFORM1FPROC piglit_Uniform1f = NULL;
PFNGLUNIFORM2FPROC piglit_Uniform2f = NULL;
PFNGLUNIFORM3FPROC piglit_Uniform3f = NULL;
PFNGLUNIFORM4FPROC piglit_Uniform4f = NULL;
55 56 57 58 59
PFNGLUNIFORM1FVPROC piglit_Uniform1fv = NULL;
PFNGLUNIFORM2FVPROC piglit_Uniform2fv = NULL;
PFNGLUNIFORM3FVPROC piglit_Uniform3fv = NULL;
PFNGLUNIFORM4FVPROC piglit_Uniform4fv = NULL;
PFNGLUNIFORM1IPROC piglit_Uniform1i = NULL;
60 61 62 63
PFNGLUNIFORM2IPROC piglit_Uniform2i = NULL;
PFNGLUNIFORM3IPROC piglit_Uniform3i = NULL;
PFNGLUNIFORM4IPROC piglit_Uniform4i = NULL;
PFNGLUNIFORM1IVPROC piglit_Uniform1iv = NULL;
64 65 66
PFNGLUNIFORM2IVPROC piglit_Uniform2iv = NULL;
PFNGLUNIFORM3IVPROC piglit_Uniform3iv = NULL;
PFNGLUNIFORM4IVPROC piglit_Uniform4iv = NULL;
67 68 69 70 71 72 73 74
PFNGLUNIFORM1UIPROC piglit_Uniform1ui = NULL;
PFNGLUNIFORM2UIPROC piglit_Uniform2ui = NULL;
PFNGLUNIFORM3UIPROC piglit_Uniform3ui = NULL;
PFNGLUNIFORM4UIPROC piglit_Uniform4ui = NULL;
PFNGLUNIFORM1UIVPROC piglit_Uniform1uiv = NULL;
PFNGLUNIFORM2UIVPROC piglit_Uniform2uiv = NULL;
PFNGLUNIFORM3UIVPROC piglit_Uniform3uiv = NULL;
PFNGLUNIFORM4UIVPROC piglit_Uniform4uiv = NULL;
75 76
PFNGLUNIFORMMATRIX2FVPROC piglit_UniformMatrix2fv = NULL;
PFNGLUNIFORMMATRIX3FVPROC piglit_UniformMatrix3fv = NULL;
77
PFNGLUNIFORMMATRIX4FVPROC piglit_UniformMatrix4fv = NULL;
Ian Romanick's avatar
Ian Romanick committed
78
PFNGLGETUNIFORMFVPROC piglit_GetUniformfv = NULL;
79 80 81
PFNGLVERTEXATTRIBPOINTERPROC piglit_VertexAttribPointer = NULL;
PFNGLENABLEVERTEXATTRIBARRAYPROC piglit_EnableVertexAttribArray = NULL;
PFNGLDISABLEVERTEXATTRIBARRAYPROC piglit_DisableVertexAttribArray = NULL;
82

83 84 85 86 87 88 89
PFNGLUNIFORMMATRIX2X3FVPROC piglit_UniformMatrix2x3fv = NULL;
PFNGLUNIFORMMATRIX2X4FVPROC piglit_UniformMatrix2x4fv = NULL;
PFNGLUNIFORMMATRIX3X2FVPROC piglit_UniformMatrix3x2fv = NULL;
PFNGLUNIFORMMATRIX3X4FVPROC piglit_UniformMatrix3x4fv = NULL;
PFNGLUNIFORMMATRIX4X2FVPROC piglit_UniformMatrix4x2fv = NULL;
PFNGLUNIFORMMATRIX4X3FVPROC piglit_UniformMatrix4x3fv = NULL;

90 91 92 93
static void
init_functions_from_core(void)
{
	piglit_AttachShader = glAttachShader;
Ian Romanick's avatar
Ian Romanick committed
94
	piglit_BindAttribLocation = glBindAttribLocation;
95 96 97 98 99
	piglit_CompileShader = glCompileShader;
	piglit_CreateProgram = glCreateProgram;
	piglit_CreateShader = glCreateShader;
	piglit_DeleteProgram = glDeleteProgram;
	piglit_DeleteShader = glDeleteShader;
100
	piglit_GetActiveUniform = glGetActiveUniform;
101
	piglit_GetAttribLocation = glGetAttribLocation;
102 103 104 105 106 107 108 109
	piglit_GetProgramInfoLog = glGetProgramInfoLog;
	piglit_GetProgramiv = glGetProgramiv;
	piglit_GetShaderInfoLog = glGetShaderInfoLog;
	piglit_GetShaderiv = glGetShaderiv;
	piglit_GetUniformLocation = glGetUniformLocation;
	piglit_LinkProgram = glLinkProgram;
	piglit_ShaderSource = glShaderSource;
	piglit_UseProgram = glUseProgram;
110 111 112 113
	piglit_Uniform1f = glUniform1f;
	piglit_Uniform2f = glUniform2f;
	piglit_Uniform3f = glUniform3f;
	piglit_Uniform4f = glUniform4f;
114 115 116 117 118
	piglit_Uniform1fv = glUniform1fv;
	piglit_Uniform2fv = glUniform2fv;
	piglit_Uniform3fv = glUniform3fv;
	piglit_Uniform4fv = glUniform4fv;
	piglit_Uniform1i = glUniform1i;
119 120 121 122
	piglit_Uniform2i = glUniform2i;
	piglit_Uniform3i = glUniform3i;
	piglit_Uniform4i = glUniform4i;
	piglit_Uniform1iv = glUniform1iv;
123 124 125
	piglit_Uniform2iv = glUniform2iv;
	piglit_Uniform3iv = glUniform3iv;
	piglit_Uniform4iv = glUniform4iv;
126 127 128 129 130 131 132 133
	piglit_Uniform1ui = glUniform1ui;
	piglit_Uniform2ui = glUniform2ui;
	piglit_Uniform3ui = glUniform3ui;
	piglit_Uniform4ui = glUniform4ui;
	piglit_Uniform1uiv = glUniform1uiv;
	piglit_Uniform2uiv = glUniform2uiv;
	piglit_Uniform3uiv = glUniform3uiv;
	piglit_Uniform4uiv = glUniform4uiv;
134 135
	piglit_UniformMatrix2fv = glUniformMatrix2fv;
	piglit_UniformMatrix3fv = glUniformMatrix3fv;
136
	piglit_UniformMatrix4fv = glUniformMatrix4fv;
Ian Romanick's avatar
Ian Romanick committed
137
	piglit_GetUniformfv = glGetUniformfv;
138 139 140
	piglit_VertexAttribPointer = glVertexAttribPointer;
	piglit_EnableVertexAttribArray = glEnableVertexAttribArray;
	piglit_DisableVertexAttribArray = glDisableVertexAttribArray;
141 142 143 144 145 146 147 148 149

	/* These are part of OpenGL 2.1.
	 */
	piglit_UniformMatrix2x3fv = glUniformMatrix2x3fv;
	piglit_UniformMatrix2x4fv = glUniformMatrix2x4fv;
	piglit_UniformMatrix3x2fv = glUniformMatrix3x2fv;
	piglit_UniformMatrix3x4fv = glUniformMatrix3x4fv;
	piglit_UniformMatrix4x2fv = glUniformMatrix4x2fv;
	piglit_UniformMatrix4x3fv = glUniformMatrix4x3fv;
150 151 152 153 154 155
}

static void
init_functions_from_extension(void)
{
	piglit_AttachShader = glAttachObjectARB;
Ian Romanick's avatar
Ian Romanick committed
156
	piglit_BindAttribLocation = glBindAttribLocationARB;
157 158 159 160 161
	piglit_CompileShader = glCompileShaderARB;
	piglit_CreateProgram = glCreateProgramObjectARB;
	piglit_CreateShader = glCreateShaderObjectARB;
	piglit_DeleteProgram = glDeleteObjectARB;
	piglit_DeleteShader = glDeleteObjectARB;
162
	piglit_GetActiveUniform = glGetActiveUniformARB;
163
	piglit_GetAttribLocation = glGetAttribLocationARB;
164 165 166 167 168 169 170 171
	piglit_GetProgramInfoLog = glGetInfoLogARB;
	piglit_GetProgramiv = glGetObjectParameterivARB;
	piglit_GetShaderInfoLog = glGetInfoLogARB;
	piglit_GetShaderiv = glGetObjectParameterivARB;
	piglit_GetUniformLocation = glGetUniformLocationARB;
	piglit_LinkProgram = glLinkProgramARB;
	piglit_ShaderSource = glShaderSourceARB;
	piglit_UseProgram = glUseProgramObjectARB;
172 173 174 175
	piglit_Uniform1f = glUniform1fARB;
	piglit_Uniform2f = glUniform2fARB;
	piglit_Uniform3f = glUniform3fARB;
	piglit_Uniform4f = glUniform4fARB;
176 177 178 179 180
	piglit_Uniform1fv = glUniform1fvARB;
	piglit_Uniform2fv = glUniform2fvARB;
	piglit_Uniform3fv = glUniform3fvARB;
	piglit_Uniform4fv = glUniform4fvARB;
	piglit_Uniform1i = glUniform1iARB;
181 182 183
	piglit_Uniform2iv = glUniform2ivARB;
	piglit_Uniform3iv = glUniform3ivARB;
	piglit_Uniform4iv = glUniform4ivARB;
184 185
	piglit_UniformMatrix2fv = glUniformMatrix2fvARB;
	piglit_UniformMatrix3fv = glUniformMatrix3fvARB;
186
	piglit_UniformMatrix4fv = glUniformMatrix4fvARB;
Ian Romanick's avatar
Ian Romanick committed
187
	piglit_GetUniformfv = glGetUniformfvARB;
188 189 190
	piglit_VertexAttribPointer = glVertexAttribPointerARB;
	piglit_EnableVertexAttribArray = glEnableVertexAttribArrayARB;
	piglit_DisableVertexAttribArray = glDisableVertexAttribArrayARB;
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
}

void
piglit_require_GLSL(void)
{
	if (GLEW_VERSION_2_0) {
		init_functions_from_core();
	} else if (GLEW_ARB_shader_objects && GLEW_ARB_shading_language_100) {
		init_functions_from_extension();
	} else {
		printf("GLSL not supported.\n");
		piglit_report_result(PIGLIT_SKIP);
		exit(1);
	}
}

207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
void
piglit_require_GLSL_version(int version)
{
	bool es;
	int major, minor;

	piglit_require_GLSL();

	piglit_get_glsl_version(&es, &major, &minor);

	if (es || 100 * major + minor < version) {
		printf("GLSL %d.%d not supported.\n",
		       version / 100, version % 100);
		piglit_report_result(PIGLIT_SKIP);
		exit(1);
	}
}

225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
void
piglit_require_vertex_shader(void)
{
	if (GLEW_VERSION_2_0) {
		init_functions_from_core();
	} else if (GLEW_ARB_shader_objects && GLEW_ARB_vertex_shader) {
		init_functions_from_extension();
	} else {
		printf("GLSL vertex shaders are not supported.\n");
		piglit_report_result(PIGLIT_SKIP);
		exit(1);
	}
}

void
piglit_require_fragment_shader(void)
{
	if (GLEW_VERSION_2_0) {
		init_functions_from_core();
	} else if (GLEW_ARB_shader_objects && GLEW_ARB_fragment_shader) {
		init_functions_from_extension();
	} else {
		printf("GLSL vertex shaders are not supported.\n");
		piglit_report_result(PIGLIT_SKIP);
		exit(1);
	}
}