import { native_ } from './Constants';
import { GPUCommandBuffer } from './GPUCommandBuffer';
import { GPUComputePassEncoder } from './GPUComputePassEncoder';
import { GPURenderPassEncoder } from './GPURenderPassEncoder';
export class GPUCommandEncoder {
    get label() {
        return this[native_]?.label ?? '';
    }
    static fromNative(encoder) {
        if (encoder) {
            const ret = new GPUCommandEncoder();
            ret[native_] = encoder;
            return ret;
        }
        return null;
    }
    beginComputePass(descriptor) {
        if (descriptor?.timestampWrites) {
            descriptor.timestampWrites.querySet = descriptor.timestampWrites.querySet[native_];
        }
        return GPUComputePassEncoder.fromNative(this[native_].beginComputePass(descriptor));
    }
    beginRenderPass(descriptor) {
        descriptor.colorAttachments = descriptor.colorAttachments.map((attachment) => {
            if (Array.isArray(attachment.clearValue)) {
                attachment.clearValue = { r: attachment.clearValue[0], g: attachment.clearValue[1], b: attachment.clearValue[2], a: attachment.clearValue[3] };
            }
            if (attachment.view) {
                attachment.view = attachment.view[native_];
            }
            else {
                /// ???
            }
            if (attachment.resolveTarget) {
                attachment.resolveTarget = attachment.resolveTarget[native_];
            }
            return attachment;
        });
        if (descriptor?.depthStencilAttachment?.view?.[native_]) {
            descriptor.depthStencilAttachment.view = descriptor.depthStencilAttachment.view[native_];
        }
        if (descriptor?.occlusionQuerySet) {
            descriptor.occlusionQuerySet = descriptor.occlusionQuerySet[native_];
        }
        if (descriptor?.timestampWrites?.querySet) {
            descriptor.timestampWrites.querySet = descriptor.timestampWrites.querySet[native_];
        }
        const passEncoder = this[native_].beginRenderPass(descriptor);
        return GPURenderPassEncoder.fromNative(passEncoder);
    }
    clearBuffer(buffer, offset, size) {
        this[native_].clearBuffer(buffer[native_], offset ?? -1, size ?? -1);
    }
    copyBufferToBuffer(source, sourceOffset, destination, destinationOffset, size) {
        this[native_].copyBufferToBuffer(source[native_], sourceOffset, destination[native_], destinationOffset, size);
    }
    copyBufferToTexture(source, destination, copySize) {
        source.buffer = source.buffer[native_];
        destination.texture = destination.texture[native_];
        if (Array.isArray(copySize)) {
            copySize = {
                width: copySize[0],
                height: copySize[1] ?? 1,
                depthOrArrayLayers: copySize[2] ?? 1,
            };
        }
        this[native_].copyBufferToTexture(source, destination, copySize);
    }
    copyTextureToBuffer(source, destination, copySize) {
        source.texture = source.texture[native_];
        destination.buffer = destination.buffer[native_];
        if (Array.isArray(copySize)) {
            copySize = {
                width: copySize[0],
                height: copySize[1] ?? 1,
                depthOrArrayLayers: copySize[2] ?? 1,
            };
        }
        this[native_].copyTextureToBuffer(source, destination, copySize);
    }
    copyTextureToTexture(source, destination, copySize) {
        source.texture = source.texture[native_];
        destination.texture = destination.texture[native_];
        if (Array.isArray(copySize)) {
            copySize = {
                width: copySize[0],
                height: copySize[1] ?? 1,
                depthOrArrayLayers: copySize[2] ?? 1,
            };
        }
        this[native_].copyTextureToTexture(source, destination, copySize);
    }
    finish(descriptor) {
        const ret = this[native_].finish(descriptor);
        return GPUCommandBuffer.fromNative(ret);
    }
    insertDebugMarker(markerLabel) {
        this[native_].insertDebugMarker(markerLabel);
    }
    popDebugGroup() {
        this[native_].popDebugGroup();
    }
    pushDebugGroup(groupLabel) {
        this[native_].pushDebugGroup(groupLabel);
    }
    resolveQuerySet(querySet, firstQuery, queryCount, destination, destinationOffset) {
        this[native_].resolveQuerySet(querySet[native_], firstQuery, queryCount, destination[native_], destinationOffset);
    }
    writeTimestamp(querySet, queryIndex) {
        this[native_].writeTimestamp(querySet[native_], queryIndex);
    }
}
//# sourceMappingURL=GPUCommandEncoder.js.map