API functions for OpenGL's 'alpha testing' capability
OpenGL's alpha testing functionality, when enabled, compares incoming alpha values of images and primitives to a user-specified "reference alpha" value, and based on the outcome of the comparison and a user-defined 'function'/mode, either discards or draws the pixel.
This functionality can easily be reproduced via a PixelEffect, but there are still plenty of systems which run LÖVE and don't support PixelEffects. Alpha testing is supported in all versions and implementations of OpenGL.
I have attached a diff which adds this functionality to LÖVE. There are 2 new functions in the love.graphics table:
mode, referencealpha = love.graphics.getAlphaTest()
mode is either "<", "<=", "==", "~=", ">=", or ">", and specifies how the reference alpha value gets compared.
referencealpha is an integer between 0 and 255, and specifies the alpha value the incoming fragment is compared to.
love.graphics.setAlphaTest(">", 127) will, for every image and primitive drawn afterward, only display pixels from those images and primitives if the alpha value of the pixel is greater than 127.
Alpha testing is disabled by default.
love.graphics.setAlphaTest() (no arguments) will disable alpha testing if it is enabled.
love.graphics.getAlphaTest() will return nil if alpha testing is disabled, otherwise it returns the current values previously set by the user.
I have also included an example .love showing the new alpha testing API being used to create metaballs without the use of PixelEffects. Left/right arrow control which mode is being used, up/down arrow control the reference alpha, and "T" toggles alpha testing entirely.