Added 50-headless example.

This commit is contained in:
Бранимир Караџић
2025-10-31 18:11:43 -07:00
parent 5e46bf86f7
commit 3722e21525
8 changed files with 392 additions and 114 deletions

66
examples/common/args.h Normal file
View File

@@ -0,0 +1,66 @@
/*
* Copyright 2011-2025 Branimir Karadzic. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include <bgfx/bgfx.h>
#include <bx/commandline.h>
///
struct Args
{
Args(int _argc, const char* const* _argv)
: m_type(bgfx::RendererType::Count)
, m_pciId(BGFX_PCI_ID_NONE)
{
bx::CommandLine cmdLine(_argc, (const char**)_argv);
if (cmdLine.hasArg("gl") )
{
m_type = bgfx::RendererType::OpenGL;
}
else if (cmdLine.hasArg("vk") )
{
m_type = bgfx::RendererType::Vulkan;
}
else if (cmdLine.hasArg("noop") )
{
m_type = bgfx::RendererType::Noop;
}
else if (cmdLine.hasArg("d3d11") )
{
m_type = bgfx::RendererType::Direct3D11;
}
else if (cmdLine.hasArg("d3d12") )
{
m_type = bgfx::RendererType::Direct3D12;
}
else if (BX_ENABLED(BX_PLATFORM_OSX) )
{
if (cmdLine.hasArg("mtl") )
{
m_type = bgfx::RendererType::Metal;
}
}
if (cmdLine.hasArg("amd") )
{
m_pciId = BGFX_PCI_ID_AMD;
}
else if (cmdLine.hasArg("nvidia") )
{
m_pciId = BGFX_PCI_ID_NVIDIA;
}
else if (cmdLine.hasArg("intel") )
{
m_pciId = BGFX_PCI_ID_INTEL;
}
else if (cmdLine.hasArg("sw") )
{
m_pciId = BGFX_PCI_ID_SOFTWARE_RASTERIZER;
}
}
bgfx::RendererType::Enum m_type;
uint16_t m_pciId;
};

View File

@@ -746,55 +746,3 @@ bgfx::RendererType::Enum getType(const bx::StringView& _name)
return bgfx::RendererType::Count;
}
Args::Args(int _argc, const char* const* _argv)
: m_type(bgfx::RendererType::Count)
, m_pciId(BGFX_PCI_ID_NONE)
{
bx::CommandLine cmdLine(_argc, (const char**)_argv);
if (cmdLine.hasArg("gl") )
{
m_type = bgfx::RendererType::OpenGL;
}
else if (cmdLine.hasArg("vk") )
{
m_type = bgfx::RendererType::Vulkan;
}
else if (cmdLine.hasArg("noop") )
{
m_type = bgfx::RendererType::Noop;
}
else if (cmdLine.hasArg("d3d11") )
{
m_type = bgfx::RendererType::Direct3D11;
}
else if (cmdLine.hasArg("d3d12") )
{
m_type = bgfx::RendererType::Direct3D12;
}
else if (BX_ENABLED(BX_PLATFORM_OSX) )
{
if (cmdLine.hasArg("mtl") )
{
m_type = bgfx::RendererType::Metal;
}
}
if (cmdLine.hasArg("amd") )
{
m_pciId = BGFX_PCI_ID_AMD;
}
else if (cmdLine.hasArg("nvidia") )
{
m_pciId = BGFX_PCI_ID_NVIDIA;
}
else if (cmdLine.hasArg("intel") )
{
m_pciId = BGFX_PCI_ID_INTEL;
}
else if (cmdLine.hasArg("sw") )
{
m_pciId = BGFX_PCI_ID_SOFTWARE_RASTERIZER;
}
}

View File

@@ -16,6 +16,7 @@
#include <tinystl/vector.h>
namespace stl = tinystl;
#include "args.h"
///
void* load(const bx::FilePath& _filePath, uint32_t* _size = NULL);
@@ -152,13 +153,4 @@ bx::StringView getName(bgfx::RendererType::Enum _type);
/// Name to bgfx::RendererType::Enum.
bgfx::RendererType::Enum getType(const bx::StringView& _name);
///
struct Args
{
Args(int _argc, const char* const* _argv);
bgfx::RendererType::Enum m_type;
uint16_t m_pciId;
};
#endif // BGFX_UTILS_H_HEADER_GUARD