summaryrefslogtreecommitdiff
path: root/src/mesh.h
blob: 70b7f4db8c35de4aae6af2a91d7665f1c2d7ae77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef HONEY_MESH_H
#define HONEY_MESH_H

/** @file mesh.h
 *
 * @brief Defines the honey_mesh struct and related basic mesh functions. 
*/

#include "common.h"

typedef struct {
    unsigned int n_vertices, n_indices;
  unsigned int vertex_array, vertex_buffer, element_buffer;
} honey_mesh;

/** @brief Lua bindings for mesh drawing and deletion functions. */
void honey_setup_mesh(lua_State* L);

/** @brief Load all meshes from a file.
 *
 * @param[in] filename The name of the file to load from.
 *
 * @returns A table containing all of the meshes.
 */
int honey_mesh_load(lua_State* L);

/** @brief Create a new mesh from vertex and index arrays.
 *
 * Note that this function creates copies of the vertex and index arrays, 
 * so you can deallocate those immediately.
 *
 * @param[out] mesh Pointer to the destination honey_mesh struct
 * @param[in] vertices Array of floats representing the vertices
 * @param[in] n_attributes The number of attributes per vertex
 * @param[in] attribute_sizes An array containing for each attribute how many floats it contains
 * @param[in] n_vertices The number of vertices (NOT the number of floats in the vertex array)
 * @param[in] indices Array of vertex indices
 * @param[in] n_indices The number of elements in the index array
 */
honey_result honey_mesh_new(honey_mesh* mesh,
                            float* vertices,
                            unsigned int n_vertices,
                            unsigned int n_attributes,
                            unsigned int* attribute_sizes,
                            unsigned int* indices,
                            unsigned int n_indices);

/** @brief Draw a mesh on screen.
 *
 * @param[in] mesh The mesh to draw
 * @param[in] shader The shader to use when drawing the mesh
 */
void honey_mesh_draw(honey_mesh mesh,
                     int shader);

/** @brief Delete a mesh.
 *
 * @param[in] mesh The mesh to delete
 */
void honey_mesh_delete(honey_mesh mesh);
  
#endif