Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/ShaderManager.cpp
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 254 Lines • ▼ Show 20 Lines | #endif | ||||
if (isGLSL) | if (isGLSL) | ||||
program = CShaderProgramPtr(CShaderProgram::ConstructGLSL(vertexFile, fragmentFile, defines, vertexAttribs, streamFlags)); | program = CShaderProgramPtr(CShaderProgram::ConstructGLSL(vertexFile, fragmentFile, defines, vertexAttribs, streamFlags)); | ||||
else | else | ||||
program = CShaderProgramPtr(CShaderProgram::ConstructARB(vertexFile, fragmentFile, defines, vertexUniforms, fragmentUniforms, streamFlags)); | program = CShaderProgramPtr(CShaderProgram::ConstructARB(vertexFile, fragmentFile, defines, vertexUniforms, fragmentUniforms, streamFlags)); | ||||
program->Reload(); | program->Reload(); | ||||
// m_HotloadFiles[xmlFilename].insert(program); // TODO: should reload somehow when the XML changes | // m_HotloadFiles[xmlFilename].insert(program); // TODO: should reload somehow when the XML changes | ||||
m_HotloadFiles[vertexFile].insert(program); | for (const VfsPath& path : program->GetFileDependencies()) | ||||
m_HotloadFiles[fragmentFile].insert(program); | AddProgramFileDependency(program, path); | ||||
return true; | return true; | ||||
} | } | ||||
static GLenum ParseComparisonFunc(const CStr& str) | static GLenum ParseComparisonFunc(const CStr& str) | ||||
{ | { | ||||
if (str == "never") | if (str == "never") | ||||
return GL_NEVER; | return GL_NEVER; | ||||
▲ Show 20 Lines • Show All 279 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
return static_cast<CShaderManager*>(param)->ReloadChangedFile(path); | return static_cast<CShaderManager*>(param)->ReloadChangedFile(path); | ||||
} | } | ||||
Status CShaderManager::ReloadChangedFile(const VfsPath& path) | Status CShaderManager::ReloadChangedFile(const VfsPath& path) | ||||
{ | { | ||||
// Find all shaders using this file | // Find all shaders using this file | ||||
HotloadFilesMap::iterator files = m_HotloadFiles.find(path); | HotloadFilesMap::iterator files = m_HotloadFiles.find(path); | ||||
if (files != m_HotloadFiles.end()) | if (files == m_HotloadFiles.end()) | ||||
Stan: Could be committed separately | |||||
vladislavbelovAuthorUnsubmitted Done Inline ActionsMaybe, but that's the only part from the original patch. vladislavbelov: Maybe, but that's the only part from the original patch. | |||||
{ | return INFO::OK; | ||||
// Reload all shaders using this file | // Reload all shaders using this file | ||||
for (std::set<std::weak_ptr<CShaderProgram> >::iterator it = files->second.begin(); it != files->second.end(); ++it) | for (const std::weak_ptr<CShaderProgram>& ptr : files->second) | ||||
{ | if (std::shared_ptr<CShaderProgram> program = ptr.lock()) | ||||
if (std::shared_ptr<CShaderProgram> program = it->lock()) | |||||
program->Reload(); | program->Reload(); | ||||
} | |||||
} | |||||
// TODO: hotloading changes to shader XML files and effect XML files would be nice | // TODO: hotloading changes to shader XML files and effect XML files would be nice | ||||
return INFO::OK; | return INFO::OK; | ||||
} | } | ||||
void CShaderManager::AddProgramFileDependency(const CShaderProgramPtr& program, const VfsPath& path) | |||||
{ | |||||
m_HotloadFiles[path].insert(program); | |||||
} |
Wildfire Games · Phabricator
Could be committed separately