GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, ARBTextureEnvCombine.GL_COMBINE_RGB_ARB,
LwjglTextureUtil.getGLCombineFuncRGB(rgbCombineFunc));
unitRecord.rgbCombineFunc = rgbCombineFunc;
}
CombinerSource combSrcRGB = texture.getCombineSrc0RGB();
if (!unitRecord.isValid() || unitRecord.combSrcRGB0 != combSrcRGB) {
if (!checked) {
checkAndSetUnit(unit, record, caps);
checked = true;
}
GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, ARBTextureEnvCombine.GL_SOURCE0_RGB_ARB,
LwjglTextureUtil.getGLCombineSrc(combSrcRGB));
unitRecord.combSrcRGB0 = combSrcRGB;
}
CombinerOperandRGB combOpRGB = texture.getCombineOp0RGB();
if (!unitRecord.isValid() || unitRecord.combOpRGB0 != combOpRGB) {
if (!checked) {
checkAndSetUnit(unit, record, caps);
checked = true;
}
GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, ARBTextureEnvCombine.GL_OPERAND0_RGB_ARB,
LwjglTextureUtil.getGLCombineOpRGB(combOpRGB));
unitRecord.combOpRGB0 = combOpRGB;
}
// We only need to do Arg1 or Arg2 if we aren't in Replace mode
if (rgbCombineFunc != CombinerFunctionRGB.Replace) {
combSrcRGB = texture.getCombineSrc1RGB();
if (!unitRecord.isValid() || unitRecord.combSrcRGB1 != combSrcRGB) {
if (!checked) {
checkAndSetUnit(unit, record, caps);
checked = true;
}
GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, ARBTextureEnvCombine.GL_SOURCE1_RGB_ARB,
LwjglTextureUtil.getGLCombineSrc(combSrcRGB));
unitRecord.combSrcRGB1 = combSrcRGB;
}
combOpRGB = texture.getCombineOp1RGB();
if (!unitRecord.isValid() || unitRecord.combOpRGB1 != combOpRGB) {
if (!checked) {
checkAndSetUnit(unit, record, caps);
checked = true;
}
GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, ARBTextureEnvCombine.GL_OPERAND1_RGB_ARB,
LwjglTextureUtil.getGLCombineOpRGB(combOpRGB));
unitRecord.combOpRGB1 = combOpRGB;
}
// We only need to do Arg2 if we are in Interpolate mode
if (rgbCombineFunc == CombinerFunctionRGB.Interpolate) {
combSrcRGB = texture.getCombineSrc2RGB();
if (!unitRecord.isValid() || unitRecord.combSrcRGB2 != combSrcRGB) {
if (!checked) {
checkAndSetUnit(unit, record, caps);
checked = true;
}
GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, ARBTextureEnvCombine.GL_SOURCE2_RGB_ARB,
LwjglTextureUtil.getGLCombineSrc(combSrcRGB));
unitRecord.combSrcRGB2 = combSrcRGB;
}
combOpRGB = texture.getCombineOp2RGB();
if (!unitRecord.isValid() || unitRecord.combOpRGB2 != combOpRGB) {
if (!checked) {
checkAndSetUnit(unit, record, caps);
checked = true;
}
GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, ARBTextureEnvCombine.GL_OPERAND2_RGB_ARB,
LwjglTextureUtil.getGLCombineOpRGB(combOpRGB));
unitRecord.combOpRGB2 = combOpRGB;
}
}
}
// Now Alpha combines
final CombinerFunctionAlpha alphaCombineFunc = texture.getCombineFuncAlpha();
if (!unitRecord.isValid() || unitRecord.alphaCombineFunc != alphaCombineFunc) {
if (!checked) {
checkAndSetUnit(unit, record, caps);
checked = true;
}
GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, ARBTextureEnvCombine.GL_COMBINE_ALPHA_ARB,
LwjglTextureUtil.getGLCombineFuncAlpha(alphaCombineFunc));
unitRecord.alphaCombineFunc = alphaCombineFunc;
}
CombinerSource combSrcAlpha = texture.getCombineSrc0Alpha();
if (!unitRecord.isValid() || unitRecord.combSrcAlpha0 != combSrcAlpha) {
if (!checked) {
checkAndSetUnit(unit, record, caps);
checked = true;
}