Commit graph

392 commits

Author SHA1 Message Date
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
Luke Wilde
53d6e1600c LibGL: Stub glStencilMask
Xash3D requires this otherwise it will crash with a jump to nullptr,
but it doesn't use it for anything interesting and just sets a default
value of ~0 during initialization.
2022-01-13 10:07:45 +02:00
Luke Wilde
cba1972deb LibGL: Implement glTexCoord{1,3,4}f(v)
Not necessarily required by Half-Life's use of Xash3D, but it looks
them up anyway and they're easy to implement, so here they are :^).
2022-01-13 10:07:45 +02:00
Jelle Raaijmakers
a4e2d93aa2 Ports+LibGL: Replace LibGL context check by ScummVM patch
According to the OpenGL spec, invoking functions without an active
context results in undefined behavior. Since ScummVM seems to be the
only port having issues with our behavior, patch their code instead.
2022-01-12 14:54:18 +01: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
Jelle Raaijmakers
a41d5ffa1e LibGfx+LibGL: Allow singular matrices to be inverted
This is basically the old behavior before the GLtron port was
introduced, but `.inverse()` no longer crashes if the matrix is
singular.
2022-01-12 01:08:38 +01:00
Jelle Raaijmakers
1c2e07d42a LibGL: Set q parameter for glTexCoord to 1 by default
According to the manual, if `q` is not specified, it is 1.
2022-01-11 23:47:42 +01:00
Jelle Raaijmakers
260663567a LibGL: Implement glTexCoord2i 2022-01-11 23:47:42 +01:00
Jelle Raaijmakers
69eb3b0838 LibGL: Remove duplicate private: from SoftwareGLContext.h 2022-01-11 23:47:42 +01:00
Jelle Raaijmakers
a4a666152b LibGfx+LibGL: Do not crash if matrix inverse does not exist
Allow `Matrix::inverse()` to return an error and deal with those in
LibGL. Also use this opportunity to more efficiently calculate the
transpose of the model view matrix for the normal transformation.
2022-01-11 23:47:42 +01:00
Jelle Raaijmakers
03c1f1780d LibGL: Stub glPointSize 2022-01-11 23:47:42 +01:00
Jelle Raaijmakers
6363797e80 LibGL: Implement glLightModeli 2022-01-11 23:47:42 +01:00
Jelle Raaijmakers
e2f79c8b5f LibGL: Implement glTexEnvi 2022-01-11 23:47:42 +01:00
Jelle Raaijmakers
eea1b95ead LibGL: Implement glRotated 2022-01-11 23:47:42 +01:00
Jelle Raaijmakers
a29534b531 LibGL: Implement glColor3d and glColor3ubv 2022-01-11 23:47:42 +01:00
Jelle Raaijmakers
57b1dcbec9 LibGL: Add stub for glColorMaterial 2022-01-09 23:23:01 +01:00
Jelle Raaijmakers
7ad18e91e2 LibGL: Add capabilities to context parameters
Context parameters are LibGL's way of centrally defining all parameters
that can be retrieved through `glGetBoolean*`, `glGetInteger*`, etc.
The spec describes that capabilities such as `GL_LIGHTING` can also be
retrieved through these methods, but it should not be possible to
retrieve random boolean parameters through `glIsEnabled`. For example,
`GL_UNPACK_LSB_FIRST` can only be retrieved through `glGet*`.

This moves reading of capabilities to `::get_context_parameter` and
implements its use in `::gl_is_enabled`.
2022-01-09 23:21:03 +01:00
Jelle Raaijmakers
29bbf56286 LibGL+LibSoftGPU: Implement viewport support
This implements the `glViewport` API call, the coordinate
transformation and the `GL_VIEWPORT` context parameter.
2022-01-09 20:22:32 +01:00
Jelle Raaijmakers
c19632128c LibGL+LibSoftGPU: Implement texture coordinate generation
Texture coordinate generation is the concept of automatically
generating vertex texture coordinates instead of using the provided
coordinates (i.e. `glTexCoord`).

This commit implements support for:

* The `GL_TEXTURE_GEN_Q/R/S/T` capabilities
* The `GL_OBJECT_LINEAR`, `GL_EYE_LINEAR`, `GL_SPHERE_MAP`,
  `GL_REFLECTION_MAP` and `GL_NORMAL_MAP` modes
* Object and eye plane coefficients (write-only at the moment)

