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

54 lines
1.5 KiB
C
Raw Normal View History

2017-10-21 21:00:33 +00:00
#include "graphics/material.h"
2018-07-04 20:51:35 +00:00
#include <stdlib.h>
2017-10-21 21:00:33 +00:00
2018-07-18 07:34:21 +00:00
Material* lovrMaterialCreate() {
2017-10-21 21:00:33 +00:00
Material* material = lovrAlloc(sizeof(Material), lovrMaterialDestroy);
if (!material) return NULL;
2018-02-12 03:16:40 +00:00
for (int i = 0; i < MAX_MATERIAL_SCALARS; i++) {
material->scalars[i] = 1.f;
}
2018-01-30 05:44:32 +00:00
for (int i = 0; i < MAX_MATERIAL_COLORS; i++) {
material->colors[i] = (Color) { 1, 1, 1, 1 };
}
2017-10-21 21:00:33 +00:00
return material;
}
2018-02-26 08:59:03 +00:00
void lovrMaterialDestroy(void* ref) {
Material* material = ref;
2017-10-21 21:00:33 +00:00
for (int i = 0; i < MAX_MATERIAL_TEXTURES; i++) {
2018-02-26 08:59:03 +00:00
lovrRelease(material->textures[i]);
2017-10-21 21:00:33 +00:00
}
free(material);
}
2018-02-12 03:16:40 +00:00
float lovrMaterialGetScalar(Material* material, MaterialScalar scalarType) {
return material->scalars[scalarType];
}
void lovrMaterialSetScalar(Material* material, MaterialScalar scalarType, float value) {
material->scalars[scalarType] = value;
}
2017-10-21 21:00:33 +00:00
Color lovrMaterialGetColor(Material* material, MaterialColor colorType) {
2018-01-30 05:44:32 +00:00
return material->colors[colorType];
2017-10-21 21:00:33 +00:00
}
void lovrMaterialSetColor(Material* material, MaterialColor colorType, Color color) {
2018-01-30 05:44:32 +00:00
material->colors[colorType] = color;
2017-10-21 21:00:33 +00:00
}
Texture* lovrMaterialGetTexture(Material* material, MaterialTexture textureType) {
return material->textures[textureType];
}
void lovrMaterialSetTexture(Material* material, MaterialTexture textureType, Texture* texture) {
if (texture != material->textures[textureType]) {
2018-02-26 08:59:03 +00:00
lovrRetain(texture);
lovrRelease(material->textures[textureType]);
material->textures[textureType] = texture;
}
2017-10-21 21:00:33 +00:00
}