[slimdx] Surface.FromMemory
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
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.
Gah. Everything always has to be so difficult...I'll take a look at straightening out the Surface creation functions.
Thanks for that and indeed thanks for the whole of SlimDX.
I wouldn't have got this far if I had to use C++ :)
I wouldn't have got this far if I had to use C++ :)
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()
That's probably all D3DXLoadSurfaceFromMemory really does, although it's hard to say for sure. Glad to know you found a workaround though, because the next official release is a long ways out.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement