Commit graph

201 commits

Author SHA1 Message Date
Jelle Raaijmakers
d905de6a7a LibGL: Set correct matrices in glFrustum and glOrtho
We were erroneously setting the projection matrix when `GL_MODELVIEW`
was supplied.
2022-02-22 23:48:59 +00:00
Jelle Raaijmakers
5cf967e4f2 LibGL: Improve glFrustum precision and error handling
Do not convert to float too early. Additionally, handle some error
cases for the input parameters.
2022-02-22 23:48:59 +00:00
Jelle Raaijmakers
d92047c74d LibGL: Clamp color in glClearColor to 0..1 2022-02-22 23:48:59 +00:00
Jelle Raaijmakers
44a3d5c101 LibGL: Implement glClearDepthf and store as float
Our API still specifies it as a double, but internally we communicate a
float to the rasterizer. Additionally, clamp the value to 0..1 as
described in the spec.
2022-02-22 23:48:59 +00:00
Jelle Raaijmakers
36a732e98e LibGL: Ignore stack on projection and model view matrix retrieval
Our implementation keeps the top-most item on the matrix stacks in a
member variable, so we can always use that instead of considering the
actual stack.

Additionally, the current matrix mode should not influence retrieving
the projection or model view matrix.
2022-02-22 23:48:59 +00:00
Jelle Raaijmakers
7004b20656 LibGL+LibSoftGPU: Use more expressive is_power_of_two 2022-02-22 23:48:59 +00:00
Jelle Raaijmakers
506a857c3e LibGL: Use clamp<float> for depth range
We get `double`s as input, so convert them to `float` first.
2022-02-22 23:48:59 +00:00
Jelle Raaijmakers
db0616c67a LibSoftGPU: Generalize pixel buffers and standardize on BGRA8888
Between the OpenGL client and server, a lot of data type and color
conversion needs to happen. We are performing these conversions both in
`LibSoftGPU` and `LibGL`, which is not ideal. Additionally, some
concepts like the color, depth and stencil buffers should share their
logic but have separate implementations.

This is the first step towards generalizing our `LibSoftGPU` frame
buffer: a generalized `Typed3DBuffer` is introduced for arbitrary 3D
value storage and retrieval, and `Typed2DBuffer` wraps around it to
provide in an easy-to-use 2D pixel buffer. The color, depth and stencil
buffers are replaced by `Typed2DBuffer` and are now managed by the new
`FrameBuffer` class.

The `Image` class now uses multiple `Typed3DBuffer`s for layers and
mipmap levels. Additionally, the textures are now always stored as
BGRA8888, only converting between formats when reading or writing
pixels.

Ideally this refactor should have no functional changes, but some
graphical glitches in Grim Fandango seem to be fixed and most OpenGL
ports get an FPS boost on my machine. :^)
2022-02-22 23:48:59 +00:00
Jelle Raaijmakers
72ec2c21f4 LibGL: Remove superfluous AK::dbgln alias 2022-02-22 23:48:59 +00:00
Jelle Raaijmakers
011f6542db LibGL: Allow all primitives in glBegin()
We check for primitive support in `glEnd()`, so we do not need to
preemptively reject the mode in `glBegin()`. This allows `glBegin()` to
be invoked with `GL_POINTS`, for example.
2022-02-22 23:48:59 +00:00
Lenny Maiorani
229188b815 LibGL: Set rasterizer material state without copying
Each of the material faces is copied member by member then the copied
material state is passed by `const&` to another function, then
destroyed.

This is changed to simply passing the material state directly without
copying.
2022-01-27 20:35:38 +00:00
Lenny Maiorani
354017e01d LibGL: Set rasterizer light state without copying
There is a loop over the lights in which each light state is copied
member by member then the copied light state is passed by `const&` to
another function, then destroyed.

