Closed GWRon closed 5 years ago
sdlgraphics.mod/sdlgraphics.bmx has this:
If glFlags Then
SDL_GL_SetSwapInterval(-1)
context.context = context.window.GLCreateContext()
End If
https://wiki.libsdl.org/SDL_GL_SetSwapInterval states that SDL_GL_SetSwapInterval
adjusts the current context. Here it seems that the context get's created afterwards ?
-> switched lines (and set interval to 0 ...) and ... bamm, got 10.000 frames per second.
The "Flip" there does call the SDL_GL_SetSwapInterval
too - but why isn't it working?
There is a pretty simple answer: SDL's swapInterval uses "-1" for adaptive vsync, "1" for vsync and "0" for immediate. While BlitzMax' Flip is "0" for "as soon as possible", "1" for vsync and "-1" for immediate/as-fast-as-possible (exception if the graphics context wasn't created withthe Graphics
command)
Another tiny bug is there:
Method Flip( sync:Int )
'bbSDLGraphicsFlip sync
If Not _currentContext Then
Return
End If
If sync <> _currentContext.sync Then
_currentContext.sync = sync
If _currentContext.context Then
_currentContext.context.SetSwapInterval(sync)
End If
End If
If _currentContext.context Then
_currentContext.window.GLSwap()
End If
End Method
That context.sync
property is only filled in this method call. And only if it differs from the initial state.
So if the initial state was 0 while the interval was defined as -1 during creation, it would not change to 0 if you called Flip(0)
as the state seems to be unchanged.
-> either set the context.sync to the default one defined during creation -> or do additional checks during flip if something changed.
Added a commit - I've choosen option 1 (context.sync-property set on creation). And I switched flag-set as it sets the current context's swap interval.
I also noted down what the incoming flip-sync values mean (just in case that it changes somewhen).
Taken from the sdl.mod-sample and enhanced to have a (simple) fps counter:
Regardless of what you put to
Flip
it always uses the hertz you use on the screen -> vsync. Using another graphics driver (seeRem ... End Rem
) and you get the desired "not limited" fps (in my case its 13.000 but it does not matter).