GLSL ES Specification 3.00.3

155
The OpenGL ES ®  Shading Language  Language Version: 3.00  Document Revision: 3 11 July 2012 Editor: Robert J. Simpson, Qualcomm OpenGL GLSL editor: John Kessenich, LunarG GLSL version 1.1 uthors: John Kessenich, !ave "ald#in, Randi Rost

Transcript of GLSL ES Specification 3.00.3

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 1/155

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 2/155

Copyright (c) 2008-2011 The Khronos Group Inc. All Rights Reserve.

This speci!ic"tion is protecte #y copyright l"$s "n cont"ins %"teri"l propriet"ry to the Khronos Group&Inc. It or "ny co%ponents %"y not #e reprouce& repu#lishe& istri#ute& tr"ns%itte& ispl"ye&#ro"c"st or other$ise e'ploite in "ny %"nner $ithout the e'press prior $ritten per%ission o! KhronosGroup. ou %"y use this speci!ic"tion !or i%ple%enting the !unction"lity therein& $ithout "ltering orre%oving "ny tr"e%"r& copyright or other notice !ro% the speci!ic"tion& #ut the receipt or possession o!this speci!ic"tion oes not convey "ny rights to reprouce& isclose& or istri#ute its contents& or to%"nu!"cture& use& or sell "nything th"t it %"y escri#e& in $hole or in p"rt.

Khronos Group gr"nts e'press per%ission to "ny current *ro%oter& Contri#utor or Aopter %e%#er o!Khronos to copy "n reistri#ute +,/II/ versions o! this speci!ic"tion in "ny !"shion& provie th"t, CARG is %"e !or the speci!ic"tion "n the l"test "v"il"#le up"te o! the speci!ic"tion !or "nyversion o! the A*I is use $henever possi#le. 3uch istri#ute speci!ic"tion %"y #e re-!or%"tte A34,G A3 the contents o! the speci!ic"tion "re not ch"nge in "ny $"y. The speci!ic"tion %"y #eincorpor"te into " prouct th"t is sol "s long "s such prouct inclues signi!ic"nt inepenent $orevelope #y the seller. A lin to the current version o! this speci!ic"tion on the Khronos Group $e#-siteshoul #e inclue $henever possi#le $ith speci!ic"tion istri#utions.

Khronos Group %"es no& "n e'pressly iscl"i%s "ny& represent"tions or $"rr"nties& e'press ori%plie& reg"ring this speci!ic"tion& incluing& $ithout li%it"tion& "ny i%plie $"rr"nties o! %erch"nt"#ilityor !itness !or " p"rticul"r purpose or non-in!ringe%ent o! "ny intellectu"l property. Khronos Group %"es

no& "n e'pressly iscl"i%s "ny& $"rr"nties& e'press or i%plie& reg"ring the correctness& "ccur"cy&co%pleteness& ti%eliness& "n reli"#ility o! the speci!ic"tion. +ner no circu%st"nces $ill the KhronosGroup& or "ny o! its *ro%oters& Contri#utors or e%#ers or their respective p"rtners& o!!icers& irectors&e%ployees& "gents or represent"tives #e li"#le !or "ny "%"ges& $hether irect& inirect& speci"l orconse5uenti"l "%"ges !or lost revenues& lost pro!its& or other$ise& "rising !ro% or in connection $iththese %"teri"ls.

Khronos& penK/& penKG3& pen6G& penA7& pen34 3 "n pen "re tr"e%"rs o!the Khronos Group Inc. C44A/A is " tr"e%"r o! 3ony Co%puter ntert"in%ent Inc. use #yper%ission #y Khronos. penG4 "n pen4 "re registere tr"e%"rs "n the penG4 3 logo is "tr"e%"r o! 3ilicon Gr"phics Inc. use #y per%ission #y Khronos. All other prouct n"%es& tr"e%"rs&"n9or co%p"ny n"%es "re use solely !or ienti!ic"tion "n #elong to their respective o$ners.

2

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 3/155

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 4/155

+.*.( Redeclarin& ames.....................................................................................................(1+.*.+ Global Scope..............................................................................................................((+.*./ Shared Globals............................................................................................................((

+.( Stora&e Quali'iers...............................................................................................................((+.(.1 !e'ault Stora&e Quali'ier ............................................................................................(++.(.* %onstant Quali'ier ......................................................................................................(++.(.( %onstant E2pressions.................................................................................................(/+.(.+ $nput ariables...........................................................................................................(/+.(./ 9ni'orm ariables......................................................................................................(7+.(.7 Output ariables.........................................................................................................(0+.(.0 $nter'ace "loc8s..........................................................................................................(5+.(.5 Laout Quali'iers........................................................................................................+)

+.(.5.1 $nput Laout Quali'iers.......................................................................................+1+.(.5.* Output Laout Quali'iers....................................................................................+1

+.(.5.( 9ni'orm "loc8 Laout Quali'iers.......................................................................+*+.(.6 $nterpolation................................................................................................................+++.(.1) Lin8in& o' erte2 Outputs and 4ra&ment $nputs......................................................+/

+.+ 3arameter Quali'iers...........................................................................................................+7+./ 3recision and 3recision Quali'iers.....................................................................................+7

+./.1 Ran&e and 3recision...................................................................................................+7+./.* %onversion bet#een precisions..................................................................................+5+./.( 3recision Quali'iers....................................................................................................+6+./.+ !e'ault 3recision Quali'iers......................................................................................./)

+.7 ariance and the $nvariant Quali'ier ................................................................................../1+.7.1 -he $nvariant Quali'ier .............................................................................................../*

+.7.* $nvariance =ithin a Shader ......................................................................................../(+.7.( $nvariance o' %onstant E2pressions.........................................................................../++.7.+ $nvariance o' 9nde'ined alues................................................................................./+

+.0 Order o' Quali'ication......................................................................................................../+/ Operators and E2pressions........................................................................................................//

/.1 Operators............................................................................................................................///.* rra Operations.............................................................................................................../7/.( 4unction %alls..................................................................................................................../7/.+ %onstructors......................................................................................................................./7

/.+.1 %onversion and Scalar %onstructors........................................................................../7/.+.* ector and <atri2 %onstructors................................................................................./0

/.+.( Structure %onstructors................................................................................................/6/.+.+ rra %onstructors.....................................................................................................7)

/./ ector %omponents............................................................................................................7)/.7 <atri2 %omponents............................................................................................................7*/.0 Structure and rra Operations..........................................................................................7*/.5 ssi&nments.......................................................................................................................7(

4

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 5/155

/.6 E2pressions........................................................................................................................7+/.1) ector and <atri2 Operations..........................................................................................77/.11 Evaluation o' e2pressions................................................................................................75

7 Statements and Structure...........................................................................................................767.1 4unction !e'initions...........................................................................................................0)

7.1.1 4unction %allin& %onventions....................................................................................0*7.* Selection.............................................................................................................................0(7.( $teration..............................................................................................................................0+7.+ Jumps..................................................................................................................................0/

0 "uilt;in ariables......................................................................................................................000.1 erte2 Shader Special ariables.......................................................................................000.* 4ra&ment Shader Special ariables...................................................................................050.( "uilt;$n %onstants..............................................................................................................050.+ "uilt;$n 9ni'orm State.......................................................................................................06

5 "uilt;in 4unctions.....................................................................................................................5)5.1 n&le and -ri&onometr 4unctions....................................................................................5*5.* E2ponential 4unctions........................................................................................................5(5.( %ommon 4unctions............................................................................................................5+5.+ 4loatin&;3oint 3ac8 and 9npac8 4unctions.......................................................................555./ Geometric 4unctions..........................................................................................................565.7 <atri2 4unctions................................................................................................................615.0 ector Relational 4unctions...............................................................................................6*5.5 -e2ture Loo8up 4unctions.................................................................................................6(5.6 4ra&ment 3rocessin& 4unctions..........................................................................................66

6 Shadin& Lan&ua&e Grammar ...................................................................................................1)*

1) Errors.....................................................................................................................................11/1).1 3reprocessor Errors........................................................................................................11/1).* Le2er>3arser Errors.........................................................................................................11/1).( Semantic Errors..............................................................................................................11/1).+ Lin8er .............................................................................................................................110

11 %ountin& o' $nputs and Outputs............................................................................................1161* $ssues.....................................................................................................................................1*(

1*.1 %ompatibilit #ith OpenGL ES *.)...............................................................................1*(1*.* %onver&ence #ith OpenGL............................................................................................1*(1*.(  umeric 3recision..........................................................................................................1*(1*.+ 4loatin& 3oint Representation and 4unctionalit...........................................................1*+

1*./ 3recision Quali'iers........................................................................................................1*/1*.7 4unction and ariable ame Spaces..............................................................................1*51*.0 Local 4unction !eclarations and 4unction idin&........................................................1*61*.5 Overloadin& main?@........................................................................................................1*61*.6 Error Reportin&..............................................................................................................1*61*.1) Structure !eclarations..................................................................................................1*6

5

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 6/155

1*.11 Embedded Structure !e'initions..................................................................................1()1*.1* Rede'inin& "uilt;in 4unctions......................................................................................1()1*.1( Global Scope................................................................................................................1(1

1*.1+ %onstant E2pressions...................................................................................................1(11*.1/ arin& Lin8a&e...........................................................................................................1(11*.17 &lA3osition....................................................................................................................1(*1*.10 3re;processor ................................................................................................................1(*1*.15 %haracter set.................................................................................................................1((1*.16 Line %ontinuation.........................................................................................................1(+1*.*) 3hases o' %ompilation..................................................................................................1(+1*.*1 <a2imum umber o' arin&s...................................................................................1(+1*.** rra !eclarations.......................................................................................................1(71*.*( $nvariance.....................................................................................................................1(71*.*+ $nvariance =ithin a shader ...........................................................................................1(5

1*.*/ =hile;loop !eclarations..............................................................................................1(61*.*7 %ross Lin8in& "et#een Shaders...................................................................................1(61*.*0 isibilit o' !eclarations.............................................................................................1(61*.*5 Lan&ua&e ersion.........................................................................................................1+)1*.*6 Samplers.......................................................................................................................1+)1*.() !namic $nde2in&........................................................................................................1+)1*.(1 <a2imum umber o' -e2ture 9nits............................................................................1+11*.(* On;tar&et Error Reportin&............................................................................................1+11*.(( Roundin& o' $nte&er !ivision.......................................................................................1+11*.(+ 9nde'ined Return alues.............................................................................................1+11*.(/ 3recisions o' Operations...............................................................................................1+*

1*.(7 %ompiler -rans'orms...................................................................................................1+(1*.(0 E2pansion o' 4unction;li8e <acros in the 3reprocessor .............................................1+(1*.(5 Should E2tension <acros be Globall !e'inedB.........................................................1+(1*.(6 <inimum ReCuirements...............................................................................................1++1*.+) 3ac8in& 4unctions........................................................................................................1++1*.+1 "oolean lo&ical vector operations ...............................................................................1++1*.+* Ran&e %hec8in& o' literals...........................................................................................1++1*.+( SeCuence operator and constant e2pressions...............................................................1+/1*.++ ersion !irective.........................................................................................................1+/1*.+/ 9se o' 9nsi&ned $nte&ers.............................................................................................1+7

1( c8no#led&ments.................................................................................................................1+0

1+  ormative Re'erences...........................................................................................................1+6

6

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 7/155

1 Introduction

-his document speci'ies onl version (.) o' the OpenGL ES Shadin& Lan&ua&e. $t reCuires

 AAERS$OAA to substitute ()), and reCuires #version to accept onl ()) es. $' #version is declared

#ith a smaller number, the lan&ua&e accepted is a previous version o' the shadin& lan&ua&e, #hich #ill be

supported dependin& on the version and tpe o' conte2t in the OpenGL ES 3$. See the OpenGL ES

Graphics Sstem Speci'ication, ersion (.), 'or details on #hat lan&ua&e versions are supported.

ll OpenGL ES Graphics Sstem Speci'ication re'erences in this speci'ication are to version (.)

1.1 Changes

-his speci'ication is derived 'rom OpenGL GLSL (.( revision 0.

1.1.1 Changes from GLSL ES 3.0 reision !

• %lari'ied that the paramter 'or s#itch statements can be a si&ned or unsi&ned inte&er 

• %lari'ied that all inte&er verte2 shader outputs and 'ra&ment shader inputs must be Cuali'ied D'latD

• $nvalid laout Cuali'iers must &enerate an error 

• Laout Cuali'ier $!s are case sensitive

• 3recision o' pac8in& and unpac8in& 'unctions

• 3recision o' return tpe o' te2tureSie?@

• 3recision reCuirements 'or built;in 'unctions

• %onversion bet#een precisions

• Removed de'ault precision 'or sampler tpes introduced in GLSL ES (.)

• &lA!epthRan&e members should be hi&hp

• %lari'ied that the laout Cuali'ier $! values can be si&ned or unsi&ned.

• %lari'ied that use o' reserved 'eatures is an error 

• %lari'ied description o' samplin& o' proFected te2tures

• erte2 shader outputs #ith inte&er tpe must be Cuali'ied as 'lat

• %lari'ied that di&raphs and tri&raphs are disallo#ed

• -he ma2imum len&th o' an identi'ier is 1)*+ characters

• -he ma2imum len&th o' a macro name is 1)*+ characters

• dded e2plicit statement that the precision o' a variable cannot be chan&ed

1

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 8/155

1 Introduction

• Re&ions o' scope in loop statements, includin& corrections to &rammar 

• Ran&e o' lo#p inte&ers

• %orrection to the countin& al&orithm e2ample 'or varin&s

• -he precision statement can be used to set the de'ault precision 'or sampler tpes

• -he de'ault precision 'or unsi&ned inte&ers cannot be set independentl 'rom si&ned inte&ers

• dded de'ault precision 'or built;in variables

• %lari'ied that a macro #ith an empt replacement list does not de'ault to D)D in a pre;processor

e2pression

• $nputs cannot be declared invariant

• Errors ma be reported at compile time or lin8 time

• %lari'ied that laout Cuali'ier parameters ma be either si&ned or unsi&ned inte&er constants

1.1.! Changes from GLSL ES 3.0 reision 1"

• %lari'ied that mediump and lo#p inte&ers #rap on over'lo#

• Ran&e chec8in& o' literal inte&ers

• Rede'inition o' built;in macros not allo#ed

• ersion directive must be the 'irst line o' a shader 

1.1.3 Changes from OpenGL GLSL 3.3"

Removed:

• 3ro'iles and deprecation

• Geometr shaders

• <ultiple compilation units

• Shared &lobals ?e2cept 'or uni'orms@

• in and out bloc8s

• verte2 arra inputs ?attribute arras@

• Laout Cuali'iers: inde2, ori&inAupperAle't and pi2elAcenterAinte&er 

• %33 to8en pastin&

• 9nsied arras.

• $mplicit tpe conversion.

• Overloadin& built;in 'unctions

• noperspective

• <ulti;sample te2tures

2

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 9/155

1 Introduction

• Rectan&ular te2tures

• -e2ture bu''ers

• 1! te2tures

•  oise

• Outer scope 'or built;in 'unctions.

• Redeclarin& built;in variables.

dded:

• Line continuation and 9-4;5 in GLSL ES 1.)) #hen used #ith OpenGL ES (.)

• rra len&th operator returns an unsi&ned inte&er;constant. -he precision is determined usin&

the rules 'or literal inte&ers

• %lari'ied that source code lines ma be o' arbitrar len&th

• Line continuation

• E2tended character set 'or comments

• "uilt;in constants: &lA<in3ro&ram-e2elO''set, &lA<a23ro&ram-e2elO''set

• andlin& and reportin& o' errors

• GLES macro

• 9se o' an unde'ined macro is an error 

•  umeric precision o' variables and operations

• !e'ault precisions

• !e'initions and behavior 'or precision Cuali'iers lo#p, mediump and hi&hp• $nvariance #ithin a shader 

• Rela2ation o' the order o' evaluation o' e2pressions

• 3ac8 and unpac8 built;in 'unctions

• List o' errors

•  ormative re'erences

• E2tension macro names al#as de'ined i' the e2tension is available

• %lari'ied that 'or the operators and HH, i' both operands are vectors, the must have the same

sie

• GLSL ES 1.)) compatibilit

• erte2 output, 'ra&ment input countin& al&orithm

3

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 10/155

1 Introduction

1.! Oerie#

-his document describes The OpenL !" "ha#ing Language$ version 3.00

$ndependent compilation units #ritten in this lan&ua&e are called  sha#ers.  program is a complete set o'shaders that are compiled and lin8ed to&ether. -he aim o' this document is to thorou&hl speci' the

 pro&rammin& lan&ua&e. -he OpenGL ES Graphics Sstem Speci'ication #ill speci' the OpenGL ES

entr points used to manipulate and communicate #ith pro&rams and shaders.

1.3 Error $andling

%ompilers, in &eneral, accept pro&rams that are ill;'ormed, due to the impossibilit o' detectin& all ill;

'ormed pro&rams. 3ortabilit is onl ensured 'or #ell;'ormed pro&rams, #hich this speci'ication

describes. %ompilers are encoura&ed to detect ill;'ormed pro&rams and issue dia&nostic messa&es, but are

not reCuired to do so 'or all cases. -he compilation process is implementation;dependent but is &enerall

split into a number o' sta&es, each o' #hich occurs at one o' the 'ollo#in& times:

• call to gl%ompile"ha#er 

• call to glLin&'rogram

• dra# call or a call to glVali#ate'rogram

-he implementation should report errors as earl a possible but in an case must satis' the 'ollo#in&:

• ll le2ical, &rammatical and semantic errors must have been detected 'ollo#in& a call to

 glLin&'rogram

• Errors due to mismatch bet#een the verte2 and 'ra&ment shader ?lin8 errors@ must have been

detected 'ollo#in& a call to &lLin83ro&ram

• Errors due to e2ceedin& resource limits must have been detected 'ollo#in& an dra# call or a call

to  glVali#ate'rogram

• call to glVali#ate'rogram must report all errors associated #ith a pro&ram obFect &iven the

current GL state.

=here the speci'ication uses the terms required , must >must  not , does>does not , disallowed  or not  

supported , the compiler or lin8er is reCuired to detect and report an violations. Similarl #hen a

condition or situation is an error, it must be reported. 9se o' an 'eature mar8ed as reserved  is an error.

=here the speci'ication uses the terms should >should  not  or undefined  behavior  there is no such

reCuirement but compilers are encoura&ed to report possible violations.

distinction is made bet#een undefined behavior  and an undefined value ?or result @. 9nde'ined

 behavior includes sstem instabilit and>or termination o' the application. $t is e2pected that sstems #ill

 be desi&ned to handle these cases &race'ull but speci'ication o' this is outside the scope o' OpenGL ES.

4

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 11/155

1 Introduction

$' a value or result is unde'ined, the sstem ma behave as i' the value or result had been assi&ned a

random value. 4or e2ample, an unde'ined &lA3osition ma cause a trian&le to be dra#n #ith a random

sie and position. -he value ma not be consistent. 4or e2ample an unde'ined boolean value ma cause

 both sub;statements in an i';then;else statement to be e2ecuted ?see section +.7.+ $nvariance o' 9nde'inedalues@. -he implementation ma also detect the &eneration and>or use o' unde'ined values and behave

accordin&l ?'or e2ample causin& a trap@. 9nde'ined values must not b themselves cause sstem

instabilit. o#ever unde'ined values ma lead to other more serious conditions such as in'inite loops or

out o' bounds arra accesses.

$mplementations ma not in &eneral support 'unctionalit beond the mandated parts o' the speci'ication

#ithout use o' the relevant e2tension. -he onl e2ceptions are:

1. $' a 'eature is mar8ed as optional.

*. =here a ma2imum values is stated ?e.&. the ma2imum number o' verte2 outputs@, the

implementation ma support a hi&her value than that speci'ied.

=here the implementation supports more than the mandated speci'ication, o'';tar&et compilers are

encoura&ed to issue #arnin&s i' these 'eatures are used.

-he compilation process is split bet#een the compiler and lin8er. -he allocation o' tas8s bet#een the

compiler and lin8er is implementation dependent. %onseCuentl there are man errors #hich ma be

detected either at compiler or lin8 time, dependin& on the implementation.

1.% T&pographical Conentions

$talic, bold, and 'ont choices have been used in this speci'ication primaril to improve readabilit. %ode

'ra&ments use a 'i2ed #idth 'ont. $denti'iers embedded in te2t are italicied. Ke#ords embedded in te2t

are bold. Operators are called b their name, 'ollo#ed b their smbol in bold in parentheses. -he

clari'in& &rammar 'ra&ments in the te2t use bold 'or literals and italics 'or non;terminals. -he o''icial

&rammar in section 6 IShadin& Lan&ua&e Grammar uses all capitals 'or terminals and lo#er case 'or

non;terminals.

1.' Compatibilit&

-he OpenGL ES (.) 3$ is desi&ned to #or8 #ith both GLSL ES v1.)) and GLSL ES (.)). $n &eneral a

shader #ritten 'or OpenGL ES *.) should #or8 #ithout modi'ication in OpenGL ES (.).

=hen portin& applications 'rom OpenGL ES *.) to OpenGL ES (.), the 'ollo#in& points should be noted:

•  ot all lan&ua&e constructs present in v1.)) o' the lan&ua&e are available in v(.)). E.&. attribute

and varin& Cuali'iers. o#ever, the 'unctionalit o' GLSL ES (.)) is a super;set o' GLSL ES

1.)).

• Some 'eatures o' the OpenGL ES (.) 3$ reCuire lan&ua&e 'eatures that are present in GLSL ES

(.)) but not present in GLSL ES 1.)).

• $t is an error to lin8 a verte2 shader and a 'ra&ment shader i' the are #ritten in di''erent versions

o' the lan&ua&e.

• -he OpenGL ES *.) 3$ does not support shaders #ritten in GLSL ES (.).

5

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 12/155

1 Introduction

• 9sin& GLSL ES 1.)) shaders #ithin OpenGL ES (.) ma e2tend the resources available beond

the minima speci'ied in GLSL ES 1.). Shaders #hich ma8e use o' this #ill not necessaril run

on an OpenGL ES *.) implementation:

Uniforms

-he number o' uni'orms speci'ied b &lA<a2erte29ni'ormectors and returned b the

correspondin& 3$ Cuer is the same 'or GLSL ES versions 1.)) and (.)) #hen used as part o'

OpenGL ES (.).

Varyings, vertex outputs and fragment inputs

-hese are speci'ied di''erentl in the t#o versions o' the lan&ua&e and ma be di''erent. 4or

GLSL ES 1.)), the ma2imum number o' varin&s is speci'ied b &lA<a2arin&ectors. 4or

GLSL ES (.)), the ma2imum number o' verte2 outputs and 'ra&ment inputs is independentl

speci'ied b &lA<a2erte2Outputectors and &lA<a24ra&ment$nputectors.

$n GLSL ES 1.)), onl varin&s #hich are staticall used in both the verte2 and 'ra&ment

shaders are counted. -his applies #hen GLSL ES 1.)) is used in OpenGL ES (.)

Multiple Render Targets

lthou&h &lA4ra&!ata is declared as an arra in GLSL ES 1.)), multiple render tar&ets are not

supported in OpenGL ES *.) and are there'ore not available #hen usin& GLSL ES 1.)) in

OpenGL ES (.).

• Support o' line continuation and support o' 9-4;5 characters #ithin comments is optional in

GLSL ES 1.)) #hen used #ith the OpenGL ES *.) 3$. o#ever, support is mandated 'or both

o' these #hen a GLSL ES 1.)) shader is used #ith the OpenGL ES (.) 3$.

6

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 13/155

! Oerie# of OpenGL ES Shading

-he OpenGL ES Shadin& Lan&ua&e is actuall t#o closel related lan&ua&es. -hese lan&ua&es are used

to create shaders 'or each o' the pro&rammable processors contained in the OpenGL ES processin&

 pipeline. %urrentl, these processors are the verte2 and 'ra&ment processors.

9nless other#ise noted in this paper, a lan&ua&e 'eature applies to all lan&ua&es, and common usa&e #ill

re'er to these lan&ua&es as a sin&le lan&ua&e. -he speci'ic lan&ua&es #ill be re'erred to b the name o'

the processor the tar&et: verte2 or 'ra&ment.

<ost OpenGL ES state is not trac8ed or made available to shaders. -picall, user;de'ined variables #ill

 be used 'or communicatin& bet#een di''erent sta&es o' the OpenGL ES pipeline. o#ever, a small

amount o' state is still trac8ed and automaticall made available to shaders, and there are a 'e# built;invariables 'or inter'aces bet#een di''erent sta&es o' the OpenGL ES pipeline.

!.1 (erte) *rocessor 

-he verte( processor  is a pro&rammable unit that operates on incomin& vertices and their associated data.

%ompilation units #ritten in the OpenGL ES Shadin& Lan&ua&e to run on this processor are called verte(

 sha#ers. =hen a complete set o' verte2 shaders are compiled and lin8ed, the result in a verte( sha#er

e(ecuta)le that runs on the verte2 processor.

-he verte2 processor operates on one verte2 at a time. $t does not replace &raphics operations that reCuire

8no#led&e o' several vertices at a time.

!.! +ragment *rocessor -he *ragment processor  is a pro&rammable unit that operates on 'ra&ment values and their associated

data. %ompilation units #ritten in the OpenGL ES Shadin& Lan&ua&e to run on this processor are called

 *ragment sha#ers. =hen a complete set o' 'ra&ment shaders are compiled and lin8ed, the result in a

 *ragment sha#er e(ecuta)le that runs on the 'ra&ment processor.

'ra&ment shader cannot chan&e a 'ra&mentDs ? (, y@ position. ccess to nei&hborin& 'ra&ments is not

allo#ed. -he values computed b the 'ra&ment shader are ultimatel used to update 'ramebu''er memor

or te2ture memor, dependin& on the current OpenGL ES state and the OpenGL ES command that caused

the 'ra&ments to be &enerated.

7

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 14/155

3 ,asics

3.1 Character Set

-he source character set used 'or the OpenGL ES shadin& lan&ua&es is a subset o' 9-4;5. $t comprises

the 'ollo#in& characters:

-he letters a-z, A-Z, and the underscore ? A  @

-he numbers !-".

-he smbols period ?@, plus ?@, dash ?-@, slash ?$@, asteris8 ?%@, percent ?&@, an&led brac8ets ?' and

(@, sCuare brac8ets ? ) and * @, parentheses ? + and  @, braces ?  and . @, caret ?/@, vertical bar ? 0 @,

ampersand ?1@, tilde ?2 @, eCuals ?3@, e2clamation point ?4@, colon ?5@, semicolon ?6@, comma ?,@, andCuestion mar8 ?7@.

-he number si&n ?#@ 'or preprocessor use.

"ac8slash ?DD@, used to indicate line continuation #hen immediatel precedin& a ne#;line.

=hite space: the space character, horiontal tab, vertical tab, 'orm 'eed, carria&e;return, and line;

'eed.

-here are no di&raphs or tri&raphs. -here are no escape seCuences or other uses o' the bac8slash beond

use as the line;continuation character.

Lines are relevant 'or compiler dia&nostic messa&es and the preprocessor. -he are terminated b

carria&e;return or line;'eed. $' both are used to&ether, it #ill count as onl a sin&le line termination. 4or

the remainder o' this document, an o' these combinations is simpl re'erred to as a ne#;line. Lines ma be o' arbitrar len&th.

$n &eneral, the lan&ua&es use o' this character set is case sensitive.

-here are no character or strin& data tpes, so no Cuotin& characters are included.

-here is no end;o';'ile character.

$nside comments, the character set is e2tended to allo# an bte values to be used but #ith the e2ception

that a bte #ith the value ero is al#as interpreted as the end o' the strin&. -he character encodin& is

assumed to be 9-4;5 but no chec8in& is per'ormed 'or invalid characters.

3.! Source Strings

-he source 'or a sin&le shader is an arra o' strin&s o' characters 'rom the character set. sin&le shader

is made 'rom the concatenation o' these strin&s. Each strin& can contain multiple lines, separated b ne#;

lines. o ne#;lines need be present in a strin&M a sin&le line can be 'ormed 'rom multiple strin&s. o

ne#;lines or other characters are inserted b the implementation #hen it concatenates the strin&s to 'orm a

sin&le shader.

8

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 15/155

3 Basics

!ia&nostic messa&es returned 'rom compilin& a shader must identi' both the line number #ithin a strin&

and #hich source strin& the messa&e applies to. Source strin&s are counted seCuentiall #ith the 'irst

strin& bein& strin& ). Line numbers are one more than the number o' ne#;lines that have been processed.

3.3 (ersion -eclaration

Shaders must declare the version o' the lan&ua&e the are #ritten to. -he version is speci'ied in the 'irst

line o' a shader b a character strin&:

#version number es

#here num)er  must be a version o' the lan&ua&e, 'ollo#in& the same convention as ++V!R",O-++  above.

-he directive I#version 8!! es is reCuired in an shader that uses version (.)) o' the lan&ua&e. n

num)er  representin& a version o' the lan&ua&e a compiler does not support #ill cause an error to be

&enerated. ersion 1.)) o' the lan&ua&e does not reCuire shaders to include this directive, and shaders

that do not include a #version directive #ill be treated as tar&etin& version 1.)).

Shaders declarin& version (.)) o' the shadin& lan&ua&e cannot be lin8ed #ith shaders declarin& version1.)).

-he #version directive must be present in the 'irst line o' a shader and must be 'ollo#ed b a ne#line. $t

ma contain optional #hite;space as speci'ied belo# but no other characters are allo#ed. -he directive is

onl permitted in the 'irst line o' a shader.

version#eclaration:

  /hitespaceopt 3O9! /hitespaceopt   ERS$O /hitespace  num)er /hitespaceopt   ES /hitespaceopt

-o8ens:

  3O9! N

  ERS$O version

  ES es

9

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 16/155

3 Basics

3.% *reprocessor  

-here is a preprocessor that processes the source strin&s as part o' the compilation process.

-he complete list o' preprocessor directives is as 'ollo#s.

#

#define

#undef

#if

#ifdef

#ifndef

#else

#elif

#endif

#error

#pragma

#extension

#line

-he 'ollo#in& operator is also available

defined

 ote that the version directive is not considered to be a preprocessor directive and so is not listed here.

Each number si&n ?#@ can be preceded in its line onl b spaces or horiontal tabs. $t ma also be

'ollo#ed b spaces and horiontal tabs, precedin& the directive. Each directive is terminated b a ne#;line. 3reprocessin& does not chan&e the number or relative location o' ne#;lines in a source strin&.

-he number si&n ?#@ on a line b itsel' is i&nored. n directive not listed above #ill cause a dia&nostic

messa&e and ma8e the implementation treat the shader as ill;'ormed.

#define and #undef  'unctionalit are de'ined as is standard 'or % preprocessors 'or macro de'initions

 both #ith and #ithout macro parameters.

-he 'ollo#in& prede'ined macros are available

__LINE__

__FILE__

__VERSION__

GL_ES

 ++L,-!++  #ill substitute a decimal inte&er constant that is one more than the number o' precedin& ne#;

lines in the current source strin&.

 ++,L!++  #ill substitute a decimal inte&er constant that sas #hich source strin& number is currentl

 bein& processed.

10

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 17/155

3 Basics

 ++V!R",O-++  #ill substitute a decimal inte&er re'lectin& the version number o' the OpenGL ES shadin&

lan&ua&e. -he version o' the shadin& lan&ua&e described in this document #ill have ++V!R",O-++  

substitute the decimal inte&er ()).

L+!" #ill be de'ined and set to 1. -his is not true 'or the non;ES OpenGL Shadin& Lan&ua&e, so it can

 be used to do a compile time test to determine i' a shader is runnin& on an ES sstem.

ll macro names containin& t#o consecutive underscores ? 99 @ are reserved 'or 'uture use as prede'ined

macro names. ll macro names pre'i2ed #ith IGLA ?IGL 'ollo#ed b a sin&le underscore@ are also

reserved.

$t is an error to unde'ine or to rede'ine a built;in ?pre;de'ined@ macro name.

-he ma2imum len&th o' a macro name is 1)*+ characters. $t is an error to declare a name #ith a len&th

&reater than this.

#if, #ifdef, #ifndef, #else, #elif, and #endif  are de'ined to operate as 'or % e2cept 'or the 'ollo#in&:

• E2pressions 'ollo#in& #if  and #elif  are restricted to e2pressions operatin& on literal inte&er

constants, plus identi'iers consumed b the defined operator.

• 9nde'ined identi'iers not consumed b the defined operator do not de'ault to D)D. 9se o' such

identi'iers causes an error.

• %haracter constants are not supported.

s in %, a macro name de'ined #ith an empt replacement list does not de'ault to D)D #hen used in a

 pre;processor e2pression.

-he operators available are as 'ollo#s:

*recedence Operator class Operators ssociatiit&

  1 ?hi&hest@ parenthetical &roupin& ? @

* unar de'ined ; P

Ri&ht to Le't

( multiplicative > Le't to Ri&ht

+ additive ; Le't to Ri&ht

/ bit;#ise shi't HH Le't to Ri&ht

7 relational H T HT Le't to Ri&ht

0 eCualit TT T Le't to Ri&ht

5 bit;#ise and U Le't to Ri&ht

6 bit;#ise e2clusive or V Le't to Ri&ht

1) bit;#ise inclusive or W Le't to Ri&ht11 lo&ical and UU Le't to Ri&ht

1* ?lo#est@ lo&ical inclusive or W W Le't to Ri&ht

11

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 18/155

3 Basics

-he defined operator can be used in either o' the 'ollo#in& #as:

defined identifier 

defined ( identifier )

 -here are no number si&n based operators ?e.&., no # or  #:@, no NN operator, nor is there a sizeof  

operator.

-he semantics o' applin& operators in the preprocessor match those standard in the % preprocessor

#ith the 'ollo#in& e2ceptions:

• -he *nd operand in a lo&ical and ?DUUD@ operation is evaluated i' and onl i' the 1st operand

evaluates to non;ero.

• -he *nd operand in a lo&ical or ?DWWD@ operation is evaluated i' and onl i' the 1st operand evaluates

to ero.

$' an operand is not evaluated, the presence o' unde'ined identi'iers in the operand #ill not cause an error.

3reprocessor e2pressions #ill be evaluated at compile time.

#error #ill cause the implementation to put a dia&nostic messa&e into the shader obFects in'ormation lo&

?see section 7.1.1* IShader and 3ro&ram Queries in the OpenGL ES Graphics Sstem Speci'ication 'or

ho# to access a shader obFects in'ormation lo&@. -he messa&e #ill be the to8ens 'ollo#in& the #error 

directive, up to the 'irst ne#;line. -he implementation must then consider the shader to be ill;'ormed.

#pragma allo#s implementation dependent compiler control. -o8ens 'ollo#in& #pragma are not subFect

to preprocessor macro e2pansion. $' an implementation does not reco&nie the to8ens 'ollo#in&

#pragma, then it #ill i&nore that pra&ma. -he 'ollo#in& pra&mas are de'ined as part o' the lan&ua&e.

#pragma S!GL

-he ;T<=> pra&ma is used to reserve pra&mas 'or use b this and 'uture revisions o' the lan&ua&e. o

implementation ma use a pra&ma #hose 'irst to8en is ;T<=>.

#pragma optimi"eon)

#pragma optimi"eoff)

can be used to turn o'' optimiations as an aid in developin& and debu&&in& shaders. $t can onl be used

outside 'unction de'initions. " de'ault, optimiation is turned on 'or all shaders. -he debu& pra&ma

#pragma de$ugon)

#pragma de$ugoff)

can be used to enable compilin& and annotatin& a shader #ith debu& in'ormation, so that it can be used

#ith a debu&&er. $t can onl be used outside 'unction de'initions. " de'ault, debu& is turned o''.

-he scope as #ell as the e''ect o' the optimie and debu& pra&mas is implementation;dependent e2cept

that their use must not &enerate an error.

12

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 19/155

3 Basics

" de'ault, compilers o' this lan&ua&e must issue compile time sntactic, &rammatical, and semantic

errors 'or shaders that do not con'orm to this speci'ication. n e2tended behavior must 'irst be enabled.

!irectives to control the behavior o' the compiler #ith respect to e2tensions are declared #ith the

#extension directive

#extension extension_name : behavior 

#extension all : behavior 

#here e(tension+name is the name o' an e2tension. E2tension names are not documented in this

speci'ication. -he to8en all means the behavior applies to all e2tensions supported b the compiler. -he

)ehavior can be one o' the 'ollo#in&:

