VectorDrawing plus lent que 2DDrawing

Sujets variés concernant le développement en PureBasic
Avatar de l’utilisateur
microdevweb
Messages : 1800
Inscription : mer. 29/juin/2011 14:11
Localisation : Belgique

VectorDrawing plus lent que 2DDrawing

Message par microdevweb »

Tout est dans le titre, voila un petit code de teste qui montrera de quoi je parle (chez mois 3X plus lent)

Code : Tout sélectionner

EnableExplicit
Enumeration 
      #MainForm
      #MainArea
      #MainCanvas
      #BtWithVector
      #BtWithDrawing
EndEnumeration
Global gCanvasW=2000,gCanvasH=2000,gGridSpace=10,gCurrentTime
Procedure VectorDrawing()
      Protected X.d=gGridSpace
      gCurrentTime=ElapsedMilliseconds()
      StartVectorDrawing(CanvasVectorOutput(#MainCanvas))
      ; Eraze the canvas
      VectorSourceColor($FBCDFAFF)
      FillVectorOutput()
      While X<gCanvasW
            MovePathCursor(X,0)
            AddPathLine(X,gCanvasH)
            X+gGridSpace
      Wend
      VectorSourceColor($FB13458B)
      DotPath(1,gGridSpace)
;       DotPath(1,gGridSpace,#PB_Path_RoundEnd)
      StopVectorDrawing()
      Debug "Time ellapsed "+Str(ElapsedMilliseconds()-gCurrentTime)
EndProcedure
Procedure NormalDrawing()
       Protected X=gGridSpace,Y=gGridSpace
      gCurrentTime=ElapsedMilliseconds()
      StartDrawing(CanvasOutput(#MainCanvas))
      ; Eraze the canvas
      Box(0,0,gCanvasW,gCanvasH,$FBCDFAFF)
      While X<gCanvasW
            Y=gGridSpace
            While Y<gCanvasH
                  Plot(X,Y,$FB13458B)
                  Y+gGridSpace
            Wend
            X+gGridSpace
      Wend
      StopDrawing()
      Debug "Time ellapsed "+Str(ElapsedMilliseconds()-gCurrentTime)
EndProcedure
OpenWindow(0,0,0,800,600,"teste",#PB_Window_Maximize|#PB_Window_SystemMenu)
ButtonGadget(#BtWithVector,10,10,180,30,"Avec Vector")
BindGadgetEvent(#BtWithVector,@VectorDrawing())
ButtonGadget(#BtWithDrawing,200,10,180,30,"Avec 2D drawing")
BindGadgetEvent(#BtWithDrawing,@NormalDrawing())
ScrollAreaGadget(#MainArea,0,40,WindowWidth(#MainForm),WindowHeight(#MainForm),gCanvasW,gCanvasH)
CanvasGadget(#MainCanvas,0,0,gCanvasW,gCanvasH)
Repeat
      If WaitWindowEvent()=#PB_Event_CloseWindow
            End
      EndIf
ForEver 


Windows 10 64 bits PB: 5.70 ; 5.72 LST
Work at Centre Spatial de Liège
Jackymb
Messages : 17
Inscription : mer. 04/août/2004 10:09
Localisation : Aix en Provence

Re: VectorDrawing plus lent que 2DDrawing

Message par Jackymb »

Bonjour Microdevweb,

Je viens de faire des tests, dont voici les résultats:

Time ellapsed 157
Time ellapsed 32
Time ellapsed 180
Time ellapsed 34
Time ellapsed 183
Time ellapsed 35
Time ellapsed 182
Time ellapsed 35

Méthode de test 1 fois 'Vector' 1 fois '2D Drawing'. c'est vrai que 'Vector' est plus long.

Matériel: Intel core i5-3470 3.20GHz avec 8Go de ram
Soft: Windows 8.1 & PB 5.40LTS 64bits.
Windows 10 x64 & x86 - PB 5.62 (x86 & x64) - PB 5.46.LTS (x86 & x64) - PB 5.70 Beta4 (x86 & x64)
Avatar de l’utilisateur
Ar-S
Messages : 9477
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: VectorDrawing plus lent que 2DDrawing

Message par Ar-S »

Je ne suis pas un expert en dessin vectoriel mais il me semble qu'ils ont l'avantage d'être zoomable sans perte car tout est recalculé. ceci explique peut être cela. hypothèse à confirmer.
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Anonyme2
Messages : 3518
Inscription : jeu. 22/janv./2004 14:31
Localisation : Sourans

Re: VectorDrawing plus lent que 2DDrawing

Message par Anonyme2 »

J'ai fait des tests sans le debug.

En 2D on dessine des points et pas en vector.

Gdi (2D) utilise l'accélération matériel et pas Gdi+ si essai sous windows

J'ai écris ceci directement en Gdi+ et j'ai affiché un requester pour le résultat.

Code : Tout sélectionner

Procedure Gdip_Drawing()
      Define .i
      Protected X=gGridSpace, *token, *gfx, HDC_CanvasGadget.i, *pen, Y, time
      Protected Dim Elements.f(1) ;// 2 éléments
      gCurrentTime=ElapsedMilliseconds()
      ;// initialisation de Gdi+
      *token = Gdiplus_New()
      HDC_CanvasGadget = StartDrawing(CanvasOutput(#MainCanvas))
      ;// création du graphique GDi+
      GdipCreateFromHDC(HDC_CanvasGadget, @*gfx)
      ; Eraze the canvas
      ;// couleur du graphics (jaune)
      GdipGraphicsClear(*gfx, $FBFFFACD)
      ;// pen de 1 pixel de largeur couleur noir
      GdipCreatePen1($FF000000, 1, #UnitPixel, @*pen)
      
      ;// 1er élément ce qui est dessiné en noir par le pen valeur 1 x largeur pen soit un point 1x1 pixel
      Elements(0) = 1
      ;// 2eme élément l'espace soit (gGridSpace-1) x largeur pen soit un espace de gGridSpace-1 pixels
      Elements(1) = gGridSpace-1
      ;// application de la forme pointillée au pen liée au tableau
      GdipSetPenDashArray(*Pen, @Elements(), 2)
      ;// position en Y inférieur (en bas canvas)
      y = GadgetHeight(#MainCanvas) -1
      
      ;// x à l'origine
      X = gGridSpace
      While X < gCanvasW
            GdipDrawLineI(*gfx, *pen, x, gGridSpace, x, Y)
            X + gGridSpace
      Wend
      StopDrawing()
      GdipDeletePen(*Pen)
      GdipDeleteGraphics(*gfx)
      GdiplusShutdown(*token)
      time = ElapsedMilliseconds()-gCurrentTime
      MessageRequester("Time ellapsed", "Gdi+ :  " +Str(time), 16)
EndProcedure
Il y a des variations parfois importantes sur les résultats si effectués plusieurs fois de suite
Essai sans debugger, win7 pro x64 (Portable 5 ans d'âge), PB 5.40 LTS x64
2D : 28
Gdi+ 59
Vector : 328

c'est plus de 10 fois sur mon PC pour vector (?)

Les essais sont encore plus lent en 32 bits pour vector et Gdi+, c'est très stable pour 2D

voici mon code d'essai complet

Code : Tout sélectionner

EnableExplicit
Enumeration
      #MainForm
      #MainArea
      #MainCanvas
      #BtWithVector
      #BtWithDrawing
      #BtWithGdiplus
EndEnumeration
Global gCanvasW=2000,gCanvasH=2000,gGridSpace=10,gCurrentTime

Procedure VectorDrawing()
      Protected X.d=gGridSpace, time
      gCurrentTime=ElapsedMilliseconds()
      StartVectorDrawing(CanvasVectorOutput(#MainCanvas))
      ; Eraze the canvas
      VectorSourceColor($FBCDFAFF)
      FillVectorOutput()
      While X < gCanvasW
            MovePathCursor(X,0)
            AddPathLine(X, gCanvasH)
            X+gGridSpace
      Wend
      VectorSourceColor($FB13458B)
      DotPath(1,gGridSpace)
      ;       DotPath(1,gGridSpace,#PB_Path_RoundEnd)
      StopVectorDrawing()
      time = ElapsedMilliseconds()-gCurrentTime
      MessageRequester("Time ellapsed", "VectorDrawing :  " +Str(time), 16)
EndProcedure

Procedure NormalDrawing()
      Protected X=gGridSpace,Y=gGridSpace, time
      gCurrentTime=ElapsedMilliseconds()
      StartDrawing(CanvasOutput(#MainCanvas)) :
      ; Eraze the canvas
      Box(0,0,gCanvasW,gCanvasH,$FBCDFAFF)
      While X < gCanvasW
            Y=gGridSpace
            While Y<gCanvasH
                  Plot(X,Y,$FB13458B)
                  Y+gGridSpace
            Wend
            X+gGridSpace
      Wend
      StopDrawing()
      time = ElapsedMilliseconds()-gCurrentTime
      MessageRequester("Time ellapsed", "NormalDrawing :  " +Str(time), 16)
EndProcedure

Structure GdiplusStartupInput Align #PB_Structure_AlignC ;{
      GdiPlusVersion.l
      *DebugEventCallback
      SuppressBackgroundThread.l
      SuppressExternalCodecs.l
EndStructure ;}

Enumeration
      #UnitWorld       ;// 0 -- World coordinate (non-physical unit)
      #UnitDisplay     ;// 1 -- Variable -- for PageTransform only
      #UnitPixel       ;// 2 -- Each unit is one device pixel.
      #UnitPoint       ;// 3 -- Each unit is a printer's point or 1/72 inch.
      #UnitInch        ;// 4 -- Each unit is 1 inch.
      #UnitDocument    ;// 5 -- Each unit is 1/300 inch.
      #UnitMillimeter  ;// 6 -- Each unit is 1 millimeter.
EndEnumeration

Import "gdiplus.lib"
      ;{
      GdipCreateFromHDC(dc.i, *graphics)
      GdipGraphicsClear(*graphics, color.l)
      GdipCreatePen1(color, width.f, unit.i, *pen)
      GdipSetPenDashArray(*pen, *dash, count.l)
      GdipDrawLineI(*graphics, *pen, x1.l, y1.l, x2.l, y2.l)
      GdipDeletePen(*Pen)
      GdipDeleteGraphics(*gfx)
      GdiplusShutdown(*token)
      GdiplusStartup(*token, *input, *output)
      ;}
EndImport

Procedure.i Gdiplus_New(version = 1, *hEventCB = #Null, Codecs = #False, bgThread = #False)
      Protected *token, input.GdiplusStartupInput
      With input
            \GdiPlusVersion = version
            ;             \DebugEventCallback = *hEventCB
            ;             \SuppressExternalCodecs = Codecs
            ;             \SuppressBackgroundThread = bgThread
      EndWith
      GdiplusStartup(@*token, @input, #Null)
      ProcedureReturn *token
EndProcedure

Procedure Gdip_Drawing()
      Define .i
      Protected X=gGridSpace, *token, *gfx, HDC_CanvasGadget.i, *pen, Y, time
      Protected Dim Elements.f(1) ;// 2 éléments
      gCurrentTime=ElapsedMilliseconds()
      ;// initialisation de Gdi+
      *token = Gdiplus_New()
      HDC_CanvasGadget = StartDrawing(CanvasOutput(#MainCanvas))
      ;// création du graphique GDi+
      GdipCreateFromHDC(HDC_CanvasGadget, @*gfx)
      ; Eraze the canvas
      ;// couleur du graphics (jaune)
      GdipGraphicsClear(*gfx, $FBFFFACD)
      ;// pen de 1 pixel de largeur couleur noir
      GdipCreatePen1($FF000000, 1, #UnitPixel, @*pen)
      
      ;// 1er élément ce qui est dessiné en noir par le pen valeur 1 x largeur pen soit un point 1x1 pixel
      Elements(0) = 1
      ;// 2eme élément l'espace soit gGridSpace x largeur pen soit un espace de gGridSpace pixels
      Elements(1) = gGridSpace-1
      ;// application de la forme pointillé au pen lié au tableau
      GdipSetPenDashArray(*Pen, @Elements(), 2)
      ;// position en Y inférieur (en bas canvas)
      y = GadgetHeight(#MainCanvas) -1
      
      ;// x à l'origine
      X = gGridSpace
      While X < gCanvasW
            GdipDrawLineI(*gfx, *pen, x, gGridSpace, x, Y)
            X + gGridSpace
      Wend
      StopDrawing()
      GdipDeletePen(*Pen)
      GdipDeleteGraphics(*gfx)
      GdiplusShutdown(*token)
      time = ElapsedMilliseconds()-gCurrentTime
      MessageRequester("Time ellapsed", "Gdi+ :  " +Str(time), 16)
EndProcedure

OpenWindow(0,0,0,800,600,"teste",#PB_Window_Maximize|#PB_Window_SystemMenu)
ButtonGadget(#BtWithVector,10,10,180,30,"Avec Vector")
BindGadgetEvent(#BtWithVector,@VectorDrawing())
ButtonGadget(#BtWithDrawing,200,10,180,30,"Avec 2D drawing")
BindGadgetEvent(#BtWithDrawing,@NormalDrawing())

ButtonGadget(#BtWithGdiplus,390,10,180,30,"Avec Gdi+")
BindGadgetEvent(#BtWithGdiplus,@Gdip_Drawing())

ScrollAreaGadget(#MainArea,0,40,WindowWidth(#MainForm),WindowHeight(#MainForm),gCanvasW,gCanvasH)
CanvasGadget(#MainCanvas,0,0,gCanvasW,gCanvasH)

Repeat
      If WaitWindowEvent()=#PB_Event_CloseWindow
            End
      EndIf
ForEver
Avatar de l’utilisateur
microdevweb
Messages : 1800
Inscription : mer. 29/juin/2011 14:11
Localisation : Belgique

Re: VectorDrawing plus lent que 2DDrawing

Message par microdevweb »

Merci Denis,

C'est triste cela, moi qui trouvais cette nouvelle lib formidable.
Windows 10 64 bits PB: 5.70 ; 5.72 LST
Work at Centre Spatial de Liège
Torp
Messages : 360
Inscription : lun. 22/nov./2004 13:05

Re: VectorDrawing plus lent que 2DDrawing

Message par Torp »

Hello,

Même constat chez moi avec de grosses disparités entre plusieurs essais, mais toujours les mêmes ordres de grandeurs entre les différents modes (le PC à 2 ans):

2D : 48
Gdi+ 71
Vector : 181
Micheao
Messages : 533
Inscription : dim. 07/déc./2014 10:12
Localisation : Sud-Est

Re: VectorDrawing plus lent que 2DDrawing

Message par Micheao »

Salut microdevweb

Chez moi avec Vecteur : Time ellapsed 134
Avatar de l’utilisateur
blendman
Messages : 2017
Inscription : sam. 19/févr./2011 12:46

Re: VectorDrawing plus lent que 2DDrawing

Message par blendman »

salut

Récemment, Freak (le dev de la vector drawing) a expliqué que pour PB5.40, il avait intégré la lib sans l'optimiser, et que l'optimisation serait faite pour une prochaine version, si j'ai bien tout compris.
L'objectif premier était d'abord que cette lib soit intégrée et fonctionnelle pour pb5.40 ;).

Pour mon soft de dessins (animatoon), je dessine directement sur les sprites, c'est le plus rapide de tout ce que j'ai testé ^^.
Avatar de l’utilisateur
microdevweb
Messages : 1800
Inscription : mer. 29/juin/2011 14:11
Localisation : Belgique

Re: VectorDrawing plus lent que 2DDrawing

Message par microdevweb »

Ben pour rad je vais faire une mélange de 2Ddrawing et vector. Je verrais au fils du temps si je doit modifier
Windows 10 64 bits PB: 5.70 ; 5.72 LST
Work at Centre Spatial de Liège
Répondre