Interface to drawing graphics. More...

#include <graphic_context.h>

Public Member Functions

 GraphicContext ()
 Constructs a null instance. More...
 
 GraphicContext (GraphicContextProvider *provider)
 
 ~GraphicContext ()
 
void clear (const Colorf &color=StandardColorf::black())
 Clears the whole context using the specified color. More...
 
void clear_depth (float value=0)
 
void clear_stencil (int value=0)
 
GraphicContext clone () const
 Create a new default graphic context cloned with this one. More...
 
GraphicContext create () const
 Create a new default graphic context compatible with this one. More...
 
GraphicContext create (FrameBuffer &buffer) const
 Create a new default graphic context with a frame buffer selected. More...
 
void dispatch (int x=1, int y=1, int z=1)
 Execute a compute shader. More...
 
void draw_primitives (PrimitivesType type, int num_vertices, const PrimitivesArray &array)
 Draw primitives on gc. More...
 
void draw_primitives_array (PrimitivesType type, int num_vertices)
 Draws primitives from the current assigned primitives array. More...
 
void draw_primitives_array (PrimitivesType type, int offset, int num_vertices)
 
void draw_primitives_array_instanced (PrimitivesType type, int offset, int num_vertices, int instance_count)
 
void draw_primitives_elements (PrimitivesType type, int count, VertexAttributeDataType indices_type, size_t offset=0)
 
void draw_primitives_elements (PrimitivesType type, int count, ElementArrayBuffer &element_array, VertexAttributeDataType indices_type, size_t offset=0)
 
void draw_primitives_elements (PrimitivesType type, int count, ElementArrayVector< unsigned int > &element_array, size_t offset=0)
 
void draw_primitives_elements (PrimitivesType type, int count, ElementArrayVector< unsigned short > &element_array, size_t offset=0)
 
void draw_primitives_elements (PrimitivesType type, int count, ElementArrayVector< unsigned char > &element_array, size_t offset=0)
 
void draw_primitives_elements_instanced (PrimitivesType type, int count, VertexAttributeDataType indices_type, size_t offset, int instance_count)
 
void draw_primitives_elements_instanced (PrimitivesType type, int count, ElementArrayBuffer &element_array, VertexAttributeDataType indices_type, size_t offset, int instance_count)
 
void draw_primitives_elements_instanced (PrimitivesType type, int count, ElementArrayVector< unsigned int > &element_array, size_t offset, int instance_count)
 
void draw_primitives_elements_instanced (PrimitivesType type, int count, ElementArrayVector< unsigned short > &element_array, size_t offset, int instance_count)
 
void draw_primitives_elements_instanced (PrimitivesType type, int count, ElementArrayVector< unsigned char > &element_array, size_t offset, int instance_count)
 
void flush ()
 Flush the command buffer. More...
 
ClipZRange get_clip_z_range () const
 Returns in what range clip space z values are clipped. More...
 
float get_dip_height () const
 
Sizef get_dip_size () const
 
float get_dip_width () const
 
int get_height () const
 Returns the current actual height of the context. More...
 
int get_major_version () const
 
Size get_max_texture_size () const
 
int get_minor_version () const
 
float get_pixel_ratio () const
 
PixelBuffer get_pixeldata (const Rect &rect, TextureFormat texture_format=tf_rgba8, bool clamp=true)
 Return the content of the read buffer into a pixel buffer. More...
 
PixelBuffer get_pixeldata (TextureFormat texture_format=tf_rgba8, bool clamp=true)
 Return the content of the read buffer into a pixel buffer. More...
 
ProgramObject get_program_object () const
 Returns the currently selected program object. More...
 
GraphicContextProviderget_provider ()
 Returns the provider for this graphic context. More...
 
const GraphicContextProviderget_provider () const
 
FrameBuffer get_read_frame_buffer () const
 
ShaderLanguage get_shader_language () const
 Returns the shader language used. More...
 
Size get_size () const
 Returns the current actual size of the context. More...
 
Texture get_texture (int index) const
 
