add texture mode for renderer
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-11 09:34:31 -05:00
parent ff2ee3d6db
commit 85ee724754
3 changed files with 45 additions and 23 deletions

View File

@@ -347,10 +347,8 @@ function software_fill_round_rect(rect, radius)
var rect_def = { var rect_def = {
thickness:1, thickness:1,
mode: 'fill',
color: Color.white, color: Color.white,
radius: 0, radius: 0
thickness:1
} }
draw.rectangle = function render_rectangle(rect, def, pipeline) { draw.rectangle = function render_rectangle(rect, def, pipeline) {
var opt = def ? {...rect_def, ...def} : rect_def var opt = def ? {...rect_def, ...def} : rect_def
@@ -390,18 +388,6 @@ draw.slice9 = function slice9(image, rect = [0,0], slice = 0, info = slice9_info
image = graphics.texture(image) image = graphics.texture(image)
render.slice9(image, rect, slice, slice9_info, pipeline); render.slice9(image, rect, slice, slice9_info, pipeline);
// var mesh = geometry.slice9(image.texture, rect, util.normalizeSpacing(slice), info)
// console.log(json.encode(mesh))
// render.geometry(image, mesh, pipeline)
/* render.queue({
type: 'geometry',
mesh,
image,
pipeline,
first_index:0,
num_indices:mesh.num_indices
})
*/
} }
draw.slice9[prosperon.DOC] = ` draw.slice9[prosperon.DOC] = `
:param image: An image object or string path to a texture. :param image: An image object or string path to a texture.
@@ -420,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

@@ -2894,7 +2894,7 @@ JSC_CCALL(renderer_rects,
/* single-rect path */ /* single-rect path */
rect w = js2rect(js, argv[0]); rect w = js2rect(js, argv[0]);
w = renderer_worldrect_to_screen(ctx, w); w = renderer_worldrect_to_screen(ctx, w);
if (!SDL_RenderFillRects(r, &w, 1)) if (!SDL_RenderFillRects(r, &w, 1))
return JS_ThrowReferenceError(js, "SDL_RenderFillRects: %s", SDL_GetError()); return JS_ThrowReferenceError(js, "SDL_RenderFillRects: %s", SDL_GetError());
) )
@@ -3005,10 +3005,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,
@@ -3202,7 +3233,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),
@@ -5708,7 +5739,8 @@ static const JSCFunctionListEntry js_SDL_Camera_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[] = {