2023-09-04 09:48:44 -05:00
|
|
|
#include "render.h"
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
#include "camera.h"
|
2023-05-12 13:22:05 -05:00
|
|
|
#include "config.h"
|
|
|
|
#include "datastream.h"
|
2021-11-30 21:29:18 -06:00
|
|
|
#include "debugdraw.h"
|
2023-05-12 13:22:05 -05:00
|
|
|
#include "font.h"
|
|
|
|
#include "gameobject.h"
|
2021-11-30 21:29:18 -06:00
|
|
|
#include "log.h"
|
2023-02-02 17:52:15 -06:00
|
|
|
#include "nuke.h"
|
2023-05-12 13:22:05 -05:00
|
|
|
#include "shader.h"
|
|
|
|
#include "sprite.h"
|
|
|
|
#include "window.h"
|
|
|
|
#include "model.h"
|
|
|
|
#include "stb_ds.h"
|
2023-09-11 15:07:36 -05:00
|
|
|
#include "stb_image_resize.h";
|
2023-09-04 09:48:44 -05:00
|
|
|
#include "resources.h"
|
2023-09-12 00:02:57 -05:00
|
|
|
#include "yugine.h"
|
2023-05-12 13:22:05 -05:00
|
|
|
|
2023-09-11 15:07:36 -05:00
|
|
|
#define SOKOL_GFX_IMPL
|
|
|
|
#include "sokol/sokol_gfx.h"
|
|
|
|
|
2023-09-12 00:02:57 -05:00
|
|
|
#define SOKOL_GFX_EXT_IMPL
|
|
|
|
#include "sokol/sokol_gfx_ext.h"
|
|
|
|
|
2023-09-11 15:07:36 -05:00
|
|
|
#define MSF_GIF_IMPL
|
|
|
|
#include "msf_gif.h"
|
|
|
|
|
2023-09-12 00:02:57 -05:00
|
|
|
static struct {
|
|
|
|
sg_pass pass;
|
|
|
|
sg_pass_action pa;
|
|
|
|
sg_pipeline pipe;
|
|
|
|
sg_bindings bind;
|
|
|
|
sg_shader shader;
|
|
|
|
sg_image img;
|
|
|
|
sg_image depth;
|
|
|
|
} sg_gif;
|
|
|
|
|
|
|
|
|
2023-09-12 07:56:40 -05:00
|
|
|
static struct {
|
|
|
|
int w;
|
|
|
|
int h;
|
|
|
|
int cpf;
|
|
|
|
int depth;
|
|
|
|
double timer;
|
|
|
|
double spf;
|
|
|
|
int rec;
|
|
|
|
char *buffer;
|
|
|
|
} gif;
|
|
|
|
|
2023-09-11 15:07:36 -05:00
|
|
|
MsfGifState gif_state = {};
|
2023-09-12 00:02:57 -05:00
|
|
|
void gif_rec_start(int w, int h, int cpf, int bitdepth)
|
2023-09-11 15:07:36 -05:00
|
|
|
{
|
2023-09-12 07:56:40 -05:00
|
|
|
gif.w = w;
|
|
|
|
gif.h = h;
|
|
|
|
gif.depth = bitdepth;
|
|
|
|
msf_gif_begin(&gif_state, gif.w, gif.h);
|
|
|
|
gif.cpf = cpf;
|
|
|
|
gif.spf = cpf/100.0;
|
|
|
|
gif.rec = 1;
|
|
|
|
gif.timer = appTime;
|
|
|
|
if (gif.buffer) free(gif.buffer);
|
|
|
|
gif.buffer = malloc(gif.w*gif.h*4);
|
2023-09-12 00:02:57 -05:00
|
|
|
|
|
|
|
sg_destroy_image(sg_gif.img);
|
|
|
|
sg_destroy_image(sg_gif.depth);
|
|
|
|
sg_destroy_pass(sg_gif.pass);
|
|
|
|
|
|
|
|
sg_gif.img = sg_make_image(&(sg_image_desc){
|
|
|
|
.render_target = true,
|
2023-09-12 07:56:40 -05:00
|
|
|
.width = gif.w,
|
|
|
|
.height = gif.h,
|
2023-09-12 00:02:57 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
sg_gif.depth = sg_make_image(&(sg_image_desc){
|
|
|
|
.render_target = true,
|
2023-09-12 07:56:40 -05:00
|
|
|
.width = gif.w,
|
|
|
|
.height = gif.h,
|
2023-09-12 00:02:57 -05:00
|
|
|
.pixel_format = SG_PIXELFORMAT_DEPTH_STENCIL
|
|
|
|
});
|
|
|
|
|
|
|
|
sg_gif.pass = sg_make_pass(&(sg_pass_desc){
|
|
|
|
.color_attachments[0].image = sg_gif.img,
|
|
|
|
.depth_stencil_attachment.image = sg_gif.depth
|
|
|
|
});
|
2023-09-11 15:07:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void gif_rec_end(char *path)
|
|
|
|
{
|
2023-09-12 17:19:46 -05:00
|
|
|
if (!gif.rec) return;
|
|
|
|
|
2023-09-12 07:56:40 -05:00
|
|
|
MsfGifResult gif_res = msf_gif_end(&gif_state);
|
|
|
|
if (gif_res.data) {
|
2023-09-11 15:07:36 -05:00
|
|
|
FILE *f = fopen(path, "wb");
|
2023-09-12 07:56:40 -05:00
|
|
|
fwrite(gif_res.data, gif_res.dataSize, 1, f);
|
2023-09-11 15:07:36 -05:00
|
|
|
fclose(f);
|
|
|
|
}
|
2023-09-12 07:56:40 -05:00
|
|
|
msf_gif_free(gif_res);
|
|
|
|
gif.rec = 0;
|
2023-09-11 15:07:36 -05:00
|
|
|
}
|
|
|
|
|
2023-08-31 17:23:24 -05:00
|
|
|
#include "sokol/sokol_app.h"
|
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
#include "HandmadeMath.h"
|
2022-12-22 16:58:06 -06:00
|
|
|
|
2023-02-16 16:13:07 -06:00
|
|
|
int renderMode = LIT;
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-11-19 17:13:57 -06:00
|
|
|
struct shader *spriteShader = NULL;
|
2023-02-16 16:13:07 -06:00
|
|
|
struct shader *wireframeShader = NULL;
|
2022-11-19 17:13:57 -06:00
|
|
|
struct shader *animSpriteShader = NULL;
|
|
|
|
static struct shader *textShader;
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2023-05-24 20:45:50 -05:00
|
|
|
struct rgba editorClearColor = {35,60,92,255};
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
float shadowLookahead = 8.5f;
|
|
|
|
|
2023-05-24 20:45:50 -05:00
|
|
|
struct rgba gridSmallColor = {
|
|
|
|
.r = 255 * 0.35f,
|
|
|
|
.g = 255,
|
|
|
|
.b = 255 * 0.9f
|
|
|
|
};
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2023-05-24 20:45:50 -05:00
|
|
|
struct rgba gridBigColor = {
|
|
|
|
.r = 255 * 0.92f,
|
|
|
|
.g = 255 * 0.92f,
|
|
|
|
.b = 255 * 0.68f
|
|
|
|
};
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
float gridScale = 500.f;
|
|
|
|
float smallGridUnit = 1.f;
|
|
|
|
float bigGridUnit = 10.f;
|
|
|
|
float gridSmallThickness = 2.f;
|
|
|
|
float gridBigThickness = 7.f;
|
|
|
|
float gridOpacity = 0.3f;
|
|
|
|
|
|
|
|
// Debug render modes
|
|
|
|
bool renderGizmos = false;
|
|
|
|
bool showGrid = true;
|
|
|
|
bool debugDrawPhysics = false;
|
|
|
|
bool renderNav = false;
|
|
|
|
|
|
|
|
// Lighting effect flags
|
|
|
|
bool renderAO = true;
|
|
|
|
bool renderDynamicShadows = true;
|
|
|
|
bool renderRefraction = true;
|
|
|
|
bool renderReflection = true;
|
|
|
|
|
|
|
|
///// for editing
|
2022-11-19 17:13:57 -06:00
|
|
|
struct gameobject *selectedobject = NULL;
|
2023-05-12 13:22:05 -05:00
|
|
|
char objectName[200] = {'\0'}; // object name buffer
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
sg_image ddimg;
|
|
|
|
|
2022-12-21 19:24:59 -06:00
|
|
|
void debug_draw_phys(int draw) {
|
2023-05-12 13:22:05 -05:00
|
|
|
debugDrawPhysics = draw;
|
2022-12-21 19:24:59 -06:00
|
|
|
}
|
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
void opengl_rendermode(enum RenderMode r) {
|
2023-02-16 16:13:07 -06:00
|
|
|
renderMode = r;
|
|
|
|
}
|
|
|
|
|
2023-05-04 17:07:00 -05:00
|
|
|
sg_pipeline mainpip;
|
|
|
|
sg_pass_action pass_action = {0};
|
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
static struct {
|
|
|
|
sg_pass_action pass_action;
|
|
|
|
sg_pass pass;
|
|
|
|
sg_pipeline pipe;
|
|
|
|
sg_shader shader;
|
|
|
|
} sg_shadow;
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
sg_shader shader;
|
|
|
|
sg_pipeline pipe;
|
|
|
|
sg_bindings bind;
|
|
|
|
sg_pass pass;
|
|
|
|
sg_image img;
|
|
|
|
sg_image depth_img;
|
|
|
|
} crt_post;
|
|
|
|
|
2023-09-12 00:02:57 -05:00
|
|
|
|
2023-09-04 09:48:44 -05:00
|
|
|
void trace_make_shader(sg_shader_desc *d, sg_shader result, void *data)
|
2023-05-24 20:45:50 -05:00
|
|
|
{
|
2023-09-04 09:48:44 -05:00
|
|
|
if (sg_query_shader_state(result) == SG_RESOURCESTATE_FAILED)
|
|
|
|
YughError("FAILED MAKING A SHADER: %s\n%s\n%s", d->label);
|
2023-05-24 20:45:50 -05:00
|
|
|
}
|
|
|
|
|
2023-09-04 09:48:44 -05:00
|
|
|
void trace_fail_shader(sg_shader id, void *data)
|
2023-05-24 20:45:50 -05:00
|
|
|
{
|
2023-06-28 11:35:41 -05:00
|
|
|
YughWarn("SHADER DID NOT COMPILE");
|
|
|
|
}
|
|
|
|
|
2023-09-04 09:48:44 -05:00
|
|
|
void trace_destroy_shader(sg_shader shd, void *data)
|
2023-06-28 11:35:41 -05:00
|
|
|
{
|
|
|
|
YughWarn("DESTROYED SHADER");
|
2023-05-24 20:45:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static sg_trace_hooks hooks = {
|
2023-09-04 09:48:44 -05:00
|
|
|
.fail_shader = trace_fail_shader,
|
|
|
|
.make_shader = trace_make_shader,
|
|
|
|
.destroy_shader = trace_destroy_shader,
|
2023-05-24 20:45:50 -05:00
|
|
|
};
|
|
|
|
|
2023-09-04 09:48:44 -05:00
|
|
|
void render_init() {
|
2023-08-31 13:00:33 -05:00
|
|
|
mainwin.width = sapp_width();
|
|
|
|
mainwin.height = sapp_height();
|
|
|
|
|
|
|
|
sg_setup(&(sg_desc){
|
|
|
|
.logger = {
|
|
|
|
.func = sg_logging,
|
|
|
|
.user_data = NULL,
|
|
|
|
},
|
|
|
|
|
|
|
|
.buffer_pool_size = 1024,
|
|
|
|
.context.sample_count = 1,
|
|
|
|
});
|
|
|
|
|
2023-05-24 20:45:50 -05:00
|
|
|
sg_trace_hooks hh = sg_install_trace_hooks(&hooks);
|
|
|
|
|
2023-09-04 09:48:44 -05:00
|
|
|
font_init();
|
2023-05-12 13:22:05 -05:00
|
|
|
debugdraw_init();
|
|
|
|
sprite_initialize();
|
2023-08-31 02:05:06 -05:00
|
|
|
nuke_init(&mainwin);
|
2023-05-12 13:22:05 -05:00
|
|
|
|
|
|
|
model_init();
|
2023-05-24 20:45:50 -05:00
|
|
|
sg_color c;
|
|
|
|
rgba2floats(&c, editorClearColor);
|
2023-05-12 13:22:05 -05:00
|
|
|
pass_action = (sg_pass_action){
|
2023-05-24 20:45:50 -05:00
|
|
|
.colors[0] = {.action = SG_ACTION_CLEAR, .value = c}
|
2023-05-12 13:22:05 -05:00
|
|
|
};
|
|
|
|
|
2023-05-24 20:45:50 -05:00
|
|
|
crt_post.shader = sg_compile_shader("shaders/postvert.glsl", "shaders/crtfrag.glsl", &(sg_shader_desc){
|
2023-05-12 13:22:05 -05:00
|
|
|
.fs.images[0] = {
|
|
|
|
.name = "diffuse_texture",
|
|
|
|
.image_type = SG_IMAGETYPE_2D,
|
|
|
|
.sampler_type = SG_SAMPLERTYPE_FLOAT
|
2022-06-27 14:12:26 -05:00
|
|
|
}
|
2023-05-12 13:22:05 -05:00
|
|
|
});
|
|
|
|
|
2023-09-12 00:02:57 -05:00
|
|
|
sg_gif.shader = sg_compile_shader("shaders/postvert.glsl", "shaders/box.glsl", &(sg_shader_desc){
|
|
|
|
.fs.images[0] = {
|
|
|
|
.name = "diffuse_texture",
|
|
|
|
.image_type = SG_IMAGETYPE_2D,
|
|
|
|
.sampler_type = SG_SAMPLERTYPE_FLOAT
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
sg_gif.pipe = sg_make_pipeline(&(sg_pipeline_desc){
|
|
|
|
.shader = sg_gif.shader,
|
|
|
|
.layout = {
|
|
|
|
.attrs = {
|
|
|
|
[0].format = SG_VERTEXFORMAT_FLOAT2,
|
|
|
|
[1].format = SG_VERTEXFORMAT_FLOAT2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
crt_post.pipe = sg_make_pipeline(&(sg_pipeline_desc){
|
|
|
|
.shader = crt_post.shader,
|
|
|
|
.layout = {
|
|
|
|
.attrs = {
|
|
|
|
[0].format = SG_VERTEXFORMAT_FLOAT2,
|
|
|
|
[1].format = SG_VERTEXFORMAT_FLOAT2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
crt_post.img = sg_make_image(&(sg_image_desc){
|
|
|
|
.render_target = true,
|
2023-09-04 01:20:55 -05:00
|
|
|
.width = mainwin.width,
|
|
|
|
.height = mainwin.height,
|
2023-05-12 13:22:05 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
crt_post.depth_img = sg_make_image(&(sg_image_desc){
|
|
|
|
.render_target = true,
|
2023-09-04 01:20:55 -05:00
|
|
|
.width = mainwin.width,
|
|
|
|
.height = mainwin.height,
|
2023-05-12 13:22:05 -05:00
|
|
|
.pixel_format = SG_PIXELFORMAT_DEPTH_STENCIL
|
|
|
|
});
|
|
|
|
|
|
|
|
crt_post.pass = sg_make_pass(&(sg_pass_desc){
|
|
|
|
.color_attachments[0].image = crt_post.img,
|
|
|
|
.depth_stencil_attachment.image = crt_post.depth_img,
|
|
|
|
});
|
|
|
|
|
2023-09-12 00:02:57 -05:00
|
|
|
sg_gif.pass = sg_make_pass(&(sg_pass_desc){
|
|
|
|
.color_attachments[0].image = sg_gif.img,
|
|
|
|
.depth_stencil_attachment.image = sg_gif.depth
|
|
|
|
});
|
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
float crt_quad[] = {
|
|
|
|
-1, 1, 0, 1,
|
|
|
|
-1, -1, 0, 0,
|
|
|
|
1, -1, 1, 0,
|
|
|
|
-1, 1, 0, 1,
|
|
|
|
1, -1, 1, 0,
|
|
|
|
1, 1, 1, 1
|
|
|
|
};
|
|
|
|
|
|
|
|
crt_post.bind.vertex_buffers[0] = sg_make_buffer(&(sg_buffer_desc){
|
|
|
|
.size = sizeof(crt_quad),
|
|
|
|
.data = crt_quad
|
|
|
|
});
|
|
|
|
|
|
|
|
crt_post.bind.fs_images[0] = crt_post.img;
|
2023-05-04 17:07:00 -05:00
|
|
|
/*
|
2023-05-12 13:22:05 -05:00
|
|
|
sg_image_desc shadow_desc = {
|
|
|
|
.render_target = true,
|
|
|
|
.width = 1024,
|
|
|
|
.height = 1024,
|
|
|
|
.pixel_format = SG_PIXELFORMAT_R32F,
|
|
|
|
};
|
|
|
|
sg_image depth_img = sg_make_image(&shadow_desc);
|
|
|
|
shadow_desc.pixel_format = SG_PIXELFORMAT_DEPTH;
|
|
|
|
ddimg = sg_make_image(&shadow_desc);
|
|
|
|
|
|
|
|
sg_shadow.pass = sg_make_pass(&(sg_pass_desc){
|
|
|
|
.color_attachments[0].image = depth_img,
|
|
|
|
.depth_stencil_attachment.image = ddimg,
|
|
|
|
});
|
|
|
|
|
|
|
|
sg_shadow.pass_action = (sg_pass_action) {
|
|
|
|
.colors[0] = { .action=SG_ACTION_CLEAR, .value = {1,1,1,1} } };
|
|
|
|
|
2023-05-24 20:45:50 -05:00
|
|
|
sg_shadow.shader = sg_compile_shader("shaders/shadowvert.glsl", "shaders/shadowfrag.glsl", &(sg_shader_desc){
|
2023-05-12 13:22:05 -05:00
|
|
|
.vs.uniform_blocks[0] = {
|
|
|
|
.size = sizeof(float) * 16 * 2,
|
|
|
|
.uniforms = {
|
|
|
|
[0] = {.name = "lightSpaceMatrix", .type = SG_UNIFORMTYPE_MAT4},
|
|
|
|
[1] = {.name = "model", .type = SG_UNIFORMTYPE_MAT4},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
sg_shadow.pipe = sg_make_pipeline(&(sg_pipeline_desc){
|
|
|
|
.shader = sg_shadow.shader,
|
|
|
|
.layout = {
|
|
|
|
.attrs = {
|
|
|
|
[0].format = SG_VERTEXFORMAT_FLOAT3,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
.depth = {
|
|
|
|
.compare = SG_COMPAREFUNC_LESS_EQUAL,
|
|
|
|
.write_enabled = true,
|
|
|
|
.pixel_format = SG_PIXELFORMAT_DEPTH
|
|
|
|
},
|
|
|
|
.colors[0].pixel_format = SG_PIXELFORMAT_R32F,
|
|
|
|
.index_type = SG_INDEXTYPE_UINT16,
|
|
|
|
.cull_mode = SG_CULLMODE_BACK,
|
|
|
|
});
|
|
|
|
|
2023-05-04 17:07:00 -05:00
|
|
|
*/
|
2023-05-24 20:45:50 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void render_winsize()
|
|
|
|
{
|
|
|
|
sg_destroy_image(crt_post.img);
|
|
|
|
sg_destroy_image(crt_post.depth_img);
|
|
|
|
sg_destroy_pass(crt_post.pass);
|
|
|
|
|
|
|
|
crt_post.img = sg_make_image(&(sg_image_desc){
|
|
|
|
.render_target = true,
|
2023-08-31 02:05:06 -05:00
|
|
|
.width = mainwin.width,
|
|
|
|
.height = mainwin.height
|
2023-05-24 20:45:50 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
crt_post.depth_img = sg_make_image(&(sg_image_desc){
|
|
|
|
.render_target = true,
|
2023-08-31 02:05:06 -05:00
|
|
|
.width = mainwin.width,
|
|
|
|
.height = mainwin.height,
|
2023-05-24 20:45:50 -05:00
|
|
|
.pixel_format = SG_PIXELFORMAT_DEPTH_STENCIL
|
|
|
|
});
|
|
|
|
|
|
|
|
crt_post.pass = sg_make_pass(&(sg_pass_desc){
|
|
|
|
.color_attachments[0].image = crt_post.img,
|
|
|
|
.depth_stencil_attachment.image = crt_post.depth_img,
|
|
|
|
});
|
|
|
|
|
|
|
|
crt_post.bind.fs_images[0] = crt_post.img;
|
2021-11-30 21:29:18 -06:00
|
|
|
}
|
|
|
|
|
2022-12-22 16:58:06 -06:00
|
|
|
static cpBody *camera = NULL;
|
|
|
|
void set_cam_body(cpBody *body) {
|
2023-05-12 13:22:05 -05:00
|
|
|
camera = body;
|
2022-12-22 16:58:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
cpVect cam_pos() {
|
2023-05-12 13:22:05 -05:00
|
|
|
return camera ? cpBodyGetPosition(camera) : cpvzero;
|
2022-12-22 16:58:06 -06:00
|
|
|
}
|
2023-05-12 13:22:05 -05:00
|
|
|
|
2022-12-22 16:58:06 -06:00
|
|
|
static float zoom = 1.f;
|
2023-02-20 16:28:07 -06:00
|
|
|
float cam_zoom() { return zoom; }
|
|
|
|
|
2022-12-22 16:58:06 -06:00
|
|
|
void add_zoom(float val) { zoom = val; }
|
|
|
|
|
2023-05-24 20:45:50 -05:00
|
|
|
HMM_Mat4 projection = {0.f};
|
|
|
|
HMM_Mat4 hudproj = {0.f};
|
2023-05-04 17:07:00 -05:00
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
HMM_Vec3 dirl_pos = {4, 100, 20};
|
2022-06-30 10:31:23 -05:00
|
|
|
|
2023-09-12 00:02:57 -05:00
|
|
|
void full_2d_pass(struct window *window)
|
|
|
|
{
|
2023-05-12 13:22:05 -05:00
|
|
|
//////////// 2D projection
|
|
|
|
cpVect pos = cam_pos();
|
|
|
|
|
2023-05-24 20:45:50 -05:00
|
|
|
projection = HMM_Orthographic_RH_NO(
|
|
|
|
pos.x - zoom * window->width / 2,
|
2023-05-12 13:22:05 -05:00
|
|
|
pos.x + zoom * window->width / 2,
|
|
|
|
pos.y - zoom * window->height / 2,
|
|
|
|
pos.y + zoom * window->height / 2, -1.f, 1.f);
|
|
|
|
|
2023-05-24 20:45:50 -05:00
|
|
|
hudproj = HMM_Orthographic_RH_NO(0, window->width, 0, window->height, -1.f, 1.f);
|
2023-08-31 02:05:06 -05:00
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
sprite_draw_all();
|
2023-05-07 19:47:49 -05:00
|
|
|
sprite_flush();
|
2023-05-24 20:45:50 -05:00
|
|
|
call_draw();
|
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
//// DEBUG
|
2023-05-24 20:45:50 -05:00
|
|
|
if (debugDrawPhysics) {
|
2023-05-12 13:22:05 -05:00
|
|
|
gameobject_draw_debugs();
|
2023-08-23 17:18:34 -05:00
|
|
|
call_debugs();
|
2023-05-24 20:45:50 -05:00
|
|
|
}
|
2023-08-23 17:18:34 -05:00
|
|
|
|
2023-06-05 10:32:45 -05:00
|
|
|
debug_flush(&projection);
|
2023-08-23 17:18:34 -05:00
|
|
|
text_flush(&projection);
|
2023-05-24 20:45:50 -05:00
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
////// TEXT && GUI
|
2023-06-05 10:32:45 -05:00
|
|
|
debug_nextpass();
|
2023-08-23 17:18:34 -05:00
|
|
|
nuke_start();
|
|
|
|
call_gui();
|
2023-06-05 10:32:45 -05:00
|
|
|
debug_flush(&hudproj);
|
2023-06-28 11:35:41 -05:00
|
|
|
text_flush(&hudproj);
|
2023-08-23 17:18:34 -05:00
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
call_nk_gui();
|
|
|
|
nuke_end();
|
2023-09-12 17:19:46 -05:00
|
|
|
|
2023-09-12 00:02:57 -05:00
|
|
|
}
|
2023-05-12 13:22:05 -05:00
|
|
|
|
2023-09-12 00:02:57 -05:00
|
|
|
void full_3d_pass(struct window *window)
|
|
|
|
{
|
|
|
|
HMM_Mat4 model = HMM_M4D(1.f);
|
|
|
|
float scale = 0.08;
|
|
|
|
model = HMM_MulM4(model, HMM_Scale((HMM_Vec3){scale,scale,scale}));
|
|
|
|
|
|
|
|
// Shadow pass
|
|
|
|
sg_begin_pass(sg_shadow.pass, &sg_shadow.pass_action);
|
|
|
|
sg_apply_pipeline(sg_shadow.pipe);
|
|
|
|
|
|
|
|
HMM_Mat4 light_proj = HMM_Orthographic_RH_ZO(-100.f, 100.f, -100.f, 100.f, 1.f, 100.f);
|
|
|
|
HMM_Mat4 light_view = HMM_LookAt_RH(dirl_pos, (HMM_Vec3){0,0,0}, (HMM_Vec3){0,1,0});
|
|
|
|
|
|
|
|
HMM_Mat4 lsm = HMM_MulM4(light_proj, light_view);
|
|
|
|
|
|
|
|
HMM_Mat4 subo[2];
|
|
|
|
subo[0] = lsm;
|
|
|
|
subo[1] = model;
|
|
|
|
|
|
|
|
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(subo));
|
|
|
|
}
|
|
|
|
|
|
|
|
void openglRender(struct window *window) {
|
|
|
|
sg_begin_pass(crt_post.pass, &pass_action);
|
|
|
|
full_2d_pass(window);
|
2023-05-12 13:22:05 -05:00
|
|
|
sg_end_pass();
|
|
|
|
|
2023-09-12 00:02:57 -05:00
|
|
|
|
2023-09-12 07:56:40 -05:00
|
|
|
if (gif.rec && (appTime - gif.timer) > gif.spf) {
|
2023-09-12 00:02:57 -05:00
|
|
|
sg_begin_pass(sg_gif.pass, &pass_action);
|
|
|
|
sg_apply_pipeline(sg_gif.pipe);
|
|
|
|
sg_apply_bindings(&crt_post.bind);
|
|
|
|
sg_draw(0,6,1);
|
|
|
|
sg_end_pass();
|
|
|
|
|
2023-09-12 07:56:40 -05:00
|
|
|
gif.timer = appTime;
|
|
|
|
sg_query_image_pixels(sg_gif.img, gif.buffer, gif.w*gif.h*4);
|
|
|
|
msf_gif_frame(&gif_state, gif.buffer, gif.cpf, gif.depth, gif.w * -4);
|
2023-09-12 00:02:57 -05:00
|
|
|
}
|
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
sg_begin_default_pass(&pass_action, window->width, window->height);
|
|
|
|
sg_apply_pipeline(crt_post.pipe);
|
|
|
|
sg_apply_bindings(&crt_post.bind);
|
|
|
|
sg_draw(0,6,1);
|
2023-09-11 15:07:36 -05:00
|
|
|
|
2023-09-12 00:02:57 -05:00
|
|
|
sg_end_pass();
|
2023-05-12 13:22:05 -05:00
|
|
|
|
|
|
|
sg_commit();
|
2023-06-05 10:32:45 -05:00
|
|
|
|
|
|
|
debug_newframe();
|
2021-11-30 21:29:18 -06:00
|
|
|
}
|
2023-05-24 20:45:50 -05:00
|
|
|
|
|
|
|
sg_shader sg_compile_shader(const char *v, const char *f, sg_shader_desc *d)
|
|
|
|
{
|
2023-06-07 08:41:09 -05:00
|
|
|
YughInfo("Making shader with %s and %s", v, f);
|
2023-09-07 16:46:35 -05:00
|
|
|
char *vs = slurp_text(v, NULL);
|
|
|
|
char *fs = slurp_text(f, NULL);
|
2023-05-24 20:45:50 -05:00
|
|
|
|
|
|
|
d->vs.source = vs;
|
|
|
|
d->fs.source = fs;
|
2023-09-04 09:48:44 -05:00
|
|
|
d->label = v;
|
2023-05-24 20:45:50 -05:00
|
|
|
|
|
|
|
sg_shader ret = sg_make_shader(d);
|
2023-09-04 09:48:44 -05:00
|
|
|
|
2023-05-24 20:45:50 -05:00
|
|
|
free(vs);
|
|
|
|
free(fs);
|
|
|
|
return ret;
|
|
|
|
}
|