2017-03-05 22:47:28 +08:00
|
|
|
/*************************************************************************/
|
2020-12-05 02:26:24 +08:00
|
|
|
/* renderer_viewport.h */
|
2017-03-05 22:47:28 +08:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 20:16:55 +08:00
|
|
|
/* https://godotengine.org */
|
2017-03-05 22:47:28 +08:00
|
|
|
/*************************************************************************/
|
2020-01-01 18:16:22 +08:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-03-05 22:47:28 +08: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-05 07:50:27 +08:00
|
|
|
|
2016-10-04 03:33:42 +08:00
|
|
|
#ifndef VISUALSERVERVIEWPORT_H
|
|
|
|
#define VISUALSERVERVIEWPORT_H
|
|
|
|
|
2020-11-08 06:33:38 +08:00
|
|
|
#include "core/templates/rid_owner.h"
|
|
|
|
#include "core/templates/self_list.h"
|
2020-12-05 02:26:24 +08:00
|
|
|
#include "renderer_compositor.h"
|
2020-03-28 02:21:27 +08:00
|
|
|
#include "servers/rendering_server.h"
|
2020-04-08 22:47:36 +08:00
|
|
|
#include "servers/xr/xr_interface.h"
|
2016-10-04 03:33:42 +08:00
|
|
|
|
2020-12-05 02:26:24 +08:00
|
|
|
class RendererViewport {
|
2016-10-04 03:33:42 +08:00
|
|
|
public:
|
2019-06-10 23:38:51 +08:00
|
|
|
struct CanvasBase {
|
2016-10-04 03:33:42 +08:00
|
|
|
};
|
|
|
|
|
2019-06-10 23:38:51 +08:00
|
|
|
struct Viewport {
|
2016-10-04 03:33:42 +08:00
|
|
|
RID self;
|
|
|
|
RID parent;
|
|
|
|
|
2020-04-08 22:47:36 +08:00
|
|
|
bool use_xr; /* use xr interface to override camera positioning and projection matrices and control output */
|
2017-04-23 20:10:41 +08:00
|
|
|
|
2016-10-04 03:33:42 +08:00
|
|
|
Size2i size;
|
|
|
|
RID camera;
|
|
|
|
RID scenario;
|
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
RS::ViewportUpdateMode update_mode;
|
2016-10-04 03:33:42 +08:00
|
|
|
RID render_target;
|
|
|
|
RID render_target_texture;
|
2019-08-19 06:40:52 +08:00
|
|
|
RID render_buffers;
|
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
RS::ViewportMSAA msaa;
|
2020-04-12 12:49:10 +08:00
|
|
|
RS::ViewportScreenSpaceAA screen_space_aa;
|
2020-04-21 05:34:47 +08:00
|
|
|
bool use_debanding;
|
2016-10-04 03:33:42 +08:00
|
|
|
|
2020-03-04 09:51:12 +08:00
|
|
|
DisplayServer::WindowID viewport_to_screen;
|
2016-10-04 03:33:42 +08:00
|
|
|
Rect2 viewport_to_screen_rect;
|
2019-05-09 02:25:34 +08:00
|
|
|
bool viewport_render_direct_to_screen;
|
2016-10-04 03:33:42 +08:00
|
|
|
|
|
|
|
bool hide_scenario;
|
|
|
|
bool hide_canvas;
|
|
|
|
bool disable_environment;
|
2020-04-11 01:18:42 +08:00
|
|
|
bool measure_render_time;
|
|
|
|
|
2020-10-30 05:09:16 +08:00
|
|
|
bool snap_2d_transforms_to_pixel;
|
|
|
|
bool snap_2d_vertices_to_pixel;
|
|
|
|
|
2020-04-11 01:18:42 +08:00
|
|
|
uint64_t time_cpu_begin;
|
|
|
|
uint64_t time_cpu_end;
|
|
|
|
|
|
|
|
uint64_t time_gpu_begin;
|
|
|
|
uint64_t time_gpu_end;
|
2016-10-04 03:33:42 +08:00
|
|
|
|
2016-11-10 10:55:06 +08:00
|
|
|
RID shadow_atlas;
|
|
|
|
int shadow_atlas_size;
|
|
|
|
|
2020-11-26 20:50:21 +08:00
|
|
|
bool sdf_active;
|
|
|
|
|
2020-03-15 00:06:39 +08:00
|
|
|
uint64_t last_pass = 0;
|
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
int render_info[RS::VIEWPORT_RENDER_INFO_MAX];
|
|
|
|
RS::ViewportDebugDraw debug_draw;
|
2017-06-12 02:52:03 +08:00
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
RS::ViewportClearMode clear_mode;
|
2016-10-04 03:33:42 +08:00
|
|
|
|
2020-10-24 23:15:43 +08:00
|
|
|
RS::CanvasItemTextureFilter texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR;
|
|
|
|
RS::CanvasItemTextureRepeat texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED;
|
|
|
|
|
2017-10-21 15:06:10 +08:00
|
|
|
bool transparent_bg;
|
|
|
|
|
2016-10-04 03:33:42 +08:00
|
|
|
struct CanvasKey {
|
2018-10-31 04:53:00 +08:00
|
|
|
int64_t stacking;
|
2016-10-04 03:33:42 +08:00
|
|
|
RID canvas;
|
2017-03-05 23:44:50 +08:00
|
|
|
bool operator<(const CanvasKey &p_canvas) const {
|
2020-05-14 22:41:43 +08:00
|
|
|
if (stacking == p_canvas.stacking) {
|
2018-10-31 04:53:00 +08:00
|
|
|
return canvas < p_canvas.canvas;
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2018-10-31 04:53:00 +08:00
|
|
|
return stacking < p_canvas.stacking;
|
|
|
|
}
|
|
|
|
CanvasKey() {
|
|
|
|
stacking = 0;
|
2017-03-05 23:44:50 +08:00
|
|
|
}
|
2018-10-31 04:53:00 +08:00
|
|
|
CanvasKey(const RID &p_canvas, int p_layer, int p_sublayer) {
|
2017-03-05 23:44:50 +08:00
|
|
|
canvas = p_canvas;
|
2019-03-06 04:18:46 +08:00
|
|
|
int64_t sign = p_layer < 0 ? -1 : 1;
|
|
|
|
stacking = sign * (((int64_t)ABS(p_layer)) << 32) + p_sublayer;
|
2017-03-05 23:44:50 +08:00
|
|
|
}
|
2018-10-31 04:53:00 +08:00
|
|
|
int get_layer() const { return stacking >> 32; }
|
2016-10-04 03:33:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CanvasData {
|
|
|
|
CanvasBase *canvas;
|
2017-01-11 11:52:51 +08:00
|
|
|
Transform2D transform;
|
2016-10-04 03:33:42 +08:00
|
|
|
int layer;
|
2018-10-31 04:53:00 +08:00
|
|
|
int sublayer;
|
2016-10-04 03:33:42 +08:00
|
|
|
};
|
|
|
|
|
2017-01-11 11:52:51 +08:00
|
|
|
Transform2D global_transform;
|
2016-10-04 03:33:42 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
Map<RID, CanvasData> canvas_map;
|
2016-10-04 03:33:42 +08:00
|
|
|
|
|
|
|
Viewport() {
|
2020-03-28 02:21:27 +08:00
|
|
|
update_mode = RS::VIEWPORT_UPDATE_WHEN_VISIBLE;
|
|
|
|
clear_mode = RS::VIEWPORT_CLEAR_ALWAYS;
|
2017-10-21 15:06:10 +08:00
|
|
|
transparent_bg = false;
|
2017-03-05 23:44:50 +08:00
|
|
|
disable_environment = false;
|
2020-03-04 09:51:12 +08:00
|
|
|
viewport_to_screen = DisplayServer::INVALID_WINDOW_ID;
|
2017-03-05 23:44:50 +08:00
|
|
|
shadow_atlas_size = 0;
|
2020-04-11 01:18:42 +08:00
|
|
|
measure_render_time = false;
|
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
debug_draw = RS::VIEWPORT_DEBUG_DRAW_DISABLED;
|
|
|
|
msaa = RS::VIEWPORT_MSAA_DISABLED;
|
2020-04-12 12:49:10 +08:00
|
|
|
screen_space_aa = RS::VIEWPORT_SCREEN_SPACE_AA_DISABLED;
|
2020-04-21 05:34:47 +08:00
|
|
|
use_debanding = false;
|
2020-04-12 12:49:10 +08:00
|
|
|
|
2020-10-30 05:09:16 +08:00
|
|
|
snap_2d_transforms_to_pixel = false;
|
|
|
|
snap_2d_vertices_to_pixel = false;
|
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
for (int i = 0; i < RS::VIEWPORT_RENDER_INFO_MAX; i++) {
|
2017-06-12 02:52:03 +08:00
|
|
|
render_info[i] = 0;
|
|
|
|
}
|
2020-04-08 22:47:36 +08:00
|
|
|
use_xr = false;
|
2020-11-26 20:50:21 +08:00
|
|
|
sdf_active = false;
|
2020-04-11 01:18:42 +08:00
|
|
|
|
|
|
|
time_cpu_begin = 0;
|
|
|
|
time_cpu_end = 0;
|
|
|
|
|
|
|
|
time_gpu_begin = 0;
|
|
|
|
time_gpu_end = 0;
|
2016-10-04 03:33:42 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-04-11 01:18:42 +08:00
|
|
|
HashMap<String, RID> timestamp_vp_map;
|
|
|
|
|
2020-03-15 00:06:39 +08:00
|
|
|
uint64_t draw_viewports_pass = 0;
|
|
|
|
|
2019-06-10 23:38:51 +08:00
|
|
|
mutable RID_PtrOwner<Viewport> viewport_owner;
|
2016-10-05 12:26:35 +08:00
|
|
|
|
|
|
|
struct ViewportSort {
|
2017-03-05 23:44:50 +08: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 12:26:35 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
if (left_to_screen == right_to_screen) {
|
2020-03-15 00:06:39 +08:00
|
|
|
return p_right->parent == p_left->self;
|
2016-10-05 12:26:35 +08:00
|
|
|
}
|
2020-03-15 00:06:39 +08:00
|
|
|
return (right_to_screen ? 0 : 1) < (left_to_screen ? 0 : 1);
|
2016-10-05 12:26:35 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
Vector<Viewport *> active_viewports;
|
2016-10-05 12:26:35 +08:00
|
|
|
|
2016-10-04 03:33:42 +08:00
|
|
|
private:
|
2020-04-08 22:47:36 +08:00
|
|
|
void _draw_3d(Viewport *p_viewport, XRInterface::Eyes p_eye);
|
|
|
|
void _draw_viewport(Viewport *p_viewport, XRInterface::Eyes p_eye = XRInterface::EYE_MONO);
|
2016-10-04 03:33:42 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
public:
|
2016-10-04 03:33:42 +08:00
|
|
|
RID viewport_create();
|
|
|
|
|
2020-04-08 22:47:36 +08:00
|
|
|
void viewport_set_use_xr(RID p_viewport, bool p_use_xr);
|
2017-04-23 20:10:41 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void viewport_set_size(RID p_viewport, int p_width, int p_height);
|
2016-10-04 03:33:42 +08:00
|
|
|
|
2020-03-04 09:51:12 +08:00
|
|
|
void viewport_attach_to_screen(RID p_viewport, const Rect2 &p_rect = Rect2(), DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID);
|
2019-05-09 02:25:34 +08:00
|
|
|
void viewport_set_render_direct_to_screen(RID p_viewport, bool p_enable);
|
2016-10-04 03:33:42 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void viewport_set_active(RID p_viewport, bool p_active);
|
|
|
|
void viewport_set_parent_viewport(RID p_viewport, RID p_parent_viewport);
|
2020-03-28 02:21:27 +08:00
|
|
|
void viewport_set_update_mode(RID p_viewport, RS::ViewportUpdateMode p_mode);
|
2017-03-05 23:44:50 +08:00
|
|
|
void viewport_set_vflip(RID p_viewport, bool p_enable);
|
2016-10-04 03:33:42 +08:00
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
void viewport_set_clear_mode(RID p_viewport, RS::ViewportClearMode p_clear_mode);
|
2016-10-04 03:33:42 +08:00
|
|
|
|
|
|
|
RID viewport_get_texture(RID p_viewport) const;
|
|
|
|
|
2017-03-05 23:44:50 +08: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);
|
2016-10-04 03:33:42 +08:00
|
|
|
|
2017-03-05 23:44:50 +08: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-04 03:33:42 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void viewport_set_global_canvas_transform(RID p_viewport, const Transform2D &p_transform);
|
2018-10-31 04:53:00 +08:00
|
|
|
void viewport_set_canvas_stacking(RID p_viewport, RID p_canvas, int p_layer, int p_sublayer);
|
2016-10-04 03:33:42 +08:00
|
|
|
|
2017-03-05 23:44:50 +08: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 10:55:06 +08:00
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
void viewport_set_msaa(RID p_viewport, RS::ViewportMSAA p_msaa);
|
2020-04-12 12:49:10 +08:00
|
|
|
void viewport_set_screen_space_aa(RID p_viewport, RS::ViewportScreenSpaceAA p_mode);
|
2020-04-21 05:34:47 +08:00
|
|
|
void viewport_set_use_debanding(RID p_viewport, bool p_use_debanding);
|
2017-01-02 09:16:52 +08:00
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
virtual int viewport_get_render_info(RID p_viewport, RS::ViewportRenderInfo p_info);
|
|
|
|
virtual void viewport_set_debug_draw(RID p_viewport, RS::ViewportDebugDraw p_draw);
|
2017-06-12 02:52:03 +08:00
|
|
|
|
2020-04-11 01:18:42 +08:00
|
|
|
void viewport_set_measure_render_time(RID p_viewport, bool p_enable);
|
|
|
|
float viewport_get_measured_render_time_cpu(RID p_viewport) const;
|
|
|
|
float viewport_get_measured_render_time_gpu(RID p_viewport) const;
|
|
|
|
|
2020-10-30 05:09:16 +08:00
|
|
|
void viewport_set_snap_2d_transforms_to_pixel(RID p_viewport, bool p_enabled);
|
|
|
|
void viewport_set_snap_2d_vertices_to_pixel(RID p_viewport, bool p_enabled);
|
|
|
|
|
2020-10-24 23:15:43 +08:00
|
|
|
void viewport_set_default_canvas_item_texture_filter(RID p_viewport, RS::CanvasItemTextureFilter p_filter);
|
|
|
|
void viewport_set_default_canvas_item_texture_repeat(RID p_viewport, RS::CanvasItemTextureRepeat p_repeat);
|
|
|
|
|
2020-11-26 20:50:21 +08:00
|
|
|
void viewport_set_sdf_oversize_and_scale(RID p_viewport, RS::ViewportSDFOversize p_over_size, RS::ViewportSDFScale p_scale);
|
|
|
|
|
2020-04-11 01:18:42 +08:00
|
|
|
void handle_timestamp(String p_timestamp, uint64_t p_cpu_time, uint64_t p_gpu_time);
|
|
|
|
|
2018-07-30 02:09:42 +08:00
|
|
|
void set_default_clear_color(const Color &p_color);
|
2016-10-04 03:33:42 +08:00
|
|
|
void draw_viewports();
|
|
|
|
|
|
|
|
bool free(RID p_rid);
|
|
|
|
|
2020-12-05 02:26:24 +08:00
|
|
|
RendererViewport();
|
|
|
|
virtual ~RendererViewport() {}
|
2016-10-04 03:33:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // VISUALSERVERVIEWPORT_H
|