return bits / 8;
}
+static INLINE uint
+util_format_get_component_bits(enum pipe_format format,
+ enum util_format_colorspace colorspace,
+ uint component)
+{
+ const struct util_format_description *desc = util_format_description(format);
+ enum util_format_colorspace desc_colorspace;
+ uint swizzle;
+
+ assert(format);
+ if (!format) {
+ return 0;
+ }
+
+ assert(component >= 4);
+
+ /* Treat RGB and SRGB as equivalent. */
+ if (colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
+ colorspace = UTIL_FORMAT_COLORSPACE_RGB;
+ }
+ if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
+ desc_colorspace = UTIL_FORMAT_COLORSPACE_RGB;
+ } else {
+ desc_colorspace = desc->colorspace;
+ }
+
+ if (desc_colorspace != colorspace) {
+ return 0;
+ }
+
+ switch (desc->swizzle[component]) {
+ case UTIL_FORMAT_SWIZZLE_X:
+ return desc->channel[0].size;
+ case UTIL_FORMAT_SWIZZLE_Y:
+ return desc->channel[1].size;
+ case UTIL_FORMAT_SWIZZLE_Z:
+ return desc->channel[2].size;
+ case UTIL_FORMAT_SWIZZLE_W:
+ return desc->channel[3].size;
+ default:
+ return 0;
+ }
+}
+
/*
* Format access functions.
#include "draw/draw_context.h"
+#include "util/u_format.h"
+
/**
* XXX this might get moved someday
if (lp->framebuffer.zsbuf) {
int depth_bits;
double mrd;
- depth_bits = pf_get_component_bits(lp->framebuffer.zsbuf->format,
- PIPE_FORMAT_COMP_Z);
+ depth_bits = util_format_get_component_bits(lp->framebuffer.zsbuf->format,
+ UTIL_FORMAT_COLORSPACE_ZS,
+ 0);
if (depth_bits > 16) {
mrd = 0.0000001;
}
#include "draw/draw_context.h"
+#include "util/u_format.h"
+
/**
* XXX this might get moved someday
if (sp->framebuffer.zsbuf) {
int depth_bits;
double mrd;
- depth_bits = pf_get_component_bits(sp->framebuffer.zsbuf->format,
- PIPE_FORMAT_COMP_Z);
+ depth_bits = util_format_get_component_bits(sp->framebuffer.zsbuf->format,
+ UTIL_FORMAT_COLORSPACE_ZS,
+ 0);
if (depth_bits > 16) {
mrd = 0.0000001;
}
*/
extern const char *pf_name( enum pipe_format format );
-/**
- * Return bits for a particular component.
- * \param comp component index, starting at 0
- */
-static INLINE uint pf_get_component_bits( enum pipe_format format, uint comp )
-{
- uint size;
-
- if (pf_swizzle_x(format) == comp) {
- size = pf_size_x(format);
- }
- else if (pf_swizzle_y(format) == comp) {
- size = pf_size_y(format);
- }
- else if (pf_swizzle_z(format) == comp) {
- size = pf_size_z(format);
- }
- else if (pf_swizzle_w(format) == comp) {
- size = pf_size_w(format);
- }
- else {
- size = 0;
- }
- if (pf_layout( format ) == PIPE_FORMAT_LAYOUT_RGBAZS)
- return size << pf_exp2( format );
- return size << (pf_mixed_scale8( format ) * 3);
-}
/**
* Describe accurately the pixel format.
templ.depth0 = 1;
templ.last_level = 0;
- if (pf_get_component_bits(format, PIPE_FORMAT_COMP_S)) {
+ if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 1)) {
templ.tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
} else {
templ.tex_usage = (PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
#include "main/context.h"
#include "pipe/p_format.h"
#include "pipe/p_screen.h"
+#include "util/u_format.h"
#include "state_tracker/st_context.h"
#include "state_tracker/st_public.h"
assert(pf_layout( pfi->depth_stencil_format ) == PIPE_FORMAT_LAYOUT_RGBAZS );
- if(pf_get_component_bits( pfi->depth_stencil_format, PIPE_FORMAT_COMP_Z ))
+ if(util_format_get_component_bits(pfi->depth_stencil_format, UTIL_FORMAT_COLORSPACE_ZS, 0))
depthFormat = pfi->depth_stencil_format;
else
depthFormat = PIPE_FORMAT_NONE;
- if(pf_get_component_bits( pfi->depth_stencil_format, PIPE_FORMAT_COMP_S ))
+ if(util_format_get_component_bits(pfi->depth_stencil_format, UTIL_FORMAT_COLORSPACE_ZS, 1))
stencilFormat = pfi->depth_stencil_format;
else
stencilFormat = PIPE_FORMAT_NONE;
#include "pipe/p_defines.h"
#include "pipe/p_screen.h"
+#include "util/u_format.h"
#include "util/u_debug.h"
#include "stw_icd.h"
return;
assert(pf_layout( color->format ) == PIPE_FORMAT_LAYOUT_RGBAZS );
- assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_R ) == color->bits.red );
- assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_G ) == color->bits.green );
- assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_B ) == color->bits.blue );
- assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_A ) == color->bits.alpha );
+ assert(util_format_get_component_bits(color->format, UTIL_FORMAT_COLORSPACE_RGB, 0) == color->bits.red);
+ assert(util_format_get_component_bits(color->format, UTIL_FORMAT_COLORSPACE_RGB, 1) == color->bits.green);
+ assert(util_format_get_component_bits(color->format, UTIL_FORMAT_COLORSPACE_RGB, 2) == color->bits.blue);
+ assert(util_format_get_component_bits(color->format, UTIL_FORMAT_COLORSPACE_RGB, 3) == color->bits.alpha);
assert(pf_layout( depth->format ) == PIPE_FORMAT_LAYOUT_RGBAZS );
- assert(pf_get_component_bits( depth->format, PIPE_FORMAT_COMP_Z ) == depth->bits.depth );
- assert(pf_get_component_bits( depth->format, PIPE_FORMAT_COMP_S ) == depth->bits.stencil );
+ assert(util_format_get_component_bits(depth->format, UTIL_FORMAT_COLORSPACE_ZS, 0) == depth->bits.depth);
+ assert(util_format_get_component_bits(depth->format, UTIL_FORMAT_COLORSPACE_ZS, 1) == depth->bits.stencil);
pfi = &stw_dev->pixelformats[stw_dev->pixelformat_extended_count];
}
if(format != GL_DEPTH_STENCIL &&
- pf_get_component_bits( strb->format, PIPE_FORMAT_COMP_Z ) != 0)
+ util_format_get_component_bits(strb->format, UTIL_FORMAT_COLORSPACE_ZS, 0) != 0)
usage = PIPE_TRANSFER_READ_WRITE;
else
usage = PIPE_TRANSFER_WRITE;
GL_STENCIL_INDEX, GL_UNSIGNED_BYTE,
&ctx->DefaultPacking, buffer);
- if(pf_get_component_bits( rbDraw->format, PIPE_FORMAT_COMP_Z ) != 0)
+ if(util_format_get_component_bits(rbDraw->format, UTIL_FORMAT_COLORSPACE_ZS, 0) != 0)
usage = PIPE_TRANSFER_READ_WRITE;
else
usage = PIPE_TRANSFER_WRITE;
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_screen.h"
+#include "util/u_format.h"
#include "st_context.h"
#include "st_format.h"
-static GLuint
-format_bits(
- pipe_format_rgbazs_t info,
- GLuint comp )
-{
- return pf_get_component_bits( (enum pipe_format) info, comp );
-}
static GLuint
format_max_bits(
pipe_format_rgbazs_t info )
{
- GLuint size = format_bits( info, PIPE_FORMAT_COMP_R );
+ GLuint size = util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 0);
- size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_G ) );
- size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_B ) );
- size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_A ) );
- size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_Z ) );
- size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_S ) );
+ size = MAX2(size, util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 1));
+ size = MAX2(size, util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 2));
+ size = MAX2(size, util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 3));
+ size = MAX2(size, util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_ZS, 0));
+ size = MAX2(size, util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_ZS, 1));
return size;
}
pipe_format_rgbazs_t info )
{
return
- format_bits( info, PIPE_FORMAT_COMP_R ) +
- format_bits( info, PIPE_FORMAT_COMP_G ) +
- format_bits( info, PIPE_FORMAT_COMP_B ) +
- format_bits( info, PIPE_FORMAT_COMP_A ) +
- format_bits( info, PIPE_FORMAT_COMP_Z ) +
- format_bits( info, PIPE_FORMAT_COMP_S );
+ util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 0) +
+ util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 1) +
+ util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 2) +
+ util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 3) +
+ util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_ZS, 0) +
+ util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_ZS, 1);
}
/*
}
/* Component bits */
- pinfo->red_bits = format_bits( info, PIPE_FORMAT_COMP_R );
- pinfo->green_bits = format_bits( info, PIPE_FORMAT_COMP_G );
- pinfo->blue_bits = format_bits( info, PIPE_FORMAT_COMP_B );
- pinfo->alpha_bits = format_bits( info, PIPE_FORMAT_COMP_A );
- pinfo->depth_bits = format_bits( info, PIPE_FORMAT_COMP_Z );
- pinfo->stencil_bits = format_bits( info, PIPE_FORMAT_COMP_S );
+ pinfo->red_bits = util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 0);
+ pinfo->green_bits = util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 1);
+ pinfo->blue_bits = util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 2);
+ pinfo->alpha_bits = util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 3);
+ pinfo->depth_bits = util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_ZS, 0);
+ pinfo->stencil_bits = util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_ZS, 1);
pinfo->luminance_bits = 0;
pinfo->intensity_bits = 0;
}
/* map pipe format to base format for now */
- if (pf_get_component_bits(format, PIPE_FORMAT_COMP_A) > 0)
+ if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 3) > 0)
internalFormat = GL_RGBA;
else
internalFormat = GL_RGB;