Public Types | Public Member Functions | Private Attributes | List of all members
nom::Texture Class Reference
Collaboration diagram for nom::Texture:
[legend]

Public Types

typedef std::shared_ptr< Texture > SharedPtr
 

Public Member Functions

 Texture (void)
 Default constructor.
 
 ~Texture (void)
 Lazy destructor.
 
 Texture (const Texture &other)
 Copy constructor.
 
bool initialize (SDL_SURFACE::RawPtr video_buffer)
 
bool initialize (int32 width, int32 height, uint32 format, uint32 flags)
 
Texture::SharedPtr clone (void) const
 
Texture & operator= (const Texture &other)
 Copy assignment operator.
 
const Point2i & position (void) const
 
const Coords & bounds (void) const
 
SDL_TEXTURE::RawPtr texture (void) const
 Get the video memory surface of the Texture object.
 
bool valid (void) const
 Is this object initialized – not nullptr?
 
int access (void) const
 
void set_position (const Point2i &pos)
 
void set_bounds (const Coords &clip)
 
int32 width (void) const
 
int32 height (void) const
 
int pitch (void) const
 
void * pixels (void) const
 
uint8 bytes_per_pixel (void) const
 
uint32 pixel_format (void) const
 
uint8 bits_per_pixel (void) const
 
const SDL_BlendMode blend_mode (void) const
 Obtain the blending mode used for texture copies.
 
bool locked (void) const
 Query memory lock status.
 
const Color & colorkey (void) const
 
bool lock (void)
 
bool lock (const Coords &lock_coords)
 
void unlock (void)
 
bool load (const std::string &filename, uint32 flags, bool use_cache=false)
 
bool update (const void *pixels, uint16 pitch, const Coords &update_area)
 Upload texture copy with new pixel data.
 
void draw (SDL_RENDERER::RawPtr target) const
 
void draw (const Window &target) const
 
void draw (SDL_RENDERER::RawPtr target, const double angle) const
 
void draw (const Window &target, const double angle) const
 
bool set_alpha (uint8 opacity)
 
uint32 pixel (int32 x, int32 y)
 
bool resize (enum ResizeAlgorithm scaling_algorithm)
 
bool resize (const Point2f &scale_factor)
 
int32 getResizeScaleFactor (enum ResizeAlgorithm scaling_algorithm)
 
bool set_blend_mode (const SDL_BlendMode blend)
 Set a new blending mode for this texture.
 
bool set_colorkey (const Color &colorkey)
 

Private Attributes

SDL_TEXTURE::SharedPtr texture_
 
void * pixels_
 
int pitch_
 Texture's pixel pitch; these are only available when a Texture is locked.
 
Point2i position_
 Holds surface position (X, Y)
 
Coords bounds_
 Holds surface offsets (clipping area: X, Y, width & height)
 
Color colorkey_
 Cached upon use of the set_colorkey method for use by external classes.
 

Detailed Description

Definition at line 67 of file Texture.hpp.

Member Function Documentation

int nom::Texture::access ( void  ) const

Query texture access type

Returns
SDL_TextureAccess enum type

Definition at line 169 of file Texture.cpp.

Here is the call graph for this function:

uint8 nom::Texture::bits_per_pixel ( void  ) const

Calculate this object's bits per pixel (color depth)

Returns
Unsigned 8-bit integer (8, 16, 24 or 32 bits per pixel); zero (0) on error (unknown color depth).
Todo:
Rename me to bpp

Definition at line 248 of file Texture.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8 nom::Texture::bytes_per_pixel ( void  ) const
Todo:
Rename me to BPP

Definition at line 261 of file Texture.cpp.

Here is the caller graph for this function:

Texture::SharedPtr nom::Texture::clone ( void  ) const

Return a std::shared_ptr copy of this instance

Todo:
Test me out!

Definition at line 141 of file Texture.cpp.

const Color & nom::Texture::colorkey ( void  ) const

Obtain the set color key for this image

Returns
Returns non-negative nom::Color on success; nom::Color::null on failure

Definition at line 299 of file Texture.cpp.

Here is the caller graph for this function:

void nom::Texture::draw ( SDL_RENDERER::RawPtr  target) const

Draw a nom::Texture to a SDL_Renderer target

Parameters
SDL_Renderer

Definition at line 422 of file Texture.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void nom::Texture::draw ( const Window &  target) const

Draw a nom::Texture to a nom::Window target

Parameters
nom::Window
Note
This is an alias for nom::Texture::draw ( SDL_Renderer* )

Definition at line 459 of file Texture.cpp.

Here is the call graph for this function:

void nom::Texture::draw ( SDL_RENDERER::RawPtr  target,
const double  angle 
) const

Draw a rotated nom::Texture to a rendering target

Parameters
targetPointer to SDL_Renderer context
angleRotation angle in degrees
Todo:
Implement pivot point & make use of SDL_RendererFlip enum

Definition at line 464 of file Texture.cpp.

Here is the call graph for this function:

