Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Mesa 3-D graphics library
  3.  *
  4.  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
  5.  * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
  6.  *
  7.  * Permission is hereby granted, free of charge, to any person obtaining a
  8.  * copy of this software and associated documentation files (the "Software"),
  9.  * to deal in the Software without restriction, including without limitation
  10.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11.  * and/or sell copies of the Software, and to permit persons to whom the
  12.  * Software is furnished to do so, subject to the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice shall be included
  15.  * in all copies or substantial portions of the Software.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  20.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  21.  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  22.  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23.  * OTHER DEALINGS IN THE SOFTWARE.
  24.  */
  25.  
  26. /**
  27.  * \file texparam.c
  28.  *
  29.  * glTexParameter-related functions
  30.  */
  31.  
  32. #include <stdbool.h>
  33. #include "main/glheader.h"
  34. #include "main/blend.h"
  35. #include "main/context.h"
  36. #include "main/enums.h"
  37. #include "main/formats.h"
  38. #include "main/glformats.h"
  39. #include "main/macros.h"
  40. #include "main/mtypes.h"
  41. #include "main/state.h"
  42. #include "main/texcompress.h"
  43. #include "main/texobj.h"
  44. #include "main/texparam.h"
  45. #include "main/teximage.h"
  46. #include "main/texstate.h"
  47. #include "program/prog_instruction.h"
  48.  
  49.  
  50. /**
  51.  * Check if a coordinate wrap mode is supported for the texture target.
  52.  * \return GL_TRUE if legal, GL_FALSE otherwise
  53.  */
  54. static GLboolean
  55. validate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap)
  56. {
  57.    const struct gl_extensions * const e = & ctx->Extensions;
  58.    const bool is_desktop_gl = _mesa_is_desktop_gl(ctx);
  59.    bool supported;
  60.  
  61.    switch (wrap) {
  62.    case GL_CLAMP:
  63.       /* GL_CLAMP was removed in the core profile, and it has never existed in
  64.        * OpenGL ES.
  65.        */
  66.       supported = (ctx->API == API_OPENGL_COMPAT)
  67.          && (target != GL_TEXTURE_EXTERNAL_OES);
  68.       break;
  69.  
  70.    case GL_CLAMP_TO_EDGE:
  71.       supported = true;
  72.       break;
  73.  
  74.    case GL_CLAMP_TO_BORDER:
  75.       supported = is_desktop_gl && e->ARB_texture_border_clamp
  76.          && (target != GL_TEXTURE_EXTERNAL_OES);
  77.       break;
  78.  
  79.    case GL_REPEAT:
  80.    case GL_MIRRORED_REPEAT:
  81.       supported = (target != GL_TEXTURE_RECTANGLE_NV)
  82.          && (target != GL_TEXTURE_EXTERNAL_OES);
  83.       break;
  84.  
  85.    case GL_MIRROR_CLAMP_EXT:
  86.       supported = is_desktop_gl
  87.          && (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)
  88.          && (target != GL_TEXTURE_RECTANGLE_NV)
  89.          && (target != GL_TEXTURE_EXTERNAL_OES);
  90.       break;
  91.  
  92.    case GL_MIRROR_CLAMP_TO_EDGE_EXT:
  93.       supported = is_desktop_gl
  94.          && (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp || e->ARB_texture_mirror_clamp_to_edge)
  95.          && (target != GL_TEXTURE_RECTANGLE_NV)
  96.          && (target != GL_TEXTURE_EXTERNAL_OES);
  97.       break;
  98.  
  99.    case GL_MIRROR_CLAMP_TO_BORDER_EXT:
  100.       supported = is_desktop_gl && e->EXT_texture_mirror_clamp
  101.          && (target != GL_TEXTURE_RECTANGLE_NV)
  102.          && (target != GL_TEXTURE_EXTERNAL_OES);
  103.       break;
  104.  
  105.    default:
  106.       supported = false;
  107.       break;
  108.    }
  109.  
  110.    if (!supported)
  111.       _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(param=0x%x)", wrap );
  112.  
  113.    return supported;
  114. }
  115.  
  116.  
  117. /**
  118.  * Get current texture object for given target.
  119.  * Return NULL if any error (and record the error).
  120.  * Note that this is different from _mesa_get_current_tex_object() in that
  121.  * proxy targets are not accepted.
  122.  * Only the glGetTexLevelParameter() functions accept proxy targets.
  123.  */
  124. static struct gl_texture_object *
  125. get_texobj_by_target(struct gl_context *ctx, GLenum target, GLboolean get)
  126. {
  127.    struct gl_texture_unit *texUnit;
  128.    int targetIndex;
  129.  
  130.    if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
  131.       _mesa_error(ctx, GL_INVALID_OPERATION,
  132.                   "gl%sTexParameter(current unit)", get ? "Get" : "");
  133.       return NULL;
  134.    }
  135.  
  136.    texUnit = _mesa_get_current_tex_unit(ctx);
  137.  
  138.    targetIndex = _mesa_tex_target_to_index(ctx, target);
  139.    if (targetIndex < 0 || targetIndex == TEXTURE_BUFFER_INDEX) {
  140.       _mesa_error(ctx, GL_INVALID_ENUM,
  141.                   "gl%sTexParameter(target)", get ? "Get" : "");
  142.       return NULL;
  143.    }
  144.    assert(targetIndex < NUM_TEXTURE_TARGETS);
  145.  
  146.    return texUnit->CurrentTex[targetIndex];
  147. }
  148.  
  149. /**
  150.  * Get current texture object for given name.
  151.  * Return NULL if any error (and record the error).
  152.  * Note that proxy targets are not accepted.
  153.  * Only the glGetTexLevelParameter() functions accept proxy targets.
  154.  */
  155. static struct gl_texture_object *
  156. get_texobj_by_name(struct gl_context *ctx, GLuint texture, GLboolean get)
  157. {
  158.    struct gl_texture_object *texObj;
  159.  
  160.    texObj = _mesa_lookup_texture(ctx, texture);
  161.    if (!texObj) {
  162.       /*
  163.        * User passed a non-generated name.
  164.        * Throw the error in the caller.
  165.        */
  166.       return NULL;
  167.    }
  168.  
  169.    switch (texObj->Target) {
  170.    case GL_TEXTURE_1D:
  171.    case GL_TEXTURE_1D_ARRAY:
  172.    case GL_TEXTURE_2D:
  173.    case GL_TEXTURE_2D_ARRAY:
  174.    case GL_TEXTURE_2D_MULTISAMPLE:
  175.    case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
  176.    case GL_TEXTURE_3D:
  177.    case GL_TEXTURE_CUBE_MAP:
  178.    case GL_TEXTURE_CUBE_MAP_ARRAY:
  179.    case GL_TEXTURE_RECTANGLE:
  180.       return texObj;
  181.    default:
  182.       _mesa_error(ctx, GL_INVALID_ENUM,
  183.                   "gl%sTextureParameter(target)", get ? "Get" : "");
  184.       return NULL;
  185.    }
  186.  
  187. }
  188.  
  189.  
  190. /**
  191.  * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
  192.  * \return -1 if error.
  193.  */
  194. static GLint
  195. comp_to_swizzle(GLenum comp)
  196. {
  197.    switch (comp) {
  198.    case GL_RED:
  199.       return SWIZZLE_X;
  200.    case GL_GREEN:
  201.       return SWIZZLE_Y;
  202.    case GL_BLUE:
  203.       return SWIZZLE_Z;
  204.    case GL_ALPHA:
  205.       return SWIZZLE_W;
  206.    case GL_ZERO:
  207.       return SWIZZLE_ZERO;
  208.    case GL_ONE:
  209.       return SWIZZLE_ONE;
  210.    default:
  211.       return -1;
  212.    }
  213. }
  214.  
  215.  
  216. static void
  217. set_swizzle_component(GLuint *swizzle, GLuint comp, GLuint swz)
  218. {
  219.    assert(comp < 4);
  220.    assert(swz <= SWIZZLE_NIL);
  221.    {
  222.       GLuint mask = 0x7 << (3 * comp);
  223.       GLuint s = (*swizzle & ~mask) | (swz << (3 * comp));
  224.       *swizzle = s;
  225.    }
  226. }
  227.  
  228.  
  229. /**
  230.  * This is called just prior to changing any texture object state which
  231.  * will not affect texture completeness.
  232.  */
  233. static inline void
  234. flush(struct gl_context *ctx)
  235. {
  236.    FLUSH_VERTICES(ctx, _NEW_TEXTURE);
  237. }
  238.  
  239.  
  240. /**
  241.  * This is called just prior to changing any texture object state which
  242.  * could affect texture completeness (texture base level, max level).
  243.  * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
  244.  * state flag and then mark the texture object as 'incomplete' so that any
  245.  * per-texture derived state gets recomputed.
  246.  */
  247. static inline void
  248. incomplete(struct gl_context *ctx, struct gl_texture_object *texObj)
  249. {
  250.    FLUSH_VERTICES(ctx, _NEW_TEXTURE);
  251.    _mesa_dirty_texobj(ctx, texObj);
  252. }
  253.  
  254.  
  255. static GLboolean
  256. target_allows_setting_sampler_parameters(GLenum target)
  257. {
  258.    switch (target) {
  259.    case GL_TEXTURE_2D_MULTISAMPLE:
  260.    case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
  261.       return GL_FALSE;
  262.  
  263.    default:
  264.       return GL_TRUE;
  265.    }
  266. }
  267.  
  268.  
  269. /**
  270.  * Set an integer-valued texture parameter
  271.  * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
  272.  */
  273. static GLboolean
  274. set_tex_parameteri(struct gl_context *ctx,
  275.                    struct gl_texture_object *texObj,
  276.                    GLenum pname, const GLint *params, bool dsa)
  277. {
  278.    const char *suffix = dsa ? "ture" : "";
  279.  
  280.    switch (pname) {
  281.    case GL_TEXTURE_MIN_FILTER:
  282.       if (!target_allows_setting_sampler_parameters(texObj->Target))
  283.          goto invalid_enum;
  284.  
  285.       if (texObj->Sampler.MinFilter == params[0])
  286.          return GL_FALSE;
  287.       switch (params[0]) {
  288.       case GL_NEAREST:
  289.       case GL_LINEAR:
  290.          flush(ctx);
  291.          texObj->Sampler.MinFilter = params[0];
  292.          return GL_TRUE;
  293.       case GL_NEAREST_MIPMAP_NEAREST:
  294.       case GL_LINEAR_MIPMAP_NEAREST:
  295.       case GL_NEAREST_MIPMAP_LINEAR:
  296.       case GL_LINEAR_MIPMAP_LINEAR:
  297.          if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
  298.              texObj->Target != GL_TEXTURE_EXTERNAL_OES) {
  299.             flush(ctx);
  300.             texObj->Sampler.MinFilter = params[0];
  301.             return GL_TRUE;
  302.          }
  303.          /* fall-through */
  304.       default:
  305.          goto invalid_param;
  306.       }
  307.       return GL_FALSE;
  308.  
  309.    case GL_TEXTURE_MAG_FILTER:
  310.       if (!target_allows_setting_sampler_parameters(texObj->Target))
  311.          goto invalid_enum;
  312.  
  313.       if (texObj->Sampler.MagFilter == params[0])
  314.          return GL_FALSE;
  315.       switch (params[0]) {
  316.       case GL_NEAREST:
  317.       case GL_LINEAR:
  318.          flush(ctx); /* does not effect completeness */
  319.          texObj->Sampler.MagFilter = params[0];
  320.          return GL_TRUE;
  321.       default:
  322.          goto invalid_param;
  323.       }
  324.       return GL_FALSE;
  325.  
  326.    case GL_TEXTURE_WRAP_S:
  327.       if (!target_allows_setting_sampler_parameters(texObj->Target))
  328.          goto invalid_enum;
  329.  
  330.       if (texObj->Sampler.WrapS == params[0])
  331.          return GL_FALSE;
  332.       if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
  333.          flush(ctx);
  334.          texObj->Sampler.WrapS = params[0];
  335.          return GL_TRUE;
  336.       }
  337.       return GL_FALSE;
  338.  
  339.    case GL_TEXTURE_WRAP_T:
  340.       if (!target_allows_setting_sampler_parameters(texObj->Target))
  341.          goto invalid_enum;
  342.  
  343.       if (texObj->Sampler.WrapT == params[0])
  344.          return GL_FALSE;
  345.       if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
  346.          flush(ctx);
  347.          texObj->Sampler.WrapT = params[0];
  348.          return GL_TRUE;
  349.       }
  350.       return GL_FALSE;
  351.  
  352.    case GL_TEXTURE_WRAP_R:
  353.       if (!target_allows_setting_sampler_parameters(texObj->Target))
  354.          goto invalid_enum;
  355.  
  356.       if (texObj->Sampler.WrapR == params[0])
  357.          return GL_FALSE;
  358.       if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
  359.          flush(ctx);
  360.          texObj->Sampler.WrapR = params[0];
  361.          return GL_TRUE;
  362.       }
  363.       return GL_FALSE;
  364.  
  365.    case GL_TEXTURE_BASE_LEVEL:
  366.       if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
  367.          goto invalid_pname;
  368.  
  369.       if (texObj->BaseLevel == params[0])
  370.          return GL_FALSE;
  371.  
  372.       if ((texObj->Target == GL_TEXTURE_2D_MULTISAMPLE ||
  373.            texObj->Target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) && params[0] != 0)
  374.          goto invalid_operation;
  375.  
  376.       if (params[0] < 0) {
  377.          _mesa_error(ctx, GL_INVALID_VALUE,
  378.                      "glTex%sParameter(param=%d)", suffix, params[0]);
  379.          return GL_FALSE;
  380.       }
  381.       if (texObj->Target == GL_TEXTURE_RECTANGLE_ARB && params[0] != 0) {
  382.          _mesa_error(ctx, GL_INVALID_OPERATION,
  383.                      "glTex%sParameter(target=%s, param=%d)", suffix,
  384.                      _mesa_lookup_enum_by_nr(texObj->Target), params[0]);
  385.          return GL_FALSE;
  386.       }
  387.       incomplete(ctx, texObj);
  388.  
  389.       /** See note about ARB_texture_storage below */
  390.       if (texObj->Immutable)
  391.          texObj->BaseLevel = MIN2(texObj->ImmutableLevels - 1, params[0]);
  392.       else
  393.          texObj->BaseLevel = params[0];
  394.  
  395.       return GL_TRUE;
  396.  
  397.    case GL_TEXTURE_MAX_LEVEL:
  398.       if (texObj->MaxLevel == params[0])
  399.          return GL_FALSE;
  400.  
  401.       if (params[0] < 0 ||
  402.           (texObj->Target == GL_TEXTURE_RECTANGLE_ARB && params[0] > 0)) {
  403.          _mesa_error(ctx, GL_INVALID_VALUE,
  404.                      "glTex%sParameter(param=%d)", suffix,
  405.                      params[0]);
  406.          return GL_FALSE;
  407.       }
  408.       incomplete(ctx, texObj);
  409.  
  410.       /** From ARB_texture_storage:
  411.        * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
  412.        * clamped to the range [0, <levels> - 1] and level_max is then clamped to
  413.        * the range [level_base, <levels> - 1], where <levels> is the parameter
  414.        * passed the call to TexStorage* for the texture object.
  415.        */
  416.       if (texObj->Immutable)
  417.           texObj->MaxLevel = CLAMP(params[0], texObj->BaseLevel,
  418.                                    texObj->ImmutableLevels - 1);
  419.       else
  420.          texObj->MaxLevel = params[0];
  421.  
  422.       return GL_TRUE;
  423.  
  424.    case GL_GENERATE_MIPMAP_SGIS:
  425.       if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  426.          goto invalid_pname;
  427.  
  428.       if (params[0] && texObj->Target == GL_TEXTURE_EXTERNAL_OES)
  429.          goto invalid_param;
  430.       if (texObj->GenerateMipmap != params[0]) {
  431.          /* no flush() */
  432.          texObj->GenerateMipmap = params[0] ? GL_TRUE : GL_FALSE;
  433.          return GL_TRUE;
  434.       }
  435.       return GL_FALSE;
  436.  
  437.    case GL_TEXTURE_COMPARE_MODE_ARB:
  438.       if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_shadow)
  439.           || _mesa_is_gles3(ctx)) {
  440.  
  441.          if (!target_allows_setting_sampler_parameters(texObj->Target))
  442.             goto invalid_enum;
  443.  
  444.          if (texObj->Sampler.CompareMode == params[0])
  445.             return GL_FALSE;
  446.          if (params[0] == GL_NONE ||
  447.              params[0] == GL_COMPARE_R_TO_TEXTURE_ARB) {
  448.             flush(ctx);
  449.             texObj->Sampler.CompareMode = params[0];
  450.             return GL_TRUE;
  451.          }
  452.          goto invalid_param;
  453.       }
  454.       goto invalid_pname;
  455.  
  456.    case GL_TEXTURE_COMPARE_FUNC_ARB:
  457.       if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_shadow)
  458.           || _mesa_is_gles3(ctx)) {
  459.  
  460.          if (!target_allows_setting_sampler_parameters(texObj->Target))
  461.             goto invalid_enum;
  462.  
  463.          if (texObj->Sampler.CompareFunc == params[0])
  464.             return GL_FALSE;
  465.          switch (params[0]) {
  466.          case GL_LEQUAL:
  467.          case GL_GEQUAL:
  468.          case GL_EQUAL:
  469.          case GL_NOTEQUAL:
  470.          case GL_LESS:
  471.          case GL_GREATER:
  472.          case GL_ALWAYS:
  473.          case GL_NEVER:
  474.             flush(ctx);
  475.             texObj->Sampler.CompareFunc = params[0];
  476.             return GL_TRUE;
  477.          default:
  478.             goto invalid_param;
  479.          }
  480.       }
  481.       goto invalid_pname;
  482.  
  483.    case GL_DEPTH_TEXTURE_MODE_ARB:
  484.       /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
  485.        * existed in OpenGL ES.
  486.        */
  487.       if (ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ARB_depth_texture) {
  488.          if (texObj->DepthMode == params[0])
  489.             return GL_FALSE;
  490.          if (params[0] == GL_LUMINANCE ||
  491.              params[0] == GL_INTENSITY ||
  492.              params[0] == GL_ALPHA ||
  493.              (ctx->Extensions.ARB_texture_rg && params[0] == GL_RED)) {
  494.             flush(ctx);
  495.             texObj->DepthMode = params[0];
  496.             return GL_TRUE;
  497.          }
  498.          goto invalid_param;
  499.       }
  500.       goto invalid_pname;
  501.  
  502.    case GL_DEPTH_STENCIL_TEXTURE_MODE:
  503.       if (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_stencil_texturing) {
  504.          bool stencil = params[0] == GL_STENCIL_INDEX;
  505.          if (!stencil && params[0] != GL_DEPTH_COMPONENT)
  506.             goto invalid_param;
  507.  
  508.          if (texObj->StencilSampling == stencil)
  509.             return GL_FALSE;
  510.  
  511.          texObj->StencilSampling = stencil;
  512.          return GL_TRUE;
  513.       }
  514.       goto invalid_pname;
  515.  
  516.    case GL_TEXTURE_CROP_RECT_OES:
  517.       if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
  518.          goto invalid_pname;
  519.  
  520.       texObj->CropRect[0] = params[0];
  521.       texObj->CropRect[1] = params[1];
  522.       texObj->CropRect[2] = params[2];
  523.       texObj->CropRect[3] = params[3];
  524.       return GL_TRUE;
  525.  
  526.    case GL_TEXTURE_SWIZZLE_R_EXT:
  527.    case GL_TEXTURE_SWIZZLE_G_EXT:
  528.    case GL_TEXTURE_SWIZZLE_B_EXT:
  529.    case GL_TEXTURE_SWIZZLE_A_EXT:
  530.       if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_swizzle)
  531.           || _mesa_is_gles3(ctx)) {
  532.          const GLuint comp = pname - GL_TEXTURE_SWIZZLE_R_EXT;
  533.          const GLint swz = comp_to_swizzle(params[0]);
  534.          if (swz < 0) {
  535.             _mesa_error(ctx, GL_INVALID_ENUM,
  536.                         "glTex%sParameter(swizzle 0x%x)", suffix, params[0]);
  537.             return GL_FALSE;
  538.          }
  539.          assert(comp < 4);
  540.  
  541.          flush(ctx);
  542.          texObj->Swizzle[comp] = params[0];
  543.          set_swizzle_component(&texObj->_Swizzle, comp, swz);
  544.          return GL_TRUE;
  545.       }
  546.       goto invalid_pname;
  547.  
  548.    case GL_TEXTURE_SWIZZLE_RGBA_EXT:
  549.       if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_swizzle)
  550.           || _mesa_is_gles3(ctx)) {
  551.          GLuint comp;
  552.          flush(ctx);
  553.          for (comp = 0; comp < 4; comp++) {
  554.             const GLint swz = comp_to_swizzle(params[comp]);
  555.             if (swz >= 0) {
  556.                texObj->Swizzle[comp] = params[comp];
  557.                set_swizzle_component(&texObj->_Swizzle, comp, swz);
  558.             }
  559.             else {
  560.                _mesa_error(ctx, GL_INVALID_ENUM,
  561.                            "glTex%sParameter(swizzle 0x%x)",
  562.                            suffix, params[comp]);
  563.                return GL_FALSE;
  564.             }
  565.          }
  566.          return GL_TRUE;
  567.       }
  568.       goto invalid_pname;
  569.  
  570.    case GL_TEXTURE_SRGB_DECODE_EXT:
  571.       if (_mesa_is_desktop_gl(ctx)
  572.           && ctx->Extensions.EXT_texture_sRGB_decode) {
  573.          GLenum decode = params[0];
  574.  
  575.          if (!target_allows_setting_sampler_parameters(texObj->Target))
  576.             goto invalid_enum;
  577.  
  578.          if (decode == GL_DECODE_EXT || decode == GL_SKIP_DECODE_EXT) {
  579.             if (texObj->Sampler.sRGBDecode != decode) {
  580.                flush(ctx);
  581.                texObj->Sampler.sRGBDecode = decode;
  582.             }
  583.             return GL_TRUE;
  584.          }
  585.       }
  586.       goto invalid_pname;
  587.  
  588.    case GL_TEXTURE_CUBE_MAP_SEAMLESS:
  589.       if (_mesa_is_desktop_gl(ctx)
  590.           && ctx->Extensions.AMD_seamless_cubemap_per_texture) {
  591.          GLenum param = params[0];
  592.  
  593.          if (!target_allows_setting_sampler_parameters(texObj->Target))
  594.             goto invalid_enum;
  595.  
  596.          if (param != GL_TRUE && param != GL_FALSE) {
  597.             goto invalid_param;
  598.          }
  599.          if (param != texObj->Sampler.CubeMapSeamless) {
  600.             flush(ctx);
  601.             texObj->Sampler.CubeMapSeamless = param;
  602.          }
  603.          return GL_TRUE;
  604.       }
  605.       goto invalid_pname;
  606.  
  607.    default:
  608.       goto invalid_pname;
  609.    }
  610.  
  611. invalid_pname:
  612.    _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
  613.                suffix, _mesa_lookup_enum_by_nr(pname));
  614.    return GL_FALSE;
  615.  
  616. invalid_param:
  617.    _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(param=%s)",
  618.                suffix, _mesa_lookup_enum_by_nr(params[0]));
  619.    return GL_FALSE;
  620.  
  621. invalid_operation:
  622.    _mesa_error(ctx, GL_INVALID_OPERATION, "glTex%sParameter(pname=%s)",
  623.                suffix, _mesa_lookup_enum_by_nr(pname));
  624.    return GL_FALSE;
  625.  
  626. invalid_enum:
  627.    _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
  628.                suffix, _mesa_lookup_enum_by_nr(pname));
  629.    return GL_FALSE;
  630. }
  631.  
  632.  
  633. /**
  634.  * Set a float-valued texture parameter
  635.  * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
  636.  */
  637. static GLboolean
  638. set_tex_parameterf(struct gl_context *ctx,
  639.                    struct gl_texture_object *texObj,
  640.                    GLenum pname, const GLfloat *params, bool dsa)
  641. {
  642.    const char *suffix = dsa ? "ture" : "";
  643.  
  644.    switch (pname) {
  645.    case GL_TEXTURE_MIN_LOD:
  646.       if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
  647.          goto invalid_pname;
  648.  
  649.       if (!target_allows_setting_sampler_parameters(texObj->Target))
  650.          goto invalid_enum;
  651.  
  652.       if (texObj->Sampler.MinLod == params[0])
  653.          return GL_FALSE;
  654.       flush(ctx);
  655.       texObj->Sampler.MinLod = params[0];
  656.       return GL_TRUE;
  657.  
  658.    case GL_TEXTURE_MAX_LOD:
  659.       if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
  660.          goto invalid_pname;
  661.  
  662.       if (!target_allows_setting_sampler_parameters(texObj->Target))
  663.          goto invalid_enum;
  664.  
  665.       if (texObj->Sampler.MaxLod == params[0])
  666.          return GL_FALSE;
  667.       flush(ctx);
  668.       texObj->Sampler.MaxLod = params[0];
  669.       return GL_TRUE;
  670.  
  671.    case GL_TEXTURE_PRIORITY:
  672.       if (ctx->API != API_OPENGL_COMPAT)
  673.          goto invalid_pname;
  674.  
  675.       flush(ctx);
  676.       texObj->Priority = CLAMP(params[0], 0.0F, 1.0F);
  677.       return GL_TRUE;
  678.  
  679.    case GL_TEXTURE_MAX_ANISOTROPY_EXT:
  680.       if (ctx->Extensions.EXT_texture_filter_anisotropic) {
  681.          if (!target_allows_setting_sampler_parameters(texObj->Target))
  682.             goto invalid_enum;
  683.  
  684.          if (texObj->Sampler.MaxAnisotropy == params[0])
  685.             return GL_FALSE;
  686.          if (params[0] < 1.0) {
  687.             _mesa_error(ctx, GL_INVALID_VALUE, "glTex%sParameter(param)",
  688.                         suffix);
  689.             return GL_FALSE;
  690.          }
  691.          flush(ctx);
  692.          /* clamp to max, that's what NVIDIA does */
  693.          texObj->Sampler.MaxAnisotropy = MIN2(params[0],
  694.                                       ctx->Const.MaxTextureMaxAnisotropy);
  695.          return GL_TRUE;
  696.       }
  697.       else {
  698.          static GLuint count = 0;
  699.          if (count++ < 10)
  700.             goto invalid_pname;
  701.       }
  702.       return GL_FALSE;
  703.  
  704.    case GL_TEXTURE_LOD_BIAS:
  705.       /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias. */
  706.       if (_mesa_is_gles(ctx))
  707.          goto invalid_pname;
  708.  
  709.       if (!target_allows_setting_sampler_parameters(texObj->Target))
  710.          goto invalid_enum;
  711.  
  712.       if (texObj->Sampler.LodBias != params[0]) {
  713.          flush(ctx);
  714.          texObj->Sampler.LodBias = params[0];
  715.          return GL_TRUE;
  716.       }
  717.       break;
  718.  
  719.    case GL_TEXTURE_BORDER_COLOR:
  720.       if (!_mesa_is_desktop_gl(ctx))
  721.          goto invalid_pname;
  722.  
  723.       if (!target_allows_setting_sampler_parameters(texObj->Target))
  724.          goto invalid_enum;
  725.  
  726.       flush(ctx);
  727.       /* ARB_texture_float disables clamping */
  728.       if (ctx->Extensions.ARB_texture_float) {
  729.          texObj->Sampler.BorderColor.f[RCOMP] = params[0];
  730.          texObj->Sampler.BorderColor.f[GCOMP] = params[1];
  731.          texObj->Sampler.BorderColor.f[BCOMP] = params[2];
  732.          texObj->Sampler.BorderColor.f[ACOMP] = params[3];
  733.       } else {
  734.          texObj->Sampler.BorderColor.f[RCOMP] = CLAMP(params[0], 0.0F, 1.0F);
  735.          texObj->Sampler.BorderColor.f[GCOMP] = CLAMP(params[1], 0.0F, 1.0F);
  736.          texObj->Sampler.BorderColor.f[BCOMP] = CLAMP(params[2], 0.0F, 1.0F);
  737.          texObj->Sampler.BorderColor.f[ACOMP] = CLAMP(params[3], 0.0F, 1.0F);
  738.       }
  739.       return GL_TRUE;
  740.  
  741.    default:
  742.       goto invalid_pname;
  743.    }
  744.    return GL_FALSE;
  745.  
  746. invalid_pname:
  747.    _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
  748.                suffix, _mesa_lookup_enum_by_nr(pname));
  749.    return GL_FALSE;
  750.  
  751. invalid_enum:
  752.    _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
  753.                suffix, _mesa_lookup_enum_by_nr(pname));
  754.    return GL_FALSE;
  755. }
  756.  
  757.  
  758. void
  759. _mesa_texture_parameterf(struct gl_context *ctx,
  760.                          struct gl_texture_object *texObj,
  761.                          GLenum pname, GLfloat param, bool dsa)
  762. {
  763.    GLboolean need_update;
  764.  
  765.    switch (pname) {
  766.    case GL_TEXTURE_MIN_FILTER:
  767.    case GL_TEXTURE_MAG_FILTER:
  768.    case GL_TEXTURE_WRAP_S:
  769.    case GL_TEXTURE_WRAP_T:
  770.    case GL_TEXTURE_WRAP_R:
  771.    case GL_TEXTURE_BASE_LEVEL:
  772.    case GL_TEXTURE_MAX_LEVEL:
  773.    case GL_GENERATE_MIPMAP_SGIS:
  774.    case GL_TEXTURE_COMPARE_MODE_ARB:
  775.    case GL_TEXTURE_COMPARE_FUNC_ARB:
  776.    case GL_DEPTH_TEXTURE_MODE_ARB:
  777.    case GL_DEPTH_STENCIL_TEXTURE_MODE:
  778.    case GL_TEXTURE_SRGB_DECODE_EXT:
  779.    case GL_TEXTURE_CUBE_MAP_SEAMLESS:
  780.    case GL_TEXTURE_SWIZZLE_R_EXT:
  781.    case GL_TEXTURE_SWIZZLE_G_EXT:
  782.    case GL_TEXTURE_SWIZZLE_B_EXT:
  783.    case GL_TEXTURE_SWIZZLE_A_EXT:
  784.       {
  785.          GLint p[4];
  786.          p[0] = (param > 0) ?
  787.                 ((param > INT_MAX) ? INT_MAX : (GLint) (param + 0.5)) :
  788.                 ((param < INT_MIN) ? INT_MIN : (GLint) (param - 0.5));
  789.  
  790.          p[1] = p[2] = p[3] = 0;
  791.          need_update = set_tex_parameteri(ctx, texObj, pname, p, dsa);
  792.       }
  793.       break;
  794.    case GL_TEXTURE_BORDER_COLOR:
  795.    case GL_TEXTURE_SWIZZLE_RGBA:
  796.       _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameterf(non-scalar pname)",
  797.                   dsa ? "ture" : "");
  798.       return;
  799.    default:
  800.       {
  801.          /* this will generate an error if pname is illegal */
  802.          GLfloat p[4];
  803.          p[0] = param;
  804.          p[1] = p[2] = p[3] = 0.0F;
  805.          need_update = set_tex_parameterf(ctx, texObj, pname, p, dsa);
  806.       }
  807.    }
  808.  
  809.    if (ctx->Driver.TexParameter && need_update) {
  810.       ctx->Driver.TexParameter(ctx, texObj, pname, &param);
  811.    }
  812. }
  813.  
  814.  
  815. void
  816. _mesa_texture_parameterfv(struct gl_context *ctx,
  817.                           struct gl_texture_object *texObj,
  818.                           GLenum pname, const GLfloat *params, bool dsa)
  819. {
  820.    GLboolean need_update;
  821.    switch (pname) {
  822.    case GL_TEXTURE_MIN_FILTER:
  823.    case GL_TEXTURE_MAG_FILTER:
  824.    case GL_TEXTURE_WRAP_S:
  825.    case GL_TEXTURE_WRAP_T:
  826.    case GL_TEXTURE_WRAP_R:
  827.    case GL_TEXTURE_BASE_LEVEL:
  828.    case GL_TEXTURE_MAX_LEVEL:
  829.    case GL_GENERATE_MIPMAP_SGIS:
  830.    case GL_TEXTURE_COMPARE_MODE_ARB:
  831.    case GL_TEXTURE_COMPARE_FUNC_ARB:
  832.    case GL_DEPTH_TEXTURE_MODE_ARB:
  833.    case GL_DEPTH_STENCIL_TEXTURE_MODE:
  834.    case GL_TEXTURE_SRGB_DECODE_EXT:
  835.    case GL_TEXTURE_CUBE_MAP_SEAMLESS:
  836.       {
  837.          /* convert float param to int */
  838.          GLint p[4];
  839.          p[0] = (GLint) params[0];
  840.          p[1] = p[2] = p[3] = 0;
  841.          need_update = set_tex_parameteri(ctx, texObj, pname, p, dsa);
  842.       }
  843.       break;
  844.    case GL_TEXTURE_CROP_RECT_OES:
  845.       {
  846.          /* convert float params to int */
  847.          GLint iparams[4];
  848.          iparams[0] = (GLint) params[0];
  849.          iparams[1] = (GLint) params[1];
  850.          iparams[2] = (GLint) params[2];
  851.          iparams[3] = (GLint) params[3];
  852.          need_update = set_tex_parameteri(ctx, texObj, pname, iparams, dsa);
  853.       }
  854.       break;
  855.    case GL_TEXTURE_SWIZZLE_R_EXT:
  856.    case GL_TEXTURE_SWIZZLE_G_EXT:
  857.    case GL_TEXTURE_SWIZZLE_B_EXT:
  858.    case GL_TEXTURE_SWIZZLE_A_EXT:
  859.    case GL_TEXTURE_SWIZZLE_RGBA_EXT:
  860.       {
  861.          GLint p[4] = {0, 0, 0, 0};
  862.          p[0] = (GLint) params[0];
  863.          if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT) {
  864.             p[1] = (GLint) params[1];
  865.             p[2] = (GLint) params[2];
  866.             p[3] = (GLint) params[3];
  867.          }
  868.          need_update = set_tex_parameteri(ctx, texObj, pname, p, dsa);
  869.       }
  870.       break;
  871.    default:
  872.       /* this will generate an error if pname is illegal */
  873.       need_update = set_tex_parameterf(ctx, texObj, pname, params, dsa);
  874.    }
  875.  
  876.    if (ctx->Driver.TexParameter && need_update) {
  877.       ctx->Driver.TexParameter(ctx, texObj, pname, params);
  878.    }
  879. }
  880.  
  881.  
  882. void
  883. _mesa_texture_parameteri(struct gl_context *ctx,
  884.                          struct gl_texture_object *texObj,
  885.                          GLenum pname, GLint param, bool dsa)
  886. {
  887.    GLboolean need_update;
  888.    switch (pname) {
  889.    case GL_TEXTURE_MIN_LOD:
  890.    case GL_TEXTURE_MAX_LOD:
  891.    case GL_TEXTURE_PRIORITY:
  892.    case GL_TEXTURE_MAX_ANISOTROPY_EXT:
  893.    case GL_TEXTURE_LOD_BIAS:
  894.    case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
  895.       {
  896.          GLfloat fparam[4];
  897.          fparam[0] = (GLfloat) param;
  898.          fparam[1] = fparam[2] = fparam[3] = 0.0F;
  899.          /* convert int param to float */
  900.          need_update = set_tex_parameterf(ctx, texObj, pname, fparam, dsa);
  901.       }
  902.       break;
  903.    case GL_TEXTURE_BORDER_COLOR:
  904.    case GL_TEXTURE_SWIZZLE_RGBA:
  905.       {
  906.          _mesa_error(ctx, GL_INVALID_ENUM,
  907.                      "glTex%sParameteri(non-scalar pname)",
  908.                      dsa ? "ture" : "");
  909.          return;
  910.       }
  911.    default:
  912.       /* this will generate an error if pname is illegal */
  913.       {
  914.          GLint iparam[4];
  915.          iparam[0] = param;
  916.          iparam[1] = iparam[2] = iparam[3] = 0;
  917.          need_update = set_tex_parameteri(ctx, texObj, pname, iparam, dsa);
  918.       }
  919.    }
  920.  
  921.    if (ctx->Driver.TexParameter && need_update) {
  922.       GLfloat fparam = (GLfloat) param;
  923.       ctx->Driver.TexParameter(ctx, texObj, pname, &fparam);
  924.    }
  925. }
  926.  
  927.  
  928. void
  929. _mesa_texture_parameteriv(struct gl_context *ctx,
  930.                           struct gl_texture_object *texObj,
  931.                           GLenum pname, const GLint *params, bool dsa)
  932. {
  933.    GLboolean need_update;
  934.  
  935.    switch (pname) {
  936.    case GL_TEXTURE_BORDER_COLOR:
  937.       {
  938.          /* convert int params to float */
  939.          GLfloat fparams[4];
  940.          fparams[0] = INT_TO_FLOAT(params[0]);
  941.          fparams[1] = INT_TO_FLOAT(params[1]);
  942.          fparams[2] = INT_TO_FLOAT(params[2]);
  943.          fparams[3] = INT_TO_FLOAT(params[3]);
  944.          need_update = set_tex_parameterf(ctx, texObj, pname, fparams, dsa);
  945.       }
  946.       break;
  947.    case GL_TEXTURE_MIN_LOD:
  948.    case GL_TEXTURE_MAX_LOD:
  949.    case GL_TEXTURE_PRIORITY:
  950.    case GL_TEXTURE_MAX_ANISOTROPY_EXT:
  951.    case GL_TEXTURE_LOD_BIAS:
  952.    case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
  953.       {
  954.          /* convert int param to float */
  955.          GLfloat fparams[4];
  956.          fparams[0] = (GLfloat) params[0];
  957.          fparams[1] = fparams[2] = fparams[3] = 0.0F;
  958.          need_update = set_tex_parameterf(ctx, texObj, pname, fparams, dsa);
  959.       }
  960.       break;
  961.    default:
  962.       /* this will generate an error if pname is illegal */
  963.       need_update = set_tex_parameteri(ctx, texObj, pname, params, dsa);
  964.    }
  965.  
  966.    if (ctx->Driver.TexParameter && need_update) {
  967.       GLfloat fparams[4];
  968.       fparams[0] = INT_TO_FLOAT(params[0]);
  969.       if (pname == GL_TEXTURE_BORDER_COLOR ||
  970.           pname == GL_TEXTURE_CROP_RECT_OES) {
  971.          fparams[1] = INT_TO_FLOAT(params[1]);
  972.          fparams[2] = INT_TO_FLOAT(params[2]);
  973.          fparams[3] = INT_TO_FLOAT(params[3]);
  974.       }
  975.       ctx->Driver.TexParameter(ctx, texObj, pname, fparams);
  976.    }
  977. }
  978.  
  979. void
  980. _mesa_texture_parameterIiv(struct gl_context *ctx,
  981.                            struct gl_texture_object *texObj,
  982.                            GLenum pname, const GLint *params, bool dsa)
  983. {
  984.    switch (pname) {
  985.    case GL_TEXTURE_BORDER_COLOR:
  986.       FLUSH_VERTICES(ctx, _NEW_TEXTURE);
  987.       /* set the integer-valued border color */
  988.       COPY_4V(texObj->Sampler.BorderColor.i, params);
  989.       break;
  990.    default:
  991.       _mesa_texture_parameteriv(ctx, texObj, pname, params, dsa);
  992.       break;
  993.    }
  994.    /* XXX no driver hook for TexParameterIiv() yet */
  995. }
  996.  
  997. void
  998. _mesa_texture_parameterIuiv(struct gl_context *ctx,
  999.                             struct gl_texture_object *texObj,
  1000.                             GLenum pname, const GLuint *params, bool dsa)
  1001. {
  1002.    switch (pname) {
  1003.    case GL_TEXTURE_BORDER_COLOR:
  1004.       FLUSH_VERTICES(ctx, _NEW_TEXTURE);
  1005.       /* set the unsigned integer-valued border color */
  1006.       COPY_4V(texObj->Sampler.BorderColor.ui, params);
  1007.       break;
  1008.    default:
  1009.       _mesa_texture_parameteriv(ctx, texObj, pname, (const GLint *) params,
  1010.                                 dsa);
  1011.       break;
  1012.    }
  1013.    /* XXX no driver hook for TexParameterIuiv() yet */
  1014. }
  1015.  
  1016. void GLAPIENTRY
  1017. _mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
  1018. {
  1019.    struct gl_texture_object *texObj;
  1020.    GET_CURRENT_CONTEXT(ctx);
  1021.  
  1022.    texObj = get_texobj_by_target(ctx, target, GL_FALSE);
  1023.    if (!texObj)
  1024.       return;
  1025.  
  1026.    _mesa_texture_parameterf(ctx, texObj, pname, param, false);
  1027. }
  1028.  
  1029. void GLAPIENTRY
  1030. _mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
  1031. {
  1032.    struct gl_texture_object *texObj;
  1033.    GET_CURRENT_CONTEXT(ctx);
  1034.  
  1035.    texObj = get_texobj_by_target(ctx, target, GL_FALSE);
  1036.    if (!texObj)
  1037.       return;
  1038.  
  1039.    _mesa_texture_parameterfv(ctx, texObj, pname, params, false);
  1040. }
  1041.  
  1042. void GLAPIENTRY
  1043. _mesa_TexParameteri(GLenum target, GLenum pname, GLint param)
  1044. {
  1045.    struct gl_texture_object *texObj;
  1046.    GET_CURRENT_CONTEXT(ctx);
  1047.  
  1048.    texObj = get_texobj_by_target(ctx, target, GL_FALSE);
  1049.    if (!texObj)
  1050.       return;
  1051.  
  1052.    _mesa_texture_parameteri(ctx, texObj, pname, param, false);
  1053. }
  1054.  
  1055. void GLAPIENTRY
  1056. _mesa_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
  1057. {
  1058.    struct gl_texture_object *texObj;
  1059.    GET_CURRENT_CONTEXT(ctx);
  1060.  
  1061.    texObj = get_texobj_by_target(ctx, target, GL_FALSE);
  1062.    if (!texObj)
  1063.       return;
  1064.  
  1065.    _mesa_texture_parameteriv(ctx, texObj, pname, params, false);
  1066. }
  1067.  
  1068. /**
  1069.  * Set tex parameter to integer value(s).  Primarily intended to set
  1070.  * integer-valued texture border color (for integer-valued textures).
  1071.  * New in GL 3.0.
  1072.  */
  1073. void GLAPIENTRY
  1074. _mesa_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
  1075. {
  1076.    struct gl_texture_object *texObj;
  1077.    GET_CURRENT_CONTEXT(ctx);
  1078.  
  1079.    texObj = get_texobj_by_target(ctx, target, GL_FALSE);
  1080.    if (!texObj)
  1081.       return;
  1082.  
  1083.    _mesa_texture_parameterIiv(ctx, texObj, pname, params, false);
  1084. }
  1085.  
  1086. /**
  1087.  * Set tex parameter to unsigned integer value(s).  Primarily intended to set
  1088.  * uint-valued texture border color (for integer-valued textures).
  1089.  * New in GL 3.0
  1090.  */
  1091. void GLAPIENTRY
  1092. _mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
  1093. {
  1094.    struct gl_texture_object *texObj;
  1095.    GET_CURRENT_CONTEXT(ctx);
  1096.  
  1097.    texObj = get_texobj_by_target(ctx, target, GL_FALSE);
  1098.    if (!texObj)
  1099.       return;
  1100.  
  1101.    _mesa_texture_parameterIuiv(ctx, texObj, pname, params, false);
  1102. }
  1103.  
  1104.  
  1105. void GLAPIENTRY
  1106. _mesa_TextureParameterfv(GLuint texture, GLenum pname, const GLfloat *params)
  1107. {
  1108.    struct gl_texture_object *texObj;
  1109.    GET_CURRENT_CONTEXT(ctx);
  1110.  
  1111.    if (!ctx->Extensions.ARB_direct_state_access) {
  1112.       _mesa_error(ctx, GL_INVALID_OPERATION,
  1113.                   "glTextureParameterfv(GL_ARB_direct_state_access "
  1114.                   "is not supported)");
  1115.       return;
  1116.    }
  1117.  
  1118.    texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
  1119.    if (!texObj) {
  1120.       /* User passed a non-generated name. */
  1121.       _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterfv(texture)");
  1122.       return;
  1123.    }
  1124.  
  1125.    _mesa_texture_parameterfv(ctx, texObj, pname, params, true);
  1126. }
  1127.  
  1128. void GLAPIENTRY
  1129. _mesa_TextureParameterf(GLuint texture, GLenum pname, GLfloat param)
  1130. {
  1131.    struct gl_texture_object *texObj;
  1132.    GET_CURRENT_CONTEXT(ctx);
  1133.  
  1134.    if (!ctx->Extensions.ARB_direct_state_access) {
  1135.       _mesa_error(ctx, GL_INVALID_OPERATION,
  1136.                   "glTextureParameterf(GL_ARB_direct_state_access "
  1137.                   "is not supported)");
  1138.       return;
  1139.    }
  1140.  
  1141.    texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
  1142.    if (!texObj) {
  1143.       /* User passed a non-generated name. */
  1144.       _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterf(texture)");
  1145.       return;
  1146.    }
  1147.  
  1148.    _mesa_texture_parameterf(ctx, texObj, pname, param, true);
  1149. }
  1150.  
  1151. void GLAPIENTRY
  1152. _mesa_TextureParameteri(GLuint texture, GLenum pname, GLint param)
  1153. {
  1154.    struct gl_texture_object *texObj;
  1155.    GET_CURRENT_CONTEXT(ctx);
  1156.  
  1157.    if (!ctx->Extensions.ARB_direct_state_access) {
  1158.       _mesa_error(ctx, GL_INVALID_OPERATION,
  1159.                   "glTextureParameteri(GL_ARB_direct_state_access "
  1160.                   "is not supported)");
  1161.       return;
  1162.    }
  1163.  
  1164.    texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
  1165.    if (!texObj) {
  1166.       /* User passed a non-generated name. */
  1167.       _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameteri(texture)");
  1168.       return;
  1169.    }
  1170.  
  1171.    _mesa_texture_parameteri(ctx, texObj, pname, param, true);
  1172. }
  1173.  
  1174. void GLAPIENTRY
  1175. _mesa_TextureParameteriv(GLuint texture, GLenum pname,
  1176.                          const GLint *params)
  1177. {
  1178.    struct gl_texture_object *texObj;
  1179.    GET_CURRENT_CONTEXT(ctx);
  1180.  
  1181.    if (!ctx->Extensions.ARB_direct_state_access) {
  1182.       _mesa_error(ctx, GL_INVALID_OPERATION,
  1183.                   "glTextureParameteriv(GL_ARB_direct_state_access "
  1184.                   "is not supported)");
  1185.       return;
  1186.    }
  1187.  
  1188.    texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
  1189.    if (!texObj) {
  1190.       /* User passed a non-generated name. */
  1191.       _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameteriv(texture)");
  1192.       return;
  1193.    }
  1194.  
  1195.    _mesa_texture_parameteriv(ctx, texObj, pname, params, true);
  1196. }
  1197.  
  1198.  
  1199. void GLAPIENTRY
  1200. _mesa_TextureParameterIiv(GLuint texture, GLenum pname, const GLint *params)
  1201. {
  1202.    struct gl_texture_object *texObj;
  1203.    GET_CURRENT_CONTEXT(ctx);
  1204.  
  1205.    if (!ctx->Extensions.ARB_direct_state_access) {
  1206.       _mesa_error(ctx, GL_INVALID_OPERATION,
  1207.                   "glTextureParameterIiv(GL_ARB_direct_state_access "
  1208.                   "is not supported)");
  1209.       return;
  1210.    }
  1211.  
  1212.    texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
  1213.    if (!texObj) {
  1214.       /* User passed a non-generated name. */
  1215.       _mesa_error(ctx, GL_INVALID_OPERATION,
  1216.                   "glTextureParameterIiv(texture)");
  1217.       return;
  1218.    }
  1219.  
  1220.    _mesa_texture_parameterIiv(ctx, texObj, pname, params, true);
  1221. }
  1222.  
  1223. void GLAPIENTRY
  1224. _mesa_TextureParameterIuiv(GLuint texture, GLenum pname, const GLuint *params)
  1225. {
  1226.    struct gl_texture_object *texObj;
  1227.    GET_CURRENT_CONTEXT(ctx);
  1228.  
  1229.    if (!ctx->Extensions.ARB_direct_state_access) {
  1230.       _mesa_error(ctx, GL_INVALID_OPERATION,
  1231.                   "glTextureParameterIuiv(GL_ARB_direct_state_access "
  1232.                   "is not supported)");
  1233.       return;
  1234.    }
  1235.  
  1236.    texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
  1237.    if (!texObj) {
  1238.       /* User passed a non-generated name. */
  1239.       _mesa_error(ctx, GL_INVALID_OPERATION,
  1240.                   "glTextureParameterIuiv(texture)");
  1241.       return;
  1242.    }
  1243.  
  1244.    _mesa_texture_parameterIuiv(ctx, texObj, pname, params, true);
  1245. }
  1246.  
  1247. static GLboolean
  1248. legal_get_tex_level_parameter_target(struct gl_context *ctx, GLenum target,
  1249.                                      bool dsa)
  1250. {
  1251.    switch (target) {
  1252.    case GL_TEXTURE_1D:
  1253.    case GL_PROXY_TEXTURE_1D:
  1254.    case GL_TEXTURE_2D:
  1255.    case GL_PROXY_TEXTURE_2D:
  1256.    case GL_TEXTURE_3D:
  1257.    case GL_PROXY_TEXTURE_3D:
  1258.       return GL_TRUE;
  1259.    case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
  1260.    case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
  1261.    case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
  1262.    case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
  1263.    case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
  1264.    case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
  1265.    case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
  1266.       return ctx->Extensions.ARB_texture_cube_map;
  1267.    case GL_TEXTURE_CUBE_MAP_ARRAY_ARB:
  1268.    case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB:
  1269.       return ctx->Extensions.ARB_texture_cube_map_array;
  1270.    case GL_TEXTURE_RECTANGLE_NV:
  1271.    case GL_PROXY_TEXTURE_RECTANGLE_NV:
  1272.       return ctx->Extensions.NV_texture_rectangle;
  1273.    case GL_TEXTURE_1D_ARRAY_EXT:
  1274.    case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
  1275.    case GL_TEXTURE_2D_ARRAY_EXT:
  1276.    case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
  1277.       return ctx->Extensions.EXT_texture_array;
  1278.    case GL_TEXTURE_BUFFER:
  1279.       /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
  1280.        * but not in earlier versions that expose ARB_texture_buffer_object.
  1281.        *
  1282.        * From the ARB_texture_buffer_object spec:
  1283.        * "(7) Do buffer textures support texture parameters (TexParameter) or
  1284.        *      queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
  1285.        *
  1286.        *    RESOLVED:  No. [...] Note that the spec edits above don't add
  1287.        *    explicit error language for any of these cases.  That is because
  1288.        *    each of the functions enumerate the set of valid <target>
  1289.        *    parameters.  Not editing the spec to allow TEXTURE_BUFFER_ARB in
  1290.        *    these cases means that target is not legal, and an INVALID_ENUM
  1291.        *    error should be generated."
  1292.        *
  1293.        * From the OpenGL 3.1 spec:
  1294.        * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
  1295.        */
  1296.       return ctx->API == API_OPENGL_CORE && ctx->Version >= 31;
  1297.    case GL_TEXTURE_2D_MULTISAMPLE:
  1298.    case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
  1299.    case GL_PROXY_TEXTURE_2D_MULTISAMPLE:
  1300.    case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY:
  1301.       return ctx->Extensions.ARB_texture_multisample;
  1302.  
  1303.    /*  This is a valid target for dsa, but the OpenGL 4.5 core spec
  1304.     *  (30.10.2014) Section 8.11 Texture Queries says:
  1305.     *       "For GetTextureLevelParameter* only, texture may also be a cube
  1306.     *       map texture object.  In this case the query is always performed
  1307.     *       for face zero (the TEXTURE_CUBE_MAP_POSITIVE_X face), since there
  1308.     *       is no way to specify another face."
  1309.     */
  1310.    case GL_TEXTURE_CUBE_MAP:
  1311.       return dsa;
  1312.    default:
  1313.       return GL_FALSE;
  1314.    }
  1315. }
  1316.  
  1317.  
  1318. static void
  1319. get_tex_level_parameter_image(struct gl_context *ctx,
  1320.                               const struct gl_texture_object *texObj,
  1321.                               GLenum target, GLint level,
  1322.                               GLenum pname, GLint *params,
  1323.                               bool dsa)
  1324. {
  1325.    const struct gl_texture_image *img = NULL;
  1326.    struct gl_texture_image dummy_image;
  1327.    mesa_format texFormat;
  1328.    const char *suffix = dsa ? "ture" : "";
  1329.  
  1330.    img = _mesa_select_tex_image(texObj, target, level);
  1331.    if (!img || img->TexFormat == MESA_FORMAT_NONE) {
  1332.       /* In case of undefined texture image return the default values.
  1333.        *
  1334.        * From OpenGL 4.0 spec, page 398:
  1335.        *    "The initial internal format of a texel array is RGBA
  1336.        *     instead of 1. TEXTURE_COMPONENTS is deprecated; always
  1337.        *     use TEXTURE_INTERNAL_FORMAT."
  1338.        */
  1339.       memset(&dummy_image, 0, sizeof(dummy_image));
  1340.       dummy_image.TexFormat = MESA_FORMAT_NONE;
  1341.       dummy_image.InternalFormat = GL_RGBA;
  1342.       dummy_image._BaseFormat = GL_NONE;
  1343.  
  1344.       img = &dummy_image;
  1345.    }
  1346.  
  1347.    texFormat = img->TexFormat;
  1348.  
  1349.    switch (pname) {
  1350.       case GL_TEXTURE_WIDTH:
  1351.          *params = img->Width;
  1352.          break;
  1353.       case GL_TEXTURE_HEIGHT:
  1354.          *params = img->Height;
  1355.          break;
  1356.       case GL_TEXTURE_DEPTH:
  1357.          *params = img->Depth;
  1358.          break;
  1359.       case GL_TEXTURE_INTERNAL_FORMAT:
  1360.          if (_mesa_is_format_compressed(texFormat)) {
  1361.             /* need to return the actual compressed format */
  1362.             *params = _mesa_compressed_format_to_glenum(ctx, texFormat);
  1363.          }
  1364.          else {
  1365.             /* If the true internal format is not compressed but the user
  1366.              * requested a generic compressed format, we have to return the
  1367.              * generic base format that matches.
  1368.              *
  1369.              * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
  1370.              *
  1371.              *     "If no specific compressed format is available,
  1372.              *     internalformat is instead replaced by the corresponding base
  1373.              *     internal format."
  1374.              *
  1375.              * Otherwise just return the user's requested internal format
  1376.              */
  1377.             const GLenum f =
  1378.                _mesa_gl_compressed_format_base_format(img->InternalFormat);
  1379.  
  1380.             *params = (f != 0) ? f : img->InternalFormat;
  1381.          }
  1382.          break;
  1383.       case GL_TEXTURE_BORDER:
  1384.          if (ctx->API != API_OPENGL_COMPAT)
  1385.             goto invalid_pname;
  1386.          *params = img->Border;
  1387.          break;
  1388.       case GL_TEXTURE_RED_SIZE:
  1389.       case GL_TEXTURE_GREEN_SIZE:
  1390.       case GL_TEXTURE_BLUE_SIZE:
  1391.       case GL_TEXTURE_ALPHA_SIZE:
  1392.          if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
  1393.             *params = _mesa_get_format_bits(texFormat, pname);
  1394.          else
  1395.             *params = 0;
  1396.          break;
  1397.       case GL_TEXTURE_INTENSITY_SIZE:
  1398.       case GL_TEXTURE_LUMINANCE_SIZE:
  1399.          if (ctx->API != API_OPENGL_COMPAT)
  1400.             goto invalid_pname;
  1401.          if (_mesa_base_format_has_channel(img->_BaseFormat, pname)) {
  1402.             *params = _mesa_get_format_bits(texFormat, pname);
  1403.             if (*params == 0) {
  1404.                /* intensity or luminance is probably stored as RGB[A] */
  1405.                *params = MIN2(_mesa_get_format_bits(texFormat,
  1406.                                                     GL_TEXTURE_RED_SIZE),
  1407.                               _mesa_get_format_bits(texFormat,
  1408.                                                     GL_TEXTURE_GREEN_SIZE));
  1409.             }
  1410.          }
  1411.          else {
  1412.             *params = 0;
  1413.          }
  1414.          break;
  1415.       case GL_TEXTURE_DEPTH_SIZE_ARB:
  1416.          if (!ctx->Extensions.ARB_depth_texture)
  1417.             goto invalid_pname;
  1418.          *params = _mesa_get_format_bits(texFormat, pname);
  1419.          break;
  1420.       case GL_TEXTURE_STENCIL_SIZE:
  1421.          *params = _mesa_get_format_bits(texFormat, pname);
  1422.          break;
  1423.       case GL_TEXTURE_SHARED_SIZE:
  1424.          if (ctx->Version < 30 &&
  1425.              !ctx->Extensions.EXT_texture_shared_exponent)
  1426.             goto invalid_pname;
  1427.          *params = texFormat == MESA_FORMAT_R9G9B9E5_FLOAT ? 5 : 0;
  1428.          break;
  1429.  
  1430.       /* GL_ARB_texture_compression */
  1431.       case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
  1432.          if (_mesa_is_format_compressed(texFormat) &&
  1433.              !_mesa_is_proxy_texture(target)) {
  1434.             *params = _mesa_format_image_size(texFormat, img->Width,
  1435.                                               img->Height, img->Depth);
  1436.     }
  1437.     else {
  1438.        _mesa_error(ctx, GL_INVALID_OPERATION,
  1439.                    "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
  1440.                    _mesa_lookup_enum_by_nr(pname));
  1441.     }
  1442.          break;
  1443.       case GL_TEXTURE_COMPRESSED:
  1444.          *params = (GLint) _mesa_is_format_compressed(texFormat);
  1445.          break;
  1446.  
  1447.       /* GL_ARB_texture_float */
  1448.       case GL_TEXTURE_LUMINANCE_TYPE_ARB:
  1449.       case GL_TEXTURE_INTENSITY_TYPE_ARB:
  1450.          if (ctx->API != API_OPENGL_COMPAT)
  1451.             goto invalid_pname;
  1452.          /* FALLTHROUGH */
  1453.       case GL_TEXTURE_RED_TYPE_ARB:
  1454.       case GL_TEXTURE_GREEN_TYPE_ARB:
  1455.       case GL_TEXTURE_BLUE_TYPE_ARB:
  1456.       case GL_TEXTURE_ALPHA_TYPE_ARB:
  1457.       case GL_TEXTURE_DEPTH_TYPE_ARB:
  1458.          if (!ctx->Extensions.ARB_texture_float)
  1459.             goto invalid_pname;
  1460.          if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
  1461.             *params = _mesa_get_format_datatype(texFormat);
  1462.          else
  1463.             *params = GL_NONE;
  1464.          break;
  1465.  
  1466.       /* GL_ARB_texture_multisample */
  1467.       case GL_TEXTURE_SAMPLES:
  1468.          if (!ctx->Extensions.ARB_texture_multisample)
  1469.             goto invalid_pname;
  1470.          *params = img->NumSamples;
  1471.          break;
  1472.  
  1473.       case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
  1474.          if (!ctx->Extensions.ARB_texture_multisample)
  1475.             goto invalid_pname;
  1476.          *params = img->FixedSampleLocations;
  1477.          break;
  1478.  
  1479.       default:
  1480.          goto invalid_pname;
  1481.    }
  1482.  
  1483.    /* no error if we get here */
  1484.    return;
  1485.  
  1486. invalid_pname:
  1487.    _mesa_error(ctx, GL_INVALID_ENUM,
  1488.                "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
  1489.                _mesa_lookup_enum_by_nr(pname));
  1490. }
  1491.  
  1492.  
  1493. static void
  1494. get_tex_level_parameter_buffer(struct gl_context *ctx,
  1495.                                const struct gl_texture_object *texObj,
  1496.                                GLenum pname, GLint *params, bool dsa)
  1497. {
  1498.    const struct gl_buffer_object *bo = texObj->BufferObject;
  1499.    mesa_format texFormat = texObj->_BufferObjectFormat;
  1500.    GLenum internalFormat = texObj->BufferObjectFormat;
  1501.    GLenum baseFormat = _mesa_get_format_base_format(texFormat);
  1502.    const char *suffix = dsa ? "ture" : "";
  1503.  
  1504.    if (!bo) {
  1505.       /* undefined texture buffer object */
  1506.       *params = pname == GL_TEXTURE_COMPONENTS ? 1 : 0;
  1507.       return;
  1508.    }
  1509.  
  1510.    switch (pname) {
  1511.       case GL_TEXTURE_BUFFER_DATA_STORE_BINDING:
  1512.          *params = bo->Name;
  1513.          break;
  1514.       case GL_TEXTURE_WIDTH:
  1515.          *params = bo->Size;
  1516.          break;
  1517.       case GL_TEXTURE_HEIGHT:
  1518.       case GL_TEXTURE_DEPTH:
  1519.       case GL_TEXTURE_BORDER:
  1520.       case GL_TEXTURE_SHARED_SIZE:
  1521.       case GL_TEXTURE_COMPRESSED:
  1522.          *params = 0;
  1523.          break;
  1524.       case GL_TEXTURE_INTERNAL_FORMAT:
  1525.          *params = internalFormat;
  1526.          break;
  1527.       case GL_TEXTURE_RED_SIZE:
  1528.       case GL_TEXTURE_GREEN_SIZE:
  1529.       case GL_TEXTURE_BLUE_SIZE:
  1530.       case GL_TEXTURE_ALPHA_SIZE:
  1531.          if (_mesa_base_format_has_channel(baseFormat, pname))
  1532.             *params = _mesa_get_format_bits(texFormat, pname);
  1533.          else
  1534.             *params = 0;
  1535.          break;
  1536.       case GL_TEXTURE_INTENSITY_SIZE:
  1537.       case GL_TEXTURE_LUMINANCE_SIZE:
  1538.          if (_mesa_base_format_has_channel(baseFormat, pname)) {
  1539.             *params = _mesa_get_format_bits(texFormat, pname);
  1540.             if (*params == 0) {
  1541.                /* intensity or luminance is probably stored as RGB[A] */
  1542.                *params = MIN2(_mesa_get_format_bits(texFormat,
  1543.                                                     GL_TEXTURE_RED_SIZE),
  1544.                               _mesa_get_format_bits(texFormat,
  1545.                                                     GL_TEXTURE_GREEN_SIZE));
  1546.             }
  1547.          } else {
  1548.             *params = 0;
  1549.          }
  1550.          break;
  1551.       case GL_TEXTURE_DEPTH_SIZE_ARB:
  1552.       case GL_TEXTURE_STENCIL_SIZE_EXT:
  1553.          *params = _mesa_get_format_bits(texFormat, pname);
  1554.          break;
  1555.  
  1556.       /* GL_ARB_texture_buffer_range */
  1557.       case GL_TEXTURE_BUFFER_OFFSET:
  1558.          if (!ctx->Extensions.ARB_texture_buffer_range)
  1559.             goto invalid_pname;
  1560.          *params = texObj->BufferOffset;
  1561.          break;
  1562.       case GL_TEXTURE_BUFFER_SIZE:
  1563.          if (!ctx->Extensions.ARB_texture_buffer_range)
  1564.             goto invalid_pname;
  1565.          *params = (texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize;
  1566.          break;
  1567.  
  1568.       /* GL_ARB_texture_compression */
  1569.       case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
  1570.          /* Always illegal for GL_TEXTURE_BUFFER */
  1571.          _mesa_error(ctx, GL_INVALID_OPERATION,
  1572.                      "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
  1573.                      _mesa_lookup_enum_by_nr(pname));
  1574.          break;
  1575.  
  1576.       /* GL_ARB_texture_float */
  1577.       case GL_TEXTURE_RED_TYPE_ARB:
  1578.       case GL_TEXTURE_GREEN_TYPE_ARB:
  1579.       case GL_TEXTURE_BLUE_TYPE_ARB:
  1580.       case GL_TEXTURE_ALPHA_TYPE_ARB:
  1581.       case GL_TEXTURE_LUMINANCE_TYPE_ARB:
  1582.       case GL_TEXTURE_INTENSITY_TYPE_ARB:
  1583.       case GL_TEXTURE_DEPTH_TYPE_ARB:
  1584.          if (!ctx->Extensions.ARB_texture_float)
  1585.             goto invalid_pname;
  1586.          if (_mesa_base_format_has_channel(baseFormat, pname))
  1587.             *params = _mesa_get_format_datatype(texFormat);
  1588.          else
  1589.             *params = GL_NONE;
  1590.          break;
  1591.  
  1592.       default:
  1593.          goto invalid_pname;
  1594.    }
  1595.  
  1596.    /* no error if we get here */
  1597.    return;
  1598.  
  1599. invalid_pname:
  1600.    _mesa_error(ctx, GL_INVALID_ENUM,
  1601.                "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
  1602.                _mesa_lookup_enum_by_nr(pname));
  1603. }
  1604.  
  1605.  
  1606. /**
  1607.  * This isn't exposed to the rest of the driver because it is a part of the
  1608.  * OpenGL API that is rarely used.
  1609.  */
  1610. static void
  1611. get_tex_level_parameteriv(struct gl_context *ctx,
  1612.                           struct gl_texture_object *texObj,
  1613.                           GLenum target, GLint level,
  1614.                           GLenum pname, GLint *params,
  1615.                           bool dsa)
  1616. {
  1617.    GLint maxLevels;
  1618.    const char *suffix = dsa ? "ture" : "";
  1619.  
  1620.    /* Check for errors */
  1621.    if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
  1622.       _mesa_error(ctx, GL_INVALID_OPERATION,
  1623.                   "glGetTex%sLevelParameter[if]v("
  1624.                   "current unit >= max combined texture units)", suffix);
  1625.       return;
  1626.    }
  1627.  
  1628.    if (!legal_get_tex_level_parameter_target(ctx, target, dsa)) {
  1629.       _mesa_error(ctx, GL_INVALID_ENUM,
  1630.                   "glGetTex%sLevelParameter[if]v(target=%s)", suffix,
  1631.                   _mesa_lookup_enum_by_nr(target));
  1632.       return;
  1633.    }
  1634.  
  1635.    maxLevels = _mesa_max_texture_levels(ctx, target);
  1636.    assert(maxLevels != 0);
  1637.  
  1638.    if (level < 0 || level >= maxLevels) {
  1639.       _mesa_error(ctx, GL_INVALID_VALUE,
  1640.                   "glGetTex%sLevelParameter[if]v(level out of range)", suffix);
  1641.       return;
  1642.    }
  1643.  
  1644.    /* Get the level parameter */
  1645.    if (target == GL_TEXTURE_BUFFER) {
  1646.       get_tex_level_parameter_buffer(ctx, texObj, pname, params, dsa);
  1647.    }
  1648.    else {
  1649.       get_tex_level_parameter_image(ctx, texObj, target,
  1650.                                     level, pname, params, dsa);
  1651.    }
  1652. }
  1653.  
  1654. void GLAPIENTRY
  1655. _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
  1656.                               GLenum pname, GLfloat *params )
  1657. {
  1658.    struct gl_texture_object *texObj;
  1659.    GLint iparam;
  1660.    GET_CURRENT_CONTEXT(ctx);
  1661.  
  1662.    texObj = _mesa_get_current_tex_object(ctx, target);
  1663.    if (!texObj)
  1664.       return;
  1665.  
  1666.    get_tex_level_parameteriv(ctx, texObj, target, level,
  1667.                              pname, &iparam, false);
  1668.  
  1669.    *params = (GLfloat) iparam;
  1670. }
  1671.  
  1672. void GLAPIENTRY
  1673. _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
  1674.                               GLenum pname, GLint *params )
  1675. {
  1676.    struct gl_texture_object *texObj;
  1677.    GET_CURRENT_CONTEXT(ctx);
  1678.  
  1679.    texObj = _mesa_get_current_tex_object(ctx, target);
  1680.    if (!texObj)
  1681.       return;
  1682.  
  1683.    get_tex_level_parameteriv(ctx, texObj, target, level,
  1684.                              pname, params, false);
  1685. }
  1686.  
  1687. void GLAPIENTRY
  1688. _mesa_GetTextureLevelParameterfv(GLuint texture, GLint level,
  1689.                                  GLenum pname, GLfloat *params)
  1690. {
  1691.    struct gl_texture_object *texObj;
  1692.    GLint iparam;
  1693.    GET_CURRENT_CONTEXT(ctx);
  1694.  
  1695.    if (!ctx->Extensions.ARB_direct_state_access) {
  1696.       _mesa_error(ctx, GL_INVALID_OPERATION,
  1697.                   "glGetTextureLevelParameterfv(GL_ARB_direct_state_access "
  1698.                   "is not supported)");
  1699.       return;
  1700.    }
  1701.  
  1702.    texObj = _mesa_lookup_texture_err(ctx, texture,
  1703.                                      "glGetTextureLevelParameterfv");
  1704.    if (!texObj)
  1705.       return;
  1706.  
  1707.    get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
  1708.                              pname, &iparam, true);
  1709.  
  1710.    *params = (GLfloat) iparam;
  1711. }
  1712.  
  1713. void GLAPIENTRY
  1714. _mesa_GetTextureLevelParameteriv(GLuint texture, GLint level,
  1715.                                  GLenum pname, GLint *params)
  1716. {
  1717.    struct gl_texture_object *texObj;
  1718.    GET_CURRENT_CONTEXT(ctx);
  1719.  
  1720.    if (!ctx->Extensions.ARB_direct_state_access) {
  1721.       _mesa_error(ctx, GL_INVALID_OPERATION,
  1722.                   "glGetTextureLevelParameteriv(GL_ARB_direct_state_access "
  1723.                   "is not supported)");
  1724.       return;
  1725.    }
  1726.  
  1727.    texObj = _mesa_lookup_texture_err(ctx, texture,
  1728.                                      "glGetTextureLevelParameteriv");
  1729.    if (!texObj)
  1730.       return;
  1731.  
  1732.    get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
  1733.                              pname, params, true);
  1734. }
  1735.  
  1736. /**
  1737.  * This isn't exposed to the rest of the driver because it is a part of the
  1738.  * OpenGL API that is rarely used.
  1739.  */
  1740. static void
  1741. get_tex_parameterfv(struct gl_context *ctx,
  1742.                     struct gl_texture_object *obj,
  1743.                     GLenum pname, GLfloat *params, bool dsa)
  1744. {
  1745.    _mesa_lock_context_textures(ctx);
  1746.    switch (pname) {
  1747.       case GL_TEXTURE_MAG_FILTER:
  1748.          *params = ENUM_TO_FLOAT(obj->Sampler.MagFilter);
  1749.          break;
  1750.       case GL_TEXTURE_MIN_FILTER:
  1751.          *params = ENUM_TO_FLOAT(obj->Sampler.MinFilter);
  1752.          break;
  1753.       case GL_TEXTURE_WRAP_S:
  1754.          *params = ENUM_TO_FLOAT(obj->Sampler.WrapS);
  1755.          break;
  1756.       case GL_TEXTURE_WRAP_T:
  1757.          *params = ENUM_TO_FLOAT(obj->Sampler.WrapT);
  1758.          break;
  1759.       case GL_TEXTURE_WRAP_R:
  1760.          *params = ENUM_TO_FLOAT(obj->Sampler.WrapR);
  1761.          break;
  1762.       case GL_TEXTURE_BORDER_COLOR:
  1763.          if (!_mesa_is_desktop_gl(ctx))
  1764.             goto invalid_pname;
  1765.  
  1766.          if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
  1767.             _mesa_update_state_locked(ctx);
  1768.          if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer)) {
  1769.             params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
  1770.             params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
  1771.             params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
  1772.             params[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
  1773.          }
  1774.          else {
  1775.             params[0] = obj->Sampler.BorderColor.f[0];
  1776.             params[1] = obj->Sampler.BorderColor.f[1];
  1777.             params[2] = obj->Sampler.BorderColor.f[2];
  1778.             params[3] = obj->Sampler.BorderColor.f[3];
  1779.          }
  1780.          break;
  1781.       case GL_TEXTURE_RESIDENT:
  1782.          if (ctx->API != API_OPENGL_COMPAT)
  1783.             goto invalid_pname;
  1784.  
  1785.          *params = 1.0F;
  1786.          break;
  1787.       case GL_TEXTURE_PRIORITY:
  1788.          if (ctx->API != API_OPENGL_COMPAT)
  1789.             goto invalid_pname;
  1790.  
  1791.          *params = obj->Priority;
  1792.          break;
  1793.       case GL_TEXTURE_MIN_LOD:
  1794.          if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
  1795.             goto invalid_pname;
  1796.  
  1797.          *params = obj->Sampler.MinLod;
  1798.          break;
  1799.       case GL_TEXTURE_MAX_LOD:
  1800.          if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
  1801.             goto invalid_pname;
  1802.  
  1803.          *params = obj->Sampler.MaxLod;
  1804.          break;
  1805.       case GL_TEXTURE_BASE_LEVEL:
  1806.          if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
  1807.             goto invalid_pname;
  1808.  
  1809.          *params = (GLfloat) obj->BaseLevel;
  1810.          break;
  1811.       case GL_TEXTURE_MAX_LEVEL:
  1812.          *params = (GLfloat) obj->MaxLevel;
  1813.          break;
  1814.       case GL_TEXTURE_MAX_ANISOTROPY_EXT:
  1815.          if (!ctx->Extensions.EXT_texture_filter_anisotropic)
  1816.             goto invalid_pname;
  1817.          *params = obj->Sampler.MaxAnisotropy;
  1818.          break;
  1819.       case GL_GENERATE_MIPMAP_SGIS:
  1820.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  1821.             goto invalid_pname;
  1822.  
  1823.          *params = (GLfloat) obj->GenerateMipmap;
  1824.          break;
  1825.       case GL_TEXTURE_COMPARE_MODE_ARB:
  1826.          if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
  1827.              && !_mesa_is_gles3(ctx))
  1828.             goto invalid_pname;
  1829.          *params = (GLfloat) obj->Sampler.CompareMode;
  1830.          break;
  1831.       case GL_TEXTURE_COMPARE_FUNC_ARB:
  1832.          if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
  1833.              && !_mesa_is_gles3(ctx))
  1834.             goto invalid_pname;
  1835.          *params = (GLfloat) obj->Sampler.CompareFunc;
  1836.          break;
  1837.       case GL_DEPTH_TEXTURE_MODE_ARB:
  1838.          /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
  1839.           * never existed in OpenGL ES.
  1840.           */
  1841.          if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
  1842.             goto invalid_pname;
  1843.          *params = (GLfloat) obj->DepthMode;
  1844.          break;
  1845.       case GL_DEPTH_STENCIL_TEXTURE_MODE:
  1846.          if (!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_stencil_texturing)
  1847.             goto invalid_pname;
  1848.          *params = (GLfloat)
  1849.             (obj->StencilSampling ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT);
  1850.          break;
  1851.       case GL_TEXTURE_LOD_BIAS:
  1852.          if (_mesa_is_gles(ctx))
  1853.             goto invalid_pname;
  1854.  
  1855.          *params = obj->Sampler.LodBias;
  1856.          break;
  1857.       case GL_TEXTURE_CROP_RECT_OES:
  1858.          if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
  1859.             goto invalid_pname;
  1860.  
  1861.          params[0] = (GLfloat) obj->CropRect[0];
  1862.          params[1] = (GLfloat) obj->CropRect[1];
  1863.          params[2] = (GLfloat) obj->CropRect[2];
  1864.          params[3] = (GLfloat) obj->CropRect[3];
  1865.          break;
  1866.  
  1867.       case GL_TEXTURE_SWIZZLE_R_EXT:
  1868.       case GL_TEXTURE_SWIZZLE_G_EXT:
  1869.       case GL_TEXTURE_SWIZZLE_B_EXT:
  1870.       case GL_TEXTURE_SWIZZLE_A_EXT:
  1871.          if ((!_mesa_is_desktop_gl(ctx)
  1872.               || !ctx->Extensions.EXT_texture_swizzle)
  1873.              && !_mesa_is_gles3(ctx))
  1874.             goto invalid_pname;
  1875.          *params = (GLfloat) obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
  1876.          break;
  1877.  
  1878.       case GL_TEXTURE_SWIZZLE_RGBA_EXT:
  1879.          if ((!_mesa_is_desktop_gl(ctx)
  1880.               || !ctx->Extensions.EXT_texture_swizzle)
  1881.              && !_mesa_is_gles3(ctx)) {
  1882.             goto invalid_pname;
  1883.          }
  1884.          else {
  1885.             GLuint comp;
  1886.             for (comp = 0; comp < 4; comp++) {
  1887.                params[comp] = (GLfloat) obj->Swizzle[comp];
  1888.             }
  1889.          }
  1890.          break;
  1891.  
  1892.       case GL_TEXTURE_CUBE_MAP_SEAMLESS:
  1893.          if (!_mesa_is_desktop_gl(ctx)
  1894.              || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
  1895.             goto invalid_pname;
  1896.          *params = (GLfloat) obj->Sampler.CubeMapSeamless;
  1897.          break;
  1898.  
  1899.       case GL_TEXTURE_IMMUTABLE_FORMAT:
  1900.          *params = (GLfloat) obj->Immutable;
  1901.          break;
  1902.  
  1903.       case GL_TEXTURE_IMMUTABLE_LEVELS:
  1904.          if (_mesa_is_gles3(ctx) ||
  1905.              (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_view))
  1906.             *params = (GLfloat) obj->ImmutableLevels;
  1907.          else
  1908.             goto invalid_pname;
  1909.          break;
  1910.  
  1911.       case GL_TEXTURE_VIEW_MIN_LEVEL:
  1912.          if (!ctx->Extensions.ARB_texture_view)
  1913.             goto invalid_pname;
  1914.          *params = (GLfloat) obj->MinLevel;
  1915.          break;
  1916.  
  1917.       case GL_TEXTURE_VIEW_NUM_LEVELS:
  1918.          if (!ctx->Extensions.ARB_texture_view)
  1919.             goto invalid_pname;
  1920.          *params = (GLfloat) obj->NumLevels;
  1921.          break;
  1922.  
  1923.       case GL_TEXTURE_VIEW_MIN_LAYER:
  1924.          if (!ctx->Extensions.ARB_texture_view)
  1925.             goto invalid_pname;
  1926.          *params = (GLfloat) obj->MinLayer;
  1927.          break;
  1928.  
  1929.       case GL_TEXTURE_VIEW_NUM_LAYERS:
  1930.          if (!ctx->Extensions.ARB_texture_view)
  1931.             goto invalid_pname;
  1932.          *params = (GLfloat) obj->NumLayers;
  1933.          break;
  1934.  
  1935.       case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
  1936.          if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
  1937.             goto invalid_pname;
  1938.          *params = (GLfloat) obj->RequiredTextureImageUnits;
  1939.          break;
  1940.  
  1941.       case GL_TEXTURE_SRGB_DECODE_EXT:
  1942.          if (!ctx->Extensions.EXT_texture_sRGB_decode)
  1943.             goto invalid_pname;
  1944.          *params = (GLfloat) obj->Sampler.sRGBDecode;
  1945.          break;
  1946.  
  1947.       default:
  1948.          goto invalid_pname;
  1949.    }
  1950.  
  1951.    /* no error if we get here */
  1952.    _mesa_unlock_context_textures(ctx);
  1953.    return;
  1954.  
  1955. invalid_pname:
  1956.    _mesa_unlock_context_textures(ctx);
  1957.    _mesa_error(ctx, GL_INVALID_ENUM, "glGetTex%sParameterfv(pname=0x%x)",
  1958.                dsa ? "ture" : "", pname);
  1959. }
  1960.  
  1961.  
  1962. static void
  1963. get_tex_parameteriv(struct gl_context *ctx,
  1964.                     struct gl_texture_object *obj,
  1965.                     GLenum pname, GLint *params, bool dsa)
  1966. {
  1967.    _mesa_lock_texture(ctx, obj);
  1968.    switch (pname) {
  1969.       case GL_TEXTURE_MAG_FILTER:
  1970.          *params = (GLint) obj->Sampler.MagFilter;
  1971.          break;
  1972.       case GL_TEXTURE_MIN_FILTER:
  1973.          *params = (GLint) obj->Sampler.MinFilter;
  1974.          break;
  1975.       case GL_TEXTURE_WRAP_S:
  1976.          *params = (GLint) obj->Sampler.WrapS;
  1977.          break;
  1978.       case GL_TEXTURE_WRAP_T:
  1979.          *params = (GLint) obj->Sampler.WrapT;
  1980.          break;
  1981.       case GL_TEXTURE_WRAP_R:
  1982.          *params = (GLint) obj->Sampler.WrapR;
  1983.          break;
  1984.       case GL_TEXTURE_BORDER_COLOR:
  1985.          if (!_mesa_is_desktop_gl(ctx))
  1986.             goto invalid_pname;
  1987.  
  1988.          {
  1989.             GLfloat b[4];
  1990.             b[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
  1991.             b[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
  1992.             b[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
  1993.             b[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
  1994.             params[0] = FLOAT_TO_INT(b[0]);
  1995.             params[1] = FLOAT_TO_INT(b[1]);
  1996.             params[2] = FLOAT_TO_INT(b[2]);
  1997.             params[3] = FLOAT_TO_INT(b[3]);
  1998.          }
  1999.          break;
  2000.       case GL_TEXTURE_RESIDENT:
  2001.          if (ctx->API != API_OPENGL_COMPAT)
  2002.             goto invalid_pname;
  2003.  
  2004.          *params = 1;
  2005.          break;
  2006.       case GL_TEXTURE_PRIORITY:
  2007.          if (ctx->API != API_OPENGL_COMPAT)
  2008.             goto invalid_pname;
  2009.  
  2010.          *params = FLOAT_TO_INT(obj->Priority);
  2011.          break;
  2012.       case GL_TEXTURE_MIN_LOD:
  2013.          if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
  2014.             goto invalid_pname;
  2015.          /* GL spec 'Data Conversions' section specifies that floating-point
  2016.           * value in integer Get function is rounded to nearest integer
  2017.           */
  2018.          *params = IROUND(obj->Sampler.MinLod);
  2019.          break;
  2020.       case GL_TEXTURE_MAX_LOD:
  2021.          if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
  2022.             goto invalid_pname;
  2023.          /* GL spec 'Data Conversions' section specifies that floating-point
  2024.           * value in integer Get function is rounded to nearest integer
  2025.           */
  2026.          *params = IROUND(obj->Sampler.MaxLod);
  2027.          break;
  2028.       case GL_TEXTURE_BASE_LEVEL:
  2029.          if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
  2030.             goto invalid_pname;
  2031.  
  2032.          *params = obj->BaseLevel;
  2033.          break;
  2034.       case GL_TEXTURE_MAX_LEVEL:
  2035.          *params = obj->MaxLevel;
  2036.          break;
  2037.       case GL_TEXTURE_MAX_ANISOTROPY_EXT:
  2038.          if (!ctx->Extensions.EXT_texture_filter_anisotropic)
  2039.             goto invalid_pname;
  2040.          /* GL spec 'Data Conversions' section specifies that floating-point
  2041.           * value in integer Get function is rounded to nearest integer
  2042.           */
  2043.          *params = IROUND(obj->Sampler.MaxAnisotropy);
  2044.          break;
  2045.       case GL_GENERATE_MIPMAP_SGIS:
  2046.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  2047.             goto invalid_pname;
  2048.  
  2049.          *params = (GLint) obj->GenerateMipmap;
  2050.          break;
  2051.       case GL_TEXTURE_COMPARE_MODE_ARB:
  2052.          if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
  2053.              && !_mesa_is_gles3(ctx))
  2054.             goto invalid_pname;
  2055.          *params = (GLint) obj->Sampler.CompareMode;
  2056.          break;
  2057.       case GL_TEXTURE_COMPARE_FUNC_ARB:
  2058.          if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
  2059.              && !_mesa_is_gles3(ctx))
  2060.             goto invalid_pname;
  2061.          *params = (GLint) obj->Sampler.CompareFunc;
  2062.          break;
  2063.       case GL_DEPTH_TEXTURE_MODE_ARB:
  2064.          if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
  2065.             goto invalid_pname;
  2066.          *params = (GLint) obj->DepthMode;
  2067.          break;
  2068.       case GL_DEPTH_STENCIL_TEXTURE_MODE:
  2069.          if (!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_stencil_texturing)
  2070.             goto invalid_pname;
  2071.          *params = (GLint)
  2072.             (obj->StencilSampling ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT);
  2073.          break;
  2074.       case GL_TEXTURE_LOD_BIAS:
  2075.          if (_mesa_is_gles(ctx))
  2076.             goto invalid_pname;
  2077.  
  2078.          /* GL spec 'Data Conversions' section specifies that floating-point
  2079.           * value in integer Get function is rounded to nearest integer
  2080.           */
  2081.          *params = IROUND(obj->Sampler.LodBias);
  2082.          break;
  2083.       case GL_TEXTURE_CROP_RECT_OES:
  2084.          if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
  2085.             goto invalid_pname;
  2086.  
  2087.          params[0] = obj->CropRect[0];
  2088.          params[1] = obj->CropRect[1];
  2089.          params[2] = obj->CropRect[2];
  2090.          params[3] = obj->CropRect[3];
  2091.          break;
  2092.       case GL_TEXTURE_SWIZZLE_R_EXT:
  2093.       case GL_TEXTURE_SWIZZLE_G_EXT:
  2094.       case GL_TEXTURE_SWIZZLE_B_EXT:
  2095.       case GL_TEXTURE_SWIZZLE_A_EXT:
  2096.          if ((!_mesa_is_desktop_gl(ctx)
  2097.               || !ctx->Extensions.EXT_texture_swizzle)
  2098.              && !_mesa_is_gles3(ctx))
  2099.             goto invalid_pname;
  2100.          *params = obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
  2101.          break;
  2102.  
  2103.       case GL_TEXTURE_SWIZZLE_RGBA_EXT:
  2104.          if ((!_mesa_is_desktop_gl(ctx)
  2105.               || !ctx->Extensions.EXT_texture_swizzle)
  2106.              && !_mesa_is_gles3(ctx))
  2107.             goto invalid_pname;
  2108.          COPY_4V(params, obj->Swizzle);
  2109.          break;
  2110.  
  2111.       case GL_TEXTURE_CUBE_MAP_SEAMLESS:
  2112.          if (!_mesa_is_desktop_gl(ctx)
  2113.              || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
  2114.             goto invalid_pname;
  2115.          *params = (GLint) obj->Sampler.CubeMapSeamless;
  2116.          break;
  2117.  
  2118.       case GL_TEXTURE_IMMUTABLE_FORMAT:
  2119.          *params = (GLint) obj->Immutable;
  2120.          break;
  2121.  
  2122.       case GL_TEXTURE_IMMUTABLE_LEVELS:
  2123.          if (_mesa_is_gles3(ctx) ||
  2124.              (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_view))
  2125.             *params = obj->ImmutableLevels;
  2126.          else
  2127.             goto invalid_pname;
  2128.          break;
  2129.  
  2130.       case GL_TEXTURE_VIEW_MIN_LEVEL:
  2131.          if (!ctx->Extensions.ARB_texture_view)
  2132.             goto invalid_pname;
  2133.          *params = (GLint) obj->MinLevel;
  2134.          break;
  2135.  
  2136.       case GL_TEXTURE_VIEW_NUM_LEVELS:
  2137.          if (!ctx->Extensions.ARB_texture_view)
  2138.             goto invalid_pname;
  2139.          *params = (GLint) obj->NumLevels;
  2140.          break;
  2141.  
  2142.       case GL_TEXTURE_VIEW_MIN_LAYER:
  2143.          if (!ctx->Extensions.ARB_texture_view)
  2144.             goto invalid_pname;
  2145.          *params = (GLint) obj->MinLayer;
  2146.          break;
  2147.  
  2148.       case GL_TEXTURE_VIEW_NUM_LAYERS:
  2149.          if (!ctx->Extensions.ARB_texture_view)
  2150.             goto invalid_pname;
  2151.          *params = (GLint) obj->NumLayers;
  2152.          break;
  2153.  
  2154.       case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
  2155.          if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
  2156.             goto invalid_pname;
  2157.          *params = obj->RequiredTextureImageUnits;
  2158.          break;
  2159.  
  2160.       case GL_TEXTURE_SRGB_DECODE_EXT:
  2161.          if (!ctx->Extensions.EXT_texture_sRGB_decode)
  2162.             goto invalid_pname;
  2163.          *params = obj->Sampler.sRGBDecode;
  2164.          break;
  2165.  
  2166.       case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
  2167.          if (!ctx->Extensions.ARB_shader_image_load_store)
  2168.             goto invalid_pname;
  2169.          *params = obj->ImageFormatCompatibilityType;
  2170.          break;
  2171.  
  2172.       default:
  2173.          goto invalid_pname;
  2174.    }
  2175.  
  2176.    /* no error if we get here */
  2177.    _mesa_unlock_texture(ctx, obj);
  2178.    return;
  2179.  
  2180. invalid_pname:
  2181.    _mesa_unlock_texture(ctx, obj);
  2182.    _mesa_error(ctx, GL_INVALID_ENUM, "glGetTex%sParameteriv(pname=0x%x)",
  2183.                dsa ? "ture" : "", pname);
  2184. }
  2185.  
  2186. static void
  2187. get_tex_parameterIiv(struct gl_context *ctx,
  2188.                      struct gl_texture_object *obj,
  2189.                      GLenum pname, GLint *params, bool dsa)
  2190. {
  2191.    switch (pname) {
  2192.    case GL_TEXTURE_BORDER_COLOR:
  2193.       COPY_4V(params, obj->Sampler.BorderColor.i);
  2194.       break;
  2195.    default:
  2196.       get_tex_parameteriv(ctx, obj, pname, params, dsa);
  2197.    }
  2198. }
  2199.  
  2200. static void
  2201. get_tex_parameterIuiv(struct gl_context *ctx,
  2202.                       struct gl_texture_object *obj,
  2203.                       GLenum pname, GLuint *params, bool dsa)
  2204. {
  2205.    switch (pname) {
  2206.    case GL_TEXTURE_BORDER_COLOR:
  2207.       COPY_4V(params, obj->Sampler.BorderColor.i);
  2208.       break;
  2209.    default:
  2210.       {
  2211.          GLint ip[4];
  2212.          get_tex_parameteriv(ctx, obj, pname, ip, dsa);
  2213.          params[0] = ip[0];
  2214.          if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT ||
  2215.              pname == GL_TEXTURE_CROP_RECT_OES) {
  2216.             params[1] = ip[1];
  2217.             params[2] = ip[2];
  2218.             params[3] = ip[3];
  2219.          }
  2220.       }
  2221.    }
  2222. }
  2223.  
  2224. void GLAPIENTRY
  2225. _mesa_GetTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
  2226. {
  2227.    struct gl_texture_object *obj;
  2228.    GET_CURRENT_CONTEXT(ctx);
  2229.  
  2230.    obj = get_texobj_by_target(ctx, target, GL_TRUE);
  2231.    if (!obj)
  2232.       return;
  2233.  
  2234.    get_tex_parameterfv(ctx, obj, pname, params, false);
  2235. }
  2236.  
  2237. void GLAPIENTRY
  2238. _mesa_GetTexParameteriv(GLenum target, GLenum pname, GLint *params)
  2239. {
  2240.    struct gl_texture_object *obj;
  2241.    GET_CURRENT_CONTEXT(ctx);
  2242.  
  2243.    obj = get_texobj_by_target(ctx, target, GL_TRUE);
  2244.    if (!obj)
  2245.       return;
  2246.  
  2247.    get_tex_parameteriv(ctx, obj, pname, params, false);
  2248. }
  2249.  
  2250. /** New in GL 3.0 */
  2251. void GLAPIENTRY
  2252. _mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
  2253. {
  2254.    struct gl_texture_object *texObj;
  2255.    GET_CURRENT_CONTEXT(ctx);
  2256.  
  2257.    texObj = get_texobj_by_target(ctx, target, GL_TRUE);
  2258.    if (!texObj)
  2259.       return;
  2260.  
  2261.    get_tex_parameterIiv(ctx, texObj, pname, params, false);
  2262. }
  2263.  
  2264.  
  2265. /** New in GL 3.0 */
  2266. void GLAPIENTRY
  2267. _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
  2268. {
  2269.    struct gl_texture_object *texObj;
  2270.    GET_CURRENT_CONTEXT(ctx);
  2271.  
  2272.    texObj = get_texobj_by_target(ctx, target, GL_TRUE);
  2273.    if (!texObj)
  2274.       return;
  2275.  
  2276.    get_tex_parameterIuiv(ctx, texObj, pname, params, false);
  2277. }
  2278.  
  2279.  
  2280. void GLAPIENTRY
  2281. _mesa_GetTextureParameterfv(GLuint texture, GLenum pname, GLfloat *params)
  2282. {
  2283.    struct gl_texture_object *obj;
  2284.    GET_CURRENT_CONTEXT(ctx);
  2285.  
  2286.    if (!ctx->Extensions.ARB_direct_state_access) {
  2287.       _mesa_error(ctx, GL_INVALID_OPERATION,
  2288.                   "glGetTextureParameterfv(GL_ARB_direct_state_access "
  2289.                   "is not supported)");
  2290.       return;
  2291.    }
  2292.  
  2293.    obj = get_texobj_by_name(ctx, texture, GL_TRUE);
  2294.    if (!obj) {
  2295.       /* User passed a non-generated name. */
  2296.       _mesa_error(ctx, GL_INVALID_OPERATION,
  2297.                   "glGetTextureParameterfv(texture)");
  2298.       return;
  2299.    }
  2300.  
  2301.    get_tex_parameterfv(ctx, obj, pname, params, true);
  2302. }
  2303.  
  2304. void GLAPIENTRY
  2305. _mesa_GetTextureParameteriv(GLuint texture, GLenum pname, GLint *params)
  2306. {
  2307.    struct gl_texture_object *obj;
  2308.    GET_CURRENT_CONTEXT(ctx);
  2309.  
  2310.    if (!ctx->Extensions.ARB_direct_state_access) {
  2311.       _mesa_error(ctx, GL_INVALID_OPERATION,
  2312.                   "glGetTextureParameteriv(GL_ARB_direct_state_access "
  2313.                   "is not supported)");
  2314.       return;
  2315.    }
  2316.  
  2317.    obj = get_texobj_by_name(ctx, texture, GL_TRUE);
  2318.    if (!obj) {
  2319.       /* User passed a non-generated name. */
  2320.       _mesa_error(ctx, GL_INVALID_OPERATION,
  2321.                   "glGetTextureParameteriv(texture)");
  2322.       return;
  2323.    }
  2324.  
  2325.    get_tex_parameteriv(ctx, obj, pname, params, true);
  2326. }
  2327.  
  2328. void GLAPIENTRY
  2329. _mesa_GetTextureParameterIiv(GLuint texture, GLenum pname, GLint *params)
  2330. {
  2331.    struct gl_texture_object *texObj;
  2332.    GET_CURRENT_CONTEXT(ctx);
  2333.  
  2334.    if (!ctx->Extensions.ARB_direct_state_access) {
  2335.       _mesa_error(ctx, GL_INVALID_OPERATION,
  2336.                   "glGetTextureParameterIiv(GL_ARB_direct_state_access "
  2337.                   "is not supported)");
  2338.       return;
  2339.    }
  2340.  
  2341.    texObj = get_texobj_by_name(ctx, texture, GL_TRUE);
  2342.    if (!texObj) {
  2343.       /* User passed a non-generated name. */
  2344.       _mesa_error(ctx, GL_INVALID_OPERATION,
  2345.                   "glGetTextureParameterIiv(texture)");
  2346.       return;
  2347.    }
  2348.  
  2349.    get_tex_parameterIiv(ctx, texObj, pname, params, true);
  2350. }
  2351.  
  2352.  
  2353. void GLAPIENTRY
  2354. _mesa_GetTextureParameterIuiv(GLuint texture, GLenum pname, GLuint *params)
  2355. {
  2356.    struct gl_texture_object *texObj;
  2357.    GET_CURRENT_CONTEXT(ctx);
  2358.  
  2359.    if (!ctx->Extensions.ARB_direct_state_access) {
  2360.       _mesa_error(ctx, GL_INVALID_OPERATION,
  2361.                   "glGetTextureParameterIuiv(GL_ARB_direct_state_access "
  2362.                   "is not supported)");
  2363.       return;
  2364.    }
  2365.  
  2366.    texObj = get_texobj_by_name(ctx, texture, GL_TRUE);
  2367.    if (!texObj) {
  2368.       /* User passed a non-generated name. */
  2369.       _mesa_error(ctx, GL_INVALID_OPERATION,
  2370.                   "glGetTextureParameterIuiv(texture)");
  2371.       return;
  2372.    }
  2373.  
  2374.    get_tex_parameterIuiv(ctx, texObj, pname, params, true);
  2375. }
  2376.