| 75 | } |
| 76 | |
| 77 | void LuxCoreApp::RefreshRenderingTexture() { |
| 78 | const unsigned int filmWidth = session->GetFilm().GetWidth(); |
| 79 | const unsigned int filmHeight = session->GetFilm().GetHeight(); |
| 80 | const float *pixels = session->GetFilm().GetChannel<float>(Film::CHANNEL_IMAGEPIPELINE, imagePipelineIndex); |
| 81 | |
| 82 | if (currentTool == TOOL_OBJECT_SELECTION) { |
| 83 | // Allocate the selectionBuffer if needed |
| 84 | if (!selectionBuffer || (selectionFilmWidth != filmWidth) || (selectionFilmHeight != filmHeight)) { |
| 85 | delete[] selectionBuffer; |
| 86 | selectionFilmWidth = filmWidth; |
| 87 | selectionFilmHeight = filmHeight; |
| 88 | selectionBuffer = new float[selectionFilmWidth * selectionFilmHeight * 3]; |
| 89 | } |
| 90 | |
| 91 | // Get the mouse coordinates |
| 92 | int frameBufferWidth, frameBufferHeight; |
| 93 | glfwGetFramebufferSize(window, &frameBufferWidth, &frameBufferHeight); |
| 94 | |
| 95 | const ImVec2 imGuiScale(filmWidth / (float)frameBufferWidth, filmHeight / (float)frameBufferHeight); |
| 96 | const int mouseX = Floor2Int(ImGui::GetIO().MousePos.x * imGuiScale.x); |
| 97 | const int mouseY = Floor2Int((frameBufferHeight - ImGui::GetIO().MousePos.y - 1) * imGuiScale.y); |
| 98 | |
| 99 | // Get the selected object ID |
| 100 | const unsigned int *objIDpixels = session->GetFilm().GetChannel<unsigned int>(Film::CHANNEL_OBJECT_ID); |
| 101 | // 0xffffffffu is LuxRays NULL_INDEX |
| 102 | unsigned int objID = 0xffffffffu; |
| 103 | if ((mouseX >= 0) && (mouseX < (int)selectionFilmWidth) && |
| 104 | (mouseY >= 0) && (mouseY < (int)selectionFilmHeight)) |
| 105 | objID = objIDpixels[mouseX + mouseY * selectionFilmWidth]; |
| 106 | |
| 107 | // 0xffffffffu is LuxRays NULL_INDEX |
| 108 | if (objID != 0xffffffffu) { |
| 109 | // Blend the current selection over the rendering |
| 110 | for (unsigned int y = 0; y < filmHeight; ++y) { |
| 111 | for (unsigned int x = 0; x < filmWidth; ++x) { |
| 112 | const unsigned int index = x + y * selectionFilmWidth; |
| 113 | const unsigned int index3 = index * 3; |
| 114 | |
| 115 | if (objIDpixels[index] == objID) { |
| 116 | selectionBuffer[index3] = Lerp(.5f, pixels[index3], 1.f); |
| 117 | selectionBuffer[index3 + 1] = Lerp(.5f, pixels[index3 + 1], 1.f); |
| 118 | selectionBuffer[index3 + 2] = pixels[index3 + 2]; |
| 119 | } else { |
| 120 | selectionBuffer[index3] = pixels[index3]; |
| 121 | selectionBuffer[index3 + 1] = pixels[index3 + 1]; |
| 122 | selectionBuffer[index3 + 2] = pixels[index3 + 2]; |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | pixels = selectionBuffer; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | glBindTexture(GL_TEXTURE_2D, renderFrameBufferTexID); |
| 132 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, filmWidth, filmHeight, 0, GL_RGB, GL_FLOAT, pixels); |
| 133 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, renderFrameBufferTexMinFilter); |
| 134 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, renderFrameBufferTexMagFilter); |
nothing calls this directly
no test coverage detected