Recommend a powerful Android OpenGL ES debugging tool

Recommend a powerful Android OpenGL ES debugging tool

The original article was first published on WeChat Official Account: Byte Flow

What is GAPID?

GAPID (Graphics API Debugger) is an open source and cross-platform graphics development and debugging tool from Google. It is used to record and check application calls to graphics drivers. It supports OpenGL ES and Vulkan debugging.

Tool download address:

The main functions of GAPID:

  • View the calling situation of OpenGL ES or Vulkan drawing interface (calling sequence, flow);
  • View the parameters passed into the shader program;
  • View textures, export models, textures and other resources;
  • View, modify and export shader scripts.

The above picture is from the GAPID official website. We can see the entire rendering process of a 3D scene and the texture map used in each rendering. Many friends who see this may have questions in their hearts: If I see the effect of an OpenGL implementation of others, can I use GAPID to grab the source code of its shader script to learn? The answer is yes.

After compiling the binary code generated by the shader script, you can grab it through GAPID and decompile it into the original shader source code. All in all, your shader script is actually running naked on the GPU, especially for mobile phone manufacturers.

As far as I know, there is currently no effective encryption or obfuscation method for shader scripts at the GPU level. A more common method is to make the variables in the shader meaningless, such as using var1, var2, etc., or split a shader into Multiple small shaders to reduce readability.

How to use GAPID?

After downloading and installing the GAPID program, connect the Android phone to the computer via USB (Android Studio needs to be closed at the same time), and the phone is in the Debug mode in the developer options. Note that GAPID supports Android 5.0 and above mobile phones, the App to be debugged requires the Debug version or the phone is rooted.

Open GAPID program, click on the Capture a new traceready to debug our program.

Select the program to be debugged, select the interface type to OpenGL EStype, and then start to crawl Graphics Trace information.

After the capture is complete, open the trace file, and then the interface of the GAPID program is as shown in the figure below.

The area on the left is the drawing process of each captured frame. The drawing process of one frame is shown in area 1. Since we used the example of drawing water ripples in the old text as the debugging program, you can compare the display in area 1. The drawing process is basically the same as the code below to draw water ripples.

void ShockWaveSample::Draw(int screenW, int screenH)
	glUseProgram (m_ProgramObj);

	GLUtils::setMat4(m_ProgramObj, "u_MVPMatrix", m_MVPMatrix);

	glBindTexture(GL_TEXTURE_2D, m_TextureId);
	GLUtils::setFloat(m_ProgramObj, "s_TextureMap", 0);

	//float time = static_cast<float>(fmod(GetSysCurrentTime(), 2000)/2000);
    float time = static_cast<float>(fmod(m_FrameIndex, 150)/120);
	GLUtils::setFloat(m_ProgramObj, "u_Time", time);

	GLUtils::setVec2(m_ProgramObj, "u_TouchXY", m_touchXY);
    GLUtils::setVec2(m_ProgramObj, "u_TexSize", vec2(m_RenderImage.width, m_RenderImage.height));
	GLUtils::setFloat(m_ProgramObj, "u_Boundary", 0.1f);

	glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, (const void *)0);


Area 2 shows the value of each variable passed to the shader program when the current frame is drawn. You can clearly see the value of each variable and matrix.

Area 3 shows the status information of the shader program. We find the corresponding LinkExtra according to the id of the shader program, and then we can get the shader script source code corresponding to the current shader program, which is consistent with the program in the code.

This article mainly introduces some common functions of GAPID, and there are more high-end functions waiting for you to explore.

Implementation code path: Android_OpenGLES_3_0

Contact and exchange