Changed getSupportedRenderers function.

This commit is contained in:
Branimir Karadžić 2016-10-07 16:58:26 -07:00
parent ede080a2be
commit 8b4ac9d440
6 changed files with 27 additions and 12 deletions

View File

@ -377,7 +377,7 @@ int _main_(int _argc, char** _argv)
// Enumerate supported backend renderers.
bgfx::RendererType::Enum renderers[bgfx::RendererType::Count];
uint8_t numRenderers = bgfx::getSupportedRenderers(renderers);
uint8_t numRenderers = bgfx::getSupportedRenderers(BX_COUNTOF(renderers), renderers);
bgfx::init(bgfx::RendererType::Count == args.m_type
? renderers[bx::getHPCounter() % numRenderers] /* randomize renderer */

View File

@ -951,9 +951,14 @@ namespace bgfx
/// Returns supported backend API renderers.
///
/// @param[in] _max Maximum number of elements in _enum array.
/// @param[inout] _enum Array where supported renderers will be written.
///
/// @returns Number of supported renderers.
///
/// @attention C99 equivalent is `bgfx_get_supported_renderers`.
///
uint8_t getSupportedRenderers(RendererType::Enum _enum[RendererType::Count]);
uint8_t getSupportedRenderers(uint8_t _max = 0, RendererType::Enum* _enum = NULL);
/// Returns name of renderer.
///

View File

@ -6,7 +6,7 @@
#ifndef BGFX_DEFINES_H_HEADER_GUARD
#define BGFX_DEFINES_H_HEADER_GUARD
#define BGFX_API_VERSION UINT32_C(25)
#define BGFX_API_VERSION UINT32_C(26)
///
#define BGFX_STATE_RGB_WRITE UINT64_C(0x0000000000000001) //!< Enable RGB write.

View File

@ -536,7 +536,7 @@ BGFX_C_API void bgfx_image_swizzle_bgra8(uint32_t _width, uint32_t _height, uint
BGFX_C_API void bgfx_image_rgba8_downsample_2x2(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst);
/**/
BGFX_C_API uint8_t bgfx_get_supported_renderers(bgfx_renderer_type_t _enum[BGFX_RENDERER_TYPE_COUNT]);
BGFX_C_API uint8_t bgfx_get_supported_renderers(uint8_t _max, bgfx_renderer_type_t* _enum);
/**/
BGFX_C_API const char* bgfx_get_renderer_name(bgfx_renderer_type_t _type);

View File

@ -81,7 +81,7 @@ typedef struct bgfx_interface_vtbl
void (*topology_sort_tri_list)(bgfx_topology_sort_t _sort, void* _dst, uint32_t _dstSize, const float _dir[3], const float _pos[3], const void* _vertices, uint32_t _stride, const void* _indices, uint32_t _numIndices, bool _index32);
void (*image_swizzle_bgra8)(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst);
void (*image_rgba8_downsample_2x2)(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst);
uint8_t (*get_supported_renderers)(bgfx_renderer_type_t _enum[BGFX_RENDERER_TYPE_COUNT]);
uint8_t (*get_supported_renderers)(uint8_t _max, bgfx_renderer_type_t* _enum);
const char* (*get_renderer_name)(bgfx_renderer_type_t _type);
bool (*init)(bgfx_renderer_type_t _type, uint16_t _vendorId, uint16_t _deviceId, bgfx_callback_interface_t* _callback, bgfx_allocator_interface_t* _allocator);
void (*shutdown)();

View File

@ -1066,7 +1066,7 @@ namespace bgfx
BX_TRACE("");
RendererType::Enum renderers[RendererType::Count];
uint8_t num = getSupportedRenderers(renderers);
uint8_t num = getSupportedRenderers(BX_COUNTOF(renderers), renderers);
BX_TRACE("Supported renderer backends (%d):", num);
for (uint32_t ii = 0; ii < num; ++ii)
@ -2384,10 +2384,12 @@ namespace bgfx
topologySortTriList(_sort, _dst, _dstSize, _dir, _pos, _vertices, _stride, _indices, _numIndices, _index32, g_allocator);
}
uint8_t getSupportedRenderers(RendererType::Enum _enum[RendererType::Count])
uint8_t getSupportedRenderers(uint8_t _max, RendererType::Enum* _enum)
{
_enum = _max == 0 ? NULL : _enum;
uint8_t num = 0;
for (uint8_t ii = 0; ii < uint8_t(RendererType::Count); ++ii)
for (uint8_t ii = 0; ii < RendererType::Count; ++ii)
{
if ( (RendererType::Direct3D11 == ii || RendererType::Direct3D12 == ii)
&& windowsVersionIs(Condition::LessEqual, 0x0502) )
@ -2395,9 +2397,17 @@ namespace bgfx
continue;
}
if (s_rendererCreator[ii].supported)
if (NULL == _enum)
{
_enum[num++] = RendererType::Enum(ii);
num++;
}
else
{
if (num < _max
&& s_rendererCreator[ii].supported)
{
_enum[num++] = RendererType::Enum(ii);
}
}
}
@ -3920,9 +3930,9 @@ BGFX_C_API void bgfx_image_rgba8_downsample_2x2(uint32_t _width, uint32_t _heigh
bgfx::imageRgba8Downsample2x2(_width, _height, _pitch, _src, _dst);
}
BGFX_C_API uint8_t bgfx_get_supported_renderers(bgfx_renderer_type_t _enum[BGFX_RENDERER_TYPE_COUNT])
BGFX_C_API uint8_t bgfx_get_supported_renderers(uint8_t _max, bgfx_renderer_type_t* _enum)
{
return bgfx::getSupportedRenderers( (bgfx::RendererType::Enum*)_enum);
return bgfx::getSupportedRenderers(_max, (bgfx::RendererType::Enum*)_enum);
}
BGFX_C_API const char* bgfx_get_renderer_name(bgfx_renderer_type_t _type)