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
|
/*
* Copyright © 2011 Intel Corporation
*
* 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.
*/
/** @file negative-prims.c
*
* Tests that glBeginTransformFeedback emits errors when attempting to
* draw primitives other than those allowed by the current transform
* feedback primitiveMode.
*
* From the EXT_transform_feedback spec:
*
* "The error INVALID_OPERATION is generated if Begin, or any
* command that performs an explicit Begin, is called when:
*
* * a geometry shader is not active and <mode> does not match
* the allowed begin modes for the current transform feedback
* state as given by table X.1."
*
* (the test also executes primitives that should pass, to ensure that
* the test is correctly generating GL errors just due to the bad
* primitives)
*/
#include "piglit-util-gl.h"
PIGLIT_GL_TEST_CONFIG_BEGIN
config.supports_gl_compat_version = 10;
config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
config.khr_no_error_support = PIGLIT_HAS_ERRORS;
PIGLIT_GL_TEST_CONFIG_END
struct {
GLenum tf_prim;
GLenum prim;
} prims[] = {
{ GL_POINTS, GL_POINTS },
{ GL_LINES, GL_LINES },
{ GL_LINES, GL_LINE_STRIP },
{ GL_LINES, GL_LINE_LOOP },
{ GL_TRIANGLES, GL_TRIANGLES },
{ GL_TRIANGLES, GL_TRIANGLE_STRIP },
{ GL_TRIANGLES, GL_TRIANGLE_FAN },
{ GL_TRIANGLES, GL_QUADS },
{ GL_TRIANGLES, GL_QUAD_STRIP },
{ GL_TRIANGLES, GL_POLYGON },
};
static bool
test_one_prim(GLenum tf_prim, int i)
{
GLenum error;
const char *prim_name = piglit_get_prim_name(prims[i].prim);
const char *tf_name = piglit_get_prim_name(tf_prim);
glDrawArrays(prims[i].prim, 0, 4);
error = glGetError();
if (prims[i].tf_prim != tf_prim) {
if (error != GL_INVALID_OPERATION) {
printf("Expected GL error 0x%x, got 0x%x, when "
"rendering %s during %s transform feedback\n",
GL_INVALID_OPERATION, error,
prim_name, tf_name);
return false;
}
} else {
if (error != 0) {
printf("Unxpected GL error 0x%x when "
"rendering %s during %s transform feedback\n",
error,
prim_name, tf_name);
return false;
}
}
return true;
}
static bool
test_transform_feedback_prim(GLenum tf_prim)
{
bool pass = true;
int i;
glBeginTransformFeedbackEXT(tf_prim);
for (i = 0; i < ARRAY_SIZE(prims); i++) {
pass = pass && test_one_prim(tf_prim, i);
}
glEndTransformFeedbackEXT();
return pass;
}
enum piglit_result
piglit_display(void)
{
bool pass = true;
pass = pass && test_transform_feedback_prim(GL_POINTS);
pass = pass && test_transform_feedback_prim(GL_LINES);
pass = pass && test_transform_feedback_prim(GL_TRIANGLES);
piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
/* UNREACHED */
return PIGLIT_FAIL;
}
static const char *vs_source =
"void main()\n"
"{\n"
" gl_Position = gl_Vertex;\n"
"}\n";
static const char *fs_source =
"void main()\n"
"{\n"
" gl_FragColor = vec4(0.0, 1.0, 0.0, 0.0);\n"
"}\n";
void
piglit_init(int argc, char **argv)
{
float verts[] = {
-1, -1,
1, -1,
1, 1,
-1, 1
};
GLuint vbo, xfb, vs, fs, prog;
const char *varying = "gl_Position";
piglit_require_extension("GL_EXT_transform_feedback");
piglit_require_gl_version(30);
piglit_require_transform_feedback();
glGenBuffersARB(1, &vbo);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, 8 * sizeof(float),
verts, GL_DYNAMIC_DRAW);
glGenBuffersARB(1, &xfb);
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, xfb);
glBufferDataARB(GL_TRANSFORM_FEEDBACK_BUFFER, 4096, NULL,
GL_DYNAMIC_DRAW);
vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source);
fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source);
prog = glCreateProgram();
glAttachShader(prog, vs);
glAttachShader(prog, fs);
glTransformFeedbackVaryings(prog, 1, &varying, GL_INTERLEAVED_ATTRIBS);
glLinkProgram(prog);
if (!fs || !vs || !prog)
piglit_report_result(PIGLIT_FAIL);
if (!piglit_link_check_status(prog))
piglit_report_result(PIGLIT_FAIL);
glUseProgram(prog);
glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 0, xfb, 0, 4096);
}
|