美文网首页
2018-06-08 2. bgfx iOS 上 使用 Meta

2018-06-08 2. bgfx iOS 上 使用 Meta

作者: 自由快挂 | 来源:发表于2018-06-08 17:01 被阅读152次

    苹果强推 Metal,cocos2d-x 论坛里也有讨论:

    https://discuss.cocos2d-x.org/t/opengl-is-deprecated-in-10-14-mojave/42732/11?u=yinjimmy
    https://discuss.cocos2d-x.org/t/what-if-cocos2d-x-switched-to-bgfx/42742

    但是帖子被锁住了,不能回帖了。

    默认的 iOS 工程是不使用 Metal 的,得自己修改。

    diff --git a/examples/common/entry/entry_ios.mm b/examples/common/entry/entry_ios.mm
    index 569e99f5..2c35b381 100644
    --- a/examples/common/entry/entry_ios.mm
    +++ b/examples/common/entry/entry_ios.mm
    @@ -14,7 +14,7 @@
     #if __IPHONE_8_0 && !TARGET_IPHONE_SIMULATOR  // check if sdk/target supports metal
     #   import <Metal/Metal.h>
     #   import <QuartzCore/CAMetalLayer.h>
    -//#   define HAS_METAL_SDK
    +#   define HAS_METAL_SDK
     #endif
    

    或者添加预编译宏 HAS_METAL_SDK,这里直接修改源代码,避免生成工程需要再修改项目工程。

    观察 log 输出:

    2018-06-08 16:41:43.662469+0800 examplesDebug[8227:4058019] [DYMTLInitPlatform] platform initialization successful
    2018-06-08 16:41:43.969076+0800 examplesDebug[8227:4057914] +[CATransaction synchronize] called within transaction
    2018-06-08 16:41:44.002333+0800 examplesDebug[8227:4057914] Metal GPU Frame Capture Enabled
    2018-06-08 16:41:44.003685+0800 examplesDebug[8227:4057914] Metal API Validation Enabled
    2018-06-08 16:41:44.032471+0800 examplesDebug[8227:4058036] /Users/admin/repos/game-engine/bgfx/src/bgfx.cpp (2898): BGFX Init...
    
    2018-06-08 16:41:44.033308+0800 examplesDebug[8227:4058036] /Users/admin/repos/game-engine/bgfx/src/bgfx.cpp (1433): BGFX Application called bgfx::renderFrame directly, not creating render thread.
    
    2018-06-08 16:41:44.033337+0800 examplesDebug[8227:4058036] /Users/admin/repos/game-engine/bgfx/src/bgfx.cpp (1449): BGFX Running in multi-threaded mode
    
    2018-06-08 16:41:44.196267+0800 examplesDebug[8227:4057914] /Users/admin/repos/game-engine/bgfx/src/renderer_mtl.mm (390): BGFX Init.
    
    2018-06-08 16:41:44.274888+0800 examplesDebug[8227:4058036] /Users/admin/repos/game-engine/bgfx/src/bgfx.cpp (1184): BGFX 
    
    2018-06-08 16:41:44.274979+0800 examplesDebug[8227:4058036] /Users/admin/repos/game-engine/bgfx/src/bgfx.cpp (1210): BGFX Supported renderer backends (3):
    
    2018-06-08 16:41:44.275027+0800 examplesDebug[8227:4058036] /Users/admin/repos/game-engine/bgfx/src/bgfx.cpp (1213): BGFX    - Noop
    
    2018-06-08 16:41:44.275044+0800 examplesDebug[8227:4058036] /Users/admin/repos/game-engine/bgfx/src/bgfx.cpp (1213): BGFX    - Metal
    
    2018-06-08 16:41:44.275060+0800 examplesDebug[8227:4058036] /Users/admin/repos/game-engine/bgfx/src/bgfx.cpp (1213): BGFX    - OpenGL ES 2.0
    
    2018-06-08 16:41:44.275075+0800 examplesDebug[8227:4058036] /Users/admin/repos/game-engine/bgfx/src/bgfx.cpp (1216): BGFX 
    
    ... 省略
    
    2018-06-08 16:41:44.360802+0800 examplesDebug[8227:4057914] /Users/admin/repos/game-engine/bgfx/src/renderer_mtl.mm (2610): BGFX Texture   0: R8 (requested: R8), layers 1, 2048x24 RT[.], WO[.], CW[.], sRGB[.]
    
    2018-06-08 16:41:44.361480+0800 examplesDebug[8227:4057914] /Users/admin/repos/game-engine/bgfx/src/renderer_mtl.mm (2340): BGFX Vertex Shader consts 1
    
    2018-06-08 16:41:44.361672+0800 examplesDebug[8227:4057914] /Users/admin/repos/game-engine/bgfx/src/renderer_mtl.mm (2340): BGFX Fragment Shader consts 0
    
    2018-06-08 16:41:44.361843+0800 examplesDebug[8227:4057914] /Users/admin/repos/game-engine/bgfx/src/renderer_mtl.mm (2411): BGFX attr a_color0: 0
    
    2018-06-08 16:41:44.361872+0800 examplesDebug[8227:4057914] /Users/admin/repos/game-engine/bgfx/src/renderer_mtl.mm (2411): BGFX attr a_color1: 1
    
    2018-06-08 16:41:44.361893+0800 examplesDebug[8227:4057914] /Users/admin/repos/game-engine/bgfx/src/renderer_mtl.mm (2411): BGFX attr a_position: 2
    
    2018-06-08 16:41:44.361922+0800 examplesDebug[8227:4057914] /Users/admin/repos/game-engine/bgfx/src/renderer_mtl.mm (2411): BGFX attr a_texcoord0: 3
    
    2018-06-08 16:41:44.361978+0800 examplesDebug[8227:4057914] vertexdecl 74c34f26 (d443ed7f), stride 28
    
    2018-06-08 16:41:44.362019+0800 examplesDebug[8227:4057914]     attr 0 - Attrib::Position, num 3, type 4, norm 0, asint 0, offset 0
    
    2018-06-08 16:41:44.362084+0800 examplesDebug[8227:4057914]     attr 4 - Attrib::Color0, num 4, type 0, norm 1, asint 0, offset 12
    
    2018-06-08 16:41:44.362124+0800 examplesDebug[8227:4057914]     attr 5 - Attrib::Color1, num 4, type 0, norm 1, asint 0, offset 16
    
    2018-06-08 16:41:44.362163+0800 examplesDebug[8227:4057914]     attr 10 - Attrib::TexCoord0, num 2, type 4, norm 0, asint 0, offset 20
    
    2018-06-08 16:41:44.362431+0800 examplesDebug[8227:4057914] /Users/admin/repos/game-engine/bgfx/src/renderer_mtl.mm (2340): BGFX Vertex Shader consts 0
    
    2018-06-08 16:41:44.363276+0800 examplesDebug[8227:4057914] /Users/admin/repos/game-engine/bgfx/src/renderer_mtl.mm (2340): BGFX Fragment Shader consts 1
    
    2018-06-08 16:41:44.363600+0800 examplesDebug[8227:4057914] /Users/admin/repos/game-engine/bgfx/src/renderer_mtl.mm (2411): BGFX attr a_position: 0
    
    2018-06-08 16:41:44.363650+0800 examplesDebug[8227:4057914] /Users/admin/repos/game-engine/bgfx/src/renderer_mtl.mm (2340): BGFX Fragment Shader consts 1
    
    2018-06-08 16:41:44.363771+0800 examplesDebug[8227:4057914] /Users/admin/repos/game-engine/bgfx/src/renderer_mtl.mm (2411): BGFX attr a_position: 0
    
    2018-06-08 16:41:44.364013+0800 examplesDebug[8227:4057914] /Users/admin/repos/game-engine/bgfx/src/renderer_mtl.mm (2340): BGFX Fragment Shader consts 1
    

    iPhone 4s 测试

    clang: fatal error: optimization flag '-fomit-frame-pointer' is not supported for target 'armv7' [-Wignored-optimization-argument]
    

    相关文章

      网友评论

          本文标题:2018-06-08 2. bgfx iOS 上 使用 Meta

          本文链接:https://www.haomeiwen.com/subject/qmvasftx.html