Commit graph

158 commits

Author SHA1 Message Date
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
Jelle Raaijmakers
b1ac181537 LibGL: Centralize all context parameters
The `glGet*` family of functions requires that all parameters of
different types are transparently converted into each other. For
example, you can request a boolean parameter as a float or a list of
double values as an integer. It might be considered bad practice to
request parameters through the wrongly-typed function, but to be spec-
compliant we need to implement this.

Introduce a new `::get_context_parameter()` to obtain a parameter
value, which is then converted to the right type by the respective
`::gl_get_*()` functions.
2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
2af9b625e8 LibGL: Implement GL_*_BITS and GL_DOUBLEBUFFER parameters 2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
033f224966 LibGL: Add GL_SHADING_LANGUAGE_VERSION to glGetString 2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
6643775999 LibGL: Add stub for glCopyTexImage2D 2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
401472c9a4 LibGL: Implement glDrawPixels and add stub for glBitmap 2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
c2960e68a8 LibGL: Implement glLightModelf and glLightModelfv 2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
0453cad46c LibGL: Add stubs for glPushAttrib and glPopAttrib 2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
fbed7a5ba8 LibGL: Implement glLineWidth 2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
506abf2a61 LibGL: Implement glIsList 2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
9c9fa33495 LibGL: Implement glClearStencil 2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
9dbc8d7e3c LibGL: Add stubs for glMaterialf and glMaterialfv 2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
4eb6295a57 LibGL: Implement glRasterPos2i 2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
78d0674228 LibGL: Implement glNormal3f and glNormal3fv 2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
ea6bcda79c LibGL: Implement glStencil* functions
This implements the context state for stencil testing functions and
operations. No rasterization is implemented.
2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
729349ce78 LibGL: Implement GL_STENCIL_TEST
Only the state is implemented; not the rasterization phase.
2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
11fea6b597 LibGL: Implement glListBase 2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
1056bac49a LibGL: Implement glCallLists 2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
7ac8cd057e LibGL: Implement glMultMatrixf 2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
40724a426f LibGL: Implement glGetDoublev 2021-12-12 21:51:08 +01:00
Jelle Raaijmakers
0be2a76ee7 LibGL: Use simpler syntax for GL_SCISSOR_BOX retrieval 2021-12-11 23:15:24 +01:00
Jelle Raaijmakers
7ad70f623e LibGL: Make glDeleteTextures skip over 0 names
As stated in the manual:
     glDeleteTextures silently ignores 0's and names that do not
     correspond to existing textures.

If we do not skip these 0 names, they end up as invalid free texture
names in our name allocator.
2021-12-11 23:15:24 +01:00
Jelle Raaijmakers
4abd6aa198 LibGL: Remove unnecessary break; from SoftwareGLContext 2021-12-11 23:15:24 +01:00
Jelle Raaijmakers
5e370e6f96 LibGL: Implement GL_(UN)PACK_ALIGNMENT
These enums are used to indicate byte-alignment when reading from and
to textures. The `GL_UNPACK_ROW_LENGTH` value was reimplemented to
support overriding the source data row width.
2021-12-11 23:15:24 +01:00
Jelle Raaijmakers
bed0f3466a LibGL: Remove TextureUnit::unbind_texture() 2021-12-01 10:21:13 +01:00
Jelle Raaijmakers
5788a139d8 LibGL: Implement texture unit texturing states 2021-12-01 10:21:13 +01:00
Jelle Raaijmakers
bb58f6ccab LibGL: Implement glScissor() 2021-11-28 09:20:58 -08:00
Jelle Raaijmakers
a36ee213b9 LibGL: Implement glIsEnabled() 2021-10-17 21:01:52 -07:00
Jelle Raaijmakers
b2627c8b74 LibGL: Implement disabling GL_FOG 2021-10-17 21:01:52 -07:00
Stephan Unverwerth
e7d3483618 LibGL: Implement glTexSubImage2D 2021-09-02 21:00:24 +04:30
Stephan Unverwerth
e34fc4e336 LibGL: Support additional enums in glGetIntegerv
GL_MAX_TETXURE_UNITS: Returns the available units for multitexturing
GL_MAX_TETXURE_SIZE: Returns the maximum width/height for textures
2021-09-02 21:00:24 +04:30
Stephan Unverwerth
7c60f4bbab LibGL: Fix glTexImage2D texture dimension validation
This now verifies that width and height are a power of 2. The previous
check was nonsensical, probably because it was written against a spec
with improper text formatting, turning 2^x into 2*x :^)
2021-09-02 21:00:24 +04:30
Stephan Unverwerth
05a7a4640d LibGL: Allow numerical internal formats in glTexImage2D
Prior to version 1.1 OpenGL only allowed the numbers 1,2,3 and 4 to be
used as internal texture formats. Symbolic constants were introduced
first with the EXT_texture extension and then later adopted into the
core profile.
2021-09-02 21:00:24 +04:30
Stephan Unverwerth
15299b763c LibGL: Implement glPolygonOffset 2021-09-02 21:00:24 +04:30
Stephan Unverwerth
7cbaaf8366 LibGL: Implement glDrawBuffer 2021-09-02 21:00:24 +04:30
Stephan Unverwerth
b54573739c LibGL: Implement glTexEnvf
This controls how fetched texels are combined with the color that was
produced by a preceding texture unit or with the vertex color if it is
the first texture unit.

Currently only a small subset of possible combine modes is implemented
as required by glquake.
2021-08-26 19:54:31 +02:00
Stephan Unverwerth
19a08ff187 LibGL: Implement glPixelStorei
This sets the length of a row for the image to be transferred. This
value is measured in pixels. When a rectangle with a width less than
this value is transferred the remaining pixels of this row are skipped.
2021-08-26 19:53:57 +02:00
Jesse Buhagiar
924d890bfe LibGL: Implement fog effect in Software Rasterizer
We support three of the possible fog modes, EXP, EXP2 and LINEAR.
2021-08-25 23:50:54 +04:30
Jesse Buhagiar
d73cc3d0eb LibGL: Implement glFogi 2021-08-25 23:50:54 +04:30
Jesse Buhagiar
f55d2a22af LibGL: Implement glFogf 2021-08-25 23:50:54 +04:30
Jesse Buhagiar
7f1cd54b80 LibGL: Implement glFogfv
This currently just sets the fog colour in the rasterizer.
2021-08-25 23:50:54 +04:30
Jesse Buhagiar
89eddb5bff LibGL: Implement glPolygonMode
Currently just sets the renderer option for what polygon mode we
want the rasterizer to draw in. GLQuake only uses `GL_FRONT_AND_BACK`
with `GL_FILL` )which implies both back and front facing triangles
are to be filled completely by the rasterizer), so keeping this as
a small stub is perfectly fine for now.
2021-08-20 20:04:06 +04:30
Jesse Buhagiar
68d895eb7c LibGL: Don't crash on invalid pname value in glGetFloatv
This brings `glGetFloatv` more inline with the other `glGet`
functions. We should prevent crashing in the driver as much as
possible and instead let the application deal with the generated
GL error.
2021-08-19 17:08:04 +02:00
Stephan Unverwerth
addbcd42d7 LibGL: Fix triangle winding calculation
Since we operate in screen space where y points down we need to reverse
what is considered clock wise and what is considered counter clockwise.

The rasterizer always expects triangles with a consistent winding order
thus swap 2 vertices if necessary to reverse the winding before passing
the triangle on to the rasterization stage.
2021-08-18 20:30:58 +02:00