xyginext  0.2.0
Second generation of xygine game creation framework
Public Member Functions | Static Public Attributes | Friends | List of all members
xy::Drawable Class Referencefinal

Drawable component. The drawable component encapsulates an sf::VertexArray which can be used to draw custom shapes, as well as being required for entities which have a sprite or text component. The purpose of the Drawable component is to allow mixing Sprite, Text and custom drawable types in a single drawing pass with variable depth. A Scene must have a RenderSystem added to it to enable any drawable entities. More...

#include <Drawable.hpp>

Inheritance diagram for xy::Drawable:

Public Member Functions

 Drawable (const sf::Texture &)
 
void setTexture (const sf::Texture *)
 Sets the texture with which to render this drawable. Setting this to nullptr removes the texture. This has no effect when used with Sprite or Text components which supply their own textures. More...
 
void setShader (sf::Shader *)
 Sets the shader used when drawing. Passing nullptr removes any active shader.
 
void bindUniform (const std::string &name, const sf::Texture &texture)
 Adds a uniform binding to be applied to any shader this drawable may have. When sharing a shader between multiple drawables it may be, for instance, desirable to the apply a different texture for each drawble. This function allows mapping a uniform name (assuming it is available in the current shader) to a texture or other value. Bindings are limited to 6 per type.
 
void bindUniform (const std::string &name, float value)
 
void bindUniform (const std::string &name, sf::Vector2f value)
 
void bindUniform (const std::string &name, sf::Vector3f value)
 
void bindUniform (const std::string &name, bool value)
 
void bindUniform (const std::string &name, sf::Color colour)
 
void bindUniform (const std::string &name, const float *value)
 Binds a pointer to a float array containing a 4x4 matrix.
 
void bindUniformToCurrentTexture (const std::string &name)
 Binds the given uniform to the value of sf::Shader::CurrentTexture. Up to 6 uniforms may be bound to this value.
 
void setBlendMode (sf::BlendMode)
 Sets the blend mode used when drawing. Note that this is overriden and has no effect if the Drawable component is used on an Entity with a Sprite loaded from a SpriteSheet, as the SpriteSheet definition takes precedence.
 
void setFilterFlags (std::uint64_t flags)
 Set filter flags for rendering. Filter flags allow certain drawables to be omitted from a drawing pass by the render system. This is useful for multipass effects which require rendering different entities to different render buffers. For example lighting objects may be flagged as such so that when the lighting only flag is active on the render system only illuminating objects are rendered to the output. Flags are bitwise values so that drawables can be categorised in multiple filters by setting the appropriate flags. The default value is Uin64::max - ie all flags set (so will always pass the render filter). More...
 
std::uint64_t getFilterFlags () const
 Returns the current filter flags of this drawable. More...
 
sf::Texture * getTexture ()
 Returns a pointer to the active texture.
 
sf::Shader * getShader ()
 Returns a pointer to the active shader, if any.
 
sf::BlendMode getBlendMode () const
 Returns the current blend mode.
 
void setDepth (sf::Int32 depth)
 Sets the z-depth of a drawable. The lower the value the further back the entity is drawn, inversely the greater the value the further forward it is drawn. Default value is 0.
 
sf::Int32 getDepth () const
 Returns the Z depth value. More...
 
void setCroppingArea (sf::FloatRect)
 Set an area to which to crop the drawable. The given rectangle should be in local coordinates, relative to the drawable.
 
sf::FloatRect getCroppingArea () const
 Returns the current cropping area.
 
std::vector< sf::Vertex > & getVertices ()
 Returns a reference to the vertex array used when drawing.
 
const std::vector< sf::Vertex > & getVertices () const
 
void setPrimitiveType (sf::PrimitiveType type)
 Sets the PrimitiveType used by the drawable. Uses sf::Quads by default.
 
sf::PrimitiveType getPrimitiveType () const
 Returns the current PrimitiveType used to draw the vertices.
 
sf::FloatRect getLocalBounds () const
 Returns the local bounds of the Drawable's vertex array. This should be updated by any systems which implement custom drawables else culling will failed and drawable will not appear on screen.
 
void updateLocalBounds ()
 Updates the local bounds. This should be called once by a system when it updates the vertex array. As this is used by the render system for culling, Drawable components will not be drawn if the bounds have not been updated.
 
void updateLocalBounds (sf::FloatRect)
 
void setCulled (bool cull)
 Enables or disables viewport culling. By default Drawables are culled from rendering when not in the viewable area of the active camera. Setting this to true will cause the drawable to always be rendered, even if it falls outside the active camera's view. More...
 
sf::RenderStates getStates () const
 Returns the RenderStates containing the current blend mode, PrimitiveType and Shader of the drawable. Generally not required, unless implementing a custom renderer.
 
void applyShader () const
 Applies all the unform bindings to the current shader. Generally not used unless implementing a custom render system, in which case this should be called immediately before the component is drawn.
 
void addGlFlag (std::int32_t)
 Adds an OpenGL flag to be applied with glEnable() before the Drawable is rendered and glDisable() afterwards. Multiple flags can be added. Generally only useful if you have a specific need for it, and probably won't do what you expect...
 

Static Public Attributes

static constexpr std::uint64_t DefaultFilterFlag = (1ull << 63)
 default flag value for drawables 0b1000000000000000000000000000000000000000000000000000000000000000
 

Friends

class RenderSystem
 

Detailed Description

Drawable component. The drawable component encapsulates an sf::VertexArray which can be used to draw custom shapes, as well as being required for entities which have a sprite or text component. The purpose of the Drawable component is to allow mixing Sprite, Text and custom drawable types in a single drawing pass with variable depth. A Scene must have a RenderSystem added to it to enable any drawable entities.

Member Function Documentation

◆ getDepth()

sf::Int32 xy::Drawable::getDepth ( ) const
inline

Returns the Z depth value.

See also
setDepth();

◆ getFilterFlags()

std::uint64_t xy::Drawable::getFilterFlags ( ) const
inline

Returns the current filter flags of this drawable.

See also
setFilterFlags()

◆ setCulled()

void xy::Drawable::setCulled ( bool  cull)
inline

Enables or disables viewport culling. By default Drawables are culled from rendering when not in the viewable area of the active camera. Setting this to true will cause the drawable to always be rendered, even if it falls outside the active camera's view.

Parameters
cullSet to true to have the drawble culled from rendering when not intersecting the current viewable area.

◆ setFilterFlags()

void xy::Drawable::setFilterFlags ( std::uint64_t  flags)
inline

Set filter flags for rendering. Filter flags allow certain drawables to be omitted from a drawing pass by the render system. This is useful for multipass effects which require rendering different entities to different render buffers. For example lighting objects may be flagged as such so that when the lighting only flag is active on the render system only illuminating objects are rendered to the output. Flags are bitwise values so that drawables can be categorised in multiple filters by setting the appropriate flags. The default value is Uin64::max - ie all flags set (so will always pass the render filter).

Parameters
flagsa bitmask of filter flags

◆ setTexture()

void xy::Drawable::setTexture ( const sf::Texture *  )

Sets the texture with which to render this drawable. Setting this to nullptr removes the texture. This has no effect when used with Sprite or Text components which supply their own textures.

See also
Sprite::setTexture()