mesa/formats: Add layout and swizzle information
v2: Move the MESA_FORMAT_SWIZZLE enum to the top of the file Signed-off-by: Jason Ekstrand <jason.ekstrand@intel.com> Reviewed-by: Brian Paul <brianp@vmware.com>
This commit is contained in:
@@ -96,6 +96,14 @@ def get_gl_data_type(fmat):
|
||||
else:
|
||||
assert False
|
||||
|
||||
def get_mesa_layout(fmat):
|
||||
if fmat.layout == 'array':
|
||||
return 'MESA_FORMAT_LAYOUT_ARRAY'
|
||||
elif fmat.layout == 'packed':
|
||||
return 'MESA_FORMAT_LAYOUT_PACKED'
|
||||
else:
|
||||
return 'MESA_FORMAT_LAYOUT_OTHER'
|
||||
|
||||
def get_channel_bits(fmat, chan_name):
|
||||
if fmat.is_compressed():
|
||||
# These values are pretty-much bogus, but OpenGL requires that we
|
||||
@@ -166,6 +174,7 @@ for fmat in formats:
|
||||
print ' {'
|
||||
print ' {0},'.format(fmat.name)
|
||||
print ' "{0}",'.format(fmat.name)
|
||||
print ' {0},'.format(get_mesa_layout(fmat))
|
||||
print ' {0},'.format(get_gl_base_format(fmat))
|
||||
print ' {0},'.format(get_gl_data_type(fmat))
|
||||
|
||||
@@ -176,6 +185,8 @@ for fmat in formats:
|
||||
|
||||
print ' {0}, {1}, {2},'.format(fmat.block_width, fmat.block_height,
|
||||
int(fmat.block_size() / 8))
|
||||
|
||||
print ' {{ {0} }},'.format(', '.join(map(str, fmat.swizzle)))
|
||||
print ' },'
|
||||
|
||||
print '};'
|
||||
|
||||
@@ -40,6 +40,8 @@ struct gl_format_info
|
||||
/** text name for debugging */
|
||||
const char *StrName;
|
||||
|
||||
enum mesa_format_layout Layout;
|
||||
|
||||
/**
|
||||
* Base format is one of GL_RED, GL_RG, GL_RGB, GL_RGBA, GL_ALPHA,
|
||||
* GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA,
|
||||
@@ -67,6 +69,8 @@ struct gl_format_info
|
||||
*/
|
||||
GLubyte BlockWidth, BlockHeight;
|
||||
GLubyte BytesPerBlock;
|
||||
|
||||
uint8_t Swizzle[4];
|
||||
};
|
||||
|
||||
#include "format_info.c"
|
||||
@@ -177,6 +181,21 @@ _mesa_get_format_max_bits(mesa_format format)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the layout type of the given format.
|
||||
* The return value will be one of:
|
||||
* MESA_FORMAT_LAYOUT_ARRAY
|
||||
* MESA_FORMAT_LAYOUT_PACKED
|
||||
* MESA_FORMAT_LAYOUT_OTHER
|
||||
*/
|
||||
extern enum mesa_format_layout
|
||||
_mesa_get_format_layout(mesa_format format)
|
||||
{
|
||||
const struct gl_format_info *info = _mesa_get_format_info(format);
|
||||
return info->Layout;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the data type (or more specifically, the data representation)
|
||||
* for the given format.
|
||||
@@ -224,6 +243,33 @@ _mesa_get_format_block_size(mesa_format format, GLuint *bw, GLuint *bh)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the an array of four numbers representing the transformation
|
||||
* from the RGBA or SZ colorspace to the given format. For array formats,
|
||||
* the i'th RGBA component is given by:
|
||||
*
|
||||
* if (swizzle[i] <= MESA_FORMAT_SWIZZLE_W)
|
||||
* comp = data[swizzle[i]];
|
||||
* else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ZERO)
|
||||
* comp = 0;
|
||||
* else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ONE)
|
||||
* comp = 1;
|
||||
* else if (swizzle[i] == MESA_FORMAT_SWIZZLE_NONE)
|
||||
* // data does not contain a channel of this format
|
||||
*
|
||||
* For packed formats, the swizzle gives the number of components left of
|
||||
* the least significant bit.
|
||||
*
|
||||
* Compressed formats have no swizzle.
|
||||
*/
|
||||
void
|
||||
_mesa_get_format_swizzle(mesa_format format, uint8_t swizzle_out[4])
|
||||
{
|
||||
const struct gl_format_info *info = _mesa_get_format_info(format);
|
||||
memcpy(swizzle_out, info->Swizzle, sizeof(info->Swizzle));
|
||||
}
|
||||
|
||||
|
||||
/** Is the given format a compressed format? */
|
||||
GLboolean
|
||||
_mesa_is_format_compressed(mesa_format format)
|
||||
|
||||
@@ -56,6 +56,29 @@ extern "C" {
|
||||
*/
|
||||
#define MAX_PIXEL_BYTES 16
|
||||
|
||||
/**
|
||||
* Specifies the layout of a pixel format. See the MESA_FORMAT
|
||||
* documentation below.
|
||||
*/
|
||||
enum mesa_format_layout {
|
||||
MESA_FORMAT_LAYOUT_ARRAY,
|
||||
MESA_FORMAT_LAYOUT_PACKED,
|
||||
MESA_FORMAT_LAYOUT_OTHER,
|
||||
};
|
||||
|
||||
/**
|
||||
* An enum representing different possible swizzling values. This is used
|
||||
* to interpret the output of _mesa_get_format_swizzle
|
||||
*/
|
||||
enum {
|
||||
MESA_FORMAT_SWIZZLE_X = 0,
|
||||
MESA_FORMAT_SWIZZLE_Y = 1,
|
||||
MESA_FORMAT_SWIZZLE_Z = 2,
|
||||
MESA_FORMAT_SWIZZLE_W = 3,
|
||||
MESA_FORMAT_SWIZZLE_ZERO = 4,
|
||||
MESA_FORMAT_SWIZZLE_ONE = 5,
|
||||
MESA_FORMAT_SWIZZLE_NONE = 6,
|
||||
};
|
||||
|
||||
/**
|
||||
* Mesa texture/renderbuffer image formats.
|
||||
@@ -419,6 +442,9 @@ _mesa_get_format_bits(mesa_format format, GLenum pname);
|
||||
extern GLuint
|
||||
_mesa_get_format_max_bits(mesa_format format);
|
||||
|
||||
extern enum mesa_format_layout
|
||||
_mesa_get_format_layout(mesa_format format);
|
||||
|
||||
extern GLenum
|
||||
_mesa_get_format_datatype(mesa_format format);
|
||||
|
||||
@@ -428,6 +454,9 @@ _mesa_get_format_base_format(mesa_format format);
|
||||
extern void
|
||||
_mesa_get_format_block_size(mesa_format format, GLuint *bw, GLuint *bh);
|
||||
|
||||
extern void
|
||||
_mesa_get_format_swizzle(mesa_format format, uint8_t swizzle_out[4]);
|
||||
|
||||
extern GLboolean
|
||||
_mesa_is_format_compressed(mesa_format format);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user