This is changed to simply passing the light state directly without
copying.
2022-01-27 20:33:46 +00:00
Jesse Buhagiar
371d49c0f6 LibGL: Implement glMateriali{v} 2022-01-26 16:44:11 +01:00
Jesse Buhagiar
170739fe39 LibGL: Implement glLighti{v} 2022-01-26 16:44:11 +01:00
Jesse Buhagiar
68e50759b4 LibGL: Implement glGetMaterial 2022-01-26 16:44:11 +01:00
Jesse Buhagiar
f5cde1b6fb LibGL: Implement glGetLight 2022-01-26 16:44:11 +01:00
Jelle Raaijmakers
a8655fbf52 LibGL+LibSoftGPU: Clean up some for loops 2022-01-20 10:35:01 +01:00
Jelle Raaijmakers
08826d60ad LibGL: Transpose matrix in glGetDoublev and glGetFloatv
We were returning row-major matrices when OpenGL clients are expecting
column-major instead.
2022-01-20 10:35:01 +01:00
Jelle Raaijmakers
c846ed0a2c LibGL: Report GL errors to debug console 2022-01-20 10:35:01 +01:00
Jelle Raaijmakers
c5abef86db LibGL: Stub GL_BACK implementation for glPolygonMode
This prevents overwriting the front face mode when providing `GL_BACK`
as a parameter.
2022-01-20 10:35:01 +01:00
Jelle Raaijmakers
453f62c935 LibGL+LibSoftGPU: Implement GL_POLYGON_OFFSET_FILL capability 2022-01-20 10:35:01 +01:00
Stephan Unverwerth
12f63df329 LibGL+LibSoftGPU: Support generation of multiple texture coordinates 2022-01-19 19:57:49 +01:00
Stephan Unverwerth
bc17a87450 LibGL: Also track active texture unit index
In addition to tracking a pointer to the active texture unit we also
track its index in the array.
2022-01-19 19:57:49 +01:00
Stephan Unverwerth
9627576d9c LibGL: Track multiple current texture coordinates in GLContext
Previously we only had a single current texture coordinate, set by
the glTexCoord family of functions. Since we now can have multiple
texture coordinates we track a vector of current texture coordinates
and set the requested one in glMultiTexCoord(). glTexCoord() Always sets
the first texture coordinate.
2022-01-19 19:57:49 +01:00
Stephan Unverwerth
a2c771a913 LibGL: Handle multiple texture coordinates in client state
This now tracks one vertex attribute pointer per texture unit and calls
glMultiTexCoord() to set the texture coordinates for the correct texture
unit.
2022-01-19 19:57:49 +01:00
Stephan Unverwerth
7571ef0343 LibGL+LibSoftGPU: Add multiple texture coordinates to vertex struct
We now have one set of texture coordinates per texture unit.
Texture coordinate generation and texture coordinate assignment is
currently only stubbed. This will be rectified in another commit.
2022-01-19 19:57:49 +01:00
Stephan Unverwerth
044582b0ce LibGL: Add stubs for multitexturing and announce GL_ARB_multitexture
This makes glquake recognize multitexture support and choose the
multitexture rendering path.
2022-01-19 19:57:49 +01:00
Stephan Unverwerth
d3d12c2fe7 LibGL: Generate GL extension string dynamically during construction
LibGL will now generate the GL extension string in the constructor and
refer to it later on when the string is queried via glGetString().
Currently we only check whether the device supports non-power-of-two
textures and add GL_ARB_texture_non_power_of_two to the supported
extensions in that case.
2022-01-19 19:57:49 +01:00
Jesse Buhagiar
865e7bbe5e LibGL+LibSoftGPU+3DFileViewer: Implement Specular highlighting :^) 2022-01-18 01:48:51 +02:00
Jesse Buhagiar
5bb8c14c8f LibGL+LibSoftGPU: Remove unused variable specular_exponent
This was a duplicate of the `Material::shininess` variable.
2022-01-18 01:48:51 +02:00
Jelle Raaijmakers
34a0f790a2 LibGL: Use number of lights from stored device info 2022-01-17 12:49:00 +01:00
Jelle Raaijmakers
11c807ebd1 LibGL+LibSoftGPU: Implement the stencil buffer
This implements an 8-bit front stencil buffer. Stencil operations are
SIMD optimized. LibGL changes include:

* New `glStencilMask` and `glStencilMaskSeparate` functions
* New context parameter `GL_STENCIL_CLEAR_VALUE`
2022-01-17 12:49:00 +01:00
Jelle Raaijmakers
6386671944 LibGL: Convert stencil front/back function and operation to Arrays 2022-01-17 12:49:00 +01:00
Jelle Raaijmakers
3609ffc450 LibGL+LibSoftGPU: Enumize material front/back face selection 2022-01-17 12:49:00 +01:00
Luke Wilde
c6a0365c58 LibGL+LibSoftGPU: Add support for 8-bit luminance (+ alpha) textures
Used by Half-Life for single colour textures. The alpha variant is
especially used for UI textures.
2022-01-15 12:58:00 +01:00
Jelle Raaijmakers
8efd6bc878 LibGL+LibSoftGPU: Implement glDrawPixels depth buffer support
This enabled writing directly to the depth buffer, and allows games
like Grim Fandango to render their pre-baked depth buffers correctly!
2022-01-14 21:38:09 +01:00
Jelle Raaijmakers
ca78327a96 LibGL+LibSoftGPU: Implement rasterization position
Implements support for `glRasterPos` and updating the raster position's
window coordinates through `glBitmap`. The input for `glRasterPos` is
an object position that needs to go through the same vertex
transformations as our regular triangles.
2022-01-14 21:38:09 +01:00
Jelle Raaijmakers
8e935ad3b1 LibGL+LibSoftGPU: Implement glColorMaterial and GL_COLOR_MATERIAL
When `GL_COLOR_MATERIAL` is enabled, specific material parameters can
be overwritten by the current color per-vertex during the lighting
calculations. Which parameter is controlled by `glColorMaterial`.

