diff --git a/builds/cube_sapp/samples/cube-sapp.glsl b/builds/cube_sapp/samples/cube-sapp.glsl deleted file mode 100644 index 4dc4082..0000000 --- a/builds/cube_sapp/samples/cube-sapp.glsl +++ /dev/null @@ -1,28 +0,0 @@ -@ctype mat4 hmm_mat4 - -@vs vs -uniform vs_params { - mat4 mvp; -}; - -in vec4 position; -in vec4 color0; - -out vec4 color; - -void main() { - gl_Position = mvp * position; - color = color0; -} -@end - -@fs fs -in vec4 color; -out vec4 frag_color; - -void main() { - frag_color = color; -} -@end - -@program cube vs fs diff --git a/builds/cube_sapp/sokol_debug_dll.dll b/builds/cube_sapp/sokol_debug_dll.dll deleted file mode 100644 index cc34233..0000000 Binary files a/builds/cube_sapp/sokol_debug_dll.dll and /dev/null differ diff --git a/builds/cube_sapp/tools/shader_compiler/win32/readme.txt b/builds/cube_sapp/tools/shader_compiler/win32/readme.txt deleted file mode 100644 index f0ec175..0000000 --- a/builds/cube_sapp/tools/shader_compiler/win32/readme.txt +++ /dev/null @@ -1,2 +0,0 @@ -Precompiled binaries for Windows (64-bit) go here. - diff --git a/builds/cube_sapp/tools/shader_compiler/win32/sokol-shdc.exe b/builds/cube_sapp/tools/shader_compiler/win32/sokol-shdc.exe deleted file mode 100644 index 03af201..0000000 Binary files a/builds/cube_sapp/tools/shader_compiler/win32/sokol-shdc.exe and /dev/null differ diff --git a/builds/cube_sapp/tools/shc_compile.lua b/builds/cube_sapp/tools/shc_compile.lua deleted file mode 100644 index d9b5597..0000000 --- a/builds/cube_sapp/tools/shc_compile.lua +++ /dev/null @@ -1,165 +0,0 @@ --- A way to run the tool as part of a runtime or a build stage. -local ffi = require("ffi") -local sg = sg or require("sokol_gfx") -local dirtools = require("tools.dirtools") - -local base_dir = nil -local tools_dir = nil - --- Setup some defaults -local sh_compiler = {} -local exec_opts = nil -local exec = nil - --- -------------------------------------------------------------------------------------- --- Set the base path from where you are running your app from --- returns a lua table that can then be used in the soko shader methods --- -------------------------------------------------------------------------------------- -sh_compiler.init = function(base_path, debug_shader, tools_path) - - base_dir = dirtools.get_app_path(base_path) - tools_dir = base_dir - if(tools_path) then - tools_dir = base_dir..tools_path.."/" - end - - sh_compiler.target_tmp = base_dir.."bin/shaderbin/shader_gen.h" - sh_compiler.target_lang = "glsl410" - sh_compiler.target_output = "sokol" - - sh_compiler.typedefs = {} - - sh_compiler.debug = debug_shader or false - - exec_opts = { - ["Linux"] = tools_dir.."tools/shader_compiler/linux/sokol-shdc", - ["Windows"] = tools_dir.."tools\\shader_compiler\\win32\\sokol-shdc.exe", - ["MacOSX"] = tools_dir.."tools/shader_compiler/win32/sokol-shdc", - } - exec = exec_opts[ffi.os] - return sh_compiler -end - --- -------------------------------------------------------------------------------------- --- Process the shader header file for use in the lua scripts --- returns a lua table that can then be used in the soko shader methods -sh_compiler.process_shader = function( filename, shader_src, program_name ) - - if(program_name) then - program_name = program_name.."_" - else - program_name = "" - end - - local tbl = { ffi = ffi, sg = sg } - local ffi_str = "" - local buff = shader_src - local header_section, body_section = string.match(buff, "#pragma pack%(push,1%)(.+)#pragma pack%(pop%)(.*)") - -- This can happen with simple shaders. - if(header_section == nil) then - header_section, body_section = string.match(buff, "#endif\n(#define.-#define.-\n)(.*)") - header_section= string.gsub(header_section, "%((%d-)%)", " = %1") - header_section = string.gsub(header_section, "#define ", "local ") - local attribs = header_section - ffi_str = ffi_str..attribs - header_section = nil - end - - if(header_section and sh_compiler.typedefs[filename] == nil) then - - local typedefs = string.gsub(header_section, "#pragma pack%(pop%)", "") - typedefs = string.gsub(typedefs, "#pragma pack%(push,1%)", "") - typedefs = string.gsub(typedefs, "SOKOL_SHDC_ALIGN%(16%)", "__declspec%(align%(16%)%)") - sh_compiler.typedefs[filename] = true - ffi_str = ffi_str.."ffi.cdef[[" - ffi_str = ffi_str..typedefs - ffi_str = ffi_str.."]]\n\n" - end - - -- Make a sg_shader_desc - - -- get vs_source - ffi_str = ffi_str..[[local ]]..program_name..[[shader = ffi.new("sg_shader_desc[1]")]].."\n" - ffi_str = ffi_str..[[local desc = ]]..program_name.."shader[0]\n\n" - - local vs_source_count, vs_source = string.match(body_section, "static const uint8_t vs_"..program_name.."source_.-(%[.-%]) = (%{.-%});") - if(vs_source) then - ffi_str = ffi_str..[[local vs_]]..program_name..[[source_]]..sh_compiler.target_lang..[[ = ffi.new("uint8_t]]..vs_source_count..[[",]]..vs_source..")\n\n" - --ffi_str = ffi_str..[[vs_]]..program_name..[[source_]]..sh_compiler.target_lang..[[ = ffi.string(vs_]]..program_name..[[source_]]..sh_compiler.target_lang..")\n\n" - end - - -- get vs_source - local fs_source_count, fs_source = string.match(body_section, "static const uint8_t fs_"..program_name.."source_.-(%[.-%]) = (%{.-%});") - if(fs_source) then - ffi_str = ffi_str..[[local fs_]]..program_name..[[source_]]..sh_compiler.target_lang..[[ = ffi.new("uint8_t]]..fs_source_count..[[",]]..fs_source..")\n\n" - --ffi_str = ffi_str..[[fs_]]..program_name..[[source_]]..sh_compiler.target_lang..[[ = ffi.string(fs_]]..program_name..[[source_]]..sh_compiler.target_lang..")\n\n" - end - - -- local desc = shader[0] - - local desc_str = "" - local program_section = body_section - if(program_name ~= "") then - program_section = string.match(body_section, "static inline const sg_shader_desc%* "..program_name..".-%{(.-)return 0;\n%}") - end - desc_str = string.match(program_section, "static sg_shader_desc desc;.-%{.-valid = true;(.-)%}") - desc_str = string.gsub(desc_str, " ", "") - desc_str = string.gsub(desc_str, ";", "") - desc_str = string.gsub(desc_str, "%(const char%*%)", "") - desc_str = string.gsub(desc_str, "SG_UNIFORMLAYOUT_STD140", "sg.SG_UNIFORMLAYOUT_STD140") - desc_str = string.gsub(desc_str, "SG_UNIFORMTYPE_FLOAT3", "sg.SG_UNIFORMTYPE_FLOAT3") - desc_str = string.gsub(desc_str, "SG_UNIFORMTYPE_FLOAT4", "sg.SG_UNIFORMTYPE_FLOAT4") - desc_str = string.gsub(desc_str, "SG_IMAGESAMPLETYPE_FLOAT", "sg.SG_IMAGESAMPLETYPE_FLOAT") - desc_str = string.gsub(desc_str, "SG_SAMPLERTYPE_FILTERING", "sg.SG_SAMPLERTYPE_FILTERING") - desc_str = string.gsub(desc_str, "SG_IMAGETYPE_2D", "sg.SG_IMAGETYPE_2D") - - ffi_str = ffi_str..desc_str.."\n" - ffi_str = ffi_str..[[return ]]..program_name..[[shader]] - - if(sh_compiler.debug) then - print(">>------- Shader: "..filename.." ---------") - print(ffi_str) - print("<<------- End Shader ---------") - end - return load(ffi_str, nil, nil, tbl)() -end - --- -------------------------------------------------------------------------------------- --- Compile shader to file, load file, parse it and build the appropriate lua script to use --- in the sokol shader setups - -sh_compiler.compile = function( glslfile, program_name ) - - local command = exec..' -i '..glslfile.." -o "..sh_compiler.target_tmp - command = command.." -l "..sh_compiler.target_lang.." -f "..sh_compiler.target_output - - local runner = io.popen(command, "r") - -- Read in the results, then the files - if(runner) then - local results = runner:read("*a") - runner:close() - print("[sh_compiler.lua] Shader: "..glslfile.." compiled correctly.") - else - print("Invalid command: "..command) - return nil - end - - -- Load in the generated file - local lua_shader = "" - local tmpfile = io.open(sh_compiler.target_tmp, "r") - if(tmpfile) then - local shader_src = tmpfile:read("*a") - tmpfile:close() - lua_shader = sh_compiler.process_shader(glslfile, shader_src, program_name) - return lua_shader - else - print("Cannot load tmpfile: "..sh_compiler.target_tmp) - return nil - end -end - --- -------------------------------------------------------------------------------------- - -return sh_compiler - --- -------------------------------------------------------------------------------------- diff --git a/examples/samples/cube_sapp.lua b/examples/samples/cube_sapp.lua index 4dbbe03..412792f 100644 --- a/examples/samples/cube_sapp.lua +++ b/examples/samples/cube_sapp.lua @@ -10,7 +10,9 @@ local slib = require("sokol_libs") -- Warn - always after gfx!! local hmm = require("hmm") local hutils = require("hmm_utils") -local ffi = require("ffi") +local utils = require("utils") + +local ffi = require("ffi") -- -------------------------------------------------------------------------------------- @@ -189,3 +191,5 @@ app_desc[0].logger.func = slib.slog_func sapp.sapp_run( app_desc ) -- -------------------------------------------------------------------------------------- + +print(utils.tdump(package)) \ No newline at end of file diff --git a/lua/utils.lua b/lua/utils.lua index 5616569..ec31961 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -93,17 +93,22 @@ function tmerge(t1, t2) end -- --------------------------------------------------------------------------- - -function tdump(o) +local visited = {} +function tdump(o, level) + local level = level or 1 + if(level == 0) then visited = {} end if type(o) == 'table' then - local s = '{ ' - for k,v in pairs(o) do - if type(k) ~= 'number' then k = '"'..k..'"' end - s = s .. '['..k..'] = ' .. tdump(v) .. ',' - end - return s .. '} ' + local s = ' {\n' + for k,v in pairs(o) do + if type(k) ~= 'number' then k = '"'..tostring(k)..'"' end + if(visited[v] == nil) then + visited[v] = true + s = s .. string.rep(" ", level)..'['..k..'] = ' .. tdump(v, level+1) + end + end + return s .. string.rep(" ", level-1)..'}\n' else - return tostring(o) + return tostring(o).."\n" end end diff --git a/tools/build/rbuilder/rbuilder.bat b/tools/build/rbuilder/rbuilder.bat new file mode 100644 index 0000000..2416d47 --- /dev/null +++ b/tools/build/rbuilder/rbuilder.bat @@ -0,0 +1 @@ +call ..\..\..\bin\win64\luajit.exe .\rbuilder.lua \ No newline at end of file diff --git a/tools/build/srlua/readme.md b/tools/build/srlua/readme.md index a40805d..f6ebc92 100644 --- a/tools/build/srlua/readme.md +++ b/tools/build/srlua/readme.md @@ -35,3 +35,9 @@ RBuild calls srlua with options to package the binaries needed and the scripts n Eventually RBuild will become of the editor. Its initial development is to design and configure the build process. +## example + +The following is an example srlua command to build the cube_sapp example +``` +..\..\ThuncBuild\libs\srlua\bin\win64\glue.exe ..\..\ThuncBuild\libs\srlua\bin\win64\srlua.exe .\examples\samples\cube_sapp.lua .\examples\samples\cube_sapp.exe +``` \ No newline at end of file diff --git a/tools/dirtools.lua b/tools/dirtools.lua index e849d33..7be8426 100644 --- a/tools/dirtools.lua +++ b/tools/dirtools.lua @@ -18,6 +18,7 @@ dirtools.add_default_paths = function(path) package.cpath = package.cpath..";"..path.."bin/"..folders[ffi.os].."/?."..extensions[ffi.os] package.path = package.path..";"..path.."/ffi/sokol/?.lua" + package.path = package.path..";"..path.."lua/?.lua" package.path = package.path..";"..path.."/?.lua" end