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