Commit graph

55 commits

Author SHA1 Message Date
Andreas Kling c7d891765c LibGfx: Use "try_" prefix for static factory functions
Also mark them as [[nodiscard]].
2021-07-21 18:02:15 +02:00
Hendiadyoin1 ed46d52252 Everywhere: Use AK/Math.h if applicable
AK's version should see better inlining behaviors, than the LibM one.
We avoid mixed usage for now though.

Also clean up some stale math includes and improper floatingpoint usage.
2021-07-19 16:34:21 +04:30
Erik Biederstadt 61bd1890d2 LibGL: Implement very basic version of glGetFloatv
This is a very basic implementation of glGetfloatv. It will only give a
result when used with GL_MODELVIEW_MATRIX. In the future
 we can update and extend it's functionality.
2021-06-09 10:49:38 +02:00
Jesse Buhagiar 8298e406a4 LibGL: Use Texture Units in Rasterizer and Context
The Context and Software Rasterizer now gets the array of texture units
instead of a single texture object. _Technically_, we now support some
primitive form of multi-texturing, though I'm not entirely sure how well
it will work in its current state.
2021-05-31 14:59:47 +01:00
Jesse Buhagiar 573c1c82f7 LibGL: Implement glActiveTexture 2021-05-31 14:59:47 +01:00
Jesse Buhagiar 52e5d3c961 LibGL: Implement basic texture units
These are merely a way to hold the different texture target bind
points that a texture can be bound to.
2021-05-31 14:59:47 +01:00
Stephan Unverwerth 755393e684 LibGL: Implement glBindTexture()
Textures are now initialized with a nullptr upon generation.
They are only actually created once they are bound to a target.
Currently only the GL_TEXTURE_2D target is supported.
The software rasterizer now allows rendering with or without
a bound TEXTURE_2D.
2021-05-30 00:32:37 +01:00
Stephan Unverwerth fde0045ebe LibGL: Introduce Texture base class for all texture types 2021-05-30 00:32:37 +01:00
Stephan Unverwerth 92339b7fe5 LibGL: Rewrite error handling according to spec
Following https://www.khronos.org/registry/OpenGL/specs/gl/glspec15.pdf
errors are now only recorded if m_error is GL_NO_ERROR
m_error is reset to GL_NO_ERROR after a successful call to glGetError()
2021-05-29 18:17:24 +01:00
Stephan Unverwerth 9334697c59 LibGL: Update rasterizer options in glDisable()
This bug must have been introduced by copy-pasting.
2021-05-29 18:17:24 +01:00
Stephan Unverwerth 9b4edacd8e LibGL: Add macro for error checking
This adds a macro `RETURN_WITH_ERROR_IF` to SoftwareGLContext
to remove a lot of noise from the interface implementation.
2021-05-29 18:17:24 +01:00
Stephan Unverwerth 10ceeb092f Everywhere: Use s.unverwerth@serenityos.org :^) 2021-05-29 12:30:08 +01:00
Jesse Buhagiar ebe38639bc LibGL: Fix incorrect sign compare caused by GLsizei changes 2021-05-26 16:36:53 +04:30
Jesse Buhagiar 3287709df9 LibGL: Add texture sampling to SW Rasterizer
The software rasterizer now samples a texture passed to us from the
GL context. This is currently a bit of a hack, as we should be
scanning from a list of texture units and checking if they are
enabled. For now, this at least gives some visual confirmation
that texturing is working as it should
2021-05-26 16:36:53 +04:30
Jesse Buhagiar e21ba0cd12 LibGL: Implement glTexCoord2f 2021-05-26 16:36:53 +04:30
Jesse Buhagiar 4f324ba4d7 LibGL: Implement Texture State Management
Some very primitive Texture State management. Data can now be
uploaded to textures.
2021-05-26 16:36:53 +04:30
Jesse Buhagiar 21dff6d40b LibGL: Add Texture Name Allocation
Texture names can now be allocated via
`glGenTextures` and deallocated via `glDeleteTextures`.
2021-05-26 16:36:53 +04:30
Jesse Buhagiar 8a69e6714e LibGL: Change GLsizei from unsigned to signed integral type
There is some really wild stuff going on in the OpenGL spec for this..
The Khronos website states that GLsizei is a 32-bit non-negative value
used for sizes, however, some functions such as `glGenTextures` state
that the input `n` could be negative, which implies signage. Most other
implementations of `gl.h` seem to `typedef` this to `int` so we should
too.
2021-05-26 16:36:53 +04:30
Stephan Unverwerth e54d96d53e LibGL: Implement glReadPixels() 2021-05-24 19:03:25 +01:00
Stephan Unverwerth d6c84ca4df LibGL: Implement glReadPixels() stub with argument validation 2021-05-24 19:03:25 +01:00
Stephan Unverwerth 24e74750d5 LibGL: Implement glReadBuffer() 2021-05-24 19:03:25 +01:00
Stephan Unverwerth eed0bcaf42 LibGL: Implement glHint() 2021-05-20 23:29:56 +02:00
Stephan Unverwerth 28ed518142 LibGL: Implement all of glVertex{2,3,4}{d,dv,f,fv,i,iv,s,sv} 2021-05-19 23:18:13 +02:00
Linus Groh 0aab774343 Everywhere: Fix a bunch of typos 2021-05-17 17:48:55 +01:00
Stephan Unverwerth 2dcafde330 LibGL: Implement alpha testing in SoftwareRasterizer 2021-05-16 19:27:23 +02:00
Stephan Unverwerth 1bd754882d LibGL: Implement glAlphaFunc()
This implements glAlphaFunc() for setting alpha test func and ref value
and also allows enabling and disabling GL_ALPHA_TEST
2021-05-16 19:27:23 +02:00
Stephan Unverwerth d6e8634576 LibGL: Add glBlendFunc() and glShadeModel() to call lists 2021-05-16 15:53:58 +02:00
Stephan Unverwerth da57563c1c LibGL: Implement glShadeModel()
This turns off interpolation of vertex colors when GL_FLAT is selected.
2021-05-16 15:53:58 +02:00
Stephan Unverwerth f70a6ff712 LibGL: Implement color blending
This implements different blend modes in the SoftwareRasterizer by
first setting up the blend factors then rendering the pixels into a
temporary buffer and finally mixing the contents of the temporary buffer
with the contents of the backbuffer based on the blend factors.
2021-05-16 00:44:31 +01:00
Stephan Unverwerth d6e9b433cf LibGL: Add support for GL_BLEND in glEnable() and glDisable() 2021-05-16 00:44:31 +01:00
Stephan Unverwerth 279737642c LibGL: Add defines and stubs for glBlendFunc() 2021-05-16 00:44:31 +01:00
Stephan Unverwerth 1b358d3b94 LibGL: Add missing GLAPI function specifiers 2021-05-16 00:44:31 +01:00
Stephan Unverwerth 2b9ad11bd8 LibGL: Implement glFlush() and glFinish() 2021-05-14 22:15:50 +02:00
Stephan Unverwerth c2d84efaae LibGfx+Demos: Make Matrix4x4 a true alias for Matrix<4,T>
Matrix4x4 was defined as a derived class of Matrix<N,T> before.
Furthermore, some code was duplicated and it was overall just messy.
This commit turns Matrix4x4 into a simple alias for Matrix<4,T>.
2021-05-13 22:24:42 +02:00
Stephan Unverwerth 0833db0874 LibGfx: Make Matrix class consistently row-major
Matrix elements were interpreted in different ways.
This makes it definitely row-major, allowing initialization via
initializer list in a standard scientific order. Also matrix
multiplication now happens in the correct order and accessing
elements happens as m_elements[row][column].
2021-05-13 22:24:42 +02:00
Stephan Unverwerth b63b15eeb5 LibGL: SoftwareRasterizer: Use perspective correct interpolation 2021-05-13 08:34:26 +02:00
Stephan Unverwerth 4b55aea307 LibGL: Generate coverage and depth masks in the software rasterizer
This untangles several concepts in the rasterizer and makes it possible
to toggle different stages on a per-block level rather than having to
check whether the feature is enabled for every pixel.
2021-05-13 08:34:26 +02:00
Stephan Unverwerth f112c594a7 LibGL: Use integer math in rasterizer coverage calculations
This makes the software rasterizer use integers for triangle coverage
calculations. The previously used floating point algorithm was not
precise enough in certain situations and showed gaps between triangles.

