Showing the changes to libraries/render/src/render/DrawStatus.cpp (1 of 8 files). Show all
Unified · Split
| @@ -68,7 +68,8 @@ const gpu::PipelinePointer DrawStatus::getDrawItemStatusPipeline() { · 67 unmodified lines | |||
| 68 | 68 | ||
| 69 | _drawItemStatusPosLoc = program->getUniforms().findLocation("inBoundPos"); | 69 | _drawItemStatusPosLoc = program->getUniforms().findLocation("inBoundPos"); |
| 70 | _drawItemStatusDimLoc = program->getUniforms().findLocation("inBoundDim"); | 70 | _drawItemStatusDimLoc = program->getUniforms().findLocation("inBoundDim"); |
| 71 | _drawItemStatusValueLoc = program->getUniforms().findLocation("inStatus"); | 71 | _drawItemStatusValue0Loc = program->getUniforms().findLocation("inStatus0"); |
| 72 | _drawItemStatusValue1Loc = program->getUniforms().findLocation("inStatus1"); | ||
| 72 | 73 | ||
| 73 | auto state = std::make_shared<gpu::State>(); | 74 | auto state = std::make_shared<gpu::State>(); |
| 74 | 75 | ||
| @@ -98,6 +99,8 @@ void DrawStatus::run(const SceneContextPointer& sceneContext, const RenderContex · 23 unmodified lines | |||
| 98 | assert(renderContext->args->_viewFrustum); | 99 | assert(renderContext->args->_viewFrustum); |
| 99 | RenderArgs* args = renderContext->args; | 100 | RenderArgs* args = renderContext->args; |
| 100 | auto& scene = sceneContext->_scene; | 101 | auto& scene = sceneContext->_scene; |
| 102 | const int NUM_STATUS_VEC4_PER_ITEM = 2; | ||
| 103 | const int VEC4_LENGTH = 4; | ||
| 101 | 104 | ||
| 102 | // FIrst thing, we collect the bound and the status for all the items we want to render | 105 | // FIrst thing, we collect the bound and the status for all the items we want to render |
| 103 | int nbItems = 0; | 106 | int nbItems = 0; |
| @@ -109,8 +112,8 @@ void DrawStatus::run(const SceneContextPointer& sceneContext, const RenderContex · 5 unmodified lines | |||
| 109 | _itemStatus = std::make_shared<gpu::Buffer>();; | 112 | _itemStatus = std::make_shared<gpu::Buffer>();; |
| 110 | } | 113 | } |
| 111 | 114 | ||
| 112 | _itemBounds->resize((inItems.size() * sizeof(AABox))); | 115 | _itemBounds->resize((inItems.size() * sizeof(AABox))); |
| 113 | _itemStatus->resize((inItems.size() * sizeof(glm::vec4))); | 116 | _itemStatus->resize((inItems.size() * NUM_STATUS_VEC4_PER_ITEM * sizeof(glm::vec4))); |
| 114 | AABox* itemAABox = reinterpret_cast<AABox*> (_itemBounds->editData()); | 117 | AABox* itemAABox = reinterpret_cast<AABox*> (_itemBounds->editData()); |
| 115 | glm::ivec4* itemStatus = reinterpret_cast<glm::ivec4*> (_itemStatus->editData()); | 118 | glm::ivec4* itemStatus = reinterpret_cast<glm::ivec4*> (_itemStatus->editData()); |
| 116 | for (auto& item : inItems) { | 119 | for (auto& item : inItems) { |
| @@ -121,11 +124,31 @@ void DrawStatus::run(const SceneContextPointer& sceneContext, const RenderContex · 4 unmodified lines | |||
| 121 | (*itemAABox).setBox(item.bounds.getCorner(), 0.1f); | 124 | (*itemAABox).setBox(item.bounds.getCorner(), 0.1f); |
| 122 | } | 125 | } |
| 123 | auto& itemScene = scene->getItem(item.id); | 126 | auto& itemScene = scene->getItem(item.id); |
| 124 | (*itemStatus) = itemScene.getStatusPackedValues(); | 127 | |
| 128 | auto itemStatusPointer = itemScene.getStatus(); | ||
| 129 | if (itemStatusPointer) { | ||
| 130 | // Query the current status values, this is where the statusGetter lambda get called | ||
| 131 | auto&& currentStatusValues = itemStatusPointer->getCurrentValues(); | ||
| 132 | int valueNum = 0; | ||
| 133 | for (int vec4Num = 0; vec4Num < NUM_STATUS_VEC4_PER_ITEM; vec4Num++) { | ||
| 134 | (*itemStatus) = glm::ivec4(Item::Status::Value::INVALID.getPackedData()); | ||
| 135 | for (int component = 0; component < VEC4_LENGTH; component++) { | ||
| 136 | valueNum = vec4Num * VEC4_LENGTH + component; | ||
| 137 | if (valueNum < (int)currentStatusValues.size()) { | ||
| 138 | (*itemStatus)[component] = currentStatusValues[valueNum].getPackedData(); | ||
| 139 | } | ||
| 140 | } | ||
| 141 | itemStatus++; | ||
| 142 | } | ||
| 143 | } else { | ||
| 144 | (*itemStatus) = glm::ivec4(Item::Status::Value::INVALID.getPackedData()); | ||
| 145 | itemStatus++; | ||
| 146 | (*itemStatus) = glm::ivec4(Item::Status::Value::INVALID.getPackedData()); | ||
| 147 | itemStatus++; | ||
| 148 | } | ||
| 125 | 149 | ||
| 126 | nbItems++; | 150 | nbItems++; |
| 127 | itemAABox++; | 151 | itemAABox++; |
| 128 | itemStatus++; | ||
| 129 | } | 152 | } |
| 130 | } | 153 | } |
| 131 | } | 154 | } |
| @@ -170,9 +193,9 @@ void DrawStatus::run(const SceneContextPointer& sceneContext, const RenderContex · 38 unmodified lines | |||
| 170 | for (int i = 0; i < nbItems; i++) { | 193 | for (int i = 0; i < nbItems; i++) { |
| 171 | batch._glUniform3fv(_drawItemStatusPosLoc, 1, (const float*) (itemAABox + i)); | 194 | batch._glUniform3fv(_drawItemStatusPosLoc, 1, (const float*) (itemAABox + i)); |
| 172 | batch._glUniform3fv(_drawItemStatusDimLoc, 1, ((const float*) (itemAABox + i)) + VEC3_ADRESS_OFFSET); | 195 | batch._glUniform3fv(_drawItemStatusDimLoc, 1, ((const float*) (itemAABox + i)) + VEC3_ADRESS_OFFSET); |
| 173 | batch._glUniform4iv(_drawItemStatusValueLoc, 1, (const int*) (itemStatus + i)); | 196 | batch._glUniform4iv(_drawItemStatusValue0Loc, 1, (const int*)(itemStatus + NUM_STATUS_VEC4_PER_ITEM * i)); |
| 174 | 197 | batch._glUniform4iv(_drawItemStatusValue1Loc, 1, (const int*)(itemStatus + NUM_STATUS_VEC4_PER_ITEM * i + 1)); | |
| 175 | batch.draw(gpu::TRIANGLES, 24, 0); | 198 | batch.draw(gpu::TRIANGLES, 24 * NUM_STATUS_VEC4_PER_ITEM, 0); |
| 176 | } | 199 | } |
| 177 | } | 200 | } |
| 178 | batch.setResourceTexture(0, 0); | 201 | batch.setResourceTexture(0, 0); |