public BgfxBuild() { var rendererRoot = AsmDefConfigFile.AsmDefDescriptionFor("Unity.Tiny.Rendering.Native").Directory; bool useLocalBgfx = false; BgfxArtifact = new StevedoreArtifact("bgfx-source"); BgfxRoot = BgfxArtifact.Path.ResolveWithFileSystem(); //BgfxRoot = @"C:\Users\sebastianm\gits\bgfx-root"; //useLocalBgfx = true; var bx = BgfxRoot.Combine("bx"); var bgfx = BgfxRoot.Combine("bgfx"); var bimg = BgfxRoot.Combine("bimg"); // Note that these 3 NativePrograms are only linked in as BagOfObjects into the bgfx dll above. // They should not have Libraries themselves (e.g. bgfx should not reference the bx or bimg NativePrograms). // This means that PublicIncludes won't work, which is why Bimg and Bgfx explicitly add BxLib's PublicIncludes // to their own Includes. BxLib = new NativeProgram("bx") { Exceptions = { false }, RTTI = { false }, PublicIncludeDirectories = { bx.Combine("include"), bx.Combine("3rdparty"), }, Sources = { //bx.Combine("src").Files("*.cpp").Except(new[] {bx.Combine("src/amalgamated.cpp"), bx.Combine("src/crtnone.cpp")}) bx.Combine("src/amalgamated.cpp") }, Defines = { "__STDC_FORMAT_MACROS" }, }; BxLib.CompilerSettings().Add(c => c.WithCppLanguageVersion(CppLanguageVersion.Cpp14)); BxLib.CompilerSettingsForMac().Add(c => c.WithObjcArc(false)); BxLib.CompilerSettingsForIos().Add(c => c.WithObjcArc(false)); BxLib.Defines.Add(c => c.Platform is WindowsPlatform, "_CRT_SECURE_NO_WARNINGS"); BxLib.PublicIncludeDirectories.Add(c => c.ToolChain is WindowsToolchain, bx.Combine("include/compat/msvc")); BxLib.PublicIncludeDirectories.Add(c => c.Platform is MacOSXPlatform, bx.Combine("include/compat/osx")); BxLib.PublicIncludeDirectories.Add(c => c.Platform is IosPlatform, bx.Combine("include/compat/ios")); BxLib.CompilerSettingsForEmscripten().Add(Il2Cpp.ManagedDebuggingIsEnabled, c => c.WithMultithreading_Compiler(EmscriptenMultithreadingMode.Enabled)); BimgLib = new NativeProgram("bimg") { Exceptions = { false }, RTTI = { false }, IncludeDirectories = { bimg.Combine("include"), bimg.Combine("3rdparty/astc-codec/include"), // comment out next line once BIMG_DECODE_ASTC lands in bimg bimg.Combine("3rdparty/astc-codec"), }, Sources = { bimg.Combine("src/image.cpp"), bimg.Combine("src/image_gnf.cpp"), // comment out next line once BIMG_DECODE_ASTC lands in bimg bimg.Combine("3rdparty/astc-codec/src/decoder").CombineMany(new [] { "astc_file.cc","codec.cc", "endpoint_codec.cc", "footprint.cc", "integer_sequence_codec.cc", "intermediate_astc_block.cc", "logical_astc_block.cc", "partition.cc", "physical_astc_block.cc", "quantization.cc", "weight_infill.cc" }) }, Defines = { "__STDC_FORMAT_MACROS", "BIMG_DECODE_ENABLE=0" }, }; BimgLib.CompilerSettings().Add(c => c.WithCppLanguageVersion(CppLanguageVersion.Cpp14)); BimgLib.CompilerSettingsForMac().Add(c => c.WithObjcArc(false)); BimgLib.CompilerSettingsForIos().Add(c => c.WithObjcArc(false)); BimgLib.IncludeDirectories.Add(c => BxLib.PublicIncludeDirectories.For(c)); BimgLib.CompilerSettingsForEmscripten().Add(Il2Cpp.ManagedDebuggingIsEnabled, c => c.WithMultithreading_Compiler(EmscriptenMultithreadingMode.Enabled)); BgfxLib = new NativeProgram("bgfx") { Exceptions = { false }, RTTI = { false }, IncludeDirectories = { bimg.Combine("include"), bgfx.Combine("include"), bgfx.Combine("3rdparty"), bgfx.Combine("3rdparty/khronos"), rendererRoot.Combine("cpp~/include"), }, Defines = { "BGFX_SHARED_LIB_BUILD", "__STDC_FORMAT_MACROS" }, }; BgfxLib.CompilerSettings().Add(c => c.WithCppLanguageVersion(CppLanguageVersion.Cpp14)); BgfxLib.CompilerSettingsForMac().Add(c => c.WithObjcArc(false)); BgfxLib.CompilerSettingsForIos().Add(c => c.WithObjcArc(false)); BgfxLib.IncludeDirectories.Add(c => BxLib.PublicIncludeDirectories.For(c)); BgfxLib.Defines.Add(c => ((DotsRuntimeNativeProgramConfiguration)c).CSharpConfig.Defines.Contains("RENDERING_ENABLE_TRACE"), "BGFX_CONFIG_DEBUG=1"); BgfxLib.Defines.Add(c => c.ToolChain is WindowsToolchain, "_CRT_SECURE_NO_WARNINGS"); //BgfxLib.Defines.Add("BGFX_CONFIG_DEBUG_UNIFORM=0"); if (!useLocalBgfx) { // when using bgfx from stevedore, this requires pix3.h which we don't distribute BgfxLib.Defines.Add(c => c.Platform is WindowsPlatform, "BGFX_CONFIG_DEBUG_ANNOTATION=0"); } else { BgfxLib.Defines.Add(c => c.Platform is WindowsPlatform, "BGFX_CONFIG_DEBUG_ANNOTATION=0"); ///BgfxLib.IncludeDirectories.Add(bgfx.Combine("3rdparty/dxsdk")); } BgfxLib.Defines.Add("BGFX_CONFIG_MAX_BONES=4"); BgfxLib.Defines.Add(c => (c as DotsRuntimeNativeProgramConfiguration)?.CSharpConfig.EnableProfiler == true, "BGFX_CONFIG_PROFILER=1"); // At some point we need to stop using amalgamated, especially for small-size web builds BgfxLib.Sources.Add(c => !(c.Platform is MacOSXPlatform || c.Platform is IosPlatform), bgfx.Combine("src/amalgamated.cpp")); BgfxLib.Sources.Add(c => (c.Platform is MacOSXPlatform || c.Platform is IosPlatform), bgfx.Combine("src/amalgamated.mm")); // This is a hack that the Khronos eglplatform.h header understands in order to define the EGL types as intptr_t, // which is what emscripten wants. Otherwise we fall into a __unix__ path, which includes X11/Xlib.h, and // all hell breaks loose. BgfxLib.Defines.Add(c => c.Platform is WebGLPlatform, "USE_OZONE"); BgfxLib.CompilerSettingsForEmscripten().Add(Il2Cpp.ManagedDebuggingIsEnabled, c => c.WithMultithreading_Compiler(EmscriptenMultithreadingMode.Enabled)); }