2017-03-05 14:47:28 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* visual_server_viewport.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2017-03-05 14:47:28 +00:00
|
|
|
/*************************************************************************/
|
2022-01-13 08:45:09 +00:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-03-05 14:47:28 +00:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2022-07-25 10:33:41 +00:00
|
|
|
#ifndef VISUAL_SERVER_VIEWPORT_H
|
|
|
|
#define VISUAL_SERVER_VIEWPORT_H
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/self_list.h"
|
2016-10-03 19:33:42 +00:00
|
|
|
#include "rasterizer.h"
|
2017-04-23 12:10:41 +00:00
|
|
|
#include "servers/arvr/arvr_interface.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "servers/visual_server.h"
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
class VisualServerViewport {
|
2016-10-03 19:33:42 +00:00
|
|
|
public:
|
|
|
|
struct CanvasBase : public RID_Data {
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Viewport : public RID_Data {
|
|
|
|
RID self;
|
|
|
|
RID parent;
|
|
|
|
|
2017-04-23 12:10:41 +00:00
|
|
|
bool use_arvr; /* use arvr interface to override camera positioning and projection matrices and control output */
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
Size2i size;
|
|
|
|
RID camera;
|
|
|
|
RID scenario;
|
|
|
|
|
|
|
|
VS::ViewportUpdateMode update_mode;
|
|
|
|
RID render_target;
|
|
|
|
RID render_target_texture;
|
|
|
|
|
|
|
|
int viewport_to_screen;
|
|
|
|
Rect2 viewport_to_screen_rect;
|
2019-05-08 18:25:34 +00:00
|
|
|
bool viewport_render_direct_to_screen;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
bool hide_scenario;
|
|
|
|
bool hide_canvas;
|
|
|
|
bool disable_environment;
|
2016-10-05 04:26:35 +00:00
|
|
|
bool disable_3d;
|
2017-06-09 03:23:50 +00:00
|
|
|
bool disable_3d_by_usage;
|
2018-04-30 12:30:11 +00:00
|
|
|
bool keep_3d_linear;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2016-11-10 02:55:06 +00:00
|
|
|
RID shadow_atlas;
|
|
|
|
int shadow_atlas_size;
|
|
|
|
|
2017-06-11 18:52:03 +00:00
|
|
|
int render_info[VS::VIEWPORT_RENDER_INFO_MAX];
|
|
|
|
VS::ViewportDebugDraw debug_draw;
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
VS::ViewportClearMode clear_mode;
|
|
|
|
|
2017-10-21 07:06:10 +00:00
|
|
|
bool transparent_bg;
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
struct CanvasKey {
|
2018-10-30 20:53:00 +00:00
|
|
|
int64_t stacking;
|
2016-10-03 19:33:42 +00:00
|
|
|
RID canvas;
|
2017-03-05 15:44:50 +00:00
|
|
|
bool operator<(const CanvasKey &p_canvas) const {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (stacking == p_canvas.stacking) {
|
2018-10-30 20:53:00 +00:00
|
|
|
return canvas < p_canvas.canvas;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2018-10-30 20:53:00 +00:00
|
|
|
return stacking < p_canvas.stacking;
|
|
|
|
}
|
|
|
|
CanvasKey() {
|
|
|
|
stacking = 0;
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2018-10-30 20:53:00 +00:00
|
|
|
CanvasKey(const RID &p_canvas, int p_layer, int p_sublayer) {
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas = p_canvas;
|
2019-03-05 20:18:46 +00:00
|
|
|
int64_t sign = p_layer < 0 ? -1 : 1;
|
|
|
|
stacking = sign * (((int64_t)ABS(p_layer)) << 32) + p_sublayer;
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2018-10-30 20:53:00 +00:00
|
|
|
int get_layer() const { return stacking >> 32; }
|
2016-10-03 19:33:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CanvasData {
|
|
|
|
CanvasBase *canvas;
|
2017-01-11 03:52:51 +00:00
|
|
|
Transform2D transform;
|
2016-10-03 19:33:42 +00:00
|
|
|
int layer;
|
2018-10-30 20:53:00 +00:00
|
|
|
int sublayer;
|
2016-10-03 19:33:42 +00:00
|
|
|
};
|
|
|
|
|
2017-01-11 03:52:51 +00:00
|
|
|
Transform2D global_transform;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Map<RID, CanvasData> canvas_map;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
Viewport() {
|
2017-03-05 15:44:50 +00:00
|
|
|
update_mode = VS::VIEWPORT_UPDATE_WHEN_VISIBLE;
|
|
|
|
clear_mode = VS::VIEWPORT_CLEAR_ALWAYS;
|
2017-10-21 07:06:10 +00:00
|
|
|
transparent_bg = false;
|
2017-03-05 15:44:50 +00:00
|
|
|
disable_environment = false;
|
|
|
|
viewport_to_screen = 0;
|
|
|
|
shadow_atlas_size = 0;
|
|
|
|
disable_3d = false;
|
2017-06-09 03:23:50 +00:00
|
|
|
disable_3d_by_usage = false;
|
2018-04-30 12:30:11 +00:00
|
|
|
keep_3d_linear = false;
|
2017-06-11 18:52:03 +00:00
|
|
|
debug_draw = VS::VIEWPORT_DEBUG_DRAW_DISABLED;
|
|
|
|
for (int i = 0; i < VS::VIEWPORT_RENDER_INFO_MAX; i++) {
|
|
|
|
render_info[i] = 0;
|
|
|
|
}
|
2017-04-23 12:10:41 +00:00
|
|
|
use_arvr = false;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
mutable RID_Owner<Viewport> viewport_owner;
|
2016-10-05 04:26:35 +00:00
|
|
|
|
|
|
|
struct ViewportSort {
|
2017-03-05 15:44:50 +00:00
|
|
|
_FORCE_INLINE_ bool operator()(const Viewport *p_left, const Viewport *p_right) const {
|
|
|
|
bool left_to_screen = p_left->viewport_to_screen_rect.size != Size2();
|
|
|
|
bool right_to_screen = p_right->viewport_to_screen_rect.size != Size2();
|
2016-10-05 04:26:35 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (left_to_screen == right_to_screen) {
|
|
|
|
return p_left->parent == p_right->self;
|
2016-10-05 04:26:35 +00:00
|
|
|
}
|
2019-06-26 13:08:25 +00:00
|
|
|
return right_to_screen;
|
2016-10-05 04:26:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector<Viewport *> active_viewports;
|
2016-10-05 04:26:35 +00:00
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
private:
|
2016-10-05 04:26:35 +00:00
|
|
|
Color clear_color;
|
2019-03-30 13:03:49 +00:00
|
|
|
void _draw_3d(Viewport *p_viewport, ARVRInterface::Eyes p_eye);
|
2017-04-23 12:10:41 +00:00
|
|
|
void _draw_viewport(Viewport *p_viewport, ARVRInterface::Eyes p_eye = ARVRInterface::EYE_MONO);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2016-10-03 19:33:42 +00:00
|
|
|
RID viewport_create();
|
|
|
|
|
2017-04-23 12:10:41 +00:00
|
|
|
void viewport_set_use_arvr(RID p_viewport, bool p_use_arvr);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void viewport_set_size(RID p_viewport, int p_width, int p_height);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void viewport_attach_to_screen(RID p_viewport, const Rect2 &p_rect = Rect2(), int p_screen = 0);
|
2019-05-08 18:25:34 +00:00
|
|
|
void viewport_set_render_direct_to_screen(RID p_viewport, bool p_enable);
|
2016-10-03 19:33:42 +00:00
|
|
|
void viewport_detach(RID p_viewport);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void viewport_set_active(RID p_viewport, bool p_active);
|
|
|
|
void viewport_set_parent_viewport(RID p_viewport, RID p_parent_viewport);
|
|
|
|
void viewport_set_update_mode(RID p_viewport, VS::ViewportUpdateMode p_mode);
|
|
|
|
void viewport_set_vflip(RID p_viewport, bool p_enable);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void viewport_set_clear_mode(RID p_viewport, VS::ViewportClearMode p_clear_mode);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RID viewport_get_texture(RID p_viewport) const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void viewport_set_hide_scenario(RID p_viewport, bool p_hide);
|
|
|
|
void viewport_set_hide_canvas(RID p_viewport, bool p_hide);
|
|
|
|
void viewport_set_disable_environment(RID p_viewport, bool p_disable);
|
|
|
|
void viewport_set_disable_3d(RID p_viewport, bool p_disable);
|
2018-04-30 12:30:11 +00:00
|
|
|
void viewport_set_keep_3d_linear(RID p_viewport, bool p_keep_3d_linear);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void viewport_attach_camera(RID p_viewport, RID p_camera);
|
|
|
|
void viewport_set_scenario(RID p_viewport, RID p_scenario);
|
|
|
|
void viewport_attach_canvas(RID p_viewport, RID p_canvas);
|
|
|
|
void viewport_remove_canvas(RID p_viewport, RID p_canvas);
|
|
|
|
void viewport_set_canvas_transform(RID p_viewport, RID p_canvas, const Transform2D &p_offset);
|
|
|
|
void viewport_set_transparent_background(RID p_viewport, bool p_enabled);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void viewport_set_global_canvas_transform(RID p_viewport, const Transform2D &p_transform);
|
2018-10-30 20:53:00 +00:00
|
|
|
void viewport_set_canvas_stacking(RID p_viewport, RID p_canvas, int p_layer, int p_sublayer);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void viewport_set_shadow_atlas_size(RID p_viewport, int p_size);
|
|
|
|
void viewport_set_shadow_atlas_quadrant_subdivision(RID p_viewport, int p_quadrant, int p_subdiv);
|
2016-11-10 02:55:06 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void viewport_set_msaa(RID p_viewport, VS::ViewportMSAA p_msaa);
|
2020-08-21 22:15:50 +00:00
|
|
|
void viewport_set_use_fxaa(RID p_viewport, bool p_fxaa);
|
2020-10-20 16:58:07 +00:00
|
|
|
void viewport_set_use_debanding(RID p_viewport, bool p_debanding);
|
2021-03-27 17:58:12 +00:00
|
|
|
void viewport_set_sharpen_intensity(RID p_viewport, float p_intensity);
|
2017-03-05 15:44:50 +00:00
|
|
|
void viewport_set_hdr(RID p_viewport, bool p_enabled);
|
2021-08-16 01:16:01 +00:00
|
|
|
void viewport_set_use_32_bpc_depth(RID p_viewport, bool p_enabled);
|
2017-06-09 03:23:50 +00:00
|
|
|
void viewport_set_usage(RID p_viewport, VS::ViewportUsage p_usage);
|
2017-01-02 01:16:52 +00:00
|
|
|
|
2017-06-11 18:52:03 +00:00
|
|
|
virtual int viewport_get_render_info(RID p_viewport, VS::ViewportRenderInfo p_info);
|
|
|
|
virtual void viewport_set_debug_draw(RID p_viewport, VS::ViewportDebugDraw p_draw);
|
|
|
|
|
2018-07-29 18:09:42 +00:00
|
|
|
void set_default_clear_color(const Color &p_color);
|
2016-10-03 19:33:42 +00:00
|
|
|
void draw_viewports();
|
|
|
|
|
|
|
|
bool free(RID p_rid);
|
|
|
|
|
|
|
|
VisualServerViewport();
|
2018-10-02 10:07:44 +00:00
|
|
|
virtual ~VisualServerViewport() {}
|
2016-10-03 19:33:42 +00:00
|
|
|
};
|
|
|
|
|
2022-07-25 10:33:41 +00:00
|
|
|
#endif // VISUAL_SERVER_VIEWPORT_H
|