CUGL 2.1
Cornell University Game Library
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
cugl::Scene2Texture Class Reference

#include <CUScene2Texture.h>

Inheritance diagram for cugl::Scene2Texture:
cugl::Scene2

Public Member Functions

 Scene2Texture ()
 
 ~Scene2Texture ()
 
virtual void dispose () override
 
bool init (const Size size)
 
bool init (float width, float height)
 
bool init (const Rect rect)
 
bool init (const Vec2 origin, const Size size)
 
virtual bool init (float x, float y, float width, float height) override
 
virtual void render (const std::shared_ptr< SpriteBatch > &batch) override
 
std::shared_ptr< TexturegetTexture () const
 
- Public Member Functions inherited from cugl::Scene2
 Scene2 ()
 
 ~Scene2 ()
 
bool init (const Size size)
 
bool init (float width, float height)
 
bool init (const Rect rect)
 
bool init (const Vec2 origin, const Size size)
 
const std::string & getName () const
 
void setName (const std::string &name)
 
std::shared_ptr< CameragetCamera ()
 
const std::shared_ptr< CameragetCamera () const
 
Color4 getColor ()
 
void setColor (Color4 color)
 
virtual std::string toString (bool verbose=false) const
 
 operator std::string () const
 
const Size getSize () const
 
void setSize (const Size size)
 
void setSize (float width, float height)
 
void setWidth (float width)
 
void setHeight (float height)
 
const Rect getBounds () const
 
void setBounds (const Rect rect)
 
void setBounds (const Vec2 origin, const Size size)
 
void setBounds (float x, float y, float width, float height)
 
void setOffset (const Vec2 origin)
 
Vec3 screenToWorldCoords (const Vec2 screenCoords) const
 
Vec2 worldToScreenCoords (const Vec3 worldCoords) const
 
size_t getChildCount () const
 
std::shared_ptr< scene2::SceneNodegetChild (unsigned int pos)
 
const std::shared_ptr< scene2::SceneNode > & getChild (unsigned int pos) const
 
template<typename T >
std::shared_ptr< TgetChild (unsigned int pos) const
 
std::shared_ptr< scene2::SceneNodegetChildByTag (unsigned int tag) const
 
template<typename T >
std::shared_ptr< TgetChildByTag (unsigned int tag) const
 
std::shared_ptr< scene2::SceneNodegetChildByName (const std::string name) const
 
template<typename T >
std::shared_ptr< TgetChildByName (const std::string name) const
 
std::vector< std::shared_ptr< scene2::SceneNode > > getChildren ()
 
const std::vector< std::shared_ptr< scene2::SceneNode > > & getChildren () const
 
virtual void addChild (const std::shared_ptr< scene2::SceneNode > &child)
 
void addChildWithTag (const std::shared_ptr< scene2::SceneNode > &child, unsigned int tag)
 
void addChildWithName (const std::shared_ptr< scene2::SceneNode > &child, const std::string name)
 
void swapChild (const std::shared_ptr< scene2::SceneNode > &child1, const std::shared_ptr< scene2::SceneNode > &child2, bool inherit=false)
 
virtual void removeChild (unsigned int pos)
 
void removeChild (const std::shared_ptr< scene2::SceneNode > &child)
 
void removeChildByTag (unsigned int tag)
 
void removeChildByName (const std::string name)
 
virtual void removeAllChildren ()
 
bool isActive () const
 
virtual void setActive (bool value)
 
virtual void update (float timestep)
 
virtual void reset ()
 

Static Public Member Functions

static std::shared_ptr< Scene2Texturealloc (const Size size)
 
static std::shared_ptr< Scene2Texturealloc (float width, float height)
 
static std::shared_ptr< Scene2Texturealloc (const Rect rect)
 
static std::shared_ptr< Scene2Texturealloc (const Vec2 origin, const Size size)
 
static std::shared_ptr< Scene2Texturealloc (float x, float y, float width, float height)
 
