Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: OpenGL bug? Nvidia driver bug? SFML bug? My fault?  (Read 48406 times)

0 Members and 1 Guest are viewing this topic.

K-Bal

  • Full Member
  • ***
  • Posts: 104
    • View Profile
    • pencilcase.bandcamp.com
    • Email
OpenGL bug? Nvidia driver bug? SFML bug? My fault?
« Reply #90 on: October 12, 2009, 10:14:38 am »
Quote
Creating the first context...
Succeeded to create context!
Creating a shared context on the same display...
Succeeded to create context!
Creating a shared context on a new display...
Succeeded to create context!


 :?

EDIT: I'm such an idiot, I compiled it on my PC :D I redo it on my Laptop now.
EDIT2: Same output on my Laptop, no GLX error.
Listen to my band: pencilcase.bandcamp.com

Lokk

  • Full Member
  • ***
  • Posts: 228
    • View Profile
    • http://betadineproject.wordpress.com/
OpenGL bug? Nvidia driver bug? SFML bug? My fault?
« Reply #91 on: October 12, 2009, 10:25:06 am »
Same issue for me...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
OpenGL bug? Nvidia driver bug? SFML bug? My fault?
« Reply #92 on: October 12, 2009, 10:43:56 am »
Thanks for this fast feedback :)

* The good news: it seems that I can share OpenGL contexts across different X connections; if not, I would have had to revert  to using a single X display for every context and window, which would have brought back the old multithreading issues.

* The bad news: I was 90% sure it was that... now I'm really confused.
Laurent Gomila - SFML developer

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
OpenGL bug? Nvidia driver bug? SFML bug? My fault?
« Reply #93 on: October 12, 2009, 11:59:54 am »
Sharing the context is a good point. I was able to successfully open a window with some changes to line 48 of src/SFML/Window/Linux/ContextGLX.cpp:

Instead of calling XOpenDisplay() for every new context, I did call it once and passed the pointer to all following contexts (for debugging I used a static variable and some poor reference counting ;)).

Good news: The window opens (thus eliminating the GLX_BadContext error) and Clear() does its job very well.
Bad news: Drawable::Draw() doesn't do anything.

I decided to stop here because you're a lot more experienced in that sector. But I hope this gives a hint for the right direction.

Edit: Funny, I just read your modified code where you seem to be doing exactly what I tried to do. Too late. :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
OpenGL bug? Nvidia driver bug? SFML bug? My fault?
« Reply #94 on: October 12, 2009, 12:35:32 pm »
Quote
I was able to successfully open a window with some changes to line 48 of src/SFML/Window/Linux/ContextGLX.cpp:

Instead of calling XOpenDisplay() for every new context, I did call it once and passed the pointer to all following contexts

I'm lost. The test above clearly shows that the multiple X displays are not involved in the error, but your modification demonstrates the exact opposite.

By the way, did you run the test?
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
OpenGL bug? Nvidia driver bug? SFML bug? My fault?
« Reply #95 on: October 12, 2009, 12:40:13 pm »
Here is another test. Same code as above, with this main() instead:
Code: [Select]
// Globals
Context c1;
Context c2(false, &c1);

int main()
{
    std::cout << "Creating a shared context..." << std::endl;
    Context c3(false, &c1);

    return 0;
}

If it fails, try to pass "true" to the constructor of c2.
Laurent Gomila - SFML developer

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
OpenGL bug? Nvidia driver bug? SFML bug? My fault?
« Reply #96 on: October 12, 2009, 12:43:10 pm »
Hehe.

Your testcode passes all tests (all contexts get created and activated). Looks like side-effects..

Edit: This is for the first testcode, I'll test the new one now.
Edit2: Succeeds for all possible combinations. ;)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
OpenGL bug? Nvidia driver bug? SFML bug? My fault?
« Reply #97 on: October 12, 2009, 04:29:05 pm »
What about this one?
Code: [Select]
#include <SFML/Window.hpp>

