Add Material;

This commit is contained in:
bjorn 2017-10-21 14:00:33 -07:00
parent 1f6a80ee85
commit 3743b9d032
2 changed files with 63 additions and 0 deletions

44
src/graphics/material.c Normal file
View File

@ -0,0 +1,44 @@
#include "graphics/graphics.h"
#include "graphics/material.h"
Material* lovrMaterialCreate(MaterialData* materialData, int isDefault) {
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);
}
}
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;
}

19
src/graphics/material.h Normal file
View File

@ -0,0 +1,19 @@
#include "util.h"
#include "graphics/texture.h"
#include "loaders/material.h"
#pragma once
typedef struct {
Ref ref;
MaterialData* materialData;
Texture* textures[MAX_MATERIAL_TEXTURES];
int isDefault;
} Material;
Material* lovrMaterialCreate(MaterialData* materialData, int isDefault);
void lovrMaterialDestroy(const Ref* ref);
Color lovrMaterialGetColor(Material* material, MaterialColor colorType);
void lovrMaterialSetColor(Material* material, MaterialColor colorType, Color color);
Texture* lovrMaterialGetTexture(Material* material, MaterialTexture textureType);
void lovrMaterialSetTexture(Material* material, MaterialTexture textureType, Texture* texture);