Source: core/Shader.js

core/Shader.js

  1. // 修改依赖库应对小程序环境
  2. import { GLShader } from '../dependencies/pixi-gl-core/';
  3. // import { GLShader } from 'pixi-gl-core';
  4. import settings from './settings';
  5. function checkPrecision(src, def)
  6. {
  7. if (src instanceof Array)
  8. {
  9. if (src[0].substring(0, 9) !== 'precision')
  10. {
  11. const copy = src.slice(0);
  12. copy.unshift(`precision ${def} float;`);
  13. return copy;
  14. }
  15. }
  16. else if (src.trim().substring(0, 9) !== 'precision')
  17. {
  18. return `precision ${def} float;\n${src}`;
  19. }
  20. return src;
  21. }
  22. /**
  23. * Wrapper class, webGL Shader for Pixi.
  24. * Adds precision string if vertexSrc or fragmentSrc have no mention of it.
  25. *
  26. * @class
  27. * @extends GLShader
  28. * @memberof PIXI
  29. */
  30. export default class Shader extends GLShader
  31. {
  32. /**
  33. *
  34. * @param {WebGLRenderingContext} gl - The current WebGL rendering context
  35. * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings.
  36. * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings.
  37. * @param {object} [attributeLocations] - A key value pair showing which location eact attribute should sit.
  38. e.g. {position:0, uvs:1}.
  39. * @param {string} [precision] - The float precision of the shader. Options are 'lowp', 'mediump' or 'highp'.
  40. */
  41. constructor(gl, vertexSrc, fragmentSrc, attributeLocations, precision)
  42. {
  43. super(gl, checkPrecision(vertexSrc, precision || settings.PRECISION_VERTEX),
  44. checkPrecision(fragmentSrc, precision || settings.PRECISION_FRAGMENT), undefined, attributeLocations);
  45. }
  46. }