Overview of the coloring of the OpenGL ES Shader language (Official document)

Source: Internet
Author: User
Tags function definition

Overview of the coloring of the OpenGL ES Shader Language (Official Document chapter II)

In fact, OpenGL es coloring language is two closely related languages. These languages are used to create shaders in the OpenGL ES processing pipeline's programmable processor. In this document, unless otherwise noted, a language feature is available for all languages, and general usage will treat them as a language. Specific languages will indicate their target processor: vertex (vertext) or slice (fragment).

any OpenGL ES state value used by the shader is automatically tracked and used on the shader . This automatic state tracking mechanism allows applications to use OpenGL ES status commands for state management, and these status values are automatically applied to the shader.

2.1 Vertex processor

A vertex processor is a programmable unit that processes input vertices and related data. The compilation unit that runs this processor in OpenGL es coloring language is called the vertex shader (vertex shader).

A vertex shader can handle only one vertex at a time.

2.2-piece Meta processor

A chip processor is a programmable unit that processes slices and related data. The compilation unit that runs this processor in OpenGL es coloring language is called a chip shader (fragment shader).

The slice shader cannot change the position of the slice. Access to neighboring slices is also not allowed. The value computed by the slice shader is ultimately used to update the frame buffer memory or texture memory, depending on the current OpenGL ES status and the command that generated the slice.

The language base of the OpenGL ES Shader Language (Official Document chapter III)

3.1 Character Set

The source character set of the OpenGL ES Shading language is a subset of ASCII encodings that contain the following characters:

              Characters       A-Z, A-Z, and Underline (_).              Digital       0-9.              Dot (.),  Plus (+),  split Line (-),  slash (/),  asterisk (*), percent sign (%), greater than less (< and >),  square brackets ([and]), parentheses ((and)), c11/> Curly braces ({and}),  caret (^),  vertical bar (|), and (&),  tilde (~),  equals sign (=),  exclamation mark (!),  colon (:),  Semicolon (;),  comma (,),  question mark (?).               The pound sign (#) is    used as a preprocessor.               Spaces: space character, Horizontal tab, Vertical tab, page break, carriage return, line feed.              the line connector (\) is not part of the language.

In short, the character set used by the language is case-sensitive.

there is no character and string type, so the character set does not contain quotation marks.

There is also no file terminator. The compiler determines the end of a string by the length of the string, rather than by a particular character.

3.2 Source String

The source of a shader is an array of strings consisting of characters in the character set . Shaders are connected by these strings. Each string can span multiple lines. A single line can contain multiple strings.

In this version of the shading language, only one vertex shader and one slice shader can be linked together.

3.3 Logic Stages of compilation

Compilation processing is based on a subset of standard C + +. The compilation units for vertex and chip processors are processed separately in the final phase of the compilation-the link. the logical phase of the compilation is as follows :

1. SOURCE String Links

2. The source string is converted into a preprocessing symbol sequence. These symbols include preprocessing numbers, identifiers, and operators. Comments are replaced with a space, and line breaks are preserved.

3. The preprocessor executes.

4.GLSL ES syntax parses the converted symbol.

5. Link uniform, verying, fixed function variable.

3.4 Preprocessor
  # #define #undef #if #ifdef#ifndef #else #elif#endif#error#pragma #extension #version #line defined__line__ line number __file__ file name The __version__  version number Gl_es value is 1, which means that the ES OpenGL rendering language is used

Precedence and associativity of operators:

defined use of the operator:

Defined identifier            defined (identifier)            #error                 //Save diagnostic information to the information log of the shader object           #pragma           //allow the implementation of dependent compilation control. #pragma后面的符号不是预处理宏定义扩展的一部分. If the symbol behind the #pragma is not recognized, the #pragma is ignored.                                         the available pragma are as follows:          #pragma stdgl        //stdgl pragma is a reserved pragma for future language revisions. If no implementation of this macro will use the macro definition that begins with it           #pragma optimize (on          ) #pragma optimize (off)          //is used to turn on and off optimizations for developing and debugging shaders, by default, All shader optimizations are turned on and can only be used outside of the function definition.          #pragma debug (on)         #pragma debug (OFF)              //compile and annotate a shader and output debugging information so that it can be used as a debugger. Can only be used outside the function, which is closed by default.          #version                   Number//returns the version numbers of the current shading language         by default, the shader language compiler must publish compile-time syntax, grammar, and semantic errors. The behavior of any extension must be activated first. Instructions to control compiler extension behavior are #extension:         #extension Extension_name:behavior         
3.5 Notes

/* Comment on a module */

Comment Line

3.6 Symbols

The shading language is a sequence of symbols that can contain the following symbols:

keywords, identifiers, integer constants, floating-point constants, operands

3.7 Key Words
   Here is the keyword that the coloring language is already using: attribute const uniform VARYING                            Break continue does for and if else in out inout                            float int void bool true false lowp Mediump HIGHP Precision Invariant  Discard return mat2 mat3 mat4 vec2 vec3 vec4        IVEC2 ivec3 ivec4 bvec2 bvec3 bvec4 sampler2d samplercube struct                            Here is the reserved keyword: ASM class Union enum typedef template This packed Goto switch Default inline noinline volatile public static extern Exter Nal interface flat long short double half fixed unsigned superp inpu                T output            HVEC2 hvec3 hvec4 dvec2 dvec3 dvec4 fvec2 fvec3 fvec4 sampler1d Sampler3d Sampler1dshadow Sampler2dshadow sampler2drect Sampler3drect Sampler2drectshad ow sizeof cast namespace using 
3.8 identifiers

Identifiers are used as variable names, function names, struct names, and domain selector names (elements of the selection vector and matrix, similar to structural body fields). identifier naming rules:

(1) cannot start with a number, only with a letter and an underscore

(2) cannot start with "Gl_", which is reserved by OpenGL

 

Overview of the coloring of the OpenGL ES Shader language (Official document)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.