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 Bsp::readVertices(char*& cursor, unsigned int count, Vec3f::List& vertices) {
     using namespace IO;
     
     vertices.reserve(count);
     for (unsigned int i = 0; i < count; i++) {
         Vec3f vertex = readVec3f(cursor);
         vertices.push_back(vertex);
     }
 }
        void VertexHandleManager::renderFaceHighlight(Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch, const Vec3& handlePosition) {
            Renderer::RenderService renderService(renderContext, renderBatch);
            renderService.setForegroundColor(pref(Preferences::HandleColor));
            
            Model::VertexToFacesMap::const_iterator it = m_unselectedFaceHandles.find(handlePosition);
            if (it != m_unselectedFaceHandles.end()) {
                const Model::BrushFaceSet& faces = it->second;
                assert(!faces.empty());
                
                const Model::BrushFace* face = *faces.begin();
                const Model::BrushFace::VertexList& vertices = face->vertices();

                Vec3f::List vertexPositions;
                vertexPositions.reserve(vertices.size());
                Vec3f::toList(vertices.begin(), vertices.end(), Model::BrushGeometry::GetVertexPosition(), vertexPositions);
                
                renderService.renderPolygonOutline(vertexPositions);
            }
        }
        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();
        }
        bool MoveVerticesCommand::performDo() {
            if (!canDo())
                return false;
            
            m_vertices.clear();
            makeSnapshots(m_brushes);
            document().brushesWillChange(m_brushes);

            BrushVerticesMap::const_iterator it, end;
            for (it = m_brushVertices.begin(), end = m_brushVertices.end(); it != end; ++it) {
                Model::Brush* brush = it->first;
                const Vec3f::List& oldVertexPositions = it->second;
                Vec3f::List newVertexPositions = brush->moveVertices(oldVertexPositions, m_delta);
                m_vertices.insert(newVertexPositions.begin(), newVertexPositions.end());
            }
            
            document().brushesDidChange(m_brushes);
            return true;
        }
 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());
     }
 }