2 * Copyright (c) 2012 VMware, Inc.
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
25 * @file sampler-incomplete.c
27 * With GL_ARB_sampler_objects it's possible for a texture to be both complete
28 * and incomplete depending on the samplers used to access it.
29 * Test that we get the right results in this situation.
36 #include "piglit-util-gl.h"
38 PIGLIT_GL_TEST_CONFIG_BEGIN
40 config
.supports_gl_compat_version
= 10;
42 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGB
;
44 PIGLIT_GL_TEST_CONFIG_END
49 static const GLfloat red
[2][2][4] = {
50 { {0.25, 0, 0, 0}, {0.25, 0, 0, 0} },
51 { {0.25, 0, 0, 0}, {0.25, 0, 0, 0} } };
52 static const char *fragShaderText
=
53 "uniform sampler2D tex0, tex1;\n"
56 " vec2 coord = vec2(0.5, 0.5); \n"
57 " gl_FragColor = texture2D(tex0, coord) \n"
58 " + texture2D(tex1, coord);\n"
65 /* Create fragment shader that adds the two textures */
66 prog
= piglit_build_simple_program(NULL
, fragShaderText
);
69 u
= glGetUniformLocation(prog
, "tex0");
71 u
= glGetUniformLocation(prog
, "tex1");
74 /* create texture with one mipmap level */
75 glGenTextures(1, &tex
);
76 glBindTexture(GL_TEXTURE_2D
, tex
);
77 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0,
78 GL_RGBA
, GL_FLOAT
, red
);
79 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
80 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
82 /* bind the texture to units 0 and 1 */
83 glActiveTexture(GL_TEXTURE0
);
84 glBindTexture(GL_TEXTURE_2D
, tex
);
85 glEnable(GL_TEXTURE_2D
);
87 glActiveTexture(GL_TEXTURE1
);
88 glBindTexture(GL_TEXTURE_2D
, tex
);
89 glEnable(GL_TEXTURE_2D
);
92 glGenSamplers(2, samplers
);
94 /* sampler[0] - nearest filtering, no mipmap.
95 * The result of sampling the texture should be (0.25, 0, 0, 0)
97 glBindSampler(0, samplers
[0]);
98 glSamplerParameteri(samplers
[0], GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
99 glSamplerParameteri(samplers
[0], GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
101 /* sampler[1] - nearest filtering, with mipmapping.
102 * The result of sampling the texture should be (0, 0, 0, 1) since the
103 * texture is incomplete with respect to this sampler (no mipmap).
105 glBindSampler(1, samplers
[1]);
106 glSamplerParameteri(samplers
[1], GL_TEXTURE_MIN_FILTER
,
107 GL_NEAREST_MIPMAP_NEAREST
);
108 glSamplerParameteri(samplers
[1], GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
115 /* NOTE: We're not checking the alpha value here.
116 * Some drivers (like NVIDIA) seem to return (0,0,0,0) when sampling
117 * an incomplete texture, but the spec says (0,0,0,1) should be
118 * returned. That's not really important for this test though so
121 GLfloat expected
[3] = {0.25, 0, 0};
124 glClear(GL_COLOR_BUFFER_BIT
);
126 piglit_draw_rect_tex(-1, -1, 2, 2, 0, 0, 1, 1);
128 p
= piglit_probe_pixel_rgb(piglit_width
/ 2, piglit_height
/ 2,
131 piglit_present_results();
133 return p
? PIGLIT_PASS
: PIGLIT_FAIL
;
138 piglit_init(int argc
, char**argv
)
140 piglit_require_GLSL();
141 piglit_require_extension("GL_ARB_sampler_objects");