From 0f330a7a08a9dcf3a1cc6637d0c24dd97a01ba17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Thu, 5 Jun 2014 22:49:51 -0700 Subject: [PATCH] Added bgfx platform C99 header. --- include/bgfxplatform.c99.h | 85 ++++++++++++++++++++++++++++++++++++++ include/bgfxplatform.h | 4 +- src/bgfx.cpp | 45 ++++++++++++++++++++ 3 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 include/bgfxplatform.c99.h diff --git a/include/bgfxplatform.c99.h b/include/bgfxplatform.c99.h new file mode 100644 index 000000000..4a2174d95 --- /dev/null +++ b/include/bgfxplatform.c99.h @@ -0,0 +1,85 @@ +/* + * Copyright 2011-2014 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE + * + * vim: set tabstop=4 expandtab: + */ + +#ifndef BGFX_PLATFORM_C99_H_HEADER_GUARD +#define BGFX_PLATFORM_C99_H_HEADER_GUARD + +// NOTICE: +// This header file contains platform specific interfaces. It is only +// necessary to use this header in conjunction with creating windows. + +#include + +typedef enum bgfx_render_frame +{ + BGFX_RENDER_FRAME_NO_CONTEXT, + BGFX_RENDER_FRAME_RENDER, + BGFX_RENDER_FRAME_EXITING, + + BGFX_RENDER_FRAME_COUNT + +} bgfx_render_frame_t; + +/** + * WARNING: This call should be only used on platforms that don't + * allow creating separate rendering thread. If it is called before + * to bgfx_init, render thread won't be created by bgfx_init call. + */ +BGFX_C_API bgfx_render_frame_t bgfx_render_frame(); + +#if BX_PLATFORM_ANDROID +# include + +/** + * + */ +BGFX_C_API void bgfx_android_set_window(ANativeWindow* _window); + +#elif BX_PLATFORM_IOS + +/** + * + */ +BGFX_C_API void bgfx_ios_set_eagl_layer(void* _layer); + +#elif BX_PLATFORM_LINUX +# include + +/** + * + */ +BGFX_C_API void bgfx_x11_set_display_window(Display* _display, Window _window); + +#elif BX_PLATFORM_NACL +# include +# include + +typedef void (*bgfx_post_swap_buffers_fn)(uint32_t _width, uint32_t _height); + +/** + * + */ +BGFX_C_API bool bgfx_nacl_set_interfaces(PP_Instance, const PPB_Instance*, const PPB_Graphics3D*, bgfx_post_swap_buffers_fn); + +#elif BX_PLATFORM_OSX + +/** + * + */ +BGFX_C_API void bgfx_osx_set_ns_window(void* _window); + +#elif BX_PLATFORM_WINDOWS +# include + +/** + * + */ +BGFX_C_API void bgfx_win_set_hwnd(HWND _window); + +#endif // BX_PLATFORM_ + +#endif // BGFX_PLATFORM_C99_H_HEADER_GUARD diff --git a/include/bgfxplatform.h b/include/bgfxplatform.h index a4bea8b84..4b398a5e4 100755 --- a/include/bgfxplatform.h +++ b/include/bgfxplatform.h @@ -1,6 +1,6 @@ /* * Copyright 2011-2014 Branimir Karadzic. All rights reserved. - * License: http://www.opensource.org/licenses/BSD-2-Clause + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_PLATFORM_H_HEADER_GUARD @@ -10,7 +10,7 @@ // This header file contains platform specific interfaces. It is only // necessary to use this header in conjunction with creating windows. -#include +#include namespace bgfx { diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 3c87c4b27..16084f901 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -2605,12 +2605,14 @@ again: } // namespace bgfx #include +#include BX_STATIC_ASSERT(bgfx::RendererType::Count == bgfx::RendererType::Enum(BGFX_RENDERER_TYPE_COUNT) ); BX_STATIC_ASSERT(bgfx::Attrib::Count == bgfx::Attrib::Enum(BGFX_ATTRIB_COUNT) ); BX_STATIC_ASSERT(bgfx::AttribType::Count == bgfx::AttribType::Enum(BGFX_ATTRIB_TYPE_COUNT) ); BX_STATIC_ASSERT(bgfx::TextureFormat::Count == bgfx::TextureFormat::Enum(BGFX_TEXTURE_FORMAT_COUNT) ); BX_STATIC_ASSERT(bgfx::UniformType::Count == bgfx::UniformType::Enum(BGFX_UNIFORM_TYPE_COUNT) ); +BX_STATIC_ASSERT(bgfx::RenderFrame::Count == bgfx::RenderFrame::Enum(BGFX_RENDER_FRAME_COUNT) ); BX_STATIC_ASSERT(sizeof(bgfx::Memory) == sizeof(bgfx_memory_t) ); BX_STATIC_ASSERT(sizeof(bgfx::VertexDecl) == sizeof(bgfx_vertex_decl_t) ); @@ -3196,3 +3198,46 @@ BGFX_C_API void bgfx_save_screen_shot(const char* _filePath) { bgfx::saveScreenShot(_filePath); } + +BGFX_C_API bgfx_render_frame_t bgfx_render_frame() +{ + return bgfx_render_frame_t(bgfx::renderFrame() ); +} + +#if BX_PLATFORM_ANDROID +BGFX_C_API void bgfx_android_set_window(ANativeWindow* _window) +{ + bgfx::androidSetWindow(_window); +} + +#elif BX_PLATFORM_IOS +BGFX_C_API void bgfx_ios_set_eagl_layer(void* _layer) +{ + bgfx::iosSetEaglLayer(_layer); +} + +#elif BX_PLATFORM_LINUX +BGFX_C_API void bgfx_x11_set_display_window(::Display* _display, ::Window _window) +{ + bgfx::x11SetDisplayWindow(_display, _window); +} + +#elif BX_PLATFORM_NACL +BGFX_C_API bool bgfx_nacl_set_interfaces(PP_Instance _instance, const PPB_Instance* _instInterface, const PPB_Graphics3D* _graphicsInterface, bgfx_post_swap_buffers_fn _postSwapBuffers) +{ + return bgfx::naclSetInterfaces(_instance, _instInterface, _graphicsInterface, _postSwapBuffers); +} + +#elif BX_PLATFORM_OSX +BGFX_C_API void bgfx_osx_set_ns_window(void* _window) +{ + bgfx::osxSetNSWindow(_window); +} + +#elif BX_PLATFORM_WINDOWS +BGFX_C_API void bgfx_win_set_hwnd(HWND _window) +{ + bgfx::winSetHwnd(_window); +} + +#endif // BX_PLATFORM_*