Source of Buffer?

Blitz3D Forums/Blitz3D Programming/Source of Buffer?

_PJ_(Posted 2010) [#1]
This one's probabkly gonna involve knowledge of the B3D/DirectX memory management or making use of pointers with some separate library or something...

I'm wondering how (in theory, it should be possible) to obtain the image/texture etc. of a Buffer, without iterating through the lot.

Presumably, from what I can gather, one would need to know in advance the type of buffer analysed, and, such details like the frame number too.

I'm not sure how the VRAM flag for textures may affect this if at all either, but it might have an impact since the memory location would be the graphics acard as opposed to the system heap?

THEN...
Is it even possible to identify the width/height of the buffer? If the above is possible, then it should be possible to just use ImageWidth or TextureWidth etc. from the source obtained.

Essentially, the idea is to get some kinda functions that work like this:

Function GetImageFromBuffer%(ImageBufferHandle%)

Function GetTextureFromBuffer%(TextureBufferHandle%)

Function GetBufferWidth%(BufferHandle%,BufferType%)
Select (BufferType)
Case Buffer_Type_ImageBuffer:
Return ImageWidth(GetImageFromBuffer(BufferHandle))
Case Buffer_Type_ImageBuffer:
Return TextureWidth(GetTextureFromBuffer(BufferHandle))
Default:
Return 0
End Select
End Function


Serpent(Posted 2010) [#2]
See
[a http://translate.google.com/translate?hl=en&ie=UTF-8&sl=ru&tl=en&u=http://blitz.pp.ru/forum/showthread.php%3Fs%3D969a613d7deeb67f32385669ba81bcbb%26threadid%3D203%26perpage%3D15%26highlight%3D%26pagenumber%3D1&prev=_t&rurl=translate.google.com]here[/a]
for stuff on Blitz internal structs. Again, thanks need to be given to MixailV. I'm not sure if these are entirely up-to-date.
Anyway, looking at the buffer diagram, the buffer struct seems to include width and height info.
Based on this:
MyWidth% = Input("Width>> ")
MyHeight% = Input("Height>> ")
Image = CreateImage(MyWidth, MyHeight)
Buffer = ImageBuffer(Image)
Width = CreateBank(4)
Height = CreateBank(4)
MoveMemoryObjInt(Width, Buffer + 92, 4)
MoveMemoryObjInt(Height, Buffer + 96, 4)
Print "BufferWidth  = " + PeekInt(Width,0)
Print "BufferHeight = " + PeekInt(Height,0)
WaitKey
End


with userdecls:
lib "Kernel32.dll"
MoveMemoryObjInt(Destination*,Source%,Length%) : "RtlMoveMemory"


This works, but I don't think it's possible to get the Blitz image/texture pointer from a buffer.

EDIT: can't get hyperlink to work sry.

Last edited 2010


Serpent(Posted 2010) [#3]
Alright, in function form:
;decls:
;.lib "kernel32.dll"
;MoveMemoryObjInt(Destination*,Source%,Length%) : "RtlMoveMemory"

;Put at start of program:
Global TempBank%
TempBank = CreateBank(4)

;Put anywhere
Function BufferWidth(BufferPointer)
	MoveMemoryObjInt(TempBank, BufferPointer + 92, 4)
	Return PeekInt(TempBank,0)
End Function
Function BufferHeight(BufferPointer)
	MoveMemoryObjInt(TempBank, BufferPointer + 96, 4)
	Return PeekInt(TempBank,0)
End Function

Note: I've made the bank handle a global to avoid having to create and free the bank every time the function is called.
Also, 'ObjInt' in the declared function name refers to how the first variable is passed as a pointer to an object, and the second as a plain integer.


_PJ_(Posted 2010) [#4]
That's fantastic! And really easy to work with too, thanks very much :)

Last edited 2010


Serpent(Posted 2010) [#5]
Yeah I know. Things like these can be surprisingly simple when others go to the hard work of figuring out the internal structs :P