/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import{O as e}from"../../../../../chunks/OITBlendEmission.glsl.js";import{OITBlendEmissionTechnique as i}from"./OITBlendEmissionTechnique.js";import{OITBlendFragmentTechniqueConfiguration as s}from"./OITBlendFragmentTechniqueConfiguration.js";import{OITBlendTechnique as t}from"./OITBlendTechnique.js";import{OITBlendTechniqueConfiguration as n}from"./OITBlendTechniqueConfiguration.js";import{OITDimOpaqueTechnique as r}from"./OITDimOpaqueTechnique.js";import{OITResolutionConfiguration as o}from"../../shaders/oitResolution.glsl.js";import{ColorAttachment1 as a,ColorAttachment2 as u,DrawBufferNone as h}from"../../../../webgl/enums.js";class m{constructor(i){this._techniques=i,this._parameters=new e,this._blendConfiguration=new n,this._dimOpaqueConfiguration=new s,this._blendEmissionConfiguration=new o}precompile(e,s,n){this._updateConfigurations(e,s,n);const{hasTransparentEmission:o,hasOpaqueEmission:a}=e;a&&1!==n&&this._techniques.precompile(r,this._dimOpaqueConfiguration),this._techniques.precompile(t,this._blendConfiguration),o&&0===n&&this._techniques.precompile(i,this._blendEmissionConfiguration)}blend(e,s,n,o,m,f){this._updateConfigurations(o,m,f),this._parameters.colorTexture=s.getTexture(),this._parameters.alphaTexture=s.getTexture(a),this._parameters.emissionTexture=s.getTexture(u),this._parameters.frontFaceTexture=n.getTexture(),this._parameters.frontFaceEmissionTexture=n.getTexture(a);const l=e.drawBuffers,{hasOpaqueEmission:p,hasTransparentEmission:c}=o;if(p&&1!==f){const i=this._techniques.get(r,this._dimOpaqueConfiguration);e.bindTechnique(i,o,this._parameters),e.setDrawBuffers([h,a]),e.screen.draw()}const d=this._techniques.get(t,this._blendConfiguration);if(e.bindTechnique(d,o,this._parameters),c){const i=l.slice();i[1]=h,e.setDrawBuffers(i),e.screen.draw()}else e.setDrawBuffers(l),e.screen.draw();if(c&&0===f){const s=this._techniques.get(i,this._blendEmissionConfiguration);e.bindTechnique(s,o,this._parameters),e.setDrawBuffers([h,a]),e.screen.draw()}e.setDrawBuffers(l)}_updateConfigurations(e,i,s){this._blendConfiguration.useFloatBlend=this._dimOpaqueConfiguration.useFloatBlend=this._blendEmissionConfiguration.useFloatBlend=e.useFloatBlend.value,this._blendConfiguration.computeHudOcclusion=i,this._blendConfiguration.hasOpaqueEmission=0===s&&e.hasOpaqueEmission,this._blendConfiguration.frontFaceMask=1===s}}export{m as OITBlend};
