Use high precision floating point variables if possible.

On desktop medium and high precision is generally the same, at least for mesa drivers. But on some Android devices medium precision is much worse, which causes artifacts. We need high precision float variables in vertex shaders for proper scene rendering. Setting different precision for fragment and vertex shaders seems to be not possible, so we just set it to high for both shader types when it's available.
This commit is contained in:
Deve
2016-09-07 22:39:58 +02:00
parent 78baaff23e
commit f2d1eb7117

View File

@@ -107,11 +107,17 @@ GLuint ShaderBase::loadShader(const std::string &file, unsigned type)
if (CVS->needsRGBBindlessWorkaround())
code << "#define SRGBBindlessFix\n";
#if !defined(USE_GLES2)
//shader compilation fails with some drivers if there is no precision qualifier
if (type == GL_FRAGMENT_SHADER)
code << "precision mediump float;\n";
#if defined(USE_GLES2)
else if (type == GL_VERTEX_SHADER)
#else
int range[2], precision;
glGetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, range, &precision);
if (precision > 0)
code << "precision highp float;\n";
else
code << "precision mediump float;\n";
#endif