1 /*
2  * Copyright 2011-2019 Branimir Karadzic. All rights reserved.
3  * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
4  */
5 
6 #ifndef BGFX_PLATFORM_H_HEADER_GUARD
7 #define BGFX_PLATFORM_H_HEADER_GUARD
8 
9 // NOTICE:
10 // This header file contains platform specific interfaces. It is only
11 // necessary to use this header in conjunction with creating windows.
12 
13 #include <bx/platform.h>
14 #include "bgfx.h"
15 
16 namespace bgfx
17 {
18 	/// Render frame enum.
19 	///
20 	/// @attention C99 equivalent is `bgfx_render_frame_t`.
21 	///
22 	struct RenderFrame
23 	{
24 		enum Enum
25 		{
26 			NoContext,
27 			Render,
28 			Timeout,
29 			Exiting,
30 
31 			Count
32 		};
33 	};
34 
35 	/// Render frame.
36 	///
37 	/// @param _msecs Timeout in milliseconds.
38 	///
39 	/// @returns Current renderer state. See: `bgfx::RenderFrame`.
40 	///
41 	/// @attention `bgfx::renderFrame` is blocking call. It waits for
42 	///   `bgfx::frame` to be called from API thread to process frame.
43 	///   If timeout value is passed call will timeout and return even
44 	///   if `bgfx::frame` is not called.
45 	///
46 	/// @warning This call should be only used on platforms that don't
47 	///   allow creating separate rendering thread. If it is called before
48 	///   to bgfx::init, render thread won't be created by bgfx::init call.
49 	///
50 	/// @attention C99 equivalent is `bgfx_render_frame`.
51 	///
52 	RenderFrame::Enum renderFrame(int32_t _msecs = -1);
53 
54 	/// Set platform data.
55 	///
56 	/// @warning Must be called before `bgfx::init`.
57 	///
58 	/// @attention C99 equivalent is `bgfx_set_platform_data`.
59 	///
60 	void setPlatformData(const PlatformData& _data);
61 
62 	/// Internal data.
63 	///
64 	/// @attention C99 equivalent is `bgfx_internal_data_t`.
65 	///
66 	struct InternalData
67 	{
68 		const struct Caps* caps; //!< Renderer capabilities.
69 		void* context;           //!< GL context, or D3D device.
70 	};
71 
72 	/// Get internal data for interop.
73 	///
74 	/// @attention It's expected you understand some bgfx internals before you
75 	///   use this call.
76 	///
77 	/// @warning Must be called only on render thread.
78 	///
79 	/// @attention C99 equivalent is `bgfx_get_internal_data`.
80 	///
81 	const InternalData* getInternalData();
82 
83 	/// Override internal texture with externally created texture. Previously
84 	/// created internal texture will released.
85 	///
86 	/// @attention It's expected you understand some bgfx internals before you
87 	///   use this call.
88 	///
89 	/// @param[in] _handle Texture handle.
90 	/// @param[in] _ptr Native API pointer to texture.
91 	///
92 	/// @returns Native API pointer to texture. If result is 0, texture is not created yet from the
93 	///   main thread.
94 	///
95 	/// @warning Must be called only on render thread.
96 	///
97 	/// @attention C99 equivalent is `bgfx_override_internal_texture_ptr`.
98 	///
99 	uintptr_t overrideInternal(TextureHandle _handle, uintptr_t _ptr);
100 
101 	/// Override internal texture by creating new texture. Previously created
102 	/// internal texture will released.
103 	///
104 	/// @attention It's expected you understand some bgfx internals before you
105 	///   use this call.
106 	///
107 	/// @param[in] _handle Texture handle.
108 	/// @param[in] _width Width.
109 	/// @param[in] _height Height.
110 	/// @param[in] _numMips Number of mip-maps.
111 	/// @param[in] _format Texture format. See: `TextureFormat::Enum`.
112 	/// @param[in] _flags Default texture sampling mode is linear, and wrap mode
113 	///   is repeat.
114 	///   - `BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap
115 	///     mode.
116 	///   - `BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic
117 	///     sampling.
118 	///
119 	/// @returns Native API pointer to texture. If result is 0, texture is not created yet from the
120 	///   main thread.
121 	///
122 	/// @warning Must be called only on render thread.
123 	///
124 	/// @attention C99 equivalent is `bgfx_override_internal_texture`.
125 	///
126 	uintptr_t overrideInternal(
127 		  TextureHandle _handle
128 		, uint16_t _width
129 		, uint16_t _height
130 		, uint8_t _numMips
131 		, TextureFormat::Enum _format
132 		, uint64_t _flags = BGFX_TEXTURE_NONE|BGFX_SAMPLER_NONE
133 		);
134 
135 } // namespace bgfx
136 
137 #endif // BGFX_PLATFORM_H_HEADER_GUARD
138