opengl – GLSL float/vec3/vec4数组最大大小= GL_MAX_VERTEX_UNIFORM_VECTORS?

前端之家收集整理的这篇文章主要介绍了opengl – GLSL float/vec3/vec4数组最大大小= GL_MAX_VERTEX_UNIFORM_VECTORS?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我跑 @H_403_2@glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS,&maxVertUniformsVect);

得到1024.

比我在GLSL做的

@H_403_2@uniform mediump vec4[1020] instance_mat

那没关系.但是使用vec3 / vec2 / float它会失败:

@H_403_2@uniform mediump float[1030] instance_mat; // fails //uniform mediump vec2[1030] instance_mat; // and this //uniform mediump vec3[1030] instance_mat; // and this

出现以下错误

cannot locate suitable resource to bind variable “instance_mat”.
Possibly large array.

问题是:
GL_MAX_VERTEX_UNIFORM_VECTORS是否返回所有类型的数组,无论它们的大小是多少?我的意思是,无论这个浮动/ vec2 / vec3 / vec4 – 都算作一个
VERTEX_UNIFORM_VECTOR?

顶点着色器代码,原样如下:

@H_403_2@#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],vec4(instance_mat[instaceId+6],instance_mat[instaceId+7],instance_mat[instaceId+8],vec4(instance_mat[instaceId+9],instance_mat[instaceId+10],instance_mat[instaceId+11],1) ); /*mediump mat4 offsetMat = mat4( vec4(instance_mat[instaceId].xyz,vec4(instance_mat[instaceId+1].xyz,vec4(instance_mat[instaceId+2].xyz,vec4(instance_mat[instaceId+3].xyz,1) );*/ gl_Position = matrix * offsetMat * vec4(vertex_,1.0); //gl_Position = matrix * vec4(vertex,1.0); }

@R_404_323@

根据 http://www.opengl.org/wiki/Uniform_%28GLSL%29(实施限制):

Implementation note: OpenGL implementations are allowed to reject
shaders for implementation-dependent reasons. So you can have fewer
active uniform components by your reckoning and still fail to link due
to uniform limits. This is usually on hardware that is innately vector
hardware. Pre-GeForce 8xxx hardware,and all ATi hardware does this.
In this case,you should assume that each separate uniform takes up 4
components,much like it would in D3D. That means a “uniform float”
is 4 components
,a mat2x4 is 16 components (each row is 4
components),but a mat4x2 is 8 components.

这也是我的情况.但它不一定总是那样.当然,出于兼容的原因,最好将每个float / vec2 / vec3统一值计算为最大值(vec4)

原文链接:https://www.f2er.com/css/217839.html

猜你在找的CSS相关文章