[Agate-svn-commit] SF.net SVN: agate:[1525] trunk
Status: Alpha
Brought to you by:
kanato
From: <ka...@us...> - 2014-09-14 03:19:37
|
Revision: 1525 http://sourceforge.net/p/agate/code/1525 Author: kanato Date: 2014-09-14 03:19:31 +0000 (Sun, 14 Sep 2014) Log Message: ----------- Implement FrameBuffers for WP8 projects. Modified Paths: -------------- trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/FrameBufferSurface.cs trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Surface.cs trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj trunk/AgateLib.Tests/Tests.WinForms/AgateLib.Tests.WinForms.csproj trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/MultipleWindows/MultipleWindowTest.cs Added Paths: ----------- trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/MultipleFramebufferTest.cs Removed Paths: ------------- trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/MultipleFramebufferTest.cs Modified: trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/FrameBufferSurface.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/FrameBufferSurface.cs 2014-09-14 00:09:08 UTC (rev 1524) +++ trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/FrameBufferSurface.cs 2014-09-14 03:19:31 UTC (rev 1525) @@ -28,48 +28,39 @@ namespace AgateLib.Platform.WindowsStore.DisplayImplementation { - class FrameBufferSurface : SDX_FrameBuffer + class FrameBufferSurface : SDX_FrameBuffer { Size mSize; SDX_Display mDisplay; D3DDevice mDevice; SDX_Surface mAgateSurface; Texture2D mTexture; - SharpDX.DXGI.Surface mRenderTarget; + RenderTargetView mRenderTargetView; bool mHasDepth; bool mHasStencil; - public FrameBufferSurface(Size size) : base(new NativeCoordinates()) + public FrameBufferSurface(Size size) + : base(new NativeCoordinates()) { - throw new NotImplementedException(); - //mDisplay = Display.Impl as SDX_Display; - //mDevice = mDisplay.D3D_Device; - //mSize = size; + mDisplay = Display.Impl as SDX_Display; + mDevice = mDisplay.D3D_Device; + mSize = size; - //try - //{ - // mTexture = new Texture2D(mDevice.Device, mSize.Width, mSize.Height, - // 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default); - //} - //catch - //{ - // Size newSize = SDX_Surface.NextPowerOfTwo(mSize); + mAgateSurface = new SDX_Surface(mSize); + mTexture = mAgateSurface.D3dTexture; - // mTexture = new Texture(mDevice.Device, newSize.Width, newSize.Height, - // 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default); - //} + var rtvdesc = new RenderTargetViewDescription + { + Format = mTexture.Description.Format, + Dimension = RenderTargetViewDimension.Texture2D, + }; - //mRenderTarget = mTexture.GetSurfaceLevel(0); - - //mAgateSurface = new SDX_Surface(new AgateLib.Utility.Ref<Texture>(mTexture), - // new Rectangle(Point.Empty, Size)); - - //SetHasDepthStencil( + mRenderTargetView = new RenderTargetView(mDevice.Device, mTexture, rtvdesc); } public override void Dispose() { - mRenderTarget.Dispose(); + mRenderTargetView.Dispose(); } public override AgateLib.Geometry.Size Size @@ -79,13 +70,11 @@ public override void BeginRender() { - //mDevice.Device.SetRenderTarget(0, mRenderTarget); - //mDevice.Device.BeginScene(); + mDevice.DeviceContext.OutputMerger.SetRenderTargets(mRenderTargetView); } public override void EndRender() { - //mDevice.Device.EndScene(); } public override bool CanAccessRenderTarget Modified: trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Surface.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Surface.cs 2014-09-14 00:09:08 UTC (rev 1524) +++ trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Surface.cs 2014-09-14 03:19:31 UTC (rev 1525) @@ -41,7 +41,6 @@ { public class SDX_Surface : SurfaceImpl { - SDX_Display mDisplay; D3DDevice mDevice { get { return mDisplay.D3D_Device; } } Modified: trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj 2014-09-14 00:09:08 UTC (rev 1524) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/AgateLib.Tests.Portable.csproj 2014-09-14 03:19:31 UTC (rev 1525) @@ -51,6 +51,7 @@ <Compile Include="DisplayTests\ColorTest.cs" /> <Compile Include="DisplayTests\CoordinateSystem.cs" /> <Compile Include="DisplayTests\Interpolation.cs" /> + <Compile Include="DisplayTests\MultipleFramebufferTest.cs" /> <Compile Include="DisplayTests\ParticleTests.cs" /> <Compile Include="DisplayTests\RotatingSpriteTester.cs" /> <Compile Include="DisplayTests\Tiling.cs" /> Copied: trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/MultipleFramebufferTest.cs (from rev 1523, trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/MultipleFramebufferTest.cs) =================================================================== --- trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/MultipleFramebufferTest.cs (rev 0) +++ trunk/AgateLib.Tests/AgateLib.Tests.Portable/DisplayTests/MultipleFramebufferTest.cs 2014-09-14 03:19:31 UTC (rev 1525) @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib; +using AgateLib.DisplayLib; +using AgateLib.Geometry; +using AgateLib.InputLib; +using AgateLib.InputLib.Legacy; + +namespace AgateLib.Testing.DisplayTests +{ + class MultipleFramebufferTest : ISerialModelTest + { + List<Surface> mRegionColors = new List<Surface>(); + + public string Name + { + get { return "Multiple Framebuffer Test"; } + } + + public string Category + { + get { return "Display"; } + } + + List<Surface> tests = new List<Surface>(); + bool done; + Font font; + Surface mySurface; + + public void EntryPoint() + { + font = Assets.Fonts.AgateSans; + font.Size = 14; + + Mouse.MouseDown += Mouse_MouseDown; + + mySurface = new Surface("9ball.png"); + + while (Display.CurrentWindow.IsClosed == false && done == false) + { + Display.RenderTarget = Display.CurrentWindow.FrameBuffer; + Display.BeginFrame(); + Display.Clear(Color.Gray); + + font.Color = Color.White; + font.DisplayAlignment = OriginAlignment.TopLeft; + font.DrawText("Click or tap to create another frame buffer."); + + int y = font.FontHeight; + int x = 10; + foreach (var surf in tests) + { + surf.Draw(x, y); + y += surf.DisplayHeight + 10; + + if (y + 42 >= Display.CurrentWindow.Height) + { + y = font.FontHeight; + x += 42; + } + } + + Display.EndFrame(); + Core.KeepAlive(); + } + } + + void Mouse_MouseDown(InputEventArgs e) + { + if (e.MouseButtons == MouseButton.Primary) + CreateTests(); + else + done = true; + } + + int hueAngle = 0; + + private void CreateTests() + { + const int angleIncrement = 373 / 8; + font.Color = Color.Black; + font.DisplayAlignment = OriginAlignment.CenterRight; + + FrameBuffer frame = new FrameBuffer(32, 32); + var clr = Color.FromHsv(hueAngle, 1, 1); + + Display.RenderTarget = frame; + Display.BeginFrame(); + Display.Clear(); + mySurface.Draw(new Rectangle(Point.Empty, frame.Size)); + Display.FillRect(new Rectangle(0, 0, 8, 32), clr); + + var pt = new Point(31, 16); + string text = tests.Count.ToString(); + + font.Color = Color.Black; + font.DrawText(pt.X - 1, pt.Y, text); + font.DrawText(pt.X + 1, pt.Y, text); + font.DrawText(pt.X, pt.Y - 1, text); + font.DrawText(pt.X, pt.Y + 1, text); + + font.Color = Color.White; + font.DrawText(pt.X, pt.Y, text); + + Display.EndFrame(); + tests.Add(frame.RenderTarget); + + hueAngle += angleIncrement; + } + + public void ModifyModelParameters(ApplicationModels.SerialModelParameters parameters) + { + } + } +} Modified: trunk/AgateLib.Tests/Tests.WinForms/AgateLib.Tests.WinForms.csproj =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/AgateLib.Tests.WinForms.csproj 2014-09-14 00:09:08 UTC (rev 1524) +++ trunk/AgateLib.Tests/Tests.WinForms/AgateLib.Tests.WinForms.csproj 2014-09-14 03:19:31 UTC (rev 1525) @@ -147,7 +147,6 @@ </Compile> <Compile Include="DisplayTests\LargeImage.cs" /> <Compile Include="DisplayTests\DisplayWindowEvents.cs" /> - <Compile Include="DisplayTests\MultipleFramebufferTest.cs" /> <Compile Include="DisplayTests\PixelBufferMask.cs" /> <Compile Include="DisplayTests\Prerendered.cs" /> <Compile Include="DisplayTests\RenderTargetContinuous.cs" /> Deleted: trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/MultipleFramebufferTest.cs =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/MultipleFramebufferTest.cs 2014-09-14 00:09:08 UTC (rev 1524) +++ trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/MultipleFramebufferTest.cs 2014-09-14 03:19:31 UTC (rev 1525) @@ -1,122 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using AgateLib; -using AgateLib.DisplayLib; -using AgateLib.Geometry; -using AgateLib.InputLib; -using AgateLib.Platform.WinForms; -using AgateLib.Platform.WinForms.Resources; -using AgateLib.Platform.WinForms.ApplicationModels; -using AgateLib.InputLib.Legacy; - -namespace AgateLib.Testing.DisplayTests -{ - class MultipleFramebufferTest : IAgateTest - { - List<Surface> mRegionColors = new List<Surface>(); - - public string Name - { - get { return "Multiple Framebuffer Test"; } - } - - public string Category - { - get { return "Display"; } - } - - List<Surface> tests = new List<Surface>(); - bool done; - Font font; - - public void Main(string[] args) - { - new PassiveModel(args).Run( () => - { - DisplayWindow wind = DisplayWindow.CreateWindowed("Multiple Framebuffer Test", - 640, 480); - - font = Assets.Fonts.AgateSans; - - CreateTests(); - - Keyboard.KeyDown += new InputEventHandler(Keyboard_KeyDown); - - while (wind.IsClosed == false && done == false) - { - Display.RenderTarget = wind.FrameBuffer; - Display.BeginFrame(); - Display.Clear(Color.Gray); - - font.Color = Color.White; - font.DisplayAlignment = OriginAlignment.TopLeft; - font.DrawText("Press space to create another frame buffer."); - - int y = font.FontHeight; - int x = 10; - foreach (var surf in tests) - { - surf.Draw(x, y); - y += surf.DisplayHeight + 10; - - if (y + 42 >= wind.Height) - { - y = font.FontHeight; - x += 42; - } - } - - Display.EndFrame(); - Core.KeepAlive(); - } - }); - } - - void Keyboard_KeyDown(InputEventArgs e) - { - if (e.KeyCode == KeyCode.Escape) - done = true; - - if (e.KeyCode == KeyCode.Space) - CreateTests(); - } - - int hueAngle = 0; - private void CreateTests() - { - const int angleIncrement = 373 / 8; - font.Color = Color.Black; - font.DisplayAlignment = OriginAlignment.CenterRight; - Surface mySurface = new Surface("jellybean.png"); - - FrameBuffer frame = new FrameBuffer(32, 32); - var clr = Color.FromHsv(hueAngle, 1, 1); - - Display.RenderTarget = frame; - Display.BeginFrame(); - Display.Clear(); - mySurface.Draw(); - Display.FillRect(new Rectangle(0, 0, 8, 32), clr); - - var pt = new Point(31, 16); - string text = tests.Count.ToString(); - - font.Color = Color.Black; - font.DrawText(pt.X - 1, pt.Y, text); - font.DrawText(pt.X + 1, pt.Y, text); - font.DrawText(pt.X, pt.Y - 1, text); - font.DrawText(pt.X, pt.Y + 1, text); - - font.Color = Color.White; - font.DrawText(pt.X, pt.Y, text); - - Display.EndFrame(); - tests.Add(frame.RenderTarget); - frame.RenderTarget.SaveTo("test.png", ImageFileFormat.Png); - - hueAngle += angleIncrement; - } - } -} Modified: trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/MultipleWindows/MultipleWindowTest.cs =================================================================== --- trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/MultipleWindows/MultipleWindowTest.cs 2014-09-14 00:09:08 UTC (rev 1524) +++ trunk/AgateLib.Tests/Tests.WinForms/DisplayTests/MultipleWindows/MultipleWindowTest.cs 2014-09-14 03:19:31 UTC (rev 1525) @@ -10,6 +10,7 @@ using AgateLib.Platform.WinForms; using AgateLib.Platform.WinForms.Resources; using AgateLib.Platform.WinForms.ApplicationModels; +using AgateLib.ApplicationModels; namespace AgateLib.Testing.DisplayTests.MultipleWindows { @@ -31,72 +32,81 @@ public void Main(string[] args) { - new PassiveModel(args).Run( () => + var parameters = new PassiveModelParameters(args); + parameters.AssetLocations.Path = "Assets"; + + new PassiveModel(parameters).Run( () => { - MultipleRenderTargetExample myForm = new MultipleRenderTargetExample(); - myForm.Show(); + EntryPoint(); + }); + } - // create three display windows - DisplayWindow wnd_1 = DisplayWindow.CreateFromControl(myForm.pictureBox1); - DisplayWindow wnd_2 = DisplayWindow.CreateFromControl(myForm.pictureBox2); - DisplayWindow wnd_3 = DisplayWindow.CreateFromControl(myForm.pictureBox3); + private void EntryPoint() + { + MultipleRenderTargetExample myForm = new MultipleRenderTargetExample(); + myForm.Show(); - myForm.pictureBox3.Resize += new EventHandler(wnd_3_Resize); + // create three display windows + DisplayWindow wnd_1 = DisplayWindow.CreateFromControl(myForm.pictureBox1); + DisplayWindow wnd_2 = DisplayWindow.CreateFromControl(myForm.pictureBox2); + DisplayWindow wnd_3 = DisplayWindow.CreateFromControl(myForm.pictureBox3); - // this is the code that will be called when the button is pressed - myForm.btnDraw.Click += new EventHandler(btnDraw_Click); - myForm.btnClearSurface.Click += new EventHandler(btnClear_Click); - myForm.btnDrawText.Click += new EventHandler(btnDrawText_Click); - Surface image1 = new Surface("jellybean.png"); - Surface image2 = new Surface("9ball.png"); - image1.DisplayWidth = 40; - image1.DisplayHeight = (int)(image1.DisplayWidth * image1.SurfaceHeight / (double)image1.SurfaceWidth); - image2.DisplayWidth = 40; - image2.DisplayHeight = (int)(image2.DisplayWidth * image2.SurfaceHeight / (double)image2.SurfaceWidth); + myForm.pictureBox3.Resize += new EventHandler(wnd_3_Resize); - double time = 0; + // this is the code that will be called when the button is pressed + myForm.btnDraw.Click += new EventHandler(btnDraw_Click); + myForm.btnClearSurface.Click += new EventHandler(btnClear_Click); + myForm.btnDrawText.Click += new EventHandler(btnDrawText_Click); + Surface image1 = new Surface("jellybean.png"); + Surface image2 = new Surface("9ball.png"); + image1.DisplayWidth = 40; + image1.DisplayHeight = (int)(image1.DisplayWidth * image1.SurfaceHeight / (double)image1.SurfaceWidth); + image2.DisplayWidth = 40; + image2.DisplayHeight = (int)(image2.DisplayWidth * image2.SurfaceHeight / (double)image2.SurfaceWidth); - frameBuffer = new FrameBuffer(wnd_3.Width, wnd_3.Height); + double time = 0; - while (myForm.Visible) - { - // Render targets must be set before the call to BeginFrame, - // and may not be changed between BeginFrame and EndFrame. - // Use the FrameBuffer property of each DisplayWindow object - // to set the Display.RenderTarget value. - Display.RenderTarget = wnd_1.FrameBuffer; + frameBuffer = new FrameBuffer(wnd_3.Width, wnd_3.Height); + ClearFrameBuffer(); - Display.BeginFrame(); - Display.Clear(Color.Red); - Display.FillRect(new Rectangle(20, 20, 40, 30), Color.Blue); - image1.Draw(120 + (int)(30 * Math.Sin(time)), 20); + while (myForm.Visible) + { + // Render targets must be set before the call to BeginFrame, + // and may not be changed between BeginFrame and EndFrame. + // Use the FrameBuffer property of each DisplayWindow object + // to set the Display.RenderTarget value. + Display.RenderTarget = wnd_1.FrameBuffer; - Display.EndFrame(); + Display.BeginFrame(); + Display.Clear(Color.Red); + Display.FillRect(new Rectangle(20, 20, 40, 30), Color.Blue); + image1.Draw(120 + (int)(30 * Math.Sin(time)), 20); - // now do the second window. - Display.RenderTarget = wnd_2.FrameBuffer; + Display.EndFrame(); - Display.BeginFrame(); - Display.Clear(Color.Green); - Display.FillRect(new Rectangle(20, 20, 40, 30), Color.Yellow); - image2.Draw(120 + (int)(30 * Math.Cos(time)), 20); + // now do the second window. + Display.RenderTarget = wnd_2.FrameBuffer; - Display.EndFrame(); + Display.BeginFrame(); + Display.Clear(Color.Green); + Display.FillRect(new Rectangle(20, 20, 40, 30), Color.Yellow); + image2.Draw(120 + (int)(30 * Math.Cos(time)), 20); - // draw the third window from the surface - Display.RenderTarget = wnd_3.FrameBuffer; + Display.EndFrame(); - surf = frameBuffer.RenderTarget; + // draw the third window from the surface + Display.RenderTarget = wnd_3.FrameBuffer; - Display.BeginFrame(); - Display.Clear(Color.Gray); - surf.Draw(0, 0); - Display.EndFrame(); + surf = frameBuffer.RenderTarget; - Core.KeepAlive(); - time = Timing.TotalSeconds; - } - }); + Display.BeginFrame(); + Display.Clear(Color.Gray); + surf.Draw(0, 0); + Display.EndFrame(); + + Core.KeepAlive(); + time = Timing.TotalSeconds; + } } void btnDrawText_Click(object sender, EventArgs e) @@ -142,6 +152,11 @@ void btnClear_Click(object sender, EventArgs e) { + ClearFrameBuffer(); + } + + private void ClearFrameBuffer() + { Display.RenderTarget = frameBuffer; Display.BeginFrame(); Display.Clear(0, 0, 0, 0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |