Previous 199869 Revisions Next

r31764 Monday 25th August, 2014 at 06:49:55 UTC by Miodrag Milanović
(OSD BRANCH) Sync with latest bgfx code (nw)
[/branches/osd/src/lib/bgfx]bgfx.cpp bgfx_p.h config.h glcontext_egl.cpp glcontext_glx.cpp glcontext_nsgl.mm renderer_gl.h
[/branches/osd/src/lib/bgfx/common/entry]entry_android.cpp entry_ios.mm entry_x11.cpp*
[/branches/osd/src/lib/bgfx/common/nanovg]nanovg_bgfx.cpp
[/branches/osd/src/lib/bgfx/include]bgfxplatform.c99.h bgfxplatform.h
[/branches/osd/src/lib/bx]bx.h config.h* float4_t.h macros.h os.h platform.h readerwriter.h timer.h

branches/osd/src/lib/bx/bx.h
r31763r31764
99#include <stdint.h> // uint32_t
1010#include <stdlib.h> // size_t
1111
12#include "platform.h"
12#include "config.h"
1313#include "macros.h"
1414
1515namespace bx
branches/osd/src/lib/bx/float4_t.h
r31763r31764
1818#elif 0 // BX_COMPILER_CLANG
1919#   include "float4_langext.h"
2020#else
21//#   pragma message("************************************\nUsing SIMD reference implementation!\n************************************")
21#   ifndef BX_FLOAT4_WARN_REFERENCE_IMPL
22#      define BX_FLOAT4_WARN_REFERENCE_IMPL 0
23#   endif // BX_FLOAT4_WARN_REFERENCE_IMPL
24
25#   if BX_FLOAT4_WARN_REFERENCE_IMPL
26#      pragma message("************************************\nUsing SIMD reference implementation!\n************************************")
27#   endif // BX_FLOAT4_WARN_REFERENCE_IMPL
28
2229#   include "float4_ref.h"
2330#endif //
2431
branches/osd/src/lib/bx/timer.h
r31763r31764
1212#   include <time.h> // clock, clock_gettime
1313#elif BX_PLATFORM_EMSCRIPTEN
1414#   include <emscripten.h>
15#elif  BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX || BX_PLATFORM_NACL || BX_PLATFORM_OSX || BX_PLATFORM_IOS || BX_PLATFORM_QNX
16#   include <sys/time.h> // gettimeofday
1715#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT
1816#   include <windows.h>
17#else
18#   include <sys/time.h> // gettimeofday
1919#endif // BX_PLATFORM_
2020
2121namespace bx
branches/osd/src/lib/bx/macros.h
r31763r31764
146146#   define BX_WARN(_condition, ...) BX_NOOP()
147147#endif // BX_CHECK
148148
149#ifndef BX_CONFIG_ALLOCATOR_DEBUG
150#   define BX_CONFIG_ALLOCATOR_DEBUG 0
151#endif // BX_CONFIG_DEBUG_ALLOC
152
153#ifndef BX_CONFIG_ALLOCATOR_CRT
154#   define BX_CONFIG_ALLOCATOR_CRT 1
155#endif // BX_CONFIG_ALLOCATOR_CRT
156
157#ifndef  BX_CONFIG_SPSCQUEUE_USE_MUTEX
158#   define BX_CONFIG_SPSCQUEUE_USE_MUTEX 0
159#endif // BX_CONFIG_SPSCQUEUE_USE_MUTEX
160
161#ifndef BX_CONFIG_CRT_FILE_READER_WRITER
162#   define BX_CONFIG_CRT_FILE_READER_WRITER (0 \
163            || BX_PLATFORM_ANDROID \
164            || BX_PLATFORM_FREEBSD \
165            || BX_PLATFORM_IOS \
166            || BX_PLATFORM_LINUX \
167            || BX_PLATFORM_OSX \
168            || BX_PLATFORM_QNX \
169            || BX_PLATFORM_WINDOWS \
170            ? 1 : 0)
171#endif // BX_CONFIG_CRT_FILE_READER_WRITER
172
173#ifndef BX_CONFIG_SEMAPHORE_PTHREAD
174#   define BX_CONFIG_SEMAPHORE_PTHREAD (BX_PLATFORM_OSX || BX_PLATFORM_IOS)
175#endif // BX_CONFIG_SEMAPHORE_PTHREAD
176
177#ifndef BX_CONFIG_SUPPORTS_THREADING
178#   define BX_CONFIG_SUPPORTS_THREADING !(BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_WINRT)
179#endif // BX_CONFIG_SUPPORTS_THREADING
180
181149#endif // BX_MACROS_H_HEADER_GUARD
branches/osd/src/lib/bx/readerwriter.h
r31763r31764
22 * Copyright 2010-2013 Branimir Karadzic. All rights reserved.
33 * License: http://www.opensource.org/licenses/BSD-2-Clause
44 */
5
5
66#ifndef BX_READERWRITER_H_HEADER_GUARD
77#define BX_READERWRITER_H_HEADER_GUARD
88
branches/osd/src/lib/bx/config.h
r0r31764
1/*
2 * Copyright 2010-2013 Branimir Karadzic. All rights reserved.
3 * License: http://www.opensource.org/licenses/BSD-2-Clause
4 */
5
6#ifndef BX_CONFIG_H_HEADER_GUARD
7#define BX_CONFIG_H_HEADER_GUARD
8
9#include "platform.h"
10
11#ifndef BX_CONFIG_ALLOCATOR_DEBUG
12#   define BX_CONFIG_ALLOCATOR_DEBUG 0
13#endif // BX_CONFIG_DEBUG_ALLOC
14
15#ifndef BX_CONFIG_ALLOCATOR_CRT
16#   define BX_CONFIG_ALLOCATOR_CRT 1
17#endif // BX_CONFIG_ALLOCATOR_CRT
18
19#ifndef  BX_CONFIG_SPSCQUEUE_USE_MUTEX
20#   define BX_CONFIG_SPSCQUEUE_USE_MUTEX 0
21#endif // BX_CONFIG_SPSCQUEUE_USE_MUTEX
22
23#ifndef BX_CONFIG_CRT_FILE_READER_WRITER
24#   define BX_CONFIG_CRT_FILE_READER_WRITER (0 \
25            || BX_PLATFORM_ANDROID \
26            || BX_PLATFORM_FREEBSD \
27            || BX_PLATFORM_IOS \
28            || BX_PLATFORM_LINUX \
29            || BX_PLATFORM_OSX \
30            || BX_PLATFORM_QNX \
31            || BX_PLATFORM_RPI \
32            || BX_PLATFORM_WINDOWS \
33            ? 1 : 0)
34#endif // BX_CONFIG_CRT_FILE_READER_WRITER
35
36#ifndef BX_CONFIG_SEMAPHORE_PTHREAD
37#   define BX_CONFIG_SEMAPHORE_PTHREAD (BX_PLATFORM_OSX || BX_PLATFORM_IOS)
38#endif // BX_CONFIG_SEMAPHORE_PTHREAD
39
40#ifndef BX_CONFIG_SUPPORTS_THREADING
41#   define BX_CONFIG_SUPPORTS_THREADING !(BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_WINRT)
42#endif // BX_CONFIG_SUPPORTS_THREADING
43
44#endif // BX_CONFIG_H_HEADER_GUARD
Property changes on: branches/osd/src/lib/bx/config.h
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native
branches/osd/src/lib/bx/os.h
r31763r31764
1616   || BX_PLATFORM_IOS \
1717   || BX_PLATFORM_LINUX \
1818   || BX_PLATFORM_NACL \
19   || BX_PLATFORM_OSX
19   || BX_PLATFORM_OSX \
20   || BX_PLATFORM_RPI
2021
2122#   include <sched.h> // sched_yield
2223#   if BX_PLATFORM_FREEBSD || BX_PLATFORM_IOS || BX_PLATFORM_NACL || BX_PLATFORM_OSX
r31763r31764
3031#      include <dlfcn.h> // dlopen, dlclose, dlsym
3132#   endif // BX_PLATFORM_NACL
3233
33#   if BX_PLATFORM_LINUX
34#   if BX_PLATFORM_LINUX || BX_PLATFORM_RPI
3435#      include <unistd.h> // syscall
3536#      include <sys/syscall.h>
36#   endif // BX_PLATFORM_LINUX
37#   endif // BX_PLATFORM_LINUX || BX_PLATFORM_RPI
3738
3839#   if BX_PLATFORM_ANDROID
3940#      include "debug.h" // getTid is not implemented...
r31763r31764
7980   {
8081#if BX_PLATFORM_WINDOWS
8182      return ::GetCurrentThreadId();
82#elif BX_PLATFORM_LINUX
83#elif BX_PLATFORM_LINUX || BX_PLATFORM_RPI
8384      return (pid_t)::syscall(SYS_gettid);
8485#elif BX_PLATFORM_IOS || BX_PLATFORM_OSX
8586      return (mach_port_t)::pthread_mach_thread_np(pthread_self() );
branches/osd/src/lib/bx/platform.h
r31763r31764
1818#define BX_PLATFORM_NACL       0
1919#define BX_PLATFORM_OSX        0
2020#define BX_PLATFORM_QNX        0
21#define BX_PLATFORM_RPI        0
2122#define BX_PLATFORM_WINDOWS    0
2223#define BX_PLATFORM_WINRT      0
2324#define BX_PLATFORM_XBOX360    0
r31763r31764
6768#      undef BX_PLATFORM_WINRT
6869#      define BX_PLATFORM_WINRT 1
6970#   endif
71#elif defined(__VCCOREVER__)
72// RaspberryPi compiler defines __linux__
73#   undef BX_PLATFORM_RPI
74#   define BX_PLATFORM_RPI 1
7075#elif defined(__native_client__)
7176// NaCl compiler defines __linux__
7277#   undef BX_PLATFORM_NACL
r31763r31764
106111                  || BX_PLATFORM_NACL \
107112                  || BX_PLATFORM_OSX \
108113                  || BX_PLATFORM_QNX \
114                  || BX_PLATFORM_RPI \
109115                  )
110116
111117// http://sourceforge.net/apps/mediawiki/predef/index.php?title=Architectures
112#if defined(__arm__) || (defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP))
118#if defined(__arm__) || defined(_M_ARM)
113119#   undef BX_CPU_ARM
114120#   define BX_CPU_ARM 1
115121#   define BX_CACHE_LINE_SIZE 64
r31763r31764
175181#   define BX_PLATFORM_NAME "OSX"
176182#elif BX_PLATFORM_QNX
177183#   define BX_PLATFORM_NAME "QNX"
184#elif BX_PLATFORM_RPI
185#   define BX_PLATFORM_NAME "RaspberryPi"
178186#elif BX_PLATFORM_WINDOWS
179187#   define BX_PLATFORM_NAME "Windows"
180188#elif BX_PLATFORM_WINRT
branches/osd/src/lib/bgfx/glcontext_egl.cpp
r31763r31764
55
66#include "bgfx_p.h"
77
8#if (BGFX_CONFIG_RENDERER_OPENGLES|BGFX_CONFIG_RENDERER_OPENGL)
8#if (BGFX_CONFIG_RENDERER_OPENGLES || BGFX_CONFIG_RENDERER_OPENGL)
99#   include "renderer_gl.h"
1010
1111#   if BGFX_USE_EGL
1212
13#      if BX_PLATFORM_RPI
14#         include <bcm_host.h>
15#      endif // BX_PLATFORM_RPI
16
1317#ifndef EGL_CONTEXT_MAJOR_VERSION_KHR
1418#   define EGL_CONTEXT_MAJOR_VERSION_KHR EGL_CONTEXT_CLIENT_VERSION
1519#endif // EGL_CONTEXT_MAJOR_VERSION_KHR
r31763r31764
9498#   define GL_IMPORT(_optional, _proto, _func, _import) _proto _func = NULL
9599#   include "glimports.h"
96100
101#   if BX_PLATFORM_RPI
102   static EGL_DISPMANX_WINDOW_T s_dispmanWindow;
103
104   void x11SetDisplayWindow(::Display* _display, ::Window _window)
105   {
106      // Noop for now...
107      BX_UNUSED(_display, _window);
108   }
109#   endif // BX_PLATFORM_RPI
110
97111   void GlContext::create(uint32_t _width, uint32_t _height)
98112   {
113#   if BX_PLATFORM_RPI
114      bcm_host_init();
115#   endif // BX_PLATFORM_RPI
116
99117      m_eglLibrary = eglOpen();
100118
101119      BX_UNUSED(_width, _height);
r31763r31764
137155      eglGetConfigAttrib(m_display, config, EGL_NATIVE_VISUAL_ID, &format);
138156      ANativeWindow_setBuffersGeometry(g_bgfxAndroidWindow, _width, _height, format);
139157      nwt = g_bgfxAndroidWindow;
158#   elif BX_PLATFORM_RPI
159      DISPMANX_DISPLAY_HANDLE_T dispmanDisplay = vc_dispmanx_display_open(0);
160      DISPMANX_UPDATE_HANDLE_T  dispmanUpdate  = vc_dispmanx_update_start(0);
161
162      VC_RECT_T dstRect = { 0, 0, _width,        _height       };
163      VC_RECT_T srcRect = { 0, 0, _width  << 16, _height << 16 };
164
165      DISPMANX_ELEMENT_HANDLE_T dispmanElement = vc_dispmanx_element_add(dispmanUpdate
166         , dispmanDisplay
167         , 0
168         , &dstRect
169         , 0
170         , &srcRect
171         , DISPMANX_PROTECTION_NONE
172         , NULL
173         , NULL
174         , DISPMANX_NO_ROTATE
175         );
176
177      s_dispmanWindow.element = dispmanElement;
178      s_dispmanWindow.width   = _width;
179      s_dispmanWindow.height  = _height;
180      nwt = &s_dispmanWindow;
181
182      vc_dispmanx_update_submit_sync(dispmanUpdate);
140183#   endif // BX_PLATFORM_ANDROID
141184
142185      m_surface = eglCreateWindowSurface(m_display, config, nwt, NULL);
r31763r31764
183226      m_context = NULL;
184227
185228      eglClose(m_eglLibrary);
229
230#   if BX_PLATFORM_RPI
231      bcm_host_deinit();
232#   endif // BX_PLATFORM_RPI
186233   }
187234
188235   void GlContext::resize(uint32_t /*_width*/, uint32_t /*_height*/, bool _vsync)
r31763r31764
227274} // namespace bgfx
228275
229276#   endif // BGFX_USE_EGL
230#endif // (BGFX_CONFIG_RENDERER_OPENGLES|BGFX_CONFIG_RENDERER_OPENGL)
277#endif // (BGFX_CONFIG_RENDERER_OPENGLES || BGFX_CONFIG_RENDERER_OPENGL)
branches/osd/src/lib/bgfx/config.h
r31763r31764
66#ifndef BGFX_CONFIG_H_HEADER_GUARD
77#define BGFX_CONFIG_H_HEADER_GUARD
88
9#include <bx/platform.h>
9#include <bx/config.h>
1010
1111#ifndef BGFX_CONFIG_DEBUG
1212#   define BGFX_CONFIG_DEBUG 0
r31763r31764
4747               || BX_PLATFORM_ANDROID \
4848               || BX_PLATFORM_IOS \
4949               || BX_PLATFORM_QNX \
50               || BX_PLATFORM_RPI \
5051               ? 1 : 0)
5152#   endif // BGFX_CONFIG_RENDERER_OPENGLES
5253
r31763r31764
121122                  || BX_PLATFORM_NACL \
122123                  || BX_PLATFORM_OSX \
123124                  || BX_PLATFORM_QNX \
125                  || BX_PLATFORM_RPI \
124126                  || BX_PLATFORM_WINDOWS \
125127                  || BX_PLATFORM_XBOX360 \
126128                  ? 1 : 0) )
branches/osd/src/lib/bgfx/bgfx.cpp
r31763r31764
130130   };
131131
132132#ifndef BGFX_CONFIG_MEMORY_TRACKING
133#   define BGFX_CONFIG_MEMORY_TRACKING (BGFX_CONFIG_DEBUG && BX_CONFIG_SUPPORTED_THREADING)
133#   define BGFX_CONFIG_MEMORY_TRACKING (BGFX_CONFIG_DEBUG && BX_CONFIG_SUPPORTS_THREADING)
134134#endif // BGFX_CONFIG_MEMORY_TRACKING
135135
136136   class AllocatorStub : public bx::ReallocatorI
r31763r31764
13691369             ||  BX_PLATFORM_EMSCRIPTEN
13701370             ||  BX_PLATFORM_IOS
13711371             ||  BX_PLATFORM_NACL
1372             ||  BX_PLATFORM_RPI
13721373             ) )
13731374         {
13741375            _type = RendererType::OpenGLES;
r31763r31764
33193320   bgfx::iosSetEaglLayer(_layer);
33203321}
33213322
3322#elif BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD
3323#elif BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX || BX_PLATFORM_RPI
33233324BGFX_C_API void bgfx_x11_set_display_window(::Display* _display, ::Window _window)
33243325{
33253326   bgfx::x11SetDisplayWindow(_display, _window);
branches/osd/src/lib/bgfx/renderer_gl.h
r31763r31764
66#ifndef BGFX_RENDERER_GL_H_HEADER_GUARD
77#define BGFX_RENDERER_GL_H_HEADER_GUARD
88
9#define BGFX_USE_EGL (BGFX_CONFIG_RENDERER_OPENGLES && (BX_PLATFORM_ANDROID || BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_QNX || BX_PLATFORM_WINDOWS) )
9#define BGFX_USE_EGL (BGFX_CONFIG_RENDERER_OPENGLES && (BX_PLATFORM_ANDROID || BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_QNX || BX_PLATFORM_RPI || BX_PLATFORM_WINDOWS) )
1010#define BGFX_USE_WGL (BGFX_CONFIG_RENDERER_OPENGL && BX_PLATFORM_WINDOWS)
1111#define BGFX_USE_GL_DYNAMIC_LIB (BX_PLATFORM_LINUX || BX_PLATFORM_OSX || BX_PLATFORM_WINDOWS)
1212
branches/osd/src/lib/bgfx/include/bgfxplatform.h
r31763r31764
5050
5151} // namespace bgfx
5252
53#elif BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD
53#elif BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX || BX_PLATFORM_RPI
5454#   include <X11/Xlib.h>
5555
5656namespace bgfx
branches/osd/src/lib/bgfx/include/bgfxplatform.c99.h
r31763r31764
4646 */
4747BGFX_C_API void bgfx_ios_set_eagl_layer(void* _layer);
4848
49#elif BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD
49#elif BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX || BX_PLATFORM_RPI
5050#    include <X11/Xlib.h>
5151
5252/**
branches/osd/src/lib/bgfx/common/nanovg/nanovg_bgfx.cpp
r31763r31764
963963      bgfx::destroyUniform(gl->u_params);
964964      bgfx::destroyUniform(gl->s_tex);
965965
966      if (bgfx::isValid(gl->u_halfTexel) )
967      {
968         bgfx::destroyUniform(gl->u_halfTexel);
969      }
970
966971      for (uint32_t ii = 0, num = gl->ntextures; ii < num; ++ii)
967972      {
968973         if (bgfx::isValid(gl->textures[ii].id) )
branches/osd/src/lib/bgfx/common/entry/entry_android.cpp
r31763r31764
2020
2121extern "C"
2222{
23#pragma GCC diagnostic push
24#pragma GCC diagnostic ignored "-Wunused-parameter"
2325#include <android_native_app_glue.c>
26#pragma GCC diagnostic pop
2427} // extern "C"
2528
2629namespace entry
branches/osd/src/lib/bgfx/common/entry/entry_ios.mm
r31763r31764
6565         chdir(path);
6666      }
6767      CFRelease(resourcesURL);
68       
68
6969      MainThreadEntry* self = (MainThreadEntry*)_userData;
7070      int32_t result = main(self->m_argc, self->m_argv);
7171      return result;
r31763r31764
140140      m_displayLink = [self.window.screen displayLinkWithTarget:self selector:@selector(renderFrame)];
141141      //[m_displayLink setFrameInterval:1];
142142      //[m_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
143//      [m_displayLink addToRunLoop:[NSRunLoop currentRunLoop]];
143      //      [m_displayLink addToRunLoop:[NSRunLoop currentRunLoop]];
144144      [m_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
145145   }
146146}
r31763r31764
161161
162162- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
163163{
164    UITouch *touch = [[event allTouches] anyObject];
165    CGPoint touchLocation = [touch locationInView:self];
166   
167    s_ctx->m_eventQueue.postMouseEvent(touchLocation.x, touchLocation.y);
168    s_ctx->m_eventQueue.postMouseEvent(touchLocation.x, touchLocation.y, MouseButton::Left, true);
164   BX_UNUSED(touches);
165   UITouch *touch = [[event allTouches] anyObject];
166   CGPoint touchLocation = [touch locationInView:self];
167
168   s_ctx->m_eventQueue.postMouseEvent(touchLocation.x, touchLocation.y, 0);
169   s_ctx->m_eventQueue.postMouseEvent(touchLocation.x, touchLocation.y, 0, MouseButton::Left, true);
169170}
170171
171172- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
172173{
173    UITouch *touch = [[event allTouches] anyObject];
174    CGPoint touchLocation = [touch locationInView:self];
175    s_ctx->m_eventQueue.postMouseEvent(touchLocation.x, touchLocation.y, MouseButton::Left, false);
174   BX_UNUSED(touches);
175   UITouch *touch = [[event allTouches] anyObject];
176   CGPoint touchLocation = [touch locationInView:self];
177   s_ctx->m_eventQueue.postMouseEvent(touchLocation.x, touchLocation.y, 0, MouseButton::Left, false);
176178}
177179
178180- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
179181{
180    UITouch *touch = [[event allTouches] anyObject];
181    CGPoint touchLocation = [touch locationInView:self];
182    s_ctx->m_eventQueue.postMouseEvent(touchLocation.x, touchLocation.y);
182   BX_UNUSED(touches);
183   UITouch *touch = [[event allTouches] anyObject];
184   CGPoint touchLocation = [touch locationInView:self];
185   s_ctx->m_eventQueue.postMouseEvent(touchLocation.x, touchLocation.y, 0);
183186}
184187
185188- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
186189{
187    UITouch *touch = [[event allTouches] anyObject];
188    CGPoint touchLocation = [touch locationInView:self];
189    s_ctx->m_eventQueue.postMouseEvent(touchLocation.x, touchLocation.y, MouseButton::Left, false);
190   BX_UNUSED(touches);
191   UITouch *touch = [[event allTouches] anyObject];
192   CGPoint touchLocation = [touch locationInView:self];
193   s_ctx->m_eventQueue.postMouseEvent(touchLocation.x, touchLocation.y, 0, MouseButton::Left, false);
190194}
191195
192196@end
r31763r31764
217221
218222   [m_window addSubview: m_view];
219223   [m_window makeKeyAndVisible];
220   
221    //float scaleFactor = [[UIScreen mainScreen] scale]; // should use this, but ui is too small on ipad retina
222    float scaleFactor = 1.0f;
223    [m_view setContentScaleFactor: scaleFactor ];
224224
225   //float scaleFactor = [[UIScreen mainScreen] scale]; // should use this, but ui is too small on ipad retina
226   float scaleFactor = 1.0f;
227   [m_view setContentScaleFactor: scaleFactor ];
228
225229   s_ctx = new Context((uint32_t)(scaleFactor*rect.size.width), (uint32_t)(scaleFactor*rect.size.height));
226230   return YES;
227231}
branches/osd/src/lib/bgfx/common/entry/entry_x11.cpp
r0r31764
1/*
2 * Copyright 2011-2014 Branimir Karadzic. All rights reserved.
3 * License: http://www.opensource.org/licenses/BSD-2-Clause
4 */
5
6#include "entry_p.h"
7
8#if ENTRY_CONFIG_USE_NATIVE && (BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX || BX_PLATFORM_RPI)
9
10#define XK_MISCELLANY
11#define XK_LATIN1
12#include <X11/keysymdef.h>
13#include <bgfxplatform.h> // will include X11 which #defines None... Don't mess with order of includes.
14
15#undef None
16#include <bx/thread.h>
17#include <bx/os.h>
18#include <string.h> // memset
19
20namespace entry
21{
22   static uint8_t s_translateKey[512];
23
24   static void initTranslateKey(uint16_t _xk, Key::Enum _key)
25   {
26      _xk += 256;
27      BX_CHECK(_xk < BX_COUNTOF(s_translateKey), "Out of bounds %d.", _xk);
28      s_translateKey[_xk&0x1ff] = (uint8_t)_key;
29   }
30
31   Key::Enum fromXk(uint16_t _xk)
32   {
33      _xk += 256;
34      return 512 > _xk ? (Key::Enum)s_translateKey[_xk] : Key::None;
35   }
36
37   struct MainThreadEntry
38   {
39      int m_argc;
40      char** m_argv;
41
42      static int32_t threadFunc(void* _userData);
43   };
44
45   struct Context
46   {
47      Context()
48         : m_modifiers(Modifier::None)
49         , m_exit(false)
50      {
51         memset(s_translateKey, 0, sizeof(s_translateKey) );
52         initTranslateKey(XK_Escape,       Key::Esc);
53         initTranslateKey(XK_Return,       Key::Return);
54         initTranslateKey(XK_Tab,          Key::Tab);
55         initTranslateKey(XK_BackSpace,    Key::Backspace);
56         initTranslateKey(XK_space,        Key::Space);
57         initTranslateKey(XK_Up,           Key::Up);
58         initTranslateKey(XK_Down,         Key::Down);
59         initTranslateKey(XK_Left,         Key::Left);
60         initTranslateKey(XK_Right,        Key::Right);
61         initTranslateKey(XK_Page_Up,      Key::PageUp);
62         initTranslateKey(XK_Page_Down,    Key::PageUp);
63         initTranslateKey(XK_Home,         Key::Home);
64         initTranslateKey(XK_KP_End,       Key::End);
65         initTranslateKey(XK_Print,        Key::Print);
66         initTranslateKey(XK_equal,        Key::Plus);
67         initTranslateKey(XK_minus,        Key::Minus);
68         initTranslateKey(XK_F1,           Key::F1);
69         initTranslateKey(XK_F2,           Key::F2);
70         initTranslateKey(XK_F3,           Key::F3);
71         initTranslateKey(XK_F4,           Key::F4);
72         initTranslateKey(XK_F5,           Key::F5);
73         initTranslateKey(XK_F6,           Key::F6);
74         initTranslateKey(XK_F7,           Key::F7);
75         initTranslateKey(XK_F8,           Key::F8);
76         initTranslateKey(XK_F9,           Key::F9);
77         initTranslateKey(XK_F10,          Key::F10);
78         initTranslateKey(XK_F11,          Key::F11);
79         initTranslateKey(XK_F12,          Key::F12);
80         initTranslateKey(XK_KP_Insert,    Key::NumPad0);
81         initTranslateKey(XK_KP_End,       Key::NumPad1);
82         initTranslateKey(XK_KP_Down,      Key::NumPad2);
83         initTranslateKey(XK_KP_Page_Down, Key::NumPad3);
84         initTranslateKey(XK_KP_Left,      Key::NumPad4);
85         initTranslateKey(XK_KP_Begin,     Key::NumPad5);
86         initTranslateKey(XK_KP_Right,     Key::NumPad6);
87         initTranslateKey(XK_KP_Home,      Key::NumPad7);
88         initTranslateKey(XK_KP_Up,        Key::NumPad8);
89         initTranslateKey(XK_KP_Page_Up,   Key::NumPad9);
90         initTranslateKey('0',             Key::Key0);
91         initTranslateKey('1',             Key::Key1);
92         initTranslateKey('2',             Key::Key2);
93         initTranslateKey('3',             Key::Key3);
94         initTranslateKey('4',             Key::Key4);
95         initTranslateKey('5',             Key::Key5);
96         initTranslateKey('6',             Key::Key6);
97         initTranslateKey('7',             Key::Key7);
98         initTranslateKey('8',             Key::Key8);
99         initTranslateKey('9',             Key::Key9);
100         initTranslateKey('a',             Key::KeyA);
101         initTranslateKey('b',             Key::KeyB);
102         initTranslateKey('c',             Key::KeyC);
103         initTranslateKey('d',             Key::KeyD);
104         initTranslateKey('e',             Key::KeyE);
105         initTranslateKey('f',             Key::KeyF);
106         initTranslateKey('g',             Key::KeyG);
107         initTranslateKey('h',             Key::KeyH);
108         initTranslateKey('i',             Key::KeyI);
109         initTranslateKey('j',             Key::KeyJ);
110         initTranslateKey('k',             Key::KeyK);
111         initTranslateKey('l',             Key::KeyL);
112         initTranslateKey('m',             Key::KeyM);
113         initTranslateKey('n',             Key::KeyN);
114         initTranslateKey('o',             Key::KeyO);
115         initTranslateKey('p',             Key::KeyP);
116         initTranslateKey('q',             Key::KeyQ);
117         initTranslateKey('r',             Key::KeyR);
118         initTranslateKey('s',             Key::KeyS);
119         initTranslateKey('t',             Key::KeyT);
120         initTranslateKey('u',             Key::KeyU);
121         initTranslateKey('v',             Key::KeyV);
122         initTranslateKey('w',             Key::KeyW);
123         initTranslateKey('x',             Key::KeyX);
124         initTranslateKey('y',             Key::KeyY);
125         initTranslateKey('z',             Key::KeyZ);
126      }
127
128      int32_t run(int _argc, char** _argv)
129      {
130         XInitThreads();
131         m_display = XOpenDisplay(0);
132
133         int32_t screen = DefaultScreen(m_display);
134         int32_t depth = DefaultDepth(m_display, screen);
135         Visual* visual = DefaultVisual(m_display, screen);
136         Window root = RootWindow(m_display, screen);
137
138         XSetWindowAttributes windowAttrs;
139         memset(&windowAttrs, 0, sizeof(windowAttrs) );
140         windowAttrs.background_pixmap = 0;
141         windowAttrs.border_pixel = 0;
142         windowAttrs.event_mask = 0
143               | ButtonPressMask
144               | ButtonReleaseMask
145               | ExposureMask
146               | KeyPressMask
147               | KeyReleaseMask
148               | PointerMotionMask
149               | ResizeRedirectMask
150               | StructureNotifyMask
151               ;
152
153         m_window = XCreateWindow(m_display
154                           , root
155                           , 0, 0
156                           , ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT, 0, depth
157                           , InputOutput
158                           , visual
159                           , CWBorderPixel|CWEventMask
160                           , &windowAttrs
161                           );
162
163         const char *wmDeleteWindowName = "WM_DELETE_WINDOW";
164         Atom wmDeleteWindow;
165         XInternAtoms(m_display, (char **)&wmDeleteWindowName, 1, False, &wmDeleteWindow);
166         XSetWMProtocols(m_display, m_window, &wmDeleteWindow, 1);
167
168         XMapWindow(m_display, m_window);
169         XStoreName(m_display, m_window, "BGFX");
170
171         bgfx::x11SetDisplayWindow(m_display, m_window);
172
173         MainThreadEntry mte;
174         mte.m_argc = _argc;
175         mte.m_argv = _argv;
176
177         bx::Thread thread;
178         thread.init(mte.threadFunc, &mte);
179
180         while (!m_exit)
181         {
182            if (XPending(m_display) )
183            {
184               XEvent event;
185               XNextEvent(m_display, &event);
186
187               switch (event.type)
188               {
189                  case Expose:
190                     break;
191
192                  case ConfigureNotify:
193                     break;
194
195                  case ClientMessage:
196                     if((Atom)event.xclient.data.l[0] == wmDeleteWindow)
197                     {
198                        m_eventQueue.postExitEvent();
199                     }
200                     break;
201
202                  case ButtonPress:
203                  case ButtonRelease:
204                     {
205                        const XButtonEvent& xbutton = event.xbutton;
206                        MouseButton::Enum mb;
207                        switch (xbutton.button)
208                        {
209                           case Button1: mb = MouseButton::Left;   break;
210                           case Button2: mb = MouseButton::Middle; break;
211                           case Button3: mb = MouseButton::Right;  break;
212                           default:      mb = MouseButton::None;   break;
213                        }
214
215                        if (MouseButton::None != mb)
216                        {
217                           m_eventQueue.postMouseEvent(xbutton.x
218                              , xbutton.y
219                              , 0
220                              , mb
221                              , event.type == ButtonPress
222                              );
223                        }
224                     }
225                     break;
226
227                  case MotionNotify:
228                     {
229                        const XMotionEvent& xmotion = event.xmotion;
230                        m_eventQueue.postMouseEvent(xmotion.x
231                              , xmotion.y
232                              , 0
233                              );
234                     }
235                     break;
236
237                  case KeyPress:
238                  case KeyRelease:
239                     {
240                        XKeyEvent& xkey = event.xkey;
241                        KeySym keysym = XLookupKeysym(&xkey, 0);
242                        switch (keysym)
243                        {
244                        case XK_Meta_L:    setModifier(Modifier::LeftMeta,   KeyPress == event.type); break;
245                        case XK_Meta_R:    setModifier(Modifier::RightMeta,  KeyPress == event.type); break;
246                        case XK_Control_L: setModifier(Modifier::LeftCtrl,   KeyPress == event.type); break;
247                        case XK_Control_R: setModifier(Modifier::RightCtrl,  KeyPress == event.type); break;
248                        case XK_Shift_L:   setModifier(Modifier::LeftShift,  KeyPress == event.type); break;
249                        case XK_Shift_R:   setModifier(Modifier::RightShift, KeyPress == event.type); break;
250                        case XK_Alt_L:     setModifier(Modifier::LeftAlt,    KeyPress == event.type); break;
251                        case XK_Alt_R:     setModifier(Modifier::RightAlt,   KeyPress == event.type); break;
252
253                        default:
254                           {
255                              Key::Enum key = fromXk(keysym);
256                              if (Key::None != key)
257                              {
258                                 m_eventQueue.postKeyEvent(key, m_modifiers, KeyPress == event.type);
259                              }
260                           }
261                           break;
262                        }
263                     }
264                     break;
265
266                  case ResizeRequest:
267                     {
268                        const XResizeRequestEvent& xresize = event.xresizerequest;
269                        XResizeWindow(m_display, m_window, xresize.width, xresize.height);
270                     }
271                     break;
272               }
273            }
274         }
275
276         thread.shutdown();
277
278         XUnmapWindow(m_display, m_window);
279         XDestroyWindow(m_display, m_window);
280
281         return EXIT_SUCCESS;
282      }
283
284      void setModifier(Modifier::Enum _modifier, bool _set)
285      {
286         m_modifiers &= ~_modifier;
287         m_modifiers |= _set ? _modifier : 0;
288      }
289
290      uint8_t m_modifiers;
291      Display* m_display;
292      Window m_window;
293      bool m_exit;
294
295      EventQueue m_eventQueue;
296   };
297
298   static Context s_ctx;
299
300   int32_t MainThreadEntry::threadFunc(void* _userData)
301   {
302      MainThreadEntry* self = (MainThreadEntry*)_userData;
303      int32_t result = main(self->m_argc, self->m_argv);
304      s_ctx.m_exit = true;
305      return result;
306   }
307
308   const Event* poll()
309   {
310      return s_ctx.m_eventQueue.poll();
311   }
312
313   void release(const Event* _event)
314   {
315      s_ctx.m_eventQueue.release(_event);
316   }
317
318   void setWindowSize(uint32_t _width, uint32_t _height)
319   {
320      XResizeRequestEvent ev;
321      ev.type = ResizeRequest;
322      ev.serial = 0;
323      ev.send_event = true;
324      ev.display = s_ctx.m_display;
325      ev.window = s_ctx.m_window;
326      ev.width = (int)_width;
327      ev.height = (int)_height;
328      XSendEvent(s_ctx.m_display, s_ctx.m_window, false, ResizeRedirectMask, (XEvent*)&ev);
329   }
330
331   void setWindowTitle(const char* _title)
332   {
333      BX_UNUSED(_title);
334   }
335
336   void toggleWindowFrame()
337   {
338   }
339
340   void setMouseLock(bool _lock)
341   {
342      BX_UNUSED(_lock);
343   }
344
345} // namespace entry
346
347int main(int _argc, char** _argv)
348{
349   using namespace entry;
350   return s_ctx.run(_argc, _argv);
351}
352
353#endif // ENTRY_CONFIG_USE_NATIVE && (BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX || BX_PLATFORM_RPI)
Property changes on: branches/osd/src/lib/bgfx/common/entry/entry_x11.cpp
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native
branches/osd/src/lib/bgfx/bgfx_p.h
r31763r31764
66#ifndef BGFX_P_H_HEADER_GUARD
77#define BGFX_P_H_HEADER_GUARD
88
9#ifndef BGFX_CONFIG_DEBUG
10#   define BGFX_CONFIG_DEBUG 0
11#endif // BGFX_CONFIG_DEBUG
12
13#if BGFX_CONFIG_DEBUG
14#   define BX_TRACE _BX_TRACE
15#   define BX_WARN  _BX_WARN
16#   define BX_CHECK _BX_CHECK
17#   define BX_CONFIG_ALLOCATOR_DEBUG 1
18#endif // BGFX_CONFIG_DEBUG
19
920#include "bgfx.h"
1021#include "config.h"
1122
r31763r31764
4455               } \
4556            BX_MACRO_BLOCK_END
4657
47#if BGFX_CONFIG_DEBUG
48#   define BX_TRACE _BX_TRACE
49#   define BX_WARN  _BX_WARN
50#   define BX_CHECK _BX_CHECK
51#   define BX_CONFIG_ALLOCATOR_DEBUG 1
52#endif // BGFX_CONFIG_DEBUG
53
5458#define BGFX_FATAL(_condition, _err, _format, ...) \
5559         BX_MACRO_BLOCK_BEGIN \
5660            if (!BX_IGNORE_C4127(_condition) ) \
r31763r31764
25202524         BX_WARN(isValid(handle), "Failed to allocate uniform handle.");
25212525         if (isValid(handle) )
25222526         {
2527            BX_TRACE("Creating uniform (handle %3d) %s", handle.idx, _name);
2528
25232529            UniformRef& uniform = m_uniformRef[handle.idx];
25242530            uniform.m_refCount = 1;
25252531            uniform.m_type = _type;
branches/osd/src/lib/bgfx/glcontext_glx.cpp
r31763r31764
55
66#include "bgfx_p.h"
77
8#if (BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD) && (BGFX_CONFIG_RENDERER_OPENGLES || BGFX_CONFIG_RENDERER_OPENGL)
8#if (BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX) && (BGFX_CONFIG_RENDERER_OPENGLES || BGFX_CONFIG_RENDERER_OPENGL)
99#   include "renderer_gl.h"
1010#   define GLX_GLXEXT_PROTOTYPES
1111#   include <glx/glxext.h>
r31763r31764
233233
234234} // namespace bgfx
235235
236#endif // (BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD) && (BGFX_CONFIG_RENDERER_OPENGLES || BGFX_CONFIG_RENDERER_OPENGL)
236#endif // (BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX) && (BGFX_CONFIG_RENDERER_OPENGLES || BGFX_CONFIG_RENDERER_OPENGL)
branches/osd/src/lib/bgfx/glcontext_nsgl.mm
r31763r31764
55
66#include "bgfx_p.h"
77
8#if BX_PLATFORM_OSX && (BGFX_CONFIG_RENDERER_OPENGLES2|BGFX_CONFIG_RENDERER_OPENGLES3|BGFX_CONFIG_RENDERER_OPENGL)
8#if BX_PLATFORM_OSX && (BGFX_CONFIG_RENDERER_OPENGLES || BGFX_CONFIG_RENDERER_OPENGL)
99#   include "renderer_gl.h"
1010#   include <Cocoa/Cocoa.h>
1111#   include <bx/os.h>

Previous 199869 Revisions Next


© 1997-2024 The MAME Team