* To create a WebGL texture, one needs to supply three pieces of information: * the type (the data type each channel will be stored as, e.g. int or float), * the format (the color channels that will each be stored in the previously * specified type, e.g. rgb or rgba), and the internal forma
(framebuffer)
| 1547 | * @private |
| 1548 | */ |
| 1549 | _getFramebufferColorFormat(framebuffer) { |
| 1550 | let type, format, internalFormat; |
| 1551 | const gl = this.GL; |
| 1552 | |
| 1553 | if (framebuffer.format === constants.FLOAT) { |
| 1554 | type = gl.FLOAT; |
| 1555 | } else if (framebuffer.format === constants.HALF_FLOAT) { |
| 1556 | type = this.webglVersion === constants.WEBGL2 |
| 1557 | ? gl.HALF_FLOAT |
| 1558 | : gl.getExtension('OES_texture_half_float').HALF_FLOAT_OES; |
| 1559 | } else { |
| 1560 | type = gl.UNSIGNED_BYTE; |
| 1561 | } |
| 1562 | |
| 1563 | if (framebuffer.channels === RGBA) { |
| 1564 | format = gl.RGBA; |
| 1565 | } else { |
| 1566 | format = gl.RGB; |
| 1567 | } |
| 1568 | |
| 1569 | if (this.webglVersion === constants.WEBGL2) { |
| 1570 | // https://webgl2fundamentals.org/webgl/lessons/webgl-data-textures.html |
| 1571 | const table = { |
| 1572 | [gl.FLOAT]: { |
| 1573 | [gl.RGBA]: gl.RGBA32F |
| 1574 | // gl.RGB32F is not available in Firefox without an alpha channel |
| 1575 | }, |
| 1576 | [gl.HALF_FLOAT]: { |
| 1577 | [gl.RGBA]: gl.RGBA16F |
| 1578 | // gl.RGB16F is not available in Firefox without an alpha channel |
| 1579 | }, |
| 1580 | [gl.UNSIGNED_BYTE]: { |
| 1581 | [gl.RGBA]: gl.RGBA8, // gl.RGBA4 |
| 1582 | [gl.RGB]: gl.RGB8 // gl.RGB565 |
| 1583 | } |
| 1584 | }; |
| 1585 | internalFormat = table[type][format]; |
| 1586 | } else if (framebuffer.format === constants.HALF_FLOAT) { |
| 1587 | internalFormat = gl.RGBA; |
| 1588 | } else { |
| 1589 | internalFormat = format; |
| 1590 | } |
| 1591 | |
| 1592 | return { internalFormat, format, type }; |
| 1593 | } |
| 1594 | |
| 1595 | /** |
| 1596 | * To create a WebGL texture, one needs to supply three pieces of information: |
no outgoing calls
no test coverage detected