move window ideas to javascript
This commit is contained in:
parent
18c5bc6a56
commit
ee72949029
2
Makefile
2
Makefile
|
@ -116,7 +116,7 @@ else
|
||||||
OS := Linux
|
OS := Linux
|
||||||
PLATFORM := linux64
|
PLATFORM := linux64
|
||||||
LDFLAGS += -pthread -rdynamic
|
LDFLAGS += -pthread -rdynamic
|
||||||
LDLIBS += GL pthread c m dl X11 Xi Xcursor EGL asound
|
LDLIBS += pthread c m dl X11 Xi Xcursor EGL asound GL
|
||||||
INFO :=$(INFO)_linux
|
INFO :=$(INFO)_linux
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
|
@ -323,7 +323,7 @@ game.engine_start = function(s) {
|
||||||
count: 3,
|
count: 3,
|
||||||
index: os.make_buffer([0,2,1],1),
|
index: os.make_buffer([0,2,1],1),
|
||||||
};
|
};
|
||||||
}, process);
|
}, process, window.size.x, window.size.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
game.startengine = 0;
|
game.startengine = 0;
|
||||||
|
@ -354,7 +354,7 @@ function process()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var st = profile.now();
|
var st = profile.now();
|
||||||
prosperon.window_render();
|
prosperon.window_render(window.rendersize);
|
||||||
prosperon.draw();
|
prosperon.draw();
|
||||||
prosperon.gui();
|
prosperon.gui();
|
||||||
prosperon.screengui();
|
prosperon.screengui();
|
||||||
|
@ -484,7 +484,10 @@ Range is given by a semantic versioning number, prefixed with nothing, a ~, or a
|
||||||
|
|
||||||
prosperon.iconified = function(icon) {};
|
prosperon.iconified = function(icon) {};
|
||||||
prosperon.focus = function(focus) {};
|
prosperon.focus = function(focus) {};
|
||||||
prosperon.resize = function(dimensions) {};
|
prosperon.resize = function(dimensions) {
|
||||||
|
window.size.x = dimensions.x;
|
||||||
|
window.size.y = dimensions.y;
|
||||||
|
};
|
||||||
prosperon.suspended = function(sus) {};
|
prosperon.suspended = function(sus) {};
|
||||||
prosperon.mouseenter = function(){};
|
prosperon.mouseenter = function(){};
|
||||||
prosperon.mouseleave = function(){};
|
prosperon.mouseleave = function(){};
|
||||||
|
@ -603,16 +606,17 @@ var Event = {
|
||||||
|
|
||||||
// window.rendersize is the resolution the game renders at
|
// window.rendersize is the resolution the game renders at
|
||||||
// window.size is the physical size of the window on the desktop
|
// window.size is the physical size of the window on the desktop
|
||||||
window.modetypes = {
|
// set to one of the following
|
||||||
stretch: 0, // stretch render to fill window
|
// stretch render to fill window
|
||||||
keep: 1, // keep render exact dimensions, with no stretching
|
// keep render exact dimensions, with no stretching
|
||||||
width: 2, // keep render at width
|
// width keep render at width
|
||||||
height: 3, // keep render at height
|
// height keep render at height
|
||||||
expand: 4, // expand width or height
|
// expand width or height
|
||||||
full: 5 // expand out beyond window
|
// full expand out beyond window
|
||||||
};
|
|
||||||
|
|
||||||
window.size = [640, 480];
|
window.size = [640, 480];
|
||||||
|
window.rendersize = window.size;
|
||||||
|
window.mode = "keep";
|
||||||
|
|
||||||
window.set_icon.doc = "Set the icon of the window using the PNG image at path.";
|
window.set_icon.doc = "Set the icon of the window using the PNG image at path.";
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,11 @@ render.doc = {
|
||||||
wireframe: "Show only wireframes of models."
|
wireframe: "Show only wireframes of models."
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var shaderlang = {
|
var shaderlang = {
|
||||||
macos: "metal_macos",
|
macos: "metal_macos",
|
||||||
windows: "hlsl5",
|
windows: "hlsl4",
|
||||||
linux: "glsl330",
|
linux: "glsl430",
|
||||||
web: "wgsl",
|
// web: "wgsl",
|
||||||
ios: "metal_ios",
|
ios: "metal_ios",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,8 +128,9 @@ render.make_shader = function(shader)
|
||||||
|
|
||||||
profile.report(st, `CACHE make shader from ${file}`);
|
profile.report(st, `CACHE make shader from ${file}`);
|
||||||
var shaderobj = json.decode(io.slurp(writejson));
|
var shaderobj = json.decode(io.slurp(writejson));
|
||||||
shaderobj.pipe = render.pipeline(shaderobj);
|
var obj = shaderobj[os.sys()];
|
||||||
return shaderobj;
|
obj.pipe = render.pipeline(obj);
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
var out = `${file.name()}.shader`;
|
var out = `${file.name()}.shader`;
|
||||||
|
@ -161,19 +161,22 @@ render.make_shader = function(shader)
|
||||||
shader = shader.replace(/uniform texture2D ?(.*);/g, "uniform _$1_size { vec2 $1_size; };\nuniform texture2D $1;");
|
shader = shader.replace(/uniform texture2D ?(.*);/g, "uniform _$1_size { vec2 $1_size; };\nuniform texture2D $1;");
|
||||||
|
|
||||||
io.slurpwrite(out, shader);
|
io.slurpwrite(out, shader);
|
||||||
var backend = shaderlang[os.sys()];
|
|
||||||
|
var compiled = {};
|
||||||
|
|
||||||
|
// shader file is created, now cross compile to all targets
|
||||||
|
for (var platform in shaderlang) {
|
||||||
|
var backend = shaderlang[platform];
|
||||||
var ret = os.system(`sokol-shdc -f bare_yaml --slang=${backend} -i ${out} -o ${out}`);
|
var ret = os.system(`sokol-shdc -f bare_yaml --slang=${backend} -i ${out} -o ${out}`);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
console.info(`error compiling shader`);
|
console.error(`error compiling shader ${file}. No compilation found for ${platform}:${backend}, and no cross compiler available.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// io.rm(out);
|
|
||||||
|
|
||||||
/* Take YAML and create the shader object */
|
/* Take YAML and create the shader object */
|
||||||
var yamlfile = `${out}_reflection.yaml`;
|
var yamlfile = `${out}_reflection.yaml`;
|
||||||
console.info(`slurping ${yamlfile}`);
|
console.info(`slurping ${yamlfile}`);
|
||||||
var jjson = yaml.tojson(io.slurp(yamlfile));
|
var jjson = yaml.tojson(io.slurp(yamlfile));
|
||||||
say(jjson);
|
|
||||||
var obj = json.decode(jjson);
|
var obj = json.decode(jjson);
|
||||||
io.rm(yamlfile);
|
io.rm(yamlfile);
|
||||||
|
|
||||||
|
@ -181,6 +184,7 @@ render.make_shader = function(shader)
|
||||||
function add_code(stage) {
|
function add_code(stage) {
|
||||||
console.info(json.encode(stage));
|
console.info(json.encode(stage));
|
||||||
stage.code = io.slurp(stage.path);
|
stage.code = io.slurp(stage.path);
|
||||||
|
|
||||||
io.rm(stage.path);
|
io.rm(stage.path);
|
||||||
delete stage.path;
|
delete stage.path;
|
||||||
}
|
}
|
||||||
|
@ -212,11 +216,10 @@ render.make_shader = function(shader)
|
||||||
if (!stage.uniform_blocks) return {};
|
if (!stage.uniform_blocks) return {};
|
||||||
var unimap = {};
|
var unimap = {};
|
||||||
for (var uni of stage.uniform_blocks) {
|
for (var uni of stage.uniform_blocks) {
|
||||||
if (uni.struct_name[0] == "_")
|
var uniname = uni.struct_name[0] == "_" ? uni.struct_name.slice(1) : uni.struct_name;
|
||||||
uni.struct_name = uni.struct_name.slice(1);
|
|
||||||
|
|
||||||
unimap[uni.struct_name] = {
|
unimap[uniname] = {
|
||||||
name: uni.struct_name,
|
name: uniname,
|
||||||
slot: Number(uni.slot),
|
slot: Number(uni.slot),
|
||||||
size: Number(uni.size)
|
size: Number(uni.size)
|
||||||
};
|
};
|
||||||
|
@ -228,14 +231,18 @@ render.make_shader = function(shader)
|
||||||
obj.vs.unimap = make_unimap(obj.vs);
|
obj.vs.unimap = make_unimap(obj.vs);
|
||||||
obj.fs.unimap = make_unimap(obj.fs);
|
obj.fs.unimap = make_unimap(obj.fs);
|
||||||
|
|
||||||
obj.files = files;
|
|
||||||
|
|
||||||
obj.name = file;
|
obj.name = file;
|
||||||
|
|
||||||
io.slurpwrite(writejson, json.encode(obj));
|
compiled[platform] = obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
compiled.files = files;
|
||||||
|
|
||||||
|
io.slurpwrite(writejson, json.encode(compiled));
|
||||||
profile.report(st, `make shader from ${file}`);
|
profile.report(st, `make shader from ${file}`);
|
||||||
|
|
||||||
console.info(`pipeline for ${file}`);
|
console.info(`pipeline for ${file}`);
|
||||||
|
var obj = compiled[os.sys()];
|
||||||
obj.pipe = render.pipeline(obj);
|
obj.pipe = render.pipeline(obj);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -352,7 +359,7 @@ render.point = function(pos,size,color = Color.blue) {
|
||||||
|
|
||||||
var tmpline = render.line;
|
var tmpline = render.line;
|
||||||
render.line = function(points, color = Color.white, thickness = 1) {
|
render.line = function(points, color = Color.white, thickness = 1) {
|
||||||
tmpline(points,color,thickness);
|
// tmpline(points,color,thickness);
|
||||||
};
|
};
|
||||||
|
|
||||||
render.cross = function(pos, size, color = Color.red) {
|
render.cross = function(pos, size, color = Color.red) {
|
||||||
|
|
|
@ -192,7 +192,7 @@ Cmdline.register_order("edit", function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
window.size = [1280, 720];
|
window.size = [1280, 720];
|
||||||
window.mode = window.modetypes.full;
|
window.mode = "full";
|
||||||
sim.pause();
|
sim.pause();
|
||||||
|
|
||||||
game.engine_start(function() {
|
game.engine_start(function() {
|
||||||
|
@ -243,7 +243,6 @@ Cmdline.register_order("play", function(argv) {
|
||||||
|
|
||||||
var project = json.decode(io.slurp(projectfile));
|
var project = json.decode(io.slurp(projectfile));
|
||||||
game.title = project.title;
|
game.title = project.title;
|
||||||
window.mode = window.modetypes.expand;
|
|
||||||
global.mixin("config.js");
|
global.mixin("config.js");
|
||||||
if (project.title) window.title = project.title;
|
if (project.title) window.title = project.title;
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,10 @@
|
||||||
#define DEG2RADS 0.0174532925199432957692369076848861271344287188854172545609719144f
|
#define DEG2RADS 0.0174532925199432957692369076848861271344287188854172545609719144f
|
||||||
#define RAD2DEGS 57.2958f
|
#define RAD2DEGS 57.2958f
|
||||||
|
|
||||||
#define CONFIG_H
|
|
||||||
#if defined __linux__
|
#if defined __linux__
|
||||||
#define SOKOL_GLCORE33
|
#define SOKOL_GLCORE
|
||||||
#elif __EMSCRIPTEN__
|
#elif __EMSCRIPTEN__
|
||||||
#define SOKOL_GLES3
|
#define SOKOL_WGPU
|
||||||
#elif __WIN32
|
#elif __WIN32
|
||||||
#define SOKOL_D3D11
|
#define SOKOL_D3D11
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
|
|
|
@ -78,6 +78,8 @@ void sg_buffer_free(sg_buffer *b)
|
||||||
free(b);
|
free(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sg_image_free(sg_image *t){}
|
||||||
|
|
||||||
void jsfreestr(const char *s) { JS_FreeCString(js, s); }
|
void jsfreestr(const char *s) { JS_FreeCString(js, s); }
|
||||||
QJSCLASS(gameobject)
|
QJSCLASS(gameobject)
|
||||||
QJSCLASS(transform)
|
QJSCLASS(transform)
|
||||||
|
@ -90,6 +92,7 @@ QJSCLASS(warp_damp)
|
||||||
QJSCLASS(window)
|
QJSCLASS(window)
|
||||||
QJSCLASS(constraint)
|
QJSCLASS(constraint)
|
||||||
QJSCLASS(sg_buffer)
|
QJSCLASS(sg_buffer)
|
||||||
|
QJSCLASS(sg_image)
|
||||||
QJSCLASS(datastream)
|
QJSCLASS(datastream)
|
||||||
|
|
||||||
static JSValue sound_proto;
|
static JSValue sound_proto;
|
||||||
|
@ -662,9 +665,7 @@ JSC_CCALL(render_flushtext,
|
||||||
return number2js(text_flush());
|
return number2js(text_flush());
|
||||||
)
|
)
|
||||||
|
|
||||||
JSC_CCALL(render_end_pass,
|
JSC_CCALL(render_glue_pass,
|
||||||
sg_end_pass();
|
|
||||||
|
|
||||||
sg_begin_pass(&(sg_pass){
|
sg_begin_pass(&(sg_pass){
|
||||||
.swapchain = sglue_swapchain(),
|
.swapchain = sglue_swapchain(),
|
||||||
.action = (sg_pass_action){
|
.action = (sg_pass_action){
|
||||||
|
@ -674,68 +675,38 @@ JSC_CCALL(render_end_pass,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sg_pipeline p = {0};
|
|
||||||
|
|
||||||
switch(mainwin.mode) {
|
|
||||||
case MODE_STRETCH:
|
|
||||||
sg_apply_viewportf(0,0,mainwin.size.x,mainwin.size.y,0);
|
|
||||||
break;
|
|
||||||
case MODE_WIDTH:
|
|
||||||
sg_apply_viewportf(0, mainwin.top, mainwin.size.x, mainwin.psize.y,0); // keep width
|
|
||||||
break;
|
|
||||||
case MODE_HEIGHT:
|
|
||||||
sg_apply_viewportf(mainwin.left,0,mainwin.psize.x, mainwin.size.y,0); // keep height
|
|
||||||
break;
|
|
||||||
case MODE_KEEP:
|
|
||||||
sg_apply_viewportf(0,0,mainwin.rendersize.x, mainwin.rendersize.y, 0); // no scaling
|
|
||||||
break;
|
|
||||||
case MODE_EXPAND:
|
|
||||||
if (mainwin.aspect < mainwin.raspect)
|
|
||||||
sg_apply_viewportf(0, mainwin.top, mainwin.size.x, mainwin.psize.y,0); // keep width
|
|
||||||
else
|
|
||||||
sg_apply_viewportf(mainwin.left,0,mainwin.psize.x, mainwin.size.y,0); // keep height
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
p.id = js2number(argv[0]);
|
|
||||||
sg_apply_pipeline(p);
|
|
||||||
sg_bindings bind = js2bind(argv[1]);
|
|
||||||
bind.fs.images[0] = screencolor;
|
|
||||||
bind.fs.samplers[0] = std_sampler;
|
|
||||||
sg_apply_bindings(&bind);
|
|
||||||
int c = js2number(js_getpropstr(argv[1], "count"));
|
|
||||||
sg_draw(0,c,1);
|
|
||||||
|
|
||||||
sg_end_pass();
|
|
||||||
sg_commit();
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
JSC_CCALL(render_viewport, sg_apply_viewportf(js2number(argv[0]), js2number(argv[1]), js2number(argv[2]), js2number(argv[3]), 0))
|
||||||
|
|
||||||
JSC_CCALL(render_commit, sg_commit())
|
JSC_CCALL(render_commit, sg_commit())
|
||||||
|
JSC_CCALL(render_end_pass, sg_end_pass())
|
||||||
|
|
||||||
JSC_SCALL(render_text_size, ret = bb2js(text_bb(str, js2number(argv[1]), js2number(argv[2]), 1)))
|
JSC_SCALL(render_text_size, ret = bb2js(text_bb(str, js2number(argv[1]), js2number(argv[2]), 1)))
|
||||||
|
|
||||||
JSC_CCALL(render_set_camera,
|
JSC_CCALL(render_set_camera,
|
||||||
JSValue cam = argv[0];
|
JSValue cam = argv[0];
|
||||||
int ortho = js2boolean(js_getpropstr(cam, "ortho"));
|
int ortho = js2boolean(js_getpropstr(cam, "ortho"));
|
||||||
int app = js2boolean(js_getpropstr(cam, "app"));
|
|
||||||
float near = js2number(js_getpropstr(cam, "near"));
|
float near = js2number(js_getpropstr(cam, "near"));
|
||||||
float far = js2number(js_getpropstr(cam, "far"));
|
float far = js2number(js_getpropstr(cam, "far"));
|
||||||
float fov = js2number(js_getpropstr(cam, "fov"))*HMM_DegToRad;
|
float fov = js2number(js_getpropstr(cam, "fov"))*HMM_DegToRad;
|
||||||
|
HMM_Vec2 size = js2vec2(js_getpropstr(cam,"size"));
|
||||||
|
|
||||||
transform *t = js2transform(js_getpropstr(cam, "transform"));
|
transform *t = js2transform(js_getpropstr(cam, "transform"));
|
||||||
//globalview.v = transform2mat(*t);
|
|
||||||
HMM_Vec3 look = HMM_AddV3(t->pos, transform_direction(t, vFWD));
|
HMM_Vec3 look = HMM_AddV3(t->pos, transform_direction(t, vFWD));
|
||||||
globalview.v = HMM_LookAt_LH(t->pos, look, vUP);
|
globalview.v = HMM_LookAt_LH(t->pos, look, vUP);
|
||||||
HMM_Vec2 size = mainwin.mode == MODE_FULL ? mainwin.size : mainwin.rendersize;
|
|
||||||
|
|
||||||
if (ortho && app)
|
|
||||||
size = mainwin.size;
|
|
||||||
|
|
||||||
if (ortho)
|
if (ortho)
|
||||||
globalview.p = HMM_Orthographic_Metal(
|
globalview.p = HMM_Orthographic_Metal(
|
||||||
-size.x/2,
|
-size.x/2,
|
||||||
size.x/2,
|
size.x/2,
|
||||||
|
#ifdef SOKOL_GLCORE //flipping orthographic Y if opengl
|
||||||
|
size.y/2,
|
||||||
|
-size.y/2,
|
||||||
|
#else
|
||||||
-size.y/2,
|
-size.y/2,
|
||||||
size.y/2,
|
size.y/2,
|
||||||
|
#endif
|
||||||
near,
|
near,
|
||||||
far
|
far
|
||||||
);
|
);
|
||||||
|
@ -745,10 +716,29 @@ JSC_CCALL(render_set_camera,
|
||||||
globalview.vp = HMM_MulM4(globalview.p, globalview.v);
|
globalview.vp = HMM_MulM4(globalview.p, globalview.v);
|
||||||
)
|
)
|
||||||
|
|
||||||
|
sg_shader_uniform_block_desc js2uniform_block(JSValue v)
|
||||||
|
{
|
||||||
|
sg_shader_uniform_block_desc desc = {0};
|
||||||
|
int slot = js2number(js_getpropstr(v, "slot"));
|
||||||
|
desc.size = js2number(js_getpropstr(v, "size"));
|
||||||
|
desc.layout = SG_UNIFORMLAYOUT_STD140;
|
||||||
|
|
||||||
|
JSValue uniforms = js_getpropstr(v, "uniforms");
|
||||||
|
for (int j = 0; j < js_arrlen(uniforms); j++) {
|
||||||
|
JSValue uniform = js_getpropidx(uniforms, j);
|
||||||
|
desc.uniforms[j].name = js2strdup(js_getpropstr(v, "struct_name"));
|
||||||
|
desc.uniforms[j].array_count = js2number(js_getpropstr(uniform, "array_count"));
|
||||||
|
desc.uniforms[j].type = SG_UNIFORMTYPE_FLOAT4;
|
||||||
|
}
|
||||||
|
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
|
|
||||||
sg_shader js2shader(JSValue v)
|
sg_shader js2shader(JSValue v)
|
||||||
{
|
{
|
||||||
sg_shader_desc desc = {0};
|
sg_shader_desc desc = {0};
|
||||||
JSValue prog = v;
|
JSValue prog = v;
|
||||||
|
desc.label = js2strdup(js_getpropstr(v, "name"));
|
||||||
JSValue vs = js_getpropstr(prog, "vs");
|
JSValue vs = js_getpropstr(prog, "vs");
|
||||||
JSValue fs = js_getpropstr(prog, "fs");
|
JSValue fs = js_getpropstr(prog, "fs");
|
||||||
char *vsf = js2str(js_getpropstr(vs, "code"));
|
char *vsf = js2str(js_getpropstr(vs, "code"));
|
||||||
|
@ -769,27 +759,17 @@ sg_shader js2shader(JSValue v)
|
||||||
desc.attrs[i].sem_name = js2strdup(js_getpropstr(u,"sem_name"));
|
desc.attrs[i].sem_name = js2strdup(js_getpropstr(u,"sem_name"));
|
||||||
desc.attrs[i].sem_index = js2number(js_getpropstr(u, "sem_index"));
|
desc.attrs[i].sem_index = js2number(js_getpropstr(u, "sem_index"));
|
||||||
}
|
}
|
||||||
|
|
||||||
JSValue vsu = js_getpropstr(vs, "uniform_blocks");
|
JSValue vsu = js_getpropstr(vs, "uniform_blocks");
|
||||||
int unin = js_arrlen(vsu);
|
for (int i = 0; i < js_arrlen(vsu); i++)
|
||||||
for (int i = 0; i < unin; i++) {
|
desc.vs.uniform_blocks[i] = js2uniform_block(js_getpropidx(vsu, i));
|
||||||
JSValue u = js_getpropidx(vsu, i);
|
|
||||||
int slot = js2number(js_getpropstr(u, "slot"));
|
|
||||||
desc.vs.uniform_blocks[slot].size = js2number(js_getpropstr(u, "size"));
|
|
||||||
desc.vs.uniform_blocks[slot].layout = SG_UNIFORMLAYOUT_STD140;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSValue fsu = js_getpropstr(fs, "uniform_blocks");
|
JSValue fsu = js_getpropstr(fs, "uniform_blocks");
|
||||||
unin = js_arrlen(fsu);
|
for (int i = 0; i < js_arrlen(fsu); i++)
|
||||||
for (int i = 0; i < unin; i++) {
|
desc.fs.uniform_blocks[i] = js2uniform_block(js_getpropidx(fsu, i));
|
||||||
JSValue u = js_getpropidx(fsu, i);
|
|
||||||
int slot = js2number(js_getpropstr(u, "slot"));
|
|
||||||
desc.fs.uniform_blocks[slot].size = js2number(js_getpropstr(u, "size"));
|
|
||||||
desc.fs.uniform_blocks[slot].layout = SG_UNIFORMLAYOUT_STD140;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSValue imgs = js_getpropstr(fs, "images");
|
JSValue imgs = js_getpropstr(fs, "images");
|
||||||
unin = js_arrlen(imgs);
|
for (int i = 0; i < js_arrlen(imgs); i++) {
|
||||||
for (int i = 0; i < unin; i++) {
|
|
||||||
JSValue u = js_getpropidx(imgs, i);
|
JSValue u = js_getpropidx(imgs, i);
|
||||||
int slot = js2number(js_getpropstr(u, "slot"));
|
int slot = js2number(js_getpropstr(u, "slot"));
|
||||||
desc.fs.images[i].used = true;
|
desc.fs.images[i].used = true;
|
||||||
|
@ -799,24 +779,23 @@ sg_shader js2shader(JSValue v)
|
||||||
}
|
}
|
||||||
|
|
||||||
JSValue samps = js_getpropstr(fs, "samplers");
|
JSValue samps = js_getpropstr(fs, "samplers");
|
||||||
unin = js_arrlen(samps);
|
for (int i = 0; i < js_arrlen(samps); i++) {
|
||||||
for (int i = 0; i < unin; i++) {
|
JSValue sampler = js_getpropidx(samps, i);
|
||||||
desc.fs.samplers[0].used = true;
|
desc.fs.samplers[0].used = true;
|
||||||
desc.fs.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING;
|
desc.fs.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSValue pairs = js_getpropstr(fs, "image_sampler_pairs");
|
JSValue pairs = js_getpropstr(fs, "image_sampler_pairs");
|
||||||
unin = js_arrlen(pairs);
|
for (int i = 0; i < js_arrlen(pairs); i++) {
|
||||||
for (int i = 0; i < unin; i++) {
|
|
||||||
JSValue pair = js_getpropidx(pairs, i);
|
JSValue pair = js_getpropidx(pairs, i);
|
||||||
desc.fs.image_sampler_pairs[0].used = true;
|
desc.fs.image_sampler_pairs[0].used = true;
|
||||||
desc.fs.image_sampler_pairs[0].image_slot = js2number(js_getpropstr(pair, "slot"));
|
desc.fs.image_sampler_pairs[0].image_slot = js2number(js_getpropstr(pair, "slot"));
|
||||||
desc.fs.image_sampler_pairs[0].sampler_slot = 0;
|
desc.fs.image_sampler_pairs[0].sampler_slot = 0;
|
||||||
|
desc.fs.image_sampler_pairs[0].glsl_name = js2strdup(js_getpropstr(pair, "name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
JSValue ssbos = js_getpropstr(vs, "storage_buffers");
|
JSValue ssbos = js_getpropstr(vs, "storage_buffers");
|
||||||
unin = js_arrlen(ssbos);
|
for (int i = 0; i < js_arrlen(ssbos); i++) {
|
||||||
for (int i = 0; i < unin; i++) {
|
|
||||||
desc.vs.storage_buffers[i].used = true;
|
desc.vs.storage_buffers[i].used = true;
|
||||||
desc.vs.storage_buffers[i].readonly = true;
|
desc.vs.storage_buffers[i].readonly = true;
|
||||||
}
|
}
|
||||||
|
@ -944,13 +923,19 @@ JSC_CCALL(render_setpipeline,
|
||||||
sg_apply_pipeline(p);
|
sg_apply_pipeline(p);
|
||||||
)
|
)
|
||||||
|
|
||||||
JSC_CCALL(render_text_ssbo,
|
JSC_CCALL(render_text_ssbo, return sg_buffer2js(&text_ssbo))
|
||||||
return sg_buffer2js(&text_ssbo);
|
JSC_CCALL(render_screencolor,
|
||||||
|
texture *t = calloc(sizeof(*t), 1);
|
||||||
|
t->id = screencolor;
|
||||||
|
return texture2js(&screencolor)
|
||||||
)
|
)
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_render_funcs[] = {
|
static const JSCFunctionListEntry js_render_funcs[] = {
|
||||||
MIST_FUNC_DEF(render, flushtext, 0),
|
MIST_FUNC_DEF(render, flushtext, 0),
|
||||||
MIST_FUNC_DEF(render, end_pass, 2),
|
MIST_FUNC_DEF(render, viewport, 4),
|
||||||
|
MIST_FUNC_DEF(render, end_pass, 0),
|
||||||
|
MIST_FUNC_DEF(render, commit, 0),
|
||||||
|
MIST_FUNC_DEF(render, glue_pass, 0),
|
||||||
MIST_FUNC_DEF(render, text_size, 3),
|
MIST_FUNC_DEF(render, text_size, 3),
|
||||||
MIST_FUNC_DEF(render, text_ssbo, 0),
|
MIST_FUNC_DEF(render, text_ssbo, 0),
|
||||||
MIST_FUNC_DEF(render, set_camera, 1),
|
MIST_FUNC_DEF(render, set_camera, 1),
|
||||||
|
@ -965,7 +950,7 @@ static const JSCFunctionListEntry js_render_funcs[] = {
|
||||||
MIST_FUNC_DEF(render, setuniv2, 2),
|
MIST_FUNC_DEF(render, setuniv2, 2),
|
||||||
MIST_FUNC_DEF(render, setuniv4, 2),
|
MIST_FUNC_DEF(render, setuniv4, 2),
|
||||||
MIST_FUNC_DEF(render, setpipeline, 1),
|
MIST_FUNC_DEF(render, setpipeline, 1),
|
||||||
MIST_FUNC_DEF(render, commit, 0),
|
MIST_FUNC_DEF(render, screencolor, 0),
|
||||||
};
|
};
|
||||||
|
|
||||||
JSC_CCALL(gui_scissor, sg_apply_scissor_rect(js2number(argv[0]), js2number(argv[1]), js2number(argv[2]), js2number(argv[3]), 0))
|
JSC_CCALL(gui_scissor, sg_apply_scissor_rect(js2number(argv[0]), js2number(argv[1]), js2number(argv[2]), js2number(argv[3]), 0))
|
||||||
|
@ -1079,10 +1064,10 @@ static const JSCFunctionListEntry js_vector_funcs[] = {
|
||||||
MIST_FUNC_DEF(vector, inflate, 2)
|
MIST_FUNC_DEF(vector, inflate, 2)
|
||||||
};
|
};
|
||||||
|
|
||||||
JSC_CCALL(game_engine_start, engine_start(argv[0],argv[1]))
|
JSC_CCALL(game_engine_start, engine_start(argv[0],argv[1], js2number(argv[2]), js2number(argv[3])))
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_game_funcs[] = {
|
static const JSCFunctionListEntry js_game_funcs[] = {
|
||||||
MIST_FUNC_DEF(game, engine_start, 2),
|
MIST_FUNC_DEF(game, engine_start, 4),
|
||||||
};
|
};
|
||||||
|
|
||||||
JSC_CCALL(input_show_keyboard, sapp_show_keyboard(js2boolean(argv[0])))
|
JSC_CCALL(input_show_keyboard, sapp_show_keyboard(js2boolean(argv[0])))
|
||||||
|
@ -1100,7 +1085,7 @@ static const JSCFunctionListEntry js_input_funcs[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
JSC_CCALL(prosperon_phys2d_step, phys2d_update(js2number(argv[0])))
|
JSC_CCALL(prosperon_phys2d_step, phys2d_update(js2number(argv[0])))
|
||||||
JSC_CCALL(prosperon_window_render, openglRender(&mainwin))
|
JSC_CCALL(prosperon_window_render, openglRender(js2vec2(argv[0])))
|
||||||
JSC_CCALL(prosperon_guid,
|
JSC_CCALL(prosperon_guid,
|
||||||
uint8_t bytes[16];
|
uint8_t bytes[16];
|
||||||
for (int i = 0; i < 16; i++) bytes[i] = rand()%256;
|
for (int i = 0; i < 16; i++) bytes[i] = rand()%256;
|
||||||
|
@ -1113,7 +1098,7 @@ JSC_CCALL(prosperon_guid,
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_prosperon_funcs[] = {
|
static const JSCFunctionListEntry js_prosperon_funcs[] = {
|
||||||
MIST_FUNC_DEF(prosperon, phys2d_step, 1),
|
MIST_FUNC_DEF(prosperon, phys2d_step, 1),
|
||||||
MIST_FUNC_DEF(prosperon, window_render, 0),
|
MIST_FUNC_DEF(prosperon, window_render, 1),
|
||||||
MIST_FUNC_DEF(prosperon, guid, 0),
|
MIST_FUNC_DEF(prosperon, guid, 0),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1471,24 +1456,6 @@ static const JSCFunctionListEntry js_sound_funcs[] = {
|
||||||
MIST_FUNC_DEF(sound, frames, 0),
|
MIST_FUNC_DEF(sound, frames, 0),
|
||||||
};
|
};
|
||||||
|
|
||||||
static JSValue js_window_get_size(JSContext *js, JSValue this) { return vec22js(js2window(this)->size); }
|
|
||||||
static JSValue js_window_set_size(JSContext *js, JSValue this, JSValue v) {
|
|
||||||
window *w = js2window(this);
|
|
||||||
if (!w->start)
|
|
||||||
w->size = js2vec2(v);
|
|
||||||
|
|
||||||
return JS_UNDEFINED;
|
|
||||||
}
|
|
||||||
static JSValue js_window_get_rendersize(JSContext *js, JSValue this) {
|
|
||||||
window *w = js2window(this);
|
|
||||||
if (w->rendersize.x == 0 || w->rendersize.y == 0) return vec22js(w->size);
|
|
||||||
return vec22js(w->rendersize);
|
|
||||||
}
|
|
||||||
static JSValue js_window_set_rendersize(JSContext *js, JSValue this, JSValue v) {
|
|
||||||
js2window(this)->rendersize = js2vec2(v);
|
|
||||||
return JS_UNDEFINED;
|
|
||||||
}
|
|
||||||
JSC_GETSET(window, mode, number)
|
|
||||||
static JSValue js_window_get_fullscreen(JSContext *js, JSValue this) { return boolean2js(js2window(this)->fullscreen); }
|
static JSValue js_window_get_fullscreen(JSContext *js, JSValue this) { return boolean2js(js2window(this)->fullscreen); }
|
||||||
static JSValue js_window_set_fullscreen(JSContext *js, JSValue this, JSValue v) { window_setfullscreen(js2window(this), js2boolean(v)); return JS_UNDEFINED; }
|
static JSValue js_window_set_fullscreen(JSContext *js, JSValue this, JSValue v) { window_setfullscreen(js2window(this), js2boolean(v)); return JS_UNDEFINED; }
|
||||||
|
|
||||||
|
@ -1510,9 +1477,6 @@ JSC_GETSET(window, high_dpi, boolean)
|
||||||
JSC_GETSET(window, sample_count, number)
|
JSC_GETSET(window, sample_count, number)
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_window_funcs[] = {
|
static const JSCFunctionListEntry js_window_funcs[] = {
|
||||||
CGETSET_ADD(window, size),
|
|
||||||
CGETSET_ADD(window, rendersize),
|
|
||||||
CGETSET_ADD(window, mode),
|
|
||||||
CGETSET_ADD(window, fullscreen),
|
CGETSET_ADD(window, fullscreen),
|
||||||
CGETSET_ADD(window, title),
|
CGETSET_ADD(window, title),
|
||||||
CGETSET_ADD(window, vsync),
|
CGETSET_ADD(window, vsync),
|
||||||
|
|
|
@ -29,6 +29,8 @@ sg_sampler std_sampler;
|
||||||
sg_sampler nofilter_sampler;
|
sg_sampler nofilter_sampler;
|
||||||
sg_sampler tex_sampler;
|
sg_sampler tex_sampler;
|
||||||
|
|
||||||
|
int TOPLEFT = 0;
|
||||||
|
|
||||||
sg_pass offscreen;
|
sg_pass offscreen;
|
||||||
|
|
||||||
#include "sokol/sokol_app.h"
|
#include "sokol/sokol_app.h"
|
||||||
|
@ -126,7 +128,6 @@ static sg_trace_hooks hooks = {
|
||||||
};
|
};
|
||||||
|
|
||||||
void render_init() {
|
void render_init() {
|
||||||
mainwin.size = (HMM_Vec2){sapp_width(), sapp_height()};
|
|
||||||
sg_setup(&(sg_desc){
|
sg_setup(&(sg_desc){
|
||||||
.environment = sglue_environment(),
|
.environment = sglue_environment(),
|
||||||
.logger = { .func = sg_logging },
|
.logger = { .func = sg_logging },
|
||||||
|
@ -149,7 +150,7 @@ void render_init() {
|
||||||
font_init();
|
font_init();
|
||||||
|
|
||||||
sg_features feat = sg_query_features();
|
sg_features feat = sg_query_features();
|
||||||
printf("top left? %d\n", feat.origin_top_left);
|
TOPLEFT = feat.origin_top_left;
|
||||||
|
|
||||||
sg_color c = (sg_color){0,0,0,1};
|
sg_color c = (sg_color){0,0,0,1};
|
||||||
pass_action = (sg_pass_action){
|
pass_action = (sg_pass_action){
|
||||||
|
@ -194,12 +195,8 @@ HMM_Mat4 projection = {0.f};
|
||||||
HMM_Mat4 hudproj = {0.f};
|
HMM_Mat4 hudproj = {0.f};
|
||||||
HMM_Mat4 useproj = {0};
|
HMM_Mat4 useproj = {0};
|
||||||
|
|
||||||
void openglRender(struct window *window) {
|
void openglRender(HMM_Vec2 usesize) {
|
||||||
HMM_Vec2 usesize = mainwin.rendersize;
|
|
||||||
if (mainwin.mode == MODE_FULL)
|
|
||||||
usesize = mainwin.size;
|
|
||||||
if (usesize.x != lastuse.x || usesize.y != lastuse.y) {
|
if (usesize.x != lastuse.x || usesize.y != lastuse.y) {
|
||||||
printf("Redoing to %g,%g\n", usesize.x, usesize.y);
|
|
||||||
sg_destroy_image(screencolor);
|
sg_destroy_image(screencolor);
|
||||||
sg_destroy_image(screendepth);
|
sg_destroy_image(screendepth);
|
||||||
sg_destroy_attachments(offscreen.attachments);
|
sg_destroy_attachments(offscreen.attachments);
|
||||||
|
|
|
@ -9,13 +9,6 @@
|
||||||
#include "transform.h"
|
#include "transform.h"
|
||||||
#include "model.h"
|
#include "model.h"
|
||||||
|
|
||||||
#define MODE_STRETCH 0
|
|
||||||
#define MODE_KEEP 1
|
|
||||||
#define MODE_WIDTH 2
|
|
||||||
#define MODE_HEIGHT 3
|
|
||||||
#define MODE_EXPAND 4
|
|
||||||
#define MODE_FULL 5
|
|
||||||
|
|
||||||
#define RGBA_MAX 255
|
#define RGBA_MAX 255
|
||||||
|
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
@ -23,8 +16,7 @@
|
||||||
extern struct rgba color_white;
|
extern struct rgba color_white;
|
||||||
extern struct rgba color_black;
|
extern struct rgba color_black;
|
||||||
extern struct rgba color_clear;
|
extern struct rgba color_clear;
|
||||||
|
extern int TOPLEFT;
|
||||||
extern int renderMode;
|
|
||||||
|
|
||||||
extern HMM_Vec3 dirl_pos;
|
extern HMM_Vec3 dirl_pos;
|
||||||
|
|
||||||
|
@ -59,19 +51,9 @@ struct draw_p3 {
|
||||||
|
|
||||||
#include <chipmunk/chipmunk.h>
|
#include <chipmunk/chipmunk.h>
|
||||||
|
|
||||||
enum RenderMode {
|
|
||||||
LIT,
|
|
||||||
UNLIT,
|
|
||||||
WIREFRAME,
|
|
||||||
DIRSHADOWMAP,
|
|
||||||
OBJECTPICKER
|
|
||||||
};
|
|
||||||
|
|
||||||
void render_init();
|
void render_init();
|
||||||
extern HMM_Vec2 campos;
|
|
||||||
extern float camzoom;
|
|
||||||
|
|
||||||
void openglRender(struct window *window);
|
void openglRender(HMM_Vec2 usesize);
|
||||||
void opengl_rendermode(enum RenderMode r);
|
void opengl_rendermode(enum RenderMode r);
|
||||||
|
|
||||||
void openglInit3d(struct window *window);
|
void openglInit3d(struct window *window);
|
||||||
|
|
1
source/engine/thirdparty/sokol/sokol_gfx.h
vendored
1
source/engine/thirdparty/sokol/sokol_gfx.h
vendored
|
@ -9341,6 +9341,7 @@ _SOKOL_PRIVATE void _sg_gl_apply_uniforms(sg_shader_stage stage_index, int ub_in
|
||||||
if (u->gl_loc == -1) {
|
if (u->gl_loc == -1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
_sg_stats_add(gl.num_uniform, 1);
|
_sg_stats_add(gl.num_uniform, 1);
|
||||||
GLfloat* fptr = (GLfloat*) (((uint8_t*)data->ptr) + u->offset);
|
GLfloat* fptr = (GLfloat*) (((uint8_t*)data->ptr) + u->offset);
|
||||||
GLint* iptr = (GLint*) (((uint8_t*)data->ptr) + u->offset);
|
GLint* iptr = (GLint*) (((uint8_t*)data->ptr) + u->offset);
|
||||||
|
|
|
@ -20,8 +20,6 @@ struct window mainwin = {
|
||||||
.vsync = 1,
|
.vsync = 1,
|
||||||
.enable_clipboard = 0,
|
.enable_clipboard = 0,
|
||||||
.enable_dragndrop = 0,
|
.enable_dragndrop = 0,
|
||||||
.size = (HMM_Vec2){640,400},
|
|
||||||
.rendersize = (HMM_Vec2){640,400},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct window *windows = NULL;
|
static struct window *windows = NULL;
|
||||||
|
@ -30,24 +28,9 @@ struct texture *icon = NULL;
|
||||||
|
|
||||||
void window_resize(int width, int height)
|
void window_resize(int width, int height)
|
||||||
{
|
{
|
||||||
window *w = &mainwin;
|
|
||||||
w->size.x = width;
|
|
||||||
w->size.y = height;
|
|
||||||
window_apply(w);
|
|
||||||
|
|
||||||
script_evalf("prosperon.resize([%d,%d]);", width,height);
|
script_evalf("prosperon.resize([%d,%d]);", width,height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void window_apply(window *w)
|
|
||||||
{
|
|
||||||
w->aspect = w->size.x/w->size.y;
|
|
||||||
w->raspect = w->rendersize.x/w->rendersize.y;
|
|
||||||
w->psize.x = w->size.x*(w->raspect/w->aspect);
|
|
||||||
w->psize.y = w->size.y*(w->aspect/w->raspect);
|
|
||||||
w->left = (w->size.x-w->psize.x)/2;
|
|
||||||
w->top = (w->size.y-w->psize.y)/2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void window_focused(int focus)
|
void window_focused(int focus)
|
||||||
{
|
{
|
||||||
mainwin.focus = focus;
|
mainwin.focus = focus;
|
||||||
|
|
|
@ -4,12 +4,6 @@
|
||||||
#include <HandmadeMath.h>
|
#include <HandmadeMath.h>
|
||||||
|
|
||||||
struct window {
|
struct window {
|
||||||
int id;
|
|
||||||
HMM_Vec2 size; // Actual width and height of the window
|
|
||||||
HMM_Vec2 rendersize; // The desired rendering resolution, what the assets are at
|
|
||||||
HMM_Vec2 psize;
|
|
||||||
float left;
|
|
||||||
float top;
|
|
||||||
double dpi;
|
double dpi;
|
||||||
int render;
|
int render;
|
||||||
int mouseFocus;
|
int mouseFocus;
|
||||||
|
@ -19,9 +13,6 @@ struct window {
|
||||||
int iconified;
|
int iconified;
|
||||||
int focus;
|
int focus;
|
||||||
int shown;
|
int shown;
|
||||||
int mode;
|
|
||||||
float aspect;
|
|
||||||
float raspect;
|
|
||||||
char *title;
|
char *title;
|
||||||
int vsync;
|
int vsync;
|
||||||
int enable_clipboard;
|
int enable_clipboard;
|
||||||
|
|
|
@ -112,7 +112,7 @@ void c_event(const sapp_event *e)
|
||||||
char lcfmt[5];
|
char lcfmt[5];
|
||||||
switch (e->type) {
|
switch (e->type) {
|
||||||
case SAPP_EVENTTYPE_MOUSE_MOVE:
|
case SAPP_EVENTTYPE_MOUSE_MOVE:
|
||||||
script_evalf("prosperon.mousemove([%g, %g], [%g, %g]);", e->mouse_x, mainwin.size.y -e->mouse_y, e->mouse_dx, -e->mouse_dy);
|
script_evalf("prosperon.mousemove([%g, %g], [%g, %g]);", e->mouse_x, e->mouse_y, e->mouse_dx, -e->mouse_dy);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SAPP_EVENTTYPE_MOUSE_SCROLL:
|
case SAPP_EVENTTYPE_MOUSE_SCROLL:
|
||||||
|
@ -252,15 +252,15 @@ sapp_desc sokol_main(int argc, char **argv) {
|
||||||
return start_desc;
|
return start_desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void engine_start(JSValue start, JSValue procfn)
|
void engine_start(JSValue start, JSValue procfn, float x, float y)
|
||||||
{
|
{
|
||||||
c_start = JS_DupValue(js,start);
|
c_start = JS_DupValue(js,start);
|
||||||
c_process_fn = JS_DupValue(js,procfn);
|
c_process_fn = JS_DupValue(js,procfn);
|
||||||
|
|
||||||
sound_init();
|
sound_init();
|
||||||
|
|
||||||
start_desc.width = mainwin.size.x;
|
start_desc.width = x;
|
||||||
start_desc.height = mainwin.size.y;
|
start_desc.height = y;
|
||||||
start_desc.window_title = mainwin.title;
|
start_desc.window_title = mainwin.title;
|
||||||
start_desc.fullscreen = mainwin.fullscreen;
|
start_desc.fullscreen = mainwin.fullscreen;
|
||||||
start_desc.swap_interval = mainwin.vsync;
|
start_desc.swap_interval = mainwin.vsync;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
double apptime();
|
double apptime();
|
||||||
void print_stacktrace();
|
void print_stacktrace();
|
||||||
void engine_start(JSValue start_fn, JSValue proc_fn); /* fn runs after the engine starts */
|
void engine_start(JSValue start_fn, JSValue proc_fn, float x, float y); /* fn runs after the engine starts */
|
||||||
|
|
||||||
void quit();
|
void quit();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue