2022-01-06 16:55:08 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
|
LibGL+LibGPU+LibSoftGPU: Implement point and line drawing
Implement (anti)aliased point drawing and anti-aliased line drawing.
Supported through LibGL's `GL_POINTS`, `GL_LINES`, `GL_LINE_LOOP` and
`GL_LINE_STRIP`.
In order to support this, `LibSoftGPU`s rasterization logic was
reworked. Now, any primitive can be drawn by invoking `rasterize()`
which takes care of the quad loop and fragment testing logic. Three
callbacks need to be passed:
* `set_coverage_mask`: the primitive needs to provide initial coverage
mask information so fragments can be discarded early.
* `set_quad_depth`: fragments survived stencil testing, so depth values
need to be set so depth testing can take place.
* `set_quad_attributes`: fragments survived depth testing, so fragment
shading is going to take place. All attributes like color, tex coords
and fog depth need to be set so alpha testing and eventually,
fragment rasterization can take place.
As of this commit, there are four instantiations of this function:
* Triangle rasterization
* Points - aliased
* Points - anti-aliased
* Lines - anti-aliased
In order to standardize vertex processing for all primitive types,
things like vertex transformation, lighting and tex coord generation
are now taking place before clipping.
2022-05-08 02:13:14 +02:00
|
|
|
* Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
|
2022-01-06 16:55:08 +01:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/SIMD.h>
|
LibGL+LibGPU+LibSoftGPU: Implement point and line drawing
Implement (anti)aliased point drawing and anti-aliased line drawing.
Supported through LibGL's `GL_POINTS`, `GL_LINES`, `GL_LINE_LOOP` and
`GL_LINE_STRIP`.
In order to support this, `LibSoftGPU`s rasterization logic was
reworked. Now, any primitive can be drawn by invoking `rasterize()`
which takes care of the quad loop and fragment testing logic. Three
callbacks need to be passed:
* `set_coverage_mask`: the primitive needs to provide initial coverage
mask information so fragments can be discarded early.
* `set_quad_depth`: fragments survived stencil testing, so depth values
need to be set so depth testing can take place.
* `set_quad_attributes`: fragments survived depth testing, so fragment
shading is going to take place. All attributes like color, tex coords
and fog depth need to be set so alpha testing and eventually,
fragment rasterization can take place.
As of this commit, there are four instantiations of this function:
* Triangle rasterization
* Points - aliased
* Points - anti-aliased
* Lines - anti-aliased
In order to standardize vertex processing for all primitive types,
things like vertex transformation, lighting and tex coord generation
are now taking place before clipping.
2022-05-08 02:13:14 +02:00
|
|
|
#include <AK/SIMDExtras.h>
|
2022-01-06 16:55:08 +01:00
|
|
|
#include <LibGfx/Vector2.h>
|
|
|
|
|
#include <LibGfx/Vector3.h>
|
|
|
|
|
#include <LibGfx/Vector4.h>
|
2022-01-15 18:33:55 +01:00
|
|
|
#include <LibSoftGPU/Config.h>
|
2022-01-06 16:55:08 +01:00
|
|
|
|
|
|
|
|
namespace SoftGPU {
|
|
|
|
|
|
LibGL+LibGPU+LibSoftGPU: Implement point and line drawing
Implement (anti)aliased point drawing and anti-aliased line drawing.
Supported through LibGL's `GL_POINTS`, `GL_LINES`, `GL_LINE_LOOP` and
`GL_LINE_STRIP`.
In order to support this, `LibSoftGPU`s rasterization logic was
reworked. Now, any primitive can be drawn by invoking `rasterize()`
which takes care of the quad loop and fragment testing logic. Three
callbacks need to be passed:
* `set_coverage_mask`: the primitive needs to provide initial coverage
mask information so fragments can be discarded early.
* `set_quad_depth`: fragments survived stencil testing, so depth values
need to be set so depth testing can take place.
* `set_quad_attributes`: fragments survived depth testing, so fragment
shading is going to take place. All attributes like color, tex coords
and fog depth need to be set so alpha testing and eventually,
fragment rasterization can take place.
As of this commit, there are four instantiations of this function:
* Triangle rasterization
* Points - aliased
* Points - anti-aliased
* Lines - anti-aliased
In order to standardize vertex processing for all primitive types,
things like vertex transformation, lighting and tex coord generation
are now taking place before clipping.
2022-05-08 02:13:14 +02:00
|
|
|
using AK::SIMD::expand4;
|
|
|
|
|
using AK::SIMD::f32x4;
|
|
|
|
|
using AK::SIMD::i32x4;
|
|
|
|
|
|
2022-01-06 16:55:08 +01:00
|
|
|
struct PixelQuad final {
|
2022-09-17 12:38:57 +02:00
|
|
|
void set_input(int index, f32x4 value) { inputs[index] = value; }
|
|
|
|
|
f32x4 get_input_float(int index) const { return inputs[index]; }
|
|
|
|
|
|
|
|
|
|
void set_input(int index, Vector4<f32x4> const& value)
|
|
|
|
|
{
|
|
|
|
|
inputs[index] = value.x();
|
|
|
|
|
inputs[index + 1] = value.y();
|
|
|
|
|
inputs[index + 2] = value.z();
|
|
|
|
|
inputs[index + 3] = value.w();
|
|
|
|
|
}
|
|
|
|
|
Vector4<f32x4> get_input_vector4(int index) const
|
|
|
|
|
{
|
|
|
|
|
return Vector4<f32x4>(
|
|
|
|
|
inputs[index],
|
|
|
|
|
inputs[index + 1],
|
|
|
|
|
inputs[index + 2],
|
|
|
|
|
inputs[index + 3]);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-17 17:16:31 +02:00
|
|
|
void set_output(int index, f32x4 value) { outputs[index] = value; }
|
|
|
|
|
f32x4 get_output_float(int index) const { return outputs[index]; }
|
|
|
|
|
|
|
|
|
|
void set_output(int index, Vector4<f32x4> const& value)
|
|
|
|
|
{
|
|
|
|
|
outputs[index] = value.x();
|
|
|
|
|
outputs[index + 1] = value.y();
|
|
|
|
|
outputs[index + 2] = value.z();
|
|
|
|
|
outputs[index + 3] = value.w();
|
|
|
|
|
}
|
|
|
|
|
Vector4<f32x4> get_output_vector4(int index) const
|
|
|
|
|
{
|
|
|
|
|
return Vector4<f32x4>(
|
|
|
|
|
outputs[index],
|
|
|
|
|
outputs[index + 1],
|
|
|
|
|
outputs[index + 2],
|
|
|
|
|
outputs[index + 3]);
|
|
|
|
|
}
|
|
|
|
|
|
LibGL+LibGPU+LibSoftGPU: Implement point and line drawing
Implement (anti)aliased point drawing and anti-aliased line drawing.
Supported through LibGL's `GL_POINTS`, `GL_LINES`, `GL_LINE_LOOP` and
`GL_LINE_STRIP`.
In order to support this, `LibSoftGPU`s rasterization logic was
reworked. Now, any primitive can be drawn by invoking `rasterize()`
which takes care of the quad loop and fragment testing logic. Three
callbacks need to be passed:
* `set_coverage_mask`: the primitive needs to provide initial coverage
mask information so fragments can be discarded early.
* `set_quad_depth`: fragments survived stencil testing, so depth values
need to be set so depth testing can take place.
* `set_quad_attributes`: fragments survived depth testing, so fragment
shading is going to take place. All attributes like color, tex coords
and fog depth need to be set so alpha testing and eventually,
fragment rasterization can take place.
As of this commit, there are four instantiations of this function:
* Triangle rasterization
* Points - aliased
* Points - anti-aliased
* Lines - anti-aliased
In order to standardize vertex processing for all primitive types,
things like vertex transformation, lighting and tex coord generation
are now taking place before clipping.
2022-05-08 02:13:14 +02:00
|
|
|
Vector2<i32x4> screen_coordinates;
|
|
|
|
|
Vector3<f32x4> barycentrics;
|
|
|
|
|
f32x4 depth;
|
2022-09-17 12:38:57 +02:00
|
|
|
Array<f32x4, NUM_SHADER_INPUTS> inputs;
|
2022-09-17 17:16:31 +02:00
|
|
|
Array<f32x4, NUM_SHADER_OUTPUTS> outputs;
|
LibGL+LibGPU+LibSoftGPU: Implement point and line drawing
Implement (anti)aliased point drawing and anti-aliased line drawing.
Supported through LibGL's `GL_POINTS`, `GL_LINES`, `GL_LINE_LOOP` and
`GL_LINE_STRIP`.
In order to support this, `LibSoftGPU`s rasterization logic was
reworked. Now, any primitive can be drawn by invoking `rasterize()`
which takes care of the quad loop and fragment testing logic. Three
callbacks need to be passed:
* `set_coverage_mask`: the primitive needs to provide initial coverage
mask information so fragments can be discarded early.
* `set_quad_depth`: fragments survived stencil testing, so depth values
need to be set so depth testing can take place.
* `set_quad_attributes`: fragments survived depth testing, so fragment
shading is going to take place. All attributes like color, tex coords
and fog depth need to be set so alpha testing and eventually,
fragment rasterization can take place.
As of this commit, there are four instantiations of this function:
* Triangle rasterization
* Points - aliased
* Points - anti-aliased
* Lines - anti-aliased
In order to standardize vertex processing for all primitive types,
things like vertex transformation, lighting and tex coord generation
are now taking place before clipping.
2022-05-08 02:13:14 +02:00
|
|
|
f32x4 fog_depth;
|
|
|
|
|
i32x4 mask;
|
|
|
|
|
f32x4 coverage { expand4(1.f) };
|
2022-01-06 16:55:08 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|