void setup_glsl_programs() { GLuint vs; GLuint fs; GLuint prog; char vert[4096]; char frag[4096]; char *version_directive; if (use_glsl_130) { version_directive = "#version 130"; } else { version_directive = ""; } sprintf(vert, "%s\n" "uniform float position_angle;\n" "uniform float clipVertex_angle;\n" "mat4 rotate(float angle)\n" "{\n" " angle = radians(angle);\n" " return mat4( cos(angle), sin(angle), 0.0, 0.0,\n" " -sin(angle), cos(angle), 0.0, 0.0,\n" " 0.0, 0.0, 1.0, 0.0,\n" " 0.0, 0.0, 0.0, 1.0);\n" "}\n" "void main()\n" "{\n" "%s\n" "}", version_directive, setters); sprintf(frag, "%s\n" "void main()\n" "{\n" " gl_FragColor = vec4(1.0);\n" "}", version_directive); vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vert); fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag); prog = piglit_CreateProgram(); piglit_AttachShader(prog, vs); piglit_AttachShader(prog, fs); piglit_LinkProgram(prog); piglit_DeleteShader(vs); piglit_DeleteShader(fs); piglit_UseProgram(prog); position_angle_loc = piglit_GetUniformLocation(prog, "position_angle"); if (use_clip_vertex) { clipVertex_angle_loc = piglit_GetUniformLocation(prog, "clipVertex_angle"); } }
enum piglit_result piglit_display(void) { GLuint vs, fs; bool pass = true; GLuint prog; float green[] = {0.0, 1.0, 0.0, 0.0}; GLint status; /* Initial buffer clear. */ glClearColor(1.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source); fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source); prog = piglit_link_simple_program(vs, fs); if (!vs || !fs || !prog) piglit_report_result(PIGLIT_FAIL); piglit_DeleteShader(vs); piglit_DeleteShader(fs); piglit_UseProgram(prog); piglit_DeleteProgram(prog); /* Try to blow out the refcount */ piglit_DeleteProgram(prog); piglit_DeleteProgram(prog); piglit_DeleteProgram(prog); /* Sanity check: deleting didn't already unbind our shader program. */ piglit_draw_rect(-1, -1, 2, 2); pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green) && pass; /* The program should still report being deleted. */ piglit_GetProgramiv(prog, GL_DELETE_STATUS, &status); if (!piglit_check_gl_error(0)) piglit_report_result(PIGLIT_FAIL); if (status != GL_TRUE) { fprintf(stderr, "GL_DELETE_STATUS after a clear reported non-true %d\n", status); pass = false; } /* Now, disable the program and it should be finally deleted. */ piglit_UseProgram(0); piglit_GetProgramiv(prog, GL_DELETE_STATUS, &status); pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass; piglit_present_results(); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
void piglit_init(int argc, char **argv) { GLuint vs; GLuint fs; piglit_require_GLSL(); piglit_require_GLSL_version(130); vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vert); fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag); prog = piglit_CreateProgram(); piglit_AttachShader(prog, vs); piglit_AttachShader(prog, fs); piglit_LinkProgram(prog); piglit_DeleteShader(vs); piglit_DeleteShader(fs); piglit_UseProgram(prog); }
/** * Test drawing with GLSL shaders and no vertex arrays. * Use a vertex shader with a hard-coded vertex position. */ static GLboolean test_glsl_no_arrays(void) { static const char *noVertexVertShaderText = "varying vec4 colorVar; \n" "void main() \n" "{ \n" " colorVar = vec4(1.0, 1.0, 0.0, 1.0); \n" " gl_Position = vec4(0.0, 0.0, 0.0, 1.0); \n" "} \n"; static const char *fragShaderText = "varying vec4 colorVar; \n" "void main() \n" "{ \n" " gl_FragColor = colorVar; \n" "} \n"; static const GLfloat expected[4] = {1.0, 1.0, 0.0, 1.0}; GLboolean p, pass = GL_TRUE; GLuint vertShader, fragShader, program; vertShader = piglit_compile_shader_text(GL_VERTEX_SHADER, noVertexVertShaderText); fragShader = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fragShaderText); program = piglit_link_simple_program(vertShader, fragShader); piglit_UseProgram(program); glClear(GL_COLOR_BUFFER_BIT); glPointSize(3.0); glDrawArrays(GL_POINTS, 0, 1); glPointSize(1.0); p = piglit_probe_pixel_rgba(piglit_width/2, piglit_height/2, expected); glutSwapBuffers(); if (!p) { printf("%s: failed when drawing with GLSL and no vertex arrays\n", TestName); pass = GL_FALSE; } piglit_DeleteShader(vertShader); piglit_DeleteProgram(program); return pass; }
/** Test drawing with GLSL shaders */ static GLboolean test_glsl_arrays(void) { static const char *vertShaderText = "attribute vec4 color, pos; \n" "varying vec4 colorVar; \n" "void main() \n" "{ \n" " colorVar = color; \n" " gl_Position = gl_ModelViewProjectionMatrix * pos; \n" "} \n"; static const char *fragShaderText = "varying vec4 colorVar; \n" "void main() \n" "{ \n" " gl_FragColor = colorVar; \n" "} \n"; static const GLfloat expected[4] = {0.5, 0.0, 0.5, 1.0}; GLuint buf; GLboolean p, pass = GL_TRUE; GLint posAttrib, colorAttrib; GLuint vertShader, fragShader, program; buf = setup_vbo(); glBindBufferARB(GL_ARRAY_BUFFER_ARB, buf); vertShader = piglit_compile_shader_text(GL_VERTEX_SHADER, vertShaderText); fragShader = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fragShaderText); program = piglit_link_simple_program(vertShader, fragShader); piglit_UseProgram(program); /* * Draw with compiler-assigned attribute locations */ { posAttrib = piglit_GetAttribLocation(program, "pos"); colorAttrib = piglit_GetAttribLocation(program, "color"); if (0) printf("%s: GLSL posAttrib = %d colorAttrib = %d\n", TestName, posAttrib, colorAttrib); glVertexAttribPointerARB(posAttrib, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (void *) 0); glVertexAttribPointerARB(colorAttrib, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (void *) (8 * sizeof(GLfloat))); glEnableVertexAttribArrayARB(posAttrib); glEnableVertexAttribArrayARB(colorAttrib); glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_QUADS, 0, 4); p = piglit_probe_pixel_rgba(piglit_width/2, piglit_height/2, expected); glutSwapBuffers(); if (!p) { printf("%s: failed when drawing with ", TestName); printf("compiler-assigned attribute locations\n"); pass = GL_FALSE; } glDisableVertexAttribArrayARB(posAttrib); glDisableVertexAttribArrayARB(colorAttrib); } /* * Draw with user-defined attribute bindings, not using 0. */ { posAttrib = 5; colorAttrib = 7; piglit_BindAttribLocation(program, posAttrib, "pos"); piglit_BindAttribLocation(program, colorAttrib, "color"); piglit_LinkProgram(program); glVertexAttribPointerARB(posAttrib, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (void *) 0); glVertexAttribPointerARB(colorAttrib, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (void *) (8 * sizeof(GLfloat))); glEnableVertexAttribArrayARB(posAttrib); glEnableVertexAttribArrayARB(colorAttrib); glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_QUADS, 0, 4); p = piglit_probe_pixel_rgba(piglit_width/2, piglit_height/2, expected); glutSwapBuffers(); if (!p) { printf("%s: failed when drawing with ", TestName); printf("user-assigned attribute locations\n"); pass = GL_FALSE; } glDisableVertexAttribArrayARB(posAttrib); glDisableVertexAttribArrayARB(colorAttrib); } piglit_DeleteShader(vertShader); piglit_DeleteProgram(program); glDeleteBuffersARB(1, &buf); return pass; }