openGL ES 2.0 笔记 vertex shader

本文详细介绍了OpenGL ES 2.0中的顶点着色器,包括内建变量gl_Position、gl_PointSize和gl_FrontFacing的使用,内建uniform变量gl_DepthRange,以及各种内置常量如gl_MaxVertexAttribs。文章还讨论了顶点着色器的兼容性问题,如循环限制、条件表达式、数组索引和计算顶点着色器中使用的uniform数量的注意事项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 内建变量gl_Position,gl_PointSize, gl_FrontFacing, 

 

2. 内建uniform gl_DepthRange

 

3. built-in constants : 

gl_MaxVertexAttribs

gl_MaxVertexUniformVectors vertex shader中最大以vec4为计数单位的uniform变量个数,当你在使用某一个内建函数时,有可能已经使用了某个内建uniform,这时,uniform使用计数为+1.当前没有一个机制,在vertex shader中查找到你可以使用的uniform变量个数

gl_MaxVaryingVectors

gl_MaxVertexTextureImageUnits

gl_MaxCombinedTextureImageUnits 最大纹理单元个数,vertex shader ,fragment shader总和

 

4.vertex shader中,如果未指定,int float的数度都 为highp

 

5.遵循以下考虑,可以写出更加兼容的代码

.Length of Vertex Shader:没有一个方法 可以查询这个,epengl es 工作组希望有一个兼容性测试,包含对这个的测试

.Temporary Variables 函数中临时变量个数

.Flow Control for循环有以下限制:

 - Only one loop index can be used in a for loop.

 - The loop index must be initialized to a constant integral expression

 - The condition expression declared in the for loop must be one of the

following:

loop_indx < constant_expression

loop_indx <= constant_expression

loop_indx > constant_expression

loop_indx >= constant_expression

loop_indx != constant_expression

loop_indx == constant_expression

 - The loop index can be modified in the for loop statement using one of

the following expressions only:

loop_index--

loop_index++

loop_index -= constant_expression

loop_index += constant_expression

 - The loop index can be passed as a read-only argument to functions

inside the for loop (i.e., the loop index can be used with arguments

declared using the in parameter qualifier).

do-while 非必须支持

.条件表达式,以下表达式被支持

if(bool_expression)

{

}

if(bool_expression)

{

}

else

{

}

bool_expression必须是bool value,通常GPU可以同时对多个顶点进行运算,如果bool_expression的值因顶点不同而值不同,那会影响并行计算的效率,因些,bool_expression最好是顶点坐标无关的表达式,This will be the case if a uniform expression is used.

.Array Indexing Array indexing of uniforms (excluding samplers) is fully supported. The

array index can be a constant, uniform, or computed value. Samplers can

only be indexed using a constant integral expression. A constant integral

expression is a literal value (e.g., 4), a const integer variable (e.g., const int

sampler_indx = 3;), or a constant expression (e.g., 3 + sampler_indx).

Attribute matrices and vectors用一个变量做为索引可能不被支持。强制支持的只是constant integral expression

Counting Number of Uniforms Used in a Vertex Shader

所有下面的类型都存储在uniform存储区中:声明为uniform型的变量,const常量,字面量,内建常量,

字面量有可能被计数多次,从而浪费uniform存储区,好的做法是声明一个const常量

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值