diff options
author | Ian Romanick <ian.d.romanick@intel.com> | 2015-05-15 15:10:44 -0700 |
---|---|---|
committer | Ian Romanick <ian.d.romanick@intel.com> | 2015-09-16 10:29:13 -0400 |
commit | b7fc9ecc09e405d62eb1c0bfb822a4182421fd6d (patch) | |
tree | 209c80d60bd5f10da51912005ba382393fdd8f7e /tests | |
parent | 8f85332681e5c166d77734b26b8c47de9f74428e (diff) |
arb_direct_state_access: Make dsa-utils more general
Future patches will make use of these utility functions. The shaders
also need to be reduced to GLSL 1.10 because that's all that's required
by OpenGL 2.0.
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Acked-by: Ilia Mirkin <imirkin@alum.mit.edu>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/spec/arb_direct_state_access/dsa-textures.c | 10 | ||||
-rw-r--r-- | tests/spec/arb_direct_state_access/dsa-utils.c | 181 | ||||
-rw-r--r-- | tests/spec/arb_direct_state_access/dsa-utils.h | 6 |
3 files changed, 171 insertions, 26 deletions
diff --git a/tests/spec/arb_direct_state_access/dsa-textures.c b/tests/spec/arb_direct_state_access/dsa-textures.c index cc519e469..29661c0a5 100644 --- a/tests/spec/arb_direct_state_access/dsa-textures.c +++ b/tests/spec/arb_direct_state_access/dsa-textures.c @@ -40,6 +40,8 @@ PIGLIT_GL_TEST_CONFIG_BEGIN PIGLIT_GL_TEST_CONFIG_END +static GLuint prog; + GLfloat* random_image_data(void) { @@ -61,7 +63,7 @@ piglit_init(int argc, char **argv) printf("Using driver %s.\n", (const char *) glGetString(GL_VERSION)); - dsa_init_program(); + prog = dsa_create_program(GL_TEXTURE_2D); } enum piglit_result @@ -80,12 +82,12 @@ piglit_display(void) glTextureParameteri(name, GL_TEXTURE_MAG_FILTER, GL_NEAREST); /* Draw the image */ - piglit_ortho_projection(piglit_width, piglit_height, false); - dsa_texture_with_unit(texunit); + dsa_texture_with_unit(prog, texunit); glEnable(GL_TEXTURE_2D); + glUseProgram(prog); glBindTextureUnit(texunit, name); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; - piglit_draw_rect_tex(0, 0, piglit_width, piglit_height, 0, 0, 1, 1); + piglit_draw_rect_tex(-1.0, -1.0, 2.0, 2.0, 0.0, 0.0, 1.0, 1.0); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; /* Check to make sure the image was drawn correctly */ diff --git a/tests/spec/arb_direct_state_access/dsa-utils.c b/tests/spec/arb_direct_state_access/dsa-utils.c index fefbae13d..727751d14 100644 --- a/tests/spec/arb_direct_state_access/dsa-utils.c +++ b/tests/spec/arb_direct_state_access/dsa-utils.c @@ -35,43 +35,184 @@ * These duplicate fixed-function gl 1.0 pipeline shading. * Adapted from arb_clear_texture/3d.c. */ -static const char dsa_vs_source[] = - "#version 120\n" +static const char vs_template[] = + "#version %s\n" + "#if __VERSION__ < 130\n" "attribute vec4 piglit_vertex;\n" - "attribute vec4 piglit_texcoord;\n" + "attribute vec2 piglit_texcoord;\n" "varying vec2 tex_coord;\n" + "#else\n" + "in vec4 piglit_vertex;\n" + "in vec2 piglit_texcoord;\n" + "out vec2 tex_coord;\n" + "#endif\n" + "uniform mat3 xform;\n" "\n" "void main()\n" "{\n" - " gl_Position = gl_ModelViewProjectionMatrix\n" - " * piglit_vertex;\n" - " tex_coord = piglit_texcoord.st;\n" - "}\n"; + " gl_Position = vec4((xform * piglit_vertex.xyw).xy, 0, 1);\n" + " tex_coord = piglit_texcoord;\n" + "}\n" + ; -static const char dsa_fs_source[] = - "#version 120\n" +static const char fs_1d_template[] = + "#version %s\n" + "#if __VERSION__ < 130\n" + "#define piglit_color gl_FragColor\n" + "#define texture(s,t) texture1D(s,t)\n" + "varying vec2 tex_coord;\n" + "#else\n" + "out vec4 piglit_color;\n" + "in vec2 tex_coord;\n" + "#endif\n" + "uniform sampler1D tex;\n" + "\n" + "void main()\n" + "{\n" + " piglit_color = texture(tex, tex_coord.x);\n" + "}\n" + ; + +static const char fs_2d_template[] = + "#version %s\n" + "#if __VERSION__ < 130\n" + "#define piglit_color gl_FragColor\n" + "#define texture(s,t) texture2D(s,t)\n" + "varying vec2 tex_coord;\n" + "#else\n" + "out vec4 piglit_color;\n" + "in vec2 tex_coord;\n" + "#endif\n" "uniform sampler2D tex;\n" + "\n" + "void main()\n" + "{\n" + " gl_FragColor = texture(tex, tex_coord);\n" + "}\n" + ; + +static const char fs_3d_template[] = + "#version %s\n" + "#if __VERSION__ < 130\n" + "#define piglit_color gl_FragColor\n" + "#define texture(s,t) texture3D(s,t)\n" + "varying vec2 tex_coord;\n" + "#else\n" + "out vec4 piglit_color;\n" + "in vec2 tex_coord;\n" + "#endif\n" + "uniform sampler3D tex;\n" + "\n" + "void main()\n" + "{\n" + " piglit_color = texture(tex, vec3(tex_coord, 0));\n" + "}\n" + ; + +static const char fs_rect_template[] = + "#version %s\n" + "#if __VERSION__ < 130\n" + "#define piglit_color gl_FragColor\n" + "#define texture(s,t) texture2DRect(s,t)\n" "varying vec2 tex_coord;\n" + "#else\n" + "out vec4 piglit_color;\n" + "in vec2 tex_coord;\n" + "#endif\n" + "uniform sampler2DRect tex;\n" "\n" "void main()\n" "{\n" - " gl_FragColor = texture2D(tex, tex_coord);\n" - "}\n"; + " piglit_color = texture(tex, tex_coord);\n" + "}\n" + ; -static GLuint dsa_prog; -static GLuint dsa_uniform; +GLuint +dsa_create_program(GLenum target) +{ + char *fs_source; + char *vs_source; + GLuint prog; + bool es; + int major; + int minor; + const char * ver; + GLint loc; + GLfloat xform[9]; + + piglit_get_glsl_version(&es, &major, &minor); + ver = ((major * 100 + minor) >= 140) ? "140" : "110"; + + asprintf(&vs_source, vs_template, ver); + switch (target) { + case GL_TEXTURE_1D: + asprintf(&fs_source, fs_1d_template, ver); + break; + case GL_TEXTURE_2D: + asprintf(&fs_source, fs_2d_template, ver); + break; + case GL_TEXTURE_3D: + asprintf(&fs_source, fs_3d_template, ver); + break; + case GL_TEXTURE_RECTANGLE_ARB: + asprintf(&fs_source, fs_rect_template, ver); + break; + default: + fprintf(stderr, "Invalid texture target in %s\n", __func__); + piglit_report_result(PIGLIT_FAIL); + } + + prog = piglit_build_simple_program(vs_source, fs_source); + free(vs_source); + free(fs_source); + + /* Note: the default value for all uniforms after linking is zero, so + * there is no need to explicitly set it here. However, the xform + * matrix needs to be set to the identity matrix. + */ + loc = glGetUniformLocation(prog, "xform"); + + xform[0] = 1.0; + xform[1] = 0.0; + xform[2] = 0.0; + + xform[3] = 0.0; + xform[4] = 1.0; + xform[5] = 0.0; + + xform[6] = 0.0; + xform[7] = 0.0; + xform[8] = 1.0; + + glProgramUniformMatrix3fv(prog, loc, 1, GL_FALSE, xform); + + return prog; +} void -dsa_init_program(void) +dsa_texture_with_unit(GLuint prog, GLuint unit) { - dsa_prog = piglit_build_simple_program(dsa_vs_source, dsa_fs_source); - glUseProgram(dsa_prog); - dsa_uniform = glGetUniformLocation(dsa_prog, "tex"); - glUniform1i(dsa_uniform, 0); + const GLuint loc = glGetUniformLocation(prog, "tex"); + glProgramUniform1i(prog, loc, unit); } void -dsa_texture_with_unit(GLuint unit) +dsa_set_xform(GLuint prog, int width, int height) { - glUniform1i(dsa_uniform, unit); + const GLint loc = glGetUniformLocation(prog, "xform"); + GLfloat xform[9]; + + xform[0] = 2.0 / width; + xform[1] = 0.0; + xform[2] = 0.0; + + xform[3] = 0.0; + xform[4] = 2.0 / height; + xform[5] = 0.0; + + xform[6] = -1.0; + xform[7] = -1.0; + xform[8] = 1.0; + + glProgramUniformMatrix3fv(prog, loc, 1, GL_FALSE, xform); } diff --git a/tests/spec/arb_direct_state_access/dsa-utils.h b/tests/spec/arb_direct_state_access/dsa-utils.h index 7bcf0047b..1f84f95af 100644 --- a/tests/spec/arb_direct_state_access/dsa-utils.h +++ b/tests/spec/arb_direct_state_access/dsa-utils.h @@ -55,9 +55,11 @@ do { \ __VA_ARGS__); \ } while (0) -void dsa_init_program(void); +GLuint dsa_create_program(GLenum target); -void dsa_texture_with_unit(GLuint); +void dsa_texture_with_unit(GLuint prog, GLuint unit); + +void dsa_set_xform(GLuint prog, int width, int height); #ifdef __cplusplus } /* end extern "C" */ |