Updated GLFW entry to test for exit.
This commit is contained in:
parent
4b60ddf44d
commit
a797b00a7f
@ -12,22 +12,79 @@
|
|||||||
#include <bgfxplatform.h>
|
#include <bgfxplatform.h>
|
||||||
#include "dbg.h"
|
#include "dbg.h"
|
||||||
|
|
||||||
|
// This is just trivial implementation of GLFW3 integration.
|
||||||
|
// It's here just for testing purpose.
|
||||||
|
|
||||||
namespace entry
|
namespace entry
|
||||||
{
|
{
|
||||||
|
static void errorCb(int _error, const char* _description)
|
||||||
|
{
|
||||||
|
DBG("GLFW error %d: %s", _error, _description);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Context
|
||||||
|
{
|
||||||
|
Context()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int run(int _argc, char** _argv)
|
||||||
|
{
|
||||||
|
glfwSetErrorCallback(errorCb);
|
||||||
|
|
||||||
|
glfwInit();
|
||||||
|
m_window = glfwCreateWindow(1280, 720, "bgfx", NULL, NULL);
|
||||||
|
glfwMakeContextCurrent(m_window);
|
||||||
|
|
||||||
|
glfwSetKeyCallback(m_window, keyCb);
|
||||||
|
|
||||||
|
bgfx::glfwSetWindow(m_window);
|
||||||
|
int result = main(_argc, _argv);
|
||||||
|
|
||||||
|
glfwDestroyWindow(m_window);
|
||||||
|
glfwTerminate();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void keyCb(GLFWwindow* _window, int _key, int _scancode, int _action, int _mods);
|
||||||
|
|
||||||
|
EventQueue m_eventQueue;
|
||||||
|
|
||||||
|
GLFWwindow* m_window;
|
||||||
|
};
|
||||||
|
|
||||||
|
Context s_ctx;
|
||||||
|
|
||||||
|
void Context::keyCb(GLFWwindow* _window, int _key, int _scancode, int _action, int _mods)
|
||||||
|
{
|
||||||
|
BX_UNUSED(_window, _scancode, _mods);
|
||||||
|
if (_key == GLFW_KEY_Q
|
||||||
|
&& _action == GLFW_PRESS
|
||||||
|
&& _mods == GLFW_MOD_CONTROL)
|
||||||
|
{
|
||||||
|
s_ctx.m_eventQueue.postExitEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const Event* poll()
|
const Event* poll()
|
||||||
{
|
{
|
||||||
return NULL;
|
glfwPollEvents();
|
||||||
|
|
||||||
|
if (glfwWindowShouldClose(s_ctx.m_window) )
|
||||||
|
{
|
||||||
|
s_ctx.m_eventQueue.postExitEvent();
|
||||||
|
}
|
||||||
|
return s_ctx.m_eventQueue.poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Event* poll(WindowHandle _handle)
|
const Event* poll(WindowHandle _handle)
|
||||||
{
|
{
|
||||||
BX_UNUSED(_handle);
|
return s_ctx.m_eventQueue.poll(_handle);
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void release(const Event* _event)
|
void release(const Event* _event)
|
||||||
{
|
{
|
||||||
BX_UNUSED(_event);
|
s_ctx.m_eventQueue.release(_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowHandle createWindow(int32_t _x, int32_t _y, uint32_t _width, uint32_t _height, uint32_t _flags, const char* _title)
|
WindowHandle createWindow(int32_t _x, int32_t _y, uint32_t _width, uint32_t _height, uint32_t _flags, const char* _title)
|
||||||
@ -75,12 +132,8 @@ namespace entry
|
|||||||
|
|
||||||
int main(int _argc, char** _argv)
|
int main(int _argc, char** _argv)
|
||||||
{
|
{
|
||||||
glfwInit();
|
using namespace entry;
|
||||||
GLFWwindow *window = glfwCreateWindow(1280, 720, "bgfx", NULL, NULL);
|
return s_ctx.run(_argc, _argv);
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
|
|
||||||
bgfx::glfwSetWindow(window);
|
|
||||||
return entry::main(_argc, _argv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ENTRY_CONFIG_USE_GLFW
|
#endif // ENTRY_CONFIG_USE_GLFW
|
||||||
|
@ -48,7 +48,7 @@ namespace bgfx { namespace gl
|
|||||||
NSWindow* nsWindow = (NSWindow*)g_bgfxNSWindow;
|
NSWindow* nsWindow = (NSWindow*)g_bgfxNSWindow;
|
||||||
m_context = g_bgfxNSGL;
|
m_context = g_bgfxNSGL;
|
||||||
|
|
||||||
if (NULL == m_context)
|
if (NULL == g_bgfxNSGL)
|
||||||
{
|
{
|
||||||
NSOpenGLPixelFormatAttribute profile =
|
NSOpenGLPixelFormatAttribute profile =
|
||||||
#if BGFX_CONFIG_RENDERER_OPENGL >= 31
|
#if BGFX_CONFIG_RENDERER_OPENGL >= 31
|
||||||
@ -95,11 +95,14 @@ namespace bgfx { namespace gl
|
|||||||
|
|
||||||
void GlContext::destroy()
|
void GlContext::destroy()
|
||||||
{
|
{
|
||||||
NSOpenGLView* glView = (NSOpenGLView*)m_view;
|
if (NULL == g_bgfxNSGL)
|
||||||
m_view = 0;
|
{
|
||||||
m_context = 0;
|
NSOpenGLView* glView = (NSOpenGLView*)m_view;
|
||||||
[glView release];
|
[glView release];
|
||||||
|
}
|
||||||
|
|
||||||
|
m_view = 0;
|
||||||
|
m_context = 0;
|
||||||
bx::dlclose(s_opengl);
|
bx::dlclose(s_opengl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user