summaryrefslogtreecommitdiff
path: root/thirdparty
diff options
context:
space:
mode:
Diffstat (limited to 'thirdparty')
-rw-r--r--thirdparty/enet/godot.cpp68
-rw-r--r--thirdparty/oidn/core/transfer_function.cpp107
-rw-r--r--thirdparty/oidn/patches/godot-changes-c58c5216.patch68
3 files changed, 158 insertions, 85 deletions
diff --git a/thirdparty/enet/godot.cpp b/thirdparty/enet/godot.cpp
index 140f0093eb..189de6cc1f 100644
--- a/thirdparty/enet/godot.cpp
+++ b/thirdparty/enet/godot.cpp
@@ -46,6 +46,7 @@
class ENetGodotSocket {
public:
virtual Error bind(IP_Address p_ip, uint16_t p_port) = 0;
+ virtual Error get_socket_address(IP_Address *r_ip, uint16_t *r_port) = 0;
virtual Error sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IP_Address p_ip, uint16_t p_port) = 0;
virtual Error recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IP_Address &r_ip, uint16_t &r_port) = 0;
virtual int set_option(ENetSocketOption p_option, int p_value) = 0;
@@ -64,8 +65,7 @@ class ENetUDP : public ENetGodotSocket {
private:
Ref<NetSocket> sock;
- IP_Address address;
- uint16_t port = 0;
+ IP_Address local_address;
bool bound = false;
public:
@@ -80,10 +80,13 @@ public:
}
Error bind(IP_Address p_ip, uint16_t p_port) {
- address = p_ip;
- port = p_port;
+ local_address = p_ip;
bound = true;
- return sock->bind(address, port);
+ return sock->bind(p_ip, p_port);
+ }
+
+ Error get_socket_address(IP_Address *r_ip, uint16_t *r_port) {
+ return sock->get_socket_address(r_ip, r_port);
}
Error sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IP_Address p_ip, uint16_t p_port) {
@@ -142,6 +145,7 @@ public:
void close() {
sock->close();
+ local_address.clear();
}
};
@@ -153,6 +157,7 @@ class ENetDTLSClient : public ENetGodotSocket {
bool verify = false;
String for_hostname;
Ref<X509Certificate> cert;
+ IP_Address local_address;
public:
ENetDTLSClient(ENetUDP *p_base, Ref<X509Certificate> p_cert, bool p_verify, String p_for_hostname) {
@@ -161,9 +166,11 @@ public:
cert = p_cert;
udp.instance();
dtls = Ref<PacketPeerDTLS>(PacketPeerDTLS::create());
- p_base->close();
if (p_base->bound) {
- bind(p_base->address, p_base->port);
+ uint16_t port;
+ p_base->get_socket_address(&local_address, &port);
+ p_base->close();
+ bind(local_address, port);
}
}
@@ -172,9 +179,19 @@ public:
}
Error bind(IP_Address p_ip, uint16_t p_port) {
+ local_address = p_ip;
return udp->bind(p_port, p_ip);
}
+ Error get_socket_address(IP_Address *r_ip, uint16_t *r_port) {
+ if (!udp->is_bound()) {
+ return ERR_UNCONFIGURED;
+ }
+ *r_ip = local_address;
+ *r_port = udp->get_local_port();
+ return OK;
+ }
+
Error sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IP_Address p_ip, uint16_t p_port) {
if (!connected) {
udp->connect_to_host(p_ip, p_port);
@@ -233,13 +250,16 @@ class ENetDTLSServer : public ENetGodotSocket {
Ref<UDPServer> udp_server;
Map<String, Ref<PacketPeerDTLS>> peers;
int last_service = 0;
+ IP_Address local_address;
public:
ENetDTLSServer(ENetUDP *p_base, Ref<CryptoKey> p_key, Ref<X509Certificate> p_cert) {
udp_server.instance();
- p_base->close();
if (p_base->bound) {
- bind(p_base->address, p_base->port);
+ uint16_t port;
+ p_base->get_socket_address(&local_address, &port);
+ p_base->close();
+ bind(local_address, port);
}
server = Ref<DTLSServer>(DTLSServer::create());
server->setup(p_key, p_cert);
@@ -254,9 +274,19 @@ public:
}
Error bind(IP_Address p_ip, uint16_t p_port) {
+ local_address = p_ip;
return udp_server->listen(p_port, p_ip);
}
+ Error get_socket_address(IP_Address *r_ip, uint16_t *r_port) {
+ if (!udp_server->is_listening()) {
+ return ERR_UNCONFIGURED;
+ }
+ *r_ip = local_address;
+ *r_port = udp_server->get_local_port();
+ return OK;
+ }
+
Error sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IP_Address p_ip, uint16_t p_port) {
String key = String(p_ip) + ":" + itos(p_port);
ERR_FAIL_COND_V(!peers.has(key), ERR_UNAVAILABLE);
@@ -341,6 +371,7 @@ public:
peers.clear();
udp_server->stop();
server->stop();
+ local_address.clear();
}
};
@@ -493,15 +524,26 @@ int enet_socket_receive(ENetSocket socket, ENetAddress *address, ENetBuffer *buf
return read;
}
+int enet_socket_get_address (ENetSocket socket, ENetAddress * address) {
+ IP_Address ip;
+ uint16_t port;
+ ENetGodotSocket *sock = (ENetGodotSocket *)socket;
+
+ if (sock->get_socket_address(&ip, &port) != OK) {
+ return -1;
+ }
+
+ enet_address_set_ip(address, ip.get_ipv6(), 16);
+ address->port = port;
+
+ return 0;
+}
+
// Not implemented
int enet_socket_wait(ENetSocket socket, enet_uint32 *condition, enet_uint32 timeout) {
return 0; // do we need this function?
}
-int enet_socket_get_address(ENetSocket socket, ENetAddress *address) {
- return -1; // do we need this function?
-}
-
int enet_socketset_select(ENetSocket maxSocket, ENetSocketSet *readSet, ENetSocketSet *writeSet, enet_uint32 timeout) {
return -1;
}
diff --git a/thirdparty/oidn/core/transfer_function.cpp b/thirdparty/oidn/core/transfer_function.cpp
index 487f0a9f75..ce5deca56b 100644
--- a/thirdparty/oidn/core/transfer_function.cpp
+++ b/thirdparty/oidn/core/transfer_function.cpp
@@ -24,10 +24,6 @@ namespace oidn {
float AutoexposureNode::autoexposure(const Image& color)
{
assert(color.format == Format::Float3);
-// -- GODOT start --
-// We don't want to mess with TTB and we don't use autoexposure, so we disable this code
-#if 0
-// -- GODOT end --
constexpr float key = 0.18f;
constexpr float eps = 1e-8f;
@@ -42,61 +38,66 @@ namespace oidn {
// Compute the average log luminance of the downsampled image
using Sum = std::pair<float, int>;
- Sum sum =
- tbb::parallel_reduce(
- tbb::blocked_range2d<int>(0, HK, 0, WK),
- Sum(0.f, 0),
- [&](const tbb::blocked_range2d<int>& r, Sum sum) -> Sum
+ // -- GODOT start --
+ // Sum sum =
+ // tbb::parallel_reduce(
+ // tbb::blocked_range2d<int>(0, HK, 0, WK),
+ // Sum(0.f, 0),
+ // [&](const tbb::blocked_range2d<int>& r, Sum sum) -> Sum
+ // {
+ // // Iterate over blocks
+ // for (int i = r.rows().begin(); i != r.rows().end(); ++i)
+ // {
+ // for (int j = r.cols().begin(); j != r.cols().end(); ++j)
+ // {
+
+ Sum sum = Sum(0.0f, 0);
+
+ for (int i = 0; i != HK; ++i)
+ {
+ for (int j = 0; j != WK; ++j)
+ {
+ // Compute the average luminance in the current block
+ const int beginH = int(ptrdiff_t(i) * H / HK);
+ const int beginW = int(ptrdiff_t(j) * W / WK);
+ const int endH = int(ptrdiff_t(i+1) * H / HK);
+ const int endW = int(ptrdiff_t(j+1) * W / WK);
+
+ float L = 0.f;
+
+ for (int h = beginH; h < endH; ++h)
{
- // Iterate over blocks
- for (int i = r.rows().begin(); i != r.rows().end(); ++i)
+ for (int w = beginW; w < endW; ++w)
{
- for (int j = r.cols().begin(); j != r.cols().end(); ++j)
- {
- // Compute the average luminance in the current block
- const int beginH = int(ptrdiff_t(i) * H / HK);
- const int beginW = int(ptrdiff_t(j) * W / WK);
- const int endH = int(ptrdiff_t(i+1) * H / HK);
- const int endW = int(ptrdiff_t(j+1) * W / WK);
-
- float L = 0.f;
-
- for (int h = beginH; h < endH; ++h)
- {
- for (int w = beginW; w < endW; ++w)
- {
- const float* rgb = (const float*)color.get(h, w);
-
- const float r = maxSafe(rgb[0], 0.f);
- const float g = maxSafe(rgb[1], 0.f);
- const float b = maxSafe(rgb[2], 0.f);
-
- L += luminance(r, g, b);
- }
- }
-
- L /= (endH - beginH) * (endW - beginW);
-
- // Accumulate the log luminance
- if (L > eps)
- {
- sum.first += log2(L);
- sum.second++;
- }
- }
+ const float* rgb = (const float*)color.get(h, w);
+
+ const float r = maxSafe(rgb[0], 0.f);
+ const float g = maxSafe(rgb[1], 0.f);
+ const float b = maxSafe(rgb[2], 0.f);
+
+ L += luminance(r, g, b);
}
+ }
- return sum;
- },
- [](Sum a, Sum b) -> Sum { return Sum(a.first+b.first, a.second+b.second); },
- tbb::static_partitioner()
- );
+ L /= (endH - beginH) * (endW - beginW);
+
+ // Accumulate the log luminance
+ if (L > eps)
+ {
+ sum.first += log2(L);
+ sum.second++;
+ }
+ }
+ }
+
+ // return sum;
+ // },
+ // [](Sum a, Sum b) -> Sum { return Sum(a.first+b.first, a.second+b.second); },
+ // tbb::static_partitioner()
+ // );
+ // -- GODOT end --
return (sum.second > 0) ? (key / exp2(sum.first / float(sum.second))) : 1.f;
-// -- GODOT start --
-#endif
- return 1.0;
-// -- GODOT end --
}
} // namespace oidn
diff --git a/thirdparty/oidn/patches/godot-changes-c58c5216.patch b/thirdparty/oidn/patches/godot-changes-c58c5216.patch
index 6a54703064..c01f00187b 100644
--- a/thirdparty/oidn/patches/godot-changes-c58c5216.patch
+++ b/thirdparty/oidn/patches/godot-changes-c58c5216.patch
@@ -280,28 +280,58 @@ index 8c2de09..ed8328c 100644
namespace oidn {
diff --git a/core/transfer_function.cpp b/core/transfer_function.cpp
-index 601f814..487f0a9 100644
+index 601f814..ce5deca 100644
--- a/core/transfer_function.cpp
+++ b/core/transfer_function.cpp
-@@ -24,6 +24,10 @@ namespace oidn {
- float AutoexposureNode::autoexposure(const Image& color)
- {
- assert(color.format == Format::Float3);
-+// -- GODOT start --
-+// We don't want to mess with TTB and we don't use autoexposure, so we disable this code
-+#if 0
-+// -- GODOT end --
+@@ -38,16 +38,24 @@ namespace oidn {
+ // Compute the average log luminance of the downsampled image
+ using Sum = std::pair<float, int>;
+
+- Sum sum =
+- tbb::parallel_reduce(
+- tbb::blocked_range2d<int>(0, HK, 0, WK),
+- Sum(0.f, 0),
+- [&](const tbb::blocked_range2d<int>& r, Sum sum) -> Sum
++ // -- GODOT start --
++ // Sum sum =
++ // tbb::parallel_reduce(
++ // tbb::blocked_range2d<int>(0, HK, 0, WK),
++ // Sum(0.f, 0),
++ // [&](const tbb::blocked_range2d<int>& r, Sum sum) -> Sum
++ // {
++ // // Iterate over blocks
++ // for (int i = r.rows().begin(); i != r.rows().end(); ++i)
++ // {
++ // for (int j = r.cols().begin(); j != r.cols().end(); ++j)
++ // {
++
++ Sum sum = Sum(0.0f, 0);
++
++ for (int i = 0; i != HK; ++i)
+ {
+- // Iterate over blocks
+- for (int i = r.rows().begin(); i != r.rows().end(); ++i)
+- {
+- for (int j = r.cols().begin(); j != r.cols().end(); ++j)
++ for (int j = 0; j != WK; ++j)
+ {
+ // Compute the average luminance in the current block
+ const int beginH = int(ptrdiff_t(i) * H / HK);
+@@ -82,11 +90,12 @@ namespace oidn {
+ }
+ }
- constexpr float key = 0.18f;
- constexpr float eps = 1e-8f;
-@@ -89,6 +93,10 @@ namespace oidn {
- );
+- return sum;
+- },
+- [](Sum a, Sum b) -> Sum { return Sum(a.first+b.first, a.second+b.second); },
+- tbb::static_partitioner()
+- );
++ // return sum;
++ // },
++ // [](Sum a, Sum b) -> Sum { return Sum(a.first+b.first, a.second+b.second); },
++ // tbb::static_partitioner()
++ // );
++ // -- GODOT end --
return (sum.second > 0) ? (key / exp2(sum.first / float(sum.second))) : 1.f;
-+// -- GODOT start --
-+#endif
-+ return 1.0;
-+// -- GODOT end --
}
-
- } // namespace oidn