New error checking in _mesa_GetTexImage().
Updated comments and some better function parameter names.
This commit is contained in:
@@ -135,10 +135,11 @@ logbase2( int n )
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get base internal format.
|
* Return the simple base format for a given internal texture format.
|
||||||
|
* For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
|
||||||
*
|
*
|
||||||
* \param ctx GL context.
|
* \param ctx GL context.
|
||||||
* \param format internal texture format enum or 1, 2, 3, 4.
|
* \param internalFormat the internal texture format token or 1, 2, 3, or 4.
|
||||||
*
|
*
|
||||||
* \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
|
* \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
|
||||||
* GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
|
* GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
|
||||||
@@ -147,13 +148,9 @@ logbase2( int n )
|
|||||||
* texture format and env mode determine the arithmetic used.
|
* texture format and env mode determine the arithmetic used.
|
||||||
*/
|
*/
|
||||||
GLint
|
GLint
|
||||||
_mesa_base_tex_format( GLcontext *ctx, GLint format )
|
_mesa_base_tex_format( GLcontext *ctx, GLint internalFormat )
|
||||||
{
|
{
|
||||||
/*
|
switch (internalFormat) {
|
||||||
* Ask the driver for the base format, if it doesn't
|
|
||||||
* know, it will return -1;
|
|
||||||
*/
|
|
||||||
switch (format) {
|
|
||||||
case GL_ALPHA:
|
case GL_ALPHA:
|
||||||
case GL_ALPHA4:
|
case GL_ALPHA4:
|
||||||
case GL_ALPHA8:
|
case GL_ALPHA8:
|
||||||
@@ -294,6 +291,8 @@ _mesa_base_tex_format( GLcontext *ctx, GLint format )
|
|||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
/* XXX add float texture formats here */
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -1; /* error */
|
return -1; /* error */
|
||||||
}
|
}
|
||||||
@@ -301,13 +300,15 @@ _mesa_base_tex_format( GLcontext *ctx, GLint format )
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if the given image format is a color/RGBA format, i.e., not
|
* Test if the given internal texture format is a color/RGBA format
|
||||||
* color index, depth, stencil, etc.
|
* (i.e., not color index, depth, stencil, etc).
|
||||||
|
* \param internalFormat an internal texture format token (or 1, 2, 3, or 4)
|
||||||
|
* \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
static GLboolean
|
static GLboolean
|
||||||
is_color_format(GLenum format)
|
is_color_format(GLenum internalFormat)
|
||||||
{
|
{
|
||||||
switch (format) {
|
switch (internalFormat) {
|
||||||
case GL_ALPHA:
|
case GL_ALPHA:
|
||||||
case GL_ALPHA4:
|
case GL_ALPHA4:
|
||||||
case GL_ALPHA8:
|
case GL_ALPHA8:
|
||||||
@@ -350,6 +351,7 @@ is_color_format(GLenum format)
|
|||||||
case GL_RGB10_A2:
|
case GL_RGB10_A2:
|
||||||
case GL_RGBA12:
|
case GL_RGBA12:
|
||||||
case GL_RGBA16:
|
case GL_RGBA16:
|
||||||
|
/* XXX add float texture formats here */
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
case GL_YCBCR_MESA: /* not considered to be RGB */
|
case GL_YCBCR_MESA: /* not considered to be RGB */
|
||||||
default:
|
default:
|
||||||
@@ -359,12 +361,12 @@ is_color_format(GLenum format)
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if the given image format is a color index format.
|
* Test if the given internal texture format is a color index format.
|
||||||
*/
|
*/
|
||||||
static GLboolean
|
static GLboolean
|
||||||
is_index_format(GLenum format)
|
is_index_format(GLenum internalFormat)
|
||||||
{
|
{
|
||||||
switch (format) {
|
switch (internalFormat) {
|
||||||
case GL_COLOR_INDEX:
|
case GL_COLOR_INDEX:
|
||||||
case GL_COLOR_INDEX1_EXT:
|
case GL_COLOR_INDEX1_EXT:
|
||||||
case GL_COLOR_INDEX2_EXT:
|
case GL_COLOR_INDEX2_EXT:
|
||||||
@@ -379,6 +381,39 @@ is_index_format(GLenum format)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if the given internal texture format is a depth component format.
|
||||||
|
*/
|
||||||
|
static GLboolean
|
||||||
|
is_depth_format(GLenum internalFormat)
|
||||||
|
{
|
||||||
|
switch (internalFormat) {
|
||||||
|
case GL_DEPTH_COMPONENT16_ARB:
|
||||||
|
case GL_DEPTH_COMPONENT24_ARB:
|
||||||
|
case GL_DEPTH_COMPONENT32_ARB:
|
||||||
|
case GL_DEPTH_COMPONENT:
|
||||||
|
return GL_TRUE;
|
||||||
|
default:
|
||||||
|
return GL_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if the given internal texture format is a YCbCr format.
|
||||||
|
*/
|
||||||
|
static GLboolean
|
||||||
|
is_ycbcr_format(GLenum internalFormat)
|
||||||
|
{
|
||||||
|
switch (internalFormat) {
|
||||||
|
case GL_YCBCR_MESA:
|
||||||
|
return GL_TRUE;
|
||||||
|
default:
|
||||||
|
return GL_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if it is a supported compressed format.
|
* Test if it is a supported compressed format.
|
||||||
*
|
*
|
||||||
@@ -1786,13 +1821,13 @@ copytexsubimage_error_check( GLcontext *ctx, GLuint dimensions,
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get texture image.
|
* Get texture image. Called by glGetTexImage.
|
||||||
*
|
*
|
||||||
* \param target texture target.
|
* \param target texture target.
|
||||||
* \param level image level.
|
* \param level image level.
|
||||||
* \param format pixel data format.
|
* \param format pixel data format for returned image.
|
||||||
* \param type pixel data type.
|
* \param type pixel data type for returned image.
|
||||||
* \param pixels pixel data.
|
* \param pixels returned pixel data.
|
||||||
*/
|
*/
|
||||||
void GLAPIENTRY
|
void GLAPIENTRY
|
||||||
_mesa_GetTexImage( GLenum target, GLint level, GLenum format,
|
_mesa_GetTexImage( GLenum target, GLint level, GLenum format,
|
||||||
@@ -1835,16 +1870,14 @@ _mesa_GetTexImage( GLenum target, GLint level, GLenum format,
|
|||||||
_mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
|
_mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx->Extensions.SGIX_depth_texture && format == GL_DEPTH_COMPONENT) {
|
if (!ctx->Extensions.SGIX_depth_texture && is_depth_format(format)) {
|
||||||
_mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
|
_mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx->Extensions.MESA_ycbcr_texture && format == GL_YCBCR_MESA) {
|
if (!ctx->Extensions.MESA_ycbcr_texture && is_ycbcr_format(format)) {
|
||||||
_mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
|
_mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX what if format/type doesn't match texture format/type? */
|
|
||||||
|
|
||||||
if (!pixels)
|
if (!pixels)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1859,6 +1892,32 @@ _mesa_GetTexImage( GLenum target, GLint level, GLenum format,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Make sure the requested image format is compatible with the
|
||||||
|
* texture's format.
|
||||||
|
*/
|
||||||
|
if (is_color_format(format)
|
||||||
|
&& !is_color_format(texImage->TexFormat->BaseFormat)) {
|
||||||
|
_mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (is_index_format(format)
|
||||||
|
&& !is_index_format(texImage->TexFormat->BaseFormat)) {
|
||||||
|
_mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (is_depth_format(format)
|
||||||
|
&& !is_depth_format(texImage->TexFormat->BaseFormat)) {
|
||||||
|
_mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (is_ycbcr_format(format)
|
||||||
|
&& !is_ycbcr_format(texImage->TexFormat->BaseFormat)) {
|
||||||
|
_mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const GLint width = texImage->Width;
|
const GLint width = texImage->Width;
|
||||||
const GLint height = texImage->Height;
|
const GLint height = texImage->Height;
|
||||||
|
@@ -5,9 +5,9 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Mesa 3-D graphics library
|
* Mesa 3-D graphics library
|
||||||
* Version: 5.1
|
* Version: 6.1
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
|
* Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
/*@{*/
|
/*@{*/
|
||||||
|
|
||||||
extern GLint
|
extern GLint
|
||||||
_mesa_base_tex_format( GLcontext *ctx, GLint format );
|
_mesa_base_tex_format( GLcontext *ctx, GLint internalFormat );
|
||||||
|
|
||||||
|
|
||||||
extern struct gl_texture_image *
|
extern struct gl_texture_image *
|
||||||
|
Reference in New Issue
Block a user