1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-21 21:23:35 +00:00
lovr/src/loaders/texture.c

47 lines
1.3 KiB
C
Raw Normal View History

2016-11-26 07:54:45 +00:00
#include "loaders/texture.h"
#include "util.h"
#include <stdlib.h>
2017-01-09 05:29:16 +00:00
TextureData* lovrTextureDataGetEmpty(int width, int height, uint8_t value) {
2016-11-27 10:06:47 +00:00
TextureData* textureData = malloc(sizeof(TextureData));
if (!textureData) return NULL;
2017-01-09 05:29:16 +00:00
int channels = 4;
int size = sizeof(uint8_t) * width * height * channels;
uint8_t* data = malloc(size);
memset(data, value, size);
2016-11-27 10:06:47 +00:00
2017-01-09 05:29:16 +00:00
textureData->data = data;
textureData->width = width;
textureData->height = height;
textureData->channels = channels;
2016-11-27 10:06:47 +00:00
return textureData;
}
2016-11-26 07:54:45 +00:00
TextureData* lovrTextureDataFromFile(void* data, int size) {
TextureData* textureData = malloc(sizeof(TextureData));
if (!textureData) return NULL;
void* image = loadImage(data, size, &textureData->width, &textureData->height, &textureData->channels, 4);
if (image) {
textureData->data = image;
return textureData;
}
2016-12-01 04:32:14 +00:00
free(textureData);
return NULL;
2016-11-26 07:54:45 +00:00
}
2016-11-26 08:31:44 +00:00
TextureData* lovrTextureDataFromOpenVRModel(OpenVRModel* vrModel) {
2016-11-26 07:54:45 +00:00
TextureData* textureData = malloc(sizeof(TextureData));
if (!textureData) return NULL;
2016-11-26 08:31:44 +00:00
RenderModel_TextureMap_t* texture = vrModel->texture;
textureData->width = texture->unWidth;
textureData->height = texture->unHeight;
textureData->data = texture->rubTextureMapData;
2016-11-26 07:54:45 +00:00
return textureData;
}