Commit graph

226 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 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
Jelle Raaijmakers 2ce73b31b6 LibGL: Extract platform types to glplatform.h 2021-12-27 11:58:43 +01:00
Stephan Unverwerth 5e9d99474d LibGL: Remove image storage from MipMap
Images are stored on the device side. Texture2D and MipMap are now only
used to store imformation about the texture and reference to the device
image.
2021-12-24 05:10:28 -08:00
Stephan Unverwerth 4c944eaa41 LibGL: Remove sampling code from Sampler2D
Texture sampling now happens entirely in SoftGPU thus this class will
now only be used to hold the sampler configuration.
2021-12-24 05:10:28 -08: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