From 955586b178dfcf11dfffe4ab562a0838ffa8da2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Jul 2013 17:34:47 +0200 Subject: [PATCH 01/11] TextureTools: use `layout(binding = ...)` only if GLSL supports it. --- src/TextureTools/DistanceFieldShader.frag | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/TextureTools/DistanceFieldShader.frag b/src/TextureTools/DistanceFieldShader.frag index c19273b79..8d7e0f427 100644 --- a/src/TextureTools/DistanceFieldShader.frag +++ b/src/TextureTools/DistanceFieldShader.frag @@ -36,10 +36,14 @@ #ifdef EXPLICIT_UNIFORM_LOCATION layout(location = 0) uniform int radius; layout(location = 1) uniform vec2 scaling; -layout(binding = 8) uniform sampler2D textureData; #else uniform lowp int radius; uniform mediump vec2 scaling; +#endif + +#ifdef EXPLICIT_TEXTURE_LAYER +layout(binding = 8) uniform sampler2D textureData; +#else uniform lowp sampler2D textureData; #endif From db8e3dd556b8258056bb69899673a5c0341dcb2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Jul 2013 17:35:17 +0200 Subject: [PATCH 02/11] Text: call proper Buffer unmapping function. The buffer was mapped with mapSub(), we need to unmap it with unmapSub(). --- src/Text/TextRenderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Text/TextRenderer.cpp b/src/Text/TextRenderer.cpp index 4f04aaccd..137da6ba3 100644 --- a/src/Text/TextRenderer.cpp +++ b/src/Text/TextRenderer.cpp @@ -218,7 +218,7 @@ void* AbstractTextRenderer::bufferMapImplementationSub(Buffer& buffer, GLsizeipt } void AbstractTextRenderer::bufferUnmapImplementationSub(Buffer& buffer) { - buffer.unmap(); + buffer.unmapSub(); } #endif From 6f0471a7e0a9c83823e25eddc074f89c41c5efb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Jul 2013 17:38:36 +0200 Subject: [PATCH 03/11] Text: add one more GlyphCache constructor combination. --- src/Text/GlyphCache.cpp | 14 ++++++++++++-- src/Text/GlyphCache.h | 10 +++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Text/GlyphCache.cpp b/src/Text/GlyphCache.cpp index a11338b0a..3e054803c 100644 --- a/src/Text/GlyphCache.cpp +++ b/src/Text/GlyphCache.cpp @@ -31,6 +31,8 @@ namespace Magnum { namespace Text { +/** @todo Do this using delegating constructors when support for GCC 4.6 is dropped */ + GlyphCache::GlyphCache(const TextureFormat internalFormat, const Vector2i& originalSize, const Vector2i& size, const Vector2i& padding): _size(originalSize), _padding(padding) { initialize(internalFormat, size); } @@ -39,7 +41,17 @@ GlyphCache::GlyphCache(const TextureFormat internalFormat, const Vector2i& size, initialize(internalFormat, size); } +GlyphCache::GlyphCache(const Vector2i& originalSize, const Vector2i& size, const Vector2i& padding): _size(originalSize), _padding(padding) { + initialize(size); +} + GlyphCache::GlyphCache(const Vector2i& size, const Vector2i& padding): _size(size), _padding(padding) { + initialize(size); +} + +GlyphCache::~GlyphCache() = default; + +void GlyphCache::initialize(const Vector2i& size) { #ifndef MAGNUM_TARGET_GLES MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg); #endif @@ -55,8 +67,6 @@ GlyphCache::GlyphCache(const Vector2i& size, const Vector2i& padding): _size(siz initialize(internalFormat, size); } -GlyphCache::~GlyphCache() = default; - void GlyphCache::initialize(const TextureFormat internalFormat, const Vector2i& size) { /* Initialize texture */ _texture.setWrapping(Sampler::Wrapping::ClampToEdge) diff --git a/src/Text/GlyphCache.h b/src/Text/GlyphCache.h index d790abc51..7446e5952 100644 --- a/src/Text/GlyphCache.h +++ b/src/Text/GlyphCache.h @@ -70,7 +70,7 @@ class MAGNUM_TEXT_EXPORT GlyphCache { * although the actual glyph cache texture has @p size. Glyph * @p padding can be used to account for e.g. glyph shadows. */ - explicit GlyphCache(TextureFormat internalFormat, const Vector2i& originalSize, const Vector2i& size, const Vector2i& padding); + explicit GlyphCache(TextureFormat internalFormat, const Vector2i& originalSize, const Vector2i& size, const Vector2i& padding = Vector2i()); /** * @brief Constructor @@ -87,6 +87,13 @@ class MAGNUM_TEXT_EXPORT GlyphCache { * ES2 uses @es_extension{EXT,texture_rg}, if available, or * @ref TextureFormat "TextureFormat::Luminance" as fallback. */ + explicit GlyphCache(const Vector2i& originalSize, const Vector2i& size, const Vector2i& padding = Vector2i()); + + /** + * @brief Constructor + * + * Same as calling the above with @p originalSize and @p size the same. + */ explicit GlyphCache(const Vector2i& size, const Vector2i& padding = Vector2i()); virtual ~GlyphCache(); @@ -178,6 +185,7 @@ class MAGNUM_TEXT_EXPORT GlyphCache { virtual void setImage(const Vector2i& offset, const ImageReference2D& image); private: + void MAGNUM_LOCAL initialize(const Vector2i& size); void MAGNUM_LOCAL initialize(TextureFormat internalFormat, const Vector2i& size); Vector2i _size, _padding; From ec467e40996046b6f9abd1f90f3fa31cdafc4acf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Jul 2013 17:42:22 +0200 Subject: [PATCH 04/11] Shaders: `range` is reserved keyword in GLSL. Neither desktop GL nor GLES on my NVidia complained. Just Chrome didn't like it. --- src/Shaders/DistanceFieldVector.frag | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Shaders/DistanceFieldVector.frag b/src/Shaders/DistanceFieldVector.frag index 07d9bbe2a..bb4811468 100644 --- a/src/Shaders/DistanceFieldVector.frag +++ b/src/Shaders/DistanceFieldVector.frag @@ -68,7 +68,7 @@ void main() { /* Outline */ if(outlineRange.x > outlineRange.y) { lowp float mid = (outlineRange.x + outlineRange.y)/2.0; - lowp float half = (outlineRange.x - outlineRange.y)/2.0; - fragmentColor += smoothstep(half+smoothness, half-smoothness, distance(mid, intensity))*outlineColor; + lowp float halfRange = (outlineRange.x - outlineRange.y)/2.0; + fragmentColor += smoothstep(halfRange+smoothness, halfRange-smoothness, distance(mid, intensity))*outlineColor; } } From f0b7489554fede81ba1d030d37e336631d8d5b66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Jul 2013 17:44:05 +0200 Subject: [PATCH 05/11] Text: fix and improve format checking of passed image in DFGlyphCache. --- src/Text/DistanceFieldGlyphCache.cpp | 19 +++++++++++++++---- src/Text/GlyphCache.cpp | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Text/DistanceFieldGlyphCache.cpp b/src/Text/DistanceFieldGlyphCache.cpp index d0643d212..8de12233e 100644 --- a/src/Text/DistanceFieldGlyphCache.cpp +++ b/src/Text/DistanceFieldGlyphCache.cpp @@ -38,6 +38,7 @@ DistanceFieldGlyphCache::DistanceFieldGlyphCache(const Vector2i& originalSize, c #if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES3) GlyphCache(TextureFormat::R8, originalSize, size, Vector2i(radius)), #else + /* Luminance is not renderable in most cases */ GlyphCache(Context::current()->isExtensionSupported() ? TextureFormat::Red : TextureFormat::RGB, originalSize, size, Vector2i(radius)), #endif @@ -48,16 +49,13 @@ DistanceFieldGlyphCache::DistanceFieldGlyphCache(const Vector2i& originalSize, c #endif #ifdef MAGNUM_TARGET_GLES2 + /* Luminance is not renderable in most cases */ if(!Context::current()->isExtensionSupported()) Warning() << "Text::DistanceFieldGlyphCache:" << Extensions::GL::EXT::texture_rg::string() << "not supported, using inefficient RGB format for glyph cache texture"; #endif } void DistanceFieldGlyphCache::setImage(const Vector2i& offset, const ImageReference2D& image) { - #ifndef MAGNUM_TARGET_GLES - MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg); - #endif - #if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES3) const TextureFormat internalFormat = TextureFormat::R8; CORRADE_ASSERT(image.format() == ImageFormat::Red, @@ -86,6 +84,19 @@ void DistanceFieldGlyphCache::setImage(const Vector2i& offset, const ImageRefere } void DistanceFieldGlyphCache::setDistanceFieldImage(const Vector2i& offset, const ImageReference2D& image) { + #if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES3) + CORRADE_ASSERT(image.format() == ImageFormat::Red, + "Text::DistanceFieldGlyphCache::setDistanceFieldImage(): expected" << ImageFormat::Red << "but got" << image.format(), ); + #else + if(Context::current()->isExtensionSupported()) + CORRADE_ASSERT(image.format() == ImageFormat::Red, + "Text::DistanceFieldGlyphCache::setDistanceFieldImage(): expected" << ImageFormat::Red << "but got" << image.format(), ); + + /* Luminance is not renderable in most cases */ + else CORRADE_ASSERT(image.format() == ImageFormat::RGB, + "Text::DistanceFieldGlyphCache::setDistanceFieldImage(): expected" << ImageFormat::RGB << "but got" << image.format(), ); + #endif + texture()->setSubImage(0, offset, image); } diff --git a/src/Text/GlyphCache.cpp b/src/Text/GlyphCache.cpp index 3e054803c..78355ad7f 100644 --- a/src/Text/GlyphCache.cpp +++ b/src/Text/GlyphCache.cpp @@ -98,6 +98,7 @@ void GlyphCache::insert(const UnsignedInt glyph, Vector2i position, Rectanglei r } void GlyphCache::setImage(const Vector2i& offset, const ImageReference2D& image) { + /** @todo some internalformat/format checking also here (if querying internal format is not slow) */ _texture.setSubImage(0, offset, image); } From a403a7f28897a3ca40268a26f82157cd39f9cf57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Jul 2013 18:20:25 +0200 Subject: [PATCH 06/11] Shaders: make GLSL code for fullscreen triangle reusable. Now you can just add the file and call `fullScreenTriangle()`. --- src/Shaders/FullScreenTriangle.glsl | 36 +++++++++++++++++++++++ src/Shaders/resources.conf | 3 ++ src/TextureTools/DistanceField.cpp | 1 + src/TextureTools/DistanceFieldShader.vert | 11 +------ src/TextureTools/resources.conf | 4 +++ 5 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 src/Shaders/FullScreenTriangle.glsl diff --git a/src/Shaders/FullScreenTriangle.glsl b/src/Shaders/FullScreenTriangle.glsl new file mode 100644 index 000000000..77eb63486 --- /dev/null +++ b/src/Shaders/FullScreenTriangle.glsl @@ -0,0 +1,36 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 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. +*/ + +#ifndef NEW_GLSL +attribute lowp vec4 position; +#endif + +void fullScreenTriangle() { + #ifdef NEW_GLSL + gl_Position = vec4((gl_VertexID == 2) ? 3.0 : -1.0, + (gl_VertexID == 1) ? -3.0 : 1.0, 0.0, 1.0); + #else + gl_Position = position; + #endif +} diff --git a/src/Shaders/resources.conf b/src/Shaders/resources.conf index 3f23a2663..8edde95b8 100644 --- a/src/Shaders/resources.conf +++ b/src/Shaders/resources.conf @@ -15,6 +15,9 @@ filename=Flat3D.vert [file] filename=Flat.frag +[file] +filename=FullScreenTriangle.glsl + [file] filename=MeshVisualizer.vert diff --git a/src/TextureTools/DistanceField.cpp b/src/TextureTools/DistanceField.cpp index 521c86beb..adb552cc9 100644 --- a/src/TextureTools/DistanceField.cpp +++ b/src/TextureTools/DistanceField.cpp @@ -79,6 +79,7 @@ DistanceFieldShader::DistanceFieldShader(): radiusUniform(0), scalingUniform(1) Shader vert(v, Shader::Type::Vertex); vert.addSource(rs.get("compatibility.glsl")) + .addSource(rs.get("FullScreenTriangle.glsl")) .addSource(rs.get("DistanceFieldShader.vert")); CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile()); attachShader(vert); diff --git a/src/TextureTools/DistanceFieldShader.vert b/src/TextureTools/DistanceFieldShader.vert index c7970fe47..44d8fbe7c 100644 --- a/src/TextureTools/DistanceFieldShader.vert +++ b/src/TextureTools/DistanceFieldShader.vert @@ -22,15 +22,6 @@ DEALINGS IN THE SOFTWARE. */ -#ifndef NEW_GLSL -attribute lowp vec4 position; -#endif - void main() { - #ifdef NEW_GLSL - gl_Position = vec4((gl_VertexID == 2) ? 3.0 : -1.0, - (gl_VertexID == 1) ? -3.0 : 1.0, 0.0, 1.0); - #else - gl_Position = position; - #endif + fullScreenTriangle(); } diff --git a/src/TextureTools/resources.conf b/src/TextureTools/resources.conf index 71a74be59..51ca5065e 100644 --- a/src/TextureTools/resources.conf +++ b/src/TextureTools/resources.conf @@ -1,5 +1,9 @@ group=MagnumTextureTools +[file] +filename=../Shaders/FullScreenTriangle.glsl +alias=FullScreenTriangle.glsl + [file] filename=DistanceFieldShader.vert From 4c1f226544aa8f9f638c80db4d5efc85cefaacac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Jul 2013 22:16:22 +0200 Subject: [PATCH 07/11] Warn about improper Buffer target hint in NaCl. Slightly eases up the porting. --- doc/best-practices.dox | 5 ++++- src/Mesh.cpp | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/doc/best-practices.dox b/doc/best-practices.dox index 7517541ca..6dba060be 100644 --- a/doc/best-practices.dox +++ b/doc/best-practices.dox @@ -57,11 +57,14 @@ information. As noted in the above link, buffers in NaCl implementation need to be bound only to one unique target, i.e., Buffer bound to @ref Buffer::Target "Target::Array" -cannot be later rebound to @ref Buffer::Target "Target::Element". However, +cannot be later rebound to @ref Buffer::Target "Target::ElementArray". However, %Magnum by default uses any sufficient target when binding the buffer internally (e.g. for setting data or copying). To avoid this, set target hint to desired target, either in constructor or using Buffer::setTargetHint(). +To ease up the development, @ref Mesh checks proper target hint when adding +vertex and index buffers. + @subsection best-practices-powervr PowerVR hardware - [PowerVR Performance Recommendations](http://www.imgtec.com/powervr/insider/docs/PowerVR.Performance%20Recommendations.1.0.28.External.pdf) [PDF] diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 995552711..368ec21a3 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -118,6 +118,11 @@ Mesh& Mesh::operator=(Mesh&& other) { } Mesh* Mesh::setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type, UnsignedInt start, UnsignedInt end) { + #ifdef CORRADE_TARGET_NACL + CORRADE_ASSERT(buffer->targetHint() == Buffer::Target::ElementArray, + "Mesh::setIndexBuffer(): the buffer has unexpected target hint, expected" << Buffer::Target::ElementArray << "but got" << buffer->targetHint(), this); + #endif + indexOffset = offset; indexType = type; #ifndef MAGNUM_TARGET_GLES2 @@ -235,10 +240,20 @@ void Mesh::destroyImplementationVAO() { } void Mesh::attributePointerImplementationDefault(const Attribute& attribute) { + #ifdef CORRADE_TARGET_NACL + CORRADE_ASSERT(attribute.buffer->targetHint() == Buffer::Target::Array, + "Mesh::addVertexBuffer(): the buffer has unexpected target hint, expected" << Buffer::Target::Array << "but got" << attribute.buffer->targetHint(), ); + #endif + attributes.push_back(attribute); } void Mesh::attributePointerImplementationVAO(const Attribute& attribute) { + #ifdef CORRADE_TARGET_NACL + CORRADE_ASSERT(attribute.buffer->targetHint() == Buffer::Target::Array, + "Mesh::addVertexBuffer(): the buffer has unexpected target hint, expected" << Buffer::Target::Array << "but got" << attribute.buffer->targetHint(), ); + #endif + bindVAO(vao); vertexAttribPointer(attribute); } From e8e94d86f5ff06d504021d23095adc3942222764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Jul 2013 22:19:48 +0200 Subject: [PATCH 08/11] Platform: minor CMakeLists.txt cleanup. --- src/Platform/CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Platform/CMakeLists.txt b/src/Platform/CMakeLists.txt index 634197a4a..43f072490 100644 --- a/src/Platform/CMakeLists.txt +++ b/src/Platform/CMakeLists.txt @@ -162,10 +162,11 @@ if(WITH_MAGNUMINFO) add_executable(magnum-info magnum-info.cpp) if(UNIX AND NOT CORRADE_TARGET_NACL) - target_link_libraries(magnum-info Magnum MagnumWindowlessGlxApplication ${X11_LIBRARIES}) + target_link_libraries(magnum-info MagnumWindowlessGlxApplication ${X11_LIBRARIES}) elseif(CORRADE_TARGET_NACL) - target_link_libraries(magnum-info Magnum MagnumWindowlessNaClApplication ppapi_cpp ppapi) + target_link_libraries(magnum-info MagnumWindowlessNaClApplication ppapi_cpp ppapi) endif() + target_link_libraries(magnum-info Magnum) install(TARGETS magnum-info DESTINATION ${MAGNUM_BINARY_INSTALL_DIR}) if(CORRADE_TARGET_NACL) From 0a51633b0a75237d37c0a13076d71d88ca264e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Jul 2013 22:22:48 +0200 Subject: [PATCH 09/11] Added TODO. --- src/AbstractShaderProgram.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 214f0df94..bf0608108 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -282,6 +282,9 @@ setUniform() documentation for more information. To achieve least state changes, set all uniforms in one run -- method chaining comes in handy. + +@todo Compiling and linking more than one shader in parallel, then checking + status, should be faster -- https://twitter.com/g_truc/status/352778836657700866 */ class MAGNUM_EXPORT AbstractShaderProgram { friend class Context; From 6a52e64d716b2e47c0b52a01efebf5c406967685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Jul 2013 22:58:09 +0200 Subject: [PATCH 10/11] Doxygen fixes. --- src/SceneGraph/AbstractFeature.h | 4 ++-- src/SceneGraph/MatrixTransformation2D.h | 2 +- src/SceneGraph/Object.h | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/SceneGraph/AbstractFeature.h b/src/SceneGraph/AbstractFeature.h index 3cd00f42b..343b9b6bc 100644 --- a/src/SceneGraph/AbstractFeature.h +++ b/src/SceneGraph/AbstractFeature.h @@ -143,8 +143,8 @@ class TransformingFeature: public SceneGraph::AbstractFeature3D { If we take for example @ref Object "Object", it is derived from @ref AbstractBasicObject "AbstractObject3D" and @ref BasicMatrixTransformation3D "MatrixTransformation3D", which is derived -from @ref BasicAbstractTranslationRotationScaling3D "AbstractTranslationRotationScaling3D", -which is derived from @ref BasicAbstractTranslationRotation3D "AbstractTranslationRotation3D", +from @ref AbstractBasicTranslationRotationScaling3D "AbstractTranslationRotationScaling3D", +which is derived from @ref AbstractBasicTranslationRotation3D "AbstractTranslationRotation3D", which is automatically extracted from the pointer in our constructor. @section AbstractFeature-explicit-specializations Explicit template specializations diff --git a/src/SceneGraph/MatrixTransformation2D.h b/src/SceneGraph/MatrixTransformation2D.h index f2861c72c..d1f4a144e 100644 --- a/src/SceneGraph/MatrixTransformation2D.h +++ b/src/SceneGraph/MatrixTransformation2D.h @@ -38,7 +38,7 @@ namespace Magnum { namespace SceneGraph { @brief Two-dimensional transformation implemented using matrices Uses Math::Matrix3 as underlying type. -@see @ref MatrixTransformation2D, @ref scenegraph, @ref RigidBasicMatrixTransformation2D, @ref BasicMatrixTransformation3D +@see @ref MatrixTransformation2D, @ref scenegraph, @ref BasicRigidMatrixTransformation2D, @ref BasicMatrixTransformation3D */ template class BasicMatrixTransformation2D: public AbstractBasicTranslationRotationScaling2D { public: diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index 359547d68..28de664cd 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -129,7 +129,7 @@ template class MAGNUM_SCENEGRAPH_EXPORT Object: public Abs * See @ref scenegraph-hierarchy for more information. */ - /** @copydoc AbstractObject::scene() */ + /** @copydoc AbstractBasicObject::scene() */ Scene* scene(); const Scene* scene() const; /**< @overload */ @@ -271,13 +271,13 @@ template class MAGNUM_SCENEGRAPH_EXPORT Object: public Abs /* `objects` passed by copy intentionally (to avoid copy internally) */ static void setClean(std::vector*> objects); - /** @copydoc AbstractObject::isDirty() */ + /** @copydoc AbstractBasicObject::isDirty() */ bool isDirty() const { return !!(flags & Flag::Dirty); } - /** @copydoc AbstractObject::setDirty() */ + /** @copydoc AbstractBasicObject::setDirty() */ void setDirty(); - /** @copydoc AbstractObject::setClean() */ + /** @copydoc AbstractBasicObject::setClean() */ void setClean(); /*@}*/ From 106921ac990b8466c01412b7214fdb5cb78294d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Jul 2013 22:20:27 +0200 Subject: [PATCH 11/11] Platform: improve magnum-info in NaCl, add reusable JS and CSS files. The page now displays download progress, last error and also hints to the user that JS console might contain something useful. NaClApplication and WindowlessNaClApplication documentation has been updated with brief "bootstrap guide". --- src/Platform/CMakeLists.txt | 5 ++ src/Platform/NaClApplication.css | 51 +++++++++++++++++++ src/Platform/NaClApplication.h | 49 +++++++++++++++++-- src/Platform/NaClApplication.js | 43 ++++++++++++++++ src/Platform/WindowlessNaClApplication.h | 9 ++-- src/Platform/magnum-info-nacl.html | 62 ++---------------------- 6 files changed, 154 insertions(+), 65 deletions(-) create mode 100644 src/Platform/NaClApplication.css create mode 100644 src/Platform/NaClApplication.js diff --git a/src/Platform/CMakeLists.txt b/src/Platform/CMakeLists.txt index 43f072490..5ff61f660 100644 --- a/src/Platform/CMakeLists.txt +++ b/src/Platform/CMakeLists.txt @@ -84,6 +84,11 @@ if(WITH_WINDOWLESSNACLAPPLICATION) install(TARGETS MagnumWindowlessNaClApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) endif() +# JavaScript stuff for NaCl +if(WITH_NACLAPPLICATION OR WITH_WINDOWLESSNACLAPPLICATION) + install(FILES NaClApplication.js DESTINATION ${MAGNUM_DATA_INSTALL_DIR}) +endif() + # GLX application if(WITH_GLXAPPLICATION) set(NEED_ABSTRACTXAPPLICATION 1) diff --git a/src/Platform/NaClApplication.css b/src/Platform/NaClApplication.css new file mode 100644 index 000000000..a2abf2c85 --- /dev/null +++ b/src/Platform/NaClApplication.css @@ -0,0 +1,51 @@ +body { + margin: 0px; + padding: 0px; + font-family: sans-serif; + background-color: #111111; + color: #aaaaaa; +} + +h1 { + text-align: center; + font-size: 20px; +} + +#listener { + border-style: solid; + border-color: #333333; + border-width: 1px; + padding: 1px; + width: 640px; + height: 480px; + margin-left: auto; + margin-right: auto; + margin-top: 20px; + margin-bottom: 20px; + position: relative; +} + +#module { + width: 640px; + height: 480px; + z-index: 10; +} + +#status { + position: absolute; + width: 640px; + text-align: center; + top: 200px; + font-size: 30px; + font-weight: bold; + z-index: 9; +} + +#statusDescription { + position: absolute; + width: 640px; + text-align: center; + top: 250px; + font-size: 15px; + z-index: 9; +} diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index e1a04d654..75b65d68c 100644 --- a/src/Platform/NaClApplication.h +++ b/src/Platform/NaClApplication.h @@ -73,12 +73,53 @@ to simplify porting. @section NaClApplication-html HTML markup and NMF file -You need to provide HTML markup containing `<embed>` pointing to `*.nmf` -file describing the application. +You need to provide HTML markup for your application. Template one is below, +you can modify it to your liking. The markup references two files, +`NaClApplication.js` and `NaClApplication.css`, both are in `Platform/` +directory in the source tree and are also installed into `share/magnum/` inside +your NaCl toolchain. +@code + + + +Magnum NaCl Application + + + +

