prepared new sample project: Primitives (currently XNA used for rendering)

This commit is contained in:
Glatzemann 2011-11-30 16:03:51 +00:00
parent 91129fcad9
commit 39ad6c969e
9 changed files with 386 additions and 82 deletions

View File

@ -105,6 +105,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RenderTarget", "Samples\Ren
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StencilBuffer", "Samples\StencilBuffer\StencilBuffer.csproj", "{41E6C2CF-51EA-4D8E-96AE-739CA3951766}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Primitives", "Samples\Primitives\Primitives.csproj", "{57097B7A-A283-4409-8AAC-35BF0F458657}"
EndProject
Global
GlobalSection(SubversionScc) = preSolution
Svn-Managed = True
@ -337,6 +339,16 @@ Global
{41E6C2CF-51EA-4D8E-96AE-739CA3951766}.Release|Mixed Platforms.Build.0 = Release|x86
{41E6C2CF-51EA-4D8E-96AE-739CA3951766}.Release|x86.ActiveCfg = Release|x86
{41E6C2CF-51EA-4D8E-96AE-739CA3951766}.Release|x86.Build.0 = Release|x86
{57097B7A-A283-4409-8AAC-35BF0F458657}.Debug|Any CPU.ActiveCfg = Debug|x86
{57097B7A-A283-4409-8AAC-35BF0F458657}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{57097B7A-A283-4409-8AAC-35BF0F458657}.Debug|Mixed Platforms.Build.0 = Debug|x86
{57097B7A-A283-4409-8AAC-35BF0F458657}.Debug|x86.ActiveCfg = Debug|x86
{57097B7A-A283-4409-8AAC-35BF0F458657}.Debug|x86.Build.0 = Debug|x86
{57097B7A-A283-4409-8AAC-35BF0F458657}.Release|Any CPU.ActiveCfg = Release|x86
{57097B7A-A283-4409-8AAC-35BF0F458657}.Release|Mixed Platforms.ActiveCfg = Release|x86
{57097B7A-A283-4409-8AAC-35BF0F458657}.Release|Mixed Platforms.Build.0 = Release|x86
{57097B7A-A283-4409-8AAC-35BF0F458657}.Release|x86.ActiveCfg = Release|x86
{57097B7A-A283-4409-8AAC-35BF0F458657}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -358,6 +370,7 @@ Global
{05233BB1-444F-43F6-A3DF-B82AA924E094} = {9B0DD48B-3912-4F33-AF3F-691AF02B73F9}
{71378D2F-0DCD-4413-8DE0-3FEC0BA04E27} = {9B0DD48B-3912-4F33-AF3F-691AF02B73F9}
{41E6C2CF-51EA-4D8E-96AE-739CA3951766} = {9B0DD48B-3912-4F33-AF3F-691AF02B73F9}
{57097B7A-A283-4409-8AAC-35BF0F458657} = {9B0DD48B-3912-4F33-AF3F-691AF02B73F9}
{E5D69E75-D77C-493F-BBDA-6F9E73B82549} = {7AD65E6B-2A48-437F-81D9-4CA9C9A85C64}
{60D08399-244F-46A3-91F1-4CFD26D961A3} = {7AD65E6B-2A48-437F-81D9-4CA9C9A85C64}
{6A582788-C4D2-410C-96CD-177F75712D65} = {5725DA44-4F5C-4E93-A957-AC5C85603EE9}

View File

