Mercurial > molko
comparison libmlk-core/mlk/core/texture.c @ 472:bc5483849614
core: texture -> mlk_texture
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 27 Feb 2023 11:24:38 +0100 |
parents | d7874f11565f |
children | 3ff1fe64d0cd |
comparison
equal
deleted
inserted
replaced
471:3761e33d429e | 472:bc5483849614 |
---|---|
26 #include "util.h" | 26 #include "util.h" |
27 #include "window.h" | 27 #include "window.h" |
28 #include "window_p.h" | 28 #include "window_p.h" |
29 | 29 |
30 int | 30 int |
31 texture_new(struct texture *tex, unsigned int w, unsigned int h) | 31 mlk_texture_new(struct mlk_texture *tex, unsigned int w, unsigned int h) |
32 { | 32 { |
33 assert(tex); | 33 assert(tex); |
34 assert(w); | 34 assert(w); |
35 assert(h); | 35 assert(h); |
36 | 36 |
47 | 47 |
48 return 0; | 48 return 0; |
49 } | 49 } |
50 | 50 |
51 int | 51 int |
52 texture_ok(const struct texture *tex) | 52 mlk_texture_ok(const struct mlk_texture *tex) |
53 { | 53 { |
54 return tex && tex->handle && tex->w && tex->h; | 54 return tex && tex->handle && tex->w && tex->h; |
55 } | 55 } |
56 | 56 |
57 int | 57 int |
58 texture_set_blend_mode(struct texture *tex, enum texture_blend blend) | 58 mlk_texture_set_blend_mode(struct mlk_texture *tex, enum mlk_texture_blend blend) |
59 { | 59 { |
60 assert(tex); | 60 assert(tex); |
61 assert(blend >= TEXTURE_BLEND_NONE && blend <= TEXTURE_BLEND_MODULATE); | 61 assert(blend >= MLK_TEXTURE_BLEND_NONE && blend < MLK_TEXTURE_BLEND_LAST); |
62 | 62 |
63 static const SDL_BlendMode table[] = { | 63 static const SDL_BlendMode table[] = { |
64 [TEXTURE_BLEND_NONE] = SDL_BLENDMODE_NONE, | 64 [MLK_TEXTURE_BLEND_NONE] = SDL_BLENDMODE_NONE, |
65 [TEXTURE_BLEND_BLEND] = SDL_BLENDMODE_BLEND, | 65 [MLK_TEXTURE_BLEND_BLEND] = SDL_BLENDMODE_BLEND, |
66 [TEXTURE_BLEND_ADD] = SDL_BLENDMODE_ADD, | 66 [MLK_TEXTURE_BLEND_ADD] = SDL_BLENDMODE_ADD, |
67 [TEXTURE_BLEND_MODULATE] = SDL_BLENDMODE_MOD | 67 [MLK_TEXTURE_BLEND_MODULATE] = SDL_BLENDMODE_MOD |
68 }; | 68 }; |
69 | 69 |
70 if (SDL_SetTextureBlendMode(tex->handle, table[blend]) < 0) | 70 if (SDL_SetTextureBlendMode(tex->handle, table[blend]) < 0) |
71 return errorf("%s", SDL_GetError()); | 71 return errorf("%s", SDL_GetError()); |
72 | 72 |
73 return 0; | 73 return 0; |
74 } | 74 } |
75 | 75 |
76 int | 76 int |
77 texture_set_alpha_mod(struct texture *tex, unsigned int alpha) | 77 mlk_texture_set_alpha_mod(struct mlk_texture *tex, unsigned int alpha) |
78 { | 78 { |
79 assert(texture_ok(tex)); | 79 assert(mlk_texture_ok(tex)); |
80 assert(alpha <= 255); | 80 assert(alpha <= 255); |
81 | 81 |
82 if (SDL_SetTextureAlphaMod(tex->handle, alpha) < 0) | 82 if (SDL_SetTextureAlphaMod(tex->handle, alpha) < 0) |
83 return errorf("%s", SDL_GetError()); | 83 return errorf("%s", SDL_GetError()); |
84 | 84 |
85 return 0; | 85 return 0; |
86 } | 86 } |
87 | 87 |
88 int | 88 int |
89 texture_set_color_mod(struct texture *tex, unsigned long color) | 89 mlk_texture_set_color_mod(struct mlk_texture *tex, unsigned long color) |
90 { | 90 { |
91 assert(texture_ok(tex)); | 91 assert(mlk_texture_ok(tex)); |
92 | 92 |
93 if (SDL_SetTextureColorMod(tex->handle, MLK_COLOR_R(color), MLK_COLOR_G(color), MLK_COLOR_B(color)) < 0) | 93 if (SDL_SetTextureColorMod(tex->handle, MLK_COLOR_R(color), MLK_COLOR_G(color), MLK_COLOR_B(color)) < 0) |
94 return errorf("%s", SDL_GetError()); | 94 return errorf("%s", SDL_GetError()); |
95 | 95 |
96 return 0; | 96 return 0; |
97 } | 97 } |
98 | 98 |
99 int | 99 int |
100 texture_draw(const struct texture *tex, int x, int y) | 100 mlk_texture_draw(const struct mlk_texture *tex, int x, int y) |
101 { | 101 { |
102 assert(tex); | 102 assert(tex); |
103 | 103 |
104 SDL_Rect dst = { | 104 SDL_Rect dst = { |
105 .x = x, | 105 .x = x, |
113 | 113 |
114 return 0; | 114 return 0; |
115 } | 115 } |
116 | 116 |
117 int | 117 int |
118 texture_scale(const struct texture *tex, | 118 mlk_texture_scale(const struct mlk_texture *tex, |
119 int src_x, | 119 int src_x, |
120 int src_y, | 120 int src_y, |
121 unsigned src_w, | 121 unsigned src_w, |
122 unsigned src_h, | 122 unsigned src_h, |
123 int dst_x, | 123 int dst_x, |
144 | 144 |
145 return 0; | 145 return 0; |
146 } | 146 } |
147 | 147 |
148 void | 148 void |
149 texture_finish(struct texture *tex) | 149 mlk_texture_finish(struct mlk_texture *tex) |
150 { | 150 { |
151 assert(tex); | 151 assert(tex); |
152 | 152 |
153 if (tex->handle) | 153 if (tex->handle) |
154 SDL_DestroyTexture(tex->handle); | 154 SDL_DestroyTexture(tex->handle); |
157 } | 157 } |
158 | 158 |
159 /* private */ | 159 /* private */ |
160 | 160 |
161 int | 161 int |
162 texture_from_surface(struct texture *tex, SDL_Surface *surface) | 162 texture_from_surface(struct mlk_texture *tex, SDL_Surface *surface) |
163 { | 163 { |
164 assert(tex); | 164 assert(tex); |
165 assert(surface); | 165 assert(surface); |
166 | 166 |
167 if (!(tex->handle = SDL_CreateTextureFromSurface(RENDERER(), surface))) { | 167 if (!(tex->handle = SDL_CreateTextureFromSurface(RENDERER(), surface))) { |