summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gles2/rasterizer_storage_gles2.cpp5
-rw-r--r--drivers/gles3/shaders/scene.glsl38
-rw-r--r--drivers/unix/net_socket_posix.cpp48
-rw-r--r--drivers/unix/net_socket_posix.h2
4 files changed, 64 insertions, 29 deletions
diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp
index 388a8423a0..60f72608a8 100644
--- a/drivers/gles2/rasterizer_storage_gles2.cpp
+++ b/drivers/gles2/rasterizer_storage_gles2.cpp
@@ -5812,10 +5812,11 @@ void RasterizerStorageGLES2::initialize() {
config.support_npot_repeat_mipmap = config.extensions.has("GL_OES_texture_npot");
#ifdef JAVASCRIPT_ENABLED
- // no way of detecting 32 or 16 bit support for renderbuffer, so default to 32
+ // RenderBuffer internal format must be 16 bits in WebGL,
+ // but depth_texture should default to 32 always
// if the implementation doesn't support 32, it should just quietly use 16 instead
// https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/
- config.depth_buffer_internalformat = GL_DEPTH_COMPONENT;
+ config.depth_buffer_internalformat = GL_DEPTH_COMPONENT16;
config.depth_type = GL_UNSIGNED_INT;
#else
// on mobile check for 24 bit depth support for RenderBufferStorage
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl
index 549a36817e..63b2938551 100644
--- a/drivers/gles3/shaders/scene.glsl
+++ b/drivers/gles3/shaders/scene.glsl
@@ -897,18 +897,22 @@ float contact_shadow_compute(vec3 pos, vec3 dir, float max_distance) {
bias += incr * 2.0;
vec3 uv_depth = (source.xyz / source.w) * 0.5 + 0.5;
- float depth = texture(depth_buffer, uv_depth.xy).r;
-
- if (depth < uv_depth.z) {
- if (depth > (bias.z / bias.w) * 0.5 + 0.5) {
- return min(pow(ratio, 4.0), 1.0);
- } else {
- return 1.0;
+ if (uv_depth.x > 0.0 && uv_depth.x < 1.0 && uv_depth.y > 0.0 && uv_depth.y < 1.0) {
+ float depth = texture(depth_buffer, uv_depth.xy).r;
+
+ if (depth < uv_depth.z) {
+ if (depth > (bias.z / bias.w) * 0.5 + 0.5) {
+ return min(pow(ratio, 4.0), 1.0);
+ } else {
+ return 1.0;
+ }
}
- }
- ratio += ratio_incr;
- steps -= 1.0;
+ ratio += ratio_incr;
+ steps -= 1.0;
+ } else {
+ return 1.0;
+ }
}
return 1.0;
@@ -1254,7 +1258,12 @@ void light_process_omni(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 bi
vec3 light_rel_vec = omni_lights[idx].light_pos_inv_radius.xyz - vertex;
float light_length = length(light_rel_vec);
float normalized_distance = light_length * omni_lights[idx].light_pos_inv_radius.w;
- float omni_attenuation = pow(max(1.0 - normalized_distance, 0.0), omni_lights[idx].light_direction_attenuation.w);
+ float omni_attenuation;
+ if (normalized_distance < 1.0) {
+ omni_attenuation = pow(normalized_distance, omni_lights[idx].light_direction_attenuation.w);
+ } else {
+ omni_attenuation = 0.0;
+ }
vec3 light_attenuation = vec3(omni_attenuation);
#if !defined(SHADOWS_DISABLED)
@@ -1313,7 +1322,12 @@ void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 bi
vec3 light_rel_vec = spot_lights[idx].light_pos_inv_radius.xyz - vertex;
float light_length = length(light_rel_vec);
float normalized_distance = light_length * spot_lights[idx].light_pos_inv_radius.w;
- float spot_attenuation = pow(max(1.0 - normalized_distance, 0.001), spot_lights[idx].light_direction_attenuation.w);
+ float spot_attenuation;
+ if (normalized_distance < 1.0) {
+ spot_attenuation = pow(1.0 - normalized_distance, spot_lights[idx].light_direction_attenuation.w);
+ } else {
+ spot_attenuation = 0.0;
+ }
vec3 spot_dir = spot_lights[idx].light_direction_attenuation.xyz;
float spot_cutoff = spot_lights[idx].light_params.y;
float scos = max(dot(-normalize(light_rel_vec), spot_dir), spot_cutoff);
diff --git a/drivers/unix/net_socket_posix.cpp b/drivers/unix/net_socket_posix.cpp
index 003c372107..0e3d81ed66 100644
--- a/drivers/unix/net_socket_posix.cpp
+++ b/drivers/unix/net_socket_posix.cpp
@@ -189,7 +189,7 @@ NetSocketPosix::~NetSocketPosix() {
#pragma GCC diagnostic ignored "-Wlogical-op"
#endif
-NetSocketPosix::NetError NetSocketPosix::_get_socket_error() {
+NetSocketPosix::NetError NetSocketPosix::_get_socket_error() const {
#if defined(WINDOWS_ENABLED)
int err = WSAGetLastError();
@@ -199,7 +199,7 @@ NetSocketPosix::NetError NetSocketPosix::_get_socket_error() {
return ERR_NET_IN_PROGRESS;
if (err == WSAEWOULDBLOCK)
return ERR_NET_WOULD_BLOCK;
- ERR_PRINTS("Socket error: " + itos(err));
+ print_verbose("Socket error: " + itos(err));
return ERR_NET_OTHER;
#else
if (errno == EISCONN)
@@ -208,7 +208,7 @@ NetSocketPosix::NetError NetSocketPosix::_get_socket_error() {
return ERR_NET_IN_PROGRESS;
if (errno == EAGAIN || errno == EWOULDBLOCK)
return ERR_NET_WOULD_BLOCK;
- ERR_PRINTS("Socket error: " + itos(errno));
+ print_verbose("Socket error: " + itos(errno));
return ERR_NET_OTHER;
#endif
}
@@ -387,8 +387,10 @@ Error NetSocketPosix::bind(IP_Address p_addr, uint16_t p_port) {
size_t addr_size = _set_addr_storage(&addr, p_addr, p_port, _ip_type);
if (::bind(_sock, (struct sockaddr *)&addr, addr_size) != 0) {
+ _get_socket_error();
+ print_verbose("Failed to bind socket.");
close();
- ERR_FAIL_V(ERR_UNAVAILABLE);
+ return ERR_UNAVAILABLE;
}
return OK;
@@ -398,9 +400,10 @@ Error NetSocketPosix::listen(int p_max_pending) {
ERR_FAIL_COND_V(!is_open(), ERR_UNCONFIGURED);
if (::listen(_sock, p_max_pending) != 0) {
-
+ _get_socket_error();
+ print_verbose("Failed to listen from socket.");
close();
- ERR_FAIL_V(FAILED);
+ return FAILED;
};
return OK;
@@ -427,7 +430,7 @@ Error NetSocketPosix::connect_to_host(IP_Address p_host, uint16_t p_port) {
case ERR_NET_IN_PROGRESS:
return ERR_BUSY;
default:
- ERR_PRINT("Connection to remote host failed!");
+ print_verbose("Connection to remote host failed!");
close();
return FAILED;
}
@@ -474,12 +477,18 @@ Error NetSocketPosix::poll(PollType p_type, int p_timeout) const {
}
int ret = select(1, rdp, wrp, &ex, tp);
- ERR_FAIL_COND_V(ret == SOCKET_ERROR, FAILED);
+ if (ret == SOCKET_ERROR) {
+ return FAILED;
+ }
if (ret == 0)
return ERR_BUSY;
- ERR_FAIL_COND_V(FD_ISSET(_sock, &ex), FAILED);
+ if (FD_ISSET(_sock, &ex)) {
+ _get_socket_error();
+ print_verbose("Exception when polling socket.");
+ return FAILED;
+ }
if (rdp && FD_ISSET(_sock, rdp))
ready = true;
@@ -506,8 +515,11 @@ Error NetSocketPosix::poll(PollType p_type, int p_timeout) const {
int ret = ::poll(&pfd, 1, p_timeout);
- ERR_FAIL_COND_V(ret < 0, FAILED);
- ERR_FAIL_COND_V(pfd.revents & POLLERR, FAILED);
+ if (ret < 0 || pfd.revents & POLLERR) {
+ _get_socket_error();
+ print_verbose("Error when polling socket.");
+ return FAILED;
+ }
if (ret == 0)
return ERR_BUSY;
@@ -685,11 +697,15 @@ bool NetSocketPosix::is_open() const {
int NetSocketPosix::get_available_bytes() const {
- ERR_FAIL_COND_V(_sock == SOCK_EMPTY, -1);
+ ERR_FAIL_COND_V(!is_open(), -1);
unsigned long len;
int ret = SOCK_IOCTL(_sock, FIONREAD, &len);
- ERR_FAIL_COND_V(ret == -1, 0);
+ if (ret == -1) {
+ _get_socket_error();
+ print_verbose("Error when checking available bytes on socket.");
+ return -1;
+ }
return len;
}
@@ -701,7 +717,11 @@ Ref<NetSocket> NetSocketPosix::accept(IP_Address &r_ip, uint16_t &r_port) {
struct sockaddr_storage their_addr;
socklen_t size = sizeof(their_addr);
SOCKET_TYPE fd = ::accept(_sock, (struct sockaddr *)&their_addr, &size);
- ERR_FAIL_COND_V(fd == SOCK_EMPTY, out);
+ if (fd == SOCK_EMPTY) {
+ _get_socket_error();
+ print_verbose("Error when accepting socket connection.");
+ return out;
+ }
_set_ip_port(&their_addr, r_ip, r_port);
diff --git a/drivers/unix/net_socket_posix.h b/drivers/unix/net_socket_posix.h
index fe5a4858de..b37e0ffb30 100644
--- a/drivers/unix/net_socket_posix.h
+++ b/drivers/unix/net_socket_posix.h
@@ -58,7 +58,7 @@ private:
ERR_NET_OTHER
};
- NetError _get_socket_error();
+ NetError _get_socket_error() const;
void _set_socket(SOCKET_TYPE p_sock, IP::Type p_ip_type, bool p_is_stream);
_FORCE_INLINE_ Error _change_multicast_group(IP_Address p_ip, String p_if_name, bool p_add);
_FORCE_INLINE_ void _set_close_exec_enabled(bool p_enabled);