Commit Graph

164 Commits

Author SHA1 Message Date
Jelle Raaijmakers
1a338844fa LibSoftGPU: Make Device statistics i64 again
They were erroneously converted into `u64` by me in a previous commit,
causing the overdraw statistic to go haywire.
2022-05-15 12:15:12 +02:00
RKBethke
0836912a6d LibGL+LibGPU+LibSoftGPU: Implement and expose glClipPlane
This commit implements glClipPlane and its supporting calls, backed
by new support for user-defined clip planes in the software GPU clipper.

This fixes some visual bugs seen in the Quake III port, in which mirrors
would only reflect correctly from close distances.
2022-05-11 23:09:47 +02:00
Jelle Raaijmakers
5861f1821e LibSoftGPU: Clamp polygon depth values to 0.f - 1.f
According to the OpenGL spec, we're expected to clamp the fragment
depth values to the range `0.f - 1.f` for all polygons.

This fixes Z-fighting issues with the sky in Quake 3.
2022-05-11 20:25:17 +02:00
Jelle Raaijmakers
b8c0ebccfd LibSoftGPU: Implement depth offset factor
This implements the depth offset factor that you can set through e.g.
OpenGL's `glPolygonOffset`. Without it, triangles might start to Z-
fight amongst each other.

This fixes the floor decals in Quake 3.
2022-05-10 19:36:41 +02:00
Jelle Raaijmakers
a20bf80b05 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-09 21:49:48 +02:00
Jelle Raaijmakers
950ded7ab9 LibSoftGPU: Mention correct i686 target in Device comment 2022-05-09 21:49:48 +02:00
Jelle Raaijmakers
7906ada015 LibSoftGPU: Update coverage mask bits during rasterization
We were not updating `coverage_bits` causing us to perform just a
little bit more work than strictly necessary.
2022-05-09 21:49:48 +02:00
Jelle Raaijmakers
e34e46ebb3 LibSoftGPU: Reference correct class in Typed2DBuffer comment
No functional changes.
2022-05-09 21:49:48 +02:00
Hendiadyoin1
d866637074 LibSoftGPU: Use round_to<int> in Device::get_rasterization_rect_of_size 2022-05-07 20:25:39 +02:00
Jelle Raaijmakers
a699e0a9d7 LibSoftGPU: Remove initial fog factor value from Device
This value was always overwritten. No functional changes.
2022-05-05 20:50:46 +02:00
Jelle Raaijmakers
526390ec06 LibSoftGPU: Move back to i32-based subpixels
Our move to floating point precision has eradicated the pixel artifacts
in Quake 1, but introduced new and not so subtle rendering glitches in
games like Tux Racer. This commit changes three things to get the best
of both worlds:

1. Subpixel logic based on `i32` types was reintroduced, the number of
   bits is set to 6. This reintroduces the artifacts in Quake 1 but
   fixes rendering of Tux Racer.

2. Before triangle culling, subpixel coordinates are calculated and
   stored in `Triangle`. These coordinates are rounded, which fixes the
   Quake 1 artifacts. Tux Racer is unaffected.

3. The triangle area (actually parallelogram area) is also stored in
   `Triangle` so we don't need to recalculate it later on. In our
   previous subpixel code, there was a subtle disconnect between the
   two calculations (one with and one without subpixel precision) which
   resulted in triangles incorrectly being culled. This fixes some
   remaining Quake 1 artifacts.
