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) 1999-2013  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. /*
  28.  * glGenerateMipmap function
  29.  */
  30.  
  31. #include "context.h"
  32. #include "enums.h"
  33. #include "genmipmap.h"
  34. #include "glformats.h"
  35. #include "macros.h"
  36. #include "mtypes.h"
  37. #include "teximage.h"
  38. #include "texobj.h"
  39. #include "hash.h"
  40.  
  41. /**
  42.  * Implements glGenerateMipmap and glGenerateTextureMipmap.
  43.  * Generates all the mipmap levels below the base level.
  44.  */
  45. void
  46. _mesa_generate_texture_mipmap(struct gl_context *ctx,
  47.                               struct gl_texture_object *texObj, GLenum target,
  48.                               bool dsa)
  49. {
  50.    struct gl_texture_image *srcImage;
  51.    GLboolean error;
  52.    const char *suffix = dsa ? "Texture" : "";
  53.  
  54.    FLUSH_VERTICES(ctx, 0);
  55.  
  56.    switch (target) {
  57.    case GL_TEXTURE_1D:
  58.       error = _mesa_is_gles(ctx);
  59.       break;
  60.    case GL_TEXTURE_2D:
  61.       error = GL_FALSE;
  62.       break;
  63.    case GL_TEXTURE_3D:
  64.       error = ctx->API == API_OPENGLES;
  65.       break;
  66.    case GL_TEXTURE_CUBE_MAP:
  67.       error = !ctx->Extensions.ARB_texture_cube_map;
  68.       break;
  69.    case GL_TEXTURE_1D_ARRAY:
  70.       error = _mesa_is_gles(ctx) || !ctx->Extensions.EXT_texture_array;
  71.       break;
  72.    case GL_TEXTURE_2D_ARRAY:
  73.       error = (_mesa_is_gles(ctx) && ctx->Version < 30)
  74.          || !ctx->Extensions.EXT_texture_array;
  75.       break;
  76.    case GL_TEXTURE_CUBE_MAP_ARRAY:
  77.       error = _mesa_is_gles(ctx) ||
  78.               !ctx->Extensions.ARB_texture_cube_map_array;
  79.       break;
  80.    default:
  81.       error = GL_TRUE;
  82.    }
  83.  
  84.    if (error) {
  85.       _mesa_error(ctx, GL_INVALID_ENUM, "glGenerate%sMipmap(target=%s)",
  86.                   suffix, _mesa_lookup_enum_by_nr(target));
  87.       return;
  88.    }
  89.  
  90.    if (texObj->BaseLevel >= texObj->MaxLevel) {
  91.       /* nothing to do */
  92.       return;
  93.    }
  94.  
  95.    if (texObj->Target == GL_TEXTURE_CUBE_MAP &&
  96.        !_mesa_cube_complete(texObj)) {
  97.       _mesa_error(ctx, GL_INVALID_OPERATION,
  98.                   "glGenerate%sMipmap(incomplete cube map)", suffix);
  99.       return;
  100.    }
  101.  
  102.    _mesa_lock_texture(ctx, texObj);
  103.  
  104.    srcImage = _mesa_select_tex_image(texObj, target, texObj->BaseLevel);
  105.    if (!srcImage) {
  106.       _mesa_unlock_texture(ctx, texObj);
  107.       _mesa_error(ctx, GL_INVALID_OPERATION,
  108.                   "glGenerate%sMipmap(zero size base image)", suffix);
  109.       return;
  110.    }
  111.  
  112.    if (_mesa_is_enum_format_integer(srcImage->InternalFormat) ||
  113.        _mesa_is_depthstencil_format(srcImage->InternalFormat) ||
  114.        _mesa_is_stencil_format(srcImage->InternalFormat)) {
  115.       _mesa_unlock_texture(ctx, texObj);
  116.       _mesa_error(ctx, GL_INVALID_OPERATION,
  117.                   "glGenerate%sMipmap(invalid internal format)", suffix);
  118.       return;
  119.    }
  120.  
  121.    if (target == GL_TEXTURE_CUBE_MAP) {
  122.       GLuint face;
  123.       for (face = 0; face < 6; face++) {
  124.          ctx->Driver.GenerateMipmap(ctx,
  125.                       GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + face, texObj);
  126.       }
  127.    }
  128.    else {
  129.       ctx->Driver.GenerateMipmap(ctx, target, texObj);
  130.    }
  131.    _mesa_unlock_texture(ctx, texObj);
  132. }
  133.  
  134. /**
  135.  * Generate all the mipmap levels below the base level.
  136.  * Note: this GL function would be more useful if one could specify a
  137.  * cube face, a set of array slices, etc.
  138.  */
  139. void GLAPIENTRY
  140. _mesa_GenerateMipmap(GLenum target)
  141. {
  142.    struct gl_texture_object *texObj;
  143.    GET_CURRENT_CONTEXT(ctx);
  144.  
  145.    texObj = _mesa_get_current_tex_object(ctx, target);
  146.    if (!texObj)
  147.       return;
  148.  
  149.    _mesa_generate_texture_mipmap(ctx, texObj, target, false);
  150. }
  151.  
  152. /**
  153.  * Generate all the mipmap levels below the base level.
  154.  */
  155. void GLAPIENTRY
  156. _mesa_GenerateTextureMipmap(GLuint texture)
  157. {
  158.    struct gl_texture_object *texObj;
  159.    GET_CURRENT_CONTEXT(ctx);
  160.  
  161.    if (!ctx->Extensions.ARB_direct_state_access) {
  162.       _mesa_error(ctx, GL_INVALID_OPERATION,
  163.                   "glGenerateTextureMipmap(GL_ARB_direct_state_access "
  164.                   "is not supported)");
  165.       return;
  166.    }
  167.  
  168.    texObj = _mesa_lookup_texture_err(ctx, texture, "glGenerateTextureMipmap");
  169.    if (!texObj)
  170.       return;
  171.  
  172.    _mesa_generate_texture_mipmap(ctx, texObj, texObj->Target, true);
  173. }
  174.