1 / 23

Language Definitions

Language Definitions. Chap. 3 of Orange Book. Contents. Data types Initializers and constructors Type conversions Qualifiers; interface to a shader Flow control Operators. Introduction.

netis
Télécharger la présentation

Language Definitions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Language Definitions Chap. 3 of Orange Book

  2. Contents • Data types • Initializers and constructors • Type conversions • Qualifiers; interface to a shader • Flow control • Operators

  3. Introduction • A program typically contains two shaders: one vertex shader and one fragment shader. More than one shader of each type can be present, but there must be exactly one function main between all the fragment shaders and exactly one function main between all the vertex shaders.

  4. Example (Vertex Shader)

  5. Example (Fragment Shader)

  6. Data Types • Scalar types • float, bool, int [bitwise ops are not supported] • Vectors • vec[2|3|4], bvec[2|3|4], ivec[2|3|4] • selecting components: x,y,z,w; s,t,p,q; r,g,b,a • GLSL does not distinguish between a color vector and a position vector or other uses of a floating-point vector. • Matrices (floating point only) • mat[2|3|4] (column-major order) • Samplers • 1|2|3D textures, cube map, shadow (depth texture) • They can only receive them from the application, through a uniform qualified sampler, or pass them on to user or built-in functions. • Shaders may not manipulate sampler values. Grass + 1 is not allowed.

  7. Data Types (cont) • Structure • Arrays (next page) • No {typecast, pointers, implicit type change} • use constructors to perform conversions

  8. Using Arrays • #version 120 – declare version of glsl • NO variable length array; array of arrays

  9. Type Conversion

  10. Swizzling

  11. Component-wise Operation

  12. Initializers and Constructors • Constant qualified variables must be initialized. • Attribute, uniform, and varying variables cannot be initialized when declared. • Attribute,uniform: API sets it • Varying: vertex shader sets it • Extra components within a single constructor argument are silently ignored. Normally, this is useful for shrinking a value, like eliminating alpha from a color or w from a position.

  13. Initialize Struct • To initialize aggregate types, constructors are used. No initializer uses the brace syntax "{. . .}" from C.

  14. Example: initializers (column-major)

  15. Qualifiers • Attribute • Floating point scalar, vectors, and matrices • For vertex shaders only • Uniform • Read-only in shaders • Varying • Dynamic interface between vertex shaders and fragment shader • Const • Compile time constant • Absent • (See next page)

  16. Absent Qualifier • If no qualifier is specified when a variable (not a function parameter) is declared, the variable can be both read and written by the shader. • Nonqualified variables declared at global scope can be shared between shaders of the same type that are linked in the same program. • Vertex shaders and fragment shaders each have their own separate global name space for nonqualified globals. (compare uniform) • However, nonqualified user-defined variables are not visible outside a program. • Unqualified variables have a lifetime limited to a single run of a shader. There is also no concept corresponding to a static variable in a C function that would allow a variable to be set to a value and have its shader retain that value from one execution to the next.

  17. goto, switch

  18. Flow Control • Looping can be done with for, while, and do-while • The keywords break and continue also exist and behave as in C. • Selection can be done with if and if-else, just as in C++, with the exception that a variable cannot be declared in the if statement. Selection by means of the selection operator (?:) is also available, with the extra constraint that the second and third operands must have exactly the same type. • The type of the expression provided to an if statement or a while statement, or to terminate a for statement, must be a scalar Boolean • A special branch, discard, can prevent a fragment from updating the frame buffer

  19. Function Calls call by value-return • Parameter qualifiers: in, out, inout; const • in qualifier is implied when no qualifiers are specified

More Related