This is not yet subpixel accurate.
2021-05-13 08:34:26 +02:00
Ali Mohammad Pur 720d21411b LibGL: Implement glGenLists and a few friends
This commit implements glGenLists(), glNewList(), glDeleteLists(), and
glCallList().
The 'compiled' records are implemented as a vector of member function
pointers and tuples containing their arguments, and a mechanism is
implemented to allow the recorded calls to copy-capture values from the
time of the call; this is currently only used with glLoadMatrix.
2021-05-11 14:09:17 +01:00
Stephan Unverwerth e8f66f821c LibGL: Add depth tests and writes to SoftwareRasterizer
Tests against and writes to the depth buffer when GL_DEPTH_TEST is
enabled via glEnable(). Currently fragment z is always compared against
existing depth with GL_LESS.
2021-05-09 15:58:35 +02:00
Stephan Unverwerth 608f81e6c2 LibGL: Add depth buffer class 2021-05-09 15:58:35 +02:00
Stephan Unverwerth a8fc4be47a LibGL: Add supporting code for depth buffer
This adds glClearDepth() and new caps for enabling and disabling
the depth buffer with glEnable() and glDisable()
2021-05-09 15:58:35 +02:00
Jesse Buhagiar e8cd89a538 LibGL: Move polygon clipping to Clipper class
This code has also been optimised to be much more memory
friendly by removing a _lot_ of extraneous copies. The result
is that, when profiled, it's around 8x faster than the previous
implementation.

