diff options
98 files changed, 4354 insertions, 12442 deletions
diff --git a/SConstruct b/SConstruct index 72012ada99..cd4657b20c 100644 --- a/SConstruct +++ b/SConstruct @@ -15,7 +15,7 @@ from collections import OrderedDict # Local import methods import glsl_builders -import gles_builders +import opengl_builders from platform_methods import run_in_subprocess # Scan possible build platforms @@ -708,20 +708,11 @@ if selected_platform in platform_list: } env.Append(BUILDERS=GLSL_BUILDERS) - if not env["platform"] == "server": # FIXME: detect GLES3 + if not env["platform"] == "server": env.Append( BUILDERS={ - "GLES3_GLSL": env.Builder( - action=run_in_subprocess(gles_builders.build_gles3_headers), - suffix="glsl.gen.h", - src_suffix=".glsl", - ) - } - ) - env.Append( - BUILDERS={ - "GLES2_GLSL": env.Builder( - action=run_in_subprocess(gles_builders.build_gles2_headers), + "OpenGL_GLSL": env.Builder( + action=run_in_subprocess(opengl_builders.build_opengl_headers), suffix="glsl.gen.h", src_suffix=".glsl", ) diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 3a4fddc670..31e9237d56 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -603,8 +603,8 @@ void OS::_bind_methods() { ADD_PROPERTY_DEFAULT("low_processor_usage_mode", false); ADD_PROPERTY_DEFAULT("low_processor_usage_mode_sleep_usec", 6900); - BIND_ENUM_CONSTANT(VIDEO_DRIVER_GLES2); BIND_ENUM_CONSTANT(VIDEO_DRIVER_VULKAN); + BIND_ENUM_CONSTANT(VIDEO_DRIVER_OPENGL); BIND_ENUM_CONSTANT(DAY_SUNDAY); BIND_ENUM_CONSTANT(DAY_MONDAY); diff --git a/core/core_bind.h b/core/core_bind.h index 3eb4c914a1..afbee4efaa 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -119,8 +119,8 @@ protected: public: enum VideoDriver { - VIDEO_DRIVER_GLES2, VIDEO_DRIVER_VULKAN, + VIDEO_DRIVER_OPENGL, }; enum Weekday { diff --git a/doc/classes/Environment.xml b/doc/classes/Environment.xml index 57f6e9547a..88c4689b5f 100644 --- a/doc/classes/Environment.xml +++ b/doc/classes/Environment.xml @@ -128,10 +128,10 @@ The bleed scale of the HDR glow. </member> <member name="glow_hdr_threshold" type="float" setter="set_glow_hdr_bleed_threshold" getter="get_glow_hdr_bleed_threshold" default="1.0"> - The lower threshold of the HDR glow. When using the GLES2 renderer (which doesn't support HDR), this needs to be below [code]1.0[/code] for glow to be visible. A value of [code]0.9[/code] works well in this case. + The lower threshold of the HDR glow. When using the OpenGL renderer (which doesn't support HDR), this needs to be below [code]1.0[/code] for glow to be visible. A value of [code]0.9[/code] works well in this case. </member> <member name="glow_intensity" type="float" setter="set_glow_intensity" getter="get_glow_intensity" default="0.8"> - The overall brightness multiplier of the glow effect. When using the GLES2 renderer, this should be increased to 1.5 to compensate for the lack of HDR rendering. + The overall brightness multiplier of the glow effect. When using the OpenGL renderer, this should be increased to 1.5 to compensate for the lack of HDR rendering. </member> <member name="glow_levels/1" type="float" setter="set_glow_level" getter="get_glow_level" default="0.0"> The intensity of the 1st level of glow. This is the most "local" level (least blurry). @@ -160,7 +160,7 @@ If [code]true[/code], glow levels will be normalized so that summed together their intensities equal [code]1.0[/code]. </member> <member name="glow_strength" type="float" setter="set_glow_strength" getter="get_glow_strength" default="1.0"> - The strength of the glow effect. This applies as the glow is blurred across the screen and increases the distance and intensity of the blur. When using the GLES2 renderer, this should be increased to 1.3 to compensate for the lack of HDR rendering. + The strength of the glow effect. This applies as the glow is blurred across the screen and increases the distance and intensity of the blur. When using the OpenGL renderer, this should be increased to 1.3 to compensate for the lack of HDR rendering. </member> <member name="reflected_light_source" type="int" setter="set_reflection_source" getter="get_reflection_source" enum="Environment.ReflectionSource" default="0"> </member> diff --git a/doc/classes/NinePatchRect.xml b/doc/classes/NinePatchRect.xml index 77fd9165bb..636ed368d1 100644 --- a/doc/classes/NinePatchRect.xml +++ b/doc/classes/NinePatchRect.xml @@ -68,11 +68,11 @@ </constant> <constant name="AXIS_STRETCH_MODE_TILE" value="1" enum="AxisStretchMode"> Repeats the center texture across the NinePatchRect. This won't cause any visible distortion. The texture must be seamless for this to work without displaying artifacts between edges. - [b]Note:[/b] Only supported when using the GLES3 renderer. When using the GLES2 renderer, this will behave like [constant AXIS_STRETCH_MODE_STRETCH]. + [b]Note:[/b] Only supported when using the Vulkan renderer. When using the OpenGL renderer, this will behave like [constant AXIS_STRETCH_MODE_STRETCH]. </constant> <constant name="AXIS_STRETCH_MODE_TILE_FIT" value="2" enum="AxisStretchMode"> Repeats the center texture across the NinePatchRect, but will also stretch the texture to make sure each tile is visible in full. This may cause the texture to be distorted, but less than [constant AXIS_STRETCH_MODE_STRETCH]. The texture must be seamless for this to work without displaying artifacts between edges. - [b]Note:[/b] Only supported when using the GLES3 renderer. When using the GLES2 renderer, this will behave like [constant AXIS_STRETCH_MODE_STRETCH]. + [b]Note:[/b] Only supported when using the Vulkan renderer. When using the OpenGL renderer, this will behave like [constant AXIS_STRETCH_MODE_STRETCH]. </constant> </constants> </class> diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml index 15cc7b9b65..cc845cc139 100644 --- a/doc/classes/OS.xml +++ b/doc/classes/OS.xml @@ -455,12 +455,12 @@ </member> </members> <constants> - <constant name="VIDEO_DRIVER_GLES2" value="0" enum="VideoDriver"> - The GLES2 rendering backend. It uses OpenGL ES 2.0 on mobile devices, OpenGL 2.1 on desktop platforms and WebGL 1.0 on the web. - </constant> - <constant name="VIDEO_DRIVER_VULKAN" value="1" enum="VideoDriver"> + <constant name="VIDEO_DRIVER_VULKAN" value="0" enum="VideoDriver"> The Vulkan rendering backend. </constant> + <constant name="VIDEO_DRIVER_OPENGL" value="1" enum="VideoDriver"> + The OpenGL rendering backend. It uses OpenGL ES 3.0 on mobile devices, OpenGL 3.3 on desktop platforms and WebGL 2.0 on the web. + </constant> <constant name="DAY_SUNDAY" value="0" enum="Weekday"> Sunday. </constant> diff --git a/drivers/SCsub b/drivers/SCsub index c486a15856..ea6d4c9a47 100644 --- a/drivers/SCsub +++ b/drivers/SCsub @@ -25,8 +25,7 @@ SConscript("winmidi/SCsub") # Graphics drivers if env["vulkan"]: SConscript("vulkan/SCsub") - SConscript("gles2/SCsub") - SConscript("gles_common/SCsub") + SConscript("opengl/SCsub") SConscript("gl_context/SCsub") else: SConscript("dummy/SCsub") diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp deleted file mode 100644 index 6ef0816934..0000000000 --- a/drivers/gles2/rasterizer_scene_gles2.cpp +++ /dev/null @@ -1,3955 +0,0 @@ -/*************************************************************************/ -/* rasterizer_scene_gles2.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 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 */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "rasterizer_scene_gles2.h" -#ifdef GLES2_BACKEND_ENABLED - -#ifdef GODOT_3 - -#include "core/math/math_funcs.h" -#include "core/math/transform.h" -#include "core/os/os.h" -#include "core/project_settings.h" -#include "core/vmap.h" -#include "rasterizer_canvas_gles2.h" -#include "servers/camera/camera_feed.h" -#include "servers/visual/visual_server_raster.h" - -#ifndef GLES_OVER_GL -#define glClearDepth glClearDepthf -#endif - -#ifndef GLES_OVER_GL -#ifdef IPHONE_ENABLED -#include <OpenGLES/ES2/glext.h> -//void *glResolveMultisampleFramebufferAPPLE; - -#define GL_READ_FRAMEBUFFER 0x8CA8 -#define GL_DRAW_FRAMEBUFFER 0x8CA9 -#endif -#endif - -static const GLenum _cube_side_enum[6] = { - GL_TEXTURE_CUBE_MAP_NEGATIVE_X, - GL_TEXTURE_CUBE_MAP_POSITIVE_X, - GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, - GL_TEXTURE_CUBE_MAP_POSITIVE_Y, - GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, - GL_TEXTURE_CUBE_MAP_POSITIVE_Z, -}; - -/* SHADOW ATLAS API */ - -RID RasterizerSceneGLES2::shadow_atlas_create() { - ShadowAtlas *shadow_atlas = memnew(ShadowAtlas); - shadow_atlas->fbo = 0; - shadow_atlas->depth = 0; - shadow_atlas->color = 0; - shadow_atlas->size = 0; - shadow_atlas->smallest_subdiv = 0; - - for (int i = 0; i < 4; i++) { - shadow_atlas->size_order[i] = i; - } - - return shadow_atlas_owner.make_rid(shadow_atlas); -} - -void RasterizerSceneGLES2::shadow_atlas_set_size(RID p_atlas, int p_size) { - ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_atlas); - ERR_FAIL_COND(!shadow_atlas); - ERR_FAIL_COND(p_size < 0); - - p_size = next_power_of_2(p_size); - - if (p_size == shadow_atlas->size) - return; - - // erase the old atlast - if (shadow_atlas->fbo) { - if (storage->config.use_rgba_3d_shadows) { - glDeleteRenderbuffers(1, &shadow_atlas->depth); - } else { - glDeleteTextures(1, &shadow_atlas->depth); - } - glDeleteFramebuffers(1, &shadow_atlas->fbo); - if (shadow_atlas->color) { - glDeleteTextures(1, &shadow_atlas->color); - } - - shadow_atlas->fbo = 0; - shadow_atlas->depth = 0; - shadow_atlas->color = 0; - } - - // erase shadow atlast references from lights - for (Map<RID, uint32_t>::Element *E = shadow_atlas->shadow_owners.front(); E; E = E->next()) { - LightInstance *li = light_instance_owner.getornull(E->key()); - ERR_CONTINUE(!li); - li->shadow_atlases.erase(p_atlas); - } - - shadow_atlas->shadow_owners.clear(); - - shadow_atlas->size = p_size; - - if (shadow_atlas->size) { - glGenFramebuffers(1, &shadow_atlas->fbo); - glBindFramebuffer(GL_FRAMEBUFFER, shadow_atlas->fbo); - - // create a depth texture - glActiveTexture(GL_TEXTURE0); - - if (storage->config.use_rgba_3d_shadows) { - //maximum compatibility, renderbuffer and RGBA shadow - glGenRenderbuffers(1, &shadow_atlas->depth); - glBindRenderbuffer(GL_RENDERBUFFER, shadow_atlas->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); - 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_COLOR_ATTACHMENT0, GL_TEXTURE_2D, shadow_atlas->color, 0); - } else { - //just depth texture - glGenTextures(1, &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); - - 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, shadow_atlas->depth, 0); - } - glViewport(0, 0, shadow_atlas->size, shadow_atlas->size); - - glDepthMask(GL_TRUE); - - glClearDepth(0.0f); - glClear(GL_DEPTH_BUFFER_BIT); - - glBindFramebuffer(GL_FRAMEBUFFER, 0); - } -} - -void RasterizerSceneGLES2::shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision) { - ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_atlas); - ERR_FAIL_COND(!shadow_atlas); - ERR_FAIL_INDEX(p_quadrant, 4); - ERR_FAIL_INDEX(p_subdivision, 16384); - - uint32_t subdiv = next_power_of_2(p_subdivision); - if (subdiv & 0xaaaaaaaa) { // sqrt(subdiv) must be integer - subdiv <<= 1; - } - - subdiv = int(Math::sqrt((float)subdiv)); - - if (shadow_atlas->quadrants[p_quadrant].shadows.size() == (int)subdiv) - return; - - // erase all data from the quadrant - for (int i = 0; i < shadow_atlas->quadrants[p_quadrant].shadows.size(); i++) { - if (shadow_atlas->quadrants[p_quadrant].shadows[i].owner.is_valid()) { - shadow_atlas->shadow_owners.erase(shadow_atlas->quadrants[p_quadrant].shadows[i].owner); - - LightInstance *li = light_instance_owner.getornull(shadow_atlas->quadrants[p_quadrant].shadows[i].owner); - ERR_CONTINUE(!li); - li->shadow_atlases.erase(p_atlas); - } - } - - shadow_atlas->quadrants[p_quadrant].shadows.resize(0); - shadow_atlas->quadrants[p_quadrant].shadows.resize(subdiv); - shadow_atlas->quadrants[p_quadrant].subdivision = subdiv; - - // cache the smallest subdivision for faster allocations - - shadow_atlas->smallest_subdiv = 1 << 30; - - for (int i = 0; i < 4; i++) { - if (shadow_atlas->quadrants[i].subdivision) { - shadow_atlas->smallest_subdiv = MIN(shadow_atlas->smallest_subdiv, shadow_atlas->quadrants[i].subdivision); - } - } - - if (shadow_atlas->smallest_subdiv == 1 << 30) { - shadow_atlas->smallest_subdiv = 0; - } - - // re-sort the quadrants - - int swaps = 0; - do { - swaps = 0; - - for (int i = 0; i < 3; i++) { - if (shadow_atlas->quadrants[shadow_atlas->size_order[i]].subdivision < shadow_atlas->quadrants[shadow_atlas->size_order[i + 1]].subdivision) { - SWAP(shadow_atlas->size_order[i], shadow_atlas->size_order[i + 1]); - swaps++; - } - } - - } while (swaps > 0); -} - -bool RasterizerSceneGLES2::_shadow_atlas_find_shadow(ShadowAtlas *shadow_atlas, int *p_in_quadrants, int p_quadrant_count, int p_current_subdiv, uint64_t p_tick, int &r_quadrant, int &r_shadow) { - for (int i = p_quadrant_count - 1; i >= 0; i--) { - int qidx = p_in_quadrants[i]; - - if (shadow_atlas->quadrants[qidx].subdivision == (uint32_t)p_current_subdiv) { - return false; - } - - // look for an empty space - - int sc = shadow_atlas->quadrants[qidx].shadows.size(); - - ShadowAtlas::Quadrant::Shadow *sarr = shadow_atlas->quadrants[qidx].shadows.ptrw(); - - int found_free_idx = -1; // found a free one - int found_used_idx = -1; // found an existing one, must steal it - uint64_t min_pass = 0; // pass of the existing one, try to use the least recently - - for (int j = 0; j < sc; j++) { - if (!sarr[j].owner.is_valid()) { - found_free_idx = j; - break; - } - - LightInstance *sli = light_instance_owner.getornull(sarr[j].owner); - ERR_CONTINUE(!sli); - - if (sli->last_scene_pass != scene_pass) { - // was just allocated, don't kill it so soon, wait a bit... - - if (p_tick - sarr[j].alloc_tick < shadow_atlas_realloc_tolerance_msec) { - continue; - } - - if (found_used_idx == -1 || sli->last_scene_pass < min_pass) { - found_used_idx = j; - min_pass = sli->last_scene_pass; - } - } - } - - if (found_free_idx == -1 && found_used_idx == -1) { - continue; // nothing found - } - - if (found_free_idx == -1 && found_used_idx != -1) { - found_free_idx = found_used_idx; - } - - r_quadrant = qidx; - r_shadow = found_free_idx; - - return true; - } - - return false; -} - -bool RasterizerSceneGLES2::shadow_atlas_update_light(RID p_atlas, RID p_light_intance, float p_coverage, uint64_t p_light_version) { - ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_atlas); - ERR_FAIL_COND_V(!shadow_atlas, false); - - LightInstance *li = light_instance_owner.getornull(p_light_intance); - ERR_FAIL_COND_V(!li, false); - - if (shadow_atlas->size == 0 || shadow_atlas->smallest_subdiv == 0) { - return false; - } - - uint32_t quad_size = shadow_atlas->size >> 1; - int desired_fit = MIN(quad_size / shadow_atlas->smallest_subdiv, next_power_of_2(quad_size * p_coverage)); - - int valid_quadrants[4]; - int valid_quadrant_count = 0; - int best_size = -1; - int best_subdiv = -1; - - for (int i = 0; i < 4; i++) { - int q = shadow_atlas->size_order[i]; - int sd = shadow_atlas->quadrants[q].subdivision; - - if (sd == 0) { - continue; - } - - int max_fit = quad_size / sd; - - if (best_size != -1 && max_fit > best_size) { - break; // what we asked for is bigger than this. - } - - valid_quadrants[valid_quadrant_count] = q; - valid_quadrant_count++; - - best_subdiv = sd; - - if (max_fit >= desired_fit) { - best_size = max_fit; - } - } - - ERR_FAIL_COND_V(valid_quadrant_count == 0, false); // no suitable block available - - uint64_t tick = OS::get_singleton()->get_ticks_msec(); - - if (shadow_atlas->shadow_owners.has(p_light_intance)) { - // light was already known! - - uint32_t key = shadow_atlas->shadow_owners[p_light_intance]; - uint32_t q = (key >> ShadowAtlas::QUADRANT_SHIFT) & 0x3; - uint32_t s = key & ShadowAtlas::SHADOW_INDEX_MASK; - - bool should_realloc = shadow_atlas->quadrants[q].subdivision != (uint32_t)best_subdiv && (shadow_atlas->quadrants[q].shadows[s].alloc_tick - tick > shadow_atlas_realloc_tolerance_msec); - - bool should_redraw = shadow_atlas->quadrants[q].shadows[s].version != p_light_version; - - if (!should_realloc) { - shadow_atlas->quadrants[q].shadows.write[s].version = p_light_version; - return should_redraw; - } - - int new_quadrant; - int new_shadow; - - // find a better place - - if (_shadow_atlas_find_shadow(shadow_atlas, valid_quadrants, valid_quadrant_count, shadow_atlas->quadrants[q].subdivision, tick, new_quadrant, new_shadow)) { - // found a better place - - ShadowAtlas::Quadrant::Shadow *sh = &shadow_atlas->quadrants[new_quadrant].shadows.write[new_shadow]; - if (sh->owner.is_valid()) { - // it is take but invalid, so we can take it - - shadow_atlas->shadow_owners.erase(sh->owner); - LightInstance *sli = light_instance_owner.get(sh->owner); - sli->shadow_atlases.erase(p_atlas); - } - - // erase previous - shadow_atlas->quadrants[q].shadows.write[s].version = 0; - shadow_atlas->quadrants[q].shadows.write[s].owner = RID(); - - sh->owner = p_light_intance; - sh->alloc_tick = tick; - sh->version = p_light_version; - li->shadow_atlases.insert(p_atlas); - - // make a new key - key = new_quadrant << ShadowAtlas::QUADRANT_SHIFT; - key |= new_shadow; - - // update it in the map - shadow_atlas->shadow_owners[p_light_intance] = key; - - // make it dirty, so we redraw - return true; - } - - // no better place found, so we keep the current place - - shadow_atlas->quadrants[q].shadows.write[s].version = p_light_version; - - return should_redraw; - } - - int new_quadrant; - int new_shadow; - - if (_shadow_atlas_find_shadow(shadow_atlas, valid_quadrants, valid_quadrant_count, -1, tick, new_quadrant, new_shadow)) { - // found a better place - - ShadowAtlas::Quadrant::Shadow *sh = &shadow_atlas->quadrants[new_quadrant].shadows.write[new_shadow]; - if (sh->owner.is_valid()) { - // it is take but invalid, so we can take it - - shadow_atlas->shadow_owners.erase(sh->owner); - LightInstance *sli = light_instance_owner.get(sh->owner); - sli->shadow_atlases.erase(p_atlas); - } - - sh->owner = p_light_intance; - sh->alloc_tick = tick; - sh->version = p_light_version; - li->shadow_atlases.insert(p_atlas); - - // make a new key - uint32_t key = new_quadrant << ShadowAtlas::QUADRANT_SHIFT; - key |= new_shadow; - - // update it in the map - shadow_atlas->shadow_owners[p_light_intance] = key; - - // make it dirty, so we redraw - return true; - } - - return false; -} - -void RasterizerSceneGLES2::set_directional_shadow_count(int p_count) { - directional_shadow.light_count = p_count; - directional_shadow.current_light = 0; -} - -int RasterizerSceneGLES2::get_directional_light_shadow_size(RID p_light_intance) { - ERR_FAIL_COND_V(directional_shadow.light_count == 0, 0); - - int shadow_size; - - if (directional_shadow.light_count == 1) { - shadow_size = directional_shadow.size; - } else { - shadow_size = directional_shadow.size / 2; //more than 4 not supported anyway - } - - LightInstance *light_instance = light_instance_owner.getornull(p_light_intance); - ERR_FAIL_COND_V(!light_instance, 0); - - switch (light_instance->light_ptr->directional_shadow_mode) { - case GD_VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL: - break; //none - case GD_VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS: - case GD_VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS: - shadow_size /= 2; - break; - } - - return shadow_size; -} -////////////////////////////////////////////////////// - -RID RasterizerSceneGLES2::reflection_atlas_create() { - return RID(); -} - -void RasterizerSceneGLES2::reflection_atlas_set_size(RID p_ref_atlas, int p_size) { -} - -void RasterizerSceneGLES2::reflection_atlas_set_subdivision(RID p_ref_atlas, int p_subdiv) { -} - -//////////////////////////////////////////////////// - -RID RasterizerSceneGLES2::reflection_probe_instance_create(RID p_probe) { - RasterizerStorageGLES2::ReflectionProbe *probe = storage->reflection_probe_owner.getornull(p_probe); - ERR_FAIL_COND_V(!probe, RID()); - - ReflectionProbeInstance *rpi = memnew(ReflectionProbeInstance); - - rpi->probe_ptr = probe; - rpi->self = reflection_probe_instance_owner.make_rid(rpi); - rpi->probe = p_probe; - rpi->reflection_atlas_index = -1; - rpi->render_step = -1; - rpi->last_pass = 0; - rpi->current_resolution = 0; - rpi->dirty = true; - - rpi->index = 0; - - for (int i = 0; i < 6; i++) { - glGenFramebuffers(1, &rpi->fbo[i]); - glGenTextures(1, &rpi->color[i]); - } - - glGenRenderbuffers(1, &rpi->depth); - - rpi->cubemap = 0; - //glGenTextures(1, &rpi->cubemap); - - return rpi->self; -} - -void RasterizerSceneGLES2::reflection_probe_instance_set_transform(RID p_instance, const Transform3D &p_transform) { - ReflectionProbeInstance *rpi = reflection_probe_instance_owner.getornull(p_instance); - ERR_FAIL_COND(!rpi); - rpi->transform = p_transform; -} - -void RasterizerSceneGLES2::reflection_probe_release_atlas_index(RID p_instance) { -} - -bool RasterizerSceneGLES2::reflection_probe_instance_needs_redraw(RID p_instance) { - const ReflectionProbeInstance *rpi = reflection_probe_instance_owner.getornull(p_instance); - ERR_FAIL_COND_V(!rpi, false); - - bool need_redraw = rpi->probe_ptr->resolution != rpi->current_resolution || rpi->dirty || rpi->probe_ptr->update_mode == GD_VS::REFLECTION_PROBE_UPDATE_ALWAYS; - rpi->dirty = false; - return need_redraw; -} - -bool RasterizerSceneGLES2::reflection_probe_instance_has_reflection(RID p_instance) { - return true; -} - -bool RasterizerSceneGLES2::reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas) { - ReflectionProbeInstance *rpi = reflection_probe_instance_owner.getornull(p_instance); - ERR_FAIL_COND_V(!rpi, false); - - rpi->render_step = 0; - - if (rpi->probe_ptr->resolution != rpi->current_resolution) { - //update cubemap if resolution changed - int size = rpi->probe_ptr->resolution; - rpi->current_resolution = size; - - GLenum internal_format = GL_RGB; - GLenum format = GL_RGB; - GLenum type = GL_UNSIGNED_BYTE; - - glActiveTexture(GL_TEXTURE0); - - glBindRenderbuffer(GL_RENDERBUFFER, rpi->depth); - glRenderbufferStorage(GL_RENDERBUFFER, storage->config.depth_internalformat, size, size); - - if (rpi->cubemap != 0) { - glDeleteTextures(1, &rpi->cubemap); - } - - glGenTextures(1, &rpi->cubemap); - glBindTexture(GL_TEXTURE_CUBE_MAP, rpi->cubemap); - - // 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 - for (int i = 0; i < 6; i++) { - glBindFramebuffer(GL_FRAMEBUFFER, rpi->fbo[i]); - glBindTexture(GL_TEXTURE_2D, rpi->color[i]); - 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); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rpi->depth); - GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - ERR_CONTINUE(status != GL_FRAMEBUFFER_COMPLETE); - } - - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES2::system_fbo); - } - - return true; -} - -bool RasterizerSceneGLES2::reflection_probe_instance_postprocess_step(RID p_instance) { - ReflectionProbeInstance *rpi = reflection_probe_instance_owner.getornull(p_instance); - ERR_FAIL_COND_V(!rpi, false); - ERR_FAIL_COND_V(rpi->current_resolution == 0, false); - - int size = rpi->probe_ptr->resolution; - - { - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - glDisable(GL_CULL_FACE); - glDisable(GL_DEPTH_TEST); - glDisable(GL_SCISSOR_TEST); - glDisable(GL_BLEND); - glDepthMask(GL_FALSE); - - for (int i = 0; i < GD_VS::ARRAY_MAX - 1; i++) { - glDisableVertexAttribArray(i); - } - } - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_CUBE_MAP, rpi->cubemap); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //use linear, no mipmaps so it does not read from what is being written to - - //first of all, copy rendered textures to cubemap - for (int i = 0; i < 6; i++) { - glBindFramebuffer(GL_FRAMEBUFFER, rpi->fbo[i]); - glViewport(0, 0, size, size); - glCopyTexSubImage2D(_cube_side_enum[i], 0, 0, 0, 0, 0, size, size); - } - //do filtering - //vdc cache - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, storage->resources.radical_inverse_vdc_cache_tex); - - // now render to the framebuffer, mipmap level for mipmap level - int lod = 1; - - size >>= 1; - int mipmaps = 6; - - storage->shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES2::USE_SOURCE_PANORAMA, false); - storage->shaders.cubemap_filter.bind(); - - glBindFramebuffer(GL_FRAMEBUFFER, storage->resources.mipmap_blur_fbo); - - //blur - while (size >= 1) { - glActiveTexture(GL_TEXTURE3); - glBindTexture(GL_TEXTURE_2D, storage->resources.mipmap_blur_color); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, storage->resources.mipmap_blur_color, 0); - glViewport(0, 0, size, size); - glActiveTexture(GL_TEXTURE0); - - for (int i = 0; i < 6; i++) { - storage->bind_quad_array(); - storage->shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES2::FACE_ID, i); - float roughness = CLAMP(lod / (float)(mipmaps - 1), 0, 1); - storage->shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES2::ROUGHNESS, roughness); - storage->shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES2::Z_FLIP, false); - - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - glCopyTexSubImage2D(_cube_side_enum[i], lod, 0, 0, 0, 0, size, size); - } - - size >>= 1; - - lod++; - } - - // restore ranges - glActiveTexture(GL_TEXTURE0); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glBindTexture(GL_TEXTURE_2D, 0); - glActiveTexture(GL_TEXTURE3); //back to panorama - glBindTexture(GL_TEXTURE_2D, 0); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, 0); - glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES2::system_fbo); - - return true; -} - -/* ENVIRONMENT API */ - -RID RasterizerSceneGLES2::environment_create() { - Environment *env = memnew(Environment); - - return environment_owner.make_rid(env); -} - -void RasterizerSceneGLES2::environment_set_background(RID p_env, GD_VS::EnvironmentBG p_bg) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); - env->bg_mode = p_bg; -} - -void RasterizerSceneGLES2::environment_set_sky(RID p_env, RID p_sky) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); - - env->sky = p_sky; -} - -void RasterizerSceneGLES2::environment_set_sky_custom_fov(RID p_env, float p_scale) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); - - env->sky_custom_fov = p_scale; -} - -void RasterizerSceneGLES2::environment_set_sky_orientation(RID p_env, const Basis &p_orientation) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); - - env->sky_orientation = p_orientation; -} - -void RasterizerSceneGLES2::environment_set_bg_color(RID p_env, const Color &p_color) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); - - env->bg_color = p_color; -} - -void RasterizerSceneGLES2::environment_set_bg_energy(RID p_env, float p_energy) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); - - env->bg_energy = p_energy; -} - -void RasterizerSceneGLES2::environment_set_canvas_max_layer(RID p_env, int p_max_layer) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); - - env->canvas_max_layer = p_max_layer; -} - -void RasterizerSceneGLES2::environment_set_ambient_light(RID p_env, const Color &p_color, float p_energy, float p_sky_contribution) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); - - env->ambient_color = p_color; - env->ambient_energy = p_energy; - env->ambient_sky_contribution = p_sky_contribution; -} - -void RasterizerSceneGLES2::environment_set_camera_feed_id(RID p_env, int p_camera_feed_id) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); - - env->camera_feed_id = p_camera_feed_id; -} - -void RasterizerSceneGLES2::environment_set_dof_blur_far(RID p_env, bool p_enable, float p_distance, float p_transition, float p_amount, GD_VS::EnvironmentDOFBlurQuality p_quality) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); - - env->dof_blur_far_enabled = p_enable; - env->dof_blur_far_distance = p_distance; - env->dof_blur_far_transition = p_transition; - env->dof_blur_far_amount = p_amount; - env->dof_blur_far_quality = p_quality; -} - -void RasterizerSceneGLES2::environment_set_dof_blur_near(RID p_env, bool p_enable, float p_distance, float p_transition, float p_amount, GD_VS::EnvironmentDOFBlurQuality p_quality) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); - - env->dof_blur_near_enabled = p_enable; - env->dof_blur_near_distance = p_distance; - env->dof_blur_near_transition = p_transition; - env->dof_blur_near_amount = p_amount; - env->dof_blur_near_quality = p_quality; -} - -void RasterizerSceneGLES2::environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_threshold, GD_VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, bool p_bicubic_upscale) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); - - env->glow_enabled = p_enable; - env->glow_levels = p_level_flags; - env->glow_intensity = p_intensity; - env->glow_strength = p_strength; - env->glow_bloom = p_bloom_threshold; - env->glow_blend_mode = p_blend_mode; - env->glow_hdr_bleed_threshold = p_hdr_bleed_threshold; - env->glow_hdr_bleed_scale = p_hdr_bleed_scale; - env->glow_hdr_luminance_cap = p_hdr_luminance_cap; - env->glow_bicubic_upscale = p_bicubic_upscale; -} - -void RasterizerSceneGLES2::environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); -} - -void RasterizerSceneGLES2::environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_in, float p_fade_out, float p_depth_tolerance, bool p_roughness) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); -} - -void RasterizerSceneGLES2::environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect, float p_ao_channel_affect, const Color &p_color, GD_VS::EnvironmentSSAOQuality p_quality, VisualServer::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); -} - -void RasterizerSceneGLES2::environment_set_tonemap(RID p_env, GD_VS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); -} - -void RasterizerSceneGLES2::environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, RID p_ramp) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); - - env->adjustments_enabled = p_enable; - env->adjustments_brightness = p_brightness; - env->adjustments_contrast = p_contrast; - env->adjustments_saturation = p_saturation; - env->color_correction = p_ramp; -} - -void RasterizerSceneGLES2::environment_set_fog(RID p_env, bool p_enable, const Color &p_color, const Color &p_sun_color, float p_sun_amount) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); - - env->fog_enabled = p_enable; - env->fog_color = p_color; - env->fog_sun_color = p_sun_color; - env->fog_sun_amount = p_sun_amount; -} - -void RasterizerSceneGLES2::environment_set_fog_depth(RID p_env, bool p_enable, float p_depth_begin, float p_depth_end, float p_depth_curve, bool p_transmit, float p_transmit_curve) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); - - env->fog_depth_enabled = p_enable; - env->fog_depth_begin = p_depth_begin; - env->fog_depth_end = p_depth_end; - env->fog_depth_curve = p_depth_curve; - env->fog_transmit_enabled = p_transmit; - env->fog_transmit_curve = p_transmit_curve; -} - -void RasterizerSceneGLES2::environment_set_fog_height(RID p_env, bool p_enable, float p_min_height, float p_max_height, float p_height_curve) { - Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND(!env); - - env->fog_height_enabled = p_enable; - env->fog_height_min = p_min_height; - env->fog_height_max = p_max_height; - env->fog_height_curve = p_height_curve; -} -bool RasterizerSceneGLES2::is_environment(RID p_env) { - return environment_owner.owns(p_env); -} - -VS::EnvironmentBG RasterizerSceneGLES2::environment_get_background(RID p_env) { - const Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND_V(!env, GD_VS::ENV_BG_MAX); - - return env->bg_mode; -} - -int RasterizerSceneGLES2::environment_get_canvas_max_layer(RID p_env) { - const Environment *env = environment_owner.getornull(p_env); - ERR_FAIL_COND_V(!env, -1); - - return env->canvas_max_layer; -} - -RID RasterizerSceneGLES2::light_instance_create(RID p_light) { - LightInstance *light_instance = memnew(LightInstance); - - light_instance->last_scene_pass = 0; - - light_instance->light = p_light; - light_instance->light_ptr = storage->light_owner.getornull(p_light); - - light_instance->light_index = 0xFFFF; - - if (!light_instance->light_ptr) { - memdelete(light_instance); - ERR_FAIL_V_MSG(RID(), "Condition ' !light_instance->light_ptr ' is true."); - } - - light_instance->self = light_instance_owner.make_rid(light_instance); - - return light_instance->self; -} - -void RasterizerSceneGLES2::light_instance_set_transform(RID p_light_instance, const Transform3D &p_transform) { - LightInstance *light_instance = light_instance_owner.getornull(p_light_instance); - ERR_FAIL_COND(!light_instance); - - light_instance->transform = p_transform; -} - -void RasterizerSceneGLES2::light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform3D &p_transform, float p_far, float p_split, int p_pass, float p_bias_scale) { - LightInstance *light_instance = light_instance_owner.getornull(p_light_instance); - ERR_FAIL_COND(!light_instance); - - if (light_instance->light_ptr->type != GD_VS::LIGHT_DIRECTIONAL) { - p_pass = 0; - } - - ERR_FAIL_INDEX(p_pass, 4); - - light_instance->shadow_transform[p_pass].camera = p_projection; - light_instance->shadow_transform[p_pass].transform = p_transform; - light_instance->shadow_transform[p_pass].farplane = p_far; - light_instance->shadow_transform[p_pass].split = p_split; - light_instance->shadow_transform[p_pass].bias_scale = p_bias_scale; -} - -void RasterizerSceneGLES2::light_instance_mark_visible(RID p_light_instance) { - LightInstance *light_instance = light_instance_owner.getornull(p_light_instance); - ERR_FAIL_COND(!light_instance); - - light_instance->last_scene_pass = scene_pass; -} - -////////////////////// - -RID RasterizerSceneGLES2::gi_probe_instance_create() { - return RID(); -} - -void RasterizerSceneGLES2::gi_probe_instance_set_light_data(RID p_probe, RID p_base, RID p_data) { -} -void RasterizerSceneGLES2::gi_probe_instance_set_transform_to_data(RID p_probe, const Transform3D &p_xform) { -} - -void RasterizerSceneGLES2::gi_probe_instance_set_bounds(RID p_probe, const Vector3 &p_bounds) { -} - -//////////////////////////// -//////////////////////////// -//////////////////////////// - -void RasterizerSceneGLES2::_add_geometry(RasterizerStorageGLES2::Geometry *p_geometry, InstanceBase *p_instance, RasterizerStorageGLES2::GeometryOwner *p_owner, int p_material, bool p_depth_pass, bool p_shadow_pass) { - RasterizerStorageGLES2::Material *material = NULL; - RID material_src; - - if (p_instance->material_override.is_valid()) { - material_src = p_instance->material_override; - } else if (p_material >= 0) { - material_src = p_instance->materials[p_material]; - } else { - material_src = p_geometry->material; - } - - if (material_src.is_valid()) { - material = storage->material_owner.getornull(material_src); - - if (!material->shader || !material->shader->valid) { - material = NULL; - } - } - - if (!material) { - material = storage->material_owner.getptr(default_material); - } - - ERR_FAIL_COND(!material); - - _add_geometry_with_material(p_geometry, p_instance, p_owner, material, p_depth_pass, p_shadow_pass); - - while (material->next_pass.is_valid()) { - material = storage->material_owner.getornull(material->next_pass); - - if (!material || !material->shader || !material->shader->valid) { - break; - } - - _add_geometry_with_material(p_geometry, p_instance, p_owner, material, p_depth_pass, p_shadow_pass); - } -} -void RasterizerSceneGLES2::_add_geometry_with_material(RasterizerStorageGLES2::Geometry *p_geometry, InstanceBase *p_instance, RasterizerStorageGLES2::GeometryOwner *p_owner, RasterizerStorageGLES2::Material *p_material, bool p_depth_pass, bool p_shadow_pass) { - bool has_base_alpha = (p_material->shader->spatial.uses_alpha && !p_material->shader->spatial.uses_alpha_scissor) || p_material->shader->spatial.uses_screen_texture || p_material->shader->spatial.uses_depth_texture; - bool has_blend_alpha = p_material->shader->spatial.blend_mode != RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_MIX; - bool has_alpha = has_base_alpha || has_blend_alpha; - - bool mirror = p_instance->mirror; - - if (p_material->shader->spatial.cull_mode == RasterizerStorageGLES2::Shader::Spatial::CULL_MODE_DISABLED) { - mirror = false; - } else if (p_material->shader->spatial.cull_mode == RasterizerStorageGLES2::Shader::Spatial::CULL_MODE_FRONT) { - mirror = !mirror; - } - - //if (p_material->shader->spatial.uses_sss) { - // state.used_sss = true; - //} - - if (p_material->shader->spatial.uses_screen_texture) { - state.used_screen_texture = true; - } - - if (p_depth_pass) { - if (has_blend_alpha || p_material->shader->spatial.uses_depth_texture || (has_base_alpha && p_material->shader->spatial.depth_draw_mode != RasterizerStorageGLES2::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS)) - return; //bye - - if (!p_material->shader->spatial.uses_alpha_scissor && !p_material->shader->spatial.writes_modelview_or_projection && !p_material->shader->spatial.uses_vertex && !p_material->shader->spatial.uses_discard && p_material->shader->spatial.depth_draw_mode != RasterizerStorageGLES2::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS) { - //shader does not use discard and does not write a vertex position, use generic material - if (p_instance->cast_shadows == GD_VS::SHADOW_CASTING_SETTING_DOUBLE_SIDED) { - p_material = storage->material_owner.getptr(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material_twosided : default_material_twosided); - mirror = false; - } else { - p_material = storage->material_owner.getptr(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material : default_material); - } - } - - has_alpha = false; - } - - RenderList::Element *e = (has_alpha || p_material->shader->spatial.no_depth_test) ? render_list.add_alpha_element() : render_list.add_element(); - - if (!e) { - return; - } - - e->geometry = p_geometry; - e->material = p_material; - e->instance = p_instance; - e->owner = p_owner; - e->sort_key = 0; - e->depth_key = 0; - e->use_accum = false; - e->light_index = RenderList::MAX_LIGHTS; - e->use_accum_ptr = &e->use_accum; - e->instancing = (e->instance->base_type == GD_VS::INSTANCE_MULTIMESH) ? 1 : 0; - e->front_facing = false; - - if (e->geometry->last_pass != render_pass) { - e->geometry->last_pass = render_pass; - e->geometry->index = current_geometry_index++; - } - - e->geometry_index = e->geometry->index; - - if (e->material->last_pass != render_pass) { - e->material->last_pass = render_pass; - e->material->index = current_material_index++; - - if (e->material->shader->last_pass != render_pass) { - e->material->shader->index = current_shader_index++; - } - } - - e->material_index = e->material->index; - - if (mirror) { - e->front_facing = true; - } - - e->refprobe_0_index = RenderList::MAX_REFLECTION_PROBES; //refprobe disabled by default - e->refprobe_1_index = RenderList::MAX_REFLECTION_PROBES; //refprobe disabled by default - - if (!p_depth_pass) { - e->depth_layer = e->instance->depth_layer; - e->priority = p_material->render_priority; - - if (has_alpha && p_material->shader->spatial.depth_draw_mode == RasterizerStorageGLES2::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS) { - //add element to opaque - RenderList::Element *eo = render_list.add_element(); - *eo = *e; - eo->use_accum_ptr = &eo->use_accum; - } - - int rpsize = e->instance->reflection_probe_instances.size(); - if (rpsize > 0) { - bool first = true; - rpsize = MIN(rpsize, 2); //more than 2 per object are not supported, this keeps it stable - - for (int i = 0; i < rpsize; i++) { - ReflectionProbeInstance *rpi = reflection_probe_instance_owner.getornull(e->instance->reflection_probe_instances[i]); - if (rpi->last_pass != render_pass) { - continue; - } - if (first) { - e->refprobe_0_index = rpi->index; - first = false; - } else { - e->refprobe_1_index = rpi->index; - break; - } - } - - /* if (e->refprobe_0_index > e->refprobe_1_index) { //if both are valid, swap them to keep order as best as possible - uint64_t tmp = e->refprobe_0_index; - e->refprobe_0_index = e->refprobe_1_index; - e->refprobe_1_index = tmp; - }*/ - } - - //add directional lights - - if (p_material->shader->spatial.unshaded) { - e->light_mode = LIGHTMODE_UNSHADED; - } else { - bool copy = false; - - for (int i = 0; i < render_directional_lights; i++) { - if (copy) { - RenderList::Element *e2 = has_alpha ? render_list.add_alpha_element() : render_list.add_element(); - if (!e2) { - break; - } - *e2 = *e; //this includes accum ptr :) - e = e2; - } - - //directional sort key - e->light_type1 = 0; - e->light_type2 = 1; - e->light_index = i; - - copy = true; - } - - //add omni / spots - - for (int i = 0; i < e->instance->light_instances.size(); i++) { - LightInstance *li = light_instance_owner.getornull(e->instance->light_instances[i]); - - 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 - } - - if (copy) { - RenderList::Element *e2 = has_alpha ? render_list.add_alpha_element() : render_list.add_element(); - if (!e2) { - break; - } - *e2 = *e; //this includes accum ptr :) - e = e2; - } - - //directional sort key - e->light_type1 = 1; - e->light_type2 = li->light_ptr->type == VisualServer::LIGHT_OMNI ? 0 : 1; - e->light_index = li->light_index; - - copy = true; - } - - if (e->instance->lightmap.is_valid()) { - e->light_mode = LIGHTMODE_LIGHTMAP; - } else if (!e->instance->lightmap_capture_data.empty()) { - e->light_mode = LIGHTMODE_LIGHTMAP_CAPTURE; - } else { - e->light_mode = LIGHTMODE_NORMAL; - } - } - } - - // do not add anything here, as lights are duplicated elements.. - - if (p_material->shader->spatial.uses_time) { - VisualServerRaster::redraw_request(); - } -} - -void RasterizerSceneGLES2::_copy_texture_to_buffer(GLuint p_texture, GLuint p_buffer) { - //copy to front buffer - glBindFramebuffer(GL_FRAMEBUFFER, p_buffer); - - glDepthMask(GL_FALSE); - glDisable(GL_DEPTH_TEST); - glDisable(GL_CULL_FACE); - glDisable(GL_BLEND); - glDepthFunc(GL_LEQUAL); - glColorMask(1, 1, 1, 1); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, p_texture); - - glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height); - - storage->shaders.copy.bind(); - - storage->bind_quad_array(); - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - glBindBuffer(GL_ARRAY_BUFFER, 0); -} - -void RasterizerSceneGLES2::_fill_render_list(InstanceBase **p_cull_result, int p_cull_count, bool p_depth_pass, bool p_shadow_pass) { - render_pass++; - current_material_index = 0; - current_geometry_index = 0; - current_light_index = 0; - current_refprobe_index = 0; - current_shader_index = 0; - - for (int i = 0; i < p_cull_count; i++) { - InstanceBase *instance = p_cull_result[i]; - - switch (instance->base_type) { - case GD_VS::INSTANCE_MESH: { - RasterizerStorageGLES2::Mesh *mesh = storage->mesh_owner.getornull(instance->base); - ERR_CONTINUE(!mesh); - - int num_surfaces = mesh->surfaces.size(); - - for (int j = 0; j < num_surfaces; j++) { - int material_index = instance->materials[j].is_valid() ? j : -1; - - RasterizerStorageGLES2::Surface *surface = mesh->surfaces[j]; - - _add_geometry(surface, instance, NULL, material_index, p_depth_pass, p_shadow_pass); - } - - } break; - - case GD_VS::INSTANCE_MULTIMESH: { - RasterizerStorageGLES2::MultiMesh *multi_mesh = storage->multimesh_owner.getptr(instance->base); - ERR_CONTINUE(!multi_mesh); - - if (multi_mesh->size == 0 || multi_mesh->visible_instances == 0) - continue; - - RasterizerStorageGLES2::Mesh *mesh = storage->mesh_owner.getptr(multi_mesh->mesh); - if (!mesh) - continue; - - int ssize = mesh->surfaces.size(); - - for (int j = 0; j < ssize; j++) { - RasterizerStorageGLES2::Surface *s = mesh->surfaces[j]; - _add_geometry(s, instance, multi_mesh, -1, p_depth_pass, p_shadow_pass); - } - } break; - - case GD_VS::INSTANCE_IMMEDIATE: { - RasterizerStorageGLES2::Immediate *im = storage->immediate_owner.getptr(instance->base); - ERR_CONTINUE(!im); - - _add_geometry(im, instance, NULL, -1, p_depth_pass, p_shadow_pass); - - } break; - - default: { - } - } - } -} - -static const GLenum gl_primitive[] = { - GL_POINTS, - GL_LINES, - GL_LINE_STRIP, - GL_LINE_LOOP, - GL_TRIANGLES, - GL_TRIANGLE_STRIP, - GL_TRIANGLE_FAN -}; - -void RasterizerSceneGLES2::_set_cull(bool p_front, bool p_disabled, bool p_reverse_cull) { - bool front = p_front; - if (p_reverse_cull) - front = !front; - - if (p_disabled != state.cull_disabled) { - if (p_disabled) - glDisable(GL_CULL_FACE); - else - glEnable(GL_CULL_FACE); - - state.cull_disabled = p_disabled; - } - - if (front != state.cull_front) { - glCullFace(front ? GL_FRONT : GL_BACK); - state.cull_front = front; - } -} - -bool RasterizerSceneGLES2::_setup_material(RasterizerStorageGLES2::Material *p_material, bool p_alpha_pass, Size2i p_skeleton_tex_size) { - // material parameters - - 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); - } - - if (p_material->shader->spatial.uses_depth_texture && storage->frame.current_rt) { - glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 4); - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->depth); - } - - bool shader_rebind = state.scene_shader.bind(); - - if (p_material->shader->spatial.no_depth_test || p_material->shader->spatial.uses_depth_texture) { - glDisable(GL_DEPTH_TEST); - } else { - glEnable(GL_DEPTH_TEST); - } - - switch (p_material->shader->spatial.depth_draw_mode) { - case RasterizerStorageGLES2::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS: - case RasterizerStorageGLES2::Shader::Spatial::DEPTH_DRAW_OPAQUE: { - glDepthMask(!p_alpha_pass && !p_material->shader->spatial.uses_depth_texture); - } break; - case RasterizerStorageGLES2::Shader::Spatial::DEPTH_DRAW_ALWAYS: { - glDepthMask(GL_TRUE && !p_material->shader->spatial.uses_depth_texture); - } break; - case RasterizerStorageGLES2::Shader::Spatial::DEPTH_DRAW_NEVER: { - glDepthMask(GL_FALSE); - } break; - } - - int tc = p_material->textures.size(); - const Pair<StringName, RID> *textures = p_material->textures.ptr(); - - const ShaderLanguage::ShaderNode::Uniform::Hint *texture_hints = p_material->shader->texture_hints.ptr(); - - state.scene_shader.set_uniform(SceneShaderGLES2::SKELETON_TEXTURE_SIZE, p_skeleton_tex_size); - - state.current_main_tex = 0; - - for (int i = 0; i < tc; i++) { - glActiveTexture(GL_TEXTURE0 + i); - - RasterizerStorageGLES2::Texture *t = storage->texture_owner.getornull(textures[i].second); - - if (!t) { - switch (texture_hints[i]) { - case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK_ALBEDO: - case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK: { - glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex); - } break; - case ShaderLanguage::ShaderNode::Uniform::HINT_ANISO: { - glBindTexture(GL_TEXTURE_2D, storage->resources.aniso_tex); - } break; - case ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL: { - glBindTexture(GL_TEXTURE_2D, storage->resources.normal_tex); - } break; - default: { - glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex); - } break; - } - - continue; - } - - if (t->redraw_if_visible) { //must check before proxy because this is often used with proxies - VisualServerRaster::redraw_request(); - } - - t = t->get_ptr(); - -#ifdef TOOLS_ENABLED - if (t->detect_3d) { - t->detect_3d(t->detect_3d_ud); - } -#endif - -#ifdef TOOLS_ENABLED - if (t->detect_normal && texture_hints[i] == ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL) { - t->detect_normal(t->detect_normal_ud); - } -#endif - if (t->render_target) - t->render_target->used_in_frame = true; - - glBindTexture(t->target, t->tex_id); - if (i == 0) { - state.current_main_tex = t->tex_id; - } - } - state.scene_shader.use_material((void *)p_material); - - return shader_rebind; -} - -void RasterizerSceneGLES2::_setup_geometry(RenderList::Element *p_element, RasterizerStorageGLES2::Skeleton *p_skeleton) { - switch (p_element->instance->base_type) { - case GD_VS::INSTANCE_MESH: { - RasterizerStorageGLES2::Surface *s = static_cast<RasterizerStorageGLES2::Surface *>(p_element->geometry); - - glBindBuffer(GL_ARRAY_BUFFER, s->vertex_id); - - if (s->index_array_len > 0) { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->index_id); - } - - for (int i = 0; i < GD_VS::ARRAY_MAX - 1; i++) { - if (s->attribs[i].enabled) { - glEnableVertexAttribArray(i); - glVertexAttribPointer(s->attribs[i].index, s->attribs[i].size, s->attribs[i].type, s->attribs[i].normalized, s->attribs[i].stride, CAST_INT_TO_UCHAR_PTR(s->attribs[i].offset)); - } else { - glDisableVertexAttribArray(i); - switch (i) { - case GD_VS::ARRAY_NORMAL: { - glVertexAttrib4f(GD_VS::ARRAY_NORMAL, 0.0, 0.0, 1, 1); - } break; - case GD_VS::ARRAY_COLOR: { - glVertexAttrib4f(GD_VS::ARRAY_COLOR, 1, 1, 1, 1); - - } break; - default: { - } - } - } - } - - bool clear_skeleton_buffer = storage->config.use_skeleton_software; - - if (p_skeleton) { - if (!storage->config.use_skeleton_software) { - //use float texture workflow - glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1); - glBindTexture(GL_TEXTURE_2D, p_skeleton->tex_id); - } else { - //use transform buffer workflow - ERR_FAIL_COND(p_skeleton->use_2d); - - PoolVector<float> &transform_buffer = storage->resources.skeleton_transform_cpu_buffer; - - if (!s->attribs[VS::ARRAY_BONES].enabled || !s->attribs[VS::ARRAY_WEIGHTS].enabled) { - break; // the whole instance has a skeleton, but this surface is not affected by it. - } - - // 3 * vec4 per vertex - if (transform_buffer.size() < s->array_len * 12) { - transform_buffer.resize(s->array_len * 12); - } - - const size_t bones_offset = s->attribs[VS::ARRAY_BONES].offset; - const size_t bones_stride = s->attribs[VS::ARRAY_BONES].stride; - const size_t bone_weight_offset = s->attribs[VS::ARRAY_WEIGHTS].offset; - const size_t bone_weight_stride = s->attribs[VS::ARRAY_WEIGHTS].stride; - - { - PoolVector<float>::Write write = transform_buffer.write(); - float *buffer = write.ptr(); - - PoolVector<uint8_t>::Read vertex_array_read = s->data.read(); - const uint8_t *vertex_data = vertex_array_read.ptr(); - - for (int i = 0; i < s->array_len; i++) { - // do magic - - size_t bones[4]; - float bone_weight[4]; - - if (s->attribs[VS::ARRAY_BONES].type == GL_UNSIGNED_BYTE) { - // read as byte - const uint8_t *bones_ptr = vertex_data + bones_offset + (i * bones_stride); - bones[0] = bones_ptr[0]; - bones[1] = bones_ptr[1]; - bones[2] = bones_ptr[2]; - bones[3] = bones_ptr[3]; - } else { - // read as short - const uint16_t *bones_ptr = (const uint16_t *)(vertex_data + bones_offset + (i * bones_stride)); - bones[0] = bones_ptr[0]; - bones[1] = bones_ptr[1]; - bones[2] = bones_ptr[2]; - bones[3] = bones_ptr[3]; - } - - if (s->attribs[VS::ARRAY_WEIGHTS].type == GL_FLOAT) { - // read as float - const float *weight_ptr = (const float *)(vertex_data + bone_weight_offset + (i * bone_weight_stride)); - bone_weight[0] = weight_ptr[0]; - bone_weight[1] = weight_ptr[1]; - bone_weight[2] = weight_ptr[2]; - bone_weight[3] = weight_ptr[3]; - } else { - // read as half - const uint16_t *weight_ptr = (const uint16_t *)(vertex_data + bone_weight_offset + (i * bone_weight_stride)); - bone_weight[0] = (weight_ptr[0] / (float)0xFFFF); - bone_weight[1] = (weight_ptr[1] / (float)0xFFFF); - bone_weight[2] = (weight_ptr[2] / (float)0xFFFF); - bone_weight[3] = (weight_ptr[3] / (float)0xFFFF); - } - - Transform3D transform; - - Transform3D bone_transforms[4] = { - storage->skeleton_bone_get_transform(p_element->instance->skeleton, bones[0]), - storage->skeleton_bone_get_transform(p_element->instance->skeleton, bones[1]), - storage->skeleton_bone_get_transform(p_element->instance->skeleton, bones[2]), - storage->skeleton_bone_get_transform(p_element->instance->skeleton, bones[3]), - }; - - transform.origin = - bone_weight[0] * bone_transforms[0].origin + - bone_weight[1] * bone_transforms[1].origin + - bone_weight[2] * bone_transforms[2].origin + - bone_weight[3] * bone_transforms[3].origin; - - transform.basis = - bone_transforms[0].basis * bone_weight[0] + - bone_transforms[1].basis * bone_weight[1] + - bone_transforms[2].basis * bone_weight[2] + - bone_transforms[3].basis * bone_weight[3]; - - float row[3][4] = { - { transform.basis[0][0], transform.basis[0][1], transform.basis[0][2], transform.origin[0] }, - { transform.basis[1][0], transform.basis[1][1], transform.basis[1][2], transform.origin[1] }, - { transform.basis[2][0], transform.basis[2][1], transform.basis[2][2], transform.origin[2] }, - }; - - size_t transform_buffer_offset = i * 12; - - copymem(&buffer[transform_buffer_offset], row, sizeof(row)); - } - } - - storage->_update_skeleton_transform_buffer(transform_buffer, s->array_len * 12); - - //enable transform buffer and bind it - glBindBuffer(GL_ARRAY_BUFFER, storage->resources.skeleton_transform_buffer); - - glEnableVertexAttribArray(INSTANCE_BONE_BASE + 0); - glEnableVertexAttribArray(INSTANCE_BONE_BASE + 1); - glEnableVertexAttribArray(INSTANCE_BONE_BASE + 2); - - glVertexAttribPointer(INSTANCE_BONE_BASE + 0, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 12, (const void *)(sizeof(float) * 4 * 0)); - glVertexAttribPointer(INSTANCE_BONE_BASE + 1, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 12, (const void *)(sizeof(float) * 4 * 1)); - glVertexAttribPointer(INSTANCE_BONE_BASE + 2, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 12, (const void *)(sizeof(float) * 4 * 2)); - - clear_skeleton_buffer = false; - } - } - - if (clear_skeleton_buffer) { - glDisableVertexAttribArray(INSTANCE_BONE_BASE + 0); - glDisableVertexAttribArray(INSTANCE_BONE_BASE + 1); - glDisableVertexAttribArray(INSTANCE_BONE_BASE + 2); - } - - } break; - - case GD_VS::INSTANCE_MULTIMESH: { - RasterizerStorageGLES2::Surface *s = static_cast<RasterizerStorageGLES2::Surface *>(p_element->geometry); - - glBindBuffer(GL_ARRAY_BUFFER, s->vertex_id); - - if (s->index_array_len > 0) { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->index_id); - } - - for (int i = 0; i < GD_VS::ARRAY_MAX - 1; i++) { - if (s->attribs[i].enabled) { - glEnableVertexAttribArray(i); - glVertexAttribPointer(s->attribs[i].index, s->attribs[i].size, s->attribs[i].type, s->attribs[i].normalized, s->attribs[i].stride, CAST_INT_TO_UCHAR_PTR(s->attribs[i].offset)); - } else { - glDisableVertexAttribArray(i); - switch (i) { - case GD_VS::ARRAY_NORMAL: { - glVertexAttrib4f(GD_VS::ARRAY_NORMAL, 0.0, 0.0, 1, 1); - } break; - case GD_VS::ARRAY_COLOR: { - glVertexAttrib4f(GD_VS::ARRAY_COLOR, 1, 1, 1, 1); - - } break; - default: { - } - } - } - } - - // prepare multimesh (disable) - glDisableVertexAttribArray(INSTANCE_ATTRIB_BASE + 0); - glDisableVertexAttribArray(INSTANCE_ATTRIB_BASE + 1); - glDisableVertexAttribArray(INSTANCE_ATTRIB_BASE + 2); - glDisableVertexAttribArray(INSTANCE_ATTRIB_BASE + 3); - glDisableVertexAttribArray(INSTANCE_ATTRIB_BASE + 4); - glDisableVertexAttribArray(INSTANCE_BONE_BASE + 0); - glDisableVertexAttribArray(INSTANCE_BONE_BASE + 1); - glDisableVertexAttribArray(INSTANCE_BONE_BASE + 2); - - } break; - - case GD_VS::INSTANCE_IMMEDIATE: { - } break; - - default: { - } - } -} - -void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) { - switch (p_element->instance->base_type) { - case GD_VS::INSTANCE_MESH: { - RasterizerStorageGLES2::Surface *s = static_cast<RasterizerStorageGLES2::Surface *>(p_element->geometry); - - // drawing - - if (s->index_array_len > 0) { - glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0); - storage->info.render.vertices_count += s->index_array_len; - } else { - glDrawArrays(gl_primitive[s->primitive], 0, s->array_len); - storage->info.render.vertices_count += s->array_len; - } - /* - if (p_element->instance->skeleton.is_valid() && s->attribs[VS::ARRAY_BONES].enabled && s->attribs[VS::ARRAY_WEIGHTS].enabled) { - //clean up after skeleton - glBindBuffer(GL_ARRAY_BUFFER, storage->resources.skeleton_transform_buffer); - - glDisableVertexAttribArray(GD_VS::ARRAY_MAX + 0); - glDisableVertexAttribArray(GD_VS::ARRAY_MAX + 1); - glDisableVertexAttribArray(GD_VS::ARRAY_MAX + 2); - - glVertexAttrib4f(GD_VS::ARRAY_MAX + 0, 1, 0, 0, 0); - glVertexAttrib4f(GD_VS::ARRAY_MAX + 1, 0, 1, 0, 0); - glVertexAttrib4f(GD_VS::ARRAY_MAX + 2, 0, 0, 1, 0); - } -*/ - } break; - - case GD_VS::INSTANCE_MULTIMESH: { - RasterizerStorageGLES2::MultiMesh *multi_mesh = static_cast<RasterizerStorageGLES2::MultiMesh *>(p_element->owner); - RasterizerStorageGLES2::Surface *s = static_cast<RasterizerStorageGLES2::Surface *>(p_element->geometry); - - int amount = MIN(multi_mesh->size, multi_mesh->visible_instances); - - if (amount == -1) { - amount = multi_mesh->size; - } - - int stride = multi_mesh->color_floats + multi_mesh->custom_data_floats + multi_mesh->xform_floats; - - int color_ofs = multi_mesh->xform_floats; - int custom_data_ofs = color_ofs + multi_mesh->color_floats; - - // drawing - - const float *base_buffer = multi_mesh->data.ptr(); - - for (int i = 0; i < amount; i++) { - const float *buffer = base_buffer + i * stride; - - { - glVertexAttrib4fv(INSTANCE_ATTRIB_BASE + 0, &buffer[0]); - glVertexAttrib4fv(INSTANCE_ATTRIB_BASE + 1, &buffer[4]); - glVertexAttrib4fv(INSTANCE_ATTRIB_BASE + 2, &buffer[8]); - } - - if (multi_mesh->color_floats) { - if (multi_mesh->color_format == GD_VS::MULTIMESH_COLOR_8BIT) { - uint8_t *color_data = (uint8_t *)(buffer + color_ofs); - glVertexAttrib4f(INSTANCE_ATTRIB_BASE + 3, color_data[0] / 255.0, color_data[1] / 255.0, color_data[2] / 255.0, color_data[3] / 255.0); - } 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) { - if (multi_mesh->custom_data_format == GD_VS::MULTIMESH_CUSTOM_DATA_8BIT) { - uint8_t *custom_data = (uint8_t *)(buffer + custom_data_ofs); - glVertexAttrib4f(INSTANCE_ATTRIB_BASE + 4, custom_data[0] / 255.0, custom_data[1] / 255.0, custom_data[2] / 255.0, custom_data[3] / 255.0); - } else { - glVertexAttrib4fv(INSTANCE_ATTRIB_BASE + 4, buffer + custom_data_ofs); - } - } - - if (s->index_array_len > 0) { - glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0); - storage->info.render.vertices_count += s->index_array_len; - } else { - glDrawArrays(gl_primitive[s->primitive], 0, s->array_len); - storage->info.render.vertices_count += s->array_len; - } - } - - } break; - - case GD_VS::INSTANCE_IMMEDIATE: { - const RasterizerStorageGLES2::Immediate *im = static_cast<const RasterizerStorageGLES2::Immediate *>(p_element->geometry); - - if (im->building) { - return; - } - - bool restore_tex = false; - - glBindBuffer(GL_ARRAY_BUFFER, state.immediate_buffer); - - for (const List<RasterizerStorageGLES2::Immediate::Chunk>::Element *E = im->chunks.front(); E; E = E->next()) { - const RasterizerStorageGLES2::Immediate::Chunk &c = E->get(); - - if (c.vertices.empty()) { - continue; - } - - int vertices = c.vertices.size(); - - uint32_t buf_ofs = 0; - - storage->info.render.vertices_count += vertices; - - if (c.texture.is_valid() && storage->texture_owner.owns(c.texture)) { - RasterizerStorageGLES2::Texture *t = storage->texture_owner.get(c.texture); - - if (t->redraw_if_visible) { - VisualServerRaster::redraw_request(); - } - t = t->get_ptr(); - -#ifdef TOOLS_ENABLED - if (t->detect_3d) { - t->detect_3d(t->detect_3d_ud); - } -#endif - if (t->render_target) { - t->render_target->used_in_frame = true; - } - - glActiveTexture(GL_TEXTURE0); - glBindTexture(t->target, t->tex_id); - restore_tex = true; - } else if (restore_tex) { - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, state.current_main_tex); - restore_tex = false; - } - - if (!c.normals.empty()) { - glEnableVertexAttribArray(GD_VS::ARRAY_NORMAL); - glBufferSubData(GL_ARRAY_BUFFER, buf_ofs, sizeof(Vector3) * vertices, c.normals.ptr()); - glVertexAttribPointer(GD_VS::ARRAY_NORMAL, 3, GL_FLOAT, GL_FALSE, sizeof(Vector3), CAST_INT_TO_UCHAR_PTR(buf_ofs)); - buf_ofs += sizeof(Vector3) * vertices; - } else { - glDisableVertexAttribArray(GD_VS::ARRAY_NORMAL); - } - - if (!c.tangents.empty()) { - glEnableVertexAttribArray(GD_VS::ARRAY_TANGENT); - glBufferSubData(GL_ARRAY_BUFFER, buf_ofs, sizeof(Plane) * vertices, c.tangents.ptr()); - glVertexAttribPointer(GD_VS::ARRAY_TANGENT, 4, GL_FLOAT, GL_FALSE, sizeof(Plane), CAST_INT_TO_UCHAR_PTR(buf_ofs)); - buf_ofs += sizeof(Plane) * vertices; - } else { - glDisableVertexAttribArray(GD_VS::ARRAY_TANGENT); - } - - if (!c.colors.empty()) { - glEnableVertexAttribArray(GD_VS::ARRAY_COLOR); - glBufferSubData(GL_ARRAY_BUFFER, buf_ofs, sizeof(Color) * vertices, c.colors.ptr()); - glVertexAttribPointer(GD_VS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buf_ofs)); - buf_ofs += sizeof(Color) * vertices; - } else { - glDisableVertexAttribArray(GD_VS::ARRAY_COLOR); - } - - if (!c.uvs.empty()) { - glEnableVertexAttribArray(GD_VS::ARRAY_TEX_UV); - glBufferSubData(GL_ARRAY_BUFFER, buf_ofs, sizeof(Vector2) * vertices, c.uvs.ptr()); - glVertexAttribPointer(GD_VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buf_ofs)); - buf_ofs += sizeof(Vector2) * vertices; - } else { - glDisableVertexAttribArray(GD_VS::ARRAY_TEX_UV); - } - - if (!c.uv2s.empty()) { - glEnableVertexAttribArray(GD_VS::ARRAY_TEX_UV2); - glBufferSubData(GL_ARRAY_BUFFER, buf_ofs, sizeof(Vector2) * vertices, c.uv2s.ptr()); - glVertexAttribPointer(GD_VS::ARRAY_TEX_UV2, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buf_ofs)); - buf_ofs += sizeof(Vector2) * vertices; - } else { - glDisableVertexAttribArray(GD_VS::ARRAY_TEX_UV2); - } - - glEnableVertexAttribArray(GD_VS::ARRAY_VERTEX); - glBufferSubData(GL_ARRAY_BUFFER, buf_ofs, sizeof(Vector3) * vertices, c.vertices.ptr()); - glVertexAttribPointer(GD_VS::ARRAY_VERTEX, 3, GL_FLOAT, GL_FALSE, sizeof(Vector3), CAST_INT_TO_UCHAR_PTR(buf_ofs)); - - glDrawArrays(gl_primitive[c.primitive], 0, c.vertices.size()); - } - - if (restore_tex) { - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, state.current_main_tex); - restore_tex = false; - } - - } break; - default: { - } - } -} - -void RasterizerSceneGLES2::_setup_light_type(LightInstance *p_light, ShadowAtlas *shadow_atlas) { - //turn off all by default - state.scene_shader.set_conditional(SceneShaderGLES2::USE_LIGHTING, false); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_SHADOW, false); - state.scene_shader.set_conditional(SceneShaderGLES2::SHADOW_MODE_PCF_5, false); - state.scene_shader.set_conditional(SceneShaderGLES2::SHADOW_MODE_PCF_13, false); - state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_MODE_DIRECTIONAL, false); - state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_MODE_OMNI, false); - state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_MODE_SPOT, false); - 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); - - if (!p_light) { //no light, return off - return; - } - - //turn on lighting - state.scene_shader.set_conditional(SceneShaderGLES2::USE_LIGHTING, true); - - switch (p_light->light_ptr->type) { - case GD_VS::LIGHT_DIRECTIONAL: { - state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_MODE_DIRECTIONAL, true); - switch (p_light->light_ptr->directional_shadow_mode) { - case GD_VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL: { - //no need - } break; - case GD_VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS: { - state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM2, true); - - } break; - case GD_VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS: { - state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM4, true); - } break; - } - - state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM_BLEND, p_light->light_ptr->directional_blend_splits); - if (!state.render_no_shadows && p_light->light_ptr->shadow) { - state.scene_shader.set_conditional(SceneShaderGLES2::USE_SHADOW, true); - glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 3); - if (storage->config.use_rgba_3d_shadows) { - glBindTexture(GL_TEXTURE_2D, directional_shadow.color); - } else { - glBindTexture(GL_TEXTURE_2D, directional_shadow.depth); - } - state.scene_shader.set_conditional(SceneShaderGLES2::SHADOW_MODE_PCF_5, shadow_filter_mode == SHADOW_FILTER_PCF5); - state.scene_shader.set_conditional(SceneShaderGLES2::SHADOW_MODE_PCF_13, shadow_filter_mode == SHADOW_FILTER_PCF13); - } - - } break; - case GD_VS::LIGHT_OMNI: { - state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_MODE_OMNI, true); - if (!state.render_no_shadows && shadow_atlas && p_light->light_ptr->shadow) { - state.scene_shader.set_conditional(SceneShaderGLES2::USE_SHADOW, true); - glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 3); - if (storage->config.use_rgba_3d_shadows) { - glBindTexture(GL_TEXTURE_2D, shadow_atlas->color); - } else { - glBindTexture(GL_TEXTURE_2D, shadow_atlas->depth); - } - state.scene_shader.set_conditional(SceneShaderGLES2::SHADOW_MODE_PCF_5, shadow_filter_mode == SHADOW_FILTER_PCF5); - state.scene_shader.set_conditional(SceneShaderGLES2::SHADOW_MODE_PCF_13, shadow_filter_mode == SHADOW_FILTER_PCF13); - } - } break; - case GD_VS::LIGHT_SPOT: { - state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_MODE_SPOT, true); - if (!state.render_no_shadows && shadow_atlas && p_light->light_ptr->shadow) { - state.scene_shader.set_conditional(SceneShaderGLES2::USE_SHADOW, true); - glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 3); - if (storage->config.use_rgba_3d_shadows) { - glBindTexture(GL_TEXTURE_2D, shadow_atlas->color); - } else { - glBindTexture(GL_TEXTURE_2D, shadow_atlas->depth); - } - state.scene_shader.set_conditional(SceneShaderGLES2::SHADOW_MODE_PCF_5, shadow_filter_mode == SHADOW_FILTER_PCF5); - state.scene_shader.set_conditional(SceneShaderGLES2::SHADOW_MODE_PCF_13, shadow_filter_mode == SHADOW_FILTER_PCF13); - } - } break; - } -} - -void RasterizerSceneGLES2::_setup_light(LightInstance *light, ShadowAtlas *shadow_atlas, const Transform3D &p_view_transform, bool accum_pass) { - RasterizerStorageGLES2::Light *light_ptr = light->light_ptr; - - //common parameters - float energy = light_ptr->param[VS::LIGHT_PARAM_ENERGY]; - float specular = light_ptr->param[VS::LIGHT_PARAM_SPECULAR]; - float sign = (light_ptr->negative && !accum_pass) ? -1 : 1; //inverse color for base pass lights only - - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SPECULAR, specular); - Color color = light_ptr->color * sign * energy * Math_PI; - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_COLOR, color); - - state.scene_shader.set_uniform(SceneShaderGLES2::SHADOW_COLOR, light_ptr->shadow_color); - - //specific parameters - - switch (light_ptr->type) { - case GD_VS::LIGHT_DIRECTIONAL: { - //not using inverse for performance, view should be normalized anyway - Vector3 direction = p_view_transform.basis.xform_inv(light->transform.basis.xform(Vector3(0, 0, -1))).normalized(); - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_DIRECTION, direction); - - CameraMatrix matrices[4]; - - if (!state.render_no_shadows && light_ptr->shadow && directional_shadow.depth) { - int shadow_count = 0; - Color split_offsets; - - switch (light_ptr->directional_shadow_mode) { - case GD_VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL: { - shadow_count = 1; - } break; - - case GD_VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS: { - shadow_count = 2; - } break; - - case GD_VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS: { - shadow_count = 4; - } break; - } - - for (int k = 0; k < shadow_count; k++) { - uint32_t x = light->directional_rect.position.x; - uint32_t y = light->directional_rect.position.y; - uint32_t width = light->directional_rect.size.x; - uint32_t height = light->directional_rect.size.y; - - if (light_ptr->directional_shadow_mode == GD_VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS) { - width /= 2; - height /= 2; - - if (k == 1) { - x += width; - } else if (k == 2) { - y += height; - } else if (k == 3) { - x += width; - y += height; - } - - } else if (light_ptr->directional_shadow_mode == GD_VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS) { - height /= 2; - - if (k != 0) { - y += height; - } - } - - split_offsets[k] = light->shadow_transform[k].split; - - Transform3D modelview = (p_view_transform.inverse() * light->shadow_transform[k].transform).affine_inverse(); - - CameraMatrix bias; - bias.set_light_bias(); - CameraMatrix rectm; - Rect2 atlas_rect = Rect2(float(x) / directional_shadow.size, float(y) / directional_shadow.size, float(width) / directional_shadow.size, float(height) / directional_shadow.size); - rectm.set_light_atlas_rect(atlas_rect); - - CameraMatrix shadow_mtx = rectm * bias * light->shadow_transform[k].camera * modelview; - matrices[k] = shadow_mtx; - - /*Color light_clamp; - light_clamp[0] = atlas_rect.position.x; - light_clamp[1] = atlas_rect.position.y; - light_clamp[2] = atlas_rect.size.x; - light_clamp[3] = atlas_rect.size.y;*/ - } - - // state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_CLAMP, light_clamp); - state.scene_shader.set_uniform(SceneShaderGLES2::SHADOW_PIXEL_SIZE, Size2(1.0 / directional_shadow.size, 1.0 / directional_shadow.size)); - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SPLIT_OFFSETS, split_offsets); - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX, matrices[0]); - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX2, matrices[1]); - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX3, matrices[2]); - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX4, matrices[3]); - } - } break; - case GD_VS::LIGHT_OMNI: { - Vector3 position = p_view_transform.xform_inv(light->transform.origin); - - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_POSITION, position); - - float range = light_ptr->param[VS::LIGHT_PARAM_RANGE]; - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_RANGE, range); - - float attenuation = light_ptr->param[VS::LIGHT_PARAM_ATTENUATION]; - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_ATTENUATION, attenuation); - - if (!state.render_no_shadows && light_ptr->shadow && shadow_atlas && shadow_atlas->shadow_owners.has(light->self)) { - uint32_t key = shadow_atlas->shadow_owners[light->self]; - - uint32_t quadrant = (key >> ShadowAtlas::QUADRANT_SHIFT) & 0x03; - uint32_t shadow = key & ShadowAtlas::SHADOW_INDEX_MASK; - - ERR_BREAK(shadow >= (uint32_t)shadow_atlas->quadrants[quadrant].shadows.size()); - - uint32_t atlas_size = shadow_atlas->size; - uint32_t quadrant_size = atlas_size >> 1; - - uint32_t x = (quadrant & 1) * quadrant_size; - uint32_t y = (quadrant >> 1) * quadrant_size; - - uint32_t shadow_size = (quadrant_size / shadow_atlas->quadrants[quadrant].subdivision); - x += (shadow % shadow_atlas->quadrants[quadrant].subdivision) * shadow_size; - y += (shadow / shadow_atlas->quadrants[quadrant].subdivision) * shadow_size; - - uint32_t width = shadow_size; - uint32_t height = shadow_size; - - if (light->light_ptr->omni_shadow_detail == GD_VS::LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL) { - height /= 2; - } else { - width /= 2; - } - - Transform3D proj = (p_view_transform.inverse() * light->transform).inverse(); - - Color light_clamp; - light_clamp[0] = float(x) / atlas_size; - light_clamp[1] = float(y) / atlas_size; - light_clamp[2] = float(width) / atlas_size; - light_clamp[3] = float(height) / atlas_size; - - state.scene_shader.set_uniform(SceneShaderGLES2::SHADOW_PIXEL_SIZE, Size2(1.0 / shadow_atlas->size, 1.0 / shadow_atlas->size)); - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX, proj); - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_CLAMP, light_clamp); - } - } break; - - case GD_VS::LIGHT_SPOT: { - Vector3 position = p_view_transform.xform_inv(light->transform.origin); - - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_POSITION, position); - - Vector3 direction = p_view_transform.inverse().basis.xform(light->transform.basis.xform(Vector3(0, 0, -1))).normalized(); - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_DIRECTION, direction); - float attenuation = light_ptr->param[VS::LIGHT_PARAM_ATTENUATION]; - float range = light_ptr->param[VS::LIGHT_PARAM_RANGE]; - float spot_attenuation = light_ptr->param[VS::LIGHT_PARAM_SPOT_ATTENUATION]; - float angle = light_ptr->param[VS::LIGHT_PARAM_SPOT_ANGLE]; - angle = Math::cos(Math::deg2rad(angle)); - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_ATTENUATION, attenuation); - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SPOT_ATTENUATION, spot_attenuation); - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SPOT_RANGE, spot_attenuation); - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SPOT_ANGLE, angle); - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_RANGE, range); - - if (!state.render_no_shadows && light->light_ptr->shadow && shadow_atlas && shadow_atlas->shadow_owners.has(light->self)) { - uint32_t key = shadow_atlas->shadow_owners[light->self]; - - uint32_t quadrant = (key >> ShadowAtlas::QUADRANT_SHIFT) & 0x03; - uint32_t shadow = key & ShadowAtlas::SHADOW_INDEX_MASK; - - ERR_BREAK(shadow >= (uint32_t)shadow_atlas->quadrants[quadrant].shadows.size()); - - uint32_t atlas_size = shadow_atlas->size; - uint32_t quadrant_size = atlas_size >> 1; - - uint32_t x = (quadrant & 1) * quadrant_size; - uint32_t y = (quadrant >> 1) * quadrant_size; - - uint32_t shadow_size = (quadrant_size / shadow_atlas->quadrants[quadrant].subdivision); - x += (shadow % shadow_atlas->quadrants[quadrant].subdivision) * shadow_size; - y += (shadow / shadow_atlas->quadrants[quadrant].subdivision) * shadow_size; - - uint32_t width = shadow_size; - uint32_t height = shadow_size; - - Rect2 rect(float(x) / atlas_size, float(y) / atlas_size, float(width) / atlas_size, float(height) / atlas_size); - - Color light_clamp; - light_clamp[0] = rect.position.x; - light_clamp[1] = rect.position.y; - light_clamp[2] = rect.size.x; - light_clamp[3] = rect.size.y; - - Transform3D modelview = (p_view_transform.inverse() * light->transform).inverse(); - - CameraMatrix bias; - bias.set_light_bias(); - - CameraMatrix rectm; - rectm.set_light_atlas_rect(rect); - - CameraMatrix shadow_matrix = rectm * bias * light->shadow_transform[0].camera * modelview; - - state.scene_shader.set_uniform(SceneShaderGLES2::SHADOW_PIXEL_SIZE, Size2(1.0 / shadow_atlas->size, 1.0 / shadow_atlas->size)); - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX, shadow_matrix); - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_CLAMP, light_clamp); - } - - } break; - default: { - } - } -} - -void RasterizerSceneGLES2::_setup_refprobes(ReflectionProbeInstance *p_refprobe1, ReflectionProbeInstance *p_refprobe2, const Transform3D &p_view_transform, Environment *p_env) { - if (p_refprobe1) { - state.scene_shader.set_uniform(SceneShaderGLES2::REFPROBE1_USE_BOX_PROJECT, p_refprobe1->probe_ptr->box_projection); - state.scene_shader.set_uniform(SceneShaderGLES2::REFPROBE1_BOX_EXTENTS, p_refprobe1->probe_ptr->extents); - state.scene_shader.set_uniform(SceneShaderGLES2::REFPROBE1_BOX_OFFSET, p_refprobe1->probe_ptr->origin_offset); - state.scene_shader.set_uniform(SceneShaderGLES2::REFPROBE1_EXTERIOR, !p_refprobe1->probe_ptr->interior); - state.scene_shader.set_uniform(SceneShaderGLES2::REFPROBE1_INTENSITY, p_refprobe1->probe_ptr->intensity); - - Color ambient; - if (p_refprobe1->probe_ptr->interior) { - ambient = p_refprobe1->probe_ptr->interior_ambient * p_refprobe1->probe_ptr->interior_ambient_energy; - ambient.a = p_refprobe1->probe_ptr->interior_ambient_probe_contrib; - } else if (p_env) { - ambient = p_env->ambient_color * p_env->ambient_energy; - ambient.a = p_env->ambient_sky_contribution; - } - - state.scene_shader.set_uniform(SceneShaderGLES2::REFPROBE1_AMBIENT, ambient); - - Transform3D proj = (p_view_transform.inverse() * p_refprobe1->transform).affine_inverse(); - - state.scene_shader.set_uniform(SceneShaderGLES2::REFPROBE1_LOCAL_MATRIX, proj); - } - - if (p_refprobe2) { - state.scene_shader.set_uniform(SceneShaderGLES2::REFPROBE2_USE_BOX_PROJECT, p_refprobe2->probe_ptr->box_projection); - state.scene_shader.set_uniform(SceneShaderGLES2::REFPROBE2_BOX_EXTENTS, p_refprobe2->probe_ptr->extents); - state.scene_shader.set_uniform(SceneShaderGLES2::REFPROBE2_BOX_OFFSET, p_refprobe2->probe_ptr->origin_offset); - state.scene_shader.set_uniform(SceneShaderGLES2::REFPROBE2_EXTERIOR, p_refprobe2->probe_ptr->interior); - state.scene_shader.set_uniform(SceneShaderGLES2::REFPROBE2_INTENSITY, p_refprobe2->probe_ptr->intensity); - - Color ambient; - if (p_refprobe2->probe_ptr->interior) { - ambient = p_refprobe2->probe_ptr->interior_ambient * p_refprobe2->probe_ptr->interior_ambient_energy; - ambient.a = p_refprobe2->probe_ptr->interior_ambient_probe_contrib; - } else if (p_env) { - ambient = p_env->ambient_color * p_env->ambient_energy; - ambient.a = p_env->ambient_sky_contribution; - } - - state.scene_shader.set_uniform(SceneShaderGLES2::REFPROBE2_AMBIENT, ambient); - - Transform3D proj = (p_view_transform.inverse() * p_refprobe2->transform).affine_inverse(); - - state.scene_shader.set_uniform(SceneShaderGLES2::REFPROBE2_LOCAL_MATRIX, proj); - } -} - -void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements, int p_element_count, const Transform3D &p_view_transform, const CameraMatrix &p_projection, RID p_shadow_atlas, Environment *p_env, GLuint p_base_env, float p_shadow_bias, float p_shadow_normal_bias, bool p_reverse_cull, bool p_alpha_pass, bool p_shadow) { - ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_shadow_atlas); - - Vector2 viewport_size = state.viewport_size; - - Vector2 screen_pixel_size = state.screen_pixel_size; - - bool use_radiance_map = false; - if (!p_shadow && p_base_env) { - glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 2); - glBindTexture(GL_TEXTURE_CUBE_MAP, p_base_env); - use_radiance_map = true; - state.scene_shader.set_conditional(SceneShaderGLES2::USE_RADIANCE_MAP, true); //since prev unshaded is false, this needs to be true if exists - } - - bool prev_unshaded = false; - bool prev_instancing = false; - bool prev_depth_prepass = false; - state.scene_shader.set_conditional(SceneShaderGLES2::SHADELESS, false); - RasterizerStorageGLES2::Material *prev_material = NULL; - RasterizerStorageGLES2::Geometry *prev_geometry = NULL; - RasterizerStorageGLES2::Skeleton *prev_skeleton = NULL; - RasterizerStorageGLES2::GeometryOwner *prev_owner = NULL; - - Transform3D view_transform_inverse = p_view_transform.inverse(); - CameraMatrix projection_inverse = p_projection.inverse(); - - bool prev_base_pass = false; - LightInstance *prev_light = NULL; - bool prev_vertex_lit = false; - ReflectionProbeInstance *prev_refprobe_1 = NULL; - ReflectionProbeInstance *prev_refprobe_2 = NULL; - - int prev_blend_mode = -2; //will always catch the first go - - state.cull_front = false; - state.cull_disabled = false; - glCullFace(GL_BACK); - glEnable(GL_CULL_FACE); - - if (p_alpha_pass) { - glEnable(GL_BLEND); - } else { - glDisable(GL_BLEND); - } - - float fog_max_distance = 0; - bool using_fog = false; - if (p_env && !p_shadow && p_env->fog_enabled && (p_env->fog_depth_enabled || p_env->fog_height_enabled)) { - state.scene_shader.set_conditional(SceneShaderGLES2::FOG_DEPTH_ENABLED, p_env->fog_depth_enabled); - state.scene_shader.set_conditional(SceneShaderGLES2::FOG_HEIGHT_ENABLED, p_env->fog_height_enabled); - if (p_env->fog_depth_end > 0) { - fog_max_distance = p_env->fog_depth_end; - } else { - fog_max_distance = p_projection.get_z_far(); - } - using_fog = true; - } - - RasterizerStorageGLES2::Texture *prev_lightmap = NULL; - float lightmap_energy = 1.0; - bool prev_use_lightmap_capture = false; - - storage->info.render.draw_call_count += p_element_count; - - for (int i = 0; i < p_element_count; i++) { - RenderList::Element *e = p_elements[i]; - - RasterizerStorageGLES2::Material *material = e->material; - - bool rebind = false; - bool accum_pass = *e->use_accum_ptr; - *e->use_accum_ptr = true; //set to accum for next time this is found - LightInstance *light = NULL; - ReflectionProbeInstance *refprobe_1 = NULL; - ReflectionProbeInstance *refprobe_2 = NULL; - RasterizerStorageGLES2::Texture *lightmap = NULL; - bool use_lightmap_capture = false; - bool rebind_light = false; - bool rebind_reflection = false; - bool rebind_lightmap = false; - - if (!p_shadow && material->shader) { - bool unshaded = material->shader->spatial.unshaded; - - if (unshaded != prev_unshaded) { - rebind = true; - if (unshaded) { - state.scene_shader.set_conditional(SceneShaderGLES2::SHADELESS, true); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_RADIANCE_MAP, false); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_LIGHTING, false); - } else { - state.scene_shader.set_conditional(SceneShaderGLES2::SHADELESS, false); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_RADIANCE_MAP, use_radiance_map); - } - - prev_unshaded = unshaded; - } - - bool base_pass = !accum_pass && !unshaded; //conditions for a base pass - - if (base_pass != prev_base_pass) { - state.scene_shader.set_conditional(SceneShaderGLES2::BASE_PASS, base_pass); - rebind = true; - prev_base_pass = base_pass; - } - - if (!unshaded && e->light_index < RenderList::MAX_LIGHTS) { - light = render_light_instances[e->light_index]; - if (e->light_mode == LightMode::LIGHTMODE_LIGHTMAP && light->light_ptr->bake_mode == GD_VS::LIGHT_BAKE_ALL) { - light = NULL; // Don't use this light, it is already included in the lightmap - } - } - - if (light != prev_light) { - _setup_light_type(light, shadow_atlas); - rebind = true; - rebind_light = true; - } - - int blend_mode = p_alpha_pass ? material->shader->spatial.blend_mode : -1; // -1 no blend, no mix - - if (accum_pass) { //accum pass force pass - blend_mode = RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_ADD; - if (light && light->light_ptr->negative) { - blend_mode = RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_SUB; - } - } - - if (prev_blend_mode != blend_mode) { - if (prev_blend_mode == -1 && blend_mode != -1) { - //does blend - glEnable(GL_BLEND); - } else if (blend_mode == -1 && prev_blend_mode != -1) { - //do not blend - glDisable(GL_BLEND); - } - - switch (blend_mode) { - //-1 not handled because not blend is enabled anyway - case RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_MIX: { - glBlendEquation(GL_FUNC_ADD); - if (storage->frame.current_rt && storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_TRANSPARENT]) { - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - } else { - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - - } break; - case RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_ADD: { - glBlendEquation(GL_FUNC_ADD); - glBlendFunc(p_alpha_pass ? GL_SRC_ALPHA : GL_ONE, GL_ONE); - - } break; - case RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_SUB: { - glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - } break; - case RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_MUL: { - glBlendEquation(GL_FUNC_ADD); - if (storage->frame.current_rt && storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_TRANSPARENT]) { - glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_DST_ALPHA, GL_ZERO); - } else { - glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_ZERO, GL_ONE); - } - - } break; - } - - prev_blend_mode = blend_mode; - } - - //condition to enable vertex lighting on this object - bool vertex_lit = (material->shader->spatial.uses_vertex_lighting || storage->config.force_vertex_shading) && ((!unshaded && light) || using_fog); //fog forces vertex lighting because it still applies even if unshaded or no fog - - if (vertex_lit != prev_vertex_lit) { - state.scene_shader.set_conditional(SceneShaderGLES2::USE_VERTEX_LIGHTING, vertex_lit); - prev_vertex_lit = vertex_lit; - rebind = true; - } - - if (!unshaded && !accum_pass && e->refprobe_0_index != RenderList::MAX_REFLECTION_PROBES) { - ERR_FAIL_INDEX(e->refprobe_0_index, reflection_probe_count); - refprobe_1 = reflection_probe_instances[e->refprobe_0_index]; - } - if (!unshaded && !accum_pass && e->refprobe_1_index != RenderList::MAX_REFLECTION_PROBES) { - ERR_FAIL_INDEX(e->refprobe_1_index, reflection_probe_count); - refprobe_2 = reflection_probe_instances[e->refprobe_1_index]; - } - - if (refprobe_1 != prev_refprobe_1 || refprobe_2 != prev_refprobe_2) { - state.scene_shader.set_conditional(SceneShaderGLES2::USE_REFLECTION_PROBE1, refprobe_1 != NULL); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_REFLECTION_PROBE2, refprobe_2 != NULL); - if (refprobe_1 != NULL && refprobe_1 != prev_refprobe_1) { - glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 5); - glBindTexture(GL_TEXTURE_CUBE_MAP, refprobe_1->cubemap); - } - if (refprobe_2 != NULL && refprobe_2 != prev_refprobe_2) { - glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 6); - glBindTexture(GL_TEXTURE_CUBE_MAP, refprobe_2->cubemap); - } - rebind = true; - rebind_reflection = true; - } - - use_lightmap_capture = !unshaded && !accum_pass && !e->instance->lightmap_capture_data.empty(); - - if (use_lightmap_capture != prev_use_lightmap_capture) { - state.scene_shader.set_conditional(SceneShaderGLES2::USE_LIGHTMAP_CAPTURE, use_lightmap_capture); - rebind = true; - } - - if (!unshaded && !accum_pass && e->instance->lightmap.is_valid()) { - lightmap = storage->texture_owner.getornull(e->instance->lightmap); - lightmap_energy = 1.0; - if (lightmap) { - RasterizerStorageGLES2::LightmapCapture *capture = storage->lightmap_capture_data_owner.getornull(e->instance->lightmap_capture->base); - if (capture) { - lightmap_energy = capture->energy; - } - } - } - - if (lightmap != prev_lightmap) { - state.scene_shader.set_conditional(SceneShaderGLES2::USE_LIGHTMAP, lightmap != NULL); - if (lightmap != NULL) { - glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 4); - glBindTexture(GL_TEXTURE_2D, lightmap->tex_id); - } - rebind = true; - rebind_lightmap = true; - } - } - - bool depth_prepass = false; - - if (!p_alpha_pass && material->shader->spatial.depth_draw_mode == RasterizerStorageGLES2::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS) { - depth_prepass = true; - } - - if (depth_prepass != prev_depth_prepass) { - state.scene_shader.set_conditional(SceneShaderGLES2::USE_DEPTH_PREPASS, depth_prepass); - prev_depth_prepass = depth_prepass; - rebind = true; - } - - bool instancing = e->instance->base_type == GD_VS::INSTANCE_MULTIMESH; - - if (instancing != prev_instancing) { - state.scene_shader.set_conditional(SceneShaderGLES2::USE_INSTANCING, instancing); - rebind = true; - } - - RasterizerStorageGLES2::Skeleton *skeleton = storage->skeleton_owner.getornull(e->instance->skeleton); - - if (skeleton != prev_skeleton) { - if ((prev_skeleton == NULL) != (skeleton == NULL)) { - if (skeleton) { - state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON, true); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON_SOFTWARE, storage->config.use_skeleton_software); - } else { - state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON, false); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON_SOFTWARE, false); - } - } - rebind = true; - } - - if (e->owner != prev_owner || e->geometry != prev_geometry || skeleton != prev_skeleton) { - _setup_geometry(e, skeleton); - storage->info.render.surface_switch_count++; - } - - bool shader_rebind = false; - if (rebind || material != prev_material) { - storage->info.render.material_switch_count++; - shader_rebind = _setup_material(material, p_alpha_pass, Size2i(skeleton ? skeleton->size * 3 : 0, 0)); - if (shader_rebind) { - storage->info.render.shader_rebind_count++; - } - } - - _set_cull(e->front_facing, material->shader->spatial.cull_mode == RasterizerStorageGLES2::Shader::Spatial::CULL_MODE_DISABLED, p_reverse_cull); - - if (i == 0 || shader_rebind) { //first time must rebind - - if (p_shadow) { - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_BIAS, p_shadow_bias); - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_NORMAL_BIAS, p_shadow_normal_bias); - if (state.shadow_is_dual_parabolloid) { - state.scene_shader.set_uniform(SceneShaderGLES2::SHADOW_DUAL_PARABOLOID_RENDER_SIDE, state.dual_parbolloid_direction); - state.scene_shader.set_uniform(SceneShaderGLES2::SHADOW_DUAL_PARABOLOID_RENDER_ZFAR, state.dual_parbolloid_zfar); - } - } else { - if (use_radiance_map) { - if (p_env) { - Transform3D 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 don't have this... - state.scene_shader.set_uniform(SceneShaderGLES2::RADIANCE_INVERSE_XFORM, p_view_transform); - } - } - - if (p_env) { - state.scene_shader.set_uniform(SceneShaderGLES2::BG_ENERGY, p_env->bg_energy); - state.scene_shader.set_uniform(SceneShaderGLES2::BG_COLOR, p_env->bg_color); - state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_SKY_CONTRIBUTION, p_env->ambient_sky_contribution); - - state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_COLOR, p_env->ambient_color); - state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_ENERGY, p_env->ambient_energy); - - } else { - state.scene_shader.set_uniform(SceneShaderGLES2::BG_ENERGY, 1.0); - state.scene_shader.set_uniform(SceneShaderGLES2::BG_COLOR, state.default_bg); - state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_SKY_CONTRIBUTION, 1.0); - state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_COLOR, state.default_ambient); - state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_ENERGY, 1.0); - } - - //rebind all these - rebind_light = true; - rebind_reflection = true; - rebind_lightmap = true; - - if (using_fog) { - state.scene_shader.set_uniform(SceneShaderGLES2::FOG_COLOR_BASE, p_env->fog_color); - Color sun_color_amount = p_env->fog_sun_color; - sun_color_amount.a = p_env->fog_sun_amount; - - state.scene_shader.set_uniform(SceneShaderGLES2::FOG_SUN_COLOR_AMOUNT, sun_color_amount); - state.scene_shader.set_uniform(SceneShaderGLES2::FOG_TRANSMIT_ENABLED, p_env->fog_transmit_enabled); - state.scene_shader.set_uniform(SceneShaderGLES2::FOG_TRANSMIT_CURVE, p_env->fog_transmit_curve); - - if (p_env->fog_depth_enabled) { - state.scene_shader.set_uniform(SceneShaderGLES2::FOG_DEPTH_BEGIN, p_env->fog_depth_begin); - state.scene_shader.set_uniform(SceneShaderGLES2::FOG_DEPTH_CURVE, p_env->fog_depth_curve); - state.scene_shader.set_uniform(SceneShaderGLES2::FOG_MAX_DISTANCE, fog_max_distance); - } - - if (p_env->fog_height_enabled) { - state.scene_shader.set_uniform(SceneShaderGLES2::FOG_HEIGHT_MIN, p_env->fog_height_min); - state.scene_shader.set_uniform(SceneShaderGLES2::FOG_HEIGHT_MAX, p_env->fog_height_max); - state.scene_shader.set_uniform(SceneShaderGLES2::FOG_HEIGHT_MAX, p_env->fog_height_max); - state.scene_shader.set_uniform(SceneShaderGLES2::FOG_HEIGHT_CURVE, p_env->fog_height_curve); - } - } - } - - state.scene_shader.set_uniform(SceneShaderGLES2::CAMERA_MATRIX, p_view_transform); - state.scene_shader.set_uniform(SceneShaderGLES2::CAMERA_INVERSE_MATRIX, view_transform_inverse); - state.scene_shader.set_uniform(SceneShaderGLES2::PROJECTION_MATRIX, p_projection); - state.scene_shader.set_uniform(SceneShaderGLES2::PROJECTION_INVERSE_MATRIX, projection_inverse); - - state.scene_shader.set_uniform(SceneShaderGLES2::TIME, storage->frame.time[0]); - - state.scene_shader.set_uniform(SceneShaderGLES2::VIEWPORT_SIZE, viewport_size); - - state.scene_shader.set_uniform(SceneShaderGLES2::SCREEN_PIXEL_SIZE, screen_pixel_size); - } - - if (rebind_light && light) { - _setup_light(light, shadow_atlas, p_view_transform, accum_pass); - } - - if (rebind_reflection && (refprobe_1 || refprobe_2)) { - _setup_refprobes(refprobe_1, refprobe_2, p_view_transform, p_env); - } - - if (rebind_lightmap && lightmap) { - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHTMAP_ENERGY, lightmap_energy); - } - - state.scene_shader.set_uniform(SceneShaderGLES2::WORLD_TRANSFORM, e->instance->transform); - - if (use_lightmap_capture) { //this is per instance, must be set always if present - glUniform4fv(state.scene_shader.get_uniform_location(SceneShaderGLES2::LIGHTMAP_CAPTURES), 12, (const GLfloat *)e->instance->lightmap_capture_data.ptr()); - state.scene_shader.set_uniform(SceneShaderGLES2::LIGHTMAP_CAPTURE_SKY, false); - } - - _render_geometry(e); - - prev_geometry = e->geometry; - prev_owner = e->owner; - prev_material = material; - prev_skeleton = skeleton; - prev_instancing = instancing; - prev_light = light; - prev_refprobe_1 = refprobe_1; - prev_refprobe_2 = refprobe_2; - prev_lightmap = lightmap; - prev_use_lightmap_capture = use_lightmap_capture; - } - - _setup_light_type(NULL, NULL); //clear light stuff - state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON, false); - state.scene_shader.set_conditional(SceneShaderGLES2::SHADELESS, false); - state.scene_shader.set_conditional(SceneShaderGLES2::BASE_PASS, false); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_INSTANCING, false); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_RADIANCE_MAP, false); - state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM4, false); - state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM2, false); - state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM_BLEND, false); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_VERTEX_LIGHTING, false); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_REFLECTION_PROBE1, false); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_REFLECTION_PROBE2, false); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_LIGHTMAP, false); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_LIGHTMAP_CAPTURE, false); - state.scene_shader.set_conditional(SceneShaderGLES2::FOG_DEPTH_ENABLED, false); - state.scene_shader.set_conditional(SceneShaderGLES2::FOG_HEIGHT_ENABLED, false); - state.scene_shader.set_conditional(SceneShaderGLES2::USE_DEPTH_PREPASS, false); -} - -void RasterizerSceneGLES2::_draw_sky(RasterizerStorageGLES2::Sky *p_sky, const CameraMatrix &p_projection, const Transform3D &p_transform, bool p_vflip, float p_custom_fov, float p_energy, const Basis &p_sky_orientation) { - ERR_FAIL_COND(!p_sky); - - RasterizerStorageGLES2::Texture *tex = storage->texture_owner.getornull(p_sky->panorama); - ERR_FAIL_COND(!tex); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(tex->target, tex->tex_id); - - glDepthMask(GL_TRUE); - glEnable(GL_DEPTH_TEST); - glDisable(GL_CULL_FACE); - glDisable(GL_BLEND); - glDepthFunc(GL_LEQUAL); - - // Camera - CameraMatrix camera; - - if (p_custom_fov) { - float near_plane = p_projection.get_z_near(); - float far_plane = p_projection.get_z_far(); - float aspect = p_projection.get_aspect(); - - camera.set_perspective(p_custom_fov, aspect, near_plane, far_plane); - } else { - camera = p_projection; - } - - float flip_sign = p_vflip ? -1 : 1; - - // If matrix[2][0] or matrix[2][1] we're dealing with an asymmetrical projection matrix. This is the case for stereoscopic rendering (i.e. VR). - // To ensure the image rendered is perspective correct we need to move some logic into the shader. For this the USE_ASYM_PANO option is introduced. - // It also means the uv coordinates are ignored in this mode and we don't need our loop. - bool asymmetrical = ((camera.matrix[2][0] != 0.0) || (camera.matrix[2][1] != 0.0)); - - Vector3 vertices[8] = { - Vector3(-1, -1 * flip_sign, 1), - Vector3(0, 1, 0), - Vector3(1, -1 * flip_sign, 1), - Vector3(1, 1, 0), - Vector3(1, 1 * flip_sign, 1), - Vector3(1, 0, 0), - Vector3(-1, 1 * flip_sign, 1), - Vector3(0, 0, 0), - }; - - if (!asymmetrical) { - 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) * 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; - } - } - - glBindBuffer(GL_ARRAY_BUFFER, state.sky_verts); - glBufferData(GL_ARRAY_BUFFER, sizeof(Vector3) * 8, vertices, GL_DYNAMIC_DRAW); - - // bind sky vertex array.... - glVertexAttribPointer(GD_VS::ARRAY_VERTEX, 3, GL_FLOAT, GL_FALSE, sizeof(Vector3) * 2, 0); - glVertexAttribPointer(GD_VS::ARRAY_TEX_UV, 3, GL_FLOAT, GL_FALSE, sizeof(Vector3) * 2, CAST_INT_TO_UCHAR_PTR(sizeof(Vector3))); - glEnableVertexAttribArray(GD_VS::ARRAY_VERTEX); - glEnableVertexAttribArray(GD_VS::ARRAY_TEX_UV); - - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_ASYM_PANO, asymmetrical); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_PANORAMA, !asymmetrical); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_MULTIPLIER, true); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_CUBEMAP, false); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_COPY_SECTION, false); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_CUSTOM_ALPHA, false); - storage->shaders.copy.bind(); - storage->shaders.copy.set_uniform(CopyShaderGLES2::MULTIPLIER, p_energy); - - // don't know why but I always have problems setting a uniform mat3, so we're using a transform - storage->shaders.copy.set_uniform(CopyShaderGLES2::SKY_TRANSFORM, Transform3D(p_sky_orientation, Vector3(0.0, 0.0, 0.0)).affine_inverse()); - - if (asymmetrical) { - // pack the bits we need from our projection matrix - storage->shaders.copy.set_uniform(CopyShaderGLES2::ASYM_PROJ, camera.matrix[2][0], camera.matrix[0][0], camera.matrix[2][1], camera.matrix[1][1]); - ///@TODO I couldn't get mat3 + p_transform.basis to work, that would be better here. - storage->shaders.copy.set_uniform(CopyShaderGLES2::PANO_TRANSFORM, p_transform); - } - - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - - glDisableVertexAttribArray(GD_VS::ARRAY_VERTEX); - glDisableVertexAttribArray(GD_VS::ARRAY_TEX_UV); - glBindBuffer(GL_ARRAY_BUFFER, 0); - - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_ASYM_PANO, false); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_PANORAMA, false); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_MULTIPLIER, false); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_CUBEMAP, false); -} - -void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p_cam_projection) { - //copy to front buffer - - glDepthMask(GL_FALSE); - glDisable(GL_DEPTH_TEST); - glDisable(GL_CULL_FACE); - glDisable(GL_BLEND); - glDepthFunc(GL_LEQUAL); - glColorMask(1, 1, 1, 1); - - //no post process on small, transparent or render targets without an env - bool use_post_process = env && !storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_TRANSPARENT]; - use_post_process = use_post_process && storage->frame.current_rt->width >= 4 && storage->frame.current_rt->height >= 4; - use_post_process = use_post_process && storage->frame.current_rt->mip_maps_allocated; - - if (env) { - use_post_process = use_post_process && (env->adjustments_enabled || env->glow_enabled || env->dof_blur_far_enabled || env->dof_blur_near_enabled); - } - use_post_process = use_post_process || storage->frame.current_rt->use_fxaa; - - GLuint next_buffer; - - 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; - } - - // If using multisample buffer, resolve to post_process_effect buffer or to front buffer - if (storage->frame.current_rt && storage->frame.current_rt->multisample_active) { -#ifdef GLES_OVER_GL - - glBindFramebuffer(GL_READ_FRAMEBUFFER, storage->frame.current_rt->multisample_fbo); - glReadBuffer(GL_COLOR_ATTACHMENT0); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, next_buffer); - glBlitFramebuffer(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, 0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); - - glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); -#elif IPHONE_ENABLED - - glBindFramebuffer(GL_READ_FRAMEBUFFER, storage->frame.current_rt->multisample_fbo); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, next_buffer); - glResolveMultisampleFramebufferAPPLE(); - - glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); -#elif ANDROID_ENABLED - - // 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) { - 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) { - return; - } - - // Order of operation - //1) DOF Blur (first blur, then copy to buffer applying the blur) //only on desktop - //2) FXAA - //3) Bloom (Glow) //only on desktop - //4) Adjustments - - // DOF Blur - - if (env && env->dof_blur_far_enabled) { - int vp_h = storage->frame.current_rt->height; - int vp_w = storage->frame.current_rt->width; - - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::USE_ORTHOGONAL_PROJECTION, p_cam_projection.is_orthogonal()); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_FAR_BLUR, true); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_LOW, env->dof_blur_far_quality == GD_VS::ENV_DOF_BLUR_QUALITY_LOW); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_MEDIUM, env->dof_blur_far_quality == GD_VS::ENV_DOF_BLUR_QUALITY_MEDIUM); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_HIGH, env->dof_blur_far_quality == GD_VS::ENV_DOF_BLUR_QUALITY_HIGH); - - state.effect_blur_shader.bind(); - int qsteps[3] = { 4, 10, 20 }; - - float radius = (env->dof_blur_far_amount * env->dof_blur_far_amount) / qsteps[env->dof_blur_far_quality]; - - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::DOF_BEGIN, env->dof_blur_far_distance); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::DOF_END, env->dof_blur_far_distance + env->dof_blur_far_transition); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::DOF_DIR, Vector2(1, 0)); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::DOF_RADIUS, radius); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h)); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::CAMERA_Z_NEAR, p_cam_projection.get_z_near()); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::CAMERA_Z_FAR, p_cam_projection.get_z_far()); - - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->depth); - - glActiveTexture(GL_TEXTURE0); - - if (storage->frame.current_rt->mip_maps[0].color) { - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->mip_maps[0].color); - } else { - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->mip_maps[0].sizes[0].color); - } - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_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); - - glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo); //copy to front first - - storage->_copy_screen(); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::DOF_DIR, Vector2(0, 1)); - glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->mip_maps[0].sizes[0].fbo); // copy to base level - storage->_copy_screen(); - - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_FAR_BLUR, false); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_LOW, false); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_MEDIUM, false); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_HIGH, false); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::USE_ORTHOGONAL_PROJECTION, false); - } - - if (env && env->dof_blur_near_enabled) { - //convert texture to RGBA format if not already - if (!storage->frame.current_rt->used_dof_blur_near) { - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, storage->frame.current_rt->width, storage->frame.current_rt->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - } - - int vp_h = storage->frame.current_rt->height; - int vp_w = storage->frame.current_rt->width; - - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::USE_ORTHOGONAL_PROJECTION, p_cam_projection.is_orthogonal()); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_NEAR_BLUR, true); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_NEAR_FIRST_TAP, true); - - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_LOW, env->dof_blur_near_quality == GD_VS::ENV_DOF_BLUR_QUALITY_LOW); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_MEDIUM, env->dof_blur_near_quality == GD_VS::ENV_DOF_BLUR_QUALITY_MEDIUM); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_HIGH, env->dof_blur_near_quality == GD_VS::ENV_DOF_BLUR_QUALITY_HIGH); - - state.effect_blur_shader.bind(); - int qsteps[3] = { 4, 10, 20 }; - - float radius = (env->dof_blur_near_amount * env->dof_blur_near_amount) / qsteps[env->dof_blur_near_quality]; - - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::DOF_BEGIN, env->dof_blur_near_distance); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::DOF_END, env->dof_blur_near_distance - env->dof_blur_near_transition); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::DOF_DIR, Vector2(1, 0)); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::DOF_RADIUS, radius); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h)); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::CAMERA_Z_NEAR, p_cam_projection.get_z_near()); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::CAMERA_Z_FAR, p_cam_projection.get_z_far()); - - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->depth); - - glActiveTexture(GL_TEXTURE0); - if (storage->frame.current_rt->mip_maps[0].color) { - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->mip_maps[0].color); - } else { - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->mip_maps[0].sizes[0].color); - } - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_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); - - glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo); //copy to front first - - storage->_copy_screen(); - - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_NEAR_FIRST_TAP, false); - state.effect_blur_shader.bind(); - - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::DOF_BEGIN, env->dof_blur_near_distance); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::DOF_END, env->dof_blur_near_distance - env->dof_blur_near_transition); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::DOF_DIR, Vector2(0, 1)); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::DOF_RADIUS, radius); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h)); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::CAMERA_Z_NEAR, p_cam_projection.get_z_near()); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::CAMERA_Z_FAR, p_cam_projection.get_z_far()); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color); - - glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->mip_maps[0].sizes[0].fbo); // copy to base level - - glEnable(GL_BLEND); - glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - storage->_copy_screen(); - - glDisable(GL_BLEND); - - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_NEAR_BLUR, false); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_NEAR_FIRST_TAP, false); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_LOW, false); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_MEDIUM, false); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::DOF_QUALITY_HIGH, false); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::USE_ORTHOGONAL_PROJECTION, false); - storage->frame.current_rt->used_dof_blur_near = true; - } - - if (env && (env->dof_blur_near_enabled || env->dof_blur_far_enabled)) { - //these needed to disable filtering, reenamble - glActiveTexture(GL_TEXTURE0); - if (storage->frame.current_rt->mip_maps[0].color) { - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->mip_maps[0].color); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - } else { - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->mip_maps[0].sizes[0].color); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - } - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - } - - //glow - - int max_glow_level = -1; - int glow_mask = 0; - - if (env && env->glow_enabled) { - for (int i = 0; i < GD_VS::MAX_GLOW_LEVELS; i++) { - if (env->glow_levels & (1 << i)) { - if (i >= storage->frame.current_rt->mip_maps[1].sizes.size()) { - max_glow_level = storage->frame.current_rt->mip_maps[1].sizes.size() - 1; - glow_mask |= 1 << max_glow_level; - - } else { - max_glow_level = i; - glow_mask |= (1 << i); - } - } - } - - // If max_texture_image_units is 8, our max glow level is 5, which allows 6 layers of glow - max_glow_level = MIN(max_glow_level, storage->config.max_texture_image_units - 3); - - for (int i = 0; i < (max_glow_level + 1); i++) { - int vp_w = storage->frame.current_rt->mip_maps[1].sizes[i].width; - int vp_h = storage->frame.current_rt->mip_maps[1].sizes[i].height; - glViewport(0, 0, vp_w, vp_h); - //horizontal pass - if (i == 0) { - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::GLOW_FIRST_PASS, true); - } - - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::GLOW_GAUSSIAN_HORIZONTAL, true); - state.effect_blur_shader.bind(); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h)); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::LOD, storage->frame.current_rt->mip_maps[0].color ? float(i) : 0.0); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::GLOW_STRENGTH, env->glow_strength); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::LUMINANCE_CAP, env->glow_hdr_luminance_cap); - - glActiveTexture(GL_TEXTURE0); - - if (storage->frame.current_rt->mip_maps[0].color) { - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->mip_maps[0].color); - } else { - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->mip_maps[0].sizes[i].color); - } - - if (i == 0) { - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::GLOW_BLOOM, env->glow_bloom); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::GLOW_HDR_THRESHOLD, env->glow_hdr_bleed_threshold); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::GLOW_HDR_SCALE, env->glow_hdr_bleed_scale); - } - - glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->mip_maps[1].sizes[i].fbo); - storage->_copy_screen(); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::GLOW_GAUSSIAN_HORIZONTAL, false); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::GLOW_FIRST_PASS, false); - - //vertical pass - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::GLOW_GAUSSIAN_VERTICAL, true); - state.effect_blur_shader.bind(); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h)); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::LOD, storage->frame.current_rt->mip_maps[0].color ? float(i) : 0.0); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES2::GLOW_STRENGTH, env->glow_strength); - glActiveTexture(GL_TEXTURE0); - - if (storage->frame.current_rt->mip_maps[0].color) { - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->mip_maps[1].color); - } else { - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->mip_maps[1].sizes[i].color); - } - - glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->mip_maps[0].sizes[i + 1].fbo); //next level, since mipmaps[0] starts one level bigger - storage->_copy_screen(); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES2::GLOW_GAUSSIAN_VERTICAL, false); - } - - glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height); - } - - if (storage->frame.current_rt->external.fbo != 0) { - glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->external.fbo); - } else { - glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo); - } - - glActiveTexture(GL_TEXTURE0); - if (storage->frame.current_rt->mip_maps[0].color) { - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->mip_maps[0].color); - } else { - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->mip_maps[0].sizes[0].color); - } - - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_FXAA, storage->frame.current_rt->use_fxaa); - - if (env) { - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_FILTER_BICUBIC, env->glow_bicubic_upscale); - - if (max_glow_level >= 0) { - if (storage->frame.current_rt->mip_maps[0].color) { - for (int i = 0; i < (max_glow_level + 1); i++) { - if (glow_mask & (1 << i)) { - if (i == 0) { - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL1, true); - } - if (i == 1) { - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL2, true); - } - if (i == 2) { - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL3, true); - } - if (i == 3) { - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL4, true); - } - if (i == 4) { - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL5, true); - } - if (i == 5) { - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL6, true); - } - if (i == 6) { - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL7, true); - } - } - } - glActiveTexture(GL_TEXTURE2); - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->mip_maps[0].color); - } else { - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_MULTI_TEXTURE_GLOW, true); - int active_glow_level = 0; - for (int i = 0; i < (max_glow_level + 1); i++) { - if (glow_mask & (1 << i)) { - active_glow_level++; - glActiveTexture(GL_TEXTURE1 + active_glow_level); - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->mip_maps[0].sizes[i + 1].color); - if (active_glow_level == 1) { - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL1, true); - } - if (active_glow_level == 2) { - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL2, true); - } - if (active_glow_level == 3) { - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL3, true); - } - if (active_glow_level == 4) { - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL4, true); - } - if (active_glow_level == 5) { - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL5, true); - } - if (active_glow_level == 6) { - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL6, true); - } - if (active_glow_level == 7) { - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL7, true); - } - } - } - } - - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_SCREEN, env->glow_blend_mode == GD_VS::GLOW_BLEND_MODE_SCREEN); - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_SOFTLIGHT, env->glow_blend_mode == GD_VS::GLOW_BLEND_MODE_SOFTLIGHT); - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_REPLACE, env->glow_blend_mode == GD_VS::GLOW_BLEND_MODE_REPLACE); - } - } - - //Adjustments - if (env && env->adjustments_enabled) { - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_BCS, true); - RasterizerStorageGLES2::Texture *tex = storage->texture_owner.getornull(env->color_correction); - if (tex) { - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_COLOR_CORRECTION, true); - glActiveTexture(GL_TEXTURE1); - glBindTexture(tex->target, tex->tex_id); - } - } - - state.tonemap_shader.bind(); - if (env) { - if (max_glow_level >= 0) { - state.tonemap_shader.set_uniform(TonemapShaderGLES2::GLOW_INTENSITY, env->glow_intensity); - int ss[2] = { - storage->frame.current_rt->width, - storage->frame.current_rt->height, - }; - glUniform2iv(state.tonemap_shader.get_uniform(TonemapShaderGLES2::GLOW_TEXTURE_SIZE), 1, ss); - } - - if (env->adjustments_enabled) { - state.tonemap_shader.set_uniform(TonemapShaderGLES2::BCS, Vector3(env->adjustments_brightness, env->adjustments_contrast, env->adjustments_saturation)); - } - } - - if (storage->frame.current_rt->use_fxaa) { - state.tonemap_shader.set_uniform(TonemapShaderGLES2::PIXEL_SIZE, Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height)); - } - - storage->_copy_screen(); - - //turn off everything used - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_FXAA, false); - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL1, false); - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL2, false); - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL3, false); - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL4, false); - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL5, false); - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL6, false); - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_LEVEL7, false); - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_REPLACE, false); - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_SCREEN, false); - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_SOFTLIGHT, false); - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_FILTER_BICUBIC, false); - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_MULTI_TEXTURE_GLOW, false); - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_BCS, false); - state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_COLOR_CORRECTION, false); -} - -void RasterizerSceneGLES2::render_scene(const Transform3D &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) { - Transform3D cam_transform = p_cam_transform; - - storage->info.render.object_count += p_cull_count; - - GLuint current_fb = 0; - Environment *env = NULL; - - int viewport_width, viewport_height; - int viewport_x = 0; - int viewport_y = 0; - bool probe_interior = false; - bool reverse_cull = false; - - if (storage->frame.current_rt && storage->frame.current_rt->flags[RendererStorage::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); - ERR_FAIL_COND(!probe); - state.render_no_shadows = !probe->probe_ptr->enable_shadows; - - if (!probe->probe_ptr->interior) { //use env only if not interior - env = environment_owner.getornull(p_environment); - } - - current_fb = probe->fbo[p_reflection_probe_pass]; - - viewport_width = probe->probe_ptr->resolution; - viewport_height = probe->probe_ptr->resolution; - - probe_interior = probe->probe_ptr->interior; - - } else { - state.render_no_shadows = false; - 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 { - current_fb = storage->frame.current_rt->fbo; - } - env = environment_owner.getornull(p_environment); - - viewport_width = storage->frame.current_rt->width; - viewport_height = storage->frame.current_rt->height; - viewport_x = storage->frame.current_rt->x; - - if (storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_DIRECT_TO_SCREEN]) { - viewport_y = OS::get_singleton()->get_window_size().height - viewport_height - storage->frame.current_rt->y; - } else { - viewport_y = storage->frame.current_rt->y; - } - } - - 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; - state.screen_pixel_size.y = 1.0 / viewport_height; - - //push back the directional lights - - if (p_light_cull_count) { - //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; - - //doing this because directional lights are at the end, put them at the beginning - int index = 0; - for (int i = render_light_instance_count - 1; i >= 0; i--) { - RID light_rid = p_light_cull_result[i]; - - LightInstance *light = light_instance_owner.getornull(light_rid); - - if (light->light_ptr->type == GD_VS::LIGHT_DIRECTIONAL) { - render_directional_lights++; - //as going in reverse, directional lights are always first anyway - } - - light->light_index = index; - render_light_instances[index] = light; - - index++; - } - - } else { - render_light_instances = NULL; - render_directional_lights = 0; - render_light_instance_count = 0; - } - - if (p_reflection_probe_cull_count) { - reflection_probe_instances = (ReflectionProbeInstance **)alloca(sizeof(ReflectionProbeInstance *) * p_reflection_probe_cull_count); - reflection_probe_count = p_reflection_probe_cull_count; - for (int i = 0; i < p_reflection_probe_cull_count; i++) { - ReflectionProbeInstance *rpi = reflection_probe_instance_owner.getornull(p_reflection_probe_cull_result[i]); - ERR_CONTINUE(!rpi); - rpi->last_pass = render_pass + 1; //will be incremented later - rpi->index = i; - reflection_probe_instances[i] = rpi; - } - - } else { - reflection_probe_instances = NULL; - reflection_probe_count = 0; - } - - if (env && env->bg_mode == GD_VS::ENV_BG_CANVAS) { - // If using canvas background, copy 2d to screen copy texture - // TODO: When GLES2 renders to current_rt->mip_maps[], this copy will no longer be needed - _copy_texture_to_buffer(storage->frame.current_rt->color, storage->frame.current_rt->copy_screen_effect.fbo); - } - - // render list stuff - - render_list.clear(); - _fill_render_list(p_cull_result, p_cull_count, false, false); - - // other stuff - - glBindFramebuffer(GL_FRAMEBUFFER, current_fb); - glViewport(viewport_x, viewport_y, viewport_width, viewport_height); - - if (storage->frame.current_rt && storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_DIRECT_TO_SCREEN]) { - glScissor(viewport_x, viewport_y, viewport_width, viewport_height); - glEnable(GL_SCISSOR_TEST); - } - - glDepthFunc(GL_LEQUAL); - glDepthMask(GL_TRUE); - glClearDepth(1.0f); - glEnable(GL_DEPTH_TEST); - glClear(GL_DEPTH_BUFFER_BIT); - - // clear color - - Color clear_color(0, 0, 0, 1); - Ref<CameraFeed> feed; - - if (storage->frame.current_rt && storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_TRANSPARENT]) { - clear_color = Color(0, 0, 0, 0); - storage->frame.clear_request = false; - } else if (!env || env->bg_mode == GD_VS::ENV_BG_CLEAR_COLOR || env->bg_mode == GD_VS::ENV_BG_SKY) { - if (storage->frame.clear_request) { - clear_color = storage->frame.clear_request_color; - storage->frame.clear_request = false; - } - } else if (env->bg_mode == GD_VS::ENV_BG_CANVAS || env->bg_mode == GD_VS::ENV_BG_COLOR || env->bg_mode == GD_VS::ENV_BG_COLOR_SKY) { - clear_color = env->bg_color; - storage->frame.clear_request = false; - } else if (env->bg_mode == GD_VS::ENV_BG_CAMERA_FEED) { - feed = CameraServer::get_singleton()->get_feed_by_id(env->camera_feed_id); - storage->frame.clear_request = false; - } else { - storage->frame.clear_request = false; - } - - if (!env || env->bg_mode != GD_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); - - if (storage->frame.current_rt && storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_DIRECT_TO_SCREEN]) { - glDisable(GL_SCISSOR_TEST); - } - - glVertexAttrib4f(GD_VS::ARRAY_COLOR, 1, 1, 1, 1); - - glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - // render sky - RasterizerStorageGLES2::Sky *sky = NULL; - GLuint env_radiance_tex = 0; - if (env) { - switch (env->bg_mode) { - case GD_VS::ENV_BG_COLOR_SKY: - case GD_VS::ENV_BG_SKY: { - sky = storage->sky_owner.getornull(env->sky); - - if (sky) { - env_radiance_tex = sky->radiance; - } - } break; - case GD_VS::ENV_BG_CAMERA_FEED: { - if (feed.is_valid() && (feed->get_base_width() > 0) && (feed->get_base_height() > 0)) { - // copy our camera feed to our background - - glDisable(GL_BLEND); - glDepthMask(GL_FALSE); - glDisable(GL_DEPTH_TEST); - glDisable(GL_CULL_FACE); - - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_NO_ALPHA, true); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_DISPLAY_TRANSFORM, true); - - if (feed->get_datatype() == CameraFeed::FEED_RGB) { - RID camera_RGBA = feed->get_texture(CameraServer::FEED_RGBA_IMAGE); - - VS::get_singleton()->texture_bind(camera_RGBA, 0); - - } else if (feed->get_datatype() == CameraFeed::FEED_YCBCR) { - RID camera_YCbCr = feed->get_texture(CameraServer::FEED_YCBCR_IMAGE); - - VS::get_singleton()->texture_bind(camera_YCbCr, 0); - - storage->shaders.copy.set_conditional(CopyShaderGLES2::YCBCR_TO_RGB, true); - - } else if (feed->get_datatype() == CameraFeed::FEED_YCBCR_SEP) { - RID camera_Y = feed->get_texture(CameraServer::FEED_Y_IMAGE); - RID camera_CbCr = feed->get_texture(CameraServer::FEED_CBCR_IMAGE); - - VS::get_singleton()->texture_bind(camera_Y, 0); - VS::get_singleton()->texture_bind(camera_CbCr, 1); - - storage->shaders.copy.set_conditional(CopyShaderGLES2::SEP_CBCR_TEXTURE, true); - storage->shaders.copy.set_conditional(CopyShaderGLES2::YCBCR_TO_RGB, true); - }; - - storage->shaders.copy.bind(); - storage->shaders.copy.set_uniform(CopyShaderGLES2::DISPLAY_TRANSFORM, feed->get_transform()); - - storage->bind_quad_array(); - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - glDisableVertexAttribArray(GD_VS::ARRAY_VERTEX); - glDisableVertexAttribArray(GD_VS::ARRAY_TEX_UV); - glBindBuffer(GL_ARRAY_BUFFER, 0); - - // turn off everything used - storage->shaders.copy.set_conditional(CopyShaderGLES2::SEP_CBCR_TEXTURE, false); - storage->shaders.copy.set_conditional(CopyShaderGLES2::YCBCR_TO_RGB, false); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_NO_ALPHA, false); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_DISPLAY_TRANSFORM, false); - - //restore - glEnable(GL_BLEND); - glDepthMask(GL_TRUE); - glEnable(GL_DEPTH_TEST); - glEnable(GL_CULL_FACE); - } else { - // don't have a feed, just show greenscreen :) - clear_color = Color(0.0, 1.0, 0.0, 1.0); - } - } break; - case GD_VS::ENV_BG_CANVAS: { - // use screen copy as background - _copy_texture_to_buffer(storage->frame.current_rt->copy_screen_effect.color, current_fb); - } break; - default: { - } break; - } - } - - if (probe_interior) { - env_radiance_tex = 0; //do not use radiance texture on interiors - state.default_ambient = Color(0, 0, 0, 1); //black as default ambient for interior - state.default_bg = Color(0, 0, 0, 1); //black as default background for interior - } - - // render opaque things first - render_list.sort_by_key(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); - - // then draw the sky after - if (env && env->bg_mode == GD_VS::ENV_BG_SKY && (!storage->frame.current_rt || !storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_TRANSPARENT])) { - if (sky && sky->panorama.is_valid()) { - _draw_sky(sky, p_cam_projection, cam_transform, false, env->sky_custom_fov, env->bg_energy, env->sky_orientation); - } - } - - if (storage->frame.current_rt && state.used_screen_texture) { - //copy screen texture - - if (storage->frame.current_rt->multisample_active) { - // Resolve framebuffer to front buffer before copying -#ifdef GLES_OVER_GL - - glBindFramebuffer(GL_READ_FRAMEBUFFER, storage->frame.current_rt->multisample_fbo); - glReadBuffer(GL_COLOR_ATTACHMENT0); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, storage->frame.current_rt->fbo); - glBlitFramebuffer(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, 0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); - - glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); -#elif IPHONE_ENABLED - - glBindFramebuffer(GL_READ_FRAMEBUFFER, storage->frame.current_rt->multisample_fbo); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, storage->frame.current_rt->fbo); - glResolveMultisampleFramebufferAPPLE(); - - glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); -#elif ANDROID_ENABLED - - // In GLES2 AndroidBlit is not available, so just copy color texture manually - _copy_texture_to_buffer(storage->frame.current_rt->multisample_color, storage->frame.current_rt->fbo); -#endif - } - - storage->canvas->_copy_screen(Rect2()); - - if (storage->frame.current_rt && storage->frame.current_rt->multisample_active) { - // Rebind the current framebuffer - glBindFramebuffer(GL_FRAMEBUFFER, current_fb); - glViewport(0, 0, viewport_width, viewport_height); - } - } - // alpha pass - - glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - - render_list.sort_by_reverse_depth_and_priority(true); - - _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); - - if (p_reflection_probe.is_valid()) { - // Rendering to a probe so no need for post_processing - return; - } - - //post process - _post_process(env, p_cam_projection); - - //#define GLES2_SHADOW_ATLAS_DEBUG_VIEW - -#ifdef GLES2_SHADOW_ATLAS_DEBUG_VIEW - ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_shadow_atlas); - if (shadow_atlas) { - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, shadow_atlas->depth); - - glViewport(0, 0, storage->frame.current_rt->width / 4, storage->frame.current_rt->height / 4); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_CUBEMAP, false); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_COPY_SECTION, false); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_CUSTOM_ALPHA, false); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_MULTIPLIER, false); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_PANORAMA, false); - storage->shaders.copy.bind(); - - storage->_copy_screen(); - } -#endif - - //#define GLES2_SHADOW_DIRECTIONAL_DEBUG_VIEW - -#ifdef GLES2_SHADOW_DIRECTIONAL_DEBUG_VIEW - if (true) { - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, directional_shadow.depth); - - glViewport(0, 0, storage->frame.current_rt->width / 4, storage->frame.current_rt->height / 4); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_CUBEMAP, false); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_COPY_SECTION, false); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_CUSTOM_ALPHA, false); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_MULTIPLIER, false); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_PANORAMA, false); - storage->shaders.copy.bind(); - - storage->_copy_screen(); - } -#endif -} - -void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, InstanceBase **p_cull_result, int p_cull_count) { - state.render_no_shadows = false; - - LightInstance *light_instance = light_instance_owner.getornull(p_light); - ERR_FAIL_COND(!light_instance); - - RasterizerStorageGLES2::Light *light = light_instance->light_ptr; - ERR_FAIL_COND(!light); - - uint32_t x; - uint32_t y; - uint32_t width; - uint32_t height; - - float zfar = 0; - bool flip_facing = false; - int custom_vp_size = 0; - GLuint fbo = 0; - state.shadow_is_dual_parabolloid = false; - state.dual_parbolloid_direction = 0.0; - - int current_cubemap = -1; - float bias = 0; - float normal_bias = 0; - - CameraMatrix light_projection; - Transform3D light_transform; - - // TODO directional light - - if (light->type == GD_VS::LIGHT_DIRECTIONAL) { - // set pssm stuff - - // TODO set this only when changed - - light_instance->light_directional_index = directional_shadow.current_light; - light_instance->last_scene_shadow_pass = scene_pass; - - directional_shadow.current_light++; - - if (directional_shadow.light_count == 1) { - light_instance->directional_rect = Rect2(0, 0, directional_shadow.size, directional_shadow.size); - } else if (directional_shadow.light_count == 2) { - light_instance->directional_rect = Rect2(0, 0, directional_shadow.size, directional_shadow.size / 2); - if (light_instance->light_directional_index == 1) { - light_instance->directional_rect.position.x += light_instance->directional_rect.size.x; - } - } else { //3 and 4 - light_instance->directional_rect = Rect2(0, 0, directional_shadow.size / 2, directional_shadow.size / 2); - if (light_instance->light_directional_index & 1) { - light_instance->directional_rect.position.x += light_instance->directional_rect.size.x; - } - if (light_instance->light_directional_index / 2) { - light_instance->directional_rect.position.y += light_instance->directional_rect.size.y; - } - } - - light_projection = light_instance->shadow_transform[p_pass].camera; - light_transform = light_instance->shadow_transform[p_pass].transform; - - x = light_instance->directional_rect.position.x; - y = light_instance->directional_rect.position.y; - width = light_instance->directional_rect.size.width; - height = light_instance->directional_rect.size.height; - - if (light->directional_shadow_mode == GD_VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS) { - width /= 2; - height /= 2; - - if (p_pass == 1) { - x += width; - } else if (p_pass == 2) { - y += height; - } else if (p_pass == 3) { - x += width; - y += height; - } - - } else if (light->directional_shadow_mode == GD_VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS) { - height /= 2; - - if (p_pass == 0) { - } else { - y += height; - } - } - - float bias_mult = Math::lerp(1.0f, light_instance->shadow_transform[p_pass].bias_scale, light->param[VS::LIGHT_PARAM_SHADOW_BIAS_SPLIT_SCALE]); - zfar = light->param[VS::LIGHT_PARAM_RANGE]; - bias = light->param[VS::LIGHT_PARAM_SHADOW_BIAS] * bias_mult; - normal_bias = light->param[VS::LIGHT_PARAM_SHADOW_NORMAL_BIAS] * bias_mult; - - fbo = directional_shadow.fbo; - } else { - ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_shadow_atlas); - ERR_FAIL_COND(!shadow_atlas); - ERR_FAIL_COND(!shadow_atlas->shadow_owners.has(p_light)); - - fbo = shadow_atlas->fbo; - - uint32_t key = shadow_atlas->shadow_owners[p_light]; - - uint32_t quadrant = (key >> ShadowAtlas::QUADRANT_SHIFT) & 0x03; - uint32_t shadow = key & ShadowAtlas::SHADOW_INDEX_MASK; - - ERR_FAIL_INDEX((int)shadow, shadow_atlas->quadrants[quadrant].shadows.size()); - - uint32_t quadrant_size = shadow_atlas->size >> 1; - - x = (quadrant & 1) * quadrant_size; - y = (quadrant >> 1) * quadrant_size; - - uint32_t shadow_size = (quadrant_size / shadow_atlas->quadrants[quadrant].subdivision); - x += (shadow % shadow_atlas->quadrants[quadrant].subdivision) * shadow_size; - y += (shadow / shadow_atlas->quadrants[quadrant].subdivision) * shadow_size; - - width = shadow_size; - height = shadow_size; - - if (light->type == GD_VS::LIGHT_OMNI) { - // cubemap only - if (light->omni_shadow_mode == GD_VS::LIGHT_OMNI_SHADOW_CUBE && storage->config.support_shadow_cubemaps) { - int cubemap_index = shadow_cubemaps.size() - 1; - - // find an appropriate cubemap to render to - for (int i = shadow_cubemaps.size() - 1; i >= 0; i--) { - if (shadow_cubemaps[i].size > shadow_size * 2) { - break; - } - - cubemap_index = i; - } - - fbo = shadow_cubemaps[cubemap_index].fbo[p_pass]; - light_projection = light_instance->shadow_transform[0].camera; - light_transform = light_instance->shadow_transform[0].transform; - - custom_vp_size = shadow_cubemaps[cubemap_index].size; - zfar = light->param[VS::LIGHT_PARAM_RANGE]; - - current_cubemap = cubemap_index; - } else { - //dual parabolloid - state.shadow_is_dual_parabolloid = true; - light_projection = light_instance->shadow_transform[0].camera; - light_transform = light_instance->shadow_transform[0].transform; - - if (light->omni_shadow_detail == GD_VS::LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL) { - height /= 2; - y += p_pass * height; - } else { - width /= 2; - x += p_pass * width; - } - - state.dual_parbolloid_direction = p_pass == 0 ? 1.0 : -1.0; - flip_facing = (p_pass == 1); - zfar = light->param[VS::LIGHT_PARAM_RANGE]; - bias = light->param[VS::LIGHT_PARAM_SHADOW_BIAS]; - - state.dual_parbolloid_zfar = zfar; - - state.scene_shader.set_conditional(SceneShaderGLES2::RENDER_DEPTH_DUAL_PARABOLOID, true); - } - - } else if (light->type == GD_VS::LIGHT_SPOT) { - light_projection = light_instance->shadow_transform[0].camera; - light_transform = light_instance->shadow_transform[0].transform; - - flip_facing = false; - zfar = light->param[VS::LIGHT_PARAM_RANGE]; - bias = light->param[VS::LIGHT_PARAM_SHADOW_BIAS]; - normal_bias = light->param[VS::LIGHT_PARAM_SHADOW_NORMAL_BIAS]; - } - } - - render_list.clear(); - - _fill_render_list(p_cull_result, p_cull_count, true, true); - - render_list.sort_by_depth(false); - - glDisable(GL_BLEND); - glDisable(GL_DITHER); - glEnable(GL_DEPTH_TEST); - - glBindFramebuffer(GL_FRAMEBUFFER, fbo); - - glDepthMask(GL_TRUE); - if (!storage->config.use_rgba_3d_shadows) { - glColorMask(0, 0, 0, 0); - } - - if (custom_vp_size) { - glViewport(0, 0, custom_vp_size, custom_vp_size); - glScissor(0, 0, custom_vp_size, custom_vp_size); - } else { - glViewport(x, y, width, height); - glScissor(x, y, width, height); - } - - glEnable(GL_SCISSOR_TEST); - glClearDepth(1.0f); - glClear(GL_DEPTH_BUFFER_BIT); - if (storage->config.use_rgba_3d_shadows) { - glClearColor(1.0, 1.0, 1.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - } - glDisable(GL_SCISSOR_TEST); - - if (light->reverse_cull) { - flip_facing = !flip_facing; - } - - state.scene_shader.set_conditional(SceneShaderGLES2::RENDER_DEPTH, true); - - _render_render_list(render_list.elements, render_list.element_count, light_transform, light_projection, RID(), NULL, 0, bias, normal_bias, flip_facing, false, true); - - state.scene_shader.set_conditional(SceneShaderGLES2::RENDER_DEPTH, false); - state.scene_shader.set_conditional(SceneShaderGLES2::RENDER_DEPTH_DUAL_PARABOLOID, false); - - // convert cubemap to dual paraboloid if needed - if (light->type == GD_VS::LIGHT_OMNI && (light->omni_shadow_mode == GD_VS::LIGHT_OMNI_SHADOW_CUBE && storage->config.support_shadow_cubemaps) && p_pass == 5) { - ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_shadow_atlas); - - glBindFramebuffer(GL_FRAMEBUFFER, shadow_atlas->fbo); - state.cube_to_dp_shader.bind(); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_CUBE_MAP, shadow_cubemaps[current_cubemap].cubemap); - - glDisable(GL_CULL_FACE); - - for (int i = 0; i < 2; i++) { - state.cube_to_dp_shader.set_uniform(CubeToDpShaderGLES2::Z_FLIP, i == 1); - state.cube_to_dp_shader.set_uniform(CubeToDpShaderGLES2::Z_NEAR, light_projection.get_z_near()); - state.cube_to_dp_shader.set_uniform(CubeToDpShaderGLES2::Z_FAR, light_projection.get_z_far()); - state.cube_to_dp_shader.set_uniform(CubeToDpShaderGLES2::BIAS, light->param[VS::LIGHT_PARAM_SHADOW_BIAS]); - - uint32_t local_width = width; - uint32_t local_height = height; - uint32_t local_x = x; - uint32_t local_y = y; - - if (light->omni_shadow_detail == GD_VS::LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL) { - local_height /= 2; - local_y += i * local_height; - } else { - local_width /= 2; - local_x += i * local_width; - } - - glViewport(local_x, local_y, local_width, local_height); - glScissor(local_x, local_y, local_width, local_height); - - glEnable(GL_SCISSOR_TEST); - - glClearDepth(1.0f); - - glClear(GL_DEPTH_BUFFER_BIT); - glDisable(GL_SCISSOR_TEST); - - glDisable(GL_BLEND); - - storage->_copy_screen(); - } - } - - if (storage->frame.current_rt) { - glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height); - } - if (!storage->config.use_rgba_3d_shadows) { - glColorMask(1, 1, 1, 1); - } -} - -void RasterizerSceneGLES2::set_scene_pass(uint64_t p_pass) { - scene_pass = p_pass; -} - -bool RasterizerSceneGLES2::free(RID p_rid) { - if (light_instance_owner.owns(p_rid)) { - LightInstance *light_instance = light_instance_owner.getptr(p_rid); - - //remove from shadow atlases.. - for (Set<RID>::Element *E = light_instance->shadow_atlases.front(); E; E = E->next()) { - ShadowAtlas *shadow_atlas = shadow_atlas_owner.get(E->get()); - ERR_CONTINUE(!shadow_atlas->shadow_owners.has(p_rid)); - uint32_t key = shadow_atlas->shadow_owners[p_rid]; - uint32_t q = (key >> ShadowAtlas::QUADRANT_SHIFT) & 0x3; - uint32_t s = key & ShadowAtlas::SHADOW_INDEX_MASK; - - shadow_atlas->quadrants[q].shadows.write[s].owner = RID(); - shadow_atlas->shadow_owners.erase(p_rid); - } - - light_instance_owner.free(p_rid); - memdelete(light_instance); - - } else if (shadow_atlas_owner.owns(p_rid)) { - ShadowAtlas *shadow_atlas = shadow_atlas_owner.get(p_rid); - shadow_atlas_set_size(p_rid, 0); - shadow_atlas_owner.free(p_rid); - memdelete(shadow_atlas); - } else if (reflection_probe_instance_owner.owns(p_rid)) { - ReflectionProbeInstance *reflection_instance = reflection_probe_instance_owner.get(p_rid); - - for (int i = 0; i < 6; i++) { - glDeleteFramebuffers(1, &reflection_instance->fbo[i]); - glDeleteTextures(1, &reflection_instance->color[i]); - } - - if (reflection_instance->cubemap != 0) { - glDeleteTextures(1, &reflection_instance->cubemap); - } - glDeleteRenderbuffers(1, &reflection_instance->depth); - - reflection_probe_release_atlas_index(p_rid); - reflection_probe_instance_owner.free(p_rid); - memdelete(reflection_instance); - - } else { - return false; - } - - return true; -} - -void RasterizerSceneGLES2::set_debug_draw_mode(GD_VS::ViewportDebugDraw p_debug_draw) { -} - -void RasterizerSceneGLES2::initialize() { - state.scene_shader.init(); - - state.scene_shader.set_conditional(SceneShaderGLES2::USE_RGBA_SHADOWS, storage->config.use_rgba_3d_shadows); - state.cube_to_dp_shader.init(); - state.effect_blur_shader.init(); - state.tonemap_shader.init(); - - render_list.init(); - - render_pass = 1; - - shadow_atlas_realloc_tolerance_msec = 500; - - { - //default material and shader - - default_shader = storage->shader_create(); - storage->shader_set_code(default_shader, "shader_type spatial;\n"); - default_material = storage->material_create(); - storage->material_set_shader(default_material, default_shader); - - default_shader_twosided = storage->shader_create(); - default_material_twosided = storage->material_create(); - storage->shader_set_code(default_shader_twosided, "shader_type spatial; render_mode cull_disabled;\n"); - storage->material_set_shader(default_material_twosided, default_shader_twosided); - } - - { - default_worldcoord_shader = storage->shader_create(); - storage->shader_set_code(default_worldcoord_shader, "shader_type spatial; render_mode world_vertex_coords;\n"); - default_worldcoord_material = storage->material_create(); - storage->material_set_shader(default_worldcoord_material, default_worldcoord_shader); - - default_worldcoord_shader_twosided = storage->shader_create(); - default_worldcoord_material_twosided = storage->material_create(); - storage->shader_set_code(default_worldcoord_shader_twosided, "shader_type spatial; render_mode cull_disabled,world_vertex_coords;\n"); - storage->material_set_shader(default_worldcoord_material_twosided, default_worldcoord_shader_twosided); - } - - { - //default material and shader - - default_overdraw_shader = storage->shader_create(); - storage->shader_set_code(default_overdraw_shader, "shader_type spatial;\nrender_mode blend_add,unshaded;\n void fragment() { ALBEDO=vec3(0.4,0.8,0.8); ALPHA=0.2; }"); - default_overdraw_material = storage->material_create(); - storage->material_set_shader(default_overdraw_material, default_overdraw_shader); - } - - { - glGenBuffers(1, &state.sky_verts); - glBindBuffer(GL_ARRAY_BUFFER, state.sky_verts); - glBufferData(GL_ARRAY_BUFFER, sizeof(Vector3) * 8, NULL, GL_DYNAMIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); - } - - { - uint32_t immediate_buffer_size = GLOBAL_DEF("rendering/limits/buffers/immediate_buffer_size_kb", 2048); - ProjectSettings::get_singleton()->set_custom_property_info("rendering/limits/buffers/immediate_buffer_size_kb", PropertyInfo(Variant::INT, "rendering/limits/buffers/immediate_buffer_size_kb", PROPERTY_HINT_RANGE, "0,8192,1,or_greater")); - - glGenBuffers(1, &state.immediate_buffer); - glBindBuffer(GL_ARRAY_BUFFER, state.immediate_buffer); - glBufferData(GL_ARRAY_BUFFER, immediate_buffer_size * 1024, NULL, GL_DYNAMIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); - } - - // cubemaps for shadows - if (storage->config.support_shadow_cubemaps) { //not going to be used - int max_shadow_cubemap_sampler_size = 512; - - int cube_size = max_shadow_cubemap_sampler_size; - - glActiveTexture(GL_TEXTURE0); - - while (cube_size >= 32) { - ShadowCubeMap cube; - - cube.size = cube_size; - - glGenTextures(1, &cube.cubemap); - glBindTexture(GL_TEXTURE_CUBE_MAP, cube.cubemap); - - for (int i = 0; i < 6; i++) { - glTexImage2D(_cube_side_enum[i], 0, storage->config.depth_internalformat, cube_size, cube_size, 0, GL_DEPTH_COMPONENT, storage->config.depth_type, NULL); - } - - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - glGenFramebuffers(6, cube.fbo); - for (int i = 0; i < 6; i++) { - glBindFramebuffer(GL_FRAMEBUFFER, cube.fbo[i]); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, _cube_side_enum[i], cube.cubemap, 0); - } - - shadow_cubemaps.push_back(cube); - - cube_size >>= 1; - } - } - - { - // directional shadows - - directional_shadow.light_count = 0; - directional_shadow.size = next_power_of_2(GLOBAL_GET("rendering/quality/directional_shadow/size")); - - glGenFramebuffers(1, &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_buffer_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); - 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_COLOR_ATTACHMENT0, GL_TEXTURE_2D, directional_shadow.color, 0); - } else { - //just a depth buffer - glGenTextures(1, &directional_shadow.depth); - glBindTexture(GL_TEXTURE_2D, directional_shadow.depth); - - glTexImage2D(GL_TEXTURE_2D, 0, storage->config.depth_internalformat, directional_shadow.size, directional_shadow.size, 0, GL_DEPTH_COMPONENT, storage->config.depth_type, 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, directional_shadow.depth, 0); - } - - GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) { - ERR_PRINT("Directional shadow framebuffer status invalid"); - } - } - - shadow_filter_mode = SHADOW_FILTER_NEAREST; - - glFrontFace(GL_CW); -} - -void RasterizerSceneGLES2::iteration() { - shadow_filter_mode = ShadowFilterMode(int(GLOBAL_GET("rendering/quality/shadows/filter_mode"))); -} - -void RasterizerSceneGLES2::finalize() { -} - -RasterizerSceneGLES2::RasterizerSceneGLES2() { -} - -#endif // godot 3 - -#endif // GLES2_BACKEND_ENABLED diff --git a/drivers/gles2/rasterizer_scene_gles2.h b/drivers/gles2/rasterizer_scene_gles2.h deleted file mode 100644 index 2181186e71..0000000000 --- a/drivers/gles2/rasterizer_scene_gles2.h +++ /dev/null @@ -1,793 +0,0 @@ -/*************************************************************************/ -/* rasterizer_scene_gles2.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* 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 */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#pragma once -// dummy - -#include "drivers/gles_common/rasterizer_platforms.h" -#ifdef GLES2_BACKEND_ENABLED - -#include "core/math/camera_matrix.h" -#include "core/templates/rid_owner.h" -#include "core/templates/self_list.h" -#include "drivers/gles_common/rasterizer_common_stubs.h" -#include "scene/resources/mesh.h" -#include "servers/rendering/renderer_compositor.h" -#include "servers/rendering_server.h" -#include "shaders/scene.glsl.gen.h" - -class RasterizerSceneGLES2 : public StubsScene { -public: - struct State { - SceneShaderGLES2 scene_shader; - - } state; - -public: - RasterizerSceneGLES2() {} - ~RasterizerSceneGLES2() {} -}; - -#ifdef GODOT_3 - -/* Must come before shaders or the Windows build fails... */ -#include "drivers/gles_common/rasterizer_version.h" -#include "rasterizer_storage_gles2.h" - -#include "shaders/cube_to_dp.glsl.gen.h" -#include "shaders/effect_blur.glsl.gen.h" -#include "shaders/scene.glsl.gen.h" -#include "shaders/tonemap.glsl.gen.h" -/* - -#include "drivers/gles3/shaders/exposure.glsl.gen.h" -#include "drivers/gles3/shaders/resolve.glsl.gen.h" -#include "drivers/gles3/shaders/scene.glsl.gen.h" -#include "drivers/gles3/shaders/screen_space_reflection.glsl.gen.h" -#include "drivers/gles3/shaders/ssao.glsl.gen.h" -#include "drivers/gles3/shaders/ssao_blur.glsl.gen.h" -#include "drivers/gles3/shaders/ssao_minify.glsl.gen.h" -#include "drivers/gles3/shaders/subsurf_scattering.glsl.gen.h" - -*/ - -class RasterizerSceneGLES2 : public RasterizerScene { -public: - enum ShadowFilterMode { - SHADOW_FILTER_NEAREST, - SHADOW_FILTER_PCF5, - SHADOW_FILTER_PCF13, - }; - - enum { - INSTANCE_ATTRIB_BASE = 8, - INSTANCE_BONE_BASE = 13, - }; - - ShadowFilterMode shadow_filter_mode; - - RID default_material; - RID default_material_twosided; - RID default_shader; - RID default_shader_twosided; - - RID default_worldcoord_material; - RID default_worldcoord_material_twosided; - RID default_worldcoord_shader; - RID default_worldcoord_shader_twosided; - - RID default_overdraw_material; - RID default_overdraw_shader; - - uint64_t render_pass; - uint64_t scene_pass; - uint32_t current_material_index; - uint32_t current_geometry_index; - uint32_t current_light_index; - uint32_t current_refprobe_index; - uint32_t current_shader_index; - - RasterizerStorageGLES2 *storage; - struct State { - bool texscreen_copied; - int current_blend_mode; - float current_line_width; - int current_depth_draw; - bool current_depth_test; - GLuint current_main_tex; - - SceneShaderGLES2 scene_shader; - CubeToDpShaderGLES2 cube_to_dp_shader; - TonemapShaderGLES2 tonemap_shader; - EffectBlurShaderGLES2 effect_blur_shader; - - GLuint sky_verts; - - GLuint immediate_buffer; - Color default_ambient; - Color default_bg; - - // ResolveShaderGLES3 resolve_shader; - // ScreenSpaceReflectionShaderGLES3 ssr_shader; - // EffectBlurShaderGLES3 effect_blur_shader; - // SubsurfScatteringShaderGLES3 sss_shader; - // SsaoMinifyShaderGLES3 ssao_minify_shader; - // SsaoShaderGLES3 ssao_shader; - // SsaoBlurShaderGLES3 ssao_blur_shader; - // ExposureShaderGLES3 exposure_shader; - - /* - struct SceneDataUBO { - //this is a std140 compatible struct. Please read the OpenGL 3.3 Specificaiton spec before doing any changes - float projection_matrix[16]; - float inv_projection_matrix[16]; - float camera_inverse_matrix[16]; - float camera_matrix[16]; - float ambient_light_color[4]; - float bg_color[4]; - float fog_color_enabled[4]; - float fog_sun_color_amount[4]; - - float ambient_energy; - float bg_energy; - float z_offset; - float z_slope_scale; - float shadow_dual_paraboloid_render_zfar; - float shadow_dual_paraboloid_render_side; - float viewport_size[2]; - float screen_pixel_size[2]; - float shadow_atlas_pixel_size[2]; - float shadow_directional_pixel_size[2]; - - float time; - float z_far; - float reflection_multiplier; - float subsurface_scatter_width; - float ambient_occlusion_affect_light; - - uint32_t fog_depth_enabled; - float fog_depth_begin; - float fog_depth_curve; - uint32_t fog_transmit_enabled; - float fog_transmit_curve; - uint32_t fog_height_enabled; - float fog_height_min; - float fog_height_max; - float fog_height_curve; - // make sure this struct is padded to be a multiple of 16 bytes for webgl - - } ubo_data; - - GLuint scene_ubo; - - struct EnvironmentRadianceUBO { - float transform[16]; - float ambient_contribution; - uint8_t padding[12]; - - } env_radiance_data; - - GLuint env_radiance_ubo; - - GLuint sky_array; - - GLuint directional_ubo; - - GLuint spot_array_ubo; - GLuint omni_array_ubo; - GLuint reflection_array_ubo; - - GLuint immediate_buffer; - GLuint immediate_array; - - uint32_t ubo_light_size; - uint8_t *spot_array_tmp; - uint8_t *omni_array_tmp; - uint8_t *reflection_array_tmp; - - int max_ubo_lights; - int max_forward_lights_per_object; - int max_ubo_reflections; - int max_skeleton_bones; - - bool used_contact_shadows; - - int spot_light_count; - int omni_light_count; - int directional_light_count; - int reflection_probe_count; - - bool used_sss; - bool using_contact_shadows; - - VS::ViewportDebugDraw debug_draw; - */ - - bool cull_front; - bool cull_disabled; - - bool used_screen_texture; - bool shadow_is_dual_parabolloid; - float dual_parbolloid_direction; - float dual_parbolloid_zfar; - - bool render_no_shadows; - - Vector2 viewport_size; - - Vector2 screen_pixel_size; - } state; - - /* SHADOW ATLAS API */ - - uint64_t shadow_atlas_realloc_tolerance_msec; - - struct ShadowAtlas : public RID_Data { - enum { - QUADRANT_SHIFT = 27, - SHADOW_INDEX_MASK = (1 << QUADRANT_SHIFT) - 1, - SHADOW_INVALID = 0xFFFFFFFF, - }; - - struct Quadrant { - uint32_t subdivision; - - struct Shadow { - RID owner; - uint64_t version; - uint64_t alloc_tick; - - Shadow() { - version = 0; - alloc_tick = 0; - } - }; - - Vector<Shadow> shadows; - - Quadrant() { - subdivision = 0; - } - } quadrants[4]; - - int size_order[4]; - uint32_t smallest_subdiv; - - int size; - - GLuint fbo; - GLuint depth; - GLuint color; - - Map<RID, uint32_t> shadow_owners; - }; - - struct ShadowCubeMap { - GLuint fbo[6]; - GLuint cubemap; - uint32_t size; - }; - - Vector<ShadowCubeMap> shadow_cubemaps; - - RID_Owner<ShadowAtlas> shadow_atlas_owner; - - RID shadow_atlas_create(); - void shadow_atlas_set_size(RID p_atlas, int p_size); - void shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision); - bool _shadow_atlas_find_shadow(ShadowAtlas *shadow_atlas, int *p_in_quadrants, int p_quadrant_count, int p_current_subdiv, uint64_t p_tick, int &r_quadrant, int &r_shadow); - bool shadow_atlas_update_light(RID p_atlas, RID p_light_intance, float p_coverage, uint64_t p_light_version); - - struct DirectionalShadow { - GLuint fbo; - GLuint depth; - GLuint color; - - int light_count; - int size; - int current_light; - } directional_shadow; - - virtual int get_directional_light_shadow_size(RID p_light_intance); - virtual void set_directional_shadow_count(int p_count); - - /* REFLECTION PROBE ATLAS API */ - - virtual RID reflection_atlas_create(); - virtual void reflection_atlas_set_size(RID p_ref_atlas, int p_size); - virtual void reflection_atlas_set_subdivision(RID p_ref_atlas, int p_subdiv); - - /* REFLECTION CUBEMAPS */ - - /* REFLECTION PROBE INSTANCE */ - - struct ReflectionProbeInstance : public RID_Data { - RasterizerStorageGLES2::ReflectionProbe *probe_ptr; - RID probe; - RID self; - RID atlas; - - int reflection_atlas_index; - - int render_step; - int reflection_index; - - GLuint fbo[6]; - GLuint color[6]; - GLuint depth; - GLuint cubemap; - - int current_resolution; - mutable bool dirty; - - uint64_t last_pass; - uint32_t index; - - Transform3D transform; - }; - - mutable RID_Owner<ReflectionProbeInstance> reflection_probe_instance_owner; - - ReflectionProbeInstance **reflection_probe_instances; - int reflection_probe_count; - - virtual RID reflection_probe_instance_create(RID p_probe); - virtual void reflection_probe_instance_set_transform(RID p_instance, const Transform3D &p_transform); - virtual void reflection_probe_release_atlas_index(RID p_instance); - virtual bool reflection_probe_instance_needs_redraw(RID p_instance); - virtual bool reflection_probe_instance_has_reflection(RID p_instance); - virtual bool reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas); - virtual bool reflection_probe_instance_postprocess_step(RID p_instance); - - /* ENVIRONMENT API */ - - struct Environment : public RID_Data { - VS::EnvironmentBG bg_mode; - - RID sky; - float sky_custom_fov; - Basis sky_orientation; - - Color bg_color; - float bg_energy; - float sky_ambient; - - int camera_feed_id; - - Color ambient_color; - float ambient_energy; - float ambient_sky_contribution; - - int canvas_max_layer; - - bool glow_enabled; - int glow_levels; - float glow_intensity; - float glow_strength; - float glow_bloom; - VS::EnvironmentGlowBlendMode glow_blend_mode; - float glow_hdr_bleed_threshold; - float glow_hdr_bleed_scale; - float glow_hdr_luminance_cap; - bool glow_bicubic_upscale; - - bool dof_blur_far_enabled; - float dof_blur_far_distance; - float dof_blur_far_transition; - float dof_blur_far_amount; - VS::EnvironmentDOFBlurQuality dof_blur_far_quality; - - bool dof_blur_near_enabled; - float dof_blur_near_distance; - float dof_blur_near_transition; - float dof_blur_near_amount; - VS::EnvironmentDOFBlurQuality dof_blur_near_quality; - - bool adjustments_enabled; - float adjustments_brightness; - float adjustments_contrast; - float adjustments_saturation; - RID color_correction; - - bool fog_enabled; - Color fog_color; - Color fog_sun_color; - float fog_sun_amount; - - bool fog_depth_enabled; - float fog_depth_begin; - float fog_depth_end; - float fog_depth_curve; - bool fog_transmit_enabled; - float fog_transmit_curve; - bool fog_height_enabled; - float fog_height_min; - float fog_height_max; - float fog_height_curve; - - Environment() : - bg_mode(GD_VS::ENV_BG_CLEAR_COLOR), - sky_custom_fov(0.0), - bg_energy(1.0), - sky_ambient(0), - camera_feed_id(0), - ambient_energy(1.0), - ambient_sky_contribution(0.0), - canvas_max_layer(0), - glow_enabled(false), - glow_levels((1 << 2) | (1 << 4)), - glow_intensity(0.8), - glow_strength(1.0), - glow_bloom(0.0), - glow_blend_mode(GD_VS::GLOW_BLEND_MODE_SOFTLIGHT), - glow_hdr_bleed_threshold(1.0), - glow_hdr_bleed_scale(2.0), - glow_hdr_luminance_cap(12.0), - glow_bicubic_upscale(false), - dof_blur_far_enabled(false), - dof_blur_far_distance(10), - dof_blur_far_transition(5), - dof_blur_far_amount(0.1), - dof_blur_far_quality(GD_VS::ENV_DOF_BLUR_QUALITY_MEDIUM), - dof_blur_near_enabled(false), - dof_blur_near_distance(2), - dof_blur_near_transition(1), - dof_blur_near_amount(0.1), - dof_blur_near_quality(GD_VS::ENV_DOF_BLUR_QUALITY_MEDIUM), - adjustments_enabled(false), - adjustments_brightness(1.0), - adjustments_contrast(1.0), - adjustments_saturation(1.0), - fog_enabled(false), - fog_color(Color(0.5, 0.5, 0.5)), - fog_sun_color(Color(0.8, 0.8, 0.0)), - fog_sun_amount(0), - fog_depth_enabled(true), - fog_depth_begin(10), - fog_depth_end(0), - fog_depth_curve(1), - fog_transmit_enabled(true), - fog_transmit_curve(1), - fog_height_enabled(false), - fog_height_min(10), - fog_height_max(0), - fog_height_curve(1) { - } - }; - - mutable RID_Owner<Environment> environment_owner; - - virtual RID environment_create(); - - virtual void environment_set_background(RID p_env, GD_VS::EnvironmentBG p_bg); - virtual void environment_set_sky(RID p_env, RID p_sky); - virtual void environment_set_sky_custom_fov(RID p_env, float p_scale); - virtual void environment_set_sky_orientation(RID p_env, const Basis &p_orientation); - virtual void environment_set_bg_color(RID p_env, const Color &p_color); - virtual void environment_set_bg_energy(RID p_env, float p_energy); - virtual void environment_set_canvas_max_layer(RID p_env, int p_max_layer); - virtual void environment_set_ambient_light(RID p_env, const Color &p_color, float p_energy = 1.0, float p_sky_contribution = 0.0); - virtual void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id); - - virtual void environment_set_dof_blur_near(RID p_env, bool p_enable, float p_distance, float p_transition, float p_amount, GD_VS::EnvironmentDOFBlurQuality p_quality); - virtual void environment_set_dof_blur_far(RID p_env, bool p_enable, float p_distance, float p_transition, float p_amount, GD_VS::EnvironmentDOFBlurQuality p_quality); - - virtual void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_threshold, GD_VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, bool p_bicubic_upscale); - virtual void environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture); - - virtual void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_in, float p_fade_out, float p_depth_tolerance, bool p_roughness); - virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect, float p_ao_channel_affect, const Color &p_color, GD_VS::EnvironmentSSAOQuality p_quality, GD_VS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness); - - virtual void environment_set_tonemap(RID p_env, GD_VS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale); - - virtual void environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, RID p_ramp); - - virtual void environment_set_fog(RID p_env, bool p_enable, const Color &p_color, const Color &p_sun_color, float p_sun_amount); - virtual void environment_set_fog_depth(RID p_env, bool p_enable, float p_depth_begin, float p_depth_end, float p_depth_curve, bool p_transmit, float p_transmit_curve); - virtual void environment_set_fog_height(RID p_env, bool p_enable, float p_min_height, float p_max_height, float p_height_curve); - - virtual bool is_environment(RID p_env); - - virtual GD_VS::EnvironmentBG environment_get_background(RID p_env); - virtual int environment_get_canvas_max_layer(RID p_env); - - /* LIGHT INSTANCE */ - - struct LightInstance : public RID_Data { - struct ShadowTransform { - CameraMatrix camera; - Transform3D transform; - float farplane; - float split; - float bias_scale; - }; - - ShadowTransform shadow_transform[4]; - - RID self; - RID light; - - RasterizerStorageGLES2::Light *light_ptr; - Transform3D transform; - - Vector3 light_vector; - Vector3 spot_vector; - float linear_att; - - // TODO passes and all that stuff ? - uint64_t last_scene_pass; - uint64_t last_scene_shadow_pass; - - uint16_t light_index; - uint16_t light_directional_index; - - Rect2 directional_rect; - - Set<RID> shadow_atlases; // atlases where this light is registered - }; - - mutable RID_Owner<LightInstance> light_instance_owner; - - virtual RID light_instance_create(RID p_light); - virtual void light_instance_set_transform(RID p_light_instance, const Transform3D &p_transform); - virtual void light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform3D &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 bool light_instances_can_render_shadow_cube() const { return storage->config.support_shadow_cubemaps; } - - LightInstance **render_light_instances; - int render_directional_lights; - int render_light_instance_count; - - /* REFLECTION INSTANCE */ - - virtual RID gi_probe_instance_create(); - virtual void gi_probe_instance_set_light_data(RID p_probe, RID p_base, RID p_data); - virtual void gi_probe_instance_set_transform_to_data(RID p_probe, const Transform3D &p_xform); - virtual void gi_probe_instance_set_bounds(RID p_probe, const Vector3 &p_bounds); - - /* RENDER LIST */ - - enum LightMode { - LIGHTMODE_NORMAL, - LIGHTMODE_UNSHADED, - LIGHTMODE_LIGHTMAP, - LIGHTMODE_LIGHTMAP_CAPTURE, - }; - - struct RenderList { - enum { - MAX_LIGHTS = 255, - MAX_REFLECTION_PROBES = 255, - DEFAULT_MAX_ELEMENTS = 65536 - }; - - int max_elements; - - struct Element { - InstanceBaseDependency *instance; - - RasterizerStorageGLES2::Geometry *geometry; - RasterizerStorageGLES2::Material *material; - RasterizerStorageGLES2::GeometryOwner *owner; - - bool use_accum; //is this an add pass for multipass - bool *use_accum_ptr; - bool front_facing; - - union { - //TODO: should be endian swapped on big endian - struct { - int32_t depth_layer : 16; - int32_t priority : 16; - }; - - uint32_t depth_key; - }; - - union { - struct { - //from least significant to most significant in sort, TODO: should be endian swapped on big endian - - uint64_t geometry_index : 14; - uint64_t instancing : 1; - uint64_t skeleton : 1; - uint64_t shader_index : 10; - uint64_t material_index : 10; - uint64_t light_index : 8; - uint64_t light_type2 : 1; // if 1==0 : nolight/directional, else omni/spot - uint64_t refprobe_1_index : 8; - uint64_t refprobe_0_index : 8; - uint64_t light_type1 : 1; //no light, directional is 0, omni spot is 1 - uint64_t light_mode : 2; // LightMode enum - }; - - uint64_t sort_key; - }; - }; - - Element *base_elements; - Element **elements; - - int element_count; - int alpha_element_count; - - void clear() { - element_count = 0; - alpha_element_count = 0; - } - - // sorts - - struct SortByKey { - _FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const { - if (A->depth_key == B->depth_key) { - return A->sort_key < B->sort_key; - } else { - return A->depth_key < B->depth_key; - } - } - }; - - void sort_by_key(bool p_alpha) { - SortArray<Element *, SortByKey> sorter; - - if (p_alpha) { - sorter.sort(&elements[max_elements - alpha_element_count], alpha_element_count); - } else { - sorter.sort(elements, element_count); - } - } - - struct SortByDepth { - _FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const { - return A->instance->depth < B->instance->depth; - } - }; - - void sort_by_depth(bool p_alpha) { //used for shadows - - SortArray<Element *, SortByDepth> sorter; - if (p_alpha) { - sorter.sort(&elements[max_elements - alpha_element_count], alpha_element_count); - } else { - sorter.sort(elements, element_count); - } - } - - struct SortByReverseDepthAndPriority { - _FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const { - if (A->priority == B->priority) { - return A->instance->depth > B->instance->depth; - } else { - return A->priority < B->priority; - } - } - }; - - void sort_by_reverse_depth_and_priority(bool p_alpha) { //used for alpha - - SortArray<Element *, SortByReverseDepthAndPriority> sorter; - if (p_alpha) { - sorter.sort(&elements[max_elements - alpha_element_count], alpha_element_count); - } else { - sorter.sort(elements, element_count); - } - } - - // element adding and stuff - - _FORCE_INLINE_ Element *add_element() { - if (element_count + alpha_element_count >= max_elements) - return NULL; - - elements[element_count] = &base_elements[element_count]; - return elements[element_count++]; - } - - _FORCE_INLINE_ Element *add_alpha_element() { - if (element_count + alpha_element_count >= max_elements) { - return NULL; - } - - int idx = max_elements - alpha_element_count - 1; - elements[idx] = &base_elements[idx]; - alpha_element_count++; - return elements[idx]; - } - - void init() { - element_count = 0; - alpha_element_count = 0; - - elements = memnew_arr(Element *, max_elements); - base_elements = memnew_arr(Element, max_elements); - - for (int i = 0; i < max_elements; i++) { - elements[i] = &base_elements[i]; - } - } - - RenderList() { - max_elements = DEFAULT_MAX_ELEMENTS; - } - - ~RenderList() { - memdelete_arr(elements); - memdelete_arr(base_elements); - } - }; - - RenderList render_list; - - void _add_geometry(RasterizerStorageGLES2::Geometry *p_geometry, InstanceBase *p_instance, RasterizerStorageGLES2::GeometryOwner *p_owner, int p_material, bool p_depth_pass, bool p_shadow_pass); - void _add_geometry_with_material(RasterizerStorageGLES2::Geometry *p_geometry, InstanceBase *p_instance, RasterizerStorageGLES2::GeometryOwner *p_owner, RasterizerStorageGLES2::Material *p_material, bool p_depth_pass, bool p_shadow_pass); - - void _copy_texture_to_buffer(GLuint p_texture, GLuint p_buffer); - void _fill_render_list(InstanceBase **p_cull_result, int p_cull_count, bool p_depth_pass, bool p_shadow_pass); - void _render_render_list(RenderList::Element **p_elements, int p_element_count, - const Transform3D &p_view_transform, - const CameraMatrix &p_projection, - RID p_shadow_atlas, - Environment *p_env, - GLuint p_base_env, - float p_shadow_bias, - float p_shadow_normal_bias, - bool p_reverse_cull, - bool p_alpha_pass, - bool p_shadow); - - void _draw_sky(RasterizerStorageGLES2::Sky *p_sky, const CameraMatrix &p_projection, const Transform3D &p_transform, bool p_vflip, float p_custom_fov, float p_energy, const Basis &p_sky_orientation); - - _FORCE_INLINE_ void _set_cull(bool p_front, bool p_disabled, bool p_reverse_cull); - _FORCE_INLINE_ bool _setup_material(RasterizerStorageGLES2::Material *p_material, bool p_alpha_pass, Size2i p_skeleton_tex_size = Size2i(0, 0)); - _FORCE_INLINE_ void _setup_geometry(RenderList::Element *p_element, RasterizerStorageGLES2::Skeleton *p_skeleton); - _FORCE_INLINE_ void _setup_light_type(LightInstance *p_light, ShadowAtlas *shadow_atlas); - _FORCE_INLINE_ void _setup_light(LightInstance *p_light, ShadowAtlas *shadow_atlas, const Transform3D &p_view_transform, bool accum_pass); - _FORCE_INLINE_ void _setup_refprobes(ReflectionProbeInstance *p_refprobe1, ReflectionProbeInstance *p_refprobe2, const Transform3D &p_view_transform, Environment *p_env); - _FORCE_INLINE_ void _render_geometry(RenderList::Element *p_element); - - void _post_process(Environment *env, const CameraMatrix &p_cam_projection); - - virtual void render_scene(const Transform3D &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); - virtual void render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, InstanceBase **p_cull_result, int p_cull_count); - virtual bool free(RID p_rid); - - virtual void set_scene_pass(uint64_t p_pass); - virtual void set_debug_draw_mode(GD_VS::ViewportDebugDraw p_debug_draw); - - void iteration(); - void initialize(); - void finalize(); - RasterizerSceneGLES2(); -}; - -#endif // godot 3 - -#endif // GLES2_BACKEND_ENABLED diff --git a/drivers/gles2/rasterizer_storage_gles2.h b/drivers/gles2/rasterizer_storage_gles2.h deleted file mode 100644 index e2db7feefb..0000000000 --- a/drivers/gles2/rasterizer_storage_gles2.h +++ /dev/null @@ -1,1093 +0,0 @@ -/*************************************************************************/ -/* rasterizer_storage_gles2.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 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 */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef RASTERIZERSTORAGEGLES2_H -#define RASTERIZERSTORAGEGLES2_H - -#include "drivers/gles_common/rasterizer_platforms.h" -#ifdef GLES2_BACKEND_ENABLED - -#include "core/templates/local_vector.h" -#include "core/templates/rid_owner.h" -#include "core/templates/self_list.h" -#include "drivers/gles_common/rasterizer_asserts.h" -#include "drivers/gles_common/rasterizer_common_stubs.h" -#include "drivers/gles_common/rasterizer_version.h" -#include "servers/rendering/renderer_compositor.h" -#include "servers/rendering/shader_language.h" -#include "shader_compiler_gles2.h" -#include "shader_gles2.h" - -#include "shaders/copy.glsl.gen.h" -#include "shaders/cubemap_filter.glsl.gen.h" - -class RasterizerCanvasGLES2; -class RasterizerSceneGLES2; - -class RasterizerStorageGLES2 : public StubsStorage { - friend class RasterizerGLES2; - - Thread::ID _main_thread_id = 0; - bool _is_main_thread(); - -public: - RasterizerCanvasGLES2 *canvas; - RasterizerSceneGLES2 *scene; - - static GLuint system_fbo; - - struct Config { - bool shrink_textures_x2; - bool use_fast_texture_filter; - bool use_skeleton_software; - - int max_vertex_texture_image_units; - int max_texture_image_units; - int max_texture_size; - - // TODO implement wireframe in GLES2 - // bool generate_wireframes; - - Set<String> extensions; - - bool float_texture_supported; - bool s3tc_supported; - bool etc1_supported; - bool pvrtc_supported; - bool rgtc_supported; - bool bptc_supported; - - bool keep_original_textures; - - bool force_vertex_shading; - - bool use_rgba_2d_shadows; - bool use_rgba_3d_shadows; - - bool support_32_bits_indices; - bool support_write_depth; - bool support_half_float_vertices; - bool support_npot_repeat_mipmap; - bool support_depth_texture; - bool support_depth_cubemaps; - - bool support_shadow_cubemaps; - - bool multisample_supported; - bool render_to_mipmap_supported; - - GLuint depth_internalformat; - GLuint depth_type; - GLuint depth_buffer_internalformat; - - // in some cases the legacy render didn't orphan. We will mark these - // so the user can switch orphaning off for them. - bool should_orphan; - } config; - - struct Resources { - GLuint white_tex; - GLuint black_tex; - GLuint normal_tex; - GLuint aniso_tex; - - GLuint mipmap_blur_fbo; - GLuint mipmap_blur_color; - - GLuint radical_inverse_vdc_cache_tex; - bool use_rgba_2d_shadows; - - GLuint quadie; - - size_t skeleton_transform_buffer_size; - GLuint skeleton_transform_buffer; - LocalVector<float> skeleton_transform_cpu_buffer; - - } resources; - - mutable struct Shaders { - ShaderCompilerGLES2 compiler; - - CopyShaderGLES2 copy; - CubemapFilterShaderGLES2 cubemap_filter; - - ShaderCompilerGLES2::IdentifierActions actions_canvas; - ShaderCompilerGLES2::IdentifierActions actions_scene; - ShaderCompilerGLES2::IdentifierActions actions_particles; - - } shaders; - - struct Info { - uint64_t texture_mem; - uint64_t vertex_mem; - - struct Render { - uint32_t object_count; - uint32_t draw_call_count; - uint32_t material_switch_count; - uint32_t surface_switch_count; - uint32_t shader_rebind_count; - uint32_t vertices_count; - uint32_t _2d_item_count; - uint32_t _2d_draw_call_count; - - void reset() { - object_count = 0; - draw_call_count = 0; - material_switch_count = 0; - surface_switch_count = 0; - shader_rebind_count = 0; - vertices_count = 0; - _2d_item_count = 0; - _2d_draw_call_count = 0; - } - } render, render_final, snap; - - Info() : - texture_mem(0), - vertex_mem(0) { - render.reset(); - render_final.reset(); - } - - } info; - - void bind_quad_array() const; - - ///////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////DATA/////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////////////////// - - /* - struct Instantiable { - RID self; - - SelfList<InstanceBaseDependency>::List instance_list; - - _FORCE_INLINE_ void instance_change_notify(bool p_aabb, bool p_materials) { - SelfList<InstanceBaseDependency> *instances = instance_list.first(); - while (instances) { - instances->self()->base_changed(p_aabb, p_materials); - instances = instances->next(); - } - } - - _FORCE_INLINE_ void instance_remove_deps() { - SelfList<InstanceBaseDependency> *instances = instance_list.first(); - - while (instances) { - instances->self()->base_removed(); - instances = instances->next(); - } - } - - Instantiable() {} - - virtual ~Instantiable() {} - }; - - struct GeometryOwner : public Instantiable { - }; - - struct Geometry : public Instantiable { - enum Type { - GEOMETRY_INVALID, - GEOMETRY_SURFACE, - GEOMETRY_IMMEDIATE, - GEOMETRY_MULTISURFACE - }; - - Type type; - RID material; - uint64_t last_pass; - uint32_t index; - - virtual void material_changed_notify() {} - - Geometry() { - last_pass = 0; - index = 0; - } - }; -*/ - ///////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////API//////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////////////////// - - // TEXTURE API - - enum GLESTextureFlags { - TEXTURE_FLAG_MIPMAPS = 1, /// Enable automatic mipmap generation - when available - TEXTURE_FLAG_REPEAT = 2, /// Repeat texture (Tiling), otherwise Clamping - TEXTURE_FLAG_FILTER = 4, /// Create texture with linear (or available) filter - TEXTURE_FLAG_ANISOTROPIC_FILTER = 8, - TEXTURE_FLAG_CONVERT_TO_LINEAR = 16, - TEXTURE_FLAG_MIRRORED_REPEAT = 32, /// Repeat texture, with alternate sections mirrored - TEXTURE_FLAG_USED_FOR_STREAMING = 2048, - TEXTURE_FLAGS_DEFAULT = TEXTURE_FLAG_REPEAT | TEXTURE_FLAG_MIPMAPS | TEXTURE_FLAG_FILTER - }; - - struct RenderTarget; - - struct Texture { - RID self; - - Texture *proxy; - Set<Texture *> proxy_owners; - - String path; - uint32_t flags; - int width, height, depth; - int alloc_width, alloc_height; - Image::Format format; - GD_RD::TextureType type; - - GLenum target; - GLenum gl_format_cache; - GLenum gl_internal_format_cache; - GLenum gl_type_cache; - - int data_size; - int total_data_size; - bool ignore_mipmaps; - - bool compressed; - - bool srgb; - - int mipmaps; - - bool resize_to_po2; - - bool active; - GLenum tex_id; - - uint16_t stored_cube_sides; - - RenderTarget *render_target; - - Vector<Ref<Image>> images; - - bool redraw_if_visible; - - GD_VS::TextureDetectCallback detect_3d; - void *detect_3d_ud; - - GD_VS::TextureDetectCallback detect_srgb; - void *detect_srgb_ud; - - GD_VS::TextureDetectCallback detect_normal; - void *detect_normal_ud; - - // some silly opengl shenanigans where - // texture coords start from bottom left, means we need to draw render target textures upside down - // to be compatible with vulkan etc. - bool is_upside_down() const { - if (proxy) - return proxy->is_upside_down(); - - return render_target != nullptr; - } - - Texture() { - create(); - } - - _ALWAYS_INLINE_ Texture *get_ptr() { - if (proxy) { - return proxy; //->get_ptr(); only one level of indirection, else not inlining possible. - } else { - return this; - } - } - - ~Texture() { - destroy(); - - if (tex_id != 0) { - glDeleteTextures(1, &tex_id); - } - } - - void copy_from(const Texture &o) { - proxy = o.proxy; - flags = o.flags; - width = o.width; - height = o.height; - alloc_width = o.alloc_width; - alloc_height = o.alloc_height; - format = o.format; - type = o.type; - target = o.target; - data_size = o.data_size; - total_data_size = o.total_data_size; - ignore_mipmaps = o.ignore_mipmaps; - compressed = o.compressed; - mipmaps = o.mipmaps; - resize_to_po2 = o.resize_to_po2; - active = o.active; - tex_id = o.tex_id; - stored_cube_sides = o.stored_cube_sides; - render_target = o.render_target; - redraw_if_visible = o.redraw_if_visible; - detect_3d = o.detect_3d; - detect_3d_ud = o.detect_3d_ud; - detect_srgb = o.detect_srgb; - detect_srgb_ud = o.detect_srgb_ud; - detect_normal = o.detect_normal; - detect_normal_ud = o.detect_normal_ud; - - images.clear(); - } - - void create() { - proxy = nullptr; - flags = 0; - width = 0; - height = 0; - alloc_width = 0; - alloc_height = 0; - format = Image::FORMAT_L8; - type = GD_RD::TEXTURE_TYPE_2D; - target = 0; - data_size = 0; - total_data_size = 0; - ignore_mipmaps = false; - compressed = false; - mipmaps = 0; - resize_to_po2 = false; - active = false; - tex_id = 0; - stored_cube_sides = 0; - render_target = nullptr; - redraw_if_visible = false; - detect_3d = nullptr; - detect_3d_ud = nullptr; - detect_srgb = nullptr; - detect_srgb_ud = nullptr; - detect_normal = nullptr; - detect_normal_ud = nullptr; - } - void destroy() { - images.clear(); - - for (Set<Texture *>::Element *E = proxy_owners.front(); E; E = E->next()) { - E->get()->proxy = NULL; - } - - if (proxy) { - proxy->proxy_owners.erase(this); - } - } - - // texture state - void GLSetFilter(GLenum p_target, RS::CanvasItemTextureFilter p_filter) { - if (p_filter == state_filter) - return; - state_filter = p_filter; - GLint pmin = GL_LINEAR; // param min - GLint pmag = GL_LINEAR; // param mag - switch (state_filter) { - default: { - } break; - case RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS: { - pmin = GL_LINEAR_MIPMAP_LINEAR; - pmag = GL_LINEAR; - } break; - case RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST: { - pmin = GL_NEAREST; - pmag = GL_NEAREST; - } break; - case RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS: { - pmin = GL_NEAREST_MIPMAP_NEAREST; - pmag = GL_NEAREST; - } break; - } - glTexParameteri(p_target, GL_TEXTURE_MIN_FILTER, pmin); - glTexParameteri(p_target, GL_TEXTURE_MAG_FILTER, pmag); - } - void GLSetRepeat(RS::CanvasItemTextureRepeat p_repeat) { - if (p_repeat == state_repeat) - return; - state_repeat = p_repeat; - GLint prep = GL_CLAMP_TO_EDGE; // parameter repeat - switch (state_repeat) { - default: { - } break; - case RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED: { - prep = GL_REPEAT; - } break; - case RS::CANVAS_ITEM_TEXTURE_REPEAT_MIRROR: { - prep = GL_MIRRORED_REPEAT; - } break; - } - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, prep); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, prep); - } - - private: - RS::CanvasItemTextureFilter state_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR; - RS::CanvasItemTextureRepeat state_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED; - }; - - mutable RID_PtrOwner<Texture> texture_owner; - - Ref<Image> _get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, Image::Format &r_real_format, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool p_force_decompress) const; - - void _texture_set_state_from_flags(Texture *p_tex); - - // new - RID texture_allocate() override; - void texture_2d_initialize(RID p_texture, const Ref<Image> &p_image) override; - - // RID texture_2d_create(const Ref<Image> &p_image) override; - // RID texture_2d_layered_create(const Vector<Ref<Image>> &p_layers, RS::TextureLayeredType p_layered_type) override; - // RID texture_3d_create(Image::Format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_data) override { return RID(); } - //RID texture_proxy_create(RID p_base) override; - - //void texture_2d_update_immediate(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) override; - void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) override; - void texture_3d_update(RID p_texture, const Vector<Ref<Image>> &p_data) override {} - void texture_proxy_update(RID p_proxy, RID p_base) override {} - - //RID texture_2d_placeholder_create() override; - //RID texture_2d_layered_placeholder_create(RenderingServer::TextureLayeredType p_layered_type) override { return RID(); } - //RID texture_3d_placeholder_create() override { return RID(); } - - Ref<Image> texture_2d_get(RID p_texture) const override; - Ref<Image> texture_2d_layer_get(RID p_texture, int p_layer) const override { return Ref<Image>(); } - Vector<Ref<Image>> texture_3d_get(RID p_texture) const override { return Vector<Ref<Image>>(); } - - void texture_replace(RID p_texture, RID p_by_texture) override; - //void texture_set_size_override(RID p_texture, int p_width, int p_height) override {} - - void texture_add_to_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override {} - void texture_remove_from_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override {} - - // old - virtual uint32_t texture_get_width(RID p_texture) const; - virtual uint32_t texture_get_height(RID p_texture) const; - -private: - virtual RID texture_create(); - - //virtual void texture_allocate(RID p_texture, int p_width, int p_height, int p_depth_3d, Image::Format p_format, GD_RD::TextureType p_type, uint32_t p_flags = TEXTURE_FLAGS_DEFAULT); - void _texture_allocate_internal(RID p_texture, int p_width, int p_height, int p_depth_3d, Image::Format p_format, GD_RD::TextureType p_type, uint32_t p_flags = TEXTURE_FLAGS_DEFAULT); - - virtual void texture_set_data(RID p_texture, const Ref<Image> &p_image, int p_layer = 0); - virtual void texture_set_data_partial(RID p_texture, const Ref<Image> &p_image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int p_dst_mip, int p_layer = 0); - //virtual Ref<Image> texture_get_data(RID p_texture, int p_layer = 0) const; - virtual void texture_set_flags(RID p_texture, uint32_t p_flags); - virtual uint32_t texture_get_flags(RID p_texture) const; - virtual Image::Format texture_get_format(RID p_texture) const; - virtual GD_RD::TextureType texture_get_type(RID p_texture) const; - virtual uint32_t texture_get_texid(RID p_texture) const; - virtual uint32_t texture_get_depth(RID p_texture) const; - void texture_set_size_override(RID p_texture, int p_width, int p_height) override; - - virtual void texture_bind(RID p_texture, uint32_t p_texture_no); - - virtual void texture_set_path(RID p_texture, const String &p_path) override; - virtual String texture_get_path(RID p_texture) const override; - - virtual void texture_set_shrink_all_x2_on_set_data(bool p_enable); - - virtual void texture_debug_usage(List<GD_VS::TextureInfo> *r_info) override; - - virtual RID texture_create_radiance_cubemap(RID p_source, int p_resolution = -1) const; - - virtual void textures_keep_original(bool p_enable); - - virtual void texture_set_proxy(RID p_texture, RID p_proxy); - virtual Size2 texture_size_with_proxy(RID p_texture) override; - - virtual void texture_set_detect_3d_callback(RID p_texture, GD_VS::TextureDetectCallback p_callback, void *p_userdata) override; - virtual void texture_set_detect_srgb_callback(RID p_texture, GD_VS::TextureDetectCallback p_callback, void *p_userdata); - virtual void texture_set_detect_normal_callback(RID p_texture, GD_VS::TextureDetectCallback p_callback, void *p_userdata) override; - void texture_set_detect_roughness_callback(RID p_texture, RS::TextureDetectRoughnessCallback p_callback, void *p_userdata) override {} - - virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) override; - -public: - // CANVAS TEXTURE API - /* - RID canvas_texture_create() override { return RID(); } - void canvas_texture_set_channel(RID p_canvas_texture, RS::CanvasTextureChannel p_channel, RID p_texture) override {} - void canvas_texture_set_shading_parameters(RID p_canvas_texture, const Color &p_base_color, float p_shininess) override {} - - void canvas_texture_set_texture_filter(RID p_item, RS::CanvasItemTextureFilter p_filter) override {} - void canvas_texture_set_texture_repeat(RID p_item, RS::CanvasItemTextureRepeat p_repeat) override {} - */ - /* SKY API */ - // not sure if used in godot 4? - struct Sky { - RID self; - RID panorama; - GLuint radiance; - int radiance_size; - }; - - mutable RID_PtrOwner<Sky> sky_owner; - - virtual RID sky_create(); - virtual void sky_set_texture(RID p_sky, RID p_panorama, int p_radiance_size); - - // SHADER API - - struct Material; - - struct Shader { - RID self; - - GD_VS::ShaderMode mode; - ShaderGLES2 *shader; - String code; - SelfList<Material>::List materials; - - Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms; - - uint32_t texture_count; - - uint32_t custom_code_id; - uint32_t version; - - SelfList<Shader> dirty_list; - - Map<StringName, RID> default_textures; - - Vector<ShaderLanguage::ShaderNode::Uniform::Hint> texture_hints; - - bool valid; - - String path; - - uint32_t index; - uint64_t last_pass; - - struct CanvasItem { - enum BlendMode { - BLEND_MODE_MIX, - BLEND_MODE_ADD, - BLEND_MODE_SUB, - BLEND_MODE_MUL, - BLEND_MODE_PMALPHA, - }; - - int blend_mode; - - enum LightMode { - LIGHT_MODE_NORMAL, - LIGHT_MODE_UNSHADED, - LIGHT_MODE_LIGHT_ONLY - }; - - int light_mode; - - // these flags are specifically for batching - // some of the logic is thus in rasterizer_storage.cpp - // we could alternatively set bitflags for each 'uses' and test on the fly - // defined in RasterizerStorageCommon::BatchFlags - unsigned int batch_flags; - - bool uses_screen_texture; - bool uses_screen_uv; - bool uses_time; - bool uses_modulate; - bool uses_color; - bool uses_vertex; - - // all these should disable item joining if used in a custom shader - bool uses_world_matrix; - bool uses_extra_matrix; - bool uses_projection_matrix; - bool uses_instance_custom; - - } canvas_item; - - struct Spatial { - enum BlendMode { - BLEND_MODE_MIX, - BLEND_MODE_ADD, - BLEND_MODE_SUB, - BLEND_MODE_MUL, - }; - - int blend_mode; - - enum DepthDrawMode { - DEPTH_DRAW_OPAQUE, - DEPTH_DRAW_ALWAYS, - DEPTH_DRAW_NEVER, - DEPTH_DRAW_ALPHA_PREPASS, - }; - - int depth_draw_mode; - - enum CullMode { - CULL_MODE_FRONT, - CULL_MODE_BACK, - CULL_MODE_DISABLED, - }; - - int cull_mode; - - bool uses_alpha; - bool uses_alpha_scissor; - bool unshaded; - bool no_depth_test; - bool uses_vertex; - bool uses_discard; - bool uses_sss; - bool uses_screen_texture; - bool uses_depth_texture; - bool uses_time; - bool uses_tangent; - bool uses_ensure_correct_normals; - bool writes_modelview_or_projection; - bool uses_vertex_lighting; - bool uses_world_coordinates; - - } spatial; - - struct Particles { - } particles; - - bool uses_vertex_time; - bool uses_fragment_time; - - Shader() : - dirty_list(this) { - shader = NULL; - valid = false; - custom_code_id = 0; - version = 1; - last_pass = 0; - } - }; - - mutable RID_PtrOwner<Shader> shader_owner; - mutable SelfList<Shader>::List _shader_dirty_list; - - void _shader_make_dirty(Shader *p_shader); - - RID shader_allocate() override; - void shader_initialize(RID p_rid) override; - - //virtual RID shader_create() override; - - virtual void shader_set_code(RID p_shader, const String &p_code) override; - virtual String shader_get_code(RID p_shader) const override; - virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const override; - - virtual void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) override; - virtual RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const override; - - virtual RS::ShaderNativeSourceCode shader_get_native_source_code(RID p_shader) const override { return RS::ShaderNativeSourceCode(); }; - - virtual void shader_add_custom_define(RID p_shader, const String &p_define); - virtual void shader_get_custom_defines(RID p_shader, Vector<String> *p_defines) const; - virtual void shader_remove_custom_define(RID p_shader, const String &p_define); - - void _update_shader(Shader *p_shader) const; - void update_dirty_shaders(); - - // new - Variant shader_get_param_default(RID p_material, const StringName &p_param) const override { return Variant(); } - - // COMMON MATERIAL API - - struct Material { - RID self; - Shader *shader; - Map<StringName, Variant> params; - SelfList<Material> list; - SelfList<Material> dirty_list; - Vector<Pair<StringName, RID>> textures; - float line_width; - int render_priority; - - RID next_pass; - - uint32_t index; - uint64_t last_pass; - - // Map<Geometry *, int> geometry_owners; - // Map<InstanceBaseDependency *, int> instance_owners; - - bool can_cast_shadow_cache; - bool is_animated_cache; - - Material() : - list(this), - dirty_list(this) { - can_cast_shadow_cache = false; - is_animated_cache = false; - shader = NULL; - line_width = 1.0; - last_pass = 0; - render_priority = 0; - } - }; - - mutable SelfList<Material>::List _material_dirty_list; - void _material_make_dirty(Material *p_material) const; - - // void _material_add_geometry(RID p_material, Geometry *p_geometry); - // void _material_remove_geometry(RID p_material, Geometry *p_geometry); - - void _update_material(Material *p_material); - - mutable RID_PtrOwner<Material> material_owner; - - // new - void material_get_instance_shader_parameters(RID p_material, List<InstanceShaderParam> *r_parameters) override {} - void material_update_dependency(RID p_material, DependencyTracker *p_instance) override {} - - // old - RID material_allocate() override; - void material_initialize(RID p_rid) override; - - //virtual RID material_create() override; - - virtual void material_set_shader(RID p_material, RID p_shader) override; - virtual RID material_get_shader(RID p_material) const; - - virtual void material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) override; - virtual Variant material_get_param(RID p_material, const StringName &p_param) const override; - virtual Variant material_get_param_default(RID p_material, const StringName &p_param) const; - - virtual void material_set_line_width(RID p_material, float p_width); - virtual void material_set_next_pass(RID p_material, RID p_next_material) override; - - virtual bool material_is_animated(RID p_material) override; - virtual bool material_casts_shadows(RID p_material) override; - virtual bool material_uses_tangents(RID p_material); - virtual bool material_uses_ensure_correct_normals(RID p_material); - - virtual void material_add_instance_owner(RID p_material, DependencyTracker *p_instance); - virtual void material_remove_instance_owner(RID p_material, DependencyTracker *p_instance); - - virtual void material_set_render_priority(RID p_material, int priority) override; - - void update_dirty_materials(); - - // RENDER TARGET - - struct RenderTarget { - RID self; - GLuint fbo; - GLuint color; - GLuint depth; - - GLuint multisample_fbo; - GLuint multisample_color; - GLuint multisample_depth; - bool multisample_active; - - struct Effect { - GLuint fbo; - int width; - int height; - - GLuint color; - - Effect() : - fbo(0), - width(0), - height(0), - color(0) { - } - }; - - Effect copy_screen_effect; - - struct MipMaps { - struct Size { - GLuint fbo; - GLuint color; - int width; - int height; - }; - - Vector<Size> sizes; - GLuint color; - int levels; - - MipMaps() : - color(0), - levels(0) { - } - }; - - MipMaps mip_maps[2]; - - struct External { - GLuint fbo; - GLuint color; - GLuint depth; - RID texture; - - External() : - fbo(0), - color(0), - depth(0) { - } - } external; - - int x, y, width, height; - - bool flags[RENDER_TARGET_FLAG_MAX]; - - // instead of allocating sized render targets immediately, - // defer this for faster startup - bool allocate_is_dirty = false; - bool used_in_frame; - GD_VS::ViewportMSAA msaa; - - bool use_fxaa; - bool use_debanding; - - RID texture; - - bool used_dof_blur_near; - bool mip_maps_allocated; - - Color clear_color; - bool clear_requested; - - RenderTarget() : - fbo(0), - color(0), - depth(0), - multisample_fbo(0), - multisample_color(0), - multisample_depth(0), - multisample_active(false), - x(0), - y(0), - width(0), - height(0), - used_in_frame(false), - msaa(GD_VS::VIEWPORT_MSAA_DISABLED), - use_fxaa(false), - use_debanding(false), - used_dof_blur_near(false), - mip_maps_allocated(false), - clear_color(Color(1, 1, 1, 1)), - clear_requested(false) { - for (int i = 0; i < RENDER_TARGET_FLAG_MAX; ++i) { - flags[i] = false; - } - external.fbo = 0; - } - }; - - mutable RID_PtrOwner<RenderTarget> render_target_owner; - - void _render_target_clear(RenderTarget *rt); - void _render_target_allocate(RenderTarget *rt); - void _set_current_render_target(RID p_render_target); - - virtual RID render_target_create() override; - virtual void render_target_set_position(RID p_render_target, int p_x, int p_y) override; - virtual void render_target_set_size(RID p_render_target, int p_width, int p_height, uint32_t p_view_count) override; - virtual RID render_target_get_texture(RID p_render_target) override; - virtual void render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id) override; - - virtual void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value) override; - virtual bool render_target_was_used(RID p_render_target) override; - virtual void render_target_clear_used(RID p_render_target); - virtual void render_target_set_msaa(RID p_render_target, GD_VS::ViewportMSAA p_msaa); - virtual void render_target_set_use_fxaa(RID p_render_target, bool p_fxaa); - virtual void render_target_set_use_debanding(RID p_render_target, bool p_debanding); - - // new - void render_target_set_as_unused(RID p_render_target) override { render_target_clear_used(p_render_target); } - - void render_target_request_clear(RID p_render_target, const Color &p_clear_color) override; - bool render_target_is_clear_requested(RID p_render_target) override; - Color render_target_get_clear_request_color(RID p_render_target) override; - void render_target_disable_clear_request(RID p_render_target) override; - void render_target_do_clear_request(RID p_render_target) override; - - // access from canvas - // RenderTarget * render_target_get(RID p_render_target); - - /* CANVAS SHADOW */ - - struct CanvasLightShadow { - RID self; - int size; - int height; - GLuint fbo; - GLuint depth; - GLuint distance; //for older devices - }; - - RID_PtrOwner<CanvasLightShadow> canvas_light_shadow_owner; - - virtual RID canvas_light_shadow_buffer_create(int p_width); - - /* LIGHT SHADOW MAPPING */ - /* - struct CanvasOccluder { - RID self; - - GLuint vertex_id; // 0 means, unconfigured - GLuint index_id; // 0 means, unconfigured - LocalVector<Vector2> lines; - int len; - }; - - RID_Owner<CanvasOccluder> canvas_occluder_owner; - - virtual RID canvas_light_occluder_create(); - virtual void canvas_light_occluder_set_polylines(RID p_occluder, const LocalVector<Vector2> &p_lines); -*/ - - virtual GD_VS::InstanceType get_base_type(RID p_rid) const override; - - virtual bool free(RID p_rid) override; - - struct Frame { - RenderTarget *current_rt; - - // these 2 may have been superceded by the equivalents in the render target. - // these may be able to be removed. - bool clear_request; - Color clear_request_color; - - float time[4]; - float delta; - uint64_t count; - - Frame() { - // current_rt = nullptr; - // clear_request = false; - } - } frame; - - void initialize(); - void finalize(); - - void _copy_screen(); - - virtual bool has_os_feature(const String &p_feature) const override; - - virtual void update_dirty_resources() override; - - virtual void set_debug_generate_wireframes(bool p_generate) override; - - // virtual void render_info_begin_capture() override; - // virtual void render_info_end_capture() override; - // virtual int get_captured_render_info(GD_VS::RenderInfo p_info) override; - - // virtual int get_render_info(GD_VS::RenderInfo p_info) override; - virtual String get_video_adapter_name() const override; - virtual String get_video_adapter_vendor() const override; - - void capture_timestamps_begin() override {} - void capture_timestamp(const String &p_name) override {} - uint32_t get_captured_timestamps_count() const override { return 0; } - uint64_t get_captured_timestamps_frame() const override { return 0; } - uint64_t get_captured_timestamp_gpu_time(uint32_t p_index) const override { return 0; } - uint64_t get_captured_timestamp_cpu_time(uint32_t p_index) const override { return 0; } - String get_captured_timestamp_name(uint32_t p_index) const override { return String(); } - - // make access easier to these - struct Dimensions { - // render target - int rt_width; - int rt_height; - - // window - int win_width; - int win_height; - Dimensions() { - rt_width = 0; - rt_height = 0; - win_width = 0; - win_height = 0; - } - } _dims; - - void buffer_orphan_and_upload(unsigned int p_buffer_size, unsigned int p_offset, unsigned int p_data_size, const void *p_data, GLenum p_target = GL_ARRAY_BUFFER, GLenum p_usage = GL_DYNAMIC_DRAW, bool p_optional_orphan = false) const; - bool safe_buffer_sub_data(unsigned int p_total_buffer_size, GLenum p_target, unsigned int p_offset, unsigned int p_data_size, const void *p_data, unsigned int &r_offset_after) const; - - void bind_framebuffer(GLuint framebuffer) { - glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); - } - - void bind_framebuffer_system() { - glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES2::system_fbo); - } - - RasterizerStorageGLES2(); -}; - -inline bool RasterizerStorageGLES2::safe_buffer_sub_data(unsigned int p_total_buffer_size, GLenum p_target, unsigned int p_offset, unsigned int p_data_size, const void *p_data, unsigned int &r_offset_after) const { - r_offset_after = p_offset + p_data_size; -#ifdef DEBUG_ENABLED - // we are trying to write across the edge of the buffer - if (r_offset_after > p_total_buffer_size) - return false; -#endif - glBufferSubData(p_target, p_offset, p_data_size, p_data); - return true; -} - -// standardize the orphan / upload in one place so it can be changed per platform as necessary, and avoid future -// bugs causing pipeline stalls -inline void RasterizerStorageGLES2::buffer_orphan_and_upload(unsigned int p_buffer_size, unsigned int p_offset, unsigned int p_data_size, const void *p_data, GLenum p_target, GLenum p_usage, bool p_optional_orphan) const { - // Orphan the buffer to avoid CPU/GPU sync points caused by glBufferSubData - // Was previously #ifndef GLES_OVER_GL however this causes stalls on desktop mac also (and possibly other) - if (!p_optional_orphan || (config.should_orphan)) { - glBufferData(p_target, p_buffer_size, NULL, p_usage); -#ifdef RASTERIZER_EXTRA_CHECKS - // fill with garbage off the end of the array - if (p_buffer_size) { - unsigned int start = p_offset + p_data_size; - unsigned int end = start + 1024; - if (end < p_buffer_size) { - uint8_t *garbage = (uint8_t *)alloca(1024); - for (int n = 0; n < 1024; n++) { - garbage[n] = Math::random(0, 255); - } - glBufferSubData(p_target, start, 1024, garbage); - } - } -#endif - } - RAST_DEV_DEBUG_ASSERT((p_offset + p_data_size) <= p_buffer_size); - glBufferSubData(p_target, p_offset, p_data_size, p_data); -} - -#endif // GLES2_BACKEND_ENABLED -#endif // RASTERIZERSTORAGEGLES2_H diff --git a/drivers/gles2/shaders/SCsub b/drivers/gles2/shaders/SCsub deleted file mode 100644 index bcd6ea79fb..0000000000 --- a/drivers/gles2/shaders/SCsub +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env python - -Import("env") - -if "GLES2_GLSL" in env["BUILDERS"]: - env.GLES2_GLSL("copy.glsl") - # env.GLES2_GLSL('resolve.glsl'); - env.GLES2_GLSL("canvas.glsl") - env.GLES2_GLSL("canvas_shadow.glsl") - env.GLES2_GLSL("scene.glsl") - env.GLES2_GLSL("cubemap_filter.glsl") - env.GLES2_GLSL("cube_to_dp.glsl") - # env.GLES2_GLSL('blend_shape.glsl'); - # env.GLES2_GLSL('screen_space_reflection.glsl'); - env.GLES2_GLSL("effect_blur.glsl") - # env.GLES2_GLSL('subsurf_scattering.glsl'); - # env.GLES2_GLSL('ssao.glsl'); - # env.GLES2_GLSL('ssao_minify.glsl'); - # env.GLES2_GLSL('ssao_blur.glsl'); - # env.GLES2_GLSL('exposure.glsl'); - env.GLES2_GLSL("tonemap.glsl") - # env.GLES2_GLSL('particles.glsl'); - env.GLES2_GLSL("lens_distorted.glsl") diff --git a/drivers/gles2/shaders/blend_shape.glsl b/drivers/gles2/shaders/blend_shape.glsl deleted file mode 100644 index 247e98c7aa..0000000000 --- a/drivers/gles2/shaders/blend_shape.glsl +++ /dev/null @@ -1,192 +0,0 @@ -/* clang-format off */ -[vertex] - -/* -from VisualServer: - -ARRAY_VERTEX=0, -ARRAY_NORMAL=1, -ARRAY_TANGENT=2, -ARRAY_COLOR=3, -ARRAY_TEX_UV=4, -ARRAY_TEX_UV2=5, -ARRAY_BONES=6, -ARRAY_WEIGHTS=7, -ARRAY_INDEX=8, -*/ - -#ifdef USE_2D_VERTEX -#define VFORMAT vec2 -#else -#define VFORMAT vec3 -#endif - -/* INPUT ATTRIBS */ - -layout(location = 0) in highp VFORMAT vertex_attrib; -/* clang-format on */ -layout(location = 1) in vec3 normal_attrib; - -#ifdef ENABLE_TANGENT -layout(location = 2) in vec4 tangent_attrib; -#endif - -#ifdef ENABLE_COLOR -layout(location = 3) in vec4 color_attrib; -#endif - -#ifdef ENABLE_UV -layout(location = 4) in vec2 uv_attrib; -#endif - -#ifdef ENABLE_UV2 -layout(location = 5) in vec2 uv2_attrib; -#endif - -#ifdef ENABLE_SKELETON -layout(location = 6) in ivec4 bone_attrib; -layout(location = 7) in vec4 weight_attrib; -#endif - -/* BLEND ATTRIBS */ - -#ifdef ENABLE_BLEND - -layout(location = 8) in highp VFORMAT vertex_attrib_blend; -layout(location = 9) in vec3 normal_attrib_blend; - -#ifdef ENABLE_TANGENT -layout(location = 10) in vec4 tangent_attrib_blend; -#endif - -#ifdef ENABLE_COLOR -layout(location = 11) in vec4 color_attrib_blend; -#endif - -#ifdef ENABLE_UV -layout(location = 12) in vec2 uv_attrib_blend; -#endif - -#ifdef ENABLE_UV2 -layout(location = 13) in vec2 uv2_attrib_blend; -#endif - -#ifdef ENABLE_SKELETON -layout(location = 14) in ivec4 bone_attrib_blend; -layout(location = 15) in vec4 weight_attrib_blend; -#endif - -#endif - -/* OUTPUTS */ - -out VFORMAT vertex_out; //tfb: - -#ifdef ENABLE_NORMAL -out vec3 normal_out; //tfb:ENABLE_NORMAL -#endif - -#ifdef ENABLE_TANGENT -out vec4 tangent_out; //tfb:ENABLE_TANGENT -#endif - -#ifdef ENABLE_COLOR -out vec4 color_out; //tfb:ENABLE_COLOR -#endif - -#ifdef ENABLE_UV -out vec2 uv_out; //tfb:ENABLE_UV -#endif - -#ifdef ENABLE_UV2 -out vec2 uv2_out; //tfb:ENABLE_UV2 -#endif - -#ifdef ENABLE_SKELETON -out ivec4 bone_out; //tfb:ENABLE_SKELETON -out vec4 weight_out; //tfb:ENABLE_SKELETON -#endif - -uniform float blend_amount; - -void main() { -#ifdef ENABLE_BLEND - - vertex_out = vertex_attrib_blend + vertex_attrib * blend_amount; - -#ifdef ENABLE_NORMAL - normal_out = normal_attrib_blend + normal_attrib * blend_amount; -#endif - -#ifdef ENABLE_TANGENT - - tangent_out.xyz = tangent_attrib_blend.xyz + tangent_attrib.xyz * blend_amount; - tangent_out.w = tangent_attrib_blend.w; //just copy, no point in blending his -#endif - -#ifdef ENABLE_COLOR - - color_out = color_attrib_blend + color_attrib * blend_amount; -#endif - -#ifdef ENABLE_UV - - uv_out = uv_attrib_blend + uv_attrib * blend_amount; -#endif - -#ifdef ENABLE_UV2 - - uv2_out = uv2_attrib_blend + uv2_attrib * blend_amount; -#endif - -#ifdef ENABLE_SKELETON - - bone_out = bone_attrib_blend; - weight_out = weight_attrib_blend + weight_attrib * blend_amount; -#endif - -#else //ENABLE_BLEND - - vertex_out = vertex_attrib * blend_amount; - -#ifdef ENABLE_NORMAL - normal_out = normal_attrib * blend_amount; -#endif - -#ifdef ENABLE_TANGENT - - tangent_out.xyz = tangent_attrib.xyz * blend_amount; - tangent_out.w = tangent_attrib.w; //just copy, no point in blending his -#endif - -#ifdef ENABLE_COLOR - - color_out = color_attrib * blend_amount; -#endif - -#ifdef ENABLE_UV - - uv_out = uv_attrib * blend_amount; -#endif - -#ifdef ENABLE_UV2 - - uv2_out = uv2_attrib * blend_amount; -#endif - -#ifdef ENABLE_SKELETON - - bone_out = bone_attrib; - weight_out = weight_attrib * blend_amount; -#endif - -#endif - gl_Position = vec4(0.0); -} - -/* clang-format off */ -[fragment] - -void main() { -} -/* clang-format on */ diff --git a/drivers/gles2/shaders/exposure.glsl b/drivers/gles2/shaders/exposure.glsl deleted file mode 100644 index c20812bfa3..0000000000 --- a/drivers/gles2/shaders/exposure.glsl +++ /dev/null @@ -1,86 +0,0 @@ -/* clang-format off */ -[vertex] - -layout(location = 0) in highp vec4 vertex_attrib; -/* clang-format on */ - -void main() { - gl_Position = vertex_attrib; -} - -/* clang-format off */ -[fragment] - -uniform highp sampler2D source_exposure; //texunit:0 -/* clang-format on */ - -#ifdef EXPOSURE_BEGIN - -uniform highp ivec2 source_render_size; -uniform highp ivec2 target_size; - -#endif - -#ifdef EXPOSURE_END - -uniform highp sampler2D prev_exposure; //texunit:1 -uniform highp float exposure_adjust; -uniform highp float min_luminance; -uniform highp float max_luminance; - -#endif - -layout(location = 0) out highp float exposure; - -void main() { -#ifdef EXPOSURE_BEGIN - - ivec2 src_pos = ivec2(gl_FragCoord.xy) * source_render_size / target_size; - -#if 1 - //more precise and expensive, but less jittery - ivec2 next_pos = ivec2(gl_FragCoord.xy + ivec2(1)) * source_render_size / target_size; - next_pos = max(next_pos, src_pos + ivec2(1)); //so it at least reads one pixel - highp vec3 source_color = vec3(0.0); - for (int i = src_pos.x; i < next_pos.x; i++) { - for (int j = src_pos.y; j < next_pos.y; j++) { - source_color += texelFetch(source_exposure, ivec2(i, j), 0).rgb; - } - } - - source_color /= float((next_pos.x - src_pos.x) * (next_pos.y - src_pos.y)); -#else - highp vec3 source_color = texelFetch(source_exposure, src_pos, 0).rgb; - -#endif - - exposure = max(source_color.r, max(source_color.g, source_color.b)); - -#else - - ivec2 coord = ivec2(gl_FragCoord.xy); - exposure = texelFetch(source_exposure, coord * 3 + ivec2(0, 0), 0).r; - exposure += texelFetch(source_exposure, coord * 3 + ivec2(1, 0), 0).r; - exposure += texelFetch(source_exposure, coord * 3 + ivec2(2, 0), 0).r; - exposure += texelFetch(source_exposure, coord * 3 + ivec2(0, 1), 0).r; - exposure += texelFetch(source_exposure, coord * 3 + ivec2(1, 1), 0).r; - exposure += texelFetch(source_exposure, coord * 3 + ivec2(2, 1), 0).r; - exposure += texelFetch(source_exposure, coord * 3 + ivec2(0, 2), 0).r; - exposure += texelFetch(source_exposure, coord * 3 + ivec2(1, 2), 0).r; - exposure += texelFetch(source_exposure, coord * 3 + ivec2(2, 2), 0).r; - exposure *= (1.0 / 9.0); - -#ifdef EXPOSURE_END - -#ifdef EXPOSURE_FORCE_SET - //will stay as is -#else - highp float prev_lum = texelFetch(prev_exposure, ivec2(0, 0), 0).r; //1 pixel previous exposure - exposure = clamp(prev_lum + (exposure - prev_lum) * exposure_adjust, min_luminance, max_luminance); - -#endif //EXPOSURE_FORCE_SET - -#endif //EXPOSURE_END - -#endif //EXPOSURE_BEGIN -} diff --git a/drivers/gles2/shaders/particles.glsl b/drivers/gles2/shaders/particles.glsl deleted file mode 100644 index b7fcb94ed2..0000000000 --- a/drivers/gles2/shaders/particles.glsl +++ /dev/null @@ -1,258 +0,0 @@ -/* clang-format off */ -[vertex] - -layout(location = 0) in highp vec4 color; -/* clang-format on */ -layout(location = 1) in highp vec4 velocity_active; -layout(location = 2) in highp vec4 custom; -layout(location = 3) in highp vec4 xform_1; -layout(location = 4) in highp vec4 xform_2; -layout(location = 5) in highp vec4 xform_3; - -struct Attractor { - vec3 pos; - vec3 dir; - float radius; - float eat_radius; - float strength; - float attenuation; -}; - -#define MAX_ATTRACTORS 64 - -uniform bool emitting; -uniform float system_phase; -uniform float prev_system_phase; -uniform int total_particles; -uniform float explosiveness; -uniform float randomness; -uniform float time; -uniform float delta; - -uniform int attractor_count; -uniform Attractor attractors[MAX_ATTRACTORS]; -uniform bool clear; -uniform uint cycle; -uniform float lifetime; -uniform mat4 emission_transform; -uniform uint random_seed; - -out highp vec4 out_color; //tfb: -out highp vec4 out_velocity_active; //tfb: -out highp vec4 out_custom; //tfb: -out highp vec4 out_xform_1; //tfb: -out highp vec4 out_xform_2; //tfb: -out highp vec4 out_xform_3; //tfb: - -#if defined(USE_MATERIAL) - -/* clang-format off */ -layout(std140) uniform UniformData { //ubo:0 - -MATERIAL_UNIFORMS -}; -/* clang-format on */ - -#endif - -/* clang-format off */ - -VERTEX_SHADER_GLOBALS - -/* clang-format on */ - -uint hash(uint x) { - x = ((x >> uint(16)) ^ x) * uint(0x45d9f3b); - x = ((x >> uint(16)) ^ x) * uint(0x45d9f3b); - x = (x >> uint(16)) ^ x; - return x; -} - -void main() { -#ifdef PARTICLES_COPY - - out_color = color; - out_velocity_active = velocity_active; - out_custom = custom; - out_xform_1 = xform_1; - out_xform_2 = xform_2; - out_xform_3 = xform_3; - -#else - - bool apply_forces = true; - bool apply_velocity = true; - float local_delta = delta; - - float mass = 1.0; - - float restart_phase = float(gl_VertexID) / float(total_particles); - - if (randomness > 0.0) { - uint seed = cycle; - if (restart_phase >= system_phase) { - seed -= uint(1); - } - seed *= uint(total_particles); - seed += uint(gl_VertexID); - float random = float(hash(seed) % uint(65536)) / 65536.0; - restart_phase += randomness * random * 1.0 / float(total_particles); - } - - restart_phase *= (1.0 - explosiveness); - bool restart = false; - bool shader_active = velocity_active.a > 0.5; - - if (system_phase > prev_system_phase) { - // restart_phase >= prev_system_phase is used so particles emit in the first frame they are processed - - if (restart_phase >= prev_system_phase && restart_phase < system_phase) { - restart = true; -#ifdef USE_FRACTIONAL_DELTA - local_delta = (system_phase - restart_phase) * lifetime; -#endif - } - - } else { - if (restart_phase >= prev_system_phase) { - restart = true; -#ifdef USE_FRACTIONAL_DELTA - local_delta = (1.0 - restart_phase + system_phase) * lifetime; -#endif - } else if (restart_phase < system_phase) { - restart = true; -#ifdef USE_FRACTIONAL_DELTA - local_delta = (system_phase - restart_phase) * lifetime; -#endif - } - } - - uint current_cycle = cycle; - - if (system_phase < restart_phase) { - current_cycle -= uint(1); - } - - uint particle_number = current_cycle * uint(total_particles) + uint(gl_VertexID); - int index = int(gl_VertexID); - - if (restart) { - shader_active = emitting; - } - - mat4 xform; - -#if defined(ENABLE_KEEP_DATA) - if (clear) { -#else - if (clear || restart) { -#endif - out_color = vec4(1.0); - out_velocity_active = vec4(0.0); - out_custom = vec4(0.0); - if (!restart) - shader_active = false; - - xform = mat4( - vec4(1.0, 0.0, 0.0, 0.0), - vec4(0.0, 1.0, 0.0, 0.0), - vec4(0.0, 0.0, 1.0, 0.0), - vec4(0.0, 0.0, 0.0, 1.0)); - } else { - out_color = color; - out_velocity_active = velocity_active; - out_custom = custom; - xform = transpose(mat4(xform_1, xform_2, xform_3, vec4(vec3(0.0), 1.0))); - } - - if (shader_active) { - //execute shader - - { - /* clang-format off */ - -VERTEX_SHADER_CODE - - /* clang-format on */ - } - -#if !defined(DISABLE_FORCE) - - if (false) { - vec3 force = vec3(0.0); - for (int i = 0; i < attractor_count; i++) { - vec3 rel_vec = xform[3].xyz - attractors[i].pos; - float dist = length(rel_vec); - if (attractors[i].radius < dist) - continue; - if (attractors[i].eat_radius > 0.0 && attractors[i].eat_radius > dist) { - out_velocity_active.a = 0.0; - } - - rel_vec = normalize(rel_vec); - - float attenuation = pow(dist / attractors[i].radius, attractors[i].attenuation); - - if (attractors[i].dir == vec3(0.0)) { - //towards center - force += attractors[i].strength * rel_vec * attenuation * mass; - } else { - force += attractors[i].strength * attractors[i].dir * attenuation * mass; - } - } - - out_velocity_active.xyz += force * local_delta; - } -#endif - -#if !defined(DISABLE_VELOCITY) - - if (true) { - xform[3].xyz += out_velocity_active.xyz * local_delta; - } -#endif - } else { - xform = mat4(0.0); - } - - xform = transpose(xform); - - out_velocity_active.a = mix(0.0, 1.0, shader_active); - - out_xform_1 = xform[0]; - out_xform_2 = xform[1]; - out_xform_3 = xform[2]; - -#endif //PARTICLES_COPY -} - -/* clang-format off */ -[fragment] - -//any code here is never executed, stuff is filled just so it works - -#if defined(USE_MATERIAL) - -layout(std140) uniform UniformData { - -MATERIAL_UNIFORMS -}; - -#endif - -FRAGMENT_SHADER_GLOBALS - -void main() { - { - -LIGHT_SHADER_CODE - - } - - { - -FRAGMENT_SHADER_CODE - - } -} -/* clang-format on */ diff --git a/drivers/gles2/shaders/resolve.glsl b/drivers/gles2/shaders/resolve.glsl deleted file mode 100644 index 071cb37a99..0000000000 --- a/drivers/gles2/shaders/resolve.glsl +++ /dev/null @@ -1,42 +0,0 @@ -/* clang-format off */ -[vertex] - -layout(location = 0) in highp vec4 vertex_attrib; -/* clang-format on */ -layout(location = 4) in vec2 uv_in; - -out vec2 uv_interp; - -void main() { - uv_interp = uv_in; - gl_Position = vertex_attrib; -} - -/* clang-format off */ -[fragment] - -#if !defined(GLES_OVER_GL) -precision mediump float; -#endif - -in vec2 uv_interp; -/* clang-format on */ -uniform sampler2D source_specular; //texunit:0 -uniform sampler2D source_ssr; //texunit:1 - -uniform vec2 pixel_size; - -in vec2 uv2_interp; - -layout(location = 0) out vec4 frag_color; - -void main() { - vec4 specular = texture(source_specular, uv_interp); - -#ifdef USE_SSR - vec4 ssr = textureLod(source_ssr, uv_interp, 0.0); - specular.rgb = mix(specular.rgb, ssr.rgb * specular.a, ssr.a); -#endif - - frag_color = vec4(specular.rgb, 1.0); -} diff --git a/drivers/gles2/shaders/screen_space_reflection.glsl b/drivers/gles2/shaders/screen_space_reflection.glsl deleted file mode 100644 index 6b5b7c885c..0000000000 --- a/drivers/gles2/shaders/screen_space_reflection.glsl +++ /dev/null @@ -1,284 +0,0 @@ -/* clang-format off */ -[vertex] - -layout(location = 0) in highp vec4 vertex_attrib; -/* clang-format on */ -layout(location = 4) in vec2 uv_in; - -out vec2 uv_interp; -out vec2 pos_interp; - -void main() { - uv_interp = uv_in; - gl_Position = vertex_attrib; - pos_interp.xy = gl_Position.xy; -} - -/* clang-format off */ -[fragment] - -in vec2 uv_interp; -/* clang-format on */ -in vec2 pos_interp; - -uniform sampler2D source_diffuse; //texunit:0 -uniform sampler2D source_normal_roughness; //texunit:1 -uniform sampler2D source_depth; //texunit:2 - -uniform float camera_z_near; -uniform float camera_z_far; - -uniform vec2 viewport_size; -uniform vec2 pixel_size; - -uniform float filter_mipmap_levels; - -uniform mat4 inverse_projection; -uniform mat4 projection; - -uniform int num_steps; -uniform float depth_tolerance; -uniform float distance_fade; -uniform float curve_fade_in; - -layout(location = 0) out vec4 frag_color; - -vec2 view_to_screen(vec3 view_pos, out float w) { - vec4 projected = projection * vec4(view_pos, 1.0); - projected.xyz /= projected.w; - projected.xy = projected.xy * 0.5 + 0.5; - w = projected.w; - return projected.xy; -} - -#define M_PI 3.14159265359 - -void main() { - vec4 diffuse = texture(source_diffuse, uv_interp); - vec4 normal_roughness = texture(source_normal_roughness, uv_interp); - - vec3 normal; - - normal = normal_roughness.xyz * 2.0 - 1.0; - - float roughness = normal_roughness.w; - - float depth_tex = texture(source_depth, uv_interp).r; - - vec4 world_pos = inverse_projection * vec4(uv_interp * 2.0 - 1.0, depth_tex * 2.0 - 1.0, 1.0); - vec3 vertex = world_pos.xyz / world_pos.w; - - vec3 view_dir = normalize(vertex); - vec3 ray_dir = normalize(reflect(view_dir, normal)); - - if (dot(ray_dir, normal) < 0.001) { - frag_color = vec4(0.0); - return; - } - //ray_dir = normalize(view_dir - normal * dot(normal,view_dir) * 2.0); - - //ray_dir = normalize(vec3(1,1,-1)); - - //////////////// - - //make ray length and clip it against the near plane (don't want to trace beyond visible) - float ray_len = (vertex.z + ray_dir.z * camera_z_far) > -camera_z_near ? (-camera_z_near - vertex.z) / ray_dir.z : camera_z_far; - vec3 ray_end = vertex + ray_dir * ray_len; - - float w_begin; - vec2 vp_line_begin = view_to_screen(vertex, w_begin); - float w_end; - vec2 vp_line_end = view_to_screen(ray_end, w_end); - vec2 vp_line_dir = vp_line_end - vp_line_begin; - - //we need to interpolate w along the ray, to generate perspective correct reflections - - w_begin = 1.0 / w_begin; - w_end = 1.0 / w_end; - - float z_begin = vertex.z * w_begin; - float z_end = ray_end.z * w_end; - - vec2 line_begin = vp_line_begin / pixel_size; - vec2 line_dir = vp_line_dir / pixel_size; - float z_dir = z_end - z_begin; - float w_dir = w_end - w_begin; - - // clip the line to the viewport edges - - float scale_max_x = min(1.0, 0.99 * (1.0 - vp_line_begin.x) / max(1e-5, vp_line_dir.x)); - float scale_max_y = min(1.0, 0.99 * (1.0 - vp_line_begin.y) / max(1e-5, vp_line_dir.y)); - float scale_min_x = min(1.0, 0.99 * vp_line_begin.x / max(1e-5, -vp_line_dir.x)); - float scale_min_y = min(1.0, 0.99 * vp_line_begin.y / max(1e-5, -vp_line_dir.y)); - float line_clip = min(scale_max_x, scale_max_y) * min(scale_min_x, scale_min_y); - line_dir *= line_clip; - z_dir *= line_clip; - w_dir *= line_clip; - - //clip z and w advance to line advance - vec2 line_advance = normalize(line_dir); //down to pixel - float step_size = length(line_advance) / length(line_dir); - float z_advance = z_dir * step_size; // adapt z advance to line advance - float w_advance = w_dir * step_size; // adapt w advance to line advance - - //make line advance faster if direction is closer to pixel edges (this avoids sampling the same pixel twice) - float advance_angle_adj = 1.0 / max(abs(line_advance.x), abs(line_advance.y)); - line_advance *= advance_angle_adj; // adapt z advance to line advance - z_advance *= advance_angle_adj; - w_advance *= advance_angle_adj; - - vec2 pos = line_begin; - float z = z_begin; - float w = w_begin; - float z_from = z / w; - float z_to = z_from; - float depth; - vec2 prev_pos = pos; - - bool found = false; - - float steps_taken = 0.0; - - for (int i = 0; i < num_steps; i++) { - pos += line_advance; - z += z_advance; - w += w_advance; - - //convert to linear depth - - depth = texture(source_depth, pos * pixel_size).r * 2.0 - 1.0; -#ifdef USE_ORTHOGONAL_PROJECTION - depth = ((depth + (camera_z_far + camera_z_near) / (camera_z_far - camera_z_near)) * (camera_z_far - camera_z_near)) / 2.0; -#else - depth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - depth * (camera_z_far - camera_z_near)); -#endif - depth = -depth; - - z_from = z_to; - z_to = z / w; - - if (depth > z_to) { - //if depth was surpassed - if (depth <= max(z_to, z_from) + depth_tolerance) { - //check the depth tolerance - found = true; - } - break; - } - - steps_taken += 1.0; - prev_pos = pos; - } - - if (found) { - float margin_blend = 1.0; - - vec2 margin = vec2((viewport_size.x + viewport_size.y) * 0.5 * 0.05); //make a uniform margin - if (any(bvec4(lessThan(pos, -margin), greaterThan(pos, viewport_size + margin)))) { - //clip outside screen + margin - frag_color = vec4(0.0); - return; - } - - { - //blend fading out towards external margin - vec2 margin_grad = mix(pos - viewport_size, -pos, lessThan(pos, vec2(0.0))); - margin_blend = 1.0 - smoothstep(0.0, margin.x, max(margin_grad.x, margin_grad.y)); - //margin_blend=1.0; - } - - vec2 final_pos; - float grad; - grad = steps_taken / float(num_steps); - float initial_fade = curve_fade_in == 0.0 ? 1.0 : pow(clamp(grad, 0.0, 1.0), curve_fade_in); - float fade = pow(clamp(1.0 - grad, 0.0, 1.0), distance_fade) * initial_fade; - final_pos = pos; - -#ifdef REFLECT_ROUGHNESS - - vec4 final_color; - //if roughness is enabled, do screen space cone tracing - if (roughness > 0.001) { - /////////////////////////////////////////////////////////////////////////////////////// - //use a blurred version (in consecutive mipmaps) of the screen to simulate roughness - - float gloss = 1.0 - roughness; - float cone_angle = roughness * M_PI * 0.5; - vec2 cone_dir = final_pos - line_begin; - float cone_len = length(cone_dir); - cone_dir = normalize(cone_dir); //will be used normalized from now on - float max_mipmap = filter_mipmap_levels - 1.0; - float gloss_mult = gloss; - - float rem_alpha = 1.0; - final_color = vec4(0.0); - - for (int i = 0; i < 7; i++) { - float op_len = 2.0 * tan(cone_angle) * cone_len; //opposite side of iso triangle - float radius; - { - //fit to sphere inside cone (sphere ends at end of cone), something like this: - // ___ - // \O/ - // V - // - // as it avoids bleeding from beyond the reflection as much as possible. As a plus - // it also makes the rough reflection more elongated. - float a = op_len; - float h = cone_len; - float a2 = a * a; - float fh2 = 4.0f * h * h; - radius = (a * (sqrt(a2 + fh2) - a)) / (4.0f * h); - } - - //find the place where screen must be sampled - vec2 sample_pos = (line_begin + cone_dir * (cone_len - radius)) * pixel_size; - //radius is in pixels, so it's natural that log2(radius) maps to the right mipmap for the amount of pixels - float mipmap = clamp(log2(radius), 0.0, max_mipmap); - - //mipmap = max(mipmap-1.0,0.0); - //do sampling - - vec4 sample_color; - { - sample_color = textureLod(source_diffuse, sample_pos, mipmap); - } - - //multiply by gloss - sample_color.rgb *= gloss_mult; - sample_color.a = gloss_mult; - - rem_alpha -= sample_color.a; - if (rem_alpha < 0.0) { - sample_color.rgb *= (1.0 - abs(rem_alpha)); - } - - final_color += sample_color; - - if (final_color.a >= 0.95) { - // This code of accumulating gloss and aborting on near one - // makes sense when you think of cone tracing. - // Think of it as if roughness was 0, then we could abort on the first - // iteration. For lesser roughness values, we need more iterations, but - // each needs to have less influence given the sphere is smaller - break; - } - - cone_len -= radius * 2.0; //go to next (smaller) circle. - - gloss_mult *= gloss; - } - } else { - final_color = textureLod(source_diffuse, final_pos * pixel_size, 0.0); - } - - frag_color = vec4(final_color.rgb, fade * margin_blend); - -#else - frag_color = vec4(textureLod(source_diffuse, final_pos * pixel_size, 0.0).rgb, fade * margin_blend); -#endif - - } else { - frag_color = vec4(0.0, 0.0, 0.0, 0.0); - } -} diff --git a/drivers/gles2/shaders/ssao.glsl b/drivers/gles2/shaders/ssao.glsl deleted file mode 100644 index 0fd29e8dcc..0000000000 --- a/drivers/gles2/shaders/ssao.glsl +++ /dev/null @@ -1,283 +0,0 @@ -/* clang-format off */ -[vertex] - -layout(location = 0) in highp vec4 vertex_attrib; -/* clang-format on */ - -void main() { - gl_Position = vertex_attrib; - gl_Position.z = 1.0; -} - -/* clang-format off */ -[fragment] - -#define TWO_PI 6.283185307179586476925286766559 - -#ifdef SSAO_QUALITY_HIGH - -#define NUM_SAMPLES (80) - -#endif - -#ifdef SSAO_QUALITY_LOW - -#define NUM_SAMPLES (15) - -#endif - -#if !defined(SSAO_QUALITY_LOW) && !defined(SSAO_QUALITY_HIGH) - -#define NUM_SAMPLES (40) - -#endif - -// If using depth mip levels, the log of the maximum pixel offset before we need to switch to a lower -// miplevel to maintain reasonable spatial locality in the cache -// If this number is too small (< 3), too many taps will land in the same pixel, and we'll get bad variance that manifests as flashing. -// If it is too high (> 5), we'll get bad performance because we're not using the MIP levels effectively -#define LOG_MAX_OFFSET (3) - -// This must be less than or equal to the MAX_MIP_LEVEL defined in SSAO.cpp -#define MAX_MIP_LEVEL (4) - -// This is the number of turns around the circle that the spiral pattern makes. This should be prime to prevent -// taps from lining up. This particular choice was tuned for NUM_SAMPLES == 9 - -const int ROTATIONS[] = int[]( - 1, 1, 2, 3, 2, 5, 2, 3, 2, - 3, 3, 5, 5, 3, 4, 7, 5, 5, 7, - 9, 8, 5, 5, 7, 7, 7, 8, 5, 8, - 11, 12, 7, 10, 13, 8, 11, 8, 7, 14, - 11, 11, 13, 12, 13, 19, 17, 13, 11, 18, - 19, 11, 11, 14, 17, 21, 15, 16, 17, 18, - 13, 17, 11, 17, 19, 18, 25, 18, 19, 19, - 29, 21, 19, 27, 31, 29, 21, 18, 17, 29, - 31, 31, 23, 18, 25, 26, 25, 23, 19, 34, - 19, 27, 21, 25, 39, 29, 17, 21, 27); -/* clang-format on */ - -//#define NUM_SPIRAL_TURNS (7) -const int NUM_SPIRAL_TURNS = ROTATIONS[NUM_SAMPLES - 1]; - -uniform sampler2D source_depth; //texunit:0 -uniform highp usampler2D source_depth_mipmaps; //texunit:1 -uniform sampler2D source_normal; //texunit:2 - -uniform ivec2 screen_size; -uniform float camera_z_far; -uniform float camera_z_near; - -uniform float intensity_div_r6; -uniform float radius; - -#ifdef ENABLE_RADIUS2 -uniform float intensity_div_r62; -uniform float radius2; -#endif - -uniform float bias; -uniform float proj_scale; - -layout(location = 0) out float visibility; - -uniform vec4 proj_info; - -vec3 reconstructCSPosition(vec2 S, float z) { -#ifdef USE_ORTHOGONAL_PROJECTION - return vec3((S.xy * proj_info.xy + proj_info.zw), z); -#else - return vec3((S.xy * proj_info.xy + proj_info.zw) * z, z); - -#endif -} - -vec3 getPosition(ivec2 ssP) { - vec3 P; - P.z = texelFetch(source_depth, ssP, 0).r; - - P.z = P.z * 2.0 - 1.0; -#ifdef USE_ORTHOGONAL_PROJECTION - P.z = ((P.z + (camera_z_far + camera_z_near) / (camera_z_far - camera_z_near)) * (camera_z_far - camera_z_near)) / 2.0; -#else - P.z = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - P.z * (camera_z_far - camera_z_near)); -#endif - P.z = -P.z; - - // Offset to pixel center - P = reconstructCSPosition(vec2(ssP) + vec2(0.5), P.z); - return P; -} - -/** Reconstructs screen-space unit normal from screen-space position */ -vec3 reconstructCSFaceNormal(vec3 C) { - return normalize(cross(dFdy(C), dFdx(C))); -} - -/** Returns a unit vector and a screen-space radius for the tap on a unit disk (the caller should scale by the actual disk radius) */ -vec2 tapLocation(int sampleNumber, float spinAngle, out float ssR) { - // Radius relative to ssR - float alpha = (float(sampleNumber) + 0.5) * (1.0 / float(NUM_SAMPLES)); - float angle = alpha * (float(NUM_SPIRAL_TURNS) * 6.28) + spinAngle; - - ssR = alpha; - return vec2(cos(angle), sin(angle)); -} - -/** Read the camera-space position of the point at screen-space pixel ssP + unitOffset * ssR. Assumes length(unitOffset) == 1 */ -vec3 getOffsetPosition(ivec2 ssC, vec2 unitOffset, float ssR) { - // Derivation: - // mipLevel = floor(log(ssR / MAX_OFFSET)); - int mipLevel = clamp(int(floor(log2(ssR))) - LOG_MAX_OFFSET, 0, MAX_MIP_LEVEL); - - ivec2 ssP = ivec2(ssR * unitOffset) + ssC; - - vec3 P; - - // We need to divide by 2^mipLevel to read the appropriately scaled coordinate from a MIP-map. - // Manually clamp to the texture size because texelFetch bypasses the texture unit - ivec2 mipP = clamp(ssP >> mipLevel, ivec2(0), (screen_size >> mipLevel) - ivec2(1)); - - if (mipLevel < 1) { - //read from depth buffer - P.z = texelFetch(source_depth, mipP, 0).r; - P.z = P.z * 2.0 - 1.0; -#ifdef USE_ORTHOGONAL_PROJECTION - P.z = ((P.z + (camera_z_far + camera_z_near) / (camera_z_far - camera_z_near)) * (camera_z_far - camera_z_near)) / 2.0; -#else - P.z = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - P.z * (camera_z_far - camera_z_near)); - -#endif - P.z = -P.z; - - } else { - //read from mipmaps - uint d = texelFetch(source_depth_mipmaps, mipP, mipLevel - 1).r; - P.z = -(float(d) / 65535.0) * camera_z_far; - } - - // Offset to pixel center - P = reconstructCSPosition(vec2(ssP) + vec2(0.5), P.z); - - return P; -} - -/** Compute the occlusion due to sample with index \a i about the pixel at \a ssC that corresponds - to camera-space point \a C with unit normal \a n_C, using maximum screen-space sampling radius \a ssDiskRadius - - Note that units of H() in the HPG12 paper are meters, not - unitless. The whole falloff/sampling function is therefore - unitless. In this implementation, we factor out (9 / radius). - - Four versions of the falloff function are implemented below -*/ -float sampleAO(in ivec2 ssC, in vec3 C, in vec3 n_C, in float ssDiskRadius, in float p_radius, in int tapIndex, in float randomPatternRotationAngle) { - // Offset on the unit disk, spun for this pixel - float ssR; - vec2 unitOffset = tapLocation(tapIndex, randomPatternRotationAngle, ssR); - ssR *= ssDiskRadius; - - // The occluding point in camera space - vec3 Q = getOffsetPosition(ssC, unitOffset, ssR); - - vec3 v = Q - C; - - float vv = dot(v, v); - float vn = dot(v, n_C); - - const float epsilon = 0.01; - float radius2 = p_radius * p_radius; - - // A: From the HPG12 paper - // Note large epsilon to avoid overdarkening within cracks - //return float(vv < radius2) * max((vn - bias) / (epsilon + vv), 0.0) * radius2 * 0.6; - - // B: Smoother transition to zero (lowers contrast, smoothing out corners). [Recommended] - float f = max(radius2 - vv, 0.0); - return f * f * f * max((vn - bias) / (epsilon + vv), 0.0); - - // C: Medium contrast (which looks better at high radii), no division. Note that the - // contribution still falls off with radius^2, but we've adjusted the rate in a way that is - // more computationally efficient and happens to be aesthetically pleasing. - // return 4.0 * max(1.0 - vv * invRadius2, 0.0) * max(vn - bias, 0.0); - - // D: Low contrast, no division operation - // return 2.0 * float(vv < radius * radius) * max(vn - bias, 0.0); -} - -void main() { - // Pixel being shaded - ivec2 ssC = ivec2(gl_FragCoord.xy); - - // World space point being shaded - vec3 C = getPosition(ssC); - - /* - if (C.z <= -camera_z_far*0.999) { - // We're on the skybox - visibility=1.0; - return; - } - */ - - //visibility=-C.z/camera_z_far; - //return; -#if 0 - vec3 n_C = texelFetch(source_normal,ssC,0).rgb * 2.0 - 1.0; -#else - vec3 n_C = reconstructCSFaceNormal(C); - n_C = -n_C; -#endif - - // Hash function used in the HPG12 AlchemyAO paper - float randomPatternRotationAngle = mod(float((3 * ssC.x ^ ssC.y + ssC.x * ssC.y) * 10), TWO_PI); - - // Reconstruct normals from positions. These will lead to 1-pixel black lines - // at depth discontinuities, however the blur will wipe those out so they are not visible - // in the final image. - - // Choose the screen-space sample radius - // proportional to the projected area of the sphere -#ifdef USE_ORTHOGONAL_PROJECTION - float ssDiskRadius = -proj_scale * radius; -#else - float ssDiskRadius = -proj_scale * radius / C.z; -#endif - float sum = 0.0; - for (int i = 0; i < NUM_SAMPLES; ++i) { - sum += sampleAO(ssC, C, n_C, ssDiskRadius, radius, i, randomPatternRotationAngle); - } - - float A = max(0.0, 1.0 - sum * intensity_div_r6 * (5.0 / float(NUM_SAMPLES))); - -#ifdef ENABLE_RADIUS2 - - //go again for radius2 - randomPatternRotationAngle = mod(float((5 * ssC.x ^ ssC.y + ssC.x * ssC.y) * 11), TWO_PI); - - // Reconstruct normals from positions. These will lead to 1-pixel black lines - // at depth discontinuities, however the blur will wipe those out so they are not visible - // in the final image. - - // Choose the screen-space sample radius - // proportional to the projected area of the sphere - ssDiskRadius = -proj_scale * radius2 / C.z; - - sum = 0.0; - for (int i = 0; i < NUM_SAMPLES; ++i) { - sum += sampleAO(ssC, C, n_C, ssDiskRadius, radius2, i, randomPatternRotationAngle); - } - - A = min(A, max(0.0, 1.0 - sum * intensity_div_r62 * (5.0 / float(NUM_SAMPLES)))); -#endif - // Bilateral box-filter over a quad for free, respecting depth edges - // (the difference that this makes is subtle) - if (abs(dFdx(C.z)) < 0.02) { - A -= dFdx(A) * (float(ssC.x & 1) - 0.5); - } - if (abs(dFdy(C.z)) < 0.02) { - A -= dFdy(A) * (float(ssC.y & 1) - 0.5); - } - - visibility = A; -} diff --git a/drivers/gles2/shaders/ssao_blur.glsl b/drivers/gles2/shaders/ssao_blur.glsl deleted file mode 100644 index f065cd74eb..0000000000 --- a/drivers/gles2/shaders/ssao_blur.glsl +++ /dev/null @@ -1,116 +0,0 @@ -/* clang-format off */ -[vertex] - -layout(location = 0) in highp vec4 vertex_attrib; -/* clang-format on */ - -void main() { - gl_Position = vertex_attrib; - gl_Position.z = 1.0; -} - -/* clang-format off */ -[fragment] - -uniform sampler2D source_ssao; //texunit:0 -/* clang-format on */ -uniform sampler2D source_depth; //texunit:1 -uniform sampler2D source_normal; //texunit:3 - -layout(location = 0) out float visibility; - -////////////////////////////////////////////////////////////////////////////////////////////// -// Tunable Parameters: - -/** Increase to make depth edges crisper. Decrease to reduce flicker. */ -uniform float edge_sharpness; - -/** Step in 2-pixel intervals since we already blurred against neighbors in the - first AO pass. This constant can be increased while R decreases to improve - performance at the expense of some dithering artifacts. - - Morgan found that a scale of 3 left a 1-pixel checkerboard grid that was - unobjectionable after shading was applied but eliminated most temporal incoherence - from using small numbers of sample taps. - */ - -uniform int filter_scale; - -/** Filter radius in pixels. This will be multiplied by SCALE. */ -#define R (4) - -////////////////////////////////////////////////////////////////////////////////////////////// - -// Gaussian coefficients -const float gaussian[R + 1] = - //float[](0.356642, 0.239400, 0.072410, 0.009869); - //float[](0.398943, 0.241971, 0.053991, 0.004432, 0.000134); // stddev = 1.0 - float[](0.153170, 0.144893, 0.122649, 0.092902, 0.062970); // stddev = 2.0 -//float[](0.111220, 0.107798, 0.098151, 0.083953, 0.067458, 0.050920, 0.036108); // stddev = 3.0 - -/** (1, 0) or (0, 1)*/ -uniform ivec2 axis; - -uniform float camera_z_far; -uniform float camera_z_near; - -uniform ivec2 screen_size; - -void main() { - ivec2 ssC = ivec2(gl_FragCoord.xy); - - float depth = texelFetch(source_depth, ssC, 0).r; - //vec3 normal = texelFetch(source_normal,ssC,0).rgb * 2.0 - 1.0; - - depth = depth * 2.0 - 1.0; - depth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - depth * (camera_z_far - camera_z_near)); - - float depth_divide = 1.0 / camera_z_far; - - //depth *= depth_divide; - - /* - if (depth > camera_z_far * 0.999) { - discard; //skybox - } - */ - - float sum = texelFetch(source_ssao, ssC, 0).r; - - // Base weight for depth falloff. Increase this for more blurriness, - // decrease it for better edge discrimination - float BASE = gaussian[0]; - float totalWeight = BASE; - sum *= totalWeight; - - ivec2 clamp_limit = screen_size - ivec2(1); - - for (int r = -R; r <= R; ++r) { - // We already handled the zero case above. This loop should be unrolled and the static branch optimized out, - // so the IF statement has no runtime cost - if (r != 0) { - ivec2 ppos = ssC + axis * (r * filter_scale); - float value = texelFetch(source_ssao, clamp(ppos, ivec2(0), clamp_limit), 0).r; - ivec2 rpos = clamp(ppos, ivec2(0), clamp_limit); - float temp_depth = texelFetch(source_depth, rpos, 0).r; - //vec3 temp_normal = texelFetch(source_normal, rpos, 0).rgb * 2.0 - 1.0; - - temp_depth = temp_depth * 2.0 - 1.0; - temp_depth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - temp_depth * (camera_z_far - camera_z_near)); - // temp_depth *= depth_divide; - - // spatial domain: offset gaussian tap - float weight = 0.3 + gaussian[abs(r)]; - //weight *= max(0.0,dot(temp_normal,normal)); - - // range domain (the "bilateral" weight). As depth difference increases, decrease weight. - weight *= max(0.0, 1.0 - edge_sharpness * abs(temp_depth - depth)); - - sum += value * weight; - totalWeight += weight; - } - } - - const float epsilon = 0.0001; - visibility = sum / (totalWeight + epsilon); -} diff --git a/drivers/gles2/shaders/ssao_minify.glsl b/drivers/gles2/shaders/ssao_minify.glsl deleted file mode 100644 index f654e00a4f..0000000000 --- a/drivers/gles2/shaders/ssao_minify.glsl +++ /dev/null @@ -1,54 +0,0 @@ -/* clang-format off */ -[vertex] - -layout(location = 0) in highp vec4 vertex_attrib; -/* clang-format on */ - -void main() { - gl_Position = vertex_attrib; -} - -/* clang-format off */ -[fragment] - -#ifdef MINIFY_START - -#define SDEPTH_TYPE highp sampler2D -uniform float camera_z_far; -uniform float camera_z_near; -/* clang-format on */ - -#else - -#define SDEPTH_TYPE mediump usampler2D - -#endif - -uniform SDEPTH_TYPE source_depth; //texunit:0 - -uniform ivec2 from_size; -uniform int source_mipmap; - -layout(location = 0) out mediump uint depth; - -void main() { - ivec2 ssP = ivec2(gl_FragCoord.xy); - - // Rotated grid subsampling to avoid XY directional bias or Z precision bias while downsampling. - // On DX9, the bit-and can be implemented with floating-point modulo - -#ifdef MINIFY_START - float fdepth = texelFetch(source_depth, clamp(ssP * 2 + ivec2(ssP.y & 1, ssP.x & 1), ivec2(0), from_size - ivec2(1)), source_mipmap).r; - fdepth = fdepth * 2.0 - 1.0; -#ifdef USE_ORTHOGONAL_PROJECTION - fdepth = ((fdepth + (camera_z_far + camera_z_near) / (camera_z_far - camera_z_near)) * (camera_z_far - camera_z_near)) / 2.0; -#else - fdepth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - fdepth * (camera_z_far - camera_z_near)); -#endif - fdepth /= camera_z_far; - depth = uint(clamp(fdepth * 65535.0, 0.0, 65535.0)); - -#else - depth = texelFetch(source_depth, clamp(ssP * 2 + ivec2(ssP.y & 1, ssP.x & 1), ivec2(0), from_size - ivec2(1)), source_mipmap).r; -#endif -} diff --git a/drivers/gles2/shaders/subsurf_scattering.glsl b/drivers/gles2/shaders/subsurf_scattering.glsl deleted file mode 100644 index d0c34cf1b0..0000000000 --- a/drivers/gles2/shaders/subsurf_scattering.glsl +++ /dev/null @@ -1,171 +0,0 @@ -/* clang-format off */ -[vertex] - -layout(location = 0) in highp vec4 vertex_attrib; -/* clang-format on */ -layout(location = 4) in vec2 uv_in; - -out vec2 uv_interp; - -void main() { - uv_interp = uv_in; - gl_Position = vertex_attrib; -} - -/* clang-format off */ -[fragment] - -//#define QUALIFIER uniform // some guy on the interweb says it may be faster with this -#define QUALIFIER const - -#ifdef USE_25_SAMPLES -const int kernel_size = 25; -/* clang-format on */ -QUALIFIER vec2 kernel[25] = vec2[]( - vec2(0.530605, 0.0), - vec2(0.000973794, -3.0), - vec2(0.00333804, -2.52083), - vec2(0.00500364, -2.08333), - vec2(0.00700976, -1.6875), - vec2(0.0094389, -1.33333), - vec2(0.0128496, -1.02083), - vec2(0.017924, -0.75), - vec2(0.0263642, -0.520833), - vec2(0.0410172, -0.333333), - vec2(0.0493588, -0.1875), - vec2(0.0402784, -0.0833333), - vec2(0.0211412, -0.0208333), - vec2(0.0211412, 0.0208333), - vec2(0.0402784, 0.0833333), - vec2(0.0493588, 0.1875), - vec2(0.0410172, 0.333333), - vec2(0.0263642, 0.520833), - vec2(0.017924, 0.75), - vec2(0.0128496, 1.02083), - vec2(0.0094389, 1.33333), - vec2(0.00700976, 1.6875), - vec2(0.00500364, 2.08333), - vec2(0.00333804, 2.52083), - vec2(0.000973794, 3.0)); -#endif //USE_25_SAMPLES - -#ifdef USE_17_SAMPLES -const int kernel_size = 17; -QUALIFIER vec2 kernel[17] = vec2[]( - vec2(0.536343, 0.0), - vec2(0.00317394, -2.0), - vec2(0.0100386, -1.53125), - vec2(0.0144609, -1.125), - vec2(0.0216301, -0.78125), - vec2(0.0347317, -0.5), - vec2(0.0571056, -0.28125), - vec2(0.0582416, -0.125), - vec2(0.0324462, -0.03125), - vec2(0.0324462, 0.03125), - vec2(0.0582416, 0.125), - vec2(0.0571056, 0.28125), - vec2(0.0347317, 0.5), - vec2(0.0216301, 0.78125), - vec2(0.0144609, 1.125), - vec2(0.0100386, 1.53125), - vec2(0.00317394, 2.0)); -#endif //USE_17_SAMPLES - -#ifdef USE_11_SAMPLES -const int kernel_size = 11; -QUALIFIER vec2 kernel[11] = vec2[]( - vec2(0.560479, 0.0), - vec2(0.00471691, -2.0), - vec2(0.0192831, -1.28), - vec2(0.03639, -0.72), - vec2(0.0821904, -0.32), - vec2(0.0771802, -0.08), - vec2(0.0771802, 0.08), - vec2(0.0821904, 0.32), - vec2(0.03639, 0.72), - vec2(0.0192831, 1.28), - vec2(0.00471691, 2.0)); -#endif //USE_11_SAMPLES - -uniform float max_radius; -uniform float camera_z_far; -uniform float camera_z_near; -uniform float unit_size; -uniform vec2 dir; -in vec2 uv_interp; - -uniform sampler2D source_diffuse; //texunit:0 -uniform sampler2D source_sss; //texunit:1 -uniform sampler2D source_depth; //texunit:2 - -layout(location = 0) out vec4 frag_color; - -void main() { - float strength = texture(source_sss, uv_interp).r; - strength *= strength; //stored as sqrt - - // Fetch color of current pixel: - vec4 base_color = texture(source_diffuse, uv_interp); - - if (strength > 0.0) { - // Fetch linear depth of current pixel: - float depth = texture(source_depth, uv_interp).r * 2.0 - 1.0; -#ifdef USE_ORTHOGONAL_PROJECTION - depth = ((depth + (camera_z_far + camera_z_near) / (camera_z_far - camera_z_near)) * (camera_z_far - camera_z_near)) / 2.0; - float scale = unit_size; //remember depth is negative by default in OpenGL -#else - depth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - depth * (camera_z_far - camera_z_near)); - float scale = unit_size / depth; //remember depth is negative by default in OpenGL -#endif - - // Calculate the final step to fetch the surrounding pixels: - vec2 step = max_radius * scale * dir; - step *= strength; // Modulate it using the alpha channel. - step *= 1.0 / 3.0; // Divide by 3 as the kernels range from -3 to 3. - - // Accumulate the center sample: - vec3 color_accum = base_color.rgb; - color_accum *= kernel[0].x; -#ifdef ENABLE_STRENGTH_WEIGHTING - float color_weight = kernel[0].x; -#endif - - // Accumulate the other samples: - for (int i = 1; i < kernel_size; i++) { - // Fetch color and depth for current sample: - vec2 offset = uv_interp + kernel[i].y * step; - vec3 color = texture(source_diffuse, offset).rgb; - -#ifdef ENABLE_FOLLOW_SURFACE - // If the difference in depth is huge, we lerp color back to "colorM": - float depth_cmp = texture(source_depth, offset).r * 2.0 - 1.0; - -#ifdef USE_ORTHOGONAL_PROJECTION - depth_cmp = ((depth_cmp + (camera_z_far + camera_z_near) / (camera_z_far - camera_z_near)) * (camera_z_far - camera_z_near)) / 2.0; -#else - depth_cmp = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - depth_cmp * (camera_z_far - camera_z_near)); -#endif - - float s = clamp(300.0f * scale * max_radius * abs(depth - depth_cmp), 0.0, 1.0); - color = mix(color, base_color.rgb, s); -#endif - - // Accumulate: - color *= kernel[i].x; - -#ifdef ENABLE_STRENGTH_WEIGHTING - float color_s = texture(source_sss, offset).r; - color_weight += color_s * kernel[i].x; - color *= color_s; -#endif - color_accum += color; - } - -#ifdef ENABLE_STRENGTH_WEIGHTING - color_accum /= color_weight; -#endif - frag_color = vec4(color_accum, base_color.a); //keep alpha (used for SSAO) - } else { - frag_color = base_color; - } -} diff --git a/drivers/gles_common/SCsub b/drivers/gles_common/SCsub deleted file mode 100644 index 91e1140b75..0000000000 --- a/drivers/gles_common/SCsub +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env python - -Import("env") - -env.add_source_files(env.drivers_sources, "*.cpp") diff --git a/drivers/gles_common/batch_diagnose.inc b/drivers/gles_common/batch_diagnose.inc deleted file mode 100644 index 88a8792edb..0000000000 --- a/drivers/gles_common/batch_diagnose.inc +++ /dev/null @@ -1,192 +0,0 @@ -void _debug_write_garbage() { - // extremely slow, writes garbage over arrays to detect using - // uninitialized in graphical output. Do not enable in normal use!! -#ifdef RASTERIZER_EXTRA_CHECKS - int num_verts = MIN(bdata.vertices.max_size(), 32); - for (int n = 0; n < num_verts; n++) { - bdata.vertices[n].pos.set(Math::random(-200.0f, 200.0f), Math::random(-200.0f, 200.0f)); - bdata.vertices[n].uv.set(Math::random(0.0f, 1.0f), Math::random(0.0f, 1.0f)); - } - - int num_colors = MIN(bdata.vertex_colors.max_size(), 32); - for (int n = 0; n < num_colors; n++) { - bdata.vertex_colors[n].set(Math::randf(), Math::randf(), Math::randf(), 1.0f); - } - - int num_modulates = MIN(bdata.vertex_modulates.max_size(), 32); - for (int n = 0; n < num_modulates; n++) { - bdata.vertex_modulates[n].set(Math::randf(), Math::randf(), Math::randf(), 1.0f); - } - - int num_light_angles = MIN(bdata.light_angles.max_size(), 32); - for (int n = 0; n < num_light_angles; n++) { - bdata.light_angles[n] = Math::random(-3.0f, +3.0f); - } - - int num_transforms = MIN(bdata.vertex_transforms.max_size(), 32); - for (int n = 0; n < num_transforms; n++) { - bdata.vertex_transforms[n].translate.set(Math::random(-200.0f, 200.0f), Math::random(-200.0f, 200.0f)); - bdata.vertex_transforms[n].basis[0].set(Math::random(-2.0f, 2.0f), Math::random(-2.0f, 2.0f)); - bdata.vertex_transforms[n].basis[1].set(Math::random(-2.0f, 2.0f), Math::random(-2.0f, 2.0f)); - } - - int num_unit_verts = MIN(bdata.unit_vertices.max_size(), 32); - for (int n = 0; n < num_unit_verts; n++) { - uint8_t *data = bdata.unit_vertices.get_unit(n); - for (int b = 0; b > bdata.unit_vertices.get_unit_size_bytes(); b++) { - data[b] = Math::random(0, 255); - } - } - -#endif -} - -String get_command_type_string(const RendererCanvasRender::Item::Command &p_command) const { - String sz = ""; - - switch (p_command.type) { - default: - break; -#ifdef GODOT_3 - case RendererCanvasRender::Item::Command::GD_TYPE_LINE: { - sz = "l"; - } break; - case RendererCanvasRender::Item::Command::GD_TYPE_POLYLINE: { - sz = "PL"; - } break; - case RendererCanvasRender::Item::Command::GD_TYPE_CIRCLE: { - sz = "c"; - } break; -#endif - case RendererCanvasRender::Item::Command::TYPE_RECT: { - sz = "r"; - } break; - case RendererCanvasRender::Item::Command::TYPE_NINEPATCH: { - sz = "n"; - } break; - case RendererCanvasRender::Item::Command::TYPE_PRIMITIVE: { - sz = "PR"; - } break; - case RendererCanvasRender::Item::Command::TYPE_POLYGON: { - sz = "p"; - } break; - case RendererCanvasRender::Item::Command::TYPE_MESH: { - sz = "m"; - } break; - case RendererCanvasRender::Item::Command::TYPE_MULTIMESH: { - sz = "MM"; - } break; - case RendererCanvasRender::Item::Command::TYPE_PARTICLES: { - sz = "PA"; - } break; - case RendererCanvasRender::Item::Command::TYPE_TRANSFORM: { - sz = "t"; - - // add a bit more info in debug build - const RendererCanvasRender::Item::CommandTransform *transform = static_cast<const RendererCanvasRender::Item::CommandTransform *>(&p_command); - const Transform2D &mat = transform->xform; - - sz += " "; - sz += String(Variant(mat.elements[2])); - sz += " "; - } break; - case RendererCanvasRender::Item::Command::TYPE_CLIP_IGNORE: { - sz = "CI"; - } break; - } // switch - - return sz; -} - -void diagnose_batches(RendererCanvasRender::Item::Command *const *p_commands) { - int num_batches = bdata.batches.size(); - - BatchColor curr_color; - curr_color.set(Color(-1, -1, -1, -1)); - bool first_color_change = true; - - for (int batch_num = 0; batch_num < num_batches; batch_num++) { - const Batch &batch = bdata.batches[batch_num]; - bdata.frame_string += "\t\t\tbatch "; - - switch (batch.type) { - case RasterizerStorageCommon::BT_POLY: { - bdata.frame_string += "P "; - bdata.frame_string += itos(batch.first_command) + "-"; - bdata.frame_string += itos(batch.num_commands); - - bdata.frame_string += " " + batch.color.to_string(); - - if (batch.num_commands > 1) { - bdata.frame_string += " MULTI"; - } - if (curr_color != batch.color) { - curr_color = batch.color; - if (!first_color_change) { - bdata.frame_string += " color"; - } else { - first_color_change = false; - } - } - bdata.frame_string += "\n"; - } break; - case RasterizerStorageCommon::BT_LINE: - case RasterizerStorageCommon::BT_LINE_AA: { - bdata.frame_string += "L "; - bdata.frame_string += itos(batch.first_command) + "-"; - bdata.frame_string += itos(batch.num_commands); - - bdata.frame_string += " " + batch.color.to_string(); - - if (batch.num_commands > 1) { - bdata.frame_string += " MULTI"; - } - if (curr_color != batch.color) { - curr_color = batch.color; - if (!first_color_change) { - bdata.frame_string += " color"; - } else { - first_color_change = false; - } - } - bdata.frame_string += "\n"; - } break; - case RasterizerStorageCommon::BT_RECT: { - bdata.frame_string += "R "; - bdata.frame_string += itos(batch.first_command) + "-"; - bdata.frame_string += itos(batch.num_commands); - - int tex_id = (int)bdata.batch_textures[batch.batch_texture_id].RID_texture.get_id(); - bdata.frame_string += " [" + itos(batch.batch_texture_id) + " - " + itos(tex_id) + "]"; - - bdata.frame_string += " " + batch.color.to_string(); - - if (batch.num_commands > 1) { - bdata.frame_string += " MULTI"; - } - if (curr_color != batch.color) { - curr_color = batch.color; - if (!first_color_change) { - bdata.frame_string += " color"; - } else { - first_color_change = false; - } - } - bdata.frame_string += "\n"; - } break; - default: { - bdata.frame_string += "D "; - bdata.frame_string += itos(batch.first_command) + "-"; - bdata.frame_string += itos(batch.num_commands) + " "; - - int num_show = MIN(batch.num_commands, 16); - for (int n = 0; n < num_show; n++) { - const RendererCanvasRender::Item::Command &comm = *p_commands[batch.first_command + n]; - bdata.frame_string += get_command_type_string(comm) + " "; - } - - bdata.frame_string += "\n"; - } break; - } - } -} diff --git a/drivers/gles_common/rasterizer_common_stubs.h b/drivers/gles_common/rasterizer_common_stubs.h deleted file mode 100644 index 8f1e036497..0000000000 --- a/drivers/gles_common/rasterizer_common_stubs.h +++ /dev/null @@ -1,1096 +0,0 @@ -/*************************************************************************/ -/* rasterizer_common_stubs.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 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 */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#pragma once - -#include "core/math/camera_matrix.h" -#include "core/templates/rid_owner.h" -#include "core/templates/self_list.h" -#include "scene/resources/mesh.h" -#include "servers/rendering/rasterizer_dummy.h" -#include "servers/rendering/renderer_compositor.h" -#include "servers/rendering_server.h" - -//class StubsScene : public RendererSceneRender { -class StubsScene : public RasterizerSceneDummy { - // StubsScene() {} - // ~StubsScene() {} -}; - -//class StubsStorage : public RendererStorage { -class StubsStorage : public RasterizerStorageDummy { - // StubsStorage() {} - // ~StubsStorage() {} -}; - -//class StubsCanvas : public RendererCanvasRender { -class StubsCanvas : public RasterizerCanvasDummy { - // StubsCanvas() {} - // ~StubsCanvas() {} -}; - -//class RasterizerDummy : public RendererCompositor { -//private: -// uint64_t frame = 1; -// float delta = 0; - -//protected: -// RasterizerCanvasDummy canvas; -// RasterizerStorageDummy storage; -// RasterizerSceneDummy scene; - -//public: -// RendererStorage *get_storage() override { return &storage; } -// RendererCanvasRender *get_canvas() override { return &canvas; } -// RendererSceneRender *get_scene() override { return &scene; } - -// void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true) override {} - -// void initialize() override {} -// void begin_frame(double frame_step) override { -// frame++; -// delta = frame_step; -// } - -// void prepare_for_blitting_render_targets() override {} -// void blit_render_targets_to_screen(int p_screen, const BlitToScreen *p_render_targets, int p_amount) override {} - -// void end_frame(bool p_swap_buffers) override { -// if (p_swap_buffers) { -// DisplayServer::get_singleton()->swap_buffers(); -// } -// } - -// void finalize() override {} - -// static RendererCompositor *_create_current() { -// return memnew(RasterizerDummy); -// } - -// static void make_current() { -// _create_func = _create_current; -// } - -// bool is_low_end() const override { return true; } -// uint64_t get_frame_number() const override { return frame; } -// float get_frame_delta_time() const override { return delta; } - -// RasterizerDummy() {} -// ~RasterizerDummy() {} -//}; - -/* -class StubsStorage : public RendererStorage { - -public: - // TEXTURE API - struct DummyTexture { - int width = 0; - int height = 0; - uint32_t flags = 0; - Image::Format format = Image::Format::FORMAT_MAX; - Ref<Image> image; - String path; - }; - - struct DummySurface { - uint32_t format = 0; - RS::PrimitiveType primitive = RS::PrimitiveType::PRIMITIVE_MAX; - Vector<uint8_t> array; - int vertex_count = 0; - Vector<uint8_t> index_array; - int index_count = 0; - AABB aabb; - Vector<Vector<uint8_t>> blend_shapes; - Vector<AABB> bone_aabbs; - }; - - struct DummyMesh { - Vector<DummySurface> surfaces; - int blend_shape_count = 0; - RS::BlendShapeMode blend_shape_mode = RS::BlendShapeMode::BLEND_SHAPE_MODE_NORMALIZED; - }; - - mutable RID_PtrOwner<DummyTexture> texture_owner; - mutable RID_PtrOwner<DummyMesh> mesh_owner; - - RID texture_2d_create(const Ref<Image> &p_image) override { return RID(); } - RID texture_2d_layered_create(const Vector<Ref<Image>> &p_layers, RS::TextureLayeredType p_layered_type) override { return RID(); } - RID texture_3d_create(Image::Format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_data) override { return RID(); } - RID texture_proxy_create(RID p_base) override { return RID(); } - - void texture_2d_update_immediate(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) override {} - void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) override {} - void texture_3d_update(RID p_texture, const Vector<Ref<Image>> &p_data) override {} - void texture_proxy_update(RID p_proxy, RID p_base) override {} - - RID texture_2d_placeholder_create() override { return RID(); } - RID texture_2d_layered_placeholder_create(RenderingServer::TextureLayeredType p_layered_type) override { return RID(); } - RID texture_3d_placeholder_create() override { return RID(); } - - Ref<Image> texture_2d_get(RID p_texture) const override { return Ref<Image>(); } - Ref<Image> texture_2d_layer_get(RID p_texture, int p_layer) const override { return Ref<Image>(); } - Vector<Ref<Image>> texture_3d_get(RID p_texture) const override { return Vector<Ref<Image>>(); } - - void texture_replace(RID p_texture, RID p_by_texture) override {} - void texture_set_size_override(RID p_texture, int p_width, int p_height) override {} -// FIXME: Disabled during Vulkan refactoring, should be ported. -#if 0 - void texture_bind(RID p_texture, uint32_t p_texture_no) = 0; -#endif - - void texture_set_path(RID p_texture, const String &p_path) override {} - String texture_get_path(RID p_texture) const override { return String(); } - - void texture_set_detect_3d_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override {} - void texture_set_detect_normal_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override {} - void texture_set_detect_roughness_callback(RID p_texture, RS::TextureDetectRoughnessCallback p_callback, void *p_userdata) override {} - - void texture_debug_usage(List<RS::TextureInfo> *r_info) override {} - void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) override {} - Size2 texture_size_with_proxy(RID p_proxy) override { return Size2(); } - - void texture_add_to_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override {} - void texture_remove_from_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override {} - - // CANVAS TEXTURE API - - RID canvas_texture_create() override { return RID(); } - void canvas_texture_set_channel(RID p_canvas_texture, RS::CanvasTextureChannel p_channel, RID p_texture) override {} - void canvas_texture_set_shading_parameters(RID p_canvas_texture, const Color &p_base_color, float p_shininess) override {} - - void canvas_texture_set_texture_filter(RID p_item, RS::CanvasItemTextureFilter p_filter) override {} - void canvas_texture_set_texture_repeat(RID p_item, RS::CanvasItemTextureRepeat p_repeat) override {} - -#if 0 - RID texture_create() override { - DummyTexture *texture = memnew(DummyTexture); - ERR_FAIL_COND_V(!texture, RID()); - return texture_owner.make_rid(texture); - } - - void texture_allocate(RID p_texture, int p_width, int p_height, int p_depth_3d, Image::Format p_format, RenderingServer::TextureType p_type = RS::TEXTURE_TYPE_2D, uint32_t p_flags = RS::TEXTURE_FLAGS_DEFAULT) override { - DummyTexture *t = texture_owner.getornull(p_texture); - ERR_FAIL_COND(!t); - t->width = p_width; - t->height = p_height; - t->flags = p_flags; - t->format = p_format; - t->image = Ref<Image>(memnew(Image)); - t->image->create(p_width, p_height, false, p_format); - } - void texture_set_data(RID p_texture, const Ref<Image> &p_image, int p_level) override { - DummyTexture *t = texture_owner.getornull(p_texture); - ERR_FAIL_COND(!t); - t->width = p_image->get_width(); - t->height = p_image->get_height(); - t->format = p_image->get_format(); - t->image->create(t->width, t->height, false, t->format, p_image->get_data()); - } - - void texture_set_data_partial(RID p_texture, const Ref<Image> &p_image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int p_dst_mip, int p_level) override { - DummyTexture *t = texture_owner.getornull(p_texture); - - ERR_FAIL_COND(!t); - ERR_FAIL_COND_MSG(p_image.is_null(), "It's not a reference to a valid Image object."); - ERR_FAIL_COND(t->format != p_image->get_format()); - ERR_FAIL_COND(src_w <= 0 || src_h <= 0); - ERR_FAIL_COND(src_x < 0 || src_y < 0 || src_x + src_w > p_image->get_width() || src_y + src_h > p_image->get_height()); - ERR_FAIL_COND(dst_x < 0 || dst_y < 0 || dst_x + src_w > t->width || dst_y + src_h > t->height); - - t->image->blit_rect(p_image, Rect2(src_x, src_y, src_w, src_h), Vector2(dst_x, dst_y)); - } - - Ref<Image> texture_get_data(RID p_texture, int p_level) const override { - DummyTexture *t = texture_owner.getornull(p_texture); - ERR_FAIL_COND_V(!t, Ref<Image>()); - return t->image; - } - void texture_set_flags(RID p_texture, uint32_t p_flags) override { - DummyTexture *t = texture_owner.getornull(p_texture); - ERR_FAIL_COND(!t); - t->flags = p_flags; - } - uint32_t texture_get_flags(RID p_texture) const override { - DummyTexture *t = texture_owner.getornull(p_texture); - ERR_FAIL_COND_V(!t, 0); - return t->flags; - } - Image::Format texture_get_format(RID p_texture) const override { - DummyTexture *t = texture_owner.getornull(p_texture); - ERR_FAIL_COND_V(!t, Image::FORMAT_RGB8); - return t->format; - } - - RenderingServer::TextureType texture_get_type(RID p_texture) const override { return RS::TEXTURE_TYPE_2D; } - uint32_t texture_get_texid(RID p_texture) const override { return 0; } - uint32_t texture_get_width(RID p_texture) const override { return 0; } - uint32_t texture_get_height(RID p_texture) const override { return 0; } - uint32_t texture_get_depth(RID p_texture) const override { return 0; } - void texture_set_size_override(RID p_texture, int p_width, int p_height, int p_depth_3d) override {} - void texture_bind(RID p_texture, uint32_t p_texture_no) override {} - - void texture_set_path(RID p_texture, const String &p_path) override { - DummyTexture *t = texture_owner.getornull(p_texture); - ERR_FAIL_COND(!t); - t->path = p_path; - } - String texture_get_path(RID p_texture) const override { - DummyTexture *t = texture_owner.getornull(p_texture); - ERR_FAIL_COND_V(!t, String()); - return t->path; - } - - void texture_set_shrink_all_x2_on_set_data(bool p_enable) override {} - - void texture_debug_usage(List<RS::TextureInfo> *r_info) override {} - - RID texture_create_radiance_cubemap(RID p_source, int p_resolution = -1) const override { return RID(); } - - void texture_set_detect_3d_callback(RID p_texture, RenderingServer::TextureDetectCallback p_callback, void *p_userdata) override {} - void texture_set_detect_srgb_callback(RID p_texture, RenderingServer::TextureDetectCallback p_callback, void *p_userdata) override {} - void texture_set_detect_normal_callback(RID p_texture, RenderingServer::TextureDetectCallback p_callback, void *p_userdata) override {} - - void textures_keep_original(bool p_enable) override {} - - void texture_set_proxy(RID p_proxy, RID p_base) override {} - Size2 texture_size_with_proxy(RID p_texture) const override { return Size2(); } - void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) override {} -#endif - - // SHADER API - - RID shader_create() override { return RID(); } - - void shader_set_code(RID p_shader, const String &p_code) override {} - String shader_get_code(RID p_shader) const override { return ""; } - void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const override {} - - void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) override {} - RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const override { return RID(); } - Variant shader_get_param_default(RID p_material, const StringName &p_param) const override { return Variant(); } - - // COMMON MATERIAL API - - RID material_create() override { return RID(); } - - void material_set_render_priority(RID p_material, int priority) override {} - void material_set_shader(RID p_shader_material, RID p_shader) override {} - - void material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) override {} - Variant material_get_param(RID p_material, const StringName &p_param) const override { return Variant(); } - - void material_set_next_pass(RID p_material, RID p_next_material) override {} - - bool material_is_animated(RID p_material) override { return false; } - bool material_casts_shadows(RID p_material) override { return false; } - void material_get_instance_shader_parameters(RID p_material, List<InstanceShaderParam> *r_parameters) override {} - void material_update_dependency(RID p_material, DependencyTracker *p_instance) override {} - - // MESH API - - RID mesh_create() override { - return RID(); - // DummyMesh *mesh = memnew(DummyMesh); - // ERR_FAIL_COND_V(!mesh, RID()); - // mesh->blend_shape_count = 0; - // mesh->blend_shape_mode = RS::BLEND_SHAPE_MODE_NORMALIZED; - // return mesh_owner.make_rid(mesh); - } - - void mesh_set_blend_shape_count(RID p_mesh, int p_blend_shape_count) override {} - - void mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface) override {} - -#if 0 - void mesh_add_surface(RID p_mesh, uint32_t p_format, RS::PrimitiveType p_primitive, const Vector<uint8_t> &p_array, int p_vertex_count, const Vector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<Vector<uint8_t> > &p_blend_shapes = Vector<Vector<uint8_t> >(), const Vector<AABB> &p_bone_aabbs = Vector<AABB>()) override { - DummyMesh *m = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND(!m); - - m->surfaces.push_back(DummySurface()); - DummySurface *s = &m->surfaces.write[m->surfaces.size() - 1]; - s->format = p_format; - s->primitive = p_primitive; - s->array = p_array; - s->vertex_count = p_vertex_count; - s->index_array = p_index_array; - s->index_count = p_index_count; - s->aabb = p_aabb; - s->blend_shapes = p_blend_shapes; - s->bone_aabbs = p_bone_aabbs; - } - - void mesh_set_blend_shape_count(RID p_mesh, int p_amount) override { - DummyMesh *m = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND(!m); - m->blend_shape_count = p_amount; - } -#endif - - int mesh_get_blend_shape_count(RID p_mesh) const override { - DummyMesh *m = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!m, 0); - return m->blend_shape_count; - } - - void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode) override { - // DummyMesh *m = mesh_owner.getornull(p_mesh); - // ERR_FAIL_COND(!m); - // m->blend_shape_mode = p_mode; - } - RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const override { - DummyMesh *m = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!m, RS::BLEND_SHAPE_MODE_NORMALIZED); - return m->blend_shape_mode; - } - - void mesh_surface_update_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override {} - - void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) override {} - RID mesh_surface_get_material(RID p_mesh, int p_surface) const override { return RID(); } - -#if 0 - int mesh_surface_get_array_len(RID p_mesh, int p_surface) const override { - DummyMesh *m = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!m, 0); - - return m->surfaces[p_surface].vertex_count; - } - int mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const override { - DummyMesh *m = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!m, 0); - - return m->surfaces[p_surface].index_count; - } - - Vector<uint8_t> mesh_surface_get_array(RID p_mesh, int p_surface) const override { - DummyMesh *m = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!m, Vector<uint8_t>()); - - return m->surfaces[p_surface].array; - } - Vector<uint8_t> mesh_surface_get_index_array(RID p_mesh, int p_surface) const override { - DummyMesh *m = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!m, Vector<uint8_t>()); - - return m->surfaces[p_surface].index_array; - } - - uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const override { - DummyMesh *m = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!m, 0); - - return m->surfaces[p_surface].format; - } - RS::PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const override { - DummyMesh *m = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!m, RS::PRIMITIVE_POINTS); - - return m->surfaces[p_surface].primitive; - } - - AABB mesh_surface_get_aabb(RID p_mesh, int p_surface) const override { - DummyMesh *m = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!m, AABB()); - - return m->surfaces[p_surface].aabb; - } - Vector<Vector<uint8_t> > mesh_surface_get_blend_shapes(RID p_mesh, int p_surface) const override { - DummyMesh *m = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!m, Vector<Vector<uint8_t> >()); - - return m->surfaces[p_surface].blend_shapes; - } - Vector<AABB> mesh_surface_get_skeleton_aabb(RID p_mesh, int p_surface) const override { - DummyMesh *m = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!m, Vector<AABB>()); - - return m->surfaces[p_surface].bone_aabbs; - } - - void mesh_remove_surface(RID p_mesh, int p_index) override { - DummyMesh *m = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND(!m); - ERR_FAIL_COND(p_index >= m->surfaces.size()); - - m->surfaces.remove(p_index); - } -#endif - - RS::SurfaceData mesh_get_surface(RID p_mesh, int p_surface) const override { return RS::SurfaceData(); } - int mesh_get_surface_count(RID p_mesh) const override { - DummyMesh *m = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!m, 0); - return m->surfaces.size(); - } - - void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) override {} - AABB mesh_get_custom_aabb(RID p_mesh) const override { return AABB(); } - - AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID()) override { return AABB(); } - void mesh_clear(RID p_mesh) override {} - - bool mesh_needs_instance(RID p_mesh, bool p_has_skeleton) override { return false; } - - // MESH INSTANCE - - RID mesh_instance_create(RID p_base) override { return RID(); } - void mesh_instance_set_skeleton(RID p_mesh_instance, RID p_skeleton) override {} - void mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int p_shape, float p_weight) override {} - void mesh_instance_check_for_update(RID p_mesh_instance) override {} - void update_mesh_instances() override {} - - // MULTIMESH API - - RID multimesh_create() override { return RID(); } - - void multimesh_allocate(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false) override {} - int multimesh_get_instance_count(RID p_multimesh) const override { return 0; } - - void multimesh_set_mesh(RID p_multimesh, RID p_mesh) override {} - void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform &p_transform) override {} - void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) override {} - void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) override {} - void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) override {} - - RID multimesh_get_mesh(RID p_multimesh) const override { return RID(); } - AABB multimesh_get_aabb(RID p_multimesh) const override { return AABB(); } - - Transform multimesh_instance_get_transform(RID p_multimesh, int p_index) const override { return Transform(); } - Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const override { return Transform2D(); } - Color multimesh_instance_get_color(RID p_multimesh, int p_index) const override { return Color(); } - Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const override { return Color(); } - void multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) override {} - Vector<float> multimesh_get_buffer(RID p_multimesh) const override { return Vector<float>(); } - - void multimesh_set_visible_instances(RID p_multimesh, int p_visible) override {} - int multimesh_get_visible_instances(RID p_multimesh) const override { return 0; } - - // IMMEDIATE API - - RID immediate_create() override { return RID(); } - void immediate_begin(RID p_immediate, RS::PrimitiveType p_rimitive, RID p_texture = RID()) override {} - void immediate_vertex(RID p_immediate, const Vector3 &p_vertex) override {} - void immediate_normal(RID p_immediate, const Vector3 &p_normal) override {} - void immediate_tangent(RID p_immediate, const Plane &p_tangent) override {} - void immediate_color(RID p_immediate, const Color &p_color) override {} - void immediate_uv(RID p_immediate, const Vector2 &tex_uv) override {} - void immediate_uv2(RID p_immediate, const Vector2 &tex_uv) override {} - void immediate_end(RID p_immediate) override {} - void immediate_clear(RID p_immediate) override {} - void immediate_set_material(RID p_immediate, RID p_material) override {} - RID immediate_get_material(RID p_immediate) const override { return RID(); } - AABB immediate_get_aabb(RID p_immediate) const override { return AABB(); } - - // SKELETON API - - RID skeleton_create() override { return RID(); } - void skeleton_allocate(RID p_skeleton, int p_bones, bool p_2d_skeleton = false) override {} - void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform) override {} - int skeleton_get_bone_count(RID p_skeleton) const override { return 0; } - void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform &p_transform) override {} - Transform skeleton_bone_get_transform(RID p_skeleton, int p_bone) const override { return Transform(); } - void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform) override {} - Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const override { return Transform2D(); } - - // Light API - - RID light_create(RS::LightType p_type) override { return RID(); } - - void light_set_color(RID p_light, const Color &p_color) override {} - void light_set_param(RID p_light, RS::LightParam p_param, float p_value) override {} - void light_set_shadow(RID p_light, bool p_enabled) override {} - void light_set_shadow_color(RID p_light, const Color &p_color) override {} - void light_set_projector(RID p_light, RID p_texture) override {} - void light_set_negative(RID p_light, bool p_enable) override {} - void light_set_cull_mask(RID p_light, uint32_t p_mask) override {} - void light_set_reverse_cull_face_mode(RID p_light, bool p_enabled) override {} - void light_set_bake_mode(RID p_light, RS::LightBakeMode p_bake_mode) override {} - void light_set_max_sdfgi_cascade(RID p_light, uint32_t p_cascade) override {} - - void light_omni_set_shadow_mode(RID p_light, RS::LightOmniShadowMode p_mode) override {} - - void light_directional_set_shadow_mode(RID p_light, RS::LightDirectionalShadowMode p_mode) override {} - void light_directional_set_blend_splits(RID p_light, bool p_enable) override {} - bool light_directional_get_blend_splits(RID p_light) const override { return false; } - void light_directional_set_shadow_depth_range_mode(RID p_light, RS::LightDirectionalShadowDepthRangeMode p_range_mode) override {} - void light_directional_set_sky_only(RID p_light, bool p_sky_only) override {} - bool light_directional_is_sky_only(RID p_light) const override { return false; } - RS::LightDirectionalShadowDepthRangeMode light_directional_get_shadow_depth_range_mode(RID p_light) const override { return RS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE; } - - RS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light) override { return RS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL; } - RS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light) override { return RS::LIGHT_OMNI_SHADOW_DUAL_PARABOLOID; } - - bool light_has_shadow(RID p_light) const override { return false; } - - RS::LightType light_get_type(RID p_light) const override { return RS::LIGHT_OMNI; } - AABB light_get_aabb(RID p_light) const override { return AABB(); } - float light_get_param(RID p_light, RS::LightParam p_param) override { return 0.0; } - Color light_get_color(RID p_light) override { return Color(); } - RS::LightBakeMode light_get_bake_mode(RID p_light) override { return RS::LIGHT_BAKE_DISABLED; } - uint32_t light_get_max_sdfgi_cascade(RID p_light) override { return 0; } - uint64_t light_get_version(RID p_light) const override { return 0; } - - // PROBE API - - RID reflection_probe_create() override { return RID(); } - - void reflection_probe_set_update_mode(RID p_probe, RS::ReflectionProbeUpdateMode p_mode) override {} - void reflection_probe_set_intensity(RID p_probe, float p_intensity) override {} - void reflection_probe_set_ambient_mode(RID p_probe, RS::ReflectionProbeAmbientMode p_mode) override {} - void reflection_probe_set_ambient_color(RID p_probe, const Color &p_color) override {} - void reflection_probe_set_ambient_energy(RID p_probe, float p_energy) override {} - void reflection_probe_set_max_distance(RID p_probe, float p_distance) override {} - void reflection_probe_set_extents(RID p_probe, const Vector3 &p_extents) override {} - void reflection_probe_set_origin_offset(RID p_probe, const Vector3 &p_offset) override {} - void reflection_probe_set_as_interior(RID p_probe, bool p_enable) override {} - void reflection_probe_set_enable_box_projection(RID p_probe, bool p_enable) override {} - void reflection_probe_set_enable_shadows(RID p_probe, bool p_enable) override {} - void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers) override {} - void reflection_probe_set_resolution(RID p_probe, int p_resolution) override {} - void reflection_probe_set_lod_threshold(RID p_probe, float p_ratio) override {} - float reflection_probe_get_lod_threshold(RID p_probe) const override { return 0.0f; } - - AABB reflection_probe_get_aabb(RID p_probe) const override { return AABB(); } - RS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const override { return RenderingServer::REFLECTION_PROBE_UPDATE_ONCE; } - uint32_t reflection_probe_get_cull_mask(RID p_probe) const override { return 0; } - Vector3 reflection_probe_get_extents(RID p_probe) const override { return Vector3(); } - Vector3 reflection_probe_get_origin_offset(RID p_probe) const override { return Vector3(); } - float reflection_probe_get_origin_max_distance(RID p_probe) const override { return 0.0; } - bool reflection_probe_renders_shadows(RID p_probe) const override { return false; } - - void base_update_dependency(RID p_base, DependencyTracker *p_instance) override {} - void skeleton_update_dependency(RID p_base, DependencyTracker *p_instance) override {} - - // DECAL API - - RID decal_create() override { return RID(); } - void decal_set_extents(RID p_decal, const Vector3 &p_extents) override {} - void decal_set_texture(RID p_decal, RS::DecalTexture p_type, RID p_texture) override {} - void decal_set_emission_energy(RID p_decal, float p_energy) override {} - void decal_set_albedo_mix(RID p_decal, float p_mix) override {} - void decal_set_modulate(RID p_decal, const Color &p_modulate) override {} - void decal_set_cull_mask(RID p_decal, uint32_t p_layers) override {} - void decal_set_distance_fade(RID p_decal, bool p_enabled, float p_begin, float p_length) override {} - void decal_set_fade(RID p_decal, float p_above, float p_below) override {} - void decal_set_normal_fade(RID p_decal, float p_fade) override {} - - AABB decal_get_aabb(RID p_decal) const override { return AABB(); } - - // GI PROBE API - - RID gi_probe_create() override { return RID(); } - - void gi_probe_allocate(RID p_gi_probe, const Transform &p_to_cell_xform, const AABB &p_aabb, const Vector3i &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts) override {} - - AABB gi_probe_get_bounds(RID p_gi_probe) const override { return AABB(); } - Vector3i gi_probe_get_octree_size(RID p_gi_probe) const override { return Vector3i(); } - Vector<uint8_t> gi_probe_get_octree_cells(RID p_gi_probe) const override { return Vector<uint8_t>(); } - Vector<uint8_t> gi_probe_get_data_cells(RID p_gi_probe) const override { return Vector<uint8_t>(); } - Vector<uint8_t> gi_probe_get_distance_field(RID p_gi_probe) const override { return Vector<uint8_t>(); } - - Vector<int> gi_probe_get_level_counts(RID p_gi_probe) const override { return Vector<int>(); } - Transform gi_probe_get_to_cell_xform(RID p_gi_probe) const override { return Transform(); } - - void gi_probe_set_dynamic_range(RID p_gi_probe, float p_range) override {} - float gi_probe_get_dynamic_range(RID p_gi_probe) const override { return 0; } - - void gi_probe_set_propagation(RID p_gi_probe, float p_range) override {} - float gi_probe_get_propagation(RID p_gi_probe) const override { return 0; } - - void gi_probe_set_energy(RID p_gi_probe, float p_range) override {} - float gi_probe_get_energy(RID p_gi_probe) const override { return 0.0; } - - void gi_probe_set_ao(RID p_gi_probe, float p_ao) override {} - float gi_probe_get_ao(RID p_gi_probe) const override { return 0; } - - void gi_probe_set_ao_size(RID p_gi_probe, float p_strength) override {} - float gi_probe_get_ao_size(RID p_gi_probe) const override { return 0; } - - void gi_probe_set_bias(RID p_gi_probe, float p_range) override {} - float gi_probe_get_bias(RID p_gi_probe) const override { return 0.0; } - - void gi_probe_set_normal_bias(RID p_gi_probe, float p_range) override {} - float gi_probe_get_normal_bias(RID p_gi_probe) const override { return 0.0; } - - void gi_probe_set_interior(RID p_gi_probe, bool p_enable) override {} - bool gi_probe_is_interior(RID p_gi_probe) const override { return false; } - - void gi_probe_set_use_two_bounces(RID p_gi_probe, bool p_enable) override {} - bool gi_probe_is_using_two_bounces(RID p_gi_probe) const override { return false; } - - void gi_probe_set_anisotropy_strength(RID p_gi_probe, float p_strength) override {} - float gi_probe_get_anisotropy_strength(RID p_gi_probe) const override { return 0; } - - uint32_t gi_probe_get_version(RID p_gi_probe) override { return 0; } - - // LIGHTMAP CAPTURE -#if 0 - struct Instantiable { - SelfList<RendererSceneRender::InstanceBase>::List instance_list; - - _FORCE_INLINE_ void instance_change_notify(bool p_aabb = true, bool p_materials = true) override { - SelfList<RendererSceneRender::InstanceBase> *instances = instance_list.first(); - while (instances) override { - //instances->self()->base_changed(p_aabb, p_materials); - instances = instances->next(); - } - } - - _FORCE_INLINE_ void instance_remove_deps() override { - SelfList<RendererSceneRender::InstanceBase> *instances = instance_list.first(); - while (instances) override { - SelfList<RendererSceneRender::InstanceBase> *next = instances->next(); - //instances->self()->base_removed(); - instances = next; - } - } - - Instantiable() override {} - ~Instantiable() override { - } - }; - - struct LightmapCapture : public Instantiable { - Vector<LightmapCaptureOctree> octree; - AABB bounds; - Transform cell_xform; - int cell_subdiv; - float energy; - LightmapCapture() override { - energy = 1.0; - cell_subdiv = 1; - } - }; - - mutable RID_PtrOwner<LightmapCapture> lightmap_capture_data_owner; - void lightmap_capture_set_bounds(RID p_capture, const AABB &p_bounds) override {} - AABB lightmap_capture_get_bounds(RID p_capture) const override { return AABB(); } - void lightmap_capture_set_octree(RID p_capture, const Vector<uint8_t> &p_octree) override {} - RID lightmap_capture_create() override { - LightmapCapture *capture = memnew(LightmapCapture); - return lightmap_capture_data_owner.make_rid(capture); - } - Vector<uint8_t> lightmap_capture_get_octree(RID p_capture) const override { - const LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture); - ERR_FAIL_COND_V(!capture, Vector<uint8_t>()); - return Vector<uint8_t>(); - } - void lightmap_capture_set_octree_cell_transform(RID p_capture, const Transform &p_xform) override {} - Transform lightmap_capture_get_octree_cell_transform(RID p_capture) const override { return Transform(); } - void lightmap_capture_set_octree_cell_subdiv(RID p_capture, int p_subdiv) override {} - int lightmap_capture_get_octree_cell_subdiv(RID p_capture) const override { return 0; } - void lightmap_capture_set_energy(RID p_capture, float p_energy) override {} - float lightmap_capture_get_energy(RID p_capture) const override { return 0.0; } - const Vector<LightmapCaptureOctree> *lightmap_capture_get_octree_ptr(RID p_capture) const override { - const LightmapCapture *capture = lightmap_capture_data_owner.getornull(p_capture); - ERR_FAIL_COND_V(!capture, nullptr); - return &capture->octree; - } -#endif - - RID lightmap_create() override { return RID(); } - - void lightmap_set_textures(RID p_lightmap, RID p_light, bool p_uses_spherical_haromics) override {} - void lightmap_set_probe_bounds(RID p_lightmap, const AABB &p_bounds) override {} - void lightmap_set_probe_interior(RID p_lightmap, bool p_interior) override {} - void lightmap_set_probe_capture_data(RID p_lightmap, const PackedVector3Array &p_points, const PackedColorArray &p_point_sh, const PackedInt32Array &p_tetrahedra, const PackedInt32Array &p_bsp_tree) override {} - PackedVector3Array lightmap_get_probe_capture_points(RID p_lightmap) const override { return PackedVector3Array(); } - PackedColorArray lightmap_get_probe_capture_sh(RID p_lightmap) const override { return PackedColorArray(); } - PackedInt32Array lightmap_get_probe_capture_tetrahedra(RID p_lightmap) const override { return PackedInt32Array(); } - PackedInt32Array lightmap_get_probe_capture_bsp_tree(RID p_lightmap) const override { return PackedInt32Array(); } - AABB lightmap_get_aabb(RID p_lightmap) const override { return AABB(); } - void lightmap_tap_sh_light(RID p_lightmap, const Vector3 &p_point, Color *r_sh) override {} - bool lightmap_is_interior(RID p_lightmap) const override { return false; } - void lightmap_set_probe_capture_update_speed(float p_speed) override {} - float lightmap_get_probe_capture_update_speed() const override { return 0; } - - // PARTICLES - - RID particles_create() override { return RID(); } - - void particles_emit(RID p_particles, const Transform &p_transform, const Vector3 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags) override {} - void particles_set_emitting(RID p_particles, bool p_emitting) override {} - void particles_set_amount(RID p_particles, int p_amount) override {} - void particles_set_lifetime(RID p_particles, float p_lifetime) override {} - void particles_set_one_shot(RID p_particles, bool p_one_shot) override {} - void particles_set_pre_process_time(RID p_particles, float p_time) override {} - void particles_set_explosiveness_ratio(RID p_particles, float p_ratio) override {} - void particles_set_randomness_ratio(RID p_particles, float p_ratio) override {} - void particles_set_custom_aabb(RID p_particles, const AABB &p_aabb) override {} - void particles_set_speed_scale(RID p_particles, float p_scale) override {} - void particles_set_use_local_coordinates(RID p_particles, bool p_enable) override {} - void particles_set_process_material(RID p_particles, RID p_material) override {} - void particles_set_fixed_fps(RID p_particles, int p_fps) override {} - void particles_set_fractional_delta(RID p_particles, bool p_enable) override {} - void particles_set_subemitter(RID p_particles, RID p_subemitter_particles) override {} - void particles_set_view_axis(RID p_particles, const Vector3 &p_axis) override {} - void particles_set_collision_base_size(RID p_particles, float p_size) override {} - void particles_restart(RID p_particles) override {} - - void particles_set_draw_order(RID p_particles, RS::ParticlesDrawOrder p_order) override {} - - void particles_set_draw_passes(RID p_particles, int p_count) override {} - void particles_set_draw_pass_mesh(RID p_particles, int p_pass, RID p_mesh) override {} - - void particles_request_process(RID p_particles) override {} - AABB particles_get_current_aabb(RID p_particles) override { return AABB(); } - AABB particles_get_aabb(RID p_particles) const override { return AABB(); } - - void particles_set_emission_transform(RID p_particles, const Transform &p_transform) override {} - - bool particles_get_emitting(RID p_particles) override { return false; } - int particles_get_draw_passes(RID p_particles) const override { return 0; } - RID particles_get_draw_pass_mesh(RID p_particles, int p_pass) const override { return RID(); } - - void particles_add_collision(RID p_particles, RID p_particles_collision_instance) override {} - void particles_remove_collision(RID p_particles, RID p_particles_collision_instance) override {} - - void update_particles() override {} - - // PARTICLES COLLISION - - RID particles_collision_create() override { return RID(); } - void particles_collision_set_collision_type(RID p_particles_collision, RS::ParticlesCollisionType p_type) override {} - void particles_collision_set_cull_mask(RID p_particles_collision, uint32_t p_cull_mask) override {} - void particles_collision_set_sphere_radius(RID p_particles_collision, float p_radius) override {} - void particles_collision_set_box_extents(RID p_particles_collision, const Vector3 &p_extents) override {} - void particles_collision_set_attractor_strength(RID p_particles_collision, float p_strength) override {} - void particles_collision_set_attractor_directionality(RID p_particles_collision, float p_directionality) override {} - void particles_collision_set_attractor_attenuation(RID p_particles_collision, float p_curve) override {} - void particles_collision_set_field_texture(RID p_particles_collision, RID p_texture) override {} - void particles_collision_height_field_update(RID p_particles_collision) override {} - void particles_collision_set_height_field_resolution(RID p_particles_collision, RS::ParticlesCollisionHeightfieldResolution p_resolution) override {} - AABB particles_collision_get_aabb(RID p_particles_collision) const override { return AABB(); } - bool particles_collision_is_heightfield(RID p_particles_collision) const override { return false; } - RID particles_collision_get_heightfield_framebuffer(RID p_particles_collision) const override { return RID(); } - - //used from 2D and 3D - RID particles_collision_instance_create(RID p_collision) override { return RID(); } - void particles_collision_instance_set_transform(RID p_collision_instance, const Transform &p_transform) override {} - void particles_collision_instance_set_active(RID p_collision_instance, bool p_active) override {} - - // GLOBAL VARIABLES - - void global_variable_add(const StringName &p_name, RS::GlobalVariableType p_type, const Variant &p_value) override {} - void global_variable_remove(const StringName &p_name) override {} - Vector<StringName> global_variable_get_list() const override { return Vector<StringName>(); } - - void global_variable_set(const StringName &p_name, const Variant &p_value) override {} - void global_variable_set_override(const StringName &p_name, const Variant &p_value) override {} - Variant global_variable_get(const StringName &p_name) const override { return Variant(); } - RS::GlobalVariableType global_variable_get_type(const StringName &p_name) const override { return RS::GLOBAL_VAR_TYPE_MAX; } - - void global_variables_load_settings(bool p_load_textures = true) override {} - void global_variables_clear() override {} - - int32_t global_variables_instance_allocate(RID p_instance) override { return 0; } - void global_variables_instance_free(RID p_instance) override {} - void global_variables_instance_update(RID p_instance, int p_index, const Variant &p_value) override {} - - bool particles_is_inactive(RID p_particles) const override { return false; } - - // RENDER TARGET - - RID render_target_create() override { return RID(); } - void render_target_set_position(RID p_render_target, int p_x, int p_y) override {} - void render_target_set_size(RID p_render_target, int p_width, int p_height) override {} - RID render_target_get_texture(RID p_render_target) override { return RID(); } - void render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id) override {} - void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value) override {} - bool render_target_was_used(RID p_render_target) override { return false; } - void render_target_set_as_unused(RID p_render_target) override {} - - void render_target_request_clear(RID p_render_target, const Color &p_clear_color) override {} - bool render_target_is_clear_requested(RID p_render_target) override { return false; } - Color render_target_get_clear_request_color(RID p_render_target) override { return Color(); } - void render_target_disable_clear_request(RID p_render_target) override {} - void render_target_do_clear_request(RID p_render_target) override {} - - void render_target_set_sdf_size_and_scale(RID p_render_target, RS::ViewportSDFOversize p_size, RS::ViewportSDFScale p_scale) override {} - Rect2i render_target_get_sdf_rect(RID p_render_target) const override { return Rect2i(); } - - RS::InstanceType get_base_type(RID p_rid) const override { - if (mesh_owner.owns(p_rid)) { - return RS::INSTANCE_MESH; - } - - return RS::INSTANCE_NONE; - } - - bool free(RID p_rid) override { - if (texture_owner.owns(p_rid)) { - // delete the texture - DummyTexture *texture = texture_owner.getornull(p_rid); - texture_owner.free(p_rid); - memdelete(texture); - } - - if (mesh_owner.owns(p_rid)) { - // delete the mesh - DummyMesh *mesh = mesh_owner.getornull(p_rid); - mesh_owner.free(p_rid); - memdelete(mesh); - } - return true; - } - - bool has_os_feature(const String &p_feature) const override { return false; } - - void update_dirty_resources() override {} - - void set_debug_generate_wireframes(bool p_generate) override {} - - void render_info_begin_capture() override {} - void render_info_end_capture() override {} - int get_captured_render_info(RS::RenderInfo p_info) override { return 0; } - - int get_render_info(RS::RenderInfo p_info) override { return 0; } - String get_video_adapter_name() const override { return String(); } - String get_video_adapter_vendor() const override { return String(); } - - static RendererStorage *base_singleton; - - void capture_timestamps_begin() override {} - void capture_timestamp(const String &p_name) override {} - uint32_t get_captured_timestamps_count() const override { return 0; } - uint64_t get_captured_timestamps_frame() const override { return 0; } - uint64_t get_captured_timestamp_gpu_time(uint32_t p_index) const override { return 0; } - uint64_t get_captured_timestamp_cpu_time(uint32_t p_index) const override { return 0; } - String get_captured_timestamp_name(uint32_t p_index) const override { return String(); } - StubsStorage() {} - ~StubsStorage() {} -}; -*/ - -/* SCENE -public: -GeometryInstance *geometry_instance_create(RID p_base) override { return nullptr; } -void geometry_instance_set_skeleton(GeometryInstance *p_geometry_instance, RID p_skeleton) override {} -void geometry_instance_set_material_override(GeometryInstance *p_geometry_instance, RID p_override) override {} -void geometry_instance_set_surface_materials(GeometryInstance *p_geometry_instance, const Vector<RID> &p_material) override {} -void geometry_instance_set_mesh_instance(GeometryInstance *p_geometry_instance, RID p_mesh_instance) override {} -void geometry_instance_set_transform(GeometryInstance *p_geometry_instance, const Transform &p_transform, const AABB &p_aabb, const AABB &p_transformed_aabbb) override {} -void geometry_instance_set_layer_mask(GeometryInstance *p_geometry_instance, uint32_t p_layer_mask) override {} -void geometry_instance_set_lod_bias(GeometryInstance *p_geometry_instance, float p_lod_bias) override {} -void geometry_instance_set_use_baked_light(GeometryInstance *p_geometry_instance, bool p_enable) override {} -void geometry_instance_set_use_dynamic_gi(GeometryInstance *p_geometry_instance, bool p_enable) override {} -void geometry_instance_set_use_lightmap(GeometryInstance *p_geometry_instance, RID p_lightmap_instance, const Rect2 &p_lightmap_uv_scale, int p_lightmap_slice_index) override {} -void geometry_instance_set_lightmap_capture(GeometryInstance *p_geometry_instance, const Color *p_sh9) override {} -void geometry_instance_set_instance_shader_parameters_offset(GeometryInstance *p_geometry_instance, int32_t p_offset) override {} -void geometry_instance_set_cast_double_sided_shadows(GeometryInstance *p_geometry_instance, bool p_enable) override {} - -uint32_t geometry_instance_get_pair_mask() override { return 0; } -void geometry_instance_pair_light_instances(GeometryInstance *p_geometry_instance, const RID *p_light_instances, uint32_t p_light_instance_count) override {} -void geometry_instance_pair_reflection_probe_instances(GeometryInstance *p_geometry_instance, const RID *p_reflection_probe_instances, uint32_t p_reflection_probe_instance_count) override {} -void geometry_instance_pair_decal_instances(GeometryInstance *p_geometry_instance, const RID *p_decal_instances, uint32_t p_decal_instance_count) override {} -void geometry_instance_pair_gi_probe_instances(GeometryInstance *p_geometry_instance, const RID *p_gi_probe_instances, uint32_t p_gi_probe_instance_count) override {} - -void geometry_instance_free(GeometryInstance *p_geometry_instance) override {} - -// SHADOW ATLAS API - -RID shadow_atlas_create() override { return RID(); } -void shadow_atlas_set_size(RID p_atlas, int p_size) override {} -void shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision) override {} -bool shadow_atlas_update_light(RID p_atlas, RID p_light_intance, float p_coverage, uint64_t p_light_version) override { return false; } - -void directional_shadow_atlas_set_size(int p_size) override {} -int get_directional_light_shadow_size(RID p_light_intance) override { return 0; } -void set_directional_shadow_count(int p_count) override {} - -// SDFGI UPDATE - -void sdfgi_update(RID p_render_buffers, RID p_environment, const Vector3 &p_world_position) override {} -int sdfgi_get_pending_region_count(RID p_render_buffers) const override { return 0; } -AABB sdfgi_get_pending_region_bounds(RID p_render_buffers, int p_region) const override { return AABB(); } -uint32_t sdfgi_get_pending_region_cascade(RID p_render_buffers, int p_region) const override { return 0; } -void sdfgi_update_probes(RID p_render_buffers, RID p_environment, const Vector<RID> &p_directional_lights, const RID *p_positional_light_instances, uint32_t p_positional_light_count) override {} - -// SKY API - -RID sky_create() override { return RID(); } -void sky_set_radiance_size(RID p_sky, int p_radiance_size) override {} -void sky_set_mode(RID p_sky, RS::SkyMode p_samples) override {} -void sky_set_material(RID p_sky, RID p_material) override {} -Ref<Image> sky_bake_panorama(RID p_sky, float p_energy, bool p_bake_irradiance, const Size2i &p_size) override { return Ref<Image>(); } - -// ENVIRONMENT API - -RID environment_create() override { return RID(); } - -void environment_set_background(RID p_env, RS::EnvironmentBG p_bg) override {} -void environment_set_sky(RID p_env, RID p_sky) override {} -void environment_set_sky_custom_fov(RID p_env, float p_scale) override {} -void environment_set_sky_orientation(RID p_env, const Basis &p_orientation) override {} -void environment_set_bg_color(RID p_env, const Color &p_color) override {} -void environment_set_bg_energy(RID p_env, float p_energy) override {} -void environment_set_canvas_max_layer(RID p_env, int p_max_layer) override {} -void environment_set_ambient_light(RID p_env, const Color &p_color, RS::EnvironmentAmbientSource p_ambient = RS::ENV_AMBIENT_SOURCE_BG, float p_energy = 1.0, float p_sky_contribution = 0.0, RS::EnvironmentReflectionSource p_reflection_source = RS::ENV_REFLECTION_SOURCE_BG, const Color &p_ao_color = Color()) override {} - -void environment_set_glow(RID p_env, bool p_enable, Vector<float> p_levels, float p_intensity, float p_strength, float p_mix, float p_bloom_threshold, RS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap) override {} -void environment_glow_set_use_bicubic_upscale(bool p_enable) override {} -void environment_glow_set_use_high_quality(bool p_enable) override {} - -void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance) override {} -void environment_set_ssr_roughness_quality(RS::EnvironmentSSRRoughnessQuality p_quality) override {} -void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_power, float p_detail, float p_horizon, float p_sharpness, float p_light_affect, float p_ao_channel_affect) override {} -void environment_set_ssao_quality(RS::EnvironmentSSAOQuality p_quality, bool p_half_size, float p_adaptive_target, int p_blur_passes, float p_fadeout_from, float p_fadeout_to) override {} - -void environment_set_sdfgi(RID p_env, bool p_enable, RS::EnvironmentSDFGICascades p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, bool p_use_multibounce, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) override {} - -void environment_set_sdfgi_ray_count(RS::EnvironmentSDFGIRayCount p_ray_count) override {} -void environment_set_sdfgi_frames_to_converge(RS::EnvironmentSDFGIFramesToConverge p_frames) override {} - -void environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale) override {} - -void environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, bool p_use_1d_color_correction, RID p_color_correction) override {} - -void environment_set_fog(RID p_env, bool p_enable, const Color &p_light_color, float p_light_energy, float p_sun_scatter, float p_density, float p_height, float p_height_density, float p_aerial_perspective) override {} -void environment_set_volumetric_fog(RID p_env, bool p_enable, float p_density, const Color &p_light, float p_light_energy, float p_length, float p_detail_spread, float p_gi_inject, RS::EnvVolumetricFogShadowFilter p_shadow_filter) override {} -void environment_set_volumetric_fog_volume_size(int p_size, int p_depth) override {} -void environment_set_volumetric_fog_filter_active(bool p_enable) override {} -void environment_set_volumetric_fog_directional_shadow_shrink_size(int p_shrink_size) override {} -void environment_set_volumetric_fog_positional_shadow_shrink_size(int p_shrink_size) override {} - -Ref<Image> environment_bake_panorama(RID p_env, bool p_bake_irradiance, const Size2i &p_size) override { return Ref<Image>(); } - -bool is_environment(RID p_env) const override { return false; } -RS::EnvironmentBG environment_get_background(RID p_env) const override { return RS::ENV_BG_KEEP; } -int environment_get_canvas_max_layer(RID p_env) const override { return 0; } - -RID camera_effects_create() override { return RID(); } - -void camera_effects_set_dof_blur_quality(RS::DOFBlurQuality p_quality, bool p_use_jitter) override {} -void camera_effects_set_dof_blur_bokeh_shape(RS::DOFBokehShape p_shape) override {} - -void camera_effects_set_dof_blur(RID p_camera_effects, bool p_far_enable, float p_far_distance, float p_far_transition, bool p_near_enable, float p_near_distance, float p_near_transition, float p_amount) override {} -void camera_effects_set_custom_exposure(RID p_camera_effects, bool p_enable, float p_exposure) override {} - -void shadows_quality_set(RS::ShadowQuality p_quality) override {} -void directional_shadow_quality_set(RS::ShadowQuality p_quality) override {} - -RID light_instance_create(RID p_light) override { return RID(); } -void light_instance_set_transform(RID p_light_instance, const Transform &p_transform) override {} -void light_instance_set_aabb(RID p_light_instance, const AABB &p_aabb) override {} -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_shadow_texel_size, float p_bias_scale = 1.0, float p_range_begin = 0, const Vector2 &p_uv_scale = Vector2()) override {} -void light_instance_mark_visible(RID p_light_instance) override {} - -RID reflection_atlas_create() override { return RID(); } -void reflection_atlas_set_size(RID p_ref_atlas, int p_reflection_size, int p_reflection_count) override {} -int reflection_atlas_get_size(RID p_ref_atlas) const override { return 0; } - -RID reflection_probe_instance_create(RID p_probe) override { return RID(); } -void reflection_probe_instance_set_transform(RID p_instance, const Transform &p_transform) override {} -void reflection_probe_release_atlas_index(RID p_instance) override {} -bool reflection_probe_instance_needs_redraw(RID p_instance) override { return false; } -bool reflection_probe_instance_has_reflection(RID p_instance) override { return false; } -bool reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas) override { return false; } -bool reflection_probe_instance_postprocess_step(RID p_instance) override { return true; } - -RID decal_instance_create(RID p_decal) override { return RID(); } -void decal_instance_set_transform(RID p_decal, const Transform &p_transform) override {} - -RID lightmap_instance_create(RID p_lightmap) override { return RID(); } -void lightmap_instance_set_transform(RID p_lightmap, const Transform &p_transform) override {} - -RID gi_probe_instance_create(RID p_gi_probe) override { return RID(); } -void gi_probe_instance_set_transform_to_data(RID p_probe, const Transform &p_xform) override {} -bool gi_probe_needs_update(RID p_probe) const override { return false; } -void gi_probe_update(RID p_probe, bool p_update_light_instances, const Vector<RID> &p_light_instances, const PagedArray<GeometryInstance *> &p_dynamic_objects) override {} - -void gi_probe_set_quality(RS::GIProbeQuality) override {} - -void render_scene(RID p_render_buffers, const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_gi_probes, const PagedArray<RID> &p_decals, const PagedArray<RID> &p_lightmaps, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_lod_threshold) override {} - -void render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, const PagedArray<GeometryInstance *> &p_instances, const Plane &p_camera_plane = Plane(), float p_lod_distance_multiplier = 0, float p_screen_lod_threshold = 0.0) override {} - -void render_material(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override {} - -void render_sdfgi(RID p_render_buffers, int p_region, const PagedArray<GeometryInstance *> &p_instances) override {} - -void render_sdfgi_static_lights(RID p_render_buffers, uint32_t p_cascade_count, const uint32_t *p_cascade_indices, const PagedArray<RID> *p_positional_lights) override {} - -void render_particle_collider_heightfield(RID p_collider, const Transform &p_transform, const PagedArray<GeometryInstance *> &p_instances) override {} - -void set_scene_pass(uint64_t p_pass) override {} -void set_time(double p_time, double p_step) override {} -void set_debug_draw_mode(RS::ViewportDebugDraw p_debug_draw) override {} - -RID render_buffers_create() override { return RID(); } -void render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_width, int p_height, RS::ViewportMSAA p_msaa, RS::ViewportScreenSpaceAA p_screen_space_aa, bool p_use_debanding) override {} - -void screen_space_roughness_limiter_set_active(bool p_enable, float p_amount, float p_curve) override {} -bool screen_space_roughness_limiter_is_active() const override { return false; } - -void sub_surface_scattering_set_quality(RS::SubSurfaceScatteringQuality p_quality) override {} -void sub_surface_scattering_set_scale(float p_scale, float p_depth_scale) override {} - -TypedArray<Image> bake_render_uv2(RID p_base, const Vector<RID> &p_material_overrides, const Size2i &p_image_size) override { return TypedArray<Image>(); } - -bool free(RID p_rid) override { return true; } -void update() override {} -void sdfgi_set_debug_probe_select(const Vector3 &p_position, const Vector3 &p_dir) override {} - -bool is_low_end() const override { return true; } -*/ - -/* -class StubsCanvas : public RendererCanvasRender { -public: - PolygonID request_polygon(const Vector<int> &p_indices, const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs = Vector<Point2>(), const Vector<int> &p_bones = Vector<int>(), const Vector<float> &p_weights = Vector<float>()) override { return 0; } - void free_polygon(PolygonID p_polygon) override {} - - void canvas_render_items(RID p_to_render_target, Item *p_item_list, const Color &p_modulate, Light *p_light_list, Light *p_directional_list, const Transform2D &p_canvas_transform, RS::CanvasItemTextureFilter p_default_filter, RS::CanvasItemTextureRepeat p_default_repeat, bool p_snap_2d_vertices_to_pixel, bool &r_sdf_used) override {} - void canvas_debug_viewport_shadows(Light *p_lights_with_shadow) override {} - - RID light_create() override { return RID(); } - void light_set_texture(RID p_rid, RID p_texture) override {} - void light_set_use_shadow(RID p_rid, bool p_enable) override {} - void light_update_shadow(RID p_rid, int p_shadow_index, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders) override {} - void light_update_directional_shadow(RID p_rid, int p_shadow_index, const Transform2D &p_light_xform, int p_light_mask, float p_cull_distance, const Rect2 &p_clip_rect, LightOccluderInstance *p_occluders) override {} - - void render_sdf(RID p_render_target, LightOccluderInstance *p_occluders) override {} - RID occluder_polygon_create() override { return RID(); } - void occluder_polygon_set_shape(RID p_occluder, const Vector<Vector2> &p_points, bool p_closed) override {} - void occluder_polygon_set_cull_mode(RID p_occluder, RS::CanvasOccluderPolygonCullMode p_mode) override {} - void set_shadow_texture_size(int p_size) override {} - - void draw_window_margins(int *p_margins, RID *p_margin_textures) override {} - - bool free(RID p_rid) override { return true; } - void update() override {} - - StubsCanvas() {} - ~StubsCanvas() {} -}; - - -*/ diff --git a/drivers/gles_common/rasterizer_version.h b/drivers/gles_common/rasterizer_version.h deleted file mode 100644 index 25e76f0907..0000000000 --- a/drivers/gles_common/rasterizer_version.h +++ /dev/null @@ -1,84 +0,0 @@ -/*************************************************************************/ -/* rasterizer_version.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 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 */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#pragma once - -//#define GLES_OVER_GL - -//#define GODOT_3 -#define GODOT_4 - -#ifdef GODOT_4 -// visual server becomes rendering server -#define GD_VS RS - -#define GD_RD RenderingDevice - -//#define GD_COMMAND_LINE CommandPrimitive -#else - -//class ContextGL_Windows { -// HDC hDC; -// HGLRC hRC; -// unsigned int pixel_format; -// HWND hWnd; -// bool opengl_3_context; -// bool use_vsync; -#define GD_VS VS - -// no rendering device in 3.2? -#define GD_RD VS - -//public: -// void release_current(); - -// void make_current(); - -// int get_window_width(); -// int get_window_height(); -// void swap_buffers(); - -// Error initialize(); - -// void set_use_vsync(bool p_use); -// bool is_using_vsync() const; - -// ContextGL_Windows(HWND hwnd, bool p_opengl_3_context); -// ~ContextGL_Windows(); -//}; - -//#endif -//#define GD_COMMAND_LINE CommandLine - -#define GD_TYPE_LINE TYPE_LINE -#define GD_TYPE_POLYLINE TYPE_POLYLINE -#define GD_TYPE_POLYGON TYPE_POLYGON -#define GD_TYPE_CIRCLE TYPE_CIRCLE -#endif diff --git a/drivers/gles2/SCsub b/drivers/opengl/SCsub index 987ddcd16e..987ddcd16e 100644 --- a/drivers/gles2/SCsub +++ b/drivers/opengl/SCsub diff --git a/drivers/gles_common/rasterizer_array.h b/drivers/opengl/rasterizer_array.h index d1b616162f..aeadee56bf 100644 --- a/drivers/gles_common/rasterizer_array.h +++ b/drivers/opengl/rasterizer_array.h @@ -36,29 +36,24 @@ * For use in render drivers, not for general use. * TO BE REPLACED by local_vector. */ -#include "rasterizer_version.h" #include "core/os/memory.h" #include <string.h> -#ifdef GODOT_4 #include "core/templates/local_vector.h" #include "core/templates/vector.h" -#else -#include "core/vector.h" -#endif // very simple non-growable array, that keeps track of the size of a 'unit' // which can be cast to whatever vertex format FVF required, and is initially // created with enough memory to hold the biggest FVF. // This allows multiple FVFs to use the same array. -class RasterizerUnitArrayGLES2 { +class RasterizerUnitArrayOpenGL { public: - RasterizerUnitArrayGLES2() { + RasterizerUnitArrayOpenGL() { _list = nullptr; free(); } - ~RasterizerUnitArrayGLES2() { free(); } + ~RasterizerUnitArrayOpenGL() { free(); } uint8_t *get_unit(unsigned int ui) { return &_list[ui * _unit_size_bytes]; } const uint8_t *get_unit(unsigned int ui) const { return &_list[ui * _unit_size_bytes]; } diff --git a/drivers/gles_common/rasterizer_asserts.h b/drivers/opengl/rasterizer_asserts.h index dbc45035b2..dbc45035b2 100644 --- a/drivers/gles_common/rasterizer_asserts.h +++ b/drivers/opengl/rasterizer_asserts.h diff --git a/drivers/gles2/rasterizer_canvas_base_gles2.cpp b/drivers/opengl/rasterizer_canvas_base_opengl.cpp index 44eeede757..9b586f296d 100644 --- a/drivers/gles2/rasterizer_canvas_base_gles2.cpp +++ b/drivers/opengl/rasterizer_canvas_base_opengl.cpp @@ -1,12 +1,12 @@ /*************************************************************************/ -/* rasterizer_canvas_base_gles2.cpp */ +/* rasterizer_canvas_base_opengl.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 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 */ @@ -28,36 +28,70 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "rasterizer_canvas_base_gles2.h" -#ifdef GLES2_BACKEND_ENABLED +#include "rasterizer_canvas_base_opengl.h" +#ifdef OPENGL_BACKEND_ENABLED #include "core/os/os.h" -#include "drivers/gles_common/rasterizer_asserts.h" -#include "rasterizer_scene_gles2.h" +#include "drivers/opengl/rasterizer_asserts.h" +#include "rasterizer_scene_opengl.h" -#ifdef GODOT_3 -#include "core/project_settings.h" -#include "servers/visual/visual_server_raster.h" -#else #include "core/config/project_settings.h" #include "servers/rendering/rendering_server_default.h" -#endif #ifndef GLES_OVER_GL #define glClearDepth glClearDepthf #endif -RID RasterizerCanvasBaseGLES2::light_internal_create() { +RID RasterizerCanvasBaseOpenGL::light_internal_create() { + return RID(); +} + +void RasterizerCanvasBaseOpenGL::light_internal_update(RID p_rid, Light *p_light) { +} + +void RasterizerCanvasBaseOpenGL::light_internal_free(RID p_rid) { +} + +RID RasterizerCanvasBaseOpenGL::light_create() { + return RID(); +} + +void RasterizerCanvasBaseOpenGL::light_set_texture(RID p_rid, RID p_texture) { +} + +void RasterizerCanvasBaseOpenGL::light_set_use_shadow(RID p_rid, bool p_enable) { +} + +void RasterizerCanvasBaseOpenGL::light_update_shadow(RID p_rid, int p_shadow_index, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders) { +} + +void RasterizerCanvasBaseOpenGL::light_update_directional_shadow(RID p_rid, int p_shadow_index, const Transform2D &p_light_xform, int p_light_mask, float p_cull_distance, const Rect2 &p_clip_rect, LightOccluderInstance *p_occluders) { +} + +void RasterizerCanvasBaseOpenGL::render_sdf(RID p_render_target, LightOccluderInstance *p_occluders) { +} + +RID RasterizerCanvasBaseOpenGL::occluder_polygon_create() { return RID(); } -void RasterizerCanvasBaseGLES2::light_internal_update(RID p_rid, Light *p_light) { +void RasterizerCanvasBaseOpenGL::occluder_polygon_set_shape(RID p_occluder, const Vector<Vector2> &p_points, bool p_closed) { } -void RasterizerCanvasBaseGLES2::light_internal_free(RID p_rid) { +void RasterizerCanvasBaseOpenGL::occluder_polygon_set_cull_mode(RID p_occluder, RS::CanvasOccluderPolygonCullMode p_mode) { } -void RasterizerCanvasBaseGLES2::canvas_begin() { +void RasterizerCanvasBaseOpenGL::set_shadow_texture_size(int p_size) { +} + +bool RasterizerCanvasBaseOpenGL::free(RID p_rid) { + return true; +} + +void RasterizerCanvasBaseOpenGL::update() { +} + +void RasterizerCanvasBaseOpenGL::canvas_begin() { state.using_transparent_rt = false; // always start with light_angle unset @@ -65,9 +99,9 @@ void RasterizerCanvasBaseGLES2::canvas_begin() { state.using_large_vertex = false; state.using_modulate = false; - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_ATTRIB_LIGHT_ANGLE, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_ATTRIB_MODULATE, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_ATTRIB_LARGE_VERTEX, false); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_ATTRIB_LIGHT_ANGLE, false); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_ATTRIB_MODULATE, false); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_ATTRIB_LARGE_VERTEX, false); state.canvas_shader.bind(); int viewport_x, viewport_y, viewport_width, viewport_height; @@ -135,8 +169,8 @@ void RasterizerCanvasBaseGLES2::canvas_begin() { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex); - glVertexAttrib4f(GD_VS::ARRAY_COLOR, 1, 1, 1, 1); - glDisableVertexAttribArray(GD_VS::ARRAY_COLOR); + glVertexAttrib4f(RS::ARRAY_COLOR, 1, 1, 1, 1); + glDisableVertexAttribArray(RS::ARRAY_COLOR); // set up default uniforms @@ -172,10 +206,10 @@ void RasterizerCanvasBaseGLES2::canvas_begin() { _bind_quad_buffer(); } -void RasterizerCanvasBaseGLES2::canvas_end() { +void RasterizerCanvasBaseOpenGL::canvas_end() { glBindBuffer(GL_ARRAY_BUFFER, 0); - for (int i = 0; i < GD_VS::ARRAY_MAX; i++) { + for (int i = 0; i < RS::ARRAY_MAX; i++) { glDisableVertexAttribArray(i); } @@ -195,38 +229,38 @@ void RasterizerCanvasBaseGLES2::canvas_end() { state.using_transparent_rt = false; } -void RasterizerCanvasBaseGLES2::draw_generic_textured_rect(const Rect2 &p_rect, const Rect2 &p_src) { - state.canvas_shader.set_uniform(CanvasShaderGLES2::DST_RECT, Color(p_rect.position.x, p_rect.position.y, p_rect.size.x, p_rect.size.y)); - state.canvas_shader.set_uniform(CanvasShaderGLES2::SRC_RECT, Color(p_src.position.x, p_src.position.y, p_src.size.x, p_src.size.y)); +void RasterizerCanvasBaseOpenGL::draw_generic_textured_rect(const Rect2 &p_rect, const Rect2 &p_src) { + state.canvas_shader.set_uniform(CanvasShaderOpenGL::DST_RECT, Color(p_rect.position.x, p_rect.position.y, p_rect.size.x, p_rect.size.y)); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::SRC_RECT, Color(p_src.position.x, p_src.position.y, p_src.size.x, p_src.size.y)); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } -void RasterizerCanvasBaseGLES2::_set_texture_rect_mode(bool p_texture_rect, bool p_light_angle, bool p_modulate, bool p_large_vertex) { +void RasterizerCanvasBaseOpenGL::_set_texture_rect_mode(bool p_texture_rect, bool p_light_angle, bool p_modulate, bool p_large_vertex) { // always set this directly (this could be state checked) - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_TEXTURE_RECT, p_texture_rect); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_TEXTURE_RECT, p_texture_rect); if (state.using_light_angle != p_light_angle) { state.using_light_angle = p_light_angle; - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_ATTRIB_LIGHT_ANGLE, p_light_angle); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_ATTRIB_LIGHT_ANGLE, p_light_angle); } if (state.using_modulate != p_modulate) { state.using_modulate = p_modulate; - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_ATTRIB_MODULATE, p_modulate); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_ATTRIB_MODULATE, p_modulate); } if (state.using_large_vertex != p_large_vertex) { state.using_large_vertex = p_large_vertex; - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_ATTRIB_LARGE_VERTEX, p_large_vertex); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_ATTRIB_LARGE_VERTEX, p_large_vertex); } } -RasterizerStorageGLES2::Texture *RasterizerCanvasBaseGLES2::_bind_canvas_texture(const RID &p_texture, const RID &p_normal_map) { - RasterizerStorageGLES2::Texture *tex_return = NULL; +RasterizerStorageOpenGL::Texture *RasterizerCanvasBaseOpenGL::_bind_canvas_texture(const RID &p_texture, const RID &p_normal_map) { + RasterizerStorageOpenGL::Texture *tex_return = NULL; if (p_texture.is_valid()) { - RasterizerStorageGLES2::Texture *texture = storage->texture_owner.getornull(p_texture); + RasterizerStorageOpenGL::Texture *texture = storage->texture_owner.get_or_null(p_texture); if (!texture) { state.current_tex = RID(); @@ -268,16 +302,16 @@ RasterizerStorageGLES2::Texture *RasterizerCanvasBaseGLES2::_bind_canvas_texture if (p_normal_map == state.current_normal) { //do none - state.canvas_shader.set_uniform(CanvasShaderGLES2::USE_DEFAULT_NORMAL, state.current_normal.is_valid()); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::USE_DEFAULT_NORMAL, state.current_normal.is_valid()); } else if (p_normal_map.is_valid()) { - RasterizerStorageGLES2::Texture *normal_map = storage->texture_owner.getornull(p_normal_map); + RasterizerStorageOpenGL::Texture *normal_map = storage->texture_owner.get_or_null(p_normal_map); if (!normal_map) { state.current_normal = RID(); glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 2); glBindTexture(GL_TEXTURE_2D, storage->resources.normal_tex); - state.canvas_shader.set_uniform(CanvasShaderGLES2::USE_DEFAULT_NORMAL, false); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::USE_DEFAULT_NORMAL, false); } else { if (normal_map->redraw_if_visible) { //check before proxy, because this is usually used with proxies @@ -289,21 +323,21 @@ RasterizerStorageGLES2::Texture *RasterizerCanvasBaseGLES2::_bind_canvas_texture glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 2); glBindTexture(GL_TEXTURE_2D, normal_map->tex_id); state.current_normal = p_normal_map; - state.canvas_shader.set_uniform(CanvasShaderGLES2::USE_DEFAULT_NORMAL, true); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::USE_DEFAULT_NORMAL, true); } } else { state.current_normal = RID(); glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 2); glBindTexture(GL_TEXTURE_2D, storage->resources.normal_tex); - state.canvas_shader.set_uniform(CanvasShaderGLES2::USE_DEFAULT_NORMAL, false); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::USE_DEFAULT_NORMAL, false); } return tex_return; } /* -void RasterizerCanvasBaseGLES2::draw_window_margins(int *black_margin, RID *black_image) { +void RasterizerCanvasBaseOpenGL::draw_window_margins(int *black_margin, RID *black_image) { return; // FTODO @@ -375,74 +409,74 @@ void RasterizerCanvasBaseGLES2::draw_window_margins(int *black_margin, RID *blac } */ -void RasterizerCanvasBaseGLES2::_bind_quad_buffer() { +void RasterizerCanvasBaseOpenGL::_bind_quad_buffer() { glBindBuffer(GL_ARRAY_BUFFER, data.canvas_quad_vertices); - glEnableVertexAttribArray(GD_VS::ARRAY_VERTEX); - glVertexAttribPointer(GD_VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, 0, NULL); + glEnableVertexAttribArray(RS::ARRAY_VERTEX); + glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, 0, NULL); } -void RasterizerCanvasBaseGLES2::_set_uniforms() { - state.canvas_shader.set_uniform(CanvasShaderGLES2::PROJECTION_MATRIX, state.uniforms.projection_matrix); - state.canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX, state.uniforms.modelview_matrix); - state.canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX, state.uniforms.extra_matrix); +void RasterizerCanvasBaseOpenGL::_set_uniforms() { + state.canvas_shader.set_uniform(CanvasShaderOpenGL::PROJECTION_MATRIX, state.uniforms.projection_matrix); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::MODELVIEW_MATRIX, state.uniforms.modelview_matrix); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::EXTRA_MATRIX, state.uniforms.extra_matrix); - state.canvas_shader.set_uniform(CanvasShaderGLES2::FINAL_MODULATE, state.uniforms.final_modulate); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::FINAL_MODULATE, state.uniforms.final_modulate); - state.canvas_shader.set_uniform(CanvasShaderGLES2::TIME, storage->frame.time[0]); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::TIME, storage->frame.time[0]); if (storage->frame.current_rt) { Vector2 screen_pixel_size; screen_pixel_size.x = 1.0 / storage->frame.current_rt->width; screen_pixel_size.y = 1.0 / storage->frame.current_rt->height; - state.canvas_shader.set_uniform(CanvasShaderGLES2::SCREEN_PIXEL_SIZE, screen_pixel_size); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::SCREEN_PIXEL_SIZE, screen_pixel_size); } if (state.using_skeleton) { - state.canvas_shader.set_uniform(CanvasShaderGLES2::SKELETON_TRANSFORM, state.skeleton_transform); - state.canvas_shader.set_uniform(CanvasShaderGLES2::SKELETON_TRANSFORM_INVERSE, state.skeleton_transform_inverse); - state.canvas_shader.set_uniform(CanvasShaderGLES2::SKELETON_TEXTURE_SIZE, state.skeleton_texture_size); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::SKELETON_TRANSFORM, state.skeleton_transform); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::SKELETON_TRANSFORM_INVERSE, state.skeleton_transform_inverse); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::SKELETON_TEXTURE_SIZE, state.skeleton_texture_size); } if (state.using_light) { Light *light = state.using_light; - state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_MATRIX, light->light_shader_xform); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::LIGHT_MATRIX, light->light_shader_xform); Transform2D basis_inverse = light->light_shader_xform.affine_inverse().orthonormalized(); basis_inverse.elements[2] = Vector2(); - state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_MATRIX_INVERSE, basis_inverse); - state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_LOCAL_MATRIX, light->xform_cache.affine_inverse()); - state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_COLOR, light->color * light->energy); - // state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_POS, light->light_shader_pos); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::LIGHT_MATRIX_INVERSE, basis_inverse); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::LIGHT_LOCAL_MATRIX, light->xform_cache.affine_inverse()); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::LIGHT_COLOR, light->color * light->energy); + // state.canvas_shader.set_uniform(CanvasShaderOpenGL::LIGHT_POS, light->light_shader_pos); // FTODO - state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_POS, light->light_shader_xform.elements[2]); - state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_HEIGHT, light->height); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::LIGHT_POS, light->light_shader_xform.elements[2]); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::LIGHT_HEIGHT, light->height); // FTODO - //state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_OUTSIDE_ALPHA, light->mode == GD_VS::CANVAS_LIGHT_MODE_MASK ? 1.0 : 0.0); - state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_OUTSIDE_ALPHA, 0.0f); + //state.canvas_shader.set_uniform(CanvasShaderOpenGL::LIGHT_OUTSIDE_ALPHA, light->mode == RS::CANVAS_LIGHT_MODE_MASK ? 1.0 : 0.0); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::LIGHT_OUTSIDE_ALPHA, 0.0f); if (state.using_shadow) { // FTODO #if 0 - RasterizerStorageGLES2::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(light->shadow_buffer); + RasterizerStorageOpenGL::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(light->shadow_buffer); glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 5); glBindTexture(GL_TEXTURE_2D, cls->distance); - state.canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_MATRIX, light->shadow_matrix_cache); - state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_SHADOW_COLOR, light->shadow_color); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::SHADOW_MATRIX, light->shadow_matrix_cache); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::LIGHT_SHADOW_COLOR, light->shadow_color); - state.canvas_shader.set_uniform(CanvasShaderGLES2::SHADOWPIXEL_SIZE, (1.0 / light->shadow_buffer_size) * (1.0 + light->shadow_smooth)); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::SHADOWPIXEL_SIZE, (1.0 / light->shadow_buffer_size) * (1.0 + light->shadow_smooth)); if (light->radius_cache == 0) { - state.canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_GRADIENT, 0.0); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::SHADOW_GRADIENT, 0.0); } else { - state.canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_GRADIENT, light->shadow_gradient_length / (light->radius_cache * 1.1)); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::SHADOW_GRADIENT, light->shadow_gradient_length / (light->radius_cache * 1.1)); } - state.canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_DISTANCE_MULT, light->radius_cache * 1.1); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::SHADOW_DISTANCE_MULT, light->radius_cache * 1.1); #endif } } } -void RasterizerCanvasBaseGLES2::reset_canvas() { +void RasterizerCanvasBaseOpenGL::reset_canvas() { glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glDisable(GL_SCISSOR_TEST); @@ -456,7 +490,7 @@ void RasterizerCanvasBaseGLES2::reset_canvas() { } // bind the back buffer to a texture so shaders can use it. - // It should probably use texture unit -3 (as GLES2 does as well) but currently that's buggy. + // It should probably use texture unit -3 (as OpenGL does as well) but currently that's buggy. // keeping this for now as there's nothing else that uses texture unit 2 // TODO ^ if (storage->frame.current_rt) { @@ -468,10 +502,10 @@ void RasterizerCanvasBaseGLES2::reset_canvas() { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } -void RasterizerCanvasBaseGLES2::canvas_debug_viewport_shadows(Light *p_lights_with_shadow) { +void RasterizerCanvasBaseOpenGL::canvas_debug_viewport_shadows(Light *p_lights_with_shadow) { } -void RasterizerCanvasBaseGLES2::_copy_texscreen(const Rect2 &p_rect) { +void RasterizerCanvasBaseOpenGL::_copy_texscreen(const Rect2 &p_rect) { state.canvas_texscreen_used = true; _copy_screen(p_rect); @@ -483,7 +517,7 @@ void RasterizerCanvasBaseGLES2::_copy_texscreen(const Rect2 &p_rect) { _set_uniforms(); } -void RasterizerCanvasBaseGLES2::_draw_polygon(const int *p_indices, int p_index_count, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor, const float *p_weights, const int *p_bones) { +void RasterizerCanvasBaseOpenGL::_draw_polygon(const int *p_indices, int p_index_count, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor, const float *p_weights, const int *p_bones) { glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer); uint32_t buffer_ofs = 0; @@ -494,47 +528,47 @@ void RasterizerCanvasBaseGLES2::_draw_polygon(const int *p_indices, int p_index_ storage->buffer_orphan_and_upload(data.polygon_buffer_size, 0, sizeof(Vector2) * p_vertex_count, p_vertices, GL_ARRAY_BUFFER, _buffer_upload_usage_flag, true); - glEnableVertexAttribArray(GD_VS::ARRAY_VERTEX); - glVertexAttribPointer(GD_VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), NULL); + glEnableVertexAttribArray(RS::ARRAY_VERTEX); + glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), NULL); buffer_ofs = buffer_ofs_after; if (p_singlecolor) { - glDisableVertexAttribArray(GD_VS::ARRAY_COLOR); + glDisableVertexAttribArray(RS::ARRAY_COLOR); Color m = *p_colors; - glVertexAttrib4f(GD_VS::ARRAY_COLOR, m.r, m.g, m.b, m.a); + glVertexAttrib4f(RS::ARRAY_COLOR, m.r, m.g, m.b, m.a); } else if (!p_colors) { - glDisableVertexAttribArray(GD_VS::ARRAY_COLOR); - glVertexAttrib4f(GD_VS::ARRAY_COLOR, 1, 1, 1, 1); + glDisableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttrib4f(RS::ARRAY_COLOR, 1, 1, 1, 1); } else { RAST_FAIL_COND(!storage->safe_buffer_sub_data(data.polygon_buffer_size, GL_ARRAY_BUFFER, buffer_ofs, sizeof(Color) * p_vertex_count, p_colors, buffer_ofs_after)); - glEnableVertexAttribArray(GD_VS::ARRAY_COLOR); - glVertexAttribPointer(GD_VS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); + glEnableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttribPointer(RS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); buffer_ofs = buffer_ofs_after; } if (p_uvs) { RAST_FAIL_COND(!storage->safe_buffer_sub_data(data.polygon_buffer_size, GL_ARRAY_BUFFER, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_uvs, buffer_ofs_after)); - glEnableVertexAttribArray(GD_VS::ARRAY_TEX_UV); - glVertexAttribPointer(GD_VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); + glEnableVertexAttribArray(RS::ARRAY_TEX_UV); + glVertexAttribPointer(RS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); buffer_ofs = buffer_ofs_after; } else { - glDisableVertexAttribArray(GD_VS::ARRAY_TEX_UV); + glDisableVertexAttribArray(RS::ARRAY_TEX_UV); } if (p_weights && p_bones) { RAST_FAIL_COND(!storage->safe_buffer_sub_data(data.polygon_buffer_size, GL_ARRAY_BUFFER, buffer_ofs, sizeof(float) * 4 * p_vertex_count, p_weights, buffer_ofs_after)); - glEnableVertexAttribArray(GD_VS::ARRAY_WEIGHTS); - glVertexAttribPointer(GD_VS::ARRAY_WEIGHTS, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 4, CAST_INT_TO_UCHAR_PTR(buffer_ofs)); + glEnableVertexAttribArray(RS::ARRAY_WEIGHTS); + glVertexAttribPointer(RS::ARRAY_WEIGHTS, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 4, CAST_INT_TO_UCHAR_PTR(buffer_ofs)); buffer_ofs = buffer_ofs_after; RAST_FAIL_COND(!storage->safe_buffer_sub_data(data.polygon_buffer_size, GL_ARRAY_BUFFER, buffer_ofs, sizeof(int) * 4 * p_vertex_count, p_bones, buffer_ofs_after)); - glEnableVertexAttribArray(GD_VS::ARRAY_BONES); - glVertexAttribPointer(GD_VS::ARRAY_BONES, 4, GL_UNSIGNED_INT, GL_FALSE, sizeof(int) * 4, CAST_INT_TO_UCHAR_PTR(buffer_ofs)); + glEnableVertexAttribArray(RS::ARRAY_BONES); + glVertexAttribPointer(RS::ARRAY_BONES, 4, GL_UNSIGNED_INT, GL_FALSE, sizeof(int) * 4, CAST_INT_TO_UCHAR_PTR(buffer_ofs)); buffer_ofs = buffer_ofs_after; } else { - glDisableVertexAttribArray(GD_VS::ARRAY_WEIGHTS); - glDisableVertexAttribArray(GD_VS::ARRAY_BONES); + glDisableVertexAttribArray(RS::ARRAY_WEIGHTS); + glDisableVertexAttribArray(RS::ARRAY_BONES); } glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.polygon_index_buffer); @@ -564,7 +598,7 @@ void RasterizerCanvasBaseGLES2::_draw_polygon(const int *p_indices, int p_index_ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } -void RasterizerCanvasBaseGLES2::_draw_generic(GLuint p_primitive, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor) { +void RasterizerCanvasBaseOpenGL::_draw_generic(GLuint p_primitive, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor) { glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer); uint32_t buffer_ofs = 0; @@ -574,31 +608,31 @@ void RasterizerCanvasBaseGLES2::_draw_generic(GLuint p_primitive, int p_vertex_c #endif storage->buffer_orphan_and_upload(data.polygon_buffer_size, 0, sizeof(Vector2) * p_vertex_count, p_vertices, GL_ARRAY_BUFFER, _buffer_upload_usage_flag, true); - glEnableVertexAttribArray(GD_VS::ARRAY_VERTEX); - glVertexAttribPointer(GD_VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), NULL); + glEnableVertexAttribArray(RS::ARRAY_VERTEX); + glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), NULL); buffer_ofs = buffer_ofs_after; if (p_singlecolor) { - glDisableVertexAttribArray(GD_VS::ARRAY_COLOR); + glDisableVertexAttribArray(RS::ARRAY_COLOR); Color m = *p_colors; - glVertexAttrib4f(GD_VS::ARRAY_COLOR, m.r, m.g, m.b, m.a); + glVertexAttrib4f(RS::ARRAY_COLOR, m.r, m.g, m.b, m.a); } else if (!p_colors) { - glDisableVertexAttribArray(GD_VS::ARRAY_COLOR); - glVertexAttrib4f(GD_VS::ARRAY_COLOR, 1, 1, 1, 1); + glDisableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttrib4f(RS::ARRAY_COLOR, 1, 1, 1, 1); } else { RAST_FAIL_COND(!storage->safe_buffer_sub_data(data.polygon_buffer_size, GL_ARRAY_BUFFER, buffer_ofs, sizeof(Color) * p_vertex_count, p_colors, buffer_ofs_after)); - glEnableVertexAttribArray(GD_VS::ARRAY_COLOR); - glVertexAttribPointer(GD_VS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); + glEnableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttribPointer(RS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); buffer_ofs = buffer_ofs_after; } if (p_uvs) { RAST_FAIL_COND(!storage->safe_buffer_sub_data(data.polygon_buffer_size, GL_ARRAY_BUFFER, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_uvs, buffer_ofs_after)); - glEnableVertexAttribArray(GD_VS::ARRAY_TEX_UV); - glVertexAttribPointer(GD_VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); + glEnableVertexAttribArray(RS::ARRAY_TEX_UV); + glVertexAttribPointer(RS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); buffer_ofs = buffer_ofs_after; } else { - glDisableVertexAttribArray(GD_VS::ARRAY_TEX_UV); + glDisableVertexAttribArray(RS::ARRAY_TEX_UV); } glDrawArrays(p_primitive, 0, p_vertex_count); @@ -607,7 +641,7 @@ void RasterizerCanvasBaseGLES2::_draw_generic(GLuint p_primitive, int p_vertex_c glBindBuffer(GL_ARRAY_BUFFER, 0); } -void RasterizerCanvasBaseGLES2::_draw_generic_indices(GLuint p_primitive, const int *p_indices, int p_index_count, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor) { +void RasterizerCanvasBaseOpenGL::_draw_generic_indices(GLuint p_primitive, const int *p_indices, int p_index_count, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor) { glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer); uint32_t buffer_ofs = 0; @@ -617,31 +651,31 @@ void RasterizerCanvasBaseGLES2::_draw_generic_indices(GLuint p_primitive, const #endif storage->buffer_orphan_and_upload(data.polygon_buffer_size, 0, sizeof(Vector2) * p_vertex_count, p_vertices, GL_ARRAY_BUFFER, _buffer_upload_usage_flag, true); - glEnableVertexAttribArray(GD_VS::ARRAY_VERTEX); - glVertexAttribPointer(GD_VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), NULL); + glEnableVertexAttribArray(RS::ARRAY_VERTEX); + glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), NULL); buffer_ofs = buffer_ofs_after; if (p_singlecolor) { - glDisableVertexAttribArray(GD_VS::ARRAY_COLOR); + glDisableVertexAttribArray(RS::ARRAY_COLOR); Color m = *p_colors; - glVertexAttrib4f(GD_VS::ARRAY_COLOR, m.r, m.g, m.b, m.a); + glVertexAttrib4f(RS::ARRAY_COLOR, m.r, m.g, m.b, m.a); } else if (!p_colors) { - glDisableVertexAttribArray(GD_VS::ARRAY_COLOR); - glVertexAttrib4f(GD_VS::ARRAY_COLOR, 1, 1, 1, 1); + glDisableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttrib4f(RS::ARRAY_COLOR, 1, 1, 1, 1); } else { RAST_FAIL_COND(!storage->safe_buffer_sub_data(data.polygon_buffer_size, GL_ARRAY_BUFFER, buffer_ofs, sizeof(Color) * p_vertex_count, p_colors, buffer_ofs_after)); - glEnableVertexAttribArray(GD_VS::ARRAY_COLOR); - glVertexAttribPointer(GD_VS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); + glEnableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttribPointer(RS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(Color), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); buffer_ofs = buffer_ofs_after; } if (p_uvs) { RAST_FAIL_COND(!storage->safe_buffer_sub_data(data.polygon_buffer_size, GL_ARRAY_BUFFER, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_uvs, buffer_ofs_after)); - glEnableVertexAttribArray(GD_VS::ARRAY_TEX_UV); - glVertexAttribPointer(GD_VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); + glEnableVertexAttribArray(RS::ARRAY_TEX_UV); + glVertexAttribPointer(RS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), CAST_INT_TO_UCHAR_PTR(buffer_ofs)); buffer_ofs = buffer_ofs_after; } else { - glDisableVertexAttribArray(GD_VS::ARRAY_TEX_UV); + glDisableVertexAttribArray(RS::ARRAY_TEX_UV); } #ifdef RASTERIZER_EXTRA_CHECKS @@ -677,7 +711,7 @@ void RasterizerCanvasBaseGLES2::_draw_generic_indices(GLuint p_primitive, const glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } -void RasterizerCanvasBaseGLES2::_legacy_draw_poly_triangles(Item::CommandPolygon *p_poly, RasterizerStorageGLES2::Material *p_material) { +void RasterizerCanvasBaseOpenGL::_legacy_draw_poly_triangles(Item::CommandPolygon *p_poly, RasterizerStorageOpenGL::Material *p_material) { // return; const PolyData &pd = _polydata[p_poly->polygon.polygon_id]; @@ -690,12 +724,12 @@ void RasterizerCanvasBaseGLES2::_legacy_draw_poly_triangles(Item::CommandPolygon } // FTODO - //RasterizerStorageGLES2::Texture *texture = _bind_canvas_texture(polygon->texture, polygon->normal_map); - RasterizerStorageGLES2::Texture *texture = _bind_canvas_texture(p_poly->texture, RID()); + //RasterizerStorageOpenGL::Texture *texture = _bind_canvas_texture(polygon->texture, polygon->normal_map); + RasterizerStorageOpenGL::Texture *texture = _bind_canvas_texture(p_poly->texture, RID()); if (texture) { Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height); - state.canvas_shader.set_uniform(CanvasShaderGLES2::COLOR_TEXPIXEL_SIZE, texpixel_size); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::COLOR_TEXPIXEL_SIZE, texpixel_size); } _draw_polygon(pd.indices.ptr(), pd.indices.size(), pd.points.size(), pd.points.ptr(), pd.uvs.ptr(), pd.colors.ptr(), pd.colors.size() == 1, nullptr, nullptr); @@ -716,7 +750,7 @@ void RasterizerCanvasBaseGLES2::_legacy_draw_poly_triangles(Item::CommandPolygon #endif } -void RasterizerCanvasBaseGLES2::_legacy_draw_primitive(Item::CommandPrimitive *p_pr, RasterizerStorageGLES2::Material *p_material) { +void RasterizerCanvasBaseOpenGL::_legacy_draw_primitive(Item::CommandPrimitive *p_pr, RasterizerStorageOpenGL::Material *p_material) { // return; if (p_pr->point_count != 4) @@ -731,15 +765,15 @@ void RasterizerCanvasBaseGLES2::_legacy_draw_primitive(Item::CommandPrimitive *p _bind_canvas_texture(RID(), RID()); - glDisableVertexAttribArray(GD_VS::ARRAY_COLOR); - glVertexAttrib4fv(GD_VS::ARRAY_COLOR, p_pr->colors[0].components); + glDisableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttrib4fv(RS::ARRAY_COLOR, p_pr->colors[0].components); - state.canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX, state.uniforms.modelview_matrix); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::MODELVIEW_MATRIX, state.uniforms.modelview_matrix); _draw_gui_primitive(p_pr->point_count, p_pr->points, NULL, NULL); } -void RasterizerCanvasBaseGLES2::_legacy_draw_line(Item::CommandPrimitive *p_pr, RasterizerStorageGLES2::Material *p_material) { +void RasterizerCanvasBaseOpenGL::_legacy_draw_line(Item::CommandPrimitive *p_pr, RasterizerStorageOpenGL::Material *p_material) { _set_texture_rect_mode(false); if (state.canvas_shader.bind()) { @@ -749,10 +783,10 @@ void RasterizerCanvasBaseGLES2::_legacy_draw_line(Item::CommandPrimitive *p_pr, _bind_canvas_texture(RID(), RID()); - glDisableVertexAttribArray(GD_VS::ARRAY_COLOR); - glVertexAttrib4fv(GD_VS::ARRAY_COLOR, p_pr->colors[0].components); + glDisableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttrib4fv(RS::ARRAY_COLOR, p_pr->colors[0].components); - state.canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX, state.uniforms.modelview_matrix); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::MODELVIEW_MATRIX, state.uniforms.modelview_matrix); #ifdef GLES_OVER_GL // if (line->antialiased) @@ -766,7 +800,7 @@ void RasterizerCanvasBaseGLES2::_legacy_draw_line(Item::CommandPrimitive *p_pr, #endif } -void RasterizerCanvasBaseGLES2::_draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color *p_colors, const Vector2 *p_uvs, const float *p_light_angles) { +void RasterizerCanvasBaseOpenGL::_draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color *p_colors, const Vector2 *p_uvs, const float *p_light_angles) { static const GLenum prim[5] = { GL_POINTS, GL_POINTS, GL_LINES, GL_TRIANGLES, GL_TRIANGLE_FAN }; int color_offset = 0; @@ -822,21 +856,21 @@ void RasterizerCanvasBaseGLES2::_draw_gui_primitive(int p_points, const Vector2 glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer); storage->buffer_orphan_and_upload(data.polygon_buffer_size, 0, p_points * stride * 4 * sizeof(float), buffer_data, GL_ARRAY_BUFFER, _buffer_upload_usage_flag, true); - glVertexAttribPointer(GD_VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, stride * sizeof(float), NULL); + glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, stride * sizeof(float), NULL); if (p_colors) { - glVertexAttribPointer(GD_VS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, stride * sizeof(float), CAST_INT_TO_UCHAR_PTR(color_offset * sizeof(float))); - glEnableVertexAttribArray(GD_VS::ARRAY_COLOR); + glVertexAttribPointer(RS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, stride * sizeof(float), CAST_INT_TO_UCHAR_PTR(color_offset * sizeof(float))); + glEnableVertexAttribArray(RS::ARRAY_COLOR); } if (p_uvs) { - glVertexAttribPointer(GD_VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, stride * sizeof(float), CAST_INT_TO_UCHAR_PTR(uv_offset * sizeof(float))); - glEnableVertexAttribArray(GD_VS::ARRAY_TEX_UV); + glVertexAttribPointer(RS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, stride * sizeof(float), CAST_INT_TO_UCHAR_PTR(uv_offset * sizeof(float))); + glEnableVertexAttribArray(RS::ARRAY_TEX_UV); } if (p_light_angles) { - glVertexAttribPointer(GD_VS::ARRAY_TANGENT, 1, GL_FLOAT, GL_FALSE, stride * sizeof(float), CAST_INT_TO_UCHAR_PTR(light_angle_offset * sizeof(float))); - glEnableVertexAttribArray(GD_VS::ARRAY_TANGENT); + glVertexAttribPointer(RS::ARRAY_TANGENT, 1, GL_FLOAT, GL_FALSE, stride * sizeof(float), CAST_INT_TO_UCHAR_PTR(light_angle_offset * sizeof(float))); + glEnableVertexAttribArray(RS::ARRAY_TANGENT); } glDrawArrays(prim[p_points], 0, p_points); @@ -844,13 +878,13 @@ void RasterizerCanvasBaseGLES2::_draw_gui_primitive(int p_points, const Vector2 if (p_light_angles) { // may not be needed - glDisableVertexAttribArray(GD_VS::ARRAY_TANGENT); + glDisableVertexAttribArray(RS::ARRAY_TANGENT); } glBindBuffer(GL_ARRAY_BUFFER, 0); } -void RasterizerCanvasBaseGLES2::_copy_screen(const Rect2 &p_rect) { +void RasterizerCanvasBaseOpenGL::_copy_screen(const Rect2 &p_rect) { if (storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_DIRECT_TO_SCREEN]) { ERR_PRINT_ONCE("Cannot use screen texture copying in render target set to render direct to screen."); return; @@ -865,17 +899,17 @@ void RasterizerCanvasBaseGLES2::_copy_screen(const Rect2 &p_rect) { Color copy_section(p_rect.position.x / wh.x, p_rect.position.y / wh.y, p_rect.size.x / wh.x, p_rect.size.y / wh.y); if (p_rect != Rect2()) { - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_COPY_SECTION, true); + storage->shaders.copy.set_conditional(CopyShaderOpenGL::USE_COPY_SECTION, true); } - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_NO_ALPHA, !state.using_transparent_rt); + storage->shaders.copy.set_conditional(CopyShaderOpenGL::USE_NO_ALPHA, !state.using_transparent_rt); storage->bind_framebuffer(storage->frame.current_rt->copy_screen_effect.fbo); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color); storage->shaders.copy.bind(); - storage->shaders.copy.set_uniform(CopyShaderGLES2::COPY_SECTION, copy_section); + storage->shaders.copy.set_uniform(CopyShaderOpenGL::COPY_SECTION, copy_section); const Vector2 vertpos[4] = { Vector2(-1, -1), @@ -898,16 +932,16 @@ void RasterizerCanvasBaseGLES2::_copy_screen(const Rect2 &p_rect) { _draw_polygon(indexpos, 6, 4, vertpos, uvpos, NULL, false); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_COPY_SECTION, false); - storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_NO_ALPHA, false); + storage->shaders.copy.set_conditional(CopyShaderOpenGL::USE_COPY_SECTION, false); + storage->shaders.copy.set_conditional(CopyShaderOpenGL::USE_NO_ALPHA, false); storage->bind_framebuffer(storage->frame.current_rt->fbo); glEnable(GL_BLEND); } -void RasterizerCanvasBaseGLES2::canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache) { +void RasterizerCanvasBaseOpenGL::canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache) { #if 0 - RasterizerStorageGLES2::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(p_buffer); + RasterizerStorageOpenGL::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(p_buffer); ERR_FAIL_COND(!cls); glDisable(GL_BLEND); @@ -920,7 +954,7 @@ void RasterizerCanvasBaseGLES2::canvas_light_shadow_buffer_update(RID p_buffer, glBindFramebuffer(GL_FRAMEBUFFER, cls->fbo); - state.canvas_shadow_shader.set_conditional(CanvasShadowShaderGLES2::USE_RGBA_SHADOWS, storage->config.use_rgba_2d_shadows); + state.canvas_shadow_shader.set_conditional(CanvasShadowShaderOpenGL::USE_RGBA_SHADOWS, storage->config.use_rgba_2d_shadows); state.canvas_shadow_shader.bind(); glViewport(0, 0, cls->size, cls->height); @@ -928,7 +962,7 @@ void RasterizerCanvasBaseGLES2::canvas_light_shadow_buffer_update(RID p_buffer, glClearColor(1, 1, 1, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - GD_VS::CanvasOccluderPolygonCullMode cull = GD_VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED; + RS::CanvasOccluderPolygonCullMode cull = RS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED; for (int i = 0; i < 4; i++) { //make sure it remains orthogonal, makes easy to read angle later @@ -962,9 +996,9 @@ void RasterizerCanvasBaseGLES2::canvas_light_shadow_buffer_update(RID p_buffer, Vector3 cam_target = Basis(Vector3(0, 0, Math_PI * 2 * (i / 4.0))).xform(Vector3(0, 1, 0)); projection = projection * CameraMatrix(Transform3D().looking_at(cam_target, Vector3(0, 0, -1)).affine_inverse()); - state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES2::PROJECTION_MATRIX, projection); - state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES2::LIGHT_MATRIX, light); - state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES2::DISTANCE_NORM, 1.0 / p_far); + state.canvas_shadow_shader.set_uniform(CanvasShadowShaderOpenGL::PROJECTION_MATRIX, projection); + state.canvas_shadow_shader.set_uniform(CanvasShadowShaderOpenGL::LIGHT_MATRIX, light); + state.canvas_shadow_shader.set_uniform(CanvasShadowShaderOpenGL::DISTANCE_NORM, 1.0 / p_far); if (i == 0) *p_xform_cache = projection; @@ -974,36 +1008,36 @@ void RasterizerCanvasBaseGLES2::canvas_light_shadow_buffer_update(RID p_buffer, LightOccluderInstance *instance = p_occluders; while (instance) { - RasterizerStorageGLES2::CanvasOccluder *cc = storage->canvas_occluder_owner.getornull(instance->polygon_buffer); + RasterizerStorageOpenGL::CanvasOccluder *cc = storage->canvas_occluder_owner.get_or_null(instance->polygon_buffer); if (!cc || cc->len == 0 || !(p_light_mask & instance->light_mask)) { instance = instance->next; continue; } - state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES2::WORLD_MATRIX, instance->xform_cache); + state.canvas_shadow_shader.set_uniform(CanvasShadowShaderOpenGL::WORLD_MATRIX, instance->xform_cache); - GD_VS::CanvasOccluderPolygonCullMode transformed_cull_cache = instance->cull_cache; + RS::CanvasOccluderPolygonCullMode transformed_cull_cache = instance->cull_cache; - if (transformed_cull_cache != GD_VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED && + if (transformed_cull_cache != RS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED && (p_light_xform.basis_determinant() * instance->xform_cache.basis_determinant()) < 0) { transformed_cull_cache = - transformed_cull_cache == GD_VS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE ? - GD_VS::CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE : - GD_VS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE; + transformed_cull_cache == RS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE ? + RS::CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE : + RS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE; } if (cull != transformed_cull_cache) { cull = transformed_cull_cache; switch (cull) { - case GD_VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED: { + case RS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED: { glDisable(GL_CULL_FACE); } break; - case GD_VS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE: { + case RS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE: { glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); } break; - case GD_VS::CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE: { + case RS::CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE: { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); @@ -1012,8 +1046,8 @@ void RasterizerCanvasBaseGLES2::canvas_light_shadow_buffer_update(RID p_buffer, } glBindBuffer(GL_ARRAY_BUFFER, cc->vertex_id); - glEnableVertexAttribArray(GD_VS::ARRAY_VERTEX); - glVertexAttribPointer(GD_VS::ARRAY_VERTEX, 3, GL_FLOAT, false, 0, 0); + glEnableVertexAttribArray(RS::ARRAY_VERTEX); + glVertexAttribPointer(RS::ARRAY_VERTEX, 3, GL_FLOAT, false, 0, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cc->index_id); glDrawElements(GL_TRIANGLES, cc->len * 3, GL_UNSIGNED_SHORT, 0); @@ -1027,7 +1061,7 @@ void RasterizerCanvasBaseGLES2::canvas_light_shadow_buffer_update(RID p_buffer, #endif } -void RasterizerCanvasBaseGLES2::draw_lens_distortion_rect(const Rect2 &p_rect, float p_k1, float p_k2, const Vector2 &p_eye_center, float p_oversample) { +void RasterizerCanvasBaseOpenGL::draw_lens_distortion_rect(const Rect2 &p_rect, float p_k1, float p_k2, const Vector2 &p_eye_center, float p_oversample) { Vector2 half_size; if (storage->frame.current_rt) { half_size = Vector2(storage->frame.current_rt->width, storage->frame.current_rt->height); @@ -1043,13 +1077,13 @@ void RasterizerCanvasBaseGLES2::draw_lens_distortion_rect(const Rect2 &p_rect, f // setup our lens shader state.lens_shader.bind(); - state.lens_shader.set_uniform(LensDistortedShaderGLES2::OFFSET, offset); - state.lens_shader.set_uniform(LensDistortedShaderGLES2::SCALE, scale); - state.lens_shader.set_uniform(LensDistortedShaderGLES2::K1, p_k1); - state.lens_shader.set_uniform(LensDistortedShaderGLES2::K2, p_k2); - state.lens_shader.set_uniform(LensDistortedShaderGLES2::EYE_CENTER, p_eye_center); - state.lens_shader.set_uniform(LensDistortedShaderGLES2::UPSCALE, p_oversample); - state.lens_shader.set_uniform(LensDistortedShaderGLES2::ASPECT_RATIO, aspect_ratio); + state.lens_shader.set_uniform(LensDistortedShaderOpenGL::OFFSET, offset); + state.lens_shader.set_uniform(LensDistortedShaderOpenGL::SCALE, scale); + state.lens_shader.set_uniform(LensDistortedShaderOpenGL::K1, p_k1); + state.lens_shader.set_uniform(LensDistortedShaderOpenGL::K2, p_k2); + state.lens_shader.set_uniform(LensDistortedShaderOpenGL::EYE_CENTER, p_eye_center); + state.lens_shader.set_uniform(LensDistortedShaderOpenGL::UPSCALE, p_oversample); + state.lens_shader.set_uniform(LensDistortedShaderOpenGL::ASPECT_RATIO, aspect_ratio); // bind our quad buffer _bind_quad_buffer(); @@ -1060,12 +1094,12 @@ void RasterizerCanvasBaseGLES2::draw_lens_distortion_rect(const Rect2 &p_rect, f // and cleanup glBindBuffer(GL_ARRAY_BUFFER, 0); - for (int i = 0; i < GD_VS::ARRAY_MAX; i++) { + for (int i = 0; i < RS::ARRAY_MAX; i++) { glDisableVertexAttribArray(i); } } -void RasterizerCanvasBaseGLES2::initialize() { +void RasterizerCanvasBaseOpenGL::initialize() { bool flag_stream = false; //flag_stream = GLOBAL_GET("rendering/options/api_usage_legacy/flag_stream"); if (flag_stream) @@ -1183,20 +1217,20 @@ void RasterizerCanvasBaseGLES2::initialize() { state.canvas_shader.init(); _set_texture_rect_mode(true); - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_RGBA_SHADOWS, storage->config.use_rgba_2d_shadows); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_RGBA_SHADOWS, storage->config.use_rgba_2d_shadows); state.canvas_shader.bind(); state.lens_shader.init(); - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_PIXEL_SNAP, GLOBAL_DEF("rendering/quality/2d/use_pixel_snap", false)); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_PIXEL_SNAP, GLOBAL_DEF("rendering/quality/2d/use_pixel_snap", false)); state.using_light = NULL; state.using_transparent_rt = false; state.using_skeleton = false; } -RendererCanvasRender::PolygonID RasterizerCanvasBaseGLES2::request_polygon(const Vector<int> &p_indices, const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, const Vector<int> &p_bones, const Vector<float> &p_weights) { +RendererCanvasRender::PolygonID RasterizerCanvasBaseOpenGL::request_polygon(const Vector<int> &p_indices, const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, const Vector<int> &p_bones, const Vector<float> &p_weights) { uint32_t id = _polydata.alloc(); PolyData &pd = _polydata[id]; pd.indices = p_indices; @@ -1205,14 +1239,14 @@ RendererCanvasRender::PolygonID RasterizerCanvasBaseGLES2::request_polygon(const pd.uvs = p_uvs; return id; } -void RasterizerCanvasBaseGLES2::free_polygon(PolygonID p_polygon) { +void RasterizerCanvasBaseOpenGL::free_polygon(PolygonID p_polygon) { _polydata.free(p_polygon); } -void RasterizerCanvasBaseGLES2::finalize() { +void RasterizerCanvasBaseOpenGL::finalize() { } -RasterizerCanvasBaseGLES2::RasterizerCanvasBaseGLES2() { +RasterizerCanvasBaseOpenGL::RasterizerCanvasBaseOpenGL() { } -#endif +#endif // OPENGL_BACKEND_ENABLED diff --git a/drivers/gles2/rasterizer_canvas_base_gles2.h b/drivers/opengl/rasterizer_canvas_base_opengl.h index e2b396dca8..ac2020e5d7 100644 --- a/drivers/gles2/rasterizer_canvas_base_gles2.h +++ b/drivers/opengl/rasterizer_canvas_base_opengl.h @@ -1,12 +1,12 @@ /*************************************************************************/ -/* rasterizer_canvas_base_gles2.h */ +/* rasterizer_canvas_base_opengl.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 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 */ @@ -28,24 +28,24 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#pragma once +#ifndef RASTERIZER_CANVAS_BASE_OPENGL_H +#define RASTERIZER_CANVAS_BASE_OPENGL_H -#include "drivers/gles_common/rasterizer_platforms.h" -#ifdef GLES2_BACKEND_ENABLED +#include "drivers/opengl/rasterizer_platforms.h" +#ifdef OPENGL_BACKEND_ENABLED -#include "drivers/gles_common/rasterizer_array.h" -#include "drivers/gles_common/rasterizer_common_stubs.h" -#include "drivers/gles_common/rasterizer_storage_common.h" -#include "drivers/gles_common/rasterizer_version.h" -#include "rasterizer_scene_gles2.h" -#include "rasterizer_storage_gles2.h" +#include "drivers/opengl/rasterizer_array.h" +#include "drivers/opengl/rasterizer_storage_common.h" +#include "rasterizer_scene_opengl.h" +#include "rasterizer_storage_opengl.h" +#include "servers/rendering/renderer_canvas_render.h" #include "servers/rendering/renderer_compositor.h" #include "shaders/canvas.glsl.gen.h" #include "shaders/canvas_shadow.glsl.gen.h" #include "shaders/lens_distorted.glsl.gen.h" -class RasterizerCanvasBaseGLES2 : public StubsCanvas { +class RasterizerCanvasBaseOpenGL : public RendererCanvasRender { public: enum { INSTANCE_ATTRIB_BASE = 8, @@ -77,9 +77,9 @@ public: struct State { Uniforms uniforms; bool canvas_texscreen_used; - CanvasShaderGLES2 canvas_shader; - CanvasShadowShaderGLES2 canvas_shadow_shader; - LensDistortedShaderGLES2 lens_shader; + CanvasShaderOpenGL canvas_shader; + CanvasShadowShaderOpenGL canvas_shadow_shader; + LensDistortedShaderOpenGL lens_shader; bool using_texture_rect; @@ -96,7 +96,7 @@ public: RID current_tex; RID current_normal; - RasterizerStorageGLES2::Texture *current_tex_ptr; + RasterizerStorageOpenGL::Texture *current_tex_ptr; Transform3D vp; Light *using_light; @@ -111,9 +111,9 @@ public: typedef void Texture; - RasterizerSceneGLES2 *scene_render; + RasterizerSceneOpenGL *scene_render; - RasterizerStorageGLES2 *storage; + RasterizerStorageOpenGL *storage; // allow user to choose api usage GLenum _buffer_upload_usage_flag; @@ -128,9 +128,9 @@ public: virtual void canvas_end(); protected: - void _legacy_draw_primitive(Item::CommandPrimitive *p_pr, RasterizerStorageGLES2::Material *p_material); - void _legacy_draw_line(Item::CommandPrimitive *p_pr, RasterizerStorageGLES2::Material *p_material); - void _legacy_draw_poly_triangles(Item::CommandPolygon *p_poly, RasterizerStorageGLES2::Material *p_material); + void _legacy_draw_primitive(Item::CommandPrimitive *p_pr, RasterizerStorageOpenGL::Material *p_material); + void _legacy_draw_line(Item::CommandPrimitive *p_pr, RasterizerStorageOpenGL::Material *p_material); + void _legacy_draw_poly_triangles(Item::CommandPolygon *p_poly, RasterizerStorageOpenGL::Material *p_material); public: void _draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color *p_colors, const Vector2 *p_uvs, const float *p_light_angles = nullptr); @@ -148,9 +148,27 @@ public: virtual void reset_canvas(); virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache); + + // Copied from RasterizerCanvasDummy: virtual void canvas_debug_viewport_shadows(Light *p_lights_with_shadow) override; - RasterizerStorageGLES2::Texture *_bind_canvas_texture(const RID &p_texture, const RID &p_normal_map); + RID light_create() override; + void light_set_texture(RID p_rid, RID p_texture) override; + void light_set_use_shadow(RID p_rid, bool p_enable) override; + void light_update_shadow(RID p_rid, int p_shadow_index, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders) override; + void light_update_directional_shadow(RID p_rid, int p_shadow_index, const Transform2D &p_light_xform, int p_light_mask, float p_cull_distance, const Rect2 &p_clip_rect, LightOccluderInstance *p_occluders) override; + + void render_sdf(RID p_render_target, LightOccluderInstance *p_occluders) override; + RID occluder_polygon_create() override; + void occluder_polygon_set_shape(RID p_occluder, const Vector<Vector2> &p_points, bool p_closed) override; + void occluder_polygon_set_cull_mode(RID p_occluder, RS::CanvasOccluderPolygonCullMode p_mode) override; + void set_shadow_texture_size(int p_size) override; + + bool free(RID p_rid) override; + void update() override; + // End copied from RasterizerCanvasDummy. + + RasterizerStorageOpenGL::Texture *_bind_canvas_texture(const RID &p_texture, const RID &p_normal_map); void _set_texture_rect_mode(bool p_texture_rect, bool p_light_angle = false, bool p_modulate = false, bool p_large_vertex = false); // NEW API @@ -170,7 +188,9 @@ public: void initialize(); void finalize(); - RasterizerCanvasBaseGLES2(); + RasterizerCanvasBaseOpenGL(); }; -#endif // GLES2_BACKEND_ENABLED +#endif // OPENGL_BACKEND_ENABLED + +#endif // RASTERIZER_CANVAS_BASE_OPENGL_H diff --git a/drivers/gles_common/rasterizer_canvas_batcher.h b/drivers/opengl/rasterizer_canvas_batcher.h index 1836fd68d2..c7345824ab 100644 --- a/drivers/gles_common/rasterizer_canvas_batcher.h +++ b/drivers/opengl/rasterizer_canvas_batcher.h @@ -36,15 +36,9 @@ #include "rasterizer_array.h" #include "rasterizer_asserts.h" #include "rasterizer_storage_common.h" -#include "rasterizer_version.h" -#ifdef GODOT_4 #include "core/config/project_settings.h" #include "servers/rendering/renderer_compositor.h" -#else -#include "core/project_settings.h" -#include "servers/visual/rasterizer.h" -#endif // We are using the curiously recurring template pattern // https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern @@ -564,12 +558,8 @@ private: void flush_render_batches(RendererCanvasRender::Item *p_first_item, RendererCanvasRender::Item *p_current_clip, bool &r_reclip, typename T_STORAGE::Material *p_material, uint32_t p_sequence_batch_type_flags); // a single joined item can contain multiple itemrefs, and thus create lots of batches -#ifdef GODOT_3 - bool prefill_joined_item(FillState &r_fill_state, int &r_command_start, RendererCanvasRender::Item *p_item, RendererCanvasRender::Item *p_current_clip, bool &r_reclip, typename T_STORAGE::Material *p_material); -#else // command start given a separate name to make easier to tell apart godot 3 and 4 bool prefill_joined_item(FillState &r_fill_state, RendererCanvasRender::Item::Command **r_first_command, RendererCanvasRender::Item *p_item, RendererCanvasRender::Item *p_current_clip, bool &r_reclip, typename T_STORAGE::Material *p_material); -#endif // prefilling different types of batch @@ -578,14 +568,6 @@ private: void _prefill_default_batch(FillState &r_fill_state, int p_command_num, const RendererCanvasRender::Item &p_item); // accelerated batches -#ifdef GODOT_3 - bool _prefill_line(RendererCanvasRender::Item::GD_COMMAND_LINE *p_line, FillState &r_fill_state, int &r_command_start, int command_num, int command_count, RendererCanvasRender::Item *p_item, bool multiply_final_modulate); - template <bool SEND_LIGHT_ANGLES> - bool _prefill_ninepatch(RendererCanvasRender::Item::CommandNinePatch *p_np, FillState &r_fill_state, int &r_command_start, int command_num, int command_count, RendererCanvasRender::Item *p_item, bool multiply_final_modulate); - template <bool SEND_LIGHT_ANGLES> - bool _prefill_polygon(RendererCanvasRender::Item::CommandPolygon *p_poly, FillState &r_fill_state, int &r_command_start, int command_num, int command_count, RendererCanvasRender::Item *p_item, bool multiply_final_modulate); - template <bool SEND_LIGHT_ANGLES> -#endif bool _prefill_rect(RendererCanvasRender::Item::CommandRect *rect, FillState &r_fill_state, int &r_command_start, int command_num, int command_count, RendererCanvasRender::Item::Command *const *commands, RendererCanvasRender::Item *p_item, bool multiply_final_modulate); // dealing with textures @@ -622,13 +604,9 @@ protected: return TM_ALL; } -#ifdef GODOT_3 - bool _software_skin_poly(RendererCanvasRender::Item::CommandPolygon *p_poly, RendererCanvasRender::Item *p_item, BatchVertex *bvs, BatchColor *vertex_colors, const FillState &p_fill_state, const BatchColor *p_precalced_colors); -#endif - typename T_STORAGE::Texture *_get_canvas_texture(const RID &p_texture) const { if (p_texture.is_valid()) { - typename T_STORAGE::Texture *texture = get_storage()->texture_owner.getornull(p_texture); + typename T_STORAGE::Texture *texture = get_storage()->texture_owner.get_or_null(p_texture); if (texture) { return texture->get_ptr(); @@ -665,7 +643,6 @@ public: } protected: -#ifdef GODOT_4 int godot4_commands_count(RendererCanvasRender::Item::Command *p_comm) const { int count = 0; while (p_comm) { @@ -683,12 +660,6 @@ protected: } return p_list.size(); } -#endif - - // no need to compile these in in release, they are unneeded outside the editor and only add to executable size -#if defined(TOOLS_ENABLED) && defined(DEBUG_ENABLED) -#include "batch_diagnose.inc" -#endif }; PREAMBLE(void)::batch_canvas_begin() { @@ -772,7 +743,7 @@ PREAMBLE(void)::batch_canvas_render_items_begin(const Color &p_modulate, Rendere while (p_light) { light_count++; - if ((p_light->z_min != GD_VS::CANVAS_ITEM_Z_MIN) || (p_light->z_max != GD_VS::CANVAS_ITEM_Z_MAX)) { + if ((p_light->z_min != RS::CANVAS_ITEM_Z_MIN) || (p_light->z_max != RS::CANVAS_ITEM_Z_MAX)) { // prevent joining across z indices. This would have caused visual regressions bdata.join_across_z_indices = false; } @@ -1200,10 +1171,6 @@ PREAMBLE(bool)::_light_scissor_begin(const Rect2 &p_item_rect, const Transform2D int rh = get_storage()->frame.current_rt->height; int y = rh - (cliprect.position.y + cliprect.size.y); -#ifdef GODOT_3 - if (get_storage()->frame.current_rt->flags[RendererStorage::RENDER_TARGET_VFLIP]) - y = cliprect.position.y; -#endif get_this()->gl_enable_scissor(cliprect.position.x, y, cliprect.size.width, cliprect.size.height); return true; @@ -1264,1168 +1231,6 @@ PREAMBLE(void)::_calculate_scissor_threshold_area() { } } -#ifdef GODOT_3 -PREAMBLE(bool)::_prefill_line(RendererCanvasRender::Item::GD_COMMAND_LINE *p_line, FillState &r_fill_state, int &r_command_start, int command_num, int command_count, RendererCanvasRender::Item *p_item, bool multiply_final_modulate) { - bool change_batch = false; - - // we have separate batch types for non and anti aliased lines. - // You can't batch the different types together. - RasterizerStorageCommon::BatchType line_batch_type = RasterizerStorageCommon::BT_LINE; - uint32_t line_batch_flags = RasterizerStorageCommon::BTF_LINE; -#ifdef GLES_OVER_GL - if (p_line->antialiased) { - line_batch_type = RasterizerStorageCommon::BT_LINE_AA; - line_batch_flags = RasterizerStorageCommon::BTF_LINE_AA; - } -#endif - - // conditions for creating a new batch - if (r_fill_state.curr_batch->type != line_batch_type) { - if (r_fill_state.sequence_batch_type_flags & (~line_batch_flags)) { - // don't allow joining to a different sequence type - r_command_start = command_num; - return true; - } - r_fill_state.sequence_batch_type_flags |= line_batch_flags; - - change_batch = true; - } - - // get the baked line color - Color col = p_line->color; - - if (multiply_final_modulate) - col *= r_fill_state.final_modulate; - - BatchColor bcol; - bcol.set(col); - - // if the color has changed we need a new batch - // (only single color line batches supported so far) - if (r_fill_state.curr_batch->color != bcol) - change_batch = true; - - // not sure if needed - r_fill_state.batch_tex_id = -1; - - // try to create vertices BEFORE creating a batch, - // because if the vertex buffer is full, we need to finish this - // function, draw what we have so far, and then start a new set of batches - - // request multiple vertices at a time, this is more efficient - BatchVertex *bvs = bdata.vertices.request(2); - if (!bvs) { - // run out of space in the vertex buffer .. finish this function and draw what we have so far - // return where we got to - r_command_start = command_num; - return true; - } - - if (change_batch) { - // open new batch (this should never fail, it dynamically grows) - r_fill_state.curr_batch = _batch_request_new(false); - - r_fill_state.curr_batch->type = line_batch_type; - r_fill_state.curr_batch->color = bcol; - r_fill_state.curr_batch->batch_texture_id = -1; - r_fill_state.curr_batch->first_command = command_num; - r_fill_state.curr_batch->num_commands = 1; - //r_fill_state.curr_batch->first_quad = bdata.total_quads; - r_fill_state.curr_batch->first_vert = bdata.total_verts; - } else { - // we could alternatively do the count when closing a batch .. perhaps more efficient - r_fill_state.curr_batch->num_commands++; - } - - // fill the geometry - Vector2 from = p_line->from; - Vector2 to = p_line->to; - - if (r_fill_state.transform_mode != TM_NONE) { - _software_transform_vertex(from, r_fill_state.transform_combined); - _software_transform_vertex(to, r_fill_state.transform_combined); - } - - bvs[0].pos.set(from); - bvs[0].uv.set(0, 0); // may not be necessary - bvs[1].pos.set(to); - bvs[1].uv.set(0, 0); - - bdata.total_verts += 2; - - return false; -} -#endif // godot 3 - -//unsigned int _ninepatch_apply_tiling_modes(RendererCanvasRender::Item::CommandNinePatch *p_np, Rect2 &r_source) { -// unsigned int rect_flags = 0; - -// switch (p_np->axis_x) { -// default: -// break; -// case VisualServer::NINE_PATCH_TILE: { -// r_source.size.x = p_np->rect.size.x; -// rect_flags = RendererCanvasRender::CANVAS_RECT_TILE; -// } break; -// case VisualServer::NINE_PATCH_TILE_FIT: { -// // prevent divide by zero (may never happen) -// if (r_source.size.x) { -// int units = p_np->rect.size.x / r_source.size.x; -// if (!units) -// units++; -// r_source.size.x = r_source.size.x * units; -// rect_flags = RendererCanvasRender::CANVAS_RECT_TILE; -// } -// } break; -// } - -// switch (p_np->axis_y) { -// default: -// break; -// case VisualServer::NINE_PATCH_TILE: { -// r_source.size.y = p_np->rect.size.y; -// rect_flags = RendererCanvasRender::CANVAS_RECT_TILE; -// } break; -// case VisualServer::NINE_PATCH_TILE_FIT: { -// // prevent divide by zero (may never happen) -// if (r_source.size.y) { -// int units = p_np->rect.size.y / r_source.size.y; -// if (!units) -// units++; -// r_source.size.y = r_source.size.y * units; -// rect_flags = RendererCanvasRender::CANVAS_RECT_TILE; -// } -// } break; -// } - -// return rect_flags; -//} - -#ifdef GODOT_3 - -T_PREAMBLE -template <bool SEND_LIGHT_ANGLES> -bool C_PREAMBLE::_prefill_ninepatch(RendererCanvasRender::Item::CommandNinePatch *p_np, FillState &r_fill_state, int &r_command_start, int command_num, int command_count, RendererCanvasRender::Item *p_item, bool multiply_final_modulate) { - typename T_STORAGE::Texture *tex = get_storage()->texture_owner.getornull(p_np->texture); - - if (!tex) { - // FIXME: Handle textureless ninepatch gracefully - WARN_PRINT("NinePatch without texture not supported yet in GLES2 backend, skipping."); - return false; - } - if (tex->width == 0 || tex->height == 0) { - WARN_PRINT("Cannot set empty texture to NinePatch."); - return false; - } - - // first check there are enough verts for this to complete successfully - if (bdata.vertices.size() + (4 * 9) > bdata.vertices.max_size()) { - // return where we got to - r_command_start = command_num; - return true; - } - - // create a temporary rect so we can reuse the rect routine - RendererCanvasRender::Item::CommandRect trect; - - trect.texture = p_np->texture; -#ifdef GODOT_3 - trect.normal_map = p_np->normal_map; -#endif - trect.modulate = p_np->color; - trect.flags = RendererCanvasRender::CANVAS_RECT_REGION; - - //Size2 texpixel_size(1.0f / tex->width, 1.0f / tex->height); - - Rect2 source = p_np->source; - if (source.size.x == 0 && source.size.y == 0) { - source.size.x = tex->width; - source.size.y = tex->height; - } - - float screen_scale = 1.0f; - - // optional crazy ninepatch scaling mode - if ((bdata.settings_ninepatch_mode == 1) && (source.size.x != 0) && (source.size.y != 0)) { - screen_scale = MIN(p_np->rect.size.x / source.size.x, p_np->rect.size.y / source.size.y); - screen_scale = MIN(1.0, screen_scale); - } - - // deal with nine patch texture wrapping modes - // this is switched off because it may not be possible with batching - // trect.flags |= _ninepatch_apply_tiling_modes(p_np, source); - - // translate to rects - Rect2 &rt = trect.rect; - Rect2 &src = trect.source; - - float tex_margin_left = p_np->margin[MARGIN_LEFT]; - float tex_margin_right = p_np->margin[MARGIN_RIGHT]; - float tex_margin_top = p_np->margin[MARGIN_TOP]; - float tex_margin_bottom = p_np->margin[MARGIN_BOTTOM]; - - float x[4]; - x[0] = p_np->rect.position.x; - x[1] = x[0] + (p_np->margin[MARGIN_LEFT] * screen_scale); - x[3] = x[0] + (p_np->rect.size.x); - x[2] = x[3] - (p_np->margin[MARGIN_RIGHT] * screen_scale); - - float y[4]; - y[0] = p_np->rect.position.y; - y[1] = y[0] + (p_np->margin[MARGIN_TOP] * screen_scale); - y[3] = y[0] + (p_np->rect.size.y); - y[2] = y[3] - (p_np->margin[MARGIN_BOTTOM] * screen_scale); - - float u[4]; - u[0] = source.position.x; - u[1] = u[0] + tex_margin_left; - u[3] = u[0] + source.size.x; - u[2] = u[3] - tex_margin_right; - - float v[4]; - v[0] = source.position.y; - v[1] = v[0] + tex_margin_top; - v[3] = v[0] + source.size.y; - v[2] = v[3] - tex_margin_bottom; - - // temporarily override to prevent single rect fallback - bool single_rect_fallback = bdata.settings_use_single_rect_fallback; - bdata.settings_use_single_rect_fallback = false; - - // each line of the ninepatch - for (int line = 0; line < 3; line++) { - rt.position = Vector2(x[0], y[line]); - rt.size = Vector2(x[1] - x[0], y[line + 1] - y[line]); - src.position = Vector2(u[0], v[line]); - src.size = Vector2(u[1] - u[0], v[line + 1] - v[line]); - _prefill_rect<SEND_LIGHT_ANGLES>(&trect, r_fill_state, r_command_start, command_num, command_count, nullptr, p_item, multiply_final_modulate); - - if ((line == 1) && (!p_np->draw_center)) - ; - else { - rt.position.x = x[1]; - rt.size.x = x[2] - x[1]; - src.position.x = u[1]; - src.size.x = u[2] - u[1]; - _prefill_rect<SEND_LIGHT_ANGLES>(&trect, r_fill_state, r_command_start, command_num, command_count, nullptr, p_item, multiply_final_modulate); - } - - rt.position.x = x[2]; - rt.size.x = x[3] - x[2]; - src.position.x = u[2]; - src.size.x = u[3] - u[2]; - _prefill_rect<SEND_LIGHT_ANGLES>(&trect, r_fill_state, r_command_start, command_num, command_count, nullptr, p_item, multiply_final_modulate); - } - - // restore single rect fallback - bdata.settings_use_single_rect_fallback = single_rect_fallback; - return false; -} - -T_PREAMBLE -template <bool SEND_LIGHT_ANGLES> -bool C_PREAMBLE::_prefill_polygon(RendererCanvasRender::Item::CommandPolygon *p_poly, FillState &r_fill_state, int &r_command_start, int command_num, int command_count, RendererCanvasRender::Item *p_item, bool multiply_final_modulate) { - bool change_batch = false; - - // conditions for creating a new batch - if (r_fill_state.curr_batch->type != RasterizerStorageCommon::BT_POLY) { - // don't allow joining to a different sequence type - if (r_fill_state.sequence_batch_type_flags & (~RasterizerStorageCommon::BTF_POLY)) { - // don't allow joining to a different sequence type - r_command_start = command_num; - return true; - } - r_fill_state.sequence_batch_type_flags |= RasterizerStorageCommon::BTF_POLY; - - change_batch = true; - } - - int num_inds = p_poly->indices.size(); - - // nothing to draw? - if (!num_inds) - return false; - - // we aren't using indices, so will transform verts more than once .. less efficient. - // could be done with a temporary vertex buffer - BatchVertex *bvs = bdata.vertices.request(num_inds); - if (!bvs) { - // run out of space in the vertex buffer .. finish this function and draw what we have so far - // return where we got to - r_command_start = command_num; - return true; - } - - BatchColor *vertex_colors = bdata.vertex_colors.request(num_inds); - RAST_DEBUG_ASSERT(vertex_colors); - - // are we using large FVF? - //////////////////////////////////// - const bool use_large_verts = bdata.use_large_verts; - const bool use_modulate = bdata.use_modulate; - - BatchColor *vertex_modulates = nullptr; - if (use_modulate) { - vertex_modulates = bdata.vertex_modulates.request(num_inds); - RAST_DEBUG_ASSERT(vertex_modulates); - // precalc the vertex modulate (will be shared by all verts) - // we store the modulate as an attribute in the fvf rather than a uniform - vertex_modulates[0].set(r_fill_state.final_modulate); - } - - BatchTransform *pBT = nullptr; - if (use_large_verts) { - pBT = bdata.vertex_transforms.request(num_inds); - RAST_DEBUG_ASSERT(pBT); - // precalc the batch transform (will be shared by all verts) - // we store the transform as an attribute in the fvf rather than a uniform - const Transform2D &tr = r_fill_state.transform_combined; - - pBT[0].translate.set(tr.elements[2]); - // could do swizzling in shader? - pBT[0].basis[0].set(tr.elements[0][0], tr.elements[1][0]); - pBT[0].basis[1].set(tr.elements[0][1], tr.elements[1][1]); - } - //////////////////////////////////// - - // the modulate is always baked - Color modulate; - if (!use_large_verts && !use_modulate && multiply_final_modulate) - modulate = r_fill_state.final_modulate; - else - modulate = Color(1, 1, 1, 1); - - int old_batch_tex_id = r_fill_state.batch_tex_id; - r_fill_state.batch_tex_id = _batch_find_or_create_tex(p_poly->texture, p_poly->normal_map, false, old_batch_tex_id); - - // conditions for creating a new batch - if (old_batch_tex_id != r_fill_state.batch_tex_id) { - change_batch = true; - } - - // N.B. polygons don't have color thus don't need a batch change with color - // This code is left as reference in case of problems. - // if (!r_fill_state.curr_batch->color.equals(modulate)) { - // change_batch = true; - // bdata.total_color_changes++; - // } - - if (change_batch) { - // put the tex pixel size in a local (less verbose and can be a register) - const BatchTex &batchtex = bdata.batch_textures[r_fill_state.batch_tex_id]; - batchtex.tex_pixel_size.to(r_fill_state.texpixel_size); - - if (bdata.settings_uv_contract) { - r_fill_state.contract_uvs = (batchtex.flags & GD_VS::TEXTURE_FLAG_FILTER) == 0; - } - - // open new batch (this should never fail, it dynamically grows) - r_fill_state.curr_batch = _batch_request_new(false); - - r_fill_state.curr_batch->type = RasterizerStorageCommon::BT_POLY; - - // modulate unused except for debugging? - r_fill_state.curr_batch->color.set(modulate); - r_fill_state.curr_batch->batch_texture_id = r_fill_state.batch_tex_id; - r_fill_state.curr_batch->first_command = command_num; - r_fill_state.curr_batch->num_commands = num_inds; - // r_fill_state.curr_batch->num_elements = num_inds; - r_fill_state.curr_batch->first_vert = bdata.total_verts; - } else { - // we could alternatively do the count when closing a batch .. perhaps more efficient - r_fill_state.curr_batch->num_commands += num_inds; - } - - // PRECALCULATE THE COLORS (as there may be less colors than there are indices - // in either hardware or software paths) - BatchColor vcol; - int num_verts = p_poly->points.size(); - - // in special cases, only 1 color is specified by convention, so we want to preset this - // to use in all verts. - if (p_poly->colors.size()) - vcol.set(p_poly->colors[0] * modulate); - else - // color is undefined, use modulate color straight - vcol.set(modulate); - - BatchColor *precalced_colors = (BatchColor *)alloca(num_verts * sizeof(BatchColor)); - - // two stage, super efficient setup of precalculated colors - int num_colors_specified = p_poly->colors.size(); - - for (int n = 0; n < num_colors_specified; n++) { - vcol.set(p_poly->colors[n] * modulate); - precalced_colors[n] = vcol; - } - for (int n = num_colors_specified; n < num_verts; n++) { - precalced_colors[n] = vcol; - } - - if (!_software_skin_poly(p_poly, p_item, bvs, vertex_colors, r_fill_state, precalced_colors)) { - for (int n = 0; n < num_inds; n++) { - int ind = p_poly->indices[n]; - - RAST_DEV_DEBUG_ASSERT(ind < p_poly->points.size()); - - // this could be moved outside the loop - if (r_fill_state.transform_mode != TM_NONE) { - Vector2 pos = p_poly->points[ind]; - _software_transform_vertex(pos, r_fill_state.transform_combined); - bvs[n].pos.set(pos.x, pos.y); - } else { - const Point2 &pos = p_poly->points[ind]; - bvs[n].pos.set(pos.x, pos.y); - } - - if (ind < p_poly->uvs.size()) { - const Point2 &uv = p_poly->uvs[ind]; - bvs[n].uv.set(uv.x, uv.y); - } else { - bvs[n].uv.set(0.0f, 0.0f); - } - - vertex_colors[n] = precalced_colors[ind]; - - if (use_modulate) { - vertex_modulates[n] = vertex_modulates[0]; - } - - if (use_large_verts) { - // reuse precalced transform (same for each vertex within polygon) - pBT[n] = pBT[0]; - } - } - } // if not software skinning - else { - // software skinning extra passes - if (use_modulate) { - for (int n = 0; n < num_inds; n++) { - vertex_modulates[n] = vertex_modulates[0]; - } - } - // not sure if this will produce garbage if software skinning is changing vertex pos - // in the shader, but is included for completeness - if (use_large_verts) { - for (int n = 0; n < num_inds; n++) { - pBT[n] = pBT[0]; - } - } - } - - // increment total vert count - bdata.total_verts += num_inds; - - return false; -} - -PREAMBLE(bool)::_software_skin_poly(RendererCanvasRender::Item::CommandPolygon *p_poly, RendererCanvasRender::Item *p_item, BatchVertex *bvs, BatchColor *vertex_colors, const FillState &p_fill_state, const BatchColor *p_precalced_colors) { - // alternatively could check get_this()->state.using_skeleton - if (p_item->skeleton == RID()) - return false; - - int num_inds = p_poly->indices.size(); - int num_verts = p_poly->points.size(); - - RID skeleton = p_item->skeleton; - int bone_count = RendererStorage::base_singleton->skeleton_get_bone_count(skeleton); - - // we want a temporary buffer of positions to transform - Vector2 *pTemps = (Vector2 *)alloca(num_verts * sizeof(Vector2)); - memset((void *)pTemps, 0, num_verts * sizeof(Vector2)); - - // these are used in the shader but don't appear to be needed for software transform - // const Transform2D &skel_trans = get_this()->state.skeleton_transform; - // const Transform2D &skel_trans_inv = get_this()->state.skeleton_transform_inverse; - - // get the bone transforms. - // this is not ideal because we don't know in advance which bones are needed - // for any particular poly, but depends how cheap the skeleton_bone_get_transform_2d call is - Transform2D *bone_transforms = (Transform2D *)alloca(bone_count * sizeof(Transform2D)); - for (int b = 0; b < bone_count; b++) { - bone_transforms[b] = RendererStorage::base_singleton->skeleton_bone_get_transform_2d(skeleton, b); - } - - if (num_verts && (p_poly->bones.size() == num_verts * 4) && (p_poly->weights.size() == p_poly->bones.size())) { - const Transform2D &item_transform = p_item->xform; - Transform2D item_transform_inv = item_transform.affine_inverse(); - - for (int n = 0; n < num_verts; n++) { - const Vector2 &src_pos = p_poly->points[n]; - Vector2 &dst_pos = pTemps[n]; - - // there can be an offset on the polygon at rigging time, this has to be accounted for - // note it may be possible that this could be concatenated with the bone transforms to save extra transforms - not sure yet - Vector2 src_pos_back_transformed = item_transform.xform(src_pos); - - float total_weight = 0.0f; - - for (int k = 0; k < 4; k++) { - int bone_id = p_poly->bones[n * 4 + k]; - float weight = p_poly->weights[n * 4 + k]; - if (weight == 0.0f) - continue; - - total_weight += weight; - - RAST_DEBUG_ASSERT(bone_id < bone_count); - const Transform2D &bone_tr = bone_transforms[bone_id]; - - Vector2 pos = bone_tr.xform(src_pos_back_transformed); - - dst_pos += pos * weight; - } - - // this is some unexplained weirdness with verts with no weights, - // but it seemed to work for the example project ... watch for regressions - if (total_weight < 0.01f) - dst_pos = src_pos; - else { - dst_pos /= total_weight; - - // retransform back from the poly offset space - dst_pos = item_transform_inv.xform(dst_pos); - } - } - - // software transform with combined matrix? - if (p_fill_state.transform_mode != TM_NONE) { - for (int n = 0; n < num_verts; n++) { - Vector2 &dst_pos = pTemps[n]; - _software_transform_vertex(dst_pos, p_fill_state.transform_combined); - } - } - - } // if bone format matches - else { - // not supported - } - - // output to the batch verts - for (int n = 0; n < num_inds; n++) { - int ind = p_poly->indices[n]; - - RAST_DEV_DEBUG_ASSERT(ind < num_verts); - const Point2 &pos = pTemps[ind]; - bvs[n].pos.set(pos.x, pos.y); - - if (ind < p_poly->uvs.size()) { - const Point2 &uv = p_poly->uvs[ind]; - bvs[n].uv.set(uv.x, uv.y); - } else { - bvs[n].uv.set(0.0f, 0.0f); - } - - vertex_colors[n] = p_precalced_colors[ind]; - } - - return true; -} - -T_PREAMBLE -template <bool SEND_LIGHT_ANGLES> -bool C_PREAMBLE::_prefill_rect(RendererCanvasRender::Item::CommandRect *rect, FillState &r_fill_state, int &r_command_start, int command_num, int command_count, RendererCanvasRender::Item::Command *const *commands, RendererCanvasRender::Item *p_item, bool multiply_final_modulate) { - bool change_batch = false; - - // conditions for creating a new batch - if (r_fill_state.curr_batch->type != RasterizerStorageCommon::BT_RECT) { - // don't allow joining to a different sequence type - if (r_fill_state.sequence_batch_type_flags & (~RasterizerStorageCommon::BTF_RECT)) { - // don't allow joining to a different sequence type - r_command_start = command_num; - return true; - } - r_fill_state.sequence_batch_type_flags |= RasterizerStorageCommon::BTF_RECT; - - change_batch = true; - - // check for special case if there is only a single or small number of rects, - // in which case we will use the legacy default rect renderer - // because it is faster for single rects - - // we only want to do this if not a joined item with more than 1 item, - // because joined items with more than 1, the command * will be incorrect - // NOTE - this is assuming that use_hardware_transform means that it is a non-joined item!! - // If that assumption is incorrect this will go horribly wrong. - if (bdata.settings_use_single_rect_fallback && r_fill_state.use_hardware_transform) { - bool is_single_rect = false; - int command_num_next = command_num + 1; - if (command_num_next < command_count) { - RendererCanvasRender::Item::Command *command_next = commands[command_num_next]; - if ((command_next->type != RendererCanvasRender::Item::Command::TYPE_RECT) && (command_next->type != RendererCanvasRender::Item::Command::TYPE_TRANSFORM)) { - is_single_rect = true; - } - } else { - is_single_rect = true; - } - // if it is a rect on its own, do exactly the same as the default routine - if (is_single_rect) { - _prefill_default_batch(r_fill_state, command_num, *p_item); - return false; - } - } // if use hardware transform - } - - // try to create vertices BEFORE creating a batch, - // because if the vertex buffer is full, we need to finish this - // function, draw what we have so far, and then start a new set of batches - - // request FOUR vertices at a time, this is more efficient - BatchVertex *bvs = bdata.vertices.request(4); - if (!bvs) { - // run out of space in the vertex buffer .. finish this function and draw what we have so far - // return where we got to - r_command_start = command_num; - return true; - } - - // are we using large FVF? - const bool use_large_verts = bdata.use_large_verts; - const bool use_modulate = bdata.use_modulate; - - Color col = rect->modulate; - - if (!use_large_verts) { - if (multiply_final_modulate) { - col *= r_fill_state.final_modulate; - } - } - - // instead of doing all the texture preparation for EVERY rect, - // we build a list of texture combinations and do this once off. - // This means we have a potentially rather slow step to identify which texture combo - // using the RIDs. - int old_batch_tex_id = r_fill_state.batch_tex_id; - -#ifdef GODOT_4 - r_fill_state.batch_tex_id = _batch_find_or_create_tex(rect->texture, RID(), rect->flags & RendererCanvasRender::CANVAS_RECT_TILE, old_batch_tex_id); -#else - r_fill_state.batch_tex_id = _batch_find_or_create_tex(rect->texture, rect->normal_map, rect->flags & RendererCanvasRender::CANVAS_RECT_TILE, old_batch_tex_id); -#endif - - //r_fill_state.use_light_angles = send_light_angles; - if (SEND_LIGHT_ANGLES) { - bdata.use_light_angles = true; - } - - // conditions for creating a new batch - if (old_batch_tex_id != r_fill_state.batch_tex_id) { - change_batch = true; - } - - // we need to treat color change separately because we need to count these - // to decide whether to switch on the fly to colored vertices. - if (!r_fill_state.curr_batch->color.equals(col)) { - change_batch = true; - bdata.total_color_changes++; - } - - if (change_batch) { - // put the tex pixel size in a local (less verbose and can be a register) - const BatchTex &batchtex = bdata.batch_textures[r_fill_state.batch_tex_id]; - batchtex.tex_pixel_size.to(r_fill_state.texpixel_size); - - if (bdata.settings_uv_contract) { - r_fill_state.contract_uvs = (batchtex.flags & GD_VS::TEXTURE_FLAG_FILTER) == 0; - } - - // need to preserve texpixel_size between items - //r_fill_state.texpixel_size = r_fill_state.texpixel_size; - - // open new batch (this should never fail, it dynamically grows) - r_fill_state.curr_batch = _batch_request_new(false); - - r_fill_state.curr_batch->type = RasterizerStorageCommon::BT_RECT; - r_fill_state.curr_batch->color.set(col); - r_fill_state.curr_batch->batch_texture_id = r_fill_state.batch_tex_id; - r_fill_state.curr_batch->first_command = command_num; - r_fill_state.curr_batch->num_commands = 1; - //r_fill_state.curr_batch->first_quad = bdata.total_quads; - r_fill_state.curr_batch->first_vert = bdata.total_verts; - } else { - // we could alternatively do the count when closing a batch .. perhaps more efficient - r_fill_state.curr_batch->num_commands++; - } - - // fill the quad geometry - Vector2 mins = rect->rect.position; - - if (r_fill_state.transform_mode == TM_TRANSLATE) { - if (!use_large_verts) { - _software_transform_vertex(mins, r_fill_state.transform_combined); - } - } - - Vector2 maxs = mins + rect->rect.size; - - // just aliases - BatchVertex *bA = &bvs[0]; - BatchVertex *bB = &bvs[1]; - BatchVertex *bC = &bvs[2]; - BatchVertex *bD = &bvs[3]; - - bA->pos.x = mins.x; - bA->pos.y = mins.y; - - bB->pos.x = maxs.x; - bB->pos.y = mins.y; - - bC->pos.x = maxs.x; - bC->pos.y = maxs.y; - - bD->pos.x = mins.x; - bD->pos.y = maxs.y; - - // possibility of applying flips here for normal mapping .. but they don't seem to be used - if (rect->rect.size.x < 0) { - SWAP(bA->pos, bB->pos); - SWAP(bC->pos, bD->pos); - } - if (rect->rect.size.y < 0) { - SWAP(bA->pos, bD->pos); - SWAP(bB->pos, bC->pos); - } - - if (r_fill_state.transform_mode == TM_ALL) { - if (!use_large_verts) { - _software_transform_vertex(bA->pos, r_fill_state.transform_combined); - _software_transform_vertex(bB->pos, r_fill_state.transform_combined); - _software_transform_vertex(bC->pos, r_fill_state.transform_combined); - _software_transform_vertex(bD->pos, r_fill_state.transform_combined); - } - } - - // uvs - Vector2 src_min; - Vector2 src_max; - if (rect->flags & RendererCanvasRender::CANVAS_RECT_REGION) { - src_min = rect->source.position; - src_max = src_min + rect->source.size; - - src_min *= r_fill_state.texpixel_size; - src_max *= r_fill_state.texpixel_size; - - const float uv_epsilon = bdata.settings_uv_contract_amount; - - // nudge offset for the maximum to prevent precision error on GPU reading into line outside the source rect - // this is very difficult to get right. - if (r_fill_state.contract_uvs) { - src_min.x += uv_epsilon; - src_min.y += uv_epsilon; - src_max.x -= uv_epsilon; - src_max.y -= uv_epsilon; - } - } else { - src_min = Vector2(0, 0); - src_max = Vector2(1, 1); - } - - // 10% faster calculating the max first - Vector2 uvs[4] = { - src_min, - Vector2(src_max.x, src_min.y), - src_max, - Vector2(src_min.x, src_max.y), - }; - - // for encoding in light angle - // flips should be optimized out when not being used for light angle. - bool flip_h = false; - bool flip_v = false; - - if (rect->flags & RendererCanvasRender::CANVAS_RECT_TRANSPOSE) { - SWAP(uvs[1], uvs[3]); - } - - if (rect->flags & RendererCanvasRender::CANVAS_RECT_FLIP_H) { - SWAP(uvs[0], uvs[1]); - SWAP(uvs[2], uvs[3]); - flip_h = !flip_h; - flip_v = !flip_v; - } - if (rect->flags & RendererCanvasRender::CANVAS_RECT_FLIP_V) { - SWAP(uvs[0], uvs[3]); - SWAP(uvs[1], uvs[2]); - flip_v = !flip_v; - } - - bA->uv.set(uvs[0]); - bB->uv.set(uvs[1]); - bC->uv.set(uvs[2]); - bD->uv.set(uvs[3]); - - // modulate - if (use_modulate) { - // store the final modulate separately from the rect modulate - BatchColor *pBC = bdata.vertex_modulates.request(4); - RAST_DEBUG_ASSERT(pBC); - pBC[0].set(r_fill_state.final_modulate); - pBC[1] = pBC[0]; - pBC[2] = pBC[0]; - pBC[3] = pBC[0]; - } - - if (use_large_verts) { - // store the transform separately - BatchTransform *pBT = bdata.vertex_transforms.request(4); - RAST_DEBUG_ASSERT(pBT); - - const Transform2D &tr = r_fill_state.transform_combined; - - pBT[0].translate.set(tr.elements[2]); - // could do swizzling in shader? - pBT[0].basis[0].set(tr.elements[0][0], tr.elements[1][0]); - pBT[0].basis[1].set(tr.elements[0][1], tr.elements[1][1]); - - pBT[1] = pBT[0]; - pBT[2] = pBT[0]; - pBT[3] = pBT[0]; - } - - if (SEND_LIGHT_ANGLES) { - // we can either keep the light angles in sync with the verts when writing, - // or sync them up during translation. We are syncing in translation. - // N.B. There may be batches that don't require light_angles between batches that do. - float *angles = bdata.light_angles.request(4); - RAST_DEBUG_ASSERT(angles); - - float angle = 0.0f; - const float TWO_PI = Math_PI * 2; - - if (r_fill_state.transform_mode != TM_NONE) { - const Transform2D &tr = r_fill_state.transform_combined; - - // apply to an x axis - // the x axis and y axis can be taken directly from the transform (no need to xform identity vectors) - Vector2 x_axis(tr.elements[0][0], tr.elements[1][0]); - - // have to do a y axis to check for scaling flips - // this is hassle and extra slowness. We could only allow flips via the flags. - Vector2 y_axis(tr.elements[0][1], tr.elements[1][1]); - - // has the x / y axis flipped due to scaling? - float cross = x_axis.cross(y_axis); - if (cross < 0.0f) { - flip_v = !flip_v; - } - - // passing an angle is smaller than a vector, it can be reconstructed in the shader - angle = x_axis.angle(); - - // we don't want negative angles, as negative is used to encode flips. - // This moves range from -PI to PI to 0 to TWO_PI - if (angle < 0.0f) - angle += TWO_PI; - - } // if transform needed - - // if horizontal flip, angle is shifted by 180 degrees - if (flip_h) { - angle += Math_PI; - - // mod to get back to 0 to TWO_PI range - angle = fmodf(angle, TWO_PI); - } - - // add 1 (to take care of zero floating point error with sign) - angle += 1.0f; - - // flip if necessary to indicate a vertical flip in the shader - if (flip_v) - angle *= -1.0f; - - // light angle must be sent for each vert, instead as a single uniform in the uniform draw method - // this has the benefit of enabling batching with light angles. - for (int n = 0; n < 4; n++) { - angles[n] = angle; - } - } - - // increment quad count - bdata.total_quads++; - bdata.total_verts += 4; - - return false; -} - -// This function may be called MULTIPLE TIMES for each item, so needs to record how far it has got -PREAMBLE(bool)::prefill_joined_item(FillState &r_fill_state, int &r_command_start, RendererCanvasRender::Item *p_item, RendererCanvasRender::Item *p_current_clip, bool &r_reclip, typename T_STORAGE::Material *p_material) { - // we will prefill batches and vertices ready for sending in one go to the vertex buffer - int command_count = p_item->commands.size(); - RendererCanvasRender::Item::Command *const *commands = p_item->commands.ptr(); - - // checking the color for not being white makes it 92/90 times faster in the case where it is white - bool multiply_final_modulate = false; - if (!r_fill_state.use_hardware_transform && (r_fill_state.final_modulate != Color(1, 1, 1, 1))) { - multiply_final_modulate = true; - } - - // start batch is a dummy batch (tex id -1) .. could be made more efficient - if (!r_fill_state.curr_batch) { - // OLD METHOD, but left dangling zero length default batches - // r_fill_state.curr_batch = _batch_request_new(); - // r_fill_state.curr_batch->type = RasterizerStorageCommon::BT_DEFAULT; - // r_fill_state.curr_batch->first_command = r_command_start; - // should tex_id be set to -1? check this - - // allocate dummy batch on the stack, it should always get replaced - // note that the rest of the structure is uninitialized, this should not matter - // if the type is checked before anything else. - r_fill_state.curr_batch = (Batch *)alloca(sizeof(Batch)); - r_fill_state.curr_batch->type = RasterizerStorageCommon::BT_DUMMY; - - // this is assumed to be the case - //CRASH_COND (r_fill_state.transform_extra_command_number_p1); - } - - // we need to return which command we got up to, so - // store this outside the loop - int command_num; - - // do as many commands as possible until the vertex buffer will be full up - for (command_num = r_command_start; command_num < command_count; command_num++) { - RendererCanvasRender::Item::Command *command = commands[command_num]; - - switch (command->type) { - default: { - _prefill_default_batch(r_fill_state, command_num, *p_item); - } break; - case RendererCanvasRender::Item::Command::TYPE_TRANSFORM: { - // if the extra matrix has been sent already, - // break this extra matrix software path (as we don't want to unset it on the GPU etc) - if (r_fill_state.extra_matrix_sent) { - _prefill_default_batch(r_fill_state, command_num, *p_item); - - // keep track of the combined matrix on the CPU in parallel, in case we use large vertex format - RendererCanvasRender::Item::CommandTransform *transform = static_cast<RendererCanvasRender::Item::CommandTransform *>(command); - const Transform2D &extra_matrix = transform->xform; - r_fill_state.transform_combined = p_item->final_transform * extra_matrix; - } else { - // Extra matrix fast path. - // Instead of sending the command immediately, we store the modified transform (in combined) - // for software transform, and only flush this transform command if we NEED to (i.e. we want to - // render some default commands) - RendererCanvasRender::Item::CommandTransform *transform = static_cast<RendererCanvasRender::Item::CommandTransform *>(command); - const Transform2D &extra_matrix = transform->xform; - - if (r_fill_state.use_hardware_transform) { - // if we are using hardware transform mode, we have already sent the final transform, - // so we only want to software transform the extra matrix - r_fill_state.transform_combined = extra_matrix; - } else { - r_fill_state.transform_combined = p_item->final_transform * extra_matrix; - } - // after a transform command, always use some form of software transform (either the combined final + extra, or just the extra) - // until we flush this dirty extra matrix because we need to render default commands. - r_fill_state.transform_mode = _find_transform_mode(r_fill_state.transform_combined); - - // make a note of which command the dirty extra matrix is store in, so we can send it later - // if necessary - r_fill_state.transform_extra_command_number_p1 = command_num + 1; // plus 1 so we can test against zero - } - } break; - case RendererCanvasRender::Item::Command::TYPE_RECT: { - RendererCanvasRender::Item::CommandRect *rect = static_cast<RendererCanvasRender::Item::CommandRect *>(command); - - // unoptimized - could this be done once per batch / batch texture? - bool send_light_angles = rect->normal_map != RID(); - - bool buffer_full = false; - - // the template params must be explicit for compilation, - // this forces building the multiple versions of the function. - if (send_light_angles) { - buffer_full = _prefill_rect<true>(rect, r_fill_state, r_command_start, command_num, command_count, commands, p_item, multiply_final_modulate); - } else { - buffer_full = _prefill_rect<false>(rect, r_fill_state, r_command_start, command_num, command_count, commands, p_item, multiply_final_modulate); - } - - if (buffer_full) - return true; - - } break; - case RendererCanvasRender::Item::Command::TYPE_NINEPATCH: { - RendererCanvasRender::Item::CommandNinePatch *np = static_cast<RendererCanvasRender::Item::CommandNinePatch *>(command); - - if ((np->axis_x != VisualServer::NINE_PATCH_STRETCH) || (np->axis_y != VisualServer::NINE_PATCH_STRETCH)) { - // not accelerated - _prefill_default_batch(r_fill_state, command_num, *p_item); - continue; - } - - // unoptimized - could this be done once per batch / batch texture? - bool send_light_angles = np->normal_map != RID(); - - bool buffer_full = false; - - if (send_light_angles) - buffer_full = _prefill_ninepatch<true>(np, r_fill_state, r_command_start, command_num, command_count, p_item, multiply_final_modulate); - else - buffer_full = _prefill_ninepatch<false>(np, r_fill_state, r_command_start, command_num, command_count, p_item, multiply_final_modulate); - - if (buffer_full) - return true; - - } break; - - case RendererCanvasRender::Item::Command::TYPE_LINE: { - RendererCanvasRender::Item::CommandLine *line = static_cast<RendererCanvasRender::Item::CommandLine *>(command); - - if (line->width <= 1) { - bool buffer_full = _prefill_line(line, r_fill_state, r_command_start, command_num, command_count, p_item, multiply_final_modulate); - - if (buffer_full) - return true; - } else { - // not accelerated - _prefill_default_batch(r_fill_state, command_num, *p_item); - } - } break; - - case RendererCanvasRender::Item::Command::TYPE_POLYGON: { - RendererCanvasRender::Item::CommandPolygon *polygon = static_cast<RendererCanvasRender::Item::CommandPolygon *>(command); -#ifdef GLES_OVER_GL - // anti aliasing not accelerated .. it is problematic because it requires a 2nd line drawn around the outside of each - // poly, which would require either a second list of indices or a second list of vertices for this step - if (polygon->antialiased) { - // not accelerated - _prefill_default_batch(r_fill_state, command_num, *p_item); - } else { -#endif - // not using software skinning? - if (!bdata.settings_use_software_skinning && get_this()->state.using_skeleton) { - // not accelerated - _prefill_default_batch(r_fill_state, command_num, *p_item); - } else { - // unoptimized - could this be done once per batch / batch texture? - bool send_light_angles = polygon->normal_map != RID(); - - bool buffer_full = false; - - if (send_light_angles) { - // NYI - _prefill_default_batch(r_fill_state, command_num, *p_item); - //buffer_full = prefill_polygon<true>(polygon, r_fill_state, r_command_start, command_num, command_count, p_item, multiply_final_modulate); - } else - buffer_full = _prefill_polygon<false>(polygon, r_fill_state, r_command_start, command_num, command_count, p_item, multiply_final_modulate); - - if (buffer_full) - return true; - } // if not using hardware skinning path -#ifdef GLES_OVER_GL - } // if not anti-aliased poly -#endif - - } break; - } - } - - // VERY IMPORTANT to return where we got to, because this func may be called multiple - // times per item. - // Don't miss out on this step by calling return earlier in the function without setting r_command_start. - r_command_start = command_num; - - return false; -} - -PREAMBLE(void)::flush_render_batches(RendererCanvasRender::Item *p_first_item, RendererCanvasRender::Item *p_current_clip, bool &r_reclip, typename T_STORAGE::Material *p_material, uint32_t p_sequence_batch_type_flags) { - // some heuristic to decide whether to use colored verts. - // feel free to tweak this. - // this could use hysteresis, to prevent jumping between methods - // .. however probably not necessary - bdata.use_colored_vertices = false; - - RasterizerStorageCommon::FVF backup_fvf = bdata.fvf; - - // the batch type in this flush can override the fvf from the joined item. - // The joined item uses the material to determine fvf, assuming a rect... - // however with custom drawing, lines or polys may be drawn. - // lines contain no color (this is stored in the batch), and polys contain vertex and color only. - if (p_sequence_batch_type_flags & (RasterizerStorageCommon::BTF_LINE | RasterizerStorageCommon::BTF_LINE_AA)) { - // do nothing, use the default regular FVF - bdata.fvf = RasterizerStorageCommon::FVF_REGULAR; - } else { - // switch from regular to colored? - if (bdata.fvf == RasterizerStorageCommon::FVF_REGULAR) { - // only check whether to convert if there are quads (prevent divide by zero) - // and we haven't decided to prevent color baking (due to e.g. MODULATE - // being used in a shader) - if (bdata.total_quads && !(bdata.joined_item_batch_flags & RasterizerStorageCommon::PREVENT_COLOR_BAKING)) { - // minus 1 to prevent single primitives (ratio 1.0) always being converted to colored.. - // in that case it is slightly cheaper to just have the color as part of the batch - float ratio = (float)(bdata.total_color_changes - 1) / (float)bdata.total_quads; - - // use bigger than or equal so that 0.0 threshold can force always using colored verts - if (ratio >= bdata.settings_colored_vertex_format_threshold) { - bdata.use_colored_vertices = true; - bdata.fvf = RasterizerStorageCommon::FVF_COLOR; - } - } - - // if we used vertex colors - if (bdata.vertex_colors.size()) { - bdata.use_colored_vertices = true; - bdata.fvf = RasterizerStorageCommon::FVF_COLOR; - } - - // needs light angles? - if (bdata.use_light_angles) { - bdata.fvf = RasterizerStorageCommon::FVF_LIGHT_ANGLE; - } - } - - backup_fvf = bdata.fvf; - } // if everything else except lines - - // translate if required to larger FVFs - switch (bdata.fvf) { - case RasterizerStorageCommon::FVF_UNBATCHED: // should not happen - break; - case RasterizerStorageCommon::FVF_REGULAR: // no change - break; - case RasterizerStorageCommon::FVF_COLOR: { - // special case, where vertex colors are used (polys) - if (!bdata.vertex_colors.size()) - _translate_batches_to_larger_FVF<BatchVertexColored, false, false, false>(p_sequence_batch_type_flags); - else - // normal, reduce number of batches by baking batch colors - _translate_batches_to_vertex_colored_FVF(); - } break; - case RasterizerStorageCommon::FVF_LIGHT_ANGLE: - _translate_batches_to_larger_FVF<BatchVertexLightAngled, true, false, false>(p_sequence_batch_type_flags); - break; - case RasterizerStorageCommon::FVF_MODULATED: - _translate_batches_to_larger_FVF<BatchVertexModulated, true, true, false>(p_sequence_batch_type_flags); - break; - case RasterizerStorageCommon::FVF_LARGE: - _translate_batches_to_larger_FVF<BatchVertexLarge, true, true, true>(p_sequence_batch_type_flags); - break; - } - - // send buffers to opengl - get_this()->_batch_upload_buffers(); - - RendererCanvasRender::Item::Command *const *commands = p_first_item->commands.ptr(); - -#if defined(TOOLS_ENABLED) && defined(DEBUG_ENABLED) - if (bdata.diagnose_frame) { - diagnose_batches(commands); - } -#endif - - get_this()->render_batches(commands, p_current_clip, r_reclip, p_material); - - // if we overrode the fvf for lines, set it back to the joined item fvf - bdata.fvf = backup_fvf; - - // overwrite source buffers with garbage if error checking -#ifdef RASTERIZER_EXTRA_CHECKS - _debug_write_garbage(); -#endif -} - -#endif // godot 3 - PREAMBLE(void)::render_joined_item_commands(const BItemJoined &p_bij, RendererCanvasRender::Item *p_current_clip, bool &r_reclip, typename T_STORAGE::Material *p_material, bool p_lit) { RendererCanvasRender::Item *item = 0; RendererCanvasRender::Item *first_item = bdata.item_refs[p_bij.first_item_ref].item; @@ -2465,11 +1270,6 @@ PREAMBLE(void)::render_joined_item_commands(const BItemJoined &p_bij, RendererCa fill_state.final_modulate = item->final_modulate; } -#ifdef GODOT_3 - int command_count = item->commands.size(); - int command_start = 0; -#endif - // ONCE OFF fill state setup, that will be retained over multiple calls to // prefill_joined_item() fill_state.transform_combined = item->final_transform; @@ -2487,18 +1287,10 @@ PREAMBLE(void)::render_joined_item_commands(const BItemJoined &p_bij, RendererCa // so we can defer sending until we see a default command fill_state.transform_extra_command_number_p1 = 0; -#ifdef GODOT_4 RendererCanvasRender::Item::Command *current_command = item->commands; while (current_command) { -#else - while (command_start < command_count) { -#endif // fill as many batches as possible (until all done, or the vertex buffer is full) -#ifdef GODOT_4 bool bFull = get_this()->prefill_joined_item(fill_state, current_command, item, p_current_clip, r_reclip, p_material); -#else - bool bFull = get_this()->prefill_joined_item(fill_state, command_start, item, p_current_clip, r_reclip, p_material); -#endif if (bFull) { // always pass first item (commands for default are always first item) @@ -2521,16 +1313,12 @@ PREAMBLE(void)::render_joined_item_commands(const BItemJoined &p_bij, RendererCa } PREAMBLE(void)::_legacy_canvas_item_render_commands(RendererCanvasRender::Item *p_item, RendererCanvasRender::Item *p_current_clip, bool &r_reclip, typename T_STORAGE::Material *p_material) { -#ifdef GODOT_3 - int command_count = p_item->commands.size(); - RendererCanvasRender::Item::Command *const *commands = p_item->commands.ptr(); -#else // reuse the same list each time to prevent needless dynamic allocations unsigned int command_count = godot4_commands_to_vector(p_item->commands, bdata.command_shortlist); RendererCanvasRender::Item::Command *const *commands = nullptr; - if (command_count) + if (command_count) { commands = &bdata.command_shortlist[0]; -#endif + } // legacy .. just create one massive batch and render everything as before bdata.batches.reset(); @@ -2554,253 +1342,7 @@ PREAMBLE(void)::record_items(RendererCanvasRender::Item *p_item_list, int p_z) { } PREAMBLE(void)::join_sorted_items() { - /* - sort_items(); - - int z = GD_VS::CANVAS_ITEM_Z_MIN; - _render_item_state.item_group_z = z; - - for (int s = 0; s < bdata.sort_items.size(); s++) { - const BSortItem &si = bdata.sort_items[s]; - RendererCanvasRender::Item *ci = si.item; - - // change z? - if (si.z_index != z) { - z = si.z_index; - - // may not be required - _render_item_state.item_group_z = z; - - // if z ranged lights are present, sometimes we have to disable joining over z_indices. - // we do this here. - // Note this restriction may be able to be relaxed with light bitfields, investigate! - if (!bdata.join_across_z_indices) { - _render_item_state.join_batch_break = true; - } - } - - bool join; - - if (_render_item_state.join_batch_break) { - // always start a new batch for this item - join = false; - - // could be another batch break (i.e. prevent NEXT item from joining this) - // so we still need to run try_join_item - // even though we know join is false. - // also we need to run try_join_item for every item because it keeps the state up to date, - // if we didn't run it the state would be out of date. - get_this()->try_join_item(ci, _render_item_state, _render_item_state.join_batch_break); - } else { - join = get_this()->try_join_item(ci, _render_item_state, _render_item_state.join_batch_break); - } - - // assume the first item will always return no join - if (!join) { - _render_item_state.joined_item = bdata.items_joined.request_with_grow(); - _render_item_state.joined_item->first_item_ref = bdata.item_refs.size(); - _render_item_state.joined_item->num_item_refs = 1; - _render_item_state.joined_item->bounding_rect = ci->global_rect_cache; - _render_item_state.joined_item->z_index = z; - _render_item_state.joined_item->flags = bdata.joined_item_batch_flags; - - // we need some logic to prevent joining items that have vastly different batch types - _render_item_state.joined_item_batch_type_flags_prev = _render_item_state.joined_item_batch_type_flags_curr; - - // add the reference - BItemRef *r = bdata.item_refs.request_with_grow(); - r->item = ci; - // we are storing final_modulate in advance per item reference - // for baking into vertex colors. - // this may not be ideal... as we are increasing the size of item reference, - // but it is stupidly complex to calculate later, which would probably be slower. - r->final_modulate = _render_item_state.final_modulate; - } else { - RAST_DEBUG_ASSERT(_render_item_state.joined_item != 0); - _render_item_state.joined_item->num_item_refs += 1; - _render_item_state.joined_item->bounding_rect = _render_item_state.joined_item->bounding_rect.merge(ci->global_rect_cache); - - BItemRef *r = bdata.item_refs.request_with_grow(); - r->item = ci; - r->final_modulate = _render_item_state.final_modulate; - } - - } // for s through sort items -*/ -} - -#ifdef GODOT_3 -PREAMBLE(void)::sort_items() { - // turned off? - if (!bdata.settings_item_reordering_lookahead) { - return; - } - - for (int s = 0; s < bdata.sort_items.size() - 2; s++) { - if (sort_items_from(s)) { -#if defined(TOOLS_ENABLED) && defined(DEBUG_ENABLED) - bdata.stats_items_sorted++; -#endif - } - } -} - -PREAMBLE(bool)::_sort_items_match(const BSortItem &p_a, const BSortItem &p_b) const { - const RendererCanvasRender::Item *a = p_a.item; - const RendererCanvasRender::Item *b = p_b.item; - - if (b->commands.size() != 1) - return false; - - // tested outside function - // if (a->commands.size() != 1) - // return false; - - const RendererCanvasRender::Item::Command &cb = *b->commands[0]; - if (cb.type != RendererCanvasRender::Item::Command::TYPE_RECT) - return false; - - const RendererCanvasRender::Item::Command &ca = *a->commands[0]; - // tested outside function - // if (ca.type != Item::Command::TYPE_RECT) - // return false; - - const RendererCanvasRender::Item::CommandRect *rect_a = static_cast<const RendererCanvasRender::Item::CommandRect *>(&ca); - const RendererCanvasRender::Item::CommandRect *rect_b = static_cast<const RendererCanvasRender::Item::CommandRect *>(&cb); - - if (rect_a->texture != rect_b->texture) - return false; - - /* ALTERNATIVE APPROACH NOT LIMITED TO RECTS -const RendererCanvasRender::Item::Command &ca = *a->commands[0]; -const RendererCanvasRender::Item::Command &cb = *b->commands[0]; - -if (ca.type != cb.type) - return false; - -// do textures match? -switch (ca.type) -{ -default: - break; -case RendererCanvasRender::Item::Command::TYPE_RECT: - { - const RendererCanvasRender::Item::CommandRect *comm_a = static_cast<const RendererCanvasRender::Item::CommandRect *>(&ca); - const RendererCanvasRender::Item::CommandRect *comm_b = static_cast<const RendererCanvasRender::Item::CommandRect *>(&cb); - if (comm_a->texture != comm_b->texture) - return false; - } - break; -case RendererCanvasRender::Item::Command::TYPE_POLYGON: - { - const RendererCanvasRender::Item::CommandPolygon *comm_a = static_cast<const RendererCanvasRender::Item::CommandPolygon *>(&ca); - const RendererCanvasRender::Item::CommandPolygon *comm_b = static_cast<const RendererCanvasRender::Item::CommandPolygon *>(&cb); - if (comm_a->texture != comm_b->texture) - return false; - } - break; -} -*/ - - return true; -} - -PREAMBLE(bool)::sort_items_from(int p_start) { -#if defined(TOOLS_ENABLED) && defined(DEBUG_ENABLED) - ERR_FAIL_COND_V((p_start + 1) >= bdata.sort_items.size(), false) -#endif - - const BSortItem &start = bdata.sort_items[p_start]; - int start_z = start.z_index; - - // check start is the right type for sorting - if (start.item->commands.size() != 1) { - return false; - } - const RendererCanvasRender::Item::Command &command_start = *start.item->commands[0]; - if (command_start.type != RendererCanvasRender::Item::Command::TYPE_RECT) { - return false; - } - - BSortItem &second = bdata.sort_items[p_start + 1]; - if (second.z_index != start_z) { - // no sorting across z indices (for now) - return false; - } - - // if the neighbours are already a good match - if (_sort_items_match(start, second)) // order is crucial, start first - { - return false; - } - - // local cached aabb - Rect2 second_AABB = second.item->global_rect_cache; - - // if the start and 2nd items overlap, can do no more - if (start.item->global_rect_cache.intersects(second_AABB)) { - return false; - } - - // which neighbour to test - int test_last = 2 + bdata.settings_item_reordering_lookahead; - for (int test = 2; test < test_last; test++) { - int test_sort_item_id = p_start + test; - - // if we've got to the end of the list, can't sort any more, give up - if (test_sort_item_id >= bdata.sort_items.size()) { - return false; - } - - BSortItem *test_sort_item = &bdata.sort_items[test_sort_item_id]; - - // across z indices? - if (test_sort_item->z_index != start_z) { - return false; - } - - RendererCanvasRender::Item *test_item = test_sort_item->item; - - // if the test item overlaps the second item, we can't swap, AT ALL - // because swapping an item OVER this one would cause artefacts - if (second_AABB.intersects(test_item->global_rect_cache)) { - return false; - } - - // do they match? - if (!_sort_items_match(start, *test_sort_item)) // order is crucial, start first - { - continue; - } - - // we can only swap if there are no AABB overlaps with sandwiched neighbours - bool ok = true; - - // start from 2, no need to check 1 as the second has already been checked against this item - // in the intersection test above - for (int sn = 2; sn < test; sn++) { - BSortItem *sandwich_neighbour = &bdata.sort_items[p_start + sn]; - if (test_item->global_rect_cache.intersects(sandwich_neighbour->item->global_rect_cache)) { - ok = false; - break; - } - } - if (!ok) { - continue; - } - - // it is ok to exchange them! - BSortItem temp; - temp.assign(second); - second.assign(*test_sort_item); - test_sort_item->assign(temp); - - return true; - } // for test - - return false; } -#endif // godot 3 PREAMBLE(void)::_software_transform_vertex(BatchVector2 &r_v, const Transform2D &p_tr) const { Vector2 vc(r_v.x, r_v.y); @@ -3011,117 +1553,6 @@ PREAMBLE(bool)::_disallow_item_join_if_batch_types_too_different(RenderItemState return disallow; } -#ifdef GODOT_3 -PREAMBLE(bool)::_detect_item_batch_break(RenderItemState &r_ris, RendererCanvasRender::Item *p_ci, bool &r_batch_break) { - int command_count = p_ci->commands.size(); - - // Any item that contains commands that are default - // (i.e. not handled by software transform and the batching renderer) should not be joined. - - // ALSO batched types that differ in what the vertex format is needed to be should not be - // joined. - - // In order to work this out, it does a lookahead through the commands, - // which could potentially be very expensive. As such it makes sense to put a limit on this - // to some small number, which will catch nearly all cases which need joining, - // but not be overly expensive in the case of items with large numbers of commands. - - // It is hard to know what this number should be, empirically, - // and this has not been fully investigated. It works to join single sprite items when set to 1 or above. - // Note that there is a cost to increasing this because it has to look in advance through - // the commands. - // On the other hand joining items where possible will usually be better up to a certain - // number where the cost of software transform is higher than separate drawcalls with hardware - // transform. - - // if there are more than this number of commands in the item, we - // don't allow joining (separate state changes, and hardware transform) - // This is set to quite a conservative (low) number until investigated properly. - // const int MAX_JOIN_ITEM_COMMANDS = 16; - - r_ris.joined_item_batch_type_flags_curr = 0; - - if (command_count > bdata.settings_max_join_item_commands) { - return true; - } else { - RendererCanvasRender::Item::Command *const *commands = p_ci->commands.ptr(); - - // run through the commands looking for one that could prevent joining - for (int command_num = 0; command_num < command_count; command_num++) { - RendererCanvasRender::Item::Command *command = commands[command_num]; - RAST_DEBUG_ASSERT(command); - - switch (command->type) { - default: { - //r_batch_break = true; - return true; - } break; - case RendererCanvasRender::Item::Command::TYPE_LINE: { - // special case, only batches certain lines - RendererCanvasRender::Item::CommandLine *line = static_cast<RendererCanvasRender::Item::CommandLine *>(command); - - if (line->width > 1) { - //r_batch_break = true; - return true; - } - - if (_disallow_item_join_if_batch_types_too_different(r_ris, RasterizerStorageCommon::BTF_LINE | RasterizerStorageCommon::BTF_LINE_AA)) { - return true; - } - } break; - case RendererCanvasRender::Item::Command::TYPE_POLYGON: { - // only allow polygons to join if they aren't skeleton - RendererCanvasRender::Item::CommandPolygon *poly = static_cast<RendererCanvasRender::Item::CommandPolygon *>(command); - -#ifdef GLES_OVER_GL - // anti aliasing not accelerated - if (poly->antialiased) - return true; -#endif - - // light angles not yet implemented, treat as default - if (poly->normal_map != RID()) - return true; - - if (!get_this()->bdata.settings_use_software_skinning && poly->bones.size()) - return true; - - if (_disallow_item_join_if_batch_types_too_different(r_ris, RasterizerStorageCommon::BTF_POLY)) { - //r_batch_break = true; - return true; - } - } break; - case RendererCanvasRender::Item::Command::TYPE_RECT: { - if (_disallow_item_join_if_batch_types_too_different(r_ris, RasterizerStorageCommon::BTF_RECT)) - return true; - } break; - case RendererCanvasRender::Item::Command::TYPE_NINEPATCH: { - // do not handle tiled ninepatches, these can't be batched and need to use legacy method - RendererCanvasRender::Item::CommandNinePatch *np = static_cast<RendererCanvasRender::Item::CommandNinePatch *>(command); - if ((np->axis_x != VisualServer::NINE_PATCH_STRETCH) || (np->axis_y != VisualServer::NINE_PATCH_STRETCH)) - return true; - - if (_disallow_item_join_if_batch_types_too_different(r_ris, RasterizerStorageCommon::BTF_RECT)) - return true; - } break; - case RendererCanvasRender::Item::Command::TYPE_TRANSFORM: { - // compatible with all types - } break; - } // switch - - } // for through commands - - } // else - - // special case, back buffer copy, so don't join - if (p_ci->copy_back_buffer) { - return true; - } - - return false; -} -#endif - #undef PREAMBLE #undef T_PREAMBLE #undef C_PREAMBLE diff --git a/drivers/gles2/rasterizer_canvas_gles2.cpp b/drivers/opengl/rasterizer_canvas_opengl.cpp index ef4159563f..41d68e5bc9 100644 --- a/drivers/gles2/rasterizer_canvas_gles2.cpp +++ b/drivers/opengl/rasterizer_canvas_opengl.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* rasterizer_canvas_gles2.cpp */ +/* rasterizer_canvas_opengl.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,22 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "rasterizer_canvas_gles2.h" -#include "drivers/gles_common/rasterizer_platforms.h" -#ifdef GLES2_BACKEND_ENABLED +#include "rasterizer_canvas_opengl.h" +#include "drivers/opengl/rasterizer_platforms.h" +#ifdef OPENGL_BACKEND_ENABLED #include "core/os/os.h" -#include "drivers/gles_common/rasterizer_asserts.h" -#include "rasterizer_scene_gles2.h" -#include "rasterizer_storage_gles2.h" +#include "drivers/opengl/rasterizer_asserts.h" +#include "rasterizer_scene_opengl.h" +#include "rasterizer_storage_opengl.h" -#ifdef GODOT_4 #include "core/config/project_settings.h" #include "servers/rendering/rendering_server_default.h" -#else -#include "core/project_settings.h" -#include "servers/visual/visual_server_raster.h" -#endif //static const GLenum gl_primitive[] = { // GL_POINTS, @@ -56,7 +51,7 @@ //}; #if 0 -void RasterizerCanvasGLES2::_batch_upload_buffers() { +void RasterizerCanvasOpenGL::_batch_upload_buffers() { // noop? if (!bdata.vertices.size()) return; @@ -98,7 +93,7 @@ void RasterizerCanvasGLES2::_batch_upload_buffers() { glBindBuffer(GL_ARRAY_BUFFER, 0); } -void RasterizerCanvasGLES2::_batch_render_lines(const Batch &p_batch, RasterizerStorageGLES2::Material *p_material, bool p_anti_alias) { +void RasterizerCanvasOpenGL::_batch_render_lines(const Batch &p_batch, RasterizerStorageOpenGL::Material *p_material, bool p_anti_alias) { _set_texture_rect_mode(false); if (state.canvas_shader.bind()) { @@ -108,8 +103,8 @@ void RasterizerCanvasGLES2::_batch_render_lines(const Batch &p_batch, Rasterizer _bind_canvas_texture(RID(), RID()); - glDisableVertexAttribArray(GD_VS::ARRAY_COLOR); - glVertexAttrib4fv(GD_VS::ARRAY_COLOR, (float *)&p_batch.color); + glDisableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttrib4fv(RS::ARRAY_COLOR, (float *)&p_batch.color); #ifdef GLES_OVER_GL if (p_anti_alias) @@ -123,9 +118,9 @@ void RasterizerCanvasGLES2::_batch_render_lines(const Batch &p_batch, Rasterizer glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bdata.gl_index_buffer); uint64_t pointer = 0; - glVertexAttribPointer(GD_VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof_vert, (const void *)pointer); + glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof_vert, (const void *)pointer); - glDisableVertexAttribArray(GD_VS::ARRAY_TEX_UV); + glDisableVertexAttribArray(RS::ARRAY_TEX_UV); int64_t offset = p_batch.first_vert; // 6 inds per quad at 2 bytes each @@ -144,7 +139,7 @@ void RasterizerCanvasGLES2::_batch_render_lines(const Batch &p_batch, Rasterizer #endif } -void RasterizerCanvasGLES2::_batch_render_generic(const Batch &p_batch, RasterizerStorageGLES2::Material *p_material) { +void RasterizerCanvasOpenGL::_batch_render_generic(const Batch &p_batch, RasterizerStorageOpenGL::Material *p_material) { ERR_FAIL_COND(p_batch.num_commands <= 0); const bool &use_light_angles = bdata.use_light_angles; @@ -188,7 +183,7 @@ void RasterizerCanvasGLES2::_batch_render_generic(const Batch &p_batch, Rasteriz // force repeat is set if non power of 2 texture, and repeat is needed if hardware doesn't support npot if (tex.tile_mode == BatchTex::TILE_FORCE_REPEAT) { - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_FORCE_REPEAT, true); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_FORCE_REPEAT, true); } if (state.canvas_shader.bind()) { @@ -203,43 +198,43 @@ void RasterizerCanvasGLES2::_batch_render_generic(const Batch &p_batch, Rasteriz glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bdata.gl_index_buffer); uint64_t pointer = 0; - glVertexAttribPointer(GD_VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof_vert, (const void *)pointer); + glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof_vert, (const void *)pointer); // always send UVs, even within a texture specified because a shader can still use UVs - glEnableVertexAttribArray(GD_VS::ARRAY_TEX_UV); - glVertexAttribPointer(GD_VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (2 * 4))); + glEnableVertexAttribArray(RS::ARRAY_TEX_UV); + glVertexAttribPointer(RS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (2 * 4))); // color if (!colored_verts) { - glDisableVertexAttribArray(GD_VS::ARRAY_COLOR); - glVertexAttrib4fv(GD_VS::ARRAY_COLOR, p_batch.color.get_data()); + glDisableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttrib4fv(RS::ARRAY_COLOR, p_batch.color.get_data()); } else { - glEnableVertexAttribArray(GD_VS::ARRAY_COLOR); - glVertexAttribPointer(GD_VS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (4 * 4))); + glEnableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttribPointer(RS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (4 * 4))); } if (use_light_angles) { - glEnableVertexAttribArray(GD_VS::ARRAY_TANGENT); - glVertexAttribPointer(GD_VS::ARRAY_TANGENT, 1, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (8 * 4))); + glEnableVertexAttribArray(RS::ARRAY_TANGENT); + glVertexAttribPointer(RS::ARRAY_TANGENT, 1, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (8 * 4))); } if (use_modulate) { - glEnableVertexAttribArray(GD_VS::ARRAY_TEX_UV2); - glVertexAttribPointer(GD_VS::ARRAY_TEX_UV2, 4, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (9 * 4))); + glEnableVertexAttribArray(RS::ARRAY_TEX_UV2); + glVertexAttribPointer(RS::ARRAY_TEX_UV2, 4, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (9 * 4))); } if (use_large_verts) { - glEnableVertexAttribArray(GD_VS::ARRAY_BONES); - glVertexAttribPointer(GD_VS::ARRAY_BONES, 2, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (13 * 4))); - glEnableVertexAttribArray(GD_VS::ARRAY_WEIGHTS); - glVertexAttribPointer(GD_VS::ARRAY_WEIGHTS, 4, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (15 * 4))); + glEnableVertexAttribArray(RS::ARRAY_BONES); + glVertexAttribPointer(RS::ARRAY_BONES, 2, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (13 * 4))); + glEnableVertexAttribArray(RS::ARRAY_WEIGHTS); + glVertexAttribPointer(RS::ARRAY_WEIGHTS, 4, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (15 * 4))); } // We only want to set the GL wrapping mode if the texture is not already tiled (i.e. set in Import). // This is an optimization left over from the legacy renderer. // If we DID set tiling in the API, and reverted to clamped, then the next draw using this texture // may use clamped mode incorrectly. - bool tex_is_already_tiled = tex.flags & RasterizerStorageGLES2::TEXTURE_FLAG_REPEAT; + bool tex_is_already_tiled = tex.flags & RasterizerStorageOpenGL::TEXTURE_FLAG_REPEAT; if (tex.tile_mode == BatchTex::TILE_NORMAL) { // if the texture is imported as tiled, no need to set GL state, as it will already be bound with repeat @@ -253,7 +248,7 @@ void RasterizerCanvasGLES2::_batch_render_generic(const Batch &p_batch, Rasteriz // could use a cast but this might be unsafe in future Vector2 tps; tex.tex_pixel_size.to(tps); - state.canvas_shader.set_uniform(CanvasShaderGLES2::COLOR_TEXPIXEL_SIZE, tps); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::COLOR_TEXPIXEL_SIZE, tps); switch (p_batch.type) { default: { @@ -277,7 +272,7 @@ void RasterizerCanvasGLES2::_batch_render_generic(const Batch &p_batch, Rasteriz switch (tex.tile_mode) { case BatchTex::TILE_FORCE_REPEAT: { - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_FORCE_REPEAT, false); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_FORCE_REPEAT, false); } break; case BatchTex::TILE_NORMAL: { // if the texture is imported as tiled, no need to revert GL state @@ -291,19 +286,19 @@ void RasterizerCanvasGLES2::_batch_render_generic(const Batch &p_batch, Rasteriz } // could these have ifs? - glDisableVertexAttribArray(GD_VS::ARRAY_TEX_UV); - glDisableVertexAttribArray(GD_VS::ARRAY_COLOR); - glDisableVertexAttribArray(GD_VS::ARRAY_TANGENT); - glDisableVertexAttribArray(GD_VS::ARRAY_TEX_UV2); - glDisableVertexAttribArray(GD_VS::ARRAY_BONES); - glDisableVertexAttribArray(GD_VS::ARRAY_WEIGHTS); + glDisableVertexAttribArray(RS::ARRAY_TEX_UV); + glDisableVertexAttribArray(RS::ARRAY_COLOR); + glDisableVertexAttribArray(RS::ARRAY_TANGENT); + glDisableVertexAttribArray(RS::ARRAY_TEX_UV2); + glDisableVertexAttribArray(RS::ARRAY_BONES); + glDisableVertexAttribArray(RS::ARRAY_WEIGHTS); // may not be necessary .. state change optimization still TODO glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } #endif -void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Item *p_current_clip, bool &r_reclip, RasterizerStorageGLES2::Material *p_material) { +void RasterizerCanvasOpenGL::render_batches(Item::Command *const *p_commands, Item *p_current_clip, bool &r_reclip, RasterizerStorageOpenGL::Material *p_material) { int num_batches = bdata.batches.size(); for (int batch_num = 0; batch_num < num_batches; batch_num++) { @@ -342,10 +337,10 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite _bind_canvas_texture(RID(), RID()); - glDisableVertexAttribArray(GD_VS::ARRAY_COLOR); - glVertexAttrib4fv(GD_VS::ARRAY_COLOR, line->color.components); + glDisableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttrib4fv(RS::ARRAY_COLOR, line->color.components); - state.canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX, state.uniforms.modelview_matrix); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::MODELVIEW_MATRIX, state.uniforms.modelview_matrix); if (line->width <= 1) { Vector2 verts[2] = { @@ -407,8 +402,8 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite case Item::Command::TYPE_RECT: { Item::CommandRect *r = static_cast<Item::CommandRect *>(command); - glDisableVertexAttribArray(GD_VS::ARRAY_COLOR); - glVertexAttrib4fv(GD_VS::ARRAY_COLOR, r->modulate.components); + glDisableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttrib4fv(RS::ARRAY_COLOR, r->modulate.components); bool can_tile = true; @@ -418,7 +413,7 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite // very inefficient, improve this if (r->texture.is_valid()) { - RasterizerStorageGLES2::Texture *texture = storage->texture_owner.getornull(r->texture); + RasterizerStorageOpenGL::Texture *texture = storage->texture_owner.get_or_null(r->texture); if (texture) { if (texture->is_upside_down()) @@ -429,13 +424,13 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite if (r->texture.is_valid() && r->flags & CANVAS_RECT_TILE && !storage->config.support_npot_repeat_mipmap) { // workaround for when setting tiling does not work due to hardware limitation - RasterizerStorageGLES2::Texture *texture = storage->texture_owner.getornull(r->texture); + RasterizerStorageOpenGL::Texture *texture = storage->texture_owner.get_or_null(r->texture); if (texture) { texture = texture->get_ptr(); if (next_power_of_2(texture->alloc_width) != (unsigned int)texture->alloc_width && next_power_of_2(texture->alloc_height) != (unsigned int)texture->alloc_height) { - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_FORCE_REPEAT, true); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_FORCE_REPEAT, true); can_tile = false; } } @@ -480,8 +475,8 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite } // FTODO - //RasterizerStorageGLES2::Texture *texture = _bind_canvas_texture(r->texture, r->normal_map); - RasterizerStorageGLES2::Texture *texture = _bind_canvas_texture(r->texture, RID()); + //RasterizerStorageOpenGL::Texture *texture = _bind_canvas_texture(r->texture, r->normal_map); + RasterizerStorageOpenGL::Texture *texture = _bind_canvas_texture(r->texture, RID()); if (texture) { Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height); @@ -515,11 +510,11 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite flip_v = !flip_v; } - state.canvas_shader.set_uniform(CanvasShaderGLES2::COLOR_TEXPIXEL_SIZE, texpixel_size); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::COLOR_TEXPIXEL_SIZE, texpixel_size); bool untile = false; - if (can_tile && r->flags & CANVAS_RECT_TILE && !(texture->flags & RasterizerStorageGLES2::TEXTURE_FLAG_REPEAT)) { + if (can_tile && r->flags & CANVAS_RECT_TILE && !(texture->flags & RasterizerStorageOpenGL::TEXTURE_FLAG_REPEAT)) { texture->GLSetRepeat(RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED); untile = true; } @@ -563,7 +558,7 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite Vector2(1.0, 0.0), }; - state.canvas_shader.set_uniform(CanvasShaderGLES2::COLOR_TEXPIXEL_SIZE, Vector2()); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::COLOR_TEXPIXEL_SIZE, Vector2()); _draw_gui_primitive(4, points, NULL, uvs); } @@ -579,8 +574,8 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite } // FTODO - //RasterizerStorageGLES2::Texture *tex = _bind_canvas_texture(r->texture, r->normal_map); - RasterizerStorageGLES2::Texture *tex = _bind_canvas_texture(r->texture, RID()); + //RasterizerStorageOpenGL::Texture *tex = _bind_canvas_texture(r->texture, r->normal_map); + RasterizerStorageOpenGL::Texture *tex = _bind_canvas_texture(r->texture, RID()); if (!tex) { Rect2 dst_rect = Rect2(r->rect.position, r->rect.size); @@ -594,15 +589,15 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite dst_rect.size.height *= -1; } - state.canvas_shader.set_uniform(CanvasShaderGLES2::DST_RECT, Color(dst_rect.position.x, dst_rect.position.y, dst_rect.size.x, dst_rect.size.y)); - state.canvas_shader.set_uniform(CanvasShaderGLES2::SRC_RECT, Color(0, 0, 1, 1)); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::DST_RECT, Color(dst_rect.position.x, dst_rect.position.y, dst_rect.size.x, dst_rect.size.y)); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::SRC_RECT, Color(0, 0, 1, 1)); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); storage->info.render._2d_draw_call_count++; } else { bool untile = false; - if (can_tile && r->flags & CANVAS_RECT_TILE && !(tex->flags & RasterizerStorageGLES2::TEXTURE_FLAG_REPEAT)) { + if (can_tile && r->flags & CANVAS_RECT_TILE && !(tex->flags & RasterizerStorageOpenGL::TEXTURE_FLAG_REPEAT)) { tex->GLSetRepeat(RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED); untile = true; } @@ -633,10 +628,10 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite dst_rect.size.x *= -1; // Encoding in the dst_rect.z uniform } - state.canvas_shader.set_uniform(CanvasShaderGLES2::COLOR_TEXPIXEL_SIZE, texpixel_size); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::COLOR_TEXPIXEL_SIZE, texpixel_size); - state.canvas_shader.set_uniform(CanvasShaderGLES2::DST_RECT, Color(dst_rect.position.x, dst_rect.position.y, dst_rect.size.x, dst_rect.size.y)); - state.canvas_shader.set_uniform(CanvasShaderGLES2::SRC_RECT, Color(src_rect.position.x, src_rect.position.y, src_rect.size.x, src_rect.size.y)); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::DST_RECT, Color(dst_rect.position.x, dst_rect.position.y, dst_rect.size.x, dst_rect.size.y)); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::SRC_RECT, Color(src_rect.position.x, src_rect.position.y, src_rect.size.x, src_rect.size.y)); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); storage->info.render._2d_draw_call_count++; @@ -650,7 +645,7 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_FORCE_REPEAT, false); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_FORCE_REPEAT, false); } break; case Item::Command::TYPE_NINEPATCH: { @@ -662,16 +657,16 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite state.canvas_shader.use_material((void *)p_material); } - glDisableVertexAttribArray(GD_VS::ARRAY_COLOR); - glVertexAttrib4fv(GD_VS::ARRAY_COLOR, np->color.components); + glDisableVertexAttribArray(RS::ARRAY_COLOR); + glVertexAttrib4fv(RS::ARRAY_COLOR, np->color.components); // FTODO - //RasterizerStorageGLES2::Texture *tex = _bind_canvas_texture(np->texture, np->normal_map); - RasterizerStorageGLES2::Texture *tex = _bind_canvas_texture(np->texture, RID()); + //RasterizerStorageOpenGL::Texture *tex = _bind_canvas_texture(np->texture, np->normal_map); + RasterizerStorageOpenGL::Texture *tex = _bind_canvas_texture(np->texture, RID()); if (!tex) { // FIXME: Handle textureless ninepatch gracefully - WARN_PRINT("NinePatch without texture not supported yet in GLES2 backend, skipping."); + WARN_PRINT("NinePatch without texture not supported yet in OpenGL backend, skipping."); continue; } if (tex->width == 0 || tex->height == 0) { @@ -681,8 +676,8 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite Size2 texpixel_size(1.0 / tex->width, 1.0 / tex->height); - // state.canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX, state.uniforms.modelview_matrix); - state.canvas_shader.set_uniform(CanvasShaderGLES2::COLOR_TEXPIXEL_SIZE, texpixel_size); + // state.canvas_shader.set_uniform(CanvasShaderOpenGL::MODELVIEW_MATRIX, state.uniforms.modelview_matrix); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::COLOR_TEXPIXEL_SIZE, texpixel_size); Rect2 source = np->source; if (source.size.x == 0 && source.size.y == 0) { @@ -814,11 +809,11 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.ninepatch_elements); - glEnableVertexAttribArray(GD_VS::ARRAY_VERTEX); - glEnableVertexAttribArray(GD_VS::ARRAY_TEX_UV); + glEnableVertexAttribArray(RS::ARRAY_VERTEX); + glEnableVertexAttribArray(RS::ARRAY_TEX_UV); - glVertexAttribPointer(GD_VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), NULL); - glVertexAttribPointer(GD_VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), CAST_INT_TO_UCHAR_PTR((sizeof(float) * 2))); + glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), NULL); + glVertexAttribPointer(RS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), CAST_INT_TO_UCHAR_PTR((sizeof(float) * 2))); glDrawElements(GL_TRIANGLES, 18 * 3 - (np->draw_center ? 0 : 6), GL_UNSIGNED_BYTE, NULL); @@ -881,17 +876,17 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite state.canvas_shader.use_material((void *)p_material); } - RasterizerStorageGLES2::Texture *texture = _bind_canvas_texture(mesh->texture, mesh->normal_map); + RasterizerStorageOpenGL::Texture *texture = _bind_canvas_texture(mesh->texture, mesh->normal_map); if (texture) { Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height); - state.canvas_shader.set_uniform(CanvasShaderGLES2::COLOR_TEXPIXEL_SIZE, texpixel_size); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::COLOR_TEXPIXEL_SIZE, texpixel_size); } - RasterizerStorageGLES2::Mesh *mesh_data = storage->mesh_owner.getornull(mesh->mesh); + RasterizerStorageOpenGL::Mesh *mesh_data = storage->mesh_owner.get_or_null(mesh->mesh); if (mesh_data) { for (int j = 0; j < mesh_data->surfaces.size(); j++) { - RasterizerStorageGLES2::Surface *s = mesh_data->surfaces[j]; + RasterizerStorageOpenGL::Surface *s = mesh_data->surfaces[j]; // materials are ignored in 2D meshes, could be added but many things (ie, lighting mode, reading from screen, etc) would break as they are not meant be set up at this point of drawing glBindBuffer(GL_ARRAY_BUFFER, s->vertex_id); @@ -900,18 +895,18 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->index_id); } - for (int k = 0; k < GD_VS::ARRAY_MAX - 1; k++) { + for (int k = 0; k < RS::ARRAY_MAX - 1; k++) { if (s->attribs[k].enabled) { glEnableVertexAttribArray(k); glVertexAttribPointer(s->attribs[k].index, s->attribs[k].size, s->attribs[k].type, s->attribs[k].normalized, s->attribs[k].stride, CAST_INT_TO_UCHAR_PTR(s->attribs[k].offset)); } else { glDisableVertexAttribArray(k); switch (k) { - case GD_VS::ARRAY_NORMAL: { - glVertexAttrib4f(GD_VS::ARRAY_NORMAL, 0.0, 0.0, 1, 1); + case RS::ARRAY_NORMAL: { + glVertexAttrib4f(RS::ARRAY_NORMAL, 0.0, 0.0, 1, 1); } break; - case GD_VS::ARRAY_COLOR: { - glVertexAttrib4f(GD_VS::ARRAY_COLOR, 1, 1, 1, 1); + case RS::ARRAY_COLOR: { + glVertexAttrib4f(RS::ARRAY_COLOR, 1, 1, 1, 1); } break; default: { @@ -927,7 +922,7 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite } } - for (int j = 1; j < GD_VS::ARRAY_MAX - 1; j++) { + for (int j = 1; j < RS::ARRAY_MAX - 1; j++) { glDisableVertexAttribArray(j); } } @@ -937,18 +932,18 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite case Item::Command::TYPE_MULTIMESH: { Item::CommandMultiMesh *mmesh = static_cast<Item::CommandMultiMesh *>(command); - RasterizerStorageGLES2::MultiMesh *multi_mesh = storage->multimesh_owner.getornull(mmesh->multimesh); + RasterizerStorageOpenGL::MultiMesh *multi_mesh = storage->multimesh_owner.get_or_null(mmesh->multimesh); if (!multi_mesh) break; - RasterizerStorageGLES2::Mesh *mesh_data = storage->mesh_owner.getornull(multi_mesh->mesh); + RasterizerStorageOpenGL::Mesh *mesh_data = storage->mesh_owner.get_or_null(multi_mesh->mesh); if (!mesh_data) break; - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_INSTANCE_CUSTOM, multi_mesh->custom_data_format != GD_VS::MULTIMESH_CUSTOM_DATA_NONE); - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_INSTANCING, true); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_INSTANCE_CUSTOM, multi_mesh->custom_data_format != RS::MULTIMESH_CUSTOM_DATA_NONE); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_INSTANCING, true); _set_texture_rect_mode(false); if (state.canvas_shader.bind()) { @@ -956,11 +951,11 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite state.canvas_shader.use_material((void *)p_material); } - RasterizerStorageGLES2::Texture *texture = _bind_canvas_texture(mmesh->texture, mmesh->normal_map); + RasterizerStorageOpenGL::Texture *texture = _bind_canvas_texture(mmesh->texture, mmesh->normal_map); if (texture) { Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height); - state.canvas_shader.set_uniform(CanvasShaderGLES2::COLOR_TEXPIXEL_SIZE, texpixel_size); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::COLOR_TEXPIXEL_SIZE, texpixel_size); } //reset shader and force rebind @@ -981,7 +976,7 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite const float *base_buffer = multi_mesh->data.ptr(); for (int j = 0; j < mesh_data->surfaces.size(); j++) { - RasterizerStorageGLES2::Surface *s = mesh_data->surfaces[j]; + RasterizerStorageOpenGL::Surface *s = mesh_data->surfaces[j]; // materials are ignored in 2D meshes, could be added but many things (ie, lighting mode, reading from screen, etc) would break as they are not meant be set up at this point of drawing //bind buffers for mesh surface @@ -991,18 +986,18 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->index_id); } - for (int k = 0; k < GD_VS::ARRAY_MAX - 1; k++) { + for (int k = 0; k < RS::ARRAY_MAX - 1; k++) { if (s->attribs[k].enabled) { glEnableVertexAttribArray(k); glVertexAttribPointer(s->attribs[k].index, s->attribs[k].size, s->attribs[k].type, s->attribs[k].normalized, s->attribs[k].stride, CAST_INT_TO_UCHAR_PTR(s->attribs[k].offset)); } else { glDisableVertexAttribArray(k); switch (k) { - case GD_VS::ARRAY_NORMAL: { - glVertexAttrib4f(GD_VS::ARRAY_NORMAL, 0.0, 0.0, 1, 1); + case RS::ARRAY_NORMAL: { + glVertexAttrib4f(RS::ARRAY_NORMAL, 0.0, 0.0, 1, 1); } break; - case GD_VS::ARRAY_COLOR: { - glVertexAttrib4f(GD_VS::ARRAY_COLOR, 1, 1, 1, 1); + case RS::ARRAY_COLOR: { + glVertexAttrib4f(RS::ARRAY_COLOR, 1, 1, 1, 1); } break; default: { @@ -1017,7 +1012,7 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite { glVertexAttrib4fv(INSTANCE_ATTRIB_BASE + 0, &buffer[0]); glVertexAttrib4fv(INSTANCE_ATTRIB_BASE + 1, &buffer[4]); - if (multi_mesh->transform_format == GD_VS::MULTIMESH_TRANSFORM_3D) { + if (multi_mesh->transform_format == RS::MULTIMESH_TRANSFORM_3D) { glVertexAttrib4fv(INSTANCE_ATTRIB_BASE + 2, &buffer[8]); } else { glVertexAttrib4f(INSTANCE_ATTRIB_BASE + 2, 0.0, 0.0, 1.0, 0.0); @@ -1025,7 +1020,7 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite } if (multi_mesh->color_floats) { - if (multi_mesh->color_format == GD_VS::MULTIMESH_COLOR_8BIT) { + if (multi_mesh->color_format == RS::MULTIMESH_COLOR_8BIT) { uint8_t *color_data = (uint8_t *)(buffer + color_ofs); glVertexAttrib4f(INSTANCE_ATTRIB_BASE + 3, color_data[0] / 255.0, color_data[1] / 255.0, color_data[2] / 255.0, color_data[3] / 255.0); } else { @@ -1036,7 +1031,7 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite } if (multi_mesh->custom_data_floats) { - if (multi_mesh->custom_data_format == GD_VS::MULTIMESH_CUSTOM_DATA_8BIT) { + if (multi_mesh->custom_data_format == RS::MULTIMESH_CUSTOM_DATA_8BIT) { uint8_t *custom_data = (uint8_t *)(buffer + custom_data_ofs); glVertexAttrib4f(INSTANCE_ATTRIB_BASE + 4, custom_data[0] / 255.0, custom_data[1] / 255.0, custom_data[2] / 255.0, custom_data[3] / 255.0); } else { @@ -1055,8 +1050,8 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite // LIGHT ANGLE PR replaced USE_INSTANCE_CUSTOM line with below .. think it was a typo, // but just in case, made this note. //_set_texture_rect_mode(false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_INSTANCE_CUSTOM, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_INSTANCING, false); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_INSTANCE_CUSTOM, false); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_INSTANCING, false); storage->info.render._2d_draw_call_count++; } break; @@ -1122,11 +1117,11 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite ERR_CONTINUE(primitive->points.size() < 1); - RasterizerStorageGLES2::Texture *texture = _bind_canvas_texture(primitive->texture, primitive->normal_map); + RasterizerStorageOpenGL::Texture *texture = _bind_canvas_texture(primitive->texture, primitive->normal_map); if (texture) { Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height); - state.canvas_shader.set_uniform(CanvasShaderGLES2::COLOR_TEXPIXEL_SIZE, texpixel_size); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::COLOR_TEXPIXEL_SIZE, texpixel_size); } // we need a temporary because this must be nulled out @@ -1134,10 +1129,10 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite const Color *colors = primitive->colors.ptr(); if (primitive->colors.size() == 1 && primitive->points.size() > 1) { Color c = primitive->colors[0]; - glVertexAttrib4f(GD_VS::ARRAY_COLOR, c.r, c.g, c.b, c.a); + glVertexAttrib4f(RS::ARRAY_COLOR, c.r, c.g, c.b, c.a); colors = nullptr; } else if (primitive->colors.empty()) { - glVertexAttrib4f(GD_VS::ARRAY_COLOR, 1, 1, 1, 1); + glVertexAttrib4f(RS::ARRAY_COLOR, 1, 1, 1, 1); } #ifdef RASTERIZER_EXTRA_CHECKS else { @@ -1155,7 +1150,7 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite case Item::Command::TYPE_TRANSFORM: { Item::CommandTransform *transform = static_cast<Item::CommandTransform *>(command); state.uniforms.extra_matrix = transform->xform; - state.canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX, state.uniforms.extra_matrix); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::EXTRA_MATRIX, state.uniforms.extra_matrix); } break; case Item::Command::TYPE_PARTICLES: { @@ -1200,31 +1195,53 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite } } -void RasterizerCanvasGLES2::canvas_end() { +void RasterizerCanvasOpenGL::canvas_end() { batch_canvas_end(); - RasterizerCanvasBaseGLES2::canvas_end(); + RasterizerCanvasBaseOpenGL::canvas_end(); } -void RasterizerCanvasGLES2::canvas_begin() { +void RasterizerCanvasOpenGL::canvas_begin() { batch_canvas_begin(); - RasterizerCanvasBaseGLES2::canvas_begin(); + RasterizerCanvasBaseOpenGL::canvas_begin(); } -void RasterizerCanvasGLES2::canvas_render_items_begin(const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform) { +void RasterizerCanvasOpenGL::canvas_render_items_begin(const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform) { batch_canvas_render_items_begin(p_modulate, p_light, p_base_transform); } -void RasterizerCanvasGLES2::canvas_render_items_end() { +void RasterizerCanvasOpenGL::canvas_render_items_end() { batch_canvas_render_items_end(); } -void RasterizerCanvasGLES2::canvas_render_items_internal(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform) { +void RasterizerCanvasOpenGL::canvas_render_items(RID p_to_render_target, Item *p_item_list, const Color &p_modulate, Light *p_light_list, Light *p_directional_list, const Transform2D &p_canvas_transform, RS::CanvasItemTextureFilter p_default_filter, RS::CanvasItemTextureRepeat p_default_repeat, bool p_snap_2d_vertices_to_pixel, bool &r_sdf_used) { + storage->frame.current_rt = nullptr; + + // first set the current render target + storage->_set_current_render_target(p_to_render_target); + + // binds the render target (framebuffer) + canvas_begin(); + + canvas_render_items_begin(p_modulate, p_light_list, p_canvas_transform); + canvas_render_items_internal(p_item_list, 0, p_modulate, p_light_list, p_canvas_transform); + canvas_render_items_end(); + + canvas_end(); + + // not sure why these are needed to get frame to render? + storage->_set_current_render_target(RID()); + // storage->frame.current_rt = nullptr; + // canvas_begin(); + // canvas_end(); +} + +void RasterizerCanvasOpenGL::canvas_render_items_internal(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform) { batch_canvas_render_items(p_item_list, p_z, p_modulate, p_light, p_base_transform); //glClearColor(Math::randf(), 0, 1, 1); } -void RasterizerCanvasGLES2::canvas_render_items_implementation(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform) { +void RasterizerCanvasOpenGL::canvas_render_items_implementation(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform) { // parameters are easier to pass around in a structure RenderItemState ris; ris.item_group_z = p_z; @@ -1232,7 +1249,7 @@ void RasterizerCanvasGLES2::canvas_render_items_implementation(Item *p_item_list ris.item_group_light = p_light; ris.item_group_base_transform = p_base_transform; - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_SKELETON, false); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_SKELETON, false); state.current_tex = RID(); state.current_tex_ptr = NULL; @@ -1242,331 +1259,22 @@ void RasterizerCanvasGLES2::canvas_render_items_implementation(Item *p_item_list glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex); - if (bdata.settings_use_batching) { -#ifdef GODOT_3 - for (int j = 0; j < bdata.items_joined.size(); j++) { - render_joined_item(bdata.items_joined[j], ris); - } -#endif - } else { - while (p_item_list) { - Item *ci = p_item_list; - _legacy_canvas_render_item(ci, ris); - p_item_list = p_item_list->next; - } + while (p_item_list) { + Item *ci = p_item_list; + _legacy_canvas_render_item(ci, ris); + p_item_list = p_item_list->next; } if (ris.current_clip) { glDisable(GL_SCISSOR_TEST); } - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_SKELETON, false); -} - -#ifdef GODOT_3 -// This function is a dry run of the state changes when drawing the item. -// It should duplicate the logic in _canvas_render_item, -// to decide whether items are similar enough to join -// i.e. no state differences between the 2 items. -bool RasterizerCanvasGLES2::try_join_item(Item *p_ci, RenderItemState &r_ris, bool &r_batch_break) { - // if we set max join items to zero we can effectively prevent any joining, so - // none of the other logic needs to run. Good for testing regression bugs, and - // could conceivably be faster in some games. - if (!bdata.settings_max_join_item_commands) { - return false; - } - - // if there are any state changes we change join to false - // we also set r_batch_break to true if we don't want this item joined to the next - // (e.g. an item that must not be joined at all) - r_batch_break = false; - bool join = true; - - // light_masked may possibly need state checking here. Check for regressions! - - // we will now allow joining even if final modulate is different - // we will instead bake the final modulate into the vertex colors - // if (p_ci->final_modulate != r_ris.final_modulate) { - // join = false; - // r_ris.final_modulate = p_ci->final_modulate; - // } - - if (r_ris.current_clip != p_ci->final_clip_owner) { - r_ris.current_clip = p_ci->final_clip_owner; - join = false; - } - - // TODO: copy back buffer - - if (p_ci->copy_back_buffer) { - join = false; - } - - RasterizerStorageGLES2::Skeleton *skeleton = NULL; - - { - //skeleton handling - if (p_ci->skeleton.is_valid() && storage->skeleton_owner.owns(p_ci->skeleton)) { - skeleton = storage->skeleton_owner.get(p_ci->skeleton); - if (!skeleton->use_2d) { - skeleton = NULL; - } - } - - bool skeleton_prevent_join = false; - - bool use_skeleton = skeleton != NULL; - if (r_ris.prev_use_skeleton != use_skeleton) { - if (!bdata.settings_use_software_skinning) - r_ris.rebind_shader = true; - - r_ris.prev_use_skeleton = use_skeleton; - // join = false; - skeleton_prevent_join = true; - } - - if (skeleton) { - // join = false; - skeleton_prevent_join = true; - state.using_skeleton = true; - } else { - state.using_skeleton = false; - } - - if (skeleton_prevent_join) { - if (!bdata.settings_use_software_skinning) - join = false; - } - } - - Item *material_owner = p_ci->material_owner ? p_ci->material_owner : p_ci; - - RID material = material_owner->material; - RasterizerStorageGLES2::Material *material_ptr = storage->material_owner.getornull(material); - - if (material != r_ris.canvas_last_material || r_ris.rebind_shader) { - join = false; - RasterizerStorageGLES2::Shader *shader_ptr = NULL; - - if (material_ptr) { - shader_ptr = material_ptr->shader; - - if (shader_ptr && shader_ptr->mode != GD_VS::SHADER_CANVAS_ITEM) { - shader_ptr = NULL; // not a canvas item shader, don't use. - } - } - - if (shader_ptr) { - if (shader_ptr->canvas_item.uses_screen_texture) { - if (!state.canvas_texscreen_used) { - join = false; - } - } - } - - r_ris.shader_cache = shader_ptr; - - r_ris.canvas_last_material = material; - - r_ris.rebind_shader = false; - } - - int blend_mode = r_ris.shader_cache ? r_ris.shader_cache->canvas_item.blend_mode : RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_MIX; - bool unshaded = r_ris.shader_cache && (r_ris.shader_cache->canvas_item.light_mode == RasterizerStorageGLES2::Shader::CanvasItem::LIGHT_MODE_UNSHADED || (blend_mode != RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_MIX && blend_mode != RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_PMALPHA)); - bool reclip = false; - - // we are precalculating the final_modulate ahead of time because we need this for baking of final modulate into vertex colors - // (only in software transform mode) - // This maybe inefficient storing it... - r_ris.final_modulate = unshaded ? p_ci->final_modulate : (p_ci->final_modulate * r_ris.item_group_modulate); - - if (r_ris.last_blend_mode != blend_mode) { - join = false; - r_ris.last_blend_mode = blend_mode; - } - - // does the shader contain BUILTINs which should break the batching? - bdata.joined_item_batch_flags = 0; - if (r_ris.shader_cache) { - unsigned int and_flags = r_ris.shader_cache->canvas_item.batch_flags & (RasterizerStorageCommon::PREVENT_COLOR_BAKING | RasterizerStorageCommon::PREVENT_VERTEX_BAKING | RasterizerStorageCommon::PREVENT_ITEM_JOINING); - if (and_flags) { - // special case for preventing item joining altogether - if (and_flags & RasterizerStorageCommon::PREVENT_ITEM_JOINING) { - join = false; - //r_batch_break = true; // don't think we need a batch break - - // save the flags so that they don't need to be recalculated in the 2nd pass - bdata.joined_item_batch_flags |= r_ris.shader_cache->canvas_item.batch_flags; - } else { - bool use_larger_fvfs = true; - - if (and_flags == RasterizerStorageCommon::PREVENT_COLOR_BAKING) { - // in some circumstances, if the modulate is identity, we still allow baking because reading modulate / color - // will still be okay to do in the shader with no ill effects - if (r_ris.final_modulate == Color(1, 1, 1, 1)) { - use_larger_fvfs = false; - } - } - - // new .. always use large FVF - if (use_larger_fvfs) { - if (and_flags == RasterizerStorageCommon::PREVENT_COLOR_BAKING) { - bdata.joined_item_batch_flags |= RasterizerStorageCommon::USE_MODULATE_FVF; - } else { - // we need to save on the joined item that it should use large fvf. - // This info will then be used in filling and rendering - bdata.joined_item_batch_flags |= RasterizerStorageCommon::USE_LARGE_FVF; - } - - bdata.joined_item_batch_flags |= r_ris.shader_cache->canvas_item.batch_flags; - } - -#if 0 - if (and_flags == RasterizerStorageCommon::PREVENT_COLOR_BAKING) { - // in some circumstances, if the modulate is identity, we still allow baking because reading modulate / color - // will still be okay to do in the shader with no ill effects - if (r_ris.final_modulate == Color(1, 1, 1, 1)) { - break_batching = false; - } - else - { - // new .. large FVF - break_batching = false; - - // we need to save on the joined item that it should use large fvf. - // This info will then be used in filling and rendering - bdata.joined_item_batch_flags |= RasterizerStorageCommon::USE_LARGE_FVF; - } - } - - if (break_batching) { - join = false; - r_batch_break = true; - - // save the flags so that they don't need to be recalculated in the 2nd pass - bdata.joined_item_batch_flags |= r_ris.shader_cache->canvas_item.batch_flags; - } -#endif - } // if not prevent item joining - } - } - - if ((blend_mode == RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_MIX || blend_mode == RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_PMALPHA) && r_ris.item_group_light && !unshaded) { - // we cannot join lit items easily. - // it is possible, but not if they overlap, because - // a + light_blend + b + light_blend IS NOT THE SAME AS - // a + b + light_blend - - bool light_allow_join = true; - - // this is a quick getout if we have turned off light joining - if ((bdata.settings_light_max_join_items == 0) || r_ris.light_region.too_many_lights) { - light_allow_join = false; - } else { - // do light joining... - - // first calculate the light bitfield - uint64_t light_bitfield = 0; - uint64_t shadow_bitfield = 0; - Light *light = r_ris.item_group_light; - - int light_count = -1; - while (light) { - light_count++; - uint64_t light_bit = 1ULL << light_count; - - // note that as a cost of batching, the light culling will be less effective - if (p_ci->light_mask & light->item_mask && r_ris.item_group_z >= light->z_min && r_ris.item_group_z <= light->z_max) { - // Note that with the above test, it is possible to also include a bound check. - // Tests so far have indicated better performance without it, but there may be reason to change this at a later stage, - // so I leave the line here for reference: - // && p_ci->global_rect_cache.intersects_transformed(light->xform_cache, light->rect_cache)) { - light_bitfield |= light_bit; - - bool has_shadow = light->shadow_buffer.is_valid() && p_ci->light_mask & light->item_shadow_mask; - - if (has_shadow) { - shadow_bitfield |= light_bit; - } - } - - light = light->next_ptr; - } - - // now compare to previous - if ((r_ris.light_region.light_bitfield != light_bitfield) || (r_ris.light_region.shadow_bitfield != shadow_bitfield)) { - light_allow_join = false; - - r_ris.light_region.light_bitfield = light_bitfield; - r_ris.light_region.shadow_bitfield = shadow_bitfield; - } else { - // only do these checks if necessary - if (join && (!r_batch_break)) { - // we still can't join, even if the lights are exactly the same, if there is overlap between the previous and this item - if (r_ris.joined_item && light_bitfield) { - if ((int)r_ris.joined_item->num_item_refs <= bdata.settings_light_max_join_items) { - for (uint32_t r = 0; r < r_ris.joined_item->num_item_refs; r++) { - Item *pRefItem = bdata.item_refs[r_ris.joined_item->first_item_ref + r].item; - if (p_ci->global_rect_cache.intersects(pRefItem->global_rect_cache)) { - light_allow_join = false; - break; - } - } - -#ifdef DEBUG_ENABLED - if (light_allow_join) { - bdata.stats_light_items_joined++; - } -#endif - - } // if below max join items - else { - // just don't allow joining if above overlap check max items - light_allow_join = false; - } - } - - } // if not batch broken already (no point in doing expensive overlap tests if not needed) - } // if bitfields don't match - } // if do light joining - - if (!light_allow_join) { - // can't join - join = false; - // we also dont want to allow joining this item with the next item, because the next item could have no lights! - r_batch_break = true; - } - - } else { - // if the last item had lights, we should not join it to this one (which has no lights) - if (r_ris.light_region.light_bitfield || r_ris.light_region.shadow_bitfield) { - join = false; - - // setting these to zero ensures that any following item with lights will, by definition, - // be affected by a different set of lights, and thus prevent a join - r_ris.light_region.light_bitfield = 0; - r_ris.light_region.shadow_bitfield = 0; - } - } - - if (reclip) { - join = false; - } - - // non rects will break the batching anyway, we don't want to record item changes, detect this - if (!r_batch_break && _detect_item_batch_break(r_ris, p_ci, r_batch_break)) { - join = false; - - r_batch_break = true; - } - - return join; + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_SKELETON, false); } -#endif // godot 3 // Legacy non-batched implementation for regression testing. // Should be removed after testing phase to avoid duplicate codepaths. -void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemState &r_ris) { +void RasterizerCanvasOpenGL::_legacy_canvas_render_item(Item *p_ci, RenderItemState &r_ris) { storage->info.render._2d_item_count++; // defaults @@ -1617,7 +1325,7 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta } #if 0 - RasterizerStorageGLES2::Skeleton *skeleton = NULL; + RasterizerStorageOpenGL::Skeleton *skeleton = NULL; { //skeleton handling @@ -1635,7 +1343,7 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta bool use_skeleton = skeleton != NULL; if (r_ris.prev_use_skeleton != use_skeleton) { r_ris.rebind_shader = true; - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_SKELETON, use_skeleton); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_SKELETON, use_skeleton); r_ris.prev_use_skeleton = use_skeleton; } @@ -1652,15 +1360,15 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta Item *material_owner = p_ci->material_owner ? p_ci->material_owner : p_ci; RID material = material_owner->material; - RasterizerStorageGLES2::Material *material_ptr = storage->material_owner.getornull(material); + RasterizerStorageOpenGL::Material *material_ptr = storage->material_owner.get_or_null(material); if (material != r_ris.canvas_last_material || r_ris.rebind_shader) { - RasterizerStorageGLES2::Shader *shader_ptr = NULL; + RasterizerStorageOpenGL::Shader *shader_ptr = NULL; if (material_ptr) { shader_ptr = material_ptr->shader; - if (shader_ptr && shader_ptr->mode != GD_VS::SHADER_CANVAS_ITEM) { + if (shader_ptr && shader_ptr->mode != RS::SHADER_CANVAS_ITEM) { shader_ptr = NULL; // not a canvas item shader, don't use. } } @@ -1672,7 +1380,7 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta _copy_texscreen(Rect2()); // blend mode will have been enabled so make sure we disable it again later on - //last_blend_mode = last_blend_mode != RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_DISABLED ? last_blend_mode : -1; + //last_blend_mode = last_blend_mode != RasterizerStorageOpenGL::Shader::CanvasItem::BLEND_MODE_DISABLED ? last_blend_mode : -1; } if (storage->frame.current_rt->copy_screen_effect.color) { @@ -1698,7 +1406,7 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta for (int i = 0; i < tc; i++) { glActiveTexture(GL_TEXTURE0 + i); - RasterizerStorageGLES2::Texture *t = storage->texture_owner.getornull(textures[i].second); + RasterizerStorageOpenGL::Texture *t = storage->texture_owner.get_or_null(textures[i].second); if (!t) { switch (texture_hints[i]) { @@ -1750,13 +1458,13 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta r_ris.rebind_shader = false; } - int blend_mode = r_ris.shader_cache ? r_ris.shader_cache->canvas_item.blend_mode : RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_MIX; - bool unshaded = r_ris.shader_cache && (r_ris.shader_cache->canvas_item.light_mode == RasterizerStorageGLES2::Shader::CanvasItem::LIGHT_MODE_UNSHADED || (blend_mode != RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_MIX && blend_mode != RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_PMALPHA)); + int blend_mode = r_ris.shader_cache ? r_ris.shader_cache->canvas_item.blend_mode : RasterizerStorageOpenGL::Shader::CanvasItem::BLEND_MODE_MIX; + bool unshaded = r_ris.shader_cache && (r_ris.shader_cache->canvas_item.light_mode == RasterizerStorageOpenGL::Shader::CanvasItem::LIGHT_MODE_UNSHADED || (blend_mode != RasterizerStorageOpenGL::Shader::CanvasItem::BLEND_MODE_MIX && blend_mode != RasterizerStorageOpenGL::Shader::CanvasItem::BLEND_MODE_PMALPHA)); bool reclip = false; if (r_ris.last_blend_mode != blend_mode) { switch (blend_mode) { - case RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_MIX: { + case RasterizerStorageOpenGL::Shader::CanvasItem::BLEND_MODE_MIX: { glBlendEquation(GL_FUNC_ADD); if (storage->frame.current_rt && storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_TRANSPARENT]) { glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); @@ -1765,7 +1473,7 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta } } break; - case RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_ADD: { + case RasterizerStorageOpenGL::Shader::CanvasItem::BLEND_MODE_ADD: { glBlendEquation(GL_FUNC_ADD); if (storage->frame.current_rt && storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_TRANSPARENT]) { glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_SRC_ALPHA, GL_ONE); @@ -1774,7 +1482,7 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta } } break; - case RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_SUB: { + case RasterizerStorageOpenGL::Shader::CanvasItem::BLEND_MODE_SUB: { glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); if (storage->frame.current_rt && storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_TRANSPARENT]) { glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_SRC_ALPHA, GL_ONE); @@ -1782,7 +1490,7 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE); } } break; - case RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_MUL: { + case RasterizerStorageOpenGL::Shader::CanvasItem::BLEND_MODE_MUL: { glBlendEquation(GL_FUNC_ADD); if (storage->frame.current_rt && storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_TRANSPARENT]) { glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_DST_ALPHA, GL_ZERO); @@ -1790,7 +1498,7 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_ZERO, GL_ONE); } } break; - case RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_PMALPHA: { + case RasterizerStorageOpenGL::Shader::CanvasItem::BLEND_MODE_PMALPHA: { glBlendEquation(GL_FUNC_ADD); if (storage->frame.current_rt && storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_TRANSPARENT]) { glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); @@ -1808,15 +1516,15 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta _set_uniforms(); - if (unshaded || (state.uniforms.final_modulate.a > 0.001 && (!r_ris.shader_cache || r_ris.shader_cache->canvas_item.light_mode != RasterizerStorageGLES2::Shader::CanvasItem::LIGHT_MODE_LIGHT_ONLY) && !p_ci->light_masked)) + if (unshaded || (state.uniforms.final_modulate.a > 0.001 && (!r_ris.shader_cache || r_ris.shader_cache->canvas_item.light_mode != RasterizerStorageOpenGL::Shader::CanvasItem::LIGHT_MODE_LIGHT_ONLY) && !p_ci->light_masked)) _legacy_canvas_item_render_commands(p_ci, NULL, reclip, material_ptr); r_ris.rebind_shader = true; // hacked in for now. - if ((blend_mode == RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_MIX || blend_mode == RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_PMALPHA) && r_ris.item_group_light && !unshaded) { + if ((blend_mode == RasterizerStorageOpenGL::Shader::CanvasItem::BLEND_MODE_MIX || blend_mode == RasterizerStorageOpenGL::Shader::CanvasItem::BLEND_MODE_PMALPHA) && r_ris.item_group_light && !unshaded) { Light *light = r_ris.item_group_light; bool light_used = false; - GD_VS::CanvasLightBlendMode bmode = GD_VS::CANVAS_LIGHT_BLEND_MODE_ADD; + RS::CanvasLightBlendMode bmode = RS::CANVAS_LIGHT_BLEND_MODE_ADD; state.uniforms.final_modulate = p_ci->final_modulate; // remove the canvas modulate while (light) { @@ -1827,17 +1535,17 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta bmode = light->blend_mode; switch (bmode) { - case GD_VS::CANVAS_LIGHT_BLEND_MODE_ADD: { + case RS::CANVAS_LIGHT_BLEND_MODE_ADD: { glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_SRC_ALPHA, GL_ONE); } break; - case GD_VS::CANVAS_LIGHT_BLEND_MODE_SUB: { + case RS::CANVAS_LIGHT_BLEND_MODE_SUB: { glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); glBlendFunc(GL_SRC_ALPHA, GL_ONE); } break; - case GD_VS::CANVAS_LIGHT_BLEND_MODE_MIX: { - // case GD_VS::CANVAS_LIGHT_MODE_MASK: { + case RS::CANVAS_LIGHT_BLEND_MODE_MIX: { + // case RS::CANVAS_LIGHT_MODE_MASK: { glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -1846,7 +1554,7 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta } if (!light_used) { - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_LIGHTING, true); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_LIGHTING, true); light_used = true; } @@ -1854,20 +1562,20 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta //bool has_shadow = light->shadow_buffer.is_valid() && p_ci->light_mask & light->item_shadow_mask; bool has_shadow = light->use_shadow && p_ci->light_mask & light->item_shadow_mask; - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_SHADOWS, has_shadow); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_SHADOWS, has_shadow); if (has_shadow) { // FTODO - //state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_USE_GRADIENT, light->shadow_gradient_length > 0); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_USE_GRADIENT, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_NEAREST, light->shadow_filter == GD_VS::CANVAS_LIGHT_FILTER_NONE); - //state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF3, light->shadow_filter == GD_VS::CANVAS_LIGHT_FILTER_PCF3); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF3, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF5, light->shadow_filter == GD_VS::CANVAS_LIGHT_FILTER_PCF5); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF7, false); - //state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF7, light->shadow_filter == GD_VS::CANVAS_LIGHT_FILTER_PCF7); - //state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF9, light->shadow_filter == GD_VS::CANVAS_LIGHT_FILTER_PCF9); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF9, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF13, light->shadow_filter == GD_VS::CANVAS_LIGHT_FILTER_PCF13); + //state.canvas_shader.set_conditional(CanvasShaderOpenGL::SHADOW_USE_GRADIENT, light->shadow_gradient_length > 0); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::SHADOW_USE_GRADIENT, false); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::SHADOW_FILTER_NEAREST, light->shadow_filter == RS::CANVAS_LIGHT_FILTER_NONE); + //state.canvas_shader.set_conditional(CanvasShaderOpenGL::SHADOW_FILTER_PCF3, light->shadow_filter == RS::CANVAS_LIGHT_FILTER_PCF3); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::SHADOW_FILTER_PCF3, false); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::SHADOW_FILTER_PCF5, light->shadow_filter == RS::CANVAS_LIGHT_FILTER_PCF5); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::SHADOW_FILTER_PCF7, false); + //state.canvas_shader.set_conditional(CanvasShaderOpenGL::SHADOW_FILTER_PCF7, light->shadow_filter == RS::CANVAS_LIGHT_FILTER_PCF7); + //state.canvas_shader.set_conditional(CanvasShaderOpenGL::SHADOW_FILTER_PCF9, light->shadow_filter == RS::CANVAS_LIGHT_FILTER_PCF9); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::SHADOW_FILTER_PCF9, false); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::SHADOW_FILTER_PCF13, light->shadow_filter == RS::CANVAS_LIGHT_FILTER_PCF13); } state.canvas_shader.bind(); @@ -1879,7 +1587,7 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta state.canvas_shader.use_material((void *)material_ptr); glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 6); - RasterizerStorageGLES2::Texture *t = storage->texture_owner.getornull(light->texture); + RasterizerStorageOpenGL::Texture *t = storage->texture_owner.get_or_null(light->texture); if (!t) { glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex); } else { @@ -1898,14 +1606,14 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta } if (light_used) { - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_LIGHTING, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_SHADOWS, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_NEAREST, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF3, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF5, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF7, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF9, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF13, false); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_LIGHTING, false); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::USE_SHADOWS, false); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::SHADOW_FILTER_NEAREST, false); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::SHADOW_FILTER_PCF3, false); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::SHADOW_FILTER_PCF5, false); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::SHADOW_FILTER_PCF7, false); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::SHADOW_FILTER_PCF9, false); + state.canvas_shader.set_conditional(CanvasShaderOpenGL::SHADOW_FILTER_PCF13, false); state.canvas_shader.bind(); @@ -1915,9 +1623,9 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta //this is set again, so it should not be needed anyway? state.canvas_item_modulate = unshaded ? ci->final_modulate : Color(ci->final_modulate.r * p_modulate.r, ci->final_modulate.g * p_modulate.g, ci->final_modulate.b * p_modulate.b, ci->final_modulate.a * p_modulate.a); - state.canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX, state.final_transform); - state.canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX, Transform2D()); - state.canvas_shader.set_uniform(CanvasShaderGLES2::FINAL_MODULATE, state.canvas_item_modulate); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::MODELVIEW_MATRIX, state.final_transform); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::EXTRA_MATRIX, Transform2D()); + state.canvas_shader.set_uniform(CanvasShaderOpenGL::FINAL_MODULATE, state.canvas_item_modulate); glBlendEquation(GL_FUNC_ADD); @@ -1942,410 +1650,17 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta } } -#ifdef GODOT_3 -void RasterizerCanvasGLES2::render_joined_item(const BItemJoined &p_bij, RenderItemState &r_ris) { - storage->info.render._2d_item_count++; - -#ifdef DEBUG_ENABLED - if (bdata.diagnose_frame) { - bdata.frame_string += "\tjoined_item " + itos(p_bij.num_item_refs) + " refs\n"; - if (p_bij.z_index != 0) { - bdata.frame_string += "\t\t(z " + itos(p_bij.z_index) + ")\n"; - } - } -#endif - - // all the joined items will share the same state with the first item - Item *ci = bdata.item_refs[p_bij.first_item_ref].item; - - if (r_ris.current_clip != ci->final_clip_owner) { - r_ris.current_clip = ci->final_clip_owner; - - if (r_ris.current_clip) { - glEnable(GL_SCISSOR_TEST); - int y = storage->frame.current_rt->height - (r_ris.current_clip->final_clip_rect.position.y + r_ris.current_clip->final_clip_rect.size.y); - if (storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_VFLIP]) - y = r_ris.current_clip->final_clip_rect.position.y; - glScissor(r_ris.current_clip->final_clip_rect.position.x, y, r_ris.current_clip->final_clip_rect.size.width, r_ris.current_clip->final_clip_rect.size.height); - } else { - glDisable(GL_SCISSOR_TEST); - } - } - - // TODO: copy back buffer - - if (ci->copy_back_buffer) { - if (ci->copy_back_buffer->full) { - _copy_texscreen(Rect2()); - } else { - _copy_texscreen(ci->copy_back_buffer->rect); - } - } - - if (!bdata.settings_use_batching || !bdata.settings_use_software_skinning) { - RasterizerStorageGLES2::Skeleton *skeleton = NULL; - - //skeleton handling - if (ci->skeleton.is_valid() && storage->skeleton_owner.owns(ci->skeleton)) { - skeleton = storage->skeleton_owner.get(ci->skeleton); - if (!skeleton->use_2d) { - skeleton = NULL; - } else { - state.skeleton_transform = r_ris.item_group_base_transform * skeleton->base_transform_2d; - state.skeleton_transform_inverse = state.skeleton_transform.affine_inverse(); - state.skeleton_texture_size = Vector2(skeleton->size * 2, 0); - } - } - - bool use_skeleton = skeleton != NULL; - if (r_ris.prev_use_skeleton != use_skeleton) { - r_ris.rebind_shader = true; - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_SKELETON, use_skeleton); - r_ris.prev_use_skeleton = use_skeleton; - } - - if (skeleton) { - glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 3); - glBindTexture(GL_TEXTURE_2D, skeleton->tex_id); - state.using_skeleton = true; - } else { - state.using_skeleton = false; - } - - } // if not using batching - - Item *material_owner = ci->material_owner ? ci->material_owner : ci; - - RID material = material_owner->material; - RasterizerStorageGLES2::Material *material_ptr = storage->material_owner.getornull(material); - - if (material != r_ris.canvas_last_material || r_ris.rebind_shader) { - RasterizerStorageGLES2::Shader *shader_ptr = NULL; - - if (material_ptr) { - shader_ptr = material_ptr->shader; - - if (shader_ptr && shader_ptr->mode != GD_VS::SHADER_CANVAS_ITEM) { - shader_ptr = NULL; // not a canvas item shader, don't use. - } - } - - if (shader_ptr) { - if (shader_ptr->canvas_item.uses_screen_texture) { - if (!state.canvas_texscreen_used) { - //copy if not copied before - _copy_texscreen(Rect2()); - - // blend mode will have been enabled so make sure we disable it again later on - //last_blend_mode = last_blend_mode != RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_DISABLED ? last_blend_mode : -1; - } - - if (storage->frame.current_rt->copy_screen_effect.color) { - glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 4); - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->copy_screen_effect.color); - } - } - - if (shader_ptr != r_ris.shader_cache) { - if (shader_ptr->canvas_item.uses_time) { - VisualServerRaster::redraw_request(); - } - - state.canvas_shader.set_custom_shader(shader_ptr->custom_code_id); - state.canvas_shader.bind(); - } - - int tc = material_ptr->textures.size(); - Pair<StringName, RID> *textures = material_ptr->textures.ptrw(); - - ShaderLanguage::ShaderNode::Uniform::Hint *texture_hints = shader_ptr->texture_hints.ptrw(); - - for (int i = 0; i < tc; i++) { - glActiveTexture(GL_TEXTURE0 + i); - - RasterizerStorageGLES2::Texture *t = storage->texture_owner.getornull(textures[i].second); - - if (!t) { - switch (texture_hints[i]) { - case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK_ALBEDO: - case ShaderLanguage::ShaderNode::Uniform::HINT_BLACK: { - glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex); - } break; - case ShaderLanguage::ShaderNode::Uniform::HINT_ANISO: { - glBindTexture(GL_TEXTURE_2D, storage->resources.aniso_tex); - } break; - case ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL: { - glBindTexture(GL_TEXTURE_2D, storage->resources.normal_tex); - } break; - default: { - glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex); - } break; - } - - continue; - } - - if (t->redraw_if_visible) { - VisualServerRaster::redraw_request(); - } - - t = t->get_ptr(); - -#ifdef TOOLS_ENABLED - if (t->detect_normal && texture_hints[i] == ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL) { - t->detect_normal(t->detect_normal_ud); - } -#endif - if (t->render_target) - t->render_target->used_in_frame = true; - - glBindTexture(t->target, t->tex_id); - } - - } else { - state.canvas_shader.set_custom_shader(0); - state.canvas_shader.bind(); - } - state.canvas_shader.use_material((void *)material_ptr); - - r_ris.shader_cache = shader_ptr; - - r_ris.canvas_last_material = material; - - r_ris.rebind_shader = false; - } - - int blend_mode = r_ris.shader_cache ? r_ris.shader_cache->canvas_item.blend_mode : RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_MIX; - bool unshaded = r_ris.shader_cache && (r_ris.shader_cache->canvas_item.light_mode == RasterizerStorageGLES2::Shader::CanvasItem::LIGHT_MODE_UNSHADED || (blend_mode != RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_MIX && blend_mode != RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_PMALPHA)); - bool reclip = false; - - if (r_ris.last_blend_mode != blend_mode) { - switch (blend_mode) { - case RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_MIX: { - glBlendEquation(GL_FUNC_ADD); - if (storage->frame.current_rt && storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_TRANSPARENT]) { - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - } else { - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE); - } - - } break; - case RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_ADD: { - glBlendEquation(GL_FUNC_ADD); - if (storage->frame.current_rt && storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_TRANSPARENT]) { - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_SRC_ALPHA, GL_ONE); - } else { - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE); - } - - } break; - case RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_SUB: { - glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); - if (storage->frame.current_rt && storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_TRANSPARENT]) { - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_SRC_ALPHA, GL_ONE); - } else { - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE); - } - } break; - case RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_MUL: { - glBlendEquation(GL_FUNC_ADD); - if (storage->frame.current_rt && storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_TRANSPARENT]) { - glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_DST_ALPHA, GL_ZERO); - } else { - glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_ZERO, GL_ONE); - } - } break; - case RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_PMALPHA: { - glBlendEquation(GL_FUNC_ADD); - if (storage->frame.current_rt && storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_TRANSPARENT]) { - glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - } else { - glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE); - } - } break; - } - } - - // using software transform? - // (i.e. don't send the transform matrix, send identity, and either use baked verts, - // or large fvf where the transform is done in the shader from transform stored in the fvf.) - if (!p_bij.use_hardware_transform()) { - state.uniforms.modelview_matrix = Transform2D(); - // final_modulate will be baked per item ref so the final_modulate can be an identity color - state.uniforms.final_modulate = Color(1, 1, 1, 1); - } else { - state.uniforms.modelview_matrix = ci->final_transform; - // could use the stored version of final_modulate in item ref? Test which is faster NYI - state.uniforms.final_modulate = unshaded ? ci->final_modulate : (ci->final_modulate * r_ris.item_group_modulate); - } - state.uniforms.extra_matrix = Transform2D(); - - _set_uniforms(); - - if (unshaded || (state.uniforms.final_modulate.a > 0.001 && (!r_ris.shader_cache || r_ris.shader_cache->canvas_item.light_mode != RasterizerStorageGLES2::Shader::CanvasItem::LIGHT_MODE_LIGHT_ONLY) && !ci->light_masked)) - render_joined_item_commands(p_bij, NULL, reclip, material_ptr, false); - - r_ris.rebind_shader = true; // hacked in for now. - - if ((blend_mode == RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_MIX || blend_mode == RasterizerStorageGLES2::Shader::CanvasItem::BLEND_MODE_PMALPHA) && r_ris.item_group_light && !unshaded) { - Light *light = r_ris.item_group_light; - bool light_used = false; - VS::CanvasLightMode mode = GD_VS::CANVAS_LIGHT_MODE_ADD; - - // we leave this set to 1, 1, 1, 1 if using software because the colors are baked into the vertices - if (p_bij.use_hardware_transform()) { - state.uniforms.final_modulate = ci->final_modulate; // remove the canvas modulate - } - - while (light) { - // use the bounding rect of the joined items, NOT only the bounding rect of the first item. - // note this is a cost of batching, the light culling will be less effective - - // note that the r_ris.item_group_z will be out of date because we are using deferred rendering till canvas_render_items_end() - // so we have to test z against the stored value in the joined item - if (ci->light_mask & light->item_mask && p_bij.z_index >= light->z_min && p_bij.z_index <= light->z_max && p_bij.bounding_rect.intersects_transformed(light->xform_cache, light->rect_cache)) { - //intersects this light - - if (!light_used || mode != light->mode) { - mode = light->mode; - - switch (mode) { - case GD_VS::CANVAS_LIGHT_MODE_ADD: { - glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - - } break; - case GD_VS::CANVAS_LIGHT_MODE_SUB: { - glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - } break; - case GD_VS::CANVAS_LIGHT_MODE_MIX: - case GD_VS::CANVAS_LIGHT_MODE_MASK: { - glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - } break; - } - } - - if (!light_used) { - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_LIGHTING, true); - light_used = true; - } - - bool has_shadow = light->shadow_buffer.is_valid() && ci->light_mask & light->item_shadow_mask; - - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_SHADOWS, has_shadow); - if (has_shadow) { - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_USE_GRADIENT, light->shadow_gradient_length > 0); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_NEAREST, light->shadow_filter == GD_VS::CANVAS_LIGHT_FILTER_NONE); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF3, light->shadow_filter == GD_VS::CANVAS_LIGHT_FILTER_PCF3); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF5, light->shadow_filter == GD_VS::CANVAS_LIGHT_FILTER_PCF5); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF7, light->shadow_filter == GD_VS::CANVAS_LIGHT_FILTER_PCF7); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF9, light->shadow_filter == GD_VS::CANVAS_LIGHT_FILTER_PCF9); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF13, light->shadow_filter == GD_VS::CANVAS_LIGHT_FILTER_PCF13); - } - - state.canvas_shader.bind(); - state.using_light = light; - state.using_shadow = has_shadow; - - //always re-set uniforms, since light parameters changed - _set_uniforms(); - state.canvas_shader.use_material((void *)material_ptr); - - glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 6); - RasterizerStorageGLES2::Texture *t = storage->texture_owner.getornull(light->texture); - if (!t) { - glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex); - } else { - t = t->get_ptr(); - - glBindTexture(t->target, t->tex_id); - } - - glActiveTexture(GL_TEXTURE0); - - // redraw using light. - // if there is no clip item, we can consider scissoring to the intersection area between the light and the item - // this can greatly reduce fill rate .. - // at the cost of glScissor commands, so is optional - if (!bdata.settings_scissor_lights || r_ris.current_clip) { - render_joined_item_commands(p_bij, NULL, reclip, material_ptr, true); - } else { - bool scissor = _light_scissor_begin(p_bij.bounding_rect, light->xform_cache, light->rect_cache); - render_joined_item_commands(p_bij, NULL, reclip, material_ptr, true); - if (scissor) { - glDisable(GL_SCISSOR_TEST); - } - } - - state.using_light = NULL; - } - - light = light->next_ptr; - } - - if (light_used) { - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_LIGHTING, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_SHADOWS, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_NEAREST, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF3, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF5, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF7, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF9, false); - state.canvas_shader.set_conditional(CanvasShaderGLES2::SHADOW_FILTER_PCF13, false); - - state.canvas_shader.bind(); - - r_ris.last_blend_mode = -1; - -#if 0 - //this is set again, so it should not be needed anyway? - state.canvas_item_modulate = unshaded ? ci->final_modulate : Color( - ci->final_modulate.r * p_modulate.r, - ci->final_modulate.g * p_modulate.g, - ci->final_modulate.b * p_modulate.b, - ci->final_modulate.a * p_modulate.a ); - - state.canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX,state.final_transform); - state.canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Transform2D()); - state.canvas_shader.set_uniform(CanvasShaderGLES2::FINAL_MODULATE,state.canvas_item_modulate); - - glBlendEquation(GL_FUNC_ADD); - - if (storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_TRANSPARENT]) { - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - } else { - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - - //@TODO RESET canvas_blend_mode -#endif - } - } - - if (reclip) { - glEnable(GL_SCISSOR_TEST); - int y = storage->frame.current_rt->height - (r_ris.current_clip->final_clip_rect.position.y + r_ris.current_clip->final_clip_rect.size.y); - if (storage->frame.current_rt->flags[RendererStorage::RENDER_TARGET_VFLIP]) - y = r_ris.current_clip->final_clip_rect.position.y; - glScissor(r_ris.current_clip->final_clip_rect.position.x, y, r_ris.current_clip->final_clip_rect.size.width, r_ris.current_clip->final_clip_rect.size.height); - } -} -#endif // def GODOT 3 - -void RasterizerCanvasGLES2::gl_enable_scissor(int p_x, int p_y, int p_width, int p_height) const { +void RasterizerCanvasOpenGL::gl_enable_scissor(int p_x, int p_y, int p_width, int p_height) const { glEnable(GL_SCISSOR_TEST); glScissor(p_x, p_y, p_width, p_height); } -void RasterizerCanvasGLES2::gl_disable_scissor() const { +void RasterizerCanvasOpenGL::gl_disable_scissor() const { glDisable(GL_SCISSOR_TEST); } -void RasterizerCanvasGLES2::initialize() { - RasterizerCanvasBaseGLES2::initialize(); +void RasterizerCanvasOpenGL::initialize() { + RasterizerCanvasBaseOpenGL::initialize(); batch_initialize(); @@ -2374,7 +1689,7 @@ void RasterizerCanvasGLES2::initialize() { indices.set(i_pos + 4, q_pos + 2); indices.set(i_pos + 5, q_pos + 3); - // we can only use 16 bit indices in GLES2! + // we can only use 16 bit indices in OpenGL! #ifdef DEBUG_ENABLED CRASH_COND((q_pos + 3) > 65535); #endif @@ -2386,8 +1701,8 @@ void RasterizerCanvasGLES2::initialize() { } // only if there is a vertex buffer (batching is on) } -RasterizerCanvasGLES2::RasterizerCanvasGLES2() { +RasterizerCanvasOpenGL::RasterizerCanvasOpenGL() { batch_constructor(); } -#endif // GLES2_BACKEND_ENABLED +#endif // OPENGL_BACKEND_ENABLED diff --git a/drivers/gles2/rasterizer_canvas_gles2.h b/drivers/opengl/rasterizer_canvas_opengl.h index fd4da5434e..ff5295e739 100644 --- a/drivers/gles2/rasterizer_canvas_gles2.h +++ b/drivers/opengl/rasterizer_canvas_opengl.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* rasterizer_canvas_gles2.h */ +/* rasterizer_canvas_opengl.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,53 +28,19 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef RASTERIZERCANVASGLES2_H -#define RASTERIZERCANVASGLES2_H +#ifndef RASTERIZER_CANVAS_OPENGL_H +#define RASTERIZER_CANVAS_OPENGL_H -#include "drivers/gles_common/rasterizer_platforms.h" -#ifdef GLES2_BACKEND_ENABLED +#include "drivers/opengl/rasterizer_platforms.h" +#ifdef OPENGL_BACKEND_ENABLED -#include "drivers/gles_common/rasterizer_canvas_batcher.h" -#include "drivers/gles_common/rasterizer_version.h" -#include "rasterizer_canvas_base_gles2.h" +#include "drivers/opengl/rasterizer_canvas_batcher.h" +#include "rasterizer_canvas_base_opengl.h" -class RasterizerSceneGLES2; +class RasterizerSceneOpenGL; -class RasterizerCanvasGLES2 : public RasterizerCanvasBaseGLES2, public RasterizerCanvasBatcher<RasterizerCanvasGLES2, RasterizerStorageGLES2> { - friend class RasterizerCanvasBatcher<RasterizerCanvasGLES2, RasterizerStorageGLES2>; - -public: - virtual void canvas_render_items_begin(const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform); - virtual void canvas_render_items_end(); - void canvas_render_items_internal(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform); - virtual void canvas_begin() override; - virtual void canvas_end() override; - - void canvas_render_items(RID p_to_render_target, Item *p_item_list, const Color &p_modulate, Light *p_light_list, Light *p_directional_list, const Transform2D &p_canvas_transform, RS::CanvasItemTextureFilter p_default_filter, RS::CanvasItemTextureRepeat p_default_repeat, bool p_snap_2d_vertices_to_pixel, bool &r_sdf_used) override { - storage->frame.current_rt = nullptr; - - //if (p_to_render_target.is_valid()) - // print_line("canvas_render_items " + itos(p_to_render_target.get_id()) ); - // print_line("canvas_render_items "); - - // first set the current render target - storage->_set_current_render_target(p_to_render_target); - - // binds the render target (framebuffer) - canvas_begin(); - - canvas_render_items_begin(p_modulate, p_light_list, p_canvas_transform); - canvas_render_items_internal(p_item_list, 0, p_modulate, p_light_list, p_canvas_transform); - canvas_render_items_end(); - - canvas_end(); - - // not sure why these are needed to get frame to render? - storage->_set_current_render_target(RID()); - // storage->frame.current_rt = nullptr; - // canvas_begin(); - // canvas_end(); - } +class RasterizerCanvasOpenGL : public RasterizerCanvasBaseOpenGL, public RasterizerCanvasBatcher<RasterizerCanvasOpenGL, RasterizerStorageOpenGL> { + friend class RasterizerCanvasBatcher<RasterizerCanvasOpenGL, RasterizerStorageOpenGL>; private: // legacy codepath .. to remove after testing @@ -82,23 +48,24 @@ private: // high level batch funcs void canvas_render_items_implementation(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform); - //void render_joined_item(const BItemJoined &p_bij, RenderItemState &r_ris); - //bool try_join_item(Item *p_ci, RenderItemState &r_ris, bool &r_batch_break); - void render_batches(Item::Command *const *p_commands, Item *p_current_clip, bool &r_reclip, RasterizerStorageGLES2::Material *p_material); - - // low level batch funcs - // void _batch_upload_buffers(); - // void _batch_render_generic(const Batch &p_batch, RasterizerStorageGLES2::Material *p_material); - // void _batch_render_lines(const Batch &p_batch, RasterizerStorageGLES2::Material *p_material, bool p_anti_alias); + void render_batches(Item::Command *const *p_commands, Item *p_current_clip, bool &r_reclip, RasterizerStorageOpenGL::Material *p_material); // funcs used from rasterizer_canvas_batcher template void gl_enable_scissor(int p_x, int p_y, int p_width, int p_height) const; void gl_disable_scissor() const; public: + void canvas_render_items_begin(const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform); + void canvas_render_items_end(); + void canvas_render_items_internal(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform); + void canvas_begin() override; + void canvas_end() override; + + void canvas_render_items(RID p_to_render_target, Item *p_item_list, const Color &p_modulate, Light *p_light_list, Light *p_directional_list, const Transform2D &p_canvas_transform, RS::CanvasItemTextureFilter p_default_filter, RS::CanvasItemTextureRepeat p_default_repeat, bool p_snap_2d_vertices_to_pixel, bool &r_sdf_used) override; + void initialize(); - RasterizerCanvasGLES2(); + RasterizerCanvasOpenGL(); }; -#endif // GLES2_BACKEND_ENABLED -#endif // RASTERIZERCANVASGLES2_H +#endif // OPENGL_BACKEND_ENABLED +#endif // RASTERIZER_CANVAS_OPENGL_H diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/opengl/rasterizer_opengl.cpp index 222c9b8494..b7eef805c0 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/opengl/rasterizer_opengl.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* rasterizer_gles2.cpp */ +/* rasterizer_opengl.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,10 +28,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "rasterizer_gles2.h" +#include "rasterizer_opengl.h" -#ifdef GLES2_BACKEND_ENABLED -#include "shader_gles2.h" +#ifdef OPENGL_BACKEND_ENABLED +#include "shader_opengl.h" #include "core/config/project_settings.h" #include "core/os/os.h" @@ -87,7 +87,7 @@ #define strcpy strcpy_s #endif -void RasterizerGLES2::begin_frame(double frame_step) { +void RasterizerOpenGL::begin_frame(double frame_step) { frame++; delta = frame_step; @@ -117,7 +117,7 @@ void RasterizerGLES2::begin_frame(double frame_step) { //scene->iteration(); } -void RasterizerGLES2::end_frame(bool p_swap_buffers) { +void RasterizerOpenGL::end_frame(bool p_swap_buffers) { // if (OS::get_singleton()->is_layered_allowed()) { // if (!OS::get_singleton()->get_window_per_pixel_transparency_enabled()) { //clear alpha @@ -196,8 +196,8 @@ typedef void (*DEBUGPROCARB)(GLenum source, typedef void (*DebugMessageCallbackARB)(DEBUGPROCARB callback, const void *userParam); -void RasterizerGLES2::initialize() { - print_verbose("Using GLES2 video driver"); +void RasterizerOpenGL::initialize() { + print_verbose("Using OpenGL video driver"); storage._main_thread_id = Thread::get_caller_id(); @@ -252,7 +252,7 @@ void RasterizerGLES2::initialize() { #endif // GLES_OVER_GL #endif // CAN_DEBUG - print_line("OpenGL ES 2.0 Renderer: " + GD_VS::get_singleton()->get_video_adapter_name()); + print_line("OpenGL Renderer: " + RS::get_singleton()->get_video_adapter_name()); storage.initialize(); canvas.initialize(); // scene.initialize(); @@ -261,7 +261,7 @@ void RasterizerGLES2::initialize() { OS::get_singleton()->set_render_main_thread_mode(OS::RENDER_MAIN_THREAD_ONLY); } -RasterizerGLES2::RasterizerGLES2() { +RasterizerOpenGL::RasterizerOpenGL() { canvas.storage = &storage; canvas.scene_render = &scene; storage.canvas = &canvas; @@ -269,15 +269,15 @@ RasterizerGLES2::RasterizerGLES2() { storage.scene = &scene; } -void RasterizerGLES2::prepare_for_blitting_render_targets() { +void RasterizerOpenGL::prepare_for_blitting_render_targets() { } -void RasterizerGLES2::_blit_render_target_to_screen(RID p_render_target, const Rect2 &p_screen_rect) { +void RasterizerOpenGL::_blit_render_target_to_screen(RID p_render_target, const Rect2 &p_screen_rect) { ERR_FAIL_COND(storage.frame.current_rt); // print_line("_blit_render_target_to_screen " + itos (p_screen) + ", rect " + String(Variant(p_screen_rect))); - RasterizerStorageGLES2::RenderTarget *rt = storage.render_target_owner.getornull(p_render_target); + RasterizerStorageOpenGL::RenderTarget *rt = storage.render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND(!rt); canvas._set_texture_rect_mode(true); @@ -300,7 +300,7 @@ void RasterizerGLES2::_blit_render_target_to_screen(RID p_render_target, const R } // is this p_screen useless in a multi window environment? -void RasterizerGLES2::blit_render_targets_to_screen(DisplayServer::WindowID p_screen, const BlitToScreen *p_render_targets, int p_amount) { +void RasterizerOpenGL::blit_render_targets_to_screen(DisplayServer::WindowID p_screen, const BlitToScreen *p_render_targets, int p_amount) { // do this once off for all blits storage.bind_framebuffer_system(); @@ -316,7 +316,7 @@ void RasterizerGLES2::blit_render_targets_to_screen(DisplayServer::WindowID p_sc } } -void RasterizerGLES2::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter) { +void RasterizerOpenGL::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter) { if (p_image.is_null() || p_image->is_empty()) return; @@ -339,7 +339,7 @@ void RasterizerGLES2::set_boot_image(const Ref<Image> &p_image, const Color &p_c RID texture = storage.texture_create(); //storage.texture_allocate(texture, p_image->get_width(), p_image->get_height(), 0, p_image->get_format(), VS::TEXTURE_TYPE_2D, p_use_filter ? VS::TEXTURE_FLAG_FILTER : 0); - storage._texture_allocate_internal(texture, p_image->get_width(), p_image->get_height(), 0, p_image->get_format(), GD_RD::TEXTURE_TYPE_2D); + storage._texture_allocate_internal(texture, p_image->get_width(), p_image->get_height(), 0, p_image->get_format(), RenderingDevice::TEXTURE_TYPE_2D); storage.texture_set_data(texture, p_image); Rect2 imgrect(0, 0, p_image->get_width(), p_image->get_height()); @@ -362,7 +362,7 @@ void RasterizerGLES2::set_boot_image(const Ref<Image> &p_image, const Color &p_c screenrect.position += ((Size2(window_w, window_h) - screenrect.size) / 2.0).floor(); } - RasterizerStorageGLES2::Texture *t = storage.texture_owner.getornull(texture); + RasterizerStorageOpenGL::Texture *t = storage.texture_owner.get_or_null(texture); glActiveTexture(GL_TEXTURE0 + storage.config.max_texture_image_units - 1); glBindTexture(GL_TEXTURE_2D, t->tex_id); canvas.draw_generic_textured_rect(screenrect, Rect2(0, 0, 1, 1)); @@ -374,4 +374,4 @@ void RasterizerGLES2::set_boot_image(const Ref<Image> &p_image, const Color &p_c end_frame(true); } -#endif // GLES2_BACKEND_ENABLED +#endif // OPENGL_BACKEND_ENABLED diff --git a/drivers/gles2/rasterizer_gles2.h b/drivers/opengl/rasterizer_opengl.h index 3066dc421b..e72c23faf9 100644 --- a/drivers/gles2/rasterizer_gles2.h +++ b/drivers/opengl/rasterizer_opengl.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* rasterizer_gles2.h */ +/* rasterizer_opengl.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,18 +28,18 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#pragma once +#ifndef RASTERIZER_OPENGL_H +#define RASTERIZER_OPENGL_H -#include "drivers/gles_common/rasterizer_platforms.h" -#ifdef GLES2_BACKEND_ENABLED +#include "drivers/opengl/rasterizer_platforms.h" +#ifdef OPENGL_BACKEND_ENABLED -#include "drivers/gles_common/rasterizer_version.h" -#include "rasterizer_canvas_gles2.h" -#include "rasterizer_scene_gles2.h" -#include "rasterizer_storage_gles2.h" +#include "rasterizer_canvas_opengl.h" +#include "rasterizer_scene_opengl.h" +#include "rasterizer_storage_opengl.h" #include "servers/rendering/renderer_compositor.h" -class RasterizerGLES2 : public RendererCompositor { +class RasterizerOpenGL : public RendererCompositor { private: uint64_t frame = 1; float delta = 0; @@ -48,9 +48,9 @@ private: double time_scale = 1.0; protected: - RasterizerCanvasGLES2 canvas; - RasterizerStorageGLES2 storage; - RasterizerSceneGLES2 scene; + RasterizerCanvasOpenGL canvas; + RasterizerStorageOpenGL storage; + RasterizerSceneOpenGL scene; void _blit_render_target_to_screen(RID p_render_target, const Rect2 &p_screen_rect); @@ -72,7 +72,7 @@ public: void finalize() {} static RendererCompositor *_create_current() { - return memnew(RasterizerGLES2); + return memnew(RasterizerOpenGL); } static void make_current() { @@ -83,8 +83,10 @@ public: uint64_t get_frame_number() const { return frame; } double get_frame_delta_time() const { return delta; } - RasterizerGLES2(); - ~RasterizerGLES2() {} + RasterizerOpenGL(); + ~RasterizerOpenGL() {} }; -#endif // GLES2_BACKEND_ENABLED +#endif // OPENGL_BACKEND_ENABLED + +#endif diff --git a/drivers/gles_common/rasterizer_platforms.h b/drivers/opengl/rasterizer_platforms.h index f1b950b71a..effae51819 100644 --- a/drivers/gles_common/rasterizer_platforms.h +++ b/drivers/opengl/rasterizer_platforms.h @@ -28,46 +28,21 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#pragma once +#ifndef RASTERIZER_PLATFORMS_H +#define RASTERIZER_PLATFORMS_H ///////////////////////////////////////////////////// // override for intellisense .. ONLY FOR DEVELOPMENT //#ifndef X11_ENABLED //#define X11_ENABLED //#endif -//#define GLES2_BACKEND_ENABLED +//#define OPENGL_BACKEND_ENABLED ///////////////////////////////////////////////////// #if defined(OPENGL_ENABLED) || defined(GLES_ENABLED) -// platform specific defines to compile in / out GLES support -// these can later be made from Scons -#ifdef X11_ENABLED -#define GLES_X11_ENABLED -#endif - -#ifdef WINDOWS_ENABLED -//#define GLES_WINDOWS_ENABLED -#endif - -#ifdef IPHONE_ENABLED -//#define GLES_IPHONE_ENABLED -#endif - -#ifdef OSX_ENABLED -//#define GLES_OSX_ENABLED -#endif - -#ifdef ANDROID_ENABLED -//#define GLES_ANDROID_ENABLED -#endif - -#if defined(GLES_X11_ENABLED) || defined(GLES_WINDOW_ENABLED) || defined(GLES_IPHONE_ENABLED) || defined(GLES_OSX_ENABLED) || defined(GLES_ANDROID_ENABLED) -#define GLES2_BACKEND_ENABLED -#endif - -#if defined(GLES_X11_ENABLED) || defined(GLES_WINDOW_ENABLED) || defined(GLES_IPHONE_ENABLED) || defined(GLES_OSX_ENABLED) || defined(GLES_ANDROID_ENABLED) -#define GLES3_BACKEND_ENABLED -#endif +#define OPENGL_BACKEND_ENABLED #endif // defined(OPENGL_ENABLED) || defined(GLES_ENABLED) + +#endif // RASTERIZER_PLATFORMS_H diff --git a/drivers/opengl/rasterizer_scene_opengl.cpp b/drivers/opengl/rasterizer_scene_opengl.cpp new file mode 100644 index 0000000000..5895147f94 --- /dev/null +++ b/drivers/opengl/rasterizer_scene_opengl.cpp @@ -0,0 +1,439 @@ +/*************************************************************************/ +/* rasterizer_scene_opengl.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 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 */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "rasterizer_scene_opengl.h" +#ifdef OPENGL_BACKEND_ENABLED + +// TODO: 3D support not implemented yet. + +RasterizerSceneOpenGL::GeometryInstance *RasterizerSceneOpenGL::geometry_instance_create(RID p_base) { + return nullptr; +} + +void RasterizerSceneOpenGL::geometry_instance_set_skeleton(GeometryInstance *p_geometry_instance, RID p_skeleton) { +} + +void RasterizerSceneOpenGL::geometry_instance_set_material_override(GeometryInstance *p_geometry_instance, RID p_override) { +} + +void RasterizerSceneOpenGL::geometry_instance_set_surface_materials(GeometryInstance *p_geometry_instance, const Vector<RID> &p_material) { +} + +void RasterizerSceneOpenGL::geometry_instance_set_mesh_instance(GeometryInstance *p_geometry_instance, RID p_mesh_instance) { +} + +void RasterizerSceneOpenGL::geometry_instance_set_transform(GeometryInstance *p_geometry_instance, const Transform3D &p_transform, const AABB &p_aabb, const AABB &p_transformed_aabbb) { +} + +void RasterizerSceneOpenGL::geometry_instance_set_layer_mask(GeometryInstance *p_geometry_instance, uint32_t p_layer_mask) { +} + +void RasterizerSceneOpenGL::geometry_instance_set_lod_bias(GeometryInstance *p_geometry_instance, float p_lod_bias) { +} + +void RasterizerSceneOpenGL::geometry_instance_set_use_baked_light(GeometryInstance *p_geometry_instance, bool p_enable) { +} + +void RasterizerSceneOpenGL::geometry_instance_set_use_dynamic_gi(GeometryInstance *p_geometry_instance, bool p_enable) { +} + +void RasterizerSceneOpenGL::geometry_instance_set_use_lightmap(GeometryInstance *p_geometry_instance, RID p_lightmap_instance, const Rect2 &p_lightmap_uv_scale, int p_lightmap_slice_index) { +} + +void RasterizerSceneOpenGL::geometry_instance_set_lightmap_capture(GeometryInstance *p_geometry_instance, const Color *p_sh9) { +} + +void RasterizerSceneOpenGL::geometry_instance_set_instance_shader_parameters_offset(GeometryInstance *p_geometry_instance, int32_t p_offset) { +} + +void RasterizerSceneOpenGL::geometry_instance_set_cast_double_sided_shadows(GeometryInstance *p_geometry_instance, bool p_enable) { +} + +uint32_t RasterizerSceneOpenGL::geometry_instance_get_pair_mask() { + return 0; +} + +void RasterizerSceneOpenGL::geometry_instance_pair_light_instances(GeometryInstance *p_geometry_instance, const RID *p_light_instances, uint32_t p_light_instance_count) { +} + +void RasterizerSceneOpenGL::geometry_instance_pair_reflection_probe_instances(GeometryInstance *p_geometry_instance, const RID *p_reflection_probe_instances, uint32_t p_reflection_probe_instance_count) { +} + +void RasterizerSceneOpenGL::geometry_instance_pair_decal_instances(GeometryInstance *p_geometry_instance, const RID *p_decal_instances, uint32_t p_decal_instance_count) { +} + +void RasterizerSceneOpenGL::geometry_instance_pair_voxel_gi_instances(GeometryInstance *p_geometry_instance, const RID *p_voxel_gi_instances, uint32_t p_voxel_gi_instance_count) { +} + +void RasterizerSceneOpenGL::geometry_instance_set_softshadow_projector_pairing(GeometryInstance *p_geometry_instance, bool p_softshadow, bool p_projector) { +} + +void RasterizerSceneOpenGL::geometry_instance_free(GeometryInstance *p_geometry_instance) { +} + +/* SHADOW ATLAS API */ + +RID RasterizerSceneOpenGL::shadow_atlas_create() { + return RID(); +} + +void RasterizerSceneOpenGL::shadow_atlas_set_size(RID p_atlas, int p_size, bool p_16_bits) { +} + +void RasterizerSceneOpenGL::shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision) { +} + +bool RasterizerSceneOpenGL::shadow_atlas_update_light(RID p_atlas, RID p_light_intance, float p_coverage, uint64_t p_light_version) { + return false; +} + +void RasterizerSceneOpenGL::directional_shadow_atlas_set_size(int p_size, bool p_16_bits) { +} + +int RasterizerSceneOpenGL::get_directional_light_shadow_size(RID p_light_intance) { + return 0; +} + +void RasterizerSceneOpenGL::set_directional_shadow_count(int p_count) { +} + +/* SDFGI UPDATE */ + +void RasterizerSceneOpenGL::sdfgi_update(RID p_render_buffers, RID p_environment, const Vector3 &p_world_position) { +} + +int RasterizerSceneOpenGL::sdfgi_get_pending_region_count(RID p_render_buffers) const { + return 0; +} + +AABB RasterizerSceneOpenGL::sdfgi_get_pending_region_bounds(RID p_render_buffers, int p_region) const { + return AABB(); +} + +uint32_t RasterizerSceneOpenGL::sdfgi_get_pending_region_cascade(RID p_render_buffers, int p_region) const { + return 0; +} + +/* SKY API */ + +RID RasterizerSceneOpenGL::sky_allocate() { + return RID(); +} + +void RasterizerSceneOpenGL::sky_initialize(RID p_rid) { +} + +void RasterizerSceneOpenGL::sky_set_radiance_size(RID p_sky, int p_radiance_size) { +} + +void RasterizerSceneOpenGL::sky_set_mode(RID p_sky, RS::SkyMode p_samples) { +} + +void RasterizerSceneOpenGL::sky_set_material(RID p_sky, RID p_material) { +} + +Ref<Image> RasterizerSceneOpenGL::sky_bake_panorama(RID p_sky, float p_energy, bool p_bake_irradiance, const Size2i &p_size) { + return Ref<Image>(); +} + +/* ENVIRONMENT API */ + +RID RasterizerSceneOpenGL::environment_allocate() { + return RID(); +} + +void RasterizerSceneOpenGL::environment_initialize(RID p_rid) { +} + +void RasterizerSceneOpenGL::environment_set_background(RID p_env, RS::EnvironmentBG p_bg) { +} + +void RasterizerSceneOpenGL::environment_set_sky(RID p_env, RID p_sky) { +} + +void RasterizerSceneOpenGL::environment_set_sky_custom_fov(RID p_env, float p_scale) { +} + +void RasterizerSceneOpenGL::environment_set_sky_orientation(RID p_env, const Basis &p_orientation) { +} + +void RasterizerSceneOpenGL::environment_set_bg_color(RID p_env, const Color &p_color) { +} + +void RasterizerSceneOpenGL::environment_set_bg_energy(RID p_env, float p_energy) { +} + +void RasterizerSceneOpenGL::environment_set_canvas_max_layer(RID p_env, int p_max_layer) { +} + +void RasterizerSceneOpenGL::environment_set_ambient_light(RID p_env, const Color &p_color, RS::EnvironmentAmbientSource p_ambient, float p_energy, float p_sky_contribution, RS::EnvironmentReflectionSource p_reflection_source) { +} + +void RasterizerSceneOpenGL::environment_set_glow(RID p_env, bool p_enable, Vector<float> p_levels, float p_intensity, float p_strength, float p_mix, float p_bloom_threshold, RS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap) { +} + +void RasterizerSceneOpenGL::environment_glow_set_use_bicubic_upscale(bool p_enable) { +} + +void RasterizerSceneOpenGL::environment_glow_set_use_high_quality(bool p_enable) { +} + +void RasterizerSceneOpenGL::environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance) { +} + +void RasterizerSceneOpenGL::environment_set_ssr_roughness_quality(RS::EnvironmentSSRRoughnessQuality p_quality) { +} + +void RasterizerSceneOpenGL::environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_power, float p_detail, float p_horizon, float p_sharpness, float p_light_affect, float p_ao_channel_affect) { +} + +void RasterizerSceneOpenGL::environment_set_ssao_quality(RS::EnvironmentSSAOQuality p_quality, bool p_half_size, float p_adaptive_target, int p_blur_passes, float p_fadeout_from, float p_fadeout_to) { +} + +void RasterizerSceneOpenGL::environment_set_sdfgi(RID p_env, bool p_enable, RS::EnvironmentSDFGICascades p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) { +} + +void RasterizerSceneOpenGL::environment_set_sdfgi_ray_count(RS::EnvironmentSDFGIRayCount p_ray_count) { +} + +void RasterizerSceneOpenGL::environment_set_sdfgi_frames_to_converge(RS::EnvironmentSDFGIFramesToConverge p_frames) { +} + +void RasterizerSceneOpenGL::environment_set_sdfgi_frames_to_update_light(RS::EnvironmentSDFGIFramesToUpdateLight p_update) { +} + +void RasterizerSceneOpenGL::environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale) { +} + +void RasterizerSceneOpenGL::environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, bool p_use_1d_color_correction, RID p_color_correction) { +} + +void RasterizerSceneOpenGL::environment_set_fog(RID p_env, bool p_enable, const Color &p_light_color, float p_light_energy, float p_sun_scatter, float p_density, float p_height, float p_height_density, float p_aerial_perspective) { +} + +void RasterizerSceneOpenGL::environment_set_volumetric_fog(RID p_env, bool p_enable, float p_density, const Color &p_light, float p_light_energy, float p_length, float p_detail_spread, float p_gi_inject, bool p_temporal_reprojection, float p_temporal_reprojection_amount) { +} + +void RasterizerSceneOpenGL::environment_set_volumetric_fog_volume_size(int p_size, int p_depth) { +} + +void RasterizerSceneOpenGL::environment_set_volumetric_fog_filter_active(bool p_enable) { +} + +Ref<Image> RasterizerSceneOpenGL::environment_bake_panorama(RID p_env, bool p_bake_irradiance, const Size2i &p_size) { + return Ref<Image>(); +} + +bool RasterizerSceneOpenGL::is_environment(RID p_env) const { + return false; +} + +RS::EnvironmentBG RasterizerSceneOpenGL::environment_get_background(RID p_env) const { + return RS::ENV_BG_KEEP; +} + +int RasterizerSceneOpenGL::environment_get_canvas_max_layer(RID p_env) const { + return 0; +} + +RID RasterizerSceneOpenGL::camera_effects_allocate() { + return RID(); +} + +void RasterizerSceneOpenGL::camera_effects_initialize(RID p_rid) { +} + +void RasterizerSceneOpenGL::camera_effects_set_dof_blur_quality(RS::DOFBlurQuality p_quality, bool p_use_jitter) { +} + +void RasterizerSceneOpenGL::camera_effects_set_dof_blur_bokeh_shape(RS::DOFBokehShape p_shape) { +} + +void RasterizerSceneOpenGL::camera_effects_set_dof_blur(RID p_camera_effects, bool p_far_enable, float p_far_distance, float p_far_transition, bool p_near_enable, float p_near_distance, float p_near_transition, float p_amount) { +} + +void RasterizerSceneOpenGL::camera_effects_set_custom_exposure(RID p_camera_effects, bool p_enable, float p_exposure) { +} + +void RasterizerSceneOpenGL::shadows_quality_set(RS::ShadowQuality p_quality) { +} + +void RasterizerSceneOpenGL::directional_shadow_quality_set(RS::ShadowQuality p_quality) { +} + +RID RasterizerSceneOpenGL::light_instance_create(RID p_light) { + return RID(); +} + +void RasterizerSceneOpenGL::light_instance_set_transform(RID p_light_instance, const Transform3D &p_transform) { +} + +void RasterizerSceneOpenGL::light_instance_set_aabb(RID p_light_instance, const AABB &p_aabb) { +} + +void RasterizerSceneOpenGL::light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform3D &p_transform, float p_far, float p_split, int p_pass, float p_shadow_texel_size, float p_bias_scale, float p_range_begin, const Vector2 &p_uv_scale) { +} + +void RasterizerSceneOpenGL::light_instance_mark_visible(RID p_light_instance) { +} + +RID RasterizerSceneOpenGL::reflection_atlas_create() { + return RID(); +} + +int RasterizerSceneOpenGL::reflection_atlas_get_size(RID p_ref_atlas) const { + return 0; +} + +void RasterizerSceneOpenGL::reflection_atlas_set_size(RID p_ref_atlas, int p_reflection_size, int p_reflection_count) { +} + +RID RasterizerSceneOpenGL::reflection_probe_instance_create(RID p_probe) { + return RID(); +} + +void RasterizerSceneOpenGL::reflection_probe_instance_set_transform(RID p_instance, const Transform3D &p_transform) { +} + +void RasterizerSceneOpenGL::reflection_probe_release_atlas_index(RID p_instance) { +} + +bool RasterizerSceneOpenGL::reflection_probe_instance_needs_redraw(RID p_instance) { + return false; +} + +bool RasterizerSceneOpenGL::reflection_probe_instance_has_reflection(RID p_instance) { + return false; +} + +bool RasterizerSceneOpenGL::reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas) { + return false; +} + +bool RasterizerSceneOpenGL::reflection_probe_instance_postprocess_step(RID p_instance) { + return true; +} + +RID RasterizerSceneOpenGL::decal_instance_create(RID p_decal) { + return RID(); +} + +void RasterizerSceneOpenGL::decal_instance_set_transform(RID p_decal, const Transform3D &p_transform) { +} + +RID RasterizerSceneOpenGL::lightmap_instance_create(RID p_lightmap) { + return RID(); +} + +void RasterizerSceneOpenGL::lightmap_instance_set_transform(RID p_lightmap, const Transform3D &p_transform) { +} + +RID RasterizerSceneOpenGL::voxel_gi_instance_create(RID p_voxel_gi) { + return RID(); +} + +void RasterizerSceneOpenGL::voxel_gi_instance_set_transform_to_data(RID p_probe, const Transform3D &p_xform) { +} + +bool RasterizerSceneOpenGL::voxel_gi_needs_update(RID p_probe) const { + return false; +} + +void RasterizerSceneOpenGL::voxel_gi_update(RID p_probe, bool p_update_light_instances, const Vector<RID> &p_light_instances, const PagedArray<RendererSceneRender::GeometryInstance *> &p_dynamic_objects) { +} + +void RasterizerSceneOpenGL::voxel_gi_set_quality(RS::VoxelGIQuality) { +} + +void RasterizerSceneOpenGL::render_scene(RID p_render_buffers, const CameraData *p_camera_data, const PagedArray<GeometryInstance *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_voxel_gi_instances, const PagedArray<RID> &p_decals, const PagedArray<RID> &p_lightmaps, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_occluder_debug_tex, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_lod_threshold, const RenderShadowData *p_render_shadows, int p_render_shadow_count, const RenderSDFGIData *p_render_sdfgi_regions, int p_render_sdfgi_region_count, const RenderSDFGIUpdateData *p_sdfgi_update_data, RendererScene::RenderInfo *r_info) { +} + +void RasterizerSceneOpenGL::render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) { +} + +void RasterizerSceneOpenGL::render_particle_collider_heightfield(RID p_collider, const Transform3D &p_transform, const PagedArray<GeometryInstance *> &p_instances) { +} + +void RasterizerSceneOpenGL::set_scene_pass(uint64_t p_pass) { +} + +void RasterizerSceneOpenGL::set_time(double p_time, double p_step) { +} + +void RasterizerSceneOpenGL::set_debug_draw_mode(RS::ViewportDebugDraw p_debug_draw) { +} + +RID RasterizerSceneOpenGL::render_buffers_create() { + return RID(); +} + +void RasterizerSceneOpenGL::render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_width, int p_height, RS::ViewportMSAA p_msaa, RS::ViewportScreenSpaceAA p_screen_space_aa, bool p_use_debanding, uint32_t p_view_count) { +} + +void RasterizerSceneOpenGL::gi_set_use_half_resolution(bool p_enable) { +} + +void RasterizerSceneOpenGL::screen_space_roughness_limiter_set_active(bool p_enable, float p_amount, float p_curve) { +} + +bool RasterizerSceneOpenGL::screen_space_roughness_limiter_is_active() const { + return false; +} + +void RasterizerSceneOpenGL::sub_surface_scattering_set_quality(RS::SubSurfaceScatteringQuality p_quality) { +} + +void RasterizerSceneOpenGL::sub_surface_scattering_set_scale(float p_scale, float p_depth_scale) { +} + +TypedArray<Image> RasterizerSceneOpenGL::bake_render_uv2(RID p_base, const Vector<RID> &p_material_overrides, const Size2i &p_image_size) { + return TypedArray<Image>(); +} + +bool RasterizerSceneOpenGL::free(RID p_rid) { + return false; +} + +void RasterizerSceneOpenGL::update() { +} + +void RasterizerSceneOpenGL::sdfgi_set_debug_probe_select(const Vector3 &p_position, const Vector3 &p_dir) { +} + +void RasterizerSceneOpenGL::decals_set_filter(RS::DecalFilter p_filter) { +} + +void RasterizerSceneOpenGL::light_projectors_set_filter(RS::LightProjectorFilter p_filter) { +} + +RasterizerSceneOpenGL::RasterizerSceneOpenGL() { +} + +#endif // OPENGL_BACKEND_ENABLED diff --git a/drivers/opengl/rasterizer_scene_opengl.h b/drivers/opengl/rasterizer_scene_opengl.h new file mode 100644 index 0000000000..2ae7633ba3 --- /dev/null +++ b/drivers/opengl/rasterizer_scene_opengl.h @@ -0,0 +1,220 @@ +/*************************************************************************/ +/* rasterizer_scene_opengl.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 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 */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef RASTERIZER_SCENE_OPENGL_H +#define RASTERIZER_SCENE_OPENGL_H + +#include "drivers/opengl/rasterizer_platforms.h" +#ifdef OPENGL_BACKEND_ENABLED + +#include "core/math/camera_matrix.h" +#include "core/templates/rid_owner.h" +#include "core/templates/self_list.h" +#include "scene/resources/mesh.h" +#include "servers/rendering/renderer_compositor.h" +#include "servers/rendering/renderer_scene_render.h" +#include "servers/rendering_server.h" +#include "shaders/scene.glsl.gen.h" + +class RasterizerSceneOpenGL : public RendererSceneRender { +public: + struct State { + SceneShaderOpenGL scene_shader; + } state; + + GeometryInstance *geometry_instance_create(RID p_base) override; + void geometry_instance_set_skeleton(GeometryInstance *p_geometry_instance, RID p_skeleton) override; + void geometry_instance_set_material_override(GeometryInstance *p_geometry_instance, RID p_override) override; + void geometry_instance_set_surface_materials(GeometryInstance *p_geometry_instance, const Vector<RID> &p_material) override; + void geometry_instance_set_mesh_instance(GeometryInstance *p_geometry_instance, RID p_mesh_instance) override; + void geometry_instance_set_transform(GeometryInstance *p_geometry_instance, const Transform3D &p_transform, const AABB &p_aabb, const AABB &p_transformed_aabbb) override; + void geometry_instance_set_layer_mask(GeometryInstance *p_geometry_instance, uint32_t p_layer_mask) override; + void geometry_instance_set_lod_bias(GeometryInstance *p_geometry_instance, float p_lod_bias) override; + void geometry_instance_set_use_baked_light(GeometryInstance *p_geometry_instance, bool p_enable) override; + void geometry_instance_set_use_dynamic_gi(GeometryInstance *p_geometry_instance, bool p_enable) override; + void geometry_instance_set_use_lightmap(GeometryInstance *p_geometry_instance, RID p_lightmap_instance, const Rect2 &p_lightmap_uv_scale, int p_lightmap_slice_index) override; + void geometry_instance_set_lightmap_capture(GeometryInstance *p_geometry_instance, const Color *p_sh9) override; + void geometry_instance_set_instance_shader_parameters_offset(GeometryInstance *p_geometry_instance, int32_t p_offset) override; + void geometry_instance_set_cast_double_sided_shadows(GeometryInstance *p_geometry_instance, bool p_enable) override; + + uint32_t geometry_instance_get_pair_mask() override; + void geometry_instance_pair_light_instances(GeometryInstance *p_geometry_instance, const RID *p_light_instances, uint32_t p_light_instance_count) override; + void geometry_instance_pair_reflection_probe_instances(GeometryInstance *p_geometry_instance, const RID *p_reflection_probe_instances, uint32_t p_reflection_probe_instance_count) override; + void geometry_instance_pair_decal_instances(GeometryInstance *p_geometry_instance, const RID *p_decal_instances, uint32_t p_decal_instance_count) override; + void geometry_instance_pair_voxel_gi_instances(GeometryInstance *p_geometry_instance, const RID *p_voxel_gi_instances, uint32_t p_voxel_gi_instance_count) override; + void geometry_instance_set_softshadow_projector_pairing(GeometryInstance *p_geometry_instance, bool p_softshadow, bool p_projector) override; + + void geometry_instance_free(GeometryInstance *p_geometry_instance) override; + + /* SHADOW ATLAS API */ + + RID shadow_atlas_create() override; + void shadow_atlas_set_size(RID p_atlas, int p_size, bool p_16_bits = false) override; + void shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision) override; + bool shadow_atlas_update_light(RID p_atlas, RID p_light_intance, float p_coverage, uint64_t p_light_version) override; + + void directional_shadow_atlas_set_size(int p_size, bool p_16_bits = false) override; + int get_directional_light_shadow_size(RID p_light_intance) override; + void set_directional_shadow_count(int p_count) override; + + /* SDFGI UPDATE */ + + void sdfgi_update(RID p_render_buffers, RID p_environment, const Vector3 &p_world_position) override; + int sdfgi_get_pending_region_count(RID p_render_buffers) const override; + AABB sdfgi_get_pending_region_bounds(RID p_render_buffers, int p_region) const override; + uint32_t sdfgi_get_pending_region_cascade(RID p_render_buffers, int p_region) const override; + + /* SKY API */ + + RID sky_allocate() override; + void sky_initialize(RID p_rid) override; + void sky_set_radiance_size(RID p_sky, int p_radiance_size) override; + void sky_set_mode(RID p_sky, RS::SkyMode p_samples) override; + void sky_set_material(RID p_sky, RID p_material) override; + Ref<Image> sky_bake_panorama(RID p_sky, float p_energy, bool p_bake_irradiance, const Size2i &p_size) override; + + /* ENVIRONMENT API */ + + RID environment_allocate() override; + void environment_initialize(RID p_rid) override; + void environment_set_background(RID p_env, RS::EnvironmentBG p_bg) override; + void environment_set_sky(RID p_env, RID p_sky) override; + void environment_set_sky_custom_fov(RID p_env, float p_scale) override; + void environment_set_sky_orientation(RID p_env, const Basis &p_orientation) override; + void environment_set_bg_color(RID p_env, const Color &p_color) override; + void environment_set_bg_energy(RID p_env, float p_energy) override; + void environment_set_canvas_max_layer(RID p_env, int p_max_layer) override; + void environment_set_ambient_light(RID p_env, const Color &p_color, RS::EnvironmentAmbientSource p_ambient = RS::ENV_AMBIENT_SOURCE_BG, float p_energy = 1.0, float p_sky_contribution = 0.0, RS::EnvironmentReflectionSource p_reflection_source = RS::ENV_REFLECTION_SOURCE_BG) override; + + void environment_set_glow(RID p_env, bool p_enable, Vector<float> p_levels, float p_intensity, float p_strength, float p_mix, float p_bloom_threshold, RS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap) override; + void environment_glow_set_use_bicubic_upscale(bool p_enable) override; + void environment_glow_set_use_high_quality(bool p_enable) override; + + void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance) override; + void environment_set_ssr_roughness_quality(RS::EnvironmentSSRRoughnessQuality p_quality) override; + void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_power, float p_detail, float p_horizon, float p_sharpness, float p_light_affect, float p_ao_channel_affect) override; + void environment_set_ssao_quality(RS::EnvironmentSSAOQuality p_quality, bool p_half_size, float p_adaptive_target, int p_blur_passes, float p_fadeout_from, float p_fadeout_to) override; + + void environment_set_sdfgi(RID p_env, bool p_enable, RS::EnvironmentSDFGICascades p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) override; + + void environment_set_sdfgi_ray_count(RS::EnvironmentSDFGIRayCount p_ray_count) override; + void environment_set_sdfgi_frames_to_converge(RS::EnvironmentSDFGIFramesToConverge p_frames) override; + void environment_set_sdfgi_frames_to_update_light(RS::EnvironmentSDFGIFramesToUpdateLight p_update) override; + + void environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale) override; + + void environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, bool p_use_1d_color_correction, RID p_color_correction) override; + + void environment_set_fog(RID p_env, bool p_enable, const Color &p_light_color, float p_light_energy, float p_sun_scatter, float p_density, float p_height, float p_height_density, float p_aerial_perspective) override; + void environment_set_volumetric_fog(RID p_env, bool p_enable, float p_density, const Color &p_light, float p_light_energy, float p_length, float p_detail_spread, float p_gi_inject, bool p_temporal_reprojection, float p_temporal_reprojection_amount) override; + void environment_set_volumetric_fog_volume_size(int p_size, int p_depth) override; + void environment_set_volumetric_fog_filter_active(bool p_enable) override; + + Ref<Image> environment_bake_panorama(RID p_env, bool p_bake_irradiance, const Size2i &p_size) override; + + bool is_environment(RID p_env) const override; + RS::EnvironmentBG environment_get_background(RID p_env) const override; + int environment_get_canvas_max_layer(RID p_env) const override; + + RID camera_effects_allocate() override; + void camera_effects_initialize(RID p_rid) override; + void camera_effects_set_dof_blur_quality(RS::DOFBlurQuality p_quality, bool p_use_jitter) override; + void camera_effects_set_dof_blur_bokeh_shape(RS::DOFBokehShape p_shape) override; + + void camera_effects_set_dof_blur(RID p_camera_effects, bool p_far_enable, float p_far_distance, float p_far_transition, bool p_near_enable, float p_near_distance, float p_near_transition, float p_amount) override; + void camera_effects_set_custom_exposure(RID p_camera_effects, bool p_enable, float p_exposure) override; + + void shadows_quality_set(RS::ShadowQuality p_quality) override; + void directional_shadow_quality_set(RS::ShadowQuality p_quality) override; + + RID light_instance_create(RID p_light) override; + void light_instance_set_transform(RID p_light_instance, const Transform3D &p_transform) override; + void light_instance_set_aabb(RID p_light_instance, const AABB &p_aabb) override; + void light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform3D &p_transform, float p_far, float p_split, int p_pass, float p_shadow_texel_size, float p_bias_scale = 1.0, float p_range_begin = 0, const Vector2 &p_uv_scale = Vector2()) override; + void light_instance_mark_visible(RID p_light_instance) override; + + RID reflection_atlas_create() override; + int reflection_atlas_get_size(RID p_ref_atlas) const override; + void reflection_atlas_set_size(RID p_ref_atlas, int p_reflection_size, int p_reflection_count) override; + + RID reflection_probe_instance_create(RID p_probe) override; + void reflection_probe_instance_set_transform(RID p_instance, const Transform3D &p_transform) override; + void reflection_probe_release_atlas_index(RID p_instance) override; + bool reflection_probe_instance_needs_redraw(RID p_instance) override; + bool reflection_probe_instance_has_reflection(RID p_instance) override; + bool reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas) override; + bool reflection_probe_instance_postprocess_step(RID p_instance) override; + + RID decal_instance_create(RID p_decal) override; + void decal_instance_set_transform(RID p_decal, const Transform3D &p_transform) override; + + RID lightmap_instance_create(RID p_lightmap) override; + void lightmap_instance_set_transform(RID p_lightmap, const Transform3D &p_transform) override; + + RID voxel_gi_instance_create(RID p_voxel_gi) override; + void voxel_gi_instance_set_transform_to_data(RID p_probe, const Transform3D &p_xform) override; + bool voxel_gi_needs_update(RID p_probe) const override; + void voxel_gi_update(RID p_probe, bool p_update_light_instances, const Vector<RID> &p_light_instances, const PagedArray<RendererSceneRender::GeometryInstance *> &p_dynamic_objects) override; + + void voxel_gi_set_quality(RS::VoxelGIQuality) override; + + void render_scene(RID p_render_buffers, const CameraData *p_camera_data, const PagedArray<GeometryInstance *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_voxel_gi_instances, const PagedArray<RID> &p_decals, const PagedArray<RID> &p_lightmaps, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_occluder_debug_tex, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_lod_threshold, const RenderShadowData *p_render_shadows, int p_render_shadow_count, const RenderSDFGIData *p_render_sdfgi_regions, int p_render_sdfgi_region_count, const RenderSDFGIUpdateData *p_sdfgi_update_data = nullptr, RendererScene::RenderInfo *r_info = nullptr) override; + void render_material(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, const PagedArray<GeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override; + void render_particle_collider_heightfield(RID p_collider, const Transform3D &p_transform, const PagedArray<GeometryInstance *> &p_instances) override; + + void set_scene_pass(uint64_t p_pass) override; + void set_time(double p_time, double p_step) override; + void set_debug_draw_mode(RS::ViewportDebugDraw p_debug_draw) override; + + RID render_buffers_create() override; + void render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_width, int p_height, RS::ViewportMSAA p_msaa, RS::ViewportScreenSpaceAA p_screen_space_aa, bool p_use_debanding, uint32_t p_view_count) override; + void gi_set_use_half_resolution(bool p_enable) override; + + void screen_space_roughness_limiter_set_active(bool p_enable, float p_amount, float p_curve) override; + bool screen_space_roughness_limiter_is_active() const override; + + void sub_surface_scattering_set_quality(RS::SubSurfaceScatteringQuality p_quality) override; + void sub_surface_scattering_set_scale(float p_scale, float p_depth_scale) override; + + TypedArray<Image> bake_render_uv2(RID p_base, const Vector<RID> &p_material_overrides, const Size2i &p_image_size) override; + + bool free(RID p_rid) override; + void update() override; + void sdfgi_set_debug_probe_select(const Vector3 &p_position, const Vector3 &p_dir) override; + + void decals_set_filter(RS::DecalFilter p_filter) override; + void light_projectors_set_filter(RS::LightProjectorFilter p_filter) override; + + RasterizerSceneOpenGL(); +}; + +#endif // OPENGL_BACKEND_ENABLED + +#endif // RASTERIZER_SCENE_OPENGL_H diff --git a/drivers/gles_common/rasterizer_storage_common.h b/drivers/opengl/rasterizer_storage_common.h index ed64b8c50a..ed64b8c50a 100644 --- a/drivers/gles_common/rasterizer_storage_common.h +++ b/drivers/opengl/rasterizer_storage_common.h diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/opengl/rasterizer_storage_opengl.cpp index 046a9d5b96..99665dcbb8 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/opengl/rasterizer_storage_opengl.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* rasterizer_storage_gles2.cpp */ +/* rasterizer_storage_opengl.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,19 +28,19 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -//#define GLES2_DISABLE_RENDER_TARGETS +//#define OPENGL_DISABLE_RENDER_TARGETS -#include "rasterizer_storage_gles2.h" -#ifdef GLES2_BACKEND_ENABLED +#include "rasterizer_storage_opengl.h" +#ifdef OPENGL_BACKEND_ENABLED #include "core/config/project_settings.h" #include "core/math/transform_3d.h" -#include "drivers/gles_common/rasterizer_storage_common.h" -#include "rasterizer_canvas_gles2.h" -#include "rasterizer_scene_gles2.h" +#include "drivers/opengl/rasterizer_storage_common.h" +#include "rasterizer_canvas_opengl.h" +#include "rasterizer_scene_opengl.h" #include "servers/rendering/shader_language.h" -GLuint RasterizerStorageGLES2::system_fbo = 0; +GLuint RasterizerStorageOpenGL::system_fbo = 0; /* TEXTURE API */ @@ -119,16 +119,20 @@ PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXTPROC glFramebufferTexture2DMultisampleEXT #define GL_MAX_SAMPLES 0x8D57 #endif //!GLES_OVER_GL -void RasterizerStorageGLES2::bind_quad_array() const { +void RasterizerStorageOpenGL::bind_quad_array() const { glBindBuffer(GL_ARRAY_BUFFER, resources.quadie); - glVertexAttribPointer(GD_VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, 0); - glVertexAttribPointer(GD_VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, CAST_INT_TO_UCHAR_PTR(8)); + glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, 0); + glVertexAttribPointer(RS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, CAST_INT_TO_UCHAR_PTR(8)); - glEnableVertexAttribArray(GD_VS::ARRAY_VERTEX); - glEnableVertexAttribArray(GD_VS::ARRAY_TEX_UV); + glEnableVertexAttribArray(RS::ARRAY_VERTEX); + glEnableVertexAttribArray(RS::ARRAY_TEX_UV); } -Ref<Image> RasterizerStorageGLES2::_get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, Image::Format &r_real_format, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool p_force_decompress) const { +bool RasterizerStorageOpenGL::can_create_resources_async() const { + return false; +} + +Ref<Image> RasterizerStorageOpenGL::_get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, Image::Format &r_real_format, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool p_force_decompress) const { r_gl_format = 0; Ref<Image> image = p_image; r_compressed = false; @@ -352,10 +356,7 @@ Ref<Image> RasterizerStorageGLES2::_get_gl_image_and_format(const Ref<Image> &p_ need_decompress = true; } } break; -#if 0 - // these have changed in the enum, no idea about PVR formats so left out for now - // FTODO - case Image::FORMAT_PVRTC2: { + case Image::FORMAT_PVRTC1_2: { if (config.pvrtc_supported) { r_gl_internal_format = _EXT_COMPRESSED_RGB_PVRTC_2BPPV1_IMG; r_gl_format = GL_RGBA; @@ -366,7 +367,7 @@ Ref<Image> RasterizerStorageGLES2::_get_gl_image_and_format(const Ref<Image> &p_ need_decompress = true; } } break; - case Image::FORMAT_PVRTC2A: { + case Image::FORMAT_PVRTC1_2A: { if (config.pvrtc_supported) { r_gl_internal_format = _EXT_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; r_gl_format = GL_RGBA; @@ -378,7 +379,7 @@ Ref<Image> RasterizerStorageGLES2::_get_gl_image_and_format(const Ref<Image> &p_ } } break; - case Image::FORMAT_PVRTC4: { + case Image::FORMAT_PVRTC1_4: { if (config.pvrtc_supported) { r_gl_internal_format = _EXT_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; r_gl_format = GL_RGBA; @@ -390,7 +391,7 @@ Ref<Image> RasterizerStorageGLES2::_get_gl_image_and_format(const Ref<Image> &p_ } } break; - case Image::FORMAT_PVRTC4A: { + case Image::FORMAT_PVRTC1_4A: { if (config.pvrtc_supported) { r_gl_internal_format = _EXT_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; r_gl_format = GL_RGBA; @@ -402,7 +403,6 @@ Ref<Image> RasterizerStorageGLES2::_get_gl_image_and_format(const Ref<Image> &p_ } } break; -#endif case Image::FORMAT_ETC: { if (config.etc1_supported) { r_gl_internal_format = _EXT_ETC1_RGB8_OES; @@ -435,7 +435,7 @@ Ref<Image> RasterizerStorageGLES2::_get_gl_image_and_format(const Ref<Image> &p_ need_decompress = true; } break; default: { - ERR_FAIL_V(Ref<Image>()); + ERR_FAIL_V(p_image); } } @@ -486,62 +486,76 @@ static const GLenum _cube_side_enum[6] = { GL_TEXTURE_CUBE_MAP_POSITIVE_Z, }; -RID RasterizerStorageGLES2::texture_allocate() { +RID RasterizerStorageOpenGL::texture_allocate() { RID id = texture_create(); ERR_FAIL_COND_V(id == RID(), id); return id; } -void RasterizerStorageGLES2::texture_2d_initialize(RID p_texture, const Ref<Image> &p_image) { - // Texture *tex = texture_owner.getornull(p_texture); - // ERR_FAIL_COND(!tex); +void RasterizerStorageOpenGL::texture_2d_initialize(RID p_texture, const Ref<Image> &p_image) { + Texture *tex = texture_owner.get_or_null(p_texture); + ERR_FAIL_COND(!tex); int w = p_image->get_width(); int h = p_image->get_height(); - _texture_allocate_internal(p_texture, w, h, 1, p_image->get_format(), GD_RD::TEXTURE_TYPE_2D, 0); + _texture_allocate_internal(p_texture, w, h, 1, p_image->get_format(), RenderingDevice::TEXTURE_TYPE_2D, 0); texture_set_data(p_texture, p_image); } -//RID RasterizerStorageGLES2::texture_2d_create(const Ref<Image> &p_image) { +void RasterizerStorageOpenGL::texture_2d_layered_initialize(RID p_texture, const Vector<Ref<Image>> &p_layers, RS::TextureLayeredType p_layered_type) { +} + +void RasterizerStorageOpenGL::texture_3d_initialize(RID p_texture, Image::Format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_data) { +} + +void RasterizerStorageOpenGL::texture_proxy_initialize(RID p_texture, RID p_base) { +} + +//RID RasterizerStorageOpenGL::texture_2d_create(const Ref<Image> &p_image) { // RID id = texture_create(); // ERR_FAIL_COND_V(id == RID(), id); // int w = p_image->get_width(); // int h = p_image->get_height(); -// texture_allocate(id, w, h, 1, p_image->get_format(), GD_RD::TEXTURE_TYPE_2D, 0); +// texture_allocate(id, w, h, 1, p_image->get_format(), RenderingDevice::TEXTURE_TYPE_2D, 0); // texture_set_data(id, p_image); // return id; //} -//RID RasterizerStorageGLES2::texture_2d_layered_create(const Vector<Ref<Image>> &p_layers, RS::TextureLayeredType p_layered_type) { +//RID RasterizerStorageOpenGL::texture_2d_layered_create(const Vector<Ref<Image>> &p_layers, RS::TextureLayeredType p_layered_type) { // return RID(); //} -//RID RasterizerStorageGLES2::texture_proxy_create(RID p_base) { +//RID RasterizerStorageOpenGL::texture_proxy_create(RID p_base) { // RID link = texture_create(); // texture_set_proxy(link, p_base); // return link; //} -//void RasterizerStorageGLES2::texture_2d_update_immediate(RID p_texture, const Ref<Image> &p_image, int p_layer) { +//void RasterizerStorageOpenGL::texture_2d_update_immediate(RID p_texture, const Ref<Image> &p_image, int p_layer) { // // only 1 layer so far // texture_set_data(p_texture, p_image); //} -void RasterizerStorageGLES2::texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer) { +void RasterizerStorageOpenGL::texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer) { // only 1 layer so far texture_set_data(p_texture, p_image); } -//RID RasterizerStorageGLES2::texture_2d_placeholder_create() { -// return RID(); -//} +void RasterizerStorageOpenGL::texture_2d_placeholder_initialize(RID p_texture) { +} + +void RasterizerStorageOpenGL::texture_2d_layered_placeholder_initialize(RID p_texture, RenderingServer::TextureLayeredType p_layered_type) { +} + +void RasterizerStorageOpenGL::texture_3d_placeholder_initialize(RID p_texture) { +} -Ref<Image> RasterizerStorageGLES2::texture_2d_get(RID p_texture) const { - Texture *tex = texture_owner.getornull(p_texture); +Ref<Image> RasterizerStorageOpenGL::texture_2d_get(RID p_texture) const { + Texture *tex = texture_owner.get_or_null(p_texture); ERR_FAIL_COND_V(!tex, Ref<Image>()); /* @@ -575,10 +589,10 @@ Ref<Image> RasterizerStorageGLES2::texture_2d_get(RID p_texture) const { // return Ref<Image>(); } -void RasterizerStorageGLES2::texture_replace(RID p_texture, RID p_by_texture) { - Texture *tex_to = texture_owner.getornull(p_texture); +void RasterizerStorageOpenGL::texture_replace(RID p_texture, RID p_by_texture) { + Texture *tex_to = texture_owner.get_or_null(p_texture); ERR_FAIL_COND(!tex_to); - Texture *tex_from = texture_owner.getornull(p_by_texture); + Texture *tex_from = texture_owner.get_or_null(p_by_texture); ERR_FAIL_COND(!tex_from); tex_to->destroy(); @@ -592,7 +606,7 @@ void RasterizerStorageGLES2::texture_replace(RID p_texture, RID p_by_texture) { } } -bool RasterizerStorageGLES2::_is_main_thread() { +bool RasterizerStorageOpenGL::_is_main_thread() { //#if defined DEBUG_ENABLED && defined TOOLS_ENABLED // must be called from main thread in OpenGL bool is_main_thread = _main_thread_id == Thread::get_caller_id(); @@ -600,7 +614,7 @@ bool RasterizerStorageGLES2::_is_main_thread() { return is_main_thread; } -RID RasterizerStorageGLES2::texture_create() { +RID RasterizerStorageOpenGL::texture_create() { ERR_FAIL_COND_V(!_is_main_thread(), RID()); Texture *texture = memnew(Texture); @@ -612,7 +626,7 @@ RID RasterizerStorageGLES2::texture_create() { return texture_owner.make_rid(texture); } -void RasterizerStorageGLES2::_texture_allocate_internal(RID p_texture, int p_width, int p_height, int p_depth_3d, Image::Format p_format, GD_RD::TextureType p_type, uint32_t p_flags) { +void RasterizerStorageOpenGL::_texture_allocate_internal(RID p_texture, int p_width, int p_height, int p_depth_3d, Image::Format p_format, RenderingDevice::TextureType p_type, uint32_t p_flags) { // GLenum format; // GLenum internal_format; // GLenum type; @@ -623,7 +637,7 @@ void RasterizerStorageGLES2::_texture_allocate_internal(RID p_texture, int p_wid p_flags &= ~TEXTURE_FLAG_MIPMAPS; // no mipies for video } - Texture *texture = texture_owner.getornull(p_texture); + Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND(!texture); texture->width = p_width; texture->height = p_height; @@ -633,11 +647,11 @@ void RasterizerStorageGLES2::_texture_allocate_internal(RID p_texture, int p_wid texture->type = p_type; switch (p_type) { - case GD_RD::TEXTURE_TYPE_2D: { + case RenderingDevice::TEXTURE_TYPE_2D: { texture->target = GL_TEXTURE_2D; texture->images.resize(1); } break; - // case GD_RD::TEXTURE_TYPE_EXTERNAL: { + // case RenderingDevice::TEXTURE_TYPE_EXTERNAL: { //#ifdef ANDROID_ENABLED // texture->target = _GL_TEXTURE_EXTERNAL_OES; //#else @@ -645,14 +659,14 @@ void RasterizerStorageGLES2::_texture_allocate_internal(RID p_texture, int p_wid //#endif // texture->images.resize(0); // } break; - case GD_RD::TEXTURE_TYPE_CUBE: { + case RenderingDevice::TEXTURE_TYPE_CUBE: { texture->target = GL_TEXTURE_CUBE_MAP; texture->images.resize(6); } break; - case GD_RD::TEXTURE_TYPE_2D_ARRAY: - case GD_RD::TEXTURE_TYPE_3D: { + case RenderingDevice::TEXTURE_TYPE_2D_ARRAY: + case RenderingDevice::TEXTURE_TYPE_3D: { texture->target = GL_TEXTURE_3D; - ERR_PRINT("3D textures and Texture Arrays are not supported in GLES2. Please switch to the GLES3 backend."); + ERR_PRINT("3D textures and Texture Arrays are not supported in OpenGL. Please switch to the Vulkan backend."); return; } break; default: { @@ -662,8 +676,8 @@ void RasterizerStorageGLES2::_texture_allocate_internal(RID p_texture, int p_wid } #if 0 - // if (p_type != GD_VS::TEXTURE_TYPE_EXTERNAL) { - if (p_type == GD_RD::TEXTURE_TYPE_2D) { + // if (p_type != RS::TEXTURE_TYPE_EXTERNAL) { + if (p_type == RenderingDevice::TEXTURE_TYPE_2D) { texture->alloc_width = texture->width; texture->alloc_height = texture->height; texture->resize_to_po2 = false; @@ -715,7 +729,7 @@ void RasterizerStorageGLES2::_texture_allocate_internal(RID p_texture, int p_wid glActiveTexture(GL_TEXTURE0); glBindTexture(texture->target, texture->tex_id); - // if (p_type == GD_VS::TEXTURE_TYPE_EXTERNAL) { + // if (p_type == RS::TEXTURE_TYPE_EXTERNAL) { // glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // glTexParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // glTexParameteri(texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -728,8 +742,8 @@ void RasterizerStorageGLES2::_texture_allocate_internal(RID p_texture, int p_wid texture->active = true; } -void RasterizerStorageGLES2::texture_set_data(RID p_texture, const Ref<Image> &p_image, int p_layer) { - Texture *texture = texture_owner.getornull(p_texture); +void RasterizerStorageOpenGL::texture_set_data(RID p_texture, const Ref<Image> &p_image, int p_layer) { + Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND(!_is_main_thread()); @@ -746,7 +760,7 @@ void RasterizerStorageGLES2::texture_set_data(RID p_texture, const Ref<Image> &p ERR_FAIL_COND(!p_image->get_width()); ERR_FAIL_COND(!p_image->get_height()); - // ERR_FAIL_COND(texture->type == GD_VS::TEXTURE_TYPE_EXTERNAL); + // ERR_FAIL_COND(texture->type == RS::TEXTURE_TYPE_EXTERNAL); GLenum type; GLenum format; @@ -838,7 +852,7 @@ void RasterizerStorageGLES2::texture_set_data(RID p_texture, const Ref<Image> &p texture->stored_cube_sides |= (1 << p_layer); - if ((texture->flags & TEXTURE_FLAG_MIPMAPS) && mipmaps == 1 && !texture->ignore_mipmaps && (texture->type != GD_RD::TEXTURE_TYPE_CUBE || texture->stored_cube_sides == (1 << 6) - 1)) { + if ((texture->flags & TEXTURE_FLAG_MIPMAPS) && mipmaps == 1 && !texture->ignore_mipmaps && (texture->type != RenderingDevice::TEXTURE_TYPE_CUBE || texture->stored_cube_sides == (1 << 6) - 1)) { //generate mipmaps if they were requested and the image does not contain them glGenerateMipmap(texture->target); } @@ -846,20 +860,20 @@ void RasterizerStorageGLES2::texture_set_data(RID p_texture, const Ref<Image> &p texture->mipmaps = mipmaps; } -void RasterizerStorageGLES2::texture_set_data_partial(RID p_texture, const Ref<Image> &p_image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int p_dst_mip, int p_layer) { +void RasterizerStorageOpenGL::texture_set_data_partial(RID p_texture, const Ref<Image> &p_image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int p_dst_mip, int p_layer) { // TODO ERR_PRINT("Not implemented (ask Karroffel to do it :p)"); } /* -Ref<Image> RasterizerStorageGLES2::texture_get_data(RID p_texture, int p_layer) const { - Texture *texture = texture_owner.getornull(p_texture); +Ref<Image> RasterizerStorageOpenGL::texture_get_data(RID p_texture, int p_layer) const { + Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND_V(!texture, Ref<Image>()); ERR_FAIL_COND_V(!texture->active, Ref<Image>()); ERR_FAIL_COND_V(texture->data_size == 0 && !texture->render_target, Ref<Image>()); - if (texture->type == GD_VS::TEXTURE_TYPE_CUBEMAP && p_layer < 6 && p_layer >= 0 && !texture->images[p_layer].is_null()) { + if (texture->type == RS::TEXTURE_TYPE_CUBEMAP && p_layer < 6 && p_layer >= 0 && !texture->images[p_layer].is_null()) { return texture->images[p_layer]; } @@ -976,7 +990,7 @@ Ref<Image> RasterizerStorageGLES2::texture_get_data(RID p_texture, int p_layer) } */ -void RasterizerStorageGLES2::_texture_set_state_from_flags(Texture *p_tex) { +void RasterizerStorageOpenGL::_texture_set_state_from_flags(Texture *p_tex) { if ((p_tex->flags & TEXTURE_FLAG_MIPMAPS) && !p_tex->ignore_mipmaps) if (p_tex->flags & TEXTURE_FLAG_FILTER) { // these do not exactly correspond ... @@ -1007,8 +1021,8 @@ void RasterizerStorageGLES2::_texture_set_state_from_flags(Texture *p_tex) { } } -void RasterizerStorageGLES2::texture_set_flags(RID p_texture, uint32_t p_flags) { - Texture *texture = texture_owner.getornull(p_texture); +void RasterizerStorageOpenGL::texture_set_flags(RID p_texture, uint32_t p_flags) { + Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND(!texture); bool had_mipmaps = texture->flags & TEXTURE_FLAG_MIPMAPS; @@ -1028,40 +1042,40 @@ void RasterizerStorageGLES2::texture_set_flags(RID p_texture, uint32_t p_flags) } } -uint32_t RasterizerStorageGLES2::texture_get_flags(RID p_texture) const { - Texture *texture = texture_owner.getornull(p_texture); +uint32_t RasterizerStorageOpenGL::texture_get_flags(RID p_texture) const { + Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND_V(!texture, 0); return texture->flags; } -Image::Format RasterizerStorageGLES2::texture_get_format(RID p_texture) const { - Texture *texture = texture_owner.getornull(p_texture); +Image::Format RasterizerStorageOpenGL::texture_get_format(RID p_texture) const { + Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND_V(!texture, Image::FORMAT_L8); return texture->format; } -GD_RD::TextureType RasterizerStorageGLES2::texture_get_type(RID p_texture) const { - Texture *texture = texture_owner.getornull(p_texture); +RenderingDevice::TextureType RasterizerStorageOpenGL::texture_get_type(RID p_texture) const { + Texture *texture = texture_owner.get_or_null(p_texture); - ERR_FAIL_COND_V(!texture, GD_RD::TEXTURE_TYPE_2D); + ERR_FAIL_COND_V(!texture, RenderingDevice::TEXTURE_TYPE_2D); return texture->type; } -uint32_t RasterizerStorageGLES2::texture_get_texid(RID p_texture) const { - Texture *texture = texture_owner.getornull(p_texture); +uint32_t RasterizerStorageOpenGL::texture_get_texid(RID p_texture) const { + Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND_V(!texture, 0); return texture->tex_id; } -void RasterizerStorageGLES2::texture_bind(RID p_texture, uint32_t p_texture_no) { - Texture *texture = texture_owner.getornull(p_texture); +void RasterizerStorageOpenGL::texture_bind(RID p_texture, uint32_t p_texture_no) { + Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND(!texture); @@ -1069,32 +1083,32 @@ void RasterizerStorageGLES2::texture_bind(RID p_texture, uint32_t p_texture_no) glBindTexture(texture->target, texture->tex_id); } -uint32_t RasterizerStorageGLES2::texture_get_width(RID p_texture) const { - Texture *texture = texture_owner.getornull(p_texture); +uint32_t RasterizerStorageOpenGL::texture_get_width(RID p_texture) const { + Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND_V(!texture, 0); return texture->width; } -uint32_t RasterizerStorageGLES2::texture_get_height(RID p_texture) const { - Texture *texture = texture_owner.getornull(p_texture); +uint32_t RasterizerStorageOpenGL::texture_get_height(RID p_texture) const { + Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND_V(!texture, 0); return texture->height; } -uint32_t RasterizerStorageGLES2::texture_get_depth(RID p_texture) const { - Texture *texture = texture_owner.getornull(p_texture); +uint32_t RasterizerStorageOpenGL::texture_get_depth(RID p_texture) const { + Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND_V(!texture, 0); return texture->depth; } -void RasterizerStorageGLES2::texture_set_size_override(RID p_texture, int p_width, int p_height) { - Texture *texture = texture_owner.getornull(p_texture); +void RasterizerStorageOpenGL::texture_set_size_override(RID p_texture, int p_width, int p_height) { + Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND(!texture); ERR_FAIL_COND(texture->render_target); @@ -1106,29 +1120,29 @@ void RasterizerStorageGLES2::texture_set_size_override(RID p_texture, int p_widt texture->height = p_height; } -void RasterizerStorageGLES2::texture_set_path(RID p_texture, const String &p_path) { - Texture *texture = texture_owner.getornull(p_texture); +void RasterizerStorageOpenGL::texture_set_path(RID p_texture, const String &p_path) { + Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND(!texture); texture->path = p_path; } -String RasterizerStorageGLES2::texture_get_path(RID p_texture) const { - Texture *texture = texture_owner.getornull(p_texture); +String RasterizerStorageOpenGL::texture_get_path(RID p_texture) const { + Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND_V(!texture, ""); return texture->path; } -void RasterizerStorageGLES2::texture_debug_usage(List<GD_VS::TextureInfo> *r_info) { +void RasterizerStorageOpenGL::texture_debug_usage(List<RS::TextureInfo> *r_info) { List<RID> textures; texture_owner.get_owned_list(&textures); for (List<RID>::Element *E = textures.front(); E; E = E->next()) { - Texture *t = texture_owner.getornull(E->get()); + Texture *t = texture_owner.get_or_null(E->get()); if (!t) continue; - GD_VS::TextureInfo tinfo; + RS::TextureInfo tinfo; tinfo.path = t->path; tinfo.format = t->format; tinfo.width = t->alloc_width; @@ -1139,16 +1153,16 @@ void RasterizerStorageGLES2::texture_debug_usage(List<GD_VS::TextureInfo> *r_inf } } -void RasterizerStorageGLES2::texture_set_shrink_all_x2_on_set_data(bool p_enable) { +void RasterizerStorageOpenGL::texture_set_shrink_all_x2_on_set_data(bool p_enable) { config.shrink_textures_x2 = p_enable; } -void RasterizerStorageGLES2::textures_keep_original(bool p_enable) { +void RasterizerStorageOpenGL::textures_keep_original(bool p_enable) { config.keep_original_textures = p_enable; } -Size2 RasterizerStorageGLES2::texture_size_with_proxy(RID p_texture) { - const Texture *texture = texture_owner.getornull(p_texture); +Size2 RasterizerStorageOpenGL::texture_size_with_proxy(RID p_texture) { + const Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND_V(!texture, Size2()); if (texture->proxy) { return Size2(texture->proxy->width, texture->proxy->height); @@ -1168,8 +1182,8 @@ Size2 RasterizerStorageGLES2::texture_size_with_proxy(RID p_texture) { // The p_proxy is the source texture // and p_texture is actually the proxy???? -void RasterizerStorageGLES2::texture_set_proxy(RID p_texture, RID p_proxy) { - Texture *texture = texture_owner.getornull(p_texture); +void RasterizerStorageOpenGL::texture_set_proxy(RID p_texture, RID p_proxy) { + Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND(!texture); if (texture->proxy) { @@ -1178,7 +1192,7 @@ void RasterizerStorageGLES2::texture_set_proxy(RID p_texture, RID p_proxy) { } if (p_proxy.is_valid()) { - Texture *proxy = texture_owner.getornull(p_proxy); + Texture *proxy = texture_owner.get_or_null(p_proxy); ERR_FAIL_COND(!proxy); ERR_FAIL_COND(proxy == texture); proxy->proxy_owners.insert(texture); @@ -1186,49 +1200,67 @@ void RasterizerStorageGLES2::texture_set_proxy(RID p_texture, RID p_proxy) { } } -void RasterizerStorageGLES2::texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) { - Texture *texture = texture_owner.getornull(p_texture); +void RasterizerStorageOpenGL::texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) { + Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND(!texture); texture->redraw_if_visible = p_enable; } -void RasterizerStorageGLES2::texture_set_detect_3d_callback(RID p_texture, GD_VS::TextureDetectCallback p_callback, void *p_userdata) { - Texture *texture = texture_owner.getornull(p_texture); +void RasterizerStorageOpenGL::texture_set_detect_3d_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) { + Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND(!texture); texture->detect_3d = p_callback; texture->detect_3d_ud = p_userdata; } -void RasterizerStorageGLES2::texture_set_detect_srgb_callback(RID p_texture, GD_VS::TextureDetectCallback p_callback, void *p_userdata) { - Texture *texture = texture_owner.getornull(p_texture); +void RasterizerStorageOpenGL::texture_set_detect_srgb_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) { + Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND(!texture); texture->detect_srgb = p_callback; texture->detect_srgb_ud = p_userdata; } -void RasterizerStorageGLES2::texture_set_detect_normal_callback(RID p_texture, GD_VS::TextureDetectCallback p_callback, void *p_userdata) { - Texture *texture = texture_owner.getornull(p_texture); +void RasterizerStorageOpenGL::texture_set_detect_normal_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) { + Texture *texture = texture_owner.get_or_null(p_texture); ERR_FAIL_COND(!texture); texture->detect_normal = p_callback; texture->detect_normal_ud = p_userdata; } -RID RasterizerStorageGLES2::texture_create_radiance_cubemap(RID p_source, int p_resolution) const { +RID RasterizerStorageOpenGL::texture_create_radiance_cubemap(RID p_source, int p_resolution) const { return RID(); } -RID RasterizerStorageGLES2::sky_create() { +RID RasterizerStorageOpenGL::canvas_texture_allocate() { + return RID(); +} + +void RasterizerStorageOpenGL::canvas_texture_initialize(RID p_rid) { +} + +void RasterizerStorageOpenGL::canvas_texture_set_channel(RID p_canvas_texture, RS::CanvasTextureChannel p_channel, RID p_texture) { +} + +void RasterizerStorageOpenGL::canvas_texture_set_shading_parameters(RID p_canvas_texture, const Color &p_base_color, float p_shininess) { +} + +void RasterizerStorageOpenGL::canvas_texture_set_texture_filter(RID p_item, RS::CanvasItemTextureFilter p_filter) { +} +void RasterizerStorageOpenGL::canvas_texture_set_texture_repeat(RID p_item, RS::CanvasItemTextureRepeat p_repeat) { +} + +RID RasterizerStorageOpenGL::sky_create() { Sky *sky = memnew(Sky); sky->radiance = 0; return sky_owner.make_rid(sky); } -void RasterizerStorageGLES2::sky_set_texture(RID p_sky, RID p_panorama, int p_radiance_size) { - Sky *sky = sky_owner.getornull(p_sky); +void RasterizerStorageOpenGL::sky_set_texture(RID p_sky, RID p_panorama, int p_radiance_size) { + Sky *sky = sky_owner.get_or_null(p_sky); ERR_FAIL_COND(!sky); if (sky->panorama.is_valid()) { @@ -1242,7 +1274,7 @@ void RasterizerStorageGLES2::sky_set_texture(RID p_sky, RID p_panorama, int p_ra return; // the panorama was cleared } - Texture *texture = texture_owner.getornull(sky->panorama); + Texture *texture = texture_owner.get_or_null(sky->panorama); if (!texture) { sky->panorama = RID(); ERR_FAIL_COND(!texture); @@ -1257,7 +1289,7 @@ void RasterizerStorageGLES2::sky_set_texture(RID p_sky, RID p_panorama, int p_ra glDisable(GL_SCISSOR_TEST); glDisable(GL_BLEND); - for (int i = 0; i < GD_VS::ARRAY_MAX - 1; i++) { + for (int i = 0; i < RS::ARRAY_MAX - 1; i++) { glDisableVertexAttribArray(i); } } @@ -1312,8 +1344,8 @@ void RasterizerStorageGLES2::sky_set_texture(RID p_sky, RID p_panorama, int p_ra int lod = 0; int mm_level = mipmaps; size = p_radiance_size / 2; - shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES2::USE_SOURCE_PANORAMA, true); - shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES2::USE_DIRECT_WRITE, true); + shaders.cubemap_filter.set_conditional(CubemapFilterShaderOpenGL::USE_SOURCE_PANORAMA, true); + shaders.cubemap_filter.set_conditional(CubemapFilterShaderOpenGL::USE_DIRECT_WRITE, true); shaders.cubemap_filter.bind(); // third, render to the framebuffer using separate textures, then copy to mipmaps @@ -1329,8 +1361,8 @@ void RasterizerStorageGLES2::sky_set_texture(RID p_sky, RID p_panorama, int p_ra glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_CUBE_MAP, sky->radiance); - shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES2::USE_SOURCE_PANORAMA, false); - shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES2::USE_DIRECT_WRITE, false); + shaders.cubemap_filter.set_conditional(CubemapFilterShaderOpenGL::USE_SOURCE_PANORAMA, false); + shaders.cubemap_filter.set_conditional(CubemapFilterShaderOpenGL::USE_DIRECT_WRITE, false); shaders.cubemap_filter.bind(); } glViewport(0, 0, size, size); @@ -1339,12 +1371,12 @@ void RasterizerStorageGLES2::sky_set_texture(RID p_sky, RID p_panorama, int p_ra glActiveTexture(GL_TEXTURE2); //back to panorama for (int i = 0; i < 6; i++) { - shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES2::FACE_ID, i); + shaders.cubemap_filter.set_uniform(CubemapFilterShaderOpenGL::FACE_ID, i); float roughness = mm_level >= 0 ? lod / (float)(mipmaps - 1) : 1; roughness = MIN(1.0, roughness); //keep max at 1 - shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES2::ROUGHNESS, roughness); - shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES2::Z_FLIP, false); + shaders.cubemap_filter.set_uniform(CubemapFilterShaderOpenGL::ROUGHNESS, roughness); + shaders.cubemap_filter.set_uniform(CubemapFilterShaderOpenGL::Z_FLIP, false); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); @@ -1358,8 +1390,8 @@ void RasterizerStorageGLES2::sky_set_texture(RID p_sky, RID p_panorama, int p_ra lod++; } - shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES2::USE_SOURCE_PANORAMA, false); - shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES2::USE_DIRECT_WRITE, false); + shaders.cubemap_filter.set_conditional(CubemapFilterShaderOpenGL::USE_SOURCE_PANORAMA, false); + shaders.cubemap_filter.set_conditional(CubemapFilterShaderOpenGL::USE_DIRECT_WRITE, false); // restore ranges glActiveTexture(GL_TEXTURE2); //back to panorama @@ -1387,9 +1419,9 @@ void RasterizerStorageGLES2::sky_set_texture(RID p_sky, RID p_panorama, int p_ra /* SHADER API */ -RID RasterizerStorageGLES2::shader_allocate() { +RID RasterizerStorageOpenGL::shader_allocate() { Shader *shader = memnew(Shader); - shader->mode = GD_VS::SHADER_SPATIAL; + shader->mode = RS::SHADER_SPATIAL; shader->shader = &scene->state.scene_shader; RID rid = shader_owner.make_rid(shader); _shader_make_dirty(shader); @@ -1398,13 +1430,13 @@ RID RasterizerStorageGLES2::shader_allocate() { return rid; } -void RasterizerStorageGLES2::shader_initialize(RID p_rid) { +void RasterizerStorageOpenGL::shader_initialize(RID p_rid) { // noop } -//RID RasterizerStorageGLES2::shader_create() { +//RID RasterizerStorageOpenGL::shader_create() { // Shader *shader = memnew(Shader); -// shader->mode = GD_VS::SHADER_SPATIAL; +// shader->mode = RS::SHADER_SPATIAL; // shader->shader = &scene->state.scene_shader; // RID rid = shader_owner.make_rid(shader); // _shader_make_dirty(shader); @@ -1413,28 +1445,28 @@ void RasterizerStorageGLES2::shader_initialize(RID p_rid) { // return rid; //} -void RasterizerStorageGLES2::_shader_make_dirty(Shader *p_shader) { +void RasterizerStorageOpenGL::_shader_make_dirty(Shader *p_shader) { if (p_shader->dirty_list.in_list()) return; _shader_dirty_list.add(&p_shader->dirty_list); } -void RasterizerStorageGLES2::shader_set_code(RID p_shader, const String &p_code) { - Shader *shader = shader_owner.getornull(p_shader); +void RasterizerStorageOpenGL::shader_set_code(RID p_shader, const String &p_code) { + Shader *shader = shader_owner.get_or_null(p_shader); ERR_FAIL_COND(!shader); shader->code = p_code; String mode_string = ShaderLanguage::get_shader_type(p_code); - GD_VS::ShaderMode mode; + RS::ShaderMode mode; if (mode_string == "canvas_item") - mode = GD_VS::SHADER_CANVAS_ITEM; + mode = RS::SHADER_CANVAS_ITEM; else if (mode_string == "particles") - mode = GD_VS::SHADER_PARTICLES; + mode = RS::SHADER_PARTICLES; else - mode = GD_VS::SHADER_SPATIAL; + mode = RS::SHADER_SPATIAL; if (shader->custom_code_id && mode != shader->mode) { shader->shader->free_custom_shader(shader->custom_code_id); @@ -1444,10 +1476,10 @@ void RasterizerStorageGLES2::shader_set_code(RID p_shader, const String &p_code) shader->mode = mode; // TODO handle all shader types - if (mode == GD_VS::SHADER_CANVAS_ITEM) { + if (mode == RS::SHADER_CANVAS_ITEM) { shader->shader = &canvas->state.canvas_shader; - } else if (mode == GD_VS::SHADER_SPATIAL) { + } else if (mode == RS::SHADER_SPATIAL) { shader->shader = &scene->state.scene_shader; } else { return; @@ -1460,14 +1492,14 @@ void RasterizerStorageGLES2::shader_set_code(RID p_shader, const String &p_code) _shader_make_dirty(shader); } -String RasterizerStorageGLES2::shader_get_code(RID p_shader) const { - const Shader *shader = shader_owner.getornull(p_shader); +String RasterizerStorageOpenGL::shader_get_code(RID p_shader) const { + const Shader *shader = shader_owner.get_or_null(p_shader); ERR_FAIL_COND_V(!shader, ""); return shader->code; } -void RasterizerStorageGLES2::_update_shader(Shader *p_shader) const { +void RasterizerStorageOpenGL::_update_shader(Shader *p_shader) const { _shader_dirty_list.remove(&p_shader->dirty_list); p_shader->valid = false; @@ -1478,11 +1510,11 @@ void RasterizerStorageGLES2::_update_shader(Shader *p_shader) const { return; //just invalid, but no error } - ShaderCompilerGLES2::GeneratedCode gen_code; - ShaderCompilerGLES2::IdentifierActions *actions = NULL; + ShaderCompilerOpenGL::GeneratedCode gen_code; + ShaderCompilerOpenGL::IdentifierActions *actions = NULL; switch (p_shader->mode) { - case GD_VS::SHADER_CANVAS_ITEM: { + case RS::SHADER_CANVAS_ITEM: { p_shader->canvas_item.light_mode = Shader::CanvasItem::LIGHT_MODE_NORMAL; p_shader->canvas_item.blend_mode = Shader::CanvasItem::BLEND_MODE_MIX; @@ -1526,7 +1558,7 @@ void RasterizerStorageGLES2::_update_shader(Shader *p_shader) const { actions->uniforms = &p_shader->uniforms; } break; - case GD_VS::SHADER_SPATIAL: { + case RS::SHADER_SPATIAL: { p_shader->spatial.blend_mode = Shader::Spatial::BLEND_MODE_MIX; p_shader->spatial.depth_draw_mode = Shader::Spatial::DEPTH_DRAW_OPAQUE; p_shader->spatial.cull_mode = Shader::Spatial::CULL_MODE_BACK; @@ -1591,7 +1623,7 @@ void RasterizerStorageGLES2::_update_shader(Shader *p_shader) const { actions->uniforms = &p_shader->uniforms; if (p_shader->spatial.uses_screen_texture && p_shader->spatial.uses_depth_texture) { - ERR_PRINT_ONCE("Using both SCREEN_TEXTURE and DEPTH_TEXTURE is not supported in GLES2"); + ERR_PRINT_ONCE("Using both SCREEN_TEXTURE and DEPTH_TEXTURE is not supported in OpenGL"); } if (p_shader->spatial.uses_depth_texture && !config.support_depth_texture) { @@ -1618,7 +1650,7 @@ void RasterizerStorageGLES2::_update_shader(Shader *p_shader) const { p_shader->uses_fragment_time = gen_code.uses_fragment_time; // some logic for batching - if (p_shader->mode == GD_VS::SHADER_CANVAS_ITEM) { + if (p_shader->mode == RS::SHADER_CANVAS_ITEM) { if (p_shader->canvas_item.uses_modulate | p_shader->canvas_item.uses_color) { p_shader->canvas_item.batch_flags |= RasterizerStorageCommon::PREVENT_COLOR_BAKING; } @@ -1643,14 +1675,14 @@ void RasterizerStorageGLES2::_update_shader(Shader *p_shader) const { p_shader->version++; } -void RasterizerStorageGLES2::update_dirty_shaders() { +void RasterizerStorageOpenGL::update_dirty_shaders() { while (_shader_dirty_list.first()) { _update_shader(_shader_dirty_list.first()->self()); } } -void RasterizerStorageGLES2::shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const { - Shader *shader = shader_owner.getornull(p_shader); +void RasterizerStorageOpenGL::shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const { + Shader *shader = shader_owner.get_or_null(p_shader); ERR_FAIL_COND(!shader); if (shader->dirty_list.in_list()) { @@ -1777,7 +1809,7 @@ void RasterizerStorageGLES2::shader_get_param_list(RID p_shader, List<PropertyIn case ShaderLanguage::TYPE_SAMPLER3D: case ShaderLanguage::TYPE_ISAMPLER3D: case ShaderLanguage::TYPE_USAMPLER3D: { - // Not implemented in GLES2 + // Not implemented in OpenGL } break; // new for godot 4 case ShaderLanguage::TYPE_SAMPLERCUBEARRAY: @@ -1790,8 +1822,8 @@ void RasterizerStorageGLES2::shader_get_param_list(RID p_shader, List<PropertyIn } } -void RasterizerStorageGLES2::shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) { - Shader *shader = shader_owner.getornull(p_shader); +void RasterizerStorageOpenGL::shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) { + Shader *shader = shader_owner.get_or_null(p_shader); ERR_FAIL_COND(!shader); ERR_FAIL_COND(p_texture.is_valid() && !texture_owner.owns(p_texture)); @@ -1804,8 +1836,8 @@ void RasterizerStorageGLES2::shader_set_default_texture_param(RID p_shader, cons _shader_make_dirty(shader); } -RID RasterizerStorageGLES2::shader_get_default_texture_param(RID p_shader, const StringName &p_name) const { - const Shader *shader = shader_owner.getornull(p_shader); +RID RasterizerStorageOpenGL::shader_get_default_texture_param(RID p_shader, const StringName &p_name) const { + const Shader *shader = shader_owner.get_or_null(p_shader); ERR_FAIL_COND_V(!shader, RID()); const Map<StringName, RID>::Element *E = shader->default_textures.find(p_name); @@ -1817,8 +1849,8 @@ RID RasterizerStorageGLES2::shader_get_default_texture_param(RID p_shader, const return E->get(); } -void RasterizerStorageGLES2::shader_add_custom_define(RID p_shader, const String &p_define) { - Shader *shader = shader_owner.getornull(p_shader); +void RasterizerStorageOpenGL::shader_add_custom_define(RID p_shader, const String &p_define) { + Shader *shader = shader_owner.get_or_null(p_shader); ERR_FAIL_COND(!shader); shader->shader->add_custom_define(p_define); @@ -1826,15 +1858,15 @@ void RasterizerStorageGLES2::shader_add_custom_define(RID p_shader, const String _shader_make_dirty(shader); } -void RasterizerStorageGLES2::shader_get_custom_defines(RID p_shader, Vector<String> *p_defines) const { - Shader *shader = shader_owner.getornull(p_shader); +void RasterizerStorageOpenGL::shader_get_custom_defines(RID p_shader, Vector<String> *p_defines) const { + Shader *shader = shader_owner.get_or_null(p_shader); ERR_FAIL_COND(!shader); shader->shader->get_custom_defines(p_defines); } -void RasterizerStorageGLES2::shader_remove_custom_define(RID p_shader, const String &p_define) { - Shader *shader = shader_owner.getornull(p_shader); +void RasterizerStorageOpenGL::shader_remove_custom_define(RID p_shader, const String &p_define) { + Shader *shader = shader_owner.get_or_null(p_shader); ERR_FAIL_COND(!shader); shader->shader->remove_custom_define(p_define); @@ -1844,32 +1876,32 @@ void RasterizerStorageGLES2::shader_remove_custom_define(RID p_shader, const Str /* COMMON MATERIAL API */ -void RasterizerStorageGLES2::_material_make_dirty(Material *p_material) const { +void RasterizerStorageOpenGL::_material_make_dirty(Material *p_material) const { if (p_material->dirty_list.in_list()) return; _material_dirty_list.add(&p_material->dirty_list); } -RID RasterizerStorageGLES2::material_allocate() { +RID RasterizerStorageOpenGL::material_allocate() { Material *material = memnew(Material); return material_owner.make_rid(material); } -void RasterizerStorageGLES2::material_initialize(RID p_rid) { +void RasterizerStorageOpenGL::material_initialize(RID p_rid) { } -//RID RasterizerStorageGLES2::material_create() { +//RID RasterizerStorageOpenGL::material_create() { // Material *material = memnew(Material); // return material_owner.make_rid(material); //} -void RasterizerStorageGLES2::material_set_shader(RID p_material, RID p_shader) { - Material *material = material_owner.getornull(p_material); +void RasterizerStorageOpenGL::material_set_shader(RID p_material, RID p_shader) { + Material *material = material_owner.get_or_null(p_material); ERR_FAIL_COND(!material); - Shader *shader = shader_owner.getornull(p_shader); + Shader *shader = shader_owner.get_or_null(p_shader); if (material->shader) { // if a shader is present, remove the old shader @@ -1885,8 +1917,8 @@ void RasterizerStorageGLES2::material_set_shader(RID p_material, RID p_shader) { _material_make_dirty(material); } -RID RasterizerStorageGLES2::material_get_shader(RID p_material) const { - const Material *material = material_owner.getornull(p_material); +RID RasterizerStorageOpenGL::material_get_shader(RID p_material) const { + const Material *material = material_owner.get_or_null(p_material); ERR_FAIL_COND_V(!material, RID()); if (material->shader) { @@ -1896,8 +1928,8 @@ RID RasterizerStorageGLES2::material_get_shader(RID p_material) const { return RID(); } -void RasterizerStorageGLES2::material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) { - Material *material = material_owner.getornull(p_material); +void RasterizerStorageOpenGL::material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) { + Material *material = material_owner.get_or_null(p_material); ERR_FAIL_COND(!material); if (p_value.get_type() == Variant::NIL) { @@ -1909,8 +1941,8 @@ void RasterizerStorageGLES2::material_set_param(RID p_material, const StringName _material_make_dirty(material); } -Variant RasterizerStorageGLES2::material_get_param(RID p_material, const StringName &p_param) const { - const Material *material = material_owner.getornull(p_material); +Variant RasterizerStorageOpenGL::material_get_param(RID p_material, const StringName &p_param) const { + const Material *material = material_owner.get_or_null(p_material); ERR_FAIL_COND_V(!material, RID()); if (material->params.has(p_param)) { @@ -1920,8 +1952,8 @@ Variant RasterizerStorageGLES2::material_get_param(RID p_material, const StringN return material_get_param_default(p_material, p_param); } -Variant RasterizerStorageGLES2::material_get_param_default(RID p_material, const StringName &p_param) const { - const Material *material = material_owner.getornull(p_material); +Variant RasterizerStorageOpenGL::material_get_param_default(RID p_material, const StringName &p_param) const { + const Material *material = material_owner.get_or_null(p_material); ERR_FAIL_COND_V(!material, Variant()); if (material->shader) { @@ -1934,22 +1966,22 @@ Variant RasterizerStorageGLES2::material_get_param_default(RID p_material, const return Variant(); } -void RasterizerStorageGLES2::material_set_line_width(RID p_material, float p_width) { - Material *material = material_owner.getornull(p_material); +void RasterizerStorageOpenGL::material_set_line_width(RID p_material, float p_width) { + Material *material = material_owner.get_or_null(p_material); ERR_FAIL_COND(!material); material->line_width = p_width; } -void RasterizerStorageGLES2::material_set_next_pass(RID p_material, RID p_next_material) { - Material *material = material_owner.getornull(p_material); +void RasterizerStorageOpenGL::material_set_next_pass(RID p_material, RID p_next_material) { + Material *material = material_owner.get_or_null(p_material); ERR_FAIL_COND(!material); material->next_pass = p_next_material; } -bool RasterizerStorageGLES2::material_is_animated(RID p_material) { - Material *material = material_owner.getornull(p_material); +bool RasterizerStorageOpenGL::material_is_animated(RID p_material) { + Material *material = material_owner.get_or_null(p_material); ERR_FAIL_COND_V(!material, false); if (material->dirty_list.in_list()) { _update_material(material); @@ -1962,8 +1994,8 @@ bool RasterizerStorageGLES2::material_is_animated(RID p_material) { return animated; } -bool RasterizerStorageGLES2::material_casts_shadows(RID p_material) { - Material *material = material_owner.getornull(p_material); +bool RasterizerStorageOpenGL::material_casts_shadows(RID p_material) { + Material *material = material_owner.get_or_null(p_material); ERR_FAIL_COND_V(!material, false); if (material->dirty_list.in_list()) { _update_material(material); @@ -1978,8 +2010,8 @@ bool RasterizerStorageGLES2::material_casts_shadows(RID p_material) { return casts_shadows; } -bool RasterizerStorageGLES2::material_uses_tangents(RID p_material) { - Material *material = material_owner.getornull(p_material); +bool RasterizerStorageOpenGL::material_uses_tangents(RID p_material) { + Material *material = material_owner.get_or_null(p_material); ERR_FAIL_COND_V(!material, false); if (!material->shader) { @@ -1993,8 +2025,8 @@ bool RasterizerStorageGLES2::material_uses_tangents(RID p_material) { return material->shader->spatial.uses_tangent; } -bool RasterizerStorageGLES2::material_uses_ensure_correct_normals(RID p_material) { - Material *material = material_owner.getornull(p_material); +bool RasterizerStorageOpenGL::material_uses_ensure_correct_normals(RID p_material) { + Material *material = material_owner.get_or_null(p_material); ERR_FAIL_COND_V(!material, false); if (!material->shader) { @@ -2008,9 +2040,9 @@ bool RasterizerStorageGLES2::material_uses_ensure_correct_normals(RID p_material return material->shader->spatial.uses_ensure_correct_normals; } -void RasterizerStorageGLES2::material_add_instance_owner(RID p_material, DependencyTracker *p_instance) { +void RasterizerStorageOpenGL::material_add_instance_owner(RID p_material, DependencyTracker *p_instance) { /* - Material *material = material_owner.getornull(p_material); + Material *material = material_owner.get_or_null(p_material); ERR_FAIL_COND(!material); Map<InstanceBaseDependency *, int>::Element *E = material->instance_owners.find(p_instance); @@ -2022,9 +2054,9 @@ void RasterizerStorageGLES2::material_add_instance_owner(RID p_material, Depende */ } -void RasterizerStorageGLES2::material_remove_instance_owner(RID p_material, DependencyTracker *p_instance) { +void RasterizerStorageOpenGL::material_remove_instance_owner(RID p_material, DependencyTracker *p_instance) { /* - Material *material = material_owner.getornull(p_material); + Material *material = material_owner.get_or_null(p_material); ERR_FAIL_COND(!material); Map<InstanceBaseDependency *, int>::Element *E = material->instance_owners.find(p_instance); @@ -2038,17 +2070,17 @@ void RasterizerStorageGLES2::material_remove_instance_owner(RID p_material, Depe */ } -void RasterizerStorageGLES2::material_set_render_priority(RID p_material, int priority) { - ERR_FAIL_COND(priority < GD_VS::MATERIAL_RENDER_PRIORITY_MIN); - ERR_FAIL_COND(priority > GD_VS::MATERIAL_RENDER_PRIORITY_MAX); +void RasterizerStorageOpenGL::material_set_render_priority(RID p_material, int priority) { + ERR_FAIL_COND(priority < RS::MATERIAL_RENDER_PRIORITY_MIN); + ERR_FAIL_COND(priority > RS::MATERIAL_RENDER_PRIORITY_MAX); - Material *material = material_owner.getornull(p_material); + Material *material = material_owner.get_or_null(p_material); ERR_FAIL_COND(!material); material->render_priority = priority; } -void RasterizerStorageGLES2::_update_material(Material *p_material) { +void RasterizerStorageOpenGL::_update_material(Material *p_material) { if (p_material->dirty_list.in_list()) { _material_dirty_list.remove(&p_material->dirty_list); } @@ -2065,7 +2097,7 @@ void RasterizerStorageGLES2::_update_material(Material *p_material) { bool can_cast_shadow = false; bool is_animated = false; - if (p_material->shader && p_material->shader->mode == GD_VS::SHADER_SPATIAL) { + if (p_material->shader && p_material->shader->mode == RS::SHADER_SPATIAL) { if (p_material->shader->spatial.blend_mode == Shader::Spatial::BLEND_MODE_MIX && (!p_material->shader->spatial.uses_alpha || p_material->shader->spatial.depth_draw_mode == Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS)) { can_cast_shadow = true; @@ -2096,7 +2128,7 @@ void RasterizerStorageGLES2::_update_material(Material *p_material) { } } - // uniforms and other things will be set in the use_material method in ShaderGLES2 + // uniforms and other things will be set in the use_material method in ShaderOpenGL if (p_material->shader && p_material->shader->texture_count > 0) { p_material->textures.resize(p_material->shader->texture_count); @@ -2128,8 +2160,8 @@ void RasterizerStorageGLES2::_update_material(Material *p_material) { } } /* -void RasterizerStorageGLES2::_material_add_geometry(RID p_material, Geometry *p_geometry) { - Material *material = material_owner.getornull(p_material); +void RasterizerStorageOpenGL::_material_add_geometry(RID p_material, Geometry *p_geometry) { + Material *material = material_owner.get_or_null(p_material); ERR_FAIL_COND(!material); Map<Geometry *, int>::Element *I = material->geometry_owners.find(p_geometry); @@ -2141,8 +2173,8 @@ void RasterizerStorageGLES2::_material_add_geometry(RID p_material, Geometry *p_ } } -void RasterizerStorageGLES2::_material_remove_geometry(RID p_material, Geometry *p_geometry) { - Material *material = material_owner.getornull(p_material); +void RasterizerStorageOpenGL::_material_remove_geometry(RID p_material, Geometry *p_geometry) { + Material *material = material_owner.get_or_null(p_material); ERR_FAIL_COND(!material); Map<Geometry *, int>::Element *I = material->geometry_owners.find(p_geometry); @@ -2155,21 +2187,868 @@ void RasterizerStorageGLES2::_material_remove_geometry(RID p_material, Geometry } } */ -void RasterizerStorageGLES2::update_dirty_materials() { +void RasterizerStorageOpenGL::update_dirty_materials() { while (_material_dirty_list.first()) { Material *material = _material_dirty_list.first()->self(); _update_material(material); } } +/* MESH API */ + +RID RasterizerStorageOpenGL::mesh_allocate() { + return RID(); +} + +void RasterizerStorageOpenGL::mesh_initialize(RID p_rid) { +} + +void RasterizerStorageOpenGL::mesh_set_blend_shape_count(RID p_mesh, int p_blend_shape_count) { +} + +bool RasterizerStorageOpenGL::mesh_needs_instance(RID p_mesh, bool p_has_skeleton) { + return false; +} + +RID RasterizerStorageOpenGL::mesh_instance_create(RID p_base) { + return RID(); +} + +void RasterizerStorageOpenGL::mesh_instance_set_skeleton(RID p_mesh_instance, RID p_skeleton) { +} + +void RasterizerStorageOpenGL::mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int p_shape, float p_weight) { +} + +void RasterizerStorageOpenGL::mesh_instance_check_for_update(RID p_mesh_instance) { +} + +void RasterizerStorageOpenGL::update_mesh_instances() { +} + +void RasterizerStorageOpenGL::reflection_probe_set_lod_threshold(RID p_probe, float p_ratio) { +} + +float RasterizerStorageOpenGL::reflection_probe_get_lod_threshold(RID p_probe) const { + return 0.0; +} + +void RasterizerStorageOpenGL::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface) { +} + +int RasterizerStorageOpenGL::mesh_get_blend_shape_count(RID p_mesh) const { + return 0; +} + +void RasterizerStorageOpenGL::mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode) { +} + +RS::BlendShapeMode RasterizerStorageOpenGL::mesh_get_blend_shape_mode(RID p_mesh) const { + return RS::BLEND_SHAPE_MODE_NORMALIZED; +} + +void RasterizerStorageOpenGL::mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) { +} + +void RasterizerStorageOpenGL::mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) { +} + +void RasterizerStorageOpenGL::mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) { +} + +void RasterizerStorageOpenGL::mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) { +} + +RID RasterizerStorageOpenGL::mesh_surface_get_material(RID p_mesh, int p_surface) const { + return RID(); +} + +RS::SurfaceData RasterizerStorageOpenGL::mesh_get_surface(RID p_mesh, int p_surface) const { + return RS::SurfaceData(); +} + +int RasterizerStorageOpenGL::mesh_get_surface_count(RID p_mesh) const { + return 0; +} + +void RasterizerStorageOpenGL::mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) { +} + +AABB RasterizerStorageOpenGL::mesh_get_custom_aabb(RID p_mesh) const { + return AABB(); +} + +AABB RasterizerStorageOpenGL::mesh_get_aabb(RID p_mesh, RID p_skeleton) { + return AABB(); +} + +void RasterizerStorageOpenGL::mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) { +} + +void RasterizerStorageOpenGL::mesh_clear(RID p_mesh) { +} + +/* MULTIMESH API */ + +RID RasterizerStorageOpenGL::multimesh_allocate() { + return RID(); +} + +void RasterizerStorageOpenGL::multimesh_initialize(RID p_rid) { +} + +void RasterizerStorageOpenGL::multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors, bool p_use_custom_data) { +} + +int RasterizerStorageOpenGL::multimesh_get_instance_count(RID p_multimesh) const { + return 0; +} + +void RasterizerStorageOpenGL::multimesh_set_mesh(RID p_multimesh, RID p_mesh) { +} + +void RasterizerStorageOpenGL::multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform) { +} + +void RasterizerStorageOpenGL::multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) { +} + +void RasterizerStorageOpenGL::multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) { +} + +void RasterizerStorageOpenGL::multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) { +} + +RID RasterizerStorageOpenGL::multimesh_get_mesh(RID p_multimesh) const { + return RID(); +} + +AABB RasterizerStorageOpenGL::multimesh_get_aabb(RID p_multimesh) const { + return AABB(); +} + +Transform3D RasterizerStorageOpenGL::multimesh_instance_get_transform(RID p_multimesh, int p_index) const { + return Transform3D(); +} + +Transform2D RasterizerStorageOpenGL::multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const { + return Transform2D(); +} + +Color RasterizerStorageOpenGL::multimesh_instance_get_color(RID p_multimesh, int p_index) const { + return Color(); +} + +Color RasterizerStorageOpenGL::multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const { + return Color(); +} + +void RasterizerStorageOpenGL::multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) { +} + +Vector<float> RasterizerStorageOpenGL::multimesh_get_buffer(RID p_multimesh) const { + return Vector<float>(); +} + +void RasterizerStorageOpenGL::multimesh_set_visible_instances(RID p_multimesh, int p_visible) { +} + +int RasterizerStorageOpenGL::multimesh_get_visible_instances(RID p_multimesh) const { + return 0; +} + +/* SKELETON API */ + +RID RasterizerStorageOpenGL::skeleton_allocate() { + return RID(); +} + +void RasterizerStorageOpenGL::skeleton_initialize(RID p_rid) { +} + +void RasterizerStorageOpenGL::skeleton_allocate_data(RID p_skeleton, int p_bones, bool p_2d_skeleton) { +} + +void RasterizerStorageOpenGL::skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform) { +} + +int RasterizerStorageOpenGL::skeleton_get_bone_count(RID p_skeleton) const { + return 0; +} + +void RasterizerStorageOpenGL::skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform3D &p_transform) { +} + +Transform3D RasterizerStorageOpenGL::skeleton_bone_get_transform(RID p_skeleton, int p_bone) const { + return Transform3D(); +} + +void RasterizerStorageOpenGL::skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform) { +} + +Transform2D RasterizerStorageOpenGL::skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const { + return Transform2D(); +} + +/* Light API */ + +RID RasterizerStorageOpenGL::directional_light_allocate() { + return RID(); +} + +void RasterizerStorageOpenGL::directional_light_initialize(RID p_rid) { +} + +RID RasterizerStorageOpenGL::omni_light_allocate() { + return RID(); +} + +void RasterizerStorageOpenGL::omni_light_initialize(RID p_rid) { +} + +RID RasterizerStorageOpenGL::spot_light_allocate() { + return RID(); +} + +void RasterizerStorageOpenGL::spot_light_initialize(RID p_rid) { +} + +RID RasterizerStorageOpenGL::reflection_probe_allocate() { + return RID(); +} + +void RasterizerStorageOpenGL::reflection_probe_initialize(RID p_rid) { +} + +void RasterizerStorageOpenGL::light_set_color(RID p_light, const Color &p_color) { +} + +void RasterizerStorageOpenGL::light_set_param(RID p_light, RS::LightParam p_param, float p_value) { +} + +void RasterizerStorageOpenGL::light_set_shadow(RID p_light, bool p_enabled) { +} + +void RasterizerStorageOpenGL::light_set_shadow_color(RID p_light, const Color &p_color) { +} + +void RasterizerStorageOpenGL::light_set_projector(RID p_light, RID p_texture) { +} + +void RasterizerStorageOpenGL::light_set_negative(RID p_light, bool p_enable) { +} + +void RasterizerStorageOpenGL::light_set_cull_mask(RID p_light, uint32_t p_mask) { +} + +void RasterizerStorageOpenGL::light_set_reverse_cull_face_mode(RID p_light, bool p_enabled) { +} + +void RasterizerStorageOpenGL::light_set_bake_mode(RID p_light, RS::LightBakeMode p_bake_mode) { +} + +void RasterizerStorageOpenGL::light_set_max_sdfgi_cascade(RID p_light, uint32_t p_cascade) { +} + +void RasterizerStorageOpenGL::light_omni_set_shadow_mode(RID p_light, RS::LightOmniShadowMode p_mode) { +} + +void RasterizerStorageOpenGL::light_directional_set_shadow_mode(RID p_light, RS::LightDirectionalShadowMode p_mode) { +} + +void RasterizerStorageOpenGL::light_directional_set_blend_splits(RID p_light, bool p_enable) { +} + +bool RasterizerStorageOpenGL::light_directional_get_blend_splits(RID p_light) const { + return false; +} + +void RasterizerStorageOpenGL::light_directional_set_sky_only(RID p_light, bool p_sky_only) { +} + +bool RasterizerStorageOpenGL::light_directional_is_sky_only(RID p_light) const { + return false; +} + +RS::LightDirectionalShadowMode RasterizerStorageOpenGL::light_directional_get_shadow_mode(RID p_light) { + return RS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL; +} + +RS::LightOmniShadowMode RasterizerStorageOpenGL::light_omni_get_shadow_mode(RID p_light) { + return RS::LIGHT_OMNI_SHADOW_DUAL_PARABOLOID; +} + +bool RasterizerStorageOpenGL::light_has_shadow(RID p_light) const { + return false; +} + +bool RasterizerStorageOpenGL::light_has_projector(RID p_light) const { + return false; +} + +RS::LightType RasterizerStorageOpenGL::light_get_type(RID p_light) const { + return RS::LIGHT_OMNI; +} + +AABB RasterizerStorageOpenGL::light_get_aabb(RID p_light) const { + return AABB(); +} + +float RasterizerStorageOpenGL::light_get_param(RID p_light, RS::LightParam p_param) { + return 0.0; +} + +Color RasterizerStorageOpenGL::light_get_color(RID p_light) { + return Color(); +} + +RS::LightBakeMode RasterizerStorageOpenGL::light_get_bake_mode(RID p_light) { + return RS::LIGHT_BAKE_DISABLED; +} + +uint32_t RasterizerStorageOpenGL::light_get_max_sdfgi_cascade(RID p_light) { + return 0; +} + +uint64_t RasterizerStorageOpenGL::light_get_version(RID p_light) const { + return 0; +} + +/* PROBE API */ + +void RasterizerStorageOpenGL::reflection_probe_set_update_mode(RID p_probe, RS::ReflectionProbeUpdateMode p_mode) { +} + +void RasterizerStorageOpenGL::reflection_probe_set_intensity(RID p_probe, float p_intensity) { +} + +void RasterizerStorageOpenGL::reflection_probe_set_ambient_mode(RID p_probe, RS::ReflectionProbeAmbientMode p_mode) { +} + +void RasterizerStorageOpenGL::reflection_probe_set_ambient_color(RID p_probe, const Color &p_color) { +} + +void RasterizerStorageOpenGL::reflection_probe_set_ambient_energy(RID p_probe, float p_energy) { +} + +void RasterizerStorageOpenGL::reflection_probe_set_max_distance(RID p_probe, float p_distance) { +} + +void RasterizerStorageOpenGL::reflection_probe_set_extents(RID p_probe, const Vector3 &p_extents) { +} + +void RasterizerStorageOpenGL::reflection_probe_set_origin_offset(RID p_probe, const Vector3 &p_offset) { +} + +void RasterizerStorageOpenGL::reflection_probe_set_as_interior(RID p_probe, bool p_enable) { +} + +void RasterizerStorageOpenGL::reflection_probe_set_enable_box_projection(RID p_probe, bool p_enable) { +} + +void RasterizerStorageOpenGL::reflection_probe_set_enable_shadows(RID p_probe, bool p_enable) { +} + +void RasterizerStorageOpenGL::reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers) { +} + +void RasterizerStorageOpenGL::reflection_probe_set_resolution(RID p_probe, int p_resolution) { +} + +AABB RasterizerStorageOpenGL::reflection_probe_get_aabb(RID p_probe) const { + return AABB(); +} + +RS::ReflectionProbeUpdateMode RasterizerStorageOpenGL::reflection_probe_get_update_mode(RID p_probe) const { + return RenderingServer::REFLECTION_PROBE_UPDATE_ONCE; +} + +uint32_t RasterizerStorageOpenGL::reflection_probe_get_cull_mask(RID p_probe) const { + return 0; +} + +Vector3 RasterizerStorageOpenGL::reflection_probe_get_extents(RID p_probe) const { + return Vector3(); +} + +Vector3 RasterizerStorageOpenGL::reflection_probe_get_origin_offset(RID p_probe) const { + return Vector3(); +} + +float RasterizerStorageOpenGL::reflection_probe_get_origin_max_distance(RID p_probe) const { + return 0.0; +} + +bool RasterizerStorageOpenGL::reflection_probe_renders_shadows(RID p_probe) const { + return false; +} + +void RasterizerStorageOpenGL::base_update_dependency(RID p_base, DependencyTracker *p_instance) { +} + +void RasterizerStorageOpenGL::skeleton_update_dependency(RID p_base, DependencyTracker *p_instance) { +} + +/* DECAL API */ + +RID RasterizerStorageOpenGL::decal_allocate() { + return RID(); +} + +void RasterizerStorageOpenGL::decal_initialize(RID p_rid) { +} + +void RasterizerStorageOpenGL::decal_set_extents(RID p_decal, const Vector3 &p_extents) { +} + +void RasterizerStorageOpenGL::decal_set_texture(RID p_decal, RS::DecalTexture p_type, RID p_texture) { +} + +void RasterizerStorageOpenGL::decal_set_emission_energy(RID p_decal, float p_energy) { +} + +void RasterizerStorageOpenGL::decal_set_albedo_mix(RID p_decal, float p_mix) { +} + +void RasterizerStorageOpenGL::decal_set_modulate(RID p_decal, const Color &p_modulate) { +} + +void RasterizerStorageOpenGL::decal_set_cull_mask(RID p_decal, uint32_t p_layers) { +} + +void RasterizerStorageOpenGL::decal_set_distance_fade(RID p_decal, bool p_enabled, float p_begin, float p_length) { +} + +void RasterizerStorageOpenGL::decal_set_fade(RID p_decal, float p_above, float p_below) { +} + +void RasterizerStorageOpenGL::decal_set_normal_fade(RID p_decal, float p_fade) { +} + +AABB RasterizerStorageOpenGL::decal_get_aabb(RID p_decal) const { + return AABB(); +} + +/* VOXEL GI API */ + +RID RasterizerStorageOpenGL::voxel_gi_allocate() { + return RID(); +} + +void RasterizerStorageOpenGL::voxel_gi_initialize(RID p_rid) { +} + +void RasterizerStorageOpenGL::voxel_gi_allocate_data(RID p_voxel_gi, const Transform3D &p_to_cell_xform, const AABB &p_aabb, const Vector3i &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts) { +} + +AABB RasterizerStorageOpenGL::voxel_gi_get_bounds(RID p_voxel_gi) const { + return AABB(); +} + +Vector3i RasterizerStorageOpenGL::voxel_gi_get_octree_size(RID p_voxel_gi) const { + return Vector3i(); +} + +Vector<uint8_t> RasterizerStorageOpenGL::voxel_gi_get_octree_cells(RID p_voxel_gi) const { + return Vector<uint8_t>(); +} + +Vector<uint8_t> RasterizerStorageOpenGL::voxel_gi_get_data_cells(RID p_voxel_gi) const { + return Vector<uint8_t>(); +} + +Vector<uint8_t> RasterizerStorageOpenGL::voxel_gi_get_distance_field(RID p_voxel_gi) const { + return Vector<uint8_t>(); +} + +Vector<int> RasterizerStorageOpenGL::voxel_gi_get_level_counts(RID p_voxel_gi) const { + return Vector<int>(); +} + +Transform3D RasterizerStorageOpenGL::voxel_gi_get_to_cell_xform(RID p_voxel_gi) const { + return Transform3D(); +} + +void RasterizerStorageOpenGL::voxel_gi_set_dynamic_range(RID p_voxel_gi, float p_range) { +} + +float RasterizerStorageOpenGL::voxel_gi_get_dynamic_range(RID p_voxel_gi) const { + return 0; +} + +void RasterizerStorageOpenGL::voxel_gi_set_propagation(RID p_voxel_gi, float p_range) { +} + +float RasterizerStorageOpenGL::voxel_gi_get_propagation(RID p_voxel_gi) const { + return 0; +} + +void RasterizerStorageOpenGL::voxel_gi_set_energy(RID p_voxel_gi, float p_range) { +} + +float RasterizerStorageOpenGL::voxel_gi_get_energy(RID p_voxel_gi) const { + return 0.0; +} + +void RasterizerStorageOpenGL::voxel_gi_set_bias(RID p_voxel_gi, float p_range) { +} + +float RasterizerStorageOpenGL::voxel_gi_get_bias(RID p_voxel_gi) const { + return 0.0; +} + +void RasterizerStorageOpenGL::voxel_gi_set_normal_bias(RID p_voxel_gi, float p_range) { +} + +float RasterizerStorageOpenGL::voxel_gi_get_normal_bias(RID p_voxel_gi) const { + return 0.0; +} + +void RasterizerStorageOpenGL::voxel_gi_set_interior(RID p_voxel_gi, bool p_enable) { +} + +bool RasterizerStorageOpenGL::voxel_gi_is_interior(RID p_voxel_gi) const { + return false; +} + +void RasterizerStorageOpenGL::voxel_gi_set_use_two_bounces(RID p_voxel_gi, bool p_enable) { +} + +bool RasterizerStorageOpenGL::voxel_gi_is_using_two_bounces(RID p_voxel_gi) const { + return false; +} + +void RasterizerStorageOpenGL::voxel_gi_set_anisotropy_strength(RID p_voxel_gi, float p_strength) { +} + +float RasterizerStorageOpenGL::voxel_gi_get_anisotropy_strength(RID p_voxel_gi) const { + return 0; +} + +uint32_t RasterizerStorageOpenGL::voxel_gi_get_version(RID p_voxel_gi) { + return 0; +} + +/* LIGHTMAP CAPTURE */ +RID RasterizerStorageOpenGL::lightmap_allocate() { + return RID(); +} + +void RasterizerStorageOpenGL::lightmap_initialize(RID p_rid) { +} + +void RasterizerStorageOpenGL::lightmap_set_textures(RID p_lightmap, RID p_light, bool p_uses_spherical_haromics) { +} + +void RasterizerStorageOpenGL::lightmap_set_probe_bounds(RID p_lightmap, const AABB &p_bounds) { +} + +void RasterizerStorageOpenGL::lightmap_set_probe_interior(RID p_lightmap, bool p_interior) { +} + +void RasterizerStorageOpenGL::lightmap_set_probe_capture_data(RID p_lightmap, const PackedVector3Array &p_points, const PackedColorArray &p_point_sh, const PackedInt32Array &p_tetrahedra, const PackedInt32Array &p_bsp_tree) { +} + +PackedVector3Array RasterizerStorageOpenGL::lightmap_get_probe_capture_points(RID p_lightmap) const { + return PackedVector3Array(); +} + +PackedColorArray RasterizerStorageOpenGL::lightmap_get_probe_capture_sh(RID p_lightmap) const { + return PackedColorArray(); +} + +PackedInt32Array RasterizerStorageOpenGL::lightmap_get_probe_capture_tetrahedra(RID p_lightmap) const { + return PackedInt32Array(); +} + +PackedInt32Array RasterizerStorageOpenGL::lightmap_get_probe_capture_bsp_tree(RID p_lightmap) const { + return PackedInt32Array(); +} + +AABB RasterizerStorageOpenGL::lightmap_get_aabb(RID p_lightmap) const { + return AABB(); +} + +void RasterizerStorageOpenGL::lightmap_tap_sh_light(RID p_lightmap, const Vector3 &p_point, Color *r_sh) { +} + +bool RasterizerStorageOpenGL::lightmap_is_interior(RID p_lightmap) const { + return false; +} + +void RasterizerStorageOpenGL::lightmap_set_probe_capture_update_speed(float p_speed) { +} + +float RasterizerStorageOpenGL::lightmap_get_probe_capture_update_speed() const { + return 0; +} + +/* OCCLUDER */ + +void RasterizerStorageOpenGL::occluder_set_mesh(RID p_occluder, const PackedVector3Array &p_vertices, const PackedInt32Array &p_indices) { +} + +/* PARTICLES */ + +RID RasterizerStorageOpenGL::particles_allocate() { + return RID(); +} + +void RasterizerStorageOpenGL::particles_initialize(RID p_rid) { +} + +void RasterizerStorageOpenGL::particles_set_mode(RID p_particles, RS::ParticlesMode p_mode) { +} + +void RasterizerStorageOpenGL::particles_emit(RID p_particles, const Transform3D &p_transform, const Vector3 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags) { +} + +void RasterizerStorageOpenGL::particles_set_emitting(RID p_particles, bool p_emitting) { +} + +void RasterizerStorageOpenGL::particles_set_amount(RID p_particles, int p_amount) { +} + +void RasterizerStorageOpenGL::particles_set_lifetime(RID p_particles, double p_lifetime) { +} + +void RasterizerStorageOpenGL::particles_set_one_shot(RID p_particles, bool p_one_shot) { +} + +void RasterizerStorageOpenGL::particles_set_pre_process_time(RID p_particles, double p_time) { +} + +void RasterizerStorageOpenGL::particles_set_explosiveness_ratio(RID p_particles, real_t p_ratio) { +} + +void RasterizerStorageOpenGL::particles_set_randomness_ratio(RID p_particles, real_t p_ratio) { +} + +void RasterizerStorageOpenGL::particles_set_custom_aabb(RID p_particles, const AABB &p_aabb) { +} + +void RasterizerStorageOpenGL::particles_set_speed_scale(RID p_particles, double p_scale) { +} + +void RasterizerStorageOpenGL::particles_set_use_local_coordinates(RID p_particles, bool p_enable) { +} + +void RasterizerStorageOpenGL::particles_set_process_material(RID p_particles, RID p_material) { +} + +void RasterizerStorageOpenGL::particles_set_fixed_fps(RID p_particles, int p_fps) { +} + +void RasterizerStorageOpenGL::particles_set_interpolate(RID p_particles, bool p_enable) { +} + +void RasterizerStorageOpenGL::particles_set_fractional_delta(RID p_particles, bool p_enable) { +} + +void RasterizerStorageOpenGL::particles_set_subemitter(RID p_particles, RID p_subemitter_particles) { +} + +void RasterizerStorageOpenGL::particles_set_view_axis(RID p_particles, const Vector3 &p_axis, const Vector3 &p_up_axis) { +} + +void RasterizerStorageOpenGL::particles_set_collision_base_size(RID p_particles, real_t p_size) { +} + +void RasterizerStorageOpenGL::particles_set_transform_align(RID p_particles, RS::ParticlesTransformAlign p_transform_align) { +} + +void RasterizerStorageOpenGL::particles_set_trails(RID p_particles, bool p_enable, double p_length) { +} + +void RasterizerStorageOpenGL::particles_set_trail_bind_poses(RID p_particles, const Vector<Transform3D> &p_bind_poses) { +} + +void RasterizerStorageOpenGL::particles_restart(RID p_particles) { +} + +void RasterizerStorageOpenGL::particles_set_draw_order(RID p_particles, RS::ParticlesDrawOrder p_order) { +} + +void RasterizerStorageOpenGL::particles_set_draw_passes(RID p_particles, int p_count) { +} + +void RasterizerStorageOpenGL::particles_set_draw_pass_mesh(RID p_particles, int p_pass, RID p_mesh) { +} + +void RasterizerStorageOpenGL::particles_request_process(RID p_particles) { +} + +AABB RasterizerStorageOpenGL::particles_get_current_aabb(RID p_particles) { + return AABB(); +} + +AABB RasterizerStorageOpenGL::particles_get_aabb(RID p_particles) const { + return AABB(); +} + +void RasterizerStorageOpenGL::particles_set_emission_transform(RID p_particles, const Transform3D &p_transform) { +} + +bool RasterizerStorageOpenGL::particles_get_emitting(RID p_particles) { + return false; +} + +int RasterizerStorageOpenGL::particles_get_draw_passes(RID p_particles) const { + return 0; +} + +RID RasterizerStorageOpenGL::particles_get_draw_pass_mesh(RID p_particles, int p_pass) const { + return RID(); +} + +void RasterizerStorageOpenGL::particles_add_collision(RID p_particles, RID p_instance) { +} + +void RasterizerStorageOpenGL::particles_remove_collision(RID p_particles, RID p_instance) { +} + +void RasterizerStorageOpenGL::particles_set_canvas_sdf_collision(RID p_particles, bool p_enable, const Transform2D &p_xform, const Rect2 &p_to_screen, RID p_texture) { +} + +void RasterizerStorageOpenGL::update_particles() { +} + +/* PARTICLES COLLISION */ + +RID RasterizerStorageOpenGL::particles_collision_allocate() { + return RID(); +} + +void RasterizerStorageOpenGL::particles_collision_initialize(RID p_rid) { +} + +void RasterizerStorageOpenGL::particles_collision_set_collision_type(RID p_particles_collision, RS::ParticlesCollisionType p_type) { +} + +void RasterizerStorageOpenGL::particles_collision_set_cull_mask(RID p_particles_collision, uint32_t p_cull_mask) { +} + +void RasterizerStorageOpenGL::particles_collision_set_sphere_radius(RID p_particles_collision, real_t p_radius) { +} + +void RasterizerStorageOpenGL::particles_collision_set_box_extents(RID p_particles_collision, const Vector3 &p_extents) { +} + +void RasterizerStorageOpenGL::particles_collision_set_attractor_strength(RID p_particles_collision, real_t p_strength) { +} + +void RasterizerStorageOpenGL::particles_collision_set_attractor_directionality(RID p_particles_collision, real_t p_directionality) { +} + +void RasterizerStorageOpenGL::particles_collision_set_attractor_attenuation(RID p_particles_collision, real_t p_curve) { +} + +void RasterizerStorageOpenGL::particles_collision_set_field_texture(RID p_particles_collision, RID p_texture) { +} + +void RasterizerStorageOpenGL::particles_collision_height_field_update(RID p_particles_collision) { +} + +void RasterizerStorageOpenGL::particles_collision_set_height_field_resolution(RID p_particles_collision, RS::ParticlesCollisionHeightfieldResolution p_resolution) { +} + +AABB RasterizerStorageOpenGL::particles_collision_get_aabb(RID p_particles_collision) const { + return AABB(); +} + +bool RasterizerStorageOpenGL::particles_collision_is_heightfield(RID p_particles_collision) const { + return false; +} + +RID RasterizerStorageOpenGL::particles_collision_get_heightfield_framebuffer(RID p_particles_collision) const { + return RID(); +} + +RID RasterizerStorageOpenGL::particles_collision_instance_create(RID p_collision) { + return RID(); +} + +void RasterizerStorageOpenGL::particles_collision_instance_set_transform(RID p_collision_instance, const Transform3D &p_transform) { +} + +void RasterizerStorageOpenGL::particles_collision_instance_set_active(RID p_collision_instance, bool p_active) { +} + +/* VISIBILITY NOTIFIER */ +RID RasterizerStorageOpenGL::visibility_notifier_allocate() { + return RID(); +} + +void RasterizerStorageOpenGL::visibility_notifier_initialize(RID p_notifier) { +} + +void RasterizerStorageOpenGL::visibility_notifier_set_aabb(RID p_notifier, const AABB &p_aabb) { +} + +void RasterizerStorageOpenGL::visibility_notifier_set_callbacks(RID p_notifier, const Callable &p_enter_callbable, const Callable &p_exit_callable) { +} + +AABB RasterizerStorageOpenGL::visibility_notifier_get_aabb(RID p_notifier) const { + return AABB(); +} + +void RasterizerStorageOpenGL::visibility_notifier_call(RID p_notifier, bool p_enter, bool p_deferred) { +} + +/* GLOBAL VARIABLES */ + +void RasterizerStorageOpenGL::global_variable_add(const StringName &p_name, RS::GlobalVariableType p_type, const Variant &p_value) { +} + +void RasterizerStorageOpenGL::global_variable_remove(const StringName &p_name) { +} + +Vector<StringName> RasterizerStorageOpenGL::global_variable_get_list() const { + return Vector<StringName>(); +} + +void RasterizerStorageOpenGL::global_variable_set(const StringName &p_name, const Variant &p_value) { +} + +void RasterizerStorageOpenGL::global_variable_set_override(const StringName &p_name, const Variant &p_value) { +} + +Variant RasterizerStorageOpenGL::global_variable_get(const StringName &p_name) const { + return Variant(); +} + +RS::GlobalVariableType RasterizerStorageOpenGL::global_variable_get_type(const StringName &p_name) const { + return RS::GLOBAL_VAR_TYPE_MAX; +} + +void RasterizerStorageOpenGL::global_variables_load_settings(bool p_load_textures) { +} + +void RasterizerStorageOpenGL::global_variables_clear() { +} + +int32_t RasterizerStorageOpenGL::global_variables_instance_allocate(RID p_instance) { + return 0; +} + +void RasterizerStorageOpenGL::global_variables_instance_free(RID p_instance) { +} + +void RasterizerStorageOpenGL::global_variables_instance_update(RID p_instance, int p_index, const Variant &p_value) { +} + +bool RasterizerStorageOpenGL::particles_is_inactive(RID p_particles) const { + return false; +} + /* RENDER TARGET */ -void RasterizerStorageGLES2::_set_current_render_target(RID p_render_target) { -#ifdef GLES2_DISABLE_RENDER_TARGETS +void RasterizerStorageOpenGL::_set_current_render_target(RID p_render_target) { +#ifdef OPENGL_DISABLE_RENDER_TARGETS return; #endif - RenderTarget *rt = render_target_owner.getornull(p_render_target); + RenderTarget *rt = render_target_owner.get_or_null(p_render_target); // FTODO // if (!p_render_target.is_valid() && storage->frame.current_rt && storage->frame.clear_request) { @@ -2189,7 +3068,7 @@ void RasterizerStorageGLES2::_set_current_render_target(RID p_render_target) { } // if (p_render_target.is_valid()) { - // RasterizerStorageGLES2::RenderTarget *rt = storage.render_target_owner.getornull(p_render_target); + // RasterizerStorageOpenGL::RenderTarget *rt = storage.render_target_owner.get_or_null(p_render_target); frame.current_rt = rt; ERR_FAIL_COND(!rt); frame.clear_request = false; @@ -2212,8 +3091,8 @@ void RasterizerStorageGLES2::_set_current_render_target(RID p_render_target) { } } -void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) { -#ifdef GLES2_DISABLE_RENDER_TARGETS +void RasterizerStorageOpenGL::_render_target_allocate(RenderTarget *rt) { +#ifdef OPENGL_DISABLE_RENDER_TARGETS return; #endif @@ -2223,7 +3102,7 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) { // do not allocate a render target that is attached to the screen if (rt->flags[RENDER_TARGET_DIRECT_TO_SCREEN]) { - rt->fbo = RasterizerStorageGLES2::system_fbo; + rt->fbo = RasterizerStorageOpenGL::system_fbo; return; } @@ -2256,7 +3135,7 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) { { /* Front FBO */ - Texture *texture = texture_owner.getornull(rt->texture); + Texture *texture = texture_owner.get_or_null(rt->texture); ERR_FAIL_COND(!texture); // framebuffer @@ -2344,7 +3223,7 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) { /* For MSAA */ #ifndef JAVASCRIPT_ENABLED - if (rt->msaa >= GD_VS::VIEWPORT_MSAA_2X && rt->msaa <= GD_VS::VIEWPORT_MSAA_8X && config.multisample_supported) { + if (rt->msaa >= RS::VIEWPORT_MSAA_2X && rt->msaa <= RS::VIEWPORT_MSAA_8X && config.multisample_supported) { rt->multisample_active = true; static const int msaa_value[] = { 0, 2, 4, 8, 16 }; @@ -2576,8 +3455,8 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) { bind_framebuffer_system(); } -void RasterizerStorageGLES2::_render_target_clear(RenderTarget *rt) { -#ifdef GLES2_DISABLE_RENDER_TARGETS +void RasterizerStorageOpenGL::_render_target_clear(RenderTarget *rt) { +#ifdef OPENGL_DISABLE_RENDER_TARGETS return; #endif @@ -2596,7 +3475,7 @@ void RasterizerStorageGLES2::_render_target_clear(RenderTarget *rt) { glDeleteFramebuffers(1, &rt->external.fbo); // clean up our texture - Texture *t = texture_owner.getornull(rt->external.texture); + Texture *t = texture_owner.get_or_null(rt->external.texture); t->alloc_height = 0; t->alloc_width = 0; t->width = 0; @@ -2618,7 +3497,7 @@ void RasterizerStorageGLES2::_render_target_clear(RenderTarget *rt) { rt->depth = 0; } - Texture *tex = texture_owner.getornull(rt->texture); + Texture *tex = texture_owner.get_or_null(rt->texture); tex->alloc_height = 0; tex->alloc_width = 0; tex->width = 0; @@ -2662,15 +3541,15 @@ void RasterizerStorageGLES2::_render_target_clear(RenderTarget *rt) { } } -RID RasterizerStorageGLES2::render_target_create() { -#ifdef GLES2_DISABLE_RENDER_TARGETS +RID RasterizerStorageOpenGL::render_target_create() { +#ifdef OPENGL_DISABLE_RENDER_TARGETS // return RID(); #endif RenderTarget *rt = memnew(RenderTarget); Texture *t = memnew(Texture); - t->type = GD_RD::TEXTURE_TYPE_2D; + t->type = RenderingDevice::TEXTURE_TYPE_2D; t->flags = 0; t->width = 0; t->height = 0; @@ -2694,24 +3573,24 @@ RID RasterizerStorageGLES2::render_target_create() { return render_target_owner.make_rid(rt); } -void RasterizerStorageGLES2::render_target_set_position(RID p_render_target, int p_x, int p_y) { -#ifdef GLES2_DISABLE_RENDER_TARGETS +void RasterizerStorageOpenGL::render_target_set_position(RID p_render_target, int p_x, int p_y) { +#ifdef OPENGL_DISABLE_RENDER_TARGETS return; #endif - RenderTarget *rt = render_target_owner.getornull(p_render_target); + RenderTarget *rt = render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND(!rt); rt->x = p_x; rt->y = p_y; } -void RasterizerStorageGLES2::render_target_set_size(RID p_render_target, int p_width, int p_height, uint32_t p_view_count) { -#ifdef GLES2_DISABLE_RENDER_TARGETS +void RasterizerStorageOpenGL::render_target_set_size(RID p_render_target, int p_width, int p_height, uint32_t p_view_count) { +#ifdef OPENGL_DISABLE_RENDER_TARGETS return; #endif - RenderTarget *rt = render_target_owner.getornull(p_render_target); + RenderTarget *rt = render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND(!rt); if (p_width == rt->width && p_height == rt->height) @@ -2728,12 +3607,12 @@ void RasterizerStorageGLES2::render_target_set_size(RID p_render_target, int p_w //_render_target_allocate(rt); } -RID RasterizerStorageGLES2::render_target_get_texture(RID p_render_target) { -#ifdef GLES2_DISABLE_RENDER_TARGETS +RID RasterizerStorageOpenGL::render_target_get_texture(RID p_render_target) { +#ifdef OPENGL_DISABLE_RENDER_TARGETS return RID(); #endif - RenderTarget *rt = render_target_owner.getornull(p_render_target); + RenderTarget *rt = render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND_V(!rt, RID()); if (rt->external.fbo == 0) { @@ -2743,12 +3622,12 @@ RID RasterizerStorageGLES2::render_target_get_texture(RID p_render_target) { } } -void RasterizerStorageGLES2::render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id) { -#ifdef GLES2_DISABLE_RENDER_TARGETS +void RasterizerStorageOpenGL::render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id) { +#ifdef OPENGL_DISABLE_RENDER_TARGETS return; #endif - RenderTarget *rt = render_target_owner.getornull(p_render_target); + RenderTarget *rt = render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND(!rt); if (p_texture_id == 0) { @@ -2762,7 +3641,7 @@ void RasterizerStorageGLES2::render_target_set_external_texture(RID p_render_tar } // clean up our texture - Texture *t = texture_owner.getornull(rt->external.texture); + Texture *t = texture_owner.get_or_null(rt->external.texture); t->alloc_height = 0; t->alloc_width = 0; t->width = 0; @@ -2786,7 +3665,7 @@ void RasterizerStorageGLES2::render_target_set_external_texture(RID p_render_tar // allocate a texture t = memnew(Texture); - t->type = GD_RD::TEXTURE_TYPE_2D; + t->type = RenderingDevice::TEXTURE_TYPE_2D; t->flags = 0; t->width = 0; t->height = 0; @@ -2814,7 +3693,7 @@ void RasterizerStorageGLES2::render_target_set_external_texture(RID p_render_tar bind_framebuffer(rt->external.fbo); // find our texture - t = texture_owner.getornull(rt->external.texture); + t = texture_owner.get_or_null(rt->external.texture); } // set our texture @@ -2829,7 +3708,7 @@ void RasterizerStorageGLES2::render_target_set_external_texture(RID p_render_tar // Switch our texture on our frame buffer #if ANDROID_ENABLED - if (rt->msaa >= GD_VS::VIEWPORT_MSAA_2X && rt->msaa <= GD_VS::VIEWPORT_MSAA_4X) { + if (rt->msaa >= RS::VIEWPORT_MSAA_2X && rt->msaa <= RS::VIEWPORT_MSAA_4X) { // This code only applies to the Oculus Go and Oculus Quest. Due to the the tiled nature // of the GPU we can do a single render pass by rendering directly into our texture chains // texture and apply MSAA as we render. @@ -2838,7 +3717,7 @@ void RasterizerStorageGLES2::render_target_set_external_texture(RID p_render_tar // the normal MSAA modes need to be used to enable our two pass approach static const int msaa_value[] = { 2, 4 }; - int msaa = msaa_value[rt->msaa - GD_VS::VIEWPORT_MSAA_2X]; + int msaa = msaa_value[rt->msaa - RS::VIEWPORT_MSAA_2X]; if (rt->external.depth == 0) { // create a multisample depth buffer, we're not reusing Godots because Godot's didn't get created.. @@ -2877,12 +3756,12 @@ void RasterizerStorageGLES2::render_target_set_external_texture(RID p_render_tar } } -void RasterizerStorageGLES2::render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value) { -#ifdef GLES2_DISABLE_RENDER_TARGETS +void RasterizerStorageOpenGL::render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value) { +#ifdef OPENGL_DISABLE_RENDER_TARGETS return; #endif - RenderTarget *rt = render_target_owner.getornull(p_render_target); + RenderTarget *rt = render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND(!rt); // When setting DIRECT_TO_SCREEN, you need to clear before the value is set, but allocate after as @@ -2913,34 +3792,34 @@ void RasterizerStorageGLES2::render_target_set_flag(RID p_render_target, RenderT } } -bool RasterizerStorageGLES2::render_target_was_used(RID p_render_target) { -#ifdef GLES2_DISABLE_RENDER_TARGETS +bool RasterizerStorageOpenGL::render_target_was_used(RID p_render_target) { +#ifdef OPENGL_DISABLE_RENDER_TARGETS return false; #endif - RenderTarget *rt = render_target_owner.getornull(p_render_target); + RenderTarget *rt = render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND_V(!rt, false); return rt->used_in_frame; } -void RasterizerStorageGLES2::render_target_clear_used(RID p_render_target) { -#ifdef GLES2_DISABLE_RENDER_TARGETS +void RasterizerStorageOpenGL::render_target_clear_used(RID p_render_target) { +#ifdef OPENGL_DISABLE_RENDER_TARGETS return; #endif - RenderTarget *rt = render_target_owner.getornull(p_render_target); + RenderTarget *rt = render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND(!rt); rt->used_in_frame = false; } -void RasterizerStorageGLES2::render_target_set_msaa(RID p_render_target, GD_VS::ViewportMSAA p_msaa) { -#ifdef GLES2_DISABLE_RENDER_TARGETS +void RasterizerStorageOpenGL::render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa) { +#ifdef OPENGL_DISABLE_RENDER_TARGETS return; #endif - RenderTarget *rt = render_target_owner.getornull(p_render_target); + RenderTarget *rt = render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND(!rt); if (rt->msaa == p_msaa) @@ -2956,43 +3835,43 @@ void RasterizerStorageGLES2::render_target_set_msaa(RID p_render_target, GD_VS:: _render_target_allocate(rt); } -//RasterizerStorageGLES2::RenderTarget * RasterizerStorageGLES2::render_target_get(RID p_render_target) +//RasterizerStorageOpenGL::RenderTarget * RasterizerStorageOpenGL::render_target_get(RID p_render_target) //{ -// return render_target_owner.getornull(p_render_target); +// return render_target_owner.get_or_null(p_render_target); //} -void RasterizerStorageGLES2::render_target_set_use_fxaa(RID p_render_target, bool p_fxaa) { -#ifdef GLES2_DISABLE_RENDER_TARGETS +void RasterizerStorageOpenGL::render_target_set_use_fxaa(RID p_render_target, bool p_fxaa) { +#ifdef OPENGL_DISABLE_RENDER_TARGETS return; #endif - RenderTarget *rt = render_target_owner.getornull(p_render_target); + RenderTarget *rt = render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND(!rt); rt->use_fxaa = p_fxaa; } -void RasterizerStorageGLES2::render_target_set_use_debanding(RID p_render_target, bool p_debanding) { -#ifdef GLES2_DISABLE_RENDER_TARGETS +void RasterizerStorageOpenGL::render_target_set_use_debanding(RID p_render_target, bool p_debanding) { +#ifdef OPENGL_DISABLE_RENDER_TARGETS return; #endif - RenderTarget *rt = render_target_owner.getornull(p_render_target); + RenderTarget *rt = render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND(!rt); if (p_debanding) { - WARN_PRINT_ONCE("Debanding is not supported in the GLES2 backend. Switch to the GLES3 backend and make sure HDR is enabled."); + WARN_PRINT_ONCE("Debanding is not supported in the OpenGL backend. Switch to the Vulkan backend and make sure HDR is enabled."); } rt->use_debanding = p_debanding; } -void RasterizerStorageGLES2::render_target_request_clear(RID p_render_target, const Color &p_clear_color) { -#ifdef GLES2_DISABLE_RENDER_TARGETS +void RasterizerStorageOpenGL::render_target_request_clear(RID p_render_target, const Color &p_clear_color) { +#ifdef OPENGL_DISABLE_RENDER_TARGETS return; #endif - RenderTarget *rt = render_target_owner.getornull(p_render_target); + RenderTarget *rt = render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND(!rt); rt->clear_requested = true; rt->clear_color = p_clear_color; @@ -3002,35 +3881,35 @@ void RasterizerStorageGLES2::render_target_request_clear(RID p_render_target, co // frame.clear_request_color = p_color; } -bool RasterizerStorageGLES2::render_target_is_clear_requested(RID p_render_target) { -#ifdef GLES2_DISABLE_RENDER_TARGETS +bool RasterizerStorageOpenGL::render_target_is_clear_requested(RID p_render_target) { +#ifdef OPENGL_DISABLE_RENDER_TARGETS return false; #endif - RenderTarget *rt = render_target_owner.getornull(p_render_target); + RenderTarget *rt = render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND_V(!rt, false); return rt->clear_requested; } -Color RasterizerStorageGLES2::render_target_get_clear_request_color(RID p_render_target) { -#ifdef GLES2_DISABLE_RENDER_TARGETS +Color RasterizerStorageOpenGL::render_target_get_clear_request_color(RID p_render_target) { +#ifdef OPENGL_DISABLE_RENDER_TARGETS return Color(); #endif - RenderTarget *rt = render_target_owner.getornull(p_render_target); + RenderTarget *rt = render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND_V(!rt, Color()); return rt->clear_color; } -void RasterizerStorageGLES2::render_target_disable_clear_request(RID p_render_target) { -#ifdef GLES2_DISABLE_RENDER_TARGETS +void RasterizerStorageOpenGL::render_target_disable_clear_request(RID p_render_target) { +#ifdef OPENGL_DISABLE_RENDER_TARGETS return; #endif - RenderTarget *rt = render_target_owner.getornull(p_render_target); + RenderTarget *rt = render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND(!rt); rt->clear_requested = false; } -void RasterizerStorageGLES2::render_target_do_clear_request(RID p_render_target) { -#ifdef GLES2_DISABLE_RENDER_TARGETS +void RasterizerStorageOpenGL::render_target_do_clear_request(RID p_render_target) { +#ifdef OPENGL_DISABLE_RENDER_TARGETS return; #endif @@ -3040,7 +3919,7 @@ void RasterizerStorageGLES2::render_target_do_clear_request(RID p_render_target) return; /* - RenderTarget *rt = render_target_owner.getornull(p_render_target); + RenderTarget *rt = render_target_owner.get_or_null(p_render_target); ERR_FAIL_COND(!rt); if (!rt->clear_requested) { return; @@ -3054,9 +3933,19 @@ void RasterizerStorageGLES2::render_target_do_clear_request(RID p_render_target) */ } +void RasterizerStorageOpenGL::render_target_set_sdf_size_and_scale(RID p_render_target, RS::ViewportSDFOversize p_size, RS::ViewportSDFScale p_scale) { +} + +Rect2i RasterizerStorageOpenGL::render_target_get_sdf_rect(RID p_render_target) const { + return Rect2i(); +} + +void RasterizerStorageOpenGL::render_target_mark_sdf_enabled(RID p_render_target, bool p_enabled) { +} + /* CANVAS SHADOW */ -RID RasterizerStorageGLES2::canvas_light_shadow_buffer_create(int p_width) { +RID RasterizerStorageOpenGL::canvas_light_shadow_buffer_create(int p_width) { CanvasLightShadow *cls = memnew(CanvasLightShadow); if (p_width > config.max_texture_size) @@ -3108,7 +3997,7 @@ RID RasterizerStorageGLES2::canvas_light_shadow_buffer_create(int p_width) { /* LIGHT SHADOW MAPPING */ /* -RID RasterizerStorageGLES2::canvas_light_occluder_create() { +RID RasterizerStorageOpenGL::canvas_light_occluder_create() { CanvasOccluder *co = memnew(CanvasOccluder); co->index_id = 0; co->vertex_id = 0; @@ -3117,7 +4006,7 @@ RID RasterizerStorageGLES2::canvas_light_occluder_create() { return canvas_occluder_owner.make_rid(co); } -void RasterizerStorageGLES2::canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2> &p_lines) { +void RasterizerStorageOpenGL::canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2> &p_lines) { CanvasOccluder *co = canvas_occluder_owner.get(p_occluder); ERR_FAIL_COND(!co); @@ -3204,34 +4093,34 @@ void RasterizerStorageGLES2::canvas_light_occluder_set_polylines(RID p_occluder, } */ -GD_VS::InstanceType RasterizerStorageGLES2::get_base_type(RID p_rid) const { - return GD_VS::INSTANCE_NONE; +RS::InstanceType RasterizerStorageOpenGL::get_base_type(RID p_rid) const { + return RS::INSTANCE_NONE; /* if (mesh_owner.owns(p_rid)) { - return GD_VS::INSTANCE_MESH; + return RS::INSTANCE_MESH; } else if (light_owner.owns(p_rid)) { - return GD_VS::INSTANCE_LIGHT; + return RS::INSTANCE_LIGHT; } else if (multimesh_owner.owns(p_rid)) { - return GD_VS::INSTANCE_MULTIMESH; + return RS::INSTANCE_MULTIMESH; } else if (immediate_owner.owns(p_rid)) { - return GD_VS::INSTANCE_IMMEDIATE; + return RS::INSTANCE_IMMEDIATE; } else if (reflection_probe_owner.owns(p_rid)) { - return GD_VS::INSTANCE_REFLECTION_PROBE; + return RS::INSTANCE_REFLECTION_PROBE; } else if (lightmap_capture_data_owner.owns(p_rid)) { - return GD_VS::INSTANCE_LIGHTMAP_CAPTURE; + return RS::INSTANCE_LIGHTMAP_CAPTURE; } else { - return GD_VS::INSTANCE_NONE; + return RS::INSTANCE_NONE; } */ } -bool RasterizerStorageGLES2::free(RID p_rid) { +bool RasterizerStorageOpenGL::free(RID p_rid) { if (render_target_owner.owns(p_rid)) { - RenderTarget *rt = render_target_owner.getornull(p_rid); + RenderTarget *rt = render_target_owner.get_or_null(p_rid); _render_target_clear(rt); - Texture *t = texture_owner.getornull(rt->texture); + Texture *t = texture_owner.get_or_null(rt->texture); if (t) { texture_owner.free(rt->texture); memdelete(t); @@ -3241,7 +4130,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (texture_owner.owns(p_rid)) { - Texture *t = texture_owner.getornull(p_rid); + Texture *t = texture_owner.get_or_null(p_rid); // can't free a render target texture ERR_FAIL_COND_V(t->render_target, true); @@ -3251,14 +4140,14 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (sky_owner.owns(p_rid)) { - Sky *sky = sky_owner.getornull(p_rid); + Sky *sky = sky_owner.get_or_null(p_rid); sky_set_texture(p_rid, RID(), 256); sky_owner.free(p_rid); memdelete(sky); return true; } else if (shader_owner.owns(p_rid)) { - Shader *shader = shader_owner.getornull(p_rid); + Shader *shader = shader_owner.get_or_null(p_rid); if (shader->shader && shader->custom_code_id) { shader->shader->free_custom_shader(shader->custom_code_id); @@ -3282,7 +4171,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (material_owner.owns(p_rid)) { - Material *m = material_owner.getornull(p_rid); + Material *m = material_owner.get_or_null(p_rid); if (m->shader) { m->shader->materials.remove(&m->list); @@ -3319,7 +4208,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { } /* } else if (skeleton_owner.owns(p_rid)) { - Skeleton *s = skeleton_owner.getornull(p_rid); + Skeleton *s = skeleton_owner.get_or_null(p_rid); if (s->update_list.in_list()) { skeleton_update_list.remove(&s->update_list); @@ -3340,7 +4229,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (mesh_owner.owns(p_rid)) { - Mesh *mesh = mesh_owner.getornull(p_rid); + Mesh *mesh = mesh_owner.get_or_null(p_rid); mesh->instance_remove_deps(); mesh_clear(p_rid); @@ -3362,17 +4251,17 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (multimesh_owner.owns(p_rid)) { - MultiMesh *multimesh = multimesh_owner.getornull(p_rid); + MultiMesh *multimesh = multimesh_owner.get_or_null(p_rid); multimesh->instance_remove_deps(); if (multimesh->mesh.is_valid()) { - Mesh *mesh = mesh_owner.getornull(multimesh->mesh); + Mesh *mesh = mesh_owner.get_or_null(multimesh->mesh); if (mesh) { mesh->multimeshes.remove(&multimesh->mesh_list); } } - multimesh_allocate(p_rid, 0, GD_VS::MULTIMESH_TRANSFORM_3D, GD_VS::MULTIMESH_COLOR_NONE); + multimesh_allocate(p_rid, 0, RS::MULTIMESH_TRANSFORM_3D, RS::MULTIMESH_COLOR_NONE); update_dirty_multimeshes(); @@ -3381,7 +4270,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (immediate_owner.owns(p_rid)) { - Immediate *im = immediate_owner.getornull(p_rid); + Immediate *im = immediate_owner.get_or_null(p_rid); im->instance_remove_deps(); immediate_owner.free(p_rid); @@ -3389,7 +4278,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (light_owner.owns(p_rid)) { - Light *light = light_owner.getornull(p_rid); + Light *light = light_owner.get_or_null(p_rid); light->instance_remove_deps(); light_owner.free(p_rid); @@ -3398,7 +4287,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (reflection_probe_owner.owns(p_rid)) { // delete the texture - ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_rid); + ReflectionProbe *reflection_probe = reflection_probe_owner.get_or_null(p_rid); reflection_probe->instance_remove_deps(); reflection_probe_owner.free(p_rid); @@ -3407,7 +4296,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (lightmap_capture_data_owner.owns(p_rid)) { // delete the texture - LightmapCapture *lightmap_capture = lightmap_capture_data_owner.getornull(p_rid); + LightmapCapture *lightmap_capture = lightmap_capture_data_owner.get_or_null(p_rid); lightmap_capture->instance_remove_deps(); lightmap_capture_data_owner.free(p_rid); @@ -3415,7 +4304,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (canvas_occluder_owner.owns(p_rid)) { - CanvasOccluder *co = canvas_occluder_owner.getornull(p_rid); + CanvasOccluder *co = canvas_occluder_owner.get_or_null(p_rid); if (co->index_id) glDeleteBuffers(1, &co->index_id); if (co->vertex_id) @@ -3427,7 +4316,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (canvas_light_shadow_owner.owns(p_rid)) { - CanvasLightShadow *cls = canvas_light_shadow_owner.getornull(p_rid); + CanvasLightShadow *cls = canvas_light_shadow_owner.get_or_null(p_rid); glDeleteFramebuffers(1, &cls->fbo); glDeleteRenderbuffers(1, &cls->depth); glDeleteTextures(1, &cls->distance); @@ -3438,7 +4327,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { */ } -bool RasterizerStorageGLES2::has_os_feature(const String &p_feature) const { +bool RasterizerStorageOpenGL::has_os_feature(const String &p_feature) const { if (p_feature == "pvrtc") return config.pvrtc_supported; @@ -3456,14 +4345,14 @@ bool RasterizerStorageGLES2::has_os_feature(const String &p_feature) const { //////////////////////////////////////////// -void RasterizerStorageGLES2::set_debug_generate_wireframes(bool p_generate) { +void RasterizerStorageOpenGL::set_debug_generate_wireframes(bool p_generate) { } -//void RasterizerStorageGLES2::render_info_begin_capture() { +//void RasterizerStorageOpenGL::render_info_begin_capture() { // info.snap = info.render; //} -//void RasterizerStorageGLES2::render_info_end_capture() { +//void RasterizerStorageOpenGL::render_info_end_capture() { // info.snap.object_count = info.render.object_count - info.snap.object_count; // info.snap.draw_call_count = info.render.draw_call_count - info.snap.draw_call_count; // info.snap.material_switch_count = info.render.material_switch_count - info.snap.material_switch_count; @@ -3474,31 +4363,31 @@ void RasterizerStorageGLES2::set_debug_generate_wireframes(bool p_generate) { // info.snap._2d_draw_call_count = info.render._2d_draw_call_count - info.snap._2d_draw_call_count; //} -//int RasterizerStorageGLES2::get_captured_render_info(GD_VS::RenderInfo p_info) { +//int RasterizerStorageOpenGL::get_captured_render_info(RS::RenderInfo p_info) { // switch (p_info) { -// case GD_VS::INFO_OBJECTS_IN_FRAME: { +// case RS::INFO_OBJECTS_IN_FRAME: { // return info.snap.object_count; // } break; -// case GD_VS::INFO_VERTICES_IN_FRAME: { +// case RS::INFO_VERTICES_IN_FRAME: { // return info.snap.vertices_count; // } break; -// case GD_VS::INFO_MATERIAL_CHANGES_IN_FRAME: { +// case RS::INFO_MATERIAL_CHANGES_IN_FRAME: { // return info.snap.material_switch_count; // } break; -// case GD_VS::INFO_SHADER_CHANGES_IN_FRAME: { +// case RS::INFO_SHADER_CHANGES_IN_FRAME: { // return info.snap.shader_rebind_count; // } break; -// case GD_VS::INFO_SURFACE_CHANGES_IN_FRAME: { +// case RS::INFO_SURFACE_CHANGES_IN_FRAME: { // return info.snap.surface_switch_count; // } break; -// case GD_VS::INFO_DRAW_CALLS_IN_FRAME: { +// case RS::INFO_DRAW_CALLS_IN_FRAME: { // return info.snap.draw_call_count; // } break; // /* -// case GD_VS::INFO_2D_ITEMS_IN_FRAME: { +// case RS::INFO_2D_ITEMS_IN_FRAME: { // return info.snap._2d_item_count; // } break; -// case GD_VS::INFO_2D_DRAW_CALLS_IN_FRAME: { +// case RS::INFO_2D_DRAW_CALLS_IN_FRAME: { // return info.snap._2d_draw_call_count; // } break; // */ @@ -3508,49 +4397,49 @@ void RasterizerStorageGLES2::set_debug_generate_wireframes(bool p_generate) { // } //} -//int RasterizerStorageGLES2::get_render_info(GD_VS::RenderInfo p_info) { +//int RasterizerStorageOpenGL::get_render_info(RS::RenderInfo p_info) { // switch (p_info) { -// case GD_VS::INFO_OBJECTS_IN_FRAME: +// case RS::INFO_OBJECTS_IN_FRAME: // return info.render_final.object_count; -// case GD_VS::INFO_VERTICES_IN_FRAME: +// case RS::INFO_VERTICES_IN_FRAME: // return info.render_final.vertices_count; -// case GD_VS::INFO_MATERIAL_CHANGES_IN_FRAME: +// case RS::INFO_MATERIAL_CHANGES_IN_FRAME: // return info.render_final.material_switch_count; -// case GD_VS::INFO_SHADER_CHANGES_IN_FRAME: +// case RS::INFO_SHADER_CHANGES_IN_FRAME: // return info.render_final.shader_rebind_count; -// case GD_VS::INFO_SURFACE_CHANGES_IN_FRAME: +// case RS::INFO_SURFACE_CHANGES_IN_FRAME: // return info.render_final.surface_switch_count; -// case GD_VS::INFO_DRAW_CALLS_IN_FRAME: +// case RS::INFO_DRAW_CALLS_IN_FRAME: // return info.render_final.draw_call_count; // /* -// case GD_VS::INFO_2D_ITEMS_IN_FRAME: +// case RS::INFO_2D_ITEMS_IN_FRAME: // return info.render_final._2d_item_count; -// case GD_VS::INFO_2D_DRAW_CALLS_IN_FRAME: +// case RS::INFO_2D_DRAW_CALLS_IN_FRAME: // return info.render_final._2d_draw_call_count; //*/ -// case GD_VS::INFO_USAGE_VIDEO_MEM_TOTAL: +// case RS::INFO_USAGE_VIDEO_MEM_TOTAL: // return 0; //no idea -// case GD_VS::INFO_VIDEO_MEM_USED: +// case RS::INFO_VIDEO_MEM_USED: // return info.vertex_mem + info.texture_mem; -// case GD_VS::INFO_TEXTURE_MEM_USED: +// case RS::INFO_TEXTURE_MEM_USED: // return info.texture_mem; -// case GD_VS::INFO_VERTEX_MEM_USED: +// case RS::INFO_VERTEX_MEM_USED: // return info.vertex_mem; // default: // return 0; //no idea either // } //} -String RasterizerStorageGLES2::get_video_adapter_name() const { +String RasterizerStorageOpenGL::get_video_adapter_name() const { return (const char *)glGetString(GL_RENDERER); } -String RasterizerStorageGLES2::get_video_adapter_vendor() const { +String RasterizerStorageOpenGL::get_video_adapter_vendor() const { return (const char *)glGetString(GL_VENDOR); } -void RasterizerStorageGLES2::initialize() { - RasterizerStorageGLES2::system_fbo = 0; +void RasterizerStorageOpenGL::initialize() { + RasterizerStorageOpenGL::system_fbo = 0; { const GLubyte *extension_string = glGetString(GL_EXTENSIONS); @@ -3659,7 +4548,7 @@ void RasterizerStorageGLES2::initialize() { #ifdef JAVASCRIPT_ENABLED config.support_half_float_vertices = false; #endif - bool disable_half_float = GLOBAL_GET("rendering/gles2/compatibility/disable_half_float"); + bool disable_half_float = GLOBAL_GET("rendering/opengl/compatibility/disable_half_float"); if (disable_half_float) { config.support_half_float_vertices = false; } @@ -3752,7 +4641,7 @@ void RasterizerStorageGLES2::initialize() { shaders.copy.init(); shaders.cubemap_filter.init(); bool ggx_hq = GLOBAL_GET("rendering/quality/reflections/high_quality_ggx"); - shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES2::LOW_QUALITY, !ggx_hq); + shaders.cubemap_filter.set_conditional(CubemapFilterShaderOpenGL::LOW_QUALITY, !ggx_hq); { // quad for copying stuff @@ -3899,24 +4788,31 @@ void RasterizerStorageGLES2::initialize() { //config.should_orphan = GLOBAL_GET("rendering/options/api_usage_legacy/orphan_buffers"); } -void RasterizerStorageGLES2::finalize() { +void RasterizerStorageOpenGL::finalize() { } -void RasterizerStorageGLES2::_copy_screen() { +void RasterizerStorageOpenGL::_copy_screen() { bind_quad_array(); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } -void RasterizerStorageGLES2::update_dirty_resources() { +void RasterizerStorageOpenGL::update_memory_info() { +} + +uint64_t RasterizerStorageOpenGL::get_rendering_info(RS::RenderingInfo p_info) { + return 0; +} + +void RasterizerStorageOpenGL::update_dirty_resources() { update_dirty_shaders(); update_dirty_materials(); // update_dirty_skeletons(); // update_dirty_multimeshes(); } -RasterizerStorageGLES2::RasterizerStorageGLES2() { - RasterizerStorageGLES2::system_fbo = 0; +RasterizerStorageOpenGL::RasterizerStorageOpenGL() { + RasterizerStorageOpenGL::system_fbo = 0; config.should_orphan = true; } -#endif // GLES2_BACKEND_ENABLED +#endif // OPENGL_BACKEND_ENABLED diff --git a/drivers/opengl/rasterizer_storage_opengl.h b/drivers/opengl/rasterizer_storage_opengl.h new file mode 100644 index 0000000000..c054e47a66 --- /dev/null +++ b/drivers/opengl/rasterizer_storage_opengl.h @@ -0,0 +1,1440 @@ +/*************************************************************************/ +/* rasterizer_storage_opengl.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 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 */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef RASTERIZER_STORAGE_OPENGL_H +#define RASTERIZER_STORAGE_OPENGL_H + +#include "drivers/opengl/rasterizer_platforms.h" +#ifdef OPENGL_BACKEND_ENABLED + +#include "core/templates/local_vector.h" +#include "core/templates/rid_owner.h" +#include "core/templates/self_list.h" +#include "drivers/opengl/rasterizer_asserts.h" +#include "servers/rendering/renderer_compositor.h" +#include "servers/rendering/renderer_storage.h" +#include "servers/rendering/shader_language.h" +#include "shader_compiler_opengl.h" +#include "shader_opengl.h" + +#include "shaders/copy.glsl.gen.h" +#include "shaders/cubemap_filter.glsl.gen.h" + +class RasterizerCanvasOpenGL; +class RasterizerSceneOpenGL; + +class RasterizerStorageOpenGL : public RendererStorage { + friend class RasterizerOpenGL; + + Thread::ID _main_thread_id = 0; + bool _is_main_thread(); + +public: + RasterizerCanvasOpenGL *canvas; + RasterizerSceneOpenGL *scene; + + static GLuint system_fbo; + + struct Config { + bool shrink_textures_x2; + bool use_fast_texture_filter; + bool use_skeleton_software; + + int max_vertex_texture_image_units; + int max_texture_image_units; + int max_texture_size; + + // TODO implement wireframe in OpenGL + // bool generate_wireframes; + + Set<String> extensions; + + bool float_texture_supported; + bool s3tc_supported; + bool etc1_supported; + bool pvrtc_supported; + bool rgtc_supported; + bool bptc_supported; + + bool keep_original_textures; + + bool force_vertex_shading; + + bool use_rgba_2d_shadows; + bool use_rgba_3d_shadows; + + bool support_32_bits_indices; + bool support_write_depth; + bool support_half_float_vertices; + bool support_npot_repeat_mipmap; + bool support_depth_texture; + bool support_depth_cubemaps; + + bool support_shadow_cubemaps; + + bool multisample_supported; + bool render_to_mipmap_supported; + + GLuint depth_internalformat; + GLuint depth_type; + GLuint depth_buffer_internalformat; + + // in some cases the legacy render didn't orphan. We will mark these + // so the user can switch orphaning off for them. + bool should_orphan; + } config; + + struct Resources { + GLuint white_tex; + GLuint black_tex; + GLuint normal_tex; + GLuint aniso_tex; + + GLuint mipmap_blur_fbo; + GLuint mipmap_blur_color; + + GLuint radical_inverse_vdc_cache_tex; + bool use_rgba_2d_shadows; + + GLuint quadie; + + size_t skeleton_transform_buffer_size; + GLuint skeleton_transform_buffer; + LocalVector<float> skeleton_transform_cpu_buffer; + + } resources; + + mutable struct Shaders { + ShaderCompilerOpenGL compiler; + + CopyShaderOpenGL copy; + CubemapFilterShaderOpenGL cubemap_filter; + + ShaderCompilerOpenGL::IdentifierActions actions_canvas; + ShaderCompilerOpenGL::IdentifierActions actions_scene; + ShaderCompilerOpenGL::IdentifierActions actions_particles; + + } shaders; + + struct Info { + uint64_t texture_mem; + uint64_t vertex_mem; + + struct Render { + uint32_t object_count; + uint32_t draw_call_count; + uint32_t material_switch_count; + uint32_t surface_switch_count; + uint32_t shader_rebind_count; + uint32_t vertices_count; + uint32_t _2d_item_count; + uint32_t _2d_draw_call_count; + + void reset() { + object_count = 0; + draw_call_count = 0; + material_switch_count = 0; + surface_switch_count = 0; + shader_rebind_count = 0; + vertices_count = 0; + _2d_item_count = 0; + _2d_draw_call_count = 0; + } + } render, render_final, snap; + + Info() : + texture_mem(0), + vertex_mem(0) { + render.reset(); + render_final.reset(); + } + + } info; + + void bind_quad_array() const; + + ///////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////DATA/////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////// + + /* + struct Instantiable { + RID self; + + SelfList<InstanceBaseDependency>::List instance_list; + + _FORCE_INLINE_ void instance_change_notify(bool p_aabb, bool p_materials) { + SelfList<InstanceBaseDependency> *instances = instance_list.first(); + while (instances) { + instances->self()->base_changed(p_aabb, p_materials); + instances = instances->next(); + } + } + + _FORCE_INLINE_ void instance_remove_deps() { + SelfList<InstanceBaseDependency> *instances = instance_list.first(); + + while (instances) { + instances->self()->base_removed(); + instances = instances->next(); + } + } + + Instantiable() {} + + ~Instantiable() {} + }; + + struct GeometryOwner : public Instantiable { + }; + + struct Geometry : public Instantiable { + enum Type { + GEOMETRY_INVALID, + GEOMETRY_SURFACE, + GEOMETRY_IMMEDIATE, + GEOMETRY_MULTISURFACE + }; + + Type type; + RID material; + uint64_t last_pass; + uint32_t index; + + void material_changed_notify() {} + + Geometry() { + last_pass = 0; + index = 0; + } + }; +*/ + ///////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////API//////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////// + + bool can_create_resources_async() const override; + + // TEXTURE API + + enum OpenGLTextureFlags { + TEXTURE_FLAG_MIPMAPS = 1, /// Enable automatic mipmap generation - when available + TEXTURE_FLAG_REPEAT = 2, /// Repeat texture (Tiling), otherwise Clamping + TEXTURE_FLAG_FILTER = 4, /// Create texture with linear (or available) filter + TEXTURE_FLAG_ANISOTROPIC_FILTER = 8, + TEXTURE_FLAG_CONVERT_TO_LINEAR = 16, + TEXTURE_FLAG_MIRRORED_REPEAT = 32, /// Repeat texture, with alternate sections mirrored + TEXTURE_FLAG_USED_FOR_STREAMING = 2048, + TEXTURE_FLAGS_DEFAULT = TEXTURE_FLAG_REPEAT | TEXTURE_FLAG_MIPMAPS | TEXTURE_FLAG_FILTER + }; + + struct RenderTarget; + + struct Texture { + RID self; + + Texture *proxy; + Set<Texture *> proxy_owners; + + String path; + uint32_t flags; + int width, height, depth; + int alloc_width, alloc_height; + Image::Format format; + RenderingDevice::TextureType type; + + GLenum target; + GLenum gl_format_cache; + GLenum gl_internal_format_cache; + GLenum gl_type_cache; + + int data_size; + int total_data_size; + bool ignore_mipmaps; + + bool compressed; + + bool srgb; + + int mipmaps; + + bool resize_to_po2; + + bool active; + GLenum tex_id; + + uint16_t stored_cube_sides; + + RenderTarget *render_target; + + Vector<Ref<Image>> images; + + bool redraw_if_visible; + + RS::TextureDetectCallback detect_3d; + void *detect_3d_ud; + + RS::TextureDetectCallback detect_srgb; + void *detect_srgb_ud; + + RS::TextureDetectCallback detect_normal; + void *detect_normal_ud; + + // some silly opengl shenanigans where + // texture coords start from bottom left, means we need to draw render target textures upside down + // to be compatible with vulkan etc. + bool is_upside_down() const { + if (proxy) + return proxy->is_upside_down(); + + return render_target != nullptr; + } + + Texture() { + create(); + } + + _ALWAYS_INLINE_ Texture *get_ptr() { + if (proxy) { + return proxy; //->get_ptr(); only one level of indirection, else not inlining possible. + } else { + return this; + } + } + + ~Texture() { + destroy(); + + if (tex_id != 0) { + glDeleteTextures(1, &tex_id); + } + } + + void copy_from(const Texture &o) { + proxy = o.proxy; + flags = o.flags; + width = o.width; + height = o.height; + alloc_width = o.alloc_width; + alloc_height = o.alloc_height; + format = o.format; + type = o.type; + target = o.target; + data_size = o.data_size; + total_data_size = o.total_data_size; + ignore_mipmaps = o.ignore_mipmaps; + compressed = o.compressed; + mipmaps = o.mipmaps; + resize_to_po2 = o.resize_to_po2; + active = o.active; + tex_id = o.tex_id; + stored_cube_sides = o.stored_cube_sides; + render_target = o.render_target; + redraw_if_visible = o.redraw_if_visible; + detect_3d = o.detect_3d; + detect_3d_ud = o.detect_3d_ud; + detect_srgb = o.detect_srgb; + detect_srgb_ud = o.detect_srgb_ud; + detect_normal = o.detect_normal; + detect_normal_ud = o.detect_normal_ud; + + images.clear(); + } + + void create() { + proxy = nullptr; + flags = 0; + width = 0; + height = 0; + alloc_width = 0; + alloc_height = 0; + format = Image::FORMAT_L8; + type = RenderingDevice::TEXTURE_TYPE_2D; + target = 0; + data_size = 0; + total_data_size = 0; + ignore_mipmaps = false; + compressed = false; + mipmaps = 0; + resize_to_po2 = false; + active = false; + tex_id = 0; + stored_cube_sides = 0; + render_target = nullptr; + redraw_if_visible = false; + detect_3d = nullptr; + detect_3d_ud = nullptr; + detect_srgb = nullptr; + detect_srgb_ud = nullptr; + detect_normal = nullptr; + detect_normal_ud = nullptr; + } + void destroy() { + images.clear(); + + for (Set<Texture *>::Element *E = proxy_owners.front(); E; E = E->next()) { + E->get()->proxy = NULL; + } + + if (proxy) { + proxy->proxy_owners.erase(this); + } + } + + // texture state + void GLSetFilter(GLenum p_target, RS::CanvasItemTextureFilter p_filter) { + if (p_filter == state_filter) + return; + state_filter = p_filter; + GLint pmin = GL_LINEAR; // param min + GLint pmag = GL_LINEAR; // param mag + switch (state_filter) { + default: { + } break; + case RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS: { + pmin = GL_LINEAR_MIPMAP_LINEAR; + pmag = GL_LINEAR; + } break; + case RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST: { + pmin = GL_NEAREST; + pmag = GL_NEAREST; + } break; + case RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS: { + pmin = GL_NEAREST_MIPMAP_NEAREST; + pmag = GL_NEAREST; + } break; + } + glTexParameteri(p_target, GL_TEXTURE_MIN_FILTER, pmin); + glTexParameteri(p_target, GL_TEXTURE_MAG_FILTER, pmag); + } + void GLSetRepeat(RS::CanvasItemTextureRepeat p_repeat) { + if (p_repeat == state_repeat) + return; + state_repeat = p_repeat; + GLint prep = GL_CLAMP_TO_EDGE; // parameter repeat + switch (state_repeat) { + default: { + } break; + case RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED: { + prep = GL_REPEAT; + } break; + case RS::CANVAS_ITEM_TEXTURE_REPEAT_MIRROR: { + prep = GL_MIRRORED_REPEAT; + } break; + } + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, prep); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, prep); + } + + private: + RS::CanvasItemTextureFilter state_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR; + RS::CanvasItemTextureRepeat state_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED; + }; + + mutable RID_PtrOwner<Texture> texture_owner; + + Ref<Image> _get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, Image::Format &r_real_format, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool p_force_decompress) const; + + void _texture_set_state_from_flags(Texture *p_tex); + + // new + RID texture_allocate() override; + void texture_2d_initialize(RID p_texture, const Ref<Image> &p_image) override; + void texture_2d_layered_initialize(RID p_texture, const Vector<Ref<Image>> &p_layers, RS::TextureLayeredType p_layered_type) override; + void texture_3d_initialize(RID p_texture, Image::Format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_data) override; + void texture_proxy_initialize(RID p_texture, RID p_base) override; //all slices, then all the mipmaps, must be coherent + + void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) override; + void texture_3d_update(RID p_texture, const Vector<Ref<Image>> &p_data) override {} + void texture_proxy_update(RID p_proxy, RID p_base) override {} + + void texture_2d_placeholder_initialize(RID p_texture) override; + void texture_2d_layered_placeholder_initialize(RID p_texture, RenderingServer::TextureLayeredType p_layered_type) override; + void texture_3d_placeholder_initialize(RID p_texture) override; + + Ref<Image> texture_2d_get(RID p_texture) const override; + Ref<Image> texture_2d_layer_get(RID p_texture, int p_layer) const override { return Ref<Image>(); } + Vector<Ref<Image>> texture_3d_get(RID p_texture) const override { return Vector<Ref<Image>>(); } + + void texture_replace(RID p_texture, RID p_by_texture) override; + //void texture_set_size_override(RID p_texture, int p_width, int p_height) override {} + + void texture_add_to_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override {} + void texture_remove_from_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override {} + + // old + uint32_t texture_get_width(RID p_texture) const; + uint32_t texture_get_height(RID p_texture) const; + +private: + RID texture_create(); + + //void texture_allocate(RID p_texture, int p_width, int p_height, int p_depth_3d, Image::Format p_format, RenderingDevice::TextureType p_type, uint32_t p_flags = TEXTURE_FLAGS_DEFAULT); + void _texture_allocate_internal(RID p_texture, int p_width, int p_height, int p_depth_3d, Image::Format p_format, RenderingDevice::TextureType p_type, uint32_t p_flags = TEXTURE_FLAGS_DEFAULT); + + void texture_set_data(RID p_texture, const Ref<Image> &p_image, int p_layer = 0); + void texture_set_data_partial(RID p_texture, const Ref<Image> &p_image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int p_dst_mip, int p_layer = 0); + //Ref<Image> texture_get_data(RID p_texture, int p_layer = 0) const; + void texture_set_flags(RID p_texture, uint32_t p_flags); + uint32_t texture_get_flags(RID p_texture) const; + Image::Format texture_get_format(RID p_texture) const; + RenderingDevice::TextureType texture_get_type(RID p_texture) const; + uint32_t texture_get_texid(RID p_texture) const; + uint32_t texture_get_depth(RID p_texture) const; + void texture_set_size_override(RID p_texture, int p_width, int p_height) override; + + void texture_bind(RID p_texture, uint32_t p_texture_no); + + void texture_set_path(RID p_texture, const String &p_path) override; + String texture_get_path(RID p_texture) const override; + + void texture_set_shrink_all_x2_on_set_data(bool p_enable); + + void texture_debug_usage(List<RS::TextureInfo> *r_info) override; + + RID texture_create_radiance_cubemap(RID p_source, int p_resolution = -1) const; + + void textures_keep_original(bool p_enable); + + void texture_set_proxy(RID p_texture, RID p_proxy); + Size2 texture_size_with_proxy(RID p_texture) override; + + void texture_set_detect_3d_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override; + void texture_set_detect_srgb_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata); + void texture_set_detect_normal_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override; + void texture_set_detect_roughness_callback(RID p_texture, RS::TextureDetectRoughnessCallback p_callback, void *p_userdata) override {} + + void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) override; + +public: + RID canvas_texture_allocate() override; + void canvas_texture_initialize(RID p_rid) override; + + void canvas_texture_set_channel(RID p_canvas_texture, RS::CanvasTextureChannel p_channel, RID p_texture) override; + void canvas_texture_set_shading_parameters(RID p_canvas_texture, const Color &p_base_color, float p_shininess) override; + + void canvas_texture_set_texture_filter(RID p_item, RS::CanvasItemTextureFilter p_filter) override; + void canvas_texture_set_texture_repeat(RID p_item, RS::CanvasItemTextureRepeat p_repeat) override; + + /* SKY API */ + // not sure if used in godot 4? + struct Sky { + RID self; + RID panorama; + GLuint radiance; + int radiance_size; + }; + + mutable RID_PtrOwner<Sky> sky_owner; + + RID sky_create(); + void sky_set_texture(RID p_sky, RID p_panorama, int p_radiance_size); + + // SHADER API + + struct Material; + + struct Shader { + RID self; + + RS::ShaderMode mode; + ShaderOpenGL *shader; + String code; + SelfList<Material>::List materials; + + Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms; + + uint32_t texture_count; + + uint32_t custom_code_id; + uint32_t version; + + SelfList<Shader> dirty_list; + + Map<StringName, RID> default_textures; + + Vector<ShaderLanguage::ShaderNode::Uniform::Hint> texture_hints; + + bool valid; + + String path; + + uint32_t index; + uint64_t last_pass; + + struct CanvasItem { + enum BlendMode { + BLEND_MODE_MIX, + BLEND_MODE_ADD, + BLEND_MODE_SUB, + BLEND_MODE_MUL, + BLEND_MODE_PMALPHA, + }; + + int blend_mode; + + enum LightMode { + LIGHT_MODE_NORMAL, + LIGHT_MODE_UNSHADED, + LIGHT_MODE_LIGHT_ONLY + }; + + int light_mode; + + // these flags are specifically for batching + // some of the logic is thus in rasterizer_storage.cpp + // we could alternatively set bitflags for each 'uses' and test on the fly + // defined in RasterizerStorageCommon::BatchFlags + unsigned int batch_flags; + + bool uses_screen_texture; + bool uses_screen_uv; + bool uses_time; + bool uses_modulate; + bool uses_color; + bool uses_vertex; + + // all these should disable item joining if used in a custom shader + bool uses_world_matrix; + bool uses_extra_matrix; + bool uses_projection_matrix; + bool uses_instance_custom; + + } canvas_item; + + struct Spatial { + enum BlendMode { + BLEND_MODE_MIX, + BLEND_MODE_ADD, + BLEND_MODE_SUB, + BLEND_MODE_MUL, + }; + + int blend_mode; + + enum DepthDrawMode { + DEPTH_DRAW_OPAQUE, + DEPTH_DRAW_ALWAYS, + DEPTH_DRAW_NEVER, + DEPTH_DRAW_ALPHA_PREPASS, + }; + + int depth_draw_mode; + + enum CullMode { + CULL_MODE_FRONT, + CULL_MODE_BACK, + CULL_MODE_DISABLED, + }; + + int cull_mode; + + bool uses_alpha; + bool uses_alpha_scissor; + bool unshaded; + bool no_depth_test; + bool uses_vertex; + bool uses_discard; + bool uses_sss; + bool uses_screen_texture; + bool uses_depth_texture; + bool uses_time; + bool uses_tangent; + bool uses_ensure_correct_normals; + bool writes_modelview_or_projection; + bool uses_vertex_lighting; + bool uses_world_coordinates; + + } spatial; + + struct Particles { + } particles; + + bool uses_vertex_time; + bool uses_fragment_time; + + Shader() : + dirty_list(this) { + shader = NULL; + valid = false; + custom_code_id = 0; + version = 1; + last_pass = 0; + } + }; + + mutable RID_PtrOwner<Shader> shader_owner; + mutable SelfList<Shader>::List _shader_dirty_list; + + void _shader_make_dirty(Shader *p_shader); + + RID shader_allocate() override; + void shader_initialize(RID p_rid) override; + + //RID shader_create() override; + + void shader_set_code(RID p_shader, const String &p_code) override; + String shader_get_code(RID p_shader) const override; + void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const override; + + void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) override; + RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const override; + + RS::ShaderNativeSourceCode shader_get_native_source_code(RID p_shader) const override { return RS::ShaderNativeSourceCode(); }; + + void shader_add_custom_define(RID p_shader, const String &p_define); + void shader_get_custom_defines(RID p_shader, Vector<String> *p_defines) const; + void shader_remove_custom_define(RID p_shader, const String &p_define); + + void _update_shader(Shader *p_shader) const; + void update_dirty_shaders(); + + // new + Variant shader_get_param_default(RID p_material, const StringName &p_param) const override { return Variant(); } + + // COMMON MATERIAL API + + struct Material { + RID self; + Shader *shader; + Map<StringName, Variant> params; + SelfList<Material> list; + SelfList<Material> dirty_list; + Vector<Pair<StringName, RID>> textures; + float line_width; + int render_priority; + + RID next_pass; + + uint32_t index; + uint64_t last_pass; + + // Map<Geometry *, int> geometry_owners; + // Map<InstanceBaseDependency *, int> instance_owners; + + bool can_cast_shadow_cache; + bool is_animated_cache; + + Material() : + list(this), + dirty_list(this) { + can_cast_shadow_cache = false; + is_animated_cache = false; + shader = NULL; + line_width = 1.0; + last_pass = 0; + render_priority = 0; + } + }; + + mutable SelfList<Material>::List _material_dirty_list; + void _material_make_dirty(Material *p_material) const; + + // void _material_add_geometry(RID p_material, Geometry *p_geometry); + // void _material_remove_geometry(RID p_material, Geometry *p_geometry); + + void _update_material(Material *p_material); + + mutable RID_PtrOwner<Material> material_owner; + + // new + void material_get_instance_shader_parameters(RID p_material, List<InstanceShaderParam> *r_parameters) override {} + void material_update_dependency(RID p_material, DependencyTracker *p_instance) override {} + + // old + RID material_allocate() override; + void material_initialize(RID p_rid) override; + + //RID material_create() override; + + void material_set_shader(RID p_material, RID p_shader) override; + RID material_get_shader(RID p_material) const; + + void material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) override; + Variant material_get_param(RID p_material, const StringName &p_param) const override; + Variant material_get_param_default(RID p_material, const StringName &p_param) const; + + void material_set_line_width(RID p_material, float p_width); + void material_set_next_pass(RID p_material, RID p_next_material) override; + + bool material_is_animated(RID p_material) override; + bool material_casts_shadows(RID p_material) override; + bool material_uses_tangents(RID p_material); + bool material_uses_ensure_correct_normals(RID p_material); + + void material_add_instance_owner(RID p_material, DependencyTracker *p_instance); + void material_remove_instance_owner(RID p_material, DependencyTracker *p_instance); + + void material_set_render_priority(RID p_material, int priority) override; + + void update_dirty_materials(); + + /* MESH API */ + + RID mesh_allocate() override; + void mesh_initialize(RID p_rid) override; + void mesh_set_blend_shape_count(RID p_mesh, int p_blend_shape_count) override; + bool mesh_needs_instance(RID p_mesh, bool p_has_skeleton) override; + RID mesh_instance_create(RID p_base) override; + void mesh_instance_set_skeleton(RID p_mesh_instance, RID p_skeleton) override; + void mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int p_shape, float p_weight) override; + void mesh_instance_check_for_update(RID p_mesh_instance) override; + void update_mesh_instances() override; + void reflection_probe_set_lod_threshold(RID p_probe, float p_ratio) override; + float reflection_probe_get_lod_threshold(RID p_probe) const override; + + void mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface) override; + + int mesh_get_blend_shape_count(RID p_mesh) const override; + + void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode) override; + RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const override; + + void mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override; + void mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override; + void mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override; + + void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) override; + RID mesh_surface_get_material(RID p_mesh, int p_surface) const override; + + RS::SurfaceData mesh_get_surface(RID p_mesh, int p_surface) const override; + int mesh_get_surface_count(RID p_mesh) const override; + + void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) override; + AABB mesh_get_custom_aabb(RID p_mesh) const override; + + AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID()) override; + void mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) override; + void mesh_clear(RID p_mesh) override; + + /* MULTIMESH API */ + + RID multimesh_allocate() override; + void multimesh_initialize(RID p_rid) override; + void multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false) override; + int multimesh_get_instance_count(RID p_multimesh) const override; + + void multimesh_set_mesh(RID p_multimesh, RID p_mesh) override; + void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform) override; + void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) override; + void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) override; + void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) override; + + RID multimesh_get_mesh(RID p_multimesh) const override; + AABB multimesh_get_aabb(RID p_multimesh) const override; + + Transform3D multimesh_instance_get_transform(RID p_multimesh, int p_index) const override; + Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const override; + Color multimesh_instance_get_color(RID p_multimesh, int p_index) const override; + Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const override; + void multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) override; + Vector<float> multimesh_get_buffer(RID p_multimesh) const override; + + void multimesh_set_visible_instances(RID p_multimesh, int p_visible) override; + int multimesh_get_visible_instances(RID p_multimesh) const override; + + /* SKELETON API */ + + RID skeleton_allocate() override; + void skeleton_initialize(RID p_rid) override; + void skeleton_allocate_data(RID p_skeleton, int p_bones, bool p_2d_skeleton = false) override; + void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform) override; + int skeleton_get_bone_count(RID p_skeleton) const override; + void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform3D &p_transform) override; + Transform3D skeleton_bone_get_transform(RID p_skeleton, int p_bone) const override; + void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform) override; + Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const override; + + /* Light API */ + + RID directional_light_allocate() override; + void directional_light_initialize(RID p_rid) override; + RID omni_light_allocate() override; + void omni_light_initialize(RID p_rid) override; + RID spot_light_allocate() override; + void spot_light_initialize(RID p_rid) override; + RID reflection_probe_allocate() override; + void reflection_probe_initialize(RID p_rid) override; + + void light_set_color(RID p_light, const Color &p_color) override; + void light_set_param(RID p_light, RS::LightParam p_param, float p_value) override; + void light_set_shadow(RID p_light, bool p_enabled) override; + void light_set_shadow_color(RID p_light, const Color &p_color) override; + void light_set_projector(RID p_light, RID p_texture) override; + void light_set_negative(RID p_light, bool p_enable) override; + void light_set_cull_mask(RID p_light, uint32_t p_mask) override; + void light_set_reverse_cull_face_mode(RID p_light, bool p_enabled) override; + void light_set_bake_mode(RID p_light, RS::LightBakeMode p_bake_mode) override; + void light_set_max_sdfgi_cascade(RID p_light, uint32_t p_cascade) override; + + void light_omni_set_shadow_mode(RID p_light, RS::LightOmniShadowMode p_mode) override; + + void light_directional_set_shadow_mode(RID p_light, RS::LightDirectionalShadowMode p_mode) override; + void light_directional_set_blend_splits(RID p_light, bool p_enable) override; + bool light_directional_get_blend_splits(RID p_light) const override; + void light_directional_set_sky_only(RID p_light, bool p_sky_only) override; + bool light_directional_is_sky_only(RID p_light) const override; + + RS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light) override; + RS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light) override; + + bool light_has_shadow(RID p_light) const override; + bool light_has_projector(RID p_light) const override; + + RS::LightType light_get_type(RID p_light) const override; + AABB light_get_aabb(RID p_light) const override; + float light_get_param(RID p_light, RS::LightParam p_param) override; + Color light_get_color(RID p_light) override; + RS::LightBakeMode light_get_bake_mode(RID p_light) override; + uint32_t light_get_max_sdfgi_cascade(RID p_light) override; + uint64_t light_get_version(RID p_light) const override; + + /* PROBE API */ + + void reflection_probe_set_update_mode(RID p_probe, RS::ReflectionProbeUpdateMode p_mode) override; + void reflection_probe_set_intensity(RID p_probe, float p_intensity) override; + void reflection_probe_set_ambient_mode(RID p_probe, RS::ReflectionProbeAmbientMode p_mode) override; + void reflection_probe_set_ambient_color(RID p_probe, const Color &p_color) override; + void reflection_probe_set_ambient_energy(RID p_probe, float p_energy) override; + void reflection_probe_set_max_distance(RID p_probe, float p_distance) override; + void reflection_probe_set_extents(RID p_probe, const Vector3 &p_extents) override; + void reflection_probe_set_origin_offset(RID p_probe, const Vector3 &p_offset) override; + void reflection_probe_set_as_interior(RID p_probe, bool p_enable) override; + void reflection_probe_set_enable_box_projection(RID p_probe, bool p_enable) override; + void reflection_probe_set_enable_shadows(RID p_probe, bool p_enable) override; + void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers) override; + void reflection_probe_set_resolution(RID p_probe, int p_resolution) override; + + AABB reflection_probe_get_aabb(RID p_probe) const override; + RS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const override; + uint32_t reflection_probe_get_cull_mask(RID p_probe) const override; + Vector3 reflection_probe_get_extents(RID p_probe) const override; + Vector3 reflection_probe_get_origin_offset(RID p_probe) const override; + float reflection_probe_get_origin_max_distance(RID p_probe) const override; + bool reflection_probe_renders_shadows(RID p_probe) const override; + + void base_update_dependency(RID p_base, DependencyTracker *p_instance) override; + void skeleton_update_dependency(RID p_base, DependencyTracker *p_instance) override; + + /* DECAL API */ + + RID decal_allocate() override; + void decal_initialize(RID p_rid) override; + void decal_set_extents(RID p_decal, const Vector3 &p_extents) override; + void decal_set_texture(RID p_decal, RS::DecalTexture p_type, RID p_texture) override; + void decal_set_emission_energy(RID p_decal, float p_energy) override; + void decal_set_albedo_mix(RID p_decal, float p_mix) override; + void decal_set_modulate(RID p_decal, const Color &p_modulate) override; + void decal_set_cull_mask(RID p_decal, uint32_t p_layers) override; + void decal_set_distance_fade(RID p_decal, bool p_enabled, float p_begin, float p_length) override; + void decal_set_fade(RID p_decal, float p_above, float p_below) override; + void decal_set_normal_fade(RID p_decal, float p_fade) override; + + AABB decal_get_aabb(RID p_decal) const override; + + /* VOXEL GI API */ + + RID voxel_gi_allocate() override; + void voxel_gi_initialize(RID p_rid) override; + void voxel_gi_allocate_data(RID p_voxel_gi, const Transform3D &p_to_cell_xform, const AABB &p_aabb, const Vector3i &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts) override; + + AABB voxel_gi_get_bounds(RID p_voxel_gi) const override; + Vector3i voxel_gi_get_octree_size(RID p_voxel_gi) const override; + Vector<uint8_t> voxel_gi_get_octree_cells(RID p_voxel_gi) const override; + Vector<uint8_t> voxel_gi_get_data_cells(RID p_voxel_gi) const override; + Vector<uint8_t> voxel_gi_get_distance_field(RID p_voxel_gi) const override; + + Vector<int> voxel_gi_get_level_counts(RID p_voxel_gi) const override; + Transform3D voxel_gi_get_to_cell_xform(RID p_voxel_gi) const override; + + void voxel_gi_set_dynamic_range(RID p_voxel_gi, float p_range) override; + float voxel_gi_get_dynamic_range(RID p_voxel_gi) const override; + + void voxel_gi_set_propagation(RID p_voxel_gi, float p_range) override; + float voxel_gi_get_propagation(RID p_voxel_gi) const override; + + void voxel_gi_set_energy(RID p_voxel_gi, float p_range) override; + float voxel_gi_get_energy(RID p_voxel_gi) const override; + + void voxel_gi_set_bias(RID p_voxel_gi, float p_range) override; + float voxel_gi_get_bias(RID p_voxel_gi) const override; + + void voxel_gi_set_normal_bias(RID p_voxel_gi, float p_range) override; + float voxel_gi_get_normal_bias(RID p_voxel_gi) const override; + + void voxel_gi_set_interior(RID p_voxel_gi, bool p_enable) override; + bool voxel_gi_is_interior(RID p_voxel_gi) const override; + + void voxel_gi_set_use_two_bounces(RID p_voxel_gi, bool p_enable) override; + bool voxel_gi_is_using_two_bounces(RID p_voxel_gi) const override; + + void voxel_gi_set_anisotropy_strength(RID p_voxel_gi, float p_strength) override; + float voxel_gi_get_anisotropy_strength(RID p_voxel_gi) const override; + + uint32_t voxel_gi_get_version(RID p_voxel_gi) override; + + /* LIGHTMAP CAPTURE */ + RID lightmap_allocate() override; + void lightmap_initialize(RID p_rid) override; + void lightmap_set_textures(RID p_lightmap, RID p_light, bool p_uses_spherical_haromics) override; + void lightmap_set_probe_bounds(RID p_lightmap, const AABB &p_bounds) override; + void lightmap_set_probe_interior(RID p_lightmap, bool p_interior) override; + void lightmap_set_probe_capture_data(RID p_lightmap, const PackedVector3Array &p_points, const PackedColorArray &p_point_sh, const PackedInt32Array &p_tetrahedra, const PackedInt32Array &p_bsp_tree) override; + PackedVector3Array lightmap_get_probe_capture_points(RID p_lightmap) const override; + PackedColorArray lightmap_get_probe_capture_sh(RID p_lightmap) const override; + PackedInt32Array lightmap_get_probe_capture_tetrahedra(RID p_lightmap) const override; + PackedInt32Array lightmap_get_probe_capture_bsp_tree(RID p_lightmap) const override; + AABB lightmap_get_aabb(RID p_lightmap) const override; + void lightmap_tap_sh_light(RID p_lightmap, const Vector3 &p_point, Color *r_sh) override; + bool lightmap_is_interior(RID p_lightmap) const override; + void lightmap_set_probe_capture_update_speed(float p_speed) override; + float lightmap_get_probe_capture_update_speed() const override; + + /* OCCLUDER */ + + void occluder_set_mesh(RID p_occluder, const PackedVector3Array &p_vertices, const PackedInt32Array &p_indices); + + /* PARTICLES */ + + RID particles_allocate() override; + void particles_initialize(RID p_rid) override; + void particles_set_mode(RID p_particles, RS::ParticlesMode p_mode) override; + void particles_emit(RID p_particles, const Transform3D &p_transform, const Vector3 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags) override; + void particles_set_emitting(RID p_particles, bool p_emitting) override; + void particles_set_amount(RID p_particles, int p_amount) override; + void particles_set_lifetime(RID p_particles, double p_lifetime) override; + void particles_set_one_shot(RID p_particles, bool p_one_shot) override; + void particles_set_pre_process_time(RID p_particles, double p_time) override; + void particles_set_explosiveness_ratio(RID p_particles, real_t p_ratio) override; + void particles_set_randomness_ratio(RID p_particles, real_t p_ratio) override; + void particles_set_custom_aabb(RID p_particles, const AABB &p_aabb) override; + void particles_set_speed_scale(RID p_particles, double p_scale) override; + void particles_set_use_local_coordinates(RID p_particles, bool p_enable) override; + void particles_set_process_material(RID p_particles, RID p_material) override; + void particles_set_fixed_fps(RID p_particles, int p_fps) override; + void particles_set_interpolate(RID p_particles, bool p_enable) override; + void particles_set_fractional_delta(RID p_particles, bool p_enable) override; + void particles_set_subemitter(RID p_particles, RID p_subemitter_particles) override; + void particles_set_view_axis(RID p_particles, const Vector3 &p_axis, const Vector3 &p_up_axis) override; + void particles_set_collision_base_size(RID p_particles, real_t p_size) override; + + void particles_set_transform_align(RID p_particles, RS::ParticlesTransformAlign p_transform_align) override; + + void particles_set_trails(RID p_particles, bool p_enable, double p_length) override; + void particles_set_trail_bind_poses(RID p_particles, const Vector<Transform3D> &p_bind_poses) override; + + void particles_restart(RID p_particles) override; + + void particles_set_draw_order(RID p_particles, RS::ParticlesDrawOrder p_order) override; + + void particles_set_draw_passes(RID p_particles, int p_count) override; + void particles_set_draw_pass_mesh(RID p_particles, int p_pass, RID p_mesh) override; + + void particles_request_process(RID p_particles) override; + AABB particles_get_current_aabb(RID p_particles) override; + AABB particles_get_aabb(RID p_particles) const override; + + void particles_set_emission_transform(RID p_particles, const Transform3D &p_transform) override; + + bool particles_get_emitting(RID p_particles) override; + int particles_get_draw_passes(RID p_particles) const override; + RID particles_get_draw_pass_mesh(RID p_particles, int p_pass) const override; + + void particles_add_collision(RID p_particles, RID p_instance) override; + void particles_remove_collision(RID p_particles, RID p_instance) override; + + void particles_set_canvas_sdf_collision(RID p_particles, bool p_enable, const Transform2D &p_xform, const Rect2 &p_to_screen, RID p_texture) override; + + void update_particles() override; + + /* PARTICLES COLLISION */ + + RID particles_collision_allocate() override; + void particles_collision_initialize(RID p_rid) override; + void particles_collision_set_collision_type(RID p_particles_collision, RS::ParticlesCollisionType p_type) override; + void particles_collision_set_cull_mask(RID p_particles_collision, uint32_t p_cull_mask) override; + void particles_collision_set_sphere_radius(RID p_particles_collision, real_t p_radius) override; + void particles_collision_set_box_extents(RID p_particles_collision, const Vector3 &p_extents) override; + void particles_collision_set_attractor_strength(RID p_particles_collision, real_t p_strength) override; + void particles_collision_set_attractor_directionality(RID p_particles_collision, real_t p_directionality) override; + void particles_collision_set_attractor_attenuation(RID p_particles_collision, real_t p_curve) override; + void particles_collision_set_field_texture(RID p_particles_collision, RID p_texture) override; + void particles_collision_height_field_update(RID p_particles_collision) override; + void particles_collision_set_height_field_resolution(RID p_particles_collision, RS::ParticlesCollisionHeightfieldResolution p_resolution) override; + AABB particles_collision_get_aabb(RID p_particles_collision) const override; + bool particles_collision_is_heightfield(RID p_particles_collision) const override; + RID particles_collision_get_heightfield_framebuffer(RID p_particles_collision) const override; + + RID particles_collision_instance_create(RID p_collision) override; + void particles_collision_instance_set_transform(RID p_collision_instance, const Transform3D &p_transform) override; + void particles_collision_instance_set_active(RID p_collision_instance, bool p_active) override; + + /* VISIBILITY NOTIFIER */ + RID visibility_notifier_allocate() override; + void visibility_notifier_initialize(RID p_notifier) override; + void visibility_notifier_set_aabb(RID p_notifier, const AABB &p_aabb) override; + void visibility_notifier_set_callbacks(RID p_notifier, const Callable &p_enter_callbable, const Callable &p_exit_callable) override; + + AABB visibility_notifier_get_aabb(RID p_notifier) const override; + void visibility_notifier_call(RID p_notifier, bool p_enter, bool p_deferred) override; + + /* GLOBAL VARIABLES */ + + void global_variable_add(const StringName &p_name, RS::GlobalVariableType p_type, const Variant &p_value) override; + void global_variable_remove(const StringName &p_name) override; + Vector<StringName> global_variable_get_list() const override; + + void global_variable_set(const StringName &p_name, const Variant &p_value) override; + void global_variable_set_override(const StringName &p_name, const Variant &p_value) override; + Variant global_variable_get(const StringName &p_name) const override; + RS::GlobalVariableType global_variable_get_type(const StringName &p_name) const override; + + void global_variables_load_settings(bool p_load_textures = true) override; + void global_variables_clear() override; + + int32_t global_variables_instance_allocate(RID p_instance) override; + void global_variables_instance_free(RID p_instance) override; + void global_variables_instance_update(RID p_instance, int p_index, const Variant &p_value) override; + + bool particles_is_inactive(RID p_particles) const override; + + // RENDER TARGET + + struct RenderTarget { + RID self; + GLuint fbo; + GLuint color; + GLuint depth; + + GLuint multisample_fbo; + GLuint multisample_color; + GLuint multisample_depth; + bool multisample_active; + + struct Effect { + GLuint fbo; + int width; + int height; + + GLuint color; + + Effect() : + fbo(0), + width(0), + height(0), + color(0) { + } + }; + + Effect copy_screen_effect; + + struct MipMaps { + struct Size { + GLuint fbo; + GLuint color; + int width; + int height; + }; + + Vector<Size> sizes; + GLuint color; + int levels; + + MipMaps() : + color(0), + levels(0) { + } + }; + + MipMaps mip_maps[2]; + + struct External { + GLuint fbo; + GLuint color; + GLuint depth; + RID texture; + + External() : + fbo(0), + color(0), + depth(0) { + } + } external; + + int x, y, width, height; + + bool flags[RENDER_TARGET_FLAG_MAX]; + + // instead of allocating sized render targets immediately, + // defer this for faster startup + bool allocate_is_dirty = false; + bool used_in_frame; + RS::ViewportMSAA msaa; + + bool use_fxaa; + bool use_debanding; + + RID texture; + + bool used_dof_blur_near; + bool mip_maps_allocated; + + Color clear_color; + bool clear_requested; + + RenderTarget() : + fbo(0), + color(0), + depth(0), + multisample_fbo(0), + multisample_color(0), + multisample_depth(0), + multisample_active(false), + x(0), + y(0), + width(0), + height(0), + used_in_frame(false), + msaa(RS::VIEWPORT_MSAA_DISABLED), + use_fxaa(false), + use_debanding(false), + used_dof_blur_near(false), + mip_maps_allocated(false), + clear_color(Color(1, 1, 1, 1)), + clear_requested(false) { + for (int i = 0; i < RENDER_TARGET_FLAG_MAX; ++i) { + flags[i] = false; + } + external.fbo = 0; + } + }; + + mutable RID_PtrOwner<RenderTarget> render_target_owner; + + void _render_target_clear(RenderTarget *rt); + void _render_target_allocate(RenderTarget *rt); + void _set_current_render_target(RID p_render_target); + + RID render_target_create() override; + void render_target_set_position(RID p_render_target, int p_x, int p_y) override; + void render_target_set_size(RID p_render_target, int p_width, int p_height, uint32_t p_view_count) override; + RID render_target_get_texture(RID p_render_target) override; + void render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id) override; + + void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value) override; + bool render_target_was_used(RID p_render_target) override; + void render_target_clear_used(RID p_render_target); + void render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa); + void render_target_set_use_fxaa(RID p_render_target, bool p_fxaa); + void render_target_set_use_debanding(RID p_render_target, bool p_debanding); + + // new + void render_target_set_as_unused(RID p_render_target) override { + render_target_clear_used(p_render_target); + } + + void render_target_request_clear(RID p_render_target, const Color &p_clear_color) override; + bool render_target_is_clear_requested(RID p_render_target) override; + Color render_target_get_clear_request_color(RID p_render_target) override; + void render_target_disable_clear_request(RID p_render_target) override; + void render_target_do_clear_request(RID p_render_target) override; + + void render_target_set_sdf_size_and_scale(RID p_render_target, RS::ViewportSDFOversize p_size, RS::ViewportSDFScale p_scale) override; + Rect2i render_target_get_sdf_rect(RID p_render_target) const override; + void render_target_mark_sdf_enabled(RID p_render_target, bool p_enabled) override; + + // access from canvas + // RenderTarget * render_target_get(RID p_render_target); + + /* CANVAS SHADOW */ + + struct CanvasLightShadow { + RID self; + int size; + int height; + GLuint fbo; + GLuint depth; + GLuint distance; //for older devices + }; + + RID_PtrOwner<CanvasLightShadow> canvas_light_shadow_owner; + + RID canvas_light_shadow_buffer_create(int p_width); + + /* LIGHT SHADOW MAPPING */ + /* + struct CanvasOccluder { + RID self; + + GLuint vertex_id; // 0 means, unconfigured + GLuint index_id; // 0 means, unconfigured + LocalVector<Vector2> lines; + int len; + }; + + RID_Owner<CanvasOccluder> canvas_occluder_owner; + + RID canvas_light_occluder_create(); + void canvas_light_occluder_set_polylines(RID p_occluder, const LocalVector<Vector2> &p_lines); +*/ + + RS::InstanceType get_base_type(RID p_rid) const override; + + bool free(RID p_rid) override; + + struct Frame { + RenderTarget *current_rt; + + // these 2 may have been superceded by the equivalents in the render target. + // these may be able to be removed. + bool clear_request; + Color clear_request_color; + + float time[4]; + float delta; + uint64_t count; + + Frame() { + // current_rt = nullptr; + // clear_request = false; + } + } frame; + + void initialize(); + void finalize(); + + void _copy_screen(); + + void update_memory_info() override; + uint64_t get_rendering_info(RS::RenderingInfo p_info) override; + + bool has_os_feature(const String &p_feature) const override; + + void update_dirty_resources() override; + + void set_debug_generate_wireframes(bool p_generate) override; + + // void render_info_begin_capture() override; + // void render_info_end_capture() override; + // int get_captured_render_info(RS::RenderInfo p_info) override; + + // int get_render_info(RS::RenderInfo p_info) override; + String get_video_adapter_name() const override; + String get_video_adapter_vendor() const override; + + void capture_timestamps_begin() override {} + void capture_timestamp(const String &p_name) override {} + uint32_t get_captured_timestamps_count() const override { + return 0; + } + uint64_t get_captured_timestamps_frame() const override { + return 0; + } + uint64_t get_captured_timestamp_gpu_time(uint32_t p_index) const override { + return 0; + } + uint64_t get_captured_timestamp_cpu_time(uint32_t p_index) const override { + return 0; + } + String get_captured_timestamp_name(uint32_t p_index) const override { + return String(); + } + + // make access easier to these + struct Dimensions { + // render target + int rt_width; + int rt_height; + + // window + int win_width; + int win_height; + Dimensions() { + rt_width = 0; + rt_height = 0; + win_width = 0; + win_height = 0; + } + } _dims; + + void buffer_orphan_and_upload(unsigned int p_buffer_size, unsigned int p_offset, unsigned int p_data_size, const void *p_data, GLenum p_target = GL_ARRAY_BUFFER, GLenum p_usage = GL_DYNAMIC_DRAW, bool p_optional_orphan = false) const; + bool safe_buffer_sub_data(unsigned int p_total_buffer_size, GLenum p_target, unsigned int p_offset, unsigned int p_data_size, const void *p_data, unsigned int &r_offset_after) const; + + void bind_framebuffer(GLuint framebuffer) { + glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); + } + + void bind_framebuffer_system() { + glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageOpenGL::system_fbo); + } + + RasterizerStorageOpenGL(); +}; + +inline bool RasterizerStorageOpenGL::safe_buffer_sub_data(unsigned int p_total_buffer_size, GLenum p_target, unsigned int p_offset, unsigned int p_data_size, const void *p_data, unsigned int &r_offset_after) const { + r_offset_after = p_offset + p_data_size; +#ifdef DEBUG_ENABLED + // we are trying to write across the edge of the buffer + if (r_offset_after > p_total_buffer_size) + return false; +#endif + glBufferSubData(p_target, p_offset, p_data_size, p_data); + return true; +} + +// standardize the orphan / upload in one place so it can be changed per platform as necessary, and avoid future +// bugs causing pipeline stalls +inline void RasterizerStorageOpenGL::buffer_orphan_and_upload(unsigned int p_buffer_size, unsigned int p_offset, unsigned int p_data_size, const void *p_data, GLenum p_target, GLenum p_usage, bool p_optional_orphan) const { + // Orphan the buffer to avoid CPU/GPU sync points caused by glBufferSubData + // Was previously #ifndef GLES_OVER_GL however this causes stalls on desktop mac also (and possibly other) + if (!p_optional_orphan || (config.should_orphan)) { + glBufferData(p_target, p_buffer_size, NULL, p_usage); +#ifdef RASTERIZER_EXTRA_CHECKS + // fill with garbage off the end of the array + if (p_buffer_size) { + unsigned int start = p_offset + p_data_size; + unsigned int end = start + 1024; + if (end < p_buffer_size) { + uint8_t *garbage = (uint8_t *)alloca(1024); + for (int n = 0; n < 1024; n++) { + garbage[n] = Math::random(0, 255); + } + glBufferSubData(p_target, start, 1024, garbage); + } + } +#endif + } + RAST_DEV_DEBUG_ASSERT((p_offset + p_data_size) <= p_buffer_size); + glBufferSubData(p_target, p_offset, p_data_size, p_data); +} + +#endif // OPENGL_BACKEND_ENABLED + +#endif // RASTERIZER_STORAGE_OPENGL_H diff --git a/drivers/gles2/shader_compiler_gles2.cpp b/drivers/opengl/shader_compiler_opengl.cpp index 2784b156fc..9638626d78 100644 --- a/drivers/gles2/shader_compiler_gles2.cpp +++ b/drivers/opengl/shader_compiler_opengl.cpp @@ -1,12 +1,12 @@ /*************************************************************************/ -/* shader_compiler_gles2.cpp */ +/* shader_compiler_opengl.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 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 */ @@ -28,24 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "shader_compiler_gles2.h" -#ifdef GLES2_BACKEND_ENABLED +#include "shader_compiler_opengl.h" +#ifdef OPENGL_BACKEND_ENABLED -#include "core/os/os.h" - -//#ifdef GODOT_3 - -#ifdef GODOT_3 -#include "core/project_settings.h" -#include "core/string_buffer.h" -#include "core/string_builder.h" -#else #include "core/config/project_settings.h" +#include "core/os/os.h" #include "core/string/string_buffer.h" #include "core/string/string_builder.h" -#endif - #define SL ShaderLanguage static String _mktab(int p_level) { @@ -216,7 +206,7 @@ static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNo } } -void ShaderCompilerGLES2::_dump_function_deps(SL::ShaderNode *p_node, const StringName &p_for_func, const Map<StringName, String> &p_func_code, StringBuilder &r_to_add, Set<StringName> &r_added) { +void ShaderCompilerOpenGL::_dump_function_deps(SL::ShaderNode *p_node, const StringName &p_for_func, const Map<StringName, String> &p_func_code, StringBuilder &r_to_add, Set<StringName> &r_added) { int fidx = -1; for (int i = 0; i < p_node->functions.size(); i++) { @@ -274,7 +264,7 @@ void ShaderCompilerGLES2::_dump_function_deps(SL::ShaderNode *p_node, const Stri } } -String ShaderCompilerGLES2::_dump_node_code(SL::Node *p_node, int p_level, GeneratedCode &r_gen_code, IdentifierActions &p_actions, const DefaultIdentifierActions &p_default_actions, bool p_assigning, bool p_use_scope) { +String ShaderCompilerOpenGL::_dump_node_code(SL::Node *p_node, int p_level, GeneratedCode &r_gen_code, IdentifierActions &p_actions, const DefaultIdentifierActions &p_default_actions, bool p_assigning, bool p_use_scope) { StringBuilder code; switch (p_node->type) { @@ -852,16 +842,15 @@ String ShaderCompilerGLES2::_dump_node_code(SL::Node *p_node, int p_level, Gener return code.as_string(); } -ShaderLanguage::DataType ShaderCompilerGLES2::_get_variable_type(const StringName &p_type) { +ShaderLanguage::DataType ShaderCompilerOpenGL::_get_variable_type(const StringName &p_type) { // RS::GlobalVariableType gvt = ((RasterizerStorageRD *)(RendererStorage::base_singleton))->global_variable_get_type_internal(p_type); RS::GlobalVariableType gvt = RS::GLOBAL_VAR_TYPE_MAX; return RS::global_variable_type_get_shader_datatype(gvt); } -Error ShaderCompilerGLES2::compile(GD_VS::ShaderMode p_mode, const String &p_code, IdentifierActions *p_actions, const String &p_path, GeneratedCode &r_gen_code) { - +Error ShaderCompilerOpenGL::compile(RS::ShaderMode p_mode, const String &p_code, IdentifierActions *p_actions, const String &p_path, GeneratedCode &r_gen_code) { ShaderLanguage::VaryingFunctionNames var_names; - + Error err = parser.compile(p_code, ShaderTypes::get_singleton()->get_functions(p_mode), ShaderTypes::get_singleton()->get_modes(p_mode), var_names, ShaderTypes::get_singleton()->get_types(), _get_variable_type); // Error ShaderLanguage::compile(const String &p_code, const Map<StringName, FunctionInfo> &p_functions, const Vector<StringName> &p_render_modes, const Set<String> &p_shader_types, GlobalVariableGetTypeFunc p_global_variable_type_func) { @@ -896,217 +885,223 @@ Error ShaderCompilerGLES2::compile(GD_VS::ShaderMode p_mode, const String &p_cod return OK; } -ShaderCompilerGLES2::ShaderCompilerGLES2() { +ShaderCompilerOpenGL::ShaderCompilerOpenGL() { /** CANVAS ITEM SHADER **/ - actions[GD_VS::SHADER_CANVAS_ITEM].renames["VERTEX"] = "outvec.xy"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["UV"] = "uv"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["POINT_SIZE"] = "point_size"; - - actions[GD_VS::SHADER_CANVAS_ITEM].renames["WORLD_MATRIX"] = "modelview_matrix"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["PROJECTION_MATRIX"] = "projection_matrix"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["EXTRA_MATRIX"] = "extra_matrix_instance"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["TIME"] = "time"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["AT_LIGHT_PASS"] = "at_light_pass"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["INSTANCE_CUSTOM"] = "instance_custom"; - - actions[GD_VS::SHADER_CANVAS_ITEM].renames["COLOR"] = "color"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["MODULATE"] = "final_modulate"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["NORMAL"] = "normal"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["NORMALMAP"] = "normal_map"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["NORMALMAP_DEPTH"] = "normal_depth"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["TEXTURE"] = "color_texture"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["TEXTURE_PIXEL_SIZE"] = "color_texpixel_size"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["NORMAL_TEXTURE"] = "normal_texture"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["SCREEN_UV"] = "screen_uv"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["SCREEN_TEXTURE"] = "screen_texture"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["SCREEN_PIXEL_SIZE"] = "screen_pixel_size"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["FRAGCOORD"] = "gl_FragCoord"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["POINT_COORD"] = "gl_PointCoord"; - - actions[GD_VS::SHADER_CANVAS_ITEM].renames["LIGHT_VEC"] = "light_vec"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["LIGHT_HEIGHT"] = "light_height"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["LIGHT_COLOR"] = "light_color"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["LIGHT_UV"] = "light_uv"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["LIGHT"] = "light"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["SHADOW_COLOR"] = "shadow_color"; - actions[GD_VS::SHADER_CANVAS_ITEM].renames["SHADOW_VEC"] = "shadow_vec"; - - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["COLOR"] = "#define COLOR_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["MODULATE"] = "#define MODULATE_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_TEXTURE"] = "#define SCREEN_TEXTURE_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_UV"] = "#define SCREEN_UV_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_PIXEL_SIZE"] = "@SCREEN_UV"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["NORMAL"] = "#define NORMAL_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["NORMALMAP"] = "#define NORMALMAP_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["LIGHT"] = "#define USE_LIGHT_SHADER_CODE\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].render_mode_defines["skip_vertex_transform"] = "#define SKIP_TRANSFORM_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["SHADOW_VEC"] = "#define SHADOW_VEC_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].renames["VERTEX"] = "outvec.xy"; + actions[RS::SHADER_CANVAS_ITEM].renames["UV"] = "uv"; + actions[RS::SHADER_CANVAS_ITEM].renames["POINT_SIZE"] = "point_size"; + + actions[RS::SHADER_CANVAS_ITEM].renames["WORLD_MATRIX"] = "modelview_matrix"; + actions[RS::SHADER_CANVAS_ITEM].renames["PROJECTION_MATRIX"] = "projection_matrix"; + actions[RS::SHADER_CANVAS_ITEM].renames["EXTRA_MATRIX"] = "extra_matrix_instance"; + actions[RS::SHADER_CANVAS_ITEM].renames["TIME"] = "time"; + actions[RS::SHADER_CANVAS_ITEM].renames["PI"] = _MKSTR(Math_PI); + actions[RS::SHADER_CANVAS_ITEM].renames["TAU"] = _MKSTR(Math_TAU); + actions[RS::SHADER_CANVAS_ITEM].renames["E"] = _MKSTR(Math_E); + actions[RS::SHADER_CANVAS_ITEM].renames["AT_LIGHT_PASS"] = "at_light_pass"; + actions[RS::SHADER_CANVAS_ITEM].renames["INSTANCE_CUSTOM"] = "instance_custom"; + + actions[RS::SHADER_CANVAS_ITEM].renames["COLOR"] = "color"; + actions[RS::SHADER_CANVAS_ITEM].renames["MODULATE"] = "final_modulate"; + actions[RS::SHADER_CANVAS_ITEM].renames["NORMAL"] = "normal"; + actions[RS::SHADER_CANVAS_ITEM].renames["NORMALMAP"] = "normal_map"; + actions[RS::SHADER_CANVAS_ITEM].renames["NORMALMAP_DEPTH"] = "normal_depth"; + actions[RS::SHADER_CANVAS_ITEM].renames["TEXTURE"] = "color_texture"; + actions[RS::SHADER_CANVAS_ITEM].renames["TEXTURE_PIXEL_SIZE"] = "color_texpixel_size"; + actions[RS::SHADER_CANVAS_ITEM].renames["NORMAL_TEXTURE"] = "normal_texture"; + actions[RS::SHADER_CANVAS_ITEM].renames["SCREEN_UV"] = "screen_uv"; + actions[RS::SHADER_CANVAS_ITEM].renames["SCREEN_TEXTURE"] = "screen_texture"; + actions[RS::SHADER_CANVAS_ITEM].renames["SCREEN_PIXEL_SIZE"] = "screen_pixel_size"; + actions[RS::SHADER_CANVAS_ITEM].renames["FRAGCOORD"] = "gl_FragCoord"; + actions[RS::SHADER_CANVAS_ITEM].renames["POINT_COORD"] = "gl_PointCoord"; + + actions[RS::SHADER_CANVAS_ITEM].renames["LIGHT_VEC"] = "light_vec"; + actions[RS::SHADER_CANVAS_ITEM].renames["LIGHT_HEIGHT"] = "light_height"; + actions[RS::SHADER_CANVAS_ITEM].renames["LIGHT_COLOR"] = "light_color"; + actions[RS::SHADER_CANVAS_ITEM].renames["LIGHT_UV"] = "light_uv"; + actions[RS::SHADER_CANVAS_ITEM].renames["LIGHT"] = "light"; + actions[RS::SHADER_CANVAS_ITEM].renames["SHADOW_COLOR"] = "shadow_color"; + actions[RS::SHADER_CANVAS_ITEM].renames["SHADOW_VEC"] = "shadow_vec"; + + actions[RS::SHADER_CANVAS_ITEM].usage_defines["COLOR"] = "#define COLOR_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["MODULATE"] = "#define MODULATE_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_TEXTURE"] = "#define SCREEN_TEXTURE_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_UV"] = "#define SCREEN_UV_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_PIXEL_SIZE"] = "@SCREEN_UV"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["NORMAL"] = "#define NORMAL_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["NORMALMAP"] = "#define NORMALMAP_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["LIGHT"] = "#define USE_LIGHT_SHADER_CODE\n"; + actions[RS::SHADER_CANVAS_ITEM].render_mode_defines["skip_vertex_transform"] = "#define SKIP_TRANSFORM_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["SHADOW_VEC"] = "#define SHADOW_VEC_USED\n"; // Ported from GLES3 - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["sinh"] = "#define SINH_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["cosh"] = "#define COSH_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["tanh"] = "#define TANH_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["asinh"] = "#define ASINH_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["acosh"] = "#define ACOSH_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["atanh"] = "#define ATANH_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["determinant"] = "#define DETERMINANT_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["transpose"] = "#define TRANSPOSE_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["outerProduct"] = "#define OUTER_PRODUCT_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["round"] = "#define ROUND_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["roundEven"] = "#define ROUND_EVEN_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["inverse"] = "#define INVERSE_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["isinf"] = "#define IS_INF_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["isnan"] = "#define IS_NAN_USED\n"; - actions[GD_VS::SHADER_CANVAS_ITEM].usage_defines["trunc"] = "#define TRUNC_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["sinh"] = "#define SINH_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["cosh"] = "#define COSH_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["tanh"] = "#define TANH_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["asinh"] = "#define ASINH_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["acosh"] = "#define ACOSH_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["atanh"] = "#define ATANH_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["determinant"] = "#define DETERMINANT_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["transpose"] = "#define TRANSPOSE_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["outerProduct"] = "#define OUTER_PRODUCT_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["round"] = "#define ROUND_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["roundEven"] = "#define ROUND_EVEN_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["inverse"] = "#define INVERSE_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["isinf"] = "#define IS_INF_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["isnan"] = "#define IS_NAN_USED\n"; + actions[RS::SHADER_CANVAS_ITEM].usage_defines["trunc"] = "#define TRUNC_USED\n"; /** SPATIAL SHADER **/ - actions[GD_VS::SHADER_SPATIAL].renames["WORLD_MATRIX"] = "world_transform"; - actions[GD_VS::SHADER_SPATIAL].renames["INV_CAMERA_MATRIX"] = "camera_inverse_matrix"; - actions[GD_VS::SHADER_SPATIAL].renames["CAMERA_MATRIX"] = "camera_matrix"; - actions[GD_VS::SHADER_SPATIAL].renames["PROJECTION_MATRIX"] = "projection_matrix"; - actions[GD_VS::SHADER_SPATIAL].renames["INV_PROJECTION_MATRIX"] = "projection_inverse_matrix"; - actions[GD_VS::SHADER_SPATIAL].renames["MODELVIEW_MATRIX"] = "modelview"; - - actions[GD_VS::SHADER_SPATIAL].renames["VERTEX"] = "vertex.xyz"; - actions[GD_VS::SHADER_SPATIAL].renames["NORMAL"] = "normal"; - actions[GD_VS::SHADER_SPATIAL].renames["TANGENT"] = "tangent"; - actions[GD_VS::SHADER_SPATIAL].renames["BINORMAL"] = "binormal"; - actions[GD_VS::SHADER_SPATIAL].renames["POSITION"] = "position"; - actions[GD_VS::SHADER_SPATIAL].renames["UV"] = "uv_interp"; - actions[GD_VS::SHADER_SPATIAL].renames["UV2"] = "uv2_interp"; - actions[GD_VS::SHADER_SPATIAL].renames["COLOR"] = "color_interp"; - actions[GD_VS::SHADER_SPATIAL].renames["POINT_SIZE"] = "point_size"; + actions[RS::SHADER_SPATIAL].renames["WORLD_MATRIX"] = "world_transform"; + actions[RS::SHADER_SPATIAL].renames["INV_CAMERA_MATRIX"] = "camera_inverse_matrix"; + actions[RS::SHADER_SPATIAL].renames["CAMERA_MATRIX"] = "camera_matrix"; + actions[RS::SHADER_SPATIAL].renames["PROJECTION_MATRIX"] = "projection_matrix"; + actions[RS::SHADER_SPATIAL].renames["INV_PROJECTION_MATRIX"] = "projection_inverse_matrix"; + actions[RS::SHADER_SPATIAL].renames["MODELVIEW_MATRIX"] = "modelview"; + + actions[RS::SHADER_SPATIAL].renames["VERTEX"] = "vertex.xyz"; + actions[RS::SHADER_SPATIAL].renames["NORMAL"] = "normal"; + actions[RS::SHADER_SPATIAL].renames["TANGENT"] = "tangent"; + actions[RS::SHADER_SPATIAL].renames["BINORMAL"] = "binormal"; + actions[RS::SHADER_SPATIAL].renames["POSITION"] = "position"; + actions[RS::SHADER_SPATIAL].renames["UV"] = "uv_interp"; + actions[RS::SHADER_SPATIAL].renames["UV2"] = "uv2_interp"; + actions[RS::SHADER_SPATIAL].renames["COLOR"] = "color_interp"; + actions[RS::SHADER_SPATIAL].renames["POINT_SIZE"] = "point_size"; // gl_InstanceID is not available in OpenGL ES 2.0 - actions[GD_VS::SHADER_SPATIAL].renames["INSTANCE_ID"] = "0"; + actions[RS::SHADER_SPATIAL].renames["INSTANCE_ID"] = "0"; //builtins - actions[GD_VS::SHADER_SPATIAL].renames["TIME"] = "time"; - actions[GD_VS::SHADER_SPATIAL].renames["VIEWPORT_SIZE"] = "viewport_size"; - - actions[GD_VS::SHADER_SPATIAL].renames["FRAGCOORD"] = "gl_FragCoord"; - actions[GD_VS::SHADER_SPATIAL].renames["FRONT_FACING"] = "gl_FrontFacing"; - actions[GD_VS::SHADER_SPATIAL].renames["NORMALMAP"] = "normalmap"; - actions[GD_VS::SHADER_SPATIAL].renames["NORMALMAP_DEPTH"] = "normaldepth"; - actions[GD_VS::SHADER_SPATIAL].renames["ALBEDO"] = "albedo"; - actions[GD_VS::SHADER_SPATIAL].renames["ALPHA"] = "alpha"; - actions[GD_VS::SHADER_SPATIAL].renames["METALLIC"] = "metallic"; - actions[GD_VS::SHADER_SPATIAL].renames["SPECULAR"] = "specular"; - actions[GD_VS::SHADER_SPATIAL].renames["ROUGHNESS"] = "roughness"; - actions[GD_VS::SHADER_SPATIAL].renames["RIM"] = "rim"; - actions[GD_VS::SHADER_SPATIAL].renames["RIM_TINT"] = "rim_tint"; - actions[GD_VS::SHADER_SPATIAL].renames["CLEARCOAT"] = "clearcoat"; - actions[GD_VS::SHADER_SPATIAL].renames["CLEARCOAT_GLOSS"] = "clearcoat_gloss"; - actions[GD_VS::SHADER_SPATIAL].renames["ANISOTROPY"] = "anisotropy"; - actions[GD_VS::SHADER_SPATIAL].renames["ANISOTROPY_FLOW"] = "anisotropy_flow"; - actions[GD_VS::SHADER_SPATIAL].renames["SSS_STRENGTH"] = "sss_strength"; - actions[GD_VS::SHADER_SPATIAL].renames["TRANSMISSION"] = "transmission"; - actions[GD_VS::SHADER_SPATIAL].renames["AO"] = "ao"; - actions[GD_VS::SHADER_SPATIAL].renames["AO_LIGHT_AFFECT"] = "ao_light_affect"; - actions[GD_VS::SHADER_SPATIAL].renames["EMISSION"] = "emission"; - actions[GD_VS::SHADER_SPATIAL].renames["POINT_COORD"] = "gl_PointCoord"; - actions[GD_VS::SHADER_SPATIAL].renames["INSTANCE_CUSTOM"] = "instance_custom"; - actions[GD_VS::SHADER_SPATIAL].renames["SCREEN_UV"] = "screen_uv"; - actions[GD_VS::SHADER_SPATIAL].renames["SCREEN_TEXTURE"] = "screen_texture"; - actions[GD_VS::SHADER_SPATIAL].renames["DEPTH_TEXTURE"] = "depth_texture"; + actions[RS::SHADER_SPATIAL].renames["TIME"] = "time"; + actions[RS::SHADER_SPATIAL].renames["PI"] = _MKSTR(Math_PI); + actions[RS::SHADER_SPATIAL].renames["TAU"] = _MKSTR(Math_TAU); + actions[RS::SHADER_SPATIAL].renames["E"] = _MKSTR(Math_E); + actions[RS::SHADER_SPATIAL].renames["VIEWPORT_SIZE"] = "viewport_size"; + + actions[RS::SHADER_SPATIAL].renames["FRAGCOORD"] = "gl_FragCoord"; + actions[RS::SHADER_SPATIAL].renames["FRONT_FACING"] = "gl_FrontFacing"; + actions[RS::SHADER_SPATIAL].renames["NORMALMAP"] = "normalmap"; + actions[RS::SHADER_SPATIAL].renames["NORMALMAP_DEPTH"] = "normaldepth"; + actions[RS::SHADER_SPATIAL].renames["ALBEDO"] = "albedo"; + actions[RS::SHADER_SPATIAL].renames["ALPHA"] = "alpha"; + actions[RS::SHADER_SPATIAL].renames["METALLIC"] = "metallic"; + actions[RS::SHADER_SPATIAL].renames["SPECULAR"] = "specular"; + actions[RS::SHADER_SPATIAL].renames["ROUGHNESS"] = "roughness"; + actions[RS::SHADER_SPATIAL].renames["RIM"] = "rim"; + actions[RS::SHADER_SPATIAL].renames["RIM_TINT"] = "rim_tint"; + actions[RS::SHADER_SPATIAL].renames["CLEARCOAT"] = "clearcoat"; + actions[RS::SHADER_SPATIAL].renames["CLEARCOAT_GLOSS"] = "clearcoat_gloss"; + actions[RS::SHADER_SPATIAL].renames["ANISOTROPY"] = "anisotropy"; + actions[RS::SHADER_SPATIAL].renames["ANISOTROPY_FLOW"] = "anisotropy_flow"; + actions[RS::SHADER_SPATIAL].renames["SSS_STRENGTH"] = "sss_strength"; + actions[RS::SHADER_SPATIAL].renames["TRANSMISSION"] = "transmission"; + actions[RS::SHADER_SPATIAL].renames["AO"] = "ao"; + actions[RS::SHADER_SPATIAL].renames["AO_LIGHT_AFFECT"] = "ao_light_affect"; + actions[RS::SHADER_SPATIAL].renames["EMISSION"] = "emission"; + actions[RS::SHADER_SPATIAL].renames["POINT_COORD"] = "gl_PointCoord"; + actions[RS::SHADER_SPATIAL].renames["INSTANCE_CUSTOM"] = "instance_custom"; + actions[RS::SHADER_SPATIAL].renames["SCREEN_UV"] = "screen_uv"; + actions[RS::SHADER_SPATIAL].renames["SCREEN_TEXTURE"] = "screen_texture"; + actions[RS::SHADER_SPATIAL].renames["DEPTH_TEXTURE"] = "depth_texture"; // Defined in GLES3, but not available in GLES2 - //actions[GD_VS::SHADER_SPATIAL].renames["DEPTH"] = "gl_FragDepth"; - actions[GD_VS::SHADER_SPATIAL].renames["ALPHA_SCISSOR"] = "alpha_scissor"; - actions[GD_VS::SHADER_SPATIAL].renames["OUTPUT_IS_SRGB"] = "SHADER_IS_SRGB"; + //actions[RS::SHADER_SPATIAL].renames["DEPTH"] = "gl_FragDepth"; + actions[RS::SHADER_SPATIAL].renames["ALPHA_SCISSOR"] = "alpha_scissor"; + actions[RS::SHADER_SPATIAL].renames["OUTPUT_IS_SRGB"] = "SHADER_IS_SRGB"; //for light - actions[GD_VS::SHADER_SPATIAL].renames["VIEW"] = "view"; - actions[GD_VS::SHADER_SPATIAL].renames["LIGHT_COLOR"] = "light_color"; - actions[GD_VS::SHADER_SPATIAL].renames["LIGHT"] = "light"; - actions[GD_VS::SHADER_SPATIAL].renames["ATTENUATION"] = "attenuation"; - actions[GD_VS::SHADER_SPATIAL].renames["DIFFUSE_LIGHT"] = "diffuse_light"; - actions[GD_VS::SHADER_SPATIAL].renames["SPECULAR_LIGHT"] = "specular_light"; - - actions[GD_VS::SHADER_SPATIAL].usage_defines["TANGENT"] = "#define ENABLE_TANGENT_INTERP\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["BINORMAL"] = "@TANGENT"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["RIM"] = "#define LIGHT_USE_RIM\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["RIM_TINT"] = "@RIM"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["CLEARCOAT"] = "#define LIGHT_USE_CLEARCOAT\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["CLEARCOAT_GLOSS"] = "@CLEARCOAT"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["ANISOTROPY"] = "#define LIGHT_USE_ANISOTROPY\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["ANISOTROPY_FLOW"] = "@ANISOTROPY"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["AO"] = "#define ENABLE_AO\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["AO_LIGHT_AFFECT"] = "#define ENABLE_AO\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["UV"] = "#define ENABLE_UV_INTERP\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["UV2"] = "#define ENABLE_UV2_INTERP\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["NORMALMAP"] = "#define ENABLE_NORMALMAP\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["NORMALMAP_DEPTH"] = "@NORMALMAP"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["COLOR"] = "#define ENABLE_COLOR_INTERP\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["INSTANCE_CUSTOM"] = "#define ENABLE_INSTANCE_CUSTOM\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["ALPHA_SCISSOR"] = "#define ALPHA_SCISSOR_USED\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["POSITION"] = "#define OVERRIDE_POSITION\n"; - - actions[GD_VS::SHADER_SPATIAL].usage_defines["SSS_STRENGTH"] = "#define ENABLE_SSS\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["TRANSMISSION"] = "#define TRANSMISSION_USED\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["SCREEN_TEXTURE"] = "#define SCREEN_TEXTURE_USED\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["DEPTH_TEXTURE"] = "#define DEPTH_TEXTURE_USED\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["SCREEN_UV"] = "#define SCREEN_UV_USED\n"; - - actions[GD_VS::SHADER_SPATIAL].usage_defines["DIFFUSE_LIGHT"] = "#define USE_LIGHT_SHADER_CODE\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["SPECULAR_LIGHT"] = "#define USE_LIGHT_SHADER_CODE\n"; + actions[RS::SHADER_SPATIAL].renames["VIEW"] = "view"; + actions[RS::SHADER_SPATIAL].renames["LIGHT_COLOR"] = "light_color"; + actions[RS::SHADER_SPATIAL].renames["LIGHT"] = "light"; + actions[RS::SHADER_SPATIAL].renames["ATTENUATION"] = "attenuation"; + actions[RS::SHADER_SPATIAL].renames["DIFFUSE_LIGHT"] = "diffuse_light"; + actions[RS::SHADER_SPATIAL].renames["SPECULAR_LIGHT"] = "specular_light"; + + actions[RS::SHADER_SPATIAL].usage_defines["TANGENT"] = "#define ENABLE_TANGENT_INTERP\n"; + actions[RS::SHADER_SPATIAL].usage_defines["BINORMAL"] = "@TANGENT"; + actions[RS::SHADER_SPATIAL].usage_defines["RIM"] = "#define LIGHT_USE_RIM\n"; + actions[RS::SHADER_SPATIAL].usage_defines["RIM_TINT"] = "@RIM"; + actions[RS::SHADER_SPATIAL].usage_defines["CLEARCOAT"] = "#define LIGHT_USE_CLEARCOAT\n"; + actions[RS::SHADER_SPATIAL].usage_defines["CLEARCOAT_GLOSS"] = "@CLEARCOAT"; + actions[RS::SHADER_SPATIAL].usage_defines["ANISOTROPY"] = "#define LIGHT_USE_ANISOTROPY\n"; + actions[RS::SHADER_SPATIAL].usage_defines["ANISOTROPY_FLOW"] = "@ANISOTROPY"; + actions[RS::SHADER_SPATIAL].usage_defines["AO"] = "#define ENABLE_AO\n"; + actions[RS::SHADER_SPATIAL].usage_defines["AO_LIGHT_AFFECT"] = "#define ENABLE_AO\n"; + actions[RS::SHADER_SPATIAL].usage_defines["UV"] = "#define ENABLE_UV_INTERP\n"; + actions[RS::SHADER_SPATIAL].usage_defines["UV2"] = "#define ENABLE_UV2_INTERP\n"; + actions[RS::SHADER_SPATIAL].usage_defines["NORMALMAP"] = "#define ENABLE_NORMALMAP\n"; + actions[RS::SHADER_SPATIAL].usage_defines["NORMALMAP_DEPTH"] = "@NORMALMAP"; + actions[RS::SHADER_SPATIAL].usage_defines["COLOR"] = "#define ENABLE_COLOR_INTERP\n"; + actions[RS::SHADER_SPATIAL].usage_defines["INSTANCE_CUSTOM"] = "#define ENABLE_INSTANCE_CUSTOM\n"; + actions[RS::SHADER_SPATIAL].usage_defines["ALPHA_SCISSOR"] = "#define ALPHA_SCISSOR_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["POSITION"] = "#define OVERRIDE_POSITION\n"; + + actions[RS::SHADER_SPATIAL].usage_defines["SSS_STRENGTH"] = "#define ENABLE_SSS\n"; + actions[RS::SHADER_SPATIAL].usage_defines["TRANSMISSION"] = "#define TRANSMISSION_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["SCREEN_TEXTURE"] = "#define SCREEN_TEXTURE_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["DEPTH_TEXTURE"] = "#define DEPTH_TEXTURE_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["SCREEN_UV"] = "#define SCREEN_UV_USED\n"; + + actions[RS::SHADER_SPATIAL].usage_defines["DIFFUSE_LIGHT"] = "#define USE_LIGHT_SHADER_CODE\n"; + actions[RS::SHADER_SPATIAL].usage_defines["SPECULAR_LIGHT"] = "#define USE_LIGHT_SHADER_CODE\n"; // Ported from GLES3 - actions[GD_VS::SHADER_SPATIAL].usage_defines["sinh"] = "#define SINH_USED\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["cosh"] = "#define COSH_USED\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["tanh"] = "#define TANH_USED\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["asinh"] = "#define ASINH_USED\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["acosh"] = "#define ACOSH_USED\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["atanh"] = "#define ATANH_USED\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["determinant"] = "#define DETERMINANT_USED\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["transpose"] = "#define TRANSPOSE_USED\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["outerProduct"] = "#define OUTER_PRODUCT_USED\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["round"] = "#define ROUND_USED\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["roundEven"] = "#define ROUND_EVEN_USED\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["inverse"] = "#define INVERSE_USED\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["isinf"] = "#define IS_INF_USED\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["isnan"] = "#define IS_NAN_USED\n"; - actions[GD_VS::SHADER_SPATIAL].usage_defines["trunc"] = "#define TRUNC_USED\n"; - - actions[GD_VS::SHADER_SPATIAL].render_mode_defines["skip_vertex_transform"] = "#define SKIP_TRANSFORM_USED\n"; - actions[GD_VS::SHADER_SPATIAL].render_mode_defines["world_vertex_coords"] = "#define VERTEX_WORLD_COORDS_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["sinh"] = "#define SINH_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["cosh"] = "#define COSH_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["tanh"] = "#define TANH_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["asinh"] = "#define ASINH_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["acosh"] = "#define ACOSH_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["atanh"] = "#define ATANH_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["determinant"] = "#define DETERMINANT_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["transpose"] = "#define TRANSPOSE_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["outerProduct"] = "#define OUTER_PRODUCT_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["round"] = "#define ROUND_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["roundEven"] = "#define ROUND_EVEN_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["inverse"] = "#define INVERSE_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["isinf"] = "#define IS_INF_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["isnan"] = "#define IS_NAN_USED\n"; + actions[RS::SHADER_SPATIAL].usage_defines["trunc"] = "#define TRUNC_USED\n"; + + actions[RS::SHADER_SPATIAL].render_mode_defines["skip_vertex_transform"] = "#define SKIP_TRANSFORM_USED\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["world_vertex_coords"] = "#define VERTEX_WORLD_COORDS_USED\n"; // Defined in GLES3, could be implemented in GLES2 too if there's a need for it - //actions[GD_VS::SHADER_SPATIAL].render_mode_defines["ensure_correct_normals"] = "#define ENSURE_CORRECT_NORMALS\n"; + //actions[RS::SHADER_SPATIAL].render_mode_defines["ensure_correct_normals"] = "#define ENSURE_CORRECT_NORMALS\n"; // Defined in GLES3, might not be possible in GLES2 as gl_FrontFacing is not available - //actions[GD_VS::SHADER_SPATIAL].render_mode_defines["cull_front"] = "#define DO_SIDE_CHECK\n"; - //actions[GD_VS::SHADER_SPATIAL].render_mode_defines["cull_disabled"] = "#define DO_SIDE_CHECK\n"; + //actions[RS::SHADER_SPATIAL].render_mode_defines["cull_front"] = "#define DO_SIDE_CHECK\n"; + //actions[RS::SHADER_SPATIAL].render_mode_defines["cull_disabled"] = "#define DO_SIDE_CHECK\n"; bool force_lambert = GLOBAL_GET("rendering/quality/shading/force_lambert_over_burley"); if (!force_lambert) { - actions[GD_VS::SHADER_SPATIAL].render_mode_defines["diffuse_burley"] = "#define DIFFUSE_BURLEY\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["diffuse_burley"] = "#define DIFFUSE_BURLEY\n"; } - actions[GD_VS::SHADER_SPATIAL].render_mode_defines["diffuse_oren_nayar"] = "#define DIFFUSE_OREN_NAYAR\n"; - actions[GD_VS::SHADER_SPATIAL].render_mode_defines["diffuse_lambert_wrap"] = "#define DIFFUSE_LAMBERT_WRAP\n"; - actions[GD_VS::SHADER_SPATIAL].render_mode_defines["diffuse_toon"] = "#define DIFFUSE_TOON\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["diffuse_oren_nayar"] = "#define DIFFUSE_OREN_NAYAR\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["diffuse_lambert_wrap"] = "#define DIFFUSE_LAMBERT_WRAP\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["diffuse_toon"] = "#define DIFFUSE_TOON\n"; bool force_blinn = GLOBAL_GET("rendering/quality/shading/force_blinn_over_ggx"); if (!force_blinn) { - actions[GD_VS::SHADER_SPATIAL].render_mode_defines["specular_schlick_ggx"] = "#define SPECULAR_SCHLICK_GGX\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["specular_schlick_ggx"] = "#define SPECULAR_SCHLICK_GGX\n"; } else { - actions[GD_VS::SHADER_SPATIAL].render_mode_defines["specular_schlick_ggx"] = "#define SPECULAR_BLINN\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["specular_schlick_ggx"] = "#define SPECULAR_BLINN\n"; } - actions[GD_VS::SHADER_SPATIAL].render_mode_defines["specular_blinn"] = "#define SPECULAR_BLINN\n"; - actions[GD_VS::SHADER_SPATIAL].render_mode_defines["specular_phong"] = "#define SPECULAR_PHONG\n"; - actions[GD_VS::SHADER_SPATIAL].render_mode_defines["specular_toon"] = "#define SPECULAR_TOON\n"; - actions[GD_VS::SHADER_SPATIAL].render_mode_defines["specular_disabled"] = "#define SPECULAR_DISABLED\n"; - actions[GD_VS::SHADER_SPATIAL].render_mode_defines["shadows_disabled"] = "#define SHADOWS_DISABLED\n"; - actions[GD_VS::SHADER_SPATIAL].render_mode_defines["ambient_light_disabled"] = "#define AMBIENT_LIGHT_DISABLED\n"; - actions[GD_VS::SHADER_SPATIAL].render_mode_defines["shadow_to_opacity"] = "#define USE_SHADOW_TO_OPACITY\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["specular_blinn"] = "#define SPECULAR_BLINN\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["specular_phong"] = "#define SPECULAR_PHONG\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["specular_toon"] = "#define SPECULAR_TOON\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["specular_disabled"] = "#define SPECULAR_DISABLED\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["shadows_disabled"] = "#define SHADOWS_DISABLED\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["ambient_light_disabled"] = "#define AMBIENT_LIGHT_DISABLED\n"; + actions[RS::SHADER_SPATIAL].render_mode_defines["shadow_to_opacity"] = "#define USE_SHADOW_TO_OPACITY\n"; - // No defines for particle shaders in GLES2, there are no GPU particles + // No defines for particle shaders in OpenGL, there are no GPU particles vertex_name = "vertex"; fragment_name = "fragment"; @@ -1122,4 +1117,4 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() { } } -#endif // GLES2_BACKEND_ENABLED +#endif // OPENGL_BACKEND_ENABLED diff --git a/drivers/gles2/shader_compiler_gles2.h b/drivers/opengl/shader_compiler_opengl.h index 580719c47a..b57d28ffe5 100644 --- a/drivers/gles2/shader_compiler_gles2.h +++ b/drivers/opengl/shader_compiler_opengl.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* shader_compiler_gles2.h */ +/* shader_compiler_opengl.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,27 +28,19 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#pragma once +#ifndef SHADER_COMPILER_OPENGL_H +#define SHADER_COMPILER_OPENGL_H -#include "drivers/gles_common/rasterizer_platforms.h" -#ifdef GLES2_BACKEND_ENABLED +#include "drivers/opengl/rasterizer_platforms.h" +#ifdef OPENGL_BACKEND_ENABLED -#include "drivers/gles_common/rasterizer_version.h" -#ifdef GODOT_3 -#include "core/pair.h" -#include "core/string_builder.h" -#include "servers/visual/shader_language.h" -#include "servers/visual/shader_types.h" -#include "servers/visual_server.h" -#else #include "core/string/string_builder.h" #include "core/templates/pair.h" #include "servers/rendering/shader_language.h" #include "servers/rendering/shader_types.h" #include "servers/rendering_server.h" -#endif -class ShaderCompilerGLES2 { +class ShaderCompilerOpenGL { public: struct IdentifierActions { Map<StringName, Pair<int *, int>> render_mode_values; @@ -98,15 +90,17 @@ private: Set<StringName> used_rmode_defines; Set<StringName> internal_functions; - DefaultIdentifierActions actions[GD_VS::SHADER_MAX]; + DefaultIdentifierActions actions[RS::SHADER_MAX]; // compatibility with godot 4 static ShaderLanguage::DataType _get_variable_type(const StringName &p_type); public: - Error compile(GD_VS::ShaderMode p_mode, const String &p_code, IdentifierActions *p_actions, const String &p_path, GeneratedCode &r_gen_code); + Error compile(RS::ShaderMode p_mode, const String &p_code, IdentifierActions *p_actions, const String &p_path, GeneratedCode &r_gen_code); - ShaderCompilerGLES2(); + ShaderCompilerOpenGL(); }; -#endif // GLES2_BACKEND_ENABLED +#endif // OPENGL_BACKEND_ENABLED + +#endif // SHADER_COMPILER_OPENGL_H diff --git a/drivers/gles2/shader_gles2.cpp b/drivers/opengl/shader_opengl.cpp index ca493a219b..a80a745047 100644 --- a/drivers/gles2/shader_gles2.cpp +++ b/drivers/opengl/shader_opengl.cpp @@ -1,12 +1,12 @@ /*************************************************************************/ -/* shader_gles2.cpp */ +/* shader_opengl.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 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 */ @@ -28,23 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "shader_gles2.h" -#include "drivers/gles_common/rasterizer_platforms.h" -#ifdef GLES2_BACKEND_ENABLED +#include "shader_opengl.h" +#include "drivers/opengl/rasterizer_platforms.h" +#ifdef OPENGL_BACKEND_ENABLED -#include "core/os/memory.h" -#include "rasterizer_gles2.h" -#include "rasterizer_storage_gles2.h" +#include "rasterizer_opengl.h" +#include "rasterizer_storage_opengl.h" -#ifdef GODOT_3 -#include "core/print_string.h" -#include "core/project_settings.h" -#include "core/string_builder.h" -#else #include "core/config/project_settings.h" +#include "core/os/memory.h" #include "core/string/print_string.h" #include "core/string/string_builder.h" -#endif // #define DEBUG_OPENGL @@ -65,7 +59,7 @@ #endif -ShaderGLES2 *ShaderGLES2::active = NULL; +ShaderOpenGL *ShaderOpenGL::active = NULL; //#define DEBUG_SHADER @@ -79,15 +73,13 @@ ShaderGLES2 *ShaderGLES2::active = NULL; #endif -GLint ShaderGLES2::get_uniform_location(int p_index) const { +GLint ShaderOpenGL::get_uniform_location(int p_index) const { ERR_FAIL_COND_V(!version, -1); return version->uniform_location[p_index]; } -//#ifdef GODOT_3 - -bool ShaderGLES2::bind() { +bool ShaderOpenGL::bind() { if (active != this || !version || new_conditional_version.key != conditional_version.key) { conditional_version = new_conditional_version; version = get_current_version(); @@ -112,7 +104,7 @@ bool ShaderGLES2::bind() { return true; } -void ShaderGLES2::unbind() { +void ShaderOpenGL::unbind() { version = NULL; glUseProgram(0); uniforms_dirty = true; @@ -142,7 +134,7 @@ static String _mkid(const String &p_id) { return id.replace("__", "_dus_"); //doubleunderscore is reserved in glsl } -ShaderGLES2::Version *ShaderGLES2::get_current_version() { +ShaderOpenGL::Version *ShaderOpenGL::get_current_version() { if (!valid) return nullptr; @@ -201,8 +193,8 @@ ShaderGLES2::Version *ShaderGLES2::get_current_version() { strings.push_back("#define USE_HIGHP_PRECISION\n"); #endif - if (GLOBAL_GET("rendering/gles2/compatibility/enable_high_float.Android")) { - // enable USE_HIGHP_PRECISION but safeguarded by an availability check as highp support is optional in GLES2 + if (GLOBAL_GET("rendering/opengl/compatibility/enable_high_float.Android")) { + // enable USE_HIGHP_PRECISION but safeguarded by an availability check as highp support is optional in OpenGL // see Section 4.5.4 of the GLSL_ES_Specification_1.00 strings.push_back("#ifdef GL_FRAGMENT_PRECISION_HIGH\n #define USE_HIGHP_PRECISION\n#endif\n"); } @@ -492,12 +484,12 @@ ShaderGLES2::Version *ShaderGLES2::get_current_version() { return &v; } -GLint ShaderGLES2::get_uniform_location(const String &p_name) const { +GLint ShaderOpenGL::get_uniform_location(const String &p_name) const { ERR_FAIL_COND_V(!version, -1); return glGetUniformLocation(version->id, p_name.ascii().get_data()); } -void ShaderGLES2::setup( +void ShaderOpenGL::setup( const char **p_conditional_defines, int p_conditional_count, const char **p_uniform_names, @@ -587,7 +579,7 @@ void ShaderGLES2::setup( valid = true; } -void ShaderGLES2::finish() { +void ShaderOpenGL::finish() { const VersionKey *V = NULL; while ((V = version_map.next(V))) { @@ -601,7 +593,7 @@ void ShaderGLES2::finish() { } } -void ShaderGLES2::clear_caches() { +void ShaderOpenGL::clear_caches() { const VersionKey *V = NULL; while ((V = version_map.next(V))) { @@ -620,13 +612,13 @@ void ShaderGLES2::clear_caches() { uniforms_dirty = true; } -uint32_t ShaderGLES2::create_custom_shader() { +uint32_t ShaderOpenGL::create_custom_shader() { custom_code_map[last_custom_code] = CustomCode(); custom_code_map[last_custom_code].version = 1; return last_custom_code++; } -void ShaderGLES2::set_custom_shader_code(uint32_t p_code_id, +void ShaderOpenGL::set_custom_shader_code(uint32_t p_code_id, const String &p_vertex, const String &p_vertex_globals, const String &p_fragment, @@ -649,11 +641,11 @@ void ShaderGLES2::set_custom_shader_code(uint32_t p_code_id, cc->version++; } -void ShaderGLES2::set_custom_shader(uint32_t p_code_id) { +void ShaderOpenGL::set_custom_shader(uint32_t p_code_id) { new_conditional_version.code_version = p_code_id; } -void ShaderGLES2::free_custom_shader(uint32_t p_code_id) { +void ShaderOpenGL::free_custom_shader(uint32_t p_code_id) { ERR_FAIL_COND(!custom_code_map.has(p_code_id)); if (conditional_version.code_version == p_code_id) { conditional_version.code_version = 0; //do not keep using a version that is going away @@ -679,8 +671,8 @@ void ShaderGLES2::free_custom_shader(uint32_t p_code_id) { custom_code_map.erase(p_code_id); } -void ShaderGLES2::use_material(void *p_material) { - RasterizerStorageGLES2::Material *material = (RasterizerStorageGLES2::Material *)p_material; +void ShaderOpenGL::use_material(void *p_material) { + RasterizerStorageOpenGL::Material *material = (RasterizerStorageOpenGL::Material *)p_material; if (!material) { return; @@ -989,7 +981,7 @@ void ShaderGLES2::use_material(void *p_material) { case ShaderLanguage::TYPE_SAMPLER3D: case ShaderLanguage::TYPE_ISAMPLER3D: case ShaderLanguage::TYPE_USAMPLER3D: { - // Not implemented in GLES2 + // Not implemented in OpenGL } break; case ShaderLanguage::TYPE_VOID: { @@ -1109,7 +1101,7 @@ void ShaderGLES2::use_material(void *p_material) { case ShaderLanguage::TYPE_SAMPLER3D: case ShaderLanguage::TYPE_ISAMPLER3D: case ShaderLanguage::TYPE_USAMPLER3D: { - // Not implemented in GLES2 + // Not implemented in OpenGL } break; case ShaderLanguage::TYPE_VOID: { @@ -1123,14 +1115,14 @@ void ShaderGLES2::use_material(void *p_material) { } } -ShaderGLES2::ShaderGLES2() { +ShaderOpenGL::ShaderOpenGL() { version = NULL; last_custom_code = 1; uniforms_dirty = true; } -ShaderGLES2::~ShaderGLES2() { +ShaderOpenGL::~ShaderOpenGL() { finish(); } -#endif // GLES2_BACKEND_ENABLED +#endif // OPENGL_BACKEND_ENABLED diff --git a/drivers/gles2/shader_gles2.h b/drivers/opengl/shader_opengl.h index 4f327c2707..4896bd6f2b 100644 --- a/drivers/gles2/shader_gles2.h +++ b/drivers/opengl/shader_opengl.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* shader_gles2.h */ +/* shader_opengl.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,40 +28,32 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#pragma once +#ifndef SHADER_OPENGL_H +#define SHADER_OPENGL_H -#include "drivers/gles_common/rasterizer_platforms.h" -#ifdef GLES2_BACKEND_ENABLED +#include "drivers/opengl/rasterizer_platforms.h" +#ifdef OPENGL_BACKEND_ENABLED // This must come first to avoid windows.h mess #include "platform_config.h" -#ifndef GLES2_INCLUDE_H -#include <GLES2/gl2.h> +#ifndef OPENGL_INCLUDE_H +#include <GLES3/gl3.h> #else -#include GLES2_INCLUDE_H +#include OPENGL_INCLUDE_H #endif #include "core/math/camera_matrix.h" -#ifdef GODOT_3 -#include "core/hash_map.h" -#include "core/map.h" -#include "core/pair.h" -#include "core/variant.h" -#include "servers/visual/shader_language.h" -#else #include "core/templates/hash_map.h" #include "core/templates/map.h" #include "core/templates/pair.h" #include "core/variant/variant.h" #include "servers/rendering/shader_language.h" -#endif #include <stdio.h> -class RasterizerStorageGLES2; -//#ifdef GODOT_3 +class RasterizerStorageOpenGL; -class ShaderGLES2 { +class ShaderOpenGL { protected: struct Enum { uint64_t mask; @@ -180,7 +172,7 @@ private: Version *get_current_version(); - static ShaderGLES2 *active; + static ShaderOpenGL *active; int max_image_units; @@ -203,7 +195,7 @@ protected: int p_vertex_code_start, int p_fragment_code_start); - ShaderGLES2(); + ShaderOpenGL(); public: enum { @@ -213,7 +205,7 @@ public: GLint get_uniform_location(const String &p_name) const; GLint get_uniform_location(int p_index) const; - static _FORCE_INLINE_ ShaderGLES2 *get_active() { return active; } + static _FORCE_INLINE_ ShaderOpenGL *get_active() { return active; } bool bind(); void unbind(); @@ -237,7 +229,7 @@ public: uint32_t get_version_key() const { return conditional_version.version; } - // this void* is actually a RasterizerStorageGLES2::Material, but C++ doesn't + // this void* is actually a RasterizerStorageOpenGL::Material, but C++ doesn't // like forward declared nested classes. void use_material(void *p_material); @@ -261,18 +253,18 @@ public: custom_defines.erase(p_define.utf8()); } - virtual ~ShaderGLES2(); + virtual ~ShaderOpenGL(); }; // called a lot, made inline -int ShaderGLES2::_get_uniform(int p_which) const { +int ShaderOpenGL::_get_uniform(int p_which) const { ERR_FAIL_INDEX_V(p_which, uniform_count, -1); ERR_FAIL_COND_V(!version, -1); return version->uniform_location[p_which]; } -void ShaderGLES2::_set_conditional(int p_which, bool p_value) { +void ShaderOpenGL::_set_conditional(int p_which, bool p_value) { ERR_FAIL_INDEX(p_which, conditional_count); if (p_value) new_conditional_version.version |= (1 << p_which); @@ -280,4 +272,6 @@ void ShaderGLES2::_set_conditional(int p_which, bool p_value) { new_conditional_version.version &= ~(1 << p_which); } -#endif // GLES2_BACKEND_ENABLED +#endif // OPENGL_BACKEND_ENABLED + +#endif // SHADER_OPENGL_H diff --git a/drivers/opengl/shaders/SCsub b/drivers/opengl/shaders/SCsub new file mode 100644 index 0000000000..dcd8bf6030 --- /dev/null +++ b/drivers/opengl/shaders/SCsub @@ -0,0 +1,14 @@ +#!/usr/bin/env python + +Import("env") + +if "OpenGL_GLSL" in env["BUILDERS"]: + env.OpenGL_GLSL("copy.glsl") + env.OpenGL_GLSL("canvas.glsl") + env.OpenGL_GLSL("canvas_shadow.glsl") + env.OpenGL_GLSL("scene.glsl") + env.OpenGL_GLSL("cubemap_filter.glsl") + env.OpenGL_GLSL("cube_to_dp.glsl") + env.OpenGL_GLSL("effect_blur.glsl") + env.OpenGL_GLSL("tonemap.glsl") + env.OpenGL_GLSL("lens_distorted.glsl") diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/opengl/shaders/canvas.glsl index 3dee2faa88..3dee2faa88 100644 --- a/drivers/gles2/shaders/canvas.glsl +++ b/drivers/opengl/shaders/canvas.glsl diff --git a/drivers/gles2/shaders/canvas_shadow.glsl b/drivers/opengl/shaders/canvas_shadow.glsl index 2abcd5e67c..2abcd5e67c 100644 --- a/drivers/gles2/shaders/canvas_shadow.glsl +++ b/drivers/opengl/shaders/canvas_shadow.glsl diff --git a/drivers/gles2/shaders/copy.glsl b/drivers/opengl/shaders/copy.glsl index e833722ac3..e833722ac3 100644 --- a/drivers/gles2/shaders/copy.glsl +++ b/drivers/opengl/shaders/copy.glsl diff --git a/drivers/gles2/shaders/cube_to_dp.glsl b/drivers/opengl/shaders/cube_to_dp.glsl index 1612ec3d5a..1612ec3d5a 100644 --- a/drivers/gles2/shaders/cube_to_dp.glsl +++ b/drivers/opengl/shaders/cube_to_dp.glsl diff --git a/drivers/gles2/shaders/cubemap_filter.glsl b/drivers/opengl/shaders/cubemap_filter.glsl index f5c91cc707..f5c91cc707 100644 --- a/drivers/gles2/shaders/cubemap_filter.glsl +++ b/drivers/opengl/shaders/cubemap_filter.glsl diff --git a/drivers/gles2/shaders/effect_blur.glsl b/drivers/opengl/shaders/effect_blur.glsl index 7b607dd76a..7b607dd76a 100644 --- a/drivers/gles2/shaders/effect_blur.glsl +++ b/drivers/opengl/shaders/effect_blur.glsl diff --git a/drivers/gles2/shaders/lens_distorted.glsl b/drivers/opengl/shaders/lens_distorted.glsl index d568006ccc..d568006ccc 100644 --- a/drivers/gles2/shaders/lens_distorted.glsl +++ b/drivers/opengl/shaders/lens_distorted.glsl diff --git a/drivers/gles2/shaders/scene.glsl b/drivers/opengl/shaders/scene.glsl index ba3a81a532..ba3a81a532 100644 --- a/drivers/gles2/shaders/scene.glsl +++ b/drivers/opengl/shaders/scene.glsl diff --git a/drivers/gles2/shaders/stdlib.glsl b/drivers/opengl/shaders/stdlib.glsl index 9c74418743..9c74418743 100644 --- a/drivers/gles2/shaders/stdlib.glsl +++ b/drivers/opengl/shaders/stdlib.glsl diff --git a/drivers/gles2/shaders/tonemap.glsl b/drivers/opengl/shaders/tonemap.glsl index 0117bdb3d3..0117bdb3d3 100644 --- a/drivers/gles2/shaders/tonemap.glsl +++ b/drivers/opengl/shaders/tonemap.glsl diff --git a/drivers/gles2/texture_loader_gles2.cpp b/drivers/opengl/texture_loader_opengl.cpp index 3878b40c19..f4ead75a86 100644 --- a/drivers/gles2/texture_loader_gles2.cpp +++ b/drivers/opengl/texture_loader_opengl.cpp @@ -1,12 +1,12 @@ /*************************************************************************/ -/* texture_loader_gles2.cpp */ +/* texture_loader_opengl.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 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 */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "texture_loader_gles2.h" -#ifdef GLES2_BACKEND_ENABLED +#include "texture_loader_opengl.h" +#ifdef OPENGL_BACKEND_ENABLED #include "core/io/file_access.h" #include "core/string/print_string.h" #include <string.h> -RES ResourceFormatGLES2Texture::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { +RES ResourceFormatGLES2Texture::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { unsigned int width = 8; unsigned int height = 8; diff --git a/drivers/gles2/texture_loader_gles2.h b/drivers/opengl/texture_loader_opengl.h index 4e6e3c4ce2..e98438624b 100644 --- a/drivers/gles2/texture_loader_gles2.h +++ b/drivers/opengl/texture_loader_opengl.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* texture_loader_gles2.h */ +/* texture_loader_opengl.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,17 +28,18 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#pragma once +#ifndef TEXTURE_LOADER_OPENGL_H +#define TEXTURE_LOADER_OPENGL_H -#include "drivers/gles_common/rasterizer_platforms.h" -#ifdef GLES2_BACKEND_ENABLED +#include "drivers/opengl/rasterizer_platforms.h" +#ifdef OPENGL_BACKEND_ENABLED #include "core/io/resource_loader.h" #include "scene/resources/texture.h" class ResourceFormatGLES2Texture : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; @@ -46,4 +47,6 @@ public: virtual ~ResourceFormatGLES2Texture() {} }; -#endif +#endif // OPENGL_BACKEND_ENABLED + +#endif // TEXTURE_LOADER_OPENGL_H diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index 4909ac7a3f..bc4d9fb156 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -1491,15 +1491,15 @@ void EditorExport::add_export_preset(const Ref<EditorExportPreset> &p_preset, in } String EditorExportPlatform::test_etc2() const { -// String driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name"); -// bool etc_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc"); -// bool etc2_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc2"); + // String driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name"); + // bool etc_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc"); + // bool etc2_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc2"); String driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name"); bool etc_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc"); bool etc2_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc2"); - if (driver == "GLES2" && !etc_supported) { - return TTR("Target platform requires 'ETC' texture compression for GLES2. Enable 'Import Etc' in Project Settings."); + if (driver == "OpenGL" && !etc_supported) { + return TTR("Target platform requires 'ETC' texture compression for OpenGL. Enable 'Import Etc' in Project Settings."); } else if (driver == "Vulkan" && !etc2_supported) { // FIXME: Review if this is true for Vulkan. return TTR("Target platform requires 'ETC2' texture compression for Vulkan. Enable 'Import Etc 2' in Project Settings."); @@ -1511,12 +1511,12 @@ String EditorExportPlatform::test_etc2_or_pvrtc() const { String driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name"); bool etc2_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc2"); bool pvrtc_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_pvrtc"); -// String driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name"); -// bool etc2_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc2"); -// bool pvrtc_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_pvrtc"); + // String driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name"); + // bool etc2_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc2"); + // bool pvrtc_supported = ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_pvrtc"); - if (driver == "GLES2" && !pvrtc_supported) { - return TTR("Target platform requires 'PVRTC' texture compression for GLES2. Enable 'Import Pvrtc' in Project Settings."); + if (driver == "OpenGL" && !pvrtc_supported) { + return TTR("Target platform requires 'PVRTC' texture compression for OpenGL. Enable 'Import Pvrtc' in Project Settings."); } else if (driver == "Vulkan" && !etc2_supported && !pvrtc_supported) { // FIXME: Review if this is true for Vulkan. return TTR("Target platform requires 'ETC2' or 'PVRTC' texture compression for Vulkan. Enable 'Import Etc 2' or 'Import Pvrtc' in Project Settings."); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 9e84718fb7..d3d055a009 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -5596,14 +5596,9 @@ void EditorNode::_bottom_panel_raise_toggled(bool p_pressed) { } void EditorNode::_update_rendering_driver_color() { - // TODO: Probably should de-hardcode this and add to editor settings. - // if (video_driver->get_text() == "GLES2") { - // video_driver->add_theme_color_override("font_color", Color::hex(0x5586a4ff)); - // } else if (video_driver->get_text() == "Vulkan") { - // video_driver->add_theme_color_override("font_color", theme_base->get_theme_color(SNAME("vulkan_color"), SNAME("Editor"))); - if (rendering_driver->get_text() == "GLES2") { + if (rendering_driver->get_text() == "opengl") { rendering_driver->add_theme_color_override("font_color", Color::hex(0x5586a4ff)); - } else if (rendering_driver->get_text() == "Vulkan") { + } else if (rendering_driver->get_text() == "vulkan") { rendering_driver->add_theme_color_override("font_color", theme_base->get_theme_color("vulkan_color", "Editor")); } } @@ -6652,8 +6647,6 @@ EditorNode::EditorNode() { rendering_driver->add_theme_font_override("font", gui_base->get_theme_font("bold", "EditorFonts")); rendering_driver->add_theme_font_size_override("font_size", gui_base->get_theme_font_size("bold_size", "EditorFonts")); - // TODO re-enable when GLES2 is ported - // video_driver->set_disabled(true); right_menu_hb->add_child(rendering_driver); // only display the render drivers that are available for this display driver diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 84992892a4..b99ccc1012 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -4376,7 +4376,7 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, Edito const int wireframe_idx = view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME); const int overdraw_idx = view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW); const int shadeless_idx = view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS); - const String unsupported_tooltip = TTR("Not available when using the GLES2 renderer."); + const String unsupported_tooltip = TTR("Not available when using the OpenGL renderer."); view_menu->get_popup()->set_item_disabled(normal_idx, true); view_menu->get_popup()->set_item_tooltip(normal_idx, unsupported_tooltip); diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 6d023b8a7d..2bd99debed 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -1246,7 +1246,7 @@ void VisualShaderEditor::_update_options_menu() { Color unsupported_color = get_theme_color(SNAME("error_color"), SNAME("Editor")); Color supported_color = get_theme_color(SNAME("warning_color"), SNAME("Editor")); - static bool low_driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name") == "GLES2"; + static bool low_driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name") == "opengl"; Map<String, TreeItem *> folders; diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index 2adcbe69d6..8d14fa899e 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -478,7 +478,7 @@ private: if (rasterizer_button_group->get_pressed_button()->get_meta("driver_name") == "Vulkan") { initial_settings["rendering/driver/driver_name"] = "Vulkan"; } else { - initial_settings["rendering/driver/driver_name"] = "GLES2"; + initial_settings["rendering/driver/driver_name"] = "OpenGL"; initial_settings["rendering/textures/vram_compression/import_etc2"] = false; initial_settings["rendering/textures/vram_compression/import_etc"] = true; } diff --git a/main/main.cpp b/main/main.cpp index 24ede50fd4..bc23d498dc 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1275,14 +1275,14 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph register_core_extensions(); //before display // possibly be worth changing the default from vulkan to something lower spec, // for the project manager, depending on how smooth the fallback is. - GLOBAL_DEF("rendering/driver/driver_name", "Vulkan"); + GLOBAL_DEF_RST("rendering/driver/driver_name", "Vulkan"); // this list is hard coded, which makes it more difficult to add new backends. // can potentially be changed to more of a plugin system at a later date. ProjectSettings::get_singleton()->set_custom_property_info("rendering/driver/driver_name", PropertyInfo(Variant::STRING, "rendering/driver/driver_name", - PROPERTY_HINT_ENUM, "Vulkan,GLES2,GLES3")); + PROPERTY_HINT_ENUM, "Vulkan,OpenGL")); // if not set on the command line if (rendering_driver == "") { @@ -1294,10 +1294,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph // shows the correct driver string. OS::get_singleton()->set_current_rendering_driver_name(rendering_driver); - // always convert to lower case vulkan for consistency in the code - if (rendering_driver == "Vulkan") { - rendering_driver = "vulkan"; - } + // always convert to lower case for consistency in the code + rendering_driver = rendering_driver.to_lower(); GLOBAL_DEF_BASIC("display/window/size/width", 1024); ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/width", diff --git a/modules/basis_universal/register_types.cpp b/modules/basis_universal/register_types.cpp index 9a13406900..d2105d7c5d 100644 --- a/modules/basis_universal/register_types.cpp +++ b/modules/basis_universal/register_types.cpp @@ -203,7 +203,7 @@ static Ref<Image> basis_universal_unpacker(const Vector<uint8_t> &p_buffer) { format = basist::transcoder_texture_format::cTFETC2; // get this from renderer imgfmt = Image::FORMAT_ETC2_RGBA8; } else { - //gles2 most likely + //opengl most likely format = basist::transcoder_texture_format::cTFRGBA4444; // get this from renderer imgfmt = Image::FORMAT_RGBA4444; } @@ -216,7 +216,7 @@ static Ref<Image> basis_universal_unpacker(const Vector<uint8_t> &p_buffer) { format = basist::transcoder_texture_format::cTFETC2; // get this from renderer imgfmt = Image::FORMAT_ETC2_RGBA8; } else { - //gles2 most likely, bad for normal maps, nothing to do about this. + //opengl most likely, bad for normal maps, nothing to do about this. format = basist::transcoder_texture_format::cTFRGBA32; imgfmt = Image::FORMAT_RGBA8; } diff --git a/modules/camera/camera_osx.mm b/modules/camera/camera_osx.mm index 02f7287d1b..6def813e5c 100644 --- a/modules/camera/camera_osx.mm +++ b/modules/camera/camera_osx.mm @@ -181,7 +181,7 @@ uint8_t *w = img_data[1].ptrw(); memcpy(w, dataCbCr, 2 * new_width * new_height); - ///TODO GLES2 doesn't support FORMAT_RG8, need to do some form of conversion + ///TODO OpenGL doesn't support FORMAT_RG8, need to do some form of conversion img[1].instantiate(); img[1]->create(new_width, new_height, 0, Image::FORMAT_RG8, img_data[1]); } diff --git a/modules/mono/utils/string_utils.cpp b/modules/mono/utils/string_utils.cpp index 6fdb5079ce..74f5e6d18a 100644 --- a/modules/mono/utils/string_utils.cpp +++ b/modules/mono/utils/string_utils.cpp @@ -201,11 +201,11 @@ String str_format(const char *p_format, ...) { } #if defined(MINGW_ENABLED) -#define gd_vsnprintf(m_buffer, m_count, m_format, m_args_copy) vsnprintf_s(m_buffer, m_count, _TRUNCATE, m_format, m_args_copy) -#define gd_vscprintf(m_format, m_args_copy) _vscprintf(m_format, m_args_copy) +#define RSnprintf(m_buffer, m_count, m_format, m_args_copy) vsnprintf_s(m_buffer, m_count, _TRUNCATE, m_format, m_args_copy) +#define RScprintf(m_format, m_args_copy) _vscprintf(m_format, m_args_copy) #else -#define gd_vsnprintf(m_buffer, m_count, m_format, m_args_copy) vsnprintf(m_buffer, m_count, m_format, m_args_copy) -#define gd_vscprintf(m_format, m_args_copy) vsnprintf(nullptr, 0, p_format, m_args_copy) +#define RSnprintf(m_buffer, m_count, m_format, m_args_copy) vsnprintf(m_buffer, m_count, m_format, m_args_copy) +#define RScprintf(m_format, m_args_copy) vsnprintf(nullptr, 0, p_format, m_args_copy) #endif String str_format(const char *p_format, va_list p_list) { @@ -231,7 +231,7 @@ char *str_format_new(const char *p_format, va_list p_list) { va_list list; va_copy(list, p_list); - int len = gd_vscprintf(p_format, list); + int len = RScprintf(p_format, list); va_end(list); len += 1; // for the trailing '/0' @@ -239,7 +239,7 @@ char *str_format_new(const char *p_format, va_list p_list) { char *buffer(memnew_arr(char, len)); va_copy(list, p_list); - gd_vsnprintf(buffer, len, p_format, list); + RSnprintf(buffer, len, p_format, list); va_end(list); return buffer; diff --git a/gles_builders.py b/opengl_builders.py index c88e21bdee..179b5c69ab 100644 --- a/gles_builders.py +++ b/opengl_builders.py @@ -187,7 +187,7 @@ def include_file_in_legacygl_header(filename, header_data, depth): return header_data -def build_legacygl_header(filename, include, class_suffix, output_attribs, gles2=False): +def build_legacygl_header(filename, include, class_suffix, output_attribs): header_data = LegacyGLHeaderStruct() include_file_in_legacygl_header(filename, header_data, 0) @@ -286,9 +286,9 @@ def build_legacygl_header(filename, include, class_suffix, output_attribs, gles2 ) fd.write( - """\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Transform& p_transform) { _FU + """\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Transform3D& p_transform) { _FU - const Transform &tr = p_transform; + const Transform3D &tr = p_transform; GLfloat matrix[16]={ /* build a 16x16 matrix */ tr.basis.elements[0][0], @@ -449,26 +449,6 @@ def build_legacygl_header(filename, include, class_suffix, output_attribs, gles2 feedback_count = 0 - if not gles2 and len(header_data.feedbacks): - - fd.write("\t\tstatic const Feedback _feedbacks[]={\n") - for x in header_data.feedbacks: - name = x[0] - cond = x[1] - if cond in conditionals_found: - fd.write('\t\t\t{"' + name + '",' + str(conditionals_found.index(cond)) + "},\n") - else: - fd.write('\t\t\t{"' + name + '",-1},\n') - - feedback_count += 1 - - fd.write("\t\t};\n\n") - else: - if gles2: - pass - else: - fd.write("\t\tstatic const Feedback* _feedbacks=NULL;\n") - if header_data.texunits: fd.write("\t\tstatic TexUnitPair _texunit_pairs[]={\n") for x in header_data.texunits: @@ -477,17 +457,6 @@ def build_legacygl_header(filename, include, class_suffix, output_attribs, gles2 else: fd.write("\t\tstatic TexUnitPair *_texunit_pairs=NULL;\n") - if not gles2 and header_data.ubos: - fd.write("\t\tstatic UBOPair _ubo_pairs[]={\n") - for x in header_data.ubos: - fd.write('\t\t\t{"' + x[0] + '",' + x[1] + "},\n") - fd.write("\t\t};\n\n") - else: - if gles2: - pass - else: - fd.write("\t\tstatic UBOPair *_ubo_pairs=NULL;\n") - fd.write("\t\tstatic const char _vertex_code[]={\n") for x in header_data.vertex_lines: for c in x: @@ -509,67 +478,31 @@ def build_legacygl_header(filename, include, class_suffix, output_attribs, gles2 fd.write("\t\tstatic const int _fragment_code_start=" + str(header_data.fragment_offset) + ";\n") if output_attribs: - if gles2: - fd.write( - "\t\tsetup(_conditional_strings," - + str(len(header_data.conditionals)) - + ",_uniform_strings," - + str(len(header_data.uniforms)) - + ",_attribute_pairs," - + str(len(header_data.attributes)) - + ", _texunit_pairs," - + str(len(header_data.texunits)) - + ",_vertex_code,_fragment_code,_vertex_code_start,_fragment_code_start);\n" - ) - else: - fd.write( - "\t\tsetup(_conditional_strings," - + str(len(header_data.conditionals)) - + ",_uniform_strings," - + str(len(header_data.uniforms)) - + ",_attribute_pairs," - + str(len(header_data.attributes)) - + ", _texunit_pairs," - + str(len(header_data.texunits)) - + ",_ubo_pairs," - + str(len(header_data.ubos)) - + ",_feedbacks," - + str(feedback_count) - + ",_vertex_code,_fragment_code,_vertex_code_start,_fragment_code_start);\n" - ) + fd.write( + "\t\tsetup(_conditional_strings," + + str(len(header_data.conditionals)) + + ",_uniform_strings," + + str(len(header_data.uniforms)) + + ",_attribute_pairs," + + str(len(header_data.attributes)) + + ", _texunit_pairs," + + str(len(header_data.texunits)) + + ",_vertex_code,_fragment_code,_vertex_code_start,_fragment_code_start);\n" + ) else: - if gles2: - fd.write( - "\t\tsetup(_conditional_strings," - + str(len(header_data.conditionals)) - + ",_uniform_strings," - + str(len(header_data.uniforms)) - + ",_texunit_pairs," - + str(len(header_data.texunits)) - + ",_enums," - + str(len(header_data.enums)) - + ",_enum_values," - + str(enum_value_count) - + ",_vertex_code,_fragment_code,_vertex_code_start,_fragment_code_start);\n" - ) - else: - fd.write( - "\t\tsetup(_conditional_strings," - + str(len(header_data.conditionals)) - + ",_uniform_strings," - + str(len(header_data.uniforms)) - + ",_texunit_pairs," - + str(len(header_data.texunits)) - + ",_enums," - + str(len(header_data.enums)) - + ",_enum_values," - + str(enum_value_count) - + ",_ubo_pairs," - + str(len(header_data.ubos)) - + ",_feedbacks," - + str(feedback_count) - + ",_vertex_code,_fragment_code,_vertex_code_start,_fragment_code_start);\n" - ) + fd.write( + "\t\tsetup(_conditional_strings," + + str(len(header_data.conditionals)) + + ",_uniform_strings," + + str(len(header_data.uniforms)) + + ",_texunit_pairs," + + str(len(header_data.texunits)) + + ",_enums," + + str(len(header_data.enums)) + + ",_enum_values," + + str(enum_value_count) + + ",_vertex_code,_fragment_code,_vertex_code_start,_fragment_code_start);\n" + ) fd.write("\t}\n\n") @@ -586,15 +519,10 @@ def build_legacygl_header(filename, include, class_suffix, output_attribs, gles2 fd.close() -def build_gles3_headers(target, source, env): - for x in source: - build_legacygl_header(str(x), include="drivers/gles3/shader_gles3.h", class_suffix="GLES3", output_attribs=True) - - -def build_gles2_headers(target, source, env): +def build_opengl_headers(target, source, env): for x in source: build_legacygl_header( - str(x), include="drivers/gles2/shader_gles2.h", class_suffix="GLES2", output_attribs=True, gles2=True + str(x), include="drivers/opengl/shader_opengl.h", class_suffix="OpenGL", output_attribs=True ) diff --git a/platform/android/display_server_android.cpp b/platform/android/display_server_android.cpp index 720752d28f..084761b794 100644 --- a/platform/android/display_server_android.cpp +++ b/platform/android/display_server_android.cpp @@ -411,9 +411,9 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis if (rendering_driver == "opengl") { bool gl_initialization_error = false; - if (RasterizerGLES2::is_viable() == OK) { - RasterizerGLES2::register_config(); - RasterizerGLES2::make_current(); + if (RasterizerOpenGLis_viable() == OK) { + RasterizerOpenGLregister_config(); + RasterizerOpenGLmake_current(); } else { gl_initialization_error = true; } diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index e01ad004a0..1cac0ed4ce 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -1599,7 +1599,7 @@ //public: // virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) override { // String driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name"); -// if (driver == "GLES2") { +// if (driver == "OpenGL") { // r_features->push_back("etc"); // } // // FIXME: Review what texture formats are used for Vulkan. @@ -1769,10 +1769,10 @@ // String tmp_export_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport.apk"); -//#define CLEANUP_AND_RETURN(m_err) \ -// { \ -// DirAccess::remove_file_or_error(tmp_export_path); \ -// return m_err; \ +//#define CLEANUP_AND_RETURN(m_err) +// { +// DirAccess::remove_file_or_error(tmp_export_path); +// return m_err; // } // // Export to temporary APK before sending to device. @@ -2565,10 +2565,10 @@ // String tmp_unaligned_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport-unaligned.apk"); -//#define CLEANUP_AND_RETURN(m_err) \ -// { \ -// DirAccess::remove_file_or_error(tmp_unaligned_path); \ -// return m_err; \ +//#define CLEANUP_AND_RETURN(m_err) +// { +// DirAccess::remove_file_or_error(tmp_unaligned_path); +// return m_err; // } // zipFile unaligned_apk = zipOpen2(tmp_unaligned_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io2); diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cpp index aa1aa4d264..50823884cd 100644 --- a/platform/android/export/export_plugin.cpp +++ b/platform/android/export/export_plugin.cpp @@ -1612,7 +1612,7 @@ Vector<String> EditorExportPlatformAndroid::get_enabled_abis(const Ref<EditorExp void EditorExportPlatformAndroid::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) { String driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name"); - if (driver == "GLES2") { + if (driver == "OpenGL") { r_features->push_back("etc"); } // FIXME: Review what texture formats are used for Vulkan. diff --git a/platform/iphone/app_delegate.h b/platform/iphone/app_delegate.h index d6a2292dd2..68cfde6508 100644 --- a/platform/iphone/app_delegate.h +++ b/platform/iphone/app_delegate.h @@ -32,7 +32,7 @@ @class ViewController; -// FIXME: Add support for both GLES2 and Vulkan when GLES2 is implemented again, +// FIXME: Add support for both OpenGL and Vulkan when OpenGL is implemented again, // so it can't be done with compilation time branching. //#if defined(OPENGL_ENABLED) //@interface AppDelegate : NSObject <UIApplicationDelegate, GLViewDelegate> { diff --git a/platform/iphone/display_layer.mm b/platform/iphone/display_layer.mm index b8df81b89a..afa75f53ed 100644 --- a/platform/iphone/display_layer.mm +++ b/platform/iphone/display_layer.mm @@ -89,7 +89,7 @@ // FIXME: Add Vulkan support via MoltenVK. Add fallback code back? // Create GL ES 2 context - if (GLOBAL_GET("rendering/driver/driver_name") == "GLES2") { + if (GLOBAL_GET("rendering/driver/driver_name") == "opengl") { context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; NSLog(@"Setting up an OpenGL ES 2.0 context."); if (!context) { diff --git a/platform/iphone/display_server_iphone.mm b/platform/iphone/display_server_iphone.mm index e18448fb6d..33601da1c8 100644 --- a/platform/iphone/display_server_iphone.mm +++ b/platform/iphone/display_server_iphone.mm @@ -52,7 +52,7 @@ DisplayServerIPhone::DisplayServerIPhone(const String &p_rendering_driver, Windo rendering_driver = p_rendering_driver; #if defined(OPENGL_ENABLED) - // FIXME: Add support for both GLES2 and Vulkan when GLES2 is implemented + // FIXME: Add support for both OpenGL and Vulkan when OpenGL is implemented // again, if (rendering_driver == "opengl_es") { @@ -60,9 +60,9 @@ DisplayServerIPhone::DisplayServerIPhone(const String &p_rendering_driver, Windo // FIXME: Add Vulkan support via MoltenVK. Add fallback code back? - if (RasterizerGLES2::is_viable() == OK) { - RasterizerGLES2::register_config(); - RasterizerGLES2::make_current(); + if (RasterizerOpenGLis_viable() == OK) { + RasterizerOpenGLregister_config(); + RasterizerOpenGLmake_current(); } else { gl_initialization_error = true; } @@ -83,7 +83,7 @@ DisplayServerIPhone::DisplayServerIPhone(const String &p_rendering_driver, Windo // reset this to what it should be, it will have been set to 0 after // rendering_server->init() is called - // RasterizerStorageGLES2::system_fbo = gl_view_base_fb; + // RasterizerStorageOpenGLsystem_fbo = gl_view_base_fb; } #endif diff --git a/platform/iphone/platform_config.h b/platform/iphone/platform_config.h index f8a8eb15d2..68ef4e31a7 100644 --- a/platform/iphone/platform_config.h +++ b/platform/iphone/platform_config.h @@ -30,8 +30,7 @@ #include <alloca.h> -#define GLES2_INCLUDE_H <ES2/gl.h> -#define GLES3_INCLUDE_H <ES3/gl.h> +#define OPENGL_INCLUDE_H <ES3/gl.h> #define PLATFORM_REFCOUNT diff --git a/platform/javascript/display_server_javascript.cpp b/platform/javascript/display_server_javascript.cpp index c2eb826db9..dacae912b5 100644 --- a/platform/javascript/display_server_javascript.cpp +++ b/platform/javascript/display_server_javascript.cpp @@ -677,7 +677,7 @@ DisplayServerJavaScript::DisplayServerJavaScript(const String &p_rendering_drive // Expose method for requesting quit. godot_js_os_request_quit_cb(request_quit_callback); - RasterizerDummy::make_current(); // TODO GLES2 in Godot 4.0... or webgpu? + RasterizerDummy::make_current(); // TODO OpenGL in Godot 4.0... or webgpu? #if 0 EmscriptenWebGLContextAttributes attributes; emscripten_webgl_init_context_attributes(&attributes); @@ -691,10 +691,10 @@ DisplayServerJavaScript::DisplayServerJavaScript(const String &p_rendering_drive bool gl_initialization_error = false; - if (RasterizerGLES2::is_viable() == OK) { + if (RasterizerOpenGLis_viable() == OK) { attributes.majorVersion = 1; - RasterizerGLES2::register_config(); - RasterizerGLES2::make_current(); + RasterizerOpenGLregister_config(); + RasterizerOpenGLmake_current(); } else { gl_initialization_error = true; } diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index 503e58f9a8..5130630c18 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -316,7 +316,7 @@ void EditorExportPlatformJavaScript::get_preset_features(const Ref<EditorExportP if (p_preset->get("vram_texture_compression/for_mobile")) { String driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name"); - if (driver == "GLES2") { + if (driver == "OpenGL") { r_features->push_back("etc"); } else if (driver == "Vulkan") { // FIXME: Review if this is correct. diff --git a/platform/javascript/export/export_plugin.cpp b/platform/javascript/export/export_plugin.cpp index 1084a0adf7..b98e87e789 100644 --- a/platform/javascript/export/export_plugin.cpp +++ b/platform/javascript/export/export_plugin.cpp @@ -300,7 +300,7 @@ void EditorExportPlatformJavaScript::get_preset_features(const Ref<EditorExportP if (p_preset->get("vram_texture_compression/for_mobile")) { String driver = ProjectSettings::get_singleton()->get("rendering/driver/driver_name"); - if (driver == "GLES2") { + if (driver == "OpenGL") { r_features->push_back("etc"); } else if (driver == "Vulkan") { // FIXME: Review if this is correct. diff --git a/platform/linuxbsd/SCsub b/platform/linuxbsd/SCsub index 05393f6246..cec8706fbc 100644 --- a/platform/linuxbsd/SCsub +++ b/platform/linuxbsd/SCsub @@ -20,8 +20,6 @@ if "x11" in env and env["x11"]: "key_mapping_x11.cpp", ] -#"context_gl_x11.cpp", - if "vulkan" in env and env["vulkan"]: common_linuxbsd.append("vulkan_context_x11.cpp") diff --git a/platform/linuxbsd/display_server_x11.cpp b/platform/linuxbsd/display_server_x11.cpp index 18247deafb..4421c868d8 100644 --- a/platform/linuxbsd/display_server_x11.cpp +++ b/platform/linuxbsd/display_server_x11.cpp @@ -44,8 +44,8 @@ #include "servers/rendering/renderer_rd/renderer_compositor_rd.h" #endif -#if defined(GLES_X11_ENABLED) -#include "drivers/gles2/rasterizer_gles2.h" +#if defined(OPENGL_ENABLED) +#include "drivers/opengl/rasterizer_opengl.h" #endif #include <limits.h> @@ -889,7 +889,7 @@ void DisplayServerX11::delete_sub_window(WindowID p_id) { context_vulkan->window_destroy(p_id); } #endif -#ifdef GLES_X11_ENABLED +#ifdef OPENGL_ENABLED if (gl_manager) { gl_manager->window_destroy(p_id); } @@ -1064,7 +1064,7 @@ int DisplayServerX11::window_get_current_screen(WindowID p_window) const { } void DisplayServerX11::gl_window_make_current(DisplayServer::WindowID p_window_id) { -#if defined(GLES_X11_ENABLED) +#if defined(OPENGL_ENABLED) if (gl_manager) gl_manager->window_make_current(p_window_id); #endif @@ -2666,7 +2666,7 @@ void DisplayServerX11::_window_changed(XEvent *event) { context_vulkan->window_resize(window_id, wd.size.width, wd.size.height); } #endif -#if defined(GLES_X11_ENABLED) +#if defined(OPENGL_ENABLED) if (gl_manager) { gl_manager->window_resize(window_id, wd.size.width, wd.size.height); } @@ -3547,19 +3547,19 @@ void DisplayServerX11::process_events() { } void DisplayServerX11::release_rendering_thread() { -#if defined(GLES_X11_ENABLED) +#if defined(OPENGL_ENABLED) // gl_manager->release_current(); #endif } void DisplayServerX11::make_rendering_thread() { -#if defined(GLES_X11_ENABLED) +#if defined(OPENGL_ENABLED) // gl_manager->make_current(); #endif } void DisplayServerX11::swap_buffers() { -#if defined(GLES_X11_ENABLED) +#if defined(OPENGL_ENABLED) if (gl_manager) { gl_manager->swap_buffers(); } @@ -3710,7 +3710,7 @@ void DisplayServerX11::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mo } #endif -#if defined(GLES_X11_ENABLED) +#if defined(OPENGL_ENABLED) if (gl_manager) { gl_manager->set_use_vsync(p_vsync_mode == DisplayServer::VSYNC_ENABLED); } @@ -3724,7 +3724,7 @@ DisplayServer::VSyncMode DisplayServerX11::window_get_vsync_mode(WindowID p_wind return context_vulkan->get_vsync_mode(p_window); } #endif -#if defined(GLES_X11_ENABLED) +#if defined(OPENGL_ENABLED) if (gl_manager) { return gl_manager->is_using_vsync() ? DisplayServer::VSYNC_ENABLED : DisplayServer::VSYNC_DISABLED; } @@ -3738,10 +3738,8 @@ Vector<String> DisplayServerX11::get_rendering_drivers_func() { #ifdef VULKAN_ENABLED drivers.push_back("vulkan"); #endif -#ifdef GLES_X11_ENABLED - // drivers.push_back("opengl"); - drivers.push_back("GLES2"); - drivers.push_back("GLES3"); +#ifdef OPENGL_ENABLED + drivers.push_back("opengl"); #endif return drivers; @@ -3750,7 +3748,7 @@ Vector<String> DisplayServerX11::get_rendering_drivers_func() { DisplayServer *DisplayServerX11::create_func(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { DisplayServer *ds = memnew(DisplayServerX11(p_rendering_driver, p_mode, p_vsync_mode, p_flags, p_resolution, r_error)); if (r_error != OK) { - OS::get_singleton()->alert("Your video card driver does not support any of the supported Vulkan versions.\n" + OS::get_singleton()->alert("Your video card driver does not support any of the supported Vulkan or OpenGL versions.\n" "Please update your drivers or if you have a very old or integrated GPU, upgrade it.\n" "If you have updated your graphics drivers recently, try rebooting.", "Unable to initialize Video driver"); @@ -3926,11 +3924,11 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, V ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, "Can't create a Vulkan window"); } #endif -#ifdef GLES_X11_ENABLED +#ifdef OPENGL_ENABLED print_line("rendering_driver " + rendering_driver); if (gl_manager) { Error err = gl_manager->window_create(id, wd.x11_window, x11_display, p_rect.size.width, p_rect.size.height); - ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, "Can't create a GLES2 window"); + ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, "Can't create an OpenGL window"); } #endif @@ -4114,15 +4112,13 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode xdnd_selection = XInternAtom(x11_display, "XdndSelection", False); //!!!!!!!!!!!!!!!!!!!!!!!!!! - //TODO - do Vulkan and GLES2 support checks, driver selection and fallback + //TODO - do Vulkan and OpenGL support checks, driver selection and fallback rendering_driver = p_rendering_driver; #ifndef _MSC_VER //#warning Forcing vulkan rendering driver because OpenGL not implemented yet //#warning Forcing opengl rendering driver because selecting properly is too much effort #endif - // rendering_driver = "vulkan"; - //rendering_driver = "GLES2"; bool driver_found = false; #if defined(VULKAN_ENABLED) @@ -4138,9 +4134,9 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode } #endif // Init context and rendering device -#if defined(GLES_X11_ENABLED) +#if defined(OPENGL_ENABLED) print_line("rendering_driver " + rendering_driver); - if (rendering_driver == "GLES2") { + if (rendering_driver == "opengl") { if (getenv("DRI_PRIME") == nullptr) { int use_prime = -1; @@ -4182,7 +4178,7 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode } } - GLManager_X11::ContextType opengl_api_type = GLManager_X11::GLES_2_0_COMPATIBLE; + GLManager_X11::ContextType opengl_api_type = GLManager_X11::GLES_3_0_COMPATIBLE; gl_manager = memnew(GLManager_X11(p_resolution, opengl_api_type)); @@ -4197,9 +4193,9 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode // gl_manager->set_use_vsync(current_videomode.use_vsync); if (true) { - // if (RasterizerGLES2::is_viable() == OK) { - // RasterizerGLES2::register_config(); - RasterizerGLES2::make_current(); + // if (RasterizerOpenGL::is_viable() == OK) { + // RasterizerOpenGL::register_config(); + RasterizerOpenGL::make_current(); } else { memdelete(gl_manager); gl_manager = nullptr; @@ -4415,9 +4411,9 @@ DisplayServerX11::~DisplayServerX11() { context_vulkan->window_destroy(E.key); } #endif -#ifdef GLES_X11_ENABLED - if (rendering_driver == "GLES2") { - gl_manager->window_destroy(E->key()); +#ifdef OPENGL_ENABLED + if (rendering_driver == "opengl") { + gl_manager->window_destroy(E.key); } #endif @@ -4444,7 +4440,7 @@ DisplayServerX11::~DisplayServerX11() { } #endif -#ifdef GLES_X11_ENABLED +#ifdef OPENGL_ENABLED if (gl_manager) { memdelete(gl_manager); gl_manager = nullptr; diff --git a/platform/linuxbsd/display_server_x11.h b/platform/linuxbsd/display_server_x11.h index bbf0e64fd3..ba25829974 100644 --- a/platform/linuxbsd/display_server_x11.h +++ b/platform/linuxbsd/display_server_x11.h @@ -31,7 +31,7 @@ #ifndef DISPLAY_SERVER_X11_H #define DISPLAY_SERVER_X11_H -#include "drivers/gles_common/rasterizer_platforms.h" +#include "drivers/opengl/rasterizer_platforms.h" #ifdef X11_ENABLED @@ -48,7 +48,7 @@ #include "servers/rendering/renderer_compositor.h" #include "servers/rendering_server.h" -#if defined(GLES_X11_ENABLED) +#if defined(OPENGL_ENABLED) #include "gl_manager_x11.h" #endif @@ -101,7 +101,7 @@ class DisplayServerX11 : public DisplayServer { Atom requested; int xdnd_version; -#if defined(GLES_X11_ENABLED) +#if defined(OPENGL_ENABLED) GLManager_X11 *gl_manager = nullptr; #endif #if defined(VULKAN_ENABLED) @@ -339,7 +339,7 @@ public: virtual void window_set_max_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override; virtual Size2i window_get_max_size(WindowID p_window = MAIN_WINDOW_ID) const override; - virtual void gl_window_make_current(DisplayServer::WindowID p_window_id); + virtual void gl_window_make_current(DisplayServer::WindowID p_window_id) override; virtual void window_set_transient(WindowID p_window, WindowID p_parent) override; diff --git a/platform/linuxbsd/gl_manager_x11.cpp b/platform/linuxbsd/gl_manager_x11.cpp index e3d12dcb01..5928ff3147 100644 --- a/platform/linuxbsd/gl_manager_x11.cpp +++ b/platform/linuxbsd/gl_manager_x11.cpp @@ -31,7 +31,7 @@ #include "gl_manager_x11.h" #ifdef X11_ENABLED -#if defined(GLES_X11_ENABLED) +#if defined(OPENGL_ENABLED) #include <stdio.h> #include <stdlib.h> @@ -174,9 +174,19 @@ Error GLManager_X11::_create_context(GLDisplay &gl_display) { int (*oldHandler)(Display *, XErrorEvent *) = XSetErrorHandler(&ctxErrorHandler); switch (context_type) { - case GLES_2_0_COMPATIBLE: { - gl_display.context->glx_context = glXCreateNewContext(gl_display.x11_display, fbconfig, GLX_RGBA_TYPE, 0, true); - ERR_FAIL_COND_V(!gl_display.context->glx_context, ERR_UNCONFIGURED); + case GLES_3_0_COMPATIBLE: { + // FIXME: Use `GLX_CONTEXT_CORE_PROFILE_BIT_ARB` instead of compatibility profile + // once deprecated API usages are fixed. + static int context_attribs[] = { + GLX_CONTEXT_MAJOR_VERSION_ARB, 3, + GLX_CONTEXT_MINOR_VERSION_ARB, 3, + GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, + GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB /*|GLX_CONTEXT_DEBUG_BIT_ARB*/, + None + }; + + gl_display.context->glx_context = glXCreateContextAttribsARB(x11_display, fbconfig, nullptr, true, context_attribs); + ERR_FAIL_COND_V(ctxErrorOccurred || !gl_display.context->glx_context, ERR_UNCONFIGURED); } break; } diff --git a/platform/linuxbsd/gl_manager_x11.h b/platform/linuxbsd/gl_manager_x11.h index 6781312074..e2e2545f3e 100644 --- a/platform/linuxbsd/gl_manager_x11.h +++ b/platform/linuxbsd/gl_manager_x11.h @@ -28,13 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#pragma once +#ifndef GL_MANAGER_X11_H +#define GL_MANAGER_X11_H #ifdef X11_ENABLED -#include "drivers/gles_common/rasterizer_platforms.h" +#include "drivers/opengl/rasterizer_platforms.h" -#if defined(GLES_X11_ENABLED) +#ifdef OPENGL_ENABLED #include "core/os/os.h" #include "core/templates/local_vector.h" @@ -47,7 +48,7 @@ struct GLManager_X11_Private; class GLManager_X11 { public: enum ContextType { - GLES_2_0_COMPATIBLE, + GLES_3_0_COMPATIBLE, }; private: @@ -123,5 +124,7 @@ public: ~GLManager_X11(); }; -#endif // GLES_X11_ENABLED +#endif // OPENGL_ENABLED #endif // X11_ENABLED + +#endif // GL_MANAGER_X11_H diff --git a/platform/linuxbsd/platform_config.h b/platform/linuxbsd/platform_config.h index cdf989fee7..aa78b48bb0 100644 --- a/platform/linuxbsd/platform_config.h +++ b/platform/linuxbsd/platform_config.h @@ -44,5 +44,4 @@ #endif #endif -#define GLES3_INCLUDE_H "thirdparty/glad/glad/glad.h" -#define GLES2_INCLUDE_H "thirdparty/glad/glad/glad.h" +#define OPENGL_INCLUDE_H "thirdparty/glad/glad/glad.h" diff --git a/platform/osx/display_server_osx.mm b/platform/osx/display_server_osx.mm index 3fe055a511..b9d47a757c 100644 --- a/platform/osx/display_server_osx.mm +++ b/platform/osx/display_server_osx.mm @@ -3750,7 +3750,7 @@ DisplayServerOSX::DisplayServerOSX(const String &p_rendering_driver, WindowMode [main_menu setSubmenu:apple_menu forItem:menu_item]; //!!!!!!!!!!!!!!!!!!!!!!!!!! - //TODO - do Vulkan and GLES2 support checks, driver selection and fallback + //TODO - do Vulkan and OpenGL support checks, driver selection and fallback rendering_driver = p_rendering_driver; #ifndef _MSC_VER diff --git a/platform/osx/platform_config.h b/platform/osx/platform_config.h index d36a72f9a1..7bfa466b97 100644 --- a/platform/osx/platform_config.h +++ b/platform/osx/platform_config.h @@ -30,6 +30,5 @@ #include <alloca.h> -#define GLES3_INCLUDE_H "thirdparty/glad/glad/glad.h" -#define GLES2_INCLUDE_H "thirdparty/glad/glad/glad.h" +#define OPENGL_INCLUDE_H "thirdparty/glad/glad/glad.h" #define PTHREAD_RENAME_SELF diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index 1a84f5da38..2d355f5f42 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -161,7 +161,7 @@ Error OS_UWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_a outside = true; // FIXME: Hardcoded for now, add Vulkan support. - p_video_driver = VIDEO_DRIVER_GLES2; + p_video_driver = VIDEO_DRIVER_OPENGL; ContextEGL_UWP::Driver opengl_api_type = ContextEGL_UWP::GLES_2_0; bool gl_initialization_error = false; @@ -175,9 +175,9 @@ Error OS_UWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_a } if (opengl_api_type == ContextEGL_UWP::GLES_2_0) { - if (RasterizerGLES2::is_viable() == OK) { - RasterizerGLES2::register_config(); - RasterizerGLES2::make_current(); + if (RasterizerOpenGLis_viable() == OK) { + RasterizerOpenGLregister_config(); + RasterizerOpenGLmake_current(); } else { gl_initialization_error = true; } diff --git a/platform/windows/detect.py b/platform/windows/detect.py index d8a1ff4c80..4740181df0 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -279,7 +279,7 @@ def configure_msvc(env, manual_msvc_config): if not env["use_volk"]: LIBS += ["vulkan"] - # env.AppendUnique(CPPDEFINES = ['OPENGL_ENABLED']) + env.AppendUnique(CPPDEFINES=["OPENGL_ENABLED"]) LIBS += ["opengl32"] env.Append(LINKFLAGS=[p + env["LIBSUFFIX"] for p in LIBS]) diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index 4b09edabdb..fda0bb1627 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -38,8 +38,8 @@ #include <avrt.h> -#if defined(GLES_WINDOWS_ENABLED) -#include "drivers/gles2/rasterizer_gles2.h" +#if defined(OPENGL_ENABLED) +#include "drivers/opengl/rasterizer_opengl.h" #endif static String format_error_message(DWORD id) { @@ -537,8 +537,8 @@ void DisplayServerWindows::delete_sub_window(WindowID p_window) { context_vulkan->window_destroy(p_window); } #endif -#ifdef GLES_WINDOWS_ENABLED - if (rendering_driver == "GLES2") { +#ifdef OPENGL_ENABLED + if (rendering_driver == "opengl") { gl_manager->window_destroy(p_window); } #endif @@ -552,7 +552,7 @@ void DisplayServerWindows::delete_sub_window(WindowID p_window) { } void DisplayServerWindows::gl_window_make_current(DisplayServer::WindowID p_window_id) { -#if defined(GLES_WINDOWS_ENABLED) +#if defined(OPENGL_ENABLED) gl_manager->window_make_current(p_window_id); #endif } @@ -827,8 +827,8 @@ void DisplayServerWindows::window_set_size(const Size2i p_size, WindowID p_windo context_vulkan->window_resize(p_window, w, h); } #endif -#if defined(GLES_WINDOWS_ENABLED) - if (rendering_driver == "GLES2") { +#if defined(OPENGL_ENABLED) + if (rendering_driver == "opengl") { gl_manager->window_resize(p_window, w, h); } #endif @@ -1611,7 +1611,7 @@ void DisplayServerWindows::make_rendering_thread() { } void DisplayServerWindows::swap_buffers() { -#if defined(GLES_WINDOWS_ENABLED) +#if defined(OPENGL_ENABLED) gl_manager->swap_buffers(); #endif } @@ -1765,17 +1765,18 @@ void DisplayServerWindows::set_icon(const Ref<Image> &p_icon) { void DisplayServerWindows::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window) { _THREAD_SAFE_METHOD_ #if defined(VULKAN_ENABLED) - context_vulkan->set_vsync_mode(p_window, p_vsync_mode); + // TODO disabling for now + //context_vulkan->set_vsync_mode(p_window, p_vsync_mode); #endif } DisplayServer::VSyncMode DisplayServerWindows::window_get_vsync_mode(WindowID p_window) const { _THREAD_SAFE_METHOD_ #if defined(VULKAN_ENABLED) - return context_vulkan->get_vsync_mode(p_window); -#else - return DisplayServer::VSYNC_ENABLED; + //TODO disabling for now + //return context_vulkan->get_vsync_mode(p_window); #endif + return DisplayServer::VSYNC_ENABLED; } void DisplayServerWindows::set_context(Context p_context) { @@ -3109,11 +3110,11 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode, } #endif -#ifdef GLES_WINDOWS_ENABLED +#ifdef OPENGL_ENABLED print_line("rendering_driver " + rendering_driver); - if (rendering_driver == "GLES2") { + if (rendering_driver == "opengl") { Error err = gl_manager->window_create(id, wd.hWnd, hInstance, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top); - ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, "Can't create a GLES2 window"); + ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, "Failed to create an OpenGL window."); } #endif @@ -3247,6 +3248,8 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win outside = true; + rendering_driver = p_rendering_driver; + // Note: Wacom WinTab driver API for pen input, for devices incompatible with Windows Ink. HMODULE wintab_lib = LoadLibraryW(L"wintab32.dll"); if (wintab_lib) { @@ -3323,9 +3326,6 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win use_raw_input = false; } - // hard coded render drivers... - // rendering_driver = "vulkan"; - // rendering_driver = "GLES2"; print_line("rendering_driver " + rendering_driver); #if defined(VULKAN_ENABLED) @@ -3340,10 +3340,10 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win } #endif // Init context and rendering device -#if defined(GLES_WINDOWS_ENABLED) +#if defined(OPENGL_ENABLED) - if (rendering_driver == "GLES2") { - GLManager_Windows::ContextType opengl_api_type = GLManager_Windows::GLES_2_0_COMPATIBLE; + if (rendering_driver == "opengl") { + GLManager_Windows::ContextType opengl_api_type = GLManager_Windows::GLES_3_0_COMPATIBLE; gl_manager = memnew(GLManager_Windows(opengl_api_type)); @@ -3357,7 +3357,7 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win // gl_manager->set_use_vsync(current_videomode.use_vsync); if (true) { - RasterizerGLES2::make_current(); + RasterizerOpenGL::make_current(); } else { memdelete(gl_manager); gl_manager = nullptr; @@ -3380,9 +3380,9 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win context_gles2->set_use_vsync(video_mode.use_vsync); - if (RasterizerGLES2::is_viable() == OK) { - RasterizerGLES2::register_config(); - RasterizerGLES2::make_current(); + if (RasterizerOpenGL::is_viable() == OK) { + RasterizerOpenGL::register_config(); + RasterizerOpenGL::make_current(); } else { memdelete(context_gles2); context_gles2 = nullptr; @@ -3448,8 +3448,8 @@ Vector<String> DisplayServerWindows::get_rendering_drivers_func() { #ifdef VULKAN_ENABLED drivers.push_back("vulkan"); #endif -#ifdef GLES_WINDOWS_ENABLED - drivers.push_back("GLES2"); +#ifdef OPENGL_ENABLED + drivers.push_back("opengl"); #endif return drivers; @@ -3458,7 +3458,7 @@ Vector<String> DisplayServerWindows::get_rendering_drivers_func() { DisplayServer *DisplayServerWindows::create_func(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { DisplayServer *ds = memnew(DisplayServerWindows(p_rendering_driver, p_mode, p_vsync_mode, p_flags, p_resolution, r_error)); if (r_error != OK) { - OS::get_singleton()->alert("Your video card driver does not support any of the supported Vulkan versions.\n" + OS::get_singleton()->alert("Your video card driver does not support any of the supported Vulkan or OpenGL versions.\n" "Please update your drivers or if you have a very old or integrated GPU upgrade it.", "Unable to initialize Video driver"); } @@ -3479,7 +3479,7 @@ DisplayServerWindows::~DisplayServerWindows() { SetWindowLongPtr(windows[MAIN_WINDOW_ID].hWnd, GWLP_WNDPROC, (LONG_PTR)user_proc); }; -#ifdef GLES_WINDOWS_ENABLED +#ifdef OPENGL_ENABLED // destroy windows .. NYI? #endif @@ -3511,7 +3511,7 @@ DisplayServerWindows::~DisplayServerWindows() { if (restore_mouse_trails > 1) { SystemParametersInfoA(SPI_SETMOUSETRAILS, restore_mouse_trails, 0, 0); } -#ifdef GLES_WINDOWS_ENABLED +#ifdef OPENGL_ENABLED if (gl_manager) { memdelete(gl_manager); gl_manager = nullptr; diff --git a/platform/windows/display_server_windows.h b/platform/windows/display_server_windows.h index 145c147208..86f47eabc8 100644 --- a/platform/windows/display_server_windows.h +++ b/platform/windows/display_server_windows.h @@ -56,7 +56,7 @@ #include "platform/windows/vulkan_context_win.h" #endif -#if defined(GLES_WINDOWS_ENABLED) +#if defined(OPENGL_ENABLED) #include "gl_manager_windows.h" #endif @@ -304,7 +304,7 @@ class DisplayServerWindows : public DisplayServer { int old_x, old_y; Point2i center; -#if defined(GLES_WINDOWS_ENABLED) +#if defined(OPENGL_ENABLED) GLManager_Windows *gl_manager; #endif diff --git a/platform/windows/gl_manager_windows.cpp b/platform/windows/gl_manager_windows.cpp index b6107088a2..8a79da987b 100644 --- a/platform/windows/gl_manager_windows.cpp +++ b/platform/windows/gl_manager_windows.cpp @@ -31,7 +31,7 @@ #include "gl_manager_windows.h" #ifdef WINDOWS_ENABLED -#ifdef GLES_WINDOWS_ENABLED +#ifdef OPENGL_ENABLED #include <stdio.h> #include <stdlib.h> @@ -66,7 +66,7 @@ int GLManager_Windows::_find_or_create_display(GLWindow &win) { // } // create - GLDisplay d_temp; + GLDisplay d_temp = {}; _displays.push_back(d_temp); int new_display_id = _displays.size() - 1; diff --git a/platform/windows/gl_manager_windows.h b/platform/windows/gl_manager_windows.h index 7d0aa0d624..53557cf68e 100644 --- a/platform/windows/gl_manager_windows.h +++ b/platform/windows/gl_manager_windows.h @@ -28,11 +28,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#pragma once +#ifndef GL_MANAGER_WINDOWS_H +#define GL_MANAGER_WINDOWS_H -#ifdef WINDOWS_ENABLED - -#ifdef GLES_WINDOWS_ENABLED +#if defined(WINDOWS_ENABLED) && defined(OPENGL_ENABLED) #include "core/error/error_list.h" #include "core/os/os.h" @@ -47,7 +46,7 @@ typedef int(APIENTRY *PFNWGLGETSWAPINTERVALEXTPROC)(void); class GLManager_Windows { public: enum ContextType { - GLES_2_0_COMPATIBLE, + GLES_3_0_COMPATIBLE, }; private: @@ -124,6 +123,6 @@ public: ~GLManager_Windows(); }; -#endif // OPENGL_ENABLED +#endif // defined(WINDOWS_ENABLED) && defined(OPENGL_ENABLED) -#endif // WINDOWS +#endif // GL_MANAGER_WINDOWS_H diff --git a/platform/windows/platform_config.h b/platform/windows/platform_config.h index 87e1743d49..dace0f86af 100644 --- a/platform/windows/platform_config.h +++ b/platform/windows/platform_config.h @@ -30,5 +30,4 @@ #include <malloc.h> -#define GLES3_INCLUDE_H "thirdparty/glad/glad/glad.h" -#define GLES2_INCLUDE_H "thirdparty/glad/glad/glad.h" +#define OPENGL_INCLUDE_H "thirdparty/glad/glad/glad.h" diff --git a/scene/2d/gpu_particles_2d.cpp b/scene/2d/gpu_particles_2d.cpp index 6950fefdbe..f1f4d1b769 100644 --- a/scene/2d/gpu_particles_2d.cpp +++ b/scene/2d/gpu_particles_2d.cpp @@ -284,7 +284,7 @@ TypedArray<String> GPUParticles2D::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); if (RenderingServer::get_singleton()->is_low_end()) { - warnings.push_back(TTR("GPU-based particles are not supported by the GLES2 video driver.\nUse the CPUParticles2D node instead. You can use the \"Convert to CPUParticles2D\" option for this purpose.")); + warnings.push_back(TTR("GPU-based particles are not supported by the OpenGL video driver.\nUse the CPUParticles2D node instead. You can use the \"Convert to CPUParticles2D\" option for this purpose.")); } if (process_material.is_null()) { diff --git a/scene/3d/gpu_particles_3d.cpp b/scene/3d/gpu_particles_3d.cpp index 13cb8b7dfb..b35a45576f 100644 --- a/scene/3d/gpu_particles_3d.cpp +++ b/scene/3d/gpu_particles_3d.cpp @@ -277,7 +277,7 @@ TypedArray<String> GPUParticles3D::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); if (RenderingServer::get_singleton()->is_low_end()) { - warnings.push_back(TTR("GPU-based particles are not supported by the GLES2 video driver.\nUse the CPUParticles3D node instead. You can use the \"Convert to CPUParticles3D\" option for this purpose.")); + warnings.push_back(TTR("GPU-based particles are not supported by the OpenGL video driver.\nUse the CPUParticles3D node instead. You can use the \"Convert to CPUParticles3D\" option for this purpose.")); } bool meshes_found = false; diff --git a/scene/3d/voxel_gi.cpp b/scene/3d/voxel_gi.cpp index 377abd5b38..f0cf8f5016 100644 --- a/scene/3d/voxel_gi.cpp +++ b/scene/3d/voxel_gi.cpp @@ -458,7 +458,7 @@ TypedArray<String> VoxelGI::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); if (RenderingServer::get_singleton()->is_low_end()) { - warnings.push_back(TTR("VoxelGIs are not supported by the GLES2 video driver.\nUse a LightmapGI instead.")); + warnings.push_back(TTR("VoxelGIs are not supported by the OpenGL video driver.\nUse a LightmapGI instead.")); } else if (probe_data.is_null()) { warnings.push_back(TTR("No VoxelGI data set, so this node is disabled. Bake static objects to enable GI.")); } diff --git a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp index 0f5af96417..ce3620b2d0 100644 --- a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp +++ b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp @@ -2722,7 +2722,7 @@ void RenderForwardClustered::_geometry_instance_update(GeometryInstance *p_geome } break; #if 0 case RS::INSTANCE_IMMEDIATE: { - RasterizerStorageGLES3::Immediate *immediate = storage->immediate_owner.get_or_null(inst->base); + RasterizerStorageOpenGL::Immediate *immediate = storage->immediate_owner.get_or_null(inst->base); ERR_CONTINUE(!immediate); _add_geometry(immediate, inst, nullptr, -1, p_depth_pass, p_shadow_pass); diff --git a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp index 95f5b46831..7716705666 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp @@ -2440,7 +2440,7 @@ void RenderForwardMobile::_geometry_instance_update(GeometryInstance *p_geometry } break; #if 0 case RS::INSTANCE_IMMEDIATE: { - RasterizerStorageGLES3::Immediate *immediate = storage->immediate_owner.get_or_null(inst->base); + RasterizerStorageOpenGL::Immediate *immediate = storage->immediate_owner.get_or_null(inst->base); ERR_CONTINUE(!immediate); _add_geometry(immediate, inst, nullptr, -1, p_depth_pass, p_shadow_pass); diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index f312c2501f..723c5ada3f 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -129,8 +129,10 @@ void RendererViewport::_draw_viewport(Viewport *p_viewport) { timestamp_vp_map[rt_id] = p_viewport->self; } - // This is currently needed for GLES to keep the current window being rendered to up to date - DisplayServer::get_singleton()->gl_window_make_current(p_viewport->viewport_to_screen); + if (OS::get_singleton()->get_current_rendering_driver_name() == "opengl") { + // This is currently needed for GLES to keep the current window being rendered to up to date + DisplayServer::get_singleton()->gl_window_make_current(p_viewport->viewport_to_screen); + } /* Camera should always be BEFORE any other 3D */ @@ -750,7 +752,7 @@ void RendererViewport::viewport_attach_to_screen(RID p_viewport, const Rect2 &p_ ERR_FAIL_COND(!viewport); if (p_screen != DisplayServer::INVALID_WINDOW_ID) { - // If using GLES2 we can optimize this operation by rendering directly to system_fbo + // If using OpenGL we can optimize this operation by rendering directly to system_fbo // instead of rendering to fbo and copying to system_fbo after if (RSG::rasterizer->is_low_end() && viewport->viewport_render_direct_to_screen) { RSG::storage->render_target_set_size(viewport->render_target, p_rect.size.x, p_rect.size.y, viewport->get_view_count()); |