Previous 199869 Revisions Next

r32205 Friday 19th September, 2014 at 13:57:07 UTC by Miodrag Milanović
(OSD BRANCH) Updated BGFX to latest, x64 builds defaults to Win7
[/branches/osd/src/lib/bgfx]renderer_d3d11.cpp renderer_d3d11.h
[/branches/osd/src/lib/bgfx/common/entry]entry.cpp entry.h entry_android.cpp entry_nacl.cpp entry_p.h entry_windows.cpp input.cpp
[/branches/osd/src/lib/bgfx/include]bgfx.c99.h
[/branches/osd/src/lib/bx]platform.h
[/branches/osd/src/osd/windows]winprefix.h

branches/osd/src/osd/windows/winprefix.h
r32204r32205
66//
77//============================================================
88
9#define _WIN32_WINNT 0x0501
10
9#ifdef PTR64
10#define _WIN32_WINNT 0x0601 // Windows 7
11#else
12#define _WIN32_WINNT 0x0501 // Windows XP
13#endif
1114#ifdef _MSC_VER
1215#include <assert.h>
1316#include <malloc.h>
branches/osd/src/lib/bx/platform.h
r32204r32205
4242#elif defined(__clang__)
4343// clang defines __GNUC__
4444#   undef BX_COMPILER_CLANG
45#   define BX_COMPILER_CLANG 1
45#   define BX_COMPILER_CLANG (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
4646#elif defined(__GNUC__)
4747#   undef BX_COMPILER_GCC
4848#   define BX_COMPILER_GCC (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
r32204r32205
163163            BX_STRINGIZE(__GNUC_MINOR__) "." \
164164            BX_STRINGIZE(__GNUC_PATCHLEVEL__)
165165#elif BX_COMPILER_CLANG
166#   define BX_COMPILER_NAME "Clang"
166#   define BX_COMPILER_NAME "Clang " \
167            BX_STRINGIZE(__clang_major__) "." \
168            BX_STRINGIZE(__clang_minor__) "." \
169            BX_STRINGIZE(__clang_patchlevel__)
167170#elif BX_COMPILER_MSVC
168171#   if BX_COMPILER_MSVC >= 1800
169172#      define BX_COMPILER_NAME "MSVC 12.0"
branches/osd/src/lib/bgfx/include/bgfx.c99.h
r32204r32205
2828
2929typedef enum bgfx_access
3030{
31   BGFX_ACCESS_READ,
32   BGFX_ACCESS_WRITE,
33   BGFX_ACCESS_READWRITE,
31    BGFX_ACCESS_READ,
32    BGFX_ACCESS_WRITE,
33    BGFX_ACCESS_READWRITE,
3434
35   BGFX_ACCESS_COUNT
35    BGFX_ACCESS_COUNT
3636
3737} bgfx_access_t;
3838
branches/osd/src/lib/bgfx/renderer_d3d11.h
r32204r32205
4444
4545      Ty* find(uint64_t _id)
4646      {
47         HashMap::iterator it = m_hashMap.find(_id);
47         typename HashMap::iterator it = m_hashMap.find(_id);
4848         if (it != m_hashMap.end() )
4949         {
5050            return it->second;
r32204r32205
5555
5656      void invalidate(uint64_t _id)
5757      {
58         HashMap::iterator it = m_hashMap.find(_id);
58         typename HashMap::iterator it = m_hashMap.find(_id);
5959         if (it != m_hashMap.end() )
6060         {
6161            DX_RELEASE_WARNONLY(it->second, 0);
r32204r32205
6565
6666      void invalidate()
6767      {
68         for (HashMap::iterator it = m_hashMap.begin(), itEnd = m_hashMap.end(); it != itEnd; ++it)
68         for (typename HashMap::iterator it = m_hashMap.begin(), itEnd = m_hashMap.end(); it != itEnd; ++it)
6969         {
7070            DX_CHECK_REFCOUNT(it->second, 1);
7171            it->second->Release();
branches/osd/src/lib/bgfx/renderer_d3d11.cpp
r32204r32205
115115      D3D11_CULL_BACK,
116116   };
117117
118   static DXGI_FORMAT s_colorFormat[] =
119   {
120      DXGI_FORMAT_UNKNOWN, // ignored
121      DXGI_FORMAT_R8G8B8A8_UNORM,
122      DXGI_FORMAT_R10G10B10A2_UNORM,
123      DXGI_FORMAT_R16G16B16A16_UNORM,
124      DXGI_FORMAT_R16G16B16A16_FLOAT,
125      DXGI_FORMAT_R16_FLOAT,
126      DXGI_FORMAT_R32_FLOAT,
127   };
128
129118   static const DXGI_FORMAT s_depthFormat[] =
130119   {
131120      DXGI_FORMAT_UNKNOWN,           // ignored
r32204r32205
21052094               , regIndex
21062095               , regCount
21072096               );
2097            BX_UNUSED(kind);
21082098         }
21092099
21102100         m_constantBuffer->finish();
r32204r32205
27672757                     commitShaderConstants();
27682758                  }
27692759               }
2770
2760               BX_UNUSED(programChanged);
27712761               ID3D11UnorderedAccessView* uav[BGFX_MAX_COMPUTE_BINDINGS] = {};
27722762               ID3D11ShaderResourceView*  srv[BGFX_MAX_COMPUTE_BINDINGS] = {};
27732763               ID3D11SamplerState*    sampler[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS] = {};
branches/osd/src/lib/bgfx/common/entry/entry_nacl.cpp
r32204r32205
5656      BX_UNUSED(_event);
5757   }
5858
59   void setWindowSize(uint32_t _width, uint32_t _height)
59   void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height)
6060   {
61      BX_UNUSED(_width, _height);
61      BX_UNUSED(_handle, _width, _height);
6262   }
6363
64   void setWindowTitle(const char* _title)
64   void setWindowTitle(WindowHandle _handle, const char* _title)
6565   {
66      BX_UNUSED(_title);
66      BX_UNUSED(_handle, _title);
6767   }
6868
69   void toggleWindowFrame()
69   void toggleWindowFrame(WindowHandle _handle)
7070   {
71      BX_UNUSED(_handle);
7172   }
7273
73   void setMouseLock(bool _lock)
74   void setMouseLock(WindowHandle _handle, bool _lock)
7475   {
75      BX_UNUSED(_lock);
76      BX_UNUSED(_handle, _lock);
7677   }
7778
7879   template<typename Type>
r32204r32205
9596   {
9697      NaclContext()
9798      {
98         const char* argv[1] = { "nacl.nexe" };
99         static const char* argv[1] = { "nacl.nexe" };
99100         m_mte.m_argc = 1;
100101         m_mte.m_argv = const_cast<char**>(argv);
101102
branches/osd/src/lib/bgfx/common/entry/input.cpp
r32204r32205
235235   if (s_input.m_mouse.m_lock != _lock)
236236   {
237237      s_input.m_mouse.m_lock = _lock;
238      entry::setMouseLock(_lock);
238      entry::WindowHandle defaultWindow = { 0 };
239      entry::setMouseLock(defaultWindow, _lock);
239240      if (_lock)
240241      {
241242         s_input.m_mouse.m_norm[0] = 0.0f;
branches/osd/src/lib/bgfx/common/entry/entry.cpp
r32204r32205
134134
135135      inputAddBindings("bindings", s_bindings);
136136
137      entry::setWindowTitle(bx::baseName(_argv[0]));
137      entry::WindowHandle defaultWindow = { 0 };
138      entry::setWindowTitle(defaultWindow, bx::baseName(_argv[0]));
138139
139140      int32_t result = ::_main_(_argc, _argv);
140141
r32204r32205
258259      s_debug = _debug;
259260      s_reset = _reset;
260261
262      WindowHandle handle = { UINT16_MAX };
263
261264      bool mouseLock = inputIsMouseLocked();
262265
263266      if (NULL != _keyboard)
r32204r32205
282285            case Event::Mouse:
283286               {
284287                  const MouseEvent* mouse = static_cast<const MouseEvent*>(ev);
288                  handle = mouse->m_handle;
285289
286290                  if (mouse->m_move)
287291                  {
r32204r32205
312316            case Event::Key:
313317               {
314318                  const KeyEvent* key = static_cast<const KeyEvent*>(ev);
319                  handle = key->m_handle;
320
315321                  inputSetKeyState(key->m_key, key->m_modifiers, key->m_down);
316322
317323                  if (NULL != _keyboard)
r32204r32205
329335            case Event::Size:
330336               {
331337                  const SizeEvent* size = static_cast<const SizeEvent*>(ev);
332                  _width = size->m_width;
338                  handle  = size->m_handle;
339                  _width  = size->m_width;
333340                  _height = size->m_height;
334                  _reset = !s_reset; // force reset
341                  _reset = !s_reset; // force reset
335342               }
336343               break;
337344
345            case Event::Window:
346               break;
347
338348            default:
339349               break;
340350            }
r32204r32205
344354
345355      } while (NULL != ev);
346356
347      if (_reset != s_reset)
357      if (handle.idx == 0
358      &&  _reset != s_reset)
348359      {
349360         _reset = s_reset;
350361         bgfx::reset(_width, _height, _reset);
branches/osd/src/lib/bgfx/common/entry/entry_android.cpp
r32204r32205
205205      s_ctx.m_eventQueue.release(_event);
206206   }
207207
208   void setWindowSize(uint32_t _width, uint32_t _height)
208   void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height)
209209   {
210      BX_UNUSED(_width, _height);
210      BX_UNUSED(_handle, _width, _height);
211211   }
212212
213   void setWindowTitle(const char* _title)
213   void setWindowTitle(WindowHandle _handle, const char* _title)
214214   {
215      BX_UNUSED(_title);
215      BX_UNUSED(_handle, _title);
216216   }
217217
218   void toggleWindowFrame()
218   void toggleWindowFrame(WindowHandle _handle)
219219   {
220      BX_UNUSED(_handle);
220221   }
221222
222   void setMouseLock(bool _lock)
223   void setMouseLock(WindowHandle _handle, bool _lock)
223224   {
224      BX_UNUSED(_lock);
225      BX_UNUSED(_handle, _lock);
225226   }
226227
227228   int32_t MainThreadEntry::threadFunc(void* _userData)
branches/osd/src/lib/bgfx/common/entry/entry.h
r32204r32205
1616
1717namespace entry
1818{
19   struct WindowHandle { uint16_t idx; };
20
1921   struct MouseButton
2022   {
2123      enum Enum
r32204r32205
160162   bx::FileReaderI* getFileReader();
161163   bx::FileWriterI* getFileWriter();
162164
163   void setWindowSize(uint32_t _width, uint32_t _height);
164   void setWindowTitle(const char* _title);
165   void toggleWindowFrame();
166   void setMouseLock(bool _lock);
165   WindowHandle createWindow(uint32_t _width, uint32_t _height, const char* _title);
166   void destroyWindow(WindowHandle _handle);
167   void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height);
168   void setWindowTitle(WindowHandle _handle, const char* _title);
169   void toggleWindowFrame(WindowHandle _handle);
170   void setMouseLock(WindowHandle _handle, bool _lock);
167171
168172} // namespace entry
169173
branches/osd/src/lib/bgfx/common/entry/entry_windows.cpp
r32204r32205
1111
1212#include <bx/uint32_t.h>
1313#include <bx/thread.h>
14#include <bx/mutex.h>
15#include <bx/handlealloc.h>
1416
1517#include <windowsx.h>
1618
17#define WM_USER_SET_WINDOW_SIZE     (WM_USER+0)
18#define WM_USER_TOGGLE_WINDOW_FRAME (WM_USER+1)
19#define WM_USER_MOUSE_LOCK          (WM_USER+2)
19#define WM_USER_CREATE_WINDOW       (WM_USER+0)
20#define WM_USER_SET_WINDOW_SIZE     (WM_USER+1)
21#define WM_USER_TOGGLE_WINDOW_FRAME (WM_USER+2)
22#define WM_USER_MOUSE_LOCK          (WM_USER+3)
2023
2124namespace entry
2225{
r32204r32205
6972      Context()
7073         : m_mz(0)
7174         , m_frame(true)
72         , m_mouseLock(false)
75         , m_mouseLock(NULL)
7376         , m_init(false)
7477         , m_exit(false)
7578      {
r32204r32205
159162         WNDCLASSEX wnd;
160163         memset(&wnd, 0, sizeof(wnd) );
161164         wnd.cbSize = sizeof(wnd);
162         wnd.lpfnWndProc = DefWindowProc;
163         wnd.hInstance = instance;
164         wnd.hIcon = LoadIcon(NULL, IDI_APPLICATION);
165         wnd.hCursor = LoadCursor(NULL, IDC_ARROW);
166         wnd.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
167         wnd.lpszClassName = "bgfx_letterbox";
168         wnd.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
169         RegisterClassExA(&wnd);
170
171         memset(&wnd, 0, sizeof(wnd) );
172         wnd.cbSize = sizeof(wnd);
173165         wnd.style = CS_HREDRAW | CS_VREDRAW;
174166         wnd.lpfnWndProc = wndProc;
175167         wnd.hInstance = instance;
r32204r32205
179171         wnd.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
180172         RegisterClassExA(&wnd);
181173
182         HWND hwnd = CreateWindowA("bgfx_letterbox"
174         m_windowAlloc.alloc();
175         m_hwnd[0] = CreateWindowA("bgfx"
183176            , "BGFX"
184            , WS_POPUP|WS_SYSMENU
185            , -32000
186            , -32000
187            , 0
188            , 0
189            , NULL
190            , NULL
191            , instance
192            , 0
193            );
194
195         m_hwnd = CreateWindowA("bgfx"
196            , "BGFX"
197177            , WS_OVERLAPPEDWINDOW|WS_VISIBLE
198178            , 0
199179            , 0
200180            , ENTRY_DEFAULT_WIDTH
201181            , ENTRY_DEFAULT_HEIGHT
202            , hwnd
203182            , NULL
183            , NULL
204184            , instance
205185            , 0
206186            );
207187
208         bgfx::winSetHwnd(m_hwnd);
188         bgfx::winSetHwnd(m_hwnd[0]);
209189
210         adjust(ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT, true);
190         adjust(m_hwnd[0], ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT, true);
211191         m_width = ENTRY_DEFAULT_WIDTH;
212192         m_height = ENTRY_DEFAULT_HEIGHT;
213193         m_oldWidth = ENTRY_DEFAULT_WIDTH;
r32204r32205
221201         thread.init(mte.threadFunc, &mte);
222202         m_init = true;
223203
224         m_eventQueue.postSizeEvent(m_width, m_height);
204         m_eventQueue.postSizeEvent(findHandle(m_hwnd[0]), m_width, m_height);
225205
226206         MSG msg;
227207         msg.message = WM_NULL;
r32204r32205
239219
240220         thread.shutdown();
241221
242         DestroyWindow(m_hwnd);
243         DestroyWindow(hwnd);
222         DestroyWindow(m_hwnd[0]);
244223
245224         return 0;
246225      }
r32204r32205
251230         {
252231            switch (_id)
253232            {
233            case WM_USER_CREATE_WINDOW:
234               {
235                  uint32_t width  = GET_X_LPARAM(_lparam);
236                  uint32_t height = GET_Y_LPARAM(_lparam);
237                  HWND hwnd = CreateWindowA("bgfx"
238                     , ""
239                     , WS_OVERLAPPEDWINDOW|WS_VISIBLE
240                     , 0
241                     , 0
242                     , width
243                     , height
244                     , NULL
245                     , NULL
246                     , (HINSTANCE)GetModuleHandle(NULL)
247                     , 0
248                     );
249
250                  m_hwnd[_wparam] = hwnd;
251                  WindowHandle handle = { (uint16_t)_wparam };
252                  m_eventQueue.postWindowEvent(handle, hwnd);
253               }
254               break;
255
254256            case WM_USER_SET_WINDOW_SIZE:
255257               {
256                  uint32_t width = GET_X_LPARAM(_lparam);
258                  uint32_t width = GET_X_LPARAM(_lparam);
257259                  uint32_t height = GET_Y_LPARAM(_lparam);
258                  adjust(width, height, true);
260                  adjust(m_hwnd[_wparam], width, height, true);
259261               }
260262               break;
261263
r32204r32205
266268                     m_oldWidth = m_width;
267269                     m_oldHeight = m_height;
268270                  }
269                  adjust(m_oldWidth, m_oldHeight, !m_frame);
271                  adjust(m_hwnd[_wparam], m_oldWidth, m_oldHeight, !m_frame);
270272               }
271273               break;
272274
273275            case WM_USER_MOUSE_LOCK:
274               setMouseLock(!!_lparam);
276               setMouseLock(_hwnd, !!_lparam);
275277               break;
276278
277279            case WM_DESTROY:
r32204r32205
279281
280282            case WM_QUIT:
281283            case WM_CLOSE:
282               m_exit = true;
283               m_eventQueue.postExitEvent();
284               m_eventQueue.postWindowEvent(findHandle(_hwnd) );
285               if (_hwnd == m_hwnd[0])
286               {
287                  m_exit = true;
288                  m_eventQueue.postExitEvent();
289               }
284290               break;
285291
286292            case WM_SIZING:
287293               {
288294                  RECT& rect = *(RECT*)_lparam;
289                  uint32_t width = rect.right - rect.left - m_frameWidth;
290                  uint32_t height = rect.bottom - rect.top - m_frameHeight;
295                  uint32_t width  = rect.right  - rect.left - m_frameWidth;
296                  uint32_t height = rect.bottom - rect.top  - m_frameHeight;
291297
292                  //Recalculate size according to aspect ratio
298                  // Recalculate size according to aspect ratio
293299                  switch (_wparam)
294300                  {
295301                  case WMSZ_LEFT:
296302                  case WMSZ_RIGHT:
297303                     {
298304                        float aspectRatio = 1.0f/m_aspectRatio;
299                        width = bx::uint32_max(ENTRY_DEFAULT_WIDTH/4, width);
305                        width = bx::uint32_max(ENTRY_DEFAULT_WIDTH/4, width);
300306                        height = uint32_t(float(width)*aspectRatio);
301307                     }
302308                     break;
r32204r32205
305311                     {
306312                        float aspectRatio = m_aspectRatio;
307313                        height = bx::uint32_max(ENTRY_DEFAULT_HEIGHT/4, height);
308                        width = uint32_t(float(height)*aspectRatio);
314                        width = uint32_t(float(height)*aspectRatio);
309315                     }
310316                     break;
311317                  }
312318
313                  //Recalculate position using different anchor points
319                  // Recalculate position using different anchor points
314320                  switch(_wparam)
315321                  {
316322                  case WMSZ_LEFT:
317323                  case WMSZ_TOPLEFT:
318324                  case WMSZ_BOTTOMLEFT:
319                     rect.left = rect.right - width - m_frameWidth;
320                     rect.bottom = rect.top + height + m_frameHeight;
325                     rect.left   = rect.right - width  - m_frameWidth;
326                     rect.bottom = rect.top   + height + m_frameHeight;
321327                     break;
322328
323329                  default:
324                     rect.right = rect.left + width + m_frameWidth;
325                     rect.bottom = rect.top + height + m_frameHeight;
330                     rect.right  = rect.left + width  + m_frameWidth;
331                     rect.bottom = rect.top  + height + m_frameHeight;
326332                     break;
327333                  }
328334
329                  m_eventQueue.postSizeEvent(m_width, m_height);
335                  m_eventQueue.postSizeEvent(findHandle(_hwnd), m_width, m_height);
330336               }
331337               return 0;
332338
333339            case WM_SIZE:
334340               {
335                  uint32_t width = GET_X_LPARAM(_lparam);
341                  uint32_t width = GET_X_LPARAM(_lparam);
336342                  uint32_t height = GET_Y_LPARAM(_lparam);
337343
338                  m_width = width;
344                  m_width = width;
339345                  m_height = height;
340                  m_eventQueue.postSizeEvent(m_width, m_height);
346                  m_eventQueue.postSizeEvent(findHandle(_hwnd), m_width, m_height);
341347               }
342348               break;
343349
r32204r32205
361367                  int32_t mx = GET_X_LPARAM(_lparam);
362368                  int32_t my = GET_Y_LPARAM(_lparam);
363369
364                  if (m_mouseLock)
370                  if (_hwnd == m_mouseLock)
365371                  {
366372                     mx -= m_mx;
367373                     my -= m_my;
r32204r32205
372378                        break;
373379                     }
374380
375                     setMousePos(m_mx, m_my);
381                     setMousePos(_hwnd, m_mx, m_my);
376382                  }
377383
378                  m_eventQueue.postMouseEvent(mx, my, m_mz);
384                  m_eventQueue.postMouseEvent(findHandle(_hwnd), mx, my, m_mz);
379385               }
380386               break;
381387
382388            case WM_MOUSEWHEEL:
383389               {
384390                  POINT pt = { GET_X_LPARAM(_lparam), GET_Y_LPARAM(_lparam) };
385                  ScreenToClient(m_hwnd, &pt);
391                  ScreenToClient(_hwnd, &pt);
386392                  int32_t mx = pt.x;
387393                  int32_t my = pt.y;
388394                  m_mz += GET_WHEEL_DELTA_WPARAM(_wparam);
389                  m_eventQueue.postMouseEvent(mx, my, m_mz);
395                  m_eventQueue.postMouseEvent(findHandle(_hwnd), mx, my, m_mz);
390396               }
391397               break;
392398
r32204r32205
396402               {
397403                  int32_t mx = GET_X_LPARAM(_lparam);
398404                  int32_t my = GET_Y_LPARAM(_lparam);
399                  m_eventQueue.postMouseEvent(mx, my, m_mz, MouseButton::Left, _id == WM_LBUTTONDOWN);
405                  m_eventQueue.postMouseEvent(findHandle(_hwnd), mx, my, m_mz, MouseButton::Left, _id == WM_LBUTTONDOWN);
400406               }
401407               break;
402408
r32204r32205
406412               {
407413                  int32_t mx = GET_X_LPARAM(_lparam);
408414                  int32_t my = GET_Y_LPARAM(_lparam);
409                  m_eventQueue.postMouseEvent(mx, my, m_mz, MouseButton::Middle, _id == WM_MBUTTONDOWN);
415                  m_eventQueue.postMouseEvent(findHandle(_hwnd), mx, my, m_mz, MouseButton::Middle, _id == WM_MBUTTONDOWN);
410416               }
411417               break;
412418
r32204r32205
416422               {
417423                  int32_t mx = GET_X_LPARAM(_lparam);
418424                  int32_t my = GET_Y_LPARAM(_lparam);
419                  m_eventQueue.postMouseEvent(mx, my, m_mz, MouseButton::Right, _id == WM_RBUTTONDOWN);
425                  m_eventQueue.postMouseEvent(findHandle(_hwnd), mx, my, m_mz, MouseButton::Right, _id == WM_RBUTTONDOWN);
420426               }
421427               break;
422428
r32204r32205
428434                  uint8_t modifiers = translateKeyModifiers();
429435                  Key::Enum key = translateKey(_wparam);
430436
437                  WindowHandle handle = findHandle(_hwnd);
438
431439                  if (Key::Print == key
432440                  &&  0x3 == ( (uint32_t)(_lparam)>>30) )
433441                  {
r32204r32205
435443                     // key state bit is set to 1 and transition state bit is set to 1.
436444                     //
437445                     // http://msdn.microsoft.com/en-us/library/windows/desktop/ms646280%28v=vs.85%29.aspx
438                     m_eventQueue.postKeyEvent(key, modifiers, true);
446                     m_eventQueue.postKeyEvent(handle, key, modifiers, true);
439447                  }
440448
441                  m_eventQueue.postKeyEvent(key, modifiers, _id == WM_KEYDOWN || _id == WM_SYSKEYDOWN);
449                  m_eventQueue.postKeyEvent(handle, key, modifiers, _id == WM_KEYDOWN || _id == WM_SYSKEYDOWN);
442450               }
443451               break;
444452
r32204r32205
450458         return DefWindowProc(_hwnd, _id, _wparam, _lparam);
451459      }
452460
453      void adjust(uint32_t _width, uint32_t _height, bool _windowFrame)
461      WindowHandle findHandle(HWND _hwnd)
454462      {
463         bx::LwMutexScope scope(m_lock);
464         for (uint32_t ii = 0, num = m_windowAlloc.getNumHandles(); ii < num; ++ii)
465         {
466            uint16_t idx = m_windowAlloc.getHandleAt(ii);
467            if (_hwnd == m_hwnd[idx])
468            {
469               WindowHandle handle = { idx };
470               return handle;
471            }
472         }
473
474         WindowHandle invalid = { UINT16_MAX };
475         return invalid;
476      }
477
478      void adjust(HWND _hwnd, uint32_t _width, uint32_t _height, bool _windowFrame)
479      {
455480         m_width = _width;
456481         m_height = _height;
457482         m_aspectRatio = float(_width)/float(_height);
458483
459         ShowWindow(m_hwnd, SW_SHOWNORMAL);
484         ShowWindow(_hwnd, SW_SHOWNORMAL);
460485         RECT rect;
461486         RECT newrect = {0, 0, (LONG)_width, (LONG)_height};
462487         DWORD style = WS_POPUP|WS_SYSMENU;
463488
464489         if (m_frame)
465490         {
466            GetWindowRect(m_hwnd, &m_rect);
467            m_style = GetWindowLong(m_hwnd, GWL_STYLE);
491            GetWindowRect(_hwnd, &m_rect);
492            m_style = GetWindowLong(_hwnd, GWL_STYLE);
468493         }
469494
470495         if (_windowFrame)
r32204r32205
475500         else
476501         {
477502#if defined(__MINGW32__)
478            rect = m_rect;
503            rect = m_rect;
479504            style = m_style;
480505#else
481            HMONITOR monitor = MonitorFromWindow(m_hwnd, MONITOR_DEFAULTTONEAREST);
506            HMONITOR monitor = MonitorFromWindow(_hwnd, MONITOR_DEFAULTTONEAREST);
482507            MONITORINFO mi;
483508            mi.cbSize = sizeof(mi);
484509            GetMonitorInfo(monitor, &mi);
r32204r32205
487512#endif // !defined(__MINGW__)
488513         }
489514
490         SetWindowLong(m_hwnd, GWL_STYLE, style);
515         SetWindowLong(_hwnd, GWL_STYLE, style);
491516         uint32_t prewidth = newrect.right - newrect.left;
492517         uint32_t preheight = newrect.bottom - newrect.top;
493518         AdjustWindowRect(&newrect, style, FALSE);
494519         m_frameWidth = (newrect.right - newrect.left) - prewidth;
495520         m_frameHeight = (newrect.bottom - newrect.top) - preheight;
496         UpdateWindow(m_hwnd);
521         UpdateWindow(_hwnd);
497522
498523         if (rect.left == -32000
499524         ||  rect.top == -32000)
r32204r32205
517542            top = newrect.top+(newrect.bottom-newrect.top-height)/2;
518543         }
519544
520         HWND parent = GetWindow(m_hwnd, GW_OWNER);
545         HWND parent = GetWindow(_hwnd, GW_OWNER);
521546         if (NULL != parent)
522547         {
523548            if (_windowFrame)
r32204r32205
544569            }
545570         }
546571
547         SetWindowPos(m_hwnd
572         SetWindowPos(_hwnd
548573            , HWND_TOP
549574            , left
550575            , top
r32204r32205
553578            , SWP_SHOWWINDOW
554579            );
555580
556         ShowWindow(m_hwnd, SW_RESTORE);
581         ShowWindow(_hwnd, SW_RESTORE);
557582
558583         m_frame = _windowFrame;
559584      }
560585
561      void setMousePos(int32_t _mx, int32_t _my)
586      void setMousePos(HWND _hwnd, int32_t _mx, int32_t _my)
562587      {
563588         POINT pt = { _mx, _my };
564         ClientToScreen(m_hwnd, &pt);
589         ClientToScreen(_hwnd, &pt);
565590         SetCursorPos(pt.x, pt.y);
566591      }
567592
568      void setMouseLock(bool _lock)
593      void setMouseLock(HWND _hwnd, bool _lock)
569594      {
570         if (_lock != m_mouseLock)
595         if (_hwnd != m_mouseLock)
571596         {
572597            if (_lock)
573598            {
574599               m_mx = m_width/2;
575600               m_my = m_height/2;
576601               ShowCursor(false);
577               setMousePos(m_mx, m_my);
602               setMousePos(_hwnd, m_mx, m_my);
578603            }
579604            else
580605            {
581               setMousePos(m_mx, m_my);
606               setMousePos(_hwnd, m_mx, m_my);
582607               ShowCursor(true);
583608            }
584609
585            m_mouseLock = _lock;
610            m_mouseLock = _hwnd;
586611         }
587612      }
588613
589614      static LRESULT CALLBACK wndProc(HWND _hwnd, UINT _id, WPARAM _wparam, LPARAM _lparam);
590615
591616      EventQueue m_eventQueue;
617      bx::LwMutex m_lock;
592618
593      HWND m_hwnd;
619      bx::HandleAllocT<ENTRY_CONFIG_MAX_WINDOWS> m_windowAlloc;
620
621      HWND m_hwnd[ENTRY_CONFIG_MAX_WINDOWS];
594622      RECT m_rect;
595623      DWORD m_style;
596624      uint32_t m_width;
r32204r32205
606634      int32_t m_mz;
607635
608636      bool m_frame;
609      bool m_mouseLock;
637      HWND m_mouseLock;
610638      bool m_init;
611639      bool m_exit;
612640
r32204r32205
629657      s_ctx.m_eventQueue.release(_event);
630658   }
631659
632   void setWindowSize(uint32_t _width, uint32_t _height)
660   WindowHandle createWindow(uint32_t _width, uint32_t _height, const char* /*_title*/)
633661   {
634      PostMessage(s_ctx.m_hwnd, WM_USER_SET_WINDOW_SIZE, 0, (_height<<16) | (_width&0xffff) );
662      bx::LwMutexScope scope(s_ctx.m_lock);
663      WindowHandle handle = { s_ctx.m_windowAlloc.alloc() };
664
665      if (UINT16_MAX != handle.idx)
666      {
667         PostMessage(s_ctx.m_hwnd[0], WM_USER_CREATE_WINDOW, handle.idx, (_height<<16) | (_width&0xffff) );
668      }
669
670      return handle;
635671   }
636672
637   void setWindowTitle(const char* _title)
673   void destroyWindow(WindowHandle _handle)
638674   {
639      SetWindowTextA(s_ctx.m_hwnd, _title);
640      SetWindowTextA(GetWindow(s_ctx.m_hwnd, GW_HWNDNEXT), _title);
675      PostMessage(s_ctx.m_hwnd[_handle.idx], WM_CLOSE, _handle.idx, 0);
641676   }
642677
643   void toggleWindowFrame()
678   void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height)
644679   {
645      PostMessage(s_ctx.m_hwnd, WM_USER_TOGGLE_WINDOW_FRAME, 0, 0);
680      PostMessage(s_ctx.m_hwnd[_handle.idx], WM_USER_SET_WINDOW_SIZE, _handle.idx, (_height<<16) | (_width&0xffff) );
646681   }
647682
648   void setMouseLock(bool _lock)
683   void setWindowTitle(WindowHandle _handle, const char* _title)
649684   {
650      PostMessage(s_ctx.m_hwnd, WM_USER_MOUSE_LOCK, 0, _lock);
685      SetWindowTextA(s_ctx.m_hwnd[_handle.idx], _title);
686//      SetWindowTextA(GetWindow(s_ctx.m_hwnd[_handle.idx], GW_HWNDNEXT), _title);
651687   }
652688
689   void toggleWindowFrame(WindowHandle _handle)
690   {
691      PostMessage(s_ctx.m_hwnd[_handle.idx], WM_USER_TOGGLE_WINDOW_FRAME, _handle.idx, 0);
692   }
693
694   void setMouseLock(WindowHandle _handle, bool _lock)
695   {
696      PostMessage(s_ctx.m_hwnd[_handle.idx], WM_USER_MOUSE_LOCK, _handle.idx, _lock);
697   }
698
653699   int32_t MainThreadEntry::threadFunc(void* _userData)
654700   {
655701      MainThreadEntry* self = (MainThreadEntry*)_userData;
656702      int32_t result = main(self->m_argc, self->m_argv);
657      PostMessage(s_ctx.m_hwnd, WM_QUIT, 0, 0);
703      PostMessage(s_ctx.m_hwnd[0], WM_QUIT, 0, 0);
658704      return result;
659705   }
660706
branches/osd/src/lib/bgfx/common/entry/entry_p.h
r32204r32205
2121#   define ENTRY_CONFIG_USE_NATIVE 0
2222#endif // ...
2323
24#ifndef ENTRY_CONFIG_MAX_WINDOWS
25#   define ENTRY_CONFIG_MAX_WINDOWS 8
26#endif // ENTRY_CONFIG_MAX_WINDOWS
27
2428#if !defined(ENTRY_DEFAULT_WIDTH) && !defined(ENTRY_DEFAULT_HEIGHT)
2529#   define ENTRY_DEFAULT_WIDTH  1280
2630#   define ENTRY_DEFAULT_HEIGHT 720
r32204r32205
2832#   error "Both ENTRY_DEFAULT_WIDTH and ENTRY_DEFAULT_HEIGHT must be defined."
2933#endif // ENTRY_DEFAULT_WIDTH
3034
35#define ENTRY_IMPLEMENT_EVENT(_class, _type) \
36         _class(WindowHandle _handle) : Event(_type, _handle) {}
37
3138namespace entry
3239{
3340   int main(int _argc, char** _argv);
r32204r32205
4047         Key,
4148         Mouse,
4249         Size,
50         Window,
4351      };
4452
53      Event(Enum _type)
54         : m_type(_type)
55      {
56         m_handle.idx = UINT16_MAX;
57      }
58
59      Event(Enum _type, WindowHandle _handle)
60         : m_type(_type)
61         , m_handle(_handle)
62      {
63      }
64
4565      Event::Enum m_type;
66      WindowHandle m_handle;
4667   };
4768
4869   struct KeyEvent : public Event
4970   {
71      ENTRY_IMPLEMENT_EVENT(KeyEvent, Event::Key);
72
5073      Key::Enum m_key;
5174      uint8_t m_modifiers;
5275      bool m_down;
r32204r32205
5477
5578   struct MouseEvent : public Event
5679   {
80      ENTRY_IMPLEMENT_EVENT(MouseEvent, Event::Mouse);
81
5782      int32_t m_mx;
5883      int32_t m_my;
5984      int32_t m_mz;
r32204r32205
6489
6590   struct SizeEvent : public Event
6691   {
92      ENTRY_IMPLEMENT_EVENT(SizeEvent, Event::Size);
93
6794      uint32_t m_width;
6895      uint32_t m_height;
6996   };
7097
98   struct WindowEvent : public Event
99   {
100      ENTRY_IMPLEMENT_EVENT(WindowEvent, Event::Window);
101
102      void* m_nwh;
103   };
104
71105   const Event* poll();
72106   void release(const Event* _event);
73107
r32204r32205
76110   public:
77111      void postExitEvent()
78112      {
79         Event* ev = new Event;
80         ev->m_type = Event::Exit;
113         Event* ev = new Event(Event::Exit);
81114         m_queue.push(ev);
82115      }
83116
84      void postKeyEvent(Key::Enum _key, uint8_t _modifiers, bool _down)
117      void postKeyEvent(WindowHandle _handle, Key::Enum _key, uint8_t _modifiers, bool _down)
85118      {
86         KeyEvent* ev = new KeyEvent;
87         ev->m_type = Event::Key;
88         ev->m_key = _key;
119         KeyEvent* ev = new KeyEvent(_handle);
120         ev->m_key       = _key;
89121         ev->m_modifiers = _modifiers;
90         ev->m_down = _down;
122         ev->m_down      = _down;
91123         m_queue.push(ev);
92124      }
93125
94      void postMouseEvent(int32_t _mx, int32_t _my, int32_t _mz)
126      void postMouseEvent(WindowHandle _handle, int32_t _mx, int32_t _my, int32_t _mz)
95127      {
96         MouseEvent* ev = new MouseEvent;
97         ev->m_type = Event::Mouse;
98         ev->m_mx = _mx;
99         ev->m_my = _my;
100         ev->m_mz = _mz;
128         MouseEvent* ev = new MouseEvent(_handle);
129         ev->m_mx     = _mx;
130         ev->m_my     = _my;
131         ev->m_mz     = _mz;
101132         ev->m_button = MouseButton::None;
102         ev->m_down = false;
103         ev->m_move = true;
133         ev->m_down   = false;
134         ev->m_move   = true;
104135         m_queue.push(ev);
105136      }
106137
107      void postMouseEvent(int32_t _mx, int32_t _my, int32_t _mz, MouseButton::Enum _button, bool _down)
138      void postMouseEvent(WindowHandle _handle, int32_t _mx, int32_t _my, int32_t _mz, MouseButton::Enum _button, bool _down)
108139      {
109         MouseEvent* ev = new MouseEvent;
110         ev->m_type = Event::Mouse;
111         ev->m_mx = _mx;
112         ev->m_my = _my;
113         ev->m_mz = _mz;
140         MouseEvent* ev = new MouseEvent(_handle);
141         ev->m_mx     = _mx;
142         ev->m_my     = _my;
143         ev->m_mz     = _mz;
114144         ev->m_button = _button;
115         ev->m_down = _down;
116         ev->m_move = false;
145         ev->m_down   = _down;
146         ev->m_move   = false;
117147         m_queue.push(ev);
118148      }
119149
120      void postSizeEvent(uint32_t _width, uint32_t _height)
150      void postSizeEvent(WindowHandle _handle, uint32_t _width, uint32_t _height)
121151      {
122         SizeEvent* ev = new SizeEvent;
123         ev->m_type = Event::Size;
124         ev->m_width = _width;
152         SizeEvent* ev = new SizeEvent(_handle);
153         ev->m_width  = _width;
125154         ev->m_height = _height;
126155         m_queue.push(ev);
127156      }
128157
158      void postWindowEvent(WindowHandle _handle, void* _nwh = NULL)
159      {
160         WindowEvent* ev = new WindowEvent(_handle);
161         ev->m_nwh = _nwh;
162         m_queue.push(ev);
163      }
164
129165      const Event* poll()
130166      {
131167         return m_queue.pop();

Previous 199869 Revisions Next


© 1997-2024 The MAME Team