Load texture from glb
Add loading image from glb file.
This commit is contained in:
@@ -15,12 +15,10 @@
|
||||
* @param bytes_count Returned bytes count
|
||||
* @param buffer Returned filled buffer
|
||||
*/
|
||||
rse_err_t file_read_bytes(const char* file_path, size_t* bytes_count, char* buffer);
|
||||
rse_err_t file_read_bytes(const char* file_path, size_t* bytes_count, unsigned char* buffer);
|
||||
|
||||
rse_err_t file_write(const char* file_name, size_t bytes_count, char* buffer);
|
||||
|
||||
rse_err_t file_load_pixels(const char* file_name, unsigned char* buffer, size_t* buffer_size, int* width, int* height);
|
||||
|
||||
rse_err_t file_append_full_path(char* file_path, size_t max_buffer_size);
|
||||
|
||||
rse_err_t file_load_gltf(const char* file_name, cgltf_data** data);
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
#include "commons.h"
|
||||
#include "errors_common.h"
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb/stb_image.h"
|
||||
|
||||
#ifdef __linux__
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
@@ -119,70 +116,7 @@ rse_err_t file_append_full_path(char* file_path, size_t max_buffer_size)
|
||||
return ret;
|
||||
}
|
||||
|
||||
rse_err_t file_load_pixels(const char* file_name, unsigned char* buffer, size_t* buffer_size, int* width, int* height)
|
||||
{
|
||||
int channels = 0;
|
||||
stbi_uc* pixel_buffer = NULL;
|
||||
size_t image_buffer_size = 0U;
|
||||
rse_err_t ret = RSE_ERROR_NO_ERROR;
|
||||
char real_path[MAX_PATH_LENGTH] = {0};
|
||||
|
||||
if (buffer_size == NULL) {
|
||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Provided NULL buffer_size");
|
||||
|
||||
return RSE_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (width == NULL) {
|
||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Provided NULL width");
|
||||
|
||||
return RSE_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (height == NULL) {
|
||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Provided NULL height");
|
||||
|
||||
return RSE_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
strncpy(real_path, file_name, MAX_PATH_LENGTH);
|
||||
if ((ret = file_append_full_path(real_path, MAX_PATH_LENGTH)) != RSE_ERROR_NO_ERROR) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
pixel_buffer = stbi_load(real_path, width, height, &channels, STBI_rgb_alpha);
|
||||
|
||||
if (pixel_buffer == NULL) {
|
||||
SDL_LogCritical(SDL_LOG_CATEGORY_GPU, "Failed to load texture from file: %s", file_name);
|
||||
return RSE_ERROR_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
image_buffer_size = *width * *height * 4; // TODO: "4" is very hardcoded value. Change this
|
||||
|
||||
if ((buffer != NULL) && (image_buffer_size > *buffer_size)) {
|
||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Provided buffer is to small to hold pixel data. %ld vs %ld",
|
||||
*buffer_size,
|
||||
image_buffer_size);
|
||||
ret = RSE_ERROR_INTERNAL_ERROR;
|
||||
|
||||
goto image_free;
|
||||
}
|
||||
|
||||
*buffer_size = image_buffer_size;
|
||||
|
||||
if (buffer != NULL) {
|
||||
memset(buffer, 0, *buffer_size);
|
||||
memcpy(buffer, pixel_buffer, *buffer_size);
|
||||
}
|
||||
|
||||
image_free:
|
||||
stbi_image_free(pixel_buffer);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
rse_err_t file_read_bytes(const char* file_name, size_t* bytes_count, char* buffer)
|
||||
rse_err_t file_read_bytes(const char* file_name, size_t* bytes_count, unsigned char* buffer)
|
||||
{
|
||||
rse_err_t ret = RSE_ERROR_NO_ERROR;
|
||||
FILE* file = NULL;
|
||||
|
||||
Reference in New Issue
Block a user