Built-in Variable (GLSL) - OpenGL Wiki - Khronos Group

文章推薦指數: 80 %
投票人數:10人

Fragment Shader · Compute Shader · Other shading languages. The OpenGL Shading Language defines a number of special variables for the various ... Built-inVariable(GLSL) FromOpenGLWiki Jumptonavigation Jumptosearch GLSL OpenGLShadingLanguage Shader Objects Compilation Introspection Thecorelanguage Variabletypes Typequalifiers Layoutqualifiers Uniformvariables Samplervariables Imagevariables Built-invariables Interfaceblocks Uniformblocks Shaderstorageblocks SPIR-V Shaderstages: VertexShader Tessellation GeometryShader FragmentShader ComputeShader Othershadinglanguages TheOpenGLShadingLanguagedefinesanumberofspecialvariablesforthevariousshaderstages.Thesebuilt-invariables(orbuilt-invariables)havespecialproperties.Theyareusuallyforcommunicatingwithcertainfixed-functionality.Byconvention,allpredefinedvariablesstartwith"gl_";nouser-definedvariablesmaystartwiththis. Note:ThispageonlydescribesthecoreOpenGLshadinglanguagepre-definedvariables.Anyvariablesthatarefromthecompatibilityprofilesarenotlistedhere. Contents 1Vertexshaderinputs 2Vertexshaderoutputs 3Tessellationcontrolshaderinputs 4Tessellationcontrolshaderoutputs 5Tessellationevaluationshaderinputs 6Tessellationevaluationshaderoutputs 7Geometryshaderinputs 8Geometryshaderoutputs 9Fragmentshaderinputs 10Fragmentshaderoutputs 11Computeshaderinputs 12Computeshaderothervariables 13Shaderuniforms 14Constants Vertexshaderinputs V·E VertexShadershavethefollowingbuilt-ininputvariables. inintgl_VertexID; inintgl_InstanceID; inintgl_DrawID;//RequiresGLSL4.60orARB_shader_draw_parameters inintgl_BaseVertex;//RequiresGLSL4.60orARB_shader_draw_parameters inintgl_BaseInstance;//RequiresGLSL4.60orARB_shader_draw_parameters gl_VertexID theindexofthevertexcurrentlybeingprocessed.Whenusingnon-indexedrendering,itistheeffectiveindexofthecurrentvertex(thenumberofverticesprocessed+thefirst​value).Forindexedrendering,itistheindexusedtofetchthisvertexfromthebuffer. Note:gl_VertexIDwillhavethebaseVertex​parameteraddedtotheindex,iftherewassuchaparameterintherenderingcommand. gl_InstanceID theindexofthecurrentinstancewhendoingsomeformofinstancedrendering.Theinstancecountalwaysstartsat0,evenwhenusingbaseinstancecalls.Whennotusinginstancedrendering,thisvaluewillbe0. Warning:ThisvaluedoesnotfollowthebaseInstance​providedbysomeinstancedrenderingfunctions.gl_InstanceIDalwaysfallsonthehalf-openrange[0,instancecount​).IfyouhaveGLSL4.60,youmayusegl_BaseInstancetocomputetheproperinstanceindex. gl_DrawID theindexofthedrawingcommandwithinmulti-drawrenderingcommands(includingindirectmulti-drawcommands).ThefirstdrawcommandhasanIDof0,increasingbyoneastherendererpassesthroughdrawingcommands. ThisvaluewillalwaysbeaDynamicallyUniformExpression. gl_BaseVertex thevalueofthebaseVertex​parameteroftherenderingcommand.Iftherenderingcommanddidnotincludethatparameter,thevalueofthisinputwillbe0. gl_BaseInstance thevalueofthebaseInstance​parameteroftheinstancedrenderingcommand.Iftherenderingcommanddidnotincludethisparameter,thevalueofthisinputwillbe0. Vertexshaderoutputs V·E VertexShadershavethefollowingpredefinedoutputs. outgl_PerVertex { vec4gl_Position; floatgl_PointSize; floatgl_ClipDistance[]; }; gl_PerVertexdefinesaninterfaceblockforoutputs.Theblockisdefinedwithoutaninstancename,sothatprefixingthenamesisnotrequired. ThesevariablesonlytakeonthemeaningsbelowifthisshaderisthelastactiveVertexProcessingstage,andifrasterizationisstillactive(ie:GL_RASTERIZER_DISCARDisnotenabled).ThetextbelowexplainshowtheVertexPost-Processingsystemusesthevariables.Thesevariablesmaynotberedeclaredwithinterpolationqualifiers. gl_Position theclip-spaceoutputpositionofthecurrentvertex. gl_PointSize thepixelwidth/heightofthepointbeingrasterized.Itonlyhasameaningwhenrenderingpointprimitives.ItwillbeclampedtotheGL_POINT_SIZE_RANGE. gl_ClipDistance allowstheshadertosetthedistancefromthevertextoeachuser-definedclippinghalf-space.Anon-negativedistancemeansthatthevertexisinside/behindtheclipplane,andanegativedistancemeansitisoutside/infrontoftheclipplane.Eachelementinthearrayisoneclipplane.Inordertousethisvariable,theusermustmanuallyredeclareitwithanexplicitsize.WithGLSL4.10orARB_separate_shader_objects,thewholegl_PerVertexblockneedstoberedeclared.Otherwisejustthegl_ClipDistancebuilt-inneedstoberedeclared. Tessellationcontrolshaderinputs V·E TessellationControlShadersprovidethefollowingbuilt-ininputvariables: inintgl_PatchVerticesIn; inintgl_PrimitiveID; inintgl_InvocationID; gl_PatchVerticesIn thenumberofverticesintheinputpatch. gl_PrimitiveID theindexofthecurrentpatchwithinthisrenderingcommand. gl_InvocationID theindexoftheTCSinvocationwithinthispatch.ATCSinvocationwritestoper-vertexoutputvariablesbyusingthistoindexthem. TheTCSalsotakesthebuilt-invariablesoutputbythevertexshader: ingl_PerVertex { vec4gl_Position; floatgl_PointSize; floatgl_ClipDistance[]; }gl_in[gl_MaxPatchVertices]; Notethatjustbecausegl_inisdefinedtohavegl_MaxPatchVerticesentriesdoesnotmeanthatyoucanaccessbeyondgl_PatchVerticesInandgetreasonablevalues.Thesevariableshaveonlythemeaningthevertexshaderthatpassedthemgavethem. Tessellationcontrolshaderoutputs V·E TessellationControlShadershavethefollowingbuilt-inpatchoutputvariables: patchoutfloatgl_TessLevelOuter[4]; patchoutfloatgl_TessLevelInner[2]; Thesedefinetheouterandinnertessellationlevelsusedbythetessellationprimitivegenerator.Theydefinehowmuchtessellationtoapplytothepatch.Theirexactmeaningdependsonthetypeofpatch(andothersettings)definedintheTessellationEvaluationShader. Note:Ifanyoftheouterlevelsusedbytheabstractpatchtypeis0ornegative(orNaN),thenthepatchwillbediscardedbythegenerator,andnoTESinvocationsforthispatchwillresult. Aswithanyotherpatchvariable,multipleTCSinvocationsforthesamepatchcanwritetothesametessellationlevelvariable,solongastheyareallcomputingandwritingtheexactsamevalue. TCS'salsoprovidethefollowingoptionalper-vertexoutputvariables: outgl_PerVertex { vec4gl_Position; floatgl_PointSize; floatgl_ClipDistance[]; }gl_out[]; TheuseofanyoftheseinaTCSiscompletelyoptional.Indeed,theirsemanticswillgenerallybeofnopracticalvaluetotheTCS.Theyhavethesamegeneralmeaningasforvertexshaders,butsinceaTCSmustalwaysbefollowedbyanevaluationshader,theTCSneverhastowritetoanyofthem. Tessellationevaluationshaderinputs V·E TessellationEvaluationShadershavethefollowingbuilt-ininputs. invec3gl_TessCoord; inintgl_PatchVerticesIn; inintgl_PrimitiveID; gl_TessCoord thelocationwithinthetessellatedabstractpatchforthisparticularvertex.EveryinputparameterotherthanthisonewillbeidenticalforallTESinvocationswithinapatch. Whichcomponentsofthisvec3thathavevalidvaluesdependsontheabstractpatchtype.Forisolinesandquads,onlytheXYcomponentshavevalidvalues.Fortriangles,allthreecomponentshavevalidvalues.Allvalidvaluesarenormalizedfloats(ontherange[0,1]). gl_PatchVerticesIn thevertexcountforthepatchbeingprocessed.ThisiseithertheoutputvertexcountspecifiedbytheTCS,orthepatchvertexsizespecifiedbyglPatchParameterifnoTCSisactive.Attemptstoindexper-vertexinputsbyavaluegreaterthanorequaltogl_PatchVerticesInresultsinundefinedbehavior. gl_PrimitiveID theindexofthecurrentpatchintheseriesofpatchesbeingprocessedforthisdrawcall.Primitiverestart,ifused,hasnoeffectontheprimitiveID. Note:Thetessellationprimitivegeneratorwillcullpatchesthathaveazeroforoneoftheactiveoutertessellationlevels.Theintentofthespecificationseemstobethatgl_PrimitiveIDwillstillbeincrementedforculledpatches.SotheprimitiveIDfortheTESisequivalenttotheIDfortheTCSinvocationsthatgeneratedthatpatch.Butthisisnotentirelyclearfromthespecitself. TheTESalsohasaccesstothetessellationlevelsprovidedforthepatchbytheTCSorbyOpenGL: patchinfloatgl_TessLevelOuter[4]; patchinfloatgl_TessLevelInner[2]; Onlytheouterandinnerlevelsactuallyusedbytheabstractpatcharevalid.Forexample,ifthisTESusesisolines,onlygl_TessLevelOuter[0]andgl_TessLevelOuter[1]willhavevalidvalues. TheTESalsotakesthebuilt-inper-vertexvariablesoutputbytheTCS: ingl_PerVertex { vec4gl_Position; floatgl_PointSize; floatgl_ClipDistance[]; }gl_in[gl_MaxPatchVertices]; Notethatjustbecausegl_inisdefinedtohavegl_MaxPatchVerticesentriesdoesnotmeanthatyoucanaccessbeyondgl_PatchVerticesInandgetreasonablevalues. Tessellationevaluationshaderoutputs V·E TessellationEvaluationShadershavethefollowingbuilt-inoutputs. outgl_PerVertex{ vec4gl_Position; floatgl_PointSize; floatgl_ClipDistance[]; }; gl_PerVertexdefinesaninterfaceblockforoutputs.Theblockisdefinedwithoutaninstancename,sothatprefixingthenamesisnotrequired. ThesevariablesonlytakeonthemeaningsbelowifthisshaderisthelastactiveVertexProcessingstage,andifrasterizationisstillactive(ie:GL_RASTERIZER_DISCARDisnotenabled).ThetextbelowexplainshowtheVertexPost-Processingsystemusesthevariables.Thesevariablesmaynotberedeclaredwithinterpolationqualifiers. gl_Position theclip-spaceoutputpositionofthecurrentvertex. gl_PointSize thepixelwidth/heightofthepointbeingrasterized.Itonlyhasameaningwhenrenderingpointprimitives,whichinaTESrequiresusingthepoint_mode​inputlayoutqualifier. gl_ClipDistance allowstheshadertosetthedistancefromthevertextoeachUser-DefinedClipPlane.Apositivedistancemeansthatthevertexisinside/behindtheclipplane,andanegativedistancemeansitisoutside/infrontoftheclipplane.Eachelementinthearrayisoneclipplane.Inordertousethisvariable,theusermustmanuallyredeclareitwithanexplicitsize. Geometryshaderinputs V·E GeometryShadersprovidethefollowingbuilt-ininputvariables: ingl_PerVertex { vec4gl_Position; floatgl_PointSize; floatgl_ClipDistance[]; }gl_in[]; Thesevariableshaveonlythemeaningthepriorshaderstage(s)thatpassedthemgavethem. TherearesomeGSinputvaluesthatarebasedonprimitives,notvertices.Thesearenotaggregatedintoarrays.Theseare: inintgl_PrimitiveIDIn; inintgl_InvocationID;//RequiresGLSL4.0orARB_gpu_shader5 gl_PrimitiveIDIn thecurrentinputprimitive'sID,basedonthenumberofprimitivesprocessedbytheGSsincethecurrentdrawingcommandstarted. gl_InvocationID thecurrentinstance,asdefinedwheninstancinggeometryshaders. Geometryshaderoutputs V·E GeometryShadershavethefollowingbuilt-inoutputs. outgl_PerVertex { vec4gl_Position; floatgl_PointSize; floatgl_ClipDistance[]; }; gl_PerVertexdefinesaninterfaceblockforoutputs.Theblockisdefinedwithoutaninstancename,sothatprefixingthenamesisnotrequired. TheGSisthefinalVertexProcessingstage.Therefore,unlessrasterizationisbeingturnedoff,youmustwritetosomeofthesevalues.Theseoutputsarealwaysassociatedwithstream0.Soifyou'reemittingverticestoadifferentstream,youdon'thavetowritetothem. gl_Position theclip-spaceoutputpositionofthecurrentvertex.Thisvaluemustbewrittenifyouareemittingavertextostream0,unlessrasterizationisoff. gl_PointSize thepixelwidth/heightofthepointbeingrasterized.Itisonlynecessarytowritetothiswhenoutputtingpointprimitives. gl_ClipDistance allowstheshadertosetthedistancefromthevertextoeachUser-DefinedClipPlane.Apositivedistancemeansthatthevertexisinside/behindtheclipplane,andanegativedistancemeansitisoutside/infrontoftheclipplane.Inordertousethisvariable,theusermustmanuallyredeclareit(andthereforetheinterfaceblock)withanexplicitsize. Certainpredefinedoutputshavespecialmeaningandsemantics. outintgl_PrimitiveID; TheprimitiveIDwillbepassedtothefragmentshader.TheprimitiveIDforaparticularline/trianglewillbetakenfromtheprovokingvertexofthatline/triangle,somakesurethatyouarewritingthecorrectvaluefortherightprovokingvertex. Themeaningforthisvalueiswhateveryouwantittobe.However,ifyouwanttomatchthestandardOpenGLmeaning(ie:whattheFragmentShaderwouldgetifnoGSwereused),youmustdothisforeachvertexbeforeemittingit: gl_PrimitiveID=gl_PrimitiveIDIn; ThisnaturallyassumesthatthenumberofprimitivesoutputbytheGSequalsthenumberofprimitivesreceivedbytheGS. V·E LayeredrenderingintheGSworksviatwospecialoutputvariables: outintgl_Layer; outintgl_ViewportIndex;//RequiresGL4.1orARB_viewport_array. Thegl_Layeroutputdefineswhichlayerinthelayeredimagetheprimitivegoesto.Eachvertexintheprimitivemustgetthesamelayerindex.Notethatwhenrenderingtocubemaparrays,thegl_Layervaluerepresentslayer-faces(thefaceswithinalayer),notthelayersofcubemaps. gl_ViewportIndex,whichrequiresGL4.1orARB_viewport_array,specifieswhichviewportindextousewiththisprimitive. Note:ARB_viewport_array,whiletechnicallya4.1feature,iswidelyavailableon3.3hardware,frombothNVIDIAandAMD. Fragmentshaderinputs V·E FragmentShadershavethefollowingbuilt-ininputvariables. invec4gl_FragCoord; inboolgl_FrontFacing; invec2gl_PointCoord; gl_FragCoord Thelocationofthefragmentinwindowspace.TheX,YandZcomponentsarethewindow-spacepositionofthefragment.TheZvaluewillbewrittentothedepthbufferifgl_FragDepthisnotwrittentobythisshaderstage.TheWcomponentofgl_FragCoordis1/Wclip,whereWclipistheinterpolatedWcomponentoftheclip-spacevertexpositionoutputtogl_PositionfromthelastVertexProcessingstage. Thespaceofgl_FragCoordcanbemodifiedbyredeclaringgl_FragCoordwithspecialinputlayoutqualifiers: layout(origin_upper_left)invec4gl_FragCoord; Thismeansthattheoriginforgl_FragCoord'swindow-spacewillbetheupper-leftofthescreen,ratherthantheusuallower-left. layout(pixel_center_integer​)invec4gl_FragCoord; OpenGLwindowspaceisdefinedsuchthatpixelcentersareonhalf-integerboundaries.Sothecenterofthelower-leftpixelis(0.5,0.5).Usingpixel_center_integer​adjustgl_FragCoordsuchthatwholeintegervaluesrepresentpixelcenters. BothoftheseexisttobecompatiblewithD3D'swindowspace.Unlessyouneedyourshaderstohavethiscompatibility,youareadvisednottousethesefeatures. gl_FrontFacing Thisisfalseifthefragmentwasgeneratedbytheback-faceoftheprimitive;itistrueinallothercases(includingPrimitivesthathavenobackface). gl_PointCoord Thelocationwithinapointprimitivethatdefinesthepositionofthefragmentrelativetothesideofthepoint.Pointsareeffectivelyrasterizedaswindow-spacesquaresofacertainpixelsize.Sincepointsaredefinedbyasinglevertex,theonlywaytotellwhereinthatsquareaparticularfragmentisiswithgl_PointCoord. Thevaluesofgl_PointCoord'scoordinatesrangefrom[0,1].OpenGLusesaupper-leftoriginforpoint-coordinatesbydefault,so(0,0)istheupper-left.However,theorigincanbeswitchedtoabottom-leftoriginbycallingglPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN,GL_LOWER_LEFT); OpenGL4.0andabovedefineadditionalsystem-generatedinputvalues: inintgl_SampleID; invec2gl_SamplePosition; inintgl_SampleMaskIn[]; gl_SampleID Thisisanintegeridentifierforthecurrentsamplethatthisfragmentisrasterizedfor. Warning:Anyuseofthisvariableatallwillforcethisshadertobeevaluatedper-sample.Sincemuchofthepointofmultisamplingistoavoidthat,youshoulduseitonlywhenyoumust. gl_SamplePosition Thisisthelocationofthecurrentsampleforthefragmentwithinthepixel'sarea,withvaluesontherange[0,1].Theoriginisthebottom-leftofthepixelarea. Warning:Anyuseofthisvariableatallwillforcethisshadertobeevaluatedper-sample.Sincemuchofthepointofmultisamplingistoavoidthat,youshoulduseitonlywhenyoumust. gl_SampleMaskIn Whenusingmultisampling,thisvariablecontainsabitfieldforthesamplemaskofthefragmentbeinggenerated.ThearrayisaslongasneededtofillinthenumberofsamplessupportedbytheGLimplementation. SomeFragmentshaderbuilt-ininputswilltakevaluesspecifiedbyOpenGL,butthesevaluescanbeoverriddenbyusercontrol. infloatgl_ClipDistance[]; inintgl_PrimitiveID; gl_ClipDistance Thisarraycontainstheinterpolatedclippingplanehalf-spaces,asoutputforverticesfromthelastVertexProcessingstage. gl_PrimitiveID Thisvalueistheindexofthecurrentprimitivebeingrenderedbythisdrawingcommand.ThisincludesanyTessellationappliedtothemesh,soeachindividualprimitivewillhaveauniqueindex. However,ifaGeometryShaderisactive,thenthegl_PrimitiveIDisexactlyandonlywhattheGSprovidedasoutput.Normally,gl_PrimitiveIDisguaranteedtobeunique,soiftwoFSinvocationshavethesameprimitiveID,theycomefromthesameprimitive.ButifaGSisactiveandoutputsnon-uniquevalues,thendifferentfragmentshaderinvocationsfordifferentprimitiveswillgetthesamevalue.IftheGSdidnotoutputavalueforgl_PrimitiveID,thenthefragmentshadergetsanundefinedvalue. Warning:Theabovediscussionofgl_PrimitiveIDisbasedonaparticularreadingoftheOpenGL4.6specification.However,thespecificationitselfissomewhatinconsistentwiththisview,suggestingthattheprimitiveIDmayonlygetincrementedbasedondatafedtothesystem,notdatageneratedby,forexample,thetessellator.AndtheVulkanspecificationseemstoconcurwiththisinterpretation,andatleastoneimplementationisknowntoagreewiththataswell.Untilthereissomeclarificationontheissue,youshouldconsidertheabovetobequestionable. GL4.3providesthefollowingadditionalinputs: inintgl_Layer; inintgl_ViewportIndex; gl_Layer Thisiseither0orthelayernumberforthisprimitiveoutputbytheGeometryShader. gl_ViewportIndex Thisiseither0ortheviewportindexforthisprimitiveoutputbytheGeometryShader. Fragmentshaderoutputs V·E FragmentShadershavethefollowingbuilt-inoutputvariables. outfloatgl_FragDepth; gl_FragDepth Thisoutputisthefragment'sdepth.Iftheshaderdoesnotstaticallywritethisvalue,thenitwilltakethevalueofgl_FragCoord.z. To"staticallywrite"toavariablemeansthatyouwritetoitanywhereintheprogram.Evenifthewritingcodeistechnicallyunreachableforsomereason,ifthereisagl_FragDepth=...expressionanywhereintheshader,thenitisstaticallywritten. Warning:Ifthefragmentshaderstaticallywritestogl_FragDepth,thenitistheresponsibilityoftheshadertostaticallywritetothevalueinallcircumstances.Nomatterwhatbranchesmayormaynotbetaken,theshadermustensurethatthevalueiswritten.So,ifyouconditionallywritetoitinoneplace,youshouldatleastmakesurethatthereisasinglenon-conditionalwritesometimebeforethat. GLSL4.20orARB_conservative_depthallowstheusertospecifythatmodificationstogl_FragDepth(relativetothegl_FragCoord.zvalueitwouldhaveotherwisehad)willhappenincertainways.ThisallowstheimplementationthefreedomtonotturnoffEarlyDepthTestsincertainsituations. Thisisdonebyre-declaringgl_FragDepthwithaspeciallayoutqualifier: layout(depth_)outfloatgl_FragDepth; Thecondition​canbeoneofthefollowing: any Thedefault.Youmayfreelychangethedepth,butyoulosethemostpotentialperformance. greater Youwillonlymakethedepthlarger,comparedtogl_FragCoord.z. less Youwillonlymakethedepthsmaller,comparedtogl_FragCoord.z. unchanged Ifyouwritetogl_FragDepth,youwillwriteexactlygl_FragCoord.z. Violatingthecondition​yieldsundefinedbehavior. GLSL4.00orARB_sample_shadingbringsus: outintgl_SampleMask[]; gl_SampleMask Thisdefinesthesamplemaskforthefragmentwhenperformingmutlisampledrendering.Ifashaderdoesnotstaticallywritetoit,thenitwillbefilledinbygl_SampleMaskIn.ThesamplemaskoutputherewillbelogicallyAND'dwiththesamplemaskcomputedbytherasterizer. Warning:Justaswithgl_FragDepth,ifafragmentshaderwritestogl_SampleMaskatall,itmustmakesuretowritetothevalueforallexecutionpaths.Butitmustalsomakesuretowritetoeachelementinthearray.Thearrayhasthesamesizeasgl_SampleMaskIn. Computeshaderinputs V·E ComputeShadershavethefollowingbuilt-ininputvariables. inuvec3gl_NumWorkGroups; inuvec3gl_WorkGroupID; inuvec3gl_LocalInvocationID; inuvec3gl_GlobalInvocationID; inuintgl_LocalInvocationIndex; gl_NumWorkGroups Thisvariablecontainsthenumberofworkgroupspassedtothedispatchfunction. gl_WorkGroupID Thisisthecurrentworkgroupforthisshaderinvocation.EachoftheXYZcomponentswillbeonthehalf-openrange[0,gl_NumWorkGroups.XYZ). gl_LocalInvocationID Thisisthecurrentinvocationoftheshaderwithintheworkgroup.EachoftheXYZcomponentswillbeonthehalf-openrange[0,gl_WorkGroupSize.XYZ). gl_GlobalInvocationID Thisvalueuniquelyidentifiesthisparticularinvocationofthecomputeshaderamongallinvocationsofthiscomputedispatchcall.It'sashort-handforthemathcomputation: gl_WorkGroupID*gl_WorkGroupSize+gl_LocalInvocationID; gl_LocalInvocationIndex Thisisa1Dversionofgl_LocalInvocationID.Itidentifiesthisinvocation'sindexwithintheworkgroup.Itisshort-handforthismathcomputation: gl_LocalInvocationIndex= gl_LocalInvocationID.z*gl_WorkGroupSize.x*gl_WorkGroupSize.y+ gl_LocalInvocationID.y*gl_WorkGroupSize.x+ gl_LocalInvocationID.x; Computeshaderothervariables constuvec3gl_WorkGroupSize;//GLSL≥4.30 Thegl_WorkGroupSizevariableisaconstantthatcontainsthelocalwork-groupsizeoftheshader,in3dimensions.Itisdefinedbythelayoutqualifierslocal_size_x/y/z.Thisisacompile-timeconstant. Shaderuniforms V·E Shadersdefinethefollowinguniforms. structgl_DepthRangeParameters { floatnear; floatfar; floatdiff; }; uniformgl_DepthRangeParametersgl_DepthRange; uniformintgl_NumSamples;//GLSL4.20 ThisstructprovidesaccesstotheglDepthRangenearandfarvalues.Thediffvalueisthefarvalueminusthenearvalue.DorecallthatOpenGLmakesnorequirementthatfarisgreaterthannear.WithregardtomultipleViewports,gl_DepthRangeonlystorestherangeforviewport0. gl_NumSamplesisthenumberofsamplesinthecurrentFramebuffer.Iftheframebufferisnotmultisampled,thenthisvaluewillbe1. Constants Therearemanyimplementation-definedshaderstagelimitswho'svalueswouldbeusefultoaparticularshader.GLSLprovidesanumberofconstantintegervariablesthatgivethesevaluestoshaders.Allofthesevaluesareavailabletoallshaderstages. Allofthesevariablesaredeclaredasconst,sotheyareconsideredconstantexpressions.TheseconstantsarenamedbasedontheOpenGLenumeratorsusedtospecifythoselimitations.Thetransformationisquitesimple:taketheGLSLname,putanunderscorebeforeeverycapitalletter(unlessthere'sonetherealready),andthenmakealltheletterscapital. Thevariablesareasfollows: MinimumRequiredValue Type Name GL3.3 GL4.4 int gl_MaxVertexAttribs 16 int gl_MaxVertexOutputComponents 64 int gl_MaxVertexUniformComponents 1024 int gl_MaxVertexTextureImageUnits 16 int gl_MaxGeometryInputComponents 64 int gl_MaxGeometryOutputComponents 128 int gl_MaxGeometryUniformComponents 1024 int gl_MaxGeometryTextureImageUnits 16 int gl_MaxGeometryOutputVertices 256 int gl_MaxGeometryTotalOutputComponents 1024 int gl_MaxGeometryVaryingComponents 64 int gl_MaxFragmentInputComponents 128 int gl_MaxDrawBuffers 8 int gl_MaxFragmentUniformComponents 1024 int gl_MaxTextureImageUnits1 16 int gl_MaxClipDistances 8 int gl_MaxCombinedTextureImageUnits 48 96 RequiresOpenGL4.0 int gl_MaxTessControlInputComponents N/A 128 int gl_MaxTessControlOutputComponents N/A 128 int gl_MaxTessControlUniformComponents N/A 1024 int gl_MaxTessControlTextureImageUnits N/A 16 int gl_MaxTessControlTotalOutputComponents N/A 4096 int gl_MaxTessEvaluationInputComponents N/A 128 int gl_MaxTessEvaluationOutputComponents N/A 128 int gl_MaxTessEvaluationUniformComponents N/A 1024 int gl_MaxTessEvaluationTextureImageUnits N/A 16 int gl_MaxTessPatchComponents N/A 120 int gl_MaxPatchVertices N/A 32 int gl_MaxTessGenLevel N/A 64 RequiresOpenGL4.1 int gl_MaxViewports N/A 16 int gl_MaxVertexUniformVectors N/A 256 int gl_MaxFragmentUniformVectors N/A 256 int gl_MaxVaryingVectors N/A 15 RequiresOpenGL4.2 int gl_MaxVertexImageUniforms N/A 0 int gl_MaxVertexAtomicCounters N/A 0 int gl_MaxVertexAtomicCounterBuffers N/A 0 int gl_MaxTessControlImageUniforms N/A 0 int gl_MaxTessControlAtomicCounters N/A 0 int gl_MaxTessControlAtomicCounterBuffers N/A 0 int gl_MaxTessEvaluationImageUniforms N/A 0 int gl_MaxTessEvaluationAtomicCounters N/A 0 int gl_MaxTessEvaluationAtomicCounterBuffers N/A 0 int gl_MaxGeometryImageUniforms N/A 0 int gl_MaxGeometryAtomicCounters N/A 0 int gl_MaxGeometryAtomicCounterBuffers N/A 0 int gl_MaxFragmentImageUniforms N/A 8 int gl_MaxFragmentAtomicCounters N/A 8 int gl_MaxFragmentAtomicCounterBuffers N/A 1 int gl_MaxCombinedImageUniforms N/A 8 int gl_MaxCombinedAtomicCounters N/A 8 int gl_MaxCombinedAtomicCounterBuffers N/A 1 int gl_MaxImageUnits N/A 8 int gl_MaxCombinedImageUnitsAndFragmentOutputs N/A 8 int gl_MaxImageSamples N/A 0 int gl_MaxAtomicCounterBindings N/A 1 int gl_MaxAtomicCounterBufferSize N/A 32 int gl_MinProgramTexelOffset N/A -8 int gl_MaxProgramTexelOffset N/A 7 RequiresOpenGL4.3 ivec3 gl_MaxComputeWorkGroupCount N/A {65535,65535,65535} ivec3 gl_MaxComputeWorkGroupSize N/A {1024,1024,64} int gl_MaxComputeUniformComponents N/A 512 int gl_MaxComputeTextureImageUnits N/A 16 int gl_MaxComputeImageUniforms N/A 8 int gl_MaxComputeAtomicCounters N/A 8 int gl_MaxComputeAtomicCounterBuffers N/A 1 RequiresOpenGL4.4 int gl_MaxTransformFeedbackBuffers N/A 4 int gl_MaxTransformFeedbackInterleavedComponents N/A 64 1:Thisisthenumberoffragmentshadertextureimageunits. Retrievedfrom"http://www.khronos.org/opengl/wiki_opengl/index.php?title=Built-in_Variable_(GLSL)&oldid=12444" Categories:PagesusingdeprecatedsourcetagsOpenGLShadingLanguage Navigationmenu Personaltools CreateaccountLogin Namespaces PageDiscussion Variants Views ReadViewsourceViewhistory More Search Navigation MainPageGettingStartedDownloadOpenGLRegistryReferencePagesReferenceGuideNewsCommunityForumsAboutOpenGL Help ContactUsPrivacyPolicyHelpEditingRecentchanges Tools WhatlinkshereRelatedchangesSpecialpagesPrintableversionPermanentlinkPageinformationCitethispage



請為這篇文章評分?