summaryrefslogtreecommitdiff
path: root/drivers/gles2/rasterizer_scene_gles2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gles2/rasterizer_scene_gles2.cpp')
-rw-r--r--drivers/gles2/rasterizer_scene_gles2.cpp41
1 files changed, 31 insertions, 10 deletions
diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp
index 2c52895bda..ac1aae62bd 100644
--- a/drivers/gles2/rasterizer_scene_gles2.cpp
+++ b/drivers/gles2/rasterizer_scene_gles2.cpp
@@ -1178,6 +1178,11 @@ bool RasterizerSceneGLES2::_setup_material(RasterizerStorageGLES2::Material *p_m
state.scene_shader.set_custom_shader(p_material->shader->custom_code_id);
+ if (p_material->shader->spatial.uses_screen_texture && storage->frame.current_rt) {
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 4);
+ glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->copy_screen_effect.color);
+ }
+
bool shader_rebind = state.scene_shader.bind();
if (p_material->shader->spatial.no_depth_test) {
@@ -1200,9 +1205,6 @@ bool RasterizerSceneGLES2::_setup_material(RasterizerStorageGLES2::Material *p_m
} break;
}
- // TODO whyyyyy????
- p_reverse_cull = true;
-
switch (p_material->shader->spatial.cull_mode) {
case RasterizerStorageGLES2::Shader::Spatial::CULL_MODE_DISABLED: {
glDisable(GL_CULL_FACE);
@@ -1564,6 +1566,8 @@ void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) {
} else {
glVertexAttrib4fv(INSTANCE_ATTRIB_BASE + 3, buffer + color_ofs);
}
+ } else {
+ glVertexAttrib4f(INSTANCE_ATTRIB_BASE + 3, 1.0, 1.0, 1.0, 1.0);
}
if (multi_mesh->custom_data_floats) {
@@ -2337,7 +2341,7 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
Transform sky_orientation(p_env->sky_orientation, Vector3(0.0, 0.0, 0.0));
state.scene_shader.set_uniform(SceneShaderGLES2::RADIANCE_INVERSE_XFORM, sky_orientation.affine_inverse() * p_view_transform);
} else {
- // would be a bit weird if we dont have this...
+ // would be a bit weird if we don't have this...
state.scene_shader.set_uniform(SceneShaderGLES2::RADIANCE_INVERSE_XFORM, p_view_transform);
}
}
@@ -2555,11 +2559,19 @@ void RasterizerSceneGLES2::_draw_sky(RasterizerStorageGLES2::Sky *p_sky, const C
void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) {
+ Transform cam_transform = p_cam_transform;
+
GLuint current_fb = 0;
Environment *env = NULL;
int viewport_width, viewport_height;
bool probe_interior = false;
+ bool reverse_cull = false;
+
+ if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP]) {
+ cam_transform.basis.set_axis(1, -cam_transform.basis.get_axis(1));
+ reverse_cull = true;
+ }
if (p_reflection_probe.is_valid()) {
ReflectionProbeInstance *probe = reflection_probe_instance_owner.getornull(p_reflection_probe);
@@ -2586,6 +2598,7 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const
viewport_height = storage->frame.current_rt->height;
}
+ state.used_screen_texture = false;
state.viewport_size.x = viewport_width;
state.viewport_size.y = viewport_height;
state.screen_pixel_size.x = 1.0 / viewport_width;
@@ -2594,7 +2607,7 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const
//push back the directional lights
if (p_light_cull_count) {
- //harcoded limit of 256 lights
+ //hardcoded limit of 256 lights
render_light_instance_count = MIN(RenderList::MAX_LIGHTS, p_light_cull_count);
render_light_instances = (LightInstance **)alloca(sizeof(LightInstance *) * render_light_instance_count);
render_directional_lights = 0;
@@ -2608,7 +2621,7 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const
if (light->light_ptr->type == VS::LIGHT_DIRECTIONAL) {
render_directional_lights++;
- //as goin in reverse, directional lights are always first anyway
+ //as going in reverse, directional lights are always first anyway
}
light->light_index = index;
@@ -2709,7 +2722,7 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const
if (env && env->bg_mode == VS::ENV_BG_SKY && (!storage->frame.current_rt || !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT])) {
if (sky && sky->panorama.is_valid()) {
- _draw_sky(sky, p_cam_projection, p_cam_transform, false, env->sky_custom_fov, env->bg_energy, env->sky_orientation);
+ _draw_sky(sky, p_cam_projection, cam_transform, false, env->sky_custom_fov, env->bg_energy, env->sky_orientation);
}
}
@@ -2719,8 +2732,12 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const
// render opaque things first
render_list.sort_by_key(false);
- _render_render_list(render_list.elements, render_list.element_count, p_cam_transform, p_cam_projection, p_shadow_atlas, env, env_radiance_tex, 0.0, 0.0, false, false, false);
+ _render_render_list(render_list.elements, render_list.element_count, cam_transform, p_cam_projection, p_shadow_atlas, env, env_radiance_tex, 0.0, 0.0, reverse_cull, false, false);
+ if (storage->frame.current_rt && state.used_screen_texture) {
+ //copy screen texture
+ storage->canvas->_copy_screen(Rect2());
+ }
// alpha pass
glBlendEquation(GL_FUNC_ADD);
@@ -2728,7 +2745,7 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const
render_list.sort_by_depth(true);
- _render_render_list(&render_list.elements[render_list.max_elements - render_list.alpha_element_count], render_list.alpha_element_count, p_cam_transform, p_cam_projection, p_shadow_atlas, env, env_radiance_tex, 0.0, 0.0, false, true, false);
+ _render_render_list(&render_list.elements[render_list.max_elements - render_list.alpha_element_count], render_list.alpha_element_count, cam_transform, p_cam_projection, p_shadow_atlas, env, env_radiance_tex, 0.0, 0.0, reverse_cull, true, false);
glDisable(GL_DEPTH_TEST);
@@ -3041,7 +3058,9 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_
}
}
- glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height);
+ if (storage->frame.current_rt) {
+ glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height);
+ }
glColorMask(1, 1, 1, 1);
}
@@ -3224,6 +3243,8 @@ void RasterizerSceneGLES2::initialize() {
}
shadow_filter_mode = SHADOW_FILTER_NEAREST;
+
+ glFrontFace(GL_CW);
}
void RasterizerSceneGLES2::iteration() {