Files

2.6 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, example, tested, tests, test_file_path, file_path, params, output
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports example tested tests test_file_path file_path params output
sprite_batch function cpp gfx 0.1.0 impure sprite_batch_create(int cap=4096) -> SpriteBatch; sprite_batch_begin/draw/end Batched textured quad renderer sobre sokol_gfx. Begin/draw/end con auto-flush por atlas change o capacity full. Vertex layout pos+uv+color, alpha blending estandar, GLSL 330 / GLES 300. Issue 0072b runtime gamedev — base de plataformeros, top-down, UI sprites.
gamedev
gfx
sokol
sprite
batch
2d
sokol_setup_cpp_gfx
Rect_cpp_core
Color_cpp_core
false error_go_core
fn::gfx::SpriteBatch b = fn::gfx::sprite_batch_create(4096); // por frame, dentro de un sg_pass: fn::gfx::sprite_batch_begin(b, view_proj); fn::gfx::sprite_batch_draw(b, atlas_img, 1024, 1024, {0,0,32,32}, {100,100,32,32}, fn::math2d::Color::white()); fn::gfx::sprite_batch_draw(b, atlas_img, 1024, 1024, {32,0,32,32}, {200,100,32,32}, fn::math2d::Color::rgba(255,0,0)); fn::gfx::sprite_batch_end(b); false
cpp/functions/gfx/sprite_batch.cpp
name desc
cap Capacidad de quads por flush (CPU buffer). Default 4096 (~96 KB).
name desc
img sg_image atlas. Cambio de img = auto-flush.
name desc
src Rect en pixeles dentro del atlas (UV se calculan dividiendo por img_w/img_h).
name desc
dst Rect destino en coordenadas world (la matriz view-proj traduce a clip space).
name desc
tint Color multiplicativo. Default Color::white().
Quads renderizados via sg_draw cuando flush. Una sola draw call por atlas binding.

sprite_batch

Renderer batched de sprites 2D sobre sokol_gfx. Patron clasico:

  1. sprite_batch_create una vez (despues de sg_setup).
  2. Por frame, dentro de un sg_pass:
    • sprite_batch_begin(b, view_proj) — pasa la matriz view-projection del camera_2d.
    • sprite_batch_draw(...) por sprite. Auto-flush cuando cambia atlas o se llena.
    • sprite_batch_end(b) — flush final.

Alpha blending activado por defecto (premultiplicado o no — usar el atlas que tengas; el shader hace texture(u_tex, v_uv) * tint).

Sampler linear filter + clamp-to-edge. Para pixel art, crear sampler propio con SG_FILTER_NEAREST y bindearlo manualmente (override no soportado por ahora — sub-issue futuro si hace falta).

Performance: 1 draw call por atlas. 10K sprites @ 60 FPS sobre WebGL2 modesto. Cap por defecto 4096 quads/flush; subir si tu juego dibuja >4K sprites del mismo atlas.