LibGame v0.4.0
The LG Game Engine - Copyright (C) 2024-2026 ETMSoftware
Loading...
Searching...
No Matches
lg_render.c File Reference

Functions

int lg_mesh_to_drawelements_cmd (LG_Mesh *mesh, int u_tex, LG_DrawElements_Cmd *draw_params)
 
void lg_draw_elements (LG_DrawElements_Cmd *draw_params)
 
void lg_drawelements_info (LG_DrawElements_Cmd *draw_params)
 
LG_Texturelg_dummy_texture ()
 

Detailed Description

 === Structs and wrapper funcs to efficiently draw mesh data ===

 - Set textures and params to be used by glDrawElements()
 - Make batch calls to glDrawElements()

 LG_DrawElements_Cmd = glDrawElements() command

Function Documentation

◆ lg_mesh_to_drawelements_cmd()

int lg_mesh_to_drawelements_cmd ( LG_Mesh mesh,
int  u_tex,
LG_DrawElements_Cmd draw_params 
)

Here we use:

  • mesh->n_usemtl = num of 'usemtl' tags in OBJ file
  • mesh->n_mat = num of 'newmtl'/'map_K' tags (materials with referenced textures) in MTL file
  • mesh->materials[N_MAT_MAX] = materials 'lib'
  • mesh->i_mat_in_vbo[N_USEMTL_MAX] = material face indices in VBO, referenced by 'usemtl' tags
  • mesh->i_mat_in_lib[N_MAT_MAX] = texture indices in materials[N_MAT_MAX]

to compute size and shift

LG_N_MAX_DRAWS = N_USEMTL_MAX

Parameters
meshPointer to a LG_Mesh struct
u_texTexture coords uniform to be used by glUniform1i()
draw_paramsPointer to a LG_DrawElements_Cmd struct
Returns
LG_OK if OK

◆ lg_draw_elements()

void lg_draw_elements ( LG_DrawElements_Cmd draw_params)

Call glDrawElements(GL_TRIANGLES, size[i], GL_UNSIGNED_INT, shift[i]) n_draws times

Parameters
draw_paramsPointer to a LG_DrawElements_Cmd struct

◆ lg_drawelements_info()

void lg_drawelements_info ( LG_DrawElements_Cmd draw_params)

Print out LG_DrawElements_Cmd info

Parameters
draw_paramsPointer to a LG_DrawElements_Cmd struct

◆ lg_dummy_texture()

LG_Texture * lg_dummy_texture ( )

To be used if no texture provided

Load the texture only once on first call

Returns
Pointer to dummy texture