smk::BlendMode Struct Reference

#include <BlendMode.hpp>

Description

Blending modes for drawing.

When drawing something into a smk::RenderTarget, the smk::BlendMode represents how the colors are mixed with the colors already in the color buffer.

Commonly used BlendMode

SMK provides 6 predefined common BlendMode:

smk::BlendMode::Add; // dst += src
smk::BlendMode::Alpha; // dst = src * a + dest * (1 - a)
smk::BlendMode::Invert; // dst = 1 - dst
static const BlendMode Add
destination += source.
Definition: BlendMode.hpp:65
static const BlendMode Subtract
destination -= source.
Definition: BlendMode.hpp:66
static const BlendMode Multiply
destination *= source
Definition: BlendMode.hpp:67
static const BlendMode Replace
destination = source.
Definition: BlendMode.hpp:64
static const BlendMode Alpha
destination = source * source.a + destination * (1 - souce.a)
Definition: BlendMode.hpp:68
static const BlendMode Invert
destination = 1 - destination
Definition: BlendMode.hpp:69

Example:

sprite.SetBlendMode(smk::BlendMode::Add);

Custom BlendMode:

This struct wrap all the parameters used by: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBlendEquation.xhtml

They define how the destination "dst" pixel is computed, knowing the source "src" pixel value.

dst.rgb = equation_rgb(src_rgb * src.rgb, dst_rgb / src.rgb)
dst.alpha = equation_alpha(src_alpha * src.alpha, dst_alpha / src.alpha)

Example

smk::BlendMode blend_mode = {
GL_FUNC_ADD, // equation_rgb
GL_FUNC_ADD, // equation_alpha
GL_ONE, // src_rgb factor
GL_ZERO, // dst_rgb factor
GL_ONE, // src_alpha factor
GL_ZERO, // dst_alpha factor
};
sprite.SetBlendMode(blend_mode);

Definition at line 62 of file BlendMode.hpp.

Public Member Functions

bool operator== (const BlendMode &) const
 
bool operator!= (const BlendMode &) const
 

Public Attributes

GLenum equation_rgb = GL_FUNC_ADD
 
GLenum equation_alpha = GL_FUNC_ADD
 
GLenum src_rgb = GL_SRC_ALPHA
 
GLenum dst_rgb = GL_ONE_MINUS_SRC_ALPHA
 
GLenum src_alpha = GL_ONE
 
GLenum dst_alpha = GL_ONE
 

Static Public Attributes

static const BlendMode Replace
 destination = source. More...
 
static const BlendMode Add
 destination += source. More...
 
static const BlendMode Subtract
 destination -= source. More...
 
static const BlendMode Multiply
 destination *= source More...
 
static const BlendMode Alpha
 destination = source * source.a + destination * (1 - souce.a) More...
 
static const BlendMode Invert
 destination = 1 - destination More...
 

Member Function Documentation

◆ operator!=()

bool smk::BlendMode::operator!= ( const BlendMode o) const

Definition at line 60 of file BlendMode.cpp.

60 {
61 return !operator==(o);
62}

◆ operator==()

bool smk::BlendMode::operator== ( const BlendMode o) const

Definition at line 51 of file BlendMode.cpp.

51 {
52 return equation_rgb == o.equation_rgb && //
53 equation_alpha == o.equation_alpha && //
54 src_rgb == o.src_rgb && //
55 dst_rgb == o.dst_rgb && //
56 src_alpha == o.src_alpha && //
57 dst_alpha == o.dst_alpha; //
58}

Member Data Documentation

◆ Add

const BlendMode smk::BlendMode::Add
static
Initial value:
= {
GL_FUNC_ADD, GL_FUNC_ADD, GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ONE,
}

destination += source.

Examples
framebuffer.cpp.

Definition at line 65 of file BlendMode.hpp.

◆ Alpha

const BlendMode smk::BlendMode::Alpha
static
Initial value:
= {
GL_FUNC_ADD, GL_FUNC_ADD,
GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
}

destination = source * source.a + destination * (1 - souce.a)

Definition at line 68 of file BlendMode.hpp.

◆ dst_alpha

GLenum smk::BlendMode::dst_alpha = GL_ONE

Definition at line 79 of file BlendMode.hpp.

◆ dst_rgb

GLenum smk::BlendMode::dst_rgb = GL_ONE_MINUS_SRC_ALPHA

Definition at line 77 of file BlendMode.hpp.

◆ equation_alpha

GLenum smk::BlendMode::equation_alpha = GL_FUNC_ADD

Definition at line 73 of file BlendMode.hpp.

◆ equation_rgb

GLenum smk::BlendMode::equation_rgb = GL_FUNC_ADD

Definition at line 72 of file BlendMode.hpp.

◆ Invert

const BlendMode smk::BlendMode::Invert
static
Initial value:
= {
GL_FUNC_ADD,
GL_FUNC_ADD,
GL_ONE_MINUS_DST_COLOR,
GL_ZERO,
GL_ONE_MINUS_SRC_ALPHA,
GL_ZERO,
}

destination = 1 - destination

Definition at line 69 of file BlendMode.hpp.

◆ Multiply

const BlendMode smk::BlendMode::Multiply
static
Initial value:
= {
GL_FUNC_ADD, GL_FUNC_ADD, GL_DST_COLOR, GL_ZERO, GL_DST_ALPHA, GL_ZERO,
}

destination *= source

Definition at line 67 of file BlendMode.hpp.

◆ Replace

const BlendMode smk::BlendMode::Replace
static
Initial value:
= {
GL_FUNC_ADD, GL_FUNC_ADD, GL_ONE, GL_ZERO, GL_ONE, GL_ZERO,
}

destination = source.

Definition at line 64 of file BlendMode.hpp.

◆ src_alpha

GLenum smk::BlendMode::src_alpha = GL_ONE

Definition at line 78 of file BlendMode.hpp.

◆ src_rgb

GLenum smk::BlendMode::src_rgb = GL_SRC_ALPHA

Definition at line 76 of file BlendMode.hpp.

◆ Subtract

const BlendMode smk::BlendMode::Subtract
static
Initial value:
= {
GL_FUNC_REVERSE_SUBTRACT,
GL_FUNC_REVERSE_SUBTRACT,
GL_ONE,
GL_ONE,
GL_ONE,
GL_ONE,
}

destination -= source.

Definition at line 66 of file BlendMode.hpp.


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