WebGLRenderingContext

WebGLRenderingContext

WebGLRenderingContext 接口提供基于 OpenGL ES 2.0 的绘图上下文,用于在 HTML 元素内绘图。

要获得这个接口的对象,可以通过在 元素上调用 getContext() 函数,调用时传入 “webgl” 参数:

var canvas = document.getElementById('myCanvas');
var gl = canvas.getContext('webgl');

当你获取到 canvas 元素的 WebGL 绘图上下文,你便可以在里面绘图。

WebGLRenderingContext

深入了解webgl接口参数

gl.drawArrays

void gl.drawArrays(mode, first, count);
mode

GLenum 类型,指定绘制图元的方式,可能值如下。
gl.POINTS: 绘制一系列点。
gl.LINE_STRIP: 绘制一个线条。即,绘制一系列线段,上一点连接下一点。
gl.LINE_LOOP: 绘制一个线圈。即,绘制一系列线段,上一点连接下一点,并且最后一点与第一个点相连。
gl.LINES: 绘制一系列单独线段。每两个点作为端点,线段之间不连接。
gl.TRIANGLE_STRIP:绘制一个三角带。
gl.TRIANGLE_FAN:绘制一个三角扇。
gl.TRIANGLES: 绘制一系列三角形。每三个点作为顶点。

first

GLint 类型 ,指定从哪个点开始绘制。

count

GLsizei 类型,指定绘制需要使用到多少个点。

