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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS AND/OR THEIR
19 * SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
26 * Tests 3D texture with depth=1 (to make sure it's not errantly treated
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
;
40 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
42 PIGLIT_GL_TEST_CONFIG_END
47 static const float green
[4] = {0.0, 1.0, 0.0, 1.0};
53 /* texcoords with R=-1.0 to sample the border color */
54 static const GLfloat texcoords
[4][3] =
62 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
64 glClear(GL_COLOR_BUFFER_BIT
);
66 verts
[0][0] = 0.0; verts
[0][1] = 0.0;
67 verts
[1][0] = piglit_width
; verts
[1][1] = 0.0;
68 verts
[2][0] = piglit_width
; verts
[2][1] = piglit_height
;
69 verts
[3][0] = 0.0; verts
[3][1] = piglit_height
;
71 glVertexPointer(2, GL_FLOAT
, 0, verts
);
72 glTexCoordPointer(3, GL_FLOAT
, 0, texcoords
);
73 glEnableClientState(GL_VERTEX_ARRAY
);
74 glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
76 glDrawArrays(GL_TRIANGLE_FAN
, 0, 4);
78 glDisableClientState(GL_VERTEX_ARRAY
);
79 glDisableClientState(GL_TEXTURE_COORD_ARRAY
);
81 /* Should have drawn solid green since we're sampling the
82 * texture border color for all fragments drawn. If red is
83 * seen, it's probably because the 3D texture (with depth=1)
84 * is being treated as a 2D texture.
86 * BTW, another way the difference between 2D/3D textures
87 * could be detected would be with R-coordinate derivatives
90 pass
= piglit_probe_rect_rgba(0, 0,
91 piglit_width
- 1, piglit_height
- 1,
94 piglit_present_results();
96 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
101 piglit_init(int argc
, char **argv
)
103 GLubyte pixels
[TEX_SIZE
][TEX_SIZE
][4];
107 piglit_require_gl_version(13);
109 /* solid red texture */
110 for (i
= 0; i
< TEX_SIZE
; i
++) {
111 for (j
= 0; j
< TEX_SIZE
; j
++) {
112 pixels
[i
][j
][0] = 255;
115 pixels
[i
][j
][3] = 255;
119 glGenTextures(1, &tex
);
120 glBindTexture(GL_TEXTURE_3D
, tex
);
121 glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
122 glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
123 glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_BORDER
);
124 glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_BORDER
);
125 glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_BORDER
);
126 glTexParameterfv(GL_TEXTURE_3D
, GL_TEXTURE_BORDER_COLOR
, green
);
128 glTexImage3D(GL_TEXTURE_3D
, 0, GL_RGBA
, TEX_SIZE
, TEX_SIZE
, 1,
129 0, GL_RGBA
, GL_UNSIGNED_BYTE
, pixels
);
131 glEnable(GL_TEXTURE_3D
);