setMaterial method

void setMaterial(
  1. Material material,
  2. bool frontFaceCW
)

Implementation

void setMaterial(Material material, bool frontFaceCW) {
  material.side == DoubleSide ? disable(gl.CULL_FACE) : enable(gl.CULL_FACE);

  var flipSided = (material.side == BackSide);
  if (frontFaceCW) flipSided = !flipSided;

  setFlipSided(flipSided);

  (material.blending == NormalBlending && material.transparent == false)
      ? setBlending(NoBlending, null, null, null, null, null, null, false)
      : setBlending(material.blending, material.blendEquation, material.blendSrc, material.blendDst,
          material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha);

  depthBuffer.setFunc(material.depthFunc);
  depthBuffer.setTest(material.depthTest);
  depthBuffer.setMask(material.depthWrite);
  colorBuffer.setMask(material.colorWrite);

  var stencilWrite = material.stencilWrite;
  stencilBuffer.setTest(stencilWrite);
  if (stencilWrite) {
    stencilBuffer.setMask(material.stencilWriteMask);
    stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
    stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  }

  setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);

  material.alphaToCoverage == true ? enable(gl.SAMPLE_ALPHA_TO_COVERAGE) : disable(gl.SAMPLE_ALPHA_TO_COVERAGE);
}