void test_uniform_int(Generator & gen) { typedef boost::uniform_int<int> int_gen; // large range => small range (modulo case) typedef boost::variate_generator<Generator&, int_gen> level_one; level_one uint12(gen, int_gen(1,2)); BOOST_CHECK((uint12.distribution().min)() == 1); BOOST_CHECK((uint12.distribution().max)() == 2); check_uniform_int(uint12, 100000); level_one uint16(gen, int_gen(1,6)); check_uniform_int(uint16, 100000); // test chaining to get all cases in operator() // identity map typedef boost::variate_generator<level_one&, int_gen> level_two; level_two uint01(uint12, int_gen(0, 1)); check_uniform_int(uint01, 100000); // small range => larger range level_two uint05(uint12, int_gen(-3, 2)); check_uniform_int(uint05, 100000); // small range => larger range level_two uint099(uint12, int_gen(0, 99)); check_uniform_int(uint099, 100000); // larger => small range, rejection case typedef boost::variate_generator<level_two&, int_gen> level_three; level_three uint1_4(uint05, int_gen(1, 4)); check_uniform_int(uint1_4, 100000); typedef boost::uniform_int<boost::uint8_t> int8_gen; typedef boost::variate_generator<Generator&, int8_gen> gen8_t; gen8_t gen8_03(gen, int8_gen(0, 3)); // use the full range of the type, where the destination // range is a power of the source range typedef boost::variate_generator<gen8_t, int8_gen> uniform_uint8; uniform_uint8 uint8_0255(gen8_03, int8_gen(0, 255)); check_uniform_int(uint8_0255, 100000); // use the full range, but a generator whose range is not // a root of the destination range. gen8_t gen8_02(gen, int8_gen(0, 2)); uniform_uint8 uint8_0255_2(gen8_02, int8_gen(0, 255)); check_uniform_int(uint8_0255_2, 100000); // expand the range to a larger type. typedef boost::variate_generator<gen8_t, int_gen> uniform_uint_from8; uniform_uint_from8 uint0300(gen8_03, int_gen(0, 300)); check_uniform_int(uint0300, 100000); }
/** * Test binding image uniforms to image units for a simple shader * program. */ static bool run_test_uniform(void) { const struct grid_info grid = grid_info(GL_FRAGMENT_SHADER, GL_RGBA32F, W, H); GLuint prog = generate_program( grid, GL_FRAGMENT_SHADER, concat(image_hunk(image_info_for_grid(grid), ""), hunk("uniform IMAGE_T imgs[2];\n" "\n" "GRID_T op(ivec2 idx, GRID_T x) {\n" " imageStore(imgs[0], IMAGE_ADDR(idx), x);\n" " imageStore(imgs[1], IMAGE_ADDR(idx), x);\n" " return x;\n" "}\n"), NULL)); const int loc = glGetUniformLocation(prog, "imgs"); bool ret = prog && check_uniform_int(prog, loc, 0) && check_uniform_int(prog, loc + 1, 0); int v[2]; glUseProgram(prog); /* * Image uniforms are bound to image units using * glUniform1i{v}. */ glUniform1i(loc, 3); ret &= check_uniform_int(prog, loc, 3) && check_uniform_int(prog, loc + 1, 0); glUniform1i(loc + 1, 3); ret &= check_uniform_int(prog, loc, 3) && check_uniform_int(prog, loc + 1, 3); v[0] = 4; v[1] = 5; glUniform1iv(loc, 2, v); ret &= check_uniform_int(prog, loc, 4) && check_uniform_int(prog, loc + 1, 5); /* * GL_INVALID_VALUE is generated if the value specified is * greater than or equal to the value of GL_MAX_IMAGE_UNITS. */ glUniform1i(loc, max_image_units()); ret &= piglit_check_gl_error(GL_INVALID_VALUE); v[0] = 3; v[1] = max_image_units() + 1; glUniform1iv(loc, 2, v); ret &= piglit_check_gl_error(GL_INVALID_VALUE); /* * GL_INVALID_VALUE is generated if the value specified is * less than zero. */ glUniform1i(loc, -1); ret &= piglit_check_gl_error(GL_INVALID_VALUE); v[0] = 3; v[1] = -4; glUniform1iv(loc, 2, v); ret &= piglit_check_gl_error(GL_INVALID_VALUE); /* * GL_INVALID_OPERATION is generated by Uniform* functions * other than Uniform1i{v}. */ CHECK_INVAL_2(glUniform, 1f, 1ui, (loc, 0), ret); CHECK_INVAL_3(glUniform, 2i, 2f, 2ui, (loc, 0, 0), ret); CHECK_INVAL_3(glUniform, 3i, 3f, 3ui, (loc, 0, 0, 0), ret); CHECK_INVAL_3(glUniform, 4i, 4f, 4ui, (loc, 0, 0, 0, 0), ret); CHECK_INVAL_2(glUniform, 1fv, 1uiv, (loc, 1, (void *)v), ret); CHECK_INVAL_3(glUniform, 2iv, 2fv, 2uiv, (loc, 1, (void *)v), ret); CHECK_INVAL_3(glUniform, 3iv, 3fv, 3uiv, (loc, 1, (void *)v), ret); CHECK_INVAL_3(glUniform, 4iv, 4fv, 4uiv, (loc, 1, (void *)v), ret); CHECK_INVAL_3(glUniformMatrix, 2fv, 3fv, 4fv, (loc, 1, GL_FALSE, (float *)v), ret); CHECK_INVAL_3(glUniformMatrix, 2x3fv, 3x2fv, 2x4fv, (loc, 1, GL_FALSE, (float *)v), ret); CHECK_INVAL_3(glUniformMatrix, 4x2fv, 3x4fv, 4x3fv, (loc, 1, GL_FALSE, (float *)v), ret); if (piglit_is_extension_supported("GL_ARB_gpu_shader_fp64")) { CHECK_INVAL_1(glUniform, 1d, (loc, 0), ret); CHECK_INVAL_1(glUniform, 2d, (loc, 0, 0), ret); CHECK_INVAL_1(glUniform, 3d, (loc, 0, 0, 0), ret); CHECK_INVAL_1(glUniform, 4d, (loc, 0, 0, 0, 0), ret); CHECK_INVAL_2(glUniform, 1dv, 2dv, (loc, 1, (double *)v), ret); CHECK_INVAL_2(glUniform, 3dv, 4dv, (loc, 1, (double *)v), ret); CHECK_INVAL_3(glUniformMatrix, 2dv, 3dv, 4dv, (loc, 1, GL_FALSE, (double *)v), ret); CHECK_INVAL_3(glUniformMatrix, 2x3dv, 3x2dv, 2x4dv, (loc, 1, GL_FALSE, (double *)v), ret); CHECK_INVAL_3(glUniformMatrix, 4x2dv, 3x4dv, 4x3dv, (loc, 1, GL_FALSE, (double *)v), ret); } glDeleteProgram(prog); return ret; }