2022-03-15 13:29:32 +01:00
|
|
|
/*************************************************************************/
|
2022-08-19 21:24:36 +02:00
|
|
|
/* rendering_server_viewport.cpp */
|
2022-03-15 13:29:32 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2022-08-19 21:24:36 +02:00
|
|
|
#include "rendering_server_viewport.h"
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-17 15:35:28 +02:00
|
|
|
#include "core/config/project_settings.h"
|
2022-08-19 21:24:36 +02:00
|
|
|
#include "rendering_server_canvas.h"
|
|
|
|
#include "rendering_server_globals.h"
|
|
|
|
#include "rendering_server_scene.h"
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
static Transform2D _canvas_get_transform(RenderingServerViewport::Viewport *p_viewport, RenderingServerCanvas::Canvas *p_canvas, RenderingServerViewport::Viewport::CanvasData *p_canvas_data, const Vector2 &p_vp_size) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Transform2D xf = p_viewport->global_transform;
|
|
|
|
|
|
|
|
float scale = 1.0;
|
|
|
|
|
|
|
|
if (p_viewport->canvas_map.has(p_canvas->parent)) {
|
|
|
|
Transform2D c_xform = p_viewport->canvas_map[p_canvas->parent].transform;
|
|
|
|
xf = xf * c_xform;
|
|
|
|
scale = p_canvas->parent_scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
Transform2D c_xform = p_canvas_data->transform;
|
|
|
|
xf = xf * c_xform;
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
if (scale != 1.0 && !RSG::canvas->disable_scale) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Vector2 pivot = p_vp_size * 0.5;
|
|
|
|
Transform2D xfpivot;
|
|
|
|
xfpivot.set_origin(pivot);
|
|
|
|
Transform2D xfscale;
|
|
|
|
xfscale.scale(Vector2(scale, scale));
|
|
|
|
|
|
|
|
xf = xfpivot.affine_inverse() * xf;
|
|
|
|
xf = xfscale * xf;
|
|
|
|
xf = xfpivot * xf;
|
|
|
|
}
|
|
|
|
|
|
|
|
return xf;
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::_draw_3d(Viewport *p_viewport) {
|
|
|
|
RSG::scene->render_camera(p_viewport->camera, p_viewport->scenario, p_viewport->size, p_viewport->shadow_atlas);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::_draw_viewport(Viewport *p_viewport) {
|
2022-03-15 13:29:32 +01:00
|
|
|
/* Camera should always be BEFORE any other 3D */
|
|
|
|
|
|
|
|
bool scenario_draw_canvas_bg = false; //draw canvas, or some layer of it, as BG for 3D instead of in front
|
|
|
|
int scenario_canvas_max_layer = 0;
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
if (!p_viewport->hide_canvas && !p_viewport->disable_environment && RSG::scene->scenario_owner.owns(p_viewport->scenario)) {
|
|
|
|
RenderingServerScene::Scenario *scenario = RSG::scene->scenario_owner.get(p_viewport->scenario);
|
2022-03-15 13:29:32 +01:00
|
|
|
ERR_FAIL_COND(!scenario);
|
2022-08-19 20:50:20 +02:00
|
|
|
if (RSG::scene_render->is_environment(scenario->environment)) {
|
|
|
|
scenario_draw_canvas_bg = RSG::scene_render->environment_get_background(scenario->environment) == RS::ENV_BG_CANVAS;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
scenario_canvas_max_layer = RSG::scene_render->environment_get_canvas_max_layer(scenario->environment);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
bool can_draw_3d = !p_viewport->disable_3d && !p_viewport->disable_3d_by_usage && RSG::scene->camera_owner.owns(p_viewport->camera);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
if (p_viewport->clear_mode != RS::VIEWPORT_CLEAR_NEVER) {
|
|
|
|
RSG::rasterizer->clear_render_target(p_viewport->transparent_bg ? Color(0, 0, 0, 0) : clear_color);
|
|
|
|
if (p_viewport->clear_mode == RS::VIEWPORT_CLEAR_ONLY_NEXT_FRAME) {
|
|
|
|
p_viewport->clear_mode = RS::VIEWPORT_CLEAR_NEVER;
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!scenario_draw_canvas_bg && can_draw_3d) {
|
2022-03-16 02:39:38 +01:00
|
|
|
_draw_3d(p_viewport);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!p_viewport->hide_canvas) {
|
2023-01-15 19:12:50 +01:00
|
|
|
RBMap<Viewport::CanvasKey, Viewport::CanvasData *> canvas_map;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
Rect2 clip_rect(0, 0, p_viewport->size.x, p_viewport->size.y);
|
|
|
|
RasterizerCanvas::Light *lights = nullptr;
|
|
|
|
RasterizerCanvas::Light *lights_with_shadow = nullptr;
|
|
|
|
RasterizerCanvas::Light *lights_with_mask = nullptr;
|
|
|
|
Rect2 shadow_rect;
|
|
|
|
|
2023-01-15 19:12:50 +01:00
|
|
|
for (RBMap<RID, Viewport::CanvasData>::Element *E = p_viewport->canvas_map.front(); E; E = E->next()) {
|
2022-08-19 20:50:20 +02:00
|
|
|
RenderingServerCanvas::Canvas *canvas = static_cast<RenderingServerCanvas::Canvas *>(E->get().canvas);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
Transform2D xf = _canvas_get_transform(p_viewport, canvas, &E->get(), clip_rect.size);
|
|
|
|
|
|
|
|
//find lights in canvas
|
|
|
|
|
2023-01-15 19:42:08 +01:00
|
|
|
for (RBSet<RasterizerCanvas::Light *>::Element *F = canvas->lights.front(); F; F = F->next()) {
|
2022-03-15 13:29:32 +01:00
|
|
|
RasterizerCanvas::Light *cl = F->get();
|
|
|
|
if (cl->enabled && cl->texture.is_valid()) {
|
|
|
|
//not super efficient..
|
2022-08-19 20:50:20 +02:00
|
|
|
Size2 tsize = RSG::storage->texture_size_with_proxy(cl->texture);
|
2022-03-15 13:29:32 +01:00
|
|
|
// Skip using lights with texture of 0 size
|
|
|
|
if (!tsize.x || !tsize.y) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
tsize *= cl->scale;
|
|
|
|
|
|
|
|
Vector2 offset = tsize / 2.0;
|
|
|
|
cl->rect_cache = Rect2(-offset + cl->texture_offset, tsize);
|
2023-08-27 18:48:25 +02:00
|
|
|
|
|
|
|
if (!RSG::canvas->_interpolation_data.interpolation_enabled || !cl->interpolated) {
|
|
|
|
cl->xform_cache = xf * cl->xform_curr;
|
|
|
|
} else {
|
|
|
|
real_t f = Engine::get_singleton()->get_physics_interpolation_fraction();
|
|
|
|
TransformInterpolator::interpolate_transform_2d(cl->xform_prev, cl->xform_curr, cl->xform_cache, f);
|
|
|
|
cl->xform_cache = xf * cl->xform_cache;
|
|
|
|
}
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
if (clip_rect.intersects_transformed(cl->xform_cache, cl->rect_cache)) {
|
|
|
|
cl->filter_next_ptr = lights;
|
|
|
|
lights = cl;
|
|
|
|
cl->texture_cache = nullptr;
|
|
|
|
Transform2D scale;
|
|
|
|
scale.scale(cl->rect_cache.size);
|
2022-08-14 15:37:05 +02:00
|
|
|
scale.columns[2] = cl->rect_cache.position;
|
2022-03-15 13:29:32 +01:00
|
|
|
cl->light_shader_xform = (cl->xform_cache * scale).affine_inverse();
|
|
|
|
cl->light_shader_pos = cl->xform_cache[2];
|
|
|
|
if (cl->shadow_buffer.is_valid()) {
|
|
|
|
cl->shadows_next_ptr = lights_with_shadow;
|
|
|
|
if (lights_with_shadow == nullptr) {
|
|
|
|
shadow_rect = cl->xform_cache.xform(cl->rect_cache);
|
|
|
|
} else {
|
|
|
|
shadow_rect = shadow_rect.merge(cl->xform_cache.xform(cl->rect_cache));
|
|
|
|
}
|
|
|
|
lights_with_shadow = cl;
|
|
|
|
cl->radius_cache = cl->rect_cache.size.length();
|
|
|
|
}
|
2022-08-19 20:50:20 +02:00
|
|
|
if (cl->mode == RS::CANVAS_LIGHT_MODE_MASK) {
|
2022-03-15 13:29:32 +01:00
|
|
|
cl->mask_next_ptr = lights_with_mask;
|
|
|
|
lights_with_mask = cl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::canvas_render->light_internal_update(cl->light_internal, cl);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
canvas_map[Viewport::CanvasKey(E->key(), E->get().layer, E->get().sublayer)] = &E->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lights_with_shadow) {
|
|
|
|
//update shadows if any
|
|
|
|
|
|
|
|
RasterizerCanvas::LightOccluderInstance *occluders = nullptr;
|
|
|
|
|
|
|
|
//make list of occluders
|
2023-01-15 19:12:50 +01:00
|
|
|
for (RBMap<RID, Viewport::CanvasData>::Element *E = p_viewport->canvas_map.front(); E; E = E->next()) {
|
2022-08-19 20:50:20 +02:00
|
|
|
RenderingServerCanvas::Canvas *canvas = static_cast<RenderingServerCanvas::Canvas *>(E->get().canvas);
|
2022-03-15 13:29:32 +01:00
|
|
|
Transform2D xf = _canvas_get_transform(p_viewport, canvas, &E->get(), clip_rect.size);
|
|
|
|
|
2023-01-15 19:42:08 +01:00
|
|
|
for (RBSet<RasterizerCanvas::LightOccluderInstance *>::Element *F = canvas->occluders.front(); F; F = F->next()) {
|
2023-08-27 18:48:25 +02:00
|
|
|
RasterizerCanvas::LightOccluderInstance *occluder = F->get();
|
|
|
|
if (!occluder->enabled) {
|
2022-03-15 13:29:32 +01:00
|
|
|
continue;
|
|
|
|
}
|
2023-08-27 18:48:25 +02:00
|
|
|
|
|
|
|
if (!RSG::canvas->_interpolation_data.interpolation_enabled || !occluder->interpolated) {
|
|
|
|
occluder->xform_cache = xf * occluder->xform_curr;
|
|
|
|
} else {
|
|
|
|
real_t f = Engine::get_singleton()->get_physics_interpolation_fraction();
|
|
|
|
TransformInterpolator::interpolate_transform_2d(occluder->xform_prev, occluder->xform_curr, occluder->xform_cache, f);
|
|
|
|
occluder->xform_cache = xf * occluder->xform_cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shadow_rect.intersects_transformed(occluder->xform_cache, occluder->aabb_cache)) {
|
|
|
|
occluder->next = occluders;
|
|
|
|
occluders = occluder;
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//update the light shadowmaps with them
|
|
|
|
RasterizerCanvas::Light *light = lights_with_shadow;
|
|
|
|
while (light) {
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::canvas_render->canvas_light_shadow_buffer_update(light->shadow_buffer, light->xform_cache.affine_inverse(), light->item_shadow_mask, light->radius_cache / 1000.0, light->radius_cache * 1.1, occluders, &light->shadow_matrix_cache);
|
2022-03-15 13:29:32 +01:00
|
|
|
light = light->shadows_next_ptr;
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
//RSG::canvas_render->reset_canvas();
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::rasterizer->restore_render_target(!scenario_draw_canvas_bg && can_draw_3d);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
if (scenario_draw_canvas_bg && canvas_map.front() && canvas_map.front()->key().get_layer() > scenario_canvas_max_layer) {
|
|
|
|
if (!can_draw_3d) {
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::scene->render_empty_scene(p_viewport->scenario, p_viewport->shadow_atlas);
|
2022-03-15 13:29:32 +01:00
|
|
|
} else {
|
2022-03-16 02:39:38 +01:00
|
|
|
_draw_3d(p_viewport);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
scenario_draw_canvas_bg = false;
|
|
|
|
}
|
|
|
|
|
2023-01-15 19:12:50 +01:00
|
|
|
for (RBMap<Viewport::CanvasKey, Viewport::CanvasData *>::Element *E = canvas_map.front(); E; E = E->next()) {
|
2022-08-19 20:50:20 +02:00
|
|
|
RenderingServerCanvas::Canvas *canvas = static_cast<RenderingServerCanvas::Canvas *>(E->get()->canvas);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
Transform2D xform = _canvas_get_transform(p_viewport, canvas, E->get(), clip_rect.size);
|
|
|
|
|
|
|
|
RasterizerCanvas::Light *canvas_lights = nullptr;
|
|
|
|
|
|
|
|
RasterizerCanvas::Light *ptr = lights;
|
|
|
|
int canvas_layer_id = E->get()->layer;
|
|
|
|
while (ptr) {
|
|
|
|
if (canvas_layer_id >= ptr->layer_min && canvas_layer_id <= ptr->layer_max) {
|
|
|
|
ptr->next_ptr = canvas_lights;
|
|
|
|
canvas_lights = ptr;
|
|
|
|
}
|
|
|
|
ptr = ptr->filter_next_ptr;
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::canvas->render_canvas(canvas, xform, canvas_lights, lights_with_mask, clip_rect, canvas_layer_id);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
if (scenario_draw_canvas_bg && E->key().get_layer() >= scenario_canvas_max_layer) {
|
|
|
|
if (!can_draw_3d) {
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::scene->render_empty_scene(p_viewport->scenario, p_viewport->shadow_atlas);
|
2022-03-15 13:29:32 +01:00
|
|
|
} else {
|
2022-03-16 02:39:38 +01:00
|
|
|
_draw_3d(p_viewport);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
scenario_draw_canvas_bg = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scenario_draw_canvas_bg) {
|
|
|
|
if (!can_draw_3d) {
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::scene->render_empty_scene(p_viewport->scenario, p_viewport->shadow_atlas);
|
2022-03-15 13:29:32 +01:00
|
|
|
} else {
|
2022-03-16 02:39:38 +01:00
|
|
|
_draw_3d(p_viewport);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
//RSG::canvas_render->canvas_debug_viewport_shadows(lights_with_shadow);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::draw_viewports() {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
|
|
|
clear_color = GLOBAL_GET("rendering/environment/default_clear_color");
|
|
|
|
}
|
|
|
|
|
|
|
|
//sort viewports
|
|
|
|
active_viewports.sort_custom<ViewportSort>();
|
|
|
|
|
|
|
|
//draw viewports
|
|
|
|
for (int i = 0; i < active_viewports.size(); i++) {
|
|
|
|
Viewport *vp = active_viewports[i];
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
if (vp->update_mode == RS::VIEWPORT_UPDATE_DISABLED) {
|
2022-03-15 13:29:32 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR_CONTINUE(!vp->render_target.is_valid());
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
bool visible = vp->viewport_to_screen_rect != Rect2() || vp->update_mode == RS::VIEWPORT_UPDATE_ALWAYS || vp->update_mode == RS::VIEWPORT_UPDATE_ONCE || (vp->update_mode == RS::VIEWPORT_UPDATE_WHEN_VISIBLE && RSG::storage->render_target_was_used(vp->render_target));
|
2022-03-15 13:29:32 +01:00
|
|
|
visible = visible && vp->size.x > 1 && vp->size.y > 1;
|
|
|
|
|
|
|
|
if (!visible) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::storage->render_target_clear_used(vp->render_target);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::storage->render_target_set_external_texture(vp->render_target, 0, 0);
|
|
|
|
RSG::rasterizer->set_current_render_target(vp->render_target);
|
2022-03-16 02:39:38 +01:00
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::scene_render->set_debug_draw_mode(vp->debug_draw);
|
|
|
|
RSG::storage->render_info_begin_capture();
|
2022-03-16 02:39:38 +01:00
|
|
|
|
|
|
|
// render standard mono camera
|
|
|
|
_draw_viewport(vp);
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::storage->render_info_end_capture();
|
|
|
|
vp->render_info[RS::VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_OBJECTS_IN_FRAME);
|
|
|
|
vp->render_info[RS::VIEWPORT_RENDER_INFO_VERTICES_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_VERTICES_IN_FRAME);
|
|
|
|
vp->render_info[RS::VIEWPORT_RENDER_INFO_MATERIAL_CHANGES_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_MATERIAL_CHANGES_IN_FRAME);
|
|
|
|
vp->render_info[RS::VIEWPORT_RENDER_INFO_SHADER_CHANGES_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_SHADER_CHANGES_IN_FRAME);
|
|
|
|
vp->render_info[RS::VIEWPORT_RENDER_INFO_SURFACE_CHANGES_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_SURFACE_CHANGES_IN_FRAME);
|
|
|
|
vp->render_info[RS::VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_DRAW_CALLS_IN_FRAME);
|
|
|
|
vp->render_info[RS::VIEWPORT_RENDER_INFO_2D_ITEMS_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_2D_ITEMS_IN_FRAME);
|
|
|
|
vp->render_info[RS::VIEWPORT_RENDER_INFO_2D_DRAW_CALLS_IN_FRAME] = RSG::storage->get_captured_render_info(RS::INFO_2D_DRAW_CALLS_IN_FRAME);
|
|
|
|
|
|
|
|
if (vp->viewport_to_screen_rect != Rect2() && (!vp->viewport_render_direct_to_screen || !RSG::rasterizer->is_low_end())) {
|
2022-03-16 02:39:38 +01:00
|
|
|
//copy to screen if set as such
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::rasterizer->set_current_render_target(RID());
|
|
|
|
RSG::rasterizer->blit_render_target_to_screen(vp->render_target, vp->viewport_to_screen_rect, vp->viewport_to_screen);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
if (vp->update_mode == RS::VIEWPORT_UPDATE_ONCE) {
|
|
|
|
vp->update_mode = RS::VIEWPORT_UPDATE_DISABLED;
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::scene_render->set_debug_draw_mode(RS::VIEWPORT_DEBUG_DRAW_DISABLED);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RID RenderingServerViewport::viewport_create() {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = memnew(Viewport);
|
|
|
|
|
|
|
|
RID rid = viewport_owner.make_rid(viewport);
|
|
|
|
|
|
|
|
viewport->self = rid;
|
|
|
|
viewport->hide_scenario = false;
|
|
|
|
viewport->hide_canvas = false;
|
2022-08-19 20:50:20 +02:00
|
|
|
viewport->render_target = RSG::storage->render_target_create();
|
|
|
|
viewport->shadow_atlas = RSG::scene_render->shadow_atlas_create();
|
2022-03-15 13:29:32 +01:00
|
|
|
viewport->viewport_render_direct_to_screen = false;
|
|
|
|
|
|
|
|
return rid;
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_size(RID p_viewport, int p_width, int p_height) {
|
2022-03-15 13:29:32 +01:00
|
|
|
ERR_FAIL_COND(p_width < 0 && p_height < 0);
|
|
|
|
|
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
viewport->size = Size2(p_width, p_height);
|
2022-03-16 02:39:38 +01:00
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::storage->render_target_set_size(viewport->render_target, p_width, p_height);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_active(RID p_viewport, bool p_active) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
if (p_active) {
|
|
|
|
ERR_FAIL_COND_MSG(active_viewports.find(viewport) != -1, "Can't make active a Viewport that is already active.");
|
|
|
|
active_viewports.push_back(viewport);
|
|
|
|
} else {
|
|
|
|
active_viewports.erase(viewport);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_parent_viewport(RID p_viewport, RID p_parent_viewport) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
viewport->parent = p_parent_viewport;
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_clear_mode(RID p_viewport, RS::ViewportClearMode p_clear_mode) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
viewport->clear_mode = p_clear_mode;
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_attach_to_screen(RID p_viewport, const Rect2 &p_rect, int p_screen) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
// If using GLES2 we can optimize this operation by rendering directly to system_fbo
|
|
|
|
// instead of rendering to fbo and copying to system_fbo after
|
2022-08-19 20:50:20 +02:00
|
|
|
if (RSG::rasterizer->is_low_end() && viewport->viewport_render_direct_to_screen) {
|
|
|
|
RSG::storage->render_target_set_size(viewport->render_target, p_rect.size.x, p_rect.size.y);
|
|
|
|
RSG::storage->render_target_set_position(viewport->render_target, p_rect.position.x, p_rect.position.y);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
viewport->viewport_to_screen_rect = p_rect;
|
|
|
|
viewport->viewport_to_screen = p_screen;
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_render_direct_to_screen(RID p_viewport, bool p_enable) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
if (p_enable == viewport->viewport_render_direct_to_screen) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if disabled, reset render_target size and position
|
|
|
|
if (!p_enable) {
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::storage->render_target_set_position(viewport->render_target, 0, 0);
|
|
|
|
RSG::storage->render_target_set_size(viewport->render_target, viewport->size.x, viewport->size.y);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_DIRECT_TO_SCREEN, p_enable);
|
2022-03-15 13:29:32 +01:00
|
|
|
viewport->viewport_render_direct_to_screen = p_enable;
|
|
|
|
|
|
|
|
// if attached to screen already, setup screen size and position, this needs to happen after setting flag to avoid an unnecessary buffer allocation
|
2022-08-19 20:50:20 +02:00
|
|
|
if (RSG::rasterizer->is_low_end() && viewport->viewport_to_screen_rect != Rect2() && p_enable) {
|
|
|
|
RSG::storage->render_target_set_size(viewport->render_target, viewport->viewport_to_screen_rect.size.x, viewport->viewport_to_screen_rect.size.y);
|
|
|
|
RSG::storage->render_target_set_position(viewport->render_target, viewport->viewport_to_screen_rect.position.x, viewport->viewport_to_screen_rect.position.y);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_detach(RID p_viewport) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
// if render_direct_to_screen was used, reset size and position
|
2022-08-19 20:50:20 +02:00
|
|
|
if (RSG::rasterizer->is_low_end() && viewport->viewport_render_direct_to_screen) {
|
|
|
|
RSG::storage->render_target_set_position(viewport->render_target, 0, 0);
|
|
|
|
RSG::storage->render_target_set_size(viewport->render_target, viewport->size.x, viewport->size.y);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
viewport->viewport_to_screen_rect = Rect2();
|
|
|
|
viewport->viewport_to_screen = 0;
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_update_mode(RID p_viewport, RS::ViewportUpdateMode p_mode) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
viewport->update_mode = p_mode;
|
|
|
|
}
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_vflip(RID p_viewport, bool p_enable) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_VFLIP, p_enable);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RID RenderingServerViewport::viewport_get_texture(RID p_viewport) const {
|
2022-03-15 13:29:32 +01:00
|
|
|
const Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND_V(!viewport, RID());
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
return RSG::storage->render_target_get_texture(viewport->render_target);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_hide_scenario(RID p_viewport, bool p_hide) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
viewport->hide_scenario = p_hide;
|
|
|
|
}
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_hide_canvas(RID p_viewport, bool p_hide) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
viewport->hide_canvas = p_hide;
|
|
|
|
}
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_disable_environment(RID p_viewport, bool p_disable) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
viewport->disable_environment = p_disable;
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_disable_3d(RID p_viewport, bool p_disable) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
viewport->disable_3d = p_disable;
|
2022-08-19 20:50:20 +02:00
|
|
|
//RSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D, p_disable);
|
2022-03-15 13:29:32 +01:00
|
|
|
//this should be just for disabling rendering of 3D, to actually disable it, set usage
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_keep_3d_linear(RID p_viewport, bool p_keep_3d_linear) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
viewport->keep_3d_linear = p_keep_3d_linear;
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_KEEP_3D_LINEAR, p_keep_3d_linear);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_attach_camera(RID p_viewport, RID p_camera) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
viewport->camera = p_camera;
|
|
|
|
}
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_scenario(RID p_viewport, RID p_scenario) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
viewport->scenario = p_scenario;
|
|
|
|
}
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_attach_canvas(RID p_viewport, RID p_canvas) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
ERR_FAIL_COND(viewport->canvas_map.has(p_canvas));
|
2022-08-19 20:50:20 +02:00
|
|
|
RenderingServerCanvas::Canvas *canvas = RSG::canvas->canvas_owner.getornull(p_canvas);
|
2022-03-15 13:29:32 +01:00
|
|
|
ERR_FAIL_COND(!canvas);
|
|
|
|
|
|
|
|
canvas->viewports.insert(p_viewport);
|
|
|
|
viewport->canvas_map[p_canvas] = Viewport::CanvasData();
|
|
|
|
viewport->canvas_map[p_canvas].layer = 0;
|
|
|
|
viewport->canvas_map[p_canvas].sublayer = 0;
|
|
|
|
viewport->canvas_map[p_canvas].canvas = canvas;
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_remove_canvas(RID p_viewport, RID p_canvas) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RenderingServerCanvas::Canvas *canvas = RSG::canvas->canvas_owner.getornull(p_canvas);
|
2022-03-15 13:29:32 +01:00
|
|
|
ERR_FAIL_COND(!canvas);
|
|
|
|
|
|
|
|
viewport->canvas_map.erase(p_canvas);
|
|
|
|
canvas->viewports.erase(p_viewport);
|
|
|
|
}
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_canvas_transform(RID p_viewport, RID p_canvas, const Transform2D &p_offset) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!viewport->canvas_map.has(p_canvas));
|
|
|
|
viewport->canvas_map[p_canvas].transform = p_offset;
|
|
|
|
}
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_transparent_background(RID p_viewport, bool p_enabled) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_TRANSPARENT, p_enabled);
|
2022-03-15 13:29:32 +01:00
|
|
|
viewport->transparent_bg = p_enabled;
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_global_canvas_transform(RID p_viewport, const Transform2D &p_transform) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
viewport->global_transform = p_transform;
|
|
|
|
}
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_canvas_stacking(RID p_viewport, RID p_canvas, int p_layer, int p_sublayer) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!viewport->canvas_map.has(p_canvas));
|
|
|
|
viewport->canvas_map[p_canvas].layer = p_layer;
|
|
|
|
viewport->canvas_map[p_canvas].sublayer = p_sublayer;
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_shadow_atlas_size(RID p_viewport, int p_size) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
viewport->shadow_atlas_size = p_size;
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::scene_render->shadow_atlas_set_size(viewport->shadow_atlas, viewport->shadow_atlas_size);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_shadow_atlas_quadrant_subdivision(RID p_viewport, int p_quadrant, int p_subdiv) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::scene_render->shadow_atlas_set_quadrant_subdivision(viewport->shadow_atlas, p_quadrant, p_subdiv);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_msaa(RID p_viewport, RS::ViewportMSAA p_msaa) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::storage->render_target_set_msaa(viewport->render_target, p_msaa);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_use_fxaa(RID p_viewport, bool p_fxaa) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::storage->render_target_set_use_fxaa(viewport->render_target, p_fxaa);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_use_debanding(RID p_viewport, bool p_debanding) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::storage->render_target_set_use_debanding(viewport->render_target, p_debanding);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_sharpen_intensity(RID p_viewport, float p_intensity) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::storage->render_target_set_sharpen_intensity(viewport->render_target, p_intensity);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_hdr(RID p_viewport, bool p_enabled) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_HDR, p_enabled);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_use_32_bpc_depth(RID p_viewport, bool p_enabled) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_USE_32_BPC_DEPTH, p_enabled);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_usage(RID p_viewport, RS::ViewportUsage p_usage) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
switch (p_usage) {
|
2022-08-19 20:50:20 +02:00
|
|
|
case RS::VIEWPORT_USAGE_2D: {
|
|
|
|
RSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D, true);
|
|
|
|
RSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D_EFFECTS, true);
|
|
|
|
RSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_SAMPLING, false);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
viewport->disable_3d_by_usage = true;
|
|
|
|
} break;
|
2022-08-19 20:50:20 +02:00
|
|
|
case RS::VIEWPORT_USAGE_2D_NO_SAMPLING: {
|
|
|
|
RSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D, true);
|
|
|
|
RSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D_EFFECTS, true);
|
|
|
|
RSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_SAMPLING, true);
|
2022-03-15 13:29:32 +01:00
|
|
|
viewport->disable_3d_by_usage = true;
|
|
|
|
} break;
|
2022-08-19 20:50:20 +02:00
|
|
|
case RS::VIEWPORT_USAGE_3D: {
|
|
|
|
RSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D, false);
|
|
|
|
RSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D_EFFECTS, false);
|
|
|
|
RSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_SAMPLING, false);
|
2022-03-15 13:29:32 +01:00
|
|
|
viewport->disable_3d_by_usage = false;
|
|
|
|
} break;
|
2022-08-19 20:50:20 +02:00
|
|
|
case RS::VIEWPORT_USAGE_3D_NO_EFFECTS: {
|
|
|
|
RSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D, false);
|
|
|
|
RSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D_EFFECTS, true);
|
|
|
|
RSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_SAMPLING, false);
|
2022-03-15 13:29:32 +01:00
|
|
|
viewport->disable_3d_by_usage = false;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
int RenderingServerViewport::viewport_get_render_info(RID p_viewport, RS::ViewportRenderInfo p_info) {
|
|
|
|
ERR_FAIL_INDEX_V(p_info, RS::VIEWPORT_RENDER_INFO_MAX, -1);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
if (!viewport) {
|
|
|
|
return 0; //there should be a lock here..
|
|
|
|
}
|
|
|
|
|
|
|
|
return viewport->render_info[p_info];
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::viewport_set_debug_draw(RID p_viewport, RS::ViewportDebugDraw p_draw) {
|
2022-03-15 13:29:32 +01:00
|
|
|
Viewport *viewport = viewport_owner.getornull(p_viewport);
|
|
|
|
ERR_FAIL_COND(!viewport);
|
|
|
|
|
|
|
|
viewport->debug_draw = p_draw;
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
bool RenderingServerViewport::free(RID p_rid) {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (viewport_owner.owns(p_rid)) {
|
|
|
|
Viewport *viewport = viewport_owner.getornull(p_rid);
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RSG::storage->free(viewport->render_target);
|
|
|
|
RSG::scene_render->free(viewport->shadow_atlas);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
while (viewport->canvas_map.front()) {
|
|
|
|
viewport_remove_canvas(p_rid, viewport->canvas_map.front()->key());
|
|
|
|
}
|
|
|
|
|
|
|
|
viewport_set_scenario(p_rid, RID());
|
|
|
|
active_viewports.erase(viewport);
|
|
|
|
|
|
|
|
viewport_owner.free(p_rid);
|
|
|
|
memdelete(viewport);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
void RenderingServerViewport::set_default_clear_color(const Color &p_color) {
|
2022-03-15 13:29:32 +01:00
|
|
|
clear_color = p_color;
|
|
|
|
}
|
|
|
|
|
2022-08-19 20:50:20 +02:00
|
|
|
RenderingServerViewport::RenderingServerViewport() {
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|