Skip to content

Commit

Permalink
Fixed wrong shader vars when adding new mesh
Browse files Browse the repository at this point in the history
Disabling for example textures and/or lighting and then adding or
reloading meshes would cause the variable change to not sync into the
new meshes' shaders.
  • Loading branch information
ousnius committed Dec 20, 2016
1 parent c921596 commit f250115
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
2 changes: 2 additions & 0 deletions src/program/OutfitStudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5811,6 +5811,8 @@ void wxGLPanel::SetMeshTextures(const string& shapeName, const vector<string>& t

if (hasMatFile)
m->UpdateFromMaterialFile(matFile);

gls.UpdateShaders(m);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/program/PreviewWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class PreviewWindow : public wxFrame {

if (hasMatFile)
m->UpdateFromMaterialFile(matFile);

gls.UpdateShaders(m);
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/render/GLSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,15 @@ void GLSurface::RenderMesh(mesh* m) {
shader.End();
}

void GLSurface::UpdateShaders(mesh* m) {
if (m->material) {
m->material->GetShader().ShowTexture(bTextured);
m->material->GetShader().ShowLighting(bLighting);
m->material->GetShader().ShowWeight(bWeightColors);
m->material->GetShader().ShowSegments(bSegmentColors);
}
}

void GLSurface::ReloadMeshFromNif(NifFile* nif, string shapeName) {
DeleteMesh(shapeName);
AddMeshFromNif(nif, shapeName);
Expand Down
28 changes: 7 additions & 21 deletions src/render/GLSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,16 @@ class GLSurface {
void RenderOneFrame();
void RenderMesh(mesh* m);

void UpdateShaders(mesh* m);

void ToggleTextures() {
if (bTextured)
bTextured = false;
else
bTextured = true;

for (auto &m : meshes)
if (m->material)
m->material->GetShader().ShowTexture(bTextured);
UpdateShaders(m);
}

void ToggleWireframe() {
Expand All @@ -293,42 +294,27 @@ class GLSurface {
bLighting = true;

for (auto &m : meshes)
if (m->material)
m->material->GetShader().ShowLighting(bLighting);
UpdateShaders(m);
}

void SetMaskVisible(bool bVisible = true) {
bMaskVisible = bVisible;

for (auto &m : meshes)
if (m->material)
m->material->GetShader().ShowMask(bVisible);
UpdateShaders(m);
}

void SetWeightColors(bool bVisible = true) {
bWeightColors = bVisible;

for (auto &m : meshes)
if (m->material)
m->material->GetShader().ShowWeight(bWeightColors);
UpdateShaders(m);
}

void SetSegmentColors(bool bVisible = true) {
bSegmentColors = bVisible;

for (auto &m : meshes)
if (m->material)
m->material->GetShader().ShowSegments(bSegmentColors);
}

void ToggleWeightColors() {
if (bWeightColors)
bWeightColors = false;
else
bWeightColors = true;

for (auto &m : activeMeshes)
if (m->material)
m->material->GetShader().ShowWeight(bWeightColors);
UpdateShaders(m);
}
};

0 comments on commit f250115

Please sign in to comment.