Skip to content

Commit

Permalink
Shaders: fix compilation of MeshVisualizer on WebGL and ANGLE.
Browse files Browse the repository at this point in the history
WebGL mandates that array subscription is done with constant expression,
ANGLE too (but I think that has also something to do with D3D9
limitations). This is however allowed by OpenGL ES 2.0 specification, so
enabling the workaround only for WebGL and ANGLE (i.e., this won't apply
to Native Client using native GL drivers).
  • Loading branch information
mosra committed Jun 29, 2014
1 parent fcea05e commit 4a44d3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Magnum/Shaders/MeshVisualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ MeshVisualizer::MeshVisualizer(const Flags flags): flags(flags), transformationP

vert.addSource(flags & Flag::Wireframe ? "#define WIREFRAME_RENDERING\n" : "")
.addSource(flags & Flag::NoGeometryShader ? "#define NO_GEOMETRY_SHADER\n" : "")
#ifdef MAGNUM_TARGET_WEBGL
.addSource("#define SUBSCRIPTING_WORKAROUND\n")
#elif defined(MAGNUM_TARGET_GLES)
.addSource(Context::current()->detectedDriver() & Context::DetectedDriver::ProbablyAngle ?
"#define SUBSCRIPTING_WORKAROUND\n" : "")
#endif
.addSource(rs.get("generic.glsl"))
.addSource(rs.get("MeshVisualizer.vert"));
frag.addSource(flags & Flag::Wireframe ? "#define WIREFRAME_RENDERING\n" : "")
Expand Down
9 changes: 8 additions & 1 deletion src/Magnum/Shaders/MeshVisualizer.vert
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,17 @@ void main() {

#if defined(WIREFRAME_RENDERING) && defined(NO_GEOMETRY_SHADER)
barycentric = vec3(0.0);
#ifndef NEW_GLSL

#ifdef SUBSCRIPTING_WORKAROUND
int i = int(mod(vertexIndex, 3.0));
if(i == 0) barycentric.x = 1.0;
else if(i == 1) barycentric.y = 1.0;
else barycentric.z = 1.0;
#elif !defined(NEW_GLSL)
barycentric[int(mod(vertexIndex, 3.0))] = 1.0;
#else
barycentric[gl_VertexID % 3] = 1.0;
#endif

#endif
}

0 comments on commit 4a44d3b

Please sign in to comment.