Various issues with SDL 2's render API

Hello people,

I’m working on porting a game from SDL 1.2 to SDL 2, and ran into a couple of problems that I’m apparently resolve on my own:

I can’t get the texture + software rendering + alpha blending combo work. The symptoms are that described in bug 2198 (https://bugzilla.libsdl.org/show_bug.cgi?id=2198), except that I can’t get good results with SDL_RenderCopy either. I’d assume this is an SDL2 bug, but the docs claim that some blend modes won’t work on all renderers… so I hope this is a bug and not intended behavior?

I’m admittedly inexperienced with low-level graphics concepts and algorithms, so it might be only my ignorance that I can’t make sense of the formula used for color modulating. We would mainly use this feature to draw a layer of a certain color over an image, but that’s not really possible with the src * (mod / 255) formula, partly because its effects depend on the value of the color channel and partly because, mod being an Uint8, it can’t be used for brightening. So, I ask, is it possible to achieve an effect like dst = src + mod (even by possibly patching SDL2 on my own)? I thought about rendering a semi-transparent colored rectangle onto the texture, but the remarks section of SDL_SetRenderTarget implies that this is probably not a widely supported feature, and our software is supposed to run on a very broad variety of platforms.

My last issue is with scaling textures. The best platform-independent algorithm, linear filtering, is still largely inferior to the bilinear interpolation algorithm that we use right now. My question is the same as with color modulation: is this something that can be fixed in SDL2 with a patch, or it’s an inherent feature of OGL/D3D?

Thanks in advance![/url]

lipk wrote:

My last issue is with scaling textures. The best platform-independent algorithm, linear filtering, is still largely inferior to the bilinear interpolation algorithm that we use right now. My question is the same as with color modulation: is this something that can be fixed in SDL2 with a patch, or it’s an inherent feature of OGL/D3D?

The texture interpolation is performed on hw. So yes it’s OGL/D3D feature. If it’s not good enough for you, probably you would have to switch to anisotropic which is not available in OpenGL renderer. I think it’s possible to implement anisotropic filtering on OpenGL renderer. What really needs here is to check if the anisotropic filtering extension is available or not, and if it’s not just return FALSE at SDL_SetHint(). Shouldn’t be really hard I guess.

I’ve looked through the source code of the directx renderer. Surprisingly (to me), quality ‘best’ (‘2’) is not implemented. Instead it is treated the same way as quality ‘good’ (‘1’). It’s even commented in the code that currently quality ‘2’ is the same as ‘1’.

That means only nearest neighbourhood and linear interpolation are implemented in both directx and opengl renderers (+ a few more).

Anyway I still doubt the quality of anisotropic filtering, given that sdl renderer renders everything in orthogonal projection and there is no rotation around x or y axis (it’s 2D, in other words). Probably bi-linear would produce better quality output.

Bilinear and bicubic should be used for “best” quality where possible
(ie, anywhere you can use a shader). People swear by bicubic for
resizing, but the fact is that it’s crap as a min filter. As a mag
filter, it’s great. :slight_smile:

JosephOn Fri, Jun 20, 2014 at 05:43:20PM +0000, mr_tawan wrote:

I’ve looked through the source code of the directx renderer. Surprisingly (to me), quality ‘best’ (‘2’) is not implemented. Instead it is treated the same way as quality ‘good’ (‘1’). It’s even commented in the code that currently quality ‘2’ is the same as ‘1’.

That means only nearest neighbourhood and linear interpolation are implemented in both directx and opengl renderers (+ a few more).

Anyway I still doubt the quality of anisotropic filtering, given that sdl renderer renders everything in orthogonal projection and there is no rotation around x or y axis (it’s 2D, in other words). Probably bi-linear would produce better quality output.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hmm… I’ll do some research on that then. Thanks for the answer.

Regarding blend modes… We’re still discussing this in another thread.
If you can’t wait, then you can either patch SDL yourself or use SDL_gpu
which does have fine control of the blend mode.

Jonny DOn Fri, Jun 20, 2014 at 7:24 PM, T. Joseph Carter < tjcarter at spiritsubstance.com> wrote:

Bilinear and bicubic should be used for “best” quality where possible (ie,
anywhere you can use a shader). People swear by bicubic for resizing, but
the fact is that it’s crap as a min filter. As a mag filter, it’s great.
:slight_smile:

Joseph

On Fri, Jun 20, 2014 at 05:43:20PM +0000, mr_tawan wrote:

I’ve looked through the source code of the directx renderer. Surprisingly
(to me), quality ‘best’ (‘2’) is not implemented. Instead it is treated the
same way as quality ‘good’ (‘1’). It’s even commented in the code that
currently quality ‘2’ is the same as ‘1’.

That means only nearest neighbourhood and linear interpolation are
implemented in both directx and opengl renderers (+ a few more).

Anyway I still doubt the quality of anisotropic filtering, given that sdl
renderer renders everything in orthogonal projection and there is no
rotation around x or y axis (it’s 2D, in other words). Probably bi-linear
would produce better quality output.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

There’s a reason I don’t join committees. sigh

I give up, as people aren’t actually reading my emails on the topic
anyway. SDL’s renderer had two goals and it currently meets neither
of them. I’m completely disincentivized to actually write the patch
at this point.

Nothing I’ve proposed for SDL’s renderer is actually complex or
beyond the scope of the promises made for it in 1.3’s development.
It just requires the time of someone who understands it to actually
do the implementation. It’s software and old school shaderless
OpenGL that would actually require some effort, and I could do those
pretty easily.

I just no longer have the desire to push against the “wisdom” of this
mailing list which remains convinced that drawing a triangle without
an accelerated 3D engine is some kind of black voodoo.

JosephOn Mon, Jun 23, 2014 at 11:11:56AM -0400, Jonathan Dearborn wrote:

Regarding blend modes… We’re still discussing this in another thread.
If you can’t wait, then you can either patch SDL yourself or use SDL_gpu
which does have fine control of the blend mode.

Jonny D

On Fri, Jun 20, 2014 at 7:24 PM, T. Joseph Carter < @T_Joseph_Carter> wrote:

Bilinear and bicubic should be used for “best” quality where possible (ie,
anywhere you can use a shader). People swear by bicubic for resizing, but
the fact is that it’s crap as a min filter. As a mag filter, it’s great.
:slight_smile:

Joseph

On Fri, Jun 20, 2014 at 05:43:20PM +0000, mr_tawan wrote:

I’ve looked through the source code of the directx renderer. Surprisingly
(to me), quality ‘best’ (‘2’) is not implemented. Instead it is treated the
same way as quality ‘good’ (‘1’). It’s even commented in the code that
currently quality ‘2’ is the same as ‘1’.

That means only nearest neighbourhood and linear interpolation are
implemented in both directx and opengl renderers (+ a few more).

Anyway I still doubt the quality of anisotropic filtering, given that sdl
renderer renders everything in orthogonal projection and there is no
rotation around x or y axis (it’s 2D, in other words). Probably bi-linear
would produce better quality output.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

2D API++

@Jonny D: Thanks, SDL_gpu looks promising. I’ll definitely take a look!

@Joseph Carter: Was that reply intended for this thread? If yes, I’m sorry for not reading your emails, but, you see, I only registered less than a week ago.