mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Revamped love.graphics.stencil and love.graphics.setStencilTest:
- Each canvas (and the screen) has an invisible stencil value associated with each pixel. Stencil values are between [0, 255].
- love.graphics.stencil takes a function argument which draws things, and makes the geometry of what's drawn set the stencil values of pixels instead of coloring the pixels.
- Its second argument is a 'stencil action' which determines what happens to the stencil values of pixels. The possible stencil actions are 'replace' (the default), 'invert', 'increment', 'decrement', 'incrementwrap', and 'decrementwrap'. If the stencil action is 'replace', the third argument of love.graphics.stencil is a number between [0, 255] which determines what the stencil value of each pixel that touches drawn objects is replaced with.
The fourth argument is a boolean which determines whether the previous stencil values of all pixels on-screen should be kept (true), or cleared to 0 (false, the default.) love.graphics.clear also clears the stencil values.
- love.graphics.setStencilTest allows for anything drawn to be affected by a comparison between the arguments to setStencilTest and the existing stencil value of the pixels that are touched by what's drawn. Its first argument is a compare mode which can be 'equal', 'notequal', 'less', 'lequal', 'gequal', or 'greater', and the second argument is an integer value (between 0 and 255) used in the comparison with the value in the stencil buffer.
For example, love.graphics.setStencilTest("greater", 0) will cause any geometry drawn afterwards to only appear on pixels whose stencil value is greater than 0.
This commit is contained in:
@@ -146,13 +146,15 @@ public:
|
||||
* Enables or disables drawing to the stencil buffer. When enabled, the
|
||||
* color buffer is disabled.
|
||||
**/
|
||||
void drawToStencilBuffer(bool enable);
|
||||
void drawToStencilBuffer(StencilAction action, int value);
|
||||
void stopDrawToStencilBuffer();
|
||||
|
||||
/**
|
||||
* Sets whether stencil testing is enabled.
|
||||
**/
|
||||
void setStencilTest(bool enable, bool invert);
|
||||
void getStencilTest(bool &enable, bool &invert);
|
||||
void setStencilTest(CompareMode compare, int value);
|
||||
void setStencilTest();
|
||||
void getStencilTest(CompareMode &compare, int &value);
|
||||
|
||||
/**
|
||||
* Clear the stencil buffer in the active Canvas(es.)
|
||||
@@ -488,8 +490,8 @@ private:
|
||||
ScissorRect scissorRect = ScissorRect();
|
||||
|
||||
// Stencil.
|
||||
bool stencilTest = false;
|
||||
bool stencilInvert = false;
|
||||
CompareMode stencilCompare = COMPARE_ALWAYS;
|
||||
int stencilTestValue = 0;
|
||||
|
||||
StrongRef<Font> font;
|
||||
StrongRef<Shader> shader;
|
||||
|
||||
Reference in New Issue
Block a user