summaryrefslogtreecommitdiff
path: root/src/texture/texture.h
blob: 785fef0cc5a1d2836a3ef2d6d426918e91c4131b (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef HONEY_TEXTURE_H
#define HONEY_TEXTURE_H

/** @file texture.h
 *
 *@brief Defines the honey_texture struct and associated functions. 
*/

#include "../common.h"

enum honey_texture_result {
  TEXTURE_OK,
  TEXTURE_FAILED,
  TEXTURE_CHANNEL_ERROR,
  N_TEXTURE_RESULTS };

typedef struct {
    unsigned int id;
    enum {
        GREY,
        RGB,
        RGBA,
        DEPTH
    } type;
    int width;
    int height;
    int channels;
} honey_texture;

/** @brief Place the honey.texture bindings as a table on the stack. */
void honey_setup_texture(lua_State* L);

/** @brief Create a greyscale texture.
 *
 * @param[out] texture Pointer to the destination texture.
 * @param[in] width The width in pixels of the texture to create.
 * @param[in] height The height in pixels of the texture to create.
 * @param[in] data The data to populate the texture with, or NULL to leave it unpopulated.
 *
 * @returns HONEY_OK on success, and appropriate error on failure.
 */
void honey_texture_new_greyscale(honey_texture* texture,
                                 int width, int height,
                                 unsigned char* data);

/** @brief Create an RGB texture.
 *
 * @param[out] texture Pointer to the destination texture.
 * @param[in] width The width in pixels of the texture to create.
 * @param[in] height The height in pixels of the texture to create.
 * @param[in] data The data to populate the texture with, or NULL to leave it unpopulated.
 *
 * @returns HONEY_OK on success, and appropriate error on failure.
 */
void honey_texture_new_rgb(honey_texture* texture,
                           int width, int height,
                           unsigned char* data);

/** @brief Create an RGBA texture.
 *
 * @param[out] texture Pointer to the destination texture.
 * @param[in] width The width in pixels of the texture to create.
 * @param[in] height The height in pixels of the texture to create.
 * @param[in] data The data to populate the texture with, or NULL to leave it unpopulated.
 *
 * @returns HONEY_OK on success, and appropriate error on failure.
 */
void honey_texture_new_rgba(honey_texture* texture,
                            int width, int height,
                            unsigned char* data);

/** @brief Create a depth texture.
 *
 * @param[out] texture Pointer to the destination texture.
 * @param[in] width The width in pixels of the texture to create.
 * @param[in] height The height in pixels of the texture to create.
 * @param[in] data The data to populate the texture with, or NULL to leave it unpopulated.
 *
 * @returns HONEY_OK on success, and appropriate error on failure.
 */
void honey_texture_new_depth(honey_texture* texture,
                             int width, int height,
                             float* data);

/** @brief Load a texture from disk.
 *
 * @param[out] texture Pointer to the destination texture
 * @param[in] texture_path Path to the location of the texture
 * @param[in] alpha_channel Set to true if the target image contains an alpha channel
 *
 * @return Success or failure type
 */
enum honey_texture_result honey_texture_load(honey_texture* texture,
                                             char* texture_path);

/** @brief Load a texture into a texture unit.
 *
 * @param[in] texture The texture to use
 * @param[in] texture_unit The texture unit to put the texture in
 */
void honey_texture_use(honey_texture texture, int texture_unit);

/** @brief Create a framebuffer object.
 *
 * @param[out] destination Pointer to store the resulting OpenGL handle in.
 * @param[in] width The width in pixels of the FBO.
 * @param[in] height The height in pixels of the FBO.
 *
 * @returns HONEY_OK on success; appropriate error otherwise.
 */
honey_result honey_texture_framebuffer_object_new(unsigned int* destination,
                                                  int width, int height);

#endif