HISE Logo Forum
    • Categories
    • Register
    • Login

    Enable/Disable GLSL and keep it permanent?

    Scheduled Pinned Locked Moved General Questions
    4 Posts 2 Posters 188 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • GabG
      Gab
      last edited by

      I'm not talking about Settings.setEnableOpenGL(true);

      I'm not sure if there's already and example on the forum about this but I would like to have a button that can enable/disable my plugin shader for the lower ends computer.

      I had a simple solution that would have been hiding the Shader panel directly by making it invisible but I'm not sure if it will actually reduce the glsl impact on GPU.

      And for making value permanent I'm not sure how to word it properly but basically I would like to have the button to be permanent so if the user click it the shader will be disabled when another instance of the plugin is loaded.

      Thanks in advance!

      HISEnbergH 1 Reply Last reply Reply Quote 0
      • HISEnbergH
        HISEnberg @Gab
        last edited by HISEnberg

        @Gab For your first issue of enabling or disabling openGl, I think you need to use Settings.setEnableOpenGL(bool shouldBeEnabled) As far as I know this is the only way of enabling/disabling it. If your panel is hidden, it won't get processed but openGl can (I believe) still effect how other componens' graphics are being processed.

        Link Preview Image
        HISE | Scripting | Settings

        Access to the plugins settings

        favicon

        (docs.hise.audio)

        With regards to making the value permanent so the user doesn't need to reset it each time, I actually just wrote a script for doing just this. My example is a bit verbose for what you need but it will work nonetheless (it doesn't need to be written to JSON for instance, and you don't need an array here).

        In this example the button state is dumped into a JSON file which I am saving in the expansions folder (AppData is a better location when you release the plugin). When the plugin is initialized the script will run and set the corresponding control callbacks to whatever state it is saved to. At the same time, toggling the button will update it's state.

        HiseSnippet 1652.3ocsXstaaaCEVJIpnwqsXEXO.D4WJqAN1oN2PV2hiiSm2xEupzf0UTDPKQayFYRCIpj5UTf8drWx8Frc3EYQeI8RvpPPrIO293ge7nCc6DdHIMkm33V57QCINtOvKXDSzuQeLk4z5PG2G40ISH3r.AVPRcNXzPbZJIxw0cwmK0wc4kbTO+yOc.NFyBIES43bAmFRNlNfJJls89+JMN9HbD4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GqpfgMUcngFWL2LuMiQqVqHSBdRpWZ9xY1zjg+oF85bm7FPU0TSrkL6lcN5eNQ7EAdf6OerGQ5hyhEWL6omO4Rn3HR5gjtP3h7mdUMyVd9BaJ8r2orS.1n6iTQo0osNuU8ia8GM+bJhPYTAEGS+Sy1YA0UlK8opBtHJ5GlyqTKCUo6I5ChexSlOcVUzYVCeM8MSV.xJQC6xQpTKX4TaTxxRUrrX9NFJxnRQ9EtZ0YRoSTmZpvLt7lLZx5cUMrzopdU3CYILX+3KMioyV25pvTWuANNtCzYr+T060z+4r+sGrOiZMd9btKVn6YA5Uf2U80TUSfVuO4TtfbFSw.VFbNZZQc6NWYF.ECuiedhks8m7wLzmkMnCIw50VJEgVamreYuaueY614C0sIZoHbrBRGmAcacaM46X5sT1asAUfpBUm0OxzYsNA6PgFnW1yvQbTP19JPNurkr4nbGA9DhyPRhfJWBtGRtFthjtk8k8NjjdkfODtsy3FZgqloC6CyanWx4TQ89d5lLbdmc.GAIFW4WtgFI5WH4U62mP60u3lX+0usOEZ9J+FWOvq1F6V4oUqsQsJNEB1vHo1101rxN63zoWtAKeu+Edjd557Du0x1ZAbuOi71zKgBL9oVFN+39Nyd8G3hW7nrXrXxaiIuypQ.P4l3JPxq4.8fJFYem1+2th1mKDerWaJb2f4iwElCFAh0WCLZtX6C8Z1sKITT.vk7N52+5bKVmWvyDPqKmfgNX.9f2oYCB.lVHAhNCH5xi7tKH4V5wUxY5APQL0.IgzHrpbrqQX0bgNCvgI7KMs1Ku578Uy.Xho9YFV16D4XzbNIO.tI+kggS5pYLbi6pgO8tZXs6pgadWMbq6pgaeWMbmOsgxenk5YB9.8wFGmSZ2TU40007ZYIa04+TotZFH
        
        Content.makeFrontInterface(100, 100);
        
        // ================== VARIABLES ======================== //
        const var Panel1 = Content.getComponent("Panel1");
        const var Button1 = Content.getComponent("Button1");
        const var buttons_stateNames = [Button1];
        const var state_filename = "buttonStates.json";
        
        // You can check the expansions folder for this file and even watch it change if you open it in xCode/Vstudio
        // You can specify any file path here, I recommend AppData since this is where the user presets are held
        // So just change FileSyste.Expansions to FileSystem.AppData
        const var stateFilePath = FileSystem.getFolder(FileSystem.Expansions).getChildFile(state_filename);
        
        reg btnEnabled = 0;
        
        // ================== ENABLE/DISABLE ======================== //
        // Panel visibility control function
        inline function setPanelEnabled(value)
        {
            Panel1.set("visible", value);
        }
        
        // ================== SAVE/LOAD BUTTON STATES =============== //
        inline function onButtonControl(component, value)
        {
            local id = component.getId();
            saveButtonState(id, value);
            
            if (id == "Button1") 
            { 
                btnEnabled = (value);
                setPanelEnabled(value); 
            }
        }
        
        // Save button states to file
        inline function saveStates(states)
        {
            Engine.dumpAsJSON(states, stateFilePath.toString(0));
            return true;
        }
        
        // Load button states
        inline function loadButtonStates()
        {
            if (stateFilePath.isFile())
            {
                local buttonStates = Engine.loadFromJSON(stateFilePath.toString(0));
                return buttonStates;
            }
            return {};
        }
        
        // Save state for a specific button
        inline function saveButtonState(buttonId, state)
        {
            local states = loadButtonStates();
            states[buttonId] = state;
            return saveStates(states);
        }
        
        // Get state for a specific button
        inline function getButtonState(buttonId, defaultValue)
        {
            local states = loadButtonStates();
            
            if (isDefined(states[buttonId]))
            {
                return states[buttonId];
            }
            
            return defaultValue;
        }
        
        // ================== INITIALIZE =============== //
        inline function initializeButtons()
        {
            for (i = 0; i < buttons_stateNames.length; i++)
            {
                local id = buttons_stateNames[i].getId();
                local savedState = getButtonState(id, 0);
                buttons_stateNames[i].setValue(savedState);
            }
            
            btnEnabled = getButtonState("Button1", 0) == 1;
            setPanelEnabled(btnEnabled); 
        }
        
        for (i = 0; i < buttons_stateNames.length; i++)
        {
            buttons_stateNames[i].setControlCallback(onButtonControl);
        }
        
        initializeButtons(); // Initialize states at the end of the script
        
        HISEnbergH 1 Reply Last reply Reply Quote 1
        • HISEnbergH
          HISEnberg @HISEnberg
          last edited by

          Oh and if you load a Floating Tile with Custom Settings you can also enable/disable open gl from there.

          GabG 1 Reply Last reply Reply Quote 1
          • GabG
            Gab @HISEnberg
            last edited by

            @HISEnberg Thanks!!

            1 Reply Last reply Reply Quote 0
            • First post
              Last post

            20

            Online

            1.7k

            Users

            11.8k

            Topics

            103.2k

            Posts