Procházet zdrojové kódy

Allow passing platform data via init.

Branimir Karadžić před 7 roky
rodič
revize
82815f1c4c

+ 18 - 0
include/bgfx/bgfx.h

@@ -600,6 +600,21 @@ namespace bgfx
 	{
 	}
 
+	/// Platform data.
+	///
+	/// @attention C99 equivalent is `bgfx_platform_data_t`.
+	///
+	struct PlatformData
+	{
+		PlatformData();
+
+		void* ndt;          //!< Native display type.
+		void* nwh;          //!< Native window handle.
+		void* context;      //!< GL context, or D3D device.
+		void* backBuffer;   //!< GL backbuffer, or D3D render target view.
+		void* backBufferDS; //!< Backbuffer depth/stencil.
+	};
+
 	/// Backbuffer resolution and reset parameters.
 	///
 	/// @attention C99 equivalent is `bgfx_resolution_t`.
@@ -645,6 +660,9 @@ namespace bgfx
 		bool debug;   //!< Enable device for debuging.
 		bool profile; //!< Enable device for profiling.
 
+		/// Platform data.
+		PlatformData platformData;
+
 		/// Backbuffer resolution and reset parameters. See: `bgfx::Resolution`.
 		Resolution resolution;
 

+ 14 - 2
include/bgfx/c99/bgfx.h

@@ -598,6 +598,17 @@ typedef struct bgfx_allocator_vtbl_s
 
 } bgfx_allocator_vtbl_t;
 
+/**/
+typedef struct bgfx_platform_data
+{
+    void* ndt;
+    void* nwh;
+    void* context;
+    void* backBuffer;
+    void* backBufferDS;
+
+} bgfx_platform_data_t;
+
 /**/
 typedef struct bgfx_resolution_s
 {
@@ -628,8 +639,9 @@ typedef struct bgfx_init_s
     bool debug;
     bool profile;
 
-    bgfx_resolution_t  resolution;
-    bgfx_init_limits_t limits;
+    bgfx_platform_data_t platformData;
+    bgfx_resolution_t    resolution;
+    bgfx_init_limits_t   limits;
 
     bgfx_callback_interface_t*  callback;
     bgfx_allocator_interface_t* allocator;

+ 0 - 11
include/bgfx/c99/platform.h

@@ -33,17 +33,6 @@ typedef enum bgfx_render_frame
  */
 BGFX_C_API bgfx_render_frame_t bgfx_render_frame(int32_t _msecs);
 
-typedef struct bgfx_platform_data
-{
-    void* ndt;
-    void* nwh;
-    void* context;
-    void* backBuffer;
-    void* backBufferDS;
-    void* session;
-
-} bgfx_platform_data_t;
-
 /**/
 BGFX_C_API void bgfx_set_platform_data(const bgfx_platform_data_t* _data);
 

+ 1 - 1
include/bgfx/defines.h

@@ -6,7 +6,7 @@
 #ifndef BGFX_DEFINES_H_HEADER_GUARD
 #define BGFX_DEFINES_H_HEADER_GUARD
 
-#define BGFX_API_VERSION UINT32_C(88)
+#define BGFX_API_VERSION UINT32_C(89)
 
 /// Color RGB/alpha/depth write. When it's not specified write will be disabled.
 #define BGFX_STATE_WRITE_R                 UINT64_C(0x0000000000000001) //!< Enable R write.

+ 0 - 14
include/bgfx/platform.h

@@ -48,20 +48,6 @@ namespace bgfx
 	///   to bgfx::init, render thread won't be created by bgfx::init call.
 	RenderFrame::Enum renderFrame(int32_t _msecs = -1);
 
-	/// Platform data.
-	///
-	/// @attention C99 equivalent is `bgfx_platform_data_t`.
-	///
-	struct PlatformData
-	{
-		void* ndt;          //!< Native display type.
-		void* nwh;          //!< Native window handle.
-		void* context;      //!< GL context, or D3D device.
-		void* backBuffer;   //!< GL backbuffer, or D3D render target view.
-		void* backBufferDS; //!< Backbuffer depth/stencil.
-		void* session;      //!< ovrSession, for Oculus SDK
-	};
-
 	/// Set platform data.
 	///
 	/// @warning Must be called before `bgfx::init`.

+ 27 - 5
src/bgfx.cpp

@@ -1449,6 +1449,19 @@ namespace bgfx
 		m_init = _init;
 		m_init.resolution.reset &= ~BGFX_RESET_INTERNAL_FORCE;
 
+		if (g_platformData.ndt          == NULL
+		&&  g_platformData.nwh          == NULL
+		&&  g_platformData.context      == NULL
+		&&  g_platformData.backBuffer   == NULL
+		&&  g_platformData.backBufferDS == NULL)
+		{
+			bx::memCopy(&g_platformData, &m_init.platformData, sizeof(PlatformData) );
+		}
+		else
+		{
+			bx::memCopy(&m_init.platformData, &g_platformData, sizeof(PlatformData) );
+		}
+
 		m_exit    = false;
 		m_flipped = true;
 		m_frames  = 0;
@@ -2837,6 +2850,15 @@ namespace bgfx
 		return s_rendererCreator[_type].name;
 	}
 
+	PlatformData::PlatformData()
+		: ndt(NULL)
+		, nwh(NULL)
+		, context(NULL)
+		, backBuffer(NULL)
+		, backBufferDS(NULL)
+	{
+	}
+
 	Resolution::Resolution()
 		: format(TextureFormat::RGBA8)
 		, width(1280)
@@ -2911,11 +2933,11 @@ namespace bgfx
 		if (true
 		&&  !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_PS4)
 		&&  RendererType::Noop != _init.type
-		&&  NULL == g_platformData.ndt
-		&&  NULL == g_platformData.nwh
-		&&  NULL == g_platformData.context
-		&&  NULL == g_platformData.backBuffer
-		&&  NULL == g_platformData.backBufferDS
+		&&  NULL == _init.platformData.ndt
+		&&  NULL == _init.platformData.nwh
+		&&  NULL == _init.platformData.context
+		&&  NULL == _init.platformData.backBuffer
+		&&  NULL == _init.platformData.backBufferDS
 		   )
 		{
 			BX_TRACE("bgfx platform data like window handle or backbuffer is not set, creating headless device.");