Implemented CopyScreen method

This commit is contained in:
Stephan Sundermann committed 2012-03-18 23:18:16 +01:00
1 parent 7b06ac12bd
commit 046fe6782f
1 file changed
+61 -30
+61 -30
View File
@@ -231,6 +231,8 @@ namespace Vocaluxe.Lib.Draw
}
}
#endregion form events
#region resize
/// <summary>
/// Resizes the viewport
/// </summary>
@@ -325,6 +327,7 @@ namespace Vocaluxe.Lib.Draw
CConfig.SaveConfig();
}
#endregion resize
#region mouse event handlers
private void OnMouseMove(object sender, MouseEventArgs e)
@@ -385,7 +388,7 @@ namespace Vocaluxe.Lib.Draw
#endregion keyboard event handlers
#region implementation
#region main stuff
/// <summary>
/// Inits the Device
/// </summary>
@@ -628,6 +631,7 @@ namespace Vocaluxe.Lib.Draw
_VerticesRotationMatrices.Clear();
}
}
#endregion main stuff
#region Basic Draw Methods
@@ -640,24 +644,51 @@ namespace Vocaluxe.Lib.Draw
}
/// <summary>
/// Not implemented yet
/// </summary>
/// <returns></returns>
/// Copies the current frame into a texture
/// <returns>A texture holding the current frame</returns>
public STexture CopyScreen()
{
//FIXME
STexture texture = new STexture(-1);
Surface backbufferSurface = _Device.GetBackBuffer(0, 0);
Texture tex = new Texture(_Device, _PresentParameters.BackBufferWidth, _PresentParameters.BackBufferHeight, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed);
Surface textureSurface = tex.GetSurfaceLevel(0);
Surface.FromSurface(textureSurface, backbufferSurface, Filter.Default, 0);
backbufferSurface.Dispose();
_D3DTextures.Add(tex);
texture.color = new SColorF(1f, 1f, 1f, 1f);
texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f);
texture.width = w;
texture.height = h;
texture.w2 = NextPowerOfTwo(texture.width);
texture.h2 = NextPowerOfTwo(texture.height);
texture.index = _D3DTextures.Count - 1;
lock (MutexTexture)
{
_Textures[texture.index] = texture;
}
return texture;
}
/// <summary>
/// Not implemented yet
/// Copies the current frame into a texture
/// </summary>
/// <returns></returns>
/// <param name="Texture">The texture in which the frame is copied to</param>
public void CopyScreen(ref STexture Texture)
{
//FIXME
return;
if (!_TextureExists(ref Texture) || (Texture.width != GetScreenWidth()) || (Texture.height != GetScreenHeight()))
{
RemoveTexture(ref Texture);
Texture = CopyScreen();
}
else
{
Surface backbufferSurface = _Device.GetBackBuffer(0, 0);
Surface textureSurface = _D3DTextures[Texture.index].GetSurfaceLevel(0);
Surface.FromSurface(textureSurface, backbufferSurface, Filter.Default, 0);
}
}
/// <summary>
@@ -733,18 +764,11 @@ namespace Vocaluxe.Lib.Draw
/// <param name="rect">The coordinates in a SRectF struct</param>
public void DrawColor(SColorF color, SRectF rect)
{
//blankMap = new Bitmap(1, 1);
//Graphics g = Graphics.FromImage(blankMap);
//g.Clear(Color.White);
//g.Dispose();
//blankTexture = AddTexture(blankMap);
//blankMap.Dispose();
DrawTexture(blankTexture, rect, color);
//RemoveTexture(ref blankTexture);
}
#endregion Basic Draw Methods
#region Textures
#region adding
/// <summary>
/// Adds a texture and stores it in the VRam
@@ -771,17 +795,6 @@ namespace Vocaluxe.Lib.Draw
return new STexture(-1);
}
/// <summary>
/// Calculates the next power of two
/// </summary>
/// <param name="n">The value of which the next power of two will be calculated</param>
/// <returns>The next power of two</returns>
private static float NextPowerOfTwo(float n)
{
if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive.");
return (float)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
}
/// <summary>
/// Adds a texture and stores it in the Vram
/// </summary>
@@ -959,7 +972,9 @@ namespace Vocaluxe.Lib.Draw
}
return texture;
}
#endregion adding
#region updating
/// <summary>
/// Updates the data of a texture
/// </summary>
@@ -1001,6 +1016,7 @@ namespace Vocaluxe.Lib.Draw
else
return false;
}
#endregion updating
/// <summary>
/// Checks if a texture exists
@@ -1042,6 +1058,7 @@ namespace Vocaluxe.Lib.Draw
}
}
#region drawing
/// <summary>
/// Draws a texture
/// </summary>
@@ -1316,6 +1333,7 @@ namespace Vocaluxe.Lib.Draw
}
}
}
#endregion drawing
private void CheckQueque()
{
@@ -1369,6 +1387,20 @@ namespace Vocaluxe.Lib.Draw
{
return _Textures.Count;
}
#endregion Textures
#endregion implementation
#region utility
/// <summary>
/// Calculates the next power of two
/// </summary>
/// <param name="n">The value of which the next power of two will be calculated</param>
/// <returns>The next power of two</returns>
private static float NextPowerOfTwo(float n)
{
if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive.");
return (float)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
}
private Matrix CalculateRotationMatrix(float rot, float rx1, float rx2, float ry1, float ry2)
{
@@ -1392,8 +1424,7 @@ namespace Vocaluxe.Lib.Draw
}
return originTranslation;
}
#endregion Textures
#endregion implementation
#endregion utility
#region TexturedColoredVertex
public struct TexturedColoredVertex