ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / gl-3.2 / pointsprite-origin.c
bloba3f02f70a9eea7adf7c5af7218a70d59c01efec8
1 /*
2 * Copyright © 2014 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 * 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
13 * Software.
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
21 * IN THE SOFTWARE.
24 /**
25 * With Mac AMD GL OpenGL drivers, the texture coordinate v (in Y-direction)
26 * is flipped for point sprites.
28 * Known to be
29 * -- Present in : ATI HD 6770M on Mac OS X 10.8.4
30 * -- Fixed in : Mac OS 10.9
34 #include "piglit-util-gl.h"
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config.supports_gl_core_version = 32;
39 config.supports_gl_compat_version = 32;
41 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
42 config.khr_no_error_support = PIGLIT_NO_ERRORS;
44 PIGLIT_GL_TEST_CONFIG_END
46 #define WIDTH 32
47 #define HEIGHT 32
48 #define COLOR_GRAY 0x7F7F7FFF
49 #define CLEAR_COLOR 0x000033FF
51 static GLuint prog;
53 static bool
54 test_pointsprite_origin(void)
56 const unsigned int numPixels = WIDTH * HEIGHT;
57 GLuint texData[WIDTH * HEIGHT];
58 GLuint i, texFbo, fbo, vao;
59 const float pointSize = WIDTH;
60 const unsigned char expectedChannelVal = 0.5f / WIDTH * 255.0f + 0.5f;
61 const unsigned int expectedTexelColor = expectedChannelVal << 24 |
62 expectedChannelVal << 16 |
63 0x0000FFFF;
65 for (i = 0; i < numPixels; ++i) {
66 texData[i] = COLOR_GRAY;
69 /* Create vertex arrays */
70 glGenVertexArrays(1, &vao);
71 glBindVertexArray(vao);
73 /* Create 2D textures */
74 glGenTextures(1, &texFbo);
75 glActiveTexture(GL_TEXTURE0);
76 glBindTexture(GL_TEXTURE_2D, texFbo);
77 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, WIDTH, HEIGHT, 0,
78 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, texData);
80 if (!piglit_check_gl_error(GL_NO_ERROR))
81 return false;
83 /* Setup the FBO */
84 glGenFramebuffers(1, &fbo);
85 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
86 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
87 GL_TEXTURE_2D, texFbo, 0);
88 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) !=
89 GL_FRAMEBUFFER_COMPLETE) {
90 printf("incomplete framebuffer at line %d\n", __LINE__);
91 return false;
94 glDrawBuffer(GL_COLOR_ATTACHMENT0);
95 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) !=
96 GL_FRAMEBUFFER_COMPLETE) {
97 printf("incomplete framebuffer at line %d\n", __LINE__);
98 return false;
101 /* Clear and draw */
102 glViewport(0, 0, WIDTH, HEIGHT);
103 glClearColor(((CLEAR_COLOR >> 24) & 0xFF) / 255.0f,
104 ((CLEAR_COLOR >> 16) & 0xFF) / 255.0f,
105 ((CLEAR_COLOR >> 8) & 0xFF) / 255.0f,
106 ((CLEAR_COLOR) & 0xFF) / 255.0f);
107 glClear(GL_COLOR_BUFFER_BIT);
108 glPointSize(pointSize);
109 glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
110 glDrawArrays(GL_POINTS, 0, 1);
112 /* Read back */
113 glReadBuffer(GL_COLOR_ATTACHMENT0);
114 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) !=
115 GL_FRAMEBUFFER_COMPLETE) {
116 printf("incomplete framebuffer at line %d\n", __LINE__);
117 return false;
120 /* read color buffer */
121 glPixelStorei(GL_PACK_ROW_LENGTH, WIDTH);
122 glPixelStorei(GL_PACK_ALIGNMENT, 1);
123 memset(texData, 0, sizeof(texData));
124 glReadPixels(0, 0, WIDTH, HEIGHT,
125 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, texData);
127 if (texData[0] != expectedTexelColor) {
128 printf("At pixel (0,0) expected 0x%x but found 0x%x\n",
129 expectedTexelColor, texData[0]);
130 /* clean up */
131 glDeleteTextures(1, &texFbo);
132 glDeleteFramebuffers(1, &fbo);
133 return false;
136 if (!piglit_check_gl_error(GL_NO_ERROR))
137 return false;
139 glDeleteTextures(1, &texFbo);
140 glDeleteFramebuffers(1, &fbo);
141 return true;
145 static void
146 setup_shaders(void)
148 static const char *vsSrc =
149 "#version 150\n"
150 "void main(void) {"
151 " gl_Position = vec4(0, 0, 0, 1);"
152 "}";
153 static const char *fsSrc =
154 "#version 150\n"
155 "out vec4 fragColor0;"
156 "void main(void) {"
157 " fragColor0.xy = gl_PointCoord.xy;"
158 " fragColor0.zw = vec2(1, 1);"
159 "}";
161 /* Create shaders and the program */
162 prog = piglit_build_simple_program(vsSrc, fsSrc);
163 glBindFragDataLocation(prog, 0, "fragColor0");
164 glLinkProgram(prog);
165 glUseProgram(prog);
169 enum piglit_result
170 piglit_display(void)
172 bool pass = test_pointsprite_origin();
174 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
178 void
179 piglit_init(int argc, char **argv)
181 setup_shaders();