This commit is contained in:
2025-12-12 17:27:33 -06:00
parent c116f4665e
commit 20b7a7ef90
2 changed files with 63 additions and 7 deletions

View File

@@ -13,7 +13,7 @@ var render = use('render')
var surface = use('surface')
var events = use('events')
var keyboard = use('keyboard')
var png = use('gitea.pockle.world/john/cell-image/png')
var png = use('/Users/john/work/cell-image/png')
var time = use('time')
// Create window

68
gpu.c
View File

@@ -438,6 +438,8 @@ JS2ENUM(SDL_GPUTextureFormat)
SDL_GPUColorTargetBlendState js2SDL_GPUColorTargetBlendState(JSContext *js, JSValue v)
{
SDL_GPUColorTargetBlendState state = {0};
if (!JS_IsObject(v))
return state;
JS_GETPROP(js,state.src_color_blendfactor,v,src_rgb,SDL_GPUBlendFactor);
JS_GETPROP(js,state.dst_color_blendfactor,v,dst_rgb,SDL_GPUBlendFactor);
JS_GETPROP(js,state.src_alpha_blendfactor,v,src_alpha,SDL_GPUBlendFactor);
@@ -522,6 +524,9 @@ SDL_GPUStencilOpState js2SDL_GPUStencilOpState(JSContext *js, JSValue v)
SDL_GPUStencilOpState state;
memset(&state, 0, sizeof(state));
if (!JS_IsObject(v))
return state;
JSValue compare_val = JS_GetPropertyStr(js, v, "compare");
if(!JS_IsNull(compare_val)) state.compare_op = js2SDL_GPUCompareOp(js, compare_val);
JS_FreeValue(js, compare_val);
@@ -1352,18 +1357,69 @@ JSC_CCALL(cmd_swapchain_pass,
if (swapchainTexture == NULL) {
return JS_ThrowReferenceError(js, "Failed to acquire swapchain texture");
}
SDL_GPUColorTargetInfo colorTargetInfo = { 0 };
if (argc > 1 && JS_IsObject(argv[1])) {
JSValue passObj = argv[1];
JSValue colorTargetsVal = JS_GetPropertyStr(js, passObj, "color_targets");
if (!JS_IsArray(js, colorTargetsVal)) {
JS_FreeValue(js, colorTargetsVal);
return JS_ThrowTypeError(js, "swapchain_pass: color_targets must be an array");
}
uint32_t colorCount = JS_ArrayLength(js, colorTargetsVal);
if (colorCount != 1) {
JS_FreeValue(js, colorTargetsVal);
return JS_ThrowTypeError(js, "swapchain_pass: only 1 color target is supported");
}
JSValue ctargetVal = JS_GetPropertyUint32(js, colorTargetsVal, 0);
SDL_GPUColorTargetInfo colorTargetInfo = js2SDL_GPUColorTargetInfo(js, ctargetVal);
JS_FreeValue(js, ctargetVal);
JS_FreeValue(js, colorTargetsVal);
colorTargetInfo.texture = swapchainTexture;
SDL_GPUDepthStencilTargetInfo depthtar;
int has_depth = 0;
JSValue depthval = JS_GetPropertyStr(js, passObj, "depth_stencil");
if (JS_IsObject(depthval)) {
has_depth = 1;
JS_GETPROP(js, depthtar.texture, depthval, texture, SDL_GPUTexture)
JS_GETPROP(js, depthtar.load_op, depthval, load, SDL_GPULoadOp)
JS_GETPROP(js, depthtar.store_op, depthval, store, SDL_GPUStoreOp)
JS_GETPROP(js, depthtar.stencil_load_op, depthval, stencil_load, SDL_GPULoadOp)
JS_GETPROP(js, depthtar.stencil_store_op, depthval, stencil_store, SDL_GPUStoreOp)
JS_GETPROP(js, depthtar.clear_depth, depthval, clear, number)
JS_GETPROP(js, depthtar.clear_stencil, depthval, clear_stencil, number)
}
JS_FreeValue(js, depthval);
SDL_GPURenderPass* renderPass = SDL_BeginGPURenderPass(
cmdbuf,
&colorTargetInfo,
1,
has_depth ? &depthtar : NULL
);
if (!renderPass) {
return JS_ThrowReferenceError(js, "Failed to begin render pass: %s", SDL_GetError());
}
return SDL_GPURenderPass2js(js, renderPass);
}
SDL_GPUColorTargetInfo colorTargetInfo = {0};
colorTargetInfo.texture = swapchainTexture;
colorTargetInfo.clear_color = (SDL_FColor){ 0.0f, 0.0f, 0.0f, 1.0f };
colorTargetInfo.clear_color = (SDL_FColor){0.0f, 0.0f, 0.0f, 1.0f};
colorTargetInfo.load_op = SDL_GPU_LOADOP_CLEAR;
colorTargetInfo.store_op = SDL_GPU_STOREOP_STORE;
SDL_GPURenderPass* renderPass = SDL_BeginGPURenderPass(cmdbuf, &colorTargetInfo, 1, NULL);
if (!renderPass) {
return JS_ThrowReferenceError(js, "Failed to begin render pass: %s", SDL_GetError());
}
return SDL_GPURenderPass2js(js, renderPass);
)
@@ -1414,7 +1470,7 @@ static const JSCFunctionListEntry js_SDL_GPUCommandBuffer_funcs[] = {
MIST_FUNC_DEF(cmd, pop_debug_group, 0),
MIST_FUNC_DEF(cmd, debug_label, 1),
MIST_FUNC_DEF(cmd, blit, 1),
MIST_FUNC_DEF(cmd, swapchain_pass, 1),
MIST_FUNC_DEF(cmd, swapchain_pass, 2),
};
JSC_CCALL(copypass_end,