Added glfw entry.

This commit is contained in:
Branimir Karadžić 2015-03-24 22:19:21 -07:00
parent b2c8c45b02
commit 0da6c77806
8 changed files with 164 additions and 39 deletions

View file

@ -0,0 +1,86 @@
/*
* Copyright 2011-2015 Branimir Karadzic. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include "entry_p.h"
#if ENTRY_CONFIG_USE_GLFW
#define GLFW_DLL
#include <GLFW/glfw3.h>
#include <bgfxplatform.h>
#include "dbg.h"
namespace entry
{
const Event* poll()
{
return NULL;
}
const Event* poll(WindowHandle _handle)
{
BX_UNUSED(_handle);
return NULL;
}
void release(const Event* _event)
{
BX_UNUSED(_event);
}
WindowHandle createWindow(int32_t _x, int32_t _y, uint32_t _width, uint32_t _height, uint32_t _flags, const char* _title)
{
BX_UNUSED(_x, _y, _width, _height, _flags, _title);
WindowHandle handle = { UINT16_MAX };
return handle;
}
void destroyWindow(WindowHandle _handle)
{
BX_UNUSED(_handle);
}
void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y)
{
BX_UNUSED(_handle, _x, _y);
}
void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height)
{
BX_UNUSED(_handle, _width, _height);
}
void setWindowTitle(WindowHandle _handle, const char* _title)
{
BX_UNUSED(_handle, _title);
}
void toggleWindowFrame(WindowHandle _handle)
{
BX_UNUSED(_handle);
}
void toggleFullscreen(WindowHandle _handle)
{
BX_UNUSED(_handle);
}
void setMouseLock(WindowHandle _handle, bool _lock)
{
BX_UNUSED(_handle, _lock);
}
}
int main(int _argc, char** _argv)
{
glfwInit();
GLFWwindow *window = glfwCreateWindow(1280, 720, "bgfx", NULL, NULL);
glfwMakeContextCurrent(window);
bgfx::glfwSetWindow(window);
return entry::main(_argc, _argv);
}
#endif // ENTRY_CONFIG_USE_GLFW

View file

@ -17,8 +17,13 @@
# define ENTRY_CONFIG_USE_SDL 0
#endif // ENTRY_CONFIG_USE_SDL
#if !ENTRY_CONFIG_USE_SDL && \
!defined(ENTRY_CONFIG_USE_NATIVE)
#ifndef ENTRY_CONFIG_USE_GLFW
# define ENTRY_CONFIG_USE_GLFW 0
#endif // ENTRY_CONFIG_USE_GLFW
#if !defined(ENTRY_CONFIG_USE_NATIVE) \
&& !ENTRY_CONFIG_USE_SDL \
&& !ENTRY_CONFIG_USE_GLFW
# define ENTRY_CONFIG_USE_NATIVE 1
#else
# define ENTRY_CONFIG_USE_NATIVE 0

View file

@ -76,7 +76,7 @@ namespace bgfx
namespace bgfx
{
///
void osxSetNSWindow(void* _window);
void osxSetNSWindow(void* _window, void* _nsgl = NULL);
} // namespace bgfx
@ -158,8 +158,9 @@ namespace bgfx
::Window window = glfwGetX11Window(_window);
x11SetDisplayWindow(display, window);
# elif BX_PLATFORM_OSX
void* id = glfwGetCocoaWindow(_window);
osxSetNSWindow(id);
void* window = glfwGetCocoaWindow(_window);
void* nsgl = glfwGetNSGLContext(_window);
osxSetNSWindow(window, nsgl);
# elif BX_PLATFORM_WINDOWS
HWND hwnd = glfwGetWin32Window(_window);
winSetHwnd(hwnd);

View file

@ -31,6 +31,12 @@ project ("example-common")
}
end
if _OPTIONS["with-glfw"] then
defines {
"ENTRY_CONFIG_USE_GLFW=1",
}
end
configuration { "mingw* or vs2008" }
includedirs {
"$(DXSDK_DIR)/include",

View file

@ -18,6 +18,11 @@ newoption {
description = "Enable SDL entry.",
}
newoption {
trigger = "with-glfw",
description = "Enable GLFW entry.",
}
newoption {
trigger = "with-shared-lib",
description = "Enable building shared library.",
@ -123,6 +128,21 @@ function exampleProject(_name)
configuration {}
end
if _OPTIONS["with-glfw"] then
defines { "ENTRY_CONFIG_USE_GLFW=1" }
links {
"glfw3"
}
configuration { "osx" }
linkoptions {
"-framework CoreVideo",
"-framework IOKit",
}
configuration {}
end
if _OPTIONS["with-ovr"] then
links {
"winmm",

View file

@ -52,10 +52,12 @@ namespace bgfx
}
#elif BX_PLATFORM_OSX
void* g_bgfxNSWindow = NULL;
void* g_bgfxNSGL = NULL;
void osxSetNSWindow(void* _window)
void osxSetNSWindow(void* _window, void* _nsgl)
{
g_bgfxNSWindow = _window;
g_bgfxNSGL = _nsgl;
}
#elif BX_PLATFORM_WINDOWS
::HWND g_bgfxHwnd = NULL;

View file

@ -206,6 +206,7 @@ namespace bgfx
extern uint32_t g_bgfxX11Window;
#elif BX_PLATFORM_OSX
extern void* g_bgfxNSWindow;
extern void* g_bgfxNSGL;
#elif BX_PLATFORM_WINDOWS
extern ::HWND g_bgfxHwnd;
#elif BX_PLATFORM_WINRT

View file

@ -46,7 +46,10 @@ namespace bgfx { namespace gl
BX_CHECK(NULL != s_opengl, "OpenGL dynamic library is not found!");
NSWindow* nsWindow = (NSWindow*)g_bgfxNSWindow;
m_context = g_bgfxNSGL;
if (NULL == m_context)
{
NSOpenGLPixelFormatAttribute profile =
#if BGFX_CONFIG_RENDERER_OPENGL >= 31
NSOpenGLProfileVersion3_2Core
@ -85,6 +88,7 @@ namespace bgfx { namespace gl
m_view = glView;
m_context = glContext;
}
import();
}