custom consumer patch: How to access blending options ?

franz's picture

Hi, i didn't find any valuable example on how to enable the blending port on a custom consumer plugin. Adding something like:

glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE);

doesn't seem to change anything. (even if glColor has some alpha value)

Any tips would be greatly appreciated ... even a link to some plugin's source> thxx (official API)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

.lov.'s picture
Re: custom consumer patch: How to access blending options ?

I don't know the answer, but i think vade's plugins sources are good starting points ;-)

cwright's picture
Re: custom consumer patch: How to access blending options ?

here's gltools:

static void enhancedBlendingSetOnOpenGLContext(id self, SEL sel, QCOpenGLContext *context)
        unsigned int mode = ((unsigned int*)((unsigned char*)self+_index))[0];//[self indexValue];
                CGLContextObj cgl_ctx = [[context openGLContext] CGLContextObj];
                GLint sfunc, dfunc;
                glGetIntegerv(GL_BLEND_SRC, (GLint*)((unsigned char*)self+_sourceFunction));
                glGetIntegerv(GL_BLEND_DST, (GLint*)((unsigned char*)self+_destFunction));
                if(! (*((unsigned char*)self+_enabled) = glIsEnabled(GL_BLEND)) )
                        case 1: // over
                                sfunc = GL_ONE;
                                dfunc = GL_ONE_MINUS_SRC_ALPHA;
                        case 2: // add
                                sfunc = dfunc = GL_ONE;
                        case 3: // Alpha!
                                sfunc = GL_SRC_ALPHA;
                                dfunc = GL_ONE_MINUS_SRC_ALPHA;
                // save an unnecessary state transition if things haven't changed
                if(sfunc != *(GLint*)((unsigned char*)self+_sourceFunction) ||
                   dfunc != *(GLint*)((unsigned char*)self+_destFunction))
                        glBlendFunc(sfunc, dfunc);

you can't use the port directly in the official api (of course), but if you make it an index port with 0-3, here's what the built-in stuff does:

0: (doesn't call glBlendFunc) (replace) 1: GL_ONE, GL_ONE_MINUS_SRC_ALPHA (over) 2: GL_ONE, GL_ONE (add) 3: GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA (alpha -- gltools adds this)

Be sure to store the old values (glGetInteger) and restore them when you're done, or things get crazy (since replace doesn't set it explicitly, it'll use any stale blend mode that isn't reset)