WebGLRenderingContext.drawElements - Web APIs
文章推薦指數: 80 %
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
延伸文章資訊
- 1glDrawElements
- 2WebGLRenderingContext.drawElements() - Web API 接口参考
该 WebGLRenderingContext.drawElements() 方法在 WebGL API 从数组数据渲染图元。 语法. void gl .drawElements( mode ,...
- 3WebGL顶点索引绘制drawElements()_郭隆邦技术博客
WebGL为了复用顶点数据新引入了一个绘制方法drawElements(),drawElements()方法和drawArrays()方法一样都是命令浏览器WebGL图形系统开始处理顶点绘制渲染...
- 4WebGL Indexed Vertices
drawElements . There are 2 basic drawing functions in WebGL. gl.drawArrays and gl.drawElements . ...
- 5[Day7] webGL修羅道(4) - 3D 與動畫 - iT 邦幫忙
drawElements 的不同點在於,你可以自己選擇要繪製的頂點數量和開始位置(index)。 所以接下來要做的事情就是建立一個繪製頂點的index array,讓webGL 如何重複使用這些...