EEVEE: Try to allocate the lightcache and use fallback if failure

This is to remove an explicit opengl dependence to GPU_extension.
This commit is contained in:
Clément Foucault 2020-09-07 19:17:04 +02:00
parent 171b36683a
commit a784e90be0
5 changed files with 22 additions and 30 deletions

View File

@ -348,17 +348,14 @@ LightCache *EEVEE_lightcache_create(const int grid_len,
int mips_len = log2_floor_u(cube_size) - MIN_CUBE_LOD_LEVEL;
if (GPU_arb_texture_cube_map_array_is_supported()) {
light_cache->cube_tx.tex = DRW_texture_create_cube_array(
cube_size, cube_len, GPU_R11F_G11F_B10F, DRW_TEX_FILTER | DRW_TEX_MIPMAP, NULL);
}
else {
light_cache->cube_tx.tex = DRW_texture_create_2d_array(cube_size,
cube_size,
cube_len * 6,
GPU_R11F_G11F_B10F,
DRW_TEX_FILTER | DRW_TEX_MIPMAP,
NULL);
/* Try to create a cubemap array. */
DRWTextureFlag cube_texflag = DRW_TEX_FILTER | DRW_TEX_MIPMAP;
light_cache->cube_tx.tex = DRW_texture_create_cube_array(
cube_size, cube_len, GPU_R11F_G11F_B10F, cube_texflag, NULL);
if (light_cache->cube_tx.tex == NULL) {
/* Try fallback to 2D array. */
light_cache->cube_tx.tex = DRW_texture_create_2d_array(
cube_size, cube_size, cube_len * 6, GPU_R11F_G11F_B10F, cube_texflag, NULL);
}
light_cache->cube_tx.tex_size[0] = cube_size;
@ -414,15 +411,16 @@ static bool eevee_lightcache_static_load(LightCache *lcache)
}
if (lcache->cube_tx.tex == NULL) {
if (GPU_arb_texture_cube_map_array_is_supported()) {
lcache->cube_tx.tex = GPU_texture_create_cube_array("lightcache_cubemaps",
lcache->cube_tx.tex_size[0],
lcache->cube_tx.tex_size[2] / 6,
lcache->mips_len + 1,
GPU_R11F_G11F_B10F,
NULL);
}
else {
/* Try to create a cubemap array. */
lcache->cube_tx.tex = GPU_texture_create_cube_array("lightcache_cubemaps",
lcache->cube_tx.tex_size[0],
lcache->cube_tx.tex_size[2] / 6,
lcache->mips_len + 1,
GPU_R11F_G11F_B10F,
NULL);
if (lcache->cube_tx.tex == NULL) {
/* Try fallback to 2D array. */
lcache->cube_tx.tex = GPU_texture_create_2d_array("lightcache_cubemaps_fallback",
UNPACK3(lcache->cube_tx.tex_size),
lcache->mips_len + 1,

View File

@ -41,7 +41,6 @@ int GPU_max_color_texture_samples(void);
int GPU_max_cube_map_size(void);
int GPU_max_ubo_binds(void);
int GPU_max_ubo_size(void);
bool GPU_arb_texture_cube_map_array_is_supported(void);
bool GPU_mip_render_workaround(void);
bool GPU_depth_blitting_workaround(void);
bool GPU_use_main_context_workaround(void);

View File

@ -81,12 +81,6 @@ int GPU_max_textures(void)
return GCaps.max_textures;
}
bool GPU_arb_texture_cube_map_array_is_supported(void)
{
/* FIXME bad level call. */
return GLContext::texture_cube_map_array_support;
}
bool GPU_mip_render_workaround(void)
{
return GCaps.mip_render_workaround;

View File

@ -113,7 +113,7 @@ char *GLShader::glsl_patch_get(void)
STR_CONCAT(patch, slen, "#extension GL_ARB_shader_draw_parameters : enable\n");
STR_CONCAT(patch, slen, "#define GPU_ARB_shader_draw_parameters\n");
}
if (GPU_arb_texture_cube_map_array_is_supported()) {
if (GLContext::texture_cube_map_array_support) {
STR_CONCAT(patch, slen, "#extension GL_ARB_texture_cube_map_array : enable\n");
STR_CONCAT(patch, slen, "#define GPU_ARB_texture_cube_map_array\n");
}

View File

@ -71,8 +71,9 @@ bool GLTexture::init_internal(void)
format_ = GPU_DEPTH32F_STENCIL8;
}
if ((type_ == GPU_TEXTURE_CUBE_ARRAY) && !GPU_arb_texture_cube_map_array_is_supported()) {
debug::raise_gl_error("Attempt to create a cubemap array without hardware support!");
if ((type_ == GPU_TEXTURE_CUBE_ARRAY) && (GLContext::texture_cube_map_array_support == false)) {
/* Silently fail and let the caller handle the error. */
// debug::raise_gl_error("Attempt to create a cubemap array without hardware support!");
return false;
}