OpenGL ES 2.0 draw Fullscreen Quad very slow

2019-08-02 20:29发布

When I'm rendering my content onto a FBO with a texture bound to it and then render this bound texture to a fullscreen quad using a basic shader the performance drops ridiculously.

For example:

Render to screen directly (with basic shader):

enter image description here

And when render to texture first, then render texture with fullscreen quad: (with same basic shader, would be something like blur or bloom normally):

enter image description here

Anyone got an idea how to speed this up? Since the current performance is not usable. Also I'm using GLKit for the basic OpenGL stuff.

2条回答
倾城 Initia
2楼-- · 2019-08-02 20:41

This is very likely caused by ill-performant openGL ES API calls.

You should attach a real device and do an openGL ES frame capture. (It really needs a real device, the option for frame capture won't be available with a simulator).

The frame capture will indicate memory and other warnings along with suggestions to fix them alongside each API call. Step through these and fix each. The performance should improve considerably.

Here's a couple of references to get this done:

查看更多
我命由我不由天
3楼-- · 2019-08-02 20:53

Need to use precisions in places where it's needed.
lowp - for colors, textures coord, normals etc.
highp - for matrices and vertices/positions
Quick reference , check the range of precisions, on 3 page in "Qualifiers".

//  BasicShader.vsh
precision mediump float;

attribute highp vec2 position;
attribute lowp vec2 texCoord;
attribute lowp vec4 color;

varying lowp vec2 textureCoord;
varying lowp vec4 textureColor;

uniform highp mat4 projectionMat;
uniform highp mat4 worldMat;

void main() {
    highp mat4 worldProj = worldMat * projectionMat;
    gl_Position = worldProj * vec4(position, 0.0, 1.0);
    textureCoord = texCoord;
    textureColor = color;
}

//  BasicShader.fsh
precision mediump float;

varying lowp vec2 textureCoord;
varying lowp vec4 textureColor;

uniform sampler2D sampler;

void main() {
    lowp vec4 Color = texture2D(sampler, textureCoord);
    gl_FragColor = Color * textureColor;
}
查看更多
登录 后发表回答