daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 1 | // |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 2 | // Copyright (c) 2002-2016 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 7 | // ResourceManager.cpp: Implements the the ResourceManager classes, which handle allocation and |
| 8 | // lifetime of GL objects. |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 9 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 10 | #include "libANGLE/ResourceManager.h" |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 11 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 12 | #include "libANGLE/Buffer.h" |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 13 | #include "libANGLE/Fence.h" |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 14 | #include "libANGLE/Path.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 15 | #include "libANGLE/Program.h" |
| 16 | #include "libANGLE/Renderbuffer.h" |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 17 | #include "libANGLE/Sampler.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 18 | #include "libANGLE/Shader.h" |
| 19 | #include "libANGLE/Texture.h" |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 20 | #include "libANGLE/renderer/GLImplFactory.h" |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 21 | |
| 22 | namespace gl |
| 23 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 24 | |
| 25 | namespace |
| 26 | { |
| 27 | |
| 28 | template <typename ResourceType> |
| 29 | GLuint AllocateEmptyObject(HandleAllocator *handleAllocator, ResourceMap<ResourceType> *objectMap) |
| 30 | { |
| 31 | GLuint handle = handleAllocator->allocate(); |
| 32 | (*objectMap)[handle] = nullptr; |
| 33 | return handle; |
| 34 | } |
| 35 | |
| 36 | template <typename ResourceType, typename CreationFunction> |
| 37 | GLuint InsertObject(HandleAllocator *handleAllocator, |
| 38 | ResourceMap<ResourceType> *objectMap, |
| 39 | const CreationFunction &func) |
| 40 | { |
| 41 | GLuint handle = handleAllocator->allocate(); |
| 42 | (*objectMap)[handle] = func(handle); |
| 43 | return handle; |
| 44 | } |
| 45 | |
| 46 | template <typename ResourceType, typename DeletionFunction> |
| 47 | void DeleteObject(HandleAllocator *handleAllocator, |
| 48 | ResourceMap<ResourceType> *objectMap, |
| 49 | GLuint handle, |
| 50 | const DeletionFunction &deletionFunc) |
| 51 | { |
| 52 | auto objectIter = objectMap->find(handle); |
| 53 | if (objectIter == objectMap->end()) |
| 54 | { |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | if (objectIter->second != nullptr) |
| 59 | { |
| 60 | deletionFunc(objectIter->second); |
| 61 | } |
| 62 | |
| 63 | handleAllocator->release(objectIter->first); |
| 64 | objectMap->erase(objectIter); |
| 65 | } |
| 66 | |
| 67 | template <typename ResourceType> |
| 68 | ResourceType *GetObject(const ResourceMap<ResourceType> &objectMap, GLuint handle) |
| 69 | { |
| 70 | auto iter = objectMap.find(handle); |
| 71 | return iter != objectMap.end() ? iter->second : nullptr; |
| 72 | } |
| 73 | |
| 74 | } // anonymous namespace |
| 75 | |
| 76 | template <typename HandleAllocatorType> |
| 77 | ResourceManagerBase<HandleAllocatorType>::ResourceManagerBase() : mRefCount(1) |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 78 | { |
| 79 | } |
| 80 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 81 | template <typename HandleAllocatorType> |
| 82 | void ResourceManagerBase<HandleAllocatorType>::addRef() |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 83 | { |
| 84 | mRefCount++; |
| 85 | } |
| 86 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 87 | template <typename HandleAllocatorType> |
| 88 | void ResourceManagerBase<HandleAllocatorType>::release() |
daniel@transgaming.com | 0d25b00 | 2010-07-28 19:21:07 +0000 | [diff] [blame] | 89 | { |
| 90 | if (--mRefCount == 0) |
| 91 | { |
| 92 | delete this; |
| 93 | } |
| 94 | } |
| 95 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 96 | template <typename ResourceType, typename HandleAllocatorType> |
| 97 | TypedResourceManager<ResourceType, HandleAllocatorType>::~TypedResourceManager() |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 98 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 99 | while (!mObjectMap.empty()) |
| 100 | { |
| 101 | deleteObject(mObjectMap.begin()->first); |
| 102 | } |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 105 | template <typename ResourceType, typename HandleAllocatorType> |
| 106 | void TypedResourceManager<ResourceType, HandleAllocatorType>::deleteObject(GLuint handle) |
| 107 | { |
| 108 | DeleteObject(&this->mHandleAllocator, &mObjectMap, handle, |
| 109 | [](ResourceType *object) { object->release(); }); |
| 110 | } |
| 111 | |
| 112 | // Instantiations of ResourceManager |
| 113 | template class ResourceManagerBase<HandleAllocator>; |
| 114 | template class ResourceManagerBase<HandleRangeAllocator>; |
| 115 | template class TypedResourceManager<Buffer, HandleAllocator>; |
| 116 | template class TypedResourceManager<Texture, HandleAllocator>; |
| 117 | template class TypedResourceManager<Renderbuffer, HandleAllocator>; |
| 118 | template class TypedResourceManager<Sampler, HandleAllocator>; |
| 119 | template class TypedResourceManager<FenceSync, HandleAllocator>; |
| 120 | |
| 121 | GLuint BufferManager::createBuffer() |
| 122 | { |
| 123 | return AllocateEmptyObject(&mHandleAllocator, &mObjectMap); |
| 124 | } |
| 125 | |
| 126 | void BufferManager::deleteBuffer(GLuint buffer) |
| 127 | { |
| 128 | deleteObject(buffer); |
| 129 | } |
| 130 | |
| 131 | Buffer *BufferManager::getBuffer(GLuint handle) const |
| 132 | { |
| 133 | return GetObject(mObjectMap, handle); |
| 134 | } |
| 135 | |
| 136 | Buffer *BufferManager::checkBufferAllocation(rx::GLImplFactory *factory, GLuint handle) |
| 137 | { |
| 138 | if (handle == 0) |
| 139 | { |
| 140 | return nullptr; |
| 141 | } |
| 142 | |
| 143 | auto objectMapIter = mObjectMap.find(handle); |
| 144 | bool handleAllocated = (objectMapIter != mObjectMap.end()); |
| 145 | |
| 146 | if (handleAllocated && objectMapIter->second != nullptr) |
| 147 | { |
| 148 | return objectMapIter->second; |
| 149 | } |
| 150 | |
| 151 | Buffer *object = new Buffer(factory, handle); |
| 152 | object->addRef(); |
| 153 | |
| 154 | if (handleAllocated) |
| 155 | { |
| 156 | objectMapIter->second = object; |
| 157 | } |
| 158 | else |
| 159 | { |
| 160 | mHandleAllocator.reserve(handle); |
| 161 | mObjectMap[handle] = object; |
| 162 | } |
| 163 | |
| 164 | return object; |
| 165 | } |
| 166 | |
| 167 | bool BufferManager::isBufferGenerated(GLuint buffer) const |
| 168 | { |
| 169 | return buffer == 0 || mObjectMap.find(buffer) != mObjectMap.end(); |
| 170 | } |
| 171 | |
| 172 | ShaderProgramManager::~ShaderProgramManager() |
| 173 | { |
| 174 | while (!mPrograms.empty()) |
| 175 | { |
| 176 | deleteProgram(mPrograms.begin()->first); |
| 177 | } |
| 178 | while (!mShaders.empty()) |
| 179 | { |
| 180 | deleteShader(mShaders.begin()->first); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | GLuint ShaderProgramManager::createShader(rx::GLImplFactory *factory, |
| 185 | const gl::Limitations &rendererLimitations, |
| 186 | GLenum type) |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 187 | { |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 188 | ASSERT(type == GL_VERTEX_SHADER || type == GL_FRAGMENT_SHADER || type == GL_COMPUTE_SHADER); |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 189 | GLuint handle = mHandleAllocator.allocate(); |
| 190 | mShaders[handle] = new Shader(this, factory, rendererLimitations, type, handle); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 191 | return handle; |
| 192 | } |
| 193 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 194 | void ShaderProgramManager::deleteShader(GLuint shader) |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 195 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 196 | deleteObject(&mShaders, shader); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 199 | Shader *ShaderProgramManager::getShader(GLuint handle) const |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 200 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 201 | return GetObject(mShaders, handle); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 204 | GLuint ShaderProgramManager::createProgram(rx::GLImplFactory *factory) |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 205 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 206 | GLuint handle = mHandleAllocator.allocate(); |
| 207 | mPrograms[handle] = new Program(factory, this, handle); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 208 | return handle; |
| 209 | } |
| 210 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 211 | void ShaderProgramManager::deleteProgram(GLuint program) |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 212 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 213 | deleteObject(&mPrograms, program); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 214 | } |
| 215 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 216 | Program *ShaderProgramManager::getProgram(GLuint handle) const |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 217 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 218 | return GetObject(mPrograms, handle); |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 219 | } |
| 220 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 221 | template <typename ObjectType> |
| 222 | void ShaderProgramManager::deleteObject(ResourceMap<ObjectType> *objectMap, GLuint id) |
| 223 | { |
| 224 | auto iter = objectMap->find(id); |
| 225 | if (iter == objectMap->end()) |
| 226 | { |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | auto object = iter->second; |
| 231 | if (object->getRefCount() == 0) |
| 232 | { |
| 233 | mHandleAllocator.release(id); |
| 234 | SafeDelete(object); |
| 235 | objectMap->erase(iter); |
| 236 | } |
| 237 | else |
| 238 | { |
| 239 | object->flagForDeletion(); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | GLuint TextureManager::createTexture() |
| 244 | { |
| 245 | return AllocateEmptyObject(&mHandleAllocator, &mObjectMap); |
| 246 | } |
| 247 | |
| 248 | void TextureManager::deleteTexture(GLuint texture) |
| 249 | { |
| 250 | deleteObject(texture); |
| 251 | } |
| 252 | |
| 253 | Texture *TextureManager::getTexture(GLuint handle) const |
| 254 | { |
| 255 | ASSERT(GetObject(mObjectMap, 0) == nullptr); |
| 256 | return GetObject(mObjectMap, handle); |
| 257 | } |
| 258 | |
| 259 | Texture *TextureManager::checkTextureAllocation(rx::GLImplFactory *factory, |
| 260 | GLuint handle, |
| 261 | GLenum type) |
| 262 | { |
| 263 | if (handle == 0) |
| 264 | { |
| 265 | return nullptr; |
| 266 | } |
| 267 | |
| 268 | auto objectMapIter = mObjectMap.find(handle); |
| 269 | bool handleAllocated = (objectMapIter != mObjectMap.end()); |
| 270 | |
| 271 | if (handleAllocated && objectMapIter->second != nullptr) |
| 272 | { |
| 273 | return objectMapIter->second; |
| 274 | } |
| 275 | |
| 276 | Texture *object = new Texture(factory, handle, type); |
| 277 | object->addRef(); |
| 278 | |
| 279 | if (handleAllocated) |
| 280 | { |
| 281 | objectMapIter->second = object; |
| 282 | } |
| 283 | else |
| 284 | { |
| 285 | mHandleAllocator.reserve(handle); |
| 286 | mObjectMap[handle] = object; |
| 287 | } |
| 288 | |
| 289 | return object; |
| 290 | } |
| 291 | |
| 292 | bool TextureManager::isTextureGenerated(GLuint texture) const |
| 293 | { |
| 294 | return texture == 0 || mObjectMap.find(texture) != mObjectMap.end(); |
| 295 | } |
| 296 | |
| 297 | GLuint RenderbufferManager::createRenderbuffer() |
| 298 | { |
| 299 | return AllocateEmptyObject(&mHandleAllocator, &mObjectMap); |
| 300 | } |
| 301 | |
| 302 | void RenderbufferManager::deleteRenderbuffer(GLuint renderbuffer) |
| 303 | { |
| 304 | deleteObject(renderbuffer); |
| 305 | } |
| 306 | |
| 307 | Renderbuffer *RenderbufferManager::getRenderbuffer(GLuint handle) |
| 308 | { |
| 309 | return GetObject(mObjectMap, handle); |
| 310 | } |
| 311 | |
| 312 | Renderbuffer *RenderbufferManager::checkRenderbufferAllocation(rx::GLImplFactory *factory, |
| 313 | GLuint handle) |
| 314 | { |
| 315 | if (handle == 0) |
| 316 | { |
| 317 | return nullptr; |
| 318 | } |
| 319 | |
| 320 | auto objectMapIter = mObjectMap.find(handle); |
| 321 | bool handleAllocated = (objectMapIter != mObjectMap.end()); |
| 322 | |
| 323 | if (handleAllocated && objectMapIter->second != nullptr) |
| 324 | { |
| 325 | return objectMapIter->second; |
| 326 | } |
| 327 | |
| 328 | Renderbuffer *object = new Renderbuffer(factory->createRenderbuffer(), handle); |
| 329 | object->addRef(); |
| 330 | |
| 331 | if (handleAllocated) |
| 332 | { |
| 333 | objectMapIter->second = object; |
| 334 | } |
| 335 | else |
| 336 | { |
| 337 | mHandleAllocator.reserve(handle); |
| 338 | mObjectMap[handle] = object; |
| 339 | } |
| 340 | |
| 341 | return object; |
| 342 | } |
| 343 | |
| 344 | bool RenderbufferManager::isRenderbufferGenerated(GLuint renderbuffer) const |
| 345 | { |
| 346 | return renderbuffer == 0 || mObjectMap.find(renderbuffer) != mObjectMap.end(); |
| 347 | } |
| 348 | |
| 349 | GLuint SamplerManager::createSampler() |
| 350 | { |
| 351 | return AllocateEmptyObject(&mHandleAllocator, &mObjectMap); |
| 352 | } |
| 353 | |
| 354 | void SamplerManager::deleteSampler(GLuint sampler) |
| 355 | { |
| 356 | deleteObject(sampler); |
| 357 | } |
| 358 | |
| 359 | Sampler *SamplerManager::getSampler(GLuint handle) |
| 360 | { |
| 361 | return GetObject(mObjectMap, handle); |
| 362 | } |
| 363 | |
| 364 | Sampler *SamplerManager::checkSamplerAllocation(rx::GLImplFactory *factory, GLuint handle) |
| 365 | { |
| 366 | if (handle == 0) |
| 367 | { |
| 368 | return nullptr; |
| 369 | } |
| 370 | |
| 371 | auto objectMapIter = mObjectMap.find(handle); |
| 372 | bool handleAllocated = (objectMapIter != mObjectMap.end()); |
| 373 | |
| 374 | if (handleAllocated && objectMapIter->second != nullptr) |
| 375 | { |
| 376 | return objectMapIter->second; |
| 377 | } |
| 378 | |
| 379 | Sampler *object = new Sampler(factory, handle); |
| 380 | object->addRef(); |
| 381 | |
| 382 | if (handleAllocated) |
| 383 | { |
| 384 | objectMapIter->second = object; |
| 385 | } |
| 386 | else |
| 387 | { |
| 388 | mHandleAllocator.reserve(handle); |
| 389 | mObjectMap[handle] = object; |
| 390 | } |
| 391 | |
| 392 | return object; |
| 393 | } |
| 394 | |
| 395 | bool SamplerManager::isSampler(GLuint sampler) |
| 396 | { |
| 397 | return mObjectMap.find(sampler) != mObjectMap.end(); |
| 398 | } |
| 399 | |
| 400 | GLuint FenceSyncManager::createFenceSync(rx::GLImplFactory *factory) |
| 401 | { |
| 402 | struct fenceSyncAllocator |
| 403 | { |
| 404 | fenceSyncAllocator(rx::GLImplFactory *factory) : factory(factory) {} |
| 405 | |
| 406 | rx::GLImplFactory *factory; |
| 407 | |
| 408 | FenceSync *operator()(GLuint handle) const |
| 409 | { |
| 410 | FenceSync *fenceSync = new FenceSync(factory->createFenceSync(), handle); |
| 411 | fenceSync->addRef(); |
| 412 | return fenceSync; |
| 413 | } |
| 414 | }; |
| 415 | |
| 416 | return InsertObject(&mHandleAllocator, &mObjectMap, fenceSyncAllocator(factory)); |
| 417 | } |
| 418 | |
| 419 | void FenceSyncManager::deleteFenceSync(GLuint fenceSync) |
| 420 | { |
| 421 | deleteObject(fenceSync); |
| 422 | } |
| 423 | |
| 424 | FenceSync *FenceSyncManager::getFenceSync(GLuint handle) |
| 425 | { |
| 426 | return GetObject(mObjectMap, handle); |
| 427 | } |
| 428 | |
| 429 | ErrorOrResult<GLuint> PathManager::createPaths(rx::GLImplFactory *factory, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 430 | { |
| 431 | // Allocate client side handles. |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 432 | const GLuint client = mHandleAllocator.allocateRange(static_cast<GLuint>(range)); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 433 | if (client == HandleRangeAllocator::kInvalidHandle) |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 434 | return Error(GL_OUT_OF_MEMORY, "Failed to allocate path handle range."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 435 | |
| 436 | const auto &paths = factory->createPaths(range); |
| 437 | if (paths.empty()) |
| 438 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 439 | mHandleAllocator.releaseRange(client, range); |
| 440 | return Error(GL_OUT_OF_MEMORY, "Failed to allocate path objects."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 441 | } |
| 442 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 443 | auto hint = mPaths.begin(); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 444 | |
| 445 | for (GLsizei i = 0; i < range; ++i) |
| 446 | { |
| 447 | const auto impl = paths[static_cast<unsigned>(i)]; |
| 448 | const auto id = client + i; |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 449 | hint = mPaths.insert(hint, std::make_pair(id, new Path(impl))); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 450 | } |
| 451 | return client; |
| 452 | } |
| 453 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 454 | void PathManager::deletePaths(GLuint first, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 455 | { |
| 456 | for (GLsizei i = 0; i < range; ++i) |
| 457 | { |
| 458 | const auto id = first + i; |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 459 | const auto it = mPaths.find(id); |
| 460 | if (it == mPaths.end()) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 461 | continue; |
| 462 | Path *p = it->second; |
| 463 | delete p; |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 464 | mPaths.erase(it); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 465 | } |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 466 | mHandleAllocator.releaseRange(first, static_cast<GLuint>(range)); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 467 | } |
| 468 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 469 | Path *PathManager::getPath(GLuint handle) const |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 470 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 471 | auto iter = mPaths.find(handle); |
| 472 | return iter != mPaths.end() ? iter->second : nullptr; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 473 | } |
| 474 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 475 | bool PathManager::hasPath(GLuint handle) const |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 476 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 477 | return mHandleAllocator.isUsed(handle); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 480 | PathManager::~PathManager() |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 481 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 482 | for (auto path : mPaths) |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 483 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame^] | 484 | SafeDelete(path.second); |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 485 | } |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 486 | } |
| 487 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 488 | } // namespace gl |