Merge remote-tracking branch 'origin/misty'
Some checks failed
Build and Deploy / build-macos (push) Failing after 5s
Build and Deploy / build-windows (CLANG64) (push) Has been cancelled
Build and Deploy / package-dist (push) Has been cancelled
Build and Deploy / deploy-itch (push) Has been cancelled
Build and Deploy / deploy-gitea (push) Has been cancelled
Build and Deploy / build-linux (push) Has been cancelled

This commit is contained in:
2025-05-24 22:24:01 -05:00
3 changed files with 43 additions and 7 deletions

View File

@@ -406,9 +406,10 @@ var image_info = {
flip_x: false, flip_x: false,
flip_y: false, flip_y: false,
color: Color.white, color: Color.white,
mode: 'linear'
} }
draw.image = function image(image, rect = [0,0], rotation = 0, anchor = [0,0], shear = [0,0], info, pipeline) { draw.image = function image(image, rect = [0,0], rotation = 0, anchor = [0,0], shear = [0,0], info = {}, pipeline) {
if (!image) throw Error('Need an image to render.') if (!image) throw Error('Need an image to render.')
if (typeof image === "string") if (typeof image === "string")
image = graphics.texture(image) image = graphics.texture(image)

View File

@@ -28,8 +28,10 @@ render.initialize = function(config)
url: "https://prosperon.dev" url: "https://prosperon.dev"
} }
prosperon.window = prosperon.engine_start({width:500,height:500}) config.__proto__ = default_conf
context = prosperon.window.make_renderer("vulkan") prosperon.window = prosperon.engine_start(config)
context = prosperon.window.make_renderer()
context.logical_size([config.resolution_x, config.resolution_y], config.mode)
} }
render.sprite = function(sprite) render.sprite = function(sprite)
@@ -49,6 +51,7 @@ render.image = function(image, rect, rotation, anchor, shear, info)
{ {
// rect.width = image.rect_px.width; // rect.width = image.rect_px.width;
// rect.height = image.rect_px.height; // rect.height = image.rect_px.height;
image.texture.mode(info.mode)
context.texture(image.texture, image.rect_px, rect, rotation, anchor); context.texture(image.texture, image.rect_px, rect, rotation, anchor);
} }

View File

@@ -1466,10 +1466,41 @@ JSC_CCALL(renderer_geometry2,
JS_FreeValue(js, idx_v); JS_FreeValue(js, idx_v);
) )
/* logical presentation helpers */
typedef struct { const char *name; SDL_RendererLogicalPresentation pres; } pres_entry;
static const pres_entry k_pres_table[] = {
{ "stretch", SDL_LOGICAL_PRESENTATION_STRETCH },
{ "letterbox", SDL_LOGICAL_PRESENTATION_LETTERBOX },
{ "overscan", SDL_LOGICAL_PRESENTATION_OVERSCAN },
{ "integer", SDL_LOGICAL_PRESENTATION_INTEGER_SCALE },
{ NULL, SDL_LOGICAL_PRESENTATION_DISABLED } /* fallback */
};
static JSValue logicalpresentation2js(JSContext *js,
SDL_RendererLogicalPresentation pres){
const pres_entry *it;
for(it = k_pres_table; it->name; ++it)
if(it->pres == pres) break;
return JS_NewString(js, it->name ? it->name : "disabled");
}
static SDL_RendererLogicalPresentation
js2SDL_LogicalPresentation(JSContext *js, JSValue v){
if(JS_IsUndefined(v)) return SDL_LOGICAL_PRESENTATION_DISABLED;
const char *s = JS_ToCString(js, v);
if(!s) return SDL_LOGICAL_PRESENTATION_DISABLED;
const pres_entry *it;
for(it = k_pres_table; it->name; ++it)
if(!strcmp(it->name, s)) break;
JS_FreeCString(js, s);
return it->pres;
}
JSC_CCALL(renderer_logical_size, JSC_CCALL(renderer_logical_size,
SDL_Renderer *r = js2renderer_ctx(js,self)->sdl; SDL_Renderer *r = js2renderer_ctx(js,self)->sdl;
HMM_Vec2 v = js2vec2(js,argv[0]); HMM_Vec2 v = js2vec2(js,argv[0]);
SDL_SetRenderLogicalPresentation(r,v.x,v.y,SDL_LOGICAL_PRESENTATION_INTEGER_SCALE); SDL_SetRenderLogicalPresentation(r,v.x,v.y,js2SDL_LogicalPresentation(js, argv[1]));
) )
JSC_CCALL(renderer_viewport, JSC_CCALL(renderer_viewport,
@@ -1663,7 +1694,7 @@ static const JSCFunctionListEntry js_renderer_ctx_funcs[] = {
MIST_FUNC_DEF(renderer, get_image, 1), MIST_FUNC_DEF(renderer, get_image, 1),
MIST_FUNC_DEF(renderer, scale, 1), MIST_FUNC_DEF(renderer, scale, 1),
MIST_FUNC_DEF(renderer, logical_size,1), MIST_FUNC_DEF(renderer, logical_size,2),
MIST_FUNC_DEF(renderer, viewport,1), MIST_FUNC_DEF(renderer, viewport,1),
MIST_FUNC_DEF(renderer, clip,1), MIST_FUNC_DEF(renderer, clip,1),
MIST_FUNC_DEF(renderer, vsync,1), MIST_FUNC_DEF(renderer, vsync,1),
@@ -1718,7 +1749,7 @@ static SDL_PixelFormat js2pixelformat(JSContext *js, JSValue v)
JS_FreeCString(js,s); JS_FreeCString(js,s);
return it->fmt; return it->fmt;
} }
typedef struct { const char *name; SDL_ScaleMode mode; } scale_entry; typedef struct { const char *name; SDL_ScaleMode mode; } scale_entry;
@@ -1894,7 +1925,8 @@ static const JSCFunctionListEntry js_SDL_Surface_funcs[] = {
JSC_CCALL(texture_mode, JSC_CCALL(texture_mode,
SDL_Texture *tex = js2SDL_Texture(js,self); SDL_Texture *tex = js2SDL_Texture(js,self);
SDL_SetTextureScaleMode(tex,js2number(js,argv[0])); SDL_ScaleMode mode = js2SDL_ScaleMode(js,argv[0]);
SDL_SetTextureScaleMode(tex,mode);
) )
static const JSCFunctionListEntry js_SDL_Texture_funcs[] = { static const JSCFunctionListEntry js_SDL_Texture_funcs[] = {