- Static Public Member Functions inherited from cugl::Scene2
static std::shared_ptr< Scene2alloc (const Size size)
 
static std::shared_ptr< Scene2alloc (float width, float height)
 
static std::shared_ptr< Scene2alloc (const Rect rect)
 
static std::shared_ptr< Scene2alloc (const Vec2 origin, const Size size)
 
static std::shared_ptr< Scene2alloc (float x, float y, float width, float height)
 

Protected Attributes

std::shared_ptr< Texture_texture
 
std::shared_ptr< RenderTarget_target
 
- Protected Attributes inherited from cugl::Scene2
std::string _name
 
std::shared_ptr< OrthographicCamera_camera
 
std::vector< std::shared_ptr< scene2::SceneNode > > _children
 
Color4 _color
 
GLenum _blendEquation
 
GLenum _srcFactor
 
GLenum _dstFactor
 
bool _active
 

Detailed Description

This class provides the root node of an offscreen scene graph.

This subclass of Scene2 supports offscreen rendering to a texture. It has its own RenderTarget, which is what it uses to render to. You can then access the result of the render with getTexture(). The rendering process ensures that the origin of the scene is rendered to the bottom left corner of the texture (and not the top right, as is the default in OpenGL), making it consist with sprite-based images used by the scene graph.

As a result, this class provides support for simple multi-pass rendering. Simply render to a scene to a texture in one pass, and then use that texture in future passes.

Constructor & Destructor Documentation

◆ Scene2Texture()

cugl::Scene2Texture::Scene2Texture ( )

Creates a new degenerate Scene2Texture on the stack.

The scene has no camera and must be initialized.

NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate an object on the heap, use one of the static constructors instead.

◆ ~Scene2Texture()

cugl::Scene2Texture::~Scene2Texture ( )
inline

Deletes this scene, disposing all resources

Member Function Documentation

◆ alloc() [1/5]

static std::shared_ptr<Scene2Texture> cugl::Scene2Texture::alloc ( const Rect  rect)
inlinestatic

Returns a newly allocated Scene2Texture for the given viewport.

Offseting the viewport origin has little affect on the Scene in general. It only affects the coordinate conversion methods Camera#project() and Camera#unproject(). It is supposed to represent the offset

Parameters
rectThe viewport bounding box
Returns
a newly allocated Scene for the given viewport.

◆ alloc() [2/5]

static std::shared_ptr<Scene2Texture> cugl::Scene2Texture::alloc ( const Size  size)
inlinestatic

Returns a newly allocated Scene2Texture for the given viewport.

The viewport origin is assumed to be (0,0).

Parameters
sizeThe viewport size
Returns
a newly allocated Scene for the given viewport.

◆ alloc() [3/5]

static std::shared_ptr<Scene2Texture> cugl::Scene2Texture::alloc ( const Vec2  origin,
const Size  size 
)
inlinestatic

Returns a newly allocated Scene2Texture for the given viewport.

Offseting the viewport origin has little affect on the Scene in general. It only affects the coordinate conversion methods Camera#project() and Camera#unproject(). It is supposed to represent the offset

Parameters
originThe viewport offset
sizeThe viewport size
Returns
a newly allocated Scene for the given viewport.

◆ alloc() [4/5]

static std::shared_ptr<Scene2Texture> cugl::Scene2Texture::alloc ( float  width,
float  height 
)
inlinestatic

Returns a newly allocated Scene2Texture for the given viewport.

The viewport origin is assumed to be (0,0).

Parameters
widthThe viewport width
heightThe viewport height
Returns
a newly allocated Scene for the given viewport.

◆ alloc() [5/5]

static std::shared_ptr<Scene2Texture> cugl::Scene2Texture::alloc ( float  x,
float  y,
float  width,
float  height 
)
inlinestatic

Returns a newly allocated Scene2Texture for the given viewport.

Offseting the viewport origin has little affect on the Scene in general. It only affects the coordinate conversion methods Camera#project() and Camera#unproject(). It is supposed to represent the offset

