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
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
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
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
;
51 rgbw_texture(GLenum format
, int w
, int h
)
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
++) {
74 if (x
< w
/ 2 && y
< h
/ 2)
83 memcpy(data
+ (y
* w
+ x
) * 4, color
,
87 glTexImage2D(GL_TEXTURE_RECTANGLE
, 0,
90 GL_RGBA
, GL_FLOAT
, data
);
99 GLboolean pass
= GL_TRUE
;
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;
107 /* Create the texture. */
108 tex
= rgbw_texture(GL_RGBA
, 50, 25);
110 glEnable(GL_TEXTURE_RECTANGLE
);
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
)
139 for (i
= 0; i
< argc
; i
++) {
140 if (!strcmp(argv
[i
], "-proj3"))
142 if (!strcmp(argv
[i
], "-proj4"))
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");
152 fs_name
= "shaders/glsl-fs-texture2drect-proj4.frag";
154 fs_name
= "shaders/glsl-fs-texture2drect-proj3.frag";
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
);
166 loc
= glGetUniformLocation(prog
, "sampler");