Skip to content

Commit

Permalink
Avalon: add EGL support, fix physics.
Browse files Browse the repository at this point in the history
  • Loading branch information
bawr committed Jun 16, 2022
1 parent 419e713 commit 54a2781
Show file tree
Hide file tree
Showing 35 changed files with 2,287 additions and 21 deletions.
4 changes: 4 additions & 0 deletions core/os/os.cpp
Expand Up @@ -675,6 +675,10 @@ bool OS::has_feature(const String &p_feature) {
}
#endif

if (p_feature == "zero_delay_physics") {
return true;
}

if (_check_internal_feature_support(p_feature)) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/gl_context/SCsub
Expand Up @@ -4,7 +4,7 @@ Import("env")

thirdparty_obj = []

if env["platform"] in ["haiku", "osx", "windows", "x11"]:
if env["platform"] in ["haiku", "osx", "windows", "x11", "egl"]:
# Thirdparty source files
thirdparty_dir = "#thirdparty/glad/"
thirdparty_sources = [
Expand Down
3 changes: 3 additions & 0 deletions drivers/gles3/rasterizer_gles3.cpp
Expand Up @@ -411,6 +411,9 @@ void RasterizerGLES3::end_frame(bool p_swap_buffers) {
}

if (p_swap_buffers) {
#ifdef EGL_ENABLED
glFinish();
#endif
OS::get_singleton()->swap_buffers();
} else {
glFinish();
Expand Down
11 changes: 10 additions & 1 deletion drivers/gles3/rasterizer_scene_gles3.cpp
Expand Up @@ -3513,7 +3513,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
//transfer to effect buffer if using buffers, also resolve MSAA
glBindFramebuffer(GL_READ_FRAMEBUFFER, storage->frame.current_rt->buffers.fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo);
glBlitFramebuffer(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, 0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBlitFramebuffer(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, 0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);

glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
Expand Down Expand Up @@ -3866,6 +3866,11 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo);
}

int depth_texture_id;
glActiveTexture(GL_TEXTURE1);
glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &depth_texture_id);
glBindTexture(GL_TEXTURE_2D, depth_texture_id);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, composite_from);
if (env) {
Expand Down Expand Up @@ -3966,6 +3971,10 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p

_copy_screen(true, true);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE0);

//turn off everything used
state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_FXAA, false);
state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_DEBANDING, false);
Expand Down
7 changes: 7 additions & 0 deletions drivers/gles3/rasterizer_storage_gles3.cpp
Expand Up @@ -2281,6 +2281,13 @@ void RasterizerStorageGLES3::_update_shader(Shader *p_shader) const {
return;
}

// TODO: alpha channel attempt:
/*
if (p_shader->spatial.unshaded) {
p_shader->spatial.uses_alpha = false;
}
*/

p_shader->shader->set_custom_shader_code(p_shader->custom_code_id, gen_code.vertex, gen_code.vertex_global, gen_code.fragment, gen_code.light, gen_code.fragment_global, gen_code.uniforms, gen_code.texture_uniforms, gen_code.defines);

p_shader->ubo_size = gen_code.uniform_total_size;
Expand Down
10 changes: 8 additions & 2 deletions drivers/gles3/shaders/tonemap.glsl
Expand Up @@ -28,6 +28,7 @@ precision mediump float;
in vec2 uv_interp;

uniform highp sampler2D source; //texunit:0
uniform highp sampler2D sdepth; //texunit:1

