Пример #1
0
void Arrow3d::RenderArrow(ScreenBase const & screen, ref_ptr<dp::GpuProgram> program,
                          dp::Color const & color, float dz, bool hasNormals)
{
    program->Bind();

    GLFunctions::glBindBuffer(m_bufferId, gl_const::GLArrayBuffer);
    uint32_t const attributePosition = program->GetAttributeLocation("a_pos");
    ASSERT_NOT_EQUAL(attributePosition, -1, ());
    GLFunctions::glEnableVertexAttribute(attributePosition);
    GLFunctions::glVertexAttributePointer(attributePosition, kComponentsInVertex,
                                          gl_const::GLFloatType, false, 0, 0);

    if (hasNormals)
    {
        GLFunctions::glBindBuffer(m_bufferNormalsId, gl_const::GLArrayBuffer);
        uint32_t const attributeNormal = program->GetAttributeLocation("a_normal");
        ASSERT_NOT_EQUAL(attributeNormal, -1, ());
        GLFunctions::glEnableVertexAttribute(attributeNormal);
        GLFunctions::glVertexAttributePointer(attributeNormal, 3, gl_const::GLFloatType, false, 0, 0);
    }

    dp::UniformValuesStorage uniforms;
    math::Matrix<float, 4, 4> const modelTransform = CalculateTransform(screen, dz);
    uniforms.SetMatrix4x4Value("u_transform", modelTransform.m_data);
    glsl::vec4 const c = glsl::ToVec4(color);
    uniforms.SetFloatValue("u_color", c.r, c.g, c.b, c.a);
    dp::ApplyState(m_state, program);
    dp::ApplyUniforms(uniforms, program);
    GLFunctions::glDrawArrays(gl_const::GLTriangles, 0, m_vertices.size() / kComponentsInVertex);
}
Пример #2
0
void Arrow3d::Build(ref_ptr<dp::GpuProgram> prg)
{
  m_bufferId = GLFunctions::glGenBuffer();
  GLFunctions::glBindBuffer(m_bufferId, gl_const::GLArrayBuffer);

  m_attributePosition = prg->GetAttributeLocation("a_pos");
  ASSERT_NOT_EQUAL(m_attributePosition, -1, ());

  GLFunctions::glBufferData(gl_const::GLArrayBuffer, m_vertices.size() * sizeof(m_vertices[0]),
                            m_vertices.data(), gl_const::GLStaticDraw);

  m_bufferNormalsId = GLFunctions::glGenBuffer();
  GLFunctions::glBindBuffer(m_bufferNormalsId, gl_const::GLArrayBuffer);

  m_attributeNormal = prg->GetAttributeLocation("a_normal");
  ASSERT_NOT_EQUAL(m_attributeNormal, -1, ());

  GLFunctions::glBufferData(gl_const::GLArrayBuffer, m_normals.size() * sizeof(m_normals[0]),
                            m_normals.data(), gl_const::GLStaticDraw);

  GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer);
}