2016-11-26 07:54:45 +00:00
|
|
|
#include "loaders/texture.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2016-11-27 10:06:47 +00:00
|
|
|
TextureData* lovrTextureDataGetEmpty() {
|
|
|
|
TextureData* textureData = malloc(sizeof(TextureData));
|
|
|
|
if (!textureData) return NULL;
|
|
|
|
|
|
|
|
uint8_t* pixel = malloc(4 * sizeof(uint8_t));
|
|
|
|
pixel[0] = pixel[1] = pixel[2] = pixel[3] = 0xff;
|
|
|
|
|
|
|
|
textureData->width = 1;
|
|
|
|
textureData->height = 1;
|
|
|
|
textureData->channels = 4;
|
|
|
|
textureData->data = pixel;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|