Compiles on MacOS; use sokol shader converter for shader x-compilation; update sokol

This commit is contained in:
John Alanbrook 2023-09-15 08:37:07 +00:00
parent e392f65485
commit d86133a317
56 changed files with 10528 additions and 8266 deletions

View file

@ -1,6 +1,4 @@
PROCS != nproc MAKEFLAGS = --jobs=8
MAKEFLAGS = --jobs=$(PROCS)
UNAME != uname UNAME != uname
MAKEDIR != pwd MAKEDIR != pwd
@ -62,7 +60,7 @@ endif
PTYPE != uname -m PTYPE != uname -m
CFLAGS += -DHAVE_CEIL -DHAVE_FLOOR -DHAVE_FMOD -DHAVE_LRINT -DHAVE_LRINTF $(includeflag) -MD $(WARNING_FLAGS) -I. -DCP_USE_DOUBLES=0 -DTINYSPLINE_FLOAT_PRECISION -DVER=\"$(VER)\" -DINFO=\"$(INFO)\" CFLAGS += -DHAVE_CEIL -DCP_USE_CGTYPES=0 -DHAVE_FLOOR -DHAVE_FMOD -DHAVE_LRINT -DHAVE_LRINTF $(includeflag) -MD $(WARNING_FLAGS) -I. -DVER=\"$(VER)\" -DINFO=\"$(INFO)\"
PKGCMD = tar --directory $(BIN) --exclude="./*.a" --exclude="./obj" -czf $(DISTDIR)/$(DIST) . PKGCMD = tar --directory $(BIN) --exclude="./*.a" --exclude="./obj" -czf $(DISTDIR)/$(DIST) .
ZIP = .tar.gz ZIP = .tar.gz
@ -95,12 +93,11 @@ else
endif endif
ifeq ($(UNAME), Darwin) ifeq ($(UNAME), Darwin)
ifeq ($(PLATFORM), macosx) CFLAGS += -x objective-c
LDLIBS += Coca QuartzCore OpenGL # LDLIBS += Cocoa QuartzCore OpenGL
LDFLAGS += -framework Cocoa -framework QuartzCore -framework OpenGL -framework AudioToolbox
PLAT = mac-$(ARCH)$(INFO) PLAT = mac-$(ARCH)$(INFO)
else ifeq ($(PLATFORM), iphoneos) #LDLIBS += Foundation UIKit OpenGLES GLKit
LDLIBS += Foundation UIKit OpenGLES GLKit
endif
endif endif
endif endif
@ -115,7 +112,7 @@ OBJS := $(addprefix $(BIN)/obj/, $(OBJS))
engineincs != find source/engine -maxdepth 1 -type d engineincs != find source/engine -maxdepth 1 -type d
includeflag != find source -type d -name include includeflag != find source -type d -name include
includeflag += $(engineincs) source/engine/thirdparty/Nuklear source/engine/thirdparty/tinycdb-0.78 includeflag += $(engineincs) source/engine/thirdparty/Nuklear source/engine/thirdparty/tinycdb-0.78 source/shaders
includeflag := $(addprefix -I, $(includeflag)) includeflag := $(addprefix -I, $(includeflag))
WARNING_FLAGS = -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types #-Wall -Wno-incompatible-function-pointer-types -Wno-unused-function# -pedantic -Wextra -Wwrite-strings -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types -Wno-unused-function -Wno-int-conversion WARNING_FLAGS = -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types #-Wall -Wno-incompatible-function-pointer-types -Wno-unused-function# -pedantic -Wextra -Wwrite-strings -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types -Wno-unused-function -Wno-int-conversion
@ -142,6 +139,9 @@ all: $(DISTDIR)/$(DIST)
DESTDIR ?= ~/.bin DESTDIR ?= ~/.bin
SHADERS = $(shell ls source/shaders/*.sglsl)
SHADERS := $(patsubst %.sglsl, %.sglsl.h, $(SHADERS))
install: $(DISTDIR)/$(DIST) install: $(DISTDIR)/$(DIST)
@echo Unpacking $(DIST) in $(DESTDIR) @echo Unpacking $(DIST) in $(DESTDIR)
@$(UNZIP) @$(UNZIP)
@ -151,16 +151,15 @@ $(BIN)/$(NAME): $(BIN)/libengine.a $(BIN)/libquickjs.a
$(LD) $^ $(LDFLAGS) -L$(BIN) $(LDLIBS) -o $@ $(LD) $^ $(LDFLAGS) -L$(BIN) $(LDLIBS) -o $@
@echo Finished build @echo Finished build
$(DISTDIR)/$(DIST): $(BIN)/$(NAME) source/shaders/* $(SCRIPTS) assets/* $(DISTDIR)/$(DIST): $(BIN)/$(NAME) $(SCRIPTS) assets/*
@echo Creating distribution $(DIST) @echo Creating distribution $(DIST)
@mkdir -p $(DISTDIR) @mkdir -p $(DISTDIR)
@cp -rf assets/* $(BIN) @cp -rf assets/* $(BIN)
@cp -rf source/shaders $(BIN)
@cp -rf source/scripts $(BIN) @cp -rf source/scripts $(BIN)
@$(PKGCMD) @$(PKGCMD)
$(BIN)/libengine.a: $(OBJS) $(BIN)/libengine.a: $(SHADERS) $(OBJS)
@$(AR) rcs $@ $^ @$(AR) rcs $@ $(OBJS)
$(BIN)/libquickjs.a: $(BIN)/libquickjs.a:
make -C quickjs clean make -C quickjs clean
@ -172,8 +171,24 @@ $(OBJDIR)/%.o:%.c
@echo Making C object $@ @echo Making C object $@
@$(CC) $(CFLAGS) -c $< -o $@ @$(CC) $(CFLAGS) -c $< -o $@
%.c: $(SHADERS)
shaders: $(SHADERS)
@echo Making shaders
%.sglsl.h:%.sglsl
@echo Creating shader $^
@./sokol-shdc --ifdef -i $^ --slang=glsl330:hlsl5:metal_macos -o $@
clean: clean:
@echo Cleaning project @echo Cleaning project
@rm -rf bin/* @rm -rf bin/*
@rm -f *.gz @rm -f *.gz
@rm source/shaders/*.sglsl.h
@rm source/shaders/*.metal
@rm -rf dist/* @rm -rf dist/*
TAGINC != find . -name "*.[chj]"
tags: $(TAGINC)
@echo Making tags.
@etags $(TAGINC)

View file

@ -7,6 +7,8 @@
#include "font.h" #include "font.h"
#include "window.h" #include "window.h"
#include "diffuse.sglsl.h"
#include "render.h" #include "render.h"
// #define HANDMADE_MATH_USE_TURNS // #define HANDMADE_MATH_USE_TURNS
@ -37,32 +39,7 @@ static sg_shader model_shader;
static sg_pipeline model_pipe; static sg_pipeline model_pipe;
void model_init() { void model_init() {
model_shader = sg_compile_shader("shaders/diffuse_v.glsl", "shaders/diffuse_f.glsl", &(sg_shader_desc){ model_shader = sg_make_shader(diffuse_shader_desc(sg_query_backend()));
.vs.uniform_blocks[0] = {
.size = sizeof(float) * 16 * 4,
.uniforms = {
[0] = {.name = "vp", .type = SG_UNIFORMTYPE_MAT4},
[1] = {.name = "model", .type = SG_UNIFORMTYPE_MAT4},
[2] = {.name = "proj", .type = SG_UNIFORMTYPE_MAT4},
[3] = {.name = "lsm", .type = SG_UNIFORMTYPE_MAT4},
}},
.fs.uniform_blocks[0] = {
.size = sizeof(float) * 3 * 5,
.uniforms = {
[0] = {.name = "point_pos", .type = SG_UNIFORMTYPE_FLOAT3},
[1] = {.name = "dir_dir", .type = SG_UNIFORMTYPE_FLOAT3},
[2] = {.name = "view_pos", .type = SG_UNIFORMTYPE_FLOAT3},
[3] = {.name = "spot_pos", .type = SG_UNIFORMTYPE_FLOAT3},
[4] = {.name = "spot_dir", .type = SG_UNIFORMTYPE_FLOAT3},
},
},
.fs.images[0] = {.name = "diffuse", .image_type = SG_IMAGETYPE_2D, .sampler_type = SG_SAMPLERTYPE_FLOAT},
.fs.images[1] = { .name = "normmap", .image_type = SG_IMAGETYPE_2D, .sampler_type = SG_SAMPLERTYPE_FLOAT},
.fs.images[2] = {.name = "shadow_map", .image_type = SG_IMAGETYPE_2D, .sampler_type = SG_SAMPLERTYPE_FLOAT},
});
model_pipe = sg_make_pipeline(&(sg_pipeline_desc){ model_pipe = sg_make_pipeline(&(sg_pipeline_desc){
.shader = model_shader, .shader = model_shader,
@ -181,17 +158,17 @@ struct model *MakeModel(const char *path) {
if (primitive.material->has_pbr_metallic_roughness && primitive.material->pbr_metallic_roughness.base_color_texture.texture) { if (primitive.material->has_pbr_metallic_roughness && primitive.material->pbr_metallic_roughness.base_color_texture.texture) {
// YughWarn("Texture is %s.", primitive.material->pbr_metallic_roughness.base_color_texture.texture->image->uri); // YughWarn("Texture is %s.", primitive.material->pbr_metallic_roughness.base_color_texture.texture->image->uri);
model->meshes[j].bind.fs_images[0] = texture_pullfromfile(primitive.material->pbr_metallic_roughness.base_color_texture.texture->image->uri)->id; model->meshes[j].bind.fs.images[0] = texture_pullfromfile(primitive.material->pbr_metallic_roughness.base_color_texture.texture->image->uri)->id;
} else } else
model->meshes[j].bind.fs_images[0] = texture_pullfromfile("k")->id; model->meshes[j].bind.fs.images[0] = texture_pullfromfile("k")->id;
cgltf_texture *tex; cgltf_texture *tex;
if (tex = primitive.material->normal_texture.texture) { if (tex = primitive.material->normal_texture.texture) {
model->meshes[j].bind.fs_images[1] = texture_pullfromfile(tex->image->uri)->id; model->meshes[j].bind.fs.images[1] = texture_pullfromfile(tex->image->uri)->id;
} else } else
model->meshes[j].bind.fs_images[1] = texture_pullfromfile("k")->id; model->meshes[j].bind.fs.images[1] = texture_pullfromfile("k")->id;
model->meshes[j].bind.fs_images[2] = ddimg; model->meshes[j].bind.fs.images[2] = ddimg;
int has_norm = 0; int has_norm = 0;

View file

@ -15,6 +15,8 @@
#include "font.h" #include "font.h"
#include "render.h" #include "render.h"
#include "mpeg2.sglsl.h"
#define CBUF_IMPLEMENT #define CBUF_IMPLEMENT
#include "cbuf.h" #include "cbuf.h"
@ -105,13 +107,7 @@ void ds_openvideo(struct datastream *ds, const char *video, const char *adriver)
} }
void MakeDatastream() { void MakeDatastream() {
vid_shader = sg_compile_shader("shaders/videovert.glsl", "shaders/videofrag.glsl", &(sg_shader_desc){ vid_shader = sg_make_shader(mpeg2_shader_desc(sg_query_backend()));}
.fs.images[0] = {
.name = "video",
.image_type = SG_IMAGETYPE_2D,
.sampler_type = SG_SAMPLERTYPE_FLOAT
}});
}
void ds_advance(struct datastream *ds, double s) { void ds_advance(struct datastream *ds, double s) {
if (ds->playing) { if (ds->playing) {

View file

@ -11,6 +11,12 @@
#include "stb_ds.h" #include "stb_ds.h"
#include "sokol/sokol_gfx.h" #include "sokol/sokol_gfx.h"
#include "point.sglsl.h"
#include "poly.sglsl.h"
#include "circle.sglsl.h"
#include "line.sglsl.h"
#include "grid.sglsl.h"
#define PAR_STREAMLINES_IMPLEMENTATION #define PAR_STREAMLINES_IMPLEMENTATION
#include "par/par_streamlines.h" #include "par/par_streamlines.h"
@ -22,7 +28,7 @@ static sg_shader point_shader;
static sg_pipeline point_pipe; static sg_pipeline point_pipe;
static sg_bindings point_bind; static sg_bindings point_bind;
struct point_vertex { struct point_vertex {
cpVect pos; struct draw_p pos;
struct rgba color; struct rgba color;
float radius; float radius;
}; };
@ -34,7 +40,7 @@ static sg_shader line_shader;
static sg_pipeline line_pipe; static sg_pipeline line_pipe;
static sg_bindings line_bind; static sg_bindings line_bind;
struct line_vert { struct line_vert {
cpVect pos; struct draw_p pos;
float dist; float dist;
struct rgba color; struct rgba color;
float seg_len; float seg_len;
@ -59,7 +65,7 @@ static int poly_v = 0;
static int poly_sc = 0; static int poly_sc = 0;
static int poly_sv = 0; static int poly_sv = 0;
struct poly_vertex { struct poly_vertex {
cpVect pos; struct draw_p pos;
float uv[2]; float uv[2];
struct rgba color; struct rgba color;
}; };
@ -72,7 +78,7 @@ static sg_shader csg;
static int circle_count = 0; static int circle_count = 0;
static int circle_sc = 0; static int circle_sc = 0;
struct circle_vertex { struct circle_vertex {
cpVect pos; struct draw_p pos;
float radius; float radius;
struct rgba color; struct rgba color;
float segsize; float segsize;
@ -109,12 +115,9 @@ void debug_flush(HMM_Mat4 *view)
sg_apply_pipeline(line_pipe); sg_apply_pipeline(line_pipe);
sg_apply_bindings(&line_bind); sg_apply_bindings(&line_bind);
sg_apply_uniforms(SG_SHADERSTAGE_VS,0,SG_RANGE_REF(*view)); sg_apply_uniforms(SG_SHADERSTAGE_VS,0,SG_RANGE_REF(*view));
float time = appTime; lfs_params_t lt;
sg_range tr = { lt.time = appTime;
.ptr = &time, sg_apply_uniforms(SG_SHADERSTAGE_FS,0,SG_RANGE_REF(lt));
.size = sizeof(float)
};
sg_apply_uniforms(SG_SHADERSTAGE_FS,0,&tr);
sg_append_buffer(line_bind.vertex_buffers[0], &(sg_range){ sg_append_buffer(line_bind.vertex_buffers[0], &(sg_range){
.ptr = line_b, .size = sizeof(struct line_vert)*line_v}); .ptr = line_b, .size = sizeof(struct line_vert)*line_v});
sg_append_buffer(line_bind.index_buffer, &(sg_range){ sg_append_buffer(line_bind.index_buffer, &(sg_range){
@ -179,9 +182,7 @@ static sg_shader_uniform_block_desc time_ubo = {
void debugdraw_init() void debugdraw_init()
{ {
point_shader = sg_compile_shader("shaders/point_v.glsl", "shaders/point_f.glsl", &(sg_shader_desc){ point_shader = sg_make_shader(point_shader_desc(sg_query_backend()));
.vs.uniform_blocks[0] = projection_ubo
});
point_pipe = sg_make_pipeline(&(sg_pipeline_desc){ point_pipe = sg_make_pipeline(&(sg_pipeline_desc){
.shader = point_shader, .shader = point_shader,
@ -201,10 +202,7 @@ void debugdraw_init()
.usage = SG_USAGE_STREAM .usage = SG_USAGE_STREAM
}); });
line_shader = sg_compile_shader("shaders/linevert.glsl", "shaders/linefrag.glsl", &(sg_shader_desc){ line_shader = sg_make_shader(line_shader_desc(sg_query_backend()));
.vs.uniform_blocks[0] = projection_ubo,
.fs.uniform_blocks[0] = time_ubo
});
line_pipe = sg_make_pipeline(&(sg_pipeline_desc){ line_pipe = sg_make_pipeline(&(sg_pipeline_desc){
.shader = line_shader, .shader = line_shader,
@ -233,9 +231,7 @@ void debugdraw_init()
.type = SG_BUFFERTYPE_INDEXBUFFER .type = SG_BUFFERTYPE_INDEXBUFFER
}); });
csg = sg_compile_shader("shaders/circlevert.glsl", "shaders/circlefrag.glsl", &(sg_shader_desc){ csg = sg_make_shader(circle_shader_desc(sg_query_backend()));
.vs.uniform_blocks[0] = projection_ubo,
});
circle_pipe = sg_make_pipeline(&(sg_pipeline_desc){ circle_pipe = sg_make_pipeline(&(sg_pipeline_desc){
.shader = csg, .shader = csg,
@ -274,22 +270,7 @@ void debugdraw_init()
.usage = SG_USAGE_IMMUTABLE, .usage = SG_USAGE_IMMUTABLE,
}); });
grid_shader = sg_compile_shader("shaders/gridvert.glsl", "shaders/gridfrag.glsl", &(sg_shader_desc){ grid_shader = sg_make_shader(grid_shader_desc(sg_query_backend()));
.vs.uniform_blocks[0] = projection_ubo,
.vs.uniform_blocks[1] = {
.size = sizeof(float)*4,
.uniforms = { [0] = { .name = "offset", .type = SG_UNIFORMTYPE_FLOAT2 },
[1] = { .name = "dimen", .type = SG_UNIFORMTYPE_FLOAT2 } } },
.fs.uniform_blocks[0] = {
.size = sizeof(float)*6,
.uniforms = {
[0] = { .name = "thickness", .type = SG_UNIFORMTYPE_FLOAT },
[1] = { .name = "span", .type = SG_UNIFORMTYPE_FLOAT },
[2] = { .name = "color", .type = SG_UNIFORMTYPE_FLOAT4 },
}
},
});
grid_pipe = sg_make_pipeline(&(sg_pipeline_desc){ grid_pipe = sg_make_pipeline(&(sg_pipeline_desc){
.shader = grid_shader, .shader = grid_shader,
@ -306,9 +287,7 @@ void debugdraw_init()
grid_bind.vertex_buffers[0] = circle_bind.vertex_buffers[1]; grid_bind.vertex_buffers[0] = circle_bind.vertex_buffers[1];
poly_shader = sg_compile_shader("shaders/poly_v.glsl", "shaders/poly_f.glsl", &(sg_shader_desc){ poly_shader = sg_make_shader(poly_shader_desc(sg_query_backend()));
.vs.uniform_blocks[0] = projection_ubo
});
poly_pipe = sg_make_pipeline(&(sg_pipeline_desc){ poly_pipe = sg_make_pipeline(&(sg_pipeline_desc){
.shader = poly_shader, .shader = poly_shader,
@ -351,7 +330,8 @@ void draw_line(cpVect *a_points, int a_n, struct rgba color, float seg_len, int
float dist = 0; float dist = 0;
for (int i = 0; i < n-1; i++) { for (int i = 0; i < n-1; i++) {
v[i].pos = points[i]; v[i].pos.x = points[i].x;
v[i].pos.y = points[i].y;
v[i].dist = dist; v[i].dist = dist;
v[i].color = color; v[i].color = color;
v[i].seg_len = seg_len; v[i].seg_len = seg_len;
@ -359,7 +339,8 @@ void draw_line(cpVect *a_points, int a_n, struct rgba color, float seg_len, int
dist += cpvdist(points[i], points[i+1]); dist += cpvdist(points[i], points[i+1]);
} }
v[n-1].pos = points[n-1]; v[n-1].pos.x = points[n-1].x;
v[n-1].pos.y = points[n-1].y;
v[n-1].dist = dist; v[n-1].dist = dist;
v[n-1].color = color; v[n-1].color = color;
v[n-1].seg_len = seg_len; v[n-1].seg_len = seg_len;
@ -458,7 +439,7 @@ void inflatepoints(cpVect *r, cpVect *p, float d, int n)
void draw_edge(cpVect *points, int n, struct rgba color, int thickness, int closed, int flags, struct rgba line_color, float line_seg) void draw_edge(cpVect *points, int n, struct rgba color, int thickness, int closed, int flags, struct rgba line_color, float line_seg)
{ {
static_assert(sizeof(cpVect) == 2*sizeof(float)); // static_assert(sizeof(cpVect) == 2*sizeof(float));
if (thickness == 0) { if (thickness == 0) {
thickness = 1; thickness = 1;
} }
@ -499,7 +480,7 @@ void draw_edge(cpVect *points, int n, struct rgba color, int thickness, int clos
struct poly_vertex vertices[mesh->num_vertices]; struct poly_vertex vertices[mesh->num_vertices];
for (int i = 0; i < mesh->num_vertices; i++) { for (int i = 0; i < mesh->num_vertices; i++) {
vertices[i].pos = (cpVect){ .x = mesh->positions[i].x, .y = mesh->positions[i].y }; vertices[i].pos = (struct draw_p){ .x = mesh->positions[i].x, .y = mesh->positions[i].y };
vertices[i].uv[0] = mesh->annotations[i].u_along_curve; vertices[i].uv[0] = mesh->annotations[i].u_along_curve;
vertices[i].uv[1] = mesh->annotations[i].v_across_curve; vertices[i].uv[1] = mesh->annotations[i].v_across_curve;
vertices[i].color = color; vertices[i].color = color;
@ -518,8 +499,8 @@ void draw_edge(cpVect *points, int n, struct rgba color, int thickness, int clos
draw_line(points,n,line_color,line_seg, 0, 0); draw_line(points,n,line_color,line_seg, 0, 0);
} else { } else {
/* Draw inside and outside lines */ /* Draw inside and outside lines */
cpVect in_p[n]; struct draw_p in_p[n];
cpVect out_p[n]; struct draw_p out_p[n];
for (int i = 0, v = 0; i < n*2+1; i+=2, v++) for (int i = 0, v = 0; i < n*2+1; i+=2, v++)
in_p[v] = vertices[i].pos; in_p[v] = vertices[i].pos;
@ -535,7 +516,8 @@ void draw_edge(cpVect *points, int n, struct rgba color, int thickness, int clos
void draw_circle(cpVect pos, float radius, float pixels, struct rgba color, float seg) void draw_circle(cpVect pos, float radius, float pixels, struct rgba color, float seg)
{ {
struct circle_vertex cv; struct circle_vertex cv;
cv.pos = pos; cv.pos.x = pos.x;
cv.pos.y = pos.y;
cv.radius = radius; cv.radius = radius;
cv.color = color; cv.color = color;
cv.segsize = seg/radius; cv.segsize = seg/radius;
@ -582,23 +564,23 @@ void draw_grid(float width, float span, struct rgba color)
float col[4] = { color.r/255.0 ,color.g/255.0 ,color.b/255.0 ,color.a/255.0 }; float col[4] = { color.r/255.0 ,color.g/255.0 ,color.b/255.0 ,color.a/255.0 };
float fubo[6]; fs_params_t pt;
fubo[0] = (float)width; pt.thickness = (float)width;
fubo[1] = span; pt.span = span;
memcpy(&fubo[2], col, sizeof(float)*4); memcpy(&pt.color, col, sizeof(float)*4);
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(projection)); sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(ubo));
sg_apply_uniforms(SG_SHADERSTAGE_VS, 1, SG_RANGE_REF(ubo)); sg_apply_uniforms(SG_SHADERSTAGE_FS, 0, SG_RANGE_REF(pt));
sg_apply_uniforms(SG_SHADERSTAGE_FS, 0, SG_RANGE_REF(fubo));
sg_draw(0,4,1); sg_draw(0,4,1);
} }
void draw_cppoint(struct cpVect point, float r, struct rgba color) void draw_cppoint(struct cpVect point, float r, struct rgba color)
{ {
struct point_vertex p = { struct point_vertex p = {
.pos = point,
.color = color, .color = color,
.radius = r .radius = r
}; };
p.pos.x = point.x;
p.pos.y = point.y;
memcpy(point_b+point_c, &p, sizeof(struct point_vertex)); memcpy(point_b+point_c, &p, sizeof(struct point_vertex));
point_c++; point_c++;
@ -631,7 +613,7 @@ void draw_poly(cpVect *points, int n, struct rgba color)
struct poly_vertex polyverts[n]; struct poly_vertex polyverts[n];
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
polyverts[i].pos = points[i]; polyverts[i].pos = (struct draw_p) { .x = points[i].x, .y = points[i].y};
polyverts[i].uv[0] = 0.0; polyverts[i].uv[0] = 0.0;
polyverts[i].uv[1] = 0.0; polyverts[i].uv[1] = 0.0;
polyverts[i].color = color; polyverts[i].color = color;

View file

@ -12,6 +12,7 @@
#include "log.h" #include "log.h"
#include "mix.h" #include "mix.h"
#include "music.h" #include "music.h"
#include "2dphysics.h"
#include "sound.h" #include "sound.h"
#include "sprite.h" #include "sprite.h"

View file

@ -13,6 +13,8 @@
#include "2dphysics.h" #include "2dphysics.h"
#include "resources.h" #include "resources.h"
#include "text.sglsl.h"
#include "stb_image_write.h" #include "stb_image_write.h"
#include "stb_rect_pack.h" #include "stb_rect_pack.h"
#include "stb_truetype.h" #include "stb_truetype.h"
@ -21,15 +23,14 @@
struct sFont *font; struct sFont *font;
#define max_chars 40000 #define max_chars 400
static sg_shader fontshader; static sg_shader fontshader;
static sg_bindings bind_text; static sg_bindings bind_text;
static sg_pipeline pipe_text; static sg_pipeline pipe_text;
struct text_vert { struct text_vert {
cpVect pos; struct draw_p pos;
cpVect wh; struct draw_p wh;
struct uv_n uv; struct uv_n uv;
struct uv_n st; struct uv_n st;
struct rgba color; struct rgba color;
@ -38,15 +39,7 @@ struct text_vert {
static struct text_vert text_buffer[max_chars]; static struct text_vert text_buffer[max_chars];
void font_init() { void font_init() {
fontshader = sg_compile_shader("shaders/textvert.glsl", "shaders/textfrag.glsl", &(sg_shader_desc){ fontshader = sg_make_shader(text_shader_desc(sg_query_backend()));
.vs.uniform_blocks[0] = {
.size = sizeof(float) * 16,
// .layout = SG_UNIFORMLAYOUT_STD140,
.uniforms = {
[0] = {.name = "projection", .type = SG_UNIFORMTYPE_MAT4}}},
.fs.images[0] = {.name = "text", .image_type = SG_IMAGETYPE_2D, .sampler_type = SG_SAMPLERTYPE_FLOAT}});
pipe_text = sg_make_pipeline(&(sg_pipeline_desc){ pipe_text = sg_make_pipeline(&(sg_pipeline_desc){
.shader = fontshader, .shader = fontshader,
.layout = { .layout = {
@ -81,10 +74,12 @@ void font_init() {
.size = sizeof(struct text_vert)*max_chars, .size = sizeof(struct text_vert)*max_chars,
.type = SG_BUFFERTYPE_VERTEXBUFFER, .type = SG_BUFFERTYPE_VERTEXBUFFER,
.usage = SG_USAGE_STREAM, .usage = SG_USAGE_STREAM,
.label = "text buffer"}); .label = "text buffer"
});
font = MakeFont("fonts/LessPerfectDOSVGA.ttf", 16); font = MakeFont("fonts/LessPerfectDOSVGA.ttf", 16);
bind_text.fs_images[0] = font->texID; bind_text.fs.images[0] = font->texID;
bind_text.fs.samplers[0] = sg_make_sampler(&(sg_sampler_desc){});
} }
struct sFont *MakeSDFFont(const char *fontfile, int height) struct sFont *MakeSDFFont(const char *fontfile, int height)
@ -155,8 +150,8 @@ struct sFont *MakeFont(const char *fontfile, int height) {
.height = packsize, .height = packsize,
.pixel_format = SG_PIXELFORMAT_R8, .pixel_format = SG_PIXELFORMAT_R8,
.usage = SG_USAGE_IMMUTABLE, .usage = SG_USAGE_IMMUTABLE,
.min_filter = SG_FILTER_NEAREST, // .min_filter = SG_FILTER_NEAREST,
.mag_filter = SG_FILTER_NEAREST, // .mag_filter = SG_FILTER_NEAREST,
.data.subimage[0][0] = { .data.subimage[0][0] = {
.ptr = bitmap, .ptr = bitmap,
.size = packsize * packsize}}); .size = packsize * packsize}});

View file

@ -122,7 +122,7 @@ void input_mouse_move(float x, float y, float dx, float dy)
mouse_delta.x = dx; mouse_delta.x = dx;
mouse_delta.y = -dy; mouse_delta.y = -dy;
JSValue argv[3]; JSValue argv[4];
argv[0] = jsmouse; argv[0] = jsmouse;
argv[1] = jsmove; argv[1] = jsmove;
argv[2] = vec2js(mouse_pos); argv[2] = vec2js(mouse_pos);

View file

@ -21,6 +21,7 @@
#include "sokol/sokol_gfx.h" #include "sokol/sokol_gfx.h"
#define SOKOL_NUKLEAR_IMPL #define SOKOL_NUKLEAR_IMPL
#define SOKOL_METAL
#include "nuklear.h" #include "nuklear.h"
#include "sokol/sokol_app.h" #include "sokol/sokol_app.h"
#include "sokol/sokol_nuklear.h" #include "sokol/sokol_nuklear.h"

View file

@ -16,11 +16,16 @@
#include "resources.h" #include "resources.h"
#include "yugine.h" #include "yugine.h"
#include "crt.sglsl.h"
#include "box.sglsl.h"
#include "shadow.sglsl.h"
#define SOKOL_TRACE_HOOKS
#define SOKOL_GFX_IMPL #define SOKOL_GFX_IMPL
#include "sokol/sokol_gfx.h" #include "sokol/sokol_gfx.h"
#define SOKOL_GFX_EXT_IMPL //#define SOKOL_GFX_EXT_IMPL
#include "sokol/sokol_gfx_ext.h" //#include "sokol/sokol_gfx_ext.h"
#define MSF_GIF_IMPL #define MSF_GIF_IMPL
#include "msf_gif.h" #include "msf_gif.h"
@ -35,7 +40,6 @@ static struct {
sg_image depth; sg_image depth;
} sg_gif; } sg_gif;
static struct { static struct {
int w; int w;
int h; int h;
@ -228,24 +232,11 @@ void render_init() {
sg_color c; sg_color c;
rgba2floats(&c, editorClearColor); rgba2floats(&c, editorClearColor);
pass_action = (sg_pass_action){ pass_action = (sg_pass_action){
.colors[0] = {.action = SG_ACTION_CLEAR, .value = c} .colors[0] = {.load_action = SG_LOADACTION_CLEAR, .clear_value = c}
}; };
crt_post.shader = sg_compile_shader("shaders/postvert.glsl", "shaders/crtfrag.glsl", &(sg_shader_desc){ crt_post.shader = sg_make_shader(crt_shader_desc(sg_query_backend()));
.fs.images[0] = { sg_gif.shader = sg_make_shader(box_shader_desc(sg_query_backend()));
.name = "diffuse_texture",
.image_type = SG_IMAGETYPE_2D,
.sampler_type = SG_SAMPLERTYPE_FLOAT
}
});
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){ sg_gif.pipe = sg_make_pipeline(&(sg_pipeline_desc){
.shader = sg_gif.shader, .shader = sg_gif.shader,
@ -285,11 +276,6 @@ void render_init() {
.depth_stencil_attachment.image = crt_post.depth_img, .depth_stencil_attachment.image = crt_post.depth_img,
}); });
sg_gif.pass = sg_make_pass(&(sg_pass_desc){
.color_attachments[0].image = sg_gif.img,
.depth_stencil_attachment.image = sg_gif.depth
});
float crt_quad[] = { float crt_quad[] = {
-1, 1, 0, 1, -1, 1, 0, 1,
-1, -1, 0, 0, -1, -1, 0, 0,
@ -304,7 +290,8 @@ void render_init() {
.data = crt_quad .data = crt_quad
}); });
crt_post.bind.fs_images[0] = crt_post.img; crt_post.bind.fs.images[0] = crt_post.img;
crt_post.bind.fs.samplers[0] = sg_make_sampler(&(sg_sampler_desc){});
/* /*
sg_image_desc shadow_desc = { sg_image_desc shadow_desc = {
.render_target = true, .render_target = true,
@ -324,15 +311,7 @@ void render_init() {
sg_shadow.pass_action = (sg_pass_action) { sg_shadow.pass_action = (sg_pass_action) {
.colors[0] = { .action=SG_ACTION_CLEAR, .value = {1,1,1,1} } }; .colors[0] = { .action=SG_ACTION_CLEAR, .value = {1,1,1,1} } };
sg_shadow.shader = sg_compile_shader("shaders/shadowvert.glsl", "shaders/shadowfrag.glsl", &(sg_shader_desc){ sg_shadow.shader = sg_make_shader(shadow_shader_desc(sg_query_backend()));
.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){ sg_shadow.pipe = sg_make_pipeline(&(sg_pipeline_desc){
.shader = sg_shadow.shader, .shader = sg_shadow.shader,
@ -379,7 +358,7 @@ void render_winsize()
.depth_stencil_attachment.image = crt_post.depth_img, .depth_stencil_attachment.image = crt_post.depth_img,
}); });
crt_post.bind.fs_images[0] = crt_post.img; crt_post.bind.fs.images[0] = crt_post.img;
} }
static cpBody *camera = NULL; static cpBody *camera = NULL;
@ -414,6 +393,7 @@ void full_2d_pass(struct window *window)
hudproj = HMM_Orthographic_RH_NO(0, window->width, 0, window->height, -1.f, 1.f); hudproj = HMM_Orthographic_RH_NO(0, window->width, 0, window->height, -1.f, 1.f);
sprite_draw_all(); sprite_draw_all();
call_draw(); call_draw();
@ -422,7 +402,6 @@ void full_2d_pass(struct window *window)
gameobject_draw_debugs(); gameobject_draw_debugs();
call_debugs(); call_debugs();
} }
debug_flush(&projection); debug_flush(&projection);
text_flush(&projection); text_flush(&projection);
@ -479,7 +458,7 @@ void openglRender(struct window *window) {
sg_end_pass(); sg_end_pass();
gif.timer = appTime; gif.timer = appTime;
sg_query_image_pixels(sg_gif.img, gif.buffer, gif.w*gif.h*4); // 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); msf_gif_frame(&gif_state, gif.buffer, gif.cpf, gif.depth, gif.w * -4);
} }

View file

@ -8,6 +8,8 @@
#elif __WIN32 #elif __WIN32
#define SOKOL_GLCORE33 #define SOKOL_GLCORE33
#define SOKOL_WIN32_FORCE_MAIN #define SOKOL_WIN32_FORCE_MAIN
#elif __APPLE__
#define SOKOL_GLCORE33
#endif #endif
#include "sokol/sokol_gfx.h" #include "sokol/sokol_gfx.h"
@ -30,6 +32,11 @@ extern HMM_Vec3 dirl_pos;
extern HMM_Mat4 projection; extern HMM_Mat4 projection;
extern HMM_Mat4 hudproj; extern HMM_Mat4 hudproj;
struct draw_p {
float x;
float y;
};
extern float gridScale; extern float gridScale;
extern float smallGridUnit; extern float smallGridUnit;
extern float bigGridUnit; extern float bigGridUnit;

View file

@ -13,6 +13,9 @@
#include <ctype.h> #include <ctype.h>
#include <limits.h> #include <limits.h>
#include "sprite.sglsl.h"
#include "9slice.sglsl.h"
struct TextureOptions TEX_SPRITE = {1, 0, 0}; struct TextureOptions TEX_SPRITE = {1, 0, 0};
static struct sprite *sprites; static struct sprite *sprites;
@ -140,20 +143,7 @@ void sprite_settex(struct sprite *sprite, struct Texture *tex) {
} }
void sprite_initialize() { void sprite_initialize() {
shader_sprite = sg_compile_shader("shaders/spritevert.glsl", "shaders/spritefrag.glsl", &(sg_shader_desc){ shader_sprite = sg_make_shader(sprite_shader_desc(sg_query_backend()));
.vs.uniform_blocks[0] = {
.size = 64,
.layout = SG_UNIFORMLAYOUT_STD140,
.uniforms = {
[0] = {.name = "proj", .type = SG_UNIFORMTYPE_MAT4},
}},
.fs.images[0] = {
.name = "image",
.image_type = SG_IMAGETYPE_2D,
.sampler_type = SG_SAMPLERTYPE_FLOAT,
},
});
pip_sprite = sg_make_pipeline(&(sg_pipeline_desc){ pip_sprite = sg_make_pipeline(&(sg_pipeline_desc){
.shader = shader_sprite, .shader = shader_sprite,
@ -177,20 +167,9 @@ void sprite_initialize() {
.usage = SG_USAGE_STREAM, .usage = SG_USAGE_STREAM,
.label = "sprite vertex buffer", .label = "sprite vertex buffer",
}); });
bind_sprite.fs.samplers[0] = sg_make_sampler(&(sg_sampler_desc){});
slice9_shader = sg_compile_shader("shaders/slice9_v.glsl", "shaders/slice9_f.glsl", &(sg_shader_desc) { slice9_shader = sg_make_shader(slice9_shader_desc(sg_query_backend()));
.vs.uniform_blocks[0] = {
.size = 64,
.layout = SG_UNIFORMLAYOUT_STD140,
.uniforms = { [0] = {.name = "projection", .type = SG_UNIFORMTYPE_MAT4},
}},
.fs.images[0] = {
.name = "image",
.image_type = SG_IMAGETYPE_2D,
.sampler_type = SG_SAMPLERTYPE_FLOAT
},
});
slice9_pipe = sg_make_pipeline(&(sg_pipeline_desc){ slice9_pipe = sg_make_pipeline(&(sg_pipeline_desc){
.shader = slice9_shader, .shader = slice9_shader,
@ -209,8 +188,6 @@ void sprite_initialize() {
.type = SG_BUFFERTYPE_VERTEXBUFFER, .type = SG_BUFFERTYPE_VERTEXBUFFER,
.usage = SG_USAGE_STREAM, .usage = SG_USAGE_STREAM,
}); });
} }
/* offset given in texture offset, so -0.5,-0.5 results in it being centered */ /* offset given in texture offset, so -0.5,-0.5 results in it being centered */
@ -258,7 +235,8 @@ void tex_draw(struct Texture *tex, HMM_Vec2 pos, float angle, HMM_Vec2 size, HMM
verts[i].uv = HMM_AddV2(verts[i].uv, wrapoffset); verts[i].uv = HMM_AddV2(verts[i].uv, wrapoffset);
} }
bind_sprite.fs_images[0] = tex->id; bind_sprite.fs.images[0] = tex->id;
sg_append_buffer(bind_sprite.vertex_buffers[0], SG_RANGE_REF(verts)); sg_append_buffer(bind_sprite.vertex_buffers[0], SG_RANGE_REF(verts));
sg_apply_bindings(&bind_sprite); sg_apply_bindings(&bind_sprite);
@ -323,7 +301,7 @@ void slice9_draw(const char *img, HMM_Vec2 pos, HMM_Vec2 dimensions, struct rgba
verts[3].uv.u = r.s1 * USHRT_MAX; verts[3].uv.u = r.s1 * USHRT_MAX;
verts[3].uv.v = r.t0 * USHRT_MAX; verts[3].uv.v = r.t0 * USHRT_MAX;
bind_sprite.fs_images[0] = tex->id; bind_sprite.fs.images[0] = tex->id;
sg_append_buffer(bind_sprite.vertex_buffers[0], SG_RANGE_REF(verts)); sg_append_buffer(bind_sprite.vertex_buffers[0], SG_RANGE_REF(verts));
sg_apply_bindings(&bind_sprite); sg_apply_bindings(&bind_sprite);

View file

@ -149,11 +149,7 @@ struct Texture *texture_pullfromfile(const char *path) {
.width = tex->width, .width = tex->width,
.height = tex->height, .height = tex->height,
.usage = SG_USAGE_IMMUTABLE, .usage = SG_USAGE_IMMUTABLE,
.min_filter = SG_FILTER_NEAREST_MIPMAP_NEAREST,
.mag_filter = SG_FILTER_NEAREST,
.num_mipmaps = mips, .num_mipmaps = mips,
.wrap_u = SG_WRAP_REPEAT,
.wrap_v = SG_WRAP_REPEAT,
.data = sg_img_data .data = sg_img_data
}); });

View file

@ -3464,7 +3464,7 @@ int main(int argc, char* argv[]) {
#endif /* SOKOL_NO_ENTRY */ #endif /* SOKOL_NO_ENTRY */
_SOKOL_PRIVATE uint32_t _sapp_macos_mods(NSEvent* ev) { _SOKOL_PRIVATE uint32_t _sapp_macos_mods(NSEvent* ev) {
const NSEventModifierFlags f = ev.modifierFlags; const NSEventModifierFlags f = (ev == nil) ? NSEvent.modifierFlags : ev.modifierFlags;
const NSUInteger b = NSEvent.pressedMouseButtons; const NSUInteger b = NSEvent.pressedMouseButtons;
uint32_t m = 0; uint32_t m = 0;
if (f & NSEventModifierFlagShift) { if (f & NSEventModifierFlagShift) {
@ -3610,12 +3610,15 @@ _SOKOL_PRIVATE void _sapp_macos_update_window_title(void) {
[_sapp.macos.window setTitle: [NSString stringWithUTF8String:_sapp.window_title]]; [_sapp.macos.window setTitle: [NSString stringWithUTF8String:_sapp.window_title]];
} }
_SOKOL_PRIVATE void _sapp_macos_mouse_update(NSEvent* event) { _SOKOL_PRIVATE void _sapp_macos_mouse_update_from_nspoint(NSPoint mouse_pos, bool clear_dxdy) {
if (!_sapp.mouse.locked) { if (!_sapp.mouse.locked) {
const NSPoint mouse_pos = event.locationInWindow;
float new_x = mouse_pos.x * _sapp.dpi_scale; float new_x = mouse_pos.x * _sapp.dpi_scale;
float new_y = _sapp.framebuffer_height - (mouse_pos.y * _sapp.dpi_scale) - 1; float new_y = _sapp.framebuffer_height - (mouse_pos.y * _sapp.dpi_scale) - 1;
if (_sapp.mouse.pos_valid) { if (clear_dxdy) {
_sapp.mouse.dx = 0.0f;
_sapp.mouse.dy = 0.0f;
}
else if (_sapp.mouse.pos_valid) {
// don't update dx/dy in the very first update // don't update dx/dy in the very first update
_sapp.mouse.dx = new_x - _sapp.mouse.x; _sapp.mouse.dx = new_x - _sapp.mouse.x;
_sapp.mouse.dy = new_y - _sapp.mouse.y; _sapp.mouse.dy = new_y - _sapp.mouse.y;
@ -3626,6 +3629,10 @@ _SOKOL_PRIVATE void _sapp_macos_mouse_update(NSEvent* event) {
} }
} }
_SOKOL_PRIVATE void _sapp_macos_mouse_update_from_nsevent(NSEvent* event, bool clear_dxdy) {
_sapp_macos_mouse_update_from_nspoint(event.locationInWindow, clear_dxdy);
}
_SOKOL_PRIVATE void _sapp_macos_show_mouse(bool visible) { _SOKOL_PRIVATE void _sapp_macos_show_mouse(bool visible) {
/* NOTE: this function is only called when the mouse visibility actually changes */ /* NOTE: this function is only called when the mouse visibility actually changes */
if (visible) { if (visible) {
@ -3956,7 +3963,9 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) {
} }
if (!drop_failed) { if (!drop_failed) {
if (_sapp_events_enabled()) { if (_sapp_events_enabled()) {
_sapp_macos_mouse_update_from_nspoint(sender.draggingLocation, true);
_sapp_init_event(SAPP_EVENTTYPE_FILES_DROPPED); _sapp_init_event(SAPP_EVENTTYPE_FILES_DROPPED);
_sapp.event.modifiers = _sapp_macos_mods(nil);
_sapp_call_event(&_sapp.event); _sapp_call_event(&_sapp.event);
} }
} }
@ -3973,19 +3982,6 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) {
@implementation _sapp_macos_view @implementation _sapp_macos_view
#if defined(SOKOL_GLCORE33) #if defined(SOKOL_GLCORE33)
/* NOTE: this is a hack/fix when the initial window size has been clipped by
macOS because it didn't fit on the screen, in that case the
frame size of the window is reported wrong if low-dpi rendering
was requested (instead the high-dpi dimensions are returned)
until the window is resized for the first time.
Hooking into reshape and getting the frame dimensions seems to report
the correct dimensions.
*/
- (void)reshape {
_sapp_macos_update_dimensions();
[super reshape];
}
- (void)timerFired:(id)sender { - (void)timerFired:(id)sender {
_SOKOL_UNUSED(sender); _SOKOL_UNUSED(sender);
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
@ -4079,8 +4075,17 @@ _SOKOL_PRIVATE void _sapp_macos_poll_input_events() {
[self addTrackingArea:_sapp.macos.tracking_area]; [self addTrackingArea:_sapp.macos.tracking_area];
[super updateTrackingAreas]; [super updateTrackingAreas];
} }
// helper function to make GL context active
static void _sapp_gl_make_current(void) {
#if defined(SOKOL_GLCORE33)
[[_sapp.macos.view openGLContext] makeCurrentContext];
#endif
}
- (void)mouseEntered:(NSEvent*)event { - (void)mouseEntered:(NSEvent*)event {
_sapp_macos_mouse_update(event); _sapp_gl_make_current();
_sapp_macos_mouse_update_from_nsevent(event, true);
/* don't send mouse enter/leave while dragging (so that it behaves the same as /* don't send mouse enter/leave while dragging (so that it behaves the same as
on Windows while SetCapture is active on Windows while SetCapture is active
*/ */
@ -4089,47 +4094,55 @@ _SOKOL_PRIVATE void _sapp_macos_poll_input_events() {
} }
} }
- (void)mouseExited:(NSEvent*)event { - (void)mouseExited:(NSEvent*)event {
_sapp_macos_mouse_update(event); _sapp_gl_make_current();
_sapp_macos_mouse_update_from_nsevent(event, true);
if (0 == _sapp.macos.mouse_buttons) { if (0 == _sapp.macos.mouse_buttons) {
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_LEAVE, SAPP_MOUSEBUTTON_INVALID, _sapp_macos_mods(event)); _sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_LEAVE, SAPP_MOUSEBUTTON_INVALID, _sapp_macos_mods(event));
} }
} }
- (void)mouseDown:(NSEvent*)event { - (void)mouseDown:(NSEvent*)event {
_sapp_macos_mouse_update(event); _sapp_gl_make_current();
_sapp_macos_mouse_update_from_nsevent(event, false);
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_DOWN, SAPP_MOUSEBUTTON_LEFT, _sapp_macos_mods(event)); _sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_DOWN, SAPP_MOUSEBUTTON_LEFT, _sapp_macos_mods(event));
_sapp.macos.mouse_buttons |= (1<<SAPP_MOUSEBUTTON_LEFT); _sapp.macos.mouse_buttons |= (1<<SAPP_MOUSEBUTTON_LEFT);
} }
- (void)mouseUp:(NSEvent*)event { - (void)mouseUp:(NSEvent*)event {
_sapp_macos_mouse_update(event); _sapp_gl_make_current();
_sapp_macos_mouse_update_from_nsevent(event, false);
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_UP, SAPP_MOUSEBUTTON_LEFT, _sapp_macos_mods(event)); _sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_UP, SAPP_MOUSEBUTTON_LEFT, _sapp_macos_mods(event));
_sapp.macos.mouse_buttons &= ~(1<<SAPP_MOUSEBUTTON_LEFT); _sapp.macos.mouse_buttons &= ~(1<<SAPP_MOUSEBUTTON_LEFT);
} }
- (void)rightMouseDown:(NSEvent*)event { - (void)rightMouseDown:(NSEvent*)event {
_sapp_macos_mouse_update(event); _sapp_gl_make_current();
_sapp_macos_mouse_update_from_nsevent(event, false);
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_DOWN, SAPP_MOUSEBUTTON_RIGHT, _sapp_macos_mods(event)); _sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_DOWN, SAPP_MOUSEBUTTON_RIGHT, _sapp_macos_mods(event));
_sapp.macos.mouse_buttons |= (1<<SAPP_MOUSEBUTTON_RIGHT); _sapp.macos.mouse_buttons |= (1<<SAPP_MOUSEBUTTON_RIGHT);
} }
- (void)rightMouseUp:(NSEvent*)event { - (void)rightMouseUp:(NSEvent*)event {
_sapp_macos_mouse_update(event); _sapp_gl_make_current();
_sapp_macos_mouse_update_from_nsevent(event, false);
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_UP, SAPP_MOUSEBUTTON_RIGHT, _sapp_macos_mods(event)); _sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_UP, SAPP_MOUSEBUTTON_RIGHT, _sapp_macos_mods(event));
_sapp.macos.mouse_buttons &= ~(1<<SAPP_MOUSEBUTTON_RIGHT); _sapp.macos.mouse_buttons &= ~(1<<SAPP_MOUSEBUTTON_RIGHT);
} }
- (void)otherMouseDown:(NSEvent*)event { - (void)otherMouseDown:(NSEvent*)event {
_sapp_macos_mouse_update(event); _sapp_gl_make_current();
_sapp_macos_mouse_update_from_nsevent(event, false);
if (2 == event.buttonNumber) { if (2 == event.buttonNumber) {
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_DOWN, SAPP_MOUSEBUTTON_MIDDLE, _sapp_macos_mods(event)); _sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_DOWN, SAPP_MOUSEBUTTON_MIDDLE, _sapp_macos_mods(event));
_sapp.macos.mouse_buttons |= (1<<SAPP_MOUSEBUTTON_MIDDLE); _sapp.macos.mouse_buttons |= (1<<SAPP_MOUSEBUTTON_MIDDLE);
} }
} }
- (void)otherMouseUp:(NSEvent*)event { - (void)otherMouseUp:(NSEvent*)event {
_sapp_macos_mouse_update(event); _sapp_gl_make_current();
_sapp_macos_mouse_update_from_nsevent(event, false);
if (2 == event.buttonNumber) { if (2 == event.buttonNumber) {
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_UP, SAPP_MOUSEBUTTON_MIDDLE, _sapp_macos_mods(event)); _sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_UP, SAPP_MOUSEBUTTON_MIDDLE, _sapp_macos_mods(event));
_sapp.macos.mouse_buttons &= (1<<SAPP_MOUSEBUTTON_MIDDLE); _sapp.macos.mouse_buttons &= (1<<SAPP_MOUSEBUTTON_MIDDLE);
} }
} }
- (void)otherMouseDragged:(NSEvent*)event { - (void)otherMouseDragged:(NSEvent*)event {
_sapp_macos_mouse_update(event); _sapp_gl_make_current();
_sapp_macos_mouse_update_from_nsevent(event, false);
if (2 == event.buttonNumber) { if (2 == event.buttonNumber) {
if (_sapp.mouse.locked) { if (_sapp.mouse.locked) {
_sapp.mouse.dx = [event deltaX]; _sapp.mouse.dx = [event deltaX];
@ -4139,7 +4152,8 @@ _SOKOL_PRIVATE void _sapp_macos_poll_input_events() {
} }
} }
- (void)mouseMoved:(NSEvent*)event { - (void)mouseMoved:(NSEvent*)event {
_sapp_macos_mouse_update(event); _sapp_gl_make_current();
_sapp_macos_mouse_update_from_nsevent(event, false);
if (_sapp.mouse.locked) { if (_sapp.mouse.locked) {
_sapp.mouse.dx = [event deltaX]; _sapp.mouse.dx = [event deltaX];
_sapp.mouse.dy = [event deltaY]; _sapp.mouse.dy = [event deltaY];
@ -4147,7 +4161,8 @@ _SOKOL_PRIVATE void _sapp_macos_poll_input_events() {
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID , _sapp_macos_mods(event)); _sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID , _sapp_macos_mods(event));
} }
- (void)mouseDragged:(NSEvent*)event { - (void)mouseDragged:(NSEvent*)event {
_sapp_macos_mouse_update(event); _sapp_gl_make_current();
_sapp_macos_mouse_update_from_nsevent(event, false);
if (_sapp.mouse.locked) { if (_sapp.mouse.locked) {
_sapp.mouse.dx = [event deltaX]; _sapp.mouse.dx = [event deltaX];
_sapp.mouse.dy = [event deltaY]; _sapp.mouse.dy = [event deltaY];
@ -4155,7 +4170,8 @@ _SOKOL_PRIVATE void _sapp_macos_poll_input_events() {
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID , _sapp_macos_mods(event)); _sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID , _sapp_macos_mods(event));
} }
- (void)rightMouseDragged:(NSEvent*)event { - (void)rightMouseDragged:(NSEvent*)event {
_sapp_macos_mouse_update(event); _sapp_gl_make_current();
_sapp_macos_mouse_update_from_nsevent(event, false);
if (_sapp.mouse.locked) { if (_sapp.mouse.locked) {
_sapp.mouse.dx = [event deltaX]; _sapp.mouse.dx = [event deltaX];
_sapp.mouse.dy = [event deltaY]; _sapp.mouse.dy = [event deltaY];
@ -4163,7 +4179,8 @@ _SOKOL_PRIVATE void _sapp_macos_poll_input_events() {
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID, _sapp_macos_mods(event)); _sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID, _sapp_macos_mods(event));
} }
- (void)scrollWheel:(NSEvent*)event { - (void)scrollWheel:(NSEvent*)event {
_sapp_macos_mouse_update(event); _sapp_gl_make_current();
_sapp_macos_mouse_update_from_nsevent(event, true);
if (_sapp_events_enabled()) { if (_sapp_events_enabled()) {
float dx = (float) event.scrollingDeltaX; float dx = (float) event.scrollingDeltaX;
float dy = (float) event.scrollingDeltaY; float dy = (float) event.scrollingDeltaY;
@ -4182,6 +4199,7 @@ _SOKOL_PRIVATE void _sapp_macos_poll_input_events() {
} }
- (void)keyDown:(NSEvent*)event { - (void)keyDown:(NSEvent*)event {
if (_sapp_events_enabled()) { if (_sapp_events_enabled()) {
_sapp_gl_make_current();
const uint32_t mods = _sapp_macos_mods(event); const uint32_t mods = _sapp_macos_mods(event);
const sapp_keycode key_code = _sapp_translate_key(event.keyCode); const sapp_keycode key_code = _sapp_translate_key(event.keyCode);
_sapp_macos_key_event(SAPP_EVENTTYPE_KEY_DOWN, key_code, event.isARepeat, mods); _sapp_macos_key_event(SAPP_EVENTTYPE_KEY_DOWN, key_code, event.isARepeat, mods);
@ -4208,6 +4226,7 @@ _SOKOL_PRIVATE void _sapp_macos_poll_input_events() {
} }
} }
- (void)keyUp:(NSEvent*)event { - (void)keyUp:(NSEvent*)event {
_sapp_gl_make_current();
_sapp_macos_key_event(SAPP_EVENTTYPE_KEY_UP, _sapp_macos_key_event(SAPP_EVENTTYPE_KEY_UP,
_sapp_translate_key(event.keyCode), _sapp_translate_key(event.keyCode),
event.isARepeat, event.isARepeat,
@ -4648,7 +4667,7 @@ EMSCRIPTEN_KEEPALIVE void _sapp_emsc_drop(int i, const char* name) {
} }
} }
EMSCRIPTEN_KEEPALIVE void _sapp_emsc_end_drop(int x, int y) { EMSCRIPTEN_KEEPALIVE void _sapp_emsc_end_drop(int x, int y, int mods) {
if (!_sapp.drop.enabled) { if (!_sapp.drop.enabled) {
return; return;
} }
@ -4664,6 +4683,11 @@ EMSCRIPTEN_KEEPALIVE void _sapp_emsc_end_drop(int x, int y) {
_sapp.mouse.dx = 0.0f; _sapp.mouse.dx = 0.0f;
_sapp.mouse.dy = 0.0f; _sapp.mouse.dy = 0.0f;
_sapp_init_event(SAPP_EVENTTYPE_FILES_DROPPED); _sapp_init_event(SAPP_EVENTTYPE_FILES_DROPPED);
// see sapp_js_add_dragndrop_listeners for mods constants
if (mods & 1) { _sapp.event.modifiers |= SAPP_MODIFIER_SHIFT; }
if (mods & 2) { _sapp.event.modifiers |= SAPP_MODIFIER_CTRL; }
if (mods & 4) { _sapp.event.modifiers |= SAPP_MODIFIER_ALT; }
if (mods & 8) { _sapp.event.modifiers |= SAPP_MODIFIER_SUPER; }
_sapp_call_event(&_sapp.event); _sapp_call_event(&_sapp.event);
} }
} }
@ -4786,8 +4810,13 @@ EM_JS(void, sapp_js_add_dragndrop_listeners, (const char* canvas_name_cstr), {
__sapp_emsc_drop(i, cstr); __sapp_emsc_drop(i, cstr);
}); });
} }
let mods = 0;
if (event.shiftKey) { mods |= 1; }
if (event.ctrlKey) { mods |= 2; }
if (event.altKey) { mods |= 4; }
if (event.metaKey) { mods |= 8; }
// FIXME? see computation of targetX/targetY in emscripten via getClientBoundingRect // FIXME? see computation of targetX/targetY in emscripten via getClientBoundingRect
__sapp_emsc_end_drop(event.clientX, event.clientY); __sapp_emsc_end_drop(event.clientX, event.clientY, mods);
}; };
canvas.addEventListener('dragenter', Module.sokol_dragenter, false); canvas.addEventListener('dragenter', Module.sokol_dragenter, false);
canvas.addEventListener('dragleave', Module.sokol_dragleave, false); canvas.addEventListener('dragleave', Module.sokol_dragleave, false);
@ -5107,8 +5136,7 @@ _SOKOL_PRIVATE EM_BOOL _sapp_emsc_mouse_cb(int emsc_type, const EmscriptenMouseE
if (_sapp.mouse.locked) { if (_sapp.mouse.locked) {
_sapp.mouse.dx = (float) emsc_event->movementX; _sapp.mouse.dx = (float) emsc_event->movementX;
_sapp.mouse.dy = (float) emsc_event->movementY; _sapp.mouse.dy = (float) emsc_event->movementY;
} } else {
else {
float new_x = emsc_event->targetX * _sapp.dpi_scale; float new_x = emsc_event->targetX * _sapp.dpi_scale;
float new_y = emsc_event->targetY * _sapp.dpi_scale; float new_y = emsc_event->targetY * _sapp.dpi_scale;
if (_sapp.mouse.pos_valid) { if (_sapp.mouse.pos_valid) {
@ -5122,6 +5150,7 @@ _SOKOL_PRIVATE EM_BOOL _sapp_emsc_mouse_cb(int emsc_type, const EmscriptenMouseE
if (_sapp_events_enabled() && (emsc_event->button >= 0) && (emsc_event->button < SAPP_MAX_MOUSEBUTTONS)) { if (_sapp_events_enabled() && (emsc_event->button >= 0) && (emsc_event->button < SAPP_MAX_MOUSEBUTTONS)) {
sapp_event_type type; sapp_event_type type;
bool is_button_event = false; bool is_button_event = false;
bool clear_dxdy = false;
switch (emsc_type) { switch (emsc_type) {
case EMSCRIPTEN_EVENT_MOUSEDOWN: case EMSCRIPTEN_EVENT_MOUSEDOWN:
type = SAPP_EVENTTYPE_MOUSE_DOWN; type = SAPP_EVENTTYPE_MOUSE_DOWN;
@ -5136,14 +5165,20 @@ _SOKOL_PRIVATE EM_BOOL _sapp_emsc_mouse_cb(int emsc_type, const EmscriptenMouseE
break; break;
case EMSCRIPTEN_EVENT_MOUSEENTER: case EMSCRIPTEN_EVENT_MOUSEENTER:
type = SAPP_EVENTTYPE_MOUSE_ENTER; type = SAPP_EVENTTYPE_MOUSE_ENTER;
clear_dxdy = true;
break; break;
case EMSCRIPTEN_EVENT_MOUSELEAVE: case EMSCRIPTEN_EVENT_MOUSELEAVE:
type = SAPP_EVENTTYPE_MOUSE_LEAVE; type = SAPP_EVENTTYPE_MOUSE_LEAVE;
clear_dxdy = true;
break; break;
default: default:
type = SAPP_EVENTTYPE_INVALID; type = SAPP_EVENTTYPE_INVALID;
break; break;
} }
if (clear_dxdy) {
_sapp.mouse.dx = 0.0f;
_sapp.mouse.dy = 0.0f;
}
if (type != SAPP_EVENTTYPE_INVALID) { if (type != SAPP_EVENTTYPE_INVALID) {
_sapp_init_event(type); _sapp_init_event(type);
_sapp.event.modifiers = _sapp_emsc_mouse_event_mods(emsc_event); _sapp.event.modifiers = _sapp_emsc_mouse_event_mods(emsc_event);
@ -5154,13 +5189,12 @@ _SOKOL_PRIVATE EM_BOOL _sapp_emsc_mouse_cb(int emsc_type, const EmscriptenMouseE
case 2: _sapp.event.mouse_button = SAPP_MOUSEBUTTON_RIGHT; break; case 2: _sapp.event.mouse_button = SAPP_MOUSEBUTTON_RIGHT; break;
default: _sapp.event.mouse_button = (sapp_mousebutton)emsc_event->button; break; default: _sapp.event.mouse_button = (sapp_mousebutton)emsc_event->button; break;
} }
} } else {
else {
_sapp.event.mouse_button = SAPP_MOUSEBUTTON_INVALID; _sapp.event.mouse_button = SAPP_MOUSEBUTTON_INVALID;
} }
_sapp_call_event(&_sapp.event); _sapp_call_event(&_sapp.event);
} }
/* mouse lock can only be activated in mouse button events (not in move, enter or leave) */ // mouse lock can only be activated in mouse button events (not in move, enter or leave)
if (is_button_event) { if (is_button_event) {
_sapp_emsc_update_mouse_lock_state(); _sapp_emsc_update_mouse_lock_state();
} }
@ -7031,6 +7065,7 @@ _SOKOL_PRIVATE void _sapp_win32_files_dropped(HDROP hdrop) {
if (!drop_failed) { if (!drop_failed) {
if (_sapp_events_enabled()) { if (_sapp_events_enabled()) {
_sapp_init_event(SAPP_EVENTTYPE_FILES_DROPPED); _sapp_init_event(SAPP_EVENTTYPE_FILES_DROPPED);
_sapp.event.modifiers = _sapp_win32_mods();
_sapp_call_event(&_sapp.event); _sapp_call_event(&_sapp.event);
} }
} }
@ -7183,6 +7218,8 @@ _SOKOL_PRIVATE LRESULT CALLBACK _sapp_win32_wndproc(HWND hWnd, UINT uMsg, WPARAM
tme.dwFlags = TME_LEAVE; tme.dwFlags = TME_LEAVE;
tme.hwndTrack = _sapp.win32.hwnd; tme.hwndTrack = _sapp.win32.hwnd;
TrackMouseEvent(&tme); TrackMouseEvent(&tme);
_sapp.mouse.dx = 0.0f;
_sapp.mouse.dy = 0.0f;
_sapp_win32_mouse_event(SAPP_EVENTTYPE_MOUSE_ENTER, SAPP_MOUSEBUTTON_INVALID); _sapp_win32_mouse_event(SAPP_EVENTTYPE_MOUSE_ENTER, SAPP_MOUSEBUTTON_INVALID);
} }
_sapp_win32_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID); _sapp_win32_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID);
@ -7227,16 +7264,16 @@ _SOKOL_PRIVATE LRESULT CALLBACK _sapp_win32_wndproc(HWND hWnd, UINT uMsg, WPARAM
case WM_MOUSELEAVE: case WM_MOUSELEAVE:
if (!_sapp.mouse.locked) { if (!_sapp.mouse.locked) {
_sapp.mouse.dx = 0.0f;
_sapp.mouse.dy = 0.0f;
_sapp.win32.mouse_tracked = false; _sapp.win32.mouse_tracked = false;
_sapp_win32_mouse_event(SAPP_EVENTTYPE_MOUSE_LEAVE, SAPP_MOUSEBUTTON_INVALID); _sapp_win32_mouse_event(SAPP_EVENTTYPE_MOUSE_LEAVE, SAPP_MOUSEBUTTON_INVALID);
} }
break; break;
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
_sapp_win32_mouse_update(lParam);
_sapp_win32_scroll_event(0.0f, (float)((SHORT)HIWORD(wParam))); _sapp_win32_scroll_event(0.0f, (float)((SHORT)HIWORD(wParam)));
break; break;
case WM_MOUSEHWHEEL: case WM_MOUSEHWHEEL:
_sapp_win32_mouse_update(lParam);
_sapp_win32_scroll_event((float)((SHORT)HIWORD(wParam)), 0.0f); _sapp_win32_scroll_event((float)((SHORT)HIWORD(wParam)), 0.0f);
break; break;
case WM_CHAR: case WM_CHAR:
@ -10086,11 +10123,14 @@ _SOKOL_PRIVATE sapp_mousebutton _sapp_x11_translate_button(const XEvent* event)
} }
} }
_SOKOL_PRIVATE void _sapp_x11_mouse_update(int x, int y) { _SOKOL_PRIVATE void _sapp_x11_mouse_update(int x, int y, bool clear_dxdy) {
if (!_sapp.mouse.locked) { if (!_sapp.mouse.locked) {
const float new_x = (float) x; const float new_x = (float) x;
const float new_y = (float) y; const float new_y = (float) y;
if (_sapp.mouse.pos_valid) { if (clear_dxdy) {
_sapp.mouse.dx = 0.0f;
_sapp.mouse.dy = 0.0f;
} else if (_sapp.mouse.pos_valid) {
_sapp.mouse.dx = new_x - _sapp.mouse.x; _sapp.mouse.dx = new_x - _sapp.mouse.x;
_sapp.mouse.dy = new_y - _sapp.mouse.y; _sapp.mouse.dy = new_y - _sapp.mouse.y;
} }
@ -10479,7 +10519,7 @@ _SOKOL_PRIVATE void _sapp_x11_process_event(XEvent* event) {
break; break;
case ButtonPress: case ButtonPress:
{ {
_sapp_x11_mouse_update(event->xbutton.x, event->xbutton.y); _sapp_x11_mouse_update(event->xbutton.x, event->xbutton.y, false);
const sapp_mousebutton btn = _sapp_x11_translate_button(event); const sapp_mousebutton btn = _sapp_x11_translate_button(event);
uint32_t mods = _sapp_x11_mods(event->xbutton.state); uint32_t mods = _sapp_x11_mods(event->xbutton.state);
// X11 doesn't set modifier bit on button down, so emulate that // X11 doesn't set modifier bit on button down, so emulate that
@ -10501,7 +10541,7 @@ _SOKOL_PRIVATE void _sapp_x11_process_event(XEvent* event) {
break; break;
case ButtonRelease: case ButtonRelease:
{ {
_sapp_x11_mouse_update(event->xbutton.x, event->xbutton.y); _sapp_x11_mouse_update(event->xbutton.x, event->xbutton.y, false);
const sapp_mousebutton btn = _sapp_x11_translate_button(event); const sapp_mousebutton btn = _sapp_x11_translate_button(event);
if (btn != SAPP_MOUSEBUTTON_INVALID) { if (btn != SAPP_MOUSEBUTTON_INVALID) {
uint32_t mods = _sapp_x11_mods(event->xbutton.state); uint32_t mods = _sapp_x11_mods(event->xbutton.state);
@ -10515,19 +10555,19 @@ _SOKOL_PRIVATE void _sapp_x11_process_event(XEvent* event) {
case EnterNotify: case EnterNotify:
/* don't send enter/leave events while mouse button held down */ /* don't send enter/leave events while mouse button held down */
if (0 == _sapp.x11.mouse_buttons) { if (0 == _sapp.x11.mouse_buttons) {
_sapp_x11_mouse_update(event->xcrossing.x, event->xcrossing.y); _sapp_x11_mouse_update(event->xcrossing.x, event->xcrossing.y, true);
_sapp_x11_mouse_event(SAPP_EVENTTYPE_MOUSE_ENTER, SAPP_MOUSEBUTTON_INVALID, _sapp_x11_mods(event->xcrossing.state)); _sapp_x11_mouse_event(SAPP_EVENTTYPE_MOUSE_ENTER, SAPP_MOUSEBUTTON_INVALID, _sapp_x11_mods(event->xcrossing.state));
} }
break; break;
case LeaveNotify: case LeaveNotify:
if (0 == _sapp.x11.mouse_buttons) { if (0 == _sapp.x11.mouse_buttons) {
_sapp_x11_mouse_update(event->xcrossing.x, event->xcrossing.y); _sapp_x11_mouse_update(event->xcrossing.x, event->xcrossing.y, true);
_sapp_x11_mouse_event(SAPP_EVENTTYPE_MOUSE_LEAVE, SAPP_MOUSEBUTTON_INVALID, _sapp_x11_mods(event->xcrossing.state)); _sapp_x11_mouse_event(SAPP_EVENTTYPE_MOUSE_LEAVE, SAPP_MOUSEBUTTON_INVALID, _sapp_x11_mods(event->xcrossing.state));
} }
break; break;
case MotionNotify: case MotionNotify:
if (!_sapp.mouse.locked) { if (!_sapp.mouse.locked) {
_sapp_x11_mouse_update(event->xmotion.x, event->xmotion.y); _sapp_x11_mouse_update(event->xmotion.x, event->xmotion.y, false);
_sapp_x11_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID, _sapp_x11_mods(event->xmotion.state)); _sapp_x11_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID, _sapp_x11_mods(event->xmotion.state));
} }
break; break;
@ -10658,7 +10698,12 @@ _SOKOL_PRIVATE void _sapp_x11_process_event(XEvent* event) {
(unsigned char**) &data); (unsigned char**) &data);
if (_sapp.drop.enabled && result) { if (_sapp.drop.enabled && result) {
if (_sapp_x11_parse_dropped_files_list(data)) { if (_sapp_x11_parse_dropped_files_list(data)) {
_sapp.mouse.dx = 0.0f;
_sapp.mouse.dy = 0.0f;
if (_sapp_events_enabled()) { if (_sapp_events_enabled()) {
// FIXME: Figure out how to get modifier key state here.
// The XSelection event has no 'state' item, and
// XQueryKeymap() always returns a zeroed array.
_sapp_init_event(SAPP_EVENTTYPE_FILES_DROPPED); _sapp_init_event(SAPP_EVENTTYPE_FILES_DROPPED);
_sapp_call_event(&_sapp.event); _sapp_call_event(&_sapp.event);
} }
@ -11017,7 +11062,7 @@ SOKOL_API_IMPL float sapp_dpi_scale(void) {
return _sapp.dpi_scale; return _sapp.dpi_scale;
} }
SOKOL_APP_IMPL const void* sapp_egl_get_display(void) { SOKOL_API_IMPL const void* sapp_egl_get_display(void) {
SOKOL_ASSERT(_sapp.valid); SOKOL_ASSERT(_sapp.valid);
#if defined(_SAPP_ANDROID) #if defined(_SAPP_ANDROID)
return _sapp.android.display; return _sapp.android.display;
@ -11028,7 +11073,7 @@ SOKOL_APP_IMPL const void* sapp_egl_get_display(void) {
#endif #endif
} }
SOKOL_APP_IMPL const void* sapp_egl_get_context(void) { SOKOL_API_IMPL const void* sapp_egl_get_context(void) {
SOKOL_ASSERT(_sapp.valid); SOKOL_ASSERT(_sapp.valid);
#if defined(_SAPP_ANDROID) #if defined(_SAPP_ANDROID)
return _sapp.android.context; return _sapp.android.context;

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -198,11 +198,11 @@
sshape_element_range_t sshape_element_range(const sshape_buffer_t* buf); sshape_element_range_t sshape_element_range(const sshape_buffer_t* buf);
sg_buffer_desc sshape_vertex_buffer_desc(const sshape_buffer_t* buf); sg_buffer_desc sshape_vertex_buffer_desc(const sshape_buffer_t* buf);
sg_buffer_desc sshape_index_buffer_desc(const sshape_buffer_t* buf); sg_buffer_desc sshape_index_buffer_desc(const sshape_buffer_t* buf);
sg_buffer_layout_desc sshape_buffer_layout_desc(void); sg_vertex_buffer_layout_state sshape_vertex_buffer_layout_state(void);
sg_vertex_attr_desc sshape_position_attr_desc(void); sg_vertex_attr_state sshape_position_vertex_attr_state(void);
sg_vertex_attr_desc sshape_normal_attr_desc(void); sg_vertex_attr_state sshape_normal_vertex_attr_state(void);
sg_vertex_attr_desc sshape_texcoord_attr_desc(void); sg_vertex_attr_state sshape_texcoord_vertex_attr_state(void);
sg_vertex_attr_desc sshape_color_attr_desc(void); sg_vertex_attr_state sshape_color_vertex_attr_state(void);
``` ```
The sshape_element_range_t struct contains the base-index and number of The sshape_element_range_t struct contains the base-index and number of
@ -234,12 +234,12 @@
```c ```c
sg_pipeline pip = sg_make_pipeline(&(sg_pipeline_desc){ sg_pipeline pip = sg_make_pipeline(&(sg_pipeline_desc){
.layout = { .layout = {
.buffers[0] = sshape_buffer_layout_desc(), .buffers[0] = sshape_vertex_buffer_layout_state(),
.attrs = { .attrs = {
[0] = sshape_position_attr_desc(), [0] = sshape_position_vertex_attr_state(),
[1] = ssape_normal_attr_desc(), [1] = ssape_normal_vertex_attr_state(),
[2] = sshape_texcoord_attr_desc(), [2] = sshape_texcoord_vertex_attr_state(),
[3] = sshape_color_attr_desc() [3] = sshape_color_vertex_attr_state()
} }
}, },
... ...
@ -247,8 +247,8 @@
``` ```
Note that you don't have to use all generated vertex attributes in the Note that you don't have to use all generated vertex attributes in the
pipeline's vertex layout, the sg_buffer_layout_desc struct returned pipeline's vertex layout, the sg_vertex_buffer_layout_state struct returned
by sshape_buffer_layout_desc() contains the correct vertex stride by sshape_vertex_buffer_layout_state() contains the correct vertex stride
to skip vertex components. to skip vertex components.
WRITING MULTIPLE SHAPES INTO THE SAME BUFFER WRITING MULTIPLE SHAPES INTO THE SAME BUFFER
@ -522,11 +522,11 @@ SOKOL_SHAPE_API_DECL sshape_sizes_t sshape_torus_sizes(uint32_t sides, uint32_t
SOKOL_SHAPE_API_DECL sshape_element_range_t sshape_element_range(const sshape_buffer_t* buf); SOKOL_SHAPE_API_DECL sshape_element_range_t sshape_element_range(const sshape_buffer_t* buf);
SOKOL_SHAPE_API_DECL sg_buffer_desc sshape_vertex_buffer_desc(const sshape_buffer_t* buf); SOKOL_SHAPE_API_DECL sg_buffer_desc sshape_vertex_buffer_desc(const sshape_buffer_t* buf);
SOKOL_SHAPE_API_DECL sg_buffer_desc sshape_index_buffer_desc(const sshape_buffer_t* buf); SOKOL_SHAPE_API_DECL sg_buffer_desc sshape_index_buffer_desc(const sshape_buffer_t* buf);
SOKOL_SHAPE_API_DECL sg_buffer_layout_desc sshape_buffer_layout_desc(void); SOKOL_SHAPE_API_DECL sg_vertex_buffer_layout_state sshape_vertex_buffer_layout_state(void);
SOKOL_SHAPE_API_DECL sg_vertex_attr_desc sshape_position_attr_desc(void); SOKOL_SHAPE_API_DECL sg_vertex_attr_state sshape_position_vertex_attr_state(void);
SOKOL_SHAPE_API_DECL sg_vertex_attr_desc sshape_normal_attr_desc(void); SOKOL_SHAPE_API_DECL sg_vertex_attr_state sshape_normal_vertex_attr_state(void);
SOKOL_SHAPE_API_DECL sg_vertex_attr_desc sshape_texcoord_attr_desc(void); SOKOL_SHAPE_API_DECL sg_vertex_attr_state sshape_texcoord_vertex_attr_state(void);
SOKOL_SHAPE_API_DECL sg_vertex_attr_desc sshape_color_attr_desc(void); SOKOL_SHAPE_API_DECL sg_vertex_attr_state sshape_color_vertex_attr_state(void);
/* helper functions to build packed color value from floats or bytes */ /* helper functions to build packed color value from floats or bytes */
SOKOL_SHAPE_API_DECL uint32_t sshape_color_4f(float r, float g, float b, float a); SOKOL_SHAPE_API_DECL uint32_t sshape_color_4f(float r, float g, float b, float a);
@ -1397,38 +1397,38 @@ SOKOL_SHAPE_API_DECL sshape_element_range_t sshape_element_range(const sshape_bu
return range; return range;
} }
SOKOL_API_IMPL sg_buffer_layout_desc sshape_buffer_layout_desc(void) { SOKOL_API_IMPL sg_vertex_buffer_layout_state sshape_vertex_buffer_layout_state(void) {
sg_buffer_layout_desc desc = { 0 }; sg_vertex_buffer_layout_state state = { 0 };
desc.stride = sizeof(sshape_vertex_t); state.stride = sizeof(sshape_vertex_t);
return desc; return state;
} }
SOKOL_API_IMPL sg_vertex_attr_desc sshape_position_attr_desc(void) { SOKOL_API_IMPL sg_vertex_attr_state sshape_position_vertex_attr_state(void) {
sg_vertex_attr_desc desc = { 0 }; sg_vertex_attr_state state = { 0 };
desc.offset = offsetof(sshape_vertex_t, x); state.offset = offsetof(sshape_vertex_t, x);
desc.format = SG_VERTEXFORMAT_FLOAT3; state.format = SG_VERTEXFORMAT_FLOAT3;
return desc; return state;
} }
SOKOL_API_IMPL sg_vertex_attr_desc sshape_normal_attr_desc(void) { SOKOL_API_IMPL sg_vertex_attr_state sshape_normal_vertex_attr_state(void) {
sg_vertex_attr_desc desc = { 0 }; sg_vertex_attr_state state = { 0 };
desc.offset = offsetof(sshape_vertex_t, normal); state.offset = offsetof(sshape_vertex_t, normal);
desc.format = SG_VERTEXFORMAT_BYTE4N; state.format = SG_VERTEXFORMAT_BYTE4N;
return desc; return state;
} }
SOKOL_API_IMPL sg_vertex_attr_desc sshape_texcoord_attr_desc(void) { SOKOL_API_IMPL sg_vertex_attr_state sshape_texcoord_vertex_attr_state(void) {
sg_vertex_attr_desc desc = { 0 }; sg_vertex_attr_state state = { 0 };
desc.offset = offsetof(sshape_vertex_t, u); state.offset = offsetof(sshape_vertex_t, u);
desc.format = SG_VERTEXFORMAT_USHORT2N; state.format = SG_VERTEXFORMAT_USHORT2N;
return desc; return state;
} }
SOKOL_API_IMPL sg_vertex_attr_desc sshape_color_attr_desc(void) { SOKOL_API_IMPL sg_vertex_attr_state sshape_color_vertex_attr_state(void) {
sg_vertex_attr_desc desc = { 0 }; sg_vertex_attr_state state = { 0 };
desc.offset = offsetof(sshape_vertex_t, color); state.offset = offsetof(sshape_vertex_t, color);
desc.format = SG_VERTEXFORMAT_UBYTE4N; state.format = SG_VERTEXFORMAT_UBYTE4N;
return desc; return state;
} }
#ifdef __clang__ #ifdef __clang__

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,4 @@
#include "yugine.h" #include "yugine.h"
#include "camera.h" #include "camera.h"
#include "font.h" #include "font.h"
#include "gameobject.h" #include "gameobject.h"
@ -33,8 +32,13 @@
#include "string.h" #include "string.h"
#include "nuklear.h"
#include "sokol/sokol_gfx.h"
#include "sokol/sokol_nuklear.h"
#define SOKOL_TRACE_HOOKS #define SOKOL_TRACE_HOOKS
#define SOKOL_IMPL #define SOKOL_IMPL
#include "sokol/sokol_app.h" #include "sokol/sokol_app.h"
#include "sokol/sokol_audio.h" #include "sokol/sokol_audio.h"
#include "sokol/sokol_time.h" #include "sokol/sokol_time.h"

View file

@ -482,7 +482,6 @@ var editor = {
time: 0, time: 0,
ed_gui() { ed_gui() {
this.time = Date.now();
/* Clean out killed objects */ /* Clean out killed objects */
this.selectlist = this.selectlist.filter(function(x) { return x.alive; }); this.selectlist = this.selectlist.filter(function(x) { return x.alive; });
@ -604,7 +603,7 @@ var editor = {
wh[0] /= editor.camera.zoom; wh[0] /= editor.camera.zoom;
wh[1] /= editor.camera.zoom; wh[1] /= editor.camera.zoom;
var bb = cwh2bb(world2screen(c),wh); var bb = cwh2bb(world2screen(c),wh);
Debug.boundingbox(bb, [255,255,255,10]); Debug.boundingbox(bb, [255,255,55,10]);
Debug.line(bb2points(bb).wrapped(1), Color.white); Debug.line(bb2points(bb).wrapped(1), Color.white);
} }

View file

@ -1,5 +1,29 @@
#version 330 @vs vs9
in vec2 vert;
in vec2 vuv;
in vec4 vborder;
in vec2 vscale;
in vec4 vcolor;
out vec2 uv;
out vec4 border;
out vec2 scale;
out vec4 fcolor;
uniform vs9_params { mat4 projection; };
void main()
{
gl_Position = projection * vec4(vert, 0.0, 1.0);
uv = vuv;
border = vborder;
scale = vscale;
fcolor = vcolor;
}
@end
@fs fs9
in vec2 uv; /* image uv */ in vec2 uv; /* image uv */
in vec4 border; /* uv length of border, normalized to image dimensions; left, bottom, right, top */ in vec4 border; /* uv length of border, normalized to image dimensions; left, bottom, right, top */
in vec2 scale; /* polygon dimensions ~ texture dimensions */ in vec2 scale; /* polygon dimensions ~ texture dimensions */
@ -7,7 +31,8 @@ in vec4 fcolor;
out vec4 color; out vec4 color;
uniform sampler2D image; uniform texture2D image;
uniform sampler smp;
float map(float value, float min1, float max1, float min2, float max2) float map(float value, float min1, float max1, float min2, float max2)
{ {
@ -33,5 +58,8 @@ vec2 uv9slice(vec2 uv, vec2 s, vec4 b)
void main() void main()
{ {
vec2 nuv = uv9slice(uv, scale, border); vec2 nuv = uv9slice(uv, scale, border);
color = fcolor * texture(image, uv); color = fcolor * texture(sampler2D(image,smp), uv);
} }
@end
@program slice9 vs9 fs9

View file

@ -1,30 +0,0 @@
#version 330 core
in vec2 TexCoords;
out vec4 frag_color;
uniform sampler2D diffuse_texture;
float[] kernel = float[9](1.0/9.0,1.0/9.0,1.0/9.0,
1.0/9.0,1.0/9.0,1.0/9.0,
1.0/9.0,1.0/9.0,1.0/9.0);
void main()
{
frag_color = texture(diffuse_texture, TexCoords);
return;
vec2 res = vec2(640,360);
vec2 uv = gl_FragCoord.xy;
vec2 screen = textureSize(diffuse_texture,0);
vec3 acc = vec3(0);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
vec2 realRes = uv + vec2(i-1,j-1);
acc += texture(diffuse_texture, realRes / res).rgb * kernel[i*3+j];
}
}
frag_color = vec4(acc,1);
}

27
source/shaders/box.sglsl Normal file
View file

@ -0,0 +1,27 @@
@vs bvs
in vec2 aPos;
in vec2 aTexCoords;
out vec2 TexCoords;
void main()
{
gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0);
TexCoords = aTexCoords;
}
@end
@fs bfs
in vec2 TexCoords;
out vec4 frag_color;
uniform texture2D diffuse;
uniform sampler smp;
void main()
{
frag_color = texture(sampler2D(diffuse,smp), TexCoords);
}
@end
@program box bvs bfs

View file

@ -1,15 +1,39 @@
#version 330 @vs circle_vs
in vec2 coords; in vec2 vertex;
in vec2 apos;
in float aradius;
in vec4 acolor;
in float asegsize;
in float afill;
out vec2 coords;
out vec4 fcolor;
out float segsize;
out float fill;
out float radius;
uniform cvs_params { mat4 proj; };
void main()
{
gl_Position = proj * vec4((vertex * aradius) + apos, 0.0, 1.0);
coords = vertex;
fcolor = acolor;
segsize = asegsize;
fill = afill;
radius = aradius;
}
@end
@fs circle_fs
out vec4 color; out vec4 color;
in vec2 coords;
in float radius;
in vec4 fcolor; in vec4 fcolor;
in vec2 pos;
in float segsize; in float segsize;
in float fill; in float fill;
in float radius;
#define PI 3.14 #define PI 3.14
@ -36,3 +60,7 @@ void main()
if (mod(f, segsize) < segsize/2) if (mod(f, segsize) < segsize/2)
discard; discard;
} }
@end
@program circle circle_vs circle_fs

View file

@ -1,27 +0,0 @@
#version 330 core
layout (location = 0) in vec2 vertex;
layout (location = 1) in vec2 apos;
layout (location = 2) in float aradius;
layout (location = 3) in vec4 acolor;
layout (location = 4) in float asegsize;
layout (location = 5) in float afill;
out vec2 coords;
out vec4 fcolor;
out float segsize;
out float fill;
out float radius;
uniform mat4 proj;
void main()
{
gl_Position = proj * vec4((vertex * aradius) + apos, 0.0, 1.0);
coords = vertex;
fcolor = acolor;
segsize = asegsize;
fill = afill;
radius = aradius;
}

View file

@ -1,17 +1,30 @@
#version 330 core @vs vs
in vec2 TexCoords; in vec2 aPos;
in vec2 aTexCoords;
out vec4 frag_color; out vec2 TexCoords;
uniform sampler2D diffuse_texture;
void main() void main()
{ {
frag_color = texture(diffuse_texture, TexCoords); gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0);
return; TexCoords = aTexCoords;
vec2 screensize = textureSize(diffuse_texture,0); }
@end
vec4 color = texture(diffuse_texture, TexCoords); @fs fs
in vec2 TexCoords;
out vec4 frag_color;
uniform texture2D diffuse;
uniform sampler smp;
void main()
{
frag_color = texture(sampler2D(diffuse,smp), TexCoords);
return;
/* vec2 screensize = textureSize(diffuse,0);
vec4 color = texture(sampler2D(diffuse,smp), TexCoords);
float avg = 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b; float avg = 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b;
frag_color = vec4(avg,avg,avg,1.0); frag_color = vec4(avg,avg,avg,1.0);
float lc = screensize.y/2.0; float lc = screensize.y/2.0;
@ -26,4 +39,8 @@ void main()
float b = color.b; float b = color.b;
frag_color = vec4(r, g*0.99, b, 1.0) * clamp(line_intensity, 0.85, 1.0); frag_color = vec4(r, g*0.99, b, 1.0) * clamp(line_intensity, 0.85, 1.0);
*/
} }
@end
@program crt vs fs

View file

@ -1,4 +1,31 @@
#version 330 core @vs vs
in vec3 a_pos;
in vec2 a_tex_coords;
in vec3 a_norm;
out vec2 tex_coords;
out vec3 normal;
out vec3 frag_pos;
out vec4 frag_pos_light;
uniform vs_p {
uniform mat4 vp;
uniform mat4 model;
uniform mat4 proj;
uniform mat4 lsm;
};
void main() {
frag_pos = vec3(model * vec4(a_pos, 1.0));
gl_Position = proj * vp * vec4(frag_pos, 1.0);
tex_coords = a_tex_coords;
normal = mat3(transpose(inverse(model))) * a_norm;
frag_pos_light = lsm * vec4(frag_pos, 1.0);
}
@end
@fs fs
in vec2 tex_coords; in vec2 tex_coords;
in vec3 normal; in vec3 normal;
in vec3 frag_pos; in vec3 frag_pos;
@ -6,16 +33,19 @@ in vec4 frag_pos_light;
out vec4 frag_color; out vec4 frag_color;
uniform sampler2D diffuse; uniform texture2D diffuse;
uniform sampler2D normmap; uniform texture2D normmap;
uniform sampler2D shadow_map; uniform texture2D shadow_map;
uniform sampler smp;
uniform fs_p {
uniform vec3 point_pos; uniform vec3 point_pos;
uniform vec3 dir_dir; uniform vec3 dir_dir;
uniform vec3 view_pos; uniform vec3 view_pos;
uniform vec3 spot_pos; uniform vec3 spot_pos;
uniform vec3 spot_dir; uniform vec3 spot_dir;
uniform vec2 shadow_dim;
};
/* Ambient light */ /* Ambient light */
float amb_str = 0.3; float amb_str = 0.3;
@ -52,7 +82,7 @@ float shadow_calc(vec4 fg)
if (pc.z > 1.0) if (pc.z > 1.0)
return 0.0; return 0.0;
float closest_depth = texture(shadow_map, pc.xy).r; float closest_depth = texture(sampler2D(shadow_map,smp), pc.xy).r;
float cur_depth = pc.z; float cur_depth = pc.z;
vec3 light_dir = normalize(vec3(4,100,20) - frag_pos); /* light pos */ vec3 light_dir = normalize(vec3(4,100,20) - frag_pos); /* light pos */
@ -61,11 +91,11 @@ float shadow_calc(vec4 fg)
return cur_depth - bias > closest_depth ? 1.0 : 0.0; return cur_depth - bias > closest_depth ? 1.0 : 0.0;
float s; float s;
vec2 texel_size = 1 / textureSize(shadow_map, 0); vec2 texel_size = 1 / shadow_dim;
for (int x = -1; x <= 1; ++x) { for (int x = -1; x <= 1; ++x) {
for (int y = -1; y <= 1; ++y) { for (int y = -1; y <= 1; ++y) {
float pcf_depth = texture(shadow_map, pc.xy + vec2(x,y) * texel_size).r; float pcf_depth = texture(sampler2D(shadow_map,smp), pc.xy + vec2(x,y) * texel_size).r;
s += cur_depth - bias > pcf_depth ? 1.0 : 0.0; s += cur_depth - bias > pcf_depth ? 1.0 : 0.0;
} }
} }
@ -97,8 +127,11 @@ void main() {
spot_amt = light_str(spot_dir) * intensity; spot_amt = light_str(spot_dir) * intensity;
} }
vec4 mm = texture(diffuse,tex_coords); vec4 mm = texture(sampler2D(diffuse,smp),tex_coords);
float shadow = shadow_calc(frag_pos_light); float shadow = shadow_calc(frag_pos_light);
vec3 res = mm.rgb * (amb_str + (point_amt + dir_amt) * (1 - shadow)); vec3 res = mm.rgb * (amb_str + (point_amt + dir_amt) * (1 - shadow));
frag_color = vec4(res, mm.a); frag_color = vec4(res, mm.a);
} }
@end
@program diffuse vs fs

View file

@ -1,23 +0,0 @@
#version 330 core
layout (location=0) in vec3 a_pos;
layout (location=1) in vec2 a_tex_coords;
layout (location=2) in vec3 a_norm;
out vec2 tex_coords;
out vec3 normal;
out vec3 frag_pos;
out vec4 frag_pos_light;
uniform mat4 vp;
uniform mat4 model;
uniform mat4 proj;
uniform mat4 lsm;
void main() {
frag_pos = vec3(model * vec4(a_pos, 1.0));
gl_Position = proj * vp * vec4(frag_pos, 1.0);
tex_coords = a_tex_coords;
normal = mat3(transpose(inverse(model))) * a_norm;
frag_pos_light = lsm * vec4(frag_pos, 1.0);
}

49
source/shaders/grid.sglsl Normal file
View file

@ -0,0 +1,49 @@
@vs vs
in vec2 pos;
out vec2 apos;
uniform mpara {
uniform vec2 offset;
uniform vec2 dimen;
};
void main()
{
apos = ((pos*0.5)*dimen) + offset;
gl_Position = vec4(pos, 0.f, 1.f);
}
@end
@fs fs
out vec4 frag_color;
in vec2 apos;
uniform fs_params {
uniform float thickness;
uniform float span;
uniform vec4 color;
};
void main()
{
float t = thickness / span;
t /= 2.0;
vec2 bpos;
bpos.x = mod(apos.x, span) / span;
bpos.y = mod(apos.y, span) / span;
bpos.x -= t;
bpos.y -= t;
float comp = min(bpos.x, bpos.y);
if (comp > t)
discard;
comp += t;
frag_color = color;
}
@end
@program grid vs fs

View file

@ -1,28 +0,0 @@
#version 330
out vec4 frag_color;
in vec2 apos; /* Drawing coordinates of the grid */
uniform float thickness; /* thickness in pixels */
uniform float span;
uniform vec4 color;
void main(void)
{
float t = thickness / span;
t /= 2.0;
vec2 bpos;
bpos.x = mod(apos.x, span) / span;
bpos.y = mod(apos.y, span) / span;
bpos.x -= t;
bpos.y -= t;
float comp = min(bpos.x, bpos.y);
if (comp > t)
discard;
comp += t;
frag_color = color;
}

View file

@ -1,18 +0,0 @@
#version 330
layout (location = 0) in vec2 pos;
out vec2 apos;
layout (std140) uniform Projection {
mat4 projection;
};
uniform vec2 offset;
uniform vec2 dimen;
void main()
{
apos = ((pos*0.5)*dimen) + offset;
gl_Position = vec4(pos, 0.f, 1.f);
}

View file

@ -1,16 +1,40 @@
#version 330 @vs lvs
in vec2 apos;
in float adist;
in vec4 acolor;
in float aseglen;
in float asegspeed;
out float dist;
out vec4 fcolor;
out float seg_len;
out float seg_speed;
uniform lvs_params { mat4 proj; };
void main()
{
gl_Position = proj * vec4(apos, 0.0, 1.0);
fcolor = acolor;
dist = adist;
seg_len = aseglen;
seg_speed = asegspeed;
}
@end
@fs lfs
out vec4 color; out vec4 color;
in float dist; in float dist;
in vec4 fcolor; in vec4 fcolor;
in float seg_len;
in float seg_speed; in float seg_speed;
in float seg_len;
float pat = 0.5; float pat = 0.5;
int pp = 0x0C24; int pp = 0x0C24;
uniform float time; uniform lfs_params { uniform float time; };
void main() void main()
{ {
@ -34,3 +58,6 @@ void main()
discard; discard;
*/ */
} }
@end
@program line lvs lfs

View file

@ -1,22 +0,0 @@
#version 330
layout (location = 0) in vec2 apos;
layout (location = 1) in float adist;
layout (location = 2) in vec4 acolor;
layout (location = 3) in float aseglen;
layout (location = 4) in float asegspeed;
out float dist;
out vec4 fcolor;
out float seg_len;
out float seg_speed;
uniform mat4 proj;
void main()
{
gl_Position = proj * vec4(apos, 0.f, 1.f);
fcolor = acolor;
dist = adist;
seg_len = aseglen;
seg_speed = asegspeed;
}

View file

@ -0,0 +1,40 @@
@vs vs
in vec4 vertex;
out vec2 TexCoords;
uniform vs_p { mat4 model; mat4 projection; };
void main()
{
TexCoords = vec2(vertex.x, 1.0 - vertex.y);
gl_Position = projection * model * vec4(vertex.xy, 0.0, 1.0);
}
@end
@fs fs
in vec2 TexCoords;
out vec4 color;
uniform texture2D texture_y;
uniform texture2D texture_cb;
uniform texture2D texture_cr;
uniform sampler smp;
mat4 rec601 = mat4(
1.16438, 0.00000, 1.59603, -0.87079,
1.16438, -0.39176, -0.81297, 0.52959,
1.16438, 2.01723, 0.00000, -1.08139,
0, 0, 0, 1
);
void main()
{
float y = texture(sampler2D(texture_y,smp), TexCoords).r;
float cb = texture(sampler2D(texture_cb,smp), TexCoords).r;
float cr = texture(sampler2D(texture_cr,smp), TexCoords).r;
color = vec4(y, cb, cr, 1.f) * rec601;
}
@end
@program mpeg2 vs fs

View file

@ -0,0 +1,34 @@
@vs pointvs
in vec2 apos;
in vec4 acolor;
in float aradius;
uniform pvs_p { mat4 proj; };
out vec4 fcolor;
void main()
{
gl_Position = proj * vec4(apos, 0.0, 1.0);
fcolor = acolor;
gl_PointSize = aradius;
}
@end
@fs pointfs
out vec4 color;
in vec4 fcolor;
void main()
{
float d = length(gl_FragCoord.xy - vec2(0.5,0.5)); /* Should really pointcoord, normalized */
if (d >= 0.47)
discard;
color = fcolor;
}
@end
@program point pointvs pointfs

View file

@ -1,13 +0,0 @@
#version 330 core
in vec4 fcolor;
out vec4 color;
void main()
{
float d = length(gl_PointCoord - vec2(0.5,0.5));
if (d >= 0.47)
discard;
color = fcolor;
}

View file

@ -1,16 +0,0 @@
#version 330 core
layout (location = 0) in vec2 apos;
layout (location = 1) in vec4 acolor;
layout (location = 2) in float radius;
uniform mat4 proj;
out vec4 fcolor;
void main()
{
gl_Position = proj * vec4(apos, 0.0, 1.0);
fcolor = acolor;
gl_PointSize = radius;
}

View file

@ -1,4 +1,4 @@
#version 330 core @vs pvs
in vec2 apos; in vec2 apos;
in vec2 auv; in vec2 auv;
in vec4 acolor; in vec4 acolor;
@ -6,7 +6,7 @@ in vec4 acolor;
out vec4 color; out vec4 color;
out vec2 uv; out vec2 uv;
uniform mat4 proj; uniform pvs_params { mat4 proj; };
void main() void main()
{ {
@ -14,3 +14,17 @@ void main()
color = acolor; color = acolor;
uv = auv; uv = auv;
} }
@end
@fs pfs
in vec4 color;
in vec2 uv;
out vec4 fcolor;
void main()
{
fcolor = color;
}
@end
@program poly pvs pfs

View file

@ -1,10 +0,0 @@
#version 330 core
out vec4 fcolor;
in vec4 color;
in vec2 uv;
void main()
{
fcolor = color;
}

View file

@ -1,58 +0,0 @@
#version 330 core
out vec4 FragColor;
in vec2 TexCoords;
uniform sampler2D screenTexture;
const float offset = 1.0 / 300.0;
void main()
{
FragColor = texture(screenTexture, TexCoords);
//Invert color
//FragColor = vec4(vec3(1.0 - texture(screenTexture, TexCoords)), 1.0);
//Grayscale
//FragColor = texture(screenTexture, TexCoords);
//float average = 0.2126 * FragColor.r + 0.7152 * FragColor.g + 0.0722 * FragColor.b;
//FragColor = vec4(average, average, average, 1.0);
//Blur
// vec2 offsets[9] = vec2[](
// vec2(-offset, offset), // top-left
// vec2( 0.0f, offset), // top-center
// vec2( offset, offset), // top-right
// vec2(-offset, 0.0f), // center-left
// vec2( 0.0f, 0.0f), // center-center
// vec2( offset, 0.0f), // center-right
// vec2(-offset, -offset), // bottom-left
// vec2( 0.0f, -offset), // bottom-center
// vec2( offset, -offset) // bottom-right
// );
// Sharpen kernel
// float kernel[9] = float[](
// -1, -1, -1,
// -1, 9, -1,
// -1, -1, -1
// );
// Blur kernel
// float kernel[9] = float[](
// 1.0 / 16, 2.0 / 16, 1.0 / 16,
// 2.0 / 16, 4.0 / 16, 2.0 / 16,
// 1.0 / 16, 2.0 / 16, 1.0 / 16
// );
// vec3 sampleTex[9];
// for(int i = 0; i < 9; i++)
// {
// sampleTex[i] = vec3(texture(screenTexture, TexCoords.st + offsets[i]));
// }
// vec3 col = vec3(0.0);
// for(int i = 0; i < 9; i++)
// col += sampleTex[i] * kernel[i];
// FragColor = vec4(col, 1.0);
}

View file

@ -1,11 +0,0 @@
#version 330 core
layout (location = 0) in vec2 aPos;
layout (location = 1) in vec2 aTexCoords;
out vec2 TexCoords;
void main()
{
gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0);
TexCoords = aTexCoords;
}

View file

@ -0,0 +1,25 @@
@vs svs
in vec3 aPos;
uniform vs_p {
mat4 lightSpaceMatrix;
mat4 model;
};
void main()
{
gl_Position = lightSpaceMatrix * model * vec4(aPos, 1.0);
}
@end
@fs sfs
out float frag_color;
void main()
{
// frag_color = encode_depth(gl_FragCoord.z);
frag_color = gl_FragCoord.z;
}
@end
@program shadow svs sfs

View file

@ -1,8 +0,0 @@
#version 330 core
out float frag_color;
void main()
{
// frag_color = encode_depth(gl_FragCoord.z);
frag_color = gl_FragCoord.z;
}

View file

@ -1,10 +0,0 @@
#version 330 core
layout (location = 0) in vec3 aPos;
uniform mat4 lightSpaceMatrix;
uniform mat4 model;
void main()
{
gl_Position = lightSpaceMatrix * model * vec4(aPos, 1.0);
}

View file

@ -1,26 +0,0 @@
#version 330 core
layout (location = 0) in vec2 vert;
layout (location = 1) in vec2 vuv;
layout (location = 2) in vec4 vborder;
layout (location = 3) in vec2 vscale;
layout (location = 4) in vec4 vcolor;
out vec2 uv;
out vec4 border;
out vec2 scale;
out vec4 fcolor;
uniform mat4 projection;
void main()
{
gl_Position = projection * vec4(vert, 0.0, 1.0);
uv = vuv;
border = vborder;
scale = vscale;
fcolor = vcolor;
}

View file

@ -0,0 +1,36 @@
@vs vs
in vec2 vertex;
in vec2 uv;
in vec4 vColor;
out vec2 texcoords;
out vec4 fcolor;
uniform vs_p { mat4 proj; };
void main()
{
fcolor = vColor;
texcoords = uv;
gl_Position = proj * vec4(vertex, 0.0, 1.0);
}
@end
@fs fs
in vec2 texcoords;
in vec4 fcolor;
out vec4 color;
uniform texture2D image;
uniform sampler smp;
void main()
{
color = fcolor * texture(sampler2D(image,smp), texcoords);
if (color.a <= 0.1f)
discard;
}
@end
@program sprite vs fs

View file

@ -1,15 +0,0 @@
#version 330 core
in vec2 texcoords;
in vec4 fcolor;
out vec4 color;
uniform sampler2D image;
void main()
{
color = fcolor * texture(image, texcoords);
if (color.a <= 0.1f)
discard;
}

View file

@ -1,16 +0,0 @@
#version 330 core
layout (location = 0) in vec2 vertex;
layout (location = 1) in vec2 uv;
layout (location = 2) in vec4 vColor;
out vec2 texcoords;
out vec4 fcolor;
uniform mat4 proj;
void main()
{
fcolor = vColor;
texcoords = uv;
gl_Position = proj * vec4(vertex, 0.0, 1.0);
}

76
source/shaders/text.sglsl Normal file
View file

@ -0,0 +1,76 @@
@vs vs
in vec2 vert;
in vec2 pos;
in vec2 wh;
in vec2 uv;
in vec2 st;
in vec4 vColor;
out vec2 TexCoords;
out vec4 fColor;
out vec2 fst;
uniform vs_params { mat4 projection; };
void main()
{
gl_Position = projection * vec4(pos + (vert * wh), 0.0, 1.0);
TexCoords = uv + vec2(vert.x*st.x, st.y - vert.y*st.y);
fst = st / wh;
fColor = vColor;
}
@end
@fs fs
in vec2 TexCoords;
in vec4 fColor;
in vec2 fst;
out vec4 color;
uniform texture2D text;
uniform sampler smp;
float osize = 1.0;
void main()
{
float lettera = texture(sampler2D(text,smp),TexCoords).r;
if (lettera <= 0.1f)
{
vec2 uvpos = TexCoords - fst;
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) {
float pa = texture(sampler2D(text,smp), uvpos + (fst*vec2(x,y))).r;
if (pa > 0.1) {
color = vec4(0.0,0.0,0.0, fColor.a);
return;
}
}
}
discard;
}
// vec2 lsize = fst / textureSize(dtext,0).xy;
/* vec2 uvpos = TexCoords - fst;
for (int x = 0; x < 3; x++) {
for (int y = 0; 0 < 3; y++) {
float pa = texture(sampler2D(text,smp), uvpos + (fst * vec2(x,y))).r;
if (pa <= 0.1) {
color = vec4(0.0,0.0,0.0,fColor.a);
return;
}
}
}
*/
color = vec4(fColor.xyz, fColor.a);
}
@end
@program text vs fs

View file

@ -1,23 +0,0 @@
#version 330 core
layout (location = 0) in vec2 vert;
layout (location = 1) in vec2 pos;
layout (location = 2) in vec2 wh;
layout (location = 3) in vec2 uv;
layout (location = 4) in vec2 st;
layout (location = 5) in vec4 vColor;
out vec2 TexCoords;
out vec4 fColor;
out vec2 fst;
uniform mat4 projection;
void main()
{
gl_Position = projection * vec4(pos + (vert * wh), 0.0, 1.0);
TexCoords = uv + vec2(vert.x*st.x, st.y - vert.y*st.y);
fst = st / wh;
fColor = vColor;
}

View file

@ -1,22 +0,0 @@
#version 330 core
in vec2 TexCoords;
out vec4 color;
uniform sampler2D texture_y;
uniform sampler2D texture_cb;
uniform sampler2D texture_cr;
uniform vec3 spriteColor;
mat4 rec601 = mat4(
1.16438, 0.00000, 1.59603, -0.87079,
1.16438, -0.39176, -0.81297, 0.52959,
1.16438, 2.01723, 0.00000, -1.08139,
0, 0, 0, 1
);
void main() {
float y = texture2D(texture_y, TexCoords).r;
float cb = texture2D(texture_cb, TexCoords).r;
float cr = texture2D(texture_cr, TexCoords).r;
color = vec4(y, cb, cr, 1.f) * rec601 * vec4(spriteColor, 1.f);
}

View file

@ -1,12 +0,0 @@
#version 330 core
layout (location = 0) in vec4 vertex;
out vec2 TexCoords;
uniform mat4 model;
uniform mat4 projection;
void main() {
TexCoords = vec2(vertex.x, 1.0 - vertex.y);
gl_Position = projection * model * vec4(vertex.xy, 0.0, 1.0);
}