Raven wrote: "This actually does an excellent job of explaining how the GL Blend can be achieved in Fragment Shaders., just be aware that the way that GL Blend worked... is that you're Queuing a Fixed-Function Post Process, for once the Render Pass has occurred."
Sorry but that is absolutely inaccurate. A lot of what you have stated above is just plain wrong.
Firstly: The example tutorial you have linked to actually uses the built in GL blend modes! It doesnt replace them in any shader ....it just uses them to do the blending as per what they are set to in the open gl functions.
Secondly: AppGameKit does have, and uses GL blend modes...these are used on everything that is drawn in AGK. Ive explained that below.
Thirdly: The equivalent of gl_blendmodes cant really be acheived in shaders as you dont have the destination colour or alpha in a shader to blend with.
All you do in a fragment shader is set the source colour and alpha (ie the fragment colour) - you dont know anything about what it is about to be applied to. You would have to render each sprite to a render target then pass the render target to the next sprite to be drawn just to get at the destination colour and destination alpha data which would be ludicrously slow and laborious. Especially when gl blendmodes are still used and available on any modern hardware.
Even when using Fragment shaders and vertex shaders...the blending using GL_BlendModes occurs after them both. Blending is a per sample operation (see image below) that occurs last in the open GL process. This is still the case in the latter versions of open GL and even in vulcan too.
See:
https://www.khronos.org/opengl/wiki/Rendering_Pipeline_Overview
Even Vulkan has settable blend modes that occur outside of the shaders:
https://vulkan.lunarg.com/doc/view/1.0.26.0/linux/vkspec.chunked/ch26s01.html
You can do a lot with shaders but overwriting the built in GL blend modes isnt really one of them without using largenumbers of render targets for everything you draw.
Grizzlius_Maximus wrote: " I want to access other GL BlendModes like GL_DST_ALPHA, GL_ONE, GL_ZERO, etc."
All app game kit objects allow you to set the blend modes per object...
See:
https://www.appgamekit.com/documentation/Reference/3D/SetObjectBlendModes.htm
So you can set the source and destination blend modes as you want them to be. (any of those you listed)
This is for 3d objects only though.... So to use these, you could render your sprites as planes with an orthographic camera setup and do exactly what you want to with blend modes. Which is a little awkward as it involves using 3d items even just for sprite drawing.
In the case of sprites there are only 3 transparency modes (0=off, 1=alpha transparency, 2=additive blending)
internally these use the following GL blend modes
0 - Off: Source GL_ONE, Destination GL_ZERO (destination is replaced by the source)
1 - Alpha: Source (sourceAlpha) , Destination (1-sourcealpha)
2 - Additive: Source GL_ONE, Destination GL_ONE (both are added together)
These are the only built in modes for sprites unfortunately. This is the case as sprites can be batched in agk and drawn in less operations, the batching currently doesn't take into account individual blend modes. In theory a per sprite belndmode setting could be added to agk. Its already the case for 3d objects.
As you are using teir 2 there is a way to do this with sprites. Set the sprite transparency to mode 3 (Mode 3 has no effect) then use these function
agk:: PlatformSetBlendEnabled( int mode )
Set mode 1 to turn it on
agk:: PlatformSetBlendFunc( int mode1, int mode2 )
Mode1 = source blendmode
Mode 2 = destination blendmode
There you go...blend modes fully set.
Then manually draw your sprites. Manually drawing it is important though as AppGameKit can batch together sprite drawing. Meaning the changes to blend modes for individual sprites wouldnt get made halfway through a batch draw. So the results wouldnt be right if you let agk draw them as part of a Render() call.
As you are capable in C++ you could modify the AGK2 source and add a source and destination blend mode to the sprite class. Then modify agk:
latformSetBlendMode( int mode ) to set them every time a sprite is drawn. It would work for small numbers of sprites with individual textures or if you manually draw them. The batching functions would need to be updated so that individual sprites could have their own blend functions and still be used in a normal Render() or sync() call.
Using the 3d drawing version may be easier if you are still getting to grips with AppGameKit teir 2 and involves no modification to the source. Approximating the blend modes in a shader might also be possible but it wont be really be correct unless you pass the contents of the back buffer to the sprite being rendered to get at the destination colour and alpha inside the shader. Its not necessary to do this just to set GL blend modes.
Edited: for horrific spelling mistakes