Co-Authored-By: Ali Mohammad Pur <ali.mpfard@gmail.com>
2021-05-08 10:13:22 +02:00
Stephan Unverwerth 5ff248649b LibGL: Add software rasterizer
This is based mostly on Fabian "ryg" Giesen's 2011 blog series
"A trip through the Graphics Pipeline" and Scratchapixel's
"Rasterization: a Practical Implementation".

The rasterizer processes triangles in grid aligned 16x16 pixel blocks,
calculates barycentric coordinates and edge derivatives and interpolates
bilinearly across each block.

This will theoretically allow for better utilization of modern processor
features such as SMT and SIMD, as opposed to a classic scanline based
triangle rasterizer.

This serves as a starting point to get something on the screen.
In the future we might look into properly pipelining the main loop to
make the rasterizer more flexible, enabling us to enable/disable
certain features at the block rather than the pixel level.
2021-05-08 10:13:22 +02:00
Stephan Unverwerth e6c0600499 LibGL: Add back face culling functions
Adds all needed functions to support back face culling
and implements back face culling in the SoftwareGLContext.
2021-05-08 10:13:22 +02:00
Ali Mohammad Pur eff3c8a954 LibGL: Implement glColor4(ub,f)v 2021-05-08 10:13:22 +02:00
Ali Mohammad Pur 193b53344a LibGL: Implement glVertex2f(v) 2021-05-08 10:13:22 +02:00
Ali Mohammad Pur 6b11a5688d LibGL: Implement glVertex3fv 2021-05-08 10:13:22 +02:00
Ali Mohammad Pur f601f12801 LibGL: Implement glOrtho and underlying functions 2021-05-08 10:13:22 +02:00
Jesse Buhagiar f07a7f7b94 LibGL: Impement glLoadMatrixf and underlying function 2021-05-08 10:13:22 +02:00