From c296c4eb3b47bc12492e2e70cae7283859ce9b82 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Mon, 14 Dec 2015 21:30:43 +0100 Subject: [PATCH] Fixed picking pass... again... --- src/Engine/Rendering/PickingPass.cpp | 30 +++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Engine/Rendering/PickingPass.cpp b/src/Engine/Rendering/PickingPass.cpp index d45c0322..148b272c 100644 --- a/src/Engine/Rendering/PickingPass.cpp +++ b/src/Engine/Rendering/PickingPass.cpp @@ -48,26 +48,31 @@ void PickingPass::Draw(RenderQueueCollection& rq) m_PickingColorsToEntity.clear(); PickingPassState* state = new PickingPassState(m_PickingBuffer.GetHandle()); - int r = 1; + int r = 0; int g = 0; //TODO: Render: Add code for more jobs than modeljobs. GLuint ShaderHandle = m_PickingProgram->GetHandle(); m_PickingProgram->Bind(); + std::map entityColors; + for (auto &job : rq.Forward) { auto modelJob = std::dynamic_pointer_cast(job); if (modelJob) { - //--------------- - //TODO: Renderer: IMPORTANT: Fixa detta så det inte loopar igenom listan varje frame. - //--------------- int pickColor[2] = { r, g }; - for (auto i : m_PickingColorsToEntity) { - if (modelJob->Entity == i.second) { - pickColor[0] = i.first.x; - pickColor[1] = i.first.y; - r -= 1; + auto color = entityColors.find(modelJob->Entity); + if (color != entityColors.end()) { + pickColor[0] = color->second[0]; + pickColor[1] = color->second[1]; + } else { + entityColors[modelJob->Entity] = glm::vec2(pickColor[0], pickColor[1]); + if (r + 10 > 255) { + r = 0; + g += 1; + } else { + r += 1; } } m_PickingColorsToEntity[glm::vec2(pickColor[0], pickColor[1])] = modelJob->Entity; @@ -82,11 +87,6 @@ void PickingPass::Draw(RenderQueueCollection& rq) glBindVertexArray(modelJob->Model->VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, nullptr, modelJob->StartIndex); - r += 1; - if (r > 255) { - r = 0; - g += 1; - } } } m_PickingBuffer.Unbind(); @@ -105,6 +105,8 @@ void PickingPass::Draw(RenderQueueCollection& rq) &m_PickingColorsToEntity); m_EventBroker->Publish(pickEvent); + + delete state; } void PickingPass::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const