Skip to content

Commit

Permalink
Blacklist gl_FragDepth on Intel windows driver
Browse files Browse the repository at this point in the history
  • Loading branch information
c42f committed Aug 10, 2015
1 parent 37eb781 commit 5e02d90
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 21 deletions.
11 changes: 7 additions & 4 deletions shaders/cylindrical_proj.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void main()
if (markerShape < 0) // markerShape == -1: discarded.
discard;
// (markerShape == 0: Square shape)
gl_FragDepth = gl_FragCoord.z;
float fragDepth = gl_FragCoord.z;
if (markerShape > 0 && pointScreenSize > pointScreenSizeLimit)
{
float w = markerWidth;
Expand All @@ -174,9 +174,9 @@ void main()
float r = length(p);
if (r > 1)
discard;
gl_FragDepth += projectionMatrix[3][2] * gl_FragCoord.w*gl_FragCoord.w
// TODO: Why is the factor of 0.5 required here?
* 0.5*modifiedPointRadius*sqrt(1-r*r);
fragDepth += projectionMatrix[3][2] * gl_FragCoord.w*gl_FragCoord.w
// TODO: Why is the factor of 0.5 required here?
* 0.5*modifiedPointRadius*sqrt(1-r*r);
}
else if (markerShape == 2) // shape: o
{
Expand All @@ -197,6 +197,9 @@ void main()
discard;
}
}
# ifndef NO_GL_FRAG_DEPTH
gl_FragDepth = fragDepth;
# endif
fragColor = vec4(pointColor, 1);
}

Expand Down
11 changes: 7 additions & 4 deletions shaders/generic_points.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void main()
if (markerShape2 < 0) // markerShape2 == -1: discarded.
discard;
// (markerShape2 == 1: Square shape)
gl_FragDepth = gl_FragCoord.z;
float fragDepth = gl_FragCoord.z;
if (markerShape2 != 1 && pointScreenSize > pointScreenSizeLimit)
{
float w = markerWidth;
Expand All @@ -103,9 +103,9 @@ void main()
float r = length(p);
if (r > 1)
discard;
gl_FragDepth += projectionMatrix[3][2] * gl_FragCoord.w*gl_FragCoord.w
// TODO: Why is the factor of 0.5 required here?
* 0.5*modifiedPointRadius*sqrt(1-r*r);
fragDepth += projectionMatrix[3][2] * gl_FragCoord.w*gl_FragCoord.w
// TODO: Why is the factor of 0.5 required here?
* 0.5*modifiedPointRadius*sqrt(1-r*r);
}
else if (markerShape2 == 2) // shape: o
{
Expand All @@ -126,6 +126,9 @@ void main()
discard;
}
}
# ifndef NO_GL_FRAG_DEPTH
gl_FragDepth = fragDepth;
# endif
fragColor = vec4(pointColor, 1);
}

Expand Down
11 changes: 7 additions & 4 deletions shaders/las_points.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void main()
if (markerShape < 0) // markerShape == -1: discarded.
discard;
// (markerShape == 0: Square shape)
gl_FragDepth = gl_FragCoord.z;
float fragDepth = gl_FragCoord.z;
if (markerShape > 0 && pointScreenSize > pointScreenSizeLimit)
{
float w = markerWidth;
Expand All @@ -180,9 +180,9 @@ void main()
float r = length(p);
if (r > 1)
discard;
gl_FragDepth += projectionMatrix[3][2] * gl_FragCoord.w*gl_FragCoord.w
// TODO: Why is the factor of 0.5 required here?
* 0.5*modifiedPointRadius*sqrt(1-r*r);
fragDepth += projectionMatrix[3][2] * gl_FragCoord.w*gl_FragCoord.w
// TODO: Why is the factor of 0.5 required here?
* 0.5*modifiedPointRadius*sqrt(1-r*r);
}
else if (markerShape == 2) // shape: o
{
Expand All @@ -203,6 +203,9 @@ void main()
discard;
}
}
# ifndef NO_GL_FRAG_DEPTH
gl_FragDepth = fragDepth;
# endif
fragColor = vec4(pointColor, 1);
}

