ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_texture_view / sampling-2d-array-as-cubemap-array.c
blob07e16d202a0fe7718b9876821f7a7925f14094f3
1 /*
2 * Copyright © 2014 Ilia Mirkin
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: Ilia Mirkin <imirkin@alum.mit.edu>
26 /**
27 * \file sampling-2d-array-as-cubemap-array.c
28 * This tests that you can cast from a 2D Array texture to a Cubemap Array
29 * texture and sample from the Cubemap Array view.
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config.supports_gl_compat_version = 30;
37 config.supports_gl_es_version = 31;
38 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
39 config.khr_no_error_support = PIGLIT_NO_ERRORS;
41 PIGLIT_GL_TEST_CONFIG_END
43 static const GLubyte green[] = {0, 255, 0, 255};
44 static const float greenf[] = {0, 1.0f, 0, 1.0f};
45 static const GLubyte red[] = {255, 0, 0, 255};
47 enum piglit_result
48 piglit_display(void)
50 GLboolean pass;
52 glViewport(0, 0, piglit_width, piglit_height);
53 glClearColor(0.5, 0.5, 0.5, 0.5);
54 glClear(GL_COLOR_BUFFER_BIT);
56 piglit_draw_rect(-1, -1, 2, 2);
58 pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, greenf);
60 piglit_present_results();
62 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
65 #ifdef PIGLIT_USE_OPENGL
66 #define GLSL_VERSION "130"
67 #else
68 #define GLSL_VERSION "310 es"
69 #endif
71 static const char *vs =
72 "#version " GLSL_VERSION "\n"
73 "in vec4 piglit_vertex;\n"
74 "void main() { \n"
75 " gl_Position = piglit_vertex;\n"
76 "}\n";
78 static const char *fs =
79 "#version " GLSL_VERSION "\n"
80 "#extension GL_ARB_texture_cube_map_array: enable\n"
81 "#extension GL_OES_texture_cube_map_array: enable\n"
82 "#ifdef GL_ES\n"
83 "precision highp float;\n"
84 "precision highp samplerCubeArray;\n"
85 "#endif\n"
86 "uniform samplerCubeArray tex;\n"
87 "out vec4 color;\n"
88 "void main() { \n"
89 " color = vec4(texture(tex, vec4(-1, 0, 0, 1)).xyz, 1.0);\n"
90 "}\n";
92 void
93 piglit_init(int argc, char **argv)
95 int tex_loc_cube, prog_cube, l;
96 GLuint tex_2DArray, tex_Cube;
98 #ifdef PIGLIT_USE_OPENGL
99 piglit_require_extension("GL_ARB_texture_view");
100 piglit_require_extension("GL_ARB_texture_cube_map_array");
101 #else
102 piglit_require_extension("GL_OES_texture_view");
103 piglit_require_extension("GL_OES_texture_cube_map_array");
104 #endif
106 /* setup shaders and program object for Cube rendering */
107 prog_cube = piglit_build_simple_program(vs, fs);
108 tex_loc_cube = glGetUniformLocation(prog_cube, "tex");
110 glGenTextures(1, &tex_2DArray);
111 glBindTexture(GL_TEXTURE_2D_ARRAY, tex_2DArray);
113 glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 1, 1, 16);
115 /* load each array layer with red */
116 for (l = 0; l < 16; l++) {
117 glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, l,
118 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, red);
120 /* make array layer 9 have green */
121 glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 9,
122 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, green);
124 glGenTextures(1, &tex_Cube);
125 /* the texture view starts at layer 2, so face 1 (-X) of
126 * element 1 will have green */
127 glTextureView(tex_Cube, GL_TEXTURE_CUBE_MAP_ARRAY, tex_2DArray, GL_RGBA8,
128 0, 1, 2, 12);
129 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
130 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
132 glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, tex_Cube);
134 glUseProgram(prog_cube);
135 glUniform1i(tex_loc_cube, 0);