From 475216609762ce4443bd4f9ddc5524db845bd0bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 4 Jul 2013 18:08:33 +0200 Subject: [PATCH] Text: use CHROMIUM_map_sub rather than OES_mapbuffer. OES_mapbuffer isn't available in (my) NaCl anyway and CHROMIUM_map_sub should be faster. --- src/Text/TextRenderer.cpp | 76 ++++++++++++++++++++++++++------------- src/Text/TextRenderer.h | 25 +++++++++++-- 2 files changed, 73 insertions(+), 28 deletions(-) diff --git a/src/Text/TextRenderer.cpp b/src/Text/TextRenderer.cpp index c2d7d0686..4f04aaccd 100644 --- a/src/Text/TextRenderer.cpp +++ b/src/Text/TextRenderer.cpp @@ -205,14 +205,55 @@ template std::tuple TextRendererisExtensionSupported()) { + if(Context::current()->isExtensionSupported()) { + bufferMapImplementation = &AbstractTextRenderer::bufferMapImplementationRange; + } else if(Context::current()->isExtensionSupported()) { + bufferMapImplementation = &AbstractTextRenderer::bufferMapImplementationSub; + bufferUnmapImplementation = &AbstractTextRenderer::bufferUnmapImplementationSub; + } else { MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::OES::mapbuffer); - Warning() << "Text::TextRenderer:" << Extensions::GL::EXT::map_buffer_range::string() - << "is not supported, using less efficient" << Extensions::GL::OES::mapbuffer::string() + Warning() << "Text::TextRenderer: neither" << Extensions::GL::EXT::map_buffer_range::string() + << "nor" << Extensions::GL::CHROMIUM::map_sub::string() + << "is supported, using inefficient" << Extensions::GL::OES::mapbuffer::string() << "instead"; } #endif @@ -258,15 +299,8 @@ void AbstractTextRenderer::reserve(const uint32_t glyphCount, const Buffer::Usag ->setIndexBuffer(&_indexBuffer, 0, indexType, 0, vertexCount); /* Map buffer for filling */ - void* indices; - #ifdef MAGNUM_TARGET_GLES2 - if(Context::current()->isExtensionSupported()) - #endif - CORRADE_INTERNAL_ASSERT_OUTPUT(indices = _indexBuffer.map(0, indicesSize, - Buffer::MapFlag::InvalidateBuffer|Buffer::MapFlag::Write)); - #ifdef MAGNUM_TARGET_GLES2 - else CORRADE_INTERNAL_ASSERT_OUTPUT(indices = _indexBuffer.map(Buffer::MapAccess::WriteOnly)); - #endif + void* const indices = bufferMapImplementation(_indexBuffer, indicesSize); + CORRADE_INTERNAL_ASSERT(indices); /* Prefill index buffer */ if(vertexCount < 255) @@ -275,7 +309,7 @@ void AbstractTextRenderer::reserve(const uint32_t glyphCount, const Buffer::Usag createIndices(indices, glyphCount); else createIndices(indices, glyphCount); - CORRADE_INTERNAL_ASSERT_OUTPUT(_indexBuffer.unmap()); + bufferUnmapImplementation(_indexBuffer); } void AbstractTextRenderer::render(const std::string& text) { @@ -288,17 +322,9 @@ void AbstractTextRenderer::render(const std::string& text) { _rectangle = {}; /* Map buffer for rendering */ - Vertex* vertices; - #ifdef MAGNUM_TARGET_GLES2 - if(Context::current()->isExtensionSupported()) - #endif - CORRADE_INTERNAL_ASSERT_OUTPUT(vertices = static_cast(_vertexBuffer.map(0, - layouter->glyphCount()*4*sizeof(Vertex), - Buffer::MapFlag::InvalidateBuffer|Buffer::MapFlag::Write))); - #ifdef MAGNUM_TARGET_GLES2 - else CORRADE_INTERNAL_ASSERT_OUTPUT(vertices = - static_cast(_vertexBuffer.map(Buffer::MapAccess::WriteOnly))); - #endif + Vertex* const vertices = static_cast(bufferMapImplementation(_vertexBuffer, + layouter->glyphCount()*4*sizeof(Vertex))); + CORRADE_INTERNAL_ASSERT_OUTPUT(vertices); /* Render all glyphs */ Vector2 cursorPosition; @@ -325,7 +351,7 @@ void AbstractTextRenderer::render(const std::string& text) { /* Advance cursor position to next character */ cursorPosition += advance; } - CORRADE_INTERNAL_ASSERT_OUTPUT(_vertexBuffer.unmap()); + bufferUnmapImplementation(_vertexBuffer); /* Update index count */ _mesh.setIndexCount(layouter->glyphCount()*6); diff --git a/src/Text/TextRenderer.h b/src/Text/TextRenderer.h index 289d44940..ce0d0b0db 100644 --- a/src/Text/TextRenderer.h +++ b/src/Text/TextRenderer.h @@ -134,6 +134,25 @@ class MAGNUM_TEXT_EXPORT AbstractTextRenderer { Float size; UnsignedInt _capacity; Rectangle _rectangle; + + #ifdef MAGNUM_TARGET_GLES2 + typedef void*(*BufferMapImplementation)(Buffer&, GLsizeiptr); + static MAGNUM_TEXT_LOCAL void* bufferMapImplementationFull(Buffer& buffer, GLsizeiptr length); + static MAGNUM_TEXT_LOCAL void* bufferMapImplementationSub(Buffer& buffer, GLsizeiptr length); + static MAGNUM_TEXT_LOCAL void* bufferMapImplementationRange(Buffer& buffer, GLsizeiptr length); + static BufferMapImplementation bufferMapImplementation; + #else + static void* bufferMapImplementation(Buffer& buffer, GLsizeiptr length); + #endif + + #ifdef MAGNUM_TARGET_GLES2 + typedef void(*BufferUnmapImplementation)(Buffer&); + static MAGNUM_TEXT_LOCAL void bufferUnmapImplementationDefault(Buffer& buffer); + static MAGNUM_TEXT_LOCAL void bufferUnmapImplementationSub(Buffer& buffer); + static MAGNUM_TEXT_LOCAL BufferUnmapImplementation bufferUnmapImplementation; + #else + static void bufferUnmapImplementation(Buffer& buffer); + #endif }; /** @@ -198,9 +217,9 @@ renderer.mesh().draw(); @section TextRenderer-extensions Required OpenGL functionality Mutable text rendering requires @extension{ARB,map_buffer_range} on desktop -OpenGL (also part of OpenGL ES 3.0). If @es_extension{EXT,map_buffer_range} is -not available in ES 2.0, at least @es_extension{OES,mapbuffer} must be -supported for asynchronous buffer updates. +OpenGL (also part of OpenGL ES 3.0). If neither @es_extension{EXT,map_buffer_range} +nor @es_extension{CHROMIUM,map_sub} is not available in ES 2.0, at least +@es_extension{OES,mapbuffer} must be supported for asynchronous buffer updates. @see TextRenderer2D, TextRenderer3D, Font, Shaders::AbstractVectorShader */