behavior  Effect

re/uire "ehave as speci'ied b the e2tension e(tension+name.

Give an error on the #extension i' the e2tension e(tension+name is notsupported, or i' all is speci'ied.

enable "ehave as speci'ied b the e2tension e(tension+name.

=arn on the #extension i' the e2tension e(tension+name is not supported.

Give an error on the #extension i' all is speci'ied.

#arn "ehave as speci'ied b the e2tension e(tension+name, e2cept issue #arnin&son an detectable use o' that e2tension, unless such use is supported b otherenabled or reCuired e2tensions.

$' all is speci'ied, then #arn on all detectable uses o' an e2tension used.

=arn on the #extension i' the e2tension e(tension+name is not supported.

disable "ehave ?includin& issuin& errors and #arnin&s@ as i' the e2tensione(tension+name is not part o' the lan&ua&e de'inition.

$' all is speci'ied, then behavior must revert bac8 to that o' the non;e2tendedcore version o' the lan&ua&e bein& compiled to.

=arn on the #extension i' the e2tension e(tension+name is not supported.

-he extension directive is a simple, lo#;level mechanism to set the behavior 'or each e2tension. $t does

not de'ine policies such as #hich combinations are appropriate, those must be de'ined else#here. Order

o' directives matters in settin& the behavior 'or each e2tension: !irectives that occur later override those

seen earlier. -he all variant sets the behavior 'or all e2tensions, overridin& all previousl issued

extension directives, but onl 'or the )ehaviors ?arn and disa@le.

13

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 20/155

3 Basics

-he initial state o' the compiler is as i' the directive

#extension all % disa$le

#as issued, tellin& the compiler that all error and #arnin& reportin& must be done accordin& to thisspeci'ication, i&norin& an e2tensions.

Each e2tension can de'ine its allo#ed &ranularit o' scope. $' nothin& is said, the &ranularit is a shader

?that is, a sin&le compilation unit@, and the e2tension directives must occur be'ore an non;preprocessor

to8ens. $' necessar, the lin8er can en'orce &ranularities lar&er than a sin&le compilation unit, in #hich

case each involved shader #ill have to contain the necessar e2tension directive.

<acro e2pansion is not done on lines containin& #extension and #version directives.

4or each e2tension there is an associated macro. -he macro is al#as de'ined in an implementation that

supports the e2tension. -his allo#s the 'ollo#in& construct to be used:

#ifdef OES_extension_name

#extension OES_extension_name % ena$le

&& 'ode t(at reuires t(e extension

#else

&& alternative 'ode

#endif

#line must have, a'ter macro substitution, one o' the 'ollo#in& 'orms:

#line line

#line line source-string-number 

#here line and sourcestringnum)er are constant inte&ral e2pressions. 'ter processin& this directive

?includin& its ne#;line@, the implementation #ill behave as i' it is compilin& at line number line and

source strin& number sourcestringnum)er . SubseCuent source strin&s #ill be numbered seCuentiall,

until another #line directive overrides that numberin&.

$' durin& macro e2pansion a preprocessor directive is encountered, the results are unde'inedM the compiler

ma or ma not report an error in such cases.

3.' Comments

%omments are delimited b > and >, or b >> and a ne#;line. -he be&in comment delimiters ?> or >>@ are

not reco&nied as comment delimiters inside o' a comment, hence comments cannot be nested. $' a

comment resides entirel #ithin a sin&le line, it is treated sntacticall as a sin&le space. e#;lines are

not eliminated b comments.

14

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 21/155

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 22/155

3 Basics

  usamplerD< usampler8< usamplerFu@e

  usamplerD<Array

  strut

-he 'ollo#in& are the 8e#ords reserved 'or 'uture use. 9sin& them #ill result in an error:

  attri@ute varying

  oBerent volatile restrit readonly ?riteonly

  resoure atomi9uint

  noperspetive

  patB sample

  su@routine

  ommon partition ative

  asm

  lass union enum typedef template tBis paCed

goto

inline noinline volatile pu@li stati extern external interfae

  long sBort dou@le Balf fixed unsigned superp

  input output

  BveD Bve8 BveE dveD dve8 dveE fveD fve8 fveE

  sampler8<Ret

filter

imageG< imageD< image8< imageFu@e

iimageG< iimageD< iimage8< iimageFu@e

uimageG< uimageD< uimage8< uimageFu@e

imageG<Array imageD<Array

iimageG<Array iimageD<Array uimageG<Array uimageD<Array

  imageG<;Bado? imageD<;Bado?

  imageG<Array;Bado? imageD<Array;Bado?

  imageHuffer iimageHuffer uimageHuffer

  samplerG< samplerG<;Bado? samplerG<Array samplerG<Array;Bado?

  isamplerG< isamplerG<Array usamplerG< usamplerG<Array

  samplerD<Ret samplerD<Ret;Bado? isamplerD<Ret usamplerD<Ret

  samplerHuffer isamplerHuffer usamplerHuffer

16

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 23/155

3 Basics

  samplerD<M; isamplerD<M; usamplerD<M;

  samplerD<M;Array isamplerD<M;Array usamplerD<M;Array

  sizeof ast  namespae using

 

$n addition, all identi'iers containin& t#o consecutive underscores ? 99 @ are reserved as possible 'uture

8e#ords.

3.4 Identifiers

$denti'iers are used 'or variable names, 'unction names, structure names, and 'ield selectors ?'ield

selectors select components o' vectors and matrices similar to structure 'ields, as discussed in section /./

Iector %omponents and section /.7 I<atri2 %omponents @. $denti'iers have the 'orm

i#enti*ier non#igit

i#enti*ier non#igit

i#enti*ier #igit

non#igit: one o' 

 9 a @ d e f g B i I C l m n o p J r s t u v ? x y z 

A H F < K L = N O P > M Q S R ; T U V W Z  

#igit : one o'

! G D 8 E X Y [ "

$denti'iers startin& #ith I&lA are reserved 'or use b OpenGL ES, and ma not be declared in a shader aseither a variable or a 'unction. $t is an error to redeclare a variable, includin& those startin& I&lA.

-he ma2imum len&th o' an identi'ier is 1)*+ characters. $t is an error to declare a variable #ith a len&th

&reater than this.

3.5 -efinitions

Some lan&ua&e rules described belo# depend on the 'ollo#in& de'initions.

3.5.1 Static 6se

shader contains a static use o' ?or static assignment  to@ a variable ( i', a'ter preprocessin&, the shader

contains a statement that #ould read ?or #rite@ (, #hether or not run;time 'lo# o' control #ill cause that

statement to be e2ecuted.

17

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 24/155

3 Basics

3.5.! 6niform and 7on86niform Control +lo#

=hen e2ecutin& statements in a 'ra&ment shader, control 'lo# starts as uni*orm control *lo/M all 'ra&ments

enter the same control path into main?@.  %ontrol 'lo# becomes nonuni*orm #hen di''erent 'ra&ments

ta8e di''erent paths throu&h control;'lo# statements ?selection, iteration, and Fumps@. %ontrol 'lo#

subseCuentl returns to bein& uni'orm a'ter such diver&ent sub;statements or s8ipped code completes,

until the ne2t time di''erent control paths are ta8en.

4or e2ample:

main)

*

  float a + ,,,-&& t(is is uniform 'ontrol flo.

  if a / $) * && t(is expression is true for some fragments0 not all

  ,,,,- && non1uniform 'ontrol flo.

  2 else *

  ,,,,- && non1uniform 'ontrol flo.

  2

  ,,,,- && uniform 'ontrol flo. again

2

Other e2amples o' non;uni'orm control 'lo# can occur #ithin s#itch statements and a'ter conditional

 brea8s, continues, earl returns, and a'ter 'ra&ment discards, #hen the condition is true 'or some

'ra&ments but not others. Loop iterations that onl some 'ra&ments e2ecute are also non;uni'orm control

'lo#.

-his is similarl de'ined 'or other shader sta&es, based on the per;instance data items the process.

3.5.3 -&namicall& 6niform E)pressions

'ra&ment;shader e2pression is #ynamically uni*orm i' all 'ra&ments evaluatin& it &et the same resultin&

value. =hen loops are involved, this re'ers to the e2pressionDs value 'or the same loop iteration. =hen'unctions are involved, this re'ers to calls 'rom the same call point.

-his is similarl de'ined 'or other shader sta&es, based on the per;instance data the process.

 ote that constant e2pressions are triviall dnamicall uni'orm. $t 'ollo#s that tpical loop counters

 based on these are also dnamicall uni'orm.

-he de'inition is not used in this version o' GLSL ES but ma be re'erenced b e2tensions.

3.10 Logical *hases of Compilation

-he compilation process is based on a subset o' the % standard ?see section 1+: ormative Re'erences@.

-he compilation units 'or the verte2 and 'ra&ment processor are processed separatel be'ore bein& lin8ed

to&ether in the 'inal sta&e o' compilation. -he lo&ical phases o' compilation are:1. Source strin&s are concatenated.

*. -he source strin& is converted into a seCuence o' preprocessin& to8ens. -hese to8ens include

 preprocessin& numbers, identi'iers and preprocessin& operations. %omments are each replaced

 b one space character. Line brea8s are retained.

18

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 25/155

3 Basics

