The OpenGL Shading Language (Language Version 4.40, Revision 9 - June 16, 2014).pdf

(858 KB) Pobierz
The OpenGL
®
Shading Language
Language Version: 4.40
Document Revision: 9
16-Jun-2014
Editor: John Kessenich, LunarG
Version 1.1 Authors: John Kessenich, Dave Baldwin, Randi Rost
Copyright (c) 2008-2014 The Khronos Group Inc. All Rights Reserved.
This specification is protected by copyright laws and contains material proprietary to the Khronos Group,
Inc. It or any components may not be reproduced, republished, distributed, transmitted, displayed,
broadcast or otherwise exploited in any manner without the express prior written permission of Khronos
Group. You may use this specification for implementing the functionality therein, without altering or
removing any trademark, copyright or other notice from the specification, but the receipt or possession of
this specification does not convey any rights to reproduce, disclose, or distribute its contents, or to
manufacture, use, or sell anything that it may describe, in whole or in part.
Khronos Group grants express permission to any current Promoter, Contributor or Adopter member of
Khronos to copy and redistribute UNMODIFIED versions of this specification in any fashion, provided that
NO CHARGE is made for the specification and the latest available update of the specification for any
version of the API is used whenever possible. Such distributed specification may be re-formatted AS
LONG AS the contents of the specification are not changed in any way. The specification may be
incorporated into a product that is sold as long as such product includes significant independent work
developed by the seller. A link to the current version of this specification on the Khronos Group web-site
should be included whenever possible with specification distributions.
Khronos Group makes no, and expressly disclaims any, representations or warranties, express or
implied, regarding this specification, including, without limitation, any implied warranties of merchantability
or fitness for a particular purpose or non-infringement of any intellectual property. Khronos Group makes
no, and expressly disclaims any, warranties, express or implied, regarding the correctness, accuracy,
completeness, timeliness, and reliability of the specification. Under no circumstances will the Khronos
Group, or any of its Promoters, Contributors or Members or their respective partners, officers, directors,
employees, agents or representatives be liable for any damages, whether direct, indirect, special or
consequential damages for lost revenues, lost profits, or otherwise, arising from or in connection with
these materials.
Khronos, OpenKODE, OpenKOGS, OpenVG, OpenMAX, OpenSL ES and OpenWF are trademarks of
the Khronos Group Inc. COLLADA is a trademark of Sony Computer Entertainment Inc. used by
permission by Khronos. OpenGL and OpenML are registered trademarks and the OpenGL ES logo is a
trademark of Silicon Graphics Inc. used by permission by Khronos. All other product names, trademarks,
and/or company names are used solely for identification and belong to their respective owners.
ii
Table of Contents
1
Introduction.................................................................................................................................1
1.1
Acknowledgments................................................................................................................2
1.2
Changes................................................................................................................................3
1.2.1
Changes since revision 8 of GLSL version 4.40..........................................................3
1.2.2
Changes since revision 7 of GLSL version 4.40..........................................................3
1.2.3
Changes since revision 6 of GLSL version 4.40..........................................................5
1.2.4
Summary of Changes from Revision 9 of GLSL Version 4.30....................................5
1.3
Overview..............................................................................................................................8
1.4
Error Handling......................................................................................................................8
1.5
Typographical Conventions.................................................................................................9
1.6
Deprecation..........................................................................................................................9
2
Overview of OpenGL Shading..................................................................................................10
2.1
Vertex Processor................................................................................................................10
2.2
Tessellation Control Processor...........................................................................................10
2.3
Tessellation Evaluation Processor......................................................................................11
2.4
Geometry Processor...........................................................................................................11
2.5
Fragment Processor............................................................................................................11
2.6
Compute Processor.............................................................................................................11
3
Basics........................................................................................................................................13
3.1
Character Set and Phases of Compilation..........................................................................13
3.2
Source Strings....................................................................................................................14
3.3
Preprocessor.......................................................................................................................15
3.4
Comments..........................................................................................................................20
3.5
Tokens................................................................................................................................21
3.6
Keywords............................................................................................................................21
3.7
Identifiers...........................................................................................................................23
3.8
Definitions..........................................................................................................................23
3.8.1
Static Use....................................................................................................................24
3.8.2
Uniform and Non-Uniform Control Flow..................................................................24
3.8.3
Dynamically Uniform Expressions.............................................................................24
4
Variables and Types..................................................................................................................25
4.1
Basic Types........................................................................................................................25
4.1.1
Void............................................................................................................................29
4.1.2
Booleans.....................................................................................................................29
4.1.3
Integers.......................................................................................................................29
4.1.4
Floating-Point Variables.............................................................................................31
4.1.5
Vectors........................................................................................................................32
4.1.6
Matrices......................................................................................................................32
iii
4.1.7
Opaque Types.............................................................................................................33
4.1.7.1
Samplers.............................................................................................................33
4.1.7.2
Images.................................................................................................................33
4.1.7.3
Atomic Counters.................................................................................................34
4.1.8
Structures....................................................................................................................34
4.1.9
Arrays.........................................................................................................................35
4.1.10
Implicit Conversions................................................................................................39
4.1.11
Initializers.................................................................................................................40
4.2
Scoping...............................................................................................................................42
4.3
Storage Qualifiers...............................................................................................................45
4.3.1
Default Storage Qualifier............................................................................................46
4.3.2
Constant Qualifier......................................................................................................46
4.3.3
Constant Expressions.................................................................................................47
4.3.4
Input Variables...........................................................................................................47
4.3.5
Uniform Variables......................................................................................................50
4.3.6
Output Variables.........................................................................................................51
4.3.7
Buffer Variables.........................................................................................................53
4.3.8
Shared Variables.........................................................................................................54
4.3.9
Interface Blocks..........................................................................................................54
4.4
Layout Qualifiers................................................................................................................59
4.4.1
Input Layout Qualifiers...............................................................................................61
4.4.1.1
Tessellation Evaluation Inputs............................................................................64
4.4.1.2
Geometry Shader Inputs......................................................................................66
4.4.1.3
Fragment Shader Inputs......................................................................................67
4.4.1.4
Compute Shader Inputs.......................................................................................68
4.4.2
Output Layout Qualifiers............................................................................................69
4.4.2.1
Transform Feedback Layout Qualifiers..............................................................71
4.4.2.2
Tessellation Control Outputs..............................................................................73
4.4.2.3
Geometry Outputs...............................................................................................74
4.4.2.4
Fragment Outputs...............................................................................................76
4.4.3
Uniform Variable Layout Qualifiers...........................................................................77
4.4.4
Subroutine Function Layout Qualifiers......................................................................78
4.4.5
Uniform and Shader Storage Block Layout Qualifiers...............................................78
4.4.6
Opaque-Uniform Layout Qualifiers............................................................................81
4.4.6.1
Atomic Counter Layout Qualifiers.....................................................................82
4.4.6.2
Format Layout Qualifiers....................................................................................83
4.5
Interpolation Qualifiers......................................................................................................85
4.5.1
Redeclaring Built-in Interpolation Variables in the Compatibility Profile.................86
4.6
Parameter Qualifiers...........................................................................................................87
iv
4.7
Precision and Precision Qualifiers.....................................................................................87
4.7.1
Range and Precision...................................................................................................87
4.7.2
Precision Qualifiers....................................................................................................88
4.7.3
Default Precision Qualifiers.......................................................................................89
4.7.4
Available Precision Qualifiers....................................................................................90
4.8
Variance and the Invariant Qualifier..................................................................................90
4.8.1
The Invariant Qualifier...............................................................................................90
4.8.2
Invariance of Constant Expressions...........................................................................91
4.9
The Precise Qualifier..........................................................................................................91
4.10
Memory Qualifiers...........................................................................................................94
4.11
Order and Repetition of Qualification..............................................................................97
5
Operators and Expressions........................................................................................................98
5.1
Operators............................................................................................................................98
5.2
Array Operations...............................................................................................................99
5.3
Function Calls....................................................................................................................99
5.4
Constructors.......................................................................................................................99
5.4.1
Conversion and Scalar Constructors..........................................................................99
5.4.2
Vector and Matrix Constructors...............................................................................100
5.4.3
Structure Constructors..............................................................................................102
5.4.4
Array Constructors...................................................................................................103
5.5
Vector and Scalar Components and Length.....................................................................103
5.6
Matrix Components..........................................................................................................105
5.7
Structure and Array Operations........................................................................................105
5.8
Assignments.....................................................................................................................106
5.9
Expressions......................................................................................................................107
5.10
Vector and Matrix Operations........................................................................................110
5.11
Out-of-Bounds Accesses................................................................................................111
6
Statements and Structure.........................................................................................................112
6.1
Function Definitions.........................................................................................................113
6.1.1
Function Calling Conventions..................................................................................116
6.1.2
Subroutines...............................................................................................................117
6.2
Selection...........................................................................................................................118
6.3
Iteration............................................................................................................................119
6.4
Jumps................................................................................................................................120
7
Built-in Variables....................................................................................................................122
7.1
Built-In Language Variables............................................................................................122
7.1.1
Compatibility Profile Built-In Language Variables..................................................131
7.2
Compatibility Profile Vertex Shader Built-In Inputs.......................................................134
7.3
Built-In Constants............................................................................................................135
v
Zgłoś jeśli naruszono regulamin