2016-11-26 07:54:45 +00:00
|
|
|
#include "loaders/texture.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2017-01-09 06:51:43 +00:00
|
|
|
TextureData* lovrTextureDataGetBlank(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;
|
|
|
|
}
|
|
|
|
|
2017-01-09 06:51:43 +00:00
|
|
|
TextureData* lovrTextureDataGetEmpty(int width, int height) {
|
|
|
|
TextureData* textureData = malloc(sizeof(TextureData));
|
|
|
|
if (!textureData) return NULL;
|
|
|
|
|
|
|
|
textureData->data = NULL;
|
|
|
|
textureData->width = width;
|
|
|
|
textureData->height = height;
|
|
|
|
textureData->channels = 4;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|