Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL ES - Get current blendFunc

Tags:

opengl-es

I want to do something like this:

currentBlendFunc = glGetCurrentBlendFunc();
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

// [...] do stuff

glBlendFunc(currentBlendFunc.src, currentBlendFunc.dest);

Is there a way to get the current blend func?

like image 944
quano Avatar asked Dec 07 '09 16:12

quano


3 Answers

Years later, I ran in the same issue, the docs still are unclear or bugged.

@don's solution in incompleted/buggy though, you also need to restore the _RGB values :

GLint last_blend_src_rgb; glGetIntegerv(GL_BLEND_SRC_RGB, &last_blend_src_rgb);
GLint last_blend_dst_rgb; glGetIntegerv(GL_BLEND_DST_RGB, &last_blend_dst_rgb);
GLint last_blend_src_alpha; glGetIntegerv(GL_BLEND_SRC_ALPHA, &last_blend_src_alpha);
GLint last_blend_dst_alpha; glGetIntegerv(GL_BLEND_DST_ALPHA, &last_blend_dst_alpha);

...

glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
like image 66
rotoglup Avatar answered Sep 19 '22 15:09

rotoglup


According to the documentation the function that you are looking for is glGet with the arguements GL_BLEND_SRC, GL_BLEND_DST. This is one of the annoyances of OpenGL is that the get and sets don't match up (amongst other things).

like image 38
monksy Avatar answered Sep 18 '22 15:09

monksy


I just ran into this exact same situation. Here is my approach to save off the previous blend state and restore when done.

// save off current state of blend enabled
GLboolean blendEnabled;
glGetBooleanv(GL_BLEND, &blendEnabled);

// save off current state of src / dst blend functions
GLint blendSrc;
GLint blendDst;
glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrc);
glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDst);

//
// change blend state... do other stuff 
//

// restore saved state of blend enabled and blend functions
if (blendEnabled) {
    glEnable(GL_BLEND);
}
else {
    glDisable(GL_BLEND);
}

glBlendFunc(blendSrc, blendDst);
like image 37
don Avatar answered Sep 22 '22 15:09

don