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

Author Topic: Drawing and Loading: One of it in a thread; Possible?  (Read 3006 times)

0 Members and 1 Guest are viewing this topic.

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
Drawing and Loading: One of it in a thread; Possible?
« on: August 16, 2010, 10:00:41 pm »
I am currently working on some code which should show something on the screen (animated) while resources are loaded.
To have a clear animation which is not interrupted by loading resources (which might take some ms per resource) I do one of the two tasks in a separate thread.

Now I'd like to know how I should manage it. I tried to let the main program create the window, start the thread and load resources whereas the thread draws a sprite on the screen, but I get some OpenGL error in the console:
Code: [Select]
An internal OpenGL call failed in Drawable.cpp (399) : GL_INVALID_OPERATION, the specefied operation is not allowed in the current state
I suggest I must draw in the same thread where I created the window, but the same thread must be responsible on loading images I suggest...

Any solutions / tips on this?
Please note that my previous display name was "Shy Guy".

Kingdom of Fish

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Drawing and Loading: One of it in a thread; Possible?
« Reply #1 on: August 16, 2010, 10:38:43 pm »
All drawing has to be made from the same thread, set the worker thread to load data instead.... there are texts about it on the wiki.

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
Drawing and Loading: One of it in a thread; Possible?
« Reply #2 on: August 16, 2010, 10:51:28 pm »
Quote from: "Kingdom of Fish"
All drawing has to be made from the same thread, set the worker thread to load data instead.... there are texts about it on the wiki.

Oops, I haven't taken a careful look in the wiki  :roll:
Thanks ^^
Please note that my previous display name was "Shy Guy".

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Drawing and Loading: One of it in a thread; Possible?
« Reply #3 on: August 16, 2010, 11:25:33 pm »
This is not true, drawing can be done from other threads. The only thing to care about is to deactivate (SetActive(false)) the window in the thread where it is active, before activating it in another thread.

But however, it is simpler to load images in a thread and leave the rendering in the main thread.
Laurent Gomila - SFML developer

Kingdom of Fish

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Drawing and Loading: One of it in a thread; Possible?
« Reply #4 on: August 16, 2010, 11:39:04 pm »
Oh, sorry  :oops:

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
Drawing and Loading: One of it in a thread; Possible?
« Reply #5 on: August 17, 2010, 12:21:47 am »
Quote from: "Laurent"
This is not true, drawing can be done from other threads. The only thing to care about is to deactivate (SetActive(false)) the window in the thread where it is active, before activating it in another thread.

But however, it is simpler to load images in a thread and leave the rendering in the main thread.

Okay, but I have it already changed that the thread loads the stuff while the main program draws on screen.

By the way, I found an old post:
Quote from: "Laurent"
I first thought it was not a good idea, but then I realized that it could easily be done without altering the public interface, nor requiring extra calls from the user.

I modified the code so that internal OpenGL textures are now not created right after loading, but rather on first use. So that loading can be done anywhere with no restriction.

Thanks for the idea

Does that have any effect (e.g. some ms delay) when first drawing it on screen? Or does the texture creation happen when I assign an image to a sprite? Or jas something changed since then?
Please note that my previous display name was "Shy Guy".