mirror of https://github.com/bjornbytes/lovr.git
setMaterial takes Texture in addition to Material;
This commit is contained in:
parent
f729320793
commit
fbf2a039b7
|
@ -241,7 +241,8 @@ static int l_lovrPassSetDepthClamp(lua_State* L) {
|
|||
static int l_lovrPassSetMaterial(lua_State* L) {
|
||||
Pass* pass = luax_checktype(L, 1, Pass);
|
||||
Material* material = luax_totype(L, 2, Material);
|
||||
lovrPassSetMaterial(pass, material);
|
||||
Texture* texture = luax_totype(L, 2, Texture);
|
||||
lovrPassSetMaterial(pass, material, texture);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ struct Texture {
|
|||
uint32_t ref;
|
||||
gpu_texture* gpu;
|
||||
gpu_texture* renderView;
|
||||
Material* material;
|
||||
TextureInfo info;
|
||||
Sync sync;
|
||||
};
|
||||
|
@ -1119,6 +1120,7 @@ Texture* lovrTextureCreateView(TextureViewInfo* view) {
|
|||
void lovrTextureDestroy(void* ref) {
|
||||
Texture* texture = ref;
|
||||
if (texture != state.window) {
|
||||
lovrRelease(texture->material, lovrMaterialDestroy);
|
||||
lovrRelease(texture->info.parent, lovrTextureDestroy);
|
||||
if (texture->renderView && texture->renderView != texture->gpu) gpu_texture_destroy(texture->renderView);
|
||||
if (texture->gpu) gpu_texture_destroy(texture->gpu);
|
||||
|
@ -1130,6 +1132,22 @@ const TextureInfo* lovrTextureGetInfo(Texture* texture) {
|
|||
return &texture->info;
|
||||
}
|
||||
|
||||
static Material* lovrTextureGetMaterial(Texture* texture) {
|
||||
if (!texture->material) {
|
||||
texture->material = lovrMaterialCreate(&(MaterialInfo) {
|
||||
.data.color = { 1.f, 1.f, 1.f, 1.f },
|
||||
.data.uvScale = { 1.f, 1.f },
|
||||
.texture = texture
|
||||
});
|
||||
|
||||
// Since the Material refcounts the Texture, this creates a cycle. Release the texture to make
|
||||
// sure this is a weak relationship (the automaterial does not keep the texture refcounted).
|
||||
lovrRelease(texture, lovrTextureDestroy);
|
||||
}
|
||||
|
||||
return texture->material;
|
||||
}
|
||||
|
||||
// Sampler
|
||||
|
||||
Sampler* lovrGraphicsGetDefaultSampler(FilterMode mode) {
|
||||
|
@ -2185,7 +2203,11 @@ void lovrPassSetDepthClamp(Pass* pass, bool clamp) {
|
|||
}
|
||||
}
|
||||
|
||||
void lovrPassSetMaterial(Pass* pass, Material* material) {
|
||||
void lovrPassSetMaterial(Pass* pass, Material* material, Texture* texture) {
|
||||
if (texture) {
|
||||
material = lovrTextureGetMaterial(texture);
|
||||
}
|
||||
|
||||
material = material ? material : state.defaultMaterial;
|
||||
|
||||
if (pass->pipeline->material != material) {
|
||||
|
|
|
@ -459,7 +459,7 @@ void lovrPassSetDepthTest(Pass* pass, CompareMode test);
|
|||
void lovrPassSetDepthWrite(Pass* pass, bool write);
|
||||
void lovrPassSetDepthOffset(Pass* pass, float offset, float sloped);
|
||||
void lovrPassSetDepthClamp(Pass* pass, bool clamp);
|
||||
void lovrPassSetMaterial(Pass* pass, Material* material);
|
||||
void lovrPassSetMaterial(Pass* pass, Material* material, Texture* texture);
|
||||
void lovrPassSetSampler(Pass* pass, Sampler* sampler);
|
||||
void lovrPassSetScissor(Pass* pass, uint32_t scissor[4]);
|
||||
void lovrPassSetShader(Pass* pass, Shader* shader);
|
||||
|
|
Loading…
Reference in New Issue