Skip to content

Instantly share code, notes, and snippets.

@aglitchman
Last active November 30, 2021 15:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aglitchman/167b7f15d01ebd584c3b9a5209adbe23 to your computer and use it in GitHub Desktop.
Save aglitchman/167b7f15d01ebd584c3b9a5209adbe23 to your computer and use it in GitHub Desktop.
Editor script for Defold IDE. The script adds the menu items "Compile Fragment Shader" and "Compile Vertex Shader" for .fp/.vp files.
-- Download and install Arm Mobile Studio from
-- https://developer.arm.com/tools-and-software/graphics-and-gaming/arm-mobile-studio/components/mali-offline-compiler
local M = {}
local function ends_with(str, ending)
return ending == "" or str:sub(-#ending) == ending
end
function M.get_commands()
return {
{
label = "Compile Fragment Shader (Mali-G72)",
locations = {"Edit", "Assets"},
query = {selection = {type = "resource", cardinality = "one"}},
active = function(opts)
local path = editor.get(opts.selection, "path")
return ends_with(path, ".fp")
end,
run = function(opts)
local path = editor.get(opts.selection, "path")
path = path:sub(2)
return {
{action = "shell", command = {"cmd", "/C", "malioc.exe", "--core", "Mali-G72", "--fragment", path}}
}
end
}, {
label = "Compile Vertex Shader (Mali-G72)",
locations = {"Edit", "Assets"},
query = {selection = {type = "resource", cardinality = "one"}},
active = function(opts)
local path = editor.get(opts.selection, "path")
return ends_with(path, ".vp")
end,
run = function(opts)
local path = editor.get(opts.selection, "path")
path = path:sub(2)
return {
{action = "shell", command = {"cmd", "/C", "malioc.exe", "--core", "Mali-G72", "--vertex", path}}
}
end
}, {
label = "Compile Fragment Shader (Mali-T860)",
locations = {"Edit", "Assets"},
query = {selection = {type = "resource", cardinality = "one"}},
active = function(opts)
local path = editor.get(opts.selection, "path")
return ends_with(path, ".fp")
end,
run = function(opts)
local path = editor.get(opts.selection, "path")
path = path:sub(2)
return {
{action = "shell", command = {"cmd", "/C", "malioc.exe", "--core", "Mali-T860", "--fragment", path}}
}
end
}, {
label = "Compile Vertex Shader (Mali-T860)",
locations = {"Edit", "Assets"},
query = {selection = {type = "resource", cardinality = "one"}},
active = function(opts)
local path = editor.get(opts.selection, "path")
return ends_with(path, ".vp")
end,
run = function(opts)
local path = editor.get(opts.selection, "path")
path = path:sub(2)
return {
{action = "shell", command = {"cmd", "/C", "malioc.exe", "--core", "Mali-T860", "--vertex", path}}
}
end
}
}
end
return M
@subsoap
Copy link

subsoap commented Jan 1, 2021

Modified version to work with stand alone legacy version of shader compiler

https://developer.arm.com/tools-and-software/graphics-and-gaming/mali-offline-compiler/downloads

-- Download and install Mali Offline Compiler Version 6.4 from 
-- https://developer.arm.com/tools-and-software/graphics-and-gaming/mali-offline-compiler/downloads

local M = {}

local function ends_with(str, ending)
    return ending == "" or str:sub(-#ending) == ending
end

function M.get_commands()
    return {
        {
            label = "Compile Fragment Shader (Mali-G72)",
            locations = {"Edit", "Assets"},
            query = {selection = {type = "resource", cardinality = "one"}},
            active = function(opts)
                local path = editor.get(opts.selection, "path")
                return ends_with(path, ".fp")
            end,
            run = function(opts)
                local path = editor.get(opts.selection, "path")
                path = path:sub(2)
                return {
                    {action = "shell", command = {"cmd", "/C", "malisc", "--core", "Mali-G72", "--fragment", path}}
                }
            end
        }, {
            label = "Compile Vertex Shader (Mali-G72)",
            locations = {"Edit", "Assets"},
            query = {selection = {type = "resource", cardinality = "one"}},
            active = function(opts)
                local path = editor.get(opts.selection, "path")
                return ends_with(path, ".vp")
            end,
            run = function(opts)
                local path = editor.get(opts.selection, "path")
                path = path:sub(2)
                return {
                    {action = "shell", command = {"cmd", "/C", "malisc", "--core", "Mali-G72", "--vertex", path}}
                }
            end
        }, {
            label = "Compile Fragment Shader (Mali-T600)",
            locations = {"Edit", "Assets"},
            query = {selection = {type = "resource", cardinality = "one"}},
            active = function(opts)
                local path = editor.get(opts.selection, "path")
                return ends_with(path, ".fp")
            end,
            run = function(opts)
                local path = editor.get(opts.selection, "path")
                path = path:sub(2)
                return {
                    {action = "shell", command = {"cmd", "/C", "malisc", "--core", "Mali-T600", "--fragment", path}}
                }
            end
        }, {
            label = "Compile Vertex Shader (Mali-T600)",
            locations = {"Edit", "Assets"},
            query = {selection = {type = "resource", cardinality = "one"}},
            active = function(opts)
                local path = editor.get(opts.selection, "path")
                return ends_with(path, ".vp")
            end,
            run = function(opts)
                local path = editor.get(opts.selection, "path")
                path = path:sub(2)
                return {
                    {action = "shell", command = {"cmd", "/C", "malisc", "--core", "Mali-T600", "--vertex", path}}
                }
            end
        }
    }
end

return M

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment