static void do_texture_setup(void) { GLuint tex; GLenum target = target_for_sampler[sampler]; pixels = malloc(components * sizeof(unsigned char) * texture_width * texture_height); expected = malloc(4 * sizeof(float) * texture_width * texture_height); glGenTextures(1, &tex); glBindTexture(target, tex); make_image(components, channel_to_fill()); make_expected(); switch(sampler) { case SAMPLER_2D: case SAMPLER_2DRECT: upload_2d(target, pixels); break; case SAMPLER_2DARRAY: upload_3d(target, NULL); upload_array_slice(target, 1, pixels); break; case SAMPLER_CUBE: /* legacy cubes are weird. the only sane way to specify the whole * thing at once is using glTexStorage, and we'd rather not rely on * ARB_texture_storage just for that. */ upload_2d(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, NULL); upload_2d(GL_TEXTURE_CUBE_MAP_POSITIVE_X, NULL); upload_2d(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, NULL); upload_2d(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, NULL); upload_2d(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, NULL); upload_2d(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, pixels); break; case SAMPLER_CUBEARRAY: upload_3d(target, NULL); upload_array_slice(target, 10, pixels); break; } glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); if (comptype == SHADOW_T) { glTexParameteri(target_for_sampler[sampler], GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); glTexParameteri(target_for_sampler[sampler], GL_TEXTURE_COMPARE_FUNC, GL_LESS); } glTexParameteri(target_for_sampler[sampler], GL_TEXTURE_WRAP_S, address_mode); glTexParameteri(target_for_sampler[sampler], GL_TEXTURE_WRAP_T, address_mode); glTexParameteri(target_for_sampler[sampler], GL_TEXTURE_WRAP_R, address_mode); }
expected<T> make_expected(optional<T> v) { if (v) return make_expected(*v); else make_unexpected(conversion_from_nullopt()); }