import '../../../assert/js/assert.js';
import '../../../globals.js';
// Copyright 2023-2024, University of Colorado Boulder
/**
 * RenderProgram for showing normals colored for debugging
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */
import Vector4 from '../../../dot/js/Vector4.js';
import { alpenglow, RenderColor, RenderInstruction, RenderProgram } from '../imports.js';
export default class RenderNormalDebug extends RenderProgram {
    constructor(normalProgram) {
        super([normalProgram], false, false);
        this.normalProgram = normalProgram;
    }
    getName() {
        return 'RenderNormalDebug';
    }
    withChildren(children) {
        assert && assert(children.length === 1);
        return new RenderNormalDebug(children[0]);
    }
    equalsTyped(other) {
        return true;
    }
    getSimplified(children) {
        const normalProgram = children[0];
        if (normalProgram.isFullyTransparent) {
            return RenderColor.TRANSPARENT;
        }
        else if (normalProgram instanceof RenderColor) {
            return new RenderColor(this.getNormalDebug(normalProgram.color));
        }
        else {
            return null;
        }
    }
    getNormalDebug(normal) {
        assert && assert(normal.isFinite());
        return new Vector4(normal.x * 0.5 + 0.5, normal.y * 0.5 + 0.5, normal.z * 0.5 + 0.5, 1);
    }
    evaluate(context) {
        const normal = this.normalProgram.evaluate(context);
        return this.getNormalDebug(normal);
    }
    writeInstructions(instructions) {
        this.normalProgram.writeInstructions(instructions);
        instructions.push(RenderInstructionNormalDebug.INSTANCE);
    }
    serialize() {
        return {
            type: 'RenderNormalDebug',
            normalProgram: this.normalProgram.serialize()
        };
    }
    static deserialize(obj) {
        return new RenderNormalDebug(RenderProgram.deserialize(obj.normalProgram));
    }
}
alpenglow.register('RenderNormalDebug', RenderNormalDebug);
const scratchVector = new Vector4(0, 0, 0, 0);
export class RenderInstructionNormalDebug extends RenderInstruction {
    toString() {
        return 'RenderInstructionNormalDebug(TODO)';
    }
    equals(other, areLocationsEqual) {
        return other instanceof RenderInstructionNormalDebug;
    }
    execute(stack, context, executor) {
        stack.readTop(scratchVector);
        stack.writeTopValues(scratchVector.x * 0.5 + 0.5, scratchVector.y * 0.5 + 0.5, scratchVector.z * 0.5 + 0.5, 1);
    }
    writeBinary(encoder, getOffset) {
        encoder.pushU32(RenderInstruction.NormalDebugCode);
    }
    getBinaryLength() {
        return 1;
    }
}
RenderInstructionNormalDebug.INSTANCE = new RenderInstructionNormalDebug();
//# sourceMappingURL=RenderNormalDebug.js.map