Files
fn_registry/cpp/functions/gfx/mesh_gpu.md
T
egutierrez fd5787c55f chore: auto-commit (43 archivos)
- .mcp.json
- bash/functions/infra/write_mcp_jupyter_config.md
- bash/functions/infra/write_mcp_jupyter_config.sh
- cpp/CMakeLists.txt
- cpp/apps/chart_demo
- cpp/apps/shaders_lab
- cpp/functions/gfx/gl_framebuffer.cpp
- cpp/functions/gfx/gl_framebuffer.h
- cpp/functions/gfx/gl_framebuffer.md
- cpp/functions/gfx/mesh_gpu.md
- ...

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-30 17:28:47 +02:00

2.1 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, tested, tests, test_file_path, file_path, framework, params, output
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports tested tests test_file_path file_path framework params output
mesh_gpu function cpp gfx 1.0.0 impure MeshGpu mesh_gpu_upload(const Mesh&); void mesh_gpu_destroy(MeshGpu&) Sube un Mesh CPU a OpenGL como VAO + VBO interleaved (pos.xyz, normal.xyz) + EBO uint32. Layout: location 0 = a_pos vec3, location 1 = a_normal vec3, stride 6 floats.
opengl
mesh
vao
vbo
ebo
gpu
gfx
mesh-3d
gl_loader_cpp_gfx
mesh_obj_load_cpp_gfx
false error_go_core
GL/gl.h
GL/glext.h
false
cpp/functions/gfx/mesh_gpu.cpp opengl
name desc
mesh Mesh CPU con positions/normals (mismo length, stride 3) e indices uint32. Si esta vacio o invalido, upload devuelve MeshGpu{} (ok()==false).
name desc
mesh_gpu MeshGpu (vao/vbo/ebo, index_count). destroy libera todo y pone IDs a 0.
mesh_gpu_upload: MeshGpu listo para draw con glDrawElements(GL_TRIANGLES, index_count, GL_UNSIGNED_INT, 0). Si !ok(), no hubo upload.

mesh_gpu

CRUD GPU minimal para Mesh. Asume contexto OpenGL 3.3+ activo.

Layout de attribs

#version 330 core
layout(location = 0) in vec3 a_pos;
layout(location = 1) in vec3 a_normal;

Stride = 6 * sizeof(float), sin padding.

Uso tipico

auto cpu = fn::gfx::mesh_obj_load("model.obj");
auto gpu = fn::gfx::mesh_gpu_upload(cpu);
if (!gpu.ok()) { /* falla */ return; }

// Draw:
glUseProgram(prog);
glBindVertexArray(gpu.vao);
glDrawElements(GL_TRIANGLES, gpu.index_count, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);

// Cleanup:
fn::gfx::mesh_gpu_destroy(gpu);

Validacion de input

mesh_gpu_upload exige que mesh.normals.size() == mesh.positions.size(). mesh_obj_parse siempre genera normales (per-face si faltan) → invariante natural.

Notas

  • Indices son GL_UNSIGNED_INT (32-bit) para soportar meshes grandes sin tener que decidir formato dinamicamente.
  • GL_STATIC_DRAW: el assumption es que la malla no cambia post-upload. Si necesitas streaming, crear otro helper con GL_DYNAMIC_DRAW.