WebGLRenderingContext.enableVertexAttribArray() - Web APIs

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

The WebGLRenderingContext method enableVertexAttribArray(), part of the WebGL API, turns on the generic vertex attribute array at the ... SkiptomaincontentSkiptosearchSkiptoselectlanguageReferencesWebAPIsWebGLRenderingContextWebGLRenderingContext.enableVertexAttribArray()ArticleActionsEnglish(US)SyntaxExamplesSpecificationsBrowsercompatibilitySeealsoRelatedTopicsWebGLAPIWebGLRenderingContextPropertiescanvasdrawingBufferHeightdrawingBufferWidthMethodsactiveTexture()attachShader()bindAttribLocation()bindBuffer()bindFramebuffer()bindRenderbuffer()bindTexture()blendColor()blendEquation()blendEquationSeparate()blendFunc()blendFuncSeparate()bufferData()bufferSubData()checkFramebufferStatus()clear()clearColor()clearDepth()clearStencil()colorMask() Experimental commit()compileShader()compressedTexImage[23]D()compressedTexSubImage2D()copyTexImage2D()copyTexSubImage2D()createBuffer()createFramebuffer()createProgram()createRenderbuffer()createShader()createTexture()cullFace()deleteBuffer()deleteFramebuffer()deleteProgram()deleteRenderbuffer()deleteShader()deleteTexture()depthFunc()depthMask()depthRange()detachShader()disable()disableVertexAttribArray()drawArrays()drawElements()enable()enableVertexAttribArray()finish()flush()framebufferRenderbuffer()framebufferTexture2D()frontFace()generateMipmap()getActiveAttrib()getActiveUniform()getAttachedShaders()getAttribLocation()getBufferParameter()getContextAttributes()getError()getExtension()getFramebufferAttachmentParameter()getParameter()getProgramInfoLog()getProgramParameter()getRenderbufferParameter()getShaderInfoLog()getShaderParameter()getShaderPrecisionFormat()getShaderSource()getSupportedExtensions()getTexParameter()getUniform()getUniformLocation()getVertexAttrib()getVertexAttribOffset()hint()isBuffer()isContextLost()isEnabled()isFramebuffer()isProgram()isRenderbuffer()isShader()isTexture()lineWidth()linkProgram()makeXRCompatible()pixelStorei()polygonOffset()readPixels()renderbufferStorage()sampleCoverage()scissor()shaderSource()stencilFunc()stencilFuncSeparate()stencilMask()stencilMaskSeparate()stencilOp()stencilOpSeparate()texImage2D()texParameter[fi]()texSubImage2D()uniform[1234][fi][v]()uniformMatrix[234]fv()useProgram()validateProgram()vertexAttrib[1234]f[v]()vertexAttribPointer()viewport()RelatedpagesforWebGLANGLE_instanced_arraysEXT_blend_minmaxEXT_color_buffer_half_floatEXT_disjoint_timer_queryEXT_frag_depthEXT_sRGBEXT_shader_texture_lodEXT_texture_filter_anisotropicOES_element_index_uintOES_standard_derivativesOES_texture_floatOES_texture_float_linearOES_texture_half_floatOES_texture_half_float_linearOES_vertex_array_objectWEBGL_color_buffer_floatWEBGL_compressed_texture_etc1WEBGL_compressed_texture_pvrtcWEBGL_compressed_texture_s3tcWEBGL_compressed_texture_s3tc_srgbWEBGL_debug_renderer_infoWEBGL_debug_shadersWEBGL_depth_textureWEBGL_draw_buffersWEBGL_lose_contextWebGL2RenderingContextWebGLActiveInfoWebGLBufferWebGLContextEventWebGLFramebufferWebGLObjectWebGLProgramWebGLQueryWebGLRenderbufferWebGLSamplerWebGLShaderWebGLShaderPrecisionFormatWebGLSyncWebGLTextureWebGLTransformFeedbackWebGLUniformLocationWebGLVertexArrayObjectSyntaxExamplesSpecificationsBrowsercompatibilitySeealsoWebGLRenderingContext.enableVertexAttribArray() TheWebGLRenderingContextmethod enableVertexAttribArray(),partoftheWebGLAPI,turnsonthegenericvertex attributearrayatthespecifiedindexintothelistofattributearrays. Note:Youcandisabletheattributearraybycalling disableVertexAttribArray(). InWebGL,valuesthatapplytoaspecificvertexarestoredinattributes.Theseareonly availabletotheJavaScriptcodeandthevertexshader.Attributesarereferencedbyan indexnumberintothelistofattributesmaintainedbytheGPU.Somevertexattribute indicesmayhavepredefinedpurposes,dependingontheplatformand/ortheGPU.Others areassignedbytheWebGLlayerwhenyoucreatetheattributes. Eitherway,sinceattributescannotbeusedunlessenabled,andaredisabledby default,youneedtocallenableVertexAttribArray()toenableindividual attributessothattheycanbeused.Oncethat'sbeendone,othermethodscanbeusedto accesstheattribute,includingvertexAttribPointer(),vertexAttrib*(),andgetVertexAttrib(). SyntaxenableVertexAttribArray(index) Parameters index AGLuintspecifyingtheindexnumberthatuniquelyidentifiesthe vertexattributetoenable.Ifyouknowthenameoftheattributebutnotitsindex, youcangettheindexbycallinggetAttribLocation(). ReturnvalueNone(undefined).Errors TocheckforerrorsaftercallingenableVertexAttribArray(),call getError(). WebGLRenderingContext.INVALID_VALUE Thespecifiedindexisinvalid;thatis,it'sgreaterthanorequalto themaximumnumberofentriespermittedinthecontext'svertexattributelist,as indicatedbythevalueofWebGLRenderingContext.MAX_VERTEX_ATTRIBS. Examples Thiscode—asnippettakenfromthefullexampleAbasic2DWebGLanimationexample—showstheuseofenableVertexArray()toactivate theattributethatwillbeusedbytheWebGLlayertopassindividualvertexesfromthe vertexbufferintothevertexshaderfunction. gl.bindBuffer(gl.ARRAY_BUFFER,vertexBuffer); aVertexPosition= gl.getAttribLocation(shaderProgram,"aVertexPosition"); gl.enableVertexAttribArray(aVertexPosition); gl.vertexAttribPointer(aVertexPosition,vertexNumComponents, gl.FLOAT,false,0,0); gl.drawArrays(gl.TRIANGLES,0,vertexCount); Note:ThiscodesnippetistakenfromthefunctionanimateScene()in"Abasic2DWebGLanimationexample."See thatarticleforthefullsampleandtoseetheresultinganimationinaction. Thiscodesetsthebufferofvertexesthatwillbeusedtodrawthetrianglesofthe shapebycallingbindBuffer().Then thevertexpositionattribute'sindexisobtainedfromtheshaderprogrambycalling getAttribLocation(). Withtheindexofthevertexpositionattributenowavailablein aVertexPosition,wecallenableVertexAttribArray()toenable thepositionattributesoitcanbeusedbytheshaderprogram(inparticular,bythe vertexshader). ThenthevertexbufferisboundtotheaVertexPositionattributeby callingvertexAttribPointer().Thisstepisnotobvious,sincethisbindingisalmosta sideeffect.Butasaresult,accessingaVertexPositionnowobtainsdata fromthevertexbuffer. Withtheassociationinplacebetweenthevertexbufferforourshapeandthe aVertexPositionattributeusedtodeliververtexesonebyoneintothe vertexshader,we'rereadytodrawtheshapebycalling drawArrays(). SpecificationsSpecificationWebGLSpecification#5.14.10BrowsercompatibilityBCDtablesonlyloadinthebrowserSeealso DatainWebGL Adding2DcontenttoaWebGLcontext Abasic2DWebGLanimationsample disableVertexAttribArray() Foundaproblemwiththispage?EditonGitHubSourceonGitHubReportaproblemwiththiscontentonGitHubWanttofixtheproblemyourself?SeeourContributionguide.Lastmodified:Jun11,2022,byMDNcontributors



請為這篇文章評分?