296个属性,139个方法。

  1. ACTIVE_ATTRIBUTES: 35721
  2. ACTIVE_TEXTURE: 34016
  3. ACTIVE_UNIFORMS: 35718
  4. ALIASED_LINE_WIDTH_RANGE: 33902
  5. ALIASED_POINT_SIZE_RANGE: 33901
  6. ALPHA: 6406
  7. ALPHA_BITS: 3413
  8. ALWAYS: 519
  9. ARRAY_BUFFER: 34962
  10. ARRAY_BUFFER_BINDING: 34964
  11. ATTACHED_SHADERS: 35717
  12. BACK: 1029
  13. BLEND: 3042
  14. BLEND_COLOR: 32773
  15. BLEND_DST_ALPHA: 32970
  16. BLEND_DST_RGB: 32968
  17. BLEND_EQUATION: 32777
  18. BLEND_EQUATION_ALPHA: 34877
  19. BLEND_EQUATION_RGB: 32777
  20. BLEND_SRC_ALPHA: 32971
  21. BLEND_SRC_RGB: 32969
  22. BLUE_BITS: 3412
  23. BOOL: 35670
  24. BOOL_VEC2: 35671
  25. BOOL_VEC3: 35672
  26. BOOL_VEC4: 35673
  27. BROWSER_DEFAULT_WEBGL: 37444
  28. BUFFER_SIZE: 34660
  29. BUFFER_USAGE: 34661
  30. BYTE: 5120
  31. CCW: 2305
  32. CLAMP_TO_EDGE: 33071
  33. COLOR_ATTACHMENT0: 36064
  34. COLOR_BUFFER_BIT: 16384
  35. COLOR_CLEAR_VALUE: 3106
  36. COLOR_WRITEMASK: 3107
  37. COMPILE_STATUS: 35713
  38. COMPRESSED_TEXTURE_FORMATS: 34467
  39. CONSTANT_ALPHA: 32771
  40. CONSTANT_COLOR: 32769
  41. CONTEXT_LOST_WEBGL: 37442
  42. CULL_FACE: 2884
  43. CULL_FACE_MODE: 2885
  44. CURRENT_PROGRAM: 35725
  45. CURRENT_VERTEX_ATTRIB: 34342
  46. CW: 2304
  47. DECR: 7683
  48. DECR_WRAP: 34056
  49. DELETE_STATUS: 35712
  50. DEPTH_ATTACHMENT: 36096
  51. DEPTH_BITS: 3414
  52. DEPTH_BUFFER_BIT: 256
  53. DEPTH_CLEAR_VALUE: 2931
  54. DEPTH_COMPONENT: 6402
  55. DEPTH_COMPONENT16: 33189
  56. DEPTH_FUNC: 2932
  57. DEPTH_RANGE: 2928
  58. DEPTH_STENCIL: 34041
  59. DEPTH_STENCIL_ATTACHMENT: 33306
  60. DEPTH_TEST: 2929
  61. DEPTH_WRITEMASK: 2930
  62. DITHER: 3024
  63. DONT_CARE: 4352
  64. DST_ALPHA: 772
  65. DST_COLOR: 774
  66. DYNAMIC_DRAW: 35048
  67. ELEMENT_ARRAY_BUFFER: 34963
  68. ELEMENT_ARRAY_BUFFER_BINDING: 34965
  69. EQUAL: 514
  70. FASTEST: 4353
  71. FLOAT: 5126
  72. FLOAT_MAT2: 35674
  73. FLOAT_MAT3: 35675
  74. FLOAT_MAT4: 35676
  75. FLOAT_VEC2: 35664
  76. FLOAT_VEC3: 35665
  77. FLOAT_VEC4: 35666
  78. FRAGMENT_SHADER: 35632
  79. FRAMEBUFFER: 36160
  80. FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: 36049
  81. FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: 36048
  82. FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: 36051
  83. FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: 36050
  84. FRAMEBUFFER_BINDING: 36006
  85. FRAMEBUFFER_COMPLETE: 36053
  86. FRAMEBUFFER_INCOMPLETE_ATTACHMENT: 36054
  87. FRAMEBUFFER_INCOMPLETE_DIMENSIONS: 36057
  88. FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: 36055
  89. FRAMEBUFFER_UNSUPPORTED: 36061
  90. FRONT: 1028
  91. FRONT_AND_BACK: 1032
  92. FRONT_FACE: 2886
  93. FUNC_ADD: 32774
  94. FUNC_REVERSE_SUBTRACT: 32779
  95. FUNC_SUBTRACT: 32778
  96. GENERATE_MIPMAP_HINT: 33170
  97. GEQUAL: 518
  98. GREATER: 516
  99. GREEN_BITS: 3411
  100. HIGH_FLOAT: 36338
  101. HIGH_INT: 36341
  102. IMPLEMENTATION_COLOR_READ_FORMAT: 35739
  103. IMPLEMENTATION_COLOR_READ_TYPE: 35738
  104. INCR: 7682
  105. INCR_WRAP: 34055
  106. INT: 5124
  107. INT_VEC2: 35667
  108. INT_VEC3: 35668
  109. INT_VEC4: 35669
  110. INVALID_ENUM: 1280
  111. INVALID_FRAMEBUFFER_OPERATION: 1286
  112. INVALID_OPERATION: 1282
  113. INVALID_VALUE: 1281
  114. INVERT: 5386
  115. KEEP: 7680
  116. LEQUAL: 515
  117. LESS: 513
  118. LINEAR: 9729
  119. LINEAR_MIPMAP_LINEAR: 9987
  120. LINEAR_MIPMAP_NEAREST: 9985
  121. LINES: 1
  122. LINE_LOOP: 2
  123. LINE_STRIP: 3
  124. LINE_WIDTH: 2849
  125. LINK_STATUS: 35714
  126. LOW_FLOAT: 36336
  127. LOW_INT: 36339
  128. LUMINANCE: 6409
  129. LUMINANCE_ALPHA: 6410
  130. MAX_COMBINED_TEXTURE_IMAGE_UNITS: 35661
  131. MAX_CUBE_MAP_TEXTURE_SIZE: 34076
  132. MAX_FRAGMENT_UNIFORM_VECTORS: 36349
  133. MAX_RENDERBUFFER_SIZE: 34024
  134. MAX_TEXTURE_IMAGE_UNITS: 34930
  135. MAX_TEXTURE_SIZE: 3379
  136. MAX_VARYING_VECTORS: 36348
  137. MAX_VERTEX_ATTRIBS: 34921
  138. MAX_VERTEX_TEXTURE_IMAGE_UNITS: 35660
  139. MAX_VERTEX_UNIFORM_VECTORS: 36347
  140. MAX_VIEWPORT_DIMS: 3386
  141. MEDIUM_FLOAT: 36337
  142. MEDIUM_INT: 36340
  143. MIRRORED_REPEAT: 33648
  144. NEAREST: 9728
  145. NEAREST_MIPMAP_LINEAR: 9986
  146. NEAREST_MIPMAP_NEAREST: 9984
  147. NEVER: 512
  148. NICEST: 4354
  149. NONE: 0
  150. NOTEQUAL: 517
  151. NO_ERROR: 0
  152. ONE: 1
  153. ONE_MINUS_CONSTANT_ALPHA: 32772
  154. ONE_MINUS_CONSTANT_COLOR: 32770
  155. ONE_MINUS_DST_ALPHA: 773
  156. ONE_MINUS_DST_COLOR: 775
  157. ONE_MINUS_SRC_ALPHA: 771
  158. ONE_MINUS_SRC_COLOR: 769
  159. OUT_OF_MEMORY: 1285
  160. PACK_ALIGNMENT: 3333
  161. POINTS: 0
  162. POLYGON_OFFSET_FACTOR: 32824
  163. POLYGON_OFFSET_FILL: 32823
  164. POLYGON_OFFSET_UNITS: 10752
  165. RED_BITS: 3410
  166. RENDERBUFFER: 36161
  167. RENDERBUFFER_ALPHA_SIZE: 36179
  168. RENDERBUFFER_BINDING: 36007
  169. RENDERBUFFER_BLUE_SIZE: 36178
  170. RENDERBUFFER_DEPTH_SIZE: 36180
  171. RENDERBUFFER_GREEN_SIZE: 36177
  172. RENDERBUFFER_HEIGHT: 36163
  173. RENDERBUFFER_INTERNAL_FORMAT: 36164
  174. RENDERBUFFER_RED_SIZE: 36176
  175. RENDERBUFFER_STENCIL_SIZE: 36181
  176. RENDERBUFFER_WIDTH: 36162
  177. RENDERER: 7937
  178. REPEAT: 10497
  179. REPLACE: 7681
  180. RGB: 6407
  181. RGB565: 36194
  182. RGB5_A1: 32855
  183. RGBA: 6408
  184. RGBA4: 32854
  185. SAMPLER_2D: 35678
  186. SAMPLER_CUBE: 35680
  187. SAMPLES: 32937
  188. SAMPLE_ALPHA_TO_COVERAGE: 32926
  189. SAMPLE_BUFFERS: 32936
  190. SAMPLE_COVERAGE: 32928
  191. SAMPLE_COVERAGE_INVERT: 32939
  192. SAMPLE_COVERAGE_VALUE: 32938
  193. SCISSOR_BOX: 3088
  194. SCISSOR_TEST: 3089
  195. SHADER_TYPE: 35663
  196. SHADING_LANGUAGE_VERSION: 35724
  197. SHORT: 5122
  198. SRC_ALPHA: 770
  199. SRC_ALPHA_SATURATE: 776
  200. SRC_COLOR: 768
  201. STATIC_DRAW: 35044
  202. STENCIL_ATTACHMENT: 36128
  203. STENCIL_BACK_FAIL: 34817
  204. STENCIL_BACK_FUNC: 34816
  205. STENCIL_BACK_PASS_DEPTH_FAIL: 34818
  206. STENCIL_BACK_PASS_DEPTH_PASS: 34819
  207. STENCIL_BACK_REF: 36003
  208. STENCIL_BACK_VALUE_MASK: 36004
  209. STENCIL_BACK_WRITEMASK: 36005
  210. STENCIL_BITS: 3415
  211. STENCIL_BUFFER_BIT: 1024
  212. STENCIL_CLEAR_VALUE: 2961
  213. STENCIL_FAIL: 2964
  214. STENCIL_FUNC: 2962
  215. STENCIL_INDEX8: 36168
  216. STENCIL_PASS_DEPTH_FAIL: 2965
  217. STENCIL_PASS_DEPTH_PASS: 2966
  218. STENCIL_REF: 2967
  219. STENCIL_TEST: 2960
  220. STENCIL_VALUE_MASK: 2963
  221. STENCIL_WRITEMASK: 2968
  222. STREAM_DRAW: 35040
  223. SUBPIXEL_BITS: 3408
  224. TEXTURE: 5890
  225. TEXTURE0: 33984
  226. TEXTURE1: 33985
  227. TEXTURE10: 33994
  228. TEXTURE11: 33995
  229. TEXTURE12: 33996
  230. TEXTURE13: 33997
  231. TEXTURE14: 33998
  232. TEXTURE15: 33999
  233. TEXTURE16: 34000
  234. TEXTURE17: 34001
  235. TEXTURE18: 34002
  236. TEXTURE19: 34003
  237. TEXTURE2: 33986
  238. TEXTURE20: 34004
  239. TEXTURE21: 34005
  240. TEXTURE22: 34006
  241. TEXTURE23: 34007
  242. TEXTURE24: 34008
  243. TEXTURE25: 34009
  244. TEXTURE26: 34010
  245. TEXTURE27: 34011
  246. TEXTURE28: 34012
  247. TEXTURE29: 34013
  248. TEXTURE3: 33987
  249. TEXTURE30: 34014
  250. TEXTURE31: 34015
  251. TEXTURE4: 33988
  252. TEXTURE5: 33989
  253. TEXTURE6: 33990
  254. TEXTURE7: 33991
  255. TEXTURE8: 33992
  256. TEXTURE9: 33993
  257. TEXTURE_2D: 3553
  258. TEXTURE_BINDING_2D: 32873
  259. TEXTURE_BINDING_CUBE_MAP: 34068
  260. TEXTURE_CUBE_MAP: 34067
  261. TEXTURE_CUBE_MAP_NEGATIVE_X: 34070
  262. TEXTURE_CUBE_MAP_NEGATIVE_Y: 34072
  263. TEXTURE_CUBE_MAP_NEGATIVE_Z: 34074
  264. TEXTURE_CUBE_MAP_POSITIVE_X: 34069
  265. TEXTURE_CUBE_MAP_POSITIVE_Y: 34071
  266. TEXTURE_CUBE_MAP_POSITIVE_Z: 34073
  267. TEXTURE_MAG_FILTER: 10240
  268. TEXTURE_MIN_FILTER: 10241
  269. TEXTURE_WRAP_S: 10242
  270. TEXTURE_WRAP_T: 10243
  271. TRIANGLES: 4
  272. TRIANGLE_FAN: 6
  273. TRIANGLE_STRIP: 5
  274. UNPACK_ALIGNMENT: 3317
  275. UNPACK_COLORSPACE_CONVERSION_WEBGL: 37443
  276. UNPACK_FLIP_Y_WEBGL: 37440
  277. UNPACK_PREMULTIPLY_ALPHA_WEBGL: 37441
  278. UNSIGNED_BYTE: 5121
  279. UNSIGNED_INT: 5125
  280. UNSIGNED_SHORT: 5123
  281. UNSIGNED_SHORT_4_4_4_4: 32819
  282. UNSIGNED_SHORT_5_5_5_1: 32820
  283. UNSIGNED_SHORT_5_6_5: 33635
  284. VALIDATE_STATUS: 35715
  285. VENDOR: 7936
  286. VERSION: 7938
  287. VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: 34975
  288. VERTEX_ATTRIB_ARRAY_ENABLED: 34338
  289. VERTEX_ATTRIB_ARRAY_NORMALIZED: 34922
  290. VERTEX_ATTRIB_ARRAY_POINTER: 34373
  291. VERTEX_ATTRIB_ARRAY_SIZE: 34339
  292. VERTEX_ATTRIB_ARRAY_STRIDE: 34340
  293. VERTEX_ATTRIB_ARRAY_TYPE: 34341
  294. VERTEX_SHADER: 35633
  295. VIEWPORT: 2978
  296. ZERO: 0
  297. activeTexture: function activeTexture()
  298. attachShader: function attachShader()
  299. bindAttribLocation: function bindAttribLocation()
  300. bindBuffer: function bindBuffer()
  301. bindFramebuffer: function bindFramebuffer()
  302. bindRenderbuffer: function bindRenderbuffer()
  303. bindTexture: function bindTexture()
  304. blendColor: function blendColor()
  305. blendEquation: function blendEquation()
  306. blendEquationSeparate: function blendEquationSeparate()
  307. blendFunc: function blendFunc()
  308. blendFuncSeparate: function blendFuncSeparate()
  309. bufferData: function bufferData()
  310. bufferSubData: function bufferSubData()
  311. canvas:
  312. checkFramebufferStatus: function checkFramebufferStatus()
  313. clear: function clear()
  314. clearColor: function clearColor()
  315. clearDepth: function clearDepth()
  316. clearStencil: function clearStencil()
  317. colorMask: function colorMask()
  318. compileShader: function compileShader()
  319. compressedTexImage2D: function compressedTexImage2D()
  320. compressedTexSubImage2D: function compressedTexSubImage2D()
  321. constructor: function ()
  322. copyTexImage2D: function copyTexImage2D()
  323. copyTexSubImage2D: function copyTexSubImage2D()
  324. createBuffer: function createBuffer()
  325. createFramebuffer: function createFramebuffer()
  326. createProgram: function createProgram()
  327. createRenderbuffer: function createRenderbuffer()
  328. createShader: function createShader()
  329. createTexture: function createTexture()
  330. cullFace: function cullFace()
  331. deleteBuffer: function deleteBuffer()
  332. deleteFramebuffer: function deleteFramebuffer()
  333. deleteProgram: function deleteProgram()
  334. deleteRenderbuffer: function deleteRenderbuffer()
  335. deleteShader: function deleteShader()
  336. deleteTexture: function deleteTexture()
  337. depthFunc: function depthFunc()
  338. depthMask: function depthMask()
  339. depthRange: function depthRange()
  340. detachShader: function detachShader()
  341. disable: function disable()
  342. disableVertexAttribArray: function disableVertexAttribArray()
  343. drawArrays: function drawArrays()
  344. drawElements: function drawElements()
  345. drawingBufferHeight:
  346. drawingBufferWidth:
  347. enable: function enable()
  348. enableVertexAttribArray: function enableVertexAttribArray()
  349. finish: function finish()
  350. flush: function flush()
  351. framebufferRenderbuffer: function framebufferRenderbuffer()
  352. framebufferTexture2D: function framebufferTexture2D()
  353. frontFace: function frontFace()
  354. generateMipmap: function generateMipmap()
  355. getActiveAttrib: function getActiveAttrib()
  356. getActiveUniform: function getActiveUniform()
  357. getAttachedShaders: function getAttachedShaders()
  358. getAttribLocation: function getAttribLocation()
  359. getBufferParameter: function getBufferParameter()
  360. getContextAttributes: function getContextAttributes()
  361. getError: function getError()
  362. getExtension: function getExtension()
  363. getFramebufferAttachmentParameter: function getFramebufferAttachmentParameter()
  364. getParameter: function getParameter()
  365. getProgramInfoLog: function getProgramInfoLog()
  366. getProgramParameter: function getProgramParameter()
  367. getRenderbufferParameter: function getRenderbufferParameter()
  368. getShaderInfoLog: function getShaderInfoLog()
  369. getShaderParameter: function getShaderParameter()
  370. getShaderPrecisionFormat: function getShaderPrecisionFormat()
  371. getShaderSource: function getShaderSource()
  372. getSupportedExtensions: function getSupportedExtensions()
  373. getTexParameter: function getTexParameter()
  374. getUniform: function getUniform()
  375. getUniformLocation: function getUniformLocation()
  376. getVertexAttrib: function getVertexAttrib()
  377. getVertexAttribOffset: function getVertexAttribOffset()
  378. hint: function hint()
  379. isBuffer: function isBuffer()
  380. isContextLost: function isContextLost()
  381. isEnabled: function isEnabled()
  382. isFramebuffer: function isFramebuffer()
  383. isProgram: function isProgram()
  384. isRenderbuffer: function isRenderbuffer()
  385. isShader: function isShader()
  386. isTexture: function isTexture()
  387. lineWidth: function lineWidth()
  388. linkProgram: function linkProgram()
  389. pixelStorei: function pixelStorei()
  390. polygonOffset: function polygonOffset()
  391. readPixels: function readPixels()
  392. renderbufferStorage: function renderbufferStorage()
  393. sampleCoverage: function sampleCoverage()
  394. scissor: function scissor()
  395. shaderSource: function shaderSource()
  396. stencilFunc: function stencilFunc()
  397. stencilFuncSeparate: function stencilFuncSeparate()
  398. stencilMask: function stencilMask()
  399. stencilMaskSeparate: function stencilMaskSeparate()
  400. stencilOp: function stencilOp()
  401. stencilOpSeparate: function stencilOpSeparate()
  402. texImage2D: function texImage2D()
  403. texParameterf: function texParameterf()
  404. texParameteri: function texParameteri()
  405. texSubImage2D: function texSubImage2D()
  406. uniform1f: function uniform1f()
  407. uniform1fv: function uniform1fv()
  408. uniform1i: function uniform1i()
  409. uniform1iv: function uniform1iv()
  410. uniform2f: function uniform2f()
  411. uniform2fv: function uniform2fv()
  412. uniform2i: function uniform2i()
  413. uniform2iv: function uniform2iv()
  414. uniform3f: function uniform3f()
  415. uniform3fv: function uniform3fv()
  416. uniform3i: function uniform3i()
  417. uniform3iv: function uniform3iv()
  418. uniform4f: function uniform4f()
  419. uniform4fv: function uniform4fv()
  420. uniform4i: function uniform4i()
  421. uniform4iv: function uniform4iv()
  422. uniformMatrix2fv: function uniformMatrix2fv()
  423. uniformMatrix3fv: function uniformMatrix3fv()
  424. uniformMatrix4fv: function uniformMatrix4fv()
  425. useProgram: function useProgram()
  426. validateProgram: function validateProgram()
  427. vertexAttrib1f: function vertexAttrib1f()
  428. vertexAttrib1fv: function vertexAttrib1fv()
  429. vertexAttrib2f: function vertexAttrib2f()
  430. vertexAttrib2fv: function vertexAttrib2fv()
  431. vertexAttrib3f: function vertexAttrib3f()
  432. vertexAttrib3fv: function vertexAttrib3fv()
  433. vertexAttrib4f: function vertexAttrib4f()
  434. vertexAttrib4fv: function vertexAttrib4fv()
  435. vertexAttribPointer: function vertexAttribPointer()
  436. viewport: function viewport()

你可能感兴趣的:(webgl)