Looks up an object with the given id. If found, makes a binding function.
| 143 | |
| 144 | // Looks up an object with the given id. If found, makes a binding function. |
| 145 | Status MakeBindingFunc(const Object& object, uint32_t id, |
| 146 | const ObjectManager& objects, |
| 147 | std::function<Status()>* binding_func) { |
| 148 | const uint32_t binding = object.binding; |
| 149 | switch (object.object_type) { |
| 150 | case ObjectType::BUFFER: { |
| 151 | auto ptr = objects.FindBuffer(id); |
| 152 | if (!ptr) { |
| 153 | return NotFoundError(absl::StrCat("Buffer ", id, " is not found")); |
| 154 | } |
| 155 | |
| 156 | // Validate buffer. |
| 157 | size_t size_in_bytes = ByteSizeOf(object); |
| 158 | // TODO(akulik): make comparison != instead of < |
| 159 | if (ptr->bytes_size() < size_in_bytes) { |
| 160 | return FailedPreconditionError( |
| 161 | absl::StrCat("Buffer ", id, " size in bytes ", ptr->bytes_size(), |
| 162 | " < requested size_in_bytes ", size_in_bytes)); |
| 163 | } |
| 164 | *binding_func = [=]() { return ptr->BindToIndex(binding); }; |
| 165 | break; |
| 166 | } |
| 167 | case ObjectType::TEXTURE: { |
| 168 | auto ptr = objects.FindTexture(id); |
| 169 | if (!ptr) { |
| 170 | return NotFoundError(absl::StrCat("Texture ", id, " is not found")); |
| 171 | } |
| 172 | *binding_func = [=]() { return ptr->BindAsReadWriteImage(binding); }; |
| 173 | break; |
| 174 | } |
| 175 | case ObjectType::UNKNOWN: |
| 176 | return InvalidArgumentError("Unknown object type"); |
| 177 | } |
| 178 | return OkStatus(); |
| 179 | } |
| 180 | |
| 181 | } // namespace |
| 182 |
no test coverage detected