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 # define ENTRY_CONFIG_USE_SDL 0
#endif // ENTRY_CONFIG_USE_SDL #endif // ENTRY_CONFIG_USE_SDL
#if !ENTRY_CONFIG_USE_SDL && \ #ifndef ENTRY_CONFIG_USE_GLFW
!defined(ENTRY_CONFIG_USE_NATIVE) # 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 # define ENTRY_CONFIG_USE_NATIVE 1
#else #else
# define ENTRY_CONFIG_USE_NATIVE 0 # define ENTRY_CONFIG_USE_NATIVE 0

View file

@ -76,7 +76,7 @@ namespace bgfx
namespace bgfx namespace bgfx
{ {
/// ///
void osxSetNSWindow(void* _window); void osxSetNSWindow(void* _window, void* _nsgl = NULL);
} // namespace bgfx } // namespace bgfx
@ -155,11 +155,12 @@ namespace bgfx
{ {
# if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD # if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD
::Display* display = glfwGetX11Display(); ::Display* display = glfwGetX11Display();
::Window window = glfwGetX11Window(_window); ::Window window = glfwGetX11Window(_window);
x11SetDisplayWindow(display, window); x11SetDisplayWindow(display, window);
# elif BX_PLATFORM_OSX # elif BX_PLATFORM_OSX
void* id = glfwGetCocoaWindow(_window); void* window = glfwGetCocoaWindow(_window);
osxSetNSWindow(id); void* nsgl = glfwGetNSGLContext(_window);
osxSetNSWindow(window, nsgl);
# elif BX_PLATFORM_WINDOWS # elif BX_PLATFORM_WINDOWS
HWND hwnd = glfwGetWin32Window(_window); HWND hwnd = glfwGetWin32Window(_window);
winSetHwnd(hwnd); winSetHwnd(hwnd);

View file

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

View file

@ -18,6 +18,11 @@ newoption {
description = "Enable SDL entry.", description = "Enable SDL entry.",
} }
newoption {
trigger = "with-glfw",
description = "Enable GLFW entry.",
}
newoption { newoption {
trigger = "with-shared-lib", trigger = "with-shared-lib",
description = "Enable building shared library.", description = "Enable building shared library.",
@ -123,6 +128,21 @@ function exampleProject(_name)
configuration {} configuration {}
end 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 if _OPTIONS["with-ovr"] then
links { links {
"winmm", "winmm",

View file

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

View file

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

View file

@ -35,7 +35,7 @@ namespace bgfx { namespace gl
{ {
} }
}; };
static void* s_opengl = NULL; static void* s_opengl = NULL;
void GlContext::create(uint32_t _width, uint32_t _height) void GlContext::create(uint32_t _width, uint32_t _height)
@ -46,45 +46,49 @@ namespace bgfx { namespace gl
BX_CHECK(NULL != s_opengl, "OpenGL dynamic library is not found!"); BX_CHECK(NULL != s_opengl, "OpenGL dynamic library is not found!");
NSWindow* nsWindow = (NSWindow*)g_bgfxNSWindow; NSWindow* nsWindow = (NSWindow*)g_bgfxNSWindow;
m_context = g_bgfxNSGL;
NSOpenGLPixelFormatAttribute profile = if (NULL == m_context)
{
NSOpenGLPixelFormatAttribute profile =
#if BGFX_CONFIG_RENDERER_OPENGL >= 31 #if BGFX_CONFIG_RENDERER_OPENGL >= 31
NSOpenGLProfileVersion3_2Core NSOpenGLProfileVersion3_2Core
#else #else
NSOpenGLProfileVersionLegacy NSOpenGLProfileVersionLegacy
#endif // BGFX_CONFIG_RENDERER_OPENGL >= 31 #endif // BGFX_CONFIG_RENDERER_OPENGL >= 31
; ;
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = { NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = {
NSOpenGLPFAOpenGLProfile, profile, NSOpenGLPFAOpenGLProfile, profile,
NSOpenGLPFAColorSize, 24, NSOpenGLPFAColorSize, 24,
NSOpenGLPFAAlphaSize, 8, NSOpenGLPFAAlphaSize, 8,
NSOpenGLPFADepthSize, 24, NSOpenGLPFADepthSize, 24,
NSOpenGLPFAStencilSize, 8, NSOpenGLPFAStencilSize, 8,
NSOpenGLPFADoubleBuffer, true, NSOpenGLPFADoubleBuffer, true,
NSOpenGLPFAAccelerated, true, NSOpenGLPFAAccelerated, true,
NSOpenGLPFANoRecovery, true, NSOpenGLPFANoRecovery, true,
0, 0, 0, 0,
}; };
NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes]; NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes];
BGFX_FATAL(NULL != pixelFormat, Fatal::UnableToInitialize, "Failed to initialize pixel format."); BGFX_FATAL(NULL != pixelFormat, Fatal::UnableToInitialize, "Failed to initialize pixel format.");
NSRect glViewRect = [[nsWindow contentView] bounds]; NSRect glViewRect = [[nsWindow contentView] bounds];
NSOpenGLView* glView = [[NSOpenGLView alloc] initWithFrame:glViewRect pixelFormat:pixelFormat]; NSOpenGLView* glView = [[NSOpenGLView alloc] initWithFrame:glViewRect pixelFormat:pixelFormat];
[pixelFormat release];
[nsWindow setContentView:glView];
NSOpenGLContext* glContext = [glView openGLContext];
BGFX_FATAL(NULL != glContext, Fatal::UnableToInitialize, "Failed to initialize GL context.");
[glContext makeCurrentContext]; [pixelFormat release];
GLint interval = 0; [nsWindow setContentView:glView];
[glContext setValues:&interval forParameter:NSOpenGLCPSwapInterval];
NSOpenGLContext* glContext = [glView openGLContext];
m_view = glView; BGFX_FATAL(NULL != glContext, Fatal::UnableToInitialize, "Failed to initialize GL context.");
m_context = glContext;
[glContext makeCurrentContext];
GLint interval = 0;
[glContext setValues:&interval forParameter:NSOpenGLCPSwapInterval];
m_view = glView;
m_context = glContext;
}
import(); import();
} }