2 * Copyright © 2013 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
25 * Verify that when GL_COORD_REPLACE is set, fragment shader texture
26 * coordinates (via the gl_TexCoord built-ins) don't get eliminated.
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
33 config
.supports_gl_compat_version
= 21;
35 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
37 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
39 PIGLIT_GL_TEST_CONFIG_END
41 static const char *vstext
=
45 " gl_Position = vec4(vertex, 1.);\n"
46 " gl_PointSize = 16;\n"
49 static const char *fstext
=
52 " gl_FragColor = gl_TexCoord[0];\n"
56 static GLuint vertBuff
;
57 static GLuint indexBuf
;
59 static GLfloat vertices
[] = {
62 static GLsizei vertSize
= sizeof(vertices
);
64 static GLuint indices
[] = {
67 static GLsizei indSize
= sizeof(indices
);
72 piglit_init(int argc
, char **argv
)
75 piglit_require_GLSL_version(130);
77 prog
= piglit_build_simple_program(vstext
, fstext
);
81 glGenBuffers(1, &vertBuff
);
82 glBindBuffer(GL_ARRAY_BUFFER
, vertBuff
);
83 glBufferData(GL_ARRAY_BUFFER
, vertSize
, vertices
, GL_STATIC_DRAW
);
85 glGenBuffers(1, &indexBuf
);
86 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, indexBuf
);
87 glBufferData(GL_ELEMENT_ARRAY_BUFFER
, indSize
,
88 indices
, GL_STATIC_DRAW
);
90 glGenVertexArrays(1, &vao
);
91 glBindVertexArray(vao
);
93 vertIndex
= glGetAttribLocation(prog
, "vertex");
95 glEnableVertexAttribArray(vertIndex
);
96 glVertexAttribPointer(vertIndex
, 3, GL_FLOAT
, GL_FALSE
, 0, 0);
106 glClearColor(.4, .4, .4, 1.);
107 glClear(GL_COLOR_BUFFER_BIT
);
109 glBindVertexArray(vao
);
110 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, indexBuf
);
112 glEnable(GL_PROGRAM_POINT_SIZE
);
113 glEnable(GL_POINT_SPRITE
);
114 glTexEnvi(GL_POINT_SPRITE
, GL_COORD_REPLACE
, GL_TRUE
);
116 glDrawElements(GL_POINTS
, ARRAY_SIZE(indices
),
117 GL_UNSIGNED_INT
, NULL
);
119 for (y
= 0; y
< ptSize
; y
++) {
120 for (x
= 0; x
< ptSize
; x
++) {
121 float test
[] = {(2 * x
+ 1) / (float)(ptSize
* 2),
122 1 - ((2 * y
+ 1) / (float)(ptSize
* 2)),
124 pass
= piglit_probe_pixel_rgb(
125 piglit_width
/2 - ptSize
/2 + x
,
126 piglit_height
/2 - ptSize
/2 + y
,
132 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
134 piglit_present_results();
136 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;