🔒 Locked
[slimdx] Surface.FromMemory
Advertisement
Original Post
I'm trying to read a custom texture format that supports DXT* (MS Flight Sim special BMP format) using Direct3D9 and VB.NET The file contains 32K of DXT1 data, 256x256 pixels br is a BinaryStream of the file w and h are 256 fmt is Format.Dxt1 size is 32K b() array of bytes b = br.ReadBytes(size) Dim tx As New Texture(d3dd, w, h, 0, Usage.None, fmt, Pool.Managed) s = tx.GetSurfaceLevel(0) ' the properties and surface description of s all seem correct at this point Surface.FromMemory(s, b, Filter.Default, 0) ' this falls over with invalid data error? Do I need to use a different overload to load DXT1 data? I've done this sort of thing many times in the past using DX8 and VB6 with the D3DXSurfaceLoad* methods - they use the pitch rather than the dimensions to load the data. Paul
Well, what's D3D say when you enable debug mode?
Nothing.
Full debug mode for D3D9, Slimdx ThrowOnError flase, watch added for invalid data.
I output ************ on the line before, it breaks there, F5 just continues with no loaded image.
Output window shows the following:
(The first 2 IO exceptions are from reading the MDL file)
A first chance exception of type 'System.IO.EndOfStreamException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.EndOfStreamException' occurred in Decapod.Mdl.dll
'MDLViewer.exe': Loaded 'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Configuration\cb4cb21d14767292e079366a5d3d76cd\System.Configuration.ni.dll', No symbols loaded.
'MDLViewer.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MDLViewer.exe': Loaded 'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Xml\36f3953f24d4f0b767bf172331ad6f3e\System.Xml.ni.dll', No symbols loaded.
'MDLViewer.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
************************************
(Pressed F5 to continue here)
Direct3D9: (WARN) :Ignoring redundant SetTextureStageState. Stage: 1, State: 1
Full debug mode for D3D9, Slimdx ThrowOnError flase, watch added for invalid data.
I output ************ on the line before, it breaks there, F5 just continues with no loaded image.
Output window shows the following:
(The first 2 IO exceptions are from reading the MDL file)
A first chance exception of type 'System.IO.EndOfStreamException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.EndOfStreamException' occurred in Decapod.Mdl.dll
'MDLViewer.exe': Loaded 'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Configuration\cb4cb21d14767292e079366a5d3d76cd\System.Configuration.ni.dll', No symbols loaded.
'MDLViewer.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MDLViewer.exe': Loaded 'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Xml\36f3953f24d4f0b767bf172331ad6f3e\System.Xml.ni.dll', No symbols loaded.
'MDLViewer.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
************************************
(Pressed F5 to continue here)
Direct3D9: (WARN) :Ignoring redundant SetTextureStageState. Stage: 1, State: 1
Ah - I notice you're using
D3DXLoadSurfaceFromFileInMemory instead of D3DXLoadSurfaceFromMemory
in Surface.cpp
So I would need to supply a surface description structure as part of the byte data (I would need to do something similar to use Texture.FromMemory)
That doesn't make slimdx too useful for loading custom texture formats.
D3DXLoadSurfaceFromFileInMemory instead of D3DXLoadSurfaceFromMemory
in Surface.cpp
So I would need to supply a surface description structure as part of the byte data (I would need to do something similar to use Texture.FromMemory)
That doesn't make slimdx too useful for loading custom texture formats.
Solved for now (I hope) I went back to basics - seems to work OK but needs a bit of refining...
Dim lrect As System.Drawing.Rectangle
Dim dRect As SlimDX.DataRectangle
Dim tx As New Texture(d3dd, w, h, 1, Usage.None, fmt, Pool.Managed)
s = tx.GetSurfaceLevel(0)
lrect.Width = w
lrect.Height = h
dRect = s.LockRectangle(lrect, LockFlags.None)
dRect.Data.Write(b, 0, b.Length)
s.UnlockRectangle()
Dim lrect As System.Drawing.Rectangle
Dim dRect As SlimDX.DataRectangle
Dim tx As New Texture(d3dd, w, h, 1, Usage.None, fmt, Pool.Managed)
s = tx.GetSurfaceLevel(0)
lrect.Width = w
lrect.Height = h
dRect = s.LockRectangle(lrect, LockFlags.None)
dRect.Data.Write(b, 0, b.Length)
s.UnlockRectangle()
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement
