燃烧的火焰

操作系统 云服务/平台 技术难度 关注领域
Android   Intermediate Embedded Gaming

任务目标

高通Adreno GPU拥有强大的绘图性能,我希望做一个模拟火焰的应用来展示这种性能,并用Snapdragon Profiler软件分析CPU和GPU的性能使用情况。

 

这是一张漂亮的火焰模型,当apk运行时你可以看到它。

所需材料/所需清单/工具

  • Adreno GPU SDK

  • Android NDK

  • Apache Ant

  • Snapdragon Profiler

源码/示例/可执行的应用程序

  • Source Code

附加资料

  • Burning-Flame.apk

以下展示了在这个项目中使用到的部分。

1. 在带有骁龙660处理器的安卓设备上安装使用Android NDK编译的apk程序,运行apk并查看火焰的显示效果。

2.Ubuntu 14

3.Windows 7

4.type-c 数据线

5.Adreno GPU SDK v5.0

6.Android NDK r17b。

7.Apache Ant 1.9.14。

8.骁龙Profiler,一个用来查看apk实时性能指标的工具。

 

部署项目

1.从链接处下载,安装PC。

2. Download Android NDK r17b and install it to PC。

3. Download Apache Ant 1.9.14 and install it to PC。

4. Download Snapdragon Profiler from https://developer.qualcomm.com/software/snapdragon-profiler, and install it to PC。

5.实现火焰shader。。

6.在APK中调用火焰shader。

7.在APK中实现FPS等信息的显示。

8.一步一步实现需要的功能。

9.选择android平台,连接设备,然后编译,生成APK并安装。

10.打开apk,欣赏它。

11.如果你关注性能指标,你可以使用骁龙Profiler 来查看。

12.如果没有问题,上传代码到github。

 

工作流程

如何实现火焰shader?

为了能够让OpenGL实现火焰的绘制,首先要创建shader

Vertex Shader

#version 300 es

layout (location = 0) in vec4 vertex; // <vec2 position, vec2 texCoords>

 

out vec2 TexCoords;

    out vec4 ParticleColor;

 

    uniform mat4 projection;

    uniform vec2 offset;

    uniform vec4 color;

    uniform float scale;

 

    void main()

    {

        TexCoords = vertex.zw;

        ParticleColor = color; //vec4(0.999995, 0.999995, 0.5, 0.0);

    #ifdef ENABLE_VERTEX_OFFSET

        gl_Position = projection * vec4(((vertex.xy - 0.5) * scale) + offset, 0.0, 1.0);

    #else //!ENABLE_VERTEX_OFFSET

        gl_Position = projection * vec4((vertex.xy * scale) + offset, 0.0, 1.0);

    #endif //ENABLE_VERTEX_OFFSET

}

 

 

Fragment Shader

    #version 300 es

    in vec2 TexCoords;

    in vec4 ParticleColor;

 

    out vec4 color;

 

    uniform sampler2D sprite;

 

    void main()

    {

#if 1

    color = (texture(sprite, TexCoords) * ParticleColor);

    #else

        color = ParticleColor;

    #endif

    }

 

这段代码分别了创建顶点着色器和片段着色器。

2.如何实现标题,菜单,文字等的显示?

调用SDK框架提供的CFrmFontGLES、CFrmUserInterfaceGLES类来实现标题,菜单和文字的显示。

// Create the font

m_pFont = new CFrmFontGLES();

if( FALSE == m_pFont->Create( "Samples/Fonts/Tuffy12.pak" ) )

{

FrmLogMessage("ERROR: create m_pFont failed\n");

return FALSE;

}

 

// Load the packed resources

CFrmPackedResourceGLES resource;

if( FALSE == resource.LoadFromFile( "Samples/Textures/Logo.pak" ) )

{

return FALSE;

}

 

// Create the logo texture

m_pLogoTexture = resource.GetTexture( "Logo" );

 

// Setup the user interface

if( FALSE == m_UserInterface.Initialize( m_pFont, g_strWindowTitle ) )

{

return FALSE;

}

 

m_UserInterface.AddOverlay( m_pLogoTexture->m_hTextureHandle, -5, -5, m_pLogoTexture->m_nWidth, m_pLogoTexture->m_nHeight );

m_UserInterface.AddTextString( (char *)"Press \200 for Help", 1.0f, -1.0f );

上述代码分别创建了CFrmFontGLES 和CFrmUserInterfaceGLES对象,其中CFrmUserInterfaceGLES对象可以调用AddOverlay和AddTextString方法来图标和文字的显示。

3.如何实现帧率的显示?

创建CFrmTimer类对象,并在render中调用CFrmUserInterfaceGLES对象来显示帧率。

// Update the timer

    m_Timer.MarkFrame();

 

// Render the user interface

    m_UserInterface.Render( m_Timer.GetFrameRate() );

4.如何编译生成APK?

Compile thesource code(编译代码)

cd jni/

ndk-build -B

cd ..

 

Update the resource file(更新资源)

./InstallAssets.sh

android update project -p . -t android-20

 

Generate the APK file(使用ant命令打包生成apk)

ant debug

5.如何使用Snapdragon Profiler软件分析CPU和GPU的使用率

1.将手机连接Snapdragon Profiler 软件。

2.选择realtime模式。

3.选择process添加CPU Utilization和GPU Utilization,实时的使用率结果会显示在中间的窗口中。

 

6.如何使用Snapdragon Profiler软件进行OpenGL的分析

1.将手机连接Snapdragon Profiler 软件。

2.改变layout设置为OpenGL。

3.选择 Snapshot Capture模式。

4.执行Take Snapshot操作。

 

1、https://github.com/ThunderSoft-XA/Adreno-Burning-Flame.git从此链接处下载源码。

2、安装 Adreno GPU SDK v5.0。

3、安装 Android NDK r17b。

4、安装 Apache Ant 1.9.14。

5、安装 Snapdragon Profiler。

6、编译成apk并安装到安卓设备。

7、打开apk,欣赏它。

8、如果关注性能指标,可以使用骁龙Profiler查看。

贡献者信息

姓名 公司

Zhen

sunzhen@thundersoft.com
Thundersoft

Rong

yangrong0925@thundersoft.com
Thundersoft

Jie

wangjie0508@thundersoft.com
Thundersoft

Kou

kouzw0723@thundersoft.com
Thundersoft

Eric

yansh0810@thundersoft.com
Thundersoft

>>浏览更多Qualcomm硬件案例:http://qualcomm.csdn.net/m/zone/qualcomm2016/project

Qualcomm 解决方案

 

高通 AI Hub

全新高通 AI Hub 包含预优化AI模型库,支持在搭载骁龙和高通平台的终端上进行无缝部署。
该模型库为开发者提供超过75个主流的AI和生成式AI模型,比如Whisper、ControlNet、Stable Diffusion和Baichuan-7B,可在不同执行环境(runtime)中打包,能够在不同形态终端中实现卓越的终端侧AI性能、降低内存占用并提升能效。所有模型均经过优化,以充分利用高通AI引擎内所有核心(NPU、CPU和GPU)的硬件加速能力,从而使推理速度提升4倍。

了解更多

SDK 下载

本版块下载 SDK,只需简单注册,就可轻松下载。