2021-05-08 22:18:34 +02:00
|
|
|
/*
|
2021-05-29 12:38:28 +02:00
|
|
|
* Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
|
2021-05-08 22:18:34 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2021-12-16 20:32:38 +01:00
|
|
|
#include <LibSoftGPU/DepthBuffer.h>
|
2021-05-08 22:18:34 +02:00
|
|
|
|
2021-12-16 20:32:38 +01:00
|
|
|
namespace SoftGPU {
|
2021-05-08 22:18:34 +02:00
|
|
|
|
|
|
|
|
DepthBuffer::DepthBuffer(Gfx::IntSize const& size)
|
|
|
|
|
: m_size(size)
|
|
|
|
|
, m_data(new float[size.width() * size.height()])
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DepthBuffer::~DepthBuffer()
|
|
|
|
|
{
|
|
|
|
|
delete[] m_data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float* DepthBuffer::scanline(int y)
|
|
|
|
|
{
|
|
|
|
|
VERIFY(y >= 0 && y < m_size.height());
|
|
|
|
|
return &m_data[y * m_size.width()];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DepthBuffer::clear(float depth)
|
|
|
|
|
{
|
|
|
|
|
int num_entries = m_size.width() * m_size.height();
|
|
|
|
|
for (int i = 0; i < num_entries; ++i) {
|
|
|
|
|
m_data[i] = depth;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-27 19:00:16 +01:00
|
|
|
void DepthBuffer::clear(Gfx::IntRect bounds, float depth)
|
|
|
|
|
{
|
|
|
|
|
bounds.intersect({ 0, 0, m_size.width(), m_size.height() });
|
|
|
|
|
for (int y = bounds.top(); y <= bounds.bottom(); ++y)
|
|
|
|
|
for (int x = bounds.left(); x <= bounds.right(); ++x)
|
|
|
|
|
m_data[y * m_size.width() + x] = depth;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-08 22:18:34 +02:00
|
|
|
}
|