目录
6 陈述和结构
OpenGL ES着色语言的基本构建块是:
- 陈述和声明
- 方法名定义
- 选择(if-else)
- 迭代(for,while和do-while)
- 跳转(discard, return, break, 和continue)
编译单元的总体结构如下
translation-unit:
global-declaration
translation-unit global-declaration
global-declaration:
function-definition
declaration
也就是说,编译单元是一系列声明和函数体。 函数体定义如下:
function definition:
function prototype { statement list }
statement list:
statement
statement-list statement
statement:
compound-statement (复合语句)
simple-statement (简单语句)
大括号用于将语句序列分组为复合语句。
compound-statement:
{ statement-list }
simple-statement:
声明语句
表达式语句
选择语句
迭代语句
跳转语句
简单的声明,表达式和跳转语句以分号结尾。
上面的内容略有简化,将在第9节“着色语言语法”中指定了完整的语法“用作明确的规范。
声明和表达在之前已经讨论过了。
![](https://i-blog.csdnimg.cn/blog_migrate/b61b18ac35ef755ca70fdb04fbb7539f.png)