uniform float exposure;
uniform float white;
Expand Down Expand Up @@ -414,7 +415,6 @@ vec3 apply_cas(vec3 color, float exposure, vec2 uv_interp, float sharpen_intensi

void main() {
vec3 color = textureLod(source, uv_interp, 0.0f).rgb;

// Exposure
float full_exposure = exposure;

Expand Down Expand Up @@ -475,5 +475,11 @@ void main() {
color = apply_color_correction(color, color_correction);
#endif

frag_color = vec4(color, 1.0f);
highp float depth = textureLod(sdepth, uv_interp, 0.0f).r;
const float d_min = 0.01; // camera near
const float d_max = 1000; // camera far
depth = d_min / ((1.0 - depth) + (d_min / d_max));
depth = clamp(1.0 / (depth + 0.5), 0.0, 1.0);

frag_color = vec4(color, depth);
}
2 changes: 2 additions & 0 deletions drivers/unix/file_access_unix.cpp
Expand Up @@ -103,6 +103,7 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) {
int err = stat(path.utf8().get_data(), &st);
if (!err) {
switch (st.st_mode & S_IFMT) {
case S_IFIFO:
case S_IFLNK:
case S_IFREG:
break;
Expand Down Expand Up @@ -291,6 +292,7 @@ bool FileAccessUnix::file_exists(const String &p_path) {

// See if this is a regular file
switch (st.st_mode & S_IFMT) {
case S_IFIFO:
case S_IFLNK:
case S_IFREG:
return true;
Expand Down
6 changes: 6 additions & 0 deletions modules/bullet/bullet_physics_server.cpp
Expand Up @@ -1549,6 +1549,12 @@ void BulletPhysicsServer::step(float p_deltaTime) {
}

void BulletPhysicsServer::flush_queries() {
if (!active)
return;

for (int i = 0; i < active_spaces_count; ++i) {
active_spaces[i]->flush_queries();
}
}

void BulletPhysicsServer::finish() {
Expand Down
5 changes: 0 additions & 5 deletions modules/bullet/space_bullet.cpp
Expand Up @@ -573,10 +573,6 @@ void SpaceBullet::remove_all_collision_objects() {
}
}

void onBulletPreTickCallback(btDynamicsWorld *p_dynamicsWorld, btScalar timeStep) {
static_cast<SpaceBullet *>(p_dynamicsWorld->getWorldUserInfo())->flush_queries();
}

void onBulletTickCallback(btDynamicsWorld *p_dynamicsWorld, btScalar timeStep) {
const btCollisionObjectArray &colObjArray = p_dynamicsWorld->getCollisionObjectArray();

Expand Down Expand Up @@ -644,7 +640,6 @@ void SpaceBullet::create_empty_world(bool p_create_soft_world) {

dynamicsWorld->setWorldUserInfo(this);

dynamicsWorld->setInternalTickCallback(onBulletPreTickCallback, this, true);
dynamicsWorld->setInternalTickCallback(onBulletTickCallback, this, false);
dynamicsWorld->getBroadphase()->getOverlappingPairCache()->setInternalGhostPairCallback(ghostPairCallback); // Setup ghost check
dynamicsWorld->getPairCache()->setOverlapFilterCallback(godotFilterCallback);
Expand Down
4 changes: 2 additions & 2 deletions modules/denoise/config.py
Expand Up @@ -5,7 +5,7 @@ def can_build(env, platform):
# as doing lightmap generation and denoising on Android or HTML5
# would be a bit far-fetched.
# Note: oneDNN doesn't support ARM64, OIDN needs updating to the latest version
supported_platform = platform in ["x11", "osx", "windows", "server"]
supported_platform = platform in ["x11", "egl", "osx", "windows", "server"]
supported_bits = env["bits"] == "64"
supported_arch = env["arch"] != "arm64" and not env["arch"].startswith("rv")

Expand All @@ -14,7 +14,7 @@ def can_build(env, platform):
# bits-handling code.
from platform import machine

if platform == "x11" and machine() != "x86_64":
if platform in ["x11", "egl"] and machine() != "x86_64":
supported_arch = False

return env["tools"] and supported_platform and supported_bits and supported_arch
Expand Down
2 changes: 1 addition & 1 deletion modules/gdnative/nativescript/SCsub
Expand Up @@ -5,5 +5,5 @@ Import("env_gdnative")

env_gdnative.add_source_files(env.modules_sources, "*.cpp")

if "platform" in env and env["platform"] in ["x11", "iphone"]:
if "platform" in env and env["platform"] in ["x11", "egl", "iphone"]:
env.Append(LINKFLAGS=["-rdynamic"])
4 changes: 2 additions & 2 deletions modules/mono/build_scripts/mono_configure.py
Expand Up @@ -59,11 +59,11 @@ def copy_file(src_dir, dst_dir, src_name, dst_name=""):


def is_desktop(platform):
return platform in ["windows", "osx", "x11", "server", "uwp", "haiku"]
return platform in ["windows", "osx", "x11", "egl", "server", "uwp", "haiku"]


def is_unix_like(platform):
return platform in ["osx", "x11", "server", "android", "haiku", "iphone"]
return platform in ["osx", "x11", "egl", "server", "android", "haiku", "iphone"]


def module_supports_tools_on(platform):
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/config.py
@@ -1,4 +1,4 @@
supported_platforms = ["windows", "osx", "x11", "server", "android", "haiku", "javascript", "iphone"]
supported_platforms = ["windows", "osx", "x11", "egl", "server", "android", "haiku", "javascript", "iphone"]


def can_build(env, platform):
Expand Down
1 change: 1 addition & 0 deletions modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs
Expand Up @@ -36,6 +36,7 @@ public static class Platforms
public const string Windows = "windows";
public const string OSX = "osx";
public const string X11 = "x11";
public const string EGL = "egl";
public const string Server = "server";
public const string UWP = "uwp";
public const string Haiku = "haiku";
Expand Down
9 changes: 3 additions & 6 deletions modules/webm/libvpx/SCsub
Expand Up @@ -227,7 +227,7 @@ if env["platform"] == "uwp":
elif env["platform"] != "windows": # Disable for Windows, yasm SIMD optimizations trigger crash (GH-50862).
import platform

is_x11_or_server_arm = (env["platform"] == "x11" or env["platform"] == "server") and (
is_x11_or_server_arm = (env["platform"] in ["x11", "egl", "server"]) and (
platform.machine().startswith("arm") or platform.machine().startswith("aarch")
)
is_macos_x86 = env["platform"] == "osx" and ("arch" in env and (env["arch"] != "arm64"))
Expand All @@ -239,9 +239,7 @@ elif env["platform"] != "windows": # Disable for Windows, yasm SIMD optimizatio
not is_x11_or_server_arm
and (cpu_bits == "32" or cpu_bits == "64")
and (
env["platform"] == "windows"
or env["platform"] == "x11"
or env["platform"] == "haiku"
env["platform"] in ["windows", "x11", "egl", "haiku"]
or is_macos_x86
or is_android_x86
or is_ios_x86
Expand Down Expand Up @@ -309,8 +307,7 @@ if webm_cpu_arm:
elif (
env["platform"] == "android"
and env["android_arch"] == "armv7"
or env["platform"] == "x11"
or env["platform"] == "server"
or env["platform"] in ["x11", "egl", "server"]
):
env_libvpx["ASFLAGS"] = "-mfpu=neon"
elif env["platform"] == "uwp":
Expand Down
17 changes: 17 additions & 0 deletions platform/egl/SCsub
@@ -0,0 +1,17 @@
#!/usr/bin/env python

Import("env")

from platform_methods import run_in_subprocess
import platform_egl_builders

common_egl = [
"context_gl_egl.cpp",
"crash_handler_egl.cpp",
"os_egl.cpp",
]

prog = env.add_program("#bin/godot", ["godot_egl.cpp"] + common_egl)

if env["debug_symbols"] and env["separate_debug_symbols"]:
env.AddPostAction(prog, run_in_subprocess(platform_egl_builders.make_debug_egl))

0 comments on commit 54a2781

Please sign in to comment.