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.
89 lines
3.3 KiB
89 lines
3.3 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 "VertexColor.h"
|
||
|
14 years ago
|
|
||
|
|
#include <Utility/Resource.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 "VertexColor2D.vert"; }
|
||
|
|
template<> constexpr const char* vertexShaderName<3>() { return "VertexColor3D.vert"; }
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
template<UnsignedInt dimensions> VertexColor<dimensions>::VertexColor(): transformationProjectionMatrixUniform(0) {
|
||
|
14 years ago
|
Corrade::Utility::Resource rs("MagnumShaders");
|
||
|
|
|
||
|
|
#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"));
|
||
|
14 years ago
|
vertexShader.addSource(rs.get(vertexShaderName<dimensions>()));
|
||
|
14 years ago
|
attachShader(vertexShader);
|
||
|
|
|
||
|
|
Shader fragmentShader(v, Shader::Type::Fragment);
|
||
|
|
fragmentShader.addSource(rs.get("compatibility.glsl"));
|
||
|
13 years ago
|
fragmentShader.addSource(rs.get("VertexColor.frag"));
|
||
|
14 years ago
|
attachShader(fragmentShader);
|
||
|
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_attrib_location>() ||
|
||
|
13 years ago
|
Context::current()->version() == Version::GL210)
|
||
|
14 years ago
|
#else
|
||
|
13 years ago
|
if(!Context::current()->isVersionSupported(Version::GLES300))
|
||
|
14 years ago
|
#endif
|
||
|
13 years ago
|
{
|
||
|
14 years ago
|
bindAttributeLocation(Position::Location, "position");
|
||
|
|
bindAttributeLocation(Color::Location, "color");
|
||
|
|
}
|
||
|
|
|
||
|
|
link();
|
||
|
|
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>())
|
||
|
14 years ago
|
#endif
|
||
|
13 years ago
|
{
|
||
|
14 years ago
|
transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix");
|
||
|
|
}
|
||
|
13 years ago
|
|
||
|
|
/* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */
|
||
|
|
#ifdef MAGNUM_TARGET_GLES
|
||
|
|
setTransformationProjectionMatrix(typename DimensionTraits<dimensions>::MatrixType());
|
||
|
|
#endif
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
template class VertexColor<2>;
|
||
|
|
template class VertexColor<3>;
|
||
|
14 years ago
|
|
||
|
|
}}
|