2022-05-05 20:50:46 +02:00
Jelle Raaijmakers
f5ea93edfd LibSoftGPU: Remove unused Matrix3x3.h include 2022-05-05 20:50:46 +02:00
Jelle Raaijmakers
e70dc20650 LibSoftGPU: Replace some interpolate() calls with VectorN::dot
The dot product is effectively the same as `interpolate()`, allowing us
to use `VectorN`. No functional changes.
2022-05-05 20:50:46 +02:00
Jelle Raaijmakers
dfb218f6a8 LibSoftGPU: East-const interpolate
No functional changes.
2022-05-05 20:50:46 +02:00
Jelle Raaijmakers
9a1364d784 LibSoftGPU: Use FloatVector4 pixel format for Image
This increases memory usage for textures 4-fold, but allows us to
completely remove calls to `(un)pack_color` in a very hot loop.
2022-05-05 20:50:46 +02:00
Jelle Raaijmakers
6090e79191 LibSoftGPU: Use u64 for Device statistics vars
No functional changes.
2022-05-05 20:50:46 +02:00
Jelle Raaijmakers
e1a6966863 LibSoftGPU: Check for bottom edge in top-left rule in Device
If a triangle edge is completely horizontal and moving in a positive X
direction, we were erroneously treating it as a top edge. This adds
a better check that accounts for those edges. :^)
2022-04-20 14:12:56 +02:00
Jelle Raaijmakers
838cee37a2 LibSoftGPU: Simplify Clipper interpolation
By setting the clip plane normals' W coordinate to 1, we can skip two
coordinate retrievals and three additions. This works because the
Vector `.dot()` operation multiplies the W coordinates of both vectors.
2022-04-20 14:12:56 +02:00
Jelle Raaijmakers
f680d82086 LibSoftGPU: Reuse edge function for front/back culling
We sat on a throne of lies: our `edge_function()` returned positive
values for _clockwise_ vertex rotation instead of _counter-clockwise_,
which was hidden by the fact that we were forcing everything into CW
rotation by an erroneous area comparison (`> 0` instead of `< 0`).

This simplifies our culling code significantly.
2022-04-20 14:12:56 +02:00
Jelle Raaijmakers
26a463506e LibSoftGPU: Use AK::abs directly instead of fabsf
Let's not go through LibC.
2022-04-20 14:12:56 +02:00
Jelle Raaijmakers
4c1d8a7785 LibSoftGPU: Optimize clipping code
Three optimizations are applied:

1. If the list of vertices to clip is empty, return immediately after
   clearing the output list.

2. Remember the previous vertex instead of recalculating whether it is
   within the clip plane.

3. Instead of copying and swapping lists around, operate on the input
   and output lists directly. This prevents a lot of `malloc`/`free`
   traffic as a result of vector assignments.

This takes the clipping code CPU load from 3.9% down to 1.8% for
Quake 3 on my machine.
2022-04-11 19:31:23 -07:00
Jelle Raaijmakers
60fccdbd71 LibSoftGPU: Remove superfluous braces in Clipper 2022-04-11 19:31:23 -07:00
Jesse Buhagiar
c9f44c746a LibGL+LibSoftGPU: Add GL_ADD Texture Environment 2022-04-09 11:40:33 +02:00
Stephan Unverwerth
5bb76e9b63 LibGL+LibGPU+LibSoftGPU: Load SoftGPU driver dynamically
This loads libsoftgpu.so during GLContext creation and instantiates the
device class which is then passed into the GLContext constructor.
2022-04-06 11:32:24 +02:00
Stephan Unverwerth
211d24a218 LibGL+LibGPU+LibSoftGPU: Add virtual base class for devices
This adds a virtual base class for GPU devices located in LibGPU.
The OpenGL context now only talks to this device agnostic interface.