Expand Down
12 changes: 7 additions & 5 deletions shaders/las_points_lod.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ void main()
if (stippleThresholds[int(gl_FragCoord.x) % 4 + 4*(int(gl_FragCoord.y) % 4)] > fragCoverage)
discard;
*/
// (fragMarkerShape == 0: Square shape)
gl_FragDepth = gl_FragCoord.z;
float fragDepth = gl_FragCoord.z;
if (fragMarkerShape > 0 && pointScreenSize > pointScreenSizeLimit)
{
vec2 p = 2*(gl_PointCoord - 0.5);
Expand All @@ -117,11 +116,14 @@ void main()
discard;
if (fragMarkerShape == 1) // shape: sphere
{
gl_FragDepth += projectionMatrix[3][2] * gl_FragCoord.w*gl_FragCoord.w
// TODO: Why is the factor of 0.5 required here?
* 0.5*modifiedPointRadius*sqrt(1-r*r);
fragDepth += projectionMatrix[3][2] * gl_FragCoord.w*gl_FragCoord.w
// TODO: Why is the factor of 0.5 required here?
* 0.5*modifiedPointRadius*sqrt(1-r*r);
}
}
# ifndef NO_GL_FRAG_DEPTH
gl_FragDepth = fragDepth;
# endif
fragColor = vec4(pointColor, 1);
}

Expand Down
11 changes: 7 additions & 4 deletions shaders/lod_debug.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void main()
if (markerShape < 0) // markerShape == -1: discarded.
discard;
// (markerShape == 0: Square shape)
gl_FragDepth = gl_FragCoord.z;
float fragDepth = gl_FragCoord.z;
if (markerShape > 0 && pointScreenSize > pointScreenSizeLimit)
{
float w = markerWidth;
Expand All @@ -183,9 +183,9 @@ void main()
float r = length(p);
if (r > 1)
discard;
gl_FragDepth += projectionMatrix[3][2] * gl_FragCoord.w*gl_FragCoord.w
// TODO: Why is the factor of 0.5 required here?
* 0.5*modifiedPointRadius*sqrt(1-r*r);
fragDepth += projectionMatrix[3][2] * gl_FragCoord.w*gl_FragCoord.w
// TODO: Why is the factor of 0.5 required here?
* 0.5*modifiedPointRadius*sqrt(1-r*r);
}
else if (markerShape == 2) // shape: o
{
Expand All @@ -206,6 +206,9 @@ void main()
discard;
}
}
# ifndef NO_GL_FRAG_DEPTH
gl_FragDepth = fragDepth;
# endif
fragColor = vec4(pointColor, 1);
}

Expand Down
1 change: 1 addition & 0 deletions src/glutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ inline void glLoadMatrix(const Imath::M44f& m)
}



//------------------------------------------------------------------------------
// Shader utilities

Expand Down
28 changes: 28 additions & 0 deletions src/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,33 @@
#include <QtGui/QComboBox>


/// Make shader #define flags for hardware or driver-dependent blacklisted
/// features. Current list:
///
/// NO_GL_FRAG_DEPTH
///
static QByteArray makeBlacklistDefines()
{
bool isWindows = false;
# ifdef _WIN32
isWindows = true;
# endif
bool isIntel = false;
// Extremely useful list of GL_VENDOR strings seen in the wild:
// http://feedback.wildfiregames.com/report/opengl/feature/GL_VENDOR
QString vendorStr = (const char*)glGetString(GL_VENDOR);
if (vendorStr.contains("intel", Qt::CaseInsensitive))
isIntel = true;
QByteArray defines;
// Blacklist use of gl_FragDepth with Intel drivers on windows - for some
// reason, this interacts badly with any use of gl_FragCoord, leading to
// gross rendering artifacts.
if (isWindows && isIntel)
defines += "#define NO_GL_FRAG_DEPTH\n";
return defines;
}


//------------------------------------------------------------------------------
// Shader implementation
bool Shader::compileSourceCode(const QByteArray& src)
Expand All @@ -49,6 +76,7 @@ bool Shader::compileSourceCode(const QByteArray& src)
case QGLShader::Vertex: defines += "#define VERTEX_SHADER\n"; break;
case QGLShader::Fragment: defines += "#define FRAGMENT_SHADER\n"; break;
}
defines += makeBlacklistDefines();
QByteArray modifiedSrc = src;
// Add defines. Some shader compilers require #version to come first (even
// before any #defines) so detect #version if it's present and put the
Expand Down
7 changes: 7 additions & 0 deletions src/view3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ void View3D::initializeGL()
m_badOpenGL = true;
return;
}
g_logger.info("OpenGL implementation:\n"
"GL_VENDOR = %s\n"
"GL_RENDERER = %s\n"
"GL_VERSION = %s",
(const char*)glGetString(GL_VENDOR),
(const char*)glGetString(GL_RENDERER),
(const char*)glGetString(GL_VERSION));
m_shaderProgram->setContext(context());
m_meshFaceShader.reset(new ShaderProgram(context()));
m_meshFaceShader->setShaderFromSourceFile("shaders:meshface.glsl");
Expand Down

0 comments on commit 5e02d90

Please sign in to comment.