Beispiel #1
0
GLUSboolean update(GLUSfloat time)
{
	static GLfloat totalTime = 0.0f;

	static GLint previousInput = 0;
	static GLint currentInput = 1;
	static GLint currentOutput = 2;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnable(GL_CULL_FACE);

    if (!updateSphere(time))
    {
    	return GLUS_FALSE;
    }

    glDisable(GL_CULL_FACE);

    //
    // Simulation part.
    //

    glUseProgram(g_computeProgram.program);

    glUniform1f(g_deltaTimeLocation, time);

    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_BUFFER_COMP_VERTICES_IN_PREVIOUS, g_verticesBuffer[previousInput]);
    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_BUFFER_COMP_VERTICES_IN_CURRENT, g_verticesBuffer[currentInput]);
    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_BUFFER_COMP_VERTICES_OUT, g_verticesBuffer[currentOutput]);
    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_BUFFER_COMP_NORMALS_OUT, g_normalsBuffer);

    // Process all vertices.
    glDispatchCompute(1, 1, 1);

    // Make sure, all vertices and normals are written.
    glMemoryBarrier(GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT);

    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_BUFFER_COMP_VERTICES_IN_PREVIOUS, 0);
    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_BUFFER_COMP_VERTICES_IN_CURRENT, 0);
    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_BUFFER_COMP_VERTICES_OUT, 0);
    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_BUFFER_COMP_NORMALS_OUT, 0);

    //
    // Drawing part.
    //

    glUseProgram(g_program.program);

    glBindVertexArray(g_vao);

	glBindBuffer(GL_ARRAY_BUFFER, g_verticesBuffer[currentOutput]);
	glVertexAttribPointer(g_vertexLocation, 4, GL_FLOAT, GL_FALSE, 0, 0);

    glDrawElements(GL_TRIANGLES, g_numberIndicesPlane, GL_UNSIGNED_INT, 0);

    glBindVertexArray(0);

    // Output is next time input etc.

    previousInput = (previousInput + 1) % 3;
    currentInput = (currentInput + 1) % 3;
    currentOutput = (currentOutput + 1) % 3;

    // Update the total passed time.

    totalTime += time;

    // Reset after 10 seconds.
    if (totalTime >= 10.0f)
    {
        previousInput = 0;
        currentInput = 1;
        currentOutput = 2;

    	glBindBuffer(GL_SHADER_STORAGE_BUFFER, g_verticesBuffer[previousInput]);
    	glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, g_gridPlane.numberVertices * 4 * sizeof(GLfloat), g_gridPlane.vertices);

    	glBindBuffer(GL_SHADER_STORAGE_BUFFER, g_verticesBuffer[currentInput]);
    	glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, g_gridPlane.numberVertices * 4 * sizeof(GLfloat), g_gridPlane.vertices);

    	glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);

    	totalTime = 0.0f;
    }

    return GLUS_TRUE;
}
void GritObject::updateSphere (float r_)
{
    updateSphere(pos, r_);
}
void DebugAttachmentSystem::onFrameUpdate(const UpdateFrame & updateFrame)
{
    auto & imGuiSystem = world().systemRef<ImGuiSystem>();

    if (!imGuiSystem.showView("Debug Attachments"))
    {
        m_visibleNode->setVisible(false);
        m_obscuredNode->setVisible(false);
        return;
    }
    m_visibleNode->setVisible(true);
    m_obscuredNode->setVisible(false);

    size_t currentAttachmentIndex = 0;

    for (const auto & entityEntry : m_entities)
    {
        if (!entityEntry.active) continue;

        const auto   entity = world().entityById(entityEntry.id);
        const auto & equipment = entity.component<Equipment>();

        for (const auto & attachment : equipment.attachments())
        {
            auto transform = Transform3D::fromPose(attachment->worldPose());
            transform.setScale(
                entity.component<Transform3DComponent>().transform().scale());

            updateSphere(
                m_visibleNode->sphere(currentAttachmentIndex),
                attachment,
                transform);
            updateSphere(
                m_obscuredNode->sphere(currentAttachmentIndex),
                attachment,
                transform);

            updatePose(
                m_visibleNode->pose(currentAttachmentIndex),
                attachment,
                transform);
            updatePose(
                m_obscuredNode->pose(currentAttachmentIndex),
                attachment,
                transform);

            currentAttachmentIndex++;
        }
    }

    m_numAllocatedPrimitives =
        std::max(currentAttachmentIndex, m_numAllocatedPrimitives);

    for (; currentAttachmentIndex < m_numAllocatedPrimitives;
         currentAttachmentIndex++)
    {
        m_visibleNode->pose(currentAttachmentIndex).setVisible(false);
        m_obscuredNode->pose(currentAttachmentIndex).setVisible(false);
        m_visibleNode->sphere(currentAttachmentIndex).setVisible(false);
        m_obscuredNode->sphere(currentAttachmentIndex).setVisible(false);
    }
}
void GritObject::updateSphere (const Vector3 &pos_)
{
    updateSphere(pos_, r);
}