1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
/*
* Copyright © 2014 VMware, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
/**
* With AMD OpenGL drivers, when we draw a point sprite and use
* gl_PointCoord in the fragment (pixel) shader, the buggy host driver
* will wrongly put gl_PointCoord value into a fragment shader input
* variable, e.g., fs_color0, so that the rendering results are all wrong.
* We will NOT see this issue if there is no vertex attribute for the
* vertex position.
*
* Known to be
* -- Present in : ATI HD 6770M on Mac OS X 10.8.4
* -- Fixed in : Mac OS 10.9
*/
#include "piglit-util-gl.h"
PIGLIT_GL_TEST_CONFIG_BEGIN
config.supports_gl_core_version = 32;
config.supports_gl_compat_version = 32;
config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
config.khr_no_error_support = PIGLIT_NO_ERRORS;
PIGLIT_GL_TEST_CONFIG_END
#define WIDTH 32
#define HEIGHT 32
#define LEVELS 6
#define COLOR_GRAY 0x7F7F7FFF
#define CLEAR_COLOR 0x000033FF
#define NUM_VERTICES 4
#define NUM_ATTRS 2
#define ATTR_SIZE 4
static GLuint prog;
static bool
test_pointsprite_ps(void)
{
static const float vertArray[ATTR_SIZE * NUM_ATTRS] = {
0.0f, 0.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
};
const unsigned int numPixels = WIDTH * HEIGHT;
GLuint texData[WIDTH * HEIGHT];
GLuint i, texFbo, fbo, vertexArray, vertexBuf;
GLint attrLoc;
const float pointSize = WIDTH;
const unsigned int expectedTexelColor = 0xFFFFFFFF;
for (i = 0; i < numPixels; ++i) {
texData[i] = COLOR_GRAY;
}
/* Create 2D textures */
glGenTextures(1, &texFbo);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texFbo);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, WIDTH, HEIGHT, 0,
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, texData);
if (!piglit_check_gl_error(GL_NO_ERROR))
return false;
/* Setup the vertex attributes */
glGenVertexArrays(1, &vertexArray);
glBindVertexArray(vertexArray);
glGenBuffers(1, &vertexBuf);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuf);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertArray), vertArray,
GL_STATIC_DRAW);
for (i = 0; i < NUM_ATTRS; i++) {
const GLvoid *offset =
(const GLvoid *)(i * ATTR_SIZE * sizeof(float));
GLchar name[8];
snprintf(name, sizeof name, "Attr%d", i);
attrLoc = glGetAttribLocation(prog, name);
glEnableVertexAttribArray(attrLoc);
glVertexAttribPointer(attrLoc, ATTR_SIZE, GL_FLOAT, GL_FALSE,
ATTR_SIZE * sizeof(float), offset);
}
if (!piglit_check_gl_error(GL_NO_ERROR))
return false;
/* Setup the FBO */
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, texFbo, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) !=
GL_FRAMEBUFFER_COMPLETE) {
printf("incomplete framebuffer at line %d\n", __LINE__);
return false;
}
glDrawBuffer(GL_COLOR_ATTACHMENT0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) !=
GL_FRAMEBUFFER_COMPLETE) {
printf("incomplete framebuffer at line %d\n", __LINE__);
return false;
}
/* Clear and draw */
glViewport(0, 0, WIDTH, HEIGHT);
glClearColor(((CLEAR_COLOR >> 24) & 0xFF) / 255.0f,
((CLEAR_COLOR >> 16) & 0xFF) / 255.0f,
((CLEAR_COLOR >> 8) & 0xFF) / 255.0f,
((CLEAR_COLOR) & 0xFF) / 255.0f);
glClear(GL_COLOR_BUFFER_BIT);
glPointSize(pointSize);
glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
glDrawArrays(GL_POINTS, 0, 1);
/* Read back */
glReadBuffer(GL_COLOR_ATTACHMENT0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) !=
GL_FRAMEBUFFER_COMPLETE) {
printf("incomplete framebuffer at line %d\n", __LINE__);
return false;
}
/* read color buffer */
glPixelStorei(GL_PACK_ROW_LENGTH, WIDTH);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
memset(texData, 0, sizeof(texData));
glReadPixels(0, 0, WIDTH, HEIGHT,
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, texData);
if (texData[0] != expectedTexelColor) {
printf("At pixel (0,0) expected 0x%x but found 0x%x\n",
expectedTexelColor, texData[0]);
/* clean up */
glDeleteTextures(1, &texFbo);
glDeleteFramebuffers(1, &fbo);
return false;
}
if (!piglit_check_gl_error(GL_NO_ERROR))
return false;
glDeleteTextures(1, &texFbo);
glDeleteFramebuffers(1, &fbo);
return true;
}
static void
setup_shaders(void)
{
static const char *vsSrc =
"#version 150\n"
"in vec4 Attr0;"
"in vec4 Attr1;"
"smooth out vec4 fs_color0;"
"void main(void) {"
" gl_Position = Attr0;"
" fs_color0 = Attr1;"
"}";
static const char *fsSrc =
"#version 150\n"
"smooth in vec4 fs_color0;"
"out vec4 fragColor0;"
"void main(void) {"
" vec2 psCoords = gl_PointCoord;"
" fragColor0 = fs_color0;"
"}";
prog = piglit_build_simple_program(vsSrc, fsSrc);
glBindFragDataLocation(prog, 0, "fragColor0");
glLinkProgram(prog);
glUseProgram(prog);
}
enum piglit_result
piglit_display(void)
{
bool pass = test_pointsprite_ps();
return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
void
piglit_init(int argc, char **argv)
{
setup_shaders();
}
|