This commit is contained in:
Tyler Bezera 2020-02-21 19:56:36 -08:00
commit 3a3bb46c8c
49 changed files with 9170 additions and 6161 deletions

View file

@ -42,8 +42,8 @@
.PHONY: all clean install uninstall
# Define required raylib variables
RAYLIB_VERSION = 2.5.0
RAYLIB_API_VERSION = 251
RAYLIB_VERSION = 3.0.0
RAYLIB_API_VERSION = 300
# See below for alternatives.
RAYLIB_PATH = ..
@ -148,8 +148,8 @@ endif
ifeq ($(PLATFORM),PLATFORM_WEB)
# Emscripten required variables
EMSDK_PATH ?= C:/emsdk
EMSCRIPTEN_PATH ?= $(EMSDK_PATH)/fastcomp/emscripten
CLANG_PATH = $(EMSDK_PATH)/fastcomp/bin
EMSCRIPTEN_PATH ?= $(EMSDK_PATH)/upstream/emscripten
CLANG_PATH = $(EMSDK_PATH)/upstream/bin
PYTHON_PATH = $(EMSDK_PATH)/python/2.7.13.1_64bit/python-2.7.13.amd64
NODE_PATH = $(EMSDK_PATH)/node/12.9.1_64bit/bin
export PATH = $(EMSDK_PATH);$(EMSCRIPTEN_PATH);$(CLANG_PATH);$(NODE_PATH);$(PYTHON_PATH);C:\raylib\MinGW\bin:$$(PATH)
@ -571,10 +571,11 @@ raudio.o : raudio.c raylib.h
# Compile raygui module
# NOTE: raygui header should be distributed with raylib.h
raygui.o : raygui.c raygui.h
@echo #define RAYGUI_IMPLEMENTATION > raygui.c
@echo #include "$(RAYLIB_MODULE_RAYGUI_PATH)/raygui.h" > raygui.c
raygui.o : raygui.c raygui.h gui_textbox_extended.h ricons.h
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -DRAYGUI_IMPLEMENTATION
raygui.c:
echo '#define RAYGUI_IMPLEMENTATION' > raygui.c
echo '#include "$(RAYLIB_MODULE_RAYGUI_PATH)/raygui.h"' >> raygui.c
# Compile physac module
# NOTE: physac header should be distributed with raylib.h

View file

@ -49,7 +49,7 @@
// Use busy wait loop for timing sync, if not defined, a high-resolution timer is setup and used
//#define SUPPORT_BUSY_WAIT_LOOP 1
// Use a half-busy wait loop, in this case frame sleeps for some time and runs a busy-wait-loop at the end
//#define SUPPORT_HALFBUSY_WAIT_LOOP
#define SUPPORT_HALFBUSY_WAIT_LOOP
// Wait for events passively (sleeping while no events) instead of polling them actively every frame
//#define SUPPORT_EVENTS_WAITING 1
// Allow automatic screen capture of current screen pressing F12, defined in KeyCallback()
@ -67,7 +67,6 @@
// Support VR simulation functionality (stereo rendering)
#define SUPPORT_VR_SIMULATOR 1
//------------------------------------------------------------------------------------
// Module: shapes - Configuration Flags
//------------------------------------------------------------------------------------
@ -94,7 +93,6 @@
//#define SUPPORT_FILEFORMAT_ASTC 1
//#define SUPPORT_FILEFORMAT_PKM 1
//#define SUPPORT_FILEFORMAT_PVR 1
// Support image export functionality (.png, .bmp, .tga, .jpg)
#define SUPPORT_IMAGE_EXPORT 1
// Support multiple image editing functions to scale, adjust colors, flip, draw on images, crop...
@ -103,7 +101,6 @@
// Support procedural image generation functionality (gradient, spot, perlin-noise, cellular)
#define SUPPORT_IMAGE_GENERATION 1
//------------------------------------------------------------------------------------
// Module: text - Configuration Flags
//------------------------------------------------------------------------------------
@ -114,7 +111,6 @@
#define SUPPORT_FILEFORMAT_FNT 1
#define SUPPORT_FILEFORMAT_TTF 1
//------------------------------------------------------------------------------------
// Module: models - Configuration Flags
//------------------------------------------------------------------------------------
@ -127,7 +123,6 @@
// NOTE: Some generated meshes DO NOT include generated texture coordinates
#define SUPPORT_MESH_GENERATION 1
//------------------------------------------------------------------------------------
// Module: audio - Configuration Flags
//------------------------------------------------------------------------------------
@ -139,7 +134,6 @@
#define SUPPORT_FILEFORMAT_FLAC 1
#define SUPPORT_FILEFORMAT_MP3 1
//------------------------------------------------------------------------------------
// Module: utils - Configuration Flags
//------------------------------------------------------------------------------------
@ -148,5 +142,4 @@
#define SUPPORT_TRACELOG 1
//#define SUPPORT_TRACELOG_DEBUG 1
#endif //defined(RAYLIB_CMAKE)

View file

