glx-multithread-texture: Avoid front-buffer rendering.
[piglit.git] / tests / shaders / glsl-fs-texture2drect.c
blobbd129b6554103c92cc50f4c0ee7dfce95812f689
1 /*
2 * Copyright © 2010 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 * Authors:
24 * Eric Anholt <eric@anholt.net>
28 /** @file glsl-fs-texture2drect.c
30 * Tests that we can access rectangular textures in the fragment shader.
33 #include "piglit-util-gl.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config.supports_gl_compat_version = 10;
39 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
41 PIGLIT_GL_TEST_CONFIG_END
43 static GLint prog;
44 float red[4] = {1.0, 0.0, 0.0, 1.0};
45 float green[4] = {0.0, 1.0, 0.0, 1.0};
46 float blue[4] = {0.0, 0.0, 1.0, 1.0};
47 float white[4] = {1.0, 1.0, 1.0, 1.0};
48 GLboolean proj3 = GL_FALSE, proj4 = GL_FALSE;
50 GLuint
51 rgbw_texture(GLenum format, int w, int h)
53 GLfloat *data;
54 int x, y;
55 GLuint tex;
57 glGenTextures(1, &tex);
58 glBindTexture(GL_TEXTURE_RECTANGLE, tex);
59 glTexParameteri(GL_TEXTURE_RECTANGLE,
60 GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
61 glTexParameteri(GL_TEXTURE_RECTANGLE,
62 GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
63 glTexParameteri(GL_TEXTURE_RECTANGLE,
64 GL_TEXTURE_MAG_FILTER, GL_NEAREST);
65 glTexParameteri(GL_TEXTURE_RECTANGLE,
66 GL_TEXTURE_MIN_FILTER, GL_NEAREST);
68 data = malloc(w * h * 4 * sizeof(GLfloat));
70 for (y = 0; y < h; y++) {
71 for (x = 0; x < w; x++) {
72 const float *color;
74 if (x < w / 2 && y < h / 2)
75 color = red;
76 else if (y < h / 2)
77 color = green;
78 else if (x < w / 2)
79 color = blue;
80 else
81 color = white;
83 memcpy(data + (y * w + x) * 4, color,
84 4 * sizeof(float));
87 glTexImage2D(GL_TEXTURE_RECTANGLE, 0,
88 format,
89 w, h, 0,
90 GL_RGBA, GL_FLOAT, data);
92 free(data);
93 return tex;
96 enum piglit_result
97 piglit_display(void)
99 GLboolean pass = GL_TRUE;
100 GLuint tex;
101 int tx1 = piglit_width * 1 / 4;
102 int tx2 = piglit_width * 3 / 4;
103 int ty1 = piglit_height * 1 / 4;
104 int ty2 = piglit_height * 3 / 4;
105 float proj;
107 /* Create the texture. */
108 tex = rgbw_texture(GL_RGBA, 50, 25);
110 glEnable(GL_TEXTURE_RECTANGLE);
112 if (proj3 || proj4)
113 proj = 2.0;
114 else
115 proj = 1.0;
117 piglit_draw_rect_tex(-1, -1, 2, 2,
118 0, 0, 50 * proj, 25 * proj);
120 pass = pass && piglit_probe_pixel_rgb(tx1, ty1, red);
121 pass = pass && piglit_probe_pixel_rgb(tx2, ty1, green);
122 pass = pass && piglit_probe_pixel_rgb(tx1, ty2, blue);
123 pass = pass && piglit_probe_pixel_rgb(tx2, ty2, white);
125 glDeleteTextures(1, &tex);
127 piglit_present_results();
129 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
132 void piglit_init(int argc, char **argv)
134 GLint vs, fs;
135 int loc;
136 char *fs_name;
137 int i = 0;
139 for (i = 0; i < argc; i++) {
140 if (!strcmp(argv[i], "-proj3"))
141 proj3 = GL_TRUE;
142 if (!strcmp(argv[i], "-proj4"))
143 proj4 = GL_TRUE;
146 piglit_require_gl_version(20);
147 piglit_require_extension("GL_ARB_texture_rectangle");
149 vs = piglit_compile_shader(GL_VERTEX_SHADER,
150 "shaders/glsl-tex-mvp.vert");
151 if (proj4) {
152 fs_name = "shaders/glsl-fs-texture2drect-proj4.frag";
153 } else if (proj3) {
154 fs_name = "shaders/glsl-fs-texture2drect-proj3.frag";
155 } else {
156 fs_name = "shaders/glsl-fs-texture2drect.frag";
158 fs = piglit_compile_shader(GL_FRAGMENT_SHADER, fs_name);
160 prog = piglit_link_simple_program(vs, fs);
161 if (!piglit_link_check_status(prog))
162 piglit_report_result(PIGLIT_FAIL);
164 glUseProgram(prog);
166 loc = glGetUniformLocation(prog, "sampler");
167 glUniform1i(loc, 0);