diff --git a/scripts/modules/draw2d.js b/scripts/modules/draw2d.js index 8b6ca884..a4820f81 100644 --- a/scripts/modules/draw2d.js +++ b/scripts/modules/draw2d.js @@ -406,9 +406,10 @@ var image_info = { flip_x: false, flip_y: false, 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 (typeof image === "string") image = graphics.texture(image) diff --git a/scripts/modules/sdl_render.js b/scripts/modules/sdl_render.js index 118894c9..30dd36e0 100644 --- a/scripts/modules/sdl_render.js +++ b/scripts/modules/sdl_render.js @@ -28,8 +28,10 @@ render.initialize = function(config) url: "https://prosperon.dev" } - prosperon.window = prosperon.engine_start({width:500,height:500}) - context = prosperon.window.make_renderer("vulkan") + config.__proto__ = default_conf + 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) @@ -49,6 +51,7 @@ render.image = function(image, rect, rotation, anchor, shear, info) { // rect.width = image.rect_px.width; // rect.height = image.rect_px.height; + image.texture.mode(info.mode) context.texture(image.texture, image.rect_px, rect, rotation, anchor); } diff --git a/source/jsffi.c b/source/jsffi.c index c52d7205..38383cc3 100644 --- a/source/jsffi.c +++ b/source/jsffi.c @@ -1466,10 +1466,41 @@ JSC_CCALL(renderer_geometry2, 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, SDL_Renderer *r = js2renderer_ctx(js,self)->sdl; 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, @@ -1663,7 +1694,7 @@ static const JSCFunctionListEntry js_renderer_ctx_funcs[] = { MIST_FUNC_DEF(renderer, get_image, 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, clip,1), MIST_FUNC_DEF(renderer, vsync,1), @@ -1718,7 +1749,7 @@ static SDL_PixelFormat js2pixelformat(JSContext *js, JSValue v) JS_FreeCString(js,s); return it->fmt; -} +} 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, 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[] = {