(. -he preprocessor is run. !irectives are e2ecuted and macro e2pansion is per'ormed.

+. 3reprocessin& to8ens are converted into to8ens.

/. =hite space and line brea8s are discarded.

7. -he snta2 is analed accordin& to the GLSL ES &rammar.

0. -he result is chec8ed accordin& to the semantic rules o' the lan&ua&e.

5. -he verte2 and 'ra&ment shaders are lin8ed to&ether. n verte2 outputs and correspondin&

'ra&ment inputs not used in both the verte2 and 'ra&ment shaders ma be discarded.

6. -he binar is &enerated.

19

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 26/155

% (ariables and T&pes

ll variables and 'unctions must be declared be'ore bein& used. ariable and 'unction names are

identi'iers.

-here are no de'ault tpes. ll variable and 'unction declarations must have a declared tpe, and

optionall Cuali'iers. variable is declared b speci'in& its tpe 'ollo#ed b one or more names

separated b commas. $n man cases, a variable can be initialied as part o' its declaration b usin& the

assi&nment operator ?3@. -he &rammar near the end o' this document provides a 'ull re'erence 'or the

snta2 o' declarin& variables.

9ser;de'ined tpes ma be de'ined usin& strut to a&&re&ate a list o' e2istin& tpes into a sin&le name.

-he OpenGL ES Shadin& Lan&ua&e is tpe sa'e. -here are no implicit conversions bet#een tpes.

%.1 ,asic T&pes

-he OpenGL ES Shadin& Lan&ua&e supports the 'ollo#in& basic data tpes, &rouped as 'ollo#s.

-ransparent tpes

T&pe 9eaning

void 'or 'unctions that do not return a value

@ool a conditional tpe, ta8in& on values o' true or 'alse

int a si&ned inte&er 

uint an unsi&ned inte&er 

float a sin&le 'loatin&;point scalar 

veD a t#o;component 'loatin&;point vector 

ve8 a three;component 'loatin&;point vector 

veE a 'our;component 'loatin&;point vector 

@veD a t#o;component "oolean vector 

@ve8 a three;component "oolean vector 

@veE a 'our;component "oolean vector 

iveD a t#o;component si&ned inte&er vector 

ive8 a three;component si&ned inte&er vector 

iveE a 'our;component si&ned inte&er vector 

uveD a t#o;component unsi&ned inte&er vector 

uve8 a three;component unsi&ned inte&er vector 

20

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 27/155

4 Variables and Types

T&pe 9eaning

uveE a 'our;component unsi&ned inte&er vector 

matD a *X* 'loatin&;point matri2mat8 a (X( 'loatin&;point matri2

matE a +X+ 'loatin&;point matri2

matDxD same as a matD

matDx8 a 'loatin&;point matri2 #ith * columns and ( ro#s

matDxE a 'loatin&;point matri2 #ith * columns and + ro#s

mat8xD a 'loatin&;point matri2 #ith ( columns and * ro#s

mat8x8 same as a mat8

mat8xE a 'loatin&;point matri2 #ith ( columns and + ro#s

matExD a 'loatin&;point matri2 #ith + columns and * ro#smatEx8 a 'loatin&;point matri2 #ith + columns and ( ro#s

matExE same as a matE

4loatin& 3oint Sampler -pes ?opaCue@

T&pe 9eaning

samplerD< a handle 'or accessin& a *! te2ture

sampler8< a handle 'or accessin& a (! te2ture

samplerFu@e a handle 'or accessin& a cube mapped te2ture

samplerFu@e;Bado? a handle 'or accessin& a cube map depth te2ture #ith comparison

samplerD<;Bado? a handle 'or accessin& a *! depth te2ture #ith comparison

samplerD<Array a handle 'or accessin& a *! arra te2ture

samplerD<Array;Bado? a handle 'or accessin& a *! arra depth te2ture #ith comparison

Si&ned $nte&er Sampler -pes ?opaCue@

T&pe 9eaning

isamplerD< a handle 'or accessin& an inte&er *! te2ture

isampler8< a handle 'or accessin& an inte&er (! te2ture

isamplerFu@e a handle 'or accessin& an inte&er cube mapped te2ture

isamplerD<Array a handle 'or accessin& an inte&er *! arra te2ture

21

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 28/155

4 Variables and Types

9nsi&ned $nte&er Sampler -pes ?opaCue@

T&pe 9eaning

usamplerD< a handle 'or accessin& an unsi&ned inte&er *! te2ture

usampler8< a handle 'or accessin& an unsi&ned inte&er (! te2ture

usamplerFu@e a handle 'or accessin& an unsi&ned inte&er cube mapped te2ture

usamplerD<Array a handle 'or accessin& an unsi&ned inte&er *! arra te2ture

$n addition, a shader can a&&re&ate these usin& arras and structures to build more comple2 tpes.

-here are no pointer tpes.

%.1.1 (oid

4unctions that do not return a value must be declared as void. -here is no de'ault 'unction return tpe.

-he 8e#ord void cannot be used in an other declarations ?e2cept 'or empt 'ormal or actual parameterlists@.

%.1.! ,ooleans

-o ma8e conditional e2ecution o' code easier to e2press, the tpe @ool is supported. -here is no

e2pectation that hard#are directl supports variables o' this tpe. $t is a &enuine "oolean tpe, holdin&

onl one o' t#o values meanin& either true or 'alse. -#o 8e#ords true and false can be used as literal

"oolean constants. "ooleans are declared and optionall initialied as in the 'ollo# e2ample:

$ool su''ess- && de'lare 3su''ess4 to $e a 5oolean

$ool done + false- && de'lare and initiali"e 3done4

-he ri&ht side o' the assi&nment operator ? 3 @ must be an e2pression #hose tpe is @ool.

E2pressions used 'or conditional Fumps ?if, for, 75, ?Bile, do-?Bile@ must evaluate to the tpe @ool.

%.1.3 Integers

Si&ned and unsi&ned inte&er variables are 'ull supported. $n this document, the term integer is meant to

&enerall include both si&ned and unsi&ned inte&ers. i&hp unsi&ned inte&ers have e2actl (* bits o'

 precision. i&hp si&ned inte&ers use (* bits, includin& a si&n bit, in t#oDs complement 'orm. <ediump

and lo#p inte&ers have implementation;de'ined numbers o' bits. Operations resultin& in over'lo# or

under'lo# #ill not cause an e2ception, nor #ill the saturate, rather the #ill I#rap to ield the lo#;

order n bits o' the result #here n is the sie in bits o' the inte&er. See section +./.1 IRan&e and 3recisionI

'or details.

$nte&ers are declared and optionall initialied #ith inte&er e2pressions, as in the 'ollo#in& e2ample:

int i0 6 + 78- && default integer literal t9pe is int

uint : + ;u- && 3u4 esta$lis(es t(e t9pe as uint

22

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 29/155

4 Variables and Types

Literal inte&er constants can be e2pressed in decimal ?base 1)@, octal ?base 5@, or he2adecimal ?base 17@

as 'ollo#s.

integerconstant:

#ecimalconstant integersu**i(opt 

octalconstant integersu**i(opt 

he(a#ecimalconstant integersu**i(opt 

integersu**i(: one o' 

u U

#ecimalconstant:

nonero#igit 

#ecimalconstant #igit 

octalconstant:

!

octalconstant octal#igit 

he(a#ecimalconstant:

)2 he(a#ecimal#igit 

)Y he(a#ecimal#igit 

he(a#ecimalconstant he(a#ecimal#igit 

#igit:

!

nonero#igit 

nonero#igit: one o' 

G D 8 E X Y [ "

octal#igit  5 one o' 

! G D 8 E X Y

he(a#ecimal#igit : one o' 

! G D 8 E X Y [ "

a @ d e f 

A H F < K L

 o #hite space is allo#ed bet#een the di&its o' an inte&er constant, includin& a'ter the leadin& ! or a'ter

the leadin& !x or ! o' a constant, or be'ore the su''i2 u or  U.  =hen the su''i2 u or U is present, the

literal has tpe uint, other#ise the tpe is int. leadin& unar minus si&n ?;@ is interpreted as an

arithmetic unar ne&ation, not as part o' the constant.

$t is an error to provide a literal inte&er #hose value #ould be too lar&e to store in a hi&hp uint variable. ote that this onl applies to literalsM no error chec8in& is per'ormed on the result o' a constant

e2pression.

23

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 30/155

4 Variables and Types

E2amples

< && signed integer0 value <

<u && unsigned integer0 value <

1< && unar9 minus applied to signed integer,

  && result is a signed integer0 value 1<

1<u && unar9 minus applies to unsigned integer

  && result is an unsigned integer0 value =xffffffff

=xffffffff && signed integer0 value 1<

=xffffffffu && unsigned integer0 value =xffffffff

=xffffffff= && error% values of signed integer is too large

%.1.% +loats

4loats are available 'or use in a variet o' scalar calculations. 4loatin&;point variables are de'ined as in

the 'ollo#in& e2ample :

float a0 $ + <,>-

s an input value to one o' the processin& units, a 'loatin&;point variable is e2pected to match the $EEE

0/+ sin&le precision 'loatin&;point de'inition 'or precision and dnamic ran&e. i&hp 'loatin&;point

variables #ithin a shader are encoded accordin& to the $EEE 0/+ speci'ication 'or sin&le;precision

'loatin&;point values ?lo&icall, not necessaril phsicall@. =hile encodin&s are lo&icall $EEE 0/+,

operations ?addition, multiplication, etc.@ are not necessaril per'ormed as reCuired b $EEE 0/+. See

section +./.1 IRan&e and 3recisionI 'or more details on precision and usa&e o' as ?ot a umber@ and

$n's ?positive or ne&ative in'inities@.

24

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 31/155

4 Variables and Types

4loatin&;point constants are de'ined as 'ollo#s.

 *loatingconstant:

 *ractionalconstant e(ponentpart opt

 *loatingsu**i(opt  

#igitseuence e(ponentpart *loatingsu**i(opt 

 *ractionalconstant:

#igitseuence . #igitseuence

#igitseuence .

 . #igitseuence

e(ponentpart:e sign

opt  #igitseuence

 E  signopt 

 #igitseuence

 sign: one o' 

\ #igitseuence:

#igit 

#igitseuence #igit 

 *loatingsu**i(: one o' 

f L

decimal point ?  @ is not needed i' the e2ponent part is present. o #hite space ma appear an#here

#ithin a 'loatin&;point constant, includin& be'ore a su''i2. leadin& unar minus si&n ?-@ is interpreted as

a unar operator and is not part o' the 'loatin&;point constant.

-here is no limit on the number o' di&its in an #igitseuence. $' the value o' the 'loatin& point number

is too lar&e ?small@ to be stored as a sin&le precision value, it is converted to positive ?ne&ative@ in'init.

value #ith a ma&nitude too small to be represented as a mantissa and e2ponent is converted to ero.

$mplementations ma also convert subnormal ?denormalied@ numbers to ero.

%.1.' (ectors

-he OpenGL ES Shadin& Lan&ua&e includes data tpes 'or &eneric *;, (;, and +;component vectors o'

'loatin&;point values, inte&ers, and "ooleans. 4loatin&;point vector variables can be used to store colors,

normals, positions, te2ture coordinates, te2ture loo8up results and the li8e. "oolean vectors can be used

'or component;#ise comparisons o' numeric vectors. Some e2amples o' vector declaration are:

ve'8 tex'oord<0 tex'oord8-

ve'; position-

ve'7 m9RG5?-

ive'8 textureLoo:up-$ve'; less-

$nitialiation o' vectors can be done #ith constructors, #hich are discussed shortl.

25

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 32/155

4 Variables and Types

%.1. 9atrices

-he OpenGL ES Shadin& Lan&ua&e has built;in tpes 'or *X*, *X(, *X+, (X*, (X(, (X+, +X*, +X(, and

+X+ matrices o' 'loatin&;point numbers. -he 'irst number in the tpe is the number o' columns, the

second is the number o' ro#s. E2ample matri2 declarations:

mat8 mat8!-

mat; opt@atrix-

mat7 vie.0 pro6e'tion-

mat7x7 vie.- && an alternate .a9 of de'laring a mat7

mat;x8 m- && a matrix .it( ; 'olumns and 8 ro.s

$nitialiation o' matri2 values is done #ith constructors ?described in section /.+ I%onstructors @ in

column;maFor order.

matD is an alias 'or matDxD, not a distinct tpe. Similarl 'or mat8 and matE -he 'ollo#in& is le&al:

mat8 a-

mat8x8 $ + a-

%.1.2 Samplers

Sampler tpes ?e.&., samplerD<@ are e''ectivel opaCue handles to te2tures and their 'ilters. -he are

used #ith the built;in te2ture 'unctions ?described in section 5.0 I-e2ture Loo8up 4unctions @ to speci'

#hich te2ture to access and ho# it is to be 'iltered. -he can onl be declared as 'unction parameters or

uniform variables ?see section +.(./ I9ni'orm @. E2cept 'or arra inde2in&, structure 'ield selection, and

 parentheses, samplers are not allo#ed to be operands in e2pressions. Samplers a&&re&ated into arras

#ithin a shader ?usin& sCuare brac8ets ) *@ can onl be inde2ed #ith constant inte&ral e2pressions ?see

section +.(.( I%onstant E2pressions@. Samplers cannot be treated as l;valuesM hence cannot be used as

out or inout 'unction parameters, nor can the be assi&ned into. s uni'orms, the are initialied onl

#ith the OpenGL ES 3$M the cannot be declared #ith an initialier in a shader. s 'unction parameters,

onl samplers ma be passed to samplers o' matchin& tpe. -his enables consistenc chec8in& bet#eenshader te2ture accesses and OpenGL ES te2ture state be'ore a shader is run.

%.1.4 Structures

9ser;de'ined tpes can be created b a&&re&atin& other alread de'ined tpes into a structure usin& the

strut 8e#ord. 4or e2ample,

stru't lig(t *

  float intensit9-

  ve'; position-

2 lig(tVar-

$n this e2ample, light  becomes the name o' the ne# tpe, and lightVar  becomes a variable o' tpe light .

-o declare variables o' the ne# tpe, use its name ?#ithout the 8e#ord strut@.

lig(t lig(tVar8-

<ore 'ormall, structures are declared as 'ollo#s. o#ever, the complete correct &rammar is as &iven in

section 6 IShadin& Lan&ua&e Grammar .

26

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 33/155

4 Variables and Types

 struct#e*inition:

uali*ier opt 

  strut nameopt 

  mem)erlist . #eclaratorsopt 

 

mem)erlist:mem)er#eclaration

mem)er#eclaration mem)erlist

mem)er#eclaration:

)asictype #eclarators

#here name becomes the user;de'ined tpe, and can be used to declare variables to be o' this ne# tpe.

-he name shares the same name space as other variables, tpes, and 'unctions. ll previousl visible

variables, tpes, constructors, or 'unctions #ith that name are hidden. -he optional uali*ier  onl applies

to an #eclarators, and is not part o' the tpe bein& de'ined 'or name.

Structures must have at least one member declaration. <ember declarators ma contain precision

Cuali'iers, but ma not contain an other Cuali'iers. "it 'ields are not supported. <ember tpes must be

alread de'ined ?there are no 'or#ard re'erences@. <ember declarations cannot contain initialiers.<ember declarators can contain arras. Such arras must have a sie speci'ied, and the sie must be a

constant inte&ral e2pression thatDs &reater than ero ?see section +.(.( I%onstant E2pressions@. Each

level o' structure has its o#n name space 'or names &iven in member declaratorsM such names need onl

 be uniCue #ithin that name space.

nonmous structures are not supported. Embedded structure de'initions are not supported.

stru't S * float f- 2- && ?llo.ed% S is defined as a stru'ture,

stru't *

S- && Error% anon9mous stru'tures disallo.ed

stru't * ,,, 2- && Error% em$edded stru'tures disallo.ed

S s- && ?llo.ed% nested stru'ture .it( a name,

2-

Structures can be initialied at declaration time usin& constructors, as discussed in section /.+.( IStructure

%onstructors .

n restrictions on the usa&e o' a tpe or Cuali'ier also appl to a structure that contains that tpe or

Cuali'ier. -his applies recursivel.

27

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 34/155

4 Variables and Types

%.1.5 rra&s

ariables o' the same tpe can be a&&re&ated into arras b declarin& a name 'ollo#ed b brac8ets ? ) * @

enclosin& a sie. -he arra sie must be a constant inte&ral e2pression ?see section +.(.( I%onstant

E2pressions @ &reater than ero. -he tpe o' the sie parameter can be a si&ned or unsi&ned inte&er and

the choice o' tpe does not a''ect the tpe o' the resultin& arra. $t is ille&al to inde2 an arra #ith a

constant inte&ral e2pression &reater than or eCual to the declared sie. $t is also ille&al to inde2 an arra

#ith a ne&ative constant e2pression. rras declared as 'ormal parameters in a 'unction declaration must

also speci' a sie. 9nde'ined behavior results 'rom inde2in& an arra #ith a non;constant e2pression

thats &reater than or eCual to the arras sie or less than ). Onl one;dimensional arras ma be

declared. ll basic tpes and structures can be 'ormed into arras. Some e2amples are:

float freuen'iesA;B-

uniform ve'7 lig(tCositionA7uB-

'onst int numLig(ts + 8-

lig(t lig(tsAnumLig(tsB-

n arra tpe can be 'ormed b speci'in& a tpe 'ollo#ed b sCuare brac8ets ?Z [@ and includin& a sie:

floatA>B

-his tpe can be used an#here an other tpe can be used, includin& as the return value 'rom a 'unction

floatA>B foo) * 2

as a constructor o' an arra

floatA>B;,70 7,80 >,=0 >,80 <,<)

as an unnamed parameter 

void foofloatA>B)

and as an alternate #a o' declarin& a variable or 'unction parameter.

floatA>B a-

n arra tpe can also be 'ormed #ithout speci'in& a sie i' the de'inition includes an initialier:

float xAB + floatA8B <,=0 8,=)- && de'lares an arra9 of si"e 8float 9AB + floatAB <,=0 8,=0 ;,=)- && de'lares an arra9 of si"e ;

float aA>B-float $AB + a-

 ote that the initialier itsel' does not need to be a constant e2pression but the len&th o' the initialier #ill

 be a constant e2pression.

28

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 35/155

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 36/155

4 Variables and Types

int '? > nested scope be&ins here > int 8@

*

  int : + : D ;- && rede'laration error of t(e name :

  ,,,2

int fint :)

*

  *

  int : + : D ;- && 8nd : is parameter0 initiali"ing nested first :

  int m + : && use of ne. :0 .(i'( is (iding t(e parameter

  2

2

4or both 'or and #hile loops, the sub;statement itsel' does not introduce a ne# scope 'or variable names,

so the 'ollo#in& has a redeclaration compile;time error:

for & nested s'ope $egins (ere & int i + =- i / <=- iDD)

*

  int i- && rede'laration error

2

-he bod o' a do;#hile loop introduces a ne# scope lastin& onl bet#een the do and #hile ?not includin&

the #hile test e2pression@, #hether or not the bod is simple or compound:

int i + <-

do

  int i + 7- && o:a90 in nested s'ope

.(ile i ++ =)- && i is <0 s'oped outside t(e do1.(ile $od9

Representin& the i' construct as:

if  i';e2pression tBen i';statement else else;statement,

a variable declared in the i';statement is scoped to the end o' the i';statement. variable declared in the

else;statement is scoped to the end o' the else;statement. -his applies both #hen these statements are

simple statements and #hen the are compound statements. -he i';e2pression does not allo# ne#

variables to be declared, hence does not 'orm a ne# scope.

30

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 37/155

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 38/155

4 Variables and Types

#eclaration is considered to be a statement that adds a name or si&nature to the smbol table.

#e*inition is a statement that 'ull de'ines that name or si&nature. E.&.

int f)- && de'laration-

int f) *return =-2 && de'laration and definition

int x- && de'laration and definition

int aA7B- && arra9 de'laration and definition

stru't S *int x-2- && stru'ture de'laration and definition

-he determination o' eCuivalence o' t#o declarations depends on the tpe o' declaration. 4or 'unctions,

the #hole 'unction si&nature must be considered ?see section 7.1 4unction !e'initions@. 4or variables

?includin& arras@ and structures onl the names must match.

=ithin each scope, a name ma be declared either as a variable declaration or  as 'unction declarations or  

as a structure.

E2amples o' combinations that are allo#ed:

1.

void fint) *,,,2

void ffloat) *,,,2 && fun'tion overloading allo.ed

*.

void fint)- && <st de'laration allo.ed)

void fint)- && repeated de'laration allo.ed)

void fint) *,,,2 && single definition allo.ed)

E2amples o' combinations that are disallo#ed:

1.

void fint) *,,,2

void fint) *,,,2 && Error% repeated definition*.

void fint)-

stru't f *int x-2- && Error% t9pe f 'onfli'ts .it( fun'tion f

(.

stru't f *int x-2-

int f- && Error% 'onfli'ts .it( t(e t9pe f

+.

int aA;B-

int aA;B- && Error% repeated arra9 definition

/.

int x-int x- && Error% repeated varia$le definition

32

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 39/155

4 Variables and Types

%.!.% Global Scope

-he built;in 'unctions are scoped in the &lobal scope users declare &lobal variables in. -hat is, a shaderDs

&lobal scope, available 'or user;de'ined 'unctions and &lobal variables, is the same as the scope containin&

the built;in 'unctions. 4unction declarations ?prototpes@ cannot occur inside o' 'unctionsM the must be at

&lobal scope.,ence it is not possible to hide a name #ith a 'unction.

%.!.' Shared Globals

Shared &lobals are variables that can be accessed b multiple compilation units. $n GLSL ES the onl

shared &lobals are uni'orms. erte2 shader outputs are not considered to be shared &lobals since the

must pass throu&h the rasteriation sta&e be'ore the are used as input b the 'ra&ment shader.

Shared &lobals share the same name space, and must be declared #ith the same tpe and precision. -he

#ill share the same stora&e. Shared &lobal arras must have the same base tpe and the same e2plicit sie.

Scalars must have e2actl the same precision, tpe name and tpe de'inition. Structures must have the

same name, seCuence o' tpe names, and tpe de'initions, and 'ield names to be considered the same tpe.

-his rule applies recursivel 'or nested or embedded tpes.

%.3 Storage ;ualifiers

ariable declarations ma have one stora&e Cuali'ier speci'ied in 'ront o' the tpe. -hese are summaried

as

;ualifier 9eaning

none: de'ault H local read>#rite memor, or an input parameter to a 'unction

onst a compile;time constant, or a 'unction parameter that is read;onl

inentroid in

lin8a&e into a shader 'rom a previous sta&e, variable is copied inlin8a&e #ith centroid based interpolation

outentroid out

lin8a&e out o' a shader to a subseCuent sta&e, variable is copied outlin8a&e #ith centroid based interpolation

uniform value does not chan&e across the primitive bein& processed, uni'orms'orm the lin8a&e bet#een a shader, OpenGL ES, and the application

Outputs 'rom shader ?out@ and inputs to a shader ?in@ can be 'urther Cuali'ied #ith one o' these

interpolation Cuali'iers

;ualifier 9eaning

smootB  perspective correct interpolation

flat no interpolation

-hese interpolation Cuali'iers ma onl precede the Cuali'iers in, entroid in, out, or entroid out in a

declaration. -he do not appl to inputs into a verte2 shader or outputs 'rom a 'ra&ment shader.

Local variables can onl use the onst stora&e Cuali'ier.

33

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 40/155

4 Variables and Types

4unction parameters can use onst, in, and out Cuali'iers, but as parameter uali*iers. 3arameter

Cuali'iers are discussed in section 7.1.1 I4unction %allin& %onventions.

4unction return tpes and structure 'ields do not use stora&e Cuali'iers.

!ata tpes 'or communication 'rom one run o' a shader e2ecutable to its ne2t run ?to communicate

 bet#een 'ra&ments or bet#een vertices@ do not e2ist. -his #ould prevent parallel e2ecution o' the same

shader e2ecutable on multiple vertices or 'ra&ments.

$nitialiers ma onl be used in declarations o' &lobals #ith no stora&e Cuali'ier or #ith a onst Cuali'ier.

Such initialiers must be a constant e2pression. Global variables #ithout stora&e Cuali'iers that are not

initialied in their declaration or b the application #ill not be initialied b OpenGL ES, but rather #ill

enter main56 #ith unde'ined values.

%.3.1 -efault Storage ;ualifier 

$' no Cuali'ier is present on a &lobal variable, then the variable has no lin8a&e to the application or shaders

runnin& on other pipeline sta&es. 4or either &lobal or local unCuali'ied variables, the declaration #ill

appear to allocate memor associated #ith the processor it tar&ets. -his variable #ill provide read>#rite

access to this allocated memor.

%.3.! Constant ;ualifier 

 amed compile;time constants can be declared usin& the onst Cuali'ier. n variables Cuali'ied as

constant are read;onl variables 'or that shader. !eclarin& variables as constant allo#s more descriptive

shaders than usin& hard;#ired numerical constants. -he onst Cuali'ier can be used #ith an o' the non;

void transparent basic data tpes as #ell as structures and arras o' these. $t is an error to #rite to a onst

variable outside o' its declaration, so the must be initialied #hen declared. 4or e2ample,

'onst ve'; "?xis + ve'; =,=0 =,=0 <,=)-

Structure 'ields ma not be Cuali'ied #ith onst. Structure variables can be declared as onst, andinitialied #ith a structure constructor.

$nitialiers 'or const declarations must be constant e2pressions, as de'ined in section +.(.( I%onstant

E2pressions.

34

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 41/155

4 Variables and Types

%.3.3 Constant E)pressions

constant e(pression is one o'

• a literal value ?e.&., X or true@

• a &lobal or local variable Cuali'ied as onst ?i.e., not includin& 'unction parameters@

• an e2pression 'ormed b an operator on operands that are all constant e2pressions, includin& &ettin& an

element o' a constant arra, or a 'ield o' a constant structure, or components o' a constant vector.

o#ever, the seCuence operator ? , @ and the assi&nment operators ? T, T, ...@ are not included in the

operators that can create a constant e2pression.

• the len&th?@ method on an arra, #hether or not the obFect itsel' is constant.

• a constructor #hose ar&uments are all constant e2pressions

• a built;in 'unction call #hose ar&uments are all constant e2pressions, #ith the e2ception o' the te2ture

loo8up 'unctions. -he built;in 'unctions dLdx, dLdy, and f?idtB must return ) #hen evaluated inside

an initialier #ith an ar&ument that is a constant e2pression.

4unction calls to user;de'ined 'unctions ?non;built;in 'unctions@ cannot be used to 'orm constant

e2pressions.

Scalar, vector, matri2, arra and structure variables are constant e2pressions i' Cuali'ied as const.

Sampler tpes cannot be constant e2pressions.

constant integral e(pression is a constant e2pression that evaluates to a scalar si&ned or unsi&ned

inte&er.

%onstant e2pressions #ill be evaluated in an invariant #a so as to create the same value in multiple

shaders #hen the same constant e2pressions appear in those shaders. See section +.7.1 I-he $nvariant

Quali'ier  'or more details on ho# to create invariant e2pressions.

%.3.% Input (ariables

Shader input variables are declared #ith the in stora&e Cuali'ier or the entroid in stora&e Cuali'ier. -he

'orm the input inter'ace bet#een previous sta&es o' the OpenGL ES pipeline and the declarin& shader.

$nput variables must be declared at &lobal scope. alues 'rom the previous pipeline sta&e are copied into

input variables at the be&innin& o' shader e2ecution. ariables declared as in or entroid in ma not be

#ritten to durin& shader e2ecution. Onl the input variables that are actuall read need to be #ritten b

the previous sta&eM it is allo#ed to have super'luous declarations o' input variables.

See section 0 I"uilt;in ariables 'or a list o' the built;in input names.

erte2 shader input variables ?or attributes@ receive per;verte2 data. -he are declared in a verte2 shader

#ith the in Cuali'ier . $t is an error to use entroid in or interpolation Cuali'iers in a verte2 shader input.

-he values copied in are established b the OpenGL ES 3$ or throu&h the use o' the laout identi'ier

location. erte2 shader inputs can onl be float, 'loatin&;point vectors, matrices, si&ned and unsi&ned

inte&ers and inte&er vectors. erte2 shader inputs cannot be arras or structures.

35

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 42/155

4 Variables and Types

E2ample declarations in a verte2 shader:

in ve'7 position-

in ve'; normal-

$t is e2pected that &raphics hard#are #ill have a small number o' 'i2ed vector locations 'or passin& verte2

inputs. -here'ore, the OpenGL ES Shadin& lan&ua&e de'ines each non;matri2 input variable as ta8in& up

one such vector location. -here is an implementation dependent limit on the number o' locations that can

 be used, and i' this is e2ceeded it #ill cause a lin8 error. ?!eclared input variables that are not staticall

used do not count a&ainst this limit.@ scalar input counts the same amount a&ainst this limit as a veE,

so applications ma #ant to consider pac8in& &roups o' 'our unrelated 'loat inputs to&ether into a vector

to better utilie the capabilities o' the underlin& hard#are. matri2 input #ill use up multiple locations.

-he number o' locations used #ill eCual the number o' columns in the matri2.

4ra&ment shader inputs &et per;'ra&ment values, tpicall interpolated 'rom a previous sta&eDs outputs.

-he are declared in 'ra&ment shaders #ith the in stora&e Cuali'ier or the entroid in stora&e Cuali'ier.

4ra&ment inputs can onl be si&ned and unsi&ned inte&ers and inte&er vectors, float, 'loatin&;point

vectors, matrices, or arras or structures o' these. 4ra&ment shader inputs that are, or contain, si&ned orunsi&ned inte&ers or inte&er vectors must be Cuali'ied #ith the interpolation Cuali'ier flat.

4ra&ment inputs are declared as in the 'ollo#in& e2amples:

in ve'; normal-

'entroid in ve'8 exHoord-

invariant 'entroid in ve'7 Holor-

flat in ve'; m9Holor-

-he output o' the verte2 shader and the input o' the 'ra&ment shader 'orm an inter'ace. 4or this inter'ace,

verte2 shader output variables and 'ra&ment shader input variables o' the same name must match in tpe

and Cuali'ication ?other than out matchin& to in@.

%.3.' 6niform (ariables

-he uniform Cuali'ier is used to declare &lobal variables #hose values are the same across the entire

 primitive bein& processed. ll uniform variables are read;onl. -he are initialied to ) at lin8 timeand

ma be updated throu&h the 3$.

E2ample declarations are:

uniform ve'7 lig(tCosition-

-he uniform Cuali'ier can be used #ith an o' the basic data tpes, or #hen declarin& a variable #hose

tpe is a structure, or an arra o' an o' these.

-here is an implementation dependent limit on the amount o' stora&e 'or uni'orms that can be used 'oreach tpe o' shader and i' this is e2ceeded it #ill cause a compile;time or lin8;time error. 9ni'orm

variables that are declared but not used do not count a&ainst this limit. -he number o' user;de'ined

uni'orm variables and the number o' built;in uni'orm variables that are used #ithin a shader are added

to&ether to determine #hether available uni'orm stora&e has been e2ceeded.

36

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 43/155

4 Variables and Types

9ni'orms in the verte2 and 'ra&ment shaders share a sin&le &lobal name space. ence, the tpes and

 precisions o' uni'orm variables #ith the same name must match across shaders that are lin8ed into a

sin&le pro&ram.

%.3. Output (ariables

Shader output variables are declared #ith the out or entroid out stora&e Cuali'iers. -he 'orm the

output inter'ace bet#een the declarin& shader and the subseCuent sta&es o' the OpenGL ES pipeline.

Output variables must be declared at &lobal scope. !urin& shader e2ecution the #ill behave as normal

unCuali'ied &lobal variables. -heir values are copied out to the subseCuent pipeline sta&e on shader e2it.

Onl output variables that are read b the subseCuent pipeline sta&e need to be #rittenM it is allo#ed to

have super'luous declarations o' output variables.

-here is not  an inout stora&e Cuali'ier at &lobal scope 'or declarin& a sin&le variable name as both input

and output to a shader. Output variables must be declared #ith di''erent names than input variables.

erte2 output variables output per;verte2 data and are declared usin& the out stora&e Cuali'ier or the

entroid out stora&e Cuali'ier. -he can onl be float, 'loatin&;point vectors, matrices, si&ned orunsi&ned inte&ers or inte&er vectors, or arras or structures o' an these. erte2 shader outputs that are,

or contain, si&ned or unsi&ned inte&ers or inte&er vectors must be Cuali'ied #ith the interpolation Cuali'ier

flat.

$ndividual verte2 outputs are declared as in the 'ollo#in& e2amples:

out ve'; normal-

'entroid out ve'8 exHoord-

invariant 'entroid out ve'7 Holor-

flat out ve'; m9Holor-

4ra&ment outputs output per;'ra&ment data and are declared usin& the out stora&e Cuali'ier. $t is an error

to use entroid out in a 'ra&ment shader. 4ra&ment outputs can onl be float, 'loatin&;point vectors,

si&ned or unsi&ned inte&ers or inte&er vectors, or arras o' an these. Outputs declared as arras ma onl be inde2ed b a constant inte&ral e2pression. <atrices and structures cannot be output. 4ra&ment outputs

are declared as in the 'ollo#in& e2amples:

out ve'7 FragmentHolor-

out uint Luminosit9-

37

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 44/155

4 Variables and Types

%.3.2 Interface ,locs

9ni'orm variable declarations can be &rouped into named inter'ace bloc8s to provide coarser &ranularit

 bac8in& than is achievable #ith individual declarations. -he can have an optional instance name, used in

the shader to re'erence their members. uni'orm bloc8 is bac8ed b the application #ith a bu''er obFect.

GLSL ES (.) does not support inter'ace bloc8s 'or shader inputs or outputs.

n inter'ace bloc8 is started b a uniform 8e#ord, 'ollo#ed b a bloc8 name, 'ollo#ed b an open curl

 brace ? @ as 'ollo#s:

inter*ace)loc&:

layoutuali*ier opt uniform )loc&name  mem)erlist . instancenameopt 6

layoutuali*ier:

layout + layoutuali*ieri#list  

layoutuali*ieri#list 

comma separated list o' layoutuali*ieri# 

mem)erlist:

mem)er#eclaration

mem)er#eclaration mem)erlist 

mem)er#eclaration:

layoutuali*ier opt uali*iersopt type #eclarators 6

instancename:

i#enti*ier 

i#enti*ier 7 constantintegrale(pression 8

Each o' the above elements is discussed belo#, #ith the e2ception o' laout Cuali'iers ? layoutuali*ier6,

#hich are de'ined in the ne2t section.

4irst, an e2ample,

uniform ransform *

  mat7 @odelVie.@atrix-

  mat7 @odelVie.Cro6e'tion@atrix-

  uniform mat; Normal@atrix- && allo.ed restatement of ualifier

  float !eformation-

2-

-he above establishes a uni'orm bloc8 named I-rans'orm #ith 'our uni'orms &rouped inside it.

-pes and declarators are the same as 'or other uni'orm variable declarations outside bloc8s, #ith these

e2ceptions:

• sampler tpes are not allo#ed

• structure de'initions cannot be nested inside a bloc8 

Other#ise, built;in tpes, previousl declared structures, and arras o' these are allo#ed as the tpe o' a

declarator in the same manner the are allo#ed outside a bloc8.

38

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 45/155

4 Variables and Types

  Repeatin& the uniform inter'ace Cuali'ier 'or a memberDs stora&e Cuali'ier is optional. 4or e2ample,

uniform ransform

*

  uniform mat7 model_vie.- && legal0 uniform inside a uniform $lo':,

  mat7 pro6e'tion- && legal0 uniform in(erited from $lo':,

  in $ool transform_flag- && illegal0 mem$er is not a uniform,

2

4or uni'orm bloc8s, the application uses the bloc8 name to identi' the bloc8. "loc8 names have no other

use #ithin a shader beond inter'ace matchin&M it is an error to use a bloc8 name at &lobal scope 'or

anthin& other than as a bloc8 name ?e.&., use o' a bloc8 name 'or a &lobal variable name or 'unction

name is currentl reserved@.

<atched bloc8 names #ithin an inter'ace ?as de'ined above@ must match in terms o' havin& the same

number o' declarations #ith the same seCuence o' tpes, precisions and the same seCuence o' member

names, as #ell as havin& the same member;#ise laout Cuali'ication ?see ne2t section@. 4urthermore, i' amatchin& bloc8 is declared as an arra, then the arra sies must also match.

$' an instance name ?instancename@ is not used, the names declared inside the bloc8 are scoped at the

&lobal level and accessed as i' the #ere declared outside the bloc8. $' an instance name ?instancename@ 

is used, then it puts all the members inside a scope #ithin its o#n name space, accessed #ith the 'ield

selector ? @ operator ?analo&ousl to structures@. 4or e2ample,

uniform ransform_<

*

  mat7 modelvie.-

2

uniform ransform_8

*  mat7 pro6e'tion-

2 transform_8-

mat7 modelvie.- && illegal as modelvie. alread9 defined at t(is s'ope

mat7 pro6e'tion- && legal as pro6e'tion and transform_8,pro6e'tion are

  && distin't,

Outside the shadin& lan&ua&e ?i.e., in the 3$@, members are similarl identi'ied e2cept the bloc8 name is

al#as used in place o' the instance name ?3$ accesses are to inter'aces, not to shaders@. $' there is no

instance name, then the 3$ does not use the bloc8 name to access a member, Fust the member name. 4or

e2ample:

39

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 46/155

4 Variables and Types

uniform ransform_<

*

  mat7 modelvie.- && ?CI .ill use 3modelvie.4

2

uniform ransform_8

*

  mat7 pro6e'tion- && ?CI .ill use 3ransform_8,pro6e'tion4

2 transform_8-

4or bloc8s declared as arras, the arra inde2 must also be included #hen accessin& members, as in this

e2ample

uniform ransform * && ?CI uses 3ransformA8B4 to refer to instan'e 8

  mat7 @odelVie.@atrix-

  mat7 @odelVie.Cro6e'tion@atrix-

  float !eformation-

2 transformsA7B-,,,

,,, + transformsA8B,@odelVie.@atrix- && s(ader a''ess of instan'e 8

&& ?CI uses 3ransform,@odelVie.@atrix4 to uer9 an offset or ot(er uer9

4or uni'orm bloc8s declared as an arra, each individual arra element corresponds to a separate bu''er

obFect bac8in& one instance o' the bloc8. s the arra sie indicates the number o' bu''er obFects needed,

uni'orm bloc8 arra declarations must speci' an arra sie. ll inde2es used to inde2 a uni'orm bloc8

arra must be constant inte&ral e2pressions.

=hen usin& OpenGL ES 3$ entr points to identi' the name o' an individual bloc8 in an arra o'

 bloc8s, the name strin& must include an arra inde2 ?e.&., Trans*orm728@. =hen usin& OpenGL ES 3$

entr points to re'er to o''sets or other characteristics o' a bloc8 member, an arra inde2 must not be

speci'ied ?e.&., Trans*orm.9o#elVie/9atri( @.-here is an implementation dependent limit on the number o' uni'orm bloc8s that can be used per sta&e.

$' this limit is e2ceeded, it #ill cause a lin8 error.

%.3.4 La&out ;ualifiers

Laout Cuali'iers can appear in several 'orms o' declaration. -he can appear as part o' an inter'ace

 bloc8 de'inition or bloc8 member, as sho#n in the &rammar in the previous section. -he can also appear

#ith Fust a uni'orm to establish laouts o' other uni'orm declarations:

layoutuali*ier  uniform  6

Or, the can appear #ith an individual variable declared #ith an inter'ace Cuali'ier:

layoutuali*ier  inter*aceuali*ier #eclaration 6

!eclarations o' laouts can onl be made at &lobal scope, and onl #here indicated in the 'ollo#in&

subsectionsM their details are speci'ic to #hat the inter'ace Cuali'ier is, and are discussed individuall.

40

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 47/155

4 Variables and Types

$nter'ace Cuali'iers are a subset o' stora&e Cuali'iers:

inter*aceuali*ier:

in

out

uniform

s sho#n in the previous section, layoutuali*ier e2pands to:

layoutuali*ier :

layout + layoutuali*ieri#list  

-he to8ens in an layoutuali*ieri#list  are identi'iers, not 8e#ords. Generall, the can be listed in

an order. Order;dependent meanin&s e2ist onl i' e2plicitl called out belo#. s 'or other identi'iers,

the are case sensitive.

%.3.4.1 Input La&out ;ualifiers

erte2 shaders allo# input laout Cuali'iers on input variable declarations. -he laout Cuali'ier identi'ier'or verte2 shader inputs is:

layoutuali*ieri# 

loation 3 integerconstant 

Onl one ar&ument is accepted. 4or e2ample,

la9outlo'ation + ;) in ve'7 normal-

#ill establish that the verte2 shader input normal is copied in 'rom vector location number (.

$' an input variable #ith no location assi&ned in the shader te2t has a location speci'ied throu&h the

OpenGL ES 3$, the 3$;assi&ned location #ill be used. Other#ise, such variables #ill be assi&ned alocation b the lin8er. See section *.11./ Ierte2 ttributes o' the OpenGL ES (.) Graphics Sstem

Speci'ication 'or more details.

4ra&ment shaders cannot have input laout Cuali'iers.

%.3.4.! Output La&out ;ualifiers

erte2 shaders cannot have output laout Cuali'iers.

$n the 'ra&ment shader, a bindin& bet#een an output variable and a numbered dra# bu''er is established

 b the location laout Cuali'ier in the output declaration. -he location o' each output corresponds to the

dra# bu''er the data is #ritten to. Locations are inte&ral values in the ran&e

Z), <YA!R=A"944ERS ^ 1[.

4ra&ment shaders allo# output laout Cuali'iers onl on the inter'ace Cuali'ier out. -he laout Cuali'ier

identi'ier 'or 'ra&ment shader outputs is:

layoutuali*ieri# 

loation 3 integerconstant 

41

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 48/155

4 Variables and Types

-he Cuali'ier ma appear at most once #ithin a declaration. 4or e2ample,

la9outlo'ation + ;) out ve'7 'olor-

#ill establish that the 'ra&ment shader output color is copied out to dra# bu''er (.

$' the named 'ra&ment shader output is an arra, it #ill be assi&ned consecutive locations startin& #ith the

location speci'ied. 4or e2ample,

la9outlo'ation + 8) out ve'7 'olorsA;B-

#ill establish that colors is copied out to dra# bu''ers *, (, and +.

$' there is onl a sin&le output, the location does not need to be speci'ied, in #hich case it de'aults to ero.

-his applies 'or all output tpes, includin& arras. 4or e2ample,

out ve'7 m9_FragHolor- && must $e t(e onl9 output de'laration

#ill establish that the 'ra&ment shader output my+rag%olor is copied out to dra# bu''er ). Li8e#ise,

out ve'7 m9_Frag!ataA7B- && must $e t(e onl9 output de'laration

#ill establish that the 'ra&ment shader outputs my+ragData708 to my+ragData738 is copied out to

dra# bu''ers ) throu&h ( respectivel.

$' there is more than one output, the location must be speci'ied 'or all outputs. $t is an error i' an o' the

'ollo#in& occur:

• -he location o' an output or element o' an arra output, is &reater or eCual to the value o'

<YA!R=A"944ERS.

• <ore than one output or element o' an arra output is bound to the same location.

 See section (.6.* IShader E2ecution o' the OpenGL ES (.) Graphics Sstem Speci'ication 'or more

details.

%.3.4.3 6niform ,loc La&out ;ualifiers

Laout Cuali'iers can be used 'or uni'orm bloc8s, but not 'or non;bloc8 uni'orm declarations. -he laout

Cuali'ier identi'iers 'or uni'orm bloc8s are:

layoutuali*ieri# 

sBared

paCed

stdGE!

ro?9maIor

olumn9maIor

 one o' these have an semantic a''ect at all on the usa&e o' the variables bein& declaredM the onl

describe ho# data is laid out in memor. 4or e2ample, matri2 semantics are al#as column;based, as

described in the rest o' this speci'ication, no matter #hat laout Cuali'iers are bein& used.

42

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 49/155

4 Variables and Types

9ni'orm bloc8 laout Cuali'iers can be declared 'or &lobal scope, on a sin&le uni'orm bloc8, or on a sin&le

 bloc8 member declaration.

!e'ault laouts are established at &lobal scope 'or uni'orm bloc8s as

la9outlayoutuali*ieri#list ) uniform-

=hen this is done, the previous de'ault Cuali'ication is 'irst inherited and then overridden as per the

override rules listed belo# 'or each Cuali'ier listed in the declaration. -he result becomes the ne# de'ault

Cuali'ication scoped to subseCuent uni'orm bloc8 de'initions.

-he initial state o' compilation is as i' the 'ollo#in& #ere declared:

la9outs(ared0 'olumn_ma6or) uniform-

E2plicitl declarin& this in a shader #ill return de'aults bac8 to their initial state.

9ni'orm bloc8s can be declared #ith optional laout Cuali'iers, and so can their individual member

declarations. Such bloc8 laout Cuali'ication is scoped onl to the content o' the bloc8. s #ith &loballaout declarations, bloc8 laout Cuali'ication 'irst inherits 'rom the current de'ault Cuali'ication and then

overrides it. Similarl, individual member laout Cuali'ication is scoped Fust to the member declaration,

and inherits 'rom and overrides the bloc8Ds Cuali'ication.

-he share# Cuali'ier overrides onl the st#10 and pac&e# Cuali'iersM other Cuali'iers are inherited. -he

compiler>lin8er #ill ensure that multiple pro&rams and pro&rammable sta&es containin& this de'inition

#ill share the same memor laout 'or this bloc8, as lon& as the also matched in their ro/+ma;or and>or

column+ma;or Cuali'ications. -his allo#s use o' the same bu''er to bac8 the same bloc8 de'inition across

di''erent pro&rams.

-he pac&e# Cuali'ier overrides onl st#10 and share# M other Cuali'iers are inherited. =hen pac&e# is

used, no shareable laout is &uaranteed. -he compiler and lin8er can optimie memor use based on #hat

variables activel &et used and on other criteria. O''sets must be Cueried, as there is no other #a o'

&uaranteein& #here ?and #hich@ variables reside #ithin the bloc8. ttempts to share a pac8ed uni'orm bloc8 across pro&rams or sta&es #ill &enerall 'ail. o#ever, implementations ma aid application

mana&ement o' pac8ed bloc8s b usin& canonical laouts 'or pac8ed bloc8s.

-he st#10 Cuali'ier overrides onl the pac&e# and share# Cuali'iersM other Cuali'iers are inherited. -he

laout is e2plicitl determined b this, as described in section *.11./ I9ni'orm ariables under

IStandard 9ni'orm "loc8 Laout o' the OpenGL ES Graphics Sstem Speci'ication. ence, as in

 share# above, the resultin& laout is shareable across pro&rams.

Laout Cuali'iers on member declarations cannot use the share# , pac&e# , or st#10 Cuali'iers. -hese can

onl be used at &lobal scope or on a bloc8 declaration.

-he ro/+ma;or Cuali'ier overrides onl the column+ma;or  Cuali'ierM other Cuali'iers are inherited. $t onl

a''ects the laout o' matrices. Elements #ithin a matri2 ro# #ill be conti&uous in memor.

-he column+ma;or Cuali'ier overrides onl the ro/+ma;or  Cuali'ierM other Cuali'iers are inherited. $t onl

a''ects the laout o' matrices. Elements #ithin a matri2 column #ill be conti&uous in memor.

=hen multiple ar&uments are listed in a layout declaration, the e''ect #ill be the same as i' the #ere

declared one at a time, in order 'rom le't to ri&ht, each in turn inheritin& 'rom and overridin& the result

'rom the previous Cuali'ication.

43

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 50/155

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 51/155

4 Variables and Types

-he tpe and presence o' the interpolation Cuali'iers and stora&e Cuali'iers and invariant Cuali'iers o'

variables #ith the same name declared in all lin8ed shaders must match, other#ise the lin8 command #ill

'ail.

%.3.10 Lining of (erte) Outputs and +ragment Inputs

-he tpe o' verte2 outputs and 'ra&ment input #ith the same name must match, other#ise the lin8

command #ill 'ail. -he precision does not need to match. Onl those 'ra&ment inputs staticall used ?i.e.

read@ in the 'ra&ment shader must be declared as outputs in the verte2 shaderM declarin& super'luous verte2

shader outputs is permissible.

-he 'ollo#in& table summaries the rules 'or matchin& verte2 outputs #ith 'ra&ment inputs:

Lragment ;Bader Nnputs

 o re'erence !eclaresM

no static use

!eclares

and static use

Vertex

;Bader

utputs

 o re'erence llo#ed llo#ed error 

!eclaresM

no static use

llo#ed llo#ed llo#ed

?values are

unde'ined@

!eclares

and static use

llo#ed llo#ed llo#ed

?values are

 potentiall

unde'ined@

-he term static use means that a'ter preprocessin& the shader includes at least one statement that accesses

the input or output, even i' that statement is never actuall e2ecuted.

-he precision o' a verte2 output does not need to match the precision o' the correspondin& 'ra&ment input.

-he minimum precision at #hich verte2 outputs are interpolated is the minimum o' the verte2 output

 precision and the 'ra&ment input precision, #ith the e2ception that 'or hi&hp, implementations do not have

to support 'ull ieee 0/+ precision. $n this case, the precision o' the interpolated value is de'ined b a

ran&e and resolution as belo#:

-he precision o' values e2ported to a trans'orm 'eedbac8 bu''er is the precision o' the outputs o' the

verte2 shader.

45

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 52/155

4 Variables and Types

%.% *arameter ;ualifiers

3arameters can have these Cuali'iers.

;ualifier 9eaning

none: de'ault H same is in

in 'or 'unction parameters passed into a 'unction

out 'or 'unction parameters passed bac8 out o' a 'unction, but not initialied'or use #hen passed in

inout 'or 'unction parameters passed both into and out o' a 'unction

3arameter Cuali'iers are discussed in more detail in section 7.1.1 I4unction %allin& %onventions.

%.' *recision and *recision ;ualifiers

%.'.1 :ange and *recision

-he precision o' hi&hp 'loatin&;point variables is de'ined b the $EEE 0/+ standard 'or (*;bit 'loatin&;

 point numbers. -his includes support 'or as ?ot a umber@ and $n's ?positive or ne&ative in'inities@.

-he 'ollo#in& rules appl to hi&hp operations: $n'inities and eros are &enerated as dictated b $EEE,

 but subFect to the precisions allo#ed in the 'ollo#in& table and subFect to allo#in& positive and ne&ative

eros to be interchan&ed. o#ever, dividin& a non;ero b ) results in the appropriatel si&ned $EEE $n':

$' both positive and ne&ative eros are implemented, the correctl si&ned $n' #ill be &enerated, other#ise

 positive $n' is &enerated. n subnormal ?denormalied@ value input into a shader or potentiall

&enerated b an operation in a shader can be 'lushed to ). -he roundin& mode cannot be set and is

unde'ined. as are not reCuired to be &enerated. Support 'or si&nalin& as is not reCuired and

e2ceptions are never raised. Operations and built;in 'unctions that operate on a a are not reCuired to

return a a as the result. o#ever i' as are &enerated, isnan?@ should return the correct value.

3recisions are e2pressed in terms o' ma2imum relative error in units o' 9L3 ?units in the last place@,

unless other#ise noted.

46

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 53/155

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 54/155

4 Variables and Types

-he reCuired ran&es and precisions 'or precision Cuali'iers are:

;ualifier +loating*oint :ange

+loating *oint9agnitude

:ange

+loating *oint*recision

Integer:ange

Signed 6nsigned

BigBp s $EEE;0/+

(−*1*7

 $*1*0)

s $EEE;0/+

).),(*−1*7 $*

1*0)

s $EEE 0/+relative:

*−*+

[−*(1 $*

(1−1]   [) $*(*−1 ]

mediump+minimum

reJuirements

(−*1+ $*

1+)   (*−1+ $*

1+)Relative:

*−1)

[−*1/ $ *

1/−1]   [) $*17−1 ]

lo?p

+minimumreJuirements

(−*, *)   (*−5 $*)

bsolute:

*−5 >   *

−6

si&ned>unsi&ned

[−*5 $*

5−1] [) $*6−1 ]

$n addition, the ran&e and precision o' a mediump 'loatin& point value must be the same as or &reater than

the ran&e and precision o' a lo#p 'loatin& point value. -he ran&e and precision o' a hi&hp 'loatin& point

value must be the same as or &reater than the ran&e and precision o' a mediump 'loatin& point value.

-he ran&e o' a mediump inte&er value must be the same as or &reater than the ran&e o' a lo#p inte&er

value. -he ran&e o' a hi&hp inte&er value must be the same as or &reater than the ran&e o' a mediump

inte&er value.

=ithin the above speci'ication, an implementation is allo#ed to var the representation o' numeric values,

 both #ithin a shader and bet#een di''erent shaders. $' necessar, this variance can be controlled usin& the

invariance Cuali'ier.

-he actual ran&es and precisions provided b an implementation can be Cueried throu&h the 3$. See the

OpenGL ES (.) speci'ication 'or details on ho# to do this.

%.'.! Conersion bet#een precisions

=ithin the same tpe, conversion 'rom a lo#er to a hi&her precision must be e2act. =hen convertin&

'rom a hi&her precision to a lo#er precision, i' the value is representable b the implementation o' the

tar&et precision, the conversion must also be e2act. $' the value is not representable, the behavior is

dependent on the tpe:

• 4or si&ned and unsi&ned inte&ers, the value is truncatedM bits in positions not present in the tar&et

 precision are set to ero. ?3ositions start at ero and the least si&ni'icant bit is considered to be

 position ero 'or this purpose.@

• 4or 'loatin& point values, the value should either clamp to $4 or ;$4, or to the ma2imum or

minimum value that the implementation supports. =hile this behavior is implementation

dependent, it should be consistent 'or a &iven implementation.

48

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 55/155

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 56/155

4 Variables and Types

4or e2ample, consider the statements.

uniform (ig(p float (<-

(ig(p float (8 + 8,; 7,- && operation and result are (ig(p pre'ision

mediump float m-

m + ;, (< (8- && all operations are (ig(p pre'ision

(8 + m (<- && operation is (ig(p pre'ision

m + (8 (<- && operation is (ig(p pre'ision

(8 + m D m- && addition and result at mediump pre'ision

void f(ig(p float p)-

f;,;)- && ;,; .ill $e passed in at (ig(p pre'ision

3recision Cuali'iers, as #ith other Cuali'iers, do not a''ect the basic tpe o' the variable. $n particular,

there are no constructors 'or precision conversionsM constructors onl convert tpes. Similarl, precision

Cuali'iers, as #ith other Cuali'iers, do not contribute to 'unction overloadin& based on parameter tpes.

s discussed in the ne2t chapter, 'unction input and output is done throu&h copies, and there'ore Cuali'iers

do not have to match.

-he same uni'orm declared in di''erent shaders that are lin8ed to&ether must have the same precision

Cuali'ication.

-he precision o' a variable is determined #hen the variable is declared and cannot be subseCuentl

chan&ed.

%.'.% -efault *recision ;ualifiers

-he precision statement

pre'ision pre'ision1ualifier t9pe-

can be used to establish a de'ault precision Cuali'ier. -he type 'ield can be either  int or float or an o'

the sampler tpes, and the precisionuali*ier can be lo?p, mediump, or BigBp. n other tpes orCuali'iers #ill result in an error. $' type is float, the directive applies to non;precision;Cuali'ied 'loatin&

 point tpe ?scalar, vector, and matri2@ declarations. $' type is int, the directive applies to all non;

 precision;Cuali'ied inte&er tpe ?scalar, vector, si&ned, and unsi&ned@ declarations. -his includes &lobal

variable declarations, 'unction return declarations, 'unction parameter declarations, and local variable

declarations.

 on;precision Cuali'ied declarations #ill use the precision Cuali'ier speci'ied in the most recent preision

statement that is still in scope. -he preision statement has the same scopin& rules as variable

declarations. $' it is declared inside a compound statement, its e''ect stops at the end o' the innermost

statement it #as declared in. 3recision statements in nested scopes override precision statements in outer

scopes. <ultiple precision statements 'or the same basic tpe can appear inside the same scope, #ith later

statements overridin& earlier statements #ithin that scope.

50

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 57/155

4 Variables and Types

-he verte2 lan&ua&e has the 'ollo#in& predeclared &loball scoped de'ault precision statements:

pre'ision (ig(p float-

pre'ision (ig(p int-

pre'ision lo.p sampler8!-

pre'ision lo.p samplerHu$e-

-he 'ra&ment lan&ua&e has the 'ollo#in& predeclared &loball scoped de'ault precision statements:

pre'ision mediump int-

pre'ision lo.p sampler8!-

pre'ision lo.p samplerHu$e-

-he 'ra&ment lan&ua&e has no de'ault precision Cuali'ier 'or 'loatin& point tpes. ence 'or float, 'loatin&

 point vector and matri2 variable declarations, either the declaration must include a precision Cuali'ier or

the de'ault 'loat precision must have been previousl declared. Similarl, there is no de'ault precisionCuali'ier 'or the 'ollo#in& sampler tpes in either the verte2 or 'ra&ment lan&ua&e:

sampler;!-

samplerHu$e-

samplerHu$eS(ado.-

sampler8!S(ado.-

sampler8!?rra9-

sampler8!?rra9S(ado.-

isampler8!-

isampler;!-

isamplerHu$e-

isampler8!?rra9-

usampler8!-

usampler;!-usamplerHu$e-

usampler8!?rra9-

%. (ariance and the Inariant ;ualifier 

$n this section, variance re'ers to the possibilit o' &ettin& di''erent values 'rom the same e2pression in

di''erent pro&rams. 4or e2ample, sa t#o verte2 shaders, in di''erent pro&rams, each set gl+'osition #ith

the same e2pression in both shaders, and the input values into that e2pression are the same #hen both

shaders run. $t is possible, due to independent compilation o' the t#o shaders, that the values assi&ned to

 gl+'osition are not e2actl the same #hen the t#o shaders run. $n this e2ample, this can cause problems

#ith ali&nment o' &eometr in a multi;pass al&orithm.

$n &eneral, such variance bet#een shaders is allo#ed. =hen such variance does not e2ist 'or a particularoutput variable, that variable is said to be invariant.

51

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 58/155

4 Variables and Types

%..1 The Inariant ;ualifier 

-o ensure that a particular output variable is invariant, it is necessar to use the invariant Cuali'ier. $t can

either be used to Cuali' a previousl declared variable as bein& invariant

invariant gl_Cosition- && ma:e $uilt1in gl_Cosition $e invariant

out ve'; Holor-

invariant Holor- && ma:e existing Holor $e invariant

invariant Holor_8- && error% Holor_8 (as not $een de'lared

or as part o' a declaration #hen a variable is declared

invariant 'entroid out ve'; Holor-

-he invariant Cuali'ier must appear be'ore an interpolation Cuali'iers or stora&e Cuali'iers #hen

combined #ith a declaration. Onl variables output 'rom a shader can be candidates 'or invariance. -his

includes user;de'ined output variables and the built;in output variables. s onl outputs can be declared

as invariant, an invariant output 'rom one shader sta&e #ill still match an input o' a subseCuent sta&e

#ithout the input bein& declared as invariant.

-he invariant 8e#ord can be 'ollo#ed b a comma separated list o' previousl declared identi'iers. ll

uses o' invariant must be at the &lobal scope, and be'ore an use o' the variables bein& declared as

invariant.

-o &uarantee invariance o' a particular output variable across t#o pro&rams, the 'ollo#in& must also be

true:

• -he output variable is declared as invariant in both pro&rams.

• -he same values must be input to all shader input variables consumed b e2pressions and control 'lo#

contributin& to the value assi&ned to the output variable.

• -he te2ture 'ormats, te2el values, and te2ture 'ilterin& are set the same #a 'or an te2ture 'unction

calls contributin& to the value o' the output variable.

• ll input values are all operated on in the same #a. ll operations in the consumin& e2pressions and

an intermediate e2pressions must be the same, #ith the same order o' operands and same

associativit, to &ive the same order o' evaluation. $ntermediate variables and 'unctions must be

declared as the same tpe #ith the same e2plicit or implicit precision Cuali'iers. n control 'lo#

a''ectin& the output value must be the same, and an e2pressions consumed to determine this control

'lo# must also 'ollo# these invariance rules.

• ll the data 'lo# and control 'lo# leadin& to settin& the invariant output variable reside in a sin&le

compilation unit.

Essentiall, all the data 'lo# and control 'lo# leadin& to an invariant output must match.

52

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 59/155

4 Variables and Types

$nitiall, b de'ault, all output variables are allo#ed to be variant. -o 'orce all output variables to be

invariant, use the pra&ma

#pragma S!GL invariantall)

 be'ore all declarations in a shader. $' this pra&ma is used a'ter the declaration o' an variables or

'unctions, then the set o' outputs that behave as invariant is unde'ined. $t is an error to use this pra&ma in

a 'ra&ment shader.

Generall, invariance is ensured at the cost o' 'le2ibilit in optimiation, so per'ormance can be de&raded

 b use o' invariance. ence, use o' this pra&ma is intended as a debu& aid, to avoid individuall declarin&

all output variables as invariant.

%..! Inariance <ithin a Shader 

=hen a value is stored in a variable, it is usuall assumed it #ill remain constant unless e2plicitl

chan&ed. o#ever, durin& the process o' optimiation, it is possible that the compiler ma choose to

recompute a value rather than store it in a re&ister. Since the precision o' operations is not completelspeci'ied ?e.&. a lo# precision operation ma be done at medium or hi&h precision@, it #ould be possible

'or the recomputed value to be di''erent 'rom the ori&inal value.

alues are allo#ed to be variant #ithin a shader. -o prevent this, the invariant Cuali'ier or invariant

 pra&ma must be used.

=ithin a shader, there is no invariance 'or values &enerated b di''erent non;constant e2pressions, even i'

those e2pressions are identical.

E2ample 1:

pre'ision mediump-

ve'7 'ol-

ve'8 a + ,,,

,,,'ol + texturetex0 a)- && a (as a value a1

,,,

'ol + texturetex0 a)- && a (as a value a2 .(ere possi$l9 a1 J a2

-o en'orce invariance in this e2ample use:

#pragma S!GL invariantall)

E2ample *:

ve'8 m + ,,,-

ve'8 n + ,,,-

ve'8 a + m D n-

ve'8 $ + m D n- && a and $ are not guaranteed to $e exa'tl9 eual

-here is no mechanism to en'orce invariance bet#een a and b.

53

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 60/155

4 Variables and Types

%..3 Inariance of Constant E)pressions

$nvariance must be &uaranteed 'or constant e2pressions. particular constant e2pression must evaluate to

the same result i' it appears a&ain in the same shader or a di''erent shader. -his includes the same

e2pression appearin& t#o shaders o' the same lan&ua&e or shaders o' t#o di''erent lan&ua&es.

%onstant e2pressions must evaluate to the same result #hen operated on as alread described above 'or

invariant variables.

%..% Inariance of 6ndefined (alues

9nde'ined values are not invariant nor can the be made invariant b use o' the invariant Cuali'ier or

 pra&ma. $n some implementations, unde'ined values ma cause une2pected behavior i' the are used in

control;'lo# e2pressions e.&. in the 'ollo#in& case, one, both or neither 'unctions ma be e2ecuted and

this ma not be consistent over multiple invocations o' the shader:

int x- && undefined value

if x ++ <)

*

  f)- && Kndefined .(et(er f) is exe'uted

2

if x ++ 8)

*

  g)- && Kndefined .(et(er g) is exe'uted,

2

 ote that an unde'ined value is a value that has not been speci'ied. value that has been speci'ied but

has a potentiall lar&e error due to, 'or e2ample, lac8 o' precision in an e2pression, is not unde'ined and

so can be made invariant.

%.2 Order of ;ualification=hen multiple Cuali'ications are present, the must 'ollo# a strict order. -his order is as 'ollo#s.

invariantuali*ier interpolationuali*ier storageuali*ier precisionuali*ier 

 storageuali*ier parameteruali*ier precisionuali*ier 

54

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 61/155

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 62/155

5 Operators and !pressions

'.! rra& Operations

-hese are no# described in section /.0 IStructure and rra Operations.

'.3 +unction Calls

$' a 'unction returns a value, then a call to that 'unction ma be used as an e2pression, #hose tpe #ill be

the tpe that #as used to declare or de'ine the 'unction.

4unction de'initions and callin& conventions are discussed in section 7.1 I4unction !e'initions .

'.% Constructors

%onstructors use the 'unction call snta2, #here the 'unction name is a tpe, and the call ma8es an obFect

o' that tpe. %onstructors are used the same #a in both initialiers and e2pressions. ?See section 6

IShadin& Lan&ua&e Grammar 'or details.@ -he parameters are used to initialie the constructed value.

%onstructors can be used to reCuest a data tpe conversion to chan&e 'rom one scalar tpe to another

scalar tpe, or to build lar&er tpes out o' smaller tpes, or to reduce a lar&er tpe to a smaller tpe.

$n &eneral, constructors are not built;in 'unctions #ith predetermined prototpes. 4or arras and

structures, there must be e2actl one ar&ument in the constructor 'or each element or 'ield. 4or the other

tpes, the ar&uments must provide a su''icient number o' components to per'orm the initialiation, and it

is an error to include so man ar&uments that the cannot all be used. !etailed rules 'ollo#. -he

 prototpes actuall listed belo# are merel a subset o' e2amples.

'.%.1 Conersion and Scalar Constructors

%onvertin& bet#een scalar tpes is done as the 'ollo#in& prototpes indicate:

int$ool) && 'onverts a 5oolean value to an int

intfloat) && 'onverts a float value to an int

float$ool) && 'onverts a 5oolean value to a float

floatint) && 'onverts a signed integer value to a float

$oolfloat) && 'onverts a float value to a 5oolean

$oolint) && 'onverts a signed integer value to a 5oolean

uint$ool) && 'onverts a 5oolean value to an unsigned integer

uintfloat) && 'onverts a float value to an unsigned integer

uintint) && 'onverts a signed integer value to an unsigned integer

intuint) && 'onverts an unsigned integer to a signed integer

$ooluint) && 'onverts an unsigned integer value to a 5oolean value

floatuint) && 'onverts an unsigned integer value to a float value

=hen constructors are used to convert a float to an int or uint, the 'ractional part o' the 'loatin&;point

value is dropped. $t is unde'ined to convert a ne&ative 'loatin& point value to an uint.

=hen a constructor is used to convert an int, uint, or a float to a @ool, ) and ).) are converted to false,

and non;ero values are converted to true. =hen a constructor is used to convert a @ool to an int, uint,

or float, false is converted to ) or ).), and true is converted to 1 or 1.).

56

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 63/155

5 Operators and !pressions

-he constructor int+uint preserves the bit pattern in the ar&ument, #hich #ill chan&e the ar&umentDs

value i' its si&n bit is set. -he constructor uint+int preserves the bit pattern in the ar&ument, #hich #ill

chan&e its value i' it is ne&ative.

$dentit constructors, li8e float?float@ are also le&al, but o' little use.

Scalar constructors #ith non;scalar parameters can be used to ta8e the 'irst element 'rom a non;scalar.

4or e2ample, the constructor float?ve8@ #ill select the 'irst component o' the ve8 parameter.

'.%.! (ector and 9atri) Constructors

%onstructors can be used to create vectors or matrices 'rom a set o' scalars, vectors, or matrices. -his

includes the abilit to shorten vectors.

$' there is a sin&le scalar parameter to a vector constructor, it is used to initialie all components o' the

constructed vector to that scalars value. $' there is a sin&le scalar parameter to a matri2 constructor, it is

used to initialie all the components on the matri2s dia&onal, #ith the remainin& components initialied

to ).).

$' a vector is constructed 'rom multiple scalars, one or more vectors, or one or more matrices, or a mi2ture

o' these, the vectorDs components #ill be constructed in order 'rom the components o' the ar&uments. -he

ar&uments #ill be consumed le't to ri&ht, and each ar&ument #ill have all its components consumed, in

order, be'ore an components 'rom the ne2t ar&ument are consumed. Similarl 'or constructin& a matri2

'rom multiple scalars or vectors, or a mi2ture o' these. <atri2 components #ill be constructed and

consumed in column maFor order. $n these cases, there must be enou&h components provided in the

ar&uments to provide an initialier 'or ever component in the constructed value. $t is an error to provide

e2tra ar&uments beond this last used ar&ument.

$' a matri2 is constructed 'rom a matri2, then each component ?column i$ ro# ;@ in the result that has a

correspondin& component ?column i$ ro# ;@ in the ar&ument #ill be initialied 'rom there. ll other

components #ill be initialied to the identit matri2. $' a matri2 ar&ument is &iven to a matri2 constructor,

it is an error to have an other ar&uments.

$' the basic tpe ?@ool, int, or float@ o' a parameter to a constructor does not match the basic tpe o' the

obFect bein& constructed, the scalar construction rules ?above@ are used to convert the parameters.

57

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 64/155

5 Operators and !pressions

Some use'ul vector constructors are as 'ollo#s:

ve';float) && initiali"es ea'( 'omponent of t(e ve'; .it( t(e float

ve'7ive'7) && ma:es a ve'7 .it( 'omponent1.ise 'onversion

ve'7mat8) && t(e ve'7 is 'olumn = follo.ed $9 'olumn <

ve'8float0 float) && initiali"es a ve'8 .it( 8 floats

ive';int0 int0 int) && initiali"es an ive'; .it( ; ints

$ve'7int0 int0 float0 float) && uses 7 5oolean 'onversions

ve'8ve';) && drops t(e t(ird 'omponent of a ve';

ve';ve'7) && drops t(e fourt( 'omponent of a ve'7

ve';ve'80 float) && ve';,x + ve'8,x0 ve';,9 + ve'8,90 ve';," + float

ve';float0 ve'8) && ve';,x + float0 ve';,9 + ve'8,x0 ve';," + ve'8,9

ve'7ve';0 float)

ve'7float0 ve';)

ve'7ve'80 ve'8)

Some e2amples o' these are:

ve'7 'olor + ve'7=,=0 <,=0 =,=0 <,=)-

ve'7 rg$a + ve'7<,=)- && sets ea'( 'omponent to <,=

ve'; rg$ + ve';'olor)- && drop t(e 7t( 'omponent

-o initialie the dia&onal o' a matri2 #ith all other elements set to ero:

mat8float)

mat;float)

mat7float)

-hat is, result7i87;8 is set to the 'loat ar&ument 'or all i = ; and set to ) 'or all i≠ ;.

58

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 65/155

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 66/155

5 Operators and !pressions

'.%.% rra& Constructors

rra tpes can also be used as constructor names, #hich can then be used in e2pressions or initialiers.

4or e2ample,

'onst float 'A;B + floatA;B>,=0 ,80 <,<)-

'onst float dA;B + floatAB>,=0 ,80 <,<)-

float g-

,,,

float aA>B + floatA>Bg0 <0 g0 8,;0 g)-

float $A;B-

$ + floatA;Bg0 g D <,=0 g D 8,=)-

-here must be e2actl the same number o' ar&uments as the sie o' the arra bein& constructed. -he

ar&uments are assi&ned in order, startin& at element ), to the elements o' the constructed arra. Each

ar&ument must be the same tpe as the element tpe o' the arra.

'.' (ector Components

-he names o' the components o' a vector are denoted b a sin&le letter. s a notational convenience,

several letters are associated #ith each component based on common usa&e o' position, color or te2ture

coordinate vectors. -he individual components o' a vector can be selected b 'ollo#in& the variable

name #ith period ?  @ and then the component name.

-he component names supported are:

>($ y$ $ /? 9se'ul #hen accessin& vectors that represent points or normals

>r$ g$ )$ a? 9se'ul #hen accessin& vectors that represent colors

>s$ t$ p$ ? 9se'ul #hen accessin& vectors that represent te2ture coordinates

-he component names ($ r$ and s are, 'or e2ample, snonms 'or the same ?'irst@ component in a vector.

 ote that the third component o' the te2ture coordinate set, r  in OpenGL ES, has been renamed p so as to

avoid the con'usion #ith r  ?'or red@ in a color.

ccessin& components beond those declared 'or the vector tpe is an error so, 'or e2ample:

ve'8 pos-

pos,x && is legal

pos," && is illegal

60

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 67/155

5 Operators and !pressions

-he component selection snta2 allo#s multiple components to be selected b appendin& their names

?'rom the same name set@ a'ter the period ?  @.

ve'7 v7-

v7,rg$a- && is a ve'7 and t(e same as 6ust using v70

v7,rg$- && is a ve';0

v7,$- && is a float0

v7,x9- && is a ve'80

v7,xg$a- && is illegal 1 t(e 'omponent names do not 'ome from

&& t(e same set,

 o more than + components can be selected.

ve'7 v7-

v7,x9".- && is a ve'7

v7,x9".x9- && is illegal sin'e it (as 'omponents

v7,x9".x9),x9- && is illegal sin'e t(e intermediate value (as 'omponents

ve'8 v8-

v8,x9x9- && is legal, It evaluates to a ve'7,

-he order o' the components can be di''erent to s#ile them, or replicated:

ve'7 pos + ve'7<,=0 8,=0 ;,=0 7,=)-

ve'7 s.i"+ pos,."9x- && s.i" + 7,=0 ;,=0 8,=0 <,=)

ve'7 dup + pos,xx99- && dup + <,=0 <,=0 8,=0 8,=)

-his notation is more concise than the constructor snta2. -o 'orm an r;value, it can be applied to an

e2pression that results in a vector r;value.

-he component &roup notation can occur on the le't hand side o' an e2pression.

ve'7 pos + ve'7<,=0 8,=0 ;,=0 7,=)-pos,x. + ve'8>,=0 ,=)- && pos + >,=0 8,=0 ;,=0 ,=)

pos,.x + ve'8,=0 M,=)- && pos + M,=0 8,=0 ;,=0 ,=)

pos,xx + ve'8;,=0 7,=)- && illegal 1 x used t.i'e

pos,x9 + ve';<,=0 8,=0 ;,=)- && illegal 1 mismat'( $et.een ve'8 and ve';

-o 'orm an l;value, s#ilin& must be applied to an l;value o' vector tpe, contain no duplicate

components, and it results in an l;value o' scalar or vector tpe, dependin& on number o' components

speci'ied.

rra subscriptin& snta2 can also be applied to vectors to provide numeric inde2in&. So in

ve'7 pos-

 pos728 re'ers to the third element o' pos and is eCuivalent to  pos. . -his allo#s variable inde2in& into avector, as #ell as a &eneric #a o' accessin& components. n inte&er e2pression can be used as the

subscript. -he 'irst component is at inde2 ero. Readin& 'rom or #ritin& to a vector usin& a constant

inte&ral e2pression #ith a value that is ne&ative or &reater than or eCual to the sie o' the vector is ille&al.

=hen inde2in& #ith non;constant e2pressions, behavior is unde'ined i' the inde2 is ne&ative, or &reater

than or eCual to the sie o' the vector.

61

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 68/155

5 Operators and !pressions

 ote that scalars are not considered to be sin&le;component vectors and there'ore the use o' component

selection operators on scalars is ille&al.

'. 9atri) Components-he components o' a matri2 can be accessed usin& arra subscriptin& snta2. pplin& a sin&le subscript

to a matri2 treats the matri2 as an arra o' column vectors, and selects a sin&le column, #hose tpe is a

vector o' the same sie as the ?column sie o' the@ matri2. -he le'tmost column is column ). second

subscript #ould then operate on the resultin& vector, as de'ined earlier 'or vectors. ence, t#o subscripts

select a column and then a ro#.

mat7 m-

mA<B + ve'78,=)- && sets t(e se'ond 'olumn to all 8,=

mA=BA=B + <,=- && sets t(e upper left element to <,=

mA8BA;B + 8,=- && sets t(e 7t( element of t(e t(ird 'olumn to 8,=

"ehavior is unde'ined #hen accessin& a component outside the bounds o' a matri2 #ith a non;constant

e2pression. $t is an error to access a matri2 #ith a constant e2pression that is outside the bounds o' the

matri2.

'.2 Structure and rra& Operations

-he 'ields o' a structure and the lengtB method o' an arra are selected usin& the period ?  @.

$n total, onl the 'ollo#in& operators are allo#ed to operate on arras and structures as #hole entities:

 'ield or method selector 

eCualit 33 43

assi&nment 3

inde2in& ?arras onl@ Z [

-he eCualit operators and assi&nment operator are onl allo#ed i' the t#o operands are same sie and

tpe. Structure tpes must be o' the same declared structure. =hen usin& the eCualit operators, t#o

structures are eCual i' and onl i' all the 'ields are component;#ise eCual, and t#o arras are eCual i' and

onl i' all the elements are element;#ise eCual.

rra elements are accessed usin& the arra subscript operator ? ) * @. n e2ample o' accessin& an arra

element is

diffuseHolor D+ lig(tIntensit9A;B NdotL-

rra indices start at ero. rra elements are accessed usin& an e2pression #hose tpe is int or uint.

"ehavior is unde'ined i' a shader subscripts an arra #ith an inde2 less than ) or &reater than or eCual to

the sie the arra #as declared #ith.

62

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 69/155

5 Operators and !pressions

rras can also be accessed #ith the method operator ? @ and the lengtB method to Cuer the sie o' the

arra:

lig(tIntensit9,lengt() && return t(e si"e of t(e arra9

'.4 ssignments

ssi&nments o' values to variable names are done #ith the assi&nment operator ? 3 @:

lvalue1expression + rvalue1expression

-he lvaluee(pression evaluates to an l;value. -he assi&nment operator stores the value o' rvalue

e(pression into the l;value and returns an r;value #ith the tpe and precision o' lvaluee(pression. -he

lvaluee(pression and rvaluee(pression must have the same tpe. n tpe;conversions must be

speci'ied e2plicitl via constructors. L;values must be #ritable. ariables that are built;in tpes, entire

structures or arras, structure 'ields, l;values #ith the 'ield selector ? @ applied to select components or

s#iles #ithout repeated 'ields, l;values #ithin parentheses, and l;values dere'erenced #ith the arra

subscript operator ? ) * @ are all l;values. Other binar or unar e2pressions, 'unction names, s#iles #ithrepeated 'ields, and constants cannot be l;values. -he ternar operator ?75@ is also not allo#ed as an l;

value.

E2pressions on the le't o' an assi&nment are evaluated be'ore e2pressions on the ri&ht o' the assi&nment.

-he other assi&nment operators are

• add into ?3@

• subtract 'rom ?-3@

• multipl into ?%3@

• divide into ?$3@

• modulus into ?&3@

• le't shi't b ?''3@

• ri&ht shi't b ?((3@

• and into ?13@

• inclusive;or into ?03@

• e2clusive;or into ?/3@

#here the &eneral e2pression

lvalue op+ expression

is eCuivalent to

  lvalue + lvalue op expression

#here op is as described belo#, and the l;value and e2pression must satis' the semantic reCuirements o'

 both op and eCuals ?3@.

63

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 70/155

5 Operators and !pressions

Readin& a variable be'ore #ritin& ?or initialiin&@ it is le&al, ho#ever the value is unde'ined.

'.5 E)pressions

E2pressions in the shadin& lan&ua&e are built 'rom the 'ollo#in&:

• %onstants o' tpe @ool, int, uint, float, all vector tpes, and all matri2 tpes.

• %onstructors o' all tpes.

• ariable names o' all tpes.

• n arra name #ith the len&th method applied.

• Subscripted arra names.

• 4unction calls that return values.

• %omponent 'ield selectors and arra subscript results.

• 3arenthesied e2pression. n e2pression can be parenthesied. 3arentheses can be used to &roupoperations. Operations #ithin parentheses are done be'ore operations across parentheses.

• -he arithmetic binar operators add ?@, subtract ?-@, multipl ?%@, and divide ?$@ operate on inte&er and

'loatin&;point scalars, vectors, and matrices. . $' the operands are inte&er tpes, the must both be

si&ned or both be unsi&ned. ll arithmetic binar operators result in the same 'undamental tpe

?si&ned inte&er, unsi&ned inte&er, or 'loatin&;point@ as the operands the operate on, a'ter operand tpe

conversion. 'ter conversion, the 'ollo#in& cases are valid

• -he t#o operands are scalars. $n this case the operation is applied, resultin& in a scalar.

• One operand is a scalar, and the other is a vector or matri2. $n this case, the scalar operation is

applied independentl to each component o' the vector or matri2, resultin& in the same sie vector

or matri2.

• -he t#o operands are vectors o' the same sie. $n this case, the operation is done component;#ise

resultin& in the same sie vector.

• -he operator is add ?@, subtract ?-@, or divide ?$@, and the operands are matrices #ith the same

number o' ro#s and the same number o' columns. $n this case, the operation is done component;

#ise resultin& in the same sie matri2.

• -he operator is multipl ?%@, #here both operands are matrices or one operand is a vector and the

other a matri2. ri&ht vector operand is treated as a column vector and a le't vector operand as a

ro# vector. $n all these cases, it is reCuired that the number o' columns o' the le't operand is eCual

to the number o' ro#s o' the ri&ht operand. -hen, the multipl ?%@ operation does a linear

al&ebraic multipl, ieldin& an obFect that has the same number o' ro#s as the le't operand and the

same number o' columns as the ri&ht operand. Section /.1) Iector and <atri2 Operations

e2plains in more detail ho# vectors and matrices are operated on.

ll other cases are ille&al.

64

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 71/155

5 Operators and !pressions

!ividin& b ero does not cause an e2ception but does result in an unspeci'ied value. 9se the built;in

'unctions dot, ross, matrixFompMult, and outerSrodut, to &et, respectivel, vector dot product,

vector cross product, matri2 component;#ise multiplication, and the matri2 product o' a column

vector times a ro# vector.

• -he operator modulus ?&@ operates on si&ned or unsi&ned inte&ers or inte&er vectors. -he operand

tpes must both be si&ned or both be unsi&ned. -he operands cannot be vectors o' di''erin& sie. $'

one operand is a scalar and the other vector, then the scalar is applied component;#ise to the vector,

resultin& in the same tpe as the vector. $' both are vectors o' the same sie, the result is computed

component;#ise. -he resultin& value is unde'ined 'or an component computed #ith a second

operand that is ero, #hile results 'or other components #ith non;ero second operands remain

de'ined. $' both operands are non;ne&ative, then the remainder is non;ne&ative. Results are

unde'ined i' one or both operands are ne&ative. -he operator modulus ?&@ is not de'ined 'or an

other data tpes ?non;inte&er tpes@.

• -he arithmetic unar operators ne&ate ?;@, post; and pre;increment and decrement ? -- and @ operate

on inte&er or 'loatin&;point values ?includin& vectors and matrices@. ll unar operators #or8

component;#ise on their operands. -hese result #ith the same tpe the operated on. 4or post; and

 pre;increment and decrement, the e2pression must be one that could be assi&ned to ?an l;value@. 3re;

increment and pre;decrement add or subtract 1 or 1.) to the contents o' the e2pression the operate on,

and the value o' the pre;increment or pre;decrement e2pression is the resultin& value o' that

modi'ication. 3ost;increment and post;decrement e2pressions add or subtract 1 or 1.) to the contents

o' the e2pression the operate on, but the resultin& e2pression has the e2pressions value be'ore the

 post;increment or post;decrement #as e2ecuted.

• -he relational operators &reater than ?(@, less than ?'@, &reater than or eCual ?(3@, and less than or

eCual ?'3@ operate onl on scalar inte&er and scalar 'loatin&;point e2pressions. -he result is scalar

"oolean. -he tpes o' the operands must match. -o do component;#ise relational comparisons on

vectors, use the built;in 'unctions lessTBan, lessTBanKJual, greaterTBan, and greaterTBanKJual

• -he eCualit operators eJual +33@, and not eCual ?43@ operate on all tpes. -he result in a scalar"oolean. -he tpes o' the operands must match. 4or vectors, matrices, structures, and arras, all

components, 'ields, or elements o' one operand must eCual the correspondin& components, 'ields, or

elements in the other operand 'or the operands to be considered eCual. -o &et a vector o' component;

#ise eCualit results 'or vectors, use the built;in 'unctions eJual and notKJual.

• -he lo&ical binar operators and ?11@, or ? 0 0 @, and e2clusive or ?//@ operate onl on t#o "oolean

e2pressions and result in a "oolean e2pression. nd ?11@ #ill onl evaluate the ri&ht hand operand

i' the le't hand operand evaluated to true. Or ? 0 0 @ #ill onl evaluate the ri&ht hand operand i' the le't

hand operand evaluated to false. E2clusive or ?//@ #ill al#as evaluate both operands.

• -he lo&ical unar operator not ?4@. $t operates onl on a "oolean e2pression and results in a "oolean

e2pression. -o operate on a vector, use the built;in 'unction not.

• -he seCuence ? , @ operator that operates on e2pressions b returnin& the tpe and value o' the ri&ht;most e2pression in a comma separated list o' e2pressions. ll e2pressions are evaluated, in order,

'rom le't to ri&ht.

65

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 72/155

5 Operators and !pressions

• -he ternar selection operator ?75@. $t operates on three e2pressions ?e(p1 7 e(p2 5 e(p3@. -his

operator evaluates the 'irst e2pression, #hich must result in a scalar "oolean. $' the result is true, it

selects to evaluate the second e2pression, other#ise it selects to evaluate the third e2pression. Onl

one o' the second and third e2pressions is evaluated. -he second and third e2pressions can be antpe, as lon& their tpes match. -his resultin& matchin& tpe is the tpe o' the entire e2pression.

• -he oneDs complement operator ?2 @. -he operand must be o' tpe si&ned or unsi&ned inte&er or inte&er

vector, and the result is the oneDs complement o' its operandM each bit o' each component is

complemented, includin& an si&n bits.

• -he shi't operators ?''@ and ?((@. 4or both operators, the operands must be si&ned or unsi&ned

inte&ers or inte&er vectors. One operand can be si&ned #hile the other is unsi&ned. $n all cases, the

resultin& tpe #ill be the same tpe as the le't operand. $' the 'irst operand is a scalar, the second

operand has to be a scalar as #ell. $' the 'irst operand is a vector, the second operand must be a scalar

or a vector #ith the same sie as the 'irst operand, and the result is computed component;#ise. -he

result is unde'ined i' the ri&ht operand is ne&ative, or &reater than or eCual to the number o' bits in the

le't e2pressionDs base tpe. -he value o' E1 E* is E1 ?interpreted as a bit pattern@ le't;shi'ted b

E* bits. -he value o' E1 HH E* is E1 ri&ht;shi'ted b E* bit positions. $' E1 is a si&ned inte&er, the

ri&ht;shi't #ill e2tend the si&n bit. $' E1 is an unsi&ned inte&er, the ri&ht;shi't #ill ero;e2tend.

• -he bit#ise operators and ?1@, e2clusive;or ?/@, and inclusive;or ?0@. -he operands must be o' tpe

si&ned or unsi&ned inte&ers or inte&er vectors. -he operands cannot be vectors o' di''erin& sie. $'

one operand is a scalar and the other a vector, the scalar is applied component;#ise to the vector,

resultin& in the same tpe as the vector. -he 'undamental tpes o' the operands ?si&ned or unsi&ned@

must match, and #ill be the resultin& 'undamental tpe. 4or and ?1@, the result is the bit#ise;and

'unction o' the operands. 4or e2clusive;or ?/@, the result is the bit#ise e2clusive;or 'unction o' the

operands. 4or inclusive;or ?0@, the result is the bit#ise inclusive;or 'unction o' the operands.

4or a complete speci'ication o' the snta2 o' e2pressions, see section 6 IShadin& Lan&ua&e Grammar.

'.10 (ector and 9atri) Operations=ith a 'e# e2ceptions, operations are component;#ise. 9suall, #hen an operator operates on a vector or

matri2, it is operatin& independentl on each component o' the vector or matri2, in a component;#ise

'ashion. 4or e2ample,

ve'; v0 u-

float f-

v + u D f-

#ill be eCuivalent to

v,x + u,x D f-

v,9 + u,9 D f-

v," + u," D f-

nd

ve'; v0 u0 .-

. + v D u-

66

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 73/155

5 Operators and !pressions

#ill be eCuivalent to

.,x + v,x D u,x-

.,9 + v,9 D u,9-

.," + v," D u,"-

and li8e#ise 'or most operators and all inte&er and 'loatin& point vector and matri2 tpes. -he e2ceptions

are matri2 multiplied b vector, vector multiplied b matri2, and matri2 multiplied b matri2. -hese do

not operate component;#ise, but rather per'orm the correct linear al&ebraic multipl.

ve'; v0 u-

mat; m-

u + v m-

is eCuivalent to

u,x + dotv0 mA=B)- && mA=B is t(e left 'olumn of m

u,9 + dotv0 mA<B)- && dota0$) is t(e inner dot) produ't of a and $u," + dotv0 mA8B)-

nd

u + m v-

is eCuivalent to

u,x + mA=B,x v,x D mA<B,x v,9 D mA8B,x v,"-

u,9 + mA=B,9 v,x D mA<B,9 v,9 D mA8B,9 v,"-

u," + mA=B," v,x D mA<B," v,9 D mA8B," v,"-

nd

mat; m0 n0 r-

r + m n-

is eCuivalent to

rA=B,x + mA=B,x nA=B,x D mA<B,x nA=B,9 D mA8B,x nA=B,"-

rA<B,x + mA=B,x nA<B,x D mA<B,x nA<B,9 D mA8B,x nA<B,"-

rA8B,x + mA=B,x nA8B,x D mA<B,x nA8B,9 D mA8B,x nA8B,"-

rA=B,9 + mA=B,9 nA=B,x D mA<B,9 nA=B,9 D mA8B,9 nA=B,"-

rA<B,9 + mA=B,9 nA<B,x D mA<B,9 nA<B,9 D mA8B,9 nA<B,"-

rA8B,9 + mA=B,9 nA8B,x D mA<B,9 nA8B,9 D mA8B,9 nA8B,"-

rA=B," + mA=B," nA=B,x D mA<B," nA=B,9 D mA8B," nA=B,"-rA<B," + mA=B," nA<B,x D mA<B," nA<B,9 D mA8B," nA<B,"-

rA8B," + mA=B," nA8B,x D mA<B," nA8B,9 D mA8B," nA8B,"-

and similarl 'or other sies o' vectors and matrices.

67

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 74/155

5 Operators and !pressions

'.11 Ealuation of e)pressions

-he % standard reCuires that e2pressions must be evaluated in the order speci'ied b the precedence o'

operations and ma onl be re&rouped i' the result is the same or #here the result is unde'ined. o other

trans'orms ma be applied that a''ect the result o' an operation. GLSL ES rela2es these reCuirements in

the 'ollo#in& #as:

• ddition and multiplication are assumed to be associative.

• <ultiplication ma be replaced b repeated addition

• 4loatin& point division ma be replaced b reciprocal and multiplication:

•   =ithin the constraints o' invariance ?#here applicable@, the precision used ma var.

68

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 75/155

Statements and Structure

-he 'undamental buildin& bloc8s o' the OpenGL ES Shadin& Lan&ua&e are:

• statements and declarations

• 'unction de'initions

• selection ?if-else and s?itB-ase-default

• iteration +for, ?Bile, and do-?Bile

•  Fumps +disard, return, @reaC, and ontinue@

-he overall structure o' a shader is as 'ollo#s

translationunit:

 glo)al#eclaration

translationunit glo)al#eclaration

 glo)al#eclaration:

 *unction#e*inition

#eclaration

-hat is, a shader is a seCuence o' declarations and 'unction bodies. 4unction bodies are de'ined as

 *unction#e*inition:

 *unctionprototype > statementlist ?

 statementlist:

 statement 

 statementlist statement 

 statement:

compoun#statement 

 simplestatement 

%url braces are used to &roup seCuences o' statements into compound statements.

compoun#statement:

> statementlist ? simplestatement:

#eclarationstatement 

e(pressionstatement 

 selectionstatement 

69

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 76/155

6 "tate#ents and "tructure

iterationstatement 

 ;umpstatement 

Simple declaration, e2pression, and Fump statements end in a semi;colon.

-his above is sli&htl simpli'ied, and the complete &rammar speci'ied in section 6 IShadin& Lan&ua&e

Grammar should be used as the de'initive speci'ication.

!eclarations and e2pressions have alread been discussed.

.1 +unction -efinitions

s indicated b the &rammar above, a valid shader is a seCuence o' &lobal declarations and 'unction

de'initions. 'unction is declared as the 'ollo#in& e2ample sho#s:

&& protot9pe

return9pe fun'tionName t9pe= arg=0 t9pe< arg<0 ,,,0 t9pen argn)-

and a 'unction is de'ined li8e

&& definition

return9pe fun'tionName t9pe= arg=0 t9pe< arg<0 ,,,0 t9pen argn)

*

  && do some 'omputation

  return returnValue-

2

#here returnType must be present and cannot be void.

or 

void fun'tionName t9pe= arg=0 t9pe< arg<0 ,,,0 t9pen argn)

*  && do some 'omputation

  return- && optional

2

. Each o' the type-  must include a tpe and can optionall include a parameter Cuali'ier and>or onst.

'unction is called b usin& its name 'ollo#ed b a list o' ar&uments in parentheses.

rras are allo#ed as ar&uments and as the return tpe. $n both cases, the arra must be e2plicitl sied.

n arra is passed or returned b usin& Fust its name, #ithout brac8ets, and the sie o' the arra must

match the sie speci'ied in the 'unctionDs declaration.

Structures are also allo#ed as ar&ument tpes. -he return tpe can also be a structure.

See section 6 IShadin& Lan&ua&e Grammar 'or the de'initive re'erence on the snta2 to declare andde'ine 'unctions.

ll 'unctions must be either declared #ith a prototpe or de'ined #ith a bod be'ore the are called. 4or

e2ample:

70

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 77/155

6 "tate#ents and "tructure

float m9fun' float f0 && f is an input parameter

  out float g)- && g is an output parameter

4unctions that return no value must be declared as void. void 'unction can onl use return #ithout a

return ar&ument, even i' the return ar&ument has void tpe. Return statements onl accept values:

void fun'<) * 2

void fun'8) * return fun'<)- 2 && illegal return statement

Onl a precision Cuali'ier is allo#ed on the return tpe o' a 'unction. 4ormal parameters can have

 parameter and precision Cuali'iers, but no other Cuali'iers.

4unctions that accept no input ar&uments need not use void in the ar&ument list because prototpes ?or

de'initions@ are reCuired and there'ore there is no ambi&uit #hen an empt ar&ument list _? @_ is declared.

-he idiom I?void@ as a parameter list is provided 'or convenience.

4unction names can be overloaded. -he same 'unction name can be used 'or multiple 'unctions, as lon&

as the parameter tpes di''er. $' a 'unction name is declared t#ice #ith the same parameter tpes, then thereturn tpes and all Cuali'iers must also match, and it is the same 'unction bein& declared. =hen 'unction

calls are resolved, an e2act tpe match 'or all the ar&uments is reCuired.

4or e2ample,

ve'7 fin ve'7 x0 out ve'7 9)-

ve'7 fin ve'7 x0 out ive'7 9)- && allo.ed0 different argument t9pe

int fin ve'7 x0 out ive'7 9)- && error0 onl9 return t9pe differs

ve'7 fin ve'7 x0 in ive'7 9)- && error0 onl9 ualifier differs

int f'onst in ve'7 x0 out ive'7 9)- && error0 onl9 ualifier differs

%allin& the 'irst t#o 'unctions above #ith the 'ollo#in& ar&ument tpes ields

fve'70 ve'7) && exa't mat'( of ve'7 fin ve'7 x0 out ve'7 9)fve'70 ive'7) && exa't mat'( of ve'7 fin ve'7 x0 out ive'7 9)

five'70 ve'7) && error0 no exa't mat'(,

five'70 ive'7) && error0 no exa't mat'(,

9ser;de'ined 'unctions can have multiple declarations, but onl one de'inition.

shader cannot rede'ine or overload built;in 'unctions.

-he 'unction main is used as the entr point to a shader e2ecutable. "oth the verte2 and 'ra&ment shaders

must de'ine a 'unction named main. -his 'unction ta8es no ar&uments, returns no value, and must be

declared as tpe void5

void main)

*

  ,,,

2

-he 'unction main can contain uses o' return. See section 7.+ IJumps 'or more details.

$t is an error to declare or de'ine a 'unction main #ith an other parameters or return tpe.

71

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 78/155

6 "tate#ents and "tructure

.1.1 +unction Calling Conentions

4unctions are called b value;return. -his means input ar&uments are copied into the 'unction at call time,

and output ar&uments are copied bac8 to the caller be'ore 'unction e2it. "ecause the 'unction #or8s #ith

local copies o' parameters, there are no issues re&ardin& aliasin& o' variables #ithin a 'unction. -o

control #hat parameters are copied in and>or out throu&h a 'unction de'inition or declaration:

• -he 8e#ord in is used as a Cuali'ier to denote a parameter is to be copied in, but not copied out.

• -he 8e#ord out is used as a Cuali'ier to denote a parameter is to be copied out, but not copied in.

-his should be used #henever possible to avoid unnecessaril copin& parameters in.

• -he 8e#ord inout is used as a Cuali'ier to denote the parameter is to be both copied in and copied

out.

• 'unction parameter declared #ith no such Cuali'ier means the same thin& as speci'in& in.

ll ar&uments are evaluated at call time, e2actl once, in order, 'rom le't to ri&ht. Evaluation o' an in

 parameter results in a value that is copied to the 'ormal parameter. Evaluation o' an out parameter results

in an l;value that is used to cop out a value #hen the 'unction returns. Evaluation o' an inout parameter

results in both a value and an l;valueM the value is copied to the 'ormal parameter at call time and the l;

value is used to cop out a value #hen the 'unction returns.

-he order in #hich output parameters are copied bac8 to the caller is unde'ined.

$n a 'unction, #ritin& to an input;onl parameter is allo#ed. Onl the 'unctions cop is modi'ied. -his

can be prevented b declarin& a parameter #ith the onst Cuali'ier.

=hen callin& a 'unction, e2pressions that do not evaluate to l;values cannot be passed to parameters

declared as out or inout.

 o Cuali'ier is allo#ed on the return tpe o' a 'unction.

 *unctionprototype: precisionuali*ier type *unctionname5constuali*ier parameteruali*ier precisionuali*ier

type name arrayspeci*ier$ ... 6

type:

an basic tpe, arra tpe, structure name, or structure #e*inition

constuali*ier:

empt

onst

 parameteruali*ier:

empt

in

out

inout

name:

empt

72

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 79/155

6 "tate#ents and "tructure

identi'ier 

arrayspeci*ier:

empt) constantintegrale(pression *

o#ever, the onst Cuali'ier cannot be used #ith out or inout. -he above is used 'or 'unction

declarations ?i.e., prototpes@ and 'or 'unction de'initions. ence, 'unction de'initions can have unnamed

ar&uments.

Static and dnamic recursion is not allo#ed Static recursion is present i' the static 'unction call &raph o'

the pro&ram contains ccles. !namic recursion occurs i' at an time control 'lo# has entered but not

e2ited a sin&le 'unction more than once.

.! Selection

%onditional control 'lo# in the shadin& lan&ua&e is done b either if , if ;else, or s?itB statements:

 selectionstatement:

if  ? )oole(pression @ statement 

if  ? )oole(pression @ statement else  statement 

s?itB ? inite(pression @ \ s/itchstatementlist opt  ]

=here s/itchstatementlist is a list o' ero or more s/itchstatement and other statements de'ined b the

lan&ua&e, #here s/itchstatement adds some 'orms o' labels. -hat is

 s/itchstatementlist:

 s/itchstatement 

 s/itchstatementlist s/itchstatement 

 s/itchstatement:

ase constante(pression:

default 5

 statement 

$' an if-e2pression evaluates to true, then the 'irst statement  is e2ecuted. $' it evaluates to false and there

is an else part then the second statement  is e2ecuted.

n e2pression #hose tpe evaluates to a "oolean can be used as the conditional e2pression )ool

e(pression. ector tpes are not accepted as the e2pression to if .

%onditionals can be nested.

73

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 80/155

6 "tate#ents and "tructure

-he tpe o' inite(pression in a s#itch statement must be a scalar inte&er. $' a ase label has a constant

e(pression o' eCual value, then e2ecution #ill continue a'ter that label. Other#ise, i' there is a default 

label, e2ecution #ill continue a'ter that label. Other#ise, e2ecution s8ips the rest o' the s#itch statement.

$t is an error to have more than one default or a replicated constante(pression. @reaC  statement notnested in a loop or other s#itch statement ?either not nested or nested onl in if  or if ;else statements@ #ill

also s8ip the rest o' the s#itch statement. 4all throu&h labels are allo#ed, but it is an error to have no

statement bet#een a label and the end o' the s?itB statement. o statements are allo#ed in a s#itch

statement be'ore the 'irst ase statement.

 o ase or default labels can be nested inside other control 'lo# nested #ithin their correspondin&

s?itB.

.3 Iteration

4or, #hile, and do loops are allo#ed as 'ollo#s:

for init1expression- 'ondition1expression- loop1expression)

  su$1statement

.(ile 'ondition1expression)

  su$1statement

do

  statement

.(ile 'ondition1expression)

See section 6 IShadin& Lan&ua&e Grammar 'or the de'initive speci'ication o' loops.

-he for loop 'irst evaluates the inite(pression, then the con#itione(pression. $' the con#ition

e(pression evaluates to true, then the bod o' the loop is e2ecuted. 'ter the bod is e2ecuted, a for loop

#ill then evaluate the loope(pression, and then loop bac8 to evaluate the con#itione(pression, repeatin&

until the con#itione(pression evaluates to 'alse. -he loop is then e2ited, s8ippin& its bod and s8ippin&

its loope(pression. ariables modi'ied b the loope(pression maintain their value a'ter the loop is

e2ited, provided the are still in scope. ariables declared in inite(pression or con#itione(pression are

onl in scope until the end o' the sub;statement o' the for loop.

-he ?Bile loop 'irst evaluates the con#itione(pression. $' true, then the bod is e2ecuted. -his is then

repeated, until the con#itione(pression evaluates to 'alse, e2itin& the loop and s8ippin& its bod.

ariables declared in the con#itione(pression are onl in scope until the end o' the sub;statement o' the

#hile loop.

4or both for and ?Bile loops, the sub;statement does not introduce a ne# scope 'or variable names, so the

'ollo#in& has a redeclaration error:

for int i + =- i / <=- iDD) *

  int i- && rede'laration error

]

-he do-?Bile loop 'irst e2ecutes the bod, then e2ecutes the con#itione(pression. -his is repeated until

con#itione(pression evaluates to 'alse, and then the loop is e2ited.

74

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 81/155

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 82/155

6 "tate#ents and "tructure

-he 'unction main can use return. -his simpl causes main to e2it in the same #a as #hen the end o'

the 'unction had been reached. $t does not impl a use o' disard in a 'ra&ment shader. 9sin& return in

main be'ore de'inin& outputs #ill have the same behavior as reachin& the end o' main be'ore de'inin&

outputs.

76

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 83/155

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 84/155

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 85/155

7 Built$in Variables

&& Implementation dependent 'onstants, (e example values $elo.

&& are t(e minimum values allo.ed for t(ese maximums,

&&

'onst mediump int gl_@axVertex?ttri$s + <-

'onst mediump int gl_@axVertexKniformVe'tors + 8>-

'onst mediump int gl_@axVertexOutputVe'tors + <-

'onst mediump int gl_@axFragmentInputVe'tors + <>-

'onst mediump int gl_@axVertexextureImageKnits + <-

'onst mediump int gl_@axHom$inedextureImageKnits + ;8-

'onst mediump int gl_@axextureImageKnits + <-

'onst mediump int gl_@axFragmentKniformVe'tors + 887-

'onst mediump int gl_@ax!ra.5uffers + 7-

'onst mediump int gl_@inCrogramexelOffset + 1M-

'onst mediump int gl_@axCrogramexelOffset + -

2.% ,uilt8In 6niform States an aid to accessin& OpenGL ES processin& state, the 'ollo#in& uni'orm variables are built into the

OpenGL ES Shadin& Lan&ua&e.

&&

&& !ept( range in .indo. 'oordinates0

&& se'tion 8,<;,< 3Hontrolling t(e Vie.port4 in t(e

&& OpenGL ES Grap(i's S9stem Spe'ifi'ation,

&&

stru't gl_!ept(RangeCarameters *

  (ig(p float near- && n

  (ig(p float far- && f

  (ig(p float diff- && f 1 n

2-uniform gl_!ept(RangeCarameters gl_!ept(Range-

79

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 86/155

4 ,uilt8in +unctions

-he OpenGL ES Shadin& Lan&ua&e de'ines an assortment o' built;in convenience 'unctions 'or scalar and

vector operations. <an o' these built;in 'unctions can be used in more than one tpe o' shader, but some

are intended to provide a direct mappin& to hard#are and so are available onl 'or a speci'ic tpe o'

shader.

-he built;in 'unctions basicall 'all into three cate&ories:

• -he e2pose some necessar hard#are 'unctionalit in a convenient #a such as accessin& a te2ture

map. -here is no #a in the lan&ua&e 'or these 'unctions to be emulated b a shader.

• -he represent a trivial operation ?clamp, mi2, etc.@ that is ver simple 'or the user to #rite, but the

are ver common and ma have direct hard#are support. $t is a ver hard problem 'or the compiler tomap e2pressions to comple2 assembler instructions.

• -he represent an operation &raphics hard#are is li8el to accelerate at some point. -he tri&onometr

'unctions 'all into this cate&or.

<an o' the 'unctions are similar to the same named ones in common % libraries, but the support vector

input as #ell as the more traditional scalar input.

pplications should be encoura&ed to use the built;in 'unctions rather than do the eCuivalent computations

in their o#n shader code since the built;in 'unctions are assumed to be optimal ?e.&., perhaps supported

directl in hard#are@.

=hen the built;in 'unctions are speci'ied belo#, #here the input ar&uments ?and correspondin& output@

can be float, veD, ve8, or veE, genType is used as the ar&ument. =here the input ar&uments ?andcorrespondin& output@ can be int, iveD, ive8, or iveE, gen,Type is used as the ar&ument. =here the

input ar&uments ?and correspondin& output@ can be uint, uveD, uve8, or uveE, genAType is used as the

ar&ument. =here the input ar&uments ?or correspondin& output@ can be @ool, @veD, @ve8, or @veE,

 genBType is used as the ar&ument. 4or an speci'ic use o' a 'unction, the actual tpes substituted 'or

 genType, gen,Type, genAType$ or genBType  have to have the same number o' components 'or all

ar&uments and 'or the return tpe. Similarl 'or mat$ #hich can be an matri2 basic tpe.

-he precision o' built;in 'unctions is dependent on the 'unction and ar&uments. -here are three

cate&ories:

• Some 'unctions have prede'ined precisions. -he precision is speci'ied

e.&.

hi&hp vec* texture;ize ?&sampler*! sampler , int lo# @• 4or the te2ture samplin& 'unctions, the precision o' the return tpe matches the precision o' the

sampler tpe.

80

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 87/155

8 Built$in %unctions

uniform lo.p sampler8! sampler-

(ig(p ve'8 'oord-

,,,

lo.p ve'7 'ol + texture sampler0 'oord)- && texture) returns lo.p

• 4or other built;in 'unctions, a call #ill return a precision Cuali'ication matchin& the hi&hest precision

Cuali'ication o' the callDs input ar&uments. See Section +./.* I3recision Quali'iers 'or more detail.

-he built;in 'unctions are assumed to be implemented accordin& to the eCuations speci'ied in the

'ollo#in& sections. -he precision at #hich the calculations are per'ormed 'ollo#s the &eneral rules 'or

 precision o' operations as speci'ied in section +./.( I3recision Quali'iersI.

E2ample:

normali1e   y  =   y

$' the input vector is lo#p, the entire calculation is per'ormed at lo#p. 4or some inputs, this #ill cause

the calculation to over'lo#, even #hen the correct result is #ithin the ran&e o' lo#p.

81

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 88/155

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 89/155

8 Built$in %unctions

S&nta) -escription

&en-pe sinB ?&en-pe (@ Returns the hperbolic sine 'unction

e (−e

− (

*

&en-pe osB ?&en-pe (@ Returns the hperbolic cosine 'unction

e (e

− (

*

&en-pe tanB ?&en-pe (@ Returns the hperbolic tan&ent 'unctionsinh  (

cosh  (

&en-pe asinB ?&en-pe (@ rc hperbolic sineM returns the inverse o' sinB.

&en-pe aosB ?&en-pe (@ rc hperbolic cosineM returns the non;ne&ative inverseo' osB. Results are unde'ined i' ( 1.

&en-pe atanB ?&en-pe (@ rc hperbolic tan&entM returns the inverse o' tanB.Results are unde'ined i'    ∣ (∣≥1.

4.! E)ponential +unctions

-hese all operate component;#ise. -he description is per component.

S&nta) -escription

&en-pe po? ?&en-pe (, &en-pe y@ Returns ( raised to the y po#er, i.e.,   ( y

Results are unde'ined i' ( C 0.

Results are unde'ined i' ( = 0 and y C= 0.

&en-pe exp ?&en-pe (@ Returns the natural e2ponentiation o' (, i.e., e (.

&en-pe log ?&en-pe (@ Returns the natural lo&arithm o' ($ i.e., returns the value y #hich satis'ies the eCuation ( T e y.

Results are unde'ined i' ( C= 0.

&en-pe expD ?&en-pe (@ Returns * raised to the ( po#er, i.e., * (

&en-pe logD ?&en-pe (@ Returns the base * lo&arithm o' ($ i.e., returns the value

 y #hich satis'ies the eCuation  (=*

 y

Results are unde'ined i' ( C= 0.

83

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 90/155

8 Built$in %unctions

S&nta) -escription

&en-pe sJrt ?&en-pe (@ Returns   ( .

Results are unde'ined i' ( C 0.

&en-pe inversesJrt ?&en-pe (@Returns

1

√  (.

Results are unde'ined i' ( C= 0.

4.3 Common +unctions

-hese all operate component;#ise. -he description is per component.

S&nta) -escription

&en-pe a@s ?&en-pe (@&en$-pe a@s ?&en$-pe (@

Returns ( i' ( HT ), other#ise it returns ^  (.

&en-pe sign ?&en-pe (@&en$-pe sign ?&en$-pe (@

Returns 1.) i' ( H ), ).) i' ( T ), or ^1.) i' (  ).

&en-pe floor ?&en-pe (@ Returns a value eCual to the nearest inte&er that is lessthan or eCual to (.

&en-pe trun ?&en-pe (@ Returns a value eCual to the nearest inte&er to ( #hoseabsolute value is not lar&er than the absolute value o' (.

&en-pe round ?&en-pe (@ Returns a value eCual to the nearest inte&er to (. -he'raction )./ #ill round in a direction chosen b theimplementation, presumabl the direction that is 'astest.-his includes the possibilit that round? (@ returns thesame value as roundKven? (@ 'or all values o' (.

&en-pe roundKven ?&en-pe (@ Returns a value eCual to the nearest inte&er to (. 'ractional part o' )./ #ill round to#ard the nearest eveninte&er. ?"oth (./ and +./ 'or 2 #ill return +.).@

&en-pe eil ?&en-pe (@ Returns a value eCual to the nearest inte&er that is

&reater than or eCual to (.

&en-pe frat ?&en-pe (@ Returns ( ^ floor ? (@.

84

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 91/155

8 Built$in %unctions

S&nta) -escription

&en-pe mod ?&en-pe (, 'loat y@&en-pe mod ?&en-pe (, &en-pe y@

<odulus. Returns ( ^ y ∗ floor ? (> y@.

&en-pe modf  ?&en-pe (, out &en-pe i@ Returns the 'ractional part o' ( and sets i to the inte&er part ?as a #hole number 'loatin& point value@. "oth thereturn value and the output parameter #ill have the samesi&n as (.

&en-pe min ?&en-pe (, &en-pe y@&en-pe min ?&en-pe (, 'loat y@&en$-pe min ?&en$-pe (, &en$-pe y@&en$-pe min ?&en$-pe (, int y@&en9-pe min ?&en9-pe (, &en9-pe y@

&en9-pe min ?&en9-pe (, uint y@

Returns y i' y  (, other#ise it returns (.

&en-pe max ?&en-pe (, &en-pe y@&en-pe max ?&en-pe (, 'loat y@&en$-pe max ?&en$-pe (, &en$-pe y@&en$-pe max ?&en$-pe (, int y@&en9-pe max ?&en9-pe (, &en9-pe y@&en9-pe max ?&en9-pe (, uint y@

Returns y i' (  y, other#ise it returns (.

&en-pe lamp ?&en-pe (,  &en-pe minVal ,  &en-pe ma(Val @&en-pe lamp ?&en-pe (,

'loat minVal ,'loat ma(Val @

&en$-pe lamp ?&en$-pe (,  &en$-pe minVal ,  &en$-pe ma(Val @&en$-pe lamp ?&en$-pe (,  int minVal ,  int ma(Val @

&en9-pe lamp ?&en9-pe (,  &en9-pe minVal ,  &en9-pe ma(Val @&en9-pe lamp ?&en9-pe (,  uint minVal ,

  uint ma(Val @

Returns min ?max ? (, minVal @, ma(Val @.

Results are unde'ined i' minVal H ma(Val .

85

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 92/155

8 Built$in %unctions

S&nta) -escription

&en-pe mix ?&en-pe (,  &en-pe y,  &en-pe a@&en-pe mix ?&en-pe (,  &en-pe y,  'loat a@

Returns the linear blend o' ( and y$ i.e., (⋅1−a  y⋅a

&en-pe mix ?&en-pe (,  &en-pe ,  &en"-pe a@

Selects #hich vector each returned component comes

'rom. 4or a component o' a that is false, the

correspondin& component o' ( is returned. 4or a

component o' a that is true, the correspondin&

component o' y is returned. %omponents o' ( and y that

are not selected are allo#ed to be invalid 'loatin& point

values and #ill have no e''ect on the results. -hus, this

 provides di''erent 'unctionalit than

&en-pe mix?&en-pe (, &en-pe y, &en-pe?a@@

#here a is a "oolean vector.

&en-pe step ?&en-pe e#ge, &en-pe (@&en-pe step ?'loat e#ge, &en-pe (@

Returns ).) i' (  e#ge, other#ise it returns 1.).

&en-pe smootBstep ?&en-pe e#ge0,&en-pe e#ge1,&en-pe (@

&en-pe smootBstep ?'loat e#ge0,'loat e#ge1,&en-pe (@

Returns ).) i' ( T e#ge0 and 1.) i' ( HT e#ge1 and per'orms smooth ermite interpolation bet#een ) and 1#hen e#ge0  (  e#ge1. -his is use'ul in cases #hereou #ould #ant a threshold 'unction #ith a smoothtransition. -his is eCuivalent to:

  &en-pe tM

  t T clamp ??2 ^ ed&e)@ > ?ed&e1 ^ ed&e)@, ), 1@M  return t t ?( ^ * t@M

 Results are un#e*ine# i* e#ge0 = e#ge1.

&en"-pe isnan ?&en-pe (@ Returns true i' ( holds a a. Returns false other#ise.

&en"-pe isinf  ?&en-pe (@ Returns true i' ( holds a positive in'init or ne&ative

in'init. Returns false other#ise.

86

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 93/155

8 Built$in %unctions

S&nta) -escription

&en$-pe floatHitsToNnt ?&en-pe value@&en9-pe floatHitsToUint ?&en-pe value@

Returns a si&ned or unsi&ned hi&hp inte&er value

representin& the encodin& o' a 'loatin&;point value. 4orhi&hp 'loatin& point, the valueDs bit level representation

is preserved. 4or mediump and lo#p, the value is 'irst

converted to hi&hp 'loatin& point and the encodin& o'

that value is returned.

&en-pe intHitsToLloat ?&en$-pe value@&en-pe uintHitsToLloat ?&en9-pe value@

Returns a hi&hp 'loatin&;point value correspondin& to a

si&ned or unsi&ned inte&er encodin& o' a 'loatin&;point

value. $' an in' or a is passed in, it #ill not si&nal,

and the resultin& 'loatin& point value is unspeci'ied.

Other#ise, the bit;level representation is preserved. 4or

lo#p and mediump, the value is 'irst converted to the

correspondin& si&ned or unsi&ned hi&hp inte&er and thenreinterpreted as a hi&hp 'loatin& point value as be'ore.

87

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 94/155

8 Built$in %unctions

4.% +loating8*oint *ac and 6npac +unctions

-hese 'unctions do not operate component;#ise, rather as described in each case.

S&nta) -escription

hi&hp uint paC;normDxGY ?vec* v@ 4irst, converts each component o' the normalied'loatin&;point value v into 17;bit inte&er values. -hen,the results are pac8ed into the returned (*;bit unsi&nedinte&er.-he conversion 'or component c o' v to 'i2ed point isdone as 'ollo#s:

paC;normDxGY: round?clamp?c, ;1, 1@ (*070.)@

-he 'irst component o' the vector #ill be #ritten to theleast si&ni'icant bits o' the outputM the last component#ill be #ritten to the most si&ni'icant bits.

hi&hp vec* unpaC;normDxGY ?hi&hp uint p@

4irst, unpac8s a sin&le (*;bit unsi&ned inte&er p into a

 pair o' 17;bit unsi&ned inte&ers. -hen, each component

is converted to a normalied 'loatin&;point value to

&enerate the returned t#o;component vector.

-he conversion 'or unpac8ed 'i2ed;point value * to'loatin& point is done as 'ollo#s:

unpaC;normDxGY5  clamp? *  > (*070.), ;1,1@

-he 'irst component o' the returned vector #ill be

e2tracted 'rom the least si&ni'icant bits o' the inputM thelast component #ill be e2tracted 'rom the mostsi&ni'icant bits.

hi&hp uint paCUnormDxGY ?vec* v@ 4irst, converts each component o' the normalied

'loatin&;point value v into 17;bit inte&er values. -hen,

the results are pac8ed into the returned (*;bit unsi&ned

inte&er.

-he conversion 'or component c o' v to 'i2ed point isdone as 'ollo#s:

paCUnormDxGY: round?clamp?c, ), 1@ 7//(/.)@

-he 'irst component o' the vector #ill be #ritten to theleast si&ni'icant bits o' the outputM the last component#ill be #ritten to the most si&ni'icant bits.

88

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 95/155

8 Built$in %unctions

S&nta) -escription

hi&hp vec* unpaCUnormDxGY ?hi&hp uint p@

4irst, unpac8s a sin&le (*;bit unsi&ned inte&er p into a

 pair o' 17;bit unsi&ned inte&ers. -hen, each componentis converted to a normalied 'loatin&;point value to

&enerate the returned t#o;component vector.

-he conversion 'or unpac8ed 'i2ed;point value * to'loatin& point is done as 'ollo#s:

unpaCUnormDxGY5   *  > 7//(/.)

-he 'irst component o' the returned vector #ill bee2tracted 'rom the least si&ni'icant bits o' the inputM thelast component #ill be e2tracted 'rom the mostsi&ni'icant bits.

hi&hp uint paCalfDxGY ?mediump vec* v@ Returns an unsi&ned inte&er obtained b convertin& thecomponents o' a t#o;component 'loatin&;point vector tothe 17;bit 'loatin&;point representation 'ound in theOpenGL ES Speci'ication, and then pac8in& these t#o17;bit inte&ers into a (*;bit unsi&ned inte&er.

-he 'irst vector component speci'ies the 17 least;si&ni'icant bits o' the resultM the second componentspeci'ies the 17 most;si&ni'icant bits.

mediump vec* unpaCalfDxGY ?hi&hp uintv@

Returns a t#o;component 'loatin&;point vector #ithcomponents obtained b unpac8in& a (*;bit unsi&nedinte&er into a pair o' 17;bit values, interpretin& those

values as 17;bit 'loatin&;point numbers accordin& to theOpenGL ES Speci'ication, and convertin& them to (*;bit'loatin&;point values.

-he 'irst component o' the vector is obtained 'rom the17 least;si&ni'icant bits o' vM the second component isobtained 'rom the 17 most;si&ni'icant bits o' v.

4.' Geometric +unctions

-hese operate on vectors as vectors, not component;#ise.

S&nta) -escription

'loat lengtB ?&en-pe (@ Returns the len&th o' vector (, i.e.,

  ([)]* ([1]

*...

89

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 96/155

8 Built$in %unctions

S&nta) -escription

'loat distane ?&en-pe p0, &en-pe p1@ Returns the distance bet#een p0 and p1, i.e.,lengtB ? p0 E p1@

'loat dot ?&en-pe (, &en-pe y@ Returns the dot product o' ( and y, i.e., ( [)]⋅ y [) ]+ ( [1]⋅ y [1 ]+...

vec( ross ?vec( (, vec( y@ Returns the cross product o' 2 and , i.e.,

[ ( [1]⋅ y[*]− y [1 ]⋅ ( [* ] ([* ]⋅ y[)]− y [*]⋅ ([)] ( [) ]⋅ y [1]− y [) ]⋅ ( [1 ]]

&en-pe normalize ?&en-pe (@ Returns a vector in the same direction as ( but #ith a

len&th o' 1 i.e.

  (

length( ()

&en-pe faefor?ard?&en-pe - ,  &en-pe , ,  &en-pe -re* @

$' dot? -re* , , @ ) return -$ other#ise return ^  -.

&en-pe reflet ?&en-pe , , &en-pe - @ 4or the incident vector ,  and sur'ace orientation - ,returns the re'lection direction:

 ,  ^ * ∗ dot? - , , @ ∗ - 

 -  must alread be normalied in order to achieve the

desired result.

&en-pe refrat?&en-pe , , &en-pe - ,  'loat eta@

4or the incident vector ,  and sur'ace normal - , and theratio o' indices o' re'raction eta$ return the re'ractionvector. -he result is computed b

8 T 1.) ; eta  eta  ?1.) ; dot? - , , @ dot? - , , @@i' ?8 ).)@

return &en-pe?).)@else

return eta  ,  ; ?eta  dot? - , , @ sJrt?8@@  - 

-he input parameters 'or the incident vector ,  and the

sur'ace normal -  must alread be normalied to &et thedesired results.

90

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 97/155

8 Built$in %unctions

4. 9atri) +unctions

S&nta) -escription

mat matrixFompMult ?mat (, mat y@ <ultipl matri2 ( b matri2 y component;#ise, i.e.,resultZi[ZF[ is the scalar product o' (Zi[ZF[ and  yZi[ZF[.

 ote: to &et linear al&ebraic matri2 multiplication, usethe multipl operator ?%@.

mat* outerSrodut?vec* c, vec* r @mat( outerSrodut?vec( c, vec( r @mat+ outerSrodut?vec+ c, vec+ r @

mat*2( outerSrodut?vec( c, vec* r @mat(2* outerSrodut?vec* c, vec( r @

mat*2+ outerSrodut?vec+ c, vec* r @mat+2* outerSrodut?vec* c, vec+ r @

mat(2+ outerSrodut?vec+ c, vec( r @mat+2( outerSrodut?vec( c, vec+ r @

-reats the 'irst parameter c as a column vector ?matri2#ith one column@ and the second parameter r  as a ro#vector ?matri2 #ith one ro#@ and does a linear al&ebraicmatri2 multipl c  r , ieldin& a matri2 #hose number o'ro#s is the number o' components in c and #hosenumber o' columns is the number o' components in r .

mat* transpose?mat* m@mat( transpose?mat( m@mat+ transpose?mat+ m@

mat*2( transpose?mat(2* m@mat(2* transpose?mat*2( m@

mat*2+ transpose?mat+2* m@mat+2* transpose?mat*2+ m@

mat(2+ transpose?mat+2( m@mat+2( transpose?mat(2+ m@

Returns a matri2 that is the transpose o' m. -he inputmatri2 m is not modi'ied.

'loat determinant?mat* m@'loat determinant?mat( m@'loat determinant?mat+ m@

Returns the determinant o' m.

mat* inverse?mat* m@mat( inverse?mat( m@mat+ inverse?mat+ m@

Returns a matri2 that is the inverse o' m. -he inputmatri2 m is not modi'ied. -he values in the returnedmatri2 are unde'ined i' m is sin&ular or poorl;conditioned ?nearl sin&ular@.

91

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 98/155

8 Built$in %unctions

4.2 (ector :elational +unctions

Relational and eCualit operators ?', '3, (, (3, 33, 43@ are de'ined to produce scalar "oolean results. 4or

vector results, use the 'ollo#in& built;in 'unctions. "elo#, Ibvec is a placeholder 'or one o' @veD, @ve8, or @veE, Iivec is a placeholder 'or one o' iveD, ive8, or iveE, Iuvec is a placeholder 'or

uveD, uve8, or uveE, and Ivec is a placeholder 'or veD, ve8, or veE. $n all cases, the sies o' the

input and return vectors 'or an particular call must match.

S&nta) -escription

 bvec lessTBan?vec 2, vec @ bvec lessTBan?ivec 2, ivec @ bvec lessTBan?uvec 2, uvec @

Returns the component;#ise compare o' (  y.

 bvec lessTBanKJual?vec 2, vec @ bvec lessTBanKJual?ivec 2, ivec @

 bvec lessTBanKJual?uvec 2, uvec @

Returns the component;#ise compare o' ( T y.

 bvec greaterTBan?vec 2, vec @ bvec greaterTBan?ivec 2, ivec @ bvec greaterTBan?uvec 2, uvec @

Returns the component;#ise compare o' ( H y.

 bvec greaterTBanKJual?vec 2, vec @ bvec greaterTBanKJual?ivec 2, ivec @ bvec greaterTBanKJual?uvec 2, uvec @

Returns the component;#ise compare o' ( HT y.

 bvec eJual?vec 2, vec @ bvec eJual?ivec 2, ivec @ bvec eJual?uvec 2, uvec @ bvec eJual?bvec 2, bvec @

 bvec notKJual?vec 2, vec @ bvec notKJual?ivec 2, ivec @ bvec notKJual?uvec 2, uvec @ bvec notKJual?bvec 2, bvec @

Returns the component;#ise compare o' ( TT y.

Returns the component;#ise compare o' ( T y.

 bool any?bvec 2@ Returns true i' an component o' ( is true.

 bool all?bvec 2@ Returns true onl i' all components o' ( are true.

 bvec not?bvec 2@ Returns the component;#ise lo&ical complement o' (.

92

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 99/155

8 Built$in %unctions

4.4 Te)ture Looup +unctions

-e2ture loo8up 'unctions are available to verte2 and 'ra&ment shaders. o#ever, level o' detail is not

implicitl computed 'or verte2 shaders. -he 'unctions in the table belo# provide access to te2turesthrou&h samplers, as set up throu&h the OpenGL ES 3$. -e2ture properties such as sie, pi2el 'ormat,

number o' dimensions, 'ilterin& method, number o' mip;map levels, depth comparison, and so on are also

de'ined b OpenGL ES 3$ calls. Such properties are ta8en into account as the te2ture is accessed via the

 built;in 'unctions de'ined belo#.

-e2ture data can be stored b the GL as 'loatin& point, unsi&ned normalied inte&er, unsi&ned inte&er or

si&ned inte&er data. -his is determined b the tpe o' the internal 'ormat o' the te2ture. -e2ture loo8ups

on unsi&ned normalied inte&er and 'loatin& point data return 'loatin& point values in the ran&e Z), 1[.

-e2ture loo8up 'unctions are provided that can return their result as 'loatin& point, unsi&ned inte&er or

si&ned inte&er, dependin& on the sampler tpe passed to the loo8up 'unction. %are must be ta8en to use

the ri&ht sampler tpe 'or te2ture access. -he 'ollo#in& table lists the supported combinations o' sampler

tpes and te2ture internal 'ormats. "lan8 entries are unsupported. !oin& a te2ture loo8up #ill return

unde'ined values 'or unsupported combinations.

$nternal -e2ture 4ormat4loatin& 3oint

Sampler -pes

Si&ned $nte&er

Sampler -pes

9nsi&ned $nte&er

Sampler -pes

4loatin& point Supported

 ormalied $nte&er Supported

Si&ned $nte&er Supported

9nsi&ned $nte&er Supported

$' an inte&er sampler tpe is used, the result o' a te2ture loo8up is an iveE. $' an unsi&ned inte&er

sampler tpe is used, the result o' a te2ture loo8up is a uveE. $' a 'loatin& point sampler tpe is used, the

result o' a te2ture loo8up is a veE, #here each component is in the ran&e Z), 1[.

$n the prototpes belo#, the I g  in the return tpe I gvec is used as a placeholder 'or nothin&, Ii, or Iu

ma8in& a return tpe o' veE, iveE, or uveE. $n these cases, the sampler ar&ument tpe also starts #ith

I g , indicatin& the same substitution done on the return tpeM it is either a 'loatin& point, si&ned inte&er, or

unsi&ned inte&er sampler, matchin& the basic tpe o' the return tpe, as described above.

4or shado# 'orms ?the sampler parameter is a shado#;tpe@, a depth comparison loo8up on the depth

te2ture bound to sampler is done as described in section (.5.17 I-e2ture %omparison <odes o' the

OpenGL ES Graphics Sstem Speci'ication. See the table belo# 'or #hich component speci'ies Dre* . -he

te2ture bound to sampler  must be a depth te2ture, or results are unde'ined. $' a non;shado# te2ture call is

made to a sampler that represents a depth te2ture #ith depth comparisons turned on, then results areunde'ined. $' a shado# te2ture call is made to a sampler that represents a depth te2ture #ith depth

comparisons turned o'', then results are unde'ined. $' a shado# te2ture call is made to a sampler that does

not represent a depth te2ture, then results are unde'ined.

93

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 100/155

8 Built$in %unctions

$n all 'unctions belo#, the )ias parameter is optional 'or 'ra&ment shaders. -he )ias parameter is not

accepted in a verte2 shader. 4or a 'ra&ment shader, i' )ias is present, it is added to the implicit level o'

detail prior to per'ormin& the te2ture access operation.

-he implicit level o' detail is selected as 'ollo#s: 4or a te2ture that is not mip;mapped, the te2ture is used

directl. $' it is mip;mapped and runnin& in a 'ra&ment shader, the LO! computed b the implementation

is used to do the te2ture loo8up. $' it is mip;mapped and runnin& on the verte2 shader, then the base

te2ture is used.

Some te2ture 'unctions ?non;I>od and non;I=rad versions@ ma reCuire implicit derivatives. $mplicit

derivatives are unde'ined #ithin non;uni'orm control 'lo# and 'or verte2 te2ture 'etches.

4or Fu@e 'orms, the direction o' '  is used to select #hich 'ace to do a *;dimensional te2ture loo8up in, as

described in section (.5.1) I%ube <ap -e2ture Selection in the OpenGL ES Graphics Sstem

Speci'ication.

4or Array 'orms, the arra laer used #ill be

ma( ),min # −1,   *loor layer )./#here # is the depth o' the te2ture arra and layer comes 'rom the component indicated in the tables

 belo#.

94

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 101/155

8 Built$in %unctions

S&nta) -escription

 hi&hp vec* texture;ize ?&sampler*! sampler , int lo# @hi&hp vec( texture;ize ?&sampler(! sampler , int lo# @hi&hp vec* texture;ize ?&sampler%ube sampler , int lo# @ hi&hp vec* texture;ize ?sampler*!Shado# sampler , int lo# @hi&hp vec* texture;ize ?sampler%ubeShado# sampler , int lo# @

hi&hp vec( texture;ize ?&sampler*!rra sampler , int lo# @

hi&hp vec( texture;ize ?sampler*!rraShado# sampler , int lo# @

Returns the dimensions o'level lo# 'or the te2ture boundto sampler , as described insection *.11.6 IShaderE2ecution o' the OpenGL ES(.) Graphics SstemSpeci'ication, under I-e2tureSie Quer.

-he components in the returnvalue are 'illed in, in order,#ith the #idth, hei&ht, depth o'the te2ture.

4or the arra 'orms, the lastcomponent o' the return valueis the number o' laers in thete2ture arra.

&vec+ texture ?&sampler*! sampler , vec* ' Z, 'loat )ias[ @&vec+ texture ?&sampler(! sampler , vec( ' Z, 'loat )ias[ @&vec+ texture ?&sampler%ube sampler , vec( ' Z, 'loat )ias[ @ 'loat texture ?sampler*!Shado# sampler$ vec( ' Z, 'loat )ias[ @

  'loat texture ?sampler%ubeShado# sampler$ vec+ ' Z, 'loat )ias[ @

&vec+ texture ?&sampler*!rra sampler , vec( ' Z, 'loat )ias[ @ 'loat texture ?sampler*!rraShado#  sampler$ vec+ ' @

9se the te2ture coordinate ' todo a te2ture loo8up in thete2ture currentl bound to

 sampler . -he last componento'  ' is used as Dre*   'or theshado# 'orms. 4or arra'orms, the arra laer comes'rom the last component o' '  in the non;shado# 'orms, andthe second to last componento' '  in the shado# 'orms.

&vec+ textureSroI ?&sampler*! sampler , vec( ' Z, 'loat )ias[ @&vec+ textureSroI ?&sampler*! sampler , vec+ ' Z, 'loat )ias[ @&vec+ textureSroI ?&sampler(! sampler , vec+ ' Z, 'loat )ias[ @ 'loat textureSroI ?sampler*!Shado# sampler$ vec+ '

Z, 'loat )ias[ @

!o a te2ture loo8up #ith proFection. -he te2turecoordinates consumed 'rom ' , not includin& the lastcomponent o' ' , are divided

 b the last component o' '  to'orm proFected coordinates '4 .-he resultin& third componento' '4  in the shado# 'orms isused as Dre* . -he thirdcomponent o' 3 is i&nored#hen sampler  has tpe

&sampler*! and '  has tpevec+. 'ter these values arecomputed, te2ture loo8up

 proceeds as in texture.

95

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 102/155

8 Built$in %unctions

S&nta) -escription

&vec+ texture>od ?&sampler*! sampler , vec* ' , 'loat lo# @&vec+ texture>od ?&sampler(! sampler , vec( ' , 'loat lo# @&vec+ texture>od ?&sampler%ube sampler , vec( ' , 'loat lo# @ 'loat texture>od ?sampler*!Shado# sampler$ vec( ' , 'loat lo# @

&vec+ texture>od ?&sampler*!rra sampler , vec( ' , 'loat lo# @ 

!o a te2ture loo8up as intexture but #ith e2plicit LO!Mlo# speci'ies F)ase  and sets the

 partial derivatives as 'ollo#s.?See section (.5.6 I-e2ture<ini'ication and eCuation(.1+ in the OpenGL ES (.)Graphics SstemSpeci'ication.@

∂u

∂ ( = )

  ∂v

∂ ( = )

  ∂/

∂ (  = )

∂u

∂ y  = )

  ∂v

∂ y = )

  ∂/

∂ y  = )

&vec+ textureffset ?&sampler*! sampler , vec* ' ,ivec* o**set Z, 'loat )ias[ @

&vec+ textureffset ?&sampler(! sampler , vec( ' ,ivec( o**set Z, 'loat )ias[ @

 

'loat textureffset ?sampler*!Shado# sampler$ vec( ' ,ivec* o**set Z, 'loat )ias[ @

&vec+ textureffset ?&sampler*!rra sampler , vec( ' ,ivec* o**set Z, 'loat )ias[ @

 

!o a te2ture loo8up as intexture but #ith o**set addedto the ?u,v,/@ te2el coordinates

 be'ore loo8in& up each te2el.-he o''set value must be aconstant e2pression. limitedran&e o' o''set values aresupportedM the minimum andma2imum o''set values areimplementation;dependent and&iven b<$A3ROGR<A-EYELAO44SE- and<YA3ROGR<A-EYELAO44SE-,

respectivel. ote that o**set  does not applto the laer coordinate 'orte2ture arras. -his ise2plained in detail in section(.5.6 I-e2ture <ini'icationo' the OpenGL ES GraphicsSstem Speci'ication, #here

o**set is   u $v $ /.  ote

that te2el o''sets are also notsupported 'or cube maps.

96

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 103/155

8 Built$in %unctions

S&nta) -escription

&vec+ texelLetB ?&sampler*! sampler , ivec* ' , int lo# @&vec+ texelLetB ?&sampler(! sampler , ivec( ' , int lo# @

&vec+ texelLetB ?&sampler*!rra sampler , ivec( ' , int lo# @

9se inte&er te2ture coordinate  ' to loo8up a sin&le te2el 'rom sampler . -he arra laercomes 'rom the last componento' '  'or the arra 'orms. -helevel;o';detail  lo# is asdescribed in sections *.11.6IShader E2ecution under-e2el 4etches and (.5I-e2turin& o' the OpenGL ES(.) Graphics SstemSpeci'ication.

&vec+ texelLetBffset ?&sampler*! sampler , ivec* ' , int lo# ,ivec* o**set @&vec+ texelLetBffset ?&sampler(! sampler , ivec( ' , int lo# ,

ivec( o**set @

&vec+ texelLetBffset ?&sampler*!rra sampler , ivec( ' , int lo# ,ivec* o**set @

4etch a sin&le te2el as in

texelLetB o''set b o**set  asdescribed in textureffset.

&vec+ textureSroIffset ?&sampler*! sampler , vec( ' ,ivec* o**set Z, 'loat )ias[ @

&vec+ textureSroIffset ?&sampler*! sampler , vec+ ' ,ivec* o**set Z, 'loat )ias[ @

&vec+ textureSroIffset ?&sampler(! sampler , vec+ ' ,ivec( o**set Z, 'loat )ias[ @ 'loat textureSroIffset ?sampler*!Shado# sampler$ vec+ ' ,

ivec* o**set Z, 'loat )ias[ @

!o a proFective te2ture loo8upas described in textureSroI o''set b o**set  as described intextureffset.

&vec+ texture>odffset ?&sampler*! sampler , vec* ' ,'loat lo# , ivec* o**set @

&vec+ texture>odffset ?&sampler(! sampler , vec( ' ,'loat lo# , ivec( o**set @

 'loat texture>odffset ?sampler*!Shado# sampler$ vec( ' ,

'loat lo# , ivec* o**set @

&vec+ texture>odffset ?&sampler*!rra sampler , vec( ' ,'loat lo# , ivec* o**set @

 

!o an o''set te2ture loo8up#ith e2plicit LO!. Seetexture>od andtextureffset.

97

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 104/155

8 Built$in %unctions

S&nta) -escription

&vec+ textureSroI>od ?&sampler*! sampler , vec( ' , 'loat lo# @&vec+ textureSroI>od ?&sampler*! sampler , vec+ ' , 'loat lo# @&vec+ textureSroI>od ?&sampler(! sampler , vec+ ' , 'loat lo# @

'loat textureSroI>od ?sampler*!Shado# sampler$ vec+ '$ 'loat lo# @

!o a proFective te2ture loo8up#ith e2plicit LO!. SeetextureSroI and texture>od.

&vec+ textureSroI>odffset ?&sampler*! sampler , vec( ' ,'loat lo# , ivec* o**set @

&vec+ textureSroI>odffset ?&sampler*! sampler , vec+ ' ,'loat lo# , ivec* o**set @

&vec+ textureSroI>odffset ?&sampler(! sampler , vec+ ' ,'loat lo# , ivec( o**set @

 'loat textureSroI>odffset ?sampler*!Shado# sampler$ vec+ ' ,

'loat lo# , ivec* o**set @

!o an o''set proFective te2tureloo8up #ith e2plicit LO!. SeetextureSroI, texture>od, andtextureffset.

&vec+ texture=rad ?&sampler*! sampler$ vec* ' ,vec* #'#(, vec* #'#y@

&vec+ texture=rad ?&sampler(! sampler$ vec( ' ,vec( #'#(, vec( #'#y@

&vec+ texture=rad ?&sampler%ube sampler , vec( ' ,vec( #'#(, vec( #'#y@

 

'loat texture=rad ?sampler*!Shado# sampler , vec( ' ,vec* #'#(, vec* #'#y@  'loat texture=rad ?sampler%ubeShado# sampler , vec+ ' ,

vec( #'#(, vec( #'#y@

&vec+ texture=rad ?&sampler*!rra sampler$ vec( ' ,vec* #'#(, vec* #'#y@

 'loat texture=rad ?sampler*!rraShado# sampler , vec+ ' ,

vec* #'#(, vec* #'#y@

!o a te2ture loo8up as intexture but #ith e2plicit&radients. -he partialderivatives o' ' are #ithrespect to #indo# 2 and#indo# . Set

∂ s∂ (

= ∂ '.s

∂ (∂ s

∂ y =

 ∂ '.s

∂ y∂t ∂ (

= ∂ '.t 

∂ (∂t ∂ y

= ∂ '.t 

∂ y∂r 

∂ (=

 ∂ '.p

∂ (cube

∂r 

∂ y=

 ∂ '.p

∂ ycube

4or the cube version, the partial derivatives o' '  are

assumed to be in thecoordinate sstem used be'orete2ture coordinates are

 proFected onto the appropriatecube 'ace.

98

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 105/155

8 Built$in %unctions

S&nta) -escription

&vec+ texture=radffset ?&sampler*! sampler , vec* ' ,vec* #'#(, vec* #'#y$ ivec* o**set @

&vec+ texture=radffset ?&sampler(! sampler , vec( ' ,vec( #'#(, vec( #'#y$ ivec( o**set @

 'loat texture=radffset ?sampler*!Shado# sampler$ vec( ' ,

vec* #'#(, vec* #'#y$ ivec* o**set @

&vec+ texture=radffset ?&sampler*!rra sampler , vec( ' ,vec* #'#(, vec* #'#y$ ivec* o**set @

 'loat texture=radffset ?sampler*!rraShado# sampler$ vec+ ' ,

vec* #'#(, vec* #'#y$ ivec* o**set @

!o a te2ture loo8up #ith bothe2plicit &radient and o''set, asdescribed in texture=rad andtextureffset.

&vec+ textureSroI=rad ?&sampler*! sampler$ vec(  ' ,vec* #'#(, vec* #'#y@

&vec+ textureSroI=rad ?&sampler*! sampler$ vec+ ' ,vec* #'#(, vec* #'#y@

&vec+ textureSroI=rad ?&sampler(! sampler$ vec+ ' ,vec( #'#(, vec( #'#y@

 'loat textureSroI=rad ?sampler*!Shado# sampler , vec+ ' ,

vec* #'#(, vec* #'#y@

!o a te2ture loo8up both

 proFectivel, as described in

textureSroI, and #ith e2plicit

&radient as described in

texture=rad. -he partial

derivatives #'#( and #'#y are

assumed to be alread

 proFected.

&vec+ textureSroI=radffset ?&sampler*! sampler$ vec(  ' ,

vec* #'#(, vec* #'#y, ivec* o**set @&vec+ textureSroI=radffset ?&sampler*! sampler$ vec+ ' ,vec* #'#(, vec* #'#y, ivec* o**set @

&vec+ textureSroI=radffset ?&sampler(! sampler$ vec+ ' ,vec( #'#(, vec( #'#y, ivec( o**set @

 'loat textureSroI=radffset ?sampler*!Shado# sampler , vec+ ' ,

vec* #'#(, vec* #'#y, ivec* o**set @

!o a te2ture loo8up

 proFectivel and #ith e2plicit&radient as described in

textureSroI=rad, as #ell as

#ith o''set, as described in

textureffset.

4.5 +ragment *rocessing +unctions

4ra&ment processin& 'unctions are onl available in 'ra&ment shaders.

!erivatives ma be computationall e2pensive and>or numericall unstable. -here'ore, an OpenGL ES

implementation ma appro2imate the true derivatives b usin& a 'ast but not entirel accurate derivative

computation. !erivatives are unde'ined #ithin non;uni'orm control 'lo#.

-he e2pected behavior o' a derivative is speci'ied usin& 'or#ard>bac8#ard di''erencin&.

99

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 106/155

8 Built$in %unctions

4or#ard di''erencin&:

   0  (#( − 0  ( ~ #0#(  (⋅#( 1a

  #0#( (~  0  (#( − 0  (#(1b

"ac8#ard di''erencin&:

   0  (−#( − 0  ( ~−#0#(  (⋅#( *a

  #0#(  (~ 0  (− 0  (−#(

#(*b

=ith sin&le;sample rasteriation, #( T 1.) in eCuations 1b and *b. 4or multi;sample rasteriation, #( 

*.) in eCuations 1b and *b.

dLdy is appro2imated similarl, #ith y replacin& (.

n OpenGL ES implementation ma use the above or other methods to per'orm the calculation, subFect to

the 'ollo#in& conditions:

1. -he method ma use piece#ise linear appro2imations. Such linear appro2imations impl that hi&her

order derivatives, dLdx?dLdx? (@@ and above, are unde'ined.

*. -he method ma assume that the 'unction evaluated is continuous. -here'ore derivatives #ithin the

 bod o' a non;uni'orm conditional are unde'ined.

(. -he method ma di''er per 'ra&ment, subFect to the constraint that the method ma var b #indo#

coordinates, not screen coordinates. -he invariance reCuirement described in section (.* I$nvariance

o' the OpenGL ES Graphics Sstem Speci'ication, is rela2ed 'or derivative calculations, because the

method ma be a 'unction o' 'ra&ment location.

Other properties that are desirable, but not reCuired, are:

+. 4unctions should be evaluated #ithin the interior o' a primitive ?interpolated, not e2trapolated@.

/. 4unctions 'or dLdx should be evaluated #hile holdin& constant. 4unctions 'or dLdy should be

evaluated #hile holdin& 2 constant. o#ever, mi2ed hi&her order derivatives, li8e dLdx?dLdy? y@@

and dLdy?dLdx? (@@ are unde'ined.

7. !erivatives o' constant ar&uments should be ).

$n some implementations, varin& de&rees o' derivative accurac ma be obtained b providin& GL hints

?section /.( Iints o' the OpenGL ES (.) Graphics Sstem Speci'ication@, allo#in& a user to ma8e an

ima&e Cualit versus speed trade o''.

100

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 107/155

8 Built$in %unctions

S&nta) -escription

&en-pe dLdx ?&en-pe p@ Returns the derivative in 2 usin& local di''erencin& 'orthe input ar&ument p.

&en-pe dLdy ?&en-pe p@ Returns the derivative in usin& local di''erencin& 'orthe input ar&ument p.

-hese t#o 'unctions are commonl used to estimate the'ilter #idth used to anti;alias procedural te2tures. =eare assumin& that the e2pression is bein& evaluated in

 parallel on a S$<! arra so that at an &iven point intime the value o' the 'unction is 8no#n at the &rid pointsrepresented b the S$<! arra. Local di''erencin&

 bet#een S$<! arra elements can there'ore be used toderive d4d2, d4d, etc.

&en-pe f?idtB ?&en-pe p@ Returns the sum o' the absolute derivative in 2 and usin& local di''erencin& 'or the input ar&ument p, i.e.,a@s ?dLdx ? p@@ a@s ?dLdy ? p@@M

101

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 108/155

5 Shading Language Grammar 

-he &rammar is 'ed 'rom the output o' le2ical analsis. -he to8ens returned 'rom le2ical analsis are

HONS 5OOL FLO? IN KIN

5RE? HONINKE !O ELSE FOR IF !ISH?R! REKRN SIHP H?SE !EF?KL

5VEH8 5VEH; 5VEH7 IVEH8 IVEH; IVEH7 KVEH8 KVEH; KVEH7 VEH8 VEH; VEH7

@?8 @?; @?7 HENROI! IN OK INOK KNIFOR@

FL? S@OOP L?QOK

@?88 @?8; @?87

@?;8 @?;; @?;7

@?78 @?7; @?77S?@CLER8! S?@CLER;! S?@CLERHK5E S?@CLER8!SP?!O

S?@CLERHK5ESP?!O S?@CLER8!?RR?Q

S?@CLER8!?RR?QSP?!O IS?@CLER8! IS?@CLER;! IS?@CLERHK5E

IS?@CLER8!?RR?Q KS?@CLER8! KS?@CLER;!

KS?@CLERHK5E KS?@CLER8!?RR?Q 

SRKH VOI! PILE

I!ENIFIER QCE_N?@E FLO?HONS?N INHONS?N KINHONS?N 5OOLHONS?N

FIEL!_SELEHION

LEF_OC RIGP_OC

INH_OC !EH_OC LE_OC GE_OC E_OC NE_OC

?N!_OC OR_OC OR_OC @KL_?SSIGN !IV_?SSIGN ?!!_?SSIGN@O!_?SSIGN LEF_?SSIGN RIGP_?SSIGN ?N!_?SSIGN OR_?SSIGN OR_?SSIGN

SK5_?SSIGN

LEF_C?REN RIGP_C?REN LEF_5R?HE RIGP_5R?HE LEF_5R?HE RIGP_5R?HE !O

HO@@? HOLON EK?L SE@IHOLON 5?NG !?SP IL!E CLKS S?R SL?SP CERHEN

LEF_?NGLE RIGP_?NGLE VERIH?L_5?R H?RE ?@CERS?N! KESION

INV?RI?N

PIGP_CREHISION @E!IK@_CREHISION LO_CREHISION CREHISION

-he 'ollo#in& describes the &rammar 'or the OpenGL ES Shadin& Lan&ua&e in terms o' the above to8ens.

varia)le+i#enti*ier:  ,D!-T,,!R

 primary+e(pression:

  varia)le+i#enti*ier

102

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 109/155

9 "&adin' (an'ua'e )ra##ar 

  ,-T%O-"TG-T 

  A,-T%O-"TG-T

 LOGT%O-"TG-T

 BOOL%O-"TG-T

 L!T+'GR!- e(pression R,HT+'GR!-

 post*i(+e(pression:

  primary+e(pression

 post*i(+e(pression L!T+BRG%I!T integer+e(pression R,HT+BRG%I!T

 *unction+call

 post*i(+e(pression DOT ,!LD+"!L!%T,O-

 post*i(+e(pression ,-%+O'

 post*i(+e(pression D!%+O'

integer+e(pression:

  e(pression

 *unction+call:

  *unction+call+or+metho# 

 *unction+call+or+metho#:

  *unction+call+generic

 post*i(+e(pression DOT *unction+call+generic

 *unction+call+generic:

  *unction+call+hea#er+/ith+parameters R,HT+'GR!-

 *unction+call+hea#er+no+parameters R,HT+'GR!-

 *unction+call+hea#er+no+parameters:

  *unction+call+hea#er VO,D

 *unction+call+hea#er

 *unction+call+hea#er+/ith+parameters:

  *unction+call+hea#er assignment+e(pression *unction+call+hea#er+/ith+parameters %O99G assignment+e(pression

 *unction+call+hea#er:

  *unction+i#enti*ier L!T+'GR!-

103

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 110/155

9 "&adin' (an'ua'e )ra##ar 

 @@ rammar -ote: %onstructors loo& li&e *unctions$ )ut le(ical analysis recognie# most o* them as @@ &ey/or#s. They are no/ recognie# through type+speci*ierK. @@ 9etho#s 5.length6 an# i#enti*iers are recognie# through post*i(+e(pression.

 *unction+i#enti*ier:

  type+speci*ier 

  ,D!-T,,!R

  ,!LD+"!L!%T,O-

unary+e(pression:

  post*i(+e(pression

 ,-%+O' unary+e(pression

 D!%+O' unary+e(pression

unary+operator unary+e(pression

 @@ rammar -ote: -o tra#itional style type casts.

unary+operator:

  'LA"

 DG"H

 BG-

T,LD! 

 @@ rammar -ote: -o 4<4 or 44 unary ops. 'ointers are not supporte#.

multiplicative+e(pression:

  unary+e(pression

multiplicative+e(pression "TGR unary+e(pression

  multiplicative+e(pression "LG"H unary+e(pression

  multiplicative+e(pression '!R%!-T unary+e(pression

a##itive+e(pression:

  multiplicative+e(pression

a##itive+e(pression 'LA" multiplicative+e(pression

a##itive+e(pression DG"H multiplicative+e(pression

 shi*t+e(pression:

  a##itive+e(pression

 shi*t+e(pression L!T+O' a##itive+e(pression

  shi*t+e(pression R,HT+O' a##itive+e(pression

104

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 111/155

9 "&adin' (an'ua'e )ra##ar 

relational+e(pression:

  shi*t+e(pression

relational+e(pression L!T+G-L! shi*t+e(pression

relational+e(pression R,HT+G-L! shi*t+e(pression

relational+e(pression L!+O' shi*t+e(pression

relational+e(pression !+O' shi*t+e(pression

euality+e(pression:

  relational+e(pression

euality+e(pression !M+O' relational+e(pression

euality+e(pression -!+O' relational+e(pression

an#+e(pression:  euality+e(pression

an#+e(pression G9'!R"G-D euality+e(pression

e(clusive+or+e(pression:

  an#+e(pression

e(clusive+or+e(pression %GR!T an#+e(pression

inclusive+or+e(pression:

  e(clusive+or+e(pression

inclusive+or+e(pression V!RT,%GL+BGR e(clusive+or+e(pression

logical+an#+e(pression:

  inclusive+or+e(pression

logical+an#+e(pression G-D+O' inclusive+or+e(pression

logical+(or+e(pression:

  logical+an#+e(pression

logical+(or+e(pression NOR+O' logical+an#+e(pression

logical+or+e(pression:

  logical+(or+e(pression

logical+or+e(pression OR+O' logical+(or+e(pression

con#itional+e(pression:

  logical+or+e(pression

logical+or+e(pression MA!"T,O- e(pression %OLO- assignment+e(pression

105

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 112/155

9 "&adin' (an'ua'e )ra##ar 

assignment+e(pression:

  con#itional+e(pression

unary+e(pression assignment+operator assignment+e(pression

assignment+operator:

  !MAGL

 9AL+G"",- 

  D,V+G"",- 

  9OD+G"",- 

  GDD+G"",-

"AB+G"",-

 L!T+G"",- 

  R,HT+G"",-   G-D+G"",- 

  NOR+G"",- 

  OR+G"",- 

e(pression:

  assignment+e(pression

e(pression %O99G assignment+e(pression

constant+e(pression:

  con#itional+e(pression

#eclaration:

  *unction+prototype "!9,%OLO-

init+#eclarator+list "!9,%OLO-

 'R!%,",O- precision+uali*ier type+speci*ier+no+prec "!9,%OLO-

type+uali*ier ,D!-T,,!R L!T+BRG%! struct+#eclaration+list R,HT+BRG%! "!9,%OLO-

type+uali*ier ,D!-T,,!R L!T+BRG%! struct+#eclaration+list R,HT+BRG%! ,D!-T,,!R "!9,%OLO- 

  type+uali*ier ,D!-T,,!R L!T+BRG%! struct+#eclaration+list R,HT+BRG%!

 ,D!-T,,!R L!T+BRG%I!T constant+e(pression R,HT+BRG%I!T "!9,%OLO-   type+uali*ier "!9,%OLO- 

 *unction+prototype:

  *unction+#eclarator R,HT+'GR!-

106

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 113/155

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 114/155

9 "&adin' (an'ua'e )ra##ar 

  init+#eclarator+list %O99G ,D!-T,,!R !MAGL initialier

 single+#eclaration:

  *ully+speci*ie#+type

 *ully+speci*ie#+type ,D!-T,,!R

 *ully+speci*ie#+type ,D!-T,,!R L!T+BRG%I!T constant+e(pression R,HT+BRG%I!T

 *ully+speci*ie#+type ,D!-T,,!R L!T+BRG%I!T R,HT+BRG%I!T !MAGL initialier

 *ully+speci*ie#+type ,D!-T,,!R L!T+BRG%I!T constant+e(pression R,HT+BRG%I!T !MAGL initialier

 *ully+speci*ie#+type ,D!-T,,!R !MAGL initialier

 ,-VGR,G-T ,D!-T,,!R

 @@ rammar -ote: -o 4enum4$ or 4type#e*4.

 *ully+speci*ie#+type:

  type+speci*ier

type+uali*ier type+speci*ier

invariant+uali*ier:

  ,-VGR,G-T 

interpolation+uali*ier:

  "9OOTH 

  LGT 

 

layout+uali*ier:

  LGOAT L!T+'GR!- layout+uali*ier+i#+list R,HT+'GR!- 

layout+uali*ier+i#+list:  layout+uali*ier+i#   layout+uali*ier+i#+list %O99G layout+uali*ier+i# 

layout+uali*ier+i#:  ,D!-T,,!R

   ,D!-T,,!R !MAGL ,-T%O-"TG-T   ,D!-T,,!R !MAGL A,-T%O-"TG-T 

 parameter+type+uali*ier:

  %O-"T 

108

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 115/155

9 "&adin' (an'ua'e )ra##ar 

type+uali*ier:

  storage+uali*ier 

  layout+uali*ier 

  layout+uali*ier storage+uali*ier 

  interpolation+uali*ier storage+uali*ier 

  interpolation+uali*ier 

  invariant+uali*ier storage+uali*ier 

  invariant+uali*ier interpolation+uali*ier storage+uali*ier 

 storage+uali*ier:

  %O-"T

 ,- 

  OAT 

  %!-TRO,D ,- 

  %!-TRO,D OAT 

  A-,OR9

type+speci*ier:

  type+speci*ier+no+prec

  precision+uali*ier type+speci*ier+no+prec

type+speci*ier+no+prec:

  type+speci*ier+nonarray

type+speci*ier+nonarray L!T+BRG%I!T R,HT+BRG%I!T

type+speci*ier+nonarray L!T+BRG%I!T constant+e(pression R,HT+BRG%I!T

type+speci*ier+nonarray:

  VO,D

 LOGT

 ,-T 

  A,-T 

  BOOL

V!%2

V!%3

V!%

 BV!%2

 BV!%3

109

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 116/155

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 117/155

9 "&adin' (an'ua'e )ra##ar 

 precision+uali*ier:  H,H+'R!%,",O-   9!D,A9+'R!%,",O- 

  LOP+'R!%,",O- 

 struct+speci*ier:

  "TRA%T ,D!-T,,!R L!T+BRG%! struct+#eclaration+list R,HT+BRG%!

"TRA%T L!T+BRG%! struct+#eclaration+list R,HT+BRG%!

 struct+#eclaration+list:

  struct+#eclaration

 struct+#eclaration+list struct+#eclaration

 struct+#eclaration:

  type+speci*ier struct+#eclarator+list "!9,%OLO-

type+uali*ier type+speci*ier struct+#eclarator+list "!9,%OLO- 

 struct+#eclarator+list:

  struct+#eclarator

 struct+#eclarator+list %O99G struct+#eclarator

 struct+#eclarator:

  ,D!-T,,!R

 ,D!-T,,!R L!T+BRG%I!T R,HT+BRG%I!T

 ,D!-T,,!R L!T+BRG%I!T constant+e(pression R,HT+BRG%I!T

initialier:

  assignment+e(pression

#eclaration+statement:

  #eclaration

 statement:

  compoun#+statement+/ith+scope

 simple+statement

 statement+no+ne/+scope:

  compoun#+statement+no+ne/+scope

 simple+statement

 statement+/ith+scope:

111

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 118/155

9 "&adin' (an'ua'e )ra##ar 

  compoun#+statement+no+ne/+scope  simple+statement 

 @@ rammar -ote: la)ele# statements *or "P,T%H only 4goto4 is not supporte#.

 simple+statement:

  #eclaration+statement

e(pression+statement

 selection+statement 

  s/itch+statement

case+la)el 

  iteration+statement

 ;ump+statement

compoun#+statement+/ith+scope:

  L!T+BRG%! R,HT+BRG%!

 L!T+BRG%! statement+list R,HT+BRG%!

compoun#+statement+no+ne/+scope:

  L!T+BRG%! R,HT+BRG%!

 L!T+BRG%! statement+list R,HT+BRG%!

 statement+list:

  statement 

  statement+list statement 

e(pression+statement:

  "!9,%OLO-

e(pression "!9,%OLO-

 selection+statement:

  , L!T+'GR!- e(pression R,HT+'GR!- selection+rest+statement

 selection+rest+statement:

  statement+/ith+scope !L"! statement+/ith+scope

 statement+/ith+scope

con#ition:

  e(pression

 *ully+speci*ie#+type ,D!-T,,!R !MAGL initialier

112

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 119/155

9 "&adin' (an'ua'e )ra##ar 

 s/itch+statement:  "P,T%H L!T+'GR!- e(pression R,HT+'GR!- L!T+BRG%! s/itch+statement+list

 R,HT+BRG%! 

 s/itch+statement+list:  @< nothing <@   statement+list 

case+la)el:  %G"! e(pression %OLO-   D!GALT %OLO- 

iteration+statement:

  PH,L! L!T+'GR!- con#ition R,HT+'GR!- statement+no+ne/+scope

 DO statement+/ith+scope PH,L! L!T+'GR!- e(pression R,HT+'GR!- "!9,%OLO-

 OR L!T+'GR!- *or+init+statement *or+rest+statement R,HT+'GR!- statement+no+ne/+scope

 *or+init+statement:

  e(pression+statement

#eclaration+statement

con#itionopt:

  con#ition

 @< empty <@ 

 *or+rest+statement:

  con#itionopt "!9,%OLO-

con#itionopt "!9,%OLO- e(pression

 ;ump+statement:

  %O-T,-A! "!9,%OLO-

 BR!GI "!9,%OLO-

 R!TAR- "!9,%OLO-

 R!TAR- e(pression "!9,%OLO-

 D,"%GRD "!9,%OLO- @@ ragment sha#er only.

 @@ rammar -ote: -o 4goto4. otos are not supporte#.

translation+unit:

  e(ternal+#eclaration

translation+unit e(ternal+#eclaration

113

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 120/155

9 "&adin' (an'ua'e )ra##ar 

e(ternal+#eclaration:

  *unction+#e*inition

#eclaration

 *unction+#e*inition:

  *unction+prototype compoun#+statement+no+ne/+scope

$n &eneral the above &rammar describes a super set o' the GLSL ES lan&ua&e. %ertain constructs that are

valid purel in terms o' the &rammar are disallo#ed b statements else#here in this speci'ication.

Rules speci'in& the scopin& are present onl to assist the understandin& o' scopin& and the do not a''ect

the lan&ua&e accepted b the &rammar. $' reCuired, the &rammar can be simpli'ied b ma8in& the

'ollo#in& substitutions:

• Replace compoun#+statement+/ith+scope and compoun#+statement+no+ne/+scope #ith a ne#rule compoun#+statement 

• Replace statement+/ith+scope and statement+no+ne/+scope #ith the e2istin& rule statement .

114

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 121/155

10 rrors

10 Errors

-his section lists errors that must be detected b the compiler or lin8er. !evelopment sstems must

report all &rammatical errors are compile time but other#ise, it is implementation;dependent #hether an

error is reported at compile time or lin8 time and there is no &uarantee o' consistenc.

-he error strin& returned is implementation;dependent.

10.1 *reprocessor Errors

3)))1: 3reprocessor snta2 error 

3)))*: Nerror 

3)))(: Ne2tension i' a reCuired e2tension e2tensionAname is not supported, or i' all is speci'ied.

3)))/: $nvalid Nversion construct

3)))7: Nline has #ron& parameters

3)))0: Lan&ua&e version not supported

3)))5: 9se o' unde'ined macro

3)))6: <acro name too lon&

10.! Le)er>*arser Errors

Grammatical errors occurs #henever the &rammar rules are not 'ollo#ed. -he are not listed individuallhere.

L)))1: Snta2 error 

-he parser also detects the 'ollo#in& errors:

L)))*: 9nde'ined identi'ier.

L)))(: 9se o' reserved 8e#ords

L)))+: $denti'ier too lon&

L)))/: $nte&er constant too lon&

10.3 Semantic ErrorsS)))1: -pe mismatch in e2pression e.&. 1 1.)

S)))*: rra parameter must be an inte&er 

S)))(: %onditional Fump parameter ?if , for, ?Bile, do;?Bile@ must be a boolean

115

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 122/155

10 rrors

S)))+: Operator not supported 'or operand tpes ?e.&. mat+ vec(@

S)))/: 75 parameter must be a boolean

S)))7: *nd and (rd parameters o' 75 must have the same tpe

S)))0: =ron& ar&uments 'or constructor 

S)))5: r&ument unused in constructor 

S)))6: -oo 'e# ar&uments 'or constructor 

S))11: r&uments in #ron& order 'or structure constructor 

S))1*: E2pression must be a constant e2pression

S))1(: $nitialier 'or constant variable must be a constant e2pression

S))1/: E2pression must be a constant inte&ral e2pression

S))10: rra sie must be &reater than ero

S))15: rra sie not de'ined

S))*): $nde2in& an arra #ith a constant inte&ral e2pression &reater than its declared sie

S))*1: $nde2in& an arra #ith a ne&ative constant inte&ral e2pression

S))**: Rede'inition o' variable in same scope

S))*(: Rede'inition o' 'unction in same scope

S))*+: Rede'inition o' name in same scope ?e.&. declarin& a 'unction #ith the same name as a struct@

S))*/: 4ield selectors must be 'rom the same set ?cannot mi2 2# #ith r&ba@

S))*7: $lle&al 'ield selector ?e.&. usin& . #ith a veD@

S))*0: -ar&et o' assi&nment is not an l;value

S))*5: 3recision used #ith tpe other than int, float or sampler tpe

S))*6: !eclarin& a main 'unction #ith the #ron& si&nature or return tpe

S))(1: onst variable does not have initialier S))(*: 9se o' float or int #ithout a precision Cuali'ier #here the de'ault precision is not de'ined

S))((: E2pression that does not have an intrinsic precision #here the de'ault precision is not de'ined

S))(+: ariable cannot be declared invariant

116

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 123/155

10 rrors

S))(/: ll uses o' invariant must be at the &lobal scope

S))(0: L;value contains duplicate components ?e.&. v.22 T CM@

S))(5: 4unction declared #ith a return value but return statement has no ar&ument

S))(6: 4unction declared void but return statement has an ar&ument

S))+): 4unction declared #ith a return value but not all paths return a value

S))+*: Return tpe o' 'unction de'inition must match return tpe o' 'unction declaration.

S))+(: 3arameter Cuali'iers o' 'unction de'inition must match parameter Cuali'iers o' 'unction

declaration.

S))+/: !eclarin& an input inside a 'unction

S))+7: !eclarin& a uni'orm inside a 'unction

S))+0: !eclarin& an output inside a 'unction

S))+5: $lle&al data tpe 'or verte2 output or 'ra&ment input

S))+6: $lle&al data tpe 'or verte2 input ?can onl use float, 'loatin&;point vectors, matrices, si&ned and

unsi&ned inte&ers and inte&er vectors@

S))/): $nitialier 'or input

S))/1: $nitialier 'or output

S))/*: $nitialier 'or uni'orm

S))/(: Static recursion present

S))/+: Overloadin& built;in 'unctions not allo#ed.

S))//: erte2 output #ith inte&er tpe must be declared as 'lat

S))/7: 4ra&ment intput #ith inte&er tpe must be declared as 'lat

S))/0: inite(pression in s#itch statement must be a scalar inte&er 

S))/5: $lle&al data tpe 'or 'ra&ment output

S))/6: $nvalid laout Cuali'ier 

S))7): $nvalid use o' laout Cuali'ier ?e.&. on verte2 shader outputs or 'ra&ment shader inputs@

10.% Liner  

L)))1: Global variables must have the same tpe ?includin& the same names 'or structure and 'ield

names and the same sie 'or arras@ and precision.

L)))(: -oo man verte2 input values

L)))+: -oo man verte2 output values

117

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 124/155

10 rrors

L)))/: -oo man uni'orm values

L)))7: -oo man verte2 output values

L)))0: 4ra&ment shader uses an input #here there is no correspondin& verte2 output

L)))5: -pe mismatch bet#een verte2 output and 'ra&ment input

L)))6: <issin& main 'unction 'or shader 

118

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 125/155

11 *ountin' o+ Inputs and Outputs

11 Counting of Inputs and Outputs

-his section applies to verte2 shader outputs and 'ra&ment shader inputs.

GLSL ES (.) speci'ies the stora&e available 'or verte2 shader outputs and 'ra&ment shader inputs in

terms o' an arra o' +;vectors. -he assumption is that variables #ill be pac8ed into these arras #ithout

#astin& space. -his places si&ni'icant burden on implementations since optimal pac8in& is

computationall intensive. $mplementations ma have more internal resources than e2posed to the

application and so avoid the need to per'orm pac8in& but this is also considered an e2pensive solution.

GLSL ES (.) there'ore rela2es the reCuirements 'or pac8in& b speci'in& a simpler al&orithm that ma

 be used. -his al&orithm speci'ies a minimum reCuirement 'or #hen a set o' variables must be supported

 b an implementation. -he implementation is allo#ed to support more than the minimum and so ma use

a more e''icient al&orithm and>or ma support more re&isters than the virtual tar&et machine.

$n all cases, 'ailin& resource allocation 'or variables must result in an error.

-he resource allocation o' variables must succeed 'or all cases #here the 'ollo#in& pac8in& al&orithm

succeeds:

• -he tar&et architecture consists o' a &rid o' re&isters, 17 ro#s b + columns 'or verte2 output and

'ra&ment input variables. Each re&ister can contain a 'loat value.

• ariables are pac8ed into the re&isters one at a time so that the each occup a conti&uous sub;

rectan&le. o splittin& o' variables is permitted.

• -he orientation o' variables is 'i2ed. ectors al#as occup re&isters in a sin&le ro#. Elements

o' an arra must be in di''erent ro#s. E.&. vec+ #ill al#as occup one ro#M 'loatZ17[ #ill

occup one column. Since it is not permitted to split a variable, lar&e arras e.&. 'loatZ(*[ #illal#as 'ail #ith this al&orithm.

•  on;sCuare matrices o' tpe mat%2R consume the same space as a sCuare matri2 o' tpe mat

#here is the &reater o' % and R. ariables o' tpe mat* occupies * complete ro#s. -hese

rules allo# implementations more 'le2ibilit in ho# variables are stored.

Other variables consume onl the minimum space reCuired.

• rras o' sie are assumed to ta8e times the sie o' the base tpe.

119

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 126/155

11 *ountin' o+ Inputs and Outputs

• ariables are pac8ed in the 'ollo#in& order:

1. rras o' mat+ and mat+

*. rras o' mat* and mat* ?since the occup 'ull ro#s@

(. rras o' vec+ and vec+

+. rras o' mat( and mat(

/. rras o' vec( and vec(

7. rras o' vec* and vec*

0. rras o' 'loat and 'loat

• 4or each o' the above tpes, the arras are processed in order o' sie, lar&est 'irst. rras o' sie

1 and the base tpe are considered eCuivalent. -he 'irst tpe to be pac8ed #ill be mat+Z+[,

mat+Z([, matZ*[ 'ollo#ed b mat+, mat*Z+[...mat*Z*[, mat*, vec+Z5[, ve+Z0[,...vec+Z1[, vec+,

mat(Z*[, mat( and so on. -he last variables to be pac8ed #ill be 'loat ?and 'loatZ1[@.

• 4or *,( and + component variables pac8in& is started usin& the 1st column o' the 1st ro#.

ariables are then allocated to successive ro#s, ali&nin& them to the 1st column.

• 4or * component variables, #hen there are no spare ro#s, the strate& is s#itched to usin& the

hi&hest numbered ro# and the lo#est numbered column #here the variable #ill 'it. ?$n practice,

this means the #ill be ali&ned to the 2 or component.@ 3ac8in& o' an 'urther ( or +

component variables #ill 'ail at this point.

• 1 component variables ?i.e. 'loats and arras o' 'loats@ have their o#n pac8in& rule. -he are

 pac8ed in order o' sie, lar&est 'irst. Each variable is placed in the column that leaves the least

amount o' space in the column and ali&ned to the lo#est available ro#s #ithin that column.

!urin& this phase o' pac8in&, space #ill be available in up to + columns. -he space #ithin each

column is al#as conti&uous.

• $' at an time the pac8in& o' a variable 'ails, the compiler or lin8er must report an error.

120

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 127/155

11 *ountin' o+ Inputs and Outputs

E2ample: pac8 the 'ollo#in& tpes:

out ve'7 a- && top left

out mat; $- && align to left0 lo.est num$ered ro.s

out mat8x; '- && same si"e as mat;0 align to left

out ve'8 dAB- && align to left0 lo.est num$ered ro.s

out ve'8 eA7B- && Hannot align to left so align to " 'olumn0 (ig(est

&& num$ered ro.s

out ve'8 f- && ?lign to left0 lo.est num$ered ro.s,

out float gA;B && Holumn .it( minimum spa'e

out float (A8B- && Holumn .it( minimum spa'e '(oi'e of ;0 an9

&& 'an $e used)

out float i- && Holumn .it( minimum spa'e

$n this e2ample, the variables happen to be listed in the order in #hich the are pac8ed. 3ac8in& is

independent o' the order o' declaration.

) & ? #

0 a a a a

G @ @ @

D @ @ @

8 @ @ @

E

X

Y

d d g

[ d d g

" d d g

G! d d

GG d d

GD d d e e

G8 f f e e

GE B i e e

GX B e e

Some tpes e.&. mat+Z5[ #ill be too lar&e to 'it. -hese al#as 'ail #ith this al&orithm.

$' re'erenced in the 'ra&ment shader ?a'ter preprocessin&@, the built;in special variables ?&lA4ra&%oord,

&lA4ront4acin& and &lA3oint%oord@ are included #hen calculatin& the stora&e reCuirements o' 'ra&ment

inputs.

121

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 128/155

11 *ountin' o+ Inputs and Outputs

erte2 outputs and 'ra&ment inputs are counted separatel. -he are onl counted i' the are staticall

used #ithin the shader.

122

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 129/155

12 Issues

1! Issues

1!.1 Compatibilit& #ith OpenGL ES !.0

o# should OpenGL ES (.) support shaders #ritten 'or OpenGL ES *.)B

Option 1: Retain all GLSL ES 1.) constructs in the ne# lan&ua&e.

Option *: llo# GLSL ES 1.) shaders to run in the OpenGL ES (.) 3$.

RESOL9-$O: Option *. -his minimies the comple2it o' the lan&ua&e #ith onl a small increase in

sstem comple2it. $t also leaves open the option o' deprecatin& the old lan&ua&e in 'uture versions o'

the 3$.

1!.! Conergence #ith OpenGL

o# much should GLSL ES be in'luenced b the GLSL speci'icationB

OpenGL ES (.) is principall tar&eted at mobile devices such as smartphones and tablets. s such, it is

e2pected that the maFor use;cases #ill include &amin& and user;inter'aces. $t is to be e2pected that

content #ill be ported to and 'rom des8top devices.

RESOL9-$O: $n the absence o' an other reCuirements, GLSL ES (.) should 'ollo# GLSL (.(. -he

main e2ceptions to this are:

• -he speci'ication should adhere to the principle that 'unctionalit should not be duplicated.

• 4unctionalit speci'ic to mobile devices ?such as reduced precision@ can be added.

• $mprovements 'ound in later versions o' GLSL can be considered 'or inclusion.

1!.3 7umeric *recision

Should the Open GL ES *.) precision reCuirements be increasedB

<ost current implementations support a subset o' $EEE 0/+ (*;bit 'loatin& point. <an implementations

also support reduced precision.

RESOL9-$OS:

• hi&hp 'loat should be speci'ied as a subset o' $EEE 0/+ 'loatin& point.

• hi&hp int should be e2actl (* bits.

• lo#p and mediump should be retained. <ediump to have increased precision.

Should there be a de'ined 'ormat 'or mediumpB

Option: `es, this #ould increase portabilit and encoura&e the use o' mediump on mobile devices.

123

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 130/155

12 Issues

Option: o, this #ould be e2pensive to implement on devices that do not nativel support it.

RESOL9-$O: o. -he speci'ication should allo# e''icient implementation o' mediump 'loat on 17;bit

'loatin& point hard#are but must also be implementable on devices #hich onl nativel support (*;bit

'loatin& point.

Should the 'ra&ment shader have a de'ault precisionB

erte2 shaders have a de'ault hi&h precision because lo#er precisions are not su''icient 'or the maForit o'

&raphics applications. o#ever, man 'ra&ment shader operations do not bene'it 'rom hi&h precision and

developers should be encoura&ed to use lo#er precision #here possible as this ma increases per'ormance

or reduce po#er consumption. $n particular, blend operations normall onl reCuire lo# precision and

man te2ture address calculations can be per'ormed at medium precision.

o#ever OpenGL ES ma also be used in hi&her per'ormance devices #here the bene'it is limited.

-here'ore there appears to be no sin&le precision that #ould be applicable to all situations.

RESOL9-$O:o, there #ill be no de'ault precision 'or 'ra&ment shaders.

1!.% +loating *oint :epresentation and +unctionalit&

Should $EEE 0/+ representation be mandatedB

-he internal 'ormat used b an implementation mi&ht not be visible to an application so it is meanin&less

to speci' this. %ertain 'unctionalit $EEE 0/+ must be present thou&h.

RESOL9-$O: $n &eneral, hi&hp 'loat must behave as i*  it is in $EEE 0/+ 'ormat.

=hich 'eatures should be mandatedB

<ost o' the $EEE 0/+ is relativel ine2pensive to implement &iven that (*;bit 'loatin& point is areCuirement. o#ever some implementations do not implement si&ned eros, roundin& modes and as

 because o' hard#are cost. $n addition, there are certain compiler optimiations that the $EEE 0+/

speci'ication prohibits.

RESOL9-$O: <andate support o' si&ned in'inities. Support o' si&ned eros, as.

Should the support o' as be consistentB

Should the speci'ication allo# either 'ull $EEE a support or no support but nothin& in bet#eenB

RESOL9-$O: o, implementations ma have partial support and there is no &uarantee o' consistenc.

-he onl reCuirement is that isnan?@ must return 'alse i' as are not supported.

Should subnormal numbers ?also 8no#n as DdenormsD@ be supportedB

RESOL9-$O: o, subnormal numbers mabe 'lushed to ero at an time.

124

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 131/155

12 Issues

o# should the roundin& mode be speci'iedB

<ost current implementations support round;to;nearest. Some but not all also support round;to;nearest;

even.

RESOL9-$O: =ithin the accurac speci'ication, the roundin& mode should be unde'ined.

Should there be &eneral invariance rules 'or numeric 'ormats and operationsB

-he GLSL ES speci'ication allo#s the implementation a de&ree o' 'le2ibilit. %onseCuentl the results o'

a computation ma be di''erent on di''erent implementations. o#ever, it is not stated #hether a sin&le

implementation is allo#ed to var the results o' a &iven computation, either in di''erent shaders or

di''erent parts o' the same shader. OpenGL has a &eneral invariance rule that prevents the results o' a

computation varin& i' no state ?includin& the choice o' shader@ is unchan&ed.

RESOL9-$O: Operations and 'ormats are in &eneral considered to be variant.

1!.' *recision ;ualifiers

Should the precisions be speci'ied as 'loat17, 'loat(* etc.B -his #ould help portabilit. $t implies

di''erent tpes rather than hints. $t #ill reCuire all implementations to use the same or similar al&orithms

and reduces the scope 'or innovation.

RESOL9-$O: o, the precision should not speci' a 'ormat. Standardied arithmetic is not ?et@ a

reCuirement 'or &raphics.

!o inte&ers have precision Cuali'iersB OpenGL ES (.) hard#are is e2pected to have native inte&er

support and some implementations ma have reduced precision available.

RESOL9-$O: `es, inte&ers have precision Cuali'iers.

o# should #rappin& behavior o' inte&ers be de'inedB $' an application relies on #rappin& on one

implementation this ma cause portabilit problems.

Option: -he standard should speci' either #rappin& or clampin&. -his allo#s 'or ma2imum

implementation 'le2ibilit.

Option: <andate #rappin&. -here is a trend to#ards more comple2 shaders and developers #ill e2pect

inte&ers to behave as in %.

RESOL9-$O: <andate #rappin&.

re precision Cuali'iers available in the verte2 shaderB

RESOL9-$O: `es. Reduced precision ma be available in the verte2 shader in some implementations

and it 8eeps the lan&ua&es consistent.

125

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 132/155

12 Issues

Should di''erent precisions create di''erent tpes and e.&. reCuire e2plicit conversion bet#een themB

Option1: o, the are Fust hints. "ut hintin& hi&h precision is meanin&less i' the implementation can

i&nore it.

Option *: `es the are di''erent tpes. "ut this introduces comple2it.

RESOL9-$O: -he precision Cuali'ier can si&ni'icantl a''ect behavior in man implementations.

BigBp means (*;bit $EEE 0+( 'loatin& pointis used but mediump means that at least medium precision is

used ?and similarl 'or lo?p so precision Cuali'iers are more than Fust hints. s 'ar as the lan&ua&e is

concerned it doesnDt a''ect the behavior so the can either be considered as hints or as di''erent tpes #ith

implicit tpe conversion. $n an case, implementations are 'ree to calculate everthin& at hi&h precision.

Should precisions be considered #hen resolvin& 'unction callsB

RESOL9-$O: o, the should be considered more as hints. 4unction declarations cannot be

overloaded based on precision.

o# should precisions be propa&ated in an e2pressionB

Option 1: Onl consider the inputs to an operation. 4or operands that have no de'ined precision,

determination o' precision starts at the lea' nodes o' the e2pression tree and proceeds to the root until the

 precision is 'ound. $' necessar this includes the l;value in an assi&nment. %onstant e2pressions must be

invariant and it is e2pected that the #ill be evaluated at compile time. -here'ore the must be evaluated

at the hi&hest precision ?either lo?p or BigBp@ supported b the tar&et, or above.

Option *: l#as ta8e the tar&et o' the e2pression into account. -he compiler should be able to #or8 out

ho# to avoid losin& precision.

RESOL9-$O: Option 1. -his ma8es it easier 'or the developer to speci' #hich precisions are used in

a comple2 e2pression.

=hat i' there is no precision in an e2pressionB

Option 1: Leave this as unde'ined.

Option *: 9se the de'ault precision.

RESOL9-$O: 9se the de'ault precision. $t is an error i' this is not de'ined ?in the 'ra&ment shader@.

!o precision Cuali'iers 'or uni'orms need to matchB

Option 1: `es.

9ni'orms are de'ined to behave as i' the are usin& the same stora&e in the verte2 and 'ra&ment processors

and ma be implemented this #a.

$' uni'orms are used in both the verte2 and 'ra&ment shaders, developers should be #arned i' the

 precisions are di''erent. %onversion o' precision should never be implicit.

126

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 133/155

12 Issues

Option *: o.

9ni'orms ma be used b both shaders but the same precision ma not be available in both so there is a

 Fusti'ication 'or allo#in& them to be di''erent.

9sin& the same uni'orm in the verte2 and 'ra&ment shaders #ill al#as reCuire the precision to be

speci'ied in the verte2 shader ?since the de'ault precision is hi&hp@. -his is an unnecessar burden on

developers.

RESOL9-$O: `es, precision Cuali'iers 'or uni'orms must match.

!o precision Cuali'iers 'or verte2 outputs and the correspondin& 'ra&ment inputs ?previousl 8no#n as

Dvarin&sD@ need to matchB

Option 1: `es. arin&s are #ritten b the verte2 shader and read b the 'ra&ment shader so there are no

situations #here the precision needs to be di''erent.

Option *: o, the verte2 outputs #ritten b the verte2 shader should not be considered to be the samevariables as those read b the 'ra&ment shader ?there can be no shared stora&e@. ence the can be

speci'ied to have di''erent precisions.

RESOL9-$O 3recision Cuali'iers 'or verte2 outputs and 'ra&ment inputs do not need to match.

lo?p int

lo?p float has a ran&e o' >; *.) but lo?p int has a ran&e o' >; */7. -his becomes problematic i'

conversion 'orm lo?p float to lo?p int is reCuired. !irect conversion i.e. lo?p int T int?lo?p float@

loses almost all the precision and multiplin& be'ore conversion e.&. lo?p int T int?lo?p float  */7@

causes an over'lo# and hence an unde'ined result. -he onl #a to maintain precision is to 'irst convert

to mediump float.

Option 1: Keep this behavior. ccept that conversion o' lo?p float to lo? int loses precision and is

there'ore not use'ul.

Options *: <a8e lo?p int consistent #ith mediump and BigBp int b settin& its ran&e to >; 1

Options (: Rede'ine the conversion o' lo?p float to lo?p int to include an 5;bit le't shi't. -he

conversion o' lo?p int to lo?p float then contains an 5;bit ri&ht shi't.

Option +: Option 1 but add built;in 'unctions to shi't;convert bet#een the t#o 'ormats.

Option /: Rede'ine the lo?p float to be a true 'loatin& point 'ormat. $t #ould then be eCuivalent to a

'loatin& point value #ith a 1) bit mantissa and a ( bit unsi&ned e2ponent.

RESOL9-$O: Option 1 %onversion #ill lose most o' the precision.

3recision o' built;in te2ture 'unctions.

127

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 134/155

12 Issues

<ost built;in 'unctions ta8e a sin&le parameter and it is sensible 'or the precision o' the return value to be

the same as the precision o' the parameter. -he te2ture 'unctions ta8e sampler and coordinate parameters.

-he return value should be completel independent o' the precision o' the coordinates. o# should the

 precision o' the return value be speci'iedB

RESOL9-$O: llo# sampler tpes to ta8e a precision Cuali'ier. -he return value o' the te2ture

'unctions have the same precision as the precision o' the sampler parameter.

=hat should the de'ault precision o' sampler tpes beB

Option 1: lo?p. -his #ill be 'aster on some implementations. $n &eneral, OpenGL ES should de'ault to

'ast operation rather than precise operation. $t is usuall easier to detect and correct a 'unctional error

than a per'ormance issue.

Option *: lo?p 'or te2tures that are e2pected to contain color values. BigBp 'or te2tures that are e2pected

to contain other values e.&. depth.

Option *: o de'ault precision. lthou&h this reCuires that the precision be speci'ied in ever shader, it

#ill 'orce the developer to consider the reCuirements.

RESOL9-$O: -he de'ault precision o' all sampler tpes present in GLSL ES 1.) should also be lo?p 

in GLSL ES (.). e# sampler tpes in GLSL ES (.) should have no de'ault precision.

1!. +unction and (ariable 7ame Spaces

!o variables and 'unctions share the same name spaceB GLSL ES doesnDt support 'unction pointers so the

&rammar can al#as be used to distin&uish cases. o#ever this is a departure 'rom %.

RESOL9-$O: 4unctions and variables share the same name space.

Should redeclarations o' the same names be permitted #ithin the same scopeB -his #ould be compatible

#ith %. -here are several cases e.&.:

1. Redeclarin& a 'unction. 'unction prototpe is a declaration but not a de'inition. 'unction

de'inition is both a declaration and a de'inition. %onseCuentl a 'unction prototpe and a

'unction de'inition ?o' the same 'unction@ #ithin the same scope Cuali'ies as redeclaration.

*. !eclarin& a name as a 'unction and then redeclarin& it as a structure.

(. !eclarin& a name as a variable and then redeclarin& it as a structure.

!isallo#in& multiple 'unction declarations ?includin& allo#in& a separate 'unction prototpe and 'unction

de'inition@ #ould prevent static recursion b desi&n. o#ever it imposes constraints on the structure o'

shaders.

GLSL ES 1.)) allo#s a sin&le 'unction de'inition plus a sin&le optional 'unction declaration.

RESOL9-$O: <ultiple de'initions are disallo#ed. <ultiple 'unction declarations ?'unction

 prototpes@ are allo#ed. -his is in line #ith %.

128

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 135/155

12 Issues

1!.2 Local +unction -eclarations and +unction $iding

Should local 'unctions hide all 'unctions o' the same sameB

-his is considered use'ul i' local 'unction declarations are allo#ed. o#ever, the onl use 'or local'unction declarations in GLSL ES is to unhide 'unctions that have been hidden b variable or structure

declarations. -his is not a compellin& reason to include them.

RESOL9-$O: !isallo# local 'unction declarations.

1!.4 Oerloading main@A

Should it be possible 'or the user to overload the main?@ 'unctionB

RESOL9-$O: o. -he main 'unction cannot be overloaded.

1!.5 Error :eporting

$n &eneral #hich errors must  be reported b the compilerB

Some errors are eas to detect. ll &rammar errors and tpe matchin& errors #ill normall be detected as

 part o' the normal compilation process. Other semantic errors #ill reCuire speci'ic code in the compiler.

-he bul8 o' the #or8 in a compiler occurs a'ter parsin& so addin& some error detection should not

increase the total cost o' compilation si&ni'icantl. o#ever, it is e2pected that development sstems #ill

have sophisticated error and #arnin& reportin& and it is not necessar to repeat this process 'or on;tar&et

compilers.

RESOL9-$O: ll &rammar, tpe mismatch and other speci'ic semantic errors as listed in this

speci'ication must be reported. Reportin& o' other errors or #arnin&s is optional.

Should compilers report i' ma2ima are e2ceeded, even i' the implementation supports themB -his couldaid portabilit.

RESOL9-$O: o, hi&h;end implementations ma Cuite le&itimatel &o beond the speci'ication in

these areas and mandatin& the use o' the e2tension mechanism #ould cause needless comple2it.

!evelopment sstems should issue portabilit #arnin&s.

Should static recursion be detectedB

RESOL9-$O: `es, the compiler #ill normall &enerate the necessar control 'lo# &raph so detection

is eas.

1!.10 Structure -eclarations

Should structures #ith the same name and same member variables be considered as the same tpeB

RESOL9-$O: o, 'ollo# the % rules. ariables onl have the same tpe i' the have been declared

#ith the same tpe and not i' the have been declared #ith di''erent tpes that have the same name. -his

does not appl to lin8in& ?'or uni'orms and varin&s@ #hich has its o#n rules.

129

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 136/155

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 137/155

12 Issues

int sinint x) *return x-2

void main)

*

  float a + sin<,=)- && legal in GLSL ES0 not legal in des:top GLSL,2

$t is also a potential source o' bac8#ards;incompatibilit i' a 'uture version o' the lan&ua&e introduces

ne# overloads.

Option (: Remove the abilit to rede'ine or overload 'unctions.

RESOL9-$O: !isallo# both overloadin& and rede'inin& built;in 'unctions. -here is no compellin& use

case.

1!.13 Global Scope

o# should the scopin& levels 'or user;de'ined and built;in names be de'inedB

GLSL ES 1.)) and most versions o' GLSL have a &lobal scope 'or user;de'ined 'unctions and variables

and a distinct DouterD scope #here the built;in 'unctions reside. -his is di''erent 'rom %. Since GLSL

ES (.)) does not allo# the rede'inition o' built;in 'unctions, a sin&le &lobal scope is su''icient.

RESOL9-$O: sin&le &lobal scope #ill be used 'or user;de'ined and built;in names.

1!.1% Constant E)pressions

Should user and built;in 'unctions be allo#ed in constant e2pressionsB e.&.

'onst float a + sin<,=)-

-he compiler must be able to evaluate all possible constant e2pressions as the can potentiall be used to

sie arras and 'unctions resolution is dependent on arra sie. %ompile;time evaluation o' built;in

'unctions is e2pensive in terms o' code sie. -he comple2it o' compile;time evaluation o' user;de'ined

'unctions is potentiall unbounded.

RESOL9-$O: llo# built;in 'unctions to be included in constant e2pressions. Rede'inition o' built;in

'unctions is prohibited. 9ser;de'ined 'unctions are not allo#ed in constant e2pressions.

1!.1' (ar&ing Linage

$n the verte2 shader, a particular varin& ma be either 1@ not declared, *@ declared but not #ritten, (@

declared and #ritten but not in all possible paths or +@ declared and #ritten in all paths. Li8e#ise a

varin& in a 'ra&ment shader ma be either a@ not declared, b@ declared but not read, c@ declared and readin some paths or d@ declared and read in all paths. =hich o' these 17 combinations should &enerate an

errorB

-he compiler should not attempt to discover i' a varin& is read or #ritten in all possible paths. -his is

considered too comple2 'or OpenGL ES.

131

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 138/155

12 Issues

-he same verte2 shader ma be paired #ith di''erent 'ra&ment shaders. -hese 'ra&ment shaders ma use a

subset o' the available input varin&s. -his behavior should be supported #ithout causin& errors.

-here'ore i' the verte2 shader #rites to a varin& that the 'ra&ment shader doesnDt declare or declared but

doesnDt read then this is not an error.

$' the verte2 shader declares but doesnDt #rite to a varin& and the 'ra&ment shader declares and reads it, is

this an errorB

RESOL9-$O: o.

RESOL9-$O: -he onl error case is #hen a varin& is declared and read b the 'ra&ment shader but is

not declared in the verte2 shader.

1!.1 glB*osition

$s it an error i' the verte2 shader doesnDt #rite to &lA3ositionB =hether a shader #rites to &lA3osition

cannot al#as be determined e.&. i' there is dependence on an attribute.

Option 1: o it is not an error. -he behavior is unde'ined in this case. !evelopment sstems shouldissue a #arnin& in this case but the on;tar&et compiler should not have to detect this.

Option *: $t is an error i' the verte2 shader does not staticall #rite to &lA3osition

Option (: $t is an error i' there is an static path throu&h the shader #here &lA3osition is not #ritten.

RESOL9-$O: o error ?option 1@. -he nature o' the unde'ined behavior must be speci'ied.

1!.12 *re8processor 

$s the preprocessor necessarB

r&uments 'or removin& or simpli'in& the preprocessor:

• -he preprocessor is moderatel comple2 to implement. $n particular, 'unction;li8e macros mahave arbitrar comple2it and reCuire si&ni'icant resources to compile.

• -he % standard does not 'ull speci' the preprocessor. $n particular, the situations #here

 preprocessor to8ens are subFect to macro e2pansion are not 'ull de'ined. either is the e''ect o'

macro de'initions encountered durin& macro e2pansion.

• Over;use o' the preprocessor is a common source o' pro&rammin& errors because there is limited

compile;time chec8in&.

r&uments 'or retainin& the preprocessor:

• -he e2tension mechanism relies on the preprocessor so this #ould need to be replaced.

• -he #define, #ifdef , #ifndef , #elsif  and #endif  constructs are commonl used 'or mana&in&

di''erent versions and 'or include &uards.

• -here is no template mechanism in GLSL ES so macros are o'ten used instead.

GLSL ES 1.)) removed to8en pastin& and other 'unctionalit.

132

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 139/155

12 Issues

RESOL9-$O: Keep the basic preprocessor as de'ined in the GLSL ES 1.)) speci'ication.

1!.14 Character set

GLSL ES 1.)) onl allo#ed a subset o' the ascii character set to be used in shaders. -hat included names

and comments. -he #ritten lan&ua&es o' man countries include other characters or use a completel

di''erent character set. -his ma8es it di''icult or impossible to #rite comments in those lan&ua&es.

=here should the ne# characters be allo#edB $t #ould be possible to decide independentl 'or comments,

identi'iers and macros. 4or macros, the could be allo#ed as part o' macro de'initions but prohibited in

the 'inal output o' macro e2pansion.

RESOL9-$O: -he ne# characters are onl allo#ed inside comments.

=hich character set should be used to de'ine the ne# characters.

9-4;5 has the advanta&e that it is bac8#ards;compatible #ith S%$$. ll S%$$ characters are valid

9-4;5 sin&le;bte characters and 9-4;5 multi;bte characters all have the hi&hest bit set to D1D in each

 bte. -he disadvanta&e is that 9-4;5 is variable len&th.

RESOL9-$O: 9-4;5

o# should the e2tended character set be speci'iedB

Options include 'ull 9-4;5 or b e2plicitl listin& the allo#ed characters.

RESOL9-$O: 4ull 9-4;5

Should the compiler chec8 'or the presence o' invalid 9-4;5 bte seCuencesB

Since an multi;bte characters #ill onl occur #ithin comments and so not reCuired 'urther processin&, it#ould be ine2pensive to chec8 'or valid 9-4;5 characters. %onversel, there appears to be no advanta&e

to doin& so. -he issue o' validit is onl o' concern to te2t editors.

RESOL9-$O: -he compiler must not chec8 'or invalid 9-4;5 characters. "tes D)D and ne#line

characters #ill be interpreted as such #herever the occur.

o# does the Nversion directive interact #ith the use o' 9-4;5 in commentsB

4ollo#in& %, the Dphases o' translationD speci'ication de'ines comment processin& to be per'ormed

 be'ore macro directives are processed. o#ever 9-4;5 is le&al in GLSL ES (.)), identi'ied b Nversion

()) but not in GLSL ES 1.)), identi'ied b Nversion 1)) ?or b absence o' a Nversion directive@.

Option: -he shader is processed in * passes. -he 'irst determines the shader version and the second per'orms compilation as be'ore.

Option: Replace the current version directive mechanism #ith a bte seCuence that must al#as occur at

the start o' the shader. -his is similar to other standards that have multiple versions e.&. http.

Option: <a8e 9-4;5 characters an optional 'eature o' GLSL ES 1.))

133

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 140/155

12 Issues

RESOL9-$O: 9-4;5 #ill be made optional in GLSL ES 1.))

1!.15 Line Continuation

Should the line continuation character DD be included in the speci'icationB

Line continuation #as deliberatel e2cluded 'rom previous versions o' GLSL and GLSL ES in order to

discoura&e e2cessive use o' the pre;processor. o#ever, 'unction;li8e macros are commonl used

 because there is no DtemplateD mechanism, #hich #ould allo# 'unctions to be parametried b a tpe.

Lon& macro de'initions are there'ore not uncommon and the line;continuation character ma aid

readabilit.

Given that shader source is stored in a list o' character strin&s, the ne#line character can be omitted and

this has the same e''ect as a ne#line 'ollo#ed b a line;continuation.

RESOL9-$O: $nclude line;continuation.

o# does this interact #ith NversionB

RESOL9-$O: Same issue as #ith 9-4;5in &eneral. Line;continuation to be made optional in GLSL ES

1.))

1!.!0 *hases of Compilation

Should the preprocessor run as the ver 'irst sta&e o' compilation or a'ter conversion to preprocessor

to8ens as #ith %>%B

-he cases #here the result is di''erent are not common.

#define e D<int n + <e-

ccordin& to the c standard, D1eD should be converted to a preprocessor to8en #hich then 'ails

conversion to a number. $' the preprocessor is run 'irst, D1eD is e2panded to D11D #hich is then parsed

success'ull.

RESOL9-$O: 4ollo# c rules.

1!.!1 9a)imum 7umber of (ar&ings

o# should &lA<a2arin&4loats be de'inedB Ori&inall this #as speci'ied as (* 'loats but currentl

some des8top implementations 'ail to implement this correctl. <an implementations use 5 vec+

re&isters and it is di''icult to split varin&s across multiple re&isters #ithout losin& per'ormance.

Option 1: Speci' the ma2imum as 5 +;vectors. $t is then up to the application to pac8 varin&s. Other

lan&ua&es reCuire the pac8in& to be done b the application. !evelopers have not reported this as a

 problem.

134

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 141/155

12 Issues

Option *: Speci' the ma2imum accordin& to a pac8in& rule. -he developer ma use a non;optimal

 pac8in& so it is better to do this in the driver. ReCuirin& the application to pac8 varin&s is problematic

#hen shaders are automaticall &enerated. $t is easier 'or the driver to implement this.

RESOL9-$O: -he ma2imum #ill be speci'ied accordin& to a pac8in& rule.

Should attributes and uni'orms 'ollo# this ruleB

RESOL9-$O: ttributes should not 'ollo# this rule. -he #ill be continued to be speci'ied as vec+s.

RESOL9-$O: 9ni'orms should not 'ollo# this rule 'or GLSL ES (.)). $mplementations are e2pected

to virtualie such resources.

Should the built;in special variables ?&lA4ra&%oord, &lA4ront4acin&, &lA3oint%oord@ be included in this

 pac8in& al&orithmB "uilt;in special variables are implemented in a variet o' #as. Some

implementations 8eep them in separate hard#are, some do not.

RESOL9-$O: n built;in special variables that are staticall used in the shader should be included in

the pac8in& al&orithm.

Should &lA4ra&%oord be included in the pac8in& al&orithmB -he 2 and components #ill al#as be

reCuired 'or rasteriation. -he and # components #ill o'ten be reCuired.

RESOL9-$O: &lA4ra&%oord is included in the count o' varin&s.

o# should matD varin&s be pac8edB

Option 1: 3ac8 them as *2*.

Option *: 3ac8 them as + columns 2 1 ro#. -his is usuall more e''icient 'or an implementation.

Option (: llocate a + column 2 * ro# space. -his is ine''icient but allo#s 'le2ibilit in ho#

implementations map them to re&isters.

Option +: s above but pac8 * matD varin&s into each + column 2 * ro# bloc8. n unpaired matD 

ta8es a #hole +2* bloc8.

RESOL9-$O: Option (

Should mat8 ta8e ( #hole ro#sB

-his #ould a&ain allo# 'le2ibilit in implementation but it #astes space that could be used 'or 'loats or'loat arras.

RESOL9-$O: o, mat8 should ta8e a (2( bloc8.

Should ve8 ta8e a #hole ro#B

135

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 142/155

12 Issues

RESOL9-$O: o.

Should &lA<a2erte29ni'orms%omponents be chan&ed ?'rom des8top GLSL@ to re'lect the pac8in&rulesB

RESOL9-$O: Rename &lA<a2erte29ni'orm%omponents to &lA<a2erte29ni'ormectors. Rename

&lA<a24ra&ment9ni'orm%omponents to &lA<a24ra&ment9ni'ormectors.

1!.!! rra& -eclarations

9nsied arra declarations.

!es8top GLSL allo#s arras to be declared #ithout a sie and these can then be accessed #ith constant

inte&ral e2pressions. -he sie never needs to be declared. -his #as to support &lA-e2coord e.&.

var9ing ve'7 gl_exHoordAB-

,,,

gl_FragHolor + texture tex0 gl_exHoordA=B,x9)-

-his allo#s &lA-e2%oord to be used #ithout havin& to declare the number o' te2ture units.

&lA-e2%oord is part o' the 'i2ed 'unctionalit so unsied arras should be removed 'or GLSL ES

RESOL9-$O: Remove unsied arra declarations.

=hich 'orms o' arra declarations should be permittedB

 float aA>B-

 ,,,

 float $AB + a- && $ is expli'itl9 si"e >

or

float aAB + floatAB <,=0 8,=0 ;,=)-

RESOL9-$O: ll above constructs are valid. o#ever, an declaration that leaves the sie unde'ined

is disallo#ed as this #ould add comple2it and there are no use;cases.

1!.!3 Inariance

o# should invariance bet#een shaders be handledB

ersion 1.1) o' des8top GLSL uses 'trans'orm?@ to &uarantee that &lA3osition can be &uaranteed to be

calculated the same #a in di''erent verte2 shaders. -his relies on the 'i2ed 'unction that has been

removed 'rom ES. $t is also ver restrictive in that it onl allo#s verte2 trans'orms based on matrices. $tdoes not appl to other values such as those used to &enerate te2ture coordinates.

Option 1: Speci' all operations to be invariant. o, this is too restrictive. Optimum use o' resources

 becomes impossible 'or some implementations.

136

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 143/155

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 144/155

12 Issues

4or e2ample suppose a boolean is represented b a (*;bit inte&er #ith D'alseD represented as ) and DtrueD

represented as D1D. $' the compiler uses both an DeCuals )D and an DeCuals 1D test, the 'ollo#in& ma occur:

$ool $- && (e implementation sets t(is to an illegal value e,g, ;

 

if $) && implementation tests $ ++ < .(i'( is false

 *

  f)-

 2

 else && implementation tests $ ++ = .(i'( is also false

 *

  g)-

 2

 either '?@ nor &?@ are e2ecuted #hich is une2pected behaviour. Such cases could be made invariant but

#ould 'or e2ample reCuire the compiler to initialie unde'ined values #hich is a per'ormance cost.

RESOL9-$O: 9nde'ined values cannot be made invariant. -hese shaders are mal'ormed and there'ore

have unde'ined behavior.

1!.!% Inariance <ithin a shader 

o# should invariance #ithin a shader be speci'iedB

%ompilers ma decide to recalculate a value rather than store it in a re&ister ?rematerialiation@. -he ne#

value ma not be e2actl the same as the ori&inal value.

Option 1: 3rohibit this behavior.

Option *: 9se the invariance Cuali'ier on variables to control this. -his is consistent #ith the des8top.

RESOL9-$O: alues #ith in a shader are in variant be de'ault. -he invariance Cuali'ier or pra&ma

ma be used to ma8e them invariant.

Should constant e2pressions be invariantB $n the 'ollo#in& e2ample, it is not de'ined #hether the literal

e2pression should al#as evaluate to the same value.

pre'ision mediump int-

pre'ision mediump float-

'onst int si"e + int'eil7,=&;,= =,;;;;;;))-

int aAsi"eB-

for int i+=- i/int'eil7,=&;,= =,;;;;;;))- iDD) *a AiB + i-2

138

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 145/155

12 Issues

$mplementations must usuall be able to evaluate constant e2pressions at compile time since the can be

used to declare the sie o' arras. ard#are ma compute a less accurate value compared #ith maths

libraries available in %. $t #ould ho#ever be e2pected that 'unctions such as sine and cosine return

similar results #hether or not the are part o' a constant e2pression. -his su&&ests that theimplementation mi&ht #ant to evaluate these 'unctions onl on the hard#are. o#ever, there are no

situations, even #ith &lobal invariance, #here compile time evaluation and runtime evaluation must match

e2actl.

RESOL9-$O: `es, constant e2pressions must be invariant.

1!.!' <hile8loop -eclarations

=hat is the purpose o' allo#in& variable declarations in a #hile statementB

.(ile $ool $ + f)) *,,,2

"oolean b #ill al#as be true until the point #here it is destroed. $t is use'ul in % since inte&ers are

implicitl converted to booleans.

RESOL9-$O: Keep this behavior. =ill be reCuired i' implicit tpe conversion is added to a 'uture

version.

similar issue e2ists in 'or;loops. -he &rammar allo#s constructs such as

for-$ool x + a / $-) -

1!.! Cross Lining ,et#een Shaders

Should it be permissible 'or a 'ra&ment shader to call a 'unction de'ined in a verte2 shader or vice versaB

RESOL9-$O: o, there is no need 'or this behavior.

1!.!2 (isibilit& of -eclarations

t #hat point should a declaration ta8e e''ectB

int x+<-

*

  int x+80 9+x- && 'ase ?

  int "+"- && 'ase 5

2

Option 1: -he name should be visible immediatel a'ter the identi'ier. "oth cases above are le&al. $n

case , is initialied to the value *. -his is consistent #ith c. 4or case ", the use case is to initialie

a variable to point to itsel' e.&. void p T UpM -his is not relevant to GLSL ES.

Option *: -he name should be visible a'ter the initialier ?i' present@, other#ise immediatel a'ter the

identi'ier. $n case , is initialied to *. %ase " is an error ?assumin& no prior declaration o' @.

Option (: -he name should be visible a'ter the declaration. $n case , is initialied to 1. %ase " is an

error i' is has no prior declaration.

139

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 146/155

12 Issues

RESOL9-$O: Option *. !eclarations are visible a'ter the initialier i' present, other#ise a'ter the

identi'ier.

1!.!4 Language (ersion=hat version number should the lan&ua&e haveB -his version o' the lan&ua&e is based on version (.() o'

the des8top GLSL. o#ever it includes a number o' 'eatures that are in version +.*) but not (.(). -he

 previous version o' GLSL ES #as version 1.)) so this version could be called version *.)).

RESOL9-$O: 4ollo# the des8top GLSL convention so that the lan&ua&e version matches the 3$

version. ence this version #ill be called (.))

1!.!5 Samplers

Should samplers be allo#ed as l;valuesB -he speci'ication alread allo#s an eCuivalent behavior:

%urrent speci'ication:

uniform sampler8! samplerAMB-

int index + f,,,)-

ve'7 tex + texturesamplerAindexB0 x9)- && allo.ed

9sin& assi&nment o' sampler tpes:

uniform sampler8! s-

s + g,,,)-

ve'7 tex + textures0 x9)- && not allo.ed

RESOL9-$O: !namic inde2in& o' sampler arras is no# prohibited b the speci'ication. Restrict

inde2in& o' sampler arras to constant inte&ral e2pressions.

1!.30 -&namic Inde)ing4or GLSL ES 1.)), support o' dnamic inde2in& o' arras, vectors and matrices #as not mandated

 because it #as not directl supported b some implementations. So't#are solutions ?via pro&ram

trans'orms@ e2ist 'or a subset o' cases but lead to poor per'ormance. Should support 'or dnamic inde2in&

 be mandated 'or GLSL ES (.))B

RESOL9-$O: <andate support 'or dnamic inde2in& o' arras e2cept 'or sampler arras, 'ra&ment

output arras and uni'orm bloc8 arras.

Should support 'or dnamic inde2in& o' vectors and matrices be mandated in GLSL ES (.))B

RESOL9-$O: `es.

$nde2in& o' arras o' samplers b constant;inde2;e2pressions is supported in GLSL ES 1.)). constant;

inde2;e2pression is an e2pression 'ormed 'rom constant;e2pressions and certain loop indices, de'ined 'or

a subset o' loop constructs. Should this 'unctionalit be included in GLSL ES (.))B

140

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 147/155

12 Issues

RESOL9-$O: o. rras o' samplers ma onl be inde2ed b constant;inte&ral;e2pressions.

1!.31 9a)imum 7umber of Te)ture 6nits

-he minimum number o' te2ture units that must be supported in the 'ra&ment shader is currentl * as

de'ined b &lA<a2-e2ture$ma&e9nits T 5. $s this too lo# 'or GLSL ES (.)B

Option 1: `es, the number o' te2turin& units is the limitin& 'actor 'or 'ra&ment shaders. -he number o'

te2ture units #as increased 'rom 1 to * &oin& 'rom OpenGL ES 1.) to OpenGL ES 1.1 and increased to 5

'or OpenGL ES *.)

RESOL9-$O: $ncrease to 17

1!.3! On8target Error :eporting

Should compilers be reCuired to report an errors at compile time or can errors be de'erred until lin8

timeB

RESOL9-$O: $' a pro&ram cannot be compiled, on;tar&et compilers are onl reCuired to report that an

error has occurred. -his error ma be reported at compile time or lin8 time or both. !evelopment

sstems must &enerate &rammar errors at compile time.

1!.33 :ounding of Integer -iision

Should the roundin& mode be speci'ied 'or inte&er divisionB

-he roundin& mode 'or division is related to the de'inition o' the remainder operator. -he important

relation in most lan&ua&es ?but not relevant in this version o' GLSL ES@ is:

?a > b@ b a b T a ?a and b are inte&ers@

9suall the remainder operator is de'ined to have the same si&n as the dividend #hich implies that divide

must round to#ards ero. ?ote that the modulo 'unction is not the same as the remainder 'unction.<odulo is de'ined to have the same si&n as the divisor@.

-he remainder operator #as not part o' GLSL ES 1.)), so it #as not necessar to speci' the roundin&

mode. $n GLSL ES (.)), the remainder operator is included but the results are unde'ined i' either or both

operands are ne&ative.

RESOL9-$O: -he roundin& mode is unde'ined 'or this version o' the speci'ication.

1!.3% 6ndefined :eturn (alues

$' a 'unction is declared #ith a non;void return tpe, an return statements #ithin the de'inition must

speci' a return e2pression #ith a tpe matchin& the return tpe. o#ever i' the 'unction returns #ithout

e2ecutin& a return statement the behaviour is unde'ined. Should the compiler attempt to chec8 'or these

cases and report them as an errorB

141

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 148/155

12 Issues

E2ample:

int f)

*

  && no return statement

2

,,,

int a + f)-

Option 1: n unde'ined value is returned to the caller. o error is &enerated. -his is #hat most c

compilers do in practice ?althou&h the c standard actuall speci'ies Dunde'ined behaviourD@.

Option *: -here must be a return statement at the end o' all 'unction de'initions that return a value.

 o, this reCuires statements to be added that ma be impossible to e2ecute.

Option (: return statement at the end o' a 'unction de'inition is reCuired onl i' it is possible 'ore2ecution to reaches the end o' the 'unction:

E.&.

int f$ool $)

*

  if $)

  return <-

  else

  return =-

  && No error, (e exe'ution 'an never rea'( t(e end of t(e fun'tion so

  && t(e impli'it return statement is never exe'uted,

2

-his becomes impossible to determine in the presence o' loops.

Option +: ll 'inite static paths throu&h a 'unction de'inition must end #ith a return statement. static

 path is a path that could potentiall be ta8en i' each branch in the code could be controlled independentl.

RESOL9-$O: Option 1: -he 'unction returns an unde'ined value.

1!.3' *recisions of Operations

Should the precision o' operations such as add and multipl be de'inedB

-hese are not de'ined b the % standard but it is &enerall assumed that % implementations #ill use

$EEE 0/+ arithmetic. -his is not true 'or G39s #hich &enerall support onl a subset o' $EEE 0/+. $n

addition, man operations such as the transcendental 'unctions are considered too e2pensive to implement

#ith more than 1) si&ni'icant bits o' precision. !ivision is commonl implemented b reciprocal and

multiplication.

RESOL9-$O: $nclude a table o' precisions 'or operations.

142

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 149/155

12 Issues

1!.3 Compiler Transforms

=hat compiler trans'orms should be allo#edB

% prohibits compiler trans'orms o' e2pressions that alter the 'inal result. ?ote that % allo#s hi&her precisions than speci'ied to be used but this is a di''erent issue.@ G39s commonl ma8e use o' such

trans'orms, 'or e2ample #hen mappin& seCuential code to vector;based architectures.

RESOL9-$O: speci'ied set o' trans'orms ?in addition to those permitted b %@ are allo#ed.

1!.32 E)pansion of +unction8lie 9acros in the *reprocessor 

=hen e2pandin& macros, each macro can onl be applied once to the ori&inal to8en or an to8en

&enerated 'rom that to8en. -o implement this, the e2pansion o' 'unction;li8e macros reCuires a list o'

applied macros 'or each to8en to be maintained. -his is a lar&e overhead.

RESOL9-$O: 4ollo# the % speci'ication.

=hat should the behaviour be i' a directive is encountered durin& e2pansion o' 'unction;li8e macrosB

-his is currentl speci'ied as unde'ined in % althou&h several compilers implement the e2pected

 behavior.

RESOL9-$O: Leave as unde'ined behavior.

1!.34 Should E)tension 9acros be Globall& -efined

4or each e2tension there is an associated macro that the shader can use to determine i' an e2tension is

available on a &iven implementation. Should this macro be de'ined &loball or should it be de'ined #hen

the e2tension is ?success'ull@ enabledB

"oth alternatives are usable since attemptin& to enable an unimplemented e2tension onl results in a

#arnin&.Option 1: Globall de'ined

#ifdef GL_OES_/extension1nameT

  #extension GL_OES_/extension1nameT % ena$le

  ,,,

#endif

Option *: !e'ined as part o' Ne2tension

#extension GL_OES_/extension1nameT % ena$le && .arning if not availa$le

#ifdef GL_OES_/extension1nameT

  ,,,

#endif

RESOL9-$O: -he macros are de'ined &loball. -here should be a #arnin&;'ree path 'or all le&al cases.

143

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 150/155

12 Issues

1!.35 9inimum :e/uirements

GLSL ES 1.)) speci'ied a set o' minimum reCuirements that e''ectivel made parts o' the speci'ication

optional. -he purpose #as to enable lo# cost implementations #hile allo#in& hi&her per'ormancedevices to e2pose 'eatures #ithout recourse to e2tensions. -hat 'le2ibilit came at the cost o' portabilit.

Should the minimum reCuirements section be included as part o' GLSL ES (.))B

RESOL9-$O: o, e2cept 'or the section on countin& o' varin&s.

1!.%0 *acing +unctions

1!.%1 ,oolean logical ector operations

-he lo&ical binar operators and ?UU@, or ? W W @, and e2clusive or ?VV@ operate onl on t#o boolean

e2pressions and result in a boolean e2pression. Should the be e2tended to operate on boolean vectorsB

-he *nd operand is conditionall evaluated 'or these operators.

$ve'7 f)-

 $ve'7 g)-

 

f) UU g)- && g) gets run for some 'omponents $ut not ot(ers,

&& (is isnt .ell defined,

RESOL9-$O: o, these should not be part o' the lan&ua&e.

1!.%! :ange Checing of literals

Should an error be &enerated i' a literal inte&er is outside the ran&e o' a (*;bit inte&erB

-his can be easil chec8ed b the compiler. o#ever, there is a complication because the literal does not

include the minus si&n 'or ne&ative constants. Si&ned inte&ers can be distin&uished 'rom unsi&ned

inte&ers b the DuD su''i2 but the value )25)))))) is onl valid i' preceded b a unar minus.

Option: %hec8 onl that the numeric part o' a literal inte&er ?si&ned or unsi&ned@ is representable b (*

 bits.

Option: $nclude an precedin& unar minus and chec8 that the literal is #ithin the ran&e o' a si&ned or

unsi&ned inte&er as appropriate.

Option: E2tend the chec8in& to an constant inte&ral e2pression.

RESOL9-$O: $t is an error to have a literal unsi&ned inte&er outside the ran&e o' a (*;bit inte&er.

Should this appl to 'loatin&;point numbersB

-he GLSL spec allo#s an arbitrar number o' di&its be'ore the decimal point. $t there'ore possible 'or a

'loat literal to have an arbitraril lar&e number o' characters but still be representable e.&.

144

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 151/155

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 152/155

12 Issues

#version ;== es

Option (: s option * but allo# some 'le2ibilit in the 'ormat so that e2tra #hite;space #ould still be

allo#ed.

Option +: s option * but use a distinctive non;pre;processor 'ormat e.&.

version1;==1es

Option /: s option + but include the characters DglslD to aid identi'ication e.&.

glsl1version1;==1es

RESOL9-$O: Option (. -he version directive is a strin&, present as the onl non;#hite;space in the

'irst line o' the shader. $t is ver unli8el that the character set #ill be chan&ed in an incompatible #a

'rom 9-4;5 in the 'uture. Option ( is the closest in appearance to the current mechanism.

1!.%' 6se of 6nsigned IntegersShould 'unctions that can onl return a positive value e.&. te2tureSie?@ and the len&th?@ method, return

si&ned or unsi&ned valuesB

Option 1: 9nsi&ned inte&er. -his allo#s 'or some de&ree o' compile;time chec8in&. 4or e2ample it

#ould be impossible to accidentall access an arra element #ith a ne&ative inde2 in a tpical

initialiation loop such as:

float aA>B-

for unit i+=u- i/a,lengt( )- iDD)

  aAiB + =,=-

Option *: Si&ned inte&er. -his allo#s &reater 'le2ibilit in calculatin& arra indices #ithout the need 'or

tpe conversions e.&.

float aASIEB-

,,,

int index + a,lengt() 1 ;- && Li$rar9 'ode, SIE ma9 not $e :no.n .(en

  && t(is 'ode is .ritten

if index T+ =) && .ould not .or: .it( an unsigned integer

  faAindexB)-

RESOL9-$O: Option *. -he principle is that inte&ers that represent values and hence ma 'orm part o'

arithmetic e2pressions should al#as be si&ned, even i' it is 8no#n that the #ill al#as be positive.

alues that represent bit vectors should al#as be unsi&ned.

-he e2tra chec8in& made available b the use o' unsi&ned inte&ers 'or values 8no#n to be positive is

minimal. $t #ould be pre'erable to include a range mechanism in a 'uture version o' the lan&ua&e.

146

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 153/155

13 ,c-no.led'#ents

13 cno#ledgments

-his speci'ication is based on the #or8 o' those #ho contributed to the OpenGL (.( Lan&ua&e

Speci'ication, the OpenGL ES *.) Lan&ua&e Speci'ication, and the 'ollo#in& contributors to this version:

corn 3oole, $!$

lberto <oreira, Qualcomm

le8sandra Krstic, Qualcomm

lon Or;"ach, o8ia

ndreF Kacpro#s8i, $ntel

rhan&e Sa'daradeh, $ntel

s8e Simon %hristensen, R<

vi Shapira, Graphic Remed

"arthold Lichtenbelt, $!$

"en "o#man, $ma&ination

-echnolo&ies

"en "rierton, "roadcom

"enF Lipcha8, pple

"enson -ao, ivante

"ill Licea;Kane, <!

"rent $ns8o, $ntel

"rian <urra, 4reescale

"ruce <err, R<

%arlos Santa, -$

%ass Everitt, Epic Games U

 $!$

%emil io&lu, -$

%han&;o `u, Samsun&

%hris !odd, $!$

%hris Kno2, $!$

%hris -sern&, -$

%la <ont&omer, -$

%li'' Gibson, $ma&ination

-echnolo&ies

!aniel Kartch, $!$

!aniel Koch, -rans&amin&!ao2ian& Gon&, $ma&ination

-echnolo&ies

!ave Shreiner, R<

!avid Garcia, <!

!avid Jarmon, ivante

!ere8 %ornish, Epic Games

Eben 9pton, "roadcom

Ed 3lo#man, $ntel U R<

Eisa8u Ohbuchi, !<3

Elan Lennard, R<

Eri8 4ae;Lund, R<

Geor& Kollin&, $ma&ination

-echnolo&ies

Graham %onnor, $ma&ination

-echnolo&ies

Graham Sellers, <!

Gre& Roth, $!$

Guillaume 3ortier, i

Guo'an& Jiao, Qualcomm

ans;<artin =ill, incent

#anon& Lee, uone

$;Gene Leon&, $!$

$an Romanic8, $ntel

$an South;!ic8inson, $!$

$lan elion;E2ch, Samsun&

$n8un Lee, uone

Jacob Strm, Ericsson

James dams, "roadcom

James Jones, $ma&ination

-echnolo&ies

James <c%ombe, $ma&ination

-echnolo&ies

Jamie Gennis, Goo&le

Jan;arald 4redri8sen, R<

Jani aisanen, o8ia

Jar88o Kemppainen, Smbio

Jau8o KlmaoFa, Smbio

Je'' "ol, $!$

Je'' Le&er, Qualcomm

Je'' i&il, Qualcomm

Jerem Sandmel, pple

Jerem -horne, "roadcom

Jim au2#ell, "roadcom

Jinsun& Kim, uone

Jioun& ̀ oon, uone

John Kessenich, LunarG

Jon Kenned, (!Labs

147

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 154/155

13 ,c-no.led'#ents

Jon Leech, Khronos

Jonathan 3utsman, $ma&ination

-echnolo&ies

Jrn stad, R<

Jussi Rasanen, $!$

Kalle Raita, dra#Elements

Kari 3ulli, o8ia

Keith =hit#ell, <#are

Kent <iller, etlo&ic

<icrosstems

Kimmo i88anen, o8ia

Konsta Karsisto, o8ia

Krsto' Kamins8i, $ntel

Larr Seiler, $ntel

Lars Remes, Smbio

Lee -homason, dobe

Le'an hon&, ivante

<arcus Lorenton, Ericsson

<ar8 "utler, $ma&ination

-echnolo&ies

<ar8 %allo#, i

<ar8 %ress#ell, "roadcom

<ar8 Snder, lt So't#are

<ar8 `oun&, <!

<athieu Robart, S-<

<att etsch, Qualcomm

<att Russo, <atro2

<aurice Ribble, <! U

Qualcomm

<a2 Kaa8ov, !<3

<i8a 3esonen, o8ia

<i8e %ai, ivante

<i8e =eiblen, ebra $ma&in&

<ila Smith, <!

 a8hoon "ae8, Kun&poo8

9niverist

 ate uan&, $!$

 eil -revett, $!$

 elson Kidd, $ntel

 ic8 aemel, <! U

 $!$

 ic8 3en#arden, Epic Games

 i8las Smedber&, Epic Games

 iar Romdan, R<

Oliver B, 4uFitsu

3at "ro#n, $!$

3aul Ru&&ieri, Qualcomm

3er =ennersten, Ericsson

3etri -alalla, Smbio

3hil u2le, iiLabs

3hilip atcher, 4reescale

3iers !aniell, $!$

3iotr -omase#s8i, Ericsson

3iotr 9mins8i, $ntel

Rami <aer, Samsun&

Rauli Laati8ainen, Ri&ht=are

Rob "arris, $!$

Rob Simpson, Qualcomm

RoF Lan&hi, ivante

Rune olm, R<

Sami Kostila, o8ia

Sean Ellis, R<

Sheree' Shehata, -$

Sila Kao, o8ia

Sla#omir GraFe#s8i, $ntel

Steve ill, S-< U "roadcom

Steven Olne, !<3

Suman Sharma, $ntel

-apani 3alli, o8ia

-eemu Laa8so, Smbio

-ero Karras, $!$

-imo Suoranta, $ma&ination

-echnolo&ies

-om %oo8se, R<

-om <cRenolds, $!$

-om Olson, -$ U R<

-omi arnio, o8ia

-omm sano, -a8umi

=es "an&, o8ia`anFun han&, ivante

`uan =an&, $ma&ination

-echnolo&ies

148

8/12/2019 GLSL ES Specification 3.00.3

http://slidepdf.com/reader/full/glsl-es-specification-3003 155/155