From 3569f4c3847efb7df172c5a9fa63ce3ea77ca1f4 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Tue, 20 Jan 2015 22:15:55 +0100 Subject: [PATCH] Check trilinear cubemap sampling --- tests/shaders/CMakeLists.gl.txt | 1 + tests/shaders/cubemap-lod.c | 222 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 223 insertions(+) create mode 100644 tests/shaders/cubemap-lod.c diff --git a/tests/shaders/CMakeLists.gl.txt b/tests/shaders/CMakeLists.gl.txt index c827256..e06903a 100644 --- a/tests/shaders/CMakeLists.gl.txt +++ b/tests/shaders/CMakeLists.gl.txt @@ -168,5 +168,6 @@ piglit_add_executable (useshaderprogram-bad-type useshaderprogram-bad-type.c) piglit_add_executable (useshaderprogram-bad-program useshaderprogram-bad-program.c) piglit_add_executable (useshaderprogram-flushverts-1 useshaderprogram-flushverts-1.c) piglit_add_executable (version-mixing version-mixing.c) +piglit_add_executable (cubemap-lod cubemap-lod.c) # vim: ft=cmake: diff --git a/tests/shaders/cubemap-lod.c b/tests/shaders/cubemap-lod.c new file mode 100644 index 0000000..c5d2355 --- /dev/null +++ b/tests/shaders/cubemap-lod.c @@ -0,0 +1,222 @@ +/* + * Copyright © 2015 Vincent Lejeune (vljn@ovi.com) + * + * 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: + * Vincent Lejeune (vljn@ovi.com) + * Based on glsl-kwin-blur-1.c from Fredrik Höglund + */ + + +#include "piglit-util-gl.h" + +/* Size of viewport and test region. */ +#define WIDTH 1280 +#define HEIGHT 728 + +PIGLIT_GL_TEST_CONFIG_BEGIN + config.supports_gl_compat_version = 33; + config.supports_gl_core_version = 33; + config.window_width = WIDTH; + config.window_height = HEIGHT; + + config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE; + +PIGLIT_GL_TEST_CONFIG_END + + + + +static const char vs_code[] = + "#version 330\n" + "#if __VERSION__ >= 330\n" + "layout(location = 0) in vec3 Position;\n" + "#else\n" + "in vec3 Position;\n" + "#endif\n" + + "void main()\n" + "{\n" + "gl_Position = vec4(Position, 1.);\n" + + "}\n"; + +static const char fs_code[] = + "#version 330\n" + "uniform mat4 InverseProjectionMatrix;\n" + "uniform mat4 InverseViewMatrix;\n" + "uniform vec2 screen;\n" + "uniform samplerCube tex;\n" + + "out vec4 FragColor;\n" + + "void main(void)\n" + "{\n" + "vec3 eyedir = vec3(gl_FragCoord.xy / screen, 1.);\n" + "eyedir = 2.0 * eyedir - 1.0;\n" + "vec4 tmp = ( vec4(eyedir, 1.));\n" + "tmp /= tmp.w;\n" + "eyedir = ( vec4(tmp.xyz, 0.)).xyz;\n" + "vec4 color = texture(tex, eyedir);\n" + "FragColor = vec4(color.xyz, 1.);\n" + "}\n"; + +static const int expected_edge[] = { + 0x00, 0x03, 0x06, 0x15, 0x24, 0x47, 0x6a, 0x95, 0xb8, 0xdb, 0xea, 0xf9, + 0xfc, 0xff +}; + +static const int expected_corner[] = { + 0x00, 0x02, 0x05, 0x14, 0x2c, 0x57, 0x85, 0xbc, 0xd7, 0xf3, 0xf9, 0xff +}; + +static GLuint setup_shaders() +{ + GLuint vs, fs, prog; + + vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_code); + fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_code); + prog = piglit_link_simple_program(vs, fs); + + glDeleteShader(vs); + glDeleteShader(fs); + + return prog; +} + +static GLboolean test() +{ + GLboolean pass = GL_TRUE; + + /* Prepare the shaders */ + GLint prog = setup_shaders(); + GLint uScreen = glGetUniformLocation(prog, "screen"); + GLint uTexUnit = glGetUniformLocation(prog, "tex"); + GLuint scratchTex; + GLuint vbo; + GLuint vao; + int i; + char *textureContent; + + /* Vertex coordinates */ + const float vc[] = { + -1., -1., 1., + -1., 3., 1., + 3., -1., 1., + }; + + textureContent = malloc(4 * 1024 * 1024 * sizeof(char)); + for (i = 0; i < 1024 * 1024; i++) + { + textureContent[4 * i] = i % 255; + textureContent[4 * i + 1] = i / 255 % 255; + textureContent[4 * i + 2] = 0; + textureContent[4 * i + 3] = 255; + } + glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); + glEnable(GL_DEPTH_TEST); + glDisable(GL_CULL_FACE); + glDisable(GL_BLEND); + + glActiveTexture(GL_TEXTURE0); + /* Create a scratch texture */ + glGenTextures(1, &scratchTex); + glBindTexture(GL_TEXTURE_CUBE_MAP, scratchTex); + glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)16.); + for (i = 0; i < 6; ++i) + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_SRGB_ALPHA, 1024, 1024, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureContent); + glGenerateMipmap(GL_TEXTURE_CUBE_MAP); + + + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + glGenBuffers(1, &vbo); + glBindBuffer(GL_ARRAY_BUFFER, vbo); + glBufferData(GL_ARRAY_BUFFER, 3 * 3 * sizeof(float), vc, GL_STATIC_DRAW); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0); + + glUseProgram(prog); + glUniform1i(uTexUnit, 0); + glUniform2f(uScreen, WIDTH, HEIGHT); + glDrawArrays(GL_TRIANGLES, 0, 3); + + assert(glGetError() == 0); + + /* Clean up */ + glUseProgram(0); + glBindTexture(GL_TEXTURE_2D, 0); + glDeleteTextures(1, &scratchTex); + glDeleteProgram(prog); + free(textureContent); + + + /* Test the sides */ +/* for (i = 0; i < 14; i++) { + float color[3]; + color[0] = expected_edge[i] / 255.; + color[1] = color[0]; + color[2] = color[0]; + pass = piglit_probe_pixel_rgb(50, 18 + i, color) && pass; + pass = piglit_probe_pixel_rgb(50, HEIGHT - 19 - i, color) && pass; + pass = piglit_probe_pixel_rgb(18 + i, 50, color) && pass; + pass = piglit_probe_pixel_rgb(WIDTH - 19 - i, 50, color) && pass; + }*/ + + /* Test the corners */ +/* for (i = 0; i < 12; i++) { + float color[3]; + color[0] = expected_corner[i] / 255.; + color[1] = color[0]; + color[2] = color[0]; + pass = piglit_probe_pixel_rgb(20 + i, 20 + i, color) && pass; + pass = piglit_probe_pixel_rgb(20 + i, HEIGHT - 21 - i, color) && pass; + pass = piglit_probe_pixel_rgb(WIDTH - 21 - i, 20 + i, color) && pass; + pass = piglit_probe_pixel_rgb(WIDTH - 21 - i, HEIGHT - 21 - i, color) && pass; + }*/ + + return pass; +} + +enum piglit_result piglit_display(void) +{ + GLboolean pass; + + glViewport(0, 0, WIDTH, HEIGHT); + glClearColor(0.0, 0.0, 0.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + pass = test(); + + piglit_present_results(); + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} + +void piglit_init(int argc, char **argv) +{ + piglit_require_gl_version(33); +} + -- 2.1.0