Removed the camera server.

This commit is contained in:
Relintai 2022-03-16 02:16:15 +01:00
parent baba212b6d
commit 938f72432e
20 changed files with 1 additions and 935 deletions

View File

@ -61,7 +61,6 @@ public:
void environment_set_bg_energy(RID p_env, float p_energy) {}
void environment_set_canvas_max_layer(RID p_env, int p_max_layer) {}
void environment_set_ambient_light(RID p_env, const Color &p_color, float p_energy = 1.0, float p_sky_contribution = 0.0) {}
void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id){};
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) {}
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) {}

View File

@ -36,7 +36,6 @@
#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
@ -801,13 +800,6 @@ void RasterizerSceneGLES2::environment_set_ambient_light(RID p_env, const Color
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, VS::EnvironmentDOFBlurQuality p_quality) {
Environment *env = environment_owner.getornull(p_env);
ERR_FAIL_COND(!env);
@ -3318,7 +3310,6 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const
// clear color
Color clear_color(0, 0, 0, 1);
Ref<CameraFeed> feed;
if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
clear_color = Color(0, 0, 0, 0);
@ -3332,7 +3323,6 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const
clear_color = env->bg_color;
storage->frame.clear_request = false;
} else if (env->bg_mode == 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;
@ -3376,66 +3366,6 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const
env_radiance_tex = sky->radiance;
}
} break;
case 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(VS::ARRAY_VERTEX);
glDisableVertexAttribArray(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 VS::ENV_BG_CANVAS: {
// use screen copy as background
_copy_texture_to_buffer(storage->frame.current_rt->copy_screen_effect.color, current_fb);

View File

@ -362,8 +362,6 @@ public:
float bg_energy;
float sky_ambient;
int camera_feed_id;
Color ambient_color;
float ambient_energy;
float ambient_sky_contribution;
@ -421,7 +419,6 @@ public:
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),
@ -479,8 +476,7 @@ public:
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, 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, VS::EnvironmentDOFBlurQuality p_quality);

View File

@ -64,7 +64,6 @@
#include "scene/resources/packed_scene.h"
#include "servers/arvr_server.h"
#include "servers/audio_server.h"
#include "servers/camera_server.h"
#include "servers/navigation_2d_server.h"
#include "servers/navigation_server.h"
#include "servers/physics_2d_server.h"
@ -106,7 +105,6 @@ static MessageQueue *message_queue = nullptr;
// Initialized in setup2()
static AudioServer *audio_server = nullptr;
static CameraServer *camera_server = nullptr;
static ARVRServer *arvr_server = nullptr;
static PhysicsServer *physics_server = nullptr;
static Physics2DServer *physics_2d_server = nullptr;
@ -1535,8 +1533,6 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
}
}
camera_server = CameraServer::create();
initialize_physics();
initialize_navigation_server();
register_server_singletons();
@ -2446,10 +2442,6 @@ void Main::cleanup(bool p_force) {
memdelete(audio_server);
}
if (camera_server) {
memdelete(camera_server);
}
OS::get_singleton()->finalize();
finalize_physics();
finalize_navigation_server();

View File

