mirror of https://github.com/mosra/magnum.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
379 lines
15 KiB
379 lines
15 KiB
|
14 years ago
|
/*
|
||
|
|
This file is part of Magnum.
|
||
|
|
|
||
|
13 years ago
|
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
|
||
|
|
|
||
|
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||
|
|
copy of this software and associated documentation files (the "Software"),
|
||
|
|
to deal in the Software without restriction, including without limitation
|
||
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||
|
|
and/or sell copies of the Software, and to permit persons to whom the
|
||
|
|
Software is furnished to do so, subject to the following conditions:
|
||
|
|
|
||
|
|
The above copyright notice and this permission notice shall be included
|
||
|
|
in all copies or substantial portions of the Software.
|
||
|
|
|
||
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||
|
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||
|
|
DEALINGS IN THE SOFTWARE.
|
||
|
14 years ago
|
*/
|
||
|
|
|
||
|
13 years ago
|
#include "Renderer.h"
|
||
|
14 years ago
|
|
||
|
13 years ago
|
#include "Context.h"
|
||
|
|
#include "Extensions.h"
|
||
|
13 years ago
|
#include "Mesh.h"
|
||
|
13 years ago
|
#include "Shaders/AbstractVector.h"
|
||
|
13 years ago
|
#include "Text/AbstractFont.h"
|
||
|
14 years ago
|
|
||
|
|
namespace Magnum { namespace Text {
|
||
|
|
|
||
|
|
namespace {
|
||
|
|
|
||
|
13 years ago
|
template<class T> void createIndices(void* output, const UnsignedInt glyphCount) {
|
||
|
13 years ago
|
T* const out = reinterpret_cast<T*>(output);
|
||
|
13 years ago
|
for(UnsignedInt i = 0; i != glyphCount; ++i) {
|
||
|
13 years ago
|
/* 0---2 0---2 5
|
||
|
|
| | | / /|
|
||
|
|
| | | / / |
|
||
|
|
| | |/ / |
|
||
|
|
1---3 1 3---4 */
|
||
|
14 years ago
|
|
||
|
13 years ago
|
const T vertex = i*4;
|
||
|
|
const T pos = i*6;
|
||
|
|
out[pos] = vertex;
|
||
|
|
out[pos+1] = vertex+1;
|
||
|
|
out[pos+2] = vertex+2;
|
||
|
|
out[pos+3] = vertex+1;
|
||
|
|
out[pos+4] = vertex+3;
|
||
|
|
out[pos+5] = vertex+2;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
struct Vertex {
|
||
|
|
Vector2 position, texcoords;
|
||
|
13 years ago
|
};
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
std::tuple<std::vector<Vector2>, std::vector<Vector2>, std::vector<UnsignedInt>, Rectangle> AbstractRenderer::render(AbstractFont& font, const GlyphCache& cache, Float size, const std::string& text) {
|
||
|
13 years ago
|
const auto layouter = font.layout(cache, size, text);
|
||
|
13 years ago
|
const UnsignedInt vertexCount = layouter->glyphCount()*4;
|
||
|
13 years ago
|
|
||
|
|
/* Output data */
|
||
|
13 years ago
|
std::vector<Vector2> positions, texcoords;
|
||
|
13 years ago
|
positions.reserve(vertexCount);
|
||
|
|
texcoords.reserve(vertexCount);
|
||
|
|
|
||
|
13 years ago
|
/* Rendered rectangle */
|
||
|
|
Rectangle rectangle;
|
||
|
|
|
||
|
13 years ago
|
/* Render all glyphs */
|
||
|
|
Vector2 cursorPosition;
|
||
|
13 years ago
|
for(UnsignedInt i = 0; i != layouter->glyphCount(); ++i) {
|
||
|
13 years ago
|
/* Position of the texture in the resulting glyph, texture coordinates */
|
||
|
|
Rectangle quadPosition, textureCoordinates;
|
||
|
|
Vector2 advance;
|
||
|
13 years ago
|
std::tie(quadPosition, textureCoordinates, advance) = layouter->renderGlyph(i);
|
||
|
|
|
||
|
|
/* Move the quad to cursor */
|
||
|
|
quadPosition.bottomLeft() += cursorPosition;
|
||
|
|
quadPosition.topRight() += cursorPosition;
|
||
|
13 years ago
|
|
||
|
13 years ago
|
/* 0---2
|
||
|
|
| |
|
||
|
|
| |
|
||
|
|
| |
|
||
|
|
1---3 */
|
||
|
|
|
||
|
14 years ago
|
positions.insert(positions.end(), {
|
||
|
13 years ago
|
quadPosition.topLeft(),
|
||
|
|
quadPosition.bottomLeft(),
|
||
|
|
quadPosition.topRight(),
|
||
|
|
quadPosition.bottomRight(),
|
||
|
14 years ago
|
});
|
||
|
|
texcoords.insert(texcoords.end(), {
|
||
|
|
textureCoordinates.topLeft(),
|
||
|
|
textureCoordinates.bottomLeft(),
|
||
|
|
textureCoordinates.topRight(),
|
||
|
|
textureCoordinates.bottomRight()
|
||
|
|
});
|
||
|
|
|
||
|
13 years ago
|
/* Extend rectangle with current quad bounds */
|
||
|
|
rectangle.bottomLeft() = Math::min(rectangle.bottomLeft(), quadPosition.bottomLeft());
|
||
|
|
rectangle.topRight() = Math::max(rectangle.topRight(), quadPosition.topRight());
|
||
|
|
|
||
|
14 years ago
|
/* Advance cursor position to next character */
|
||
|
|
cursorPosition += advance;
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
/* Create indices */
|
||
|
13 years ago
|
std::vector<UnsignedInt> indices(layouter->glyphCount()*6);
|
||
|
|
createIndices<UnsignedInt>(indices.data(), layouter->glyphCount());
|
||
|
13 years ago
|
|
||
|
13 years ago
|
return std::make_tuple(std::move(positions), std::move(texcoords), std::move(indices), rectangle);
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
std::tuple<Mesh, Rectangle> AbstractRenderer::render(AbstractFont& font, const GlyphCache& cache, Float size, const std::string& text, Buffer& vertexBuffer, Buffer& indexBuffer, Buffer::Usage usage) {
|
||
|
13 years ago
|
const auto layouter = font.layout(cache, size, text);
|
||
|
14 years ago
|
|
||
|
13 years ago
|
const UnsignedInt vertexCount = layouter->glyphCount()*4;
|
||
|
|
const UnsignedInt indexCount = layouter->glyphCount()*6;
|
||
|
14 years ago
|
|
||
|
13 years ago
|
/* Vertex buffer */
|
||
|
13 years ago
|
std::vector<Vertex> vertices;
|
||
|
13 years ago
|
vertices.reserve(vertexCount);
|
||
|
14 years ago
|
|
||
|
13 years ago
|
/* Rendered rectangle */
|
||
|
|
Rectangle rectangle;
|
||
|
|
|
||
|
13 years ago
|
/* Render all glyphs */
|
||
|
|
Vector2 cursorPosition;
|
||
|
13 years ago
|
for(UnsignedInt i = 0; i != layouter->glyphCount(); ++i) {
|
||
|
13 years ago
|
/* Position of the texture in the resulting glyph, texture coordinates */
|
||
|
|
Rectangle quadPosition, textureCoordinates;
|
||
|
|
Vector2 advance;
|
||
|
13 years ago
|
std::tie(quadPosition, textureCoordinates, advance) = layouter->renderGlyph(i);
|
||
|
|
|
||
|
|
/* Move the quad to cursor */
|
||
|
|
quadPosition.bottomLeft() += cursorPosition;
|
||
|
|
quadPosition.topRight() += cursorPosition;
|
||
|
13 years ago
|
|
||
|
|
vertices.insert(vertices.end(), {
|
||
|
13 years ago
|
{quadPosition.topLeft(), textureCoordinates.topLeft()},
|
||
|
|
{quadPosition.bottomLeft(), textureCoordinates.bottomLeft()},
|
||
|
|
{quadPosition.topRight(), textureCoordinates.topRight()},
|
||
|
|
{quadPosition.bottomRight(), textureCoordinates.bottomRight()}
|
||
|
13 years ago
|
});
|
||
|
14 years ago
|
|
||
|
13 years ago
|
/* Extend rectangle with current quad bounds */
|
||
|
|
rectangle.bottomLeft() = Math::min(rectangle.bottomLeft(), quadPosition.bottomLeft());
|
||
|
|
rectangle.topRight() = Math::max(rectangle.topRight(), quadPosition.topRight());
|
||
|
|
|
||
|
13 years ago
|
/* Advance cursor position to next character */
|
||
|
|
cursorPosition += advance;
|
||
|
|
}
|
||
|
13 years ago
|
vertexBuffer.setData(vertices, usage);
|
||
|
13 years ago
|
|
||
|
|
/* Fill index buffer */
|
||
|
|
Mesh::IndexType indexType;
|
||
|
|
std::size_t indicesSize;
|
||
|
|
char* indices;
|
||
|
|
if(vertexCount < 255) {
|
||
|
|
indexType = Mesh::IndexType::UnsignedByte;
|
||
|
13 years ago
|
indicesSize = indexCount*sizeof(UnsignedByte);
|
||
|
13 years ago
|
indices = new char[indicesSize];
|
||
|
13 years ago
|
createIndices<UnsignedByte>(indices, layouter->glyphCount());
|
||
|
13 years ago
|
} else if(vertexCount < 65535) {
|
||
|
|
indexType = Mesh::IndexType::UnsignedShort;
|
||
|
13 years ago
|
indicesSize = indexCount*sizeof(UnsignedShort);
|
||
|
13 years ago
|
indices = new char[indicesSize];
|
||
|
13 years ago
|
createIndices<UnsignedShort>(indices, layouter->glyphCount());
|
||
|
13 years ago
|
} else {
|
||
|
|
indexType = Mesh::IndexType::UnsignedInt;
|
||
|
13 years ago
|
indicesSize = indexCount*sizeof(UnsignedInt);
|
||
|
13 years ago
|
indices = new char[indicesSize];
|
||
|
13 years ago
|
createIndices<UnsignedInt>(indices, layouter->glyphCount());
|
||
|
13 years ago
|
}
|
||
|
13 years ago
|
indexBuffer.setData({indices, indicesSize}, usage);
|
||
|
13 years ago
|
delete indices;
|
||
|
14 years ago
|
|
||
|
13 years ago
|
/* Configure mesh except for vertex buffer (depends on dimension count, done
|
||
|
|
in subclass) */
|
||
|
13 years ago
|
Mesh mesh;
|
||
|
14 years ago
|
mesh.setPrimitive(Mesh::Primitive::Triangles)
|
||
|
13 years ago
|
.setIndexCount(indexCount)
|
||
|
|
.setIndexBuffer(indexBuffer, 0, indexType, 0, vertexCount);
|
||
|
14 years ago
|
|
||
|
13 years ago
|
return std::make_tuple(std::move(mesh), rectangle);
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
template<UnsignedInt dimensions> std::tuple<Mesh, Rectangle> Renderer<dimensions>::render(AbstractFont& font, const GlyphCache& cache, Float size, const std::string& text, Buffer& vertexBuffer, Buffer& indexBuffer, Buffer::Usage usage) {
|
||
|
13 years ago
|
/* Finalize mesh configuration and return the result */
|
||
|
13 years ago
|
auto r = AbstractRenderer::render(font, cache, size, text, vertexBuffer, indexBuffer, usage);
|
||
|
13 years ago
|
Mesh& mesh = std::get<0>(r);
|
||
|
13 years ago
|
mesh.addVertexBuffer(vertexBuffer, 0,
|
||
|
13 years ago
|
typename Shaders::AbstractVector<dimensions>::Position(
|
||
|
|
Shaders::AbstractVector<dimensions>::Position::Components::Two),
|
||
|
|
typename Shaders::AbstractVector<dimensions>::TextureCoordinates());
|
||
|
13 years ago
|
return std::move(r);
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
#if defined(MAGNUM_TARGET_GLES2) && !defined(CORRADE_TARGET_EMSCRIPTEN)
|
||
|
13 years ago
|
AbstractRenderer::BufferMapImplementation AbstractRenderer::bufferMapImplementation = &AbstractRenderer::bufferMapImplementationFull;
|
||
|
|
AbstractRenderer::BufferUnmapImplementation AbstractRenderer::bufferUnmapImplementation = &AbstractRenderer::bufferUnmapImplementationDefault;
|
||
|
13 years ago
|
|
||
|
13 years ago
|
void* AbstractRenderer::bufferMapImplementationFull(Buffer& buffer, GLsizeiptr) {
|
||
|
13 years ago
|
return buffer.map(Buffer::MapAccess::WriteOnly);
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
void* AbstractRenderer::bufferMapImplementationSub(Buffer& buffer, GLsizeiptr length) {
|
||
|
13 years ago
|
return buffer.mapSub(0, length, Buffer::MapAccess::WriteOnly);
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
void AbstractRenderer::bufferUnmapImplementationSub(Buffer& buffer) {
|
||
|
13 years ago
|
buffer.unmapSub();
|
||
|
13 years ago
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
13 years ago
|
#if !defined(MAGNUM_TARGET_GLES2) || defined(CORRADE_TARGET_EMSCRIPTEN)
|
||
|
13 years ago
|
inline void* AbstractRenderer::bufferMapImplementation(Buffer& buffer, GLsizeiptr length)
|
||
|
13 years ago
|
#else
|
||
|
13 years ago
|
void* AbstractRenderer::bufferMapImplementationRange(Buffer& buffer, GLsizeiptr length)
|
||
|
13 years ago
|
#endif
|
||
|
|
{
|
||
|
13 years ago
|
#ifndef CORRADE_TARGET_EMSCRIPTEN
|
||
|
13 years ago
|
return buffer.map(0, length, Buffer::MapFlag::InvalidateBuffer|Buffer::MapFlag::Write);
|
||
|
13 years ago
|
#else
|
||
|
|
static_cast<void>(length);
|
||
|
|
return &buffer == &_indexBuffer ? _indexBufferData : _vertexBufferData;
|
||
|
|
#endif
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
#if !defined(MAGNUM_TARGET_GLES2) || defined(CORRADE_TARGET_EMSCRIPTEN)
|
||
|
13 years ago
|
inline void AbstractRenderer::bufferUnmapImplementation(Buffer& buffer)
|
||
|
13 years ago
|
#else
|
||
|
13 years ago
|
void AbstractRenderer::bufferUnmapImplementationDefault(Buffer& buffer)
|
||
|
13 years ago
|
#endif
|
||
|
|
{
|
||
|
13 years ago
|
#ifndef CORRADE_TARGET_EMSCRIPTEN
|
||
|
13 years ago
|
buffer.unmap();
|
||
|
13 years ago
|
#else
|
||
|
|
buffer.setSubData(0, &buffer == &_indexBuffer ? _indexBufferData : _vertexBufferData);
|
||
|
|
#endif
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
AbstractRenderer::AbstractRenderer(AbstractFont& font, const GlyphCache& cache, Float size): _vertexBuffer(Buffer::Target::Array), _indexBuffer(Buffer::Target::ElementArray), font(font), cache(cache), size(size), _capacity(0) {
|
||
|
13 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::map_buffer_range);
|
||
|
13 years ago
|
#elif defined(MAGNUM_TARGET_GLES2) && !defined(CORRADE_TARGET_EMSCRIPTEN)
|
||
|
13 years ago
|
if(Context::current()->isExtensionSupported<Extensions::GL::EXT::map_buffer_range>()) {
|
||
|
13 years ago
|
bufferMapImplementation = &AbstractRenderer::bufferMapImplementationRange;
|
||
|
13 years ago
|
} else if(Context::current()->isExtensionSupported<Extensions::GL::CHROMIUM::map_sub>()) {
|
||
|
13 years ago
|
bufferMapImplementation = &AbstractRenderer::bufferMapImplementationSub;
|
||
|
|
bufferUnmapImplementation = &AbstractRenderer::bufferUnmapImplementationSub;
|
||
|
13 years ago
|
} else {
|
||
|
13 years ago
|
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::OES::mapbuffer);
|
||
|
13 years ago
|
Warning() << "Text::Renderer: neither" << Extensions::GL::EXT::map_buffer_range::string()
|
||
|
13 years ago
|
<< "nor" << Extensions::GL::CHROMIUM::map_sub::string()
|
||
|
|
<< "is supported, using inefficient" << Extensions::GL::OES::mapbuffer::string()
|
||
|
13 years ago
|
<< "instead";
|
||
|
|
}
|
||
|
13 years ago
|
#endif
|
||
|
|
|
||
|
13 years ago
|
/* Vertex buffer configuration depends on dimension count, done in subclass */
|
||
|
|
_mesh.setPrimitive(Mesh::Primitive::Triangles);
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
AbstractRenderer::~AbstractRenderer() {}
|
||
|
13 years ago
|
|
||
|
13 years ago
|
template<UnsignedInt dimensions> Renderer<dimensions>::Renderer(AbstractFont& font, const GlyphCache& cache, const Float size): AbstractRenderer(font, cache, size) {
|
||
|
13 years ago
|
/* Finalize mesh configuration */
|
||
|
13 years ago
|
_mesh.addVertexBuffer(_vertexBuffer, 0,
|
||
|
13 years ago
|
typename Shaders::AbstractVector<dimensions>::Position(Shaders::AbstractVector<dimensions>::Position::Components::Two),
|
||
|
|
typename Shaders::AbstractVector<dimensions>::TextureCoordinates());
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
void AbstractRenderer::reserve(const uint32_t glyphCount, const Buffer::Usage vertexBufferUsage, const Buffer::Usage indexBufferUsage) {
|
||
|
13 years ago
|
_capacity = glyphCount;
|
||
|
|
|
||
|
13 years ago
|
const UnsignedInt vertexCount = glyphCount*4;
|
||
|
|
const UnsignedInt indexCount = glyphCount*6;
|
||
|
13 years ago
|
|
||
|
|
/* Allocate vertex buffer, reset vertex count */
|
||
|
13 years ago
|
_vertexBuffer.setData({nullptr, vertexCount*sizeof(Vertex)}, vertexBufferUsage);
|
||
|
13 years ago
|
#ifdef CORRADE_TARGET_EMSCRIPTEN
|
||
|
|
_vertexBufferData = Containers::Array<UnsignedByte>(vertexCount*sizeof(Vertex));
|
||
|
|
#endif
|
||
|
13 years ago
|
_mesh.setVertexCount(0);
|
||
|
|
|
||
|
|
/* Allocate index buffer, reset index count and reconfigure buffer binding */
|
||
|
|
Mesh::IndexType indexType;
|
||
|
|
std::size_t indicesSize;
|
||
|
|
if(vertexCount < 255) {
|
||
|
|
indexType = Mesh::IndexType::UnsignedByte;
|
||
|
13 years ago
|
indicesSize = indexCount*sizeof(UnsignedByte);
|
||
|
13 years ago
|
} else if(vertexCount < 65535) {
|
||
|
|
indexType = Mesh::IndexType::UnsignedShort;
|
||
|
13 years ago
|
indicesSize = indexCount*sizeof(UnsignedShort);
|
||
|
13 years ago
|
} else {
|
||
|
|
indexType = Mesh::IndexType::UnsignedInt;
|
||
|
13 years ago
|
indicesSize = indexCount*sizeof(UnsignedInt);
|
||
|
13 years ago
|
}
|
||
|
13 years ago
|
_indexBuffer.setData({nullptr, indicesSize}, indexBufferUsage);
|
||
|
13 years ago
|
#ifdef CORRADE_TARGET_EMSCRIPTEN
|
||
|
|
_indexBufferData = Containers::Array<UnsignedByte>(indicesSize);
|
||
|
|
#endif
|
||
|
13 years ago
|
_mesh.setIndexCount(0)
|
||
|
13 years ago
|
.setIndexBuffer(_indexBuffer, 0, indexType, 0, vertexCount);
|
||
|
13 years ago
|
|
||
|
13 years ago
|
/* Map buffer for filling */
|
||
|
13 years ago
|
void* const indices = bufferMapImplementation(_indexBuffer, indicesSize);
|
||
|
|
CORRADE_INTERNAL_ASSERT(indices);
|
||
|
13 years ago
|
|
||
|
13 years ago
|
/* Prefill index buffer */
|
||
|
|
if(vertexCount < 255)
|
||
|
13 years ago
|
createIndices<UnsignedByte>(indices, glyphCount);
|
||
|
13 years ago
|
else if(vertexCount < 65535)
|
||
|
13 years ago
|
createIndices<UnsignedShort>(indices, glyphCount);
|
||
|
13 years ago
|
else
|
||
|
13 years ago
|
createIndices<UnsignedInt>(indices, glyphCount);
|
||
|
13 years ago
|
bufferUnmapImplementation(_indexBuffer);
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
void AbstractRenderer::render(const std::string& text) {
|
||
|
13 years ago
|
const auto layouter = font.layout(cache, size, text);
|
||
|
13 years ago
|
|
||
|
13 years ago
|
CORRADE_ASSERT(layouter->glyphCount() <= _capacity,
|
||
|
13 years ago
|
"Text::Renderer::render(): capacity" << _capacity << "too small to render" << layouter->glyphCount() << "glyphs", );
|
||
|
13 years ago
|
|
||
|
|
/* Reset rendered rectangle */
|
||
|
|
_rectangle = {};
|
||
|
13 years ago
|
|
||
|
13 years ago
|
/* Map buffer for rendering */
|
||
|
13 years ago
|
Vertex* const vertices = static_cast<Vertex*>(bufferMapImplementation(_vertexBuffer,
|
||
|
|
layouter->glyphCount()*4*sizeof(Vertex)));
|
||
|
|
CORRADE_INTERNAL_ASSERT_OUTPUT(vertices);
|
||
|
13 years ago
|
|
||
|
13 years ago
|
/* Render all glyphs */
|
||
|
|
Vector2 cursorPosition;
|
||
|
13 years ago
|
for(UnsignedInt i = 0; i != layouter->glyphCount(); ++i) {
|
||
|
13 years ago
|
/* Position of the texture in the resulting glyph, texture coordinates */
|
||
|
|
Rectangle quadPosition, textureCoordinates;
|
||
|
|
Vector2 advance;
|
||
|
13 years ago
|
std::tie(quadPosition, textureCoordinates, advance) = layouter->renderGlyph(i);
|
||
|
|
|
||
|
|
/* Move the quad to cursor */
|
||
|
|
quadPosition.bottomLeft() += cursorPosition;
|
||
|
|
quadPosition.topRight() += cursorPosition;
|
||
|
13 years ago
|
|
||
|
13 years ago
|
/* Extend rectangle with current quad bounds */
|
||
|
|
_rectangle.bottomLeft() = Math::min(_rectangle.bottomLeft(), quadPosition.bottomLeft());
|
||
|
|
_rectangle.topRight() = Math::max(_rectangle.topRight(), quadPosition.topRight());
|
||
|
13 years ago
|
|
||
|
|
const std::size_t vertex = i*4;
|
||
|
13 years ago
|
vertices[vertex] = {quadPosition.topLeft(), textureCoordinates.topLeft()};
|
||
|
|
vertices[vertex+1] = {quadPosition.bottomLeft(), textureCoordinates.bottomLeft()};
|
||
|
|
vertices[vertex+2] = {quadPosition.topRight(), textureCoordinates.topRight()};
|
||
|
|
vertices[vertex+3] = {quadPosition.bottomRight(), textureCoordinates.bottomRight()};
|
||
|
13 years ago
|
|
||
|
|
/* Advance cursor position to next character */
|
||
|
|
cursorPosition += advance;
|
||
|
|
}
|
||
|
13 years ago
|
bufferUnmapImplementation(_vertexBuffer);
|
||
|
13 years ago
|
|
||
|
|
/* Update index count */
|
||
|
13 years ago
|
_mesh.setIndexCount(layouter->glyphCount()*6);
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
#ifndef DOXYGEN_GENERATING_OUTPUT
|
||
|
13 years ago
|
template class MAGNUM_TEXT_EXPORT Renderer<2>;
|
||
|
|
template class MAGNUM_TEXT_EXPORT Renderer<3>;
|
||
|
13 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
|
}}
|