2 * Copyright 2014 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
21 * DEALINGS IN THE SOFTWARE.
24 /** @file dsa-textures.c
26 * Tests the direct state access functionality for creating, initializing, and
27 * rendering texture objects.
29 #include "piglit-util-gl.h"
30 #include "dsa-utils.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config
.supports_gl_core_version
= 31;
37 config
.supports_gl_compat_version
= 20;
39 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
|
40 PIGLIT_GL_VISUAL_DOUBLE
;
41 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
43 PIGLIT_GL_TEST_CONFIG_END
48 random_image_data(void)
51 GLfloat
*img
= malloc(4*piglit_width
*piglit_height
*sizeof(GLfloat
));
52 for (i
= 0; i
< 4*piglit_width
*piglit_height
; ++i
) {
53 img
[i
] = (float) rand() / RAND_MAX
;
56 } /* random_image_data */
59 piglit_init(int argc
, char **argv
)
61 piglit_require_extension("GL_ARB_direct_state_access");
62 piglit_require_extension("GL_ARB_texture_storage");
66 printf("Using driver %s.\n", (const char *) glGetString(GL_VERSION
));
68 prog
= dsa_create_program(GL_TEXTURE_2D
);
75 GLfloat
* data
= random_image_data();
77 const GLuint texunit
= 3;
79 glCreateTextures(GL_TEXTURE_2D
, 1, &name
);
80 glTextureStorage2D(name
, 1, GL_RGBA32F
, piglit_width
, piglit_height
);
81 glTextureSubImage2D(name
, 0, 0, 0, piglit_width
, piglit_height
,
82 GL_RGBA
, GL_FLOAT
, data
);
83 glTextureParameteri(name
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
84 glTextureParameteri(name
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
87 dsa_texture_with_unit(prog
, texunit
);
89 glBindTextureUnit(texunit
, name
);
90 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
91 piglit_draw_rect_tex(-1.0, -1.0, 2.0, 2.0, 0.0, 0.0, 1.0, 1.0);
92 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
94 /* Check to make sure the image was drawn correctly */
95 pass
= piglit_probe_image_rgba(0, 0, piglit_width
, piglit_height
, data
)
98 if (!piglit_automatic
)
99 piglit_present_results();
101 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;