Also move the lighting calculations _before_ clipping, because the spec
says so. As a result, we interpolate the resulting vertex color instead
of the input color.
2022-01-13 12:13:58 +01:00
Jelle Raaijmakers
9d4c2f6308 LibGL+LibSoftGPU: Calculate spotlight cutoff angle as degrees
We were storing the radians but never using that value in the GPU. We
now directly use the degrees value.
2022-01-13 12:13:58 +01:00
Jelle Raaijmakers
8c28d167c9 LibGL: Report unsupported capabilities in glEnable and glDisable 2022-01-13 12:13:58 +01:00
Jelle Raaijmakers
c03b21f0ea LibGL: Make MaterialFace a simple u8 enum
Now we don't need to use `to_underlying` everywhere.
2022-01-13 12:13:58 +01:00
Jelle Raaijmakers
db1509c0de LibGL: Use C++ casts in glColor 2022-01-13 12:13:58 +01:00
Luke Wilde
1fc611877f LibGL: Implement glIsTexture
Required by Xash3D for the r_showtextures command, where it shows every
allocated texture on screen.

Description of glIsTexture from the spec:
"glIsTexture returns GL_TRUE if texture is currently the name of a
texture. If texture is zero, or is a non-zero value that is not
currently the name of a texture, or if an error occurs, glIsTexture
returns GL_FALSE.

A name returned by glGenTextures, but not yet associated with a texture
by calling glBindTexture, is not the name of a texture."

https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glIsTexture.xhtml
2022-01-13 12:13:40 +01:00
Luke Wilde
f91e41f90c LibGL: Generate texture in glBindTexture if not previously generated
Required by Xash3D, which forgoes glGenTexture and implements its own
texture generator. It expects glBindTexture to pick up on this though.

The strategy here is to keep texture_object null if we don't find the
texture in the allocation textures map, as it will then both generate
and set the texture in the allocated textures map using the texture
name passed to us, then bind it.
2022-01-13 10:07:45 +02:00
Jesse Buhagiar
4035532ee8 LibGL+LibSoftGPU: Pass along lighting flag to Software GPU
This was currently only set in the OpenGL context, as the previous
architecture did all of the transformation in LibGL before passing the
transformed triangles onto the rasterizer. As this has now changed, and
we require the vertex data to be in eye-space before we can apply
lighting, we need to pass this flag along as well via the GPU options.
2022-01-12 13:36:56 +01:00
Jesse Buhagiar
775ef000e0 LibGL+LibSoftGPU: Move lighting model parameters to SoftGPU
Most of the T&L stuff is, like on an actual GPU, now done inside of
LibSoftGPU. As such, it no longer makes sense to have specific values
like the scene ambient color inside of LibGL as part of the GL context.
These have now been moved into LibSoftGPU and use the same pattern as
the render options to set/get.
2022-01-12 13:36:56 +01:00
Jesse Buhagiar
92373ab0b6 LibGL: Flesh out glMaterialf{v}
These two functions have been turned from stubs into actually doing
something. They now set the correspondingmaterial data member based on
the value passed into the `pname`argument.

Co-authored-by: Stephan Unverwerth <s.unverwerth@serenityos.org>
2022-01-12 13:36:56 +01:00
Jesse Buhagiar
9118b0d164 LibGL: Support enabling/disabling lights via glEnable()/Disable() 2022-01-12 13:36:56 +01:00
Jesse Buhagiar
bf294612a7 LibGL: Implement glLightf{v} and fix gl.h prototype
This implements the `glLightf{v}` family of functions used to set
lighting parameters per light in the GL. It also fixes an incorrect
prototype for the user exposed version of `glLightf{v}` in which
`params` was not marked as `const`.
2022-01-12 13:36:56 +01:00
Jesse Buhagiar
192befa84b LibGL+LibSoftGPU: Add GL_MAX_LIGHTS to get_context_parameter
This is required to allow lighting to work properly in the GL. We
currently have the maximum number of lights in the software GL context
set to 8, as this is the minimum that OpenGL mandates according to the
spec.
2022-01-12 13:36:56 +01:00