From 114152e068ec919feb0a57a1259c2ada970b9f02 Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Thu, 12 Mar 2009 15:01:16 +0100 Subject: mesa: add support for ATI_envmap_bumpmap add new entrypoints, new texture format, etc translate in texenvprogram.c for drivers using the mesa-generated tex env fragment program also handled in swrast, but not tested (cannot work due to negative texel results not handled correctly) --- src/mesa/main/texenv.c | 174 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 173 insertions(+), 1 deletion(-) (limited to 'src/mesa/main/texenv.c') diff --git a/src/mesa/main/texenv.c b/src/mesa/main/texenv.c index 95547a500e..c2960fc820 100644 --- a/src/mesa/main/texenv.c +++ b/src/mesa/main/texenv.c @@ -142,7 +142,11 @@ set_combiner_mode(GLcontext *ctx, case GL_MODULATE_ADD_ATI: case GL_MODULATE_SIGNED_ADD_ATI: case GL_MODULATE_SUBTRACT_ATI: - legal =ctx->Extensions.ATI_texture_env_combine3; + legal = ctx->Extensions.ATI_texture_env_combine3; + break; + case GL_BUMP_ENVMAP_ATI: + legal = (ctx->Extensions.ATI_envmap_bumpmap && + pname == GL_COMBINE_RGB); break; default: legal = GL_FALSE; @@ -500,6 +504,26 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param ) case GL_ALPHA_SCALE: set_combiner_scale(ctx, texUnit, pname, param[0]); break; + case GL_BUMP_TARGET_ATI: + if (!ctx->Extensions.ATI_envmap_bumpmap) { + _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname=0x%x)", pname ); + return; + } + if (((GLenum) (GLint) param[0] < GL_TEXTURE0) || + ((GLenum) (GLint) param[0] > GL_TEXTURE31)) { + /* spec doesn't say this but it seems logical */ + _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(param=0x%x)", (GLenum) (GLint) param[0]); + return; + } + if (!((1 << ((GLenum) (GLint) param[0] - GL_TEXTURE0)) & ctx->Const.SupportedBumpUnits)) { + _mesa_error( ctx, GL_INVALID_VALUE, "glTexEnv(param=0x%x)", (GLenum) (GLint) param[0]); + return; + } + else { + FLUSH_VERTICES(ctx, _NEW_TEXTURE); + texUnit->BumpTarget = (GLenum) (GLint) param[0]; + } + break; default: _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" ); return; @@ -735,6 +759,16 @@ get_texenvi(GLcontext *ctx, const struct gl_texture_unit *texUnit, _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)"); } break; + case GL_BUMP_TARGET_ATI: + /* spec doesn't say so, but I think this should be queryable */ + if (ctx->Extensions.ATI_envmap_bumpmap) { + return texUnit->BumpTarget; + } + else { + _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)"); + } + break; + default: ; } @@ -874,4 +908,142 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params ) } } +/* why does ATI_envmap_bumpmap require new entrypoints? Should just + reuse TexEnv ones... */ +void GLAPIENTRY +_mesa_TexBumpParameterivATI( GLenum pname, const GLint *param ) +{ + GLfloat p[4]; + if (pname == GL_BUMP_ROT_MATRIX_ATI) { + /* hope that conversion is correct here */ + p[0] = INT_TO_FLOAT( param[0] ); + p[1] = INT_TO_FLOAT( param[1] ); + p[2] = INT_TO_FLOAT( param[2] ); + p[3] = INT_TO_FLOAT( param[3] ); + } + else { + p[0] = (GLfloat) param[0]; + p[1] = p[2] = p[3] = 0; /* init to zero, just to be safe */ + } + _mesa_TexBumpParameterfvATI( pname, p ); +} + +void GLAPIENTRY +_mesa_TexBumpParameterfvATI( GLenum pname, const GLfloat *param ) +{ + struct gl_texture_unit *texUnit; + GET_CURRENT_CONTEXT(ctx); + ASSERT_OUTSIDE_BEGIN_END(ctx); + + /* should return error if extension not supported? */ + texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; + + if (pname == GL_BUMP_ROT_MATRIX_ATI) { + if (TEST_EQ_4V(param, texUnit->RotMatrix)) + return; + FLUSH_VERTICES(ctx, _NEW_TEXTURE); + COPY_4FV(texUnit->RotMatrix, param); + } + else { + _mesa_error( ctx, GL_INVALID_ENUM, "glTexBumpParameter(pname)" ); + return; + } + /* Drivers might want to know about this, instead of dedicated function + just shove it into TexEnv where it really belongs anyway */ + if (ctx->Driver.TexEnv) { + (*ctx->Driver.TexEnv)( ctx, 0, pname, param ); + } +} + +void GLAPIENTRY +_mesa_GetTexBumpParameterivATI( GLenum pname, GLint *param ) +{ + const struct gl_texture_unit *texUnit; + GLint i; + GLint temp = 0; + GET_CURRENT_CONTEXT(ctx); + ASSERT_OUTSIDE_BEGIN_END(ctx); + + /* should return error if extension not supported? */ + texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; + + if (pname == GL_BUMP_ROT_MATRIX_SIZE_ATI) { + /* spec leaves open to support larger matrices. + Don't think anyone would ever want to use it + (and apps almost certainly would not understand it and + thus fail to submit matrices correctly) so hardcode this. */ + *param = 4; + } + else if (pname == GL_BUMP_ROT_MATRIX_ATI) { + /* hope that conversion is correct here */ + param[0] = FLOAT_TO_INT(texUnit->RotMatrix[0]); + param[1] = FLOAT_TO_INT(texUnit->RotMatrix[1]); + param[2] = FLOAT_TO_INT(texUnit->RotMatrix[2]); + param[3] = FLOAT_TO_INT(texUnit->RotMatrix[3]); + } + else if (pname == GL_BUMP_NUM_TEX_UNITS_ATI) { + for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) { + if (ctx->Const.SupportedBumpUnits & (1 << i)) { + temp++; + } + } + *param = temp; + } + else if (pname == GL_BUMP_TEX_UNITS_ATI) { + for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) { + if (ctx->Const.SupportedBumpUnits & (1 << i)) { + *param++ = i + GL_TEXTURE0; + } + } + } + else { + _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexBumpParameter(pname)" ); + return; + } +} + +void GLAPIENTRY +_mesa_GetTexBumpParameterfvATI( GLenum pname, GLfloat *param ) +{ + const struct gl_texture_unit *texUnit; + GLint i; + GLint temp = 0; + GET_CURRENT_CONTEXT(ctx); + ASSERT_OUTSIDE_BEGIN_END(ctx); + + /* should return error if extension not supported? */ + texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; + + if (pname == GL_BUMP_ROT_MATRIX_SIZE_ATI) { + /* spec leaves open to support larger matrices. + Don't think anyone would ever want to use it + (and apps might not understand it) so hardcode this. */ + *param = (GLfloat) 4; + } + else if (pname == GL_BUMP_ROT_MATRIX_ATI) { + param[0] = texUnit->RotMatrix[0]; + param[1] = texUnit->RotMatrix[1]; + param[2] = texUnit->RotMatrix[2]; + param[3] = texUnit->RotMatrix[3]; + } + else if (pname == GL_BUMP_NUM_TEX_UNITS_ATI) { + for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) { + if (ctx->Const.SupportedBumpUnits & (1 << i)) { + temp++; + } + } + *param = (GLfloat) temp; + } + else if (pname == GL_BUMP_TEX_UNITS_ATI) { + for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) { + if (ctx->Const.SupportedBumpUnits & (1 << i)) { + *param++ = (GLfloat) (i + GL_TEXTURE0); + } + } + } + else { + _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexBumpParameter(pname)" ); + return; + } +} -- cgit v1.2.3