Search code examples
opengltraceopengl-4

How can I determine the length of data in bytes for the call to glTexImage3D()?


I'm tracing some gl calls and want to record the data passed into glTexImage3D(). I need to know how many bytes long the data is.

It starts off easy with:

size_t num_pixels = width*height*depth;

But I'm not sure of the correct way to determine the bytes per pixel given internalformat, format, and type?

Does format give me the color components? and type give me the number of bits per color component?


Solution

  • The internalformat parameter is irrelevant for figuring out the data stored in pixel transfer operations; only format and type matter.

    Well, not "only" actually. See, format and type combine to determine the size of a pixel's worth of data (format tells you how many channels are in the data, the ordering of those channels, and whether the data is floating-point or integer; type tells you how a channel or pixel value is stored). But to determine how to move from pixel to pixel, row to row, and 2D-image to 2D-image, you need more.

    What you need are all of the GL_UNPACK_* state, whose values are set by the glPixelStore. GL_UNPACK_ALIGNMENT tells you the alignment of each row of pixel data. You need this in order to jump from row to row. There are also other UNPACK state, which allows users to select a sub-rectangle to upload from. If you want to interpret what gets uploaded in all cases, you must use glGetIntegerv to get all of these UNPACK parameters and interpret them as the standard specifies.