From c51f54749f88cb7cce3a5b653f0df2cad1f64fe8 Mon Sep 17 00:00:00 2001 From: George Marques Date: Sat, 3 Sep 2016 19:36:44 -0300 Subject: [PATCH] Fix drivers coding for WinRT - Add a proper function to retrieve IP addresses. - Solve issues with Windows FileAccess and DirAccess to use the same code for WinRT. - Add patches to the GLES2 rasterizer to workaround ANGLE issues. --- drivers/gles2/rasterizer_gles2.cpp | 10 +++++++++- drivers/gles2/shaders/material.glsl | 4 ++++ drivers/unix/ip_unix.cpp | 14 ++++++++++---- drivers/windows/dir_access_windows.cpp | 23 ----------------------- drivers/windows/file_access_windows.cpp | 10 ++++++++++ drivers/windows/semaphore_windows.cpp | 2 +- 6 files changed, 34 insertions(+), 29 deletions(-) diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index bf99535af7..d3cd35ad8d 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -10193,6 +10193,11 @@ void RasterizerGLES2::init() { shadow = NULL; shadow_pass = 0; +#ifdef ANGLE_ENABLED + // Fix for ANGLE + material_shader.set_conditional(MaterialShaderGLES2::DISABLE_FRONT_FACING, true); +#endif + framebuffer.fbo = 0; framebuffer.width = 0; framebuffer.height = 0; @@ -10271,9 +10276,12 @@ void RasterizerGLES2::init() { s3tc_supported = extensions.has("GL_EXT_texture_compression_dxt1") || extensions.has("GL_EXT_texture_compression_s3tc") || extensions.has("WEBGL_compressed_texture_s3tc"); use_half_float = extensions.has("GL_OES_vertex_half_float"); atitc_supported = extensions.has("GL_AMD_compressed_ATC_texture"); - srgb_supported = extensions.has("GL_EXT_sRGB"); +#ifndef ANGLE_ENABLED s3tc_srgb_supported = s3tc_supported && extensions.has("GL_EXT_texture_compression_s3tc"); +#else + s3tc_srgb_supported = s3tc_supported; +#endif latc_supported = extensions.has("GL_EXT_texture_compression_latc"); anisotropic_level = 1.0; use_anisotropic_filter = extensions.has("GL_EXT_texture_filter_anisotropic"); diff --git a/drivers/gles2/shaders/material.glsl b/drivers/gles2/shaders/material.glsl index 763347efc5..e5be25757d 100644 --- a/drivers/gles2/shaders/material.glsl +++ b/drivers/gles2/shaders/material.glsl @@ -811,7 +811,11 @@ void main() { float specular_exp=1.0; float glow=0.0; float shade_param=0.0; +#ifdef DISABLE_FRONT_FACING + float side=float(1)*2.0-1.0; +#else float side=float(gl_FrontFacing)*2.0-1.0; +#endif #if defined(ENABLE_TANGENT_INTERP) vec3 binormal = normalize(binormal_interp)*side; vec3 tangent = normalize(tangent_interp)*side; diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp index 8d46495e15..feb1809fca 100644 --- a/drivers/unix/ip_unix.cpp +++ b/drivers/unix/ip_unix.cpp @@ -127,6 +127,15 @@ void IP_Unix::get_local_addresses(List *r_addresses) const { using namespace Windows::Networking; using namespace Windows::Networking::Connectivity; + auto hostnames = NetworkInformation::GetHostNames(); + + for (int i = 0; i < hostnames->Size; i++) { + + if (hostnames->GetAt(i)->Type == HostNameType::Ipv4 && hostnames->GetAt(i)->IPInformation != nullptr) { + + r_addresses->push_back(IP_Address(String(hostnames->GetAt(i)->CanonicalName->Data()))); + } + } auto hostnames = NetworkInformation::GetHostNames(); @@ -148,10 +157,7 @@ void IP_Unix::get_local_addresses(List *r_addresses) const { while (true) { addrs = (IP_ADAPTER_ADDRESSES *)memalloc(buf_size); - int err = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_SKIP_ANYCAST | - GAA_FLAG_SKIP_MULTICAST | - GAA_FLAG_SKIP_DNS_SERVER | - GAA_FLAG_SKIP_FRIENDLY_NAME, + int err = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_FRIENDLY_NAME, NULL, addrs, &buf_size); if (err == NO_ERROR) { break; diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp index 070e599067..e590111d4a 100644 --- a/drivers/windows/dir_access_windows.cpp +++ b/drivers/windows/dir_access_windows.cpp @@ -38,12 +38,6 @@ #include #include -#ifdef WINRT_ENABLED -#include -#include -#include -#endif - /* [03:57] yessopie, so i dont havemak to rely on unicows @@ -130,14 +124,6 @@ Error DirAccessWindows::change_dir(String p_dir) { GLOBAL_LOCK_FUNCTION -#ifdef WINRT_ENABLED - - p_dir = fix_path(p_dir); - current_dir = normalize_path(p_dir); - - return OK; -#else - p_dir = fix_path(p_dir); wchar_t real_current_dir_name[2048]; @@ -170,19 +156,12 @@ Error DirAccessWindows::change_dir(String p_dir) { //} return worked ? OK : ERR_INVALID_PARAMETER; -#endif } Error DirAccessWindows::make_dir(String p_dir) { GLOBAL_LOCK_FUNCTION -#ifdef WINRT_ENABLED - - return ERR_CANT_CREATE; - -#else - if (p_dir.is_rel_path()) p_dir = get_current_dir().plus_file(p_dir); @@ -207,8 +186,6 @@ Error DirAccessWindows::make_dir(String p_dir) { }; return ERR_CANT_CREATE; - -#endif } String DirAccessWindows::get_current_dir() { diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp index 64e73cd2b3..42537ad1f5 100644 --- a/drivers/windows/file_access_windows.cpp +++ b/drivers/windows/file_access_windows.cpp @@ -115,7 +115,16 @@ void FileAccessWindows::close() { //int rename_error = _wrename((save_path+".tmp").c_str(),save_path.c_str()); bool rename_error; + +#ifdef WINRT_ENABLED + // WinRT has no PathFileExists, so we check attributes instead + DWORD fileAttr; + + fileAttr = GetFileAttributesW(save_path.c_str()); + if (INVALID_FILE_ATTRIBUTES == fileAttr) { +#else if (!PathFileExistsW(save_path.c_str())) { +#endif //creating new file rename_error = _wrename((save_path + ".tmp").c_str(), save_path.c_str()) != 0; } else { @@ -130,6 +139,7 @@ void FileAccessWindows::close() { ERR_FAIL_COND(rename_error); } } + bool FileAccessWindows::is_open() const { return (f != NULL); diff --git a/drivers/windows/semaphore_windows.cpp b/drivers/windows/semaphore_windows.cpp index 755481b972..acf18be7ee 100644 --- a/drivers/windows/semaphore_windows.cpp +++ b/drivers/windows/semaphore_windows.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "semaphore_windows.h" -#if defined(WINDOWS_ENABLED) && !defined(WINRT_ENABLED) +#if defined(WINDOWS_ENABLED) #include "os/memory.h"