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

Author Topic: OpenGL context resource sharing  (Read 4223 times)

0 Members and 1 Guest are viewing this topic.

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
OpenGL context resource sharing
« on: September 02, 2013, 06:07:19 pm »
Assuming I have some secondary threads and one main thread that runs the window.

Is it enough to just create the window in the main thread, and instantiate sf::Context once per secondary thread in the respective thread? Will the active context of the main thread have access to OpenGL resources created by secondary threads (i.e. if I create a texture in thread 2 and receive the name "42" for it from OpenGL, will the other threads be able to access it via glBindTexture(..., 42)?).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: OpenGL context resource sharing
« Reply #1 on: September 02, 2013, 06:18:26 pm »
Yes ;)
Laurent Gomila - SFML developer

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: OpenGL context resource sharing
« Reply #2 on: September 02, 2013, 08:06:37 pm »
Have you tested this on both windows and linux?

It doesn't seem to work for me. When I create the resource in question in a secondary thread, the main thread doesn't render it (I've gone through the code a dozen times now, the rendering logic is correct, just nothing shows up on screen). When I "pre-load" the resource in the main thread, it renders as expected. The main thread just starts a window at the start of the application, and the secondary thread just puts a sf::Context context; in a place where it stays until the thread is shut down (which doesn't happen until the end of the application).

The secondary thread still creates the resources correctly (I've checked with gDebugger), but for some reason when the main thread renders using those resources nothing shows up.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: OpenGL context resource sharing
« Reply #3 on: September 02, 2013, 09:10:00 pm »
Which version of SFML are you using? Can you show a complete and minimal code that reproduces the problem? Have you tried a glFlush() at the end of the loading thread?
Laurent Gomila - SFML developer

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: OpenGL context resource sharing
« Reply #4 on: September 03, 2013, 09:04:44 pm »
Which version of SFML are you using? Can you show a complete and minimal code that reproduces the problem? Have you tried a glFlush() at the end of the loading thread?

2.1

glFlush won't solve the issue. The resources are loaded and available (checked with gDebugger) when the main thread wants to access them.

Minimal code that reproduces the problem... ughh. I have to write boilerplate opengl again :D. Not today, I'm in super lazy mode since Rome 2 was released. But I'll post something tomorrow.

You know, I just rembered that I don't set the same pixel format with sf::ContextSettings when I create sf::Context instance. This is required in windows, I think (unless sf::Context takes care of using the settings of the main context somehow), otherwise it won't recognize the context's as shared. I'll try it out tomorrow, now I need to conquer Carthage.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: OpenGL context resource sharing
« Reply #5 on: September 03, 2013, 10:31:11 pm »
Quote
glFlush won't solve the issue. The resources are loaded and available (checked with gDebugger) when the main thread wants to access them.
You should try instead of assuming :P
Laurent Gomila - SFML developer