This changeset allows Tux Racer to render its terrain :^)
2021-12-30 14:24:29 +01:00
Jelle Raaijmakers
fef7f7159c LibGL+LibSoftGPU: Implement eye, clip, NDC and window coordinates
This follows the OpenGL 1.5 spec much more closely. We need to store
the eye coordinates especially, since they are used in texture
coordinate generation and fog fragment depth calculation.
2021-12-30 14:24:29 +01:00
Jelle Raaijmakers
e4080aed00 LibGL: Use standard debug message for gl_materialv 2021-12-30 14:24:29 +01:00
Jelle Raaijmakers
92ecd66490 LibGL: Reduce nesting levels in gl_tex_env 2021-12-30 14:24:29 +01:00
Jelle Raaijmakers
8cf91a5ae5 LibGL: Change gl_tex_gen param to GLint
The singular form of `glTexGeni/f/d` only supports constants, not
floating point values as its parameter.
2021-12-30 14:24:29 +01:00
Jelle Raaijmakers
f2d8fcb830 LibGL: Remove glPush/PopMatrix debug spam
Even behind the `GL_DEBUG` macro this was too noisy.
2021-12-30 14:24:29 +01:00
Jelle Raaijmakers
3a5f69b6f3 LibGL+LibSoftGPU: Implement normalization of normals
* LibGL now supports the `GL_NORMALIZE` capability
* LibSoftGPU transforms and normalizes the vertices' normals

Normals are heavily used in texture coordinate generation, to be
implemented in a future commit.
2021-12-30 14:24:29 +01:00
Jelle Raaijmakers
9bc8587c0d LibGL: Implement fog in GL_LINEAR mode
The `GL_LINEAR` param was erroneously not picked up on. Also implement
support for `GL_FOG_START` and `GL_FOG_END`, and make sure that the
`gl_fog*` family of functions are optionally registered with the active
list.
2021-12-30 14:24:29 +01:00
Jelle Raaijmakers
d9ea1fe4c9 LibGL: Implement GL_QUAD_STRIP
It seems like we can render this with `GL_TRIANGLE_STRIP`. This makes
the track marks in Tux Racer work.
2021-12-27 11:58:43 +01:00
Jelle Raaijmakers
7833f25f8f LibGL: Remove stubbed border from glTexImage2D
Providing anything else than `border == 0` is deprecated and should
result in an invalid value error.
2021-12-27 11:58:43 +01:00
Jelle Raaijmakers
b2e75929f4 LibGL: Implement GL_LINEAR_MIPMAP_NEAREST support 2021-12-27 11:58:43 +01:00
Jelle Raaijmakers
ccf6769d95 LibGL: Stub more API calls
These stubs are largely implemented the same: their API is exposed, but
they print to the debug console and sometimes `TODO()`. These changes
allow GLU and Tux Racer to build.

Methods stubbed:

* `glTexImage1D`
* `glTexImage3D`
* `glTexCoord2d(v)`
* `glNormalPointer`
* `glTexGen(d|f|i)`
* `glTexGenfv`
2021-12-27 11:58:43 +01:00
Jelle Raaijmakers
abecff1766 LibGL: Stub lots of map-related methods
This adds stubs for `glMap(1|2)(d|f)`, `glMapGrid(1|2)(d|f)`,
`glEvalCoord(1|2)(d|f)`, `glEvalMesh(1|2)` and `glEvalPoint(1|2)`.
2021-12-27 11:58:43 +01:00
Jelle Raaijmakers
dae63352a3 LibGL: Implement glGetTexLevelParameteriv 2021-12-27 11:58:43 +01:00
Jelle Raaijmakers
d83702cb92 LibGL: Implement glRectf and glRecti 2021-12-27 11:58:43 +01:00
Jelle Raaijmakers
4a36d6b439 LibGL: Implement glMultMatrixd 2021-12-27 11:58:43 +01:00
Jelle Raaijmakers
b455e6ca0d LibGL: Stub glClear support for stencil buffer
Previously, if the client supplied `GL_STENCIL_BUFFER_BIT`, `glClear`
would return an error. Since it is a valid parameter, we now continue
and report that this parameter is unimplemented instead.
2021-12-27 11:58:43 +01:00
Jelle Raaijmakers
688adba1a8 LibGL: Uncrash glMaterialf on invalid input
We should handle this in the context.
2021-12-27 11:58:43 +01:00
Jelle Raaijmakers
9e9e1c7634 LibGL: Implement glColor3/4dv 2021-12-27 11:58:43 +01:00
Jelle Raaijmakers
3883b42764 LibGL: Stub GL_(UN)PACK_* context parameters
Libraries like GLU depend on their memory initialization by requesting
these parameters, so if we do not support them, segfaults will occur.
2021-12-27 11:58:43 +01:00
Jelle Raaijmakers
70c6907546 LibGL: Add glext.h and lots of new defines in gl.h
These constants are used by GLU and Tux Racer.
2021-12-27 11:58:43 +01:00