Added IOcclusionQuery interface and implemented the base OcclusionQuery class and the GL3 implementation.

This commit is contained in:
SND\AstrorEnales_cp 2012-09-03 21:54:12 +00:00
parent 32af20abf4
commit 28f3010330
19 changed files with 233 additions and 81 deletions

View File

@ -193,7 +193,7 @@
<Project>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</Project> <Project>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</Project>
<Name>ANX.Framework</Name> <Name>ANX.Framework</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\SoundSystems\WaveUtils\WaveUtils.csproj"> <ProjectReference Include="..\SoundSystems\WaveUtils\WaveUtils_WindowsMetro.csproj">
<Project>{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}</Project> <Project>{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}</Project>
<Name>WaveUtils</Name> <Name>WaveUtils</Name>
</ProjectReference> </ProjectReference>

View File

@ -441,6 +441,7 @@
<Compile Include="NonXNA\PlatformSystem\INativeMediaLibrary.cs" /> <Compile Include="NonXNA\PlatformSystem\INativeMediaLibrary.cs" />
<Compile Include="NonXNA\Reflection\AssemblyLoader.cs" /> <Compile Include="NonXNA\Reflection\AssemblyLoader.cs" />
<Compile Include="NonXNA\RenderSystem\INativeConstantBuffer.cs" /> <Compile Include="NonXNA\RenderSystem\INativeConstantBuffer.cs" />
<Compile Include="NonXNA\RenderSystem\IOcclusionQuery.cs" />
<Compile Include="NonXNA\SoundSystem\IMicrophone.cs" /> <Compile Include="NonXNA\SoundSystem\IMicrophone.cs" />
<Compile Include="NonXNA\ThreadHelper.cs" /> <Compile Include="NonXNA\ThreadHelper.cs" />
<Compile Include="NonXNA\Windows8\AssetsHelper.cs" /> <Compile Include="NonXNA\Windows8\AssetsHelper.cs" />

View File

@ -441,6 +441,7 @@
<Compile Include="NonXNA\PlatformSystem\INativeMediaLibrary.cs" /> <Compile Include="NonXNA\PlatformSystem\INativeMediaLibrary.cs" />
<Compile Include="NonXNA\Reflection\AssemblyLoader.cs" /> <Compile Include="NonXNA\Reflection\AssemblyLoader.cs" />
<Compile Include="NonXNA\RenderSystem\INativeConstantBuffer.cs" /> <Compile Include="NonXNA\RenderSystem\INativeConstantBuffer.cs" />
<Compile Include="NonXNA\RenderSystem\IOcclusionQuery.cs" />
<Compile Include="NonXNA\SoundSystem\IMicrophone.cs" /> <Compile Include="NonXNA\SoundSystem\IMicrophone.cs" />
<Compile Include="NonXNA\ThreadHelper.cs" /> <Compile Include="NonXNA\ThreadHelper.cs" />
<Compile Include="NonXNA\Windows8\AssetsHelper.cs" /> <Compile Include="NonXNA\Windows8\AssetsHelper.cs" />

View File

@ -443,6 +443,7 @@
<Compile Include="NonXNA\PlatformSystem\INativeMediaLibrary.cs" /> <Compile Include="NonXNA\PlatformSystem\INativeMediaLibrary.cs" />
<Compile Include="NonXNA\Reflection\AssemblyLoader.cs" /> <Compile Include="NonXNA\Reflection\AssemblyLoader.cs" />
<Compile Include="NonXNA\RenderSystem\INativeConstantBuffer.cs" /> <Compile Include="NonXNA\RenderSystem\INativeConstantBuffer.cs" />
<Compile Include="NonXNA\RenderSystem\IOcclusionQuery.cs" />
<Compile Include="NonXNA\SoundSystem\IMicrophone.cs" /> <Compile Include="NonXNA\SoundSystem\IMicrophone.cs" />
<Compile Include="NonXNA\ThreadHelper.cs" /> <Compile Include="NonXNA\ThreadHelper.cs" />
<Compile Include="NonXNA\Windows8\AssetsHelper.cs" /> <Compile Include="NonXNA\Windows8\AssetsHelper.cs" />

View File

