mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-18 12:39:18 +02:00
Add sky light, physical atmosphere, auto exposure and bloom to the GL 4.6 renderer
This commit is contained in:
51
gl/readback.cpp
Normal file
51
gl/readback.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "stdafx.h"
|
||||
#include "readback.h"
|
||||
|
||||
gl::readback::readback(GLsizeiptr size) : m_size(size) {}
|
||||
|
||||
gl::readback::~readback()
|
||||
{
|
||||
for (auto &slot : m_slots)
|
||||
{
|
||||
// fences first, they belong to the copies
|
||||
slot.copied.reset();
|
||||
if (slot.buffer != 0)
|
||||
glDeleteBuffers(1, &slot.buffer);
|
||||
}
|
||||
}
|
||||
|
||||
void gl::readback::push(GLuint Source, GLintptr Offset)
|
||||
{
|
||||
if (m_used >= SLOTS)
|
||||
return;
|
||||
|
||||
auto &slot{m_slots[(m_first + m_used) % SLOTS]};
|
||||
if (slot.buffer == 0)
|
||||
{
|
||||
glCreateBuffers(1, &slot.buffer);
|
||||
glNamedBufferStorage(slot.buffer, m_size, nullptr, GL_CLIENT_STORAGE_BIT);
|
||||
}
|
||||
glCopyNamedBufferSubData(Source, slot.buffer, Offset, 0, m_size);
|
||||
slot.copied = std::make_unique<fence>();
|
||||
++m_used;
|
||||
}
|
||||
|
||||
bool gl::readback::pop(void *Data)
|
||||
{
|
||||
bool result{false};
|
||||
// oldest first, as long as the gpu has finished the copies; the newest finished one ends in Data
|
||||
while (m_used > 0)
|
||||
{
|
||||
auto &slot{m_slots[m_first]};
|
||||
if (!slot.copied->is_signalled())
|
||||
break;
|
||||
|
||||
glGetNamedBufferSubData(slot.buffer, 0, m_size, Data);
|
||||
slot.copied.reset();
|
||||
result = true;
|
||||
|
||||
m_first = (m_first + 1) % SLOTS;
|
||||
--m_used;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user