comparison libmlk-core/mlk/core/texture.c @ 486:d6757c30658e

core: rework errors
author David Demelier <markand@malikania.fr>
date Tue, 28 Feb 2023 13:04:13 +0100
parents 3ff1fe64d0cd
children 23559c7ccf47
comparison
equal deleted inserted replaced
485:3ff1fe64d0cd 486:d6757c30658e
18 18
19 #include <assert.h> 19 #include <assert.h>
20 #include <string.h> 20 #include <string.h>
21 21
22 #include "color.h" 22 #include "color.h"
23 #include "error.h"
24 #include "texture.h" 23 #include "texture.h"
25 #include "texture_p.h" 24 #include "texture_p.h"
26 #include "util.h" 25 #include "util.h"
27 #include "window.h" 26 #include "window.h"
28 #include "window_p.h" 27 #include "window_p.h"
66 [MLK_TEXTURE_BLEND_ADD] = SDL_BLENDMODE_ADD, 65 [MLK_TEXTURE_BLEND_ADD] = SDL_BLENDMODE_ADD,
67 [MLK_TEXTURE_BLEND_MODULATE] = SDL_BLENDMODE_MOD 66 [MLK_TEXTURE_BLEND_MODULATE] = SDL_BLENDMODE_MOD
68 }; 67 };
69 68
70 if (SDL_SetTextureBlendMode(tex->handle, table[blend]) < 0) 69 if (SDL_SetTextureBlendMode(tex->handle, table[blend]) < 0)
71 return errorf("%s", SDL_GetError()); 70 return MLK_ERR_SDL;
72 71
73 return 0; 72 return 0;
74 } 73 }
75 74
76 int 75 int
78 { 77 {
79 assert(mlk_texture_ok(tex)); 78 assert(mlk_texture_ok(tex));
80 assert(alpha <= 255); 79 assert(alpha <= 255);
81 80
82 if (SDL_SetTextureAlphaMod(tex->handle, alpha) < 0) 81 if (SDL_SetTextureAlphaMod(tex->handle, alpha) < 0)
83 return errorf("%s", SDL_GetError()); 82 return MLK_ERR_SDL;
84 83
85 return 0; 84 return 0;
86 } 85 }
87 86
88 int 87 int
89 mlk_texture_set_color_mod(struct mlk_texture *tex, unsigned long color) 88 mlk_texture_set_color_mod(struct mlk_texture *tex, unsigned long color)
90 { 89 {
91 assert(mlk_texture_ok(tex)); 90 assert(mlk_texture_ok(tex));
92 91
93 if (SDL_SetTextureColorMod(tex->handle, MLK_COLOR_R(color), MLK_COLOR_G(color), MLK_COLOR_B(color)) < 0) 92 if (SDL_SetTextureColorMod(tex->handle, MLK_COLOR_R(color), MLK_COLOR_G(color), MLK_COLOR_B(color)) < 0)
94 return errorf("%s", SDL_GetError()); 93 return MLK_ERR_SDL;
95 94
96 return 0; 95 return 0;
97 } 96 }
98 97
99 int 98 int
107 .w = tex->w, 106 .w = tex->w,
108 .h = tex->h 107 .h = tex->h
109 }; 108 };
110 109
111 if (SDL_RenderCopy(MLK__RENDERER(), tex->handle, NULL, &dst) < 0) 110 if (SDL_RenderCopy(MLK__RENDERER(), tex->handle, NULL, &dst) < 0)
112 return errorf("%s", SDL_GetError()); 111 return MLK_ERR_SDL;
113 112
114 return 0; 113 return 0;
115 } 114 }
116 115
117 int 116 int
138 .w = dst_w, 137 .w = dst_w,
139 .h = dst_h 138 .h = dst_h
140 }; 139 };
141 140
142 if (SDL_RenderCopyEx(MLK__RENDERER(), tex->handle, &src, &dst, angle, NULL, SDL_FLIP_NONE) < 0) 141 if (SDL_RenderCopyEx(MLK__RENDERER(), tex->handle, &src, &dst, angle, NULL, SDL_FLIP_NONE) < 0)
143 return errorf("%s", SDL_GetError()); 142 return MLK_ERR_SDL;
144 143
145 return 0; 144 return 0;
146 } 145 }
147 146
148 void 147 void