Added support for scissor testing.

This commit is contained in:
binary1248 2018-06-10 20:57:15 +02:00
parent ff011dc51d
commit 562229fcac
No known key found for this signature in database
GPG key ID: E5E52A5D6082224A
4 changed files with 130 additions and 0 deletions

View file

@ -129,6 +129,21 @@ public:
////////////////////////////////////////////////////////////
IntRect getViewport(const View& view) const;
////////////////////////////////////////////////////////////
/// \brief Get the scissor rectangle of a view, applied to this render target
///
/// The scissor rectangle is defined in the view as a ratio, this
/// function simply applies this ratio to the current dimensions
/// of the render target to calculate the pixels rectangle
/// that the scissor rectangle actually covers in the target.
///
/// \param view The view for which we want to compute the scissor rectangle
///
/// \return Scissor rectangle, expressed in pixels
///
////////////////////////////////////////////////////////////
IntRect getScissor(const View& view) const;
////////////////////////////////////////////////////////////
/// \brief Convert a point from target coordinates to world
/// coordinates, using the current view
@ -461,6 +476,7 @@ private:
bool enable; ///< Is the cache enabled?
bool glStatesSet; ///< Are our internal GL states set yet?
bool viewChanged; ///< Has the current view changed since last draw?
bool scissorEnabled; ///< Is scissor testing enabled?
BlendMode lastBlendMode; ///< Cached blending mode
Uint64 lastTextureId; ///< Cached texture
bool texCoordsArrayEnabled; ///< Is GL_TEXTURE_COORD_ARRAY client state enabled?

View file

@ -140,6 +140,27 @@ public:
////////////////////////////////////////////////////////////
void setViewport(const FloatRect& viewport);
////////////////////////////////////////////////////////////
/// \brief Set the target scissor rectangle
///
/// The scissor rectangle, expressed as a factor (between 0 and 1) of
/// the RenderTarget, specifies the region of the RenderTarget whose
/// pixels are able to be modified by draw or clear operations.
/// Any pixels which lie outside of the scissor rectangle will
/// not be modified by draw or clear operations.
/// For example, a scissor rectangle which only allows modifications
/// to the right side of the target would be defined
/// with View.setScissor(sf::FloatRect(0.5, 0, 0.5, 1)).
/// By default, a view has a scissor rectangle which allows
/// modifications to the entire target.
///
/// \param scissor New scissor rectangle
///
/// \see getScissor
///
////////////////////////////////////////////////////////////
void setScissor(const FloatRect& scissor);
////////////////////////////////////////////////////////////
/// \brief Reset the view to the given rectangle
///
@ -192,6 +213,16 @@ public:
////////////////////////////////////////////////////////////
const FloatRect& getViewport() const;
////////////////////////////////////////////////////////////
/// \brief Get the scissor rectangle of the view
///
/// \return Scissor rectangle, expressed as a factor of the target size
///
/// \see setScissor
///
////////////////////////////////////////////////////////////
const FloatRect& getScissor() const;
////////////////////////////////////////////////////////////
/// \brief Move the view relatively to its current position
///
@ -273,6 +304,7 @@ private:
Vector2f m_size; ///< Size of the view, in scene coordinates
float m_rotation; ///< Angle of rotation of the view rectangle, in degrees
FloatRect m_viewport; ///< Viewport rectangle, expressed as a factor of the render-target's size
FloatRect m_scissor; ///< Scissor rectangle, expressed as a factor of the render-target's size
mutable Transform m_transform; ///< Precomputed projection transform corresponding to the view
mutable Transform m_inverseTransform; ///< Precomputed inverse projection transform corresponding to the view
mutable bool m_transformUpdated; ///< Internal state telling if the transform needs to be updated
@ -305,6 +337,12 @@ private:
/// rectangle doesn't have the same size as the viewport, its
/// contents will be stretched to fit in.
///
/// The scissor rectangle allows for specifying regions of the
/// render target to which modifications can be made by draw
/// and clear operations. Only pixels that are within the region
/// will be able to be modified. Pixels outside of the region will
/// not be modified by draw or clear operations.
///
/// To apply a view, you have to assign it to the render target.
/// Then, objects drawn in this render target will be
/// affected by the view until you use another view.