@ -612,7 +612,6 @@ void register_scene_types() {
ClassDB::register_class<GradientTexture2D>();
ClassDB::register_class<ProxyTexture>();
ClassDB::register_class<AnimatedTexture>();
ClassDB::register_class<CameraTexture>();
ClassDB::register_class<ExternalTexture>();
ClassDB::register_class<CubeMap>();
ClassDB::register_virtual_class<TextureLayered>();

View File

@ -102,11 +102,6 @@ void Environment::set_ambient_light_sky_contribution(float p_energy) {
VS::get_singleton()->environment_set_ambient_light(environment, ambient_color, ambient_energy, ambient_sky_contribution);
}
void Environment::set_camera_feed_id(int p_camera_feed_id) {
camera_feed_id = p_camera_feed_id;
VS::get_singleton()->environment_set_camera_feed_id(environment, camera_feed_id);
};
Environment::BGMode Environment::get_background() const {
return bg_mode;
}
@ -149,9 +144,6 @@ float Environment::get_ambient_light_energy() const {
float Environment::get_ambient_light_sky_contribution() const {
return ambient_sky_contribution;
}
int Environment::get_camera_feed_id() const {
return camera_feed_id;
}
void Environment::set_tonemapper(ToneMapper p_tone_mapper) {
tone_mapper = p_tone_mapper;
@ -281,12 +273,6 @@ void Environment::_validate_property(PropertyInfo &property) const {
}
}
if (property.name == "background_camera_feed_id") {
if (bg_mode != BG_CAMERA_FEED) {
property.usage = PROPERTY_USAGE_NOEDITOR;
}
}
static const char *hide_prefixes[] = {
"fog_",
"auto_exposure_",
@ -813,7 +799,6 @@ void Environment::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_ambient_light_color", "color"), &Environment::set_ambient_light_color);
ClassDB::bind_method(D_METHOD("set_ambient_light_energy", "energy"), &Environment::set_ambient_light_energy);
ClassDB::bind_method(D_METHOD("set_ambient_light_sky_contribution", "energy"), &Environment::set_ambient_light_sky_contribution);
ClassDB::bind_method(D_METHOD("set_camera_feed_id", "camera_feed_id"), &Environment::set_camera_feed_id);
ClassDB::bind_method(D_METHOD("get_background"), &Environment::get_background);
ClassDB::bind_method(D_METHOD("get_sky"), &Environment::get_sky);
@ -827,7 +812,6 @@ void Environment::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_ambient_light_color"), &Environment::get_ambient_light_color);
ClassDB::bind_method(D_METHOD("get_ambient_light_energy"), &Environment::get_ambient_light_energy);
ClassDB::bind_method(D_METHOD("get_ambient_light_sky_contribution"), &Environment::get_ambient_light_sky_contribution);
ClassDB::bind_method(D_METHOD("get_camera_feed_id"), &Environment::get_camera_feed_id);
ADD_GROUP("Background", "background_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "background_mode", PROPERTY_HINT_ENUM, "Clear Color,Custom Color,Sky,Color+Sky,Canvas,Keep,Camera Feed"), "set_background", "get_background");
@ -841,7 +825,6 @@ void Environment::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "background_color"), "set_bg_color", "get_bg_color");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "background_energy", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_bg_energy", "get_bg_energy");
ADD_PROPERTY(PropertyInfo(Variant::INT, "background_canvas_max_layer", PROPERTY_HINT_RANGE, "-1000,1000,1"), "set_canvas_max_layer", "get_canvas_max_layer");
ADD_PROPERTY(PropertyInfo(Variant::INT, "background_camera_feed_id", PROPERTY_HINT_RANGE, "1,10,1"), "set_camera_feed_id", "get_camera_feed_id");
ADD_GROUP("Ambient Light", "ambient_light_");
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "ambient_light_color"), "set_ambient_light_color", "get_ambient_light_color");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "ambient_light_energy", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_ambient_light_energy", "get_ambient_light_energy");
@ -1187,7 +1170,6 @@ Environment::Environment() :
ambient_energy = 1.0;
//ambient_sky_contribution = 1.0;
set_ambient_light_sky_contribution(1.0);
set_camera_feed_id(1);
tone_mapper = TONE_MAPPER_LINEAR;
tonemap_exposure = 1.0;

View File

@ -99,7 +99,6 @@ private:
Color ambient_color;
float ambient_energy;
float ambient_sky_contribution;
int camera_feed_id;
ToneMapper tone_mapper;
float tonemap_exposure;
@ -195,7 +194,6 @@ public:
void set_ambient_light_color(const Color &p_color);
void set_ambient_light_energy(float p_energy);
void set_ambient_light_sky_contribution(float p_energy);
void set_camera_feed_id(int p_camera_feed_id);
BGMode get_background() const;
Ref<Sky> get_sky() const;
@ -209,7 +207,6 @@ public:
Color get_ambient_light_color() const;
float get_ambient_light_energy() const;
float get_ambient_light_sky_contribution() const;
int get_camera_feed_id() const;
void set_tonemapper(ToneMapper p_tone_mapper);
ToneMapper get_tonemapper() const;

View File

