我有非常简单的顶点着色器,如:
uniform mat4 u_Matrix;
uniform float u_PointSize;
attribute vec4 a_Position;
attribute vec4 a_Color;
varying vec4 v_Color;
void main() {
v_Color = a_Color;
gl_PointSize = u_PointSize;
gl_Position = u_Matrix * a_Position;
}
我初始化浮点缓冲区,比如:
floatBuffer = ByteBuffer
.allocateDirect(vertexData.length * Constants.BYTES_PER_FLOAT)
.order(ByteOrder.nativeOrder())
.asFloatBuffer()
.put(vertexData);
其中顶点数据包含例如(X、Y、R、G、B):
float[] vertexData = new float[] {100, 100, 1f, 0f, 0f}
当我想改变坐标(在某些情况下,我真的需要它,而使用变换矩阵不是解决方案)或颜色时,我需要:
-
更改vertexData数组中的必要值
-
创建新ByteBuffer
这看起来是一个糟糕的解决方案,因为每次我想更改颜色/坐标时,它都会通过调用ByteBuffer.allocateDirect(..)来创建新的字节缓冲区。
你能解释一下哪种方式更好吗?
我考虑过使用制服进行颜色,每次我需要更改/恢复颜色时都使用glUniformMatrix4fv(..),但我不确定这是否也是一种好方法。