mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-24 13:35:12 +00:00
LibGL: Add depth buffer class
This commit is contained in:
parent
a8fc4be47a
commit
608f81e6c2
Notes:
sideshowbarker
2024-07-18 18:26:24 +09:00
Author: https://github.com/sunverwerth Commit: https://github.com/SerenityOS/serenity/commit/608f81e6c22 Pull-request: https://github.com/SerenityOS/serenity/pull/6973
3 changed files with 64 additions and 0 deletions
|
@ -7,6 +7,7 @@ set(SOURCES
|
|||
GLVert.cpp
|
||||
SoftwareGLContext.cpp
|
||||
SoftwareRasterizer.cpp
|
||||
DepthBuffer.cpp
|
||||
)
|
||||
|
||||
serenity_lib(LibGL gl)
|
||||
|
|
36
Userland/Libraries/LibGL/DepthBuffer.cpp
Normal file
36
Userland/Libraries/LibGL/DepthBuffer.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@gmx.de>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "DepthBuffer.h"
|
||||
|
||||
namespace GL {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
27
Userland/Libraries/LibGL/DepthBuffer.h
Normal file
27
Userland/Libraries/LibGL/DepthBuffer.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@gmx.de>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibGfx/Size.h>
|
||||
|
||||
namespace GL {
|
||||
|
||||
class DepthBuffer final {
|
||||
public:
|
||||
DepthBuffer(Gfx::IntSize const&);
|
||||
~DepthBuffer();
|
||||
|
||||
float* scanline(int y);
|
||||
|
||||
void clear(float depth);
|
||||
|
||||
private:
|
||||
Gfx::IntSize m_size;
|
||||
float* m_data { nullptr };
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue