Browse Source

GL: port to Utility::Path.

Shader::addSource() won't silently ignore file read errors anymore, like
in the other cases mentioned with plugins etc. before.
pull/556/head
Vladimír Vondruš 4 years ago
parent
commit
160fbf7d3c
  1. 10
      src/Magnum/GL/Shader.cpp
  2. 15
      src/Magnum/GL/Test/RendererGLTest.cpp
  3. 5
      src/Magnum/GL/Test/ShaderGLTest.cpp

10
src/Magnum/GL/Shader.cpp

@ -30,10 +30,11 @@
#ifndef MAGNUM_TARGET_WEBGL
#include <Corrade/Containers/String.h>
#endif
#include <Corrade/Containers/StringStl.h> /** @todo remove once Shader is <string>-free */
#include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/Debug.h>
#include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/Directory.h>
#include <Corrade/Utility/Path.h>
#include "Magnum/GL/Context.h"
#include "Magnum/GL/Extensions.h"
@ -740,10 +741,9 @@ void Shader::addSourceImplementationEmscriptenPthread(std::string source) {
#endif
Shader& Shader::addFile(const std::string& filename) {
CORRADE_ASSERT(Utility::Directory::exists(filename),
"GL::Shader file " << '\'' + filename + '\'' << " cannot be read.", *this);
addSource(Utility::Directory::readString(filename));
const Containers::Optional<Containers::String> string = Utility::Path::readString(filename);
CORRADE_ASSERT(string, "GL::Shader::addFile(): can't read" << filename, *this);
addSource(*string);
return *this;
}

15
src/Magnum/GL/Test/RendererGLTest.cpp

@ -24,9 +24,14 @@
*/
#include <Corrade/Containers/StridedArrayView.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/Reference.h>
#include <Corrade/PluginManager/Manager.h>
#include <Corrade/Utility/Directory.h>
#include <Corrade/Utility/Path.h>
#ifdef CORRADE_TARGET_APPLE
#include <Corrade/Utility/System.h> /* isSandboxed() */
#endif
#include "Magnum/Image.h"
#include "Magnum/DebugTools/CompareImage.h"
@ -65,7 +70,7 @@ struct RendererGLTest: OpenGLTester {
private:
PluginManager::Manager<Trade::AbstractImporter> _manager{"nonexistent"};
std::string _testDir;
Containers::String _testDir;
GL::Renderbuffer _color{NoCreate};
GL::Framebuffer _framebuffer{NoCreate};
@ -95,13 +100,13 @@ RendererGLTest::RendererGLTest() {
#endif
#ifdef CORRADE_TARGET_APPLE
if(Utility::Directory::isSandboxed()
if(Utility::System::isSandboxed()
#if defined(CORRADE_TARGET_IOS) && defined(CORRADE_TESTSUITE_TARGET_XCTEST)
/** @todo Fix this once I persuade CMake to run XCTest tests properly */
&& std::getenv("SIMULATOR_UDID")
#endif
) {
_testDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "RendererGLTestFiles");
_testDir = Utility::Path::join(Utility::Path::split(*Utility::Path::executableLocation()).first(), "RendererGLTestFiles");
} else
#endif
{
@ -232,7 +237,7 @@ void RendererGLTest::pointCoord() {
CORRADE_COMPARE_WITH(
/* Dropping the alpha channel, as it's always 1.0 */
Containers::arrayCast<Color3ub>(_framebuffer.read(_framebuffer.viewport(), {Magnum::PixelFormat::RGBA8Unorm}).pixels<Color4ub>()),
Utility::Directory::join(_testDir, "pointcoord.tga"),
Utility::Path::join(_testDir, "pointcoord.tga"),
(DebugTools::CompareImageToFile{_manager, maxThreshold, meanThreshold}));
}

5
src/Magnum/GL/Test/ShaderGLTest.cpp

@ -23,8 +23,9 @@
DEALINGS IN THE SOFTWARE.
*/
#include <Corrade/Containers/StringStl.h> /** @todo remove once Shader is <string>-free */
#include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/Directory.h>
#include <Corrade/Utility/Path.h>
#include "Magnum/GL/Context.h"
#include "Magnum/GL/Extensions.h"
@ -243,7 +244,7 @@ void ShaderGLTest::addFile() {
Shader shader(Version::GLES200, Shader::Type::Fragment);
#endif
shader.addFile(Utility::Directory::join(SHADERGLTEST_FILES_DIR, "shader.glsl"));
shader.addFile(Utility::Path::join(SHADERGLTEST_FILES_DIR, "shader.glsl"));
#ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE(shader.sources(), (std::vector<std::string>{

Loading…
Cancel
Save