Jump to content

glBlitFramebufferEXT


Flexman
 Share

Recommended Posts

This is a GL 3.0 extension so I'm not too sure if I should be using it.

 

I need to cut'n'paste a small section of one buffer into another and not clear on what best practice is here. I'm using glBlitFramebufferEXT which does the job fine. An example...

 

glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, Self.buffer.framebuffer) ;
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0) ;
glBlitFramebufferEXT(0, 0, 511, 511, 0, game.scene.screenheight - 511, 511, game.scene.screenheight, GL_COLOR_BUFFER_BIT, GL_NEAREST) ;
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0) ;
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0) ;

 

But since Leadwerks minimum requirement is Shader Model 3, it's reasonable to use this no? Anyone have an alternative to consider?

 

All I want to do is snip out a small region of the main buffer for use in a texture which I'll post process for night vision. Currently I'm using a second camera to do this but it seems like overkill and can cripple performance.

6600 2.4G / GTX 460 280.26 / 4GB Windows 7

Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT

Tricubic Studios Ltd. ~ Combat Helo

Link to comment
Share on other sites

OpenGL 1.0 has a blitter command too, no need to use the OpenGL 3.0 version for that. SDL seems to have also a optimized hardware blitting, which is faster than raw OpenGL:

http://kevinlocke.name/inquiry/sdlblitspeed/sdlblitspeed.php

SDL works fine with LE, just need to write a simple register function to link the graphics canvas to SDL. I can make a demo of that too, probably in the gamelib tutorials.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

That's fine to use, it's what the engine's copybuffer command uses internally:

Function CopyBuffer(src:TBuffer,dst:TBuffer,flags=BUFFER_DEPTH|BUFFER_COLOR0|BUFFER_COLOR1|BUFFER_COLOR2|BUFFER_COLOR3)
'If src=BackBuffer() Return
If src=dst Return
Local buffer:TBuffer=GetBuffer()
Local filter=GL_NEAREST
Local temp:Int

If src.width()<>dst.width() Or src.height()<>dst.height()
	filter=GL_LINEAR
EndIf
If (BUFFER_DEPTH & flags)
	If src.depthbuffer<>Null And (dst.depthbuffer<>Null Or dst=BackBuffer()) And (src.depthbuffer<>dst.depthbuffer)
		If dst=BackBuffer() Or glGetVendor()=VENDOR_ATI
			SetBuffer dst
			If Not Shader_DepthBlit Shader_DepthBlit=LoadShader("abstract::postfilter.vert","abstract::DepthBlit.frag")
			If Not Shader_DepthBlit AppLog "Failed to load shader.",APPLOG_ERROR
			Local shader:TShader=GetShader()
			ClearBuffer BUFFER_DEPTH
			SetShader Shader_DepthBlit
			glEnable GL_DEPTH_TEST
			glDepthMask True
			glColorMask False,False,False,False
			DrawImage src.depthbuffer,0,dst.height(),dst.width(),-dst.height()
			glDepthMask False
			glColorMask True,True,True,True
			glDisable GL_DEPTH_TEST
			SetShader shader
			SetBuffer Buffer
			BindTexture Null,0
		Else
			glBindFramebufferEXT GL_READ_FRAMEBUFFER_EXT,src.framebuffer
			glBindFramebufferEXT GL_DRAW_FRAMEBUFFER_EXT,dst.framebuffer
			glBlitFramebufferEXT 0,0,src.width(),src.height(),0,0,dst.width(),dst.height(),GL_DEPTH_BUFFER_BIT,GL_NEAREST
		EndIf
	EndIf
