diff --git a/.gitignore b/.gitignore index 859499268..55537f1ab 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ _ReSharper* *.vcxproj* *.sln .vs/ +/.idea/ +/cmake-build-*/ Win32 x64 Debug diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c0f62503..f1c41bc8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,10 @@ if (UNIX) option(GLFW_USE_OSMESA "Use OSMesa for offscreen context creation" OFF) endif() +if (UNIX) + option(GLFW_USE_VIVANTE "Use Vivante EGL for window creation" OFF) +endif() + if (WIN32) option(GLFW_USE_HYBRID_HPG "Force use of high-performance GPU on hybrid systems" OFF) endif() @@ -145,6 +149,9 @@ endif() if (GLFW_USE_WAYLAND) set(_GLFW_WAYLAND 1) message(STATUS "Using Wayland for window creation") +elseif (GLFW_USE_VIVANTE) + set(_GLFW_VIVANTE 1) + message(STATUS "Using Vivante for window creation") elseif (GLFW_USE_OSMESA) set(_GLFW_OSMESA 1) message(STATUS "Using OSMesa for headless context creation") @@ -269,6 +276,16 @@ if (_GLFW_WAYLAND) endif() endif() +#-------------------------------------------------------------------- +# Use Vivante for window creation +#-------------------------------------------------------------------- +if (_GLFW_VIVANTE) + list(APPEND glfw_LIBRARIES "-lEGL") + list(APPEND glfw_PKG_LIBS "-lEGL") + + list(APPEND glfw_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}") +endif() + #-------------------------------------------------------------------- # Use OSMesa for offscreen context creation #-------------------------------------------------------------------- diff --git a/README.md b/README.md index 27a0b3872..ebd81b0be 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,5 @@ # GLFW -[![Build status](https://travis-ci.org/glfw/glfw.svg?branch=master)](https://travis-ci.org/glfw/glfw) -[![Build status](https://ci.appveyor.com/api/projects/status/0kf0ct9831i5l6sp/branch/master?svg=true)](https://ci.appveyor.com/project/elmindreda/glfw) -[![Coverity Scan](https://scan.coverity.com/projects/4884/badge.svg)](https://scan.coverity.com/projects/glfw-glfw) - ## Introduction GLFW is an Open Source, multi-platform library for OpenGL, OpenGL ES and Vulkan diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 98da2cd7b..a4b06a985 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -15,6 +15,12 @@ if (GLFW_USE_OSMESA) add_definitions(-DUSE_NATIVE_OSMESA) endif() +if (GLFW_USE_VIVANTE) + add_definitions(-DGLFW_INCLUDE_ES2) + add_definitions(-DGL_GLES_PROTOTYPES=0) + link_libraries(-pthread) +endif() + if (WIN32) set(ICON glfw.rc) elseif (APPLE) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0913579b6..8e59317b1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,6 +60,12 @@ elseif (_GLFW_OSMESA) posix_time.h posix_thread.h osmesa_context.h) set(glfw_SOURCES ${common_SOURCES} null_init.c null_monitor.c null_window.c null_joystick.c posix_time.c posix_thread.c osmesa_context.c) +elseif (_GLFW_VIVANTE) + set(glfw_HEADERS ${common_HEADERS} vivante_platform.h xkb_unicode.h linux_joystick.h + posix_time.h posix_thread.h egl_context.h) + set(glfw_SOURCES ${common_SOURCES} vivante_init.c vivante_monitor.c vivante_window.c + xkb_unicode.c linux_joystick.c posix_time.c posix_thread.c + egl_context.c) endif() if (_GLFW_X11 OR _GLFW_WAYLAND) diff --git a/src/egl_context.h b/src/egl_context.h index 7def043af..926e01fe4 100644 --- a/src/egl_context.h +++ b/src/egl_context.h @@ -43,6 +43,10 @@ typedef Window EGLNativeWindowType; #define EGLAPIENTRY typedef struct wl_display* EGLNativeDisplayType; typedef struct wl_egl_window* EGLNativeWindowType; +#elif defined(_GLFW_VIVANTE) + #define EGLAPIENTRY + #define EGL_API_FB + #include #else #error "No supported EGL platform selected" #endif diff --git a/src/glfw_config.h.in b/src/glfw_config.h.in index f418c9950..dfebd79df 100644 --- a/src/glfw_config.h.in +++ b/src/glfw_config.h.in @@ -44,6 +44,8 @@ #cmakedefine _GLFW_WAYLAND // Define this to 1 if building GLFW for OSMesa #cmakedefine _GLFW_OSMESA +// Define this to 1 if building GLFW for Vivante +#cmakedefine _GLFW_VIVANTE // Define this to 1 if building as a shared library / dynamic library / DLL #cmakedefine _GLFW_BUILD_DLL diff --git a/src/internal.h b/src/internal.h index 618507c6d..3de986704 100644 --- a/src/internal.h +++ b/src/internal.h @@ -189,6 +189,8 @@ typedef void (APIENTRY * PFN_vkVoidFunction)(void); #include "wl_platform.h" #elif defined(_GLFW_OSMESA) #include "null_platform.h" +#elif defined(_GLFW_VIVANTE) + #include "vivante_platform.h" #else #error "No supported window creation API selected" #endif diff --git a/src/vivante_init.c b/src/vivante_init.c new file mode 100644 index 000000000..585305cb4 --- /dev/null +++ b/src/vivante_init.c @@ -0,0 +1,85 @@ +//======================================================================== +// GLFW 3.3 - www.glfw.org +//------------------------------------------------------------------------ +// Copyright (c) 2016 Google Inc. +// Copyright (c) 2016-2017 Camilla Löwy +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== + +#include "internal.h" + + +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// + +int _glfwPlatformInit(void) +{ + _glfw.vivante.display = fbGetDisplay(NULL); + if (!_glfw.vivante.display) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Vivante: Failed to open display"); + + return GLFW_FALSE; + } + + + + + + _glfwInitTimerPOSIX(); + + if (!_glfwInitJoysticksLinux()) + return GLFW_FALSE; + + return GLFW_TRUE; +} + +void _glfwPlatformTerminate(void) +{ + _glfwTerminateJoysticksLinux(); + + if (_glfw.vivante.display) + { + fbDestroyDisplay(_glfw.vivante.display); + _glfw.vivante.display = NULL; + } +} + +const char* _glfwPlatformGetVersionString(void) +{ + return _GLFW_VERSION_NUMBER " vivante EGL" +#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK) + " clock_gettime" +#else + " gettimeofday" +#endif +#if defined(__linux__) + " evdev" +#endif +#if defined(_GLFW_BUILD_DLL) + " shared" +#endif + ; +} + diff --git a/src/vivante_monitor.c b/src/vivante_monitor.c new file mode 100644 index 000000000..f5cb092f7 --- /dev/null +++ b/src/vivante_monitor.c @@ -0,0 +1,75 @@ +//======================================================================== +// GLFW 3.3 - www.glfw.org +//------------------------------------------------------------------------ +// Copyright (c) 2016 Google Inc. +// Copyright (c) 2016-2019 Camilla Löwy +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== + +#include "internal.h" + + +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// + +void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor) +{ +} + +void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) +{ +} + +void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor, + float* xscale, float* yscale) +{ + if (xscale) + *xscale = 1.f; + if (yscale) + *yscale = 1.f; +} + +void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor, + int* xpos, int* ypos, + int* width, int* height) +{ +} + +GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) +{ + return NULL; +} + +void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) +{ +} + +GLFWbool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) +{ + return GLFW_FALSE; +} + +void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) +{ +} + diff --git a/src/vivante_platform.h b/src/vivante_platform.h new file mode 100644 index 000000000..57f9f3e5e --- /dev/null +++ b/src/vivante_platform.h @@ -0,0 +1,73 @@ +//======================================================================== +// GLFW 3.3 - www.glfw.org +//------------------------------------------------------------------------ +// Copyright (c) 2016 Google Inc. +// Copyright (c) 2016-2017 Camilla Löwy +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== + +#include +#include // TODO: remove it + +#define _GLFW_PLATFORM_CONTEXT_STATE +#define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE +#define _GLFW_OSMESA_CONTEXT_STATE +#define _GLFW_OSMESA_LIBRARY_CONTEXT_STATE + +#include "posix_time.h" +#include "posix_thread.h" +#include "xkb_unicode.h" +#include "egl_context.h" +#include "linux_joystick.h" + +#define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) +#define _glfw_dlclose(handle) dlclose(handle) +#define _glfw_dlsym(handle, name) dlsym(handle, name) + +#define _GLFW_EGL_NATIVE_WINDOW (window->vivante.native_window) +#define _GLFW_EGL_NATIVE_DISPLAY (_glfw.vivante.display) + +#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowVivante vivante +#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryVivante vivante +#define _GLFW_PLATFORM_MONITOR_STATE //_GLFWmonitorVivante vivante +#define _GLFW_PLATFORM_CURSOR_STATE //_GLFWcursorVivante vivante + +// Vivante-specific per-window data +// +typedef struct _GLFWwindowVivante +{ + EGLNativeWindowType native_window; + EGLSurface egl_surface; + + // Cached position and size used to filter out duplicate events + int width, height; + int xpos, ypos; + +} _GLFWwindowVivante; + +// Vivante-specific global data +// +typedef struct _GLFWlibraryVivante +{ + EGLNativeDisplayType display; + +} _GLFWlibraryVivante; diff --git a/src/vivante_window.c b/src/vivante_window.c new file mode 100644 index 000000000..3dee5a278 --- /dev/null +++ b/src/vivante_window.c @@ -0,0 +1,338 @@ +//======================================================================== +// GLFW 3.3 - www.glfw.org +//------------------------------------------------------------------------ +// Copyright (c) 2016 Google Inc. +// Copyright (c) 2016-2019 Camilla Löwy +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== + +#include "internal.h" + +static int createNativeWindow(_GLFWwindow* window, + const _GLFWwndconfig* wndconfig) +{ + window->vivante.native_window = fbCreateWindow( _GLFW_EGL_NATIVE_DISPLAY, 0, 0, wndconfig->width, wndconfig->height ); + if (!window->vivante.native_window) + return GLFW_FALSE; + + window->vivante.width = wndconfig->width; + window->vivante.height = wndconfig->height; + + return GLFW_TRUE; +} + + +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// + +int _glfwPlatformCreateWindow(_GLFWwindow* window, + const _GLFWwndconfig* wndconfig, + const _GLFWctxconfig* ctxconfig, + const _GLFWfbconfig* fbconfig) +{ + if (!createNativeWindow(window, wndconfig)) + return GLFW_FALSE; + + if (ctxconfig->client != GLFW_NO_API) + { + if (ctxconfig->source == GLFW_NATIVE_CONTEXT_API || + ctxconfig->source == GLFW_EGL_CONTEXT_API) + { + if (!_glfwInitEGL()) + return GLFW_FALSE; + if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig)) + return GLFW_FALSE; + } + else + { + _glfwInputError(GLFW_API_UNAVAILABLE, "Null: EGL not available"); + return GLFW_FALSE; + } + } + + return GLFW_TRUE; +} + +void _glfwPlatformDestroyWindow(_GLFWwindow* window) +{ + if (window->context.destroy) + window->context.destroy(window); + + if (window->vivante.native_window){ + fbDestroyWindow(window->vivante.native_window); + window->vivante.native_window = NULL; + } +} + +void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) +{ +} + +void _glfwPlatformSetWindowIcon(_GLFWwindow* window, int count, + const GLFWimage* images) +{ +} + +void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, + _GLFWmonitor* monitor, + int xpos, int ypos, + int width, int height, + int refreshRate) +{ +} + +void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos) +{ +} + +void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos) +{ +} + +void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height) +{ + if (width) + *width = window->vivante.width; + if (height) + *height = window->vivante.height; +} + +void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) +{ + window->vivante.width = width; + window->vivante.height = height; +} + +void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window, + int minwidth, int minheight, + int maxwidth, int maxheight) +{ +} + +void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int n, int d) +{ +} + +void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height) +{ + if (width) + *width = window->vivante.width; + if (height) + *height = window->vivante.height; +} + +void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window, + int* left, int* top, + int* right, int* bottom) +{ +} + +void _glfwPlatformGetWindowContentScale(_GLFWwindow* window, + float* xscale, float* yscale) +{ + if (xscale) + *xscale = 1.f; + if (yscale) + *yscale = 1.f; +} + +void _glfwPlatformIconifyWindow(_GLFWwindow* window) +{ +} + +void _glfwPlatformRestoreWindow(_GLFWwindow* window) +{ +} + +void _glfwPlatformMaximizeWindow(_GLFWwindow* window) +{ +} + +int _glfwPlatformWindowMaximized(_GLFWwindow* window) +{ + return GLFW_FALSE; +} + +int _glfwPlatformWindowHovered(_GLFWwindow* window) +{ + return GLFW_FALSE; +} + +int _glfwPlatformFramebufferTransparent(_GLFWwindow* window) +{ + return GLFW_FALSE; +} + +void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled) +{ +} + +void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, GLFWbool enabled) +{ +} + +void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled) +{ +} + +float _glfwPlatformGetWindowOpacity(_GLFWwindow* window) +{ + return 1.f; +} + +void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity) +{ +} + +void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window, GLFWbool enabled) +{ +} + +GLFWbool _glfwPlatformRawMouseMotionSupported(void) +{ + return GLFW_FALSE; +} + +void _glfwPlatformShowWindow(_GLFWwindow* window) +{ +} + + +void _glfwPlatformRequestWindowAttention(_GLFWwindow* window) +{ +} + +void _glfwPlatformUnhideWindow(_GLFWwindow* window) +{ +} + +void _glfwPlatformHideWindow(_GLFWwindow* window) +{ +} + +void _glfwPlatformFocusWindow(_GLFWwindow* window) +{ +} + +int _glfwPlatformWindowFocused(_GLFWwindow* window) +{ + return GLFW_FALSE; +} + +int _glfwPlatformWindowIconified(_GLFWwindow* window) +{ + return GLFW_FALSE; +} + +int _glfwPlatformWindowVisible(_GLFWwindow* window) +{ + return GLFW_FALSE; +} + +void _glfwPlatformPollEvents(void) +{ +} + +void _glfwPlatformWaitEvents(void) +{ +} + +void _glfwPlatformWaitEventsTimeout(double timeout) +{ +} + +void _glfwPlatformPostEmptyEvent(void) +{ +} + +void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos) +{ +} + +void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y) +{ +} + +void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) +{ +} + +int _glfwPlatformCreateCursor(_GLFWcursor* cursor, + const GLFWimage* image, + int xhot, int yhot) +{ + return GLFW_TRUE; +} + +int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape) +{ + return GLFW_TRUE; +} + +void _glfwPlatformDestroyCursor(_GLFWcursor* cursor) +{ +} + +void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) +{ +} + +void _glfwPlatformSetClipboardString(const char* string) +{ +} + +const char* _glfwPlatformGetClipboardString(void) +{ + return NULL; +} + +const char* _glfwPlatformGetScancodeName(int scancode) +{ + return ""; +} + +int _glfwPlatformGetKeyScancode(int key) +{ + return -1; +} + +void _glfwPlatformGetRequiredInstanceExtensions(char** extensions) +{ +} + +int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance, + VkPhysicalDevice device, + uint32_t queuefamily) +{ + return GLFW_FALSE; +} + +VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, + _GLFWwindow* window, + const VkAllocationCallbacks* allocator, + VkSurfaceKHR* surface) +{ + // This seems like the most appropriate error to return here + return VK_ERROR_INITIALIZATION_FAILED; +} + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 97da4684c..62dd2665c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,6 +11,12 @@ if (MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) endif() +if (GLFW_USE_VIVANTE) + add_definitions(-DGLFW_INCLUDE_ES2) + add_definitions(-DGL_GLES_PROTOTYPES=0) + link_libraries(-pthread) +endif() + set(GLAD_GL "${GLFW_SOURCE_DIR}/deps/glad/gl.h" "${GLFW_SOURCE_DIR}/deps/glad_gl.c") set(GLAD_VULKAN "${GLFW_SOURCE_DIR}/deps/glad/vulkan.h"