@ -151,13 +151,13 @@
#define SUPPORT_HIGH_DPI // Force HighDPI support on macOS
#endif
#include <stdlib.h> // Required for: srand(), rand(), atexit()
#include <stdio.h> // Required for: FILE, fopen(), fseek(), fread(), fwrite(), fclose() [Used in StorageSaveValue()/StorageLoadValue()]
#include <string.h> // Required for: strrchr(), strcmp(), strlen()
#include <time.h> // Required for: time() - Android/RPI hi-res timer (NOTE: Linux only!)
#include <math.h> // Required for: tan() [Used in BeginMode3D()]
#include <stdlib.h> // Required for: srand(), rand(), atexit()
#include <stdio.h> // Required for: FILE, fopen(), fseek(), fread(), fwrite(), fclose() [Used in StorageSaveValue()/StorageLoadValue()]
#include <string.h> // Required for: strrchr(), strcmp(), strlen()
#include <time.h> // Required for: time() [Used in InitTimer()]
#include <math.h> // Required for: tan() [Used in BeginMode3D()]
#include <sys/stat.h> // Required for stat() [Used in GetLastWriteTime()]
#include <sys/stat.h> // Required for: stat() [Used in GetFileModTime()]
#if (defined(PLATFORM_DESKTOP) || defined(PLATFORM_UWP)) && defined(_WIN32) && (defined(_MSC_VER) || defined(__TINYC__))
#include "external/dirent.h" // Required for: DIR, opendir(), closedir() [Used in GetDirectoryFiles()]
@ -171,7 +171,7 @@
#define CHDIR _chdir
#include <io.h> // Required for _access() [Used in FileExists()]
#else
#include "unistd.h" // Required for: getch(), chdir() (POSIX), access()
#include <unistd.h> // Required for: getch(), chdir() (POSIX), access()
#define GETCWD getcwd
#define CHDIR chdir
#endif
@ -209,8 +209,7 @@
#endif
#if defined(__linux__)
#include <linux/limits.h> // for NAME_MAX and PATH_MAX defines
#define MAX_FILEPATH_LENGTH PATH_MAX // Use Linux define (4096)
#define MAX_FILEPATH_LENGTH 4096 // Use Linux PATH_MAX value
#else
#define MAX_FILEPATH_LENGTH 512 // Use common value
#endif
@ -228,7 +227,7 @@
#include <fcntl.h> // POSIX file control definitions - open(), creat(), fcntl()
#include <unistd.h> // POSIX standard function definitions - read(), close(), STDIN_FILENO
#include <termios.h> // POSIX terminal control definitions - tcgetattr(), tcsetattr()
#include <pthread.h> // POSIX threads management (mouse input)
#include <pthread.h> // POSIX threads management (inputs reading)
#include <dirent.h> // POSIX directory browsing
#include <sys/ioctl.h> // UNIX System call for device-specific input/output operations - ioctl()
@ -317,7 +316,7 @@ typedef struct{
typedef struct { int x; int y; } Point;
typedef struct { int width; int height; } Size;
typedef struct { unsigned int width; unsigned int height; } Size;
#if defined(PLATFORM_UWP)
extern EGLNativeWindowType handle; // Native window handler for UWP (external, defined in UWP App)
@ -683,7 +682,9 @@ void InitWindow(int width, int height, const char *title)
// Load default font
// NOTE: External functions (defined in module: text)
LoadFontDefault();
SetShapesTexture(GetFontDefault().texture, GetFontDefault().recs[95]);
Rectangle rec = GetFontDefault().recs[95];
// NOTE: We setup a 1px padding on char rectangle to avoid pixel bleeding on MSAA filtering
SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 1, rec.y + 1, rec.width - 2, rec.height - 2 });
#endif
#if defined(PLATFORM_DESKTOP) && defined(SUPPORT_HIGH_DPI)
// Set default font texture filter for HighDPI (blurry)
@ -1610,9 +1611,30 @@ void SetTargetFPS(int fps)
}
// Returns current FPS
// NOTE: We calculate an average framerate
int GetFPS(void)
{
return (int)roundf(1.0f/GetFrameTime());
#define FPS_CAPTURE_FRAMES_COUNT 30 // 30 captures
#define FPS_AVERAGE_TIME_SECONDS 0.5f // 500 millisecondes
#define FPS_STEP (FPS_AVERAGE_TIME_SECONDS/FPS_CAPTURE_FRAMES_COUNT)
static int index = 0;
static float history[FPS_CAPTURE_FRAMES_COUNT] = { 0 };
static float average = 0, last = 0;
float fpsFrame = GetFrameTime();
if (fpsFrame == 0) return 0;
if ((GetTime() - last) > FPS_STEP)
{
last = GetTime();
index = (index + 1)%FPS_CAPTURE_FRAMES_COUNT;
average -= history[index];
history[index] = fpsFrame/FPS_CAPTURE_FRAMES_COUNT;
average += history[index];
}
return (int)roundf(1.0f/average);
}
// Returns time in seconds for last frame drawn
@ -1965,17 +1987,22 @@ const char *GetDirectoryPath(const char *filePath)
static char dirPath[MAX_FILEPATH_LENGTH];
memset(dirPath, 0, MAX_FILEPATH_LENGTH);
// For security, we set starting path to current directory,
// obtained path will be concated to this
//dirPath[0] = '.';
//dirPath[1] = '/';
// In case provided path does not contains a root drive letter (C:\, D:\),
// we add the current directory path to dirPath
if (filePath[1] != ':')
{
// For security, we set starting path to current directory,
// obtained path will be concated to this
dirPath[0] = '.';
dirPath[1] = '/';
}
lastSlash = strprbrk(filePath, "\\/");
if (lastSlash)
{
// NOTE: Be careful, strncpy() is not safe, it does not care about '\0'
strncpy(dirPath, filePath, strlen(filePath) - (strlen(lastSlash) - 1));
dirPath[strlen(filePath) - strlen(lastSlash)] = '\0'; // Add '\0' manually
strncpy(dirPath + ((filePath[1] != ':')? 2 : 0), filePath, strlen(filePath) - (strlen(lastSlash) - 1));
dirPath[strlen(filePath) - strlen(lastSlash) + ((filePath[1] != ':')? 2 : 0)] = '\0'; // Add '\0' manually
}
return dirPath;
@ -2233,17 +2260,21 @@ void OpenURL(const char *url)
}
else
{
#if defined(PLATFORM_DESKTOP)
char *cmd = (char *)RL_CALLOC(strlen(url) + 10, sizeof(char));
#if defined(_WIN32)
#if defined(_WIN32)
sprintf(cmd, "explorer %s", url);
#elif defined(__linux__)
#elif defined(__linux__)
sprintf(cmd, "xdg-open '%s'", url); // Alternatives: firefox, x-www-browser
#elif defined(__APPLE__)
#elif defined(__APPLE__)
sprintf(cmd, "open '%s'", url);
#endif
#endif
system(cmd);
RL_FREE(cmd);
#endif
#if defined(PLATFORM_WEB)
emscripten_run_script(TextFormat("window.open('%s', '_blank')", url));
#endif
}
}
@ -2452,8 +2483,8 @@ bool IsMouseButtonPressed(int button)
if (IsGestureDetected(GESTURE_TAP)) pressed = true;
#else
// NOTE: On PLATFORM_DESKTOP and PLATFORM_WEB IsMouseButtonPressed() is equivalent to GESTURE_TAP
if (((CORE.Input.Mouse.currentButtonState[button] != CORE.Input.Mouse.previousButtonState[button]) &&
(CORE.Input.Mouse.currentButtonState[button] == 1)) || IsGestureDetected(GESTURE_TAP)) pressed = true;
if ((CORE.Input.Mouse.currentButtonState[button] != CORE.Input.Mouse.previousButtonState[button]) &&
(GetMouseButtonStatus(button) == 1)) pressed = true;
#endif
return pressed;
@ -2468,7 +2499,8 @@ bool IsMouseButtonDown(int button)
if (IsGestureDetected(GESTURE_HOLD)) down = true;
#else
// NOTE: On PLATFORM_DESKTOP and PLATFORM_WEB IsMouseButtonDown() is equivalent to GESTURE_HOLD or GESTURE_DRAG
if ((GetMouseButtonStatus(button) == 1) || IsGestureDetected(GESTURE_HOLD) || IsGestureDetected(GESTURE_DRAG)) down = true;
if (GetMouseButtonStatus(button) == 1) down = true;
// || IsGestureDetected(GESTURE_HOLD) || IsGestureDetected(GESTURE_DRAG)) down = true;
#endif
return down;
@ -2481,7 +2513,7 @@ bool IsMouseButtonReleased(int button)
#if !defined(PLATFORM_ANDROID)
if ((CORE.Input.Mouse.currentButtonState[button] != CORE.Input.Mouse.previousButtonState[button]) &&
(CORE.Input.Mouse.currentButtonState[button] == 0)) released = true;
(GetMouseButtonStatus(button) == 0)) released = true;
#endif
return released;
@ -3177,12 +3209,12 @@ static bool InitGraphicsDevice(int width, int height)
dispmanElement = vc_dispmanx_element_add(dispmanUpdate, dispmanDisplay, 0/*layer*/, &dstRect, 0/*src*/,
&srcRect, DISPMANX_PROTECTION_NONE, &alpha, 0/*clamp*/, DISPMANX_NO_ROTATE);
window.element = dispmanElement;
window.width = CORE.Window.render.width;
window.height = CORE.Window.render.height;
CORE.Window.handle.element = dispmanElement;
CORE.Window.handle.width = CORE.Window.render.width;
CORE.Window.handle.height = CORE.Window.render.height;
vc_dispmanx_update_submit_sync(dispmanUpdate);
CORE.Window.surface = eglCreateWindowSurface(CORE.Window.device, CORE.Window.config, &window, NULL);
CORE.Window.surface = eglCreateWindowSurface(CORE.Window.device, CORE.Window.config, &CORE.Window.handle, NULL);
//---------------------------------------------------------------------------------
#endif // PLATFORM_RPI
@ -3556,7 +3588,7 @@ static void PollInputEvents(void)
for (int i = 0; i < 3; i++)
{
CORE.Input.Mouse.previousButtonState[i] = CORE.Input.Mouse.currentButtonState[i];
CORE.Input.Mouse.currentButtonState[i] = currentButtonStateEvdev[i];
CORE.Input.Mouse.currentButtonState[i] = CORE.Input.Mouse.currentButtonStateEvdev[i];
}
#endif
@ -3970,7 +4002,7 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int
#if defined(SUPPORT_GESTURES_SYSTEM) && defined(SUPPORT_MOUSE_GESTURES)
// Process mouse events as touches to be able to use mouse-gestures
GestureEvent gestureEvent;
GestureEvent gestureEvent = { 0 };
// Register touch actions
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) gestureEvent.touchAction = TOUCH_DOWN;
@ -4001,7 +4033,7 @@ static void MouseCursorPosCallback(GLFWwindow *window, double x, double y)
{
#if defined(SUPPORT_GESTURES_SYSTEM) && defined(SUPPORT_MOUSE_GESTURES)
// Process mouse events as touches to be able to use mouse-gestures
GestureEvent gestureEvent;
GestureEvent gestureEvent = { 0 };
gestureEvent.touchAction = TOUCH_MOVE;
@ -4132,7 +4164,9 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd)
// Load default font
// NOTE: External function (defined in module: text)
LoadFontDefault();
SetShapesTexture(GetFontDefault().texture, GetFontDefault().recs[95]);
Rectangle rec = GetFontDefault().recs[95];
// NOTE: We setup a 1px padding on char rectangle to avoid pixel bleeding on MSAA filtering
SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 1, rec.y + 1, rec.width - 2, rec.height - 2 });
#endif
// TODO: GPU assets reload in case of lost focus (lost context)
@ -4269,7 +4303,7 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
#if defined(SUPPORT_GESTURES_SYSTEM)
GestureEvent gestureEvent;
GestureEvent gestureEvent = { 0 };
// Register touch actions
if (flags == AMOTION_EVENT_ACTION_DOWN) gestureEvent.touchAction = TOUCH_DOWN;
@ -4384,7 +4418,7 @@ static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent
static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
{
#if defined(SUPPORT_GESTURES_SYSTEM)
GestureEvent gestureEvent;
GestureEvent gestureEvent = { 0 };
// Register touch actions
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) gestureEvent.touchAction = TOUCH_DOWN;
@ -4652,11 +4686,13 @@ static void InitEvdevInput(void)
CORE.Input.Touch.position[i].x = -1;
CORE.Input.Touch.position[i].y = -1;
}
// Reset keypress buffer
CORE.Input.Keyboard.lastKeyPressed.Head = 0;
CORE.Input.Keyboard.lastKeyPressed.Tail = 0;
// Reset keyboard key state
for (int i = 0; i < 512; i++) CORE.Input.Keyboard.currentKeyStateEvdev[i] = 0;
for (int i = 0; i < 512; i++) CORE.Input.Keyboard.currentKeyState[i] = 0;
// Open the linux directory of "/dev/input"
directory = opendir(DEFAULT_EVDEV_PATH);
@ -4990,7 +5026,7 @@ static void *EventThread(void *arg)
// Mouse button parsing
if ((event.code == BTN_TOUCH) || (event.code == BTN_LEFT))
{
currentButtonStateEvdev[MOUSE_LEFT_BUTTON] = event.value;
CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_LEFT_BUTTON] = event.value;
#if defined(SUPPORT_GESTURES_SYSTEM)
if (event.value > 0) touchAction = TOUCH_DOWN;
@ -4999,9 +5035,8 @@ static void *EventThread(void *arg)
#endif
}
if (event.code == BTN_RIGHT) currentButtonStateEvdev[MOUSE_RIGHT_BUTTON] = event.value;
if (event.code == BTN_MIDDLE) currentButtonStateEvdev[MOUSE_MIDDLE_BUTTON] = event.value;
if (event.code == BTN_RIGHT) CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_RIGHT_BUTTON] = event.value;
if (event.code == BTN_MIDDLE) CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_MIDDLE_BUTTON] = event.value;
// Keyboard button parsing
if ((event.code >= 1) && (event.code <= 255)) //Keyboard keys appear for codes 1 to 255

406
src/external/cgltf.h vendored
View file

