Supersampling in SDL2

Started by
3 comments, last by tdcoish 9 years, 5 months ago

Hi, this is my first time post. Anyway, I have a very simple game that I'm working on, and, being a simple 2D game, there's lots of processor power left over to throw at different things. I decided I wanted to supersample the game, also known as downsampling. I want to render the game at double the final resolution, and then blend/scale to the final resolution.

The problem is that SDL2 just doesn't seem to give any easy way of creating a renderer at any resolution different from the window.

I've tried to use SDL_SetRenderLogicalSize, and a few other things, but right now the only thing that I think would work is creating a texture at the supersampled resolution that I write everything to, and then manually blitting everything, and then creating a resolution at the final resolution that I blend everything down to again, before sending that to the renderer. The problem with that, is that it really reduces a lot of the benefit of SDL2 in the first place.

It's very possible that I'm just coming at this from the wrong direction.

Advertisement
Well, at least in DirectX you usually do supersampling in hardware, i.e. using a multisampled render target (framebuffer) instead of manually rendering to twice the resolution and then downscaling. Check if SDL2 doesn't have an option to set the backbuffer to be multisampled, perhaps.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Looks like I'll need to use OpenGL instead of the SDL2 2D API. The relevant line of code is something like:

SDL_GL_SetAttribute(SDL_GL_MULTISAMPLE_BUFFERS, 1);

That would require me rewriting the rendering of the game though. I'll definitely keep looking, and may simply convert to doing that. Thanks for the reply.

Hi,

This may or may not be relevant to your problem, but I write this in the hope that it may help somehow...

I looked into supersampling some time ago for improving the rendering of the game I'm writing, where all of its original assets are low resolution (PSX era), and so my first stab at the solution came in the form of rescaling the sprites in real-time (during load / init) using the scale2x algorithm (easily ported to utilize SDL2), and later settled with simply loading pre-scaled scale2x assets at load-time (for sake of simplicity). The hqx algorithm is probably worth looking into, too FYI.

I bring up a window with a size two times that of the original resolution (768x448), and then use SDL_SetLogicalSize with the original game asset resolution (384x224). I take into account for the difference in positioning and size coordinates of game objects by computing the proper origins, offsets and what not at compile / build time -- although it is best that these be done at run-time, I simply haven't gotten around to situating things to do at run-time...

As I'm still learning the ins and outs of game programming, I have no idea how efficient or wise this kind of implementation holds in the long run, but I can attest to it holding up at least through several internal rewrites of rendering code, and is easily integrated with other rendering systems in mind (i.e.: libRocket). The downside (of which I've seen) boils down to that of maintenance cost (of keeping up with two different resolutions, assuming you do not wish to throw away the original).

(In case you have not), you should familiarize yourself with the SDL2 hint SDL_HINT_RENDER_SCALE_QUALITY especially when in use with SDL_SetLogicalSize, as this makes a significant difference in the resulting image. "Linear" produces anti-aliased results, which is great for rendering text, but at the potential cost of degrading low resolution artwork, which generally yields a better image with "nearest".

Thanks for the reply. I tried something similar, although maybe only half-assed it, and it didn't really work for me. As of right now, supersampling is a low priority thing with the game, but when the project is nearing completion I'll return to this post and try to figure it out again.

This topic is closed to new replies.

Advertisement