summaryrefslogtreecommitdiff
path: root/src/core/texture.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/texture.c')
-rw-r--r--src/core/texture.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/core/texture.c b/src/core/texture.c
index c7dc884..33a00c5 100644
--- a/src/core/texture.c
+++ b/src/core/texture.c
@@ -48,11 +48,23 @@ Texture* texture_loadfromfile(const char* path) {
Texture* texture = ssrM_new(Texture);
texture->width = width; texture->height = height;
texture->pixels = ssrM_newvector(Color32, width*height);
+ texture->filter_mode = FILTERMODE_POINT;
+ texture->wrap_mode = WRAPMODE_CLAMP;
texture_abgr2c32(pixels, texture->pixels, width*height);
ssrM_free(pixels);
return texture;
}
+Texture* texture_create(uint width, uint height) {
+ Texture* tex = ssrM_new(Texture);
+ tex->pixels = ssrM_newvector(Color32, width*height);
+ tex->width = width;
+ tex->height = height;
+ tex->filter_mode = FILTERMODE_POINT;
+ tex->wrap_mode = WRAPMODE_CLAMP;
+ return tex;
+}
+
static Color32 sampling(Texture* tex, WrapMode wrap_mode, int x, int y) {
if (wrap_mode == WRAPMODE_CLAMP) { /*clamp*/
x = clamp(x, 0, tex->width - 1);
@@ -64,8 +76,10 @@ static Color32 sampling(Texture* tex, WrapMode wrap_mode, int x, int y) {
return tex->pixels[x + y * tex->width];
}
-Color32 texture_sampling(Texture* tex, FilterMode filter_mode, WrapMode wrap_mode, float x01, float y01) {
+Color32 texture_sampling(Texture* tex, float x01, float y01) {
ssr_assert(tex);
+ FilterMode filter_mode = tex->filter_mode;
+ WrapMode wrap_mode = tex->wrap_mode;
float x = x01 * tex->width, y = (1 - y01) * tex->height; /*map to texture coordinate*/
int x_min = floor(x), y_min = floor(y);
int x_max = ceil(x), y_max = ceil(y);
@@ -94,3 +108,19 @@ Color32 texture_sampling(Texture* tex, FilterMode filter_mode, WrapMode wrap_mod
}
*/
}
+
+void texture_setfiltermode(Texture* tex, FilterMode filter) {
+ ssr_assert(tex);
+ tex->filter_mode = filter;
+}
+
+void texture_setwrapmode(Texture* tex, WrapMode wrap) {
+ ssr_assert(tex);
+ tex->wrap_mode = wrap;
+}
+
+void texture_free(Texture* tex) {
+ if (tex->pixels)
+ ssrM_free(tex->pixels);
+ ssrM_free(tex);
+}