diff --git a/CMakeLists.txt b/CMakeLists.txt index 49781f968..a5f3a2d82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,8 +161,7 @@ endif() if(BUILD_GL_TESTS) if(UNIX AND (NOT MAGNUM_TARGET_GLES OR MAGNUM_TARGET_DESKTOP_GLES)) set(WITH_WINDOWLESSGLXAPPLICATION ON) - find_package(X11 REQUIRED) - set(GL_TEST_LIBRARIES Magnum MagnumWindowlessGlxApplication ${X11_LIBRARIES}) + set(GL_TEST_LIBRARIES Magnum MagnumWindowlessGlxApplication) else() message(FATAL_ERROR "Cannot run tests for OpenGL code on this platform. Set BUILD_GL_TESTS to OFF to skip building them.") endif() diff --git a/doc/cmake.dox b/doc/cmake.dox index da9e2b171..b586ae336 100644 --- a/doc/cmake.dox +++ b/doc/cmake.dox @@ -173,7 +173,7 @@ are also available as preprocessor variables if including If `MAGNUM_BUILD_DEPRECATED` is defined, the `MAGNUM_INCLUDE_DIR` variable also contains path directly to Magnum directory (i.e. for includes without `Magnum/` prefix) and `MAGNUM_PLUGINS_INCLUDE_DIR` contains include dir for plugins (i.e. -instead of `MagnumPlugins/` prefix). +for includes without `MagnumPlugins/` prefix). %Corrade library provides also its own set of CMake macros and variables, see @ref corrade-cmake "its documentation" for more information. diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 55addc7aa..cef0cfc98 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -94,10 +94,10 @@ # emulation on desktop OpenGL # MAGNUM_TARGET_WEBGL - Defined if compiled for WebGL # -# If `MAGNUM_BUILD_DEPRECATED` is defined, the `MAGNUM_INCLUDE_DIR` variable -# also contains path directly to Magnum directory (i.e. for includes without -# `Magnum/` prefix) and `MAGNUM_PLUGINS_INCLUDE_DIR` contains include dir for -# plugins (i.e. instead of `MagnumPlugins/` prefix). +# If MAGNUM_BUILD_DEPRECATED is defined, the MAGNUM_INCLUDE_DIR variable also +# contains path directly to Magnum directory (i.e. for includes without +# Magnum/ prefix) and MAGNUM_PLUGINS_INCLUDE_DIR contains include dir for +# plugins (i.e. for includes without MagnumPlugins/ prefix). # # Additionally these variables are defined for internal usage: # MAGNUM_INCLUDE_DIR - Root include dir (w/o dependencies) @@ -181,6 +181,15 @@ endif() find_path(MAGNUM_INCLUDE_DIR NAMES Magnum/Magnum.h) +# We need to open configure.h file from MAGNUM_INCLUDE_DIR before we check for +# the components. Bail out with proper error message if it wasn't found. The +# complete check with all components is further below. +if(NOT MAGNUM_INCLUDE_DIR) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Magnum + REQUIRED_VARS MAGNUM_LIBRARY MAGNUM_INCLUDE_DIR) +endif() + # Configuration file(READ ${MAGNUM_INCLUDE_DIR}/Magnum/configure.h _magnumConfigure) @@ -348,20 +357,18 @@ foreach(component ${Magnum_FIND_COMPONENTS}) else() unset(MAGNUM_${_COMPONENT}_LIBRARY) endif() - endif() # GLUT application dependencies - if(${component} STREQUAL GlutApplication) + elseif(${component} STREQUAL GlutApplication) find_package(GLUT) if(GLUT_FOUND) set(_MAGNUM_${_COMPONENT}_LIBRARIES ${GLUT_glut_LIBRARY}) else() unset(MAGNUM_${_COMPONENT}_LIBRARY) endif() - endif() # SDL2 application dependencies - if(${component} STREQUAL Sdl2Application) + elseif(${component} STREQUAL Sdl2Application) find_package(SDL2) if(SDL2_FOUND) set(_MAGNUM_${_COMPONENT}_LIBRARIES ${SDL2_LIBRARY}) @@ -369,25 +376,25 @@ foreach(component ${Magnum_FIND_COMPONENTS}) else() unset(MAGNUM_${_COMPONENT}_LIBRARY) endif() - endif() # (Windowless) NaCl application dependencies - if(${component} STREQUAL NaClApplication OR ${component} STREQUAL WindowlessNaClApplication) + elseif(${component} STREQUAL NaClApplication OR ${component} STREQUAL WindowlessNaClApplication) set(_MAGNUM_${_COMPONENT}_LIBRARIES ppapi_cpp ppapi) - endif() - # GLX application dependencies - if(${component} STREQUAL GlxApplication OR ${component} STREQUAL WindowlessGlxApplication) + # (Windowless) GLX application dependencies + elseif(${component} STREQUAL GlxApplication OR ${component} STREQUAL WindowlessGlxApplication) find_package(X11) if(X11_FOUND) set(_MAGNUM_${_COMPONENT}_LIBRARIES ${X11_LIBRARIES}) else() unset(MAGNUM_${_COMPONENT}_LIBRARY) endif() - endif() + + # Windowless CGL application has no additional dependencies + # Windowless WGL application has no additional dependencies # X/EGL application dependencies - if(${component} STREQUAL XEglApplication) + elseif(${component} STREQUAL XEglApplication) find_package(EGL) find_package(X11) if(EGL_FOUND AND X11_FOUND) @@ -398,7 +405,9 @@ foreach(component ${Magnum_FIND_COMPONENTS}) endif() # Common application dependencies - set(_MAGNUM_${_COMPONENT}_LIBRARIES ${_MAGNUM_${_COMPONENT}_LIBRARIES} ${_WINDOWCONTEXT_MAGNUM_LIBRARIES_DEPENDENCY}) + set(_MAGNUM_${_COMPONENT}_LIBRARIES + ${_MAGNUM_${_COMPONENT}_LIBRARIES} + ${_WINDOWCONTEXT_MAGNUM_LIBRARIES_DEPENDENCY}) # Audio library elseif(${component} STREQUAL Audio) @@ -471,7 +480,7 @@ foreach(component ${Magnum_FIND_COMPONENTS}) endif() endforeach() -include(FindPackageHandleStandardArgs) +# Complete the check with also all components find_package_handle_standard_args(Magnum REQUIRED_VARS MAGNUM_LIBRARY MAGNUM_INCLUDE_DIR HANDLE_COMPONENTS) diff --git a/src/Magnum/AbstractFramebuffer.cpp b/src/Magnum/AbstractFramebuffer.cpp index c0c5f2f7e..99cefef14 100644 --- a/src/Magnum/AbstractFramebuffer.cpp +++ b/src/Magnum/AbstractFramebuffer.cpp @@ -211,7 +211,9 @@ void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, Buf } #endif -void AbstractFramebuffer::invalidateImplementation(GLsizei count, GLenum* attachments) { +void AbstractFramebuffer::invalidateImplementationNoOp(GLsizei, const GLenum* const) {} + +void AbstractFramebuffer::invalidateImplementationDefault(const GLsizei count, const GLenum* const attachments) { /** @todo Re-enable when extension loader is available for ES */ #ifndef MAGNUM_TARGET_GLES2 glInvalidateFramebuffer(GLenum(bindInternal()), count, attachments); @@ -223,7 +225,9 @@ void AbstractFramebuffer::invalidateImplementation(GLsizei count, GLenum* attach #endif } -void AbstractFramebuffer::invalidateImplementation(GLsizei count, GLenum* attachments, const Range2Di& rectangle) { +void AbstractFramebuffer::invalidateImplementationNoOp(GLsizei, const GLenum*, const Range2Di&) {} + +void AbstractFramebuffer::invalidateImplementationDefault(const GLsizei count, const GLenum* const attachments, const Range2Di& rectangle) { /** @todo Re-enable when extension loader is available for ES */ #ifndef MAGNUM_TARGET_GLES2 glInvalidateSubFramebuffer(GLenum(bindInternal()), count, attachments, rectangle.left(), rectangle.bottom(), rectangle.sizeX(), rectangle.sizeY()); diff --git a/src/Magnum/AbstractFramebuffer.h b/src/Magnum/AbstractFramebuffer.h index ba4316317..9fff9d5b7 100644 --- a/src/Magnum/AbstractFramebuffer.h +++ b/src/Magnum/AbstractFramebuffer.h @@ -338,9 +338,6 @@ class MAGNUM_EXPORT AbstractFramebuffer { FramebufferTarget MAGNUM_LOCAL bindInternal(); void MAGNUM_LOCAL setViewportInternal(); - void MAGNUM_LOCAL invalidateImplementation(GLsizei count, GLenum* attachments); - void MAGNUM_LOCAL invalidateImplementation(GLsizei count, GLenum* attachments, const Range2Di& rectangle); - GLuint _id; Range2Di _viewport; @@ -367,6 +364,12 @@ class MAGNUM_EXPORT AbstractFramebuffer { static void MAGNUM_LOCAL readImplementationDefault(const Vector2i& offset, const Vector2i& size, ColorFormat format, ColorType type, std::size_t dataSize, GLvoid* data); static void MAGNUM_LOCAL readImplementationRobustness(const Vector2i& offset, const Vector2i& size, ColorFormat format, ColorType type, std::size_t dataSize, GLvoid* data); + + void MAGNUM_LOCAL invalidateImplementationNoOp(GLsizei, const GLenum*); + void MAGNUM_LOCAL invalidateImplementationDefault(GLsizei count, const GLenum* attachments); + + void MAGNUM_LOCAL invalidateImplementationNoOp(GLsizei, const GLenum*, const Range2Di&); + void MAGNUM_LOCAL invalidateImplementationDefault(GLsizei count, const GLenum* attachments, const Range2Di& rectangle); }; inline AbstractFramebuffer::AbstractFramebuffer() = default; diff --git a/src/Magnum/AbstractObject.cpp b/src/Magnum/AbstractObject.cpp index f295e3de1..0b07d3c8f 100644 --- a/src/Magnum/AbstractObject.cpp +++ b/src/Magnum/AbstractObject.cpp @@ -26,6 +26,7 @@ #include "AbstractObject.h" #include +#include #include "Magnum/Context.h" #include "Magnum/Extensions.h" @@ -123,26 +124,26 @@ Int AbstractObject::maxLabelLength() { return value; } -void AbstractObject::labelImplementationNoOp(GLenum, GLuint, const std::string&) {} +void AbstractObject::labelImplementationNoOp(GLenum, GLuint, Containers::ArrayReference) {} -void AbstractObject::labelImplementationKhr(const GLenum identifier, const GLuint name, const std::string& label) { +void AbstractObject::labelImplementationKhr(const GLenum identifier, const GLuint name, const Containers::ArrayReference label) { /** @todo Re-enable when extension loader is available for ES */ #ifndef MAGNUM_TARGET_GLES - glObjectLabel(identifier, name, label.size(), label.data()); + glObjectLabel(identifier, name, label.size(), label); #else static_cast(identifier); static_cast(name); static_cast(label); CORRADE_INTERNAL_ASSERT(false); - //glObjectLabelKHR(identifier, name, label.size(), label.data()); + //glObjectLabelKHR(identifier, name, label.size(), label); #endif } -void AbstractObject::labelImplementationExt(const GLenum identifier, const GLuint name, const std::string& label) { +void AbstractObject::labelImplementationExt(const GLenum identifier, const GLuint name, const Containers::ArrayReference label) { const GLenum type = extTypeFromKhrIdentifier(identifier); /** @todo Re-enable when extension loader is available for ES */ #ifndef MAGNUM_TARGET_GLES - glLabelObjectEXT(type, name, label.size(), label.data()); + glLabelObjectEXT(type, name, label.size(), label); #else static_cast(type); static_cast(name); @@ -154,46 +155,31 @@ void AbstractObject::labelImplementationExt(const GLenum identifier, const GLuin std::string AbstractObject::getLabelImplementationNoOp(GLenum, GLuint) { return {}; } std::string AbstractObject::getLabelImplementationKhr(const GLenum identifier, const GLuint name) { - /** - * @todo Get rid of this workaround when NVidia returns proper size for - * length=0 & label=nullptr (even crashes on length>0 & label=nullptr) - */ - #if 0 /* Get label size (w/o null terminator) */ GLsizei size; + /** @todo Re-enable when extension loader is available for ES */ #ifndef MAGNUM_TARGET_GLES - glGetObjectLabel(type, name, 0, &size, nullptr); + glGetObjectLabel(identifier, name, 0, &size, nullptr); #else - glGetObjectLabelKHR(type, name, 0, &size, nullptr); + static_cast(identifier); + static_cast(name); + CORRADE_INTERNAL_ASSERT(false); + //glGetObjectLabelKHR(identifier, name, 0, &size, nullptr); #endif /* Make place also for the null terminator */ std::string label; label.resize(size+1); + /** @todo Re-enable when extension loader is available for ES */ #ifndef MAGNUM_TARGET_GLES glGetObjectLabel(identifier, name, size+1, nullptr, &label[0]); #else - glGetObjectLabelKHR(identifier, name, size+1, nullptr, &label[0]); + //glGetObjectLabelKHR(identifier, name, size+1, nullptr, &label[0]); #endif /* Pop null terminator and return the string */ label.resize(size); return label; - #else - GLsizei size; - std::string label; - label.resize(maxLabelLength()); - /** @todo Re-enable when extension loader is available for ES */ - #ifndef MAGNUM_TARGET_GLES - glGetObjectLabel(identifier, name, label.size(), &size, &label[0]); - #else - static_cast(identifier); - static_cast(name); - CORRADE_INTERNAL_ASSERT(false); - //glGetObjectLabelKHR(identifier, name, label.size(), &size, &label[0]); - #endif - return label.substr(0, size); - #endif } std::string AbstractObject::getLabelImplementationExt(const GLenum identifier, const GLuint name) { diff --git a/src/Magnum/AbstractObject.h b/src/Magnum/AbstractObject.h index 9e70bbeeb..1c89397d1 100644 --- a/src/Magnum/AbstractObject.h +++ b/src/Magnum/AbstractObject.h @@ -30,9 +30,10 @@ */ #include +#include +#include "Magnum/Magnum.h" #include "Magnum/OpenGL.h" -#include "Magnum/Types.h" #include "Magnum/visibility.h" namespace Magnum { @@ -66,9 +67,9 @@ class MAGNUM_EXPORT AbstractObject { MAGNUM_LOCAL ~AbstractObject(); private: - static MAGNUM_LOCAL void labelImplementationNoOp(GLenum, GLuint, const std::string&); - static MAGNUM_LOCAL void labelImplementationExt(GLenum identifier, GLuint name, const std::string& label); - static MAGNUM_LOCAL void labelImplementationKhr(GLenum identifier, GLuint name, const std::string& label); + static MAGNUM_LOCAL void labelImplementationNoOp(GLenum, GLuint, Containers::ArrayReference label); + static MAGNUM_LOCAL void labelImplementationExt(GLenum identifier, GLuint name, Containers::ArrayReference label); + static MAGNUM_LOCAL void labelImplementationKhr(GLenum identifier, GLuint name, Containers::ArrayReference label); static MAGNUM_LOCAL std::string getLabelImplementationNoOp(GLenum, GLuint); static MAGNUM_LOCAL std::string getLabelImplementationExt(GLenum identifier, GLuint name); static MAGNUM_LOCAL std::string getLabelImplementationKhr(GLenum identifier, GLuint name); diff --git a/src/Magnum/AbstractShaderProgram.cpp b/src/Magnum/AbstractShaderProgram.cpp index 7fbeb70bb..6e39c4333 100644 --- a/src/Magnum/AbstractShaderProgram.cpp +++ b/src/Magnum/AbstractShaderProgram.cpp @@ -227,7 +227,7 @@ std::string AbstractShaderProgram::label() const { #endif } -AbstractShaderProgram& AbstractShaderProgram::setLabel(const std::string& label) { +AbstractShaderProgram& AbstractShaderProgram::setLabelInternal(const Containers::ArrayReference label) { #ifndef MAGNUM_TARGET_GLES Context::current()->state().debug->labelImplementation(GL_PROGRAM, _id, label); #else @@ -264,16 +264,20 @@ void AbstractShaderProgram::attachShader(Shader& shader) { glAttachShader(_id, shader.id()); } -void AbstractShaderProgram::bindAttributeLocation(UnsignedInt location, const std::string& name) { - glBindAttribLocation(_id, location, name.data()); +void AbstractShaderProgram::attachShaders(std::initializer_list> shaders) { + for(Shader& s: shaders) attachShader(s); +} + +void AbstractShaderProgram::bindAttributeLocationInternal(const UnsignedInt location, const Containers::ArrayReference name) { + glBindAttribLocation(_id, location, name); } #ifndef MAGNUM_TARGET_GLES -void AbstractShaderProgram::bindFragmentDataLocation(UnsignedInt location, const std::string& name) { - glBindFragDataLocation(_id, location, name.data()); +void AbstractShaderProgram::bindFragmentDataLocationInternal(const UnsignedInt location, const Containers::ArrayReference name) { + glBindFragDataLocation(_id, location, name); } -void AbstractShaderProgram::bindFragmentDataLocationIndexed(UnsignedInt location, UnsignedInt index, const std::string& name) { - glBindFragDataLocationIndexed(_id, location, index, name.data()); +void AbstractShaderProgram::bindFragmentDataLocationIndexedInternal(const UnsignedInt location, UnsignedInt index, const Containers::ArrayReference name) { + glBindFragDataLocationIndexed(_id, location, index, name); } #endif @@ -354,10 +358,10 @@ bool AbstractShaderProgram::link(std::initializer_list name) { + GLint location = glGetUniformLocation(_id, name); if(location == -1) - Warning() << "AbstractShaderProgram: location of uniform \'" + name + "\' cannot be retrieved!"; + Warning() << "AbstractShaderProgram: location of uniform \'" + std::string{name, name.size()} + "\' cannot be retrieved!"; return location; } diff --git a/src/Magnum/AbstractShaderProgram.h b/src/Magnum/AbstractShaderProgram.h index 8fd304461..b77b46cbc 100644 --- a/src/Magnum/AbstractShaderProgram.h +++ b/src/Magnum/AbstractShaderProgram.h @@ -31,6 +31,7 @@ #include #include +#include #include #include "Magnum/AbstractObject.h" @@ -540,7 +541,14 @@ class MAGNUM_EXPORT AbstractShaderProgram: public AbstractObject { * @def_gl{PROGRAM} or @fn_gl_extension2{LabelObject,EXT,debug_label} * with @def_gl{PROGRAM_OBJECT_EXT} */ - AbstractShaderProgram& setLabel(const std::string& label); + AbstractShaderProgram& setLabel(const std::string& label) { + return setLabelInternal({label.data(), label.size()}); + } + + /** @overload */ + template AbstractShaderProgram& setLabel(const char (&label)[size]) { + return setLabelInternal(label); + } /** * @brief Validate program @@ -614,6 +622,15 @@ class MAGNUM_EXPORT AbstractShaderProgram: public AbstractObject { */ void attachShader(Shader& shader); + /** + * @brief Attach shaders + * + * Convenience overload to the above, allowing the user to specify more + * than one shader at once. Other than that there is no other + * (performance) difference when using this function. + */ + void attachShaders(std::initializer_list> shaders); + /** * @brief Bind attribute to given location * @param location Location @@ -627,7 +644,14 @@ class MAGNUM_EXPORT AbstractShaderProgram: public AbstractObject { * @ref AbstractShaderProgram-attribute-location "class documentation" * for more information. */ - void bindAttributeLocation(UnsignedInt location, const std::string& name); + void bindAttributeLocation(UnsignedInt location, const std::string& name) { + bindAttributeLocationInternal(location, {name.data(), name.size()}); + } + + /** @overload */ + template void bindAttributeLocation(UnsignedInt location, const char(&name)[size]) { + bindAttributeLocationInternal(location, name); + } #ifndef MAGNUM_TARGET_GLES /** @@ -648,7 +672,14 @@ class MAGNUM_EXPORT AbstractShaderProgram: public AbstractObject { * @requires_gl Multiple blend function inputs are not available in * OpenGL ES. */ - void bindFragmentDataLocationIndexed(UnsignedInt location, UnsignedInt index, const std::string& name); + void bindFragmentDataLocationIndexed(UnsignedInt location, UnsignedInt index, const std::string& name) { + bindFragmentDataLocationIndexedInternal(location, index, {name.data(), name.size()}); + } + + /** @overload */ + template void bindFragmentDataLocationIndexed(UnsignedInt location, UnsignedInt index, const char(&name)[size]) { + bindFragmentDataLocationIndexedInternal(location, index, name); + } /** * @brief Bind fragment data to given location and first color input index @@ -663,7 +694,15 @@ class MAGNUM_EXPORT AbstractShaderProgram: public AbstractObject { * and `gl_FragData[n]` provided by @es_extension2{NV,draw_buffers,GL_NV_draw_buffers} * in OpenGL ES 2.0. */ - void bindFragmentDataLocation(UnsignedInt location, const std::string& name); + void bindFragmentDataLocation(UnsignedInt location, const std::string& name) { + bindFragmentDataLocationInternal(location, {name.data(), name.size()}); + } + + /** @overload */ + template void bindFragmentDataLocation(UnsignedInt location, const char(&name)[size]) { + /* Not using const char* parameter, because this way it avoids most accidents with non-zero-terminated strings */ + bindFragmentDataLocationInternal(location, name); + } #endif /** @@ -689,7 +728,14 @@ class MAGNUM_EXPORT AbstractShaderProgram: public AbstractObject { * @ref AbstractShaderProgram-uniform-location "class documentation" * for more information. */ - Int uniformLocation(const std::string& name); + Int uniformLocation(const std::string& name) { + return uniformLocationInternal({name.data(), name.size()}); + } + + /** @overload */ + template Int uniformLocation(const char(&name)[size]) { + return uniformLocationInternal(name); + } /** * @brief Set uniform value @@ -811,6 +857,12 @@ class MAGNUM_EXPORT AbstractShaderProgram: public AbstractObject { #endif private: + AbstractShaderProgram& setLabelInternal(Containers::ArrayReference label); + void bindAttributeLocationInternal(UnsignedInt location, Containers::ArrayReference name); + void bindFragmentDataLocationIndexedInternal(UnsignedInt location, UnsignedInt index, Containers::ArrayReference name); + void bindFragmentDataLocationInternal(UnsignedInt location, Containers::ArrayReference name); + Int uniformLocationInternal(Containers::ArrayReference name); + #ifndef MAGNUM_BUILD_DEPRECATED void use(); #endif diff --git a/src/Magnum/AbstractTexture.cpp b/src/Magnum/AbstractTexture.cpp index 619132ca7..c305de84b 100644 --- a/src/Magnum/AbstractTexture.cpp +++ b/src/Magnum/AbstractTexture.cpp @@ -190,7 +190,7 @@ std::string AbstractTexture::label() const { return Context::current()->state().debug->getLabelImplementation(GL_TEXTURE, _id); } -AbstractTexture& AbstractTexture::setLabel(const std::string& label) { +AbstractTexture& AbstractTexture::setLabelInternal(const Containers::ArrayReference label) { Context::current()->state().debug->labelImplementation(GL_TEXTURE, _id, label); return *this; } diff --git a/src/Magnum/AbstractTexture.h b/src/Magnum/AbstractTexture.h index 8f2d205ba..902518328 100644 --- a/src/Magnum/AbstractTexture.h +++ b/src/Magnum/AbstractTexture.h @@ -29,6 +29,8 @@ * @brief Class @ref Magnum::AbstractTexture */ +#include + #include "Magnum/Sampler.h" #include "Magnum/AbstractObject.h" @@ -264,7 +266,14 @@ class MAGNUM_EXPORT AbstractTexture: public AbstractObject { * @fn_gl_extension2{LabelObject,EXT,debug_label} with * @def_gl{TEXTURE} */ - AbstractTexture& setLabel(const std::string& label); + AbstractTexture& setLabel(const std::string& label) { + return setLabelInternal({label.data(), label.size()}); + } + + /** @overload */ + template AbstractTexture& setLabel(const char(&label)[size]) { + return setLabelInternal(label); + } /** @brief OpenGL texture ID */ GLuint id() const { return _id; } @@ -294,6 +303,8 @@ class MAGNUM_EXPORT AbstractTexture: public AbstractObject { explicit AbstractTexture(GLenum target); + AbstractTexture& setLabelInternal(Containers::ArrayReference label); + /* Unlike bind() this also sets the texture binding unit as active */ void MAGNUM_LOCAL bindInternal(); diff --git a/src/Magnum/Audio/AbstractImporter.h b/src/Magnum/Audio/AbstractImporter.h index 443183d19..303acf0ff 100644 --- a/src/Magnum/Audio/AbstractImporter.h +++ b/src/Magnum/Audio/AbstractImporter.h @@ -59,6 +59,8 @@ checked by the implementation: supported. - All `do*()` implementations working on opened file are called only if there is any file opened. + +Plugin interface string is `"cz.mosra.magnum.Audio.AbstractImporter/0.1"`. */ class MAGNUM_AUDIO_EXPORT AbstractImporter: public PluginManager::AbstractPlugin { CORRADE_PLUGIN_INTERFACE("cz.mosra.magnum.Audio.AbstractImporter/0.1") diff --git a/src/Magnum/Audio/Audio.cpp b/src/Magnum/Audio/Audio.cpp index 90e4ea522..940d215c0 100644 --- a/src/Magnum/Audio/Audio.cpp +++ b/src/Magnum/Audio/Audio.cpp @@ -26,6 +26,7 @@ #include #include +#include "Corrade/configure.h" #include "Magnum/Types.h" namespace Magnum { namespace Audio { diff --git a/src/Magnum/Audio/CMakeLists.txt b/src/Magnum/Audio/CMakeLists.txt index f5b35054d..2dc837505 100644 --- a/src/Magnum/Audio/CMakeLists.txt +++ b/src/Magnum/Audio/CMakeLists.txt @@ -27,7 +27,7 @@ find_package(OpenAL REQUIRED) include_directories(${OPENAL_INCLUDE_DIR}) -set(MagnumAudio_SOURCES +set(MagnumAudio_SRCS AbstractImporter.cpp Audio.cpp Buffer.cpp @@ -45,7 +45,9 @@ set(MagnumAudio_HEADERS visibility.h) -add_library(MagnumAudio ${SHARED_OR_STATIC} ${MagnumAudio_SOURCES}) +add_library(MagnumAudio ${SHARED_OR_STATIC} + ${MagnumAudio_SRCS} + ${MagnumAudio_HEADERS}) set_target_properties(MagnumAudio PROPERTIES DEBUG_POSTFIX "-d") target_link_libraries(MagnumAudio ${CORRADE_PLUGINMANAGER_LIBRARIES} ${OPENAL_LIBRARY}) diff --git a/src/Magnum/Buffer.cpp b/src/Magnum/Buffer.cpp index 37d96f8fc..75411ae09 100644 --- a/src/Magnum/Buffer.cpp +++ b/src/Magnum/Buffer.cpp @@ -138,7 +138,7 @@ std::string Buffer::label() const { #endif } -Buffer& Buffer::setLabel(const std::string& label) { +Buffer& Buffer::setLabelInternal(const Containers::ArrayReference label) { #ifndef MAGNUM_TARGET_GLES Context::current()->state().debug->labelImplementation(GL_BUFFER, _id, label); #else diff --git a/src/Magnum/Buffer.h b/src/Magnum/Buffer.h index f4fc40f32..3c5611914 100644 --- a/src/Magnum/Buffer.h +++ b/src/Magnum/Buffer.h @@ -582,7 +582,14 @@ class MAGNUM_EXPORT Buffer: public AbstractObject { * or @fn_gl_extension2{LabelObject,EXT,debug_label} with * @def_gl{BUFFER_OBJECT_EXT} */ - Buffer& setLabel(const std::string& label); + Buffer& setLabel(const std::string& label) { + return setLabelInternal({label.data(), label.size()}); + } + + /** @overload */ + template Buffer& setLabel(const char(&label)[size]) { + return setLabelInternal(label); + } /** @brief Target hint */ Target targetHint() const { return _targetHint; } @@ -854,6 +861,8 @@ class MAGNUM_EXPORT Buffer: public AbstractObject { #endif private: + Buffer& setLabelInternal(Containers::ArrayReference label); + static void bind(Target hint, GLuint id); Target MAGNUM_LOCAL bindInternal(Target hint); diff --git a/src/Magnum/BufferTexture.h b/src/Magnum/BufferTexture.h index b5c5880b7..9954b6f4b 100644 --- a/src/Magnum/BufferTexture.h +++ b/src/Magnum/BufferTexture.h @@ -279,6 +279,10 @@ class MAGNUM_EXPORT BufferTexture: public AbstractTexture { AbstractTexture::setLabel(label); return *this; } + template BufferTexture& setLabel(const char(&label)[size]) { + AbstractTexture::setLabel(label); + return *this; + } #endif private: diff --git a/src/Magnum/CMakeLists.txt b/src/Magnum/CMakeLists.txt index dd7499091..9cbe04011 100644 --- a/src/Magnum/CMakeLists.txt +++ b/src/Magnum/CMakeLists.txt @@ -119,6 +119,19 @@ set(Magnum_HEADERS visibility.h) +# Header files to display in project view of IDEs only +set(Magnum_PRIVATE_HEADERS + Implementation/BufferState.h + Implementation/DebugState.h + Implementation/FramebufferState.h + Implementation/maxTextureSize.h + Implementation/MeshState.h + Implementation/RendererState.h + Implementation/ShaderProgramState.h + Implementation/ShaderState.h + Implementation/State.h + Implementation/TextureState.h) + # Deprecated headers if(BUILD_DEPRECATED) set(Magnum_HEADERS ${Magnum_HEADERS} @@ -159,6 +172,8 @@ set(MagnumMath_SRCS add_library(MagnumMathObjects OBJECT ${MagnumMath_SRCS}) add_library(Magnum ${SHARED_OR_STATIC} ${Magnum_SRCS} + ${Magnum_HEADERS} + ${Magnum_PRIVATE_HEADERS} $) set_target_properties(Magnum PROPERTIES DEBUG_POSTFIX "-d") diff --git a/src/Magnum/Context.cpp b/src/Magnum/Context.cpp index e2ffa3663..1e6538fde 100644 --- a/src/Magnum/Context.cpp +++ b/src/Magnum/Context.cpp @@ -332,7 +332,7 @@ Context::Context() { /* Allow ES2 context on driver that reports ES3 as supported */ const std::string version = versionString(); #ifndef MAGNUM_TARGET_GLES - if(version.compare(0, 4, "2.1 ") == 0) + if(version.compare(0, 3, "2.1") == 0) #elif defined(MAGNUM_TARGET_WEBGL) if(version.find("WebGL 1") != std::string::npos) #else diff --git a/src/Magnum/CubeMapTexture.h b/src/Magnum/CubeMapTexture.h index 8158e3ce6..d98d1f8c8 100644 --- a/src/Magnum/CubeMapTexture.h +++ b/src/Magnum/CubeMapTexture.h @@ -392,6 +392,10 @@ class MAGNUM_EXPORT CubeMapTexture: public AbstractTexture { AbstractTexture::setLabel(label); return *this; } + template CubeMapTexture& setLabel(const char(&label)[size]) { + AbstractTexture::setLabel(label); + return *this; + } #endif }; diff --git a/src/Magnum/CubeMapTextureArray.h b/src/Magnum/CubeMapTextureArray.h index 521a0dfec..58c4abf3e 100644 --- a/src/Magnum/CubeMapTextureArray.h +++ b/src/Magnum/CubeMapTextureArray.h @@ -415,6 +415,10 @@ class CubeMapTextureArray: public AbstractTexture { AbstractTexture::setLabel(label); return *this; } + template CubeMapTextureArray& setLabel(const char(&label)[size]) { + AbstractTexture::setLabel(label); + return *this; + } #endif }; diff --git a/src/Magnum/DebugMessage.h b/src/Magnum/DebugMessage.h index 217ebbc68..a213a1fb9 100644 --- a/src/Magnum/DebugMessage.h +++ b/src/Magnum/DebugMessage.h @@ -56,8 +56,8 @@ using @ref setCallback() or use the default one provided in @ref setDefaultCallback(): @code -Renderer::setFeature(Renderer::Feature::DebugOutput, true); -Renderer::setFeature(Renderer::Feature::DebugOutputSynchronous, true); +Renderer::enable(Renderer::Feature::DebugOutput); +Renderer::enable(Renderer::Feature::DebugOutputSynchronous); DebugMessage::setDefaultCallback(); DebugMessage::insert(DebugMessage::Source::Application, DebugMessage::Type::Marker, diff --git a/src/Magnum/DebugTools/CMakeLists.txt b/src/Magnum/DebugTools/CMakeLists.txt index 4455b248e..d7dd783b3 100644 --- a/src/Magnum/DebugTools/CMakeLists.txt +++ b/src/Magnum/DebugTools/CMakeLists.txt @@ -50,7 +50,26 @@ set(MagnumDebugTools_HEADERS visibility.h) -add_library(MagnumDebugTools ${SHARED_OR_STATIC} ${MagnumDebugTools_SRCS}) +# Header files to display in project view of IDEs only +set(MagnumDebugTools_PRIVATE_HEADERS + Implementation/AbstractBoxRenderer.h + Implementation/AbstractShapeRenderer.h + Implementation/AxisAlignedBoxRenderer.h + Implementation/BoxRenderer.h + Implementation/CapsuleRenderer.h + Implementation/CapsuleRendererTransformation.h + Implementation/CylinderRenderer.h + Implementation/CylinderRendererTransformation.h + Implementation/ForceRendererTransformation.h + Implementation/LineSegmentRenderer.h + Implementation/LineSegmentRendererTransformation.h + Implementation/PointRenderer.h + Implementation/SphereRenderer.h) + +add_library(MagnumDebugTools ${SHARED_OR_STATIC} + ${MagnumDebugTools_SRCS} + ${MagnumDebugTools_HEADERS} + ${MagnumDebugTools_PRIVATE_HEADERS}) set_target_properties(MagnumDebugTools PROPERTIES DEBUG_POSTFIX "-d") if(BUILD_STATIC_PIC) # TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property diff --git a/src/Magnum/DefaultFramebuffer.cpp b/src/Magnum/DefaultFramebuffer.cpp index f494f2872..2b2d70d57 100644 --- a/src/Magnum/DefaultFramebuffer.cpp +++ b/src/Magnum/DefaultFramebuffer.cpp @@ -77,7 +77,7 @@ void DefaultFramebuffer::invalidate(std::initializer_list*Context::current()->state().framebuffer->invalidateImplementation)(attachments.size(), _attachments); } void DefaultFramebuffer::invalidate(std::initializer_list attachments, const Range2Di& rectangle) { @@ -86,7 +86,7 @@ void DefaultFramebuffer::invalidate(std::initializer_list*Context::current()->state().framebuffer->invalidateSubImplementation)(attachments.size(), _attachments, rectangle); } void DefaultFramebuffer::initializeContextBasedFunctionality(Context& context) { diff --git a/src/Magnum/DefaultFramebuffer.h b/src/Magnum/DefaultFramebuffer.h index db2b87b76..b859ce9e8 100644 --- a/src/Magnum/DefaultFramebuffer.h +++ b/src/Magnum/DefaultFramebuffer.h @@ -388,17 +388,13 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * @brief Invalidate framebuffer * @param attachments Attachments to invalidate * - * The framebuffer is bound to some target before the operation, if - * not already. + * If extension @extension{ARB,invalidate_subdata} (part of OpenGL + * 4.3), extension @es_extension{EXT,discard_framebuffer} in OpenGL ES + * 2.0 or OpenGL ES 3.0 is not available, this function does nothing. + * The framebuffer is bound to some target before the operation, if not + * already. * @see @fn_gl{InvalidateFramebuffer} or @fn_gles_extension{DiscardFramebuffer,EXT,discard_framebuffer} * on OpenGL ES 2.0 - * @requires_gl43 %Extension @extension{ARB,invalidate_subdata}. Use - * @ref Magnum::DefaultFramebuffer::clear() "clear()" instead - * where the extension is not supported. - * @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer} - * in OpenGL ES 2.0. Use - * @ref Magnum::DefaultFramebuffer::clear() "clear()" instead - * where the extension is not supported. */ void invalidate(std::initializer_list attachments); @@ -407,17 +403,13 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * @param attachments Attachments to invalidate * @param rectangle %Rectangle to invalidate * - * The framebuffer is bound to some target before the operation, if - * not already. + * If extension @extension{ARB,invalidate_subdata} (part of OpenGL + * 4.3), extension @es_extension{EXT,discard_framebuffer} in OpenGL ES + * 2.0 or OpenGL ES 3.0 is not available, this function does nothing. + * The framebuffer is bound to some target before the operation, if not + * already. * @see @fn_gl{InvalidateSubFramebuffer} or @fn_gles_extension{DiscardSubFramebuffer,EXT,discard_framebuffer} * on OpenGL ES 2.0 - * @requires_gl43 %Extension @extension{ARB,invalidate_subdata}. Use - * @ref Magnum::DefaultFramebuffer::clear() "clear()" instead - * where the extension is not supported. - * @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer} - * in OpenGL ES 2.0. Use - * @ref Magnum::DefaultFramebuffer::clear() "clear()" instead - * where the extension is not supported. */ void invalidate(std::initializer_list attachments, const Range2Di& rectangle); diff --git a/src/Magnum/Framebuffer.cpp b/src/Magnum/Framebuffer.cpp index 35b7188e0..eeb530b7a 100644 --- a/src/Magnum/Framebuffer.cpp +++ b/src/Magnum/Framebuffer.cpp @@ -112,7 +112,7 @@ std::string Framebuffer::label() const { return Context::current()->state().debug->getLabelImplementation(GL_FRAMEBUFFER, _id); } -Framebuffer& Framebuffer::setLabel(const std::string& label) { +Framebuffer& Framebuffer::setLabelInternal(const Containers::ArrayReference label) { Context::current()->state().debug->labelImplementation(GL_FRAMEBUFFER, _id, label); return *this; } @@ -154,7 +154,7 @@ void Framebuffer::invalidate(std::initializer_list attac for(std::size_t i = 0; i != attachments.size(); ++i) _attachments[i] = GLenum(*(attachments.begin()+i)); - invalidateImplementation(attachments.size(), _attachments); + (this->*Context::current()->state().framebuffer->invalidateImplementation)(attachments.size(), _attachments); } void Framebuffer::invalidate(std::initializer_list attachments, const Range2Di& rectangle) { @@ -163,7 +163,7 @@ void Framebuffer::invalidate(std::initializer_list attac for(std::size_t i = 0; i != attachments.size(); ++i) _attachments[i] = GLenum(*(attachments.begin()+i)); - invalidateImplementation(attachments.size(), _attachments, rectangle); + (this->*Context::current()->state().framebuffer->invalidateSubImplementation)(attachments.size(), _attachments, rectangle); } Framebuffer& Framebuffer::attachRenderbuffer(const BufferAttachment attachment, Renderbuffer& renderbuffer) { diff --git a/src/Magnum/Framebuffer.h b/src/Magnum/Framebuffer.h index 4884ead4a..ac18fd033 100644 --- a/src/Magnum/Framebuffer.h +++ b/src/Magnum/Framebuffer.h @@ -370,7 +370,14 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer, public AbstractObje * @fn_gl_extension2{LabelObject,EXT,debug_label} with * @def_gl{FRAMEBUFFER} */ - Framebuffer& setLabel(const std::string& label); + Framebuffer& setLabel(const std::string& label) { + return setLabelInternal({label.data(), label.size()}); + } + + /** @overload */ + template Framebuffer& setLabel(const char(&label)[size]) { + return setLabelInternal(label); + } /** * @brief Check framebuffer status @@ -466,16 +473,13 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer, public AbstractObje * @param attachments Attachments to invalidate * @param rectangle %Rectangle to invalidate * - * The framebuffer is bound to some target before the operation, if - * not already. - * @see @fn_gl{InvalidateSubFramebuffer} or @fn_gles_extension{DiscardSubFramebuffer,EXT,discard_framebuffer} + * If extension @extension{ARB,invalidate_subdata} (part of OpenGL + * 4.3), extension @es_extension{EXT,discard_framebuffer} in OpenGL ES + * 2.0 or OpenGL ES 3.0 is not available, this function does nothing. + * The framebuffer is bound to some target before the operation, if not + * already. + * @see @fn_gl{InvalidateFramebuffer} or @fn_gles_extension{DiscardFramebuffer,EXT,discard_framebuffer} * on OpenGL ES 2.0 - * @requires_gl43 %Extension @extension{ARB,invalidate_subdata}. Use - * @ref Magnum::Framebuffer::clear() "clear()" instead where the - * extension is not supported. - * @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer} - * in OpenGL ES 2.0. Use @ref Magnum::Framebuffer::clear() "clear()" - * instead where the extension is not supported. */ void invalidate(std::initializer_list attachments, const Range2Di& rectangle); @@ -485,11 +489,13 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer, public AbstractObje * @param renderbuffer %Renderbuffer * @return Reference to self (for method chaining) * - * If @extension{EXT,direct_state_access} is not available and the - * framebufferbuffer is not currently bound, it is bound before the - * operation. - * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferRenderbuffer} or - * @fn_gl_extension{NamedFramebufferRenderbuffer,EXT,direct_state_access} + * If extension @extension{ARB,invalidate_subdata} (part of OpenGL + * 4.3), extension @es_extension{EXT,discard_framebuffer} in OpenGL ES + * 2.0 or OpenGL ES 3.0 is not available, this function does nothing. + * The framebuffer is bound to some target before the operation, if not + * already. + * @see @fn_gl{InvalidateSubFramebuffer} or @fn_gles_extension{DiscardSubFramebuffer,EXT,discard_framebuffer} + * on OpenGL ES 2.0 */ Framebuffer& attachRenderbuffer(BufferAttachment attachment, Renderbuffer& renderbuffer); @@ -643,6 +649,8 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer, public AbstractObje #endif private: + Framebuffer& setLabelInternal(Containers::ArrayReference label); + void MAGNUM_LOCAL renderbufferImplementationDefault(BufferAttachment attachment, Renderbuffer& renderbuffer); #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL renderbufferImplementationDSA(BufferAttachment attachment, Renderbuffer& renderbuffer); diff --git a/src/Magnum/Implementation/DebugState.h b/src/Magnum/Implementation/DebugState.h index a435e1b20..dd90ec181 100644 --- a/src/Magnum/Implementation/DebugState.h +++ b/src/Magnum/Implementation/DebugState.h @@ -36,7 +36,7 @@ struct DebugState { explicit DebugState(Context& context, std::vector& extensions); std::string(*getLabelImplementation)(GLenum, GLuint); - void(*labelImplementation)(GLenum, GLuint, const std::string&); + void(*labelImplementation)(GLenum, GLuint, Containers::ArrayReference); void(*messageInsertImplementation)(DebugMessage::Source, DebugMessage::Type, UnsignedInt, DebugMessage::Severity, const std::string&); void(*messageCallbackImplementation)(DebugMessage::Callback, const void*); diff --git a/src/Magnum/Implementation/FramebufferState.cpp b/src/Magnum/Implementation/FramebufferState.cpp index 0f6f3c121..010d23307 100644 --- a/src/Magnum/Implementation/FramebufferState.cpp +++ b/src/Magnum/Implementation/FramebufferState.cpp @@ -138,6 +138,36 @@ FramebufferState::FramebufferState(Context& context, std::vector& e renderbufferStorageMultisampleImplementation = &Renderbuffer::storageMultisampleImplementationDefault; #endif } + + /* Framebuffer invalidation implementation on desktop GL */ + #ifndef MAGNUM_TARGET_GLES + if(context.isExtensionSupported()) { + extensions.push_back(Extensions::GL::ARB::invalidate_subdata::string()); + + invalidateImplementation = &AbstractFramebuffer::invalidateImplementationDefault; + invalidateSubImplementation = &AbstractFramebuffer::invalidateImplementationDefault; + } else { + invalidateImplementation = &AbstractFramebuffer::invalidateImplementationNoOp; + invalidateSubImplementation = &AbstractFramebuffer::invalidateImplementationNoOp; + } + + /* Framebuffer invalidation implementation on ES2 */ + #elif defined(MAGNUM_TARGET_GLES2) + if(context.isExtensionSupported()) { + extensions.push_back(Extensions::GL::EXT::discard_framebuffer::string()); + + invalidateImplementation = &AbstractFramebuffer::invalidateImplementationDefault; + invalidateSubImplementation = &AbstractFramebuffer::invalidateImplementationDefault; + } else { + invalidateImplementation = &AbstractFramebuffer::invalidateImplementationNoOp; + invalidateSubImplementation = &AbstractFramebuffer::invalidateImplementationNoOp; + } + + /* Always available on ES3 */ + #else + invalidateImplementation = &AbstractFramebuffer::invalidateImplementationDefault; + invalidateSubImplementation = &AbstractFramebuffer::invalidateImplementationDefault; + #endif } void FramebufferState::reset() { diff --git a/src/Magnum/Implementation/FramebufferState.h b/src/Magnum/Implementation/FramebufferState.h index 67f52af4a..29239627d 100644 --- a/src/Magnum/Implementation/FramebufferState.h +++ b/src/Magnum/Implementation/FramebufferState.h @@ -51,6 +51,8 @@ struct FramebufferState { void(AbstractFramebuffer::*drawBuffersImplementation)(GLsizei, const GLenum*); void(AbstractFramebuffer::*drawBufferImplementation)(GLenum); void(AbstractFramebuffer::*readBufferImplementation)(GLenum); + void(AbstractFramebuffer::*invalidateImplementation)(GLsizei, const GLenum*); + void(AbstractFramebuffer::*invalidateSubImplementation)(GLsizei, const GLenum*, const Range2Di&); void(Framebuffer::*renderbufferImplementation)(Framebuffer::BufferAttachment, Renderbuffer&); #ifndef MAGNUM_TARGET_GLES diff --git a/src/Magnum/Math/Algorithms/CMakeLists.txt b/src/Magnum/Math/Algorithms/CMakeLists.txt index 93f6d48b6..deeec09df 100644 --- a/src/Magnum/Math/Algorithms/CMakeLists.txt +++ b/src/Magnum/Math/Algorithms/CMakeLists.txt @@ -28,6 +28,9 @@ set(MagnumMathAlgorithms_HEADERS GramSchmidt.h Svd.h) +# Force IDEs to display all header files in project view +add_custom_target(MagnumMathAlgorithms SOURCES ${MagnumMathAlgorithms_HEADERS}) + install(FILES ${MagnumMathAlgorithms_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Math/Algorithms) if(BUILD_TESTS) diff --git a/src/Magnum/Math/Algorithms/Test/GramSchmidtTest.cpp b/src/Magnum/Math/Algorithms/Test/GramSchmidtTest.cpp index df224adb3..a3a1169c9 100644 --- a/src/Magnum/Math/Algorithms/Test/GramSchmidtTest.cpp +++ b/src/Magnum/Math/Algorithms/Test/GramSchmidtTest.cpp @@ -90,9 +90,9 @@ void GramSchmidtTest::orthonormalize() { CORRADE_COMPARE(Vector3::dot(orthonormalized[1], orthonormalized[2]), 0.0f); /* Just to be sure */ - Matrix3x3 expected(Vector3( 0.303046f, 0.505076f, 0.808122f), - Vector3( 0.928316f, -0.348119f, -0.130544f), - Vector3(-0.215388f, -0.789754f, 0.574367f)); + Matrix3x3 expected(Vector3( 0.3030458f, 0.5050763f, 0.8081220f), + Vector3( 0.9283164f, -0.3481189f, -0.1305445f), + Vector3(-0.2153877f, -0.7897540f, 0.5743665f)); CORRADE_COMPARE(orthonormalized, expected); } diff --git a/src/Magnum/Math/CMakeLists.txt b/src/Magnum/Math/CMakeLists.txt index cff0d8ee6..bcffdce8b 100644 --- a/src/Magnum/Math/CMakeLists.txt +++ b/src/Magnum/Math/CMakeLists.txt @@ -47,6 +47,9 @@ set(MagnumMath_HEADERS Vector3.h Vector4.h) +# Force IDEs to display all header files in project view +add_custom_target(MagnumMath SOURCES ${MagnumMath_HEADERS}) + install(FILES ${MagnumMath_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Math) add_subdirectory(Algorithms) diff --git a/src/Magnum/Math/Geometry/CMakeLists.txt b/src/Magnum/Math/Geometry/CMakeLists.txt index 1e35f14f7..ac7fb7ff8 100644 --- a/src/Magnum/Math/Geometry/CMakeLists.txt +++ b/src/Magnum/Math/Geometry/CMakeLists.txt @@ -33,6 +33,9 @@ if(BUILD_DEPRECATED) Rectangle.h) endif() +# Force IDEs to display all header files in project view +add_custom_target(MagnumMathGeometry SOURCES ${MagnumMathGeometry_HEADERS}) + install(FILES ${MagnumMathGeometry_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Math/Geometry) if(BUILD_TESTS) diff --git a/src/Magnum/Math/Test/Matrix4Test.cpp b/src/Magnum/Math/Test/Matrix4Test.cpp index b77a363a1..0403aaf68 100644 --- a/src/Magnum/Math/Test/Matrix4Test.cpp +++ b/src/Magnum/Math/Test/Matrix4Test.cpp @@ -274,10 +274,10 @@ void Matrix4Test::rotation() { CORRADE_COMPARE(Matrix4::rotation(Deg(-74.0f), {-1.0f, 2.0f, 2.0f}), Matrix4()); CORRADE_COMPARE(o.str(), "Math::Matrix4::rotation(): axis must be normalized\n"); - Matrix4 matrix({ 0.35612214f, -0.80181062f, 0.47987163f, 0.0f}, - { 0.47987163f, 0.59757638f, 0.6423595f, 0.0f}, - {-0.80181062f, 0.0015183985f, 0.59757638f, 0.0f}, - { 0.0f, 0.0f, 0.0f, 1.0f}); + Matrix4 matrix({ 0.35612202f, -0.80181062f, 0.47987163f, 0.0f}, + { 0.47987163f, 0.59757626f, 0.6423596f, 0.0f}, + {-0.80181062f, 0.00151846f, 0.59757626f, 0.0f}, + { 0.0f, 0.0f, 0.0f, 1.0f}); CORRADE_COMPARE(Matrix4::rotation(Deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized()), matrix); } @@ -399,9 +399,9 @@ void Matrix4Test::rotationNormalizedPart() { void Matrix4Test::rotationPart() { Matrix4 rotation = Matrix4::rotation(Deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized()); - Matrix3x3 expectedRotationPart(Vector3( 0.35612214f, -0.80181062f, 0.47987163f), - Vector3( 0.47987163f, 0.59757638f, 0.6423595f), - Vector3(-0.80181062f, 0.0015183985f, 0.59757638f)); + Matrix3x3 expectedRotationPart(Vector3( 0.35612206f, -0.80181074f, 0.47987169f), + Vector3( 0.47987163f, 0.59757626f, 0.64235962f), + Vector3(-0.80181062f, 0.00151846f, 0.59757626f)); /* For rotation and translation this is the same as rotationScaling() */ Matrix4 rotationTranslation = rotation*Matrix4::translation({2.0f, 5.0f, -3.0f}); diff --git a/src/Magnum/Math/Test/QuaternionTest.cpp b/src/Magnum/Math/Test/QuaternionTest.cpp index 1caa4d10a..a4a064bcf 100644 --- a/src/Magnum/Math/Test/QuaternionTest.cpp +++ b/src/Magnum/Math/Test/QuaternionTest.cpp @@ -347,7 +347,7 @@ void QuaternionTest::slerp() { CORRADE_COMPARE(o.str(), "Math::Quaternion::slerp(): quaternions must be normalized\n"); Quaternion slerp = Quaternion::slerp(a, b, 0.35f); - CORRADE_COMPARE(slerp, Quaternion({0.119165f, 0.0491109f, 0.0491109f}, 0.990442f)); + CORRADE_COMPARE(slerp, Quaternion({0.1191653f, 0.0491109f, 0.0491109f}, 0.9904423f)); } void QuaternionTest::transformVector() { diff --git a/src/Magnum/Math/Test/TypeTraitsTest.cpp b/src/Magnum/Math/Test/TypeTraitsTest.cpp index 4afda934d..ebdc96466 100644 --- a/src/Magnum/Math/Test/TypeTraitsTest.cpp +++ b/src/Magnum/Math/Test/TypeTraitsTest.cpp @@ -34,17 +34,29 @@ class TypeTraitsTest: public Corrade::TestSuite::Tester { public: TypeTraitsTest(); - void equalsFloatingPoint(); void equalsIntegral(); + void equalsFloatingPoint0(); + void equalsFloatingPoint1(); + void equalsFloatingPointLarge(); + void equalsFloatingPointInfinity(); + void equalsFloatingPointNaN(); private: - template void _equalsFloatingPoint(); - template void _equalsIntegral(); + template void _equalsIntegral(); + template void _equalsFloatingPoint0(); + template void _equalsFloatingPoint1(); + template void _equalsFloatingPointLarge(); + template void _equalsFloatingPointInfinity(); + template void _equalsFloatingPointNaN(); }; TypeTraitsTest::TypeTraitsTest() { addTests({&TypeTraitsTest::equalsIntegral, - &TypeTraitsTest::equalsFloatingPoint}); + &TypeTraitsTest::equalsFloatingPoint0, + &TypeTraitsTest::equalsFloatingPoint1, + &TypeTraitsTest::equalsFloatingPointLarge, + &TypeTraitsTest::equalsFloatingPointInfinity, + &TypeTraitsTest::equalsFloatingPointNaN}); } void TypeTraitsTest::equalsIntegral() { @@ -58,29 +70,68 @@ void TypeTraitsTest::equalsIntegral() { _equalsIntegral(); } -void TypeTraitsTest::equalsFloatingPoint() { - _equalsFloatingPoint(); +template void TypeTraitsTest::_equalsIntegral() { + CORRADE_VERIFY(!TypeTraits::equals(1, 1+TypeTraits::epsilon())); +} + +void TypeTraitsTest::equalsFloatingPoint0() { + _equalsFloatingPoint0(); #ifndef MAGNUM_TARGET_GLES - _equalsFloatingPoint(); + _equalsFloatingPoint0(); #endif } -template void TypeTraitsTest::_equalsIntegral() { - CORRADE_VERIFY(!TypeTraits::equals(1, 1+TypeTraits::epsilon())); +template void TypeTraitsTest::_equalsFloatingPoint0() { + CORRADE_VERIFY(TypeTraits::equals(T(0)+TypeTraits::epsilon()/T(2), T(0))); + CORRADE_VERIFY(!TypeTraits::equals(T(0)+TypeTraits::epsilon()*T(2), T(0))); } -template void TypeTraitsTest::_equalsFloatingPoint() { +void TypeTraitsTest::equalsFloatingPoint1() { + _equalsFloatingPoint1(); + #ifndef MAGNUM_TARGET_GLES + _equalsFloatingPoint1(); + #endif +} + +template void TypeTraitsTest::_equalsFloatingPoint1() { CORRADE_VERIFY(TypeTraits::equals(T(1)+TypeTraits::epsilon()/T(2), T(1))); - CORRADE_VERIFY(!TypeTraits::equals(T(1)+TypeTraits::epsilon()*T(2), T(1))); + CORRADE_VERIFY(!TypeTraits::equals(T(1)+TypeTraits::epsilon()*T(3), T(1))); +} + +void TypeTraitsTest::equalsFloatingPointLarge() { + _equalsFloatingPointLarge(); + #ifndef MAGNUM_TARGET_GLES + _equalsFloatingPointLarge(); + #endif +} + +template void TypeTraitsTest::_equalsFloatingPointLarge() { + CORRADE_VERIFY(TypeTraits::equals(T(25)+TypeTraits::epsilon()*T(2), T(25))); + CORRADE_VERIFY(!TypeTraits::equals(T(25)+TypeTraits::epsilon()*T(75), T(25))); +} - { - CORRADE_EXPECT_FAIL("Comparing to infinity is broken"); - CORRADE_VERIFY(TypeTraits::equals(std::numeric_limits::infinity(), - std::numeric_limits::infinity())); - } +void TypeTraitsTest::equalsFloatingPointInfinity() { + _equalsFloatingPointInfinity(); + #ifndef MAGNUM_TARGET_GLES + _equalsFloatingPointInfinity(); + #endif +} + +template void TypeTraitsTest::_equalsFloatingPointInfinity() { + CORRADE_VERIFY(TypeTraits::equals(std::numeric_limits::infinity(), + std::numeric_limits::infinity())); +} + +void TypeTraitsTest::equalsFloatingPointNaN() { + _equalsFloatingPointNaN(); + #ifndef MAGNUM_TARGET_GLES + _equalsFloatingPointNaN(); + #endif +} +template void TypeTraitsTest::_equalsFloatingPointNaN() { CORRADE_VERIFY(!TypeTraits::equals(std::numeric_limits::quiet_NaN(), - std::numeric_limits::quiet_NaN())); + std::numeric_limits::quiet_NaN())); } }}} diff --git a/src/Magnum/Math/Test/UnitTest.cpp b/src/Magnum/Math/Test/UnitTest.cpp index 6016f6c7e..adae64f11 100644 --- a/src/Magnum/Math/Test/UnitTest.cpp +++ b/src/Magnum/Math/Test/UnitTest.cpp @@ -86,8 +86,8 @@ void UnitTest::constructConversion() { } void UnitTest::compare() { - CORRADE_VERIFY(Sec(25.0f + TypeTraits::epsilon()/2) == Sec(25.0f)); - CORRADE_VERIFY(Sec(25.0f + TypeTraits::epsilon()*2) != Sec(25.0f)); + CORRADE_VERIFY(Sec(25.0f + TypeTraits::epsilon()/2.0f) == Sec(25.0f)); + CORRADE_VERIFY(Sec(25.0f + TypeTraits::epsilon()*75.0f) != Sec(25.0f)); constexpr bool c = Sec(3.0f) < Sec(3.0f); constexpr bool d = Sec(3.0f) <= Sec(3.0f); diff --git a/src/Magnum/Math/TypeTraits.h b/src/Magnum/Math/TypeTraits.h index 5ec50d96b..9502f51da 100644 --- a/src/Magnum/Math/TypeTraits.h +++ b/src/Magnum/Math/TypeTraits.h @@ -36,7 +36,7 @@ /** @brief Precision when testing floats for equality */ #ifndef FLOAT_EQUALITY_PRECISION -#define FLOAT_EQUALITY_PRECISION 1.0e-6f +#define FLOAT_EQUALITY_PRECISION 1.0e-5f #endif /** @brief Precision when testing doubles for equality */ @@ -107,14 +107,6 @@ template struct TypeTraits: Implementation::TypeTraitsDefault { #endif }; -/** @bug Infinity comparison! */ - -/** - * @todo Implement better fuzzy comparison algorithm, like at - * http://floating-point-gui.de/errors/comparison/ or - * http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm - */ - /* Integral scalar types */ namespace Implementation { template struct TypeTraitsIntegral: TypeTraitsDefault { @@ -160,13 +152,31 @@ template<> struct TypeTraits: Implementation::TypeTraitsIntegral { /* Floating-point scalar types */ namespace Implementation { - template struct TypeTraitsFloatingPoint { - TypeTraitsFloatingPoint() = delete; - static bool equals(T a, T b) { - return std::abs(a - b) < TypeTraits::epsilon(); - } - }; +template struct TypeTraitsFloatingPoint { + TypeTraitsFloatingPoint() = delete; + + static bool equals(T a, T b); +}; + +/* Adapted from http://floating-point-gui.de/errors/comparison/ */ +template bool TypeTraitsFloatingPoint::equals(const T a, const T b) { + /* Shortcut for binary equality (also infinites) */ + if (a == b) return true; + + const T absA = std::abs(a); + const T absB = std::abs(b); + const T difference = std::abs(a - b); + + /* One of the numbers is zero or both are extremely close to it, relative + error is meaningless */ + if (a == T{} || b == T{} || difference < TypeTraits::epsilon()) + return difference < TypeTraits::epsilon(); + + /* Relative error */ + return difference/(absA + absB) < TypeTraits::epsilon(); +} + } template<> struct TypeTraits: Implementation::TypeTraitsFloatingPoint { diff --git a/src/Magnum/Mesh.cpp b/src/Magnum/Mesh.cpp index 31630cb4f..c9ed84d0c 100644 --- a/src/Magnum/Mesh.cpp +++ b/src/Magnum/Mesh.cpp @@ -148,7 +148,7 @@ std::string Mesh::label() const { #endif } -Mesh& Mesh::setLabel(const std::string& label) { +Mesh& Mesh::setLabelInternal(const Containers::ArrayReference label) { #ifndef MAGNUM_TARGET_GLES Context::current()->state().debug->labelImplementation(GL_VERTEX_ARRAY, _id, label); #else diff --git a/src/Magnum/Mesh.h b/src/Magnum/Mesh.h index c2d40b3fb..4e3cdf063 100644 --- a/src/Magnum/Mesh.h +++ b/src/Magnum/Mesh.h @@ -467,7 +467,14 @@ class MAGNUM_EXPORT Mesh: public AbstractObject { * @def_gl{VERTEX_ARRAY} or @fn_gl_extension2{LabelObject,EXT,debug_label} * with @def_gl{VERTEX_ARRAY_OBJECT_EXT} */ - Mesh& setLabel(const std::string& label); + Mesh& setLabel(const std::string& label) { + return setLabelInternal({label.data(), label.size()}); + } + + /** @overload */ + template Mesh& setLabelInternal(const char(&label)[size]) { + return setLabelInternal(label); + } /** * @brief Whether the mesh is indexed @@ -836,6 +843,8 @@ class MAGNUM_EXPORT Mesh: public AbstractObject { #endif #endif + Mesh& setLabelInternal(Containers::ArrayReference label); + /* Computing stride of interleaved vertex attributes */ template static GLsizei strideOfInterleaved(const AbstractShaderProgram::Attribute& attribute, const U&... attributes) { return attribute.vectorSize()*AbstractShaderProgram::Attribute::VectorCount + strideOfInterleaved(attributes...); diff --git a/src/Magnum/MeshTools/CMakeLists.txt b/src/Magnum/MeshTools/CMakeLists.txt index e700d6f0f..39be0a151 100644 --- a/src/Magnum/MeshTools/CMakeLists.txt +++ b/src/Magnum/MeshTools/CMakeLists.txt @@ -54,7 +54,9 @@ set(MagnumMeshTools_HEADERS # Set shared library flags for the objects, as they will be part of shared lib # TODO: fix when CMake sets target_EXPORTS for OBJECT targets as well -add_library(MagnumMeshToolsObjects OBJECT ${MagnumMeshTools_SRCS}) +add_library(MagnumMeshToolsObjects OBJECT + ${MagnumMeshTools_SRCS} + ${MagnumMeshTools_HEADERS}) if(NOT BUILD_SHARED OR BUILD_STATIC_PIC) # TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property set_target_properties(MagnumMeshToolsObjects PROPERTIES COMPILE_FLAGS "-DMagnumMeshToolsObjects_EXPORTS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") diff --git a/src/Magnum/MultisampleTexture.h b/src/Magnum/MultisampleTexture.h index 739c92f07..97794042a 100644 --- a/src/Magnum/MultisampleTexture.h +++ b/src/Magnum/MultisampleTexture.h @@ -180,6 +180,10 @@ template class MultisampleTexture: public AbstractTextur AbstractTexture::setLabel(label); return *this; } + template MultisampleTexture& setLabel(const char(&label)[size]) { + AbstractTexture::setLabel(label); + return *this; + } #endif }; diff --git a/src/Magnum/Platform/CMakeLists.txt b/src/Magnum/Platform/CMakeLists.txt index 09087aca0..7001bd717 100644 --- a/src/Magnum/Platform/CMakeLists.txt +++ b/src/Magnum/Platform/CMakeLists.txt @@ -24,13 +24,16 @@ # # Headers -set(Platform_HEADERS +set(MagnumPlatform_HEADERS Platform.h Screen.h ScreenedApplication.h ScreenedApplication.hpp) -install(FILES ${Platform_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) +# Files to display in project view of IDEs only (filled in below) +set(MagnumPlatform_FILES ) + +install(FILES ${MagnumPlatform_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) # Android application if(WITH_ANDROIDAPPLICATION) @@ -40,12 +43,21 @@ if(WITH_ANDROIDAPPLICATION) include_directories(${ANDROID_NATIVE_APP_GLUE_INCLUDE_DIR}) - add_library(MagnumAndroidApplication STATIC + set(MagnumAndroidApplication_SRCS AndroidApplication.cpp - Implementation/Egl.cpp + Implementation/Egl.cpp) + set(MagnumAndroidApplication_HEADERS + AndroidApplication.h) + set(MagnumAndroidApplication_PRIVATE_HEADERS + Implementation/Egl.h) + + add_library(MagnumAndroidApplication STATIC + ${MagnumAndroidApplication_SRCS} + ${MagnumAndroidApplication_HEADERS} + ${MagnumAndroidApplication_PRIVATE_HEADERS} ${ANDROID_NATIVE_APP_GLUE_SRC}) set_target_properties(MagnumAndroidApplication PROPERTIES DEBUG_POSTFIX "-d") - install(FILES AndroidApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) + install(FILES ${MagnumAndroidApplication_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumAndroidApplication RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} @@ -55,34 +67,45 @@ endif() # GLUT application if(WITH_GLUTAPPLICATION) find_package(GLUT) - if(GLUT_FOUND) - add_library(MagnumGlutApplication STATIC GlutApplication.cpp) - set_target_properties(MagnumGlutApplication PROPERTIES DEBUG_POSTFIX "-d") - install(FILES GlutApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) - install(TARGETS MagnumGlutApplication - RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} - LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} - ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) - else() + if(NOT GLUT_FOUND) message(FATAL_ERROR "GLUT library, required by GlutApplication, was not found. Set WITH_GLUTAPPLICATION to OFF to skip building it.") endif() + + set(MagnumGlutApplication_SRCS GlutApplication.cpp) + set(MagnumGlutApplication_HEADERS GlutApplication.h) + + add_library(MagnumGlutApplication STATIC + ${MagnumGlutApplication_SRCS} + ${MagnumGlutApplication_HEADERS}) + set_target_properties(MagnumGlutApplication PROPERTIES DEBUG_POSTFIX "-d") + install(FILES ${MagnumGlutApplication_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) + install(TARGETS MagnumGlutApplication + RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} + LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} + ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) endif() # SDL2 application if(WITH_SDL2APPLICATION) find_package(SDL2) - if(SDL2_FOUND) - include_directories(${SDL2_INCLUDE_DIR}) - add_library(MagnumSdl2Application STATIC Sdl2Application.cpp) - set_target_properties(MagnumSdl2Application PROPERTIES DEBUG_POSTFIX "-d") - install(FILES Sdl2Application.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) - install(TARGETS MagnumSdl2Application - RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} - LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} - ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) - else() + if(NOT SDL2_FOUND) message(FATAL_ERROR "SDL2 library, required by Sdl2Application, was not found. Set WITH_SDL2APPLICATION to OFF to skip building it.") endif() + + include_directories(${SDL2_INCLUDE_DIR}) + + set(MagnumSdl2Application_SRCS Sdl2Application.cpp) + set(MagnumSdl2Application_HEADERS Sdl2Application.h) + + add_library(MagnumSdl2Application STATIC + ${MagnumSdl2Application_SRCS} + ${MagnumSdl2Application_HEADERS}) + set_target_properties(MagnumSdl2Application PROPERTIES DEBUG_POSTFIX "-d") + install(FILES ${MagnumSdl2Application_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) + install(TARGETS MagnumSdl2Application + RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} + LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} + ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) endif() # NaCl application @@ -91,9 +114,14 @@ if(WITH_NACLAPPLICATION) message(FATAL_ERROR "NaClApplication is available only when targeting Google Chrome Native Client. Set WITH_NACLAPPLICATION to OFF to skip building it.") endif() - add_library(MagnumNaClApplication STATIC NaClApplication.cpp) + set(MagnumNaClApplication_SRCS NaClApplication.cpp) + set(MagnumNaClApplication_HEADERS NaClApplication.h) + + add_library(MagnumNaClApplication STATIC + ${MagnumNaClApplication_SRCS} + ${MagnumNaClApplication_HEADERS}) set_target_properties(MagnumNaClApplication PROPERTIES DEBUG_POSTFIX "-d") - install(FILES NaClApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) + install(FILES ${MagnumNaClApplication_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumNaClApplication RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} @@ -106,9 +134,15 @@ if(WITH_WINDOWLESSNACLAPPLICATION) message(FATAL_ERROR "WindowlessNaClApplication is available only when targeting Google Chrome Native Client. Set WITH_WINDOWLESSNACLAPPLICATION to OFF to skip building it.") endif() - add_library(MagnumWindowlessNaClApplication STATIC WindowlessNaClApplication.cpp) + set(MagnumWindowlessNaClApplication_SRCS WindowlessNaClApplication.cpp) + set(MagnumWindowlessNaClApplication_HEADERS WindowlessNaClApplication.h) + + add_library(MagnumWindowlessNaClApplication STATIC + ${MagnumWindowlessNaClApplication_SRCS} + ${MagnumWindowlessNaClApplication_HEADERS}) set_target_properties(MagnumWindowlessNaClApplication PROPERTIES DEBUG_POSTFIX "-d") - install(FILES WindowlessNaClApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) + target_link_libraries(MagnumWindowlessNaClApplication Magnum ppapi_cpp ppapi) + install(FILES ${MagnumWindowlessNaClApplication_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumWindowlessNaClApplication RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} @@ -117,24 +151,38 @@ endif() # JavaScript and CSS stuff for NaCl if(WITH_NACLAPPLICATION OR WITH_WINDOWLESSNACLAPPLICATION) - install(FILES NaClApplication.js WebApplication.css DESTINATION ${MAGNUM_DATA_INSTALL_DIR}) + set(MagnumNaClApplication_FILES + NaClApplication.js + WebApplication.css) + list(APPEND MagnumPlatform_FILES ${MagnumNaClApplication_FILES}) + install(FILES ${MagnumNaClApplication_FILES} DESTINATION ${MAGNUM_DATA_INSTALL_DIR}) endif() # JavaScript and CSS stuff for Emscripten if(WITH_SDL2APPLICATION AND CORRADE_TARGET_EMSCRIPTEN) - install(FILES EmscriptenApplication.js WebApplication.css DESTINATION ${MAGNUM_DATA_INSTALL_DIR}) + set(MagnumSdl2Application_FILES + EmscriptenApplication.js + WebApplication.css) + list(APPEND MagnumPlatform_FILES ${MagnumSdl2Application_FILES}) + install(FILES ${MagnumSdl2Application_FILES} DESTINATION ${MAGNUM_DATA_INSTALL_DIR}) endif() # GLX application if(WITH_GLXAPPLICATION) set(NEED_ABSTRACTXAPPLICATION 1) set(NEED_GLXCONTEXT 1) - add_library(MagnumGlxApplication STATIC + + set(MagnumGlxApplication_SRCS $ $ GlxApplication.cpp) + set(MagnumGlxApplication_HEADERS GlxApplication.h) + + add_library(MagnumGlxApplication STATIC + ${MagnumGlxApplication_SRCS} + ${MagnumGlxApplication_HEADERS}) set_target_properties(MagnumGlxApplication PROPERTIES DEBUG_POSTFIX "-d") - install(FILES GlxApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) + install(FILES ${MagnumGlxApplication_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumGlxApplication RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} @@ -145,12 +193,18 @@ endif() if(WITH_XEGLAPPLICATION) set(NEED_ABSTRACTXAPPLICATION 1) set(NEED_EGLCONTEXT 1) - add_library(MagnumXEglApplication STATIC + + set(MagnumXEglApplication_SRCS $ $ XEglApplication.cpp) + set(MagnumXEglApplication_HEADERS XEglApplication.h) + + add_library(MagnumXEglApplication STATIC + ${MagnumXEglApplication_SRCS} + ${MagnumXEglApplication_HEADERS}) set_target_properties(MagnumXEglApplication PROPERTIES DEBUG_POSTFIX "-d") - install(FILES XEglApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) + install(FILES ${MagnumXEglApplication_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumXEglApplication RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} @@ -166,12 +220,18 @@ endif() # Windowless GLX application if(WITH_WINDOWLESSGLXAPPLICATION) - add_library(MagnumWindowlessGlxApplication STATIC WindowlessGlxApplication.cpp) + set(MagnumWindowlessGlxApplication_SRCS WindowlessGlxApplication.cpp) + set(MagnumWindowlessGlxApplication_HEADERS WindowlessGlxApplication.h) + + add_library(MagnumWindowlessGlxApplication STATIC + ${MagnumWindowlessGlxApplication_SRCS} + ${MagnumWindowlessGlxApplication_HEADERS}) # X11 macros are a mess, disable warnings for C-style casts set_target_properties(MagnumWindowlessGlxApplication PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast" DEBUG_POSTFIX "-d") - install(FILES WindowlessGlxApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) + target_link_libraries(MagnumWindowlessGlxApplication Magnum ${X11_LIBRARIES}) + install(FILES ${MagnumWindowlessGlxApplication_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumWindowlessGlxApplication RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} @@ -180,11 +240,17 @@ endif() # Windowless WGL application if(WITH_WINDOWLESSWGLAPPLICATION) - add_library(MagnumWindowlessWglApplication STATIC WindowlessWglApplication.cpp) + set(MagnumWindowlessWglApplication_SRCS WindowlessWglApplication.cpp) + set(MagnumWindowlessWglApplication_HEADERS WindowlessWglApplication.h) + + add_library(MagnumWindowlessWglApplication STATIC + ${MagnumWindowlessWglApplication_SRCS} + ${MagnumWindowlessWglApplication_HEADERS}) set_target_properties(MagnumWindowlessWglApplication PROPERTIES COMPILE_FLAGS "-DUNICODE" DEBUG_POSTFIX "-d") - install(FILES WindowlessWglApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) + target_link_libraries(MagnumWindowlessWglApplication Magnum) + install(FILES ${MagnumWindowlessWglApplication_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumWindowlessWglApplication RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} @@ -193,8 +259,15 @@ endif() # Windowless CGL application if(WITH_WINDOWLESSCGLAPPLICATION) - add_library(MagnumWindowlessCglApplication STATIC WindowlessCglApplication.cpp) - install(FILES WindowlessCglApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) + set(MagnumWindowlessCglApplication_SRCS WindowlessCglApplication.cpp) + set(MagnumWindowlessCglApplication_HEADERS WindowlessCglApplication.h) + + add_library(MagnumWindowlessCglApplication STATIC + ${MagnumWindowlessCglApplication_SRCS} + ${MagnumWindowlessCglApplication_HEADERS}) + set_target_properties(MagnumWindowlessCglApplication PROPERTIES DEBUG_POSTFIX "-d") + target_link_libraries(MagnumWindowlessCglApplication Magnum) + install(FILES ${MagnumWindowlessGlxApplication_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumWindowlessCglApplication RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} @@ -203,15 +276,28 @@ endif() # Abstract X application if(NEED_ABSTRACTXAPPLICATION) - add_library(MagnumAbstractXApplication OBJECT AbstractXApplication.cpp) + set(MagnumAbstractXApplication_SRCS AbstractXApplication.cpp) + set(MagnumAbstractXApplication_HEADERS AbstractXApplication.h) + + add_library(MagnumAbstractXApplication OBJECT + ${MagnumAbstractXApplication_SRCS} + ${MagnumAbstractXApplication_HEADERS}) # X11 macros are a mess, disable warnings for C-style casts set_target_properties(MagnumAbstractXApplication PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") - install(FILES AbstractXApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) + install(FILES ${MagnumAbstractXApplication_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) endif() # GLX context if(NEED_GLXCONTEXT) - add_library(MagnumGlxContextHandler OBJECT Implementation/GlxContextHandler.cpp) + set(MagnumGlxContextHandler_SRCS + Implementation/GlxContextHandler.cpp) + set(MagnumGlxContextHandler_PRIVATE_HEADERS + Implementation/AbstractContextHandler.h + Implementation/GlxContextHandler.h) + + add_library(MagnumGlxContextHandler OBJECT + ${MagnumGlxContextHandler_SRCS} + ${MagnumGlxContextHandler_PRIVATE_HEADERS}) # X11 macros are a mess, disable warnings for C-style casts set_target_properties(MagnumGlxContextHandler PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") endif() @@ -222,9 +308,18 @@ if(NEED_EGLCONTEXT) if(NOT EGL_FOUND) message(FATAL_ERROR "EGL library, required by some window contexts, was not found. Set WITH_*EGL*APPLICATION to OFF to skip building them.") endif() - add_library(MagnumEglContextHandler OBJECT + + set(MagnumEglContextHandler_SRCS Implementation/EglContextHandler.cpp Implementation/Egl.cpp) + set(MagnumEglContextHandler_PRIVATE_HEADERS + Implementation/AbstractContextHandler.h + Implementation/EglContextHandler.h + Implementation/Egl.h) + + add_library(MagnumEglContextHandler OBJECT + ${MagnumEglContextHandler_SRCS} + ${MagnumEglContextHandler_PRIVATE_HEADERS}) # X11 macros are a mess, disable warnings for C-style casts set_target_properties(MagnumEglContextHandler PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") endif() @@ -235,9 +330,9 @@ if(WITH_MAGNUMINFO) if(CORRADE_TARGET_APPLE) target_link_libraries(magnum-info MagnumWindowlessCglApplication) elseif(CORRADE_TARGET_NACL) - target_link_libraries(magnum-info MagnumWindowlessNaClApplication ppapi_cpp ppapi) + target_link_libraries(magnum-info MagnumWindowlessNaClApplication) elseif(CORRADE_TARGET_UNIX) - target_link_libraries(magnum-info MagnumWindowlessGlxApplication ${X11_LIBRARIES}) + target_link_libraries(magnum-info MagnumWindowlessGlxApplication) elseif(CORRADE_TARGET_WINDOWS) target_link_libraries(magnum-info MagnumWindowlessWglApplication) else() @@ -249,5 +344,9 @@ if(WITH_MAGNUMINFO) if(CORRADE_TARGET_NACL) install(FILES magnum-info-nacl.html DESTINATION ${MAGNUM_DATA_INSTALL_DIR} RENAME magnum-info.html) install(FILES magnum-info-nacl.nmf DESTINATION ${MAGNUM_DATA_INSTALL_DIR} RENAME magnum-info.nmf) + list(APPEND MagnumPlatform_FILES magnum-info-nacl.html magnum-info-nacl.nmf) endif() endif() + +# Force IDEs display also all header files and additional files in project view +add_custom_target(MagnumPlatform SOURCES ${MagnumPlatform_HEADERS} ${MagnumPlatform_FILES}) diff --git a/src/Magnum/Primitives/CMakeLists.txt b/src/Magnum/Primitives/CMakeLists.txt index 6f2119939..04c2976cf 100644 --- a/src/Magnum/Primitives/CMakeLists.txt +++ b/src/Magnum/Primitives/CMakeLists.txt @@ -52,7 +52,15 @@ set(MagnumPrimitives_HEADERS visibility.h) -add_library(MagnumPrimitives ${SHARED_OR_STATIC} ${MagnumPrimitives_SRCS}) +# Header files to display in project view of IDEs only +set(MagnumPrimitives_PRIVATE_HEADERS + Implementation/Spheroid.h + Implementation/WireframeSpheroid.h) + +add_library(MagnumPrimitives ${SHARED_OR_STATIC} + ${MagnumPrimitives_SRCS} + ${MagnumPrimitives_HEADERS} + ${MagnumPrimitives_PRIVATE_HEADERS}) set_target_properties(MagnumPrimitives PROPERTIES DEBUG_POSTFIX "-d") if(BUILD_STATIC_PIC) # TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property diff --git a/src/Magnum/Query.cpp b/src/Magnum/Query.cpp index d6bee60f2..8fd4e7a15 100644 --- a/src/Magnum/Query.cpp +++ b/src/Magnum/Query.cpp @@ -66,7 +66,7 @@ std::string AbstractQuery::label() const { #endif } -AbstractQuery& AbstractQuery::setLabel(const std::string& label) { +AbstractQuery& AbstractQuery::setLabelInternal(const Containers::ArrayReference label) { #ifndef MAGNUM_TARGET_GLES Context::current()->state().debug->labelImplementation(GL_QUERY, _id, label); #else diff --git a/src/Magnum/Query.h b/src/Magnum/Query.h index eaf646e95..302bfc955 100644 --- a/src/Magnum/Query.h +++ b/src/Magnum/Query.h @@ -29,6 +29,7 @@ * @brief Class @ref Magnum::AbstractQuery, @ref Magnum::PrimitiveQuery, @ref Magnum::SampleQuery, @ref Magnum::TimeQuery */ +#include #include #include "Magnum/AbstractObject.h" @@ -84,7 +85,14 @@ class MAGNUM_EXPORT AbstractQuery: public AbstractObject { * @def_gl{QUERY} or @fn_gl_extension2{LabelObject,EXT,debug_label} * with @def_gl{QUERY_OBJECT_EXT} */ - AbstractQuery& setLabel(const std::string& label); + AbstractQuery& setLabel(const std::string& label) { + return setLabelInternal({label.data(), label.size()}); + } + + /** @overload */ + template AbstractQuery& setLabel(const char(&label)[size]) { + return setLabelInternal(label); + } /** * @brief Whether the result is available @@ -140,6 +148,8 @@ class MAGNUM_EXPORT AbstractQuery: public AbstractObject { void begin(GLenum target); private: + AbstractQuery& setLabelInternal(Containers::ArrayReference label); + GLuint _id; GLenum target; }; @@ -227,6 +237,10 @@ class PrimitiveQuery: public AbstractQuery { AbstractQuery::setLabel(label); return *this; } + template PrimitiveQuery& setLabel(const char(&label)[size]) { + AbstractQuery::setLabel(label); + return *this; + } #endif }; #endif @@ -387,6 +401,10 @@ class SampleQuery: public AbstractQuery { AbstractQuery::setLabel(label); return *this; } + template SampleQuery& setLabel(const char(&label)[size]) { + AbstractQuery::setLabel(label); + return *this; + } #endif }; @@ -476,6 +494,10 @@ class TimeQuery: public AbstractQuery { AbstractQuery::setLabel(label); return *this; } + template TimeQuery& setLabel(const char(&label)[size]) { + AbstractQuery::setLabel(label); + return *this; + } #endif }; diff --git a/src/Magnum/RectangleTexture.h b/src/Magnum/RectangleTexture.h index 3bea9918d..cf98b51e9 100644 --- a/src/Magnum/RectangleTexture.h +++ b/src/Magnum/RectangleTexture.h @@ -404,6 +404,10 @@ class MAGNUM_EXPORT RectangleTexture: public AbstractTexture { AbstractTexture::setLabel(label); return *this; } + template RectangleTexture& setLabel(const char(&label)[size]) { + AbstractTexture::setLabel(label); + return *this; + } #endif }; diff --git a/src/Magnum/Renderbuffer.cpp b/src/Magnum/Renderbuffer.cpp index 47a99b4bb..d2a0e8b4e 100644 --- a/src/Magnum/Renderbuffer.cpp +++ b/src/Magnum/Renderbuffer.cpp @@ -81,7 +81,7 @@ std::string Renderbuffer::label() const { return Context::current()->state().debug->getLabelImplementation(GL_RENDERBUFFER, _id); } -Renderbuffer& Renderbuffer::setLabel(const std::string& label) { +Renderbuffer& Renderbuffer::setLabelInternal(const Containers::ArrayReference label) { Context::current()->state().debug->labelImplementation(GL_RENDERBUFFER, _id, label); return *this; } diff --git a/src/Magnum/Renderbuffer.h b/src/Magnum/Renderbuffer.h index cfff3ce93..579a3516b 100644 --- a/src/Magnum/Renderbuffer.h +++ b/src/Magnum/Renderbuffer.h @@ -29,6 +29,8 @@ * @brief Class @ref Magnum::Renderbuffer */ +#include + #include "Magnum/AbstractObject.h" #include "Magnum/Magnum.h" @@ -139,7 +141,14 @@ class MAGNUM_EXPORT Renderbuffer: public AbstractObject { * @fn_gl_extension2{LabelObject,EXT,debug_label} with * @def_gl{RENDERBUFFER} */ - Renderbuffer& setLabel(const std::string& label); + Renderbuffer& setLabel(const std::string& label) { + return setLabelInternal({label.data(), label.size()}); + } + + /** @overload */ + template Renderbuffer& setLabel(const char(&label)[size]) { + return setLabelInternal(label); + } /** * @brief Set renderbuffer storage @@ -173,6 +182,8 @@ class MAGNUM_EXPORT Renderbuffer: public AbstractObject { void setStorageMultisample(Int samples, RenderbufferFormat internalFormat, const Vector2i& size); private: + Renderbuffer& setLabelInternal(Containers::ArrayReference label); + void MAGNUM_LOCAL storageImplementationDefault(RenderbufferFormat internalFormat, const Vector2i& size); #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL storageImplementationDSA(RenderbufferFormat internalFormat, const Vector2i& size); diff --git a/src/Magnum/Renderer.cpp b/src/Magnum/Renderer.cpp index e35a83c7f..9d68aab86 100644 --- a/src/Magnum/Renderer.cpp +++ b/src/Magnum/Renderer.cpp @@ -35,8 +35,16 @@ namespace Magnum { +void Renderer::enable(const Feature feature) { + glEnable(GLenum(feature)); +} + +void Renderer::disable(const Feature feature) { + glDisable(GLenum(feature)); +} + void Renderer::setFeature(const Feature feature, const bool enabled) { - enabled ? glEnable(GLenum(feature)) : glDisable(GLenum(feature)); + enabled ? enable(feature) : disable(feature); } void Renderer::setHint(const Hint target, const HintMode mode) { diff --git a/src/Magnum/Renderer.h b/src/Magnum/Renderer.h index bb90767ed..6df8f9513 100644 --- a/src/Magnum/Renderer.h +++ b/src/Magnum/Renderer.h @@ -74,7 +74,7 @@ class MAGNUM_EXPORT Renderer { * @brief Features * * All features are disabled by default unless specified otherwise. - * @see @ref setFeature() + * @see @ref enable(), @ref disable(), @ref setFeature() */ enum class Feature: GLenum { /** @@ -219,9 +219,28 @@ class MAGNUM_EXPORT Renderer { }; /** - * @brief Set feature + * @brief Enable feature * - * @see @fn_gl{Enable}/@fn_gl{Disable} + * @see @ref disable(), @ref setFeature(), @fn_gl{Enable} + */ + static void enable(Feature feature); + + /** + * @brief Disable feature + * + * @see @ref enable(), @ref setFeature(), @fn_gl{Disable} + */ + static void disable(Feature feature); + + /** + * @brief Enable or disable feature + * + * Convenience equivalent to the following: + * @code + * enabled ? Renderer::enable(feature) : Renderer::disable(feature) + * @endcode + * Prefer to use @ref enable() and @ref disable() directly to avoid + * unnecessary branching. */ static void setFeature(Feature feature, bool enabled); diff --git a/src/Magnum/SceneGraph/CMakeLists.txt b/src/Magnum/SceneGraph/CMakeLists.txt index f9166bec9..3ec9ca2e2 100644 --- a/src/Magnum/SceneGraph/CMakeLists.txt +++ b/src/Magnum/SceneGraph/CMakeLists.txt @@ -71,7 +71,9 @@ set(MagnumSceneGraph_HEADERS # Set shared library flags for the objects, as they will be part of shared lib # TODO: fix when CMake sets target_EXPORTS for OBJECT targets as well -add_library(MagnumSceneGraphObjects OBJECT ${MagnumSceneGraph_SRCS}) +add_library(MagnumSceneGraphObjects OBJECT + ${MagnumSceneGraph_SRCS} + ${MagnumSceneGraph_HEADERS}) if(NOT BUILD_STATIC OR BUILD_STATIC_PIC) # TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property set_target_properties(MagnumSceneGraphObjects PROPERTIES COMPILE_FLAGS "-DMagnumSceneGraphObjects_EXPORTS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") diff --git a/src/Magnum/SceneGraph/Drawable.h b/src/Magnum/SceneGraph/Drawable.h index f2c864d31..9ea2d5eb1 100644 --- a/src/Magnum/SceneGraph/Drawable.h +++ b/src/Magnum/SceneGraph/Drawable.h @@ -109,9 +109,9 @@ void MyApplication::drawEvent() { .setAmbientColor(ambientColor); camera.draw(phongObjects); - Renderer::setFeature(Renderer::Feature::Blending, true); + Renderer::enable(Renderer::Feature::Blending); camera.draw(transparentObjects); - Renderer::setFeature(Renderer::Feature::Blending, false); + Renderer::disable(Renderer::Feature::Blending); // ... } diff --git a/src/Magnum/Shader.cpp b/src/Magnum/Shader.cpp index 506908b0d..bcd78ca4b 100644 --- a/src/Magnum/Shader.cpp +++ b/src/Magnum/Shader.cpp @@ -581,7 +581,7 @@ std::string Shader::label() const { #endif } -Shader& Shader::setLabel(const std::string& label) { +Shader& Shader::setLabelInternal(const Containers::ArrayReference label) { #ifndef MAGNUM_TARGET_GLES Context::current()->state().debug->labelImplementation(GL_SHADER, _id, label); #else diff --git a/src/Magnum/Shader.h b/src/Magnum/Shader.h index 6c6971b68..acc4c0aa0 100644 --- a/src/Magnum/Shader.h +++ b/src/Magnum/Shader.h @@ -32,6 +32,7 @@ #include #include #include +#include #include "Magnum/AbstractObject.h" #include "Magnum/Magnum.h" @@ -508,7 +509,14 @@ class MAGNUM_EXPORT Shader: public AbstractObject { * @def_gl{SHADER} or @fn_gl_extension2{LabelObject,EXT,debug_label} * with @def_gl{SHADER_OBJECT_EXT} */ - Shader& setLabel(const std::string& label); + Shader& setLabel(const std::string& label) { + return setLabelInternal({label.data(), label.size()}); + } + + /** @overload */ + template Shader& setLabel(const char(&label)[size]) { + return setLabelInternal(label); + } /** @brief %Shader type */ Type type() const { return _type; } @@ -552,6 +560,8 @@ class MAGNUM_EXPORT Shader: public AbstractObject { } private: + Shader& setLabelInternal(Containers::ArrayReference label); + Type _type; GLuint _id; diff --git a/src/Magnum/Shaders/CMakeLists.txt b/src/Magnum/Shaders/CMakeLists.txt index 6ffa51558..04a0a0db9 100644 --- a/src/Magnum/Shaders/CMakeLists.txt +++ b/src/Magnum/Shaders/CMakeLists.txt @@ -34,8 +34,6 @@ set(MagnumShaders_SRCS Vector.cpp VertexColor.cpp - Implementation/CreateCompatibilityShader.cpp - ${MagnumShaders_RCS}) set(MagnumShaders_HEADERS @@ -51,6 +49,9 @@ set(MagnumShaders_HEADERS visibility.h) +# Header files to display in project view of IDEs only +set(MagnumShaders_PRIVATE_HEADERS Implementation/CreateCompatibilityShader.h) + if(BUILD_STATIC) set(MagnumShaders_HEADERS ${MagnumShaders_HEADERS} resourceImport.hpp) @@ -59,7 +60,10 @@ if(BUILD_STATIC) endif() endif() -add_library(MagnumShaders ${SHARED_OR_STATIC} ${MagnumShaders_SRCS}) +add_library(MagnumShaders ${SHARED_OR_STATIC} + ${MagnumShaders_SRCS} + ${MagnumShaders_HEADERS} + ${MagnumShaders_PRIVATE_HEADERS}) set_target_properties(MagnumShaders PROPERTIES DEBUG_POSTFIX "-d") if(BUILD_STATIC_PIC) # TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property diff --git a/src/Magnum/Shaders/DistanceFieldVector.cpp b/src/Magnum/Shaders/DistanceFieldVector.cpp index 8dd861719..5ef839799 100644 --- a/src/Magnum/Shaders/DistanceFieldVector.cpp +++ b/src/Magnum/Shaders/DistanceFieldVector.cpp @@ -65,8 +65,7 @@ template DistanceFieldVector::DistanceFieldV std::initializer_list> ss{std::ref(frag), std::ref(vert)}; CORRADE_INTERNAL_ASSERT_OUTPUT(Shader::compile(ss)); - AbstractShaderProgram::attachShader(frag); - AbstractShaderProgram::attachShader(vert); + AbstractShaderProgram::attachShaders({frag, vert}); #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported(version)) diff --git a/src/Magnum/Shaders/Flat.cpp b/src/Magnum/Shaders/Flat.cpp index 41effb5b4..67375357c 100644 --- a/src/Magnum/Shaders/Flat.cpp +++ b/src/Magnum/Shaders/Flat.cpp @@ -70,8 +70,7 @@ template Flat::Flat(const Flags flags): tran std::initializer_list> ss{std::ref(frag), std::ref(vert)}; CORRADE_INTERNAL_ASSERT_OUTPUT(Shader::compile(ss)); - attachShader(vert); - attachShader(frag); + attachShaders({vert, frag}); #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported(version)) diff --git a/src/Magnum/Shaders/Implementation/CreateCompatibilityShader.cpp b/src/Magnum/Shaders/Implementation/CreateCompatibilityShader.cpp deleted file mode 100644 index 04accbfa1..000000000 --- a/src/Magnum/Shaders/Implementation/CreateCompatibilityShader.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - This file is part of Magnum. - - Copyright © 2010, 2011, 2012, 2013, 2014 - Vladimír Vondruš - - 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 "CreateCompatibilityShader.h" - -#include - -#include "Magnum/Context.h" -#include "Magnum/Extensions.h" - -namespace Magnum { namespace Shaders { namespace Implementation { - -Shader createCompatibilityShader(const Version version, const Shader::Type type) { - Shader shader(version, type); - - #ifndef MAGNUM_TARGET_GLES - if(Context::current()->isExtensionDisabled(version)) - shader.addSource("#define DISABLE_GL_ARB_explicit_attrib_location\n"); - if(Context::current()->isExtensionDisabled(version)) - shader.addSource("#define DISABLE_GL_ARB_shading_language_420pack\n"); - if(Context::current()->isExtensionDisabled(version)) - shader.addSource("#define DISABLE_GL_ARB_explicit_uniform_location\n"); - #endif - - /* My Android emulator (running on NVidia) doesn't define GL_ES - preprocessor macro, thus *all* the stock shaders fail to compile */ - /** @todo remove this when Android emulator is sane */ - #ifdef CORRADE_TARGET_ANDROID - shader.addSource("#ifndef GL_ES\n#define GL_ES 1\n#endif\n"); - #endif - - shader.addSource(Utility::Resource("MagnumShaders").get("compatibility.glsl")); - return shader; -} - -}}} diff --git a/src/Magnum/Shaders/Implementation/CreateCompatibilityShader.h b/src/Magnum/Shaders/Implementation/CreateCompatibilityShader.h index bb8790629..b3cd0322f 100644 --- a/src/Magnum/Shaders/Implementation/CreateCompatibilityShader.h +++ b/src/Magnum/Shaders/Implementation/CreateCompatibilityShader.h @@ -25,11 +25,36 @@ DEALINGS IN THE SOFTWARE. */ +#include + +#include "Magnum/Context.h" +#include "Magnum/Extensions.h" #include "Magnum/Shader.h" namespace Magnum { namespace Shaders { namespace Implementation { -Shader createCompatibilityShader(Version version, Shader::Type type); +inline Shader createCompatibilityShader(Version version, Shader::Type type) { + Shader shader(version, type); + + #ifndef MAGNUM_TARGET_GLES + if(Context::current()->isExtensionDisabled(version)) + shader.addSource("#define DISABLE_GL_ARB_explicit_attrib_location\n"); + if(Context::current()->isExtensionDisabled(version)) + shader.addSource("#define DISABLE_GL_ARB_shading_language_420pack\n"); + if(Context::current()->isExtensionDisabled(version)) + shader.addSource("#define DISABLE_GL_ARB_explicit_uniform_location\n"); + #endif + + /* My Android emulator (running on NVidia) doesn't define GL_ES + preprocessor macro, thus *all* the stock shaders fail to compile */ + /** @todo remove this when Android emulator is sane */ + #ifdef CORRADE_TARGET_ANDROID + shader.addSource("#ifndef GL_ES\n#define GL_ES 1\n#endif\n"); + #endif + + shader.addSource(Utility::Resource("MagnumShaders").get("compatibility.glsl")); + return shader; +} }}} diff --git a/src/Magnum/Shaders/MeshVisualizer.cpp b/src/Magnum/Shaders/MeshVisualizer.cpp index 0696cbbb8..25f2d8dd0 100644 --- a/src/Magnum/Shaders/MeshVisualizer.cpp +++ b/src/Magnum/Shaders/MeshVisualizer.cpp @@ -88,8 +88,7 @@ MeshVisualizer::MeshVisualizer(const Flags flags): flags(flags), transformationP #endif Shader::compile({std::ref(vert), std::ref(frag)}); - attachShader(vert); - attachShader(frag); + attachShaders({vert, frag}); #ifndef MAGNUM_TARGET_GLES if(geom) attachShader(*geom); #endif diff --git a/src/Magnum/Shaders/Phong.cpp b/src/Magnum/Shaders/Phong.cpp index 02bcaae0c..5c8666724 100644 --- a/src/Magnum/Shaders/Phong.cpp +++ b/src/Magnum/Shaders/Phong.cpp @@ -67,8 +67,7 @@ Phong::Phong(const Flags flags): transformationMatrixUniform(0), projectionMatri /* GCC 4.4 has explicit std::reference_wrapper constructor */ CORRADE_INTERNAL_ASSERT_OUTPUT(Shader::compile({std::ref(vert), std::ref(frag)})); - attachShader(vert); - attachShader(frag); + attachShaders({vert, frag}); #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported(version)) diff --git a/src/Magnum/Shaders/Vector.cpp b/src/Magnum/Shaders/Vector.cpp index 5a608384f..38dec2134 100644 --- a/src/Magnum/Shaders/Vector.cpp +++ b/src/Magnum/Shaders/Vector.cpp @@ -65,8 +65,7 @@ template Vector::Vector(): transformationPro std::initializer_list> ss{std::ref(frag), std::ref(vert)}; CORRADE_INTERNAL_ASSERT_OUTPUT(Shader::compile(ss)); - AbstractShaderProgram::attachShader(vert); - AbstractShaderProgram::attachShader(frag); + AbstractShaderProgram::attachShaders({vert, frag}); #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported(version)) diff --git a/src/Magnum/Shaders/VertexColor.cpp b/src/Magnum/Shaders/VertexColor.cpp index e64f31b23..879333e42 100644 --- a/src/Magnum/Shaders/VertexColor.cpp +++ b/src/Magnum/Shaders/VertexColor.cpp @@ -73,8 +73,7 @@ template VertexColor::VertexColor(): transfo std::initializer_list> ss{std::ref(frag), std::ref(vert)}; CORRADE_INTERNAL_ASSERT_OUTPUT(Shader::compile(ss)); - attachShader(vert); - attachShader(frag); + attachShaders({vert, frag}); #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported(version)) diff --git a/src/Magnum/Shapes/CMakeLists.txt b/src/Magnum/Shapes/CMakeLists.txt index 4c8669773..42f90ba38 100644 --- a/src/Magnum/Shapes/CMakeLists.txt +++ b/src/Magnum/Shapes/CMakeLists.txt @@ -61,7 +61,13 @@ set(MagnumShapes_HEADERS shapeImplementation.h visibility.h) -add_library(MagnumShapes ${SHARED_OR_STATIC} ${MagnumShapes_SRCS}) +# Header files to display in project view of IDEs only +set(MagnumShapes_PRIVATE_HEADERS Implementation/CollisionDispatch.h) + +add_library(MagnumShapes ${SHARED_OR_STATIC} + ${MagnumShapes_SRCS} + ${MagnumShapes_HEADERS} + ${MagnumShapes_PRIVATE_HEADERS}) set_target_properties(MagnumShapes PROPERTIES DEBUG_POSTFIX "-d") if(BUILD_STATIC_PIC) # TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property diff --git a/src/Magnum/Test/AbstractOpenGLTester.h b/src/Magnum/Test/AbstractOpenGLTester.h index e73d70032..3731007a5 100644 --- a/src/Magnum/Test/AbstractOpenGLTester.h +++ b/src/Magnum/Test/AbstractOpenGLTester.h @@ -54,8 +54,8 @@ class AbstractOpenGLTester: public TestSuite::Tester, public Platform::Windowles AbstractOpenGLTester::AbstractOpenGLTester(): Platform::WindowlessApplication({zero, nullptr}) { if(Context::current()->isExtensionSupported()) { - Renderer::setFeature(Renderer::Feature::DebugOutput, true); - Renderer::setFeature(Renderer::Feature::DebugOutputSynchronous, true); + Renderer::enable(Renderer::Feature::DebugOutput); + Renderer::enable(Renderer::Feature::DebugOutputSynchronous); DebugMessage::setDefaultCallback(); } } diff --git a/src/Magnum/Test/AbstractQueryGLTest.cpp b/src/Magnum/Test/AbstractQueryGLTest.cpp index 2c8d35b1c..503d0f511 100644 --- a/src/Magnum/Test/AbstractQueryGLTest.cpp +++ b/src/Magnum/Test/AbstractQueryGLTest.cpp @@ -113,7 +113,15 @@ void AbstractQueryGLTest::label() { !Context::current()->isExtensionSupported()) CORRADE_SKIP("Required extension is not available"); + { + /** @todo Is this even legal optimization? */ + CORRADE_EXPECT_FAIL("The object must be used at least once before setting/querying label."); + CORRADE_VERIFY(false); + } SampleQuery query; + query.begin(SampleQuery::Target::AnySamplesPassed); + query.end(); + CORRADE_COMPARE(query.label(), ""); query.setLabel("MyQuery"); diff --git a/src/Magnum/Test/AbstractShaderProgramGLTest.cpp b/src/Magnum/Test/AbstractShaderProgramGLTest.cpp index 22a609535..c848ddc10 100644 --- a/src/Magnum/Test/AbstractShaderProgramGLTest.cpp +++ b/src/Magnum/Test/AbstractShaderProgramGLTest.cpp @@ -155,7 +155,7 @@ void AbstractShaderProgramGLTest::label() { namespace { struct MyPublicShader: AbstractShaderProgram { - using AbstractShaderProgram::attachShader; + using AbstractShaderProgram::attachShaders; using AbstractShaderProgram::bindAttributeLocation; #ifndef MAGNUM_TARGET_GLES using AbstractShaderProgram::bindFragmentDataLocationIndexed; @@ -190,8 +190,7 @@ void AbstractShaderProgramGLTest::create() { CORRADE_VERIFY(fragCompiled); MyPublicShader program; - program.attachShader(vert); - program.attachShader(frag); + program.attachShaders({vert, frag}); MAGNUM_VERIFY_NO_ERROR(); @@ -232,8 +231,7 @@ void AbstractShaderProgramGLTest::createMultipleOutputs() { CORRADE_VERIFY(fragCompiled); MyPublicShader program; - program.attachShader(vert); - program.attachShader(frag); + program.attachShaders({vert, frag}); MAGNUM_VERIFY_NO_ERROR(); @@ -270,8 +268,7 @@ void AbstractShaderProgramGLTest::createMultipleOutputsIndexed() { CORRADE_VERIFY(fragCompiled); MyPublicShader program; - program.attachShader(vert); - program.attachShader(frag); + program.attachShaders({vert, frag}); MAGNUM_VERIFY_NO_ERROR(); @@ -306,21 +303,17 @@ MyShader::MyShader() { #ifndef MAGNUM_TARGET_GLES Shader vert(Version::GL210, Shader::Type::Vertex); - #else - Shader vert(Version::GLES200, Shader::Type::Vertex); - #endif - vert.addSource(rs.get("MyShader.vert")) - .compile(); - attachShader(vert); - - #ifndef MAGNUM_TARGET_GLES Shader frag(Version::GL210, Shader::Type::Fragment); #else + Shader vert(Version::GLES200, Shader::Type::Vertex); Shader frag(Version::GLES200, Shader::Type::Fragment); #endif - frag.addSource(rs.get("MyShader.frag")) - .compile(); - attachShader(frag); + vert.addSource(rs.get("MyShader.vert")); + frag.addSource(rs.get("MyShader.frag")); + + Shader::compile({vert, frag}); + + attachShaders({vert, frag}); bindAttributeLocation(0, "position"); link(); diff --git a/src/Magnum/Test/AbstractTextureGLTest.cpp b/src/Magnum/Test/AbstractTextureGLTest.cpp index f5c059f0a..8c4497c05 100644 --- a/src/Magnum/Test/AbstractTextureGLTest.cpp +++ b/src/Magnum/Test/AbstractTextureGLTest.cpp @@ -100,7 +100,14 @@ void AbstractTextureGLTest::label() { !Context::current()->isExtensionSupported()) CORRADE_SKIP("Required extension is not available"); + { + /** @todo Is this even legal optimization? */ + CORRADE_EXPECT_FAIL("The object must be used at least once before setting/querying label."); + CORRADE_VERIFY(false); + } Texture2D texture; + texture.setMinificationFilter(Sampler::Filter::Linear); + CORRADE_COMPARE(texture.label(), ""); texture.setLabel("MyTexture"); diff --git a/src/Magnum/Test/BufferGLTest.cpp b/src/Magnum/Test/BufferGLTest.cpp index 632201876..ba4d70790 100644 --- a/src/Magnum/Test/BufferGLTest.cpp +++ b/src/Magnum/Test/BufferGLTest.cpp @@ -125,7 +125,14 @@ void BufferGLTest::label() { !Context::current()->isExtensionSupported()) CORRADE_SKIP("Required extension is not available"); + { + /** @todo Is this even legal optimization? */ + CORRADE_EXPECT_FAIL("The object must be used at least once before setting/querying label."); + CORRADE_VERIFY(false); + } Buffer buffer; + buffer.setData({nullptr, 3}, BufferUsage::StaticDraw); + CORRADE_COMPARE(buffer.label(), ""); buffer.setLabel("MyBuffer"); diff --git a/src/Magnum/Test/CubeMapTextureGLTest.cpp b/src/Magnum/Test/CubeMapTextureGLTest.cpp index 7428b0e10..0f77f2bc4 100644 --- a/src/Magnum/Test/CubeMapTextureGLTest.cpp +++ b/src/Magnum/Test/CubeMapTextureGLTest.cpp @@ -467,7 +467,7 @@ void CubeMapTextureGLTest::invalidateImage() { void CubeMapTextureGLTest::invalidateSubImage() { CubeMapTexture texture; texture.setStorage(2, TextureFormat::RGBA8, Vector2i(32)); - texture.invalidateSubImage(1, Vector3i(2), Vector3i(8)); + texture.invalidateSubImage(1, Vector3i(2), Vector3i(Vector2i(8), 4)); MAGNUM_VERIFY_NO_ERROR(); } diff --git a/src/Magnum/Test/DebugGLTest.cpp b/src/Magnum/Test/DebugGLTest.cpp index 0fe9f26e1..4e25d5112 100644 --- a/src/Magnum/Test/DebugGLTest.cpp +++ b/src/Magnum/Test/DebugGLTest.cpp @@ -77,16 +77,16 @@ void DebugGLTest::insertMessage() { if(!Context::current()->isExtensionSupported()) CORRADE_SKIP(Extensions::GL::KHR::debug::string() + std::string(" is not supported")); - Renderer::setFeature(Renderer::Feature::DebugOutput, true); + Renderer::enable(Renderer::Feature::DebugOutput); - Renderer::setFeature(Renderer::Feature::DebugOutputSynchronous, true); + Renderer::enable(Renderer::Feature::DebugOutputSynchronous); std::ostringstream out; Debug::setOutput(&out); DebugMessage::setDefaultCallback(); DebugMessage::insert(DebugMessage::Source::Application, DebugMessage::Type::Marker, 1337, DebugMessage::Severity::Notification, "Hello from OpenGL command stream!"); - Renderer::setFeature(Renderer::Feature::DebugOutput, false); + Renderer::enable(Renderer::Feature::DebugOutput); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(out.str(), diff --git a/src/Magnum/Test/FramebufferGLTest.cpp b/src/Magnum/Test/FramebufferGLTest.cpp index 6e4641c5a..e5d610f60 100644 --- a/src/Magnum/Test/FramebufferGLTest.cpp +++ b/src/Magnum/Test/FramebufferGLTest.cpp @@ -206,7 +206,19 @@ void FramebufferGLTest::label() { !Context::current()->isExtensionSupported()) CORRADE_SKIP("Required extension is not available"); + { + /** @todo Is this even legal optimization? */ + CORRADE_EXPECT_FAIL("The object must be used at least once before setting/querying label."); + CORRADE_VERIFY(false); + } + Renderbuffer renderbuffer; + #ifndef MAGNUM_TARGET_GLES2 + renderbuffer.setStorage(RenderbufferFormat::RGBA8, {128, 128}); + #else + renderbuffer.setStorage(RenderbufferFormat::RGBA4, {128, 128}); + #endif Framebuffer framebuffer({{}, Vector2i(32)}); + framebuffer.attachRenderbuffer(Framebuffer::BufferAttachment(Framebuffer::BufferAttachment::Depth), renderbuffer); CORRADE_COMPARE(framebuffer.label(), ""); MAGNUM_VERIFY_NO_ERROR(); @@ -638,11 +650,6 @@ void FramebufferGLTest::invalidate() { #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::framebuffer_object::string() + std::string(" is not available.")); - if(!Context::current()->isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::invalidate_subdata::string() + std::string(" is not available.")); - #elif defined(MAGNUM_TARGET_GLES2) - if(!Context::current()->isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::discard_framebuffer::string() + std::string(" is not available.")); #endif Renderbuffer color; @@ -670,11 +677,6 @@ void FramebufferGLTest::invalidateSub() { #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::framebuffer_object::string() + std::string(" is not available.")); - if(!Context::current()->isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::invalidate_subdata::string() + std::string(" is not available.")); - #elif defined(MAGNUM_TARGET_GLES2) - if(!Context::current()->isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::discard_framebuffer::string() + std::string(" is not available.")); #endif Renderbuffer color; diff --git a/src/Magnum/Test/MeshGLTest.cpp b/src/Magnum/Test/MeshGLTest.cpp index 42d8badb3..4eadd934b 100644 --- a/src/Magnum/Test/MeshGLTest.cpp +++ b/src/Magnum/Test/MeshGLTest.cpp @@ -302,7 +302,15 @@ void MeshGLTest::label() { !Context::current()->isExtensionSupported()) CORRADE_SKIP("Required extension is not available"); + { + /** @todo Is this even legal optimization? */ + CORRADE_EXPECT_FAIL("The object must be used at least once before setting/querying label."); + CORRADE_VERIFY(false); + } + Buffer buffer{Buffer::Target::ElementArray}; Mesh mesh; + mesh.setIndexBuffer(buffer, 0, Mesh::IndexType::UnsignedShort); + CORRADE_COMPARE(mesh.label(), ""); mesh.setLabel("MyMesh"); @@ -377,8 +385,8 @@ FloatShader::FloatShader(const std::string& type, const std::string& conversion) /* GCC 4.4 has explicit std::reference_wrapper constructor */ CORRADE_INTERNAL_ASSERT_OUTPUT(Shader::compile({std::ref(vert), std::ref(frag)})); - attachShader(vert); - attachShader(frag); + + attachShaders({vert, frag}); bindAttributeLocation(0, "value"); @@ -407,8 +415,8 @@ IntegerShader::IntegerShader(const std::string& type) { /* GCC 4.4 has explicit std::reference_wrapper constructor */ CORRADE_INTERNAL_ASSERT_OUTPUT(Shader::compile({std::ref(vert), std::ref(frag)})); - attachShader(vert); - attachShader(frag); + + attachShaders({vert, frag}); bindAttributeLocation(0, "value"); @@ -433,8 +441,8 @@ DoubleShader::DoubleShader(const std::string& type, const std::string& outputTyp /* GCC 4.4 has explicit std::reference_wrapper constructor */ CORRADE_INTERNAL_ASSERT_OUTPUT(Shader::compile({std::ref(vert), std::ref(frag)})); - attachShader(vert); - attachShader(frag); + + attachShaders({vert, frag}); bindAttributeLocation(0, "value"); @@ -1106,8 +1114,8 @@ MultipleShader::MultipleShader() { /* GCC 4.4 has explicit std::reference_wrapper constructor */ CORRADE_INTERNAL_ASSERT_OUTPUT(Shader::compile({std::ref(vert), std::ref(frag)})); - attachShader(vert); - attachShader(frag); + + attachShaders({vert, frag}); bindAttributeLocation(Position::Location, "position"); bindAttributeLocation(Normal::Location, "normal"); diff --git a/src/Magnum/Test/PrimitiveQueryGLTest.cpp b/src/Magnum/Test/PrimitiveQueryGLTest.cpp index 7099cd0ae..c85a70f05 100644 --- a/src/Magnum/Test/PrimitiveQueryGLTest.cpp +++ b/src/Magnum/Test/PrimitiveQueryGLTest.cpp @@ -62,15 +62,16 @@ void PrimitiveQueryGLTest::query() { explicit MyShader() { Utility::Resource rs("QueryGLTest"); - Shader vert(Version::GL210, Shader::Type::Vertex); - vert.addSource(rs.get("MyShader.vert")); - CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile()); - attachShader(vert); + Shader vert(Version::GL210, Shader::Type::Vertex); Shader frag(Version::GL210, Shader::Type::Fragment); + + vert.addSource(rs.get("MyShader.vert")); frag.addSource(rs.get("MyShader.frag")); - CORRADE_INTERNAL_ASSERT_OUTPUT(frag.compile()); - attachShader(frag); + + CORRADE_INTERNAL_ASSERT_OUTPUT(Shader::compile({vert, frag})); + + attachShaders({vert, frag}); CORRADE_INTERNAL_ASSERT_OUTPUT(link()); } diff --git a/src/Magnum/Test/RenderbufferGLTest.cpp b/src/Magnum/Test/RenderbufferGLTest.cpp index 401e80fde..3badddc3a 100644 --- a/src/Magnum/Test/RenderbufferGLTest.cpp +++ b/src/Magnum/Test/RenderbufferGLTest.cpp @@ -123,7 +123,18 @@ void RenderbufferGLTest::label() { !Context::current()->isExtensionSupported()) CORRADE_SKIP("Required extension is not available"); + { + /** @todo Is this even legal optimization? */ + CORRADE_EXPECT_FAIL("The object must be used at least once before setting/querying label."); + CORRADE_VERIFY(false); + } Renderbuffer renderbuffer; + #ifndef MAGNUM_TARGET_GLES2 + renderbuffer.setStorage(RenderbufferFormat::RGBA8, {128, 128}); + #else + renderbuffer.setStorage(RenderbufferFormat::RGBA4, {128, 128}); + #endif + CORRADE_COMPARE(renderbuffer.label(), ""); renderbuffer.setLabel("MyRenderbuffer"); diff --git a/src/Magnum/Test/SampleQueryGLTest.cpp b/src/Magnum/Test/SampleQueryGLTest.cpp index 1d5acb6fd..e3f305f2b 100644 --- a/src/Magnum/Test/SampleQueryGLTest.cpp +++ b/src/Magnum/Test/SampleQueryGLTest.cpp @@ -68,23 +68,21 @@ namespace { #ifndef DOXYGEN_GENERATING_OUTPUT MyShader::MyShader() { Utility::Resource rs("QueryGLTest"); - #ifndef MAGNUM_TARGET_GLES - Shader vert(Version::GL210, Shader::Type::Vertex); - #else - Shader vert(Version::GLES200, Shader::Type::Vertex); - #endif - vert.addSource(rs.get("MyShader.vert")); - CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile()); - attachShader(vert); #ifndef MAGNUM_TARGET_GLES + Shader vert(Version::GL210, Shader::Type::Vertex); Shader frag(Version::GL210, Shader::Type::Fragment); #else + Shader vert(Version::GLES200, Shader::Type::Vertex); Shader frag(Version::GLES200, Shader::Type::Fragment); #endif + + vert.addSource(rs.get("MyShader.vert")); frag.addSource(rs.get("MyShader.frag")); - CORRADE_INTERNAL_ASSERT_OUTPUT(frag.compile()); - attachShader(frag); + + CORRADE_INTERNAL_ASSERT_OUTPUT(Shader::compile({vert, frag})); + + attachShaders({vert, frag}); CORRADE_INTERNAL_ASSERT_OUTPUT(link()); } diff --git a/src/Magnum/Test/TimeQueryGLTest.cpp b/src/Magnum/Test/TimeQueryGLTest.cpp index 60552c30b..233a98b8a 100644 --- a/src/Magnum/Test/TimeQueryGLTest.cpp +++ b/src/Magnum/Test/TimeQueryGLTest.cpp @@ -60,7 +60,7 @@ void TimeQueryGLTest::queryTime() { TimeQuery q2; q2.begin(TimeQuery::Target::TimeElapsed); - Renderer::setFeature(Renderer::Feature::Blending, true); + Renderer::enable(Renderer::Feature::Blending); Renderer::finish(); q2.end(); const auto result2 = q2.result(); @@ -80,7 +80,7 @@ void TimeQueryGLTest::queryTimestamp() { q1.timestamp(); q.begin(TimeQuery::Target::TimeElapsed); - Renderer::setFeature(Renderer::Feature::Blending, true); + Renderer::enable(Renderer::Feature::Blending); Renderer::finish(); q.end(); diff --git a/src/Magnum/Text/AbstractFont.h b/src/Magnum/Text/AbstractFont.h index 9d4bd8b74..0137d385c 100644 --- a/src/Magnum/Text/AbstractFont.h +++ b/src/Magnum/Text/AbstractFont.h @@ -71,6 +71,8 @@ checked by the implementation: @ref Feature::OpenData is supported. - All `do*()` implementations working on opened file are called only if there is any file opened. + +Plugin interface string is `"cz.mosra.magnum.Text.AbstractFont/0.2.3"`. */ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin { CORRADE_PLUGIN_INTERFACE("cz.mosra.magnum.Text.AbstractFont/0.2.3") diff --git a/src/Magnum/Text/AbstractFontConverter.h b/src/Magnum/Text/AbstractFontConverter.h index eb28ff7c6..fabbbe2cd 100644 --- a/src/Magnum/Text/AbstractFontConverter.h +++ b/src/Magnum/Text/AbstractFontConverter.h @@ -67,6 +67,8 @@ checked by the implementation: if @ref Feature::ConvertData is supported. - Function `doImport*FromData()` is called only if there is at least one data array passed. + +Plugin interface string is `"cz.mosra.magnum.Text.AbstractFontConverter/0.1.1"`. */ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPlugin { CORRADE_PLUGIN_INTERFACE("cz.mosra.magnum.Text.AbstractFontConverter/0.1.1") diff --git a/src/Magnum/Text/CMakeLists.txt b/src/Magnum/Text/CMakeLists.txt index 5513a8d5d..4127a15b6 100644 --- a/src/Magnum/Text/CMakeLists.txt +++ b/src/Magnum/Text/CMakeLists.txt @@ -45,7 +45,9 @@ if(MAGNUM_BUILD_DEPRECATED) TextRenderer.h) endif() -add_library(MagnumText ${SHARED_OR_STATIC} ${MagnumText_SRCS}) +add_library(MagnumText ${SHARED_OR_STATIC} + ${MagnumText_SRCS} + ${MagnumText_HEADERS}) set_target_properties(MagnumText PROPERTIES DEBUG_POSTFIX "-d") if(BUILD_STATIC_PIC) # TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property @@ -68,11 +70,11 @@ if(WITH_FONTCONVERTER) add_executable(magnum-fontconverter fontconverter.cpp) if(CORRADE_TARGET_APPLE) - target_link_libraries(magnum-fontconverter MagnumText Magnum MagnumWindowlessCglApplication) + target_link_libraries(magnum-fontconverter MagnumText MagnumWindowlessCglApplication) elseif(CORRADE_TARGET_UNIX AND NOT TARGET_GLES) - target_link_libraries(magnum-fontconverter MagnumText Magnum MagnumWindowlessGlxApplication ${X11_LIBRARIES}) + target_link_libraries(magnum-fontconverter MagnumText MagnumWindowlessGlxApplication) elseif(CORRADE_TARGET_WINDOWS) - target_link_libraries(magnum-fontconverter MagnumText Magnum MagnumWindowlessWglApplication) + target_link_libraries(magnum-fontconverter MagnumText MagnumWindowlessWglApplication) else() message(FATAL_ERROR "magnum-fontconverter is not available on this platform. Set WITH_FONTCONVERTER to OFF to suppress this warning.") endif() diff --git a/src/Magnum/Texture.h b/src/Magnum/Texture.h index b6423fc55..211fd5361 100644 --- a/src/Magnum/Texture.h +++ b/src/Magnum/Texture.h @@ -769,6 +769,10 @@ template class Texture: public AbstractTexture { AbstractTexture::setLabel(label); return *this; } + template Texture& setLabel(const char(&label)[size]) { + AbstractTexture::setLabel(label); + return *this; + } #endif }; diff --git a/src/Magnum/TextureArray.h b/src/Magnum/TextureArray.h index 5a8a725e0..1399a5929 100644 --- a/src/Magnum/TextureArray.h +++ b/src/Magnum/TextureArray.h @@ -389,6 +389,10 @@ template class TextureArray: public AbstractTexture { AbstractTexture::setLabel(label); return *this; } + template TextureArray& setLabel(const char(&label)[size]) { + AbstractTexture::setLabel(label); + return *this; + } #endif }; diff --git a/src/Magnum/TextureTools/CMakeLists.txt b/src/Magnum/TextureTools/CMakeLists.txt index d5ad0a28d..8621c2a63 100644 --- a/src/Magnum/TextureTools/CMakeLists.txt +++ b/src/Magnum/TextureTools/CMakeLists.txt @@ -40,7 +40,9 @@ if(BUILD_STATIC) set(MagnumTextureTools_HEADERS ${MagnumTextureTools_HEADERS} magnumTextureToolsResourceImport.hpp) endif() -add_library(MagnumTextureTools ${SHARED_OR_STATIC} ${MagnumTextureTools_SRCS}) +add_library(MagnumTextureTools ${SHARED_OR_STATIC} + ${MagnumTextureTools_SRCS} + ${MagnumTextureTools_HEADERS}) set_target_properties(MagnumTextureTools PROPERTIES DEBUG_POSTFIX "-d") if(BUILD_STATIC_PIC) # TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property @@ -57,11 +59,11 @@ if(WITH_DISTANCEFIELDCONVERTER) add_executable(magnum-distancefieldconverter distancefieldconverter.cpp) if(CORRADE_TARGET_APPLE) - target_link_libraries(magnum-distancefieldconverter MagnumTextureTools MagnumWindowlessCglApplication Magnum) + target_link_libraries(magnum-distancefieldconverter MagnumTextureTools MagnumWindowlessCglApplication) elseif(CORRADE_TARGET_UNIX AND NOT TARGET_GLES) - target_link_libraries(magnum-distancefieldconverter MagnumTextureTools Magnum MagnumWindowlessGlxApplication ${X11_LIBRARIES}) + target_link_libraries(magnum-distancefieldconverter MagnumTextureTools Magnum MagnumWindowlessGlxApplication) elseif(CORRADE_TARGET_WINDOWS) - target_link_libraries(magnum-distancefieldconverter MagnumTextureTools MagnumWindowlessWglApplication Magnum) + target_link_libraries(magnum-distancefieldconverter MagnumTextureTools MagnumWindowlessWglApplication) else() message(FATAL_ERROR "magnum-distancefieldconverter is not available on this platform. Set WITH_DISTANCEFIELDCONVERTER to OFF to suppress this warning.") endif() diff --git a/src/Magnum/TextureTools/DistanceField.cpp b/src/Magnum/TextureTools/DistanceField.cpp index 1145732bd..42aadc390 100644 --- a/src/Magnum/TextureTools/DistanceField.cpp +++ b/src/Magnum/TextureTools/DistanceField.cpp @@ -36,6 +36,7 @@ #include "Magnum/Mesh.h" #include "Magnum/Shader.h" #include "Magnum/Texture.h" +#include "Magnum/Shaders/Implementation/CreateCompatibilityShader.h" namespace Magnum { namespace TextureTools { @@ -84,18 +85,16 @@ DistanceFieldShader::DistanceFieldShader(): radiusUniform(0), scalingUniform(1) const Version v = Context::current()->supportedVersion({Version::GLES300, Version::GLES200}); #endif - Shader vert(v, Shader::Type::Vertex); - vert.addSource(rs.get("compatibility.glsl")) - .addSource(rs.get("FullScreenTriangle.glsl")) + Shader vert = Shaders::Implementation::createCompatibilityShader(v, Shader::Type::Vertex); + Shader frag = Shaders::Implementation::createCompatibilityShader(v, Shader::Type::Fragment); + + vert.addSource(rs.get("FullScreenTriangle.glsl")) .addSource(rs.get("DistanceFieldShader.vert")); - CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile()); - attachShader(vert); - - Shader frag(v, Shader::Type::Fragment); - frag.addSource(rs.get("compatibility.glsl")) - .addSource(rs.get("DistanceFieldShader.frag")); - CORRADE_INTERNAL_ASSERT_OUTPUT(frag.compile()); - attachShader(frag); + frag.addSource(rs.get("DistanceFieldShader.frag")); + + CORRADE_INTERNAL_ASSERT_OUTPUT(Shader::compile({vert, frag})); + + attachShaders({vert, frag}); /* Older GLSL doesn't have gl_VertexID, vertices must be supplied explicitly */ #ifndef MAGNUM_TARGET_GLES diff --git a/src/Magnum/TextureTools/DistanceFieldShader.frag b/src/Magnum/TextureTools/DistanceFieldShader.frag index b82c6d94b..1224b7f72 100644 --- a/src/Magnum/TextureTools/DistanceFieldShader.frag +++ b/src/Magnum/TextureTools/DistanceFieldShader.frag @@ -26,10 +26,13 @@ #ifndef NEW_GLSL #define in varying #define value gl_FragColor.x -#define const #define texture texture2D #endif +#ifndef RUNTIME_CONST +#define const +#endif + #if (defined(GL_ES) && __VERSION__ >= 300) || (!defined(GL_ES) && __VERSION__ >= 150) #define TEXELFETCH_USABLE #endif diff --git a/src/Magnum/Trade/AbstractImageConverter.h b/src/Magnum/Trade/AbstractImageConverter.h index 58312001e..cb855ad0d 100644 --- a/src/Magnum/Trade/AbstractImageConverter.h +++ b/src/Magnum/Trade/AbstractImageConverter.h @@ -55,6 +55,8 @@ checked by the implementation: - Functions @ref doExportToImage() or @ref doExportToData() are called only if @ref Feature::ConvertImage or @ref Feature::ConvertData is supported. + +Plugin interface string is `"cz.mosra.magnum.Trade.AbstractImageConverter/0.2.1"`. */ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin { CORRADE_PLUGIN_INTERFACE("cz.mosra.magnum.Trade.AbstractImageConverter/0.2.1") diff --git a/src/Magnum/Trade/AbstractImporter.cpp b/src/Magnum/Trade/AbstractImporter.cpp index de293b54a..44550a9cd 100644 --- a/src/Magnum/Trade/AbstractImporter.cpp +++ b/src/Magnum/Trade/AbstractImporter.cpp @@ -26,6 +26,7 @@ #include "AbstractImporter.h" #include +#include #include #include @@ -44,7 +45,9 @@ namespace Magnum { namespace Trade { AbstractImporter::AbstractImporter() = default; -AbstractImporter::AbstractImporter(PluginManager::AbstractManager& manager, std::string plugin): AbstractPlugin(manager, std::move(plugin)) {} +AbstractImporter::AbstractImporter(PluginManager::Manager& manager): AbstractManagingPlugin{manager} {} + +AbstractImporter::AbstractImporter(PluginManager::AbstractManager& manager, std::string plugin): AbstractManagingPlugin(manager, std::move(plugin)) {} bool AbstractImporter::openData(Containers::ArrayReference data) { CORRADE_ASSERT(features() & Feature::OpenData, diff --git a/src/Magnum/Trade/AbstractImporter.h b/src/Magnum/Trade/AbstractImporter.h index a32bb41ad..348dde22f 100644 --- a/src/Magnum/Trade/AbstractImporter.h +++ b/src/Magnum/Trade/AbstractImporter.h @@ -31,7 +31,7 @@ #include #include -#include +#include #include "Magnum/Magnum.h" #include "Magnum/visibility.h" @@ -72,9 +72,11 @@ checked by the implementation: - All `do*()` implementations taking data ID as parameter are called only if the ID is from valid range. +Plugin interface string is `"cz.mosra.magnum.Trade.AbstractImporter/0.3"`. + @todo How to handle casting from std::unique_ptr<> in more convenient way? */ -class MAGNUM_EXPORT AbstractImporter: public PluginManager::AbstractPlugin { +class MAGNUM_EXPORT AbstractImporter: public PluginManager::AbstractManagingPlugin { CORRADE_PLUGIN_INTERFACE("cz.mosra.magnum.Trade.AbstractImporter/0.3") public: @@ -94,6 +96,9 @@ class MAGNUM_EXPORT AbstractImporter: public PluginManager::AbstractPlugin { /** @brief Default constructor */ explicit AbstractImporter(); + /** @brief Constructor with access to plugin manager */ + explicit AbstractImporter(PluginManager::Manager& manager); + /** @brief Plugin manager constructor */ explicit AbstractImporter(PluginManager::AbstractManager& manager, std::string plugin); diff --git a/src/Magnum/Trade/CMakeLists.txt b/src/Magnum/Trade/CMakeLists.txt index 6dcbc34f2..229492815 100644 --- a/src/Magnum/Trade/CMakeLists.txt +++ b/src/Magnum/Trade/CMakeLists.txt @@ -41,6 +41,9 @@ set(MagnumTrade_HEADERS TextureData.h Trade.h) +# Force IDEs to display all header files in project view +add_custom_target(MagnumTrade SOURCES ${MagnumTrade_HEADERS}) + install(FILES ${MagnumTrade_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Trade) if(BUILD_TESTS) diff --git a/src/MagnumExternal/OpenGL/GL/CMakeLists.txt b/src/MagnumExternal/OpenGL/GL/CMakeLists.txt index 2e5a98c50..450b9cca6 100644 --- a/src/MagnumExternal/OpenGL/GL/CMakeLists.txt +++ b/src/MagnumExternal/OpenGL/GL/CMakeLists.txt @@ -25,7 +25,7 @@ add_library(MagnumGLLoadGenObjects OBJECT gl_magnum.c) -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang") set_target_properties(MagnumGLLoadGenObjects PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} -fvisibility=hidden -DGLLoadGen_EXPORTS") else() set_target_properties(MagnumGLLoadGenObjects PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} -DGLLoadGen_EXPORTS") diff --git a/src/MagnumPlugins/TgaImporter/TgaImporter.conf b/src/MagnumPlugins/TgaImporter/TgaImporter.conf index 02be1f4ce..e69de29bb 100644 --- a/src/MagnumPlugins/TgaImporter/TgaImporter.conf +++ b/src/MagnumPlugins/TgaImporter/TgaImporter.conf @@ -1,4 +0,0 @@ -author=Vladimír Vondruš - -[metadata] -name=TGA image importer diff --git a/src/MagnumPlugins/TgaImporter/TgaImporter.cpp b/src/MagnumPlugins/TgaImporter/TgaImporter.cpp index fc90a4d0f..a0bc64462 100644 --- a/src/MagnumPlugins/TgaImporter/TgaImporter.cpp +++ b/src/MagnumPlugins/TgaImporter/TgaImporter.cpp @@ -91,9 +91,9 @@ UnsignedInt TgaImporter::doImage2DCount() const { return 1; } std::optional TgaImporter::doImage2D(UnsignedInt) { /* Check if the file is long enough */ in->seekg(0, std::istream::end); - std::streampos filesize = in->tellg(); + std::streamoff filesize = in->tellg(); in->seekg(0, std::istream::beg); - if(filesize < std::streampos(sizeof(TgaHeader))) { + if(filesize < std::streamoff(sizeof(TgaHeader))) { Error() << "Trade::TgaImporter::image2D(): the file is too short:" << filesize << "bytes"; return std::nullopt; }