void nom::Texture::draw ( const Window &  target,
const double  angle 
) const

Draw a rotated nom::Texture on a nom::Window

Parameters
targetReference to an active nom::Window
angleRotation angle in degrees

Definition at line 501 of file Texture.cpp.

Here is the call graph for this function:

int32 nom::Texture::getResizeScaleFactor ( enum ResizeAlgorithm  scaling_algorithm)

Return the correct scaling factor of the chosen algorithm

Todo:
SDL2 port

Definition at line 836 of file Texture.cpp.

Here is the caller graph for this function:

int32 nom::Texture::height ( void  ) const

Obtain height, in pixels, of texture

Returns
-1 on error; non-zero height on success

Definition at line 225 of file Texture.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool nom::Texture::initialize ( SDL_SURFACE::RawPtr  video_buffer)

Constructor variant for creating a fresh, empty video surface. You should be sure to read over the details gory details scattered throughout the documentation for SDL.

The SDL_SWSURFACE flag is passed by default if an argument is not specified – this is optimal for writing to the video memory buffer directly (pixel manipulation).

As per libSDL docs, this must be called only after video initialization; (SDL_SetVideoMode).

See http://sdl.beuc.net/sdl.wiki/SDL_CreateRGBSurface Construct a video surface object using the data from an existing surface; you can think of this as a copy method. As with the previous method, you ought to read over the technicalities that the SDL library documentation covers.

You remain the owner of the pointer leading to your existing data and therefore are responsible for memory management.

See http://sdl.beuc.net/sdl.wiki/SDL_CreateRGBSurfaceFrom Initialize object with SDL1 video surface

The new texture created will be of type 'SDL_TEXTUREACCESS_STATIC'

Definition at line 97 of file Texture.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool nom::Texture::initialize ( int32  width,
int32  height,
uint32  format,
uint32  flags 
)

Initialize object with new specified parameters ...

Definition at line 123 of file Texture.cpp.

Here is the call graph for this function:

bool nom::Texture::load ( const std::string &  filename,
uint32  flags,
bool  use_cache = false 
)

Load an image into memory from a file

Parameters
filenameFile path you wish to load into memory as a valid bitmap / texture (think: supported image file types).
flags[...TO BE WRITTEN...]
use_cacheWhether or not to use an internal object cache feature of nomlib. Defaults to off.
Todo:
Test/Research Texture caching – nom::ObjectCache worked beautifully with SDL_Surface, is the same true of SDL_Texture?
Todo:
merge 'use_cache' in with 'flags'

Definition at line 353 of file Texture.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool nom::Texture::lock ( void  )

Lock a portion of the texture for write-only pixel access.

Texture must be created with SDL_TEXTUREACCESS_STREAMING.

Definition at line 304 of file Texture.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool nom::Texture::lock ( const Coords &  lock_coords)

Lock a portion of this texture for write-only pixel access.

Texture must be created with SDL_TEXTUREACCESS_STREAMING.

Parameters
lock_coordsThe area encompassing the area to lock for write access.

Definition at line 321 of file Texture.cpp.

Here is the call graph for this function:

uint32 nom::Texture::pixel ( int32  x,
int32  y 
)

Pixel reading – supports 8-bit, 15/16-bit, 24-bit & 32-bit color modes

Returns -1 on error

You are responsible for locking & unlocking of the Texture before-hand

Todo:
Test 8-bit, 15/16-bit & 24-bit pixels

Definition at line 519 of file Texture.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool nom::Texture::resize ( enum ResizeAlgorithm  scaling_algorithm)

Resize the video surface with the chosen rescaling algorithm.

See the ResizeAlgorithm enum for available rescaling algorithms

Todo:
SDL2 port

Definition at line 559 of file Texture.cpp.

Here is the caller graph for this function:

bool nom::Texture::resize ( const Point2f &  scale_factor)
Todo:
SDL2 port

Definition at line 732 of file Texture.cpp.

bool nom::Texture::set_colorkey ( const Color &  colorkey)

Set a new color key

Parameters
colorkeynom::Color object representing the RGB pixel to be marked transparent.
Todo:
ERR check on locking call, etc.

(This method requires locking the texture; use wisely!).

Definition at line 870 of file Texture.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void nom::Texture::set_position ( const Point2i &  pos)

Reset the video surface object with another video surface object.

Todo:
Relocate me to a surface class void setTexture ( const Texture& surface );

Definition at line 201 of file Texture.cpp.

Here is the caller graph for this function:

void nom::Texture::unlock ( void  )

Unlock this texture, thereby uploading any applicable changes to video memory.

Definition at line 340 of file Texture.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int32 nom::Texture::width ( void  ) const

Obtain width, in pixels, of texture

Returns
-1 on error; non-zero width on success

Definition at line 212 of file Texture.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

void* nom::Texture::pixels_
private

Texture's pixels; these are only available when a Texture is locked and is intended for writing to.

Definition at line 296 of file Texture.hpp.


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