Make render path simpler
This commit is contained in:
parent
204aa19c50
commit
fe3250752d
6
Makefile
6
Makefile
|
@ -14,10 +14,14 @@ OPT ?= 0
|
|||
INFO :=
|
||||
LD = $(CC)
|
||||
|
||||
|
||||
STEAM = steam/sdk
|
||||
STEAMAPI = steam_api
|
||||
|
||||
LDFLAGS += -Wl,-rpath=./
|
||||
CCC != $(CC) -v
|
||||
ifneq ($(findstring clangcc , $(CCC)),)
|
||||
LDFLAGS += -Wl,-rpath=./
|
||||
endif
|
||||
|
||||
ifeq ($(CC), x86_64-w64-mingw32-gcc)
|
||||
AR = x86_64-w64-mingw32-ar
|
||||
|
|
|
@ -92,18 +92,17 @@ Object.mixin(os.sprite(true), {
|
|||
console.trace();
|
||||
this.del_anim?.();
|
||||
var sp = this;
|
||||
var stop;
|
||||
this.del_anim = function() {
|
||||
sp = undefined;
|
||||
advance = undefined;
|
||||
this.del_anim = undefined;
|
||||
this.anim_done = undefined;
|
||||
stop();
|
||||
}
|
||||
str ??= 0;
|
||||
var playing = this.anim[str];
|
||||
if (!playing) return;
|
||||
var f = 0;
|
||||
var stop;
|
||||
sp.path = playing.path;
|
||||
|
||||
function advance() {
|
||||
|
@ -112,7 +111,10 @@ Object.mixin(os.sprite(true), {
|
|||
//sp.path = playing.path;
|
||||
sp.frame = playing.frames[f].rect;
|
||||
f = (f+1)%playing.frames.length;
|
||||
if (f === 0) sp.anim_done?.();
|
||||
if (f === 0) {
|
||||
sp.anim_done?.();
|
||||
if (!sp.loop) { sp.stop(); return; }
|
||||
}
|
||||
stop = sp.gameobject.delay(advance, playing.frames[f].time);
|
||||
}
|
||||
this.tex(game.texture(playing.path));
|
||||
|
|
|
@ -241,17 +241,20 @@ function process()
|
|||
prosperon.window_render(world, 1);
|
||||
else
|
||||
prosperon.window_render(game.camera, game.camera.zoom);
|
||||
render.sprites();
|
||||
render.models();
|
||||
render.emitters();
|
||||
prosperon.draw();
|
||||
debug.draw();
|
||||
|
||||
render.set_camera();
|
||||
render.sprites(); // blits all sprites
|
||||
render.models(); // blits all models
|
||||
render.emitters(); // blits emitters
|
||||
prosperon.draw(); // draw calls
|
||||
debug.draw(); // calls needed debugs
|
||||
render.flush();
|
||||
render.pass();
|
||||
|
||||
render.set_window();
|
||||
prosperon.gui();
|
||||
render.flush_hud();
|
||||
render.flush();
|
||||
|
||||
render.end_pass();
|
||||
render.commit();
|
||||
}
|
||||
|
||||
game.timescale = 1;
|
||||
|
|
2
scripts/sprite.jso
Normal file
2
scripts/sprite.jso
Normal file
|
@ -0,0 +1,2 @@
|
|||
this.phys = physics.static;
|
||||
this.add_component(component.sprite);
|
|
@ -369,11 +369,10 @@ struct model *MakeModel(const char *path)
|
|||
/* eye position */
|
||||
HMM_Vec3 eye = {0,0,100};
|
||||
|
||||
void draw_model(struct model *model, HMM_Mat4 amodel) {
|
||||
HMM_Mat4 proj = projection;
|
||||
void draw_model(struct model *model, HMM_Mat4 amodel, HMM_Mat4 *proj) {
|
||||
HMM_Vec3 center = {0.f, 0.f, 0.f};
|
||||
HMM_Mat4 view = HMM_LookAt_RH(eye, center, vUP);
|
||||
HMM_Mat4 vp = HMM_MulM4(proj, view);
|
||||
HMM_Mat4 vp = HMM_MulM4(*proj, view);
|
||||
|
||||
HMM_Vec3 dir_dir = HMM_NormV3(HMM_SubV3(center, dirl_pos));
|
||||
|
||||
|
@ -411,7 +410,7 @@ void draw_drawmodel(struct drawmodel *dm)
|
|||
if (!dm->model) return;
|
||||
struct gameobject *go = dm->go;
|
||||
HMM_Mat4 rst = t3d_go2world(go);
|
||||
draw_model(dm->model, rst);
|
||||
draw_model(dm->model, rst, &useproj);
|
||||
}
|
||||
|
||||
void drawmodel_free(struct drawmodel *dm) {
|
||||
|
|
|
@ -142,6 +142,8 @@ void debug_flush(HMM_Mat4 *view)
|
|||
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(*view));
|
||||
sg_draw(circle_sc,4,circle_count);
|
||||
}
|
||||
|
||||
debug_nextpass();
|
||||
}
|
||||
|
||||
void debug_nextpass()
|
||||
|
@ -174,7 +176,7 @@ void debug_newframe()
|
|||
}
|
||||
|
||||
static sg_shader_uniform_block_desc projection_ubo = {
|
||||
.size = sizeof(projection),
|
||||
.size = sizeof(useproj),
|
||||
.uniforms = {
|
||||
[0] = { .name = "proj", .type = SG_UNIFORMTYPE_MAT4 },
|
||||
}
|
||||
|
|
|
@ -744,15 +744,19 @@ JSC_CCALL(render_line,
|
|||
|
||||
JSC_CCALL(render_sprites, sprite_draw_all())
|
||||
JSC_CCALL(render_models, model_draw_all())
|
||||
JSC_CCALL(render_emitters, emitters_draw())
|
||||
JSC_CCALL(render_flush, debug_flush(&projection); text_flush(&projection))
|
||||
JSC_CCALL(render_flush_hud, debug_flush(&hudproj); debug_flush(&hudproj); sprite_flush();)
|
||||
JSC_CCALL(render_pass, debug_nextpass())
|
||||
JSC_CCALL(render_end_pass, sg_end_pass())
|
||||
JSC_CCALL(render_commit, sg_commit(); debug_newframe();)
|
||||
JSC_CCALL(render_emitters, emitters_draw(&useproj))
|
||||
JSC_CCALL(render_flush, debug_flush(&useproj); text_flush(&useproj))
|
||||
JSC_CCALL(render_end_pass,
|
||||
sg_end_pass();
|
||||
sg_commit();
|
||||
debug_newframe();
|
||||
sprite_flush();
|
||||
)
|
||||
JSC_SCALL(render_text_size, ret = bb2js(text_bb(str, js2number(argv[1]), js2number(argv[2]), 1)))
|
||||
JSC_CCALL(render_world2screen, return vec22js(world2screen(js2vec2(argv[0]))))
|
||||
JSC_CCALL(render_screen2world, return vec22js(screen2world(js2vec2(argv[0]))))
|
||||
JSC_CCALL(render_set_camera, useproj = projection)
|
||||
JSC_CCALL(render_set_window, useproj = hudproj)
|
||||
|
||||
static const JSCFunctionListEntry js_render_funcs[] = {
|
||||
MIST_FUNC_DEF(render,world2screen,1),
|
||||
|
@ -768,14 +772,13 @@ static const JSCFunctionListEntry js_render_funcs[] = {
|
|||
MIST_FUNC_DEF(render, models, 0),
|
||||
MIST_FUNC_DEF(render, emitters, 0),
|
||||
MIST_FUNC_DEF(render, flush, 0),
|
||||
MIST_FUNC_DEF(render, flush_hud, 0),
|
||||
MIST_FUNC_DEF(render, pass, 0),
|
||||
MIST_FUNC_DEF(render, end_pass, 0),
|
||||
MIST_FUNC_DEF(render, commit, 0),
|
||||
MIST_FUNC_DEF(render, text_size, 3)
|
||||
MIST_FUNC_DEF(render, text_size, 3),
|
||||
MIST_FUNC_DEF(render, set_camera, 0),
|
||||
MIST_FUNC_DEF(render, set_window, 0),
|
||||
};
|
||||
|
||||
JSC_CCALL(gui_flush, text_flush(&hudproj));
|
||||
JSC_CCALL(gui_flush, text_flush(&useproj));
|
||||
JSC_CCALL(gui_scissor, sg_apply_scissor_rectf(js2number(argv[0]), js2number(argv[1]), js2number(argv[2]), js2number(argv[3]), 0))
|
||||
JSC_CCALL(gui_text,
|
||||
const char *s = JS_ToCString(js, argv[0]);
|
||||
|
|
|
@ -171,7 +171,7 @@ void parallel_pv(emitter *e, struct scheduler *sched, struct sched_task_partitio
|
|||
}
|
||||
}
|
||||
|
||||
void emitters_draw()
|
||||
void emitters_draw(HMM_Mat4 *proj)
|
||||
{
|
||||
if (arrlen(emitters) == 0) return;
|
||||
int draw_count = 0;
|
||||
|
@ -188,7 +188,7 @@ void emitters_draw()
|
|||
}
|
||||
|
||||
sg_apply_pipeline(par_pipe);
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(projection));
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(*proj));
|
||||
sg_apply_bindings(&par_bind);
|
||||
sg_draw(0, 4, draw_count);
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ void stop_emitter(emitter *e);
|
|||
|
||||
void emitter_emit(emitter *e, int count);
|
||||
void emitters_step(double dt);
|
||||
void emitters_draw();
|
||||
void emitters_draw(HMM_Mat4 *proj);
|
||||
void emitter_step(emitter *e, double dt);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -286,6 +286,7 @@ HMM_Vec2 screen2world(HMM_Vec2 pos)
|
|||
|
||||
HMM_Mat4 projection = {0.f};
|
||||
HMM_Mat4 hudproj = {0.f};
|
||||
HMM_Mat4 useproj = {0};
|
||||
|
||||
HMM_Vec3 dirl_pos = {4, 100, 20};
|
||||
|
||||
|
@ -341,7 +342,6 @@ void openglRender(struct window *window, gameobject *cam, float zoom) {
|
|||
campos.y + camzoom * usesize.y / 2, -10000.f, 10000.f);
|
||||
|
||||
hudproj = HMM_Orthographic_LH_ZO(0, usesize.x, 0, usesize.y, -1.f, 1.f);
|
||||
return;
|
||||
|
||||
/* if (gif.rec && (apptime() - gif.timer) > gif.spf) {
|
||||
sg_begin_pass(&(sg_pass){
|
||||
|
|
|
@ -31,6 +31,8 @@ extern HMM_Vec3 dirl_pos;
|
|||
extern HMM_Mat4 projection;
|
||||
extern HMM_Mat4 hudproj;
|
||||
|
||||
extern HMM_Mat4 useproj;
|
||||
|
||||
struct camera3d {
|
||||
|
||||
};
|
||||
|
|
|
@ -94,7 +94,7 @@ void sprite_draw_all() {
|
|||
if (arrlen(sprites) == 0) return;
|
||||
|
||||
sg_apply_pipeline(pip_sprite);
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(projection));
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(useproj));
|
||||
|
||||
qsort(sprites, arrlen(sprites), sizeof(*sprites), sprite_sort);
|
||||
|
||||
|
@ -103,7 +103,6 @@ void sprite_draw_all() {
|
|||
}
|
||||
|
||||
void sprite_initialize() {
|
||||
|
||||
shader_sprite = sg_make_shader(sprite_shader_desc(sg_query_backend()));
|
||||
|
||||
pip_sprite = sg_make_pipeline(&(sg_pipeline_desc){
|
||||
|
@ -213,7 +212,12 @@ void sprite_draw(struct sprite *sprite) {
|
|||
}
|
||||
|
||||
void gui_draw_img(texture *tex, transform2d t, int wrap, HMM_Vec2 wrapoffset, float wrapscale, struct rgba color) {
|
||||
//sg_apply_pipeline(pip_sprite);
|
||||
//sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(hudproj));
|
||||
sg_apply_pipeline(pip_sprite);
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(useproj));
|
||||
tex_draw(tex, transform2d2mat(t), ST_UNIT, color, wrap, wrapoffset, (HMM_Vec2){wrapscale,wrapscale}, (struct rgba){0,0,0,0}, 0);
|
||||
}
|
||||
|
||||
void slice9_draw(texture *tex, transform2d *t, HMM_Vec4 border, struct rgba color)
|
||||
{
|
||||
|
||||
}
|
Loading…
Reference in a new issue