CUGL 3.0
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
cugl::scene2::Scene2Texture Class Reference

#include <CUScene2Texture.h>

Inheritance diagram for cugl::scene2::Scene2Texture:
cugl::scene2::Scene2 cugl::Scene

Public Member Functions

 Scene2Texture ()
 
 ~Scene2Texture ()
 
virtual void dispose () override
 
virtual bool init () override
 
bool initWithHint (const Size hint) override
 
bool initWithHint (float width, float height) override
 
virtual void render () override
 
std::shared_ptr< graphics::TexturegetTexture () const
 
- Public Member Functions inherited from cugl::scene2::Scene2
 Scene2 ()
 
 ~Scene2 ()
 
virtual void dispose () override
 
virtual bool init () override
 
virtual bool initWithHint (Size hint) override
 
virtual bool initWithHint (float width, float height) override
 
Color4 getColor ()
 
void setColor (Color4 color)
 
virtual std::string toString (bool verbose=false) const override
 
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 ()
 
std::shared_ptr< graphics::SpriteBatchgetSpriteBatch () const
 
void setSpriteBatch (const std::shared_ptr< graphics::SpriteBatch > &batch)
 
virtual void render () override
 
- Public Member Functions inherited from cugl::Scene
 Scene ()
 
 ~Scene ()
 
virtual void dispose ()
 
virtual bool init ()
 
virtual bool initWithHint (Size hint)
 
virtual bool initWithHint (float width, float height)
 
const std::string getName () const
 
void setName (const std::string name)
 
std::shared_ptr< CameragetCamera ()
 
const std::shared_ptr< CameragetCamera () const
 
virtual std::string toString (bool verbose=false) const
 
 operator std::string () const
 
const Size getSize () const
 
const Rect getBounds () const
 
Vec3 screenToWorldCoords (const Vec2 screenCoords) const
 
Vec2 worldToScreenCoords (const Vec3 worldCoords) const
 
bool isActive () const
 
virtual void setActive (bool value)
 
virtual void update (float timestep)
 
virtual void reset ()
 
virtual void render ()
 

Static Public Member Functions

static std::shared_ptr< Scene2Texturealloc ()
 
static std::shared_ptr< Scene2TextureallocWithHint (const Size hint)
 
static std::shared_ptr< Scene2TextureallocWithHint (float width, float height)
 
- Static Public Member Functions inherited from cugl::scene2::Scene2
static std::shared_ptr< Scene2alloc ()
 
static std::shared_ptr< Scene2allocWithHint (const Size hint)
 
static std::shared_ptr< Scene2allocWithHint (float width, float height)
 

Protected Attributes

std::shared_ptr< graphics::Texture_texture
 
std::shared_ptr< graphics::RenderTarget_target
 
- Protected Attributes inherited from cugl::scene2::Scene2
std::shared_ptr< graphics::SpriteBatch_batch
 
std::vector< std::shared_ptr< scene2::SceneNode > > _children
 
Color4 _color
 
GLenum _blendEquation
 
GLenum _srcFactor
 
GLenum _dstFactor
 
- Protected Attributes inherited from cugl::Scene
std::shared_ptr< Camera_camera
 
std::string _name
 
Size _size
 
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 graphics::RenderTarget, which is what it uses to render to. You can then access the result of this 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::scene2::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::scene2::Scene2Texture::~Scene2Texture ( )
inline

Deletes this scene, disposing all resources

Member Function Documentation

◆ alloc()

static std::shared_ptr< Scene2Texture > cugl::scene2::Scene2Texture::alloc ( )
inlinestatic

Returns a newly allocated Scene to fill the entire screen.

Returns
a newly allocated Scene to fill the entire screen..

◆ allocWithHint() [1/2]

static std::shared_ptr< Scene2Texture > cugl::scene2::Scene2Texture::allocWithHint ( const Size  hint)
inlinestatic

Returns a newly allocated Scene2Texture with the given size hint.

Scenes are designed to fill the entire screen. If you want a scene that is only part of the screen, that should be implemented with a specific scene graph. However, the size of that screen can vary from device to device. To make scene design easier, designs are typically locked to a dimension: width or height.

This is the purpose of the size hint. If either of the values of hint are non-zero, then the scene will lock that dimension to that particular size. If both are non-zero, it will choose its dimension according to the device orientation. Landscape will be height, while portrait will pick width. Devices with no orientation will always priortize height over width.

Parameters
hintThe size hint
Returns
a newly allocated Scene2Texture with the given size hint.

◆ allocWithHint() [2/2]

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

Returns a newly allocated Scene2Texture with the given size hint.

Scenes are designed to fill the entire screen. If you want a scene that is only part of the screen, that should be implemented with a specific scene graph. However, the size of that screen can vary from device to device. To make scene design easier, designs are typically locked to a dimension: width or height.

This is the purpose of the size hint. If either of the values of hint are non-zero, then the scene will lock that dimension to that particular size. If both are non-zero, it will choose its dimension according to the device orientation. Landscape will be height, while portrait will pick width. Devices with no orientation will always priortize height over width.

Parameters
widthThe width size hint
heightThe height size hint
Returns
a newly allocated Scene2Texture with the given size hint.

◆ dispose()

virtual void cugl::scene2::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::Scene2.

◆ getTexture()

std::shared_ptr< graphics::Texture > cugl::scene2::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()

virtual bool cugl::scene2::Scene2Texture::init ( )
overridevirtual

Initializes a Scene to fill the entire screen.

Returns
true if initialization was successful.

Reimplemented from cugl::scene2::Scene2.

◆ initWithHint() [1/2]

bool cugl::scene2::Scene2Texture::initWithHint ( const Size  hint)
overridevirtual

Initializes a Scene2Texture with the given size hint.

Scenes are designed to fill the entire screen. If you want a scene that is only part of the screen, that should be implemented with a specific scene graph. However, the size of that screen can vary from device to device. To make scene design easier, designs are typically locked to a dimension: width or height.

This is the purpose of the size hint. If either of the values of hint are non-zero, then the scene will lock that dimension to that particular size. If both are non-zero, it will choose its dimension according to the device orientation. Landscape will be height, while portrait will pick width. Devices with no orientation will always priortize height over width.

Parameters
hintThe size hint
Returns
a newly allocated Scene with the given size hint.

Reimplemented from cugl::scene2::Scene2.

◆ initWithHint() [2/2]

bool cugl::scene2::Scene2Texture::initWithHint ( float  width,
float  height 
)
inlineoverridevirtual

Initializes a Scene2Texture with the given size hint.

Scenes are designed to fill the entire screen. If you want a scene that is only part of the screen, that should be implemented with a specific scene graph. However, the size of that screen can vary from device to device. To make scene design easier, designs are typically locked to a dimension: width or height.

This is the purpose of the size hint. If either of the values of hint are non-zero, then the scene will lock that dimension to that particular size. If both are non-zero, it will choose its dimension according to the device orientation. Landscape will be height, while portrait will pick width. Devices with no orientation will always priortize height over width.

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

Reimplemented from cugl::scene2::Scene2.

◆ render()

virtual void cugl::scene2::Scene2Texture::render ( )
overridevirtual

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

This method with draw using getSpriteBatch. If not sprite batch has been assigned, nothing will be drawn.

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 OrderedNode in the scene graph to specify an alternative order.

Reimplemented from cugl::scene2::Scene2.

Member Data Documentation

◆ _target

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

The offscreen buffer for rendering the texture.

◆ _texture

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

The texture created by this scene


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