Separated Shaders from Manager
Former-commit-id: 7faddbd38bd729b2778f09be3f98105ef5219740
This commit is contained in:
42
build/scripts/actions/encodeshaders.lua
Normal file
42
build/scripts/actions/encodeshaders.lua
Normal file
@@ -0,0 +1,42 @@
|
||||
function encodeShaders()
|
||||
local targets = os.matchdirs("../src/Nazara/Renderer/Shaders/*")
|
||||
for k, targetPath in pairs(targets) do
|
||||
local shaders = os.matchfiles(targetPath .. "/*")
|
||||
for k, filePath in pairs(shaders) do
|
||||
local ext = filePath:sub(-5)
|
||||
if (ext == ".frag" or ext == ".geom" or ext == ".vert") then
|
||||
local shader, err = io.open(filePath, "rb")
|
||||
if (not shader) then
|
||||
error("Failed to read shader file: " .. err)
|
||||
end
|
||||
|
||||
local header, err = io.open(filePath .. ".h", "w+")
|
||||
if (not header) then
|
||||
error("Failed to create header file: " .. err)
|
||||
end
|
||||
|
||||
local str = shader:read(64)
|
||||
repeat
|
||||
local l = str:len()
|
||||
for i = 1, l do
|
||||
local byte = str:sub(i, i):byte()
|
||||
if (byte >= 128) then
|
||||
byte = byte - 256
|
||||
end
|
||||
header:write(string.format("%d,", byte))
|
||||
end
|
||||
str = shader:read(64)
|
||||
until (not str)
|
||||
|
||||
header:close()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
newaction
|
||||
{
|
||||
trigger = "encodeshaders",
|
||||
description = "Generate a includable header version of shaders",
|
||||
execute = encodeShaders
|
||||
}
|
||||
Reference in New Issue
Block a user