mesa: remove pointless assignments in init_teximage_fields_ms()
[mesa.git] / src / mesa / main / formatquery.c
index 32f8cf429530a2354a2df95dd83eda06f20da367..07fb2f2330fbe87f8fc43a559638bfea1117afc2 100644 (file)
@@ -387,13 +387,13 @@ _is_target_supported(struct gl_context *ctx, GLenum target)
     *     "if a particular type of <target> is not supported by the
     *     implementation the "unsupported" answer should be given.
     *     This is not an error."
+    *
+    * For OpenGL ES, queries can only be used with GL_RENDERBUFFER or MS.
     */
    switch(target){
+   case GL_TEXTURE_1D:
    case GL_TEXTURE_2D:
    case GL_TEXTURE_3D:
-      break;
-
-   case GL_TEXTURE_1D:
       if (!_mesa_is_desktop_gl(ctx))
          return false;
       break;
@@ -404,12 +404,12 @@ _is_target_supported(struct gl_context *ctx, GLenum target)
       break;
 
    case GL_TEXTURE_2D_ARRAY:
-      if (!(_mesa_has_EXT_texture_array(ctx) || _mesa_is_gles3(ctx)))
+      if (!_mesa_has_EXT_texture_array(ctx))
          return false;
       break;
 
    case GL_TEXTURE_CUBE_MAP:
-      if (!_mesa_has_ARB_texture_cube_map(ctx))
+      if (ctx->API != API_OPENGL_CORE && !_mesa_has_ARB_texture_cube_map(ctx))
          return false;
       break;
 
@@ -419,7 +419,7 @@ _is_target_supported(struct gl_context *ctx, GLenum target)
       break;
 
    case GL_TEXTURE_RECTANGLE:
-      if (!_mesa_has_NV_texture_rectangle(ctx))
+      if (!_mesa_has_ARB_texture_rectangle(ctx))
           return false;
       break;
 
@@ -559,7 +559,7 @@ _is_internalformat_supported(struct gl_context *ctx, GLenum target,
     */
    GLint buffer[1];
 
-   /* At this point a internalformat is valid if it is valid as a texture or
+   /* At this point an internalformat is valid if it is valid as a texture or
     * as a renderbuffer format. The checks are different because those methods
     * return different values when passing non supported internalformats */
    if (_mesa_base_tex_format(ctx, internalformat) < 0 &&
@@ -645,7 +645,9 @@ _mesa_query_internal_format_default(struct gl_context *ctx, GLenum target,
       break;
    }
 
-   case GL_READ_PIXELS_TYPE: {
+   case GL_READ_PIXELS_TYPE:
+   case GL_TEXTURE_IMAGE_TYPE:
+   case GL_GET_TEXTURE_IMAGE_TYPE: {
       GLenum base_format = _mesa_base_tex_format(ctx, internalFormat);
       if (base_format > 0)
          params[0] = _mesa_generic_type_for_internal_format(internalFormat);
@@ -654,6 +656,21 @@ _mesa_query_internal_format_default(struct gl_context *ctx, GLenum target,
       break;
    }
 
+   case GL_TEXTURE_IMAGE_FORMAT:
+   case GL_GET_TEXTURE_IMAGE_FORMAT: {
+      GLenum format = GL_NONE;
+      GLenum base_format = _mesa_base_tex_format(ctx, internalFormat);
+      if (base_format > 0) {
+         if (_mesa_is_enum_format_integer(internalFormat))
+           format = _mesa_base_format_to_integer_format(base_format);
+         else
+           format = base_format;
+      }
+
+      params[0] = format;
+      break;
+   }
+
    case GL_MANUAL_GENERATE_MIPMAP:
    case GL_AUTO_GENERATE_MIPMAP:
    case GL_SRGB_READ:
@@ -701,8 +718,8 @@ _mesa_query_internal_format_default(struct gl_context *ctx, GLenum target,
  * arb_internalformat_query2 spec.
  */
 static GLenum
-equivalentSizePname(GLenum target,
-                    GLenum pname)
+_equivalent_size_pname(GLenum target,
+                       GLenum pname)
 {
    switch (target) {
    case GL_TEXTURE_1D:
@@ -746,7 +763,7 @@ equivalentSizePname(GLenum target,
  * per-se, so we can't just call _mesa_get_texture_dimension directly.
  */
 static GLint
-get_target_dimensions(GLenum target)
+_get_target_dimensions(GLenum target)
 {
    switch(target) {
    case GL_TEXTURE_BUFFER:
@@ -771,7 +788,7 @@ get_target_dimensions(GLenum target)
  *  <skip>."
  */
 static GLint
-get_min_dimensions(GLenum pname)
+_get_min_dimensions(GLenum pname)
 {
    switch(pname) {
    case GL_MAX_WIDTH:
@@ -790,7 +807,7 @@ get_min_dimensions(GLenum pname)
  * dimensions.
  */
 static bool
-is_multisample_target(GLenum target)
+_is_multisample_target(GLenum target)
 {
    switch(target) {
    case GL_TEXTURE_2D_MULTISAMPLE:
@@ -860,6 +877,9 @@ _mesa_GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname,
        *     "Since multisampling is not supported for signed and unsigned
        *     integer internal formats, the value of NUM_SAMPLE_COUNTS will be
        *     zero for such formats.
+       *
+       * Since OpenGL ES 3.1 adds support for multisampled integer formats, we
+       * have to check the version for 30 exactly.
        */
       if (pname == GL_NUM_SAMPLE_COUNTS && ctx->API == API_OPENGLES2 &&
           ctx->Version == 30 && _mesa_is_enum_format_integer(internalformat)) {
@@ -885,7 +905,10 @@ _mesa_GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname,
        *     format for representing resources of the specified <internalformat> is
        *     returned in <params>.
        *
-       * Therefore, we let the driver answer.
+       * Therefore, we let the driver answer. Note that if we reach this
+       * point, it means that the internalformat is supported, so the driver
+       * is called just to try to get a preferred format. If not supported,
+       * GL_NONE was already returned and the driver is not called.
        */
       ctx->Driver.QueryInternalFormat(ctx, target, internalformat, pname,
                                       buffer);
@@ -945,7 +968,8 @@ _mesa_GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname,
 
       switch (pname) {
       case GL_INTERNALFORMAT_DEPTH_SIZE:
-         if (!_mesa_has_ARB_depth_texture(ctx) &&
+         if (ctx->API != API_OPENGL_CORE &&
+             !_mesa_has_ARB_depth_texture(ctx) &&
              target != GL_RENDERBUFFER &&
              target != GL_TEXTURE_BUFFER)
             goto end;
@@ -992,12 +1016,12 @@ _mesa_GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname,
        * "If the resource does not have at least two dimensions, or if the
        * resource is unsupported, zero is returned."
        */
-      dimensions = get_target_dimensions(target);
-      min_dimensions = get_min_dimensions(pname);
+      dimensions = _get_target_dimensions(target);
+      min_dimensions = _get_min_dimensions(pname);
       if (dimensions < min_dimensions)
          goto end;
 
-      get_pname = equivalentSizePname(target, pname);
+      get_pname = _equivalent_size_pname(target, pname);
       if (get_pname == 0)
          goto end;
 
@@ -1031,7 +1055,7 @@ _mesa_GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname,
        * returned as MAX_HEIGHT or MAX_DEPTH */
       for (i = 0; i < 4; i++) {
          if (max_dimensions_pnames[i] == GL_SAMPLES &&
-             !is_multisample_target(target))
+             !_is_multisample_target(target))
             continue;
 
          _mesa_GetInternalformativ(target, internalformat,
@@ -1135,19 +1159,11 @@ _mesa_GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname,
       break;
 
    case GL_TEXTURE_IMAGE_FORMAT:
-      /* @TODO */
-      break;
-
-   case GL_TEXTURE_IMAGE_TYPE:
-      /* @TODO */
-      break;
-
    case GL_GET_TEXTURE_IMAGE_FORMAT:
-      /* @TODO */
-      break;
-
+   case GL_TEXTURE_IMAGE_TYPE:
    case GL_GET_TEXTURE_IMAGE_TYPE:
-      /* @TODO */
+      ctx->Driver.QueryInternalFormat(ctx, target, internalformat, pname,
+                                      buffer);
       break;
 
    case GL_MIPMAP:
@@ -1548,7 +1564,8 @@ _mesa_GetInternalformati64v(GLenum target, GLenum internalformat,
     * no pname can return a negative value, we fill params32 with negative
     * values as reference values, that can be used to know what copy-back to
     * params */
-   memset(params32, -1, 16);
+   for (i = 0; i < realSize; i++)
+      params32[i] = -1;
 
    /* For GL_MAX_COMBINED_DIMENSIONS we need to get back 2 32-bit integers,
     * and at the same time we only need 2. So for that pname, we call the