@ -444,6 +444,7 @@
<Compile Include="NonXNA\PlatformSystem\INativeMediaLibrary.cs" /> <Compile Include="NonXNA\PlatformSystem\INativeMediaLibrary.cs" />
<Compile Include="NonXNA\Reflection\AssemblyLoader.cs" /> <Compile Include="NonXNA\Reflection\AssemblyLoader.cs" />
<Compile Include="NonXNA\RenderSystem\INativeConstantBuffer.cs" /> <Compile Include="NonXNA\RenderSystem\INativeConstantBuffer.cs" />
<Compile Include="NonXNA\RenderSystem\IOcclusionQuery.cs" />
<Compile Include="NonXNA\SoundSystem\IMicrophone.cs" /> <Compile Include="NonXNA\SoundSystem\IMicrophone.cs" />
<Compile Include="NonXNA\ThreadHelper.cs" /> <Compile Include="NonXNA\ThreadHelper.cs" />
<Compile Include="NonXNA\Windows8\AssetsHelper.cs" /> <Compile Include="NonXNA\Windows8\AssetsHelper.cs" />

View File

@ -1,8 +1,7 @@
#region Using Statements
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using ANX.Framework.NonXNA;
#endregion // Using Statements using ANX.Framework.NonXNA.RenderSystem;
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
@ -12,60 +11,19 @@ namespace ANX.Framework.Graphics
{ {
public class OcclusionQuery : GraphicsResource, IGraphicsResource public class OcclusionQuery : GraphicsResource, IGraphicsResource
{ {
#region Private
private bool hasBegun; private bool hasBegun;
private bool completeCallPending; private bool completeCallPending;
public OcclusionQuery(GraphicsDevice graphicsDevice) private IOcclusionQuery nativeQuery;
: base(graphicsDevice) #endregion
{
throw new NotImplementedException();
}
public void Begin()
{
if (this.hasBegun)
{
throw new InvalidOperationException("Begin cannot be called again until End is called.");
}
if (this.completeCallPending)
{
throw new InvalidOperationException("Begin may not be called on this query object again before IsComplete is checked.");
}
this.hasBegun = true;
this.completeCallPending = true;
throw new NotImplementedException();
}
public void End()
{
if (!this.hasBegun)
{
throw new InvalidOperationException("Begin must be called before End can be called.");
}
throw new NotImplementedException();
}
public override void Dispose()
{
throw new NotImplementedException();
}
protected override void Dispose([MarshalAs(UnmanagedType.U1)] bool disposeManaged)
{
throw new NotImplementedException();
}
#region Public
public bool IsComplete public bool IsComplete
{ {
get get
{ {
this.completeCallPending = false; return nativeQuery.IsComplete;
throw new NotImplementedException();
} }
} }
@ -74,12 +32,69 @@ namespace ANX.Framework.Graphics
get get
{ {
if (this.completeCallPending) if (this.completeCallPending)
throw new InvalidOperationException("The status of the query data is unknown. Use the IsComplete " +
"property to determine if the data is available before attempting to retrieve it.");
return nativeQuery.PixelCount;
}
}
#endregion
#region Constructor
public OcclusionQuery(GraphicsDevice graphicsDevice)
: base(graphicsDevice)
{ {
throw new InvalidOperationException("The status of the query data is unknown. Use the IsComplete property to determine if the data is available before attempting to retrieve it."); var creator = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>();
nativeQuery = creator.CreateOcclusionQuery();
} }
throw new NotImplementedException(); ~OcclusionQuery()
{
Dispose(true);
}
#endregion
#region Begin
public void Begin()
{
if (hasBegun)
throw new InvalidOperationException("Begin cannot be called again until End is called.");
if (completeCallPending)
throw new InvalidOperationException("Begin may not be called on this query object again before IsComplete " +
"is checked.");
hasBegun = true;
completeCallPending = true;
nativeQuery.Begin();
}
#endregion
#region End
public void End()
{
if (this.hasBegun == false)
throw new InvalidOperationException("Begin must be called before End can be called.");
nativeQuery.End();
}
#endregion
#region Dispose
public override void Dispose()
{
Dispose(true);
}
protected override void Dispose([MarshalAs(UnmanagedType.U1)] bool disposeManaged)
{
if (nativeQuery != null)
{
nativeQuery.Dispose();
nativeQuery = null;
} }
} }
#endregion
} }
} }

View File

@ -0,0 +1,17 @@
using System;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.NonXNA.RenderSystem
{
public interface IOcclusionQuery : IDisposable
{
bool IsComplete { get; }
int PixelCount { get; }
void Begin();
void End();
}
}

View File

