|
|
|
|
/*
|
|
|
|
|
This file is part of Magnum.
|
|
|
|
|
|
|
|
|
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
|
|
|
|
|
2020, 2021, 2022 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <Corrade/Containers/StringStl.h> /** @todo remove once Shader is <string>-free */
|
|
|
|
|
#include <Corrade/Utility/DebugStl.h>
|
|
|
|
|
#include <Corrade/Utility/Path.h>
|
|
|
|
|
|
|
|
|
|
#include "Magnum/GL/Context.h"
|
|
|
|
|
#include "Magnum/GL/Extensions.h"
|
|
|
|
|
#include "Magnum/GL/Shader.h"
|
|
|
|
|
#include "Magnum/GL/OpenGLTester.h"
|
|
|
|
|
|
GL: port label() / setLabel() away from std::string.
All the tests were updated to explicitly check that non-null-terminated
strings get handled properly (the GL label APIs have an explicit size,
so it *should*, but just in case). Also, because various subclasses
override the setter to return correct type for method chaining and the
override has to be deinlined to avoid relying on a StringView include,
the tests are now explicitly done for each leaf class, instead of the
subclass
The <string> being removed from the base class for all GL objects may
affect downstream projects which relied on it being included. In case of
Magnum, the breakages were already fixed in the previous commit.
Compile time improvement for the MagnumGL library alone is 0.2 second or
4% (6.1 seconds before, 5.9 after). Not bad, given that there's three
more files to compile and strings are still heavily used in other GL
debug output APIs and all shader stuff. For a build of just the GL
library and all tests, it goes down from 28.9 seconds to 28.1. Most
tests also still rely quite heavily on std::stringstream for debug
output testing, so the numbers still could go further.
5 years ago
|
|
|
#ifndef MAGNUM_TARGET_WEBGL
|
|
|
|
|
#include <Corrade/Containers/String.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "configure.h"
|
|
|
|
|
|
|
|
|
|
namespace Magnum { namespace GL { namespace Test { namespace {
|
|
|
|
|
|
|
|
|
|
struct ShaderGLTest: OpenGLTester {
|
|
|
|
|
explicit ShaderGLTest();
|
|
|
|
|
|
|
|
|
|
void construct();
|
|
|
|
|
void constructNoVersion();
|
|
|
|
|
void constructMove();
|
|
|
|
|
|
|
|
|
|
#ifndef MAGNUM_TARGET_WEBGL
|
|
|
|
|
void label();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void addSource();
|
|
|
|
|
void addSourceNoVersion();
|
|
|
|
|
void addFile();
|
|
|
|
|
void compile();
|
|
|
|
|
void compileUtf8();
|
|
|
|
|
void compileNoVersion();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ShaderGLTest::ShaderGLTest() {
|
|
|
|
|
addTests({&ShaderGLTest::construct,
|
|
|
|
|
&ShaderGLTest::constructNoVersion,
|
|
|
|
|
&ShaderGLTest::constructMove,
|
|
|
|
|
|
|
|
|
|
#ifndef MAGNUM_TARGET_WEBGL
|
|
|
|
|
&ShaderGLTest::label,
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
&ShaderGLTest::addSource,
|
|
|
|
|
&ShaderGLTest::addSourceNoVersion,
|
|
|
|
|
&ShaderGLTest::addFile,
|
|
|
|
|
&ShaderGLTest::compile,
|
|
|
|
|
&ShaderGLTest::compileUtf8,
|
|
|
|
|
&ShaderGLTest::compileNoVersion});
|
|
|
|
|
}
|
|
|
|
|
|
GL: port label() / setLabel() away from std::string.
All the tests were updated to explicitly check that non-null-terminated
strings get handled properly (the GL label APIs have an explicit size,
so it *should*, but just in case). Also, because various subclasses
override the setter to return correct type for method chaining and the
override has to be deinlined to avoid relying on a StringView include,
the tests are now explicitly done for each leaf class, instead of the
subclass
The <string> being removed from the base class for all GL objects may
affect downstream projects which relied on it being included. In case of
Magnum, the breakages were already fixed in the previous commit.
Compile time improvement for the MagnumGL library alone is 0.2 second or
4% (6.1 seconds before, 5.9 after). Not bad, given that there's three
more files to compile and strings are still heavily used in other GL
debug output APIs and all shader stuff. For a build of just the GL
library and all tests, it goes down from 28.9 seconds to 28.1. Most
tests also still rely quite heavily on std::stringstream for debug
output testing, so the numbers still could go further.
5 years ago
|
|
|
#ifndef MAGNUM_TARGET_WEBGL
|
|
|
|
|
using namespace Containers::Literals;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
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_GL_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
|
|
|
|
|
CORRADE_COMPARE(shader.sources(), std::vector<std::string>{"#version 300 es\n"});
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MAGNUM_VERIFY_NO_GL_ERROR();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShaderGLTest::constructNoVersion() {
|
|
|
|
|
const Shader shader(Version::None, Shader::Type::Fragment);
|
|
|
|
|
CORRADE_VERIFY(shader.sources().empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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_GL_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
|
|
|
|
|
CORRADE_COMPARE(b.sources(), std::vector<std::string>{"#version 300 es\n"});
|
|
|
|
|
#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_GL_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
|
|
|
|
|
CORRADE_COMPARE(c.sources(), std::vector<std::string>{"#version 300 es\n"});
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
CORRADE_VERIFY(std::is_nothrow_move_constructible<Shader>::value);
|
|
|
|
|
CORRADE_VERIFY(std::is_nothrow_move_assignable<Shader>::value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifndef MAGNUM_TARGET_WEBGL
|
|
|
|
|
void ShaderGLTest::label() {
|
|
|
|
|
/* No-Op version is tested in AbstractObjectGLTest */
|
|
|
|
|
if(!Context::current().isExtensionSupported<Extensions::KHR::debug>() &&
|
|
|
|
|
!Context::current().isExtensionSupported<Extensions::EXT::debug_label>())
|
|
|
|
|
CORRADE_SKIP("Required extension is not available");
|
|
|
|
|
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES
|
|
|
|
|
Shader shader(Version::GL210, Shader::Type::Vertex);
|
|
|
|
|
#else
|
|
|
|
|
Shader shader(Version::GLES200, Shader::Type::Vertex);
|
|
|
|
|
#endif
|
|
|
|
|
CORRADE_COMPARE(shader.label(), "");
|
GL: port label() / setLabel() away from std::string.
All the tests were updated to explicitly check that non-null-terminated
strings get handled properly (the GL label APIs have an explicit size,
so it *should*, but just in case). Also, because various subclasses
override the setter to return correct type for method chaining and the
override has to be deinlined to avoid relying on a StringView include,
the tests are now explicitly done for each leaf class, instead of the
subclass
The <string> being removed from the base class for all GL objects may
affect downstream projects which relied on it being included. In case of
Magnum, the breakages were already fixed in the previous commit.
Compile time improvement for the MagnumGL library alone is 0.2 second or
4% (6.1 seconds before, 5.9 after). Not bad, given that there's three
more files to compile and strings are still heavily used in other GL
debug output APIs and all shader stuff. For a build of just the GL
library and all tests, it goes down from 28.9 seconds to 28.1. Most
tests also still rely quite heavily on std::stringstream for debug
output testing, so the numbers still could go further.
5 years ago
|
|
|
MAGNUM_VERIFY_NO_GL_ERROR();
|
|
|
|
|
|
GL: port label() / setLabel() away from std::string.
All the tests were updated to explicitly check that non-null-terminated
strings get handled properly (the GL label APIs have an explicit size,
so it *should*, but just in case). Also, because various subclasses
override the setter to return correct type for method chaining and the
override has to be deinlined to avoid relying on a StringView include,
the tests are now explicitly done for each leaf class, instead of the
subclass
The <string> being removed from the base class for all GL objects may
affect downstream projects which relied on it being included. In case of
Magnum, the breakages were already fixed in the previous commit.
Compile time improvement for the MagnumGL library alone is 0.2 second or
4% (6.1 seconds before, 5.9 after). Not bad, given that there's three
more files to compile and strings are still heavily used in other GL
debug output APIs and all shader stuff. For a build of just the GL
library and all tests, it goes down from 28.9 seconds to 28.1. Most
tests also still rely quite heavily on std::stringstream for debug
output testing, so the numbers still could go further.
5 years ago
|
|
|
/* Test the string size gets correctly used, instead of relying on null
|
|
|
|
|
termination */
|
|
|
|
|
shader.setLabel("MyShader!"_s.except(1));
|
|
|
|
|
MAGNUM_VERIFY_NO_GL_ERROR();
|
|
|
|
|
|
GL: port label() / setLabel() away from std::string.
All the tests were updated to explicitly check that non-null-terminated
strings get handled properly (the GL label APIs have an explicit size,
so it *should*, but just in case). Also, because various subclasses
override the setter to return correct type for method chaining and the
override has to be deinlined to avoid relying on a StringView include,
the tests are now explicitly done for each leaf class, instead of the
subclass
The <string> being removed from the base class for all GL objects may
affect downstream projects which relied on it being included. In case of
Magnum, the breakages were already fixed in the previous commit.
Compile time improvement for the MagnumGL library alone is 0.2 second or
4% (6.1 seconds before, 5.9 after). Not bad, given that there's three
more files to compile and strings are still heavily used in other GL
debug output APIs and all shader stuff. For a build of just the GL
library and all tests, it goes down from 28.9 seconds to 28.1. Most
tests also still rely quite heavily on std::stringstream for debug
output testing, so the numbers still could go further.
5 years ago
|
|
|
CORRADE_COMPARE(shader.label(), "MyShader");
|
|
|
|
|
MAGNUM_VERIFY_NO_GL_ERROR();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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>{
|
|
|
|
|
"",
|
|
|
|
|
"#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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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::Path::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
|
|
|
|
|
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("void main() {}\n");
|
|
|
|
|
CORRADE_VERIFY(shader.compile());
|
|
|
|
|
|
|
|
|
|
Shader shader2(v, Shader::Type::Fragment);
|
|
|
|
|
shader2.addSource("[fu] bleh error #:! stuff\n");
|
|
|
|
|
CORRADE_VERIFY(!shader2.compile());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShaderGLTest::compileNoVersion() {
|
|
|
|
|
Shader shader(Version::None, Shader::Type::Fragment);
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES
|
|
|
|
|
#ifndef CORRADE_TARGET_APPLE
|
|
|
|
|
shader.addSource("#version 120\nvoid main() {}\n");
|
|
|
|
|
#else
|
|
|
|
|
shader.addSource("#version 400\nvoid main() {}\n");
|
|
|
|
|
#endif
|
|
|
|
|
#else
|
|
|
|
|
shader.addSource("#version 100\nvoid main() {}\n");
|
|
|
|
|
#endif
|
|
|
|
|
CORRADE_VERIFY(shader.compile());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}}}}
|
|
|
|
|
|
|
|
|
|
CORRADE_TEST_MAIN(Magnum::GL::Test::ShaderGLTest)
|