makehumancommunity / makehuman

This is the main repository for the MakeHuman application as such.
http://www.makehumancommunity.org
Other
1.22k stars 250 forks source link

OpenGL Fallback functions #68

Closed mdamonconnolly closed 4 years ago

mdamonconnolly commented 4 years ago

This patch brings in fallback functions for the problematic openGL areas to address issue #62

For the people on modern cards this should be un-noticeable, but there may be a performance degrade for those who use the fallbacks. To what extent, I have no idea.

Recommend testing first to make sure this works, It generates no errors for me but I don't have the hardware to test it properly.

I'll add more comments to the PR as it gets tested if theres any interest.

joepal1976 commented 4 years ago

This looks very interesting. I hope to be able to take a look at it tomorrow.

joepal1976 commented 4 years ago

I must be missing something here. Can you walk me through how safeRun works?

We have

def safeRun(func: Callable, *args, fallbacks: List[Callable] = None, **kwargs):

and then we call it with, for example

safeRun(glGenFramebuffers(1), glGenFramebuffersEXT(1))

So I understand that the idea is that glGenFramebuffers is tried first, and if that doesn't work we try glGenFramebuffersEXT. I just don't understand how the code gets there.

Reading the code I would have assumed that with the line above, safeRun would have been called with the return values of glGenFramebuffers(1) and glGenFramebuffersEXT(1). Basically, the code would be equivalent to:

a = glGenFramebuffers(1)        # "a" contains return value of glGenFramebuffers(1)
b = glGenFramebuffersEXT(1) # "b" contains return value of glGenFramebuffersEXT(1)
safeRun(a, b)

So trying this, I create a basic character with a skin texture and then I go and click the render button.

Without this change, I get a rendered image.

With the change I get a stack trace:

Traceback (most recent call last):
  File "./lib/glmodule.py", line 74, in safeRun
    func(*args, **kwargs)
TypeError: 'numpy.uint32' object is not callable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./core/events3d.py", line 211, in callEvent
    method(event)
  File "/home/joepal/source/makehuman/makehuman-github-py3-with-assets-gl/makehuman/plugins/4_rendering_opengl/__init__.py", line 125, in onClicked
    mh2opengl.Render(settings)
  File "/home/joepal/source/makehuman/makehuman-github-py3-with-assets-gl/makehuman/plugins/4_rendering_opengl/mh2opengl.py", line 104, in Render
    img = mh.renderToBuffer(width, height)
  File "./lib/glmodule.py", line 835, in renderToBuffer
    framebuffer = safeRun(glGenFramebuffers(1), glGenFramebuffersEXT(1))
  File "./lib/glmodule.py", line 76, in safeRun
    log.error(f"{func.__name__} raised {error}")
AttributeError: 'numpy.uint32' object has no attribute '__name__'

I.e, "func" is of the type numpy.uint32, which seems like a sensible return value from glGenFramebuffers(1)

What am I missing?

mdamonconnolly commented 4 years ago

Ahh yes, pure stupidity on my part :) I'll get this fixed ASAP. I'm still mapping out the program so between implementing this and trying to learn makehuman so I can contribute more time to it, My brain sometimes turns into spaghetti. i Swear it was working for me! Anyway I can see the issue so I'll get right on that when I get home tonight! and update you when it's working. I do have a wider concern regarding fallbacks but I don't think this discussion thread is the place to bring that up so I'll save that for now!

Aranuvir commented 4 years ago

Maybe we could push these changes to another branch than master?

mdamonconnolly commented 4 years ago

@joepal1976 @Aranuvir I think it's fixed now. I've tested it, I can render with no warnings or errors. The only foreseeable performance hit is, for someone using the older openGL, when saferun is called, it must go who-knows-how-far into the standard openGL function before it throws an error and reverts to the fallback. Let me know how testing goes for you!

joepal1976 commented 4 years ago

It now works for me without warnings too.

I think it will be difficult to thoroughly test this without publishing a build so everyone who had gl issues can try it.

So I'm going to merge this to master in the hope that an alpha 4 can be published within the near future.