TextureImageYAxis get_texture_image_y_axis () const
 Returns the Y axis direction for viewports, clipping rects, textures and render targets. More...
 
std::vector< Textureget_textures () const
 
int get_width () const
 Returns the current actual width of the context. More...
 
FrameBuffer get_write_frame_buffer () const
 
bool has_compute_shader_support () const
 
bool is_frame_buffer_owner (const FrameBuffer &fb)
 
bool is_null () const
 Returns true if this object is invalid. More...
 
bool is_primitives_array_owner (const PrimitivesArray &primitives_array)
 
 operator bool () const
 
bool operator!= (const GraphicContext &other) const
 
bool operator== (const GraphicContext &other) const
 
void reset_blend_state ()
 Set active blend state. More...
 
void reset_depth_stencil_state ()
 Set active depth stencil state. More...
 
void reset_frame_buffer ()
 Resets the current frame buffer to be the initial frame buffer. More...
 
void reset_image_texture (int unit_index)
 
void reset_image_textures ()
 Remove all selected textures. More...
 
void reset_primitives_array ()
 Reset the primitives arrays. More...
 
void reset_primitives_elements ()
 Resets current elements array buffer. More...
 
void reset_program_object ()
 Remove active program object. More...
 
void reset_rasterizer_state ()
 Set active rasterizer state. More...
 
void reset_scissor ()
 Removes the set clipping rectangle. More...
 
void reset_storage_buffer (int index)
 Remove storage buffer from index. More...
 
void reset_texture (int unit_index)
 
void reset_textures ()
 Remove all selected textures. More...
 
void reset_uniform_buffer (int index)
 Remove uniform buffer from index. More...
 
void set_blend_state (const BlendState &state, const Colorf &blend_color=StandardColorf::white(), unsigned int sample_mask=0xffffffff)
 Set active blend state. More...
 
void set_depth_range (float n, float f)
 Specifies the depth range for all viewports. More...
 
void set_depth_range (int viewport, float n, float f)
 Specifies the depth range for the specified viewport. More...
 
void set_depth_stencil_state (const DepthStencilState &state, int stencil_ref=0)
 Set active depth stencil state. More...
 
void set_draw_buffer (DrawBuffer buffer)
 Set used draw buffer. More...
 
void set_frame_buffer (const FrameBuffer &write_buffer)
 Sets the current frame buffer. More...
 
void set_frame_buffer (const FrameBuffer &write_buffer, const FrameBuffer &read_buffer)
 
void set_image_texture (int unit_index, const Texture &texture)
 
void set_image_texture (std::vector< Texture > &textures)
 
void set_primitives_array (const PrimitivesArray &array)
 Set the primitives array on the gc. More...
 
void set_primitives_elements (ElementArrayBuffer &element_array)
 Sets current elements array buffer. More...
 
template<typename Type >
void set_primitives_elements (ElementArrayVector< Type > &element_array)
 Sets current elements array buffer. More...
 
void set_program_object (StandardProgram standard_program)
 Set active program object to the standard program specified. More...
 
void set_program_object (const ProgramObject &program)
 
void set_rasterizer_state (const RasterizerState &state)
 Set active rasterizer state. More...
 
void set_scissor (const Rect &rect, TextureImageYAxis y_axis)
 Set the current clipping rectangle. More...
 
void set_storage_buffer (int index, const StorageBuffer &buffer)
 Select storage buffer into index. More...
 
void set_texture (int unit_index, const Texture &texture)
 
void set_textures (std::vector< Texture > &textures)
 
void set_uniform_buffer (int index, const UniformBuffer &buffer)
 Select uniform buffer into index. More...
 
void set_viewport (const Rectf &viewport)
 
void set_viewport (int index, const Rectf &viewport)
 
void throw_if_null () const
 Throw an exception if this object is invalid. More...
 

Friends

class OpenGL
 

Detailed Description

Interface to drawing graphics.

Constructor & Destructor Documentation

clan::GraphicContext::GraphicContext ( )

Constructs a null instance.

clan::GraphicContext::GraphicContext ( GraphicContextProvider provider)

Constructs a new graphic context from a provider.

