Browse Source

Blind port of PhongShader to OpenGL ES 2.0.

pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
084294e60b
  1. 3
      src/Shaders/CMakeLists.txt
  2. 23
      src/Shaders/PhongShader.cpp
  3. 4
      src/Shaders/PhongShader.frag
  4. 5
      src/Shaders/PhongShader.vert
  5. 14
      src/Shaders/compatibility.glsl

3
src/Shaders/CMakeLists.txt

@ -1,6 +1,7 @@
corrade_add_resource(MagnumShaders_RCS MagnumShaders
FlatShader2D.vert FlatShader2D.frag
PhongShader.frag PhongShader.vert)
PhongShader.frag PhongShader.vert
compatibility.glsl)
set(MagnumShaders_SRCS
FlatShader.cpp
PhongShader.cpp

23
src/Shaders/PhongShader.cpp

@ -24,11 +24,28 @@ namespace Magnum { namespace Shaders {
PhongShader::PhongShader() {
Corrade::Utility::Resource rs("MagnumShaders");
Version v = Context::current()->isVersionSupported(Version::GL320) ? Version::GL320 : Version::GL210;
attachShader(Shader::fromData(v, Shader::Type::Vertex, rs.get("PhongShader.vert")));
attachShader(Shader::fromData(v, Shader::Type::Fragment, rs.get("PhongShader.frag")));
#ifndef MAGNUM_TARGET_GLES
Version v = Context::current()->supportedVersion({Version::GL320, Version::GL210});
#else
Version v = Context::current()->supportedVersion({Version::GLES300, Version::GLES200});
#endif
Shader vertexShader(v, Shader::Type::Vertex);
vertexShader.addSource(rs.get("compatibility.glsl"));
vertexShader.addSource(rs.get("PhongShader.vert"));
attachShader(vertexShader);
Shader fragmentShader(v, Shader::Type::Fragment);
fragmentShader.addSource(rs.get("compatibility.glsl"));
fragmentShader.addSource(rs.get("PhongShader.frag"));
attachShader(fragmentShader);
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_attrib_location>()) {
#else
if(!Context::current()->isVersionSupported(Version::GLES300)) {
#endif
bindAttributeLocation(Position::Location, "position");
bindAttributeLocation(Normal::Location, "normal");
}

4
src/Shaders/PhongShader.frag

@ -1,4 +1,4 @@
#if __VERSION__ == 120
#ifndef NEW_GLSL
#define in varying
#define color gl_FragColor
#endif
@ -13,7 +13,7 @@ in vec3 transformedNormal;
in vec3 lightDirection;
in vec3 cameraDirection;
#if __VERSION__ != 120
#ifdef NEW_GLSL
out vec4 color;
#endif

5
src/Shaders/PhongShader.vert

@ -1,4 +1,4 @@
#if __VERSION__ == 120
#ifndef NEW_GLSL
#define in attribute
#define out varying
#endif
@ -7,8 +7,7 @@ uniform mat4 transformationMatrix;
uniform mat4 projectionMatrix;
uniform vec3 light;
#if __VERSION__ != 120 && defined(GL_ARB_explicit_attrib_location)
#extension GL_ARB_explicit_attrib_location: enable
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = 0) in vec4 position;
layout(location = 1) in vec3 normal;
#else

14
src/Shaders/compatibility.glsl

@ -0,0 +1,14 @@
#if (!defined(GL_ES) && __VERSION__ >= 130) || (defined(GL_ES) && __VERSION__ >= 300)
#define NEW_GLSL
#endif
/* On NVidia and GLSL 1.20 layout qualifiers result in parsing error, even if
the extension is defined as supported */
#if !defined(GL_ES) && __VERSION__ >= 120 && defined(GL_ARB_explicit_attrib_location)
#extension GL_ARB_explicit_attrib_location: enable
#define EXPLICIT_ATTRIB_LOCATION
#endif
#if defined(GL_ES) && __VERSION__ >= 300
#define EXPLICIT_ATTRIB_LOCATION
#endif
Loading…
Cancel
Save