Parameters
xThe viewport x offset
yThe viewport y offset
widthThe viewport width
heightThe viewport height
Returns
a newly allocated Scene for the given viewport.

◆ dispose()

virtual void cugl::Scene2Texture::dispose ( )
overridevirtual

Disposes all of the resources used by this scene.

A disposed Scene2Texture can be safely reinitialized. Any children owned by this scene will be released. They will be deleted if no other object owns them.

Reimplemented from cugl::Scene2.

◆ getTexture()

std::shared_ptr<Texture> cugl::Scene2Texture::getTexture ( ) const
inline

Returns the texture associated with this scene graph.

Rendering this scene graph will draw to the offscreen texture. This method returns that texture so that it can be used in subsequent passes.

Returns
the texture associated with this scene graph.

◆ init() [1/5]

bool cugl::Scene2Texture::init ( const Rect  rect)
inline

Initializes a Scene2Texture with the given viewport.

Offseting the viewport origin has little affect on the scene in general. It only affects the coordinate conversion methods Camera#project() and Camera#unproject(). It is supposed to represent the offset of the viewport in a larger canvas.

Parameters
rectThe viewport bounding box
Returns
true if initialization was successful.

◆ init() [2/5]

bool cugl::Scene2Texture::init ( const Size  size)
inline

Initializes a Scene2Texture with the given viewport.

The viewport origin is assumed to be (0,0).

Parameters
sizeThe viewport size
Returns
true if initialization was successful.

◆ init() [3/5]

bool cugl::Scene2Texture::init ( const Vec2  origin,
const Size  size 
)
inline

Initializes a Scene2Texture with the given viewport.

Offseting the viewport origin has little affect on the scene in general. It only affects the coordinate conversion methods Camera#project() and Camera#unproject(). It is supposed to represent the offset of the viewport in a larger canvas.

Parameters
originThe viewport offset
sizeThe viewport size
Returns
true if initialization was successful.

◆ init() [4/5]

bool cugl::Scene2Texture::init ( float  width,
float  height 
)
inline

Initializes a Scene2Texture with the given viewport.

The viewport origin is assumed to be (0,0).

Parameters
widthThe viewport width
heightThe viewport height
Returns
true if initialization was successful.

◆ init() [5/5]

virtual bool cugl::Scene2Texture::init ( float  x,
float  y,
float  width,
float  height 
)
overridevirtual

Initializes a Scene2Texture with the given viewport.

Offseting the viewport origin has little affect on the scene in general. It only affects the coordinate conversion methods Camera#project() and Camera#unproject(). It is supposed to represent the offset of the viewport in a larger canvas.

Parameters
xThe viewport x offset
yThe viewport y offset
widthThe viewport width
heightThe viewport height
Returns
true if initialization was successful.

Reimplemented from cugl::Scene2.

◆ render()

virtual void cugl::Scene2Texture::render ( const std::shared_ptr< SpriteBatch > &  batch)
overridevirtual

Draws all of the children in this scene with the given SpriteBatch.

This method assumes that the sprite batch is not actively drawing. It will call both begin() and end().

Rendering happens by traversing the the scene graph using an "Pre-Order" tree traversal algorithm ( https://en.wikipedia.org/wiki/Tree_traversal#Pre-order ). That means that parents are always draw before (and behind children). To override this draw order, you should place an scene2::OrderedNode in the scene graph to specify an alternative order.

This will render to the offscreen texture associated with this scene. That texture can then be used in subsequent render passes.

Parameters
batchThe SpriteBatch to draw with.

Reimplemented from cugl::Scene2.

Member Data Documentation

◆ _target

std::shared_ptr<RenderTarget> cugl::Scene2Texture::_target
protected

The offscreen buffer for rendering the texture.

◆ _texture

std::shared_ptr<Texture> cugl::Scene2Texture::_texture
protected

The texture created by this scene


The documentation for this class was generated from the following file: