Strive for maximum compatibility in GLES2 regarding depth buffers.

This commit is contained in:
Juan Linietsky 2019-03-01 11:20:44 -03:00
parent 2363c38d87
commit 8799f69b2c
4 changed files with 156 additions and 66 deletions

View file

@ -83,7 +83,11 @@ void RasterizerSceneGLES2::shadow_atlas_set_size(RID p_atlas, int p_size) {
// erase the old atlast // erase the old atlast
if (shadow_atlas->fbo) { if (shadow_atlas->fbo) {
if (storage->config.use_rgba_3d_shadows) {
glDeleteRenderbuffers(1, &shadow_atlas->depth);
} else {
glDeleteTextures(1, &shadow_atlas->depth); glDeleteTextures(1, &shadow_atlas->depth);
}
glDeleteFramebuffers(1, &shadow_atlas->fbo); glDeleteFramebuffers(1, &shadow_atlas->fbo);
if (shadow_atlas->color) { if (shadow_atlas->color) {
glDeleteTextures(1, &shadow_atlas->color); glDeleteTextures(1, &shadow_atlas->color);
@ -111,6 +115,25 @@ void RasterizerSceneGLES2::shadow_atlas_set_size(RID p_atlas, int p_size) {
// create a depth texture // create a depth texture
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
if (storage->config.use_rgba_3d_shadows) {
//maximum compatibility, renderbuffer and RGBA shadow
glGenRenderbuffers(1, &shadow_atlas->depth);
glBindRenderbuffer(GL_RENDERBUFFER, directional_shadow.depth);
glRenderbufferStorage(GL_RENDERBUFFER, storage->config.depth_internalformat, shadow_atlas->size, shadow_atlas->size);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, shadow_atlas->depth);
glGenTextures(1, &shadow_atlas->color);
glBindTexture(GL_TEXTURE_2D, shadow_atlas->color);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, shadow_atlas->size, shadow_atlas->size, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, shadow_atlas->color, 0);
} else {
//just depth texture
glGenTextures(1, &shadow_atlas->depth); glGenTextures(1, &shadow_atlas->depth);
glBindTexture(GL_TEXTURE_2D, shadow_atlas->depth); glBindTexture(GL_TEXTURE_2D, shadow_atlas->depth);
glTexImage2D(GL_TEXTURE_2D, 0, storage->config.depth_internalformat, shadow_atlas->size, shadow_atlas->size, 0, GL_DEPTH_COMPONENT, storage->config.depth_type, NULL); glTexImage2D(GL_TEXTURE_2D, 0, storage->config.depth_internalformat, shadow_atlas->size, shadow_atlas->size, 0, GL_DEPTH_COMPONENT, storage->config.depth_type, NULL);
@ -121,16 +144,6 @@ void RasterizerSceneGLES2::shadow_atlas_set_size(RID p_atlas, int p_size) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadow_atlas->depth, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadow_atlas->depth, 0);
if (storage->config.use_rgba_3d_shadows) {
glGenTextures(1, &shadow_atlas->color);
glBindTexture(GL_TEXTURE_2D, shadow_atlas->color);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, shadow_atlas->size, shadow_atlas->size, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, shadow_atlas->color, 0);
} }
glViewport(0, 0, shadow_atlas->size, shadow_atlas->size); glViewport(0, 0, shadow_atlas->size, shadow_atlas->size);
@ -475,7 +488,8 @@ RID RasterizerSceneGLES2::reflection_probe_instance_create(RID p_probe) {
glGenTextures(1, &rpi->color[i]); glGenTextures(1, &rpi->color[i]);
} }
glGenTextures(1, &rpi->depth); glGenRenderbuffers(1, &rpi->depth);
rpi->cubemap = 0; rpi->cubemap = 0;
//glGenTextures(1, &rpi->cubemap); //glGenTextures(1, &rpi->cubemap);
@ -524,8 +538,8 @@ bool RasterizerSceneGLES2::reflection_probe_instance_begin_render(RID p_instance
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, rpi->depth); glBindRenderbuffer(GL_RENDERBUFFER, rpi->depth);
glTexImage2D(GL_TEXTURE_2D, 0, storage->config.depth_internalformat, size, size, 0, GL_DEPTH_COMPONENT, storage->config.depth_type, NULL); glRenderbufferStorage(GL_RENDERBUFFER, storage->config.depth_internalformat, size, size);
if (rpi->cubemap != 0) { if (rpi->cubemap != 0) {
glDeleteTextures(1, &rpi->cubemap); glDeleteTextures(1, &rpi->cubemap);
@ -547,7 +561,7 @@ bool RasterizerSceneGLES2::reflection_probe_instance_begin_render(RID p_instance
glBindTexture(GL_TEXTURE_2D, rpi->color[i]); glBindTexture(GL_TEXTURE_2D, rpi->color[i]);
glTexImage2D(GL_TEXTURE_2D, 0, internal_format, size, size, 0, format, type, NULL); glTexImage2D(GL_TEXTURE_2D, 0, internal_format, size, size, 0, format, type, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rpi->color[i], 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rpi->color[i], 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, rpi->depth, 0); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rpi->depth);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
ERR_CONTINUE(status != GL_FRAMEBUFFER_COMPLETE); ERR_CONTINUE(status != GL_FRAMEBUFFER_COMPLETE);
} }
@ -566,8 +580,6 @@ bool RasterizerSceneGLES2::reflection_probe_instance_begin_render(RID p_instance
//adjust framebuffer //adjust framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, rpi->fbo[i]); glBindFramebuffer(GL_FRAMEBUFFER, rpi->fbo[i]);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, _cube_side_enum[i], rpi->cubemap, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, _cube_side_enum[i], rpi->cubemap, 0);
glBindRenderbuffer(GL_RENDERBUFFER, rpi->depth);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, size, size); // Note: used to be _DEPTH_COMPONENT24_OES. GL_DEPTH_COMPONENT untested.
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rpi->depth); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rpi->depth);
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
@ -2977,7 +2989,7 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_
if (light->type == VS::LIGHT_OMNI) { if (light->type == VS::LIGHT_OMNI) {
// cubemap only // cubemap only
if (light->omni_shadow_mode == VS::LIGHT_OMNI_SHADOW_CUBE && storage->config.support_write_depth) { if (light->omni_shadow_mode == VS::LIGHT_OMNI_SHADOW_CUBE && storage->config.support_shadow_cubemaps) {
int cubemap_index = shadow_cubemaps.size() - 1; int cubemap_index = shadow_cubemaps.size() - 1;
// find an appropriate cubemap to render to // find an appropriate cubemap to render to
@ -3075,7 +3087,7 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_
state.scene_shader.set_conditional(SceneShaderGLES2::RENDER_DEPTH_DUAL_PARABOLOID, false); state.scene_shader.set_conditional(SceneShaderGLES2::RENDER_DEPTH_DUAL_PARABOLOID, false);
// convert cubemap to dual paraboloid if needed // convert cubemap to dual paraboloid if needed
if (light->type == VS::LIGHT_OMNI && (light->omni_shadow_mode == VS::LIGHT_OMNI_SHADOW_CUBE && storage->config.support_write_depth) && p_pass == 5) { if (light->type == VS::LIGHT_OMNI && (light->omni_shadow_mode == VS::LIGHT_OMNI_SHADOW_CUBE && storage->config.support_shadow_cubemaps) && p_pass == 5) {
ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_shadow_atlas); ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_shadow_atlas);
glBindFramebuffer(GL_FRAMEBUFFER, shadow_atlas->fbo); glBindFramebuffer(GL_FRAMEBUFFER, shadow_atlas->fbo);
@ -3172,7 +3184,7 @@ bool RasterizerSceneGLES2::free(RID p_rid) {
if (reflection_instance->cubemap != 0) { if (reflection_instance->cubemap != 0) {
glDeleteTextures(1, &reflection_instance->cubemap); glDeleteTextures(1, &reflection_instance->cubemap);
} }
glDeleteTextures(1, &reflection_instance->depth); glDeleteRenderbuffers(1, &reflection_instance->depth);
reflection_probe_release_atlas_index(p_rid); reflection_probe_release_atlas_index(p_rid);
reflection_probe_instance_owner.free(p_rid); reflection_probe_instance_owner.free(p_rid);
@ -3253,7 +3265,7 @@ void RasterizerSceneGLES2::initialize() {
} }
// cubemaps for shadows // cubemaps for shadows
if (storage->config.support_write_depth) { //not going to be used if (storage->config.support_shadow_cubemaps) { //not going to be used
int max_shadow_cubemap_sampler_size = 512; int max_shadow_cubemap_sampler_size = 512;
int cube_size = max_shadow_cubemap_sampler_size; int cube_size = max_shadow_cubemap_sampler_size;
@ -3302,6 +3314,23 @@ void RasterizerSceneGLES2::initialize() {
glGenFramebuffers(1, &directional_shadow.fbo); glGenFramebuffers(1, &directional_shadow.fbo);
glBindFramebuffer(GL_FRAMEBUFFER, directional_shadow.fbo); glBindFramebuffer(GL_FRAMEBUFFER, directional_shadow.fbo);
if (storage->config.use_rgba_3d_shadows) {
//maximum compatibility, renderbuffer and RGBA shadow
glGenRenderbuffers(1, &directional_shadow.depth);
glBindRenderbuffer(GL_RENDERBUFFER, directional_shadow.depth);
glRenderbufferStorage(GL_RENDERBUFFER, storage->config.depth_internalformat, directional_shadow.size, directional_shadow.size);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, directional_shadow.depth);
glGenTextures(1, &directional_shadow.color);
glBindTexture(GL_TEXTURE_2D, directional_shadow.color);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, directional_shadow.size, directional_shadow.size, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, directional_shadow.color, 0);
} else {
//just a depth buffer
glGenTextures(1, &directional_shadow.depth); glGenTextures(1, &directional_shadow.depth);
glBindTexture(GL_TEXTURE_2D, directional_shadow.depth); glBindTexture(GL_TEXTURE_2D, directional_shadow.depth);
@ -3313,16 +3342,6 @@ void RasterizerSceneGLES2::initialize() {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, directional_shadow.depth, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, directional_shadow.depth, 0);
if (storage->config.use_rgba_3d_shadows) {
glGenTextures(1, &directional_shadow.color);
glBindTexture(GL_TEXTURE_2D, directional_shadow.color);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, directional_shadow.size, directional_shadow.size, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, directional_shadow.color, 0);
} }
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);

View file

@ -475,7 +475,7 @@ public:
virtual void light_instance_set_transform(RID p_light_instance, const Transform &p_transform); virtual void light_instance_set_transform(RID p_light_instance, const Transform &p_transform);
virtual void light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass, float p_bias_scale = 1.0); virtual void light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass, float p_bias_scale = 1.0);
virtual void light_instance_mark_visible(RID p_light_instance); virtual void light_instance_mark_visible(RID p_light_instance);
virtual bool light_instances_can_render_shadow_cube() const { return storage->config.support_write_depth; } virtual bool light_instances_can_render_shadow_cube() const { return storage->config.support_shadow_cubemaps; }
LightInstance **render_light_instances; LightInstance **render_light_instances;
int render_directional_lights; int render_directional_lights;

