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
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
26 * A very simple test of basic ClearTexImage and ClearTexSubImage
27 * functionality. Clears 2 textures, and puts them up side-by-side for
30 * The output should look like
37 * With the boxes from left to right being green, blue, and yellow.
40 #include "piglit-util-gl.h"
42 PIGLIT_GL_TEST_CONFIG_BEGIN
44 config
.supports_gl_compat_version
= 13;
46 config
.window_width
= 128;
47 config
.window_height
= 64;
48 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
49 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
51 PIGLIT_GL_TEST_CONFIG_END
53 static GLuint texture
[2];
54 static const float green
[3] = {0.0, 1.0, 0.0};
55 static const float red
[3] = {1.0, 0.0, 0.0};
56 static const float blue
[3] = {0.0, 0.0, 1.0};
57 static const float yellow
[3] = {1.0, 1.0, 0.0};
60 piglit_init(int argc
, char **argv
)
63 float *color
= malloc(sizeof(float) * 64 * 64 * 3);
65 piglit_require_extension("GL_ARB_clear_texture");
66 piglit_require_extension("GL_EXT_framebuffer_object");
68 /* Create color data for texture */
69 for (i
= 0; i
< 64 * 64; i
++) {
70 memcpy(&color
[i
*3], &red
[0], sizeof(red
));
73 glGenTextures(2, texture
);
75 /* Initialize textures to all red. */
76 glBindTexture(GL_TEXTURE_2D
, texture
[0]);
77 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, 64, 64,
78 0, GL_RGB
, GL_FLOAT
, color
);
79 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
80 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
82 glBindTexture(GL_TEXTURE_2D
, texture
[1]);
83 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, 64, 64,
84 0, GL_RGB
, GL_FLOAT
, color
);
85 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
86 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
96 if (!piglit_check_gl_error(GL_NO_ERROR
))
97 piglit_report_result(PIGLIT_FAIL
);
99 /* Clear the whole first texture with green */
100 glClearTexImage(texture
[0], 0, GL_RGB
, GL_FLOAT
, green
);
101 pass
&= piglit_check_gl_error(GL_NO_ERROR
);
103 /* Clear the left half of the second texture with blue */
104 glClearTexSubImage(texture
[1], 0,
107 GL_RGB
, GL_FLOAT
, blue
);
108 pass
&= piglit_check_gl_error(GL_NO_ERROR
);
109 /* And the right half with yellow */
110 glClearTexSubImage(texture
[1], 0,
113 GL_RGB
, GL_FLOAT
, yellow
);
114 pass
&= piglit_check_gl_error(GL_NO_ERROR
);
116 /* Render both textures to the screen */
117 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
119 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, piglit_winsys_fbo
);
120 glEnable(GL_TEXTURE_2D
);
121 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
123 glBindTexture(GL_TEXTURE_2D
, texture
[0]);
124 piglit_draw_rect_tex(0, 0, 64, 64, 0, 0, 1, 1);
126 glBindTexture(GL_TEXTURE_2D
, texture
[1]);
127 piglit_draw_rect_tex(64, 0, 64, 64, 0, 0, 1, 1);
129 glDisable(GL_TEXTURE_2D
);
131 /* Check for the 3 separate regions */
132 pass
&= piglit_probe_rect_rgb(0, 0, 64, 64, green
);
133 pass
&= piglit_probe_rect_rgb(64, 0, 32, 64, blue
);
134 pass
&= piglit_probe_rect_rgb(96, 0, 32, 64, yellow
);
136 piglit_present_results();
138 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;