bool test_exact() { int i, Bpp, channels; float *tmp_float; GLubyte *data, *observed; GLint tex_width, tex_height; bool pass = true; if (format->data_type == GL_NONE) { piglit_report_subtest_result(PIGLIT_SKIP, "Exact upload-download of %s", piglit_get_gl_enum_name(format->internal_format)); return true; } channels = num_channels(format->format); Bpp = bytes_per_pixel(format->format, format->data_type); if (format->data_type == GL_FLOAT) { /* Sanatize so we don't get invalid floating point values */ tmp_float = malloc(texture_size * texture_size * channels * sizeof(float)); for (i = 0; i < texture_size * texture_size * channels; ++i) tmp_float[i] = sn_to_float(32, ((GLint *)rand_data)[i]); data = (GLubyte *)tmp_float; } else { tmp_float = NULL; data = rand_data; } glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, format->internal_format, texture_size, texture_size, 0, format->format, format->data_type, data); pass &= piglit_check_gl_error(GL_NO_ERROR); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &tex_width); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &tex_height); glPixelStorei(GL_PACK_ALIGNMENT, 1); observed = malloc(tex_width * tex_height * Bpp); glGetTexImage(GL_TEXTURE_2D, 0, format->format, format->data_type, observed); pass &= piglit_check_gl_error(GL_NO_ERROR); for (i = 0; i < texture_size; ++i) pass &= memcmp(&data[i * texture_size * Bpp], &observed[i * tex_width * Bpp], texture_size * Bpp) == 0; free(observed); free(tmp_float); piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL, "Exact upload-download of %s", piglit_get_gl_enum_name(format->internal_format)); return pass; }
/* * Prints the info of a failing case. If expected_value is smaller * that 0, it is not printed. */ void print_failing_case_full(const GLenum target, const GLenum internalformat, const GLenum pname, GLint64 expected_value, test_data *data) { /* Knowing if it is supported is interesting in order to know * if the test is being too restrictive */ bool supported = test_data_check_supported(data, target, internalformat); GLint64 current_value = test_data_value_at_index(data, 0); if (data->testing64) { fprintf(stderr, " 64 bit failing case: "); } else { fprintf(stderr, " 32 bit failing case: "); } fprintf(stderr, "pname = %s, " "target = %s, internalformat = %s, ", piglit_get_gl_enum_name(pname), piglit_get_gl_enum_name(target), piglit_get_gl_enum_name(internalformat)); if (expected_value >= 0) fprintf(stderr, "expected value = (%" PRIi64 "), ", expected_value); fprintf(stderr, "params[0] = (%" PRIi64 ",%s), " "supported=%i\n", current_value, piglit_get_gl_enum_name(current_value), supported); }
void piglit_init(int argc, char **argv) { bool pass = true; GLint64 data = -2; int i = 0; int stuff[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int size = sizeof(stuff); int offset = 1; int range = 5; GLuint buff = 0; glGenBuffers(1, &buff); for (i = 0; i < ARRAY_SIZE(buffers); i++) { glBindBuffer(buffers[i], buff); glBufferData(buffers[i], size, stuff, GL_STATIC_READ); glMapBufferRange(buffers[i], offset, range, GL_MAP_READ_BIT); glGetBufferParameteri64v(buffers[i], GL_BUFFER_SIZE, &data); if(data != size) { printf("GL_BUFFER_SIZE for %s expected %d, but %d " "was returned.\n", piglit_get_gl_enum_name(buffers[i]), size, (int)data); pass = false; } pass = piglit_check_gl_error(GL_NO_ERROR) && pass; glGetBufferParameteri64v(buffers[i], GL_BUFFER_MAP_OFFSET, &data); if(data != offset) { printf("GL_BUFFER_MAP_OFFSET for %s expected %d, but " "%d was returned.\n", piglit_get_gl_enum_name(buffers[i]), offset, (int)data); pass = false; } pass = piglit_check_gl_error(GL_NO_ERROR) && pass; glGetBufferParameteri64v(buffers[i], GL_BUFFER_MAP_LENGTH, &data); if(data != range) { printf("GL_BUFFER_MAP_LENGTH for %s expected %d, but " "%d was returned.\n", piglit_get_gl_enum_name(buffers[i]), range, (int)data); pass = false; } glUnmapBuffer(buffers[i]); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; } pass = piglit_check_gl_error(GL_NO_ERROR) && pass; piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }
bool CheckFramebufferStatus(GLenum expected) { GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if(status != expected) { printf("Expected Framebuffer status '%s', got '%s'\n", piglit_get_gl_enum_name(expected), piglit_get_gl_enum_name(status)); return false; } return true; }
bool check_framebuffer_status(GLenum target, GLenum expected) { GLenum observed = glCheckFramebufferStatus(target); if(expected != observed) { printf("Unexpected framebuffer status!\n" " Observed: %s\n Expected: %s\n", piglit_get_gl_enum_name(observed), piglit_get_gl_enum_name(expected)); return false; } return true; }
void piglit_init(int argc, char **argv) { GLsync sync; GLenum ret1, ret2; bool pass = true; piglit_require_extension("GL_ARB_sync"); glClear(GL_COLOR_BUFFER_BIT); sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); ret1 = glClientWaitSync(sync, GL_SYNC_FLUSH_COMMANDS_BIT, 0); glFinish(); ret2 = glClientWaitSync(sync, 0, 0); glDeleteSync(sync); if (ret1 != GL_TIMEOUT_EXPIRED && ret1 != GL_ALREADY_SIGNALED) { fprintf(stderr, "On first wait:\n" " Expected GL_ALREADY_SIGNALED or GL_TIMEOUT_EXPIRED\n" " Got %s\n", piglit_get_gl_enum_name(ret1)); pass = false; } if (ret2 != GL_ALREADY_SIGNALED) { fprintf(stderr, "On repeated wait:\n" " Expected GL_ALREADY_SIGNALED\n" " Got %s\n", piglit_get_gl_enum_name(ret2)); pass = false; } glClear(GL_COLOR_BUFFER_BIT); sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); glFinish(); ret1 = glClientWaitSync(sync, GL_SYNC_FLUSH_COMMANDS_BIT, 0); if (ret1 != GL_ALREADY_SIGNALED) { fprintf(stderr, "On wait after a finish:\n" " Expected GL_ALREADY_SIGNALED\n" " Got %s\n", piglit_get_gl_enum_name(ret1)); pass = false; } piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }
void piglit_init(int argc, char **argv) { int i; bool pass = true; GLenum fbStatus; GLuint fbo, texture; GLint attachmentLayeredStatus; for(i = 0; i < ARRAY_SIZE(textureType); i++) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); texture = create_bind_texture(textureType[i]); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture, 0); if(!piglit_check_gl_error(GL_NO_ERROR)) { printf("Error creating texture and framebuffer setup\n" "texture type: %s\n", piglit_get_gl_enum_name(textureType[i])); glDeleteFramebuffers(1, &fbo); glDeleteTextures(1, &texture); piglit_report_result(PIGLIT_FAIL); } fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER); if(fbStatus != GL_FRAMEBUFFER_COMPLETE) { printf("Framebuffer Status: %s\n", piglit_get_gl_enum_name(fbStatus)); glDeleteFramebuffers(1, &fbo); glDeleteTextures(1, &texture); piglit_report_result(PIGLIT_FAIL); } /* Check if the attachment is layered */ glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_LAYERED, &attachmentLayeredStatus); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; if(attachmentLayeredStatus != GL_TRUE) { pass = false; } glDeleteFramebuffers(1, &fbo); glDeleteTextures(1, &texture); } piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }
/* * print_failing_case just prints out details of which case * failed. Here we are trying to add debug info about why the test * failed. It assumes that fails on getting the wrong value, not on * getting a opengl error */ static void print_failing_details(GLenum target, GLenum internalformat) { if (target == GL_TEXTURE_BUFFER || is_multisample_target(target)) fprintf(stderr, "\tTarget %s doesn't support multi-texel filtering\n", piglit_get_gl_enum_name(target)); if (is_integer_internalformat(internalformat)) fprintf(stderr, "\tInteger internalformats like %s doesn't " "support multi-texel filtering\n", piglit_get_gl_enum_name(internalformat)); }
static GLboolean test_combo(GLenum frontMode, GLenum backMode) { GLenum frontPrim = get_prim_mode(frontMode); GLenum backPrim = get_prim_mode(backMode); GLboolean pass = GL_TRUE; GLenum expectedPrims[4]; int i; /* Draw reference image */ glClear(GL_COLOR_BUFFER_BIT); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDrawArrays(frontPrim, 0, 4); glDrawArrays(backPrim, 4, 4); glDrawArrays(frontPrim, 8, 4); glDrawArrays(backPrim, 12, 4); /* determine what kind of primitives were drawn */ for (i = 0; i < 4; i++) { GLenum testMode = (i & 1) ? backMode : frontMode; expectedPrims[i] = identify_primitive(&Positions[4 * i], Colors[4 * i]); if (expectedPrims[i] != testMode) { /* we didn't get the expected reference primitive */ fprintf(stderr, "%s: reference drawing failed for frontPrim=%s, backPrim=%s\n", TestName, piglit_get_gl_enum_name(frontMode), piglit_get_gl_enum_name(backMode)); fprintf(stderr, "At position %d, found prim %s instead of %s\n", i, piglit_get_gl_enum_name(expectedPrims[i]), piglit_get_gl_enum_name(testMode)); return GL_FALSE; } } /* Draw test image */ glClear(GL_COLOR_BUFFER_BIT); glPolygonMode(GL_FRONT, frontMode); glPolygonMode(GL_BACK, backMode); glDrawArrays(GL_QUADS, 0, 16); /* check that these prims match the reference prims */ for (i = 0; i < 4; i++) { GLenum prim = identify_primitive(&Positions[4 * i], Colors[4 * i]); if (prim != expectedPrims[i]) { fprintf(stderr, "%s: glPolygonMode(front=%s, back=%s) failed\n", TestName, piglit_get_gl_enum_name(frontMode), piglit_get_gl_enum_name(backMode)); fprintf(stderr, "At position %d, found prim %s instead of %s\n", i, piglit_get_gl_enum_name(prim), piglit_get_gl_enum_name(expectedPrims[i])); pass = GL_FALSE; } } piglit_present_results(); return pass; }
PIGLIT_GL_TEST_CONFIG_END static bool test_format(const struct uniform_type *type) { /* Using 140 to get unsigned ints. */ const char *fs_template = "#version 140\n" "layout(std140) uniform ubo {\n" " float align_test;\n" " %s u;\n" "};\n" "\n" "void main() {\n" " gl_FragColor = vec4(align_test + float(%s));\n" "}\n"; char *fs_source; GLuint prog; const char *uniform_name = "u"; GLuint uniform_index; GLint uniform_type; const char *deref; if (type->size == 4) { deref = "u"; } else if (type->size <= 16) { deref = "u.x"; } else { deref = "u[0].x"; } asprintf(&fs_source, fs_template, type->type, deref); prog = piglit_build_simple_program(NULL, fs_source); free(fs_source); glGetUniformIndices(prog, 1, &uniform_name, &uniform_index); glGetActiveUniformsiv(prog, 1, &uniform_index, GL_UNIFORM_TYPE, &uniform_type); glDeleteProgram(prog); printf("%-20s %20s %20s%s\n", type->type, piglit_get_gl_enum_name(uniform_type), piglit_get_gl_enum_name(type->gl_type), uniform_type == type->gl_type ? "" : " FAIL"); return uniform_type == type->gl_type; }
static bool test_param(GLenum pname, GLenum expected_value, const char *const source) { int v; glGetProgramiv(prog, pname, &v); if (v == expected_value) return true; fprintf(stderr, "%s is %s, expected %s for program \n%s\n", piglit_get_gl_enum_name(pname), piglit_get_gl_enum_name(v), piglit_get_gl_enum_name(expected_value), source); return false; }
/** * Iterate through array of texture formats and check if call to TextureView * causes the gl error "err" */ static bool check_format_array(const GLenum err, const unsigned int numFormats, const GLenum *formatArray, const GLenum target, const GLuint tex, const GLuint levels, const GLuint layers) { unsigned int i; bool pass = true; for (i = 0; i < numFormats; i++) { GLenum format; GLuint newTex; format = formatArray[i]; if (format == 0) continue; glGenTextures(1, &newTex); glTextureView(newTex, target, tex, format, 0, levels, 0, layers); glDeleteTextures(1, &newTex); if (!piglit_check_gl_error(err)) { printf("failing texView format=%s\n", piglit_get_gl_enum_name(format)); pass = false; break; } } return pass; }
void piglit_init(int argc, char **argv) { GLsync sync; GLenum ret1, ret2; piglit_require_extension("GL_ARB_sync"); glClear(GL_COLOR_BUFFER_BIT); sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); ret1 = glClientWaitSync(sync, GL_SYNC_FLUSH_COMMANDS_BIT, ONE_SECOND); ret2 = glClientWaitSync(sync, 0, ONE_SECOND); if (ret1 == GL_TIMEOUT_EXPIRED) { printf("timeout expired on the first wait\n"); piglit_report_result(PIGLIT_SKIP); } if (ret2 != GL_ALREADY_SIGNALED) { fprintf(stderr, "Expected GL_ALREADY_SIGNALED on second wait, got %s", piglit_get_gl_enum_name(ret2)); piglit_report_result(PIGLIT_FAIL); } piglit_report_result(PIGLIT_PASS); }
/** * Determine whether the given type contains floating-point values. */ static bool is_floating_type(GLenum type) { switch (type) { case GL_FLOAT: case GL_FLOAT_VEC2: case GL_FLOAT_VEC3: case GL_FLOAT_VEC4: case GL_FLOAT_MAT2: case GL_FLOAT_MAT2x3: case GL_FLOAT_MAT2x4: case GL_FLOAT_MAT3x2: case GL_FLOAT_MAT3: case GL_FLOAT_MAT3x4: case GL_FLOAT_MAT4x2: case GL_FLOAT_MAT4x3: case GL_FLOAT_MAT4: return true; case GL_INT: case GL_INT_VEC2: case GL_INT_VEC3: case GL_INT_VEC4: case GL_UNSIGNED_INT: case GL_UNSIGNED_INT_VEC2: case GL_UNSIGNED_INT_VEC3: case GL_UNSIGNED_INT_VEC4: return false; default: printf("Unexpected type: %u (%s)\n", type, piglit_get_gl_enum_name(type)); piglit_report_result(PIGLIT_FAIL); return false; } }
static bool test_link_fail(GLenum target, const char *source) { GLuint shader, prog; GLint ok; shader = piglit_compile_shader_text(target, source); prog = glCreateProgram(); glAttachShader(prog, shader); glLinkProgram(prog); glDeleteShader(shader); glGetProgramiv(prog, GL_LINK_STATUS, &ok); glDeleteProgram(prog); if (ok) { fprintf(stderr, "Linking with only a %s succeeded when it should have " "failed:\n", piglit_get_gl_enum_name(target)); return false; } return true; }
bool check_fbo_status(GLenum expect) { GLenum status = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); if (status != expect) { fprintf(stderr, "status was %s (0x%04x), " "expected %s (0x%04x).\n", piglit_get_gl_enum_name(status), status, piglit_get_gl_enum_name(expect), expect); return false; } return true; }
static bool test_3d_tex_format(GLenum internalFormat) { GLint width, height, depth; bool pass = true; unsigned mbytes; piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); /* use proxy texture to find actual max texture size */ width = height = depth = 0; find_max_tex3d_size(internalFormat, MaxSize, &width, &height, &depth); mbytes = tex_size(internalFormat, width, height, depth); printf("Actual max 3D texture size for %s: %d x %d x %d (%u MB)\n", piglit_get_gl_enum_name(internalFormat), width, height, depth, mbytes); /* first, try some smaller res 3D texture rendering */ pass = test_render(internalFormat, width, height, depth/4); pass = test_render(internalFormat, width, height, depth/2) && pass; /* test largest 3D texture size */ pass = test_render(internalFormat, width, height, depth) && pass; return pass; }
static void * pixelsInit(GLenum format, GLenum type) { switch(format) { case GL_RED: case GL_GREEN: case GL_BLUE: case GL_ALPHA: case GL_LUMINANCE: case GL_DEPTH_COMPONENT: case GL_STENCIL_INDEX: return (allocPixels(format, type, 1)); case GL_LUMINANCE_ALPHA: case GL_RG: return (allocPixels(format, type, 2)); case GL_RGB: case GL_BGR: return (allocPixels(format, type, 3)); case GL_RGBA: case GL_BGRA: return (allocPixels(format, type, 4)); default: printf("format = %s not allowed in glDrawPixels()\n", piglit_get_gl_enum_name(format)); piglit_report_result(PIGLIT_FAIL); } return NULL; }
static void piglit_test_uint64(GLenum token, GLuint64 limit, bool max) { const char *name = piglit_get_gl_enum_name(token); GLuint64 val = SENTINEL; bool pass; /* To obtain GLuint64 values, we must use glGetInteger64v. * Justification is found in the GL_ARB_sync spec: * * 30) What is the type of the timeout interval? * * RESOLVED: GLuint64. [...] Consequently the type of <timeout> * has been changed to 'GLuint64' and a corresponding * 'GetInteger64v' query taking 'GLint64' added (by symmetry * with GetInteger, where unsigned quantities are queries with * a function taking a pointer to a signed integer - the pointer * conversion is harmless). */ glGetInteger64v(token, (GLint64*) &val); pass = piglit_check_gl_error(GL_NO_ERROR); piglit_report_uint64(name, limit, val, pass && val != SENTINEL && ((max && val <= limit) || (!max && val >= limit))); }
static bool check_textures_type(void) { bool check_pass = true; test_data *data = test_data_new(0, 1); unsigned i; int testing64; for (i = 0; i < ARRAY_SIZE(pnames); i++) { bool pass = true; for (testing64 = 0; testing64 <= 1; testing64++) { test_data_set_testing64(data, testing64); pass = try_textures_type(texture_targets, ARRAY_SIZE(texture_targets), valid_internalformats, ARRAY_SIZE(valid_internalformats), pnames[i], equivalent_pnames[i], data) && pass; } piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL, "%s", piglit_get_gl_enum_name(pnames[i])); check_pass = check_pass && pass; } test_data_clear(&data); return check_pass; }
/** * Compute the number of varying slots occupied by a given type. */ static unsigned size_of_type(GLenum type) { switch (type) { case GL_FLOAT: return 1; case GL_FLOAT_VEC2: return 2; case GL_FLOAT_VEC3: return 3; case GL_FLOAT_VEC4: return 4; case GL_FLOAT_MAT2: return 4; case GL_FLOAT_MAT2x3: return 6; case GL_FLOAT_MAT2x4: return 8; case GL_FLOAT_MAT3x2: return 6; case GL_FLOAT_MAT3: return 9; case GL_FLOAT_MAT3x4: return 12; case GL_FLOAT_MAT4x2: return 8; case GL_FLOAT_MAT4x3: return 12; case GL_FLOAT_MAT4: return 16; case GL_INT: return 1; case GL_INT_VEC2: return 2; case GL_INT_VEC3: return 3; case GL_INT_VEC4: return 4; case GL_UNSIGNED_INT: return 1; case GL_UNSIGNED_INT_VEC2: return 2; case GL_UNSIGNED_INT_VEC3: return 3; case GL_UNSIGNED_INT_VEC4: return 4; default: printf("Unexpected type: %u (%s)\n", type, piglit_get_gl_enum_name(type)); piglit_report_result(PIGLIT_FAIL); return 0; } }
PIGLIT_GL_TEST_CONFIG_END static bool test_get(GLenum pname, GLint expectedValue) { GLint i; GLfloat f; GLdouble d; GLboolean b; bool pass = true; glGetIntegerv(pname, &i); glGetFloatv(pname, &f); glGetDoublev(pname, &d); glGetBooleanv(pname, &b); if (i != expectedValue) { printf("glGetIntegerv(%s) failed: expected %d, got %d\n", piglit_get_gl_enum_name(pname), expectedValue, i); pass = false; } if (f != (GLfloat) expectedValue) { printf("glGetFloatv(%s) failed: expected %f, got %f\n", piglit_get_gl_enum_name(pname), (GLfloat) expectedValue, f); pass = false; } if (d != (GLdouble) expectedValue) { printf("glGetDoublev(%s) failed: expected %f, got %f\n", piglit_get_gl_enum_name(pname), (GLdouble) expectedValue, f); pass = false; } if (b != (GLboolean) !!expectedValue) { printf("glGetBooleanv(%s) failed: expected %d, got %d\n", piglit_get_gl_enum_name(pname), !!expectedValue, b); pass = false; } return pass; }
static bool test_list(GLuint list, GLenum dlmode, const char *func) { bool pass = true; const float *exp_color; assert(dlmode == GL_COMPILE || dlmode == GL_COMPILE_AND_EXECUTE); if (dlmode == GL_COMPILE_AND_EXECUTE) { /* the polygon should have been drawn during display * list construction. */ exp_color = white; } else { /* the polygon should not have been drawn yet */ exp_color = black; } pass = piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height, exp_color); if (!pass) { fprintf(stderr, "Compiling %s in display list failed for %s mode\n", func, piglit_get_gl_enum_name(dlmode)); glDeleteLists(list, 1); return pass; } /* Now, call the list and make sure the polygon is rendered */ glClear(GL_COLOR_BUFFER_BIT); glCallList(list); pass = piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height, white); piglit_present_results(); glDeleteLists(list, 1); if (!pass) { fprintf(stderr, "Calling %s in display list failed for %s mode\n", func, piglit_get_gl_enum_name(dlmode)); } return pass; }
void piglit_init(int argc, char **argv) { bool pass = true; unsigned i; if (piglit_get_gl_version() >= 40) { /* Behaviour/error list changed on OpenGL 4.0, so we * let the equivalent 4.x test to test it. */ piglit_report_result(PIGLIT_SKIP); } /* Selecting the default framebuffer */ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); for (i = 0; i < ARRAY_SIZE(valids); i++) { GLenum err = 0; glDrawBuffers(1, &valids[i]); err = glGetError(); /* err = INVALID_OPERATION if that color buffer is not * allocated to the window system */ if (err != GL_NONE && err != GL_INVALID_OPERATION) { printf("Expected GL_NONE or GL_INVALID_OPERATION with" " %s but received: %s\n", piglit_get_gl_enum_name(valids[i]), piglit_get_gl_enum_name(err)); pass = false; } } for (i = 0; i < ARRAY_SIZE(invalids); i++) { GLenum err = 0; glDrawBuffers(1, &invalids[i]); err = glGetError(); if (err != GL_INVALID_ENUM) { printf("Expected GL_INVALID_ENUM with %s but " "received: %s\n", piglit_get_gl_enum_name(invalids[i]), piglit_get_gl_enum_name(err)); pass = false; } } piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }
/** * Verify that glGetTransformFeedbackVarying() returns the proper * information for all "good" varying names. * * The program should already be linked and stored in the global \c * prog. */ static enum piglit_result test_gets() { unsigned i; unsigned num_good_varyings = count_strings(test->good_varyings); const char **varyings; bool pass = true; if (use_interface_blocks) varyings = prepend_varyings("Blk.", test->good_varyings); else varyings = test->good_varyings; for (i = 0; i < num_good_varyings; i++) { const char *exp_name = varyings[i]; GLsizei exp_length = strlen(exp_name); GLsizei exp_size = test->expected_sizes[i]; GLenum exp_type = test->expected_types[i]; GLsizei length; GLsizei size; GLenum type; char name[100]; glGetTransformFeedbackVarying(prog, i, sizeof(name), &length, &size, &type, name); if (length != exp_length || size != exp_size || type != exp_type || strcmp(name, exp_name) != 0) { pass = false; printf("glGetTransformFeedbackVarying() returned " "unexpected data for varying %u:\n", i); printf(" length: expected %u, got %u\n", exp_length, length); printf(" size: expected %u, got %u\n", exp_size, size); printf(" type: expected %u (%s), got %u (%s)\n", exp_type, piglit_get_gl_enum_name(exp_type), type, piglit_get_gl_enum_name(type)); printf(" name: expected %s, got %s\n", exp_name, name); } } if (use_interface_blocks) free_varyings(varyings); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
static bool _expect(int line, GLenum token, GLint val) { GLint ret = 0xd0d0d0d0; glGetIntegerv(token, &ret); if (ret != val) { fprintf(stderr, "line %d: %s was %s, expected %s\n", line, piglit_get_gl_enum_name(token), piglit_get_gl_enum_name(ret), piglit_get_gl_enum_name(val)); return false; } return true; }
static float typeToFloat(GLenum format, GLenum type, GLvoid *src, GLuint index, p_ops pixelops) { /* Scale factors */ GLuint pi, pui, mask; GLushort pus; GLshort ps; GLfloat pf; GLint stencil_bits; GLbyte pb; GLubyte pub; const GLuint *uisrc; const GLushort *ussrc; const GLubyte *ubsrc; GLfloat rs = 1.0f, gs = 1.0f, bs = 1.0f, as = 1.0f; GLboolean swap = (pixelops.pname == GL_UNPACK_SWAP_BYTES) ? pixelops.param : false; if (format == GL_STENCIL_INDEX) { glGetIntegerv(GL_STENCIL_BITS, &stencil_bits); /* Clamp the return value to the size of stencil buffer */ mask = 0xffffffff >> (sizeof(GLuint) * 8 - stencil_bits); switch(type) { case GL_BYTE: pb = ((GLbyte *)src)[index]; return pb & mask; case GL_UNSIGNED_BYTE: pub = ((GLubyte *)src)[index]; return pub & mask; case GL_SHORT: ps = ((GLshort *)src)[index]; if (swap) Swap2Byte(&ps); return ps & mask; case GL_UNSIGNED_SHORT: pus = ((GLushort *)src)[index]; if (swap) Swap2Byte(&pus); return pus & mask; case GL_INT: pi = ((GLint *)src)[index]; if (swap) Swap4Byte(&pi); return pi & mask; case GL_UNSIGNED_INT: pui = ((GLuint *)src)[index]; if (swap) Swap4Byte(&pui); return pui & mask; case GL_FLOAT: pf = ((GLfloat *)src)[index]; if (swap) Swap4Byte(&pf); return (GLfloat)((GLuint)pf & mask); default: printf("type = %s not allowed in glDrawPixels()\n", piglit_get_gl_enum_name(type)); piglit_report_result(PIGLIT_FAIL); } }
static void enumerate_subtests(void) { const char *names[64]; assert(ARRAY_SIZE(formats) + ARRAY_SIZE(invalid_formats) < 64); int t = 0; for (int i = 0; i < ARRAY_SIZE(formats); i++) { names[t++] = piglit_get_gl_enum_name(formats[i].format); } for (int i = 0; i < ARRAY_SIZE(invalid_formats); i++) { names[t++] = piglit_get_gl_enum_name(invalid_formats[i]); } names[t] = NULL; piglit_register_subtests(names); }
static bool setup_fbo_2d(const GLuint colorTarget, const GLenum internalFormat, const GLenum format, const GLenum formatType, const GLuint width, const GLuint height, const GLuint fbo, GLuint *pTexture) { GLenum status; glGenTextures(1, pTexture); glBindTexture(GL_TEXTURE_2D, *pTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, formatType, NULL); /* * Framebuffer object is implied to be bound. */ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + colorTarget, GL_TEXTURE_2D, *pTexture, 0); if (!piglit_check_gl_error(GL_NO_ERROR)) { fprintf(stderr, "Failed to create FBO %u.\n", colorTarget); piglit_report_result(PIGLIT_FAIL); return false; } status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { fprintf(stderr, "Incomplete fbo for format %s.%s (status %s)\n", piglit_get_gl_enum_name(internalFormat), piglit_get_gl_enum_name(format), piglit_get_gl_enum_name(status)); piglit_report_result(PIGLIT_FAIL); return false; } return true; }
/* * Blit the passed texture to the screen. If texture is layered, * loops through each layer and blit it to the screen. Otherwise scales * the layer zero vertically with a factor of texDepth. */ bool display_texture(int x, int y, GLuint tex, int layers) { GLuint tempFBO; GLenum fbStatus; /* Gen temp fbo to work with */ glGenFramebuffers(1, &tempFBO); if (layers == 1) { glBindFramebuffer(GL_FRAMEBUFFER, tempFBO); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0); /* Blit layer to screen */ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo); glBindFramebuffer(GL_READ_FRAMEBUFFER, tempFBO); glBlitFramebuffer(0, 0, texWidth, texHeight, x, y, x + texWidth, y + texDepth * texHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); } else { int i; /* loop through each layer */ for (i = 0; i < layers; i++) { /* Bind new layer to display */ glBindFramebuffer(GL_FRAMEBUFFER, tempFBO); glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex, 0, i); fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (fbStatus != GL_FRAMEBUFFER_COMPLETE) { printf("Framebuffer Status: %s\n", piglit_get_gl_enum_name(fbStatus)); return false; } /* Blit layer to screen */ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo); glBindFramebuffer(GL_READ_FRAMEBUFFER, tempFBO); glBlitFramebuffer(0, 0, texWidth, texHeight, x, y + i * texHeight, x + texWidth, y + (i + 1) * texHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); } } /* Cleanup temp fbo */ glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo); glDeleteFramebuffers(1, &tempFBO); return piglit_check_gl_error(GL_NO_ERROR); }