| 308 | } |
| 309 | |
| 310 | inline void LoadFrom(void *img_data, const size_t img_data_size, const u32 custom_width, const u32 custom_height) { |
| 311 | int data_width; |
| 312 | int data_height; |
| 313 | int bpp; |
| 314 | auto stb_data = stbi_load_from_memory(reinterpret_cast<const u8*>(img_data), img_data_size, &data_width, &data_height, &bpp, 0); |
| 315 | |
| 316 | GLuint gl_tex; |
| 317 | glGenTextures(1, &gl_tex); |
| 318 | glBindTexture(GL_TEXTURE_2D, gl_tex); |
| 319 | |
| 320 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 321 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 322 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 323 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 324 | |
| 325 | if(bpp == 4) { |
| 326 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, data_width, data_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, stb_data); |
| 327 | } |
| 328 | else if(bpp == 3) { |
| 329 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, data_width, data_height, 0, GL_RGB, GL_UNSIGNED_BYTE, stb_data); |
| 330 | } |
| 331 | else { |
| 332 | emscripten_log(EM_LOG_CONSOLE, "Unexpected bpp amount in image: %d", bpp); |
| 333 | } |
| 334 | |
| 335 | stbi_image_free(stb_data); |
| 336 | free(img_data); |
| 337 | |
| 338 | this->width = (custom_width > 0) ? custom_width : data_width; |
| 339 | this->height = (custom_height > 0) ? custom_height : data_height; |
| 340 | this->gl_tex = gl_tex; |
| 341 | } |
| 342 | }; |
| 343 | |
| 344 | struct ElementLoadContext { |