@ -11,33 +11,29 @@ namespace ANX.Framework.NonXNA
{ {
public interface IRenderSystemCreator : ICreator public interface IRenderSystemCreator : ICreator
{ {
INativeGraphicsDevice CreateGraphicsDevice( INativeGraphicsDevice CreateGraphicsDevice(PresentationParameters presentationParameters);
PresentationParameters presentationParameters);
INativeTexture2D CreateTexture(GraphicsDevice graphics, INativeTexture2D CreateTexture(GraphicsDevice graphics, SurfaceFormat surfaceFormat, int width, int height, int mipCount);
SurfaceFormat surfaceFormat, int width, int height, int mipCount);
INativeRenderTarget2D CreateRenderTarget(GraphicsDevice graphics, INativeRenderTarget2D CreateRenderTarget(GraphicsDevice graphics, int width, int height, bool mipMap,
int width, int height, bool mipMap, SurfaceFormat preferredFormat, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount,
DepthFormat preferredDepthFormat, int preferredMultiSampleCount,
RenderTargetUsage usage); RenderTargetUsage usage);
INativeIndexBuffer CreateIndexBuffer(GraphicsDevice graphics, INativeIndexBuffer CreateIndexBuffer(GraphicsDevice graphics, IndexBuffer managedBuffer, IndexElementSize size,
IndexBuffer managedBuffer, IndexElementSize size, int indexCount, int indexCount, BufferUsage usage);
BufferUsage usage);
INativeVertexBuffer CreateVertexBuffer(GraphicsDevice graphics, INativeVertexBuffer CreateVertexBuffer(GraphicsDevice graphics, VertexBuffer managedBuffer,
VertexBuffer managedBuffer, VertexDeclaration vertexDeclaration, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage);
int vertexCount, BufferUsage usage);
#if XNAEXT #if XNAEXT
INativeConstantBuffer CreateConstantBuffer(GraphicsDevice graphics, ConstantBuffer managedBuffer, BufferUsage usage); INativeConstantBuffer CreateConstantBuffer(GraphicsDevice graphics, ConstantBuffer managedBuffer, BufferUsage usage);
#endif #endif
INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect, INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect, Stream byteCode);
Stream byteCode); INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect, Stream vertexShaderByteCode,
INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect, Stream pixelShaderByteCode);
Stream vertexShaderByteCode, Stream pixelShaderByteCode);
IOcclusionQuery CreateOcclusionQuery();
bool IsLanguageSupported(EffectSourceLanguage sourceLanguage); bool IsLanguageSupported(EffectSourceLanguage sourceLanguage);

View File

@ -247,5 +247,12 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
return sourceLanguage == EffectSourceLanguage.HLSL_FX || sourceLanguage == EffectSourceLanguage.HLSL; return sourceLanguage == EffectSourceLanguage.HLSL_FX || sourceLanguage == EffectSourceLanguage.HLSL;
} }
#region CreateOcclusionQuery (TODO)
public IOcclusionQuery CreateOcclusionQuery()
{
throw new NotImplementedException();
}
#endregion
} }
} }

View File

@ -56,6 +56,7 @@
<Compile Include="Helpers\LinuxInterop.cs" /> <Compile Include="Helpers\LinuxInterop.cs" />
<Compile Include="Helpers\WindowsInterop.cs" /> <Compile Include="Helpers\WindowsInterop.cs" />
<Compile Include="IndexBufferGL3.cs" /> <Compile Include="IndexBufferGL3.cs" />
<Compile Include="OcclusionQueryGL3.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RasterizerStateGL3.cs" /> <Compile Include="RasterizerStateGL3.cs" />
<Compile Include="RenderTarget2DGL3.cs" /> <Compile Include="RenderTarget2DGL3.cs" />

View File

@ -56,6 +56,7 @@
<Compile Include="Helpers\LinuxInterop.cs" /> <Compile Include="Helpers\LinuxInterop.cs" />
<Compile Include="Helpers\WindowsInterop.cs" /> <Compile Include="Helpers\WindowsInterop.cs" />
<Compile Include="IndexBufferGL3.cs" /> <Compile Include="IndexBufferGL3.cs" />
<Compile Include="OcclusionQueryGL3.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RasterizerStateGL3.cs" /> <Compile Include="RasterizerStateGL3.cs" />
<Compile Include="RenderTarget2DGL3.cs" /> <Compile Include="RenderTarget2DGL3.cs" />

View File

@ -57,6 +57,7 @@
<Compile Include="Helpers\LinuxInterop.cs" /> <Compile Include="Helpers\LinuxInterop.cs" />
<Compile Include="Helpers\WindowsInterop.cs" /> <Compile Include="Helpers\WindowsInterop.cs" />
<Compile Include="IndexBufferGL3.cs" /> <Compile Include="IndexBufferGL3.cs" />
<Compile Include="OcclusionQueryGL3.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RasterizerStateGL3.cs" /> <Compile Include="RasterizerStateGL3.cs" />
<Compile Include="RenderTarget2DGL3.cs" /> <Compile Include="RenderTarget2DGL3.cs" />

View File

