Commit fdc94ddf authored by Eric Anholt's avatar Eric Anholt

Add a test for uniform updates getting reflected in GLSL drawing.

This is currently broken on the Mesa 7.4 branch for 965.
parent 65716a70
......@@ -4,6 +4,7 @@ include_directories(
${GLUT_INCLUDE_DIR}
${piglit_SOURCE_DIR}/tests/mesa/util
${piglit_SOURCE_DIR}/tests/util
${GLEW_INCLUDE_DIR}
)
link_directories (
......@@ -18,6 +19,7 @@ link_libraries (
${OPENGL_glu_LIBRARY}
${GLUT_glut_LIBRARY}
${TIFF_LIBRARY}
${GLEW_glew_LIBRARY}
)
add_executable (trinity-fp1 trinity-fp1.c)
......@@ -28,4 +30,5 @@ add_executable (fp-generic fp-generic.c)
add_executable (fp-kil fp-kil.c)
add_executable (fp-incomplete-tex fp-incomplete-tex.c)
add_executable (fp-indirections fp-indirections.c)
add_executable (glsl-uniform-update glsl-uniform-update.c)
add_executable (vp-bad-program vp-bad-program.c)
/*
* Copyright © 2009 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.
*
* Authors:
* Eric Anholt <eric@anholt.net>
*
*/
/** @file glsl-uniform-update.c
*
* Tests that updates to uniforms between drawing calls get respected.
*
* Create a simple shader that passes through vertex data, and uses a uniform
* to set a color, and just updates that uniform between draw calls. This
* catches a bug found in the 965 driver in an app I was writing.
*/
#define GL_GLEXT_PROTOTYPES
#include <GL/glew.h>
#include "GL/glut.h"
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
#include "piglit-util.h"
#define WIN_WIDTH 100
#define WIN_HEIGHT 100
static int color_location;
static GLint prog;
static GLboolean Automatic;
static void
display(void)
{
GLboolean pass = GL_TRUE;
static const float red[] = {1.0, 0.0, 0.0, 0.0};
static const float blue[] = {0.0, 1.0, 0.0, 0.0};
glClearColor(0.5, 0.5, 0.5, 0.5);
glClear(GL_COLOR_BUFFER_BIT);
glUniform4fv(color_location, 1, red);
piglit_draw_rect(20, 20, 20, 20);
glUniform4fv(color_location, 1, blue);
piglit_draw_rect(50, 20, 20, 20);
pass &= piglit_probe_pixel_rgb(30, 30, red);
pass &= piglit_probe_pixel_rgb(60, 30, blue);
glutSwapBuffers();
if (Automatic) {
piglit_report_result (pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE);
}
}
static void key(unsigned char key, int x, int y)
{
(void) x;
(void) y;
switch (key) {
case 27:
exit(0);
break;
}
glutPostRedisplay();
}
static void init()
{
GLint vs, fs;
/* Set up projection matrix so we can just draw using window
* coordinates.
*/
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, WIN_WIDTH, 0, WIN_HEIGHT, -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
vs = piglit_compile_shader(GL_VERTEX_SHADER,
"glsl-uniform-update.vert");
fs = piglit_compile_shader(GL_FRAGMENT_SHADER,
"glsl-uniform-update.frag");
prog = piglit_link_simple_program(vs, fs);
glUseProgram(prog);
color_location = glGetUniformLocation(prog, "color");
}
int main(int argc, char**argv)
{
int i;
glutInit(&argc, argv);
for(i = 1; i < argc; ++i) {
if (!strcmp(argv[i], "-auto"))
Automatic = 1;
else
printf("Unknown option: %s\n", argv[i]);
}
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(WIN_WIDTH, WIN_HEIGHT);
glutCreateWindow("glsl-uniform-update");
glutKeyboardFunc(key);
glutDisplayFunc(display);
glewInit();
if (!GLEW_VERSION_2_0) {
printf("Requires OpenGL 2.0\n");
piglit_report_result(PIGLIT_SKIP);
exit(1);
}
init();
glutMainLoop();
return 0;
}
uniform vec4 color;
void main()
{
gl_FragColor = color;
}
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
......@@ -26,6 +26,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <GL/glew.h>
#if defined(__APPLE__)
#include <GLUT/glut.h>
......@@ -339,3 +342,116 @@ GLuint piglit_compile_program(GLenum target, const char* text)
return program;
}
/**
* Convenience function to compile a GLSL shader from a file.
*/
GLint
piglit_compile_shader(GLenum target, char *filename)
{
GLint prog;
GLint ok;
struct stat st;
int err;
GLchar *prog_string;
FILE *f;
err = stat(filename, &st);
if (err == -1) {
fprintf(stderr, "Couldn't stat program: %s\n", strerror(errno));
exit(1);
}
prog_string = malloc(st.st_size + 1);
if (prog_string == NULL) {
fprintf(stderr, "malloc\n");
exit(1);
}
f = fopen(filename, "ro");
if (f == NULL) {
fprintf(stderr, "Couldn't open program: %s\n", strerror(errno));
exit(1);
}
fread(prog_string, 1, st.st_size, f);
prog_string[st.st_size] = '\0';
fclose(f);
prog = glCreateShader(target);
glShaderSource(prog, 1, (const GLchar **)&prog_string, NULL);
glCompileShader(prog);
glGetShaderiv(prog, GL_COMPILE_STATUS, &ok);
if (!ok) {
GLchar *info;
GLint size;
glGetShaderiv(prog, GL_INFO_LOG_LENGTH, &size);
info = malloc(size);
glGetShaderInfoLog(prog, size, NULL, info);
fprintf(stderr, "Failed to compile %s: %s\n",
target == GL_FRAGMENT_SHADER ? "FS" : "VS",
info);
}
free(prog_string);
return prog;
}
GLint piglit_link_simple_program(GLint vs, GLint fs)
{
GLint prog, ok;
prog = glCreateProgram();
glAttachShader(prog, fs);
glAttachShader(prog, vs);
glLinkProgram(prog);
glGetProgramiv(prog, GL_LINK_STATUS, &ok);
if (!ok) {
GLchar *info;
GLint size;
glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size);
info = malloc(size);
glGetProgramInfoLog(prog, size, NULL, info);
fprintf(stderr, "Failed to link: %s\n", info);
free(info);
}
return prog;
}
/**
* Convenience function to draw an axis-aligned rectangle.
*/
GLvoid
piglit_draw_rect(float x, float y, float w, float h)
{
float verts[4][4];
verts[0][0] = x;
verts[0][1] = y;
verts[0][2] = 0.0;
verts[0][3] = 1.0;
verts[1][0] = x + w;
verts[1][1] = y;
verts[1][2] = 0.0;
verts[1][3] = 1.0;
verts[2][0] = x + w;
verts[2][1] = y + h;
verts[2][2] = 0.0;
verts[2][3] = 1.0;
verts[3][0] = x;
verts[3][1] = y + h;
verts[3][2] = 0.0;
verts[3][3] = 1.0;
glVertexPointer(4, GL_FLOAT, 0, verts);
glEnable(GL_VERTEX_ARRAY);
glDrawArrays(GL_QUADS, 0, 4);
glDisable(GL_VERTEX_ARRAY);
}
......@@ -62,6 +62,9 @@ int piglit_use_vertex_program();
void piglit_require_fragment_program();
void piglit_require_vertex_program();
GLuint piglit_compile_program(GLenum target, const char* text);
GLint piglit_compile_shader(GLenum target, char *filename);
GLint piglit_link_simple_program(GLint vs, GLint fs);
GLvoid piglit_draw_rect(float x, float y, float w, float h);
extern GLfloat cube_face_texcoords[6][4][3];
extern const char *cube_face_names[6];
......
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