Merge branch 'js-rm-ta' into js-rm-modules
This commit is contained in:
@@ -170,33 +170,6 @@ typedef struct texture_vertex {
|
|||||||
uint8_t r, g, b,a;
|
uint8_t r, g, b,a;
|
||||||
} texture_vertex;
|
} texture_vertex;
|
||||||
|
|
||||||
|
|
||||||
static inline size_t typed_array_bytes(JSTypedArrayEnum type) {
|
|
||||||
switch(type) {
|
|
||||||
case JS_TYPED_ARRAY_UINT8C:
|
|
||||||
case JS_TYPED_ARRAY_INT8:
|
|
||||||
case JS_TYPED_ARRAY_UINT8:
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
case JS_TYPED_ARRAY_INT16:
|
|
||||||
case JS_TYPED_ARRAY_UINT16:
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
case JS_TYPED_ARRAY_INT32:
|
|
||||||
case JS_TYPED_ARRAY_UINT32:
|
|
||||||
case JS_TYPED_ARRAY_FLOAT32:
|
|
||||||
return 4;
|
|
||||||
|
|
||||||
case JS_TYPED_ARRAY_BIG_INT64:
|
|
||||||
case JS_TYPED_ARRAY_BIG_UINT64:
|
|
||||||
case JS_TYPED_ARRAY_FLOAT64:
|
|
||||||
return 8;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return 0; // Return 0 for unknown types
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define JS_GETNUM(JS,VAL,I,TO,TYPE) { \
|
#define JS_GETNUM(JS,VAL,I,TO,TYPE) { \
|
||||||
JSValue val = JS_GetPropertyUint32(JS,VAL,I); \
|
JSValue val = JS_GetPropertyUint32(JS,VAL,I); \
|
||||||
TO = js2##TYPE(JS, val); \
|
TO = js2##TYPE(JS, val); \
|
||||||
@@ -274,23 +247,25 @@ JSValue make_gpu_buffer(JSContext *js, void *data, size_t size, int type, int el
|
|||||||
tstack[2] = JS_UNDEFINED;
|
tstack[2] = JS_UNDEFINED;
|
||||||
// TODO: always copying; implement "takeover"
|
// TODO: always copying; implement "takeover"
|
||||||
tstack[0] = js_new_blob_stoned_copy(js,data,size);//, make_gpu_buffer, NULL, 1);
|
tstack[0] = js_new_blob_stoned_copy(js,data,size);//, make_gpu_buffer, NULL, 1);
|
||||||
JSValue ret = JS_NewTypedArray(js, 3, tstack, type);
|
// JSValue ret = JS_NewTypedArray(js, 3, tstack, type);
|
||||||
JS_SetPropertyStr(js,ret,"stride", number2js(js,typed_array_bytes(type)*elements));
|
// JS_SetPropertyStr(js,ret,"stride", number2js(js,typed_array_bytes(type)*elements));
|
||||||
JS_SetPropertyStr(js,ret,"elen", number2js(js,typed_array_bytes(type)));
|
// JS_SetPropertyStr(js,ret,"elen", number2js(js,typed_array_bytes(type)));
|
||||||
JS_SetPropertyStr(js,ret,"index", JS_NewBool(js,index));
|
// JS_SetPropertyStr(js,ret,"index", JS_NewBool(js,index));
|
||||||
JS_FreeValue(js,tstack[0]);
|
// JS_FreeValue(js,tstack[0]);
|
||||||
return ret;
|
// return ret;
|
||||||
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *get_gpu_buffer(JSContext *js, JSValue argv, size_t *stride, size_t *size)
|
void *get_gpu_buffer(JSContext *js, JSValue argv, size_t *stride, size_t *size)
|
||||||
{
|
{
|
||||||
size_t o, len, bytes, msize;
|
return NULL;
|
||||||
|
/* size_t o, len, bytes, msize;
|
||||||
JSValue buf = JS_GetTypedArrayBuffer(js, argv, &o, &len, &bytes);
|
JSValue buf = JS_GetTypedArrayBuffer(js, argv, &o, &len, &bytes);
|
||||||
void *data = js_get_blob_data(js, &msize, buf);
|
void *data = js_get_blob_data(js, &msize, buf);
|
||||||
JS_FreeValue(js,buf);
|
JS_FreeValue(js,buf);
|
||||||
if (stride) *stride = js_getnum_str(js, argv, "stride");
|
if (stride) *stride = js_getnum_str(js, argv, "stride");
|
||||||
if (size) *size = msize;
|
if (size) *size = msize;
|
||||||
return data;
|
return data;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
JSValue make_quad_indices_buffer(JSContext *js, int quads)
|
JSValue make_quad_indices_buffer(JSContext *js, int quads)
|
||||||
@@ -314,7 +289,7 @@ JSValue make_quad_indices_buffer(JSContext *js, int quads)
|
|||||||
if (!JS_IsUndefined(rt->idx_buffer))
|
if (!JS_IsUndefined(rt->idx_buffer))
|
||||||
JS_FreeValue(js,rt->idx_buffer);
|
JS_FreeValue(js,rt->idx_buffer);
|
||||||
|
|
||||||
rt->idx_buffer = make_gpu_buffer(js,indices, sizeof(*indices)*count, JS_TYPED_ARRAY_UINT16, 1,0,1);
|
// rt->idx_buffer = make_gpu_buffer(js,indices, sizeof(*indices)*count, JS_TYPED_ARRAY_UINT16, 1,0,1);
|
||||||
rt->idx_count = count;
|
rt->idx_count = count;
|
||||||
return JS_DupValue(js,rt->idx_buffer);
|
return JS_DupValue(js,rt->idx_buffer);
|
||||||
}
|
}
|
||||||
@@ -333,9 +308,9 @@ JSValue quads_to_mesh(JSContext *js, text_vert *buffer)
|
|||||||
color[i] = buffer[i].color;
|
color[i] = buffer[i].color;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSValue jspos = make_gpu_buffer(js, pos, sizeof(HMM_Vec2)*arrlen(buffer), JS_TYPED_ARRAY_FLOAT32, 2,0,0);
|
JSValue jspos = make_gpu_buffer(js, pos, sizeof(HMM_Vec2)*arrlen(buffer), 0, 2,0,0);
|
||||||
JSValue jsuv = make_gpu_buffer(js, uv, sizeof(HMM_Vec2)*arrlen(buffer), JS_TYPED_ARRAY_FLOAT32, 2,0,0);
|
JSValue jsuv = make_gpu_buffer(js, uv, sizeof(HMM_Vec2)*arrlen(buffer), 0, 2,0,0);
|
||||||
JSValue jscolor = make_gpu_buffer(js, color, sizeof(HMM_Vec4)*arrlen(buffer), JS_TYPED_ARRAY_FLOAT32, 4,0,0);
|
JSValue jscolor = make_gpu_buffer(js, color, sizeof(HMM_Vec4)*arrlen(buffer), 0, 4,0,0);
|
||||||
|
|
||||||
size_t quads = verts/4;
|
size_t quads = verts/4;
|
||||||
size_t count = verts/2*3;
|
size_t count = verts/2*3;
|
||||||
@@ -1239,10 +1214,12 @@ JSValue make_color_buffer(JSContext *js, colorf c, int verts)
|
|||||||
for (int i = 0; i < verts; i++)
|
for (int i = 0; i < verts; i++)
|
||||||
colordata[i] = c;
|
colordata[i] = c;
|
||||||
|
|
||||||
return make_gpu_buffer(js, colordata, sizeof(*colordata)*verts, JS_TYPED_ARRAY_FLOAT32, 4, 0, 0);
|
return make_gpu_buffer(js, colordata, sizeof(*colordata)*verts, 0, 4, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSC_CCALL(os_make_line_prim,
|
JSC_CCALL(os_make_line_prim,
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
/*
|
||||||
JSValue prim = JS_NewObject(js);
|
JSValue prim = JS_NewObject(js);
|
||||||
HMM_Vec2 *v = js2cpvec2arr(js,argv[0]);
|
HMM_Vec2 *v = js2cpvec2arr(js,argv[0]);
|
||||||
|
|
||||||
@@ -1262,7 +1239,7 @@ JSC_CCALL(os_make_line_prim,
|
|||||||
.closed = JS_ToBool(js,argv[3])
|
.closed = JS_ToBool(js,argv[3])
|
||||||
});
|
});
|
||||||
|
|
||||||
JS_SetPropertyStr(js, prim, "pos", make_gpu_buffer(js,m->positions,sizeof(*m->positions)*m->num_vertices, JS_TYPED_ARRAY_FLOAT32, 2,1,0));
|
JS_SetPropertyStr(js, prim, "pos", make_gpu_buffer(js,m->positions,sizeof(*m->positions)*m->num_vertices, 0, 2,1,0));
|
||||||
|
|
||||||
JS_SetPropertyStr(js, prim, "indices", make_gpu_buffer(js,m->triangle_indices,sizeof(*m->triangle_indices)*m->num_triangles*3, JS_TYPED_ARRAY_UINT32, 1,1,1));
|
JS_SetPropertyStr(js, prim, "indices", make_gpu_buffer(js,m->triangle_indices,sizeof(*m->triangle_indices)*m->num_triangles*3, JS_TYPED_ARRAY_UINT32, 1,1,1));
|
||||||
|
|
||||||
@@ -1272,7 +1249,7 @@ JSC_CCALL(os_make_line_prim,
|
|||||||
uv[i*2+1] = m->annotations[i].v_across_curve;
|
uv[i*2+1] = m->annotations[i].v_across_curve;
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_SetPropertyStr(js, prim, "uv", make_gpu_buffer(js, uv, sizeof(uv), JS_TYPED_ARRAY_FLOAT32,2,1,0));
|
JS_SetPropertyStr(js, prim, "uv", make_gpu_buffer(js, uv, sizeof(uv), 0,2,1,0));
|
||||||
JS_SetPropertyStr(js,prim,"vertices", number2js(js,m->num_vertices));
|
JS_SetPropertyStr(js,prim,"vertices", number2js(js,m->num_vertices));
|
||||||
JS_SetPropertyStr(js,prim,"color",make_color_buffer(js,js2color(js,argv[4]), m->num_vertices));
|
JS_SetPropertyStr(js,prim,"color",make_color_buffer(js,js2color(js,argv[4]), m->num_vertices));
|
||||||
JS_SetPropertyStr(js,prim,"num_indices", number2js(js,m->num_triangles*3));
|
JS_SetPropertyStr(js,prim,"num_indices", number2js(js,m->num_triangles*3));
|
||||||
@@ -1281,6 +1258,7 @@ JSC_CCALL(os_make_line_prim,
|
|||||||
parsl_destroy_context(par_ctx);
|
parsl_destroy_context(par_ctx);
|
||||||
|
|
||||||
return prim;
|
return prim;
|
||||||
|
*/
|
||||||
)
|
)
|
||||||
|
|
||||||
static void render_frame(plm_t *mpeg, plm_frame_t *frame, datastream *ds) {
|
static void render_frame(plm_t *mpeg, plm_frame_t *frame, datastream *ds) {
|
||||||
|
|||||||
@@ -529,9 +529,9 @@ JSC_CCALL(gpu_make_sprite_mesh,
|
|||||||
size_t uv_size = sizeof(*uvdata)*verts;
|
size_t uv_size = sizeof(*uvdata)*verts;
|
||||||
size_t color_size = sizeof(*colordata)*verts;
|
size_t color_size = sizeof(*colordata)*verts;
|
||||||
|
|
||||||
BufferCheckResult pos_chk = get_or_extend_buffer(js, old_mesh, "pos", pos_size, JS_TYPED_ARRAY_FLOAT32, 2, 1, 0);
|
BufferCheckResult pos_chk = get_or_extend_buffer(js, old_mesh, "pos", pos_size, 0, 2, 1, 0);
|
||||||
BufferCheckResult uv_chk = get_or_extend_buffer(js, old_mesh, "uv", uv_size, JS_TYPED_ARRAY_FLOAT32, 2, 1, 0);
|
BufferCheckResult uv_chk = get_or_extend_buffer(js, old_mesh, "uv", uv_size, 0, 2, 1, 0);
|
||||||
BufferCheckResult color_chk = get_or_extend_buffer(js, old_mesh, "color", color_size, JS_TYPED_ARRAY_FLOAT32, 4, 1, 0);
|
BufferCheckResult color_chk = get_or_extend_buffer(js, old_mesh, "color", color_size, 0, 4, 1, 0);
|
||||||
|
|
||||||
int need_new_all = pos_chk.need_new || uv_chk.need_new || color_chk.need_new;
|
int need_new_all = pos_chk.need_new || uv_chk.need_new || color_chk.need_new;
|
||||||
|
|
||||||
@@ -539,9 +539,9 @@ JSC_CCALL(gpu_make_sprite_mesh,
|
|||||||
|
|
||||||
if (need_new_all) {
|
if (need_new_all) {
|
||||||
// Create all new buffers
|
// Create all new buffers
|
||||||
JSValue new_pos = make_gpu_buffer(js, posdata, pos_size, JS_TYPED_ARRAY_FLOAT32, 2, 1,0);
|
JSValue new_pos = make_gpu_buffer(js, posdata, pos_size, 0, 2, 1,0);
|
||||||
JSValue new_uv = make_gpu_buffer(js, uvdata, uv_size, JS_TYPED_ARRAY_FLOAT32, 2, 1,0);
|
JSValue new_uv = make_gpu_buffer(js, uvdata, uv_size, 0, 2, 1,0);
|
||||||
JSValue new_color = make_gpu_buffer(js, colordata, color_size, JS_TYPED_ARRAY_FLOAT32, 0, 1,0);
|
JSValue new_color = make_gpu_buffer(js, colordata, color_size, 0, 0, 1,0);
|
||||||
|
|
||||||
JS_SetPropertyStr(js, ret, "pos", new_pos);
|
JS_SetPropertyStr(js, ret, "pos", new_pos);
|
||||||
JS_SetPropertyStr(js, ret, "uv", new_uv);
|
JS_SetPropertyStr(js, ret, "uv", new_uv);
|
||||||
@@ -603,9 +603,9 @@ struct quad_buffers quad_buffers_new(int verts)
|
|||||||
|
|
||||||
JSValue quadbuffers_to_mesh(JSContext *js, struct quad_buffers buffers)
|
JSValue quadbuffers_to_mesh(JSContext *js, struct quad_buffers buffers)
|
||||||
{
|
{
|
||||||
JSValue jspos = make_gpu_buffer(js, buffers.pos, sizeof(HMM_Vec2)*buffers.verts, JS_TYPED_ARRAY_FLOAT32, 2, 0, 0);
|
JSValue jspos = make_gpu_buffer(js, buffers.pos, sizeof(HMM_Vec2)*buffers.verts, 0, 2, 0, 0);
|
||||||
JSValue jsuv = make_gpu_buffer(js, buffers.uv, sizeof(HMM_Vec2)*buffers.verts, JS_TYPED_ARRAY_FLOAT32, 2,0,0);
|
JSValue jsuv = make_gpu_buffer(js, buffers.uv, sizeof(HMM_Vec2)*buffers.verts, 0, 2,0,0);
|
||||||
JSValue jscolor = make_gpu_buffer(js, buffers.color, sizeof(HMM_Vec4)*buffers.verts, JS_TYPED_ARRAY_FLOAT32, 4,0,0);
|
JSValue jscolor = make_gpu_buffer(js, buffers.color, sizeof(HMM_Vec4)*buffers.verts, 0, 4,0,0);
|
||||||
|
|
||||||
size_t quads = buffers.verts/4;
|
size_t quads = buffers.verts/4;
|
||||||
size_t count = buffers.verts/2*3;
|
size_t count = buffers.verts/2*3;
|
||||||
|
|||||||
@@ -166,10 +166,10 @@ static JSValue js_miniz_decompress(JSContext *js,
|
|||||||
JSValue ret;
|
JSValue ret;
|
||||||
int asString = (argc > 1) && JS_ToBool(js, argv[1]);
|
int asString = (argc > 1) && JS_ToBool(js, argv[1]);
|
||||||
|
|
||||||
if (asString)
|
// if (asString)
|
||||||
ret = JS_NewStringLen(js, (const char *)out_ptr, out_len);
|
ret = JS_NewStringLen(js, (const char *)out_ptr, out_len);
|
||||||
else
|
// else
|
||||||
ret = JS_NewArrayBufferCopy(js, out_ptr, out_len);
|
// ret = JS_NewArrayBufferCopy(js, out_ptr, out_len);
|
||||||
|
|
||||||
#ifdef MZ_FREE
|
#ifdef MZ_FREE
|
||||||
MZ_FREE(out_ptr);
|
MZ_FREE(out_ptr);
|
||||||
|
|||||||
3809
source/quickjs.c
3809
source/quickjs.c
File diff suppressed because it is too large
Load Diff
@@ -400,7 +400,7 @@ void JS_AddIntrinsicRegExp(JSContext *ctx);
|
|||||||
void JS_AddIntrinsicJSON(JSContext *ctx);
|
void JS_AddIntrinsicJSON(JSContext *ctx);
|
||||||
void JS_AddIntrinsicProxy(JSContext *ctx);
|
void JS_AddIntrinsicProxy(JSContext *ctx);
|
||||||
void JS_AddIntrinsicMapSet(JSContext *ctx);
|
void JS_AddIntrinsicMapSet(JSContext *ctx);
|
||||||
void JS_AddIntrinsicTypedArrays(JSContext *ctx);
|
void JS_AddIntrinsicWeakRef(JSContext *ctx);
|
||||||
|
|
||||||
JSValue js_string_codePointRange(JSContext *ctx, JSValueConst this_val,
|
JSValue js_string_codePointRange(JSContext *ctx, JSValueConst this_val,
|
||||||
int argc, JSValueConst *argv);
|
int argc, JSValueConst *argv);
|
||||||
@@ -853,44 +853,6 @@ JSValue JS_ParseJSON2(JSContext *ctx, const char *buf, size_t buf_len,
|
|||||||
JSValue JS_JSONStringify(JSContext *ctx, JSValueConst obj,
|
JSValue JS_JSONStringify(JSContext *ctx, JSValueConst obj,
|
||||||
JSValueConst replacer, JSValueConst space0);
|
JSValueConst replacer, JSValueConst space0);
|
||||||
|
|
||||||
typedef void JSFreeArrayBufferDataFunc(JSRuntime *rt, void *opaque, void *ptr);
|
|
||||||
JSValue JS_NewArrayBuffer(JSContext *ctx, uint8_t *buf, size_t len,
|
|
||||||
JSFreeArrayBufferDataFunc *free_func, void *opaque,
|
|
||||||
JS_BOOL is_shared);
|
|
||||||
JSValue JS_NewArrayBufferCopy(JSContext *ctx, const uint8_t *buf, size_t len);
|
|
||||||
void JS_DetachArrayBuffer(JSContext *ctx, JSValueConst obj);
|
|
||||||
uint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValueConst obj);
|
|
||||||
|
|
||||||
typedef enum JSTypedArrayEnum {
|
|
||||||
JS_TYPED_ARRAY_UINT8C = 0,
|
|
||||||
JS_TYPED_ARRAY_INT8,
|
|
||||||
JS_TYPED_ARRAY_UINT8,
|
|
||||||
JS_TYPED_ARRAY_INT16,
|
|
||||||
JS_TYPED_ARRAY_UINT16,
|
|
||||||
JS_TYPED_ARRAY_INT32,
|
|
||||||
JS_TYPED_ARRAY_UINT32,
|
|
||||||
JS_TYPED_ARRAY_BIG_INT64,
|
|
||||||
JS_TYPED_ARRAY_BIG_UINT64,
|
|
||||||
JS_TYPED_ARRAY_FLOAT16,
|
|
||||||
JS_TYPED_ARRAY_FLOAT32,
|
|
||||||
JS_TYPED_ARRAY_FLOAT64,
|
|
||||||
} JSTypedArrayEnum;
|
|
||||||
|
|
||||||
JSValue JS_NewTypedArray(JSContext *ctx, int argc, JSValueConst *argv,
|
|
||||||
JSTypedArrayEnum array_type);
|
|
||||||
JSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValueConst obj,
|
|
||||||
size_t *pbyte_offset,
|
|
||||||
size_t *pbyte_length,
|
|
||||||
size_t *pbytes_per_element);
|
|
||||||
typedef struct {
|
|
||||||
void *(*sab_alloc)(void *opaque, size_t size);
|
|
||||||
void (*sab_free)(void *opaque, void *ptr);
|
|
||||||
void (*sab_dup)(void *opaque, void *ptr);
|
|
||||||
void *sab_opaque;
|
|
||||||
} JSSharedArrayBufferFunctions;
|
|
||||||
void JS_SetSharedArrayBufferFunctions(JSRuntime *rt,
|
|
||||||
const JSSharedArrayBufferFunctions *sf);
|
|
||||||
|
|
||||||
typedef enum JSPromiseStateEnum {
|
typedef enum JSPromiseStateEnum {
|
||||||
JS_PROMISE_PENDING,
|
JS_PROMISE_PENDING,
|
||||||
JS_PROMISE_FULFILLED,
|
JS_PROMISE_FULFILLED,
|
||||||
@@ -910,8 +872,6 @@ void JS_SetHostPromiseRejectionTracker(JSRuntime *rt, JSHostPromiseRejectionTrac
|
|||||||
/* return != 0 if the JS code needs to be interrupted */
|
/* return != 0 if the JS code needs to be interrupted */
|
||||||
typedef int JSInterruptHandler(JSRuntime *rt, void *opaque);
|
typedef int JSInterruptHandler(JSRuntime *rt, void *opaque);
|
||||||
void JS_SetInterruptHandler(JSRuntime *rt, JSInterruptHandler *cb, void *opaque);
|
void JS_SetInterruptHandler(JSRuntime *rt, JSInterruptHandler *cb, void *opaque);
|
||||||
/* if can_block is TRUE, Atomics.wait() can be used */
|
|
||||||
void JS_SetCanBlock(JSRuntime *rt, JS_BOOL can_block);
|
|
||||||
/* select which debug info is stripped from the compiled code */
|
/* select which debug info is stripped from the compiled code */
|
||||||
#define JS_STRIP_SOURCE (1 << 0) /* strip source code */
|
#define JS_STRIP_SOURCE (1 << 0) /* strip source code */
|
||||||
#define JS_STRIP_DEBUG (1 << 1) /* strip all debug info including source code */
|
#define JS_STRIP_DEBUG (1 << 1) /* strip all debug info including source code */
|
||||||
|
|||||||
Reference in New Issue
Block a user