diff options
-rw-r--r-- | editor/plugins/spatial_editor_plugin.cpp | 94 | ||||
-rw-r--r-- | editor/plugins/spatial_editor_plugin.h | 30 | ||||
-rw-r--r-- | modules/gdscript/gdscript_parser.cpp | 42 | ||||
-rw-r--r-- | thirdparty/README.md | 8 | ||||
-rw-r--r-- | thirdparty/squish/Add-Decompress-Bc5-to-Squish.patch | 143 | ||||
-rw-r--r-- | thirdparty/squish/colourblock.cpp | 85 | ||||
-rw-r--r-- | thirdparty/squish/colourblock.h | 3 | ||||
-rw-r--r-- | thirdparty/squish/squish.cpp | 8 |
8 files changed, 355 insertions, 58 deletions
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index cefc957ebf..0f27310264 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -3884,8 +3884,7 @@ Dictionary SpatialEditor::get_state() const { d["rotate_snap"] = get_rotate_snap(); d["scale_snap"] = get_scale_snap(); - int local_coords_index = transform_menu->get_popup()->get_item_index(MENU_TRANSFORM_LOCAL_COORDS); - d["local_coords"] = transform_menu->get_popup()->is_item_checked(local_coords_index); + d["local_coords"] = tool_option_button[TOOL_OPT_LOCAL_COORDS]->is_pressed(); int vc = 0; if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT))) @@ -3923,8 +3922,7 @@ void SpatialEditor::set_state(const Dictionary &p_state) { if (d.has("snap_enabled")) { snap_enabled = d["snap_enabled"]; - int snap_enabled_idx = transform_menu->get_popup()->get_item_index(MENU_TRANSFORM_USE_SNAP); - transform_menu->get_popup()->set_item_checked(snap_enabled_idx, snap_enabled); + tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_pressed(d["snap_enabled"]); } if (d.has("translate_snap")) @@ -3937,8 +3935,7 @@ void SpatialEditor::set_state(const Dictionary &p_state) { snap_scale->set_text(d["scale_snap"]); if (d.has("local_coords")) { - int local_coords_idx = transform_menu->get_popup()->get_item_index(MENU_TRANSFORM_LOCAL_COORDS); - transform_menu->get_popup()->set_item_checked(local_coords_idx, d["local_coords"]); + tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_pressed(d["local_coords"]); update_transform_gizmo(); } @@ -4078,6 +4075,22 @@ void SpatialEditor::_xform_dialog_action() { undo_redo->commit_action(); } +void SpatialEditor::_menu_item_toggled(bool pressed, int p_option) { + + switch (p_option) { + case MENU_TOOL_LOCAL_COORDS: { + + tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_pressed(pressed); + update_transform_gizmo(); + } break; + + case MENU_TOOL_USE_SNAP: { + tool_option_button[TOOL_OPT_USE_SNAP]->set_pressed(pressed); + snap_enabled = pressed; + } break; + } +} + void SpatialEditor::_menu_item_pressed(int p_option) { switch (p_option) { @@ -4091,29 +4104,13 @@ void SpatialEditor::_menu_item_pressed(int p_option) { for (int i = 0; i < TOOL_MAX; i++) tool_button[i]->set_pressed(i == p_option); tool_mode = (ToolMode)p_option; - - //static const char *_mode[]={"Selection Mode.","Translation Mode.","Rotation Mode.","Scale Mode.","List Selection Mode."}; - //set_message(_mode[p_option],3); update_transform_gizmo(); } break; - case MENU_TRANSFORM_USE_SNAP: { - - bool is_checked = transform_menu->get_popup()->is_item_checked(transform_menu->get_popup()->get_item_index(p_option)); - snap_enabled = !is_checked; - transform_menu->get_popup()->set_item_checked(transform_menu->get_popup()->get_item_index(p_option), snap_enabled); - } break; case MENU_TRANSFORM_CONFIGURE_SNAP: { snap_dialog->popup_centered(Size2(200, 180)); } break; - case MENU_TRANSFORM_LOCAL_COORDS: { - - bool is_checked = transform_menu->get_popup()->is_item_checked(transform_menu->get_popup()->get_item_index(p_option)); - transform_menu->get_popup()->set_item_checked(transform_menu->get_popup()->get_item_index(p_option), !is_checked); - update_transform_gizmo(); - - } break; case MENU_TRANSFORM_DIALOG: { for (int i = 0; i < 3; i++) { @@ -4718,6 +4715,19 @@ 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/local_coords", p_event)) + if (are_local_coords_enabled()) { + _menu_item_toggled(false, MENU_TOOL_LOCAL_COORDS); + } else { + _menu_item_toggled(true, MENU_TOOL_LOCAL_COORDS); + } + else if (ED_IS_SHORTCUT("spatial_editor/snap", p_event)) + if (is_snap_enabled()) { + _menu_item_toggled(false, MENU_TOOL_USE_SNAP); + } else { + _menu_item_toggled(true, MENU_TOOL_USE_SNAP); + } } } } @@ -4733,6 +4743,9 @@ void SpatialEditor::_notification(int p_what) { tool_button[SpatialEditor::TOOL_LOCK_SELECTED]->set_icon(get_icon("Lock", "EditorIcons")); tool_button[SpatialEditor::TOOL_UNLOCK_SELECTED]->set_icon(get_icon("Unlock", "EditorIcons")); + tool_option_button[SpatialEditor::TOOL_OPT_LOCAL_COORDS]->set_icon(get_icon("Object", "EditorIcons")); + tool_option_button[SpatialEditor::TOOL_OPT_USE_SNAP]->set_icon(get_icon("Snap", "EditorIcons")); + view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), get_icon("Panels1", "EditorIcons")); view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), get_icon("Panels2", "EditorIcons")); view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), get_icon("Panels2Alt", "EditorIcons")); @@ -4768,6 +4781,9 @@ void SpatialEditor::_notification(int p_what) { tool_button[SpatialEditor::TOOL_MODE_SCALE]->set_icon(get_icon("ToolScale", "EditorIcons")); tool_button[SpatialEditor::TOOL_MODE_LIST_SELECT]->set_icon(get_icon("ListSelect", "EditorIcons")); + tool_option_button[SpatialEditor::TOOL_OPT_LOCAL_COORDS]->set_icon(get_icon("Object", "EditorIcons")); + tool_option_button[SpatialEditor::TOOL_OPT_USE_SNAP]->set_icon(get_icon("Snap", "EditorIcons")); + view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), get_icon("Panels1", "EditorIcons")); view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), get_icon("Panels2", "EditorIcons")); view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), get_icon("Panels2Alt", "EditorIcons")); @@ -4886,6 +4902,7 @@ void SpatialEditor::_bind_methods() { ClassDB::bind_method("_unhandled_key_input", &SpatialEditor::_unhandled_key_input); ClassDB::bind_method("_node_removed", &SpatialEditor::_node_removed); ClassDB::bind_method("_menu_item_pressed", &SpatialEditor::_menu_item_pressed); + ClassDB::bind_method("_menu_item_toggled", &SpatialEditor::_menu_item_toggled); ClassDB::bind_method("_xform_dialog_action", &SpatialEditor::_xform_dialog_action); ClassDB::bind_method("_get_editor_data", &SpatialEditor::_get_editor_data); ClassDB::bind_method("_request_gizmo", &SpatialEditor::_request_gizmo); @@ -4949,6 +4966,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { Vector<Variant> button_binds; button_binds.resize(1); + String sct; tool_button[TOOL_MODE_SELECT] = memnew(ToolButton); hbc_menu->add_child(tool_button[TOOL_MODE_SELECT]); @@ -4960,7 +4978,6 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_button[TOOL_MODE_SELECT]->set_tooltip(TTR("Select Mode (Q)\n") + keycode_get_string(KEY_MASK_CMD) + TTR("Drag: Rotate\nAlt+Drag: Move\nAlt+RMB: Depth list selection")); tool_button[TOOL_MODE_MOVE] = memnew(ToolButton); - hbc_menu->add_child(tool_button[TOOL_MODE_MOVE]); tool_button[TOOL_MODE_MOVE]->set_toggle_mode(true); tool_button[TOOL_MODE_MOVE]->set_flat(true); @@ -4984,9 +5001,6 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_button[TOOL_MODE_SCALE]->connect("pressed", this, "_menu_item_pressed", button_binds); tool_button[TOOL_MODE_SCALE]->set_tooltip(TTR("Scale Mode (R)")); - VSeparator *vs = memnew(VSeparator); - hbc_menu->add_child(vs); - tool_button[TOOL_MODE_LIST_SELECT] = memnew(ToolButton); hbc_menu->add_child(tool_button[TOOL_MODE_LIST_SELECT]); tool_button[TOOL_MODE_LIST_SELECT]->set_toggle_mode(true); @@ -5007,6 +5021,29 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_button[TOOL_UNLOCK_SELECTED]->connect("pressed", this, "_menu_item_pressed", button_binds); tool_button[TOOL_UNLOCK_SELECTED]->set_tooltip(TTR("Unlock the selected object (can be moved).")); + VSeparator *vs = memnew(VSeparator); + hbc_menu->add_child(vs); + + tool_option_button[TOOL_OPT_LOCAL_COORDS] = memnew(ToolButton); + hbc_menu->add_child(tool_option_button[TOOL_OPT_LOCAL_COORDS]); + tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_toggle_mode(true); + tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_flat(true); + button_binds[0] = MENU_TOOL_LOCAL_COORDS; + tool_option_button[TOOL_OPT_LOCAL_COORDS]->connect("toggled", this, "_menu_item_toggled", button_binds); + ED_SHORTCUT("spatial_editor/local_coords", TTR("Local Coords"), KEY_T); + sct = ED_GET_SHORTCUT("spatial_editor/local_coords").ptr()->get_as_text(); + tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_tooltip(vformat(TTR("Local Space Mode (%s)"), sct)); + + tool_option_button[TOOL_OPT_USE_SNAP] = memnew(ToolButton); + hbc_menu->add_child(tool_option_button[TOOL_OPT_USE_SNAP]); + tool_option_button[TOOL_OPT_USE_SNAP]->set_toggle_mode(true); + tool_option_button[TOOL_OPT_USE_SNAP]->set_flat(true); + button_binds[0] = MENU_TOOL_USE_SNAP; + tool_option_button[TOOL_OPT_USE_SNAP]->connect("toggled", this, "_menu_item_toggled", button_binds); + ED_SHORTCUT("spatial_editor/snap", TTR("Snap"), KEY_Y); + sct = ED_GET_SHORTCUT("spatial_editor/snap").ptr()->get_as_text(); + tool_option_button[TOOL_OPT_USE_SNAP]->set_tooltip(vformat(TTR("Snap Mode (%s)"), sct)); + vs = memnew(VSeparator); hbc_menu->add_child(vs); @@ -5021,7 +5058,6 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { ED_SHORTCUT("spatial_editor/left_view", TTR("Left View"), KEY_MASK_ALT + KEY_KP_3); ED_SHORTCUT("spatial_editor/right_view", TTR("Right View"), KEY_KP_3); ED_SHORTCUT("spatial_editor/switch_perspective_orthogonal", TTR("Switch Perspective/Orthogonal view"), KEY_KP_5); - ED_SHORTCUT("spatial_editor/snap", TTR("Snap"), KEY_S); ED_SHORTCUT("spatial_editor/insert_anim_key", TTR("Insert Animation Key"), KEY_K); ED_SHORTCUT("spatial_editor/focus_origin", TTR("Focus Origin"), KEY_O); ED_SHORTCUT("spatial_editor/focus_selection", TTR("Focus Selection"), KEY_F); @@ -5043,12 +5079,8 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { hbc_menu->add_child(transform_menu); p = transform_menu->get_popup(); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/use_snap", TTR("Use Snap")), MENU_TRANSFORM_USE_SNAP); p->add_shortcut(ED_SHORTCUT("spatial_editor/configure_snap", TTR("Configure Snap..")), MENU_TRANSFORM_CONFIGURE_SNAP); p->add_separator(); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/local_coords", TTR("Local Coords")), MENU_TRANSFORM_LOCAL_COORDS); - //p->set_item_checked(p->get_item_count()-1,true); - p->add_separator(); p->add_shortcut(ED_SHORTCUT("spatial_editor/transform_dialog", TTR("Transform Dialog..")), MENU_TRANSFORM_DIALOG); p->connect("id_pressed", this, "_menu_item_pressed"); diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index 8369a5de54..86b814ab8a 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -405,6 +405,14 @@ public: }; + enum ToolOptions { + + TOOL_OPT_LOCAL_COORDS, + TOOL_OPT_USE_SNAP, + TOOL_OPT_MAX + + }; + private: EditorNode *editor; EditorSelection *editor_selection; @@ -449,17 +457,6 @@ private: Spatial *preview_node; AABB preview_bounds; - /* - struct Selected { - AABB aabb; - Transform original; // original location when moving - Transform last_xform; // last transform - Spatial *sp; - RID poly_instance; - }; - - Map<uint32_t,Selected> selected; -*/ struct Gizmo { bool visible; @@ -474,9 +471,9 @@ private: MENU_TOOL_ROTATE, MENU_TOOL_SCALE, MENU_TOOL_LIST_SELECT, - MENU_TRANSFORM_USE_SNAP, + MENU_TOOL_LOCAL_COORDS, + MENU_TOOL_USE_SNAP, MENU_TRANSFORM_CONFIGURE_SNAP, - MENU_TRANSFORM_LOCAL_COORDS, MENU_TRANSFORM_DIALOG, MENU_VIEW_USE_1_VIEWPORT, MENU_VIEW_USE_2_VIEWPORTS, @@ -493,6 +490,7 @@ private: }; Button *tool_button[TOOL_MAX]; + Button *tool_option_button[TOOL_OPT_MAX]; MenuButton *transform_menu; MenuButton *view_menu; @@ -524,11 +522,10 @@ private: void _xform_dialog_action(); void _menu_item_pressed(int p_option); + void _menu_item_toggled(bool pressed, int p_option); HBoxContainer *hbc_menu; - // - // void _generate_selection_box(); UndoRedo *undo_redo; @@ -579,13 +576,12 @@ public: bool is_gizmo_visible() const { return gizmo.visible; } ToolMode get_tool_mode() const { return tool_mode; } + bool are_local_coords_enabled() const { return tool_option_button[SpatialEditor::TOOL_OPT_LOCAL_COORDS]->is_pressed(); } bool is_snap_enabled() const { return snap_enabled; } float get_translate_snap() const { return snap_translate->get_text().to_double(); } float get_rotate_snap() const { return snap_rotate->get_text().to_double(); } float get_scale_snap() const { return snap_scale->get_text().to_double(); } - bool are_local_coords_enabled() const { return transform_menu->get_popup()->is_item_checked(transform_menu->get_popup()->get_item_index(SpatialEditor::MENU_TRANSFORM_LOCAL_COORDS)); } - Ref<ArrayMesh> get_move_gizmo(int idx) const { return move_gizmo[idx]; } Ref<ArrayMesh> get_move_plane_gizmo(int idx) const { return move_plane_gizmo[idx]; } Ref<ArrayMesh> get_rotate_gizmo(int idx) const { return rotate_gizmo[idx]; } diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 36ae61e388..8c110143b8 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -597,12 +597,36 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s OperatorNode *op = alloc_node<OperatorNode>(); op->op = OperatorNode::OP_CALL; + //Do a quick Array and Dictionary Check. Replace if either require no arguments. + bool replaced = false; + if (tokenizer->get_token() == GDScriptTokenizer::TK_BUILT_IN_TYPE) { + Variant::Type ct = tokenizer->get_token_type(); + if (p_parsing_constant == false) { + if (ct == Variant::ARRAY) { + if (tokenizer->get_token(2) == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { + ArrayNode *arr = alloc_node<ArrayNode>(); + expr = arr; + replaced = true; + tokenizer->advance(3); + } + } + if (ct == Variant::DICTIONARY) { + if (tokenizer->get_token(2) == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { + DictionaryNode *dict = alloc_node<DictionaryNode>(); + expr = dict; + replaced = true; + tokenizer->advance(3); + } + } + } - TypeNode *tn = alloc_node<TypeNode>(); - tn->vtype = tokenizer->get_token_type(); - op->arguments.push_back(tn); - tokenizer->advance(2); + if (!replaced) { + TypeNode *tn = alloc_node<TypeNode>(); + tn->vtype = tokenizer->get_token_type(); + op->arguments.push_back(tn); + tokenizer->advance(2); + } } else if (tokenizer->get_token() == GDScriptTokenizer::TK_BUILT_IN_FUNC) { BuiltInFunctionNode *bn = alloc_node<BuiltInFunctionNode>(); @@ -628,11 +652,11 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s _make_completable_call(0); completion_node = op; } - if (!_parse_arguments(op, op->arguments, p_static, true)) - return NULL; - - expr = op; - + if (!replaced) { + if (!_parse_arguments(op, op->arguments, p_static, true)) + return NULL; + expr = op; + } } else if (tokenizer->is_token_literal(0, true)) { // We check with is_token_literal, as this allows us to use match/sync/etc. as a name //identifier (reference) diff --git a/thirdparty/README.md b/thirdparty/README.md index 8c50081782..62690e21c7 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -365,6 +365,7 @@ Files extracted from upstream source: - celt/ and silk/ subfolders - COPYING + ## pcre2 - Upstream: http://www.pcre.org/ @@ -378,6 +379,7 @@ Files extracted from upstream source: - src/pcre2_jit_*.c and src/sljit/* - AUTHORS and COPYING + ## pvrtccompressor - Upstream: https://bitbucket.org/jthlim/pvrtccompressor @@ -389,12 +391,14 @@ Files extracted from upstream source: - all .cpp and .h files apart from `main.cpp` - LICENSE.TXT + ## recastnavigation - Upstream: https://github.com/recastnavigation/recastnavigation - version: git commit ef3ea40f - 2016-02-06 - License: zlib + ## rtaudio - Upstream: http://www.music.mcgill.ca/~gary/rtaudio/ @@ -416,6 +420,10 @@ Files extracted from upstream source: - all .cpp, .h and .inl files +Important: Some files have Godot-made changes. +They are marked with `// -- GODOT start --` and `// -- GODOT end --` +comments and a patch is provided in the squish/ folder. + ## tinyexr diff --git a/thirdparty/squish/Add-Decompress-Bc5-to-Squish.patch b/thirdparty/squish/Add-Decompress-Bc5-to-Squish.patch new file mode 100644 index 0000000000..1e06a8d318 --- /dev/null +++ b/thirdparty/squish/Add-Decompress-Bc5-to-Squish.patch @@ -0,0 +1,143 @@ +From 7b64cc4c8b0be0443741483bf65909f5140179c0 Mon Sep 17 00:00:00 2001 +From: Orkun <orkuntezerm@gmail.com> +Date: Sun, 19 Nov 2017 02:24:31 +0300 +Subject: [PATCH] Fix #12220: Add Decompress Bc5 to Squish + +This Commit fixes the corrupted file preview described in #12220. +Added DecompressColourBc5 function to squish. +--- + thirdparty/squish/colourblock.cpp | 85 +++++++++++++++++++++++++++++++++++++++ + thirdparty/squish/colourblock.h | 3 ++ + thirdparty/squish/squish.cpp | 8 +++- + 3 files changed, 95 insertions(+), 1 deletion(-) + +diff --git a/thirdparty/squish/colourblock.cpp b/thirdparty/squish/colourblock.cpp +index af8b98036..3de46382c 100644 +--- a/thirdparty/squish/colourblock.cpp ++++ b/thirdparty/squish/colourblock.cpp +@@ -211,4 +211,89 @@ void DecompressColour( u8* rgba, void const* block, bool isDxt1 ) + } + } + ++// -- Godot start -- ++void DecompressColourBc5( u8* rgba, void const* block) ++{ ++ // get the block bytes ++ u8 const* bytes = reinterpret_cast< u8 const* >( block ); ++ ++ // unpack the endpoints ++ u8 codes[16]; ++ int red_0 = bytes[0]; ++ int red_1 = bytes[1]; ++ ++ codes[0] = red_0; ++ codes[1] = red_1; ++ codes[6] = 0.0f; ++ codes[7] = 1.0f; ++ // generate the midpoints ++ if(red_0 > red_1) ++ { ++ for( int i = 2; i < 8; ++i ) ++ { ++ codes[i] = ((8-i)*red_0 + (i-1)*red_1)/7; ++ } ++ } ++ else ++ { ++ for( int i = 2; i < 6; ++i ) ++ { ++ codes[i] = ((6-i)*red_0 + (i-1)*red_1)/5; ++ } ++ } ++ ++ int green_0 = bytes[8]; ++ int green_1 = bytes[9]; ++ ++ codes[0 + 8] = green_0; ++ codes[1 + 8] = green_1; ++ codes[6 + 8] = 0.0f; ++ codes[7 + 8] = 1.0f; ++ // generate the midpoints ++ if(green_0 > green_1) ++ { ++ for( int i = 2; i < 8; ++i ) ++ { ++ codes[i + 8] = ((8-i)*green_0 + (i-1)*green_1)/7; ++ } ++ } ++ else ++ { ++ for( int i = 2; i < 6; ++i ) ++ { ++ codes[i + 8] = ((6-i)*green_0 + (i-1)*green_1)/5; ++ } ++ } ++ ++ u8 indices[32]; ++ for( int i = 0; i < 4; ++i ) ++ { ++ u8 packed = bytes[2 + i]; ++ u8* red_ind = indices + 4*i; ++ ++ red_ind[0] = packed & 0x3; ++ red_ind[1] = ( packed >> 2 ) & 0x3; ++ red_ind[2] = ( packed >> 4 ) & 0x3; ++ red_ind[3] = ( packed >> 6 ) & 0x3; ++ ++ packed = bytes[8 + i]; ++ u8* green_ind = indices + 4*i + 16; ++ green_ind[0] = packed & 0x3; ++ green_ind[1] = ( packed >> 2 ) & 0x3; ++ green_ind[2] = ( packed >> 4 ) & 0x3; ++ green_ind[3] = ( packed >> 6 ) & 0x3; ++ } ++ ++ // store out the colours ++ for( int i = 0; i < 16; ++i ) ++ { ++ rgba[4*i] = codes[indices[i]]; ++ rgba[4*i +1] = codes[indices[i + 16] + 8]; ++ rgba[4*i +2] = 0; ++ rgba[4*i +3] = 255; ++ } ++} ++// -- GODOT end -- ++ ++ + } // namespace squish +diff --git a/thirdparty/squish/colourblock.h b/thirdparty/squish/colourblock.h +index fee2cd7c5..3cb9b7e3b 100644 +--- a/thirdparty/squish/colourblock.h ++++ b/thirdparty/squish/colourblock.h +@@ -35,6 +35,9 @@ void WriteColourBlock3( Vec3::Arg start, Vec3::Arg end, u8 const* indices, void* + void WriteColourBlock4( Vec3::Arg start, Vec3::Arg end, u8 const* indices, void* block ); + + void DecompressColour( u8* rgba, void const* block, bool isDxt1 ); ++// -- GODOT start -- ++void DecompressColourBc5( u8* rgba, void const* block ); ++// -- GODOT end -- + + } // namespace squish + +diff --git a/thirdparty/squish/squish.cpp b/thirdparty/squish/squish.cpp +index 1d22a64ad..fd11a147d 100644 +--- a/thirdparty/squish/squish.cpp ++++ b/thirdparty/squish/squish.cpp +@@ -135,7 +135,13 @@ void Decompress( u8* rgba, void const* block, int flags ) + colourBlock = reinterpret_cast< u8 const* >( block ) + 8; + + // decompress colour +- DecompressColour( rgba, colourBlock, ( flags & kDxt1 ) != 0 ); ++ // -- GODOT start -- ++ //DecompressColour( rgba, colourBlock, ( flags & kDxt1 ) != 0 ); ++ if(( flags & ( kBc5 ) ) != 0) ++ DecompressColourBc5( rgba, colourBlock); ++ else ++ DecompressColour( rgba, colourBlock, ( flags & kDxt1 ) != 0 ); ++ // -- GODOT end -- + + // decompress alpha separately if necessary + if( ( flags & kDxt3 ) != 0 ) +-- +2.13.6 + diff --git a/thirdparty/squish/colourblock.cpp b/thirdparty/squish/colourblock.cpp index af8b980365..3de46382c0 100644 --- a/thirdparty/squish/colourblock.cpp +++ b/thirdparty/squish/colourblock.cpp @@ -211,4 +211,89 @@ void DecompressColour( u8* rgba, void const* block, bool isDxt1 ) } } +// -- Godot start -- +void DecompressColourBc5( u8* rgba, void const* block) +{ + // get the block bytes + u8 const* bytes = reinterpret_cast< u8 const* >( block ); + + // unpack the endpoints + u8 codes[16]; + int red_0 = bytes[0]; + int red_1 = bytes[1]; + + codes[0] = red_0; + codes[1] = red_1; + codes[6] = 0.0f; + codes[7] = 1.0f; + // generate the midpoints + if(red_0 > red_1) + { + for( int i = 2; i < 8; ++i ) + { + codes[i] = ((8-i)*red_0 + (i-1)*red_1)/7; + } + } + else + { + for( int i = 2; i < 6; ++i ) + { + codes[i] = ((6-i)*red_0 + (i-1)*red_1)/5; + } + } + + int green_0 = bytes[8]; + int green_1 = bytes[9]; + + codes[0 + 8] = green_0; + codes[1 + 8] = green_1; + codes[6 + 8] = 0.0f; + codes[7 + 8] = 1.0f; + // generate the midpoints + if(green_0 > green_1) + { + for( int i = 2; i < 8; ++i ) + { + codes[i + 8] = ((8-i)*green_0 + (i-1)*green_1)/7; + } + } + else + { + for( int i = 2; i < 6; ++i ) + { + codes[i + 8] = ((6-i)*green_0 + (i-1)*green_1)/5; + } + } + + u8 indices[32]; + for( int i = 0; i < 4; ++i ) + { + u8 packed = bytes[2 + i]; + u8* red_ind = indices + 4*i; + + red_ind[0] = packed & 0x3; + red_ind[1] = ( packed >> 2 ) & 0x3; + red_ind[2] = ( packed >> 4 ) & 0x3; + red_ind[3] = ( packed >> 6 ) & 0x3; + + packed = bytes[8 + i]; + u8* green_ind = indices + 4*i + 16; + green_ind[0] = packed & 0x3; + green_ind[1] = ( packed >> 2 ) & 0x3; + green_ind[2] = ( packed >> 4 ) & 0x3; + green_ind[3] = ( packed >> 6 ) & 0x3; + } + + // store out the colours + for( int i = 0; i < 16; ++i ) + { + rgba[4*i] = codes[indices[i]]; + rgba[4*i +1] = codes[indices[i + 16] + 8]; + rgba[4*i +2] = 0; + rgba[4*i +3] = 255; + } +} +// -- GODOT end -- + + } // namespace squish diff --git a/thirdparty/squish/colourblock.h b/thirdparty/squish/colourblock.h index fee2cd7c5d..3cb9b7e3b9 100644 --- a/thirdparty/squish/colourblock.h +++ b/thirdparty/squish/colourblock.h @@ -35,6 +35,9 @@ void WriteColourBlock3( Vec3::Arg start, Vec3::Arg end, u8 const* indices, void* void WriteColourBlock4( Vec3::Arg start, Vec3::Arg end, u8 const* indices, void* block ); void DecompressColour( u8* rgba, void const* block, bool isDxt1 ); +// -- GODOT start -- +void DecompressColourBc5( u8* rgba, void const* block ); +// -- GODOT end -- } // namespace squish diff --git a/thirdparty/squish/squish.cpp b/thirdparty/squish/squish.cpp index 1d22a64ad6..fd11a147de 100644 --- a/thirdparty/squish/squish.cpp +++ b/thirdparty/squish/squish.cpp @@ -135,7 +135,13 @@ void Decompress( u8* rgba, void const* block, int flags ) colourBlock = reinterpret_cast< u8 const* >( block ) + 8; // decompress colour - DecompressColour( rgba, colourBlock, ( flags & kDxt1 ) != 0 ); + // -- GODOT start -- + //DecompressColour( rgba, colourBlock, ( flags & kDxt1 ) != 0 ); + if(( flags & ( kBc5 ) ) != 0) + DecompressColourBc5( rgba, colourBlock); + else + DecompressColour( rgba, colourBlock, ( flags & kDxt1 ) != 0 ); + // -- GODOT end -- // decompress alpha separately if necessary if( ( flags & kDxt3 ) != 0 ) |