Parameters
provider= Graphic Context Provider
clan::GraphicContext::~GraphicContext ( )

Member Function Documentation

void clan::GraphicContext::clear ( const Colorf color = StandardColorf::black())

Clears the whole context using the specified color.

void clan::GraphicContext::clear_depth ( float  value = 0)

Clear the depth buffer

Parameters
valuevalue to clear to. Range 0.0 - 1.0.
void clan::GraphicContext::clear_stencil ( int  value = 0)

Clear the stencil buffer

Parameters
valuevalue to clear to.
GraphicContext clan::GraphicContext::clone ( ) const

Create a new default graphic context cloned with this one.

GraphicContext clan::GraphicContext::create ( ) const

Create a new default graphic context compatible with this one.

GraphicContext clan::GraphicContext::create ( FrameBuffer buffer) const

Create a new default graphic context with a frame buffer selected.

void clan::GraphicContext::dispatch ( int  x = 1,
int  y = 1,
int  z = 1 
)

Execute a compute shader.

void clan::GraphicContext::draw_primitives ( PrimitivesType  type,
int  num_vertices,
const PrimitivesArray array 
)

Draw primitives on gc.

void clan::GraphicContext::draw_primitives_array ( PrimitivesType  type,
int  num_vertices 
)

Draws primitives from the current assigned primitives array.

void clan::GraphicContext::draw_primitives_array ( PrimitivesType  type,
int  offset,
int  num_vertices 
)

Draw primitives array

Parameters
type= Primitives Type
offset= value
num_vertices= value
void clan::GraphicContext::draw_primitives_array_instanced ( PrimitivesType  type,
int  offset,
int  num_vertices,
int  instance_count 
)

Draw primitives array instanced

Parameters
type= Primitives Type
offset= value
num_vertices= value
instance_count= number of instances drawn
void clan::GraphicContext::draw_primitives_elements ( PrimitivesType  type,
int  count,
VertexAttributeDataType  indices_type,
size_t  offset = 0 
)

Draw primitives elements

Parameters
type= Primitives Type
count= value
indices_type= Vertex Attribute Data Type
offset= void

Referenced by draw_primitives_elements().

void clan::GraphicContext::draw_primitives_elements ( PrimitivesType  type,
int  count,
ElementArrayBuffer element_array,
VertexAttributeDataType  indices_type,
size_t  offset = 0 
)

Draw primitives elements

Parameters
type= Primitives Type
count= value
element_array= Element Array Buffer
indices_type= Vertex Attribute Data Type
offset= void
void clan::GraphicContext::draw_primitives_elements ( PrimitivesType  type,
int  count,
ElementArrayVector< unsigned int > &  element_array,
size_t  offset = 0 
)
inline

Draw primitives elements

Parameters
type= Primitives Type
count= value
element_array= Element Array Buffer
indices_type= Vertex Attribute Data Type
offset= void

References draw_primitives_elements(), and clan::type_unsigned_int.

void clan::GraphicContext::draw_primitives_elements ( PrimitivesType  type,
int  count,
ElementArrayVector< unsigned short > &  element_array,
size_t  offset = 0 
)
inline

Draw primitives elements

Parameters
type= Primitives Type
count= value
element_array= Element Array Buffer
indices_type= Vertex Attribute Data Type
offset= void

References draw_primitives_elements(), and clan::type_unsigned_short.

void clan::GraphicContext::draw_primitives_elements ( PrimitivesType  type,
int  count,
ElementArrayVector< unsigned char > &  element_array,
size_t  offset = 0 
)
inline

Draw primitives elements

Parameters
type= Primitives Type
count= value
element_array= Element Array Buffer
indices_type= Vertex Attribute Data Type
offset= void

References draw_primitives_elements(), and clan::type_unsigned_byte.

void clan::GraphicContext::draw_primitives_elements_instanced ( PrimitivesType  type,
int  count,
VertexAttributeDataType  indices_type,
size_t  offset,
int  instance_count 
)

Draw primitives elements instanced

