<div dir="ltr">This was a problem that was copied in from the test this was based upon (getteximage-targets). I've made a lot of changes to this test for a new set of patches to mesa, so this will get fixed soon.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 8, 2015 at 4:05 PM, Vinson Lee <span dir="ltr"><<a href="mailto:vlee@freedesktop.org" target="_blank">vlee@freedesktop.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Mon, Dec 15, 2014 at 5:24 PM, Laura Ekstrand <<a href="mailto:laura@jlekstrand.net">laura@jlekstrand.net</a>> wrote:<br>
> ---<br>
> tests/all.py | 6 +<br>
> .../spec/arb_direct_state_access/CMakeLists.gl.txt | 5 +<br>
> tests/spec/arb_direct_state_access/get-textures.c | 114 +++++<br>
> .../gettextureimage-formats.c | 559 +++++++++++++++++++++<br>
> .../gettextureimage-luminance.c | 260 ++++++++++<br>
> .../gettextureimage-simple.c | 86 ++++<br>
> .../gettextureimage-targets.c | 305 +++++++++++<br>
> 7 files changed, 1335 insertions(+)<br>
> create mode 100644 tests/spec/arb_direct_state_access/get-textures.c<br>
> create mode 100644 tests/spec/arb_direct_state_access/gettextureimage-formats.c<br>
> create mode 100644 tests/spec/arb_direct_state_access/gettextureimage-luminance.c<br>
> create mode 100644 tests/spec/arb_direct_state_access/gettextureimage-simple.c<br>
> create mode 100644 tests/spec/arb_direct_state_access/gettextureimage-targets.c<br>
><br>
> diff --git a/tests/all.py b/tests/all.py<br>
> index 48ec09f..8dfb5ac 100644<br>
> --- a/tests/all.py<br>
> +++ b/tests/all.py<br>
> @@ -4316,6 +4316,12 @@ spec['ARB_direct_state_access']['texunits'] = PiglitGLTest('arb_direct_state_acc<br>
> spec['ARB_direct_state_access']['texture-params'] = PiglitGLTest('arb_direct_state_access-texture-params', run_concurrent=True)<br>
> spec['ARB_direct_state_access']['copytexturesubimage'] = PiglitGLTest('arb_direct_state_access-copytexturesubimage', run_concurrent=True)<br>
> spec['ARB_direct_state_access']['texture-errors'] = PiglitGLTest('arb_direct_state_access-texture-errors', run_concurrent=True)<br>
> +spec['ARB_direct_state_access']['get-textures'] = PiglitGLTest('arb_direct_state_access-get-textures', run_concurrent=True)<br>
> +spec['ARB_direct_state_access']['gettextureimage-formats'] = PiglitGLTest('arb_direct_state_access-gettextureimage-formats', run_concurrent=True)<br>
> +spec['ARB_direct_state_access']['gettextureimage-luminance'] = PiglitGLTest('arb_direct_state_access-gettextureimage-luminance', run_concurrent=True)<br>
> +spec['ARB_direct_state_access']['gettextureimage-simple'] = PiglitGLTest('arb_direct_state_access-gettextureimage-simple', run_concurrent=True)<br>
> +spec['ARB_direct_state_access']['gettextureimage-targets'] = PiglitGLTest('arb_direct_state_access-gettextureimage-targets', run_concurrent=True)<br>
> +<br>
><br>
> profile.tests['hiz'] = hiz<br>
> profile.tests['fast_color_clear'] = fast_color_clear<br>
> diff --git a/tests/spec/arb_direct_state_access/CMakeLists.gl.txt b/tests/spec/arb_direct_state_access/CMakeLists.gl.txt<br>
> index 4f8f49f..d5a496e 100644<br>
> --- a/tests/spec/arb_direct_state_access/CMakeLists.gl.txt<br>
> +++ b/tests/spec/arb_direct_state_access/CMakeLists.gl.txt<br>
> @@ -18,4 +18,9 @@ piglit_add_executable (arb_direct_state_access-texunits texunits.c)<br>
> piglit_add_executable (arb_direct_state_access-texture-params texture-params.c)<br>
> piglit_add_executable (arb_direct_state_access-copytexturesubimage copytexturesubimage.c)<br>
> piglit_add_executable (arb_direct_state_access-texture-errors texture-errors.c)<br>
> +piglit_add_executable (arb_direct_state_access-get-textures get-textures.c)<br>
> +piglit_add_executable (arb_direct_state_access-gettextureimage-formats gettextureimage-formats.c)<br>
> +piglit_add_executable (arb_direct_state_access-gettextureimage-luminance gettextureimage-luminance.c)<br>
> +piglit_add_executable (arb_direct_state_access-gettextureimage-simple gettextureimage-simple.c)<br>
> +piglit_add_executable (arb_direct_state_access-gettextureimage-targets gettextureimage-targets.c)<br>
> # vim: ft=cmake:<br>
> diff --git a/tests/spec/arb_direct_state_access/get-textures.c b/tests/spec/arb_direct_state_access/get-textures.c<br>
> new file mode 100644<br>
> index 0000000..95d5bc4<br>
> --- /dev/null<br>
> +++ b/tests/spec/arb_direct_state_access/get-textures.c<br>
> @@ -0,0 +1,114 @@<br>
> +/*<br>
> + * Copyright 2014 Intel Corporation<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the "Software"),<br>
> + * to deal in the Software without restriction, including without limitation<br>
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> + * and/or sell copies of the Software, and to permit persons to whom the<br>
> + * Software is furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice (including the next<br>
> + * paragraph) shall be included in all copies or substantial portions of the<br>
> + * Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
> + * DEALINGS IN THE SOFTWARE.<br>
> + */<br>
> +<br>
> +/** @file get-textures.c<br>
> + *<br>
> + * Tests glGetTextureImage to see if it behaves in the expected way,<br>
> + * throwing the correct errors, etc.<br>
> + */<br>
> +<br>
> +#include "piglit-util-gl.h"<br>
> +<br>
> +PIGLIT_GL_TEST_CONFIG_BEGIN<br>
> +<br>
> + config.supports_gl_compat_version = 13;<br>
> +<br>
> + config.window_visual = PIGLIT_GL_VISUAL_RGBA |<br>
> + PIGLIT_GL_VISUAL_DOUBLE;<br>
> +<br>
> +PIGLIT_GL_TEST_CONFIG_END<br>
> +<br>
> +void<br>
> +piglit_init(int argc, char **argv)<br>
> +{<br>
> + piglit_require_extension("GL_ARB_direct_state_access");<br>
> +}<br>
> +<br>
> +enum piglit_result<br>
> +piglit_display(void)<br>
> +{<br>
> + bool pass = true;<br>
> + GLuint name;<br>
> + GLubyte *data = malloc(50 * 50 * 6 * 4 * sizeof(GLubyte));<br>
> + GLubyte *image = malloc(50 * 50 * 4 * sizeof(GLubyte));<br>
> +<br>
> + /* Throw some invalid inputs at glGetTextureImage. */<br>
> +<br>
> + /* Non-gen-ed name */<br>
> + glGetTextureImage(3, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, data);<br>
> + pass &= piglit_check_gl_error(GL_INVALID_OPERATION);<br>
> +<br>
> + /* Unsupported target. */<br>
> + glGenTextures(1, &name);<br>
> + glBindTexture(GL_TEXTURE_CUBE_MAP_POSITIVE_X, name);<br>
> + glGetTextureImage(name, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, data);<br>
> + pass &= piglit_check_gl_error(GL_INVALID_ENUM);<br>
> + glDeleteTextures(1, &name);<br>
> +<br>
> + /* Unsupported dsa target for non-dsa version. */<br>
> + glGetTexImage(GL_TEXTURE_CUBE_MAP, 0, GL_RGBA, GL_UNSIGNED_BYTE,<br>
> + data);<br>
> + pass &= piglit_check_gl_error(GL_INVALID_ENUM);<br>
> +<br>
> + /* No Storage<br>
> + *<br>
> + * The spec doesn't say what should happen in this case. This is<br>
> + * addressed by Khronos Bug 13223.<br>
> + */<br>
> + glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &name);<br>
> + glGetTextureImage(name, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, data);<br>
> + pass &= piglit_check_gl_error(GL_INVALID_OPERATION);<br>
> + glDeleteTextures(1, &name);<br>
> +<br>
> + /* Insufficient storage<br>
> + *<br>
> + * The spec doesn't say what should happen in this case. This is<br>
> + * addressed by Khronos Bug 13223.<br>
> + */<br>
> + glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &name);<br>
> + glBindTexture(GL_TEXTURE_CUBE_MAP, name);<br>
> + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0,<br>
> + GL_RGBA8, 50, 50, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);<br>
> + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0,<br>
> + GL_RGBA8, 50, 50, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);<br>
> + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0,<br>
> + GL_RGBA8, 50, 50, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);<br>
> + /* Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set */<br>
> + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0,<br>
> + GL_RGBA8, 50, 50, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);<br>
> + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0,<br>
> + GL_RGBA8, 50, 50, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);<br>
> + glGetTextureImage(name, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, data);<br>
> + pass &= piglit_check_gl_error(GL_INVALID_OPERATION);<br>
> + glDeleteTextures(1, &name);<br>
> +<br>
> + /* Trivial, but should work. */<br>
> + glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &name);<br>
> + glTextureStorage2D(name, 1, GL_RGBA8, 50, 50);<br>
> + glGetTextureImage(name, 0, GL_RGBA, GL_UNSIGNED_BYTE,<br>
> + 50 * 50 * 6 * 4, data);<br>
> + pass &= piglit_check_gl_error(GL_NO_ERROR);<br>
> +<br>
> + return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
> +}<br>
> +<br>
> diff --git a/tests/spec/arb_direct_state_access/gettextureimage-formats.c b/tests/spec/arb_direct_state_access/gettextureimage-formats.c<br>
> new file mode 100644<br>
> index 0000000..a22d235<br>
> --- /dev/null<br>
> +++ b/tests/spec/arb_direct_state_access/gettextureimage-formats.c<br>
> @@ -0,0 +1,559 @@<br>
> +/*<br>
> + * Copyright (c) 2011 VMware, Inc.<br>
> + * Copyright (c) 2014 Intel Corporation.<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the "Software"),<br>
> + * to deal in the Software without restriction, including without limitation<br>
> + * on the rights to use, copy, modify, merge, publish, distribute, sub<br>
> + * license, and/or sell copies of the Software, and to permit persons to whom<br>
> + * the Software is furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice (including the next<br>
> + * paragraph) shall be included in all copies or substantial portions of the<br>
> + * Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,<br>
> + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF<br>
> + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND<br>
> + * NON-INFRINGEMENT. IN NO EVENT SHALL VMWARE AND/OR THEIR SUPPLIERS<br>
> + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN<br>
> + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN<br>
> + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE<br>
> + * SOFTWARE.<br>
> + */<br>
> +<br>
> +<br>
> +/**<br>
> + * @file gettextureimage-formats.c<br>
> + *<br>
> + * Test glGetTexImage with a variety of formats.<br>
> + * Brian Paul<br>
> + * Sep 2011<br>
> + *<br>
> + * Adapted for testing glGetTextureImage in ARB_direct_state_access by<br>
> + * Laura Ekstrand <<a href="mailto:laura@jlekstrand.net">laura@jlekstrand.net</a>>, November 2014.<br>
> + */<br>
> +<br>
> +<br>
> +#include "piglit-util-gl.h"<br>
> +#include "../fbo/fbo-formats.h"<br>
> +<br>
> +PIGLIT_GL_TEST_CONFIG_BEGIN<br>
> +<br>
> + config.supports_gl_compat_version = 10;<br>
> +<br>
> + config.window_width = 600;<br>
> + config.window_height = 200;<br>
> + config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;<br>
> +<br>
> +PIGLIT_GL_TEST_CONFIG_END<br>
> +<br>
> +static const char *TestName = "gettextureimage-formats";<br>
> +<br>
> +static const GLfloat clearColor[4] = { 0.4, 0.4, 0.4, 0.0 };<br>
> +static GLuint texture_id;<br>
> +static GLboolean init_by_rendering;<br>
> +<br>
> +#define TEX_SIZE 128<br>
> +<br>
> +#define DO_BLEND 1<br>
> +<br>
> +<br>
> +/**<br>
> + * Make a simple texture image where red increases from left to right,<br>
> + * green increases from bottom to top, blue stays constant (50%) and<br>
> + * the alpha channel is a checkerboard pattern.<br>
> + * \return GL_TRUE for success, GL_FALSE if unsupported format<br>
> + */<br>
> +static GLboolean<br>
> +make_texture_image(GLenum intFormat, GLubyte upperRightTexel[4])<br>
> +{<br>
> + GLubyte tex[TEX_SIZE][TEX_SIZE][4];<br>
> + int i, j;<br>
> + GLuint fb, status;<br>
> +<br>
> + for (i = 0; i < TEX_SIZE; i++) {<br>
> + for (j = 0; j < TEX_SIZE; j++) {<br>
> + tex[i][j][0] = j * 255 / TEX_SIZE;<br>
> + tex[i][j][1] = i * 255 / TEX_SIZE;<br>
> + tex[i][j][2] = 128;<br>
> + if (((i >> 4) ^ (j >> 4)) & 1)<br>
> + tex[i][j][3] = 255; /* opaque */<br>
> + else<br>
> + tex[i][j][3] = 125; /* transparent */<br>
> + }<br>
> + }<br>
> +<br>
> + memcpy(upperRightTexel, tex[TEX_SIZE-1][TEX_SIZE-1], 4);<br>
> +<br>
> + if (init_by_rendering) {<br>
> + /* Initialize the mipmap levels. */<br>
> + for (i = TEX_SIZE, j = 0; i; i >>= 1, j++) {<br>
> + glTexImage2D(GL_TEXTURE_2D, j, intFormat, i, i, 0,<br>
> + GL_RGBA, GL_UNSIGNED_BYTE, NULL);<br>
> + }<br>
> +<br>
> + /* Initialize the texture with glDrawPixels. */<br>
> + glGenFramebuffers(1, &fb);<br>
> + glBindFramebuffer(GL_FRAMEBUFFER, fb);<br>
> + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,<br>
> + GL_TEXTURE_2D, texture_id, 0);<br>
> + status = glCheckFramebufferStatus(GL_FRAMEBUFFER);<br>
> + if (status != GL_FRAMEBUFFER_COMPLETE) {<br>
> + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);<br>
> + glDeleteFramebuffers(1, &fb);<br>
> + return GL_FALSE;<br>
> + }<br>
> +<br>
> + glViewport(0, 0, TEX_SIZE, TEX_SIZE);<br>
> +<br>
> + glWindowPos2iARB(0, 0);<br>
> + glDrawPixels(TEX_SIZE, TEX_SIZE, GL_RGBA, GL_UNSIGNED_BYTE, tex);<br>
> + glGenerateMipmap(GL_TEXTURE_2D);<br>
> +<br>
> + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);<br>
> + glDeleteFramebuffers(1, &fb);<br>
> + glViewport(0, 0, piglit_width, piglit_height);<br>
> + }<br>
> + else {<br>
> + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);<br>
> + glTexImage2D(GL_TEXTURE_2D, 0, intFormat, TEX_SIZE, TEX_SIZE, 0,<br>
> + GL_RGBA, GL_UNSIGNED_BYTE, tex);<br>
> + }<br>
> +<br>
> + return glGetError() == GL_NO_ERROR;<br>
> +}<br>
> +<br>
> +static GLfloat<br>
> +ubyte_to_float(GLubyte b, GLint bits)<br>
> +{<br>
> + if (bits <= 8) {<br>
> + GLint b2 = b >> (8 - bits);<br>
> + GLint max = 255 >> (8 - bits);<br>
> + return b2 / (float) max;<br>
> + }<br>
> + else {<br>
> + return b / 255.0;<br>
> + }<br>
> +}<br>
> +<br>
> +<br>
> +<br>
> +static GLfloat<br>
> +bits_to_tolerance(GLint bits, GLboolean compressed)<br>
> +{<br>
> + GLfloat t;<br>
> +<br>
> + if (bits == 0) {<br>
> + return 0.25;<br>
> + }<br>
> + else if (bits == 1) {<br>
> + return 0.5;<br>
> + }<br>
> + else if (bits > 8) {<br>
> + /* The original texture was specified as GLubyte and we<br>
> + * assume that the window/surface is 8-bits/channel.<br>
> + */<br>
> + t = 4.0 / 255;<br>
> + }<br>
> + else {<br>
> + t = 4.0 / (1 << (bits - 1));<br>
> + }<br>
> +<br>
> + if (compressed) {<br>
> + /* Use a fudge factor. The queries for GL_TEXTURE_RED/<br>
> + * GREEN/BLUE/ALPHA_SIZE don't return well-defined values for<br>
> + * compressed formats so using them is unreliable. This is<br>
> + * pretty loose, but good enough to catch some Mesa bugs during<br>
> + * development.<br>
> + */<br>
> + t = 0.3;<br>
> + }<br>
> + return t;<br>
> +}<br>
> +<br>
> +<br>
> +static void<br>
> +compute_expected_color(const struct format_desc *fmt,<br>
> + const GLubyte upperRightTexel[4],<br>
> + GLfloat expected[4], GLfloat tolerance[4])<br>
> +{<br>
> + GLfloat texel[4];<br>
> + GLint compressed;<br>
> + int bits[4];<br>
> +<br>
> + bits[0] = bits[1] = bits[2] = bits[3] = 0;<br>
> +<br>
> + /* Handle special cases first */<br>
> + if (fmt->internalformat == GL_R11F_G11F_B10F_EXT) {<br>
> + bits[0] = bits[1] = bits[2] = 8;<br>
> + bits[3] = 0;<br>
> + texel[0] = ubyte_to_float(upperRightTexel[0], bits[0]);<br>
> + texel[1] = ubyte_to_float(upperRightTexel[1], bits[1]);<br>
> + texel[2] = ubyte_to_float(upperRightTexel[2], bits[2]);<br>
> + texel[3] = 1.0;<br>
> + compressed = GL_FALSE;<br>
> + }<br>
> + else {<br>
> + GLint r, g, b, a, l, i;<br>
> + GLenum baseFormat = 0;<br>
> +<br>
> + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_RED_SIZE, &r);<br>
> + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_GREEN_SIZE, &g);<br>
> + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_BLUE_SIZE, &b);<br>
> + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_ALPHA_SIZE, &a);<br>
> + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_LUMINANCE_SIZE, &l);<br>
> + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTENSITY_SIZE, &i);<br>
> + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED, &compressed);<br>
> +<br>
> + if (0)<br>
> + printf("r=%d g=%d b=%d a=%d l=%d i=%d\n", r, g, b, a, l, i);<br>
> +<br>
> + if (i > 0) {<br>
> + baseFormat = GL_INTENSITY;<br>
> + bits[0] = i;<br>
> + bits[1] = 0;<br>
> + bits[2] = 0;<br>
> + bits[3] = i;<br>
> + texel[0] = ubyte_to_float(upperRightTexel[0], bits[0]);<br>
> + texel[1] = 0.0;<br>
> + texel[2] = 0.0;<br>
> + texel[3] = ubyte_to_float(upperRightTexel[0], bits[3]);<br>
> + }<br>
> + else if (a > 0) {<br>
> + if (l > 0) {<br>
> + baseFormat = GL_LUMINANCE_ALPHA;<br>
> + bits[0] = l;<br>
> + bits[1] = 0;<br>
> + bits[2] = 0;<br>
> + bits[3] = a;<br>
> + texel[0] = ubyte_to_float(upperRightTexel[0], bits[0]);<br>
> + texel[1] = 0.0;<br>
> + texel[2] = 0.0;<br>
> + texel[3] = ubyte_to_float(upperRightTexel[3], bits[3]);<br>
> + }<br>
> + else if (r > 0 && g > 0 && b > 0) {<br>
> + baseFormat = GL_RGBA;<br>
> + bits[0] = r;<br>
> + bits[1] = g;<br>
> + bits[2] = b;<br>
> + bits[3] = a;<br>
> + texel[0] = ubyte_to_float(upperRightTexel[0], bits[0]);<br>
> + texel[1] = ubyte_to_float(upperRightTexel[1], bits[1]);<br>
> + texel[2] = ubyte_to_float(upperRightTexel[2], bits[2]);<br>
> + texel[3] = ubyte_to_float(upperRightTexel[3], bits[3]);<br>
> + }<br>
> + else if (r == 0 && g == 0 && b == 0) {<br>
> + baseFormat = GL_ALPHA;<br>
> + bits[0] = 0;<br>
> + bits[1] = 0;<br>
> + bits[2] = 0;<br>
> + bits[3] = a;<br>
> + texel[0] = 0.0;<br>
> + texel[1] = 0.0;<br>
> + texel[2] = 0.0;<br>
> + texel[3] = ubyte_to_float(upperRightTexel[3], bits[3]);<br>
> + }<br>
> + else {<br>
> + baseFormat = 0; /* ??? */<br>
> + texel[0] = 0.0;<br>
> + texel[1] = 0.0;<br>
> + texel[2] = 0.0;<br>
> + texel[3] = 0.0;<br>
> + }<br>
> + }<br>
> + else if (l > 0) {<br>
> + baseFormat = GL_LUMINANCE;<br>
> + bits[0] = l;<br>
> + bits[1] = 0;<br>
> + bits[2] = 0;<br>
> + bits[3] = 0;<br>
> + texel[0] = ubyte_to_float(upperRightTexel[0], bits[0]);<br>
> + texel[1] = 0.0;<br>
> + texel[2] = 0.0;<br>
> + texel[3] = 1.0;<br>
> + }<br>
> + else if (r > 0) {<br>
> + if (g > 0) {<br>
> + if (b > 0) {<br>
> + baseFormat = GL_RGB;<br>
> + bits[0] = r;<br>
> + bits[1] = g;<br>
> + bits[2] = b;<br>
> + bits[3] = 0;<br>
> + texel[0] = ubyte_to_float(upperRightTexel[0], bits[0]);<br>
> + texel[1] = ubyte_to_float(upperRightTexel[1], bits[1]);<br>
> + texel[2] = ubyte_to_float(upperRightTexel[2], bits[2]);<br>
> + texel[3] = 1.0;<br>
> + }<br>
> + else {<br>
> + baseFormat = GL_RG;<br>
> + bits[0] = r;<br>
> + bits[1] = g;<br>
> + bits[2] = 0;<br>
> + bits[3] = 0;<br>
> + texel[0] = ubyte_to_float(upperRightTexel[0], bits[0]);<br>
> + texel[1] = ubyte_to_float(upperRightTexel[1], bits[1]);<br>
> + texel[2] = 0.0;<br>
> + texel[3] = 1.0;<br>
> + }<br>
> + }<br>
> + else {<br>
> + baseFormat = GL_RED;<br>
> + bits[0] = r;<br>
> + bits[1] = 0;<br>
> + bits[2] = 0;<br>
> + bits[3] = 0;<br>
> + texel[0] = ubyte_to_float(upperRightTexel[0], bits[0]);<br>
> + texel[1] = 0.0;<br>
> + texel[2] = 0.0;<br>
> + texel[3] = 1.0;<br>
> + }<br>
> + } else {<br>
> + assert(!"Unexpected texture component sizes");<br>
> + texel[0] = 0.0;<br>
> + texel[1] = 0.0;<br>
> + texel[2] = 0.0;<br>
> + texel[3] = 0.0;<br>
> + }<br>
> +<br>
> + (void) baseFormat; /* not used, at this time */<br>
> + }<br>
> +<br>
> + /* compute texel color blended with background color */<br>
> +#if DO_BLEND<br>
> + expected[0] = texel[0] * texel[3] + clearColor[0] * (1.0 - texel[3]);<br>
> + expected[1] = texel[1] * texel[3] + clearColor[1] * (1.0 - texel[3]);<br>
> + expected[2] = texel[2] * texel[3] + clearColor[2] * (1.0 - texel[3]);<br>
> + expected[3] = texel[3] * texel[3] + clearColor[3] * (1.0 - texel[3]);<br>
> +#else<br>
> + expected[0] = texel[0];<br>
> + expected[1] = texel[1];<br>
> + expected[2] = texel[2];<br>
> + expected[3] = texel[3];<br>
> +#endif<br>
> +<br>
> + assert(expected[0] == expected[0]);<br>
> +<br>
> + tolerance[0] = bits_to_tolerance(bits[0], compressed);<br>
> + tolerance[1] = bits_to_tolerance(bits[1], compressed);<br>
> + tolerance[2] = bits_to_tolerance(bits[2], compressed);<br>
> + tolerance[3] = bits_to_tolerance(bits[3], compressed);<br>
> +}<br>
> +<br>
> +<br>
> +static GLboolean<br>
> +colors_equal(const GLfloat expected[4], const GLfloat pix[4],<br>
> + GLfloat tolerance[4])<br>
> +{<br>
> + if (fabsf(expected[0] - pix[0]) > tolerance[0] ||<br>
> + fabsf(expected[1] - pix[1]) > tolerance[1] ||<br>
> + fabsf(expected[2] - pix[2]) > tolerance[2] ||<br>
> + fabsf(expected[3] - pix[3]) > tolerance[3]) {<br>
> + return GL_FALSE;<br>
> + }<br>
> + return GL_TRUE;<br>
> +}<br>
> +<br>
> +<br>
> +static GLboolean<br>
> +test_format(const struct test_desc *test,<br>
> + const struct format_desc *fmt)<br>
> +{<br>
> + int x, y;<br>
> + int w = TEX_SIZE, h = TEX_SIZE;<br>
> + GLfloat readback[TEX_SIZE][TEX_SIZE][4];<br>
> + GLubyte upperRightTexel[4];<br>
> + int level;<br>
> + GLfloat expected[4], pix[4], tolerance[4];<br>
> + GLboolean pass = GL_TRUE;<br>
> +<br>
> + glClear(GL_COLOR_BUFFER_BIT);<br>
> +<br>
> + /* The RGBA_DXT1 formats seem to expose a Mesa/libtxc_dxtn bug.<br>
> + * Just skip them for now. Testing the other compressed formats<br>
> + * is good enough.<br>
> + */<br>
> + if (fmt->internalformat != GL_COMPRESSED_RGBA_S3TC_DXT1_EXT &&<br>
> + fmt->internalformat != GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT) {<br>
> + /* init texture image */<br>
> + if (!make_texture_image(fmt->internalformat, upperRightTexel))<br>
> + return GL_TRUE; /* unsupported = OK */<br>
> +<br>
> + x = 10;<br>
> + y = 40;<br>
> +<br>
> + compute_expected_color(fmt, upperRightTexel, expected, tolerance);<br>
> +<br>
> + /* Draw with the texture */<br>
> + glEnable(GL_TEXTURE_2D);<br>
> +#if DO_BLEND<br>
> + glEnable(GL_BLEND);<br>
> +#endif<br>
> + piglit_draw_rect_tex(x, y, w, h, 0.0, 0.0, 1.0, 1.0);<br>
> + glDisable(GL_TEXTURE_2D);<br>
> + glDisable(GL_BLEND);<br>
> +<br>
> + x += TEX_SIZE + 20;<br>
> +<br>
> + level = 0;<br>
> + while (w > 0) {<br>
> + /* Get the texture image */<br>
> + assert(!glIsEnabled(GL_TEXTURE_2D));<br>
> + glGetTextureImage(texture_id, level, GL_RGBA,<br>
> + GL_FLOAT, sizeof(readback),<br>
> + readback);<br>
> +<br>
> + assert(!glIsEnabled(GL_TEXTURE_2D));<br>
> + /* Draw the texture image */<br>
> + glWindowPos2iARB(x, y);<br>
> +#if DO_BLEND<br>
> + glEnable(GL_BLEND);<br>
> +#endif<br>
> + assert(!glIsEnabled(GL_TEXTURE_2D));<br>
> + glDrawPixels(w, h, GL_RGBA, GL_FLOAT, readback);<br>
> + glDisable(GL_BLEND);<br>
> +<br>
> + assert(!glIsEnabled(GL_TEXTURE_2D));<br>
> +<br>
> + if (level <= 2) {<br>
> + GLint rx = x + w-1;<br>
> + GLint ry = y + h-1;<br>
> + glReadPixels(rx, ry, 1, 1, GL_RGBA, GL_FLOAT, pix);<br>
> + if (!colors_equal(expected, pix, tolerance)) {<br>
> + printf("%s failure: format: %s, level %d at pixel(%d, %d)\n",<br>
> + TestName, fmt->name, level, rx, ry);<br>
> + printf(" Expected (%f, %f, %f, %f)\n",<br>
> + expected[0], expected[1], expected[2], expected[3]);<br>
> + printf(" Found (%f, %f, %f, %f)\n",<br>
> + pix[0], pix[1], pix[2], pix[3]);<br>
> + printf("Tolerance (%f, %f, %f, %f)\n",<br>
> + tolerance[0], tolerance[1], tolerance[2], tolerance[3]);<br>
> + pass = GL_FALSE;<br>
> + }<br>
> + }<br>
> +<br>
> + x += w + 20;<br>
> + w /= 2;<br>
> + h /= 2;<br>
> + level++;<br>
> + }<br>
> +<br>
> + }<br>
> +<br>
> + piglit_present_results();<br>
> +<br>
> + return pass;<br>
> +}<br>
> +<br>
> +<br>
> +/**<br>
> + * Is the given set of formats supported?<br>
> + * This checks if required extensions are present and if this piglit test<br>
> + * can actually grok the formats.<br>
> + */<br>
> +static GLboolean<br>
> +supported_format_set(const struct test_desc *set)<br>
> +{<br>
> + if (!supported(set))<br>
> + return GL_FALSE;<br>
> +<br>
> + if (set->format == ext_texture_integer ||<br>
> + set->format == ext_packed_depth_stencil ||<br>
> + set->format == arb_texture_rg_int ||<br>
> + set->format == arb_depth_texture ||<br>
> + set->format == arb_depth_buffer_float) {<br>
> + /*<br>
> + * texture_integer requires a fragment shader, different<br>
> + * glTexImage calls. Depth/stencil formats not implemented.<br>
> + */<br>
> + return GL_FALSE;<br>
> + }<br>
> +<br>
> + return GL_TRUE;<br>
> +}<br>
> +<br>
> +<br>
> +static GLboolean<br>
> +test_all_formats(void)<br>
> +{<br>
> + GLboolean pass = GL_TRUE;<br>
> + int i, j;<br>
> +<br>
> + for (i = 0; i < ARRAY_SIZE(test_sets); i++) {<br>
> + const struct test_desc *set = &test_sets[i];<br>
> + if (supported_format_set(set)) {<br>
> + for (j = 0; j < set->num_formats; j++) {<br>
> + if (!test_format(set, &set->format[j])) {<br>
> + pass = GL_FALSE;<br>
> + }<br>
> + }<br>
> + }<br>
> + }<br>
> +<br>
> + return pass;<br>
> +}<br>
> +<br>
> +<br>
> +enum piglit_result<br>
> +piglit_display(void)<br>
> +{<br>
> + GLboolean pass;<br>
> +<br>
> + piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);<br>
> +<br>
> + if (piglit_automatic) {<br>
> + pass = test_all_formats();<br>
> + }<br>
> + else {<br>
> + const struct test_desc *set = &test_sets[test_index];<br>
> + if (supported_format_set(set)) {<br>
> + pass = test_format(set, &set->format[format_index]);<br>
> + }<br>
> + else {<br>
> + /* unsupported format - not a failure */<br>
> + pass = GL_TRUE;<br>
> + glClear(GL_COLOR_BUFFER_BIT);<br>
> + piglit_present_results();<br>
> + }<br>
> + }<br>
> +<br>
> + return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
> +}<br>
> +<br>
> +void<br>
> +piglit_init(int argc, char **argv)<br>
> +{<br>
> + int i;<br>
> +<br>
> + piglit_require_extension("GL_ARB_direct_state_access");<br>
> +<br>
> + if ((piglit_get_gl_version() < 14) && !piglit_is_extension_supported("GL_ARB_window_pos")) {<br>
> + printf("Requires GL 1.4 or GL_ARB_window_pos");<br>
> + piglit_report_result(PIGLIT_SKIP);<br>
> + }<br>
> +<br>
> + fbo_formats_init(1, argv, !piglit_automatic);<br>
> + (void) fbo_formats_display;<br>
> +<br>
> + for (i = 1; i < argc; i++) {<br>
> + if (strcmp(argv[i], "init-by-rendering") == 0) {<br>
> + init_by_rendering = GL_TRUE;<br>
> + puts("The textures will be initialized by rendering "<br>
> + "to them using glDrawPixels.");<br>
> + break;<br>
> + }<br>
> + }<br>
> +<br>
> + glGenTextures(1, &texture_id);<br>
> + glBindTexture(GL_TEXTURE_2D, texture_id);<br>
> + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);<br>
> + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);<br>
> +<br>
> + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);<br>
> +<br>
> + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);<br>
> +<br>
> + glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);<br>
> +}<br>
> diff --git a/tests/spec/arb_direct_state_access/gettextureimage-luminance.c b/tests/spec/arb_direct_state_access/gettextureimage-luminance.c<br>
> new file mode 100644<br>
> index 0000000..3add1d7<br>
> --- /dev/null<br>
> +++ b/tests/spec/arb_direct_state_access/gettextureimage-luminance.c<br>
> @@ -0,0 +1,260 @@<br>
> +/*<br>
> + * Copyright (c) 2012 VMware, Inc.<br>
> + * Copyright (c) 2014 Intel Corporation<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the "Software"),<br>
> + * to deal in the Software without restriction, including without limitation<br>
> + * on the rights to use, copy, modify, merge, publish, distribute, sub<br>
> + * license, and/or sell copies of the Software, and to permit persons to whom<br>
> + * the Software is furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice (including the next<br>
> + * paragraph) shall be included in all copies or substantial portions of the<br>
> + * Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,<br>
> + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF<br>
> + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND<br>
> + * NON-INFRINGEMENT. IN NO EVENT SHALL VMWARE AND/OR THEIR SUPPLIERS<br>
> + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN<br>
> + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN<br>
> + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE<br>
> + * SOFTWARE.<br>
> + */<br>
> +<br>
> +/*<br>
> + * Test glGetTexImage for luminance formats.<br>
> + * Brian Paul<br>
> + * 8 Mar 2012<br>
> + *<br>
> + * Adapted for testing glGetTextureImage in ARB_direct_state_access by<br>
> + * Laura Ekstrand <<a href="mailto:laura@jlekstrand.net">laura@jlekstrand.net</a>>, November 2014.<br>
> + */<br>
> +<br>
> +#include "piglit-util-gl.h"<br>
> +<br>
> +PIGLIT_GL_TEST_CONFIG_BEGIN<br>
> +<br>
> + config.supports_gl_compat_version = 10;<br>
> +<br>
> + config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;<br>
> +<br>
> +PIGLIT_GL_TEST_CONFIG_END<br>
> +<br>
> +static const char *TestName = "gettextureimage-luminance";<br>
> +static float tolerance = 3.0 / 255.0;<br>
> +<br>
> +<br>
> +static bool<br>
> +rgba_equal(const float *c1, const float *c2)<br>
> +{<br>
> + return ((fabs(c1[0] - c2[0]) < tolerance) &&<br>
> + (fabs(c1[1] - c2[1]) < tolerance) &&<br>
> + (fabs(c1[2] - c2[2]) < tolerance) &&<br>
> + (fabs(c1[3] - c2[3]) < tolerance));<br>
> +}<br>
> +<br>
> +<br>
> +static bool<br>
> +lum_equal(const float *l1, const float *l2)<br>
> +{<br>
> + return fabs(*l1 - *l2) < tolerance;<br>
> +}<br>
> +<br>
> +<br>
> +/*<br>
> + * Test reading back a luminance texture as luminance and RGBA.<br>
> + */<br>
> +static bool<br>
> +test_luminance(void)<br>
> +{<br>
> + static const GLfloat lumImage[2*2] = { 0.25, 0.25, 0.25, 0.25 };<br>
> + static const GLfloat rgbaImage[4] = { 0.25, 0.0, 0.0, 1.0 };<br>
> + GLuint tex;<br>
> + GLfloat test[2*2*4];<br>
> +<br>
> + /* create 2x2 GL_LUMINANCE texture */<br>
> + glGenTextures(1, &tex);<br>
> + glBindTexture(GL_TEXTURE_2D, tex);<br>
> + glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 2, 2, 0,<br>
> + GL_LUMINANCE, GL_FLOAT, lumImage);<br>
> +<br>
> + /* Get and check luminance image */<br>
> + glGetTextureImage(tex, 0, GL_LUMINANCE, GL_FLOAT, sizeof(test), test);<br>
> + if (!lum_equal(lumImage, test)) {<br>
> + printf("%s: glGetTextureImage(GL_LUMINANCE as"<br>
> + " GL_LUMINANCE) failed\n", TestName);<br>
> + printf(" Expected %g Found %g\n", lumImage[0], test[0]);<br>
> + return false;<br>
> + }<br>
> +<br>
> + /* Get and check rgba image */<br>
> + glGetTextureImage(tex, 0, GL_RGBA, GL_FLOAT, sizeof(test), &test);<br>
> + if (!rgba_equal(rgbaImage, test)) {<br>
> + printf("%s: glGetTextureImage(GL_LUMINANCE as"<br>
> + " GL_RGBA) failed\n", TestName);<br>
> + printf(" Expected %g, %g, %g, %g Found %g, %g, %g, %g\n",<br>
> + rgbaImage[0], rgbaImage[1], rgbaImage[2], rgbaImage[3],<br>
> + test[0], test[1], test[2], test[3]);<br>
> + return false;<br>
> + }<br>
> +<br>
> + return true;<br>
> +}<br>
> +<br>
> +<br>
> +/*<br>
> + * Test reading back an RGBA texture as luminance.<br>
> + */<br>
> +static bool<br>
> +test_rgba(void)<br>
> +{<br>
> + static const GLfloat rgbaImage[4] = { 0.5, 0.25, 0.125, 1.0 };<br>
> + static const GLfloat lumImage[1] = { 0.5 };<br>
> + GLuint tex;<br>
> + GLfloat test[2*2*4];<br>
> +<br>
> + /* create 1x1 GL_RGBA texture */<br>
> + glGenTextures(1, &tex);<br>
> + glBindTexture(GL_TEXTURE_2D, tex);<br>
> + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0,<br>
> + GL_RGBA, GL_FLOAT, rgbaImage);<br>
> +<br>
> + /* Get and check luminance image */<br>
> + glGetTextureImage(tex, 0, GL_LUMINANCE, GL_FLOAT, sizeof(test), test);<br>
> + if (!lum_equal(lumImage, test)) {<br>
> + printf("%s: glGetTextureImage(GL_RGBA as"<br>
> + " GL_LUMINANCE) failed\n", TestName);<br>
> + printf(" Expected %g Found %g\n", lumImage[0], test[0]);<br>
> + return false;<br>
> + }<br>
> +<br>
> + return true;<br>
> +}<br>
> +<br>
> +<br>
> +/*<br>
> + * Test reading back a luminance texture via FBO + glReadPixels as RGBA.<br>
> + */<br>
> +static bool<br>
> +test_fbo_readpixels_lum_as_rgba(void)<br>
> +{<br>
> + static const GLfloat lumImage[2*2] = { 0.25, 0.25, 0.25, 0.25 };<br>
> + static const GLfloat rgbaImage[4] = { 0.25, 0.0, 0.0, 1.0 };<br>
> + GLuint tex, fbo;<br>
> + GLfloat test[2*2*4];<br>
> + GLenum status;<br>
> +<br>
> + if (!piglit_is_extension_supported("GL_ARB_framebuffer_object"))<br>
> + return true;<br>
> +<br>
> + /* create 2x2 GL_LUMINANCE texture */<br>
> + glGenTextures(1, &tex);<br>
> + glBindTexture(GL_TEXTURE_2D, tex);<br>
> + glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 2, 2, 0,<br>
> + GL_LUMINANCE, GL_FLOAT, lumImage);<br>
> +<br>
> + /* create an FBO to wrap the texture so we can read it back<br>
> + * with glReadPixels<br>
> + */<br>
> + glGenFramebuffers(1, &fbo);<br>
> + glBindFramebuffer(GL_FRAMEBUFFER, fbo);<br>
> + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT,<br>
> + GL_TEXTURE_2D, tex, 0);<br>
> +<br>
> + status = glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);<br>
> + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {<br>
> + /* can't test glReadPixels from a luminance fbo/texture */<br>
> + if (!piglit_automatic) {<br>
> + printf("Skipping FBO ReadPixels test\n");<br>
> + }<br>
> + return true;<br>
> + }<br>
> +<br>
> + /* get rgba image (only red should have the lum value) */<br>
> + glReadPixels(0, 0, 1, 1, GL_RGBA, GL_FLOAT, test);<br>
> + if (!rgba_equal(rgbaImage, test)) {<br>
> + printf("%s: glReadPixels(GL_LUMINANCE as GL_RGBA) failed\n",<br>
> + TestName);<br>
> + printf(" Expected %g, %g, %g, %g Found %g, %g, %g, %g\n",<br>
> + rgbaImage[0], rgbaImage[1], rgbaImage[2], rgbaImage[3],<br>
> + test[0], test[1], test[2], test[3]);<br>
> + return false;<br>
> + }<br>
> +<br>
> + return true;<br>
> +}<br>
> +<br>
> +<br>
> +/*<br>
> + * Test reading back an RGBA texture via FBO + glReadPixels as luminance.<br>
> + */<br>
> +static bool<br>
> +test_fbo_readpixels_rgba_as_lum(void)<br>
> +{<br>
> + static const GLfloat rgbaImage[4] = { 0.5, 0.25, 0.125, 1.0 };<br>
> + static const GLfloat lumImage[1] = { 0.5 + 0.25 + 0.125 };<br>
> + GLuint tex, fbo;<br>
> + GLfloat test[1];<br>
> + GLenum status;<br>
> +<br>
> + if (!piglit_is_extension_supported("GL_ARB_framebuffer_object"))<br>
> + return true;<br>
> +<br>
> + /* create 1x1 GL_RGBA texture */<br>
> + glGenTextures(1, &tex);<br>
> + glBindTexture(GL_TEXTURE_2D, tex);<br>
> + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0,<br>
> + GL_RGBA, GL_FLOAT, rgbaImage);<br>
> +<br>
> + /* create an FBO to wrap the texture so we can read it back<br>
> + * with glReadPixels<br>
> + */<br>
> + glGenFramebuffers(1, &fbo);<br>
> + glBindFramebuffer(GL_FRAMEBUFFER, fbo);<br>
> + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT,<br>
> + GL_TEXTURE_2D, tex, 0);<br>
> +<br>
> + status = glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);<br>
> + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {<br>
> + /* something failed with FBO setup, ignore it */<br>
> + if (!piglit_automatic) {<br>
> + printf("Skipping FBO ReadPixels test\n");<br>
> + }<br>
> + return true;<br>
> + }<br>
> +<br>
> + /* get luminance image, should be sum of RGB values */<br>
> + glReadPixels(0, 0, 1, 1, GL_LUMINANCE, GL_FLOAT, test);<br>
> + if (!lum_equal(lumImage, test)) {<br>
> + printf("%s: glReadPixels(GL_RGBA as GL_LUMINANCE) failed\n",<br>
> + TestName);<br>
> + printf(" Expected %g Found %g\n", lumImage[0], test[0]);<br>
> + return false;<br>
> + }<br>
> +<br>
> + return true;<br>
> +}<br>
> +<br>
> +<br>
> +enum piglit_result<br>
> +piglit_display(void)<br>
> +{<br>
> + bool pass = true;<br>
> +<br>
> + pass = test_luminance() && pass;<br>
> + pass = test_rgba() && pass;<br>
> + pass = test_fbo_readpixels_lum_as_rgba() && pass;<br>
> + pass = test_fbo_readpixels_rgba_as_lum() && pass;<br>
> +<br>
> + return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
> +}<br>
> +<br>
> +<br>
> +void<br>
> +piglit_init(int argc, char **argv)<br>
> +{<br>
> + piglit_require_extension("GL_ARB_direct_state_access");<br>
> + piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);<br>
> +}<br>
> diff --git a/tests/spec/arb_direct_state_access/gettextureimage-simple.c b/tests/spec/arb_direct_state_access/gettextureimage-simple.c<br>
> new file mode 100644<br>
> index 0000000..081caaa<br>
> --- /dev/null<br>
> +++ b/tests/spec/arb_direct_state_access/gettextureimage-simple.c<br>
> @@ -0,0 +1,86 @@<br>
> +/**<br>
> + * @file gettextureimage-simple.c<br>
> + *<br>
> + * Extremely basic test to check whether image data can be retrieved.<br>
> + *<br>
> + * Note that the texture is used in a full frame of rendering before<br>
> + * the readback, to ensure that buffer manager related code for uploading<br>
> + * texture images is executed before the readback.<br>
> + *<br>
> + * This used to crash for R300+bufmgr.<br>
> + *<br>
> + * Adapted for testing glGetTextureImage in ARB_direct_state_access by<br>
> + * Laura Ekstrand <<a href="mailto:laura@jlekstrand.net">laura@jlekstrand.net</a>>, November 2014.<br>
> + */<br>
> +<br>
> +#include "piglit-util-gl.h"<br>
> +<br>
> +PIGLIT_GL_TEST_CONFIG_BEGIN<br>
> +<br>
> + config.supports_gl_compat_version = 10;<br>
> +<br>
> + config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;<br>
> +<br>
> +PIGLIT_GL_TEST_CONFIG_END<br>
> +<br>
> +static GLubyte data[4096]; /* 64*16*4 */<br>
> +static GLuint name; /* texture name */<br>
> +<br>
> +static int test_getteximage(void)<br>
> +{<br>
> + GLubyte compare[4096];<br>
> + int i;<br>
> +<br>
> + glGetTextureImage(name, 0, GL_RGBA, GL_UNSIGNED_BYTE,<br>
> + sizeof(compare), compare);<br>
> +<br>
> + for(i = 0; i < 4096; ++i) {<br>
> + if (data[i] != compare[i]) {<br>
> + printf("GetTextureImage() returns incorrect data in byte %i\n", i);<br>
> + printf(" corresponding to (%i,%i) channel %i\n", i / 64, (i / 4) % 16, i % 4);<br>
> + printf(" expected: %i\n", data[i]);<br>
> + printf(" got: %i\n", compare[i]);<br>
> + return 0;<br>
> + }<br>
> + }<br>
> +<br>
> + return 1;<br>
> +}<br>
> +<br>
> +enum piglit_result<br>
> +piglit_display(void)<br>
> +{<br>
> + int pass;<br>
> +<br>
> + glClearColor(0.0, 0.0, 0.0, 1.0);<br>
> + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);<br>
> +<br>
> + glEnable(GL_TEXTURE_2D);<br>
> + glBindTextureUnit(0, name);<br>
> + piglit_draw_rect_tex(0, 0, 1, 1, 0, 0, 1, 1);<br>
> +<br>
> + piglit_present_results();<br>
> +<br>
> + pass = test_getteximage();<br>
> +<br>
> + return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
> +}<br>
> +<br>
> +void<br>
> +piglit_init(int argc, char **argv)<br>
> +{<br>
> + int i;<br>
> + piglit_require_extension("GL_ARB_direct_state_access");<br>
> +<br>
> + for(i = 0; i < 4096; ++i)<br>
> + data[i] = rand() & 0xff;<br>
> +<br>
> + glCreateTextures(GL_TEXTURE_2D, 1, &name);<br>
> + glTextureParameteri(name, GL_TEXTURE_MAG_FILTER, GL_LINEAR);<br>
> + glTextureParameteri(name, GL_TEXTURE_MIN_FILTER, GL_LINEAR);<br>
> + glTextureStorage2D(name, 1, GL_RGBA8, 64, 16);<br>
> + glTextureSubImage2D(name, 0, 0, 0, 64, 16, GL_RGBA, GL_UNSIGNED_BYTE,<br>
> + data);<br>
> +<br>
> + piglit_gen_ortho_projection(0.0, 1.0, 0.0, 1.0, -2.0, 6.0, GL_FALSE);<br>
> +}<br>
> diff --git a/tests/spec/arb_direct_state_access/gettextureimage-targets.c b/tests/spec/arb_direct_state_access/gettextureimage-targets.c<br>
> new file mode 100644<br>
> index 0000000..b827a12<br>
> --- /dev/null<br>
> +++ b/tests/spec/arb_direct_state_access/gettextureimage-targets.c<br>
> @@ -0,0 +1,305 @@<br>
> +/*<br>
> + * Copyright © 2012 Marek Olšák <<a href="mailto:maraeo@gmail.com">maraeo@gmail.com</a>><br>
> + * Copyright © 2014 Intel Corporation<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the "Software"),<br>
> + * to deal in the Software without restriction, including without limitation<br>
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> + * and/or sell copies of the Software, and to permit persons to whom the<br>
> + * Software is furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice (including the next<br>
> + * paragraph) shall be included in all copies or substantial portions of the<br>
> + * Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
> + * IN THE SOFTWARE.<br>
> + */<br>
> +<br>
> +/**<br>
> + * @file gettextureimage-targets.c<br>
> + *<br>
> + * Adapted for testing glGetTextureImage in ARB_direct_state_access by<br>
> + * Laura Ekstrand <<a href="mailto:laura@jlekstrand.net">laura@jlekstrand.net</a>>, November 2014.<br>
> + */<br>
> +<br>
> +#include "piglit-util-gl.h"<br>
> +<br>
> +PIGLIT_GL_TEST_CONFIG_BEGIN<br>
> +<br>
> + config.supports_gl_compat_version = 10;<br>
> +<br>
> + config.window_visual = PIGLIT_GL_VISUAL_RGBA |<br>
> + PIGLIT_GL_VISUAL_DOUBLE;<br>
> +<br>
> +PIGLIT_GL_TEST_CONFIG_END<br>
> +<br>
> +#define IMAGE_WIDTH 32<br>
> +#define IMAGE_HEIGHT 32<br>
> +#define IMAGE_SIZE (IMAGE_WIDTH * IMAGE_HEIGHT * 4)<br>
> +<br>
> +static void<br>
> +init_layer_data(GLubyte *layer_data, int num_layers)<br>
> +{<br>
> + int x, y, z, i, j;<br>
> +<br>
> + for (z = 0; z < num_layers; z++) {<br>
> + GLubyte *data = layer_data + IMAGE_SIZE * z;<br>
> +<br>
> + for (x = 0; x < IMAGE_WIDTH; x += 4) {<br>
> + for (y = 0; y < IMAGE_HEIGHT; y += 4) {<br>
> + int r = (x + 1) * 255 / (IMAGE_WIDTH - 1);<br>
> + int g = (y + 1) * 255 / (IMAGE_HEIGHT - 1);<br>
> + int b = (z + 1) * 255 / (num_layers - 1);<br>
> + int a = x ^ y ^ z;<br>
> +<br>
> + /* each 4x4 block constains only one color (for S3TC) */<br>
> + for (i = 0; i < 4; i++) {<br>
> + for (j = 0; j < 4; j++) {<br>
> + data[((y + j) * IMAGE_WIDTH + x<br>
> + + i) * 4 + 0] = r;<br>
> + data[((y + j) * IMAGE_WIDTH + x<br>
> + + i) * 4 + 1] = g;<br>
> + data[((y + j) * IMAGE_WIDTH + x<br>
> + + i) * 4 + 2] = b;<br>
> + data[((y + j) * IMAGE_WIDTH + x<br>
> + + i) * 4 + 3] = a;<br>
> + }<br>
> + }<br>
> + }<br>
> + }<br>
> + }<br>
> +}<br>
> +<br>
> +static bool<br>
> +compare_layer(int layer, int num_elements, int tolerance,<br>
> + GLubyte *data, GLubyte *expected)<br>
> +{<br>
> + int i;<br>
> +<br>
> + for (i = 0; i < num_elements; ++i) {<br>
> + if (abs((int)data[i] - (int)expected[i]) > tolerance) {<br>
> + printf("GetTextureImage() returns incorrect data in byte %i for layer %i\n",<br>
> + i, layer);<br>
> + printf(" corresponding to (%i,%i), channel %i\n",<br>
> + (i / 4) / IMAGE_WIDTH, (i / 4) % IMAGE_HEIGHT, i % 4);<br>
> + printf(" expected: %i\n", expected[i]);<br>
> + printf(" got: %i\n", data[i]);<br>
> + return false;<br>
> + }<br>
> + }<br>
> + return true;<br>
> +}<br>
> +<br>
> +static bool<br>
> +getTexImage(bool doPBO, GLenum target, GLubyte data[][IMAGE_SIZE],<br>
> + GLenum internalformat, int tolerance)<br>
> +{<br>
> + int i;<br>
> + int num_layers=1, num_faces=1, layer_size;<br>
> + GLubyte data2[18][IMAGE_SIZE];<br>
> + GLubyte *dataGet;<br>
> + GLuint packPBO;<br>
> + bool pass = true;<br>
> + GLuint name;<br>
> +<br>
> + switch (target) {<br>
> + case GL_TEXTURE_1D:<br>
> + glCreateTextures(target, 1, &name);<br>
> + glTextureStorage1D(name, 1, internalformat, IMAGE_WIDTH);<br>
> + glTextureSubImage1D(name, 0, 0, IMAGE_WIDTH, GL_RGBA,<br>
> + GL_UNSIGNED_BYTE, data);<br>
> + layer_size = IMAGE_WIDTH * 4;<br>
> + break;<br>
> +<br>
> + case GL_TEXTURE_2D:<br>
> + case GL_TEXTURE_RECTANGLE:<br>
> + glCreateTextures(target, 1, &name);<br>
> + glTextureStorage2D(name, 1, internalformat, IMAGE_WIDTH,<br>
> + IMAGE_HEIGHT);<br>
> + glTextureSubImage2D(name, 0, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT,<br>
> + GL_RGBA, GL_UNSIGNED_BYTE, data);<br>
> + layer_size = IMAGE_SIZE;<br>
> + break;<br>
> +<br>
> + case GL_TEXTURE_CUBE_MAP:<br>
> + num_faces = 6;<br>
> + glCreateTextures(target, 1, &name);<br>
> + /* This is invalid. You must use 2D storage call for cube. */<br>
> + glTextureStorage3D(name, 1, internalformat,<br>
> + IMAGE_WIDTH, IMAGE_HEIGHT, num_faces);<br>
> + pass &= piglit_check_gl_error(GL_INVALID_ENUM);<br>
> + glTextureStorage2D(name, 1, internalformat,<br>
> + IMAGE_WIDTH, IMAGE_HEIGHT);<br>
> + /* This is legal. */<br>
> + glTextureSubImage3D(name, 0, 0, 0, 0, IMAGE_WIDTH,<br>
> + IMAGE_HEIGHT, num_faces, GL_RGBA,<br>
> + GL_UNSIGNED_BYTE, data);<br>
> + layer_size = IMAGE_SIZE;<br>
> + break;<br>
> +<br>
> + case GL_TEXTURE_1D_ARRAY:<br>
> + num_layers = 7;<br>
> + glCreateTextures(target, 1, &name);<br>
> + // test as a single layer 2D image<br>
> + glTextureStorage2D(name, 1, internalformat, IMAGE_WIDTH,<br>
> + num_layers);<br>
> + glTextureSubImage2D(name, 0, 0, 0, IMAGE_WIDTH, num_layers,<br>
> + GL_RGBA, GL_UNSIGNED_BYTE, data);<br>
> + layer_size = IMAGE_WIDTH * 4 * num_layers;<br>
> + num_layers = 1;<br>
> + break;<br>
> +<br>
> + case GL_TEXTURE_3D:<br>
> + num_layers = 16; /* Fall through. */<br>
> + case GL_TEXTURE_2D_ARRAY:<br>
> + num_layers = 7; /* Fall through. */<br>
> + case GL_TEXTURE_CUBE_MAP_ARRAY:<br>
> + num_layers = 6 * 3;<br>
> + glCreateTextures(target, 1, &name);<br>
> + glTextureStorage3D(name, 1, internalformat, IMAGE_WIDTH,<br>
> + IMAGE_HEIGHT, num_layers);<br>
> + glTextureSubImage3D(name, 0, 0, 0, 0,<br>
> + IMAGE_WIDTH, IMAGE_HEIGHT, num_layers,<br>
> + GL_RGBA, GL_UNSIGNED_BYTE, data);<br>
> + layer_size = IMAGE_SIZE;<br>
> + break;<br>
> +<br>
> + default:<br>
> + puts("Invalid texture target.");<br>
> + return false;<br>
> +<br>
> + }<br>
> +<br>
> + /* Setup the PBO or data array to read into from glGetTextureImage */<br>
> + if (doPBO) {<br>
> + glGenBuffers(1, &packPBO);<br>
> + glBindBuffer(GL_PIXEL_PACK_BUFFER, packPBO);<br>
> + glBufferData(GL_PIXEL_PACK_BUFFER,<br>
> + layer_size * num_faces * num_layers,<br>
> + NULL, GL_STREAM_READ);<br>
> + } else {<br>
> + glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);<br>
> + memset(data2, 123, sizeof(data2));<br>
> + }<br>
> + pass = piglit_check_gl_error(GL_NO_ERROR) && pass;<br>
> + assert(num_layers * num_faces * layer_size <= sizeof(data2));<br>
> +<br>
> + if (doPBO) {<br>
> + glGetTextureImage(name, 0, GL_RGBA, GL_UNSIGNED_BYTE,<br>
> + layer_size * num_faces * num_layers, NULL);<br>
> + }<br>
> + else {<br>
> + glGetTextureImage(name, 0, GL_RGBA, GL_UNSIGNED_BYTE,<br>
> + layer_size * num_faces * num_layers, data2);<br>
> + }<br>
> + pass = piglit_check_gl_error(GL_NO_ERROR) && pass;<br>
> +<br>
> + if (doPBO)<br>
> + dataGet = (GLubyte *) glMapBufferRange(<br>
> + GL_PIXEL_PACK_BUFFER, 0,<br>
> + layer_size * num_layers *<br>
> + num_faces,<br>
> + GL_MAP_READ_BIT);<br>
> + else<br>
> + dataGet = data2[0];<br>
> +<br>
> + for (i = 0; i < num_faces * num_layers; i++) {<br>
> + pass = compare_layer(i, layer_size, tolerance, dataGet,<br>
> + data[i]) && pass;<br>
> + dataGet += layer_size;<br>
> + }<br>
> +<br>
> + if (doPBO) {<br>
> + glUnmapBuffer(GL_PIXEL_PACK_BUFFER);<br>
> + glDeleteBuffers(1, &packPBO);<br>
> + }<br>
> +<br>
> + glDeleteTextures(1, &name);<br>
> +<br>
> + return pass;<br>
> +}<br>
> +<br>
> +struct target_and_mask {<br>
> + GLenum target;<br>
> + bool mask;<br>
> +};<br>
> +<br>
> +static struct target_and_mask targets[] = {<br>
> + {GL_TEXTURE_1D, 1},<br>
> + {GL_TEXTURE_2D, 1},<br>
> + {GL_TEXTURE_3D, 1},<br>
> + {GL_TEXTURE_RECTANGLE, 1},<br>
> + {GL_TEXTURE_CUBE_MAP, 1},<br>
> + {GL_TEXTURE_1D_ARRAY, 1},<br>
> + {GL_TEXTURE_2D_ARRAY, 1},<br>
> + {GL_TEXTURE_CUBE_MAP_ARRAY, 1},<br>
> +};<br>
> +<br>
> +static void<br>
> +clear_target_mask(GLenum target)<br>
> +{<br>
> + int i;<br>
> + for (i = 0; i < ARRAY_SIZE(targets); ++i) {<br>
> + if (targets[i].target == target) {<br>
> + targets[i].mask = 0;<br>
> + }<br>
> + }<br>
> +}<br>
> +<br>
> +void<br>
> +piglit_init(int argc, char **argv)<br>
> +{<br>
> + piglit_require_extension("GL_ARB_direct_state_access");<br>
> +<br>
> + if (piglit_get_gl_version() < 12)<br>
> + clear_target_mask(GL_TEXTURE_3D);<br>
> + if (!piglit_is_extension_supported("GL_ARB_texture_rectangle"))<br>
> + clear_target_mask(GL_TEXTURE_RECTANGLE);<br>
> + if (!piglit_is_extension_supported("GL_ARB_texture_cube_map"))<br>
> + clear_target_mask(GL_TEXTURE_CUBE_MAP);<br>
> + if (!piglit_is_extension_supported("GL_EXT_texture_array")) {<br>
> + clear_target_mask(GL_TEXTURE_1D_ARRAY);<br>
> + clear_target_mask(GL_TEXTURE_2D_ARRAY);<br>
> + }<br>
> + if (!piglit_is_extension_supported("GL_ARB_texture_cube_map_array"))<br>
> + clear_target_mask(GL_TEXTURE_CUBE_MAP_ARRAY);<br>
> +}<br>
> +<br>
> +enum piglit_result<br>
> +piglit_display(void)<br>
> +{<br>
> + int i;<br>
> + bool pass = true;<br>
> + GLenum internalformat = GL_RGBA8;<br>
> + int tolerance = 0;<br>
> + GLubyte data[18][IMAGE_SIZE];<br>
> +<br>
> + init_layer_data(data[0], 18);<br>
> +<br>
> + for (i = 0; i < ARRAY_SIZE(targets); ++i) {<br>
> + if (!targets[i].mask)<br>
> + continue;<br>
> +<br>
> + printf("Testing %s into PBO\n",<br>
> + piglit_get_gl_enum_name(targets[i].target));<br>
> + pass &= getTexImage(true, targets[i].target, data,<br>
> + internalformat, tolerance);<br>
> +<br>
> + printf("Testing %s into client array\n",<br>
> + piglit_get_gl_enum_name(targets[i].target));<br>
> + pass &= getTexImage(false, targets[i].target, data,<br>
> + internalformat, tolerance);<br>
> +<br>
> + pass &= piglit_check_gl_error(GL_NO_ERROR);<br>
> + }<br>
> +<br>
> + return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
> +}<br>
> +<br>
> --<br>
> 2.1.0<br>
><br>
</div></div>> _______________________________________________<br>
> Piglit mailing list<br>
> <a href="mailto:Piglit@lists.freedesktop.org">Piglit@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/piglit" target="_blank">http://lists.freedesktop.org/mailman/listinfo/piglit</a><br>
<br>
<br>
This patch introduced several Coverity unused value defects.<br>
<br>
The variable num_layers is assigned and reassigned without being used<br>
in the fall-through case statements.<br>
</blockquote></div><br></div>