Jump to content
  • Advertisement
Sign in to follow this  
wlastas

SlimDX reading Texture2D to DataStream

This topic is 2479 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Device device = new Device( SharpDX.Direct3D10.DriverType.Hardware, DeviceCreationFlags.Debug);
ImageLoadInformation li = new ImageLoadInformation()
{
CpuAccessFlags = CpuAccessFlags.Read,
BindFlags = BindFlags.None,
MipLevels = 1,
Format = Format.R8G8B8A8_UNorm,
MipFilter = FilterFlags.None,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Staging
};
Texture2D bitmap = Texture2D.FromFile<Texture2D>(device, @"N:\MI\bin\Maps\16x1.bmp", li);
DataRectangle dr = bitmap.Map(0, MapMode.Read, MapFlags.None);
DataStream ds = new DataStream(dr.DataPointer, dr.Pitch * bitmap.Description.Height, true, true);

List<Byte4> b = new List<Byte4>();
while(ds.Position <ds.Length)
b.Add( ds.Read<Byte4>());

Share this post


Link to post
Share on other sites
Advertisement
Hidden
<span id="result_box" class="" lang="en"><span class="hps">the ability to debug</span> <span class="hps">I</span> <span class="hps">helped a lot</span> <span class="hps">during the day</span><span class="">, plus</span> <span class="hps">studied</span> <span class="hps">your</span> <span class="hps">forum</span> <span class="hps">to my question</span><span>.</span> <span class="hps">In the end,</span> <span class="hps">remove the</span> <span class="hps">write</span> <span class="hps">code that does not</span> <span class="hps">generate errors,</span> <span class="hps">but the result</span> <span class="hps">of his work</span> <span class="hps">is clearly</span> <span class="hps">wrong<br><br>&nbsp; ImageLoadInformation li = new ImageLoadInformation()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BindFlags = BindFlags.ShaderResource,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MipLevels = 1,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FilterFlags = FilterFlags.None,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MipFilterFlags = FilterFlags.None,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OptionFlags = ResourceOptionFlags.None,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Device device = new Device(DriverType.Hardware, DeviceCreationFlags.Debug);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Texture2D bitmap = Texture2D.FromFile(device, @"N:\MI\bin\Maps\3x3.bmp", li);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Texture2DDescription de = bitmap.Description;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; de.MipLevels = 1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; de.CpuAccessFlags = CpuAccessFlags.Write;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; de.Usage = ResourceUsage.Dynamic;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Texture2D new_bitmap = new Texture2D(device, de);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; device.CopyResource(bitmap, new_bitmap);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataRectangle dr = new_bitmap.Map(0, MapMode.WriteDiscard, MapFlags.None);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataStream ds = dr.Data;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ds.Position = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List&lt;float&gt; tmp = new List&lt;float&gt;();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (ds.Position &lt; ds.Length)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tmp.Add(ds.Read&lt;float&gt;());<br><br></span></span><span id="result_box" class="" lang="en"><span class="hps"> ds.Length </span></span><span id="result_box" class="" lang="en"><span class="hps">wrong!!!<br><br></span></span><span id="result_box" class="" lang="en"><span class="hps">Byt</span> <span class="hps">may</span> <span class="hps">be</span> <span class="hps">to use some</span> <span class="hps">other algorithm</span><span>?</span><br> <span class="hps">What is wrong with</span> <span class="hps">my code</span><span class="">?</span></span><br><span id="result_box" class="" lang="en"><span class="hps"><br></span></span>

Share this post


Link to post
Hidden

Turn on the Direct3D debug runtimes and see if it gives you any debugging information about the error.

the ability to debug I helped a lot during the day, plus studied your forum to my question. In the end, remove the write code that does not generate errors, but the result of his work is clearly wrong

Device device = new Device(DriverType.Hardware, DeviceCreationFlags.Debug);

ImageLoadInformation li = new ImageLoadInformation()
{
CpuAccessFlags = SlimDX.Direct3D10.CpuAccessFlags.Write,
BindFlags = BindFlags.ShaderResource,
MipLevels = 1,
FilterFlags = FilterFlags.None,
Format = SlimDX.DXGI.Format.R32_Float,
MipFilterFlags = FilterFlags.None,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Dynamic
};
Texture2D bitmap = Texture2D.FromFile(device, @"N:\MI\bin\Maps\3x3.bmp", li);
DataRectangle dr = bitmap.Map(0, MapMode.WriteDiscard, MapFlags.None);
DataStream ds = dr.Data;

List<float> tmp = new List<float>();
while (ds.Position < ds.Length)
tmp.Add(ds.Read<float>());

ds.Length wrong!!!

Byt may be to use some other algorithm?
What is wrong with my code?

Share this post


Link to post
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!