int main()
{
    sf::Context context;
    return 0;
}
Laurent Gomila - SFML developer

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
OpenGL bug? Nvidia driver bug? SFML bug? My fault?
« Reply #98 on: October 12, 2009, 04:39:37 pm »
GLXBadContext.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
OpenGL bug? Nvidia driver bug? SFML bug? My fault?
« Reply #99 on: October 12, 2009, 06:09:18 pm »
The exact same from scratch (i.e. without SFML):
Code: [Select]
#include <X11/Xlib.h>
#include <GL/glx.h>
#include <GL/gl.h>
#include <GL/glxext.h>
#include <stdlib.h>
#include <iostream>

class Context
{
public :

    Context(Context* shared = NULL)
    {
        myDisplay = XOpenDisplay(NULL);
        int screen = DefaultScreen(myDisplay);
        myWindow = XCreateWindow(myDisplay,
                                 RootWindow(myDisplay, screen),
                                 0, 0,
                                 1, 1,
                                 0,
                                 DefaultDepth(myDisplay, screen),
                                 InputOutput,
                                 DefaultVisual(myDisplay, screen),
                                 0, NULL);

        CreateContext(shared);
        if (shared)
            glXMakeCurrent(myDisplay, myWindow, myContext);

        std::cout << "Succeeded to create context!" << std::endl;
    }

    ~Context()
    {
        if (glXGetCurrentContext() == myContext)
            glXMakeCurrent(myDisplay, None, NULL);
        glXDestroyContext(myDisplay, myContext);
        XDestroyWindow(myDisplay, myWindow);
        XCloseDisplay(myDisplay);
    }

private :

    void CreateContext(Context* shared)
    {
        XWindowAttributes windowAttributes;
        if (XGetWindowAttributes(myDisplay, myWindow, &windowAttributes) == 0)
        {
            std::cerr << "Failed to get the window attributes" << std::endl;
            return;
        }
        XVisualInfo tpl;
        tpl.depth    = windowAttributes.depth;
        tpl.visualid = XVisualIDFromVisual(windowAttributes.visual);
        tpl.screen   = DefaultScreen(myDisplay);

        int nbVisuals = 0;
        XVisualInfo* visuals = XGetVisualInfo(myDisplay, VisualDepthMask | VisualIDMask | VisualScreenMask, &tpl, &nbVisuals);
        if (!visuals || (nbVisuals == 0))
        {
            if (visuals)
                XFree(visuals);
            std::cerr << "There is no valid visual for the selected screen" << std::endl;
            return;
        }

        int          bestScore  = 0xFFFF;
        XVisualInfo* bestVisual = NULL;
        while (!bestVisual)
        {
            for (int i = 0; i < nbVisuals; ++i)
            {
                int RGBA, doubleBuffer, red, green, blue, alpha, depth, stencil, multiSampling, amples;
                glXGetConfig(myDisplay, &visuals[i], GLX_RGBA,               &RGBA);
                glXGetConfig(myDisplay, &visuals[i], GLX_DOUBLEBUFFER,       &doubleBuffer);
                glXGetConfig(myDisplay, &visuals[i], GLX_RED_SIZE,           &red);
                glXGetConfig(myDisplay, &visuals[i], GLX_GREEN_SIZE,         &green);
                glXGetConfig(myDisplay, &visuals[i], GLX_BLUE_SIZE,          &blue);
                glXGetConfig(myDisplay, &visuals[i], GLX_ALPHA_SIZE,         &alpha);
                glXGetConfig(myDisplay, &visuals[i], GLX_DEPTH_SIZE,         &depth);        
                glXGetConfig(myDisplay, &visuals[i], GLX_STENCIL_SIZE,       &stencil);
                glXGetConfig(myDisplay, &visuals[i], GLX_SAMPLE_BUFFERS_ARB, &multiSampling);        
                glXGetConfig(myDisplay, &visuals[i], GLX_SAMPLES_ARB,        &samples);

                if ((RGBA == 0) || (doubleBuffer == 0))
                    continue;

                int color = red + green + blue + alpha;
                int score = abs(static_cast<int>(32 - color))   +
                            abs(static_cast<int>( 0 - depth))   +
                            abs(static_cast<int>( 0 - stencil)) +
                            abs(static_cast<int>( 0 - 0));
                if (score < bestScore)
                {
                    bestScore  = score;
                    bestVisual = &visuals[i];
                }
            }
        }

        GLXContext toShare = shared ? shared->myContext : NULL;
        myContext = glXCreateContext(myDisplay, bestVisual, toShare, true);
        if (!myContext)
        {
            std::cerr << "Failed to create an OpenGL context for this window" << std::endl;
            return;
        }

        Window root = RootWindow(myDisplay, DefaultScreen(myDisplay));
        Colormap colorMap = XCreateColormap(myDisplay, root, bestVisual->visual, AllocNone);
        XSetWindowColormap(myDisplay, myWindow, colorMap);
        XFree(visuals);
    }