@ -1,7 +1,7 @@
/**
* cgltf - a single-file glTF 2.0 parser written in C99.
*
* Version: 1.4
* Version: 1.5
*
* Website: https://github.com/jkuhlmann/cgltf
*
@ -24,8 +24,8 @@
*
* `cgltf_options` is the struct passed to `cgltf_parse()` to control
* parts of the parsing process. You can use it to force the file type
* and provide memory allocation callbacks. Should be zero-initialized
* to trigger default behavior.
* and provide memory allocation as well as file operation callbacks.
* Should be zero-initialized to trigger default behavior.
*
* `cgltf_data` is the struct allocated and filled by `cgltf_parse()`.
* It generally mirrors the glTF format as described by the spec (see
@ -72,6 +72,11 @@
* size is the number of floats in the output buffer, which should be in the range [1, 16]. Returns
* false if the passed-in element_size is too small, or if the accessor is sparse.
*
* `cgltf_accessor_read_uint` is similar to its floating-point counterpart, but limited to reading
* vector types and does not support matrix types. The passed-in element size is the number of uints
* in the output buffer, which should be in the range [1, 4]. Returns false if the passed-in
* element_size is too small, or if the accessor is sparse.
*
* `cgltf_accessor_read_index` is similar to its floating-point counterpart, but it returns size_t
* and only works with single-component data types.
*
@ -96,6 +101,7 @@ extern "C" {
typedef size_t cgltf_size;
typedef float cgltf_float;
typedef int cgltf_int;
typedef unsigned int cgltf_uint;
typedef int cgltf_bool;
typedef enum cgltf_file_type
@ -105,15 +111,6 @@ typedef enum cgltf_file_type
cgltf_file_type_glb,
} cgltf_file_type;
typedef struct cgltf_options
{
cgltf_file_type type; /* invalid == auto detect */
cgltf_size json_token_count; /* 0 == auto */
void* (*memory_alloc)(void* user, cgltf_size size);
void (*memory_free) (void* user, void* ptr);
void* memory_user_data;
} cgltf_options;
typedef enum cgltf_result
{
cgltf_result_success,
@ -128,6 +125,28 @@ typedef enum cgltf_result
cgltf_result_legacy_gltf,
} cgltf_result;
typedef struct cgltf_memory_options
{
void* (*alloc)(void* user, cgltf_size size);
void (*free) (void* user, void* ptr);
void* user_data;
} cgltf_memory_options;
typedef struct cgltf_file_options
{
cgltf_result(*read)(const struct cgltf_memory_options* memory_options, const struct cgltf_file_options* file_options, const char* path, cgltf_size* size, void** data);
void (*release)(const struct cgltf_memory_options* memory_options, const struct cgltf_file_options* file_options, void* data);
void* user_data;
} cgltf_file_options;
typedef struct cgltf_options
{
cgltf_file_type type; /* invalid == auto detect */
cgltf_size json_token_count; /* 0 == auto */
cgltf_memory_options memory;
cgltf_file_options file;
} cgltf_options;
typedef enum cgltf_buffer_view_type
{
cgltf_buffer_view_type_invalid,
@ -560,8 +579,8 @@ typedef struct cgltf_data
const void* bin;
cgltf_size bin_size;
void (*memory_free) (void* user, void* ptr);
void* memory_user_data;
cgltf_memory_options memory;
cgltf_file_options file;
} cgltf_data;
cgltf_result cgltf_parse(
@ -591,6 +610,7 @@ void cgltf_node_transform_local(const cgltf_node* node, cgltf_float* out_matrix)
void cgltf_node_transform_world(const cgltf_node* node, cgltf_float* out_matrix);
cgltf_bool cgltf_accessor_read_float(const cgltf_accessor* accessor, cgltf_size index, cgltf_float* out, cgltf_size element_size);
cgltf_bool cgltf_accessor_read_uint(const cgltf_accessor* accessor, cgltf_size index, cgltf_uint* out, cgltf_size element_size);
cgltf_size cgltf_accessor_read_index(const cgltf_accessor* accessor, cgltf_size index);
cgltf_size cgltf_num_components(cgltf_type type);
@ -713,7 +733,7 @@ static void* cgltf_calloc(cgltf_options* options, size_t element_size, cgltf_siz
{
return NULL;
}
void* result = options->memory_alloc(options->memory_user_data, element_size * count);
void* result = options->memory.alloc(options->memory.user_data, element_size * count);
if (!result)
{
return NULL;
@ -722,6 +742,71 @@ static void* cgltf_calloc(cgltf_options* options, size_t element_size, cgltf_siz
return result;
}
static cgltf_result cgltf_default_file_read(const struct cgltf_memory_options* memory_options, const struct cgltf_file_options* file_options, const char* path, cgltf_size* size, void** data)
{
(void)file_options;
void* (*memory_alloc)(void*, cgltf_size) = memory_options->alloc ? memory_options->alloc : &cgltf_default_alloc;
void (*memory_free)(void*, void*) = memory_options->free ? memory_options->free : &cgltf_default_free;
FILE* file = fopen(path, "rb");
if (!file)
{
return cgltf_result_file_not_found;
}
cgltf_size file_size = size ? *size : 0;
if (file_size == 0)
{
fseek(file, 0, SEEK_END);
long length = ftell(file);
if (length < 0)
{
fclose(file);
return cgltf_result_io_error;
}
fseek(file, 0, SEEK_SET);
file_size = (cgltf_size)length;
}
char* file_data = (char*)memory_alloc(memory_options->user_data, file_size);
if (!file_data)
{
fclose(file);
return cgltf_result_out_of_memory;
}
cgltf_size read_size = fread(file_data, 1, file_size, file);
fclose(file);
if (read_size != file_size)
{
memory_free(memory_options->user_data, file_data);
return cgltf_result_io_error;
}
if (size)
{
*size = file_size;
}
if (data)
{
*data = file_data;
}
return cgltf_result_success;
}
static void cgltf_default_file_release(const struct cgltf_memory_options* memory_options, const struct cgltf_file_options* file_options, void* data)
{
(void)file_options;
void (*memfree)(void*, void*) = memory_options->free ? memory_options->free : &cgltf_default_free;
memfree(memory_options->user_data, data);
}
static cgltf_result cgltf_parse_json(cgltf_options* options, const uint8_t* json_chunk, cgltf_size size, cgltf_data** out_data);
cgltf_result cgltf_parse(const cgltf_options* options, const void* data, cgltf_size size, cgltf_data** out_data)
@ -737,13 +822,13 @@ cgltf_result cgltf_parse(const cgltf_options* options, const void* data, cgltf_s
}
cgltf_options fixed_options = *options;
if (fixed_options.memory_alloc == NULL)
if (fixed_options.memory.alloc == NULL)
{
fixed_options.memory_alloc = &cgltf_default_alloc;
fixed_options.memory.alloc = &cgltf_default_alloc;
}
if (fixed_options.memory_free == NULL)
if (fixed_options.memory.free == NULL)
{
fixed_options.memory_free = &cgltf_default_free;
fixed_options.memory.free = &cgltf_default_free;
}
uint32_t tmp;
@ -863,49 +948,23 @@ cgltf_result cgltf_parse_file(const cgltf_options* options, const char* path, cg
return cgltf_result_invalid_options;
}
void* (*memory_alloc)(void*, cgltf_size) = options->memory_alloc ? options->memory_alloc : &cgltf_default_alloc;
void (*memory_free)(void*, void*) = options->memory_free ? options->memory_free : &cgltf_default_free;
void* (*memory_alloc)(void*, cgltf_size) = options->memory.alloc ? options->memory.alloc : &cgltf_default_alloc;
void (*memory_free)(void*, void*) = options->memory.free ? options->memory.free : &cgltf_default_free;
cgltf_result (*file_read)(const struct cgltf_memory_options*, const struct cgltf_file_options*, const char*, cgltf_size*, void**) = options->file.read ? options->file.read : &cgltf_default_file_read;
FILE* file = fopen(path, "rb");
if (!file)
void* file_data = NULL;
cgltf_size file_size = 0;
cgltf_result result = file_read(&options->memory, &options->file, path, &file_size, &file_data);
if (result != cgltf_result_success)
{
return cgltf_result_file_not_found;
return result;
}
fseek(file, 0, SEEK_END);
long length = ftell(file);
if (length < 0)
{
fclose(file);
return cgltf_result_io_error;
}
fseek(file, 0, SEEK_SET);
char* file_data = (char*)memory_alloc(options->memory_user_data, length);
if (!file_data)
{
fclose(file);
return cgltf_result_out_of_memory;
}
cgltf_size file_size = (cgltf_size)length;
cgltf_size read_size = fread(file_data, 1, file_size, file);
fclose(file);
if (read_size != file_size)
{
memory_free(options->memory_user_data, file_data);
return cgltf_result_io_error;
}
cgltf_result result = cgltf_parse(options, file_data, file_size, out_data);
result = cgltf_parse(options, file_data, file_size, out_data);
if (result != cgltf_result_success)
{
memory_free(options->memory_user_data, file_data);
memory_free(options->memory.user_data, file_data);
return result;
}
@ -935,10 +994,11 @@ static void cgltf_combine_paths(char* path, const char* base, const char* uri)
static cgltf_result cgltf_load_buffer_file(const cgltf_options* options, cgltf_size size, const char* uri, const char* gltf_path, void** out_data)
{
void* (*memory_alloc)(void*, cgltf_size) = options->memory_alloc ? options->memory_alloc : &cgltf_default_alloc;
void (*memory_free)(void*, void*) = options->memory_free ? options->memory_free : &cgltf_default_free;
void* (*memory_alloc)(void*, cgltf_size) = options->memory.alloc ? options->memory.alloc : &cgltf_default_alloc;
void (*memory_free)(void*, void*) = options->memory.free ? options->memory.free : &cgltf_default_free;
cgltf_result (*file_read)(const struct cgltf_memory_options*, const struct cgltf_file_options*, const char*, cgltf_size*, void**) = options->file.read ? options->file.read : &cgltf_default_file_read;
char* path = (char*)memory_alloc(options->memory_user_data, strlen(uri) + strlen(gltf_path) + 1);
char* path = (char*)memory_alloc(options->memory.user_data, strlen(uri) + strlen(gltf_path) + 1);
if (!path)
{
return cgltf_result_out_of_memory;
@ -946,30 +1006,11 @@ static cgltf_result cgltf_load_buffer_file(const cgltf_options* options, cgltf_s
cgltf_combine_paths(path, gltf_path, uri);
FILE* file = fopen(path, "rb");
memory_free(options->memory_user_data, path);
if (!file)
void* file_data = NULL;
cgltf_result result = file_read(&options->memory, &options->file, path, &size, &file_data);
if (result != cgltf_result_success)
{
return cgltf_result_file_not_found;
}
char* file_data = (char*)memory_alloc(options->memory_user_data, size);
if (!file_data)
{
fclose(file);
return cgltf_result_out_of_memory;
}
cgltf_size read_size = fread(file_data, 1, size, file);
fclose(file);
if (read_size != size)
{
memory_free(options->memory_user_data, file_data);
return cgltf_result_io_error;
return result;
}
*out_data = file_data;
@ -979,10 +1020,10 @@ static cgltf_result cgltf_load_buffer_file(const cgltf_options* options, cgltf_s
cgltf_result cgltf_load_buffer_base64(const cgltf_options* options, cgltf_size size, const char* base64, void** out_data)
{
void* (*memory_alloc)(void*, cgltf_size) = options->memory_alloc ? options->memory_alloc : &cgltf_default_alloc;
void (*memory_free)(void*, void*) = options->memory_free ? options->memory_free : &cgltf_default_free;
void* (*memory_alloc)(void*, cgltf_size) = options->memory.alloc ? options->memory.alloc : &cgltf_default_alloc;
void (*memory_free)(void*, void*) = options->memory.free ? options->memory.free : &cgltf_default_free;
unsigned char* data = (unsigned char*)memory_alloc(options->memory_user_data, size);
unsigned char* data = (unsigned char*)memory_alloc(options->memory.user_data, size);
if (!data)
{
return cgltf_result_out_of_memory;
@ -1007,7 +1048,7 @@ cgltf_result cgltf_load_buffer_base64(const cgltf_options* options, cgltf_size s
if (index < 0)
{
memory_free(options->memory_user_data, data);
memory_free(options->memory.user_data, data);
return cgltf_result_io_error;
}
@ -1372,155 +1413,157 @@ void cgltf_free(cgltf_data* data)
return;
}
data->memory_free(data->memory_user_data, data->asset.copyright);
data->memory_free(data->memory_user_data, data->asset.generator);
data->memory_free(data->memory_user_data, data->asset.version);
data->memory_free(data->memory_user_data, data->asset.min_version);
void (*file_release)(const struct cgltf_memory_options*, const struct cgltf_file_options*, void* data) = data->file.release ? data->file.release : cgltf_default_file_release;
data->memory_free(data->memory_user_data, data->accessors);
data->memory_free(data->memory_user_data, data->buffer_views);
data->memory.free(data->memory.user_data, data->asset.copyright);
data->memory.free(data->memory.user_data, data->asset.generator);
data->memory.free(data->memory.user_data, data->asset.version);
data->memory.free(data->memory.user_data, data->asset.min_version);
data->memory.free(data->memory.user_data, data->accessors);
data->memory.free(data->memory.user_data, data->buffer_views);
for (cgltf_size i = 0; i < data->buffers_count; ++i)
{
if (data->buffers[i].data != data->bin)
{
data->memory_free(data->memory_user_data, data->buffers[i].data);
file_release(&data->memory, &data->file, data->buffers[i].data);
}
data->memory_free(data->memory_user_data, data->buffers[i].uri);
data->memory.free(data->memory.user_data, data->buffers[i].uri);
}
data->memory_free(data->memory_user_data, data->buffers);
data->memory.free(data->memory.user_data, data->buffers);
for (cgltf_size i = 0; i < data->meshes_count; ++i)
{
data->memory_free(data->memory_user_data, data->meshes[i].name);
data->memory.free(data->memory.user_data, data->meshes[i].name);
for (cgltf_size j = 0; j < data->meshes[i].primitives_count; ++j)
{
for (cgltf_size k = 0; k < data->meshes[i].primitives[j].attributes_count; ++k)
{
data->memory_free(data->memory_user_data, data->meshes[i].primitives[j].attributes[k].name);
data->memory.free(data->memory.user_data, data->meshes[i].primitives[j].attributes[k].name);
}
data->memory_free(data->memory_user_data, data->meshes[i].primitives[j].attributes);
data->memory.free(data->memory.user_data, data->meshes[i].primitives[j].attributes);
for (cgltf_size k = 0; k < data->meshes[i].primitives[j].targets_count; ++k)
{
for (cgltf_size m = 0; m < data->meshes[i].primitives[j].targets[k].attributes_count; ++m)
{
data->memory_free(data->memory_user_data, data->meshes[i].primitives[j].targets[k].attributes[m].name);
data->memory.free(data->memory.user_data, data->meshes[i].primitives[j].targets[k].attributes[m].name);
}
data->memory_free(data->memory_user_data, data->meshes[i].primitives[j].targets[k].attributes);
data->memory.free(data->memory.user_data, data->meshes[i].primitives[j].targets[k].attributes);
}
data->memory_free(data->memory_user_data, data->meshes[i].primitives[j].targets);
data->memory.free(data->memory.user_data, data->meshes[i].primitives[j].targets);
}
data->memory_free(data->memory_user_data, data->meshes[i].primitives);
data->memory_free(data->memory_user_data, data->meshes[i].weights);
data->memory.free(data->memory.user_data, data->meshes[i].primitives);
data->memory.free(data->memory.user_data, data->meshes[i].weights);
for (cgltf_size j = 0; j < data->meshes[i].target_names_count; ++j)
{
data->memory_free(data->memory_user_data, data->meshes[i].target_names[j]);
data->memory.free(data->memory.user_data, data->meshes[i].target_names[j]);
}
data->memory_free(data->memory_user_data, data->meshes[i].target_names);
data->memory.free(data->memory.user_data, data->meshes[i].target_names);
}
data->memory_free(data->memory_user_data, data->meshes);
data->memory.free(data->memory.user_data, data->meshes);
for (cgltf_size i = 0; i < data->materials_count; ++i)
{
data->memory_free(data->memory_user_data, data->materials[i].name);
data->memory.free(data->memory.user_data, data->materials[i].name);
}
data->memory_free(data->memory_user_data, data->materials);
data->memory.free(data->memory.user_data, data->materials);
for (cgltf_size i = 0; i < data->images_count; ++i)
{
data->memory_free(data->memory_user_data, data->images[i].name);
data->memory_free(data->memory_user_data, data->images[i].uri);
data->memory_free(data->memory_user_data, data->images[i].mime_type);
data->memory.free(data->memory.user_data, data->images[i].name);
data->memory.free(data->memory.user_data, data->images[i].uri);
data->memory.free(data->memory.user_data, data->images[i].mime_type);
}
data->memory_free(data->memory_user_data, data->images);
data->memory.free(data->memory.user_data, data->images);
for (cgltf_size i = 0; i < data->textures_count; ++i)
{
data->memory_free(data->memory_user_data, data->textures[i].name);
data->memory.free(data->memory.user_data, data->textures[i].name);
}
data->memory_free(data->memory_user_data, data->textures);
data->memory.free(data->memory.user_data, data->textures);
data->memory_free(data->memory_user_data, data->samplers);
data->memory.free(data->memory.user_data, data->samplers);
for (cgltf_size i = 0; i < data->skins_count; ++i)
{
data->memory_free(data->memory_user_data, data->skins[i].name);
data->memory_free(data->memory_user_data, data->skins[i].joints);
data->memory.free(data->memory.user_data, data->skins[i].name);
data->memory.free(data->memory.user_data, data->skins[i].joints);
}
data->memory_free(data->memory_user_data, data->skins);
data->memory.free(data->memory.user_data, data->skins);
for (cgltf_size i = 0; i < data->cameras_count; ++i)
{
data->memory_free(data->memory_user_data, data->cameras[i].name);
data->memory.free(data->memory.user_data, data->cameras[i].name);
}
data->memory_free(data->memory_user_data, data->cameras);
data->memory.free(data->memory.user_data, data->cameras);
for (cgltf_size i = 0; i < data->lights_count; ++i)
{
data->memory_free(data->memory_user_data, data->lights[i].name);
data->memory.free(data->memory.user_data, data->lights[i].name);
}
data->memory_free(data->memory_user_data, data->lights);
data->memory.free(data->memory.user_data, data->lights);
for (cgltf_size i = 0; i < data->nodes_count; ++i)
{
data->memory_free(data->memory_user_data, data->nodes[i].name);
data->memory_free(data->memory_user_data, data->nodes[i].children);
data->memory_free(data->memory_user_data, data->nodes[i].weights);
data->memory.free(data->memory.user_data, data->nodes[i].name);
data->memory.free(data->memory.user_data, data->nodes[i].children);
data->memory.free(data->memory.user_data, data->nodes[i].weights);
}
data->memory_free(data->memory_user_data, data->nodes);
data->memory.free(data->memory.user_data, data->nodes);
for (cgltf_size i = 0; i < data->scenes_count; ++i)
{
data->memory_free(data->memory_user_data, data->scenes[i].name);
data->memory_free(data->memory_user_data, data->scenes[i].nodes);
data->memory.free(data->memory.user_data, data->scenes[i].name);
data->memory.free(data->memory.user_data, data->scenes[i].nodes);
}
data->memory_free(data->memory_user_data, data->scenes);
data->memory.free(data->memory.user_data, data->scenes);
for (cgltf_size i = 0; i < data->animations_count; ++i)
{
data->memory_free(data->memory_user_data, data->animations[i].name);
data->memory_free(data->memory_user_data, data->animations[i].samplers);
data->memory_free(data->memory_user_data, data->animations[i].channels);
data->memory.free(data->memory.user_data, data->animations[i].name);
data->memory.free(data->memory.user_data, data->animations[i].samplers);
data->memory.free(data->memory.user_data, data->animations[i].channels);
}
data->memory_free(data->memory_user_data, data->animations);
data->memory.free(data->memory.user_data, data->animations);
for (cgltf_size i = 0; i < data->extensions_used_count; ++i)
{
data->memory_free(data->memory_user_data, data->extensions_used[i]);
data->memory.free(data->memory.user_data, data->extensions_used[i]);
}
data->memory_free(data->memory_user_data, data->extensions_used);
data->memory.free(data->memory.user_data, data->extensions_used);
for (cgltf_size i = 0; i < data->extensions_required_count; ++i)
{
data->memory_free(data->memory_user_data, data->extensions_required[i]);
data->memory.free(data->memory.user_data, data->extensions_required[i]);
}
data->memory_free(data->memory_user_data, data->extensions_required);
data->memory.free(data->memory.user_data, data->extensions_required);
data->memory_free(data->memory_user_data, data->file_data);
file_release(&data->memory, &data->file, data->file_data);
data->memory_free(data->memory_user_data, data);
data->memory.free(data->memory.user_data, data);
}
void cgltf_node_transform_local(const cgltf_node* node, cgltf_float* out_matrix)
@ -1787,6 +1830,77 @@ cgltf_size cgltf_accessor_unpack_floats(const cgltf_accessor* accessor, cgltf_fl
return element_count * floats_per_element;
}
static cgltf_uint cgltf_component_read_uint(const void* in, cgltf_component_type component_type)
{
switch (component_type)
{
case cgltf_component_type_r_8:
return *((const int8_t*) in);
case cgltf_component_type_r_8u:
return *((const uint8_t*) in);
case cgltf_component_type_r_16:
return *((const int16_t*) in);
case cgltf_component_type_r_16u:
return *((const uint16_t*) in);
case cgltf_component_type_r_32u:
return *((const uint32_t*) in);
default:
return 0;
}
return 0;
}
static cgltf_bool cgltf_element_read_uint(const uint8_t* element, cgltf_type type, cgltf_component_type component_type, cgltf_uint* out, cgltf_size element_size)
{
cgltf_size num_components = cgltf_num_components(type);
if (element_size < num_components)
{
return 0;
}
// Reading integer matrices is not a valid use case
if (type == cgltf_type_mat2 || type == cgltf_type_mat3 || type == cgltf_type_mat4)
{
return 0;
}
cgltf_size component_size = cgltf_component_size(component_type);
for (cgltf_size i = 0; i < num_components; ++i)
{
out[i] = cgltf_component_read_uint(element + component_size * i, component_type);
}
return 1;
}
cgltf_bool cgltf_accessor_read_uint(const cgltf_accessor* accessor, cgltf_size index, cgltf_uint* out, cgltf_size element_size)
{
if (accessor->is_sparse)
{
return 0;
}
if (accessor->buffer_view == NULL)
{
memset(out, 0, element_size * sizeof( cgltf_uint ));
return 1;
}
if (accessor->buffer_view->buffer->data == NULL)
{
return 0;
}
cgltf_size offset = accessor->offset + accessor->buffer_view->offset;
const uint8_t* element = (const uint8_t*) accessor->buffer_view->buffer->data;
element += offset + accessor->stride * index;
return cgltf_element_read_uint(element, accessor->type, accessor->component_type, out, element_size);
}
cgltf_size cgltf_accessor_read_index(const cgltf_accessor* accessor, cgltf_size index)
{
if (accessor->is_sparse)
@ -1916,7 +2030,7 @@ static int cgltf_parse_json_string(cgltf_options* options, jsmntok_t const* toke
return CGLTF_ERROR_JSON;
}
int size = tokens[i].end - tokens[i].start;
char* result = (char*)options->memory_alloc(options->memory_user_data, size + 1);
char* result = (char*)options->memory.alloc(options->memory.user_data, size + 1);
if (!result)
{
return CGLTF_ERROR_NOMEM;
@ -4387,7 +4501,7 @@ cgltf_result cgltf_parse_json(cgltf_options* options, const uint8_t* json_chunk,
options->json_token_count = token_count;
}
jsmntok_t* tokens = (jsmntok_t*)options->memory_alloc(options->memory_user_data, sizeof(jsmntok_t) * (options->json_token_count + 1));
jsmntok_t* tokens = (jsmntok_t*)options->memory.alloc(options->memory.user_data, sizeof(jsmntok_t) * (options->json_token_count + 1));
if (!tokens)
{
@ -4400,7 +4514,7 @@ cgltf_result cgltf_parse_json(cgltf_options* options, const uint8_t* json_chunk,
if (token_count <= 0)
{
options->memory_free(options->memory_user_data, tokens);
options->memory.free(options->memory.user_data, tokens);
return cgltf_result_invalid_json;
}
@ -4408,21 +4522,21 @@ cgltf_result cgltf_parse_json(cgltf_options* options, const uint8_t* json_chunk,
// for invalid JSON inputs this makes sure we don't perform out of bound reads of token data
tokens[token_count].type = JSMN_UNDEFINED;
cgltf_data* data = (cgltf_data*)options->memory_alloc(options->memory_user_data, sizeof(cgltf_data));
cgltf_data* data = (cgltf_data*)options->memory.alloc(options->memory.user_data, sizeof(cgltf_data));
if (!data)
{
options->memory_free(options->memory_user_data, tokens);
options->memory.free(options->memory.user_data, tokens);
return cgltf_result_out_of_memory;
}
memset(data, 0, sizeof(cgltf_data));
data->memory_free = options->memory_free;
data->memory_user_data = options->memory_user_data;
data->memory = options->memory;
data->file = options->file;
int i = cgltf_parse_json_root(options, tokens, 0, json_chunk, data);
options->memory_free(options->memory_user_data, tokens);
options->memory.free(options->memory.user_data, tokens);
if (i < 0)
{

38
src/external/glfw/CMake/Info.plist.in vendored Normal file
View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
<key>CFBundleGetInfoString</key>
<string>${MACOSX_BUNDLE_INFO_STRING}</string>
<key>CFBundleIconFile</key>
<string>${MACOSX_BUNDLE_ICON_FILE}</string>
<key>CFBundleIdentifier</key>
<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleLongVersionString</key>
<string>${MACOSX_BUNDLE_LONG_VERSION_STRING}</string>
<key>CFBundleName</key>
<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>LSRequiresCarbon</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.1)
project(GLFW VERSION 3.4.0 LANGUAGES C)
@ -75,7 +75,7 @@ if (MSVC)
include(CheckIncludeFile)
check_include_file(dinput.h DINPUT_H_FOUND)
if (NOT DINPUT_H_FOUND)
message(FATAL_ERROR "DirectX 9 SDK not found")
message(FATAL_ERROR "DirectX 9 headers not found; install DirectX 9 SDK")
endif()
# Workaround for VS 2008 not shipping with stdint.h
list(APPEND glfw_INCLUDE_DIRS "${GLFW_SOURCE_DIR}/deps/vs2008")

View file

@ -11,7 +11,7 @@ application development. It provides a simple, platform-independent API for
creating windows, contexts and surfaces, reading input, handling events, etc.
GLFW natively supports Windows, macOS and Linux and other Unix-like systems. On
Linux both X11 and Wayland is supported.
Linux both X11 and Wayland are supported.
GLFW is licensed under the [zlib/libpng
license](http://www.glfw.org/license.html).
@ -85,10 +85,11 @@ in the documentation for more information.
## Dependencies
GLFW itself depends only on the headers and libraries for your window system.
GLFW itself needs only CMake 3.1 or later and the headers and libraries for your
OS and window system.
The (experimental) Wayland backend also depends on the `extra-cmake-modules`
package, which is used to generated Wayland protocol headers.
package, which is used to generate Wayland protocol headers.
The examples and test programs depend on a number of tiny libraries. These are
located in the `deps/` directory.
@ -123,33 +124,57 @@ information on what to include when reporting a bug.
- Added `GLFW_RESIZE_EW_CURSOR` alias for `GLFW_HRESIZE_CURSOR` (#427)
- Added `GLFW_RESIZE_NS_CURSOR` alias for `GLFW_VRESIZE_CURSOR` (#427)
- Added `GLFW_POINTING_HAND_CURSOR` alias for `GLFW_HAND_CURSOR` (#427)
- Updated the minimum required CMake version to 3.1
- Disabled tests and examples by default when built as a CMake subdirectory
- Bugfix: The CMake config-file package used an absolute path and was not
relocatable (#1470)
- Bugfix: Video modes with a duplicate screen area were discarded (#1555,#1556)
- Bugfix: Compiling with -Wextra-semi caused warnings (#1440)
- Bugfix: Built-in mappings failed because some OEMs re-used VID/PID (#1583)
- [Win32] Added the `GLFW_WIN32_KEYBOARD_MENU` window hint for enabling access
to the window menu
- [Win32] Added a version info resource to the GLFW DLL
- [Win32] Bugfix: `GLFW_INCLUDE_VULKAN` plus `VK_USE_PLATFORM_WIN32_KHR` caused
symbol redefinition (#1524)
- [Win32] Bugfix: The cursor position event was emitted before its cursor enter
event (#1490)
- [Win32] Bugfix: The window hint `GLFW_MAXIMIZED` did not move or resize the
window (#1499)
- [Win32] Bugfix: Disabled cursor mode interfered with some non-client actions
- [Win32] Bugfix: Super key was not released after Win+V hotkey (#1622)
- [Win32] Bugfix: `glfwGetKeyName` could access out of bounds and return an
invalid pointer
- [Win32] Bugfix: Some synthetic key events were reported as `GLFW_KEY_UNKNOWN`
(#1623)
- [Cocoa] Added support for `VK_EXT_metal_surface` (#1619)
- [Cocoa] Added locating the Vulkan loader at runtime in an application bundle
- [Cocoa] Removed dependency on the CoreVideo framework
- [Cocoa] Bugfix: `glfwSetWindowSize` used a bottom-left anchor point (#1553)
- [Cocoa] Bugfix: Window remained on screen after destruction until event poll
(#1412)
- [Cocoa] Bugfix: Event processing before window creation would assert (#1543)
- [Cocoa] Bugfix: Undecorated windows could not be iconified on recent macOS
- [X11] Bugfix: The CMake files did not check for the XInput headers (#1480)
- [X11] Bugfix: Key names were not updated when the keyboard layout changed
(#1462,#1528)
- [X11] Bugfix: Decorations could not be enabled after window creation (#1566)
- [X11] Bugfix: Content scale fallback value could be inconsistent (#1578)
- [X11] Bugfix: `glfwMaximizeWindow` had no effect on hidden windows
- [X11] Bugfix: Clearing `GLFW_FLOATING` on a hidden window caused invalid read
- [X11] Bugfix: Changing `GLFW_FLOATING` on a hidden window could silently fail
- [X11] Bugfix: Disabled cursor mode was interrupted by indicator windows
- [X11] Bugfix: Monitor physical dimensions could be reported as zero mm
- [X11] Bugfix: Window position events were not emitted during resizing (#1613)
- [X11] Bugfix: `glfwFocusWindow` could terminate on older WMs or without a WM
- [X11] Bugfix: Querying a disconnected monitor could segfault (#1602)
- [Wayland] Removed support for `wl_shell` (#1443)
- [Wayland] Bugfix: The `GLFW_HAND_CURSOR` shape used the wrong image (#1432)
- [Wayland] Bugfix: `CLOCK_MONOTONIC` was not correctly enabled
- [POSIX] Bugfix: `CLOCK_MONOTONIC` was not correctly tested for or enabled
- [NSGL] Removed enforcement of forward-compatible flag for core contexts
- Export CMake `GLFW_PKG_DEPS` and `GLFW_PKG_LIBS` to parent scope for use
in client pkg-configs (#1307)
- Added a `glfw_objlib` CMake OBJECT library target for embedding into static
libraries (#1307)
- [NSGL] Bugfix: `GLFW_COCOA_RETINA_FRAMEBUFFER` had no effect on newer
macOS versions (#1442)
- [NSGL] Bugfix: Workaround for swap interval on 10.14 broke on 10.12 (#1483)
## Contact
@ -222,6 +247,7 @@ skills.
- GeO4d
- Marcus Geelnard
- Charles Giessen
- Ryan C. Gordon
- Stephen Gowen
- Kovid Goyal
- Eloi Marín Gratacós
@ -242,6 +268,7 @@ skills.
- Cem Karan
- Osman Keskin
- Josh Kilmer
- Byunghoon Kim
- Cameron King
- Peter Knut
- Christoph Kubisch
@ -249,6 +276,7 @@ skills.
- Rokas Kupstys
- Konstantin Käfer
- Eric Larson
- Francis Lecavalier
- Robin Leffmann
- Glenn Lewis
- Shane Liesegang
@ -257,6 +285,7 @@ skills.
- Eyal Lotem
- Aaron Loucks
- Luflosi
- lukect
- Tristam MacDonald
- Hans Mackowiak
- Дмитри Малышев
@ -302,6 +331,7 @@ skills.
- Alexandre Pretyman
- Pablo Prietz
- przemekmirek
- pthom
- Guillaume Racicot
- Philip Rideout
- Eddie Ringle
@ -332,6 +362,7 @@ skills.
- Paul Sultana
- Nathan Sweet
- TTK-Bandit
- Jared Tiala
- Sergey Tikhomirov
- Arthur Tombs
- Ioannis Tsakpinis

View file

@ -2685,7 +2685,7 @@ GLFWAPI void glfwWindowHintString(int hint, const char* value);
* [High Resolution Guidelines for OS X](https://developer.apple.com/library/mac/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Explained/Explained.html)
* in the Mac Developer Library. The GLFW test and example programs use
* a custom `Info.plist` template for this, which can be found as
* `CMake/MacOSXBundleInfo.plist.in` in the source tree.
* `CMake/Info.plist.in` in the source tree.
*
* @remark @macos When activating frame autosaving with
* [GLFW_COCOA_FRAME_NAME](@ref GLFW_COCOA_FRAME_NAME_hint), the specified
@ -5776,8 +5776,9 @@ GLFWAPI int glfwVulkanSupported(void);
* returned array, as it is an error to specify an extension more than once in
* the `VkInstanceCreateInfo` struct.
*
* @remark @macos This function currently only supports the
* `VK_MVK_macos_surface` extension from MoltenVK.
* @remark @macos This function currently supports either the
* `VK_MVK_macos_surface` extension from MoltenVK or `VK_EXT_metal_surface`
* extension.
*
* @pointer_lifetime The returned array is allocated and freed by GLFW. You
* should not free it yourself. It is guaranteed to be valid only until the

View file

@ -431,9 +431,8 @@ static GLFWbool initializeTIS(void)
// In case we are unbundled, make us a proper UI application
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
// Menu bar setup must go between sharedApplication above and
// finishLaunching below, in order to properly emulate the behavior
// of NSApplicationMain
// Menu bar setup must go between sharedApplication and finishLaunching
// in order to properly emulate the behavior of NSApplicationMain
if ([[NSBundle mainBundle] pathForResource:@"MainMenu" ofType:@"nib"])
{
@ -448,9 +447,9 @@ static GLFWbool initializeTIS(void)
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
[NSApp stop:nil];
_glfw.ns.finishedLaunching = GLFW_TRUE;
_glfwPlatformPostEmptyEvent();
[NSApp stop:nil];
}
- (void)applicationDidHide:(NSNotification *)notification
@ -464,6 +463,32 @@ static GLFWbool initializeTIS(void)
@end // GLFWApplicationDelegate
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
void* _glfwLoadLocalVulkanLoaderNS(void)
{
CFBundleRef bundle = CFBundleGetMainBundle();
if (!bundle)
return NULL;
CFURLRef url =
CFBundleCopyAuxiliaryExecutableURL(bundle, CFSTR("libvulkan.1.dylib"));
if (!url)
return NULL;
char path[PATH_MAX];
void* handle = NULL;
if (CFURLGetFileSystemRepresentation(url, true, (UInt8*) path, sizeof(path) - 1))
handle = _glfw_dlopen(path);
CFRelease(url);
return handle;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////

View file

@ -331,7 +331,7 @@ void _glfwInitJoysticksNS(void)
return;
}
for (int i = 0; i < sizeof(usages) / sizeof(long); i++)
for (size_t i = 0; i < sizeof(usages) / sizeof(long); i++)
{
const long page = kHIDPage_GenericDesktop;

View file

@ -144,7 +144,7 @@ static GLFWbool modeIsGood(CGDisplayModeRef mode)
// Convert Core Graphics display mode to GLFW video mode
//
static GLFWvidmode vidmodeFromCGDisplayMode(CGDisplayModeRef mode,
CVDisplayLinkRef link)
double fallbackRefreshRate)
{
GLFWvidmode result;
result.width = (int) CGDisplayModeGetWidth(mode);
@ -152,11 +152,7 @@ static GLFWvidmode vidmodeFromCGDisplayMode(CGDisplayModeRef mode,
result.refreshRate = (int) round(CGDisplayModeGetRefreshRate(mode));
if (result.refreshRate == 0)
{
const CVTime time = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(link);
if (!(time.flags & kCVTimeIsIndefinite))
result.refreshRate = (int) (time.timeScale / (double) time.timeValue);
}
result.refreshRate = (int) round(fallbackRefreshRate);
#if MAC_OS_X_VERSION_MAX_ALLOWED <= 101100
CFStringRef format = CGDisplayModeCopyPixelEncoding(mode);
@ -238,6 +234,68 @@ static GLFWbool refreshMonitorScreen(_GLFWmonitor* monitor)
return GLFW_FALSE;
}
// Returns the display refresh rate queried from the I/O registry
//
static double getFallbackRefreshRate(CGDirectDisplayID displayID)
{
double refreshRate = 60.0;
io_iterator_t it;
io_service_t service;
if (IOServiceGetMatchingServices(kIOMasterPortDefault,
IOServiceMatching("IOFramebuffer"),
&it) != 0)
{
return refreshRate;
}
while ((service = IOIteratorNext(it)) != 0)
{
const CFNumberRef indexRef =
IORegistryEntryCreateCFProperty(service,
CFSTR("IOFramebufferOpenGLIndex"),
kCFAllocatorDefault,
kNilOptions);
if (!indexRef)
continue;
uint32_t index = 0;
CFNumberGetValue(indexRef, kCFNumberIntType, &index);
CFRelease(indexRef);
if (CGOpenGLDisplayMaskToDisplayID(1 << index) != displayID)
continue;
const CFNumberRef clockRef =
IORegistryEntryCreateCFProperty(service,
CFSTR("IOFBCurrentPixelClock"),
kCFAllocatorDefault,
kNilOptions);
const CFNumberRef countRef =
IORegistryEntryCreateCFProperty(service,
CFSTR("IOFBCurrentPixelCount"),
kCFAllocatorDefault,
kNilOptions);
if (!clockRef || !countRef)
break;
uint32_t clock = 0, count = 0;
CFNumberGetValue(clockRef, kCFNumberIntType, &clock);
CFNumberGetValue(countRef, kCFNumberIntType, &count);
CFRelease(clockRef);
CFRelease(countRef);
if (clock > 0 && count > 0)
refreshRate = clock / (double) count;
break;
}
IOObjectRelease(it);
return refreshRate;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
@ -294,6 +352,11 @@ void _glfwPollMonitorsNS(void)
free(name);
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displays[i]);
if (CGDisplayModeGetRefreshRate(mode) == 0.0)
monitor->ns.fallbackRefreshRate = getFallbackRefreshRate(displays[i]);
CGDisplayModeRelease(mode);
_glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_LAST);
}
@ -318,9 +381,6 @@ void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired)
if (_glfwCompareVideoModes(&current, best) == 0)
return;
CVDisplayLinkRef link;
CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link);
CFArrayRef modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL);
const CFIndex count = CFArrayGetCount(modes);
CGDisplayModeRef native = NULL;
@ -331,7 +391,8 @@ void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired)
if (!modeIsGood(dm))
continue;
const GLFWvidmode mode = vidmodeFromCGDisplayMode(dm, link);
const GLFWvidmode mode =
vidmodeFromCGDisplayMode(dm, monitor->ns.fallbackRefreshRate);
if (_glfwCompareVideoModes(best, &mode) == 0)
{
native = dm;
@ -350,7 +411,6 @@ void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired)
}
CFRelease(modes);
CVDisplayLinkRelease(link);
}
// Restore the previously saved (original) video mode
@ -440,9 +500,6 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
*count = 0;
CVDisplayLinkRef link;
CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link);
CFArrayRef modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL);
const CFIndex found = CFArrayGetCount(modes);
GLFWvidmode* result = calloc(found, sizeof(GLFWvidmode));
@ -453,7 +510,8 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
if (!modeIsGood(dm))
continue;
const GLFWvidmode mode = vidmodeFromCGDisplayMode(dm, link);
const GLFWvidmode mode =
vidmodeFromCGDisplayMode(dm, monitor->ns.fallbackRefreshRate);
CFIndex j;
for (j = 0; j < *count; j++)
@ -471,7 +529,6 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
}
CFRelease(modes);
CVDisplayLinkRelease(link);
return result;
} // autoreleasepool
@ -481,15 +538,10 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode *mode)
{
@autoreleasepool {
CVDisplayLinkRef link;
CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link);
CGDisplayModeRef native = CGDisplayCopyDisplayMode(monitor->ns.displayID);
*mode = vidmodeFromCGDisplayMode(native, link);
*mode = vidmodeFromCGDisplayMode(native, monitor->ns.fallbackRefreshRate);
CGDisplayModeRelease(native);
CVDisplayLinkRelease(link);
} // autoreleasepool
}

View file

@ -28,8 +28,6 @@
#include <dlfcn.h>
#include <Carbon/Carbon.h>
#include <CoreVideo/CVBase.h>
#include <CoreVideo/CVDisplayLink.h>
// NOTE: All of NSGL was deprecated in the 10.14 SDK
// This disables the pointless warnings for every symbol we use
@ -63,6 +61,7 @@ typedef void* id;
#endif
typedef VkFlags VkMacOSSurfaceCreateFlagsMVK;
typedef VkFlags VkMetalSurfaceCreateFlagsEXT;
typedef struct VkMacOSSurfaceCreateInfoMVK
{
@ -72,7 +71,16 @@ typedef struct VkMacOSSurfaceCreateInfoMVK
const void* pView;
} VkMacOSSurfaceCreateInfoMVK;
typedef struct VkMetalSurfaceCreateInfoEXT
{
VkStructureType sType;
const void* pNext;
VkMetalSurfaceCreateFlagsEXT flags;
const void* pLayer;
} VkMetalSurfaceCreateInfoEXT;
typedef VkResult (APIENTRY *PFN_vkCreateMacOSSurfaceMVK)(VkInstance,const VkMacOSSurfaceCreateInfoMVK*,const VkAllocationCallbacks*,VkSurfaceKHR*);
typedef VkResult (APIENTRY *PFN_vkCreateMetalSurfaceEXT)(VkInstance,const VkMetalSurfaceCreateInfoEXT*,const VkAllocationCallbacks*,VkSurfaceKHR*);
#include "posix_thread.h"
#include "cocoa_joystick.h"
@ -170,6 +178,7 @@ typedef struct _GLFWmonitorNS
CGDisplayModeRef previousMode;
uint32_t unitNumber;
id screen;
double fallbackRefreshRate;
} _GLFWmonitorNS;
@ -198,3 +207,5 @@ void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor);
float _glfwTransformYNS(float y);
void* _glfwLoadLocalVulkanLoaderNS(void);

View file

@ -322,12 +322,6 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
_glfwInputWindowFocus(window, GLFW_FALSE);
}
- (void)windowDidChangeScreen:(NSNotification *)notification
{
if (window->context.source == GLFW_NATIVE_CONTEXT_API)
_glfwUpdateDisplayLinkDisplayNSGL(window);
}
@end
@ -891,10 +885,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
@autoreleasepool {
if (!_glfw.ns.finishedLaunching)
{
[NSApp run];
_glfw.ns.finishedLaunching = GLFW_TRUE;
}
if (!createNativeWindow(window, wndconfig, fbconfig))
return GLFW_FALSE;
@ -967,13 +958,14 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
} // autoreleasepool
}
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title)
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
{
@autoreleasepool {
[window->ns.object setTitle:@(title)];
NSString* string = @(title);
[window->ns.object setTitle:string];
// HACK: Set the miniwindow title explicitly as setTitle: doesn't update it
// if the window lacks NSWindowStyleMaskTitled
[window->ns.object setMiniwindowTitle:@(title)];
[window->ns.object setMiniwindowTitle:string];
} // autoreleasepool
}
@ -1385,6 +1377,9 @@ void _glfwPlatformPollEvents(void)
{
@autoreleasepool {
if (!_glfw.ns.finishedLaunching)
[NSApp run];
for (;;)
{
NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny
@ -1404,6 +1399,9 @@ void _glfwPlatformWaitEvents(void)
{
@autoreleasepool {
if (!_glfw.ns.finishedLaunching)
[NSApp run];
// I wanted to pass NO to dequeue:, and rely on PollEvents to
// dequeue and send. For reasons not at all clear to me, passing
// NO to dequeue: causes this method never to return.
@ -1422,6 +1420,9 @@ void _glfwPlatformWaitEventsTimeout(double timeout)
{
@autoreleasepool {
if (!_glfw.ns.finishedLaunching)
[NSApp run];
NSDate* date = [NSDate dateWithTimeIntervalSinceNow:timeout];
NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny
untilDate:date
@ -1439,6 +1440,9 @@ void _glfwPlatformPostEmptyEvent(void)
{
@autoreleasepool {
if (!_glfw.ns.finishedLaunching)
[NSApp run];
NSEvent* event = [NSEvent otherEventWithType:NSEventTypeApplicationDefined
location:NSMakePoint(0, 0)
modifierFlags:0
@ -1512,6 +1516,13 @@ const char* _glfwPlatformGetScancodeName(int scancode)
{
@autoreleasepool {
if (scancode < 0 || scancode > 0xff ||
_glfw.ns.keycodes[scancode] == GLFW_KEY_UNKNOWN)
{
_glfwInputError(GLFW_INVALID_VALUE, "Invalid scancode");
return NULL;
}
const int key = _glfw.ns.keycodes[scancode];
UInt32 deadKeyState = 0;
@ -1607,13 +1618,13 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
// HACK: Try to use a private message
if (shape == GLFW_RESIZE_EW_CURSOR)
cursorSelector = @selector(_windowResizeEastWestCursor);
cursorSelector = NSSelectorFromString(@"_windowResizeEastWestCursor");
else if (shape == GLFW_RESIZE_NS_CURSOR)
cursorSelector = @selector(_windowResizeNorthSouthCursor);
cursorSelector = NSSelectorFromString(@"_windowResizeNorthSouthCursor");
else if (shape == GLFW_RESIZE_NWSE_CURSOR)
cursorSelector = @selector(_windowResizeNorthWestSouthEastCursor);
cursorSelector = NSSelectorFromString(@"_windowResizeNorthWestSouthEastCursor");
else if (shape == GLFW_RESIZE_NESW_CURSOR)
cursorSelector = @selector(_windowResizeNorthEastSouthWestCursor);
cursorSelector = NSSelectorFromString(@"_windowResizeNorthEastSouthWestCursor");
if (cursorSelector && [NSCursor respondsToSelector:cursorSelector])
{
@ -1711,11 +1722,16 @@ const char* _glfwPlatformGetClipboardString(void)
void _glfwPlatformGetRequiredInstanceExtensions(char** extensions)
{
if (!_glfw.vk.KHR_surface || !_glfw.vk.MVK_macos_surface)
return;
extensions[0] = "VK_KHR_surface";
extensions[1] = "VK_MVK_macos_surface";
if (_glfw.vk.KHR_surface && _glfw.vk.EXT_metal_surface)
{
extensions[0] = "VK_KHR_surface";
extensions[1] = "VK_EXT_metal_surface";
}
else if (_glfw.vk.KHR_surface && _glfw.vk.MVK_macos_surface)
{
extensions[0] = "VK_KHR_surface";
extensions[1] = "VK_MVK_macos_surface";
}
}
int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
@ -1733,19 +1749,6 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
@autoreleasepool {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101100
VkResult err;
VkMacOSSurfaceCreateInfoMVK sci;
PFN_vkCreateMacOSSurfaceMVK vkCreateMacOSSurfaceMVK;
vkCreateMacOSSurfaceMVK = (PFN_vkCreateMacOSSurfaceMVK)
vkGetInstanceProcAddr(instance, "vkCreateMacOSSurfaceMVK");
if (!vkCreateMacOSSurfaceMVK)
{
_glfwInputError(GLFW_API_UNAVAILABLE,
"Cocoa: Vulkan instance missing VK_MVK_macos_surface extension");
return VK_ERROR_EXTENSION_NOT_PRESENT;
}
// HACK: Dynamically load Core Animation to avoid adding an extra
// dependency for the majority who don't use MoltenVK
NSBundle* bundle = [NSBundle bundleWithPath:@"/System/Library/Frameworks/QuartzCore.framework"];
@ -1771,11 +1774,49 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
[window->ns.view setLayer:window->ns.layer];
[window->ns.view setWantsLayer:YES];
memset(&sci, 0, sizeof(sci));
sci.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
sci.pView = window->ns.view;
VkResult err;
if (_glfw.vk.EXT_metal_surface)
{
VkMetalSurfaceCreateInfoEXT sci;
PFN_vkCreateMetalSurfaceEXT vkCreateMetalSurfaceEXT;
vkCreateMetalSurfaceEXT = (PFN_vkCreateMetalSurfaceEXT)
vkGetInstanceProcAddr(instance, "vkCreateMetalSurfaceEXT");
if (!vkCreateMetalSurfaceEXT)
{
_glfwInputError(GLFW_API_UNAVAILABLE,
"Cocoa: Vulkan instance missing VK_EXT_metal_surface extension");
return VK_ERROR_EXTENSION_NOT_PRESENT;
}
memset(&sci, 0, sizeof(sci));
sci.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT;
sci.pLayer = window->ns.layer;
err = vkCreateMetalSurfaceEXT(instance, &sci, allocator, surface);
}
else
{
VkMacOSSurfaceCreateInfoMVK sci;
PFN_vkCreateMacOSSurfaceMVK vkCreateMacOSSurfaceMVK;
vkCreateMacOSSurfaceMVK = (PFN_vkCreateMacOSSurfaceMVK)
vkGetInstanceProcAddr(instance, "vkCreateMacOSSurfaceMVK");
if (!vkCreateMacOSSurfaceMVK)
{
_glfwInputError(GLFW_API_UNAVAILABLE,
"Cocoa: Vulkan instance missing VK_MVK_macos_surface extension");
return VK_ERROR_EXTENSION_NOT_PRESENT;
}
memset(&sci, 0, sizeof(sci));
sci.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
sci.pView = window->ns.view;
err = vkCreateMacOSSurfaceMVK(instance, &sci, allocator, surface);
}
err = vkCreateMacOSSurfaceMVK(instance, &sci, allocator, surface);
if (err)
{
_glfwInputError(GLFW_PLATFORM_ERROR,

View file

@ -123,23 +123,24 @@ static GLFWbool chooseEGLConfig(const _GLFWctxconfig* ctxconfig,
continue;
#if defined(_GLFW_X11)
XVisualInfo vi = {0};
// Only consider EGLConfigs with associated Visuals
vi.visualid = getEGLConfigAttrib(n, EGL_NATIVE_VISUAL_ID);
if (!vi.visualid)
continue;
if (desired->transparent)
{
int count;
XVisualInfo* vis = XGetVisualInfo(_glfw.x11.display,
VisualIDMask, &vi,
&count);
if (vis)
XVisualInfo vi = {0};
// Only consider EGLConfigs with associated Visuals
vi.visualid = getEGLConfigAttrib(n, EGL_NATIVE_VISUAL_ID);
if (!vi.visualid)
continue;
if (desired->transparent)
{
u->transparent = _glfwIsVisualTransparentX11(vis[0].visual);
XFree(vis);
int count;
XVisualInfo* vis =
XGetVisualInfo(_glfw.x11.display, VisualIDMask, &vi, &count);
if (vis)
{
u->transparent = _glfwIsVisualTransparentX11(vis[0].visual);
XFree(vis);
}
}
}
#endif // _GLFW_X11

30
src/external/glfw/src/glfw.rc.in vendored Normal file
View file

@ -0,0 +1,30 @@
#include <winver.h>
VS_VERSION_INFO VERSIONINFO
FILEVERSION @GLFW_VERSION_MAJOR@,@GLFW_VERSION_MINOR@,@GLFW_VERSION_PATCH@,0
PRODUCTVERSION @GLFW_VERSION_MAJOR@,@GLFW_VERSION_MINOR@,@GLFW_VERSION_PATCH@,0
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
FILEFLAGS 0
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0
{
BLOCK "StringFileInfo"
{
BLOCK "040904B0"
{
VALUE "CompanyName", "GLFW"
VALUE "FileDescription", "GLFW @GLFW_VERSION@ DLL"
VALUE "FileVersion", "@GLFW_VERSION@"
VALUE "OriginalFilename", "glfw3.dll"
VALUE "ProductName", "GLFW"
VALUE "ProductVersion", "@GLFW_VERSION@"
}
}
BLOCK "VarFileInfo"
{
VALUE "Translation", 0x409, 1200
}
}

View file

@ -1 +1,3 @@
include(CMakeFindDependencyMacro)
find_dependency(Threads)
include("${CMAKE_CURRENT_LIST_DIR}/glfw3Targets.cmake")

View file

@ -128,6 +128,7 @@ typedef enum VkStructureType
VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR = 1000006000,
VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR = 1000009000,
VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK = 1000123000,
VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT = 1000217000,
VK_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF
} VkStructureType;
@ -559,6 +560,7 @@ struct _GLFWlibrary
GLFWbool KHR_win32_surface;
#elif defined(_GLFW_COCOA)
GLFWbool MVK_macos_surface;
GLFWbool EXT_metal_surface;
#elif defined(_GLFW_X11)
GLFWbool KHR_xlib_surface;
GLFWbool KHR_xcb_surface;

View file

@ -44,10 +44,6 @@ typedef struct _GLFWcontextNSGL
{
id pixelFormat;
id object;
CVDisplayLinkRef displayLink;
atomic_int swapInterval;
int swapIntervalsPassed;
id swapIntervalCond;
} _GLFWcontextNSGL;
@ -67,5 +63,4 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig);
void _glfwDestroyContextNSGL(_GLFWwindow* window);
void _glfwUpdateDisplayLinkDisplayNSGL(_GLFWwindow* window);

View file

@ -28,29 +28,8 @@
#include "internal.h"
// Display link callback for manual swap interval implementation
// This is based on a similar workaround added to SDL2
//
static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink,
const CVTimeStamp* now,
const CVTimeStamp* outputTime,
CVOptionFlags flagsIn,
CVOptionFlags* flagsOut,
void* userInfo)
{
_GLFWwindow* window = (_GLFWwindow *) userInfo;
const int interval = atomic_load(&window->context.nsgl.swapInterval);
if (interval > 0)
{
[window->context.nsgl.swapIntervalCond lock];
window->context.nsgl.swapIntervalsPassed++;
[window->context.nsgl.swapIntervalCond signal];
[window->context.nsgl.swapIntervalCond unlock];
}
return kCVReturnSuccess;
}
#include <unistd.h>
#include <math.h>
static void makeContextCurrentNSGL(_GLFWwindow* window)
{
@ -70,19 +49,28 @@ static void swapBuffersNSGL(_GLFWwindow* window)
{
@autoreleasepool {
const int interval = atomic_load(&window->context.nsgl.swapInterval);
if (interval > 0)
// HACK: Simulate vsync with usleep as NSGL swap interval does not apply to
// windows with a non-visible occlusion state
if (!([window->ns.object occlusionState] & NSWindowOcclusionStateVisible))
{
[window->context.nsgl.swapIntervalCond lock];
do
int interval = 0;
[window->context.nsgl.object getValues:&interval
forParameter:NSOpenGLContextParameterSwapInterval];
if (interval > 0)
{
[window->context.nsgl.swapIntervalCond wait];
} while (window->context.nsgl.swapIntervalsPassed % interval != 0);
window->context.nsgl.swapIntervalsPassed = 0;
[window->context.nsgl.swapIntervalCond unlock];
const double framerate = 60.0;
const uint64_t frequency = _glfwPlatformGetTimerFrequency();
const uint64_t value = _glfwPlatformGetTimerValue();
const double elapsed = value / (double) frequency;
const double period = 1.0 / framerate;
const double delay = period - fmod(elapsed, period);
usleep(floorl(delay * 1e6));
}
}
// ARP appears to be unnecessary, but this is future-proof
[window->context.nsgl.object flushBuffer];
} // autoreleasepool
@ -91,11 +79,14 @@ static void swapBuffersNSGL(_GLFWwindow* window)
static void swapIntervalNSGL(int interval)
{
@autoreleasepool {
_GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot);
atomic_store(&window->context.nsgl.swapInterval, interval);
[window->context.nsgl.swapIntervalCond lock];
window->context.nsgl.swapIntervalsPassed = 0;
[window->context.nsgl.swapIntervalCond unlock];
if (window)
{
[window->context.nsgl.object setValues:&interval
forParameter:NSOpenGLContextParameterSwapInterval];
}
} // autoreleasepool
}
@ -123,17 +114,6 @@ static void destroyContextNSGL(_GLFWwindow* window)
{
@autoreleasepool {
if (window->context.nsgl.displayLink)
{
if (CVDisplayLinkIsRunning(window->context.nsgl.displayLink))
CVDisplayLinkStop(window->context.nsgl.displayLink);
CVDisplayLinkRelease(window->context.nsgl.displayLink);
}
[window->context.nsgl.swapIntervalCond release];
window->context.nsgl.swapIntervalCond = nil;
[window->context.nsgl.pixelFormat release];
window->context.nsgl.pixelFormat = nil;
@ -354,17 +334,10 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
forParameter:NSOpenGLContextParameterSurfaceOpacity];
}
if (window->ns.retina)
[window->ns.view setWantsBestResolutionOpenGLSurface:YES];
GLint interval = 0;
[window->context.nsgl.object setValues:&interval
forParameter:NSOpenGLContextParameterSwapInterval];
[window->ns.view setWantsBestResolutionOpenGLSurface:window->ns.retina];
[window->context.nsgl.object setView:window->ns.view];
window->context.nsgl.swapIntervalCond = [NSCondition new];
window->context.makeCurrent = makeContextCurrentNSGL;
window->context.swapBuffers = swapBuffersNSGL;
window->context.swapInterval = swapIntervalNSGL;
@ -372,26 +345,9 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
window->context.getProcAddress = getProcAddressNSGL;
window->context.destroy = destroyContextNSGL;
CVDisplayLinkCreateWithActiveCGDisplays(&window->context.nsgl.displayLink);
CVDisplayLinkSetOutputCallback(window->context.nsgl.displayLink,
&displayLinkCallback,
window);
CVDisplayLinkStart(window->context.nsgl.displayLink);
_glfwUpdateDisplayLinkDisplayNSGL(window);
return GLFW_TRUE;
}
void _glfwUpdateDisplayLinkDisplayNSGL(_GLFWwindow* window)
{
CGDirectDisplayID displayID =
[[[window->ns.object screen] deviceDescription][@"NSScreenNumber"] unsignedIntValue];
if (!displayID)
return;
CVDisplayLinkSetCurrentCGDisplay(window->context.nsgl.displayLink, displayID);
}
//////////////////////////////////////////////////////////////////////////
////// GLFW native API //////

View file

@ -27,8 +27,11 @@
// It is fine to use C99 in this file because it will not be built with VS
//========================================================================
#define _POSIX_C_SOURCE 199309L
#include "internal.h"
#include <unistd.h>
#include <sys/time.h>
#include <time.h>
@ -41,7 +44,7 @@
//
void _glfwInitTimerPOSIX(void)
{
#if defined(CLOCK_MONOTONIC)
#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK)
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
@ -64,7 +67,7 @@ void _glfwInitTimerPOSIX(void)
uint64_t _glfwPlatformGetTimerValue(void)
{
#if defined(CLOCK_MONOTONIC)
#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK)
if (_glfw.timer.posix.monotonic)
{
struct timespec ts;

Some files were not shown because too many files have changed in this diff Show more