Multiple StartDrawing()/StopDrawing

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Multiple StartDrawing()/StopDrawing

Post by DK_PETER »

StartDrawing(TextureOutput(Texture))
StopDrawing(TextureOutPut(Texture))
StartDrawing(ImageOutput(Image))
StopDrawing(ImageOutput(Image))
StartDrawing(CanvasOutput(ID))
StopDrawing(CanvasOutput(ID))
etc...
Except from ScreenOutput(), it should be doable...I think. :)
Don't know how much work it would require, though.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Multiple StartDrawing()/StopDrawing

Post by Michael Vogel »

Do you mean, something like this...

Code: Select all

StartDrawing(TextureOutput(Texture))
StartDrawing(ImageOutput(Image))
dc=StartDrawing(CanvasOutput(ID))

StopDrawing(TextureOutPut(Texture))
StopDrawing(ImageOutput(Image))
StopDrawing(CanvasOutput(ID))
...should be allowed?

I would like it, but it would need to change all drawing commands adding a referer parameter, e.g. Box(dc,x,y,w,h)
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Multiple StartDrawing()/StopDrawing

Post by DK_PETER »

Yes. Right now we have a single StopDrawing() for all outputs.
(Screen, Sprite, Texture, Image, Canvas, Printer and Window)
Being able to do multiple outputs at the same time would be
a big leap forward.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Multiple StartDrawing()/StopDrawing

Post by STARGÅTE »

DK_PETER wrote:Being able to do multiple outputs at the same time would bea big leap forward.
It is already implemented:
PureBasic Help wrote:If "Create thread-safe executable" is enabled in the compiler options then every thread has its own current drawing output, which means two threads can do drawing on separate outputs at the same time.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Multiple StartDrawing()/StopDrawing

Post by DK_PETER »

@StarGate
Here's an example of what I would like to be able to do.

Code: Select all

Declare.i InsertImage()

OpenWindow(0, 0, 0, 800, 800, "Test", #PB_Window_SystemMenu)
CanvasGadget(0, 0, 0, 500, 500)
StartDrawing(CanvasOutput(0))
For y = 0 To 4 Step 100
  For x = 0 To 4 Step 100
    DrawImage(ImageID(InsertImage()), x * 100, y * 100)
  Next x
Next y
StopDrawing()

Repeat : ev = WindowEvent() : Until ev = #PB_Event_CloseWindow

Procedure.i InsertImage()
  Protected im = CreateImage(#PB_Any, 100, 100)
  StartDrawing(ImageOutput(im))
  Box(0,0, 100, 100, RGB(Random(255), Random(255), Random(255)))
  StopDrawing()
  ProcedureReturn im
EndProcedure
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
#NULL
Addict
Addict
Posts: 1497
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Multiple StartDrawing()/StopDrawing

Post by #NULL »

maybe something like this:
(tested on linux)

Code: Select all

; enable threadsafe!

Procedure getImage(*p.Integer)
  Protected im = CreateImage(#PB_Any, 100, 100)
  StartDrawing(ImageOutput(im))
  Box(0,0, 100, 100, RGB(Random(255), Random(255), Random(255)))
  StopDrawing()
  *p\i = im
EndProcedure

Procedure.i InsertImage()
  Protected im, t
  t = CreateThread(@ getImage(), @ im)
  WaitThread(t)
  ProcedureReturn im
EndProcedure

OpenWindow(0, 0, 0, 800, 800, "Test", #PB_Window_SystemMenu)
CanvasGadget(0, 0, 0, 500, 500)
StartDrawing(CanvasOutput(0))
For y = 0 To 4 Step 100
  For x = 0 To 4 Step 100
    DrawImage(ImageID(InsertImage()), x * 100, y * 100)
  Next x
Next y
StopDrawing()

Repeat : ev = WindowEvent() : Until ev = #PB_Event_CloseWindow


User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Multiple StartDrawing()/StopDrawing

Post by STARGÅTE »

@Null, I was to slow ^^, looks very similar :-P

Code: Select all

CompilerIf Not #PB_Compiler_Thread
	MessageRequester("", "Enable Create thread-safe executable")
	End
CompilerEndIf

Declare.i InsertImage()

OpenWindow(0, 0, 0, 800, 800, "Test", #PB_Window_SystemMenu)
CanvasGadget(0, 0, 0, 500, 500)
StartDrawing(CanvasOutput(0))
For y = 0 To 4 Step 1
  For x = 0 To 4 Step 1
    DrawImage(ImageID(InsertImage()), x * 100, y * 100)
  Next x
Next y
StopDrawing()

Repeat : ev = WindowEvent() : Until ev = #PB_Event_CloseWindow

Procedure.i InsertImageThread(*Image.Integer)
  Protected im = CreateImage(#PB_Any, 100, 100)
  StartDrawing(ImageOutput(im))
  Box(0,0, 100, 100, RGB(Random(255), Random(255), Random(255)))
  StopDrawing()
  *Image\i = im
EndProcedure

Procedure.i InsertImage()
	Protected Image.i
	WaitThread(CreateThread(@InsertImageThread(), @Image))
	ProcedureReturn Image
EndProcedure
Last edited by STARGÅTE on Sat Aug 18, 2018 10:14 am, edited 1 time in total.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Multiple StartDrawing()/StopDrawing

Post by Michael Vogel »

Not sure if a something like PushDrawingState() and PopDrawingState() could be useful to allow something like the example above without using threads.

Code: Select all

Procedure ImageFx(image)
	
	state=#False
	
	PushDrawingState()
	If StartDrawing(ImageOutput(image))
		
		;...
		
		StopDrawing()
		state=#True
	EndIf
	
	PopDrawingState()
	
	ProcedureReturn state
	
EndProcedure
Last edited by Michael Vogel on Sat Aug 18, 2018 9:31 am, edited 1 time in total.
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Multiple StartDrawing()/StopDrawing

Post by DK_PETER »

@Null And @Stargate
I do think, that my idea would be the best way, if possible.
Anyway, thank you both for a nice alternative solution - I didn't think of that.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
#NULL
Addict
Addict
Posts: 1497
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Multiple StartDrawing()/StopDrawing

Post by #NULL »

STARGÅTE wrote:@Null, I was to slow ^^, looks very similar :-P
At least you used a proper threadsafe check instead of my lazy comment :)
Post Reply