1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
/*
* Copyright 2011-2016 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
*/
#include "entry_p.h"
#if ENTRY_CONFIG_USE_GLFW
#if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
# define GLFW_EXPOSE_NATIVE_X11
# define GLFW_EXPOSE_NATIVE_GLX
#elif BX_PLATFORM_OSX
# define GLFW_EXPOSE_NATIVE_COCOA
# define GLFW_EXPOSE_NATIVE_NSGL
#elif BX_PLATFORM_WINDOWS
# define GLFW_EXPOSE_NATIVE_WIN32
# define GLFW_EXPOSE_NATIVE_WGL
#endif //
#define GLFW_DLL
#include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h>
#include <bgfx/bgfxplatform.h>
#include "dbg.h"
// This is just trivial implementation of GLFW3 integration.
// It's here just for testing purpose.
namespace entry
{
inline void glfwSetWindow(GLFWwindow* _window)
{
bgfx::PlatformData pd;
# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
pd.ndt = glfwGetX11Display();
pd.nwh = (void*)(uintptr_t)glfwGetGLXWindow(_window);
pd.context = glfwGetGLXContext(_window);
# elif BX_PLATFORM_OSX
pd.ndt = NULL;
pd.nwh = glfwGetCocoaWindow(_window);
pd.context = glfwGetNSGLContext(_window);
# elif BX_PLATFORM_WINDOWS
pd.ndt = NULL;
pd.nwh = glfwGetWin32Window(_window);
pd.context = NULL;
# endif // BX_PLATFORM_WINDOWS
pd.backBuffer = NULL;
pd.backBufferDS = NULL;
bgfx::setPlatformData(pd);
}
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);
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()
{
glfwPollEvents();
if (glfwWindowShouldClose(s_ctx.m_window) )
{
s_ctx.m_eventQueue.postExitEvent();
}
return s_ctx.m_eventQueue.poll();
}
const Event* poll(WindowHandle _handle)
{
return s_ctx.m_eventQueue.poll(_handle);
}
void release(const Event* _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)
{
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)
{
using namespace entry;
return s_ctx.run(_argc, _argv);
}
#endif // ENTRY_CONFIG_USE_GLFW
|