ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_texture_view / sampling-2d-array-as-cubemap.c
bloba7f02b5e04101ab6b8f94eba52c875a46731b42c
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.c
28 * This tests that you can cast from a 2D Array texture to a Cubemap
29 * texture and sample from the Cubemap 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 "#ifdef GL_ES\n"
81 "precision highp float;\n"
82 "precision highp samplerCube;\n"
83 "#endif\n"
84 "uniform samplerCube tex;\n"
85 "out vec4 color;\n"
86 "void main() { \n"
87 " color = vec4(texture(tex, vec3(-1, 0, 0)).xyz, 1.0);\n"
88 "}\n";
90 void
91 piglit_init(int argc, char **argv)
93 int tex_loc_cube, prog_cube, l;
94 GLuint tex_2DArray, tex_Cube;
96 #ifdef PIGLIT_USE_OPENGL
97 piglit_require_extension("GL_ARB_texture_view");
98 #else
99 piglit_require_extension("GL_OES_texture_view");
100 #endif
102 /* setup shaders and program object for Cube rendering */
103 prog_cube = piglit_build_simple_program(vs, fs);
104 tex_loc_cube = glGetUniformLocation(prog_cube, "tex");
106 glGenTextures(1, &tex_2DArray);
107 glBindTexture(GL_TEXTURE_2D_ARRAY, tex_2DArray);
109 glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 1, 1, 8);
111 /* load each array layer with red */
112 for (l = 0; l < 8; l++) {
113 glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, l,
114 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, red);
116 /* make array layer 3 have green */
117 glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 3,
118 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, green);
120 glGenTextures(1, &tex_Cube);
121 /* the texture view starts at layer 2, so face 1 (-X) will have green */
122 glTextureView(tex_Cube, GL_TEXTURE_CUBE_MAP, tex_2DArray, GL_RGBA8,
123 0, 1, 2, 6);
124 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
125 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
127 glBindTexture(GL_TEXTURE_CUBE_MAP, tex_Cube);
129 glUseProgram(prog_cube);
130 glUniform1i(tex_loc_cube, 0);