    Display*   myDisplay;
    Window     myWindow;
    GLXContext myContext;

};

Context c1;
Context c2(&c1);

int main()
{
    Context c3(&c1);
    return 0;
}


Quote
g++ test.cpp -o test -lX11 -lGL
./test
Laurent Gomila - SFML developer

Lokk

  • Full Member
  • ***
  • Posts: 228
    • View Profile
    • http://betadineproject.wordpress.com/
OpenGL bug? Nvidia driver bug? SFML bug? My fault?
« Reply #100 on: October 12, 2009, 10:01:55 pm »
Ok, so the first context succeed.
But with a new one (global or not), the glx error occured. (especially on glxMakeCurrent call)

I looked at http://cours.logti.etsmtl.ca/log750/share/GL/glx/xmakecurrent.html
and found :
Quote
Because glXMakeCurrent always replaces the current rendering
context with ctx, there can be only one current context per
thread.


Maybe it can help you... ;)

Lokk

  • Full Member
  • ***
  • Posts: 228
    • View Profile
    • http://betadineproject.wordpress.com/
OpenGL bug? Nvidia driver bug? SFML bug? My fault?
« Reply #101 on: October 12, 2009, 10:25:22 pm »
I maybe found a solution :

Code: [Select]
   /*
    if (shared)
      {
        glXMakeCurrent(myDisplay, myWindow, myContext);
      }
    */
    glXMakeCurrent(myDisplay, myWindow, myContext);


Anyone can test this patch ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
OpenGL bug? Nvidia driver bug? SFML bug? My fault?
« Reply #102 on: October 12, 2009, 10:30:22 pm »
Quote
Ok, so the first context succeed.
But with a new one (global or not), the glx error occured

You mean c3? Or a fourth one?

Quote
the glx error occured. (especially on glxMakeCurrent call)

The exact same error happens on glxMakeCurrent?

Quote
I maybe found a solution

Actually, by doing this you removed a fix ;)
A context that is shared cannot be active at the time it is shared. Thus I only activate a context by default it is not the one that will be shared.

Did doing this make the GLX error disappear for you?
Laurent Gomila - SFML developer

Lokk

  • Full Member
  • ***
  • Posts: 228
    • View Profile
    • http://betadineproject.wordpress.com/
OpenGL bug? Nvidia driver bug? SFML bug? My fault?
« Reply #103 on: October 12, 2009, 11:46:34 pm »
Quote
You mean c3? Or a fourth one?

Context1 has been created but Context2 or Context3 (shared contexts to c1) send a glx error

And yes the error then disappeared.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
OpenGL bug? Nvidia driver bug? SFML bug? My fault?
« Reply #104 on: October 13, 2009, 07:47:11 am »
Quote
Context1 has been created but Context2 or Context3 (shared contexts to c1) send a glx error

Ok. So the problem seems to be caused by activation (or not) of the first context. Can you try the first test (which succeeded) with the same condition on activation (if (shared) ...)?
Laurent Gomila - SFML developer