ladybird/Userland/Libraries/LibGL/SoftwareRasterizer.h

78 lines
2.1 KiB
C
Raw Normal View History

/*
* Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include "DepthBuffer.h"
#include "GL/gl.h"
#include "GLStruct.h"
#include "Tex/Texture2D.h"
#include "Tex/TextureUnit.h"
#include <AK/Array.h>
#include <AK/OwnPtr.h>
#include <LibGfx/Bitmap.h>
2021-11-27 21:00:16 +03:00
#include <LibGfx/Rect.h>
#include <LibGfx/Vector4.h>
namespace GL {
struct RasterizerOptions {
bool shade_smooth { true };
bool enable_depth_test { false };
2021-08-13 02:06:26 +03:00
bool enable_depth_write { true };
bool enable_alpha_test { false };
GLenum alpha_test_func { GL_ALWAYS };
float alpha_test_ref_value { 0 };
bool enable_blending { false };
GLenum blend_source_factor { GL_ONE };
GLenum blend_destination_factor { GL_ONE };
2021-08-13 15:03:39 +03:00
u32 color_mask { 0xffffffff };
2021-08-16 18:52:12 +03:00
float depth_min { 0 };
float depth_max { 1 };
2021-08-16 18:59:45 +03:00
GLenum depth_func { GL_LESS };
GLenum polygon_mode { GL_FILL };
FloatVector4 fog_color {
0.0f,
0.0f,
0.0f,
0.0f,
};
2021-08-24 18:17:28 +03:00
GLfloat fog_density { 1.0f };
2021-08-24 18:21:54 +03:00
GLenum fog_mode { GL_EXP };
GLboolean fog_enabled { false };
GLfloat fog_start { 0.0f };
GLfloat fog_end { 1.0f };
2021-11-27 21:00:16 +03:00
bool scissor_enabled { false };
Gfx::IntRect scissor_box;
2021-08-31 21:23:29 +03:00
GLenum draw_buffer { GL_BACK };
2021-08-31 21:50:01 +03:00
GLfloat depth_offset_factor { 0 };
GLfloat depth_offset_constant { 0 };
};
class SoftwareRasterizer final {
public:
SoftwareRasterizer(const Gfx::IntSize& min_size);
void submit_triangle(GLTriangle const& triangle, TextureUnit::BoundList const& bound_texture_units);
void resize(const Gfx::IntSize& min_size);
void clear_color(const FloatVector4&);
void clear_depth(float);
void blit(Gfx::Bitmap const&, int x, int y);
void blit_to(Gfx::Bitmap&);
void wait_for_all_threads() const;
void set_options(const RasterizerOptions&);
RasterizerOptions options() const { return m_options; }
2021-05-24 18:52:24 +03:00
Gfx::RGBA32 get_backbuffer_pixel(int x, int y);
float get_depthbuffer_value(int x, int y);
private:
RefPtr<Gfx::Bitmap> m_render_target;
OwnPtr<DepthBuffer> m_depth_buffer;
RasterizerOptions m_options;
};
}