2023-09-05 18:05:18 +02:00
|
|
|
/// @macro {String} Path to the GMD3D11 dynamic library.
|
|
|
|
/// Default value is "GMD3D11.dll".
|
|
|
|
#macro GMD3D11_PATH "GMD3D11.dll"
|
|
|
|
|
|
|
|
/// @macro {Bool} Expands to `true` if GMD3D11 is supported on the current
|
|
|
|
/// platform.
|
|
|
|
#macro GMD3D11_IS_SUPPORTED (os_type == os_windows)
|
|
|
|
|
|
|
|
/// @func d3d11_get_error_string()
|
|
|
|
///
|
|
|
|
/// @desc Retrieves the last error message.
|
|
|
|
///
|
|
|
|
/// @return {String} The last error message.
|
2023-10-28 10:53:11 +02:00
|
|
|
function d3d11_get_error_string() {
|
2023-11-08 03:11:01 +01:00
|
|
|
if(!GMD3D11_IS_SUPPORTED) return;
|
2023-11-08 08:38:04 +01:00
|
|
|
INLINE
|
2023-10-28 10:53:11 +02:00
|
|
|
static _fn = external_define(GMD3D11_PATH, "d3d11_get_error_string", dll_cdecl, ty_string, 0);
|
2023-09-05 18:05:18 +02:00
|
|
|
return external_call(_fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @func d3d11_texture_set_stage_vs(_slot, _texture)
|
|
|
|
///
|
|
|
|
/// @desc Passes a texture to a vertex shader.
|
|
|
|
///
|
|
|
|
/// @param {Real} _slot The vertex texture slot index. Must be in range
|
|
|
|
/// 0..{@link D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT}-1.
|
|
|
|
/// @param {Pointer.Texture} _texture The texture to pass.
|
|
|
|
///
|
|
|
|
/// @return {Real} Returns 1 on success or 0 on fail.
|
2023-10-28 10:53:11 +02:00
|
|
|
function d3d11_texture_set_stage_vs(_slot, _texture) {
|
2023-11-08 03:11:01 +01:00
|
|
|
if(!GMD3D11_IS_SUPPORTED) return;
|
2023-11-08 08:38:04 +01:00
|
|
|
INLINE
|
2023-10-28 10:53:11 +02:00
|
|
|
static _fn = external_define(GMD3D11_PATH, "d3d11_texture_set_stage_vs", dll_cdecl, ty_real, 1, ty_real);
|
2023-09-05 18:05:18 +02:00
|
|
|
texture_set_stage(0, _texture);
|
|
|
|
return external_call(_fn, _slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @func texture_set_stage_vs(_slot, _texture)
|
|
|
|
///
|
|
|
|
/// @desc If GMD3D11 is supported, then uses {@link d3d11_texture_set_stage_vs}
|
|
|
|
/// to pass a texture to a vertex shader, otherwise uses `texture_set_stage`
|
|
|
|
/// (which should work on OpenGL platforms).
|
|
|
|
///
|
|
|
|
/// @param {Real} _slot The vertex texture slot index. Must be in range 0..7.
|
|
|
|
/// @param {Pointer.Texture} _texture The texture to pass.
|
|
|
|
///
|
|
|
|
/// @see GMD3D11_IS_SUPPORTED
|
2023-10-28 10:53:11 +02:00
|
|
|
function texture_set_stage_vs(_slot, _texture) {
|
2023-11-08 08:38:04 +01:00
|
|
|
INLINE
|
2023-10-28 10:53:11 +02:00
|
|
|
if (GMD3D11_IS_SUPPORTED) {
|
2023-09-05 18:05:18 +02:00
|
|
|
d3d11_texture_set_stage_vs(_slot, _texture);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
texture_set_stage(_slot, _texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @func d3d11_texture_set_stage_ps(_slot, _texture)
|
|
|
|
///
|
|
|
|
/// @desc Passes a texture to a pixel shader.
|
|
|
|
///
|
|
|
|
/// @param {Real} _slot The pixel texture slot index. Must be in range
|
|
|
|
/// 0..{@link D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT}-1.
|
|
|
|
/// @param {Pointer.Texture} _texture The texture to pass.
|
|
|
|
///
|
|
|
|
/// @return {Real} Returns 1 on success or 0 on fail.
|
2023-10-28 10:53:11 +02:00
|
|
|
function d3d11_texture_set_stage_ps(_slot, _texture) {
|
2023-11-08 03:11:01 +01:00
|
|
|
if(!GMD3D11_IS_SUPPORTED) return;
|
2023-11-08 08:38:04 +01:00
|
|
|
INLINE
|
2023-10-28 10:53:11 +02:00
|
|
|
static _fn = external_define(GMD3D11_PATH, "d3d11_texture_set_stage_ps", dll_cdecl, ty_real, 1, ty_real);
|
2023-09-05 18:05:18 +02:00
|
|
|
texture_set_stage(0, _texture);
|
|
|
|
return external_call(_fn, _slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @func d3d11_draw_instanced(_count)
|
|
|
|
///
|
|
|
|
/// @desc Configures the number of instances to draw the next time a vertex buffer
|
|
|
|
/// is submitted. After that the number is reset back to 0!
|
|
|
|
///
|
|
|
|
/// @param {Real} _count Number of instances to draw. Use 0 to disable instanced rendering.
|
2023-10-28 10:53:11 +02:00
|
|
|
function d3d11_draw_instanced(_count) {
|
2023-11-08 03:11:01 +01:00
|
|
|
if(!GMD3D11_IS_SUPPORTED) return;
|
2023-11-08 08:38:04 +01:00
|
|
|
INLINE
|
2023-10-28 10:53:11 +02:00
|
|
|
static _fn = external_define(GMD3D11_PATH, "d3d11_draw_instanced", dll_cdecl, ty_real, 1, ty_real);
|
2023-09-05 18:05:18 +02:00
|
|
|
return external_call(_fn, _count);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @func vertex_submit_instanced(_vbuff, _prim, _texture, _count)
|
|
|
|
///
|
|
|
|
/// @desc Draws multiple instances of a vertex buffer.
|
|
|
|
///
|
|
|
|
/// @param {Id.VertexBuffer} _vbuff The vertex buffer to submit.
|
|
|
|
/// @param {Constant.PrimitiveType} _prim The primitive type.
|
|
|
|
/// @param {Pointer.Texture} _texture The texture to use.
|
|
|
|
/// @param {Real} _count The number of instances to draw.
|
2023-10-28 10:53:11 +02:00
|
|
|
function vertex_submit_instanced(_vbuff, _prim, _texture, _count) {
|
2023-11-08 03:11:01 +01:00
|
|
|
if(!GMD3D11_IS_SUPPORTED) return;
|
2023-11-08 08:38:04 +01:00
|
|
|
INLINE
|
2023-09-05 18:05:18 +02:00
|
|
|
if (!d3d11_draw_instanced(_count))
|
|
|
|
return false;
|
2023-10-28 10:53:11 +02:00
|
|
|
|
2023-09-05 18:05:18 +02:00
|
|
|
vertex_submit(_vbuff, _prim, _texture);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-10-28 10:53:11 +02:00
|
|
|
function vertex_buffer_load(_filename, _vformat) {
|
2023-11-08 03:11:01 +01:00
|
|
|
if(!GMD3D11_IS_SUPPORTED) return;
|
2023-11-08 08:38:04 +01:00
|
|
|
INLINE
|
2023-10-28 10:53:11 +02:00
|
|
|
var _buffer = buffer_load(_filename);
|
|
|
|
var _vbuffer = vertex_create_buffer_from_buffer(_buffer, _vformat);
|
|
|
|
buffer_delete(_buffer);
|
|
|
|
return _vbuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GMD3D11_IS_SUPPORTED) {
|
|
|
|
var _init = external_define(GMD3D11_PATH, "d3d11_init", dll_cdecl, ty_real, 2, ty_string, ty_string);
|
|
|
|
var _osInfo = os_get_info();
|
|
|
|
var _device = _osInfo[? "video_d3d11_device"];
|
2023-09-05 18:05:18 +02:00
|
|
|
var _context = _osInfo[? "video_d3d11_context"];
|
|
|
|
external_call(_init, _device, _context);
|
|
|
|
}
|