我正在将一些C#Windows Phone 7应用移植到Windows 8.
手机应用程序使用XNA SoundEffect从缓冲区播放任意声音.在最简单的情况下,我只需要创建所需持续时间和频率的正弦波.持续时间和频率都可以变化很大,所以我宁愿不依赖MediaElements(除非有一些方法可以改变基本文件的频率,但这只会帮助我生成单频率).
WinRT中的XNA SoundEffectInstance相当于什么?
我假设我需要使用DirectX,但我不知道如何从其他C#/ XAML应用程序中解决这个问题.我已经看过SharpDX,但它似乎没有我认为我需要使用的DirectSound,SecondaryBuffer,SecondaryBuffer类.
我已经做了一些上面的假设.可能是我正在寻找错误的类,或者有一种完全独立的方式从Windows 8应用程序生成任意声音.
我找到了一个使用SharpDX的XAudio2通过AudioBuffer播放wav文件的例子.这似乎很有希望,我只需要将生成的音频缓冲区替换为本机文件流.
PM>安装包装SharpDX
PM> Install-Package SharpDX.XAudio2
public void PlaySound()
{
XAudio2 xaudio;
MasteringVoice masteringVoice;
xaudio = new XAudio2();
masteringVoice = new MasteringVoice(xaudio);
var nativefilestream = new NativeFileStream(
@"Assets\SpeechOn.wav",
NativeFileMode.Open,
NativeFileAccess.Read,
NativeFileShare.Read);
var soundstream = new SoundStream(nativefilestream);
var waveFormat = soundstream.Format;
var buffer = new AudioBuffer
{
Stream = soundstream.ToDataStream(),
AudioBytes = (int)soundstream.Length,
Flags = BufferFlags.EndOfStream
};
var sourceVoice = new SourceVoice(xaudio, waveFormat, true);
// …Run Code Online (Sandbox Code Playgroud) 是否可以使用默认的.net绘制方法(System.Drawing方法)绘制到SharpDX Texture2D对象的东西,以便我可以将其显示为纹理?最好使用SharpDX Toolkit.
如果有,怎么样?
编辑:我到目前为止所尝试的内容:
Bitmap b = new Bitmap(100,100);
MemoryStream ms = new MemoryStream();
b.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
Texture2D tex = Texture2D.Load(g.device, ms); // crashing here
ms.Close();
Run Code Online (Sandbox Code Playgroud) 我正在开发一个使用SharpDX和SharpDX Toolkit绘制简单3D形状的应用程序,Geometrics.Desktop样本对入门非常有帮助.现在我正在努力使一些形状变得透明,并且为了简单起见,我只是想让那个样本中的茶壶模型显得透明(也许半透明会更精确).
对于那些不熟悉Geometrics.Desktop示例的人,它会在3D中绘制一些简单的原始几何形状.作为一个示例应用程序,它非常简单,因此它是一个非常好的暂存器,用于试验SharpDX"Toolkit"库的3D功能.
我已将此添加到LoadContent方法(在启动时运行一次),以便准备Direct3D进行混合:
var blendStateDescription = new BlendStateDescription();
blendStateDescription.AlphaToCoverageEnable = false;
blendStateDescription.RenderTarget[0].IsBlendEnabled = true;
blendStateDescription.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha;
blendStateDescription.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha;
blendStateDescription.RenderTarget[0].BlendOperation = BlendOperation.Add;
blendStateDescription.RenderTarget[0].SourceAlphaBlend = BlendOption.Zero;
blendStateDescription.RenderTarget[0].DestinationAlphaBlend = BlendOption.Zero;
blendStateDescription.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add;
blendStateDescription.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
var blendState = SharpDX.Toolkit.Graphics.BlendState.New(this.GraphicsDevice, blendStateDescription);
this.GraphicsDevice.SetBlendState(blendState);
Run Code Online (Sandbox Code Playgroud)
我已经设置了深度模板如下:
var depthDisabledStencilDesc = new DepthStencilStateDescription()
{
IsDepthEnabled = false,
DepthWriteMask = DepthWriteMask.All,
DepthComparison = Comparison.Less,
IsStencilEnabled = true,
StencilReadMask = 0xFF,
StencilWriteMask = 0xFF,
// Stencil operation if pixel front-facing.
FrontFace = new DepthStencilOperationDescription()
{
FailOperation = …Run Code Online (Sandbox Code Playgroud) 我只是偶然发现了这个令人烦恼的行为,同时在示例程序上添加了全屏支持.
创建一个全屏窗口可以工作,但只要我在包含我的全屏窗口的输出上移动任何窗口(从另一个应用程序),它就会自动切换回窗口.
有没有办法防止这种行为(所以全屏窗口不会回到窗口)?
作为参考,这是一个小的独立示例(因此可以轻松复制问题).
如果这很有用,我也在Windows 8.1上运行.
我已经尝试更改WindowAssociationFlags和SwapChainFlags,两者都没有成功,与使用FlipSequential而不是Discard相同
SharpDX.DXGI.Factory2 factory = new SharpDX.DXGI.Factory2();
SharpDX.DXGI.Adapter adapter = factory.GetAdapter(0);
var renderForm1 = new RenderForm("Form 1");
factory.MakeWindowAssociation(renderForm1.Handle, SharpDX.DXGI.WindowAssociationFlags.IgnoreAll);
Device device = new Device(adapter, DeviceCreationFlags.BgraSupport);
SharpDX.DXGI.SwapChainDescription sd = new SharpDX.DXGI.SwapChainDescription()
{
BufferCount = 2,
ModeDescription = new SharpDX.DXGI.ModeDescription(0, 0, new SharpDX.DXGI.Rational(50, 1), SharpDX.DXGI.Format.R8G8B8A8_UNorm),
IsWindowed = true,
OutputHandle = renderForm1.Handle,
SampleDescription = new SharpDX.DXGI.SampleDescription(1,0),
SwapEffect = SharpDX.DXGI.SwapEffect.Discard,
Usage = SharpDX.DXGI.Usage.RenderTargetOutput,
Flags = SharpDX.DXGI.SwapChainFlags.None
};
var swapChain1 = new SharpDX.DXGI.SwapChain(factory, device, sd);
renderForm1.Left = 1922; //Just hardcoded …Run Code Online (Sandbox Code Playgroud) 我想在Visual Studio 2015中的C#项目中编译一个hlsl着色器文件.如果我添加了一个如下图所示的hlsl文件,我会立即获得正确的属性:
但是,当我想在我的C#项目(使用SharpDX)中执行此操作时,我没有获得这样的选项,因此无法编译为我的项目的CSO文件.
有谁知道这方面的解决方案?
我试图使用D3DImage在DX11中获得MSAA,但似乎是不可能的,因为不允许共享多重采样纹理,如下所述:http://msdn.microsoft.com/en-us/library/windows/桌面/ ff476531(v = vs.85)的.aspx
实际上,我使用了D3DImage的SharpDX实现,它可以很好地用于DX11和DX10,因为只要有人反对就可以离开.
解决这个问题的方法在这个主题中描述:http://sharpdx.org/forum/5-api-usage/1000-d3d11-problem-with-usage-of-texture2d,这些方法都没有成功.还有另一个线程提出了类似的问题:多重采样和Direct3D10/D3DImage互操作
最后,问题实际上是,如果有人能够确认,那么绝对不可能使用D3DImage来渲染DX10/DX11的抗锯齿内容吗?
我正在用 SharpDX 编写一个相机,并在四元数的帮助下旋转它。
我已经能够从四元数 s 获得俯仰、偏航和滚转。以下 C# 代码:
public static class QuaternionExtensions
{
public static Vector3 GetPitchYawRoll(this Quaternion q)
{
return new Vector3(q.GetPitch(), q.GetYaw(), q.GetRoll());
}
public static float GetPitch(this Quaternion q)
{
return q.GetK().GetPitch();
}
public static float GetYaw(this Quaternion q)
{
return q.GetK().GetYaw();
}
public static float GetRoll(this Quaternion q)
{
// This is M12 * M22 of rotation …Run Code Online (Sandbox Code Playgroud) 我有一个非常接近完成的SharpDX项目.它使用Kinect进行交互.因此,我的项目将WPF用于Kinect区域和KinectUserViewer对象.到目前为止,SharpDX已经为一切工作做得很好,然而,当它到达使用direct3D的程序的某个部分时,它开始闪烁.这显然与D3Dimage(由MainWindow.xaml中的SharpDXElement使用)可能"从根本上被破坏并且不适合WPF中的有效D3D渲染"这一事实有关[1].有没有办法保持我的WPF元素,而不是使用direct3D闪烁?
我正在开发一个集成 WPF、Direct3D9(使用 Microsoft 的 D3DImage WPF 类)和 CUDA(我需要能够在 GPU 上为 D3DImage 生成纹理)的原型。
问题是,CUDA 不会更新我的纹理。没有返回错误代码,纹理只是保持不变。即使我在自己写的之后阅读,我也看不到任何变化。如何更新我的 D3D9 纹理?
我什至没有运行任何 CUDA 内核,出于调试目的,我仅使用 cuMemcpy2D API 通过从 CPU 复制一些假数据来写入 CUDA 内存。
这是代码,它是 C#,但我在注释中放置了本机 API:
static void updateTexture( Texture tx )
{
var size = tx.getSize();
using( CudaDirectXInteropResource res = new CudaDirectXInteropResource( tx.NativePointer, CUGraphicsRegisterFlags.None, CudaContext.DirectXVersion.D3D9 ) ) // cuGraphicsD3D9RegisterResource
{
res.Map(); // = cuGraphicsMapResources
using( CudaArray2D arr = res.GetMappedArray2D( 0, 0 ) ) // cuGraphicsSubResourceGetMappedArray, cuArrayGetDescriptor. The size is correct here, BTW
{
// Debug code …Run Code Online (Sandbox Code Playgroud) 我尝试使用SharpDX捕获桌面截图.我的应用程序能够捕获屏幕截图但在Windows资源管理器中没有标签.我尝试了2种解决方案,但没有改变.我尝试在文档中找到任何信息,但没有变化.
这是mi代码:
public void SCR()
{
uint numAdapter = 0; // # of graphics card adapter
uint numOutput = 0; // # of output device (i.e. monitor)
// create device and factory
var device = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware);
var factory = new Factory1();
// creating CPU-accessible texture resource
var texdes = new SharpDX.Direct3D11.Texture2DDescription
{
CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.Read,
BindFlags = SharpDX.Direct3D11.BindFlags.None,
Format = Format.B8G8R8A8_UNorm,
Height = factory.Adapters1[numAdapter].Outputs[numOutput].Description.DesktopBounds.Height,
Width = factory.Adapters1[numAdapter].Outputs[numOutput].Description.DesktopBounds.Width,
OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.None,
MipLevels = 1,
ArraySize = 1
};
texdes.SampleDescription.Count = …Run Code Online (Sandbox Code Playgroud) sharpdx ×10
c# ×7
d3dimage ×2
directx ×2
directx-11 ×2
wpf ×2
.net ×1
camera ×1
cuda ×1
direct3d ×1
direct3d11 ×1
direct3d9 ×1
dxgi ×1
hlsl ×1
managed-cuda ×1
msaa ×1
quaternions ×1
rotation ×1
shader ×1
winrt-xaml ×1
xaml ×1