Branimir Karadžić vor 10 Jahren
Ursprung
Commit
6ffdb3e247
4 geänderte Dateien mit 92 neuen und 23 gelöschten Zeilen
  1. 22 20
      examples/08-update/update.cpp
  2. 4 2
      examples/09-hdr/hdr.cpp
  3. 58 1
      examples/common/bgfx_utils.cpp
  4. 8 0
      examples/common/bgfx_utils.h

+ 22 - 20
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);
 	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 width  = 1280;
 	uint32_t height = 720;
 	uint32_t height = 720;
 	uint32_t debug  = BGFX_DEBUG_TEXT;
 	uint32_t debug  = BGFX_DEBUG_TEXT;
 	uint32_t reset  = BGFX_RESET_VSYNC;
 	uint32_t reset  = BGFX_RESET_VSYNC;
 
 
-	bgfx::init();
+	bgfx::init(args.m_type, args.m_pciId);
 	bgfx::reset(width, height, reset);
 	bgfx::reset(width, height, reset);
 
 
 	// Enable debug text.
 	// Enable debug text.
@@ -149,24 +151,6 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 		loadTexture("texture_compression_ptc24.pvr"),
 		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 bgfx::Caps* caps = bgfx::getCaps();
 	const bool texture3DSupported = !!(caps->supported & BGFX_CAPS_TEXTURE_3D);
 	const bool texture3DSupported = !!(caps->supported & BGFX_CAPS_TEXTURE_3D);
 	const bool blitSupported      = !!(caps->supported & BGFX_CAPS_TEXTURE_BLIT);
 	const bool blitSupported      = !!(caps->supported & BGFX_CAPS_TEXTURE_BLIT);
@@ -176,6 +160,24 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 
 
 	if (texture3DSupported)
 	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]) )
 		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);
 			textures3d[numTextures3d++] = bgfx::createTexture3D(32, 32, 32, 0, bgfx::TextureFormat::R8,   BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP, mem8);

+ 4 - 2
examples/09-hdr/hdr.cpp

@@ -141,14 +141,16 @@ inline float square(float _x)
 
 
 class HDR : public entry::AppI
 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_width  = 1280;
 		m_height = 720;
 		m_height = 720;
 		m_debug  = BGFX_DEBUG_TEXT;
 		m_debug  = BGFX_DEBUG_TEXT;
 		m_reset  = BGFX_RESET_VSYNC;
 		m_reset  = BGFX_RESET_VSYNC;
 
 
-		bgfx::init();
+		bgfx::init(args.m_type, args.m_pciId);
 		bgfx::reset(m_width, m_height, m_reset);
 		bgfx::reset(m_width, m_height, m_reset);
 
 
 		// Enable m_debug text.
 		// Enable m_debug text.

+ 58 - 1
examples/common/bgfx_utils.cpp

@@ -13,8 +13,9 @@
 namespace stl = tinystl;
 namespace stl = tinystl;
 
 
 #include <bgfx/bgfx.h>
 #include <bgfx/bgfx.h>
-#include <bx/readerwriter.h>
+#include <bx/commandline.h>
 #include <bx/fpumath.h>
 #include <bx/fpumath.h>
+#include <bx/readerwriter.h>
 #include <bx/string.h>
 #include <bx/string.h>
 #include "entry/entry.h"
 #include "entry/entry.h"
 #include <ib-compress/indexbufferdecompression.h>
 #include <ib-compress/indexbufferdecompression.h>
@@ -621,3 +622,59 @@ void meshSubmit(const Mesh* _mesh, const MeshState*const* _state, uint8_t _numPa
 {
 {
 	_mesh->submit(_state, _numPasses, _mtx, _numMatrices);
 	_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;
+	}
+}

+ 8 - 0
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, 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);
 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
 #endif // BGFX_UTILS_H_HEADER_GUARD