Parameters
type= Primitives Type
count= value
indices_type= Vertex Attribute Data Type
offset= void
instance_count= number of instances drawn

Referenced by draw_primitives_elements_instanced().

void clan::GraphicContext::draw_primitives_elements_instanced ( PrimitivesType  type,
int  count,
ElementArrayBuffer element_array,
VertexAttributeDataType  indices_type,
size_t  offset,
int  instance_count 
)

Draw primitives elements instanced

Parameters
type= Primitives Type
count= value
element_array= Element Array Buffer
indices_type= Vertex Attribute Data Type
offset= void
instance_count= number of instances drawn
void clan::GraphicContext::draw_primitives_elements_instanced ( PrimitivesType  type,
int  count,
ElementArrayVector< unsigned int > &  element_array,
size_t  offset,
int  instance_count 
)
inline

Draw primitives elements instanced

Parameters
type= Primitives Type
count= value
element_array= Element Array Buffer
indices_type= Vertex Attribute Data Type
offset= void
instance_count= number of instances drawn

References draw_primitives_elements_instanced(), and clan::type_unsigned_int.

void clan::GraphicContext::draw_primitives_elements_instanced ( PrimitivesType  type,
int  count,
ElementArrayVector< unsigned short > &  element_array,
size_t  offset,
int  instance_count 
)
inline

Draw primitives elements instanced

Parameters
type= Primitives Type
count= value
element_array= Element Array Buffer
indices_type= Vertex Attribute Data Type
offset= void
instance_count= number of instances drawn

References draw_primitives_elements_instanced(), and clan::type_unsigned_short.

void clan::GraphicContext::draw_primitives_elements_instanced ( PrimitivesType  type,
int  count,
ElementArrayVector< unsigned char > &  element_array,
size_t  offset,
int  instance_count 
)
inline

Draw primitives elements instanced

Parameters
type= Primitives Type
count= value
element_array= Element Array Buffer
indices_type= Vertex Attribute Data Type
offset= void
instance_count= number of instances drawn

References draw_primitives_elements_instanced(), and clan::type_unsigned_byte.

void clan::GraphicContext::flush ( )

Flush the command buffer.

ClipZRange clan::GraphicContext::get_clip_z_range ( ) const

Returns in what range clip space z values are clipped.

float clan::GraphicContext::get_dip_height ( ) const
inline

Calculates the device independent height of the context. Resolution Independence

References get_height(), and get_pixel_ratio().

Referenced by get_dip_size(), and clan::Canvas::get_height().

Sizef clan::GraphicContext::get_dip_size ( ) const
inline

Calculates the device independent dimensions of the context. Resolution Independence

References get_dip_height(), and get_dip_width().

Referenced by clan::Canvas::get_size().

float clan::GraphicContext::get_dip_width ( ) const
inline

Calculates the device independent width of the context. Resolution Independence

References get_pixel_ratio(), and get_width().

Referenced by get_dip_size(), and clan::Canvas::get_width().

int clan::GraphicContext::get_height ( ) const

Returns the current actual height of the context.

Referenced by get_dip_height().

int clan::GraphicContext::get_major_version ( ) const

Returns the major version / feature level supported by the hardware. For an OpenGL target, this returns the major OpenGL version the driver supports. For a Direct3D target, this returns the major feature level.

Size clan::GraphicContext::get_max_texture_size ( ) const

Retrieves the maximum size for a texture that this graphic context will allow. Size(0, 0) will be returned if there is no known limitation to the maximum texture size allowed for the context.

int clan::GraphicContext::get_minor_version ( ) const

Returns the minor version / feature level supported by the hardware. For an OpenGL target, this returns the minor OpenGL version the driver supports. For a Direct3D target, this returns the minor feature level.

float clan::GraphicContext::get_pixel_ratio ( ) const

Retrieves the display pixel ratio of the context. Resolution Independence

Referenced by get_dip_height(), get_dip_width(), and clan::Canvas::get_pixel_ratio().

PixelBuffer clan::GraphicContext::get_pixeldata ( const Rect rect,
TextureFormat  texture_format = tf_rgba8,
bool  clamp = true 
)

