1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-03 13:03:38 +00:00
lovr/src/graphics/material.c

47 lines
1.4 KiB
C
Raw Normal View History

2017-10-21 21:00:33 +00:00
#include "graphics/graphics.h"
#include "graphics/material.h"
2017-10-31 08:14:09 +00:00
Material* lovrMaterialCreate(MaterialData* materialData, bool isDefault) {
2017-10-21 21:00:33 +00:00
Material* material = lovrAlloc(sizeof(Material), lovrMaterialDestroy);
if (!material) return NULL;
material->materialData = materialData;
material->isDefault = isDefault;
for (int i = 0; i < MAX_MATERIAL_TEXTURES; i++) {
if (materialData->textures[i]) {
material->textures[i] = lovrTextureCreate(TEXTURE_2D, &materialData->textures[i], 1);
2017-10-21 21:32:41 +00:00
} else {
material->textures[i] = NULL;
2017-10-21 21:00:33 +00:00
}
}
return material;
}
void lovrMaterialDestroy(const Ref* ref) {
Material* material = containerof(ref, Material);
for (int i = 0; i < MAX_MATERIAL_TEXTURES; i++) {
if (material->textures[i]) {
lovrRelease(&material->textures[i]->ref);
}
}
free(material);
}
Color lovrMaterialGetColor(Material* material, MaterialColor colorType) {
return material->materialData->colors[colorType];
}
void lovrMaterialSetColor(Material* material, MaterialColor colorType, Color color) {
material->materialData->colors[colorType] = color;
}
Texture* lovrMaterialGetTexture(Material* material, MaterialTexture textureType) {
return material->textures[textureType];
}
void lovrMaterialSetTexture(Material* material, MaterialTexture textureType, Texture* texture) {
material->textures[textureType] = texture;
}