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(); } }
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()); } }