Return the content of the read buffer into a pixel buffer.

PixelBuffer clan::GraphicContext::get_pixeldata ( TextureFormat  texture_format = tf_rgba8,
bool  clamp = true 
)

Return the content of the read buffer into a pixel buffer.

ProgramObject clan::GraphicContext::get_program_object ( ) const

Returns the currently selected program object.

GraphicContextProvider* clan::GraphicContext::get_provider ( )

Returns the provider for this graphic context.

const GraphicContextProvider* clan::GraphicContext::get_provider ( ) const
FrameBuffer clan::GraphicContext::get_read_frame_buffer ( ) const

Returns the currently selected read frame buffer.

Returns
The frame buffer. Use frame_buffer.is_null() to determine if the frame buffer was not selected
ShaderLanguage clan::GraphicContext::get_shader_language ( ) const

Returns the shader language used.

Size clan::GraphicContext::get_size ( ) const

Returns the current actual size of the context.

Texture clan::GraphicContext::get_texture ( int  index) const

Retrieves the texture selected in this context with an index number.

Parameters
indexThe texture index number to retrieve. [0 to n]
Returns
The texture on the specified index. Use Texture::is_null() to determine whether the texture has been selected by the context.
TextureImageYAxis clan::GraphicContext::get_texture_image_y_axis ( ) const

Returns the Y axis direction for viewports, clipping rects, textures and render targets.

std::vector<Texture> clan::GraphicContext::get_textures ( ) const

Returns the textures currently selected in this context.

Returns
A vector containing the selected textures. The vector may contain null (unselected) texture elements within it..
int clan::GraphicContext::get_width ( ) const

Returns the current actual width of the context.

Referenced by get_dip_width().

FrameBuffer clan::GraphicContext::get_write_frame_buffer ( ) const

Returns the currently selected write frame buffer.

Returns
The frame buffer. Use frame_buffer.is_null() to determine if the frame buffer was not selected
bool clan::GraphicContext::has_compute_shader_support ( ) const

Returns true if the hardware supports compute shaders. This function will always returns true for OpenGL 4.3 or newer, or Direct3D 11.0 or newer. For Direct3D 10.0 and 10.1, the support for compute shaders is optional.

bool clan::GraphicContext::is_frame_buffer_owner ( const FrameBuffer fb)

Returns true if this frame buffer object is owned by this graphic context.

Frame buffer objects cannot be shared between graphic contexts. This function will verify if the frame buffer object belongs to this graphic context.

bool clan::GraphicContext::is_null ( ) const
inline

Returns true if this object is invalid.

bool clan::GraphicContext::is_primitives_array_owner ( const PrimitivesArray primitives_array)

Returns true if this primitives array is owned by this graphic context.

Primitive array objects cannot be shared between graphic contexts. This function verifies that the primitives array belongs to this graphic context.

clan::GraphicContext::operator bool ( ) const
inlineexplicit
bool clan::GraphicContext::operator!= ( const GraphicContext other) const
inline
bool clan::GraphicContext::operator== ( const GraphicContext other) const
inline
void clan::GraphicContext::reset_blend_state ( )

Set active blend state.

void clan::GraphicContext::reset_depth_stencil_state ( )

Set active depth stencil state.

void clan::GraphicContext::reset_frame_buffer ( )

Resets the current frame buffer to be the initial frame buffer.

void clan::GraphicContext::reset_image_texture ( int  unit_index)

Remove texture from index.

Parameters
unit_index= 0 to x, the index of the texture
void clan::GraphicContext::reset_image_textures ( )

Remove all selected textures.

void clan::GraphicContext::reset_primitives_array ( )

Reset the primitives arrays.

void clan::GraphicContext::reset_primitives_elements ( )

Resets current elements array buffer.

void clan::GraphicContext::reset_program_object ( )

Remove active program object.

void clan::GraphicContext::reset_rasterizer_state ( )

Set active rasterizer state.

void clan::GraphicContext::reset_scissor ( )

Removes the set clipping rectangle.

void clan::GraphicContext::reset_storage_buffer ( int  index)

