From 464a7358a0915913b21e28da33159002b31d895e Mon Sep 17 00:00:00 2001 From: Jian Zhao Date: Wed, 7 Dec 2011 16:45:21 +0800 Subject: [PATCH] Add a test case on glsl built in function textureLod and textureGrad, and verify that textureGrad may equal to textureLod for sampler2D. --- tests/shaders/CMakeLists.gl.txt | 1 + tests/shaders/glsl-tex-grad.c | 66 ++++++++++++++++++++++++++++++++++++ tests/shaders/glsl-tex-grad.frag | 69 ++++++++++++++++++++++++++++++++++++++ tests/shaders/glsl-tex-grad.vert | 10 +++++ 4 files changed, 146 insertions(+), 0 deletions(-) create mode 100644 tests/shaders/glsl-tex-grad.c create mode 100644 tests/shaders/glsl-tex-grad.frag create mode 100644 tests/shaders/glsl-tex-grad.vert diff --git a/tests/shaders/CMakeLists.gl.txt b/tests/shaders/CMakeLists.gl.txt index 175458c..f7368df 100644 --- a/tests/shaders/CMakeLists.gl.txt +++ b/tests/shaders/CMakeLists.gl.txt @@ -50,6 +50,7 @@ add_executable (glsl-arb-fragment-coord-conventions glsl-arb-fragment-coord-conv add_executable (glsl-arb-fragment-coord-conventions-define glsl-arb-fragment-coord-conventions-define.c) add_executable (glsl-bindattriblocation glsl-bindattriblocation.c) add_executable (glsl-bug-22603 glsl-bug-22603.c) +add_executable (glsl-tex-grad glsl-tex-grad.c) add_executable (glsl-dlist-getattriblocation glsl-dlist-getattriblocation.c) add_executable (glsl-explicit-location-01 glsl-explicit-location-01.c) add_executable (glsl-explicit-location-02 glsl-explicit-location-02.c) diff --git a/tests/shaders/glsl-tex-grad.c b/tests/shaders/glsl-tex-grad.c new file mode 100644 index 0000000..f3e6277 --- /dev/null +++ b/tests/shaders/glsl-tex-grad.c @@ -0,0 +1,66 @@ +/* + * Copyright © 2011 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. + */ + +/** + * \file glsl-tex-grad.c. + * + * Verify that textureGrad may equal to textureLod for sampler2D + * + * \author Jian Zhao + */ + +#include "piglit-util.h" + +int piglit_width = 100, piglit_height = 100; +int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE; + +enum piglit_result +piglit_display(void) +{ + return PIGLIT_FAIL; +} + +void piglit_init(int argc, char **argv) +{ + GLint vert, frag; + GLint prog; + GLboolean ok; + + + vert = piglit_compile_shader(GL_VERTEX_SHADER, + "shaders/glsl-tex-grad.vert"); + frag = piglit_compile_shader(GL_FRAGMENT_SHADER, + "shaders/glsl-tex-grad.frag"); + prog = glCreateProgram(); + glAttachShader(prog, vert); + glAttachShader(prog, frag); + + glLinkProgram(prog); + + ok = piglit_link_check_status(prog); + if (ok == GL_TRUE) + ok = PIGLIT_PASS; + + piglit_report_result(ok); +} + diff --git a/tests/shaders/glsl-tex-grad.frag b/tests/shaders/glsl-tex-grad.frag new file mode 100644 index 0000000..f203122 --- /dev/null +++ b/tests/shaders/glsl-tex-grad.frag @@ -0,0 +1,69 @@ +#version 130 + +precision highp float; +vec4 res, ref, cmp; +out vec4 results[3]; +vec4 ColorToVec4(uint); +float GetLOD(vec3[2]); +const uvec3 dims = uvec3(1024,1024,0); + + +float GetLOD(vec3[2] d) +{ + float lod = 0.f; + vec2 temp; + d[0] *= vec3(dims); + d[1] *= vec3(dims); + temp.x = sqrt(d[0].x*d[0].x+d[0].y*d[0].y+d[0].z*d[0].z); + temp.y = sqrt(d[1].x*d[1].x+d[1].y*d[1].y+d[1].z*d[1].z); + lod = round(log2(max(temp.x, temp.y))); + lod = max(0.f, lod); + lod = min(4.f, lod); + return lod; +} + +vec4 ColorToVec4(uint color) +{ + if (color == 0u) + return vec4(255, 0, 0, 255); + if (color == 1u) + return vec4(0, 255, 0, 255); + if (color == 2u) + return vec4(0, 0, 255, 255); + if (color == 3u) + return vec4(0, 0, 0, 255); + if (color == 4u) + return vec4(255, 255, 255, 255); + if (color == 5u) + return vec4(255, 255, 0, 255); + if (color == 6u) + return vec4(0, 255, 255, 255); +} +uniform sampler2D tex; +vec4 testFunction(vec4 pos, vec4 relPos) +{ + vec3[2] d = vec3[2](vec3(0), vec3(0)); + for (int dPdx=-20; dPdx<=20; dPdx+=3) + for (int dPdy=-20; dPdy<=20; dPdy+=3) + { + d[0].x = dPdx / 10.f; + d[1].y = dPdy / 9.f; + if (textureLod(tex, pos.xy, GetLOD(d)) != textureGrad(tex, pos.xy, d[0].xy, d[1].xy)) + return ColorToVec4(0u); + } + return ColorToVec4(1u); +} + +void main() +{ + + cmp = testFunction(gl_FragCoord/100.f,gl_TexCoord[0]); + if (any(greaterThanEqual(res.xyz, vec3(1)))) + res = res / vec4(vec3(255), 1); + if (any(greaterThanEqual(ref.xyz, vec3(1)))) + ref = ref / vec4(vec3(255), 1); + results[0] = res; + results[1] = ref; + results[2] = cmp / vec4(255); +} + diff --git a/tests/shaders/glsl-tex-grad.vert b/tests/shaders/glsl-tex-grad.vert new file mode 100644 index 0000000..ce609ff --- /dev/null +++ b/tests/shaders/glsl-tex-grad.vert @@ -0,0 +1,10 @@ +#version 130 + +precision highp float; + + +void main() +{ + gl_Position = gl_Vertex; + gl_TexCoord[0] = gl_MultiTexCoord0; +} -- 1.7.6