Commit 467e6355 authored by Ian Romanick's avatar Ian Romanick

Add GLSL related utility functions

parent af848978
......@@ -9,6 +9,7 @@ include_directories(
set (UTIL_SOURCES
fdo-bitmap.c
piglit-shader.c
piglit-util.c
shader-load.c
piglit-framework.c
......@@ -17,6 +18,7 @@ set (UTIL_SOURCES
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
add_definitions ( -DUSE_GLX )
add_library (piglitglxutil
piglit-shader.c
piglit-util.c
piglit-glx-framework.c
piglit-glx-util.c
......
/*
* 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.
*/
#if defined(_MSC_VER)
#include <windows.h>
#endif
#include "piglit-util.h"
PFNGLATTACHSHADERPROC piglit_AttachShader = NULL;
PFNGLCOMPILESHADERPROC piglit_CompileShader = NULL;
PFNGLCREATEPROGRAMPROC piglit_CreateProgram = NULL;
PFNGLCREATESHADERPROC piglit_CreateShader = NULL;
PFNGLDELETEPROGRAMPROC piglit_DeleteProgram = NULL;
PFNGLDELETESHADERPROC piglit_DeleteShader = NULL;
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;
PFNGLUNIFORM1FVPROC piglit_Uniform1fv = NULL;
PFNGLUNIFORM2FVPROC piglit_Uniform2fv = NULL;
PFNGLUNIFORM3FVPROC piglit_Uniform3fv = NULL;
PFNGLUNIFORM4FVPROC piglit_Uniform4fv = NULL;
PFNGLUNIFORM1IPROC piglit_Uniform1i = NULL;
static void
init_functions_from_core(void)
{
piglit_AttachShader = glAttachShader;
piglit_CompileShader = glCompileShader;
piglit_CreateProgram = glCreateProgram;
piglit_CreateShader = glCreateShader;
piglit_DeleteProgram = glDeleteProgram;
piglit_DeleteShader = glDeleteShader;
piglit_GetProgramInfoLog = glGetProgramInfoLog;
piglit_GetProgramiv = glGetProgramiv;
piglit_GetShaderInfoLog = glGetShaderInfoLog;
piglit_GetShaderiv = glGetShaderiv;
piglit_GetUniformLocation = glGetUniformLocation;
piglit_LinkProgram = glLinkProgram;
piglit_ShaderSource = glShaderSource;
piglit_UseProgram = glUseProgram;
piglit_Uniform1fv = glUniform1fv;
piglit_Uniform2fv = glUniform2fv;
piglit_Uniform3fv = glUniform3fv;
piglit_Uniform4fv = glUniform4fv;
piglit_Uniform1i = glUniform1i;
}
static void
init_functions_from_extension(void)
{
piglit_AttachShader = glAttachObjectARB;
piglit_CompileShader = glCompileShaderARB;
piglit_CreateProgram = glCreateProgramObjectARB;
piglit_CreateShader = glCreateShaderObjectARB;
piglit_DeleteProgram = glDeleteObjectARB;
piglit_DeleteShader = glDeleteObjectARB;
piglit_GetProgramInfoLog = glGetInfoLogARB;
piglit_GetProgramiv = glGetObjectParameterivARB;
piglit_GetShaderInfoLog = glGetInfoLogARB;
piglit_GetShaderiv = glGetObjectParameterivARB;
piglit_GetUniformLocation = glGetUniformLocationARB;
piglit_LinkProgram = glLinkProgramARB;
piglit_ShaderSource = glShaderSourceARB;
piglit_UseProgram = glUseProgramObjectARB;
piglit_Uniform1fv = glUniform1fvARB;
piglit_Uniform2fv = glUniform2fvARB;
piglit_Uniform3fv = glUniform3fvARB;
piglit_Uniform4fv = glUniform4fvARB;
piglit_Uniform1i = glUniform1iARB;
}
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);
}
}
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);
}
}
......@@ -585,20 +585,32 @@ piglit_compile_shader_text(GLenum target, const char *text)
GLuint prog;
GLint ok;
prog = glCreateShader(target);
glShaderSource(prog, 1, (const GLchar **) &text, NULL);
glCompileShader(prog);
switch (target) {
case GL_VERTEX_SHADER:
piglit_require_vertex_shader();
break;
case GL_FRAGMENT_SHADER:
piglit_require_fragment_shader();
break;
default:
piglit_require_GLSL();
break;
}
prog = piglit_CreateShader(target);
piglit_ShaderSource(prog, 1, (const GLchar **) &text, NULL);
piglit_CompileShader(prog);
glGetShaderiv(prog, GL_COMPILE_STATUS, &ok);
piglit_GetShaderiv(prog, GL_COMPILE_STATUS, &ok);
{
GLchar *info;
GLint size;
glGetShaderiv(prog, GL_INFO_LOG_LENGTH, &size);
piglit_GetShaderiv(prog, GL_INFO_LOG_LENGTH, &size);
info = malloc(size);
glGetShaderInfoLog(prog, size, NULL, info);
piglit_GetShaderInfoLog(prog, size, NULL, info);
if (!ok) {
fprintf(stderr, "Failed to compile %s: %s\n",
target == GL_FRAGMENT_SHADER ? "FS" : "VS",
......@@ -624,15 +636,17 @@ link_check_status(GLint prog, FILE *output)
GLint size;
GLint ok;
glGetProgramiv(prog, GL_LINK_STATUS, &ok);
piglit_require_GLSL();
piglit_GetProgramiv(prog, GL_LINK_STATUS, &ok);
/* Some drivers return a size of 1 for an empty log. This is the size
* of a log that contains only a terminating NUL character.
*/
glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size);
piglit_GetProgramiv(prog, GL_INFO_LOG_LENGTH, &size);
if (size > 1) {
info = malloc(size);
glGetProgramInfoLog(prog, size, NULL, info);
piglit_GetProgramInfoLog(prog, size, NULL, info);
}
if (!ok) {
......@@ -678,12 +692,12 @@ GLint piglit_link_simple_program(GLint vs, GLint fs)
{
GLint prog;
prog = glCreateProgram();
prog = piglit_CreateProgram();
if (fs)
glAttachShader(prog, fs);
piglit_AttachShader(prog, fs);
if (vs)
glAttachShader(prog, vs);
glLinkProgram(prog);
piglit_AttachShader(prog, vs);
piglit_LinkProgram(prog);
piglit_link_check_status(prog);
......
......@@ -145,6 +145,62 @@ extern const GLenum cube_face_targets[6];
*/
extern GLint piglit_ARBfp_pass_through;
/**
* \name Portable wrappers for GLSL functions\
*
* \note
* One of \c piglit_require_GLSL, \c piglit_require_vertex_shader, or
* \c piglit_require_fragment_shader must be called before using these
* wrappers.
*/
/*@{*/
#if defined(PIGLIT_GLES2)
#define piglit_AttachShader glAttachShader
#define piglit_CompileShader glCompileShader
#define piglit_CreateProgram glCreateProgram
#define piglit_CreateShader glCreateShader
#define piglit_DeleteProgram glDeleteProgram
#define piglit_DeleteShader glDeleteShader
#define piglit_GetProgramInfoLog glGetProgramInfoLog
#define piglit_GetProgramiv glGetProgramiv
#define piglit_GetShaderInfoLog glGetShaderInfoLog
#define piglit_GetShaderiv glGetShaderiv
#define piglit_GetUniformLocation glGetUniformLocation
#define piglit_LinkProgram glLinkProgram
#define piglit_ShaderSource glShaderSource
#define piglit_UseProgram glUseProgram
#define piglit_Uniform1fv glUniform1fv
#define piglit_Uniform2fv glUniform2fv
#define piglit_Uniform3fv glUniform3fv
#define piglit_Uniform4fv glUniform4fv
#define piglit_Uniform1i glUniform1i
#else
extern PFNGLATTACHSHADERPROC piglit_AttachShader;
extern PFNGLCOMPILESHADERPROC piglit_CompileShader;
extern PFNGLCREATEPROGRAMPROC piglit_CreateProgram;
extern PFNGLCREATESHADERPROC piglit_CreateShader;
extern PFNGLDELETEPROGRAMPROC piglit_DeleteProgram;
extern PFNGLDELETESHADERPROC piglit_DeleteShader;
extern PFNGLGETPROGRAMINFOLOGPROC piglit_GetProgramInfoLog;
extern PFNGLGETPROGRAMIVPROC piglit_GetProgramiv;
extern PFNGLGETSHADERINFOLOGPROC piglit_GetShaderInfoLog;
extern PFNGLGETSHADERIVPROC piglit_GetShaderiv;
extern PFNGLGETUNIFORMLOCATIONPROC piglit_GetUniformLocation;
extern PFNGLLINKPROGRAMPROC piglit_LinkProgram;
extern PFNGLSHADERSOURCEPROC piglit_ShaderSource;
extern PFNGLUSEPROGRAMPROC piglit_UseProgram;
extern PFNGLUNIFORM1FVPROC piglit_Uniform1fv;
extern PFNGLUNIFORM2FVPROC piglit_Uniform2fv;
extern PFNGLUNIFORM3FVPROC piglit_Uniform3fv;
extern PFNGLUNIFORM4FVPROC piglit_Uniform4fv;
extern PFNGLUNIFORM1IPROC piglit_Uniform1i;
#endif
/*@}*/
extern void piglit_require_GLSL(void);
extern void piglit_require_fragment_shader(void);
extern void piglit_require_vertex_shader(void);
#ifndef HAVE_STRCHRNUL
char *strchrnul(const char *s, int c);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment