3.7 Working with pointers

Several OpenGL functions expect you to pass a pointer to a raw memory buffer to them. Working with pointers directly is the most efficient way to interact with OpenGL since it avoids any overhead created by having to read the contents of Hollywood tables into memory buffers first.

You can use the functions of Hollywood's memory block library to allocate memory buffers, read or write to them, and obtain a pointer to their raw memory buffer. To allocate a memory buffer, you use the AllocMem() function, to read from a memory buffer you use Peek() while Poke() can be used to write to a memory buffer. Finally, GetMemPointer() returns the pointer of a memory block object. You can pass the return value of GetMemPointer() to all OpenGL functions which expect a pointer argument.

Here is an example:

AllocMem(1, 640*480*4)
Local ptr = GetMemPointer(1)
gl.ReadPixelsRaw(0, 0, 640, 480, #GL_BGRA, #GL_UNSIGNED_BYTE, ptr)
... ; do something with the data

The code above reads 480 rows of 640 pixels into memory block object 1. You could then write the data to a file using WriteMem(), you could convert it to a table using MemToTable() or read individual values from it using Peek(). See the documentation of Hollywood's memory block library for more information.

Show TOC