Fix rendering regressions; update image and screen pixel pulling

This commit is contained in:
John Alanbrook 2023-09-15 17:31:31 +00:00
parent d86133a317
commit d15c4ec6d1
11 changed files with 41 additions and 102 deletions

View file

@ -94,10 +94,8 @@ else
ifeq ($(UNAME), Darwin)
CFLAGS += -x objective-c
# LDLIBS += Cocoa QuartzCore OpenGL
LDFLAGS += -framework Cocoa -framework QuartzCore -framework OpenGL -framework AudioToolbox
PLAT = mac-$(ARCH)$(INFO)
#LDLIBS += Foundation UIKit OpenGLES GLKit
PLAT = osx-$(ARCH)$(INFO)
endif
endif
@ -115,7 +113,7 @@ includeflag != find source -type d -name include
includeflag += $(engineincs) source/engine/thirdparty/Nuklear source/engine/thirdparty/tinycdb-0.78 source/shaders
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 -Wno-unused-function -Wno-unused-const-variable
NAME = yugine$(EXT)
SEM = 0.0.1
@ -158,21 +156,20 @@ $(DISTDIR)/$(DIST): $(BIN)/$(NAME) $(SCRIPTS) assets/*
@cp -rf source/scripts $(BIN)
@$(PKGCMD)
$(BIN)/libengine.a: $(SHADERS) $(OBJS)
$(BIN)/libengine.a: $(OBJS)
@$(AR) rcs $@ $(OBJS)
$(BIN)/libquickjs.a:
make -C quickjs clean
make -C quickjs OPT=$(OPT) libquickjs.a libquickjs.lto.a CC=$(CC)
cp quickjs/libquickjs.* $(BIN)
make -C quickjs OPT=$(OPT) HOST_CC=$(CC) libquickjs.a libquickjs.lto.a CC=$(CC)
@mkdir -p $(BIN)
cp -rf quickjs/libquickjs.* $(BIN)
$(OBJDIR)/%.o:%.c
$(OBJDIR)/%.o: %.c $(SHADERS)
@mkdir -p $(@D)
@echo Making C object $@
@$(CC) $(CFLAGS) -c $< -o $@
%.c: $(SHADERS)
shaders: $(SHADERS)
@echo Making shaders
@ -184,9 +181,10 @@ clean:
@echo Cleaning project
@rm -rf bin/*
@rm -f *.gz
@rm source/shaders/*.sglsl.h
@rm source/shaders/*.metal
@rm -f source/shaders/*.sglsl.h
@rm -f source/shaders/*.metal
@rm -rf dist/*
@rm TAGS
TAGINC != find . -name "*.[chj]"
tags: $(TAGINC)

View file

@ -70,6 +70,7 @@ ifdef CONFIG_CLANG
CFLAGS += -Wextra
CFLAGS += -Wno-sign-compare
CFLAGS += -Wno-missing-field-initializers
CFLAGS += -Wno-unused-function -Wno-unused-const-variable
CFLAGS += -Wundef -Wuninitialized
CFLAGS += -Wunused -Wno-unused-parameter
CFLAGS += -Wwrite-strings
@ -89,6 +90,7 @@ else
CC=$(CROSS_PREFIX)gcc
CFLAGS=-g -Wall -MMD -MF $(OBJDIR)/$(@F).d
CFLAGS += -Wno-array-bounds -Wno-format-truncation
CFLAGS += -Wno-unused-function -Wno-unused-const-variable
ifdef CONFIG_LTO
AR=$(CROSS_PREFIX)gcc-ar
else

View file

@ -288,7 +288,6 @@ void debugdraw_init()
grid_bind.vertex_buffers[0] = circle_bind.vertex_buffers[1];
poly_shader = sg_make_shader(poly_shader_desc(sg_query_backend()));
poly_pipe = sg_make_pipeline(&(sg_pipeline_desc){
.shader = poly_shader,
.layout = {
@ -300,7 +299,6 @@ void debugdraw_init()
.index_type = SG_INDEXTYPE_UINT32,
.colors[0].blend = blend_trans,
});
poly_bind.vertex_buffers[0] = sg_make_buffer(&(sg_buffer_desc){
.size = sizeof(struct poly_vertex)*v_amt,
.usage = SG_USAGE_STREAM,

View file

@ -23,7 +23,7 @@
struct sFont *font;
#define max_chars 400
#define max_chars 4000
static sg_shader fontshader;
static sg_bindings bind_text;
@ -36,9 +36,10 @@ struct text_vert {
struct rgba color;
};
static struct text_vert text_buffer[max_chars];
static struct text_vert *text_buffer;
void font_init() {
text_buffer = malloc(sizeof(*text_buffer)*max_chars);
fontshader = sg_make_shader(text_shader_desc(sg_query_backend()));
pipe_text = sg_make_pipeline(&(sg_pipeline_desc){
.shader = fontshader,
@ -215,6 +216,9 @@ void text_flush(HMM_Mat4 *proj) {
static int drawcaret = 0;
void sdrawCharacter(struct Character c, HMM_Vec2 cursor, float scale, struct rgba color) {
if (curchar == max_chars)
return;
struct text_vert vert;
float lsize = 1.0 / 1024.0;

View file

@ -24,8 +24,8 @@
#define SOKOL_GFX_IMPL
#include "sokol/sokol_gfx.h"
//#define SOKOL_GFX_EXT_IMPL
//#include "sokol/sokol_gfx_ext.h"
#define SOKOL_GFX_EXT_IMPL
#include "sokol/sokol_gfx_ext.h"
#define MSF_GIF_IMPL
#include "msf_gif.h"
@ -458,7 +458,7 @@ void openglRender(struct window *window) {
sg_end_pass();
gif.timer = appTime;
// sg_query_image_pixels(sg_gif.img, gif.buffer, gif.w*gif.h*4);
sg_query_image_pixels(sg_gif.img, crt_post.bind.fs.samplers[0], gif.buffer, gif.w*gif.h*4);
msf_gif_frame(&gif_state, gif.buffer, gif.cpf, gif.depth, gif.w * -4);
}

View file

@ -21,9 +21,8 @@ https://github.com/edubart/sokol_gp
extern "C" {
#endif
SOKOL_GFX_API_DECL void sg_query_image_pixels(sg_image img_id, void* pixels, int size);
SOKOL_GFX_API_DECL void sg_query_image_pixels(sg_image img_id, sg_sampler smp_id, void* pixels, int size);
SOKOL_GFX_API_DECL void sg_query_pixels(int x, int y, int w, int h, bool origin_top_left, void *pixels, int size);
SOKOL_GFX_API_DECL void sg_update_texture_filter(sg_image img_id, sg_filter min_filter, sg_filter mag_filter);
#ifdef __cplusplus
} // extern "C"
@ -41,15 +40,15 @@ SOKOL_GFX_API_DECL void sg_update_texture_filter(sg_image img_id, sg_filter min_
#if defined(_SOKOL_ANY_GL)
static void _sg_gl_query_image_pixels(_sg_image_t* img, void* pixels) {
static void _sg_gl_query_image_pixels(_sg_image_t* img, _sg_sampler_t *smp, void* pixels) {
SOKOL_ASSERT(img->gl.target == GL_TEXTURE_2D);
SOKOL_ASSERT(0 != img->gl.tex[img->cmn.active_slot]);
#if defined(SOKOL_GLCORE33)
_sg_gl_cache_store_texture_binding(0);
_sg_gl_cache_bind_texture(0, img->gl.target, img->gl.tex[img->cmn.active_slot]);
_sg_gl_cache_store_texture_sampler_binding(0);
_sg_gl_cache_bind_texture_sampler(0, img->gl.target, img->gl.tex[img->cmn.active_slot], smp->gl.smp);
glGetTexImage(img->gl.target, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
_SG_GL_CHECK_ERROR();
_sg_gl_cache_restore_texture_binding(0);
_sg_gl_cache_restore_texture_sampler_binding(0);
#else
static GLuint newFbo = 0;
GLuint oldFbo = 0;
@ -86,18 +85,6 @@ static void _sg_gl_query_pixels(int x, int y, int w, int h, bool origin_top_left
_SG_GL_CHECK_ERROR();
}
static void _sg_gl_update_texture_filter(_sg_image_t* img, sg_filter min_filter, sg_filter mag_filter) {
_sg_gl_cache_store_texture_binding(0);
_sg_gl_cache_bind_texture(0, img->gl.target, img->gl.tex[img->cmn.active_slot]);
img->cmn.min_filter = min_filter;
img->cmn.mag_filter = mag_filter;
GLenum gl_min_filter = _sg_gl_filter(img->cmn.min_filter);
GLenum gl_mag_filter = _sg_gl_filter(img->cmn.mag_filter);
glTexParameteri(img->gl.target, GL_TEXTURE_MIN_FILTER, (GLint)gl_min_filter);
glTexParameteri(img->gl.target, GL_TEXTURE_MAG_FILTER, (GLint)gl_mag_filter);
_sg_gl_cache_restore_texture_binding(0);
}
#elif defined(SOKOL_D3D11)
static inline void _sgext_d3d11_Texture2D_GetDesc(ID3D11Texture2D* self, D3D11_TEXTURE2D_DESC* pDesc) {
@ -261,21 +248,6 @@ static void _sg_d3d11_query_pixels(int x, int y, int w, int h, bool origin_top_l
if(staging_tex) _sg_d3d11_Release(staging_tex);
}
static void _sg_d3d11_update_texture_filter(_sg_image_t* img, sg_filter min_filter, sg_filter mag_filter) {
SOKOL_ASSERT(img->d3d11.tex2d || img->d3d11.tex3d);
HRESULT hr;
_SOKOL_UNUSED(hr);
D3D11_SAMPLER_DESC d3d11_smp_desc;
memset(&d3d11_smp_desc, 0, sizeof(d3d11_smp_desc));
_sgext_d3d11_SamplerState_GetDesc(img->d3d11.smp, &d3d11_smp_desc);
_sg_d3d11_Release(img->d3d11.smp);
img->cmn.min_filter = min_filter;
img->cmn.mag_filter = mag_filter;
d3d11_smp_desc.Filter = _sg_d3d11_filter(img->cmn.min_filter, img->cmn.mag_filter, img->cmn.max_anisotropy);
hr = _sg_d3d11_CreateSamplerState(_sg.d3d11.dev, &d3d11_smp_desc, &img->d3d11.smp);
SOKOL_ASSERT(SUCCEEDED(hr) && img->d3d11.smp);
}
#elif defined(SOKOL_METAL)
#import <Metal/Metal.h>
@ -339,33 +311,18 @@ static void _sg_metal_query_pixels(int x, int y, int w, int h, bool origin_top_l
_sg_metal_encode_texture_pixels(x, y, w, h, origin_top_left, mtl_drawable.texture, pixels);
}
static void _sg_metal_update_texture_filter(_sg_image_t* img, sg_filter min_filter, sg_filter mag_filter) {
sg_image_desc image_desc = {
.min_filter = min_filter,
.mag_filter = mag_filter,
.wrap_u = img->cmn.wrap_u,
.wrap_v = img->cmn.wrap_v,
.wrap_w = img->cmn.wrap_w,
.max_anisotropy = img->cmn.max_anisotropy,
.border_color = img->cmn.border_color,
};
sg_image_desc desc_def = _sg_image_desc_defaults(&image_desc);
img->mtl.sampler_state = _sg_mtl_create_sampler(_sg.mtl.device, &desc_def);
img->cmn.min_filter = min_filter;
img->cmn.mag_filter = mag_filter;
}
#endif
void sg_query_image_pixels(sg_image img_id, void* pixels, int size) {
void sg_query_image_pixels(sg_image img_id, sg_sampler smp_id, void* pixels, int size) {
SOKOL_ASSERT(pixels);
SOKOL_ASSERT(img_id.id != SG_INVALID_ID);
_sg_image_t* img = _sg_lookup_image(&_sg.pools, img_id.id);
_sg_sampler_t *smp = _sg_lookup_sampler(&_sg.pools, smp_id.id);
SOKOL_ASSERT(img);
SOKOL_ASSERT(size >= (img->cmn.width * img->cmn.height * 4));
_SOKOL_UNUSED(size);
#if defined(_SOKOL_ANY_GL)
_sg_gl_query_image_pixels(img, pixels);
_sg_gl_query_image_pixels(img, smp, pixels);
#elif defined(SOKOL_D3D11)
_sg_d3d11_query_image_pixels(img, pixels);
#elif defined(SOKOL_METAL)
@ -386,18 +343,5 @@ void sg_query_pixels(int x, int y, int w, int h, bool origin_top_left, void *pix
#endif
}
void sg_update_texture_filter(sg_image img_id, sg_filter min_filter, sg_filter mag_filter) {
SOKOL_ASSERT(img_id.id != SG_INVALID_ID);
_sg_image_t* img = _sg_lookup_image(&_sg.pools, img_id.id);
SOKOL_ASSERT(img);
#if defined(_SOKOL_ANY_GL)
_sg_gl_update_texture_filter(img, min_filter, mag_filter);
#elif defined(SOKOL_D3D11)
_sg_d3d11_update_texture_filter(img, min_filter, mag_filter);
#elif defined(SOKOL_METAL)
_sg_metal_update_texture_filter(img, min_filter, mag_filter);
#endif
}
#endif // SOKOL_GFX_EXT_IMPL_INCLUDED
#endif // SOKOL_GFX_EXT_IMPL

View file

@ -653,14 +653,6 @@ function bb_expand(oldbb, x) {
return bb;
};
function bb_draw(bb, color) {
if (!bb) return;
var draw = bb2cwh(bb);
draw.wh[0] /= Game.camera.zoom;
draw.wh[1] /= Game.camera.zoom;
Debug.box(world2screen(draw.c), draw.wh, color);
};
function bb_from_objects(objs) {
var bb = objs[0].boundingbox;
objs.forEach(function(obj) { bb = bb_expand(bb, obj.boundingbox); });

View file

@ -52,7 +52,7 @@ var sprite = clone(component, {
get layer() { return undefined; },
boundingbox() {
var dim = this.dimensions;
var dim = this.dimensions();
dim = dim.scale(this.gameobject.scale);
var realpos = this.pos.copy();
realpos.x = realpos.x * dim.x + (dim.x/2);

View file

@ -85,7 +85,7 @@ var Debug = {
draw() {
if (this.draw_bb)
Game.objects.forEach(function(x) { bb_draw(x.boundingbox()); });
Game.objects.forEach(function(x) { Debug.boundingbox(x.boundingbox(), [255,255,255,10]); });
if (Game.paused()) gui_text("PAUSED", [0,0],1);

View file

@ -58,7 +58,7 @@ vec2 uv9slice(vec2 uv, vec2 s, vec4 b)
void main()
{
vec2 nuv = uv9slice(uv, scale, border);
color = fcolor * texture(sampler2D(image,smp), uv);
color = fcolor * texture(sampler2D(image,smp), nuv);
}
@end

View file

@ -1,22 +1,22 @@
@vs pvs
@vs polyvs
in vec2 apos;
in vec2 auv;
in vec2 vuv;
in vec4 acolor;
out vec4 color;
out vec2 uv;
uniform pvs_params { mat4 proj; };
uniform polyvs_params { mat4 proj; };
void main()
{
gl_Position = proj * vec4(apos, 0.0, 1.0);
color = acolor;
uv = auv;
uv = vuv;
gl_Position = proj * vec4(apos, 0.0, 1.0);
}
@end
@fs pfs
@fs polyfs
in vec4 color;
in vec2 uv;
out vec4 fcolor;
@ -24,7 +24,8 @@ out vec4 fcolor;
void main()
{
fcolor = color;
fcolor.x *= (1 + uv.x/100.0); /* Temp dbg fix so vuv compiles */
}
@end
@program poly pvs pfs
@program poly polyvs polyfs