void DefaultPointHandleRenderer::render(Vbo& vbo, RenderContext& context) {
            const Vec4f::List& positionList = positions();
            if (positionList.empty())
                return;

            SetVboState activateVbo(vbo, Vbo::VboActive);
            
            if (m_vertexArray == NULL) {
                Vec3f::List vertices = sphere();
                
                unsigned int vertexCount = static_cast<unsigned int>(vertices.size());
                m_vertexArray = new VertexArray(vbo, GL_TRIANGLES, vertexCount,
                                                Attribute::position3f());
                
                SetVboState mapVbo(vbo, Vbo::VboMapped);
                Vec3f::List::const_iterator vIt, vEnd;
                for (vIt = vertices.begin(), vEnd = vertices.end(); vIt != vEnd; ++vIt) {
                    const Vec3f& vertex = *vIt;
                    m_vertexArray->addAttribute(vertex);
                }
            }
            
            Renderer::ActivateShader shader(context.shaderManager(), Renderer::Shaders::PointHandleShader);
            shader.currentShader().setUniformVariable("Color", color());
            shader.currentShader().setUniformVariable("CameraPosition", context.camera().position());
            shader.currentShader().setUniformVariable("ScalingFactor", scalingFactor());
            shader.currentShader().setUniformVariable("MaximumDistance", maximumDistance());
            
            Vec4f::List::const_iterator pIt, pEnd;
            for (pIt = positionList.begin(), pEnd = positionList.end(); pIt != pEnd; ++pIt) {
                const Vec4f& position = *pIt;
                shader.currentShader().setUniformVariable("Position", position);
                m_vertexArray->render();
            }
        }
Ejemplo n.º 2
0
        void LinesRenderer::render(Vbo& vbo, RenderContext& context) {
            Renderer::SetVboState activateVbo(vbo, Renderer::Vbo::VboActive);
            
            if (!m_valid) {
                delete m_vertexArray;
                m_vertexArray = NULL;
                
                if (!m_vertices.empty()) {
                    Renderer::SetVboState mapVbo(vbo, Renderer::Vbo::VboMapped);

                    m_vertexArray = new VertexArray(vbo, GL_LINES, static_cast<unsigned int>(m_vertices.size()), Attribute::position3f(), 0);
                    m_vertexArray->addAttributes(m_vertices);
                    m_vertices.clear();
                    m_valid = true;
                }
            }
            
            if (m_vertexArray != NULL) {
                Renderer::glSetEdgeOffset(0.3f);
                
                Renderer::ActivateShader handleShader(context.shaderManager(), Renderer::Shaders::HandleShader);
                
                glDisable(GL_DEPTH_TEST);
                handleShader.setUniformVariable("Color", m_occludedColor);
                m_vertexArray->render();
                glEnable(GL_DEPTH_TEST);
                
                handleShader.setUniformVariable("Color", m_color);
                m_vertexArray->render();
                
                Renderer::glResetEdgeOffset();
            }
        }
Ejemplo n.º 3
0
        void EntityRenderer::validateBounds(RenderContext& context) {
            delete m_boundsVertexArray;
            m_boundsVertexArray = NULL;

            Model::EntityList entities;
            Model::EntitySet::iterator entityIt, entityEnd;
            for (entityIt = m_entities.begin(), entityEnd = m_entities.end(); entityIt != entityEnd; ++entityIt) {
                Model::Entity* entity = *entityIt;
                if (context.filter().entityVisible(*entity))
                    entities.push_back(entity);
            }

            if (entities.empty())
                return;

            SetVboState mapVbo(m_boundsVbo, Vbo::VboMapped);

            if (m_overrideBoundsColor) {
                unsigned int vertexCount = 2 * 4 * 6 * static_cast<unsigned int>(entities.size());
                m_boundsVertexArray = new VertexArray(m_boundsVbo, GL_LINES, vertexCount,
                                                      Attribute::position3f());
                writeBounds(context, entities);
            } else {
                unsigned int vertexCount = 2 * 4 * 6 * static_cast<unsigned int>(entities.size());
                m_boundsVertexArray = new VertexArray(m_boundsVbo, GL_LINES, vertexCount,
                                                      Attribute::position3f(),
                                                      Attribute::color4f());
                writeColoredBounds(context, entities);
            }

            m_boundsValid = true;
        }
