Beispiel #1
0
void Lights::load(GLBuffer& buffer, int bufferIdx, const glm::mat4& viewMatrix)
{
    buffer.bind(GL_UNIFORM_BUFFER, bufferIdx);
    buffer.setSubData(&m_lightCount, LIGHT_COUNT_OFFSET, 1, bufferIdx);
    for ( size_t i = 0; i < m_lights.size(); ++i )
    {
        LightInfo& info = m_lights[i];

        // compute light position in view coordinates
        glm::vec3 position = (viewMatrix * glm::vec4(info.position, 1.0)).xyz();

        // set buffer data
        buffer.setSubData(&position, LIGHT_ARRAY_OFFSET + i * LIGHT_ARRAY_STEP + LIGHT_ARRAY_POSITION_OFFSET, 1, bufferIdx);
        buffer.setSubData(&info.diffuse, LIGHT_ARRAY_OFFSET + i * LIGHT_ARRAY_STEP + LIGHT_ARRAY_DIFFUSE_OFFSET, 1, bufferIdx);
        buffer.setSubData(&info.specular, LIGHT_ARRAY_OFFSET + i * LIGHT_ARRAY_STEP + LIGHT_ARRAY_SPECULAR_OFFSET, 1, bufferIdx);
        buffer.setSubData(&info.ambient, LIGHT_ARRAY_OFFSET + i * LIGHT_ARRAY_STEP + LIGHT_ARRAY_AMBIENT_OFFSET, 1, bufferIdx);
    }
    GLBuffer::unbindBuffers(GL_UNIFORM_BUFFER);
}
Beispiel #2
0
bool Lights::loadLight(GLBuffer& buffer, int bufferIdx, const glm::mat4& viewMatrix, size_t idx)
{
    if ( idx < m_idxMap.size() && m_idxMap[idx] != INVALID_INDEX )
    {
        LightInfo& info = m_lights[m_idxMap[idx]];

        // compute light position in view coordinates
        glm::vec3 position = (viewMatrix * glm::vec4(info.position, 1.0)).xyz();

        // set buffer data
        buffer.bind(GL_UNIFORM_BUFFER, bufferIdx);
        buffer.setSubData(&position, LIGHT_ARRAY_OFFSET + m_idxMap[idx] * LIGHT_ARRAY_STEP + LIGHT_ARRAY_POSITION_OFFSET, 1, bufferIdx);
        buffer.setSubData(&info.diffuse, LIGHT_ARRAY_OFFSET + m_idxMap[idx] * LIGHT_ARRAY_STEP + LIGHT_ARRAY_DIFFUSE_OFFSET, 1, bufferIdx);
        buffer.setSubData(&info.specular, LIGHT_ARRAY_OFFSET + m_idxMap[idx] * LIGHT_ARRAY_STEP + LIGHT_ARRAY_SPECULAR_OFFSET, 1, bufferIdx);
        buffer.setSubData(&info.ambient, LIGHT_ARRAY_OFFSET + m_idxMap[idx] * LIGHT_ARRAY_STEP + LIGHT_ARRAY_AMBIENT_OFFSET, 1, bufferIdx);
        GLBuffer::unbindBuffers(GL_UNIFORM_BUFFER);
        
        return true;
    }
    return false;
}
Beispiel #3
0
void Lights::loadCount(GLBuffer& buffer, int bufferIdx)
{
    buffer.bind(GL_UNIFORM_BUFFER, bufferIdx);
    buffer.setSubData(&m_lightCount, LIGHT_COUNT_OFFSET, 1, bufferIdx);
    GLBuffer::unbindBuffers(GL_UNIFORM_BUFFER);
}