1#include "Shading/SharedMemoryManager.h"
2#include "Base/Shader.h"
6static int lastBinding = 1;
142float &SharedMemoryItem::operator[](
int i)
244SharedMemoryManager::SharedMemoryManager()
246 glGenBuffers(1, &ssbo);
247 glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
248 glBufferData(GL_SHADER_STORAGE_BUFFER,
sizeof(
SharedMemoryItem), NULL, GL_DYNAMIC_DRAW);
249 ssboBinding = lastBinding++;
250 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, ssboBinding, ssbo);
251 glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
254SharedMemoryManager::~SharedMemoryManager()
256 glDeleteBuffers(1, &ssbo);
259void SharedMemoryManager::Clear()
262 sharedMemoryBlobs.clear();
265int SharedMemoryManager::AddItem()
268 sharedMemoryBlobs.push_back(blob);
274 return sharedMemoryBlobs.data() + id;
277void SharedMemoryManager::UpdateShader(
Shader *shader)
279 glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
280 glBufferData(GL_SHADER_STORAGE_BUFFER,
sizeof(
SharedMemoryItem) * sharedMemoryBlobs.size(), sharedMemoryBlobs.data(), GL_DYNAMIC_DRAW);
281 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, ssboBinding, ssbo);
282 glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
SharedMemoryItem ! A data structure to be passed to the GPU.