Commit 9ad8f431 authored by Jordan Justen's avatar Jordan Justen

mesa: add glformats integer type/format detection routines

_mesa_is_integer_format is moved to formats.c and renamed
as _mesa_is_enum_format_integer.

_mesa_is_format_unsigned, _mesa_is_type_integer,
_mesa_is_type_unsigned, and _mesa_is_enum_format_or_type_integer
are added.
Signed-off-by: default avatarJordan Justen <jordan.l.justen@intel.com>
Reviewed-by: default avatarBrian Paul <brianp@vmware.com>
parent e2e7b467
......@@ -80,6 +80,7 @@ main_sources = [
'main/framebuffer.c',
'main/get.c',
'main/getstring.c',
'main/glformats.c',
'main/hash.c',
'main/hint.c',
'main/histogram.c',
......
......@@ -35,6 +35,7 @@
#include "pbo.h"
#include "state.h"
#include "dispatch.h"
#include "glformats.h"
#if FEATURE_drawpix
......@@ -89,7 +90,7 @@ _mesa_DrawPixels( GLsizei width, GLsizei height,
* input), NVIDIA's implementation also just returns this error despite
* exposing GL_EXT_texture_integer, just return an error regardless.
*/
if (_mesa_is_integer_format(format)) {
if (_mesa_is_enum_format_integer(format)) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glDrawPixels(integer format)");
goto end;
}
......
......@@ -28,6 +28,7 @@
#include "formats.h"
#include "mfeatures.h"
#include "macros.h"
#include "glformats.h"
/**
......@@ -1711,6 +1712,17 @@ _mesa_is_format_integer_color(gl_format format)
}
/**
* Is the given format an unsigned integer format?
*/
GLboolean
_mesa_is_format_unsigned(gl_format format)
{
const struct gl_format_info *info = _mesa_get_format_info(format);
return _mesa_is_type_unsigned(info->DataType);
}
/**
* Return color encoding for given format.
* \return GL_LINEAR or GL_SRGB
......@@ -2933,3 +2945,4 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
return GL_FALSE;
}
......@@ -311,6 +311,9 @@ _mesa_is_format_packed_depth_stencil(gl_format format);
extern GLboolean
_mesa_is_format_integer_color(gl_format format);
extern GLboolean
_mesa_is_format_unsigned(gl_format format);
extern GLenum
_mesa_get_format_color_encoding(gl_format format);
......@@ -346,7 +349,6 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
GLenum format, GLenum type,
GLboolean swapBytes);
#ifdef __cplusplus
}
#endif
......
/*
* Mesa 3-D graphics library
*
* Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
* Copyright (c) 2008-2009 VMware, Inc.
* Copyright (c) 2012 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "imports.h"
#include "glformats.h"
/**
* Test if the given format is an integer (non-normalized) format.
*/
GLboolean
_mesa_is_enum_format_integer(GLenum format)
{
switch (format) {
/* generic integer formats */
case GL_RED_INTEGER_EXT:
case GL_GREEN_INTEGER_EXT:
case GL_BLUE_INTEGER_EXT:
case GL_ALPHA_INTEGER_EXT:
case GL_RGB_INTEGER_EXT:
case GL_RGBA_INTEGER_EXT:
case GL_BGR_INTEGER_EXT:
case GL_BGRA_INTEGER_EXT:
case GL_LUMINANCE_INTEGER_EXT:
case GL_LUMINANCE_ALPHA_INTEGER_EXT:
case GL_RG_INTEGER:
/* specific integer formats */
case GL_RGBA32UI_EXT:
case GL_RGB32UI_EXT:
case GL_RG32UI:
case GL_R32UI:
case GL_ALPHA32UI_EXT:
case GL_INTENSITY32UI_EXT:
case GL_LUMINANCE32UI_EXT:
case GL_LUMINANCE_ALPHA32UI_EXT:
case GL_RGBA16UI_EXT:
case GL_RGB16UI_EXT:
case GL_RG16UI:
case GL_R16UI:
case GL_ALPHA16UI_EXT:
case GL_INTENSITY16UI_EXT:
case GL_LUMINANCE16UI_EXT:
case GL_LUMINANCE_ALPHA16UI_EXT:
case GL_RGBA8UI_EXT:
case GL_RGB8UI_EXT:
case GL_RG8UI:
case GL_R8UI:
case GL_ALPHA8UI_EXT:
case GL_INTENSITY8UI_EXT:
case GL_LUMINANCE8UI_EXT:
case GL_LUMINANCE_ALPHA8UI_EXT:
case GL_RGBA32I_EXT:
case GL_RGB32I_EXT:
case GL_RG32I:
case GL_R32I:
case GL_ALPHA32I_EXT:
case GL_INTENSITY32I_EXT:
case GL_LUMINANCE32I_EXT:
case GL_LUMINANCE_ALPHA32I_EXT:
case GL_RGBA16I_EXT:
case GL_RGB16I_EXT:
case GL_RG16I:
case GL_R16I:
case GL_ALPHA16I_EXT:
case GL_INTENSITY16I_EXT:
case GL_LUMINANCE16I_EXT:
case GL_LUMINANCE_ALPHA16I_EXT:
case GL_RGBA8I_EXT:
case GL_RGB8I_EXT:
case GL_RG8I:
case GL_R8I:
case GL_ALPHA8I_EXT:
case GL_INTENSITY8I_EXT:
case GL_LUMINANCE8I_EXT:
case GL_LUMINANCE_ALPHA8I_EXT:
case GL_RGB10_A2UI:
return GL_TRUE;
default:
return GL_FALSE;
}
}
/**
* Test if the given type is an integer (non-normalized) format.
*/
GLboolean
_mesa_is_type_integer(GLenum type)
{
switch (type) {
case GL_INT:
case GL_UNSIGNED_INT:
case GL_SHORT:
case GL_UNSIGNED_SHORT:
case GL_BYTE:
case GL_UNSIGNED_BYTE:
return GL_TRUE;
default:
return GL_FALSE;
}
}
/**
* Test if the given format or type is an integer (non-normalized) format.
*/
extern GLboolean
_mesa_is_enum_format_or_type_integer(GLenum format, GLenum type)
{
return _mesa_is_enum_format_integer(format) || _mesa_is_type_integer(type);
}
GLboolean
_mesa_is_type_unsigned(GLenum type)
{
switch (type) {
case GL_UNSIGNED_INT:
case GL_UNSIGNED_INT_8_8_8_8:
case GL_UNSIGNED_INT_8_8_8_8_REV:
case GL_UNSIGNED_INT_10_10_10_2:
case GL_UNSIGNED_INT_2_10_10_10_REV:
case GL_UNSIGNED_SHORT:
case GL_UNSIGNED_SHORT_4_4_4_4:
case GL_UNSIGNED_SHORT_5_5_5_1:
case GL_UNSIGNED_SHORT_5_6_5:
case GL_UNSIGNED_SHORT_5_6_5_REV:
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
case GL_UNSIGNED_SHORT_8_8_MESA:
case GL_UNSIGNED_SHORT_8_8_REV_MESA:
case GL_UNSIGNED_BYTE:
case GL_UNSIGNED_BYTE_3_3_2:
case GL_UNSIGNED_BYTE_2_3_3_REV:
return GL_TRUE;
default:
return GL_FALSE;
}
}
/**
* Convert various base formats to the cooresponding integer format.
*/
GLenum
_mesa_base_format_to_integer_format(GLenum format)
{
switch(format) {
case GL_RED:
return GL_RED_INTEGER;
case GL_GREEN:
return GL_GREEN_INTEGER;
case GL_BLUE:
return GL_BLUE_INTEGER;
case GL_RG:
return GL_RG_INTEGER;
case GL_RGB:
return GL_RGB_INTEGER;
case GL_RGBA:
return GL_RGBA_INTEGER;
case GL_BGR:
return GL_BGR_INTEGER;
case GL_BGRA:
return GL_BGRA_INTEGER;
case GL_ALPHA:
return GL_ALPHA_INTEGER;
case GL_LUMINANCE:
return GL_LUMINANCE_INTEGER_EXT;
case GL_LUMINANCE_ALPHA:
return GL_LUMINANCE_ALPHA_INTEGER_EXT;
}
return format;
}
/*
* Mesa 3-D graphics library
*
* Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
* Copyright (c) 2008-2009 VMware, Inc.
* Copyright (c) 2012 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef GLFORMATS_H
#define GLFORMATS_H
#include <GL/gl.h>
#ifdef __cplusplus
extern "C" {
#endif
extern GLboolean
_mesa_is_type_integer(GLenum type);
extern GLboolean
_mesa_is_type_unsigned(GLenum type);
extern GLboolean
_mesa_is_enum_format_integer(GLenum format);
extern GLboolean
_mesa_is_enum_format_or_type_integer(GLenum format, GLenum type);
extern GLenum
_mesa_base_format_to_integer_format(GLenum format);
#ifdef __cplusplus
}
#endif
#endif /* GLFORMATS_H */
......@@ -1057,82 +1057,6 @@ _mesa_is_dudv_format(GLenum format)
}
/**
* Test if the given format is an integer (non-normalized) format.
*/
GLboolean
_mesa_is_integer_format(GLenum format)
{
switch (format) {
/* generic integer formats */
case GL_RED_INTEGER_EXT:
case GL_GREEN_INTEGER_EXT:
case GL_BLUE_INTEGER_EXT:
case GL_ALPHA_INTEGER_EXT:
case GL_RGB_INTEGER_EXT:
case GL_RGBA_INTEGER_EXT:
case GL_BGR_INTEGER_EXT:
case GL_BGRA_INTEGER_EXT:
case GL_LUMINANCE_INTEGER_EXT:
case GL_LUMINANCE_ALPHA_INTEGER_EXT:
case GL_RG_INTEGER:
/* specific integer formats */
case GL_RGBA32UI_EXT:
case GL_RGB32UI_EXT:
case GL_RG32UI:
case GL_R32UI:
case GL_ALPHA32UI_EXT:
case GL_INTENSITY32UI_EXT:
case GL_LUMINANCE32UI_EXT:
case GL_LUMINANCE_ALPHA32UI_EXT:
case GL_RGBA16UI_EXT:
case GL_RGB16UI_EXT:
case GL_RG16UI:
case GL_R16UI:
case GL_ALPHA16UI_EXT:
case GL_INTENSITY16UI_EXT:
case GL_LUMINANCE16UI_EXT:
case GL_LUMINANCE_ALPHA16UI_EXT:
case GL_RGBA8UI_EXT:
case GL_RGB8UI_EXT:
case GL_RG8UI:
case GL_R8UI:
case GL_ALPHA8UI_EXT:
case GL_INTENSITY8UI_EXT:
case GL_LUMINANCE8UI_EXT:
case GL_LUMINANCE_ALPHA8UI_EXT:
case GL_RGBA32I_EXT:
case GL_RGB32I_EXT:
case GL_RG32I:
case GL_R32I:
case GL_ALPHA32I_EXT:
case GL_INTENSITY32I_EXT:
case GL_LUMINANCE32I_EXT:
case GL_LUMINANCE_ALPHA32I_EXT:
case GL_RGBA16I_EXT:
case GL_RGB16I_EXT:
case GL_RG16I:
case GL_R16I:
case GL_ALPHA16I_EXT:
case GL_INTENSITY16I_EXT:
case GL_LUMINANCE16I_EXT:
case GL_LUMINANCE_ALPHA16I_EXT:
case GL_RGBA8I_EXT:
case GL_RGB8I_EXT:
case GL_RG8I:
case GL_R8I:
case GL_ALPHA8I_EXT:
case GL_INTENSITY8I_EXT:
case GL_LUMINANCE8I_EXT:
case GL_LUMINANCE_ALPHA8I_EXT:
case GL_RGB10_A2UI:
return GL_TRUE;
default:
return GL_FALSE;
}
}
/**
* Test if an image format is a supported compressed format.
* \param format the internal format token provided by the user.
......
......@@ -78,9 +78,6 @@ _mesa_is_depth_or_stencil_format(GLenum format);
extern GLboolean
_mesa_is_dudv_format(GLenum format);
extern GLboolean
_mesa_is_integer_format(GLenum format);
extern GLboolean
_mesa_is_compressed_format(struct gl_context *ctx, GLenum format);
......
......@@ -52,6 +52,7 @@
#include "pack.h"
#include "pixeltransfer.h"
#include "imports.h"
#include "glformats.h"
#include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
#include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
......@@ -558,7 +559,7 @@ _mesa_pack_rgba_span_float(struct gl_context *ctx, GLuint n, GLfloat rgba[][4],
{
GLfloat *luminance;
const GLint comps = _mesa_components_in_format(dstFormat);
const GLboolean intDstFormat = _mesa_is_integer_format(dstFormat);
const GLboolean intDstFormat = _mesa_is_enum_format_integer(dstFormat);
GLuint i;
if (dstFormat == GL_LUMINANCE ||
......@@ -2489,7 +2490,7 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4],
stride = _mesa_components_in_format(srcFormat);
intFormat = _mesa_is_integer_format(srcFormat);
intFormat = _mesa_is_enum_format_integer(srcFormat);
#define PROCESS(SRC_INDEX, DST_INDEX, DEFAULT_FLT, DEFAULT_INT, TYPE, CONVERSION) \
if ((SRC_INDEX) < 0) { \
......@@ -3544,7 +3545,7 @@ _mesa_unpack_color_span_ubyte(struct gl_context *ctx,
const struct gl_pixelstore_attrib *srcPacking,
GLbitfield transferOps )
{
GLboolean intFormat = _mesa_is_integer_format(srcFormat);
GLboolean intFormat = _mesa_is_enum_format_integer(srcFormat);
ASSERT(dstFormat == GL_ALPHA ||
dstFormat == GL_LUMINANCE ||
dstFormat == GL_LUMINANCE_ALPHA ||
......@@ -3851,7 +3852,7 @@ _mesa_unpack_color_span_float( struct gl_context *ctx,
GLint dstComponents;
GLint rDst, gDst, bDst, aDst, lDst, iDst;
GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * n * sizeof(GLfloat));
GLboolean intFormat = _mesa_is_integer_format(srcFormat);
GLboolean intFormat = _mesa_is_enum_format_integer(srcFormat);
if (!rgba) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
......
......@@ -36,6 +36,7 @@
#include "pack.h"
#include "pbo.h"
#include "state.h"
#include "glformats.h"
/**
......@@ -337,7 +338,7 @@ slow_read_rgba_pixels( struct gl_context *ctx,
goto done;
for (j = 0; j < height; j++) {
if (_mesa_is_integer_format(format)) {
if (_mesa_is_enum_format_integer(format)) {
_mesa_unpack_uint_rgba_row(rbFormat, width, map, (GLuint (*)[4]) rgba);
_mesa_rebase_rgba_uint(width, (GLuint (*)[4]) rgba,
rb->_BaseFormat);
......@@ -378,7 +379,7 @@ read_rgba_pixels( struct gl_context *ctx,
return;
if ((ctx->Color._ClampReadColor == GL_TRUE || type != GL_FLOAT) &&
!_mesa_is_integer_format(format)) {
!_mesa_is_enum_format_integer(format)) {
transferOps |= IMAGE_CLAMP_BIT;
}
......@@ -713,7 +714,7 @@ _mesa_ReadnPixelsARB( GLint x, GLint y, GLsizei width, GLsizei height,
if (ctx->Extensions.EXT_texture_integer && _mesa_is_color_format(format)) {
const struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
const GLboolean srcInteger = _mesa_is_format_integer_color(rb->Format);
const GLboolean dstInteger = _mesa_is_integer_format(format);
const GLboolean dstInteger = _mesa_is_enum_format_integer(format);
if (dstInteger != srcInteger) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glReadPixels(integer / non-integer format mismatch");
......
......@@ -47,6 +47,7 @@
#include "texstate.h"
#include "texpal.h"
#include "mtypes.h"
#include "glformats.h"
/**
......@@ -1764,8 +1765,8 @@ texture_error_check( struct gl_context *ctx,
/* additional checks for integer textures */
if ((ctx->VersionMajor >= 3 || ctx->Extensions.EXT_texture_integer) &&
(_mesa_is_integer_format(format) !=
_mesa_is_integer_format(internalFormat))) {
(_mesa_is_enum_format_integer(format) !=
_mesa_is_enum_format_integer(internalFormat))) {
if (!isProxy) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glTexImage%dD(integer/non-integer format mismatch)",
......@@ -1939,7 +1940,7 @@ subtexture_error_check2( struct gl_context *ctx, GLuint dimensions,
if (ctx->VersionMajor >= 3 || ctx->Extensions.EXT_texture_integer) {
/* both source and dest must be integer-valued, or neither */
if (_mesa_is_format_integer_color(destTex->TexFormat) !=
_mesa_is_integer_format(format)) {
_mesa_is_enum_format_integer(format)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glTexSubImage%dD(integer/non-integer format mismatch)",
dimensions);
......@@ -2042,8 +2043,8 @@ copytexture_error_check( struct gl_context *ctx, GLuint dimensions,
if (_mesa_is_color_format(internalFormat)) {
struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
if (_mesa_is_integer_format(rb->InternalFormat) !=
_mesa_is_integer_format(internalFormat)) {
if (_mesa_is_enum_format_integer(rb->InternalFormat) !=
_mesa_is_enum_format_integer(internalFormat)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glCopyTexImage%dD(integer vs non-integer)", dimensions);
return GL_TRUE;
......
......@@ -49,6 +49,7 @@ MAIN_FILES = \
$(SRCDIR)/main/framebuffer.c \
$(SRCDIR)/main/get.c \
$(SRCDIR)/main/getstring.c \
$(SRCDIR)/main/glformats.c \
$(SRCDIR)/main/hash.c \
$(SRCDIR)/main/hint.c \
$(SRCDIR)/main/histogram.c \
......
......@@ -43,6 +43,7 @@
#include "main/texformat.h"
#include "main/teximage.h"
#include "main/texstore.h"
#include "main/glformats.h"
#include "program/program.h"
#include "program/prog_print.h"
#include "program/prog_instruction.h"
......@@ -368,7 +369,7 @@ internal_format(struct gl_context *ctx, GLenum format, GLenum type)
return GL_STENCIL_INDEX;
default:
if (_mesa_is_integer_format(format)) {
if (_mesa_is_enum_format_integer(format)) {
switch (type) {
case GL_BYTE:
return GL_RGBA8I;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment