diff options
84 files changed, 2921 insertions, 1224 deletions
diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h index bae8cf7fca..83c90a925c 100644 --- a/core/command_queue_mt.h +++ b/core/command_queue_mt.h @@ -170,6 +170,43 @@ class CommandQueueMT { virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8); } }; + template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9> + struct Command9 : public CommandBase { + + T *instance; + M method; + typename GetSimpleTypeT<P1>::type_t p1; + typename GetSimpleTypeT<P2>::type_t p2; + typename GetSimpleTypeT<P3>::type_t p3; + typename GetSimpleTypeT<P4>::type_t p4; + typename GetSimpleTypeT<P5>::type_t p5; + typename GetSimpleTypeT<P6>::type_t p6; + typename GetSimpleTypeT<P7>::type_t p7; + typename GetSimpleTypeT<P8>::type_t p8; + typename GetSimpleTypeT<P9>::type_t p9; + + virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8, p9); } + }; + + template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9, class P10> + struct Command10 : public CommandBase { + + T *instance; + M method; + typename GetSimpleTypeT<P1>::type_t p1; + typename GetSimpleTypeT<P2>::type_t p2; + typename GetSimpleTypeT<P3>::type_t p3; + typename GetSimpleTypeT<P4>::type_t p4; + typename GetSimpleTypeT<P5>::type_t p5; + typename GetSimpleTypeT<P6>::type_t p6; + typename GetSimpleTypeT<P7>::type_t p7; + typename GetSimpleTypeT<P8>::type_t p8; + typename GetSimpleTypeT<P9>::type_t p9; + typename GetSimpleTypeT<P10>::type_t p10; + + virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); } + }; + /* comands that return */ template <class T, class M, class R> @@ -779,6 +816,52 @@ public: if (sync) sync->post(); } + + template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9> + void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9) { + + Command9<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9> *cmd = allocate_and_lock<Command9<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9> >(); + + cmd->instance = p_instance; + cmd->method = p_method; + cmd->p1 = p1; + cmd->p2 = p2; + cmd->p3 = p3; + cmd->p4 = p4; + cmd->p5 = p5; + cmd->p6 = p6; + cmd->p7 = p7; + cmd->p8 = p8; + cmd->p9 = p9; + + unlock(); + + if (sync) sync->post(); + } + + template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9, class P10> + void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10) { + + Command10<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10> *cmd = allocate_and_lock<Command10<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10> >(); + + cmd->instance = p_instance; + cmd->method = p_method; + cmd->p1 = p1; + cmd->p2 = p2; + cmd->p3 = p3; + cmd->p4 = p4; + cmd->p5 = p5; + cmd->p6 = p6; + cmd->p7 = p7; + cmd->p8 = p8; + cmd->p9 = p9; + cmd->p10 = p10; + + unlock(); + + if (sync) sync->post(); + } + /*** PUSH AND RET COMMANDS ***/ template <class T, class M, class R> diff --git a/core/helper/math_fieldwise.cpp b/core/helper/math_fieldwise.cpp index cf45902bf9..5545c2d642 100644 --- a/core/helper/math_fieldwise.cpp +++ b/core/helper/math_fieldwise.cpp @@ -110,9 +110,9 @@ Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const SETUP_TYPE(Rect3) - /**/ TRY_TRANSFER_FIELD("px", pos.x) - else TRY_TRANSFER_FIELD("py", pos.y) - else TRY_TRANSFER_FIELD("pz", pos.z) + /**/ TRY_TRANSFER_FIELD("px", position.x) + else TRY_TRANSFER_FIELD("py", position.y) + else TRY_TRANSFER_FIELD("pz", position.z) else TRY_TRANSFER_FIELD("sx", size.x) else TRY_TRANSFER_FIELD("sy", size.y) else TRY_TRANSFER_FIELD("sz", size.z) diff --git a/core/image.cpp b/core/image.cpp index 2da91c7b13..686735c906 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -81,21 +81,21 @@ const char *Image::format_names[Image::FORMAT_MAX] = { SavePNGFunc Image::save_png_func = NULL; -void Image::_put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_dst, const uint8_t *p_src) { +void Image::_put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_data, const uint8_t *p_pixel) { uint32_t ofs = (p_y * width + p_x) * p_pixelsize; for (uint32_t i = 0; i < p_pixelsize; i++) { - p_dst[ofs + i] = p_src[i]; + p_data[ofs + i] = p_pixel[i]; } } -void Image::_get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p_src, uint8_t *p_dst) { +void Image::_get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p_data, uint8_t *p_pixel) { uint32_t ofs = (p_y * width + p_x) * p_pixelsize; for (uint32_t i = 0; i < p_pixelsize; i++) { - p_dst[i] = p_src[ofs + i]; + p_pixel[i] = p_data[ofs + i]; } } @@ -818,7 +818,7 @@ void Image::flip_y() { uint8_t down[16]; uint32_t pixel_size = get_format_pixel_size(format); - for (int y = 0; y < height; y++) { + for (int y = 0; y < height / 2; y++) { for (int x = 0; x < width; x++) { @@ -854,7 +854,7 @@ void Image::flip_x() { for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { + for (int x = 0; x < width / 2; x++) { _get_pixelb(x, y, pixel_size, w.ptr(), up); _get_pixelb(width - x - 1, y, pixel_size, w.ptr(), down); @@ -1457,7 +1457,7 @@ Error Image::save_png(const String &p_path) const { if (save_png_func == NULL) return ERR_UNAVAILABLE; - return save_png_func(p_path, Ref<Image>(this)); + return save_png_func(p_path, Ref<Image>((Image *)this)); } int Image::get_image_data_size(int p_width, int p_height, Format p_format, int p_mipmaps) { @@ -1599,7 +1599,7 @@ Rect2 Image::get_used_rect() const { Ref<Image> Image::get_rect(const Rect2 &p_area) const { Ref<Image> img = memnew(Image(p_area.size.x, p_area.size.y, mipmaps, format)); - img->blit_rect(Ref<Image>(this), p_area, Point2(0, 0)); + img->blit_rect(Ref<Image>((Image *)this), p_area, Point2(0, 0)); return img; } diff --git a/core/image.h b/core/image.h index 2a78870f53..e3174a2899 100644 --- a/core/image.h +++ b/core/image.h @@ -162,8 +162,8 @@ private: static int _get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps = -1); bool _can_modify(Format p_format) const; - _FORCE_INLINE_ void _put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_dst, const uint8_t *p_src); - _FORCE_INLINE_ void _get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p_src, uint8_t *p_dst); + _FORCE_INLINE_ void _put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_data, const uint8_t *p_pixel); + _FORCE_INLINE_ void _get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p_data, uint8_t *p_pixel); void _set_data(const Dictionary &p_data); Dictionary _get_data() const; diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index ceae543ff9..75dfd563dd 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -211,9 +211,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int ERR_FAIL_COND_V(len < (int)4 * 6, ERR_INVALID_DATA); Rect3 val; - val.pos.x = decode_float(&buf[0]); - val.pos.y = decode_float(&buf[4]); - val.pos.z = decode_float(&buf[8]); + val.position.x = decode_float(&buf[0]); + val.position.y = decode_float(&buf[4]); + val.position.z = decode_float(&buf[8]); val.size.x = decode_float(&buf[12]); val.size.y = decode_float(&buf[16]); val.size.z = decode_float(&buf[20]); @@ -926,9 +926,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) { if (buf) { Rect3 aabb = p_variant; - encode_float(aabb.pos.x, &buf[0]); - encode_float(aabb.pos.y, &buf[4]); - encode_float(aabb.pos.z, &buf[8]); + encode_float(aabb.position.x, &buf[0]); + encode_float(aabb.position.y, &buf[4]); + encode_float(aabb.position.z, &buf[8]); encode_float(aabb.size.x, &buf[12]); encode_float(aabb.size.y, &buf[16]); encode_float(aabb.size.z, &buf[20]); diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 01cad9d525..0373176cd2 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -191,9 +191,9 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { case VARIANT_RECT3: { Rect3 v; - v.pos.x = f->get_real(); - v.pos.y = f->get_real(); - v.pos.z = f->get_real(); + v.position.x = f->get_real(); + v.position.y = f->get_real(); + v.position.z = f->get_real(); v.size.x = f->get_real(); v.size.y = f->get_real(); v.size.z = f->get_real(); @@ -1327,9 +1327,9 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant &p_property, f->store_32(VARIANT_RECT3); Rect3 val = p_property; - f->store_real(val.pos.x); - f->store_real(val.pos.y); - f->store_real(val.pos.z); + f->store_real(val.position.x); + f->store_real(val.position.y); + f->store_real(val.position.z); f->store_real(val.size.x); f->store_real(val.size.y); f->store_real(val.size.z); diff --git a/core/io/resource_import.h b/core/io/resource_import.h index 25b7a534b2..9d2a5180dc 100644 --- a/core/io/resource_import.h +++ b/core/io/resource_import.h @@ -61,6 +61,7 @@ public: String get_internal_resource_path(const String &p_path) const; void add_importer(const Ref<ResourceImporter> &p_importer) { importers.insert(p_importer); } + void remove_importer(const Ref<ResourceImporter> &p_importer) { importers.erase(p_importer); } Ref<ResourceImporter> get_importer_by_name(const String &p_name); Ref<ResourceImporter> get_importer_by_extension(const String &p_extension); void get_importers_for_extension(const String &p_extension, List<Ref<ResourceImporter> > *r_importers); diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp index 9bbce752c0..327a6017c3 100644 --- a/core/math/bsp_tree.cpp +++ b/core/math/bsp_tree.cpp @@ -39,8 +39,8 @@ void BSP_Tree::from_aabb(const Rect3 &p_aabb) { Vector3 n; n[i] = 1; - planes.push_back(Plane(n, p_aabb.pos[i] + p_aabb.size[i])); - planes.push_back(Plane(-n, -p_aabb.pos[i])); + planes.push_back(Plane(n, p_aabb.position[i] + p_aabb.size[i])); + planes.push_back(Plane(-n, -p_aabb.position[i])); } nodes.clear(); @@ -552,7 +552,7 @@ BSP_Tree::BSP_Tree(const PoolVector<Face3> &p_faces, real_t p_error_radius) { if (first) { - aabb.pos = f.vertex[0]; + aabb.position = f.vertex[0]; first = false; } else { diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp index c26b12b0f0..33ad522315 100644 --- a/core/math/camera_matrix.cpp +++ b/core/math/camera_matrix.cpp @@ -559,8 +559,8 @@ void CameraMatrix::make_scale(const Vector3 &p_scale) { void CameraMatrix::scale_translate_to_fit(const Rect3 &p_aabb) { - Vector3 min = p_aabb.pos; - Vector3 max = p_aabb.pos + p_aabb.size; + Vector3 min = p_aabb.position; + Vector3 max = p_aabb.position + p_aabb.size; matrix[0][0] = 2 / (max.x - min.x); matrix[1][0] = 0; diff --git a/core/math/face3.cpp b/core/math/face3.cpp index 6d772cf08c..5b66e1999a 100644 --- a/core/math/face3.cpp +++ b/core/math/face3.cpp @@ -197,20 +197,20 @@ bool Face3::intersects_aabb(const Rect3 &p_aabb) const { /** TEST FACE AXIS */ -#define TEST_AXIS(m_ax) \ - { \ - real_t aabb_min = p_aabb.pos.m_ax; \ - real_t aabb_max = p_aabb.pos.m_ax + p_aabb.size.m_ax; \ - real_t tri_min, tri_max; \ - for (int i = 0; i < 3; i++) { \ - if (i == 0 || vertex[i].m_ax > tri_max) \ - tri_max = vertex[i].m_ax; \ - if (i == 0 || vertex[i].m_ax < tri_min) \ - tri_min = vertex[i].m_ax; \ - } \ - \ - if (tri_max < aabb_min || aabb_max < tri_min) \ - return false; \ +#define TEST_AXIS(m_ax) \ + { \ + real_t aabb_min = p_aabb.position.m_ax; \ + real_t aabb_max = p_aabb.position.m_ax + p_aabb.size.m_ax; \ + real_t tri_min, tri_max; \ + for (int i = 0; i < 3; i++) { \ + if (i == 0 || vertex[i].m_ax > tri_max) \ + tri_max = vertex[i].m_ax; \ + if (i == 0 || vertex[i].m_ax < tri_min) \ + tri_min = vertex[i].m_ax; \ + } \ + \ + if (tri_max < aabb_min || aabb_max < tri_min) \ + return false; \ } TEST_AXIS(x); diff --git a/core/math/face3.h b/core/math/face3.h index 31ab72b925..1cc94321c3 100644 --- a/core/math/face3.h +++ b/core/math/face3.h @@ -101,7 +101,7 @@ bool Face3::intersects_aabb2(const Rect3 &p_aabb) const { Vector3 perp = (vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]); Vector3 half_extents = p_aabb.size * 0.5; - Vector3 ofs = p_aabb.pos + half_extents; + Vector3 ofs = p_aabb.position + half_extents; Vector3 sup = Vector3( (perp.x > 0) ? -half_extents.x : half_extents.x, @@ -117,8 +117,8 @@ bool Face3::intersects_aabb2(const Rect3 &p_aabb) const { #define TEST_AXIS(m_ax) \ { \ - real_t aabb_min = p_aabb.pos.m_ax; \ - real_t aabb_max = p_aabb.pos.m_ax + p_aabb.size.m_ax; \ + real_t aabb_min = p_aabb.position.m_ax; \ + real_t aabb_max = p_aabb.position.m_ax + p_aabb.size.m_ax; \ real_t tri_min, tri_max; \ for (int i = 0; i < 3; i++) { \ if (i == 0 || vertex[i].m_ax > tri_max) \ @@ -150,68 +150,68 @@ bool Face3::intersects_aabb2(const Rect3 &p_aabb) const { case 0: { - from = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z); - to = Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z); + from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z); + to = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z); } break; case 1: { - from = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z); - to = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z); + from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z); + to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z); } break; case 2: { - from = Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z); - to = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z); + from = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z); + to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z); } break; case 3: { - from = Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z); - to = Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z); + from = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z); + to = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z); } break; case 4: { - from = Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z); - to = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z); + from = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z); + to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z); } break; case 5: { - from = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z); - to = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z); + from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z); + to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z); } break; case 6: { - from = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z); - to = Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z); + from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z); + to = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z); } break; case 7: { - from = Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z); - to = Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z); + from = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z); + to = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z); } break; case 8: { - from = Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z); - to = Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z); + from = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z); + to = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z); } break; case 9: { - from = Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z); - to = Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z); + from = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z); + to = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z); } break; case 10: { - from = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z); - to = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z); + from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z); + to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z); } break; case 11: { - from = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z); - to = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z); + from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z); + to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z); } break; } diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp index 618017f8b3..2bea514d37 100644 --- a/core/math/geometry.cpp +++ b/core/math/geometry.cpp @@ -301,7 +301,7 @@ enum _CellFlags { static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int len_x, int len_y, int len_z, const Vector3 &voxelsize, const Face3 &p_face) { Rect3 aabb(Vector3(x, y, z), Vector3(len_x, len_y, len_z)); - aabb.pos = aabb.pos * voxelsize; + aabb.position = aabb.position * voxelsize; aabb.size = aabb.size * voxelsize; if (!p_face.intersects_aabb(aabb)) @@ -640,7 +640,7 @@ PoolVector<Face3> Geometry::wrap_geometry(PoolVector<Face3> p_array, real_t *p_e Face3 f = faces[i]; for (int j = 0; j < 3; j++) { - f.vertex[j] -= global_aabb.pos; + f.vertex[j] -= global_aabb.position; } _plot_face(cell_status, 0, 0, 0, div_x, div_y, div_z, voxelsize, f); } @@ -707,7 +707,7 @@ PoolVector<Face3> Geometry::wrap_geometry(PoolVector<Face3> p_array, real_t *p_e Vector3 &v = wrapped_faces_ptr[i].vertex[j]; v = v * voxelsize; - v += global_aabb.pos; + v += global_aabb.position; } } diff --git a/core/math/octree.h b/core/math/octree.h index 4cc046ddf4..010c1b18f7 100644 --- a/core/math/octree.h +++ b/core/math/octree.h @@ -483,11 +483,11 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct aabb.size *= 0.5; if (i & 1) - aabb.pos.x += aabb.size.x; + aabb.position.x += aabb.size.x; if (i & 2) - aabb.pos.y += aabb.size.y; + aabb.position.y += aabb.size.y; if (i & 4) - aabb.pos.z += aabb.size.z; + aabb.position.z += aabb.size.z; if (aabb.intersects_inclusive(p_element->aabb)) { /* if actually intersects, create the child */ @@ -544,11 +544,11 @@ void Octree<T, use_pairs, AL>::_ensure_valid_root(const Rect3 &p_aabb) { while (!base.encloses(p_aabb)) { - if (ABS(base.pos.x + base.size.x) <= ABS(base.pos.x)) { + if (ABS(base.position.x + base.size.x) <= ABS(base.position.x)) { /* grow towards positive */ base.size *= 2.0; } else { - base.pos -= base.size; + base.position -= base.size; base.size *= 2.0; } } @@ -576,14 +576,14 @@ void Octree<T, use_pairs, AL>::_ensure_valid_root(const Rect3 &p_aabb) { octant_count++; root->parent = gp; - if (ABS(base.pos.x + base.size.x) <= ABS(base.pos.x)) { + if (ABS(base.position.x + base.size.x) <= ABS(base.position.x)) { /* grow towards positive */ base.size *= 2.0; gp->aabb = base; gp->children[0] = root; root->parent_index = 0; } else { - base.pos -= base.size; + base.position -= base.size; base.size *= 2.0; gp->aabb = base; gp->children[(1 << 0) | (1 << 1) | (1 << 2)] = root; // add at all-positive @@ -797,9 +797,9 @@ OctreeElementID Octree<T, use_pairs, AL>::create(T *p_userdata, const Rect3 &p_a // check for AABB validity #ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(p_aabb.pos.x > 1e15 || p_aabb.pos.x < -1e15, 0); - ERR_FAIL_COND_V(p_aabb.pos.y > 1e15 || p_aabb.pos.y < -1e15, 0); - ERR_FAIL_COND_V(p_aabb.pos.z > 1e15 || p_aabb.pos.z < -1e15, 0); + ERR_FAIL_COND_V(p_aabb.position.x > 1e15 || p_aabb.position.x < -1e15, 0); + ERR_FAIL_COND_V(p_aabb.position.y > 1e15 || p_aabb.position.y < -1e15, 0); + ERR_FAIL_COND_V(p_aabb.position.z > 1e15 || p_aabb.position.z < -1e15, 0); ERR_FAIL_COND_V(p_aabb.size.x > 1e15 || p_aabb.size.x < 0.0, 0); ERR_FAIL_COND_V(p_aabb.size.y > 1e15 || p_aabb.size.y < 0.0, 0); ERR_FAIL_COND_V(p_aabb.size.z > 1e15 || p_aabb.size.z < 0.0, 0); @@ -837,9 +837,9 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const Rect3 &p_aabb) { #ifdef DEBUG_ENABLED // check for AABB validity - ERR_FAIL_COND(p_aabb.pos.x > 1e15 || p_aabb.pos.x < -1e15); - ERR_FAIL_COND(p_aabb.pos.y > 1e15 || p_aabb.pos.y < -1e15); - ERR_FAIL_COND(p_aabb.pos.z > 1e15 || p_aabb.pos.z < -1e15); + ERR_FAIL_COND(p_aabb.position.x > 1e15 || p_aabb.position.x < -1e15); + ERR_FAIL_COND(p_aabb.position.y > 1e15 || p_aabb.position.y < -1e15); + ERR_FAIL_COND(p_aabb.position.z > 1e15 || p_aabb.position.z < -1e15); ERR_FAIL_COND(p_aabb.size.x > 1e15 || p_aabb.size.x < 0.0); ERR_FAIL_COND(p_aabb.size.y > 1e15 || p_aabb.size.y < 0.0); ERR_FAIL_COND(p_aabb.size.z > 1e15 || p_aabb.size.z < 0.0); diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp index ce93720067..9f594ba4fa 100644 --- a/core/math/quick_hull.cpp +++ b/core/math/quick_hull.cpp @@ -42,7 +42,7 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me for (int i = 0; i < p_points.size(); i++) { if (i == 0) { - aabb.pos = p_points[i]; + aabb.position = p_points[i]; } else { aabb.expand_to(p_points[i]); } diff --git a/core/math/rect3.cpp b/core/math/rect3.cpp index 39b0beb071..973607f565 100644 --- a/core/math/rect3.cpp +++ b/core/math/rect3.cpp @@ -38,11 +38,11 @@ real_t Rect3::get_area() const { bool Rect3::operator==(const Rect3 &p_rval) const { - return ((pos == p_rval.pos) && (size == p_rval.size)); + return ((position == p_rval.position) && (size == p_rval.size)); } bool Rect3::operator!=(const Rect3 &p_rval) const { - return ((pos != p_rval.pos) || (size != p_rval.size)); + return ((position != p_rval.position) || (size != p_rval.size)); } void Rect3::merge_with(const Rect3 &p_aabb) { @@ -51,8 +51,8 @@ void Rect3::merge_with(const Rect3 &p_aabb) { Vector3 end_1, end_2; Vector3 min, max; - beg_1 = pos; - beg_2 = p_aabb.pos; + beg_1 = position; + beg_2 = p_aabb.position; end_1 = Vector3(size.x, size.y, size.z) + beg_1; end_2 = Vector3(p_aabb.size.x, p_aabb.size.y, p_aabb.size.z) + beg_2; @@ -64,16 +64,16 @@ void Rect3::merge_with(const Rect3 &p_aabb) { max.y = (end_1.y > end_2.y) ? end_1.y : end_2.y; max.z = (end_1.z > end_2.z) ? end_1.z : end_2.z; - pos = min; + position = min; size = max - min; } Rect3 Rect3::intersection(const Rect3 &p_aabb) const { - Vector3 src_min = pos; - Vector3 src_max = pos + size; - Vector3 dst_min = p_aabb.pos; - Vector3 dst_max = p_aabb.pos + p_aabb.size; + Vector3 src_min = position; + Vector3 src_max = position + size; + Vector3 dst_min = p_aabb.position; + Vector3 dst_max = p_aabb.position + p_aabb.size; Vector3 min, max; @@ -107,18 +107,18 @@ Rect3 Rect3::intersection(const Rect3 &p_aabb) const { bool Rect3::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip, Vector3 *r_normal) const { Vector3 c1, c2; - Vector3 end = pos + size; + Vector3 end = position + size; real_t near = -1e20; real_t far = 1e20; int axis = 0; for (int i = 0; i < 3; i++) { if (p_dir[i] == 0) { - if ((p_from[i] < pos[i]) || (p_from[i] > end[i])) { + if ((p_from[i] < position[i]) || (p_from[i] > end[i])) { return false; } } else { // ray not parallel to planes in this direction - c1[i] = (pos[i] - p_from[i]) / p_dir[i]; + c1[i] = (position[i] - p_from[i]) / p_dir[i]; c2[i] = (end[i] - p_from[i]) / p_dir[i]; if (c1[i] > c2[i]) { @@ -156,7 +156,7 @@ bool Rect3::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vecto for (int i = 0; i < 3; i++) { real_t seg_from = p_from[i]; real_t seg_to = p_to[i]; - real_t box_begin = pos[i]; + real_t box_begin = position[i]; real_t box_end = box_begin + size[i]; real_t cmin, cmax; real_t csign; @@ -208,14 +208,14 @@ bool Rect3::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vecto bool Rect3::intersects_plane(const Plane &p_plane) const { Vector3 points[8] = { - Vector3(pos.x, pos.y, pos.z), - Vector3(pos.x, pos.y, pos.z + size.z), - Vector3(pos.x, pos.y + size.y, pos.z), - Vector3(pos.x, pos.y + size.y, pos.z + size.z), - Vector3(pos.x + size.x, pos.y, pos.z), - Vector3(pos.x + size.x, pos.y, pos.z + size.z), - Vector3(pos.x + size.x, pos.y + size.y, pos.z), - Vector3(pos.x + size.x, pos.y + size.y, pos.z + size.z), + Vector3(position.x, position.y, position.z), + Vector3(position.x, position.y, position.z + size.z), + Vector3(position.x, position.y + size.y, position.z), + Vector3(position.x, position.y + size.y, position.z + size.z), + Vector3(position.x + size.x, position.y, position.z), + Vector3(position.x + size.x, position.y, position.z + size.z), + Vector3(position.x + size.x, position.y + size.y, position.z), + Vector3(position.x + size.x, position.y + size.y, position.z + size.z), }; bool over = false; @@ -327,68 +327,68 @@ void Rect3::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const { case 0: { - r_from = Vector3(pos.x + size.x, pos.y, pos.z); - r_to = Vector3(pos.x, pos.y, pos.z); + r_from = Vector3(position.x + size.x, position.y, position.z); + r_to = Vector3(position.x, position.y, position.z); } break; case 1: { - r_from = Vector3(pos.x + size.x, pos.y, pos.z + size.z); - r_to = Vector3(pos.x + size.x, pos.y, pos.z); + r_from = Vector3(position.x + size.x, position.y, position.z + size.z); + r_to = Vector3(position.x + size.x, position.y, position.z); } break; case 2: { - r_from = Vector3(pos.x, pos.y, pos.z + size.z); - r_to = Vector3(pos.x + size.x, pos.y, pos.z + size.z); + r_from = Vector3(position.x, position.y, position.z + size.z); + r_to = Vector3(position.x + size.x, position.y, position.z + size.z); } break; case 3: { - r_from = Vector3(pos.x, pos.y, pos.z); - r_to = Vector3(pos.x, pos.y, pos.z + size.z); + r_from = Vector3(position.x, position.y, position.z); + r_to = Vector3(position.x, position.y, position.z + size.z); } break; case 4: { - r_from = Vector3(pos.x, pos.y + size.y, pos.z); - r_to = Vector3(pos.x + size.x, pos.y + size.y, pos.z); + r_from = Vector3(position.x, position.y + size.y, position.z); + r_to = Vector3(position.x + size.x, position.y + size.y, position.z); } break; case 5: { - r_from = Vector3(pos.x + size.x, pos.y + size.y, pos.z); - r_to = Vector3(pos.x + size.x, pos.y + size.y, pos.z + size.z); + r_from = Vector3(position.x + size.x, position.y + size.y, position.z); + r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z); } break; case 6: { - r_from = Vector3(pos.x + size.x, pos.y + size.y, pos.z + size.z); - r_to = Vector3(pos.x, pos.y + size.y, pos.z + size.z); + r_from = Vector3(position.x + size.x, position.y + size.y, position.z + size.z); + r_to = Vector3(position.x, position.y + size.y, position.z + size.z); } break; case 7: { - r_from = Vector3(pos.x, pos.y + size.y, pos.z + size.z); - r_to = Vector3(pos.x, pos.y + size.y, pos.z); + r_from = Vector3(position.x, position.y + size.y, position.z + size.z); + r_to = Vector3(position.x, position.y + size.y, position.z); } break; case 8: { - r_from = Vector3(pos.x, pos.y, pos.z + size.z); - r_to = Vector3(pos.x, pos.y + size.y, pos.z + size.z); + r_from = Vector3(position.x, position.y, position.z + size.z); + r_to = Vector3(position.x, position.y + size.y, position.z + size.z); } break; case 9: { - r_from = Vector3(pos.x, pos.y, pos.z); - r_to = Vector3(pos.x, pos.y + size.y, pos.z); + r_from = Vector3(position.x, position.y, position.z); + r_to = Vector3(position.x, position.y + size.y, position.z); } break; case 10: { - r_from = Vector3(pos.x + size.x, pos.y, pos.z); - r_to = Vector3(pos.x + size.x, pos.y + size.y, pos.z); + r_from = Vector3(position.x + size.x, position.y, position.z); + r_to = Vector3(position.x + size.x, position.y + size.y, position.z); } break; case 11: { - r_from = Vector3(pos.x + size.x, pos.y, pos.z + size.z); - r_to = Vector3(pos.x + size.x, pos.y + size.y, pos.z + size.z); + r_from = Vector3(position.x + size.x, position.y, position.z + size.z); + r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z); } break; } @@ -396,5 +396,5 @@ void Rect3::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const { Rect3::operator String() const { - return String() + pos + " - " + size; + return String() + position + " - " + size; } diff --git a/core/math/rect3.h b/core/math/rect3.h index 136a156151..b7c94ad9f7 100644 --- a/core/math/rect3.h +++ b/core/math/rect3.h @@ -36,12 +36,12 @@ /** * AABB / AABB (Axis Aligned Bounding Box) - * This is implemented by a point (pos) and the box size + * This is implemented by a point (position) and the box size */ class Rect3 { public: - Vector3 pos; + Vector3 position; Vector3 size; real_t get_area() const; /// get area @@ -55,8 +55,8 @@ public: return (size.x <= CMP_EPSILON && size.y <= CMP_EPSILON && size.z <= CMP_EPSILON); } - const Vector3 &get_pos() const { return pos; } - void set_pos(const Vector3 &p_pos) { pos = p_pos; } + const Vector3 &get_position() const { return position; } + void set_position(const Vector3 &p_pos) { position = p_pos; } const Vector3 &get_size() const { return size; } void set_size(const Vector3 &p_size) { size = p_size; } @@ -102,24 +102,24 @@ public: _FORCE_INLINE_ Rect3() {} inline Rect3(const Vector3 &p_pos, const Vector3 &p_size) { - pos = p_pos; + position = p_pos; size = p_size; } }; inline bool Rect3::intersects(const Rect3 &p_aabb) const { - if (pos.x >= (p_aabb.pos.x + p_aabb.size.x)) + if (position.x >= (p_aabb.position.x + p_aabb.size.x)) return false; - if ((pos.x + size.x) <= p_aabb.pos.x) + if ((position.x + size.x) <= p_aabb.position.x) return false; - if (pos.y >= (p_aabb.pos.y + p_aabb.size.y)) + if (position.y >= (p_aabb.position.y + p_aabb.size.y)) return false; - if ((pos.y + size.y) <= p_aabb.pos.y) + if ((position.y + size.y) <= p_aabb.position.y) return false; - if (pos.z >= (p_aabb.pos.z + p_aabb.size.z)) + if (position.z >= (p_aabb.position.z + p_aabb.size.z)) return false; - if ((pos.z + size.z) <= p_aabb.pos.z) + if ((position.z + size.z) <= p_aabb.position.z) return false; return true; @@ -127,17 +127,17 @@ inline bool Rect3::intersects(const Rect3 &p_aabb) const { inline bool Rect3::intersects_inclusive(const Rect3 &p_aabb) const { - if (pos.x > (p_aabb.pos.x + p_aabb.size.x)) + if (position.x > (p_aabb.position.x + p_aabb.size.x)) return false; - if ((pos.x + size.x) < p_aabb.pos.x) + if ((position.x + size.x) < p_aabb.position.x) return false; - if (pos.y > (p_aabb.pos.y + p_aabb.size.y)) + if (position.y > (p_aabb.position.y + p_aabb.size.y)) return false; - if ((pos.y + size.y) < p_aabb.pos.y) + if ((position.y + size.y) < p_aabb.position.y) return false; - if (pos.z > (p_aabb.pos.z + p_aabb.size.z)) + if (position.z > (p_aabb.position.z + p_aabb.size.z)) return false; - if ((pos.z + size.z) < p_aabb.pos.z) + if ((position.z + size.z) < p_aabb.position.z) return false; return true; @@ -145,10 +145,10 @@ inline bool Rect3::intersects_inclusive(const Rect3 &p_aabb) const { inline bool Rect3::encloses(const Rect3 &p_aabb) const { - Vector3 src_min = pos; - Vector3 src_max = pos + size; - Vector3 dst_min = p_aabb.pos; - Vector3 dst_max = p_aabb.pos + p_aabb.size; + Vector3 src_min = position; + Vector3 src_max = position + size; + Vector3 dst_min = p_aabb.position; + Vector3 dst_max = p_aabb.position + p_aabb.size; return ( (src_min.x <= dst_min.x) && @@ -162,7 +162,7 @@ inline bool Rect3::encloses(const Rect3 &p_aabb) const { Vector3 Rect3::get_support(const Vector3 &p_normal) const { Vector3 half_extents = size * 0.5; - Vector3 ofs = pos + half_extents; + Vector3 ofs = position + half_extents; return Vector3( (p_normal.x > 0) ? -half_extents.x : half_extents.x, @@ -174,14 +174,14 @@ Vector3 Rect3::get_support(const Vector3 &p_normal) const { Vector3 Rect3::get_endpoint(int p_point) const { switch (p_point) { - case 0: return Vector3(pos.x, pos.y, pos.z); - case 1: return Vector3(pos.x, pos.y, pos.z + size.z); - case 2: return Vector3(pos.x, pos.y + size.y, pos.z); - case 3: return Vector3(pos.x, pos.y + size.y, pos.z + size.z); - case 4: return Vector3(pos.x + size.x, pos.y, pos.z); - case 5: return Vector3(pos.x + size.x, pos.y, pos.z + size.z); - case 6: return Vector3(pos.x + size.x, pos.y + size.y, pos.z); - case 7: return Vector3(pos.x + size.x, pos.y + size.y, pos.z + size.z); + case 0: return Vector3(position.x, position.y, position.z); + case 1: return Vector3(position.x, position.y, position.z + size.z); + case 2: return Vector3(position.x, position.y + size.y, position.z); + case 3: return Vector3(position.x, position.y + size.y, position.z + size.z); + case 4: return Vector3(position.x + size.x, position.y, position.z); + case 5: return Vector3(position.x + size.x, position.y, position.z + size.z); + case 6: return Vector3(position.x + size.x, position.y + size.y, position.z); + case 7: return Vector3(position.x + size.x, position.y + size.y, position.z + size.z); }; ERR_FAIL_V(Vector3()); @@ -192,7 +192,7 @@ bool Rect3::intersects_convex_shape(const Plane *p_planes, int p_plane_count) co #if 1 Vector3 half_extents = size * 0.5; - Vector3 ofs = pos + half_extents; + Vector3 ofs = position + half_extents; for (int i = 0; i < p_plane_count; i++) { const Plane &p = p_planes[i]; @@ -210,14 +210,14 @@ bool Rect3::intersects_convex_shape(const Plane *p_planes, int p_plane_count) co //cache all points to check against! // #warning should be easy to optimize, just use the same as when taking the support and use only that point Vector3 points[8] = { - Vector3(pos.x, pos.y, pos.z), - Vector3(pos.x, pos.y, pos.z + size.z), - Vector3(pos.x, pos.y + size.y, pos.z), - Vector3(pos.x, pos.y + size.y, pos.z + size.z), - Vector3(pos.x + size.x, pos.y, pos.z), - Vector3(pos.x + size.x, pos.y, pos.z + size.z), - Vector3(pos.x + size.x, pos.y + size.y, pos.z), - Vector3(pos.x + size.x, pos.y + size.y, pos.z + size.z), + Vector3(position.x, position.y, position.z), + Vector3(position.x, position.y, position.z + size.z), + Vector3(position.x, position.y + size.y, position.z), + Vector3(position.x, position.y + size.y, position.z + size.z), + Vector3(position.x + size.x, position.y, position.z), + Vector3(position.x + size.x, position.y, position.z + size.z), + Vector3(position.x + size.x, position.y + size.y, position.z), + Vector3(position.x + size.x, position.y + size.y, position.z + size.z), }; for (int i = 0; i < p_plane_count; i++) { //for each plane @@ -246,17 +246,17 @@ bool Rect3::intersects_convex_shape(const Plane *p_planes, int p_plane_count) co bool Rect3::has_point(const Vector3 &p_point) const { - if (p_point.x < pos.x) + if (p_point.x < position.x) return false; - if (p_point.y < pos.y) + if (p_point.y < position.y) return false; - if (p_point.z < pos.z) + if (p_point.z < position.z) return false; - if (p_point.x > pos.x + size.x) + if (p_point.x > position.x + size.x) return false; - if (p_point.y > pos.y + size.y) + if (p_point.y > position.y + size.y) return false; - if (p_point.z > pos.z + size.z) + if (p_point.z > position.z + size.z) return false; return true; @@ -264,8 +264,8 @@ bool Rect3::has_point(const Vector3 &p_point) const { inline void Rect3::expand_to(const Vector3 &p_vector) { - Vector3 begin = pos; - Vector3 end = pos + size; + Vector3 begin = position; + Vector3 end = position + size; if (p_vector.x < begin.x) begin.x = p_vector.x; @@ -281,14 +281,14 @@ inline void Rect3::expand_to(const Vector3 &p_vector) { if (p_vector.z > end.z) end.z = p_vector.z; - pos = begin; + position = begin; size = end - begin; } void Rect3::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const { Vector3 half_extents(size.x * 0.5, size.y * 0.5, size.z * 0.5); - Vector3 center(pos.x + half_extents.x, pos.y + half_extents.y, pos.z + half_extents.z); + Vector3 center(position.x + half_extents.x, position.y + half_extents.y, position.z + half_extents.z); real_t length = p_plane.normal.abs().dot(half_extents); real_t distance = p_plane.distance_to(center); @@ -332,21 +332,21 @@ bool Rect3::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t real_t divy = 1.0 / dir.y; real_t divz = 1.0 / dir.z; - Vector3 upbound = pos + size; + Vector3 upbound = position + size; real_t tmin, tmax, tymin, tymax, tzmin, tzmax; if (dir.x >= 0) { - tmin = (pos.x - from.x) * divx; + tmin = (position.x - from.x) * divx; tmax = (upbound.x - from.x) * divx; } else { tmin = (upbound.x - from.x) * divx; - tmax = (pos.x - from.x) * divx; + tmax = (position.x - from.x) * divx; } if (dir.y >= 0) { - tymin = (pos.y - from.y) * divy; + tymin = (position.y - from.y) * divy; tymax = (upbound.y - from.y) * divy; } else { tymin = (upbound.y - from.y) * divy; - tymax = (pos.y - from.y) * divy; + tymax = (position.y - from.y) * divy; } if ((tmin > tymax) || (tymin > tmax)) return false; @@ -355,11 +355,11 @@ bool Rect3::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t if (tymax < tmax) tmax = tymax; if (dir.z >= 0) { - tzmin = (pos.z - from.z) * divz; + tzmin = (position.z - from.z) * divz; tzmax = (upbound.z - from.z) * divz; } else { tzmin = (upbound.z - from.z) * divz; - tzmax = (pos.z - from.z) * divz; + tzmax = (position.z - from.z) * divz; } if ((tmin > tzmax) || (tzmin > tmax)) return false; @@ -372,9 +372,9 @@ bool Rect3::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t void Rect3::grow_by(real_t p_amount) { - pos.x -= p_amount; - pos.y -= p_amount; - pos.z -= p_amount; + position.x -= p_amount; + position.y -= p_amount; + position.z -= p_amount; size.x += 2.0 * p_amount; size.y += 2.0 * p_amount; size.z += 2.0 * p_amount; diff --git a/core/math/transform.h b/core/math/transform.h index 4731496bf3..c39ea7826f 100644 --- a/core/math/transform.h +++ b/core/math/transform.h @@ -167,10 +167,10 @@ _FORCE_INLINE_ Rect3 Transform::xform(const Rect3 &p_aabb) const { Vector3 x = basis.get_axis(0) * p_aabb.size.x; Vector3 y = basis.get_axis(1) * p_aabb.size.y; Vector3 z = basis.get_axis(2) * p_aabb.size.z; - Vector3 pos = xform(p_aabb.pos); + Vector3 pos = xform(p_aabb.position); //could be even further optimized Rect3 new_aabb; - new_aabb.pos = pos; + new_aabb.position = pos; new_aabb.expand_to(pos + x); new_aabb.expand_to(pos + y); new_aabb.expand_to(pos + z); @@ -182,14 +182,14 @@ _FORCE_INLINE_ Rect3 Transform::xform(const Rect3 &p_aabb) const { #else Vector3 vertices[8] = { - Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z), - Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z), - Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z), - Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z), - Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z), - Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z), - Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z), - Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z) + Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z), + Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z), + Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z), + Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z), + Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z), + Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z), + Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z), + Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z) }; AABB ret; @@ -208,19 +208,19 @@ _FORCE_INLINE_ Rect3 Transform::xform_inv(const Rect3 &p_aabb) const { /* define vertices */ Vector3 vertices[8] = { - Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z), - Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z), - Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z), - Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z), - Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z), - Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z), - Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z), - Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z) + Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z), + Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z), + Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z), + Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z), + Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z), + Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z), + Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z), + Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z) }; Rect3 ret; - ret.pos = xform_inv(vertices[0]); + ret.position = xform_inv(vertices[0]); for (int i = 1; i < 8; i++) { diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp index 1cf1351646..08ac08d776 100644 --- a/core/math/triangle_mesh.cpp +++ b/core/math/triangle_mesh.cpp @@ -79,7 +79,7 @@ int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, in int index = max_alloc++; BVH *_new = &p_bvh[index]; _new->aabb = aabb; - _new->center = aabb.pos + aabb.size * 0.5; + _new->center = aabb.position + aabb.size * 0.5; _new->face_index = -1; _new->left = left; _new->right = right; @@ -128,7 +128,7 @@ void TriangleMesh::create(const PoolVector<Vector3> &p_faces) { f.indices[j] = vidx; if (j == 0) - bw[i].aabb.pos = vs; + bw[i].aabb.position = vs; else bw[i].aabb.expand_to(vs); } @@ -138,7 +138,7 @@ void TriangleMesh::create(const PoolVector<Vector3> &p_faces) { bw[i].left = -1; bw[i].right = -1; bw[i].face_index = i; - bw[i].center = bw[i].aabb.pos + bw[i].aabb.size * 0.5; + bw[i].center = bw[i].aabb.position + bw[i].aabb.size * 0.5; } vertices.resize(db.size()); diff --git a/core/object.cpp b/core/object.cpp index 7aee936a2d..f20e93f9d7 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -1831,10 +1831,10 @@ void postinitialize_handler(Object *p_object) { p_object->_postinitialize(); } -HashMap<uint32_t, Object *> ObjectDB::instances; -uint32_t ObjectDB::instance_counter = 1; +HashMap<ObjectID, Object *> ObjectDB::instances; +ObjectID ObjectDB::instance_counter = 1; HashMap<Object *, ObjectID, ObjectDB::ObjectPtrHash> ObjectDB::instance_checks; -uint32_t ObjectDB::add_instance(Object *p_object) { +ObjectID ObjectDB::add_instance(Object *p_object) { ERR_FAIL_COND_V(p_object->get_instance_ID() != 0, 0); @@ -1859,7 +1859,7 @@ void ObjectDB::remove_instance(Object *p_object) { rw_lock->write_unlock(); } -Object *ObjectDB::get_instance(uint32_t p_instance_ID) { +Object *ObjectDB::get_instance(ObjectID p_instance_ID) { rw_lock->read_lock(); Object **obj = instances.getptr(p_instance_ID); @@ -1874,7 +1874,7 @@ void ObjectDB::debug_objects(DebugFunc p_func) { rw_lock->read_lock(); - const uint32_t *K = NULL; + const ObjectID *K = NULL; while ((K = instances.next(K))) { p_func(instances[*K]); @@ -1909,7 +1909,7 @@ void ObjectDB::cleanup() { WARN_PRINT("ObjectDB Instances still exist!"); if (OS::get_singleton()->is_stdout_verbose()) { - const uint32_t *K = NULL; + const ObjectID *K = NULL; while ((K = instances.next(K))) { String node_name; diff --git a/core/object.h b/core/object.h index 3b39224af0..83b03b9239 100644 --- a/core/object.h +++ b/core/object.h @@ -350,7 +350,7 @@ public: \ private: class ScriptInstance; -typedef uint32_t ObjectID; +typedef uint64_t ObjectID; class Object { public: @@ -423,7 +423,7 @@ private: bool _block_signals; int _predelete_ok; Set<Object *> change_receptors; - uint32_t _instance_ID; + ObjectID _instance_ID; bool _predelete(); void _postinitialize(); bool _can_translate; @@ -690,16 +690,16 @@ class ObjectDB { } }; - static HashMap<uint32_t, Object *> instances; + static HashMap<ObjectID, Object *> instances; static HashMap<Object *, ObjectID, ObjectPtrHash> instance_checks; - static uint32_t instance_counter; + static ObjectID instance_counter; friend class Object; friend void unregister_core_types(); static RWLock *rw_lock; static void cleanup(); - static uint32_t add_instance(Object *p_object); + static ObjectID add_instance(Object *p_object); static void remove_instance(Object *p_object); friend void register_core_types(); static void setup(); @@ -707,7 +707,7 @@ class ObjectDB { public: typedef void (*DebugFunc)(Object *p_obj); - static Object *get_instance(uint32_t p_instance_ID); + static Object *get_instance(ObjectID p_instance_ID); static void debug_objects(DebugFunc p_func); static int get_object_count(); diff --git a/core/variant.cpp b/core/variant.cpp index 0543dd6b79..0807a33788 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -2590,7 +2590,7 @@ uint32_t Variant::hash() const { uint32_t hash = 5831; for (int i = 0; i < 3; i++) { - hash = hash_djb2_one_float(_data._rect3->pos[i], hash); + hash = hash_djb2_one_float(_data._rect3->position[i], hash); hash = hash_djb2_one_float(_data._rect3->size[i], hash); } @@ -2855,7 +2855,7 @@ bool Variant::hash_compare(const Variant &p_variant) const { const Rect3 *l = _data._rect3; const Rect3 *r = p_variant._data._rect3; - return (hash_compare_vector3(l->pos, r->pos) && + return (hash_compare_vector3(l->position, r->position) && (hash_compare_vector3(l->size, r->size))); } break; diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 4871df8918..7b2d0f6886 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -1304,9 +1304,9 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) const String *str = reinterpret_cast<const String *>(p_index._data._mem); Rect3 *v = _data._rect3; - if (*str == "pos") { + if (*str == "position") { valid = true; - v->pos = p_value; + v->position = p_value; return; } else if (*str == "size") { valid = true; @@ -1314,7 +1314,7 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) return; } else if (*str == "end") { valid = true; - v->size = Vector3(p_value) - v->pos; + v->size = Vector3(p_value) - v->position; return; } } @@ -1718,15 +1718,15 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { const String *str = reinterpret_cast<const String *>(p_index._data._mem); const Rect3 *v = _data._rect3; - if (*str == "pos") { + if (*str == "position") { valid = true; - return v->pos; + return v->position; } else if (*str == "size") { valid = true; return v->size; } else if (*str == "end") { valid = true; - return v->size + v->pos; + return v->size + v->position; } } } break; @@ -2769,7 +2769,7 @@ void Variant::blend(const Variant &a, const Variant &b, float c, Variant &r_dst) case RECT3: { const Rect3 *ra = reinterpret_cast<const Rect3 *>(a._data._mem); const Rect3 *rb = reinterpret_cast<const Rect3 *>(b._data._mem); - r_dst = Rect3(ra->pos + rb->pos * c, ra->size + rb->size * c); + r_dst = Rect3(ra->position + rb->position * c, ra->size + rb->size * c); } return; case QUAT: { @@ -2899,7 +2899,7 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & } return; case RECT3: { - r_dst = Rect3(a._data._rect3->pos.linear_interpolate(b._data._rect3->pos, c), a._data._rect3->size.linear_interpolate(b._data._rect3->size, c)); + r_dst = Rect3(a._data._rect3->position.linear_interpolate(b._data._rect3->position, c), a._data._rect3->size.linear_interpolate(b._data._rect3->size, c)); } return; case BASIS: { diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index da78d98134..26a6a05a30 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -1637,7 +1637,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str case Variant::RECT3: { Rect3 aabb = p_variant; - p_store_string_func(p_store_string_ud, "Rect3( " + rtosfix(aabb.pos.x) + ", " + rtosfix(aabb.pos.y) + ", " + rtosfix(aabb.pos.z) + ", " + rtosfix(aabb.size.x) + ", " + rtosfix(aabb.size.y) + ", " + rtosfix(aabb.size.z) + " )"); + p_store_string_func(p_store_string_ud, "Rect3( " + rtosfix(aabb.position.x) + ", " + rtosfix(aabb.position.y) + ", " + rtosfix(aabb.position.z) + ", " + rtosfix(aabb.size.x) + ", " + rtosfix(aabb.size.y) + ", " + rtosfix(aabb.size.z) + " )"); } break; case Variant::QUAT: { diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp index 2262580d9a..53df7e9c3d 100644 --- a/drivers/gles3/rasterizer_gles3.cpp +++ b/drivers/gles3/rasterizer_gles3.cpp @@ -212,11 +212,8 @@ void RasterizerGLES3::begin_frame() { storage->update_dirty_resources(); - storage->info.render_object_count = 0; - storage->info.render_material_switch_count = 0; - storage->info.render_surface_switch_count = 0; - storage->info.render_shader_rebind_count = 0; - storage->info.render_vertices_count = 0; + storage->info.render_final = storage->info.render; + storage->info.render.reset(); scene->iteration(); } diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index af03819a16..08f15a9b84 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -1290,8 +1290,11 @@ void RasterizerSceneGLES3::_setup_geometry(RenderList::Element *e, const Transfo storage->mesh_render_blend_shapes(s, e->instance->blend_values.ptr()); //rebind shader state.scene_shader.bind(); +#ifdef DEBUG_ENABLED + } else if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_WIREFRAME && s->array_wireframe_id) { + glBindVertexArray(s->array_wireframe_id); // everything is so easy nowadays +#endif } else { - glBindVertexArray(s->array_id); // everything is so easy nowadays } @@ -1301,7 +1304,16 @@ void RasterizerSceneGLES3::_setup_geometry(RenderList::Element *e, const Transfo RasterizerStorageGLES3::MultiMesh *multi_mesh = static_cast<RasterizerStorageGLES3::MultiMesh *>(e->owner); RasterizerStorageGLES3::Surface *s = static_cast<RasterizerStorageGLES3::Surface *>(e->geometry); - glBindVertexArray(s->instancing_array_id); // use the instancing array ID +#ifdef DEBUG_ENABLED + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_WIREFRAME && s->instancing_array_wireframe_id) { + + glBindVertexArray(s->instancing_array_wireframe_id); // use the instancing array ID + } else +#endif + { + glBindVertexArray(s->instancing_array_id); // use the instancing array ID + } + glBindBuffer(GL_ARRAY_BUFFER, multi_mesh->buffer); //modify the buffer int stride = (multi_mesh->xform_floats + multi_mesh->color_floats) * 4; @@ -1366,13 +1378,26 @@ void RasterizerSceneGLES3::_setup_geometry(RenderList::Element *e, const Transfo sorter.sort(particle_array, particles->amount); glUnmapBuffer(GL_ARRAY_BUFFER); +#ifdef DEBUG_ENABLED + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_WIREFRAME && s->instancing_array_wireframe_id) { + glBindVertexArray(s->instancing_array_wireframe_id); // use the wireframe instancing array ID + } else +#endif + { - glBindVertexArray(s->instancing_array_id); // use the instancing array ID + glBindVertexArray(s->instancing_array_id); // use the instancing array ID + } glBindBuffer(GL_ARRAY_BUFFER, particles->particle_buffer_histories[1]); //modify the buffer } else { - - glBindVertexArray(s->instancing_array_id); // use the instancing array ID +#ifdef DEBUG_ENABLED + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_WIREFRAME && s->instancing_array_wireframe_id) { + glBindVertexArray(s->instancing_array_wireframe_id); // use the wireframe instancing array ID + } else +#endif + { + glBindVertexArray(s->instancing_array_id); // use the instancing array ID + } glBindBuffer(GL_ARRAY_BUFFER, particles->particle_buffers[0]); //modify the buffer } @@ -1421,17 +1446,25 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) { RasterizerStorageGLES3::Surface *s = static_cast<RasterizerStorageGLES3::Surface *>(e->geometry); - if (s->index_array_len > 0) { +#ifdef DEBUG_ENABLED + + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_WIREFRAME && s->array_wireframe_id) { + + glDrawElements(GL_LINES, s->index_wireframe_len, GL_UNSIGNED_INT, 0); + storage->info.render.vertices_count += s->index_array_len; + } else +#endif + if (s->index_array_len > 0) { glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0); - storage->info.render_vertices_count += s->index_array_len; + storage->info.render.vertices_count += s->index_array_len; } else { glDrawArrays(gl_primitive[s->primitive], 0, s->array_len); - storage->info.render_vertices_count += s->array_len; + storage->info.render.vertices_count += s->array_len; } } break; @@ -1442,17 +1475,25 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) { int amount = MAX(multi_mesh->size, multi_mesh->visible_instances); - if (s->index_array_len > 0) { +#ifdef DEBUG_ENABLED + + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_WIREFRAME && s->array_wireframe_id) { + + glDrawElementsInstanced(GL_LINES, s->index_wireframe_len, GL_UNSIGNED_INT, 0, amount); + storage->info.render.vertices_count += s->index_array_len * amount; + } else +#endif + if (s->index_array_len > 0) { glDrawElementsInstanced(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0, amount); - storage->info.render_vertices_count += s->index_array_len * amount; + storage->info.render.vertices_count += s->index_array_len * amount; } else { glDrawArraysInstanced(gl_primitive[s->primitive], 0, s->array_len, amount); - storage->info.render_vertices_count += s->array_len * amount; + storage->info.render.vertices_count += s->array_len * amount; } } break; @@ -1478,7 +1519,7 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) { int vertices = c.vertices.size(); uint32_t buf_ofs = 0; - storage->info.render_vertices_count += vertices; + storage->info.render.vertices_count += vertices; if (c.texture.is_valid() && storage->texture_owner.owns(c.texture)) { @@ -1600,18 +1641,25 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) { glEnableVertexAttribArray(12); //custom glVertexAttribPointer(12, 4, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)NULL) + stride * split + sizeof(float) * 4 * 2); glVertexAttribDivisor(12, 1); +#ifdef DEBUG_ENABLED - if (s->index_array_len > 0) { + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_WIREFRAME && s->array_wireframe_id) { + + glDrawElementsInstanced(GL_LINES, s->index_wireframe_len, GL_UNSIGNED_INT, 0, amount - split); + storage->info.render.vertices_count += s->index_array_len * (amount - split); + } else +#endif + if (s->index_array_len > 0) { glDrawElementsInstanced(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0, amount - split); - storage->info.render_vertices_count += s->index_array_len * (amount - split); + storage->info.render.vertices_count += s->index_array_len * (amount - split); } else { glDrawArraysInstanced(gl_primitive[s->primitive], 0, s->array_len, amount - split); - storage->info.render_vertices_count += s->array_len * (amount - split); + storage->info.render.vertices_count += s->array_len * (amount - split); } } @@ -1631,34 +1679,49 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) { glEnableVertexAttribArray(12); //custom glVertexAttribPointer(12, 4, GL_FLOAT, GL_FALSE, stride, ((uint8_t *)NULL) + sizeof(float) * 4 * 2); glVertexAttribDivisor(12, 1); +#ifdef DEBUG_ENABLED - if (s->index_array_len > 0) { + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_WIREFRAME && s->array_wireframe_id) { + + glDrawElementsInstanced(GL_LINES, s->index_wireframe_len, GL_UNSIGNED_INT, 0, split); + storage->info.render.vertices_count += s->index_array_len * split; + } else +#endif + if (s->index_array_len > 0) { glDrawElementsInstanced(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0, split); - storage->info.render_vertices_count += s->index_array_len * split; + storage->info.render.vertices_count += s->index_array_len * split; } else { glDrawArraysInstanced(gl_primitive[s->primitive], 0, s->array_len, split); - storage->info.render_vertices_count += s->array_len * split; + storage->info.render.vertices_count += s->array_len * split; } } } else { - if (s->index_array_len > 0) { +#ifdef DEBUG_ENABLED + + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_WIREFRAME && s->array_wireframe_id) { + + glDrawElementsInstanced(GL_LINES, s->index_wireframe_len, GL_UNSIGNED_INT, 0, amount); + storage->info.render.vertices_count += s->index_array_len * amount; + } else +#endif + if (s->index_array_len > 0) { glDrawElementsInstanced(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0, amount); - storage->info.render_vertices_count += s->index_array_len * amount; + storage->info.render.vertices_count += s->index_array_len * amount; } else { glDrawArraysInstanced(gl_primitive[s->primitive], 0, s->array_len, amount); - storage->info.render_vertices_count += s->array_len * amount; + storage->info.render.vertices_count += s->array_len * amount; } } @@ -1783,13 +1846,6 @@ void RasterizerSceneGLES3::_set_cull(bool p_front, bool p_reverse_cull) { void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements, int p_element_count, const Transform &p_view_transform, const CameraMatrix &p_projection, GLuint p_base_env, bool p_reverse_cull, bool p_alpha_pass, bool p_shadow, bool p_directional_add, bool p_directional_shadows) { - if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP]) { - //p_reverse_cull=!p_reverse_cull; - glFrontFace(GL_CCW); - } else { - glFrontFace(GL_CW); - } - glBindBufferBase(GL_UNIFORM_BUFFER, 0, state.scene_ubo); //bind globals ubo if (!p_shadow && !p_directional_add) { @@ -1834,7 +1890,7 @@ void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements, int p_ bool first = true; bool prev_use_instancing = false; - storage->info.render_object_count += p_element_count; + storage->info.render.draw_call_count += p_element_count; for (int i = 0; i < p_element_count; i++) { @@ -1982,12 +2038,12 @@ void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements, int p_ if (material != prev_material || rebind) { - storage->info.render_material_switch_count++; + storage->info.render.material_switch_count++; rebind = _setup_material(material, p_alpha_pass); if (rebind) { - storage->info.render_shader_rebind_count++; + storage->info.render.shader_rebind_count++; } } @@ -1998,7 +2054,7 @@ void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements, int p_ if (e->owner != prev_owner || prev_base_type != e->instance->base_type || prev_geometry != e->geometry) { _setup_geometry(e, p_view_transform); - storage->info.render_surface_switch_count++; + storage->info.render.surface_switch_count++; } _set_cull(e->sort_key & RenderList::SORT_KEY_MIRROR_FLAG, p_reverse_cull); @@ -2041,6 +2097,10 @@ void RasterizerSceneGLES3::_add_geometry(RasterizerStorageGLES3::Geometry *p_geo RasterizerStorageGLES3::Material *m = NULL; RID m_src = p_instance->material_override.is_valid() ? p_instance->material_override : (p_material >= 0 ? p_instance->materials[p_material] : p_geometry->material); + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_OVERDRAW) { + m_src = default_overdraw_material; + } + /* #ifdef DEBUG_ENABLED if (current_debug==VS::SCENARIO_DEBUG_OVERDRAW) { @@ -2159,7 +2219,7 @@ void RasterizerSceneGLES3::_add_geometry(RasterizerStorageGLES3::Geometry *p_geo //e->light_type=0xFF; // no lights! - if (shadow || m->shader->spatial.unshaded /*|| current_debug==VS::SCENARIO_DEBUG_SHADELESS*/) { + if (shadow || m->shader->spatial.unshaded || state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_UNSHADED) { e->sort_key |= RenderList::SORT_KEY_UNSHADED_FLAG; } @@ -3306,19 +3366,21 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); - if (!env) { - //no environment, simply return and convert to SRGB + if (!env || storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) { + //no environment or transparent render, simply return and convert to SRGB glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color); storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB, true); - storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA, true); + storage->shaders.copy.set_conditional(CopyShaderGLES3::V_FLIP, storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP]); + storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA, !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]); storage->shaders.copy.bind(); _copy_screen(); storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB, false); storage->shaders.copy.set_conditional(CopyShaderGLES3::DISABLE_ALPHA, false); //compute luminance + storage->shaders.copy.set_conditional(CopyShaderGLES3::V_FLIP, false); return; } @@ -3692,6 +3754,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p } } + state.tonemap_shader.set_conditional(TonemapShaderGLES3::V_FLIP, storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP]); state.tonemap_shader.bind(); state.tonemap_shader.set_uniform(TonemapShaderGLES3::EXPOSURE, env->tone_mapper_exposure); @@ -3739,6 +3802,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_FILTER_BICUBIC, false); state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_BCS, false); state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_COLOR_CORRECTION, false); + state.tonemap_shader.set_conditional(TonemapShaderGLES3::V_FLIP, false); } void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) { @@ -3748,6 +3812,8 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const //fill up ubo + storage->info.render.object_count += p_cull_count; + Environment *env = environment_owner.getornull(p_environment); ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_shadow_atlas); ReflectionAtlas *reflection_atlas = reflection_atlas_owner.getornull(p_reflection_atlas); @@ -3792,7 +3858,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const state.used_contact_shadows = true; - if (storage->frame.current_rt && true) { //detect with state.used_contact_shadows too + if (storage->frame.current_rt && state.debug_draw != VS::VIEWPORT_DEBUG_DRAW_OVERDRAW) { //detect with state.used_contact_shadows too //pre z pass glDisable(GL_BLEND); @@ -3880,6 +3946,10 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const } else { use_mrt = env && (state.used_screen_texture || state.used_sss || env->ssao_enabled || env->ssr_enabled); //only enable MRT rendering if any of these is enabled + //effects disabled and transparency also prevent using MRTs + use_mrt = use_mrt && !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]; + use_mrt = use_mrt && !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_NO_3D_EFFECTS]; + use_mrt = use_mrt && state.debug_draw != VS::VIEWPORT_DEBUG_DRAW_OVERDRAW; glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height); @@ -3928,7 +3998,12 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const RasterizerStorageGLES3::Sky *sky = NULL; GLuint env_radiance_tex = 0; - if (!env || env->bg_mode == VS::ENV_BG_CLEAR_COLOR) { + if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_OVERDRAW) { + clear_color = Color(0, 0, 0, 0); + storage->frame.clear_request = false; + } else if (storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) { + clear_color = Color(0, 0, 0, 0); + } else if (!env || env->bg_mode == VS::ENV_BG_CLEAR_COLOR) { if (storage->frame.clear_request) { @@ -3961,20 +4036,14 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) { glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); } else { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_BLEND); } - glDisable(GL_BLEND); - render_list.sort_by_key(false); - if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) { - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - } else { - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - if (state.directional_light_count == 0) { directional_light = NULL; _render_list(render_list.elements, render_list.element_count, p_cam_transform, p_cam_projection, env_radiance_tex, false, false, false, false, shadow_atlas != NULL); @@ -3996,14 +4065,14 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const glDrawBuffers(1, &gldb); } - if (env && env->bg_mode == VS::ENV_BG_SKY) { + if (env && env->bg_mode == VS::ENV_BG_SKY && !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT] && state.debug_draw != VS::VIEWPORT_DEBUG_DRAW_OVERDRAW) { /* if (use_mrt) { glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->buffers.fbo); //switch to alpha fbo for sky, only diffuse/ambient matters */ - _draw_sky(sky, p_cam_projection, p_cam_transform, storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP], env->sky_scale, env->bg_energy); + _draw_sky(sky, p_cam_projection, p_cam_transform, false, env->sky_scale, env->bg_energy); } //_render_list_forward(&alpha_render_list,camera_transform,camera_transform_inverse,camera_projection,false,fragment_lighting,true); @@ -4558,136 +4627,39 @@ bool RasterizerSceneGLES3::free(RID p_rid) { return true; } -// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html -static _FORCE_INLINE_ float radicalInverse_VdC(uint32_t bits) { - bits = (bits << 16u) | (bits >> 16u); - bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u); - bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u); - bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u); - bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u); - return float(bits) * 2.3283064365386963e-10f; // / 0x100000000 -} +void RasterizerSceneGLES3::set_debug_draw_mode(VS::ViewportDebugDraw p_debug_draw) { -static _FORCE_INLINE_ Vector2 Hammersley(uint32_t i, uint32_t N) { - return Vector2(float(i) / float(N), radicalInverse_VdC(i)); + state.debug_draw = p_debug_draw; } -static _FORCE_INLINE_ Vector3 ImportanceSampleGGX(Vector2 Xi, float Roughness, Vector3 N) { - float a = Roughness * Roughness; // DISNEY'S ROUGHNESS [see Burley'12 siggraph] - - // Compute distribution direction - float Phi = 2.0f * Math_PI * Xi.x; - float CosTheta = Math::sqrt((float)(1.0f - Xi.y) / (1.0f + (a * a - 1.0f) * Xi.y)); - float SinTheta = Math::sqrt((float)Math::abs(1.0f - CosTheta * CosTheta)); - - // Convert to spherical direction - Vector3 H; - H.x = SinTheta * Math::cos(Phi); - H.y = SinTheta * Math::sin(Phi); - H.z = CosTheta; - - Vector3 UpVector = Math::abs(N.z) < 0.999 ? Vector3(0.0, 0.0, 1.0) : Vector3(1.0, 0.0, 0.0); - Vector3 TangentX = UpVector.cross(N); - TangentX.normalize(); - Vector3 TangentY = N.cross(TangentX); - - // Tangent to world space - return TangentX * H.x + TangentY * H.y + N * H.z; -} - -static _FORCE_INLINE_ float GGX(float NdotV, float a) { - float k = a / 2.0; - return NdotV / (NdotV * (1.0 - k) + k); -} - -// http://graphicrants.blogspot.com.au/2013/08/specular-brdf-reference.html -float _FORCE_INLINE_ G_Smith(float a, float nDotV, float nDotL) { - return GGX(nDotL, a * a) * GGX(nDotV, a * a); -} - -void RasterizerSceneGLES3::_generate_brdf() { - - int brdf_size = GLOBAL_DEF("rendering/gles3/brdf_texture_size", 64); - - PoolVector<uint8_t> brdf; - brdf.resize(brdf_size * brdf_size * 2); - - PoolVector<uint8_t>::Write w = brdf.write(); - - for (int i = 0; i < brdf_size; i++) { - for (int j = 0; j < brdf_size; j++) { - - float Roughness = float(j) / (brdf_size - 1); - float NoV = float(i + 1) / (brdf_size); //avoid storing nov0 - - Vector3 V; - V.x = Math::sqrt(1.0f - NoV * NoV); - V.y = 0.0; - V.z = NoV; - - Vector3 N = Vector3(0.0, 0.0, 1.0); - - float A = 0; - float B = 0; - - for (int s = 0; s < 512; s++) { - - Vector2 xi = Hammersley(s, 512); - Vector3 H = ImportanceSampleGGX(xi, Roughness, N); - Vector3 L = 2.0 * V.dot(H) * H - V; +void RasterizerSceneGLES3::initialize() { - float NoL = CLAMP(L.z, 0.0, 1.0); - float NoH = CLAMP(H.z, 0.0, 1.0); - float VoH = CLAMP(V.dot(H), 0.0, 1.0); + render_pass = 0; - if (NoL > 0.0) { - float G = G_Smith(Roughness, NoV, NoL); - float G_Vis = G * VoH / (NoH * NoV); - float Fc = pow(1.0 - VoH, 5.0); + state.scene_shader.init(); - A += (1.0 - Fc) * G_Vis; - B += Fc * G_Vis; - } - } + { + //default material and shader - A /= 512.0; - B /= 512.0; + default_shader = storage->shader_create(); + storage->shader_set_code(default_shader, "shader_type spatial;\n"); + default_material = storage->material_create(); + storage->material_set_shader(default_material, default_shader); - int tofs = ((brdf_size - j - 1) * brdf_size + i) * 2; - w[tofs + 0] = CLAMP(A * 255, 0, 255); - w[tofs + 1] = CLAMP(B * 255, 0, 255); - } + default_shader_twosided = storage->shader_create(); + default_material_twosided = storage->material_create(); + storage->shader_set_code(default_shader_twosided, "shader_type spatial; render_mode cull_disabled;\n"); + storage->material_set_shader(default_material_twosided, default_shader_twosided); } - //set up brdf texture - - glGenTextures(1, &state.brdf_texture); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, state.brdf_texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RG8, brdf_size, brdf_size, 0, GL_RG, GL_UNSIGNED_BYTE, w.ptr()); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glBindTexture(GL_TEXTURE_2D, 0); -} - -void RasterizerSceneGLES3::initialize() { - - render_pass = 0; - - state.scene_shader.init(); - - default_shader = storage->shader_create(); - storage->shader_set_code(default_shader, "shader_type spatial;\n"); - default_material = storage->material_create(); - storage->material_set_shader(default_material, default_shader); + { + //default material and shader - default_shader_twosided = storage->shader_create(); - default_material_twosided = storage->material_create(); - storage->shader_set_code(default_shader_twosided, "shader_type spatial; render_mode cull_disabled;\n"); - storage->material_set_shader(default_material_twosided, default_shader_twosided); + default_overdraw_shader = storage->shader_create(); + storage->shader_set_code(default_overdraw_shader, "shader_type spatial;\nrender_mode blend_add,unshaded;\n void fragment() { ALBEDO=vec3(0.4,0.8,0.8); ALPHA=0.2; }"); + default_overdraw_material = storage->material_create(); + storage->material_set_shader(default_overdraw_material, default_overdraw_shader); + } glGenBuffers(1, &state.scene_ubo); glBindBuffer(GL_UNIFORM_BUFFER, state.scene_ubo); @@ -4725,7 +4697,6 @@ void RasterizerSceneGLES3::initialize() { } render_list.init(); state.cube_to_dp_shader.init(); - _generate_brdf(); shadow_atlas_realloc_tolerance_msec = 500; @@ -4972,6 +4943,8 @@ void RasterizerSceneGLES3::initialize() { GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); ERR_CONTINUE(status != GL_FRAMEBUFFER_COMPLETE); } + + state.debug_draw = VS::VIEWPORT_DEBUG_DRAW_DISABLED; } void RasterizerSceneGLES3::iteration() { diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h index 55d314a800..59b8e3fb35 100644 --- a/drivers/gles3/rasterizer_scene_gles3.h +++ b/drivers/gles3/rasterizer_scene_gles3.h @@ -77,6 +77,9 @@ public: RID default_shader; RID default_shader_twosided; + RID default_overdraw_material; + RID default_overdraw_shader; + RasterizerStorageGLES3 *storage; Vector<RasterizerStorageGLES3::RenderTarget::Exposure> exposure_shrink; @@ -152,8 +155,6 @@ public: GLuint env_radiance_ubo; - GLuint brdf_texture; - GLuint sky_verts; GLuint sky_array; @@ -187,6 +188,7 @@ public: bool used_sss; bool used_screen_texture; + VS::ViewportDebugDraw debug_draw; } state; /* SHADOW ATLAS API */ @@ -783,9 +785,8 @@ public: virtual void render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, InstanceBase **p_cull_result, int p_cull_count); virtual bool free(RID p_rid); - void _generate_brdf(); - virtual void set_scene_pass(uint64_t p_pass); + virtual void set_debug_draw_mode(VS::ViewportDebugDraw p_debug_draw); void iteration(); void initialize(); diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index a503b6daa7..54e99eb622 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -782,7 +782,6 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Ref<Image> &p int bh = h; glCompressedTexImage2D(blit_target, i, internal_format, bw, bh, 0, size, &read[ofs]); - print_line("format: " + Image::get_format_name(texture->format) + " size: " + Vector2(bw, bh) + " block: " + itos(block)); } else { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); @@ -825,8 +824,7 @@ Ref<Image> RasterizerStorageGLES3::texture_get_data(RID p_texture, VS::CubeMapSi ERR_FAIL_COND_V(!texture, Ref<Image>()); ERR_FAIL_COND_V(!texture->active, Ref<Image>()); - ERR_FAIL_COND_V(texture->data_size == 0, Ref<Image>()); - ERR_FAIL_COND_V(texture->render_target, Ref<Image>()); + ERR_FAIL_COND_V(texture->data_size == 0 && !texture->render_target, Ref<Image>()); if (!texture->images[p_cube_side].is_null()) { return texture->images[p_cube_side]; @@ -2660,6 +2658,7 @@ void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: surface->skeleton_bone_used.resize(surface->skeleton_bone_aabb.size()); surface->aabb = p_aabb; surface->max_bone = p_bone_aabbs.size(); + surface->total_data_size += surface->array_byte_size + surface->index_array_byte_size; for (int i = 0; i < surface->skeleton_bone_used.size(); i++) { if (surface->skeleton_bone_aabb[i].size.x < 0 || surface->skeleton_bone_aabb[i].size.y < 0 || surface->skeleton_bone_aabb[i].size.z < 0) { @@ -2729,6 +2728,112 @@ void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } + +#ifdef DEBUG_ENABLED + + if (config.generate_wireframes && p_primitive == VS::PRIMITIVE_TRIANGLES) { + //generate wireframes, this is used mostly by editor + PoolVector<uint32_t> wf_indices; + int index_count; + + if (p_format & VS::ARRAY_FORMAT_INDEX) { + + index_count = p_index_count * 2; + wf_indices.resize(index_count); + + PoolVector<uint8_t>::Read ir = p_index_array.read(); + PoolVector<uint32_t>::Write wr = wf_indices.write(); + + if (p_vertex_count < (1 << 16)) { + //read 16 bit indices + const uint16_t *src_idx = (const uint16_t *)ir.ptr(); + for (int i = 0; i < index_count; i += 6) { + + wr[i + 0] = src_idx[i / 2]; + wr[i + 1] = src_idx[i / 2 + 1]; + wr[i + 2] = src_idx[i / 2 + 1]; + wr[i + 3] = src_idx[i / 2 + 2]; + wr[i + 4] = src_idx[i / 2 + 2]; + wr[i + 5] = src_idx[i / 2]; + } + + } else { + + //read 16 bit indices + const uint32_t *src_idx = (const uint32_t *)ir.ptr(); + for (int i = 0; i < index_count; i += 6) { + + wr[i + 0] = src_idx[i / 2]; + wr[i + 1] = src_idx[i / 2 + 1]; + wr[i + 2] = src_idx[i / 2 + 1]; + wr[i + 3] = src_idx[i / 2 + 2]; + wr[i + 4] = src_idx[i / 2 + 2]; + wr[i + 5] = src_idx[i / 2]; + } + } + + } else { + + index_count = p_vertex_count * 2; + wf_indices.resize(index_count); + PoolVector<uint32_t>::Write wr = wf_indices.write(); + for (int i = 0; i < index_count; i += 6) { + + wr[i + 0] = i / 2; + wr[i + 1] = i / 2 + 1; + wr[i + 2] = i / 2 + 1; + wr[i + 3] = i / 2 + 2; + wr[i + 4] = i / 2 + 2; + wr[i + 5] = i / 2; + } + } + { + PoolVector<uint32_t>::Read ir = wf_indices.read(); + + glGenBuffers(1, &surface->index_wireframe_id); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, surface->index_wireframe_id); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_count * sizeof(uint32_t), ir.ptr(), GL_STATIC_DRAW); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); //unbind + + surface->index_wireframe_len = index_count; + } + + for (int ai = 0; ai < 2; ai++) { + + if (ai == 0) { + //for normal draw + glGenVertexArrays(1, &surface->array_wireframe_id); + glBindVertexArray(surface->array_wireframe_id); + glBindBuffer(GL_ARRAY_BUFFER, surface->vertex_id); + } else if (ai == 1) { + //for instancing draw (can be changed and no one cares) + glGenVertexArrays(1, &surface->instancing_array_wireframe_id); + glBindVertexArray(surface->instancing_array_wireframe_id); + glBindBuffer(GL_ARRAY_BUFFER, surface->vertex_id); + } + + for (int i = 0; i < VS::ARRAY_MAX - 1; i++) { + + if (!attribs[i].enabled) + continue; + + if (attribs[i].integer) { + glVertexAttribIPointer(attribs[i].index, attribs[i].size, attribs[i].type, attribs[i].stride, ((uint8_t *)0) + attribs[i].offset); + } else { + glVertexAttribPointer(attribs[i].index, attribs[i].size, attribs[i].type, attribs[i].normalized, attribs[i].stride, ((uint8_t *)0) + attribs[i].offset); + } + glEnableVertexAttribArray(attribs[i].index); + } + + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, surface->index_wireframe_id); + + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + } + } + +#endif } { @@ -2741,6 +2846,8 @@ void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: PoolVector<uint8_t>::Read vr = p_blend_shapes[i].read(); + surface->total_data_size += array_size; + glGenBuffers(1, &mt.vertex_id); glBindBuffer(GL_ARRAY_BUFFER, mt.vertex_id); glBufferData(GL_ARRAY_BUFFER, array_size, vr.ptr(), GL_STATIC_DRAW); @@ -2772,6 +2879,8 @@ void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: mesh->surfaces.push_back(surface); mesh->instance_change_notify(); + + info.vertex_mem += surface->total_data_size; } void RasterizerStorageGLES3::mesh_set_blend_shape_count(RID p_mesh, int p_amount) { @@ -3000,6 +3109,14 @@ void RasterizerStorageGLES3::mesh_remove_surface(RID p_mesh, int p_surface) { glDeleteVertexArrays(1, &surface->blend_shapes[i].array_id); } + if (surface->index_wireframe_id) { + glDeleteBuffers(1, &surface->index_wireframe_id); + glDeleteVertexArrays(1, &surface->array_wireframe_id); + glDeleteVertexArrays(1, &surface->instancing_array_wireframe_id); + } + + info.vertex_mem -= surface->total_data_size; + mesh->instance_material_change_notify(); memdelete(surface); @@ -3832,7 +3949,7 @@ void RasterizerStorageGLES3::immediate_vertex(RID p_immediate, const Vector3 &p_ if (c->vertices.empty() && im->chunks.size() == 1) { - im->aabb.pos = p_vertex; + im->aabb.position = p_vertex; im->aabb.size = Vector3(); } else { im->aabb.expand_to(p_vertex); @@ -4499,7 +4616,7 @@ Rect3 RasterizerStorageGLES3::reflection_probe_get_aabb(RID p_probe) const { ERR_FAIL_COND_V(!reflection_probe, Rect3()); Rect3 aabb; - aabb.pos = -reflection_probe->extents; + aabb.position = -reflection_probe->extents; aabb.size = reflection_probe->extents * 2.0; return aabb; @@ -5092,7 +5209,7 @@ Rect3 RasterizerStorageGLES3::particles_get_current_aabb(RID p_particles) { pos = inv.xform(pos); } if (i == 0) - aabb.pos = pos; + aabb.position = pos; else aabb.expand_to(pos); } @@ -5493,6 +5610,7 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) { tex->alloc_width = 0; tex->width = 0; tex->height = 0; + tex->active = false; for (int i = 0; i < 2; i++) { for (int j = 0; j < rt->effects.mip_maps[i].sizes.size(); j++) { @@ -5589,13 +5707,14 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) { tex->alloc_width = rt->width; tex->height = rt->height; tex->alloc_height = rt->height; + tex->active = true; texture_set_flags(rt->texture, tex->flags); } /* BACK FBO */ - if (config.render_arch == RENDER_ARCH_DESKTOP && !rt->flags[RENDER_TARGET_NO_3D]) { + if (!rt->flags[RENDER_TARGET_NO_3D]) { static const int msaa_value[] = { 0, 2, 4, 8, 16 }; int msaa = msaa_value[rt->msaa]; @@ -5623,75 +5742,155 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) { glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rt->buffers.diffuse); - glGenRenderbuffers(1, &rt->buffers.specular); - glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.specular); + if (!rt->flags[RENDER_TARGET_NO_3D_EFFECTS]) { - if (msaa == 0) - glRenderbufferStorage(GL_RENDERBUFFER, color_internal_format, rt->width, rt->height); - else - glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, color_internal_format, rt->width, rt->height); + glGenRenderbuffers(1, &rt->buffers.specular); + glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.specular); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, rt->buffers.specular); + if (msaa == 0) + glRenderbufferStorage(GL_RENDERBUFFER, color_internal_format, rt->width, rt->height); + else + glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, color_internal_format, rt->width, rt->height); - glGenRenderbuffers(1, &rt->buffers.normal_rough); - glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.normal_rough); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, rt->buffers.specular); - if (msaa == 0) - glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, rt->width, rt->height); - else - glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_RGBA8, rt->width, rt->height); + glGenRenderbuffers(1, &rt->buffers.normal_rough); + glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.normal_rough); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_RENDERBUFFER, rt->buffers.normal_rough); + if (msaa == 0) + glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, rt->width, rt->height); + else + glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_RGBA8, rt->width, rt->height); - glGenRenderbuffers(1, &rt->buffers.sss); - glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.sss); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_RENDERBUFFER, rt->buffers.normal_rough); - if (msaa == 0) - glRenderbufferStorage(GL_RENDERBUFFER, GL_R8, rt->width, rt->height); - else - glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_R8, rt->width, rt->height); + glGenRenderbuffers(1, &rt->buffers.sss); + glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.sss); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_RENDERBUFFER, rt->buffers.sss); + if (msaa == 0) + glRenderbufferStorage(GL_RENDERBUFFER, GL_R8, rt->width, rt->height); + else + glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_R8, rt->width, rt->height); - GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_RENDERBUFFER, rt->buffers.sss); - if (status != GL_FRAMEBUFFER_COMPLETE) { - printf("err status: %x\n", status); - _render_target_clear(rt); - ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); - } + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo); - glBindRenderbuffer(GL_RENDERBUFFER, 0); + if (status != GL_FRAMEBUFFER_COMPLETE) { + printf("err status: %x\n", status); + _render_target_clear(rt); + ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); + } - // effect resolver + glBindRenderbuffer(GL_RENDERBUFFER, 0); - glGenFramebuffers(1, &rt->buffers.effect_fbo); - glBindFramebuffer(GL_FRAMEBUFFER, rt->buffers.effect_fbo); + // effect resolver - glGenTextures(1, &rt->buffers.effect); - glBindTexture(GL_TEXTURE_2D, rt->buffers.effect); - glTexImage2D(GL_TEXTURE_2D, 0, color_internal_format, rt->width, rt->height, 0, - color_format, color_type, NULL); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - GL_TEXTURE_2D, rt->buffers.effect, 0); + glGenFramebuffers(1, &rt->buffers.effect_fbo); + glBindFramebuffer(GL_FRAMEBUFFER, rt->buffers.effect_fbo); - if (status != GL_FRAMEBUFFER_COMPLETE) { - printf("err status: %x\n", status); - _render_target_clear(rt); - ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); - } + glGenTextures(1, &rt->buffers.effect); + glBindTexture(GL_TEXTURE_2D, rt->buffers.effect); + glTexImage2D(GL_TEXTURE_2D, 0, color_internal_format, rt->width, rt->height, 0, + color_format, color_type, NULL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + GL_TEXTURE_2D, rt->buffers.effect, 0); - glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo); + if (status != GL_FRAMEBUFFER_COMPLETE) { + printf("err status: %x\n", status); + _render_target_clear(rt); + ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); + } - if (status != GL_FRAMEBUFFER_COMPLETE) { - _render_target_clear(rt); - ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); + glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo); + + if (status != GL_FRAMEBUFFER_COMPLETE) { + _render_target_clear(rt); + ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); + } + + ///////////////// ssao + + //AO strength textures + for (int i = 0; i < 2; i++) { + + glGenFramebuffers(1, &rt->effects.ssao.blur_fbo[i]); + glBindFramebuffer(GL_FRAMEBUFFER, rt->effects.ssao.blur_fbo[i]); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, + GL_TEXTURE_2D, rt->depth, 0); + + glGenTextures(1, &rt->effects.ssao.blur_red[i]); + glBindTexture(GL_TEXTURE_2D, rt->effects.ssao.blur_red[i]); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, rt->width, rt->height, 0, GL_RED, GL_UNSIGNED_BYTE, NULL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->effects.ssao.blur_red[i], 0); + + status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) { + _render_target_clear(rt); + ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); + } + } + //5 mip levels for depth texture, but base is read separately + + glGenTextures(1, &rt->effects.ssao.linear_depth); + glBindTexture(GL_TEXTURE_2D, rt->effects.ssao.linear_depth); + + int ssao_w = rt->width / 2; + int ssao_h = rt->height / 2; + + for (int i = 0; i < 4; i++) { //5, but 4 mips, base is read directly to save bw + + glTexImage2D(GL_TEXTURE_2D, i, GL_R16UI, ssao_w, ssao_h, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, NULL); + ssao_w >>= 1; + ssao_h >>= 1; + } + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 3); + + for (int i = 0; i < 4; i++) { //5, but 4 mips, base is read directly to save bw + + GLuint fbo; + glGenFramebuffers(1, &fbo); + glBindFramebuffer(GL_FRAMEBUFFER, fbo); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->effects.ssao.linear_depth, i); + rt->effects.ssao.depth_mipmap_fbos.push_back(fbo); + } + + //////Exposure + + glGenFramebuffers(1, &rt->exposure.fbo); + glBindFramebuffer(GL_FRAMEBUFFER, rt->exposure.fbo); + + glGenTextures(1, &rt->exposure.color); + glBindTexture(GL_TEXTURE_2D, rt->exposure.color); + glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, 1, 1, 0, GL_RED, GL_FLOAT, NULL); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->exposure.color, 0); + + status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) { + _render_target_clear(rt); + ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); + } } + } + + if (!rt->flags[RENDER_TARGET_NO_SAMPLING]) { for (int i = 0; i < 2; i++) { @@ -5738,7 +5937,7 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) { glBindFramebuffer(GL_FRAMEBUFFER, mm.fbo); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->effects.mip_maps[i].color, j); - status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { _render_target_clear(rt); ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); @@ -5758,79 +5957,6 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) { glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } - ///////////////// ssao - - //AO strength textures - for (int i = 0; i < 2; i++) { - - glGenFramebuffers(1, &rt->effects.ssao.blur_fbo[i]); - glBindFramebuffer(GL_FRAMEBUFFER, rt->effects.ssao.blur_fbo[i]); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, - GL_TEXTURE_2D, rt->depth, 0); - - glGenTextures(1, &rt->effects.ssao.blur_red[i]); - glBindTexture(GL_TEXTURE_2D, rt->effects.ssao.blur_red[i]); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, rt->width, rt->height, 0, GL_RED, GL_UNSIGNED_BYTE, NULL); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->effects.ssao.blur_red[i], 0); - - status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) { - _render_target_clear(rt); - ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); - } - } - //5 mip levels for depth texture, but base is read separately - - glGenTextures(1, &rt->effects.ssao.linear_depth); - glBindTexture(GL_TEXTURE_2D, rt->effects.ssao.linear_depth); - - int ssao_w = rt->width / 2; - int ssao_h = rt->height / 2; - - for (int i = 0; i < 4; i++) { //5, but 4 mips, base is read directly to save bw - - glTexImage2D(GL_TEXTURE_2D, i, GL_R16UI, ssao_w, ssao_h, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, NULL); - ssao_w >>= 1; - ssao_h >>= 1; - } - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 3); - - for (int i = 0; i < 4; i++) { //5, but 4 mips, base is read directly to save bw - - GLuint fbo; - glGenFramebuffers(1, &fbo); - glBindFramebuffer(GL_FRAMEBUFFER, fbo); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->effects.ssao.linear_depth, i); - rt->effects.ssao.depth_mipmap_fbos.push_back(fbo); - } - - //////Exposure - - glGenFramebuffers(1, &rt->exposure.fbo); - glBindFramebuffer(GL_FRAMEBUFFER, rt->exposure.fbo); - - glGenTextures(1, &rt->exposure.color); - glBindTexture(GL_TEXTURE_2D, rt->exposure.color); - glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, 1, 1, 0, GL_RED, GL_FLOAT, NULL); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->exposure.color, 0); - - status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) { - _render_target_clear(rt); - ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); - } } } @@ -5855,9 +5981,10 @@ RID RasterizerStorageGLES3::render_target_create() { t->srgb = false; t->total_data_size = 0; t->ignore_mipmaps = false; - t->mipmaps = 0; + t->mipmaps = 1; t->active = true; t->tex_id = 0; + t->render_target = rt; rt->texture = texture_owner.make_rid(t); @@ -5894,8 +6021,10 @@ void RasterizerStorageGLES3::render_target_set_flag(RID p_render_target, RenderT rt->flags[p_flag] = p_value; switch (p_flag) { + case RENDER_TARGET_HDR: case RENDER_TARGET_NO_3D: - case RENDER_TARGET_TRANSPARENT: { + case RENDER_TARGET_NO_SAMPLING: + case RENDER_TARGET_NO_3D_EFFECTS: { //must reset for these formats _render_target_clear(rt); _render_target_allocate(rt); @@ -6335,10 +6464,98 @@ bool RasterizerStorageGLES3::has_os_feature(const String &p_feature) const { //////////////////////////////////////////// -void RasterizerStorageGLES3::initialize() { +void RasterizerStorageGLES3::set_debug_generate_wireframes(bool p_generate) { + + config.generate_wireframes = p_generate; +} + +void RasterizerStorageGLES3::render_info_begin_capture() { + + info.snap = info.render; +} - config.render_arch = RENDER_ARCH_DESKTOP; - //config.fbo_deferred=int(Globals::get_singleton()->get("rendering/gles3/lighting_technique")); +void RasterizerStorageGLES3::render_info_end_capture() { + + info.snap.object_count = info.render.object_count - info.snap.object_count; + info.snap.draw_call_count = info.render.draw_call_count - info.snap.draw_call_count; + info.snap.material_switch_count = info.render.material_switch_count - info.snap.material_switch_count; + info.snap.surface_switch_count = info.render.surface_switch_count - info.snap.surface_switch_count; + info.snap.shader_rebind_count = info.render.shader_rebind_count - info.snap.shader_rebind_count; + info.snap.vertices_count = info.render.vertices_count - info.snap.vertices_count; +} + +int RasterizerStorageGLES3::get_captured_render_info(VS::RenderInfo p_info) { + + switch (p_info) { + case VS::INFO_OBJECTS_IN_FRAME: { + + return info.snap.object_count; + } break; + case VS::INFO_VERTICES_IN_FRAME: { + + return info.snap.vertices_count; + } break; + case VS::INFO_MATERIAL_CHANGES_IN_FRAME: { + return info.snap.material_switch_count; + } break; + case VS::INFO_SHADER_CHANGES_IN_FRAME: { + return info.snap.shader_rebind_count; + } break; + case VS::INFO_SURFACE_CHANGES_IN_FRAME: { + return info.snap.surface_switch_count; + } break; + case VS::INFO_DRAW_CALLS_IN_FRAME: { + return info.snap.draw_call_count; + } break; + default: { + return get_render_info(p_info); + } + } +} + +int RasterizerStorageGLES3::get_render_info(VS::RenderInfo p_info) { + + switch (p_info) { + case VS::INFO_OBJECTS_IN_FRAME: { + + return info.render_final.object_count; + } break; + case VS::INFO_VERTICES_IN_FRAME: { + + return info.render_final.vertices_count; + } break; + case VS::INFO_MATERIAL_CHANGES_IN_FRAME: { + return info.render_final.material_switch_count; + } break; + case VS::INFO_SHADER_CHANGES_IN_FRAME: { + return info.render_final.shader_rebind_count; + } break; + case VS::INFO_SURFACE_CHANGES_IN_FRAME: { + return info.render_final.surface_switch_count; + } break; + case VS::INFO_DRAW_CALLS_IN_FRAME: { + return info.render_final.draw_call_count; + } break; + case VS::INFO_USAGE_VIDEO_MEM_TOTAL: { + + return 0; //no idea + } break; + case VS::INFO_VIDEO_MEM_USED: { + + return info.vertex_mem + info.texture_mem; + } break; + case VS::INFO_TEXTURE_MEM_USED: { + + return info.texture_mem; + } break; + case VS::INFO_VERTEX_MEM_USED: { + + return info.vertex_mem; + } break; + } +} + +void RasterizerStorageGLES3::initialize() { RasterizerStorageGLES3::system_fbo = 0; @@ -6519,6 +6736,7 @@ void RasterizerStorageGLES3::initialize() { frame.delta = 0; frame.current_rt = NULL; config.keep_original_textures = false; + config.generate_wireframes = false; } void RasterizerStorageGLES3::finalize() { diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index c8edeaefbf..1357206bfa 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -61,8 +61,6 @@ public: struct Config { - RenderArchitecture render_arch; - bool shrink_textures_x2; bool use_fast_texture_filter; bool use_anisotropic_filter; @@ -86,6 +84,8 @@ public: int max_texture_image_units; int max_texture_size; + bool generate_wireframes; + Set<String> extensions; bool keep_original_textures; @@ -126,12 +126,33 @@ public: struct Info { uint64_t texture_mem; + uint64_t vertex_mem; + + struct Render { + uint32_t object_count; + uint32_t draw_call_count; + uint32_t material_switch_count; + uint32_t surface_switch_count; + uint32_t shader_rebind_count; + uint32_t vertices_count; + + void reset() { + object_count = 0; + draw_call_count = 0; + material_switch_count = 0; + surface_switch_count = 0; + shader_rebind_count = 0; + vertices_count = 0; + } + } render, render_final, snap; - uint32_t render_object_count; - uint32_t render_material_switch_count; - uint32_t render_surface_switch_count; - uint32_t render_shader_rebind_count; - uint32_t render_vertices_count; + Info() { + + texture_mem = 0; + vertex_mem = 0; + render.reset(); + render_final.reset(); + } } info; @@ -539,6 +560,11 @@ public: GLuint vertex_id; GLuint index_id; + GLuint index_wireframe_id; + GLuint array_wireframe_id; + GLuint instancing_array_wireframe_id; + int index_wireframe_len; + Vector<Rect3> skeleton_bone_aabb; Vector<bool> skeleton_bone_used; @@ -569,6 +595,8 @@ public: mesh->update_multimeshes(); } + int total_data_size; + Surface() { array_byte_size = 0; @@ -583,6 +611,13 @@ public: primitive = VS::PRIMITIVE_POINTS; index_array_len = 0; active = false; + + total_data_size = 0; + + index_wireframe_id = 0; + array_wireframe_id = 0; + instancing_array_wireframe_id = 0; + index_wireframe_len = 0; } ~Surface() { @@ -1209,9 +1244,10 @@ public: flags[RENDER_TARGET_VFLIP] = false; flags[RENDER_TARGET_TRANSPARENT] = false; + flags[RENDER_TARGET_NO_3D_EFFECTS] = false; flags[RENDER_TARGET_NO_3D] = false; - flags[RENDER_TARGET_HDR] = true; flags[RENDER_TARGET_NO_SAMPLING] = false; + flags[RENDER_TARGET_HDR] = true; last_exposure_tick = 0; } @@ -1275,6 +1311,7 @@ public: float delta; uint64_t prev_tick; uint64_t count; + } frame; void initialize(); @@ -1284,6 +1321,14 @@ public: virtual void update_dirty_resources(); + virtual void set_debug_generate_wireframes(bool p_generate); + + virtual void render_info_begin_capture(); + virtual void render_info_end_capture(); + virtual int get_captured_render_info(VS::RenderInfo p_info); + + virtual int get_render_info(VS::RenderInfo p_info); + RasterizerStorageGLES3(); }; diff --git a/drivers/gles3/shaders/copy.glsl b/drivers/gles3/shaders/copy.glsl index 621ae83162..4c8648903e 100644 --- a/drivers/gles3/shaders/copy.glsl +++ b/drivers/gles3/shaders/copy.glsl @@ -23,6 +23,10 @@ void main() { cube_interp = cube_in; #else uv_interp = uv_in; +#ifdef V_FLIP + uv_interp.y = 1.0-uv_interp.y; +#endif + #endif uv2_interp = uv2_in; gl_Position = vertex_attrib; diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index 8965f475d7..60efc953f9 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -1709,7 +1709,7 @@ FRAGMENT_SHADER_CODE sss_buffer = sss_strength; #endif -#else +#else //USE_MULTIPLE_RENDER_TARGETS #ifdef SHADELESS diff --git a/drivers/gles3/shaders/tonemap.glsl b/drivers/gles3/shaders/tonemap.glsl index b2615fa29c..3ce2edf4e9 100644 --- a/drivers/gles3/shaders/tonemap.glsl +++ b/drivers/gles3/shaders/tonemap.glsl @@ -6,12 +6,13 @@ layout(location=4) in vec2 uv_in; out vec2 uv_interp; - - void main() { gl_Position = vertex_attrib; uv_interp = uv_in; +#ifdef V_FLIP + uv_interp.y = 1.0-uv_interp.y; +#endif } diff --git a/drivers/png/resource_saver_png.cpp b/drivers/png/resource_saver_png.cpp index 1700603489..0d7e1d9d72 100644 --- a/drivers/png/resource_saver_png.cpp +++ b/drivers/png/resource_saver_png.cpp @@ -55,41 +55,6 @@ Error ResourceSaverPNG::save(const String &p_path, const RES &p_resource, uint32 Error err = save_image(p_path, img); if (err == OK) { - - bool global_filter = GlobalConfig::get_singleton()->get("image_loader/filter"); - bool global_mipmaps = GlobalConfig::get_singleton()->get("image_loader/gen_mipmaps"); - bool global_repeat = GlobalConfig::get_singleton()->get("image_loader/repeat"); - - String text; - - if (global_filter != bool(texture->get_flags() & Texture::FLAG_FILTER)) { - text += bool(texture->get_flags() & Texture::FLAG_FILTER) ? "filter=true\n" : "filter=false\n"; - } - if (global_mipmaps != bool(texture->get_flags() & Texture::FLAG_MIPMAPS)) { - text += bool(texture->get_flags() & Texture::FLAG_MIPMAPS) ? "gen_mipmaps=true\n" : "gen_mipmaps=false\n"; - } - if (global_repeat != bool(texture->get_flags() & Texture::FLAG_REPEAT)) { - text += bool(texture->get_flags() & Texture::FLAG_REPEAT) ? "repeat=true\n" : "repeat=false\n"; - } - if (bool(texture->get_flags() & Texture::FLAG_ANISOTROPIC_FILTER)) { - text += "anisotropic=true\n"; - } - if (bool(texture->get_flags() & Texture::FLAG_CONVERT_TO_LINEAR)) { - text += "tolinear=true\n"; - } - if (bool(texture->get_flags() & Texture::FLAG_MIRRORED_REPEAT)) { - text += "mirroredrepeat=true\n"; - } - - if (text != "" || FileAccess::exists(p_path + ".flags")) { - - FileAccess *f = FileAccess::open(p_path + ".flags", FileAccess::WRITE); - if (f) { - - f->store_string(text); - memdelete(f); - } - } } return err; diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 30e6d4ba93..8fa9cbdc1c 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -823,56 +823,54 @@ void EditorNode::_save_scene_with_preview(String p_file) { } save.step(TTR("Creating Thumbnail"), 1); //current view? - int screen = -1; - for (int i = 0; i < editor_table.size(); i++) { - if (editor_plugin_screen == editor_table[i]) { - screen = i; - break; - } + + Ref<Image> img; + if (is2d) { + img = scene_root->get_texture()->get_data(); + } else { + img = SpatialEditor::get_singleton()->get_editor_viewport(0)->get_viewport_node()->get_texture()->get_data(); } - _editor_select(is2d ? EDITOR_2D : EDITOR_3D); + if (img.is_valid()) { + save.step(TTR("Creating Thumbnail"), 2); + save.step(TTR("Creating Thumbnail"), 3); - save.step(TTR("Creating Thumbnail"), 2); - save.step(TTR("Creating Thumbnail"), 3); -#if 0 - Image img = VS::get_singleton()->viewport_texture(scree_capture(viewport); - int preview_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); - preview_size*=EDSCALE; - int width,height; - if (img.get_width() > preview_size && img.get_width() >= img.get_height()) { + int preview_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); + preview_size *= EDSCALE; + int width, height; + if (img->get_width() > preview_size && img->get_width() >= img->get_height()) { - width=preview_size; - height = img.get_height() * preview_size / img.get_width(); - } else if (img.get_height() > preview_size && img.get_height() >= img.get_width()) { + width = preview_size; + height = img->get_height() * preview_size / img->get_width(); + } else if (img->get_height() > preview_size && img->get_height() >= img->get_width()) { - height=preview_size; - width = img.get_width() * preview_size / img.get_height(); - } else { + height = preview_size; + width = img->get_width() * preview_size / img->get_height(); + } else { - width=img.get_width(); - height=img.get_height(); - } + width = img->get_width(); + height = img->get_height(); + } - img.convert(Image::FORMAT_RGB8); - img.resize(width,height); + img->convert(Image::FORMAT_RGB8); + img->resize(width, height); + img->flip_y(); - String pfile = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp/last_scene_preview.png"); - img.save_png(pfile); - Vector<uint8_t> imgdata = FileAccess::get_file_as_array(pfile); + //save thumbnail directly, as thumbnailer may not update due to actual scene not changing md5 + String temp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp"); + String cache_base = GlobalConfig::get_singleton()->globalize_path(p_file).md5_text(); + cache_base = temp_path.plus_file("resthumb-" + cache_base); - //print_line("img data is "+itos(imgdata.size())); + //does not have it, try to load a cached thumbnail - if (editor_data.get_edited_scene_import_metadata().is_null()) - editor_data.set_edited_scene_import_metadata(Ref<ResourceImportMetadata>( memnew( ResourceImportMetadata ) ) ); - editor_data.get_edited_scene_import_metadata()->set_option("thumbnail",imgdata); -#endif - //tamanio tel thumbnail - if (screen != -1) { - _editor_select(screen); + String file = cache_base + ".png"; + + img->save_png(file); } + save.step(TTR("Saving Scene"), 4); _save_scene(p_file); + EditorResourcePreview::get_singleton()->check_for_invalidation(p_file); } void EditorNode::_save_scene(String p_file, int idx) { @@ -4880,6 +4878,7 @@ EditorNode::EditorNode() { Resource::_get_local_scene_func = _resource_get_edited_scene; VisualServer::get_singleton()->textures_keep_original(true); + VisualServer::get_singleton()->set_debug_generate_wireframes(true); EditorHelp::generate_doc(); //before any editor classes are crated SceneState::set_disable_placeholders(true); @@ -6057,14 +6056,13 @@ EditorNode::EditorNode() { plugin_init_callbacks[i](); } - /*resource_preview->add_preview_generator( Ref<EditorTexturePreviewPlugin>( memnew(EditorTexturePreviewPlugin ))); - resource_preview->add_preview_generator( Ref<EditorPackedScenePreviewPlugin>( memnew(EditorPackedScenePreviewPlugin ))); - resource_preview->add_preview_generator( Ref<EditorMaterialPreviewPlugin>( memnew(EditorMaterialPreviewPlugin ))); - resource_preview->add_preview_generator( Ref<EditorScriptPreviewPlugin>( memnew(EditorScriptPreviewPlugin ))); - resource_preview->add_preview_generator( Ref<EditorSamplePreviewPlugin>( memnew(EditorSamplePreviewPlugin ))); - resource_preview->add_preview_generator( Ref<EditorMeshPreviewPlugin>( memnew(EditorMeshPreviewPlugin ))); - resource_preview->add_preview_generator( Ref<EditorBitmapPreviewPlugin>( memnew(EditorBitmapPreviewPlugin ))); -*/ + resource_preview->add_preview_generator(Ref<EditorTexturePreviewPlugin>(memnew(EditorTexturePreviewPlugin))); + resource_preview->add_preview_generator(Ref<EditorPackedScenePreviewPlugin>(memnew(EditorPackedScenePreviewPlugin))); + resource_preview->add_preview_generator(Ref<EditorMaterialPreviewPlugin>(memnew(EditorMaterialPreviewPlugin))); + resource_preview->add_preview_generator(Ref<EditorScriptPreviewPlugin>(memnew(EditorScriptPreviewPlugin))); + //resource_preview->add_preview_generator( Ref<EditorSamplePreviewPlugin>( memnew(EditorSamplePreviewPlugin ))); + resource_preview->add_preview_generator(Ref<EditorMeshPreviewPlugin>(memnew(EditorMeshPreviewPlugin))); + resource_preview->add_preview_generator(Ref<EditorBitmapPreviewPlugin>(memnew(EditorBitmapPreviewPlugin))); circle_step_msec = OS::get_singleton()->get_ticks_msec(); circle_step_frame = Engine::get_singleton()->get_frames_drawn(); diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index 1b8d1b1677..6fcea98e32 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -281,6 +281,11 @@ void EditorPlugin::add_import_plugin(const Ref<EditorImportPlugin> &p_importer) EditorFileSystem::get_singleton()->scan_changes(); } +void EditorPlugin::remove_import_plugin(const Ref<EditorImportPlugin> &p_importer) { + ResourceFormatImporter::get_singleton()->remove_importer(p_importer); + EditorFileSystem::get_singleton()->scan_changes(); +} + void EditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) { if (get_script_instance() && get_script_instance()->has_method("set_window_layout")) { @@ -366,6 +371,7 @@ void EditorPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("queue_save_layout"), &EditorPlugin::queue_save_layout); ClassDB::bind_method(D_METHOD("edit_resource"), &EditorPlugin::edit_resource); ClassDB::bind_method(D_METHOD("add_import_plugin"), &EditorPlugin::add_import_plugin); + ClassDB::bind_method(D_METHOD("remove_import_plugin"), &EditorPlugin::remove_import_plugin); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "forward_canvas_gui_input", PropertyInfo(Variant::TRANSFORM2D, "canvas_xform"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); ClassDB::add_virtual_method(get_class_static(), MethodInfo("forward_draw_over_canvas", PropertyInfo(Variant::TRANSFORM2D, "canvas_xform"), PropertyInfo(Variant::OBJECT, "canvas:Control"))); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "forward_spatial_gui_input", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h index 1ef447a6b8..c607846ec9 100644 --- a/editor/editor_plugin.h +++ b/editor/editor_plugin.h @@ -148,6 +148,7 @@ public: virtual void save_global_state(); void add_import_plugin(const Ref<EditorImportPlugin> &p_importer); + void remove_import_plugin(const Ref<EditorImportPlugin> &p_importer); EditorPlugin(); virtual ~EditorPlugin(); diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index 0b1887e8a2..5d68de3bb6 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -190,7 +190,7 @@ void EditorResourcePreview::_thread() { } else { preview_mutex->unlock(); - Ref<Texture> texture; + Ref<ImageTexture> texture; //print_line("pop from queue "+item.path); @@ -229,6 +229,7 @@ void EditorResourcePreview::_thread() { bool cache_valid = true; if (tsize != thumbnail_size) { + cache_valid = false; memdelete(f); } else if (last_modtime != modtime) { @@ -240,6 +241,7 @@ void EditorResourcePreview::_thread() { if (last_md5 != md5) { cache_valid = false; + } else { //update modified time @@ -252,14 +254,20 @@ void EditorResourcePreview::_thread() { memdelete(f); } - cache_valid = false; + //cache_valid = false; if (cache_valid) { - texture = ResourceLoader::load(cache_base + ".png", "ImageTexture", true); - if (!texture.is_valid()) { + Ref<Image> img; + img.instance(); + + if (img->load(cache_base + ".png") != OK) { //well fuck cache_valid = false; + } else { + + texture.instance(); + texture->create_from_image(img, Texture::FLAG_FILTER); } } diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 3dab1707a1..ec7e7597d5 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -614,6 +614,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { set("editors/2d/bone_ik_color", Color(0.9, 0.9, 0.45, 0.9)); set("editors/2d/keep_margins_when_changing_anchors", false); set("editors/2d/warped_mouse_panning", true); + set("editors/2d/scroll_to_pan", false); + set("editors/2d/pan_speed", 20); set("editors/poly_editor/point_grab_radius", 8); diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 8d0f3267f7..342808f9e1 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -54,7 +54,7 @@ String ResourceImporterOBJ::get_save_extension() const { String ResourceImporterOBJ::get_resource_type() const { - return "Mesh"; + return "ArrayMesh"; } bool ResourceImporterOBJ::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { diff --git a/editor/pane_drag.h b/editor/pane_drag.h index 7bd9feb63b..0be017b8f7 100644 --- a/editor/pane_drag.h +++ b/editor/pane_drag.h @@ -34,7 +34,7 @@ class PaneDrag : public Control { - GDCLASS(PaneDrag, Control); + GDCLASS(PaneDrag, Control) bool mouse_over; diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index e6c08a9009..803e59469c 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -1010,8 +1010,7 @@ void CanvasItemEditor::_list_select(const Ref<InputEventMouseButton> &b) { selection_menu->add_item(item->get_name()); selection_menu->set_item_icon(i, icon); selection_menu->set_item_metadata(i, node_path); - selection_menu->set_item_tooltip(i, String(item->get_name()) + - "\nType: " + item->get_class() + "\nPath: " + node_path); + selection_menu->set_item_tooltip(i, String(item->get_name()) + "\nType: " + item->get_class() + "\nPath: " + node_path); } additive_selection = b->get_shift(); @@ -1047,17 +1046,25 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { if (b->get_button_index() == BUTTON_WHEEL_DOWN) { - if (zoom < MIN_ZOOM) - return; + if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) { + + v_scroll->set_value(v_scroll->get_value() + int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor()); + + } else { + + if (zoom < MIN_ZOOM) + return; - float prev_zoom = zoom; - zoom = zoom * (1 - (0.05 * b->get_factor())); - { - Point2 ofs = b->get_position(); - ofs = ofs / prev_zoom - ofs / zoom; - h_scroll->set_value(h_scroll->get_value() + ofs.x); - v_scroll->set_value(v_scroll->get_value() + ofs.y); + float prev_zoom = zoom; + zoom = zoom * (1 - (0.05 * b->get_factor())); + { + Point2 ofs = b->get_position(); + ofs = ofs / prev_zoom - ofs / zoom; + h_scroll->set_value(h_scroll->get_value() + ofs.x); + v_scroll->set_value(v_scroll->get_value() + ofs.y); + } } + _update_scroll(0); viewport->update(); return; @@ -1065,16 +1072,21 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { if (b->get_button_index() == BUTTON_WHEEL_UP) { - if (zoom > MAX_ZOOM) - return; + if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) { + + v_scroll->set_value(v_scroll->get_value() - int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor()); - float prev_zoom = zoom; - zoom = zoom * ((0.95 + (0.05 * b->get_factor())) / 0.95); - { - Point2 ofs = b->get_position(); - ofs = ofs / prev_zoom - ofs / zoom; - h_scroll->set_value(h_scroll->get_value() + ofs.x); - v_scroll->set_value(v_scroll->get_value() + ofs.y); + } else { + if (zoom > MAX_ZOOM) return; + + float prev_zoom = zoom; + zoom = zoom * ((0.95 + (0.05 * b->get_factor())) / 0.95); + { + Point2 ofs = b->get_position(); + ofs = ofs / prev_zoom - ofs / zoom; + h_scroll->set_value(h_scroll->get_value() + ofs.x); + v_scroll->set_value(v_scroll->get_value() + ofs.y); + } } _update_scroll(0); @@ -1082,6 +1094,22 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { return; } + if (b->get_button_index() == BUTTON_WHEEL_LEFT) { + + if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) { + + h_scroll->set_value(h_scroll->get_value() - int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor()); + } + } + + if (b->get_button_index() == BUTTON_WHEEL_RIGHT) { + + if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) { + + h_scroll->set_value(h_scroll->get_value() + int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor()); + } + } + if (b->get_button_index() == BUTTON_RIGHT) { if (b->is_pressed() && (tool == TOOL_SELECT && b->get_alt())) { diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index db8060d591..7f8b98e1d3 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -39,239 +39,226 @@ #include "scene/resources/bit_mask.h" #include "scene/resources/mesh.h" -#if 0 -bool EditorTexturePreviewPlugin::handles(const String& p_type) const { +bool EditorTexturePreviewPlugin::handles(const String &p_type) const { - return (ClassDB::is_type(p_type,"ImageTexture") || ClassDB::is_type(p_type, "AtlasTexture")); + return ClassDB::is_parent_class(p_type, "Texture"); } -Ref<Texture> EditorTexturePreviewPlugin::generate(const RES& p_from) { +Ref<Texture> EditorTexturePreviewPlugin::generate(const RES &p_from) { - Image img; + Ref<Image> img; Ref<AtlasTexture> atex = p_from; if (atex.is_valid()) { - Ref<ImageTexture> tex = atex->get_atlas(); + Ref<Texture> tex = atex->get_atlas(); if (!tex.is_valid()) { return Ref<Texture>(); } - Image atlas = tex->get_data(); - img = atlas.get_rect(atex->get_region()); - } - else { - Ref<ImageTexture> tex = p_from; + Ref<Image> atlas = tex->get_data(); + img = atlas->get_rect(atex->get_region()); + } else { + Ref<Texture> tex = p_from; img = tex->get_data(); } - if (img.empty()) + if (img.is_null() || img->empty()) return Ref<Texture>(); - img.clear_mipmaps(); + img->clear_mipmaps(); int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); - thumbnail_size*=EDSCALE; - if (img.is_compressed()) { - if (img.decompress()!=OK) + thumbnail_size *= EDSCALE; + if (img->is_compressed()) { + if (img->decompress() != OK) return Ref<Texture>(); - } else if (img.get_format()!=Image::FORMAT_RGB8 && img.get_format()!=Image::FORMAT_RGBA8) { - img.convert(Image::FORMAT_RGBA8); + } else if (img->get_format() != Image::FORMAT_RGB8 && img->get_format() != Image::FORMAT_RGBA8) { + img->convert(Image::FORMAT_RGBA8); } - int width,height; - if (img.get_width() > thumbnail_size && img.get_width() >= img.get_height()) { + int width, height; + if (img->get_width() > thumbnail_size && img->get_width() >= img->get_height()) { - width=thumbnail_size; - height = img.get_height() * thumbnail_size / img.get_width(); - } else if (img.get_height() > thumbnail_size && img.get_height() >= img.get_width()) { + width = thumbnail_size; + height = img->get_height() * thumbnail_size / img->get_width(); + } else if (img->get_height() > thumbnail_size && img->get_height() >= img->get_width()) { - height=thumbnail_size; - width = img.get_width() * thumbnail_size / img.get_height(); - } else { + height = thumbnail_size; + width = img->get_width() * thumbnail_size / img->get_height(); + } else { - width=img.get_width(); - height=img.get_height(); + width = img->get_width(); + height = img->get_height(); } - img.resize(width,height); + img->resize(width, height); - Ref<ImageTexture> ptex = Ref<ImageTexture>( memnew( ImageTexture )); + Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); - ptex->create_from_image(img,0); + ptex->create_from_image(img, 0); return ptex; - } EditorTexturePreviewPlugin::EditorTexturePreviewPlugin() { - - } //////////////////////////////////////////////////////////////////////////// -bool EditorBitmapPreviewPlugin::handles(const String& p_type) const { +bool EditorBitmapPreviewPlugin::handles(const String &p_type) const { - return ClassDB::is_type(p_type,"BitMap"); + return ClassDB::is_parent_class(p_type, "BitMap"); } -Ref<Texture> EditorBitmapPreviewPlugin::generate(const RES& p_from) { +Ref<Texture> EditorBitmapPreviewPlugin::generate(const RES &p_from) { - Ref<BitMap> bm =p_from; + Ref<BitMap> bm = p_from; - if (bm->get_size()==Size2()) { + if (bm->get_size() == Size2()) { return Ref<Texture>(); } PoolVector<uint8_t> data; - data.resize(bm->get_size().width*bm->get_size().height); + data.resize(bm->get_size().width * bm->get_size().height); { - PoolVector<uint8_t>::Write w=data.write(); + PoolVector<uint8_t>::Write w = data.write(); - for(int i=0;i<bm->get_size().width;i++) { - for(int j=0;j<bm->get_size().height;j++) { - if (bm->get_bit(Point2i(i,j))) { - w[j*bm->get_size().width+i]=255; + for (int i = 0; i < bm->get_size().width; i++) { + for (int j = 0; j < bm->get_size().height; j++) { + if (bm->get_bit(Point2i(i, j))) { + w[j * bm->get_size().width + i] = 255; } else { - w[j*bm->get_size().width+i]=0; - + w[j * bm->get_size().width + i] = 0; } } - } } - - Image img(bm->get_size().width,bm->get_size().height,0,Image::FORMAT_L8,data); + Ref<Image> img; + img.instance(); + img->create(bm->get_size().width, bm->get_size().height, 0, Image::FORMAT_L8, data); int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); - thumbnail_size*=EDSCALE; - if (img.is_compressed()) { - if (img.decompress()!=OK) + thumbnail_size *= EDSCALE; + if (img->is_compressed()) { + if (img->decompress() != OK) return Ref<Texture>(); - } else if (img.get_format()!=Image::FORMAT_RGB8 && img.get_format()!=Image::FORMAT_RGBA8) { - img.convert(Image::FORMAT_RGBA8); + } else if (img->get_format() != Image::FORMAT_RGB8 && img->get_format() != Image::FORMAT_RGBA8) { + img->convert(Image::FORMAT_RGBA8); } - int width,height; - if (img.get_width() > thumbnail_size && img.get_width() >= img.get_height()) { + int width, height; + if (img->get_width() > thumbnail_size && img->get_width() >= img->get_height()) { - width=thumbnail_size; - height = img.get_height() * thumbnail_size / img.get_width(); - } else if (img.get_height() > thumbnail_size && img.get_height() >= img.get_width()) { + width = thumbnail_size; + height = img->get_height() * thumbnail_size / img->get_width(); + } else if (img->get_height() > thumbnail_size && img->get_height() >= img->get_width()) { - height=thumbnail_size; - width = img.get_width() * thumbnail_size / img.get_height(); - } else { + height = thumbnail_size; + width = img->get_width() * thumbnail_size / img->get_height(); + } else { - width=img.get_width(); - height=img.get_height(); + width = img->get_width(); + height = img->get_height(); } - img.resize(width,height); + img->resize(width, height); - Ref<ImageTexture> ptex = Ref<ImageTexture>( memnew( ImageTexture )); + Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); - ptex->create_from_image(img,0); + ptex->create_from_image(img, 0); return ptex; - } EditorBitmapPreviewPlugin::EditorBitmapPreviewPlugin() { - - } /////////////////////////////////////////////////////////////////////////// +bool EditorPackedScenePreviewPlugin::handles(const String &p_type) const { -Ref<Texture> EditorPackedScenePreviewPlugin::_gen_from_imd(Ref<ResourceImportMetadata> p_imd) { - - if (p_imd.is_null()) { - return Ref<Texture>(); - } + return ClassDB::is_parent_class(p_type, "PackedScene"); +} +Ref<Texture> EditorPackedScenePreviewPlugin::generate(const RES &p_from) { - if (!p_imd->has_option("thumbnail")) - return Ref<Texture>(); + return generate_from_path(p_from->get_path()); +} - Variant tn = p_imd->get_option("thumbnail"); - //print_line(Variant::get_type_name(tn.get_type())); - PoolVector<uint8_t> thumbnail = tn; +Ref<Texture> EditorPackedScenePreviewPlugin::generate_from_path(const String &p_path) { - int len = thumbnail.size(); - if (len==0) - return Ref<Texture>(); + String temp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp"); + String cache_base = GlobalConfig::get_singleton()->globalize_path(p_path).md5_text(); + cache_base = temp_path.plus_file("resthumb-" + cache_base); + //does not have it, try to load a cached thumbnail - PoolVector<uint8_t>::Read r = thumbnail.read(); + String path = cache_base + ".png"; - Image img(r.ptr(),len); - if (img.empty()) + if (!FileAccess::exists(path)) return Ref<Texture>(); - Ref<ImageTexture> ptex = Ref<ImageTexture>( memnew( ImageTexture )); - ptex->create_from_image(img,0); - return ptex; + Ref<Image> img; + img.instance(); + Error err = img->load(path); + if (err == OK) { -} + Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); -bool EditorPackedScenePreviewPlugin::handles(const String& p_type) const { + ptex->create_from_image(img, 0); + return ptex; - return ClassDB::is_type(p_type,"PackedScene"); + } else { + return Ref<Texture>(); + } } -Ref<Texture> EditorPackedScenePreviewPlugin::generate(const RES& p_from) { - Ref<ResourceImportMetadata> imd = p_from->get_import_metadata(); - return _gen_from_imd(imd); +EditorPackedScenePreviewPlugin::EditorPackedScenePreviewPlugin() { } -Ref<Texture> EditorPackedScenePreviewPlugin::generate_from_path(const String& p_path) { +////////////////////////////////////////////////////////////////// + +void EditorMaterialPreviewPlugin::_preview_done(const Variant &p_udata) { - Ref<ResourceImportMetadata> imd = ResourceLoader::load_import_metadata(p_path); - return _gen_from_imd(imd); + preview_done = true; } -EditorPackedScenePreviewPlugin::EditorPackedScenePreviewPlugin() { +void EditorMaterialPreviewPlugin::_bind_methods() { + ClassDB::bind_method("_preview_done", &EditorMaterialPreviewPlugin::_preview_done); } -////////////////////////////////////////////////////////////////// +bool EditorMaterialPreviewPlugin::handles(const String &p_type) const { -bool EditorMaterialPreviewPlugin::handles(const String& p_type) const { - - return ClassDB::is_type(p_type,"Material"); //any material + return ClassDB::is_parent_class(p_type, "Material"); //any material } -Ref<Texture> EditorMaterialPreviewPlugin::generate(const RES& p_from) { +Ref<Texture> EditorMaterialPreviewPlugin::generate(const RES &p_from) { Ref<Material> material = p_from; - ERR_FAIL_COND_V(material.is_null(),Ref<Texture>()); + ERR_FAIL_COND_V(material.is_null(), Ref<Texture>()); - VS::get_singleton()->mesh_surface_set_material(sphere,0,material->get_rid()); + VS::get_singleton()->mesh_surface_set_material(sphere, 0, material->get_rid()); - VS::get_singleton()->viewport_queue_screen_capture(viewport); - VS::get_singleton()->viewport_set_render_target_update_mode(viewport,VS::RENDER_TARGET_UPDATE_ONCE); //once used for capture + VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture //print_line("queue capture!"); - Image img; - int timeout=1000; - while(timeout) { - //print_line("try capture?"); + preview_done = false; + VS::get_singleton()->request_frame_drawn_callback(this, "_preview_done", Variant()); + + while (!preview_done) { OS::get_singleton()->delay_usec(10); - img = VS::get_singleton()->viewport_get_screen_capture(viewport); - if (!img.empty()) - break; - timeout--; } - //print_line("captured!"); - VS::get_singleton()->mesh_surface_set_material(sphere,0,RID()); + Ref<Image> img = VS::get_singleton()->VS::get_singleton()->texture_get_data(viewport_texture); + VS::get_singleton()->mesh_surface_set_material(sphere, 0, RID()); - int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); - thumbnail_size*=EDSCALE; - img.resize(thumbnail_size,thumbnail_size); + ERR_FAIL_COND_V(!img.is_valid(), Ref<ImageTexture>()); - Ref<ImageTexture> ptex = Ref<ImageTexture>( memnew( ImageTexture )); - ptex->create_from_image(img,0); + int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); + thumbnail_size *= EDSCALE; + img->convert(Image::FORMAT_RGBA8); + img->resize(thumbnail_size, thumbnail_size); + Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); + ptex->create_from_image(img, 0); return ptex; } @@ -280,70 +267,68 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() { scenario = VS::get_singleton()->scenario_create(); viewport = VS::get_singleton()->viewport_create(); - VS::get_singleton()->viewport_set_as_render_target(viewport,true); - VS::get_singleton()->viewport_set_render_target_update_mode(viewport,VS::RENDER_TARGET_UPDATE_DISABLED); - VS::get_singleton()->viewport_set_scenario(viewport,scenario); - VS::ViewportRect vr; - vr.x=0; - vr.y=0; - vr.width=128; - vr.height=128; - VS::get_singleton()->viewport_set_rect(viewport,vr); + VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_DISABLED); + VS::get_singleton()->viewport_set_scenario(viewport, scenario); + VS::get_singleton()->viewport_set_size(viewport, 128, 128); + VS::get_singleton()->viewport_set_transparent_background(viewport, true); + VS::get_singleton()->viewport_set_active(viewport, true); + VS::get_singleton()->viewport_set_vflip(viewport, true); + viewport_texture = VS::get_singleton()->viewport_get_texture(viewport); camera = VS::get_singleton()->camera_create(); - VS::get_singleton()->viewport_attach_camera(viewport,camera); - VS::get_singleton()->camera_set_transform(camera,Transform(Matrix3(),Vector3(0,0,3))); - VS::get_singleton()->camera_set_perspective(camera,45,0.1,10); + VS::get_singleton()->viewport_attach_camera(viewport, camera); + VS::get_singleton()->camera_set_transform(camera, Transform(Basis(), Vector3(0, 0, 3))); + VS::get_singleton()->camera_set_perspective(camera, 45, 0.1, 10); light = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); - light_instance = VS::get_singleton()->instance_create2(light,scenario); - VS::get_singleton()->instance_set_transform(light_instance,Transform().looking_at(Vector3(-1,-1,-1),Vector3(0,1,0))); + light_instance = VS::get_singleton()->instance_create2(light, scenario); + VS::get_singleton()->instance_set_transform(light_instance, Transform().looking_at(Vector3(-1, -1, -1), Vector3(0, 1, 0))); light2 = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); - VS::get_singleton()->light_set_color(light2,VS::LIGHT_COLOR_DIFFUSE,Color(0.7,0.7,0.7)); - VS::get_singleton()->light_set_color(light2,VS::LIGHT_COLOR_SPECULAR,Color(0.0,0.0,0.0)); - light_instance2 = VS::get_singleton()->instance_create2(light2,scenario); + VS::get_singleton()->light_set_color(light2, Color(0.7, 0.7, 0.7)); + //VS::get_singleton()->light_set_color(light2, Color(0.7, 0.7, 0.7)); + + light_instance2 = VS::get_singleton()->instance_create2(light2, scenario); - VS::get_singleton()->instance_set_transform(light_instance2,Transform().looking_at(Vector3(0,1,0),Vector3(0,0,1))); + VS::get_singleton()->instance_set_transform(light_instance2, Transform().looking_at(Vector3(0, 1, 0), Vector3(0, 0, 1))); sphere = VS::get_singleton()->mesh_create(); - sphere_instance = VS::get_singleton()->instance_create2(sphere,scenario); + sphere_instance = VS::get_singleton()->instance_create2(sphere, scenario); - int lats=32; - int lons=32; - float radius=1.0; + int lats = 32; + int lons = 32; + float radius = 1.0; PoolVector<Vector3> vertices; PoolVector<Vector3> normals; PoolVector<Vector2> uvs; PoolVector<float> tangents; - Matrix3 tt = Matrix3(Vector3(0,1,0),Math_PI*0.5); + Basis tt = Basis(Vector3(0, 1, 0), Math_PI * 0.5); - for(int i = 1; i <= lats; i++) { - double lat0 = Math_PI * (-0.5 + (double) (i - 1) / lats); - double z0 = Math::sin(lat0); - double zr0 = Math::cos(lat0); + for (int i = 1; i <= lats; i++) { + double lat0 = Math_PI * (-0.5 + (double)(i - 1) / lats); + double z0 = Math::sin(lat0); + double zr0 = Math::cos(lat0); - double lat1 = Math_PI * (-0.5 + (double) i / lats); + double lat1 = Math_PI * (-0.5 + (double)i / lats); double z1 = Math::sin(lat1); double zr1 = Math::cos(lat1); - for(int j = lons; j >= 1; j--) { + for (int j = lons; j >= 1; j--) { - double lng0 = 2 * Math_PI * (double) (j - 1) / lons; + double lng0 = 2 * Math_PI * (double)(j - 1) / lons; double x0 = Math::cos(lng0); double y0 = Math::sin(lng0); - double lng1 = 2 * Math_PI * (double) (j) / lons; + double lng1 = 2 * Math_PI * (double)(j) / lons; double x1 = Math::cos(lng1); double y1 = Math::sin(lng1); - - Vector3 v[4]={ - Vector3(x1 * zr0, z0, y1 *zr0), - Vector3(x1 * zr1, z1, y1 *zr1), - Vector3(x0 * zr1, z1, y0 *zr1), - Vector3(x0 * zr0, z0, y0 *zr0) + Vector3 v[4] = { + Vector3(x1 * zr0, z0, y1 * zr0), + Vector3(x1 * zr1, z1, y1 * zr1), + Vector3(x0 * zr1, z1, y0 * zr1), + Vector3(x0 * zr0, z0, y0 * zr0) }; #define ADD_POINT(m_idx) \ @@ -364,8 +349,6 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() { tangents.push_back(1.0); \ } - - ADD_POINT(0); ADD_POINT(1); ADD_POINT(2); @@ -378,12 +361,11 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() { Array arr; arr.resize(VS::ARRAY_MAX); - arr[VS::ARRAY_VERTEX]=vertices; - arr[VS::ARRAY_NORMAL]=normals; - arr[VS::ARRAY_TANGENT]=tangents; - arr[VS::ARRAY_TEX_UV]=uvs; - VS::get_singleton()->mesh_add_surface(sphere,VS::PRIMITIVE_TRIANGLES,arr); - + arr[VS::ARRAY_VERTEX] = vertices; + arr[VS::ARRAY_NORMAL] = normals; + arr[VS::ARRAY_TANGENT] = tangents; + arr[VS::ARRAY_TEX_UV] = uvs; + VS::get_singleton()->mesh_add_surface_from_arrays(sphere, VS::PRIMITIVE_TRIANGLES, arr); } EditorMaterialPreviewPlugin::~EditorMaterialPreviewPlugin() { @@ -397,30 +379,28 @@ EditorMaterialPreviewPlugin::~EditorMaterialPreviewPlugin() { VS::get_singleton()->free(light_instance2); VS::get_singleton()->free(camera); VS::get_singleton()->free(scenario); - } /////////////////////////////////////////////////////////////////////////// static bool _is_text_char(CharType c) { - return (c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='_'; + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'; } -bool EditorScriptPreviewPlugin::handles(const String& p_type) const { +bool EditorScriptPreviewPlugin::handles(const String &p_type) const { - return ClassDB::is_type(p_type,"Script"); + return ClassDB::is_parent_class(p_type, "Script"); } -Ref<Texture> EditorScriptPreviewPlugin::generate(const RES& p_from) { - +Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from) { Ref<Script> scr = p_from; if (scr.is_null()) return Ref<Texture>(); String code = scr->get_source_code().strip_edges(); - if (code=="") + if (code == "") return Ref<Texture>(); List<String> kwors; @@ -428,107 +408,103 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES& p_from) { Set<String> keywords; - for(List<String>::Element *E=kwors.front();E;E=E->next()) { + for (List<String>::Element *E = kwors.front(); E; E = E->next()) { keywords.insert(E->get()); - } - int line = 0; - int col=0; + int col = 0; int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); - thumbnail_size*=EDSCALE; - Image img(thumbnail_size,thumbnail_size,0,Image::FORMAT_RGBA8); - - + thumbnail_size *= EDSCALE; + Ref<Image> img; + img.instance(); + img->create(thumbnail_size, thumbnail_size, 0, Image::FORMAT_RGBA8); Color bg_color = EditorSettings::get_singleton()->get("text_editor/highlighting/background_color"); - bg_color.a=1.0; + bg_color.a = 1.0; Color keyword_color = EditorSettings::get_singleton()->get("text_editor/highlighting/keyword_color"); Color text_color = EditorSettings::get_singleton()->get("text_editor/highlighting/text_color"); Color symbol_color = EditorSettings::get_singleton()->get("text_editor/highlighting/symbol_color"); - - for(int i=0;i<thumbnail_size;i++) { - for(int j=0;j<thumbnail_size;j++) { - img.put_pixel(i,j,bg_color); + for (int i = 0; i < thumbnail_size; i++) { + for (int j = 0; j < thumbnail_size; j++) { + img->put_pixel(i, j, bg_color); } - } - bool prev_is_text=false; - bool in_keyword=false; - for(int i=0;i<code.length();i++) { + img->lock(); + bool prev_is_text = false; + bool in_keyword = false; + for (int i = 0; i < code.length(); i++) { CharType c = code[i]; - if (c>32) { - if (col<thumbnail_size) { + if (c > 32) { + if (col < thumbnail_size) { Color color = text_color; - if (c!='_' && ((c>='!' && c<='/') || (c>=':' && c<='@') || (c>='[' && c<='`') || (c>='{' && c<='~') || c=='\t')) { + if (c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t')) { //make symbol a little visible - color=symbol_color; - in_keyword=false; + color = symbol_color; + in_keyword = false; } else if (!prev_is_text && _is_text_char(c)) { int pos = i; - while(_is_text_char(code[pos])) { + while (_is_text_char(code[pos])) { pos++; } ///print_line("from "+itos(i)+" to "+itos(pos)); - String word = code.substr(i,pos-i); + String word = code.substr(i, pos - i); //print_line("found word: "+word); if (keywords.has(word)) - in_keyword=true; + in_keyword = true; } else if (!_is_text_char(c)) { - in_keyword=false; + in_keyword = false; } if (in_keyword) - color=keyword_color; + color = keyword_color; - Color ul=color; - ul.a*=0.5; - img.put_pixel(col,line*2,bg_color.blend(ul)); - img.put_pixel(col,line*2+1,color); + Color ul = color; + ul.a *= 0.5; + img->put_pixel(col, line * 2, bg_color.blend(ul)); + img->put_pixel(col, line * 2 + 1, color); - prev_is_text=_is_text_char(c); + prev_is_text = _is_text_char(c); } } else { - prev_is_text=false; - in_keyword=false; + prev_is_text = false; + in_keyword = false; - if (c=='\n') { - col=0; + if (c == '\n') { + col = 0; line++; - if (line>=thumbnail_size/2) + if (line >= thumbnail_size / 2) break; - } else if (c=='\t') { - col+=3; + } else if (c == '\t') { + col += 3; } } col++; } - Ref<ImageTexture> ptex = Ref<ImageTexture>( memnew( ImageTexture)); + img->unlock(); - ptex->create_from_image(img,0); - return ptex; + Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); + ptex->create_from_image(img, 0); + return ptex; } EditorScriptPreviewPlugin::EditorScriptPreviewPlugin() { - - } /////////////////////////////////////////////////////////////////// #if 0 bool EditorSamplePreviewPlugin::handles(const String& p_type) const { - return ClassDB::is_type(p_type,"Sample"); + return ClassDB::is_parent_class(p_type,"Sample"); } Ref<Texture> EditorSamplePreviewPlugin::generate(const RES& p_from) { @@ -795,105 +771,108 @@ EditorSamplePreviewPlugin::EditorSamplePreviewPlugin() { #endif /////////////////////////////////////////////////////////////////////////// -bool EditorMeshPreviewPlugin::handles(const String& p_type) const { +void EditorMeshPreviewPlugin::_preview_done(const Variant &p_udata) { - return ClassDB::is_type(p_type,"Mesh"); //any Mesh + preview_done = true; } -Ref<Texture> EditorMeshPreviewPlugin::generate(const RES& p_from) { +void EditorMeshPreviewPlugin::_bind_methods() { + + ClassDB::bind_method("_preview_done", &EditorMeshPreviewPlugin::_preview_done); +} +bool EditorMeshPreviewPlugin::handles(const String &p_type) const { + + return ClassDB::is_parent_class(p_type, "Mesh"); //any Mesh +} +Ref<Texture> EditorMeshPreviewPlugin::generate(const RES &p_from) { + + print_line("**Generating for mesh finally??"); Ref<Mesh> mesh = p_from; - ERR_FAIL_COND_V(mesh.is_null(),Ref<Texture>()); + ERR_FAIL_COND_V(mesh.is_null(), Ref<Texture>()); - VS::get_singleton()->instance_set_base(mesh_instance,mesh->get_rid()); + VS::get_singleton()->instance_set_base(mesh_instance, mesh->get_rid()); - AABB aabb= mesh->get_aabb(); - Vector3 ofs = aabb.pos + aabb.size*0.5; - aabb.pos-=ofs; + Rect3 aabb = mesh->get_aabb(); + print_line("mesh aabb: " + aabb); + Vector3 ofs = aabb.position + aabb.size * 0.5; + aabb.position -= ofs; Transform xform; - xform.basis=Matrix3().rotated(Vector3(0,1,0),-Math_PI*0.125); - xform.basis = Matrix3().rotated(Vector3(1,0,0),Math_PI*0.125)*xform.basis; - AABB rot_aabb = xform.xform(aabb); - float m = MAX(rot_aabb.size.x,rot_aabb.size.y)*0.5; - if (m==0) + xform.basis = Basis().rotated(Vector3(0, 1, 0), -Math_PI * 0.125); + xform.basis = Basis().rotated(Vector3(1, 0, 0), Math_PI * 0.125) * xform.basis; + Rect3 rot_aabb = xform.xform(aabb); + float m = MAX(rot_aabb.size.x, rot_aabb.size.y) * 0.5; + if (m == 0) return Ref<Texture>(); - m=1.0/m; - m*=0.5; + m = 1.0 / m; + m *= 0.5; //print_line("scale: "+rtos(m)); - xform.basis.scale(Vector3(m,m,m)); - xform.origin=-xform.basis.xform(ofs); //-ofs*m; - xform.origin.z-=rot_aabb.size.z*2; - VS::get_singleton()->instance_set_transform(mesh_instance,xform); - + xform.basis.scale(Vector3(m, m, m)); + xform.origin = -xform.basis.xform(ofs); //-ofs*m; + xform.origin.z -= rot_aabb.size.z * 2; + VS::get_singleton()->instance_set_transform(mesh_instance, xform); - - VS::get_singleton()->viewport_queue_screen_capture(viewport); - VS::get_singleton()->viewport_set_render_target_update_mode(viewport,VS::RENDER_TARGET_UPDATE_ONCE); //once used for capture + VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture //print_line("queue capture!"); - Image img; - int timeout=1000; - while(timeout) { - //print_line("try capture?"); + preview_done = false; + VS::get_singleton()->request_frame_drawn_callback(this, "_preview_done", Variant()); + + while (!preview_done) { OS::get_singleton()->delay_usec(10); - img = VS::get_singleton()->viewport_get_screen_capture(viewport); - if (!img.empty()) - break; - timeout--; } - //print_line("captured!"); - VS::get_singleton()->instance_set_base(mesh_instance,RID()); + Ref<Image> img = VS::get_singleton()->VS::get_singleton()->texture_get_data(viewport_texture); + ERR_FAIL_COND_V(img.is_null(), Ref<ImageTexture>()); + + print_line("captured! " + itos(img->get_width()) + "x" + itos(img->get_height())); + VS::get_singleton()->instance_set_base(mesh_instance, RID()); int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); - thumbnail_size*=EDSCALE; - img.resize(thumbnail_size,thumbnail_size); + thumbnail_size *= EDSCALE; + img->convert(Image::FORMAT_RGBA8); + img->resize(thumbnail_size, thumbnail_size); - Ref<ImageTexture> ptex = Ref<ImageTexture>( memnew( ImageTexture )); - ptex->create_from_image(img,0); + Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); + ptex->create_from_image(img, 0); return ptex; } EditorMeshPreviewPlugin::EditorMeshPreviewPlugin() { scenario = VS::get_singleton()->scenario_create(); + viewport = VS::get_singleton()->viewport_create(); - VS::get_singleton()->viewport_set_as_render_target(viewport,true); - VS::get_singleton()->viewport_set_render_target_update_mode(viewport,VS::RENDER_TARGET_UPDATE_DISABLED); - VS::get_singleton()->viewport_set_scenario(viewport,scenario); - VS::ViewportRect vr; - vr.x=0; - vr.y=0; - vr.width=128; - vr.height=128; - VS::get_singleton()->viewport_set_rect(viewport,vr); + VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_DISABLED); + VS::get_singleton()->viewport_set_vflip(viewport, true); + VS::get_singleton()->viewport_set_scenario(viewport, scenario); + VS::get_singleton()->viewport_set_size(viewport, 128, 128); + VS::get_singleton()->viewport_set_transparent_background(viewport, true); + VS::get_singleton()->viewport_set_active(viewport, true); + viewport_texture = VS::get_singleton()->viewport_get_texture(viewport); camera = VS::get_singleton()->camera_create(); - VS::get_singleton()->viewport_attach_camera(viewport,camera); - VS::get_singleton()->camera_set_transform(camera,Transform(Matrix3(),Vector3(0,0,3))); + VS::get_singleton()->viewport_attach_camera(viewport, camera); + VS::get_singleton()->camera_set_transform(camera, Transform(Basis(), Vector3(0, 0, 3))); //VS::get_singleton()->camera_set_perspective(camera,45,0.1,10); - VS::get_singleton()->camera_set_orthogonal(camera,1.0,0.01,1000.0); + VS::get_singleton()->camera_set_orthogonal(camera, 1.0, 0.01, 1000.0); light = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); - light_instance = VS::get_singleton()->instance_create2(light,scenario); - VS::get_singleton()->instance_set_transform(light_instance,Transform().looking_at(Vector3(-1,-1,-1),Vector3(0,1,0))); + light_instance = VS::get_singleton()->instance_create2(light, scenario); + VS::get_singleton()->instance_set_transform(light_instance, Transform().looking_at(Vector3(-1, -1, -1), Vector3(0, 1, 0))); light2 = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); - VS::get_singleton()->light_set_color(light2,VS::LIGHT_COLOR_DIFFUSE,Color(0.7,0.7,0.7)); - VS::get_singleton()->light_set_color(light2,VS::LIGHT_COLOR_SPECULAR,Color(0.0,0.0,0.0)); - light_instance2 = VS::get_singleton()->instance_create2(light2,scenario); + VS::get_singleton()->light_set_color(light2, Color(0.7, 0.7, 0.7)); + //VS::get_singleton()->light_set_color(light2, VS::LIGHT_COLOR_SPECULAR, Color(0.0, 0.0, 0.0)); + light_instance2 = VS::get_singleton()->instance_create2(light2, scenario); - VS::get_singleton()->instance_set_transform(light_instance2,Transform().looking_at(Vector3(0,1,0),Vector3(0,0,1))); + VS::get_singleton()->instance_set_transform(light_instance2, Transform().looking_at(Vector3(0, 1, 0), Vector3(0, 0, 1))); //sphere = VS::get_singleton()->mesh_create(); mesh_instance = VS::get_singleton()->instance_create(); - VS::get_singleton()->instance_set_scenario(mesh_instance,scenario); - - - + VS::get_singleton()->instance_set_scenario(mesh_instance, scenario); } - EditorMeshPreviewPlugin::~EditorMeshPreviewPlugin() { //VS::get_singleton()->free(sphere); @@ -905,6 +884,4 @@ EditorMeshPreviewPlugin::~EditorMeshPreviewPlugin() { VS::get_singleton()->free(light_instance2); VS::get_singleton()->free(camera); VS::get_singleton()->free(scenario); - } -#endif diff --git a/editor/plugins/editor_preview_plugins.h b/editor/plugins/editor_preview_plugins.h index 993e36df02..7e7d36eb1e 100644 --- a/editor/plugins/editor_preview_plugins.h +++ b/editor/plugins/editor_preview_plugins.h @@ -32,55 +32,58 @@ #include "editor/editor_resource_preview.h" -#if 0 class EditorTexturePreviewPlugin : public EditorResourcePreviewGenerator { + GDCLASS(EditorTexturePreviewPlugin, EditorResourcePreviewGenerator) public: - - virtual bool handles(const String& p_type) const; - virtual Ref<Texture> generate(const RES& p_from); + virtual bool handles(const String &p_type) const; + virtual Ref<Texture> generate(const RES &p_from); EditorTexturePreviewPlugin(); }; - class EditorBitmapPreviewPlugin : public EditorResourcePreviewGenerator { + GDCLASS(EditorBitmapPreviewPlugin, EditorResourcePreviewGenerator) public: - - virtual bool handles(const String& p_type) const; - virtual Ref<Texture> generate(const RES& p_from); + virtual bool handles(const String &p_type) const; + virtual Ref<Texture> generate(const RES &p_from); EditorBitmapPreviewPlugin(); }; - - class EditorPackedScenePreviewPlugin : public EditorResourcePreviewGenerator { - Ref<Texture> _gen_from_imd(Ref<ResourceImportMetadata> p_imd); public: - - virtual bool handles(const String& p_type) const; - virtual Ref<Texture> generate(const RES& p_from); - virtual Ref<Texture> generate_from_path(const String& p_path); + virtual bool handles(const String &p_type) const; + virtual Ref<Texture> generate(const RES &p_from); + virtual Ref<Texture> generate_from_path(const String &p_path); EditorPackedScenePreviewPlugin(); }; class EditorMaterialPreviewPlugin : public EditorResourcePreviewGenerator { + GDCLASS(EditorMaterialPreviewPlugin, EditorResourcePreviewGenerator) + RID scenario; RID sphere; RID sphere_instance; RID viewport; + RID viewport_texture; RID light; RID light_instance; RID light2; RID light_instance2; RID camera; -public: + volatile bool preview_done; - virtual bool handles(const String& p_type) const; - virtual Ref<Texture> generate(const RES& p_from); + void _preview_done(const Variant &p_udata); + +protected: + static void _bind_methods(); + +public: + virtual bool handles(const String &p_type) const; + virtual Ref<Texture> generate(const RES &p_from); EditorMaterialPreviewPlugin(); ~EditorMaterialPreviewPlugin(); @@ -88,9 +91,8 @@ public: class EditorScriptPreviewPlugin : public EditorResourcePreviewGenerator { public: - - virtual bool handles(const String& p_type) const; - virtual Ref<Texture> generate(const RES& p_from); + virtual bool handles(const String &p_type) const; + virtual Ref<Texture> generate(const RES &p_from); EditorScriptPreviewPlugin(); }; @@ -108,22 +110,30 @@ public: #endif class EditorMeshPreviewPlugin : public EditorResourcePreviewGenerator { + GDCLASS(EditorMeshPreviewPlugin, EditorResourcePreviewGenerator) + RID scenario; RID mesh_instance; RID viewport; + RID viewport_texture; RID light; RID light_instance; RID light2; RID light_instance2; RID camera; -public: + volatile bool preview_done; - virtual bool handles(const String& p_type) const; - virtual Ref<Texture> generate(const RES& p_from); + void _preview_done(const Variant &p_udata); + +protected: + static void _bind_methods(); + +public: + virtual bool handles(const String &p_type) const; + virtual Ref<Texture> generate(const RES &p_from); EditorMeshPreviewPlugin(); ~EditorMeshPreviewPlugin(); }; -#endif #endif // EDITORPREVIEWPLUGINS_H diff --git a/editor/plugins/particles_editor_plugin.cpp b/editor/plugins/particles_editor_plugin.cpp index dc2da80b06..d918a3e24e 100644 --- a/editor/plugins/particles_editor_plugin.cpp +++ b/editor/plugins/particles_editor_plugin.cpp @@ -254,7 +254,7 @@ void ParticlesEditor::_generate_emission_points() { for (int j = 0; j < 3; j++) { if (i == 0 && j == 0) - aabb.pos = r[i].vertex[j]; + aabb.position = r[i].vertex[j]; else aabb.expand_to(r[i].vertex[j]); } @@ -272,7 +272,7 @@ void ParticlesEditor::_generate_emission_points() { dir[Math::rand() % 3] = 1.0; Vector3 ofs = Vector3(1, 1, 1) - dir; ofs = (Vector3(1, 1, 1) - dir) * Vector3(Math::randf(), Math::randf(), Math::randf()) * aabb.size; - ofs += aabb.pos; + ofs += aabb.position; Vector3 ofsv = ofs + aabb.size * dir; diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 61f6880433..a8d875a769 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -1676,7 +1676,7 @@ void SpatialEditorViewport::_notification(int p_what) { } Transform t = sp->get_global_transform(); - t.translate(se->aabb.pos); + t.translate(se->aabb.position); t.basis.scale(se->aabb.size); exist = true; @@ -1724,6 +1724,33 @@ void SpatialEditorViewport::_notification(int p_what) { bool hdr = GlobalConfig::get_singleton()->get("rendering/quality/hdr"); viewport->set_hdr(hdr); + + bool show_info = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_INFORMATION)); + if (show_info != info->is_visible()) { + if (show_info) + info->show(); + else + info->hide(); + } + + if (show_info) { + + String text; + text += TTR("Objects Drawn") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_OBJECTS_IN_FRAME)) + "\n"; + text += TTR("Material Changes") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_MATERIAL_CHANGES_IN_FRAME)) + "\n"; + text += TTR("Shader Changes") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_SHADER_CHANGES_IN_FRAME)) + "\n"; + text += TTR("Surface Changes") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_SURFACE_CHANGES_IN_FRAME)) + "\n"; + text += TTR("Draw Calls") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_DRAW_CALLS_IN_FRAME)) + "\n"; + text += TTR("Vertices") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_VERTICES_IN_FRAME)); + + if (info_label->get_text() != text || surface->get_size() != prev_size) { + info_label->set_text(text); + Size2 ms = info->get_minimum_size(); + info->set_position(surface->get_size() - ms - Vector2(20, 20) * EDSCALE); + } + } + + prev_size = surface->get_size(); } if (p_what == NOTIFICATION_ENTER_TREE) { @@ -1731,6 +1758,7 @@ void SpatialEditorViewport::_notification(int p_what) { surface->connect("draw", this, "_draw"); surface->connect("gui_input", this, "_sinput"); surface->connect("mouse_entered", this, "_smouseenter"); + info->add_style_override("panel", get_stylebox("panel", "Panel")); preview_camera->set_icon(get_icon("Camera", "EditorIcons")); _init_gizmo_instance(index); } @@ -1997,6 +2025,52 @@ void SpatialEditorViewport::_menu_option(int p_option) { view_menu->get_popup()->set_item_checked(idx, current); } break; + case VIEW_INFORMATION: { + + int idx = view_menu->get_popup()->get_item_index(VIEW_INFORMATION); + bool current = view_menu->get_popup()->is_item_checked(idx); + view_menu->get_popup()->set_item_checked(idx, !current); + + } break; + case VIEW_DISPLAY_NORMAL: { + + viewport->set_debug_draw(Viewport::DEBUG_DRAW_DISABLED); + + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL), true); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS), false); + + } break; + case VIEW_DISPLAY_WIREFRAME: { + + viewport->set_debug_draw(Viewport::DEBUG_DRAW_WIREFRAME); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME), true); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS), false); + + } break; + case VIEW_DISPLAY_OVERDRAW: { + + viewport->set_debug_draw(Viewport::DEBUG_DRAW_OVERDRAW); + VisualServer::get_singleton()->scenario_set_debug(get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_OVERDRAW); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW), true); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS), false); + + } break; + case VIEW_DISPLAY_SHADELESS: { + + viewport->set_debug_draw(Viewport::DEBUG_DRAW_UNSHADED); + VisualServer::get_singleton()->scenario_set_debug(get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_SHADELESS); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS), true); + + } break; } } @@ -2273,6 +2347,7 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed surface = memnew(Control); add_child(surface); surface->set_area_as_parent_rect(); + surface->set_clip_contents(true); camera = memnew(Camera); camera->set_disable_gizmo(true); camera->set_cull_mask(((1 << 20) - 1) | (1 << (GIZMO_BASE_LAYER + p_index)) | (1 << GIZMO_EDIT_LAYER) | (1 << GIZMO_GRID_LAYER)); @@ -2296,12 +2371,18 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed view_menu->get_popup()->add_check_item(TTR("Orthogonal") + " (" + ED_GET_SHORTCUT("spatial_editor/switch_perspective_orthogonal")->get_as_text() + ")", VIEW_ORTHOGONAL); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_PERSPECTIVE), true); view_menu->get_popup()->add_separator(); - view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_environment", TTR("Environment")), VIEW_ENVIRONMENT); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_normal", TTR("Display Normal")), VIEW_DISPLAY_NORMAL); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_wireframe", TTR("Display Wireframe")), VIEW_DISPLAY_WIREFRAME); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_overdraw", TTR("Display Overdraw")), VIEW_DISPLAY_OVERDRAW); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_unshaded", TTR("Display Unshaded")), VIEW_DISPLAY_SHADELESS); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL), true); + view_menu->get_popup()->add_separator(); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_environment", TTR("View Environment")), VIEW_ENVIRONMENT); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_gizmos", TTR("View Gizmos")), VIEW_GIZMOS); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_information", TTR("View Information")), VIEW_INFORMATION); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_ENVIRONMENT), true); view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_audio_listener", TTR("Audio Listener")), VIEW_AUDIO_LISTENER); - view_menu->get_popup()->add_separator(); - view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_gizmos", TTR("Gizmos")), VIEW_GIZMOS); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_GIZMOS), true); view_menu->get_popup()->add_separator(); @@ -2322,6 +2403,13 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed preview = NULL; gizmo_scale = 1.0; + info = memnew(PanelContainer); + info->set_self_modulate(Color(1, 1, 1, 0.4)); + surface->add_child(info); + info_label = memnew(Label); + info->add_child(info_label); + info->hide(); + freelook_active = false; selection_menu = memnew(PopupMenu); @@ -2341,6 +2429,305 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed EditorSettings::get_singleton()->connect("settings_changed", this, "update_transform_gizmo_view"); } +////////////////////////////////////////////////////////////// + +void SpatialEditorViewportContainer::_gui_input(const Ref<InputEvent> &p_event) { + + Ref<InputEventMouseButton> mb = p_event; + + if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { + + Vector2 size = get_size(); + + int h_sep = get_constant("separation", "HSplitContainer"); + int v_sep = get_constant("separation", "VSplitContainer"); + + int mid_w = size.width * ratio_h; + int mid_h = size.height * ratio_v; + + dragging_h = mb->get_position().x > (mid_w - h_sep / 2) && mb->get_position().x < (mid_w + h_sep / 2); + dragging_v = mb->get_position().y > (mid_h - v_sep / 2) && mb->get_position().y < (mid_h + v_sep / 2); + + drag_begin_pos = mb->get_position(); + drag_begin_ratio.x = ratio_h; + drag_begin_ratio.y = ratio_v; + + switch (view) { + case VIEW_USE_1_VIEWPORT: { + + dragging_h = false; + dragging_v = false; + + } break; + case VIEW_USE_2_VIEWPORTS: { + + dragging_h = false; + + } break; + case VIEW_USE_2_VIEWPORTS_ALT: { + + dragging_v = false; + + } break; + case VIEW_USE_3_VIEWPORTS: { + + if (dragging_v) + dragging_h = false; + else + dragging_v = false; + + } break; + case VIEW_USE_3_VIEWPORTS_ALT: { + + if (dragging_h) + dragging_v = false; + else + dragging_h = false; + } break; + case VIEW_USE_4_VIEWPORTS: { + + } break; + } + } + + if (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { + dragging_h = false; + dragging_v = false; + } + + Ref<InputEventMouseMotion> mm = p_event; + + if (mm.is_valid() && (dragging_h || dragging_v)) { + + if (dragging_h) { + float new_ratio = drag_begin_ratio.x + (mm->get_position().x - drag_begin_pos.x) / get_size().width; + new_ratio = CLAMP(new_ratio, 40 / get_size().width, (get_size().width - 40) / get_size().width); + ratio_h = new_ratio; + queue_sort(); + update(); + } + if (dragging_v) { + float new_ratio = drag_begin_ratio.y + (mm->get_position().y - drag_begin_pos.y) / get_size().height; + new_ratio = CLAMP(new_ratio, 40 / get_size().height, (get_size().height - 40) / get_size().height); + ratio_v = new_ratio; + queue_sort(); + update(); + } + } +} + +void SpatialEditorViewportContainer::_notification(int p_what) { + + if (p_what == NOTIFICATION_MOUSE_ENTER || p_what == NOTIFICATION_MOUSE_EXIT) { + + mouseover = (p_what == NOTIFICATION_MOUSE_ENTER); + update(); + } + + if (p_what == NOTIFICATION_DRAW && mouseover) { + + Ref<Texture> h_grabber = get_icon("grabber", "HSplitContainer"); + + Ref<Texture> v_grabber = get_icon("grabber", "VSplitContainer"); + + Vector2 size = get_size(); + + int h_sep = get_constant("separation", "HSplitContainer"); + + int v_sep = get_constant("separation", "VSplitContainer"); + + int mid_w = size.width * ratio_h; + int mid_h = size.height * ratio_v; + + int size_left = mid_w - h_sep / 2; + int size_bottom = size.height - mid_h - v_sep / 2; + + switch (view) { + + case VIEW_USE_1_VIEWPORT: { + + //nothing to show + + } break; + case VIEW_USE_2_VIEWPORTS: { + + draw_texture(v_grabber, Vector2((size.width - v_grabber->get_width()) / 2, mid_h - v_grabber->get_height() / 2)); + + } break; + case VIEW_USE_2_VIEWPORTS_ALT: { + + draw_texture(h_grabber, Vector2(mid_w - h_grabber->get_width() / 2, (size.height - h_grabber->get_height()) / 2)); + + } break; + case VIEW_USE_3_VIEWPORTS: { + + draw_texture(v_grabber, Vector2((size.width - v_grabber->get_width()) / 2, mid_h - v_grabber->get_height() / 2)); + draw_texture(h_grabber, Vector2(mid_w - h_grabber->get_width() / 2, mid_h + v_grabber->get_height() / 2 + (size_bottom - h_grabber->get_height()) / 2)); + + } break; + case VIEW_USE_3_VIEWPORTS_ALT: { + + draw_texture(v_grabber, Vector2((size_left - v_grabber->get_width()) / 2, mid_h - v_grabber->get_height() / 2)); + draw_texture(h_grabber, Vector2(mid_w - h_grabber->get_width() / 2, (size.height - h_grabber->get_height()) / 2)); + } break; + case VIEW_USE_4_VIEWPORTS: { + + Vector2 half(mid_w, mid_h); + draw_texture(v_grabber, half - v_grabber->get_size() / 2.0); + draw_texture(h_grabber, half - h_grabber->get_size() / 2.0); + + } break; + } + } + + if (p_what == NOTIFICATION_SORT_CHILDREN) { + + SpatialEditorViewport *viewports[4]; + int vc = 0; + for (int i = 0; i < get_child_count(); i++) { + viewports[vc] = get_child(i)->cast_to<SpatialEditorViewport>(); + if (viewports[vc]) { + vc++; + } + } + + ERR_FAIL_COND(vc != 4); + + Size2 size = get_size(); + + if (size.x < 10 || size.y < 10) { + for (int i = 0; i < 4; i++) { + viewports[i]->hide(); + } + return; + } + int h_sep = get_constant("separation", "HSplitContainer"); + + int v_sep = get_constant("separation", "VSplitContainer"); + + int mid_w = size.width * ratio_h; + int mid_h = size.height * ratio_v; + + int size_left = mid_w - h_sep / 2; + int size_right = size.width - mid_w - h_sep / 2; + + int size_top = mid_h - v_sep / 2; + int size_bottom = size.height - mid_h - v_sep / 2; + + switch (view) { + + case VIEW_USE_1_VIEWPORT: { + + for (int i = 1; i < 4; i++) { + + viewports[i]->hide(); + } + + fit_child_in_rect(viewports[0], Rect2(Vector2(), size)); + + } break; + case VIEW_USE_2_VIEWPORTS: { + + for (int i = 1; i < 4; i++) { + + if (i == 1 || i == 3) + viewports[i]->hide(); + else + viewports[i]->show(); + } + + fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size.width, size_top))); + fit_child_in_rect(viewports[2], Rect2(Vector2(0, mid_h + v_sep / 2), Vector2(size.width, size_bottom))); + + } break; + case VIEW_USE_2_VIEWPORTS_ALT: { + + for (int i = 1; i < 4; i++) { + + if (i == 1 || i == 3) + viewports[i]->hide(); + else + viewports[i]->show(); + } + fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size_left, size.height))); + fit_child_in_rect(viewports[2], Rect2(Vector2(mid_w + h_sep / 2, 0), Vector2(size_right, size.height))); + + } break; + case VIEW_USE_3_VIEWPORTS: { + + for (int i = 1; i < 4; i++) { + + if (i == 1) + viewports[i]->hide(); + else + viewports[i]->show(); + } + + fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size.width, size_top))); + fit_child_in_rect(viewports[2], Rect2(Vector2(0, mid_h + v_sep / 2), Vector2(size_left, size_bottom))); + fit_child_in_rect(viewports[3], Rect2(Vector2(mid_w + h_sep / 2, mid_h + v_sep / 2), Vector2(size_right, size_bottom))); + + } break; + case VIEW_USE_3_VIEWPORTS_ALT: { + + for (int i = 1; i < 4; i++) { + + if (i == 1) + viewports[i]->hide(); + else + viewports[i]->show(); + } + + fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size_left, size_top))); + fit_child_in_rect(viewports[2], Rect2(Vector2(0, mid_h + v_sep / 2), Vector2(size_left, size_bottom))); + fit_child_in_rect(viewports[3], Rect2(Vector2(mid_w + h_sep / 2, 0), Vector2(size_right, size.height))); + + } break; + case VIEW_USE_4_VIEWPORTS: { + + for (int i = 1; i < 4; i++) { + + viewports[i]->show(); + } + + fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size_left, size_top))); + fit_child_in_rect(viewports[1], Rect2(Vector2(mid_w + h_sep / 2, 0), Vector2(size_right, size_top))); + fit_child_in_rect(viewports[2], Rect2(Vector2(0, mid_h + v_sep / 2), Vector2(size_left, size_bottom))); + fit_child_in_rect(viewports[3], Rect2(Vector2(mid_w + h_sep / 2, mid_h + v_sep / 2), Vector2(size_right, size_bottom))); + + } break; + } + } +} + +void SpatialEditorViewportContainer::set_view(View p_view) { + + view = p_view; + queue_sort(); +} + +SpatialEditorViewportContainer::View SpatialEditorViewportContainer::get_view() { + + return view; +} + +void SpatialEditorViewportContainer::_bind_methods() { + + ClassDB::bind_method("_gui_input", &SpatialEditorViewportContainer::_gui_input); +} + +SpatialEditorViewportContainer::SpatialEditorViewportContainer() { + + view = VIEW_USE_1_VIEWPORT; + mouseover = false; + ratio_h = 0.5; + ratio_v = 0.5; + dragging_v = false; + dragging_h = false; +} + +/////////////////////////////////////////////////////////////////// + SpatialEditor *SpatialEditor::singleton = NULL; SpatialEditorSelectedItem::~SpatialEditorSelectedItem() { @@ -2379,7 +2766,7 @@ void SpatialEditor::update_transform_gizmo() { Transform xf = se->sp->get_global_transform(); if (first) { - center.pos = xf.origin; + center.position = xf.origin; first = false; if (local_gizmo_coords) { gizmo_basis = xf.basis; @@ -2392,7 +2779,7 @@ void SpatialEditor::update_transform_gizmo() { //count++; } - Vector3 pcenter = center.pos + center.size * 0.5; + Vector3 pcenter = center.position + center.size * 0.5; gizmo.visible = !first; gizmo.transform.origin = pcenter; gizmo.transform.basis = gizmo_basis; @@ -2719,12 +3106,7 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_1_VIEWPORT: { - for (int i = 1; i < 4; i++) { - - viewports[i]->hide(); - } - - viewports[0]->set_area_as_parent_rect(); + viewport_base->set_view(SpatialEditorViewportContainer::VIEW_USE_1_VIEWPORT); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), true); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false); @@ -2736,17 +3118,7 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_2_VIEWPORTS: { - for (int i = 1; i < 4; i++) { - - if (i == 1 || i == 3) - viewports[i]->hide(); - else - viewports[i]->show(); - } - viewports[0]->set_area_as_parent_rect(); - //viewports[0]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); - viewports[2]->set_area_as_parent_rect(); - //viewports[2]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); + viewport_base->set_view(SpatialEditorViewportContainer::VIEW_USE_2_VIEWPORTS); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), true); @@ -2758,17 +3130,7 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_2_VIEWPORTS_ALT: { - for (int i = 1; i < 4; i++) { - - if (i == 1 || i == 3) - viewports[i]->hide(); - else - viewports[i]->show(); - } - viewports[0]->set_area_as_parent_rect(); - //viewports[0]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); - viewports[2]->set_area_as_parent_rect(); - //viewports[2]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); + viewport_base->set_view(SpatialEditorViewportContainer::VIEW_USE_2_VIEWPORTS_ALT); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false); @@ -2780,21 +3142,7 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_3_VIEWPORTS: { - for (int i = 1; i < VIEWPORTS_COUNT; i++) { - - if (i == 1) - viewports[i]->hide(); - else - viewports[i]->show(); - } - viewports[0]->set_area_as_parent_rect(); - //viewports[0]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); - viewports[2]->set_area_as_parent_rect(); - //viewports[2]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); - //viewports[2]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); - viewports[3]->set_area_as_parent_rect(); - //viewports[3]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); - //viewports[3]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); + viewport_base->set_view(SpatialEditorViewportContainer::VIEW_USE_3_VIEWPORTS); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false); @@ -2806,21 +3154,7 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_3_VIEWPORTS_ALT: { - for (int i = 1; i < VIEWPORTS_COUNT; i++) { - - if (i == 1) - viewports[i]->hide(); - else - viewports[i]->show(); - } - viewports[0]->set_area_as_parent_rect(); - //viewports[0]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); - //viewports[0]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); - viewports[2]->set_area_as_parent_rect(); - //viewports[2]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); - //viewports[2]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); - viewports[3]->set_area_as_parent_rect(); - //viewports[3]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); + viewport_base->set_view(SpatialEditorViewportContainer::VIEW_USE_3_VIEWPORTS_ALT); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false); @@ -2832,22 +3166,7 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_4_VIEWPORTS: { - for (int i = 1; i < VIEWPORTS_COUNT; i++) { - - viewports[i]->show(); - } - viewports[0]->set_area_as_parent_rect(); - //viewports[0]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); - //viewports[0]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); - viewports[1]->set_area_as_parent_rect(); - //viewports[1]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); - //viewports[1]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); - viewports[2]->set_area_as_parent_rect(); - //viewports[2]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); - //viewports[2]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); - viewports[3]->set_area_as_parent_rect(); - //viewports[3]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); - //viewports[3]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); + viewport_base->set_view(SpatialEditorViewportContainer::VIEW_USE_4_VIEWPORTS); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false); @@ -2857,43 +3176,6 @@ void SpatialEditor::_menu_item_pressed(int p_option) { view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), false); } break; - case MENU_VIEW_DISPLAY_NORMAL: { - - VisualServer::get_singleton()->scenario_set_debug(get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_DISABLED); - - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), true); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_OVERDRAW), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_SHADELESS), false); - - } break; - case MENU_VIEW_DISPLAY_WIREFRAME: { - - VisualServer::get_singleton()->scenario_set_debug(get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_WIREFRAME); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), true); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_OVERDRAW), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_SHADELESS), false); - - } break; - case MENU_VIEW_DISPLAY_OVERDRAW: { - - VisualServer::get_singleton()->scenario_set_debug(get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_OVERDRAW); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_OVERDRAW), true); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_SHADELESS), false); - - } break; - case MENU_VIEW_DISPLAY_SHADELESS: { - - VisualServer::get_singleton()->scenario_set_debug(get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_SHADELESS); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_OVERDRAW), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_SHADELESS), true); - - } break; case MENU_VIEW_ORIGIN: { bool is_checked = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(p_option)); @@ -3242,17 +3524,6 @@ void SpatialEditor::_unhandled_key_input(Ref<InputEvent> p_event) { else if (ED_IS_SHORTCUT("spatial_editor/tool_scale", p_event)) _menu_item_pressed(MENU_TOOL_SCALE); - - else if (ED_IS_SHORTCUT("spatial_editor/display_wireframe", p_event)) { - if (k->get_shift() || k->get_control() || k->get_command()) - return; - - if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME))) { - _menu_item_pressed(MENU_VIEW_DISPLAY_NORMAL); - } else { - _menu_item_pressed(MENU_VIEW_DISPLAY_WIREFRAME); - } - } } } } @@ -3419,9 +3690,6 @@ void SpatialEditor::clear() { viewports[i]->reset(); } - _menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT); - _menu_item_pressed(MENU_VIEW_DISPLAY_NORMAL); - VisualServer::get_singleton()->instance_set_visible(origin_instance, true); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_ORIGIN), true); for (int i = 0; i < 3; ++i) { @@ -3566,17 +3834,11 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { p->add_check_shortcut(ED_SHORTCUT("spatial_editor/4_viewports", TTR("4 Viewports"), KEY_MASK_CMD + KEY_4), MENU_VIEW_USE_4_VIEWPORTS); p->add_separator(); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/display_normal", TTR("Display Normal")), MENU_VIEW_DISPLAY_NORMAL); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/display_wireframe", TTR("Display Wireframe")), MENU_VIEW_DISPLAY_WIREFRAME); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/display_overdraw", TTR("Display Overdraw")), MENU_VIEW_DISPLAY_OVERDRAW); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/display_shadeless", TTR("Display Shadeless")), MENU_VIEW_DISPLAY_SHADELESS); - p->add_separator(); p->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_origin", TTR("View Origin")), MENU_VIEW_ORIGIN); p->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_grid", TTR("View Grid")), MENU_VIEW_GRID); p->add_separator(); p->add_shortcut(ED_SHORTCUT("spatial_editor/settings", TTR("Settings")), MENU_VIEW_CAMERA_SETTINGS); - p->set_item_checked(p->get_item_index(MENU_VIEW_DISPLAY_NORMAL), true); p->set_item_checked(p->get_item_index(MENU_VIEW_ORIGIN), true); p->set_item_checked(p->get_item_index(MENU_VIEW_GRID), true); @@ -3591,7 +3853,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { shader_split = memnew(VSplitContainer); shader_split->set_h_size_flags(SIZE_EXPAND_FILL); palette_split->add_child(shader_split); - viewport_base = memnew(Control); + viewport_base = memnew(SpatialEditorViewportContainer); shader_split->add_child(viewport_base); viewport_base->set_v_size_flags(SIZE_EXPAND_FILL); for (int i = 0; i < VIEWPORTS_COUNT; i++) { diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index 394002db3b..6b05a8b370 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -84,6 +84,11 @@ class SpatialEditorViewport : public Control { VIEW_ORTHOGONAL, VIEW_AUDIO_LISTENER, VIEW_GIZMOS, + VIEW_INFORMATION, + VIEW_DISPLAY_NORMAL, + VIEW_DISPLAY_WIREFRAME, + VIEW_DISPLAY_OVERDRAW, + VIEW_DISPLAY_SHADELESS, }; public: @@ -116,6 +121,9 @@ private: bool freelook_active; + PanelContainer *info; + Label *info_label; + struct _RayResult { Spatial *item; @@ -287,6 +295,43 @@ public: ~SpatialEditorSelectedItem(); }; +class SpatialEditorViewportContainer : public Container { + + GDCLASS(SpatialEditorViewportContainer, Container) +public: + enum View { + VIEW_USE_1_VIEWPORT, + VIEW_USE_2_VIEWPORTS, + VIEW_USE_2_VIEWPORTS_ALT, + VIEW_USE_3_VIEWPORTS, + VIEW_USE_3_VIEWPORTS_ALT, + VIEW_USE_4_VIEWPORTS, + }; + +private: + View view; + bool mouseover; + float ratio_h; + float ratio_v; + + bool dragging_v; + bool dragging_h; + Vector2 drag_begin_pos; + Vector2 drag_begin_ratio; + + void _gui_input(const Ref<InputEvent> &p_event); + +protected: + void _notification(int p_what); + static void _bind_methods(); + +public: + void set_view(View p_view); + View get_view(); + + SpatialEditorViewportContainer(); +}; + class SpatialEditor : public VBoxContainer { GDCLASS(SpatialEditor, VBoxContainer); @@ -309,7 +354,7 @@ private: EditorNode *editor; EditorSelection *editor_selection; - Control *viewport_base; + SpatialEditorViewportContainer *viewport_base; SpatialEditorViewport *viewports[VIEWPORTS_COUNT]; VSplitContainer *shader_split; HSplitContainer *palette_split; @@ -379,10 +424,6 @@ private: MENU_VIEW_USE_3_VIEWPORTS, MENU_VIEW_USE_3_VIEWPORTS_ALT, MENU_VIEW_USE_4_VIEWPORTS, - MENU_VIEW_DISPLAY_NORMAL, - MENU_VIEW_DISPLAY_WIREFRAME, - MENU_VIEW_DISPLAY_OVERDRAW, - MENU_VIEW_DISPLAY_SHADELESS, MENU_VIEW_ORIGIN, MENU_VIEW_GRID, MENU_VIEW_CAMERA_SETTINGS, diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index d1b79ea7aa..3d3fecc8f9 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -733,9 +733,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: config_value_editors(6, 3, 16, field_names); Rect3 aabb = v; - value_editor[0]->set_text(String::num(aabb.pos.x)); - value_editor[1]->set_text(String::num(aabb.pos.y)); - value_editor[2]->set_text(String::num(aabb.pos.z)); + value_editor[0]->set_text(String::num(aabb.position.x)); + value_editor[1]->set_text(String::num(aabb.position.y)); + value_editor[2]->set_text(String::num(aabb.position.z)); value_editor[3]->set_text(String::num(aabb.size.x)); value_editor[4]->set_text(String::num(aabb.size.y)); value_editor[5]->set_text(String::num(aabb.size.z)); diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index 149b06e50a..1b7afd3c43 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -1722,8 +1722,8 @@ void CollisionShapeSpatialGizmo::redraw() { Ref<BoxShape> bs = s; Vector<Vector3> lines; Rect3 aabb; - aabb.pos = -bs->get_extents(); - aabb.size = aabb.pos * -2; + aabb.position = -bs->get_extents(); + aabb.size = aabb.position * -2; for (int i = 0; i < 12; i++) { Vector3 a, b; @@ -1953,7 +1953,7 @@ void VisibilityNotifierGizmo::set_handle(int p_idx, Camera *p_camera, const Poin Vector3 ray_dir = p_camera->project_ray_normal(p_point); Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 4096) }; - Vector3 ofs = aabb.pos + aabb.size * 0.5; + Vector3 ofs = aabb.position + aabb.size * 0.5; Vector3 axis; axis[p_idx] = 1.0; @@ -1964,7 +1964,7 @@ void VisibilityNotifierGizmo::set_handle(int p_idx, Camera *p_camera, const Poin if (d < 0.001) d = 0.001; - aabb.pos[p_idx] = (aabb.pos[p_idx] + aabb.size[p_idx] * 0.5) - d; + aabb.position[p_idx] = (aabb.position[p_idx] + aabb.size[p_idx] * 0.5) - d; aabb.size[p_idx] = d * 2; notifier->set_aabb(aabb); } @@ -2002,7 +2002,7 @@ void VisibilityNotifierGizmo::redraw() { for (int i = 0; i < 3; i++) { Vector3 ax; - ax[i] = aabb.pos[i] + aabb.size[i]; + ax[i] = aabb.position[i] + aabb.size[i]; handles.push_back(ax); } @@ -2053,7 +2053,7 @@ void ParticlesGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_poi Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 4096) }; - Vector3 ofs = aabb.pos + aabb.size * 0.5; + Vector3 ofs = aabb.position + aabb.size * 0.5; Vector3 axis; axis[p_idx] = 1.0; @@ -2065,7 +2065,7 @@ void ParticlesGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_poi float d = ra[p_idx]; - aabb.pos[p_idx] = d - 1.0 - aabb.size[p_idx] * 0.5; + aabb.position[p_idx] = d - 1.0 - aabb.size[p_idx] * 0.5; particles->set_visibility_aabb(aabb); } else { @@ -2076,7 +2076,7 @@ void ParticlesGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_poi if (d < 0.001) d = 0.001; //resize - aabb.pos[p_idx] = (aabb.pos[p_idx] + aabb.size[p_idx] * 0.5) - d; + aabb.position[p_idx] = (aabb.position[p_idx] + aabb.size[p_idx] * 0.5) - d; aabb.size[p_idx] = d * 2; particles->set_visibility_aabb(aabb); } @@ -2115,13 +2115,13 @@ void ParticlesGizmo::redraw() { for (int i = 0; i < 3; i++) { Vector3 ax; - ax[i] = aabb.pos[i] + aabb.size[i]; - ax[(i + 1) % 3] = aabb.pos[(i + 1) % 3] + aabb.size[(i + 1) % 3] * 0.5; - ax[(i + 2) % 3] = aabb.pos[(i + 2) % 3] + aabb.size[(i + 2) % 3] * 0.5; + ax[i] = aabb.position[i] + aabb.size[i]; + ax[(i + 1) % 3] = aabb.position[(i + 1) % 3] + aabb.size[(i + 1) % 3] * 0.5; + ax[(i + 2) % 3] = aabb.position[(i + 2) % 3] + aabb.size[(i + 2) % 3] * 0.5; handles.push_back(ax); } - Vector3 center = aabb.pos + aabb.size * 0.5; + Vector3 center = aabb.position + aabb.size * 0.5; for (int i = 0; i < 3; i++) { Vector3 ax; @@ -2218,7 +2218,7 @@ void ReflectionProbeGizmo::commit_handle(int p_idx, const Variant &p_restore, bo Rect3 restore = p_restore; if (p_cancel) { - probe->set_extents(restore.pos); + probe->set_extents(restore.position); probe->set_origin_offset(restore.size); return; } @@ -2227,7 +2227,7 @@ void ReflectionProbeGizmo::commit_handle(int p_idx, const Variant &p_restore, bo ur->create_action(TTR("Change Probe Extents")); ur->add_do_method(probe, "set_extents", probe->get_extents()); ur->add_do_method(probe, "set_origin_offset", probe->get_origin_offset()); - ur->add_undo_method(probe, "set_extents", restore.pos); + ur->add_undo_method(probe, "set_extents", restore.position); ur->add_undo_method(probe, "set_origin_offset", restore.size); ur->commit_action(); } @@ -2241,7 +2241,7 @@ void ReflectionProbeGizmo::redraw() { Vector3 extents = probe->get_extents(); Rect3 aabb; - aabb.pos = -extents; + aabb.position = -extents; aabb.size = extents * 2; for (int i = 0; i < 12; i++) { @@ -2262,7 +2262,7 @@ void ReflectionProbeGizmo::redraw() { for (int i = 0; i < 3; i++) { Vector3 ax; - ax[i] = aabb.pos[i] + aabb.size[i]; + ax[i] = aabb.position[i] + aabb.size[i]; handles.push_back(ax); } @@ -2392,7 +2392,7 @@ void GIProbeGizmo::redraw() { for (int k = 0; k < 4; k++) { - Vector3 from = aabb.pos, to = aabb.pos; + Vector3 from = aabb.position, to = aabb.position; from[j] += cell_size * i; to[j] += cell_size * i; @@ -2421,7 +2421,7 @@ void GIProbeGizmo::redraw() { for (int i = 0; i < 3; i++) { Vector3 ax; - ax[i] = aabb.pos[i] + aabb.size[i]; + ax[i] = aabb.position[i] + aabb.size[i]; handles.push_back(ax); } diff --git a/modules/gdnative/godot/godot_rect3.cpp b/modules/gdnative/godot/godot_rect3.cpp index 2642424145..e524fa8463 100644 --- a/modules/gdnative/godot/godot_rect3.cpp +++ b/modules/gdnative/godot/godot_rect3.cpp @@ -45,18 +45,18 @@ void GDAPI godot_rect3_new(godot_rect3 *r_dest, const godot_vector3 *p_pos, cons *dest = Rect3(*pos, *size); } -godot_vector3 GDAPI godot_rect3_get_pos(const godot_rect3 *p_self) { +godot_vector3 GDAPI godot_rect3_get_position(const godot_rect3 *p_self) { godot_vector3 raw_ret; const Rect3 *self = (const Rect3 *)p_self; Vector3 *ret = (Vector3 *)&raw_ret; - *ret = self->pos; + *ret = self->position; return raw_ret; } -void GDAPI godot_rect3_set_pos(const godot_rect3 *p_self, const godot_vector3 *p_v) { +void GDAPI godot_rect3_set_position(const godot_rect3 *p_self, const godot_vector3 *p_v) { Rect3 *self = (Rect3 *)p_self; const Vector3 *v = (const Vector3 *)p_v; - self->pos = *v; + self->position = *v; } godot_vector3 GDAPI godot_rect3_get_size(const godot_rect3 *p_self) { diff --git a/modules/gdnative/godot/godot_rect3.h b/modules/gdnative/godot/godot_rect3.h index 6ebc06157b..9e9a49ac27 100644 --- a/modules/gdnative/godot/godot_rect3.h +++ b/modules/gdnative/godot/godot_rect3.h @@ -49,8 +49,8 @@ typedef struct godot_rect3 { void GDAPI godot_rect3_new(godot_rect3 *r_dest, const godot_vector3 *p_pos, const godot_vector3 *p_size); -godot_vector3 GDAPI godot_rect3_get_pos(const godot_rect3 *p_self); -void GDAPI godot_rect3_set_pos(const godot_rect3 *p_self, const godot_vector3 *p_v); +godot_vector3 GDAPI godot_rect3_get_position(const godot_rect3 *p_self); +void GDAPI godot_rect3_set_position(const godot_rect3 *p_self, const godot_vector3 *p_v); godot_vector3 GDAPI godot_rect3_get_size(const godot_rect3 *p_self); void GDAPI godot_rect3_set_size(const godot_rect3 *p_self, const godot_vector3 *p_v); diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index d1f54e021f..9d3da8227c 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -1057,12 +1057,12 @@ Error GridMap::create_area(int p_id, const Rect3 &p_bounds) { // FIRST VALIDATE AREA IndexKey from, to; - from.x = p_bounds.pos.x; - from.y = p_bounds.pos.y; - from.z = p_bounds.pos.z; - to.x = p_bounds.pos.x + p_bounds.size.x; - to.y = p_bounds.pos.y + p_bounds.size.y; - to.z = p_bounds.pos.z + p_bounds.size.z; + from.x = p_bounds.position.x; + from.y = p_bounds.position.y; + from.z = p_bounds.position.z; + to.x = p_bounds.position.x + p_bounds.size.x; + to.y = p_bounds.position.y + p_bounds.size.y; + to.z = p_bounds.position.z + p_bounds.size.z; for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) { //this should somehow be faster... @@ -1101,8 +1101,8 @@ Rect3 GridMap::area_get_bounds(int p_area) const { const Area *a = area_map[p_area]; Rect3 aabb; - aabb.pos = Vector3(a->from.x, a->from.y, a->from.z); - aabb.size = Vector3(a->to.x, a->to.y, a->to.z) - aabb.pos; + aabb.position = Vector3(a->from.x, a->from.y, a->from.z); + aabb.size = Vector3(a->to.x, a->to.y, a->to.z) - aabb.position; return aabb; } diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index 121b403f64..954e865bcd 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -635,7 +635,7 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu int area = E->get(); Rect3 aabb = node->area_get_bounds(area); - aabb.pos *= node->get_cell_size(); + aabb.position *= node->get_cell_size(); aabb.size *= node->get_cell_size(); Vector3 rclip, rnormal; diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp index e927f1ceaa..32772e0cd2 100644 --- a/modules/squish/image_compress_squish.cpp +++ b/modules/squish/image_compress_squish.cpp @@ -64,6 +64,7 @@ void image_decompress_squish(Image *p_image) { } else if (p_image->get_format() == Image::FORMAT_RGTC_RG) { squish_flags = squish::kBc5; } else { + print_line("wtf askd to decompress.. " + itos(p_image->get_format())); ERR_FAIL_COND(true); return; } diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index 3a37d663ad..123816b22d 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -30,21 +30,21 @@ #ifndef OS_OSX_H #define OS_OSX_H +#include "drivers/alsa/audio_driver_alsa.h" +#include "drivers/rtaudio/audio_driver_rtaudio.h" #include "drivers/unix/os_unix.h" #include "joypad_osx.h" #include "main/input_default.h" #include "os/input.h" -#include "power_osx.h" -#include "servers/visual_server.h" -// #include "servers/visual/visual_server_wrap_mt.h" -#include "drivers/alsa/audio_driver_alsa.h" -#include "drivers/rtaudio/audio_driver_rtaudio.h" #include "platform/osx/audio_driver_osx.h" +#include "power_osx.h" #include "servers/audio_server.h" #include "servers/physics_2d/physics_2d_server_sw.h" #include "servers/physics_2d/physics_2d_server_wrap_mt.h" #include "servers/physics_server.h" #include "servers/visual/rasterizer.h" +#include "servers/visual/visual_server_wrap_mt.h" +#include "servers/visual_server.h" #include <ApplicationServices/ApplicationServices.h> //bitch diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 54b1802250..72fba39e33 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -932,12 +932,10 @@ void OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_au //visual_server = memnew( VisualServerRaster(rasterizer) ); visual_server = memnew(VisualServerRaster); - // FIXME: Reimplement threaded rendering? Or remove? - /* - if (get_render_thread_mode()!=RENDER_THREAD_UNSAFE) { - visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD)); + if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) { + + visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD)); } -*/ visual_server->init(); visual_server->cursor_set_visible(false, 0); diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index a9fcf70b55..4393cad3bf 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -37,15 +37,15 @@ #include "drivers/windows/rw_lock_windows.h" #include "drivers/windows/semaphore_windows.h" #include "drivers/windows/thread_windows.h" -#include "servers/audio_server.h" -#include "servers/visual/visual_server_raster.h" -//#include "servers/visual/visual_server_wrap_mt.h" #include "global_config.h" #include "io/marshalls.h" #include "joypad.h" #include "lang_table.h" #include "main/main.h" #include "packet_peer_udp_winsock.h" +#include "servers/audio_server.h" +#include "servers/visual/visual_server_raster.h" +#include "servers/visual/visual_server_wrap_mt.h" #include "stream_peer_winsock.h" #include "tcp_server_winsock.h" @@ -1029,12 +1029,10 @@ void OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int #endif visual_server = memnew(VisualServerRaster); - // FIXME: Reimplement threaded rendering? Or remove? - /* - if (get_render_thread_mode()!=RENDER_THREAD_UNSAFE) { - visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD)); + if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) { + + visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD)); } - */ physics_server = memnew(PhysicsServerSW); physics_server->init(); diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 8ac37c965b..2eebc96d2c 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -34,6 +34,7 @@ #include "print_string.h" #include "servers/physics/physics_server_sw.h" #include "servers/visual/visual_server_raster.h" +#include "servers/visual/visual_server_wrap_mt.h" #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -206,12 +207,12 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au #endif visual_server = memnew(VisualServerRaster); -#if 0 - if (get_render_thread_mode()!=RENDER_THREAD_UNSAFE) { - visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD)); + if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) { + + visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD)); } -#endif + // borderless fullscreen window mode if (current_videomode.fullscreen) { // needed for lxde/openbox, possibly others diff --git a/scene/3d/collision_polygon.cpp b/scene/3d/collision_polygon.cpp index a9a693f370..d9321f7134 100644 --- a/scene/3d/collision_polygon.cpp +++ b/scene/3d/collision_polygon.cpp @@ -208,7 +208,7 @@ void CollisionPolygon::set_polygon(const Vector<Point2> &p_polygon) { aabb = Rect3(Vector3(-1, -1, -1), Vector3(2, 2, 2)); } else { - aabb.pos -= aabb.size * 0.3; + aabb.position -= aabb.size * 0.3; aabb.size += aabb.size * 0.6; } _update_parent(); diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp index ec3e059249..adca1492c3 100644 --- a/scene/3d/gi_probe.cpp +++ b/scene/3d/gi_probe.cpp @@ -564,7 +564,7 @@ void GIProbe::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, cons Vector3 ofs_j = float(j) * t2; - Vector3 from = p_aabb.pos + ofs_i + ofs_j; + Vector3 from = p_aabb.position + ofs_i + ofs_j; Vector3 to = from + t1 + t2 + axis * p_aabb.size[closest_axis]; Vector3 half = (to - from) * 0.5; @@ -619,7 +619,7 @@ void GIProbe::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, cons //could not in any way get texture information.. so use closest point to center Face3 f(p_vtx[0], p_vtx[1], p_vtx[2]); - Vector3 inters = f.get_closest_point_to(p_aabb.pos + p_aabb.size * 0.5); + Vector3 inters = f.get_closest_point_to(p_aabb.position + p_aabb.size * 0.5); Vector2 uv = get_uv(inters, p_vtx, p_uv); @@ -700,15 +700,15 @@ void GIProbe::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, cons int nz = p_z; if (i & 1) { - aabb.pos.x += aabb.size.x; + aabb.position.x += aabb.size.x; nx += half; } if (i & 2) { - aabb.pos.y += aabb.size.y; + aabb.position.y += aabb.size.y; ny += half; } if (i & 4) { - aabb.pos.z += aabb.size.z; + aabb.position.z += aabb.size.z; nz += half; } //make sure to not plot beyond limits @@ -720,7 +720,7 @@ void GIProbe::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, cons //test_aabb.grow_by(test_aabb.get_longest_axis_size()*0.05); //grow a bit to avoid numerical error in real-time Vector3 qsize = test_aabb.size * 0.5; //quarter size, for fast aabb test - if (!fast_tri_box_overlap(test_aabb.pos + qsize, qsize, p_vtx)) { + if (!fast_tri_box_overlap(test_aabb.position + qsize, qsize, p_vtx)) { //if (!Face3(p_vtx[0],p_vtx[1],p_vtx[2]).intersects_aabb2(aabb)) { //does not fit in child, go on continue; @@ -1155,7 +1155,7 @@ void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug) { Transform to_bounds; to_bounds.basis.scale(Vector3(baker.po2_bounds.size[longest_axis], baker.po2_bounds.size[longest_axis], baker.po2_bounds.size[longest_axis])); - to_bounds.origin = baker.po2_bounds.pos; + to_bounds.origin = baker.po2_bounds.position; Transform to_grid; to_grid.basis.scale(Vector3(baker.axis_cell_size[longest_axis], baker.axis_cell_size[longest_axis], baker.axis_cell_size[longest_axis])); @@ -1274,7 +1274,7 @@ void GIProbe::_debug_mesh(int p_idx, int p_level, const Rect3 &p_aabb, Ref<Multi if (p_level == p_baker->cell_subdiv - 1) { - Vector3 center = p_aabb.pos + p_aabb.size * 0.5; + Vector3 center = p_aabb.position + p_aabb.size * 0.5; Transform xform; xform.origin = center; xform.basis.scale(p_aabb.size * 0.5); @@ -1296,11 +1296,11 @@ void GIProbe::_debug_mesh(int p_idx, int p_level, const Rect3 &p_aabb, Ref<Multi aabb.size *= 0.5; if (i & 1) - aabb.pos.x += aabb.size.x; + aabb.position.x += aabb.size.x; if (i & 2) - aabb.pos.y += aabb.size.y; + aabb.position.y += aabb.size.y; if (i & 4) - aabb.pos.z += aabb.size.z; + aabb.position.z += aabb.size.z; _debug_mesh(p_baker->bake_cells[p_idx].childs[i], p_level + 1, aabb, p_multimesh, idx, p_baker); } diff --git a/scene/3d/immediate_geometry.cpp b/scene/3d/immediate_geometry.cpp index 8c1ad1d052..128c8b44c3 100644 --- a/scene/3d/immediate_geometry.cpp +++ b/scene/3d/immediate_geometry.cpp @@ -65,7 +65,7 @@ void ImmediateGeometry::add_vertex(const Vector3 &p_vertex) { VS::get_singleton()->immediate_vertex(im, p_vertex); if (empty) { - aabb.pos = p_vertex; + aabb.position = p_vertex; aabb.size = Vector3(); empty = false; } else { diff --git a/scene/3d/reflection_probe.cpp b/scene/3d/reflection_probe.cpp index 845245b090..86a62bec97 100644 --- a/scene/3d/reflection_probe.cpp +++ b/scene/3d/reflection_probe.cpp @@ -181,7 +181,7 @@ ReflectionProbe::UpdateMode ReflectionProbe::get_update_mode() const { Rect3 ReflectionProbe::get_aabb() const { Rect3 aabb; - aabb.pos = -origin_offset; + aabb.position = -origin_offset; aabb.size = origin_offset + extents; return aabb; } diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index 43487505c2..a95bb4a67f 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -421,7 +421,7 @@ void Sprite3D::_draw() { vtx[y_axis] = vertices[i][1]; VS::get_singleton()->immediate_vertex(immediate, vtx); if (i == 0) { - aabb.pos = vtx; + aabb.position = vtx; aabb.size = Vector3(); } else { aabb.expand_to(vtx); @@ -922,7 +922,7 @@ void AnimatedSprite3D::_draw() { vtx[y_axis] = vertices[i][1]; VS::get_singleton()->immediate_vertex(immediate, vtx); if (i == 0) { - aabb.pos = vtx; + aabb.position = vtx; aabb.size = Vector3(); } else { aabb.expand_to(vtx); diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 2a6ffb5628..67920d177e 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -421,9 +421,9 @@ Variant Tween::_run_equation(InterpolateData &p_data) { Rect3 d = delta_val; Rect3 r; - APPLY_EQUATION(pos.x); - APPLY_EQUATION(pos.y); - APPLY_EQUATION(pos.z); + APPLY_EQUATION(position.x); + APPLY_EQUATION(position.y); + APPLY_EQUATION(position.z); APPLY_EQUATION(size.x); APPLY_EQUATION(size.y); APPLY_EQUATION(size.z); @@ -963,7 +963,7 @@ bool Tween::_calc_delta_val(const Variant &p_initial_val, const Variant &p_final case Variant::RECT3: { Rect3 i = initial_val; Rect3 f = final_val; - delta_val = Rect3(f.pos - i.pos, f.size - i.size); + delta_val = Rect3(f.position - i.position, f.size - i.size); } break; case Variant::TRANSFORM: { Transform i = initial_val; diff --git a/scene/gui/split_container.h b/scene/gui/split_container.h index 94b80cf279..87a210f24c 100644 --- a/scene/gui/split_container.h +++ b/scene/gui/split_container.h @@ -34,7 +34,7 @@ class SplitContainer : public Container { - GDCLASS(SplitContainer, Container); + GDCLASS(SplitContainer, Container) public: enum DraggerVisibility { diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index ec36cf48bc..763cac2af4 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -117,7 +117,11 @@ bool ViewportTexture::has_alpha() const { return false; } +Ref<Image> ViewportTexture::get_data() const { + ERR_FAIL_COND_V(!vp, Ref<Image>()); + return VS::get_singleton()->texture_get_data(vp->texture_rid); +} void ViewportTexture::set_flags(uint32_t p_flags) { if (!vp) @@ -2516,6 +2520,32 @@ bool Viewport::get_hdr() const { return hdr; } +void Viewport::set_usage(Usage p_usage) { + + usage = p_usage; + VS::get_singleton()->viewport_set_usage(viewport, VS::ViewportUsage(p_usage)); +} + +Viewport::Usage Viewport::get_usage() const { + return usage; +} + +void Viewport::set_debug_draw(DebugDraw p_debug_draw) { + + debug_draw = p_debug_draw; + VS::get_singleton()->viewport_set_debug_draw(viewport, VS::ViewportDebugDraw(p_debug_draw)); +} + +Viewport::DebugDraw Viewport::get_debug_draw() const { + + return debug_draw; +} + +int Viewport::get_render_info(RenderInfo p_info) { + + return VS::get_singleton()->viewport_get_render_info(viewport, VS::ViewportRenderInfo(p_info)); +} + void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_size", "size"), &Viewport::set_size); @@ -2569,6 +2599,14 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_hdr", "enable"), &Viewport::set_hdr); ClassDB::bind_method(D_METHOD("get_hdr"), &Viewport::get_hdr); + ClassDB::bind_method(D_METHOD("set_usage", "usage"), &Viewport::set_usage); + ClassDB::bind_method(D_METHOD("get_usage"), &Viewport::get_usage); + + ClassDB::bind_method(D_METHOD("set_debug_draw", "debug_draw"), &Viewport::set_debug_draw); + ClassDB::bind_method(D_METHOD("get_debug_draw"), &Viewport::get_debug_draw); + + ClassDB::bind_method(D_METHOD("get_render_info", "info"), &Viewport::get_render_info); + ClassDB::bind_method(D_METHOD("get_texture:ViewportTexture"), &Viewport::get_texture); ClassDB::bind_method(D_METHOD("set_physics_object_picking", "enable"), &Viewport::set_physics_object_picking); @@ -2622,6 +2660,8 @@ void Viewport::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x"), "set_msaa", "get_msaa"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hdr"), "set_hdr", "get_hdr"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disable_3d"), "set_disable_3d", "is_3d_disabled"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "usage", PROPERTY_HINT_ENUM, "2D,2D No-Sampling,3D,3D No-Effects"), "set_usage", "get_usage"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "debug_draw", PROPERTY_HINT_ENUM, "Disabled,Unshaded,Overdraw,Wireframe"), "set_debug_draw", "get_debug_draw"); ADD_GROUP("Render Target", "render_target_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_target_v_flip"), "set_vflip", "get_vflip"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_target_clear_on_new_frame"), "set_clear_on_new_frame", "get_clear_on_new_frame"); @@ -2656,6 +2696,19 @@ void Viewport::_bind_methods() { BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_1024); BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_MAX); + BIND_CONSTANT(RENDER_INFO_OBJECTS_IN_FRAME); + BIND_CONSTANT(RENDER_INFO_VERTICES_IN_FRAME); + BIND_CONSTANT(RENDER_INFO_MATERIAL_CHANGES_IN_FRAME); + BIND_CONSTANT(RENDER_INFO_SHADER_CHANGES_IN_FRAME); + BIND_CONSTANT(RENDER_INFO_SURFACE_CHANGES_IN_FRAME); + BIND_CONSTANT(RENDER_INFO_DRAW_CALLS_IN_FRAME); + BIND_CONSTANT(RENDER_INFO_MAX); + + BIND_CONSTANT(DEBUG_DRAW_DISABLED); + BIND_CONSTANT(DEBUG_DRAW_UNSHADED); + BIND_CONSTANT(DEBUG_DRAW_OVERDRAW); + BIND_CONSTANT(DEBUG_DRAW_WIREFRAME); + BIND_CONSTANT(MSAA_DISABLED); BIND_CONSTANT(MSAA_2X); BIND_CONSTANT(MSAA_4X); @@ -2730,6 +2783,9 @@ Viewport::Viewport() { msaa = MSAA_DISABLED; hdr = false; + + usage = USAGE_3D; + debug_draw = DEBUG_DRAW_DISABLED; } Viewport::~Viewport() { diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 7470cefb49..378055bef5 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -77,6 +77,8 @@ public: virtual void set_flags(uint32_t p_flags); virtual uint32_t get_flags() const; + virtual Ref<Image> get_data() const; + ViewportTexture(); ~ViewportTexture(); }; @@ -113,6 +115,31 @@ public: MSAA_16X, }; + enum Usage { + USAGE_2D, + USAGE_2D_NO_SAMPLING, + USAGE_3D, + USAGE_3D_NO_EFFECTS, + }; + + enum RenderInfo { + + RENDER_INFO_OBJECTS_IN_FRAME, + RENDER_INFO_VERTICES_IN_FRAME, + RENDER_INFO_MATERIAL_CHANGES_IN_FRAME, + RENDER_INFO_SHADER_CHANGES_IN_FRAME, + RENDER_INFO_SURFACE_CHANGES_IN_FRAME, + RENDER_INFO_DRAW_CALLS_IN_FRAME, + RENDER_INFO_MAX + }; + + enum DebugDraw { + DEBUG_DRAW_DISABLED, + DEBUG_DRAW_UNSHADED, + DEBUG_DRAW_OVERDRAW, + DEBUG_DRAW_WIREFRAME, + }; + private: friend class ViewportTexture; @@ -195,6 +222,10 @@ private: RID texture_rid; uint32_t texture_flags; + DebugDraw debug_draw; + + Usage usage; + int shadow_atlas_size; ShadowAtlasQuadrantSubdiv shadow_atlas_quadrant_subdiv[4]; @@ -416,6 +447,14 @@ public: virtual String get_configuration_warning() const; + void set_usage(Usage p_usage); + Usage get_usage() const; + + void set_debug_draw(DebugDraw p_debug_draw); + DebugDraw get_debug_draw() const; + + int get_render_info(RenderInfo p_info); + Viewport(); ~Viewport(); }; @@ -423,5 +462,8 @@ public: VARIANT_ENUM_CAST(Viewport::UpdateMode); VARIANT_ENUM_CAST(Viewport::ShadowAtlasQuadrantSubdiv); VARIANT_ENUM_CAST(Viewport::MSAA); +VARIANT_ENUM_CAST(Viewport::Usage); +VARIANT_ENUM_CAST(Viewport::DebugDraw); +VARIANT_ENUM_CAST(Viewport::RenderInfo); #endif diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index fe5e6e775a..459d3ffe41 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -1165,7 +1165,7 @@ Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a Rect3 pb = p_post_b; return Rect3( - a.pos.cubic_interpolate(b.pos, pa.pos, pb.pos, p_c), + a.position.cubic_interpolate(b.position, pa.position, pb.position, p_c), a.size.cubic_interpolate(b.size, pa.size, pb.size, p_c)); } break; default: { diff --git a/scene/resources/box_shape.cpp b/scene/resources/box_shape.cpp index fedfc71313..d5c25b718e 100644 --- a/scene/resources/box_shape.cpp +++ b/scene/resources/box_shape.cpp @@ -34,8 +34,8 @@ Vector<Vector3> BoxShape::_gen_debug_mesh_lines() { Vector<Vector3> lines; Rect3 aabb; - aabb.pos = -get_extents(); - aabb.size = aabb.pos * -2; + aabb.position = -get_extents(); + aabb.size = aabb.position * -2; for (int i = 0; i < 12; i++) { Vector3 a, b; diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index e2ede41290..9f55f0c364 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -693,6 +693,7 @@ void ArrayMesh::add_surface(uint32_t p_format, PrimitiveType p_primitive, const Surface s; s.aabb = p_aabb; surfaces.push_back(s); + _recompute_aabb(); VisualServer::get_singleton()->mesh_add_surface(mesh, p_format, (VS::PrimitiveType)p_primitive, p_array, p_vertex_count, p_index_array, p_index_count, p_aabb, p_blend_shapes, p_bone_aabbs); } @@ -719,7 +720,7 @@ void ArrayMesh::add_surface_from_arrays(PrimitiveType p_primitive, const Array & for (int i = 0; i < len; i++) { if (i == 0) - aabb.pos = vtx[i]; + aabb.position = vtx[i]; else aabb.expand_to(vtx[i]); } @@ -882,7 +883,7 @@ void ArrayMesh::add_surface_from_mesh_data(const Geometry::MeshData &p_mesh_data for (int i = 0; i < p_mesh_data.vertices.size(); i++) { if (i == 0) - aabb.pos = p_mesh_data.vertices[i]; + aabb.position = p_mesh_data.vertices[i]; else aabb.expand_to(p_mesh_data.vertices[i]); } diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index a1e0c95dd9..0b8ad5536c 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -1781,6 +1781,10 @@ float GradientTexture::get_offset(int pos) const { return 0; //TODO: Maybe throw some error instead? } +Ref<Image> GradientTexture::get_data() const { + return VisualServer::get_singleton()->texture_get_data(texture); +} + void GradientTexture::set_color(int pos, const Color &color) { if (points.size() <= pos) { points.resize(pos + 1); diff --git a/scene/resources/texture.h b/scene/resources/texture.h index 07416529ae..9ee9588d2b 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -539,6 +539,8 @@ public: return pointFirst.color.linear_interpolate(pointSecond.color, (p_offset - pointFirst.offset) / (pointSecond.offset - pointFirst.offset)); } + virtual Ref<Image> get_data() const; + int get_points_count() const; GradientTexture(); diff --git a/servers/physics/collision_object_sw.cpp b/servers/physics/collision_object_sw.cpp index 5eb10a4d09..dc0b2fc84f 100644 --- a/servers/physics/collision_object_sw.cpp +++ b/servers/physics/collision_object_sw.cpp @@ -164,7 +164,7 @@ void CollisionObjectSW::_update_shapes_with_motion(const Vector3 &p_motion) { Rect3 shape_aabb = s.shape->get_aabb(); Transform xform = transform * s.xform; shape_aabb = xform.xform(shape_aabb); - shape_aabb = shape_aabb.merge(Rect3(shape_aabb.pos + p_motion, shape_aabb.size)); //use motion + shape_aabb = shape_aabb.merge(Rect3(shape_aabb.position + p_motion, shape_aabb.size)); //use motion s.aabb_cache = shape_aabb; space->get_broadphase()->move(s.bpid, shape_aabb); diff --git a/servers/physics/collision_solver_sw.cpp b/servers/physics/collision_solver_sw.cpp index 38ce31ec78..32a42bcaf4 100644 --- a/servers/physics/collision_solver_sw.cpp +++ b/servers/physics/collision_solver_sw.cpp @@ -166,7 +166,7 @@ bool CollisionSolverSW::solve_concave(const ShapeSW *p_shape_A, const Transform smin *= axis_scale; smax *= axis_scale; - local_aabb.pos[i] = smin; + local_aabb.position[i] = smin; local_aabb.size[i] = smax - smin; } @@ -332,7 +332,7 @@ bool CollisionSolverSW::solve_distance(const ShapeSW *p_shape_A, const Transform Rect3 cc_hint_aabb; if (use_cc_hint) { cc_hint_aabb = p_concave_hint; - cc_hint_aabb.pos -= p_transform_B.origin; + cc_hint_aabb.position -= p_transform_B.origin; } Rect3 local_aabb; @@ -353,7 +353,7 @@ bool CollisionSolverSW::solve_distance(const ShapeSW *p_shape_A, const Transform smin *= axis_scale; smax *= axis_scale; - local_aabb.pos[i] = smin; + local_aabb.position[i] = smin; local_aabb.size[i] = smax - smin; } diff --git a/servers/physics/shape_sw.cpp b/servers/physics/shape_sw.cpp index ff7b442442..7b3df37a63 100644 --- a/servers/physics/shape_sw.cpp +++ b/servers/physics/shape_sw.cpp @@ -757,7 +757,7 @@ void ConvexPolygonShapeSW::_setup(const Vector<Vector3> &p_vertices) { for (int i = 0; i < mesh.vertices.size(); i++) { if (i == 0) - _aabb.pos = mesh.vertices[i]; + _aabb.position = mesh.vertices[i]; else _aabb.expand_to(mesh.vertices[i]); } @@ -1388,7 +1388,7 @@ void ConcavePolygonShapeSW::_setup(PoolVector<Vector3> p_faces) { Face3 face(facesr[i * 3 + 0], facesr[i * 3 + 1], facesr[i * 3 + 2]); bvh_arrayw[i].aabb = face.get_aabb(); - bvh_arrayw[i].center = bvh_arrayw[i].aabb.pos + bvh_arrayw[i].aabb.size * 0.5; + bvh_arrayw[i].center = bvh_arrayw[i].aabb.position + bvh_arrayw[i].aabb.size * 0.5; bvh_arrayw[i].face_index = i; facesw[i].indices[0] = i * 3 + 0; facesw[i].indices[1] = i * 3 + 1; @@ -1504,7 +1504,7 @@ void HeightMapShapeSW::_setup(PoolVector<real_t> p_heights, int p_width, int p_d Vector3 pos(j * cell_size, h, i * cell_size); if (i == 0 || j == 0) - aabb.pos = pos; + aabb.position = pos; else aabb.expand_to(pos); } diff --git a/servers/physics/space_sw.cpp b/servers/physics/space_sw.cpp index a4bf857bd8..16562dce6b 100644 --- a/servers/physics/space_sw.cpp +++ b/servers/physics/space_sw.cpp @@ -180,7 +180,7 @@ bool PhysicsDirectSpaceStateSW::cast_motion(const RID &p_shape, const Transform ERR_FAIL_COND_V(!shape, false); Rect3 aabb = p_xform.xform(shape->get_aabb()); - aabb = aabb.merge(Rect3(aabb.pos + p_motion, aabb.size)); //motion + aabb = aabb.merge(Rect3(aabb.position + p_motion, aabb.size)); //motion aabb = aabb.grow(p_margin); /* diff --git a/servers/server_wrap_mt_common.h b/servers/server_wrap_mt_common.h index f6b78e8f40..d434a6622e 100644 --- a/servers/server_wrap_mt_common.h +++ b/servers/server_wrap_mt_common.h @@ -41,8 +41,9 @@ } #define FUNCRID(m_type) \ + List<RID> m_type##_id_pool; \ int m_type##allocn() { \ - for (int i = 0; i < m_type##_pool_max_size; i++) { \ + for (int i = 0; i < pool_max_size; i++) { \ m_type##_id_pool.push_back(server_name->m_type##_create()); \ } \ return 0; \ @@ -747,3 +748,21 @@ server_name->m_type(p1, p2, p3, p4, p5, p6, p7, p8); \ } \ } + +#define FUNC9(m_type, m_arg1, m_arg2, m_arg3, m_arg4, m_arg5, m_arg6, m_arg7, m_arg8, m_arg9) \ + virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4, m_arg5 p5, m_arg6 p6, m_arg7 p7, m_arg8 p8, m_arg9 p9) { \ + if (Thread::get_caller_ID() != server_thread) { \ + command_queue.push(server_name, &ServerName::m_type, p1, p2, p3, p4, p5, p6, p7, p8, p9); \ + } else { \ + server_name->m_type(p1, p2, p3, p4, p5, p6, p7, p8, p9); \ + } \ + } + +#define FUNC10(m_type, m_arg1, m_arg2, m_arg3, m_arg4, m_arg5, m_arg6, m_arg7, m_arg8, m_arg9, m_arg10) \ + virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4, m_arg5 p5, m_arg6 p6, m_arg7 p7, m_arg8 p8, m_arg9 p9, m_arg10 p10) { \ + if (Thread::get_caller_ID() != server_thread) { \ + command_queue.push(server_name, &ServerName::m_type, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); \ + } else { \ + server_name->m_type(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); \ + } \ + } diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 9dfb0b2e71..eb06c64c40 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -155,6 +155,7 @@ public: virtual void render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, InstanceBase **p_cull_result, int p_cull_count) = 0; virtual void set_scene_pass(uint64_t p_pass) = 0; + virtual void set_debug_draw_mode(VS::ViewportDebugDraw p_debug_draw) = 0; virtual bool free(RID p_rid) = 0; @@ -468,6 +469,7 @@ public: enum RenderTargetFlags { RENDER_TARGET_VFLIP, RENDER_TARGET_TRANSPARENT, + RENDER_TARGET_NO_3D_EFFECTS, RENDER_TARGET_NO_3D, RENDER_TARGET_NO_SAMPLING, RENDER_TARGET_HDR, @@ -497,6 +499,14 @@ public: virtual void update_dirty_resources() = 0; + virtual void set_debug_generate_wireframes(bool p_generate) = 0; + + virtual void render_info_begin_capture() = 0; + virtual void render_info_end_capture() = 0; + virtual int get_captured_render_info(VS::RenderInfo p_info) = 0; + + virtual int get_render_info(VS::RenderInfo p_info) = 0; + static RasterizerStorage *base_singleton; RasterizerStorage(); virtual ~RasterizerStorage() {} @@ -812,7 +822,7 @@ public: const Item::CommandMesh *mesh = static_cast<const Item::CommandMesh *>(c); Rect3 aabb = RasterizerStorage::base_singleton->mesh_get_aabb(mesh->mesh, mesh->skeleton); - r = Rect2(aabb.pos.x, aabb.pos.y, aabb.size.x, aabb.size.y); + r = Rect2(aabb.position.x, aabb.position.y, aabb.size.x, aabb.size.y); } break; case Item::Command::TYPE_MULTIMESH: { @@ -820,7 +830,7 @@ public: const Item::CommandMultiMesh *multimesh = static_cast<const Item::CommandMultiMesh *>(c); Rect3 aabb = RasterizerStorage::base_singleton->multimesh_get_aabb(multimesh->multimesh); - r = Rect2(aabb.pos.x, aabb.pos.y, aabb.size.x, aabb.size.y); + r = Rect2(aabb.position.x, aabb.position.y, aabb.size.x, aabb.size.y); } break; case Item::Command::TYPE_CIRCLE: { diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index 2fdff29f0a..8d332b3e6c 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -74,6 +74,19 @@ void VisualServerRaster::free(RID p_rid) { /* EVENT QUEUING */ +void VisualServerRaster::request_frame_drawn_callback(Object *p_where, const StringName &p_method, const Variant &p_userdata) { + + ERR_FAIL_NULL(p_where); + FrameDrawnCallbacks fdc; + fdc.object = p_where->get_instance_ID(); + fdc.method = p_method; + fdc.param = p_userdata; + + frame_drawn_callbacks.push_back(fdc); + + print_line("added callback to draw"); +} + void VisualServerRaster::draw() { /* @@ -92,6 +105,22 @@ void VisualServerRaster::draw() { //_draw_cursors_and_margins(); VSG::rasterizer->end_frame(); //draw_extra_frame=VS:rasterizer->needs_to_draw_next_frame(); + + while (frame_drawn_callbacks.front()) { + + Object *obj = ObjectDB::get_instance(frame_drawn_callbacks.front()->get().object); + if (obj) { + Variant::CallError ce; + const Variant *v = &frame_drawn_callbacks.front()->get().param; + obj->call(frame_drawn_callbacks.front()->get().method, &v, 1, ce); + if (ce.error != Variant::CallError::CALL_OK) { + String err = Variant::get_call_error_text(obj, frame_drawn_callbacks.front()->get().method, &v, 1, ce); + ERR_PRINTS("Error calling frame drawn function: " + err); + } + } + + frame_drawn_callbacks.pop_front(); + } } void VisualServerRaster::sync() { } @@ -116,7 +145,7 @@ void VisualServerRaster::finish() { int VisualServerRaster::get_render_info(RenderInfo p_info) { - return 0; + return VSG::storage->get_render_info(p_info); } /* TESTING */ @@ -146,6 +175,11 @@ bool VisualServerRaster::has_os_feature(const String &p_feature) const { return VSG::storage->has_os_feature(p_feature); } +void VisualServerRaster::set_debug_generate_wireframes(bool p_generate) { + + VSG::storage->set_debug_generate_wireframes(p_generate); +} + VisualServerRaster::VisualServerRaster() { VSG::canvas = memnew(VisualServerCanvas); diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 8c311300ad..b4b43a31be 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -61,6 +61,15 @@ class VisualServerRaster : public VisualServer { bool draw_extra_frame; RID test_cube; + struct FrameDrawnCallbacks { + + ObjectID object; + StringName method; + Variant param; + }; + + List<FrameDrawnCallbacks> frame_drawn_callbacks; + #if 0 struct Room { @@ -586,6 +595,8 @@ public: m_r m_name(m_type1 arg1) { return BINDBASE->m_name(arg1); } #define BIND1RC(m_r, m_name, m_type1) \ m_r m_name(m_type1 arg1) const { return BINDBASE->m_name(arg1); } +#define BIND2R(m_r, m_name, m_type1, m_type2) \ + m_r m_name(m_type1 arg1, m_type2 arg2) { return BINDBASE->m_name(arg1, arg2); } #define BIND2RC(m_r, m_name, m_type1, m_type2) \ m_r m_name(m_type1 arg1, m_type2 arg2) const { return BINDBASE->m_name(arg1, arg2); } #define BIND3RC(m_r, m_name, m_type1, m_type2, m_type3) \ @@ -632,7 +643,6 @@ public: BIND1RC(uint32_t, texture_get_width, RID) BIND1RC(uint32_t, texture_get_height, RID) BIND3(texture_set_size_override, RID, int, int) - BIND2RC(RID, texture_create_radiance_cubemap, RID, int) BIND3(texture_set_detect_3d_callback, RID, TextureDetectCallback, void *) BIND3(texture_set_detect_srgb_callback, RID, TextureDetectCallback, void *) @@ -922,6 +932,10 @@ public: BIND3(viewport_set_shadow_atlas_quadrant_subdivision, RID, int, int) BIND2(viewport_set_msaa, RID, ViewportMSAA) BIND2(viewport_set_hdr, RID, bool) + BIND2(viewport_set_usage, RID, ViewportUsage) + + BIND2R(int, viewport_get_render_info, RID, ViewportRenderInfo) + BIND2(viewport_set_debug_draw, RID, ViewportDebugDraw) /* ENVIRONMENT API */ @@ -944,7 +958,6 @@ public: BIND6(environment_set_dof_blur_near, RID, bool, float, float, float, EnvironmentDOFBlurQuality) BIND6(environment_set_dof_blur_far, RID, bool, float, float, float, EnvironmentDOFBlurQuality) BIND10(environment_set_glow, RID, bool, int, float, float, float, EnvironmentGlowBlendMode, float, float, bool) - BIND5(environment_set_fog, RID, bool, float, float, RID) BIND9(environment_set_tonemap, RID, EnvironmentToneMapper, float, float, bool, float, float, float, float) @@ -1100,6 +1113,8 @@ public: /* EVENT QUEUING */ + virtual void request_frame_drawn_callback(Object *p_where, const StringName &p_method, const Variant &p_userdata); + virtual void draw(); virtual void sync(); virtual bool has_changed() const; @@ -1120,6 +1135,7 @@ public: virtual bool has_feature(Features p_feature) const; virtual bool has_os_feature(const String &p_feature) const; + virtual void set_debug_generate_wireframes(bool p_generate); VisualServerRaster(); ~VisualServerRaster(); diff --git a/servers/visual/visual_server_viewport.cpp b/servers/visual/visual_server_viewport.cpp index c1f1922255..a99b890601 100644 --- a/servers/visual/visual_server_viewport.cpp +++ b/servers/visual/visual_server_viewport.cpp @@ -88,7 +88,7 @@ void VisualServerViewport::_draw_viewport(Viewport *p_viewport) { } } - if (!p_viewport->disable_3d && p_viewport->camera.is_valid()) { + if (!p_viewport->disable_3d && !p_viewport->disable_3d_by_usage && p_viewport->camera.is_valid()) { VSG::scene->render_camera(p_viewport->camera, p_viewport->scenario, p_viewport->size, p_viewport->shadow_atlas); } @@ -272,8 +272,20 @@ void VisualServerViewport::draw_viewports() { continue; VSG::rasterizer->set_current_render_target(vp->render_target); + + VSG::scene_render->set_debug_draw_mode(vp->debug_draw); + VSG::storage->render_info_begin_capture(); + _draw_viewport(vp); + VSG::storage->render_info_end_capture(); + vp->render_info[VS::VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME] = VSG::storage->get_captured_render_info(VS::INFO_OBJECTS_IN_FRAME); + vp->render_info[VS::VIEWPORT_RENDER_INFO_VERTICES_IN_FRAME] = VSG::storage->get_captured_render_info(VS::INFO_VERTICES_IN_FRAME); + vp->render_info[VS::VIEWPORT_RENDER_INFO_MATERIAL_CHANGES_IN_FRAME] = VSG::storage->get_captured_render_info(VS::INFO_MATERIAL_CHANGES_IN_FRAME); + vp->render_info[VS::VIEWPORT_RENDER_INFO_SHADER_CHANGES_IN_FRAME] = VSG::storage->get_captured_render_info(VS::INFO_SHADER_CHANGES_IN_FRAME); + vp->render_info[VS::VIEWPORT_RENDER_INFO_SURFACE_CHANGES_IN_FRAME] = VSG::storage->get_captured_render_info(VS::INFO_SURFACE_CHANGES_IN_FRAME); + vp->render_info[VS::VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME] = VSG::storage->get_captured_render_info(VS::INFO_DRAW_CALLS_IN_FRAME); + if (vp->viewport_to_screen_rect != Rect2()) { //copy to screen if set as such VSG::rasterizer->set_current_render_target(RID()); @@ -283,6 +295,7 @@ void VisualServerViewport::draw_viewports() { if (vp->update_mode == VS::VIEWPORT_UPDATE_ONCE) { vp->update_mode = VS::VIEWPORT_UPDATE_DISABLED; } + VSG::scene_render->set_debug_draw_mode(VS::VIEWPORT_DEBUG_DRAW_DISABLED); } } @@ -409,7 +422,8 @@ void VisualServerViewport::viewport_set_disable_3d(RID p_viewport, bool p_disabl ERR_FAIL_COND(!viewport); viewport->disable_3d = p_disable; - VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D, p_disable); + //VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D, p_disable); + //this should be just for disabling rendering of 3D, to actually disable it, set usage } void VisualServerViewport::viewport_attach_camera(RID p_viewport, RID p_camera) { @@ -518,6 +532,63 @@ void VisualServerViewport::viewport_set_hdr(RID p_viewport, bool p_enabled) { VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_HDR, p_enabled); } +void VisualServerViewport::viewport_set_usage(RID p_viewport, VS::ViewportUsage p_usage) { + + Viewport *viewport = viewport_owner.getornull(p_viewport); + ERR_FAIL_COND(!viewport); + + switch (p_usage) { + case VS::VIEWPORT_USAGE_2D: { + + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D, true); + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D_EFFECTS, true); + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_SAMPLING, false); + + viewport->disable_3d_by_usage = true; + } break; + case VS::VIEWPORT_USAGE_2D_NO_SAMPLING: { + + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D, true); + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D_EFFECTS, true); + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_SAMPLING, true); + viewport->disable_3d_by_usage = true; + } break; + case VS::VIEWPORT_USAGE_3D: { + + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D, false); + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D_EFFECTS, false); + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_SAMPLING, false); + viewport->disable_3d_by_usage = false; + } break; + case VS::VIEWPORT_USAGE_3D_NO_EFFECTS: { + + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D, false); + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D_EFFECTS, true); + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_SAMPLING, false); + viewport->disable_3d_by_usage = false; + } break; + } +} + +int VisualServerViewport::viewport_get_render_info(RID p_viewport, VS::ViewportRenderInfo p_info) { + + ERR_FAIL_INDEX_V(p_info, VS::VIEWPORT_RENDER_INFO_MAX, -1); + + Viewport *viewport = viewport_owner.getornull(p_viewport); + if (!viewport) + return 0; //there should be a lock here.. + + return viewport->render_info[p_info]; +} + +void VisualServerViewport::viewport_set_debug_draw(RID p_viewport, VS::ViewportDebugDraw p_draw) { + + Viewport *viewport = viewport_owner.getornull(p_viewport); + ERR_FAIL_COND(!viewport); + + viewport->debug_draw = p_draw; +} + bool VisualServerViewport::free(RID p_rid) { if (viewport_owner.owns(p_rid)) { diff --git a/servers/visual/visual_server_viewport.h b/servers/visual/visual_server_viewport.h index 118d11a111..4d46e39b77 100644 --- a/servers/visual/visual_server_viewport.h +++ b/servers/visual/visual_server_viewport.h @@ -59,10 +59,14 @@ public: bool hide_canvas; bool disable_environment; bool disable_3d; + bool disable_3d_by_usage; RID shadow_atlas; int shadow_atlas_size; + int render_info[VS::VIEWPORT_RENDER_INFO_MAX]; + VS::ViewportDebugDraw debug_draw; + VS::ViewportClearMode clear_mode; bool rendered_in_prev_frame; @@ -101,6 +105,11 @@ public: viewport_to_screen = 0; shadow_atlas_size = 0; disable_3d = false; + disable_3d_by_usage = false; + debug_draw = VS::VIEWPORT_DEBUG_DRAW_DISABLED; + for (int i = 0; i < VS::VIEWPORT_RENDER_INFO_MAX; i++) { + render_info[i] = 0; + } } }; @@ -164,6 +173,10 @@ public: void viewport_set_msaa(RID p_viewport, VS::ViewportMSAA p_msaa); void viewport_set_hdr(RID p_viewport, bool p_enabled); + void viewport_set_usage(RID p_viewport, VS::ViewportUsage p_usage); + + virtual int viewport_get_render_info(RID p_viewport, VS::ViewportRenderInfo p_info); + virtual void viewport_set_debug_draw(RID p_viewport, VS::ViewportDebugDraw p_draw); void draw_viewports(); diff --git a/servers/visual/visual_server_wrap_mt.cpp b/servers/visual/visual_server_wrap_mt.cpp new file mode 100644 index 0000000000..fd15633244 --- /dev/null +++ b/servers/visual/visual_server_wrap_mt.cpp @@ -0,0 +1,193 @@ +/*************************************************************************/ +/* visual_server_wrap_mt.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "visual_server_wrap_mt.h" +#include "global_config.h" +#include "os/os.h" + +void VisualServerWrapMT::thread_exit() { + + exit = true; +} + +void VisualServerWrapMT::thread_draw() { + + draw_mutex->lock(); + + draw_pending--; + bool draw = (draw_pending == 0); // only draw when no more flushes are pending + + draw_mutex->unlock(); + + if (draw) { + + visual_server->draw(); + } +} + +void VisualServerWrapMT::thread_flush() { + + draw_mutex->lock(); + + draw_pending--; + + draw_mutex->unlock(); +} + +void VisualServerWrapMT::_thread_callback(void *_instance) { + + VisualServerWrapMT *vsmt = reinterpret_cast<VisualServerWrapMT *>(_instance); + + vsmt->thread_loop(); +} + +void VisualServerWrapMT::thread_loop() { + + server_thread = Thread::get_caller_ID(); + + OS::get_singleton()->make_rendering_thread(); + + visual_server->init(); + + exit = false; + draw_thread_up = true; + while (!exit) { + // flush commands one by one, until exit is requested + command_queue.wait_and_flush_one(); + } + + command_queue.flush_all(); // flush all + + visual_server->finish(); +} + +/* EVENT QUEUING */ + +void VisualServerWrapMT::sync() { + + if (create_thread) { + + /* TODO: sync with the thread */ + + /* + ERR_FAIL_COND(!draw_mutex); + draw_mutex->lock(); + draw_pending++; //cambiar por un saferefcount + draw_mutex->unlock(); + */ + //command_queue.push( this, &VisualServerWrapMT::thread_flush); + } else { + + command_queue.flush_all(); //flush all pending from other threads + } +} + +void VisualServerWrapMT::draw() { + + if (create_thread) { + + /* TODO: Make it draw + ERR_FAIL_COND(!draw_mutex); + draw_mutex->lock(); + draw_pending++; //cambiar por un saferefcount + draw_mutex->unlock(); + + command_queue.push( this, &VisualServerWrapMT::thread_draw); + */ + } else { + + visual_server->draw(); + } +} + +void VisualServerWrapMT::init() { + + if (create_thread) { + + draw_mutex = Mutex::create(); + print_line("CREATING RENDER THREAD"); + OS::get_singleton()->release_rendering_thread(); + if (create_thread) { + thread = Thread::create(_thread_callback, this); + print_line("STARTING RENDER THREAD"); + } + while (!draw_thread_up) { + OS::get_singleton()->delay_usec(1000); + } + print_line("DONE RENDER THREAD"); + } else { + + visual_server->init(); + } +} + +void VisualServerWrapMT::finish() { + + if (thread) { + + command_queue.push(this, &VisualServerWrapMT::thread_exit); + Thread::wait_to_finish(thread); + memdelete(thread); + + texture_free_cached_ids(); + //mesh_free_cached_ids(); + + thread = NULL; + } else { + visual_server->finish(); + } + + if (draw_mutex) + memdelete(draw_mutex); +} + +VisualServerWrapMT::VisualServerWrapMT(VisualServer *p_contained, bool p_create_thread) + : command_queue(p_create_thread) { + + visual_server = p_contained; + create_thread = p_create_thread; + thread = NULL; + draw_mutex = NULL; + draw_pending = 0; + draw_thread_up = false; + alloc_mutex = Mutex::create(); + pool_max_size = GLOBAL_DEF("memory/servers/thread_rid_prealloc_amount", 20); + + if (!p_create_thread) { + server_thread = Thread::get_caller_ID(); + } else { + server_thread = 0; + } +} + +VisualServerWrapMT::~VisualServerWrapMT() { + + memdelete(visual_server); + memdelete(alloc_mutex); + //finish(); +} diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h new file mode 100644 index 0000000000..407a4fd32b --- /dev/null +++ b/servers/visual/visual_server_wrap_mt.h @@ -0,0 +1,583 @@ +/*************************************************************************/ +/* visual_server_wrap_mt.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef VISUAL_SERVER_WRAP_MT_H +#define VISUAL_SERVER_WRAP_MT_H + +#include "command_queue_mt.h" +#include "os/thread.h" +#include "servers/visual_server.h" + +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ +class VisualServerWrapMT : public VisualServer { + + // the real visual server + mutable VisualServer *visual_server; + + mutable CommandQueueMT command_queue; + + static void _thread_callback(void *_instance); + void thread_loop(); + + Thread::ID server_thread; + volatile bool exit; + Thread *thread; + volatile bool draw_thread_up; + bool create_thread; + + Mutex *draw_mutex; + int draw_pending; + void thread_draw(); + void thread_flush(); + + void thread_exit(); + + Mutex *alloc_mutex; + + int pool_max_size; + +//#define DEBUG_SYNC + +#ifdef DEBUG_SYNC +#define SYNC_DEBUG print_line("sync on: " + String(__FUNCTION__)); +#else +#define SYNC_DEBUG +#endif + +public: +#define ServerName VisualServer +#define ServerNameWrapMT VisualServerWrapMT +#define server_name visual_server +#include "servers/server_wrap_mt_common.h" + + /* EVENT QUEUING */ + FUNCRID(texture) + FUNC5(texture_allocate, RID, int, int, Image::Format, uint32_t) + FUNC3(texture_set_data, RID, const Ref<Image> &, CubeMapSide) + FUNC2RC(Ref<Image>, texture_get_data, RID, CubeMapSide) + FUNC2(texture_set_flags, RID, uint32_t) + FUNC1RC(uint32_t, texture_get_flags, RID) + FUNC1RC(Image::Format, texture_get_format, RID) + FUNC1RC(uint32_t, texture_get_texid, RID) + FUNC1RC(uint32_t, texture_get_width, RID) + FUNC1RC(uint32_t, texture_get_height, RID) + FUNC3(texture_set_size_override, RID, int, int) + + FUNC3(texture_set_detect_3d_callback, RID, TextureDetectCallback, void *) + FUNC3(texture_set_detect_srgb_callback, RID, TextureDetectCallback, void *) + + FUNC2(texture_set_path, RID, const String &) + FUNC1RC(String, texture_get_path, RID) + FUNC1(texture_set_shrink_all_x2_on_set_data, bool) + FUNC1(texture_debug_usage, List<TextureInfo> *) + + FUNC1(textures_keep_original, bool) + + /* SKY API */ + + FUNC0R(RID, sky_create) + FUNC3(sky_set_texture, RID, RID, int) + + /* SHADER API */ + + FUNC0R(RID, shader_create) + + FUNC2(shader_set_code, RID, const String &) + FUNC1RC(String, shader_get_code, RID) + + FUNC2C(shader_get_param_list, RID, List<PropertyInfo> *) + + FUNC3(shader_set_default_texture_param, RID, const StringName &, RID) + FUNC2RC(RID, shader_get_default_texture_param, RID, const StringName &) + + /* COMMON MATERIAL API */ + + FUNC0R(RID, material_create) + + FUNC2(material_set_shader, RID, RID) + FUNC1RC(RID, material_get_shader, RID) + + FUNC3(material_set_param, RID, const StringName &, const Variant &) + FUNC2RC(Variant, material_get_param, RID, const StringName &) + + FUNC2(material_set_line_width, RID, float) + + /* MESH API */ + + FUNC0R(RID, mesh_create) + + FUNC10(mesh_add_surface, RID, uint32_t, PrimitiveType, const PoolVector<uint8_t> &, int, const PoolVector<uint8_t> &, int, const Rect3 &, const Vector<PoolVector<uint8_t> > &, const Vector<Rect3> &) + + FUNC2(mesh_set_blend_shape_count, RID, int) + FUNC1RC(int, mesh_get_blend_shape_count, RID) + + FUNC2(mesh_set_blend_shape_mode, RID, BlendShapeMode) + FUNC1RC(BlendShapeMode, mesh_get_blend_shape_mode, RID) + + FUNC3(mesh_surface_set_material, RID, int, RID) + FUNC2RC(RID, mesh_surface_get_material, RID, int) + + FUNC2RC(int, mesh_surface_get_array_len, RID, int) + FUNC2RC(int, mesh_surface_get_array_index_len, RID, int) + + FUNC2RC(PoolVector<uint8_t>, mesh_surface_get_array, RID, int) + FUNC2RC(PoolVector<uint8_t>, mesh_surface_get_index_array, RID, int) + + FUNC2RC(uint32_t, mesh_surface_get_format, RID, int) + FUNC2RC(PrimitiveType, mesh_surface_get_primitive_type, RID, int) + + FUNC2RC(Rect3, mesh_surface_get_aabb, RID, int) + FUNC2RC(Vector<PoolVector<uint8_t> >, mesh_surface_get_blend_shapes, RID, int) + FUNC2RC(Vector<Rect3>, mesh_surface_get_skeleton_aabb, RID, int) + + FUNC2(mesh_remove_surface, RID, int) + FUNC1RC(int, mesh_get_surface_count, RID) + + FUNC2(mesh_set_custom_aabb, RID, const Rect3 &) + FUNC1RC(Rect3, mesh_get_custom_aabb, RID) + + FUNC1(mesh_clear, RID) + + /* MULTIMESH API */ + + FUNC0R(RID, multimesh_create) + + FUNC4(multimesh_allocate, RID, int, MultimeshTransformFormat, MultimeshColorFormat) + FUNC1RC(int, multimesh_get_instance_count, RID) + + FUNC2(multimesh_set_mesh, RID, RID) + FUNC3(multimesh_instance_set_transform, RID, int, const Transform &) + FUNC3(multimesh_instance_set_transform_2d, RID, int, const Transform2D &) + FUNC3(multimesh_instance_set_color, RID, int, const Color &) + + FUNC1RC(RID, multimesh_get_mesh, RID) + FUNC1RC(Rect3, multimesh_get_aabb, RID) + + FUNC2RC(Transform, multimesh_instance_get_transform, RID, int) + FUNC2RC(Transform2D, multimesh_instance_get_transform_2d, RID, int) + FUNC2RC(Color, multimesh_instance_get_color, RID, int) + + FUNC2(multimesh_set_visible_instances, RID, int) + FUNC1RC(int, multimesh_get_visible_instances, RID) + + /* IMMEDIATE API */ + + FUNC0R(RID, immediate_create) + FUNC3(immediate_begin, RID, PrimitiveType, RID) + FUNC2(immediate_vertex, RID, const Vector3 &) + FUNC2(immediate_normal, RID, const Vector3 &) + FUNC2(immediate_tangent, RID, const Plane &) + FUNC2(immediate_color, RID, const Color &) + FUNC2(immediate_uv, RID, const Vector2 &) + FUNC2(immediate_uv2, RID, const Vector2 &) + FUNC1(immediate_end, RID) + FUNC1(immediate_clear, RID) + FUNC2(immediate_set_material, RID, RID) + FUNC1RC(RID, immediate_get_material, RID) + + /* SKELETON API */ + + FUNC0R(RID, skeleton_create) + FUNC3(skeleton_allocate, RID, int, bool) + FUNC1RC(int, skeleton_get_bone_count, RID) + FUNC3(skeleton_bone_set_transform, RID, int, const Transform &) + FUNC2RC(Transform, skeleton_bone_get_transform, RID, int) + FUNC3(skeleton_bone_set_transform_2d, RID, int, const Transform2D &) + FUNC2RC(Transform2D, skeleton_bone_get_transform_2d, RID, int) + + /* Light API */ + + FUNC1R(RID, light_create, LightType) + + FUNC2(light_set_color, RID, const Color &) + FUNC3(light_set_param, RID, LightParam, float) + FUNC2(light_set_shadow, RID, bool) + FUNC2(light_set_shadow_color, RID, const Color &) + FUNC2(light_set_projector, RID, RID) + FUNC2(light_set_negative, RID, bool) + FUNC2(light_set_cull_mask, RID, uint32_t) + + FUNC2(light_omni_set_shadow_mode, RID, LightOmniShadowMode) + FUNC2(light_omni_set_shadow_detail, RID, LightOmniShadowDetail) + + FUNC2(light_directional_set_shadow_mode, RID, LightDirectionalShadowMode) + FUNC2(light_directional_set_blend_splits, RID, bool) + + /* PROBE API */ + + FUNC0R(RID, reflection_probe_create) + + FUNC2(reflection_probe_set_update_mode, RID, ReflectionProbeUpdateMode) + FUNC2(reflection_probe_set_intensity, RID, float) + FUNC2(reflection_probe_set_interior_ambient, RID, const Color &) + FUNC2(reflection_probe_set_interior_ambient_energy, RID, float) + FUNC2(reflection_probe_set_interior_ambient_probe_contribution, RID, float) + FUNC2(reflection_probe_set_max_distance, RID, float) + FUNC2(reflection_probe_set_extents, RID, const Vector3 &) + FUNC2(reflection_probe_set_origin_offset, RID, const Vector3 &) + FUNC2(reflection_probe_set_as_interior, RID, bool) + FUNC2(reflection_probe_set_enable_box_projection, RID, bool) + FUNC2(reflection_probe_set_enable_shadows, RID, bool) + FUNC2(reflection_probe_set_cull_mask, RID, uint32_t) + + /* ROOM API */ + + FUNC0R(RID, room_create) + FUNC4(room_add_bounds, RID, const PoolVector<Vector2> &, float, const Transform &) + FUNC1(room_clear_bounds, RID) + + /* PORTAL API */ + + // portals are only (x/y) points, forming a convex shape, which its clockwise + // order points outside. (z is 0); + + FUNC0R(RID, portal_create) + FUNC2(portal_set_shape, RID, const Vector<Point2> &) + FUNC2(portal_set_enabled, RID, bool) + FUNC2(portal_set_disable_distance, RID, float) + FUNC2(portal_set_disabled_color, RID, const Color &) + + /* BAKED LIGHT API */ + + FUNC0R(RID, gi_probe_create) + + FUNC2(gi_probe_set_bounds, RID, const Rect3 &) + FUNC1RC(Rect3, gi_probe_get_bounds, RID) + + FUNC2(gi_probe_set_cell_size, RID, float) + FUNC1RC(float, gi_probe_get_cell_size, RID) + + FUNC2(gi_probe_set_to_cell_xform, RID, const Transform &) + FUNC1RC(Transform, gi_probe_get_to_cell_xform, RID) + + FUNC2(gi_probe_set_dynamic_range, RID, int) + FUNC1RC(int, gi_probe_get_dynamic_range, RID) + + FUNC2(gi_probe_set_energy, RID, float) + FUNC1RC(float, gi_probe_get_energy, RID) + + FUNC2(gi_probe_set_bias, RID, float) + FUNC1RC(float, gi_probe_get_bias, RID) + + FUNC2(gi_probe_set_propagation, RID, float) + FUNC1RC(float, gi_probe_get_propagation, RID) + + FUNC2(gi_probe_set_interior, RID, bool) + FUNC1RC(bool, gi_probe_is_interior, RID) + + FUNC2(gi_probe_set_compress, RID, bool) + FUNC1RC(bool, gi_probe_is_compressed, RID) + + FUNC2(gi_probe_set_dynamic_data, RID, const PoolVector<int> &) + FUNC1RC(PoolVector<int>, gi_probe_get_dynamic_data, RID) + + /* PARTICLES */ + + FUNC0R(RID, particles_create) + + FUNC2(particles_set_emitting, RID, bool) + FUNC2(particles_set_amount, RID, int) + FUNC2(particles_set_lifetime, RID, float) + FUNC2(particles_set_pre_process_time, RID, float) + FUNC2(particles_set_explosiveness_ratio, RID, float) + FUNC2(particles_set_randomness_ratio, RID, float) + FUNC2(particles_set_custom_aabb, RID, const Rect3 &) + FUNC2(particles_set_speed_scale, RID, float) + FUNC2(particles_set_use_local_coordinates, RID, bool) + FUNC2(particles_set_process_material, RID, RID) + FUNC2(particles_set_fixed_fps, RID, int) + FUNC2(particles_set_fractional_delta, RID, bool) + + FUNC2(particles_set_draw_order, RID, VS::ParticlesDrawOrder) + + FUNC2(particles_set_draw_passes, RID, int) + FUNC3(particles_set_draw_pass_mesh, RID, int, RID) + + FUNC1R(Rect3, particles_get_current_aabb, RID) + + /* CAMERA API */ + + FUNC0R(RID, camera_create) + FUNC4(camera_set_perspective, RID, float, float, float) + FUNC4(camera_set_orthogonal, RID, float, float, float) + FUNC2(camera_set_transform, RID, const Transform &) + FUNC2(camera_set_cull_mask, RID, uint32_t) + FUNC2(camera_set_environment, RID, RID) + FUNC2(camera_set_use_vertical_aspect, RID, bool) + + /* VIEWPORT TARGET API */ + + FUNC0R(RID, viewport_create) + + FUNC3(viewport_set_size, RID, int, int) + + FUNC2(viewport_set_active, RID, bool) + FUNC2(viewport_set_parent_viewport, RID, RID) + + FUNC2(viewport_set_clear_mode, RID, ViewportClearMode) + + FUNC3(viewport_attach_to_screen, RID, const Rect2 &, int) + FUNC1(viewport_detach, RID) + + FUNC2(viewport_set_update_mode, RID, ViewportUpdateMode) + FUNC2(viewport_set_vflip, RID, bool) + + FUNC1RC(RID, viewport_get_texture, RID) + + FUNC2(viewport_set_hide_scenario, RID, bool) + FUNC2(viewport_set_hide_canvas, RID, bool) + FUNC2(viewport_set_disable_environment, RID, bool) + FUNC2(viewport_set_disable_3d, RID, bool) + + FUNC2(viewport_attach_camera, RID, RID) + FUNC2(viewport_set_scenario, RID, RID) + FUNC2(viewport_attach_canvas, RID, RID) + + FUNC2(viewport_remove_canvas, RID, RID) + FUNC3(viewport_set_canvas_transform, RID, RID, const Transform2D &) + FUNC2(viewport_set_transparent_background, RID, bool) + + FUNC2(viewport_set_global_canvas_transform, RID, const Transform2D &) + FUNC3(viewport_set_canvas_layer, RID, RID, int) + FUNC2(viewport_set_shadow_atlas_size, RID, int) + FUNC3(viewport_set_shadow_atlas_quadrant_subdivision, RID, int, int) + FUNC2(viewport_set_msaa, RID, ViewportMSAA) + FUNC2(viewport_set_hdr, RID, bool) + FUNC2(viewport_set_usage, RID, ViewportUsage) + + //this passes directly to avoid stalling, but it's pretty dangerous, so dont call after freeing a viewport + virtual int viewport_get_render_info(RID p_viewport, ViewportRenderInfo p_info) { + visual_server->viewport_get_render_info(p_viewport, p_info); + } + + FUNC2(viewport_set_debug_draw, RID, ViewportDebugDraw) + + /* ENVIRONMENT API */ + + FUNC0R(RID, environment_create) + + FUNC2(environment_set_background, RID, EnvironmentBG) + FUNC2(environment_set_sky, RID, RID) + FUNC2(environment_set_sky_scale, RID, float) + FUNC2(environment_set_bg_color, RID, const Color &) + FUNC2(environment_set_bg_energy, RID, float) + FUNC2(environment_set_canvas_max_layer, RID, int) + FUNC4(environment_set_ambient_light, RID, const Color &, float, float) + FUNC8(environment_set_ssr, RID, bool, int, float, float, float, bool, bool) + FUNC10(environment_set_ssao, RID, bool, float, float, float, float, float, float, const Color &, bool) + + FUNC6(environment_set_dof_blur_near, RID, bool, float, float, float, EnvironmentDOFBlurQuality) + FUNC6(environment_set_dof_blur_far, RID, bool, float, float, float, EnvironmentDOFBlurQuality) + FUNC10(environment_set_glow, RID, bool, int, float, float, float, EnvironmentGlowBlendMode, float, float, bool) + + FUNC9(environment_set_tonemap, RID, EnvironmentToneMapper, float, float, bool, float, float, float, float) + + FUNC6(environment_set_adjustment, RID, bool, float, float, float, RID) + + FUNC5(environment_set_fog, RID, bool, const Color &, const Color &, float) + FUNC6(environment_set_fog_depth, RID, bool, float, float, bool, float) + FUNC5(environment_set_fog_height, RID, bool, float, float, float) + + FUNC0R(RID, scenario_create) + + FUNC2(scenario_set_debug, RID, ScenarioDebugMode) + FUNC2(scenario_set_environment, RID, RID) + FUNC3(scenario_set_reflection_atlas_size, RID, int, int) + FUNC2(scenario_set_fallback_environment, RID, RID) + + /* INSTANCING API */ + // from can be mesh, light, area and portal so far. + FUNC0R(RID, instance_create) + + FUNC2(instance_set_base, RID, RID) // from can be mesh, light, poly, area and portal so far. + FUNC2(instance_set_scenario, RID, RID) // from can be mesh, light, poly, area and portal so far. + FUNC2(instance_set_layer_mask, RID, uint32_t) + FUNC2(instance_set_transform, RID, const Transform &) + FUNC2(instance_attach_object_instance_ID, RID, ObjectID) + FUNC3(instance_set_blend_shape_weight, RID, int, float) + FUNC3(instance_set_surface_material, RID, int, RID) + FUNC2(instance_set_visible, RID, bool) + + FUNC2(instance_attach_skeleton, RID, RID) + FUNC2(instance_set_exterior, RID, bool) + FUNC2(instance_set_room, RID, RID) + + FUNC2(instance_set_extra_visibility_margin, RID, real_t) + + // don't use these in a game! + FUNC2RC(Vector<ObjectID>, instances_cull_aabb, const Rect3 &, RID) + FUNC3RC(Vector<ObjectID>, instances_cull_ray, const Vector3 &, const Vector3 &, RID) + FUNC2RC(Vector<ObjectID>, instances_cull_convex, const Vector<Plane> &, RID) + + FUNC3(instance_geometry_set_flag, RID, InstanceFlags, bool) + FUNC2(instance_geometry_set_cast_shadows_setting, RID, ShadowCastingSetting) + FUNC2(instance_geometry_set_material_override, RID, RID) + + FUNC5(instance_geometry_set_draw_range, RID, float, float, float, float) + FUNC2(instance_geometry_set_as_instance_lod, RID, RID) + + /* CANVAS (2D) */ + + FUNC0R(RID, canvas_create) + FUNC3(canvas_set_item_mirroring, RID, RID, const Point2 &) + FUNC2(canvas_set_modulate, RID, const Color &) + + FUNC0R(RID, canvas_item_create) + FUNC2(canvas_item_set_parent, RID, RID) + + FUNC2(canvas_item_set_visible, RID, bool) + FUNC2(canvas_item_set_light_mask, RID, int) + + FUNC2(canvas_item_set_transform, RID, const Transform2D &) + FUNC2(canvas_item_set_clip, RID, bool) + FUNC2(canvas_item_set_distance_field_mode, RID, bool) + FUNC3(canvas_item_set_custom_rect, RID, bool, const Rect2 &) + FUNC2(canvas_item_set_modulate, RID, const Color &) + FUNC2(canvas_item_set_self_modulate, RID, const Color &) + + FUNC2(canvas_item_set_draw_behind_parent, RID, bool) + + FUNC6(canvas_item_add_line, RID, const Point2 &, const Point2 &, const Color &, float, bool) + FUNC3(canvas_item_add_rect, RID, const Rect2 &, const Color &) + FUNC4(canvas_item_add_circle, RID, const Point2 &, float, const Color &) + FUNC6(canvas_item_add_texture_rect, RID, const Rect2 &, RID, bool, const Color &, bool) + FUNC6(canvas_item_add_texture_rect_region, RID, const Rect2 &, RID, const Rect2 &, const Color &, bool) + FUNC10(canvas_item_add_nine_patch, RID, const Rect2 &, const Rect2 &, RID, const Vector2 &, const Vector2 &, NinePatchAxisMode, NinePatchAxisMode, bool, const Color &) + FUNC6(canvas_item_add_primitive, RID, const Vector<Point2> &, const Vector<Color> &, const Vector<Point2> &, RID, float) + FUNC5(canvas_item_add_polygon, RID, const Vector<Point2> &, const Vector<Color> &, const Vector<Point2> &, RID) + FUNC7(canvas_item_add_triangle_array, RID, const Vector<int> &, const Vector<Point2> &, const Vector<Color> &, const Vector<Point2> &, RID, int) + FUNC3(canvas_item_add_mesh, RID, const RID &, RID) + FUNC3(canvas_item_add_multimesh, RID, RID, RID) + FUNC2(canvas_item_add_set_transform, RID, const Transform2D &) + FUNC2(canvas_item_add_clip_ignore, RID, bool) + FUNC2(canvas_item_set_sort_children_by_y, RID, bool) + FUNC2(canvas_item_set_z, RID, int) + FUNC2(canvas_item_set_z_as_relative_to_parent, RID, bool) + FUNC3(canvas_item_set_copy_to_backbuffer, RID, bool, const Rect2 &) + + FUNC1(canvas_item_clear, RID) + FUNC2(canvas_item_set_draw_index, RID, int) + + FUNC2(canvas_item_set_material, RID, RID) + + FUNC2(canvas_item_set_use_parent_material, RID, bool) + + FUNC0R(RID, canvas_light_create) + FUNC2(canvas_light_attach_to_canvas, RID, RID) + FUNC2(canvas_light_set_enabled, RID, bool) + FUNC2(canvas_light_set_scale, RID, float) + FUNC2(canvas_light_set_transform, RID, const Transform2D &) + FUNC2(canvas_light_set_texture, RID, RID) + FUNC2(canvas_light_set_texture_offset, RID, const Vector2 &) + FUNC2(canvas_light_set_color, RID, const Color &) + FUNC2(canvas_light_set_height, RID, float) + FUNC2(canvas_light_set_energy, RID, float) + FUNC3(canvas_light_set_z_range, RID, int, int) + FUNC3(canvas_light_set_layer_range, RID, int, int) + FUNC2(canvas_light_set_item_cull_mask, RID, int) + FUNC2(canvas_light_set_item_shadow_cull_mask, RID, int) + + FUNC2(canvas_light_set_mode, RID, CanvasLightMode) + + FUNC2(canvas_light_set_shadow_enabled, RID, bool) + FUNC2(canvas_light_set_shadow_buffer_size, RID, int) + FUNC2(canvas_light_set_shadow_gradient_length, RID, float) + FUNC2(canvas_light_set_shadow_filter, RID, CanvasLightShadowFilter) + FUNC2(canvas_light_set_shadow_color, RID, const Color &) + + FUNC0R(RID, canvas_light_occluder_create) + FUNC2(canvas_light_occluder_attach_to_canvas, RID, RID) + FUNC2(canvas_light_occluder_set_enabled, RID, bool) + FUNC2(canvas_light_occluder_set_polygon, RID, RID) + FUNC2(canvas_light_occluder_set_transform, RID, const Transform2D &) + FUNC2(canvas_light_occluder_set_light_mask, RID, int) + + FUNC0R(RID, canvas_occluder_polygon_create) + FUNC3(canvas_occluder_polygon_set_shape, RID, const PoolVector<Vector2> &, bool) + FUNC2(canvas_occluder_polygon_set_shape_as_lines, RID, const PoolVector<Vector2> &) + + FUNC2(canvas_occluder_polygon_set_cull_mode, RID, CanvasOccluderPolygonCullMode) + + /* CURSOR */ + FUNC2(cursor_set_rotation, float, int) // radians + FUNC4(cursor_set_texture, RID, const Point2 &, int, const Rect2 &) + FUNC2(cursor_set_visible, bool, int) + FUNC2(cursor_set_pos, const Point2 &, int) + + /* BLACK BARS */ + + FUNC4(black_bars_set_margins, int, int, int, int) + FUNC4(black_bars_set_images, RID, RID, RID, RID) + + /* FREE */ + + FUNC1(free, RID) + + /* EVENT QUEUING */ + + FUNC3(request_frame_drawn_callback, Object *, const StringName &, const Variant &) + + virtual void init(); + virtual void finish(); + virtual void draw(); + virtual void sync(); + FUNC0RC(bool, has_changed) + + /* RENDER INFO */ + + //this passes directly to avoid stalling + virtual int get_render_info(RenderInfo p_info) { + visual_server->get_render_info(p_info); + } + + FUNC3(set_boot_image, const Ref<Image> &, const Color &, bool) + FUNC1(set_default_clear_color, const Color &) + + FUNC0R(RID, get_test_cube) + + FUNC1(set_debug_generate_wireframes, bool) + + virtual bool has_feature(Features p_feature) const { return visual_server->has_feature(p_feature); } + virtual bool has_os_feature(const String &p_feature) const { return visual_server->has_os_feature(p_feature); } + + VisualServerWrapMT(VisualServer *p_contained, bool p_create_thread); + ~VisualServerWrapMT(); + +#undef ServerName +#undef ServerNameWrapMT +#undef server_name +}; + +#ifdef DEBUG_SYNC +#undef DEBUG_SYNC +#endif +#undef SYNC_DEBUG + +#endif diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index 498b7dcc43..2f53465d11 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -770,7 +770,7 @@ Error VisualServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint32_ if (bptr->size.x < 0) { //first bptr[idx] = Rect3(); - bptr[idx].pos = v; + bptr[idx].position = v; any_valid = true; } else { bptr[idx].expand_to(v); diff --git a/servers/visual_server.h b/servers/visual_server.h index 3d5ca9d99a..3290a460a1 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -579,7 +579,38 @@ public: }; virtual void viewport_set_msaa(RID p_viewport, ViewportMSAA p_msaa) = 0; + + enum ViewportUsage { + VIEWPORT_USAGE_2D, + VIEWPORT_USAGE_2D_NO_SAMPLING, + VIEWPORT_USAGE_3D, + VIEWPORT_USAGE_3D_NO_EFFECTS, + }; + virtual void viewport_set_hdr(RID p_viewport, bool p_enabled) = 0; + virtual void viewport_set_usage(RID p_viewport, ViewportUsage p_usage) = 0; + + enum ViewportRenderInfo { + + VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME, + VIEWPORT_RENDER_INFO_VERTICES_IN_FRAME, + VIEWPORT_RENDER_INFO_MATERIAL_CHANGES_IN_FRAME, + VIEWPORT_RENDER_INFO_SHADER_CHANGES_IN_FRAME, + VIEWPORT_RENDER_INFO_SURFACE_CHANGES_IN_FRAME, + VIEWPORT_RENDER_INFO_DRAW_CALLS_IN_FRAME, + VIEWPORT_RENDER_INFO_MAX + }; + + virtual int viewport_get_render_info(RID p_viewport, ViewportRenderInfo p_info) = 0; + + enum ViewportDebugDraw { + VIEWPORT_DEBUG_DRAW_DISABLED, + VIEWPORT_DEBUG_DRAW_UNSHADED, + VIEWPORT_DEBUG_DRAW_OVERDRAW, + VIEWPORT_DEBUG_DRAW_WIREFRAME, + }; + + virtual void viewport_set_debug_draw(RID p_viewport, ViewportDebugDraw p_draw) = 0; /* ENVIRONMENT API */ @@ -623,7 +654,6 @@ public: GLOW_BLEND_MODE_REPLACE, }; virtual void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_treshold, EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_treshold, float p_hdr_bleed_scale, bool p_bicubic_upscale) = 0; - virtual void environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture) = 0; enum EnvironmentToneMapper { ENV_TONE_MAPPER_LINEAR, @@ -848,6 +878,8 @@ public: virtual void free(RID p_rid) = 0; ///< free RIDs associated with the visual server + virtual void request_frame_drawn_callback(Object *p_where, const StringName &p_method, const Variant &p_userdata) = 0; + /* EVENT QUEUING */ virtual void draw() = 0; @@ -902,6 +934,8 @@ public: virtual bool has_os_feature(const String &p_feature) const = 0; + virtual void set_debug_generate_wireframes(bool p_generate) = 0; + VisualServer(); virtual ~VisualServer(); }; |