0绘制全屏Quad很慢

0绘制全屏Quad很慢

本文介绍了OpenGL ES 2.0绘制全屏Quad很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将内容渲染到绑定了纹理的FBO上,然后使用基本着色器将此绑定纹理渲染到全屏四边形时,性能会大大降低.

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.

例如:

直接渲染到屏幕(使用基本着色器):

Render to screen directly (with basic shader):

当首先渲染为纹理时,然后使用全屏四边形渲染纹理:(使用相同的基本着色器,通常会像是模糊或绽放):

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

有人知道如何加快速度吗?由于当前性能无法使用.另外,我将GLKit用于基本的OpenGL内容.

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.

推荐答案

需要在需要的地方使用精度.
lowp-用于颜色,纹理坐标,法线等.
highp-用于矩阵和顶点/位置
快速参考,请检查精度范围,在限定词"的3页上.

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;
}

这篇关于OpenGL ES 2.0绘制全屏Quad很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 16:50