88 glTexImage2D(tex->target, 0, internal_format, |
88 glTexImage2D(tex->target, 0, internal_format, |
89 surface->w, surface->h, |
89 surface->w, surface->h, |
90 0, format, |
90 0, format, |
91 GL_UNSIGNED_BYTE, surface->pixels); |
91 GL_UNSIGNED_BYTE, surface->pixels); |
92 asc_error_catch_gl("Writing texture data"); |
92 asc_error_catch_gl("Writing texture data"); |
|
93 if (tex->use_mipmaps) { |
|
94 glGenerateTextureMipmap(tex->tex_id); |
|
95 asc_error_catch_gl("Generating texture mipmaps"); |
|
96 } |
93 } |
97 } |
94 |
98 |
95 void asc_texture_from_file(AscTexture *tex, const char *name) { |
99 void asc_texture_from_file(AscTexture *tex, const char *name) { |
96 cxmutstr filepath = asc_filesystem_combine_paths(cx_strcast(asc_context.texture_path), cx_str(name)); |
100 cxmutstr filepath = asc_filesystem_combine_paths(cx_strcast(asc_context.texture_path), cx_str(name)); |
97 asc_dprintf("Load texture from %" CX_PRIstr, CX_SFMT(filepath)); |
101 asc_dprintf("Load texture from %" CX_PRIstr, CX_SFMT(filepath)); |
135 |
139 |
136 for (unsigned i = 0; i < count; ++i) { |
140 for (unsigned i = 0; i < count; ++i) { |
137 memset(&tex[i], 0, sizeof(AscTexture)); |
141 memset(&tex[i], 0, sizeof(AscTexture)); |
138 tex[i].tex_id = textures[i]; |
142 tex[i].tex_id = textures[i]; |
139 tex[i].target = texture_targets[target]; |
143 tex[i].target = texture_targets[target]; |
|
144 tex[i].use_mipmaps = min_filter > 1; |
140 glBindTexture(tex[i].target, tex[i].tex_id); |
145 glBindTexture(tex[i].target, tex[i].tex_id); |
141 glTexParameteri(tex[i].target, GL_TEXTURE_MIN_FILTER, |
146 glTexParameteri(tex[i].target, GL_TEXTURE_MIN_FILTER, |
142 texture_filters[min_filter]); |
147 texture_filters[min_filter]); |
143 glTexParameteri(tex[i].target, GL_TEXTURE_MAG_FILTER, |
148 glTexParameteri(tex[i].target, GL_TEXTURE_MAG_FILTER, |
144 texture_filters[mag_filter]); |
149 texture_filters[mag_filter]); |