WebGLRenderingContext.drawElements - Web APIs

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

The WebGLRenderingContext.drawElements() method of the WebGL API renders primitives from array data. WebGLRenderingContext.drawElements() TheWebGLRenderingContext.drawElements()methodoftheWebGLAPIrendersprimitivesfromarraydata. Syntax voidgl.drawElements(mode,count,type,offset); Parameters modeAGLenumspecifyingthetypeprimitivetorender.Possiblevaluesare: gl.POINTS:Drawsasingledot. gl.LINE_STRIP:Drawsastraightlinetothenextvertex.gl.LINE_LOOP:Drawsastraightlinetothenextvertex,andconnectsthelastvertexbacktothefirst. gl.LINES:Drawsalinebetweenapairofvertices.gl.TRIANGLE_STRIPgl.TRIANGLE_FAN gl.TRIANGLES:Drawsatriangleforagroupofthreevertices.countAGLsizeispecifyingthenumberofelementsoftheboundelementarraybuffertoberendered.Forexample,todrawawireframetrianglewithgl.LINESthecountshouldbe2endpointsperline×3lines=6elements.Howevertodrawthesamewireframetrianglewithgl.LINE_STRIPtheelementarraybufferdoesnotrepeattheindicesfortheendofthefirstline/startofthesecondline,andendofthesecondline/startofthethirdline,socountwillbefour.Todrawthesametrianglewithgl.LINE_LOOPtheelementarraybufferdoesnotrepeatthefirst/lastvertexeithersocountwillbethree.typeAGLenumspecifyingthetypeofthevaluesintheelementarraybuffer.Possiblevaluesare:gl.UNSIGNED_BYTEgl.UNSIGNED_SHORTWhenusingtheOES_element_index_uintextension:gl.UNSIGNED_INToffsetAGLintptrspecifyingabyteoffsetintheelementarraybuffer.Mustbeavalidmultipleofthesizeofthegiventype. Returnvalue None. Exceptions Ifmodeisnotoneoftheacceptedvalues,agl.INVALID_ENUMerroristhrown.Ifoffsetisnotavalidmultipleofthesizeofthegiventype,agl.INVALID_OPERATIONerroristhrown.Ifcountisnegative,agl.INVALID_VALUEerroristhrown. Examples gl.drawElements(gl.POINTS,8,gl.UNSIGNED_BYTE,0); Specifications Specification WebGLSpecification(WebGL)#5.14.11 Browsercompatibility Desktop Mobile Chrome Edge Firefox InternetExplorer Opera Safari WebViewAndroid ChromeAndroid FirefoxforAndroid OperaAndroid SafarionIOS SamsungInternet drawElements 9 12 4 11 12 5.1 ≤37 25 Yes 12 8 1.5 Seealso WebGLRenderingContext.drawArrays()OES_element_index_uintWEBGL_multi_draw.multiDrawElementsWEBGL() ©2005–2021MDNcontributors.LicensedundertheCreativeCommonsAttribution-ShareAlikeLicensev2.5orlater. https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements



請為這篇文章評分?