1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 20:07:36 +00:00

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
6 changed files with 198 additions and 197 deletions

View file

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

View file

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

View file

@ -23,4 +23,8 @@ static constexpr int NUM_LIGHTS = 8;
// FIXME: make this dynamically configurable through ConfigServer // FIXME: make this dynamically configurable through ConfigServer
static constexpr bool CLAMP_DEPRECATED_BEHAVIOR = false; 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 = {}; m_alpha_blend_factors = {};
switch (m_options.blend_source_factor) { switch (m_options.blend_source_factor) {
case BlendFactor::Zero: case GPU::BlendFactor::Zero:
break; break;
case BlendFactor::One: case GPU::BlendFactor::One:
m_alpha_blend_factors.src_constant = { 1.0f, 1.0f, 1.0f, 1.0f }; m_alpha_blend_factors.src_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
break; break;
case BlendFactor::SrcColor: case GPU::BlendFactor::SrcColor:
m_alpha_blend_factors.src_factor_src_color = 1; m_alpha_blend_factors.src_factor_src_color = 1;
break; 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_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
m_alpha_blend_factors.src_factor_src_color = -1; m_alpha_blend_factors.src_factor_src_color = -1;
break; break;
case BlendFactor::SrcAlpha: case GPU::BlendFactor::SrcAlpha:
m_alpha_blend_factors.src_factor_src_alpha = 1; m_alpha_blend_factors.src_factor_src_alpha = 1;
break; 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_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
m_alpha_blend_factors.src_factor_src_alpha = -1; m_alpha_blend_factors.src_factor_src_alpha = -1;
break; break;
case BlendFactor::DstAlpha: case GPU::BlendFactor::DstAlpha:
m_alpha_blend_factors.src_factor_dst_alpha = 1; m_alpha_blend_factors.src_factor_dst_alpha = 1;
break; 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_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
m_alpha_blend_factors.src_factor_dst_alpha = -1; m_alpha_blend_factors.src_factor_dst_alpha = -1;
break; break;
case BlendFactor::DstColor: case GPU::BlendFactor::DstColor:
m_alpha_blend_factors.src_factor_dst_color = 1; m_alpha_blend_factors.src_factor_dst_color = 1;
break; 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_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
m_alpha_blend_factors.src_factor_dst_color = -1; m_alpha_blend_factors.src_factor_dst_color = -1;
break; break;
case BlendFactor::SrcAlphaSaturate: case GPU::BlendFactor::SrcAlphaSaturate:
default: default:
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
switch (m_options.blend_destination_factor) { switch (m_options.blend_destination_factor) {
case BlendFactor::Zero: case GPU::BlendFactor::Zero:
break; break;
case BlendFactor::One: case GPU::BlendFactor::One:
m_alpha_blend_factors.dst_constant = { 1.0f, 1.0f, 1.0f, 1.0f }; m_alpha_blend_factors.dst_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
break; break;
case BlendFactor::SrcColor: case GPU::BlendFactor::SrcColor:
m_alpha_blend_factors.dst_factor_src_color = 1; m_alpha_blend_factors.dst_factor_src_color = 1;
break; 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_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
m_alpha_blend_factors.dst_factor_src_color = -1; m_alpha_blend_factors.dst_factor_src_color = -1;
break; break;
case BlendFactor::SrcAlpha: case GPU::BlendFactor::SrcAlpha:
m_alpha_blend_factors.dst_factor_src_alpha = 1; m_alpha_blend_factors.dst_factor_src_alpha = 1;
break; 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_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
m_alpha_blend_factors.dst_factor_src_alpha = -1; m_alpha_blend_factors.dst_factor_src_alpha = -1;
break; break;
case BlendFactor::DstAlpha: case GPU::BlendFactor::DstAlpha:
m_alpha_blend_factors.dst_factor_dst_alpha = 1; m_alpha_blend_factors.dst_factor_dst_alpha = 1;
break; 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_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
m_alpha_blend_factors.dst_factor_dst_alpha = -1; m_alpha_blend_factors.dst_factor_dst_alpha = -1;
break; break;
case BlendFactor::DstColor: case GPU::BlendFactor::DstColor:
m_alpha_blend_factors.dst_factor_dst_color = 1; m_alpha_blend_factors.dst_factor_dst_color = 1;
break; 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_constant = { 1.0f, 1.0f, 1.0f, 1.0f };
m_alpha_blend_factors.dst_factor_dst_color = -1; m_alpha_blend_factors.dst_factor_dst_color = -1;
break; break;
case BlendFactor::SrcAlphaSaturate: case GPU::BlendFactor::SrcAlphaSaturate:
default: default:
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
@ -180,7 +180,7 @@ void Device::rasterize_triangle(Triangle const& triangle)
INCREASE_STATISTICS_COUNTER(g_num_rasterized_triangles, 1); INCREASE_STATISTICS_COUNTER(g_num_rasterized_triangles, 1);
// Return if alpha testing is a no-op // 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; return;
// Vertices // Vertices
@ -262,33 +262,33 @@ void Device::rasterize_triangle(Triangle const& triangle)
auto stencil_buffer = m_frame_buffer->stencil_buffer(); auto stencil_buffer = m_frame_buffer->stencil_buffer();
// Stencil configuration and writing // 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 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) { 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 == StencilOperation::Keep) if (write_mask == 0 || op == GPU::StencilOperation::Keep)
return; return;
switch (op) { switch (op) {
case StencilOperation::Decrement: case GPU::StencilOperation::Decrement:
stencil_value = (stencil_value & ~write_mask) | (max(stencil_value - 1, expand4(0)) & write_mask); stencil_value = (stencil_value & ~write_mask) | (max(stencil_value - 1, expand4(0)) & write_mask);
break; break;
case StencilOperation::DecrementWrap: case GPU::StencilOperation::DecrementWrap:
stencil_value = (stencil_value & ~write_mask) | (((stencil_value - 1) & 0xFF) & write_mask); stencil_value = (stencil_value & ~write_mask) | (((stencil_value - 1) & 0xFF) & write_mask);
break; break;
case StencilOperation::Increment: case GPU::StencilOperation::Increment:
stencil_value = (stencil_value & ~write_mask) | (min(stencil_value + 1, expand4(0xFF)) & write_mask); stencil_value = (stencil_value & ~write_mask) | (min(stencil_value + 1, expand4(0xFF)) & write_mask);
break; break;
case StencilOperation::IncrementWrap: case GPU::StencilOperation::IncrementWrap:
stencil_value = (stencil_value & ~write_mask) | (((stencil_value + 1) & 0xFF) & write_mask); stencil_value = (stencil_value & ~write_mask) | (((stencil_value + 1) & 0xFF) & write_mask);
break; break;
case StencilOperation::Invert: case GPU::StencilOperation::Invert:
stencil_value ^= write_mask; stencil_value ^= write_mask;
break; break;
case StencilOperation::Replace: case GPU::StencilOperation::Replace:
stencil_value = (stencil_value & ~write_mask) | (reference_value & write_mask); stencil_value = (stencil_value & ~write_mask) | (reference_value & write_mask);
break; break;
case StencilOperation::Zero: case GPU::StencilOperation::Zero:
stencil_value &= ~write_mask; stencil_value &= ~write_mask;
break; break;
default: default:
@ -344,28 +344,28 @@ void Device::rasterize_triangle(Triangle const& triangle)
i32x4 stencil_test_passed; i32x4 stencil_test_passed;
switch (stencil_configuration.test_function) { switch (stencil_configuration.test_function) {
case StencilTestFunction::Always: case GPU::StencilTestFunction::Always:
stencil_test_passed = expand4(~0); stencil_test_passed = expand4(~0);
break; break;
case StencilTestFunction::Equal: case GPU::StencilTestFunction::Equal:
stencil_test_passed = stencil_value == stencil_reference_value; stencil_test_passed = stencil_value == stencil_reference_value;
break; break;
case StencilTestFunction::Greater: case GPU::StencilTestFunction::Greater:
stencil_test_passed = stencil_value > stencil_reference_value; stencil_test_passed = stencil_value > stencil_reference_value;
break; break;
case StencilTestFunction::GreaterOrEqual: case GPU::StencilTestFunction::GreaterOrEqual:
stencil_test_passed = stencil_value >= stencil_reference_value; stencil_test_passed = stencil_value >= stencil_reference_value;
break; break;
case StencilTestFunction::Less: case GPU::StencilTestFunction::Less:
stencil_test_passed = stencil_value < stencil_reference_value; stencil_test_passed = stencil_value < stencil_reference_value;
break; break;
case StencilTestFunction::LessOrEqual: case GPU::StencilTestFunction::LessOrEqual:
stencil_test_passed = stencil_value <= stencil_reference_value; stencil_test_passed = stencil_value <= stencil_reference_value;
break; break;
case StencilTestFunction::Never: case GPU::StencilTestFunction::Never:
stencil_test_passed = expand4(0); stencil_test_passed = expand4(0);
break; break;
case StencilTestFunction::NotEqual: case GPU::StencilTestFunction::NotEqual:
stencil_test_passed = stencil_value != stencil_reference_value; stencil_test_passed = stencil_value != stencil_reference_value;
break; break;
default: default:
@ -407,19 +407,19 @@ void Device::rasterize_triangle(Triangle const& triangle)
i32x4 depth_test_passed; i32x4 depth_test_passed;
switch (m_options.depth_func) { switch (m_options.depth_func) {
case DepthTestFunction::Always: case GPU::DepthTestFunction::Always:
depth_test_passed = expand4(~0); depth_test_passed = expand4(~0);
break; break;
case DepthTestFunction::Never: case GPU::DepthTestFunction::Never:
depth_test_passed = expand4(0); depth_test_passed = expand4(0);
break; break;
case DepthTestFunction::Greater: case GPU::DepthTestFunction::Greater:
depth_test_passed = quad.depth > depth; depth_test_passed = quad.depth > depth;
break; break;
case DepthTestFunction::GreaterOrEqual: case GPU::DepthTestFunction::GreaterOrEqual:
depth_test_passed = quad.depth >= depth; depth_test_passed = quad.depth >= depth;
break; break;
case DepthTestFunction::NotEqual: case GPU::DepthTestFunction::NotEqual:
#ifdef __SSE__ #ifdef __SSE__
depth_test_passed = quad.depth != depth; depth_test_passed = quad.depth != depth;
#else #else
@ -431,7 +431,7 @@ void Device::rasterize_triangle(Triangle const& triangle)
}; };
#endif #endif
break; break;
case DepthTestFunction::Equal: case GPU::DepthTestFunction::Equal:
#ifdef __SSE__ #ifdef __SSE__
depth_test_passed = quad.depth == depth; depth_test_passed = quad.depth == depth;
#else #else
@ -454,10 +454,10 @@ void Device::rasterize_triangle(Triangle const& triangle)
}; };
#endif #endif
break; break;
case DepthTestFunction::LessOrEqual: case GPU::DepthTestFunction::LessOrEqual:
depth_test_passed = quad.depth <= depth; depth_test_passed = quad.depth <= depth;
break; break;
case DepthTestFunction::Less: case GPU::DepthTestFunction::Less:
depth_test_passed = quad.depth < depth; depth_test_passed = quad.depth < depth;
break; break;
default: default:
@ -518,7 +518,7 @@ void Device::rasterize_triangle(Triangle const& triangle)
shade_fragments(quad); 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; continue;
// Write to depth buffer // 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; auto mode = options.texcoord_generation_config[texcoord_index][config_index].mode;
switch (mode) { switch (mode) {
case TexCoordGenerationMode::ObjectLinear: { case GPU::TexCoordGenerationMode::ObjectLinear: {
auto coefficients = options.texcoord_generation_config[texcoord_index][config_index].coefficients; auto coefficients = options.texcoord_generation_config[texcoord_index][config_index].coefficients;
return coefficients.dot(vertex.position); return coefficients.dot(vertex.position);
} }
case TexCoordGenerationMode::EyeLinear: { case GPU::TexCoordGenerationMode::EyeLinear: {
auto coefficients = options.texcoord_generation_config[texcoord_index][config_index].coefficients; auto coefficients = options.texcoord_generation_config[texcoord_index][config_index].coefficients;
return coefficients.dot(vertex.eye_coordinates); return coefficients.dot(vertex.eye_coordinates);
} }
case TexCoordGenerationMode::SphereMap: { case GPU::TexCoordGenerationMode::SphereMap: {
auto const eye_unit = vertex.eye_coordinates.normalized(); auto const eye_unit = vertex.eye_coordinates.normalized();
FloatVector3 const eye_unit_xyz = eye_unit.xyz(); FloatVector3 const eye_unit_xyz = eye_unit.xyz();
auto const normal = vertex.normal; 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]; auto const reflection_value = reflection[config_index];
return reflection_value / (2 * reflection.length()) + 0.5f; return reflection_value / (2 * reflection.length()) + 0.5f;
} }
case TexCoordGenerationMode::ReflectionMap: { case GPU::TexCoordGenerationMode::ReflectionMap: {
auto const eye_unit = vertex.eye_coordinates.normalized(); auto const eye_unit = vertex.eye_coordinates.normalized();
FloatVector3 const eye_unit_xyz = eye_unit.xyz(); FloatVector3 const eye_unit_xyz = eye_unit.xyz();
auto const normal = vertex.normal; auto const normal = vertex.normal;
auto reflection = eye_unit_xyz - normal * 2 * normal.dot(eye_unit_xyz); auto reflection = eye_unit_xyz - normal * 2 * normal.dot(eye_unit_xyz);
return reflection[config_index]; return reflection[config_index];
} }
case TexCoordGenerationMode::NormalMap: { case GPU::TexCoordGenerationMode::NormalMap: {
return vertex.normal[config_index]; return vertex.normal[config_index];
} }
default: default:
@ -631,15 +631,15 @@ static void generate_texture_coordinates(Vertex& vertex, RasterizerOptions const
auto& tex_coord = vertex.tex_coords[i]; auto& tex_coord = vertex.tex_coords[i];
auto const enabled_coords = options.texcoord_generation_enabled_coordinates[i]; auto const enabled_coords = options.texcoord_generation_enabled_coordinates[i];
tex_coord = { tex_coord = {
((enabled_coords & TexCoordGenerationCoordinate::S) > 0) ? generate_coordinate(i, 0) : tex_coord.x(), ((enabled_coords & GPU::TexCoordGenerationCoordinate::S) > 0) ? generate_coordinate(i, 0) : tex_coord.x(),
((enabled_coords & TexCoordGenerationCoordinate::T) > 0) ? generate_coordinate(i, 1) : tex_coord.y(), ((enabled_coords & GPU::TexCoordGenerationCoordinate::T) > 0) ? generate_coordinate(i, 1) : tex_coord.y(),
((enabled_coords & TexCoordGenerationCoordinate::R) > 0) ? generate_coordinate(i, 2) : tex_coord.z(), ((enabled_coords & GPU::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::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) 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 // 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(); m_processed_triangles.clear_with_capacity();
// Let's construct some triangles // Let's construct some triangles
if (primitive_type == PrimitiveType::Triangles) { if (primitive_type == GPU::PrimitiveType::Triangles) {
Triangle triangle; Triangle triangle;
if (vertices.size() < 3) if (vertices.size() < 3)
return; return;
@ -669,7 +669,7 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
m_triangle_list.append(triangle); 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 // We need to construct two triangles to form the quad
Triangle triangle; Triangle triangle;
if (vertices.size() < 4) if (vertices.size() < 4)
@ -687,7 +687,7 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
triangle.vertices[2] = vertices.at(i); triangle.vertices[2] = vertices.at(i);
m_triangle_list.append(triangle); m_triangle_list.append(triangle);
} }
} else if (primitive_type == PrimitiveType::TriangleFan) { } else if (primitive_type == GPU::PrimitiveType::TriangleFan) {
Triangle triangle; Triangle triangle;
triangle.vertices[0] = vertices.at(0); // Root vertex is always the vertex defined first 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); triangle.vertices[2] = vertices.at(i + 1);
m_triangle_list.append(triangle); m_triangle_list.append(triangle);
} }
} else if (primitive_type == PrimitiveType::TriangleStrip) { } else if (primitive_type == GPU::PrimitiveType::TriangleStrip) {
Triangle triangle; Triangle triangle;
if (vertices.size() < 3) if (vertices.size() < 3)
return; return;
@ -753,22 +753,22 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
auto specular = material.specular; auto specular = material.specular;
if (m_options.color_material_enabled 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) { switch (m_options.color_material_mode) {
case ColorMaterialMode::Ambient: case GPU::ColorMaterialMode::Ambient:
ambient = vertex.color; ambient = vertex.color;
break; break;
case ColorMaterialMode::AmbientAndDiffuse: case GPU::ColorMaterialMode::AmbientAndDiffuse:
ambient = vertex.color; ambient = vertex.color;
diffuse = vertex.color; diffuse = vertex.color;
break; break;
case ColorMaterialMode::Diffuse: case GPU::ColorMaterialMode::Diffuse:
diffuse = vertex.color; diffuse = vertex.color;
break; break;
case ColorMaterialMode::Emissive: case GPU::ColorMaterialMode::Emissive:
emissive = vertex.color; emissive = vertex.color;
break; break;
case ColorMaterialMode::Specular: case GPU::ColorMaterialMode::Specular:
specular = vertex.color; specular = vertex.color;
break; break;
} }
@ -916,7 +916,7 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
// Generate texture coordinates if at least one coordinate is enabled // Generate texture coordinates if at least one coordinate is enabled
bool texture_coordinate_generation_enabled = false; bool texture_coordinate_generation_enabled = false;
for (auto const coordinates_enabled : m_options.texcoord_generation_enabled_coordinates) { 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; texture_coordinate_generation_enabled = true;
break; break;
} }
@ -935,7 +935,7 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
continue; continue;
if (m_options.enable_culling) { 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) if (!is_front && m_options.cull_back)
continue; continue;
@ -977,13 +977,13 @@ ALWAYS_INLINE void Device::shade_fragments(PixelQuad& quad)
// FIXME: Implement more blend modes // FIXME: Implement more blend modes
switch (sampler.config().fixed_function_texture_env_mode) { switch (sampler.config().fixed_function_texture_env_mode) {
case TextureEnvMode::Modulate: case SoftGPU::TextureEnvMode::Modulate:
quad.out_color = quad.out_color * texel; quad.out_color = quad.out_color * texel;
break; break;
case TextureEnvMode::Replace: case SoftGPU::TextureEnvMode::Replace:
quad.out_color = texel; quad.out_color = texel;
break; break;
case TextureEnvMode::Decal: { case SoftGPU::TextureEnvMode::Decal: {
auto dst_alpha = texel.w(); auto dst_alpha = texel.w();
quad.out_color.set_x(mix(quad.out_color.x(), texel.x(), dst_alpha)); 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)); 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) { if (m_options.fog_enabled) {
auto factor = expand4(0.0f); auto factor = expand4(0.0f);
switch (m_options.fog_mode) { 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); factor = (m_options.fog_end - quad.fog_depth) / (m_options.fog_end - m_options.fog_start);
break; break;
case FogMode::Exp: { case GPU::FogMode::Exp: {
auto argument = -m_options.fog_density * quad.fog_depth; auto argument = -m_options.fog_density * quad.fog_depth;
factor = exp(argument); factor = exp(argument);
} break; } break;
case FogMode::Exp2: { case GPU::FogMode::Exp2: {
auto argument = m_options.fog_density * quad.fog_depth; auto argument = m_options.fog_density * quad.fog_depth;
argument *= -argument; argument *= -argument;
factor = exp(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); auto const ref_value = expand4(m_options.alpha_test_ref_value);
switch (m_options.alpha_test_func) { switch (m_options.alpha_test_func) {
case AlphaTestFunction::Less: case GPU::AlphaTestFunction::Less:
quad.mask &= alpha < ref_value; quad.mask &= alpha < ref_value;
break; break;
case AlphaTestFunction::Equal: case GPU::AlphaTestFunction::Equal:
quad.mask &= alpha == ref_value; quad.mask &= alpha == ref_value;
break; break;
case AlphaTestFunction::LessOrEqual: case GPU::AlphaTestFunction::LessOrEqual:
quad.mask &= alpha <= ref_value; quad.mask &= alpha <= ref_value;
break; break;
case AlphaTestFunction::Greater: case GPU::AlphaTestFunction::Greater:
quad.mask &= alpha > ref_value; quad.mask &= alpha > ref_value;
break; break;
case AlphaTestFunction::NotEqual: case GPU::AlphaTestFunction::NotEqual:
quad.mask &= alpha != ref_value; quad.mask &= alpha != ref_value;
break; break;
case AlphaTestFunction::GreaterOrEqual: case GPU::AlphaTestFunction::GreaterOrEqual:
quad.mask &= alpha >= ref_value; quad.mask &= alpha >= ref_value;
break; break;
case AlphaTestFunction::Never: case GPU::AlphaTestFunction::Never:
case AlphaTestFunction::Always: case GPU::AlphaTestFunction::Always:
default: default:
VERIFY_NOT_REACHED(); 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; 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; 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; m_stencil_configuration[face] = stencil_configuration;
} }

View file

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

View file

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