mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-07 03:13:49 +00:00
Compile shader from keys if shader storage binary is invalid
This commit is contained in:
parent
402cf6f8b6
commit
e129d66c22
|
@ -202,12 +202,10 @@ bool ShaderStorage::saveShadersStorage(const graphics::Combiners & _combiners) c
|
||||||
|
|
||||||
static
|
static
|
||||||
CombinerProgramImpl * _readCombinerProgramFromStream(std::istream & _is,
|
CombinerProgramImpl * _readCombinerProgramFromStream(std::istream & _is,
|
||||||
|
CombinerKey& _cmbKey,
|
||||||
CombinerProgramUniformFactory & _uniformFactory,
|
CombinerProgramUniformFactory & _uniformFactory,
|
||||||
opengl::CachedUseProgram * _useProgram)
|
opengl::CachedUseProgram * _useProgram)
|
||||||
{
|
{
|
||||||
CombinerKey cmbKey;
|
|
||||||
cmbKey.read(_is);
|
|
||||||
|
|
||||||
int inputs;
|
int inputs;
|
||||||
_is.read((char*)&inputs, sizeof(inputs));
|
_is.read((char*)&inputs, sizeof(inputs));
|
||||||
CombinerInputs cmbInputs(inputs);
|
CombinerInputs cmbInputs(inputs);
|
||||||
|
@ -220,15 +218,17 @@ CombinerProgramImpl * _readCombinerProgramFromStream(std::istream & _is,
|
||||||
_is.read(binary.data(), binaryLength);
|
_is.read(binary.data(), binaryLength);
|
||||||
|
|
||||||
GLuint program = glCreateProgram();
|
GLuint program = glCreateProgram();
|
||||||
const bool isRect = cmbKey.isRectKey();
|
const bool isRect = _cmbKey.isRectKey();
|
||||||
glsl::Utils::locateAttributes(program, isRect, cmbInputs.usesTexture());
|
glsl::Utils::locateAttributes(program, isRect, cmbInputs.usesTexture());
|
||||||
glProgramBinary(program, binaryFormat, binary.data(), binaryLength);
|
glProgramBinary(program, binaryFormat, binary.data(), binaryLength);
|
||||||
assert(glsl::Utils::checkProgramLinkStatus(program));
|
if (!glsl::Utils::checkProgramLinkStatus(program, true)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
UniformGroups uniforms;
|
UniformGroups uniforms;
|
||||||
_uniformFactory.buildUniforms(program, cmbInputs, cmbKey, uniforms);
|
_uniformFactory.buildUniforms(program, cmbInputs, _cmbKey, uniforms);
|
||||||
|
|
||||||
return new CombinerProgramImpl(cmbKey, program, _useProgram, cmbInputs, std::move(uniforms));
|
return new CombinerProgramImpl(_cmbKey, program, _useProgram, cmbInputs, std::move(uniforms));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShaderStorage::_loadFromCombinerKeys(graphics::Combiners & _combiners)
|
bool ShaderStorage::_loadFromCombinerKeys(graphics::Combiners & _combiners)
|
||||||
|
@ -344,9 +344,21 @@ bool ShaderStorage::loadShadersStorage(graphics::Combiners & _combiners)
|
||||||
f32 progress = 0.0f;
|
f32 progress = 0.0f;
|
||||||
f32 percents = percent;
|
f32 percents = percent;
|
||||||
for (u32 i = 0; i < len; ++i) {
|
for (u32 i = 0; i < len; ++i) {
|
||||||
CombinerProgramImpl * pCombiner = _readCombinerProgramFromStream(fin, uniformFactory, m_useProgram);
|
CombinerKey cmbKey;
|
||||||
|
cmbKey.read(fin);
|
||||||
|
|
||||||
|
CombinerProgramImpl * pCombiner = _readCombinerProgramFromStream(fin, cmbKey, uniformFactory, m_useProgram);
|
||||||
|
|
||||||
|
if (pCombiner != nullptr) {
|
||||||
pCombiner->update(true);
|
pCombiner->update(true);
|
||||||
_combiners[pCombiner->getKey()] = pCombiner;
|
_combiners[pCombiner->getKey()] = pCombiner;
|
||||||
|
} else {
|
||||||
|
LOG(LOG_ERROR, "Shader is not a valid binary compiling from key instead");
|
||||||
|
graphics::CombinerProgram *pCombinerFromKey = Combiner_Compile(cmbKey);
|
||||||
|
pCombinerFromKey->update(true);
|
||||||
|
_combiners[cmbKey] = pCombinerFromKey;
|
||||||
|
}
|
||||||
|
|
||||||
progress += step;
|
progress += step;
|
||||||
if (progress > percents) {
|
if (progress > percents) {
|
||||||
displayLoadProgress(L"LOAD COMBINER SHADERS %.1f%%", f32(i + 1) * 100.f / f32(len) );
|
displayLoadProgress(L"LOAD COMBINER SHADERS %.1f%%", f32(i + 1) * 100.f / f32(len) );
|
||||||
|
|
|
@ -52,9 +52,9 @@ bool Utils::checkShaderCompileStatus(GLuint obj)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Utils::checkProgramLinkStatus(GLuint obj)
|
static
|
||||||
|
bool _checkProgramLinkStatus(GLuint obj)
|
||||||
{
|
{
|
||||||
#ifdef GL_DEBUG
|
|
||||||
GLint status;
|
GLint status;
|
||||||
glGetProgramiv(obj, GL_LINK_STATUS, &status);
|
glGetProgramiv(obj, GL_LINK_STATUS, &status);
|
||||||
if (status == GL_FALSE) {
|
if (status == GL_FALSE) {
|
||||||
|
@ -64,10 +64,20 @@ bool Utils::checkProgramLinkStatus(GLuint obj)
|
||||||
LOG(LOG_ERROR, "shader_link error: %s", shader_log);
|
LOG(LOG_ERROR, "shader_link error: %s", shader_log);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Utils::checkProgramLinkStatus(GLuint obj, bool _force)
|
||||||
|
{
|
||||||
|
#ifdef GL_DEBUG
|
||||||
|
return _checkProgramLinkStatus(obj);
|
||||||
|
#else
|
||||||
|
if (_force)
|
||||||
|
return _checkProgramLinkStatus(obj);
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void Utils::logErrorShader(GLenum _shaderType, const std::string & _strShader)
|
void Utils::logErrorShader(GLenum _shaderType, const std::string & _strShader)
|
||||||
{
|
{
|
||||||
LOG(LOG_ERROR, "Error in %s shader", _shaderType == GL_VERTEX_SHADER ? "vertex" : "fragment");
|
LOG(LOG_ERROR, "Error in %s shader", _shaderType == GL_VERTEX_SHADER ? "vertex" : "fragment");
|
||||||
|
|
|
@ -8,7 +8,7 @@ namespace glsl {
|
||||||
struct Utils {
|
struct Utils {
|
||||||
static void locateAttributes(GLuint _program, bool _rect, bool _textures);
|
static void locateAttributes(GLuint _program, bool _rect, bool _textures);
|
||||||
static bool checkShaderCompileStatus(GLuint obj);
|
static bool checkShaderCompileStatus(GLuint obj);
|
||||||
static bool checkProgramLinkStatus(GLuint obj);
|
static bool checkProgramLinkStatus(GLuint obj, bool _force = false);
|
||||||
static void logErrorShader(GLenum _shaderType, const std::string & _strShader);
|
static void logErrorShader(GLenum _shaderType, const std::string & _strShader);
|
||||||
static GLuint createRectShaderProgram(const char * _strVertex, const char * _strFragment);
|
static GLuint createRectShaderProgram(const char * _strVertex, const char * _strFragment);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user