From cb7f4ca672c060107fbd9cd04e32e9a1eea4639c Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 3 Feb 2015 23:06:09 -0800 Subject: [PATCH] Pre-pull checking --- interface/src/avatar/Avatar.cpp | 5 +- libraries/entities/src/EntityTreeElement.cpp | 9 +- tests/render-utils/src/main.cpp | 176 +++++-------------- 3 files changed, 49 insertions(+), 141 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index af068377b2..71d53c4aa0 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -913,8 +913,9 @@ void Avatar::setAttachmentData(const QVector& attachmentData) { void Avatar::setDisplayName(const QString& displayName) { AvatarData::setDisplayName(displayName); - // FIXME need to find an alternate mechanism for this. - //_displayNameBoundingRect = textRenderer(DISPLAYNAME)->metrics().tightBoundingRect(displayName); + // FIXME is this a sufficient replacement for tightBoundingRect? + glm::vec2 extent = textRenderer(DISPLAYNAME)->computeExtent(displayName); + _displayNameBoundingRect = QRect(QPoint(0, 0), QPoint((int)extent.x, (int)extent.y)); } void Avatar::setBillboard(const QByteArray& billboard) { diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index b80982e9c2..aff6e64f57 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -680,11 +680,10 @@ EntityItem* EntityTreeElement::getEntityWithEntityItemID(const EntityItemID& id) void EntityTreeElement::cleanupEntities() { uint16_t numberOfEntities = _entityItems->size(); - QList entitiesToDelete = *_entityItems; - foreach(EntityItem* entity, entitiesToDelete) { - entity->_element = NULL; - delete entity; - assert(_entityItems->size() == entitiesToDelete.size()); + for (uint16_t i = 0; i < numberOfEntities; i++) { + EntityItem* entity = (*_entityItems)[i]; + entity->_element = NULL; + delete entity; } _entityItems->clear(); } diff --git a/tests/render-utils/src/main.cpp b/tests/render-utils/src/main.cpp index 97c6b597f6..9e622da1c1 100644 --- a/tests/render-utils/src/main.cpp +++ b/tests/render-utils/src/main.cpp @@ -1,6 +1,6 @@ // // main.cpp -// tests/physics/src +// tests/render-utils/src // // Copyright 2014 High Fidelity, Inc. // @@ -13,8 +13,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -28,71 +30,38 @@ #include #include -//#define USE_OGLPLUS -#ifdef USE_OGLPLUS -#include -#include -#include -using ProgramPtr = std::shared_ptr < oglplus::Program >; -using ShapeWrapperPtr = std::shared_ptr < oglplus::shapes::ShapeWrapper >; -#endif - - - -const char simple_vs[] = R"XXXX(#version 330 - -uniform mat4 Projection = mat4(1); -uniform mat4 ModelView = mat4(1); -layout(location = 0) in vec3 Position; - -void main() { - gl_Position = Projection * ModelView * vec4(Position, 1); -} -)XXXX"; - -const char example_gs[] = R"XXXX(#version 330 - layout(triangles) in; - layout(triangle_strip, max_vertices = 3) out; - - void main() { - for (int i = 0; i < 3; ++i) { - gl_Position = vec4(gl_in[i].gl_Position.xyz / 2.0f, 1.0); - EmitVertex(); - } - EndPrimitive(); - } -)XXXX"; - -const char colored_fs[] = R"XXXX(#version 330 - -uniform vec4 Color = vec4(1, 0, 1, 1); -out vec4 FragColor; - -void main() { - FragColor = Color; -} -)XXXX"; - - - +// Create a simple OpenGL window that renders text in various ways class QTestWindow : public QWindow { Q_OBJECT - QOpenGLContext * m_context; -#ifdef USE_OGLPLUS - ProgramPtr shader; - ShapeWrapperPtr plane; -#endif + QOpenGLContext * _context; QSize _size; TextRenderer* _textRenderer[4]; +protected: + void resizeEvent(QResizeEvent * ev) override { + QWindow::resizeEvent(ev); + _size = ev->size(); + resizeGl(); + } + + void resizeGl() { + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, _size.width(), _size.height(), 0, 1, -1); + glMatrixMode(GL_MODELVIEW); + glViewport(0, 0, _size.width(), _size.height()); + } + public: QTestWindow(); - virtual ~QTestWindow(); - void makeCurrent(); - void draw(); + virtual ~QTestWindow() { -protected: - void resizeEvent(QResizeEvent * ev) override; + } + void makeCurrent() { + _context->makeCurrent(this); + } + + void draw(); }; QTestWindow::QTestWindow() { @@ -106,9 +75,9 @@ QTestWindow::QTestWindow() { format.setProfile(QSurfaceFormat::OpenGLContextProfile::CompatibilityProfile); setFormat(format); - m_context = new QOpenGLContext; - m_context->setFormat(format); - m_context->create(); + _context = new QOpenGLContext; + _context->setFormat(format); + _context->create(); show(); makeCurrent(); @@ -132,67 +101,24 @@ QTestWindow::QTestWindow() { setFramePosition(QPoint(100, -900)); resize(QSize(800, 600)); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + _size = QSize(800, 600); _textRenderer[0] = TextRenderer::getInstance(SANS_FONT_FAMILY, 12, false); _textRenderer[1] = TextRenderer::getInstance(SERIF_FONT_FAMILY, 12, false, TextRenderer::SHADOW_EFFECT); _textRenderer[2] = TextRenderer::getInstance(MONO_FONT_FAMILY, 48, -1, false, TextRenderer::OUTLINE_EFFECT); _textRenderer[3] = TextRenderer::getInstance(INCONSOLATA_FONT_FAMILY, 24); - -#ifdef USE_OGLPLUS - using namespace oglplus; - shader = ProgramPtr(new Program()); - // attach the shaders to the program - shader->AttachShader( - VertexShader() - .Source(GLSLSource((const char*)simple_vs)) - .Compile() - ); - shader->AttachShader( - GeometryShader() - .Source(GLSLSource((const char*)example_gs)) - .Compile() - ); - shader->AttachShader( - FragmentShader() - .Source(GLSLSource((const char*)colored_fs)) - .Compile() - ); - shader->Link(); - - size_t uniformCount = shader->ActiveUniforms().Size(); - for (size_t i = 0; i < uniformCount; ++i) { - std::string name = shader->ActiveUniforms().At(i).Name(); - int location = shader->ActiveUniforms().At(i).Index(); - qDebug() << name.c_str() << " " << location; - } - plane = ShapeWrapperPtr( - new shapes::ShapeWrapper( - { "Position", "TexCoord" }, - shapes::Plane(Vec3f(1, 0, 0), Vec3f(0, 1, 0)), - *shader - ) - ); - plane->Use(); -#endif - glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -} - -QTestWindow::~QTestWindow() { -} - -void QTestWindow::makeCurrent() { - m_context->makeCurrent(this); + glClearColor(0.2f, 0.2f, 0.2f, 1); + glDisable(GL_DEPTH_TEST); + resizeGl(); } static const wchar_t * EXAMPLE_TEXT = L"Áy Hello 1.0\nyÁ line 2\nÁy"; static const glm::uvec2 QUAD_OFFSET(10, 10); static const glm::vec3 COLORS[4] = { - { 1, 1, 1 }, + { 1.0, 1.0, 1.0 }, { 0.5, 1.0, 0.5 }, { 1.0, 0.5, 0.5 }, { 0.5, 0.5, 1.0 }, @@ -200,26 +126,7 @@ static const glm::vec3 COLORS[4] = { void QTestWindow::draw() { makeCurrent(); - - glViewport(0, 0, _size.width(), _size.height()); - glClearColor(0.2f, 0.2f, 0.2f, 1); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - //{ - // using namespace oglplus; - // shader->Use(); - // Uniform(*shader, "Color").Set(Vec4f(1.0f, 0, 0, 1.0f)); - // plane->Use(); - // plane->Draw(); - // NoProgram().Bind(); - //} - - // m_context->swapBuffers(this); return; - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(0, _size.width(), _size.height(), 0, 1, -1); - glMatrixMode(GL_MODELVIEW); - + glClear(GL_COLOR_BUFFER_BIT); const glm::uvec2 size = glm::uvec2(_size.width() / 2, _size.height() / 2); const glm::uvec2 offsets[4] = { @@ -230,8 +137,11 @@ void QTestWindow::draw() { }; QString str = QString::fromWCharArray(EXAMPLE_TEXT); + for (int i = 0; i < 4; ++i) { glm::vec2 bounds = _textRenderer[i]->computeExtent(str); + + // Draw backgrounds around where the text will appear glPushMatrix(); { glTranslatef(offsets[i].x, offsets[i].y, 0); glColor3f(0, 0, 0); @@ -242,14 +152,12 @@ void QTestWindow::draw() { glVertex2f(bounds.x, 0); } glEnd(); } glPopMatrix(); + + // Draw the text itself _textRenderer[i]->draw(offsets[i].x, offsets[i].y, str, glm::vec4(COLORS[i], 1.0f)); } - m_context->swapBuffers(this); -} -void QTestWindow::resizeEvent(QResizeEvent * ev) { - QWindow::resizeEvent(ev); - _size = ev->size(); + _context->swapBuffers(this); } int main(int argc, char** argv) {