2017-03-05 14:47:28 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* visual_server_canvas.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* 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
|
|
|
/*************************************************************************/
|
2018-01-01 13:40:08 +00:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 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
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
#include "visual_server_canvas.h"
|
|
|
|
#include "visual_server_global.h"
|
2018-08-29 19:48:32 +00:00
|
|
|
#include "visual_server_raster.h"
|
2016-10-03 19:33:42 +00:00
|
|
|
#include "visual_server_viewport.h"
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::_render_canvas_item_tree(Item *p_canvas_item, const Transform2D &p_transform, const Rect2 &p_clip_rect, const Color &p_modulate, RasterizerCanvas::Light *p_lights) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static const int z_range = VS::CANVAS_ITEM_Z_MAX - VS::CANVAS_ITEM_Z_MIN + 1;
|
2016-10-03 19:33:42 +00:00
|
|
|
RasterizerCanvas::Item *z_list[z_range];
|
|
|
|
RasterizerCanvas::Item *z_last_list[z_range];
|
|
|
|
|
2017-08-27 00:40:04 +00:00
|
|
|
memset(z_list, 0, z_range * sizeof(RasterizerCanvas::Item *));
|
|
|
|
memset(z_last_list, 0, z_range * sizeof(RasterizerCanvas::Item *));
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_render_canvas_item(p_canvas_item, p_transform, p_clip_rect, Color(1, 1, 1, 1), 0, z_list, z_last_list, NULL, NULL);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < z_range; i++) {
|
2016-10-03 19:33:42 +00:00
|
|
|
if (!z_list[i])
|
|
|
|
continue;
|
2018-02-21 20:23:27 +00:00
|
|
|
VSG::canvas_render->canvas_render_items(z_list[i], VS::CANVAS_ITEM_Z_MIN + i, p_modulate, p_lights, p_transform);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-21 13:01:11 +00:00
|
|
|
void _collect_ysort_children(VisualServerCanvas::Item *p_canvas_item, Transform2D p_transform, VisualServerCanvas::Item **r_items, int &r_index) {
|
2018-10-30 18:00:31 +00:00
|
|
|
int child_item_count = p_canvas_item->child_items.size();
|
|
|
|
VisualServerCanvas::Item **child_items = p_canvas_item->child_items.ptrw();
|
|
|
|
for (int i = 0; i < child_item_count; i++) {
|
|
|
|
if (r_items) {
|
|
|
|
r_items[r_index] = child_items[i];
|
|
|
|
child_items[i]->ysort_xform = p_transform;
|
|
|
|
child_items[i]->ysort_pos = p_transform.xform(child_items[i]->xform.elements[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
r_index++;
|
|
|
|
|
|
|
|
if (child_items[i]->sort_y)
|
2018-11-21 13:01:11 +00:00
|
|
|
_collect_ysort_children(child_items[i], p_transform * child_items[i]->xform, r_items, r_index);
|
2018-10-30 18:00:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::_render_canvas_item(Item *p_canvas_item, const Transform2D &p_transform, const Rect2 &p_clip_rect, const Color &p_modulate, int p_z, RasterizerCanvas::Item **z_list, RasterizerCanvas::Item **z_last_list, Item *p_canvas_clip, Item *p_material_owner) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
Item *ci = p_canvas_item;
|
|
|
|
|
|
|
|
if (!ci->visible)
|
|
|
|
return;
|
|
|
|
|
2018-10-30 18:00:31 +00:00
|
|
|
if (ci->children_order_dirty) {
|
2017-06-22 12:32:47 +00:00
|
|
|
|
2018-10-30 18:00:31 +00:00
|
|
|
ci->child_items.sort_custom<ItemIndexSort>();
|
|
|
|
ci->children_order_dirty = false;
|
2017-06-22 12:32:47 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
Rect2 rect = ci->get_rect();
|
2017-01-11 03:52:51 +00:00
|
|
|
Transform2D xform = p_transform * ci->xform;
|
2016-10-03 19:33:42 +00:00
|
|
|
Rect2 global_rect = xform.xform(rect);
|
2017-06-03 22:25:13 +00:00
|
|
|
global_rect.position += p_clip_rect.position;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
if (ci->use_parent_material && p_material_owner)
|
2017-03-05 15:44:50 +00:00
|
|
|
ci->material_owner = p_material_owner;
|
2016-10-03 19:33:42 +00:00
|
|
|
else {
|
2017-03-05 15:44:50 +00:00
|
|
|
p_material_owner = ci;
|
|
|
|
ci->material_owner = NULL;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Color modulate(ci->modulate.r * p_modulate.r, ci->modulate.g * p_modulate.g, ci->modulate.b * p_modulate.b, ci->modulate.a * p_modulate.a);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (modulate.a < 0.007)
|
2016-10-03 19:33:42 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int child_item_count = ci->child_items.size();
|
2018-10-30 18:00:31 +00:00
|
|
|
Item **child_items = ci->child_items.ptrw();
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
if (ci->clip) {
|
|
|
|
if (p_canvas_clip != NULL) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ci->final_clip_rect = p_canvas_clip->final_clip_rect.clip(global_rect);
|
2016-10-03 19:33:42 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
ci->final_clip_rect = global_rect;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
ci->final_clip_owner = ci;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
ci->final_clip_owner = p_canvas_clip;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ci->sort_y) {
|
|
|
|
|
2018-10-30 18:00:31 +00:00
|
|
|
if (ci->ysort_children_count == -1) {
|
|
|
|
ci->ysort_children_count = 0;
|
2018-11-21 13:01:11 +00:00
|
|
|
_collect_ysort_children(ci, Transform2D(), NULL, ci->ysort_children_count);
|
2018-10-30 18:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
child_item_count = ci->ysort_children_count;
|
|
|
|
child_items = (Item **)alloca(child_item_count * sizeof(Item *));
|
|
|
|
|
|
|
|
int i = 0;
|
2018-11-21 13:01:11 +00:00
|
|
|
_collect_ysort_children(ci, Transform2D(), child_items, i);
|
2018-10-30 18:00:31 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
SortArray<Item *, ItemPtrSort> sorter;
|
|
|
|
sorter.sort(child_items, child_item_count);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ci->z_relative)
|
2017-12-29 22:06:03 +00:00
|
|
|
p_z = CLAMP(p_z + ci->z_index, VS::CANVAS_ITEM_Z_MIN, VS::CANVAS_ITEM_Z_MAX);
|
2016-10-03 19:33:42 +00:00
|
|
|
else
|
2017-12-29 22:06:03 +00:00
|
|
|
p_z = ci->z_index;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < child_item_count; i++) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2018-10-30 18:00:31 +00:00
|
|
|
if (!child_items[i]->behind || (ci->sort_y && child_items[i]->sort_y))
|
2016-10-03 19:33:42 +00:00
|
|
|
continue;
|
2018-10-30 18:00:31 +00:00
|
|
|
if (ci->sort_y) {
|
|
|
|
_render_canvas_item(child_items[i], xform * child_items[i]->ysort_xform, p_clip_rect, modulate, p_z, z_list, z_last_list, (Item *)ci->final_clip_owner, p_material_owner);
|
|
|
|
} else {
|
|
|
|
_render_canvas_item(child_items[i], xform, p_clip_rect, modulate, p_z, z_list, z_last_list, (Item *)ci->final_clip_owner, p_material_owner);
|
|
|
|
}
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ci->copy_back_buffer) {
|
|
|
|
|
|
|
|
ci->copy_back_buffer->screen_rect = xform.xform(ci->copy_back_buffer->rect).clip(p_clip_rect);
|
|
|
|
}
|
|
|
|
|
2018-08-29 19:48:32 +00:00
|
|
|
if (ci->update_when_visible) {
|
|
|
|
VisualServerRaster::redraw_request();
|
|
|
|
}
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
if ((!ci->commands.empty() && p_clip_rect.intersects(global_rect)) || ci->vp_render || ci->copy_back_buffer) {
|
|
|
|
//something to draw?
|
2017-03-05 15:44:50 +00:00
|
|
|
ci->final_transform = xform;
|
|
|
|
ci->final_modulate = Color(modulate.r * ci->self_modulate.r, modulate.g * ci->self_modulate.g, modulate.b * ci->self_modulate.b, modulate.a * ci->self_modulate.a);
|
|
|
|
ci->global_rect_cache = global_rect;
|
2017-06-03 22:25:13 +00:00
|
|
|
ci->global_rect_cache.position -= p_clip_rect.position;
|
2017-03-05 15:44:50 +00:00
|
|
|
ci->light_masked = false;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int zidx = p_z - VS::CANVAS_ITEM_Z_MIN;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
if (z_last_list[zidx]) {
|
2017-03-05 15:44:50 +00:00
|
|
|
z_last_list[zidx]->next = ci;
|
|
|
|
z_last_list[zidx] = ci;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
z_list[zidx] = ci;
|
|
|
|
z_last_list[zidx] = ci;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ci->next = NULL;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < child_item_count; i++) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2018-10-30 18:00:31 +00:00
|
|
|
if (child_items[i]->behind || (ci->sort_y && child_items[i]->sort_y))
|
2016-10-03 19:33:42 +00:00
|
|
|
continue;
|
2018-10-30 18:00:31 +00:00
|
|
|
if (ci->sort_y) {
|
|
|
|
_render_canvas_item(child_items[i], xform * child_items[i]->ysort_xform, p_clip_rect, modulate, p_z, z_list, z_last_list, (Item *)ci->final_clip_owner, p_material_owner);
|
|
|
|
} else {
|
|
|
|
_render_canvas_item(child_items[i], xform, p_clip_rect, modulate, p_z, z_list, z_last_list, (Item *)ci->final_clip_owner, p_material_owner);
|
|
|
|
}
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::_light_mask_canvas_items(int p_z, RasterizerCanvas::Item *p_canvas_item, RasterizerCanvas::Light *p_masked_lights) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
if (!p_masked_lights)
|
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
RasterizerCanvas::Item *ci = p_canvas_item;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (ci) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
RasterizerCanvas::Light *light = p_masked_lights;
|
|
|
|
while (light) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (ci->light_mask & light->item_mask && p_z >= light->z_min && p_z <= light->z_max && ci->global_rect_cache.intersects_transformed(light->xform_cache, light->rect_cache)) {
|
|
|
|
ci->light_masked = true;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
light = light->mask_next_ptr;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ci = ci->next;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-11 03:52:51 +00:00
|
|
|
void VisualServerCanvas::render_canvas(Canvas *p_canvas, const Transform2D &p_transform, RasterizerCanvas::Light *p_lights, RasterizerCanvas::Light *p_masked_lights, const Rect2 &p_clip_rect) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
VSG::canvas_render->canvas_begin();
|
|
|
|
|
2017-06-22 12:32:47 +00:00
|
|
|
if (p_canvas->children_order_dirty) {
|
|
|
|
|
|
|
|
p_canvas->child_items.sort();
|
|
|
|
p_canvas->children_order_dirty = false;
|
|
|
|
}
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
int l = p_canvas->child_items.size();
|
2017-11-25 03:07:54 +00:00
|
|
|
Canvas::ChildItem *ci = p_canvas->child_items.ptrw();
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool has_mirror = false;
|
|
|
|
for (int i = 0; i < l; i++) {
|
2016-10-03 19:33:42 +00:00
|
|
|
if (ci[i].mirror.x || ci[i].mirror.y) {
|
2017-03-05 15:44:50 +00:00
|
|
|
has_mirror = true;
|
2016-10-03 19:33:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!has_mirror) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static const int z_range = VS::CANVAS_ITEM_Z_MAX - VS::CANVAS_ITEM_Z_MIN + 1;
|
2016-10-03 19:33:42 +00:00
|
|
|
RasterizerCanvas::Item *z_list[z_range];
|
|
|
|
RasterizerCanvas::Item *z_last_list[z_range];
|
|
|
|
|
2017-08-27 00:40:04 +00:00
|
|
|
memset(z_list, 0, z_range * sizeof(RasterizerCanvas::Item *));
|
|
|
|
memset(z_last_list, 0, z_range * sizeof(RasterizerCanvas::Item *));
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < l; i++) {
|
|
|
|
_render_canvas_item(ci[i].item, p_transform, p_clip_rect, Color(1, 1, 1, 1), 0, z_list, z_last_list, NULL, NULL);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < z_range; i++) {
|
2016-10-03 19:33:42 +00:00
|
|
|
if (!z_list[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (p_masked_lights) {
|
2017-03-05 15:44:50 +00:00
|
|
|
_light_mask_canvas_items(VS::CANVAS_ITEM_Z_MIN + i, z_list[i], p_masked_lights);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2018-02-21 20:23:27 +00:00
|
|
|
VSG::canvas_render->canvas_render_items(z_list[i], VS::CANVAS_ITEM_Z_MIN + i, p_canvas->modulate, p_lights, p_transform);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < l; i++) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
const Canvas::ChildItem &ci = p_canvas->child_items[i];
|
2017-03-05 15:44:50 +00:00
|
|
|
_render_canvas_item_tree(ci.item, p_transform, p_clip_rect, p_canvas->modulate, p_lights);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
//mirroring (useful for scrolling backgrounds)
|
2017-03-05 15:44:50 +00:00
|
|
|
if (ci.mirror.x != 0) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Transform2D xform2 = p_transform * Transform2D(0, Vector2(ci.mirror.x, 0));
|
|
|
|
_render_canvas_item_tree(ci.item, xform2, p_clip_rect, p_canvas->modulate, p_lights);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (ci.mirror.y != 0) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Transform2D xform2 = p_transform * Transform2D(0, Vector2(0, ci.mirror.y));
|
|
|
|
_render_canvas_item_tree(ci.item, xform2, p_clip_rect, p_canvas->modulate, p_lights);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (ci.mirror.y != 0 && ci.mirror.x != 0) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Transform2D xform2 = p_transform * Transform2D(0, ci.mirror);
|
|
|
|
_render_canvas_item_tree(ci.item, xform2, p_clip_rect, p_canvas->modulate, p_lights);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-04-09 20:56:37 +00:00
|
|
|
|
|
|
|
VSG::canvas_render->canvas_end();
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RID VisualServerCanvas::canvas_create() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Canvas *canvas = memnew(Canvas);
|
|
|
|
ERR_FAIL_COND_V(!canvas, RID());
|
|
|
|
RID rid = canvas_owner.make_rid(canvas);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
return rid;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_set_item_mirroring(RID p_canvas, RID p_item, const Point2 &p_mirroring) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Canvas *canvas = canvas_owner.getornull(p_canvas);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas);
|
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
|
|
|
int idx = canvas->find_item(canvas_item);
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(idx == -1);
|
2018-07-25 01:11:03 +00:00
|
|
|
canvas->child_items.write[idx].mirror = p_mirroring;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_set_modulate(RID p_canvas, const Color &p_color) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Canvas *canvas = canvas_owner.get(p_canvas);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas);
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas->modulate = p_color;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RID VisualServerCanvas::canvas_item_create() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = memnew(Item);
|
|
|
|
ERR_FAIL_COND_V(!canvas_item, RID());
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return canvas_item_owner.make_rid(canvas_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_set_parent(RID p_item, RID p_parent) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
|
|
|
if (canvas_item->parent.is_valid()) {
|
|
|
|
|
|
|
|
if (canvas_owner.owns(canvas_item->parent)) {
|
|
|
|
|
|
|
|
Canvas *canvas = canvas_owner.get(canvas_item->parent);
|
|
|
|
canvas->erase_item(canvas_item);
|
|
|
|
} else if (canvas_item_owner.owns(canvas_item->parent)) {
|
|
|
|
|
|
|
|
Item *item_owner = canvas_item_owner.get(canvas_item->parent);
|
|
|
|
item_owner->child_items.erase(canvas_item);
|
2018-11-21 13:01:11 +00:00
|
|
|
|
|
|
|
Item *ysort_owner = item_owner;
|
|
|
|
while (ysort_owner && ysort_owner->sort_y) {
|
|
|
|
item_owner->ysort_children_count = -1;
|
|
|
|
ysort_owner = canvas_item_owner.getornull(ysort_owner->parent);
|
|
|
|
}
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->parent = RID();
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p_parent.is_valid()) {
|
|
|
|
if (canvas_owner.owns(p_parent)) {
|
|
|
|
|
|
|
|
Canvas *canvas = canvas_owner.get(p_parent);
|
|
|
|
Canvas::ChildItem ci;
|
2017-03-05 15:44:50 +00:00
|
|
|
ci.item = canvas_item;
|
2016-10-03 19:33:42 +00:00
|
|
|
canvas->child_items.push_back(ci);
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas->children_order_dirty = true;
|
2016-10-03 19:33:42 +00:00
|
|
|
} else if (canvas_item_owner.owns(p_parent)) {
|
|
|
|
|
|
|
|
Item *item_owner = canvas_item_owner.get(p_parent);
|
|
|
|
item_owner->child_items.push_back(canvas_item);
|
2017-03-05 15:44:50 +00:00
|
|
|
item_owner->children_order_dirty = true;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2018-10-30 18:00:31 +00:00
|
|
|
Item *ysort_owner = item_owner;
|
|
|
|
while (ysort_owner && ysort_owner->sort_y) {
|
|
|
|
item_owner->ysort_children_count = -1;
|
|
|
|
ysort_owner = canvas_item_owner.getornull(ysort_owner->parent);
|
|
|
|
}
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
ERR_EXPLAIN("Invalid parent");
|
|
|
|
ERR_FAIL();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->parent = p_parent;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_set_visible(RID p_item, bool p_visible) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->visible = p_visible;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_set_light_mask(RID p_item, int p_mask) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->light_mask = p_mask;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_set_transform(RID p_item, const Transform2D &p_transform) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->xform = p_transform;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_set_clip(RID p_item, bool p_clip) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->clip = p_clip;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_set_distance_field_mode(RID p_item, bool p_enable) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->distance_field = p_enable;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_set_custom_rect(RID p_item, bool p_custom_rect, const Rect2 &p_rect) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->custom_rect = p_custom_rect;
|
|
|
|
canvas_item->rect = p_rect;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_set_modulate(RID p_item, const Color &p_color) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->modulate = p_color;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_set_self_modulate(RID p_item, const Color &p_color) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->self_modulate = p_color;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_set_draw_behind_parent(RID p_item, bool p_enable) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->behind = p_enable;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 19:48:32 +00:00
|
|
|
void VisualServerCanvas::canvas_item_set_update_when_visible(RID p_item, bool p_update) {
|
|
|
|
|
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
|
|
|
canvas_item->update_when_visible = p_update;
|
|
|
|
}
|
|
|
|
|
2017-08-11 19:10:05 +00:00
|
|
|
void VisualServerCanvas::canvas_item_add_line(RID p_item, const Point2 &p_from, const Point2 &p_to, const Color &p_color, float p_width, bool p_antialiased) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item::CommandLine *line = memnew(Item::CommandLine);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!line);
|
2017-08-11 19:10:05 +00:00
|
|
|
line->color = p_color;
|
2017-03-05 15:44:50 +00:00
|
|
|
line->from = p_from;
|
|
|
|
line->to = p_to;
|
|
|
|
line->width = p_width;
|
|
|
|
line->antialiased = p_antialiased;
|
|
|
|
canvas_item->rect_dirty = true;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
canvas_item->commands.push_back(line);
|
|
|
|
}
|
|
|
|
|
2017-07-01 00:30:17 +00:00
|
|
|
void VisualServerCanvas::canvas_item_add_polyline(RID p_item, const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width, bool p_antialiased) {
|
|
|
|
|
|
|
|
ERR_FAIL_COND(p_points.size() < 2);
|
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
|
|
|
Item::CommandPolyLine *pline = memnew(Item::CommandPolyLine);
|
|
|
|
ERR_FAIL_COND(!pline);
|
|
|
|
|
|
|
|
pline->antialiased = p_antialiased;
|
2017-12-09 17:11:26 +00:00
|
|
|
pline->multiline = false;
|
2017-07-01 00:30:17 +00:00
|
|
|
|
|
|
|
if (p_width <= 1) {
|
|
|
|
pline->lines = p_points;
|
|
|
|
pline->line_colors = p_colors;
|
|
|
|
if (pline->line_colors.size() == 0) {
|
|
|
|
pline->line_colors.push_back(Color(1, 1, 1, 1));
|
|
|
|
} else if (pline->line_colors.size() > 1 && pline->line_colors.size() != pline->lines.size()) {
|
|
|
|
pline->line_colors.resize(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//make a trianglestrip for drawing the line...
|
|
|
|
Vector2 prev_t;
|
|
|
|
pline->triangles.resize(p_points.size() * 2);
|
|
|
|
if (p_antialiased) {
|
|
|
|
pline->lines.resize(p_points.size() * 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_colors.size() == 0) {
|
|
|
|
pline->triangle_colors.push_back(Color(1, 1, 1, 1));
|
|
|
|
if (p_antialiased) {
|
|
|
|
pline->line_colors.push_back(Color(1, 1, 1, 1));
|
|
|
|
}
|
2018-03-19 18:22:38 +00:00
|
|
|
} else if (p_colors.size() == 1) {
|
2017-07-01 00:30:17 +00:00
|
|
|
pline->triangle_colors = p_colors;
|
|
|
|
pline->line_colors = p_colors;
|
|
|
|
} else {
|
2018-03-19 18:22:38 +00:00
|
|
|
if (p_colors.size() != p_points.size()) {
|
|
|
|
pline->triangle_colors.push_back(p_colors[0]);
|
|
|
|
pline->line_colors.push_back(p_colors[0]);
|
|
|
|
} else {
|
|
|
|
pline->triangle_colors.resize(pline->triangles.size());
|
|
|
|
pline->line_colors.resize(pline->lines.size());
|
|
|
|
}
|
2017-07-01 00:30:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < p_points.size(); i++) {
|
|
|
|
|
|
|
|
Vector2 t;
|
|
|
|
if (i == p_points.size() - 1) {
|
|
|
|
t = prev_t;
|
|
|
|
} else {
|
|
|
|
t = (p_points[i + 1] - p_points[i]).normalized().tangent();
|
|
|
|
if (i == 0) {
|
|
|
|
prev_t = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2 tangent = ((t + prev_t).normalized()) * p_width * 0.5;
|
|
|
|
|
|
|
|
if (p_antialiased) {
|
2018-07-25 01:11:03 +00:00
|
|
|
pline->lines.write[i] = p_points[i] + tangent;
|
|
|
|
pline->lines.write[p_points.size() * 2 - i - 1] = p_points[i] - tangent;
|
2017-07-01 00:30:17 +00:00
|
|
|
if (pline->line_colors.size() > 1) {
|
2018-07-25 01:11:03 +00:00
|
|
|
pline->line_colors.write[i] = p_colors[i];
|
|
|
|
pline->line_colors.write[p_points.size() * 2 - i - 1] = p_colors[i];
|
2017-07-01 00:30:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
pline->triangles.write[i * 2 + 0] = p_points[i] + tangent;
|
|
|
|
pline->triangles.write[i * 2 + 1] = p_points[i] - tangent;
|
2017-07-01 00:30:17 +00:00
|
|
|
|
|
|
|
if (pline->triangle_colors.size() > 1) {
|
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
pline->triangle_colors.write[i * 2 + 0] = p_colors[i];
|
|
|
|
pline->triangle_colors.write[i * 2 + 1] = p_colors[i];
|
2017-07-01 00:30:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
prev_t = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
canvas_item->rect_dirty = true;
|
|
|
|
canvas_item->commands.push_back(pline);
|
|
|
|
}
|
|
|
|
|
2017-12-09 17:11:26 +00:00
|
|
|
void VisualServerCanvas::canvas_item_add_multiline(RID p_item, const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width, bool p_antialiased) {
|
|
|
|
|
|
|
|
ERR_FAIL_COND(p_points.size() < 2);
|
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
|
|
|
Item::CommandPolyLine *pline = memnew(Item::CommandPolyLine);
|
|
|
|
ERR_FAIL_COND(!pline);
|
|
|
|
|
|
|
|
pline->antialiased = false; //todo
|
|
|
|
pline->multiline = true;
|
|
|
|
|
|
|
|
pline->lines = p_points;
|
|
|
|
pline->line_colors = p_colors;
|
|
|
|
if (pline->line_colors.size() == 0) {
|
|
|
|
pline->line_colors.push_back(Color(1, 1, 1, 1));
|
|
|
|
} else if (pline->line_colors.size() > 1 && pline->line_colors.size() != pline->lines.size()) {
|
|
|
|
pline->line_colors.resize(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
canvas_item->rect_dirty = true;
|
|
|
|
canvas_item->commands.push_back(pline);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_add_rect(RID p_item, const Rect2 &p_rect, const Color &p_color) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item::CommandRect *rect = memnew(Item::CommandRect);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!rect);
|
2017-03-05 15:44:50 +00:00
|
|
|
rect->modulate = p_color;
|
|
|
|
rect->rect = p_rect;
|
|
|
|
canvas_item->rect_dirty = true;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
canvas_item->commands.push_back(rect);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_add_circle(RID p_item, const Point2 &p_pos, float p_radius, const Color &p_color) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item::CommandCircle *circle = memnew(Item::CommandCircle);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!circle);
|
2017-03-05 15:44:50 +00:00
|
|
|
circle->color = p_color;
|
|
|
|
circle->pos = p_pos;
|
|
|
|
circle->radius = p_radius;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
canvas_item->commands.push_back(circle);
|
|
|
|
}
|
|
|
|
|
2017-06-18 02:26:49 +00:00
|
|
|
void VisualServerCanvas::canvas_item_add_texture_rect(RID p_item, const Rect2 &p_rect, RID p_texture, bool p_tile, const Color &p_modulate, bool p_transpose, RID p_normal_map) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item::CommandRect *rect = memnew(Item::CommandRect);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!rect);
|
2017-03-05 15:44:50 +00:00
|
|
|
rect->modulate = p_modulate;
|
|
|
|
rect->rect = p_rect;
|
|
|
|
rect->flags = 0;
|
2016-10-03 19:33:42 +00:00
|
|
|
if (p_tile) {
|
2017-03-05 15:44:50 +00:00
|
|
|
rect->flags |= RasterizerCanvas::CANVAS_RECT_TILE;
|
|
|
|
rect->flags |= RasterizerCanvas::CANVAS_RECT_REGION;
|
|
|
|
rect->source = Rect2(0, 0, p_rect.size.width, p_rect.size.height);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_rect.size.x < 0) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
rect->flags |= RasterizerCanvas::CANVAS_RECT_FLIP_H;
|
2016-10-03 19:33:42 +00:00
|
|
|
rect->rect.size.x = -rect->rect.size.x;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_rect.size.y < 0) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
rect->flags |= RasterizerCanvas::CANVAS_RECT_FLIP_V;
|
2016-10-03 19:33:42 +00:00
|
|
|
rect->rect.size.y = -rect->rect.size.y;
|
|
|
|
}
|
|
|
|
if (p_transpose) {
|
2017-03-05 15:44:50 +00:00
|
|
|
rect->flags |= RasterizerCanvas::CANVAS_RECT_TRANSPOSE;
|
2016-10-03 19:33:42 +00:00
|
|
|
SWAP(rect->rect.size.x, rect->rect.size.y);
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
rect->texture = p_texture;
|
2017-06-18 02:26:49 +00:00
|
|
|
rect->normal_map = p_normal_map;
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->rect_dirty = true;
|
2016-10-03 19:33:42 +00:00
|
|
|
canvas_item->commands.push_back(rect);
|
|
|
|
}
|
|
|
|
|
2017-06-19 01:55:02 +00:00
|
|
|
void VisualServerCanvas::canvas_item_add_texture_rect_region(RID p_item, const Rect2 &p_rect, RID p_texture, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, RID p_normal_map, bool p_clip_uv) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item::CommandRect *rect = memnew(Item::CommandRect);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!rect);
|
2017-03-05 15:44:50 +00:00
|
|
|
rect->modulate = p_modulate;
|
|
|
|
rect->rect = p_rect;
|
|
|
|
rect->texture = p_texture;
|
2017-06-18 02:26:49 +00:00
|
|
|
rect->normal_map = p_normal_map;
|
2017-03-05 15:44:50 +00:00
|
|
|
rect->source = p_src_rect;
|
|
|
|
rect->flags = RasterizerCanvas::CANVAS_RECT_REGION;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_rect.size.x < 0) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
rect->flags |= RasterizerCanvas::CANVAS_RECT_FLIP_H;
|
2016-10-03 19:33:42 +00:00
|
|
|
rect->rect.size.x = -rect->rect.size.x;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_rect.size.y < 0) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
rect->flags |= RasterizerCanvas::CANVAS_RECT_FLIP_V;
|
2016-10-03 19:33:42 +00:00
|
|
|
rect->rect.size.y = -rect->rect.size.y;
|
|
|
|
}
|
|
|
|
if (p_transpose) {
|
2017-03-05 15:44:50 +00:00
|
|
|
rect->flags |= RasterizerCanvas::CANVAS_RECT_TRANSPOSE;
|
2016-10-03 19:33:42 +00:00
|
|
|
SWAP(rect->rect.size.x, rect->rect.size.y);
|
|
|
|
}
|
|
|
|
|
2017-06-19 01:55:02 +00:00
|
|
|
if (p_clip_uv) {
|
|
|
|
rect->flags |= RasterizerCanvas::CANVAS_RECT_CLIP_UV;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->rect_dirty = true;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
canvas_item->commands.push_back(rect);
|
|
|
|
}
|
|
|
|
|
2017-06-18 02:26:49 +00:00
|
|
|
void VisualServerCanvas::canvas_item_add_nine_patch(RID p_item, const Rect2 &p_rect, const Rect2 &p_source, RID p_texture, const Vector2 &p_topleft, const Vector2 &p_bottomright, VS::NinePatchAxisMode p_x_axis_mode, VS::NinePatchAxisMode p_y_axis_mode, bool p_draw_center, const Color &p_modulate, RID p_normal_map) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item::CommandNinePatch *style = memnew(Item::CommandNinePatch);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!style);
|
2017-03-05 15:44:50 +00:00
|
|
|
style->texture = p_texture;
|
2017-06-18 02:26:49 +00:00
|
|
|
style->normal_map = p_normal_map;
|
2017-03-05 15:44:50 +00:00
|
|
|
style->rect = p_rect;
|
|
|
|
style->source = p_source;
|
|
|
|
style->draw_center = p_draw_center;
|
|
|
|
style->color = p_modulate;
|
|
|
|
style->margin[MARGIN_LEFT] = p_topleft.x;
|
|
|
|
style->margin[MARGIN_TOP] = p_topleft.y;
|
|
|
|
style->margin[MARGIN_RIGHT] = p_bottomright.x;
|
|
|
|
style->margin[MARGIN_BOTTOM] = p_bottomright.y;
|
|
|
|
style->axis_x = p_x_axis_mode;
|
|
|
|
style->axis_y = p_y_axis_mode;
|
|
|
|
canvas_item->rect_dirty = true;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
canvas_item->commands.push_back(style);
|
|
|
|
}
|
2017-06-18 02:26:49 +00:00
|
|
|
void VisualServerCanvas::canvas_item_add_primitive(RID p_item, const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, RID p_texture, float p_width, RID p_normal_map) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item::CommandPrimitive *prim = memnew(Item::CommandPrimitive);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!prim);
|
2017-03-05 15:44:50 +00:00
|
|
|
prim->texture = p_texture;
|
2017-06-18 02:26:49 +00:00
|
|
|
prim->normal_map = p_normal_map;
|
2017-03-05 15:44:50 +00:00
|
|
|
prim->points = p_points;
|
|
|
|
prim->uvs = p_uvs;
|
|
|
|
prim->colors = p_colors;
|
|
|
|
prim->width = p_width;
|
|
|
|
canvas_item->rect_dirty = true;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
canvas_item->commands.push_back(prim);
|
|
|
|
}
|
|
|
|
|
2017-08-19 16:14:04 +00:00
|
|
|
void VisualServerCanvas::canvas_item_add_polygon(RID p_item, const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, RID p_texture, RID p_normal_map, bool p_antialiased) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
int pointcount = p_points.size();
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(pointcount < 3);
|
|
|
|
int color_size = p_colors.size();
|
|
|
|
int uv_size = p_uvs.size();
|
|
|
|
ERR_FAIL_COND(color_size != 0 && color_size != 1 && color_size != pointcount);
|
2018-07-29 23:47:20 +00:00
|
|
|
ERR_FAIL_COND(uv_size != 0 && (uv_size != pointcount));
|
2016-10-03 19:33:42 +00:00
|
|
|
#endif
|
|
|
|
Vector<int> indices = Geometry::triangulate_polygon(p_points);
|
|
|
|
|
|
|
|
if (indices.empty()) {
|
|
|
|
|
|
|
|
ERR_EXPLAIN("Bad Polygon!");
|
2018-10-04 13:38:52 +00:00
|
|
|
ERR_FAIL();
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item::CommandPolygon *polygon = memnew(Item::CommandPolygon);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!polygon);
|
2017-03-05 15:44:50 +00:00
|
|
|
polygon->texture = p_texture;
|
2017-06-18 02:26:49 +00:00
|
|
|
polygon->normal_map = p_normal_map;
|
2017-03-05 15:44:50 +00:00
|
|
|
polygon->points = p_points;
|
|
|
|
polygon->uvs = p_uvs;
|
|
|
|
polygon->colors = p_colors;
|
|
|
|
polygon->indices = indices;
|
|
|
|
polygon->count = indices.size();
|
2017-08-19 16:14:04 +00:00
|
|
|
polygon->antialiased = p_antialiased;
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->rect_dirty = true;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
canvas_item->commands.push_back(polygon);
|
|
|
|
}
|
|
|
|
|
2018-05-03 20:29:15 +00:00
|
|
|
void VisualServerCanvas::canvas_item_add_triangle_array(RID p_item, const Vector<int> &p_indices, const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, const Vector<int> &p_bones, const Vector<float> &p_weights, RID p_texture, int p_count, RID p_normal_map) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
|
|
|
int ps = p_points.size();
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(!p_colors.empty() && p_colors.size() != ps && p_colors.size() != 1);
|
|
|
|
ERR_FAIL_COND(!p_uvs.empty() && p_uvs.size() != ps);
|
2018-05-03 20:29:15 +00:00
|
|
|
ERR_FAIL_COND(!p_bones.empty() && p_bones.size() != ps * 4);
|
|
|
|
ERR_FAIL_COND(!p_weights.empty() && p_weights.size() != ps * 4);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
Vector<int> indices = p_indices;
|
|
|
|
|
|
|
|
int count = p_count * 3;
|
|
|
|
|
|
|
|
if (indices.empty()) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(ps % 3 != 0);
|
2016-10-03 19:33:42 +00:00
|
|
|
if (p_count == -1)
|
|
|
|
count = ps;
|
|
|
|
} else {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(indices.size() % 3 != 0);
|
2016-10-03 19:33:42 +00:00
|
|
|
if (p_count == -1)
|
|
|
|
count = indices.size();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item::CommandPolygon *polygon = memnew(Item::CommandPolygon);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!polygon);
|
2017-03-05 15:44:50 +00:00
|
|
|
polygon->texture = p_texture;
|
2017-06-18 02:26:49 +00:00
|
|
|
polygon->normal_map = p_normal_map;
|
2017-03-05 15:44:50 +00:00
|
|
|
polygon->points = p_points;
|
|
|
|
polygon->uvs = p_uvs;
|
|
|
|
polygon->colors = p_colors;
|
2018-05-03 20:29:15 +00:00
|
|
|
polygon->bones = p_bones;
|
|
|
|
polygon->weights = p_weights;
|
2017-03-05 15:44:50 +00:00
|
|
|
polygon->indices = indices;
|
2016-10-03 19:33:42 +00:00
|
|
|
polygon->count = count;
|
2017-08-28 21:37:42 +00:00
|
|
|
polygon->antialiased = false;
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->rect_dirty = true;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
canvas_item->commands.push_back(polygon);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_add_set_transform(RID p_item, const Transform2D &p_transform) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item::CommandTransform *tr = memnew(Item::CommandTransform);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!tr);
|
2017-03-05 15:44:50 +00:00
|
|
|
tr->xform = p_transform;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
canvas_item->commands.push_back(tr);
|
|
|
|
}
|
|
|
|
|
2018-02-21 20:23:27 +00:00
|
|
|
void VisualServerCanvas::canvas_item_add_mesh(RID p_item, const RID &p_mesh, RID p_texture, RID p_normal_map) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item::CommandMesh *m = memnew(Item::CommandMesh);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!m);
|
2017-03-05 15:44:50 +00:00
|
|
|
m->mesh = p_mesh;
|
2018-02-21 12:38:21 +00:00
|
|
|
m->texture = p_texture;
|
|
|
|
m->normal_map = p_normal_map;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
canvas_item->commands.push_back(m);
|
|
|
|
}
|
2018-09-27 11:05:57 +00:00
|
|
|
void VisualServerCanvas::canvas_item_add_particles(RID p_item, RID p_particles, RID p_texture, RID p_normal) {
|
2017-06-21 19:25:45 +00:00
|
|
|
|
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
|
|
|
Item::CommandParticles *part = memnew(Item::CommandParticles);
|
|
|
|
ERR_FAIL_COND(!part);
|
|
|
|
part->particles = p_particles;
|
|
|
|
part->texture = p_texture;
|
|
|
|
part->normal_map = p_normal;
|
|
|
|
|
|
|
|
//take the chance and request processing for them, at least once until they become visible again
|
|
|
|
VSG::storage->particles_request_process(p_particles);
|
|
|
|
|
2017-08-19 16:14:04 +00:00
|
|
|
canvas_item->rect_dirty = true;
|
2017-06-21 19:25:45 +00:00
|
|
|
canvas_item->commands.push_back(part);
|
|
|
|
}
|
|
|
|
|
2018-02-21 20:23:27 +00:00
|
|
|
void VisualServerCanvas::canvas_item_add_multimesh(RID p_item, RID p_mesh, RID p_texture, RID p_normal_map) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item::CommandMultiMesh *mm = memnew(Item::CommandMultiMesh);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!mm);
|
2017-03-05 15:44:50 +00:00
|
|
|
mm->multimesh = p_mesh;
|
2018-02-21 12:38:21 +00:00
|
|
|
mm->texture = p_texture;
|
|
|
|
mm->normal_map = p_normal_map;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-08-19 16:14:04 +00:00
|
|
|
canvas_item->rect_dirty = true;
|
2016-10-03 19:33:42 +00:00
|
|
|
canvas_item->commands.push_back(mm);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_add_clip_ignore(RID p_item, bool p_ignore) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item::CommandClipIgnore *ci = memnew(Item::CommandClipIgnore);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!ci);
|
2017-03-05 15:44:50 +00:00
|
|
|
ci->ignore = p_ignore;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
canvas_item->commands.push_back(ci);
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_set_sort_children_by_y(RID p_item, bool p_enable) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->sort_y = p_enable;
|
2018-10-30 18:00:31 +00:00
|
|
|
canvas_item->ysort_children_count = -1;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-12-29 22:06:03 +00:00
|
|
|
void VisualServerCanvas::canvas_item_set_z_index(RID p_item, int p_z) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(p_z < VS::CANVAS_ITEM_Z_MIN || p_z > VS::CANVAS_ITEM_Z_MAX);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-12-29 22:06:03 +00:00
|
|
|
canvas_item->z_index = p_z;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_set_z_as_relative_to_parent(RID p_item, bool p_enable) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->z_relative = p_enable;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2018-02-21 20:23:27 +00:00
|
|
|
|
|
|
|
void VisualServerCanvas::canvas_item_attach_skeleton(RID p_item, RID p_skeleton) {
|
|
|
|
|
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
|
|
|
canvas_item->skeleton = p_skeleton;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_set_copy_to_backbuffer(RID p_item, bool p_enable, const Rect2 &p_rect) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (bool(canvas_item->copy_back_buffer != NULL) != p_enable) {
|
2016-10-03 19:33:42 +00:00
|
|
|
if (p_enable) {
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->copy_back_buffer = memnew(RasterizerCanvas::Item::CopyBackBuffer);
|
2016-10-03 19:33:42 +00:00
|
|
|
} else {
|
|
|
|
memdelete(canvas_item->copy_back_buffer);
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->copy_back_buffer = NULL;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_enable) {
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->copy_back_buffer->rect = p_rect;
|
|
|
|
canvas_item->copy_back_buffer->full = p_rect == Rect2();
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_clear(RID p_item) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
|
|
|
canvas_item->clear();
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_set_draw_index(RID p_item, int p_index) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.getornull(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->index = p_index;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (canvas_item_owner.owns(canvas_item->parent)) {
|
|
|
|
Item *canvas_item_parent = canvas_item_owner.getornull(canvas_item->parent);
|
|
|
|
canvas_item_parent->children_order_dirty = true;
|
2016-10-03 19:33:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Canvas *canvas = canvas_owner.getornull(canvas_item->parent);
|
2016-10-03 19:33:42 +00:00
|
|
|
if (canvas) {
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas->children_order_dirty = true;
|
2016-10-03 19:33:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_set_material(RID p_item, RID p_material) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.get(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->material = p_material;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_item_set_use_parent_material(RID p_item, bool p_enable) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Item *canvas_item = canvas_item_owner.get(p_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!canvas_item);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->use_parent_material = p_enable;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
RID VisualServerCanvas::canvas_light_create() {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
RasterizerCanvas::Light *clight = memnew(RasterizerCanvas::Light);
|
2016-10-03 19:33:42 +00:00
|
|
|
clight->light_internal = VSG::canvas_render->light_internal_create();
|
|
|
|
return canvas_light_owner.make_rid(clight);
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_attach_to_canvas(RID p_light, RID p_canvas) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
|
|
|
|
if (clight->canvas.is_valid()) {
|
|
|
|
|
|
|
|
Canvas *canvas = canvas_owner.getornull(clight->canvas);
|
|
|
|
canvas->lights.erase(clight);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!canvas_owner.owns(p_canvas))
|
2017-03-05 15:44:50 +00:00
|
|
|
p_canvas = RID();
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->canvas = p_canvas;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
if (clight->canvas.is_valid()) {
|
|
|
|
|
|
|
|
Canvas *canvas = canvas_owner.get(clight->canvas);
|
|
|
|
canvas->lights.insert(clight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_set_enabled(RID p_light, bool p_enabled) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->enabled = p_enabled;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_set_scale(RID p_light, float p_scale) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->scale = p_scale;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_set_transform(RID p_light, const Transform2D &p_transform) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->xform = p_transform;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_set_texture(RID p_light, RID p_texture) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->texture = p_texture;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_set_texture_offset(RID p_light, const Vector2 &p_offset) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->texture_offset = p_offset;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_set_color(RID p_light, const Color &p_color) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->color = p_color;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_set_height(RID p_light, float p_height) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->height = p_height;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_set_energy(RID p_light, float p_energy) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->energy = p_energy;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_set_z_range(RID p_light, int p_min_z, int p_max_z) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->z_min = p_min_z;
|
|
|
|
clight->z_max = p_max_z;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_set_layer_range(RID p_light, int p_min_layer, int p_max_layer) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->layer_max = p_max_layer;
|
|
|
|
clight->layer_min = p_min_layer;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_set_item_cull_mask(RID p_light, int p_mask) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->item_mask = p_mask;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_set_item_shadow_cull_mask(RID p_light, int p_mask) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->item_shadow_mask = p_mask;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_set_mode(RID p_light, VS::CanvasLightMode p_mode) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->mode = p_mode;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_set_shadow_enabled(RID p_light, bool p_enabled) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (clight->shadow_buffer.is_valid() == p_enabled)
|
2016-10-03 19:33:42 +00:00
|
|
|
return;
|
|
|
|
if (p_enabled) {
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->shadow_buffer = VSG::storage->canvas_light_shadow_buffer_create(clight->shadow_buffer_size);
|
2016-10-03 19:33:42 +00:00
|
|
|
} else {
|
|
|
|
VSG::storage->free(clight->shadow_buffer);
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->shadow_buffer = RID();
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_set_shadow_buffer_size(RID p_light, int p_size) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(p_size < 32 || p_size > 16384);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
|
2017-08-17 21:35:55 +00:00
|
|
|
int new_size = next_power_of_2(p_size);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (new_size == clight->shadow_buffer_size)
|
2016-10-03 19:33:42 +00:00
|
|
|
return;
|
|
|
|
|
2017-08-17 21:35:55 +00:00
|
|
|
clight->shadow_buffer_size = next_power_of_2(p_size);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
if (clight->shadow_buffer.is_valid()) {
|
|
|
|
VSG::storage->free(clight->shadow_buffer);
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->shadow_buffer = VSG::storage->canvas_light_shadow_buffer_create(clight->shadow_buffer_size);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualServerCanvas::canvas_light_set_shadow_gradient_length(RID p_light, float p_length) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(p_length < 0);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->shadow_gradient_length = p_length;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
void VisualServerCanvas::canvas_light_set_shadow_filter(RID p_light, VS::CanvasLightShadowFilter p_filter) {
|
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->shadow_filter = p_filter;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_set_shadow_color(RID p_light, const Color &p_color) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
clight->shadow_color = p_color;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-06-13 04:23:04 +00:00
|
|
|
void VisualServerCanvas::canvas_light_set_shadow_smooth(RID p_light, float p_smooth) {
|
|
|
|
|
|
|
|
RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light);
|
|
|
|
ERR_FAIL_COND(!clight);
|
|
|
|
clight->shadow_smooth = p_smooth;
|
|
|
|
}
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
RID VisualServerCanvas::canvas_light_occluder_create() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
RasterizerCanvas::LightOccluderInstance *occluder = memnew(RasterizerCanvas::LightOccluderInstance);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
return canvas_light_occluder_owner.make_rid(occluder);
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_occluder_attach_to_canvas(RID p_occluder, RID p_canvas) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.get(p_occluder);
|
|
|
|
ERR_FAIL_COND(!occluder);
|
|
|
|
|
|
|
|
if (occluder->canvas.is_valid()) {
|
|
|
|
|
|
|
|
Canvas *canvas = canvas_owner.get(occluder->canvas);
|
|
|
|
canvas->occluders.erase(occluder);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!canvas_owner.owns(p_canvas))
|
2017-03-05 15:44:50 +00:00
|
|
|
p_canvas = RID();
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
occluder->canvas = p_canvas;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
if (occluder->canvas.is_valid()) {
|
|
|
|
|
|
|
|
Canvas *canvas = canvas_owner.get(occluder->canvas);
|
|
|
|
canvas->occluders.insert(occluder);
|
|
|
|
}
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_occluder_set_enabled(RID p_occluder, bool p_enabled) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.get(p_occluder);
|
|
|
|
ERR_FAIL_COND(!occluder);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
occluder->enabled = p_enabled;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_occluder_set_polygon(RID p_occluder, RID p_polygon) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.get(p_occluder);
|
|
|
|
ERR_FAIL_COND(!occluder);
|
|
|
|
|
|
|
|
if (occluder->polygon.is_valid()) {
|
|
|
|
LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get(p_polygon);
|
|
|
|
if (occluder_poly) {
|
|
|
|
occluder_poly->owners.erase(occluder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
occluder->polygon = p_polygon;
|
|
|
|
occluder->polygon_buffer = RID();
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
if (occluder->polygon.is_valid()) {
|
|
|
|
LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get(p_polygon);
|
2017-08-25 15:14:33 +00:00
|
|
|
if (!occluder_poly) {
|
2017-03-05 15:44:50 +00:00
|
|
|
occluder->polygon = RID();
|
2017-08-25 15:14:33 +00:00
|
|
|
ERR_FAIL_COND(!occluder_poly);
|
|
|
|
} else {
|
|
|
|
occluder_poly->owners.insert(occluder);
|
|
|
|
occluder->polygon_buffer = occluder_poly->occluder;
|
|
|
|
occluder->aabb_cache = occluder_poly->aabb;
|
|
|
|
occluder->cull_cache = occluder_poly->cull_mode;
|
|
|
|
}
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_occluder_set_transform(RID p_occluder, const Transform2D &p_xform) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.get(p_occluder);
|
|
|
|
ERR_FAIL_COND(!occluder);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
occluder->xform = p_xform;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_light_occluder_set_light_mask(RID p_occluder, int p_mask) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.get(p_occluder);
|
|
|
|
ERR_FAIL_COND(!occluder);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
occluder->light_mask = p_mask;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RID VisualServerCanvas::canvas_occluder_polygon_create() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
LightOccluderPolygon *occluder_poly = memnew(LightOccluderPolygon);
|
|
|
|
occluder_poly->occluder = VSG::storage->canvas_light_occluder_create();
|
2016-10-03 19:33:42 +00:00
|
|
|
return canvas_light_occluder_polygon_owner.make_rid(occluder_poly);
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_occluder_polygon_set_shape(RID p_occluder_polygon, const PoolVector<Vector2> &p_shape, bool p_closed) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_shape.size() < 3) {
|
|
|
|
canvas_occluder_polygon_set_shape_as_lines(p_occluder_polygon, p_shape);
|
2016-10-03 19:33:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-07 21:25:37 +00:00
|
|
|
PoolVector<Vector2> lines;
|
2017-03-05 15:44:50 +00:00
|
|
|
int lc = p_shape.size() * 2;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
lines.resize(lc - (p_closed ? 0 : 2));
|
2016-10-03 19:33:42 +00:00
|
|
|
{
|
2017-01-07 21:25:37 +00:00
|
|
|
PoolVector<Vector2>::Write w = lines.write();
|
|
|
|
PoolVector<Vector2>::Read r = p_shape.read();
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int max = lc / 2;
|
2016-10-03 19:33:42 +00:00
|
|
|
if (!p_closed) {
|
|
|
|
max--;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < max; i++) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
Vector2 a = r[i];
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector2 b = r[(i + 1) % (lc / 2)];
|
|
|
|
w[i * 2 + 0] = a;
|
|
|
|
w[i * 2 + 1] = b;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_occluder_polygon_set_shape_as_lines(p_occluder_polygon, lines);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_occluder_polygon_set_shape_as_lines(RID p_occluder_polygon, const PoolVector<Vector2> &p_shape) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get(p_occluder_polygon);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!occluder_poly);
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(p_shape.size() & 1);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
int lc = p_shape.size();
|
2017-03-05 15:44:50 +00:00
|
|
|
occluder_poly->aabb = Rect2();
|
2016-10-03 19:33:42 +00:00
|
|
|
{
|
2017-01-07 21:25:37 +00:00
|
|
|
PoolVector<Vector2>::Read r = p_shape.read();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < lc; i++) {
|
|
|
|
if (i == 0)
|
2017-06-03 22:25:13 +00:00
|
|
|
occluder_poly->aabb.position = r[i];
|
2016-10-03 19:33:42 +00:00
|
|
|
else
|
|
|
|
occluder_poly->aabb.expand_to(r[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
VSG::storage->canvas_light_occluder_set_polylines(occluder_poly->occluder, p_shape);
|
|
|
|
for (Set<RasterizerCanvas::LightOccluderInstance *>::Element *E = occluder_poly->owners.front(); E; E = E->next()) {
|
|
|
|
E->get()->aabb_cache = occluder_poly->aabb;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerCanvas::canvas_occluder_polygon_set_cull_mode(RID p_occluder_polygon, VS::CanvasOccluderPolygonCullMode p_mode) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get(p_occluder_polygon);
|
2016-10-03 19:33:42 +00:00
|
|
|
ERR_FAIL_COND(!occluder_poly);
|
2017-03-05 15:44:50 +00:00
|
|
|
occluder_poly->cull_mode = p_mode;
|
|
|
|
for (Set<RasterizerCanvas::LightOccluderInstance *>::Element *E = occluder_poly->owners.front(); E; E = E->next()) {
|
|
|
|
E->get()->cull_cache = p_mode;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisualServerCanvas::free(RID p_rid) {
|
|
|
|
|
|
|
|
if (canvas_owner.owns(p_rid)) {
|
|
|
|
|
|
|
|
Canvas *canvas = canvas_owner.get(p_rid);
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!canvas, false);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (canvas->viewports.size()) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
VisualServerViewport::Viewport *vp = VSG::viewport->viewport_owner.get(canvas->viewports.front()->get());
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!vp, true);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Map<RID, VisualServerViewport::Viewport::CanvasData>::Element *E = vp->canvas_map.find(p_rid);
|
|
|
|
ERR_FAIL_COND_V(!E, true);
|
2016-10-03 19:33:42 +00:00
|
|
|
vp->canvas_map.erase(p_rid);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas->viewports.erase(canvas->viewports.front());
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < canvas->child_items.size(); i++) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas->child_items[i].item->parent = RID();
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Set<RasterizerCanvas::Light *>::Element *E = canvas->lights.front(); E; E = E->next()) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
E->get()->canvas = RID();
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Set<RasterizerCanvas::LightOccluderInstance *>::Element *E = canvas->occluders.front(); E; E = E->next()) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
E->get()->canvas = RID();
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_owner.free(p_rid);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
memdelete(canvas);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
} else if (canvas_item_owner.owns(p_rid)) {
|
|
|
|
|
|
|
|
Item *canvas_item = canvas_item_owner.get(p_rid);
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!canvas_item, true);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
if (canvas_item->parent.is_valid()) {
|
|
|
|
|
|
|
|
if (canvas_owner.owns(canvas_item->parent)) {
|
|
|
|
|
|
|
|
Canvas *canvas = canvas_owner.get(canvas_item->parent);
|
|
|
|
canvas->erase_item(canvas_item);
|
|
|
|
} else if (canvas_item_owner.owns(canvas_item->parent)) {
|
|
|
|
|
|
|
|
Item *item_owner = canvas_item_owner.get(canvas_item->parent);
|
|
|
|
item_owner->child_items.erase(canvas_item);
|
2018-11-21 13:01:11 +00:00
|
|
|
|
|
|
|
Item *ysort_owner = item_owner;
|
|
|
|
while (ysort_owner && ysort_owner->sort_y) {
|
|
|
|
item_owner->ysort_children_count = -1;
|
|
|
|
ysort_owner = canvas_item_owner.getornull(ysort_owner->parent);
|
|
|
|
}
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < canvas_item->child_items.size(); i++) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item->child_items[i]->parent = RID();
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
/*
|
|
|
|
if (canvas_item->material) {
|
|
|
|
canvas_item->material->owners.erase(canvas_item);
|
|
|
|
}
|
|
|
|
*/
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_item_owner.free(p_rid);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
memdelete(canvas_item);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
} else if (canvas_light_owner.owns(p_rid)) {
|
|
|
|
|
|
|
|
RasterizerCanvas::Light *canvas_light = canvas_light_owner.get(p_rid);
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!canvas_light, true);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
if (canvas_light->canvas.is_valid()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
Canvas *canvas = canvas_owner.get(canvas_light->canvas);
|
2016-10-03 19:33:42 +00:00
|
|
|
if (canvas)
|
|
|
|
canvas->lights.erase(canvas_light);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (canvas_light->shadow_buffer.is_valid())
|
|
|
|
VSG::storage->free(canvas_light->shadow_buffer);
|
|
|
|
|
|
|
|
VSG::canvas_render->light_internal_free(canvas_light->light_internal);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_light_owner.free(p_rid);
|
|
|
|
memdelete(canvas_light);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
} else if (canvas_light_occluder_owner.owns(p_rid)) {
|
|
|
|
|
|
|
|
RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.get(p_rid);
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!occluder, true);
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
if (occluder->polygon.is_valid()) {
|
|
|
|
|
|
|
|
LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get(occluder->polygon);
|
|
|
|
if (occluder_poly) {
|
|
|
|
occluder_poly->owners.erase(occluder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (occluder->canvas.is_valid() && canvas_owner.owns(occluder->canvas)) {
|
|
|
|
|
|
|
|
Canvas *canvas = canvas_owner.get(occluder->canvas);
|
|
|
|
canvas->occluders.erase(occluder);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_light_occluder_owner.free(p_rid);
|
2016-10-03 19:33:42 +00:00
|
|
|
memdelete(occluder);
|
|
|
|
|
|
|
|
} else if (canvas_light_occluder_polygon_owner.owns(p_rid)) {
|
|
|
|
|
|
|
|
LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get(p_rid);
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!occluder_poly, true);
|
2016-10-03 19:33:42 +00:00
|
|
|
VSG::storage->free(occluder_poly->occluder);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (occluder_poly->owners.size()) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
occluder_poly->owners.front()->get()->polygon = RID();
|
|
|
|
occluder_poly->owners.erase(occluder_poly->owners.front());
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
canvas_light_occluder_polygon_owner.free(p_rid);
|
2016-10-03 19:33:42 +00:00
|
|
|
memdelete(occluder_poly);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
VisualServerCanvas::VisualServerCanvas() {
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|