Magnum NaCl Application

+
+ + +
Initialization...
+
+
+ + +@endcode + +You can modify all the files to your liking, but the HTML file must contain at +least the `<embed>` enclosed in listener `<div>`. The JavaScript +file contains event listeners which print loading status on the page. The +status displayed in the remaining two `<div>`s, if they are available. +The CSS file contains rudimentary style to avoid eye bleeding. + +The `<embed>` file references NMF file which you need to provide too. If +you target @ref CORRADE_TARGET_NACL_NEWLIB_ "newlib", the file is pretty +simple, for example: +@code +{ + "program": { + "x86-32": {"url": "application-x86-32.nexe"}, + "x86-64": {"url": "application-x86-64.nexe"} + } +} +@endcode -@todoc Document this better, add "bootstrap" examples +If you target @ref CORRADE_TARGET_NACL_GLIBC_ "glibc", you need to specify also +all additional dependencies. See [Native Client](https://developers.google.com/native-client/) +documentation for more information. -@subsection NaClApplication-html-console Redirecting output to Chrome's JavaScript console +@section NaClApplication-console Redirecting output to Chrome's JavaScript console The application redirects @ref Corrade::Utility::Debug "Debug", @ref Corrade::Utility::Warning "Warning" and @ref Corrade::Utility::Error "Error" diff --git a/src/Platform/NaClApplication.js b/src/Platform/NaClApplication.js new file mode 100644 index 000000000..50bbe023a --- /dev/null +++ b/src/Platform/NaClApplication.js @@ -0,0 +1,43 @@ +function setStatus(message) { + var status = document.getElementById('status'); + if(status) status.innerHTML = message; +} + +function setStatusDescription(message) { + var statusDescription = document.getElementById('statusDescription'); + if(statusDescription) statusDescription.innerHTML = message; +} + +var listener = document.getElementById('listener'); + +listener.addEventListener('loadstart', function() { + setStatus('Loading...'); +}, true); + +listener.addEventListener('progress', function(event) { + setStatus('Downloading...'); + + /* Show progress */ + if(event.lengthComputable && event.total > 0) + setStatusDescription(Math.round(event.loaded*100/event.total) + '% of ' + + Math.round(event.total/1024) + ' kB'); + + /* Unknown total size */ + else setStatusDescription(Math.round(event.loaded/1024) + ' kB'); + +}, true); + +listener.addEventListener('error', function() { + setStatus('Loading failed'); + setStatusDescription(document.getElementById('module').lastError + '
Check JavaScript console for more information.'); +}, true); + +listener.addEventListener('abort', function() { + setStatus('Loading aborted'); + setStatusDescription(''); +}, true); + +listener.addEventListener('load', function() { + setStatus(''); + setStatusDescription(''); +}, true); diff --git a/src/Platform/WindowlessNaClApplication.h b/src/Platform/WindowlessNaClApplication.h index d0f4ebb19..54de3ea05 100644 --- a/src/Platform/WindowlessNaClApplication.h +++ b/src/Platform/WindowlessNaClApplication.h @@ -71,11 +71,12 @@ If no other application header is included this class is also aliased to @section WindowlessNaClApplication-html HTML markup and NMF file You need to provide HTML markup containing `<embed>` pointing to `*.nmf` -file describing the application. +file describing the application. See @ref NaClApplication for more information. +You may want to hide the `<embed>` (for example using CSS +`visibility: hidden;`), as it probably won't display anything to default +framebuffer. -@todoc Document this better, add "bootstrap" examples - -@subsection WindowlessNaClApplication-html-console Redirecting output to Chrome's JavaScript console +@section WindowlessNaClApplication-console Redirecting output to Chrome's JavaScript console The application redirects @ref Corrade::Utility::Debug "Debug", @ref Corrade::Utility::Warning "Warning" and @ref Corrade::Utility::Error "Error" diff --git a/src/Platform/magnum-info-nacl.html b/src/Platform/magnum-info-nacl.html index f12bcf996..4a3af2251 100644 --- a/src/Platform/magnum-info-nacl.html +++ b/src/Platform/magnum-info-nacl.html @@ -2,37 +2,10 @@ Magnum Info + - +

Magnum Info

+
Initialization...
+