Commit graph

201 commits

Author SHA1 Message Date
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
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
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
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
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
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
Stephan Unverwerth
39995548e4 LibGL+LibSoftGPU: Add method to query device info
This adds a method `info()` to SoftGPU that returns the name of the
hardware vendor and device name, as well as the number of texture untis.

LibGL uses the returned texture unit count to initialize its internal
texture unit array.
2021-12-24 05:10:28 -08:00
Stephan Unverwerth
f7c40b25ac LibSoftGPU: Remove GLenum used for selecting rendered primitive type
This removes the last reference to LibGL from LibSoftGPU. The GLenum
has been replaced by our own enum.
2021-12-24 05:10:28 -08:00
Stephan Unverwerth
de0069188f LibSoftGPU: Remove OpenGL type for polygon mode
Replaces the GLenum used to setup polygon mode in RasterizerOptions with
our own enum.
2021-12-24 05:10:28 -08:00
Stephan Unverwerth
f4d29bf665 LibSoftGPU: Remove OpenGL type for fog mode
Replaces the GLenum used to set up the fog mode in RasterizerOptions
with out own enum.
2021-12-24 05:10:28 -08:00
Stephan Unverwerth
74ed7713fa LibSoftGPU: Remove OpenGL type for depth test func
Replaces the GLenum used in the RasterizerConfig for selecting the depth
test function with out own enum.
2021-12-24 05:10:28 -08:00
Stephan Unverwerth
33e601800c LibSoftGPU: Remove OpenGL type for draw buffer selection
Replaces the GLenum used in RasterizerConfig to select the draw buffer
with a simple boolean that disabled color output when the draw buffer
is set to GL_NONE on the OpenGL side.
2021-12-24 05:10:28 -08:00
Stephan Unverwerth
1904be0370 LibSoftGPU: Remove OpenGL type for culled side selection
Replaces the GLenum in RasterizerConfig, that selects the triangle sides
to be culled, with two booleans.
2021-12-24 05:10:28 -08:00
Stephan Unverwerth
24c76741e8 LibSoftGPU: Remove OpenGL type for front face selection
Replaces the GLenum used for selecting the frontface in the rasterizer
config with out own enum.
2021-12-24 05:10:28 -08:00
Stephan Unverwerth
c720cd00db LibSoftGPU: Remove OpenGL type for alpha blend factors
Replaces the GLenum used for configuring alpha blend factors in the
SoftGPU device with out own enum.
2021-12-24 05:10:28 -08:00
Stephan Unverwerth
40bd73bdef LibSoftGPU: Remove OpenGL type for alpha test func
Replaces the OpenGL enum used for setting the alpha test func in
RasterizerOptions with out own enum.
2021-12-24 05:10:28 -08:00
Stephan Unverwerth
d8c17c8838 LibGL+LibSoftGPU: Use device samplers for rendering
We now sample textures from the device owned image samplers.
Passing of enabled texture units has been simplified by only passing a
list of texture unit indices.
2021-12-24 05:10:28 -08:00
Stephan Unverwerth
f69de5e850 LibGL: Synchronize device config before rendering if anything changed 2021-12-24 05:10:28 -08:00
Stephan Unverwerth
39545d4b49 LibGL: Attach device image to texture object and upload image data 2021-12-24 05:10:28 -08:00
Stephan Unverwerth
a9e27b9a0f LibSoftGPU: Rename class SoftwareRasterizer to Device
This class does everything related to rendering now. It is the software
implementation of a full GPU device.
2021-12-24 05:10:28 -08:00
Stephan Unverwerth
178b28b469 LibGL: Remove unused GLStruct.h 2021-12-24 05:10:28 -08:00
Stephan Unverwerth
251f3c007f LibGL+LibSoftGPU: Move Vertex and Triangle structs to LibSoftGPU 2021-12-24 05:10:28 -08:00
Stephan Unverwerth
73ba208ee7 LibGL+LibSoftGPU: Move primitive assembly and clipping into LibSoftGPU 2021-12-24 05:10:28 -08:00
Stephan Unverwerth
2f35135743 LibGL+LibSoftGPU: Add face culling state to rasterizer options 2021-12-24 05:10:28 -08:00
Stephan Unverwerth
ad3d5d43bd LibGL+LibSoftGPU: Move rendering related code to LibSoftGPU library
This introduces a new library, LibSoftGPU, that incorporates all
rendering related features that formerly resided within LibGL itself.

Going forward we will make both libraries completely independent from
each other allowing LibGL to load different, possibly accelerated,
rendering backends.
2021-12-24 05:10:28 -08:00
Jelle Raaijmakers
7fa2e792a8 LibGL: Simplify glDrawPixels checks and reduce debug spam 2021-12-21 12:58:58 -08:00
Jelle Raaijmakers
a1fb16e89c LibGL: Implement GL_POLYGON rendering
This is a deprecated feature that is still in use in some older games,
most notably Grim Fandango in ScummVM makes heavy use of it.

Luckily, since you can only draw convex polygons, the end result is
exactly the same as when you would have used `glBegin(GL_TRIANGLE_FAN)`
- so we just reuse that code as-is.
2021-12-21 12:58:58 -08:00
Jelle Raaijmakers
604eea5827 LibGL: Allow querying maximum matrix stack depths 2021-12-21 12:58:58 -08:00
Jelle Raaijmakers
18399d00fa LibGL: Implement matrix mode GL_TEXTURE
Implement support for the `GL_TEXTURE` matrix mode, the texture matrix
stack and texture coordinate matrix transformation.

Also, an unused `m_current_matrix` was removed to make room for
`m_texture_matrix`.
2021-12-21 12:58:58 -08:00
Jelle Raaijmakers
4703e8cbcf LibGL: Make texture coordinates a FloatVector4
In OpenGL, texture coordinates can have up to 4 values. This change
will help with easy application of texture coordinate matrix
transformations in the future.

Additionally, correct the initial value for texture coordinates to
`{ 0.f, 0.f, 0.f, 1.f}`.
2021-12-21 12:58:58 -08:00
Jelle Raaijmakers
4e3ed16527 LibGL: Only pass bound texture units to rasterizer
Before, `SoftwareRasterizer` was iterating over all 32 possible texture
units for each fragment and checking each if they're bound to a texture.

After this change, an intrusive list containing only texture units with
bound textures is passed to the rasterizer. In GLQuake, this results in
a performance improvement of ~30% (from 12 to 16 FPS in the first demo)
on my machine.
2021-12-20 10:36:53 -08:00
Jelle Raaijmakers
212334eaef LibGL: Simplify Texture2D reading; add support for RGB565 2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
12c4491cca LibGL: Prevent limbo state if glEnd does not support drawing mode
If an unsupported drawing mode was configured, `glEnd` would not reach
the line where `m_in_draw_state` was set to `false`. This caused all
subsequent invocations to `glBegin` to fail.
2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
46c564dd1a LibGL: Invoke own methods when drawing arrays or elements
Instead of calling the public API, call our own internal API.
2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
a06b69c5b5 LibGL: Implement the GL_DITHER parameter 2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
b89524c981 LibGL: Implement the GL_LIGHTING parameter 2021-12-12 21:51:08 +01:00