| 401 | } |
| 402 | |
| 403 | void GL46Engine::EnableSBuffers(Shader const* shader, GLuint program) |
| 404 | { |
| 405 | // Configure atomic counter buffer objects used by the shader. |
| 406 | auto const& atomicCounters = shader->GetData(Shader::AtomicCounterShaderDataLookup); |
| 407 | auto const& atomicCounterBuffers = shader->GetData(Shader::AtomicCounterBufferShaderDataLookup); |
| 408 | for (uint32_t acbIndex = 0; acbIndex < atomicCounterBuffers.size(); ++acbIndex) |
| 409 | { |
| 410 | auto const& acb = atomicCounterBuffers[acbIndex]; |
| 411 | |
| 412 | // Allocate a new raw buffer? |
| 413 | if (acbIndex >= mAtomicCounterRawBuffers.size()) |
| 414 | { |
| 415 | mAtomicCounterRawBuffers.push_back(nullptr); |
| 416 | } |
| 417 | |
| 418 | // Look at the current raw buffer defined at this index. Could be |
| 419 | // nullptr if a new location was just inserted. |
| 420 | auto& rawBuffer = mAtomicCounterRawBuffers[acbIndex]; |
| 421 | |
| 422 | // If the raw buffer is not large enough, then unbind old one and |
| 423 | // ready to create new one. |
| 424 | if (rawBuffer && (acb.numBytes > static_cast<int32_t>(rawBuffer->GetNumBytes()))) |
| 425 | { |
| 426 | Unbind(rawBuffer.get()); |
| 427 | rawBuffer = nullptr; |
| 428 | } |
| 429 | |
| 430 | // Find the currently mapped GL4AtomicCounterBuffer. |
| 431 | GL46AtomicCounterBuffer* gl4ACB = nullptr; |
| 432 | if (rawBuffer) |
| 433 | { |
| 434 | gl4ACB = static_cast<GL46AtomicCounterBuffer*>(Get(rawBuffer)); |
| 435 | } |
| 436 | else |
| 437 | { |
| 438 | // By definition, RawBuffer contains 4-byte elements. We do not |
| 439 | // need CPU-side storage, but we must be able to copy values |
| 440 | // between buffers. |
| 441 | rawBuffer = std::make_shared<RawBuffer>((acb.numBytes + 3) / 4, false); |
| 442 | rawBuffer->SetUsage(Resource::Usage::DYNAMIC_UPDATE); |
| 443 | |
| 444 | // Do a manual Bind operation because this is a special mapping |
| 445 | // from RawBuffer to GL4AtomicCounterBuffer. |
| 446 | auto temp = GL46AtomicCounterBuffer::Create(mGEObjectCreator, rawBuffer.get()); |
| 447 | mGOMapMutex.lock(); |
| 448 | mGOMap.insert(std::make_pair(rawBuffer.get(), temp)); |
| 449 | mGOMapMutex.unlock(); |
| 450 | gl4ACB = static_cast<GL46AtomicCounterBuffer*>(temp.get()); |
| 451 | } |
| 452 | |
| 453 | // TODO: ShaderStorage blocks have a glShaderStorageBlockBinding() |
| 454 | // call. Uniform blocks have a glUniforBlockBinding() call. Is there |
| 455 | // something equivalent for atomic counters buffers? |
| 456 | |
| 457 | // Bind this atomic counter buffer |
| 458 | gl4ACB->AttachToUnit(acb.bindPoint); |
| 459 | } |
| 460 |
nothing calls this directly
no test coverage detected