Commit Graph

10 Commits

Author SHA1 Message Date
Jelle Raaijmakers
84c4b66721 LibGL+LibGPU+LibSoftGPU: Implement texture pixel format support
In OpenGL this is called the (base) internal format which is an
expectation expressed by the client for the minimum supported texel
storage format in the GPU for textures.

Since we store everything as RGBA in a `FloatVector4`, the only thing
we do in this patch is remember the expected internal format, and when
we write new texels we fixate the value for the alpha channel to 1 for
two formats that require it.

`PixelConverter` has learned how to transform pixels during transfer to
support this.
2022-08-27 12:28:05 +02:00
Jelle Raaijmakers
eb7c3d16fb LibGL+LibGPU+LibSoftGPU: Implement flexible pixel format conversion
A GPU (driver) is now responsible for reading and writing pixels from
and to user data. The client (LibGL) is responsible for specifying how
the user data must be interpreted or written to.

This allows us to centralize all pixel format conversion in one class,
`LibSoftGPU::PixelConverter`. For both the input and output image, it
takes a specification containing the image dimensions, the pixel type
and the selection (basically a clipping rect), and converts the pixels
from the input image to the output image.

Effectively this means we now support almost all OpenGL 1.5 formats,
and all custom logic has disappeared from:
  - `glDrawPixels`
  - `glReadPixels`
  - `glTexImage2D`
  - `glTexSubImage2D`

The new logic is still unoptimized, but on my machine I experienced no
noticeable slowdown. :^)
2022-08-27 12:28:05 +02:00
sin-ack
3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
Luke Wilde
971d6ce16f LibGL: Reject GL_LEFT and GL_RIGHT in glCullFace
glCullFace only accepts GL_FRONT, GL_BACK and GL_FRONT_AND_BACK.
We checked if the mode was valid by performing
```
cull_mode < GL_FRONT || cull_mode > GL_FRONT_AND_BACK
```

However, this range also contains GL_LEFT and GL_RIGHT, which we would
accept when we should return a GL_INVALID_ENUM error.
2022-06-04 22:25:16 +01:00
Luke Wilde
bc5dd8dd0f LibGL: Check that texture name is allocated before marking it as free
glDeleteTextures previously did not check that the texture name was
allocated by glGenTextures before adding it to the free texture name
list.

This means that if you delete a texture twice in a row, the name will
appear twice in the free texture list, making glGenTextures return the
same texture name twice in a row.
2022-06-02 13:14:39 +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
65d4fb7649 LibGL: Set W-coordinate to 1 in glRect*
According to the spec, these calls should be identical to an invocation
of `glVertex2*`, which sets the W-coordinate to 1 by default.

This fixes the credits sequence rendering of Tux Racer.
2022-04-20 14:12:56 +02:00
Jelle Raaijmakers
8cfabbcd93 Tests: Implement reference image testing for LibGL
Each LibGL test can now be tested against a reference QOI image.
Initially, these images can be generated by setting `SAVE_OUTPUT` to
`true`, which will save a bunch of QOI images to `/home/anon`.
2022-04-17 09:58:29 +04:30
Simon Wanner
206d6ece55 LibGfx: Move other font-related files to LibGfx/Font/ 2022-04-09 23:48:18 +02:00
Hendiadyoin1
7a27ecc135 Tests: Add a simple LibGL render-test
At the moment we just check if we *can* render a simple triangle, we do
not yet actually test if the image is indeed the triangle we wanted.

This test also outputs the rendered image when GL_DEBUG is enabled to a
file called "picture.bmp" for manual verification.

Co-authored-by: sunverwerth <s.unverwerth@serenityos.org>
2021-11-29 23:17:05 +03:30