![]() |
CUGL 2.3
Cornell University Game Library
|
#include <CUScissor.h>
Public Member Functions | |
Scissor () | |
Scissor (const Scissor &mask) | |
Scissor (Scissor &&mask) | |
~Scissor () | |
void | dispose () |
bool | init (const Size size, float fringe=0.5) |
bool | init (const Rect rect, float fringe=0.5) |
bool | init (const Size size, const Affine2 &aff, float fringe=0.5) |
bool | init (const Rect rect, const Affine2 &aff, float fringe=0.5) |
bool | init (const Size size, const Mat4 &mat, float fringe=0.5) |
bool | init (const Rect rect, const Mat4 &mat, float fringe=0.5) |
bool | init (const std::shared_ptr< Scissor > &mask) |
Scissor & | operator= (const Scissor &mask) |
Scissor & | operator= (Scissor &&mask) |
Scissor & | operator= (const Rect rect) |
Scissor & | set (const Scissor &mask) |
Scissor & | set (const std::shared_ptr< Scissor > &mask) |
Scissor & | set (const Rect rect, float fringe=0.5) |
Scissor & | set (const Rect rect, const Affine2 &aff, float fringe=0.5) |
Scissor & | set (const Rect rect, const Mat4 &mat, float fringe=0.5) |
Scissor & | setZero () |
Affine2 | getTransform () const |
void | setTransform (const Affine2 &transform) |
void | setTransform (const Mat4 &transform) |
Rect | getBounds () const |
void | setBounds (const Rect bounds) |
float | getFringe () const |
void | setFringe (float fringe) |
Scissor & | rotate (float angle) |
Scissor & | scale (float value) |
Scissor & | scale (const Vec2 s) |
Scissor & | scale (float sx, float sy) |
Scissor & | translate (const Vec2 t) |
Scissor & | translate (float tx, float ty) |
Scissor & | multiply (const Mat4 &mat) |
Scissor & | multiply (const Affine2 &aff) |
Scissor & | operator*= (const Mat4 &mat) |
Scissor & | operator*= (const Affine2 &aff) |
Scissor | operator* (const Mat4 &mat) const |
Scissor | operator* (const Affine2 &aff) const |
Scissor & | intersect (const Scissor &mask) |
Scissor | getIntersection (const Scissor &mask) const |
Scissor & | intersect (const std::shared_ptr< Scissor > &mask) |
std::shared_ptr< Scissor > | getIntersection (const std::shared_ptr< Scissor > &mask) const |
float * | getData (float *array) const |
float * | getComponents (float *array) const |
std::string | toString (bool verbose=false) const |
operator std::string () const | |
Static Public Member Functions | |
static std::shared_ptr< Scissor > | alloc (const Size size, float fringe=0.5) |
static std::shared_ptr< Scissor > | alloc (const Rect rect, float fringe=0.5) |
static std::shared_ptr< Scissor > | alloc (const Size size, const Affine2 &aff, float fringe=0.5) |
static std::shared_ptr< Scissor > | alloc (const Rect rect, const Affine2 &aff, float fringe=0.5) |
static std::shared_ptr< Scissor > | alloc (const Size size, const Mat4 &mat, float fringe=0.5) |
static std::shared_ptr< Scissor > | alloc (const Rect rect, const Mat4 &mat, float fringe=0.5) |
static std::shared_ptr< Scissor > | alloc (const std::shared_ptr< Scissor > &mask) |
This class defines a general purpose scissor mask.
A scissor mask is used to prevent portions of a 2d shape from showing. The mask is a transformed rectangle, and any pixel outside of this region is dropped. Unlike Gradient
, a scissor is applied to a region of the framebuffer and is not a texture that can be applied to a surface. Therefore, the scissor mask region must be defined in terms of pixels (or at least in the same coordinate system as the vertices it is masking).
A scissor mask is defined by three values (in terms of largest to smallest data):
Unpacking this data into std140 format is a 16 element array of floats (the fringe is expanded into a per-axis value for the shader). And this is the format that this data is represented in the getData
method so that it can be passed to a UniformBuffer
for improved performance. It is also possible to get access to the individual components of the scissor mask, to pass them to a shader directly (though the transform must be inverted first if it is passed directly).
Scissor masks can be intersected. However, a scissor mask must always be a transformed rectangle, and not all quadrilateral intersections are guaranteed to be transformed rectangles. Therefore, these intersections are always an an approximation, with the intersecting scissor mask converted into an axis-aligned rectangle in the coordinate space of the current scissor mask. The affect is the same as the Rect#intersect
operation in in Rect
.
cugl::Scissor::Scissor | ( | ) |
Creates a degenerate scissor of size 0.
All pixels will be dropped by this mask.
|
inline |
Creates a copy of the given scissor mask.
mask | The scissor mask to copy |
cugl::Scissor::Scissor | ( | Scissor && | mask | ) |
Creates a copy with the resources of the given scissor mask.
The original scissor mask is no longer safe to use after calling this constructor.
mask | The scissor mask to take from |
|
inline |
Deletes this scissor mask, releasing all resources.
|
inlinestatic |
Returns a new scissor with the given transformed bounds and fringe.
The fringe is the size of the scissor border in pixels. A value less than 0 gives a sharp transition, where larger values have more gradual transitions.
rect | The scissor mask bounds |
aff | The scissor mask transform |
fringe | The size of the scissor border in pixels |
|
inlinestatic |
Returns a new scissor with the given transformed bounds and fringe.
The fringe is the size of the scissor border in pixels. A value less than 0 gives a sharp transition, where larger values have more gradual transitions.
All z-components from the given matrix transform are lost.
rect | The scissor mask bounds |
mat | The scissor mask transform |
fringe | The size of the scissor border in pixels |
|
inlinestatic |
Returns a new scissor with the given bounds and fringe.
The fringe is the size of the scissor border in pixels. A value less than 0 gives a sharp transition, where larger values have more gradual transitions.
rect | The scissor mask bounds |
fringe | The size of the scissor border in pixels |
|
inlinestatic |
Returns a new scissor with the given transformed bounds and fringe.
The bounding box will have origin (0,0). The fringe is the size of the scissor border in pixels. A value less than 0 gives a sharp transition, where larger values have more gradual transitions.
size | The scissor mask size |
aff | The scissor mask transform |
fringe | The size of the scissor border in pixels |
|
inlinestatic |
Returns a new scissor with the given transformed bounds and fringe.
The bounding box will have origin (0,0). The fringe is the size of the scissor border in pixels. A value less than 0 gives a sharp transition, where larger values have more gradual transitions.
All z-components from the given matrix transform are lost.
size | The scissor mask size |
mat | The scissor mask transform |
fringe | The size of the scissor border in pixels |
|
inlinestatic |
Returns a new scissor with the given bounds and fringe.
The bounding box will have origin (0,0). The fringe is the size of the scissor border in pixels. A value less than 0 gives a sharp transition, where larger values have more gradual transitions.
size | The scissor mask size |
fringe | The size of the scissor border in pixels |
|
inlinestatic |
Returns a new scissor mask that is a copy of the other.
mask | The scissor mask to copy |
void cugl::Scissor::dispose | ( | ) |
Deletes the scissor mask and resets all attributes.
You must reinitialize the scissor mask to use it.
|
inline |
Returns the bounding box of this scissor mask
The bounding box is axis-aligned. It ignored the transform component of the scissor mask.
float * cugl::Scissor::getComponents | ( | float * | array | ) | const |
Reads the scissor mask into the provided array
The scissor mask is written to the array so that it can be passed the the shader one component at a time (e.g. NOT in std140 format). It differs from getData in that it only uses 9 floats for the affine transform (as a 3x3 homogenous matrix).
array | The array to store the values |
float * cugl::Scissor::getData | ( | float * | array | ) | const |
Reads the scissor mask into the provided array
The scissor mask is written to the given array in std140 format. That is (1) 12 floats for the affine transform (as a 3x3 homogenous matrix), (2) 2 floats for the extent, and (3) 2 floats for the fringe (one for each axis). Values are written in this order.
array | The array to store the values |
|
inline |
Returns the edge fringe of this scissor mask
The fringe is the size of the scissor border in pixels. A value less than 0 gives a sharp transition, where larger values have more gradual transitions.
Returns the intersection of the given scissor mask with this one.
The intersection will take place in the coordinate system of this scissor mask. The other mask will be transformed to be in this coordinate space. This transformation will compute the bounding box of the transformed scissor and interesect it with the bounding box of this scissor.
As long as the scissors have the same rotational angle, this will have the expected effect of intersecting two scissors. However, if their rotational angles differ, the transformed scissor will be the axis-aligned bounding box (in the coordinate system of this scissor mask) of the original. This my result in revealing areas once hidden.
This scissor mask will not be affected by this method.
mask | The scissor mask to intersect with this one |
std::shared_ptr< Scissor > cugl::Scissor::getIntersection | ( | const std::shared_ptr< Scissor > & | mask | ) | const |
Returns the intersection of the given scissor mask with this one.
The intersection will take place in the coordinate system of this scissor mask. The other mask will be transformed to be in this coordinate space. This transformation will compute the bounding box of the transformed scissor and interesect it with the bounding box of this scissor.
As long as the scissors have the same rotational angle, this will have the expected effect of intersecting two scissors. However, if their rotational angles differ, the transformed scissor will be the axis-aligned bounding box (in the coordinate system of this scissor mask) of the original. This my result in revealing areas once hidden.
This scissor mask will not be affected by this method.
mask | The scissor mask to intersect with this one |
|
inline |
Returns the transform component of this scissor mask
If the scissor mask is not rotated or otherwise transformed, this value will be the identity.
This value only contains the transform on the scissor mask bounding box. It is not the same as the scissor matrix in a scissor shader. Do not pass this information directly to the shader. Use either the method getData
or getComponents
depending on whether or not you need std140 representation.
Initializes a scissor with the given transformed bounds and fringe.
The fringe is the size of the scissor border in pixels. A value less than 0 gives a sharp transition, where larger values have more gradual transitions.
rect | The scissor mask bounds |
aff | The scissor mask transform |
fringe | The size of the scissor border in pixels |
Initializes a scissor with the given transformed bounds and fringe.
The fringe is the size of the scissor border in pixels. A value less than 0 gives a sharp transition, where larger values have more gradual transitions.
All z-components from the given matrix transform are lost.
rect | The scissor mask bounds |
mat | The scissor mask transform |
fringe | The size of the scissor border in pixels |
bool cugl::Scissor::init | ( | const Rect | rect, |
float | fringe = 0.5 |
||
) |
Initializes a scissor with the given bounds and fringe.
The fringe is the size of the scissor border in pixels. A value less than 0 gives a sharp transition, where larger values have more gradual transitions.
rect | The scissor mask bounds |
fringe | The size of the scissor border in pixels |
Initializes a scissor with the given transformed bounds and fringe.
The bounding box will have origin (0,0). The fringe is the size of the scissor border in pixels. A value less than 0 gives a sharp transition, where larger values have more gradual transitions.
size | The scissor mask size |
aff | The scissor mask transform |
fringe | The size of the scissor border in pixels |
Initializes a scissor with the given transformed bounds and fringe.
The bounding box will have origin (0,0). The fringe is the size of the scissor border in pixels. A value less than 0 gives a sharp transition, where larger values have more gradual transitions.
All z-components from the given matrix transform are lost.
size | The scissor mask size |
mat | The scissor mask transform |
fringe | The size of the scissor border in pixels |
|
inline |
Initializes a scissor with the given size and fringe.
The bounding box will have origin (0,0). The fringe is the size of the scissor border in pixels. A value less than 0 gives a sharp transition, where larger values have more gradual transitions.
size | The scissor mask size |
fringe | The size of the scissor border in pixels |
bool cugl::Scissor::init | ( | const std::shared_ptr< Scissor > & | mask | ) |
Initializes this scissor mask to be a copy of the other.
mask | The scissor mask to copy |
Intersects the given scissor mask with this one.
The intersection will take place in the coordinate system of this scissor mask. The other mask will be transformed to be in this coordinate space. This transformation will compute the bounding box of the transformed scissor and interesect it with the bounding box of this scissor.
As long as the scissors have the same rotational angle, this will have the expected effect of intersecting two scissors. However, if their rotational angles differ, the transformed scissor will be the axis-aligned bounding box (in the coordinate system of this scissor mask) of the original. This my result in revealing areas once hidden.
mask | The scissor mask to intersect with this one |
Intersects the given scissor mask with this one.
The intersection will take place in the coordinate system of this scissor mask. The other mask will be transformed to be in this coordinate space. This transformation will compute the bounding box of the transformed scissor and interesect it with the bounding box of this scissor.
As long as the scissors have the same rotational angle, this will have the expected effect of intersecting two scissors. However, if their rotational angles differ, the transformed scissor will be the axis-aligned bounding box (in the coordinate system of this scissor mask) of the original. This my result in revealing areas once hidden.
mask | The scissor mask to intersect with this one |
Applies the given transform to this scissor mask.
The matrix transform is applied after the existing scissor transform (which is natural, since the transform defines the initial box bounds). To pre-multiply a transform, set the transform directly.
aff | The matrix to multiply by. |
Applies the given transform to this scissor mask.
This transform is applied after the existing gradient transform (which is natural, since the transform defines the gradient shape). To pre-multiply a transform, set the transform directly.
mat | The matrix to multiply by. |
|
inline |
Cast from Scissor to a string.
Returns a copy of the scissor mask transformed by the given matrix.
The matrix transform is applied after the existing scissor transform (which is natural, since the transform defines the initial box bounds). To pre-multiply a transform, set the transform directly.
Note: This does not modify the scissor mask.
aff | The transform to multiply by. |
Returns a copy of the scissor mask transformed by the given matrix.
The matrix transform is applied after the existing scissor transform (which is natural, since the transform defines the initial box bounds). To pre-multiply a transform, set the transform directly.
Note: This does not modify the scissor mask.
mat | The transform to multiply by. |
Applies the given transform to this scissor mask.
The matrix transform is applied after the existing scissor transform (which is natural, since the transform defines the initial box bounds). To pre-multiply a transform, set the transform directly.
aff | The matrix to multiply by. |
Applies the given transform to this scissor mask.
This transform is applied after the existing gradient transform (which is natural, since the transform defines the gradient shape). To pre-multiply a transform, set the transform directly.
mat | The matrix to multiply by. |
Sets this to be a scissor mask with the given bouding rectangle.
Any previous transforms are dropped when this operator is called.
rect | The scissor mask bounds |
Sets this scissor mask to be a copy of the given one.
mask | The scissor mask to copy |
Sets this scissor mask to be have the resources of the given one.
The original scissor mask is no longer safe to use after calling this operator.
mask | The scissor mask to take from |
Scissor & cugl::Scissor::rotate | ( | float | angle | ) |
Applies a rotation to this scissor mask.
The rotation is in radians, counter-clockwise about the given axis.
angle | The angle (in radians). |
Applies a non-uniform scale to this scissor mask.
s | The vector storing the individual scaling factors |
|
inline |
Applies a non-uniform scale to this scissor mask.
sx | The amount to scale along the x-axis. |
sy | The amount to scale along the y-axis. |
Scissor & cugl::Scissor::scale | ( | float | value | ) |
Applies a uniform scale to this scissor mask.
value | The scalar to multiply by. |
Sets the scissor mask to have the given transformed bounds and fringe.
Any previous transforms are dropped when this method is called.
The fringe is the size of the scissor border in pixels. A value less than 0 gives a sharp transition, where larger values have more gradual transitions.
rect | The scissor mask bounds |
aff | The scissor mask transform |
fringe | The size of the scissor border in pixels |
Sets the scissor mask to have the given transformed bounds and fringe.
Any previous transforms are dropped when this method is called.
The fringe is the size of the scissor border in pixels. A value less than 0 gives a sharp transition, where larger values have more gradual transitions.
All z-components from the given matrix transform are lost.
rect | The scissor mask bounds |
mat | The scissor mask transform |
fringe | The size of the scissor border in pixels |
Sets the scissor mask to have the given bounds and fringe.
Any previous transforms are dropped when this method is called.
The fringe is the size of the scissor border in pixels. A value less than 0 gives a sharp transition, where larger values have more gradual transitions.
rect | The scissor mask bounds |
fringe | The size of the scissor border in pixels |
Sets this scissor mask to be a copy of the given one.
mask | The scissor mask to copy |
Sets this scissor mask to be a copy of the given one.
mask | The scissor mask to copy |
void cugl::Scissor::setBounds | ( | const Rect | bounds | ) |
Sets the bounding box of this scissor mask
The bounding box is axis-aligned. It ignores the transform component of the scissor mask.
bounds | The bounding box of this scissor mask |
|
inline |
Sets the edge fringe of this scissor mask
The fringe is the size of the scissor border in pixels. A value less than 0 gives a sharp transition, where larger values have more gradual transitions.
fringe | The edge fringe of this scissor mask |
void cugl::Scissor::setTransform | ( | const Affine2 & | transform | ) |
Sets the transform component of this scissor mask
If the scissor mask is not rotated or otherwise transformed, this value should be the identity.
This value only contains the transform on the scissor mask bounding box. It is not the same as the scissor matrix in a scissor shader. Do not pass this information directly to the shader. Use either the method getData
or getComponents
depending on whether or not you need std140 representation.
transform | The transform component of this scissor mask |
void cugl::Scissor::setTransform | ( | const Mat4 & | transform | ) |
Sets the transform component of this scissor mask
If the scissor mask is not rotated or otherwise transformed, this value should be the identity.
This value only contains the transform on the scissor mask bounding box. It is not the same as the scissor matrix in a scissor shader. Do not pass this information directly to the shader. Use either the method getData
or getComponents
depending on whether or not you need std140 representation.
transform | The transform component of this scissor mask |
Scissor & cugl::Scissor::setZero | ( | ) |
Sets this to be a degenerate scissor of size 0.
All pixels will be dropped by this mask.
std::string cugl::Scissor::toString | ( | bool | verbose = false | ) | const |
Returns a string representation of this scissor for debuggging purposes.
If verbose is true, the string will include class information. This allows us to unambiguously identify the class.
verbose | Whether to include class information |
Applies a translation to this gradient.
t | The vector storing the individual translation offsets |
|
inline |
Applies a translation to this gradient.
tx | The translation offset for the x-axis. |
ty | The translation offset for the y-axis. |