diff options
Diffstat (limited to 'modules')
22 files changed, 598 insertions, 38 deletions
diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp index da895a6d6..71593ebfa 100644 --- a/modules/dds/texture_loader_dds.cpp +++ b/modules/dds/texture_loader_dds.cpp @@ -76,8 +76,6 @@ static const DDSFormatInfo dds_format_info[DDS_MAX] = { { "DXT1", true, false, 4, 8, Image::FORMAT_DXT1 }, { "DXT3", true, false, 4, 16, Image::FORMAT_DXT3 }, { "DXT5", true, false, 4, 16, Image::FORMAT_DXT5 }, - { "ATI1", true, false, 4, 8, Image::FORMAT_LATC_L }, - { "ATI2", true, false, 4, 16, Image::FORMAT_LATC_LA }, { "BGRA8", false, false, 1, 4, Image::FORMAT_RGBA8 }, { "BGR8", false, false, 1, 3, Image::FORMAT_RGB8 }, { "RGBA8", false, false, 1, 4, Image::FORMAT_RGBA8 }, diff --git a/modules/gdnative/godot/godot_array.cpp b/modules/gdnative/godot/godot_array.cpp index bf2ef3597..8cf6d1b8e 100644 --- a/modules/gdnative/godot/godot_array.cpp +++ b/modules/gdnative/godot/godot_array.cpp @@ -49,6 +49,12 @@ void GDAPI godot_array_new(godot_array *p_arr) { memnew_placement(a, Array); } +void GDAPI godot_array_new_copy(godot_array *p_dest, const godot_array *p_src) { + Array *dest = (Array *)p_dest; + const Array *src = (const Array *)p_src; + memnew_placement(dest, Array(*src)); +} + void GDAPI godot_array_new_pool_color_array(godot_array *p_arr, const godot_pool_color_array *p_pca) { Array *a = (Array *)p_arr; PoolVector<Color> *pca = (PoolVector<Color> *)p_pca; diff --git a/modules/gdnative/godot/godot_array.h b/modules/gdnative/godot/godot_array.h index f7150950f..5db0031b8 100644 --- a/modules/gdnative/godot/godot_array.h +++ b/modules/gdnative/godot/godot_array.h @@ -49,6 +49,7 @@ typedef struct godot_array { #include "../godot.h" void GDAPI godot_array_new(godot_array *p_arr); +void GDAPI godot_array_new_copy(godot_array *p_dest, const godot_array *p_src); void GDAPI godot_array_new_pool_color_array(godot_array *p_arr, const godot_pool_color_array *p_pca); void GDAPI godot_array_new_pool_vector3_array(godot_array *p_arr, const godot_pool_vector3_array *p_pv3a); void GDAPI godot_array_new_pool_vector2_array(godot_array *p_arr, const godot_pool_vector2_array *p_pv2a); diff --git a/modules/gdnative/godot/godot_dictionary.cpp b/modules/gdnative/godot/godot_dictionary.cpp index b98ee5b5c..deec5f8ff 100644 --- a/modules/gdnative/godot/godot_dictionary.cpp +++ b/modules/gdnative/godot/godot_dictionary.cpp @@ -44,6 +44,12 @@ void GDAPI godot_dictionary_new(godot_dictionary *r_dest) { memnew_placement(dest, Dictionary); } +void GDAPI godot_dictionary_new_copy(godot_dictionary *r_dest, const godot_dictionary *r_src) { + Dictionary *dest = (Dictionary *)r_dest; + const Dictionary *src = (const Dictionary *)r_src; + memnew_placement(dest, Dictionary(*src)); +} + void GDAPI godot_dictionary_destroy(godot_dictionary *p_self) { Dictionary *self = (Dictionary *)p_self; self->~Dictionary(); diff --git a/modules/gdnative/godot/godot_dictionary.h b/modules/gdnative/godot/godot_dictionary.h index 42f7f872a..a89bd4bba 100644 --- a/modules/gdnative/godot/godot_dictionary.h +++ b/modules/gdnative/godot/godot_dictionary.h @@ -48,6 +48,7 @@ typedef struct godot_dictionary { #include "godot_variant.h" void GDAPI godot_dictionary_new(godot_dictionary *r_dest); +void GDAPI godot_dictionary_new_copy(godot_dictionary *r_dest, const godot_dictionary *r_src); void GDAPI godot_dictionary_destroy(godot_dictionary *p_self); godot_int GDAPI godot_dictionary_size(const godot_dictionary *p_self); diff --git a/modules/gdnative/godot/godot_pool_arrays.cpp b/modules/gdnative/godot/godot_pool_arrays.cpp index 10d5d6d93..ff4586ebe 100644 --- a/modules/gdnative/godot/godot_pool_arrays.cpp +++ b/modules/gdnative/godot/godot_pool_arrays.cpp @@ -49,6 +49,12 @@ void GDAPI godot_pool_byte_array_new(godot_pool_byte_array *p_pba) { memnew_placement(pba, PoolVector<uint8_t>); } +void GDAPI godot_pool_byte_array_new_copy(godot_pool_byte_array *p_dest, const godot_pool_byte_array *p_src) { + PoolVector<uint8_t> *dest = (PoolVector<uint8_t> *)p_dest; + const PoolVector<uint8_t> *src = (const PoolVector<uint8_t> *)p_src; + memnew_placement(dest, PoolVector<uint8_t>(*src)); +} + void GDAPI godot_pool_byte_array_new_with_array(godot_pool_byte_array *p_pba, const godot_array *p_a) { PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; Array *a = (Array *)p_a; @@ -118,14 +124,20 @@ void GDAPI godot_pool_byte_array_destroy(godot_pool_byte_array *p_pba) { // int void GDAPI godot_pool_int_array_new(godot_pool_int_array *p_pba) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; - memnew_placement(pba, PoolVector<uint8_t>); + PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; + memnew_placement(pba, PoolVector<godot_int>); +} + +void GDAPI godot_pool_int_array_new_copy(godot_pool_int_array *p_dest, const godot_pool_int_array *p_src) { + PoolVector<godot_int> *dest = (PoolVector<godot_int> *)p_dest; + const PoolVector<godot_int> *src = (const PoolVector<godot_int> *)p_src; + memnew_placement(dest, PoolVector<godot_int>(*src)); } void GDAPI godot_pool_int_array_new_with_array(godot_pool_int_array *p_pba, const godot_array *p_a) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; Array *a = (Array *)p_a; - memnew_placement(pba, PoolVector<uint8_t>); + memnew_placement(pba, PoolVector<godot_int>); pba->resize(a->size()); for (size_t i = 0; i < a->size(); i++) { @@ -191,14 +203,20 @@ void GDAPI godot_pool_int_array_destroy(godot_pool_int_array *p_pba) { // real void GDAPI godot_pool_real_array_new(godot_pool_real_array *p_pba) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; - memnew_placement(pba, PoolVector<uint8_t>); + PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; + memnew_placement(pba, PoolVector<godot_real>); +} + +void GDAPI godot_pool_real_array_new_copy(godot_pool_real_array *p_dest, const godot_pool_real_array *p_src) { + PoolVector<godot_real> *dest = (PoolVector<godot_real> *)p_dest; + const PoolVector<godot_real> *src = (const PoolVector<godot_real> *)p_src; + memnew_placement(dest, PoolVector<godot_real>(*src)); } void GDAPI godot_pool_real_array_new_with_array(godot_pool_real_array *p_pba, const godot_array *p_a) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; Array *a = (Array *)p_a; - memnew_placement(pba, PoolVector<uint8_t>); + memnew_placement(pba, PoolVector<godot_real>); pba->resize(a->size()); for (size_t i = 0; i < a->size(); i++) { @@ -268,6 +286,12 @@ void GDAPI godot_pool_string_array_new(godot_pool_string_array *p_pba) { memnew_placement(pba, PoolVector<String>); } +void GDAPI godot_pool_string_array_new_copy(godot_pool_string_array *p_dest, const godot_pool_string_array *p_src) { + PoolVector<String> *dest = (PoolVector<String> *)p_dest; + const PoolVector<String> *src = (const PoolVector<String> *)p_src; + memnew_placement(dest, PoolVector<String>(*src)); +} + void GDAPI godot_pool_string_array_new_with_array(godot_pool_string_array *p_pba, const godot_array *p_a) { PoolVector<String> *pba = (PoolVector<String> *)p_pba; Array *a = (Array *)p_a; @@ -349,6 +373,12 @@ void GDAPI godot_pool_vector2_array_new(godot_pool_vector2_array *p_pba) { memnew_placement(pba, PoolVector<Vector2>); } +void GDAPI godot_pool_vector2_array_new_copy(godot_pool_vector2_array *p_dest, const godot_pool_vector2_array *p_src) { + PoolVector<Vector2> *dest = (PoolVector<Vector2> *)p_dest; + const PoolVector<Vector2> *src = (const PoolVector<Vector2> *)p_src; + memnew_placement(dest, PoolVector<Vector2>(*src)); +} + void GDAPI godot_pool_vector2_array_new_with_array(godot_pool_vector2_array *p_pba, const godot_array *p_a) { PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; Array *a = (Array *)p_a; @@ -429,6 +459,12 @@ void GDAPI godot_pool_vector3_array_new(godot_pool_vector3_array *p_pba) { memnew_placement(pba, PoolVector<Vector3>); } +void GDAPI godot_pool_vector3_array_new_copy(godot_pool_vector3_array *p_dest, const godot_pool_vector3_array *p_src) { + PoolVector<Vector3> *dest = (PoolVector<Vector3> *)p_dest; + const PoolVector<Vector3> *src = (const PoolVector<Vector3> *)p_src; + memnew_placement(dest, PoolVector<Vector3>(*src)); +} + void GDAPI godot_pool_vector3_array_new_with_array(godot_pool_vector3_array *p_pba, const godot_array *p_a) { PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; Array *a = (Array *)p_a; @@ -509,6 +545,12 @@ void GDAPI godot_pool_color_array_new(godot_pool_color_array *p_pba) { memnew_placement(pba, PoolVector<Color>); } +void GDAPI godot_pool_color_array_new_copy(godot_pool_color_array *p_dest, const godot_pool_color_array *p_src) { + PoolVector<Color> *dest = (PoolVector<Color> *)p_dest; + const PoolVector<Color> *src = (const PoolVector<Color> *)p_src; + memnew_placement(dest, PoolVector<Color>(*src)); +} + void GDAPI godot_pool_color_array_new_with_array(godot_pool_color_array *p_pba, const godot_array *p_a) { PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; Array *a = (Array *)p_a; diff --git a/modules/gdnative/godot/godot_pool_arrays.h b/modules/gdnative/godot/godot_pool_arrays.h index 015be65c3..8b0d0137f 100644 --- a/modules/gdnative/godot/godot_pool_arrays.h +++ b/modules/gdnative/godot/godot_pool_arrays.h @@ -102,6 +102,7 @@ typedef struct godot_pool_color_array { // byte void GDAPI godot_pool_byte_array_new(godot_pool_byte_array *p_pba); +void GDAPI godot_pool_byte_array_new_copy(godot_pool_byte_array *p_dest, const godot_pool_byte_array *p_src); void GDAPI godot_pool_byte_array_new_with_array(godot_pool_byte_array *p_pba, const godot_array *p_a); void GDAPI godot_pool_byte_array_append(godot_pool_byte_array *p_pba, const uint8_t p_data); @@ -128,6 +129,7 @@ void GDAPI godot_pool_byte_array_destroy(godot_pool_byte_array *p_pba); // int void GDAPI godot_pool_int_array_new(godot_pool_int_array *p_pia); +void GDAPI godot_pool_int_array_new_copy(godot_pool_int_array *p_dest, const godot_pool_int_array *p_src); void GDAPI godot_pool_int_array_new_with_array(godot_pool_int_array *p_pia, const godot_array *p_a); void GDAPI godot_pool_int_array_append(godot_pool_int_array *p_pia, const godot_int p_data); @@ -154,6 +156,7 @@ void GDAPI godot_pool_int_array_destroy(godot_pool_int_array *p_pia); // real void GDAPI godot_pool_real_array_new(godot_pool_real_array *p_pra); +void GDAPI godot_pool_real_array_new_copy(godot_pool_real_array *p_dest, const godot_pool_real_array *p_src); void GDAPI godot_pool_real_array_new_with_array(godot_pool_real_array *p_pra, const godot_array *p_a); void GDAPI godot_pool_real_array_append(godot_pool_real_array *p_pra, const godot_real p_data); @@ -180,6 +183,7 @@ void GDAPI godot_pool_real_array_destroy(godot_pool_real_array *p_pra); // string void GDAPI godot_pool_string_array_new(godot_pool_string_array *p_psa); +void GDAPI godot_pool_string_array_new_copy(godot_pool_string_array *p_dest, const godot_pool_string_array *p_src); void GDAPI godot_pool_string_array_new_with_array(godot_pool_string_array *p_psa, const godot_array *p_a); void GDAPI godot_pool_string_array_append(godot_pool_string_array *p_psa, const godot_string *p_data); @@ -206,6 +210,7 @@ void GDAPI godot_pool_string_array_destroy(godot_pool_string_array *p_psa); // vector2 void GDAPI godot_pool_vector2_array_new(godot_pool_vector2_array *p_pv2a); +void GDAPI godot_pool_vector2_array_new_copy(godot_pool_vector2_array *p_dest, const godot_pool_vector2_array *p_src); void GDAPI godot_pool_vector2_array_new_with_array(godot_pool_vector2_array *p_pv2a, const godot_array *p_a); void GDAPI godot_pool_vector2_array_append(godot_pool_vector2_array *p_pv2a, const godot_vector2 *p_data); @@ -232,6 +237,7 @@ void GDAPI godot_pool_vector2_array_destroy(godot_pool_vector2_array *p_pv2a); // vector3 void GDAPI godot_pool_vector3_array_new(godot_pool_vector3_array *p_pv3a); +void GDAPI godot_pool_vector3_array_new_copy(godot_pool_vector3_array *p_dest, const godot_pool_vector3_array *p_src); void GDAPI godot_pool_vector3_array_new_with_array(godot_pool_vector3_array *p_pv3a, const godot_array *p_a); void GDAPI godot_pool_vector3_array_append(godot_pool_vector3_array *p_pv3a, const godot_vector3 *p_data); @@ -258,6 +264,7 @@ void GDAPI godot_pool_vector3_array_destroy(godot_pool_vector3_array *p_pv3a); // color void GDAPI godot_pool_color_array_new(godot_pool_color_array *p_pca); +void GDAPI godot_pool_color_array_new_copy(godot_pool_color_array *p_dest, const godot_pool_color_array *p_src); void GDAPI godot_pool_color_array_new_with_array(godot_pool_color_array *p_pca, const godot_array *p_a); void GDAPI godot_pool_color_array_append(godot_pool_color_array *p_pca, const godot_color *p_data); diff --git a/modules/gdnative/godot/godot_rect2.cpp b/modules/gdnative/godot/godot_rect2.cpp index eea95ca6f..0e456ea3b 100644 --- a/modules/gdnative/godot/godot_rect2.cpp +++ b/modules/gdnative/godot/godot_rect2.cpp @@ -38,11 +38,11 @@ extern "C" { void _rect2_api_anchor() {} -void GDAPI godot_rect2_new_with_pos_and_size(godot_rect2 *r_dest, const godot_vector2 *p_pos, const godot_vector2 *p_size) { - const Vector2 *pos = (const Vector2 *)p_pos; +void GDAPI godot_rect2_new_with_position_and_size(godot_rect2 *r_dest, const godot_vector2 *p_pos, const godot_vector2 *p_size) { + const Vector2 *position = (const Vector2 *)p_pos; const Vector2 *size = (const Vector2 *)p_size; Rect2 *dest = (Rect2 *)r_dest; - *dest = Rect2(*pos, *size); + *dest = Rect2(*position, *size); } void GDAPI godot_rect2_new(godot_rect2 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_width, const godot_real p_height) { @@ -124,11 +124,11 @@ godot_bool GDAPI godot_rect2_operator_equal(const godot_rect2 *p_self, const god return *self == *b; } -godot_vector2 GDAPI godot_rect2_get_pos(const godot_rect2 *p_self) { +godot_vector2 GDAPI godot_rect2_get_position(const godot_rect2 *p_self) { godot_vector2 dest; Vector2 *d = (Vector2 *)&dest; const Rect2 *self = (const Rect2 *)p_self; - *d = self->get_pos(); + *d = self->get_position(); return dest; } @@ -140,10 +140,10 @@ godot_vector2 GDAPI godot_rect2_get_size(const godot_rect2 *p_self) { return dest; } -void GDAPI godot_rect2_set_pos(godot_rect2 *p_self, const godot_vector2 *p_pos) { +void GDAPI godot_rect2_set_position(godot_rect2 *p_self, const godot_vector2 *p_pos) { Rect2 *self = (Rect2 *)p_self; - const Vector2 *pos = (const Vector2 *)p_pos; - self->set_pos(*pos); + const Vector2 *position = (const Vector2 *)p_pos; + self->set_position(*position); } void GDAPI godot_rect2_set_size(godot_rect2 *p_self, const godot_vector2 *p_size) { diff --git a/modules/gdnative/godot/godot_rect2.h b/modules/gdnative/godot/godot_rect2.h index 9743321a3..488a1204f 100644 --- a/modules/gdnative/godot/godot_rect2.h +++ b/modules/gdnative/godot/godot_rect2.h @@ -46,7 +46,7 @@ typedef struct godot_rect2 { #include "../godot.h" #include "godot_vector2.h" -void GDAPI godot_rect2_new_with_pos_and_size(godot_rect2 *r_dest, const godot_vector2 *p_pos, const godot_vector2 *p_size); +void GDAPI godot_rect2_new_with_position_and_size(godot_rect2 *r_dest, const godot_vector2 *p_pos, const godot_vector2 *p_size); void GDAPI godot_rect2_new(godot_rect2 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_width, const godot_real p_height); godot_string GDAPI godot_rect2_as_string(const godot_rect2 *p_self); @@ -71,11 +71,11 @@ godot_rect2 GDAPI godot_rect2_expand(const godot_rect2 *p_self, const godot_vect godot_bool GDAPI godot_rect2_operator_equal(const godot_rect2 *p_self, const godot_rect2 *p_b); -godot_vector2 GDAPI godot_rect2_get_pos(const godot_rect2 *p_self); +godot_vector2 GDAPI godot_rect2_get_position(const godot_rect2 *p_self); godot_vector2 GDAPI godot_rect2_get_size(const godot_rect2 *p_self); -void GDAPI godot_rect2_set_pos(godot_rect2 *p_self, const godot_vector2 *p_pos); +void GDAPI godot_rect2_set_position(godot_rect2 *p_self, const godot_vector2 *p_pos); void GDAPI godot_rect2_set_size(godot_rect2 *p_self, const godot_vector2 *p_size); diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index e567e08c7..121b403f6 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -560,7 +560,7 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu else return false; - return do_input_action(p_camera, Point2(mb->get_pos().x, mb->get_pos().y), true); + return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true); } else { if ( @@ -604,7 +604,7 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu if (mm.is_valid()) { - return do_input_action(p_camera, mm->get_pos(), false); + return do_input_action(p_camera, mm->get_position(), false); } } else if (edit_mode->get_selected() == 1) { @@ -616,7 +616,7 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { - Point2 point = mb->get_pos(); + Point2 point = mb->get_position(); Camera *camera = p_camera; Vector3 from = camera->project_ray_origin(point); diff --git a/modules/hdr/image_loader_hdr.cpp b/modules/hdr/image_loader_hdr.cpp index 85819104c..19df27b96 100644 --- a/modules/hdr/image_loader_hdr.cpp +++ b/modules/hdr/image_loader_hdr.cpp @@ -131,7 +131,7 @@ Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force //convert for (int i = 0; i < width * height; i++) { - float exp = pow(2, ptr[3] - 128); + float exp = pow(2.0f, ptr[3] - 128.0f); Color c( ptr[0] * exp / 255.0, diff --git a/modules/hdr/image_loader_hdr.h b/modules/hdr/image_loader_hdr.h index 9bc1fadd1..127833ebd 100644 --- a/modules/hdr/image_loader_hdr.h +++ b/modules/hdr/image_loader_hdr.h @@ -27,8 +27,8 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef IMAGE_LOADER_TINYEXR_H -#define IMAGE_LOADER_TINYEXR_H +#ifndef IMAGE_LOADER_HDR_H +#define IMAGE_LOADER_HDR_H #include "io/image_loader.h" diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp index 2427dac8a..e927f1cea 100644 --- a/modules/squish/image_compress_squish.cpp +++ b/modules/squish/image_compress_squish.cpp @@ -59,9 +59,9 @@ void image_decompress_squish(Image *p_image) { squish_flags = squish::kDxt3; } else if (p_image->get_format() == Image::FORMAT_DXT5) { squish_flags = squish::kDxt5; - } else if (p_image->get_format() == Image::FORMAT_LATC_L || p_image->get_format() == Image::FORMAT_RGTC_R) { + } else if (p_image->get_format() == Image::FORMAT_RGTC_R) { squish_flags = squish::kBc4; - } else if (p_image->get_format() == Image::FORMAT_LATC_LA || p_image->get_format() == Image::FORMAT_RGTC_RG) { + } else if (p_image->get_format() == Image::FORMAT_RGTC_RG) { squish_flags = squish::kBc5; } else { ERR_FAIL_COND(true); @@ -79,7 +79,7 @@ void image_decompress_squish(Image *p_image) { p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data); } -void image_compress_squish(Image *p_image) { +void image_compress_squish(Image *p_image, bool p_srgb) { if (p_image->get_format() >= Image::FORMAT_DXT1) return; //do not compress, already compressed @@ -96,16 +96,21 @@ void image_compress_squish(Image *p_image) { p_image->convert(Image::FORMAT_RGBA8); //still uses RGBA to convert + if (p_srgb && (dc == Image::DETECTED_R || dc == Image::DETECTED_RG)) { + //R and RG do not support SRGB + dc = Image::DETECTED_RGB; + } + switch (dc) { case Image::DETECTED_L: { - target_format = Image::FORMAT_LATC_L; - squish_comp |= squish::kBc4; + target_format = Image::FORMAT_DXT1; + squish_comp |= squish::kDxt1; } break; case Image::DETECTED_LA: { - target_format = Image::FORMAT_LATC_LA; - squish_comp |= squish::kBc5; + target_format = Image::FORMAT_DXT5; + squish_comp |= squish::kDxt5; } break; case Image::DETECTED_R: { @@ -148,8 +153,8 @@ void image_compress_squish(Image *p_image) { int bh = h % 4 != 0 ? h + (4 - h % 4) : h; int src_ofs = p_image->get_mipmap_offset(i); - squish::CompressImage(&rb[src_ofs], bw, bh, &wb[dst_ofs], squish_comp); - dst_ofs += (MAX(4, w) * MAX(4, h)) >> shift; + squish::CompressImage(&rb[src_ofs], w, h, &wb[dst_ofs], squish_comp); + dst_ofs += (MAX(4, bw) * MAX(4, bh)) >> shift; w >>= 1; h >>= 1; } diff --git a/modules/squish/image_compress_squish.h b/modules/squish/image_compress_squish.h index 519e3537e..8d859b8e0 100644 --- a/modules/squish/image_compress_squish.h +++ b/modules/squish/image_compress_squish.h @@ -32,7 +32,7 @@ #include "image.h" -void image_compress_squish(Image *p_image); +void image_compress_squish(Image *p_image, bool p_srgb); void image_decompress_squish(Image *p_image); #endif // IMAGE_COMPRESS_SQUISH_H diff --git a/modules/tga/SCsub b/modules/tga/SCsub new file mode 100644 index 000000000..7e405f405 --- /dev/null +++ b/modules/tga/SCsub @@ -0,0 +1,9 @@ +#!/usr/bin/env python + +Import('env') +Import('env_modules') + +env_tga = env_modules.Clone() + +# Godot's own source files +env_tga.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/tga/config.py b/modules/tga/config.py new file mode 100644 index 000000000..fb920482f --- /dev/null +++ b/modules/tga/config.py @@ -0,0 +1,7 @@ + +def can_build(platform): + return True + + +def configure(env): + pass diff --git a/modules/tga/image_loader_tga.cpp b/modules/tga/image_loader_tga.cpp new file mode 100644 index 000000000..5b8610b97 --- /dev/null +++ b/modules/tga/image_loader_tga.cpp @@ -0,0 +1,314 @@ +/*************************************************************************/ +/* image_loader_jpegd.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "image_loader_tga.h" + +#include "os/os.h" +#include "print_string.h" + +Error ImageLoaderTGA::decode_tga_rle(const uint8_t *p_compressed_buffer, size_t p_pixel_size, uint8_t *p_uncompressed_buffer, size_t p_output_size) { + Error error; + + PoolVector<uint8_t> pixels; + error = pixels.resize(p_pixel_size); + if (error != OK) + return error; + + PoolVector<uint8_t>::Write pixels_w = pixels.write(); + + size_t compressed_pos = 0; + size_t output_pos = 0; + size_t c = 0; + size_t count = 0; + + while (output_pos < p_output_size) { + c = p_compressed_buffer[compressed_pos]; + compressed_pos += 1; + count = (c & 0x7f) + 1; + + if (c & 0x80) { + for (int i = 0; i < p_pixel_size; i++) { + pixels_w.ptr()[i] = p_compressed_buffer[compressed_pos]; + compressed_pos += 1; + } + for (int i = 0; i < count; i++) { + for (int j = 0; j < p_pixel_size; j++) { + p_uncompressed_buffer[output_pos + j] = pixels_w.ptr()[j]; + } + output_pos += p_pixel_size; + } + } else { + count *= p_pixel_size; + for (int i = 0; i < count; i++) { + p_uncompressed_buffer[output_pos] = p_compressed_buffer[compressed_pos]; + compressed_pos += 1; + output_pos += 1; + } + } + } + return OK; +} + +Error ImageLoaderTGA::convert_to_image(Ref<Image> p_image, const uint8_t *p_buffer, const tga_header_s &p_header, const uint8_t *p_palette, const bool p_is_monochrome) { + +#define TGA_PUT_PIXEL(r, g, b, a) \ + int image_data_ofs = ((y * width) + x); \ + image_data_w[image_data_ofs * 4 + 0] = r; \ + image_data_w[image_data_ofs * 4 + 1] = g; \ + image_data_w[image_data_ofs * 4 + 2] = b; \ + image_data_w[image_data_ofs * 4 + 3] = a; + + uint32_t width = p_header.image_width; + uint32_t height = p_header.image_height; + tga_origin_e origin = static_cast<tga_origin_e>((p_header.image_descriptor & TGA_ORIGIN_MASK) >> TGA_ORIGIN_SHIFT); + + uint32_t x_start; + int32_t x_step; + uint32_t x_end; + uint32_t y_start; + int32_t y_step; + uint32_t y_end; + + if (origin == TGA_ORIGIN_TOP_LEFT || origin == TGA_ORIGIN_TOP_RIGHT) { + y_start = 0; + y_step = 1; + y_end = height; + } else { + y_start = height - 1; + y_step = -1; + y_end = -1; + } + + if (origin == TGA_ORIGIN_TOP_LEFT || origin == TGA_ORIGIN_BOTTOM_LEFT) { + x_start = 0; + x_step = 1; + x_end = width; + } else { + x_start = width - 1; + x_step = -1; + x_end = -1; + } + + PoolVector<uint8_t> image_data; + image_data.resize(width * height * sizeof(uint32_t)); + PoolVector<uint8_t>::Write image_data_w = image_data.write(); + + size_t i = 0; + uint32_t x = x_start; + uint32_t y = y_start; + + if (p_header.pixel_depth == 8) { + if (p_is_monochrome) { + while (y != y_end) { + while (x != x_end) { + uint8_t shade = p_buffer[i]; + + TGA_PUT_PIXEL(shade, shade, shade, 0xff) + + x += x_step; + i += 1; + } + x = x_start; + y += y_step; + } + } else { + while (y != y_end) { + while (x != x_end) { + uint8_t index = p_buffer[i]; + uint8_t r = 0x00; + uint8_t g = 0x00; + uint8_t b = 0x00; + uint8_t a = 0xff; + + if (p_header.color_map_depth == 24) { + r = (p_palette[(index * 3) + 0]); + g = (p_palette[(index * 3) + 1]); + b = (p_palette[(index * 3) + 2]); + } else { + return ERR_INVALID_DATA; + } + + TGA_PUT_PIXEL(r, g, b, a) + + x += x_step; + i += 1; + } + x = x_start; + y += y_step; + } + } + } else if (p_header.pixel_depth == 24) { + while (y != y_end) { + while (x != x_end) { + uint8_t r = p_buffer[i + 2]; + uint8_t g = p_buffer[i + 1]; + uint8_t b = p_buffer[i + 0]; + + TGA_PUT_PIXEL(r, g, b, 0xff) + + x += x_step; + i += 3; + } + x = x_start; + y += y_step; + } + } else if (p_header.pixel_depth == 32) { + while (y != y_end) { + while (x != x_end) { + uint8_t a = p_buffer[i + 3]; + uint8_t r = p_buffer[i + 2]; + uint8_t g = p_buffer[i + 1]; + uint8_t b = p_buffer[i + 0]; + + TGA_PUT_PIXEL(r, g, b, a) + + x += x_step; + i += 4; + } + x = x_start; + y += y_step; + } + } + + image_data_w = PoolVector<uint8_t>::Write(); + + p_image->create(width, height, 0, Image::FORMAT_RGBA8, image_data); + + return OK; +} + +Error ImageLoaderTGA::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { + + PoolVector<uint8_t> src_image; + int src_image_len = f->get_len(); + ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT); + ERR_FAIL_COND_V(src_image_len < sizeof(tga_header_s), ERR_FILE_CORRUPT); + src_image.resize(src_image_len); + + Error err = OK; + + tga_header_s tga_header; + tga_header.id_length = f->get_8(); + tga_header.color_map_type = f->get_8(); + tga_header.image_type = static_cast<tga_type_e>(f->get_8()); + + tga_header.first_color_entry = f->get_16(); + tga_header.color_map_length = f->get_16(); + tga_header.color_map_depth = f->get_8(); + + tga_header.x_origin = f->get_16(); + tga_header.y_origin = f->get_16(); + tga_header.image_width = f->get_16(); + tga_header.image_height = f->get_16(); + tga_header.pixel_depth = f->get_8(); + tga_header.image_descriptor = f->get_8(); + + bool is_encoded = (tga_header.image_type == TGA_TYPE_RLE_INDEXED || tga_header.image_type == TGA_TYPE_RLE_RGB || tga_header.image_type == TGA_TYPE_RLE_MONOCHROME); + bool has_color_map = (tga_header.image_type == TGA_TYPE_RLE_INDEXED || tga_header.image_type == TGA_TYPE_INDEXED); + bool is_monochrome = (tga_header.image_type == TGA_TYPE_RLE_MONOCHROME || tga_header.image_type == TGA_TYPE_MONOCHROME); + + if (tga_header.image_type == TGA_TYPE_NO_DATA) + err = FAILED; + + if (has_color_map) { + if (tga_header.color_map_length > 256 || (tga_header.color_map_depth != 24) || tga_header.color_map_type != 1) { + err = FAILED; + } + } else { + if (tga_header.color_map_type) { + err = FAILED; + } + } + + if (tga_header.image_width <= 0 || tga_header.image_height <= 0) + err = FAILED; + + if (tga_header.pixel_depth != 8 && tga_header.pixel_depth != 24 && tga_header.pixel_depth != 32) + err = FAILED; + + if (err == OK) { + f->seek(f->get_pos() + tga_header.id_length); + + PoolVector<uint8_t> palette; + + if (has_color_map) { + size_t color_map_size = tga_header.color_map_length * (tga_header.color_map_depth >> 3); + err = palette.resize(color_map_size); + if (err == OK) { + PoolVector<uint8_t>::Write palette_w = palette.write(); + f->get_buffer(&palette_w[0], color_map_size); + } else { + return OK; + } + } + + PoolVector<uint8_t>::Write src_image_w = src_image.write(); + f->get_buffer(&src_image_w[0], src_image_len - f->get_pos()); + + PoolVector<uint8_t>::Read src_image_r = src_image.read(); + + const size_t pixel_size = tga_header.pixel_depth >> 3; + const size_t buffer_size = (tga_header.image_width * tga_header.image_height) * pixel_size; + + PoolVector<uint8_t> uncompressed_buffer; + uncompressed_buffer.resize(buffer_size); + PoolVector<uint8_t>::Write uncompressed_buffer_w = uncompressed_buffer.write(); + PoolVector<uint8_t>::Read uncompressed_buffer_r; + + const uint8_t *buffer = NULL; + + if (is_encoded) { + + err = decode_tga_rle(src_image_r.ptr(), pixel_size, uncompressed_buffer_w.ptr(), buffer_size); + + if (err == OK) { + uncompressed_buffer_r = uncompressed_buffer.read(); + buffer = uncompressed_buffer_r.ptr(); + } + } else { + buffer = src_image_r.ptr(); + }; + + if (err == OK) { + PoolVector<uint8_t>::Read palette_r = palette.read(); + err = convert_to_image(p_image, buffer, tga_header, palette_r.ptr(), is_monochrome); + } + } + + f->close(); + return err; +} + +void ImageLoaderTGA::get_recognized_extensions(List<String> *p_extensions) const { + + p_extensions->push_back("tga"); +} + +ImageLoaderTGA::ImageLoaderTGA() { +} diff --git a/modules/tga/image_loader_tga.h b/modules/tga/image_loader_tga.h new file mode 100644 index 000000000..11329ec68 --- /dev/null +++ b/modules/tga/image_loader_tga.h @@ -0,0 +1,83 @@ +/*************************************************************************/ +/* image_loader_jpegd.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef IMAGE_LOADER_TGA_H +#define IMAGE_LOADER_TGA_H + +#include "io/image_loader.h" + +/** + @author SaracenOne +*/ +class ImageLoaderTGA : public ImageFormatLoader { + enum tga_type_e { + TGA_TYPE_NO_DATA = 0, + TGA_TYPE_INDEXED = 1, + TGA_TYPE_RGB = 2, + TGA_TYPE_MONOCHROME = 3, + TGA_TYPE_RLE_INDEXED = 9, + TGA_TYPE_RLE_RGB = 10, + TGA_TYPE_RLE_MONOCHROME = 11 + }; + + enum tga_origin_e { + TGA_ORIGIN_BOTTOM_LEFT = 0x00, + TGA_ORIGIN_BOTTOM_RIGHT = 0x01, + TGA_ORIGIN_TOP_LEFT = 0x02, + TGA_ORIGIN_TOP_RIGHT = 0x03, + TGA_ORIGIN_SHIFT = 0x04, + TGA_ORIGIN_MASK = 0x30 + }; + + struct tga_header_s { + uint8_t id_length; + uint8_t color_map_type; + tga_type_e image_type; + + uint16_t first_color_entry; + uint16_t color_map_length; + uint8_t color_map_depth; + + uint16_t x_origin; + uint16_t y_origin; + uint16_t image_width; + uint16_t image_height; + uint8_t pixel_depth; + uint8_t image_descriptor; + }; + static Error decode_tga_rle(const uint8_t *p_compressed_buffer, size_t p_pixel_size, uint8_t *p_uncompressed_buffer, size_t p_output_size); + static Error convert_to_image(Ref<Image> p_image, const uint8_t *p_buffer, const tga_header_s &p_header, const uint8_t *p_palette, const bool p_is_monochrome); + +public: + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); + virtual void get_recognized_extensions(List<String> *p_extensions) const; + ImageLoaderTGA(); +}; + +#endif diff --git a/modules/tga/register_types.cpp b/modules/tga/register_types.cpp new file mode 100644 index 000000000..6e120fa3b --- /dev/null +++ b/modules/tga/register_types.cpp @@ -0,0 +1,45 @@ +/*************************************************************************/ +/* register_types.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "register_types.h" + +#include "image_loader_tga.h" + +static ImageLoaderTGA *image_loader_tga = NULL; + +void register_tga_types() { + + image_loader_tga = memnew(ImageLoaderTGA); + ImageLoader::add_image_format_loader(image_loader_tga); +} + +void unregister_tga_types() { + + memdelete(image_loader_tga); +} diff --git a/modules/tga/register_types.h b/modules/tga/register_types.h new file mode 100644 index 000000000..079b7bf29 --- /dev/null +++ b/modules/tga/register_types.h @@ -0,0 +1,31 @@ +/*************************************************************************/ +/* register_types.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +void register_tga_types(); +void unregister_tga_types(); diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 5839bc924..941668d47 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -1011,7 +1011,7 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt } Rect2 pos = members->get_item_rect(ti); - new_function_menu->set_position(members->get_global_position() + pos.pos + Vector2(0, pos.size.y)); + new_function_menu->set_position(members->get_global_position() + pos.position + Vector2(0, pos.size.y)); new_function_menu->popup(); return; } else if (p_button == 0) { @@ -2240,6 +2240,10 @@ void VisualScriptEditor::add_callback(const String &p_function, PoolStringArray //undo_redo->clear_history(); } +bool VisualScriptEditor::show_members_overview() { + return false; +} + void VisualScriptEditor::update_settings() { _update_graph(); diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index bb832431a..92f31f20d 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -248,6 +248,7 @@ public: virtual void get_breakpoints(List<int> *p_breakpoints); virtual void add_callback(const String &p_function, PoolStringArray p_args); virtual void update_settings(); + virtual bool show_members_overview(); virtual void set_debugger_active(bool p_active); virtual void set_tooltip_request_func(String p_method, Object *p_obj); virtual Control *get_edit_menu(); |