Remove storage buffer from index.

void clan::GraphicContext::reset_texture ( int  unit_index)

Remove texture from index.

Parameters
unit_index= 0 to x, the index of the texture
void clan::GraphicContext::reset_textures ( )

Remove all selected textures.

void clan::GraphicContext::reset_uniform_buffer ( int  index)

Remove uniform buffer from index.

void clan::GraphicContext::set_blend_state ( const BlendState state,
const Colorf blend_color = StandardColorf::white(),
unsigned int  sample_mask = 0xffffffff 
)

Set active blend state.

void clan::GraphicContext::set_depth_range ( float  n,
float  f 
)

Specifies the depth range for all viewports.

void clan::GraphicContext::set_depth_range ( int  viewport,
float  n,
float  f 
)

Specifies the depth range for the specified viewport.

void clan::GraphicContext::set_depth_stencil_state ( const DepthStencilState state,
int  stencil_ref = 0 
)

Set active depth stencil state.

void clan::GraphicContext::set_draw_buffer ( DrawBuffer  buffer)

Set used draw buffer.

void clan::GraphicContext::set_frame_buffer ( const FrameBuffer write_buffer)

Sets the current frame buffer.

void clan::GraphicContext::set_frame_buffer ( const FrameBuffer write_buffer,
const FrameBuffer read_buffer 
)
void clan::GraphicContext::set_image_texture ( int  unit_index,
const Texture texture 
)

Select texture image into index.

Parameters
unit_index= 0 to x, the index of this texture
texture= The texture to select. This can be an empty texture Texture()
void clan::GraphicContext::set_image_texture ( std::vector< Texture > &  textures)

Select texture images

Only textures units from 0 to textures.size()-1 are set.

Parameters
textures= The texture to select (placed at unit_index 0 to texture.size()-1). These may contain null textures
void clan::GraphicContext::set_primitives_array ( const PrimitivesArray array)

Set the primitives array on the gc.

void clan::GraphicContext::set_primitives_elements ( ElementArrayBuffer element_array)

Sets current elements array buffer.

Referenced by set_primitives_elements().

template<typename Type >
void clan::GraphicContext::set_primitives_elements ( ElementArrayVector< Type > &  element_array)
inline

Sets current elements array buffer.

References set_primitives_elements().

void clan::GraphicContext::set_program_object ( StandardProgram  standard_program)

Set active program object to the standard program specified.

void clan::GraphicContext::set_program_object ( const ProgramObject program)

Set active program object.

Parameters
program= Program to set
void clan::GraphicContext::set_rasterizer_state ( const RasterizerState state)

Set active rasterizer state.

void clan::GraphicContext::set_scissor ( const Rect rect,
TextureImageYAxis  y_axis 
)

Set the current clipping rectangle.

void clan::GraphicContext::set_storage_buffer ( int  index,
const StorageBuffer buffer 
)

Select storage buffer into index.

void clan::GraphicContext::set_texture ( int  unit_index,
const Texture texture 
)

Select texture into index.

Parameters
unit_index= 0 to x, the index of this texture
texture= The texture to select. This can be an empty texture Texture()
void clan::GraphicContext::set_textures ( std::vector< Texture > &  textures)

Select textures

Only textures units from 0 to textures.size()-1 are set.

Parameters
textures= The texture to select (placed at unit_index 0 to texture.size()-1). These may contain null textures
void clan::GraphicContext::set_uniform_buffer ( int  index,
const UniformBuffer buffer 
)

Select uniform buffer into index.

void clan::GraphicContext::set_viewport ( const Rectf viewport)

Set the viewport to be used in user projection map mode.

Parameters
viewport= The viewport to set
void clan::GraphicContext::set_viewport ( int  index,
const Rectf viewport 
)

Set the specified viewport to be used in user projection map mode.

Parameters
index= The viewport index (0 to x)
viewport= The viewport to set
void clan::GraphicContext::throw_if_null ( ) const

Throw an exception if this object is invalid.

Friends And Related Function Documentation

friend class OpenGL
friend

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