summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.mailmap2
-rw-r--r--.travis.yml15
-rw-r--r--AUTHORS.md1
-rw-r--r--DONORS.md135
-rw-r--r--core/debugger/debugger_marshalls.cpp4
-rw-r--r--core/debugger/remote_debugger.cpp2
-rw-r--r--core/math/expression.cpp2
-rw-r--r--core/os/mutex.cpp4
-rw-r--r--core/os/mutex.h26
-rw-r--r--doc/classes/CheckBox.xml2
-rw-r--r--doc/classes/CheckButton.xml2
-rw-r--r--doc/classes/Geometry.xml4
-rw-r--r--doc/classes/NavigationAgent.xml2
-rw-r--r--doc/classes/NavigationAgent2D.xml2
-rw-r--r--doc/classes/NavigationRegion.xml2
-rw-r--r--doc/classes/PacketPeerUDP.xml2
-rw-r--r--doc/classes/PhysicsServer.xml2
-rw-r--r--doc/classes/VisualShaderNodeIf.xml2
-rw-r--r--drivers/SCsub2
-rw-r--r--drivers/dummy/rasterizer_dummy.h259
-rw-r--r--editor/debugger/script_editor_debugger.cpp2
-rw-r--r--editor/import/resource_importer_texture.cpp2
-rw-r--r--modules/basis_universal/SCsub1
-rw-r--r--modules/csg/csg.cpp6
-rw-r--r--modules/enet/doc_classes/NetworkedMultiplayerENet.xml2
-rw-r--r--modules/gdnavigation/gd_navigation_server.cpp2
-rw-r--r--modules/gdnavigation/nav_map.cpp4
-rw-r--r--modules/gdscript/gdscript_parser.cpp2
-rw-r--r--modules/visual_script/visual_script_expression.cpp2
-rw-r--r--modules/websocket/emws_peer.cpp5
-rw-r--r--platform/javascript/SCsub41
-rw-r--r--platform/javascript/audio_driver_javascript.cpp93
-rw-r--r--platform/javascript/audio_driver_javascript.h1
-rw-r--r--platform/javascript/detect.py116
-rw-r--r--platform/javascript/emscripten_helpers.py37
-rw-r--r--platform/javascript/engine.js411
-rw-r--r--platform/javascript/engine/engine.js184
-rw-r--r--platform/javascript/engine/externs.js3
-rw-r--r--platform/javascript/engine/loader.js33
-rw-r--r--platform/javascript/engine/preloader.js139
-rw-r--r--platform/javascript/engine/utils.js69
-rw-r--r--platform/javascript/export/export.cpp8
-rw-r--r--platform/javascript/http_client.h.inc2
-rw-r--r--platform/javascript/http_client_javascript.cpp23
-rw-r--r--platform/javascript/id_handler.js2
-rw-r--r--platform/javascript/javascript_eval.cpp10
-rw-r--r--platform/javascript/os_javascript.cpp31
-rw-r--r--platform/javascript/pre.js5
-rw-r--r--platform/x11/detect_prime.cpp1
-rw-r--r--scene/gui/text_edit.cpp14
-rw-r--r--scene/resources/mesh.cpp16
-rw-r--r--servers/navigation_2d_server.h2
-rw-r--r--servers/navigation_server.h2
-rw-r--r--servers/visual/rasterizer_rd/rasterizer_canvas_rd.cpp4
-rw-r--r--servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp2
-rw-r--r--servers/visual/rasterizer_rd/shaders/canvas.glsl2
-rw-r--r--servers/visual/rendering_device.h8
-rw-r--r--servers/visual/shader_language.cpp2
-rw-r--r--thirdparty/README.md2
-rw-r--r--thirdparty/basis_universal/basisu_tool.cpp1548
60 files changed, 993 insertions, 2318 deletions
diff --git a/.mailmap b/.mailmap
index 9c930c773c..1baddb9c58 100644
--- a/.mailmap
+++ b/.mailmap
@@ -24,7 +24,9 @@ Chris Bradfield <chris@kidscancode.org> <cb@scribe.net>
Clay John <claynjohn@gmail.com>
Clay John <claynjohn@gmail.com> <clayjohn@shaw.ca>
Dana Olson <dana@shineuponthee.com> <adolson@gmail.com>
+dankan1890 <mewuidev2@gmail.com>
Daniel J. Ramirez <djrmuv@gmail.com>
+Emmanuel Barroga <emmanuelbarroga@gmail.com>
Erik Selecký <35656626+rxlecky@users.noreply.github.com>
Erik Selecký <35656626+rxlecky@users.noreply.github.com> <35656626+SeleckyErik@users.noreply.github.com>
Fabian <supagu@gmail.com>
diff --git a/.travis.yml b/.travis.yml
index 80191423c1..25b7795e13 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -117,6 +117,16 @@ matrix:
packages:
- *linux_deps
+ - name: Javascript export template (release, emscripten latest)
+ stage: build
+ env: PLATFORM=javascript TOOLS=no TARGET=release CACHE_NAME=${PLATFORM}-emcc-latest EXTRA_ARGS="use_closure_compiler=yes"
+ os: linux
+ compiler: clang
+ addons:
+ apt:
+ packages:
+ - *linux_deps
+
before_install:
- eval "${MATRIX_EVAL}"
- if [ "$STATIC_CHECKS" = "yes" ]; then
@@ -135,6 +145,11 @@ install:
java -version;
misc/travis/android-tools-linux.sh;
fi
+ - if [ "$PLATFORM" = "javascript" ]; then
+ git clone --depth 1 "https://github.com/emscripten-core/emsdk.git";
+ ./emsdk/emsdk install latest;
+ ./emsdk/emsdk activate latest;
+ fi
before_script:
- if [ "$PLATFORM" = "android" ]; then
diff --git a/AUTHORS.md b/AUTHORS.md
index 8be2d05455..a3269a73f7 100644
--- a/AUTHORS.md
+++ b/AUTHORS.md
@@ -124,6 +124,7 @@ name is available.
Michael Alexsander (YeldhamDev)
MichiRecRoom (LikeLakers2)
mrezai
+ muiroc
Nathan Warden (NathanWarden)
Nils André-Chang (NilsIrl)
Nuno Donato (nunodonato)
diff --git a/DONORS.md b/DONORS.md
index b0f0c138ee..0b7829c55d 100644
--- a/DONORS.md
+++ b/DONORS.md
@@ -28,8 +28,11 @@ generous deed immortalized in the next stable release of Godot Engine.
Andres Hernandez
Andrew Dunai
Brandon Lamb
+ Christian Baune
Christopher Montesano
Darkhan Baimyrza
+ Darrin Massena
+ Dov Zimring
Edward Flick
Gamechuck
GameDev.net
@@ -42,13 +45,12 @@ generous deed immortalized in the next stable release of Godot Engine.
Justin Arnold
Justo Delgado Baudí
Kyle Szklenski
- Leonard Meagher
- Mariano Suligoy
Matthieu Huvé
Maxim Karsten
Mike King
Nathan Warden
Neal Gompa (Conan Kudo)
+ Péter Magyar
Slobodan Milnovic
Stephan Lanfermann
Steve
@@ -77,32 +79,31 @@ generous deed immortalized in the next stable release of Godot Engine.
Austen McRae
Bernhard Werner
beVR
- Brian van der Stel
Carlo Cabanilla
Daniel James
David Giardi
Default Name
+ eggs
+ Felix Bohmann
Florian Breisch
Gamejunkey
Javier Roman
Jay Horton
- Joel Höglund
Jon Woodward
- Jose Fernando Alexandre
Karl Werf
+ Keinan Powers
Klavdij Voncina
Lex Steers
Luke
Maciej Pendolski
Matthew Hillier
Mohamed Ikbel Boulabiar
- Mored1984
- Péter Magyar
+ Mored4u
Rob Messick
Ryan Badour
+ Sandro Jenny
Scott Wadden
Sergey
- Shawn Yu
thechris
Tom Langwaldt
tukon
@@ -115,6 +116,7 @@ generous deed immortalized in the next stable release of Godot Engine.
Conrad Curry
Craig Smith
Darrian Little
+ Horváth Péter
Ivan Trombley
Jakub Dering
Joan Fons
@@ -128,6 +130,7 @@ generous deed immortalized in the next stable release of Godot Engine.
Rob
Robert Willes
Ronnie Ashlock
+ SKison
Thomas Bjarnelöf
Unseen Domains
Valryia
@@ -135,49 +138,59 @@ generous deed immortalized in the next stable release of Godot Engine.
Wojciech Chojnacki
Xavier PATRICELLI
+ Adam Nakonieczny
Adam Neumann
Alexander J Maynard
Alexey Dyadchenko
+ Alex Z
Andreas Funke
André Frélicot
- Andrew Bowen
aoshiwik
+ Ben Powell
Carlos de Sousa Marques
+ Charlie Whitfield
Chase Taranto
Chris Petrich
Christian Leth Jeppesen
Christoph Schröder
Cody Parker
+ Coldragon
Craig Ostrin
D
Daniel Eichler
David White
+ Denis Janßen
+ Easypete
Eric Monson
+ ethan ball
Eugenio Hugo Salgüero Jáñez
Fain
flesk
+ Gary Hulst
gavlig
GGGames.org
+ Green Fox
Guilherme Felipe de C. G. da Silva
+ Halom Vered
Heath Hayes
- Hysteria
Idzard Kwadijk
+ Isaac Clausman
Jared White
Jeff Nyte
Jeremy Sims
Jerry Ling
Joe Flood
+ John G Gentzel
+ Jon Hermansen
Jose Malheiro
Joshua Lesperance
Juan Velandia
Juraj Móza
- Kasper Jeppesen
kinfox
Marcelo Dornbusch Lopes
Markus Fehr
Markus Wiesner
Martin Eigel
- Marvin
Matt Eunson
Max Bulai
MuffinManKen
@@ -190,19 +203,23 @@ generous deed immortalized in the next stable release of Godot Engine.
pl
Ranoller
Robert Larnach
- Robin Arys
Rocknight Studios
Romildo Franco
- Ryan
Samuel Judd
Scott Pilet
+ Sean Morgan
+ SleepCircle
spilldata
+ Steve Hyatt
Stoned Xander
TheLevelOfDetail .
Thomas Krampl
Thomas Kurz
Tobias Bocanegra
+ Tricky Fat Cat
Urho
+ William Foster
+ Zhou Tuizhi
Zie Weaver
蕭惟允
@@ -214,7 +231,7 @@ generous deed immortalized in the next stable release of Godot Engine.
Adam Brunnmeier
Adam Carr
Adam Long
- Adam Nakonieczny
+ Adam McCurdy
Adam N Webber
Adam Smeltzer
Adam Szymański
@@ -223,21 +240,23 @@ generous deed immortalized in the next stable release of Godot Engine.
Agustinus Arya
Aidan O'Flannagain
Aki Mimoto
+ Alan Mervitz
+ Alan Stice
Albin Jonasson Svärdsby
Alder Stefano
Alessandro Senese
+ Alexander Erlemann
alex clavelle
- Alex Davies-Moore
+ Allan Davis
Allen Schade
Andreas Evers
Andreas Krampitz
André Simões
Andrew Thomas
- Andrzej Skalski
- Angelos Arnaoutis
Anthony Staunton
AP Condomines
Arda Erol
+ Armin Preiml
Arseniy M
Arthur S. Muszynski
Asger
@@ -253,28 +272,29 @@ generous deed immortalized in the next stable release of Godot Engine.
Black Block
Blair Allen
Bobby CC Wong
- Bryan Stevenson
+ brian
+ bugcaptor
+ Burney Waring
+ Cameron Meyer
Carl van der Geest
Carwyn Edwards
- Casey M.
+ Cassidy James
Chris Brown
Chris Chapin
- Christian Baune
Christian Winter
Christoffer Sundbom
+ Christoph Brodmann
Christopher Schmitt
Christoph Woinke
Clay Heaton
- Collin Shooltz
+ Curt King
+ Dancin Liao
Daniel Johnson
Daniel Kimblad
- DanielMaximiano
Daniel Pontillo
- Daniel Reed
David May
- David Rapisarda
David Woodard
- Dennis Idzikowsky
+ DiCola Jamn
Dominic Cooney
Dominik Wetzel
Donn Eddy
@@ -286,51 +306,61 @@ generous deed immortalized in the next stable release of Godot Engine.
Dylan Todd
Eduardo Teixeira
Edward Herbert
+ Edward Moulsdale
+ Edward Swartz
Egon Elbre
+ Elias Nykrem
Elmeri '- Duy Kevin Nguyen
+ Ephemeral
Eric Ellingson
+ Eric Rogers
Eric Williams
Erkki Seppälä
Evan Rose
Fancy Ants Studios
Fekinox
Felix Kollmann
- fengjiongmax
Flaredown
Forty Doubleu
FuDiggity
- G3Dev sàrl
Gadzhi Kharkharov
gamedev by Celio
- Gary Hulst
+ Gary Thomas
George Marques
GiulianoB
+ Gordian Arragon
Greg Olson
GREGORY C FEIN
Greg P
Greyson Richey
+ Grid
Guldoman
Hal A
Heribert Hirth
+ Hudson Thorpe-Doubble
Hunter Jones
Hylpher
+ Ichiro Dohi
Iiari
+ iKlem
IndustrialRobot
- Isaac Morton
Jaiden Gerig
Jaime Ruiz-Borau Vizárraga
Jako Danar
James A F Manley
+ Janders
Jannik Gröger
- Jax
+ JARKKO PARVIAINEN
+ Jarrod Davis
Jeff Hungerford
Jennifer Graves
Jeremy Kahn
Jesse Dubay
- Joe Alden
Joel Fivat
+ Joel Höglund
Joel Setterberg
Johannes Wuensch
+ John Gabriel
Jomei Jackson
Jonas Rudlang
Jonas Yamazaki
@@ -338,6 +368,7 @@ generous deed immortalized in the next stable release of Godot Engine.
Jonathon
Jon Bonazza
Jon Sully
+ Jorge Caballero
Jose Aleman
Jose C. Rubio
Joseph Catrambone
@@ -346,9 +377,8 @@ generous deed immortalized in the next stable release of Godot Engine.
Julian Murgia
JungleRobba
Justin Spedding
- Kaiser Bald0
+ KaDokta
Kauzig
- KC Chan
Keedong Park
Keith Bradner
Kevin McPhillips
@@ -356,40 +386,44 @@ generous deed immortalized in the next stable release of Godot Engine.
Kiyohiro Kawamura (kyorohiro)
Kjetil Haugland
Klagsam
- Klassix
KR McGinley
KsyTek Games
Kuan Cheang
kycho
+ Kyle Appelgate
+ Laurent Tréguier
Leonardo Dimano
Levi Lindsey
Linus Lind Lundgren
Lionel Gaillard
+ Luigi Renna
LunaticInAHat
Lurkars
Major Haul
Malcolm
Malik Ahmed
Malik Nejer
- Marcus Richter
Markus Michael Egger
Martin Holas
Martin Liška
+ Marvin
+ Mathieu Rimelen
+ Matt Edwards
Matthew Little
Matti Pohjanvirta
Maxime Blade
Maxwell
medecau
+ Megasploot
Melissa Mears
- M H
+ mewin
mhilbrunner
- Michael Dürwald
- Michael Gringauz
Michael Haney
Michael Labbe
Mikael Olsson
Mikayla
Mike Birkhead
+ Mike Cunningham
Mitchell J. Wagner
MoM
Nathan Fish
@@ -399,8 +433,8 @@ generous deed immortalized in the next stable release of Godot Engine.
Neil Wang
Nerdforge
Nicholas
+ Nicholas Girga
Nick Macholl
- Niclas Eriksen
Nicolás Montaña
Nicolas SAN AGUSTIN
Nima Farid
@@ -418,10 +452,7 @@ generous deed immortalized in the next stable release of Godot Engine.
Penguin
Petrus Prinsloo
Philip Cohoe
- Pierre-Igor Berthet
- Pitsanu Tongprasin
Point08
- Poryg
Rad Cat
Rafa Laguna
rainerLinux
@@ -431,13 +462,13 @@ generous deed immortalized in the next stable release of Godot Engine.
Ricardo Alcantara
Richard Diss
Richard Ivánek
- Richard Patching
Robert Farr (Larington)
Robert Hernandez
- Rodrigo Loli
+ Roberto Sánchez
Roger Smith
Roland Rząsa
Roman Tinkov
+ Ronald Ho Hip (CrimsonZA)
Ronan
Ryan Groom
Ryan Hentz
@@ -446,27 +477,29 @@ generous deed immortalized in the next stable release of Godot Engine.
Samuele Zolfanelli
Sasori Olkof
Scott D. Yelich
+ Scott Longley
Sebastian Michailidis
+ Sergio Mello-Grand
sgnsajgon
Shane
Shane Sicienski
Shane Spoor
+ Siim Raidma
Simon Wenner
SK
smbe19
- Stonepyre
+ smo1704
Svenne Krap
+ Terry
tezuvholovdr
thomas
Thomas Bechtold
+ Thomas Detoy
Thomas Kelly
- tiansheng li
Tim Drumheller
Timothy B. MacDonald
- tinyBigGames LLC
Tobbun
- Tom Fulp
- Tom Glenn
+ Torgeir Lilleskog
Torsten Crass
Travis O'Brien
Trent Skinner
@@ -476,7 +509,6 @@ generous deed immortalized in the next stable release of Godot Engine.
Tyler Compton
Tyler Stafos
UltyX
- Vaiktorg
Vaughan Ling
Victor
Vigilant Watch
@@ -487,7 +519,6 @@ generous deed immortalized in the next stable release of Godot Engine.
Wiley Thompson
Will
William Hogben
- Wout Standaert
Wyatt Goodin
Yegor
Yuri Sizov
diff --git a/core/debugger/debugger_marshalls.cpp b/core/debugger/debugger_marshalls.cpp
index 4bccf0805f..eb3a19506a 100644
--- a/core/debugger/debugger_marshalls.cpp
+++ b/core/debugger/debugger_marshalls.cpp
@@ -32,8 +32,8 @@
#include "core/io/marshalls.h"
-#define CHECK_SIZE(arr, expected, what) ERR_FAIL_COND_V_MSG((uint32_t)arr.size() < (uint32_t)(expected), false, String("Malformed ") + what + " message from script debugger, message too short. Exptected size: " + itos(expected) + ", actual size: " + itos(arr.size()))
-#define CHECK_END(arr, expected, what) ERR_FAIL_COND_V_MSG((uint32_t)arr.size() > (uint32_t)expected, false, String("Malformed ") + what + " message from script debugger, message too long. Exptected size: " + itos(expected) + ", actual size: " + itos(arr.size()))
+#define CHECK_SIZE(arr, expected, what) ERR_FAIL_COND_V_MSG((uint32_t)arr.size() < (uint32_t)(expected), false, String("Malformed ") + what + " message from script debugger, message too short. Expected size: " + itos(expected) + ", actual size: " + itos(arr.size()))
+#define CHECK_END(arr, expected, what) ERR_FAIL_COND_V_MSG((uint32_t)arr.size() > (uint32_t)expected, false, String("Malformed ") + what + " message from script debugger, message too long. Expected size: " + itos(expected) + ", actual size: " + itos(arr.size()))
Array DebuggerMarshalls::ResourceUsage::serialize() {
infos.sort();
diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp
index 7952391a27..5f7ffb115c 100644
--- a/core/debugger/remote_debugger.cpp
+++ b/core/debugger/remote_debugger.cpp
@@ -887,7 +887,7 @@ RemoteDebugger::RemoteDebugger(Ref<RemoteDebuggerPeer> p_peer) {
visual_profiler = memnew(VisualProfiler);
_bind_profiler("visual", visual_profiler);
- // Perfromance Profiler
+ // Performance Profiler
Object *perf = Engine::get_singleton()->get_singleton_object("Performance");
if (perf) {
performance_profiler = memnew(PerformanceProfiler(perf));
diff --git a/core/math/expression.cpp b/core/math/expression.cpp
index 058673b681..04fda9d09a 100644
--- a/core/math/expression.cpp
+++ b/core/math/expression.cpp
@@ -1839,7 +1839,7 @@ Expression::ENode *Expression::_parse_expression() {
}
}
- //consecutively do unary opeators
+ //consecutively do unary operators
for (int i = expr_pos - 1; i >= next_op; i--) {
OperatorNode *op = alloc_node<OperatorNode>();
diff --git a/core/os/mutex.cpp b/core/os/mutex.cpp
index 74c308f646..97297dca28 100644
--- a/core/os/mutex.cpp
+++ b/core/os/mutex.cpp
@@ -40,7 +40,11 @@ void _global_unlock() {
_global_mutex.unlock();
}
+#ifndef NO_THREADS
+
template class MutexImpl<std::recursive_mutex>;
template class MutexImpl<std::mutex>;
template class MutexLock<MutexImpl<std::recursive_mutex> >;
template class MutexLock<MutexImpl<std::mutex> >;
+
+#endif
diff --git a/core/os/mutex.h b/core/os/mutex.h
index 8d7b378d60..9033f0cb06 100644
--- a/core/os/mutex.h
+++ b/core/os/mutex.h
@@ -71,9 +71,22 @@ public:
}
};
+using Mutex = MutexImpl<std::recursive_mutex>; // Recursive, for general use
+using BinaryMutex = MutexImpl<std::mutex>; // Non-recursive, handle with care
+
+extern template class MutexImpl<std::recursive_mutex>;
+extern template class MutexImpl<std::mutex>;
+extern template class MutexLock<MutexImpl<std::recursive_mutex> >;
+extern template class MutexLock<MutexImpl<std::mutex> >;
+
#else
-template <class StdMutexType>
+class FakeMutex {
+
+ FakeMutex(){};
+};
+
+template <class MutexT>
class MutexImpl {
public:
_ALWAYS_INLINE_ void lock() const {}
@@ -87,14 +100,9 @@ public:
explicit MutexLock(const MutexT &p_mutex) {}
};
-#endif // !NO_THREADS
-
-using Mutex = MutexImpl<std::recursive_mutex>; // Recursive, for general use
-using BinaryMutex = MutexImpl<std::mutex>; // Non-recursive, handle with care
+using Mutex = MutexImpl<FakeMutex>;
+using BinaryMutex = MutexImpl<FakeMutex>; // Non-recursive, handle with care
-extern template class MutexImpl<std::recursive_mutex>;
-extern template class MutexImpl<std::mutex>;
-extern template class MutexLock<MutexImpl<std::recursive_mutex> >;
-extern template class MutexLock<MutexImpl<std::mutex> >;
+#endif // !NO_THREADS
#endif
diff --git a/doc/classes/CheckBox.xml b/doc/classes/CheckBox.xml
index c29f089bce..9c42091eb8 100644
--- a/doc/classes/CheckBox.xml
+++ b/doc/classes/CheckBox.xml
@@ -4,7 +4,7 @@
Binary choice user interface widget. See also [CheckButton].
</brief_description>
<description>
- A checkbox allows the user to make a binary choice (choosing only one of two possible options). It's similar to [CheckButton] in functionality, but it has a different apperance. To follow established UX patterns, it's recommended to use CheckBox when toggling it has [b]no[/b] immediate effect on something. For instance, it should be used when toggling it will only do something once a confirmation button is pressed.
+ A checkbox allows the user to make a binary choice (choosing only one of two possible options). It's similar to [CheckButton] in functionality, but it has a different appearance. To follow established UX patterns, it's recommended to use CheckBox when toggling it has [b]no[/b] immediate effect on something. For instance, it should be used when toggling it will only do something once a confirmation button is pressed.
</description>
<tutorials>
</tutorials>
diff --git a/doc/classes/CheckButton.xml b/doc/classes/CheckButton.xml
index 616940a494..514ff9a691 100644
--- a/doc/classes/CheckButton.xml
+++ b/doc/classes/CheckButton.xml
@@ -4,7 +4,7 @@
Checkable button. See also [CheckBox].
</brief_description>
<description>
- CheckButton is a toggle button displayed as a check field. It's similar to [CheckBox] in functionality, but it has a different apperance. To follow established UX patterns, it's recommended to use CheckButton when toggling it has an [b]immediate[/b] effect on something. For instance, it should be used if toggling it enables/disables a setting without requiring the user to press a confirmation button.
+ CheckButton is a toggle button displayed as a check field. It's similar to [CheckBox] in functionality, but it has a different appearance. To follow established UX patterns, it's recommended to use CheckButton when toggling it has an [b]immediate[/b] effect on something. For instance, it should be used if toggling it enables/disables a setting without requiring the user to press a confirmation button.
</description>
<tutorials>
</tutorials>
diff --git a/doc/classes/Geometry.xml b/doc/classes/Geometry.xml
index b2d77f6f92..4d6f7b60a3 100644
--- a/doc/classes/Geometry.xml
+++ b/doc/classes/Geometry.xml
@@ -70,7 +70,7 @@
</argument>
<description>
Clips [code]polygon_a[/code] against [code]polygon_b[/code] and returns an array of clipped polygons. This performs [constant OPERATION_DIFFERENCE] between polygons. Returns an empty array if [code]polygon_b[/code] completely overlaps [code]polygon_a[/code].
- If [code]polygon_b[/code] is enclosed by [code]polygon_a[/code], returns an outer polygon (boundary) and inner polygon (hole) which could be distiguished by calling [method is_polygon_clockwise].
+ If [code]polygon_b[/code] is enclosed by [code]polygon_a[/code], returns an outer polygon (boundary) and inner polygon (hole) which could be distinguished by calling [method is_polygon_clockwise].
</description>
</method>
<method name="clip_polyline_with_polygon_2d">
@@ -102,7 +102,7 @@
</argument>
<description>
Mutually excludes common area defined by intersection of [code]polygon_a[/code] and [code]polygon_b[/code] (see [method intersect_polygons_2d]) and returns an array of excluded polygons. This performs [constant OPERATION_XOR] between polygons. In other words, returns all but common area between polygons.
- The operation may result in an outer polygon (boundary) and inner polygon (hole) produced which could be distiguished by calling [method is_polygon_clockwise].
+ The operation may result in an outer polygon (boundary) and inner polygon (hole) produced which could be distinguished by calling [method is_polygon_clockwise].
</description>
</method>
<method name="get_closest_point_to_segment">
diff --git a/doc/classes/NavigationAgent.xml b/doc/classes/NavigationAgent.xml
index f896bf6d15..c6c9abec13 100644
--- a/doc/classes/NavigationAgent.xml
+++ b/doc/classes/NavigationAgent.xml
@@ -124,7 +124,7 @@
The distance to search for other agents.
</member>
<member name="path_max_distance" type="float" setter="set_path_max_distance" getter="get_path_max_distance" default="3.0">
- The maximum distance the agent is allowed away from the ideal path to the final location. This can happen due to trying to avoid collisions. When the maximum distance is exceded, it recalculates the ideal path.
+ The maximum distance the agent is allowed away from the ideal path to the final location. This can happen due to trying to avoid collisions. When the maximum distance is exceeded, it recalculates the ideal path.
</member>
<member name="radius" type="float" setter="set_radius" getter="get_radius" default="1.0">
The radius of the agent.
diff --git a/doc/classes/NavigationAgent2D.xml b/doc/classes/NavigationAgent2D.xml
index 116db76cc5..5a9c31ef67 100644
--- a/doc/classes/NavigationAgent2D.xml
+++ b/doc/classes/NavigationAgent2D.xml
@@ -118,7 +118,7 @@
The distance to search for other agents.
</member>
<member name="path_max_distance" type="float" setter="set_path_max_distance" getter="get_path_max_distance" default="3.0">
- The maximum distance the agent is allowed away from the ideal path to the final location. This can happen due to trying to avoid collisions. When the maximum distance is exceded, it recalculates the ideal path.
+ The maximum distance the agent is allowed away from the ideal path to the final location. This can happen due to trying to avoid collisions. When the maximum distance is exceeded, it recalculates the ideal path.
</member>
<member name="radius" type="float" setter="set_radius" getter="get_radius" default="10.0">
The radius of the agent.
diff --git a/doc/classes/NavigationRegion.xml b/doc/classes/NavigationRegion.xml
index 41fac70654..a32ded2878 100644
--- a/doc/classes/NavigationRegion.xml
+++ b/doc/classes/NavigationRegion.xml
@@ -13,7 +13,7 @@
<return type="void">
</return>
<description>
- Bakes the [NavigationMesh]. The baking is done in a seperate thread because navigation baking is not a cheap operation. This can be done at runtime. When it is completed, it automatically sets the new [NavigationMesh].
+ Bakes the [NavigationMesh]. The baking is done in a separate thread because navigation baking is not a cheap operation. This can be done at runtime. When it is completed, it automatically sets the new [NavigationMesh].
</description>
</method>
</methods>
diff --git a/doc/classes/PacketPeerUDP.xml b/doc/classes/PacketPeerUDP.xml
index aa5599a3fb..668655b725 100644
--- a/doc/classes/PacketPeerUDP.xml
+++ b/doc/classes/PacketPeerUDP.xml
@@ -25,7 +25,7 @@
</argument>
<description>
Calling this method connects this UDP peer to the given [code]host[/code]/[code]port[/code] pair. UDP is in reality connectionless, so this option only means that incoming packets from different addresses are automatically discarded, and that outgoing packets are always sent to the connected address (future calls to [method set_dest_address] are not allowed). This method does not send any data to the remote peer, to do that, use [method PacketPeer.put_var] or [method PacketPeer.put_packet] as usual. See also [UDPServer].
- Note: Connecting to the remote peer does not help to protect from malicious attacks like IP spoofing, etc. Think about using an encryption technique like SSL or DTLS if you feel like your application is transfering sensitive information.
+ Note: Connecting to the remote peer does not help to protect from malicious attacks like IP spoofing, etc. Think about using an encryption technique like SSL or DTLS if you feel like your application is transferring sensitive information.
</description>
</method>
<method name="get_packet_ip" qualifiers="const">
diff --git a/doc/classes/PhysicsServer.xml b/doc/classes/PhysicsServer.xml
index c9f4accee2..1b9ce80a1b 100644
--- a/doc/classes/PhysicsServer.xml
+++ b/doc/classes/PhysicsServer.xml
@@ -1388,7 +1388,7 @@
</constant>
<constant name="CONE_TWIST_JOINT_SWING_SPAN" value="0" enum="ConeTwistJointParam">
Swing is rotation from side to side, around the axis perpendicular to the twist axis.
- The swing span defines, how much rotation will not get corrected allong the swing axis.
+ The swing span defines, how much rotation will not get corrected along the swing axis.
Could be defined as looseness in the [ConeTwistJoint].
If below 0.05, this behavior is locked.
</constant>
diff --git a/doc/classes/VisualShaderNodeIf.xml b/doc/classes/VisualShaderNodeIf.xml
index 1ebd945d42..ad0b21a370 100644
--- a/doc/classes/VisualShaderNodeIf.xml
+++ b/doc/classes/VisualShaderNodeIf.xml
@@ -4,7 +4,7 @@
Compares two floating-point numbers in order to return a required vector within the visual shader graph.
</brief_description>
<description>
- First two ports are scalar floatin-point numbers to compare, third is tolerance comparsion amount and last three ports represents a vectors returned if [code]a == b[/code], [code]a &gt; b[/code] and [code]a &lt; b[/code] respectivly.
+ First two ports are scalar floatin-point numbers to compare, third is tolerance comparison amount and last three ports represents a vectors returned if [code]a == b[/code], [code]a &gt; b[/code] and [code]a &lt; b[/code] respectively.
</description>
<tutorials>
</tutorials>
diff --git a/drivers/SCsub b/drivers/SCsub
index 932014b540..41c20d81ad 100644
--- a/drivers/SCsub
+++ b/drivers/SCsub
@@ -23,7 +23,7 @@ SConscript('coremidi/SCsub')
SConscript('winmidi/SCsub')
# Graphics drivers
-if (env["platform"] != "server"):
+if (env["platform"] != "server" and env["platform"] != "javascript"):
# SConscript('gles2/SCsub')
SConscript('vulkan/SCsub')
SConscript('gl_context/SCsub')
diff --git a/drivers/dummy/rasterizer_dummy.h b/drivers/dummy/rasterizer_dummy.h
index fb23370863..4df28e3ea4 100644
--- a/drivers/dummy/rasterizer_dummy.h
+++ b/drivers/dummy/rasterizer_dummy.h
@@ -47,9 +47,18 @@ public:
void shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision) {}
bool shadow_atlas_update_light(RID p_atlas, RID p_light_intance, float p_coverage, uint64_t p_light_version) { return false; }
+ void directional_shadow_atlas_set_size(int p_size) {}
int get_directional_light_shadow_size(RID p_light_intance) { return 0; }
void set_directional_shadow_count(int p_count) {}
+ /* SKY API */
+
+ RID sky_create() { return RID(); }
+ void sky_set_radiance_size(RID p_sky, int p_radiance_size) {}
+ void sky_set_mode(RID p_sky, VS::SkyMode p_samples) {}
+ void sky_set_texture(RID p_sky, RID p_panorama) {}
+ void sky_set_texture(RID p_sky, RID p_cube_map, int p_radiance_size) {}
+
/* ENVIRONMENT API */
RID environment_create() { return RID(); }
@@ -61,17 +70,19 @@ public:
void environment_set_bg_color(RID p_env, const Color &p_color) {}
void environment_set_bg_energy(RID p_env, float p_energy) {}
void environment_set_canvas_max_layer(RID p_env, int p_max_layer) {}
- void environment_set_ambient_light(RID p_env, const Color &p_color, float p_energy = 1.0, float p_sky_contribution = 0.0) {}
- void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id){};
+ void environment_set_ambient_light(RID p_env, const Color &p_color, VS::EnvironmentAmbientSource p_ambient = VS::ENV_AMBIENT_SOURCE_BG, float p_energy = 1.0, float p_sky_contribution = 0.0, VS::EnvironmentReflectionSource p_reflection_source = VS::ENV_REFLECTION_SOURCE_BG, const Color &p_ao_color = Color()) {}
+// FIXME: Disabled during Vulkan refactoring, should be ported.
+#if 0
+ void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id) {}
+#endif
- void environment_set_dof_blur_near(RID p_env, bool p_enable, float p_distance, float p_transition, float p_far_amount, VS::EnvironmentDOFBlurQuality p_quality) {}
- void environment_set_dof_blur_far(RID p_env, bool p_enable, float p_distance, float p_transition, float p_far_amount, VS::EnvironmentDOFBlurQuality p_quality) {}
- void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_threshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, bool p_bicubic_upscale) {}
+ void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_mix, float p_bloom_threshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, bool p_bicubic_upscale) {}
void environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture) {}
void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance, bool p_roughness) {}
- void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect, float p_ao_channel_affect, const Color &p_color, VS::EnvironmentSSAOQuality p_quality, VS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness) {}
+ virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_bias, float p_light_affect, float p_ao_channel_affect, VS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness) {}
+ virtual void environment_set_ssao_quality(VS::EnvironmentSSAOQuality p_quality, bool p_half_size) {}
void environment_set_tonemap(RID p_env, VS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale) {}
@@ -81,9 +92,17 @@ public:
void environment_set_fog_depth(RID p_env, bool p_enable, float p_depth_begin, float p_depth_end, float p_depth_curve, bool p_transmit, float p_transmit_curve) {}
void environment_set_fog_height(RID p_env, bool p_enable, float p_min_height, float p_max_height, float p_height_curve) {}
- bool is_environment(RID p_env) { return false; }
- VS::EnvironmentBG environment_get_background(RID p_env) { return VS::ENV_BG_KEEP; }
- int environment_get_canvas_max_layer(RID p_env) { return 0; }
+ bool is_environment(RID p_env) const { return false; }
+ VS::EnvironmentBG environment_get_background(RID p_env) const { return VS::ENV_BG_KEEP; }
+ int environment_get_canvas_max_layer(RID p_env) const { return 0; }
+
+ virtual RID camera_effects_create() { return RID(); }
+
+ virtual void camera_effects_set_dof_blur_quality(VS::DOFBlurQuality p_quality, bool p_use_jitter) {}
+ virtual void camera_effects_set_dof_blur_bokeh_shape(VS::DOFBokehShape p_shape) {}
+
+ virtual void camera_effects_set_dof_blur(RID p_camera_effects, bool p_far_enable, float p_far_distance, float p_far_transition, bool p_near_enable, float p_near_distance, float p_near_transition, float p_amount) {}
+ virtual void camera_effects_set_custom_exposure(RID p_camera_effects, bool p_enable, float p_exposure) {}
RID light_instance_create(RID p_light) { return RID(); }
void light_instance_set_transform(RID p_light_instance, const Transform &p_transform) {}
@@ -91,8 +110,7 @@ public:
void light_instance_mark_visible(RID p_light_instance) {}
RID reflection_atlas_create() { return RID(); }
- void reflection_atlas_set_size(RID p_ref_atlas, int p_size) {}
- void reflection_atlas_set_subdivision(RID p_ref_atlas, int p_subdiv) {}
+ virtual void reflection_atlas_set_size(RID p_ref_atlas, int p_reflection_size, int p_reflection_count) {}
RID reflection_probe_instance_create(RID p_probe) { return RID(); }
void reflection_probe_instance_set_transform(RID p_instance, const Transform &p_transform) {}
@@ -102,18 +120,28 @@ public:
bool reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas) { return false; }
bool reflection_probe_instance_postprocess_step(RID p_instance) { return true; }
- RID gi_probe_instance_create() { return RID(); }
+ virtual RID gi_probe_instance_create(RID p_gi_probe) { return RID(); }
void gi_probe_instance_set_light_data(RID p_probe, RID p_base, RID p_data) {}
void gi_probe_instance_set_transform_to_data(RID p_probe, const Transform &p_xform) {}
- void gi_probe_instance_set_bounds(RID p_probe, const Vector3 &p_bounds) {}
+ virtual bool gi_probe_needs_update(RID p_probe) const { return false; }
+ virtual void gi_probe_update(RID p_probe, bool p_update_light_instances, const Vector<RID> &p_light_instances, int p_dynamic_object_count, InstanceBase **p_dynamic_objects) {}
- void 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) {}
+ virtual void render_scene(RID p_render_buffers, 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_gi_probe_cull_result, int p_gi_probe_cull_count, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) {}
void render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, InstanceBase **p_cull_result, int p_cull_count) {}
+ virtual void render_material(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID p_framebuffer, const Rect2i &p_region) {}
void set_scene_pass(uint64_t p_pass) {}
+ virtual void set_time(double p_time, double p_step) {}
void set_debug_draw_mode(VS::ViewportDebugDraw p_debug_draw) {}
+ virtual RID render_buffers_create() { return RID(); }
+ virtual void render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_width, int p_height, VS::ViewportMSAA p_msaa) {}
+
+ virtual void screen_space_roughness_limiter_set_active(bool p_enable, float p_curve) {}
+ virtual bool screen_space_roughness_limiter_is_active() const { return false; }
+
bool free(RID p_rid) { return true; }
+ virtual void update() {}
RasterizerSceneDummy() {}
~RasterizerSceneDummy() {}
@@ -152,6 +180,43 @@ public:
mutable RID_PtrOwner<DummyTexture> texture_owner;
mutable RID_PtrOwner<DummyMesh> mesh_owner;
+ virtual RID texture_2d_create(const Ref<Image> &p_image) { return RID(); }
+ virtual RID texture_2d_layered_create(const Vector<Ref<Image> > &p_layers, VS::TextureLayeredType p_layered_type) { return RID(); }
+ virtual RID texture_3d_create(const Vector<Ref<Image> > &p_slices) { return RID(); }
+ virtual RID texture_proxy_create(RID p_base) { return RID(); }
+
+ virtual void texture_2d_update_immediate(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) {}
+ virtual void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) {}
+ virtual void texture_3d_update(RID p_texture, const Ref<Image> &p_image, int p_depth, int p_mipmap) {}
+ virtual void texture_proxy_update(RID p_proxy, RID p_base) {}
+
+ virtual RID texture_2d_placeholder_create() { return RID(); }
+ virtual RID texture_2d_layered_placeholder_create() { return RID(); }
+ virtual RID texture_3d_placeholder_create() { return RID(); }
+
+ virtual Ref<Image> texture_2d_get(RID p_texture) const { return Ref<Image>(); }
+ virtual Ref<Image> texture_2d_layer_get(RID p_texture, int p_layer) const { return Ref<Image>(); }
+ virtual Ref<Image> texture_3d_slice_get(RID p_texture, int p_depth, int p_mipmap) const { return Ref<Image>(); }
+
+ virtual void texture_replace(RID p_texture, RID p_by_texture) {}
+ virtual void texture_set_size_override(RID p_texture, int p_width, int p_height) {}
+// FIXME: Disabled during Vulkan refactoring, should be ported.
+#if 0
+ virtual void texture_bind(RID p_texture, uint32_t p_texture_no) = 0;
+#endif
+
+ virtual void texture_set_path(RID p_texture, const String &p_path) {}
+ virtual String texture_get_path(RID p_texture) const { return String(); }
+
+ virtual void texture_set_detect_3d_callback(RID p_texture, VS::TextureDetectCallback p_callback, void *p_userdata) {}
+ virtual void texture_set_detect_normal_callback(RID p_texture, VS::TextureDetectCallback p_callback, void *p_userdata) {}
+ virtual void texture_set_detect_roughness_callback(RID p_texture, VS::TextureDetectRoughnessCallback p_callback, void *p_userdata) {}
+
+ virtual void texture_debug_usage(List<VS::TextureInfo> *r_info) {}
+ virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) {}
+ virtual Size2 texture_size_with_proxy(RID p_proxy) { return Size2(); }
+
+#if 0
RID texture_create() {
DummyTexture *texture = memnew(DummyTexture);
@@ -246,11 +311,7 @@ public:
void texture_set_proxy(RID p_proxy, RID p_base) {}
virtual Size2 texture_size_with_proxy(RID p_texture) const { return Size2(); }
void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) {}
-
- /* SKY API */
-
- RID sky_create() { return RID(); }
- void sky_set_texture(RID p_sky, RID p_cube_map, int p_radiance_size) {}
+#endif
/* SHADER API */
@@ -262,6 +323,7 @@ public:
void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) {}
RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const { return RID(); }
+ virtual Variant shader_get_param_default(RID p_material, const StringName &p_param) const { return Variant(); }
/* COMMON MATERIAL API */
@@ -269,21 +331,15 @@ public:
void material_set_render_priority(RID p_material, int priority) {}
void material_set_shader(RID p_shader_material, RID p_shader) {}
- RID material_get_shader(RID p_shader_material) const { return RID(); }
void material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) {}
Variant material_get_param(RID p_material, const StringName &p_param) const { return Variant(); }
- Variant material_get_param_default(RID p_material, const StringName &p_param) const { return Variant(); }
-
- void material_set_line_width(RID p_material, float p_width) {}
void material_set_next_pass(RID p_material, RID p_next_material) {}
bool material_is_animated(RID p_material) { return false; }
bool material_casts_shadows(RID p_material) { return false; }
-
- void material_add_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance) {}
- void material_remove_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance) {}
+ void material_update_dependency(RID p_material, RasterizerScene::InstanceBase *p_instance) {}
/* MESH API */
@@ -295,6 +351,9 @@ public:
return mesh_owner.make_rid(mesh);
}
+ void mesh_add_surface(RID p_mesh, const VS::SurfaceData &p_surface) {}
+
+#if 0
void mesh_add_surface(RID p_mesh, uint32_t p_format, VS::PrimitiveType p_primitive, const Vector<uint8_t> &p_array, int p_vertex_count, const Vector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<Vector<uint8_t> > &p_blend_shapes = Vector<Vector<uint8_t> >(), const Vector<AABB> &p_bone_aabbs = Vector<AABB>()) {
DummyMesh *m = mesh_owner.getornull(p_mesh);
ERR_FAIL_COND(!m);
@@ -317,6 +376,8 @@ public:
ERR_FAIL_COND(!m);
m->blend_shape_count = p_amount;
}
+#endif
+
int mesh_get_blend_shape_count(RID p_mesh) const {
DummyMesh *m = mesh_owner.getornull(p_mesh);
ERR_FAIL_COND_V(!m, 0);
@@ -339,6 +400,7 @@ public:
void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) {}
RID mesh_surface_get_material(RID p_mesh, int p_surface) const { return RID(); }
+#if 0
int mesh_surface_get_array_len(RID p_mesh, int p_surface) const {
DummyMesh *m = mesh_owner.getornull(p_mesh);
ERR_FAIL_COND_V(!m, 0);
@@ -404,6 +466,9 @@ public:
m->surfaces.remove(p_index);
}
+#endif
+
+ VS::SurfaceData mesh_get_surface(RID p_mesh, int p_surface) const { return VS::SurfaceData(); }
int mesh_get_surface_count(RID p_mesh) const {
DummyMesh *m = mesh_owner.getornull(p_mesh);
ERR_FAIL_COND_V(!m, 0);
@@ -413,14 +478,14 @@ public:
void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) {}
AABB mesh_get_custom_aabb(RID p_mesh) const { return AABB(); }
- AABB mesh_get_aabb(RID p_mesh, RID p_skeleton) const { return AABB(); }
+ AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID()) { return AABB(); }
void mesh_clear(RID p_mesh) {}
/* MULTIMESH API */
virtual RID multimesh_create() { return RID(); }
- void multimesh_allocate(RID p_multimesh, int p_instances, VS::MultimeshTransformFormat p_transform_format, VS::MultimeshColorFormat p_color_format, VS::MultimeshCustomDataFormat p_data = VS::MULTIMESH_CUSTOM_DATA_NONE) {}
+ virtual void multimesh_allocate(RID p_multimesh, int p_instances, VS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false) {}
int multimesh_get_instance_count(RID p_multimesh) const { return 0; }
void multimesh_set_mesh(RID p_multimesh, RID p_mesh) {}
@@ -430,19 +495,18 @@ public:
void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) {}
RID multimesh_get_mesh(RID p_multimesh) const { return RID(); }
+ AABB multimesh_get_aabb(RID p_multimesh) const { return AABB(); }
Transform multimesh_instance_get_transform(RID p_multimesh, int p_index) const { return Transform(); }
Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const { return Transform2D(); }
Color multimesh_instance_get_color(RID p_multimesh, int p_index) const { return Color(); }
Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const { return Color(); }
-
- void multimesh_set_as_bulk_array(RID p_multimesh, const Vector<float> &p_array) {}
+ virtual void multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) {}
+ virtual Vector<float> multimesh_get_buffer(RID p_multimesh) const { return Vector<float>(); }
void multimesh_set_visible_instances(RID p_multimesh, int p_visible) {}
int multimesh_get_visible_instances(RID p_multimesh) const { return 0; }
- AABB multimesh_get_aabb(RID p_multimesh) const { return AABB(); }
-
/* IMMEDIATE API */
RID immediate_create() { return RID(); }
@@ -490,7 +554,6 @@ public:
void light_set_use_gi(RID p_light, bool p_enabled) {}
void light_omni_set_shadow_mode(RID p_light, VS::LightOmniShadowMode p_mode) {}
- void light_omni_set_shadow_detail(RID p_light, VS::LightOmniShadowDetail p_detail) {}
void light_directional_set_shadow_mode(RID p_light, VS::LightDirectionalShadowMode p_mode) {}
void light_directional_set_blend_splits(RID p_light, bool p_enable) {}
@@ -536,57 +599,55 @@ public:
float reflection_probe_get_origin_max_distance(RID p_probe) const { return 0.0; }
bool reflection_probe_renders_shadows(RID p_probe) const { return false; }
- void instance_add_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance) {}
- void instance_remove_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance) {}
-
- void instance_add_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) {}
- void instance_remove_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) {}
+ virtual void base_update_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) {}
+ virtual void skeleton_update_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) {}
/* GI PROBE API */
RID gi_probe_create() { return RID(); }
- void gi_probe_set_bounds(RID p_probe, const AABB &p_bounds) {}
- AABB gi_probe_get_bounds(RID p_probe) const { return AABB(); }
+ virtual void gi_probe_allocate(RID p_gi_probe, const Transform &p_to_cell_xform, const AABB &p_aabb, const Vector3i &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts) {}
- void gi_probe_set_cell_size(RID p_probe, float p_range) {}
- float gi_probe_get_cell_size(RID p_probe) const { return 0.0; }
+ virtual AABB gi_probe_get_bounds(RID p_gi_probe) const { return AABB(); }
+ virtual Vector3i gi_probe_get_octree_size(RID p_gi_probe) const { return Vector3i(); }
+ virtual Vector<uint8_t> gi_probe_get_octree_cells(RID p_gi_probe) const { return Vector<uint8_t>(); }
+ virtual Vector<uint8_t> gi_probe_get_data_cells(RID p_gi_probe) const { return Vector<uint8_t>(); }
+ virtual Vector<uint8_t> gi_probe_get_distance_field(RID p_gi_probe) const { return Vector<uint8_t>(); }
- void gi_probe_set_to_cell_xform(RID p_probe, const Transform &p_xform) {}
- Transform gi_probe_get_to_cell_xform(RID p_probe) const { return Transform(); }
+ virtual Vector<int> gi_probe_get_level_counts(RID p_gi_probe) const { return Vector<int>(); }
+ virtual Transform gi_probe_get_to_cell_xform(RID p_gi_probe) const { return Transform(); }
- void gi_probe_set_dynamic_data(RID p_probe, const Vector<int> &p_data) {}
- Vector<int> gi_probe_get_dynamic_data(RID p_probe) const {
- Vector<int> p;
- return p;
- }
+ virtual void gi_probe_set_dynamic_range(RID p_gi_probe, float p_range) {}
+ virtual float gi_probe_get_dynamic_range(RID p_gi_probe) const { return 0; }
+
+ virtual void gi_probe_set_propagation(RID p_gi_probe, float p_range) {}
+ virtual float gi_probe_get_propagation(RID p_gi_probe) const { return 0; }
- void gi_probe_set_dynamic_range(RID p_probe, int p_range) {}
- int gi_probe_get_dynamic_range(RID p_probe) const { return 0; }
+ void gi_probe_set_energy(RID p_gi_probe, float p_range) {}
+ float gi_probe_get_energy(RID p_gi_probe) const { return 0.0; }
- void gi_probe_set_energy(RID p_probe, float p_range) {}
- float gi_probe_get_energy(RID p_probe) const { return 0.0; }
+ virtual void gi_probe_set_ao(RID p_gi_probe, float p_ao) {}
+ virtual float gi_probe_get_ao(RID p_gi_probe) const { return 0; }
- void gi_probe_set_bias(RID p_probe, float p_range) {}
- float gi_probe_get_bias(RID p_probe) const { return 0.0; }
+ virtual void gi_probe_set_ao_size(RID p_gi_probe, float p_strength) {}
+ virtual float gi_probe_get_ao_size(RID p_gi_probe) const { return 0; }
- void gi_probe_set_normal_bias(RID p_probe, float p_range) {}
- float gi_probe_get_normal_bias(RID p_probe) const { return 0.0; }
+ void gi_probe_set_bias(RID p_gi_probe, float p_range) {}
+ float gi_probe_get_bias(RID p_gi_probe) const { return 0.0; }
- void gi_probe_set_propagation(RID p_probe, float p_range) {}
- float gi_probe_get_propagation(RID p_probe) const { return 0.0; }
+ void gi_probe_set_normal_bias(RID p_gi_probe, float p_range) {}
+ float gi_probe_get_normal_bias(RID p_gi_probe) const { return 0.0; }
- void gi_probe_set_interior(RID p_probe, bool p_enable) {}
- bool gi_probe_is_interior(RID p_probe) const { return false; }
+ void gi_probe_set_interior(RID p_gi_probe, bool p_enable) {}
+ bool gi_probe_is_interior(RID p_gi_probe) const { return false; }
- void gi_probe_set_compress(RID p_probe, bool p_enable) {}
- bool gi_probe_is_compressed(RID p_probe) const { return false; }
+ virtual void gi_probe_set_use_two_bounces(RID p_gi_probe, bool p_enable) {}
+ virtual bool gi_probe_is_using_two_bounces(RID p_gi_probe) const { return false; }
- uint32_t gi_probe_get_version(RID p_probe) { return 0; }
+ virtual void gi_probe_set_anisotropy_strength(RID p_gi_probe, float p_strength) {}
+ virtual float gi_probe_get_anisotropy_strength(RID p_gi_probe) const { return 0; }
- GIProbeCompression gi_probe_get_dynamic_data_get_preferred_compression() const { return GI_PROBE_UNCOMPRESSED; }
- RID gi_probe_dynamic_data_create(int p_width, int p_height, int p_depth, GIProbeCompression p_compression) { return RID(); }
- void gi_probe_dynamic_data_update(RID p_gi_probe_data, int p_depth_slice, int p_slice_count, int p_mipmap, const void *p_data) {}
+ uint32_t gi_probe_get_version(RID p_gi_probe) { return 0; }
/* LIGHTMAP CAPTURE */
struct Instantiable {
@@ -598,7 +659,7 @@ public:
SelfList<RasterizerScene::InstanceBase> *instances = instance_list.first();
while (instances) {
- instances->self()->base_changed(p_aabb, p_materials);
+ //instances->self()->base_changed(p_aabb, p_materials);
instances = instances->next();
}
}
@@ -608,7 +669,7 @@ public:
while (instances) {
SelfList<RasterizerScene::InstanceBase> *next = instances->next();
- instances->self()->base_removed();
+ //instances->self()->base_removed();
instances = next;
}
}
@@ -697,21 +758,17 @@ public:
RID render_target_create() { return RID(); }
void render_target_set_position(RID p_render_target, int p_x, int p_y) {}
void render_target_set_size(RID p_render_target, int p_width, int p_height) {}
- RID render_target_get_texture(RID p_render_target) const { return RID(); }
+ RID render_target_get_texture(RID p_render_target) { return RID(); }
void render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id) {}
void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value) {}
bool render_target_was_used(RID p_render_target) { return false; }
void render_target_set_as_unused(RID p_render_target) {}
- void render_target_set_msaa(RID p_render_target, VS::ViewportMSAA p_msaa) {}
-
- /* CANVAS SHADOW */
-
- RID canvas_light_shadow_buffer_create(int p_width) { return RID(); }
- /* LIGHT SHADOW MAPPING */
-
- RID canvas_light_occluder_create() { return RID(); }
- void canvas_light_occluder_set_polylines(RID p_occluder, const Vector<Vector2> &p_lines) {}
+ virtual void render_target_request_clear(RID p_render_target, const Color &p_clear_color) {}
+ virtual bool render_target_is_clear_requested(RID p_render_target) { return false; }
+ virtual Color render_target_get_clear_request_color(RID p_render_target) { return Color(); }
+ virtual void render_target_disable_clear_request(RID p_render_target) {}
+ virtual void render_target_do_clear_request(RID p_render_target) {}
VS::InstanceType get_base_type(RID p_rid) const {
if (mesh_owner.owns(p_rid)) {
@@ -748,28 +805,43 @@ public:
static RasterizerStorage *base_singleton;
- RasterizerStorageDummy(){};
+ virtual void capture_timestamps_begin() {}
+ virtual void capture_timestamp(const String &p_name) {}
+ virtual uint32_t get_captured_timestamps_count() const { return 0; }
+ virtual uint64_t get_captured_timestamps_frame() const { return 0; }
+ virtual uint64_t get_captured_timestamp_gpu_time(uint32_t p_index) const { return 0; }
+ virtual uint64_t get_captured_timestamp_cpu_time(uint32_t p_index) const { return 0; }
+ virtual String get_captured_timestamp_name(uint32_t p_index) const { return String(); }
+
+ RasterizerStorageDummy() {}
~RasterizerStorageDummy() {}
};
class RasterizerCanvasDummy : public RasterizerCanvas {
public:
- RID light_internal_create() { return RID(); }
- void light_internal_update(RID p_rid, Light *p_light) {}
- void light_internal_free(RID p_rid) {}
+ virtual TextureBindingID request_texture_binding(RID p_texture, RID p_normalmap, RID p_specular, VS::CanvasItemTextureFilter p_filter, VS::CanvasItemTextureRepeat p_repeat, RID p_multimesh) { return 0; }
+ virtual void free_texture_binding(TextureBindingID p_binding) {}
- void canvas_begin(){};
- void canvas_end(){};
+ virtual PolygonID request_polygon(const Vector<int> &p_indices, const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs = Vector<Point2>(), const Vector<int> &p_bones = Vector<int>(), const Vector<float> &p_weights = Vector<float>()) { return 0; }
+ virtual void free_polygon(PolygonID p_polygon) {}
- void canvas_render_items(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_transform){};
- void canvas_debug_viewport_shadows(Light *p_lights_with_shadow){};
+ virtual void canvas_render_items(RID p_to_render_target, Item *p_item_list, const Color &p_modulate, Light *p_light_list, const Transform2D &p_canvas_transform) {}
+ virtual void canvas_debug_viewport_shadows(Light *p_lights_with_shadow) {}
- void canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache) {}
+ virtual RID light_create() { return RID(); }
+ virtual void light_set_texture(RID p_rid, RID p_texture) {}
+ virtual void light_set_use_shadow(RID p_rid, bool p_enable, int p_resolution) {}
+ virtual void light_update_shadow(RID p_rid, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders) {}
- void reset_canvas() {}
+ virtual RID occluder_polygon_create() { return RID(); }
+ virtual void occluder_polygon_set_shape_as_lines(RID p_occluder, const Vector<Vector2> &p_lines) {}
+ virtual void occluder_polygon_set_cull_mode(RID p_occluder, VS::CanvasOccluderPolygonCullMode p_mode) {}
void draw_window_margins(int *p_margins, RID *p_margin_textures) {}
+ virtual bool free(RID p_rid) { return true; }
+ virtual void update() {}
+
RasterizerCanvasDummy() {}
~RasterizerCanvasDummy() {}
};
@@ -789,11 +861,10 @@ public:
void initialize() {}
void begin_frame(double frame_step) {}
- void set_current_render_target(RID p_render_target) {}
- void restore_render_target(bool p_3d_was_drawn) {}
- void clear_render_target(const Color &p_color) {}
- void blit_render_target_to_screen(RID p_render_target, const Rect2 &p_screen_rect, int p_screen = 0) {}
- void output_lens_distorted_to_screen(RID p_render_target, const Rect2 &p_screen_rect, float p_k1, float p_k2, const Vector2 &p_eye_center, float p_oversample) {}
+
+ virtual void prepare_for_blitting_render_targets() {}
+ virtual void blit_render_targets_to_screen(int p_screen, const BlitToScreen *p_render_targets, int p_amount) {}
+
void end_frame(bool p_swap_buffers) { OS::get_singleton()->swap_buffers(); }
void finalize() {}
diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp
index 920f4d858a..3d567ed2b3 100644
--- a/editor/debugger/script_editor_debugger.cpp
+++ b/editor/debugger/script_editor_debugger.cpp
@@ -1425,7 +1425,7 @@ void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) {
void ScriptEditorDebugger::_tab_changed(int p_tab) {
if (tabs->get_tab_title(p_tab) == TTR("Video RAM")) {
- // "Video RAM" tab was clicked, refresh the data it's dislaying when entering the tab.
+ // "Video RAM" tab was clicked, refresh the data it's displaying when entering the tab.
_video_mem_request();
}
}
diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp
index 92ecda8508..0090d30b9c 100644
--- a/editor/import/resource_importer_texture.cpp
+++ b/editor/import/resource_importer_texture.cpp
@@ -350,7 +350,7 @@ void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String
f->store_32(flags);
f->store_32(p_limit_mipmap);
- //reserverd for future use
+ //reserved for future use
f->store_32(0);
f->store_32(0);
f->store_32(0);
diff --git a/modules/basis_universal/SCsub b/modules/basis_universal/SCsub
index d7342358d7..63324e920b 100644
--- a/modules/basis_universal/SCsub
+++ b/modules/basis_universal/SCsub
@@ -22,7 +22,6 @@ tool_sources = [
"basisu_resample_filters.cpp",
"basisu_resampler.cpp",
"basisu_ssim.cpp",
- "basisu_tool.cpp",
"lodepng.cpp",
]
tool_sources = [thirdparty_dir + file for file in tool_sources]
diff --git a/modules/csg/csg.cpp b/modules/csg/csg.cpp
index e9ca1d3e5b..4e39cce4a5 100644
--- a/modules/csg/csg.cpp
+++ b/modules/csg/csg.cpp
@@ -88,7 +88,7 @@ static inline bool ray_intersects_triangle(const Vector3 &p_from, const Vector3
Vector3 edge2 = p_vertices[2] - p_vertices[0];
Vector3 h = p_dir.cross(edge2);
real_t a = edge1.dot(h);
- // Check if ray is parrallel to triangle.
+ // Check if ray is parallel to triangle.
if (Math::is_zero_approx(a))
return false;
real_t f = 1.0 / a;
@@ -818,7 +818,7 @@ void CSGBrushOperation::Build2DFaces::_add_vertex_idx_sorted(Vector<int> &r_vert
int axis = 0;
if (Math::abs(new_point.x - first_point.x) < Math::abs(new_point.y - first_point.y)) axis = 1;
- // Add it to the beginnig or the end appropriately.
+ // Add it to the beginning or the end appropriately.
if (new_point[axis] < first_point[axis])
r_vertex_indices.insert(0, p_new_vertex_index);
else
@@ -868,7 +868,7 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_
inner_idx = p_segment_indices[segments + segments / 2 - sorted_idx];
}
- // Find the mergable faces.
+ // Find the mergeable faces.
Vector<int> merge_faces_idx;
Vector<Face2D> merge_faces;
Vector<int> merge_faces_inner_vertex_idx;
diff --git a/modules/enet/doc_classes/NetworkedMultiplayerENet.xml b/modules/enet/doc_classes/NetworkedMultiplayerENet.xml
index 456bf649d2..860da32a22 100644
--- a/modules/enet/doc_classes/NetworkedMultiplayerENet.xml
+++ b/modules/enet/doc_classes/NetworkedMultiplayerENet.xml
@@ -134,7 +134,7 @@
The compression method used for network packets. These have different tradeoffs of compression speed versus bandwidth, you may need to test which one works best for your use case if you use compression at all.
</member>
<member name="dtls_verify" type="bool" setter="set_dtls_verify_enabled" getter="is_dtls_verify_enabled" default="true">
- Enable or disable certiticate verification when [member use_dtls] [code]true[/code].
+ Enable or disable certificate verification when [member use_dtls] [code]true[/code].
</member>
<member name="refuse_new_connections" type="bool" setter="set_refuse_new_connections" getter="is_refusing_new_connections" override="true" default="false" />
<member name="server_relay" type="bool" setter="set_server_relay_enabled" getter="is_server_relay_enabled" default="true">
diff --git a/modules/gdnavigation/gd_navigation_server.cpp b/modules/gdnavigation/gd_navigation_server.cpp
index 4db10cda78..a1f6ddfedc 100644
--- a/modules/gdnavigation/gd_navigation_server.cpp
+++ b/modules/gdnavigation/gd_navigation_server.cpp
@@ -41,7 +41,7 @@
*/
/// Creates a struct for each function and a function that once called creates
-/// an instance of that struct with the submited parameters.
+/// an instance of that struct with the submitted parameters.
/// Then, that struct is stored in an array; the `sync` function consume that array.
#define COMMAND_1(F_NAME, T_0, D_0) \
diff --git a/modules/gdnavigation/nav_map.cpp b/modules/gdnavigation/nav_map.cpp
index 00a1901c48..338e49eb9f 100644
--- a/modules/gdnavigation/nav_map.cpp
+++ b/modules/gdnavigation/nav_map.cpp
@@ -691,7 +691,7 @@ void NavMap::sync() {
const float ecm_squared(edge_connection_margin * edge_connection_margin);
#define LEN_TOLLERANCE 0.1
#define DIR_TOLLERANCE 0.9
- // In front of tollerance
+ // In front of tolerance
#define IFO_TOLLERANCE 0.5
// Find the compatible near edges.
@@ -715,7 +715,7 @@ void NavMap::sync() {
Vector3 rel_centers = other_edge.edge_center - edge.edge_center;
if (ecm_squared > rel_centers.length_squared() // Are enough closer?
&& ABS(edge.edge_len_squared - other_edge.edge_len_squared) < LEN_TOLLERANCE // Are the same length?
- && ABS(edge.edge_dir.dot(other_edge.edge_dir)) > DIR_TOLLERANCE // Are alligned?
+ && ABS(edge.edge_dir.dot(other_edge.edge_dir)) > DIR_TOLLERANCE // Are aligned?
&& ABS(rel_centers.normalized().dot(edge.edge_dir)) < IFO_TOLLERANCE // Are one in front the other?
) {
// The edges can be connected
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index 353c79d6bb..b42fcba7d3 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -1517,7 +1517,7 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
}
}
- //consecutively do unary opeators
+ //consecutively do unary operators
for (int i = expr_pos - 1; i >= next_op; i--) {
OperatorNode *op = alloc_node<OperatorNode>();
diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp
index 23d1c8ccc0..c52315a477 100644
--- a/modules/visual_script/visual_script_expression.cpp
+++ b/modules/visual_script/visual_script_expression.cpp
@@ -1141,7 +1141,7 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
}
}
- //consecutively do unary opeators
+ //consecutively do unary operators
for (int i = expr_pos - 1; i >= next_op; i--) {
OperatorNode *op = alloc_node<OperatorNode>();
diff --git a/modules/websocket/emws_peer.cpp b/modules/websocket/emws_peer.cpp
index f396a1c812..9472daa620 100644
--- a/modules/websocket/emws_peer.cpp
+++ b/modules/websocket/emws_peer.cpp
@@ -90,12 +90,11 @@ Error EMWSPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
if (_in_buffer.packets_left() == 0)
return ERR_UNAVAILABLE;
- uint8_t *rw = _packet_buffer.ptrw();
int read = 0;
- Error err = _in_buffer.read_packet(rw.ptr(), _packet_buffer.size(), &_is_string, read);
+ Error err = _in_buffer.read_packet(_packet_buffer.ptrw(), _packet_buffer.size(), &_is_string, read);
ERR_FAIL_COND_V(err != OK, err);
- *r_buffer = rw.ptr();
+ *r_buffer = _packet_buffer.ptr();
r_buffer_size = read;
return OK;
diff --git a/platform/javascript/SCsub b/platform/javascript/SCsub
index 85a633442e..d3cd8f76b7 100644
--- a/platform/javascript/SCsub
+++ b/platform/javascript/SCsub
@@ -10,8 +10,11 @@ javascript_files = [
'os_javascript.cpp',
]
-build = env.add_program(['#bin/godot${PROGSUFFIX}.js', '#bin/godot${PROGSUFFIX}.wasm'], javascript_files);
-js, wasm = build
+build_targets = ['#bin/godot${PROGSUFFIX}.js', '#bin/godot${PROGSUFFIX}.wasm']
+if env['threads_enabled']:
+ build_targets.append('#bin/godot${PROGSUFFIX}.worker.js')
+
+build = env.add_program(build_targets, javascript_files)
js_libraries = [
'http_request.js',
@@ -27,18 +30,38 @@ for module in js_modules:
env.Append(LINKFLAGS=['--pre-js', env.File(module).path])
env.Depends(build, js_modules)
-wrapper_start = env.File('pre.js')
-wrapper_end = env.File('engine.js')
-js_wrapped = env.Textfile('#bin/godot', [wrapper_start, js, wrapper_end], TEXTFILESUFFIX='${PROGSUFFIX}.wrapped.js')
+engine = [
+ 'engine/preloader.js',
+ 'engine/loader.js',
+ 'engine/utils.js',
+ 'engine/engine.js',
+]
+externs = [
+ env.File('#platform/javascript/engine/externs.js')
+]
+js_engine = env.CreateEngineFile('#bin/godot${PROGSUFFIX}.engine.js', engine, externs)
+env.Depends(js_engine, externs)
+
+wrap_list = [
+ build[0],
+ js_engine,
+]
+js_wrapped = env.Textfile('#bin/godot', [env.File(f) for f in wrap_list], TEXTFILESUFFIX='${PROGSUFFIX}.wrapped.js')
zip_dir = env.Dir('#bin/.javascript_zip')
-zip_files = env.InstallAs([
+out_files = [
zip_dir.File('godot.js'),
zip_dir.File('godot.wasm'),
zip_dir.File('godot.html')
-], [
+]
+in_files = [
js_wrapped,
- wasm,
+ build[1],
'#misc/dist/html/full-size.html'
-])
+]
+if env['threads_enabled']:
+ in_files.append(build[2])
+ out_files.append(zip_dir.File('godot.worker.js'))
+
+zip_files = env.InstallAs(out_files, in_files)
env.Zip('#bin/godot', zip_files, ZIPROOT=zip_dir, ZIPSUFFIX='${PROGSUFFIX}${ZIPSUFFIX}', ZIPCOMSTR='Archving $SOURCES as $TARGET')
diff --git a/platform/javascript/audio_driver_javascript.cpp b/platform/javascript/audio_driver_javascript.cpp
index f1bc7c4382..d63c6a40a5 100644
--- a/platform/javascript/audio_driver_javascript.cpp
+++ b/platform/javascript/audio_driver_javascript.cpp
@@ -69,31 +69,37 @@ void AudioDriverJavaScript::process_capture(float sample) {
Error AudioDriverJavaScript::init() {
/* clang-format off */
- EM_ASM({
- _audioDriver_audioContext = new (window.AudioContext || window.webkitAudioContext);
- _audioDriver_audioInput = null;
- _audioDriver_inputStream = null;
- _audioDriver_scriptNode = null;
+ _driver_id = EM_ASM_INT({
+ return Module.IDHandler.add({
+ 'context': new (window.AudioContext || window.webkitAudioContext),
+ 'input': null,
+ 'stream': null,
+ 'script': null
+ });
});
/* clang-format on */
int channel_count = get_total_channels_by_speaker_mode(get_speaker_mode());
/* clang-format off */
buffer_length = EM_ASM_INT({
- var CHANNEL_COUNT = $0;
+ var ref = Module.IDHandler.get($0);
+ var ctx = ref['context'];
+ var CHANNEL_COUNT = $1;
- var channelCount = _audioDriver_audioContext.destination.channelCount;
+ var channelCount = ctx.destination.channelCount;
+ var script = null;
try {
// Try letting the browser recommend a buffer length.
- _audioDriver_scriptNode = _audioDriver_audioContext.createScriptProcessor(0, 2, channelCount);
+ script = ctx.createScriptProcessor(0, 2, channelCount);
} catch (e) {
// ...otherwise, default to 4096.
- _audioDriver_scriptNode = _audioDriver_audioContext.createScriptProcessor(4096, 2, channelCount);
+ script = ctx.createScriptProcessor(4096, 2, channelCount);
}
- _audioDriver_scriptNode.connect(_audioDriver_audioContext.destination);
+ script.connect(ctx.destination);
+ ref['script'] = script;
- return _audioDriver_scriptNode.bufferSize;
- }, channel_count);
+ return script.bufferSize;
+ }, _driver_id, channel_count);
/* clang-format on */
if (!buffer_length) {
return FAILED;
@@ -112,11 +118,12 @@ void AudioDriverJavaScript::start() {
/* clang-format off */
EM_ASM({
- var INTERNAL_BUFFER_PTR = $0;
+ const ref = Module.IDHandler.get($0);
+ var INTERNAL_BUFFER_PTR = $1;
var audioDriverMixFunction = cwrap('audio_driver_js_mix');
var audioDriverProcessCapture = cwrap('audio_driver_process_capture', null, ['number']);
- _audioDriver_scriptNode.onaudioprocess = function(audioProcessingEvent) {
+ ref['script'].onaudioprocess = function(audioProcessingEvent) {
audioDriverMixFunction();
var input = audioProcessingEvent.inputBuffer;
@@ -133,7 +140,7 @@ void AudioDriverJavaScript::start() {
}
}
- if (_audioDriver_audioInput) {
+ if (ref['input']) {
var inputDataL = input.getChannelData(0);
var inputDataR = input.getChannelData(1);
for (var i = 0; i < inputDataL.length; i++) {
@@ -142,34 +149,37 @@ void AudioDriverJavaScript::start() {
}
}
};
- }, internal_buffer);
+ }, _driver_id, internal_buffer);
/* clang-format on */
}
void AudioDriverJavaScript::resume() {
/* clang-format off */
EM_ASM({
- if (_audioDriver_audioContext.resume)
- _audioDriver_audioContext.resume();
- });
+ const ref = Module.IDHandler.get($0);
+ if (ref && ref['context'] && ref['context'].resume)
+ ref['context'].resume();
+ }, _driver_id);
/* clang-format on */
}
int AudioDriverJavaScript::get_mix_rate() const {
/* clang-format off */
- return EM_ASM_INT_V({
- return _audioDriver_audioContext.sampleRate;
- });
+ return EM_ASM_INT({
+ const ref = Module.IDHandler.get($0);
+ return ref && ref['context'] ? ref['context'].sampleRate : 0;
+ }, _driver_id);
/* clang-format on */
}
AudioDriver::SpeakerMode AudioDriverJavaScript::get_speaker_mode() const {
/* clang-format off */
- return get_speaker_mode_by_total_channels(EM_ASM_INT_V({
- return _audioDriver_audioContext.destination.channelCount;
- }));
+ return get_speaker_mode_by_total_channels(EM_ASM_INT({
+ const ref = Module.IDHandler.get($0);
+ return ref && ref['context'] ? ref['context'].destination.channelCount : 0;
+ }, _driver_id));
/* clang-format on */
}
@@ -184,16 +194,15 @@ void AudioDriverJavaScript::finish() {
/* clang-format off */
EM_ASM({
- _audioDriver_audioContext = null;
- _audioDriver_audioInput = null;
- _audioDriver_scriptNode = null;
- });
+ Module.IDHandler.remove($0);
+ }, _driver_id);
/* clang-format on */
if (internal_buffer) {
memdelete_arr(internal_buffer);
internal_buffer = NULL;
}
+ _driver_id = 0;
}
Error AudioDriverJavaScript::capture_start() {
@@ -203,9 +212,10 @@ Error AudioDriverJavaScript::capture_start() {
/* clang-format off */
EM_ASM({
function gotMediaInput(stream) {
- _audioDriver_inputStream = stream;
- _audioDriver_audioInput = _audioDriver_audioContext.createMediaStreamSource(stream);
- _audioDriver_audioInput.connect(_audioDriver_scriptNode);
+ var ref = Module.IDHandler.get($0);
+ ref['stream'] = stream;
+ ref['input'] = ref['context'].createMediaStreamSource(stream);
+ ref['input'].connect(ref['script']);
}
function gotMediaInputError(e) {
@@ -219,7 +229,7 @@ Error AudioDriverJavaScript::capture_start() {
navigator.getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
navigator.getUserMedia({"audio": true}, gotMediaInput, gotMediaInputError);
}
- });
+ }, _driver_id);
/* clang-format on */
return OK;
@@ -229,20 +239,21 @@ Error AudioDriverJavaScript::capture_stop() {
/* clang-format off */
EM_ASM({
- if (_audioDriver_inputStream) {
- const tracks = _audioDriver_inputStream.getTracks();
+ var ref = Module.IDHandler.get($0);
+ if (ref['stream']) {
+ const tracks = ref['stream'].getTracks();
for (var i = 0; i < tracks.length; i++) {
tracks[i].stop();
}
- _audioDriver_inputStream = null;
+ ref['stream'] = null;
}
- if (_audioDriver_audioInput) {
- _audioDriver_audioInput.disconnect();
- _audioDriver_audioInput = null;
+ if (ref['input']) {
+ ref['input'].disconnect();
+ ref['input'] = null;
}
- });
+ }, _driver_id);
/* clang-format on */
input_buffer.clear();
@@ -252,7 +263,9 @@ Error AudioDriverJavaScript::capture_stop() {
AudioDriverJavaScript::AudioDriverJavaScript() {
+ _driver_id = 0;
internal_buffer = NULL;
+ buffer_length = 0;
singleton = this;
}
diff --git a/platform/javascript/audio_driver_javascript.h b/platform/javascript/audio_driver_javascript.h
index 2bb97ba192..f6f2dacd4e 100644
--- a/platform/javascript/audio_driver_javascript.h
+++ b/platform/javascript/audio_driver_javascript.h
@@ -37,6 +37,7 @@ class AudioDriverJavaScript : public AudioDriver {
float *internal_buffer;
+ int _driver_id;
int buffer_length;
public:
diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py
index 1766833364..fb02752aa7 100644
--- a/platform/javascript/detect.py
+++ b/platform/javascript/detect.py
@@ -1,5 +1,6 @@
import os
+from emscripten_helpers import parse_config, run_closure_compiler, create_engine_file
def is_active():
return True
@@ -18,6 +19,8 @@ def get_opts():
return [
# eval() can be a security concern, so it can be disabled.
BoolVariable('javascript_eval', 'Enable JavaScript eval interface', True),
+ BoolVariable('threads_enabled', 'Enable WebAssembly Threads support (limited browser support)', False),
+ BoolVariable('use_closure_compiler', 'Use closure compiler to minimize Javascript code', False),
]
@@ -37,7 +40,7 @@ def configure(env):
## Build type
- if env['target'] != 'debug':
+ if env['target'] == 'release':
# Use -Os to prioritize optimizing for reduced file size. This is
# particularly valuable for the web platform because it directly
# decreases download time.
@@ -46,38 +49,55 @@ def configure(env):
# run-time performance.
env.Append(CCFLAGS=['-Os'])
env.Append(LINKFLAGS=['-Os'])
- if env['target'] == 'release_debug':
- env.Append(CPPDEFINES=['DEBUG_ENABLED'])
- # Retain function names for backtraces at the cost of file size.
- env.Append(LINKFLAGS=['--profiling-funcs'])
- else:
+ elif env['target'] == 'release_debug':
+ env.Append(CCFLAGS=['-Os'])
+ env.Append(LINKFLAGS=['-Os'])
+ env.Append(CPPDEFINES=['DEBUG_ENABLED'])
+ # Retain function names for backtraces at the cost of file size.
+ env.Append(LINKFLAGS=['--profiling-funcs'])
+ else: # 'debug'
env.Append(CPPDEFINES=['DEBUG_ENABLED'])
env.Append(CCFLAGS=['-O1', '-g'])
env.Append(LINKFLAGS=['-O1', '-g'])
env.Append(LINKFLAGS=['-s', 'ASSERTIONS=1'])
- ## Compiler configuration
+ if env['tools']:
+ if not env['threads_enabled']:
+ raise RuntimeError("Threads must be enabled to build the editor. Please add the 'threads_enabled=yes' option")
+ # Tools need more memory. Initial stack memory in bytes. See `src/settings.js` in emscripten repository (will be renamed to INITIAL_MEMORY).
+ env.Append(LINKFLAGS=['-s', 'TOTAL_MEMORY=33554432'])
+ else:
+ # Disable exceptions and rtti on non-tools (template) builds
+ # These flags help keep the file size down.
+ env.Append(CCFLAGS=['-fno-exceptions', '-fno-rtti'])
+ # Don't use dynamic_cast, necessary with no-rtti.
+ env.Append(CPPDEFINES=['NO_SAFE_CAST'])
+ ## Copy env variables.
env['ENV'] = os.environ
- em_config_file = os.getenv('EM_CONFIG') or os.path.expanduser('~/.emscripten')
- if not os.path.exists(em_config_file):
- raise RuntimeError("Emscripten configuration file '%s' does not exist" % em_config_file)
- with open(em_config_file) as f:
- em_config = {}
- try:
- # Emscripten configuration file is a Python file with simple assignments.
- exec(f.read(), em_config)
- except StandardError as e:
- raise RuntimeError("Emscripten configuration file '%s' is invalid:\n%s" % (em_config_file, e))
- if 'BINARYEN_ROOT' in em_config and os.path.isdir(os.path.join(em_config.get('BINARYEN_ROOT'), 'emscripten')):
- # New style, emscripten path as a subfolder of BINARYEN_ROOT
- env.PrependENVPath('PATH', os.path.join(em_config.get('BINARYEN_ROOT'), 'emscripten'))
- elif 'EMSCRIPTEN_ROOT' in em_config:
- # Old style (but can be there as a result from previous activation, so do last)
- env.PrependENVPath('PATH', em_config.get('EMSCRIPTEN_ROOT'))
- else:
- raise RuntimeError("'BINARYEN_ROOT' or 'EMSCRIPTEN_ROOT' missing in Emscripten configuration file '%s'" % em_config_file)
+ # LTO
+ if env['use_lto']:
+ env.Append(CCFLAGS=['-s', 'WASM_OBJECT_FILES=0'])
+ env.Append(LINKFLAGS=['-s', 'WASM_OBJECT_FILES=0'])
+ env.Append(LINKFLAGS=['--llvm-lto', '1'])
+
+ # Closure compiler
+ if env['use_closure_compiler']:
+ # For emscripten support code.
+ env.Append(LINKFLAGS=['--closure', '1'])
+ # Register builder for our Engine files
+ jscc = env.Builder(generator=run_closure_compiler, suffix='.cc.js', src_suffix='.js')
+ env.Append(BUILDERS = {'BuildJS' : jscc})
+
+ # Add method that joins/compiles our Engine files.
+ env.AddMethod(create_engine_file, "CreateEngineFile")
+
+ # Closure compiler extern and support for ecmascript specs (const, let, etc).
+ env['ENV']['EMCC_CLOSURE_ARGS'] = '--language_in ECMASCRIPT6'
+
+ em_config = parse_config()
+ env.PrependENVPath('PATH', em_config['EMCC_ROOT'])
env['CC'] = 'emcc'
env['CXX'] = 'em++'
@@ -104,44 +124,31 @@ def configure(env):
env['LIBPREFIXES'] = ['$LIBPREFIX']
env['LIBSUFFIXES'] = ['$LIBSUFFIX']
- ## Compile flags
-
env.Prepend(CPPPATH=['#platform/javascript'])
env.Append(CPPDEFINES=['JAVASCRIPT_ENABLED', 'UNIX_ENABLED'])
- # No multi-threading (SharedArrayBuffer) available yet,
- # once feasible also consider memory buffer size issues.
- env.Append(CPPDEFINES=['NO_THREADS'])
-
- # Disable exceptions and rtti on non-tools (template) builds
- if not env['tools']:
- # These flags help keep the file size down.
- env.Append(CCFLAGS=['-fno-exceptions', '-fno-rtti'])
- # Don't use dynamic_cast, necessary with no-rtti.
- env.Append(CPPDEFINES=['NO_SAFE_CAST'])
-
if env['javascript_eval']:
env.Append(CPPDEFINES=['JAVASCRIPT_EVAL_ENABLED'])
- ## Link flags
+ # Thread support (via SharedArrayBuffer).
+ if env['threads_enabled']:
+ env.Append(CPPDEFINES=['PTHREAD_NO_RENAME'])
+ env.Append(CCFLAGS=['-s', 'USE_PTHREADS=1'])
+ env.Append(LINKFLAGS=['-s', 'USE_PTHREADS=1'])
+ env.Append(LINKFLAGS=['-s', 'PTHREAD_POOL_SIZE=4'])
+ env.Append(LINKFLAGS=['-s', 'WASM_MEM_MAX=2048MB'])
+ else:
+ env.Append(CPPDEFINES=['NO_THREADS'])
+
+ # Reduce code size by generating less support code (e.g. skip NodeJS support).
+ env.Append(LINKFLAGS=['-s', 'ENVIRONMENT=web,worker'])
# We use IDBFS in javascript_main.cpp. Since Emscripten 1.39.1 it needs to
# be linked explicitly.
env.Append(LIBS=['idbfs.js'])
env.Append(LINKFLAGS=['-s', 'BINARYEN=1'])
-
- # Only include the JavaScript support code for the web environment
- # (i.e. exclude Node.js and other unused environments).
- # This makes the JavaScript support code about 4 KB smaller.
- env.Append(LINKFLAGS=['-s', 'ENVIRONMENT=web'])
-
- # This needs to be defined for Emscripten using 'fastcomp' (default pre-1.39.0)
- # and undefined if using 'upstream'. And to make things simple, earlier
- # Emscripten versions didn't include 'fastcomp' in their path, so we check
- # against the presence of 'upstream' to conditionally add the flag.
- if not "upstream" in em_config['EMSCRIPTEN_ROOT']:
- env.Append(LINKFLAGS=['-s', 'BINARYEN_TRAP_MODE=\'clamp\''])
+ env.Append(LINKFLAGS=['-s', 'MODULARIZE=1', '-s', 'EXPORT_NAME="Godot"'])
# Allow increasing memory buffer size during runtime. This is efficient
# when using WebAssembly (in comparison to asm.js) and works well for
@@ -153,8 +160,5 @@ def configure(env):
env.Append(LINKFLAGS=['-s', 'INVOKE_RUN=0'])
- # TODO: Reevaluate usage of this setting now that engine.js manages engine runtime.
- env.Append(LINKFLAGS=['-s', 'NO_EXIT_RUNTIME=1'])
-
- #adding flag due to issue with emscripten 1.38.41 callMain method https://github.com/emscripten-core/emscripten/blob/incoming/ChangeLog.md#v13841-08072019
- env.Append(LINKFLAGS=['-s', 'EXTRA_EXPORTED_RUNTIME_METHODS=["callMain"]'])
+ # callMain for manual start, FS for preloading.
+ env.Append(LINKFLAGS=['-s', 'EXTRA_EXPORTED_RUNTIME_METHODS=["callMain", "FS"]'])
diff --git a/platform/javascript/emscripten_helpers.py b/platform/javascript/emscripten_helpers.py
new file mode 100644
index 0000000000..bda5b40a74
--- /dev/null
+++ b/platform/javascript/emscripten_helpers.py
@@ -0,0 +1,37 @@
+import os
+
+def parse_config():
+ em_config_file = os.getenv('EM_CONFIG') or os.path.expanduser('~/.emscripten')
+ if not os.path.exists(em_config_file):
+ raise RuntimeError("Emscripten configuration file '%s' does not exist" % em_config_file)
+
+ normalized = {}
+ em_config = {}
+ with open(em_config_file) as f:
+ try:
+ # Emscripten configuration file is a Python file with simple assignments.
+ exec(f.read(), em_config)
+ except StandardError as e:
+ raise RuntimeError("Emscripten configuration file '%s' is invalid:\n%s" % (em_config_file, e))
+ normalized['EMCC_ROOT'] = em_config.get('EMSCRIPTEN_ROOT')
+ normalized['NODE_JS'] = em_config.get('NODE_JS')
+ normalized['CLOSURE_BIN'] = os.path.join(normalized['EMCC_ROOT'], 'node_modules', '.bin', 'google-closure-compiler')
+ return normalized
+
+
+def run_closure_compiler(target, source, env, for_signature):
+ cfg = parse_config()
+ cmd = [cfg['NODE_JS'], cfg['CLOSURE_BIN']]
+ cmd.extend(['--compilation_level', 'ADVANCED_OPTIMIZATIONS'])
+ for f in env['JSEXTERNS']:
+ cmd.extend(['--externs', f.get_abspath()])
+ for f in source:
+ cmd.extend(['--js', f.get_abspath()])
+ cmd.extend(['--js_output_file', target[0].get_abspath()])
+ return ' '.join(cmd)
+
+
+def create_engine_file(env, target, source, externs):
+ if env['use_closure_compiler']:
+ return env.BuildJS(target, source, JSEXTERNS=externs)
+ return env.Textfile(target, [env.File(s) for s in source])
diff --git a/platform/javascript/engine.js b/platform/javascript/engine.js
deleted file mode 100644
index 227accadb0..0000000000
--- a/platform/javascript/engine.js
+++ /dev/null
@@ -1,411 +0,0 @@
- // The following is concatenated with generated code, and acts as the end
- // of a wrapper for said code. See pre.js for the other part of the
- // wrapper.
- exposedLibs['PATH'] = PATH;
- exposedLibs['FS'] = FS;
- return Module;
- },
-};
-
-(function() {
- var engine = Engine;
-
- var DOWNLOAD_ATTEMPTS_MAX = 4;
-
- var basePath = null;
- var wasmFilenameExtensionOverride = null;
- var engineLoadPromise = null;
-
- var loadingFiles = {};
-
- function getPathLeaf(path) {
-
- while (path.endsWith('/'))
- path = path.slice(0, -1);
- return path.slice(path.lastIndexOf('/') + 1);
- }
-
- function getBasePath(path) {
-
- if (path.endsWith('/'))
- path = path.slice(0, -1);
- if (path.lastIndexOf('.') > path.lastIndexOf('/'))
- path = path.slice(0, path.lastIndexOf('.'));
- return path;
- }
-
- function getBaseName(path) {
-
- return getPathLeaf(getBasePath(path));
- }
-
- Engine = function Engine() {
-
- this.rtenv = null;
-
- var LIBS = {};
-
- var initPromise = null;
- var unloadAfterInit = true;
-
- var preloadedFiles = [];
-
- var resizeCanvasOnStart = true;
- var progressFunc = null;
- var preloadProgressTracker = {};
- var lastProgress = { loaded: 0, total: 0 };
-
- var canvas = null;
- var executableName = null;
- var locale = null;
- var stdout = null;
- var stderr = null;
-
- this.init = function(newBasePath) {
-
- if (!initPromise) {
- initPromise = Engine.load(newBasePath).then(
- instantiate.bind(this)
- );
- requestAnimationFrame(animateProgress);
- if (unloadAfterInit)
- initPromise.then(Engine.unloadEngine);
- }
- return initPromise;
- };
-
- function instantiate(wasmBuf) {
-
- var rtenvProps = {
- engine: this,
- ENV: {},
- };
- if (typeof stdout === 'function')
- rtenvProps.print = stdout;
- if (typeof stderr === 'function')
- rtenvProps.printErr = stderr;
- rtenvProps.instantiateWasm = function(imports, onSuccess) {
- WebAssembly.instantiate(wasmBuf, imports).then(function(result) {
- onSuccess(result.instance);
- });
- return {};
- };
-
- return new Promise(function(resolve, reject) {
- rtenvProps.onRuntimeInitialized = resolve;
- rtenvProps.onAbort = reject;
- rtenvProps.thisProgram = executableName;
- rtenvProps.engine.rtenv = Engine.RuntimeEnvironment(rtenvProps, LIBS);
- });
- }
-
- this.preloadFile = function(pathOrBuffer, destPath) {
-
- if (pathOrBuffer instanceof ArrayBuffer) {
- pathOrBuffer = new Uint8Array(pathOrBuffer);
- } else if (ArrayBuffer.isView(pathOrBuffer)) {
- pathOrBuffer = new Uint8Array(pathOrBuffer.buffer);
- }
- if (pathOrBuffer instanceof Uint8Array) {
- preloadedFiles.push({
- path: destPath,
- buffer: pathOrBuffer
- });
- return Promise.resolve();
- } else if (typeof pathOrBuffer === 'string') {
- return loadPromise(pathOrBuffer, preloadProgressTracker).then(function(xhr) {
- preloadedFiles.push({
- path: destPath || pathOrBuffer,
- buffer: xhr.response
- });
- });
- } else {
- throw Promise.reject("Invalid object for preloading");
- }
- };
-
- this.start = function() {
-
- return this.init().then(
- Function.prototype.apply.bind(synchronousStart, this, arguments)
- );
- };
-
- this.startGame = function(execName, mainPack) {
-
- executableName = execName;
- var mainArgs = [ '--main-pack', getPathLeaf(mainPack) ];
-
- return Promise.all([
- this.init(getBasePath(execName)),
- this.preloadFile(mainPack, getPathLeaf(mainPack))
- ]).then(
- Function.prototype.apply.bind(synchronousStart, this, mainArgs)
- );
- };
-
- function synchronousStart() {
-
- if (canvas instanceof HTMLCanvasElement) {
- this.rtenv.canvas = canvas;
- } else {
- var firstCanvas = document.getElementsByTagName('canvas')[0];
- if (firstCanvas instanceof HTMLCanvasElement) {
- this.rtenv.canvas = firstCanvas;
- } else {
- throw new Error("No canvas found");
- }
- }
-
- var actualCanvas = this.rtenv.canvas;
- // canvas can grab focus on click
- if (actualCanvas.tabIndex < 0) {
- actualCanvas.tabIndex = 0;
- }
- // necessary to calculate cursor coordinates correctly
- actualCanvas.style.padding = 0;
- actualCanvas.style.borderWidth = 0;
- actualCanvas.style.borderStyle = 'none';
- // disable right-click context menu
- actualCanvas.addEventListener('contextmenu', function(ev) {
- ev.preventDefault();
- }, false);
- // until context restoration is implemented
- actualCanvas.addEventListener('webglcontextlost', function(ev) {
- alert("WebGL context lost, please reload the page");
- ev.preventDefault();
- }, false);
-
- if (locale) {
- this.rtenv.locale = locale;
- } else {
- this.rtenv.locale = navigator.languages ? navigator.languages[0] : navigator.language;
- }
- this.rtenv.locale = this.rtenv.locale.split('.')[0];
- this.rtenv.resizeCanvasOnStart = resizeCanvasOnStart;
-
- preloadedFiles.forEach(function(file) {
- var dir = LIBS.PATH.dirname(file.path);
- try {
- LIBS.FS.stat(dir);
- } catch (e) {
- if (e.code !== 'ENOENT') {
- throw e;
- }
- LIBS.FS.mkdirTree(dir);
- }
- // With memory growth, canOwn should be false.
- LIBS.FS.createDataFile(file.path, null, new Uint8Array(file.buffer), true, true, false);
- }, this);
-
- preloadedFiles = null;
- initPromise = null;
- this.rtenv.callMain(arguments);
- }
-
- this.setProgressFunc = function(func) {
- progressFunc = func;
- };
-
- this.setResizeCanvasOnStart = function(enabled) {
- resizeCanvasOnStart = enabled;
- };
-
- function animateProgress() {
-
- var loaded = 0;
- var total = 0;
- var totalIsValid = true;
- var progressIsFinal = true;
-
- [loadingFiles, preloadProgressTracker].forEach(function(tracker) {
- Object.keys(tracker).forEach(function(file) {
- if (!tracker[file].final)
- progressIsFinal = false;
- if (!totalIsValid || tracker[file].total === 0) {
- totalIsValid = false;
- total = 0;
- } else {
- total += tracker[file].total;
- }
- loaded += tracker[file].loaded;
- });
- });
- if (loaded !== lastProgress.loaded || total !== lastProgress.total) {
- lastProgress.loaded = loaded;
- lastProgress.total = total;
- if (typeof progressFunc === 'function')
- progressFunc(loaded, total);
- }
- if (!progressIsFinal)
- requestAnimationFrame(animateProgress);
- }
-
- this.setCanvas = function(elem) {
- canvas = elem;
- };
-
- this.setExecutableName = function(newName) {
-
- executableName = newName;
- };
-
- this.setLocale = function(newLocale) {
-
- locale = newLocale;
- };
-
- this.setUnloadAfterInit = function(enabled) {
-
- if (enabled && !unloadAfterInit && initPromise) {
- initPromise.then(Engine.unloadEngine);
- }
- unloadAfterInit = enabled;
- };
-
- this.setStdoutFunc = function(func) {
-
- var print = function(text) {
- if (arguments.length > 1) {
- text = Array.prototype.slice.call(arguments).join(" ");
- }
- func(text);
- };
- if (this.rtenv)
- this.rtenv.print = print;
- stdout = print;
- };
-
- this.setStderrFunc = function(func) {
-
- var printErr = function(text) {
- if (arguments.length > 1)
- text = Array.prototype.slice.call(arguments).join(" ");
- func(text);
- };
- if (this.rtenv)
- this.rtenv.printErr = printErr;
- stderr = printErr;
- };
-
-
- }; // Engine()
-
- Engine.RuntimeEnvironment = engine.RuntimeEnvironment;
-
- Engine.isWebGLAvailable = function(majorVersion = 1) {
-
- var testContext = false;
- try {
- var testCanvas = document.createElement('canvas');
- if (majorVersion === 1) {
- testContext = testCanvas.getContext('webgl') || testCanvas.getContext('experimental-webgl');
- } else if (majorVersion === 2) {
- testContext = testCanvas.getContext('webgl2') || testCanvas.getContext('experimental-webgl2');
- }
- } catch (e) {}
- return !!testContext;
- };
-
- Engine.setWebAssemblyFilenameExtension = function(override) {
-
- if (String(override).length === 0) {
- throw new Error('Invalid WebAssembly filename extension override');
- }
- wasmFilenameExtensionOverride = String(override);
- }
-
- Engine.load = function(newBasePath) {
-
- if (newBasePath !== undefined) basePath = getBasePath(newBasePath);
- if (engineLoadPromise === null) {
- if (typeof WebAssembly !== 'object')
- return Promise.reject(new Error("Browser doesn't support WebAssembly"));
- // TODO cache/retrieve module to/from idb
- engineLoadPromise = loadPromise(basePath + '.' + (wasmFilenameExtensionOverride || 'wasm')).then(function(xhr) {
- return xhr.response;
- });
- engineLoadPromise = engineLoadPromise.catch(function(err) {
- engineLoadPromise = null;
- throw err;
- });
- }
- return engineLoadPromise;
- };
-
- Engine.unload = function() {
- engineLoadPromise = null;
- };
-
- function loadPromise(file, tracker) {
- if (tracker === undefined)
- tracker = loadingFiles;
- return new Promise(function(resolve, reject) {
- loadXHR(resolve, reject, file, tracker);
- });
- }
-
- function loadXHR(resolve, reject, file, tracker) {
-
- var xhr = new XMLHttpRequest;
- xhr.open('GET', file);
- if (!file.endsWith('.js')) {
- xhr.responseType = 'arraybuffer';
- }
- ['loadstart', 'progress', 'load', 'error', 'abort'].forEach(function(ev) {
- xhr.addEventListener(ev, onXHREvent.bind(xhr, resolve, reject, file, tracker));
- });
- xhr.send();
- }
-
- function onXHREvent(resolve, reject, file, tracker, ev) {
-
- if (this.status >= 400) {
-
- if (this.status < 500 || ++tracker[file].attempts >= DOWNLOAD_ATTEMPTS_MAX) {
- reject(new Error("Failed loading file '" + file + "': " + this.statusText));
- this.abort();
- return;
- } else {
- setTimeout(loadXHR.bind(null, resolve, reject, file, tracker), 1000);
- }
- }
-
- switch (ev.type) {
- case 'loadstart':
- if (tracker[file] === undefined) {
- tracker[file] = {
- total: ev.total,
- loaded: ev.loaded,
- attempts: 0,
- final: false,
- };
- }
- break;
-
- case 'progress':
- tracker[file].loaded = ev.loaded;
- tracker[file].total = ev.total;
- break;
-
- case 'load':
- tracker[file].final = true;
- resolve(this);
- break;
-
- case 'error':
- if (++tracker[file].attempts >= DOWNLOAD_ATTEMPTS_MAX) {
- tracker[file].final = true;
- reject(new Error("Failed loading file '" + file + "'"));
- } else {
- setTimeout(loadXHR.bind(null, resolve, reject, file, tracker), 1000);
- }
- break;
-
- case 'abort':
- tracker[file].final = true;
- reject(new Error("Loading file '" + file + "' was aborted."));
- break;
- }
- }
-})();
diff --git a/platform/javascript/engine/engine.js b/platform/javascript/engine/engine.js
new file mode 100644
index 0000000000..6d7509377f
--- /dev/null
+++ b/platform/javascript/engine/engine.js
@@ -0,0 +1,184 @@
+Function('return this')()['Engine'] = (function() {
+
+ var unloadAfterInit = true;
+ var canvas = null;
+ var resizeCanvasOnStart = false;
+ var customLocale = 'en_US';
+ var wasmExt = '.wasm';
+
+ var preloader = new Preloader();
+ var loader = new Loader();
+ var rtenv = null;
+
+ var executableName = '';
+ var loadPath = '';
+ var loadPromise = null;
+ var initPromise = null;
+ var stderr = null;
+ var stdout = null;
+ var progressFunc = null;
+
+ function load(basePath) {
+ if (loadPromise == null) {
+ loadPath = basePath;
+ loadPromise = preloader.loadPromise(basePath + wasmExt);
+ preloader.setProgressFunc(progressFunc);
+ requestAnimationFrame(preloader.animateProgress);
+ }
+ return loadPromise;
+ };
+
+ function unload() {
+ loadPromise = null;
+ };
+
+ /** @constructor */
+ function Engine() {};
+
+ Engine.prototype.init = /** @param {string=} basePath */ function(basePath) {
+ if (initPromise) {
+ return initPromise;
+ }
+ if (!loadPromise) {
+ if (!basePath) {
+ initPromise = Promise.reject(new Error("A base path must be provided when calling `init` and the engine is not loaded."));
+ return initPromise;
+ }
+ load(basePath);
+ }
+ var config = {}
+ if (typeof stdout === 'function')
+ config.print = stdout;
+ if (typeof stderr === 'function')
+ config.printErr = stderr;
+ initPromise = loader.init(loadPromise, loadPath, config).then(function() {
+ return new Promise(function(resolve, reject) {
+ rtenv = loader.env;
+ if (unloadAfterInit) {
+ loadPromise = null;
+ }
+ resolve();
+ });
+ });
+ return initPromise;
+ };
+
+ /** @type {function(string, string):Object} */
+ Engine.prototype.preloadFile = function(file, path) {
+ return preloader.preload(file, path);
+ };
+
+ /** @type {function(...string):Object} */
+ Engine.prototype.start = function() {
+ // Start from arguments.
+ var args = [];
+ for (var i = 0; i < arguments.length; i++) {
+ args.push(arguments[i]);
+ }
+ var me = this;
+ return new Promise(function(resolve, reject) {
+ return me.init().then(function() {
+ if (!(canvas instanceof HTMLCanvasElement)) {
+ canvas = Utils.findCanvas();
+ }
+ rtenv['locale'] = customLocale;
+ rtenv['canvas'] = canvas;
+ rtenv['thisProgram'] = executableName;
+ rtenv['resizeCanvasOnStart'] = resizeCanvasOnStart;
+ loader.start(preloader.preloadedFiles, args).then(function() {
+ loader = null;
+ initPromise = null;
+ resolve();
+ });
+ });
+ });
+ };
+
+ Engine.prototype.startGame = function(execName, mainPack) {
+ // Start and init with execName as loadPath if not inited.
+ executableName = execName;
+ var me = this;
+ return Promise.all([
+ this.init(execName),
+ this.preloadFile(mainPack, mainPack)
+ ]).then(function() {
+ return me.start('--main-pack', mainPack);
+ });
+ };
+
+ Engine.prototype.setWebAssemblyFilenameExtension = function(override) {
+ if (String(override).length === 0) {
+ throw new Error('Invalid WebAssembly filename extension override');
+ }
+ wasmExt = String(override);
+ };
+
+ Engine.prototype.setUnloadAfterInit = function(enabled) {
+ unloadAfterInit = enabled;
+ };
+
+ Engine.prototype.setCanvas = function(canvasElem) {
+ canvas = canvasElem;
+ };
+
+ Engine.prototype.setCanvasResizedOnStart = function(enabled) {
+ resizeCanvasOnStart = enabled;
+ };
+
+ Engine.prototype.setLocale = function(locale) {
+ customLocale = locale;
+ };
+
+ Engine.prototype.setExecutableName = function(newName) {
+ executableName = newName;
+ };
+
+ Engine.prototype.setProgressFunc = function(func) {
+ progressFunc = func;
+ }
+
+ Engine.prototype.setStdoutFunc = function(func) {
+
+ var print = function(text) {
+ if (arguments.length > 1) {
+ text = Array.prototype.slice.call(arguments).join(" ");
+ }
+ func(text);
+ };
+ if (rtenv)
+ rtenv.print = print;
+ stdout = print;
+ };
+
+ Engine.prototype.setStderrFunc = function(func) {
+
+ var printErr = function(text) {
+ if (arguments.length > 1)
+ text = Array.prototype.slice.call(arguments).join(" ");
+ func(text);
+ };
+ if (rtenv)
+ rtenv.printErr = printErr;
+ stderr = printErr;
+ };
+
+ // Closure compiler exported engine methods.
+ /** @export */
+ Engine['isWebGLAvailable'] = Utils.isWebGLAvailable;
+ Engine['load'] = load;
+ Engine['unload'] = unload;
+ Engine.prototype['init'] = Engine.prototype.init
+ Engine.prototype['preloadFile'] = Engine.prototype.preloadFile
+ Engine.prototype['start'] = Engine.prototype.start
+ Engine.prototype['startGame'] = Engine.prototype.startGame
+ Engine.prototype['setWebAssemblyFilenameExtension'] = Engine.prototype.setWebAssemblyFilenameExtension
+ Engine.prototype['setUnloadAfterInit'] = Engine.prototype.setUnloadAfterInit
+ Engine.prototype['setCanvas'] = Engine.prototype.setCanvas
+ Engine.prototype['setCanvasResizedOnStart'] = Engine.prototype.setCanvasResizedOnStart
+ Engine.prototype['setLocale'] = Engine.prototype.setLocale
+ Engine.prototype['setExecutableName'] = Engine.prototype.setExecutableName
+ Engine.prototype['setProgressFunc'] = Engine.prototype.setProgressFunc
+ Engine.prototype['setStdoutFunc'] = Engine.prototype.setStdoutFunc
+ Engine.prototype['setStderrFunc'] = Engine.prototype.setStderrFunc
+ return Engine;
+})();
diff --git a/platform/javascript/engine/externs.js b/platform/javascript/engine/externs.js
new file mode 100644
index 0000000000..1a94dd15ec
--- /dev/null
+++ b/platform/javascript/engine/externs.js
@@ -0,0 +1,3 @@
+var Godot;
+var WebAssembly = {};
+WebAssembly.instantiate = function(buffer, imports) {};
diff --git a/platform/javascript/engine/loader.js b/platform/javascript/engine/loader.js
new file mode 100644
index 0000000000..d27fbf612e
--- /dev/null
+++ b/platform/javascript/engine/loader.js
@@ -0,0 +1,33 @@
+var Loader = /** @constructor */ function() {
+
+ this.env = null;
+
+ this.init = function(loadPromise, basePath, config) {
+ var me = this;
+ return new Promise(function(resolve, reject) {
+ var cfg = config || {};
+ cfg['locateFile'] = Utils.createLocateRewrite(basePath);
+ cfg['instantiateWasm'] = Utils.createInstantiatePromise(loadPromise);
+ loadPromise = null;
+ Godot(cfg).then(function(module) {
+ me.env = module;
+ resolve();
+ });
+ });
+ }
+
+ this.start = function(preloadedFiles, args) {
+ var me = this;
+ return new Promise(function(resolve, reject) {
+ if (!me.env) {
+ reject(new Error('The engine must be initialized before it can be started'));
+ }
+ preloadedFiles.forEach(function(file) {
+ Utils.copyToFS(me.env['FS'], file.path, file.buffer);
+ });
+ preloadedFiles.length = 0; // Clear memory
+ me.env['callMain'](args);
+ resolve();
+ });
+ }
+};
diff --git a/platform/javascript/engine/preloader.js b/platform/javascript/engine/preloader.js
new file mode 100644
index 0000000000..17918eae38
--- /dev/null
+++ b/platform/javascript/engine/preloader.js
@@ -0,0 +1,139 @@
+var Preloader = /** @constructor */ function() {
+
+ var DOWNLOAD_ATTEMPTS_MAX = 4;
+ var progressFunc = null;
+ var lastProgress = { loaded: 0, total: 0 };
+
+ var loadingFiles = {};
+ this.preloadedFiles = [];
+
+ function loadXHR(resolve, reject, file, tracker) {
+ var xhr = new XMLHttpRequest;
+ xhr.open('GET', file);
+ if (!file.endsWith('.js')) {
+ xhr.responseType = 'arraybuffer';
+ }
+ ['loadstart', 'progress', 'load', 'error', 'abort'].forEach(function(ev) {
+ xhr.addEventListener(ev, onXHREvent.bind(xhr, resolve, reject, file, tracker));
+ });
+ xhr.send();
+ }
+
+ function onXHREvent(resolve, reject, file, tracker, ev) {
+
+ if (this.status >= 400) {
+
+ if (this.status < 500 || ++tracker[file].attempts >= DOWNLOAD_ATTEMPTS_MAX) {
+ reject(new Error("Failed loading file '" + file + "': " + this.statusText));
+ this.abort();
+ return;
+ } else {
+ setTimeout(loadXHR.bind(null, resolve, reject, file, tracker), 1000);
+ }
+ }
+
+ switch (ev.type) {
+ case 'loadstart':
+ if (tracker[file] === undefined) {
+ tracker[file] = {
+ total: ev.total,
+ loaded: ev.loaded,
+ attempts: 0,
+ final: false,
+ };
+ }
+ break;
+
+ case 'progress':
+ tracker[file].loaded = ev.loaded;
+ tracker[file].total = ev.total;
+ break;
+
+ case 'load':
+ tracker[file].final = true;
+ resolve(this);
+ break;
+
+ case 'error':
+ if (++tracker[file].attempts >= DOWNLOAD_ATTEMPTS_MAX) {
+ tracker[file].final = true;
+ reject(new Error("Failed loading file '" + file + "'"));
+ } else {
+ setTimeout(loadXHR.bind(null, resolve, reject, file, tracker), 1000);
+ }
+ break;
+
+ case 'abort':
+ tracker[file].final = true;
+ reject(new Error("Loading file '" + file + "' was aborted."));
+ break;
+ }
+ }
+
+ this.loadPromise = function(file) {
+ return new Promise(function(resolve, reject) {
+ loadXHR(resolve, reject, file, loadingFiles);
+ });
+ }
+
+ this.preload = function(pathOrBuffer, destPath) {
+ if (pathOrBuffer instanceof ArrayBuffer) {
+ pathOrBuffer = new Uint8Array(pathOrBuffer);
+ } else if (ArrayBuffer.isView(pathOrBuffer)) {
+ pathOrBuffer = new Uint8Array(pathOrBuffer.buffer);
+ }
+ if (pathOrBuffer instanceof Uint8Array) {
+ this.preloadedFiles.push({
+ path: destPath,
+ buffer: pathOrBuffer
+ });
+ return Promise.resolve();
+ } else if (typeof pathOrBuffer === 'string') {
+ var me = this;
+ return this.loadPromise(pathOrBuffer).then(function(xhr) {
+ me.preloadedFiles.push({
+ path: destPath || pathOrBuffer,
+ buffer: xhr.response
+ });
+ return Promise.resolve();
+ });
+ } else {
+ throw Promise.reject("Invalid object for preloading");
+ }
+ };
+
+ var animateProgress = function() {
+
+ var loaded = 0;
+ var total = 0;
+ var totalIsValid = true;
+ var progressIsFinal = true;
+
+ Object.keys(loadingFiles).forEach(function(file) {
+ const stat = loadingFiles[file];
+ if (!stat.final) {
+ progressIsFinal = false;
+ }
+ if (!totalIsValid || stat.total === 0) {
+ totalIsValid = false;
+ total = 0;
+ } else {
+ total += stat.total;
+ }
+ loaded += stat.loaded;
+ });
+ if (loaded !== lastProgress.loaded || total !== lastProgress.total) {
+ lastProgress.loaded = loaded;
+ lastProgress.total = total;
+ if (typeof progressFunc === 'function')
+ progressFunc(loaded, total);
+ }
+ if (!progressIsFinal)
+ requestAnimationFrame(animateProgress);
+ }
+ this.animateProgress = animateProgress; // Also exposed to start it.
+
+ this.setProgressFunc = function(callback) {
+ progressFunc = callback;
+ }
+};
diff --git a/platform/javascript/engine/utils.js b/platform/javascript/engine/utils.js
new file mode 100644
index 0000000000..fdff90a923
--- /dev/null
+++ b/platform/javascript/engine/utils.js
@@ -0,0 +1,69 @@
+var Utils = {
+
+ createLocateRewrite: function(execName) {
+ function rw(path) {
+ if (path.endsWith('.worker.js')) {
+ return execName + '.worker.js';
+ } else if (path.endsWith('.js')) {
+ return execName + '.js';
+ } else if (path.endsWith('.wasm')) {
+ return execName + '.wasm';
+ }
+ }
+ return rw;
+ },
+
+ createInstantiatePromise: function(wasmLoader) {
+ function instantiateWasm(imports, onSuccess) {
+ wasmLoader.then(function(xhr) {
+ WebAssembly.instantiate(xhr.response, imports).then(function(result) {
+ onSuccess(result['instance'], result['module']);
+ });
+ });
+ wasmLoader = null;
+ return {};
+ };
+
+ return instantiateWasm;
+ },
+
+ copyToFS: function(fs, path, buffer) {
+ var p = path.lastIndexOf("/");
+ var dir = "/";
+ if (p > 0) {
+ dir = path.slice(0, path.lastIndexOf("/"));
+ }
+ try {
+ fs.stat(dir);
+ } catch (e) {
+ if (e.errno !== 44) { // 'ENOENT', see https://github.com/emscripten-core/emscripten/blob/master/system/lib/libc/musl/arch/emscripten/bits/errno.h
+ throw e;
+ }
+ fs['mkdirTree'](dir);
+ }
+ // With memory growth, canOwn should be false.
+ fs['writeFile'](path, new Uint8Array(buffer), {'flags': 'wx+'});
+ },
+
+ findCanvas: function() {
+ var nodes = document.getElementsByTagName('canvas');
+ if (nodes.length && nodes[0] instanceof HTMLCanvasElement) {
+ return nodes[0];
+ }
+ throw new Error("No canvas found");
+ },
+
+ isWebGLAvailable: function(majorVersion = 1) {
+
+ var testContext = false;
+ try {
+ var testCanvas = document.createElement('canvas');
+ if (majorVersion === 1) {
+ testContext = testCanvas.getContext('webgl') || testCanvas.getContext('experimental-webgl');
+ } else if (majorVersion === 2) {
+ testContext = testCanvas.getContext('webgl2') || testCanvas.getContext('experimental-webgl2');
+ }
+ } catch (e) {}
+ return !!testContext;
+ }
+};
diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp
index f0326d5027..da61425747 100644
--- a/platform/javascript/export/export.cpp
+++ b/platform/javascript/export/export.cpp
@@ -94,6 +94,9 @@ public:
} else if (req[1] == basereq + ".js") {
filepath += ".js";
ctype = "application/javascript";
+ } else if (req[1] == basereq + ".worker.js") {
+ filepath += ".worker.js";
+ ctype = "application/javascript";
} else if (req[1] == basereq + ".pck") {
filepath += ".pck";
ctype = "application/octet-stream";
@@ -432,6 +435,10 @@ Error EditorExportPlatformJavaScript::export_project(const Ref<EditorExportPrese
} else if (file == "godot.js") {
file = p_path.get_file().get_basename() + ".js";
+ } else if (file == "godot.worker.js") {
+
+ file = p_path.get_file().get_basename() + ".worker.js";
+
} else if (file == "godot.wasm") {
file = p_path.get_file().get_basename() + ".wasm";
@@ -563,6 +570,7 @@ Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_prese
// Export generates several files, clean them up on failure.
DirAccess::remove_file_or_error(basepath + ".html");
DirAccess::remove_file_or_error(basepath + ".js");
+ DirAccess::remove_file_or_error(basepath + ".worker.js");
DirAccess::remove_file_or_error(basepath + ".pck");
DirAccess::remove_file_or_error(basepath + ".png");
DirAccess::remove_file_or_error(basepath + ".wasm");
diff --git a/platform/javascript/http_client.h.inc b/platform/javascript/http_client.h.inc
index 03e2ce8b8a..ac275aadbc 100644
--- a/platform/javascript/http_client.h.inc
+++ b/platform/javascript/http_client.h.inc
@@ -45,7 +45,7 @@ String password;
int polled_response_code;
String polled_response_header;
-PoolByteArray polled_response;
+PackedByteArray polled_response;
#ifdef DEBUG_ENABLED
bool has_polled;
diff --git a/platform/javascript/http_client_javascript.cpp b/platform/javascript/http_client_javascript.cpp
index d7796cc4f4..472384cf30 100644
--- a/platform/javascript/http_client_javascript.cpp
+++ b/platform/javascript/http_client_javascript.cpp
@@ -108,8 +108,7 @@ Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector
Error err = prepare_request(p_method, p_url, p_headers);
if (err != OK)
return err;
- const uint8_t *read = p_body.ptr();
- godot_xhr_send_data(xhr_id, read.ptr(), p_body.size());
+ godot_xhr_send_data(xhr_id, p_body.ptr(), p_body.size());
return OK;
}
@@ -180,11 +179,7 @@ PackedByteArray HTTPClient::read_response_body_chunk() {
int to_read = MIN(read_limit, polled_response.size() - response_read_offset);
PackedByteArray chunk;
chunk.resize(to_read);
- uint8_t *write = chunk.ptrw();
- const uint8_t *read = polled_response.ptr();
- memcpy(write.ptr(), read.ptr() + response_read_offset, to_read);
- write = uint8_t * ();
- read = const uint8_t * ();
+ memcpy(chunk.ptrw(), polled_response.ptr() + response_read_offset, to_read);
response_read_offset += to_read;
if (response_read_offset == polled_response.size()) {
@@ -267,19 +262,13 @@ Error HTTPClient::poll() {
int len = godot_xhr_get_response_headers_length(xhr_id);
bytes.resize(len + 1);
- uint8_t *write = bytes.ptrw();
- godot_xhr_get_response_headers(xhr_id, reinterpret_cast<char *>(write.ptr()), len);
- write[len] = 0;
- write = uint8_t * ();
+ godot_xhr_get_response_headers(xhr_id, reinterpret_cast<char *>(bytes.ptrw()), len);
+ bytes.ptrw()[len] = 0;
- const uint8_t *read = bytes.ptr();
- polled_response_header = String::utf8(reinterpret_cast<const char *>(read.ptr()));
- read = const uint8_t * ();
+ polled_response_header = String::utf8(reinterpret_cast<const char *>(bytes.ptr()));
polled_response.resize(godot_xhr_get_response_length(xhr_id));
- write = polled_response.ptrw();
- godot_xhr_get_response(xhr_id, write.ptr(), polled_response.size());
- write = uint8_t * ();
+ godot_xhr_get_response(xhr_id, polled_response.ptrw(), polled_response.size());
break;
}
diff --git a/platform/javascript/id_handler.js b/platform/javascript/id_handler.js
index 3851123ed1..67d29075b8 100644
--- a/platform/javascript/id_handler.js
+++ b/platform/javascript/id_handler.js
@@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-var IDHandler = function() {
+var IDHandler = /** @constructor */ function() {
var ids = {};
var size = 0;
diff --git a/platform/javascript/javascript_eval.cpp b/platform/javascript/javascript_eval.cpp
index 44cce28d57..db8050b90e 100644
--- a/platform/javascript/javascript_eval.cpp
+++ b/platform/javascript/javascript_eval.cpp
@@ -33,11 +33,11 @@
#include "api/javascript_eval.h"
#include "emscripten.h"
-extern "C" EMSCRIPTEN_KEEPALIVE uint8_t *resize_PackedByteArray_and_open_write(PackedByteArray *p_arr, uint8_t **r_write, int p_len) {
+extern "C" EMSCRIPTEN_KEEPALIVE uint8_t *resize_PackedByteArray_and_open_write(PackedByteArray *p_arr, VectorWriteProxy<uint8_t> *r_write, int p_len) {
p_arr->resize(p_len);
- *r_write = p_arr->write();
- return r_write->ptr();
+ *r_write = p_arr->write;
+ return p_arr->ptrw();
}
Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) {
@@ -49,7 +49,7 @@ Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) {
} js_data;
PackedByteArray arr;
- uint8_t *arr_write;
+ VectorWriteProxy<uint8_t> arr_write;
/* clang-format off */
Variant::Type return_type = static_cast<Variant::Type>(EM_ASM_INT({
@@ -138,7 +138,7 @@ Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) {
return str;
}
case Variant::PACKED_BYTE_ARRAY:
- arr_write = uint8_t * ();
+ arr_write = VectorWriteProxy<uint8_t>();
return arr;
default:
return Variant();
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp
index 037f78c7af..1d7a16db80 100644
--- a/platform/javascript/os_javascript.cpp
+++ b/platform/javascript/os_javascript.cpp
@@ -31,7 +31,8 @@
#include "os_javascript.h"
#include "core/io/file_access_buffered_fa.h"
-#include "drivers/gles2/rasterizer_gles2.h"
+//#include "drivers/gles2/rasterizer_gles2.h"
+#include "drivers/dummy/rasterizer_dummy.h"
#include "drivers/unix/dir_access_unix.h"
#include "drivers/unix/file_access_unix.h"
#include "main/main.h"
@@ -539,15 +540,11 @@ void OS_JavaScript::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_s
PackedByteArray png;
size_t len;
- const uint8_t *r = image->get_data().ptr();
- ERR_FAIL_COND(!png_image_write_get_memory_size(png_meta, len, 0, r.ptr(), 0, NULL));
+ PackedByteArray data = image->get_data();
+ ERR_FAIL_COND(!png_image_write_get_memory_size(png_meta, len, 0, data.ptr(), 0, NULL));
png.resize(len);
- uint8_t *w = png.ptrw();
- ERR_FAIL_COND(!png_image_write_to_memory(&png_meta, w.ptr(), &len, 0, r.ptr(), 0, NULL));
- w = uint8_t * ();
-
- r = png.ptr();
+ ERR_FAIL_COND(!png_image_write_to_memory(&png_meta, png.ptrw(), &len, 0, data.ptr(), 0, NULL));
char *object_url;
/* clang-format off */
@@ -562,9 +559,8 @@ void OS_JavaScript::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_s
var string_on_wasm_heap = _malloc(length_bytes);
setValue(PTR, string_on_wasm_heap, '*');
stringToUTF8(url, string_on_wasm_heap, length_bytes);
- }, r.ptr(), len, &object_url);
+ }, png.ptr(), len, &object_url);
/* clang-format on */
- r = const uint8_t * ();
String url = String::utf8(object_url) + "?" + itos(p_hotspot.x) + " " + itos(p_hotspot.y);
@@ -896,6 +892,7 @@ void OS_JavaScript::initialize_core() {
Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
+#if 0
EmscriptenWebGLContextAttributes attributes;
emscripten_webgl_init_context_attributes(&attributes);
attributes.alpha = GLOBAL_GET("display/window/per_pixel_transparency/allowed");
@@ -938,6 +935,7 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver,
if (p_desired.fullscreen) {
/* clang-format off */
EM_ASM({
+ const canvas = Module.canvas;
(canvas.requestFullscreen || canvas.msRequestFullscreen ||
canvas.mozRequestFullScreen || canvas.mozRequestFullscreen ||
canvas.webkitRequestFullscreen
@@ -952,6 +950,8 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver,
} else {
set_window_size(get_window_size());
}
+#endif
+ RasterizerDummy::make_current(); // TODO GLES2 in Godot 4.0... or webgpu?
char locale_ptr[16];
/* clang-format off */
@@ -1181,15 +1181,12 @@ void OS_JavaScript::set_icon(const Ref<Image> &p_icon) {
PackedByteArray png;
size_t len;
- const uint8_t *r = icon->get_data().ptr();
- ERR_FAIL_COND(!png_image_write_get_memory_size(png_meta, len, 0, r.ptr(), 0, NULL));
+ PackedByteArray data = icon->get_data();
+ ERR_FAIL_COND(!png_image_write_get_memory_size(png_meta, len, 0, data.ptr(), 0, NULL));
png.resize(len);
- uint8_t *w = png.ptrw();
- ERR_FAIL_COND(!png_image_write_to_memory(&png_meta, w.ptr(), &len, 0, r.ptr(), 0, NULL));
- w = uint8_t * ();
+ ERR_FAIL_COND(!png_image_write_to_memory(&png_meta, png.ptrw(), &len, 0, data.ptr(), 0, NULL));
- r = png.ptr();
/* clang-format off */
EM_ASM_ARGS({
var PNG_PTR = $0;
@@ -1205,7 +1202,7 @@ void OS_JavaScript::set_icon(const Ref<Image> &p_icon) {
document.head.appendChild(link);
}
link.href = url;
- }, r.ptr(), len);
+ }, png.ptr(), len);
/* clang-format on */
}
diff --git a/platform/javascript/pre.js b/platform/javascript/pre.js
deleted file mode 100644
index a870e676ea..0000000000
--- a/platform/javascript/pre.js
+++ /dev/null
@@ -1,5 +0,0 @@
-var Engine = {
- RuntimeEnvironment: function(Module, exposedLibs) {
- // The above is concatenated with generated code, and acts as the start of
- // a wrapper for said code. See engine.js for the other part of the
- // wrapper.
diff --git a/platform/x11/detect_prime.cpp b/platform/x11/detect_prime.cpp
index 98a51ff27c..a0e5f835c0 100644
--- a/platform/x11/detect_prime.cpp
+++ b/platform/x11/detect_prime.cpp
@@ -62,6 +62,7 @@ vendor vendormap[] = {
{ "NVIDIA Corporation", 30 },
{ "X.Org", 30 },
{ "Intel Open Source Technology Center", 20 },
+ { "Intel", 20 },
{ "nouveau", 10 },
{ "Mesa Project", 0 },
{ NULL, 0 }
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 5e925bf37f..784a6afc7b 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -1856,6 +1856,7 @@ void TextEdit::_consume_pair_symbol(CharType ch) {
bool in_single_quote = false;
bool in_double_quote = false;
+ bool found_comment = false;
int c = 0;
while (c < line.length()) {
@@ -1865,6 +1866,9 @@ void TextEdit::_consume_pair_symbol(CharType ch) {
if (cursor.column == c) {
break;
}
+ } else if (!in_single_quote && !in_double_quote && line[c] == '#') {
+ found_comment = true;
+ break;
} else {
if (line[c] == '\'' && !in_double_quote) {
in_single_quote = !in_single_quote;
@@ -1880,7 +1884,15 @@ void TextEdit::_consume_pair_symbol(CharType ch) {
}
}
- // Disallow inserting duplicated quotes while already in string
+ // Do not need to duplicate quotes while in comments
+ if (found_comment) {
+ insert_text_at_cursor(ch_single);
+ cursor_set_column(cursor_position_to_move);
+
+ return;
+ }
+
+ // Disallow inserting duplicated quotes while already in string
if ((in_single_quote || in_double_quote) && (ch == '"' || ch == '\'')) {
insert_text_at_cursor(ch_single);
cursor_set_column(cursor_position_to_move);
diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp
index a063b7f74f..5e032c41bf 100644
--- a/scene/resources/mesh.cpp
+++ b/scene/resources/mesh.cpp
@@ -252,10 +252,12 @@ Ref<Shape> Mesh::create_trimesh_shape() const {
Vector<Vector3> face_points;
face_points.resize(faces.size() * 3);
- for (int i = 0; i < face_points.size(); i++) {
+ for (int i = 0; i < face_points.size(); i += 3) {
Face3 f = faces.get(i / 3);
- face_points.set(i, f.vertex[i % 3]);
+ face_points.set(i, f.vertex[0]);
+ face_points.set(i + 1, f.vertex[1]);
+ face_points.set(i + 2, f.vertex[2]);
}
Ref<ConcavePolygonShape> shape = memnew(ConcavePolygonShape);
@@ -543,15 +545,9 @@ Vector<Ref<Shape> > Mesh::convex_decompose() const {
ERR_FAIL_COND_V(!convex_composition_function, Vector<Ref<Shape> >());
- Vector<Face3> faces = get_faces();
- Vector<Face3> f3;
- f3.resize(faces.size());
- const Face3 *f = faces.ptr();
- for (int i = 0; i < f3.size(); i++) {
- f3.write[i] = f[i];
- }
+ const Vector<Face3> faces = get_faces();
- Vector<Vector<Face3> > decomposed = convex_composition_function(f3);
+ Vector<Vector<Face3> > decomposed = convex_composition_function(faces);
Vector<Ref<Shape> > ret;
diff --git a/servers/navigation_2d_server.h b/servers/navigation_2d_server.h
index 955b0c3726..7b0b9fbb01 100644
--- a/servers/navigation_2d_server.h
+++ b/servers/navigation_2d_server.h
@@ -49,7 +49,7 @@ protected:
static void _bind_methods();
public:
- /// Thread safe, can be used accross many threads.
+ /// Thread safe, can be used across many threads.
static const Navigation2DServer *get_singleton() { return singleton; }
/// MUST be used in single thread!
diff --git a/servers/navigation_server.h b/servers/navigation_server.h
index 7c9b6ba595..546e543db3 100644
--- a/servers/navigation_server.h
+++ b/servers/navigation_server.h
@@ -54,7 +54,7 @@ protected:
static void _bind_methods();
public:
- /// Thread safe, can be used accross many threads.
+ /// Thread safe, can be used across many threads.
static const NavigationServer *get_singleton();
/// MUST be used in single thread!
diff --git a/servers/visual/rasterizer_rd/rasterizer_canvas_rd.cpp b/servers/visual/rasterizer_rd/rasterizer_canvas_rd.cpp
index 78fff0c381..38b1e3b3a6 100644
--- a/servers/visual/rasterizer_rd/rasterizer_canvas_rd.cpp
+++ b/servers/visual/rasterizer_rd/rasterizer_canvas_rd.cpp
@@ -2242,14 +2242,14 @@ RasterizerCanvasRD::RasterizerCanvasRD(RasterizerStorageRD *p_storage) {
//non light variants
variants.push_back(""); //none by default is first variant
variants.push_back("#define USE_NINEPATCH\n"); //ninepatch is the second variant
- variants.push_back("#define USE_PRIMITIVE\n"); //primitve is the third
+ variants.push_back("#define USE_PRIMITIVE\n"); //primitive is the third
variants.push_back("#define USE_PRIMITIVE\n#define USE_POINT_SIZE\n"); //points need point size
variants.push_back("#define USE_ATTRIBUTES\n"); // attributes for vertex arrays
variants.push_back("#define USE_ATTRIBUTES\n#define USE_POINT_SIZE\n"); //attributes with point size
//light variants
variants.push_back("#define USE_LIGHTING\n"); //none by default is first variant
variants.push_back("#define USE_LIGHTING\n#define USE_NINEPATCH\n"); //ninepatch is the second variant
- variants.push_back("#define USE_LIGHTING\n#define USE_PRIMITIVE\n"); //primitve is the third
+ variants.push_back("#define USE_LIGHTING\n#define USE_PRIMITIVE\n"); //primitive is the third
variants.push_back("#define USE_LIGHTING\n#define USE_PRIMITIVE\n#define USE_POINT_SIZE\n"); //points need point size
variants.push_back("#define USE_LIGHTING\n#define USE_ATTRIBUTES\n"); // attributes for vertex arrays
variants.push_back("#define USE_LIGHTING\n#define USE_ATTRIBUTES\n#define USE_POINT_SIZE\n"); //attributes with point size
diff --git a/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp b/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp
index 52cefa7511..850acbf554 100644
--- a/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp
+++ b/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp
@@ -3938,7 +3938,7 @@ void RasterizerStorageRD::_update_render_target(RenderTarget *rt) {
if (rt->size.width == 0 || rt->size.height == 0) {
return;
}
- //until we implement suport for HDR monitors (and render target is attached to screen), this is enough.
+ //until we implement support for HDR monitors (and render target is attached to screen), this is enough.
rt->color_format = RD::DATA_FORMAT_R8G8B8A8_UNORM;
rt->color_format_srgb = RD::DATA_FORMAT_R8G8B8A8_SRGB;
rt->image_format = rt->flags[RENDER_TARGET_TRANSPARENT] ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8;
diff --git a/servers/visual/rasterizer_rd/shaders/canvas.glsl b/servers/visual/rasterizer_rd/shaders/canvas.glsl
index 57e9451e48..28135fce31 100644
--- a/servers/visual/rasterizer_rd/shaders/canvas.glsl
+++ b/servers/visual/rasterizer_rd/shaders/canvas.glsl
@@ -416,7 +416,7 @@ FRAGMENT_SHADER_CODE
vec4 base_color = color;
if (bool(draw_data.flags & FLAGS_USING_LIGHT_MASK)) {
- color = vec4(0.0); //inivisible by default due to using light mask
+ color = vec4(0.0); //invisible by default due to using light mask
}
color *= canvas_data.canvas_modulation;
diff --git a/servers/visual/rendering_device.h b/servers/visual/rendering_device.h
index c3b937d5e2..1ff169f102 100644
--- a/servers/visual/rendering_device.h
+++ b/servers/visual/rendering_device.h
@@ -418,7 +418,7 @@ public:
virtual RID texture_create_shared_from_slice(const TextureView &p_view, RID p_with_texture, uint32_t p_layer, uint32_t p_mipmap, TextureSliceType p_slice_type = TEXTURE_SLICE_2D) = 0;
- virtual Error texture_update(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, bool p_sync_with_draw = false) = 0; //this function can be used from any thread and it takes effect at the begining of the frame, unless sync with draw is used, which is used to mix updates with draw calls
+ virtual Error texture_update(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, bool p_sync_with_draw = false) = 0; //this function can be used from any thread and it takes effect at the beginning of the frame, unless sync with draw is used, which is used to mix updates with draw calls
virtual Vector<uint8_t> texture_get_data(RID p_texture, uint32_t p_layer) = 0; // CPU textures will return immediately, while GPU textures will most likely force a flush
virtual bool texture_is_format_supported_for_usage(DataFormat p_format, uint32_t p_usage) const = 0;
@@ -621,7 +621,7 @@ public:
virtual RID uniform_set_create(const Vector<Uniform> &p_uniforms, RID p_shader, uint32_t p_shader_set) = 0;
virtual bool uniform_set_is_valid(RID p_uniform_set) = 0;
- virtual Error buffer_update(RID p_buffer, uint32_t p_offset, uint32_t p_size, const void *p_data, bool p_sync_with_draw = false) = 0; //this function can be used from any thread and it takes effect at the begining of the frame, unless sync with draw is used, which is used to mix updates with draw calls
+ virtual Error buffer_update(RID p_buffer, uint32_t p_offset, uint32_t p_size, const void *p_data, bool p_sync_with_draw = false) = 0; //this function can be used from any thread and it takes effect at the beginning of the frame, unless sync with draw is used, which is used to mix updates with draw calls
virtual Vector<uint8_t> buffer_get_data(RID p_buffer) = 0; //this causes stall, only use to retrieve large buffers for saving
/*************************/
@@ -643,7 +643,7 @@ public:
RENDER_PRIMITIVE_MAX
};
- //disable optimization, tesselate control points
+ //disable optimization, tessellate control points
enum PolygonCullMode {
POLYGON_CULL_DISABLED,
@@ -907,7 +907,7 @@ public:
enum InitialAction {
INITIAL_ACTION_CLEAR, //start rendering and clear the framebuffer (supply params)
INITIAL_ACTION_KEEP, //start rendering, but keep attached color texture contents (depth will be cleared)
- INITIAL_ACTION_CONTINUE, //continue rendering (framebuffer must have been left in "continue" state as final action prevously)
+ INITIAL_ACTION_CONTINUE, //continue rendering (framebuffer must have been left in "continue" state as final action previously)
INITIAL_ACTION_MAX
};
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp
index ed3feccb43..8cd0dc7937 100644
--- a/servers/visual/shader_language.cpp
+++ b/servers/visual/shader_language.cpp
@@ -4346,7 +4346,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
}
}
- //consecutively do unary opeators
+ //consecutively do unary operators
for (int i = expr_pos - 1; i >= next_op; i--) {
OperatorNode *op = alloc_node<OperatorNode>();
diff --git a/thirdparty/README.md b/thirdparty/README.md
index 5c9c114ad1..b52b68fe47 100644
--- a/thirdparty/README.md
+++ b/thirdparty/README.md
@@ -32,7 +32,7 @@ Files extracted from upstream source:
Files extracted from upstream source:
-- `.cpp` and `.h` files in root folder
+- `.cpp` and `.h` files in root folder except for `basisu_tool.cpp` (contains `main` and can cause link error)
- `.cpp`, `.h` and `.inc` files in `transcoder/`, keeping folder structure
- `LICENSE`
diff --git a/thirdparty/basis_universal/basisu_tool.cpp b/thirdparty/basis_universal/basisu_tool.cpp
deleted file mode 100644
index 8172a8c5cc..0000000000
--- a/thirdparty/basis_universal/basisu_tool.cpp
+++ /dev/null
@@ -1,1548 +0,0 @@
-// basisu_tool.cpp
-// Copyright (C) 2019 Binomial LLC. All Rights Reserved.
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-#include "transcoder/basisu.h"
-#include "transcoder/basisu_transcoder_internal.h"
-#include "basisu_enc.h"
-#include "basisu_etc.h"
-#include "basisu_gpu_texture.h"
-#include "basisu_frontend.h"
-#include "basisu_backend.h"
-#include "transcoder/basisu_global_selector_palette.h"
-#include "basisu_comp.h"
-#include "transcoder/basisu_transcoder.h"
-#include "basisu_ssim.h"
-
-#define BASISU_CATCH_EXCEPTIONS 1
-
-using namespace basisu;
-
-#define BASISU_TOOL_VERSION "1.10.00"
-
-enum tool_mode
-{
- cDefault,
- cCompress,
- cValidate,
- cUnpack,
- cCompare,
- cVersion,
-};
-
-static void print_usage()
-{
- printf("\nUsage: basisu filename [filename ...] <options>\n");
-
- puts("\n"
- "The default mode is compression of one or more PNG files to a .basis file. Alternate modes:\n"
- " -unpack: Use transcoder to unpack .basis file to one or more .ktx/.png files\n"
- " -validate: Validate and display information about a .basis file\n"
- " -compare: Compare two PNG images specified with -file, output PSNR and SSIM statistics and RGB/A delta images\n"
- " -version: Print basisu version and exit\n"
- "Unless an explicit mode is specified, if one or more files have the .basis extension this tool defaults to unpack mode.\n"
- "\n"
- "Important: By default, the compressor assumes the input is in the sRGB colorspace (like photos/albedo textures).\n"
- "If the input is NOT sRGB (like a normal map), be sure to specify -linear for less artifacts. Depending on the content type, some experimentation may be needed.\n"
- "\n"
- "Filenames prefixed with a @ symbol are read as filename listing files. Listing text files specify which actual filenames to process (one filename per line).\n"
- "\n"
- "Options:\n"
- " -file filename.png: Input image filename, multiple images are OK, use -file X for each input filename (prefixing input filenames with -file is optional)\n"
- " -alpha_file filename.png: Input alpha image filename, multiple images are OK, use -file X for each input filename (must be paired with -file), images converted to REC709 grayscale and used as input alpha\n"
- " -multifile_printf: printf() format strint to use to compose multiple filenames\n"
- " -multifile_first: The index of the first file to process, default is 0 (must specify -multifile_printf and -multifile_num)\n"
- " -multifile_num: The total number of files to process.\n"
- " -q X: Set quality level, 1-255, default is 128, lower=better compression/lower quality/faster, higher=less compression/higher quality/slower, default is 128. For even higher quality, use -max_endpoints/-max_selectors.\n"
- " -linear: Use linear colorspace metrics (instead of the default sRGB), and by default linear (not sRGB) mipmap filtering.\n"
- " -output_file filename: Output .basis/.ktx filename\n"
- " -output_path: Output .basis/.ktx files to specified directory.\n"
- " -debug: Enable codec debug print to stdout (slightly slower).\n"
- " -debug_images: Enable codec debug images (much slower).\n"
- " -stats: Compute and display image quality metrics (slightly slower).\n"
- " -tex_type <2d, 2darray, 3d, video, cubemap>: Set Basis file header's texture type field. Cubemap arrays require multiples of 6 images, in X+, X-, Y+, Y-, Z+, Z- order, each image must be the same resolutions.\n"
- " 2d=arbitrary 2D images, 2darray=2D array, 3D=volume texture slices, video=video frames, cubemap=array of faces. For 2darray/3d/cubemaps/video, each source image's dimensions and # of mipmap levels must be the same.\n"
- " For video, the .basis file will be written with the first frame being an I-Frame, and subsequent frames being P-Frames (using conditional replenishment). Playback must always occur in order from first to last image.\n"
- " -framerate X: Set framerate in header to X/frames sec.\n"
- " -individual: Process input images individually and output multiple .basis files (not as a texture array)\n"
- " -comp_level X: Set encoding speed vs. quality tradeoff. Range is 0-5, default is 1. Higher values=MUCH slower, but slightly higher quality. Mostly intended for videos. Use -q first!\n"
- " -fuzz_testing: Use with -validate: Disables CRC16 validation of file contents before transcoding\n"
- "\n"
- "More options:\n"
- " -max_endpoints X: Manually set the max number of color endpoint clusters from 1-16128, use instead of -q\n"
- " -max_selectors X: Manually set the max number of color selector clusters from 1-16128, use instead of -q\n"
- " -y_flip: Flip input images vertically before compression\n"
- " -normal_map: Tunes codec parameters for better quality on normal maps (linear colorspace metrics, linear mipmap filtering, no selector RDO, no sRGB)\n"
- " -no_alpha: Always output non-alpha basis files, even if one or more inputs has alpha\n"
- " -force_alpha: Always output alpha basis files, even if no inputs has alpha\n"
- " -separate_rg_to_color_alpha: Separate input R and G channels to RGB and A (for tangent space XY normal maps)\n"
- " -no_multithreading: Disable multithreading\n"
- " -no_ktx: Disable KTX writing when unpacking (faster)\n"
- " -etc1_only: Only unpack to ETC1, skipping the other texture formats during -unpack\n"
- " -disable_hierarchical_endpoint_codebooks: Disable hierarchical endpoint codebook usage, slower but higher quality on some compression levels\n"
- " -compare_ssim: Compute and display SSIM of image comparison (slow)\n"
- "\n"
- "Mipmap generation options:\n"
- " -mipmap: Generate mipmaps for each source image\n"
- " -mip_srgb: Convert image to linear before filtering, then back to sRGB\n"
- " -mip_linear: Keep image in linear light during mipmap filtering\n"
- " -mip_scale X: Set mipmap filter kernel's scale, lower=sharper, higher=more blurry, default is 1.0\n"
- " -mip_filter X: Set mipmap filter kernel, default is kaiser, filters: box, tent, bell, blackman, catmullrom, mitchell, etc.\n"
- " -mip_renorm: Renormalize normal map to unit length vectors after filtering\n"
- " -mip_clamp: Use clamp addressing on borders, instead of wrapping\n"
- " -mip_smallest X: Set smallest pixel dimension for generated mipmaps, default is 1 pixel\n"
- "By default, mipmap filtering will occur in sRGB space (for the RGB color channels) unless -linear is specified. You can override this behavior with -mip_srgb/-mip_linear.\n"
- "\n"
- "Backend endpoint/selector RDO codec options:\n"
- " -no_selector_rdo: Disable backend's selector rate distortion optimizations (slightly faster, less noisy output, but lower quality per output bit)\n"
- " -selector_rdo_thresh X: Set selector RDO quality threshold, default is 1.25, lower is higher quality but less quality per output bit (try 1.0-3.0)\n"
- " -no_endpoint_rdo: Disable backend's endpoint rate distortion optimizations (slightly faster, less noisy output, but lower quality per output bit)\n"
- " -endpoint_rdo_thresh X: Set endpoint RDO quality threshold, default is 1.5, lower is higher quality but less quality per output bit (try 1.0-3.0)\n"
- "\n"
- "Hierarchical virtual selector codebook options:\n"
- " -global_sel_pal: Always use vitual selector palettes (instead of custom palettes), slightly smaller files, but lower quality, slower encoding\n"
- " -auto_global_sel_pal: Automatically use virtual selector palettes on small images for slightly smaller files (defaults to off for faster encoding time)\n"
- " -no_hybrid_sel_cb: Don't automatically use hybrid virtual selector codebooks (for higher quality, only active when -global_sel_pal is specified)\n"
- " -global_pal_bits X: Set virtual selector codebook palette bits, range is [0,12], default is 8, higher is slower/better quality\n"
- " -global_mod_bits X: Set virtual selector codebook modifier bits, range is [0,15], defualt is 8, higher is slower/better quality\n"
- " -hybrid_sel_cb_quality_thresh X: Set hybrid selector codebook quality threshold, default is 2.0, try 1.5-3, higher is lower quality/smaller codebooks\n"
- "\n"
- "Set various fields in the Basis file header:\n"
- " -userdata0 X: Set 32-bit userdata0 field in Basis file header to X (X is a signed 32-bit int)\n"
- " -userdata1 X: Set 32-bit userdata1 field in Basis file header to X (X is a signed 32-bit int)\n"
- "\n"
- "Various command line examples:\n"
- " basisu x.png : Compress sRGB image x.png to x.basis using default settings (multiple filenames OK)\n"
- " basisu x.basis : Unpack x.basis to PNG/KTX files (multiple filenames OK)\n"
- " basisu -file x.png -mipmap -y_flip : Compress a mipmapped x.basis file from an sRGB image named x.png, Y flip each source image\n"
- " basisu -validate -file x.basis : Validate x.basis (check header, check file CRC's, attempt to transcode all slices)\n"
- " basisu -unpack -file x.basis : Validates, transcodes and unpacks x.basis to mipmapped .KTX and RGB/A .PNG files (transcodes to all supported GPU texture formats)\n"
- " basisu -q 255 -file x.png -mipmap -debug -stats : Compress sRGB x.png to x.basis at quality level 255 with compressor debug output/statistics\n"
- " basisu -linear -max_endpoints 16128 -max_selectors 16128 -file x.png : Compress non-sRGB x.png to x.basis using the largest supported manually specified codebook sizes\n"
- " basisu -linear -global_sel_pal -no_hybrid_sel_cb -file x.png : Compress a non-sRGB image, use virtual selector codebooks for improved compression (but slower encoding)\n"
- " basisu -linear -global_sel_pal -file x.png: Compress a non-sRGB image, use hybrid selector codebooks for slightly improved compression (but slower encoding)\n"
- " basisu -tex_type video -framerate 20 -multifile_printf \"x%02u.png\" -multifile_first 1 -multifile_count 20 : Compress a 20 sRGB source image video sequence (x01.png, x02.png, x03.png, etc.) to x01.basis\n"
- "\n"
- "Note: For video use, it's recommended you use a very powerful machine with many cores. Use -slower for better codebook generation, specify very large codebooks using -max_endpoints and -max_selectors, and reduce\n"
- "the default endpoint RDO threshold (-endpoint_rdo_thresh) to around 1.25. Videos may have mipmaps and alpha channels. Videos must always be played back by the transcoder in first to last image order.\n"
- "Video files currently use I-Frames on the first image, and P-Frames using conditional replenishment on subsequent frames.\n"
- "Compression level details:\n"
- " Level 0: Fastest, but has marginal quality and is a work in progress. Brittle on complex images. Avg. Y dB: 35.45\n"
- " Level 1: Hierarchical codebook searching. 36.87 dB, ~1.4x slower vs. level 0. (This is the default setting.)\n"
- " Level 2: Full codebook searching. 37.13 dB, ~1.8x slower vs. level 0. (Equivalent the the initial release's default settings.)\n"
- " Level 3: Hierarchical codebook searching, codebook k-means iterations. 37.15 dB, ~4x slower vs. level 0\n"
- " Level 4: Full codebook searching, codebook k-means iterations. 37.41 dB, ~5.5x slower vs. level 0. (Equivalent to the initial release's -slower setting.)\n"
- " Level 5: Full codebook searching, twice as many codebook k-means iterations, best ETC1 endpoint opt. 37.43 dB, ~12x slower vs. level 0\n"
- );
-}
-
-static bool load_listing_file(const std::string &f, std::vector<std::string> &filenames)
-{
- std::string filename(f);
- filename.erase(0, 1);
-
- FILE *pFile = nullptr;
-#ifdef _WIN32
- fopen_s(&pFile, filename.c_str(), "r");
-#else
- pFile = fopen(filename.c_str(), "r");
-#endif
-
- if (!pFile)
- {
- error_printf("Failed opening listing file: \"%s\"\n", filename.c_str());
- return false;
- }
-
- uint32_t total_filenames = 0;
-
- for ( ; ; )
- {
- char buf[3072];
- buf[0] = '\0';
-
- char *p = fgets(buf, sizeof(buf), pFile);
- if (!p)
- {
- if (ferror(pFile))
- {
- error_printf("Failed reading from listing file: \"%s\"\n", filename.c_str());
-
- fclose(pFile);
- return false;
- }
- else
- break;
- }
-
- std::string read_filename(p);
- while (read_filename.size())
- {
- if (read_filename[0] == ' ')
- read_filename.erase(0, 1);
- else
- break;
- }
-
- while (read_filename.size())
- {
- const char c = read_filename.back();
- if ((c == ' ') || (c == '\n') || (c == '\r'))
- read_filename.erase(read_filename.size() - 1, 1);
- else
- break;
- }
-
- if (read_filename.size())
- {
- filenames.push_back(read_filename);
- total_filenames++;
- }
- }
-
- fclose(pFile);
-
- printf("Successfully read %u filenames(s) from listing file \"%s\"\n", total_filenames, filename.c_str());
-
- return true;
-}
-
-class command_line_params
-{
- BASISU_NO_EQUALS_OR_COPY_CONSTRUCT(command_line_params);
-
-public:
- command_line_params() :
- m_mode(cDefault),
- m_multifile_first(0),
- m_multifile_num(0),
- m_individual(false),
- m_no_ktx(false),
- m_etc1_only(false),
- m_fuzz_testing(false),
- m_compare_ssim(false)
- {
- }
-
- bool parse(int arg_c, const char **arg_v)
- {
- int arg_index = 1;
- while (arg_index < arg_c)
- {
- const char *pArg = arg_v[arg_index];
- const int num_remaining_args = arg_c - (arg_index + 1);
- int arg_count = 1;
-
-#define REMAINING_ARGS_CHECK(n) if (num_remaining_args < (n)) { error_printf("Error: Expected %u values to follow %s!\n", n, pArg); return false; }
-
- if (strcasecmp(pArg, "-compress") == 0)
- m_mode = cCompress;
- else if (strcasecmp(pArg, "-compare") == 0)
- m_mode = cCompare;
- else if (strcasecmp(pArg, "-unpack") == 0)
- m_mode = cUnpack;
- else if (strcasecmp(pArg, "-validate") == 0)
- m_mode = cValidate;
- else if (strcasecmp(pArg, "-version") == 0)
- m_mode = cVersion;
- else if (strcasecmp(pArg, "-compare_ssim") == 0)
- m_compare_ssim = true;
- else if (strcasecmp(pArg, "-file") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_input_filenames.push_back(std::string(arg_v[arg_index + 1]));
- arg_count++;
- }
- else if (strcasecmp(pArg, "-alpha_file") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_input_alpha_filenames.push_back(std::string(arg_v[arg_index + 1]));
- arg_count++;
- }
- else if (strcasecmp(pArg, "-multifile_printf") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_multifile_printf = std::string(arg_v[arg_index + 1]);
- arg_count++;
- }
- else if (strcasecmp(pArg, "-multifile_first") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_multifile_first = atoi(arg_v[arg_index + 1]);
- arg_count++;
- }
- else if (strcasecmp(pArg, "-multifile_num") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_multifile_num = atoi(arg_v[arg_index + 1]);
- arg_count++;
- }
- else if (strcasecmp(pArg, "-linear") == 0)
- m_comp_params.m_perceptual = false;
- else if (strcasecmp(pArg, "-srgb") == 0)
- m_comp_params.m_perceptual = true;
- else if (strcasecmp(pArg, "-q") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_comp_params.m_quality_level = clamp<int>(atoi(arg_v[arg_index + 1]), BASISU_QUALITY_MIN, BASISU_QUALITY_MAX);
- arg_count++;
- }
- else if (strcasecmp(pArg, "-output_file") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_output_filename = arg_v[arg_index + 1];
- arg_count++;
- }
- else if (strcasecmp(pArg, "-output_path") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_output_path = arg_v[arg_index + 1];
- arg_count++;
- }
- else if (strcasecmp(pArg, "-debug") == 0)
- {
- m_comp_params.m_debug = true;
- enable_debug_printf(true);
- }
- else if (strcasecmp(pArg, "-debug_images") == 0)
- m_comp_params.m_debug_images = true;
- else if (strcasecmp(pArg, "-stats") == 0)
- m_comp_params.m_compute_stats = true;
- else if (strcasecmp(pArg, "-comp_level") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_comp_params.m_compression_level = atoi(arg_v[arg_index + 1]);
- arg_count++;
- }
- else if (strcasecmp(pArg, "-slower") == 0)
- {
- // This option is gone, but we'll do something reasonable with it anyway. Level 4 is equivalent to the original release's -slower, but let's just go to level 2.
- m_comp_params.m_compression_level = 2;
- }
- else if (strcasecmp(pArg, "-max_endpoints") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_comp_params.m_max_endpoint_clusters = clamp<int>(atoi(arg_v[arg_index + 1]), 1, BASISU_MAX_ENDPOINT_CLUSTERS);
- arg_count++;
- }
- else if (strcasecmp(pArg, "-max_selectors") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_comp_params.m_max_selector_clusters = clamp<int>(atoi(arg_v[arg_index + 1]), 1, BASISU_MAX_SELECTOR_CLUSTERS);
- arg_count++;
- }
- else if (strcasecmp(pArg, "-y_flip") == 0)
- m_comp_params.m_y_flip = true;
- else if (strcasecmp(pArg, "-normal_map") == 0)
- {
- m_comp_params.m_perceptual = false;
- m_comp_params.m_mip_srgb = false;
- m_comp_params.m_no_selector_rdo = true;
- m_comp_params.m_no_endpoint_rdo = true;
- }
- else if (strcasecmp(pArg, "-no_alpha") == 0)
- m_comp_params.m_check_for_alpha = false;
- else if (strcasecmp(pArg, "-force_alpha") == 0)
- m_comp_params.m_force_alpha = true;
- else if ((strcasecmp(pArg, "-separate_rg_to_color_alpha") == 0) ||
- (strcasecmp(pArg, "-seperate_rg_to_color_alpha") == 0)) // was mispelled for a while - whoops!
- m_comp_params.m_seperate_rg_to_color_alpha = true;
- else if (strcasecmp(pArg, "-no_multithreading") == 0)
- {
- m_comp_params.m_multithreading = false;
- }
- else if (strcasecmp(pArg, "-mipmap") == 0)
- m_comp_params.m_mip_gen = true;
- else if (strcasecmp(pArg, "-no_ktx") == 0)
- m_no_ktx = true;
- else if (strcasecmp(pArg, "-etc1_only") == 0)
- m_etc1_only = true;
- else if (strcasecmp(pArg, "-disable_hierarchical_endpoint_codebooks") == 0)
- m_comp_params.m_disable_hierarchical_endpoint_codebooks = true;
- else if (strcasecmp(pArg, "-mip_scale") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_comp_params.m_mip_scale = (float)atof(arg_v[arg_index + 1]);
- arg_count++;
- }
- else if (strcasecmp(pArg, "-mip_filter") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_comp_params.m_mip_filter = arg_v[arg_index + 1];
- // TODO: Check filter
- arg_count++;
- }
- else if (strcasecmp(pArg, "-mip_renorm") == 0)
- m_comp_params.m_mip_renormalize = true;
- else if (strcasecmp(pArg, "-mip_clamp") == 0)
- m_comp_params.m_mip_wrapping = false;
- else if (strcasecmp(pArg, "-mip_smallest") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_comp_params.m_mip_smallest_dimension = atoi(arg_v[arg_index + 1]);
- arg_count++;
- }
- else if (strcasecmp(pArg, "-mip_srgb") == 0)
- m_comp_params.m_mip_srgb = true;
- else if (strcasecmp(pArg, "-mip_linear") == 0)
- m_comp_params.m_mip_srgb = false;
- else if (strcasecmp(pArg, "-no_selector_rdo") == 0)
- m_comp_params.m_no_selector_rdo = true;
- else if (strcasecmp(pArg, "-selector_rdo_thresh") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_comp_params.m_selector_rdo_thresh = (float)atof(arg_v[arg_index + 1]);
- arg_count++;
- }
- else if (strcasecmp(pArg, "-no_endpoint_rdo") == 0)
- m_comp_params.m_no_endpoint_rdo = true;
- else if (strcasecmp(pArg, "-endpoint_rdo_thresh") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_comp_params.m_endpoint_rdo_thresh = (float)atof(arg_v[arg_index + 1]);
- arg_count++;
- }
- else if (strcasecmp(pArg, "-global_sel_pal") == 0)
- m_comp_params.m_global_sel_pal = true;
- else if (strcasecmp(pArg, "-no_auto_global_sel_pal") == 0)
- m_comp_params.m_auto_global_sel_pal = false;
- else if (strcasecmp(pArg, "-auto_global_sel_pal") == 0)
- m_comp_params.m_auto_global_sel_pal = true;
- else if (strcasecmp(pArg, "-global_pal_bits") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_comp_params.m_global_pal_bits = atoi(arg_v[arg_index + 1]);
- arg_count++;
- }
- else if (strcasecmp(pArg, "-global_mod_bits") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_comp_params.m_global_mod_bits = atoi(arg_v[arg_index + 1]);
- arg_count++;
- }
- else if (strcasecmp(pArg, "-no_hybrid_sel_cb") == 0)
- m_comp_params.m_no_hybrid_sel_cb = true;
- else if (strcasecmp(pArg, "-hybrid_sel_cb_quality_thresh") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_comp_params.m_hybrid_sel_cb_quality_thresh = (float)atof(arg_v[arg_index + 1]);
- arg_count++;
- }
- else if (strcasecmp(pArg, "-userdata0") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_comp_params.m_userdata0 = atoi(arg_v[arg_index + 1]);
- arg_count++;
- }
- else if (strcasecmp(pArg, "-userdata1") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_comp_params.m_userdata1 = atoi(arg_v[arg_index + 1]);
- arg_count++;
- }
- else if (strcasecmp(pArg, "-framerate") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- double fps = atof(arg_v[arg_index + 1]);
- double us_per_frame = 0;
- if (fps > 0)
- us_per_frame = 1000000.0f / fps;
-
- m_comp_params.m_us_per_frame = clamp<int>(static_cast<int>(us_per_frame + .5f), 0, basist::cBASISMaxUSPerFrame);
- arg_count++;
- }
- else if (strcasecmp(pArg, "-tex_type") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- const char *pType = arg_v[arg_index + 1];
- if (strcasecmp(pType, "2d") == 0)
- m_comp_params.m_tex_type = basist::cBASISTexType2D;
- else if (strcasecmp(pType, "2darray") == 0)
- m_comp_params.m_tex_type = basist::cBASISTexType2DArray;
- else if (strcasecmp(pType, "3d") == 0)
- m_comp_params.m_tex_type = basist::cBASISTexTypeVolume;
- else if (strcasecmp(pType, "cubemap") == 0)
- m_comp_params.m_tex_type = basist::cBASISTexTypeCubemapArray;
- else if (strcasecmp(pType, "video") == 0)
- m_comp_params.m_tex_type = basist::cBASISTexTypeVideoFrames;
- else
- {
- error_printf("Invalid texture type: %s\n", pType);
- return false;
- }
- arg_count++;
- }
- else if (strcasecmp(pArg, "-individual") == 0)
- m_individual = true;
- else if (strcasecmp(pArg, "-fuzz_testing") == 0)
- m_fuzz_testing = true;
- else if (strcasecmp(pArg, "-csv_file") == 0)
- {
- REMAINING_ARGS_CHECK(1);
- m_csv_file = arg_v[arg_index + 1];
- m_comp_params.m_compute_stats = true;
-
- arg_count++;
- }
- else if (pArg[0] == '-')
- {
- error_printf("Unrecognized command line option: %s\n", pArg);
- return false;
- }
- else
- {
- // Let's assume it's a source filename, so globbing works
- //error_printf("Unrecognized command line option: %s\n", pArg);
- m_input_filenames.push_back(pArg);
- }
-
- arg_index += arg_count;
- }
-
- if (m_comp_params.m_quality_level != -1)
- {
- m_comp_params.m_max_endpoint_clusters = 0;
- m_comp_params.m_max_selector_clusters = 0;
- }
- else if ((!m_comp_params.m_max_endpoint_clusters) || (!m_comp_params.m_max_selector_clusters))
- {
- m_comp_params.m_max_endpoint_clusters = 0;
- m_comp_params.m_max_selector_clusters = 0;
-
- m_comp_params.m_quality_level = 128;
- }
-
- if (!m_comp_params.m_mip_srgb.was_changed())
- {
- // They didn't specify what colorspace to do mipmap filtering in, so choose sRGB if they've specified that the texture is sRGB.
- if (m_comp_params.m_perceptual)
- m_comp_params.m_mip_srgb = true;
- else
- m_comp_params.m_mip_srgb = false;
- }
-
- return true;
- }
-
- bool process_listing_files()
- {
- std::vector<std::string> new_input_filenames;
- for (uint32_t i = 0; i < m_input_filenames.size(); i++)
- {
- if (m_input_filenames[i][0] == '@')
- {
- if (!load_listing_file(m_input_filenames[i], new_input_filenames))
- return false;
- }
- else
- new_input_filenames.push_back(m_input_filenames[i]);
- }
- new_input_filenames.swap(m_input_filenames);
-
- std::vector<std::string> new_input_alpha_filenames;
- for (uint32_t i = 0; i < m_input_alpha_filenames.size(); i++)
- {
- if (m_input_alpha_filenames[i][0] == '@')
- {
- if (!load_listing_file(m_input_alpha_filenames[i], new_input_alpha_filenames))
- return false;
- }
- else
- new_input_alpha_filenames.push_back(m_input_alpha_filenames[i]);
- }
- new_input_alpha_filenames.swap(m_input_alpha_filenames);
-
- return true;
- }
-
- basis_compressor_params m_comp_params;
-
- tool_mode m_mode;
-
- std::vector<std::string> m_input_filenames;
- std::vector<std::string> m_input_alpha_filenames;
-
- std::string m_output_filename;
- std::string m_output_path;
-
- std::string m_multifile_printf;
- uint32_t m_multifile_first;
- uint32_t m_multifile_num;
-
- std::string m_csv_file;
-
- bool m_individual;
- bool m_no_ktx;
- bool m_etc1_only;
- bool m_fuzz_testing;
- bool m_compare_ssim;
-};
-
-static bool expand_multifile(command_line_params &opts)
-{
- if (!opts.m_multifile_printf.size())
- return true;
-
- if (!opts.m_multifile_num)
- {
- error_printf("-multifile_printf specified, but not -multifile_num\n");
- return false;
- }
-
- std::string fmt(opts.m_multifile_printf);
- size_t x = fmt.find_first_of('!');
- if (x != std::string::npos)
- fmt[x] = '%';
-
- if (string_find_right(fmt, '%') == -1)
- {
- error_printf("Must include C-style printf() format character '%%' in -multifile_printf string\n");
- return false;
- }
-
- for (uint32_t i = opts.m_multifile_first; i < opts.m_multifile_first + opts.m_multifile_num; i++)
- {
- char buf[1024];
-#ifdef _WIN32
- sprintf_s(buf, sizeof(buf), fmt.c_str(), i);
-#else
- snprintf(buf, sizeof(buf), fmt.c_str(), i);
-#endif
-
- if (buf[0])
- opts.m_input_filenames.push_back(buf);
- }
-
- return true;
-}
-
-static bool compress_mode(command_line_params &opts)
-{
- basist::etc1_global_selector_codebook sel_codebook(basist::g_global_selector_cb_size, basist::g_global_selector_cb);
-
- uint32_t num_threads = 1;
-
- if (opts.m_comp_params.m_multithreading)
- {
- num_threads = std::thread::hardware_concurrency();
- if (num_threads < 1)
- num_threads = 1;
- }
-
- job_pool jpool(num_threads);
- opts.m_comp_params.m_pJob_pool = &jpool;
-
- if (!expand_multifile(opts))
- {
- error_printf("-multifile expansion failed!\n");
- return false;
- }
-
- if (!opts.m_input_filenames.size())
- {
- error_printf("No input files to process!\n");
- return false;
- }
-
- basis_compressor_params &params = opts.m_comp_params;
-
- params.m_read_source_images = true;
- params.m_write_output_basis_files = true;
- params.m_pSel_codebook = &sel_codebook;
-
- FILE *pCSV_file = nullptr;
- if (opts.m_csv_file.size())
- {
- pCSV_file = fopen_safe(opts.m_csv_file.c_str(), "a");
- if (!pCSV_file)
- {
- error_printf("Failed opening CVS file \"%s\"\n", opts.m_csv_file.c_str());
- return false;
- }
- }
-
- printf("Processing %u total files\n", (uint32_t)opts.m_input_filenames.size());
-
- for (size_t file_index = 0; file_index < (opts.m_individual ? opts.m_input_filenames.size() : 1U); file_index++)
- {
- if (opts.m_individual)
- {
- params.m_source_filenames.resize(1);
- params.m_source_filenames[0] = opts.m_input_filenames[file_index];
-
- if (file_index < opts.m_input_alpha_filenames.size())
- {
- params.m_source_alpha_filenames.resize(1);
- params.m_source_alpha_filenames[0] = opts.m_input_alpha_filenames[file_index];
-
- printf("Processing source file \"%s\", alpha file \"%s\"\n", params.m_source_filenames[0].c_str(), params.m_source_alpha_filenames[0].c_str());
- }
- else
- {
- params.m_source_alpha_filenames.resize(0);
-
- printf("Processing source file \"%s\"\n", params.m_source_filenames[0].c_str());
- }
- }
- else
- {
- params.m_source_filenames = opts.m_input_filenames;
- params.m_source_alpha_filenames = opts.m_input_alpha_filenames;
- }
-
- if ((opts.m_output_filename.size()) && (!opts.m_individual))
- params.m_out_filename = opts.m_output_filename;
- else
- {
- std::string filename;
-
- string_get_filename(opts.m_input_filenames[file_index].c_str(), filename);
- string_remove_extension(filename);
- filename += ".basis";
-
- if (opts.m_output_path.size())
- string_combine_path(filename, opts.m_output_path.c_str(), filename.c_str());
-
- params.m_out_filename = filename;
- }
-
- basis_compressor c;
-
- if (!c.init(opts.m_comp_params))
- {
- error_printf("basis_compressor::init() failed!\n");
-
- if (pCSV_file)
- {
- fclose(pCSV_file);
- pCSV_file = nullptr;
- }
-
- return false;
- }
-
- interval_timer tm;
- tm.start();
-
- basis_compressor::error_code ec = c.process();
-
- tm.stop();
-
- if (ec == basis_compressor::cECSuccess)
- {
- printf("Compression succeeded to file \"%s\" in %3.3f secs\n", params.m_out_filename.c_str(), tm.get_elapsed_secs());
- }
- else
- {
- bool exit_flag = true;
-
- switch (ec)
- {
- case basis_compressor::cECFailedReadingSourceImages:
- {
- error_printf("Compressor failed reading a source image!\n");
-
- if (opts.m_individual)
- exit_flag = false;
-
- break;
- }
- case basis_compressor::cECFailedValidating:
- error_printf("Compressor failed 2darray/cubemap/video validation checks!\n");
- break;
- case basis_compressor::cECFailedFrontEnd:
- error_printf("Compressor frontend stage failed!\n");
- break;
- case basis_compressor::cECFailedFontendExtract:
- error_printf("Compressor frontend data extraction failed!\n");
- break;
- case basis_compressor::cECFailedBackend:
- error_printf("Compressor backend stage failed!\n");
- break;
- case basis_compressor::cECFailedCreateBasisFile:
- error_printf("Compressor failed creating Basis file data!\n");
- break;
- case basis_compressor::cECFailedWritingOutput:
- error_printf("Compressor failed writing to output Basis file!\n");
- break;
- default:
- error_printf("basis_compress::process() failed!\n");
- break;
- }
-
- if (exit_flag)
- {
- if (pCSV_file)
- {
- fclose(pCSV_file);
- pCSV_file = nullptr;
- }
-
- return false;
- }
- }
-
- if ((pCSV_file) && (c.get_stats().size()))
- {
- for (size_t slice_index = 0; slice_index < c.get_stats().size(); slice_index++)
- {
- fprintf(pCSV_file, "\"%s\", %u, %u, %u, %u, %u, %f, %f, %f, %f, %u, %u, %f\n",
- params.m_out_filename.c_str(),
- (uint32_t)slice_index, (uint32_t)c.get_stats().size(),
- c.get_stats()[slice_index].m_width, c.get_stats()[slice_index].m_height, (uint32_t)c.get_any_source_image_has_alpha(),
- c.get_basis_bits_per_texel(),
- c.get_stats()[slice_index].m_best_luma_709_psnr,
- c.get_stats()[slice_index].m_basis_etc1s_luma_709_psnr,
- c.get_stats()[slice_index].m_basis_bc1_luma_709_psnr,
- params.m_quality_level, (int)params.m_compression_level, tm.get_elapsed_secs());
- fflush(pCSV_file);
- }
- }
-
- if (opts.m_individual)
- printf("\n");
-
- } // file_index
-
- if (pCSV_file)
- {
- fclose(pCSV_file);
- pCSV_file = nullptr;
- }
-
- return true;
-}
-
-static bool unpack_and_validate_mode(command_line_params &opts, bool validate_flag)
-{
- basist::etc1_global_selector_codebook sel_codebook(basist::g_global_selector_cb_size, basist::g_global_selector_cb);
-
- if (!opts.m_input_filenames.size())
- {
- error_printf("No input files to process!\n");
- return false;
- }
-
- uint32_t total_unpack_warnings = 0;
- uint32_t total_pvrtc_nonpow2_warnings = 0;
-
- for (uint32_t file_index = 0; file_index < opts.m_input_filenames.size(); file_index++)
- {
- const char* pInput_filename = opts.m_input_filenames[file_index].c_str();
-
- std::string base_filename;
- string_split_path(pInput_filename, nullptr, nullptr, &base_filename, nullptr);
-
- uint8_vec basis_data;
- if (!basisu::read_file_to_vec(pInput_filename, basis_data))
- {
- error_printf("Failed reading file \"%s\"\n", pInput_filename);
- return false;
- }
-
- printf("Input file \"%s\"\n", pInput_filename);
-
- if (!basis_data.size())
- {
- error_printf("File is empty!\n");
- return false;
- }
-
- if (basis_data.size() > UINT32_MAX)
- {
- error_printf("File is too large!\n");
- return false;
- }
-
- basist::basisu_transcoder dec(&sel_codebook);
-
- if (!opts.m_fuzz_testing)
- {
- // Skip the full validation, which CRC16's the entire file.
-
- // Validate the file - note this isn't necessary for transcoding
- if (!dec.validate_file_checksums(&basis_data[0], (uint32_t)basis_data.size(), true))
- {
- error_printf("File version is unsupported, or file fail CRC checks!\n");
- return false;
- }
- }
-
- printf("File version and CRC checks succeeded\n");
-
- basist::basisu_file_info fileinfo;
- if (!dec.get_file_info(&basis_data[0], (uint32_t)basis_data.size(), fileinfo))
- {
- error_printf("Failed retrieving Basis file information!\n");
- return false;
- }
-
- assert(fileinfo.m_total_images == fileinfo.m_image_mipmap_levels.size());
- assert(fileinfo.m_total_images == dec.get_total_images(&basis_data[0], (uint32_t)basis_data.size()));
-
- printf("File info:\n");
- printf(" Version: %X\n", fileinfo.m_version);
- printf(" Total header size: %u\n", fileinfo.m_total_header_size);
- printf(" Total selectors: %u\n", fileinfo.m_total_selectors);
- printf(" Selector codebook size: %u\n", fileinfo.m_selector_codebook_size);
- printf(" Total endpoints: %u\n", fileinfo.m_total_endpoints);
- printf(" Endpoint codebook size: %u\n", fileinfo.m_endpoint_codebook_size);
- printf(" Tables size: %u\n", fileinfo.m_tables_size);
- printf(" Slices size: %u\n", fileinfo.m_slices_size);
- printf(" Texture type: %s\n", basist::basis_get_texture_type_name(fileinfo.m_tex_type));
- printf(" us per frame: %u (%f fps)\n", fileinfo.m_us_per_frame, fileinfo.m_us_per_frame ? (1.0f / ((float)fileinfo.m_us_per_frame / 1000000.0f)) : 0.0f);
- printf(" Total slices: %u\n", (uint32_t)fileinfo.m_slice_info.size());
- printf(" Total images: %i\n", fileinfo.m_total_images);
- printf(" Y Flipped: %u, Has alpha slices: %u\n", fileinfo.m_y_flipped, fileinfo.m_has_alpha_slices);
- printf(" userdata0: 0x%X userdata1: 0x%X\n", fileinfo.m_userdata0, fileinfo.m_userdata1);
- printf(" Per-image mipmap levels: ");
- for (uint32_t i = 0; i < fileinfo.m_total_images; i++)
- printf("%u ", fileinfo.m_image_mipmap_levels[i]);
- printf("\n");
-
- printf("\nImage info:\n");
- for (uint32_t i = 0; i < fileinfo.m_total_images; i++)
- {
- basist::basisu_image_info ii;
- if (!dec.get_image_info(&basis_data[0], (uint32_t)basis_data.size(), ii, i))
- {
- error_printf("get_image_info() failed!\n");
- return false;
- }
-
- printf("Image %u: MipLevels: %u OrigDim: %ux%u, BlockDim: %ux%u, FirstSlice: %u, HasAlpha: %u\n", i, ii.m_total_levels, ii.m_orig_width, ii.m_orig_height,
- ii.m_num_blocks_x, ii.m_num_blocks_y, ii.m_first_slice_index, (uint32_t)ii.m_alpha_flag);
- }
-
- printf("\nSlice info:\n");
- for (uint32_t i = 0; i < fileinfo.m_slice_info.size(); i++)
- {
- const basist::basisu_slice_info& sliceinfo = fileinfo.m_slice_info[i];
- printf("%u: OrigWidthHeight: %ux%u, BlockDim: %ux%u, TotalBlocks: %u, Compressed size: %u, Image: %u, Level: %u, UnpackedCRC16: 0x%X, alpha: %u, iframe: %i\n",
- i,
- sliceinfo.m_orig_width, sliceinfo.m_orig_height,
- sliceinfo.m_num_blocks_x, sliceinfo.m_num_blocks_y,
- sliceinfo.m_total_blocks,
- sliceinfo.m_compressed_size,
- sliceinfo.m_image_index, sliceinfo.m_level_index,
- sliceinfo.m_unpacked_slice_crc16,
- (uint32_t)sliceinfo.m_alpha_flag,
- (uint32_t)sliceinfo.m_iframe_flag);
- }
- printf("\n");
-
- interval_timer tm;
- tm.start();
-
- if (!dec.start_transcoding(&basis_data[0], (uint32_t)basis_data.size()))
- {
- error_printf("start_transcoding() failed!\n");
- return false;
- }
-
- printf("start_transcoding time: %3.3f ms\n", tm.get_elapsed_ms());
-
- std::vector< gpu_image_vec > gpu_images[(int)basist::transcoder_texture_format::cTFTotalTextureFormats];
-
- int first_format = 0;
- int last_format = (int)basist::transcoder_texture_format::cTFTotalTextureFormats;
-
- if (opts.m_etc1_only)
- {
- first_format = (int)basist::transcoder_texture_format::cTFETC1_RGB;
- last_format = first_format + 1;
- }
-
- for (int format_iter = first_format; format_iter < last_format; format_iter++)
- {
- basist::transcoder_texture_format tex_fmt = static_cast<basist::transcoder_texture_format>(format_iter);
-
- if (basist::basis_transcoder_format_is_uncompressed(tex_fmt))
- continue;
-
- gpu_images[(int)tex_fmt].resize(fileinfo.m_total_images);
-
- for (uint32_t image_index = 0; image_index < fileinfo.m_total_images; image_index++)
- gpu_images[(int)tex_fmt][image_index].resize(fileinfo.m_image_mipmap_levels[image_index]);
- }
-
- // Now transcode the file to all supported texture formats and save mipmapped KTX files
- for (int format_iter = first_format; format_iter < last_format; format_iter++)
- {
- const basist::transcoder_texture_format transcoder_tex_fmt = static_cast<basist::transcoder_texture_format>(format_iter);
-
- if (basist::basis_transcoder_format_is_uncompressed(transcoder_tex_fmt))
- continue;
-
- for (uint32_t image_index = 0; image_index < fileinfo.m_total_images; image_index++)
- {
- for (uint32_t level_index = 0; level_index < fileinfo.m_image_mipmap_levels[image_index]; level_index++)
- {
- basist::basisu_image_level_info level_info;
-
- if (!dec.get_image_level_info(&basis_data[0], (uint32_t)basis_data.size(), level_info, image_index, level_index))
- {
- error_printf("Failed retrieving image level information (%u %u)!\n", image_index, level_index);
- return false;
- }
-
- if ((transcoder_tex_fmt == basist::transcoder_texture_format::cTFPVRTC1_4_RGB) || (transcoder_tex_fmt == basist::transcoder_texture_format::cTFPVRTC1_4_RGBA))
- {
- if (!is_pow2(level_info.m_width) || !is_pow2(level_info.m_height))
- {
- total_pvrtc_nonpow2_warnings++;
-
- printf("Warning: Will not transcode image %u level %u res %ux%u to PVRTC1 (one or more dimension is not a power of 2)\n", image_index, level_index, level_info.m_width, level_info.m_height);
-
- // Can't transcode this image level to PVRTC because it's not a pow2 (we're going to support transcoding non-pow2 to the next larger pow2 soon)
- continue;
- }
- }
-
- basisu::texture_format tex_fmt = basis_get_basisu_texture_format(transcoder_tex_fmt);
-
- gpu_image& gi = gpu_images[(int)transcoder_tex_fmt][image_index][level_index];
- gi.init(tex_fmt, level_info.m_orig_width, level_info.m_orig_height);
-
- // Fill the buffer with psuedo-random bytes, to help more visibly detect cases where the transcoder fails to write to part of the output.
- fill_buffer_with_random_bytes(gi.get_ptr(), gi.get_size_in_bytes());
-
- uint32_t decode_flags = 0;
-
- tm.start();
-
- if (!dec.transcode_image_level(&basis_data[0], (uint32_t)basis_data.size(), image_index, level_index, gi.get_ptr(), gi.get_total_blocks(), transcoder_tex_fmt, decode_flags))
- {
- error_printf("Failed transcoding image level (%u %u %u)!\n", image_index, level_index, format_iter);
- return false;
- }
-
- double total_transcode_time = tm.get_elapsed_ms();
-
- printf("Transcode of image %u level %u res %ux%u format %s succeeded in %3.3f ms\n", image_index, level_index, level_info.m_orig_width, level_info.m_orig_height, basist::basis_get_format_name(transcoder_tex_fmt), total_transcode_time);
-
- } // format_iter
-
- } // level_index
-
- } // image_info
-
- if (!validate_flag)
- {
- // Now write KTX files and unpack them to individual PNG's
-
- for (int format_iter = first_format; format_iter < last_format; format_iter++)
- {
- const basist::transcoder_texture_format transcoder_tex_fmt = static_cast<basist::transcoder_texture_format>(format_iter);
-
- if (basist::basis_transcoder_format_is_uncompressed(transcoder_tex_fmt))
- continue;
-
- if ((!opts.m_no_ktx) && (fileinfo.m_tex_type == basist::cBASISTexTypeCubemapArray))
- {
- // No KTX tool that we know of supports cubemap arrays, so write individual cubemap files.
- for (uint32_t image_index = 0; image_index < fileinfo.m_total_images; image_index += 6)
- {
- std::vector<gpu_image_vec> cubemap;
- for (uint32_t i = 0; i < 6; i++)
- cubemap.push_back(gpu_images[format_iter][image_index + i]);
-
- std::string ktx_filename(base_filename + string_format("_transcoded_cubemap_%s_%u.ktx", basist::basis_get_format_name(transcoder_tex_fmt), image_index / 6));
- if (!write_compressed_texture_file(ktx_filename.c_str(), cubemap, true))
- {
- error_printf("Failed writing KTX file \"%s\"!\n", ktx_filename.c_str());
- return false;
- }
- printf("Wrote KTX file \"%s\"\n", ktx_filename.c_str());
- }
- }
-
- for (uint32_t image_index = 0; image_index < fileinfo.m_total_images; image_index++)
- {
- gpu_image_vec& gi = gpu_images[format_iter][image_index];
-
- if (!gi.size())
- continue;
-
- uint32_t level;
- for (level = 0; level < gi.size(); level++)
- if (!gi[level].get_total_blocks())
- break;
-
- if (level < gi.size())
- continue;
-
- if ((!opts.m_no_ktx) && (fileinfo.m_tex_type != basist::cBASISTexTypeCubemapArray))
- {
- std::string ktx_filename(base_filename + string_format("_transcoded_%s_%04u.ktx", basist::basis_get_format_name(transcoder_tex_fmt), image_index));
- if (!write_compressed_texture_file(ktx_filename.c_str(), gi))
- {
- error_printf("Failed writing KTX file \"%s\"!\n", ktx_filename.c_str());
- return false;
- }
- printf("Wrote KTX file \"%s\"\n", ktx_filename.c_str());
- }
-
- for (uint32_t level_index = 0; level_index < gi.size(); level_index++)
- {
- basist::basisu_image_level_info level_info;
-
- if (!dec.get_image_level_info(&basis_data[0], (uint32_t)basis_data.size(), level_info, image_index, level_index))
- {
- error_printf("Failed retrieving image level information (%u %u)!\n", image_index, level_index);
- return false;
- }
-
- image u;
- if (!gi[level_index].unpack(u))
- {
- printf("Warning: Failed unpacking GPU texture data (%u %u %u). Unpacking as much as possible.\n", format_iter, image_index, level_index);
- total_unpack_warnings++;
- }
- //u.crop(level_info.m_orig_width, level_info.m_orig_height);
-
- std::string rgb_filename;
- if (gi.size() > 1)
- rgb_filename = base_filename + string_format("_unpacked_rgb_%s_%u_%04u.png", basist::basis_get_format_name(transcoder_tex_fmt), level_index, image_index);
- else
- rgb_filename = base_filename + string_format("_unpacked_rgb_%s_%04u.png", basist::basis_get_format_name(transcoder_tex_fmt), image_index);
- if (!save_png(rgb_filename, u, cImageSaveIgnoreAlpha))
- {
- error_printf("Failed writing to PNG file \"%s\"\n", rgb_filename.c_str());
- return false;
- }
- printf("Wrote PNG file \"%s\"\n", rgb_filename.c_str());
-
- if (transcoder_tex_fmt == basist::transcoder_texture_format::cTFFXT1_RGB)
- {
- std::string out_filename;
- if (gi.size() > 1)
- out_filename = base_filename + string_format("_unpacked_rgb_%s_%u_%04u.out", basist::basis_get_format_name(transcoder_tex_fmt), level_index, image_index);
- else
- out_filename = base_filename + string_format("_unpacked_rgb_%s_%04u.out", basist::basis_get_format_name(transcoder_tex_fmt), image_index);
- if (!write_3dfx_out_file(out_filename.c_str(), gi[level_index]))
- {
- error_printf("Failed writing to OUT file \"%s\"\n", out_filename.c_str());
- return false;
- }
- printf("Wrote .OUT file \"%s\"\n", out_filename.c_str());
- }
-
- if (basis_transcoder_format_has_alpha(transcoder_tex_fmt))
- {
- std::string a_filename;
- if (gi.size() > 1)
- a_filename = base_filename + string_format("_unpacked_a_%s_%u_%04u.png", basist::basis_get_format_name(transcoder_tex_fmt), level_index, image_index);
- else
- a_filename = base_filename + string_format("_unpacked_a_%s_%04u.png", basist::basis_get_format_name(transcoder_tex_fmt), image_index);
- if (!save_png(a_filename, u, cImageSaveGrayscale, 3))
- {
- error_printf("Failed writing to PNG file \"%s\"\n", a_filename.c_str());
- return false;
- }
- printf("Wrote PNG file \"%s\"\n", a_filename.c_str());
- }
-
- } // level_index
-
- } // image_index
-
- } // format_iter
-
- } // if (!validate_flag)
-
- // Now unpack to RGBA using the transcoder itself to do the unpacking to raster images
- for (uint32_t image_index = 0; image_index < fileinfo.m_total_images; image_index++)
- {
- for (uint32_t level_index = 0; level_index < fileinfo.m_image_mipmap_levels[image_index]; level_index++)
- {
- const basist::transcoder_texture_format transcoder_tex_fmt = basist::transcoder_texture_format::cTFRGBA32;
-
- basist::basisu_image_level_info level_info;
-
- if (!dec.get_image_level_info(&basis_data[0], (uint32_t)basis_data.size(), level_info, image_index, level_index))
- {
- error_printf("Failed retrieving image level information (%u %u)!\n", image_index, level_index);
- return false;
- }
-
- image img(level_info.m_orig_width, level_info.m_orig_height);
-
- fill_buffer_with_random_bytes(&img(0, 0), img.get_total_pixels() * sizeof(uint32_t));
-
- tm.start();
-
- if (!dec.transcode_image_level(&basis_data[0], (uint32_t)basis_data.size(), image_index, level_index, &img(0, 0).r, img.get_total_pixels(), transcoder_tex_fmt, 0, img.get_pitch(), nullptr, img.get_height()))
- {
- error_printf("Failed transcoding image level (%u %u %u)!\n", image_index, level_index, transcoder_tex_fmt);
- return false;
- }
-
- double total_transcode_time = tm.get_elapsed_ms();
-
- printf("Transcode of image %u level %u res %ux%u format %s succeeded in %3.3f ms\n", image_index, level_index, level_info.m_orig_width, level_info.m_orig_height, basist::basis_get_format_name(transcoder_tex_fmt), total_transcode_time);
-
- std::string rgb_filename(base_filename + string_format("_unpacked_rgb_%s_%u_%04u.png", basist::basis_get_format_name(transcoder_tex_fmt), level_index, image_index));
- if (!save_png(rgb_filename, img, cImageSaveIgnoreAlpha))
- {
- error_printf("Failed writing to PNG file \"%s\"\n", rgb_filename.c_str());
- return false;
- }
- printf("Wrote PNG file \"%s\"\n", rgb_filename.c_str());
-
- std::string a_filename(base_filename + string_format("_unpacked_a_%s_%u_%04u.png", basist::basis_get_format_name(transcoder_tex_fmt), level_index, image_index));
- if (!save_png(a_filename, img, cImageSaveGrayscale, 3))
- {
- error_printf("Failed writing to PNG file \"%s\"\n", a_filename.c_str());
- return false;
- }
- printf("Wrote PNG file \"%s\"\n", a_filename.c_str());
-
- } // level_index
- } // image_index
-
- // Now unpack to RGB565 using the transcoder itself to do the unpacking to raster images
- for (uint32_t image_index = 0; image_index < fileinfo.m_total_images; image_index++)
- {
- for (uint32_t level_index = 0; level_index < fileinfo.m_image_mipmap_levels[image_index]; level_index++)
- {
- const basist::transcoder_texture_format transcoder_tex_fmt = basist::transcoder_texture_format::cTFRGB565;
-
- basist::basisu_image_level_info level_info;
-
- if (!dec.get_image_level_info(&basis_data[0], (uint32_t)basis_data.size(), level_info, image_index, level_index))
- {
- error_printf("Failed retrieving image level information (%u %u)!\n", image_index, level_index);
- return false;
- }
-
- std::vector<uint16_t> packed_img(level_info.m_orig_width * level_info.m_orig_height);
-
- fill_buffer_with_random_bytes(&packed_img[0], packed_img.size() * sizeof(uint16_t));
-
- tm.start();
-
- if (!dec.transcode_image_level(&basis_data[0], (uint32_t)basis_data.size(), image_index, level_index, &packed_img[0], (uint32_t)packed_img.size(), transcoder_tex_fmt, 0, level_info.m_orig_width, nullptr, level_info.m_orig_height))
- {
- error_printf("Failed transcoding image level (%u %u %u)!\n", image_index, level_index, transcoder_tex_fmt);
- return false;
- }
-
- double total_transcode_time = tm.get_elapsed_ms();
-
- image img(level_info.m_orig_width, level_info.m_orig_height);
- for (uint32_t y = 0; y < level_info.m_orig_height; y++)
- {
- for (uint32_t x = 0; x < level_info.m_orig_width; x++)
- {
- const uint16_t p = packed_img[x + y * level_info.m_orig_width];
- uint32_t r = p >> 11, g = (p >> 5) & 63, b = p & 31;
- r = (r << 3) | (r >> 2);
- g = (g << 2) | (g >> 4);
- b = (b << 3) | (b >> 2);
- img(x, y).set(r, g, b, 255);
- }
- }
-
- printf("Transcode of image %u level %u res %ux%u format %s succeeded in %3.3f ms\n", image_index, level_index, level_info.m_orig_width, level_info.m_orig_height, basist::basis_get_format_name(transcoder_tex_fmt), total_transcode_time);
-
- std::string rgb_filename(base_filename + string_format("_unpacked_rgb_%s_%u_%04u.png", basist::basis_get_format_name(transcoder_tex_fmt), level_index, image_index));
- if (!save_png(rgb_filename, img, cImageSaveIgnoreAlpha))
- {
- error_printf("Failed writing to PNG file \"%s\"\n", rgb_filename.c_str());
- return false;
- }
- printf("Wrote PNG file \"%s\"\n", rgb_filename.c_str());
-
- } // level_index
- } // image_index
-
- // Now unpack to RGBA4444 using the transcoder itself to do the unpacking to raster images
- for (uint32_t image_index = 0; image_index < fileinfo.m_total_images; image_index++)
- {
- for (uint32_t level_index = 0; level_index < fileinfo.m_image_mipmap_levels[image_index]; level_index++)
- {
- const basist::transcoder_texture_format transcoder_tex_fmt = basist::transcoder_texture_format::cTFRGBA4444;
-
- basist::basisu_image_level_info level_info;
-
- if (!dec.get_image_level_info(&basis_data[0], (uint32_t)basis_data.size(), level_info, image_index, level_index))
- {
- error_printf("Failed retrieving image level information (%u %u)!\n", image_index, level_index);
- return false;
- }
-
- std::vector<uint16_t> packed_img(level_info.m_orig_width * level_info.m_orig_height);
-
- fill_buffer_with_random_bytes(&packed_img[0], packed_img.size() * sizeof(uint16_t));
-
- tm.start();
-
- if (!dec.transcode_image_level(&basis_data[0], (uint32_t)basis_data.size(), image_index, level_index, &packed_img[0], (uint32_t)packed_img.size(), transcoder_tex_fmt, 0, level_info.m_orig_width, nullptr, level_info.m_orig_height))
- {
- error_printf("Failed transcoding image level (%u %u %u)!\n", image_index, level_index, transcoder_tex_fmt);
- return false;
- }
-
- double total_transcode_time = tm.get_elapsed_ms();
-
- image img(level_info.m_orig_width, level_info.m_orig_height);
- for (uint32_t y = 0; y < level_info.m_orig_height; y++)
- {
- for (uint32_t x = 0; x < level_info.m_orig_width; x++)
- {
- const uint16_t p = packed_img[x + y * level_info.m_orig_width];
- uint32_t r = p >> 12, g = (p >> 8) & 15, b = (p >> 4) & 15, a = p & 15;
- r = (r << 4) | r;
- g = (g << 4) | g;
- b = (b << 4) | b;
- a = (a << 4) | a;
- img(x, y).set(r, g, b, a);
- }
- }
-
- printf("Transcode of image %u level %u res %ux%u format %s succeeded in %3.3f ms\n", image_index, level_index, level_info.m_orig_width, level_info.m_orig_height, basist::basis_get_format_name(transcoder_tex_fmt), total_transcode_time);
-
- std::string rgb_filename(base_filename + string_format("_unpacked_rgb_%s_%u_%04u.png", basist::basis_get_format_name(transcoder_tex_fmt), level_index, image_index));
- if (!save_png(rgb_filename, img, cImageSaveIgnoreAlpha))
- {
- error_printf("Failed writing to PNG file \"%s\"\n", rgb_filename.c_str());
- return false;
- }
- printf("Wrote PNG file \"%s\"\n", rgb_filename.c_str());
-
- std::string a_filename(base_filename + string_format("_unpacked_a_%s_%u_%04u.png", basist::basis_get_format_name(transcoder_tex_fmt), level_index, image_index));
- if (!save_png(a_filename, img, cImageSaveGrayscale, 3))
- {
- error_printf("Failed writing to PNG file \"%s\"\n", a_filename.c_str());
- return false;
- }
- printf("Wrote PNG file \"%s\"\n", a_filename.c_str());
-
- } // level_index
- } // image_index
-
- } // file_index
-
- if (total_pvrtc_nonpow2_warnings)
- printf("Warning: %u images could not be transcoded to PVRTC1 because one or both dimensions were not a power of 2\n", total_pvrtc_nonpow2_warnings);
-
- if (total_unpack_warnings)
- printf("ATTENTION: %u total images had invalid GPU texture data!\n", total_unpack_warnings);
- else
- printf("Success\n");
-
- return true;
-}
-
-static bool compare_mode(command_line_params &opts)
-{
- if (opts.m_input_filenames.size() != 2)
- {
- error_printf("Must specify two PNG filenames using -file\n");
- return false;
- }
-
- image a, b;
- if (!load_png(opts.m_input_filenames[0].c_str(), a))
- {
- error_printf("Failed loading image from file \"%s\"!\n", opts.m_input_filenames[0].c_str());
- return false;
- }
-
- printf("Loaded \"%s\", %ux%u, has alpha: %u\n", opts.m_input_filenames[0].c_str(), a.get_width(), a.get_height(), a.has_alpha());
-
- if (!load_png(opts.m_input_filenames[1].c_str(), b))
- {
- error_printf("Failed loading image from file \"%s\"!\n", opts.m_input_filenames[1].c_str());
- return false;
- }
-
- printf("Loaded \"%s\", %ux%u, has alpha: %u\n", opts.m_input_filenames[1].c_str(), b.get_width(), b.get_height(), b.has_alpha());
-
- if ((a.get_width() != b.get_width()) || (a.get_height() != b.get_height()))
- {
- printf("Images don't have the same dimensions - cropping input images to smallest common dimensions\n");
-
- uint32_t w = minimum(a.get_width(), b.get_width());
- uint32_t h = minimum(a.get_height(), b.get_height());
-
- a.crop(w, h);
- b.crop(w, h);
- }
-
- printf("Comparison image res: %ux%u\n", a.get_width(), a.get_height());
-
- image_metrics im;
- im.calc(a, b, 0, 3);
- im.print("RGB ");
-
- im.calc(a, b, 0, 1);
- im.print("R ");
-
- im.calc(a, b, 1, 1);
- im.print("G ");
-
- im.calc(a, b, 2, 1);
- im.print("B ");
-
- im.calc(a, b, 0, 0);
- im.print("Y 709 " );
-
- im.calc(a, b, 0, 0, true, true);
- im.print("Y 601 " );
-
- if (opts.m_compare_ssim)
- {
- vec4F s_rgb(compute_ssim(a, b, false, false));
-
- printf("R SSIM: %f\n", s_rgb[0]);
- printf("G SSIM: %f\n", s_rgb[1]);
- printf("B SSIM: %f\n", s_rgb[2]);
- printf("RGB Avg SSIM: %f\n", (s_rgb[0] + s_rgb[1] + s_rgb[2]) / 3.0f);
- printf("A SSIM: %f\n", s_rgb[3]);
-
- vec4F s_y_709(compute_ssim(a, b, true, false));
- printf("Y 709 SSIM: %f\n", s_y_709[0]);
-
- vec4F s_y_601(compute_ssim(a, b, true, true));
- printf("Y 601 SSIM: %f\n", s_y_601[0]);
- }
-
- image delta_img(a.get_width(), a.get_height());
-
- const int X = 2;
-
- for (uint32_t y = 0; y < a.get_height(); y++)
- {
- for (uint32_t x = 0; x < a.get_width(); x++)
- {
- color_rgba &d = delta_img(x, y);
-
- for (int c = 0; c < 4; c++)
- d[c] = (uint8_t)clamp<int>((a(x, y)[c] - b(x, y)[c]) * X + 128, 0, 255);
- } // x
- } // y
-
- save_png("a_rgb.png", a, cImageSaveIgnoreAlpha);
- save_png("a_alpha.png", a, cImageSaveGrayscale, 3);
- printf("Wrote a_rgb.png and a_alpha.png\n");
-
- save_png("b_rgb.png", b, cImageSaveIgnoreAlpha);
- save_png("b_alpha.png", b, cImageSaveGrayscale, 3);
- printf("Wrote b_rgb.png and b_alpha.png\n");
-
- save_png("delta_img_rgb.png", delta_img, cImageSaveIgnoreAlpha);
- printf("Wrote delta_img_rgb.png\n");
-
- save_png("delta_img_a.png", delta_img, cImageSaveGrayscale, 3);
- printf("Wrote delta_img_a.png\n");
-
- return true;
-}
-
-static int main_internal(int argc, const char **argv)
-{
- printf("Basis Universal GPU Texture Compressor Reference Encoder v" BASISU_TOOL_VERSION ", Copyright (C) 2019 Binomial LLC, All rights reserved\n");
-
- //interval_timer tm;
- //tm.start();
-
- basisu_encoder_init();
-
- //printf("Encoder and transcoder libraries initialized in %3.3f ms\n", tm.get_elapsed_ms());
-
-#if defined(DEBUG) || defined(_DEBUG)
- printf("DEBUG build\n");
-#endif
-
- if (argc == 1)
- {
- print_usage();
- return EXIT_FAILURE;
- }
-
- command_line_params opts;
- if (!opts.parse(argc, argv))
- {
- print_usage();
- return EXIT_FAILURE;
- }
-
- if (!opts.process_listing_files())
- return EXIT_FAILURE;
-
- if (opts.m_mode == cDefault)
- {
- for (size_t i = 0; i < opts.m_input_filenames.size(); i++)
- {
- std::string ext(string_get_extension(opts.m_input_filenames[i]));
- if (strcasecmp(ext.c_str(), "basis") == 0)
- {
- // If they haven't specified any modes, and they give us a .basis file, then assume they want to unpack it.
- opts.m_mode = cUnpack;
- break;
- }
- }
- }
-
- bool status = false;
-
- switch (opts.m_mode)
- {
- case cDefault:
- case cCompress:
- status = compress_mode(opts);
- break;
- case cValidate:
- status = unpack_and_validate_mode(opts, true);
- break;
- case cUnpack:
- status = unpack_and_validate_mode(opts, false);
- break;
- case cCompare:
- status = compare_mode(opts);
- break;
- case cVersion:
- status = true; // We printed the version at the beginning of main_internal
- break;
- default:
- assert(0);
- break;
- }
-
- return status ? EXIT_SUCCESS : EXIT_FAILURE;
-}
-
-int main(int argc, const char **argv)
-{
- int status = EXIT_FAILURE;
-
-#if BASISU_CATCH_EXCEPTIONS
- try
- {
- status = main_internal(argc, argv);
- }
- catch (const std::exception &exc)
- {
- fprintf(stderr, "Fatal error: Caught exception \"%s\"\n", exc.what());
- }
- catch (...)
- {
- fprintf(stderr, "Fatal error: Uncaught exception!\n");
- }
-#else
- status = main_internal(argc, argv);
-#endif
-
- return status;
-}