@ -37,7 +37,6 @@
#include "core/os/os.h"
#include "mesh.h"
#include "scene/resources/bit_map.h"
#include "servers/camera/camera_feed.h"
Size2 Texture::get_size() const {
return Size2(get_width(), get_height());
@ -2752,110 +2751,6 @@ String ResourceFormatLoaderTextureLayered::get_resource_type(const String &p_pat
return "";
}
void CameraTexture::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_camera_feed_id", "feed_id"), &CameraTexture::set_camera_feed_id);
ClassDB::bind_method(D_METHOD("get_camera_feed_id"), &CameraTexture::get_camera_feed_id);
ClassDB::bind_method(D_METHOD("set_which_feed", "which_feed"), &CameraTexture::set_which_feed);
ClassDB::bind_method(D_METHOD("get_which_feed"), &CameraTexture::get_which_feed);
ClassDB::bind_method(D_METHOD("set_camera_active", "active"), &CameraTexture::set_camera_active);
ClassDB::bind_method(D_METHOD("get_camera_active"), &CameraTexture::get_camera_active);
ADD_PROPERTY(PropertyInfo(Variant::INT, "camera_feed_id"), "set_camera_feed_id", "get_camera_feed_id");
ADD_PROPERTY(PropertyInfo(Variant::INT, "which_feed"), "set_which_feed", "get_which_feed");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "camera_is_active"), "set_camera_active", "get_camera_active");
}
int CameraTexture::get_width() const {
Ref<CameraFeed> feed = CameraServer::get_singleton()->get_feed_by_id(camera_feed_id);
if (feed.is_valid()) {
return feed->get_base_width();
} else {
return 0;
}
}
int CameraTexture::get_height() const {
Ref<CameraFeed> feed = CameraServer::get_singleton()->get_feed_by_id(camera_feed_id);
if (feed.is_valid()) {
return feed->get_base_height();
} else {
return 0;
}
}
bool CameraTexture::has_alpha() const {
return false;
}
RID CameraTexture::get_rid() const {
Ref<CameraFeed> feed = CameraServer::get_singleton()->get_feed_by_id(camera_feed_id);
if (feed.is_valid()) {
return feed->get_texture(which_feed);
} else {
return RID();
}
}
void CameraTexture::set_flags(uint32_t p_flags) {
// not supported
}
uint32_t CameraTexture::get_flags() const {
// not supported
return 0;
}
Ref<Image> CameraTexture::get_data() const {
// not (yet) supported
return Ref<Image>();
}
void CameraTexture::set_camera_feed_id(int p_new_id) {
camera_feed_id = p_new_id;
_change_notify();
}
int CameraTexture::get_camera_feed_id() const {
return camera_feed_id;
}
void CameraTexture::set_which_feed(CameraServer::FeedImage p_which) {
which_feed = p_which;
_change_notify();
}
CameraServer::FeedImage CameraTexture::get_which_feed() const {
return which_feed;
}
void CameraTexture::set_camera_active(bool p_active) {
Ref<CameraFeed> feed = CameraServer::get_singleton()->get_feed_by_id(camera_feed_id);
if (feed.is_valid()) {
feed->set_active(p_active);
_change_notify();
}
}
bool CameraTexture::get_camera_active() const {
Ref<CameraFeed> feed = CameraServer::get_singleton()->get_feed_by_id(camera_feed_id);
if (feed.is_valid()) {
return feed->is_active();
} else {
return false;
}
}
CameraTexture::CameraTexture() {
camera_feed_id = 0;
which_feed = CameraServer::FEED_RGBA_IMAGE;
}
CameraTexture::~CameraTexture() {
// nothing to do here yet
}
void ExternalTexture::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_size", "size"), &ExternalTexture::set_size);
ClassDB::bind_method(D_METHOD("get_external_texture_id"), &ExternalTexture::get_external_texture_id);

View File

