diff options
Diffstat (limited to 'servers')
-rw-r--r-- | servers/audio/effects/audio_effect_spectrum_analyzer.cpp | 32 | ||||
-rw-r--r-- | servers/audio/effects/audio_effect_spectrum_analyzer.h | 30 | ||||
-rw-r--r-- | servers/audio/effects/audio_stream_generator.cpp | 30 | ||||
-rw-r--r-- | servers/audio/effects/audio_stream_generator.h | 36 | ||||
-rw-r--r-- | servers/audio_server.h | 2 | ||||
-rw-r--r-- | servers/physics_2d/joints_2d_sw.cpp | 2 | ||||
-rw-r--r-- | servers/physics_2d/shape_2d_sw.cpp | 13 | ||||
-rw-r--r-- | servers/visual/rasterizer.h | 2 | ||||
-rw-r--r-- | servers/visual/shader_language.cpp | 107 | ||||
-rw-r--r-- | servers/visual/shader_language.h | 10 | ||||
-rw-r--r-- | servers/visual/shader_types.cpp | 2 | ||||
-rw-r--r-- | servers/visual/visual_server_raster.cpp | 4 | ||||
-rw-r--r-- | servers/visual/visual_server_raster.h | 1 | ||||
-rw-r--r-- | servers/visual/visual_server_viewport.cpp | 44 | ||||
-rw-r--r-- | servers/visual/visual_server_viewport.h | 2 | ||||
-rw-r--r-- | servers/visual/visual_server_wrap_mt.h | 1 | ||||
-rw-r--r-- | servers/visual_server.cpp | 1 | ||||
-rw-r--r-- | servers/visual_server.h | 1 |
18 files changed, 298 insertions, 22 deletions
diff --git a/servers/audio/effects/audio_effect_spectrum_analyzer.cpp b/servers/audio/effects/audio_effect_spectrum_analyzer.cpp index 05cba416be..f5ac0afefa 100644 --- a/servers/audio/effects/audio_effect_spectrum_analyzer.cpp +++ b/servers/audio/effects/audio_effect_spectrum_analyzer.cpp @@ -1,3 +1,33 @@ +/*************************************************************************/ +/* audio_effect_spectrum_analyzer.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 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 "audio_effect_spectrum_analyzer.h" #include "servers/audio_server.h" @@ -170,7 +200,7 @@ Vector2 AudioEffectSpectrumAnalyzerInstance::get_magnitude_for_frequency_range(f for (int i = begin_pos; i <= end_pos; i++) { max.x = MAX(max.x, r[i].l); - max.y = MAX(max.x, r[i].r); + max.y = MAX(max.y, r[i].r); } return max; diff --git a/servers/audio/effects/audio_effect_spectrum_analyzer.h b/servers/audio/effects/audio_effect_spectrum_analyzer.h index 0534426da3..4f4c3c8a58 100644 --- a/servers/audio/effects/audio_effect_spectrum_analyzer.h +++ b/servers/audio/effects/audio_effect_spectrum_analyzer.h @@ -1,3 +1,33 @@ +/*************************************************************************/ +/* audio_effect_spectrum_analyzer.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 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 AUDIO_EFFECT_SPECTRUM_ANALYZER_H #define AUDIO_EFFECT_SPECTRUM_ANALYZER_H diff --git a/servers/audio/effects/audio_stream_generator.cpp b/servers/audio/effects/audio_stream_generator.cpp index f4a66b5643..49af63e82a 100644 --- a/servers/audio/effects/audio_stream_generator.cpp +++ b/servers/audio/effects/audio_stream_generator.cpp @@ -1,3 +1,33 @@ +/*************************************************************************/ +/* audio_stream_generator.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 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 "audio_stream_generator.h" void AudioStreamGenerator::set_mix_rate(float p_mix_rate) { diff --git a/servers/audio/effects/audio_stream_generator.h b/servers/audio/effects/audio_stream_generator.h index 2082682907..c3490ddaa5 100644 --- a/servers/audio/effects/audio_stream_generator.h +++ b/servers/audio/effects/audio_stream_generator.h @@ -1,5 +1,35 @@ -#ifndef AUDIO_STREAM_USER_FED_H -#define AUDIO_STREAM_USER_FED_H +/*************************************************************************/ +/* audio_stream_generator.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 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 AUDIO_STREAM_GENERATOR_H +#define AUDIO_STREAM_GENERATOR_H #include "core/ring_buffer.h" #include "servers/audio/audio_stream.h" @@ -63,4 +93,4 @@ public: AudioStreamGeneratorPlayback(); }; -#endif // AUDIO_STREAM_USER_FED_H +#endif // AUDIO_STREAM_GENERATOR_H diff --git a/servers/audio_server.h b/servers/audio_server.h index e56d87ce84..8c0ffd5a6b 100644 --- a/servers/audio_server.h +++ b/servers/audio_server.h @@ -149,7 +149,7 @@ class AudioServer : public Object { GDCLASS(AudioServer, Object) public: - //re-expose this her, as AudioDriver is not exposed to script + //re-expose this here, as AudioDriver is not exposed to script enum SpeakerMode { SPEAKER_MODE_STEREO, SPEAKER_SURROUND_31, diff --git a/servers/physics_2d/joints_2d_sw.cpp b/servers/physics_2d/joints_2d_sw.cpp index 954b0fa3ea..acdaa6e6df 100644 --- a/servers/physics_2d/joints_2d_sw.cpp +++ b/servers/physics_2d/joints_2d_sw.cpp @@ -92,7 +92,7 @@ normal_relative_velocity(Body2DSW *a, Body2DSW *b, Vector2 rA, Vector2 rB, Vecto bool PinJoint2DSW::setup(real_t p_step) { Space2DSW *space = A->get_space(); - ERR_FAIL_COND_V(!space, false;) + ERR_FAIL_COND_V(!space, false); rA = A->get_transform().basis_xform(anchor_A); rB = B ? B->get_transform().basis_xform(anchor_B) : anchor_B; diff --git a/servers/physics_2d/shape_2d_sw.cpp b/servers/physics_2d/shape_2d_sw.cpp index 66d2dcd417..0043b948b0 100644 --- a/servers/physics_2d/shape_2d_sw.cpp +++ b/servers/physics_2d/shape_2d_sw.cpp @@ -240,12 +240,7 @@ bool SegmentShape2DSW::intersect_segment(const Vector2 &p_begin, const Vector2 & real_t SegmentShape2DSW::get_moment_of_inertia(real_t p_mass, const Size2 &p_scale) const { - Vector2 s[2] = { a * p_scale, b * p_scale }; - - real_t l = s[1].distance_to(s[0]); - Vector2 ofs = (s[0] + s[1]) * 0.5; - - return p_mass * (l * l / 12.0 + ofs.length_squared()); + return p_mass * ((a * p_scale).distance_squared_to(b * p_scale)) / 12; } void SegmentShape2DSW::set_data(const Variant &p_data) { @@ -318,7 +313,9 @@ bool CircleShape2DSW::intersect_segment(const Vector2 &p_begin, const Vector2 &p real_t CircleShape2DSW::get_moment_of_inertia(real_t p_mass, const Size2 &p_scale) const { - return (radius * radius) * (p_scale.x * 0.5 + p_scale.y * 0.5); + real_t a = radius * p_scale.x; + real_t b = radius * p_scale.y; + return p_mass * (a * a + b * b) / 4; } void CircleShape2DSW::set_data(const Variant &p_data) { @@ -637,7 +634,7 @@ real_t ConvexPolygonShape2DSW::get_moment_of_inertia(real_t p_mass, const Size2 aabb.expand_to(points[i].pos * p_scale); } - return p_mass * aabb.size.dot(aabb.size) / 12.0 + p_mass * (aabb.position + aabb.size * 0.5).length_squared(); + return p_mass * aabb.size.dot(aabb.size) / 12.0; } void ConvexPolygonShape2DSW::set_data(const Variant &p_data) { diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index a02f52f034..31888261ec 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -550,10 +550,12 @@ public: RENDER_TARGET_NO_SAMPLING, RENDER_TARGET_HDR, RENDER_TARGET_KEEP_3D_LINEAR, + RENDER_TARGET_DIRECT_TO_SCREEN, RENDER_TARGET_FLAG_MAX }; virtual RID render_target_create() = 0; + virtual void render_target_set_position(RID p_render_target, int p_x, int p_y) = 0; virtual void render_target_set_size(RID p_render_target, int p_width, int p_height) = 0; virtual RID render_target_get_texture(RID p_render_target) const = 0; virtual void render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id) = 0; diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index cb3a744730..42b9f19d9d 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -132,6 +132,7 @@ const char *ShaderLanguage::token_names[TK_MAX] = { "TYPE_SAMPLERCUBE", "INTERPOLATION_FLAT", "INTERPOLATION_SMOOTH", + "CONST", "PRECISION_LOW", "PRECISION_MID", "PRECISION_HIGH", @@ -271,6 +272,7 @@ const ShaderLanguage::KeyWord ShaderLanguage::keyword_list[] = { { TK_TYPE_SAMPLERCUBE, "samplerCube" }, { TK_INTERPOLATION_FLAT, "flat" }, { TK_INTERPOLATION_SMOOTH, "smooth" }, + { TK_CONST, "const" }, { TK_PRECISION_LOW, "lowp" }, { TK_PRECISION_MID, "mediump" }, { TK_PRECISION_HIGH, "highp" }, @@ -920,6 +922,16 @@ bool ShaderLanguage::_find_identifier(const BlockNode *p_block, const Map<String return true; } + if (shader->constants.has(p_identifier)) { + if (r_data_type) { + *r_data_type = shader->constants[p_identifier].type; + } + if (r_type) { + *r_type = IDENTIFIER_CONSTANT; + } + return true; + } + for (int i = 0; i < shader->functions.size(); i++) { if (!shader->functions[i].callable) @@ -2699,6 +2711,12 @@ bool ShaderLanguage::_validate_assign(Node *p_node, const Map<StringName, BuiltI return false; } + if (shader->constants.has(var->name)) { + if (r_message) + *r_message = RTR("Constants cannot be modified."); + return false; + } + if (!(p_builtin_types.has(var->name) && p_builtin_types[var->name].constant)) { return true; } @@ -2968,6 +2986,10 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons member_type = DataType(dt - 1); } else if (l == 2) { member_type = dt; + } else if (l == 3) { + member_type = DataType(dt + 1); + } else if (l == 4) { + member_type = DataType(dt + 2); } else { ok = false; break; @@ -3001,6 +3023,8 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons member_type = DataType(dt - 1); } else if (l == 3) { member_type = dt; + } else if (l == 4) { + member_type = DataType(dt + 1); } else { ok = false; break; @@ -3987,7 +4011,7 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui } else { - //nothng else, so expression + //nothing else, so expression _set_tkpos(pos); //rollback Node *expr = _parse_and_reduce_expression(p_block, p_builtin_types); if (!expr) @@ -4316,24 +4340,30 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } break; default: { - //function + //function or constant variable + bool is_constant = false; DataPrecision precision = PRECISION_DEFAULT; DataType type; StringName name; + if (tk.type == TK_CONST) { + is_constant = true; + tk = _get_token(); + } + if (is_token_precision(tk.type)) { precision = get_token_precision(tk.type); tk = _get_token(); } if (!is_token_datatype(tk.type)) { - _set_error("Expected function, uniform or varying "); + _set_error("Expected constant, function, uniform or varying "); return ERR_PARSE_ERROR; } if (!is_token_variable_datatype(tk.type)) { - _set_error("Invalid data type for function return (samplers not allowed)"); + _set_error("Invalid data type for constants or function return (samplers not allowed)"); return ERR_PARSE_ERROR; } @@ -4353,8 +4383,73 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct tk = _get_token(); if (tk.type != TK_PARENTHESIS_OPEN) { - _set_error("Expected '(' after identifier"); - return ERR_PARSE_ERROR; + if (type == TYPE_VOID) { + _set_error("Expected '(' after function identifier"); + return ERR_PARSE_ERROR; + } + + //variable + + while (true) { + ShaderNode::Constant constant; + constant.type = type; + constant.precision = precision; + constant.initializer = NULL; + + if (tk.type == TK_OP_ASSIGN) { + + if (!is_constant) { + _set_error("Expected 'const' keyword before constant definition"); + return ERR_PARSE_ERROR; + } + + //variable created with assignment! must parse an expression + Node *expr = _parse_and_reduce_expression(NULL, Map<StringName, BuiltInInfo>()); + if (!expr) + return ERR_PARSE_ERROR; + + if (expr->type != Node::TYPE_CONSTANT) { + _set_error("Expected constant expression after '='"); + return ERR_PARSE_ERROR; + } + + constant.initializer = static_cast<ConstantNode *>(expr); + + if (type != expr->get_datatype()) { + _set_error("Invalid assignment of '" + get_datatype_name(expr->get_datatype()) + "' to '" + get_datatype_name(type) + "'"); + return ERR_PARSE_ERROR; + } + tk = _get_token(); + } else { + _set_error("Expected initialization of constant"); + return ERR_PARSE_ERROR; + } + + shader->constants[name] = constant; + if (tk.type == TK_COMMA) { + tk = _get_token(); + if (tk.type != TK_IDENTIFIER) { + _set_error("Expected identifier after type"); + return ERR_PARSE_ERROR; + } + + name = tk.text; + if (_find_identifier(NULL, Map<StringName, BuiltInInfo>(), name)) { + _set_error("Redefinition of '" + String(name) + "'"); + return ERR_PARSE_ERROR; + } + + tk = _get_token(); + + } else if (tk.type == TK_SEMICOLON) { + break; + } else { + _set_error("Expected ',' or ';' after constant"); + return ERR_PARSE_ERROR; + } + } + + break; } Map<StringName, BuiltInInfo> builtin_types; diff --git a/servers/visual/shader_language.h b/servers/visual/shader_language.h index 67c273d267..934dc2c403 100644 --- a/servers/visual/shader_language.h +++ b/servers/visual/shader_language.h @@ -80,6 +80,7 @@ public: TK_TYPE_SAMPLERCUBE, TK_INTERPOLATION_FLAT, TK_INTERPOLATION_SMOOTH, + TK_CONST, TK_PRECISION_LOW, TK_PRECISION_MID, TK_PRECISION_HIGH, @@ -440,6 +441,13 @@ public: }; struct ShaderNode : public Node { + + struct Constant { + DataType type; + DataPrecision precision; + ConstantNode *initializer; + }; + struct Function { StringName name; FunctionNode *function; @@ -492,6 +500,7 @@ public: } }; + Map<StringName, Constant> constants; Map<StringName, Varying> varyings; Map<StringName, Uniform> uniforms; Vector<StringName> render_modes; @@ -632,6 +641,7 @@ private: IDENTIFIER_FUNCTION_ARGUMENT, IDENTIFIER_LOCAL_VAR, IDENTIFIER_BUILTIN_VAR, + IDENTIFIER_CONSTANT, }; bool _find_identifier(const BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types, const StringName &p_identifier, DataType *r_data_type = NULL, IdentifierType *r_type = NULL); diff --git a/servers/visual/shader_types.cpp b/servers/visual/shader_types.cpp index 8fd5dfc738..bc6010117c 100644 --- a/servers/visual/shader_types.cpp +++ b/servers/visual/shader_types.cpp @@ -147,6 +147,7 @@ ShaderTypes::ShaderTypes() { shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["DIFFUSE_LIGHT"] = ShaderLanguage::TYPE_VEC3; shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["SPECULAR_LIGHT"] = ShaderLanguage::TYPE_VEC3; shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["OUTPUT_IS_SRGB"] = constt(ShaderLanguage::TYPE_BOOL); + shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["ALPHA"] = ShaderLanguage::TYPE_FLOAT; shader_modes[VS::SHADER_SPATIAL].functions["light"].can_discard = true; @@ -187,6 +188,7 @@ ShaderTypes::ShaderTypes() { shader_modes[VS::SHADER_SPATIAL].modes.push_back("shadows_disabled"); shader_modes[VS::SHADER_SPATIAL].modes.push_back("ambient_light_disabled"); + shader_modes[VS::SHADER_SPATIAL].modes.push_back("shadow_to_opacity"); shader_modes[VS::SHADER_SPATIAL].modes.push_back("vertex_lighting"); diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index a9ca920178..310aa16130 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -201,8 +201,10 @@ VisualServerRaster::VisualServerRaster() { VSG::canvas_render = VSG::rasterizer->get_canvas(); VSG::scene_render = VSG::rasterizer->get_scene(); - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { black_margin[i] = 0; + black_image[i] = RID(); + } } VisualServerRaster::~VisualServerRaster() { diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 3ec428d687..921d55556d 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -454,6 +454,7 @@ public: BIND2(viewport_set_clear_mode, RID, ViewportClearMode) BIND3(viewport_attach_to_screen, RID, const Rect2 &, int) + BIND2(viewport_set_render_direct_to_screen, RID, bool) BIND1(viewport_detach, RID) BIND2(viewport_set_update_mode, RID, ViewportUpdateMode) diff --git a/servers/visual/visual_server_viewport.cpp b/servers/visual/visual_server_viewport.cpp index e7f60c2c1f..b7c54caffd 100644 --- a/servers/visual/visual_server_viewport.cpp +++ b/servers/visual/visual_server_viewport.cpp @@ -343,7 +343,7 @@ void VisualServerViewport::draw_viewports() { vp->render_info[VS::VIEWPORT_RENDER_INFO_SURFACE_CHANGES_IN_FRAME] = VSG::storage->get_captured_render_info(VS::INFO_SURFACE_CHANGES_IN_FRAME); vp->render_info[VS::VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME] = VSG::storage->get_captured_render_info(VS::INFO_DRAW_CALLS_IN_FRAME); - if (vp->viewport_to_screen_rect != Rect2()) { + if (vp->viewport_to_screen_rect != Rect2() && (!vp->viewport_render_direct_to_screen || !VSG::rasterizer->is_low_end())) { //copy to screen if set as such VSG::rasterizer->set_current_render_target(RID()); VSG::rasterizer->blit_render_target_to_screen(vp->render_target, vp->viewport_to_screen_rect, vp->viewport_to_screen); @@ -368,6 +368,7 @@ RID VisualServerViewport::viewport_create() { viewport->hide_canvas = false; viewport->render_target = VSG::storage->render_target_create(); viewport->shadow_atlas = VSG::scene_render->shadow_atlas_create(); + viewport->viewport_render_direct_to_screen = false; return rid; } @@ -424,14 +425,55 @@ void VisualServerViewport::viewport_attach_to_screen(RID p_viewport, const Rect2 Viewport *viewport = viewport_owner.getornull(p_viewport); ERR_FAIL_COND(!viewport); + // If using GLES2 we can optimize this operation by rendering directly to system_fbo + // instead of rendering to fbo and copying to system_fbo after + if (VSG::rasterizer->is_low_end() && viewport->viewport_render_direct_to_screen) { + + VSG::storage->render_target_set_size(viewport->render_target, p_rect.size.x, p_rect.size.y); + VSG::storage->render_target_set_position(viewport->render_target, p_rect.position.x, p_rect.position.y); + } + viewport->viewport_to_screen_rect = p_rect; viewport->viewport_to_screen = p_screen; } + +void VisualServerViewport::viewport_set_render_direct_to_screen(RID p_viewport, bool p_enable) { + Viewport *viewport = viewport_owner.getornull(p_viewport); + ERR_FAIL_COND(!viewport); + + if (p_enable == viewport->viewport_render_direct_to_screen) + return; + + // if disabled, reset render_target size and position + if (!p_enable) { + + VSG::storage->render_target_set_position(viewport->render_target, 0, 0); + VSG::storage->render_target_set_size(viewport->render_target, viewport->size.x, viewport->size.y); + } + + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_DIRECT_TO_SCREEN, p_enable); + viewport->viewport_render_direct_to_screen = p_enable; + + // if attached to screen already, setup screen size and position, this needs to happen after setting flag to avoid an unneccesary buffer allocation + if (VSG::rasterizer->is_low_end() && viewport->viewport_to_screen_rect != Rect2() && p_enable) { + + VSG::storage->render_target_set_size(viewport->render_target, viewport->viewport_to_screen_rect.size.x, viewport->viewport_to_screen_rect.size.y); + VSG::storage->render_target_set_position(viewport->render_target, viewport->viewport_to_screen_rect.position.x, viewport->viewport_to_screen_rect.position.y); + } +} + void VisualServerViewport::viewport_detach(RID p_viewport) { Viewport *viewport = viewport_owner.getornull(p_viewport); ERR_FAIL_COND(!viewport); + // if render_direct_to_screen was used, reset size and position + if (VSG::rasterizer->is_low_end() && viewport->viewport_render_direct_to_screen) { + + VSG::storage->render_target_set_position(viewport->render_target, 0, 0); + VSG::storage->render_target_set_size(viewport->render_target, viewport->size.x, viewport->size.y); + } + viewport->viewport_to_screen_rect = Rect2(); viewport->viewport_to_screen = 0; } diff --git a/servers/visual/visual_server_viewport.h b/servers/visual/visual_server_viewport.h index 555b40a103..43bbcb66c3 100644 --- a/servers/visual/visual_server_viewport.h +++ b/servers/visual/visual_server_viewport.h @@ -58,6 +58,7 @@ public: int viewport_to_screen; Rect2 viewport_to_screen_rect; + bool viewport_render_direct_to_screen; bool hide_scenario; bool hide_canvas; @@ -158,6 +159,7 @@ public: void viewport_set_size(RID p_viewport, int p_width, int p_height); void viewport_attach_to_screen(RID p_viewport, const Rect2 &p_rect = Rect2(), int p_screen = 0); + void viewport_set_render_direct_to_screen(RID p_viewport, bool p_enable); void viewport_detach(RID p_viewport); void viewport_set_active(RID p_viewport, bool p_active); diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index b2753369b8..cd24deb60c 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -381,6 +381,7 @@ public: FUNC2(viewport_set_clear_mode, RID, ViewportClearMode) FUNC3(viewport_attach_to_screen, RID, const Rect2 &, int) + FUNC2(viewport_set_render_direct_to_screen, RID, bool) FUNC1(viewport_detach, RID) FUNC2(viewport_set_update_mode, RID, ViewportUpdateMode) diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index b39b400a53..0fe00ad61a 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -1876,6 +1876,7 @@ void VisualServer::_bind_methods() { ClassDB::bind_method(D_METHOD("viewport_set_active", "viewport", "active"), &VisualServer::viewport_set_active); ClassDB::bind_method(D_METHOD("viewport_set_parent_viewport", "viewport", "parent_viewport"), &VisualServer::viewport_set_parent_viewport); ClassDB::bind_method(D_METHOD("viewport_attach_to_screen", "viewport", "rect", "screen"), &VisualServer::viewport_attach_to_screen, DEFVAL(Rect2()), DEFVAL(0)); + ClassDB::bind_method(D_METHOD("viewport_set_render_direct_to_screen", "viewport", "enabled"), &VisualServer::viewport_set_render_direct_to_screen); ClassDB::bind_method(D_METHOD("viewport_detach", "viewport"), &VisualServer::viewport_detach); ClassDB::bind_method(D_METHOD("viewport_set_update_mode", "viewport", "update_mode"), &VisualServer::viewport_set_update_mode); ClassDB::bind_method(D_METHOD("viewport_set_vflip", "viewport", "enabled"), &VisualServer::viewport_set_vflip); diff --git a/servers/visual_server.h b/servers/visual_server.h index 5146ca47f1..01be996bfc 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -610,6 +610,7 @@ public: virtual void viewport_set_parent_viewport(RID p_viewport, RID p_parent_viewport) = 0; virtual void viewport_attach_to_screen(RID p_viewport, const Rect2 &p_rect = Rect2(), int p_screen = 0) = 0; + virtual void viewport_set_render_direct_to_screen(RID p_viewport, bool p_enable) = 0; virtual void viewport_detach(RID p_viewport) = 0; enum ViewportUpdateMode { |