texenv.c revision 33e01d93ca1a1d3183243c308a2c87f4b969b3bd
111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul/* 211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * Mesa 3-D graphics library 30a40033047373d9c16039cff9e63130478e78e0fBrian Paul * Version: 7.5 411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * 511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 60a40033047373d9c16039cff9e63130478e78e0fBrian Paul * Copyright (C) 2009 VMware, Inc. All Rights Reserved. 711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * 811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * Permission is hereby granted, free of charge, to any person obtaining a 911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * copy of this software and associated documentation files (the "Software"), 1011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * to deal in the Software without restriction, including without limitation 1111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * the rights to use, copy, modify, merge, publish, distribute, sublicense, 1211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * and/or sell copies of the Software, and to permit persons to whom the 1311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * Software is furnished to do so, subject to the following conditions: 1411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * 1511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * The above copyright notice and this permission notice shall be included 1611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * in all copies or substantial portions of the Software. 1711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * 1811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 1911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 2111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 2311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul */ 2511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 2611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul/** 2711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * \file texenv.c 2811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * 2911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * glTexEnv-related functions 3011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul */ 3111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 3211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 3311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul#include "main/glheader.h" 3411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul#include "main/context.h" 3511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul#include "main/enums.h" 3611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul#include "main/macros.h" 370117da40cd7edd3d165bb28569c289b37eca12b9Vinson Lee#include "main/mtypes.h" 38e5c6a92a12b5cd7db205d72039f58d302b0be9d5Marek Olšák#include "main/state.h" 3911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul#include "main/texenv.h" 406aa7a03d856f4cfdbed493c976387b2164a0c922Brian Paul#include "main/texstate.h" 4111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 4211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 430a40033047373d9c16039cff9e63130478e78e0fBrian Paul#define TE_ERROR(errCode, msg, value) \ 440a40033047373d9c16039cff9e63130478e78e0fBrian Paul _mesa_error(ctx, errCode, msg, _mesa_lookup_enum_by_nr(value)); 450a40033047373d9c16039cff9e63130478e78e0fBrian Paul 460a40033047373d9c16039cff9e63130478e78e0fBrian Paul 470a40033047373d9c16039cff9e63130478e78e0fBrian Paul/** Set texture env mode */ 480a40033047373d9c16039cff9e63130478e78e0fBrian Paulstatic void 49f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergset_env_mode(struct gl_context *ctx, 500a40033047373d9c16039cff9e63130478e78e0fBrian Paul struct gl_texture_unit *texUnit, 510a40033047373d9c16039cff9e63130478e78e0fBrian Paul GLenum mode) 520a40033047373d9c16039cff9e63130478e78e0fBrian Paul{ 530a40033047373d9c16039cff9e63130478e78e0fBrian Paul GLboolean legal; 540a40033047373d9c16039cff9e63130478e78e0fBrian Paul 550a40033047373d9c16039cff9e63130478e78e0fBrian Paul if (texUnit->EnvMode == mode) 560a40033047373d9c16039cff9e63130478e78e0fBrian Paul return; 570a40033047373d9c16039cff9e63130478e78e0fBrian Paul 580a40033047373d9c16039cff9e63130478e78e0fBrian Paul switch (mode) { 590a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_MODULATE: 600a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_BLEND: 610a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_DECAL: 620a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_REPLACE: 635c4f914f9a883be67a93a78c853de103bb6a2d2aIan Romanick case GL_ADD: 64bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick case GL_COMBINE: 650a40033047373d9c16039cff9e63130478e78e0fBrian Paul legal = GL_TRUE; 660a40033047373d9c16039cff9e63130478e78e0fBrian Paul break; 670a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_REPLACE_EXT: 680a40033047373d9c16039cff9e63130478e78e0fBrian Paul mode = GL_REPLACE; /* GL_REPLACE_EXT != GL_REPLACE */ 690a40033047373d9c16039cff9e63130478e78e0fBrian Paul legal = GL_TRUE; 700a40033047373d9c16039cff9e63130478e78e0fBrian Paul break; 710a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_COMBINE4_NV: 720a40033047373d9c16039cff9e63130478e78e0fBrian Paul legal = ctx->Extensions.NV_texture_env_combine4; 730a40033047373d9c16039cff9e63130478e78e0fBrian Paul break; 740a40033047373d9c16039cff9e63130478e78e0fBrian Paul default: 750a40033047373d9c16039cff9e63130478e78e0fBrian Paul legal = GL_FALSE; 760a40033047373d9c16039cff9e63130478e78e0fBrian Paul } 770a40033047373d9c16039cff9e63130478e78e0fBrian Paul 780a40033047373d9c16039cff9e63130478e78e0fBrian Paul if (legal) { 790a40033047373d9c16039cff9e63130478e78e0fBrian Paul FLUSH_VERTICES(ctx, _NEW_TEXTURE); 800a40033047373d9c16039cff9e63130478e78e0fBrian Paul texUnit->EnvMode = mode; 810a40033047373d9c16039cff9e63130478e78e0fBrian Paul } 820a40033047373d9c16039cff9e63130478e78e0fBrian Paul else { 830a40033047373d9c16039cff9e63130478e78e0fBrian Paul TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode); 840a40033047373d9c16039cff9e63130478e78e0fBrian Paul } 850a40033047373d9c16039cff9e63130478e78e0fBrian Paul} 860a40033047373d9c16039cff9e63130478e78e0fBrian Paul 870a40033047373d9c16039cff9e63130478e78e0fBrian Paul 880a40033047373d9c16039cff9e63130478e78e0fBrian Paulstatic void 89f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergset_env_color(struct gl_context *ctx, 900a40033047373d9c16039cff9e63130478e78e0fBrian Paul struct gl_texture_unit *texUnit, 910a40033047373d9c16039cff9e63130478e78e0fBrian Paul const GLfloat *color) 920a40033047373d9c16039cff9e63130478e78e0fBrian Paul{ 93e5c6a92a12b5cd7db205d72039f58d302b0be9d5Marek Olšák if (TEST_EQ_4V(color, texUnit->EnvColorUnclamped)) 940a40033047373d9c16039cff9e63130478e78e0fBrian Paul return; 950a40033047373d9c16039cff9e63130478e78e0fBrian Paul FLUSH_VERTICES(ctx, _NEW_TEXTURE); 96e5c6a92a12b5cd7db205d72039f58d302b0be9d5Marek Olšák COPY_4FV(texUnit->EnvColorUnclamped, color); 97e5c6a92a12b5cd7db205d72039f58d302b0be9d5Marek Olšák texUnit->EnvColor[0] = CLAMP(color[0], 0.0F, 1.0F); 98e5c6a92a12b5cd7db205d72039f58d302b0be9d5Marek Olšák texUnit->EnvColor[1] = CLAMP(color[1], 0.0F, 1.0F); 99e5c6a92a12b5cd7db205d72039f58d302b0be9d5Marek Olšák texUnit->EnvColor[2] = CLAMP(color[2], 0.0F, 1.0F); 100e5c6a92a12b5cd7db205d72039f58d302b0be9d5Marek Olšák texUnit->EnvColor[3] = CLAMP(color[3], 0.0F, 1.0F); 1010a40033047373d9c16039cff9e63130478e78e0fBrian Paul} 1020a40033047373d9c16039cff9e63130478e78e0fBrian Paul 1030a40033047373d9c16039cff9e63130478e78e0fBrian Paul 1040a40033047373d9c16039cff9e63130478e78e0fBrian Paul/** Set an RGB or A combiner mode/function */ 1050a40033047373d9c16039cff9e63130478e78e0fBrian Paulstatic void 106f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergset_combiner_mode(struct gl_context *ctx, 1070a40033047373d9c16039cff9e63130478e78e0fBrian Paul struct gl_texture_unit *texUnit, 1080a40033047373d9c16039cff9e63130478e78e0fBrian Paul GLenum pname, GLenum mode) 1090a40033047373d9c16039cff9e63130478e78e0fBrian Paul{ 1100a40033047373d9c16039cff9e63130478e78e0fBrian Paul GLboolean legal; 1110a40033047373d9c16039cff9e63130478e78e0fBrian Paul 1120a40033047373d9c16039cff9e63130478e78e0fBrian Paul switch (mode) { 1130a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_REPLACE: 1140a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_MODULATE: 1150a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_ADD: 1160a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_ADD_SIGNED: 1170a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_INTERPOLATE: 1180a40033047373d9c16039cff9e63130478e78e0fBrian Paul legal = GL_TRUE; 1190a40033047373d9c16039cff9e63130478e78e0fBrian Paul break; 1200a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_SUBTRACT: 1210a40033047373d9c16039cff9e63130478e78e0fBrian Paul legal = ctx->Extensions.ARB_texture_env_combine; 1220a40033047373d9c16039cff9e63130478e78e0fBrian Paul break; 1230a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_DOT3_RGB_EXT: 1240a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_DOT3_RGBA_EXT: 1258a263b6efd2c520a4ed9c98b9c8142c6c2c6f389Ian Romanick legal = (ctx->API == API_OPENGL && 1268a263b6efd2c520a4ed9c98b9c8142c6c2c6f389Ian Romanick ctx->Extensions.EXT_texture_env_dot3 && 1270a40033047373d9c16039cff9e63130478e78e0fBrian Paul pname == GL_COMBINE_RGB); 1280a40033047373d9c16039cff9e63130478e78e0fBrian Paul break; 1290a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_DOT3_RGB: 1300a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_DOT3_RGBA: 1310a40033047373d9c16039cff9e63130478e78e0fBrian Paul legal = (ctx->Extensions.ARB_texture_env_dot3 && 1320a40033047373d9c16039cff9e63130478e78e0fBrian Paul pname == GL_COMBINE_RGB); 1330a40033047373d9c16039cff9e63130478e78e0fBrian Paul break; 1340a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_MODULATE_ADD_ATI: 1350a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_MODULATE_SIGNED_ADD_ATI: 1360a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_MODULATE_SUBTRACT_ATI: 1378a263b6efd2c520a4ed9c98b9c8142c6c2c6f389Ian Romanick legal = (ctx->API == API_OPENGL && 1388a263b6efd2c520a4ed9c98b9c8142c6c2c6f389Ian Romanick ctx->Extensions.ATI_texture_env_combine3); 139114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger break; 140114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_BUMP_ENVMAP_ATI: 1418a263b6efd2c520a4ed9c98b9c8142c6c2c6f389Ian Romanick legal = (ctx->API == API_OPENGL && 1428a263b6efd2c520a4ed9c98b9c8142c6c2c6f389Ian Romanick ctx->Extensions.ATI_envmap_bumpmap && 143114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger pname == GL_COMBINE_RGB); 1440a40033047373d9c16039cff9e63130478e78e0fBrian Paul break; 1450a40033047373d9c16039cff9e63130478e78e0fBrian Paul default: 1460a40033047373d9c16039cff9e63130478e78e0fBrian Paul legal = GL_FALSE; 1470a40033047373d9c16039cff9e63130478e78e0fBrian Paul } 1480a40033047373d9c16039cff9e63130478e78e0fBrian Paul 1490a40033047373d9c16039cff9e63130478e78e0fBrian Paul if (!legal) { 1500a40033047373d9c16039cff9e63130478e78e0fBrian Paul TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode); 1510a40033047373d9c16039cff9e63130478e78e0fBrian Paul return; 1520a40033047373d9c16039cff9e63130478e78e0fBrian Paul } 1530a40033047373d9c16039cff9e63130478e78e0fBrian Paul 1540a40033047373d9c16039cff9e63130478e78e0fBrian Paul switch (pname) { 1550a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_COMBINE_RGB: 1560a40033047373d9c16039cff9e63130478e78e0fBrian Paul if (texUnit->Combine.ModeRGB == mode) 1570a40033047373d9c16039cff9e63130478e78e0fBrian Paul return; 1580a40033047373d9c16039cff9e63130478e78e0fBrian Paul FLUSH_VERTICES(ctx, _NEW_TEXTURE); 1590a40033047373d9c16039cff9e63130478e78e0fBrian Paul texUnit->Combine.ModeRGB = mode; 1600a40033047373d9c16039cff9e63130478e78e0fBrian Paul break; 1610a40033047373d9c16039cff9e63130478e78e0fBrian Paul 1620a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_COMBINE_ALPHA: 1630a40033047373d9c16039cff9e63130478e78e0fBrian Paul if (texUnit->Combine.ModeA == mode) 1640a40033047373d9c16039cff9e63130478e78e0fBrian Paul return; 1650a40033047373d9c16039cff9e63130478e78e0fBrian Paul FLUSH_VERTICES(ctx, _NEW_TEXTURE); 1660a40033047373d9c16039cff9e63130478e78e0fBrian Paul texUnit->Combine.ModeA = mode; 1670a40033047373d9c16039cff9e63130478e78e0fBrian Paul break; 1680a40033047373d9c16039cff9e63130478e78e0fBrian Paul default: 1690a40033047373d9c16039cff9e63130478e78e0fBrian Paul TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); 1700a40033047373d9c16039cff9e63130478e78e0fBrian Paul } 1710a40033047373d9c16039cff9e63130478e78e0fBrian Paul} 1720a40033047373d9c16039cff9e63130478e78e0fBrian Paul 1730a40033047373d9c16039cff9e63130478e78e0fBrian Paul 1740a40033047373d9c16039cff9e63130478e78e0fBrian Paul 1750a40033047373d9c16039cff9e63130478e78e0fBrian Paul/** Set an RGB or A combiner source term */ 1760a40033047373d9c16039cff9e63130478e78e0fBrian Paulstatic void 177f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergset_combiner_source(struct gl_context *ctx, 1780a40033047373d9c16039cff9e63130478e78e0fBrian Paul struct gl_texture_unit *texUnit, 1790a40033047373d9c16039cff9e63130478e78e0fBrian Paul GLenum pname, GLenum param) 1800a40033047373d9c16039cff9e63130478e78e0fBrian Paul{ 181bd9b2be8284fda3f8aac235908ded118b5648a38Brian Paul GLuint term; 1820a40033047373d9c16039cff9e63130478e78e0fBrian Paul GLboolean alpha, legal; 1830a40033047373d9c16039cff9e63130478e78e0fBrian Paul 1840a40033047373d9c16039cff9e63130478e78e0fBrian Paul /* 185bd9b2be8284fda3f8aac235908ded118b5648a38Brian Paul * Translate pname to (term, alpha). 186de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick * 187de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick * The enums were given sequential values for a reason. 1880a40033047373d9c16039cff9e63130478e78e0fBrian Paul */ 1890a40033047373d9c16039cff9e63130478e78e0fBrian Paul switch (pname) { 1900a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_SOURCE0_RGB: 1910a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_SOURCE1_RGB: 1920a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_SOURCE2_RGB: 19308fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul case GL_SOURCE3_RGB_NV: 194de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick term = pname - GL_SOURCE0_RGB; 195de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick alpha = GL_FALSE; 19608fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul break; 1970a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_SOURCE0_ALPHA: 1980a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_SOURCE1_ALPHA: 1990a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_SOURCE2_ALPHA: 20008fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul case GL_SOURCE3_ALPHA_NV: 201de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick term = pname - GL_SOURCE0_ALPHA; 202de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick alpha = GL_TRUE; 20308fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul break; 2040a40033047373d9c16039cff9e63130478e78e0fBrian Paul default: 2050a40033047373d9c16039cff9e63130478e78e0fBrian Paul TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); 2060a40033047373d9c16039cff9e63130478e78e0fBrian Paul return; 2070a40033047373d9c16039cff9e63130478e78e0fBrian Paul } 2080a40033047373d9c16039cff9e63130478e78e0fBrian Paul 2098a263b6efd2c520a4ed9c98b9c8142c6c2c6f389Ian Romanick if ((term == 3) && (ctx->API != API_OPENGL 2108a263b6efd2c520a4ed9c98b9c8142c6c2c6f389Ian Romanick || !ctx->Extensions.NV_texture_env_combine4)) { 211de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); 212de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick return; 213de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick } 214de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick 215bd9b2be8284fda3f8aac235908ded118b5648a38Brian Paul assert(term < MAX_COMBINER_TERMS); 21608fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul 2170a40033047373d9c16039cff9e63130478e78e0fBrian Paul /* 2180a40033047373d9c16039cff9e63130478e78e0fBrian Paul * Error-check param (the source term) 2190a40033047373d9c16039cff9e63130478e78e0fBrian Paul */ 2200a40033047373d9c16039cff9e63130478e78e0fBrian Paul switch (param) { 2210a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_TEXTURE: 2220a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_CONSTANT: 2230a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_PRIMARY_COLOR: 2240a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_PREVIOUS: 2250a40033047373d9c16039cff9e63130478e78e0fBrian Paul legal = GL_TRUE; 2260a40033047373d9c16039cff9e63130478e78e0fBrian Paul break; 2270a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_TEXTURE0: 2280a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_TEXTURE1: 2290a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_TEXTURE2: 2300a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_TEXTURE3: 2310a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_TEXTURE4: 2320a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_TEXTURE5: 2330a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_TEXTURE6: 2340a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_TEXTURE7: 2350a40033047373d9c16039cff9e63130478e78e0fBrian Paul legal = (ctx->Extensions.ARB_texture_env_crossbar && 2360a40033047373d9c16039cff9e63130478e78e0fBrian Paul param - GL_TEXTURE0 < ctx->Const.MaxTextureUnits); 2370a40033047373d9c16039cff9e63130478e78e0fBrian Paul break; 2380a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_ZERO: 2398a263b6efd2c520a4ed9c98b9c8142c6c2c6f389Ian Romanick legal = (ctx->API == API_OPENGL && 2408a263b6efd2c520a4ed9c98b9c8142c6c2c6f389Ian Romanick (ctx->Extensions.ATI_texture_env_combine3 || 2418a263b6efd2c520a4ed9c98b9c8142c6c2c6f389Ian Romanick ctx->Extensions.NV_texture_env_combine4)); 24208fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul break; 2430a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_ONE: 2448a263b6efd2c520a4ed9c98b9c8142c6c2c6f389Ian Romanick legal = (ctx->API == API_OPENGL && 2458a263b6efd2c520a4ed9c98b9c8142c6c2c6f389Ian Romanick ctx->Extensions.ATI_texture_env_combine3); 2460a40033047373d9c16039cff9e63130478e78e0fBrian Paul break; 2470a40033047373d9c16039cff9e63130478e78e0fBrian Paul default: 2480a40033047373d9c16039cff9e63130478e78e0fBrian Paul legal = GL_FALSE; 2490a40033047373d9c16039cff9e63130478e78e0fBrian Paul } 2500a40033047373d9c16039cff9e63130478e78e0fBrian Paul 2510a40033047373d9c16039cff9e63130478e78e0fBrian Paul if (!legal) { 2520a40033047373d9c16039cff9e63130478e78e0fBrian Paul TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", param); 2530a40033047373d9c16039cff9e63130478e78e0fBrian Paul return; 2540a40033047373d9c16039cff9e63130478e78e0fBrian Paul } 2550a40033047373d9c16039cff9e63130478e78e0fBrian Paul 2560a40033047373d9c16039cff9e63130478e78e0fBrian Paul FLUSH_VERTICES(ctx, _NEW_TEXTURE); 2570a40033047373d9c16039cff9e63130478e78e0fBrian Paul 2580a40033047373d9c16039cff9e63130478e78e0fBrian Paul if (alpha) 259bd9b2be8284fda3f8aac235908ded118b5648a38Brian Paul texUnit->Combine.SourceA[term] = param; 2600a40033047373d9c16039cff9e63130478e78e0fBrian Paul else 261bd9b2be8284fda3f8aac235908ded118b5648a38Brian Paul texUnit->Combine.SourceRGB[term] = param; 2620a40033047373d9c16039cff9e63130478e78e0fBrian Paul} 2630a40033047373d9c16039cff9e63130478e78e0fBrian Paul 2640a40033047373d9c16039cff9e63130478e78e0fBrian Paul 2650a40033047373d9c16039cff9e63130478e78e0fBrian Paul/** Set an RGB or A combiner operand term */ 2660a40033047373d9c16039cff9e63130478e78e0fBrian Paulstatic void 267f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergset_combiner_operand(struct gl_context *ctx, 2680a40033047373d9c16039cff9e63130478e78e0fBrian Paul struct gl_texture_unit *texUnit, 2690a40033047373d9c16039cff9e63130478e78e0fBrian Paul GLenum pname, GLenum param) 2700a40033047373d9c16039cff9e63130478e78e0fBrian Paul{ 271bd9b2be8284fda3f8aac235908ded118b5648a38Brian Paul GLuint term; 2720a40033047373d9c16039cff9e63130478e78e0fBrian Paul GLboolean alpha, legal; 2730a40033047373d9c16039cff9e63130478e78e0fBrian Paul 274de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick /* The enums were given sequential values for a reason. 275de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick */ 2760a40033047373d9c16039cff9e63130478e78e0fBrian Paul switch (pname) { 2770a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_OPERAND0_RGB: 2780a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_OPERAND1_RGB: 2790a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_OPERAND2_RGB: 28008fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul case GL_OPERAND3_RGB_NV: 281de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick term = pname - GL_OPERAND0_RGB; 282de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick alpha = GL_FALSE; 28308fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul break; 2840a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_OPERAND0_ALPHA: 2850a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_OPERAND1_ALPHA: 2860a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_OPERAND2_ALPHA: 28708fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul case GL_OPERAND3_ALPHA_NV: 288de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick term = pname - GL_OPERAND0_ALPHA; 289de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick alpha = GL_TRUE; 29008fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul break; 2910a40033047373d9c16039cff9e63130478e78e0fBrian Paul default: 2920a40033047373d9c16039cff9e63130478e78e0fBrian Paul TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); 2930a40033047373d9c16039cff9e63130478e78e0fBrian Paul return; 2940a40033047373d9c16039cff9e63130478e78e0fBrian Paul } 2950a40033047373d9c16039cff9e63130478e78e0fBrian Paul 2968a263b6efd2c520a4ed9c98b9c8142c6c2c6f389Ian Romanick if ((term == 3) && (ctx->API != API_OPENGL 2978a263b6efd2c520a4ed9c98b9c8142c6c2c6f389Ian Romanick || !ctx->Extensions.NV_texture_env_combine4)) { 298de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); 299de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick return; 300de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick } 301de1ffd2f62257c174325d877c327d56b1a9e6cbcIan Romanick 302bd9b2be8284fda3f8aac235908ded118b5648a38Brian Paul assert(term < MAX_COMBINER_TERMS); 30308fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul 3040a40033047373d9c16039cff9e63130478e78e0fBrian Paul /* 3050a40033047373d9c16039cff9e63130478e78e0fBrian Paul * Error-check param (the source operand) 3060a40033047373d9c16039cff9e63130478e78e0fBrian Paul */ 3070a40033047373d9c16039cff9e63130478e78e0fBrian Paul switch (param) { 3080a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_SRC_COLOR: 3090a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_ONE_MINUS_SRC_COLOR: 3101a2d498b4164f457c48e9fde9ae8bbadfcf7fa72Ian Romanick /* The color input can only be used with GL_OPERAND[01]_RGB in the EXT 3118a263b6efd2c520a4ed9c98b9c8142c6c2c6f389Ian Romanick * version. In the ARB and NV versions and OpenGL ES 1.x they can be 3128a263b6efd2c520a4ed9c98b9c8142c6c2c6f389Ian Romanick * used for any RGB operand. 3131a2d498b4164f457c48e9fde9ae8bbadfcf7fa72Ian Romanick */ 3141a2d498b4164f457c48e9fde9ae8bbadfcf7fa72Ian Romanick legal = !alpha 3151a2d498b4164f457c48e9fde9ae8bbadfcf7fa72Ian Romanick && ((term < 2) || ctx->Extensions.ARB_texture_env_combine 3161a2d498b4164f457c48e9fde9ae8bbadfcf7fa72Ian Romanick || ctx->Extensions.NV_texture_env_combine4); 3170a40033047373d9c16039cff9e63130478e78e0fBrian Paul break; 3180a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_ONE_MINUS_SRC_ALPHA: 3191a2d498b4164f457c48e9fde9ae8bbadfcf7fa72Ian Romanick /* GL_ONE_MINUS_SRC_ALPHA can only be used with 3201a2d498b4164f457c48e9fde9ae8bbadfcf7fa72Ian Romanick * GL_OPERAND[01]_(RGB|ALPHA) in the EXT version. In the ARB and NV 3218a263b6efd2c520a4ed9c98b9c8142c6c2c6f389Ian Romanick * versions and OpenGL ES 1.x it can be used for any operand. 3221a2d498b4164f457c48e9fde9ae8bbadfcf7fa72Ian Romanick */ 3231a2d498b4164f457c48e9fde9ae8bbadfcf7fa72Ian Romanick legal = (term < 2) || ctx->Extensions.ARB_texture_env_combine 3241a2d498b4164f457c48e9fde9ae8bbadfcf7fa72Ian Romanick || ctx->Extensions.NV_texture_env_combine4; 3251a2d498b4164f457c48e9fde9ae8bbadfcf7fa72Ian Romanick break; 3261a2d498b4164f457c48e9fde9ae8bbadfcf7fa72Ian Romanick case GL_SRC_ALPHA: 3270a40033047373d9c16039cff9e63130478e78e0fBrian Paul legal = GL_TRUE; 3280a40033047373d9c16039cff9e63130478e78e0fBrian Paul break; 3290a40033047373d9c16039cff9e63130478e78e0fBrian Paul default: 3300a40033047373d9c16039cff9e63130478e78e0fBrian Paul legal = GL_FALSE; 3310a40033047373d9c16039cff9e63130478e78e0fBrian Paul } 3320a40033047373d9c16039cff9e63130478e78e0fBrian Paul 3330a40033047373d9c16039cff9e63130478e78e0fBrian Paul if (!legal) { 3340a40033047373d9c16039cff9e63130478e78e0fBrian Paul TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", param); 3350a40033047373d9c16039cff9e63130478e78e0fBrian Paul return; 3360a40033047373d9c16039cff9e63130478e78e0fBrian Paul } 3370a40033047373d9c16039cff9e63130478e78e0fBrian Paul 3380a40033047373d9c16039cff9e63130478e78e0fBrian Paul FLUSH_VERTICES(ctx, _NEW_TEXTURE); 3390a40033047373d9c16039cff9e63130478e78e0fBrian Paul 3400a40033047373d9c16039cff9e63130478e78e0fBrian Paul if (alpha) 341bd9b2be8284fda3f8aac235908ded118b5648a38Brian Paul texUnit->Combine.OperandA[term] = param; 3420a40033047373d9c16039cff9e63130478e78e0fBrian Paul else 343bd9b2be8284fda3f8aac235908ded118b5648a38Brian Paul texUnit->Combine.OperandRGB[term] = param; 3440a40033047373d9c16039cff9e63130478e78e0fBrian Paul} 3450a40033047373d9c16039cff9e63130478e78e0fBrian Paul 3460a40033047373d9c16039cff9e63130478e78e0fBrian Paul 3470a40033047373d9c16039cff9e63130478e78e0fBrian Paulstatic void 348f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergset_combiner_scale(struct gl_context *ctx, 3490a40033047373d9c16039cff9e63130478e78e0fBrian Paul struct gl_texture_unit *texUnit, 3500a40033047373d9c16039cff9e63130478e78e0fBrian Paul GLenum pname, GLfloat scale) 3510a40033047373d9c16039cff9e63130478e78e0fBrian Paul{ 3520a40033047373d9c16039cff9e63130478e78e0fBrian Paul GLuint shift; 3530a40033047373d9c16039cff9e63130478e78e0fBrian Paul 3540a40033047373d9c16039cff9e63130478e78e0fBrian Paul if (scale == 1.0F) { 3550a40033047373d9c16039cff9e63130478e78e0fBrian Paul shift = 0; 3560a40033047373d9c16039cff9e63130478e78e0fBrian Paul } 3570a40033047373d9c16039cff9e63130478e78e0fBrian Paul else if (scale == 2.0F) { 3580a40033047373d9c16039cff9e63130478e78e0fBrian Paul shift = 1; 3590a40033047373d9c16039cff9e63130478e78e0fBrian Paul } 3600a40033047373d9c16039cff9e63130478e78e0fBrian Paul else if (scale == 4.0F) { 3610a40033047373d9c16039cff9e63130478e78e0fBrian Paul shift = 2; 3620a40033047373d9c16039cff9e63130478e78e0fBrian Paul } 3630a40033047373d9c16039cff9e63130478e78e0fBrian Paul else { 3640a40033047373d9c16039cff9e63130478e78e0fBrian Paul _mesa_error( ctx, GL_INVALID_VALUE, 3650a40033047373d9c16039cff9e63130478e78e0fBrian Paul "glTexEnv(GL_RGB_SCALE not 1, 2 or 4)" ); 3660a40033047373d9c16039cff9e63130478e78e0fBrian Paul return; 3670a40033047373d9c16039cff9e63130478e78e0fBrian Paul } 3680a40033047373d9c16039cff9e63130478e78e0fBrian Paul 3690a40033047373d9c16039cff9e63130478e78e0fBrian Paul switch (pname) { 3700a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_RGB_SCALE: 3710a40033047373d9c16039cff9e63130478e78e0fBrian Paul if (texUnit->Combine.ScaleShiftRGB == shift) 3720a40033047373d9c16039cff9e63130478e78e0fBrian Paul return; 3730a40033047373d9c16039cff9e63130478e78e0fBrian Paul FLUSH_VERTICES(ctx, _NEW_TEXTURE); 3740a40033047373d9c16039cff9e63130478e78e0fBrian Paul texUnit->Combine.ScaleShiftRGB = shift; 3750a40033047373d9c16039cff9e63130478e78e0fBrian Paul break; 3760a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_ALPHA_SCALE: 3770a40033047373d9c16039cff9e63130478e78e0fBrian Paul if (texUnit->Combine.ScaleShiftA == shift) 3780a40033047373d9c16039cff9e63130478e78e0fBrian Paul return; 3790a40033047373d9c16039cff9e63130478e78e0fBrian Paul FLUSH_VERTICES(ctx, _NEW_TEXTURE); 3800a40033047373d9c16039cff9e63130478e78e0fBrian Paul texUnit->Combine.ScaleShiftA = shift; 3810a40033047373d9c16039cff9e63130478e78e0fBrian Paul break; 3820a40033047373d9c16039cff9e63130478e78e0fBrian Paul default: 3830a40033047373d9c16039cff9e63130478e78e0fBrian Paul TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); 3840a40033047373d9c16039cff9e63130478e78e0fBrian Paul } 3850a40033047373d9c16039cff9e63130478e78e0fBrian Paul} 3860a40033047373d9c16039cff9e63130478e78e0fBrian Paul 3870a40033047373d9c16039cff9e63130478e78e0fBrian Paul 38811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 38911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paulvoid GLAPIENTRY 39011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul_mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param ) 39111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul{ 3925b902a08c1919d1bc4666d3e3b8e3f7933b7974bBrian Paul const GLint iparam0 = (GLint) param[0]; 3935b902a08c1919d1bc4666d3e3b8e3f7933b7974bBrian Paul struct gl_texture_unit *texUnit; 39411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul GLuint maxUnit; 3955b902a08c1919d1bc4666d3e3b8e3f7933b7974bBrian Paul 39611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul GET_CURRENT_CONTEXT(ctx); 39711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul ASSERT_OUTSIDE_BEGIN_END(ctx); 39811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 39911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul maxUnit = (target == GL_POINT_SPRITE_NV && pname == GL_COORD_REPLACE_NV) 400bfe284fd26e96b71c7cf46e6365b3697d68cde83Henri Verbeet ? ctx->Const.MaxTextureCoordUnits : ctx->Const.MaxCombinedTextureImageUnits; 40111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (ctx->Texture.CurrentUnit >= maxUnit) { 40211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexEnvfv(current unit)"); 40311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul return; 40411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 40511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 4066aa7a03d856f4cfdbed493c976387b2164a0c922Brian Paul texUnit = _mesa_get_current_tex_unit(ctx); 40711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 40811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (target == GL_TEXTURE_ENV) { 40911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul switch (pname) { 41011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul case GL_TEXTURE_ENV_MODE: 4115b902a08c1919d1bc4666d3e3b8e3f7933b7974bBrian Paul set_env_mode(ctx, texUnit, (GLenum) iparam0); 41211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul break; 41311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul case GL_TEXTURE_ENV_COLOR: 4140a40033047373d9c16039cff9e63130478e78e0fBrian Paul set_env_color(ctx, texUnit, param); 41511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul break; 41611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul case GL_COMBINE_RGB: 41711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul case GL_COMBINE_ALPHA: 4185b902a08c1919d1bc4666d3e3b8e3f7933b7974bBrian Paul set_combiner_mode(ctx, texUnit, pname, (GLenum) iparam0); 41911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul break; 42011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul case GL_SOURCE0_RGB: 42111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul case GL_SOURCE1_RGB: 42211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul case GL_SOURCE2_RGB: 42308fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul case GL_SOURCE3_RGB_NV: 42411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul case GL_SOURCE0_ALPHA: 42511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul case GL_SOURCE1_ALPHA: 42611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul case GL_SOURCE2_ALPHA: 42708fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul case GL_SOURCE3_ALPHA_NV: 4285b902a08c1919d1bc4666d3e3b8e3f7933b7974bBrian Paul set_combiner_source(ctx, texUnit, pname, (GLenum) iparam0); 42911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul break; 43011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul case GL_OPERAND0_RGB: 43111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul case GL_OPERAND1_RGB: 4320a40033047373d9c16039cff9e63130478e78e0fBrian Paul case GL_OPERAND2_RGB: 43308fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul case GL_OPERAND3_RGB_NV: 43411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul case GL_OPERAND0_ALPHA: 43511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul case GL_OPERAND1_ALPHA: 43611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul case GL_OPERAND2_ALPHA: 43708fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul case GL_OPERAND3_ALPHA_NV: 4385b902a08c1919d1bc4666d3e3b8e3f7933b7974bBrian Paul set_combiner_operand(ctx, texUnit, pname, (GLenum) iparam0); 43911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul break; 44011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul case GL_RGB_SCALE: 44111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul case GL_ALPHA_SCALE: 4420a40033047373d9c16039cff9e63130478e78e0fBrian Paul set_combiner_scale(ctx, texUnit, pname, param[0]); 44311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul break; 444114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_BUMP_TARGET_ATI: 4458a263b6efd2c520a4ed9c98b9c8142c6c2c6f389Ian Romanick if (ctx->API != API_OPENGL || !ctx->Extensions.ATI_envmap_bumpmap) { 446114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname=0x%x)", pname ); 447114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger return; 448114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 4495b902a08c1919d1bc4666d3e3b8e3f7933b7974bBrian Paul if ((iparam0 < GL_TEXTURE0) || 4505b902a08c1919d1bc4666d3e3b8e3f7933b7974bBrian Paul (iparam0 > GL_TEXTURE31)) { 451114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger /* spec doesn't say this but it seems logical */ 4525b902a08c1919d1bc4666d3e3b8e3f7933b7974bBrian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(param=0x%x)", iparam0); 453114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger return; 454114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 4555b902a08c1919d1bc4666d3e3b8e3f7933b7974bBrian Paul if (!((1 << (iparam0 - GL_TEXTURE0)) & ctx->Const.SupportedBumpUnits)) { 4565b902a08c1919d1bc4666d3e3b8e3f7933b7974bBrian Paul _mesa_error( ctx, GL_INVALID_VALUE, "glTexEnv(param=0x%x)", iparam0); 457114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger return; 458114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 459114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger else { 460114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger FLUSH_VERTICES(ctx, _NEW_TEXTURE); 4615b902a08c1919d1bc4666d3e3b8e3f7933b7974bBrian Paul texUnit->BumpTarget = iparam0; 462114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 463114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger break; 46411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul default: 46511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" ); 46611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul return; 46711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 46811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 46911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul else if (target == GL_TEXTURE_FILTER_CONTROL_EXT) { 47011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (pname == GL_TEXTURE_LOD_BIAS_EXT) { 47111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (texUnit->LodBias == param[0]) 47211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul return; 47311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul FLUSH_VERTICES(ctx, _NEW_TEXTURE); 47411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul texUnit->LodBias = param[0]; 47511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 47611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul else { 47711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); 47811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul return; 47911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 48011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 48111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul else if (target == GL_POINT_SPRITE_NV) { 48211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul /* GL_ARB_point_sprite / GL_NV_point_sprite */ 48311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (!ctx->Extensions.NV_point_sprite 48411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul && !ctx->Extensions.ARB_point_sprite) { 48511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(target=0x%x)", target ); 48611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul return; 48711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 48811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (pname == GL_COORD_REPLACE_NV) { 4895b902a08c1919d1bc4666d3e3b8e3f7933b7974bBrian Paul if (iparam0 == GL_TRUE || iparam0 == GL_FALSE) { 49011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul /* It's kind of weird to set point state via glTexEnv, 49111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul * but that's what the spec calls for. 49211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul */ 4935b902a08c1919d1bc4666d3e3b8e3f7933b7974bBrian Paul const GLboolean state = (GLboolean) iparam0; 49411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (ctx->Point.CoordReplace[ctx->Texture.CurrentUnit] == state) 49511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul return; 49611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul FLUSH_VERTICES(ctx, _NEW_POINT); 49711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul ctx->Point.CoordReplace[ctx->Texture.CurrentUnit] = state; 49811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 49911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul else { 5005b902a08c1919d1bc4666d3e3b8e3f7933b7974bBrian Paul _mesa_error( ctx, GL_INVALID_VALUE, "glTexEnv(param=0x%x)", iparam0); 50111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul return; 50211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 50311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 50411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul else { 50511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname=0x%x)", pname ); 50611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul return; 50711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 50811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 50911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul else { 51011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(target=0x%x)",target ); 51111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul return; 51211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 51311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 51411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE)) 51511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_debug(ctx, "glTexEnv %s %s %.1f(%s) ...\n", 51611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_lookup_enum_by_nr(target), 51711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_lookup_enum_by_nr(pname), 51811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul *param, 5195b902a08c1919d1bc4666d3e3b8e3f7933b7974bBrian Paul _mesa_lookup_enum_by_nr((GLenum) iparam0)); 52011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 52111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul /* Tell device driver about the new texture environment */ 52211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (ctx->Driver.TexEnv) { 52311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul (*ctx->Driver.TexEnv)( ctx, target, pname, param ); 52411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 52511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul} 52611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 52711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 52811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paulvoid GLAPIENTRY 52911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul_mesa_TexEnvf( GLenum target, GLenum pname, GLfloat param ) 53011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul{ 531a11d60d14caf8efc07f70af63b57b33273f8cf9bVinson Lee GLfloat p[4]; 532a11d60d14caf8efc07f70af63b57b33273f8cf9bVinson Lee p[0] = param; 533a11d60d14caf8efc07f70af63b57b33273f8cf9bVinson Lee p[1] = p[2] = p[3] = 0.0; 534a11d60d14caf8efc07f70af63b57b33273f8cf9bVinson Lee _mesa_TexEnvfv( target, pname, p ); 53511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul} 53611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 53711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 53811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 53911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paulvoid GLAPIENTRY 54011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul_mesa_TexEnvi( GLenum target, GLenum pname, GLint param ) 54111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul{ 54211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul GLfloat p[4]; 54311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul p[0] = (GLfloat) param; 54411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul p[1] = p[2] = p[3] = 0.0; 54511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_TexEnvfv( target, pname, p ); 54611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul} 54711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 54811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 54911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paulvoid GLAPIENTRY 55011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul_mesa_TexEnviv( GLenum target, GLenum pname, const GLint *param ) 55111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul{ 55211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul GLfloat p[4]; 55311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (pname == GL_TEXTURE_ENV_COLOR) { 55411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul p[0] = INT_TO_FLOAT( param[0] ); 55511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul p[1] = INT_TO_FLOAT( param[1] ); 55611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul p[2] = INT_TO_FLOAT( param[2] ); 55711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul p[3] = INT_TO_FLOAT( param[3] ); 55811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 55911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul else { 56011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul p[0] = (GLfloat) param[0]; 56111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul p[1] = p[2] = p[3] = 0; /* init to zero, just to be safe */ 56211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 56311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_TexEnvfv( target, pname, p ); 56411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul} 56511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 56611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 567ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul 568ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul/** 569ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul * Helper for glGetTexEnvi/f() 570ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul * \return value of queried pname or -1 if error. 571ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul */ 572ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paulstatic GLint 573f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergget_texenvi(struct gl_context *ctx, const struct gl_texture_unit *texUnit, 574ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul GLenum pname) 575ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul{ 576ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul switch (pname) { 577ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul case GL_TEXTURE_ENV_MODE: 578ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul return texUnit->EnvMode; 579ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul break; 580ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul case GL_COMBINE_RGB: 581bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick return texUnit->Combine.ModeRGB; 582ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul case GL_COMBINE_ALPHA: 583bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick return texUnit->Combine.ModeA; 584ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul case GL_SOURCE0_RGB: 585ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul case GL_SOURCE1_RGB: 586bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick case GL_SOURCE2_RGB: { 587bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick const unsigned rgb_idx = pname - GL_SOURCE0_RGB; 588bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick return texUnit->Combine.SourceRGB[rgb_idx]; 589bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick } 59008fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul case GL_SOURCE3_RGB_NV: 59133e01d93ca1a1d3183243c308a2c87f4b969b3bdIan Romanick if (ctx->API == API_OPENGL && ctx->Extensions.NV_texture_env_combine4) { 59208fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul return texUnit->Combine.SourceRGB[3]; 59308fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul } 59408fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul else { 59508fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)"); 59608fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul } 59708fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul break; 598ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul case GL_SOURCE0_ALPHA: 599ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul case GL_SOURCE1_ALPHA: 600bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick case GL_SOURCE2_ALPHA: { 601bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick const unsigned alpha_idx = pname - GL_SOURCE0_ALPHA; 602bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick return texUnit->Combine.SourceA[alpha_idx]; 603bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick } 60408fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul case GL_SOURCE3_ALPHA_NV: 60533e01d93ca1a1d3183243c308a2c87f4b969b3bdIan Romanick if (ctx->API == API_OPENGL && ctx->Extensions.NV_texture_env_combine4) { 60608fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul return texUnit->Combine.SourceA[3]; 60708fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul } 60808fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul else { 60908fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)"); 61008fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul } 61108fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul break; 612ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul case GL_OPERAND0_RGB: 613ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul case GL_OPERAND1_RGB: 614bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick case GL_OPERAND2_RGB: { 615bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick const unsigned op_rgb = pname - GL_OPERAND0_RGB; 616bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick return texUnit->Combine.OperandRGB[op_rgb]; 617bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick } 61808fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul case GL_OPERAND3_RGB_NV: 61933e01d93ca1a1d3183243c308a2c87f4b969b3bdIan Romanick if (ctx->API == API_OPENGL && ctx->Extensions.NV_texture_env_combine4) { 62008fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul return texUnit->Combine.OperandRGB[3]; 62108fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul } 62208fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul else { 62308fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)"); 62408fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul } 62508fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul break; 626ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul case GL_OPERAND0_ALPHA: 627ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul case GL_OPERAND1_ALPHA: 628bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick case GL_OPERAND2_ALPHA: { 629bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick const unsigned op_alpha = pname - GL_OPERAND0_ALPHA; 630bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick return texUnit->Combine.OperandA[op_alpha]; 631bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick } 63208fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul case GL_OPERAND3_ALPHA_NV: 63333e01d93ca1a1d3183243c308a2c87f4b969b3bdIan Romanick if (ctx->API == API_OPENGL && ctx->Extensions.NV_texture_env_combine4) { 63408fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul return texUnit->Combine.OperandA[3]; 63508fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul } 63608fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul else { 63708fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)"); 63808fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul } 63908fbbdd4dceb8ca7ac15f0ce469f59e13e0ba82bBrian Paul break; 640ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul case GL_RGB_SCALE: 641bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick return 1 << texUnit->Combine.ScaleShiftRGB; 642ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul case GL_ALPHA_SCALE: 643bde8bd99b64876b47f9d335320eb1ad5b3be8d9dIan Romanick return 1 << texUnit->Combine.ScaleShiftA; 644114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger case GL_BUMP_TARGET_ATI: 645114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger /* spec doesn't say so, but I think this should be queryable */ 64633e01d93ca1a1d3183243c308a2c87f4b969b3bdIan Romanick if (ctx->API == API_OPENGL && ctx->Extensions.ATI_envmap_bumpmap) { 647114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger return texUnit->BumpTarget; 648114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 649114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger else { 650114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)"); 651114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 652114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger break; 653114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 654ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul default: 655b020b111a82266743d2cc501195defe687657e96Yuanhan Liu _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)"); 656b020b111a82266743d2cc501195defe687657e96Yuanhan Liu break; 657ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul } 658ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul 659ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul return -1; /* error */ 660ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul} 661ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul 662ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul 663ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul 66411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paulvoid GLAPIENTRY 66511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul_mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params ) 66611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul{ 66711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul GLuint maxUnit; 66811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul const struct gl_texture_unit *texUnit; 66911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul GET_CURRENT_CONTEXT(ctx); 67011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul ASSERT_OUTSIDE_BEGIN_END(ctx); 67111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 67211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul maxUnit = (target == GL_POINT_SPRITE_NV && pname == GL_COORD_REPLACE_NV) 673bfe284fd26e96b71c7cf46e6365b3697d68cde83Henri Verbeet ? ctx->Const.MaxTextureCoordUnits : ctx->Const.MaxCombinedTextureImageUnits; 67411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (ctx->Texture.CurrentUnit >= maxUnit) { 67511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexEnvfv(current unit)"); 67611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul return; 67711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 67811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 6796aa7a03d856f4cfdbed493c976387b2164a0c922Brian Paul texUnit = _mesa_get_current_tex_unit(ctx); 68011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 68111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (target == GL_TEXTURE_ENV) { 682ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul if (pname == GL_TEXTURE_ENV_COLOR) { 683e5c6a92a12b5cd7db205d72039f58d302b0be9d5Marek Olšák if(ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP)) 684e5c6a92a12b5cd7db205d72039f58d302b0be9d5Marek Olšák _mesa_update_state(ctx); 685e5c6a92a12b5cd7db205d72039f58d302b0be9d5Marek Olšák if(ctx->Color._ClampFragmentColor) 686e5c6a92a12b5cd7db205d72039f58d302b0be9d5Marek Olšák COPY_4FV( params, texUnit->EnvColor ); 687e5c6a92a12b5cd7db205d72039f58d302b0be9d5Marek Olšák else 688e5c6a92a12b5cd7db205d72039f58d302b0be9d5Marek Olšák COPY_4FV( params, texUnit->EnvColorUnclamped ); 689ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul } 690ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul else { 691ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul GLint val = get_texenvi(ctx, texUnit, pname); 692ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul if (val >= 0) { 693ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul *params = (GLfloat) val; 694ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul } 69511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 69611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 69711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul else if (target == GL_TEXTURE_FILTER_CONTROL_EXT) { 69811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (pname == GL_TEXTURE_LOD_BIAS_EXT) { 69911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul *params = texUnit->LodBias; 70011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 70111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul else { 70211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" ); 70311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul return; 70411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 70511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 70611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul else if (target == GL_POINT_SPRITE_NV) { 70711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul /* GL_ARB_point_sprite / GL_NV_point_sprite */ 70811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (!ctx->Extensions.NV_point_sprite 70911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul && !ctx->Extensions.ARB_point_sprite) { 71011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" ); 71111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul return; 71211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 71311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (pname == GL_COORD_REPLACE_NV) { 71411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul *params = (GLfloat) ctx->Point.CoordReplace[ctx->Texture.CurrentUnit]; 71511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 71611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul else { 71711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" ); 71811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul return; 71911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 72011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 72111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul else { 72211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" ); 72311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul return; 72411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 72511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul} 72611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 72711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 72811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paulvoid GLAPIENTRY 72911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul_mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params ) 73011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul{ 73111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul GLuint maxUnit; 73211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul const struct gl_texture_unit *texUnit; 73311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul GET_CURRENT_CONTEXT(ctx); 73411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul ASSERT_OUTSIDE_BEGIN_END(ctx); 73511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 73611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul maxUnit = (target == GL_POINT_SPRITE_NV && pname == GL_COORD_REPLACE_NV) 737bfe284fd26e96b71c7cf46e6365b3697d68cde83Henri Verbeet ? ctx->Const.MaxTextureCoordUnits : ctx->Const.MaxCombinedTextureImageUnits; 73811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (ctx->Texture.CurrentUnit >= maxUnit) { 73911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexEnviv(current unit)"); 74011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul return; 74111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 74211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 7436aa7a03d856f4cfdbed493c976387b2164a0c922Brian Paul texUnit = _mesa_get_current_tex_unit(ctx); 74411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 74511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (target == GL_TEXTURE_ENV) { 746ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul if (pname == GL_TEXTURE_ENV_COLOR) { 747ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul params[0] = FLOAT_TO_INT( texUnit->EnvColor[0] ); 748ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul params[1] = FLOAT_TO_INT( texUnit->EnvColor[1] ); 749ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul params[2] = FLOAT_TO_INT( texUnit->EnvColor[2] ); 750ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul params[3] = FLOAT_TO_INT( texUnit->EnvColor[3] ); 751ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul } 752ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul else { 753ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul GLint val = get_texenvi(ctx, texUnit, pname); 754ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul if (val >= 0) { 755ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul *params = val; 756ad338c14c2aca87199da7ec1ae08ceb5062a9954Brian Paul } 75711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 75811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 75911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul else if (target == GL_TEXTURE_FILTER_CONTROL_EXT) { 76011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (pname == GL_TEXTURE_LOD_BIAS_EXT) { 76111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul *params = (GLint) texUnit->LodBias; 76211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 76311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul else { 76411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)" ); 76511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul return; 76611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 76711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 76811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul else if (target == GL_POINT_SPRITE_NV) { 76911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul /* GL_ARB_point_sprite / GL_NV_point_sprite */ 77011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (!ctx->Extensions.NV_point_sprite 77111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul && !ctx->Extensions.ARB_point_sprite) { 77211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(target)" ); 77311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul return; 77411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 77511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul if (pname == GL_COORD_REPLACE_NV) { 77611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul *params = (GLint) ctx->Point.CoordReplace[ctx->Texture.CurrentUnit]; 77711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 77811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul else { 77911ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)" ); 78011ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul return; 78111ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 78211ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 78311ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul else { 78411ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(target)" ); 78511ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul return; 78611ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul } 78711ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul} 78811ebfd22bb451f86a492254b77c90aeb011f8d9aBrian Paul 78947a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul 79047a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul/** 79147a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul * Why does ATI_envmap_bumpmap require new entrypoints? Should just 79247a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul * reuse TexEnv ones... 79347a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul */ 794114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheideggervoid GLAPIENTRY 795114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger_mesa_TexBumpParameterivATI( GLenum pname, const GLint *param ) 796114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger{ 797114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger GLfloat p[4]; 79847a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul GET_CURRENT_CONTEXT(ctx); 79947a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul ASSERT_OUTSIDE_BEGIN_END(ctx); 80047a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul 80147a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul if (!ctx->Extensions.ATI_envmap_bumpmap) { 80247a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul /* This isn't an "official" error case, but let's tell the user 80347a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul * that something's wrong. 80447a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul */ 80547a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBumpParameterivATI"); 80647a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul return; 80747a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul } 80847a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul 809114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger if (pname == GL_BUMP_ROT_MATRIX_ATI) { 810114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger /* hope that conversion is correct here */ 811114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger p[0] = INT_TO_FLOAT( param[0] ); 812114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger p[1] = INT_TO_FLOAT( param[1] ); 813114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger p[2] = INT_TO_FLOAT( param[2] ); 814114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger p[3] = INT_TO_FLOAT( param[3] ); 815114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 816114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger else { 817114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger p[0] = (GLfloat) param[0]; 81847a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul p[1] = p[2] = p[3] = 0.0F; /* init to zero, just to be safe */ 819114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 820114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger _mesa_TexBumpParameterfvATI( pname, p ); 821114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger} 822114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 82347a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul 824114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheideggervoid GLAPIENTRY 825114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger_mesa_TexBumpParameterfvATI( GLenum pname, const GLfloat *param ) 826114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger{ 827114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger struct gl_texture_unit *texUnit; 828114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger GET_CURRENT_CONTEXT(ctx); 829114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger ASSERT_OUTSIDE_BEGIN_END(ctx); 830114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 83147a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul if (!ctx->Extensions.ATI_envmap_bumpmap) { 83247a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBumpParameterfvATI"); 83347a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul return; 83447a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul } 8356aa7a03d856f4cfdbed493c976387b2164a0c922Brian Paul 8366aa7a03d856f4cfdbed493c976387b2164a0c922Brian Paul texUnit = _mesa_get_current_tex_unit(ctx); 837114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 838114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger if (pname == GL_BUMP_ROT_MATRIX_ATI) { 839114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger if (TEST_EQ_4V(param, texUnit->RotMatrix)) 840114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger return; 841114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger FLUSH_VERTICES(ctx, _NEW_TEXTURE); 842114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger COPY_4FV(texUnit->RotMatrix, param); 843114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 844114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger else { 845114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger _mesa_error( ctx, GL_INVALID_ENUM, "glTexBumpParameter(pname)" ); 846114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger return; 847114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 848114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger /* Drivers might want to know about this, instead of dedicated function 849114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger just shove it into TexEnv where it really belongs anyway */ 850114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger if (ctx->Driver.TexEnv) { 851114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger (*ctx->Driver.TexEnv)( ctx, 0, pname, param ); 852114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 853114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger} 854114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 85547a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul 856114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheideggervoid GLAPIENTRY 857114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger_mesa_GetTexBumpParameterivATI( GLenum pname, GLint *param ) 858114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger{ 859114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger const struct gl_texture_unit *texUnit; 86037f2117cd132527ebf89f9294b2f35db87326460José Fonseca GLuint i; 861114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger GET_CURRENT_CONTEXT(ctx); 862114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger ASSERT_OUTSIDE_BEGIN_END(ctx); 863114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 86447a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul if (!ctx->Extensions.ATI_envmap_bumpmap) { 86547a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexBumpParameterivATI"); 86647a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul return; 86747a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul } 8686aa7a03d856f4cfdbed493c976387b2164a0c922Brian Paul 8696aa7a03d856f4cfdbed493c976387b2164a0c922Brian Paul texUnit = _mesa_get_current_tex_unit(ctx); 870114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 871114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger if (pname == GL_BUMP_ROT_MATRIX_SIZE_ATI) { 872114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger /* spec leaves open to support larger matrices. 873114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger Don't think anyone would ever want to use it 874114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger (and apps almost certainly would not understand it and 875114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger thus fail to submit matrices correctly) so hardcode this. */ 876114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger *param = 4; 877114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 878114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger else if (pname == GL_BUMP_ROT_MATRIX_ATI) { 879114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger /* hope that conversion is correct here */ 880114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger param[0] = FLOAT_TO_INT(texUnit->RotMatrix[0]); 881114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger param[1] = FLOAT_TO_INT(texUnit->RotMatrix[1]); 882114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger param[2] = FLOAT_TO_INT(texUnit->RotMatrix[2]); 883114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger param[3] = FLOAT_TO_INT(texUnit->RotMatrix[3]); 884114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 885114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger else if (pname == GL_BUMP_NUM_TEX_UNITS_ATI) { 88647a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul GLint count = 0; 887114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) { 888114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger if (ctx->Const.SupportedBumpUnits & (1 << i)) { 88947a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul count++; 890114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 891114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 89247a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul *param = count; 893114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 894114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger else if (pname == GL_BUMP_TEX_UNITS_ATI) { 895114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) { 896114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger if (ctx->Const.SupportedBumpUnits & (1 << i)) { 897114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger *param++ = i + GL_TEXTURE0; 898114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 899114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 900114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 901114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger else { 902114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexBumpParameter(pname)" ); 903114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger return; 904114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 905114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger} 906114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 90747a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul 908114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheideggervoid GLAPIENTRY 909114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger_mesa_GetTexBumpParameterfvATI( GLenum pname, GLfloat *param ) 910114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger{ 911114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger const struct gl_texture_unit *texUnit; 91237f2117cd132527ebf89f9294b2f35db87326460José Fonseca GLuint i; 913114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger GET_CURRENT_CONTEXT(ctx); 914114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger ASSERT_OUTSIDE_BEGIN_END(ctx); 915114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 91647a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul if (!ctx->Extensions.ATI_envmap_bumpmap) { 91747a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexBumpParameterfvATI"); 91847a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul return; 91947a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul } 9206aa7a03d856f4cfdbed493c976387b2164a0c922Brian Paul 9216aa7a03d856f4cfdbed493c976387b2164a0c922Brian Paul texUnit = _mesa_get_current_tex_unit(ctx); 922114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger 923114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger if (pname == GL_BUMP_ROT_MATRIX_SIZE_ATI) { 924114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger /* spec leaves open to support larger matrices. 925114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger Don't think anyone would ever want to use it 926114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger (and apps might not understand it) so hardcode this. */ 92747a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul *param = 4.0F; 928114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 929114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger else if (pname == GL_BUMP_ROT_MATRIX_ATI) { 930114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger param[0] = texUnit->RotMatrix[0]; 931114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger param[1] = texUnit->RotMatrix[1]; 932114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger param[2] = texUnit->RotMatrix[2]; 933114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger param[3] = texUnit->RotMatrix[3]; 934114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 935114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger else if (pname == GL_BUMP_NUM_TEX_UNITS_ATI) { 93647a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul GLint count = 0; 937114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) { 938114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger if (ctx->Const.SupportedBumpUnits & (1 << i)) { 93947a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul count++; 940114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 941114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 94247a385b43be9cf2ef0d0b24b1d588dc26940dfe6Brian Paul *param = (GLfloat) count; 943114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 944114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger else if (pname == GL_BUMP_TEX_UNITS_ATI) { 945114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) { 946114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger if (ctx->Const.SupportedBumpUnits & (1 << i)) { 947114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger *param++ = (GLfloat) (i + GL_TEXTURE0); 948114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 949114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 950114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 951114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger else { 952114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexBumpParameter(pname)" ); 953114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger return; 954114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger } 955114152e068ec919feb0a57a1259c2ada970b9f02Roland Scheidegger} 956