Ejemplo n.º 4
0
        VboBlock* Vbo::allocBlock(size_t capacity) {
            assert(capacity > 0);
            
#ifdef _DEBUG_VBO
            checkBlockChain();
            checkFreeBlocks();
#endif

            size_t index = findFreeBlock(0, capacity);
            if (index >= m_freeBlocks.size()) {
                SetVboState mapVbo(*this, VboMapped);
                pack();

                if (capacity > m_freeCapacity) {
                    const size_t usedCapacity = m_totalCapacity - m_freeCapacity;
                    size_t newCapacity = m_totalCapacity;
                    size_t newFreeCapacity = m_freeCapacity;
                    while (capacity > newFreeCapacity) {
                        newCapacity *= 2;
                        newFreeCapacity = newCapacity - usedCapacity;
                    }
                    resizeVbo(newCapacity);
                }
                
                index = findFreeBlock(0, capacity);
                assert(index < m_freeBlocks.size());
            }
            
            VboBlock* block = m_freeBlocks[index];
            std::vector<VboBlock*>::iterator it = m_freeBlocks.begin();
            std::advance(it, index);
            m_freeBlocks.erase(it);
            
            // split block
            if (capacity < block->capacity()) {
                VboBlock* remainder = new VboBlock(*this, block->address() + capacity, block->capacity() - capacity);
                remainder->insertBetween(block, block->m_next);
                block->m_capacity = capacity;
                insertFreeBlock(*remainder);
                if (m_last == block) m_last = remainder;
            }
            
            m_freeCapacity -= block->capacity();
            block->m_free = false;

#ifdef _DEBUG_VBO
            checkBlockChain();
            checkFreeBlocks();
#endif

            return block;
        }
        void SphereFigure::render(Vbo& vbo, RenderContext& context) {
            SetVboState activateVbo(vbo, Vbo::VboActive);

            if (m_vertexArray == NULL) {
                Vec3f::List vertices = sphere(m_radius, m_iterations);

                unsigned int vertexCount = static_cast<unsigned int>(vertices.size());
                m_vertexArray = new VertexArray(vbo, GL_TRIANGLES, vertexCount,
                                                Attribute::position3f());
                
                SetVboState mapVbo(vbo, Vbo::VboMapped);
                Vec3f::List::iterator it, end;
                for (it = vertices.begin(), end = vertices.end(); it != end; ++it)
                    m_vertexArray->addAttribute(*it);
            }
            
            assert(m_vertexArray != NULL);
            m_vertexArray->render();
        }
 void InstancedPointHandleRenderer::render(Vbo& vbo, RenderContext& context) {
     SetVboState activateVbo(vbo, Vbo::VboActive);
     
     if (!valid()) {
         delete m_vertexArray;
         m_vertexArray = NULL;
         
         const Vec4f::List& positionList = positions();
         
         if (!positionList.empty()) {
             Vec3f::List vertices = sphere();
             
             unsigned int vertexCount = static_cast<unsigned int>(vertices.size());
             unsigned int instanceCount = static_cast<unsigned int>(positionList.size());
             m_vertexArray = new InstancedVertexArray(vbo, GL_TRIANGLES, vertexCount, instanceCount,
                                                      Attribute::position3f());
             
             SetVboState mapVbo(vbo, Vbo::VboMapped);
             Vec3f::List::iterator it, end;
             for (it = vertices.begin(), end = vertices.end(); it != end; ++it)
                 m_vertexArray->addAttribute(*it);
             
             m_vertexArray->addAttributeArray("position", positionList);
         }
         validate();
     }
     
     if (m_vertexArray != NULL) {
         Renderer::ActivateShader shader(context.shaderManager(), Renderer::Shaders::InstancedPointHandleShader);
         shader.currentShader().setUniformVariable("Color", color());
         shader.currentShader().setUniformVariable("CameraPosition", context.camera().position());
         shader.currentShader().setUniformVariable("ScalingFactor", scalingFactor());
         shader.currentShader().setUniformVariable("MaximumDistance", maximumDistance());
         m_vertexArray->render(shader.currentShader());
     }
 }
