diff options
Diffstat (limited to 'servers')
22 files changed, 914 insertions, 17 deletions
diff --git a/servers/SCsub b/servers/SCsub index f4af347fe6..34ba70b8cb 100644 --- a/servers/SCsub +++ b/servers/SCsub @@ -6,6 +6,7 @@ env.servers_sources = [] env.add_source_files(env.servers_sources, "*.cpp") SConscript('arvr/SCsub') +SConscript('camera/SCsub') SConscript('physics/SCsub') SConscript('physics_2d/SCsub') SConscript('visual/SCsub') diff --git a/servers/arvr/arvr_interface.cpp b/servers/arvr/arvr_interface.cpp index 686ad0ba9b..e1b7611354 100644 --- a/servers/arvr/arvr_interface.cpp +++ b/servers/arvr/arvr_interface.cpp @@ -56,6 +56,7 @@ void ARVRInterface::_bind_methods() { // but we do have properties specific to AR.... ClassDB::bind_method(D_METHOD("get_anchor_detection_is_enabled"), &ARVRInterface::get_anchor_detection_is_enabled); ClassDB::bind_method(D_METHOD("set_anchor_detection_is_enabled", "enable"), &ARVRInterface::set_anchor_detection_is_enabled); + ClassDB::bind_method(D_METHOD("get_camera_feed_id"), &ARVRInterface::get_camera_feed_id); ADD_GROUP("AR", "ar_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ar_is_anchor_detection_enabled"), "set_anchor_detection_is_enabled", "get_anchor_detection_is_enabled"); @@ -136,3 +137,9 @@ bool ARVRInterface::get_anchor_detection_is_enabled() const { void ARVRInterface::set_anchor_detection_is_enabled(bool p_enable){ // don't do anything here, this needs to be implemented on AR interface to enable/disable things like plane detection etc. }; + +int ARVRInterface::get_camera_feed_id() { + // don't do anything here, this needs to be implemented on AR interface to enable/disable things like plane detection etc. + + return 0; +}; diff --git a/servers/arvr/arvr_interface.h b/servers/arvr/arvr_interface.h index 9ea59a3961..ffafa4fcf5 100644 --- a/servers/arvr/arvr_interface.h +++ b/servers/arvr/arvr_interface.h @@ -101,6 +101,7 @@ public: /** specific to AR **/ virtual bool get_anchor_detection_is_enabled() const; virtual void set_anchor_detection_is_enabled(bool p_enable); + virtual int get_camera_feed_id(); /** rendering and internal **/ diff --git a/servers/audio/effects/audio_effect_spectrum_analyzer.cpp b/servers/audio/effects/audio_effect_spectrum_analyzer.cpp index 8e15e9288f..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" 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/camera/SCsub b/servers/camera/SCsub new file mode 100644 index 0000000000..ccc76e823f --- /dev/null +++ b/servers/camera/SCsub @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +Import('env') + +env.add_source_files(env.servers_sources, "*.cpp") + +Export('env') diff --git a/servers/camera/camera_feed.cpp b/servers/camera/camera_feed.cpp new file mode 100644 index 0000000000..31b8b2874f --- /dev/null +++ b/servers/camera/camera_feed.cpp @@ -0,0 +1,266 @@ +/*************************************************************************/ +/* camera_feed.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 "camera_feed.h" +#include "servers/visual_server.h" + +void CameraFeed::_bind_methods() { + // The setters prefixed with _ are only exposed so we can have feeds through GDNative! + // They should not be called by the end user. + + ClassDB::bind_method(D_METHOD("get_id"), &CameraFeed::get_id); + ClassDB::bind_method(D_METHOD("get_name"), &CameraFeed::get_name); + ClassDB::bind_method(D_METHOD("_set_name", "name"), &CameraFeed::set_name); + + ClassDB::bind_method(D_METHOD("is_active"), &CameraFeed::is_active); + ClassDB::bind_method(D_METHOD("set_active", "active"), &CameraFeed::set_active); + + ClassDB::bind_method(D_METHOD("get_position"), &CameraFeed::get_position); + ClassDB::bind_method(D_METHOD("_set_position", "position"), &CameraFeed::set_position); + + // Note, for transform some feeds may override what the user sets (such as ARKit) + ClassDB::bind_method(D_METHOD("get_transform"), &CameraFeed::get_transform); + ClassDB::bind_method(D_METHOD("set_transform", "transform"), &CameraFeed::set_transform); + + ClassDB::bind_method(D_METHOD("_set_RGB_img", "rgb_img"), &CameraFeed::set_RGB_img); + ClassDB::bind_method(D_METHOD("_set_YCbCr_img", "ycbcr_img"), &CameraFeed::set_YCbCr_img); + ClassDB::bind_method(D_METHOD("_set_YCbCr_imgs", "y_img", "cbcr_img"), &CameraFeed::set_YCbCr_imgs); + ClassDB::bind_method(D_METHOD("_allocate_texture", "width", "height", "format", "texture_type", "data_type"), &CameraFeed::allocate_texture); + + ADD_GROUP("Feed", "feed_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "feed_is_active"), "set_active", "is_active"); + ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "feed_transform"), "set_transform", "get_transform"); + + BIND_ENUM_CONSTANT(FEED_NOIMAGE); + BIND_ENUM_CONSTANT(FEED_RGB); + BIND_ENUM_CONSTANT(FEED_YCbCr); + BIND_ENUM_CONSTANT(FEED_YCbCr_Sep); + + BIND_ENUM_CONSTANT(FEED_UNSPECIFIED); + BIND_ENUM_CONSTANT(FEED_FRONT); + BIND_ENUM_CONSTANT(FEED_BACK); +} + +int CameraFeed::get_id() const { + return id; +} + +bool CameraFeed::is_active() const { + return active; +} + +void CameraFeed::set_active(bool p_is_active) { + if (p_is_active == active) { + // all good + } else if (p_is_active) { + // attempt to activate this feed + if (activate_feed()) { + print_line("Activate " + name); + active = true; + } + } else { + // just deactivate it + deactivate_feed(); + print_line("Deactivate " + name); + active = false; + } +} + +String CameraFeed::get_name() const { + return name; +} + +void CameraFeed::set_name(String p_name) { + name = p_name; +} + +int CameraFeed::get_base_width() const { + return base_width; +} + +int CameraFeed::get_base_height() const { + return base_height; +} + +CameraFeed::FeedDataType CameraFeed::get_datatype() const { + return datatype; +} + +CameraFeed::FeedPosition CameraFeed::get_position() const { + return position; +} + +void CameraFeed::set_position(CameraFeed::FeedPosition p_position) { + position = p_position; +} + +Transform2D CameraFeed::get_transform() const { + return transform; +} + +void CameraFeed::set_transform(const Transform2D &p_transform) { + transform = p_transform; +} + +RID CameraFeed::get_texture(CameraServer::FeedImage p_which) { + return texture[p_which]; +} + +CameraFeed::CameraFeed() { + // initialize our feed + id = CameraServer::get_singleton()->get_free_id(); + name = "???"; + active = false; + datatype = CameraFeed::FEED_RGB; + position = CameraFeed::FEED_UNSPECIFIED; + transform = Transform2D(1.0, 0.0, 0.0, -1.0, 0.0, 1.0); + + // create a texture object + VisualServer *vs = VisualServer::get_singleton(); + texture[CameraServer::FEED_Y_IMAGE] = vs->texture_create(); // also used for RGBA + texture[CameraServer::FEED_CbCr_IMAGE] = vs->texture_create(); +} + +CameraFeed::CameraFeed(String p_name, FeedPosition p_position) { + // initialize our feed + id = CameraServer::get_singleton()->get_free_id(); + base_width = 0; + base_height = 0; + name = p_name; + active = false; + datatype = CameraFeed::FEED_NOIMAGE; + position = p_position; + transform = Transform2D(1.0, 0.0, 0.0, -1.0, 0.0, 1.0); + + // create a texture object + VisualServer *vs = VisualServer::get_singleton(); + texture[CameraServer::FEED_Y_IMAGE] = vs->texture_create(); // also used for RGBA + texture[CameraServer::FEED_CbCr_IMAGE] = vs->texture_create(); +} + +CameraFeed::~CameraFeed() { + // Free our textures + VisualServer *vs = VisualServer::get_singleton(); + vs->free(texture[CameraServer::FEED_Y_IMAGE]); + vs->free(texture[CameraServer::FEED_CbCr_IMAGE]); +} + +void CameraFeed::set_RGB_img(Ref<Image> p_rgb_img) { + if (active) { + VisualServer *vs = VisualServer::get_singleton(); + + int new_width = p_rgb_img->get_width(); + int new_height = p_rgb_img->get_height(); + + if ((base_width != new_width) || (base_height != new_height)) { + // We're assuming here that our camera image doesn't change around formats etc, allocate the whole lot... + base_width = new_width; + base_height = new_height; + + vs->texture_allocate(texture[CameraServer::FEED_RGBA_IMAGE], new_width, new_height, 0, Image::FORMAT_RGB8, VS::TEXTURE_TYPE_2D, VS::TEXTURE_FLAGS_DEFAULT); + } + + vs->texture_set_data(texture[CameraServer::FEED_RGBA_IMAGE], p_rgb_img); + datatype = CameraFeed::FEED_RGB; + } +} + +void CameraFeed::set_YCbCr_img(Ref<Image> p_ycbcr_img) { + if (active) { + VisualServer *vs = VisualServer::get_singleton(); + + int new_width = p_ycbcr_img->get_width(); + int new_height = p_ycbcr_img->get_height(); + + if ((base_width != new_width) || (base_height != new_height)) { + // We're assuming here that our camera image doesn't change around formats etc, allocate the whole lot... + base_width = new_width; + base_height = new_height; + + vs->texture_allocate(texture[CameraServer::FEED_RGBA_IMAGE], new_width, new_height, 0, Image::FORMAT_RGB8, VS::TEXTURE_TYPE_2D, VS::TEXTURE_FLAGS_DEFAULT); + } + + vs->texture_set_data(texture[CameraServer::FEED_RGBA_IMAGE], p_ycbcr_img); + datatype = CameraFeed::FEED_YCbCr; + } +} + +void CameraFeed::set_YCbCr_imgs(Ref<Image> p_y_img, Ref<Image> p_cbcr_img) { + if (active) { + VisualServer *vs = VisualServer::get_singleton(); + + ///@TODO investigate whether we can use thirdparty/misc/yuv2rgb.h here to convert our YUV data to RGB, our shader approach is potentially faster though.. + // Wondering about including that into multiple projects, may cause issues. + // That said, if we convert to RGB, we could enable using texture resources again... + + int new_y_width = p_y_img->get_width(); + int new_y_height = p_y_img->get_height(); + int new_cbcr_width = p_cbcr_img->get_width(); + int new_cbcr_height = p_cbcr_img->get_height(); + + if ((base_width != new_y_width) || (base_height != new_y_height)) { + // We're assuming here that our camera image doesn't change around formats etc, allocate the whole lot... + base_width = new_y_width; + base_height = new_y_height; + + vs->texture_allocate(texture[CameraServer::FEED_Y_IMAGE], new_y_width, new_y_height, 0, Image::FORMAT_R8, VS::TEXTURE_TYPE_2D, VS::TEXTURE_FLAG_USED_FOR_STREAMING); + + ///@TODO GLES2 doesn't support FORMAT_RG8, need to do some form of conversion + vs->texture_allocate(texture[CameraServer::FEED_CbCr_IMAGE], new_cbcr_width, new_cbcr_height, 0, Image::FORMAT_RG8, VS::TEXTURE_TYPE_2D, VS::TEXTURE_FLAG_USED_FOR_STREAMING); + } + + vs->texture_set_data(texture[CameraServer::FEED_Y_IMAGE], p_y_img); + vs->texture_set_data(texture[CameraServer::FEED_CbCr_IMAGE], p_cbcr_img); + datatype = CameraFeed::FEED_YCbCr_Sep; + } +} + +void CameraFeed::allocate_texture(int p_width, int p_height, Image::Format p_format, VisualServer::TextureType p_texture_type, FeedDataType p_data_type) { + VisualServer *vs = VisualServer::get_singleton(); + + if ((base_width != p_width) || (base_height != p_height)) { + // We're assuming here that our camera image doesn't change around formats etc, allocate the whole lot... + base_width = p_width; + base_height = p_height; + + vs->texture_allocate(texture[0], p_width, p_height, 0, p_format, p_texture_type, VS::TEXTURE_FLAGS_DEFAULT); + } + + datatype = p_data_type; +} + +bool CameraFeed::activate_feed() { + // nothing to do here + return true; +} + +void CameraFeed::deactivate_feed() { + // nothing to do here +} diff --git a/servers/camera/camera_feed.h b/servers/camera/camera_feed.h new file mode 100644 index 0000000000..90c076071c --- /dev/null +++ b/servers/camera/camera_feed.h @@ -0,0 +1,115 @@ +/*************************************************************************/ +/* camera_feed.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 CAMERA_FEED_H +#define CAMERA_FEED_H + +#include "core/image.h" +#include "core/math/transform_2d.h" +#include "servers/camera_server.h" +#include "servers/visual_server.h" + +/** + @author Bastiaan Olij <mux213@gmail.com> + + The camera server is a singleton object that gives access to the various + camera feeds that can be used as the background for our environment. +**/ + +class CameraFeed : public Reference { + GDCLASS(CameraFeed, Reference); + +public: + enum FeedDataType { + FEED_NOIMAGE, // we don't have an image yet + FEED_RGB, // our texture will contain a normal RGB texture that can be used directly + FEED_YCbCr, // our texture will contain a YCbCr texture that needs to be converted to RGB before output + FEED_YCbCr_Sep // our camera is split into two textures, first plane contains Y data, second plane contains CbCr data + }; + + enum FeedPosition { + FEED_UNSPECIFIED, // we have no idea + FEED_FRONT, // this is a camera on the front of the device + FEED_BACK // this is a camera on the back of the device + }; + +private: + int id; // unique id for this, for internal use in case feeds are removed + int base_width; + int base_height; + +protected: + String name; // name of our camera feed + FeedDataType datatype; // type of texture data stored + FeedPosition position; // position of camera on the device + Transform2D transform; // display transform + + bool active; // only when active do we actually update the camera texture each frame + RID texture[CameraServer::FEED_IMAGES]; // texture images needed for this + + static void _bind_methods(); + +public: + int get_id() const; + bool is_active() const; + void set_active(bool p_is_active); + + String get_name() const; + void set_name(String p_name); + + int get_base_width() const; + int get_base_height() const; + + FeedPosition get_position() const; + void set_position(FeedPosition p_position); + + Transform2D get_transform() const; + void set_transform(const Transform2D &p_transform); + + RID get_texture(CameraServer::FeedImage p_which); + + CameraFeed(); + CameraFeed(String p_name, FeedPosition p_position = CameraFeed::FEED_UNSPECIFIED); + virtual ~CameraFeed(); + + FeedDataType get_datatype() const; + void set_RGB_img(Ref<Image> p_rgb_img); + void set_YCbCr_img(Ref<Image> p_ycbcr_img); + void set_YCbCr_imgs(Ref<Image> p_y_img, Ref<Image> p_cbcr_img); + void allocate_texture(int p_width, int p_height, Image::Format p_format, VisualServer::TextureType p_texture_type, FeedDataType p_data_type); + + virtual bool activate_feed(); + virtual void deactivate_feed(); +}; + +VARIANT_ENUM_CAST(CameraFeed::FeedDataType); +VARIANT_ENUM_CAST(CameraFeed::FeedPosition); + +#endif /* !CAMERA_FEED_H */ diff --git a/servers/camera_server.cpp b/servers/camera_server.cpp new file mode 100644 index 0000000000..8d2ae37001 --- /dev/null +++ b/servers/camera_server.cpp @@ -0,0 +1,169 @@ +/*************************************************************************/ +/* camera_server.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 "camera_server.h" +#include "servers/camera/camera_feed.h" +#include "visual_server.h" + +//////////////////////////////////////////////////////// +// CameraServer + +void CameraServer::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_feed", "index"), &CameraServer::get_feed); + ClassDB::bind_method(D_METHOD("get_feed_count"), &CameraServer::get_feed_count); + ClassDB::bind_method(D_METHOD("feeds"), &CameraServer::get_feeds); + + ClassDB::bind_method(D_METHOD("add_feed", "feed"), &CameraServer::add_feed); + ClassDB::bind_method(D_METHOD("remove_feed", "feed"), &CameraServer::remove_feed); + + ADD_SIGNAL(MethodInfo("camera_feed_added", PropertyInfo(Variant::INT, "id"))); + ADD_SIGNAL(MethodInfo("camera_feed_removed", PropertyInfo(Variant::INT, "id"))); + + BIND_ENUM_CONSTANT(FEED_RGBA_IMAGE); + BIND_ENUM_CONSTANT(FEED_YCbCr_IMAGE); + BIND_ENUM_CONSTANT(FEED_Y_IMAGE); + BIND_ENUM_CONSTANT(FEED_CbCr_IMAGE); +}; + +CameraServer *CameraServer::singleton = NULL; + +CameraServer *CameraServer::get_singleton() { + return singleton; +}; + +int CameraServer::get_free_id() { + bool id_exists = true; + int newid = 0; + + // find a free id + while (id_exists) { + newid++; + id_exists = false; + for (int i = 0; i < feeds.size() && !id_exists; i++) { + if (feeds[i]->get_id() == newid) { + id_exists = true; + }; + }; + }; + + return newid; +}; + +int CameraServer::get_feed_index(int p_id) { + for (int i = 0; i < feeds.size(); i++) { + if (feeds[i]->get_id() == p_id) { + return i; + }; + }; + + return -1; +}; + +Ref<CameraFeed> CameraServer::get_feed_by_id(int p_id) { + int index = get_feed_index(p_id); + + if (index == -1) { + return NULL; + } else { + return feeds[index]; + } +}; + +void CameraServer::add_feed(const Ref<CameraFeed> &p_feed) { + // add our feed + feeds.push_back(p_feed); + +// record for debugging +#ifdef DEBUG_ENABLED + print_line("Registered camera " + p_feed->get_name() + " with id " + itos(p_feed->get_id()) + " position " + itos(p_feed->get_position()) + " at index " + itos(feeds.size() - 1)); +#endif + + // let whomever is interested know + emit_signal("camera_feed_added", p_feed->get_id()); +}; + +void CameraServer::remove_feed(const Ref<CameraFeed> &p_feed) { + for (int i = 0; i < feeds.size(); i++) { + if (feeds[i] == p_feed) { + int feed_id = p_feed->get_id(); + +// record for debugging +#ifdef DEBUG_ENABLED + print_line("Removed camera " + p_feed->get_name() + " with id " + itos(feed_id) + " position " + itos(p_feed->get_position())); +#endif + + // remove it from our array, if this results in our feed being unreferenced it will be destroyed + feeds.remove(i); + + // let whomever is interested know + emit_signal("camera_feed_removed", feed_id); + return; + }; + }; +}; + +Ref<CameraFeed> CameraServer::get_feed(int p_index) { + ERR_FAIL_INDEX_V(p_index, feeds.size(), NULL); + + return feeds[p_index]; +}; + +int CameraServer::get_feed_count() { + return feeds.size(); +}; + +Array CameraServer::get_feeds() { + Array return_feeds; + int cc = get_feed_count(); + return_feeds.resize(cc); + + for (int i = 0; i < feeds.size(); i++) { + return_feeds[i] = get_feed(i); + }; + + return return_feeds; +}; + +RID CameraServer::feed_texture(int p_id, CameraServer::FeedImage p_texture) { + int index = get_feed_index(p_id); + ERR_FAIL_COND_V(index == -1, RID()); + + Ref<CameraFeed> feed = get_feed(index); + + return feed->get_texture(p_texture); +}; + +CameraServer::CameraServer() { + singleton = this; +}; + +CameraServer::~CameraServer() { + singleton = NULL; +}; diff --git a/servers/camera_server.h b/servers/camera_server.h new file mode 100644 index 0000000000..d204142c7d --- /dev/null +++ b/servers/camera_server.h @@ -0,0 +1,96 @@ +/*************************************************************************/ +/* camera_server.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 CAMERA_SERVER_H +#define CAMERA_SERVER_H + +#include "core/object.h" +#include "core/os/thread_safe.h" +#include "core/reference.h" +#include "core/rid.h" +#include "core/variant.h" + +/** + @author Bastiaan Olij <mux213@gmail.com> + + The camera server is a singleton object that gives access to the various + camera feeds that can be used as the background for our environment. +**/ + +class CameraFeed; + +class CameraServer : public Object { + GDCLASS(CameraServer, Object); + _THREAD_SAFE_CLASS_ + +public: + enum FeedImage { + FEED_RGBA_IMAGE = 0, + FEED_YCbCr_IMAGE = 0, + FEED_Y_IMAGE = 0, + FEED_CbCr_IMAGE = 1, + FEED_IMAGES = 2 + }; + +private: +protected: + Vector<Ref<CameraFeed> > feeds; + + static CameraServer *singleton; + + static void _bind_methods(); + +public: + static CameraServer *get_singleton(); + + // Right now we identify our feed by it's ID when it's used in the background. + // May see if we can change this to purely relying on CameraFeed objects or by name. + int get_free_id(); + int get_feed_index(int p_id); + Ref<CameraFeed> get_feed_by_id(int p_id); + + // add and remove feeds + void add_feed(const Ref<CameraFeed> &p_feed); + void remove_feed(const Ref<CameraFeed> &p_feed); + + // get our feeds + Ref<CameraFeed> get_feed(int p_idx); + int get_feed_count(); + Array get_feeds(); + + RID feed_texture(int p_id, FeedImage p_texture); + + CameraServer(); + ~CameraServer(); +}; + +VARIANT_ENUM_CAST(CameraServer::FeedImage); + +#endif /* CAMERA_SERVER_H */ 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/register_server_types.cpp b/servers/register_server_types.cpp index f3394019f5..f7cec6a378 100644 --- a/servers/register_server_types.cpp +++ b/servers/register_server_types.cpp @@ -54,6 +54,8 @@ #include "audio/effects/audio_effect_stereo_enhance.h" #include "audio/effects/audio_stream_generator.h" #include "audio_server.h" +#include "camera/camera_feed.h" +#include "camera_server.h" #include "core/script_debugger_remote.h" #include "physics/physics_server_sw.h" #include "physics_2d/physics_2d_server_sw.h" @@ -114,6 +116,7 @@ void register_server_types() { ClassDB::register_virtual_class<PhysicsServer>(); ClassDB::register_virtual_class<Physics2DServer>(); ClassDB::register_class<ARVRServer>(); + ClassDB::register_class<CameraServer>(); shader_types = memnew(ShaderTypes); @@ -169,6 +172,8 @@ void register_server_types() { ClassDB::register_virtual_class<AudioEffectSpectrumAnalyzerInstance>(); } + ClassDB::register_class<CameraFeed>(); + ClassDB::register_virtual_class<Physics2DDirectBodyState>(); ClassDB::register_virtual_class<Physics2DDirectSpaceState>(); ClassDB::register_virtual_class<Physics2DShapeQueryResult>(); @@ -208,4 +213,5 @@ void register_server_singletons() { Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer", PhysicsServer::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("Physics2DServer", Physics2DServer::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("ARVRServer", ARVRServer::get_singleton())); + Engine::get_singleton()->add_singleton(Engine::Singleton("CameraServer", CameraServer::get_singleton())); } diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 31888261ec..31b468b50b 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -60,6 +60,7 @@ public: virtual void environment_set_bg_energy(RID p_env, float p_energy) = 0; virtual void environment_set_canvas_max_layer(RID p_env, int p_max_layer) = 0; virtual void environment_set_ambient_light(RID p_env, const Color &p_color, float p_energy = 1.0, float p_sky_contribution = 0.0) = 0; + virtual void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id) = 0; virtual void environment_set_dof_blur_near(RID p_env, bool p_enable, float p_distance, float p_transition, float p_far_amount, VS::EnvironmentDOFBlurQuality p_quality) = 0; virtual void environment_set_dof_blur_far(RID p_env, bool p_enable, float p_distance, float p_transition, float p_far_amount, VS::EnvironmentDOFBlurQuality p_quality) = 0; @@ -204,6 +205,7 @@ public: virtual uint32_t texture_get_height(RID p_texture) const = 0; virtual uint32_t texture_get_depth(RID p_texture) const = 0; virtual void texture_set_size_override(RID p_texture, int p_width, int p_height, int p_depth_3d) = 0; + virtual void texture_bind(RID p_texture, uint32_t p_texture_no) = 0; virtual void texture_set_path(RID p_texture, const String &p_path) = 0; virtual String texture_get_path(RID p_texture) const = 0; @@ -1103,7 +1105,7 @@ public: virtual RasterizerCanvas *get_canvas() = 0; virtual RasterizerScene *get_scene() = 0; - virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale) = 0; + virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true) = 0; virtual void initialize() = 0; virtual void begin_frame(double frame_step) = 0; diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index 6efd05593e..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; } @@ -3993,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) @@ -4322,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; } @@ -4359,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/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index 310aa16130..d45bda72b7 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -153,10 +153,10 @@ int VisualServerRaster::get_render_info(RenderInfo p_info) { /* TESTING */ -void VisualServerRaster::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale) { +void VisualServerRaster::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter) { redraw_request(); - VSG::rasterizer->set_boot_image(p_image, p_color, p_scale); + VSG::rasterizer->set_boot_image(p_image, p_color, p_scale, p_use_filter); } void VisualServerRaster::set_default_clear_color(const Color &p_color) { VSG::viewport->set_default_clear_color(p_color); diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 921d55556d..f37d651dee 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -159,6 +159,7 @@ public: BIND1RC(uint32_t, texture_get_height, RID) BIND1RC(uint32_t, texture_get_depth, RID) BIND4(texture_set_size_override, RID, int, int, int) + BIND2(texture_bind, RID, uint32_t) BIND3(texture_set_detect_3d_callback, RID, TextureDetectCallback, void *) BIND3(texture_set_detect_srgb_callback, RID, TextureDetectCallback, void *) @@ -503,6 +504,7 @@ public: BIND2(environment_set_bg_energy, RID, float) BIND2(environment_set_canvas_max_layer, RID, int) BIND4(environment_set_ambient_light, RID, const Color &, float, float) + BIND2(environment_set_camera_feed_id, RID, int) BIND7(environment_set_ssr, RID, bool, int, float, float, float, bool) BIND13(environment_set_ssao, RID, bool, float, float, float, float, float, float, float, const Color &, EnvironmentSSAOQuality, EnvironmentSSAOBlur, float) @@ -685,7 +687,7 @@ public: /* TESTING */ - virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale); + virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true); virtual void set_default_clear_color(const Color &p_color); virtual bool has_feature(Features p_feature) const; diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index cd24deb60c..24e50eb99e 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -95,6 +95,7 @@ public: FUNC1RC(uint32_t, texture_get_height, RID) FUNC1RC(uint32_t, texture_get_depth, RID) FUNC4(texture_set_size_override, RID, int, int, int) + FUNC2(texture_bind, RID, uint32_t) FUNC3(texture_set_detect_3d_callback, RID, TextureDetectCallback, void *) FUNC3(texture_set_detect_srgb_callback, RID, TextureDetectCallback, void *) @@ -430,6 +431,7 @@ public: FUNC2(environment_set_bg_energy, RID, float) FUNC2(environment_set_canvas_max_layer, RID, int) FUNC4(environment_set_ambient_light, RID, const Color &, float, float) + FUNC2(environment_set_camera_feed_id, RID, int) FUNC7(environment_set_ssr, RID, bool, int, float, float, float, bool) FUNC13(environment_set_ssao, RID, bool, float, float, float, float, float, float, float, const Color &, EnvironmentSSAOQuality, EnvironmentSSAOBlur, float) @@ -602,7 +604,7 @@ public: return visual_server->get_render_info(p_info); } - FUNC3(set_boot_image, const Ref<Image> &, const Color &, bool) + FUNC4(set_boot_image, const Ref<Image> &, const Color &, bool, bool) FUNC1(set_default_clear_color, const Color &) FUNC0R(RID, get_test_cube) diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index 0fe00ad61a..60be63fd24 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -1676,6 +1676,7 @@ void VisualServer::_bind_methods() { ClassDB::bind_method(D_METHOD("texture_set_path", "texture", "path"), &VisualServer::texture_set_path); ClassDB::bind_method(D_METHOD("texture_get_path", "texture"), &VisualServer::texture_get_path); ClassDB::bind_method(D_METHOD("texture_set_shrink_all_x2_on_set_data", "shrink"), &VisualServer::texture_set_shrink_all_x2_on_set_data); + ClassDB::bind_method(D_METHOD("texture_bind", "texture", "number"), &VisualServer::texture_bind); ClassDB::bind_method(D_METHOD("texture_debug_usage"), &VisualServer::_texture_debug_usage_bind); ClassDB::bind_method(D_METHOD("textures_keep_original", "enable"), &VisualServer::textures_keep_original); @@ -2047,7 +2048,7 @@ void VisualServer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_test_texture"), &VisualServer::get_test_texture); ClassDB::bind_method(D_METHOD("get_white_texture"), &VisualServer::get_white_texture); - ClassDB::bind_method(D_METHOD("set_boot_image", "image", "color", "scale"), &VisualServer::set_boot_image); + ClassDB::bind_method(D_METHOD("set_boot_image", "image", "color", "scale", "use_filter"), &VisualServer::set_boot_image, DEFVAL(true)); ClassDB::bind_method(D_METHOD("set_default_clear_color", "color"), &VisualServer::set_default_clear_color); ClassDB::bind_method(D_METHOD("has_feature", "feature"), &VisualServer::has_feature); diff --git a/servers/visual_server.h b/servers/visual_server.h index 01be996bfc..a84d395e3f 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -140,6 +140,7 @@ public: virtual uint32_t texture_get_height(RID p_texture) const = 0; virtual uint32_t texture_get_depth(RID p_texture) const = 0; virtual void texture_set_size_override(RID p_texture, int p_width, int p_height, int p_depth_3d) = 0; + virtual void texture_bind(RID p_texture, uint32_t p_texture_no) = 0; virtual void texture_set_path(RID p_texture, const String &p_path) = 0; virtual String texture_get_path(RID p_texture) const = 0; @@ -707,6 +708,7 @@ public: ENV_BG_COLOR_SKY, ENV_BG_CANVAS, ENV_BG_KEEP, + ENV_BG_CAMERA_FEED, ENV_BG_MAX }; @@ -718,6 +720,7 @@ public: virtual void environment_set_bg_energy(RID p_env, float p_energy) = 0; virtual void environment_set_canvas_max_layer(RID p_env, int p_max_layer) = 0; virtual void environment_set_ambient_light(RID p_env, const Color &p_color, float p_energy = 1.0, float p_sky_contribution = 0.0) = 0; + virtual void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id) = 0; //set default SSAO options //set default SSR options @@ -1029,7 +1032,7 @@ public: virtual void mesh_add_surface_from_mesh_data(RID p_mesh, const Geometry::MeshData &p_mesh_data); virtual void mesh_add_surface_from_planes(RID p_mesh, const PoolVector<Plane> &p_planes); - virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale) = 0; + virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true) = 0; virtual void set_default_clear_color(const Color &p_color) = 0; enum Features { |