ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_texture_view / texsubimage-layers.c
blobd9204e045022daa1307f03c8811f769c139845ca
1 /*
2 * Copyright © 2014 Intel Corporation
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * 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, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
23 * Author: Chris Forbes <chrisf@ijw.co.nz>
26 /**
27 * \file texsubimage-layers.c
28 * This tests that TexSubImage* into a view behaves correctly when the view
29 * has a nonzero MinLayer.
32 #include "piglit-util-gl.h"
33 #include "common.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config.supports_gl_compat_version = 30;
38 config.supports_gl_es_version = 31;
39 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
40 config.khr_no_error_support = PIGLIT_NO_ERRORS;
42 PIGLIT_GL_TEST_CONFIG_END
44 enum piglit_result
45 piglit_display(void)
47 return PIGLIT_FAIL;
50 #define NUM_LAYERS 7
51 #define VIEW_MIN_LAYER 2
52 #define VIEW_NUM_LAYERS 3
53 #define TEX_SIZE 64
55 void
56 piglit_init(int argc, char **argv)
58 GLuint tex, view;
59 GLuint buffer;
60 int i, j;
61 bool use_pbo = false;
62 bool pass = true;
64 #ifdef PIGLIT_USE_OPENGL
65 piglit_require_extension("GL_ARB_texture_view");
66 #else
67 piglit_require_extension("GL_OES_texture_view");
68 #endif
70 for (i = 1; i < argc; ++i) {
71 if (strcmp(argv[i], "pbo") == 0) {
72 piglit_require_extension("GL_ARB_pixel_buffer_object");
73 use_pbo = true;
77 /* build a 2d array texture; no mip levels */
78 glGenTextures(1, &tex);
79 glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
80 glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1,
81 GL_RGBA8, TEX_SIZE, TEX_SIZE, NUM_LAYERS);
83 if (use_pbo) {
84 glGenBuffers(1, &buffer);
85 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer);
88 for (i=0; i < NUM_LAYERS; i++) {
89 GLubyte *pixels = create_solid_image(TEX_SIZE, TEX_SIZE,
90 1, 4, i);
91 if (!pixels) {
92 printf("Allocation failure for layer %d\n", i);
93 piglit_report_result(PIGLIT_FAIL);
96 if (use_pbo) {
97 glBufferData(GL_PIXEL_UNPACK_BUFFER, TEX_SIZE * TEX_SIZE * 4,
98 pixels, GL_STREAM_DRAW);
100 glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0,
101 0, 0, i, TEX_SIZE, TEX_SIZE, 1,
102 GL_RGBA, GL_UNSIGNED_BYTE, use_pbo ? NULL : pixels);
103 free(pixels);
106 /* create a view to a subset of the layers */
107 glGenTextures(1, &view);
108 glTextureView(view, GL_TEXTURE_2D_ARRAY, tex, GL_RGBA8,
109 0, 1, VIEW_MIN_LAYER, VIEW_NUM_LAYERS);
111 if (!piglit_check_gl_error(GL_NO_ERROR))
112 piglit_report_result(PIGLIT_FAIL);
114 /* upload through the view */
115 glBindTexture(GL_TEXTURE_2D_ARRAY, view);
116 for (i = 0; i < VIEW_NUM_LAYERS; i++) {
117 GLubyte *pixels = create_solid_image(TEX_SIZE, TEX_SIZE,
118 1, 4, i + NUM_LAYERS);
119 if (!pixels) {
120 printf("Allocation failure for view layer %d\n", i);
121 piglit_report_result(PIGLIT_FAIL);
124 if (use_pbo) {
125 glBufferData(GL_PIXEL_UNPACK_BUFFER, TEX_SIZE * TEX_SIZE * 4,
126 pixels, GL_STREAM_DRAW);
128 glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0,
129 0, 0, i, TEX_SIZE, TEX_SIZE, 1,
130 GL_RGBA, GL_UNSIGNED_BYTE, use_pbo ? NULL : pixels);
131 free(pixels);
134 if (!piglit_check_gl_error(GL_NO_ERROR))
135 piglit_report_result(PIGLIT_FAIL);
137 /* bind the underlying texture and readback */
138 glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
139 for (i = 0; i < NUM_LAYERS; i++) {
140 /* the layers inside the view should have been replaced.
141 * everything else should be untouched.
144 float expected_color[4];
145 int color_index = i;
146 if (i >= VIEW_MIN_LAYER && i < VIEW_MIN_LAYER + VIEW_NUM_LAYERS) {
147 color_index = i + NUM_LAYERS - VIEW_MIN_LAYER;
150 printf("Testing layer %d\n", i);
152 for (j = 0; j < 4; j++)
153 expected_color[j] = Colors[color_index][j] / 255.0f;
155 pass = piglit_probe_texel_volume_rgba(GL_TEXTURE_2D_ARRAY, 0,
156 0, 0, i,
157 TEX_SIZE, TEX_SIZE, 1,
158 expected_color) && pass;
161 if (use_pbo)
162 glDeleteBuffers(1, &buffer);
164 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);