bmx-ng / sdl.mod

SDL backend for BlitzMax
7 stars 6 forks source link

SDLRender.mod - expose SDL_ComposeCustomBlendMode #43

Closed GWRon closed 1 year ago

GWRon commented 2 years ago

sdl.mod/sdlrender.mod/common.bmx:

    Function SDL_GetRendererInfo(handle:Byte Ptr, info:SDLRendererInfo Var)
    Function SDL_GetRenderDriverInfo:Int(index:Int, info:SDLRendererInfo Var)
'add:
    Function SDL_ComposeCustomBlendMode:Int(srcColorFactor:Int, dstColorFactor:Int, colorOperation:Int, srcAlphaFactor:Int, dstAlphaFactor:Int, alphaOperation:int)

sdl.mod/sdlrender.mod/sdlrender.bmx:

Type TSDLRenderer
...
'add:   
    Method ComposeCustomBlendMode:Int(srcColorFactor:Int, dstColorFactor:Int, colorOperation:Int, srcAlphaFactor:Int, dstAlphaFactor:Int, alphaOperation:int)
        Return SDL_ComposeCustomBlendMode(srcColorFactor, dstColorFactor, colorOperation, srcAlphaFactor, dstAlphaFactor, alphaOperation)
    End Method

This should allow to set custom blend modes to a renderer:

        local mode:Int = renderer.ComposeCustomBlendMode(SDL_BlendFactor.SDL_BLENDFACTOR_SRC_COLOR.Ordinal(), ..
                                                         SDL_BlendFactor.SDL_BLENDFACTOR_DST_COLOR.Ordinal(), ..
                                                         SDL_BlendOperation.SDL_BLENDOPERATION_ADD.Ordinal(), ..
                                                         SDL_BlendFactor.SDL_BLENDFACTOR_SRC_ALPHA.Ordinal(), ..
                                                         SDL_BlendFactor.SDL_BLENDFACTOR_DST_ALPHA.Ordinal(), ..
                                                         SDL_BlendOperation.SDL_BLENDOPERATION_ADD.Ordinal())
        renderer.SetDrawBlendMode(mode)

Dunno if that is done correctly - so adjust to your needs. Eg it is not really bound to a "renderer", so could become something like `SDLComposeCustomBlendMode()" or so ... or ... might even be directly useable without being "wrapped" - so adding the thing to "common.bmx" might be already enough.