StartDrawing very very low PB6.30b6

Everything else that doesn't fall into one of the other PB categories.
User avatar
thyphoon
Enthusiast
Enthusiast
Posts: 364
Joined: Sat Dec 25, 2004 2:37 pm

StartDrawing very very low PB6.30b6

Post by thyphoon »

I just noticed something... with a 4K screen, a simple `startdrawing(screenoutput())` causes the FPS to plummet... it goes from 60 FPS to 30 FPS just by displaying the text by pressing F2... is that normal? I understand StartDrawing is expensive, but this is ridiculous! And even with more complex displays, the FPS drops from 60 to 30.
Test machine: i7-8700, 32GB RAM, and Nvidia GTX 1080!
Can anyone confirm this? I'm wondering if there's a bug.
This is happening with PureBasic version 6.30 beta 6.

Code: Select all


EnableExplicit

#SpriteID = 0
#SpriteSize = 32

If InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Erreur", "InitSprite() ou InitKeyboard() a échoué.")
  End
EndIf

; Récupération résolution écran (desktop 0)
ExamineDesktops()
Define.i screenW = DesktopWidth(0)
Define.i screenH = DesktopHeight(0)

If screenW <= 0 Or screenH <= 0
  MessageRequester("Erreur", "Impossible de lire la résolution du bureau.")
  End
EndIf

; Ouvrir l'écran à la résolution native
; Note: en fullscreen, pas de barre/menus, et Escape pour quitter.
If OpenScreen(screenW, screenH, 32, "Sprite rebond + FPS (F2)") = 0
  MessageRequester("Erreur", "OpenScreen() a échoué.")
  End
EndIf

; Création du sprite (carré blanc)
If CreateSprite(#SpriteID, #SpriteSize, #SpriteSize, #PB_Sprite_AlphaBlending) = 0
  MessageRequester("Erreur", "CreateSprite() a échoué.")
  End
EndIf

If StartDrawing(SpriteOutput(#SpriteID))
  Box(0, 0, #SpriteSize, #SpriteSize, RGB(255, 255, 255))
  StopDrawing()
EndIf

; Position / vitesse
Define.f x = (screenW - #SpriteSize) * 0.5
Define.f y = (screenH - #SpriteSize) * 0.5
Define.f vx = 6.0
Define.f vy = 4.0

; FPS
Define showFPS.i = #False
Define frames.i = 0
Define fps.i = 0
Define lastFpsTick.i = ElapsedMilliseconds()

; Gestion toggle F2 (anti-répétition)
Define f2WasDown.i = #False

Repeat
  ExamineKeyboard()

  If KeyboardPushed(#PB_Key_Escape)
    Break
  EndIf

  ; Toggle F2 (une fois par appui)
  If KeyboardPushed(#PB_Key_F2)
    If f2WasDown = #False
      showFPS ! 1
      f2WasDown = #True
    EndIf
  Else
    f2WasDown = #False
  EndIf

  ; Mouvement
  x + vx
  y + vy

  ; Rebond X
  If x < 0
    x = 0
    vx = -vx
  ElseIf x + #SpriteSize > screenW
    x = screenW - #SpriteSize
    vx = -vx
  EndIf

  ; Rebond Y
  If y < 0
    y = 0
    vy = -vy
  ElseIf y + #SpriteSize > screenH
    y = screenH - #SpriteSize
    vy = -vy
  EndIf

  ; Rendu
  ClearScreen(RGB(0, 0, 0))
  DisplaySprite(#SpriteID, Int(x), Int(y))

  ; Calcul FPS (mise à jour 1 fois / seconde)
  frames + 1
  If ElapsedMilliseconds() - lastFpsTick >= 1000
    Debug fps
    fps = frames
    frames = 0
    lastFpsTick = ElapsedMilliseconds()
  EndIf

  ; Affichage FPS
  If showFPS
    If StartDrawing(ScreenOutput())
      DrawingMode(#PB_2DDrawing_Transparent)
      DrawText(10, 10, "FPS : " + Str(fps), RGB(255, 255, 255))
      StopDrawing()
    EndIf
  EndIf

  FlipBuffers()

ForEver

End



// Moved from "Bugs - Windows" to "General Discussion" (Kiffi)
Justin
Addict
Addict
Posts: 962
Joined: Sat Apr 26, 2003 2:49 pm

Re: StartDrawing very very low PB6.30b6

Post by Justin »

I get <20fps on 4k but the doc says it's very slow, if i remember well i think people use sprites to draw text
User avatar
thyphoon
Enthusiast
Enthusiast
Posts: 364
Joined: Sat Dec 25, 2004 2:37 pm

Re: StartDrawing very very low PB6.30b6

Post by thyphoon »

Thank you for trying.😉🙏
I know it's slow... I've been using it for years but I never realized it was this slow! 😱😅
User avatar
idle
Always Here
Always Here
Posts: 6130
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: StartDrawing very very low PB6.30b6

Post by idle »

Also something else going on with the drawing modes as DisplayTransparentSprite isn't working properly
sprites now need to be created with #PB_Sprite_AlphaBlending and then it breaks compatibility with 6.20 code
Post Reply