mirror of https://github.com/mosra/magnum.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
3.9 KiB
96 lines
3.9 KiB
|
14 years ago
|
/*
|
||
|
|
This file is part of Magnum.
|
||
|
|
|
||
|
13 years ago
|
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
|
||
|
|
|
||
|
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||
|
|
copy of this software and associated documentation files (the "Software"),
|
||
|
|
to deal in the Software without restriction, including without limitation
|
||
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||
|
|
and/or sell copies of the Software, and to permit persons to whom the
|
||
|
|
Software is furnished to do so, subject to the following conditions:
|
||
|
|
|
||
|
|
The above copyright notice and this permission notice shall be included
|
||
|
|
in all copies or substantial portions of the Software.
|
||
|
|
|
||
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||
|
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||
|
|
DEALINGS IN THE SOFTWARE.
|
||
|
14 years ago
|
*/
|
||
|
|
|
||
|
13 years ago
|
#include "Vector.h"
|
||
|
14 years ago
|
|
||
|
|
#include <Utility/Resource.h>
|
||
|
|
|
||
|
|
#include "Context.h"
|
||
|
|
#include "Extensions.h"
|
||
|
|
#include "Shader.h"
|
||
|
|
|
||
|
|
namespace Magnum { namespace Shaders {
|
||
|
|
|
||
|
|
namespace {
|
||
|
13 years ago
|
template<UnsignedInt> constexpr const char* vertexShaderName();
|
||
|
13 years ago
|
template<> constexpr const char* vertexShaderName<2>() { return "AbstractVector2D.vert"; }
|
||
|
|
template<> constexpr const char* vertexShaderName<3>() { return "AbstractVector3D.vert"; }
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
template<UnsignedInt dimensions> Vector<dimensions>::Vector(): transformationProjectionMatrixUniform(0), backgroundColorUniform(1), colorUniform(2) {
|
||
|
13 years ago
|
Utility::Resource rs("MagnumShaders");
|
||
|
14 years ago
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
const Version version = Context::current()->supportedVersion({Version::GL320, Version::GL310, Version::GL300, Version::GL210});
|
||
|
14 years ago
|
#else
|
||
|
13 years ago
|
const Version version = Context::current()->supportedVersion({Version::GLES300, Version::GLES200});
|
||
|
14 years ago
|
#endif
|
||
|
|
|
||
|
13 years ago
|
Shader vert(version, Shader::Type::Vertex);
|
||
|
13 years ago
|
vert.addSource(rs.get("compatibility.glsl"))
|
||
|
13 years ago
|
.addSource(rs.get("generic.glsl"))
|
||
|
13 years ago
|
.addSource(rs.get(vertexShaderName<dimensions>()));
|
||
|
|
CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile());
|
||
|
|
AbstractShaderProgram::attachShader(vert);
|
||
|
|
|
||
|
13 years ago
|
Shader frag(version, Shader::Type::Fragment);
|
||
|
13 years ago
|
frag.addSource(rs.get("compatibility.glsl"))
|
||
|
|
.addSource(rs.get("Vector.frag"));
|
||
|
|
CORRADE_INTERNAL_ASSERT_OUTPUT(frag.compile());
|
||
|
|
AbstractShaderProgram::attachShader(frag);
|
||
|
14 years ago
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_attrib_location>(version))
|
||
|
14 years ago
|
#else
|
||
|
13 years ago
|
if(!Context::current()->isVersionSupported(Version::GLES300))
|
||
|
14 years ago
|
#endif
|
||
|
13 years ago
|
{
|
||
|
13 years ago
|
AbstractShaderProgram::bindAttributeLocation(AbstractVector<dimensions>::Position::Location, "position");
|
||
|
|
AbstractShaderProgram::bindAttributeLocation(AbstractVector<dimensions>::TextureCoordinates::Location, "textureCoordinates");
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
CORRADE_INTERNAL_ASSERT_OUTPUT(AbstractShaderProgram::link());
|
||
|
14 years ago
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>(version))
|
||
|
14 years ago
|
#endif
|
||
|
13 years ago
|
{
|
||
|
13 years ago
|
transformationProjectionMatrixUniform = AbstractShaderProgram::uniformLocation("transformationProjectionMatrix");
|
||
|
13 years ago
|
backgroundColorUniform = AbstractShaderProgram::uniformLocation("backgroundColor");
|
||
|
13 years ago
|
colorUniform = AbstractShaderProgram::uniformLocation("color");
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shading_language_420pack>(version))
|
||
|
14 years ago
|
#endif
|
||
|
13 years ago
|
{
|
||
|
|
AbstractShaderProgram::setUniform(AbstractShaderProgram::uniformLocation("vectorTexture"), AbstractVector<dimensions>::VectorTextureLayer);
|
||
|
|
}
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
template class Vector<2>;
|
||
|
|
template class Vector<3>;
|
||
|
14 years ago
|
|
||
|
|
}}
|