I'm studying the DirectX and SharpDX(use ver.2.6.2).
Now, I try to create a texture from byte array by using Texture2D.FromMemory() method. My sample code is as follows.
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using SharpDX;
using SharpDX.D3DCompiler;
using SharpDX.Direct3D;
using SharpDX.Direct3D11;
using SharpDX.DXGI;
using SharpDX.Windows;
using Buffer = SharpDX.Direct3D11.Buffer;
using Device = SharpDX.Direct3D11.Device;
using MapFlags = SharpDX.Direct3D11.MapFlags;
namespace HLSLTest
{
static class Program
{
[STAThread]
static void Main()
{
Form1 form = new Form1();
form.Text = "D3DRendering - Test";
form.Width = 640;
form.Height = 480;
Device device;
SwapChain swapChain;
var desc = new SwapChainDescription()
{
BufferCount = 1,
ModeDescription = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
IsWindowed = true,
OutputHandle = form.Handle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
Device.CreateWithSwapChain(
SharpDX.Direct3D.DriverType.Hardware,
DeviceCreationFlags.None,
new[] {
SharpDX.Direct3D.FeatureLevel.Level_11_0,
SharpDX.Direct3D.FeatureLevel.Level_10_1,
SharpDX.Direct3D.FeatureLevel.Level_10_0,
},
desc,
out device,
out swapChain
);
// It's Ok, no error
//var texture = Texture2D.FromFile<Texture2D>(device, "GeneticaMortarlessBlocks.jpg");
// "An unhandled exception of type 'SharpDX.SharpDXException' occurred in SharpDX.dll"
// "Additional information: HRESULT: [0x80004005], Module: [General], ApiCode: [E_FAIL/Unspecified error]"
byte[] texArray = new byte[8];
var texture = Texture2D.FromMemory(device, texArray);
var textureView = new ShaderResourceView(device, texture);
}
}
}
However, my code occurrs the following exception.
An unhandled exception of type 'SharpDX.SharpDXException' occurred in SharpDX.dll
Additional information: HRESULT: [0x80004005], Module: [General], ApiCode:[E_FAIL/Unspecified error], Message: エラーを特定できません
I search same problem or a solution on the web but I cannot find anything.
Please give me any advices.
Thanks,