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

Author Topic: Possible glTexCoordPointer issue  (Read 4441 times)

0 Members and 1 Guest are viewing this topic.

anthnich

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Long Division LLC
Possible glTexCoordPointer issue
« on: September 28, 2017, 08:17:30 pm »
Hi.

In reference to this commit: https://github.com/SFML/SFML/commit/973ac8ddcd5eea22a01556405e16c554c7dd9788

With commit: https://i.imgur.com/a1llfMb.jpg (notice incorrect coords with camera and pc console)

Without commit: https://i.imgur.com/4bJX1EY.jpg

When I comment out the code (as seen in pic #2), everything is fine.

The actors that affected are sf::Sprites.  Anyone else encounter this issue?

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Possible glTexCoordPointer issue
« Reply #1 on: September 29, 2017, 01:30:38 am »
What OS? Hardware? Driver version?
Does this happen consistently, i.e. across restarts of the game?
Does it happen with exactly the same sprite(s) every time?
What happens if sprites are added or removed from the set of objects that you draw on the screen?
Are you making any raw calls to OpenGL somewhere in your code?
Are you making use of multi-threading?
If you have access to them, have you run sanitizers over your code?
« Last Edit: September 29, 2017, 01:38:17 am by binary1248 »
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

anthnich

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Long Division LLC
Re: Possible glTexCoordPointer issue
« Reply #2 on: September 29, 2017, 02:02:59 am »
* Win 10. GTX 1080. 385.69.
* Yes. Restarts of game + restarts of PC. Happened in my Win, Linux, and Mac builds.
* No, it affects a a number of sprites in the game, but these particular sprites I can get happening repeatably. I haven't run into this issue until recently. I was testing some changes when I saw it happening. I keep backup of all of my built library revisions, so I kept stepping back until I came upon this commit. Commented out code and everything is fine.
* Keeps happening on and off with other ones.
* No.
* No.
* I haven't, but I'll look into it if you want.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Possible glTexCoordPointer issue
« Reply #3 on: September 29, 2017, 02:07:06 am »
Actually, upon closer inspection of the sf::RenderTarget::draw() function, I can think of a possible edge case that would lead to stale texture coordinates from previous draws being re-used instead of fresh data. This effect is highly dependent on what is being drawn and in what order, which is probably the reason not many have noticed it yet. I'll try to reproduce the issue using a minimal example when I have time tomorrow.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Possible glTexCoordPointer issue
« Reply #4 on: September 29, 2017, 03:28:24 am »
I believe this is an example: https://gist.github.com/FRex/b04a5de124d2ce82a2a859bc345ae1a1

Basically what you gotta do is:
One) draw something that doesn't use cache but uses texturing.
Two) draw something that uses cache but doesn't use texturing.
Tri) draw something that uses both texturing and cache.

Using the cache just means drawing 4 or less vertices.

The first time a call is using the cache it will set all the pointers to cache, but if it's not using textures it'll not set the cache.
Next calls that use the cache will not set any pointers and thus reuse the stale pointer from before first cache call.

And if you only use cached drawings and never do a call that uses texturing (i.e. comment out 'one' in my example) then you don't ever set the texturing pointer but have texturing enabled.

If you comment out 'two' and leave 'one' and 'tri' in then it works.

You can try adding a call like 'one' before drawing a spirte or something else that's 4 or less vertices as a quick fix in game code if you want.

By the way, what is that game and when is it coming out, is it a stealth game?
« Last Edit: September 29, 2017, 04:23:25 am by FRex »
Back to C++ gamedev with SFML in May 2023

anthnich

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Long Division LLC
Re: Possible glTexCoordPointer issue
« Reply #5 on: September 29, 2017, 06:06:05 am »
I use sf::VertexArrays and append 4 sf::Vertexs to create quads to populate it. I also use sf::Sprites. They all have textures applied. I apply the texture to the sprite prior to drawing, and I draw the VertexArrays by passing them to the draw function of a RenderTexture, along with the texture.

The game is called Turnover. I released it at the end of 2015. Just doing my best to keep it updated and as bug free as possible.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Possible glTexCoordPointer issue
« Reply #6 on: September 29, 2017, 10:59:25 pm »
Should be fixed with #1297.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

anthnich

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Long Division LLC
Re: Possible glTexCoordPointer issue
« Reply #7 on: September 30, 2017, 04:03:45 am »
Yup, that fixed it! Very nice job. Thank you.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Possible glTexCoordPointer issue
« Reply #8 on: September 30, 2017, 04:50:51 am »
Can you add std::printf("CLEAR------------------\n"); to clear and std::printf("RenderTarget::draw %p %u %p %p\n", vertices, (unsigned)vertexCount, states.texture, states.shader); to draw?
You said you always use texturing so it shouldn't be this bug but you also said the fix worked so I'd like to see the output of that and see what exactly did that.
Back to C++ gamedev with SFML in May 2023

anthnich

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Long Division LLC
Re: Possible glTexCoordPointer issue
« Reply #9 on: September 30, 2017, 05:26:59 am »
I did a little more snooping, and the level in which I could replicate this bug does have a VertexArray that is not given a texture, so I was incorrect in my original statement. Sorry about that!

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Possible glTexCoordPointer issue
« Reply #10 on: September 30, 2017, 05:47:49 am »
Alright then, it was this edge case then.
Back to C++ gamedev with SFML in May 2023

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Possible glTexCoordPointer issue
« Reply #11 on: October 12, 2017, 08:40:12 pm »
Merged in 516678fe
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/