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.
311 lines
8.8 KiB
311 lines
8.8 KiB
|
13 years ago
|
/*
|
||
|
|
This file is part of Magnum.
|
||
|
|
|
||
|
8 years ago
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
|
||
|
12 years ago
|
Vladimír Vondruš <mosra@centrum.cz>
|
||
|
13 years ago
|
|
||
|
|
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.
|
||
|
|
*/
|
||
|
|
|
||
|
12 years ago
|
#include <Corrade/Utility/Directory.h>
|
||
|
13 years ago
|
|
||
|
12 years ago
|
#include "Magnum/Context.h"
|
||
|
|
#include "Magnum/Extensions.h"
|
||
|
|
#include "Magnum/Shader.h"
|
||
|
9 years ago
|
#include "Magnum/OpenGLTester.h"
|
||
|
13 years ago
|
|
||
|
12 years ago
|
#include "configure.h"
|
||
|
13 years ago
|
|
||
|
13 years ago
|
namespace Magnum { namespace Test {
|
||
|
|
|
||
|
9 years ago
|
struct ShaderGLTest: OpenGLTester {
|
||
|
11 years ago
|
explicit ShaderGLTest();
|
||
|
13 years ago
|
|
||
|
11 years ago
|
void construct();
|
||
|
|
void constructNoVersion();
|
||
|
|
void constructCopy();
|
||
|
|
void constructMove();
|
||
|
13 years ago
|
|
||
|
8 years ago
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
11 years ago
|
void label();
|
||
|
8 years ago
|
#endif
|
||
|
13 years ago
|
|
||
|
11 years ago
|
void addSource();
|
||
|
10 years ago
|
void addSourceNoVersion();
|
||
|
11 years ago
|
void addFile();
|
||
|
|
void compile();
|
||
|
8 years ago
|
void compileUtf8();
|
||
|
10 years ago
|
void compileNoVersion();
|
||
|
13 years ago
|
};
|
||
|
|
|
||
|
|
ShaderGLTest::ShaderGLTest() {
|
||
|
13 years ago
|
addTests({&ShaderGLTest::construct,
|
||
|
12 years ago
|
&ShaderGLTest::constructNoVersion,
|
||
|
13 years ago
|
&ShaderGLTest::constructCopy,
|
||
|
|
&ShaderGLTest::constructMove,
|
||
|
|
|
||
|
8 years ago
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
13 years ago
|
&ShaderGLTest::label,
|
||
|
8 years ago
|
#endif
|
||
|
13 years ago
|
|
||
|
|
&ShaderGLTest::addSource,
|
||
|
10 years ago
|
&ShaderGLTest::addSourceNoVersion,
|
||
|
13 years ago
|
&ShaderGLTest::addFile,
|
||
|
10 years ago
|
&ShaderGLTest::compile,
|
||
|
8 years ago
|
&ShaderGLTest::compileUtf8,
|
||
|
10 years ago
|
&ShaderGLTest::compileNoVersion});
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
|
void ShaderGLTest::construct() {
|
||
|
|
{
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
const Shader shader(Version::GL300, Shader::Type::Fragment);
|
||
|
|
#else
|
||
|
|
const Shader shader(Version::GLES300, Shader::Type::Fragment);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
MAGNUM_VERIFY_NO_ERROR();
|
||
|
|
CORRADE_VERIFY(shader.id() > 0);
|
||
|
|
CORRADE_COMPARE(shader.type(), Shader::Type::Fragment);
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
CORRADE_COMPARE(shader.sources(), std::vector<std::string>{"#version 130\n"});
|
||
|
|
#else
|
||
|
12 years ago
|
CORRADE_COMPARE(shader.sources(), std::vector<std::string>{"#version 300 es\n"});
|
||
|
13 years ago
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
MAGNUM_VERIFY_NO_ERROR();
|
||
|
|
}
|
||
|
|
|
||
|
12 years ago
|
void ShaderGLTest::constructNoVersion() {
|
||
|
|
const Shader shader(Version::None, Shader::Type::Fragment);
|
||
|
|
CORRADE_VERIFY(shader.sources().empty());
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
void ShaderGLTest::constructCopy() {
|
||
|
13 years ago
|
CORRADE_VERIFY(!(std::is_constructible<Shader, const Shader&>{}));
|
||
|
|
CORRADE_VERIFY(!(std::is_assignable<Shader, const Shader&>{}));
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
|
void ShaderGLTest::constructMove() {
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
Shader a(Version::GL300, Shader::Type::Fragment);
|
||
|
|
#else
|
||
|
|
Shader a(Version::GLES300, Shader::Type::Fragment);
|
||
|
|
#endif
|
||
|
|
const Int id = a.id();
|
||
|
|
|
||
|
|
MAGNUM_VERIFY_NO_ERROR();
|
||
|
|
CORRADE_VERIFY(id > 0);
|
||
|
|
|
||
|
|
Shader b(std::move(a));
|
||
|
|
|
||
|
|
CORRADE_COMPARE(a.id(), 0);
|
||
|
|
CORRADE_COMPARE(b.id(), id);
|
||
|
|
CORRADE_COMPARE(b.type(), Shader::Type::Fragment);
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
CORRADE_COMPARE(b.sources(), std::vector<std::string>{"#version 130\n"});
|
||
|
|
#else
|
||
|
12 years ago
|
CORRADE_COMPARE(b.sources(), std::vector<std::string>{"#version 300 es\n"});
|
||
|
13 years ago
|
#endif
|
||
|
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
Shader c(Version::GL210, Shader::Type::Vertex);
|
||
|
|
#else
|
||
|
|
Shader c(Version::GLES200, Shader::Type::Vertex);
|
||
|
|
#endif
|
||
|
|
const Int cId = c.id();
|
||
|
|
c = std::move(b);
|
||
|
|
|
||
|
|
MAGNUM_VERIFY_NO_ERROR();
|
||
|
|
CORRADE_VERIFY(cId > 0);
|
||
|
|
CORRADE_COMPARE(b.id(), cId);
|
||
|
|
CORRADE_COMPARE(c.id(), id);
|
||
|
|
CORRADE_COMPARE(c.type(), Shader::Type::Fragment);
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
CORRADE_COMPARE(c.sources(), std::vector<std::string>{"#version 130\n"});
|
||
|
|
#else
|
||
|
12 years ago
|
CORRADE_COMPARE(c.sources(), std::vector<std::string>{"#version 300 es\n"});
|
||
|
13 years ago
|
#endif
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
8 years ago
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
13 years ago
|
void ShaderGLTest::label() {
|
||
|
|
/* No-Op version is tested in AbstractObjectGLTest */
|
||
|
10 years ago
|
if(!Context::current().isExtensionSupported<Extensions::GL::KHR::debug>() &&
|
||
|
|
!Context::current().isExtensionSupported<Extensions::GL::EXT::debug_label>())
|
||
|
13 years ago
|
CORRADE_SKIP("Required extension is not available");
|
||
|
|
|
||
|
13 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
Shader shader(Version::GL210, Shader::Type::Vertex);
|
||
|
13 years ago
|
#else
|
||
|
|
Shader shader(Version::GLES200, Shader::Type::Vertex);
|
||
|
|
#endif
|
||
|
13 years ago
|
CORRADE_COMPARE(shader.label(), "");
|
||
|
|
|
||
|
|
shader.setLabel("MyShader");
|
||
|
|
CORRADE_COMPARE(shader.label(), "MyShader");
|
||
|
|
|
||
|
|
MAGNUM_VERIFY_NO_ERROR();
|
||
|
|
}
|
||
|
8 years ago
|
#endif
|
||
|
13 years ago
|
|
||
|
13 years ago
|
void ShaderGLTest::addSource() {
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
Shader shader(Version::GL210, Shader::Type::Fragment);
|
||
|
|
#else
|
||
|
|
Shader shader(Version::GLES200, Shader::Type::Fragment);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
shader.addSource("#define FOO BAR\n")
|
||
|
|
.addSource("void main() {}\n");
|
||
|
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
CORRADE_COMPARE(shader.sources(), (std::vector<std::string>{
|
||
|
|
"#version 120\n",
|
||
|
|
"#line 1 1\n",
|
||
|
|
"#define FOO BAR\n",
|
||
|
|
"#line 1 2\n",
|
||
|
|
"void main() {}\n"
|
||
|
|
}));
|
||
|
|
#else
|
||
|
|
CORRADE_COMPARE(shader.sources(), (std::vector<std::string>{
|
||
|
|
"#version 100\n",
|
||
|
|
"#line 1 1\n",
|
||
|
|
"#define FOO BAR\n",
|
||
|
|
"#line 1 2\n",
|
||
|
|
"void main() {}\n"
|
||
|
|
}));
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
10 years ago
|
void ShaderGLTest::addSourceNoVersion() {
|
||
|
|
Shader shader(Version::None, Shader::Type::Fragment);
|
||
|
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
shader.addSource("#version 120\n");
|
||
|
|
#else
|
||
|
|
shader.addSource("#version 100\n");
|
||
|
|
#endif
|
||
|
|
shader.addSource("#define FOO BAR\n")
|
||
|
|
.addSource("void main() {}\n");
|
||
|
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
CORRADE_COMPARE(shader.sources(), (std::vector<std::string>{
|
||
|
10 years ago
|
"",
|
||
|
10 years ago
|
"#version 120\n",
|
||
|
|
"#line 1 1\n",
|
||
|
|
"#define FOO BAR\n",
|
||
|
|
"#line 1 2\n",
|
||
|
|
"void main() {}\n"
|
||
|
|
}));
|
||
|
|
#else
|
||
|
|
CORRADE_COMPARE(shader.sources(), (std::vector<std::string>{
|
||
|
10 years ago
|
"",
|
||
|
10 years ago
|
"#version 100\n",
|
||
|
|
"#line 1 1\n",
|
||
|
|
"#define FOO BAR\n",
|
||
|
|
"#line 1 2\n",
|
||
|
|
"void main() {}\n"
|
||
|
|
}));
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
void ShaderGLTest::addFile() {
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
Shader shader(Version::GL210, Shader::Type::Fragment);
|
||
|
|
#else
|
||
|
|
Shader shader(Version::GLES200, Shader::Type::Fragment);
|
||
|
|
#endif
|
||
|
|
|
||
|
|
shader.addFile(Utility::Directory::join(SHADERGLTEST_FILES_DIR, "shader.glsl"));
|
||
|
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
CORRADE_COMPARE(shader.sources(), (std::vector<std::string>{
|
||
|
|
"#version 120\n",
|
||
|
|
"#line 1 1\n",
|
||
|
|
"void main() {}\n"
|
||
|
|
}));
|
||
|
|
#else
|
||
|
|
CORRADE_COMPARE(shader.sources(), (std::vector<std::string>{
|
||
|
|
"#version 100\n",
|
||
|
|
"#line 1 1\n",
|
||
|
|
"void main() {}\n"
|
||
|
|
}));
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
void ShaderGLTest::compile() {
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
10 years ago
|
constexpr Version v =
|
||
|
|
#ifndef CORRADE_TARGET_APPLE
|
||
|
|
Version::GL210
|
||
|
|
#else
|
||
|
|
Version::GL310
|
||
|
|
#endif
|
||
|
|
;
|
||
|
13 years ago
|
#else
|
||
|
|
constexpr Version v = Version::GLES200;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
Shader shader(v, Shader::Type::Fragment);
|
||
|
|
shader.addSource("void main() {}\n");
|
||
|
|
CORRADE_VERIFY(shader.compile());
|
||
|
|
|
||
|
|
Shader shader2(v, Shader::Type::Fragment);
|
||
|
|
shader2.addSource("[fu] bleh error #:! stuff\n");
|
||
|
|
CORRADE_VERIFY(!shader2.compile());
|
||
|
|
}
|
||
|
|
|
||
|
8 years ago
|
void ShaderGLTest::compileUtf8() {
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
constexpr Version v =
|
||
|
|
#ifndef CORRADE_TARGET_APPLE
|
||
|
|
Version::GL210
|
||
|
|
#else
|
||
|
|
Version::GL310
|
||
|
|
#endif
|
||
|
|
;
|
||
|
|
#else
|
||
|
|
constexpr Version v = Version::GLES200;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
Shader shader(v, Shader::Type::Fragment);
|
||
|
|
shader.addSource("/* hýždě */ void main() {} \n");
|
||
|
|
CORRADE_VERIFY(shader.compile());
|
||
|
|
}
|
||
|
|
|
||
|
10 years ago
|
void ShaderGLTest::compileNoVersion() {
|
||
|
|
Shader shader(Version::None, Shader::Type::Fragment);
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
9 years ago
|
#ifndef CORRADE_TARGET_APPLE
|
||
|
10 years ago
|
shader.addSource("#version 120\nvoid main() {}\n");
|
||
|
|
#else
|
||
|
9 years ago
|
shader.addSource("#version 400\nvoid main() {}\n");
|
||
|
|
#endif
|
||
|
|
#else
|
||
|
10 years ago
|
shader.addSource("#version 100\nvoid main() {}\n");
|
||
|
|
#endif
|
||
|
|
CORRADE_VERIFY(shader.compile());
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
}}
|
||
|
|
|
||
|
9 years ago
|
CORRADE_TEST_MAIN(Magnum::Test::ShaderGLTest)
|