mirror of https://github.com/bjornbytes/lovr.git
Add Material;
This commit is contained in:
parent
1f6a80ee85
commit
3743b9d032
|
@ -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;
|
||||
}
|
|
@ -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);
|
Loading…
Reference in New Issue