"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebGLBackend = void 0;
const backend_onnxjs_1 = require("../../backend-onnxjs");
const instrument_1 = require("../instrument");
const session_handler_1 = require("./webgl/session-handler");
const webgl_context_factory_1 = require("./webgl/webgl-context-factory");
/**
 * WebGLBackend is the entry point for all WebGL opeartions
 * When it starts it created the WebGLRenderingContext
 * and other main framework components such as Program and Texture Managers
 */
class WebGLBackend {
    get contextId() {
        return backend_onnxjs_1.flags.contextId;
    }
    set contextId(value) {
        backend_onnxjs_1.flags.contextId = value;
    }
    get matmulMaxBatchSize() {
        return backend_onnxjs_1.flags.matmulMaxBatchSize;
    }
    set matmulMaxBatchSize(value) {
        backend_onnxjs_1.flags.matmulMaxBatchSize = value;
    }
    get textureCacheMode() {
        return backend_onnxjs_1.flags.textureCacheMode;
    }
    set textureCacheMode(value) {
        backend_onnxjs_1.flags.textureCacheMode = value;
    }
    get pack() {
        return backend_onnxjs_1.flags.pack;
    }
    set pack(value) {
        backend_onnxjs_1.flags.pack = value;
    }
    initialize() {
        try {
            this.glContext = webgl_context_factory_1.createWebGLContext(this.contextId);
            if (typeof this.matmulMaxBatchSize !== 'number') {
                this.matmulMaxBatchSize = 16;
            }
            if (typeof this.textureCacheMode !== 'string') {
                this.textureCacheMode = 'full';
            }
            if (typeof this.pack !== 'boolean') {
                this.pack = false;
            }
            instrument_1.Logger.verbose('WebGLBackend', `Created WebGLContext: ${typeof this.glContext} with matmulMaxBatchSize: ${this.matmulMaxBatchSize}; textureCacheMode: ${this.textureCacheMode}; pack: ${this.pack}.`);
            return true;
        }
        catch (e) {
            instrument_1.Logger.warning('WebGLBackend', `Unable to initialize WebGLBackend. ${e}`);
            return false;
        }
    }
    createSessionHandler(context) {
        return new session_handler_1.WebGLSessionHandler(this, context);
    }
    dispose() {
        this.glContext.dispose();
    }
}
exports.WebGLBackend = WebGLBackend;
//# sourceMappingURL=backend-webgl.js.map