ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_texture_float / get-tex3d.c
blob68c9504d60773f257b6ecfb246deb0bee5b6950d
1 /*
2 * Copyright (c) 2016 VMware, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NON-INFRINGEMENT. IN NO EVENT SHALL VMWARE AND/OR THEIR SUPPLIERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
26 /**
27 * Tests glGetTexImage() with float format.
28 * This hits a rare pixel transfer patch in Mesa.
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config.supports_gl_compat_version = 10;
35 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
36 PIGLIT_GL_TEST_CONFIG_END
39 enum piglit_result
40 piglit_display(void)
42 /* should not called */
43 return PIGLIT_FAIL;
47 void
48 piglit_init(int argc, char **argv)
50 GLuint texture;
51 const unsigned w = 16, h = 8, d = 4;
52 unsigned i;
53 float *texData;
54 bool pass = true;
56 piglit_require_extension("GL_ARB_texture_float");
58 glGenTextures(1, &texture);
59 glBindTexture(GL_TEXTURE_3D, texture);
60 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
61 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
63 /* Define 3D texture with float values */
64 texData = malloc(4 * w * h * d * sizeof(float));
65 for (i = 0; i < w * h * d * 4; i++) {
66 texData[i] = (rand() & 0xff) / 255.0f;
68 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32F, w, h, d, 0,
69 GL_RGBA, GL_FLOAT, texData);
71 /* Get 3D texture as GLfloat (no transfer ops) */
73 GLfloat *getData = malloc(4 * w * h * d * sizeof(GLfloat));
74 glGetTexImage(GL_TEXTURE_3D, 0, GL_RGBA, GL_FLOAT, getData);
75 for (i = 0; i < w * h * d * 4; i++) {
76 GLfloat expected = texData[i];
77 if (getData[i] != expected) {
78 printf("Expected float value %f, found %f at %u\n",
79 expected, getData[i], i);
80 pass = false;
81 break;
85 free(getData);
88 /* Get 3D texture as GLubyte */
90 GLubyte *getData = malloc(4 * w * h * d * sizeof(GLubyte));
91 glGetTexImage(GL_TEXTURE_3D, 0, GL_RGBA, GL_UNSIGNED_BYTE, getData);
92 for (i = 0; i < w * h * d * 4; i++) {
93 GLubyte expected = (GLubyte) (texData[i] * 255);
94 if (getData[i] != expected) {
95 printf("Expected ubyte value %u, found %u at %u\n",
96 expected, getData[i], i);
97 pass = false;
98 break;
102 free(getData);
105 free(texData);
107 glDeleteTextures(1, &texture);
109 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);