diff options
Diffstat (limited to 'mesalib/src')
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_format.c | 94 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_format.h | 19 | ||||
-rw-r--r-- | mesalib/src/mesa/main/dlist.c | 15 | ||||
-rw-r--r-- | mesalib/src/mesa/main/drawpix.c | 2 | ||||
-rw-r--r-- | mesalib/src/mesa/state_tracker/st_cb_texture.c | 7 |
5 files changed, 131 insertions, 6 deletions
diff --git a/mesalib/src/gallium/auxiliary/util/u_format.c b/mesalib/src/gallium/auxiliary/util/u_format.c index 34922ab18..700382a0f 100644 --- a/mesalib/src/gallium/auxiliary/util/u_format.c +++ b/mesalib/src/gallium/auxiliary/util/u_format.c @@ -67,6 +67,100 @@ util_format_is_float(enum pipe_format format) } +/** + * Return the number of logical channels in the given format by + * examining swizzles. + * XXX this could be made into a public function if useful elsewhere. + */ +static unsigned +nr_logical_channels(const struct util_format_description *desc) +{ + boolean swizzle_used[UTIL_FORMAT_SWIZZLE_MAX]; + + memset(swizzle_used, 0, sizeof(swizzle_used)); + + swizzle_used[desc->swizzle[0]] = TRUE; + swizzle_used[desc->swizzle[1]] = TRUE; + swizzle_used[desc->swizzle[2]] = TRUE; + swizzle_used[desc->swizzle[3]] = TRUE; + + return (swizzle_used[UTIL_FORMAT_SWIZZLE_X] + + swizzle_used[UTIL_FORMAT_SWIZZLE_Y] + + swizzle_used[UTIL_FORMAT_SWIZZLE_Z] + + swizzle_used[UTIL_FORMAT_SWIZZLE_W]); +} + + +/** Test if the format contains RGB, but not alpha */ +boolean +util_format_is_rgb_no_alpha(enum pipe_format format) +{ + const struct util_format_description *desc = + util_format_description(format); + + if ((desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB || + desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) && + nr_logical_channels(desc) == 3) { + return TRUE; + } + return FALSE; +} + + +boolean +util_format_is_luminance(enum pipe_format format) +{ + const struct util_format_description *desc = + util_format_description(format); + + if ((desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB || + desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) && + desc->swizzle[0] == UTIL_FORMAT_SWIZZLE_X && + desc->swizzle[1] == UTIL_FORMAT_SWIZZLE_X && + desc->swizzle[2] == UTIL_FORMAT_SWIZZLE_X && + desc->swizzle[3] == UTIL_FORMAT_SWIZZLE_1) { + return TRUE; + } + return FALSE; +} + + +boolean +util_format_is_luminance_alpha(enum pipe_format format) +{ + const struct util_format_description *desc = + util_format_description(format); + + if ((desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB || + desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) && + desc->swizzle[0] == UTIL_FORMAT_SWIZZLE_X && + desc->swizzle[1] == UTIL_FORMAT_SWIZZLE_X && + desc->swizzle[2] == UTIL_FORMAT_SWIZZLE_X && + desc->swizzle[3] == UTIL_FORMAT_SWIZZLE_Y) { + return TRUE; + } + return FALSE; +} + + +boolean +util_format_is_intensity(enum pipe_format format) +{ + const struct util_format_description *desc = + util_format_description(format); + + if ((desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB || + desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) && + desc->swizzle[0] == UTIL_FORMAT_SWIZZLE_X && + desc->swizzle[1] == UTIL_FORMAT_SWIZZLE_X && + desc->swizzle[2] == UTIL_FORMAT_SWIZZLE_X && + desc->swizzle[3] == UTIL_FORMAT_SWIZZLE_X) { + return TRUE; + } + return FALSE; +} + + boolean util_format_is_supported(enum pipe_format format, unsigned bind) { diff --git a/mesalib/src/gallium/auxiliary/util/u_format.h b/mesalib/src/gallium/auxiliary/util/u_format.h index 352710310..2eb3e1b80 100644 --- a/mesalib/src/gallium/auxiliary/util/u_format.h +++ b/mesalib/src/gallium/auxiliary/util/u_format.h @@ -105,7 +105,8 @@ enum util_format_swizzle { UTIL_FORMAT_SWIZZLE_W = 3, UTIL_FORMAT_SWIZZLE_0 = 4, UTIL_FORMAT_SWIZZLE_1 = 5, - UTIL_FORMAT_SWIZZLE_NONE = 6 + UTIL_FORMAT_SWIZZLE_NONE = 6, + UTIL_FORMAT_SWIZZLE_MAX = 7 /**< Number of enums counter (must be last) */ }; @@ -477,6 +478,22 @@ boolean util_format_is_float(enum pipe_format format); +boolean +util_format_is_rgb_no_alpha(enum pipe_format format); + + +boolean +util_format_is_luminance(enum pipe_format format); + + +boolean +util_format_is_luminance_alpha(enum pipe_format format); + + +boolean +util_format_is_intensity(enum pipe_format format); + + /** * Whether the src format can be blitted to destation format with a simple * memcpy. diff --git a/mesalib/src/mesa/main/dlist.c b/mesalib/src/mesa/main/dlist.c index 6e075b4e5..2b2ff9015 100644 --- a/mesalib/src/mesa/main/dlist.c +++ b/mesalib/src/mesa/main/dlist.c @@ -871,7 +871,11 @@ translate_id(GLsizei n, GLenum type, const GLvoid * list) /** * Wrapper for _mesa_unpack_image() that handles pixel buffer objects. - * If we run out of memory, GL_OUT_OF_MEMORY will be recorded. + * If width < 0 or height < 0 or format or type are invalid we'll just + * return NULL. We will not generate an error since OpenGL command + * arguments aren't error-checked until the command is actually executed + * (not when they're compiled). + * But if we run out of memory, GL_OUT_OF_MEMORY will be recorded. */ static GLvoid * unpack_image(struct gl_context *ctx, GLuint dimensions, @@ -879,6 +883,15 @@ unpack_image(struct gl_context *ctx, GLuint dimensions, GLenum format, GLenum type, const GLvoid * pixels, const struct gl_pixelstore_attrib *unpack) { + if (width <= 0 || height <= 0) { + return NULL; + } + + if (_mesa_bytes_per_pixel(format, type) <= 0) { + /* bad format and/or type */ + return NULL; + } + if (!_mesa_is_bufferobj(unpack->BufferObj)) { /* no PBO */ GLvoid *image = _mesa_unpack_image(dimensions, width, height, depth, diff --git a/mesalib/src/mesa/main/drawpix.c b/mesalib/src/mesa/main/drawpix.c index 89c2b2697..b7e2c36e1 100644 --- a/mesalib/src/mesa/main/drawpix.c +++ b/mesalib/src/mesa/main/drawpix.c @@ -62,7 +62,7 @@ _mesa_DrawPixels( GLsizei width, GLsizei height, if (width < 0 || height < 0) { - _mesa_error( ctx, GL_INVALID_VALUE, "glDrawPixels(width or height < 0" ); + _mesa_error( ctx, GL_INVALID_VALUE, "glDrawPixels(width or height < 0)" ); return; } diff --git a/mesalib/src/mesa/state_tracker/st_cb_texture.c b/mesalib/src/mesa/state_tracker/st_cb_texture.c index e4be7fba4..eab02fb3b 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_texture.c +++ b/mesalib/src/mesa/state_tracker/st_cb_texture.c @@ -1829,9 +1829,10 @@ st_finalize_texture(struct gl_context *ctx, /* Need to import images in main memory or held in other textures. */ if (stImage && stObj->pt != stImage->pt) { - if (level == 0 || (stImage->base.Width == u_minify(stObj->width0, level) && - stImage->base.Height == u_minify(stObj->height0, level) && - stImage->base.Depth == u_minify(stObj->depth0, level))) { + if (level == 0 || + (stImage->base.Width == u_minify(stObj->width0, level) && + stImage->base.Height == u_minify(stObj->height0, level) && + stImage->base.Depth == u_minify(stObj->depth0, level))) { /* src image fits expected dest mipmap level size */ copy_image_data_to_texture(st, stObj, level, stImage); } |