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

Author Topic: RenderWindow::draw not working on different thread?  (Read 2849 times)

0 Members and 1 Guest are viewing this topic.

Flawe

  • Newbie
  • *
  • Posts: 24
    • View Profile
RenderWindow::draw not working on different thread?
« on: January 02, 2013, 05:12:11 pm »
So I have my main thread set up to create the window and poll the event queue. I set the window to inactive on this thread, launch a second thread and do most of the logic and rendering there.

I use mostly ogl calls but I wanted to add some text rendering utilizing what is available in sfml. I quickly found out that text doesn't render. After investigating a bit, it seems any calls to RenderWindow::draw have no effect when they happen on this second thread. If I do them on the main thread where I created the window every works just fine.

Any ideas what I might be missing? I'm resetting the ogl states, everything else works just fine, no errors, or artifacts, no nothing.

Thanks!

EDIT: I just synced an built latest from the github repo, for what it's worth
« Last Edit: January 02, 2013, 05:16:24 pm by Flawe »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: RenderWindow::draw not working on different thread?
« Reply #1 on: January 02, 2013, 05:34:18 pm »
I set the window to inactive on this thread, launch a second thread and do most of the logic and rendering there.
Do you also set the second thread active?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: RenderWindow::draw not working on different thread?
« Reply #2 on: January 02, 2013, 05:41:04 pm »
If you call setText not in the drawing thread, make sure to call glFlush() after it so that the drawing thread is aware of the new glyphs.
Laurent Gomila - SFML developer

Flawe

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: RenderWindow::draw not working on different thread?
« Reply #3 on: January 02, 2013, 05:45:11 pm »
Thanks for the quick reply guys...

It all happens on the drawing thread (which is set to active). I've tried adding the glFlush as well but no change. This seems to affect any calls to renderWindow::draw, shapes and text, etc.

Flawe

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: RenderWindow::draw not working on different thread?
« Reply #4 on: January 02, 2013, 05:57:17 pm »
For what it's worth, I can confirm the internal RenderTarget::draw call is made with the vertex list, and the glDrawArray happens with no error.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: RenderWindow::draw not working on different thread?
« Reply #5 on: January 02, 2013, 06:38:09 pm »
I'm afraid you'll have to provide a complete and minimal code that reproduces the error :P
Laurent Gomila - SFML developer

Flawe

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: RenderWindow::draw not working on different thread?
« Reply #6 on: January 02, 2013, 07:27:27 pm »
Ah, interesting, it's not the thread at all. I have some buffers stored in vram and some code that looks like this:
...
glDeleteBuffers(1, &vbo);
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, numVerts * sizeof(sVertexData), NULL, GL_DYNAMIC_DRAW);
...
glDeleteBuffers(1, &ibo);
glGenBuffers(1, &ibo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices * sizeof(u32), NULL, GL_STATIC_DRAW);
...

if I remove/bypass this code the font rendering works just fine.

edit: to be more specific, it's just the vertex buffer causing the issue, the index array can be allocated just fine without breaking font rendering.
« Last Edit: January 02, 2013, 07:46:08 pm by Flawe »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: RenderWindow::draw not working on different thread?
« Reply #7 on: January 02, 2013, 08:52:52 pm »
You must call
glBindBuffer(GL_ARRAY_BUFFER, 0);
before drawingSFML stuff.

It should be inside RenderTarget::resetGLStates(), I'll add it soon.
Laurent Gomila - SFML developer

Flawe

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: RenderWindow::draw not working on different thread?
« Reply #8 on: January 02, 2013, 08:59:10 pm »
cool, thanks!