EndIf
If (BUFFER_COLOR0 & flags)
	'glReadBuffer GL_COLOR_ATTACHMENT0_EXT		
	If dst=BackBuffer()
		If src.colorbuffer[0]<>Null
			SetBuffer(dst)
			Local shader:TShader=GetShader()
			SetShader Null
			temp=src.colorbuffer[0].reference.filter
			If filter=GL_LINEAR src.colorbuffer[0].reference.filter=TEXFILTER_SMOOTH Else src.colorbuffer[0].reference.filter=TEXFILTER_PIXEL
			DrawImage src.colorbuffer[0],0,dst.height(),dst.width(),-dst.height()
			SetShader shader
			src.colorbuffer[0].reference.filter=temp
			'SetBuffer src
			'glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT,0)
			'glDrawBuffer(GL_BACK)
			'SetBuffer Buffer
		EndIf
	Else
		If src=BackBuffer() And dst.colorbuffer[0]<>Null And (src.colorbuffer[0]<>dst.colorbuffer[0])
			glBindFramebufferEXT GL_READ_FRAMEBUFFER_EXT,0
			glBindFramebufferEXT GL_DRAW_FRAMEBUFFER_EXT,dst.framebuffer
			glReadBuffer GL_BACK
			glDrawBuffer GL_COLOR_ATTACHMENT0_EXT
			glBlitFramebufferEXT 0,0,src.width(),src.height(),0,0,dst.width(),dst.height(),GL_COLOR_BUFFER_BIT,filter
		ElseIf src.colorbuffer[0]<>Null And dst.colorbuffer[0]<>Null And (src.colorbuffer[0]<>dst.colorbuffer[0])
			glBindFramebufferEXT GL_READ_FRAMEBUFFER_EXT,src.framebuffer
			glBindFramebufferEXT GL_DRAW_FRAMEBUFFER_EXT,dst.framebuffer
			glReadBuffer GL_COLOR_ATTACHMENT0_EXT
			glDrawBuffer GL_COLOR_ATTACHMENT0_EXT
			glBlitFramebufferEXT 0,0,src.width(),src.height(),0,0,dst.width(),dst.height(),GL_COLOR_BUFFER_BIT,filter
		EndIf
	EndIf
EndIf
If src<>BackBuffer() And dst<>BackBuffer()
	If (BUFFER_COLOR1 & flags)
		If dst=BackBuffer() Return
		If src.colorbuffer[1]<>Null And dst.colorbuffer[1]<>Null And (src.colorbuffer[1]<>dst.colorbuffer[1])
			glBindFramebufferEXT GL_READ_FRAMEBUFFER_EXT,src.framebuffer
			glBindFramebufferEXT GL_DRAW_FRAMEBUFFER_EXT,dst.framebuffer
			glReadBuffer GL_COLOR_ATTACHMENT1_EXT
			glDrawBuffer GL_COLOR_ATTACHMENT1_EXT
			glBlitFramebufferEXT 0,0,src.width(),src.height(),0,0,dst.width(),dst.height(),GL_COLOR_BUFFER_BIT,filter
		EndIf
	EndIf
	If (BUFFER_COLOR2 & flags)
		If dst=BackBuffer() Return
		If src.colorbuffer[2]<>Null And dst.colorbuffer[2]<>Null And (src.colorbuffer[2]<>dst.colorbuffer[2])
			glBindFramebufferEXT GL_READ_FRAMEBUFFER_EXT,src.framebuffer
			glBindFramebufferEXT GL_DRAW_FRAMEBUFFER_EXT,dst.framebuffer
			glReadBuffer GL_COLOR_ATTACHMENT2_EXT
			glDrawBuffer GL_COLOR_ATTACHMENT2_EXT
			glBlitFramebufferEXT 0,0,src.width(),src.height(),0,0,dst.width(),dst.height(),GL_COLOR_BUFFER_BIT,filter
		EndIf
	EndIf
	If (BUFFER_COLOR3 & flags)
		If dst=BackBuffer() Return
		If src.colorbuffer[3]<>Null And dst.colorbuffer[3]<>Null And (src.colorbuffer[3]<>dst.colorbuffer[3])
			glBindFramebufferEXT GL_READ_FRAMEBUFFER_EXT,src.framebuffer
			glBindFramebufferEXT GL_DRAW_FRAMEBUFFER_EXT,dst.framebuffer
			glReadBuffer GL_COLOR_ATTACHMENT3_EXT
			glDrawBuffer GL_COLOR_ATTACHMENT3_EXT
			glBlitFramebufferEXT 0,0,src.width(),src.height(),0,0,dst.width(),dst.height(),GL_COLOR_BUFFER_BIT,filter
		EndIf
	EndIf
EndIf
SetBuffer(buffer)
EndFunction

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...