diff --git a/examples/08-update/update.cpp b/examples/08-update/update.cpp index 23825b57f..ef4016bd0 100644 --- a/examples/08-update/update.cpp +++ b/examples/08-update/update.cpp @@ -112,14 +112,16 @@ static void updateTextureCubeRectBgra8(bgfx::TextureHandle _handle, uint8_t _sid bgfx::updateTextureCube(_handle, _side, 0, _x, _y, _width, _height, mem); } -int _main_(int /*_argc*/, char** /*_argv*/) +int _main_(int _argc, char** _argv) { + Args args(_argc, _argv); + uint32_t width = 1280; uint32_t height = 720; uint32_t debug = BGFX_DEBUG_TEXT; uint32_t reset = BGFX_RESET_VSYNC; - bgfx::init(); + bgfx::init(args.m_type, args.m_pciId); bgfx::reset(width, height, reset); // Enable debug text. @@ -149,24 +151,6 @@ int _main_(int /*_argc*/, char** /*_argv*/) loadTexture("texture_compression_ptc24.pvr"), }; - const bgfx::Memory* mem8 = bgfx::alloc(32*32*32); - const bgfx::Memory* mem16f = bgfx::alloc(32*32*32*2); - const bgfx::Memory* mem32f = bgfx::alloc(32*32*32*4); - for (uint8_t zz = 0; zz < 32; ++zz) - { - for (uint8_t yy = 0; yy < 32; ++yy) - { - for (uint8_t xx = 0; xx < 32; ++xx) - { - const uint32_t offset = ( (zz*32+yy)*32+xx); - const uint32_t val = xx ^ yy ^ zz; - mem8->data[offset] = val<<3; - *(uint16_t*)&mem16f->data[offset*2] = bx::halfFromFloat( (float)val/32.0f); - *(float*)&mem32f->data[offset*4] = (float)val/32.0f; - } - } - } - const bgfx::Caps* caps = bgfx::getCaps(); const bool texture3DSupported = !!(caps->supported & BGFX_CAPS_TEXTURE_3D); const bool blitSupported = !!(caps->supported & BGFX_CAPS_TEXTURE_BLIT); @@ -176,6 +160,24 @@ int _main_(int /*_argc*/, char** /*_argv*/) if (texture3DSupported) { + const bgfx::Memory* mem8 = bgfx::alloc(32*32*32); + const bgfx::Memory* mem16f = bgfx::alloc(32*32*32*2); + const bgfx::Memory* mem32f = bgfx::alloc(32*32*32*4); + for (uint8_t zz = 0; zz < 32; ++zz) + { + for (uint8_t yy = 0; yy < 32; ++yy) + { + for (uint8_t xx = 0; xx < 32; ++xx) + { + const uint32_t offset = ( (zz*32+yy)*32+xx); + const uint32_t val = xx ^ yy ^ zz; + mem8->data[offset] = val<<3; + *(uint16_t*)&mem16f->data[offset*2] = bx::halfFromFloat( (float)val/32.0f); + *(float*)&mem32f->data[offset*4] = (float)val/32.0f; + } + } + } + if (0 != (BGFX_CAPS_FORMAT_TEXTURE_2D & caps->formats[bgfx::TextureFormat::R8]) ) { textures3d[numTextures3d++] = bgfx::createTexture3D(32, 32, 32, 0, bgfx::TextureFormat::R8, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP, mem8); diff --git a/examples/09-hdr/hdr.cpp b/examples/09-hdr/hdr.cpp index dd141e7c3..a5985f45e 100644 --- a/examples/09-hdr/hdr.cpp +++ b/examples/09-hdr/hdr.cpp @@ -141,14 +141,16 @@ inline float square(float _x) class HDR : public entry::AppI { - void init(int /*_argc*/, char** /*_argv*/) BX_OVERRIDE + void init(int _argc, char** _argv) BX_OVERRIDE { + Args args(_argc, _argv); + m_width = 1280; m_height = 720; m_debug = BGFX_DEBUG_TEXT; m_reset = BGFX_RESET_VSYNC; - bgfx::init(); + bgfx::init(args.m_type, args.m_pciId); bgfx::reset(m_width, m_height, m_reset); // Enable m_debug text. diff --git a/examples/common/bgfx_utils.cpp b/examples/common/bgfx_utils.cpp index 386062c06..b1897c8f5 100644 --- a/examples/common/bgfx_utils.cpp +++ b/examples/common/bgfx_utils.cpp @@ -13,8 +13,9 @@ namespace stl = tinystl; #include -#include +#include #include +#include #include #include "entry/entry.h" #include @@ -621,3 +622,59 @@ void meshSubmit(const Mesh* _mesh, const MeshState*const* _state, uint8_t _numPa { _mesh->submit(_state, _numPasses, _mtx, _numMatrices); } + +Args::Args(int _argc, char** _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("noop") + || cmdLine.hasArg("vk") ) + { + m_type = bgfx::RendererType::OpenGL; + } + else if (BX_ENABLED(BX_PLATFORM_WINDOWS) ) + { + if (cmdLine.hasArg("d3d9") ) + { + m_type = bgfx::RendererType::Direct3D9; + } + 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; + } +} diff --git a/examples/common/bgfx_utils.h b/examples/common/bgfx_utils.h index 2938abff1..a2427e511 100644 --- a/examples/common/bgfx_utils.h +++ b/examples/common/bgfx_utils.h @@ -43,4 +43,12 @@ void meshStateDestroy(MeshState* _meshState); void meshSubmit(const Mesh* _mesh, uint8_t _id, bgfx::ProgramHandle _program, const float* _mtx, uint64_t _state = BGFX_STATE_MASK); void meshSubmit(const Mesh* _mesh, const MeshState*const* _state, uint8_t _numPasses, const float* _mtx, uint16_t _numMatrices = 1); +struct Args +{ + Args(int _argc, char** _argv); + + bgfx::RendererType::Enum m_type; + uint16_t m_pciId; +}; + #endif // BGFX_UTILS_H_HEADER_GUARD