Skip to content

Instantly share code, notes, and snippets.

@rygorous
Created February 20, 2014 22:40
Embed
What would you like to do?
State setting.
static int set_render_state(GDrawRenderState *r, /* ... */)
{
static struct gdraw_gl_blendspec {
GLboolean enable;
GLenum src;
GLenum dst;
} blends[ASSERT_COUNT(GDRAW_BLEND__count, 6)] = {
{ GL_FALSE, GL_ONE, GL_ZERO }, // GDRAW_BLEND_none
{ GL_TRUE, GL_ONE, GL_ONE_MINUS_SRC_ALPHA }, // GDRAW_BLEND_alpha
{ GL_TRUE, GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA }, // GDRAW_BLEND_multiply
{ GL_TRUE, GL_ONE, GL_ONE }, // GDRAW_BLEND_add
{ GL_FALSE, GL_ONE, GL_ZERO }, // GDRAW_BLEND_filter
{ GL_FALSE, GL_ONE, GL_ZERO }, // GDRAW_BLEND_special
};
int blend_mode = r->blend_mode;
assert(blend_mode >= 0 && blend_mode < sizeof(blends)/sizeof(*blends));
if (blends[blend_mode].enable) {
glEnable(GL_BLEND);
glBlendFunc(blends[blend_mode].src, blends[blend_mode].dst);
} else
glDisable(GL_BLEND);
// and so forth.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment