gpu backend uniform binding
This commit is contained in:
@@ -13,11 +13,13 @@
|
||||
#define QJSCLASSGPUWRAPPER(WRAPPERTYPE, SDLTYPE) \
|
||||
typedef struct { \
|
||||
SDL_GPUDevice *device; \
|
||||
JSValue js_device; \
|
||||
SDL_##SDLTYPE *type; \
|
||||
} WRAPPERTYPE; \
|
||||
JSClassID js_SDL_##SDLTYPE##_id; \
|
||||
static void js_SDL_##SDLTYPE##_finalizer(JSRuntime *rt, JSValue val) { \
|
||||
WRAPPERTYPE *wrapper = JS_GetOpaque(val, js_SDL_##SDLTYPE##_id); \
|
||||
JS_FreeValueRT(rt, wrapper->js_device); \
|
||||
if (wrapper && wrapper->device && wrapper->type) \
|
||||
SDL_Release##SDLTYPE(wrapper->device, wrapper->type); \
|
||||
free(wrapper); \
|
||||
@@ -31,9 +33,10 @@ SDL_##SDLTYPE *js2SDL_##SDLTYPE(JSContext *js, JSValue val) { \
|
||||
WRAPPERTYPE *wrapper = JS_GetOpaque(val, js_SDL_##SDLTYPE##_id); \
|
||||
return wrapper ? wrapper->type : NULL; \
|
||||
} \
|
||||
JSValue SDL_##SDLTYPE##2js(JSContext *js, SDL_GPUDevice *device, SDL_##SDLTYPE *member) { \
|
||||
JSValue SDL_##SDLTYPE##2js(JSContext *js, JSValue device, SDL_##SDLTYPE *member) { \
|
||||
WRAPPERTYPE *wrapper = malloc(sizeof(WRAPPERTYPE)); \
|
||||
wrapper->device = device; \
|
||||
wrapper->js_device = JS_DupValue(js,device); \
|
||||
wrapper->device = js2SDL_GPUDevice(js, device); \
|
||||
wrapper->type = member; \
|
||||
JSValue j = JS_NewObjectClass(js, js_SDL_##SDLTYPE##_id); \
|
||||
JS_SetOpaque(j, wrapper); \
|
||||
@@ -719,7 +722,7 @@ static JSValue js_gpu_graphics_pipeline_constructor(JSContext *js, JSValueConst
|
||||
SDL_GPUGraphicsPipeline *pipeline = SDL_CreateGPUGraphicsPipeline(gpu, &info);
|
||||
if (!pipeline) return JS_ThrowInternalError(js, "Failed to create GPU pipeline: %s", SDL_GetError());
|
||||
|
||||
return SDL_GPUGraphicsPipeline2js(js, gpu, pipeline);
|
||||
return SDL_GPUGraphicsPipeline2js(js, argv[0], pipeline);
|
||||
}
|
||||
|
||||
// Standalone sampler constructor: new sdl_gpu.sampler(device, config)
|
||||
@@ -750,7 +753,7 @@ static JSValue js_gpu_sampler_constructor(JSContext *js, JSValueConst self, int
|
||||
SDL_GPUSampler *sdl_sampler = SDL_CreateGPUSampler(gpu, &info);
|
||||
if (!sdl_sampler) return JS_ThrowInternalError(js, "Failed to create GPU sampler: %s", SDL_GetError());
|
||||
|
||||
return SDL_GPUSampler2js(js, gpu, sdl_sampler);
|
||||
return SDL_GPUSampler2js(js, argv[0], sdl_sampler);
|
||||
}
|
||||
|
||||
JSC_CCALL(gpu_driver,
|
||||
@@ -807,7 +810,7 @@ static JSValue js_gpu_shader_constructor(JSContext *js, JSValueConst self, int a
|
||||
if (!shader)
|
||||
return JS_ThrowReferenceError(js, "Unable to create shader: %s", SDL_GetError());
|
||||
|
||||
return SDL_GPUShader2js(js, gpu, shader);
|
||||
return SDL_GPUShader2js(js, argv[0], shader);
|
||||
}
|
||||
|
||||
JSC_CCALL(gpu_acquire_cmd_buffer,
|
||||
@@ -879,7 +882,7 @@ static JSValue js_gpu_compute_pipeline_constructor(JSContext *js, JSValueConst s
|
||||
SDL_GPUComputePipeline *pipeline = SDL_CreateGPUComputePipeline(gpu, &info);
|
||||
JS_FreeCString(js,info.entrypoint);
|
||||
if (!pipeline) return JS_ThrowReferenceError(js,"Could not create compute pipeline: %s", SDL_GetError());
|
||||
return SDL_GPUComputePipeline2js(js, gpu, pipeline);
|
||||
return SDL_GPUComputePipeline2js(js, argv[0], pipeline);
|
||||
}
|
||||
|
||||
// Standalone buffer constructor: new sdl_gpu.buffer(device, config)
|
||||
@@ -915,7 +918,7 @@ static JSValue js_gpu_buffer_constructor(JSContext *js, JSValueConst self, int a
|
||||
SDL_GPUBuffer *buffer = SDL_CreateGPUBuffer(gpu, &info);
|
||||
if (!buffer) return JS_ThrowReferenceError(js, "Unable to create buffer: %s", SDL_GetError());
|
||||
|
||||
return SDL_GPUBuffer2js(js, gpu, buffer);
|
||||
return SDL_GPUBuffer2js(js, argv[0], buffer);
|
||||
}
|
||||
|
||||
static JSValue js_gpu_transfer_buffer_constructor(JSContext *js, JSValueConst self, int argc, JSValueConst *argv) {
|
||||
@@ -936,7 +939,7 @@ static JSValue js_gpu_transfer_buffer_constructor(JSContext *js, JSValueConst se
|
||||
SDL_GPUTransferBuffer *buffer = SDL_CreateGPUTransferBuffer(gpu, &info);
|
||||
if (!buffer) return JS_ThrowReferenceError(js, "Unable to create transfer buffer: %s", SDL_GetError());
|
||||
|
||||
return SDL_GPUTransferBuffer2js(js, gpu, buffer);
|
||||
return SDL_GPUTransferBuffer2js(js, argv[0], buffer);
|
||||
}
|
||||
|
||||
// Standalone texture constructor: new sdl_gpu.texture(device, config)
|
||||
@@ -974,7 +977,7 @@ static JSValue js_gpu_texture_constructor(JSContext *js, JSValueConst self, int
|
||||
SDL_GPUTexture *tex = SDL_CreateGPUTexture(gpu, &info);
|
||||
if (!tex) return JS_ThrowReferenceError(js, "Unable to create texture: %s", SDL_GetError());
|
||||
|
||||
JSValue jstex = SDL_GPUTexture2js(js, gpu, tex);
|
||||
JSValue jstex = SDL_GPUTexture2js(js, argv[0], tex);
|
||||
JS_SetPropertyStr(js, jstex, "width", number2js(js, info.width));
|
||||
JS_SetPropertyStr(js, jstex, "height", number2js(js, info.height));
|
||||
JS_SetPropertyStr(js, jstex, "dim", vec22js(js, (HMM_Vec2){info.width, info.height}));
|
||||
|
||||
@@ -789,22 +789,6 @@ JSValue JS_ParseJSON2(JSContext *ctx, const char *buf, size_t buf_len,
|
||||
JSValue JS_JSONStringify(JSContext *ctx, JSValueConst obj,
|
||||
JSValueConst replacer, JSValueConst space0);
|
||||
|
||||
typedef enum JSPromiseStateEnum {
|
||||
JS_PROMISE_PENDING,
|
||||
JS_PROMISE_FULFILLED,
|
||||
JS_PROMISE_REJECTED,
|
||||
} JSPromiseStateEnum;
|
||||
|
||||
JSValue JS_NewPromiseCapability(JSContext *ctx, JSValue *resolving_funcs);
|
||||
JSPromiseStateEnum JS_PromiseState(JSContext *ctx, JSValue promise);
|
||||
JSValue JS_PromiseResult(JSContext *ctx, JSValue promise);
|
||||
|
||||
/* is_handled = TRUE means that the rejection is handled */
|
||||
typedef void JSHostPromiseRejectionTracker(JSContext *ctx, JSValueConst promise,
|
||||
JSValueConst reason,
|
||||
JS_BOOL is_handled, void *opaque);
|
||||
void JS_SetHostPromiseRejectionTracker(JSRuntime *rt, JSHostPromiseRejectionTracker *cb, void *opaque);
|
||||
|
||||
/* return != 0 if the JS code needs to be interrupted */
|
||||
typedef int JSInterruptHandler(JSRuntime *rt, void *opaque);
|
||||
void JS_SetInterruptHandler(JSRuntime *rt, JSInterruptHandler *cb, void *opaque);
|
||||
|
||||
Reference in New Issue
Block a user