@ -58,6 +58,7 @@
<Compile Include="Helpers\LinuxInterop.cs" /> <Compile Include="Helpers\LinuxInterop.cs" />
<Compile Include="Helpers\WindowsInterop.cs" /> <Compile Include="Helpers\WindowsInterop.cs" />
<Compile Include="IndexBufferGL3.cs" /> <Compile Include="IndexBufferGL3.cs" />
<Compile Include="OcclusionQueryGL3.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RasterizerStateGL3.cs" /> <Compile Include="RasterizerStateGL3.cs" />
<Compile Include="RenderTarget2DGL3.cs" /> <Compile Include="RenderTarget2DGL3.cs" />

View File

@ -323,5 +323,12 @@ namespace ANX.RenderSystem.Windows.GL3
return sourceLanguage == EffectSourceLanguage.GLSL_FX || sourceLanguage == EffectSourceLanguage.GLSL; return sourceLanguage == EffectSourceLanguage.GLSL_FX || sourceLanguage == EffectSourceLanguage.GLSL;
} }
#endregion #endregion
#region CreateOcclusionQuery
public IOcclusionQuery CreateOcclusionQuery()
{
return new OcclusionQueryGL3();
}
#endregion
} }
} }

View File

@ -0,0 +1,73 @@
using ANX.Framework.NonXNA.Development;
using ANX.Framework.NonXNA.RenderSystem;
using OpenTK.Graphics.OpenGL;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.RenderSystem.Windows.GL3
{
[PercentageComplete(100)]
[TestState(TestStateAttribute.TestState.Untested)]
[Developer("AstrorEnales")]
public class OcclusionQueryGL3 : IOcclusionQuery
{
private uint[] handle;
#region Public
public bool IsComplete
{
get
{
int state;
GL.GetQueryObject(handle[0], GetQueryObjectParam.QueryResultAvailable, out state);
return state != 0;
}
}
public int PixelCount
{
get
{
int result;
GL.GetQueryObject(handle[0], GetQueryObjectParam.QueryResult, out result);
return result;
}
}
#endregion
#region Constructor
public OcclusionQueryGL3()
{
handle = new uint[1];
GL.GenQueries(1, handle);
}
#endregion
#region Begin
public void Begin()
{
//GLCore.ColorMask(false, false, false, false);
//GLCore.DepthMask(false);
GL.BeginQuery(QueryTarget.SamplesPassed, handle[0]);
}
#endregion
#region End
public void End()
{
GL.EndQuery(QueryTarget.SamplesPassed);
//GLCore.DepthMask(true);
//GLCore.ColorMask(true, true, true, true);
}
#endregion
#region Dispose
public void Dispose()
{
GL.DeleteQueries(1, handle);
}
#endregion
}
}

View File

@ -160,5 +160,11 @@ namespace ANX.RenderSystem.PsVita
return false; return false;
} }
#region CreateOcclusionQuery (TODO)
public IOcclusionQuery CreateOcclusionQuery()
{
throw new NotImplementedException();
}
#endregion
} }
} }

View File

@ -243,5 +243,11 @@ namespace ANX.RenderSystem.Windows.DX11
return sourceLanguage == EffectSourceLanguage.HLSL_FX || sourceLanguage == EffectSourceLanguage.HLSL; return sourceLanguage == EffectSourceLanguage.HLSL_FX || sourceLanguage == EffectSourceLanguage.HLSL;
} }
#region CreateOcclusionQuery (TODO)
public IOcclusionQuery CreateOcclusionQuery()
{
throw new NotImplementedException();
}
#endregion
} }
} }

View File

@ -262,5 +262,22 @@ namespace ANX.RenderSystem.Windows.Metro
preferredFormat, preferredDepthFormat, preferredMultiSampleCount, usage); preferredFormat, preferredDepthFormat, preferredMultiSampleCount, usage);
} }
#endregion #endregion
#region CreateOcclusionQuery (TODO)
public IOcclusionQuery CreateOcclusionQuery()
{
throw new NotImplementedException();
}
#endregion
#region IRenderSystemCreator Member
public bool IsLanguageSupported(EffectSourceLanguage sourceLanguage)
{
throw new NotImplementedException();
}
#endregion
} }
} }

View File

@ -74,7 +74,7 @@
<Project>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</Project> <Project>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</Project>
<Name>ANX.Framework</Name> <Name>ANX.Framework</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\WaveUtils\WaveUtils.csproj"> <ProjectReference Include="..\WaveUtils\WaveUtils_WindowsMetro.csproj">
<Project>{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}</Project> <Project>{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}</Project>
<Name>WaveUtils</Name> <Name>WaveUtils</Name>
</ProjectReference> </ProjectReference>