Ronny Otto 2 年 前
コミット
1a77c24dbd
3 ファイル変更20 行追加24 行削除
  1. 16 21
      d3d9max2d.mod/d3d9max2d.bmx
  2. 1 1
      max2d.mod/driver.bmx
  3. 3 2
      max2d.mod/image.bmx

+ 16 - 21
d3d9max2d.mod/d3d9max2d.bmx

@@ -292,10 +292,6 @@ Type TD3D9RenderImageFrame Extends TD3D9ImageFrame
 
 		Return RenderImage
 	End Function
-	
-	Method DestroyRenderImage()
-		ReleaseNow()
-	End Method
 
 	Method OnDeviceLost()
 		Local BackBuffer:TD3D9RenderImageFrame = _BackBufferRenderImageFrame
@@ -311,13 +307,13 @@ Type TD3D9RenderImageFrame Extends TD3D9ImageFrame
 		' dont re-create until the device is ready
 		If _d3dDev.TestCooperativeLevel() = 0
 			If(_stagingPixmap)
-				RecreateFromPixmap()
+				LoadFromPixmap(_stagingPixmap)
+				_stagingPixmap = Null
 			EndIf
 		EndIf
 	End Method
 
-Private
-	Method RecreateFromPixmap()
+	Method LoadFromPixmap(pixmap:TPixmap) override
 		If _d3ddev.CreateTexture(_width, _height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, _texture, Null) < 0
 			Throw "Failed to create render target"
 			Return
@@ -329,37 +325,36 @@ Private
 			Return
 		EndIf
 
-		Local StagingSurface:IDirect3DSurface9
-		If _d3ddev.CreateOffscreenPlainSurface(_width, _height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, StagingSurface, Null) < 0
-			Throw "Failed to create a staging surface"
+		Local replacementSurface:IDirect3DSurface9
+		If _d3ddev.CreateOffscreenPlainSurface(_width, _height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, replacementSurface, Null) < 0
+			Throw "Failed to create a replacement surface"
 			ReleaseNow()
 			Return
 		EndIf
 
 		Local lockedrect:D3DLOCKED_RECT = New D3DLOCKED_RECT
-		If StagingSurface.LockRect(lockedrect, Null, 0) < 0
-			Throw "Failed to lock the staging surface"
+		If replacementSurface.LockRect(lockedrect, Null, 0) < 0
+			Throw "Failed to lock the replacement surface"
 			ReleaseNow()
-			StagingSurface.Release_()
+			replacementSurface.Release_()
 			Return
 		EndIf
 
 		For Local y:Int = 0 Until _height
-			Local srcptr:Byte Ptr = _stagingPixmap.pixels + y * _stagingPixmap.pitch
+			Local srcptr:Byte Ptr = pixmap.pixels + y * pixmap.pitch
 			Local dstptr:Byte Ptr = lockedrect.pBits + y * lockedrect.Pitch
-			MemCopy dstptr, srcptr, Size_T(_stagingPixmap.width * 4)
+			MemCopy dstptr, srcptr, Size_T(pixmap.width * 4)
 		Next
-		StagingSurface.UnlockRect()
+		replacementSurface.UnlockRect()
 
-		If _d3ddev.UpdateSurface(StagingSurface, Null, _surface, Null) < 0
-			Throw "Failed to copy the staging surface texture data to the render target"
+		If _d3ddev.UpdateSurface(replacementSurface, Null, _surface, Null) < 0
+			Throw "Failed to copy the replacement surface texture data to the render target"
 			ReleaseNow()
-			StagingSurface.Release_()
+			replacementSurface.Release_()
 			Return
 		EndIf
 
-		StagingSurface.Release_()
-		_stagingPixmap = Null
+		replacementSurface.Release_()
 	End Method
 	
 	Method RenderTargetToPixmap:TPixmap()	

+ 1 - 1
max2d.mod/driver.bmx

@@ -32,7 +32,7 @@ Type TMax2DDriver Extends TGraphicsDriver
 	'Backend specific!
 	'implement this function in each TMax2D-extending type (OpenGL, DX, ..)
 	Method CreateRenderImageContext:Object(g:TGraphics)
-		Throw "Feature ~qRender2Texture~q not yet implemented in this graphics driver (" + ToString() + ")." 
+		Throw "Feature ~qRender2Texture~q not yet implemented in this graphics driver (" + _max2dDriver.ToString() + ")." 
 		Return Null
 	End Method
 

+ 3 - 2
max2d.mod/image.bmx

@@ -31,7 +31,8 @@ Type TImage
 	Method Clear(r:UInt, g:UInt, b:UInt, a:Float = 1.0, frameIndex:Int = -1)
 		Local clearColor:Int = Int(int(255*a) * $1000000) + Int(r * $10000) + Int(g * $100) + b
 		If frameIndex < 0
-			For Local p:TPixmap = EachIn pixmaps
+			For Local i:Int = 0 until pixmaps.length
+				Local p:TPixmap = Lock(i, True, True)
 				p.ClearPixels(clearColor)
 			Next
 		Else
@@ -130,7 +131,7 @@ Type TRenderImage Extends TImage
 		Return frames[index]
 	End Method
 	
-	Function Create:TRenderImage(width:UInt, height:UInt, flags:Int, MaskRed:Int, MaskGreen:Int, MaskBlue:Int)
+	Function Create:TRenderImage(width:Int, height:Int, flags:Int, MaskRed:Int, MaskGreen:Int, MaskBlue:Int)
 		Local t:TRenderImage = New TRenderImage
 		t.width = width
 		t.height = height