glBlendFuncSeparate in RenderTexture

Found out that in cocos2d-x 3 RenderTexture has premultiplied alpha, so I need to use the following code for my RenderTexture to look the same as with cocos2d-x 2.
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

Everything works OK if I call the function in draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated). But I guess I have to call GL::blendResetToCache after it. If I do, the blend func gets reset and everything is wrong again (because actual draw is done in a separate function). The question is where should I call the glBlendFuncSeparate, shouldn’t it be added to Node just as setBlendFunc, so that it is set right before actual rendering?

Hi Elvman,
Did you find the answer for your question. I also want RenderTexture to behave just the way it used to in v2.x.

No, I haven’t found the answer. I can’t find a way to change blending options just before the sprite is rendered.

Hey guys, I too need glBlendFuncSeparate support for the RenderTexture sprite. (I’m testing on WP8)
At least I think so… I’m drawing sprites onto a Node then drawing that Node onto a RenderTexture.
Cocos is then drawing the RenderTexture, but with the alpha premultiplied on the sprites.
I’ve had a similar issue on iOS with my own engine, I solved it with
glBlendFuncSeparateOES(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

You guys had any luck in solving this?
(first post)

Quick update, OK found a kind of solution…
was doing some digging and in “cocos2d-x\cocos\2d\ccGLStateCache.cpp” and inside SetBlending(GLenum sfactor, GLenum dfactor) on line 114, I replaced:
glBlendFunc(sfactor, dfactor);
with
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
This gave me the result I was looking for, I know its not the correct way to fix it but thought it was a useful enough solution for you guys right now.
:slight_smile: