Browse Source

Shaders: NO, these are not layers.

pull/432/head
Vladimír Vondruš 6 years ago
parent
commit
3759d26a7d
  1. 2
      src/Magnum/Shaders/AbstractVector.cpp
  2. 6
      src/Magnum/Shaders/AbstractVector.h
  3. 2
      src/Magnum/Shaders/DistanceFieldVector.cpp
  4. 6
      src/Magnum/Shaders/Flat.cpp
  5. 26
      src/Magnum/Shaders/Phong.cpp
  6. 2
      src/Magnum/Shaders/Vector.cpp

2
src/Magnum/Shaders/AbstractVector.cpp

@ -31,7 +31,7 @@
namespace Magnum { namespace Shaders {
template<UnsignedInt dimensions> AbstractVector<dimensions>& AbstractVector<dimensions>::bindVectorTexture(GL::Texture2D& texture) {
texture.bind(VectorTextureLayer);
texture.bind(VectorTextureUnit);
return *this;
}

6
src/Magnum/Shaders/AbstractVector.h

@ -98,9 +98,9 @@ template<UnsignedInt dimensions> class AbstractVector: public GL::AbstractShader
#endif
/* Those textures are quite specific (and likely reused multiple times
per frame for e.g. text rendering, so put them in a specific slot.
Older iOS (and iOS WebGL) has only 8 texture binding slots, so can't
go above that. Binding 7 is used by TextureTools::DistanceField. */
enum: Int { VectorTextureLayer = 6 };
Older iOS (and iOS WebGL) has only 8 texture units, so can't go
above that. Unit 7 is used by TextureTools::DistanceField. */
enum: Int { VectorTextureUnit = 6 };
explicit AbstractVector(NoCreateT) noexcept: GL::AbstractShaderProgram{NoCreate} {}
explicit AbstractVector() = default;

2
src/Magnum/Shaders/DistanceFieldVector.cpp

@ -99,7 +99,7 @@ template<UnsignedInt dimensions> DistanceFieldVector<dimensions>::DistanceFieldV
#endif
{
GL::AbstractShaderProgram::setUniform(GL::AbstractShaderProgram::uniformLocation("vectorTexture"),
AbstractVector<dimensions>::VectorTextureLayer);
AbstractVector<dimensions>::VectorTextureUnit);
}
/* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */

6
src/Magnum/Shaders/Flat.cpp

@ -42,7 +42,7 @@
namespace Magnum { namespace Shaders {
namespace {
enum: Int { TextureLayer = 0 };
enum: Int { TextureUnit = 0 };
}
template<UnsignedInt dimensions> Flat<dimensions>::Flat(const Flags flags): _flags(flags) {
@ -125,7 +125,7 @@ template<UnsignedInt dimensions> Flat<dimensions>::Flat(const Flags flags): _fla
if(!GL::Context::current().isExtensionSupported<GL::Extensions::ARB::shading_language_420pack>(version))
#endif
{
if(flags & Flag::Textured) setUniform(uniformLocation("textureData"), TextureLayer);
if(flags & Flag::Textured) setUniform(uniformLocation("textureData"), TextureUnit);
}
/* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */
@ -158,7 +158,7 @@ template<UnsignedInt dimensions> Flat<dimensions>& Flat<dimensions>::setColor(co
template<UnsignedInt dimensions> Flat<dimensions>& Flat<dimensions>::bindTexture(GL::Texture2D& texture) {
CORRADE_ASSERT(_flags & Flag::Textured,
"Shaders::Flat::bindTexture(): the shader was not created with texturing enabled", *this);
texture.bind(TextureLayer);
texture.bind(TextureUnit);
return *this;
}

26
src/Magnum/Shaders/Phong.cpp

@ -47,10 +47,10 @@ namespace Magnum { namespace Shaders {
namespace {
enum: Int {
AmbientTextureLayer = 0,
DiffuseTextureLayer = 1,
SpecularTextureLayer = 2,
NormalTextureLayer = 3
AmbientTextureUnit = 0,
DiffuseTextureUnit = 1,
SpecularTextureUnit = 2,
NormalTextureUnit = 3
};
}
@ -179,11 +179,11 @@ Phong::Phong(const Flags flags, const UnsignedInt lightCount): _flags{flags}, _l
if(flags && !GL::Context::current().isExtensionSupported<GL::Extensions::ARB::shading_language_420pack>(version))
#endif
{
if(flags & Flag::AmbientTexture) setUniform(uniformLocation("ambientTexture"), AmbientTextureLayer);
if(flags & Flag::AmbientTexture) setUniform(uniformLocation("ambientTexture"), AmbientTextureUnit);
if(lightCount) {
if(flags & Flag::DiffuseTexture) setUniform(uniformLocation("diffuseTexture"), DiffuseTextureLayer);
if(flags & Flag::SpecularTexture) setUniform(uniformLocation("specularTexture"), SpecularTextureLayer);
if(flags & Flag::NormalTexture) setUniform(uniformLocation("normalTexture"), NormalTextureLayer);
if(flags & Flag::DiffuseTexture) setUniform(uniformLocation("diffuseTexture"), DiffuseTextureUnit);
if(flags & Flag::SpecularTexture) setUniform(uniformLocation("specularTexture"), SpecularTextureUnit);
if(flags & Flag::NormalTexture) setUniform(uniformLocation("normalTexture"), NormalTextureUnit);
}
}
@ -216,7 +216,7 @@ Phong& Phong::setAmbientColor(const Magnum::Color4& color) {
Phong& Phong::bindAmbientTexture(GL::Texture2D& texture) {
CORRADE_ASSERT(_flags & Flag::AmbientTexture,
"Shaders::Phong::bindAmbientTexture(): the shader was not created with ambient texture enabled", *this);
texture.bind(AmbientTextureLayer);
texture.bind(AmbientTextureUnit);
return *this;
}
@ -228,7 +228,7 @@ Phong& Phong::setDiffuseColor(const Magnum::Color4& color) {
Phong& Phong::bindDiffuseTexture(GL::Texture2D& texture) {
CORRADE_ASSERT(_flags & Flag::DiffuseTexture,
"Shaders::Phong::bindDiffuseTexture(): the shader was not created with diffuse texture enabled", *this);
if(_lightCount) texture.bind(DiffuseTextureLayer);
if(_lightCount) texture.bind(DiffuseTextureUnit);
return *this;
}
@ -240,21 +240,21 @@ Phong& Phong::setSpecularColor(const Magnum::Color4& color) {
Phong& Phong::bindSpecularTexture(GL::Texture2D& texture) {
CORRADE_ASSERT(_flags & Flag::SpecularTexture,
"Shaders::Phong::bindSpecularTexture(): the shader was not created with specular texture enabled", *this);
if(_lightCount) texture.bind(SpecularTextureLayer);
if(_lightCount) texture.bind(SpecularTextureUnit);
return *this;
}
Phong& Phong::bindNormalTexture(GL::Texture2D& texture) {
CORRADE_ASSERT(_flags & Flag::NormalTexture,
"Shaders::Phong::bindNormalTexture(): the shader was not created with normal texture enabled", *this);
if(_lightCount) texture.bind(NormalTextureLayer);
if(_lightCount) texture.bind(NormalTextureUnit);
return *this;
}
Phong& Phong::bindTextures(GL::Texture2D* ambient, GL::Texture2D* diffuse, GL::Texture2D* specular, GL::Texture2D* normal) {
CORRADE_ASSERT(_flags & (Flag::AmbientTexture|Flag::DiffuseTexture|Flag::SpecularTexture|Flag::NormalTexture),
"Shaders::Phong::bindTextures(): the shader was not created with any textures enabled", *this);
GL::AbstractTexture::bind(AmbientTextureLayer, {ambient, diffuse, specular, normal});
GL::AbstractTexture::bind(AmbientTextureUnit, {ambient, diffuse, specular, normal});
return *this;
}

2
src/Magnum/Shaders/Vector.cpp

@ -96,7 +96,7 @@ template<UnsignedInt dimensions> Vector<dimensions>::Vector(const Flags flags):
if(!GL::Context::current().isExtensionSupported<GL::Extensions::ARB::shading_language_420pack>(version))
#endif
{
GL::AbstractShaderProgram::setUniform(GL::AbstractShaderProgram::uniformLocation("vectorTexture"), AbstractVector<dimensions>::VectorTextureLayer);
GL::AbstractShaderProgram::setUniform(GL::AbstractShaderProgram::uniformLocation("vectorTexture"), AbstractVector<dimensions>::VectorTextureUnit);
}
/* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */

Loading…
Cancel
Save