From b8ec0ec5c17346f56753ae1120776485384cb25c Mon Sep 17 00:00:00 2001 From: David Lannan Date: Sat, 26 Oct 2024 22:43:32 +1030 Subject: [PATCH] Preparing for adding an engine library. --- bin/shaderbin/shader_gen.h | 249 ++++++++++++++++++++++---- examples/samples/nuklear_png_sapp.lua | 2 +- tools/shc_compile.lua | 42 ++--- 3 files changed, 228 insertions(+), 65 deletions(-) diff --git a/bin/shaderbin/shader_gen.h b/bin/shaderbin/shader_gen.h index 6a28c4c..89931c2 100644 --- a/bin/shaderbin/shader_gen.h +++ b/bin/shaderbin/shader_gen.h @@ -5,17 +5,42 @@ Generated by sokol-shdc (https://github.com/floooh/sokol-tools) Cmdline: - sokol-shdc -i ./samples/triangle-sapp.glsl -o F:\dev\luajit\Thunc\sokol-luajit\bin/shaderbin/shader_gen.h -l glsl410 -f sokol + sokol-shdc -i ./samples/offscreen-sapp.glsl -o F:\dev\luajit\Thunc\sokol-luajit\bin/shaderbin/shader_gen.h -l glsl410 -f sokol Overview: ========= - Shader program: 'triangle': - Get shader desc: triangle_shader_desc(sg_query_backend()); - Vertex shader: vs + Shader program: 'default': + Get shader desc: default_shader_desc(sg_query_backend()); + Vertex shader: vs_default Attributes: - ATTR_vs_position => 0 - ATTR_vs_color0 => 1 - Fragment shader: fs + ATTR_vs_default_position => 0 + ATTR_vs_default_normal => 1 + ATTR_vs_default_texcoord0 => 2 + Uniform block 'vs_params': + C struct: vs_params_t + Bind slot: SLOT_vs_params => 0 + Fragment shader: fs_default + Image 'tex': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: SLOT_tex => 0 + Sampler 'smp': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SLOT_smp => 0 + Image Sampler Pair 'tex_smp': + Image: tex + Sampler: smp + Shader program: 'offscreen': + Get shader desc: offscreen_shader_desc(sg_query_backend()); + Vertex shader: vs_offscreen + Attributes: + ATTR_vs_offscreen_position => 0 + ATTR_vs_offscreen_normal => 1 + Uniform block 'vs_params': + C struct: vs_params_t + Bind slot: SLOT_vs_params => 0 + Fragment shader: fs_offscreen */ #if !defined(SOKOL_GFX_INCLUDED) #error "Please include sokol_gfx.h before shader_gen.h" @@ -27,73 +52,219 @@ #define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) #endif #endif -#define ATTR_vs_position (0) -#define ATTR_vs_color0 (1) +#define ATTR_vs_default_position (0) +#define ATTR_vs_default_normal (1) +#define ATTR_vs_default_texcoord0 (2) +#define ATTR_vs_offscreen_position (0) +#define ATTR_vs_offscreen_normal (1) +#define SLOT_vs_params (0) +#define SLOT_tex (0) +#define SLOT_smp (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct vs_params_t { + hmm_mat4 mvp; +} vs_params_t; +#pragma pack(pop) /* #version 410 + uniform vec4 vs_params[4]; layout(location = 0) in vec4 position; - layout(location = 0) out vec4 color; - layout(location = 1) in vec4 color0; + layout(location = 0) out vec4 nrm; + layout(location = 1) in vec4 normal; void main() { - gl_Position = position; - color = color0; + gl_Position = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * position; + nrm = normal; } */ -static const uint8_t vs_source_glsl410[194] = { - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x31,0x30,0x0a,0x0a,0x6c,0x61, - 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, - 0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73,0x69,0x74, - 0x69,0x6f,0x6e,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65, - 0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, - 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69, - 0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a, - 0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, - 0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f, - 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x00, +static const uint8_t vs_offscreen_source_glsl410[280] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x31,0x30,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73,0x5f,0x70,0x61, + 0x72,0x61,0x6d,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, + 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e, + 0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6e,0x72, + 0x6d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61, + 0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x76,0x73, + 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72, + 0x61,0x6d,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d, + 0x73,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x72,0x6d,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d, + 0x61,0x6c,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; /* #version 410 layout(location = 0) out vec4 frag_color; - layout(location = 0) in vec4 color; + layout(location = 0) in vec4 nrm; void main() { - frag_color = color; + frag_color = vec4((nrm.xyz * 0.5) + vec3(0.5), 1.0); } */ -static const uint8_t fs_source_glsl410[135] = { +static const uint8_t fs_offscreen_source_glsl410[166] = { 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x31,0x30,0x0a,0x0a,0x6c,0x61, 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67, 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20, - 0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69, - 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, - 0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x76,0x65,0x63,0x34,0x20,0x6e,0x72,0x6d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, + 0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61, + 0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28, + 0x6e,0x72,0x6d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b, + 0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; -static inline const sg_shader_desc* triangle_shader_desc(sg_backend backend) { +/* + #version 410 + + uniform vec4 vs_params[4]; + layout(location = 0) in vec4 position; + layout(location = 1) out vec2 uv; + layout(location = 2) in vec2 texcoord0; + layout(location = 0) out vec4 nrm; + layout(location = 1) in vec4 normal; + + void main() + { + mat4 _22 = mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]); + gl_Position = _22 * position; + uv = texcoord0; + nrm = _22 * normal; + } + +*/ +static const uint8_t vs_default_source_glsl410[400] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x31,0x30,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73,0x5f,0x70,0x61, + 0x72,0x61,0x6d,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, + 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e, + 0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x31,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76, + 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x74, + 0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f, + 0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6e,0x72,0x6d,0x3b,0x0a,0x6c,0x61,0x79, + 0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31, + 0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c, + 0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x5f,0x32,0x32,0x20,0x3d,0x20, + 0x6d,0x61,0x74,0x34,0x28,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30, + 0x5d,0x2c,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x2c, + 0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x32,0x5d,0x2c,0x20,0x76, + 0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x33,0x5d,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x5f,0x32,0x32,0x20,0x2a,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x75,0x76,0x20,0x3d,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72, + 0x64,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x72,0x6d,0x20,0x3d,0x20,0x5f,0x32, + 0x32,0x20,0x2a,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + +}; +/* + #version 410 + + uniform sampler2D tex_smp; + + layout(location = 1) in vec2 uv; + layout(location = 0) in vec4 nrm; + layout(location = 0) out vec4 frag_color; + + void main() + { + frag_color = vec4(texture(tex_smp, uv * vec2(20.0, 10.0)).xyz * fma(clamp(dot(nrm.xyz, vec3(0.57735025882720947265625, 0.57735025882720947265625, -0.57735025882720947265625)), 0.0, 1.0), 2.0, 0.25), 1.0); + } + +*/ +static const uint8_t fs_default_source_glsl410[379] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x31,0x30,0x0a,0x0a,0x75,0x6e, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20, + 0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69, + 0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20, + 0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x6e,0x72,0x6d,0x3b,0x0a,0x6c,0x61,0x79, + 0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30, + 0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69, + 0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x74,0x65,0x78,0x74, + 0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x2c,0x20,0x75,0x76,0x20, + 0x2a,0x20,0x76,0x65,0x63,0x32,0x28,0x32,0x30,0x2e,0x30,0x2c,0x20,0x31,0x30,0x2e, + 0x30,0x29,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x66,0x6d,0x61,0x28,0x63,0x6c, + 0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x6e,0x72,0x6d,0x2e,0x78,0x79,0x7a,0x2c, + 0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x35,0x37,0x37,0x33,0x35,0x30,0x32,0x35, + 0x38,0x38,0x32,0x37,0x32,0x30,0x39,0x34,0x37,0x32,0x36,0x35,0x36,0x32,0x35,0x2c, + 0x20,0x30,0x2e,0x35,0x37,0x37,0x33,0x35,0x30,0x32,0x35,0x38,0x38,0x32,0x37,0x32, + 0x30,0x39,0x34,0x37,0x32,0x36,0x35,0x36,0x32,0x35,0x2c,0x20,0x2d,0x30,0x2e,0x35, + 0x37,0x37,0x33,0x35,0x30,0x32,0x35,0x38,0x38,0x32,0x37,0x32,0x30,0x39,0x34,0x37, + 0x32,0x36,0x35,0x36,0x32,0x35,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31, + 0x2e,0x30,0x29,0x2c,0x20,0x32,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x32,0x35,0x29,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +}; +static inline const sg_shader_desc* default_shader_desc(sg_backend backend) { if (backend == SG_BACKEND_GLCORE) { static sg_shader_desc desc; static bool valid; if (!valid) { valid = true; desc.attrs[0].name = "position"; - desc.attrs[1].name = "color0"; - desc.vs.source = (const char*)vs_source_glsl410; + desc.attrs[1].name = "normal"; + desc.attrs[2].name = "texcoord0"; + desc.vs.source = (const char*)vs_default_source_glsl410; desc.vs.entry = "main"; - desc.fs.source = (const char*)fs_source_glsl410; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; + desc.fs.source = (const char*)fs_default_source_glsl410; desc.fs.entry = "main"; - desc.label = "triangle_shader"; + desc.fs.images[0].used = true; + desc.fs.images[0].multisampled = false; + desc.fs.images[0].image_type = SG_IMAGETYPE_2D; + desc.fs.images[0].sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.fs.samplers[0].used = true; + desc.fs.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.fs.image_sampler_pairs[0].used = true; + desc.fs.image_sampler_pairs[0].image_slot = 0; + desc.fs.image_sampler_pairs[0].sampler_slot = 0; + desc.fs.image_sampler_pairs[0].glsl_name = "tex_smp"; + desc.label = "default_shader"; + } + return &desc; + } + return 0; +} +static inline const sg_shader_desc* offscreen_shader_desc(sg_backend backend) { + if (backend == SG_BACKEND_GLCORE) { + static sg_shader_desc desc; + static bool valid; + if (!valid) { + valid = true; + desc.attrs[0].name = "position"; + desc.attrs[1].name = "normal"; + desc.vs.source = (const char*)vs_offscreen_source_glsl410; + desc.vs.entry = "main"; + desc.vs.uniform_blocks[0].size = 64; + desc.vs.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.vs.uniform_blocks[0].uniforms[0].name = "vs_params"; + desc.vs.uniform_blocks[0].uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.vs.uniform_blocks[0].uniforms[0].array_count = 4; + desc.fs.source = (const char*)fs_offscreen_source_glsl410; + desc.fs.entry = "main"; + desc.label = "offscreen_shader"; } return &desc; } diff --git a/examples/samples/nuklear_png_sapp.lua b/examples/samples/nuklear_png_sapp.lua index 70933e7..f7fb47c 100644 --- a/examples/samples/nuklear_png_sapp.lua +++ b/examples/samples/nuklear_png_sapp.lua @@ -1,4 +1,4 @@ -package.path = package.path..";../../?.lua" +package.path = package.path..";../?.lua" local dirtools = require("tools.dirtools") local base_path = dirtools.get_app_path("sokol%-luajit") diff --git a/tools/shc_compile.lua b/tools/shc_compile.lua index d3ddcd2..ec687e2 100644 --- a/tools/shc_compile.lua +++ b/tools/shc_compile.lua @@ -1,27 +1,10 @@ -- A way to run the tool as part of a runtime or a build stage. local ffi = require("ffi") -local sg = require("sokol_gfx") +local sg = sg or require("sokol_gfx") local dirtools = require("tools.dirtools") --- local base_dir = "." --- if(ffi.os == "Windows") then --- local cmdh = io.popen("cd", "r") --- if(cmdh) then base_dir = cmdh:read("*a"); cmdh:close() end --- else --- local cmdh = io.popen("cwd", "r") --- if(cmdh) then base_dir = cmdh:read("*a"); cmdh:close() end --- end - --- local folder_name = "sokol%-luajit" --- local last_folder, remain = string.match(base_dir, "(.-"..folder_name..")(.-)") --- remain = remain:gsub("%s+", "") --- if(ffi.os == "Windows") then --- base_dir = last_folder.."\\" --- else --- base_dir = last_folder.."/" --- end --- print("Base Directory: "..base_dir) -local base_dir = dirtools.get_app_path("sokol%-luajit") +local base_dir = nil +local tools_dir = nil -- Setup some defaults local sh_compiler = {} @@ -32,8 +15,13 @@ 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) +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" @@ -41,12 +29,12 @@ sh_compiler.init = function(base_path, debug_shader) sh_compiler.typedefs = {} - sh_compiler.debug = debug_shader + sh_compiler.debug = debug_shader or false exec_opts = { - ["Linx"] = base_dir.."tools/shader_compiler/linux/sokol-shdc.exe", - ["Windows"] = base_dir.."tools\\shader_compiler\\win32\\sokol-shdc.exe", - ["MacOSX"] = base_dir.."tools/shader_compiler/win32/sokol-shdc.exe", + ["Linx"] = tools_dir.."tools/shader_compiler/linux/sokol-shdc.exe", + ["Windows"] = tools_dir.."tools\\shader_compiler\\win32\\sokol-shdc.exe", + ["MacOSX"] = tools_dir.."tools/shader_compiler/win32/sokol-shdc.exe", } exec = exec_opts[ffi.os] return sh_compiler @@ -171,4 +159,8 @@ sh_compiler.compile = function( glslfile, program_name ) end end +-- -------------------------------------------------------------------------------------- + return sh_compiler + +-- --------------------------------------------------------------------------------------