@ -115,23 +115,6 @@ namespace ANX.Framework.Graphics
#endregion // Constructor & Destructor
internal void Recreate(PresentationParameters presentationParameters)
{
if (nativeDevice != null)
{
nativeDevice.Dispose();
nativeDevice = null;
}
if (nativeDevice == null)
{
this.currentPresentationParameters = presentationParameters;
nativeDevice = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().CreateGraphicsDevice(presentationParameters);
this.viewport = new Viewport(0, 0, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight);
}
}
#region Clear
public void Clear(Color color)
{
@ -368,14 +351,6 @@ namespace ANX.Framework.Graphics
//TODO: implement
}
internal INativeGraphicsDevice NativeDevice
{
get
{
return this.nativeDevice;
}
}
#region Public Properties
public IndexBuffer Indices
{
@ -610,6 +585,31 @@ namespace ANX.Framework.Graphics
}
}
internal INativeGraphicsDevice NativeDevice
{
get
{
return this.nativeDevice;
}
}
internal void Recreate(PresentationParameters presentationParameters)
{
if (nativeDevice != null)
{
nativeDevice.Dispose();
nativeDevice = null;
}
if (nativeDevice == null)
{
this.currentPresentationParameters = presentationParameters;
nativeDevice = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().CreateGraphicsDevice(presentationParameters);
this.viewport = new Viewport(0, 0, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight);
}
}
protected void raise_Disposing(object sender, EventArgs args)
{
if (Disposing != null)

View File

@ -230,11 +230,80 @@ namespace ANX.Framework.Windows.DX10
#endregion
public void Present()
#region Present
public void Present()
{
swapChain.Present(this.vSyncEnabled ? 1 : 0, PresentFlags.None);
}
#endregion // Present
#region DrawPrimitives & DrawIndexedPrimitives
public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount)
{
SharpDX.Direct3D10.EffectPass pass; SharpDX.Direct3D10.EffectTechnique technique; ShaderBytecode passSignature;
SetupEffectForDraw(out pass, out technique, out passSignature);
SetupInputLayout(passSignature);
// Prepare All the stages
device.InputAssembler.PrimitiveTopology = FormatConverter.Translate(primitiveType);
device.Rasterizer.SetViewports(currentViewport);
device.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
for (int i = 0; i < technique.Description.PassCount; ++i)
{
pass.Apply();
device.DrawIndexed(CalculateVertexCount(primitiveType, primitiveCount), startIndex, baseVertex);
}
}
public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset, int primitiveCount)
{
SharpDX.Direct3D10.EffectPass pass; SharpDX.Direct3D10.EffectTechnique technique; ShaderBytecode passSignature;
SetupEffectForDraw(out pass, out technique, out passSignature);
SetupInputLayout(passSignature);
// Prepare All the stages
device.InputAssembler.PrimitiveTopology = FormatConverter.Translate(primitiveType);
device.Rasterizer.SetViewports(currentViewport);
device.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
for (int i = 0; i < technique.Description.PassCount; ++i)
{
pass.Apply();
device.Draw(primitiveCount, vertexOffset);
}
}
#endregion // DrawPrimitives & DrawIndexedPrimitives
#region DrawInstancedPrimitives
public void DrawInstancedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount, int instanceCount)
{
throw new NotImplementedException();
}
#endregion // DrawInstancedPrimitives
#region DrawUserIndexedPrimitives<T>
public void DrawUserIndexedPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, Array indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration, IndexElementSize indexFormat) where T : struct, IVertexType
{
throw new NotImplementedException();
}
#endregion // DrawUserIndexedPrimitives<T>
#region DrawUserPrimitives<T>
public void DrawUserPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType
{
throw new NotImplementedException();
}
#endregion // DrawUserPrimitives<T>
internal Device NativeDevice
{
get
@ -290,45 +359,6 @@ namespace ANX.Framework.Windows.DX10
}
}
public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount)
{
SharpDX.Direct3D10.EffectPass pass; SharpDX.Direct3D10.EffectTechnique technique; ShaderBytecode passSignature;
SetupEffectForDraw(out pass, out technique, out passSignature);
SetupInputLayout(passSignature);
// Prepare All the stages
device.InputAssembler.PrimitiveTopology = FormatConverter.Translate(primitiveType);
device.Rasterizer.SetViewports(currentViewport);
device.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
for (int i = 0; i < technique.Description.PassCount; ++i)
{
pass.Apply();
device.DrawIndexed(CalculateVertexCount(primitiveType, primitiveCount), startIndex, baseVertex);
}
}
public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset, int primitiveCount)
{
SharpDX.Direct3D10.EffectPass pass; SharpDX.Direct3D10.EffectTechnique technique; ShaderBytecode passSignature;
SetupEffectForDraw(out pass, out technique, out passSignature);
SetupInputLayout(passSignature);
// Prepare All the stages
device.InputAssembler.PrimitiveTopology = FormatConverter.Translate(primitiveType);
device.Rasterizer.SetViewports(currentViewport);
device.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
for (int i = 0; i < technique.Description.PassCount; ++i)
{
pass.Apply();
device.Draw(primitiveCount, vertexOffset);
}
}
public void SetIndexBuffer(IndexBuffer indexBuffer)
{
if (indexBuffer == null)
@ -466,7 +496,6 @@ namespace ANX.Framework.Windows.DX10
}
}
public void GetBackBufferData<T>(Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
{
throw new NotImplementedException();
@ -482,22 +511,6 @@ namespace ANX.Framework.Windows.DX10
throw new NotImplementedException();
}
public void DrawInstancedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount, int instanceCount)
{
throw new NotImplementedException();
}
public void DrawUserIndexedPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, Array indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration, IndexElementSize indexFormat) where T : struct, IVertexType
{
throw new NotImplementedException();
}
public void DrawUserPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType
{
throw new NotImplementedException();
}
public void ResizeBuffers(PresentationParameters presentationParameters)
{
if (swapChain != null)

View File

@ -0,0 +1,94 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
#endregion // Using Statements
namespace Primitives
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
SpriteFont font;
Texture2D bgTexture;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "SampleContent";
}
protected override void Initialize()
{
graphics.PreferredBackBufferWidth = 600;
graphics.PreferredBackBufferHeight = 600;
graphics.ApplyChanges();
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
this.font = Content.Load<SpriteFont>(@"Fonts/Debug");
this.bgTexture = new Texture2D(GraphicsDevice, 1, 1);
this.bgTexture.SetData<Color>(new Color[] { Color.White });
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
Keyboard.GetState().IsKeyDown(Keys.Escape))
this.Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.Draw(bgTexture, new Rectangle(0, 0, 600, 200), Color.Blue);
spriteBatch.Draw(bgTexture, new Rectangle(0, 200, 300, 200), Color.Red);
spriteBatch.Draw(bgTexture, new Rectangle(300, 200, 300, 200), Color.Orange);
spriteBatch.Draw(bgTexture, new Rectangle(0, 400, 300, 200), Color.Green);
spriteBatch.Draw(bgTexture, new Rectangle(300, 400, 300, 200), Color.LightSeaGreen);
DrawShadowText(spriteBatch, this.font, "DrawInstancedPrimitives", new Vector2(10, 10), Color.White, Color.Black);
DrawShadowText(spriteBatch, this.font, "DrawPrimitives", new Vector2(10, 210), Color.White, Color.Black);
DrawShadowText(spriteBatch, this.font, "DrawIndexedPrimitives", new Vector2(310, 210), Color.White, Color.Black);
DrawShadowText(spriteBatch, this.font, "DrawUserPrimitives", new Vector2(10, 410), Color.White, Color.Black);
DrawShadowText(spriteBatch, this.font, "DrawUserIndexedPrimitives", new Vector2(310, 410), Color.White, Color.Black);
spriteBatch.End();
base.Draw(gameTime);
}
private void DrawShadowText(SpriteBatch spriteBatch, SpriteFont font, String text, Vector2 position, Color foreground, Color shadow)
{
spriteBatch.DrawString(font, text, position + new Vector2(2, 2), shadow);
spriteBatch.DrawString(font, text, position, foreground);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{57097B7A-A283-4409-8AAC-35BF0F458657}</ProjectGuid>
<ProjectTypeGuids>{6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Primitives</RootNamespace>
<AssemblyName>Primitives</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<XnaFrameworkVersion>v4.0</XnaFrameworkVersion>
<XnaPlatform>Windows</XnaPlatform>
<XnaProfile>HiDef</XnaProfile>
<XnaCrossPlatformGroupID>4b5697b8-4699-4c1a-85fd-a80f5d4b2aa3</XnaCrossPlatformGroupID>
<XnaOutputType>Game</XnaOutputType>
<ApplicationIcon>anx.ico</ApplicationIcon>
<Thumbnail>GameThumbnail.png</Thumbnail>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\x86\Debug</OutputPath>
<DefineConstants>DEBUG;TRACE;WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<UseVSHostingProcess>false</UseVSHostingProcess>
<PlatformTarget>x86</PlatformTarget>
<XnaCompressContent>false</XnaCompressContent>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\x86\Release</OutputPath>
<DefineConstants>TRACE;WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<UseVSHostingProcess>false</UseVSHostingProcess>
<PlatformTarget>x86</PlatformTarget>
<XnaCompressContent>true</XnaCompressContent>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="Microsoft.Xna.Framework.Game, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="Microsoft.Xna.Framework.Graphics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="Microsoft.Xna.Framework.GamerServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Net" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Program.cs" />
<Compile Include="Game1.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="anx.ico" />
<Content Include="GameThumbnail.png">
<XnaPlatformSpecific>true</XnaPlatformSpecific>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SampleContent\SampleContent.contentproj">
<Project>{FA6E229D-4504-47B1-8A23-2D3FCC13F778}</Project>
<Name>SampleContent</Name>
<XnaReferenceType>Content</XnaReferenceType>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4 Client Profile %28x86 und x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Xna.Framework.4.0">
<Visible>False</Visible>
<ProductName>Microsoft XNA Framework Redistributable 4.0</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\Microsoft.Xna.GameStudio.targets" />
<!--
To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,21 @@
using System;
namespace Primitives
{
#if WINDOWS || XBOX
static class Program
{
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
static void Main(string[] args)
{
using (Game1 game = new Game1())
{
game.Run();
}
}
}
#endif
}

View File

@ -0,0 +1,34 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über den folgenden
// Satz von Attributen kontrolliert. Ändern Sie diese Attributwerte, um die mit einer Assembly
// verbundenen Informationen zu ändern.
[assembly: AssemblyTitle("Primitives")]
[assembly: AssemblyProduct("Primitives")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyCompany("ANX.Framework Team")]
[assembly: AssemblyCopyright("Copyright © ANX.Framework Team 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Bei Einstellung von ComVisible auf falsch sind die Typen in dieser Assembly für
// COM-Komponenten nicht sichtbar. Wenn Sie von COM aus auf einen Typ in dieser Assembly
// zugreifen müssen, stellen Sie das Attribut ComVisible bei diesem Typ auf wahr ein. Nur Windows-
// Assemblys unterstützen COM.
[assembly: ComVisible(false)]
// Auf Windows gilt die folgende GUID für die ID von typelib, wenn dieses
// COM ausgesetzt ist. Auf anderen Plattformen identifiziert sie den
// Titelspeichercontainer bei Bereitstellung dieser Assembly auf dem Gerät eindeutig.
[assembly: Guid("a3fa690f-1084-43f1-baad-b2e734650d4e")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Größere Version
// Kleinere Version
// Build-Nummer
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]

BIN
Samples/Primitives/anx.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB