/*
* Mesa 3-D graphics library
- * Version: 6.3
+ * Version: 6.5
*
* Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
*
#include "colortab.h"
#include "context.h"
#include "enums.h"
-#include "extensions.h"
#include "macros.h"
-#include "nvfragprog.h"
#include "texobj.h"
#include "teximage.h"
#include "texstate.h"
+#include "texenvprogram.h"
#include "mtypes.h"
#include "math/m_xform.h"
-#include "math/m_matrix.h"
-#ifdef SPECIALCAST
-/* Needed for an Amiga compiler */
#define ENUM_TO_FLOAT(X) ((GLfloat)(GLint)(X))
#define ENUM_TO_DOUBLE(X) ((GLdouble)(GLint)(X))
-#else
-/* all other compilers */
-#define ENUM_TO_FLOAT(X) ((GLfloat)(X))
-#define ENUM_TO_DOUBLE(X) ((GLdouble)(X))
-#endif
+
/**
* Default texture combine environment state. This is used to initialize
}
break;
case GL_OPERAND2_RGB:
- if (ctx->Extensions.EXT_texture_env_combine ||
- ctx->Extensions.ARB_texture_env_combine) {
+ if (ctx->Extensions.ARB_texture_env_combine) {
const GLenum operand = (GLenum) (GLint) *param;
if (texUnit->Combine.OperandRGB[2] == operand)
return;
return;
}
}
+ else if (ctx->Extensions.EXT_texture_env_combine) {
+ const GLenum operand = (GLenum) (GLint) *param;
+ if (texUnit->Combine.OperandRGB[2] == operand)
+ return;
+ /* operand must be GL_SRC_ALPHA which is the initial value - thus
+ don't need to actually compare the operand to the possible value */
+ else {
+ TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand);
+ return;
+ }
+ }
else {
TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
return;
}
break;
case GL_OPERAND2_ALPHA:
- if (ctx->Extensions.EXT_texture_env_combine ||
- ctx->Extensions.ARB_texture_env_combine) {
+ if (ctx->Extensions.ARB_texture_env_combine) {
const GLenum operand = (GLenum) (GLint) *param;
if (texUnit->Combine.OperandA[2] == operand)
return;
return;
}
}
+ else if (ctx->Extensions.EXT_texture_env_combine) {
+ const GLenum operand = (GLenum) (GLint) *param;
+ if (texUnit->Combine.OperandA[2] == operand)
+ return;
+ /* operand must be GL_SRC_ALPHA which is the initial value - thus
+ don't need to actually compare the operand to the possible value */
+ else {
+ TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand);
+ return;
+ }
+ }
else {
TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
return;
return;
}
- switch (target) {
- case GL_TEXTURE_1D:
- case GL_PROXY_TEXTURE_1D:
- case GL_TEXTURE_2D:
- case GL_PROXY_TEXTURE_2D:
- maxLevels = ctx->Const.MaxTextureLevels;
- break;
- case GL_TEXTURE_3D:
- case GL_PROXY_TEXTURE_3D:
- maxLevels = ctx->Const.Max3DTextureLevels;
- break;
- case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
- case GL_PROXY_TEXTURE_CUBE_MAP:
- maxLevels = ctx->Const.MaxCubeTextureLevels;
- break;
- case GL_TEXTURE_RECTANGLE_NV:
- case GL_PROXY_TEXTURE_RECTANGLE_NV:
- maxLevels = 1;
- break;
- default:
- _mesa_problem(ctx, "switch in _mesa_GetTexLevelParameter");
+ maxLevels = _mesa_max_texture_levels(ctx, target);
+ if (maxLevels == 0) {
+ /* should not happen since <target> was just checked above */
+ _mesa_problem(ctx, "maxLevels=0 in _mesa_GetTexLevelParameter");
return;
}
return;
}
- isProxy = (target == GL_PROXY_TEXTURE_1D) ||
- (target == GL_PROXY_TEXTURE_2D) ||
- (target == GL_PROXY_TEXTURE_3D) ||
- (target == GL_PROXY_TEXTURE_CUBE_MAP) ||
- (target == GL_PROXY_TEXTURE_RECTANGLE_NV);
+ isProxy = _mesa_is_proxy_texture(target);
switch (pname) {
case GL_TEXTURE_WIDTH:
*params = img->Depth;
return;
case GL_TEXTURE_INTERNAL_FORMAT:
- *params = img->IntFormat;
+ *params = img->InternalFormat;
return;
case GL_TEXTURE_BORDER:
*params = img->Border;
return;
case GL_TEXTURE_RED_SIZE:
- if (img->Format == GL_RGB || img->Format == GL_RGBA)
+ if (img->_BaseFormat == GL_RGB || img->_BaseFormat == GL_RGBA)
*params = img->TexFormat->RedBits;
else
*params = 0;
return;
case GL_TEXTURE_GREEN_SIZE:
- if (img->Format == GL_RGB || img->Format == GL_RGBA)
+ if (img->_BaseFormat == GL_RGB || img->_BaseFormat == GL_RGBA)
*params = img->TexFormat->GreenBits;
else
*params = 0;
return;
case GL_TEXTURE_BLUE_SIZE:
- if (img->Format == GL_RGB || img->Format == GL_RGBA)
+ if (img->_BaseFormat == GL_RGB || img->_BaseFormat == GL_RGBA)
*params = img->TexFormat->BlueBits;
else
*params = 0;
return;
case GL_TEXTURE_ALPHA_SIZE:
- if (img->Format == GL_ALPHA || img->Format == GL_LUMINANCE_ALPHA ||
- img->Format == GL_RGBA)
+ if (img->_BaseFormat == GL_ALPHA ||
+ img->_BaseFormat == GL_LUMINANCE_ALPHA ||
+ img->_BaseFormat == GL_RGBA)
*params = img->TexFormat->AlphaBits;
else
*params = 0;
return;
case GL_TEXTURE_INTENSITY_SIZE:
- if (img->Format != GL_INTENSITY)
+ if (img->_BaseFormat != GL_INTENSITY)
*params = 0;
else if (img->TexFormat->IntensityBits > 0)
*params = img->TexFormat->IntensityBits;
*params = MIN2(img->TexFormat->RedBits, img->TexFormat->GreenBits);
return;
case GL_TEXTURE_LUMINANCE_SIZE:
- if (img->Format != GL_LUMINANCE &&
- img->Format != GL_LUMINANCE_ALPHA)
+ if (img->_BaseFormat != GL_LUMINANCE &&
+ img->_BaseFormat != GL_LUMINANCE_ALPHA)
*params = 0;
else if (img->TexFormat->LuminanceBits > 0)
*params = img->TexFormat->LuminanceBits;
*params = MIN2(img->TexFormat->RedBits, img->TexFormat->GreenBits);
return;
case GL_TEXTURE_INDEX_SIZE_EXT:
- if (img->Format == GL_COLOR_INDEX)
+ if (img->_BaseFormat == GL_COLOR_INDEX)
*params = img->TexFormat->IndexBits;
else
*params = 0;
return;
- case GL_DEPTH_BITS:
- /* XXX this isn't in the GL_SGIX_depth_texture spec
- * but seems appropriate.
- */
- if (ctx->Extensions.SGIX_depth_texture)
+ case GL_TEXTURE_DEPTH_SIZE_ARB:
+ if (ctx->Extensions.SGIX_depth_texture ||
+ ctx->Extensions.ARB_depth_texture)
*params = img->TexFormat->DepthBits;
else
_mesa_error(ctx, GL_INVALID_ENUM,
"glGetTexLevelParameter[if]v(pname)");
return;
+ case GL_TEXTURE_STENCIL_SIZE_EXT:
+ if (ctx->Extensions.EXT_packed_depth_stencil) {
+ *params = img->TexFormat->StencilBits;
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetTexLevelParameter[if]v(pname)");
+ }
+ return;
/* GL_ARB_texture_compression */
case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
"glGetTexLevelParameter[if]v(pname)");
}
return;
+
default:
_mesa_error(ctx, GL_INVALID_ENUM,
"glGetTexLevelParameter[if]v(pname)");
case GL_S:
if (pname==GL_TEXTURE_GEN_MODE) {
GLenum mode = (GLenum) (GLint) *params;
- GLuint bits;
+ GLbitfield bits;
switch (mode) {
case GL_OBJECT_LINEAR:
bits = TEXGEN_OBJ_LINEAR;
if (TEST_EQ_4V(texUnit->ObjectPlaneS, params))
return;
FLUSH_VERTICES(ctx, _NEW_TEXTURE);
- texUnit->ObjectPlaneS[0] = params[0];
- texUnit->ObjectPlaneS[1] = params[1];
- texUnit->ObjectPlaneS[2] = params[2];
- texUnit->ObjectPlaneS[3] = params[3];
+ COPY_4FV(texUnit->ObjectPlaneS, params);
}
else if (pname==GL_EYE_PLANE) {
GLfloat tmp[4];
-
/* Transform plane equation by the inverse modelview matrix */
if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top)) {
_math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
case GL_T:
if (pname==GL_TEXTURE_GEN_MODE) {
GLenum mode = (GLenum) (GLint) *params;
- GLuint bitt;
+ GLbitfield bitt;
switch (mode) {
case GL_OBJECT_LINEAR:
bitt = TEXGEN_OBJ_LINEAR;
if (TEST_EQ_4V(texUnit->ObjectPlaneT, params))
return;
FLUSH_VERTICES(ctx, _NEW_TEXTURE);
- texUnit->ObjectPlaneT[0] = params[0];
- texUnit->ObjectPlaneT[1] = params[1];
- texUnit->ObjectPlaneT[2] = params[2];
- texUnit->ObjectPlaneT[3] = params[3];
+ COPY_4FV(texUnit->ObjectPlaneT, params);
}
else if (pname==GL_EYE_PLANE) {
GLfloat tmp[4];
case GL_R:
if (pname==GL_TEXTURE_GEN_MODE) {
GLenum mode = (GLenum) (GLint) *params;
- GLuint bitr;
+ GLbitfield bitr;
switch (mode) {
case GL_OBJECT_LINEAR:
bitr = TEXGEN_OBJ_LINEAR;
if (TEST_EQ_4V(texUnit->ObjectPlaneR, params))
return;
FLUSH_VERTICES(ctx, _NEW_TEXTURE);
- texUnit->ObjectPlaneR[0] = params[0];
- texUnit->ObjectPlaneR[1] = params[1];
- texUnit->ObjectPlaneR[2] = params[2];
- texUnit->ObjectPlaneR[3] = params[3];
+ COPY_4FV(texUnit->ObjectPlaneR, params);
}
else if (pname==GL_EYE_PLANE) {
GLfloat tmp[4];
case GL_Q:
if (pname==GL_TEXTURE_GEN_MODE) {
GLenum mode = (GLenum) (GLint) *params;
- GLuint bitq;
+ GLbitfield bitq;
switch (mode) {
case GL_OBJECT_LINEAR:
bitq = TEXGEN_OBJ_LINEAR;
if (TEST_EQ_4V(texUnit->ObjectPlaneQ, params))
return;
FLUSH_VERTICES(ctx, _NEW_TEXTURE);
- texUnit->ObjectPlaneQ[0] = params[0];
- texUnit->ObjectPlaneQ[1] = params[1];
- texUnit->ObjectPlaneQ[2] = params[2];
- texUnit->ObjectPlaneQ[3] = params[3];
+ COPY_4FV(texUnit->ObjectPlaneQ, params);
}
else if (pname==GL_EYE_PLANE) {
GLfloat tmp[4];
-/**********************************************************************/
-/* Pixel Texgen Extensions */
-/**********************************************************************/
-
-void GLAPIENTRY
-_mesa_PixelTexGenSGIX(GLenum mode)
-{
- GLenum newRgbSource, newAlphaSource;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- switch (mode) {
- case GL_NONE:
- newRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
- newAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
- break;
- case GL_ALPHA:
- newRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
- newAlphaSource = GL_CURRENT_RASTER_COLOR;
- break;
- case GL_RGB:
- newRgbSource = GL_CURRENT_RASTER_COLOR;
- newAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
- break;
- case GL_RGBA:
- newRgbSource = GL_CURRENT_RASTER_COLOR;
- newAlphaSource = GL_CURRENT_RASTER_COLOR;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glPixelTexGenSGIX(mode)");
- return;
- }
-
- if (newRgbSource == ctx->Pixel.FragmentRgbSource &&
- newAlphaSource == ctx->Pixel.FragmentAlphaSource)
- return;
-
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.FragmentRgbSource = newRgbSource;
- ctx->Pixel.FragmentAlphaSource = newAlphaSource;
-}
-
-
-void GLAPIENTRY
-_mesa_PixelTexGenParameterfSGIS(GLenum target, GLfloat value)
-{
- _mesa_PixelTexGenParameteriSGIS(target, (GLint) value);
-}
-
-
-void GLAPIENTRY
-_mesa_PixelTexGenParameterfvSGIS(GLenum target, const GLfloat *value)
-{
- _mesa_PixelTexGenParameteriSGIS(target, (GLint) *value);
-}
-
-
-void GLAPIENTRY
-_mesa_PixelTexGenParameteriSGIS(GLenum target, GLint value)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (value != GL_CURRENT_RASTER_COLOR && value != GL_PIXEL_GROUP_COLOR_SGIS) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glPixelTexGenParameterSGIS(value)");
- return;
- }
-
- switch (target) {
- case GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS:
- if (ctx->Pixel.FragmentRgbSource == (GLenum) value)
- return;
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.FragmentRgbSource = (GLenum) value;
- break;
- case GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS:
- if (ctx->Pixel.FragmentAlphaSource == (GLenum) value)
- return;
- FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.FragmentAlphaSource = (GLenum) value;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glPixelTexGenParameterSGIS(target)");
- return;
- }
-}
-
-
-void GLAPIENTRY
-_mesa_PixelTexGenParameterivSGIS(GLenum target, const GLint *value)
-{
- _mesa_PixelTexGenParameteriSGIS(target, *value);
-}
-
-
-void GLAPIENTRY
-_mesa_GetPixelTexGenParameterfvSGIS(GLenum target, GLfloat *value)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (target == GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS) {
- *value = (GLfloat) ctx->Pixel.FragmentRgbSource;
- }
- else if (target == GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS) {
- *value = (GLfloat) ctx->Pixel.FragmentAlphaSource;
- }
- else {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelTexGenParameterfvSGIS(target)");
- }
-}
-
-
-void GLAPIENTRY
-_mesa_GetPixelTexGenParameterivSGIS(GLenum target, GLint *value)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (target == GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS) {
- *value = (GLint) ctx->Pixel.FragmentRgbSource;
- }
- else if (target == GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS) {
- *value = (GLint) ctx->Pixel.FragmentAlphaSource;
- }
- else {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelTexGenParameterivSGIS(target)");
- }
-}
-
-
-
/**********************************************************************/
/***** State management *****/
/**********************************************************************/
}
-
-
/**
* \note This routine refers to derived texture matrix values to
* compute the ENABLE_TEXMAT flags, but is only called on
*/
for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
- GLuint enableBits;
+ GLbitfield enableBits;
texUnit->_Current = NULL;
texUnit->_ReallyEnabled = 0;
texUnit->_CurrentCombine = & texUnit->Combine;
}
else {
- GLenum format = texUnit->_Current->Image[0][0]->Format;
+ GLenum format = texUnit->_Current->Image[0][0]->_BaseFormat;
if (format == GL_COLOR_INDEX) {
format = GL_RGBA; /* a bit of a hack */
}
- else if (format == GL_DEPTH_COMPONENT) {
+ else if (format == GL_DEPTH_COMPONENT
+ || format == GL_DEPTH_STENCIL_EXT) {
format = texUnit->_Current->DepthMode;
}
calculate_derived_texenv(&texUnit->_EnvMode, texUnit->EnvMode, format);
*/
if (ctx->FragmentProgram._Enabled) {
ctx->Texture._EnabledCoordUnits |=
- (ctx->FragmentProgram.Current->InputsRead >> FRAG_ATTRIB_TEX0);
+ (ctx->FragmentProgram.Current->Base.InputsRead >> FRAG_ATTRIB_TEX0);
}
}
update_texture_state( ctx );
}
+
/**********************************************************************/
/***** Initialization *****/
/**********************************************************************/
}
-GLboolean _mesa_init_texture( GLcontext * ctx )
+/**
+ * Initialize texture state for the given context.
+ */
+GLboolean
+_mesa_init_texture(GLcontext *ctx)
{
- int i;
+ GLuint i;
assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
return GL_TRUE;
}
-void _mesa_free_texture_data( GLcontext *ctx )
+
+/**
+ * Free dynamically-allocted texture data attached to the given context.
+ */
+void
+_mesa_free_texture_data(GLcontext *ctx)
{
- int i;
+ GLuint i;
/* Free proxy texture objects */
(ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy1D );
for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++)
_mesa_free_colortable_data( &ctx->Texture.Unit[i].ColorTable );
+
+ _mesa_TexEnvProgramCacheDestroy( ctx );
}