plugin_api.h - Engine C API Reference

plugin_api.h
  1. #pragma once
  2. #include "plugin_api_types.h"
  3. #include "plugin_c_api.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #include <stdarg.h>
  8. #include <stdint.h>
  9. /*
  10. This file defines the Plugin API for the engine.
  11. The plugin interface is based around a single function:
  12. __declspec(dllexport) void *get_plugin_api(unsigned api_id);
  13. The API ID is an integer that uniquely identify a specific version of a particular service.
  14. If the plugin can provide the service it returns a pointer to an API struct that contains
  15. function pointers for using the service.
  16. For ABI compatibility and simplicity, only C code is used in the interfaces.
  17. This method is used both by the plugins to provide services to the engine and by the engine
  18. to provide services to the plugins. For the second case, the engine sends a function:
  19. void *get_engine_api(unsigned api_id);
  20. to the plugins when they are initialized. The plugins can use this function to query for
  21. engine interfaces. Plugins can also use this to call on services provided by other plugins
  22. through the get_next_plugin_api() in the PluginManagerApi.
  23. Starting with the 1.7 release of the engine, we will make an effort to keep the plugin
  24. APIs backwards compatible. This means that you cannot remove functions or change the
  25. signature of functions in the API, only add new ones in the reserved functions. Old functions
  26. can be marked as deprecated but should be left in the API.
  27. If you need to make big changes to an API, that cannot easily be covered by just adding
  28. new functions, you should make a completely new API with a new ID (i.e.
  29. APPLICATION_API_V2_ID), while keeping the old one intact. That way, backwards compatibility
  30. is ensured.
  31. */
  32. #include <stddef.h>
  33. /* API IDs for the different services. */
  34. enum PluginApiID {
  35. PLUGIN_API_ID = 0,
  36. LUA_API_ID = 1,
  37. DATA_COMPILER_API_ID = 2,
  38. DATA_COMPILE_PARAMETERS_API_ID = 3,
  39. ALLOCATOR_API_ID = 4,
  40. RESOURCE_MANAGER_API_ID = 5,
  41. LOGGING_API_ID = 6,
  42. UNIT_API_ID = 8,
  43. SCENE_GRAPH_API_ID = 9,
  44. FUTURE_INPUT_ARCHIVE_API_ID = 10,
  45. INPUT_ARCHIVE_API_ID = 11,
  46. APPLICATION_API_ID = 12,
  47. APPLICATION_OPTIONS_API_ID = 13,
  48. UNIT_REFERENCE_API_ID = 14,
  49. ERROR_CONTEXT_API_ID = 15,
  50. RENDER_INTERFACE_API_ID = 16,
  51. RAYCAST_API_ID = 17,
  52. RENDER_CALLBACKS_PLUGIN_API_ID = 18,
  53. RENDER_OVERRIDES_PLUGIN_API_ID = 19,
  54. FILESYSTEM_API_ID = 20,
  55. PLUGIN_MANAGER_API_ID = 21,
  56. WORLD_API_ID = 22,
  57. LINE_OBJECT_DRAWER_API_ID = 23,
  58. PROFILER_API_ID = 24,
  59. ERROR_API_ID = 25,
  60. RENDER_BUFFER_API_ID = 26,
  61. MESH_API_ID = 27,
  62. INPUT_BUFFER_API_ID = 28,
  63. RENDER_SCENE_GRAPH_API_ID = 29,
  64. SOUND_STREAM_SOURCE_API_ID = 30,
  65. C_API_ID = 31,
  66. THREAD_API_ID = 32,
  67. TIMER_API_ID = 33,
  68. MATERIAL_API_ID = 34,
  69. SCENE_DATABASE_API_ID = 35,
  70. STREAM_CAPTURE_API_ID = 36,
  71. FLOW_NODES_API_ID = 37,
  72. CAMERA_API_ID = 38,
  73. ENTITY_COMPILE_DATA_API_ID = 39,
  74. PHYSICS_RUNTIME_COOKING_API_ID = 40,
  75. END_OF_ENGINE_RESERVED_RANGE = 65535,
  76. /* API IDs in the range 0--65535 are reserved by the engine. If you want to
  77. provide your own API in your plugin, we suggest using a hash of the API's
  78. name as ID. */
  79. };
  80. /* ----------------------------------------------------------------------
  81. Common types
  82. ---------------------------------------------------------------------- */
  83. /* These types are used in multiple plugins. */
  84. /* Opaque struct representing an input file archive that data can be read from. */
  85. struct InputArchive;
  86. /* Opaque struct representing a buffer that an input archive gets information from. */
  87. struct InputBuffer;
  88. /* ----------------------------------------------------------------------
  89. Plugin
  90. ---------------------------------------------------------------------- */
  91. /* This function can be used by the plugin to query for engine APIs. */
  92. typedef void *(*GetApiFunction)(unsigned api);
  93. /* Opaque struct representing a stream of state changes sent from the main thread to the render
  94. thread. */
  95. struct StateReflectionStream;
  96. /* Deprecated. */
  97. struct RD_DeviceData {
  98. struct Context *context;
  99. struct RenderTarget* render_target;
  100. struct DepthStencilTarget* depth_stencil_target;
  101. };
  102. /* Deprecated. */
  103. struct RD_EngineData {
  104. /* A custom rendering environment returned by the plugin in get_render_env(). */
  105. void* render_env;
  106. void* render_target;
  107. void* depth_stencil_target;
  108. };
  109. /* Deprecated. */
  110. struct RenderDevicePluginArguments {
  111. struct RD_DeviceData device_data;
  112. struct RD_EngineData engine_data;
  113. };
  114. /*
  115. This is the main interface provided by the plugins. The functions in this interface will
  116. be called at various points during the engine's setup and shutdown sequence.
  117. The plugin is not obligated to implement all these functions. You can return NULL for the
  118. functions that you do not support.
  119. */
  120. struct PluginApi
  121. {
  122. /* Returns the name of the plugin. */
  123. const char *(*get_name)();
  124. /* Called to initialize the plugin once it has been loaded into memory. For plugins loaded at
  125. boot, this function is called once all plugins have been loaded (so you can query for other
  126. plugins in this function). For plugins loaded on demand, this function is called as soon
  127. as the plugin have been loaded. */
  128. void (*loaded)(GetApiFunction get_engine_api);
  129. /* Called just before the plugin is unloaded. */
  130. void (*unloaded)();
  131. /* Called at the start of a "hot reload" of the plugin DLL. Should return a
  132. pointer to a serialized "state" for the plugin.*/
  133. void *(*start_reload)(GetApiFunction get_engine_api);
  134. /* Called to finalized the "hot reload" after the plugin has been reloaded with
  135. the new code. Should restore the state from the serialized state data. Note
  136. that it is the responsibility of the plugin to free the state data. */
  137. void (*finish_reload)(GetApiFunction get_engine_api, void *state);
  138. /* Called when the engine sets up the DataCompiler. You can use the functions in the DataCompiler
  139. API to add custom data types to the DataCompiler. */
  140. void (*setup_data_compiler)(GetApiFunction get_engine_api);
  141. /* Called when the engine shuts down the data compiler. */
  142. void (*shutdown_data_compiler)();
  143. /* Called when the engine sets up the ResourceManager. At this point you can use the ResourceManagerApi
  144. to add support for resource manager loading of your custom data types. */
  145. void (*setup_resources)(GetApiFunction get_engine_api);
  146. /* Called when the engine shuts down the ResourceManager. */
  147. void (*shutdown_resources)();
  148. /* Called when the engine reloads its resources. The plugin should return true if it is able
  149. to hot-reload resources of the specified type. */
  150. int (*can_refresh)(uint64_t type);
  151. /* Called when the engine reloads its resources, to tell the plugin to refresh the given resource. */
  152. void (*refresh)(uint64_t type, uint64_t name);
  153. /* Called when the engine sets up the game. At this point, you can use the functions in the LuaApi
  154. to add functions to the engine's Lua API. */
  155. void (*setup_game)(GetApiFunction get_engine_api);
  156. /* Called per game frame. */
  157. void (*update_game)(float dt);
  158. /* Called when the engine shuts down the game. */
  159. void (*shutdown_game)();
  160. /* Called after the world has been created and is about to be added to the engines list of worlds */
  161. void (*register_world)(CApiWorld * world);
  162. /* Called before a world is about to be destroyed and removed from the engines list of worlds. */
  163. void (*unregister_world)(CApiWorld * world);
  164. /* Called when units are spawned by the engine. */
  165. void (*units_spawned)(CApiUnit **units, unsigned count);
  166. /* Called when units are unspawned by the engine. */
  167. void (*units_unspawned)(CApiUnit **units, unsigned count);
  168. /* Called by the engine to draw debug visuals into the world. */
  169. void (*debug_draw)(CApiWorld * world, struct StateReflectionStream * srs);
  170. /* Deprecated. */
  171. void * (*get_render_env)();
  172. /* Deprecated. */
  173. void (*render)(struct RenderDevicePluginArguments *arguments);
  174. /* Reserved for expansion of the API. */
  175. void *reserved[32];
  176. };
  177. enum RenderCallbacksPluginApi_EventType {
  178. RC_CASCADED_SHADOW_MAPPING = 2,
  179. RC_ATLASED_SHADOW_MAPPING = 3
  180. };
  181. /*
  182. This is the interface implemented by plugins who are interested in callbacks from the rendering
  183. thread.
  184. The plugin is not obligated to implement all these functions. You can return NULL for the
  185. functions that you do not support.
  186. */
  187. struct RenderCallbacksPluginApi
  188. {
  189. /* Called when a new swapchain is created. */
  190. void (*create_swap_chain)(unsigned swap_chain_handle, unsigned width, unsigned height);
  191. /* Called just before a swap chain is resized. */
  192. void (*prepare_resize_swap_chain)(unsigned swap_chain_handle, unsigned width, unsigned height);
  193. /* Called when a swap chain has been resized. */
  194. void (*resize_swap_chain)(unsigned swap_chain_handle, unsigned width, unsigned height);
  195. /* Called when a swap chain is destroyed. */
  196. void (*destroy_swap_chain)(unsigned swap_chain_handle);
  197. /* Called when rendering of a frame starts. */
  198. void (*begin_frame)();
  199. /* Called when rendering of a frame finishes. */
  200. void (*end_frame)();
  201. /* Called before cascaded shadow rendering is processed. */
  202. void (*on_pre_shadow)(enum RenderCallbacksPluginApi_EventType event_type);
  203. /* Called after cascaded shadow rendering is processed. */
  204. void (*on_post_shadow)(enum RenderCallbacksPluginApi_EventType event_type);
  205. /* Reserved for expansion of the API. */
  206. void *reserved[30];
  207. };
  208. /*
  209. This is the interface implemented by plugins who are interested in overriding certain functionality
  210. on the rendering thread.
  211. The plugin is not obligated to implement all these functions. You can return NULL for the
  212. functions that you do not support.
  213. TODO: How do we best deal with multiple plugins overriding the same function?
  214. */
  215. struct RenderOverridesPluginApi
  216. {
  217. /* Called when the engine presents the rendered data.
  218. You should return 0 from this function if you still want the default present functionality
  219. to be executed. Otherwise, return 1. */
  220. int (*present)(unsigned swap_chain_handle);
  221. /* Reserved for expansion of the API. */
  222. void *reserved[32];
  223. };
  224. /* ----------------------------------------------------------------------
  225. Lua
  226. ---------------------------------------------------------------------- */
  227. /* Opaque struct representing a Lua state. */
  228. typedef struct lua_State lua_State;
  229. /* Types from Lua. */
  230. typedef int (*lua_CFunction) (lua_State *L);
  231. typedef struct lua_Debug lua_Debug;
  232. typedef double lua_Number;
  233. typedef ptrdiff_t lua_Integer;
  234. typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
  235. typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
  236. typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);
  237. typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
  238. typedef struct luaL_Reg luaL_Reg;
  239. /*
  240. Interface to access Lua services.
  241. */
  242. struct LuaApi
  243. {
  244. /* -----------------------------------------------------------------------
  245. Extending Lua
  246. ----------------------------------------------------------------------- */
  247. /* Adds a new lua function in the module with the specified name.
  248. The function will be callable as stingray.{module}.{name}() */
  249. void (*add_module_function)(const char *module, const char *name, lua_CFunction f);
  250. /* As add_module_function() but prints a deprecation warning when the function is used. */
  251. void (*deprecated_warning)(const char *module, const char *name, lua_CFunction f, const char* message);
  252. /* As add_module_function() but prints a deprecation error when the function is used. */
  253. void (*deprecated_error)(const char *module, const char *name, const char* message);
  254. /* Sets a bool constant in a module. */
  255. void (*set_module_bool)(const char *module, const char *key, int value);
  256. /* Sets a number constant in a module. */
  257. void (*set_module_number)(const char *module, const char *key, double value);
  258. /* Sets a number constant in a namespace in a module. */
  259. void (*set_module_namespace_number)(const char *module, const char* name_space, const char *key, double value);
  260. /* Sets a string constant in a module. */
  261. void (*set_module_string)(const char *module, const char *key, const char *value);
  262. /* Adds a new console command. Console commands are Lua functions in the stingray.Console
  263. module that only takes string parameters. They can be used from the console:
  264. > memory_resources all
  265. is equivalent to
  266. > Console.memory_resources("all")
  267. The vararg is a sequence of documentation strings, ended by a nullptr -- like this:
  268. add_console_command("memory_resources", memory_resources_f,
  269. "Print memory usage per resource",
  270. "all", "print memory use of all resources",
  271. "sound", "print memory use of sound resources",
  272. "texture_categories [details]", "print memory usage per texture category",
  273. "list <TYPE>", "list memory use of specified types",
  274. (void*)nullptr); */
  275. void (*add_console_command)(const char *command, lua_CFunction f, const char *desc, ...);
  276. /* Removes all entries from the specified module. */
  277. void (*remove_all_module_entries)(const char *module);
  278. /* Removes the specified module entry from the runtime. */
  279. void (*remove_module_entry)(const char *module, const char *entry);
  280. /* -----------------------------------------------------------------------
  281. Lua standard functions
  282. See the Lua API for documentation.
  283. ----------------------------------------------------------------------- */
  284. /* State manipulation */
  285. void (*close) (lua_State *L);
  286. lua_State *(*newthread) (lua_State *L);
  287. lua_CFunction (*atpanic) (lua_State *L, lua_CFunction panicf);
  288. /* Basic stack manipulation */
  289. int (*gettop) (lua_State *L);
  290. void (*settop) (lua_State *L, int idx);
  291. void (*pushvalue) (lua_State *L, int idx);
  292. void (*remove) (lua_State *L, int idx);
  293. void (*insert) (lua_State *L, int idx);
  294. void (*replace) (lua_State *L, int idx);
  295. int (*checkstack) (lua_State *L, int sz);
  296. void (*xmove) (lua_State *from, lua_State *to, int n);
  297. /* Access functions */
  298. int (*isnumber) (lua_State *L, int idx);
  299. int (*isstring) (lua_State *L, int idx);
  300. int (*iscfunction) (lua_State *L, int idx);
  301. int (*isuserdata) (lua_State *L, int idx);
  302. int (*type) (lua_State *L, int idx);
  303. const char *(*lua_typename) (lua_State *L, int tp);
  304. int (*equal) (lua_State *L, int idx1, int idx2);
  305. int (*rawequal) (lua_State *L, int idx1, int idx2);
  306. int (*lessthan) (lua_State *L, int idx1, int idx2);
  307. lua_Number (*tonumber) (lua_State *L, int idx);
  308. lua_Integer (*tointeger) (lua_State *L, int idx);
  309. int (*toboolean) (lua_State *L, int idx);
  310. const char *(*tolstring) (lua_State *L, int idx, size_t *len);
  311. size_t (*objlen) (lua_State *L, int idx);
  312. lua_CFunction (*tocfunction) (lua_State *L, int idx);
  313. void *(*touserdata) (lua_State *L, int idx);
  314. lua_State *(*tothread) (lua_State *L, int idx);
  315. const void *(*topointer) (lua_State *L, int idx);
  316. /* Push functions */
  317. void (*pushnil) (lua_State *L);
  318. void (*pushnumber) (lua_State *L, lua_Number n);
  319. void (*pushinteger) (lua_State *L, lua_Integer n);
  320. void (*pushlstring) (lua_State *L, const char *s, size_t l);
  321. void (*pushstring) (lua_State *L, const char *s);
  322. const char *(*pushvfstring) (lua_State *L, const char *fmt, va_list argp);
  323. const char *(*pushfstring) (lua_State *L, const char *fmt, ...);
  324. void (*pushcclosure) (lua_State *L, lua_CFunction fn, int n);
  325. void (*pushboolean) (lua_State *L, int b);
  326. void (*pushlightuserdata) (lua_State *L, void *p);
  327. int (*pushthread) (lua_State *L);
  328. /* Get functions */
  329. void (*gettable) (lua_State *L, int idx);
  330. void (*getfield) (lua_State *L, int idx, const char *k);
  331. void (*rawget) (lua_State *L, int idx);
  332. void (*rawgeti) (lua_State *L, int idx, int n);
  333. void (*createtable) (lua_State *L, int narr, int nrec);
  334. void *(*newuserdata) (lua_State *L, size_t sz);
  335. int (*getmetatable) (lua_State *L, int objindex);
  336. void (*getfenv) (lua_State *L, int idx);
  337. /* Set functions */
  338. void (*settable) (lua_State *L, int idx);
  339. void (*setfield) (lua_State *L, int idx, const char *k);
  340. void (*rawset) (lua_State *L, int idx);
  341. void (*rawseti) (lua_State *L, int idx, int n);
  342. int (*setmetatable) (lua_State *L, int objindex);
  343. int (*setfenv) (lua_State *L, int idx);
  344. /* Load and call functions */
  345. void (*call) (lua_State *L, int nargs, int nresults);
  346. int (*pcall) (lua_State *L, int nargs, int nresults, int errfunc);
  347. int (*cpcall) (lua_State *L, lua_CFunction func, void *ud);
  348. int (*load) (lua_State *L, lua_Reader reader, void *dt, const char *chunkname);
  349. int (*dump) (lua_State *L, lua_Writer writer, void *data);
  350. /* Coroutine functions */
  351. int (*yield) (lua_State *L, int nresults);
  352. int (*resume) (lua_State *L, int narg);
  353. int (*status) (lua_State *L);
  354. /* Garbage collection */
  355. int (*gc) (lua_State *L, int what, int data);
  356. /* Miscellaneous functions */
  357. int (*error) (lua_State *L);
  358. int (*next) (lua_State *L, int idx);
  359. void (*concat) (lua_State *L, int n);
  360. /* Debugging */
  361. int (*getstack) (lua_State *L, int level, lua_Debug *ar);
  362. int (*getinfo) (lua_State *L, const char *what, lua_Debug *ar);
  363. const char *(*getlocal) (lua_State *L, const lua_Debug *ar, int n);
  364. const char *(*setlocal) (lua_State *L, const lua_Debug *ar, int n);
  365. const char *(*getupvalue) (lua_State *L, int funcindex, int n);
  366. const char *(*setupvalue) (lua_State *L, int funcindex, int n);
  367. int (*sethook) (lua_State *L, lua_Hook func, int mask, int count);
  368. lua_Hook (*gethook) (lua_State *L);
  369. int (*gethookmask) (lua_State *L);
  370. int (*gethookcount) (lua_State *L);
  371. /* Library functions */
  372. void (*lib_openlib) (lua_State *L, const char *libname, const luaL_Reg *l, int nup);
  373. void (*lib_register) (lua_State *L, const char *libname, const luaL_Reg *l);
  374. int (*lib_getmetafield) (lua_State *L, int obj, const char *e);
  375. int (*lib_callmeta) (lua_State *L, int obj, const char *e);
  376. int (*lib_typerror) (lua_State *L, int narg, const char *tname);
  377. int (*lib_argerror) (lua_State *L, int numarg, const char *extramsg);
  378. const char *(*lib_checklstring) (lua_State *L, int numArg, size_t *l);
  379. const char *(*lib_optlstring) (lua_State *L, int numArg, const char *def, size_t *l);
  380. lua_Number (*lib_checknumber) (lua_State *L, int numArg);
  381. lua_Number (*lib_optnumber) (lua_State *L, int nArg, lua_Number def);
  382. lua_Integer (*lib_checkinteger) (lua_State *L, int numArg);
  383. lua_Integer (*lib_optinteger) (lua_State *L, int nArg, lua_Integer def);
  384. void (*lib_checkstack) (lua_State *L, int sz, const char *msg);
  385. void (*lib_checktype) (lua_State *L, int narg, int t);
  386. void (*lib_checkany) (lua_State *L, int narg);
  387. int (*lib_newmetatable) (lua_State *L, const char *tname);
  388. void*(*lib_checkudata) (lua_State *L, int ud, const char *tname);
  389. void (*lib_where) (lua_State *L, int lvl);
  390. int (*lib_error) (lua_State *L, const char *fmt, ...);
  391. int (*lib_checkoption) (lua_State *L, int narg, const char *def, const char *const lst[]);
  392. int (*lib_ref) (lua_State *L, int t);
  393. void (*lib_unref) (lua_State *L, int t, int ref);
  394. int (*lib_loadfile) (lua_State *L, const char *filename);
  395. int (*lib_loadbuffer) (lua_State *L, const char *buff, size_t sz, const char *name);
  396. int (*lib_loadstring) (lua_State *L, const char *s);
  397. lua_State *(*lib_newstate) (void);
  398. const char *(*lib_gsub) (lua_State *L, const char *s, const char *p, const char *r);
  399. const char *(*lib_findtable) (lua_State *L, int idx, const char *fname, int szhint);
  400. void (*lib_openlibs)(lua_State *L);
  401. /* -----------------------------------------------------------------------
  402. Lua Stingray extensions
  403. ----------------------------------------------------------------------- */
  404. /* Gets an index integer from the stack. This will automatically convert
  405. from 1-based (Lua convention) to 0-based (C convention). */
  406. int (*getindex) (lua_State *L, int idx);
  407. /* Pushes an index integer to the stack. This will automatically convert
  408. from 0-based (C convention) to 1-based (lua convention). */
  409. void (*pushindex) (lua_State *L, int n);
  410. /* As getindex() but uses either 0 or 1 based convention on the Lua side,
  411. depending on user project settings. */
  412. int (*getindex_0_or_1_based) (lua_State *L, int idx);
  413. /* As pushindex() but uses either 0 or 1 based convention on the Lua side,
  414. depending on user project settings. */
  415. void (*pushindex_0_or_1_based) (lua_State *L, int n);
  416. /* Pushes a Vector2 to the stack. */
  417. void (*pushvector2) (lua_State *L, float v[2]);
  418. /* Pushes a Vector3 to the stack. */
  419. void (*pushvector3) (lua_State *L, float v[3]);
  420. /* Pushes a Vector4 to the stack. */
  421. void (*pushvector4) (lua_State *L, float v[4]);
  422. /* Pushes a Quaternion to the stack. */
  423. void (*pushquaternion) (lua_State *L, float q[4]);
  424. /* Pushes a Matrix4x4 to the stack. */
  425. void (*pushmatrix4x4) (lua_State *L, float m[16]);
  426. /* Gets a Vector2 at the specified index. */
  427. float * (*getvector2) (lua_State *L, int i);
  428. /* Gets a Vector3 at the specified index. */
  429. float * (*getvector3) (lua_State *L, int i);
  430. /* Gets a Vector4 at the specified index. */
  431. float * (*getvector4) (lua_State *L, int i);
  432. /* Gets a Quaternion at the specified index. */
  433. float * (*getquaternion) (lua_State *L, int i);
  434. /* Gets a Matrix4x4 at the specified index. */
  435. float * (*getmatrix4x4) (lua_State *L, int i);
  436. /* Gets a Unit at the specified index. */
  437. CApiUnit * (*getunit) (lua_State *L, int i);
  438. /* Gets the Lua state where the main scripts execute. */
  439. lua_State* (*getscriptenvironmentstate)();
  440. /* Returns true if the stack entry is a table. */
  441. int (*istable) (lua_State *L, int i);
  442. /* Returns true if the stack entry is a Vector2. */
  443. int (*isvector2) (lua_State *L, int i);
  444. /* Returns true if the stack entry is a Vector3. */
  445. int (*isvector3) (lua_State *L, int i);
  446. /* Returns true if the stack entry is a Vector4. */
  447. int (*isvector4) (lua_State *L, int i);
  448. /* Returns true if the stack entry is a Quaternion. */
  449. int (*isquaternion) (lua_State *L, int i);
  450. /* Returns true if the stack entry is a Matrix4x4. */
  451. int (*ismatrix4x4) (lua_State *L, int i);
  452. /* Returns true if the stack entry is a UnitReference. */
  453. int (*isunitreference) (lua_State *L, int i);
  454. /* Pops the top value from the Lua stack. */
  455. void (*pop) (lua_State *L);
  456. /* Gets an Entity at the specified index. */
  457. EntityRef (*getentity)(lua_State *L, int i);
  458. /* Pushes an Entity to the stack. */
  459. void (*pushentity)(lua_State *L, EntityRef e_ref);
  460. /* Returns true if the stack entry is a nil. */
  461. int(*isnil) (lua_State *L, int i);
  462. /* Returns true if the stack entry is a boolean. */
  463. int(*isbool) (lua_State *L, int i);
  464. /* Reserved for expansion of the API. */
  465. void *reserved[28];
  466. };
  467. /* ----------------------------------------------------------------------
  468. DataCompiler
  469. ---------------------------------------------------------------------- */
  470. /* Represents a buffer of data. */
  471. struct Buffer
  472. {
  473. /* Pointer to data. */
  474. char *p;
  475. /* Size of data. */
  476. unsigned len;
  477. };
  478. struct ConfigErrorState
  479. {
  480. const char *file;
  481. struct Buffer source;
  482. const char *error;
  483. };
  484. /* Represents the result of a data compile operation. */
  485. struct DataCompileResult
  486. {
  487. /* The memory resident compiled data. */
  488. struct Buffer data;
  489. /* Compiled data available for streaming. */
  490. struct Buffer stream;
  491. /* NULL if compiled successfully, an error message otherwise. */
  492. const char *error;
  493. };
  494. /* Opaque struct representing parameters for a data compile operation. */
  495. struct DataCompileParameters;
  496. /* Opaque struct representing parameters for a entity compile operation. */
  497. struct EntityComponentCompileData;
  498. /* Opaque struct representing parameters for a entity compile operation. */
  499. struct EntityComponentPackageIncludeData;
  500. /* Function type for compiling data. Based on the compile parameters that include
  501. among other things the source data, the compile function should produce a
  502. binary blob that can be accessed as a resource by the runtime. */
  503. typedef struct DataCompileResult (*CompileFunction)(struct DataCompileParameters *data_compile_params);
  504. /* Function for compiling preprocessed data for a closed platform. This is called from a normal
  505. resource compiler to do closed platform specific compilation for a particular platform. The
  506. format of the input data depends on the resource type (note: it is not the raw source data). */
  507. typedef struct DataCompileResult (*RawCompileFunction)(const char *input, unsigned len, struct AllocatorObject *allocator);
  508. /* Function type for compiling additional dependencies. You can use this to add new dependencies
  509. for an existing resource type, such as .level, without changing how that type is compiled.
  510. The function should return NULL if successful and an error string otherwise. */
  511. typedef const char * (*PackageIncludeCompileFunction)(struct DataCompileParameters *data_compile_params);
  512. /* Function type for compiling entity component data. */
  513. typedef struct DataCompileResult (*EntityComponentCompileFunction)(struct EntityComponentCompileData *compile_data, struct EntityComponentPackageIncludeData *package_include_data);
  514. /* Function type for compiling resources to scene databases. */
  515. typedef const char* (*SceneDatabaseCompileFunction)(const char *file_name, const char *data, int64_t length, void *scene_ptr, const char *extract_embedded_path, const char *resource_name, const char *platform_data_folder);
  516. /* Enumerates the texture types that can be returned by custom texture readers. */
  517. enum SourceTextureReadResult_ResultType {
  518. DC_STRR_RT_IMAGE2D,
  519. DC_STRR_RT_IMAGE3D,
  520. DC_STRR_RT_IMAGECUBE,
  521. DC_STRR_RT_UNKNOWN
  522. };
  523. /* Enumerates the texture pixel formats that can be returned by customer texture readers. */
  524. enum SourceTextureReadResult_ResultPixelFormat {
  525. DC_STRR_RPF_R8G8B8A8,
  526. DC_STRR_RPF_R16F,
  527. DC_STRR_RPF_R16G16B16A16F,
  528. DC_STRR_RPF_R16G16F,
  529. DC_STRR_RPF_NUM_FORMATS,
  530. DC_STRR_RPF_UNKNOWN
  531. };
  532. /* Format of the texture data returned by custom texture readers. Currently only one format is
  533. supported, the one described by SourceTextureReadResult */
  534. #define SOURCE_TEXTURE_READ_RESULT_DEFAULT_FORMAT 1
  535. /* Used to return the result of a custom texture read operation. */
  536. struct SourceTextureReadResult {
  537. /* Format of the returned data. This should be equal to SOURCE_TEXTURE_READ_RESULT_DEFAULT_FORMAT. */
  538. unsigned format;
  539. /* Texture dimensions. */
  540. unsigned width;
  541. unsigned height;
  542. /* Format of the pixel data. */
  543. enum SourceTextureReadResult_ResultPixelFormat pixel_format;
  544. /* Type of image. */
  545. enum SourceTextureReadResult_ResultType image_type;
  546. /* Pixel data container. */
  547. struct Buffer data;
  548. /* NULL if read successfully, an error message otherwise. */
  549. const char *error;
  550. };
  551. /* Function type for custom texture readers. */
  552. typedef struct SourceTextureReadResult (*SourceTextureReadFunction)(const char *type, const void *data, unsigned len, struct AllocatorObject *allocator);
  553. /*
  554. API for extending Stingray with your own custom data types.
  555. */
  556. struct DataCompilerApi
  557. {
  558. /* Adds a data compiler for a new data type to the Stingray engine. The version
  559. parameter specifies the version number of the binary data. Increase the number if
  560. you make any changes to the binary format. */
  561. void (*add_compiler)(const char *type, unsigned version, CompileFunction compile);
  562. /* Adds a data compiler for one of the closed platforms (XB1, PS4). (Since these
  563. compilers contain closed code, they can't be in the main engine, but must be
  564. loaded as plugins. */
  565. void (*add_closed_platform_compiler)(const char *platform, const char *type, RawCompileFunction compile);
  566. /* Adds a compile step that can add additional dependencies to an existing resource format,
  567. without otherwise changing how that resource format is compiled. For example, it can be
  568. used to add new dependencies to .level files. */
  569. void (*add_extra_package_include_compiler)(const char *type, int id, int version, PackageIncludeCompileFunction compile);
  570. /* Adds a new texture reader to Stingray. This lets Stingray support additional texture
  571. formats. */
  572. void (*add_texture_reader)(const char *type, SourceTextureReadFunction read);
  573. /* Specifies that the compiler for the specified type uses the FBX SDK. This is needed because
  574. the FBX SDK is not thread safe, so compilers that use the FBX SDK must be serialized
  575. on a single thread. */
  576. void (*set_uses_fbx)(const char *type);
  577. /* Adds an entity component compiler for the specified component typename. */
  578. void(*add_entity_component_compiler)(const char *name, EntityComponentCompileFunction compile, int spawn_order);
  579. /* Adds a scene database compiler for a new data type to the Stingray engine*/
  580. void(*add_scene_database_compiler)(const char *extension, SceneDatabaseCompileFunction compile);
  581. /* Reserved for expansion of the API. */
  582. void *reserved[31];
  583. };
  584. /* ----------------------------------------------------------------------
  585. DataCompileParameters
  586. ---------------------------------------------------------------------- */
  587. /*
  588. Used to get information about a resource that is being compiled.
  589. */
  590. struct DataCompileParametersApi
  591. {
  592. /* Path to the resource on disk. */
  593. const char * (*source_path)(struct DataCompileParameters *input);
  594. /* Name of the resource. */
  595. const char * (*name)(struct DataCompileParameters *input);
  596. /* Gets the string name of the destination platform that the data is compiled for. */
  597. const char * (*destination_platform)(struct DataCompileParameters *input);
  598. /* Parses the input data as a SJSON file and returns a buffer describing the data.
  599. The buffer uses the ConstConfig format and can be interpreted using the ConstConfig
  600. API in plugin_foundation. */
  601. struct DataCompileResult (*parse)(struct DataCompileParameters *input);
  602. /* Reads the input data and returns it as a raw buffer. */
  603. struct DataCompileResult (*read)(struct DataCompileParameters *input);
  604. /* Used to read the content of file folders, i.e. folders that are treated as a single
  605. resource by the data compiler (like .s2d folders).
  606. The entire content of the folder will be returned in a buffer with the following layout:
  607. [number_of_files]
  608. [offset_to_path_1] [size_of_path_1] [offset_to_file_data_1] [size_of_file_data_1]
  609. [offset_to_path_2] [size_of_path_2] [offset_to_file_data_2] [size_of_file_data_2]
  610. ...
  611. [offset_to_path_n] [size_of_path_n] [offset_to_file_data_n] [size_of_file_data_n]
  612. [buffer_data]
  613. All the sizes and offsets are uint32_t. */
  614. struct DataCompileResult (*read_file_folder)(struct DataCompileParameters *input);
  615. /* Returns the allocator that should be used to allocate the data returned by the compile
  616. function. */
  617. struct AllocatorObject *(*allocator)(struct DataCompileParameters *input);
  618. /* Creates a package include of the resource specified by (type, name) for the resource that
  619. is being compiled. What this means is that the compiled resource has an automatic dependency
  620. on (type, name), so whenever the compiled resource is included in a package, its
  621. dependencies will follow. This is used for example to ensure that when you include a level
  622. in a package, all its units and their textures follow along. */
  623. void (*include_in_package)(struct DataCompileParameters *input, const char *type, const char *name);
  624. /* Creates a package include of all the resources of the type that match the pattern
  625. `{prefix}*{suffix}`. */
  626. void (*glob_include_in_package)(struct DataCompileParameters *input, const char *prefix, const char *suffix, const char *type);
  627. /* Returns true if the path exists. */
  628. int (*exists)(struct DataCompileParameters *input, const char *path);
  629. /* Reserved for expansion of the API. */
  630. void *reserved[32];
  631. };
  632. /* ----------------------------------------------------------------------
  633. EntityCompileDataApi
  634. ---------------------------------------------------------------------- */
  635. /* API for working with entity compile data. */
  636. struct EntityCompileDataApi
  637. {
  638. /* Returns the allocator to use for compiled data. */
  639. struct AllocatorObject *(*allocator)(struct EntityComponentCompileData *compile_data);
  640. /* Returns the component type definition. */
  641. struct Buffer (*type_definition)(struct EntityComponentCompileData *compile_data, struct AllocatorObject *allocator);
  642. /* Returns the component meta data. */
  643. struct Buffer (*type_metadata)(struct EntityComponentCompileData *compile_data, struct AllocatorObject *allocator);
  644. /* Returns the property for the specified property key. */
  645. struct Buffer (*get_property)(struct EntityComponentCompileData *compile_data, const char *property_key, struct AllocatorObject *allocator, struct ConfigErrorState *es);
  646. /* Returns the merged property for the specified property key. */
  647. struct Buffer (*get_merged_property)(struct EntityComponentCompileData *compile_data, const char *property_key, struct AllocatorObject *allocator, struct ConfigErrorState *es);
  648. };
  649. /* ----------------------------------------------------------------------
  650. Allocator
  651. ---------------------------------------------------------------------- */
  652. /*
  653. API used to allocate memory through an AllocatorObject.
  654. */
  655. struct AllocatorApi
  656. {
  657. /* Create a new allocator for use by the plugin. */
  658. struct AllocatorObject *(*make_plugin_allocator)(const char *plugin_name);
  659. /* Destroys an allocator created by make_plugin_allocator(). You must free all the memory
  660. allocated by the allocator before you destroy it. */
  661. void (*destroy_plugin_allocator)(struct AllocatorObject *);
  662. /* Makes a physical allocator for the plugin. This is an allocator that is guaranteed to
  663. allocate physical (i.e. not virtual) memory. This is needed by certain resource
  664. types that cannot reside in virtual memory.
  665. The allocator should be destroyed by destroy_plugin_allocator(). */
  666. struct AllocatorObject *(*make_plugin_physical_allocator)(const char *plugin_name);
  667. /* Creates a temporary memory allocator. Temporary memory allocators should be used
  668. for short-term memory allocations that are released before a function exits (i.e.
  669. similar to alloca()). Allocations made with the temporary memory allocator do not
  670. have to be explicitly freed. They are automatically freed when you destroy the allocator.
  671. You should call destroy_temp_allocator() to destroy the allocator before exiting the
  672. function.
  673. Temporary allocators are not thread safe and can only be used on the thread that creates
  674. them. */
  675. struct AllocatorObject *(*make_temp_allocator)();
  676. /* Destroys a temporary memory allocator created by make_temp_allocator(). */
  677. void (*destroy_temp_allocator)(struct AllocatorObject *);
  678. /* Allocates memory using the specified allocator. The align parameter specifies the
  679. desired alignment of the allocated memory. */
  680. void *(*allocate)(struct AllocatorObject *allocator, size_t size, unsigned align);
  681. /* Frees memory allocated by allocate(). */
  682. size_t (*deallocate)(struct AllocatorObject *allocator, void *p);
  683. /* Returns the size of the memory block allocated at p. p must be a block of memory allocated
  684. by the specified allocator. Note that the allocated_size() might be greater than the size
  685. requested in the call to allocate(). (Some allocators round up the allocations.) */
  686. size_t (*allocated_size)(struct AllocatorObject *allocator, void *p);
  687. };
  688. /* ----------------------------------------------------------------------
  689. ResourceManager
  690. ---------------------------------------------------------------------- */
  691. /* Opaque struct representing an InputArchive that will become readable at some point in the
  692. future. */
  693. struct FutureInputArchive;
  694. /* Hashed version of a resource names. */
  695. typedef uint64_t ResourceID;
  696. /* Opaque struct representing a context in which changes can be applied to GPU residing resources. */
  697. struct RenderResourceContext;
  698. /* Struct of callbacks used to implement a custom resource type on the runtime side. You don't
  699. need to implement all the functions in this interface. Use NULL for the functions you don't
  700. implement. */
  701. struct RM_ResourceTypeCallbacks
  702. {
  703. /* User data that will be supplied to you in the obj parameter of the callback functions. */
  704. void *user_data;
  705. /* Called to load a resource into memory. `name` is the name of the resource and `archive` its
  706. serialized data. The function should allocate an in-memory representation of the resource
  707. with the `allocator` and return it.
  708. You only need to implement this callback if you want the in-memory representation to be
  709. different than the disk serialized one. The recommendation is to use the same format on
  710. disk as in-memory. Then you can use NULL for this callback and the disk data will
  711. automatically be loaded into memory. */
  712. void *(*load) (void *obj, ResourceID name, struct InputArchive *archive, struct AllocatorObject *allocator, struct RenderResourceContext *rrc);
  713. /* A companion to load(), this is used to destroy the in-memory representation. You only need
  714. to implement this if you implement load(), to destroy the data allocated by load(). */
  715. void (*destroy) (void *obj, void *resource, struct AllocatorObject *allocator, struct RenderResourceContext *rrc);
  716. /* This is called on the main thread, once the resource data has been loaded. Implement this
  717. if you need to register the loaded data in some global structure. */
  718. void (*bring_in) (void *obj, void *resource);
  719. /* Implement this to unregister what you registered in bring_in(). */
  720. void (*bring_out) (void *obj, void *resource);
  721. /* Allocator used to allocate the data if using default load. Use NULL to use the default
  722. allocator. */
  723. struct AllocatorObject *allocator;
  724. /* Desired alignment of the loaded resource data into memory if using default load. Use 0 to
  725. use default alignment. */
  726. unsigned int align;
  727. /* Reserved for expansion of the API. */
  728. void *reserved[32];
  729. };
  730. /*
  731. Interface to the Stingray ResourceManager. The ResourceManager can be used to query for loaded
  732. resources as well as to implement custom loaders for custom types.
  733. */
  734. struct ResourceManagerApi
  735. {
  736. /* Returns the version number of the resource manager. The version number is changed
  737. whenever resources are added or removed. */
  738. unsigned int (*version)();
  739. /* Gets a list of loaded resources for the specified type. The function returns the total
  740. number of loaded resources of the specified type, and the first names_size of these
  741. resources are copied into the names array. You can call the function with zero to size
  742. the array. */
  743. unsigned (*loaded_resources)(const uint64_t type_id, uint64_t *names, unsigned names_size);
  744. /* Registers a new resource type with the resource manager. The type uses the default load
  745. mechanism (i.e. the serialized data will be loaded directly into memory as a data blob,
  746. with no additional patching). */
  747. void (*register_type)(const char *type);
  748. /* Registers a new resource type with custom load functionality. */
  749. void (*register_type_with_callbacks)(const char *type, struct RM_ResourceTypeCallbacks * data);
  750. /* Returns true if there is a loaded resource with the specified type and name. */
  751. int (*can_get)(const char *type, const char *name);
  752. /* As can_get(), but uses a hashed type and name instead. */
  753. int (*can_get_by_id)(uint64_t type_id, uint64_t name_id);
  754. /* Returns the loaded resource identified by (type, name). This will assert if there is no
  755. resource loaded with the specified type and name. */
  756. void *(*get)(const char *type, const char *name);
  757. /* As get() but uses a hashed type and name instead. */
  758. void *(*get_by_id)(uint64_t type_id, uint64_t name_id);
  759. /* Opens the streamed data belonging to the resource. When you are done with using the data
  760. you should destroy it with delete_stream().
  761. The data is returned as a FutureInputArchive... this is an input stream that will be
  762. ready for reading at some point in the future. */
  763. struct FutureInputArchive * (*new_open_stream)(struct AllocatorObject * allocator,
  764. const char * type, const char * name);
  765. /* As new_open_stream() but uses a hashed type and name instead. */
  766. struct FutureInputArchive * (*new_open_stream_by_id)(struct AllocatorObject * allocator,
  767. uint64_t type_id, uint64_t name_id);
  768. /* Destroys a stream opened by new_open_stream(). */
  769. void (*delete_stream)(struct FutureInputArchive * fia, struct AllocatorObject * allocator);
  770. /* Returns true if the specified resource is online. */
  771. int(*is_online)(const char *type, const char *name);
  772. /* As is_online() but uses a hashed type and name instead. */
  773. int(*is_online_by_id)(uint64_t type_id, uint64_t name_id);
  774. /* Reserved for expansion of the API. */
  775. void *reserved[30];
  776. };
  777. /* ----------------------------------------------------------------------
  778. FutureInputArchive
  779. ---------------------------------------------------------------------- */
  780. /*
  781. Interface for FutureInputArchives. A FutureInputArchive is used to represent a file that will
  782. become readable at some point in the future. A future is used, since accessing the file
  783. immediately might cause a stall.
  784. */
  785. struct FutureInputArchiveApi
  786. {
  787. /* Returns true if the archive is ready to be used, i.e. if new_archive() will succeed without
  788. stalling. */
  789. int (*ready)(struct FutureInputArchive * fia);
  790. /* Waits for the archive to be ready for usage. Note that this will stall the waiting thread. */
  791. void (*wait)(struct FutureInputArchive * fia);
  792. /* Cancels the request for the InputArchive. You can use this if you decide that you are no
  793. longer interested in reading from the archive.
  794. A FutureInputArchive should always be properly closed, either by calling cancel() on it,
  795. or by calling new_archive() to explicitly create an InputArchive from it. */
  796. void (*cancel)(struct FutureInputArchive * fia);
  797. /* Creates an InputArchive from the FutureInputArchive. The created archive must be destroyed
  798. with delete_archive(). This function will stall if the archive is not ready to be opened. */
  799. struct InputArchive * (*new_archive)(struct FutureInputArchive * fia,
  800. struct AllocatorObject * allocator);
  801. /* Deletes an archive created by new_archive(). You must delete the archive when done with it. */
  802. void (*delete_archive)(struct InputArchive * fia, struct AllocatorObject * allocator);
  803. /* Reserved for expansion of the API. */
  804. void *reserved[32];
  805. };
  806. /* ----------------------------------------------------------------------
  807. InputArchive
  808. ---------------------------------------------------------------------- */
  809. /*
  810. Interface that represents a stream of data from disk or memory.
  811. */
  812. struct InputArchiveApi
  813. {
  814. /* Reads size bytes from the archive into the buffer. */
  815. void (*read)(struct InputArchive * input_archive, void *buffer, unsigned size);
  816. /* Sets the read position of the archive to the specified offset. */
  817. void (*set_position)(struct InputArchive * input_archive, int64_t position);
  818. /* Returns the size of the archive. */
  819. int64_t (*size)(struct InputArchive * input_archive);
  820. /* Provides raw access to the input buffer that feeds the archive. Accessing the input
  821. buffer directly is needed if you want to be able to stream data from the archive
  822. without stalling. (Just calling read() on a disk archive might stall your thread.) */
  823. struct InputBuffer * (*buffer)(struct InputArchive * input_archive);
  824. /* Reserved for expansion of the API. */
  825. void *reserved[32];
  826. };
  827. /* ----------------------------------------------------------------------
  828. InputBuffer
  829. ---------------------------------------------------------------------- */
  830. /*
  831. Interface for performing low level operations (such as streaming) on a stream of input data.
  832. */
  833. struct InputBufferApi
  834. {
  835. /* The total size of the input buffer data. A never ending buffer will return INT64_MAX. */
  836. int64_t (*size)(struct InputBuffer * input_buffer);
  837. /* The number of bytes available to be read directly from the pointer without streaming in
  838. more data. */
  839. unsigned (*available)(struct InputBuffer * input_buffer);
  840. /* Consumes `bytes` bytes. Note that that many bytes must be available in the buffer. */
  841. void (*consume)(struct InputBuffer * input_buffer, unsigned bytes);
  842. /* Ensures that at least the specified number of bytes are available in
  843. the buffer. Will flush (stall) to fetch the bytes if necessary. */
  844. void (*ensure)(struct InputBuffer * input_buffer, unsigned bytes);
  845. /* Returns a raw pointer to the start of the input stream. You can read available() bytes
  846. from the stream and then consume() those bytes to advance the stream pointer. */
  847. void * (*ptr)(struct InputBuffer * input_buffer);
  848. /* Returns the current offset of the readhead. */
  849. int64_t (*position)(struct InputBuffer * input_buffer);
  850. /* Sets the stream readhead to the specified position. */
  851. void (*set_position)(struct InputBuffer * input_buffer, int64_t offset);
  852. /* Sets the size of the "chunks" used to stream in data from disk.
  853. Typically an input buffer keeps two chunks in flight, and when you have consumed one chunk
  854. fully, a new one is streamed in, in the background. */
  855. void (*set_read_chunk)(struct InputBuffer * input_buffer, unsigned size);
  856. /* Fetches more data from the source, ensuring that at least the specified number of
  857. bytes are available. This might stall. */
  858. void (*flush)(struct InputBuffer * input_buffer, unsigned bytes);
  859. /* Returns true if a flush with a byte size of 0 will succeed without stalling.
  860. (I.e. if all pending I/O operations have finished.) */
  861. int (*can_flush_without_stalling)(struct InputBuffer * input_buffer);
  862. /* Reserved for expansion of the API. */
  863. void *reserved[32];
  864. };
  865. /* ----------------------------------------------------------------------
  866. Logging
  867. ---------------------------------------------------------------------- */
  868. /*
  869. Interface to log messages to the editor console.
  870. */
  871. struct LoggingApi
  872. {
  873. /* Logs an informational message */
  874. void (*info)(const char *system, const char *info);
  875. /* Logs a warning message. */
  876. void (*warning)(const char *system, const char *warning);
  877. /* Logs an error message. */
  878. void (*error)(const char *system, const char *error);
  879. };
  880. /* ----------------------------------------------------------------------
  881. RendererInterface
  882. ---------------------------------------------------------------------- */
  883. /* Opaque struct representing the render device. On a D3D platform, this will be ID3D11Device. */
  884. struct RI_Device;
  885. /* Enum describing the different resource types used by the renderer. */
  886. enum RI_ResourceType {
  887. RI_RESOURCE_TEXTURE,
  888. RI_RESOURCE_RENDER_TARGET,
  889. RI_RESOURCE_NOT_INITIALIZED = 0x00FFFFFF
  890. };
  891. /* Used to identify a render resource. */
  892. struct RenderResource {
  893. unsigned handle;
  894. };
  895. #if defined(WINDOWSPC) || defined(XBOXONE) || defined(UWP)
  896. /* D3D rendering interface. */
  897. struct ID3D11RenderTargetView;
  898. struct ID3D11ShaderResourceView;
  899. struct ID3D11Texture2D;
  900. struct IDXGISwapChain;
  901. struct RI_PlatformTexture2d
  902. {
  903. struct ID3D11Texture2D *texture;
  904. struct ID3D11ShaderResourceView *resource_view;
  905. struct ID3D11ShaderResourceView *resource_view_srgb;
  906. };
  907. struct RI_PlatformRenderTarget
  908. {
  909. struct ID3D11RenderTargetView *render_target_view;
  910. };
  911. struct RI_PlatformSwapChain
  912. {
  913. struct IDXGISwapChain *dxgi_swap_chain;
  914. };
  915. struct RI_PlatformWindow
  916. {
  917. void *window;
  918. };
  919. #else
  920. /* TODO: Implement RI_PlatformRenderTarget for other platforms. */
  921. struct RI_PlatformRenderTarget { char unused; };
  922. #if defined(ANDROID)
  923. /* cf. gl::Context */
  924. struct RI_Device {
  925. void* context; /* EGLContext */
  926. void* display; /* EGLDisplay */
  927. void* surface; /* EGLSurface */
  928. void* config; /* EGLConfig */
  929. };
  930. #endif
  931. #if defined(MACOSX) || defined(IOS) || defined(ANDROID) || defined(WEB) || defined(LINUXPC)
  932. struct RI_PlatformTexture2d {
  933. unsigned int handle; /* binding handle */
  934. unsigned int format; /* internal pixel format, e.g., GL_DEPTH24_STENCIL8, GL_R16F */
  935. unsigned int type; /* channel type info, e.g., GL_UNSIGNED_INT_24_8, GL_UNSIGNED_BYTE */
  936. unsigned int width;
  937. unsigned int height;
  938. unsigned int size; /* size in bytes used by the texture */
  939. };
  940. #else
  941. /* TODO: Implement Texture2D for other platforms. */
  942. struct RI_PlatformTexture2d { char unused; };
  943. #endif
  944. /* TODO: Implement SwapChain and Window for other platforms. */
  945. struct RI_PlatformSwapChain { char unused; };
  946. struct RI_PlatformWindow { char unused; };
  947. #endif
  948. /*
  949. Interface to the Stingray renderer.
  950. */
  951. struct RenderInterfaceApi
  952. {
  953. /* Creates a fence for the GPU. */
  954. int (*create_fence)();
  955. /* Wait for the GPU to reach the specified fence. */
  956. void (*wait_for_fence)(int);
  957. /* Run the specified callback function on the render thread. */
  958. void (*run_callback)(void(*callback)(void* data), void* user_data, uint32_t user_data_size);
  959. /* Returns the render device. */
  960. struct RI_Device* (*device)();
  961. /* Returns the named global render resource. */
  962. struct RenderResource* (*global_render_resource)(const char *name);
  963. /* Returns a texture. */
  964. struct RI_PlatformTexture2d (*texture_2d)(struct RenderResource *render_resource);
  965. /* Returns the swap chain. */
  966. struct RI_PlatformSwapChain (*swap_chain)(unsigned handle);
  967. /* Returns the render target for the specified swap chain, layer and mip_level. */
  968. struct RI_PlatformRenderTarget (*render_target)(unsigned handle, int layer, int mip_level);
  969. /* Returns the window corresponding to the specified handle. */
  970. struct RI_PlatformWindow (*window)(unsigned handle);
  971. /* Sets render setting values that are applied to the render configuration */
  972. void (*set_render_setting)(const char* name, ConstConfigRootPtr value);
  973. /* Reserved for expansion of the API. */
  974. void *reserved[31];
  975. };
  976. /* ----------------------------------------------------------------------
  977. Unit
  978. ---------------------------------------------------------------------- */
  979. /* Enum for the different kinds of physics actors supported. */
  980. enum U_ActorType {
  981. U_ACTOR_SPHERE = 0,
  982. U_ACTOR_PLANE = 1,
  983. U_ACTOR_CAPSULE = 2,
  984. U_ACTOR_BOX = 3,
  985. U_ACTOR_CONVEXMESH = 4,
  986. U_ACTOR_TRIANGLEMESH = 5,
  987. U_ACTOR_HEIGHTFIELD = 6
  988. };
  989. /* Opaque struct representing a collision filter, that specifies which actors collide with which
  990. other actors. */
  991. struct CollisionFilter;
  992. /* Represents a triangle mesh. */
  993. struct U_TriangleMesh
  994. {
  995. const char *indices;
  996. unsigned num_triangles;
  997. unsigned index_stride;
  998. const char *vertices;
  999. unsigned vertex_stride;
  1000. float transform[16];
  1001. };
  1002. struct U_BoundingVolume
  1003. {
  1004. float min[3];
  1005. float max[3];
  1006. float radius;
  1007. };
  1008. /* Represents a convex mesh. */
  1009. struct U_ConvexMesh
  1010. {
  1011. const char *indices;
  1012. unsigned num_polygons;
  1013. unsigned index_stride;
  1014. const char *vertices;
  1015. unsigned vertex_stride;
  1016. float transform[16];
  1017. };
  1018. /* Represents a height field. */
  1019. struct U_HeightField
  1020. {
  1021. unsigned num_rows;
  1022. unsigned num_columns;
  1023. float row_scale;
  1024. float column_scale;
  1025. };
  1026. /* Represents a sphere. */
  1027. struct U_Sphere
  1028. {
  1029. float transform[16];
  1030. float radius;
  1031. };
  1032. /* Represents a capsule. */
  1033. struct U_Capsule
  1034. {
  1035. float transform[16];
  1036. float radius;
  1037. float half_height;
  1038. };
  1039. /* Represents a box. */
  1040. struct U_Box
  1041. {
  1042. float transform[16];
  1043. float half_extents[3];
  1044. };
  1045. /* Represents a position in the height field. */
  1046. struct U_HeightFieldPos
  1047. {
  1048. float pos[3];
  1049. };
  1050. /* Represents animation clip playback information */
  1051. struct U_AnimationPlayingInfo
  1052. {
  1053. uint64_t clip_resource_id;
  1054. double time;
  1055. double length;
  1056. uint8_t loop;
  1057. };
  1058. /* Opaque struct representing a hierarchy of objects in a Unit. */
  1059. struct SceneGraph;
  1060. /*
  1061. Interface for interacting with units.
  1062. */
  1063. struct UnitApi
  1064. {
  1065. /* Returns the unit's scene graph. */
  1066. struct SceneGraph * (*scene_graph)(CApiUnit *unit);
  1067. /* Returns a reference to the unit. Unit references are weak pointers that get invalidated when
  1068. the unit dies. */
  1069. CApiUnitRef (*reference)(CApiUnit * unitobject);
  1070. /* Returns the number of meshes in the unit. */
  1071. int (*num_meshes)(CApiUnit *unit);
  1072. /* Returns the mesh at the specified index. */
  1073. void (*mesh)(CApiUnit *unit, int mesh_index, struct U_TriangleMesh *mesh);
  1074. /* Returns the hashed name of the mesh at the specified index. */
  1075. uint32_t (*mesh_name)(CApiUnit *unit, int mesh_index);
  1076. /* Returns the index of the scene graph node that owns the mesh at the specified index. */
  1077. int (*mesh_node)(CApiUnit *unit, int mesh_index);
  1078. /* True if the specified mesh is visible. */
  1079. int (*is_mesh_visible)(CApiUnit *unit, int mesh_index);
  1080. /* Returns the number of actors in the unit. */
  1081. int (*num_actors)(CApiUnit *unit);
  1082. /* Returns the actor at the specified index. */
  1083. CApiActor* (*actor)(CApiUnit *unit, int index);
  1084. /* True if collisions are enabled for the specified actor. */
  1085. int (*is_collision_enabled)(CApiActor *ao);
  1086. /* True if the specified actor is static. */
  1087. int (*is_static)(CApiActor *ao);
  1088. /* True if the specified actor is kinematic. */
  1089. int (*is_kinematic)(CApiActor * ao);
  1090. /* Returns the number of shapes in the actor. */
  1091. int (*num_shapes)(CApiActor* ao);
  1092. /* Returns the type of the shape at the specified index. */
  1093. int (*shape_type)(CApiActor *ao, int shape_index);
  1094. /* Gets shape data for a sphere shape. Returns false if shape is not a sphere. */
  1095. int (*sphere)(CApiActor *ao, int shape_index, struct U_Sphere *so);
  1096. /* Gets shape data for a capsule shape. Returns false if shape is not a capsule. */
  1097. int (*capsule)(CApiActor *ao, int shape_index, struct U_Capsule *co);
  1098. /* Gets shape data for a box shape. Returns false if shape is not a box. */
  1099. int (*box)(CApiActor *ao, int shape_index, struct U_Box *bo);
  1100. /* Gets shape data for a mesh shape. Returns false if shape is not a mesh. */
  1101. int (*triangle_mesh)(CApiActor *ao, int shape_index, struct U_TriangleMesh *mesh);
  1102. /* Gets shape data for a convex shape. Returns false if shape is not a convex. */
  1103. int (*convex_mesh)(CApiActor *ao, int shape_index, struct U_ConvexMesh *convexmesh);
  1104. /* Returns the number of vertices of the specified polygon in the convex shape. */
  1105. int (*convex_mesh_polygon_num_vertices)(CApiActor *ao, int shape_index, int polygon_index);
  1106. /* Returns the index at which the polygon's vertices start in the convex mesh's
  1107. vertex buffer. */
  1108. int (*convex_mesh_polygon_base_index)(CApiActor *ao, int shape_index, int polygon_index);
  1109. /* Gets shape data for a height field shape. Returns false if shape is not a height field. */
  1110. int (*height_field)(CApiActor *ao, int shape_index, struct U_HeightField *height_field);
  1111. /* Returns the height field position at the specified coordinates. */
  1112. int (*height_field_position)(CApiActor *ao, int shape_index, float x, float y, struct U_HeightFieldPos *pos);
  1113. /* Returns the unit's mover (character controller). */
  1114. CApiMover* (*mover)(CApiUnit *unit);
  1115. /* Returns the collision filter of the mover. */
  1116. struct CollisionFilter* (*collision_filter)(CApiMover *mo);
  1117. /* Returns the hash of the unit's resource name. */
  1118. uint64_t (*unit_resource_name)(CApiUnit *unit);
  1119. /* Gets the value of the unit animation curve for the specified object and parameter.
  1120. Returns true if the curve value was successfully fetched. */
  1121. uint8_t (*get_curve_value)(CApiUnit *unit, uint32_t object, uint32_t parameter, unsigned count, float* floats);
  1122. /* The world that the unit lives in. */
  1123. CApiWorld* (*world)(CApiUnit *unit);
  1124. /* Query number of playing animation clips and fill in playback details. */
  1125. uint32_t (*get_playing_animation_infos)(CApiUnit *unit, uint32_t layer_id, struct U_AnimationPlayingInfo *playing_infos, uint32_t maximum);
  1126. /* Returns the bounding volume of the mesh at the specified index. */
  1127. void(*mesh_bounding_volume)(CApiUnit *unit, int mesh_index, struct U_BoundingVolume *bounding_volume);
  1128. /* Reserved for expansion of the API. */
  1129. void *reserved[30];
  1130. };
  1131. /*
  1132. Interface for working with unit references. Unit references are weak pointers that get
  1133. invalidated when the unit is destroyed.
  1134. */
  1135. struct UnitReferenceApi
  1136. {
  1137. /* Dereferences the reference into a unit pointer. Returns NULL if the unit has been
  1138. destroyed. */
  1139. CApiUnit * (*dereference)(CApiUnitRef ref);
  1140. /* Reserved for expansion of the API. */
  1141. void *reserved[32];
  1142. };
  1143. /* ----------------------------------------------------------------------
  1144. SceneGraph
  1145. ---------------------------------------------------------------------- */
  1146. /* Opaque struct that represents the "dirty" state of nodes in a unit's scene graph. I.e. a bit
  1147. flag for each node that is dirty and needs its transform updated. */
  1148. struct SceneFlags;
  1149. /*
  1150. Interface for manipulating scene graphs (i.e., node hierarchies inside units).
  1151. */
  1152. struct SceneGraphApi
  1153. {
  1154. /* Returns the world matrix of the node in the scene graph with specified index. The matrix
  1155. is returned as an array of 16 floats. */
  1156. const float * (*world)(struct SceneGraph * scene_graph, int index);
  1157. /* Returns the local transform of the node with the specified index. */
  1158. const CApiLocalTransform * (*local)(struct SceneGraph *scene_graph, int index);
  1159. /* Returns the scene graph's render handle to be used with the RenderSceneGraphApi. */
  1160. uint32_t (*render_handle)(struct SceneGraph *scene_graph);
  1161. /* Transforms the scene graph using the specified node as root. This updates the world
  1162. transforms of all objects based on their parent's transform and their local transforms. */
  1163. void (*transform_with_root)(struct SceneGraph *scene_graph, int index, ConstMatrix4x4Ptr root);
  1164. /* Unlinks the node at the index from its current parent. */
  1165. void (*unlink_internal)(struct SceneGraph *scene_graph, int index);
  1166. /* Relinks a node back to its parent. */
  1167. void (*relink_internal)(struct SceneGraph *scene_graph, int index);
  1168. /* Returns the total number of nodes in the scene graph. */
  1169. uint32_t (*num_nodes)(struct SceneGraph *scene_graph);
  1170. /* Returns the index of the parent node to the node at the specified index. If the node
  1171. doesn't have a parent, this function returns -1. */
  1172. int (*parent)(struct SceneGraph *scene_graph, int index);
  1173. /* Returns true if the node with the specified index is a root (i.e., does not have a parent
  1174. node). */
  1175. uint8_t (*is_root)(struct SceneGraph * scene_graph, int index);
  1176. /* Returns the 32 bit hash of the node's name. */
  1177. uint32_t (*name)(struct SceneGraph *scene_graph, int index);
  1178. /* Returns a pointer to an array with the hashes of all the node names in the scene graph. */
  1179. uint32_t * (*names_array_pointer)(struct SceneGraph *scene_graph);
  1180. /* Returns the array of dirty flags. This is a bit array with the bit set for each node that
  1181. has a local transform change that has not yet been reflected to its world transform. This
  1182. array can be(useful when defining a post animation callback that changes local node transforms. */
  1183. struct SceneFlags * (*dirty_array_pointer)(struct SceneGraph *scene_graph);
  1184. /* Reserved for expansion of the API. */
  1185. void *reserved[32];
  1186. };
  1187. /* ----------------------------------------------------------------------
  1188. Application
  1189. ---------------------------------------------------------------------- */
  1190. /* Opaque struct that represents the command-line options that were passed to the application at
  1191. launch. */
  1192. struct ApplicationOptions;
  1193. /* Abstract struct that can be cast to either ANativeActivity or UIApplication based on the
  1194. platform. */
  1195. struct AP_PlatformActivity;
  1196. /* Specifies whether callbacks should be called before the activity happens or after it happens. */
  1197. enum AP_PlatformCallbackOrder
  1198. {
  1199. AP_PRE_ACTIVITY,
  1200. AP_POST_ACTIVITY
  1201. };
  1202. /* Callbacks for Android activity events. See Android documentation. */
  1203. struct AndroidActivityCallbacks
  1204. {
  1205. void (*start)(struct AP_PlatformActivity*);
  1206. void (*resume)(struct AP_PlatformActivity*);
  1207. void * (*save_instance_state)(struct AP_PlatformActivity*, size_t*);
  1208. void (*pause)(struct AP_PlatformActivity*);
  1209. void (*stop)(struct AP_PlatformActivity*);
  1210. void (*destroy)(struct AP_PlatformActivity*);
  1211. void (*window_focus_changed)(struct AP_PlatformActivity*, int);
  1212. void (*native_window_created)(struct AP_PlatformActivity*, void*);
  1213. void (*native_window_resized)(struct AP_PlatformActivity*, void*);
  1214. void (*native_window_redraw_needed)(struct AP_PlatformActivity*, void*);
  1215. void (*native_window_destroyed)(struct AP_PlatformActivity*, void*);
  1216. void (*input_queue_created)(struct AP_PlatformActivity*, void*);
  1217. void (*input_queue_destroyed)(struct AP_PlatformActivity*, void*);
  1218. void (*content_rect_changed)(struct AP_PlatformActivity*, const void*);
  1219. void (*configuration_changed)(struct AP_PlatformActivity*);
  1220. void (*low_memory)(struct AP_PlatformActivity*);
  1221. };
  1222. /* Callbacks for iOS activity events. See iOS documentation. */
  1223. struct IOSActivityCallbacks
  1224. {
  1225. void (*did_finish_launching)(struct AP_PlatformActivity*);
  1226. void (*will_enter_foreground)(struct AP_PlatformActivity*);
  1227. void (*will_terminate)(struct AP_PlatformActivity*);
  1228. void (*did_receive_memory_warning)(struct AP_PlatformActivity*);
  1229. void (*will_resign_active)(struct AP_PlatformActivity*);
  1230. void (*did_enter_background)(struct AP_PlatformActivity*);
  1231. void (*did_become_active)(struct AP_PlatformActivity*);
  1232. };
  1233. /* Abstract struct representing platform activity callbacks that should be either an
  1234. AndroidActivityCallbacks or an IOSActivityCallbacks. */
  1235. struct PlatformActivityCallbacks;
  1236. /* Function type for receiving console commands. client_id is the ID of the console client
  1237. instigating the command. ConstConfigRootPtr is a ConstConfig representation of the console
  1238. command's JSON data. data and data_length is any binary data that was sent with the command. */
  1239. typedef void (*AP_ReceiverFunction)(void *user_data, int client_id, ConstConfigRootPtr dv,
  1240. const char *data, uint32_t data_length);
  1241. /* Wraps a console command receiver callback with a user_data value that will be passed to the
  1242. callback. */
  1243. struct AP_ReceiverUserDataWrapper
  1244. {
  1245. void * user_data;
  1246. AP_ReceiverFunction function;
  1247. };
  1248. /*
  1249. Interface for manipulating the application.
  1250. */
  1251. struct ApplicationApi
  1252. {
  1253. /* Returns the command-line options that were passed to the application at launch. */
  1254. const struct ApplicationOptions * (*options)();
  1255. /* Returns a representation of the settings.ini file used with the application. The settings
  1256. are returned as a pointer to a ConstConfigRoot item and can be parsed using the ConstConfig
  1257. API in the plugin foundation. */
  1258. const void * (*settings)();
  1259. /* Returns the activity interface for native lifecycle handling. */
  1260. struct AP_PlatformActivity * (*platform_activity)();
  1261. /* Register platform activity callbacks to be called on platform activity events. */
  1262. void (*register_platform_callbacks)(enum AP_PlatformCallbackOrder,
  1263. const struct PlatformActivityCallbacks*);
  1264. /* Unregisters callbacks registered with register_platform_callbacks(). */
  1265. void (*unregister_platform_callbacks)(enum AP_PlatformCallbackOrder,
  1266. const struct PlatformActivityCallbacks*);
  1267. /* Returns the number of worlds managed by the application. */
  1268. int (*num_worlds)();
  1269. /* Returns the world at the specified index. */
  1270. CApiWorld * (*world)(int index);
  1271. /* Returns a string identifying the Stingray version. */
  1272. const char * (*product_version)();
  1273. /* Hooks a receiver function for console connection commands. This allows you to extend the
  1274. console interface with your own commands. */
  1275. void (*hook_console_receiver)(const char *type, struct AP_ReceiverUserDataWrapper *user_wrapper);
  1276. /* Unhooks a receiver hooked with hook_console_receiver(). */
  1277. void (*unhook_console_receiver)(const char *type);
  1278. /* Can be used in console receivers to get the id of the console connection that originated
  1279. the command. */
  1280. int (*current_client_id)();
  1281. /* Returns the holographic space created early in the app lifecycle when on the Hololens platform.
  1282. Null otherwise. TODO: Adding a plugin hook early enough in the app lifecycle (pre-window activation)
  1283. would alleviate the need for this API member. */
  1284. void * (*holographic_space)();
  1285. /* Sends data over a console connection. The data sent can be a combination of textual data
  1286. (JSON) and a binary payload. If sync is true, the send is synchronized. If client_id is
  1287. not -1, then the message is only sent to that particular console client instead of
  1288. broadcast to everybody. */
  1289. void (*console_send_with_binary_data)(const char *text, uint32_t text_len, const char *data,
  1290. uint32_t data_len, uint8_t sync, int client_id);
  1291. /* Returns the swap chain handle of a window */
  1292. unsigned (*swap_chain_handle_for_window)(void *window);
  1293. /* Reserved for expansion of the API. */
  1294. void *reserved[31];
  1295. };
  1296. /* ----------------------------------------------------------------------
  1297. ApplicationOptions
  1298. ---------------------------------------------------------------------- */
  1299. /*
  1300. Interface to read the command options used when launching the application.
  1301. */
  1302. struct ApplicationOptionsApi
  1303. {
  1304. /* Returns the bundle directory if the engine was launched in bundle mode. */
  1305. const char * (*bundle_directory)(const struct ApplicationOptions * application_options);
  1306. /* Returns the data directory if the engine was launched in data directory mode. */
  1307. const char * (*data_directory)(const struct ApplicationOptions * application_options);
  1308. /* Returns true if rendering is enabled. */
  1309. int (*is_rendering_enabled)(const struct ApplicationOptions * application_options);
  1310. /* Reserved for expansion of the API. */
  1311. void *reserved[31];
  1312. };
  1313. /* ----------------------------------------------------------------------
  1314. ErrorContext
  1315. ---------------------------------------------------------------------- */
  1316. /*
  1317. Allows plugins to use the error context functionality on custom threads created by
  1318. the plugin.
  1319. */
  1320. struct ErrorContextApi
  1321. {
  1322. /* Creates a thread error context stack for the current thread. */
  1323. void (*make_thread_error_context_stack)(struct AllocatorObject *allocator);
  1324. /* Deletes the thread error context stack for the current thread. */
  1325. void (*delete_thread_error_context_stack)(struct AllocatorObject *allocator);
  1326. /* Returns true if the current thread has en error context stack and false otherwise. */
  1327. int (*has_thread_error_context_stack)();
  1328. /* Reserved for expansion of the API. */
  1329. void *reserved[32];
  1330. };
  1331. /* ----------------------------------------------------------------------
  1332. Raycast
  1333. ---------------------------------------------------------------------- */
  1334. /*
  1335. Interface for performing raycasts.
  1336. */
  1337. struct RaycastApi
  1338. {
  1339. /* Casts a ray into the world, from the origin in the specified direction. Only actors matching
  1340. the collision filter are considered. If a hit is found, the function returns true and sets
  1341. the hit position and normal in the out parameters. */
  1342. int (*find_first_collision)(
  1343. CApiWorld *world,
  1344. float ray_origin_x, float ray_origin_y, float ray_origin_z,
  1345. float ray_direction_x, float ray_direction_y, float ray_direction_z,
  1346. float ray_length,
  1347. struct CollisionFilter *collision_filter,
  1348. float *hit_position_x, float *hit_position_y, float *hit_position_z,
  1349. float *hit_normal_x, float *hit_normal_y, float *hit_normal_z);
  1350. /* Reserved for expansion of the API. */
  1351. void *reserved[32];
  1352. };
  1353. /* ----------------------------------------------------------------------
  1354. FileSystem
  1355. ---------------------------------------------------------------------- */
  1356. /* Opaque struct representing a file system. */
  1357. struct FileSystem;
  1358. /*
  1359. Interface for accessing a file system.
  1360. */
  1361. struct FileSystemApi
  1362. {
  1363. /* Returns true if a file with the specified name exists in the file system. */
  1364. int (*exists)(struct FileSystem *filesystem, const char *filename);
  1365. /* Creates a new disk file system with the specified directory as its root. You can use
  1366. the empty string for the directory if you want a file system that represents the entire
  1367. disk. */
  1368. struct FileSystem * (*create)(const char *directory);
  1369. /* Destroys a file syste created by create(). */
  1370. void (*destroy)(struct FileSystem *filesystem);
  1371. /* Returns true if the specified path is a directory, false if it isn't or if there
  1372. was an error. If there was an error, the error message is returned in the error
  1373. parameter. */
  1374. int (*is_directory)(struct FileSystem *filesystem, const char *file, const char **error);
  1375. /* Creates a directory at the specified path. Returns NULL if successful and an
  1376. error message otherwise. */
  1377. const char * (*make_directory)(struct FileSystem *filesystem, const char *file);
  1378. /* Reads file, parses it into ConstConfig */
  1379. ConstConfigRootPtr (*parse_sjson)(struct FileSystem *filesystem, const char *file, struct AllocatorObject *allocator, const char **error);
  1380. /* Reserved for expansion of the API. */
  1381. void *reserved[31];
  1382. };
  1383. /* ----------------------------------------------------------------------
  1384. PluginManager
  1385. ---------------------------------------------------------------------- */
  1386. /*
  1387. Interface for manipulating the plugin system.
  1388. */
  1389. struct PluginManagerApi
  1390. {
  1391. /* On-demand loads the plugin at the specified path. */
  1392. void (*load_relative_plugin)(const char *plugin_relative_path);
  1393. /* Used to enumerate services exposed by plugins. Call it with an API ID and NULL to retrieve
  1394. a pointer to the first interface that implements a certain API. Repeat the call with the
  1395. previously returned pointer to continue enumerating implementations. The function will
  1396. return NULL when all interfaces have been enumerated.
  1397. Note that this function will only enumerate services implemented in plugins, not the ones
  1398. implemented in the engine. */
  1399. void *(*get_next_plugin_api)(unsigned api_id, void *prev_api);
  1400. /* Reserved for expansion of the API. */
  1401. void *reserved[32];
  1402. };
  1403. /* ----------------------------------------------------------------------
  1404. World
  1405. ---------------------------------------------------------------------- */
  1406. /* Opaque struct representing a scope for drawing lines. */
  1407. struct LineObjectDrawer;
  1408. /* Callback to be called after animations have been evaluated. */
  1409. typedef void (*PostAnimationCallback)(CApiWorld * world_object, float dt);
  1410. /*
  1411. Interface for accessing the world.
  1412. */
  1413. struct WorldApi
  1414. {
  1415. /* Returns a LineObjectDrawer that can be used to draw debug lines into the world. */
  1416. struct LineObjectDrawer * (*line_object_drawer)(CApiWorld * world);
  1417. /* Registers a callback that will run after animations (forward kinematics) have been run.
  1418. This can be used to implement IK and other animation controllers. */
  1419. void (*register_post_animation_callback)(CApiWorld * world, PostAnimationCallback function);
  1420. /* Unregisters a callback registered with register_post_animation_callback(). */
  1421. void (*unregister_post_animation_callback)(CApiWorld * world, PostAnimationCallback function);
  1422. /* Finds all the instances of the named unit resource in the level. The unit resource is
  1423. identified by a 64 bit hash.
  1424. The function returns the total number of units of the specified type found in the level
  1425. and the first units_size of these are copied into the array. */
  1426. unsigned (*find_units_by_resource_name)(CApiWorld *world, uint64_t resource_name,
  1427. CApiUnit **units, unsigned units_size);
  1428. /* Reserved for expansion of the API. */
  1429. void *reserved[32];
  1430. };
  1431. /* ----------------------------------------------------------------------
  1432. LineObjectDrawer
  1433. ---------------------------------------------------------------------- */
  1434. /* Opaque struct that represents a collection of drawn lines. */
  1435. struct LineObject;
  1436. /*
  1437. Interface for drawing debug lines.
  1438. */
  1439. struct LineObjectDrawerApi
  1440. {
  1441. /* Creates a new line object for drawing a number of lines. */
  1442. struct LineObject *(*new_line_object)(struct LineObjectDrawer * drawer);
  1443. /* Frees a line object created by new_line_object(). */
  1444. void (*release_line_object)(struct LineObjectDrawer * drawer, struct LineObject *lo);
  1445. /* Dispatches the lines drawn into the specified line object to the renderer for rendering. */
  1446. void (*dispatch)(struct LineObjectDrawer * drawer, struct StateReflectionStream *srs,
  1447. struct LineObject *lo);
  1448. /* Clears the lines from the line object. */
  1449. void (*reset)(struct LineObject * lo);
  1450. /* Adds a number of lines to the line objects. The colors array encodes the color of each line
  1451. as an ARGB unsigned. The line_starts and line_ends array encode interleaved x, y, z coordinates
  1452. for the start points and end points of each line respectively. n is the total number of lines
  1453. added. */
  1454. void (*add_lines)(struct LineObject * lo, unsigned * colors, float * line_starts, float * line_ends, unsigned n);
  1455. /* Reserved for expansion of the API. */
  1456. void *reserved[32];
  1457. };
  1458. /* ----------------------------------------------------------------------
  1459. Profiler
  1460. ---------------------------------------------------------------------- */
  1461. /*
  1462. Interface to the Stingray profiler.
  1463. */
  1464. struct ProfilerApi
  1465. {
  1466. /* Starts a new profiler scope with the specified name. Each call to profile_start() should
  1467. be matched by a corresponding call to profile_stop(). */
  1468. void (*profile_start)(const char *name);
  1469. /* Ends a profile scope started by profile_start(). */
  1470. void (*profile_stop)();
  1471. /* Function for creating a profiler for a specific thread.
  1472. Must be called on the thread that the profiler should be created for. */
  1473. void (*make_thread_profiler)(struct AllocatorObject *allocator);
  1474. /* Function for deleting a profiler for a specific thread.
  1475. Must be called on the thread that the profiler should be deleted for. */
  1476. void (*delete_thread_profiler)(struct AllocatorObject *allocator);
  1477. /* Checks if the current thread already has a thread profiler. */
  1478. int (*has_thread_profiler)();
  1479. /* Reserved for expansion of the API. */
  1480. void *reserved[29];
  1481. };
  1482. /* ----------------------------------------------------------------------
  1483. Error
  1484. ---------------------------------------------------------------------- */
  1485. /*
  1486. Interface for reporting errors.
  1487. */
  1488. struct ErrorApi
  1489. {
  1490. /* printf() function for generating error messages. The messages will be generated into a ring
  1491. buffer that eventually gets recycled. */
  1492. const char *(*eprintf)(const char *msg, ...);
  1493. /* Reports a crash with the specified error message. */
  1494. void (*report_crash)(const char *msg);
  1495. /* Reports an assert() failure at the specified line and file. */
  1496. void (*report_assert_failure)(int line, const char *file, const char *assert_test, const char *msg);
  1497. /* Reserved for expansion of the API. */
  1498. void *reserved[32];
  1499. };
  1500. /* ----------------------------------------------------------------------
  1501. RenderBuffer
  1502. ---------------------------------------------------------------------- */
  1503. /* Enum for all the texture compression formats supported by the engine. This gets encoded into the
  1504. buffer_format (uint32_t) when the user creates a format using
  1505. RenderBufferApi::compressed_format(). */
  1506. typedef enum
  1507. {
  1508. /* https://en.wikipedia.org/wiki/S3_Texture_Compression */
  1509. RB_BLOCK_COMPRESSED_1 = 0x0, /* BC1 */
  1510. RB_BLOCK_COMPRESSED_2, /* BC2 */
  1511. RB_BLOCK_COMPRESSED_3, /* BC3 */
  1512. RB_BLOCK_COMPRESSED_4, /* BC4 */
  1513. RB_BLOCK_COMPRESSED_5, /* BC5 */
  1514. RB_BLOCK_COMPRESSED_6, /* BC6 */
  1515. RB_BLOCK_COMPRESSED_7, /* BC7 */
  1516. /* https://en.wikipedia.org/wiki/PVRTC */
  1517. RB_PVR_RGB_2BPP = 0x100, /* PVR RGB 2BPP */
  1518. RB_PVR_RGBA_2BPP, /* PVR RGBA 2BPP */
  1519. RB_PVR_RGB_4BPP, /* PVR RGB 4BPP */
  1520. RB_PVR_RGBA_4BPP, /* PVR RGBA 4BPP */
  1521. /* https://en.wikipedia.org/wiki/Ericsson_Texture_Compression */
  1522. RB_ETC2_RGB8 = 0x200, /* ETC2 RGB8 */
  1523. RB_ETC2_RGB8A1, /* ETC2 RGB8A1 */
  1524. RB_ETC2_RGBA8, /* ETC2 RGBA8 */
  1525. RB_ETC2_R11, /* ETC2 R11 */
  1526. RB_ETC2_RG11 /* ETC2 RG11 */
  1527. } RB_CompressedFormat;
  1528. /* Buffer component type. */
  1529. typedef enum
  1530. {
  1531. RB_FLOAT_COMPONENT = 0,
  1532. RB_INTEGER_COMPONENT = 1
  1533. } RB_ComponentType;
  1534. /* RenderBuffer Descriptors ---------------------------------------------*/
  1535. /* Vertex channel semantic names. */
  1536. typedef enum
  1537. {
  1538. RB_POSITION_SEMANTIC,
  1539. RB_NORMAL_SEMANTIC,
  1540. RB_TANGENT_SEMANTIC,
  1541. RB_BINORMAL_SEMANTIC,
  1542. RB_TEXCOORD_SEMANTIC,
  1543. RB_COLOR_SEMANTIC,
  1544. RB_BLEND_INDICES_SEMANTIC,
  1545. RB_BLEND_WEIGHTS_SEMANTIC,
  1546. RB_UNKNOWN_SEMANTIC,
  1547. RB_SEMANTIC_COUNT = RB_UNKNOWN_SEMANTIC
  1548. } RB_VertexSemantic;
  1549. /* Describes a vertex channel inside a vertex buffe.r */
  1550. struct RB_VertexChannel
  1551. {
  1552. uint32_t format; /* Created using RenderBufferApi::format(). */
  1553. uint8_t semantic; /* Semantic name from RB_VertexSemantic. */
  1554. uint8_t vb_index; /* Vertex buffer index. */
  1555. uint8_t set; /* Semantic set (TEXCOORD0, TEXCOORD1, etc..). */
  1556. uint8_t instance; /* true if vertex channel contains per instance data. */
  1557. };
  1558. /* Describes a vertex format as a collection of vertex channels. */
  1559. struct RB_VertexDescription
  1560. {
  1561. struct RB_VertexChannel channels[16];
  1562. uint32_t n_channels;
  1563. };
  1564. typedef enum
  1565. {
  1566. RB_VERTEX_DESCRIPTION /* View of RB_VertexDescription. */
  1567. } RB_Description;
  1568. /* RenderBuffer Views -----------------------------------------*/
  1569. struct RB_VertexBufferView
  1570. {
  1571. uint32_t stride; /* Per vertex stride in bytes. */
  1572. uint32_t reserved[7]; /* Reserved for future use - must be zero. */
  1573. };
  1574. struct RB_IndexBufferView
  1575. {
  1576. uint32_t stride; /* Per index stride in bytes (must be 2 or 4). */
  1577. uint32_t reserved[7]; /* Reserved for future use - must be zero. */
  1578. };
  1579. struct RB_RawBufferView
  1580. {
  1581. uint32_t format; /* Format descriptor. */
  1582. uint32_t reserved[7]; /* Reserved for future use - Must be zero. */
  1583. };
  1584. /* Enum for the supported texture types. */
  1585. typedef enum
  1586. {
  1587. RB_TEXTURE_TYPE_2D = 0,
  1588. RB_TEXTURE_TYPE_CUBE = 1,
  1589. RB_TEXTURE_TYPE_3D = 2
  1590. } RB_TextureBufferType;
  1591. /* View into a texture buffer. */
  1592. struct RB_TextureBufferView
  1593. {
  1594. uint32_t format; /* Format of texture buffer. */
  1595. uint32_t type; /* Type of texture, should be any of the available types in RB_TextureBufferType. */
  1596. uint32_t width; /* Width of texture. */
  1597. uint32_t height; /* Height of texture. */
  1598. uint32_t depth; /* Depth of texture (Only used if type == RB_TEXTURE_TYPE_3D). */
  1599. uint32_t slices; /* Number of slices (1 for regular textures, >1 for texture arrays). */
  1600. uint32_t mip_levels; /* Number of mip levels in buffer. */
  1601. uint32_t reserved[7]; /* Reserved for future use - must be zero. */
  1602. };
  1603. /* Enum enumerating view types. */
  1604. typedef enum
  1605. {
  1606. RB_VERTEX_BUFFER_VIEW, /* View of RB_VertexBufferView */
  1607. RB_INDEX_BUFFER_VIEW, /* View of RB_IndexBufferView */
  1608. RB_RAW_BUFFER_VIEW, /* View of RB_RawBufferView */
  1609. RB_TEXTURE_BUFFER_VIEW /* View of RB_TextureBufferView */
  1610. } RB_View;
  1611. /* RenderBuffer API----------------------------------------------*/
  1612. /* Represents updatability of a buffer. */
  1613. typedef enum
  1614. {
  1615. /* The buffer is immutable. The content of the buffer must be passed in create_buffer() and
  1616. cannot change after that. */
  1617. RB_VALIDITY_STATIC,
  1618. /* The content of the buffer can be updated with update_buffer(). */
  1619. RB_VALIDITY_UPDATABLE
  1620. } RB_Validity;
  1621. struct RenderBufferApi
  1622. {
  1623. /* Creates a format descriptor describing a piece of data in a buffer.
  1624. type = RB_FLOAT_COMPONENT or RB_INTEGER_COMPONENT
  1625. signed_bool = true if component should be treated as signed
  1626. normalize_bool = true if component should be as a normalized value when read in a shader
  1627. bit_depth_ = number of bits per x,y,z,w component
  1628. */
  1629. uint32_t (*format)(RB_ComponentType type, uint8_t signed_bool, uint8_t normalize_bool, uint8_t bit_depth_x, uint8_t bit_depth_y, uint8_t bit_depth_z, uint8_t bit_depth_w);
  1630. /* Creates a format descriptor describing a compressed buffer. */
  1631. uint32_t (*compressed_format)(RB_CompressedFormat compression);
  1632. /* Returns true if format is a compressed format. */
  1633. uint8_t (*is_compressed)(uint32_t format);
  1634. /* Returns total number of bits used by the format.*/
  1635. uint32_t (*num_bits)(uint32_t format);
  1636. /* Returns the number of components in the format. */
  1637. uint32_t (*num_components)(uint32_t format);
  1638. /* Returns the component type for the format */
  1639. RB_ComponentType (*component_type)(uint32_t format);
  1640. /* Creates a descriptor object of the specified type and returns a handle to it.
  1641. desc should be an appropriate RB_*Description object. */
  1642. uint32_t (*create_description)(RB_Description view, const void *desc);
  1643. /* Updates the specified descriptor object. */
  1644. void (*update_description)(uint32_t handle, const void *desc);
  1645. /* Destroys a descriptor object created by create_description(). */
  1646. void (*destroy_description)(uint32_t handle);
  1647. /* Creates a buffer with the specified parameters and returns a handle to it.
  1648. view_data should be an appropriate RB_*View object and data should be the raw buffer data. */
  1649. uint32_t (*create_buffer)(uint32_t size, RB_Validity validity, RB_View view, const void *view_data, const void *data);
  1650. /* Updates the buffer with the specified content. */
  1651. void (*update_buffer)(uint32_t handle, uint32_t size, const void *data);
  1652. /* Destroys a buffer created by create_buffer(). */
  1653. void (*destroy_buffer)(uint32_t handle);
  1654. /* Translates a handle to a RenderResource that can be piped to MeshObjectApi::add_resource(),
  1655. remove_resource() as well as the Lua interface Material.set_resource(). */
  1656. struct RenderResource* (*lookup_resource)(uint32_t handle);
  1657. /* Overrides a resource with another resource. */
  1658. void (*resource_override)(struct RenderResource *resource_to_override, struct RenderResource *resource);
  1659. /* Releases the override done to the resource.*/
  1660. void (*release_resource_override)(struct RenderResource *overriden_resource);
  1661. /* Partial update of a buffer, offset and size in bytes. Partial updates are not allowed to grow a buffer, use update_buffer if you need to resize the buffer. */
  1662. void(*partial_update_buffer)(uint32_t handle, uint32_t offset, uint32_t size, const void *data);
  1663. /* Partial update of a texture buffer, offset[] and size[] are in pixels. Partial updates are not allowed to grow a buffer, use update_buffer if you need to resize the buffer. */
  1664. /* array_index, slice_index and mip_index describes which surface of the image to update. for now array_index must always be 0. */
  1665. /* Valid ranges for slice_index and mip_index depends on RB_TextureBufferView used when creating the texture. */
  1666. void(*partial_update_texture)(uint32_t handle, uint32_t array_index, uint32_t slice_index, uint32_t mip_index, uint32_t offset[3], uint32_t size[3], const void *data);
  1667. /* Updates the specified descriptor object. */
  1668. void(*update_description_from_resource)(struct RenderResource *resource, const void *desc);
  1669. /* Updates the buffer with the specified content. */
  1670. void(*update_buffer_from_resource)(struct RenderResource *resource, uint32_t size, const void *data);
  1671. /* Reserved for expansion of the API. */
  1672. void *reserved[26];
  1673. };
  1674. /* ----------------------------------------------------------------------
  1675. MeshObject
  1676. ---------------------------------------------------------------------- */
  1677. /* Describes the primitive type for a render batch. */
  1678. typedef enum { MO_TRIANGLE_LIST, MO_LINE_LIST } MO_PrimitiveType;
  1679. /* Describes a render batch in a mesh. */
  1680. struct MO_BatchInfo
  1681. {
  1682. MO_PrimitiveType primitive_type; /* Primitive type.e */
  1683. uint32_t material_index; /* Index into material array set by MeshObjectApi::set_materials() function. */
  1684. uint32_t vertex_offset; /* Offset to first vertex to read from vertex buffer. (If set when indexed this value is added to the index fetched from the index buffer before fetching the vertex.) */
  1685. uint32_t primitives; /* Number of primitives to draw. */
  1686. uint32_t index_offset; /* Offset to the first index to read from the index buffer (only valid when batch is indexed). */
  1687. uint32_t vertices; /* Number of vertices in batch (only valid if batch is non indexed). */
  1688. uint32_t instances; /* Number of instances of this batch to draw (1 equals no instancing). */
  1689. };
  1690. /* Describes a piece of mesh geometry for rendering. */
  1691. struct MO_Geometry
  1692. {
  1693. void *vertices[8]; /* Holds 0-8 different vertex buffers, contents described by vertex_channels[]. If mesh references more than 8 vertex buffers MeshObjectApi will generate an error. */
  1694. uint32_t vertex_stride[8]; /* Holds 0-8 strides, one for each buffer in vertices[]. */
  1695. uint32_t num_vertices; /* Total number of vertices. */
  1696. struct RB_VertexDescription vertex_description;/* Vertex description. */
  1697. void *indices; /* Pointer to index list. */
  1698. uint32_t index_stride; /* Stride of index list (2 or 4). */
  1699. uint32_t num_indices; /* Total number of indices. */
  1700. };
  1701. /* Describes a piece of mesh geometry for rendering. */
  1702. struct MO_MeshGeometry
  1703. {
  1704. struct RenderResource *vertex_stream;
  1705. struct RenderResource *vertex_description;
  1706. struct RenderResource *index_stream;
  1707. };
  1708. /* Culling flags for meshes. */
  1709. typedef enum
  1710. {
  1711. MO_VIEWPORT_VISIBLE_FLAG = 0x1, /* Mesh is part of regular rendering */
  1712. MO_SHADOW_CASTER_FLAG = 0x2, /* Mesh is part of shadow rendering */
  1713. MO_DISABLE_CULLING_FLAG = 0x4 /* Mesh always passes culling, i.e its bounding volume state is ignored. Note: might significantly impact performance */
  1714. } MO_Flags;
  1715. /* A context in which the mesh is either visible or not. */
  1716. typedef enum
  1717. {
  1718. MO_VIEWPORT_CONTEXT, /* Visibility context for regular rendering */
  1719. MO_SHADOW_CASTER_CONTEXT, /* Visibility context for shadow casting */
  1720. MO_ALL_CONTEXTS /* Visibility context for both regular rendering and shadow casting */
  1721. } MO_VisibilityContexts;
  1722. struct MeshObjectApi
  1723. {
  1724. /* Tries to retrieve the geometry of an existing mesh and if successful returns it in
  1725. MO_Geometry (this will only give valid results when a representation of the geometry exist
  1726. on the CPU side). */
  1727. uint8_t (*read_geometry)(CApiUnit *unit, uint32_t mesh_name, struct MO_Geometry *geometry);
  1728. /* Creates a new mesh object linked to the node referenced by node_name within the Unit
  1729. referenced by unit. The mesh_name is given to the new MeshObject and can be used to
  1730. retrieve the object from the Unit interface. flags is a combination of MO_Flags */
  1731. uint32_t (*create)(CApiUnit *unit, uint32_t node_name, uint32_t mesh_name, uint32_t flags);
  1732. /* Lookup an existing mesh object by name */
  1733. uint32_t (*lookup)(CApiUnit *unit, uint32_t mesh_name);
  1734. /* Destroy a mesh object created using create() or lookup(), for meshes looked up using
  1735. lookup() this just releases the plugin handle. */
  1736. void (*destroy)(uint32_t handle);
  1737. /* Assigns an array of materials to the mesh. material_resources is an array of material
  1738. resources retrieved using ResourceManagerApi::get() */
  1739. void (*set_materials)(uint32_t handle, uint32_t num_materials, void **material_resources);
  1740. /* Returns the number of materials assigned to the mesh */
  1741. uint32_t (*num_materials)(uint32_t handle);
  1742. /* Returns a pointer to the material instance at the specified index. */
  1743. void * (*material)(uint32_t handle, uint32_t material_index);
  1744. /* Sets batch/drawcall information of the mesh */
  1745. void (*set_batch_info)(uint32_t handle, uint32_t num_infos, struct MO_BatchInfo *batch_infos);
  1746. /* Adds resources such as vertex buffers, index buffers and vertex declarations created through
  1747. the RenderBufferApi or piped down from Lua. */
  1748. void (*add_resource)(uint32_t handle, struct RenderResource *r);
  1749. /* Removes a resource added with add_resource(). */
  1750. void (*remove_resource)(uint32_t handle, struct RenderResource *r);
  1751. /* Clears any already assigned resources from a mesh */
  1752. void (*clear_resources)(uint32_t handle);
  1753. /* Sets min & max bounds in mesh local coordinates to be used for culling. */
  1754. void (*set_bounding_box)(uint32_t handle, float min[3], float max[3]);
  1755. /* Sets visibility of the mesh for a specific MO_VisibilityContext */
  1756. void (*set_visibility)(uint32_t handle, uint32_t visibility_context, uint8_t visibility_bool);
  1757. /* Returns the visibility of the mesh in the specified context. */
  1758. uint8_t (*visibility)(uint32_t handle, uint32_t visibility_context);
  1759. /* Sets the culling MO_Flags for object (will overrride the flags passed in create()). */
  1760. void (*set_flags)(uint32_t handle, uint32_t flags);
  1761. /* Returns the culling flags of the object. */
  1762. uint32_t (*flags)(uint32_t handle);
  1763. /* Creates a new empty mesh object. A scene graph must be associated to it and it must be dispatched
  1764. to the render thread through a render interface before use with the mesh api. (this is currently
  1765. used for the mesh component api) */
  1766. uint32_t (*create_mesh)(WorldPtr world, uint32_t mesh_name, uint32_t flags);
  1767. /* Lookup an existing mesh object by its handle */
  1768. MeshPtr(*lookup_mesh)(uint32_t handle);
  1769. /* Tries to retrieve the mesh geometry of an existing mesh and if successful returns it in
  1770. MO_MeshGeometry. */
  1771. uint8_t (*read_mesh_geometry)(void *unit_resource, uint32_t mesh_name, struct MO_MeshGeometry *geometry);
  1772. /* Reserved for expansion of the API. */
  1773. void *reserved[29];
  1774. };
  1775. /* ----------------------------------------------------------------------
  1776. SoundStreamSourceApi
  1777. ---------------------------------------------------------------------- */
  1778. #pragma pack(push, 1)
  1779. /* Represents the format for sound data. */
  1780. struct WaveFormat
  1781. {
  1782. unsigned short format_tag; /* Tag specifying the format (e.g. WAVE_FORMAT_PCM). */
  1783. unsigned short num_channels; /* Number of sound channels (e.g. 2). */
  1784. unsigned samples_per_second; /* Samples per second (e.g. 44100). */
  1785. unsigned average_bytes_per_second; /* Not used. */
  1786. unsigned short block_align; /* For MP3 files, samples per frame. */
  1787. unsigned short bits_per_sample; /* Bits per sample (e.g. 16). */
  1788. unsigned short size; /* Number of extra bytes of header data. */
  1789. };
  1790. #pragma pack(pop)
  1791. /* Sound debug information. */
  1792. struct SoundData
  1793. {
  1794. unsigned id; /* IdString32 equivalent */
  1795. char debug_name[32];
  1796. };
  1797. /* Header for a piece of sound data. */
  1798. struct SoundHeader
  1799. {
  1800. unsigned offset; /* Offset of sample data in the file */
  1801. unsigned size; /* Size of sample data */
  1802. unsigned num_samples; /* Total number of samples (when unpacked) */
  1803. struct SoundData sound_data; /* Debug information */
  1804. };
  1805. /* Opaque struct representing a compiled piece of sound. */
  1806. struct SoundResource;
  1807. /* The result of streaming sound data. Contains the next chunk of streamed data. The
  1808. is_finished flag is set to true if this is the last chunk of sound data in the stream. */
  1809. struct GetNextChunkResult
  1810. {
  1811. struct SoundResource * data;
  1812. int is_finished;
  1813. };
  1814. /* Opaque struct representing a sound source for streaming sounds. */
  1815. struct SoundStreamSource;
  1816. /*
  1817. Interface for streaming sounds.
  1818. */
  1819. struct SoundStreamSourceApi
  1820. {
  1821. /* Get the next chunk of streaming data from the stream source. */
  1822. struct GetNextChunkResult (*get_next_chunk)(struct SoundStreamSource * ss);
  1823. /* Gets the sound resource for the stream source. */
  1824. struct SoundResource * (*get_resource)(struct SoundStreamSource * ss);
  1825. /* Gets the sound header for the specified sound resource. */
  1826. struct SoundHeader (*resource_header)(struct SoundResource * sr);
  1827. /* Gets the sound format for the specified sound resource. */
  1828. struct WaveFormat (*resource_format)(struct SoundResource * sr);
  1829. };
  1830. /* ----------------------------------------------------------------------
  1831. MaterialApi
  1832. ---------------------------------------------------------------------- */
  1833. /*
  1834. Interface for manipulating materials.
  1835. */
  1836. struct MaterialApi
  1837. {
  1838. /* Sets a number of resources to be used by the material. The resources are identified
  1839. by their hashed names. */
  1840. void (*set_resources)(void *material, uint32_t num_resources, const uint32_t *resource_names,
  1841. const struct RenderResource **resources);
  1842. /* Sets a number of constants for the material. */
  1843. void (*set_constants)(void *material, uint32_t num_constants, const uint32_t *constant_names,
  1844. const uint32_t *strides, const uint32_t *sizes, const void **constants);
  1845. /* Reserved for expansion of the API. */
  1846. void *reserved[32];
  1847. };
  1848. /* ----------------------------------------------------------------------
  1849. RenderSceneGraphApi
  1850. ---------------------------------------------------------------------- */
  1851. /*
  1852. Interface for accessing the render thread copy of the scene graph. These functions should
  1853. only be called on the render thread.
  1854. */
  1855. struct RenderSceneGraphApi
  1856. {
  1857. /* Returns the world matrix of the specified scene graph node. */
  1858. ConstMatrix4x4Ptr (*world)(uint32_t render_handle, CApiWorld *world, unsigned index);
  1859. /* Sets the world matrix of the specified scene graph node. */
  1860. void (*set_world)(uint32_t render_handle, CApiWorld *world, unsigned index, ConstMatrix4x4Ptr m);
  1861. /* Sets the world matrix of the specified scene graph node and transform its children
  1862. accordingly */
  1863. void (*transform_hierarchy)(uint32_t render_handle, CApiWorld *world, const struct SceneGraph *graph, unsigned index, ConstMatrix4x4Ptr m);
  1864. /* Reserved for expansion of the API. */
  1865. void *reserved[32];
  1866. };
  1867. /* ----------------------------------------------------------------------
  1868. ThreadApi
  1869. ---------------------------------------------------------------------- */
  1870. /* Defines for thread priorities. */
  1871. #define PLUGIN_THREAD_PRIORITY_IDLE -15
  1872. #define PLUGIN_THREAD_PRIORITY_LOWEST -2
  1873. #define PLUGIN_THREAD_PRIORITY_BELOW_NORMAL -1
  1874. #define PLUGIN_THREAD_PRIORITY_NORMAL 0
  1875. #define PLUGIN_THREAD_PRIORITY_ABOVE_NORMAL 1
  1876. #define PLUGIN_THREAD_PRIORITY_HIGHEST 2
  1877. #define PLUGIN_THREAD_PRIORITY_TIME_CRITICAL 15
  1878. /* ID for identifying a particular thread. */
  1879. typedef void* ThreadID;
  1880. /* Thread entry point callback function. */
  1881. typedef void (*ThreadEntry)(void* user_data);
  1882. /* Opaque struct representing an event. */
  1883. struct ThreadEvent;
  1884. /* Opaque struct representing a critical section. */
  1885. struct ThreadCriticalSection;
  1886. /*
  1887. Interface for accessing threading functionality.
  1888. */
  1889. struct ThreadApi
  1890. {
  1891. /* Creates a new thread and returns its ID. The user_data is passed to the thread entry point. */
  1892. ThreadID (*create_thread)(const char *thread_name, ThreadEntry entry, void *user_data, int priority);
  1893. /* Returns true if the thread is alive. */
  1894. int (*is_thread_alive)(ThreadID thread_id);
  1895. /* Returns the name of the specified thread. */
  1896. const char* (*thread_name)(ThreadID thread_id);
  1897. /* Waits until the thread has finished. */
  1898. void (*wait_for_thread)(ThreadID thread_id);
  1899. /* Creates an event for thread signaling. If manual_reset is false, the event will be
  1900. auto-reset after being triggered. initial_state specifies the initial state of the
  1901. event (set or not). */
  1902. struct ThreadEvent* (*create_event)(struct AllocatorObject *allocator, int manual_reset, int initial_state, const char *debug_name);
  1903. /* Destroys an event created by create_event(). */
  1904. void (*destroy_event)(struct ThreadEvent* evt, struct AllocatorObject *allocator );
  1905. /* Resets the event manually. */
  1906. void (*reset_event)(struct ThreadEvent* evt);
  1907. /* Sets the event. */
  1908. void (*set_event)(struct ThreadEvent* evt);
  1909. /* Returns true if the event is set. */
  1910. int (*is_event_set)(struct ThreadEvent* evt);
  1911. /* Wait for the event to become set. */
  1912. void (*wait_for_event)(struct ThreadEvent* evt);
  1913. /* Wait for the event to become set with a maximum timeout specified in milliseconds. */
  1914. int (*wait_for_event_timeout)(struct ThreadEvent* evt, unsigned timeout_ms);
  1915. /* Creates a critical section for thread protection and locking. */
  1916. struct ThreadCriticalSection* (*create_critical_section)(struct AllocatorObject *allocator);
  1917. /* Destroys a critical section created by create_critical_section(). */
  1918. void (*destroy_critical_section)(struct ThreadCriticalSection* cs,
  1919. struct AllocatorObject *allocator);
  1920. /* Enters the critical section. This will block if any other thread is already in the
  1921. critical section. */
  1922. void (*enter_critical_section)(struct ThreadCriticalSection* cs);
  1923. /* Leaves the critical section. */
  1924. void (*leave_critical_section)(struct ThreadCriticalSection* cs);
  1925. /* Tries to enter the critical section. This function won't block, instead it will return
  1926. false if another thread is already in the critical section, and true otherwise. */
  1927. int (*try_to_enter_critical_section)(struct ThreadCriticalSection* cs);
  1928. /* Returns the current assigned thread index. */
  1929. unsigned (*worker_thread_index)();
  1930. /* Assign to the current thread a worker thread index */
  1931. void (*assign_worker_thread_index)();
  1932. /* Reserved for expansion of the API. */
  1933. void *reserved[30];
  1934. };
  1935. /* ----------------------------------------------------------------------
  1936. TimerApi
  1937. ---------------------------------------------------------------------- */
  1938. /*
  1939. API for accessing the game timer.
  1940. */
  1941. struct TimerApi
  1942. {
  1943. /* Returns the number of ticks elapsed. The length of a tick is platform dependent, you need
  1944. to use ticks_to_seconds() to convert it to a real world number. */
  1945. uint64_t (*ticks)();
  1946. /* Converts ticks to seconds. */
  1947. double (*ticks_to_seconds)(uint64_t ticks);
  1948. /* Reserved for expansion of the API. */
  1949. void *reserved[32];
  1950. };
  1951. /* ----------------------------------------------------------------------
  1952. StreamCaptureApi
  1953. ---------------------------------------------------------------------- */
  1954. /* Describes a captured buffer. */
  1955. struct SC_Buffer {
  1956. /* Frame number. */
  1957. uint32_t frame;
  1958. /* Format descriptor, use RenderBufferApi to interpret */
  1959. uint32_t format;
  1960. /* Surface dimension */
  1961. uint32_t width;
  1962. uint32_t height;
  1963. /* Buffer data. */
  1964. void *data;
  1965. };
  1966. /*
  1967. Interface for capturing buffer data (render targets, etc) from the engine.
  1968. */
  1969. struct StreamCaptureApi
  1970. {
  1971. /* Enables stream capture of the named buffers. */
  1972. void (*enable_capture)(void *window, uint32_t n_buffers, uint32_t *buffer_names);
  1973. /* Disables stream capture for the named buffers. */
  1974. void (*disable_capture)(void *window, uint32_t n_buffers, uint32_t *buffer_names);
  1975. /* Extracts data from the named capture modifier into the output buffer. Returns true if
  1976. successful.
  1977. The captured data is allocated with the specified allocator. It is the responsibility of
  1978. the caller to deallocate the data pointer in the SC_Buffer. */
  1979. uint8_t (*capture_buffer)(void *window, uint32_t name, struct AllocatorObject *allocator,
  1980. struct SC_Buffer *output);
  1981. /* Returns the name of a stream capture modifier */
  1982. const char* (*capture_target_name)(CApiCaptureBufferPtr buffer);
  1983. /* Returns an opaque pointer to a stream capture modifier */
  1984. CApiCaptureBufferPtr (*capture_target)(unsigned index);
  1985. /* Returns the length of currently available stream capture modifiers */
  1986. unsigned (*num_available_capture_targets)();
  1987. /* Returns the amount of used capture buffers to buffer capture data */
  1988. unsigned (*num_used_buffers)();
  1989. /* Reserved for expansion of the API. */
  1990. void *reserved[31];
  1991. };
  1992. /* ----------------------------------------------------------------------
  1993. FlowApi
  1994. ---------------------------------------------------------------------- */
  1995. /* Opaque struct representing the context in which flow events are triggered. */
  1996. struct FlowTriggerContext;
  1997. /* Opaque struct representing a set of output events for a flow node. */
  1998. struct FlowOutputEvents;
  1999. /* Identifier for the special query event, which is sent to query nodes to get them to update
  2000. their data. */
  2001. #define PLUGIN_QUERY_EVENT 0xffff
  2002. typedef uint32_t FlowNodeType;
  2003. /* Data for a flow trigger event. */
  2004. struct FlowData
  2005. {
  2006. /* An integer identifying the type of the flow node. */
  2007. FlowNodeType node_type;
  2008. /* Identifier for the node. */
  2009. unsigned short node;
  2010. /* Index of the in event that was triggered on the flow node. */
  2011. unsigned short event_index;
  2012. /* Opaque struct that represents the out events of the flow node. Can be used to trigger out
  2013. events. */
  2014. const struct FlowOutputEvents* out_events;
  2015. };
  2016. /* Maximum number of parameters to a flow node. */
  2017. #define PLUGIN_FLOW_NODES_MAX_PARAMS 63
  2018. /* Maximum length of flow string variables. */
  2019. #define PLUGIN_FLOW_STRING_VARIABLE_LENGTH 128
  2020. /* Represents the parameters of a flow node. */
  2021. struct FlowParameters {
  2022. const void* parameters[PLUGIN_FLOW_NODES_MAX_PARAMS + 1];
  2023. };
  2024. struct FlowString
  2025. {
  2026. unsigned int is_id64; // Always set to zero
  2027. char plain[PLUGIN_FLOW_STRING_VARIABLE_LENGTH];
  2028. };
  2029. struct FlowId
  2030. {
  2031. unsigned int is_id64; // May be 0 or 1 for input, always 1 for output
  2032. unsigned int padding;
  2033. uint64_t id;
  2034. };
  2035. /* Callback function for performing an action when a flow node is triggered. */
  2036. typedef void (*FlowFunction)(struct FlowTriggerContext* tc, const struct FlowData *fd, const struct FlowParameters *fp);
  2037. /* Callback function for setting variables on the flow node. */
  2038. typedef void (*SetVariableFunction)(struct FlowTriggerContext* tc, const struct FlowParameters *fp, unsigned key, void *data);
  2039. /* Callback function for triggering an out event. */
  2040. typedef void (*EventCallbackFunction)(struct FlowTriggerContext* tc, const struct FlowData *fd, const struct FlowParameters *fp);
  2041. /*
  2042. Type Input field (can be null) Output field (not null)
  2043. "unit" const CApiUnitRef* CApiUnitRef*
  2044. "actor" const CApiActor* CApiActor*
  2045. "mover" const CApiMover* CApiMover*
  2046. "vector3" const CApiVector3* CApiVector3*
  2047. "float" const float* float*
  2048. "bool" const unsigned* unsigned*
  2049. "string" const FlowString* FlowString*
  2050. "id" const FlowId* FlowId*
  2051. "quaternion" const CApiQuaternion* CApiQuaternion*
  2052. "unsigned" const unsigned* unsigned*
  2053. "camera" const CApiCamera* CApiCamera*
  2054. "light" const CApiLight* CApiLight*
  2055. "mesh" const CApiMesh* CApiMesh*
  2056. "material" const CApiMaterial* CApiMaterial*
  2057. "resource" const FlowString*
  2058. "enum" int
  2059. */
  2060. /*
  2061. Interface for implementing custom flow nodes.
  2062. */
  2063. struct FlowNodesApi
  2064. {
  2065. /* Registers a flow trigger function for a flow node with the specified name. */
  2066. void (*setup_trigger_function)(unsigned name_id32, FlowFunction trigger_function);
  2067. /* Registers an event callback for a flow node with the specified name. */
  2068. void (*setup_event_callback)(unsigned name_id32, EventCallbackFunction event_callback_function);
  2069. /* Registers a set_variable callback for a flow node with the specified name. */
  2070. void (*setup_set_variable_callback)(unsigned name_id32, SetVariableFunction variable_callback_function);
  2071. /* Unregisters the flow node with the specified name. */
  2072. void (*unregister_flow_node)(unsigned name_id32);
  2073. /* Used in the flow trigger implementation to trigger one of the flow node's out events. */
  2074. void (*trigger_out_event)(struct FlowTriggerContext *tc, const struct FlowData* fd, int event_index);
  2075. /* Used in the flow trigger implementation to trigger an external level event. */
  2076. void (*trigger_external_level_event)(CApiLevel *level, unsigned id_string_32);
  2077. /* Used in the flow trigger implementation to trigger an external unit event. */
  2078. void (*trigger_external_unit_event)(CApiUnit *unit, unsigned id_string_32);
  2079. /* Reserved for expansion of the API. */
  2080. void *reserved[32];
  2081. };
  2082. /* ----------------------------------------------------------------------
  2083. CameraApi
  2084. ---------------------------------------------------------------------- */
  2085. /* Camera mode. */
  2086. typedef enum
  2087. {
  2088. C_MONO,
  2089. C_STEREO
  2090. } C_Mode;
  2091. /* Camera projection. */
  2092. typedef enum
  2093. {
  2094. C_ORTHOGRAPHIC,
  2095. C_PERSPECTIVE
  2096. } C_ProjectionType;
  2097. /*
  2098. Interface for manipulating cameras.
  2099. */
  2100. struct CameraApi
  2101. {
  2102. /* Returns the scene graph that owns the camera. */
  2103. struct SceneGraph * (*scene_graph)(CApiCamera *camera);
  2104. /* Returns the near range of the camera. */
  2105. float (*near_range)(CApiCamera *camera);
  2106. /* Sets the near range of the camera. */
  2107. void (*set_near_range)(CApiCamera *, float near_range);
  2108. /* Returns the far range of the camera. */
  2109. float (*far_range)(CApiCamera *camera);
  2110. /* Sets the far range of the camera. */
  2111. void (*set_far_range)(CApiCamera *camera, float far_range);
  2112. /* Returns the projection type of the camera. */
  2113. uint8_t (*projection_type)(CApiCamera *camera);
  2114. /* Sets the projection type of the camera. */
  2115. void (*set_projection_type)(CApiCamera *camera, uint8_t projection_type);
  2116. /* Returns the vertical FOV of the camera. */
  2117. float (*vertical_fov)(CApiCamera *camera, unsigned i);
  2118. /* Sets the vertical FOV of the camera. */
  2119. void (*set_vertical_fov)(CApiCamera *camera, float fov, unsigned i);
  2120. /* Sets the dimensions of the specified camera frustum. */
  2121. void (*set_frustum)(CApiCamera *camera, float left, float right, float bottom, float top,
  2122. unsigned i);
  2123. void (*set_frustum_shear)(CApiCamera *camera, float shear_x, float shear_y, unsigned i);
  2124. /* Sets the half angles of the specifies camera frustum. */
  2125. void (*set_frustum_half_angles)(CApiCamera *camera, float left_tan, float right_tan,
  2126. float bottom_tan, float top_tan, unsigned i);
  2127. /* Returns the camera mode. */
  2128. uint8_t (*mode)(CApiCamera *camera);
  2129. /* Sets the camera mode. */
  2130. void (*set_mode)(CApiCamera *camera, uint8_t mode);
  2131. /* Sets the local position of the camera. */
  2132. void (*set_local)(CApiCamera *camera, ConstMatrix4x4Ptr offset, unsigned i);
  2133. /* Reserved for expansion of the API. */
  2134. void *reserved[32];
  2135. };
  2136. /* ----------------------------------------------------------------------
  2137. PhysicsRuntimeCookingApi
  2138. ---------------------------------------------------------------------- */
  2139. /*
  2140. API for doing runtime physics compilation of meshes into physics actors. Currently only supported on UWP.
  2141. */
  2142. /* Description of the triangle mesh to cook */
  2143. typedef struct MeshDescription
  2144. {
  2145. unsigned num_vertices;
  2146. unsigned vertice_stride;
  2147. void *vertices;
  2148. unsigned num_triangles;
  2149. unsigned triangle_stride;
  2150. void *triangles;
  2151. } MeshDescription;
  2152. struct PhysicsRuntimeCookingApi
  2153. {
  2154. /* Setup and initialize the physics cooking */
  2155. void (*setup)();
  2156. /* Shutdown the physics cooking */
  2157. void (*shutdown)();
  2158. /* Cooks a mesh and returns a pointer to the cooked mesh data allocated in the supplied allocator*/
  2159. void *(*cook_mesh)(const MeshDescription *mesh_description, struct AllocatorObject *allocator);
  2160. /* Creates a physics mesh from cooked data */
  2161. void *(*create_physics_mesh)(const void *cooked_mesh);
  2162. /* Releases physics mesh */
  2163. void (*release_physics_mesh)(void *physics_mesh);
  2164. /* Reserved for expansion of the API. */
  2165. void *reserved[32];
  2166. };
  2167. #ifdef __cplusplus
  2168. }
  2169. #endif