We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3830 - Adding custom blend modes to opengl renderer
Summary: Adding custom blend modes to opengl renderer
Status: NEW
Alias: None
Product: SDL
Classification: Unclassified
Component: render (show other bugs)
Version: HG 2.0
Hardware: All All
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-09-14 22:35 UTC by Simon Hug
Modified: 2017-09-21 09:39 UTC (History)
0 users

See Also:


Attachments
Patch (draft) that adds the remaining custom blend modes to the opengl renderer. (55.39 KB, patch)
2017-09-14 22:35 UTC, Simon Hug
Details | Diff
Patch (draft version 2) that adds the remaining custom blend modes to the opengl renderer. (64.04 KB, patch)
2017-09-19 05:26 UTC, Simon Hug
Details | Diff
blendmodestest1.c is a test program for custom blend modes. (54.93 KB, text/x-csrc)
2017-09-19 05:47 UTC, Simon Hug
Details
Patch (draft version 3) that adds the remaining custom blend modes to the opengl renderer. (68.76 KB, patch)
2017-09-21 09:39 UTC, Simon Hug
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Hug 2017-09-14 22:35:50 UTC
Created attachment 2945 [details]
Patch (draft) that adds the remaining custom blend modes to the opengl renderer.

Attached is a patch that adds support for the remaining custom blend modes to the opengl renderer. It also makes the loading of the OpenGL functions a bit more robust. In the current tip, it's possible that function loading fails (with an OpenGL 1.1 software renderer for example) and GL_ActivateRenderer calls GL_UpdateViewport which expects data->glViewport not to be NULL.

Other things the patch does:

* Adds a SDL_RENDER_OPENGL_NPOT_TEXTURES hint. This hint can be set to 0 to make SDL always create power-of-two textures. Users can use that if they have drivers that just work better that way.

* Sorts the function list in SDL_glfuncs.h by OpenGL version support and then alphabetically. GL_CreateRenderer expects the used functions in this list to be present after the context is created. Functions requiring OpenGL 1.2 and higher probably need to be handled in a more special way in GL_CreateRenderer.

* Adds several checks for the OpenGL version when additional functions and extensions are loaded in GL_CreateRenderer.

* Adds a check if context was made current on render destruction. If it failed, the memory will be freed without deleting the OpenGL resources. I'm guessing proper drivers will tear them down with the context so there should be no leaks.

I have done some minor testing but would like to do more over the next three days. This patch should be considered a draft. Comments are welcome of course.


During testing, I noticed that the Windows software renderer GDI Generic (on at least Windows XP) has some issues when the default framebuffer alpha size is 0. 
Is it intentional that the renderer doesn't ask for an accelerated visual if the SDL_RENDERER_ACCELERATED flag is set?
Comment 1 Simon Hug 2017-09-19 05:26:10 UTC
Created attachment 2950 [details]
Patch (draft version 2) that adds the remaining custom blend modes to the opengl renderer.

I got some testing in on Linux on Windows (8.1 and XP) but plan to do some more.

Changes I made to the patch:

* Corrected the reporting of GL_MIN and GL_MAX operation support. They are limited to the GL_ONE factors.

* Had to rename some functions in the opengles2 renderer. They collided with the names from the opengl renderer and link.exe chose the wrong one.
Comment 2 Simon Hug 2017-09-19 05:47:29 UTC
Created attachment 2951 [details]
blendmodestest1.c is a test program for custom blend modes.

Test program I mashed together.

It uses the RGBA file from bug 3359. Just rename it to blendmodestest.rgba: https://bugzilla.libsdl.org/attachment.cgi?id=2488
Comment 3 Simon Hug 2017-09-21 09:39:06 UTC
Created attachment 2955 [details]
Patch (draft version 3) that adds the remaining custom blend modes to the opengl renderer.

Windows 7 and 10 also got some testing. I'm currently just comparing OpenGL with Direct3D 11 and there seems to be an issue when selecting some alpha factors. For example (SRC_COLOR, ONE, ADD, SRC_COLOR, ONE, ADD) looks different. Is it possible that D3D11 doesn't support all combinations?

Changes I made to the patch:

* Added an alpha size hint that allows controlling the alpha channel size on the default framebuffer of all OpenGL renderers. SDL didn't set any size and I got a framebuffer without alpha. The new blending modes can now interact with this and the difference to D3D11 (which always seems to allocate B8G8R8A8) is visible. The hint only activates if something is set because I'm not sure if existing applications rely on the default behavior.