LibGL+LibGPU+LibSoftGPU: Move Enums.h to LibGPU

This commit is contained in:
Stephan Unverwerth 2022-03-15 01:11:58 +01:00 committed by Andreas Kling
parent ac033dd9b6
commit 24d420312c
Notes: sideshowbarker 2024-07-17 14:23:37 +09:00
6 changed files with 198 additions and 197 deletions

View File

@ -15,11 +15,11 @@
#include <AK/Variant.h>
#include <AK/Vector.h>
#include <LibGL/GLContext.h>
#include <LibGPU/Enums.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Painter.h>
#include <LibGfx/Vector4.h>
#include <LibSoftGPU/Device.h>
#include <LibSoftGPU/Enums.h>
#include <LibSoftGPU/ImageFormat.h>
__attribute__((visibility("hidden"))) GL::GLContext* g_gl_context;
@ -359,21 +359,21 @@ void GLContext::gl_end()
sync_device_config();
SoftGPU::PrimitiveType primitive_type;
GPU::PrimitiveType primitive_type;
switch (m_current_draw_mode) {
case GL_TRIANGLES:
primitive_type = SoftGPU::PrimitiveType::Triangles;
primitive_type = GPU::PrimitiveType::Triangles;
break;
case GL_TRIANGLE_STRIP:
case GL_QUAD_STRIP:
primitive_type = SoftGPU::PrimitiveType::TriangleStrip;
primitive_type = GPU::PrimitiveType::TriangleStrip;
break;
case GL_TRIANGLE_FAN:
case GL_POLYGON:
primitive_type = SoftGPU::PrimitiveType::TriangleFan;
primitive_type = GPU::PrimitiveType::TriangleFan;
break;
case GL_QUADS:
primitive_type = SoftGPU::PrimitiveType::Quads;
primitive_type = GPU::PrimitiveType::Quads;
break;
default:
VERIFY_NOT_REACHED();
@ -1036,7 +1036,7 @@ void GLContext::gl_front_face(GLenum face)
m_front_face = face;
auto rasterizer_options = m_rasterizer.options();
rasterizer_options.front_face = (face == GL_CW) ? SoftGPU::WindingOrder::Clockwise : SoftGPU::WindingOrder::CounterClockwise;
rasterizer_options.front_face = (face == GL_CW) ? GPU::WindingOrder::Clockwise : GPU::WindingOrder::CounterClockwise;
m_rasterizer.set_options(rasterizer_options);
}
@ -1266,27 +1266,27 @@ void GLContext::gl_blend_func(GLenum src_factor, GLenum dst_factor)
{
switch (factor) {
case GL_ZERO:
return SoftGPU::BlendFactor::Zero;
return GPU::BlendFactor::Zero;
case GL_ONE:
return SoftGPU::BlendFactor::One;
return GPU::BlendFactor::One;
case GL_SRC_ALPHA:
return SoftGPU::BlendFactor::SrcAlpha;
return GPU::BlendFactor::SrcAlpha;
case GL_ONE_MINUS_SRC_ALPHA:
return SoftGPU::BlendFactor::OneMinusSrcAlpha;
return GPU::BlendFactor::OneMinusSrcAlpha;
case GL_SRC_COLOR:
return SoftGPU::BlendFactor::SrcColor;
return GPU::BlendFactor::SrcColor;
case GL_ONE_MINUS_SRC_COLOR:
return SoftGPU::BlendFactor::OneMinusSrcColor;
return GPU::BlendFactor::OneMinusSrcColor;
case GL_DST_ALPHA:
return SoftGPU::BlendFactor::DstAlpha;
return GPU::BlendFactor::DstAlpha;
case GL_ONE_MINUS_DST_ALPHA:
return SoftGPU::BlendFactor::OneMinusDstAlpha;
return GPU::BlendFactor::OneMinusDstAlpha;
case GL_DST_COLOR:
return SoftGPU::BlendFactor::DstColor;
return GPU::BlendFactor::DstColor;
case GL_ONE_MINUS_DST_COLOR:
return SoftGPU::BlendFactor::OneMinusDstColor;
return GPU::BlendFactor::OneMinusDstColor;
case GL_SRC_ALPHA_SATURATE:
return SoftGPU::BlendFactor::SrcAlphaSaturate;
return GPU::BlendFactor::SrcAlphaSaturate;
default:
VERIFY_NOT_REACHED();
}
@ -1324,28 +1324,28 @@ void GLContext::gl_alpha_func(GLenum func, GLclampf ref)
switch (func) {
case GL_NEVER:
options.alpha_test_func = SoftGPU::AlphaTestFunction::Never;
options.alpha_test_func = GPU::AlphaTestFunction::Never;
break;
case GL_ALWAYS:
options.alpha_test_func = SoftGPU::AlphaTestFunction::Always;
options.alpha_test_func = GPU::AlphaTestFunction::Always;
break;
case GL_LESS:
options.alpha_test_func = SoftGPU::AlphaTestFunction::Less;
options.alpha_test_func = GPU::AlphaTestFunction::Less;
break;
case GL_LEQUAL:
options.alpha_test_func = SoftGPU::AlphaTestFunction::LessOrEqual;
options.alpha_test_func = GPU::AlphaTestFunction::LessOrEqual;
break;
case GL_EQUAL:
options.alpha_test_func = SoftGPU::AlphaTestFunction::Equal;
options.alpha_test_func = GPU::AlphaTestFunction::Equal;
break;
case GL_NOTEQUAL:
options.alpha_test_func = SoftGPU::AlphaTestFunction::NotEqual;
options.alpha_test_func = GPU::AlphaTestFunction::NotEqual;
break;
case GL_GEQUAL:
options.alpha_test_func = SoftGPU::AlphaTestFunction::GreaterOrEqual;
options.alpha_test_func = GPU::AlphaTestFunction::GreaterOrEqual;
break;
case GL_GREATER:
options.alpha_test_func = SoftGPU::AlphaTestFunction::Greater;
options.alpha_test_func = GPU::AlphaTestFunction::Greater;
break;
default:
VERIFY_NOT_REACHED();
@ -2301,28 +2301,28 @@ void GLContext::gl_depth_func(GLenum func)
switch (func) {
case GL_NEVER:
options.depth_func = SoftGPU::DepthTestFunction::Never;
options.depth_func = GPU::DepthTestFunction::Never;
break;
case GL_ALWAYS:
options.depth_func = SoftGPU::DepthTestFunction::Always;
options.depth_func = GPU::DepthTestFunction::Always;
break;
case GL_LESS:
options.depth_func = SoftGPU::DepthTestFunction::Less;
options.depth_func = GPU::DepthTestFunction::Less;
break;
case GL_LEQUAL:
options.depth_func = SoftGPU::DepthTestFunction::LessOrEqual;
options.depth_func = GPU::DepthTestFunction::LessOrEqual;
break;
case GL_EQUAL:
options.depth_func = SoftGPU::DepthTestFunction::Equal;
options.depth_func = GPU::DepthTestFunction::Equal;
break;
case GL_NOTEQUAL:
options.depth_func = SoftGPU::DepthTestFunction::NotEqual;
options.depth_func = GPU::DepthTestFunction::NotEqual;
break;
case GL_GEQUAL:
options.depth_func = SoftGPU::DepthTestFunction::GreaterOrEqual;
options.depth_func = GPU::DepthTestFunction::GreaterOrEqual;
break;
case GL_GREATER:
options.depth_func = SoftGPU::DepthTestFunction::Greater;
options.depth_func = GPU::DepthTestFunction::Greater;
break;
default:
VERIFY_NOT_REACHED();
@ -2467,14 +2467,14 @@ void GLContext::gl_polygon_mode(GLenum face, GLenum mode)
return;
}
auto map_mode = [](GLenum mode) -> SoftGPU::PolygonMode {
auto map_mode = [](GLenum mode) -> GPU::PolygonMode {
switch (mode) {
case GL_FILL:
return SoftGPU::PolygonMode::Fill;
return GPU::PolygonMode::Fill;
case GL_LINE:
return SoftGPU::PolygonMode::Line;
return GPU::PolygonMode::Line;
case GL_POINT:
return SoftGPU::PolygonMode::Point;
return GPU::PolygonMode::Point;
default:
VERIFY_NOT_REACHED();
}
@ -2550,13 +2550,13 @@ void GLContext::gl_fogi(GLenum pname, GLint param)
case GL_FOG_MODE:
switch (param) {
case GL_LINEAR:
options.fog_mode = SoftGPU::FogMode::Linear;
options.fog_mode = GPU::FogMode::Linear;
break;
case GL_EXP:
options.fog_mode = SoftGPU::FogMode::Exp;
options.fog_mode = GPU::FogMode::Exp;
break;
case GL_EXP2:
options.fog_mode = SoftGPU::FogMode::Exp2;
options.fog_mode = GPU::FogMode::Exp2;
break;
}
break;
@ -2730,7 +2730,7 @@ void GLContext::gl_light_model(GLenum pname, GLfloat x, GLfloat y, GLfloat z, GL
case GL_LIGHT_MODEL_COLOR_CONTROL: {
GLenum color_control = static_cast<GLenum>(x);
RETURN_WITH_ERROR_IF(color_control != GL_SINGLE_COLOR && color_control != GL_SEPARATE_SPECULAR_COLOR, GL_INVALID_ENUM);
lighting_params.color_control = (color_control == GL_SINGLE_COLOR) ? SoftGPU::ColorControl::SingleColor : SoftGPU::ColorControl::SeparateSpecularColor;
lighting_params.color_control = (color_control == GL_SINGLE_COLOR) ? GPU::ColorControl::SingleColor : GPU::ColorControl::SeparateSpecularColor;
break;
}
case GL_LIGHT_MODEL_LOCAL_VIEWER:
@ -3031,33 +3031,33 @@ void GLContext::sync_light_state()
options.color_material_enabled = m_color_material_enabled;
switch (m_color_material_face) {
case GL_BACK:
options.color_material_face = SoftGPU::ColorMaterialFace::Back;
options.color_material_face = GPU::ColorMaterialFace::Back;
break;
case GL_FRONT:
options.color_material_face = SoftGPU::ColorMaterialFace::Front;
options.color_material_face = GPU::ColorMaterialFace::Front;
break;
case GL_FRONT_AND_BACK:
options.color_material_face = SoftGPU::ColorMaterialFace::FrontAndBack;
options.color_material_face = GPU::ColorMaterialFace::FrontAndBack;
break;
default:
VERIFY_NOT_REACHED();
}
switch (m_color_material_mode) {
case GL_AMBIENT:
options.color_material_mode = SoftGPU::ColorMaterialMode::Ambient;
options.color_material_mode = GPU::ColorMaterialMode::Ambient;
break;
case GL_AMBIENT_AND_DIFFUSE:
options.color_material_mode = SoftGPU::ColorMaterialMode::Ambient;
options.color_material_mode = SoftGPU::ColorMaterialMode::Diffuse;
options.color_material_mode = GPU::ColorMaterialMode::Ambient;
options.color_material_mode = GPU::ColorMaterialMode::Diffuse;
break;
case GL_DIFFUSE:
options.color_material_mode = SoftGPU::ColorMaterialMode::Diffuse;
options.color_material_mode = GPU::ColorMaterialMode::Diffuse;
break;
case GL_EMISSION:
options.color_material_mode = SoftGPU::ColorMaterialMode::Emissive;
options.color_material_mode = GPU::ColorMaterialMode::Emissive;
break;
case GL_SPECULAR:
options.color_material_mode = SoftGPU::ColorMaterialMode::Specular;
options.color_material_mode = GPU::ColorMaterialMode::Specular;
break;
default:
VERIFY_NOT_REACHED();
@ -3069,8 +3069,8 @@ void GLContext::sync_light_state()
m_rasterizer.set_light_state(light_id, current_light_state);
}
m_rasterizer.set_material_state(SoftGPU::Face::Front, m_material_states[Face::Front]);
m_rasterizer.set_material_state(SoftGPU::Face::Back, m_material_states[Face::Back]);
m_rasterizer.set_material_state(GPU::Face::Front, m_material_states[Face::Front]);
m_rasterizer.set_material_state(GPU::Face::Back, m_material_states[Face::Back]);
}
void GLContext::sync_device_texcoord_config()
@ -3083,7 +3083,7 @@ void GLContext::sync_device_texcoord_config()
for (size_t i = 0; i < m_device_info.num_texture_units; ++i) {
u8 enabled_coordinates = SoftGPU::TexCoordGenerationCoordinate::None;
u8 enabled_coordinates = GPU::TexCoordGenerationCoordinate::None;
for (GLenum capability = GL_TEXTURE_GEN_S; capability <= GL_TEXTURE_GEN_Q; ++capability) {
auto const context_coordinate_config = texture_coordinate_generation(i, capability);
if (!context_coordinate_config.enabled)
@ -3092,19 +3092,19 @@ void GLContext::sync_device_texcoord_config()
SoftGPU::TexCoordGenerationConfig* texcoord_generation_config;
switch (capability) {
case GL_TEXTURE_GEN_S:
enabled_coordinates |= SoftGPU::TexCoordGenerationCoordinate::S;
enabled_coordinates |= GPU::TexCoordGenerationCoordinate::S;
texcoord_generation_config = &options.texcoord_generation_config[i][0];
break;
case GL_TEXTURE_GEN_T:
enabled_coordinates |= SoftGPU::TexCoordGenerationCoordinate::T;
enabled_coordinates |= GPU::TexCoordGenerationCoordinate::T;
texcoord_generation_config = &options.texcoord_generation_config[i][1];
break;
case GL_TEXTURE_GEN_R:
enabled_coordinates |= SoftGPU::TexCoordGenerationCoordinate::R;
enabled_coordinates |= GPU::TexCoordGenerationCoordinate::R;
texcoord_generation_config = &options.texcoord_generation_config[i][2];
break;
case GL_TEXTURE_GEN_Q:
enabled_coordinates |= SoftGPU::TexCoordGenerationCoordinate::Q;
enabled_coordinates |= GPU::TexCoordGenerationCoordinate::Q;
texcoord_generation_config = &options.texcoord_generation_config[i][3];
break;
default:
@ -3113,21 +3113,21 @@ void GLContext::sync_device_texcoord_config()
switch (context_coordinate_config.generation_mode) {
case GL_OBJECT_LINEAR:
texcoord_generation_config->mode = SoftGPU::TexCoordGenerationMode::ObjectLinear;
texcoord_generation_config->mode = GPU::TexCoordGenerationMode::ObjectLinear;
texcoord_generation_config->coefficients = context_coordinate_config.object_plane_coefficients;
break;
case GL_EYE_LINEAR:
texcoord_generation_config->mode = SoftGPU::TexCoordGenerationMode::EyeLinear;
texcoord_generation_config->mode = GPU::TexCoordGenerationMode::EyeLinear;
texcoord_generation_config->coefficients = context_coordinate_config.eye_plane_coefficients;
break;
case GL_SPHERE_MAP:
texcoord_generation_config->mode = SoftGPU::TexCoordGenerationMode::SphereMap;
texcoord_generation_config->mode = GPU::TexCoordGenerationMode::SphereMap;
break;
case GL_REFLECTION_MAP:
texcoord_generation_config->mode = SoftGPU::TexCoordGenerationMode::ReflectionMap;
texcoord_generation_config->mode = GPU::TexCoordGenerationMode::ReflectionMap;
break;
case GL_NORMAL_MAP:
texcoord_generation_config->mode = SoftGPU::TexCoordGenerationMode::NormalMap;
texcoord_generation_config->mode = GPU::TexCoordGenerationMode::NormalMap;
break;
}
}
@ -3143,28 +3143,28 @@ void GLContext::sync_stencil_configuration()
return;
m_stencil_configuration_dirty = false;
auto set_device_stencil = [&](SoftGPU::Face face, StencilFunctionOptions func, StencilOperationOptions op) {
auto set_device_stencil = [&](GPU::Face face, StencilFunctionOptions func, StencilOperationOptions op) {
SoftGPU::StencilConfiguration device_configuration;
// Stencil test function
auto map_func = [](GLenum func) -> SoftGPU::StencilTestFunction {
auto map_func = [](GLenum func) -> GPU::StencilTestFunction {
switch (func) {
case GL_ALWAYS:
return SoftGPU::StencilTestFunction::Always;
return GPU::StencilTestFunction::Always;
case GL_EQUAL:
return SoftGPU::StencilTestFunction::Equal;
return GPU::StencilTestFunction::Equal;
case GL_GEQUAL:
return SoftGPU::StencilTestFunction::GreaterOrEqual;
return GPU::StencilTestFunction::GreaterOrEqual;
case GL_GREATER:
return SoftGPU::StencilTestFunction::Greater;
return GPU::StencilTestFunction::Greater;
case GL_LESS:
return SoftGPU::StencilTestFunction::Less;
return GPU::StencilTestFunction::Less;
case GL_LEQUAL:
return SoftGPU::StencilTestFunction::LessOrEqual;
return GPU::StencilTestFunction::LessOrEqual;
case GL_NEVER:
return SoftGPU::StencilTestFunction::Never;
return GPU::StencilTestFunction::Never;
case GL_NOTEQUAL:
return SoftGPU::StencilTestFunction::NotEqual;
return GPU::StencilTestFunction::NotEqual;
}
VERIFY_NOT_REACHED();
};
@ -3173,24 +3173,24 @@ void GLContext::sync_stencil_configuration()
device_configuration.test_mask = func.mask;
// Stencil operation
auto map_operation = [](GLenum operation) -> SoftGPU::StencilOperation {
auto map_operation = [](GLenum operation) -> GPU::StencilOperation {
switch (operation) {
case GL_DECR:
return SoftGPU::StencilOperation::Decrement;
return GPU::StencilOperation::Decrement;
case GL_DECR_WRAP:
return SoftGPU::StencilOperation::DecrementWrap;
return GPU::StencilOperation::DecrementWrap;
case GL_INCR:
return SoftGPU::StencilOperation::Increment;
return GPU::StencilOperation::Increment;
case GL_INCR_WRAP:
return SoftGPU::StencilOperation::IncrementWrap;
return GPU::StencilOperation::IncrementWrap;
case GL_INVERT:
return SoftGPU::StencilOperation::Invert;
return GPU::StencilOperation::Invert;
case GL_KEEP:
return SoftGPU::StencilOperation::Keep;
return GPU::StencilOperation::Keep;
case GL_REPLACE:
return SoftGPU::StencilOperation::Replace;
return GPU::StencilOperation::Replace;
case GL_ZERO:
return SoftGPU::StencilOperation::Zero;
return GPU::StencilOperation::Zero;
}
VERIFY_NOT_REACHED();
};
@ -3201,8 +3201,8 @@ void GLContext::sync_stencil_configuration()
m_rasterizer.set_stencil_configuration(face, device_configuration);
};
set_device_stencil(SoftGPU::Face::Front, m_stencil_function[Face::Front], m_stencil_operation[Face::Front]);
set_device_stencil(SoftGPU::Face::Back, m_stencil_function[Face::Back], m_stencil_operation[Face::Back]);
set_device_stencil(GPU::Face::Front, m_stencil_function[Face::Front], m_stencil_operation[Face::Front]);
set_device_stencil(GPU::Face::Back, m_stencil_function[Face::Back], m_stencil_operation[Face::Back]);
}
void GLContext::build_extension_string()

View File

@ -8,11 +8,7 @@
#include <AK/Types.h>
namespace SoftGPU {
using ColorType = u32; // BGRA:8888
using DepthType = float;
using StencilType = u8;
namespace GPU {
enum class AlphaTestFunction {
Never,

View File

@ -23,4 +23,8 @@ static constexpr int NUM_LIGHTS = 8;
// FIXME: make this dynamically configurable through ConfigServer
static constexpr bool CLAMP_DEPRECATED_BEHAVIOR = false;
using ColorType = u32; // BGRA:8888
using DepthType = float;
using StencilType = u8;
}

View File

@ -97,79 +97,79 @@ void Device::setup_blend_factors()
m_alpha_blend_factors = {};
switch (m_options.blend_source_factor) {
case BlendFactor::Zero:
case GPU::BlendFactor::Zero:
break;
case BlendFactor::One:
case GPU::BlendFactor::One:
m_alpha_blend_factors.src_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
break;
case BlendFactor::SrcColor:
case GPU::BlendFactor::SrcColor:
m_alpha_blend_factors.src_factor_src_color = 1;
break;
case BlendFactor::OneMinusSrcColor:
case GPU::BlendFactor::OneMinusSrcColor:
m_alpha_blend_factors.src_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
m_alpha_blend_factors.src_factor_src_color = -1;
break;
case BlendFactor::SrcAlpha:
case GPU::BlendFactor::SrcAlpha:
m_alpha_blend_factors.src_factor_src_alpha = 1;
break;
case BlendFactor::OneMinusSrcAlpha:
case GPU::BlendFactor::OneMinusSrcAlpha:
m_alpha_blend_factors.src_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
m_alpha_blend_factors.src_factor_src_alpha = -1;
break;
case BlendFactor::DstAlpha:
case GPU::BlendFactor::DstAlpha:
m_alpha_blend_factors.src_factor_dst_alpha = 1;
break;
case BlendFactor::OneMinusDstAlpha:
case GPU::BlendFactor::OneMinusDstAlpha:
m_alpha_blend_factors.src_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
m_alpha_blend_factors.src_factor_dst_alpha = -1;
break;
case BlendFactor::DstColor:
case GPU::BlendFactor::DstColor:
m_alpha_blend_factors.src_factor_dst_color = 1;
break;
case BlendFactor::OneMinusDstColor:
case GPU::BlendFactor::OneMinusDstColor:
m_alpha_blend_factors.src_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
m_alpha_blend_factors.src_factor_dst_color = -1;
break;
case BlendFactor::SrcAlphaSaturate:
case GPU::BlendFactor::SrcAlphaSaturate:
default:
VERIFY_NOT_REACHED();
}
switch (m_options.blend_destination_factor) {
case BlendFactor::Zero:
case GPU::BlendFactor::Zero:
break;
case BlendFactor::One:
case GPU::BlendFactor::One:
m_alpha_blend_factors.dst_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
break;
case BlendFactor::SrcColor:
case GPU::BlendFactor::SrcColor:
m_alpha_blend_factors.dst_factor_src_color = 1;
break;
case BlendFactor::OneMinusSrcColor:
case GPU::BlendFactor::OneMinusSrcColor:
m_alpha_blend_factors.dst_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
m_alpha_blend_factors.dst_factor_src_color = -1;
break;
case BlendFactor::SrcAlpha:
case GPU::BlendFactor::SrcAlpha:
m_alpha_blend_factors.dst_factor_src_alpha = 1;
break;
case BlendFactor::OneMinusSrcAlpha:
case GPU::BlendFactor::OneMinusSrcAlpha:
m_alpha_blend_factors.dst_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
m_alpha_blend_factors.dst_factor_src_alpha = -1;
break;
case BlendFactor::DstAlpha:
case GPU::BlendFactor::DstAlpha:
m_alpha_blend_factors.dst_factor_dst_alpha = 1;
break;
case BlendFactor::OneMinusDstAlpha:
case GPU::BlendFactor::OneMinusDstAlpha:
m_alpha_blend_factors.dst_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
m_alpha_blend_factors.dst_factor_dst_alpha = -1;
break;
case BlendFactor::DstColor:
case GPU::BlendFactor::DstColor:
m_alpha_blend_factors.dst_factor_dst_color = 1;
break;
case BlendFactor::OneMinusDstColor:
case GPU::BlendFactor::OneMinusDstColor:
m_alpha_blend_factors.dst_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
m_alpha_blend_factors.dst_factor_dst_color = -1;
break;
case BlendFactor::SrcAlphaSaturate:
case GPU::BlendFactor::SrcAlphaSaturate:
default:
VERIFY_NOT_REACHED();
}
@ -180,7 +180,7 @@ void Device::rasterize_triangle(Triangle const& triangle)
INCREASE_STATISTICS_COUNTER(g_num_rasterized_triangles, 1);
// Return if alpha testing is a no-op
if (m_options.enable_alpha_test && m_options.alpha_test_func == AlphaTestFunction::Never)
if (m_options.enable_alpha_test && m_options.alpha_test_func == GPU::AlphaTestFunction::Never)
return;
// Vertices
@ -262,33 +262,33 @@ void Device::rasterize_triangle(Triangle const& triangle)
auto stencil_buffer = m_frame_buffer->stencil_buffer();
// Stencil configuration and writing
auto const& stencil_configuration = m_stencil_configuration[Face::Front];
auto const& stencil_configuration = m_stencil_configuration[GPU::Face::Front];
auto const stencil_reference_value = stencil_configuration.reference_value & stencil_configuration.test_mask;
auto write_to_stencil = [](StencilType* stencil_ptrs[4], i32x4 stencil_value, StencilOperation op, StencilType reference_value, StencilType write_mask, i32x4 pixel_mask) {
if (write_mask == 0 || op == StencilOperation::Keep)
auto write_to_stencil = [](StencilType* stencil_ptrs[4], i32x4 stencil_value, GPU::StencilOperation op, StencilType reference_value, StencilType write_mask, i32x4 pixel_mask) {
if (write_mask == 0 || op == GPU::StencilOperation::Keep)
return;
switch (op) {
case StencilOperation::Decrement:
case GPU::StencilOperation::Decrement:
stencil_value = (stencil_value & ~write_mask) | (max(stencil_value - 1, expand4(0)) & write_mask);
break;
case StencilOperation::DecrementWrap:
case GPU::StencilOperation::DecrementWrap:
stencil_value = (stencil_value & ~write_mask) | (((stencil_value - 1) & 0xFF) & write_mask);
break;
case StencilOperation::Increment:
case GPU::StencilOperation::Increment:
stencil_value = (stencil_value & ~write_mask) | (min(stencil_value + 1, expand4(0xFF)) & write_mask);
break;
case StencilOperation::IncrementWrap:
case GPU::StencilOperation::IncrementWrap:
stencil_value = (stencil_value & ~write_mask) | (((stencil_value + 1) & 0xFF) & write_mask);
break;
case StencilOperation::Invert:
case GPU::StencilOperation::Invert:
stencil_value ^= write_mask;
break;
case StencilOperation::Replace:
case GPU::StencilOperation::Replace:
stencil_value = (stencil_value & ~write_mask) | (reference_value & write_mask);
break;
case StencilOperation::Zero:
case GPU::StencilOperation::Zero:
stencil_value &= ~write_mask;
break;
default:
@ -344,28 +344,28 @@ void Device::rasterize_triangle(Triangle const& triangle)
i32x4 stencil_test_passed;
switch (stencil_configuration.test_function) {
case StencilTestFunction::Always:
case GPU::StencilTestFunction::Always:
stencil_test_passed = expand4(~0);
break;
case StencilTestFunction::Equal:
case GPU::StencilTestFunction::Equal:
stencil_test_passed = stencil_value == stencil_reference_value;
break;
case StencilTestFunction::Greater:
case GPU::StencilTestFunction::Greater:
stencil_test_passed = stencil_value > stencil_reference_value;
break;
case StencilTestFunction::GreaterOrEqual:
case GPU::StencilTestFunction::GreaterOrEqual:
stencil_test_passed = stencil_value >= stencil_reference_value;
break;
case StencilTestFunction::Less:
case GPU::StencilTestFunction::Less:
stencil_test_passed = stencil_value < stencil_reference_value;
break;
case StencilTestFunction::LessOrEqual:
case GPU::StencilTestFunction::LessOrEqual:
stencil_test_passed = stencil_value <= stencil_reference_value;
break;
case StencilTestFunction::Never:
case GPU::StencilTestFunction::Never:
stencil_test_passed = expand4(0);
break;
case StencilTestFunction::NotEqual:
case GPU::StencilTestFunction::NotEqual:
stencil_test_passed = stencil_value != stencil_reference_value;
break;
default:
@ -407,19 +407,19 @@ void Device::rasterize_triangle(Triangle const& triangle)
i32x4 depth_test_passed;
switch (m_options.depth_func) {
case DepthTestFunction::Always:
case GPU::DepthTestFunction::Always:
depth_test_passed = expand4(~0);
break;
case DepthTestFunction::Never:
case GPU::DepthTestFunction::Never:
depth_test_passed = expand4(0);
break;
case DepthTestFunction::Greater:
case GPU::DepthTestFunction::Greater:
depth_test_passed = quad.depth > depth;
break;
case DepthTestFunction::GreaterOrEqual:
case GPU::DepthTestFunction::GreaterOrEqual:
depth_test_passed = quad.depth >= depth;
break;
case DepthTestFunction::NotEqual:
case GPU::DepthTestFunction::NotEqual:
#ifdef __SSE__
depth_test_passed = quad.depth != depth;
#else
@ -431,7 +431,7 @@ void Device::rasterize_triangle(Triangle const& triangle)
};
#endif
break;
case DepthTestFunction::Equal:
case GPU::DepthTestFunction::Equal:
#ifdef __SSE__
depth_test_passed = quad.depth == depth;
#else
@ -454,10 +454,10 @@ void Device::rasterize_triangle(Triangle const& triangle)
};
#endif
break;
case DepthTestFunction::LessOrEqual:
case GPU::DepthTestFunction::LessOrEqual:
depth_test_passed = quad.depth <= depth;
break;
case DepthTestFunction::Less:
case GPU::DepthTestFunction::Less:
depth_test_passed = quad.depth < depth;
break;
default:
@ -518,7 +518,7 @@ void Device::rasterize_triangle(Triangle const& triangle)
shade_fragments(quad);
if (m_options.enable_alpha_test && m_options.alpha_test_func != AlphaTestFunction::Always && !test_alpha(quad))
if (m_options.enable_alpha_test && m_options.alpha_test_func != GPU::AlphaTestFunction::Always && !test_alpha(quad))
continue;
// Write to depth buffer
@ -595,15 +595,15 @@ static void generate_texture_coordinates(Vertex& vertex, RasterizerOptions const
auto mode = options.texcoord_generation_config[texcoord_index][config_index].mode;
switch (mode) {
case TexCoordGenerationMode::ObjectLinear: {
case GPU::TexCoordGenerationMode::ObjectLinear: {
auto coefficients = options.texcoord_generation_config[texcoord_index][config_index].coefficients;
return coefficients.dot(vertex.position);
}
case TexCoordGenerationMode::EyeLinear: {
case GPU::TexCoordGenerationMode::EyeLinear: {
auto coefficients = options.texcoord_generation_config[texcoord_index][config_index].coefficients;
return coefficients.dot(vertex.eye_coordinates);
}
case TexCoordGenerationMode::SphereMap: {
case GPU::TexCoordGenerationMode::SphereMap: {
auto const eye_unit = vertex.eye_coordinates.normalized();
FloatVector3 const eye_unit_xyz = eye_unit.xyz();
auto const normal = vertex.normal;
@ -612,14 +612,14 @@ static void generate_texture_coordinates(Vertex& vertex, RasterizerOptions const
auto const reflection_value = reflection[config_index];
return reflection_value / (2 * reflection.length()) + 0.5f;
}
case TexCoordGenerationMode::ReflectionMap: {
case GPU::TexCoordGenerationMode::ReflectionMap: {
auto const eye_unit = vertex.eye_coordinates.normalized();
FloatVector3 const eye_unit_xyz = eye_unit.xyz();
auto const normal = vertex.normal;
auto reflection = eye_unit_xyz - normal * 2 * normal.dot(eye_unit_xyz);
return reflection[config_index];
}
case TexCoordGenerationMode::NormalMap: {
case GPU::TexCoordGenerationMode::NormalMap: {
return vertex.normal[config_index];
}
default:
@ -631,15 +631,15 @@ static void generate_texture_coordinates(Vertex& vertex, RasterizerOptions const
auto& tex_coord = vertex.tex_coords[i];
auto const enabled_coords = options.texcoord_generation_enabled_coordinates[i];
tex_coord = {
((enabled_coords & TexCoordGenerationCoordinate::S) > 0) ? generate_coordinate(i, 0) : tex_coord.x(),
((enabled_coords & TexCoordGenerationCoordinate::T) > 0) ? generate_coordinate(i, 1) : tex_coord.y(),
((enabled_coords & TexCoordGenerationCoordinate::R) > 0) ? generate_coordinate(i, 2) : tex_coord.z(),
((enabled_coords & TexCoordGenerationCoordinate::Q) > 0) ? generate_coordinate(i, 3) : tex_coord.w(),
((enabled_coords & GPU::TexCoordGenerationCoordinate::S) > 0) ? generate_coordinate(i, 0) : tex_coord.x(),
((enabled_coords & GPU::TexCoordGenerationCoordinate::T) > 0) ? generate_coordinate(i, 1) : tex_coord.y(),
((enabled_coords & GPU::TexCoordGenerationCoordinate::R) > 0) ? generate_coordinate(i, 2) : tex_coord.z(),
((enabled_coords & GPU::TexCoordGenerationCoordinate::Q) > 0) ? generate_coordinate(i, 3) : tex_coord.w(),
};
}
}
void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform,
void Device::draw_primitives(GPU::PrimitiveType primitive_type, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform,
FloatMatrix4x4 const& texture_transform, Vector<Vertex> const& vertices, Vector<size_t> const& enabled_texture_units)
{
// At this point, the user has effectively specified that they are done with defining the geometry
@ -658,7 +658,7 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
m_processed_triangles.clear_with_capacity();
// Let's construct some triangles
if (primitive_type == PrimitiveType::Triangles) {
if (primitive_type == GPU::PrimitiveType::Triangles) {
Triangle triangle;
if (vertices.size() < 3)
return;
@ -669,7 +669,7 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
m_triangle_list.append(triangle);
}
} else if (primitive_type == PrimitiveType::Quads) {
} else if (primitive_type == GPU::PrimitiveType::Quads) {
// We need to construct two triangles to form the quad
Triangle triangle;
if (vertices.size() < 4)
@ -687,7 +687,7 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
triangle.vertices[2] = vertices.at(i);
m_triangle_list.append(triangle);
}
} else if (primitive_type == PrimitiveType::TriangleFan) {
} else if (primitive_type == GPU::PrimitiveType::TriangleFan) {
Triangle triangle;
triangle.vertices[0] = vertices.at(0); // Root vertex is always the vertex defined first
@ -697,7 +697,7 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
triangle.vertices[2] = vertices.at(i + 1);
m_triangle_list.append(triangle);
}
} else if (primitive_type == PrimitiveType::TriangleStrip) {
} else if (primitive_type == GPU::PrimitiveType::TriangleStrip) {
Triangle triangle;
if (vertices.size() < 3)
return;
@ -753,22 +753,22 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
auto specular = material.specular;
if (m_options.color_material_enabled
&& (m_options.color_material_face == ColorMaterialFace::Front || m_options.color_material_face == ColorMaterialFace::FrontAndBack)) {
&& (m_options.color_material_face == GPU::ColorMaterialFace::Front || m_options.color_material_face == GPU::ColorMaterialFace::FrontAndBack)) {
switch (m_options.color_material_mode) {
case ColorMaterialMode::Ambient:
case GPU::ColorMaterialMode::Ambient:
ambient = vertex.color;
break;
case ColorMaterialMode::AmbientAndDiffuse:
case GPU::ColorMaterialMode::AmbientAndDiffuse:
ambient = vertex.color;
diffuse = vertex.color;
break;
case ColorMaterialMode::Diffuse:
case GPU::ColorMaterialMode::Diffuse:
diffuse = vertex.color;
break;
case ColorMaterialMode::Emissive:
case GPU::ColorMaterialMode::Emissive:
emissive = vertex.color;
break;
case ColorMaterialMode::Specular:
case GPU::ColorMaterialMode::Specular:
specular = vertex.color;
break;
}
@ -916,7 +916,7 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
// Generate texture coordinates if at least one coordinate is enabled
bool texture_coordinate_generation_enabled = false;
for (auto const coordinates_enabled : m_options.texcoord_generation_enabled_coordinates) {
if (coordinates_enabled != TexCoordGenerationCoordinate::None) {
if (coordinates_enabled != GPU::TexCoordGenerationCoordinate::None) {
texture_coordinate_generation_enabled = true;
break;
}
@ -935,7 +935,7 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
continue;
if (m_options.enable_culling) {
bool is_front = (m_options.front_face == WindingOrder::CounterClockwise ? area > 0 : area < 0);
bool is_front = (m_options.front_face == GPU::WindingOrder::CounterClockwise ? area > 0 : area < 0);
if (!is_front && m_options.cull_back)
continue;
@ -977,13 +977,13 @@ ALWAYS_INLINE void Device::shade_fragments(PixelQuad& quad)
// FIXME: Implement more blend modes
switch (sampler.config().fixed_function_texture_env_mode) {
case TextureEnvMode::Modulate:
case SoftGPU::TextureEnvMode::Modulate:
quad.out_color = quad.out_color * texel;
break;
case TextureEnvMode::Replace:
case SoftGPU::TextureEnvMode::Replace:
quad.out_color = texel;
break;
case TextureEnvMode::Decal: {
case SoftGPU::TextureEnvMode::Decal: {
auto dst_alpha = texel.w();
quad.out_color.set_x(mix(quad.out_color.x(), texel.x(), dst_alpha));
quad.out_color.set_y(mix(quad.out_color.y(), texel.y(), dst_alpha));
@ -1002,14 +1002,14 @@ ALWAYS_INLINE void Device::shade_fragments(PixelQuad& quad)
if (m_options.fog_enabled) {
auto factor = expand4(0.0f);
switch (m_options.fog_mode) {
case FogMode::Linear:
case GPU::FogMode::Linear:
factor = (m_options.fog_end - quad.fog_depth) / (m_options.fog_end - m_options.fog_start);
break;
case FogMode::Exp: {
case GPU::FogMode::Exp: {
auto argument = -m_options.fog_density * quad.fog_depth;
factor = exp(argument);
} break;
case FogMode::Exp2: {
case GPU::FogMode::Exp2: {
auto argument = m_options.fog_density * quad.fog_depth;
argument *= -argument;
factor = exp(argument);
@ -1032,26 +1032,26 @@ ALWAYS_INLINE bool Device::test_alpha(PixelQuad& quad)
auto const ref_value = expand4(m_options.alpha_test_ref_value);
switch (m_options.alpha_test_func) {
case AlphaTestFunction::Less:
case GPU::AlphaTestFunction::Less:
quad.mask &= alpha < ref_value;
break;
case AlphaTestFunction::Equal:
case GPU::AlphaTestFunction::Equal:
quad.mask &= alpha == ref_value;
break;
case AlphaTestFunction::LessOrEqual:
case GPU::AlphaTestFunction::LessOrEqual:
quad.mask &= alpha <= ref_value;
break;
case AlphaTestFunction::Greater:
case GPU::AlphaTestFunction::Greater:
quad.mask &= alpha > ref_value;
break;
case AlphaTestFunction::NotEqual:
case GPU::AlphaTestFunction::NotEqual:
quad.mask &= alpha != ref_value;
break;
case AlphaTestFunction::GreaterOrEqual:
case GPU::AlphaTestFunction::GreaterOrEqual:
quad.mask &= alpha >= ref_value;
break;
case AlphaTestFunction::Never:
case AlphaTestFunction::Always:
case GPU::AlphaTestFunction::Never:
case GPU::AlphaTestFunction::Always:
default:
VERIFY_NOT_REACHED();
}
@ -1241,12 +1241,12 @@ void Device::set_light_state(unsigned int light_id, Light const& light)
m_lights.at(light_id) = light;
}
void Device::set_material_state(Face face, Material const& material)
void Device::set_material_state(GPU::Face face, Material const& material)
{
m_materials[face] = material;
}
void Device::set_stencil_configuration(Face face, StencilConfiguration const& stencil_configuration)
void Device::set_stencil_configuration(GPU::Face face, StencilConfiguration const& stencil_configuration)
{
m_stencil_configuration[face] = stencil_configuration;
}

View File

@ -12,6 +12,7 @@
#include <AK/RefPtr.h>
#include <AK/Vector.h>
#include <LibGPU/DeviceInfo.h>
#include <LibGPU/Enums.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Matrix3x3.h>
#include <LibGfx/Matrix4x4.h>
@ -22,7 +23,6 @@
#include <LibSoftGPU/Buffer/Typed2DBuffer.h>
#include <LibSoftGPU/Clipper.h>
#include <LibSoftGPU/Config.h>
#include <LibSoftGPU/Enums.h>
#include <LibSoftGPU/Image.h>
#include <LibSoftGPU/ImageFormat.h>
#include <LibSoftGPU/Light/Light.h>
@ -34,7 +34,7 @@
namespace SoftGPU {
struct TexCoordGenerationConfig {
TexCoordGenerationMode mode { TexCoordGenerationMode::EyeLinear };
GPU::TexCoordGenerationMode mode { GPU::TexCoordGenerationMode::EyeLinear };
FloatVector4 coefficients {};
};
@ -44,19 +44,19 @@ struct RasterizerOptions {
bool enable_depth_test { false };
bool enable_depth_write { true };
bool enable_alpha_test { false };
AlphaTestFunction alpha_test_func { AlphaTestFunction::Always };
GPU::AlphaTestFunction alpha_test_func { GPU::AlphaTestFunction::Always };
float alpha_test_ref_value { 0 };
bool enable_blending { false };
BlendFactor blend_source_factor { BlendFactor::One };
BlendFactor blend_destination_factor { BlendFactor::One };
GPU::BlendFactor blend_source_factor { GPU::BlendFactor::One };
GPU::BlendFactor blend_destination_factor { GPU::BlendFactor::One };
u32 color_mask { 0xffffffff };
float depth_min { 0.f };
float depth_max { 1.f };
DepthTestFunction depth_func { DepthTestFunction::Less };
PolygonMode polygon_mode { PolygonMode::Fill };
GPU::DepthTestFunction depth_func { GPU::DepthTestFunction::Less };
GPU::PolygonMode polygon_mode { GPU::PolygonMode::Fill };
FloatVector4 fog_color { 0.0f, 0.0f, 0.0f, 0.0f };
float fog_density { 1.0f };
FogMode fog_mode { FogMode::Exp };
GPU::FogMode fog_mode { GPU::FogMode::Exp };
bool fog_enabled { false };
float fog_start { 0.0f };
float fog_end { 1.0f };
@ -68,7 +68,7 @@ struct RasterizerOptions {
float depth_offset_constant { 0 };
bool depth_offset_enabled { false };
bool enable_culling { false };
WindingOrder front_face { WindingOrder::CounterClockwise };
GPU::WindingOrder front_face { GPU::WindingOrder::CounterClockwise };
bool cull_back { true };
bool cull_front { false };
Array<u8, NUM_SAMPLERS> texcoord_generation_enabled_coordinates {};
@ -76,14 +76,14 @@ struct RasterizerOptions {
Gfx::IntRect viewport;
bool lighting_enabled { false };
bool color_material_enabled { false };
ColorMaterialFace color_material_face { ColorMaterialFace::FrontAndBack };
ColorMaterialMode color_material_mode { ColorMaterialMode::AmbientAndDiffuse };
GPU::ColorMaterialFace color_material_face { GPU::ColorMaterialFace::FrontAndBack };
GPU::ColorMaterialMode color_material_mode { GPU::ColorMaterialMode::AmbientAndDiffuse };
};
struct LightModelParameters {
FloatVector4 scene_ambient_color { 0.2f, 0.2f, 0.2f, 1.0f };
bool viewer_at_infinity { false };
ColorControl color_control { ColorControl::SingleColor };
GPU::ColorControl color_control { GPU::ColorControl::SingleColor };
bool two_sided_lighting { false };
};
@ -99,13 +99,13 @@ struct RasterPosition {
};
struct StencilConfiguration {
StencilTestFunction test_function;
GPU::StencilTestFunction test_function;
StencilType reference_value;
StencilType test_mask;
StencilOperation on_stencil_test_fail;
StencilOperation on_depth_test_fail;
StencilOperation on_pass;
GPU::StencilOperation on_stencil_test_fail;
GPU::StencilOperation on_depth_test_fail;
GPU::StencilOperation on_pass;
StencilType write_mask;
};
@ -115,7 +115,7 @@ public:
GPU::DeviceInfo info() const;
void draw_primitives(PrimitiveType, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform, FloatMatrix4x4 const& texture_transform, Vector<Vertex> const& vertices, Vector<size_t> const& enabled_texture_units);
void draw_primitives(GPU::PrimitiveType, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform, FloatMatrix4x4 const& texture_transform, Vector<Vertex> const& vertices, Vector<size_t> const& enabled_texture_units);
void resize(Gfx::IntSize const& min_size);
void clear_color(FloatVector4 const&);
void clear_depth(DepthType);
@ -134,8 +134,8 @@ public:
void set_sampler_config(unsigned, SamplerConfig const&);
void set_light_state(unsigned, Light const&);
void set_material_state(Face, Material const&);
void set_stencil_configuration(Face, StencilConfiguration const&);
void set_material_state(GPU::Face, Material const&);
void set_stencil_configuration(GPU::Face, StencilConfiguration const&);
RasterPosition raster_position() const { return m_raster_position; }
void set_raster_position(RasterPosition const& raster_position);

View File

@ -10,10 +10,11 @@
#include <AK/FixedArray.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <LibGPU/Enums.h>
#include <LibGfx/Vector3.h>
#include <LibGfx/Vector4.h>
#include <LibSoftGPU/Buffer/Typed3DBuffer.h>
#include <LibSoftGPU/Enums.h>
#include <LibSoftGPU/Config.h>
#include <LibSoftGPU/ImageDataLayout.h>
#include <LibSoftGPU/ImageFormat.h>