It is currently Wed Nov 20, 2019 11:43 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 48 posts ]  Go to page Previous  1, 2, 3, 4
Author Message
 Post subject: Re: Gaussian blur in real time?
PostPosted: Mon Oct 21, 2019 9:33 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Sep 18, 2013 11:54 am
Posts: 390
Location: France
The structure of most of my 2D programs:

Code:
EnableExplicit

#screen_width = 1920
#screen_height = 1080
#app_title = "TITLE"

Define sprite_mouse.i, sprite_fps.i
Define frame.i, frame_refresh, frame_time.i, event.i
Global delta.d

InitKeyboard() : InitMouse() : InitSprite()

OpenWindow(0, 0, 0, #screen_width, #screen_height, #app_title, #PB_Window_BorderLess | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, #screen_width, #screen_height, #False, 0, 0, #PB_Screen_SmartSynchronization)

sprite_mouse = CreateSprite(#PB_Any, 7, 7)
StartDrawing(SpriteOutput(sprite_mouse))
Box(0, 0, OutputWidth(), OutputHeight(), #Black)
Box(0, 0, OutputWidth() - 2, OutputHeight() - 2, #White)
StopDrawing()

sprite_fps = CreateSprite(#PB_Any, 40, 20)

Repeat
  Repeat
    event.i = WindowEvent()
    If event = #PB_Event_CloseWindow : Break 2 : EndIf
  Until event = 0
 
  ClearScreen(RGB(50, 65, 70))
 
  ExamineKeyboard() : ExamineMouse()
  MouseLocate(DesktopMouseX(), DesktopMouseY())
 
  StartDrawing(ScreenOutput())
  DrawingBuffer() ; PERF
  StopDrawing()
 
  DisplaySprite(sprite_fps, 0, 0)
  DisplaySprite(sprite_mouse, MouseX(), MouseY())
 
  ; FPS and Delta Time
  frame + 1
  If ElapsedMilliseconds() > frame_refresh
    StartDrawing(SpriteOutput(sprite_fps))
    DrawText(0, 0, "fps:" + frame)
    StopDrawing()
    frame_refresh = ElapsedMilliseconds() + 1000
    frame = 0
  EndIf
  delta = (ElapsedMilliseconds() - frame_time) / 1000
  frame_time = ElapsedMilliseconds()
 
  FlipBuffers()   
Until KeyboardReleased(#PB_Key_Escape)


40 FPS. (without Debugger)

EDIT: Ok, with DirectX11 without Debugger, there's no cost, steady 60FPS. On OpenGL, I drop at 30 and the DirectionalBlur module gives me black and white pixels. Weird.


Top
 Profile  
Reply with quote  
 Post subject: Re: Gaussian blur in real time?
PostPosted: Mon Oct 21, 2019 9:53 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3519
Location: Netherlands
Joubarbe wrote:
EDIT: Ok, with DirectX11 without Debugger, there's no cost, steady 60FPS. On OpenGL, I drop at 30 and the DirectionalBlur module gives me black and white pixels. Weird.

It's explained in the PB help page for ScreenOutput().
OpenGL doesn't allow direct buffer access.
So when using OpenGL, the whole screen buffer is copied to main memory and back again when StopDrawing() is called.
This is what makes it slow on OpenGL.

_________________
macOS 10.15 Catalina, PB 5.71 x64


Top
 Profile  
Reply with quote  
 Post subject: Re: Gaussian blur in real time?
PostPosted: Mon Oct 21, 2019 11:18 am 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1135
Location: right here
Joubarbe wrote:
But there must be something I don't get, because this obviously doesn't work. Nothing get blurred, even though the CPU is working.

You would have to either copy the 2nd buffer back to the drawing buffer or pass the drawing buffer address directly to the blur function. Currently it looks like your are just blurring the copied memory but you don't do anything with it.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 48 posts ]  Go to page Previous  1, 2, 3, 4

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye