bkaradzic / bgfx

Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
https://bkaradzic.github.io/bgfx/overview.html
BSD 2-Clause "Simplified" License
14.86k stars 1.93k forks source link

Bgfx window creation problem with Nvidia 310.32 on Linux64. #23

Closed dariomanesku closed 11 years ago

dariomanesku commented 11 years ago

Bgfx is not working with Nvidia 310.32 on Linux64.

There is a problem in window creation. The error is:

    X Error of failed request:  BadMatch (invalid parameter attributes)
      Major opcode of failed request:  153 (GLX)
      Minor opcode of failed request:  5 (X_GLXMakeCurrent)
      Serial number of failed request:  34
      Current serial number in output stream:  34

Here: In entry_linux.cpp you are creating the Window with XCreateWindow(..., DefaultVisual(m_display, screen), ...). However, you are creating the glxcontext with a fbconfig that does not match that visual and the error is latter at glxMakeCurrent(s_display, s_window, m_context) and it says: BadMatch (which is because window and context do not match). Here is what you should check:

If you iterate through all configs that you got with specified attrsGlx[]:

    visualInfo = glxGetVisualFromFBConfig(s_display, configs[i]);
    print( visualInfo->visual );

None of them matches the:

    visual = DefaultVisual(m_display, screen);
    print( visual );

Which is used for window creation.

The GLX_ALPHA_SIZE, 8 in attrsGlx[] is the problem. (if you comment that out, there is a match and it passes, yet that's not the solution, you can only run helloworld example with that)

The solution: You should call XCreateWindow(...) with:

    XVisualInfo *vi = glXGetVisualFromFBConfig(s_display, bestConfig);
    XCreateWindow(... vi->visual, ...).

And not with:

    XCreateWindow(... DefaultVisual(...), ...).

(but this implies that you should change the place of Window creation, take a look at the code. Or, I guess you could destroy the window in glxcontext and recreate it there with the visual from the best fbconfig)

Also you might need to specifiy the Colormap in XSetWindowAttributes which you can get like:

    winAttrs.colormap = XCreateColormap(s_display, 
           RootWindow(s_display, vi->screen, vi->visual, AllocNone);
    XCreateWindow(... CWBorderPixel | CWColormap | CWEventMask, &winAttrs);
bkaradzic commented 11 years ago

I reproduced it on 310.19. Actually back buffer alpha is not necessary. I don't see any issues when it's commented out, all examples work correctly when alpha is not requested. Do you see something else?

dariomanesku commented 11 years ago

then there must be some other reason why some other examples didn't work. I'll check it out.

dariomanesku commented 11 years ago

oh, it's shader path problem. if I copy 'shaders' folder from /examples/runtime to the /bin dir, it's all fine.

bkaradzic commented 11 years ago

Actually you should run examples from runtime dir (some examples need textures and meshes). Like:

/bgfx/examples/runtime $ ../../.build/linux64_gcc/bin/example-
bkaradzic commented 11 years ago

Fixed: https://github.com/bkaradzic/bgfx/commit/5afe69f2404345d6353046eb31736ef4be0e485d