comparison libmlk-core/core/texture.h @ 243:71b3b7036de7

misc: lot of cleanups, - prefix libraries with libmlk, - move assets from source directories closes #2520, - prefix header guards closes #2519
author David Demelier <markand@malikania.fr>
date Sat, 28 Nov 2020 22:37:30 +0100
parents libcore/core/texture.h@dd7c8d4321a3
children c4da052c0def
comparison
equal deleted inserted replaced
242:4c24604efcab 243:71b3b7036de7
1 /*
2 * texture.h -- basic texture management
3 *
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #ifndef MOLKO_CORE_TEXTURE_H
20 #define MOLKO_CORE_TEXTURE_H
21
22 /**
23 * \file texture.h
24 * \brief Basic texture management.
25 * \ingroup drawing
26 *
27 * See also \a image.h for usage of textures.
28 */
29
30 #include <stdbool.h>
31
32 /**
33 * \brief Texture object.
34 */
35 struct texture {
36 unsigned int w; /*!< (-) Texture width. */
37 unsigned int h; /*!< (-) Texture height. */
38 void *handle; /*!< (*) Native handle. */
39 };
40
41 /**
42 * \brief Blend type when rendering.
43 */
44 enum texture_blend {
45 TEXTURE_BLEND_NONE, /*!< No pixel modulation. */
46 TEXTURE_BLEND_BLEND, /*!< Blend transparency. */
47 TEXTURE_BLEND_ADD, /*!< Additive blending. */
48 TEXTURE_BLEND_MODULATE, /*!< Color modulation. */
49 TEXTURE_BLEND_LAST /*!< Unused. */
50 };
51
52 /**
53 * Create a new texture.
54 *
55 * \pre tex != NULL
56 * \param tex the texture to initialize
57 * \param w the width
58 * \param h the height
59 * \return False on error.
60 */
61 bool
62 texture_new(struct texture *tex, unsigned int w, unsigned int h);
63
64 /**
65 * Check if the texture is valid.
66 *
67 * This function simply checks if the texture is initialized and has non-null
68 * dimensions.
69 *
70 * \param tex the texture to check (may be NULL)
71 * \return True if the texture is properly initialized.
72 */
73 bool
74 texture_ok(const struct texture *tex);
75
76 /**
77 * Set blend mode.
78 *
79 * \pre texture_ok(tex)
80 * \param tex the texture
81 * \param blend the blend mode
82 * \return False on errors.
83 */
84 bool
85 texture_set_blend_mode(struct texture *tex, enum texture_blend blend);
86
87 /**
88 * Apply an alpha modulation (aka transparency).
89 *
90 * You may need to use texture_set_blend_mode before this function to work.
91 *
92 * \pre texture_ok(tex)
93 * \param tex the texture
94 * \param alpha the alpha (0-255)
95 * \return False on errors.
96 */
97 bool
98 texture_set_alpha_mod(struct texture *tex, unsigned int alpha);
99
100 /**
101 * Apply a color modulation (for every pixel).
102 *
103 * \pre texture_ok(tex)
104 * \param tex the texture to modify
105 * \param color the color
106 * \return False on errors.
107 */
108 bool
109 texture_set_color_mod(struct texture *tex, unsigned long color);
110
111 /**
112 * Simple texture drawing.
113 *
114 * \pre tex != NULL
115 * \param tex the texture
116 * \param x the X coordinate
117 * \param y the Y coordinate
118 * \return False in case of rendering error.
119 */
120 bool
121 texture_draw(const struct texture *tex, int x, int y);
122
123 /**
124 * Advanced texture drawing.
125 *
126 * \pre tex != NULL
127 * \param tex the texture
128 * \param src_x the source rectangle X coordinate
129 * \param src_y the source rectangle Y coordinate
130 * \param src_w the source rectangle width
131 * \param src_h the source rectangle height
132 * \param dst_x the destination rectangle X coordinate
133 * \param dst_y the destination rectangle Y coordinate
134 * \param dst_w the destination rectangle width
135 * \param dst_h the destination rectangle height
136 * \param angle the angle
137 * \return False in case of rendering error.
138 */
139 bool
140 texture_scale(const struct texture *tex,
141 int src_x,
142 int src_y,
143 unsigned src_w,
144 unsigned src_h,
145 int dst_x,
146 int dst_y,
147 unsigned dst_w,
148 unsigned dst_h,
149 double angle);
150
151 /**
152 * Close the texture, do not use afterwards.
153 *
154 * \pre tex != NULL
155 * \param tex the texture
156 */
157 void
158 texture_finish(struct texture *tex);
159
160 #endif /* !MOLKO_CORE_TEXTURE_H */