diff options
Diffstat (limited to 'drivers/gles2/rasterizer_scene_gles2.cpp')
-rw-r--r-- | drivers/gles2/rasterizer_scene_gles2.cpp | 83 |
1 files changed, 29 insertions, 54 deletions
diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp index f712219a64..c0ba93db6a 100644 --- a/drivers/gles2/rasterizer_scene_gles2.cpp +++ b/drivers/gles2/rasterizer_scene_gles2.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -557,15 +557,16 @@ bool RasterizerSceneGLES2::reflection_probe_instance_begin_render(RID p_instance glGenTextures(1, &rpi->cubemap); glBindTexture(GL_TEXTURE_CUBE_MAP, rpi->cubemap); -#if 1 - //Mobile hardware (PowerVR specially) prefers this approach, the other one kills the game + + // Mobile hardware (PowerVR specially) prefers this approach, + // the previous approach with manual lod levels kills the game. for (int i = 0; i < 6; i++) { glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internal_format, size, size, 0, format, type, NULL); } glGenerateMipmap(GL_TEXTURE_CUBE_MAP); - //Generate framebuffers for rendering + // Generate framebuffers for rendering for (int i = 0; i < 6; i++) { glBindFramebuffer(GL_FRAMEBUFFER, rpi->fbo[i]); glBindTexture(GL_TEXTURE_2D, rpi->color[i]); @@ -576,34 +577,6 @@ bool RasterizerSceneGLES2::reflection_probe_instance_begin_render(RID p_instance ERR_CONTINUE(status != GL_FRAMEBUFFER_COMPLETE); } -#else - int lod = 0; - - //the approach below is fatal for powervr - - // Set the initial (empty) mipmaps, all need to be set for this to work in GLES2, even if they won't be used later. - while (size >= 1) { - - for (int i = 0; i < 6; i++) { - glTexImage2D(_cube_side_enum[i], lod, internal_format, size, size, 0, format, type, NULL); - if (size == rpi->current_resolution) { - //adjust framebuffer - glBindFramebuffer(GL_FRAMEBUFFER, rpi->fbo[i]); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, _cube_side_enum[i], rpi->cubemap, 0); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rpi->depth); - -#ifdef DEBUG_ENABLED - GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - ERR_CONTINUE(status != GL_FRAMEBUFFER_COMPLETE); -#endif - } - } - - lod++; - - size >>= 1; - } -#endif glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -1169,7 +1142,7 @@ void RasterizerSceneGLES2::_add_geometry_with_material(RasterizerStorageGLES2::G LightInstance *li = light_instance_owner.getornull(e->instance->light_instances[i]); - if (li->light_index >= render_light_instance_count || render_light_instances[li->light_index] != li) { + if (!li || li->light_index >= render_light_instance_count || render_light_instances[li->light_index] != li) { continue; // too many or light_index did not correspond to the light instances to be rendered } @@ -1869,7 +1842,6 @@ void RasterizerSceneGLES2::_setup_light_type(LightInstance *p_light, ShadowAtlas state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM2, false); state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM4, false); state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM_BLEND, false); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_SHADOW, false); if (!p_light) { //no light, return off return; @@ -1955,8 +1927,7 @@ void RasterizerSceneGLES2::_setup_light(LightInstance *light, ShadowAtlas *shado Color color = light_ptr->color * sign * energy * Math_PI; state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_COLOR, color); - Color shadow_color = light_ptr->shadow_color.to_linear(); - state.scene_shader.set_uniform(SceneShaderGLES2::SHADOW_COLOR, shadow_color); + state.scene_shader.set_uniform(SceneShaderGLES2::SHADOW_COLOR, light_ptr->shadow_color); //specific parameters @@ -2342,9 +2313,7 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements, if (accum_pass) { //accum pass force pass blend_mode = RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_ADD; - if (rebind_light && light && light->light_ptr->negative) { - glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); + if (light && light->light_ptr->negative) { blend_mode = RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_SUB; } } @@ -2689,14 +2658,14 @@ void RasterizerSceneGLES2::_draw_sky(RasterizerStorageGLES2::Sky *p_sky, const C }; if (!asymmetrical) { - float vw, vh, zn; - camera.get_viewport_size(vw, vh); + Vector2 vp_he = camera.get_viewport_half_extents(); + float zn; zn = p_projection.get_z_near(); for (int i = 0; i < 4; i++) { Vector3 uv = vertices[i * 2 + 1]; - uv.x = (uv.x * 2.0 - 1.0) * vw; - uv.y = -(uv.y * 2.0 - 1.0) * vh; + uv.x = (uv.x * 2.0 - 1.0) * vp_he.x; + uv.y = -(uv.y * 2.0 - 1.0) * vp_he.y; uv.z = -zn; vertices[i * 2 + 1] = p_transform.basis.xform(uv).normalized(); vertices[i * 2 + 1].z = -vertices[i * 2 + 1].z; @@ -2704,7 +2673,7 @@ void RasterizerSceneGLES2::_draw_sky(RasterizerStorageGLES2::Sky *p_sky, const C } glBindBuffer(GL_ARRAY_BUFFER, state.sky_verts); - glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vector3) * 8, vertices); + glBufferData(GL_ARRAY_BUFFER, sizeof(Vector3) * 8, vertices, GL_DYNAMIC_DRAW); // bind sky vertex array.... glVertexAttribPointer(VS::ARRAY_VERTEX, 3, GL_FLOAT, GL_FALSE, sizeof(Vector3) * 2, 0); @@ -2767,6 +2736,8 @@ void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p if (use_post_process) { next_buffer = storage->frame.current_rt->mip_maps[0].sizes[0].fbo; + } else if (storage->frame.current_rt->external.fbo != 0) { + next_buffer = storage->frame.current_rt->external.fbo; } else { // set next_buffer to front buffer so multisample blit can happen if needed next_buffer = storage->frame.current_rt->fbo; @@ -2795,9 +2766,15 @@ void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p // In GLES2 Android Blit is not available, so just copy color texture manually _copy_texture_to_buffer(storage->frame.current_rt->multisample_color, next_buffer); +#else + // TODO: any other platform not supported? this will fail.. maybe we should just call _copy_texture_to_buffer here as well? #endif } else if (use_post_process) { - _copy_texture_to_buffer(storage->frame.current_rt->color, storage->frame.current_rt->mip_maps[0].sizes[0].fbo); + if (storage->frame.current_rt->external.fbo != 0) { + _copy_texture_to_buffer(storage->frame.current_rt->external.color, storage->frame.current_rt->mip_maps[0].sizes[0].fbo); + } else { + _copy_texture_to_buffer(storage->frame.current_rt->color, storage->frame.current_rt->mip_maps[0].sizes[0].fbo); + } } if (!use_post_process) { @@ -3220,14 +3197,12 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const } else { state.render_no_shadows = false; - if (storage->frame.current_rt->external.fbo != 0) { + if (storage->frame.current_rt->multisample_active) { + current_fb = storage->frame.current_rt->multisample_fbo; + } else if (storage->frame.current_rt->external.fbo != 0) { current_fb = storage->frame.current_rt->external.fbo; } else { - if (storage->frame.current_rt->multisample_active) { - current_fb = storage->frame.current_rt->multisample_fbo; - } else { - current_fb = storage->frame.current_rt->fbo; - } + current_fb = storage->frame.current_rt->fbo; } env = environment_owner.getornull(p_environment); @@ -3323,6 +3298,7 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const glDepthMask(GL_TRUE); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); + glClear(GL_DEPTH_BUFFER_BIT); // clear color @@ -3349,13 +3325,12 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const if (!env || env->bg_mode != VS::ENV_BG_KEEP) { glClearColor(clear_color.r, clear_color.g, clear_color.b, clear_color.a); + glClear(GL_COLOR_BUFFER_BIT); } state.default_ambient = Color(clear_color.r, clear_color.g, clear_color.b, 1.0); state.default_bg = Color(clear_color.r, clear_color.g, clear_color.b, 1.0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_DIRECT_TO_SCREEN]) { glDisable(GL_SCISSOR_TEST); } |