fast sprite render

This commit is contained in:
2025-05-01 01:35:05 -05:00
parent f3031d6cd0
commit 600fbfd3b7
13 changed files with 188 additions and 54 deletions

View File

@@ -2883,7 +2883,8 @@ JSC_CCALL(renderer_rects,
// Should take a single struct with pos, color, uv, and indices arrays
JSC_CCALL(renderer_geometry,
SDL_Renderer *r = js2renderer_ctx(js,self)->sdl;
renderer_ctx *ctx = js2renderer_ctx(js,self);
SDL_Renderer *r = ctx->sdl;
JSValue pos = JS_GetPropertyStr(js,argv[1], "pos");
JSValue color = JS_GetPropertyStr(js,argv[1], "color");
JSValue uv = JS_GetPropertyStr(js,argv[1], "uv");
@@ -2902,8 +2903,11 @@ JSC_CCALL(renderer_geometry,
HMM_Vec2 *trans_pos = malloc(vertices*sizeof(HMM_Vec2));
memcpy(trans_pos,posdata, sizeof(HMM_Vec2)*vertices);
for (int i = 0; i < vertices; i++)
trans_pos[i] = HMM_MulM3V3(cam_mat, (HMM_Vec3){trans_pos[i].x, trans_pos[i].y, 1}).xy;
for (int i = 0; i < vertices; i++) {
SDL_FPoint p = renderer_world_to_screen(ctx, trans_pos[i]);
trans_pos[i].x = p.x;
trans_pos[i].y = p.y;
}
if (!SDL_RenderGeometryRaw(r, tex, trans_pos, pos_stride,colordata,color_stride,uvdata, uv_stride, vertices, idxdata, count, indices_stride))
ret = JS_ThrowReferenceError(js, "Error rendering geometry: %s",SDL_GetError());
@@ -2914,7 +2918,6 @@ JSC_CCALL(renderer_geometry,
JS_FreeValue(js,color);
JS_FreeValue(js,uv);
JS_FreeValue(js,indices);
printf("AMDET\n");
)
JSC_CCALL(renderer_logical_size,
@@ -2988,7 +2991,6 @@ JSC_CCALL(renderer_target,
// Given an array of sprites, make the necessary geometry
// A sprite is expected to have:
// transform: a transform encoding position and rotation. its scale is in pixels - so a scale of 1 means the image will draw only on a single pixel.
// image: a standard prosperon image of a surface, rect, and texture
// color: the color this sprite should be hued by
JSC_CCALL(renderer_make_sprite_mesh,
@@ -3003,7 +3005,6 @@ JSC_CCALL(renderer_make_sprite_mesh,
for (int i = 0; i < quads; i++) {
JSValue sub = JS_GetPropertyUint32(js,sprites,i);
JSValue jstransform = JS_GetProperty(js,sub,transform);
JSValue jssrc = JS_GetProperty(js,sub,src);
JSValue jscolor = JS_GetProperty(js,sub,color);
@@ -3034,7 +3035,6 @@ JSC_CCALL(renderer_make_sprite_mesh,
colordata[base+2] = color;
colordata[base+3] = color;
JS_FreeValue(js,jstransform);
JS_FreeValue(js,sub);
JS_FreeValue(js,jscolor);
JS_FreeValue(js,jssrc);