Currently the device interface is simply a copy of the existing SoftGPU
interface to get things going :^)
2022-04-06 11:32:24 +02:00
Stephan Unverwerth
4a99875582 LibGL+LibGPU+LibSoftGPU: Add virtual base class for Images
This introduces a new device independent base class for Images in LibGPU
that also keeps track of the device from which it was created in order
to prevent assigning images across devices.
2022-04-06 11:32:24 +02:00
Stephan Unverwerth
1f3642ed48 LibGPU+LibSoftGPU: Move RasterizerOptions into LibGPU 2022-04-06 11:32:24 +02:00
Stephan Unverwerth
5d2740217f LibGL+LibGPU+LibSoftGPU: Move Vertex.h to LibGPU 2022-04-06 11:32:24 +02:00
Stephan Unverwerth
5bf224708f LibGPU+LibSoftGPU: Move LightModelParameters into LibGPU 2022-04-06 11:32:24 +02:00
Stephan Unverwerth
5a5596b381 LibGL+LibGPU+LibSoftGPU: Move TexCoordGenerationConfig into LibGPU 2022-04-06 11:32:24 +02:00
Stephan Unverwerth
8f359bf758 LibGPU+LibSoftGPU: Move RasterPosition into its own header in LibGPU 2022-04-06 11:32:24 +02:00
Stephan Unverwerth
e416380826 LibGL+LibGPU+LibSoftGPU: Move StencilConfiguration.h to LibGPU 2022-04-06 11:32:24 +02:00
Stephan Unverwerth
b652db1f54 LibGL+LibGPU+LibSoftGPU: Move Material.h to LibGPU 2022-04-06 11:32:24 +02:00
Stephan Unverwerth
7da9447619 LibGL+LibGPU+LibSoftGPU: Move Light.h to LibGPU 2022-04-06 11:32:24 +02:00
Stephan Unverwerth
e7450fa940 LibGL+LibGPU+LibSoftGPU: Move SamplerConfig to LibGPU 2022-04-06 11:32:24 +02:00
Stephan Unverwerth
54307a9cd3 LibGL+LibGPU+LibSoftGPU: Move ImageDataLayout.h to LibGPU 2022-04-06 11:32:24 +02:00
Stephan Unverwerth
4e0643ae97 LibGL+LibGPU+LibSoftGPU: Move ImageFormat.h to LibGPU 2022-04-06 11:32:24 +02:00
Stephan Unverwerth
24d420312c LibGL+LibGPU+LibSoftGPU: Move Enums.h to LibGPU 2022-04-06 11:32:24 +02:00
Stephan Unverwerth
ac033dd9b6 LibGL+LibGPU+LibSoftGPU: Move DeviceConfig to LibGPU
This introduces a new abstraction layer, LibGPU, that serves as the
usermode interface to GPU devices. To get started we just move the
DeviceConfig there and make sure everything still works :^)
2022-04-06 11:32:24 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Jelle Raaijmakers
8a3242cb83 LibGL+LibSoftGPU+LibGfx: Reimplement normal transformation
We now support generating top-left submatrices from a `Gfx::Matrix`
and we move the normal transformation calculation into
`SoftGPU::Device`. No functional changes.
2022-03-27 09:19:43 -07:00
Jelle Raaijmakers
bc5e5afc7b LibSoftGPU+LibGfx: Transform and normalize normals before lighting
We were transforming the vertices' normals twice (bug 1) and
normalizing them after lighting (bug 2). In the lighting code, we were
then diverting from the spec to deal with the normal situation, which
is now no longer needed.

This fixes the lighting of Tux in Tux Racer.
2022-03-27 09:19:43 -07:00
Jelle Raaijmakers
23476dac64 LibSoftGPU: Clean up Material initial value style 2022-03-27 09:19:43 -07:00
Jelle Raaijmakers
284a629ab4 LibGL+LibSoftGPU: Implement more of GL_LIGHT_MODEL_COLOR_CONTROL
This gets rid of a place where OpenGL was leaking into LibSoftGPU.
2022-03-27 09:19:43 -07:00
Jelle Raaijmakers
ae88c642c6 LibSoftGPU: Test for 1.f equality in determining the scale factor
We are still not doing the right thing here, but using `<=` instead of
`<` at least gets rid of artifacts in Grim Fandango.
2022-03-27 09:19:43 -07:00
Lenny Maiorani
759857b597 LibSoftGPU: Avoid copying data when doing triangle rasterization
Several large-ish objects shouldn't be copied to the stack when a
reference will do.
2022-03-18 23:41:06 +00:00
Jelle Raaijmakers
870b835115 LibGfx+LibSoftGPU: Allow indexed reads into Gfx::Vector 2022-03-11 12:30:43 +01:00
Jelle Raaijmakers
20a5a4363c LibSoftGPU: Remove unused vector types from Device 2022-03-11 12:30:43 +01:00
Jelle Raaijmakers
3ece3f3ed1 LibSoftGPU: Remove a lot of [ui]32x4 casts in Sampler 2022-03-08 15:32:35 +01:00
Stephan Unverwerth
8165346ae4 LibSoftGPU: Choose correct texture filter based on scale factor
Previously the test determining whether to use texture maginifaction or
texture minification was reversed. This commit fixes the test and also
provides an early out of the sampler in case of texture magnification
since magnification does not make use of mipmaps.
2022-03-08 00:49:31 +02:00