浏览代码

Enable GrabPixmap for GLMax2D+RenderTarget

Ronny Otto 2 年之前
父节点
当前提交
347ddf78e8
共有 2 个文件被更改,包括 13 次插入72 次删除
  1. 13 9
      glmax2d.mod/glmax2d.bmx
  2. 0 63
      glmax2d.mod/rectnode.bmx

+ 13 - 9
glmax2d.mod/glmax2d.bmx

@@ -102,7 +102,7 @@ Function DeleteTex( name:Int,seq:Int )
 End Function
 
 Function CreateTex:Int( width:Int,height:Int,flags:Int,pixmap:TPixmap )
-	If pixmap.dds_fmt<>0 Return pixmap.tex_name ' if dds texture already exists
+	If pixmap.dds_fmt<>0 Then Return pixmap.tex_name ' if dds texture already exists
 	
 	'alloc new tex
 	Local name:Int
@@ -188,8 +188,8 @@ Function AdjustTexSize( width:Int Var,height:Int Var )
 		glGetTexLevelParameteriv GL_PROXY_TEXTURE_2D,0,GL_TEXTURE_WIDTH,Varptr t
 		If t Then Return
 		If width=1 And height=1 Then RuntimeError "Unable to calculate tex size"
-		If width>1 Then width:/2
-		If height>1 Then height:/2
+		If width>1 Then width :/ 2
+		If height>1 Then height :/ 2
 	Forever
 End Function
 
@@ -277,7 +277,7 @@ Type TGLImageFrame Extends TImageFrame
 		Local v0:Float=sy * vscale
 		Local u1:Float=(sx+sw) * uscale
 		Local v1:Float=(sy+sh) * vscale
-		
+
 		EnableTex name
 		glBegin GL_QUADS
 		glTexCoord2f u0,v0
@@ -370,7 +370,7 @@ Type TGLRenderImageFrame Extends TGLImageFrame
 		glEnd
 	EndMethod
 	
-	Function Create:TGLRenderImageFrame(width:UInt, height:UInt, flags:Int)		
+	Function Create:TGLRenderImageFrame(width:UInt, height:UInt, flags:Int)
 		' Need this to enable frame buffer objects - glGenFramebuffers
 		Global GlewIsInitialised:Int = False
 		If Not GlewIsInitialised
@@ -425,7 +425,7 @@ Private
 	Method Delete()
 		glDeleteFramebuffers(1, Varptr FBO) ' gl ignores 0
 	EndMethod
-	
+
 	Method New()
 	EndMethod
 EndType
@@ -670,7 +670,11 @@ Type TGLMax2DDriver Extends TMax2DDriver
 		'backbuffers require a complete transparent pixmap to start with.
 		p.ClearPixels(0)
 		
-		glReadPixels x,GraphicsHeight()-h-y,w,h,GL_RGBA,GL_UNSIGNED_BYTE,p.pixels
+		If _CurrentRenderImageFrame and _CurrentRenderImageFrame <> _BackbufferRenderImageFrame
+			glReadPixels(x, _CurrentRenderImageFrame.height - h - y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, p.pixels)
+		Else
+			glReadPixels(x, _BackbufferRenderImageFrame.height - h - y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, p.pixels)
+		EndIf
 		p=YFlipPixmap( p )
 		SetBlend blend
 		Return p
@@ -682,7 +686,7 @@ Type TGLMax2DDriver Extends TMax2DDriver
 		glOrtho 0,width,height,0,-1,1
 		glMatrixMode GL_MODELVIEW
 	End Method
-	
+
 	Method CreateRenderImageFrame:TImageFrame(width:UInt, height:UInt, flags:Int) Override
 		Return TGLRenderImageFrame.Create(width, height, flags)
 	EndMethod
@@ -718,7 +722,7 @@ Private
 
 	Method SetScissor(x:Int, y:Int, w:Int, h:Int)
 		Local ri:TImageFrame = _CurrentRenderImageFrame
-		If x = 0  And y = 0 And w = _CurrentRenderImageFrame.width And h = _CurrentRenderImageFrame.height
+		If x = 0 And y = 0 And w = _CurrentRenderImageFrame.width And h = _CurrentRenderImageFrame.height
 			glDisable(GL_SCISSOR_TEST)
 		Else
 			glEnable(GL_SCISSOR_TEST)

+ 0 - 63
glmax2d.mod/rectnode.bmx

@@ -1,63 +0,0 @@
-
-Strict
-
-Rem
-Simple rect packer
-Based on lightmap packing code by blackpawn
-To remove a rect, set its kind to HOLLOW and optimize the root rect
-End Rem
-
-Type TRectNode
-
-	Const NODE=0,SOLID=1,HOLLOW=-1
-
-	Field x,y,width,height,kind
-	Field child0:TRectNode,child1:TRectNode
-	
-	Method Insert:TRectNode( w,h )
-		Local r:TRectNode
-		If kind=NODE
-			r=child0.Insert( w,h )
-			If r Return r
-			Return child1.Insert( w,h )
-		EndIf
-		If kind=SOLID Return Null
-		If w>width Or h>height Return Null
-		If w=width And h=height
-			kind=SOLID
-			Return Self
-		EndIf
-		kind=NODE
-		Local dw=width-w
-		Local dh=height-h
-		If dw>dh
-			child0=Create( x,y,w,height )
-			child1=Create( x+w,y,dw,height )
-		Else
-			child0=Create( x,y,width,h )
-			child1=Create( x,y+h,width,dh )
-		EndIf
-		Return child0.Insert( w,h )
-	End Method
-	
-	Method Optimize()
-		If kind<>NODE Return
-		child0.Optimize
-		child1.Optimize
-		If child0.kind<>HOLLOW Or child1.kind<>HOLLOW Return
-		kind=HOLLOW
-		child0=Null
-		child1=Null
-	End Method
-	
-	Function Create:TRectNode( x,y,w,h )
-		Local r:TRectNode=New TRectNode
-		r.x=x
-		r.y=y
-		r.width=w
-		r.height=h
-		r.kind=HOLLOW
-		Return r
-	End Function
-	
-End Type