Ejemplo n.º 7
0
        void EntityLinkDecorator::render(Vbo& vbo, RenderContext& context) {
            if (context.viewOptions().linkDisplayMode() == View::ViewOptions::LinkDisplayNone)
                return;

            const Model::EntityList& entities = map().entities();
            if (entities.empty())
                return;

            SetVboState activateVbo(vbo, Vbo::VboActive);
            
            if (m_doRebuild) {
                delete m_vertexArray;
                m_vertexArray = NULL;
                m_doRebuild = false;

                // for keeping track of which entities have already been visited by the link-gathering algorithm - should this be part of each entity instead ?
                Model::EntitySet visitedEntities;

                Vec4f::List vertsLocal; // links directly connected to a selected entity
                Vec4f::List vertsContext; // links not directly connected, but in the same context
                Vec4f::List vertsUnrelated; // links not related to the current selection

                Model::EntityList::const_iterator it, end;

                // first pass, outputs local or local+context links
                for (it = entities.begin(), end = entities.end(); it != end; ++it) {
                    Model::Entity& entity = **it;

                    if (entity.selected()) {
                        if (context.viewOptions().linkDisplayMode() == View::ViewOptions::LinkDisplayLocal) {
                            gatherLinksLocal(vertsLocal, context, entity);
                        } else {
                            gatherLinks(vertsLocal, vertsContext, context, entity, visitedEntities);
                        }
                    }
                }

                // second pass, only used in "display all" mode, outputs target links of entities the first pass didn't visit
                if (context.viewOptions().linkDisplayMode() == View::ViewOptions::LinkDisplayAll) {
                    Model::EntitySet::const_iterator vIt;
                    for (it = entities.begin(), end = entities.end(); it != end; ++it) {
                        Model::Entity& entity = **it;
                        vIt = visitedEntities.lower_bound( &entity );

                        if( *vIt != &entity )
                            gatherLinksUnrelated(vertsUnrelated, context, entity);
                    }
                }

                unsigned int vertexCount = static_cast<unsigned int>(vertsLocal.size() + vertsContext.size() + vertsUnrelated.size());
                if (vertexCount == 0)
                    return;
                
                //FIXME : doesn't need to be a color4f at the moment
                m_vertexArray = new VertexArray(vbo, GL_LINES, vertexCount, Attribute::position3f(), Attribute::color4f(), 0);
                
                SetVboState mapVbo(vbo, Vbo::VboMapped);

                // draw order : unrelated -> context -> local
                // vertData.y sets the type of link for the shader ( 0 = unrelated, 0.5 = context, 1.0 = local )
                Vec4f vertData(1.0f);

                vertData.y = 0.0f;
                for (int i = 0; i != vertsUnrelated.size(); ++i ) {
                    vertData.x = vertsUnrelated[i].w;
                    m_vertexArray->addAttribute(Vec3f(vertsUnrelated[i].x, vertsUnrelated[i].y, vertsUnrelated[i].z));
                    m_vertexArray->addAttribute(vertData);
                }
                vertData.y = 0.5f;
                for (int i = 0; i != vertsContext.size(); ++i) {
                    vertData.x = vertsContext[i].w;
                    m_vertexArray->addAttribute(Vec3f(vertsContext[i].x, vertsContext[i].y, vertsContext[i].z));
                    m_vertexArray->addAttribute(vertData);
                }
                vertData.y = 1.0f;
                for (int i = 0; i != vertsLocal.size(); ++i) {
                    vertData.x = vertsLocal[i].w;
                    m_vertexArray->addAttribute(Vec3f(vertsLocal[i].x, vertsLocal[i].y, vertsLocal[i].z));
                    m_vertexArray->addAttribute(vertData);
                }

                m_valid = true;
            }

            if (!m_valid || m_vertexArray == NULL)
                return;

            ActivateShader shader(context.shaderManager(), Shaders::EntityLinkShader );
            shader.currentShader().setUniformVariable("CameraPosition", context.camera().position());
            //shader.currentShader().setUniformVariable("Color", m_color); // unused at the moment, make color view-prefs for the different types of links ?
            shader.currentShader().setUniformVariable("Occluded", 1.0f);

            // render the "occluded" portion without depth-test
            glLineWidth(2.0f);
            glDepthMask(GL_FALSE);
            glDisable(GL_DEPTH_TEST);

            m_vertexArray->render();

            shader.currentShader().setUniformVariable("Occluded", 0.0f);
            glEnable(GL_DEPTH_TEST);

            m_vertexArray->render();

            glDepthMask(GL_TRUE);
            glLineWidth(1.0f);
        }