View file

@ -1308,7 +1308,19 @@ void RasterizerStorageGLES2::_update_shader(Shader *p_shader) const {
actions->uniforms = &p_shader->uniforms; actions->uniforms = &p_shader->uniforms;
if (p_shader->spatial.uses_screen_texture && p_shader->spatial.uses_depth_texture) { if (p_shader->spatial.uses_screen_texture && p_shader->spatial.uses_depth_texture) {
WARN_PRINT("Using both SCREEN_TEXTURE and DEPTH_TEXTURE is not supported in GLES2"); static bool show_warning = true; //show warning only once
if (show_warning) {
ERR_PRINT("Using both SCREEN_TEXTURE and DEPTH_TEXTURE is not supported in GLES2");
show_warning = false;
}
}
if (p_shader->spatial.uses_depth_texture && !config.support_depth_texture) {
static bool show_warning = true; //show warning only once
if (show_warning) {
ERR_PRINT("Using DEPTH_TEXTURE is not permitted on this hardware, operation will fail.");
show_warning = false;
}
} }
} break; } break;
@ -4306,9 +4318,9 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) {
// depth // depth
if (config.support_depth_texture) {
glGenTextures(1, &rt->depth); glGenTextures(1, &rt->depth);
glBindTexture(GL_TEXTURE_2D, rt->depth); glBindTexture(GL_TEXTURE_2D, rt->depth);
glTexImage2D(GL_TEXTURE_2D, 0, config.depth_internalformat, rt->width, rt->height, 0, GL_DEPTH_COMPONENT, config.depth_type, NULL); glTexImage2D(GL_TEXTURE_2D, 0, config.depth_internalformat, rt->width, rt->height, 0, GL_DEPTH_COMPONENT, config.depth_type, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@ -4317,13 +4329,25 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, rt->depth, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, rt->depth, 0);
} else {
glGenRenderbuffers(1, &rt->depth);
glBindRenderbuffer(GL_RENDERBUFFER, rt->depth);
glRenderbufferStorage(GL_RENDERBUFFER, config.depth_internalformat, rt->width, rt->height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->depth);
}
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) { if (status != GL_FRAMEBUFFER_COMPLETE) {
glDeleteFramebuffers(1, &rt->fbo); glDeleteFramebuffers(1, &rt->fbo);
if (config.support_depth_texture) {
glDeleteTextures(1, &rt->depth); glDeleteTextures(1, &rt->depth);
} else {
glDeleteRenderbuffers(1, &rt->depth);
}
glDeleteTextures(1, &rt->color); glDeleteTextures(1, &rt->color);
rt->fbo = 0; rt->fbo = 0;
rt->width = 0; rt->width = 0;
@ -4395,7 +4419,12 @@ void RasterizerStorageGLES2::_render_target_clear(RenderTarget *rt) {
} }
if (rt->depth) { if (rt->depth) {
if (config.support_depth_texture) {
glDeleteTextures(1, &rt->depth); glDeleteTextures(1, &rt->depth);
} else {
glDeleteRenderbuffers(1, &rt->depth);
}
rt->depth = 0; rt->depth = 0;
} }
@ -4533,17 +4562,10 @@ RID RasterizerStorageGLES2::canvas_light_shadow_buffer_create(int p_width) {
glGenFramebuffers(1, &cls->fbo); glGenFramebuffers(1, &cls->fbo);
glBindFramebuffer(GL_FRAMEBUFFER, cls->fbo); glBindFramebuffer(GL_FRAMEBUFFER, cls->fbo);
glGenTextures(1, &cls->depth); glGenRenderbuffers(1, &cls->depth);
glBindTexture(GL_TEXTURE_2D, cls->depth); glBindRenderbuffer(GL_RENDERBUFFER, cls->depth);
glRenderbufferStorage(GL_RENDERBUFFER, config.depth_internalformat, cls->size, cls->height);
glTexImage2D(GL_TEXTURE_2D, 0, config.depth_internalformat, cls->size, cls->height, 0, GL_DEPTH_COMPONENT, config.depth_type, NULL); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, cls->depth);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, cls->depth, 0);
glGenTextures(1, &cls->distance); glGenTextures(1, &cls->distance);
glBindTexture(GL_TEXTURE_2D, cls->distance); glBindTexture(GL_TEXTURE_2D, cls->distance);
@ -4908,7 +4930,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) {
CanvasLightShadow *cls = canvas_light_shadow_owner.get(p_rid); CanvasLightShadow *cls = canvas_light_shadow_owner.get(p_rid);
glDeleteFramebuffers(1, &cls->fbo); glDeleteFramebuffers(1, &cls->fbo);
glDeleteTextures(1, &cls->depth); glDeleteRenderbuffers(1, &cls->depth);
glDeleteTextures(1, &cls->distance); glDeleteTextures(1, &cls->distance);
canvas_light_shadow_owner.free(p_rid); canvas_light_shadow_owner.free(p_rid);
memdelete(cls); memdelete(cls);
@ -4986,21 +5008,17 @@ void RasterizerStorageGLES2::initialize() {
config.pvrtc_supported = config.extensions.has("IMG_texture_compression_pvrtc"); config.pvrtc_supported = config.extensions.has("IMG_texture_compression_pvrtc");
config.support_npot_repeat_mipmap = config.extensions.has("GL_OES_texture_npot"); config.support_npot_repeat_mipmap = config.extensions.has("GL_OES_texture_npot");
if (config.extensions.has("GL_OES_depth24")) {
config.depth_internalformat = _DEPTH_COMPONENT24_OES;
config.depth_type = GL_UNSIGNED_INT;
} else {
config.depth_internalformat = GL_DEPTH_COMPONENT16;
config.depth_type = GL_UNSIGNED_SHORT;
}
#endif #endif
#ifdef GLES_OVER_GL #ifdef GLES_OVER_GL
config.use_rgba_2d_shadows = false; config.use_rgba_2d_shadows = false;
config.support_depth_texture = true;
config.use_rgba_3d_shadows = false; config.use_rgba_3d_shadows = false;
config.support_depth_cubemaps = true;
#else #else
config.use_rgba_2d_shadows = !(config.float_texture_supported && config.extensions.has("GL_EXT_texture_rg")); config.use_rgba_2d_shadows = !(config.float_texture_supported && config.extensions.has("GL_EXT_texture_rg"));
config.use_rgba_3d_shadows = config.extensions.has("GL_OES_depth_texture"); config.support_depth_texture = config.extensions.has("GL_OES_depth_texture");
config.use_rgba_3d_shadows = !config.support_depth_texture;
config.support_depth_cubemaps = config.extensions.has("GL_OES_depth_texture_cube_map");
#endif #endif
#ifdef GLES_OVER_GL #ifdef GLES_OVER_GL
@ -5024,6 +5042,55 @@ void RasterizerStorageGLES2::initialize() {
config.support_half_float_vertices = true; config.support_half_float_vertices = true;
#endif #endif
//determine formats for depth textures (or renderbuffers)
if (config.support_depth_texture) {
// Will use texture for depth
// have to manually see if we can create a valid framebuffer texture using UNSIGNED_INT,
// as there is no extension to test for this.
GLuint fbo;
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
GLuint depth;
glGenTextures(1, &depth);
glBindTexture(GL_TEXTURE_2D, depth);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 32, 32, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth, 0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status == GL_FRAMEBUFFER_COMPLETE) {
config.depth_internalformat = GL_DEPTH_COMPONENT;
config.depth_type = GL_UNSIGNED_INT;
} else {
config.depth_internalformat = GL_DEPTH_COMPONENT16;
config.depth_type = GL_UNSIGNED_SHORT;
}
glBindFramebuffer(GL_FRAMEBUFFER, system_fbo);
glDeleteFramebuffers(1, &fbo);
glBindTexture(GL_TEXTURE_2D, 0);
glDeleteTextures(1, &depth);
} else {
// Will use renderbuffer for depth
if (config.extensions.has("GL_OES_depth24")) {
config.depth_internalformat = _DEPTH_COMPONENT24_OES;
config.depth_type = GL_UNSIGNED_INT;
} else {
config.depth_internalformat = GL_DEPTH_COMPONENT16;
config.depth_type = GL_UNSIGNED_SHORT;
}
}
//picky requirements for these
config.support_shadow_cubemaps = config.support_depth_texture && config.support_write_depth && config.support_depth_cubemaps;
frame.count = 0; frame.count = 0;
frame.delta = 0; frame.delta = 0;
frame.current_rt = NULL; frame.current_rt = NULL;

View file

@ -85,6 +85,10 @@ public:
bool support_write_depth; bool support_write_depth;
bool support_half_float_vertices; bool support_half_float_vertices;
bool support_npot_repeat_mipmap; bool support_npot_repeat_mipmap;
bool support_depth_texture;
bool support_depth_cubemaps;
bool support_shadow_cubemaps;
GLuint depth_internalformat; GLuint depth_internalformat;
GLuint depth_type; GLuint depth_type;