问题描述
我跑
glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxVertUniformsVect);
得到 1024.
比在 GLSL 中我做的
Than in GLSL I do
uniform mediump vec4[1020] instance_mat
没关系.但是使用 vec3/vec2/float 它失败了:
and that was ok. But with vec3/vec2/float it fails:
uniform mediump float[1030] instance_mat; // fails
//uniform mediump vec2[1030] instance_mat; // and this
//uniform mediump vec3[1030] instance_mat; // and this
出现以下错误:
无法找到合适的资源来绑定变量instance_mat".可能是大数组.
问题是:GL_MAX_VERTEX_UNIFORM_VECTORS 是否返回所有类型数组的数量,无论它们的大小如何?我的意思是,无论这个 float/vec2/vec3/vec4 - 都算作一VERTEX_UNIFORM_VECTOR?
The question is:Does GL_MAX_VERTEX_UNIFORM_VECTORS return the number of all kind of arrays, no matter what size they are? I mean, no matter does this float/vec2/vec3/vec4 - all counts as one VERTEX_UNIFORM_VECTOR?
顶点着色器代码,原样:
Vertex shader code, as is:
#version 120
uniform mediump float[1200] instance_mat; //mat4x3
attribute mediump float instaceIdF; // in range 0..1000 Will be converted to int
attribute mediump vec3 vertex_;
attribute lowp vec4 color;
uniform mediump mat4 matrix;
varying lowp vec4 v_color;
void main(void)
{
v_color = color;
int instaceId = int(instaceIdF) * 12;
mediump mat4 offsetMat = mat4(
vec4(instance_mat[instaceId], instance_mat[instaceId+1], instance_mat[instaceId+2], 0),
vec4(instance_mat[instaceId+3], instance_mat[instaceId+4], instance_mat[instaceId+5], 0),
vec4(instance_mat[instaceId+6], instance_mat[instaceId+7], instance_mat[instaceId+8], 0),
vec4(instance_mat[instaceId+9], instance_mat[instaceId+10], instance_mat[instaceId+11], 1)
);
/*mediump mat4 offsetMat = mat4(
vec4(instance_mat[instaceId].xyz, 0),
vec4(instance_mat[instaceId+1].xyz, 0),
vec4(instance_mat[instaceId+2].xyz, 0),
vec4(instance_mat[instaceId+3].xyz, 1)
);*/
gl_Position = matrix * offsetMat * vec4(vertex_, 1.0);
//gl_Position = matrix * vec4(vertex, 1.0);
}
推荐答案
根据 http://www.opengl.org/wiki/Uniform_%28GLSL%29(实施限制):
实现说明:OpenGL实现允许拒绝着色器的实现相关的原因.所以你可以少活动统一组件按您的计算仍然无法链接到统一限度.这通常是在天生矢量的硬件上硬件.Pre-GeForce 8xxx 硬件和所有 ATi 硬件都这样做.在这种情况下,您应该假设每个单独的制服占用 4组件,就像在 D3D 中一样.这意味着统一浮动"是 4 个分量,一个 mat2x4 是 16 个分量(每行是 4组件),但 mat4x2 是 8 个组件.
我也是这种情况.但它不必总是那样.当然,出于兼容的原因,最好将每个 float/vec2/vec3 统一值计算为最大大小值 (vec4)
Which is my case, also. But it not has to be always like that.Of course, for compatible reasons it is always better to count each float/vec2/vec3 uniform value, as max size value (vec4)
这篇关于GLSL float/vec3/vec4 数组最大大小 = GL_MAX_VERTEX_UNIFORM_VECTORS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!