mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-02 20:56:27 +01:00
Record the opaque scene once and replay it for the depth prepass and the colour pass
This commit is contained in:
@@ -42,6 +42,11 @@ gl::frame_stream::~frame_stream()
|
||||
{
|
||||
release(slot);
|
||||
}
|
||||
for (auto &retired : m_retired)
|
||||
{
|
||||
if (!retired.empty())
|
||||
glDeleteBuffers(static_cast<GLsizei>(retired.size()), retired.data());
|
||||
}
|
||||
}
|
||||
|
||||
void gl::frame_stream::create(slot &Slot, GLsizeiptr Size)
|
||||
@@ -125,6 +130,13 @@ void gl::frame_stream::next_frame()
|
||||
}
|
||||
m_slot = (m_slot + 1) % FRAMES;
|
||||
wait(m_slots[m_slot]);
|
||||
// the buffers this slot outgrew in its last frame, which the gpu is done with now
|
||||
auto &retired{m_retired[m_slot]};
|
||||
if (!retired.empty())
|
||||
{
|
||||
glDeleteBuffers(static_cast<GLsizei>(retired.size()), retired.data());
|
||||
retired.clear();
|
||||
}
|
||||
m_fill = m_start;
|
||||
}
|
||||
|
||||
@@ -139,8 +151,12 @@ GLintptr gl::frame_stream::push(void const *Data, GLsizeiptr Size)
|
||||
if (size > current->size)
|
||||
{
|
||||
// a bigger buffer for the rest of the frame, starting after its header again. the fence of the slot (if any) was
|
||||
// waited for when the frame took the slot over, the old buffer is only read by the draws of this frame
|
||||
release(*current);
|
||||
// waited for when the frame took the slot over, the old buffer is only read by this frame, which may still bind it
|
||||
// for what it wrote there (a recorded draw drawn later), so it's kept, mapped, until the slot is taken over again
|
||||
m_retired[m_slot].push_back(current->buffer);
|
||||
current->buffer = 0;
|
||||
current->data = nullptr;
|
||||
current->size = 0;
|
||||
create(*current, size);
|
||||
++m_grows;
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ namespace gl
|
||||
// ends the frame: what was written so far goes with its fence, the next frame writes to the next buffer
|
||||
void next_frame();
|
||||
// appends Size bytes to the buffer of the frame and returns their offset. may replace the buffer of the frame with a
|
||||
// bigger one (generation() changes, buffer() tells which to bind); the draws issued before keep the old one until the
|
||||
// gpu is done with them
|
||||
// bigger one (generation() changes, buffer() tells which to bind); the old one stays until the frame is done with, so
|
||||
// what was written to it can still be bound and drawn from later in the frame
|
||||
GLintptr push(void const *Data, GLsizeiptr Size);
|
||||
|
||||
GLuint buffer() const
|
||||
@@ -83,6 +83,8 @@ namespace gl
|
||||
void wait(slot &Slot);
|
||||
|
||||
std::array<slot, FRAMES> m_slots;
|
||||
// buffers of the slots replaced by bigger ones in their frame, deleted when the slot is taken over again
|
||||
std::array<std::vector<GLuint>, FRAMES> m_retired;
|
||||
std::size_t m_slot = 0;
|
||||
GLsizeiptr m_alignment;
|
||||
bool m_mapped; // buffers made from now on are mapped
|
||||
|
||||
Reference in New Issue
Block a user