@ -39,7 +39,6 @@
#include "core/resource.h"
#include "scene/resources/curve.h"
#include "scene/resources/gradient.h"
#include "servers/camera_server.h"
#include "servers/visual_server.h"
class Texture : public Resource {
@ -831,40 +830,6 @@ public:
~AnimatedTexture();
};
class CameraTexture : public Texture {
GDCLASS(CameraTexture, Texture);
private:
int camera_feed_id;
CameraServer::FeedImage which_feed;
protected:
static void _bind_methods();
public:
virtual int get_width() const;
virtual int get_height() const;
virtual RID get_rid() const;
virtual bool has_alpha() const;
virtual void set_flags(uint32_t p_flags);
virtual uint32_t get_flags() const;
virtual Ref<Image> get_data() const;
void set_camera_feed_id(int p_new_id);
int get_camera_feed_id() const;
void set_which_feed(CameraServer::FeedImage p_which);
CameraServer::FeedImage get_which_feed() const;
void set_camera_active(bool p_active);
bool get_camera_active() const;
CameraTexture();
~CameraTexture();
};
// External textures as defined by https://www.khronos.org/registry/OpenGL/extensions/OES/OES_EGL_image_external.txt
class ExternalTexture : public Texture {
GDCLASS(ExternalTexture, Texture);

View File

@ -56,7 +56,6 @@ 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");

View File

@ -1,5 +0,0 @@
#!/usr/bin/env python
Import("env")
env.add_source_files(env.servers_sources, "*.cpp")

View File

@ -1,270 +0,0 @@
/*************************************************************************/
/* camera_feed.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 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] = RID_PRIME(vs->texture_create()); // also used for RGBA
texture[CameraServer::FEED_CBCR_IMAGE] = RID_PRIME(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] = RID_PRIME(vs->texture_create()); // also used for RGBA
texture[CameraServer::FEED_CBCR_IMAGE] = RID_PRIME(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(const Ref<Image> &p_rgb_img) {
ERR_FAIL_COND(p_rgb_img.is_null());
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(const Ref<Image> &p_ycbcr_img) {
ERR_FAIL_COND(p_ycbcr_img.is_null());
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(const Ref<Image> &p_y_img, const Ref<Image> &p_cbcr_img) {
ERR_FAIL_COND(p_y_img.is_null());
ERR_FAIL_COND(p_cbcr_img.is_null());
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
}

View File

@ -1,115 +0,0 @@
/*************************************************************************/
/* camera_feed.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 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(const Ref<Image> &p_rgb_img);
void set_YCbCr_img(const Ref<Image> &p_ycbcr_img);
void set_YCbCr_imgs(const Ref<Image> &p_y_img, const 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 */

View File

@ -1,173 +0,0 @@
/*************************************************************************/
/* camera_server.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 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
CameraServer::CreateFunc CameraServer::create_func = nullptr;
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 = nullptr;
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 nullptr;
} else {
return feeds[index];
}
};
void CameraServer::add_feed(const Ref<CameraFeed> &p_feed) {
ERR_FAIL_COND(p_feed.is_null());
// 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(), nullptr);
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 = nullptr;
};

View File

@ -1,115 +0,0 @@
/*************************************************************************/
/* camera_server.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 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
};
typedef CameraServer *(*CreateFunc)();
private:
protected:
static CreateFunc create_func;
Vector<Ref<CameraFeed>> feeds;
static CameraServer *singleton;
static void _bind_methods();
template <class T>
static CameraServer *_create_builtin() {
return memnew(T);
}
public:
static CameraServer *get_singleton();
template <class T>
static void make_default() {
create_func = _create_builtin<T>;
}
static CameraServer *create() {
CameraServer *server = create_func ? create_func() : memnew(CameraServer);
return server;
};
// 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_index);
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 */

View File

@ -55,8 +55,6 @@
#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 "navigation_2d_server.h"
#include "navigation_server.h"
#include "physics/physics_server_sw.h"
@ -117,7 +115,6 @@ void register_server_types() {
ClassDB::register_virtual_class<NavigationServer>();
ClassDB::register_virtual_class<Navigation2DServer>();
ClassDB::register_class<ARVRServer>();
ClassDB::register_class<CameraServer>();
shader_types = memnew(ShaderTypes);
@ -175,8 +172,6 @@ void register_server_types() {
ClassDB::register_class<AudioEffectCapture>();
}
ClassDB::register_class<CameraFeed>();
ClassDB::register_virtual_class<Physics2DDirectBodyState>();
ClassDB::register_virtual_class<Physics2DDirectSpaceState>();
ClassDB::register_class<Physics2DTestMotionResult>();
@ -216,5 +211,4 @@ void register_server_singletons() {
Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer", NavigationServer::get_singleton_mut()));
Engine::get_singleton()->add_singleton(Engine::Singleton("Navigation2DServer", Navigation2DServer::get_singleton_mut()));
Engine::get_singleton()->add_singleton(Engine::Singleton("ARVRServer", ARVRServer::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("CameraServer", CameraServer::get_singleton()));
}

View File

@ -61,7 +61,6 @@ 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;

View File

@ -442,7 +442,6 @@ 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)

View File

@ -365,7 +365,6 @@ 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)

View File

@ -666,7 +666,6 @@ 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