1af69d88dSmrg/* 2af69d88dSmrg * Mesa 3-D graphics library 3af69d88dSmrg * 4af69d88dSmrg * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 5af69d88dSmrg * Copyright (c) 2008-2009 VMware, Inc. 6af69d88dSmrg * Copyright (c) 2012 Intel Corporation 7af69d88dSmrg * 8af69d88dSmrg * Permission is hereby granted, free of charge, to any person obtaining a 9af69d88dSmrg * copy of this software and associated documentation files (the "Software"), 10af69d88dSmrg * to deal in the Software without restriction, including without limitation 11af69d88dSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12af69d88dSmrg * and/or sell copies of the Software, and to permit persons to whom the 13af69d88dSmrg * Software is furnished to do so, subject to the following conditions: 14af69d88dSmrg * 15af69d88dSmrg * The above copyright notice and this permission notice shall be included 16af69d88dSmrg * in all copies or substantial portions of the Software. 17af69d88dSmrg * 18af69d88dSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19af69d88dSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20af69d88dSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 22af69d88dSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 23af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24af69d88dSmrg * OTHER DEALINGS IN THE SOFTWARE. 25af69d88dSmrg */ 26af69d88dSmrg 27af69d88dSmrg 28af69d88dSmrg#include "context.h" 29af69d88dSmrg#include "glformats.h" 3001e04c3fSmrg#include "formats.h" 3101e04c3fSmrg#include "texcompress.h" 3201e04c3fSmrg#include "enums.h" 3301e04c3fSmrg 3401e04c3fSmrgenum { 3501e04c3fSmrg ZERO = 4, 3601e04c3fSmrg ONE = 5 3701e04c3fSmrg}; 3801e04c3fSmrg 3901e04c3fSmrgenum { 4001e04c3fSmrg IDX_LUMINANCE = 0, 4101e04c3fSmrg IDX_ALPHA, 4201e04c3fSmrg IDX_INTENSITY, 4301e04c3fSmrg IDX_LUMINANCE_ALPHA, 4401e04c3fSmrg IDX_RGB, 4501e04c3fSmrg IDX_RGBA, 4601e04c3fSmrg IDX_RED, 4701e04c3fSmrg IDX_GREEN, 4801e04c3fSmrg IDX_BLUE, 4901e04c3fSmrg IDX_BGR, 5001e04c3fSmrg IDX_BGRA, 5101e04c3fSmrg IDX_ABGR, 5201e04c3fSmrg IDX_RG, 5301e04c3fSmrg MAX_IDX 5401e04c3fSmrg}; 5501e04c3fSmrg 5601e04c3fSmrg#define MAP1(x) MAP4(x, ZERO, ZERO, ZERO) 5701e04c3fSmrg#define MAP2(x,y) MAP4(x, y, ZERO, ZERO) 5801e04c3fSmrg#define MAP3(x,y,z) MAP4(x, y, z, ZERO) 5901e04c3fSmrg#define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE } 6001e04c3fSmrg 6101e04c3fSmrgstatic const struct { 6201e04c3fSmrg GLubyte format_idx; 6301e04c3fSmrg GLubyte to_rgba[6]; 6401e04c3fSmrg GLubyte from_rgba[6]; 6501e04c3fSmrg} mappings[MAX_IDX] = 6601e04c3fSmrg{ 6701e04c3fSmrg { 6801e04c3fSmrg IDX_LUMINANCE, 6901e04c3fSmrg MAP4(0,0,0,ONE), 7001e04c3fSmrg MAP1(0) 7101e04c3fSmrg }, 7201e04c3fSmrg 7301e04c3fSmrg { 7401e04c3fSmrg IDX_ALPHA, 7501e04c3fSmrg MAP4(ZERO, ZERO, ZERO, 0), 7601e04c3fSmrg MAP1(3) 7701e04c3fSmrg }, 7801e04c3fSmrg 7901e04c3fSmrg { 8001e04c3fSmrg IDX_INTENSITY, 8101e04c3fSmrg MAP4(0, 0, 0, 0), 8201e04c3fSmrg MAP1(0), 8301e04c3fSmrg }, 8401e04c3fSmrg 8501e04c3fSmrg { 8601e04c3fSmrg IDX_LUMINANCE_ALPHA, 8701e04c3fSmrg MAP4(0,0,0,1), 8801e04c3fSmrg MAP2(0,3) 8901e04c3fSmrg }, 9001e04c3fSmrg 9101e04c3fSmrg { 9201e04c3fSmrg IDX_RGB, 9301e04c3fSmrg MAP4(0,1,2,ONE), 9401e04c3fSmrg MAP3(0,1,2) 9501e04c3fSmrg }, 9601e04c3fSmrg 9701e04c3fSmrg { 9801e04c3fSmrg IDX_RGBA, 9901e04c3fSmrg MAP4(0,1,2,3), 10001e04c3fSmrg MAP4(0,1,2,3), 10101e04c3fSmrg }, 10201e04c3fSmrg 10301e04c3fSmrg { 10401e04c3fSmrg IDX_RED, 10501e04c3fSmrg MAP4(0, ZERO, ZERO, ONE), 10601e04c3fSmrg MAP1(0), 10701e04c3fSmrg }, 10801e04c3fSmrg 10901e04c3fSmrg { 11001e04c3fSmrg IDX_GREEN, 11101e04c3fSmrg MAP4(ZERO, 0, ZERO, ONE), 11201e04c3fSmrg MAP1(1), 11301e04c3fSmrg }, 11401e04c3fSmrg 11501e04c3fSmrg { 11601e04c3fSmrg IDX_BLUE, 11701e04c3fSmrg MAP4(ZERO, ZERO, 0, ONE), 11801e04c3fSmrg MAP1(2), 11901e04c3fSmrg }, 12001e04c3fSmrg 12101e04c3fSmrg { 12201e04c3fSmrg IDX_BGR, 12301e04c3fSmrg MAP4(2,1,0,ONE), 12401e04c3fSmrg MAP3(2,1,0) 12501e04c3fSmrg }, 12601e04c3fSmrg 12701e04c3fSmrg { 12801e04c3fSmrg IDX_BGRA, 12901e04c3fSmrg MAP4(2,1,0,3), 13001e04c3fSmrg MAP4(2,1,0,3) 13101e04c3fSmrg }, 13201e04c3fSmrg 13301e04c3fSmrg { 13401e04c3fSmrg IDX_ABGR, 13501e04c3fSmrg MAP4(3,2,1,0), 13601e04c3fSmrg MAP4(3,2,1,0) 13701e04c3fSmrg }, 13801e04c3fSmrg 13901e04c3fSmrg { 14001e04c3fSmrg IDX_RG, 14101e04c3fSmrg MAP4(0, 1, ZERO, ONE), 14201e04c3fSmrg MAP2(0, 1) 14301e04c3fSmrg }, 14401e04c3fSmrg}; 14501e04c3fSmrg 14601e04c3fSmrg/** 14701e04c3fSmrg * Convert a GL image format enum to an IDX_* value (see above). 14801e04c3fSmrg */ 14901e04c3fSmrgstatic int 15001e04c3fSmrgget_map_idx(GLenum value) 15101e04c3fSmrg{ 15201e04c3fSmrg switch (value) { 15301e04c3fSmrg case GL_LUMINANCE: 15401e04c3fSmrg case GL_LUMINANCE_INTEGER_EXT: 15501e04c3fSmrg return IDX_LUMINANCE; 15601e04c3fSmrg case GL_ALPHA: 15701e04c3fSmrg case GL_ALPHA_INTEGER: 15801e04c3fSmrg return IDX_ALPHA; 15901e04c3fSmrg case GL_INTENSITY: 16001e04c3fSmrg return IDX_INTENSITY; 16101e04c3fSmrg case GL_LUMINANCE_ALPHA: 16201e04c3fSmrg case GL_LUMINANCE_ALPHA_INTEGER_EXT: 16301e04c3fSmrg return IDX_LUMINANCE_ALPHA; 16401e04c3fSmrg case GL_RGB: 16501e04c3fSmrg case GL_RGB_INTEGER: 16601e04c3fSmrg return IDX_RGB; 16701e04c3fSmrg case GL_RGBA: 16801e04c3fSmrg case GL_RGBA_INTEGER: 16901e04c3fSmrg return IDX_RGBA; 17001e04c3fSmrg case GL_RED: 17101e04c3fSmrg case GL_RED_INTEGER: 17201e04c3fSmrg return IDX_RED; 17301e04c3fSmrg case GL_GREEN: 17401e04c3fSmrg return IDX_GREEN; 17501e04c3fSmrg case GL_BLUE: 17601e04c3fSmrg return IDX_BLUE; 17701e04c3fSmrg case GL_BGR: 17801e04c3fSmrg case GL_BGR_INTEGER: 17901e04c3fSmrg return IDX_BGR; 18001e04c3fSmrg case GL_BGRA: 18101e04c3fSmrg case GL_BGRA_INTEGER: 18201e04c3fSmrg return IDX_BGRA; 18301e04c3fSmrg case GL_ABGR_EXT: 18401e04c3fSmrg return IDX_ABGR; 18501e04c3fSmrg case GL_RG: 18601e04c3fSmrg case GL_RG_INTEGER: 18701e04c3fSmrg return IDX_RG; 18801e04c3fSmrg default: 18901e04c3fSmrg _mesa_problem(NULL, "Unexpected inFormat %s", 19001e04c3fSmrg _mesa_enum_to_string(value)); 19101e04c3fSmrg return 0; 19201e04c3fSmrg } 19301e04c3fSmrg} 194af69d88dSmrg 19501e04c3fSmrg/** 19601e04c3fSmrg * When promoting texture formats (see below) we need to compute the 19701e04c3fSmrg * mapping of dest components back to source components. 19801e04c3fSmrg * This function does that. 19901e04c3fSmrg * \param inFormat the incoming format of the texture 20001e04c3fSmrg * \param outFormat the final texture format 20101e04c3fSmrg * \return map[6] a full 6-component map 20201e04c3fSmrg */ 20301e04c3fSmrgvoid 20401e04c3fSmrg_mesa_compute_component_mapping(GLenum inFormat, GLenum outFormat, GLubyte *map) 20501e04c3fSmrg{ 20601e04c3fSmrg const int inFmt = get_map_idx(inFormat); 20701e04c3fSmrg const int outFmt = get_map_idx(outFormat); 20801e04c3fSmrg const GLubyte *in2rgba = mappings[inFmt].to_rgba; 20901e04c3fSmrg const GLubyte *rgba2out = mappings[outFmt].from_rgba; 21001e04c3fSmrg int i; 21101e04c3fSmrg 21201e04c3fSmrg for (i = 0; i < 4; i++) 21301e04c3fSmrg map[i] = in2rgba[rgba2out[i]]; 21401e04c3fSmrg 21501e04c3fSmrg map[ZERO] = ZERO; 21601e04c3fSmrg map[ONE] = ONE; 21701e04c3fSmrg 21801e04c3fSmrg#if 0 21901e04c3fSmrg printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n", 22001e04c3fSmrg inFormat, _mesa_enum_to_string(inFormat), 22101e04c3fSmrg outFormat, _mesa_enum_to_string(outFormat), 22201e04c3fSmrg map[0], 22301e04c3fSmrg map[1], 22401e04c3fSmrg map[2], 22501e04c3fSmrg map[3], 22601e04c3fSmrg map[4], 22701e04c3fSmrg map[5]); 22801e04c3fSmrg#endif 22901e04c3fSmrg} 230af69d88dSmrg 231af69d88dSmrg/** 232af69d88dSmrg * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise. 233af69d88dSmrg */ 234af69d88dSmrgGLboolean 235af69d88dSmrg_mesa_type_is_packed(GLenum type) 236af69d88dSmrg{ 237af69d88dSmrg switch (type) { 238af69d88dSmrg case GL_UNSIGNED_BYTE_3_3_2: 239af69d88dSmrg case GL_UNSIGNED_BYTE_2_3_3_REV: 240af69d88dSmrg case MESA_UNSIGNED_BYTE_4_4: 241af69d88dSmrg case GL_UNSIGNED_SHORT_5_6_5: 242af69d88dSmrg case GL_UNSIGNED_SHORT_5_6_5_REV: 243af69d88dSmrg case GL_UNSIGNED_SHORT_4_4_4_4: 244af69d88dSmrg case GL_UNSIGNED_SHORT_4_4_4_4_REV: 245af69d88dSmrg case GL_UNSIGNED_SHORT_5_5_5_1: 246af69d88dSmrg case GL_UNSIGNED_SHORT_1_5_5_5_REV: 247af69d88dSmrg case GL_UNSIGNED_INT_8_8_8_8: 248af69d88dSmrg case GL_UNSIGNED_INT_8_8_8_8_REV: 249af69d88dSmrg case GL_UNSIGNED_INT_10_10_10_2: 250af69d88dSmrg case GL_UNSIGNED_INT_2_10_10_10_REV: 251af69d88dSmrg case GL_UNSIGNED_SHORT_8_8_MESA: 252af69d88dSmrg case GL_UNSIGNED_SHORT_8_8_REV_MESA: 253af69d88dSmrg case GL_UNSIGNED_INT_24_8_EXT: 254af69d88dSmrg case GL_UNSIGNED_INT_5_9_9_9_REV: 255af69d88dSmrg case GL_UNSIGNED_INT_10F_11F_11F_REV: 256af69d88dSmrg case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: 257af69d88dSmrg return GL_TRUE; 258af69d88dSmrg } 259af69d88dSmrg 260af69d88dSmrg return GL_FALSE; 261af69d88dSmrg} 262af69d88dSmrg 263af69d88dSmrg 264af69d88dSmrg/** 265af69d88dSmrg * Get the size of a GL data type. 266af69d88dSmrg * 267af69d88dSmrg * \param type GL data type. 268af69d88dSmrg * 269af69d88dSmrg * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1 270af69d88dSmrg * if an invalid type enum. 271af69d88dSmrg */ 272af69d88dSmrgGLint 273af69d88dSmrg_mesa_sizeof_type(GLenum type) 274af69d88dSmrg{ 275af69d88dSmrg switch (type) { 276af69d88dSmrg case GL_BITMAP: 277af69d88dSmrg return 0; 278af69d88dSmrg case GL_UNSIGNED_BYTE: 279af69d88dSmrg return sizeof(GLubyte); 280af69d88dSmrg case GL_BYTE: 281af69d88dSmrg return sizeof(GLbyte); 282af69d88dSmrg case GL_UNSIGNED_SHORT: 283af69d88dSmrg return sizeof(GLushort); 284af69d88dSmrg case GL_SHORT: 285af69d88dSmrg return sizeof(GLshort); 286af69d88dSmrg case GL_UNSIGNED_INT: 287af69d88dSmrg return sizeof(GLuint); 288af69d88dSmrg case GL_INT: 289af69d88dSmrg return sizeof(GLint); 290af69d88dSmrg case GL_FLOAT: 291af69d88dSmrg return sizeof(GLfloat); 292af69d88dSmrg case GL_DOUBLE: 293af69d88dSmrg return sizeof(GLdouble); 294af69d88dSmrg case GL_HALF_FLOAT_ARB: 29501e04c3fSmrg case GL_HALF_FLOAT_OES: 296af69d88dSmrg return sizeof(GLhalfARB); 297af69d88dSmrg case GL_FIXED: 298af69d88dSmrg return sizeof(GLfixed); 299af69d88dSmrg default: 300af69d88dSmrg return -1; 301af69d88dSmrg } 302af69d88dSmrg} 303af69d88dSmrg 304af69d88dSmrg 305af69d88dSmrg/** 306af69d88dSmrg * Same as _mesa_sizeof_type() but also accepting the packed pixel 307af69d88dSmrg * format data types. 308af69d88dSmrg */ 309af69d88dSmrgGLint 310af69d88dSmrg_mesa_sizeof_packed_type(GLenum type) 311af69d88dSmrg{ 312af69d88dSmrg switch (type) { 313af69d88dSmrg case GL_BITMAP: 314af69d88dSmrg return 0; 315af69d88dSmrg case GL_UNSIGNED_BYTE: 316af69d88dSmrg return sizeof(GLubyte); 317af69d88dSmrg case GL_BYTE: 318af69d88dSmrg return sizeof(GLbyte); 319af69d88dSmrg case GL_UNSIGNED_SHORT: 320af69d88dSmrg return sizeof(GLushort); 321af69d88dSmrg case GL_SHORT: 322af69d88dSmrg return sizeof(GLshort); 323af69d88dSmrg case GL_UNSIGNED_INT: 324af69d88dSmrg return sizeof(GLuint); 325af69d88dSmrg case GL_INT: 326af69d88dSmrg return sizeof(GLint); 327af69d88dSmrg case GL_HALF_FLOAT_ARB: 32801e04c3fSmrg case GL_HALF_FLOAT_OES: 329af69d88dSmrg return sizeof(GLhalfARB); 330af69d88dSmrg case GL_FLOAT: 331af69d88dSmrg return sizeof(GLfloat); 332af69d88dSmrg case GL_UNSIGNED_BYTE_3_3_2: 333af69d88dSmrg case GL_UNSIGNED_BYTE_2_3_3_REV: 334af69d88dSmrg case MESA_UNSIGNED_BYTE_4_4: 335af69d88dSmrg return sizeof(GLubyte); 336af69d88dSmrg case GL_UNSIGNED_SHORT_5_6_5: 337af69d88dSmrg case GL_UNSIGNED_SHORT_5_6_5_REV: 338af69d88dSmrg case GL_UNSIGNED_SHORT_4_4_4_4: 339af69d88dSmrg case GL_UNSIGNED_SHORT_4_4_4_4_REV: 340af69d88dSmrg case GL_UNSIGNED_SHORT_5_5_5_1: 341af69d88dSmrg case GL_UNSIGNED_SHORT_1_5_5_5_REV: 342af69d88dSmrg case GL_UNSIGNED_SHORT_8_8_MESA: 343af69d88dSmrg case GL_UNSIGNED_SHORT_8_8_REV_MESA: 344af69d88dSmrg return sizeof(GLushort); 345af69d88dSmrg case GL_UNSIGNED_INT_8_8_8_8: 346af69d88dSmrg case GL_UNSIGNED_INT_8_8_8_8_REV: 347af69d88dSmrg case GL_UNSIGNED_INT_10_10_10_2: 348af69d88dSmrg case GL_UNSIGNED_INT_2_10_10_10_REV: 349af69d88dSmrg case GL_UNSIGNED_INT_24_8_EXT: 350af69d88dSmrg case GL_UNSIGNED_INT_5_9_9_9_REV: 351af69d88dSmrg case GL_UNSIGNED_INT_10F_11F_11F_REV: 352af69d88dSmrg return sizeof(GLuint); 353af69d88dSmrg case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: 354af69d88dSmrg return 8; 355af69d88dSmrg default: 356af69d88dSmrg return -1; 357af69d88dSmrg } 358af69d88dSmrg} 359af69d88dSmrg 360af69d88dSmrg 361af69d88dSmrg/** 362af69d88dSmrg * Get the number of components in a pixel format. 363af69d88dSmrg * 364af69d88dSmrg * \param format pixel format. 365af69d88dSmrg * 366af69d88dSmrg * \return the number of components in the given format, or -1 if a bad format. 367af69d88dSmrg */ 368af69d88dSmrgGLint 369af69d88dSmrg_mesa_components_in_format(GLenum format) 370af69d88dSmrg{ 371af69d88dSmrg switch (format) { 372af69d88dSmrg case GL_COLOR_INDEX: 373af69d88dSmrg case GL_STENCIL_INDEX: 374af69d88dSmrg case GL_DEPTH_COMPONENT: 375af69d88dSmrg case GL_RED: 376af69d88dSmrg case GL_RED_INTEGER_EXT: 377af69d88dSmrg case GL_GREEN: 378af69d88dSmrg case GL_GREEN_INTEGER_EXT: 379af69d88dSmrg case GL_BLUE: 380af69d88dSmrg case GL_BLUE_INTEGER_EXT: 381af69d88dSmrg case GL_ALPHA: 382af69d88dSmrg case GL_ALPHA_INTEGER_EXT: 383af69d88dSmrg case GL_LUMINANCE: 384af69d88dSmrg case GL_LUMINANCE_INTEGER_EXT: 385af69d88dSmrg case GL_INTENSITY: 386af69d88dSmrg return 1; 387af69d88dSmrg 388af69d88dSmrg case GL_LUMINANCE_ALPHA: 389af69d88dSmrg case GL_LUMINANCE_ALPHA_INTEGER_EXT: 390af69d88dSmrg case GL_RG: 391af69d88dSmrg case GL_YCBCR_MESA: 392af69d88dSmrg case GL_DEPTH_STENCIL_EXT: 393af69d88dSmrg case GL_RG_INTEGER: 394af69d88dSmrg return 2; 395af69d88dSmrg 396af69d88dSmrg case GL_RGB: 397af69d88dSmrg case GL_BGR: 398af69d88dSmrg case GL_RGB_INTEGER_EXT: 399af69d88dSmrg case GL_BGR_INTEGER_EXT: 400af69d88dSmrg return 3; 401af69d88dSmrg 402af69d88dSmrg case GL_RGBA: 403af69d88dSmrg case GL_BGRA: 404af69d88dSmrg case GL_ABGR_EXT: 405af69d88dSmrg case GL_RGBA_INTEGER_EXT: 406af69d88dSmrg case GL_BGRA_INTEGER_EXT: 407af69d88dSmrg return 4; 408af69d88dSmrg 409af69d88dSmrg default: 410af69d88dSmrg return -1; 411af69d88dSmrg } 412af69d88dSmrg} 413af69d88dSmrg 414af69d88dSmrg 415af69d88dSmrg/** 416af69d88dSmrg * Get the bytes per pixel of pixel format type pair. 417af69d88dSmrg * 418af69d88dSmrg * \param format pixel format. 419af69d88dSmrg * \param type pixel type. 420af69d88dSmrg * 421af69d88dSmrg * \return bytes per pixel, or -1 if a bad format or type was given. 422af69d88dSmrg */ 423af69d88dSmrgGLint 424af69d88dSmrg_mesa_bytes_per_pixel(GLenum format, GLenum type) 425af69d88dSmrg{ 426af69d88dSmrg GLint comps = _mesa_components_in_format(format); 427af69d88dSmrg if (comps < 0) 428af69d88dSmrg return -1; 429af69d88dSmrg 430af69d88dSmrg switch (type) { 431af69d88dSmrg case GL_BITMAP: 432af69d88dSmrg return 0; /* special case */ 433af69d88dSmrg case GL_BYTE: 434af69d88dSmrg case GL_UNSIGNED_BYTE: 435af69d88dSmrg return comps * sizeof(GLubyte); 436af69d88dSmrg case GL_SHORT: 437af69d88dSmrg case GL_UNSIGNED_SHORT: 438af69d88dSmrg return comps * sizeof(GLshort); 439af69d88dSmrg case GL_INT: 440af69d88dSmrg case GL_UNSIGNED_INT: 441af69d88dSmrg return comps * sizeof(GLint); 442af69d88dSmrg case GL_FLOAT: 443af69d88dSmrg return comps * sizeof(GLfloat); 444af69d88dSmrg case GL_HALF_FLOAT_ARB: 44501e04c3fSmrg case GL_HALF_FLOAT_OES: 446af69d88dSmrg return comps * sizeof(GLhalfARB); 447af69d88dSmrg case GL_UNSIGNED_BYTE_3_3_2: 448af69d88dSmrg case GL_UNSIGNED_BYTE_2_3_3_REV: 449af69d88dSmrg if (format == GL_RGB || format == GL_BGR || 450af69d88dSmrg format == GL_RGB_INTEGER_EXT || format == GL_BGR_INTEGER_EXT) 451af69d88dSmrg return sizeof(GLubyte); 452af69d88dSmrg else 453af69d88dSmrg return -1; /* error */ 454af69d88dSmrg case GL_UNSIGNED_SHORT_5_6_5: 455af69d88dSmrg case GL_UNSIGNED_SHORT_5_6_5_REV: 456af69d88dSmrg if (format == GL_RGB || format == GL_BGR || 457af69d88dSmrg format == GL_RGB_INTEGER_EXT || format == GL_BGR_INTEGER_EXT) 458af69d88dSmrg return sizeof(GLushort); 459af69d88dSmrg else 460af69d88dSmrg return -1; /* error */ 461af69d88dSmrg case GL_UNSIGNED_SHORT_4_4_4_4: 462af69d88dSmrg case GL_UNSIGNED_SHORT_4_4_4_4_REV: 46301e04c3fSmrg if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT || 46401e04c3fSmrg format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT) 46501e04c3fSmrg return sizeof(GLushort); 46601e04c3fSmrg else 46701e04c3fSmrg return -1; 468af69d88dSmrg case GL_UNSIGNED_SHORT_5_5_5_1: 469af69d88dSmrg case GL_UNSIGNED_SHORT_1_5_5_5_REV: 47001e04c3fSmrg if (format == GL_RGBA || format == GL_BGRA || 471af69d88dSmrg format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT) 472af69d88dSmrg return sizeof(GLushort); 473af69d88dSmrg else 474af69d88dSmrg return -1; 475af69d88dSmrg case GL_UNSIGNED_INT_8_8_8_8: 476af69d88dSmrg case GL_UNSIGNED_INT_8_8_8_8_REV: 47701e04c3fSmrg if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT || 47801e04c3fSmrg format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT || 47901e04c3fSmrg format == GL_RGB) 48001e04c3fSmrg return sizeof(GLuint); 48101e04c3fSmrg else 48201e04c3fSmrg return -1; 483af69d88dSmrg case GL_UNSIGNED_INT_10_10_10_2: 484af69d88dSmrg case GL_UNSIGNED_INT_2_10_10_10_REV: 48501e04c3fSmrg if (format == GL_RGBA || format == GL_BGRA || 486af69d88dSmrg format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT || 487af69d88dSmrg format == GL_RGB) 488af69d88dSmrg return sizeof(GLuint); 489af69d88dSmrg else 490af69d88dSmrg return -1; 491af69d88dSmrg case GL_UNSIGNED_SHORT_8_8_MESA: 492af69d88dSmrg case GL_UNSIGNED_SHORT_8_8_REV_MESA: 493af69d88dSmrg if (format == GL_YCBCR_MESA) 494af69d88dSmrg return sizeof(GLushort); 495af69d88dSmrg else 496af69d88dSmrg return -1; 497af69d88dSmrg case GL_UNSIGNED_INT_24_8_EXT: 49801e04c3fSmrg if (format == GL_DEPTH_COMPONENT || 49901e04c3fSmrg format == GL_DEPTH_STENCIL_EXT) 500af69d88dSmrg return sizeof(GLuint); 501af69d88dSmrg else 502af69d88dSmrg return -1; 503af69d88dSmrg case GL_UNSIGNED_INT_5_9_9_9_REV: 504af69d88dSmrg if (format == GL_RGB) 505af69d88dSmrg return sizeof(GLuint); 506af69d88dSmrg else 507af69d88dSmrg return -1; 508af69d88dSmrg case GL_UNSIGNED_INT_10F_11F_11F_REV: 509af69d88dSmrg if (format == GL_RGB) 510af69d88dSmrg return sizeof(GLuint); 511af69d88dSmrg else 512af69d88dSmrg return -1; 513af69d88dSmrg case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: 514af69d88dSmrg if (format == GL_DEPTH_STENCIL) 515af69d88dSmrg return 8; 516af69d88dSmrg else 517af69d88dSmrg return -1; 518af69d88dSmrg default: 519af69d88dSmrg return -1; 520af69d88dSmrg } 521af69d88dSmrg} 522af69d88dSmrg 523af69d88dSmrg 524af69d88dSmrg/** 525af69d88dSmrg * Get the number of bytes for a vertex attrib with the given number of 526af69d88dSmrg * components and type. 527af69d88dSmrg * 528af69d88dSmrg * \param comps number of components. 529af69d88dSmrg * \param type data type. 530af69d88dSmrg * 531af69d88dSmrg * \return bytes per attribute, or -1 if a bad comps/type combination was given. 532af69d88dSmrg */ 533af69d88dSmrgGLint 534af69d88dSmrg_mesa_bytes_per_vertex_attrib(GLint comps, GLenum type) 535af69d88dSmrg{ 536af69d88dSmrg switch (type) { 537af69d88dSmrg case GL_BYTE: 538af69d88dSmrg case GL_UNSIGNED_BYTE: 539af69d88dSmrg return comps * sizeof(GLubyte); 540af69d88dSmrg case GL_SHORT: 541af69d88dSmrg case GL_UNSIGNED_SHORT: 542af69d88dSmrg return comps * sizeof(GLshort); 543af69d88dSmrg case GL_INT: 544af69d88dSmrg case GL_UNSIGNED_INT: 545af69d88dSmrg return comps * sizeof(GLint); 546af69d88dSmrg case GL_FLOAT: 547af69d88dSmrg return comps * sizeof(GLfloat); 548af69d88dSmrg case GL_HALF_FLOAT_ARB: 54901e04c3fSmrg case GL_HALF_FLOAT_OES: 550af69d88dSmrg return comps * sizeof(GLhalfARB); 551af69d88dSmrg case GL_DOUBLE: 552af69d88dSmrg return comps * sizeof(GLdouble); 553af69d88dSmrg case GL_FIXED: 554af69d88dSmrg return comps * sizeof(GLfixed); 555af69d88dSmrg case GL_INT_2_10_10_10_REV: 556af69d88dSmrg case GL_UNSIGNED_INT_2_10_10_10_REV: 557af69d88dSmrg if (comps == 4) 558af69d88dSmrg return sizeof(GLuint); 559af69d88dSmrg else 560af69d88dSmrg return -1; 561af69d88dSmrg case GL_UNSIGNED_INT_10F_11F_11F_REV: 562af69d88dSmrg if (comps == 3) 563af69d88dSmrg return sizeof(GLuint); 564af69d88dSmrg else 565af69d88dSmrg return -1; 56601e04c3fSmrg case GL_UNSIGNED_INT64_ARB: 56701e04c3fSmrg return comps * 8; 568af69d88dSmrg default: 569af69d88dSmrg return -1; 570af69d88dSmrg } 571af69d88dSmrg} 572af69d88dSmrg 573af69d88dSmrg/** 574af69d88dSmrg * Test if the given format is unsized. 575af69d88dSmrg */ 576af69d88dSmrgGLboolean 577af69d88dSmrg_mesa_is_enum_format_unsized(GLenum format) 578af69d88dSmrg{ 579af69d88dSmrg switch (format) { 580af69d88dSmrg case GL_RGBA: 581af69d88dSmrg case GL_BGRA: 582af69d88dSmrg case GL_ABGR_EXT: 583af69d88dSmrg case GL_RGB: 584af69d88dSmrg case GL_BGR: 585af69d88dSmrg case GL_RG: 586af69d88dSmrg case GL_RED: 587af69d88dSmrg case GL_GREEN: 588af69d88dSmrg case GL_BLUE: 589af69d88dSmrg case GL_ALPHA: 590af69d88dSmrg case GL_INTENSITY: 591af69d88dSmrg case GL_LUMINANCE: 592af69d88dSmrg case GL_LUMINANCE_ALPHA: 593af69d88dSmrg 594af69d88dSmrg case GL_SRGB: 595af69d88dSmrg case GL_SRGB_ALPHA: 596af69d88dSmrg case GL_SLUMINANCE: 597af69d88dSmrg case GL_SLUMINANCE_ALPHA: 598af69d88dSmrg 599af69d88dSmrg case GL_RGBA_SNORM: 600af69d88dSmrg case GL_RGB_SNORM: 601af69d88dSmrg case GL_RG_SNORM: 602af69d88dSmrg case GL_RED_SNORM: 603af69d88dSmrg case GL_ALPHA_SNORM: 604af69d88dSmrg case GL_INTENSITY_SNORM: 605af69d88dSmrg case GL_LUMINANCE_SNORM: 606af69d88dSmrg case GL_LUMINANCE_ALPHA_SNORM: 607af69d88dSmrg 608af69d88dSmrg case GL_RED_INTEGER: 609af69d88dSmrg case GL_GREEN_INTEGER: 610af69d88dSmrg case GL_BLUE_INTEGER: 611af69d88dSmrg case GL_ALPHA_INTEGER: 612af69d88dSmrg case GL_RGB_INTEGER: 613af69d88dSmrg case GL_RGBA_INTEGER: 614af69d88dSmrg case GL_BGR_INTEGER: 615af69d88dSmrg case GL_BGRA_INTEGER: 616af69d88dSmrg case GL_RG_INTEGER: 617af69d88dSmrg case GL_LUMINANCE_INTEGER_EXT: 618af69d88dSmrg case GL_LUMINANCE_ALPHA_INTEGER_EXT: 619af69d88dSmrg 620af69d88dSmrg case GL_DEPTH_COMPONENT: 621af69d88dSmrg case GL_DEPTH_STENCIL: 622af69d88dSmrg case GL_STENCIL_INDEX: 623af69d88dSmrg return GL_TRUE; 624af69d88dSmrg default: 625af69d88dSmrg return GL_FALSE; 626af69d88dSmrg } 627af69d88dSmrg} 628af69d88dSmrg 629af69d88dSmrg/** 630af69d88dSmrg * Test if the given format is a UNORM (unsigned-normalized) format. 631af69d88dSmrg */ 632af69d88dSmrgGLboolean 633af69d88dSmrg_mesa_is_enum_format_unorm(GLenum format) 634af69d88dSmrg{ 635af69d88dSmrg switch(format) { 636af69d88dSmrg case GL_RED: 637af69d88dSmrg case GL_GREEN: 638af69d88dSmrg case GL_BLUE: 639af69d88dSmrg case GL_ALPHA: 640af69d88dSmrg case GL_ALPHA4: 641af69d88dSmrg case GL_ALPHA8: 642af69d88dSmrg case GL_ALPHA12: 643af69d88dSmrg case GL_ALPHA16: 644af69d88dSmrg case 1: 645af69d88dSmrg case GL_LUMINANCE: 646af69d88dSmrg case GL_SLUMINANCE: 647af69d88dSmrg case GL_LUMINANCE4: 648af69d88dSmrg case GL_LUMINANCE8: 649af69d88dSmrg case GL_LUMINANCE12: 650af69d88dSmrg case GL_LUMINANCE16: 651af69d88dSmrg case 2: 652af69d88dSmrg case GL_LUMINANCE_ALPHA: 653af69d88dSmrg case GL_SLUMINANCE_ALPHA: 654af69d88dSmrg case GL_LUMINANCE4_ALPHA4: 655af69d88dSmrg case GL_LUMINANCE6_ALPHA2: 656af69d88dSmrg case GL_LUMINANCE8_ALPHA8: 657af69d88dSmrg case GL_LUMINANCE12_ALPHA4: 658af69d88dSmrg case GL_LUMINANCE12_ALPHA12: 659af69d88dSmrg case GL_LUMINANCE16_ALPHA16: 660af69d88dSmrg case GL_INTENSITY: 661af69d88dSmrg case GL_INTENSITY4: 662af69d88dSmrg case GL_INTENSITY8: 663af69d88dSmrg case GL_INTENSITY12: 664af69d88dSmrg case GL_INTENSITY16: 665af69d88dSmrg case GL_R8: 666af69d88dSmrg case GL_R16: 667af69d88dSmrg case GL_RG: 668af69d88dSmrg case GL_RG8: 669af69d88dSmrg case GL_RG16: 670af69d88dSmrg case 3: 671af69d88dSmrg case GL_RGB: 672af69d88dSmrg case GL_BGR: 673af69d88dSmrg case GL_SRGB: 674af69d88dSmrg case GL_R3_G3_B2: 675af69d88dSmrg case GL_RGB4: 676af69d88dSmrg case GL_RGB5: 677af69d88dSmrg case GL_RGB565: 678af69d88dSmrg case GL_RGB8: 679af69d88dSmrg case GL_RGB10: 680af69d88dSmrg case GL_RGB12: 681af69d88dSmrg case GL_RGB16: 682af69d88dSmrg case 4: 683af69d88dSmrg case GL_ABGR_EXT: 684af69d88dSmrg case GL_RGBA: 685af69d88dSmrg case GL_BGRA: 686af69d88dSmrg case GL_SRGB_ALPHA: 687af69d88dSmrg case GL_RGBA2: 688af69d88dSmrg case GL_RGBA4: 689af69d88dSmrg case GL_RGB5_A1: 690af69d88dSmrg case GL_RGBA8: 691af69d88dSmrg case GL_RGB10_A2: 692af69d88dSmrg case GL_RGBA12: 693af69d88dSmrg case GL_RGBA16: 694af69d88dSmrg return GL_TRUE; 695af69d88dSmrg default: 696af69d88dSmrg return GL_FALSE; 697af69d88dSmrg } 698af69d88dSmrg} 699af69d88dSmrg 700af69d88dSmrg/** 701af69d88dSmrg * Test if the given format is a SNORM (signed-normalized) format. 702af69d88dSmrg */ 703af69d88dSmrgGLboolean 704af69d88dSmrg_mesa_is_enum_format_snorm(GLenum format) 705af69d88dSmrg{ 706af69d88dSmrg switch (format) { 707af69d88dSmrg /* signed, normalized texture formats */ 708af69d88dSmrg case GL_RED_SNORM: 709af69d88dSmrg case GL_R8_SNORM: 710af69d88dSmrg case GL_R16_SNORM: 711af69d88dSmrg case GL_RG_SNORM: 712af69d88dSmrg case GL_RG8_SNORM: 713af69d88dSmrg case GL_RG16_SNORM: 714af69d88dSmrg case GL_RGB_SNORM: 715af69d88dSmrg case GL_RGB8_SNORM: 716af69d88dSmrg case GL_RGB16_SNORM: 717af69d88dSmrg case GL_RGBA_SNORM: 718af69d88dSmrg case GL_RGBA8_SNORM: 719af69d88dSmrg case GL_RGBA16_SNORM: 720af69d88dSmrg case GL_ALPHA_SNORM: 721af69d88dSmrg case GL_ALPHA8_SNORM: 722af69d88dSmrg case GL_ALPHA16_SNORM: 723af69d88dSmrg case GL_LUMINANCE_SNORM: 724af69d88dSmrg case GL_LUMINANCE8_SNORM: 725af69d88dSmrg case GL_LUMINANCE16_SNORM: 726af69d88dSmrg case GL_LUMINANCE_ALPHA_SNORM: 727af69d88dSmrg case GL_LUMINANCE8_ALPHA8_SNORM: 728af69d88dSmrg case GL_LUMINANCE16_ALPHA16_SNORM: 729af69d88dSmrg case GL_INTENSITY_SNORM: 730af69d88dSmrg case GL_INTENSITY8_SNORM: 731af69d88dSmrg case GL_INTENSITY16_SNORM: 732af69d88dSmrg return GL_TRUE; 733af69d88dSmrg default: 734af69d88dSmrg return GL_FALSE; 735af69d88dSmrg } 736af69d88dSmrg} 737af69d88dSmrg 738af69d88dSmrg/** 739af69d88dSmrg * Test if the given format is an integer (non-normalized) format. 740af69d88dSmrg */ 741af69d88dSmrgGLboolean 742af69d88dSmrg_mesa_is_enum_format_unsigned_int(GLenum format) 743af69d88dSmrg{ 744af69d88dSmrg switch (format) { 745af69d88dSmrg /* specific integer formats */ 746af69d88dSmrg case GL_RGBA32UI_EXT: 747af69d88dSmrg case GL_RGB32UI_EXT: 748af69d88dSmrg case GL_RG32UI: 749af69d88dSmrg case GL_R32UI: 750af69d88dSmrg case GL_ALPHA32UI_EXT: 751af69d88dSmrg case GL_INTENSITY32UI_EXT: 752af69d88dSmrg case GL_LUMINANCE32UI_EXT: 753af69d88dSmrg case GL_LUMINANCE_ALPHA32UI_EXT: 754af69d88dSmrg case GL_RGBA16UI_EXT: 755af69d88dSmrg case GL_RGB16UI_EXT: 756af69d88dSmrg case GL_RG16UI: 757af69d88dSmrg case GL_R16UI: 758af69d88dSmrg case GL_ALPHA16UI_EXT: 759af69d88dSmrg case GL_INTENSITY16UI_EXT: 760af69d88dSmrg case GL_LUMINANCE16UI_EXT: 761af69d88dSmrg case GL_LUMINANCE_ALPHA16UI_EXT: 762af69d88dSmrg case GL_RGBA8UI_EXT: 763af69d88dSmrg case GL_RGB8UI_EXT: 764af69d88dSmrg case GL_RG8UI: 765af69d88dSmrg case GL_R8UI: 766af69d88dSmrg case GL_ALPHA8UI_EXT: 767af69d88dSmrg case GL_INTENSITY8UI_EXT: 768af69d88dSmrg case GL_LUMINANCE8UI_EXT: 769af69d88dSmrg case GL_LUMINANCE_ALPHA8UI_EXT: 770af69d88dSmrg case GL_RGB10_A2UI: 771af69d88dSmrg return GL_TRUE; 772af69d88dSmrg default: 773af69d88dSmrg return GL_FALSE; 774af69d88dSmrg } 775af69d88dSmrg} 776af69d88dSmrg 777af69d88dSmrg 778af69d88dSmrg/** 779af69d88dSmrg * Test if the given format is an integer (non-normalized) format. 780af69d88dSmrg */ 781af69d88dSmrgGLboolean 782af69d88dSmrg_mesa_is_enum_format_signed_int(GLenum format) 783af69d88dSmrg{ 784af69d88dSmrg switch (format) { 785af69d88dSmrg /* generic integer formats */ 786af69d88dSmrg case GL_RED_INTEGER_EXT: 787af69d88dSmrg case GL_GREEN_INTEGER_EXT: 788af69d88dSmrg case GL_BLUE_INTEGER_EXT: 789af69d88dSmrg case GL_ALPHA_INTEGER_EXT: 790af69d88dSmrg case GL_RGB_INTEGER_EXT: 791af69d88dSmrg case GL_RGBA_INTEGER_EXT: 792af69d88dSmrg case GL_BGR_INTEGER_EXT: 793af69d88dSmrg case GL_BGRA_INTEGER_EXT: 794af69d88dSmrg case GL_LUMINANCE_INTEGER_EXT: 795af69d88dSmrg case GL_LUMINANCE_ALPHA_INTEGER_EXT: 796af69d88dSmrg case GL_RG_INTEGER: 797af69d88dSmrg /* specific integer formats */ 798af69d88dSmrg case GL_RGBA32I_EXT: 799af69d88dSmrg case GL_RGB32I_EXT: 800af69d88dSmrg case GL_RG32I: 801af69d88dSmrg case GL_R32I: 802af69d88dSmrg case GL_ALPHA32I_EXT: 803af69d88dSmrg case GL_INTENSITY32I_EXT: 804af69d88dSmrg case GL_LUMINANCE32I_EXT: 805af69d88dSmrg case GL_LUMINANCE_ALPHA32I_EXT: 806af69d88dSmrg case GL_RGBA16I_EXT: 807af69d88dSmrg case GL_RGB16I_EXT: 808af69d88dSmrg case GL_RG16I: 809af69d88dSmrg case GL_R16I: 810af69d88dSmrg case GL_ALPHA16I_EXT: 811af69d88dSmrg case GL_INTENSITY16I_EXT: 812af69d88dSmrg case GL_LUMINANCE16I_EXT: 813af69d88dSmrg case GL_LUMINANCE_ALPHA16I_EXT: 814af69d88dSmrg case GL_RGBA8I_EXT: 815af69d88dSmrg case GL_RGB8I_EXT: 816af69d88dSmrg case GL_RG8I: 817af69d88dSmrg case GL_R8I: 818af69d88dSmrg case GL_ALPHA8I_EXT: 819af69d88dSmrg case GL_INTENSITY8I_EXT: 820af69d88dSmrg case GL_LUMINANCE8I_EXT: 821af69d88dSmrg case GL_LUMINANCE_ALPHA8I_EXT: 822af69d88dSmrg return GL_TRUE; 823af69d88dSmrg default: 824af69d88dSmrg return GL_FALSE; 825af69d88dSmrg } 826af69d88dSmrg} 827af69d88dSmrg 82801e04c3fSmrg/** 82901e04c3fSmrg * Test if the given format is an ASTC 2D format. 83001e04c3fSmrg */ 83101e04c3fSmrgstatic bool 83201e04c3fSmrgis_astc_2d_format(GLenum internalFormat) 83301e04c3fSmrg{ 83401e04c3fSmrg switch (internalFormat) { 83501e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_4x4_KHR: 83601e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_5x4_KHR: 83701e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_5x5_KHR: 83801e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_6x5_KHR: 83901e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_6x6_KHR: 84001e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_8x5_KHR: 84101e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_8x6_KHR: 84201e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_8x8_KHR: 84301e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_10x5_KHR: 84401e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_10x6_KHR: 84501e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_10x8_KHR: 84601e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_10x10_KHR: 84701e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_12x10_KHR: 84801e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_12x12_KHR: 84901e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: 85001e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR: 85101e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR: 85201e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR: 85301e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR: 85401e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR: 85501e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR: 85601e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR: 85701e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR: 85801e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR: 85901e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR: 86001e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR: 86101e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR: 86201e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: 86301e04c3fSmrg return true; 86401e04c3fSmrg default: 86501e04c3fSmrg return false; 86601e04c3fSmrg } 86701e04c3fSmrg} 86801e04c3fSmrg 86901e04c3fSmrg/** 87001e04c3fSmrg * Test if the given format is an ASTC 3D format. 87101e04c3fSmrg */ 87201e04c3fSmrgstatic bool 87301e04c3fSmrgis_astc_3d_format(GLenum internalFormat) 87401e04c3fSmrg{ 87501e04c3fSmrg switch (internalFormat) { 87601e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_3x3x3_OES: 87701e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_4x3x3_OES: 87801e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_4x4x3_OES: 87901e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_4x4x4_OES: 88001e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_5x4x4_OES: 88101e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_5x5x4_OES: 88201e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_5x5x5_OES: 88301e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_6x5x5_OES: 88401e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_6x6x5_OES: 88501e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_6x6x6_OES: 88601e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES: 88701e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES: 88801e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES: 88901e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES: 89001e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES: 89101e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES: 89201e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES: 89301e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES: 89401e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES: 89501e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES: 89601e04c3fSmrg return true; 89701e04c3fSmrg default: 89801e04c3fSmrg return false; 89901e04c3fSmrg } 90001e04c3fSmrg} 90101e04c3fSmrg 90201e04c3fSmrg/** 90301e04c3fSmrg * Test if the given format is an ASTC format. 90401e04c3fSmrg */ 90501e04c3fSmrgGLboolean 90601e04c3fSmrg_mesa_is_astc_format(GLenum internalFormat) 90701e04c3fSmrg{ 90801e04c3fSmrg return is_astc_2d_format(internalFormat) || 90901e04c3fSmrg is_astc_3d_format(internalFormat); 91001e04c3fSmrg} 91101e04c3fSmrg 91201e04c3fSmrg/** 91301e04c3fSmrg * Test if the given format is an ETC2 format. 91401e04c3fSmrg */ 91501e04c3fSmrgGLboolean 91601e04c3fSmrg_mesa_is_etc2_format(GLenum internalFormat) 91701e04c3fSmrg{ 91801e04c3fSmrg switch (internalFormat) { 91901e04c3fSmrg case GL_COMPRESSED_RGB8_ETC2: 92001e04c3fSmrg case GL_COMPRESSED_SRGB8_ETC2: 92101e04c3fSmrg case GL_COMPRESSED_RGBA8_ETC2_EAC: 92201e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 92301e04c3fSmrg case GL_COMPRESSED_R11_EAC: 92401e04c3fSmrg case GL_COMPRESSED_RG11_EAC: 92501e04c3fSmrg case GL_COMPRESSED_SIGNED_R11_EAC: 92601e04c3fSmrg case GL_COMPRESSED_SIGNED_RG11_EAC: 92701e04c3fSmrg case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: 92801e04c3fSmrg case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 92901e04c3fSmrg return true; 93001e04c3fSmrg default: 93101e04c3fSmrg return false; 93201e04c3fSmrg } 93301e04c3fSmrg} 934af69d88dSmrg 935af69d88dSmrg/** 936af69d88dSmrg * Test if the given format is an integer (non-normalized) format. 937af69d88dSmrg */ 938af69d88dSmrgGLboolean 939af69d88dSmrg_mesa_is_enum_format_integer(GLenum format) 940af69d88dSmrg{ 941af69d88dSmrg return _mesa_is_enum_format_unsigned_int(format) || 942af69d88dSmrg _mesa_is_enum_format_signed_int(format); 943af69d88dSmrg} 944af69d88dSmrg 945af69d88dSmrg 946af69d88dSmrgGLboolean 947af69d88dSmrg_mesa_is_type_unsigned(GLenum type) 948af69d88dSmrg{ 949af69d88dSmrg switch (type) { 950af69d88dSmrg case GL_UNSIGNED_INT: 951af69d88dSmrg case GL_UNSIGNED_INT_8_8_8_8: 952af69d88dSmrg case GL_UNSIGNED_INT_8_8_8_8_REV: 953af69d88dSmrg case GL_UNSIGNED_INT_10_10_10_2: 954af69d88dSmrg case GL_UNSIGNED_INT_2_10_10_10_REV: 955af69d88dSmrg 956af69d88dSmrg case GL_UNSIGNED_SHORT: 957af69d88dSmrg case GL_UNSIGNED_SHORT_4_4_4_4: 958af69d88dSmrg case GL_UNSIGNED_SHORT_5_5_5_1: 959af69d88dSmrg case GL_UNSIGNED_SHORT_5_6_5: 960af69d88dSmrg case GL_UNSIGNED_SHORT_5_6_5_REV: 961af69d88dSmrg case GL_UNSIGNED_SHORT_4_4_4_4_REV: 962af69d88dSmrg case GL_UNSIGNED_SHORT_1_5_5_5_REV: 963af69d88dSmrg case GL_UNSIGNED_SHORT_8_8_MESA: 964af69d88dSmrg case GL_UNSIGNED_SHORT_8_8_REV_MESA: 965af69d88dSmrg 966af69d88dSmrg case GL_UNSIGNED_BYTE: 967af69d88dSmrg case GL_UNSIGNED_BYTE_3_3_2: 968af69d88dSmrg case GL_UNSIGNED_BYTE_2_3_3_REV: 969af69d88dSmrg return GL_TRUE; 970af69d88dSmrg 971af69d88dSmrg default: 972af69d88dSmrg return GL_FALSE; 973af69d88dSmrg } 974af69d88dSmrg} 975af69d88dSmrg 976af69d88dSmrg 977af69d88dSmrg/** 978af69d88dSmrg * Test if the given image format is a color/RGBA format (i.e., not color 979af69d88dSmrg * index, depth, stencil, etc). 980af69d88dSmrg * \param format the image format value (may by an internal texture format) 981af69d88dSmrg * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise. 982af69d88dSmrg */ 983af69d88dSmrgGLboolean 984af69d88dSmrg_mesa_is_color_format(GLenum format) 985af69d88dSmrg{ 986af69d88dSmrg switch (format) { 987af69d88dSmrg case GL_RED: 988af69d88dSmrg case GL_GREEN: 989af69d88dSmrg case GL_BLUE: 990af69d88dSmrg case GL_ALPHA: 991af69d88dSmrg case GL_ALPHA4: 992af69d88dSmrg case GL_ALPHA8: 993af69d88dSmrg case GL_ALPHA12: 994af69d88dSmrg case GL_ALPHA16: 995af69d88dSmrg case 1: 996af69d88dSmrg case GL_LUMINANCE: 997af69d88dSmrg case GL_LUMINANCE4: 998af69d88dSmrg case GL_LUMINANCE8: 999af69d88dSmrg case GL_LUMINANCE12: 1000af69d88dSmrg case GL_LUMINANCE16: 1001af69d88dSmrg case 2: 1002af69d88dSmrg case GL_LUMINANCE_ALPHA: 1003af69d88dSmrg case GL_LUMINANCE4_ALPHA4: 1004af69d88dSmrg case GL_LUMINANCE6_ALPHA2: 1005af69d88dSmrg case GL_LUMINANCE8_ALPHA8: 1006af69d88dSmrg case GL_LUMINANCE12_ALPHA4: 1007af69d88dSmrg case GL_LUMINANCE12_ALPHA12: 1008af69d88dSmrg case GL_LUMINANCE16_ALPHA16: 1009af69d88dSmrg case GL_INTENSITY: 1010af69d88dSmrg case GL_INTENSITY4: 1011af69d88dSmrg case GL_INTENSITY8: 1012af69d88dSmrg case GL_INTENSITY12: 1013af69d88dSmrg case GL_INTENSITY16: 1014af69d88dSmrg case GL_R8: 1015af69d88dSmrg case GL_R16: 1016af69d88dSmrg case GL_RG: 1017af69d88dSmrg case GL_RG8: 1018af69d88dSmrg case GL_RG16: 1019af69d88dSmrg case 3: 1020af69d88dSmrg case GL_RGB: 1021af69d88dSmrg case GL_BGR: 1022af69d88dSmrg case GL_R3_G3_B2: 1023af69d88dSmrg case GL_RGB4: 1024af69d88dSmrg case GL_RGB5: 1025af69d88dSmrg case GL_RGB565: 1026af69d88dSmrg case GL_RGB8: 1027af69d88dSmrg case GL_RGB10: 1028af69d88dSmrg case GL_RGB12: 1029af69d88dSmrg case GL_RGB16: 1030af69d88dSmrg case 4: 1031af69d88dSmrg case GL_ABGR_EXT: 1032af69d88dSmrg case GL_RGBA: 1033af69d88dSmrg case GL_BGRA: 1034af69d88dSmrg case GL_RGBA2: 1035af69d88dSmrg case GL_RGBA4: 1036af69d88dSmrg case GL_RGB5_A1: 1037af69d88dSmrg case GL_RGBA8: 1038af69d88dSmrg case GL_RGB10_A2: 1039af69d88dSmrg case GL_RGBA12: 1040af69d88dSmrg case GL_RGBA16: 1041af69d88dSmrg /* float texture formats */ 1042af69d88dSmrg case GL_ALPHA16F_ARB: 1043af69d88dSmrg case GL_ALPHA32F_ARB: 1044af69d88dSmrg case GL_LUMINANCE16F_ARB: 1045af69d88dSmrg case GL_LUMINANCE32F_ARB: 1046af69d88dSmrg case GL_LUMINANCE_ALPHA16F_ARB: 1047af69d88dSmrg case GL_LUMINANCE_ALPHA32F_ARB: 1048af69d88dSmrg case GL_INTENSITY16F_ARB: 1049af69d88dSmrg case GL_INTENSITY32F_ARB: 1050af69d88dSmrg case GL_R16F: 1051af69d88dSmrg case GL_R32F: 1052af69d88dSmrg case GL_RG16F: 1053af69d88dSmrg case GL_RG32F: 1054af69d88dSmrg case GL_RGB16F_ARB: 1055af69d88dSmrg case GL_RGB32F_ARB: 1056af69d88dSmrg case GL_RGBA16F_ARB: 1057af69d88dSmrg case GL_RGBA32F_ARB: 1058af69d88dSmrg /* compressed formats */ 1059af69d88dSmrg case GL_COMPRESSED_ALPHA: 1060af69d88dSmrg case GL_COMPRESSED_LUMINANCE: 1061af69d88dSmrg case GL_COMPRESSED_LUMINANCE_ALPHA: 1062af69d88dSmrg case GL_COMPRESSED_INTENSITY: 1063af69d88dSmrg case GL_COMPRESSED_RED: 1064af69d88dSmrg case GL_COMPRESSED_RG: 1065af69d88dSmrg case GL_COMPRESSED_RGB: 1066af69d88dSmrg case GL_COMPRESSED_RGBA: 1067af69d88dSmrg case GL_RGB_S3TC: 1068af69d88dSmrg case GL_RGB4_S3TC: 1069af69d88dSmrg case GL_RGBA_S3TC: 1070af69d88dSmrg case GL_RGBA4_S3TC: 1071af69d88dSmrg case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 1072af69d88dSmrg case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 1073af69d88dSmrg case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 1074af69d88dSmrg case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 1075af69d88dSmrg case GL_COMPRESSED_RGB_FXT1_3DFX: 1076af69d88dSmrg case GL_COMPRESSED_RGBA_FXT1_3DFX: 10777ec681f3Smrg case GL_SR8_EXT: 10787ec681f3Smrg case GL_SRG8_EXT: 1079af69d88dSmrg case GL_SRGB_EXT: 1080af69d88dSmrg case GL_SRGB8_EXT: 1081af69d88dSmrg case GL_SRGB_ALPHA_EXT: 1082af69d88dSmrg case GL_SRGB8_ALPHA8_EXT: 1083af69d88dSmrg case GL_SLUMINANCE_ALPHA_EXT: 1084af69d88dSmrg case GL_SLUMINANCE8_ALPHA8_EXT: 1085af69d88dSmrg case GL_SLUMINANCE_EXT: 1086af69d88dSmrg case GL_SLUMINANCE8_EXT: 1087af69d88dSmrg case GL_COMPRESSED_SRGB_EXT: 1088af69d88dSmrg case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: 1089af69d88dSmrg case GL_COMPRESSED_SRGB_ALPHA_EXT: 1090af69d88dSmrg case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 1091af69d88dSmrg case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 1092af69d88dSmrg case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 1093af69d88dSmrg case GL_COMPRESSED_SLUMINANCE_EXT: 1094af69d88dSmrg case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT: 1095af69d88dSmrg case GL_COMPRESSED_RED_RGTC1: 1096af69d88dSmrg case GL_COMPRESSED_SIGNED_RED_RGTC1: 1097af69d88dSmrg case GL_COMPRESSED_RG_RGTC2: 1098af69d88dSmrg case GL_COMPRESSED_SIGNED_RG_RGTC2: 1099af69d88dSmrg case GL_COMPRESSED_LUMINANCE_LATC1_EXT: 1100af69d88dSmrg case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT: 1101af69d88dSmrg case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT: 1102af69d88dSmrg case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT: 1103af69d88dSmrg case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI: 1104af69d88dSmrg case GL_ETC1_RGB8_OES: 1105af69d88dSmrg case GL_COMPRESSED_RGB8_ETC2: 1106af69d88dSmrg case GL_COMPRESSED_SRGB8_ETC2: 1107af69d88dSmrg case GL_COMPRESSED_RGBA8_ETC2_EAC: 1108af69d88dSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 1109af69d88dSmrg case GL_COMPRESSED_R11_EAC: 1110af69d88dSmrg case GL_COMPRESSED_RG11_EAC: 1111af69d88dSmrg case GL_COMPRESSED_SIGNED_R11_EAC: 1112af69d88dSmrg case GL_COMPRESSED_SIGNED_RG11_EAC: 1113af69d88dSmrg case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: 1114af69d88dSmrg case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 1115af69d88dSmrg case GL_COMPRESSED_RGBA_BPTC_UNORM: 1116af69d88dSmrg case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM: 1117af69d88dSmrg case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT: 1118af69d88dSmrg case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT: 111901e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_4x4_KHR: 112001e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_5x4_KHR: 112101e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_5x5_KHR: 112201e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_6x5_KHR: 112301e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_6x6_KHR: 112401e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_8x5_KHR: 112501e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_8x6_KHR: 112601e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_8x8_KHR: 112701e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_10x5_KHR: 112801e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_10x6_KHR: 112901e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_10x8_KHR: 113001e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_10x10_KHR: 113101e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_12x10_KHR: 113201e04c3fSmrg case GL_COMPRESSED_RGBA_ASTC_12x12_KHR: 113301e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: 113401e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR: 113501e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR: 113601e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR: 113701e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR: 113801e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR: 113901e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR: 114001e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR: 114101e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR: 114201e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR: 114301e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR: 114401e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR: 114501e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR: 114601e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: 1147b9abf16eSmaya case GL_ATC_RGB_AMD: 1148b9abf16eSmaya case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: 1149b9abf16eSmaya case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: 1150af69d88dSmrg /* generic integer formats */ 1151af69d88dSmrg case GL_RED_INTEGER_EXT: 1152af69d88dSmrg case GL_GREEN_INTEGER_EXT: 1153af69d88dSmrg case GL_BLUE_INTEGER_EXT: 1154af69d88dSmrg case GL_ALPHA_INTEGER_EXT: 1155af69d88dSmrg case GL_RGB_INTEGER_EXT: 1156af69d88dSmrg case GL_RGBA_INTEGER_EXT: 1157af69d88dSmrg case GL_BGR_INTEGER_EXT: 1158af69d88dSmrg case GL_BGRA_INTEGER_EXT: 1159af69d88dSmrg case GL_RG_INTEGER: 1160af69d88dSmrg case GL_LUMINANCE_INTEGER_EXT: 1161af69d88dSmrg case GL_LUMINANCE_ALPHA_INTEGER_EXT: 1162af69d88dSmrg /* sized integer formats */ 1163af69d88dSmrg case GL_RGBA32UI_EXT: 1164af69d88dSmrg case GL_RGB32UI_EXT: 1165af69d88dSmrg case GL_RG32UI: 1166af69d88dSmrg case GL_R32UI: 1167af69d88dSmrg case GL_ALPHA32UI_EXT: 1168af69d88dSmrg case GL_INTENSITY32UI_EXT: 1169af69d88dSmrg case GL_LUMINANCE32UI_EXT: 1170af69d88dSmrg case GL_LUMINANCE_ALPHA32UI_EXT: 1171af69d88dSmrg case GL_RGBA16UI_EXT: 1172af69d88dSmrg case GL_RGB16UI_EXT: 1173af69d88dSmrg case GL_RG16UI: 1174af69d88dSmrg case GL_R16UI: 1175af69d88dSmrg case GL_ALPHA16UI_EXT: 1176af69d88dSmrg case GL_INTENSITY16UI_EXT: 1177af69d88dSmrg case GL_LUMINANCE16UI_EXT: 1178af69d88dSmrg case GL_LUMINANCE_ALPHA16UI_EXT: 1179af69d88dSmrg case GL_RGBA8UI_EXT: 1180af69d88dSmrg case GL_RGB8UI_EXT: 1181af69d88dSmrg case GL_RG8UI: 1182af69d88dSmrg case GL_R8UI: 1183af69d88dSmrg case GL_ALPHA8UI_EXT: 1184af69d88dSmrg case GL_INTENSITY8UI_EXT: 1185af69d88dSmrg case GL_LUMINANCE8UI_EXT: 1186af69d88dSmrg case GL_LUMINANCE_ALPHA8UI_EXT: 1187af69d88dSmrg case GL_RGBA32I_EXT: 1188af69d88dSmrg case GL_RGB32I_EXT: 1189af69d88dSmrg case GL_RG32I: 1190af69d88dSmrg case GL_R32I: 1191af69d88dSmrg case GL_ALPHA32I_EXT: 1192af69d88dSmrg case GL_INTENSITY32I_EXT: 1193af69d88dSmrg case GL_LUMINANCE32I_EXT: 1194af69d88dSmrg case GL_LUMINANCE_ALPHA32I_EXT: 1195af69d88dSmrg case GL_RGBA16I_EXT: 1196af69d88dSmrg case GL_RGB16I_EXT: 1197af69d88dSmrg case GL_RG16I: 1198af69d88dSmrg case GL_R16I: 1199af69d88dSmrg case GL_ALPHA16I_EXT: 1200af69d88dSmrg case GL_INTENSITY16I_EXT: 1201af69d88dSmrg case GL_LUMINANCE16I_EXT: 1202af69d88dSmrg case GL_LUMINANCE_ALPHA16I_EXT: 1203af69d88dSmrg case GL_RGBA8I_EXT: 1204af69d88dSmrg case GL_RGB8I_EXT: 1205af69d88dSmrg case GL_RG8I: 1206af69d88dSmrg case GL_R8I: 1207af69d88dSmrg case GL_ALPHA8I_EXT: 1208af69d88dSmrg case GL_INTENSITY8I_EXT: 1209af69d88dSmrg case GL_LUMINANCE8I_EXT: 1210af69d88dSmrg case GL_LUMINANCE_ALPHA8I_EXT: 1211af69d88dSmrg /* signed, normalized texture formats */ 1212af69d88dSmrg case GL_RED_SNORM: 1213af69d88dSmrg case GL_R8_SNORM: 1214af69d88dSmrg case GL_R16_SNORM: 1215af69d88dSmrg case GL_RG_SNORM: 1216af69d88dSmrg case GL_RG8_SNORM: 1217af69d88dSmrg case GL_RG16_SNORM: 1218af69d88dSmrg case GL_RGB_SNORM: 1219af69d88dSmrg case GL_RGB8_SNORM: 1220af69d88dSmrg case GL_RGB16_SNORM: 1221af69d88dSmrg case GL_RGBA_SNORM: 1222af69d88dSmrg case GL_RGBA8_SNORM: 1223af69d88dSmrg case GL_RGBA16_SNORM: 1224af69d88dSmrg case GL_ALPHA_SNORM: 1225af69d88dSmrg case GL_ALPHA8_SNORM: 1226af69d88dSmrg case GL_ALPHA16_SNORM: 1227af69d88dSmrg case GL_LUMINANCE_SNORM: 1228af69d88dSmrg case GL_LUMINANCE8_SNORM: 1229af69d88dSmrg case GL_LUMINANCE16_SNORM: 1230af69d88dSmrg case GL_LUMINANCE_ALPHA_SNORM: 1231af69d88dSmrg case GL_LUMINANCE8_ALPHA8_SNORM: 1232af69d88dSmrg case GL_LUMINANCE16_ALPHA16_SNORM: 1233af69d88dSmrg case GL_INTENSITY_SNORM: 1234af69d88dSmrg case GL_INTENSITY8_SNORM: 1235af69d88dSmrg case GL_INTENSITY16_SNORM: 1236af69d88dSmrg case GL_RGB9_E5: 1237af69d88dSmrg case GL_R11F_G11F_B10F: 1238af69d88dSmrg case GL_RGB10_A2UI: 1239af69d88dSmrg return GL_TRUE; 1240af69d88dSmrg case GL_YCBCR_MESA: /* not considered to be RGB */ 12417ec681f3Smrg FALLTHROUGH; 1242af69d88dSmrg default: 1243af69d88dSmrg return GL_FALSE; 1244af69d88dSmrg } 1245af69d88dSmrg} 1246af69d88dSmrg 1247af69d88dSmrg 1248af69d88dSmrg/** 1249af69d88dSmrg * Test if the given image format is a depth component format. 1250af69d88dSmrg */ 1251af69d88dSmrgGLboolean 1252af69d88dSmrg_mesa_is_depth_format(GLenum format) 1253af69d88dSmrg{ 1254af69d88dSmrg switch (format) { 1255af69d88dSmrg case GL_DEPTH_COMPONENT: 1256af69d88dSmrg case GL_DEPTH_COMPONENT16: 1257af69d88dSmrg case GL_DEPTH_COMPONENT24: 1258af69d88dSmrg case GL_DEPTH_COMPONENT32: 1259af69d88dSmrg case GL_DEPTH_COMPONENT32F: 1260af69d88dSmrg return GL_TRUE; 1261af69d88dSmrg default: 1262af69d88dSmrg return GL_FALSE; 1263af69d88dSmrg } 1264af69d88dSmrg} 1265af69d88dSmrg 1266af69d88dSmrg 1267af69d88dSmrg/** 1268af69d88dSmrg * Test if the given image format is a stencil format. 1269af69d88dSmrg */ 1270af69d88dSmrgGLboolean 1271af69d88dSmrg_mesa_is_stencil_format(GLenum format) 1272af69d88dSmrg{ 1273af69d88dSmrg switch (format) { 1274af69d88dSmrg case GL_STENCIL_INDEX: 1275af69d88dSmrg return GL_TRUE; 1276af69d88dSmrg default: 1277af69d88dSmrg return GL_FALSE; 1278af69d88dSmrg } 1279af69d88dSmrg} 1280af69d88dSmrg 1281af69d88dSmrg 1282af69d88dSmrg/** 1283af69d88dSmrg * Test if the given image format is a YCbCr format. 1284af69d88dSmrg */ 1285af69d88dSmrgGLboolean 1286af69d88dSmrg_mesa_is_ycbcr_format(GLenum format) 1287af69d88dSmrg{ 1288af69d88dSmrg switch (format) { 1289af69d88dSmrg case GL_YCBCR_MESA: 1290af69d88dSmrg return GL_TRUE; 1291af69d88dSmrg default: 1292af69d88dSmrg return GL_FALSE; 1293af69d88dSmrg } 1294af69d88dSmrg} 1295af69d88dSmrg 1296af69d88dSmrg 1297af69d88dSmrg/** 1298af69d88dSmrg * Test if the given image format is a depth+stencil format. 1299af69d88dSmrg */ 1300af69d88dSmrgGLboolean 1301af69d88dSmrg_mesa_is_depthstencil_format(GLenum format) 1302af69d88dSmrg{ 1303af69d88dSmrg switch (format) { 1304af69d88dSmrg case GL_DEPTH24_STENCIL8_EXT: 1305af69d88dSmrg case GL_DEPTH_STENCIL_EXT: 1306af69d88dSmrg case GL_DEPTH32F_STENCIL8: 1307af69d88dSmrg return GL_TRUE; 1308af69d88dSmrg default: 1309af69d88dSmrg return GL_FALSE; 1310af69d88dSmrg } 1311af69d88dSmrg} 1312af69d88dSmrg 1313af69d88dSmrg 1314af69d88dSmrg/** 1315af69d88dSmrg * Test if the given image format is a depth or stencil format. 1316af69d88dSmrg */ 1317af69d88dSmrgGLboolean 1318af69d88dSmrg_mesa_is_depth_or_stencil_format(GLenum format) 1319af69d88dSmrg{ 1320af69d88dSmrg switch (format) { 1321af69d88dSmrg case GL_DEPTH_COMPONENT: 1322af69d88dSmrg case GL_DEPTH_COMPONENT16: 1323af69d88dSmrg case GL_DEPTH_COMPONENT24: 1324af69d88dSmrg case GL_DEPTH_COMPONENT32: 1325af69d88dSmrg case GL_STENCIL_INDEX: 1326af69d88dSmrg case GL_STENCIL_INDEX1_EXT: 1327af69d88dSmrg case GL_STENCIL_INDEX4_EXT: 1328af69d88dSmrg case GL_STENCIL_INDEX8_EXT: 1329af69d88dSmrg case GL_STENCIL_INDEX16_EXT: 1330af69d88dSmrg case GL_DEPTH_STENCIL_EXT: 1331af69d88dSmrg case GL_DEPTH24_STENCIL8_EXT: 1332af69d88dSmrg case GL_DEPTH_COMPONENT32F: 1333af69d88dSmrg case GL_DEPTH32F_STENCIL8: 1334af69d88dSmrg return GL_TRUE; 1335af69d88dSmrg default: 1336af69d88dSmrg return GL_FALSE; 1337af69d88dSmrg } 1338af69d88dSmrg} 1339af69d88dSmrg 13407ec681f3Smrg/** 13417ec681f3Smrg * Test if the given image format has a floating-point depth component. 13427ec681f3Smrg */ 13437ec681f3SmrgGLboolean 13447ec681f3Smrg_mesa_has_depth_float_channel(GLenum internalFormat) 13457ec681f3Smrg{ 13467ec681f3Smrg return internalFormat == GL_DEPTH32F_STENCIL8 || 13477ec681f3Smrg internalFormat == GL_DEPTH_COMPONENT32F; 13487ec681f3Smrg} 1349af69d88dSmrg 1350af69d88dSmrg/** 1351af69d88dSmrg * Test if an image format is a supported compressed format. 1352af69d88dSmrg * \param format the internal format token provided by the user. 1353af69d88dSmrg * \return GL_TRUE if compressed, GL_FALSE if uncompressed 1354af69d88dSmrg */ 1355af69d88dSmrgGLboolean 135601e04c3fSmrg_mesa_is_compressed_format(const struct gl_context *ctx, GLenum format) 1357af69d88dSmrg{ 135801e04c3fSmrg mesa_format m_format = _mesa_glenum_to_compressed_format(format); 135901e04c3fSmrg 136001e04c3fSmrg /* Some formats in this switch have an equivalent mesa_format_layout 136101e04c3fSmrg * to the compressed formats in the layout switch below and thus 136201e04c3fSmrg * must be handled first. 136301e04c3fSmrg */ 1364af69d88dSmrg switch (format) { 1365af69d88dSmrg case GL_RGB_S3TC: 1366af69d88dSmrg case GL_RGB4_S3TC: 1367af69d88dSmrg case GL_RGBA_S3TC: 1368af69d88dSmrg case GL_RGBA4_S3TC: 1369b9abf16eSmaya return _mesa_has_S3_s3tc(ctx); 1370af69d88dSmrg case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI: 1371b9abf16eSmaya return _mesa_has_ATI_texture_compression_3dc(ctx); 1372af69d88dSmrg case GL_PALETTE4_RGB8_OES: 1373af69d88dSmrg case GL_PALETTE4_RGBA8_OES: 1374af69d88dSmrg case GL_PALETTE4_R5_G6_B5_OES: 1375af69d88dSmrg case GL_PALETTE4_RGBA4_OES: 1376af69d88dSmrg case GL_PALETTE4_RGB5_A1_OES: 1377af69d88dSmrg case GL_PALETTE8_RGB8_OES: 1378af69d88dSmrg case GL_PALETTE8_RGBA8_OES: 1379af69d88dSmrg case GL_PALETTE8_R5_G6_B5_OES: 1380af69d88dSmrg case GL_PALETTE8_RGBA4_OES: 1381af69d88dSmrg case GL_PALETTE8_RGB5_A1_OES: 1382af69d88dSmrg return ctx->API == API_OPENGLES; 138301e04c3fSmrg } 138401e04c3fSmrg 138501e04c3fSmrg switch (_mesa_get_format_layout(m_format)) { 138601e04c3fSmrg case MESA_FORMAT_LAYOUT_S3TC: 13877ec681f3Smrg if (!_mesa_is_format_srgb(m_format)) { 1388b9abf16eSmaya return _mesa_has_EXT_texture_compression_s3tc(ctx); 138901e04c3fSmrg } else { 1390b9abf16eSmaya return (_mesa_has_EXT_texture_sRGB(ctx) || 1391b9abf16eSmaya _mesa_has_EXT_texture_compression_s3tc_srgb(ctx)) && 1392b9abf16eSmaya _mesa_has_EXT_texture_compression_s3tc(ctx); 139301e04c3fSmrg } 139401e04c3fSmrg case MESA_FORMAT_LAYOUT_FXT1: 1395b9abf16eSmaya return _mesa_has_3DFX_texture_compression_FXT1(ctx); 139601e04c3fSmrg case MESA_FORMAT_LAYOUT_RGTC: 1397b9abf16eSmaya return _mesa_has_ARB_texture_compression_rgtc(ctx) || 1398b9abf16eSmaya _mesa_has_EXT_texture_compression_rgtc(ctx); 139901e04c3fSmrg case MESA_FORMAT_LAYOUT_LATC: 1400b9abf16eSmaya return _mesa_has_EXT_texture_compression_latc(ctx); 140101e04c3fSmrg case MESA_FORMAT_LAYOUT_ETC1: 1402b9abf16eSmaya return _mesa_has_OES_compressed_ETC1_RGB8_texture(ctx); 140301e04c3fSmrg case MESA_FORMAT_LAYOUT_ETC2: 1404b9abf16eSmaya return _mesa_is_gles3(ctx) || _mesa_has_ARB_ES3_compatibility(ctx); 140501e04c3fSmrg case MESA_FORMAT_LAYOUT_BPTC: 1406b9abf16eSmaya return _mesa_has_ARB_texture_compression_bptc(ctx) || 1407b9abf16eSmaya _mesa_has_EXT_texture_compression_bptc(ctx); 140801e04c3fSmrg case MESA_FORMAT_LAYOUT_ASTC: 1409b9abf16eSmaya return _mesa_has_KHR_texture_compression_astc_ldr(ctx); 1410b9abf16eSmaya case MESA_FORMAT_LAYOUT_ATC: 1411b9abf16eSmaya return _mesa_has_AMD_compressed_ATC_texture(ctx); 1412af69d88dSmrg default: 1413af69d88dSmrg return GL_FALSE; 1414af69d88dSmrg } 1415af69d88dSmrg} 1416af69d88dSmrg 141701e04c3fSmrg/** 141801e04c3fSmrg * Test if the given format represents an sRGB format. 141901e04c3fSmrg * \param format the GL format (can be an internal format) 142001e04c3fSmrg * \return GL_TRUE if format is sRGB, GL_FALSE otherwise 142101e04c3fSmrg */ 142201e04c3fSmrgGLboolean 142301e04c3fSmrg_mesa_is_srgb_format(GLenum format) 142401e04c3fSmrg{ 142501e04c3fSmrg switch (format) { 14267ec681f3Smrg case GL_SR8_EXT: 14277ec681f3Smrg case GL_SRG8_EXT: 142801e04c3fSmrg case GL_SRGB: 142901e04c3fSmrg case GL_SRGB8: 143001e04c3fSmrg case GL_SRGB_ALPHA: 143101e04c3fSmrg case GL_SRGB8_ALPHA8: 143201e04c3fSmrg case GL_COMPRESSED_SRGB: 143301e04c3fSmrg case GL_COMPRESSED_SRGB_ALPHA: 143401e04c3fSmrg case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: 143501e04c3fSmrg case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 143601e04c3fSmrg case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 143701e04c3fSmrg case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 143801e04c3fSmrg case GL_COMPRESSED_SRGB8_ETC2: 143901e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 144001e04c3fSmrg case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 144101e04c3fSmrg case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM: 144201e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: 144301e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR: 144401e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR: 144501e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR: 144601e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR: 144701e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR: 144801e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR: 144901e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR: 145001e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR: 145101e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR: 145201e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR: 145301e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR: 145401e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR: 145501e04c3fSmrg case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: 145601e04c3fSmrg return GL_TRUE; 145701e04c3fSmrg default: 145801e04c3fSmrg break; 145901e04c3fSmrg } 146001e04c3fSmrg 146101e04c3fSmrg return GL_FALSE; 146201e04c3fSmrg} 146301e04c3fSmrg 146401e04c3fSmrg/** 146501e04c3fSmrg * Convert various unpack formats to the corresponding base format. 146601e04c3fSmrg */ 146701e04c3fSmrgGLenum 146801e04c3fSmrg_mesa_unpack_format_to_base_format(GLenum format) 146901e04c3fSmrg{ 147001e04c3fSmrg switch(format) { 147101e04c3fSmrg case GL_RED_INTEGER: 147201e04c3fSmrg return GL_RED; 147301e04c3fSmrg case GL_GREEN_INTEGER: 147401e04c3fSmrg return GL_GREEN; 147501e04c3fSmrg case GL_BLUE_INTEGER: 147601e04c3fSmrg return GL_BLUE; 147701e04c3fSmrg case GL_ALPHA_INTEGER: 147801e04c3fSmrg return GL_ALPHA; 147901e04c3fSmrg case GL_RG_INTEGER: 148001e04c3fSmrg return GL_RG; 148101e04c3fSmrg case GL_RGB_INTEGER: 148201e04c3fSmrg return GL_RGB; 148301e04c3fSmrg case GL_RGBA_INTEGER: 148401e04c3fSmrg return GL_RGBA; 148501e04c3fSmrg case GL_BGR_INTEGER: 148601e04c3fSmrg return GL_BGR; 148701e04c3fSmrg case GL_BGRA_INTEGER: 148801e04c3fSmrg return GL_BGRA; 148901e04c3fSmrg case GL_LUMINANCE_INTEGER_EXT: 149001e04c3fSmrg return GL_LUMINANCE; 149101e04c3fSmrg case GL_LUMINANCE_ALPHA_INTEGER_EXT: 149201e04c3fSmrg return GL_LUMINANCE_ALPHA; 149301e04c3fSmrg case GL_RED: 149401e04c3fSmrg case GL_GREEN: 149501e04c3fSmrg case GL_BLUE: 149601e04c3fSmrg case GL_RG: 149701e04c3fSmrg case GL_RGB: 149801e04c3fSmrg case GL_RGBA: 149901e04c3fSmrg case GL_BGR: 150001e04c3fSmrg case GL_BGRA: 150101e04c3fSmrg case GL_ALPHA: 150201e04c3fSmrg case GL_LUMINANCE: 150301e04c3fSmrg case GL_LUMINANCE_ALPHA: 150401e04c3fSmrg default: 150501e04c3fSmrg return format; 150601e04c3fSmrg } 150701e04c3fSmrg} 1508af69d88dSmrg 1509af69d88dSmrg/** 151001e04c3fSmrg * Convert various base formats to the corresponding integer format. 1511af69d88dSmrg */ 1512af69d88dSmrgGLenum 1513af69d88dSmrg_mesa_base_format_to_integer_format(GLenum format) 1514af69d88dSmrg{ 1515af69d88dSmrg switch(format) { 1516af69d88dSmrg case GL_RED: 1517af69d88dSmrg return GL_RED_INTEGER; 1518af69d88dSmrg case GL_GREEN: 1519af69d88dSmrg return GL_GREEN_INTEGER; 1520af69d88dSmrg case GL_BLUE: 1521af69d88dSmrg return GL_BLUE_INTEGER; 1522af69d88dSmrg case GL_RG: 1523af69d88dSmrg return GL_RG_INTEGER; 1524af69d88dSmrg case GL_RGB: 1525af69d88dSmrg return GL_RGB_INTEGER; 1526af69d88dSmrg case GL_RGBA: 1527af69d88dSmrg return GL_RGBA_INTEGER; 1528af69d88dSmrg case GL_BGR: 1529af69d88dSmrg return GL_BGR_INTEGER; 1530af69d88dSmrg case GL_BGRA: 1531af69d88dSmrg return GL_BGRA_INTEGER; 1532af69d88dSmrg case GL_ALPHA: 1533af69d88dSmrg return GL_ALPHA_INTEGER; 1534af69d88dSmrg case GL_LUMINANCE: 1535af69d88dSmrg return GL_LUMINANCE_INTEGER_EXT; 1536af69d88dSmrg case GL_LUMINANCE_ALPHA: 1537af69d88dSmrg return GL_LUMINANCE_ALPHA_INTEGER_EXT; 1538af69d88dSmrg } 1539af69d88dSmrg 1540af69d88dSmrg return format; 1541af69d88dSmrg} 1542af69d88dSmrg 1543af69d88dSmrg 1544af69d88dSmrg/** 1545af69d88dSmrg * Does the given base texture/renderbuffer format have the channel 1546af69d88dSmrg * named by 'pname'? 1547af69d88dSmrg */ 1548af69d88dSmrgGLboolean 1549af69d88dSmrg_mesa_base_format_has_channel(GLenum base_format, GLenum pname) 1550af69d88dSmrg{ 1551af69d88dSmrg switch (pname) { 1552af69d88dSmrg case GL_TEXTURE_RED_SIZE: 1553af69d88dSmrg case GL_TEXTURE_RED_TYPE: 1554af69d88dSmrg case GL_RENDERBUFFER_RED_SIZE_EXT: 1555af69d88dSmrg case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: 155601e04c3fSmrg case GL_INTERNALFORMAT_RED_SIZE: 155701e04c3fSmrg case GL_INTERNALFORMAT_RED_TYPE: 1558af69d88dSmrg if (base_format == GL_RED || 1559af69d88dSmrg base_format == GL_RG || 1560af69d88dSmrg base_format == GL_RGB || 1561af69d88dSmrg base_format == GL_RGBA) { 1562af69d88dSmrg return GL_TRUE; 1563af69d88dSmrg } 1564af69d88dSmrg return GL_FALSE; 1565af69d88dSmrg case GL_TEXTURE_GREEN_SIZE: 1566af69d88dSmrg case GL_TEXTURE_GREEN_TYPE: 1567af69d88dSmrg case GL_RENDERBUFFER_GREEN_SIZE_EXT: 1568af69d88dSmrg case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: 156901e04c3fSmrg case GL_INTERNALFORMAT_GREEN_SIZE: 157001e04c3fSmrg case GL_INTERNALFORMAT_GREEN_TYPE: 1571af69d88dSmrg if (base_format == GL_RG || 1572af69d88dSmrg base_format == GL_RGB || 1573af69d88dSmrg base_format == GL_RGBA) { 1574af69d88dSmrg return GL_TRUE; 1575af69d88dSmrg } 1576af69d88dSmrg return GL_FALSE; 1577af69d88dSmrg case GL_TEXTURE_BLUE_SIZE: 1578af69d88dSmrg case GL_TEXTURE_BLUE_TYPE: 1579af69d88dSmrg case GL_RENDERBUFFER_BLUE_SIZE_EXT: 1580af69d88dSmrg case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: 158101e04c3fSmrg case GL_INTERNALFORMAT_BLUE_SIZE: 158201e04c3fSmrg case GL_INTERNALFORMAT_BLUE_TYPE: 1583af69d88dSmrg if (base_format == GL_RGB || 1584af69d88dSmrg base_format == GL_RGBA) { 1585af69d88dSmrg return GL_TRUE; 1586af69d88dSmrg } 1587af69d88dSmrg return GL_FALSE; 1588af69d88dSmrg case GL_TEXTURE_ALPHA_SIZE: 1589af69d88dSmrg case GL_TEXTURE_ALPHA_TYPE: 1590af69d88dSmrg case GL_RENDERBUFFER_ALPHA_SIZE_EXT: 1591af69d88dSmrg case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: 159201e04c3fSmrg case GL_INTERNALFORMAT_ALPHA_SIZE: 159301e04c3fSmrg case GL_INTERNALFORMAT_ALPHA_TYPE: 1594af69d88dSmrg if (base_format == GL_RGBA || 1595af69d88dSmrg base_format == GL_ALPHA || 1596af69d88dSmrg base_format == GL_LUMINANCE_ALPHA) { 1597af69d88dSmrg return GL_TRUE; 1598af69d88dSmrg } 1599af69d88dSmrg return GL_FALSE; 1600af69d88dSmrg case GL_TEXTURE_LUMINANCE_SIZE: 1601af69d88dSmrg case GL_TEXTURE_LUMINANCE_TYPE: 1602af69d88dSmrg if (base_format == GL_LUMINANCE || 1603af69d88dSmrg base_format == GL_LUMINANCE_ALPHA) { 1604af69d88dSmrg return GL_TRUE; 1605af69d88dSmrg } 1606af69d88dSmrg return GL_FALSE; 1607af69d88dSmrg case GL_TEXTURE_INTENSITY_SIZE: 1608af69d88dSmrg case GL_TEXTURE_INTENSITY_TYPE: 1609af69d88dSmrg if (base_format == GL_INTENSITY) { 1610af69d88dSmrg return GL_TRUE; 1611af69d88dSmrg } 1612af69d88dSmrg return GL_FALSE; 1613af69d88dSmrg case GL_TEXTURE_DEPTH_SIZE: 1614af69d88dSmrg case GL_TEXTURE_DEPTH_TYPE: 1615af69d88dSmrg case GL_RENDERBUFFER_DEPTH_SIZE_EXT: 1616af69d88dSmrg case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: 161701e04c3fSmrg case GL_INTERNALFORMAT_DEPTH_SIZE: 161801e04c3fSmrg case GL_INTERNALFORMAT_DEPTH_TYPE: 1619af69d88dSmrg if (base_format == GL_DEPTH_STENCIL || 1620af69d88dSmrg base_format == GL_DEPTH_COMPONENT) { 1621af69d88dSmrg return GL_TRUE; 1622af69d88dSmrg } 1623af69d88dSmrg return GL_FALSE; 1624af69d88dSmrg case GL_RENDERBUFFER_STENCIL_SIZE_EXT: 1625af69d88dSmrg case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: 162601e04c3fSmrg case GL_INTERNALFORMAT_STENCIL_SIZE: 162701e04c3fSmrg case GL_INTERNALFORMAT_STENCIL_TYPE: 1628af69d88dSmrg if (base_format == GL_DEPTH_STENCIL || 1629af69d88dSmrg base_format == GL_STENCIL_INDEX) { 1630af69d88dSmrg return GL_TRUE; 1631af69d88dSmrg } 1632af69d88dSmrg return GL_FALSE; 1633af69d88dSmrg default: 1634af69d88dSmrg _mesa_warning(NULL, "%s: Unexpected channel token 0x%x\n", 163501e04c3fSmrg __func__, pname); 1636af69d88dSmrg return GL_FALSE; 1637af69d88dSmrg } 1638af69d88dSmrg 1639af69d88dSmrg return GL_FALSE; 1640af69d88dSmrg} 1641af69d88dSmrg 1642af69d88dSmrg 1643af69d88dSmrg/** 1644af69d88dSmrg * If format is a generic compressed format, return the corresponding 1645af69d88dSmrg * non-compressed format. For other formats, return the format as-is. 1646af69d88dSmrg */ 1647af69d88dSmrgGLenum 1648af69d88dSmrg_mesa_generic_compressed_format_to_uncompressed_format(GLenum format) 1649af69d88dSmrg{ 1650af69d88dSmrg switch (format) { 1651af69d88dSmrg case GL_COMPRESSED_RED: 1652af69d88dSmrg return GL_RED; 1653af69d88dSmrg case GL_COMPRESSED_RG: 1654af69d88dSmrg return GL_RG; 1655af69d88dSmrg case GL_COMPRESSED_RGB: 1656af69d88dSmrg return GL_RGB; 1657af69d88dSmrg case GL_COMPRESSED_RGBA: 1658af69d88dSmrg return GL_RGBA; 1659af69d88dSmrg case GL_COMPRESSED_ALPHA: 1660af69d88dSmrg return GL_ALPHA; 1661af69d88dSmrg case GL_COMPRESSED_LUMINANCE: 1662af69d88dSmrg return GL_LUMINANCE; 1663af69d88dSmrg case GL_COMPRESSED_LUMINANCE_ALPHA: 1664af69d88dSmrg return GL_LUMINANCE_ALPHA; 1665af69d88dSmrg case GL_COMPRESSED_INTENSITY: 1666af69d88dSmrg return GL_INTENSITY; 1667af69d88dSmrg /* sRGB formats */ 1668af69d88dSmrg case GL_COMPRESSED_SRGB: 1669af69d88dSmrg return GL_SRGB; 1670af69d88dSmrg case GL_COMPRESSED_SRGB_ALPHA: 1671af69d88dSmrg return GL_SRGB_ALPHA; 1672af69d88dSmrg case GL_COMPRESSED_SLUMINANCE: 1673af69d88dSmrg return GL_SLUMINANCE; 1674af69d88dSmrg case GL_COMPRESSED_SLUMINANCE_ALPHA: 1675af69d88dSmrg return GL_SLUMINANCE_ALPHA; 1676af69d88dSmrg default: 1677af69d88dSmrg return format; 1678af69d88dSmrg } 1679af69d88dSmrg} 1680af69d88dSmrg 1681af69d88dSmrg 1682af69d88dSmrg/** 1683af69d88dSmrg * Return the equivalent non-generic internal format. 1684af69d88dSmrg * This is useful for comparing whether two internal formats are equivalent. 1685af69d88dSmrg */ 1686af69d88dSmrgGLenum 1687af69d88dSmrg_mesa_get_nongeneric_internalformat(GLenum format) 1688af69d88dSmrg{ 1689af69d88dSmrg switch (format) { 1690af69d88dSmrg /* GL 1.1 formats. */ 1691af69d88dSmrg case 4: 1692af69d88dSmrg case GL_RGBA: 1693af69d88dSmrg return GL_RGBA8; 1694af69d88dSmrg case 3: 1695af69d88dSmrg case GL_RGB: 1696af69d88dSmrg return GL_RGB8; 1697af69d88dSmrg case 2: 1698af69d88dSmrg case GL_LUMINANCE_ALPHA: 1699af69d88dSmrg return GL_LUMINANCE8_ALPHA8; 1700af69d88dSmrg case 1: 1701af69d88dSmrg case GL_LUMINANCE: 1702af69d88dSmrg return GL_LUMINANCE8; 1703af69d88dSmrg case GL_ALPHA: 1704af69d88dSmrg return GL_ALPHA8; 1705af69d88dSmrg case GL_INTENSITY: 1706af69d88dSmrg return GL_INTENSITY8; 1707af69d88dSmrg 1708af69d88dSmrg /* GL_ARB_texture_rg */ 1709af69d88dSmrg case GL_RED: 1710af69d88dSmrg return GL_R8; 1711af69d88dSmrg case GL_RG: 1712af69d88dSmrg return GL_RG8; 1713af69d88dSmrg 1714af69d88dSmrg /* GL_EXT_texture_sRGB */ 1715af69d88dSmrg case GL_SRGB: 1716af69d88dSmrg return GL_SRGB8; 1717af69d88dSmrg case GL_SRGB_ALPHA: 1718af69d88dSmrg return GL_SRGB8_ALPHA8; 1719af69d88dSmrg case GL_SLUMINANCE: 1720af69d88dSmrg return GL_SLUMINANCE8; 1721af69d88dSmrg case GL_SLUMINANCE_ALPHA: 1722af69d88dSmrg return GL_SLUMINANCE8_ALPHA8; 1723af69d88dSmrg 1724af69d88dSmrg /* GL_EXT_texture_snorm */ 1725af69d88dSmrg case GL_RGBA_SNORM: 1726af69d88dSmrg return GL_RGBA8_SNORM; 1727af69d88dSmrg case GL_RGB_SNORM: 1728af69d88dSmrg return GL_RGB8_SNORM; 1729af69d88dSmrg case GL_RG_SNORM: 1730af69d88dSmrg return GL_RG8_SNORM; 1731af69d88dSmrg case GL_RED_SNORM: 1732af69d88dSmrg return GL_R8_SNORM; 1733af69d88dSmrg case GL_LUMINANCE_ALPHA_SNORM: 1734af69d88dSmrg return GL_LUMINANCE8_ALPHA8_SNORM; 1735af69d88dSmrg case GL_LUMINANCE_SNORM: 1736af69d88dSmrg return GL_LUMINANCE8_SNORM; 1737af69d88dSmrg case GL_ALPHA_SNORM: 1738af69d88dSmrg return GL_ALPHA8_SNORM; 1739af69d88dSmrg case GL_INTENSITY_SNORM: 1740af69d88dSmrg return GL_INTENSITY8_SNORM; 1741af69d88dSmrg 1742af69d88dSmrg default: 1743af69d88dSmrg return format; 1744af69d88dSmrg } 1745af69d88dSmrg} 1746af69d88dSmrg 1747af69d88dSmrg 1748af69d88dSmrg/** 1749af69d88dSmrg * Convert an sRGB internal format to linear. 1750af69d88dSmrg */ 1751af69d88dSmrgGLenum 1752af69d88dSmrg_mesa_get_linear_internalformat(GLenum format) 1753af69d88dSmrg{ 1754af69d88dSmrg switch (format) { 1755af69d88dSmrg case GL_SRGB: 1756af69d88dSmrg return GL_RGB; 1757af69d88dSmrg case GL_SRGB_ALPHA: 1758af69d88dSmrg return GL_RGBA; 1759af69d88dSmrg case GL_SRGB8: 1760af69d88dSmrg return GL_RGB8; 1761af69d88dSmrg case GL_SRGB8_ALPHA8: 1762af69d88dSmrg return GL_RGBA8; 1763af69d88dSmrg case GL_SLUMINANCE8: 1764af69d88dSmrg return GL_LUMINANCE8; 1765af69d88dSmrg case GL_SLUMINANCE: 1766af69d88dSmrg return GL_LUMINANCE; 1767af69d88dSmrg case GL_SLUMINANCE_ALPHA: 1768af69d88dSmrg return GL_LUMINANCE_ALPHA; 1769af69d88dSmrg case GL_SLUMINANCE8_ALPHA8: 1770af69d88dSmrg return GL_LUMINANCE8_ALPHA8; 1771af69d88dSmrg default: 1772af69d88dSmrg return format; 1773af69d88dSmrg } 1774af69d88dSmrg} 1775af69d88dSmrg 1776af69d88dSmrg 1777af69d88dSmrg/** 1778af69d88dSmrg * Do error checking of format/type combinations for glReadPixels, 1779af69d88dSmrg * glDrawPixels and glTex[Sub]Image. Note that depending on the format 1780af69d88dSmrg * and type values, we may either generate GL_INVALID_OPERATION or 1781af69d88dSmrg * GL_INVALID_ENUM. 1782af69d88dSmrg * 1783af69d88dSmrg * \param format pixel format. 1784af69d88dSmrg * \param type pixel type. 1785af69d88dSmrg * 1786af69d88dSmrg * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR 1787af69d88dSmrg */ 1788af69d88dSmrgGLenum 1789af69d88dSmrg_mesa_error_check_format_and_type(const struct gl_context *ctx, 1790af69d88dSmrg GLenum format, GLenum type) 1791af69d88dSmrg{ 1792af69d88dSmrg /* From OpenGL 3.3 spec, page 220: 1793af69d88dSmrg * "If the format is DEPTH_STENCIL, then values are taken from 1794af69d88dSmrg * both the depth buffer and the stencil buffer. If there is no 1795af69d88dSmrg * depth buffer or if there is no stencil buffer, then the error 1796af69d88dSmrg * INVALID_OPERATION occurs. If the type parameter is not 1797af69d88dSmrg * UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the 1798af69d88dSmrg * error INVALID_ENUM occurs." 1799af69d88dSmrg * 1800af69d88dSmrg * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels 1801af69d88dSmrg * cannot be used to read depth or stencil in that API. 1802af69d88dSmrg */ 1803af69d88dSmrg if (_mesa_is_desktop_gl(ctx) && format == GL_DEPTH_STENCIL 1804af69d88dSmrg && type != GL_UNSIGNED_INT_24_8 1805af69d88dSmrg && type != GL_FLOAT_32_UNSIGNED_INT_24_8_REV) 1806af69d88dSmrg return GL_INVALID_ENUM; 1807af69d88dSmrg 1808af69d88dSmrg /* special type-based checks (see glReadPixels, glDrawPixels error lists) */ 1809af69d88dSmrg switch (type) { 1810af69d88dSmrg case GL_BITMAP: 1811af69d88dSmrg if (format != GL_COLOR_INDEX && format != GL_STENCIL_INDEX) { 1812af69d88dSmrg return GL_INVALID_ENUM; 1813af69d88dSmrg } 1814af69d88dSmrg break; 1815af69d88dSmrg 1816af69d88dSmrg case GL_UNSIGNED_BYTE_3_3_2: 1817af69d88dSmrg case GL_UNSIGNED_BYTE_2_3_3_REV: 1818af69d88dSmrg case GL_UNSIGNED_SHORT_5_6_5: 1819af69d88dSmrg case GL_UNSIGNED_SHORT_5_6_5_REV: 1820af69d88dSmrg if (format == GL_RGB) { 1821af69d88dSmrg break; /* OK */ 1822af69d88dSmrg } 1823af69d88dSmrg if (format == GL_RGB_INTEGER_EXT && 1824b9abf16eSmaya _mesa_has_texture_rgb10_a2ui(ctx)) { 1825af69d88dSmrg break; /* OK */ 1826af69d88dSmrg } 1827af69d88dSmrg return GL_INVALID_OPERATION; 1828af69d88dSmrg 1829af69d88dSmrg case GL_UNSIGNED_SHORT_4_4_4_4: 1830af69d88dSmrg case GL_UNSIGNED_SHORT_4_4_4_4_REV: 1831af69d88dSmrg case GL_UNSIGNED_INT_8_8_8_8: 1832af69d88dSmrg case GL_UNSIGNED_INT_8_8_8_8_REV: 1833af69d88dSmrg if (format == GL_RGBA || 1834af69d88dSmrg format == GL_BGRA || 1835af69d88dSmrg format == GL_ABGR_EXT) { 1836af69d88dSmrg break; /* OK */ 1837af69d88dSmrg } 1838af69d88dSmrg if ((format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT) && 1839b9abf16eSmaya _mesa_has_texture_rgb10_a2ui(ctx)) { 1840af69d88dSmrg break; /* OK */ 1841af69d88dSmrg } 184201e04c3fSmrg return GL_INVALID_OPERATION; 184301e04c3fSmrg 184401e04c3fSmrg case GL_UNSIGNED_SHORT_5_5_5_1: 184501e04c3fSmrg case GL_UNSIGNED_SHORT_1_5_5_5_REV: 184601e04c3fSmrg case GL_UNSIGNED_INT_10_10_10_2: 184701e04c3fSmrg case GL_UNSIGNED_INT_2_10_10_10_REV: 184801e04c3fSmrg if (format == GL_RGBA || 184901e04c3fSmrg format == GL_BGRA) { 185001e04c3fSmrg break; /* OK */ 185101e04c3fSmrg } 185201e04c3fSmrg if ((format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT) && 1853b9abf16eSmaya _mesa_has_texture_rgb10_a2ui(ctx)) { 185401e04c3fSmrg break; /* OK */ 185501e04c3fSmrg } 1856af69d88dSmrg if (type == GL_UNSIGNED_INT_2_10_10_10_REV && format == GL_RGB && 1857af69d88dSmrg ctx->API == API_OPENGLES2) { 1858af69d88dSmrg break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */ 1859af69d88dSmrg } 1860af69d88dSmrg return GL_INVALID_OPERATION; 1861af69d88dSmrg 1862af69d88dSmrg case GL_UNSIGNED_INT_24_8: 186301e04c3fSmrg /* Depth buffer OK to read in OpenGL ES (NV_read_depth). */ 186401e04c3fSmrg if (ctx->API == API_OPENGLES2 && format == GL_DEPTH_COMPONENT) 186501e04c3fSmrg return GL_NO_ERROR; 186601e04c3fSmrg 1867af69d88dSmrg if (format != GL_DEPTH_STENCIL) { 1868af69d88dSmrg return GL_INVALID_OPERATION; 1869af69d88dSmrg } 1870af69d88dSmrg return GL_NO_ERROR; 1871af69d88dSmrg 1872af69d88dSmrg case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: 1873b9abf16eSmaya if (!_mesa_has_float_depth_buffer(ctx)) { 1874af69d88dSmrg return GL_INVALID_ENUM; 1875af69d88dSmrg } 1876af69d88dSmrg if (format != GL_DEPTH_STENCIL) { 1877af69d88dSmrg return GL_INVALID_OPERATION; 1878af69d88dSmrg } 1879af69d88dSmrg return GL_NO_ERROR; 1880af69d88dSmrg 1881af69d88dSmrg case GL_UNSIGNED_INT_10F_11F_11F_REV: 1882b9abf16eSmaya if (!_mesa_has_packed_float(ctx)) { 1883af69d88dSmrg return GL_INVALID_ENUM; 1884af69d88dSmrg } 1885af69d88dSmrg if (format != GL_RGB) { 1886af69d88dSmrg return GL_INVALID_OPERATION; 1887af69d88dSmrg } 1888af69d88dSmrg return GL_NO_ERROR; 1889af69d88dSmrg 189001e04c3fSmrg case GL_HALF_FLOAT_OES: 189101e04c3fSmrg switch (format) { 189201e04c3fSmrg case GL_RGBA: 189301e04c3fSmrg case GL_RGB: 189401e04c3fSmrg case GL_LUMINANCE_ALPHA: 189501e04c3fSmrg case GL_LUMINANCE: 189601e04c3fSmrg case GL_ALPHA: 189701e04c3fSmrg return GL_NO_ERROR; 189801e04c3fSmrg case GL_RG: 189901e04c3fSmrg case GL_RED: 1900b9abf16eSmaya if (_mesa_has_rg_textures(ctx)) 190101e04c3fSmrg return GL_NO_ERROR; 19027ec681f3Smrg FALLTHROUGH; 190301e04c3fSmrg default: 190401e04c3fSmrg return GL_INVALID_OPERATION; 190501e04c3fSmrg } 190601e04c3fSmrg 1907af69d88dSmrg default: 1908af69d88dSmrg ; /* fall-through */ 1909af69d88dSmrg } 1910af69d88dSmrg 1911af69d88dSmrg /* now, for each format, check the type for compatibility */ 1912af69d88dSmrg switch (format) { 1913af69d88dSmrg case GL_COLOR_INDEX: 1914af69d88dSmrg case GL_STENCIL_INDEX: 1915af69d88dSmrg switch (type) { 1916af69d88dSmrg case GL_BITMAP: 1917af69d88dSmrg case GL_BYTE: 1918af69d88dSmrg case GL_UNSIGNED_BYTE: 1919af69d88dSmrg case GL_SHORT: 1920af69d88dSmrg case GL_UNSIGNED_SHORT: 1921af69d88dSmrg case GL_INT: 1922af69d88dSmrg case GL_UNSIGNED_INT: 1923af69d88dSmrg case GL_FLOAT: 1924af69d88dSmrg case GL_HALF_FLOAT: 1925af69d88dSmrg return GL_NO_ERROR; 1926af69d88dSmrg default: 1927af69d88dSmrg return GL_INVALID_ENUM; 1928af69d88dSmrg } 1929af69d88dSmrg 1930af69d88dSmrg case GL_RED: 1931af69d88dSmrg case GL_GREEN: 1932af69d88dSmrg case GL_BLUE: 1933af69d88dSmrg case GL_ALPHA: 1934af69d88dSmrg#if 0 /* not legal! see table 3.6 of the 1.5 spec */ 1935af69d88dSmrg case GL_INTENSITY: 1936af69d88dSmrg#endif 1937af69d88dSmrg case GL_LUMINANCE: 1938af69d88dSmrg case GL_LUMINANCE_ALPHA: 1939af69d88dSmrg case GL_DEPTH_COMPONENT: 1940af69d88dSmrg switch (type) { 1941af69d88dSmrg case GL_BYTE: 1942af69d88dSmrg case GL_UNSIGNED_BYTE: 1943af69d88dSmrg case GL_SHORT: 1944af69d88dSmrg case GL_UNSIGNED_SHORT: 1945af69d88dSmrg case GL_INT: 1946af69d88dSmrg case GL_UNSIGNED_INT: 1947af69d88dSmrg case GL_FLOAT: 1948af69d88dSmrg case GL_HALF_FLOAT: 1949af69d88dSmrg return GL_NO_ERROR; 1950af69d88dSmrg default: 1951af69d88dSmrg return GL_INVALID_ENUM; 1952af69d88dSmrg } 1953af69d88dSmrg 1954af69d88dSmrg case GL_RG: 1955b9abf16eSmaya if (!_mesa_has_rg_textures(ctx)) 1956b9abf16eSmaya return GL_INVALID_ENUM; 1957af69d88dSmrg switch (type) { 1958af69d88dSmrg case GL_BYTE: 1959af69d88dSmrg case GL_UNSIGNED_BYTE: 1960af69d88dSmrg case GL_SHORT: 1961af69d88dSmrg case GL_UNSIGNED_SHORT: 1962af69d88dSmrg case GL_INT: 1963af69d88dSmrg case GL_UNSIGNED_INT: 1964af69d88dSmrg case GL_FLOAT: 1965af69d88dSmrg case GL_HALF_FLOAT: 1966af69d88dSmrg return GL_NO_ERROR; 1967af69d88dSmrg default: 1968af69d88dSmrg return GL_INVALID_ENUM; 1969af69d88dSmrg } 1970af69d88dSmrg 1971af69d88dSmrg case GL_RGB: 1972af69d88dSmrg switch (type) { 1973af69d88dSmrg case GL_BYTE: 1974af69d88dSmrg case GL_UNSIGNED_BYTE: 1975af69d88dSmrg case GL_SHORT: 1976af69d88dSmrg case GL_UNSIGNED_SHORT: 1977af69d88dSmrg case GL_INT: 1978af69d88dSmrg case GL_UNSIGNED_INT: 1979af69d88dSmrg case GL_FLOAT: 1980af69d88dSmrg case GL_UNSIGNED_BYTE_3_3_2: 1981af69d88dSmrg case GL_UNSIGNED_BYTE_2_3_3_REV: 1982af69d88dSmrg case GL_UNSIGNED_SHORT_5_6_5: 1983af69d88dSmrg case GL_UNSIGNED_SHORT_5_6_5_REV: 1984af69d88dSmrg case GL_HALF_FLOAT: 1985af69d88dSmrg return GL_NO_ERROR; 1986af69d88dSmrg case GL_UNSIGNED_INT_2_10_10_10_REV: 1987af69d88dSmrg /* OK by GL_EXT_texture_type_2_10_10_10_REV */ 1988af69d88dSmrg return (ctx->API == API_OPENGLES2) 1989af69d88dSmrg ? GL_NO_ERROR : GL_INVALID_ENUM; 1990af69d88dSmrg case GL_UNSIGNED_INT_5_9_9_9_REV: 1991b9abf16eSmaya return _mesa_has_texture_shared_exponent(ctx) 1992af69d88dSmrg ? GL_NO_ERROR : GL_INVALID_ENUM; 1993af69d88dSmrg case GL_UNSIGNED_INT_10F_11F_11F_REV: 1994b9abf16eSmaya return _mesa_has_packed_float(ctx) 1995af69d88dSmrg ? GL_NO_ERROR : GL_INVALID_ENUM; 1996af69d88dSmrg default: 1997af69d88dSmrg return GL_INVALID_ENUM; 1998af69d88dSmrg } 1999af69d88dSmrg 2000af69d88dSmrg case GL_BGR: 2001af69d88dSmrg switch (type) { 2002af69d88dSmrg /* NOTE: no packed types are supported with BGR. That's 2003af69d88dSmrg * intentional, according to the GL spec. 2004af69d88dSmrg */ 2005af69d88dSmrg case GL_BYTE: 2006af69d88dSmrg case GL_UNSIGNED_BYTE: 2007af69d88dSmrg case GL_SHORT: 2008af69d88dSmrg case GL_UNSIGNED_SHORT: 2009af69d88dSmrg case GL_INT: 2010af69d88dSmrg case GL_UNSIGNED_INT: 2011af69d88dSmrg case GL_FLOAT: 2012af69d88dSmrg case GL_HALF_FLOAT: 2013af69d88dSmrg return GL_NO_ERROR; 2014af69d88dSmrg default: 2015af69d88dSmrg return GL_INVALID_ENUM; 2016af69d88dSmrg } 2017af69d88dSmrg 2018af69d88dSmrg case GL_RGBA: 2019af69d88dSmrg case GL_BGRA: 2020af69d88dSmrg switch (type) { 2021af69d88dSmrg case GL_BYTE: 2022af69d88dSmrg case GL_UNSIGNED_BYTE: 2023af69d88dSmrg case GL_SHORT: 2024af69d88dSmrg case GL_UNSIGNED_SHORT: 2025af69d88dSmrg case GL_INT: 2026af69d88dSmrg case GL_UNSIGNED_INT: 2027af69d88dSmrg case GL_FLOAT: 2028af69d88dSmrg case GL_UNSIGNED_SHORT_4_4_4_4: 2029af69d88dSmrg case GL_UNSIGNED_SHORT_4_4_4_4_REV: 2030af69d88dSmrg case GL_UNSIGNED_SHORT_5_5_5_1: 2031af69d88dSmrg case GL_UNSIGNED_SHORT_1_5_5_5_REV: 2032af69d88dSmrg case GL_UNSIGNED_INT_8_8_8_8: 2033af69d88dSmrg case GL_UNSIGNED_INT_8_8_8_8_REV: 2034af69d88dSmrg case GL_UNSIGNED_INT_10_10_10_2: 2035af69d88dSmrg case GL_UNSIGNED_INT_2_10_10_10_REV: 2036af69d88dSmrg case GL_HALF_FLOAT: 2037af69d88dSmrg return GL_NO_ERROR; 2038af69d88dSmrg default: 2039af69d88dSmrg return GL_INVALID_ENUM; 2040af69d88dSmrg } 2041af69d88dSmrg 204201e04c3fSmrg case GL_ABGR_EXT: 204301e04c3fSmrg switch (type) { 204401e04c3fSmrg case GL_BYTE: 204501e04c3fSmrg case GL_UNSIGNED_BYTE: 204601e04c3fSmrg case GL_SHORT: 204701e04c3fSmrg case GL_UNSIGNED_SHORT: 204801e04c3fSmrg case GL_INT: 204901e04c3fSmrg case GL_UNSIGNED_INT: 205001e04c3fSmrg case GL_FLOAT: 205101e04c3fSmrg case GL_UNSIGNED_SHORT_4_4_4_4: 205201e04c3fSmrg case GL_UNSIGNED_SHORT_4_4_4_4_REV: 205301e04c3fSmrg case GL_UNSIGNED_INT_8_8_8_8: 205401e04c3fSmrg case GL_UNSIGNED_INT_8_8_8_8_REV: 205501e04c3fSmrg case GL_HALF_FLOAT: 205601e04c3fSmrg return GL_NO_ERROR; 205701e04c3fSmrg default: 205801e04c3fSmrg return GL_INVALID_ENUM; 205901e04c3fSmrg } 206001e04c3fSmrg 206101e04c3fSmrg case GL_YCBCR_MESA: 2062b9abf16eSmaya if (!_mesa_has_MESA_ycbcr_texture(ctx)) 206301e04c3fSmrg return GL_INVALID_ENUM; 206401e04c3fSmrg if (type == GL_UNSIGNED_SHORT_8_8_MESA || 206501e04c3fSmrg type == GL_UNSIGNED_SHORT_8_8_REV_MESA) 206601e04c3fSmrg return GL_NO_ERROR; 206701e04c3fSmrg else 2068af69d88dSmrg return GL_INVALID_OPERATION; 2069af69d88dSmrg 2070af69d88dSmrg case GL_DEPTH_STENCIL: 2071af69d88dSmrg if (type == GL_UNSIGNED_INT_24_8) 2072af69d88dSmrg return GL_NO_ERROR; 2073b9abf16eSmaya else if (_mesa_has_float_depth_buffer(ctx) && 2074af69d88dSmrg type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV) 2075af69d88dSmrg return GL_NO_ERROR; 2076af69d88dSmrg else 2077af69d88dSmrg return GL_INVALID_ENUM; 2078af69d88dSmrg 2079af69d88dSmrg /* integer-valued formats */ 2080af69d88dSmrg case GL_RED_INTEGER_EXT: 2081af69d88dSmrg case GL_GREEN_INTEGER_EXT: 2082af69d88dSmrg case GL_BLUE_INTEGER_EXT: 2083af69d88dSmrg case GL_ALPHA_INTEGER_EXT: 2084af69d88dSmrg case GL_RG_INTEGER: 2085af69d88dSmrg switch (type) { 2086af69d88dSmrg case GL_BYTE: 2087af69d88dSmrg case GL_UNSIGNED_BYTE: 2088af69d88dSmrg case GL_SHORT: 2089af69d88dSmrg case GL_UNSIGNED_SHORT: 2090af69d88dSmrg case GL_INT: 2091af69d88dSmrg case GL_UNSIGNED_INT: 2092b9abf16eSmaya return _mesa_has_integer_textures(ctx) 2093af69d88dSmrg ? GL_NO_ERROR : GL_INVALID_ENUM; 2094af69d88dSmrg default: 2095af69d88dSmrg return GL_INVALID_ENUM; 2096af69d88dSmrg } 2097af69d88dSmrg 2098af69d88dSmrg case GL_RGB_INTEGER_EXT: 2099af69d88dSmrg switch (type) { 2100af69d88dSmrg case GL_BYTE: 2101af69d88dSmrg case GL_UNSIGNED_BYTE: 2102af69d88dSmrg case GL_SHORT: 2103af69d88dSmrg case GL_UNSIGNED_SHORT: 2104af69d88dSmrg case GL_INT: 2105af69d88dSmrg case GL_UNSIGNED_INT: 2106b9abf16eSmaya return _mesa_has_integer_textures(ctx) 2107af69d88dSmrg ? GL_NO_ERROR : GL_INVALID_ENUM; 2108af69d88dSmrg case GL_UNSIGNED_BYTE_3_3_2: 2109af69d88dSmrg case GL_UNSIGNED_BYTE_2_3_3_REV: 2110af69d88dSmrg case GL_UNSIGNED_SHORT_5_6_5: 2111af69d88dSmrg case GL_UNSIGNED_SHORT_5_6_5_REV: 2112b9abf16eSmaya return _mesa_has_texture_rgb10_a2ui(ctx) 2113af69d88dSmrg ? GL_NO_ERROR : GL_INVALID_ENUM; 2114af69d88dSmrg default: 2115af69d88dSmrg return GL_INVALID_ENUM; 2116af69d88dSmrg } 2117af69d88dSmrg 2118af69d88dSmrg case GL_BGR_INTEGER_EXT: 2119af69d88dSmrg switch (type) { 2120af69d88dSmrg case GL_BYTE: 2121af69d88dSmrg case GL_UNSIGNED_BYTE: 2122af69d88dSmrg case GL_SHORT: 2123af69d88dSmrg case GL_UNSIGNED_SHORT: 2124af69d88dSmrg case GL_INT: 2125af69d88dSmrg case GL_UNSIGNED_INT: 2126af69d88dSmrg /* NOTE: no packed formats w/ BGR format */ 2127b9abf16eSmaya return _mesa_has_integer_textures(ctx) 2128af69d88dSmrg ? GL_NO_ERROR : GL_INVALID_ENUM; 2129af69d88dSmrg default: 2130af69d88dSmrg return GL_INVALID_ENUM; 2131af69d88dSmrg } 2132af69d88dSmrg 2133af69d88dSmrg case GL_RGBA_INTEGER_EXT: 2134af69d88dSmrg case GL_BGRA_INTEGER_EXT: 2135af69d88dSmrg switch (type) { 2136af69d88dSmrg case GL_BYTE: 2137af69d88dSmrg case GL_UNSIGNED_BYTE: 2138af69d88dSmrg case GL_SHORT: 2139af69d88dSmrg case GL_UNSIGNED_SHORT: 2140af69d88dSmrg case GL_INT: 2141af69d88dSmrg case GL_UNSIGNED_INT: 2142b9abf16eSmaya return _mesa_has_integer_textures(ctx) 2143af69d88dSmrg ? GL_NO_ERROR : GL_INVALID_ENUM; 2144af69d88dSmrg case GL_UNSIGNED_SHORT_4_4_4_4: 2145af69d88dSmrg case GL_UNSIGNED_SHORT_4_4_4_4_REV: 2146af69d88dSmrg case GL_UNSIGNED_SHORT_5_5_5_1: 2147af69d88dSmrg case GL_UNSIGNED_SHORT_1_5_5_5_REV: 2148af69d88dSmrg case GL_UNSIGNED_INT_8_8_8_8: 2149af69d88dSmrg case GL_UNSIGNED_INT_8_8_8_8_REV: 2150af69d88dSmrg case GL_UNSIGNED_INT_10_10_10_2: 2151af69d88dSmrg case GL_UNSIGNED_INT_2_10_10_10_REV: 2152b9abf16eSmaya return _mesa_has_texture_rgb10_a2ui(ctx) 2153af69d88dSmrg ? GL_NO_ERROR : GL_INVALID_ENUM; 2154af69d88dSmrg default: 2155af69d88dSmrg return GL_INVALID_ENUM; 2156af69d88dSmrg } 2157af69d88dSmrg 2158af69d88dSmrg case GL_LUMINANCE_INTEGER_EXT: 2159af69d88dSmrg case GL_LUMINANCE_ALPHA_INTEGER_EXT: 2160af69d88dSmrg switch (type) { 2161af69d88dSmrg case GL_BYTE: 2162af69d88dSmrg case GL_UNSIGNED_BYTE: 2163af69d88dSmrg case GL_SHORT: 2164af69d88dSmrg case GL_UNSIGNED_SHORT: 2165af69d88dSmrg case GL_INT: 2166af69d88dSmrg case GL_UNSIGNED_INT: 2167b9abf16eSmaya return _mesa_has_integer_textures(ctx) 2168af69d88dSmrg ? GL_NO_ERROR : GL_INVALID_ENUM; 2169af69d88dSmrg default: 2170af69d88dSmrg return GL_INVALID_ENUM; 2171af69d88dSmrg } 2172af69d88dSmrg 2173af69d88dSmrg default: 2174af69d88dSmrg return GL_INVALID_ENUM; 2175af69d88dSmrg } 2176af69d88dSmrg return GL_NO_ERROR; 2177af69d88dSmrg} 2178af69d88dSmrg 2179af69d88dSmrg 2180af69d88dSmrg/** 2181af69d88dSmrg * Do error checking of format/type combinations for OpenGL ES glReadPixels 2182af69d88dSmrg * and glTex[Sub]Image. 2183af69d88dSmrg * \return error code, or GL_NO_ERROR. 2184af69d88dSmrg */ 2185af69d88dSmrgGLenum 218601e04c3fSmrg_mesa_es_error_check_format_and_type(const struct gl_context *ctx, 218701e04c3fSmrg GLenum format, GLenum type, 2188af69d88dSmrg unsigned dimensions) 2189af69d88dSmrg{ 2190af69d88dSmrg GLboolean type_valid = GL_TRUE; 2191af69d88dSmrg 2192af69d88dSmrg switch (format) { 219301e04c3fSmrg case GL_RED: 219401e04c3fSmrg case GL_RG: 2195b9abf16eSmaya if (!_mesa_has_rg_textures(ctx)) 219601e04c3fSmrg return GL_INVALID_VALUE; 21977ec681f3Smrg FALLTHROUGH; 2198af69d88dSmrg case GL_ALPHA: 2199af69d88dSmrg case GL_LUMINANCE: 2200af69d88dSmrg case GL_LUMINANCE_ALPHA: 2201af69d88dSmrg type_valid = (type == GL_UNSIGNED_BYTE 2202af69d88dSmrg || type == GL_FLOAT 2203af69d88dSmrg || type == GL_HALF_FLOAT_OES); 2204af69d88dSmrg break; 2205af69d88dSmrg 2206af69d88dSmrg case GL_RGB: 2207af69d88dSmrg type_valid = (type == GL_UNSIGNED_BYTE 2208af69d88dSmrg || type == GL_UNSIGNED_SHORT_5_6_5 2209af69d88dSmrg || type == GL_FLOAT 2210af69d88dSmrg || type == GL_HALF_FLOAT_OES); 2211af69d88dSmrg break; 2212af69d88dSmrg 2213af69d88dSmrg case GL_RGBA: 2214af69d88dSmrg type_valid = (type == GL_UNSIGNED_BYTE 2215af69d88dSmrg || type == GL_UNSIGNED_SHORT_4_4_4_4 2216af69d88dSmrg || type == GL_UNSIGNED_SHORT_5_5_5_1 2217af69d88dSmrg || type == GL_FLOAT 2218af69d88dSmrg || type == GL_HALF_FLOAT_OES 2219b9abf16eSmaya || (_mesa_has_texture_type_2_10_10_10_REV(ctx) && 222001e04c3fSmrg type == GL_UNSIGNED_INT_2_10_10_10_REV)); 2221af69d88dSmrg break; 2222af69d88dSmrg 2223af69d88dSmrg case GL_DEPTH_COMPONENT: 2224af69d88dSmrg /* This format is filtered against invalid dimensionalities elsewhere. 2225af69d88dSmrg */ 2226af69d88dSmrg type_valid = (type == GL_UNSIGNED_SHORT 2227af69d88dSmrg || type == GL_UNSIGNED_INT); 2228af69d88dSmrg break; 2229af69d88dSmrg 2230af69d88dSmrg case GL_DEPTH_STENCIL: 2231af69d88dSmrg /* This format is filtered against invalid dimensionalities elsewhere. 2232af69d88dSmrg */ 2233af69d88dSmrg type_valid = (type == GL_UNSIGNED_INT_24_8); 2234af69d88dSmrg break; 2235af69d88dSmrg 2236af69d88dSmrg case GL_BGRA_EXT: 2237af69d88dSmrg type_valid = (type == GL_UNSIGNED_BYTE); 2238af69d88dSmrg 2239af69d88dSmrg /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but 2240af69d88dSmrg * the format does not appear to be allowed for 3D textures in OpenGL 2241af69d88dSmrg * ES. 2242af69d88dSmrg */ 2243af69d88dSmrg if (dimensions != 2) 2244af69d88dSmrg return GL_INVALID_VALUE; 2245af69d88dSmrg 2246af69d88dSmrg break; 2247af69d88dSmrg 2248af69d88dSmrg default: 2249af69d88dSmrg return GL_INVALID_VALUE; 2250af69d88dSmrg } 2251af69d88dSmrg 2252af69d88dSmrg return type_valid ? GL_NO_ERROR : GL_INVALID_OPERATION; 2253af69d88dSmrg} 2254af69d88dSmrg 225501e04c3fSmrg/** 225601e04c3fSmrg * Return the simple base format for a given internal texture format. 225701e04c3fSmrg * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA. 225801e04c3fSmrg * 225901e04c3fSmrg * \param ctx GL context. 226001e04c3fSmrg * \param internalFormat the internal texture format token or 1, 2, 3, or 4. 226101e04c3fSmrg * 226201e04c3fSmrg * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE, 226301e04c3fSmrg * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum. 226401e04c3fSmrg * 226501e04c3fSmrg * This is the format which is used during texture application (i.e. the 226601e04c3fSmrg * texture format and env mode determine the arithmetic used. 226701e04c3fSmrg */ 226801e04c3fSmrgGLint 226901e04c3fSmrg_mesa_base_tex_format(const struct gl_context *ctx, GLint internalFormat) 227001e04c3fSmrg{ 227101e04c3fSmrg switch (internalFormat) { 227201e04c3fSmrg case GL_ALPHA: 227301e04c3fSmrg case GL_ALPHA4: 227401e04c3fSmrg case GL_ALPHA8: 227501e04c3fSmrg case GL_ALPHA12: 227601e04c3fSmrg case GL_ALPHA16: 227701e04c3fSmrg return (ctx->API != API_OPENGL_CORE) ? GL_ALPHA : -1; 227801e04c3fSmrg case 1: 227901e04c3fSmrg case GL_LUMINANCE: 228001e04c3fSmrg case GL_LUMINANCE4: 228101e04c3fSmrg case GL_LUMINANCE8: 228201e04c3fSmrg case GL_LUMINANCE12: 228301e04c3fSmrg case GL_LUMINANCE16: 228401e04c3fSmrg return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE : -1; 228501e04c3fSmrg case 2: 228601e04c3fSmrg case GL_LUMINANCE_ALPHA: 228701e04c3fSmrg case GL_LUMINANCE4_ALPHA4: 228801e04c3fSmrg case GL_LUMINANCE6_ALPHA2: 228901e04c3fSmrg case GL_LUMINANCE8_ALPHA8: 229001e04c3fSmrg case GL_LUMINANCE12_ALPHA4: 229101e04c3fSmrg case GL_LUMINANCE12_ALPHA12: 229201e04c3fSmrg case GL_LUMINANCE16_ALPHA16: 229301e04c3fSmrg return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE_ALPHA : -1; 229401e04c3fSmrg case GL_INTENSITY: 229501e04c3fSmrg case GL_INTENSITY4: 229601e04c3fSmrg case GL_INTENSITY8: 229701e04c3fSmrg case GL_INTENSITY12: 229801e04c3fSmrg case GL_INTENSITY16: 229901e04c3fSmrg return (ctx->API != API_OPENGL_CORE) ? GL_INTENSITY : -1; 230001e04c3fSmrg case 3: 230101e04c3fSmrg return (ctx->API != API_OPENGL_CORE) ? GL_RGB : -1; 230201e04c3fSmrg case GL_RGB: 230301e04c3fSmrg case GL_R3_G3_B2: 230401e04c3fSmrg case GL_RGB4: 230501e04c3fSmrg case GL_RGB5: 230601e04c3fSmrg case GL_RGB8: 230701e04c3fSmrg case GL_RGB10: 230801e04c3fSmrg case GL_RGB12: 230901e04c3fSmrg case GL_RGB16: 231001e04c3fSmrg return GL_RGB; 231101e04c3fSmrg case 4: 231201e04c3fSmrg return (ctx->API != API_OPENGL_CORE) ? GL_RGBA : -1; 231301e04c3fSmrg case GL_RGBA: 231401e04c3fSmrg case GL_RGBA2: 231501e04c3fSmrg case GL_RGBA4: 231601e04c3fSmrg case GL_RGB5_A1: 231701e04c3fSmrg case GL_RGBA8: 231801e04c3fSmrg case GL_RGB10_A2: 231901e04c3fSmrg case GL_RGBA12: 232001e04c3fSmrg case GL_RGBA16: 232101e04c3fSmrg return GL_RGBA; 232201e04c3fSmrg default: 232301e04c3fSmrg ; /* fallthrough */ 232401e04c3fSmrg } 232501e04c3fSmrg 232601e04c3fSmrg /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0). 232701e04c3fSmrg */ 232801e04c3fSmrg if (_mesa_is_gles(ctx)) { 232901e04c3fSmrg switch (internalFormat) { 233001e04c3fSmrg case GL_BGRA: 233101e04c3fSmrg return GL_RGBA; 233201e04c3fSmrg default: 233301e04c3fSmrg ; /* fallthrough */ 233401e04c3fSmrg } 233501e04c3fSmrg } 233601e04c3fSmrg 2337b9abf16eSmaya if (_mesa_has_ARB_ES2_compatibility(ctx) || 2338b9abf16eSmaya _mesa_has_OES_framebuffer_object(ctx) || 2339b9abf16eSmaya ctx->API == API_OPENGLES2) { 234001e04c3fSmrg switch (internalFormat) { 234101e04c3fSmrg case GL_RGB565: 234201e04c3fSmrg return GL_RGB; 234301e04c3fSmrg default: 234401e04c3fSmrg ; /* fallthrough */ 234501e04c3fSmrg } 234601e04c3fSmrg } 234701e04c3fSmrg 2348b9abf16eSmaya if (_mesa_has_ARB_depth_texture(ctx) || _mesa_has_OES_depth_texture(ctx) || 2349b9abf16eSmaya ctx->API == API_OPENGL_CORE) { 235001e04c3fSmrg switch (internalFormat) { 235101e04c3fSmrg case GL_DEPTH_COMPONENT: 235201e04c3fSmrg case GL_DEPTH_COMPONENT16: 235301e04c3fSmrg case GL_DEPTH_COMPONENT24: 235401e04c3fSmrg case GL_DEPTH_COMPONENT32: 235501e04c3fSmrg return GL_DEPTH_COMPONENT; 235601e04c3fSmrg case GL_DEPTH_STENCIL: 235701e04c3fSmrg case GL_DEPTH24_STENCIL8: 235801e04c3fSmrg return GL_DEPTH_STENCIL; 235901e04c3fSmrg default: 236001e04c3fSmrg ; /* fallthrough */ 236101e04c3fSmrg } 236201e04c3fSmrg } 236301e04c3fSmrg 2364b9abf16eSmaya if (_mesa_has_ARB_texture_stencil8(ctx) || 2365b9abf16eSmaya _mesa_has_OES_texture_stencil8(ctx)) { 236601e04c3fSmrg switch (internalFormat) { 236701e04c3fSmrg case GL_STENCIL_INDEX: 236801e04c3fSmrg case GL_STENCIL_INDEX1: 236901e04c3fSmrg case GL_STENCIL_INDEX4: 237001e04c3fSmrg case GL_STENCIL_INDEX8: 237101e04c3fSmrg case GL_STENCIL_INDEX16: 237201e04c3fSmrg return GL_STENCIL_INDEX; 237301e04c3fSmrg default: 237401e04c3fSmrg ; /* fallthrough */ 237501e04c3fSmrg } 237601e04c3fSmrg } 237701e04c3fSmrg 237801e04c3fSmrg switch (internalFormat) { 237901e04c3fSmrg case GL_COMPRESSED_ALPHA: 23807ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_ALPHA : -1; 238101e04c3fSmrg case GL_COMPRESSED_LUMINANCE: 23827ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE : -1; 238301e04c3fSmrg case GL_COMPRESSED_LUMINANCE_ALPHA: 23847ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE_ALPHA : -1; 238501e04c3fSmrg case GL_COMPRESSED_INTENSITY: 23867ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_INTENSITY : -1; 238701e04c3fSmrg case GL_COMPRESSED_RGB: 238801e04c3fSmrg return GL_RGB; 238901e04c3fSmrg case GL_COMPRESSED_RGBA: 239001e04c3fSmrg return GL_RGBA; 239101e04c3fSmrg default: 239201e04c3fSmrg ; /* fallthrough */ 239301e04c3fSmrg } 239401e04c3fSmrg 239501e04c3fSmrg if (_mesa_is_compressed_format(ctx, internalFormat)) { 239601e04c3fSmrg GLenum base_compressed = 239701e04c3fSmrg _mesa_gl_compressed_format_base_format(internalFormat); 239801e04c3fSmrg if (base_compressed) 239901e04c3fSmrg return base_compressed; 240001e04c3fSmrg } 240101e04c3fSmrg 2402b9abf16eSmaya if ((_mesa_has_KHR_texture_compression_astc_ldr(ctx) && 240301e04c3fSmrg is_astc_2d_format(internalFormat)) || 2404b9abf16eSmaya (_mesa_has_OES_texture_compression_astc(ctx) && 240501e04c3fSmrg is_astc_3d_format(internalFormat))) 240601e04c3fSmrg return GL_RGBA; 240701e04c3fSmrg 24087ec681f3Smrg if (_mesa_has_MESA_ycbcr_texture(ctx)) { 240901e04c3fSmrg if (internalFormat == GL_YCBCR_MESA) 241001e04c3fSmrg return GL_YCBCR_MESA; 241101e04c3fSmrg } 241201e04c3fSmrg 2413b9abf16eSmaya if (_mesa_has_half_float_textures(ctx)) { 241401e04c3fSmrg switch (internalFormat) { 241501e04c3fSmrg case GL_ALPHA16F_ARB: 24167ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_ALPHA : -1; 241701e04c3fSmrg case GL_RGBA16F_ARB: 241801e04c3fSmrg return GL_RGBA; 241901e04c3fSmrg case GL_RGB16F_ARB: 242001e04c3fSmrg return GL_RGB; 242101e04c3fSmrg case GL_INTENSITY16F_ARB: 24227ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_INTENSITY : -1; 242301e04c3fSmrg case GL_LUMINANCE16F_ARB: 24247ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE : -1; 242501e04c3fSmrg case GL_LUMINANCE_ALPHA16F_ARB: 24267ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE_ALPHA : -1; 2427b9abf16eSmaya } 2428b9abf16eSmaya } 2429b9abf16eSmaya 2430b9abf16eSmaya if (_mesa_has_float_textures(ctx)) { 2431b9abf16eSmaya switch (internalFormat) { 2432b9abf16eSmaya case GL_ALPHA32F_ARB: 24337ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_ALPHA : -1; 2434b9abf16eSmaya case GL_RGBA32F_ARB: 2435b9abf16eSmaya return GL_RGBA; 2436b9abf16eSmaya case GL_RGB32F_ARB: 2437b9abf16eSmaya return GL_RGB; 2438b9abf16eSmaya case GL_INTENSITY32F_ARB: 24397ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_INTENSITY : -1; 2440b9abf16eSmaya case GL_LUMINANCE32F_ARB: 24417ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE : -1; 244201e04c3fSmrg case GL_LUMINANCE_ALPHA32F_ARB: 24437ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE_ALPHA : -1; 244401e04c3fSmrg } 244501e04c3fSmrg } 244601e04c3fSmrg 2447b9abf16eSmaya if (_mesa_has_EXT_texture_snorm(ctx) || _mesa_is_gles3(ctx)) { 244801e04c3fSmrg switch (internalFormat) { 244901e04c3fSmrg case GL_RED_SNORM: 245001e04c3fSmrg case GL_R8_SNORM: 245101e04c3fSmrg case GL_R16_SNORM: 245201e04c3fSmrg return GL_RED; 245301e04c3fSmrg case GL_RG_SNORM: 245401e04c3fSmrg case GL_RG8_SNORM: 245501e04c3fSmrg case GL_RG16_SNORM: 245601e04c3fSmrg return GL_RG; 245701e04c3fSmrg case GL_RGB_SNORM: 245801e04c3fSmrg case GL_RGB8_SNORM: 245901e04c3fSmrg case GL_RGB16_SNORM: 246001e04c3fSmrg return GL_RGB; 246101e04c3fSmrg case GL_RGBA_SNORM: 246201e04c3fSmrg case GL_RGBA8_SNORM: 246301e04c3fSmrg case GL_RGBA16_SNORM: 246401e04c3fSmrg return GL_RGBA; 246501e04c3fSmrg case GL_ALPHA_SNORM: 246601e04c3fSmrg case GL_ALPHA8_SNORM: 246701e04c3fSmrg case GL_ALPHA16_SNORM: 24687ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_ALPHA : -1; 246901e04c3fSmrg case GL_LUMINANCE_SNORM: 247001e04c3fSmrg case GL_LUMINANCE8_SNORM: 247101e04c3fSmrg case GL_LUMINANCE16_SNORM: 24727ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE : -1; 247301e04c3fSmrg case GL_LUMINANCE_ALPHA_SNORM: 247401e04c3fSmrg case GL_LUMINANCE8_ALPHA8_SNORM: 247501e04c3fSmrg case GL_LUMINANCE16_ALPHA16_SNORM: 24767ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE_ALPHA : -1; 247701e04c3fSmrg case GL_INTENSITY_SNORM: 247801e04c3fSmrg case GL_INTENSITY8_SNORM: 247901e04c3fSmrg case GL_INTENSITY16_SNORM: 24807ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_INTENSITY : -1; 248101e04c3fSmrg default: 248201e04c3fSmrg ; /* fallthrough */ 248301e04c3fSmrg } 248401e04c3fSmrg } 248501e04c3fSmrg 2486b9abf16eSmaya if (_mesa_has_EXT_texture_sRGB(ctx) || _mesa_is_gles3(ctx)) { 248701e04c3fSmrg switch (internalFormat) { 248801e04c3fSmrg case GL_SRGB_EXT: 248901e04c3fSmrg case GL_SRGB8_EXT: 249001e04c3fSmrg case GL_COMPRESSED_SRGB_EXT: 249101e04c3fSmrg return GL_RGB; 249201e04c3fSmrg case GL_SRGB_ALPHA_EXT: 249301e04c3fSmrg case GL_SRGB8_ALPHA8_EXT: 249401e04c3fSmrg case GL_COMPRESSED_SRGB_ALPHA_EXT: 249501e04c3fSmrg return GL_RGBA; 249601e04c3fSmrg case GL_SLUMINANCE_ALPHA_EXT: 249701e04c3fSmrg case GL_SLUMINANCE8_ALPHA8_EXT: 249801e04c3fSmrg case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT: 24997ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE_ALPHA : -1; 250001e04c3fSmrg case GL_SLUMINANCE_EXT: 250101e04c3fSmrg case GL_SLUMINANCE8_EXT: 250201e04c3fSmrg case GL_COMPRESSED_SLUMINANCE_EXT: 25037ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE : -1; 250401e04c3fSmrg default: 250501e04c3fSmrg ; /* fallthrough */ 250601e04c3fSmrg } 250701e04c3fSmrg } 250801e04c3fSmrg 2509b9abf16eSmaya if (_mesa_has_EXT_texture_sRGB_R8(ctx)) { 2510b9abf16eSmaya switch (internalFormat) { 2511b9abf16eSmaya case GL_SR8_EXT: 2512b9abf16eSmaya return GL_RED; 2513b9abf16eSmaya default: 2514b9abf16eSmaya ; /* fallthrough */ 2515b9abf16eSmaya } 2516b9abf16eSmaya } 2517b9abf16eSmaya 25187ec681f3Smrg if (_mesa_has_EXT_texture_sRGB_RG8(ctx)) { 25197ec681f3Smrg switch (internalFormat) { 25207ec681f3Smrg case GL_SRG8_EXT: 25217ec681f3Smrg return GL_RG; 25227ec681f3Smrg default: 25237ec681f3Smrg ; /* fallthrough */ 25247ec681f3Smrg } 25257ec681f3Smrg } 25267ec681f3Smrg 2527b9abf16eSmaya if (_mesa_has_integer_textures(ctx)) { 252801e04c3fSmrg switch (internalFormat) { 252901e04c3fSmrg case GL_RGBA8UI_EXT: 253001e04c3fSmrg case GL_RGBA16UI_EXT: 253101e04c3fSmrg case GL_RGBA32UI_EXT: 253201e04c3fSmrg case GL_RGBA8I_EXT: 253301e04c3fSmrg case GL_RGBA16I_EXT: 253401e04c3fSmrg case GL_RGBA32I_EXT: 253501e04c3fSmrg return GL_RGBA; 253601e04c3fSmrg case GL_RGB8UI_EXT: 253701e04c3fSmrg case GL_RGB16UI_EXT: 253801e04c3fSmrg case GL_RGB32UI_EXT: 253901e04c3fSmrg case GL_RGB8I_EXT: 254001e04c3fSmrg case GL_RGB16I_EXT: 254101e04c3fSmrg case GL_RGB32I_EXT: 254201e04c3fSmrg return GL_RGB; 254301e04c3fSmrg } 254401e04c3fSmrg } 254501e04c3fSmrg 2546b9abf16eSmaya if (_mesa_has_texture_rgb10_a2ui(ctx)) { 254701e04c3fSmrg switch (internalFormat) { 254801e04c3fSmrg case GL_RGB10_A2UI: 254901e04c3fSmrg return GL_RGBA; 255001e04c3fSmrg } 255101e04c3fSmrg } 255201e04c3fSmrg 2553b9abf16eSmaya if (_mesa_has_integer_textures(ctx)) { 255401e04c3fSmrg switch (internalFormat) { 255501e04c3fSmrg case GL_ALPHA8UI_EXT: 255601e04c3fSmrg case GL_ALPHA16UI_EXT: 255701e04c3fSmrg case GL_ALPHA32UI_EXT: 255801e04c3fSmrg case GL_ALPHA8I_EXT: 255901e04c3fSmrg case GL_ALPHA16I_EXT: 256001e04c3fSmrg case GL_ALPHA32I_EXT: 25617ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_ALPHA : -1; 256201e04c3fSmrg case GL_INTENSITY8UI_EXT: 256301e04c3fSmrg case GL_INTENSITY16UI_EXT: 256401e04c3fSmrg case GL_INTENSITY32UI_EXT: 256501e04c3fSmrg case GL_INTENSITY8I_EXT: 256601e04c3fSmrg case GL_INTENSITY16I_EXT: 256701e04c3fSmrg case GL_INTENSITY32I_EXT: 25687ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_INTENSITY : -1; 256901e04c3fSmrg case GL_LUMINANCE8UI_EXT: 257001e04c3fSmrg case GL_LUMINANCE16UI_EXT: 257101e04c3fSmrg case GL_LUMINANCE32UI_EXT: 257201e04c3fSmrg case GL_LUMINANCE8I_EXT: 257301e04c3fSmrg case GL_LUMINANCE16I_EXT: 257401e04c3fSmrg case GL_LUMINANCE32I_EXT: 25757ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE : -1; 257601e04c3fSmrg case GL_LUMINANCE_ALPHA8UI_EXT: 257701e04c3fSmrg case GL_LUMINANCE_ALPHA16UI_EXT: 257801e04c3fSmrg case GL_LUMINANCE_ALPHA32UI_EXT: 257901e04c3fSmrg case GL_LUMINANCE_ALPHA8I_EXT: 258001e04c3fSmrg case GL_LUMINANCE_ALPHA16I_EXT: 258101e04c3fSmrg case GL_LUMINANCE_ALPHA32I_EXT: 25827ec681f3Smrg return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE_ALPHA : -1; 258301e04c3fSmrg default: 258401e04c3fSmrg ; /* fallthrough */ 258501e04c3fSmrg } 258601e04c3fSmrg } 258701e04c3fSmrg 2588b9abf16eSmaya if (_mesa_has_rg_textures(ctx)) { 258901e04c3fSmrg switch (internalFormat) { 259001e04c3fSmrg case GL_R16F: 2591b9abf16eSmaya if (!_mesa_has_half_float_textures(ctx)) 2592b9abf16eSmaya break; 2593b9abf16eSmaya return GL_RED; 259401e04c3fSmrg case GL_R32F: 2595b9abf16eSmaya if (!_mesa_has_float_textures(ctx)) 2596b9abf16eSmaya break; 259701e04c3fSmrg return GL_RED; 259801e04c3fSmrg case GL_R8I: 259901e04c3fSmrg case GL_R8UI: 260001e04c3fSmrg case GL_R16I: 260101e04c3fSmrg case GL_R16UI: 260201e04c3fSmrg case GL_R32I: 260301e04c3fSmrg case GL_R32UI: 2604b9abf16eSmaya if (!_mesa_has_integer_textures(ctx)) 2605b9abf16eSmaya break; 26067ec681f3Smrg FALLTHROUGH; 260701e04c3fSmrg case GL_R8: 260801e04c3fSmrg case GL_R16: 260901e04c3fSmrg case GL_RED: 261001e04c3fSmrg case GL_COMPRESSED_RED: 261101e04c3fSmrg return GL_RED; 261201e04c3fSmrg 261301e04c3fSmrg case GL_RG16F: 2614b9abf16eSmaya if (!_mesa_has_half_float_textures(ctx)) 2615b9abf16eSmaya break; 2616b9abf16eSmaya return GL_RG; 261701e04c3fSmrg case GL_RG32F: 2618b9abf16eSmaya if (!_mesa_has_float_textures(ctx)) 2619b9abf16eSmaya break; 262001e04c3fSmrg return GL_RG; 262101e04c3fSmrg case GL_RG8I: 262201e04c3fSmrg case GL_RG8UI: 262301e04c3fSmrg case GL_RG16I: 262401e04c3fSmrg case GL_RG16UI: 262501e04c3fSmrg case GL_RG32I: 262601e04c3fSmrg case GL_RG32UI: 2627b9abf16eSmaya if (!_mesa_has_integer_textures(ctx)) 2628b9abf16eSmaya break; 26297ec681f3Smrg FALLTHROUGH; 263001e04c3fSmrg case GL_RG: 263101e04c3fSmrg case GL_RG8: 263201e04c3fSmrg case GL_RG16: 263301e04c3fSmrg case GL_COMPRESSED_RG: 263401e04c3fSmrg return GL_RG; 263501e04c3fSmrg default: 263601e04c3fSmrg ; /* fallthrough */ 263701e04c3fSmrg } 263801e04c3fSmrg } 263901e04c3fSmrg 2640b9abf16eSmaya if (_mesa_has_texture_shared_exponent(ctx)) { 264101e04c3fSmrg switch (internalFormat) { 264201e04c3fSmrg case GL_RGB9_E5_EXT: 264301e04c3fSmrg return GL_RGB; 264401e04c3fSmrg default: 264501e04c3fSmrg ; /* fallthrough */ 264601e04c3fSmrg } 264701e04c3fSmrg } 264801e04c3fSmrg 2649b9abf16eSmaya if (_mesa_has_packed_float(ctx)) { 265001e04c3fSmrg switch (internalFormat) { 265101e04c3fSmrg case GL_R11F_G11F_B10F_EXT: 265201e04c3fSmrg return GL_RGB; 265301e04c3fSmrg default: 265401e04c3fSmrg ; /* fallthrough */ 265501e04c3fSmrg } 265601e04c3fSmrg } 265701e04c3fSmrg 2658b9abf16eSmaya if (_mesa_has_float_depth_buffer(ctx)) { 265901e04c3fSmrg switch (internalFormat) { 266001e04c3fSmrg case GL_DEPTH_COMPONENT32F: 266101e04c3fSmrg return GL_DEPTH_COMPONENT; 266201e04c3fSmrg case GL_DEPTH32F_STENCIL8: 266301e04c3fSmrg return GL_DEPTH_STENCIL; 266401e04c3fSmrg default: 266501e04c3fSmrg ; /* fallthrough */ 266601e04c3fSmrg } 266701e04c3fSmrg } 266801e04c3fSmrg 266901e04c3fSmrg return -1; /* error */ 267001e04c3fSmrg} 267101e04c3fSmrg 267201e04c3fSmrg/** 267301e04c3fSmrg * Returns the effective internal format from a texture format and type. 267401e04c3fSmrg * This is used by texture image operations internally for validation, when 267501e04c3fSmrg * the specified internal format is a base (unsized) format. 267601e04c3fSmrg * 267701e04c3fSmrg * This method will only return a valid effective internal format if the 267801e04c3fSmrg * combination of format, type and internal format in base form, is acceptable. 267901e04c3fSmrg * 268001e04c3fSmrg * If a single sized internal format is defined in the spec (OpenGL-ES 3.0.4) or 268101e04c3fSmrg * in extensions, to unambiguously correspond to the given base format, then 268201e04c3fSmrg * that internal format is returned as the effective. Otherwise, if the 268301e04c3fSmrg * combination is accepted but a single effective format is not defined, the 268401e04c3fSmrg * passed base format will be returned instead. 268501e04c3fSmrg * 268601e04c3fSmrg * \param format the texture format 268701e04c3fSmrg * \param type the texture type 268801e04c3fSmrg */ 268901e04c3fSmrgstatic GLenum 2690b9abf16eSmayagles_effective_internal_format_for_format_and_type(GLenum format, 2691b9abf16eSmaya GLenum type) 269201e04c3fSmrg{ 269301e04c3fSmrg switch (type) { 269401e04c3fSmrg case GL_UNSIGNED_BYTE: 269501e04c3fSmrg switch (format) { 269601e04c3fSmrg case GL_RGBA: 269701e04c3fSmrg return GL_RGBA8; 269801e04c3fSmrg case GL_RGB: 269901e04c3fSmrg return GL_RGB8; 270001e04c3fSmrg case GL_RG: 270101e04c3fSmrg return GL_RG8; 270201e04c3fSmrg case GL_RED: 270301e04c3fSmrg return GL_R8; 270401e04c3fSmrg /* Although LUMINANCE_ALPHA, LUMINANCE and ALPHA appear in table 3.12, 270501e04c3fSmrg * (section 3.8 Texturing, page 128 of the OpenGL-ES 3.0.4) as effective 270601e04c3fSmrg * internal formats, they do not correspond to GL constants, so the base 270701e04c3fSmrg * format is returned instead. 270801e04c3fSmrg */ 270901e04c3fSmrg case GL_BGRA_EXT: 271001e04c3fSmrg case GL_LUMINANCE_ALPHA: 271101e04c3fSmrg case GL_LUMINANCE: 271201e04c3fSmrg case GL_ALPHA: 271301e04c3fSmrg return format; 271401e04c3fSmrg } 271501e04c3fSmrg break; 271601e04c3fSmrg 271701e04c3fSmrg case GL_UNSIGNED_SHORT_4_4_4_4: 271801e04c3fSmrg if (format == GL_RGBA) 271901e04c3fSmrg return GL_RGBA4; 272001e04c3fSmrg break; 272101e04c3fSmrg 272201e04c3fSmrg case GL_UNSIGNED_SHORT_5_5_5_1: 272301e04c3fSmrg if (format == GL_RGBA) 272401e04c3fSmrg return GL_RGB5_A1; 272501e04c3fSmrg break; 272601e04c3fSmrg 272701e04c3fSmrg case GL_UNSIGNED_SHORT_5_6_5: 272801e04c3fSmrg if (format == GL_RGB) 272901e04c3fSmrg return GL_RGB565; 273001e04c3fSmrg break; 273101e04c3fSmrg 273201e04c3fSmrg /* OES_packed_depth_stencil */ 273301e04c3fSmrg case GL_UNSIGNED_INT_24_8: 273401e04c3fSmrg if (format == GL_DEPTH_STENCIL) 273501e04c3fSmrg return GL_DEPTH24_STENCIL8; 273601e04c3fSmrg break; 273701e04c3fSmrg 273801e04c3fSmrg case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: 273901e04c3fSmrg if (format == GL_DEPTH_STENCIL) 274001e04c3fSmrg return GL_DEPTH32F_STENCIL8; 274101e04c3fSmrg break; 274201e04c3fSmrg 274301e04c3fSmrg case GL_UNSIGNED_SHORT: 274401e04c3fSmrg if (format == GL_DEPTH_COMPONENT) 274501e04c3fSmrg return GL_DEPTH_COMPONENT16; 274601e04c3fSmrg break; 274701e04c3fSmrg 274801e04c3fSmrg case GL_UNSIGNED_INT: 274901e04c3fSmrg /* It can be DEPTH_COMPONENT16 or DEPTH_COMPONENT24, so just return 275001e04c3fSmrg * the format. 275101e04c3fSmrg */ 275201e04c3fSmrg if (format == GL_DEPTH_COMPONENT) 275301e04c3fSmrg return format; 275401e04c3fSmrg break; 275501e04c3fSmrg 275601e04c3fSmrg /* OES_texture_float and OES_texture_half_float */ 275701e04c3fSmrg case GL_FLOAT: 275801e04c3fSmrg if (format == GL_DEPTH_COMPONENT) 275901e04c3fSmrg return GL_DEPTH_COMPONENT32F; 27607ec681f3Smrg FALLTHROUGH; 276101e04c3fSmrg case GL_HALF_FLOAT_OES: 276201e04c3fSmrg switch (format) { 276301e04c3fSmrg case GL_RGBA: 276401e04c3fSmrg case GL_RGB: 276501e04c3fSmrg case GL_LUMINANCE_ALPHA: 276601e04c3fSmrg case GL_LUMINANCE: 276701e04c3fSmrg case GL_ALPHA: 276801e04c3fSmrg case GL_RED: 276901e04c3fSmrg case GL_RG: 277001e04c3fSmrg return format; 277101e04c3fSmrg } 277201e04c3fSmrg break; 277301e04c3fSmrg case GL_HALF_FLOAT: 277401e04c3fSmrg switch (format) { 277501e04c3fSmrg case GL_RG: 277601e04c3fSmrg case GL_RED: 277701e04c3fSmrg return format; 277801e04c3fSmrg } 277901e04c3fSmrg break; 278001e04c3fSmrg 278101e04c3fSmrg /* GL_EXT_texture_type_2_10_10_10_REV */ 278201e04c3fSmrg case GL_UNSIGNED_INT_2_10_10_10_REV: 278301e04c3fSmrg switch (format) { 278401e04c3fSmrg case GL_RGBA: 278501e04c3fSmrg case GL_RGB: 278601e04c3fSmrg return format; 278701e04c3fSmrg } 278801e04c3fSmrg break; 278901e04c3fSmrg 279001e04c3fSmrg default: 279101e04c3fSmrg /* fall through and return NONE */ 279201e04c3fSmrg break; 279301e04c3fSmrg } 279401e04c3fSmrg 279501e04c3fSmrg return GL_NONE; 279601e04c3fSmrg} 2797af69d88dSmrg 2798af69d88dSmrg/** 2799af69d88dSmrg * Do error checking of format/type combinations for OpenGL ES 3 280001e04c3fSmrg * glTex[Sub]Image, or ES1/ES2 with GL_OES_required_internalformat. 2801af69d88dSmrg * \return error code, or GL_NO_ERROR. 2802af69d88dSmrg */ 2803af69d88dSmrgGLenum 2804b9abf16eSmaya_mesa_gles_error_check_format_and_type(const struct gl_context *ctx, 2805b9abf16eSmaya GLenum format, GLenum type, 2806b9abf16eSmaya GLenum internalFormat) 2807af69d88dSmrg{ 280801e04c3fSmrg /* If internalFormat is an unsized format, then the effective internal 280901e04c3fSmrg * format derived from format and type should be used instead. Page 127, 281001e04c3fSmrg * section "3.8 Texturing" of the GLES 3.0.4 spec states: 281101e04c3fSmrg * 281201e04c3fSmrg * "if internalformat is a base internal format, the effective 281301e04c3fSmrg * internal format is a sized internal format that is derived 281401e04c3fSmrg * from the format and type for internal use by the GL. 281501e04c3fSmrg * Table 3.12 specifies the mapping of format and type to effective 281601e04c3fSmrg * internal formats. The effective internal format is used by the GL 281701e04c3fSmrg * for purposes such as texture completeness or type checks for 281801e04c3fSmrg * CopyTex* commands. In these cases, the GL is required to operate 281901e04c3fSmrg * as if the effective internal format was used as the internalformat 282001e04c3fSmrg * when specifying the texture data." 282101e04c3fSmrg */ 282201e04c3fSmrg if (_mesa_is_enum_format_unsized(internalFormat)) { 282301e04c3fSmrg GLenum effectiveInternalFormat = 2824b9abf16eSmaya gles_effective_internal_format_for_format_and_type(format, type); 282501e04c3fSmrg 282601e04c3fSmrg if (effectiveInternalFormat == GL_NONE) 282701e04c3fSmrg return GL_INVALID_OPERATION; 282801e04c3fSmrg 282901e04c3fSmrg GLenum baseInternalFormat; 283001e04c3fSmrg if (internalFormat == GL_BGRA_EXT) { 283101e04c3fSmrg /* Unfortunately, _mesa_base_tex_format returns a base format of 283201e04c3fSmrg * GL_RGBA for GL_BGRA_EXT. This makes perfect sense if you're 283301e04c3fSmrg * asking the question, "what channels does this format have?" 283401e04c3fSmrg * However, if we're trying to determine if two internal formats 283501e04c3fSmrg * match in the ES3 sense, we actually want GL_BGRA. 283601e04c3fSmrg */ 283701e04c3fSmrg baseInternalFormat = GL_BGRA_EXT; 283801e04c3fSmrg } else { 283901e04c3fSmrg baseInternalFormat = 284001e04c3fSmrg _mesa_base_tex_format(ctx, effectiveInternalFormat); 284101e04c3fSmrg } 284201e04c3fSmrg 284301e04c3fSmrg if (internalFormat != baseInternalFormat) 284401e04c3fSmrg return GL_INVALID_OPERATION; 284501e04c3fSmrg 284601e04c3fSmrg internalFormat = effectiveInternalFormat; 284701e04c3fSmrg } 284801e04c3fSmrg 284901e04c3fSmrg /* The GLES variant of EXT_texture_compression_s3tc is very vague and 285001e04c3fSmrg * doesn't list valid types. Just do exactly what the spec says. 285101e04c3fSmrg */ 2852b9abf16eSmaya if (_mesa_has_EXT_texture_compression_s3tc(ctx) && 285301e04c3fSmrg (internalFormat == GL_COMPRESSED_RGB_S3TC_DXT1_EXT || 285401e04c3fSmrg internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT || 285501e04c3fSmrg internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT || 285601e04c3fSmrg internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)) 285701e04c3fSmrg return format == GL_RGB || format == GL_RGBA ? GL_NO_ERROR : 285801e04c3fSmrg GL_INVALID_OPERATION; 285901e04c3fSmrg 2860af69d88dSmrg switch (format) { 286101e04c3fSmrg case GL_BGRA_EXT: 28627ec681f3Smrg if (type != GL_UNSIGNED_BYTE || 28637ec681f3Smrg (internalFormat != GL_BGRA && 28647ec681f3Smrg internalFormat != GL_RGBA8 && 28657ec681f3Smrg internalFormat != GL_SRGB8_ALPHA8)) 28667ec681f3Smrg return GL_INVALID_OPERATION; 28677ec681f3Smrg break; 28687ec681f3Smrg 28697ec681f3Smrg case GL_BGR_EXT: 28707ec681f3Smrg if (type != GL_UNSIGNED_BYTE || 28717ec681f3Smrg (internalFormat != GL_RGB8 && 28727ec681f3Smrg internalFormat != GL_SRGB8)) 287301e04c3fSmrg return GL_INVALID_OPERATION; 287401e04c3fSmrg break; 287501e04c3fSmrg 2876af69d88dSmrg case GL_RGBA: 2877af69d88dSmrg switch (type) { 2878af69d88dSmrg case GL_UNSIGNED_BYTE: 2879af69d88dSmrg switch (internalFormat) { 2880af69d88dSmrg case GL_RGBA: 2881af69d88dSmrg case GL_RGBA8: 2882af69d88dSmrg case GL_RGB5_A1: 2883af69d88dSmrg case GL_RGBA4: 288401e04c3fSmrg break; 2885af69d88dSmrg case GL_SRGB8_ALPHA8_EXT: 288601e04c3fSmrg if (ctx->Version <= 20) 288701e04c3fSmrg return GL_INVALID_OPERATION; 2888af69d88dSmrg break; 2889b9abf16eSmaya case GL_COMPRESSED_RGBA_BPTC_UNORM: 2890b9abf16eSmaya case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM: 2891b9abf16eSmaya if (!_mesa_has_EXT_texture_compression_bptc(ctx)) 2892b9abf16eSmaya return GL_INVALID_OPERATION; 2893b9abf16eSmaya break; 2894af69d88dSmrg default: 2895af69d88dSmrg return GL_INVALID_OPERATION; 2896af69d88dSmrg } 2897af69d88dSmrg break; 2898af69d88dSmrg 2899af69d88dSmrg case GL_BYTE: 290001e04c3fSmrg if (ctx->Version <= 20 || internalFormat != GL_RGBA8_SNORM) 290101e04c3fSmrg return GL_INVALID_OPERATION; 290201e04c3fSmrg break; 290301e04c3fSmrg 290401e04c3fSmrg case GL_UNSIGNED_SHORT: 290501e04c3fSmrg if (!_mesa_has_EXT_texture_norm16(ctx) || internalFormat != GL_RGBA16) 290601e04c3fSmrg return GL_INVALID_OPERATION; 290701e04c3fSmrg break; 290801e04c3fSmrg 290901e04c3fSmrg case GL_SHORT: 291001e04c3fSmrg if (!_mesa_has_EXT_texture_norm16(ctx) || 291101e04c3fSmrg internalFormat != GL_RGBA16_SNORM) 2912af69d88dSmrg return GL_INVALID_OPERATION; 2913af69d88dSmrg break; 2914af69d88dSmrg 2915af69d88dSmrg case GL_UNSIGNED_SHORT_4_4_4_4: 2916af69d88dSmrg switch (internalFormat) { 2917af69d88dSmrg case GL_RGBA: 2918af69d88dSmrg case GL_RGBA4: 2919af69d88dSmrg break; 2920af69d88dSmrg default: 2921af69d88dSmrg return GL_INVALID_OPERATION; 2922af69d88dSmrg } 2923af69d88dSmrg break; 2924af69d88dSmrg 2925af69d88dSmrg case GL_UNSIGNED_SHORT_5_5_5_1: 2926af69d88dSmrg switch (internalFormat) { 2927af69d88dSmrg case GL_RGBA: 2928af69d88dSmrg case GL_RGB5_A1: 2929af69d88dSmrg break; 2930af69d88dSmrg default: 2931af69d88dSmrg return GL_INVALID_OPERATION; 2932af69d88dSmrg } 2933af69d88dSmrg break; 2934af69d88dSmrg 2935af69d88dSmrg case GL_UNSIGNED_INT_2_10_10_10_REV: 2936af69d88dSmrg switch (internalFormat) { 293701e04c3fSmrg case GL_RGBA: 2938af69d88dSmrg case GL_RGB10_A2: 2939af69d88dSmrg case GL_RGB5_A1: 2940b9abf16eSmaya if (!_mesa_has_texture_type_2_10_10_10_REV(ctx)) 294101e04c3fSmrg return GL_INVALID_OPERATION; 2942af69d88dSmrg break; 2943af69d88dSmrg default: 2944af69d88dSmrg return GL_INVALID_OPERATION; 2945af69d88dSmrg } 2946af69d88dSmrg break; 2947af69d88dSmrg 2948af69d88dSmrg case GL_HALF_FLOAT: 294901e04c3fSmrg if (ctx->Version <= 20 || internalFormat != GL_RGBA16F) 2950af69d88dSmrg return GL_INVALID_OPERATION; 2951af69d88dSmrg break; 2952af69d88dSmrg 2953af69d88dSmrg case GL_FLOAT: 2954af69d88dSmrg switch (internalFormat) { 2955af69d88dSmrg case GL_RGBA16F: 2956af69d88dSmrg case GL_RGBA32F: 295701e04c3fSmrg if (ctx->Version <= 20) 295801e04c3fSmrg return GL_INVALID_OPERATION; 2959af69d88dSmrg break; 296001e04c3fSmrg case GL_RGBA: 29617ec681f3Smrg if (!_mesa_has_OES_texture_float(ctx) || internalFormat != format) 29627ec681f3Smrg return GL_INVALID_OPERATION; 29637ec681f3Smrg break; 2964af69d88dSmrg default: 2965af69d88dSmrg return GL_INVALID_OPERATION; 2966af69d88dSmrg } 2967af69d88dSmrg break; 2968af69d88dSmrg 296901e04c3fSmrg case GL_HALF_FLOAT_OES: 29707ec681f3Smrg if (!_mesa_has_OES_texture_half_float(ctx) || internalFormat != format) 29717ec681f3Smrg return GL_INVALID_OPERATION; 29727ec681f3Smrg break; 2973af69d88dSmrg default: 2974af69d88dSmrg return GL_INVALID_OPERATION; 2975af69d88dSmrg } 2976af69d88dSmrg break; 2977af69d88dSmrg 2978af69d88dSmrg case GL_RGBA_INTEGER: 297901e04c3fSmrg if (ctx->Version <= 20) 298001e04c3fSmrg return GL_INVALID_OPERATION; 2981af69d88dSmrg switch (type) { 2982af69d88dSmrg case GL_UNSIGNED_BYTE: 2983af69d88dSmrg if (internalFormat != GL_RGBA8UI) 2984af69d88dSmrg return GL_INVALID_OPERATION; 2985af69d88dSmrg break; 2986af69d88dSmrg 2987af69d88dSmrg case GL_BYTE: 2988af69d88dSmrg if (internalFormat != GL_RGBA8I) 2989af69d88dSmrg return GL_INVALID_OPERATION; 2990af69d88dSmrg break; 2991af69d88dSmrg 2992af69d88dSmrg case GL_UNSIGNED_SHORT: 2993af69d88dSmrg if (internalFormat != GL_RGBA16UI) 2994af69d88dSmrg return GL_INVALID_OPERATION; 2995af69d88dSmrg break; 2996af69d88dSmrg 2997af69d88dSmrg case GL_SHORT: 2998af69d88dSmrg if (internalFormat != GL_RGBA16I) 2999af69d88dSmrg return GL_INVALID_OPERATION; 3000af69d88dSmrg break; 3001af69d88dSmrg 3002af69d88dSmrg case GL_UNSIGNED_INT: 3003af69d88dSmrg if (internalFormat != GL_RGBA32UI) 3004af69d88dSmrg return GL_INVALID_OPERATION; 3005af69d88dSmrg break; 3006af69d88dSmrg 3007af69d88dSmrg case GL_INT: 3008af69d88dSmrg if (internalFormat != GL_RGBA32I) 3009af69d88dSmrg return GL_INVALID_OPERATION; 3010af69d88dSmrg break; 3011af69d88dSmrg 3012af69d88dSmrg case GL_UNSIGNED_INT_2_10_10_10_REV: 3013af69d88dSmrg if (internalFormat != GL_RGB10_A2UI) 3014af69d88dSmrg return GL_INVALID_OPERATION; 3015af69d88dSmrg break; 3016af69d88dSmrg 3017af69d88dSmrg default: 3018af69d88dSmrg return GL_INVALID_OPERATION; 3019af69d88dSmrg } 3020af69d88dSmrg break; 3021af69d88dSmrg 3022af69d88dSmrg case GL_RGB: 3023af69d88dSmrg switch (type) { 3024af69d88dSmrg case GL_UNSIGNED_BYTE: 3025af69d88dSmrg switch (internalFormat) { 3026af69d88dSmrg case GL_RGB: 3027af69d88dSmrg case GL_RGB8: 3028af69d88dSmrg case GL_RGB565: 302901e04c3fSmrg break; 3030af69d88dSmrg case GL_SRGB8: 303101e04c3fSmrg if (ctx->Version <= 20) 303201e04c3fSmrg return GL_INVALID_OPERATION; 3033af69d88dSmrg break; 3034af69d88dSmrg default: 3035af69d88dSmrg return GL_INVALID_OPERATION; 3036af69d88dSmrg } 3037af69d88dSmrg break; 3038af69d88dSmrg 3039af69d88dSmrg case GL_BYTE: 304001e04c3fSmrg if (ctx->Version <= 20 || internalFormat != GL_RGB8_SNORM) 304101e04c3fSmrg return GL_INVALID_OPERATION; 304201e04c3fSmrg break; 304301e04c3fSmrg 304401e04c3fSmrg case GL_UNSIGNED_SHORT: 304501e04c3fSmrg if (!_mesa_has_EXT_texture_norm16(ctx) || internalFormat != GL_RGB16) 304601e04c3fSmrg return GL_INVALID_OPERATION; 304701e04c3fSmrg break; 304801e04c3fSmrg 304901e04c3fSmrg case GL_SHORT: 305001e04c3fSmrg if (!_mesa_has_EXT_texture_norm16(ctx) || 305101e04c3fSmrg internalFormat != GL_RGB16_SNORM) 3052af69d88dSmrg return GL_INVALID_OPERATION; 3053af69d88dSmrg break; 3054af69d88dSmrg 3055af69d88dSmrg case GL_UNSIGNED_SHORT_5_6_5: 3056af69d88dSmrg switch (internalFormat) { 3057af69d88dSmrg case GL_RGB: 3058af69d88dSmrg case GL_RGB565: 3059af69d88dSmrg break; 3060af69d88dSmrg default: 3061af69d88dSmrg return GL_INVALID_OPERATION; 3062af69d88dSmrg } 3063af69d88dSmrg break; 3064af69d88dSmrg 3065af69d88dSmrg case GL_UNSIGNED_INT_10F_11F_11F_REV: 306601e04c3fSmrg if (ctx->Version <= 20 || internalFormat != GL_R11F_G11F_B10F) 3067af69d88dSmrg return GL_INVALID_OPERATION; 3068af69d88dSmrg break; 3069af69d88dSmrg 3070af69d88dSmrg case GL_UNSIGNED_INT_5_9_9_9_REV: 307101e04c3fSmrg if (ctx->Version <= 20 || internalFormat != GL_RGB9_E5) 3072af69d88dSmrg return GL_INVALID_OPERATION; 3073af69d88dSmrg break; 3074af69d88dSmrg 3075af69d88dSmrg case GL_HALF_FLOAT: 307601e04c3fSmrg if (ctx->Version <= 20) 307701e04c3fSmrg return GL_INVALID_OPERATION; 3078af69d88dSmrg switch (internalFormat) { 3079af69d88dSmrg case GL_RGB16F: 3080af69d88dSmrg case GL_R11F_G11F_B10F: 3081af69d88dSmrg case GL_RGB9_E5: 3082af69d88dSmrg break; 3083af69d88dSmrg default: 3084af69d88dSmrg return GL_INVALID_OPERATION; 3085af69d88dSmrg } 3086af69d88dSmrg break; 3087af69d88dSmrg 3088af69d88dSmrg case GL_FLOAT: 3089af69d88dSmrg switch (internalFormat) { 3090af69d88dSmrg case GL_RGB16F: 3091af69d88dSmrg case GL_RGB32F: 3092af69d88dSmrg case GL_R11F_G11F_B10F: 3093af69d88dSmrg case GL_RGB9_E5: 309401e04c3fSmrg if (ctx->Version <= 20) 309501e04c3fSmrg return GL_INVALID_OPERATION; 3096af69d88dSmrg break; 3097b9abf16eSmaya case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT: 3098b9abf16eSmaya case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT: 3099b9abf16eSmaya if (!_mesa_has_EXT_texture_compression_bptc(ctx)) 3100b9abf16eSmaya return GL_INVALID_OPERATION; 3101b9abf16eSmaya break; 31027ec681f3Smrg case GL_RGB: 31037ec681f3Smrg if (!_mesa_has_OES_texture_float(ctx) || internalFormat != format) 31047ec681f3Smrg return GL_INVALID_OPERATION; 31057ec681f3Smrg break; 3106af69d88dSmrg default: 3107af69d88dSmrg return GL_INVALID_OPERATION; 3108af69d88dSmrg } 3109af69d88dSmrg break; 3110af69d88dSmrg 311101e04c3fSmrg case GL_HALF_FLOAT_OES: 3112b9abf16eSmaya if (!_mesa_has_OES_texture_half_float(ctx) || internalFormat != format) 311301e04c3fSmrg return GL_INVALID_OPERATION; 311401e04c3fSmrg break; 311501e04c3fSmrg 3116af69d88dSmrg case GL_UNSIGNED_INT_2_10_10_10_REV: 3117af69d88dSmrg switch (internalFormat) { 311801e04c3fSmrg case GL_RGB: 311901e04c3fSmrg case GL_RGB10: 312001e04c3fSmrg case GL_RGB8: 312101e04c3fSmrg case GL_RGB565: 312201e04c3fSmrg /* GL_EXT_texture_type_2_10_10_10_REV allows GL_RGB even though 312301e04c3fSmrg * GLES3 doesn't, and GL_OES_required_internalformat extends that 312401e04c3fSmrg * to allow the sized RGB internalformats as well. 312501e04c3fSmrg */ 3126b9abf16eSmaya if (!_mesa_has_texture_type_2_10_10_10_REV(ctx)) 312701e04c3fSmrg return GL_INVALID_OPERATION; 3128af69d88dSmrg break; 3129af69d88dSmrg default: 3130af69d88dSmrg return GL_INVALID_OPERATION; 3131af69d88dSmrg } 3132af69d88dSmrg break; 3133af69d88dSmrg 3134af69d88dSmrg default: 3135af69d88dSmrg return GL_INVALID_OPERATION; 3136af69d88dSmrg } 3137af69d88dSmrg break; 3138af69d88dSmrg 3139af69d88dSmrg case GL_RGB_INTEGER: 314001e04c3fSmrg if (ctx->Version <= 20) 314101e04c3fSmrg return GL_INVALID_OPERATION; 3142af69d88dSmrg switch (type) { 3143af69d88dSmrg case GL_UNSIGNED_BYTE: 3144af69d88dSmrg if (internalFormat != GL_RGB8UI) 3145af69d88dSmrg return GL_INVALID_OPERATION; 3146af69d88dSmrg break; 3147af69d88dSmrg 3148af69d88dSmrg case GL_BYTE: 3149af69d88dSmrg if (internalFormat != GL_RGB8I) 3150af69d88dSmrg return GL_INVALID_OPERATION; 3151af69d88dSmrg break; 3152af69d88dSmrg 3153af69d88dSmrg case GL_UNSIGNED_SHORT: 3154af69d88dSmrg if (internalFormat != GL_RGB16UI) 3155af69d88dSmrg return GL_INVALID_OPERATION; 3156af69d88dSmrg break; 3157af69d88dSmrg 3158af69d88dSmrg case GL_SHORT: 3159af69d88dSmrg if (internalFormat != GL_RGB16I) 3160af69d88dSmrg return GL_INVALID_OPERATION; 3161af69d88dSmrg break; 3162af69d88dSmrg 3163af69d88dSmrg case GL_UNSIGNED_INT: 3164af69d88dSmrg if (internalFormat != GL_RGB32UI) 3165af69d88dSmrg return GL_INVALID_OPERATION; 3166af69d88dSmrg break; 3167af69d88dSmrg 3168af69d88dSmrg case GL_INT: 3169af69d88dSmrg if (internalFormat != GL_RGB32I) 3170af69d88dSmrg return GL_INVALID_OPERATION; 3171af69d88dSmrg break; 3172af69d88dSmrg 3173af69d88dSmrg default: 3174af69d88dSmrg return GL_INVALID_OPERATION; 3175af69d88dSmrg } 3176af69d88dSmrg break; 3177af69d88dSmrg 3178af69d88dSmrg case GL_RG: 3179b9abf16eSmaya if (!_mesa_has_rg_textures(ctx)) 318001e04c3fSmrg return GL_INVALID_OPERATION; 3181af69d88dSmrg switch (type) { 3182af69d88dSmrg case GL_UNSIGNED_BYTE: 31837ec681f3Smrg if (internalFormat == GL_RG8 || 31847ec681f3Smrg (_mesa_has_EXT_texture_compression_rgtc(ctx) && 31857ec681f3Smrg internalFormat == GL_COMPRESSED_RED_GREEN_RGTC2_EXT) || 31867ec681f3Smrg (_mesa_has_EXT_texture_sRGB_RG8(ctx) && 31877ec681f3Smrg internalFormat == GL_SRG8_EXT)) 31887ec681f3Smrg break; 31897ec681f3Smrg return GL_INVALID_OPERATION; 3190af69d88dSmrg 3191af69d88dSmrg case GL_BYTE: 3192b9abf16eSmaya if (internalFormat != GL_RG8_SNORM && 3193b9abf16eSmaya (!_mesa_has_EXT_texture_compression_rgtc(ctx) || 3194b9abf16eSmaya internalFormat != GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT)) 3195af69d88dSmrg return GL_INVALID_OPERATION; 3196af69d88dSmrg break; 3197af69d88dSmrg 319801e04c3fSmrg case GL_UNSIGNED_SHORT: 319901e04c3fSmrg if (!_mesa_has_EXT_texture_norm16(ctx) || internalFormat != GL_RG16) 3200af69d88dSmrg return GL_INVALID_OPERATION; 3201af69d88dSmrg break; 3202af69d88dSmrg 320301e04c3fSmrg case GL_SHORT: 320401e04c3fSmrg if (!_mesa_has_EXT_texture_norm16(ctx) || 320501e04c3fSmrg internalFormat != GL_RG16_SNORM) 320601e04c3fSmrg return GL_INVALID_OPERATION; 320701e04c3fSmrg break; 320801e04c3fSmrg 320901e04c3fSmrg case GL_HALF_FLOAT: 321001e04c3fSmrg case GL_HALF_FLOAT_OES: 321101e04c3fSmrg switch (internalFormat) { 321201e04c3fSmrg case GL_RG16F: 321301e04c3fSmrg if (ctx->Version <= 20) 321401e04c3fSmrg return GL_INVALID_OPERATION; 321501e04c3fSmrg break; 321601e04c3fSmrg case GL_RG: 32177ec681f3Smrg if (!_mesa_has_rg_textures(ctx) || 32187ec681f3Smrg !_mesa_has_OES_texture_half_float(ctx)) 32197ec681f3Smrg return GL_INVALID_OPERATION; 32207ec681f3Smrg break; 322101e04c3fSmrg default: 322201e04c3fSmrg return GL_INVALID_OPERATION; 322301e04c3fSmrg } 322401e04c3fSmrg break; 322501e04c3fSmrg 3226af69d88dSmrg case GL_FLOAT: 3227af69d88dSmrg switch (internalFormat) { 3228af69d88dSmrg case GL_RG16F: 3229af69d88dSmrg case GL_RG32F: 3230af69d88dSmrg break; 323101e04c3fSmrg case GL_RG: 32327ec681f3Smrg if (!_mesa_has_rg_textures(ctx) || 32337ec681f3Smrg !_mesa_has_OES_texture_float(ctx)) 32347ec681f3Smrg return GL_INVALID_OPERATION; 32357ec681f3Smrg break; 3236af69d88dSmrg default: 3237af69d88dSmrg return GL_INVALID_OPERATION; 3238af69d88dSmrg } 3239af69d88dSmrg break; 3240af69d88dSmrg 3241af69d88dSmrg default: 3242af69d88dSmrg return GL_INVALID_OPERATION; 3243af69d88dSmrg } 3244af69d88dSmrg break; 3245af69d88dSmrg 3246af69d88dSmrg case GL_RG_INTEGER: 324701e04c3fSmrg if (ctx->Version <= 20) 324801e04c3fSmrg return GL_INVALID_OPERATION; 3249af69d88dSmrg switch (type) { 3250af69d88dSmrg case GL_UNSIGNED_BYTE: 3251af69d88dSmrg if (internalFormat != GL_RG8UI) 3252af69d88dSmrg return GL_INVALID_OPERATION; 3253af69d88dSmrg break; 3254af69d88dSmrg 3255af69d88dSmrg case GL_BYTE: 3256af69d88dSmrg if (internalFormat != GL_RG8I) 3257af69d88dSmrg return GL_INVALID_OPERATION; 3258af69d88dSmrg break; 3259af69d88dSmrg 3260af69d88dSmrg case GL_UNSIGNED_SHORT: 3261af69d88dSmrg if (internalFormat != GL_RG16UI) 3262af69d88dSmrg return GL_INVALID_OPERATION; 3263af69d88dSmrg break; 3264af69d88dSmrg 3265af69d88dSmrg case GL_SHORT: 3266af69d88dSmrg if (internalFormat != GL_RG16I) 3267af69d88dSmrg return GL_INVALID_OPERATION; 3268af69d88dSmrg break; 3269af69d88dSmrg 3270af69d88dSmrg case GL_UNSIGNED_INT: 3271af69d88dSmrg if (internalFormat != GL_RG32UI) 3272af69d88dSmrg return GL_INVALID_OPERATION; 3273af69d88dSmrg break; 3274af69d88dSmrg 3275af69d88dSmrg case GL_INT: 3276af69d88dSmrg if (internalFormat != GL_RG32I) 3277af69d88dSmrg return GL_INVALID_OPERATION; 3278af69d88dSmrg break; 3279af69d88dSmrg 3280af69d88dSmrg default: 3281af69d88dSmrg return GL_INVALID_OPERATION; 3282af69d88dSmrg } 3283af69d88dSmrg break; 3284af69d88dSmrg 3285af69d88dSmrg case GL_RED: 3286b9abf16eSmaya if (!_mesa_has_rg_textures(ctx)) 328701e04c3fSmrg return GL_INVALID_OPERATION; 3288af69d88dSmrg switch (type) { 3289af69d88dSmrg case GL_UNSIGNED_BYTE: 3290b9abf16eSmaya if (internalFormat == GL_R8 || 3291b9abf16eSmaya ((internalFormat == GL_SR8_EXT) && 3292b9abf16eSmaya _mesa_has_EXT_texture_sRGB_R8(ctx)) || 3293b9abf16eSmaya (internalFormat == GL_COMPRESSED_RED_RGTC1_EXT && 3294b9abf16eSmaya _mesa_has_EXT_texture_compression_rgtc(ctx))) 3295b9abf16eSmaya break; 3296b9abf16eSmaya return GL_INVALID_OPERATION; 3297af69d88dSmrg 3298af69d88dSmrg case GL_BYTE: 3299b9abf16eSmaya if (internalFormat != GL_R8_SNORM && 3300b9abf16eSmaya (!_mesa_has_EXT_texture_compression_rgtc(ctx) || 3301b9abf16eSmaya internalFormat != GL_COMPRESSED_SIGNED_RED_RGTC1_EXT)) 3302af69d88dSmrg return GL_INVALID_OPERATION; 3303af69d88dSmrg break; 3304af69d88dSmrg 330501e04c3fSmrg case GL_UNSIGNED_SHORT: 330601e04c3fSmrg if (!_mesa_has_EXT_texture_norm16(ctx) || internalFormat != GL_R16) 330701e04c3fSmrg return GL_INVALID_OPERATION; 330801e04c3fSmrg break; 330901e04c3fSmrg 331001e04c3fSmrg case GL_SHORT: 331101e04c3fSmrg if (!_mesa_has_EXT_texture_norm16(ctx) || 331201e04c3fSmrg internalFormat != GL_R16_SNORM) 331301e04c3fSmrg return GL_INVALID_OPERATION; 331401e04c3fSmrg break; 331501e04c3fSmrg 3316af69d88dSmrg case GL_HALF_FLOAT: 331701e04c3fSmrg case GL_HALF_FLOAT_OES: 331801e04c3fSmrg switch (internalFormat) { 331901e04c3fSmrg case GL_R16F: 332001e04c3fSmrg if (ctx->Version <= 20) 332101e04c3fSmrg return GL_INVALID_OPERATION; 332201e04c3fSmrg break; 332301e04c3fSmrg case GL_RG: 332401e04c3fSmrg case GL_RED: 33257ec681f3Smrg if (!_mesa_has_rg_textures(ctx) || 33267ec681f3Smrg !_mesa_has_OES_texture_half_float(ctx)) 33277ec681f3Smrg return GL_INVALID_OPERATION; 33287ec681f3Smrg break; 332901e04c3fSmrg default: 3330af69d88dSmrg return GL_INVALID_OPERATION; 333101e04c3fSmrg } 3332af69d88dSmrg break; 3333af69d88dSmrg 3334af69d88dSmrg case GL_FLOAT: 3335af69d88dSmrg switch (internalFormat) { 3336af69d88dSmrg case GL_R16F: 3337af69d88dSmrg case GL_R32F: 3338af69d88dSmrg break; 333901e04c3fSmrg case GL_RED: 33407ec681f3Smrg if (!_mesa_has_rg_textures(ctx) || 33417ec681f3Smrg !_mesa_has_OES_texture_float(ctx)) 33427ec681f3Smrg return GL_INVALID_OPERATION; 33437ec681f3Smrg break; 3344af69d88dSmrg default: 3345af69d88dSmrg return GL_INVALID_OPERATION; 3346af69d88dSmrg } 3347af69d88dSmrg break; 3348af69d88dSmrg 3349af69d88dSmrg default: 3350af69d88dSmrg return GL_INVALID_OPERATION; 3351af69d88dSmrg } 3352af69d88dSmrg break; 3353af69d88dSmrg 3354af69d88dSmrg case GL_RED_INTEGER: 335501e04c3fSmrg if (ctx->Version <= 20) 335601e04c3fSmrg return GL_INVALID_OPERATION; 3357af69d88dSmrg switch (type) { 3358af69d88dSmrg case GL_UNSIGNED_BYTE: 3359af69d88dSmrg if (internalFormat != GL_R8UI) 3360af69d88dSmrg return GL_INVALID_OPERATION; 3361af69d88dSmrg break; 3362af69d88dSmrg 3363af69d88dSmrg case GL_BYTE: 3364af69d88dSmrg if (internalFormat != GL_R8I) 3365af69d88dSmrg return GL_INVALID_OPERATION; 3366af69d88dSmrg break; 3367af69d88dSmrg 3368af69d88dSmrg case GL_UNSIGNED_SHORT: 3369af69d88dSmrg if (internalFormat != GL_R16UI) 3370af69d88dSmrg return GL_INVALID_OPERATION; 3371af69d88dSmrg break; 3372af69d88dSmrg 3373af69d88dSmrg case GL_SHORT: 3374af69d88dSmrg if (internalFormat != GL_R16I) 3375af69d88dSmrg return GL_INVALID_OPERATION; 3376af69d88dSmrg break; 3377af69d88dSmrg 3378af69d88dSmrg case GL_UNSIGNED_INT: 3379af69d88dSmrg if (internalFormat != GL_R32UI) 3380af69d88dSmrg return GL_INVALID_OPERATION; 3381af69d88dSmrg break; 3382af69d88dSmrg 3383af69d88dSmrg case GL_INT: 3384af69d88dSmrg if (internalFormat != GL_R32I) 3385af69d88dSmrg return GL_INVALID_OPERATION; 3386af69d88dSmrg break; 3387af69d88dSmrg 3388af69d88dSmrg default: 3389af69d88dSmrg return GL_INVALID_OPERATION; 3390af69d88dSmrg } 3391af69d88dSmrg break; 3392af69d88dSmrg 3393af69d88dSmrg case GL_DEPTH_COMPONENT: 3394af69d88dSmrg switch (type) { 3395af69d88dSmrg case GL_UNSIGNED_SHORT: 3396af69d88dSmrg if (internalFormat != GL_DEPTH_COMPONENT 3397af69d88dSmrg && internalFormat != GL_DEPTH_COMPONENT16) 3398af69d88dSmrg return GL_INVALID_OPERATION; 3399af69d88dSmrg break; 3400af69d88dSmrg 3401af69d88dSmrg case GL_UNSIGNED_INT: 3402af69d88dSmrg switch (internalFormat) { 3403af69d88dSmrg case GL_DEPTH_COMPONENT: 3404af69d88dSmrg case GL_DEPTH_COMPONENT16: 3405af69d88dSmrg case GL_DEPTH_COMPONENT24: 3406af69d88dSmrg break; 3407af69d88dSmrg default: 3408af69d88dSmrg return GL_INVALID_OPERATION; 3409af69d88dSmrg } 3410af69d88dSmrg break; 3411af69d88dSmrg 3412af69d88dSmrg case GL_FLOAT: 341301e04c3fSmrg if (ctx->Version <= 20 || internalFormat != GL_DEPTH_COMPONENT32F) 3414af69d88dSmrg return GL_INVALID_OPERATION; 3415af69d88dSmrg break; 3416af69d88dSmrg 3417af69d88dSmrg default: 3418af69d88dSmrg return GL_INVALID_OPERATION; 3419af69d88dSmrg } 3420af69d88dSmrg break; 3421af69d88dSmrg 3422af69d88dSmrg case GL_DEPTH_STENCIL: 3423af69d88dSmrg switch (type) { 3424af69d88dSmrg case GL_UNSIGNED_INT_24_8: 3425af69d88dSmrg if (internalFormat != GL_DEPTH_STENCIL 3426af69d88dSmrg && internalFormat != GL_DEPTH24_STENCIL8) 3427af69d88dSmrg return GL_INVALID_OPERATION; 3428af69d88dSmrg break; 3429af69d88dSmrg 3430af69d88dSmrg case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: 343101e04c3fSmrg if (ctx->Version <= 20 || internalFormat != GL_DEPTH32F_STENCIL8) 3432af69d88dSmrg return GL_INVALID_OPERATION; 3433af69d88dSmrg break; 3434af69d88dSmrg 3435af69d88dSmrg default: 3436af69d88dSmrg return GL_INVALID_OPERATION; 3437af69d88dSmrg } 3438af69d88dSmrg break; 3439af69d88dSmrg 344001e04c3fSmrg case GL_STENCIL_INDEX: 344101e04c3fSmrg if (!_mesa_has_OES_texture_stencil8(ctx) || 344201e04c3fSmrg type != GL_UNSIGNED_BYTE || 344301e04c3fSmrg internalFormat != GL_STENCIL_INDEX8) { 344401e04c3fSmrg return GL_INVALID_OPERATION; 344501e04c3fSmrg } 344601e04c3fSmrg break; 344701e04c3fSmrg 3448af69d88dSmrg case GL_ALPHA: 3449af69d88dSmrg case GL_LUMINANCE: 3450af69d88dSmrg case GL_LUMINANCE_ALPHA: 345101e04c3fSmrg switch (type) { 345201e04c3fSmrg case GL_FLOAT: 3453b9abf16eSmaya if (!_mesa_has_OES_texture_float(ctx) || internalFormat != format) 345401e04c3fSmrg return GL_INVALID_OPERATION; 345501e04c3fSmrg break; 345601e04c3fSmrg case GL_HALF_FLOAT_OES: 3457b9abf16eSmaya if (!_mesa_has_OES_texture_half_float(ctx) || internalFormat != format) 345801e04c3fSmrg return GL_INVALID_OPERATION; 345901e04c3fSmrg break; 346001e04c3fSmrg case GL_UNSIGNED_BYTE: 346101e04c3fSmrg if (!(format == internalFormat || 346201e04c3fSmrg (format == GL_ALPHA && internalFormat == GL_ALPHA8) || 346301e04c3fSmrg (format == GL_LUMINANCE && internalFormat == GL_LUMINANCE8) || 346401e04c3fSmrg (format == GL_LUMINANCE_ALPHA && 346501e04c3fSmrg ((internalFormat == GL_LUMINANCE8_ALPHA8) || 346601e04c3fSmrg (internalFormat == GL_LUMINANCE4_ALPHA4))))) { 346701e04c3fSmrg return GL_INVALID_OPERATION; 346801e04c3fSmrg } 346901e04c3fSmrg break; 347001e04c3fSmrg default: 3471af69d88dSmrg return GL_INVALID_OPERATION; 347201e04c3fSmrg } 3473af69d88dSmrg break; 3474af69d88dSmrg } 3475af69d88dSmrg 3476af69d88dSmrg return GL_NO_ERROR; 3477af69d88dSmrg} 347801e04c3fSmrg 347901e04c3fSmrgstatic void 348001e04c3fSmrgset_swizzle(uint8_t *swizzle, int x, int y, int z, int w) 348101e04c3fSmrg{ 348201e04c3fSmrg swizzle[MESA_FORMAT_SWIZZLE_X] = x; 348301e04c3fSmrg swizzle[MESA_FORMAT_SWIZZLE_Y] = y; 348401e04c3fSmrg swizzle[MESA_FORMAT_SWIZZLE_Z] = z; 348501e04c3fSmrg swizzle[MESA_FORMAT_SWIZZLE_W] = w; 348601e04c3fSmrg} 348701e04c3fSmrg 348801e04c3fSmrgstatic bool 348901e04c3fSmrgget_swizzle_from_gl_format(GLenum format, uint8_t *swizzle) 349001e04c3fSmrg{ 349101e04c3fSmrg switch (format) { 349201e04c3fSmrg case GL_RGBA: 349301e04c3fSmrg case GL_RGBA_INTEGER_EXT: 349401e04c3fSmrg set_swizzle(swizzle, 0, 1, 2, 3); 349501e04c3fSmrg return true; 349601e04c3fSmrg case GL_BGRA: 349701e04c3fSmrg case GL_BGRA_INTEGER_EXT: 349801e04c3fSmrg set_swizzle(swizzle, 2, 1, 0, 3); 349901e04c3fSmrg return true; 350001e04c3fSmrg case GL_ABGR_EXT: 350101e04c3fSmrg set_swizzle(swizzle, 3, 2, 1, 0); 350201e04c3fSmrg return true; 350301e04c3fSmrg case GL_RGB: 350401e04c3fSmrg case GL_RGB_INTEGER_EXT: 350501e04c3fSmrg set_swizzle(swizzle, 0, 1, 2, 5); 350601e04c3fSmrg return true; 350701e04c3fSmrg case GL_BGR: 350801e04c3fSmrg case GL_BGR_INTEGER_EXT: 350901e04c3fSmrg set_swizzle(swizzle, 2, 1, 0, 5); 351001e04c3fSmrg return true; 351101e04c3fSmrg case GL_LUMINANCE_ALPHA: 351201e04c3fSmrg case GL_LUMINANCE_ALPHA_INTEGER_EXT: 351301e04c3fSmrg set_swizzle(swizzle, 0, 0, 0, 1); 351401e04c3fSmrg return true; 351501e04c3fSmrg case GL_RG: 351601e04c3fSmrg case GL_RG_INTEGER: 351701e04c3fSmrg set_swizzle(swizzle, 0, 1, 4, 5); 351801e04c3fSmrg return true; 351901e04c3fSmrg case GL_RED: 352001e04c3fSmrg case GL_RED_INTEGER_EXT: 352101e04c3fSmrg set_swizzle(swizzle, 0, 4, 4, 5); 352201e04c3fSmrg return true; 352301e04c3fSmrg case GL_GREEN: 352401e04c3fSmrg case GL_GREEN_INTEGER_EXT: 352501e04c3fSmrg set_swizzle(swizzle, 4, 0, 4, 5); 352601e04c3fSmrg return true; 352701e04c3fSmrg case GL_BLUE: 352801e04c3fSmrg case GL_BLUE_INTEGER_EXT: 352901e04c3fSmrg set_swizzle(swizzle, 4, 4, 0, 5); 353001e04c3fSmrg return true; 353101e04c3fSmrg case GL_ALPHA: 353201e04c3fSmrg case GL_ALPHA_INTEGER_EXT: 353301e04c3fSmrg set_swizzle(swizzle, 4, 4, 4, 0); 353401e04c3fSmrg return true; 353501e04c3fSmrg case GL_LUMINANCE: 353601e04c3fSmrg case GL_LUMINANCE_INTEGER_EXT: 353701e04c3fSmrg set_swizzle(swizzle, 0, 0, 0, 5); 353801e04c3fSmrg return true; 353901e04c3fSmrg case GL_INTENSITY: 354001e04c3fSmrg set_swizzle(swizzle, 0, 0, 0, 0); 354101e04c3fSmrg return true; 35427ec681f3Smrg case GL_DEPTH_COMPONENT: 35437ec681f3Smrg set_swizzle(swizzle, 0, 6, 6, 6); 35447ec681f3Smrg return true; 35457ec681f3Smrg case GL_STENCIL_INDEX: 35467ec681f3Smrg set_swizzle(swizzle, 6, 0, 6, 6); 35477ec681f3Smrg return true; 354801e04c3fSmrg default: 354901e04c3fSmrg return false; 355001e04c3fSmrg } 355101e04c3fSmrg} 355201e04c3fSmrg 35537ec681f3Smrgbool 35547ec681f3Smrg_mesa_swap_bytes_in_type_enum(GLenum *type) 35557ec681f3Smrg{ 35567ec681f3Smrg switch (*type) { 35577ec681f3Smrg case GL_UNSIGNED_INT_8_8_8_8: 35587ec681f3Smrg *type = GL_UNSIGNED_INT_8_8_8_8_REV; 35597ec681f3Smrg return true; 35607ec681f3Smrg case GL_UNSIGNED_INT_8_8_8_8_REV: 35617ec681f3Smrg *type = GL_UNSIGNED_INT_8_8_8_8; 35627ec681f3Smrg return true; 35637ec681f3Smrg case GL_UNSIGNED_SHORT_8_8_MESA: 35647ec681f3Smrg *type = GL_UNSIGNED_SHORT_8_8_REV_MESA; 35657ec681f3Smrg return true; 35667ec681f3Smrg case GL_UNSIGNED_SHORT_8_8_REV_MESA: 35677ec681f3Smrg *type = GL_UNSIGNED_SHORT_8_8_MESA; 35687ec681f3Smrg return true; 35697ec681f3Smrg case GL_BYTE: 35707ec681f3Smrg case GL_UNSIGNED_BYTE: 35717ec681f3Smrg /* format/types that are arrays of 8-bit values are unaffected by 35727ec681f3Smrg * swapBytes. 35737ec681f3Smrg */ 35747ec681f3Smrg return true; 35757ec681f3Smrg default: 35767ec681f3Smrg /* swapping bytes on 4444, 1555, or >8 bit per channel types etc. will 35777ec681f3Smrg * never match a Mesa format. 35787ec681f3Smrg */ 35797ec681f3Smrg return false; 35807ec681f3Smrg } 35817ec681f3Smrg} 35827ec681f3Smrg 358301e04c3fSmrg/** 358401e04c3fSmrg* Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT, 358501e04c3fSmrg* GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format 358601e04c3fSmrg* otherwise (for non-array formats). 358701e04c3fSmrg* 358801e04c3fSmrg* This function will typically be used to compute a mesa format from a GL type 358901e04c3fSmrg* so we can then call _mesa_format_convert. This function does 359001e04c3fSmrg* not consider byte swapping, so it returns types assuming that no byte 359101e04c3fSmrg* swapping is involved. If byte swapping is involved then clients are supposed 359201e04c3fSmrg* to handle that on their side before calling _mesa_format_convert. 359301e04c3fSmrg* 359401e04c3fSmrg* This function returns an uint32_t that can pack a mesa_format or a 359501e04c3fSmrg* mesa_array_format. Clients must check the mesa array format bit 359601e04c3fSmrg* (MESA_ARRAY_FORMAT_BIT) on the return value to know if the returned 359701e04c3fSmrg* format is a mesa_array_format or a mesa_format. 359801e04c3fSmrg*/ 359901e04c3fSmrguint32_t 360001e04c3fSmrg_mesa_format_from_format_and_type(GLenum format, GLenum type) 360101e04c3fSmrg{ 360201e04c3fSmrg bool is_array_format = true; 360301e04c3fSmrg uint8_t swizzle[4]; 360401e04c3fSmrg bool normalized = false, is_float = false, is_signed = false; 360501e04c3fSmrg int num_channels = 0, type_size = 0; 360601e04c3fSmrg 36077ec681f3Smrg if (format == GL_COLOR_INDEX) 36087ec681f3Smrg return MESA_FORMAT_NONE; 36097ec681f3Smrg 361001e04c3fSmrg /* Extract array format type information from the OpenGL data type */ 361101e04c3fSmrg switch (type) { 361201e04c3fSmrg case GL_UNSIGNED_BYTE: 361301e04c3fSmrg type_size = 1; 361401e04c3fSmrg break; 361501e04c3fSmrg case GL_BYTE: 361601e04c3fSmrg type_size = 1; 361701e04c3fSmrg is_signed = true; 361801e04c3fSmrg break; 361901e04c3fSmrg case GL_UNSIGNED_SHORT: 362001e04c3fSmrg type_size = 2; 362101e04c3fSmrg break; 362201e04c3fSmrg case GL_SHORT: 362301e04c3fSmrg type_size = 2; 362401e04c3fSmrg is_signed = true; 362501e04c3fSmrg break; 362601e04c3fSmrg case GL_UNSIGNED_INT: 362701e04c3fSmrg type_size = 4; 362801e04c3fSmrg break; 362901e04c3fSmrg case GL_INT: 363001e04c3fSmrg type_size = 4; 363101e04c3fSmrg is_signed = true; 363201e04c3fSmrg break; 363301e04c3fSmrg case GL_HALF_FLOAT: 363401e04c3fSmrg case GL_HALF_FLOAT_OES: 363501e04c3fSmrg type_size = 2; 363601e04c3fSmrg is_signed = true; 363701e04c3fSmrg is_float = true; 363801e04c3fSmrg break; 363901e04c3fSmrg case GL_FLOAT: 364001e04c3fSmrg type_size = 4; 364101e04c3fSmrg is_signed = true; 364201e04c3fSmrg is_float = true; 364301e04c3fSmrg break; 364401e04c3fSmrg default: 364501e04c3fSmrg is_array_format = false; 364601e04c3fSmrg break; 364701e04c3fSmrg } 364801e04c3fSmrg 364901e04c3fSmrg /* Extract array format swizzle information from the OpenGL format */ 365001e04c3fSmrg if (is_array_format) 365101e04c3fSmrg is_array_format = get_swizzle_from_gl_format(format, swizzle); 365201e04c3fSmrg 365301e04c3fSmrg /* If this is an array format type after checking data type and format, 365401e04c3fSmrg * create the array format 365501e04c3fSmrg */ 365601e04c3fSmrg if (is_array_format) { 36577ec681f3Smrg enum mesa_array_format_base_format bf; 36587ec681f3Smrg switch (format) { 36597ec681f3Smrg case GL_DEPTH_COMPONENT: 36607ec681f3Smrg bf = MESA_ARRAY_FORMAT_BASE_FORMAT_DEPTH; 36617ec681f3Smrg break; 36627ec681f3Smrg case GL_STENCIL_INDEX: 36637ec681f3Smrg bf = MESA_ARRAY_FORMAT_BASE_FORMAT_STENCIL; 36647ec681f3Smrg break; 36657ec681f3Smrg default: 36667ec681f3Smrg bf = MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS; 36677ec681f3Smrg break; 36687ec681f3Smrg } 36697ec681f3Smrg 36707ec681f3Smrg normalized = !(_mesa_is_enum_format_integer(format) || 36717ec681f3Smrg format == GL_STENCIL_INDEX); 367201e04c3fSmrg num_channels = _mesa_components_in_format(format); 367301e04c3fSmrg 36747ec681f3Smrg return MESA_ARRAY_FORMAT(bf, type_size, is_signed, is_float, 367501e04c3fSmrg normalized, num_channels, 367601e04c3fSmrg swizzle[0], swizzle[1], swizzle[2], swizzle[3]); 367701e04c3fSmrg } 367801e04c3fSmrg 367901e04c3fSmrg /* Otherwise this is not an array format, so return the mesa_format 368001e04c3fSmrg * matching the OpenGL format and data type 368101e04c3fSmrg */ 368201e04c3fSmrg switch (type) { 368301e04c3fSmrg case GL_UNSIGNED_SHORT_5_6_5: 368401e04c3fSmrg if (format == GL_RGB) 368501e04c3fSmrg return MESA_FORMAT_B5G6R5_UNORM; 368601e04c3fSmrg else if (format == GL_BGR) 368701e04c3fSmrg return MESA_FORMAT_R5G6B5_UNORM; 368801e04c3fSmrg else if (format == GL_RGB_INTEGER) 368901e04c3fSmrg return MESA_FORMAT_B5G6R5_UINT; 369001e04c3fSmrg break; 369101e04c3fSmrg case GL_UNSIGNED_SHORT_5_6_5_REV: 369201e04c3fSmrg if (format == GL_RGB) 369301e04c3fSmrg return MESA_FORMAT_R5G6B5_UNORM; 369401e04c3fSmrg else if (format == GL_BGR) 369501e04c3fSmrg return MESA_FORMAT_B5G6R5_UNORM; 369601e04c3fSmrg else if (format == GL_RGB_INTEGER) 369701e04c3fSmrg return MESA_FORMAT_R5G6B5_UINT; 369801e04c3fSmrg break; 369901e04c3fSmrg case GL_UNSIGNED_SHORT_4_4_4_4: 370001e04c3fSmrg if (format == GL_RGBA) 370101e04c3fSmrg return MESA_FORMAT_A4B4G4R4_UNORM; 370201e04c3fSmrg else if (format == GL_BGRA) 370301e04c3fSmrg return MESA_FORMAT_A4R4G4B4_UNORM; 370401e04c3fSmrg else if (format == GL_ABGR_EXT) 370501e04c3fSmrg return MESA_FORMAT_R4G4B4A4_UNORM; 370601e04c3fSmrg else if (format == GL_RGBA_INTEGER) 370701e04c3fSmrg return MESA_FORMAT_A4B4G4R4_UINT; 370801e04c3fSmrg else if (format == GL_BGRA_INTEGER) 370901e04c3fSmrg return MESA_FORMAT_A4R4G4B4_UINT; 371001e04c3fSmrg break; 371101e04c3fSmrg case GL_UNSIGNED_SHORT_4_4_4_4_REV: 371201e04c3fSmrg if (format == GL_RGBA) 371301e04c3fSmrg return MESA_FORMAT_R4G4B4A4_UNORM; 371401e04c3fSmrg else if (format == GL_BGRA) 371501e04c3fSmrg return MESA_FORMAT_B4G4R4A4_UNORM; 371601e04c3fSmrg else if (format == GL_ABGR_EXT) 371701e04c3fSmrg return MESA_FORMAT_A4B4G4R4_UNORM; 371801e04c3fSmrg else if (format == GL_RGBA_INTEGER) 371901e04c3fSmrg return MESA_FORMAT_R4G4B4A4_UINT; 372001e04c3fSmrg else if (format == GL_BGRA_INTEGER) 372101e04c3fSmrg return MESA_FORMAT_B4G4R4A4_UINT; 372201e04c3fSmrg break; 372301e04c3fSmrg case GL_UNSIGNED_SHORT_5_5_5_1: 372401e04c3fSmrg if (format == GL_RGBA) 372501e04c3fSmrg return MESA_FORMAT_A1B5G5R5_UNORM; 372601e04c3fSmrg else if (format == GL_BGRA) 372701e04c3fSmrg return MESA_FORMAT_A1R5G5B5_UNORM; 372801e04c3fSmrg else if (format == GL_RGBA_INTEGER) 372901e04c3fSmrg return MESA_FORMAT_A1B5G5R5_UINT; 373001e04c3fSmrg else if (format == GL_BGRA_INTEGER) 373101e04c3fSmrg return MESA_FORMAT_A1R5G5B5_UINT; 373201e04c3fSmrg break; 373301e04c3fSmrg case GL_UNSIGNED_SHORT_1_5_5_5_REV: 373401e04c3fSmrg if (format == GL_RGBA) 373501e04c3fSmrg return MESA_FORMAT_R5G5B5A1_UNORM; 373601e04c3fSmrg else if (format == GL_BGRA) 373701e04c3fSmrg return MESA_FORMAT_B5G5R5A1_UNORM; 373801e04c3fSmrg else if (format == GL_RGBA_INTEGER) 373901e04c3fSmrg return MESA_FORMAT_R5G5B5A1_UINT; 374001e04c3fSmrg else if (format == GL_BGRA_INTEGER) 374101e04c3fSmrg return MESA_FORMAT_B5G5R5A1_UINT; 374201e04c3fSmrg break; 374301e04c3fSmrg case GL_UNSIGNED_BYTE_3_3_2: 374401e04c3fSmrg if (format == GL_RGB) 374501e04c3fSmrg return MESA_FORMAT_B2G3R3_UNORM; 374601e04c3fSmrg else if (format == GL_RGB_INTEGER) 374701e04c3fSmrg return MESA_FORMAT_B2G3R3_UINT; 374801e04c3fSmrg break; 374901e04c3fSmrg case GL_UNSIGNED_BYTE_2_3_3_REV: 375001e04c3fSmrg if (format == GL_RGB) 375101e04c3fSmrg return MESA_FORMAT_R3G3B2_UNORM; 375201e04c3fSmrg else if (format == GL_RGB_INTEGER) 375301e04c3fSmrg return MESA_FORMAT_R3G3B2_UINT; 375401e04c3fSmrg break; 375501e04c3fSmrg case GL_UNSIGNED_INT_5_9_9_9_REV: 375601e04c3fSmrg if (format == GL_RGB) 375701e04c3fSmrg return MESA_FORMAT_R9G9B9E5_FLOAT; 375801e04c3fSmrg break; 375901e04c3fSmrg case GL_UNSIGNED_INT_10_10_10_2: 376001e04c3fSmrg if (format == GL_RGBA) 376101e04c3fSmrg return MESA_FORMAT_A2B10G10R10_UNORM; 376201e04c3fSmrg else if (format == GL_RGBA_INTEGER) 376301e04c3fSmrg return MESA_FORMAT_A2B10G10R10_UINT; 376401e04c3fSmrg else if (format == GL_BGRA) 376501e04c3fSmrg return MESA_FORMAT_A2R10G10B10_UNORM; 376601e04c3fSmrg else if (format == GL_BGRA_INTEGER) 376701e04c3fSmrg return MESA_FORMAT_A2R10G10B10_UINT; 376801e04c3fSmrg break; 376901e04c3fSmrg case GL_UNSIGNED_INT_2_10_10_10_REV: 377001e04c3fSmrg if (format == GL_RGB) 377101e04c3fSmrg return MESA_FORMAT_R10G10B10X2_UNORM; 377201e04c3fSmrg if (format == GL_RGBA) 377301e04c3fSmrg return MESA_FORMAT_R10G10B10A2_UNORM; 377401e04c3fSmrg else if (format == GL_RGBA_INTEGER) 377501e04c3fSmrg return MESA_FORMAT_R10G10B10A2_UINT; 377601e04c3fSmrg else if (format == GL_BGRA) 377701e04c3fSmrg return MESA_FORMAT_B10G10R10A2_UNORM; 377801e04c3fSmrg else if (format == GL_BGRA_INTEGER) 377901e04c3fSmrg return MESA_FORMAT_B10G10R10A2_UINT; 378001e04c3fSmrg break; 378101e04c3fSmrg case GL_UNSIGNED_INT_8_8_8_8: 378201e04c3fSmrg if (format == GL_RGBA) 378301e04c3fSmrg return MESA_FORMAT_A8B8G8R8_UNORM; 378401e04c3fSmrg else if (format == GL_BGRA) 378501e04c3fSmrg return MESA_FORMAT_A8R8G8B8_UNORM; 378601e04c3fSmrg else if (format == GL_ABGR_EXT) 378701e04c3fSmrg return MESA_FORMAT_R8G8B8A8_UNORM; 378801e04c3fSmrg else if (format == GL_RGBA_INTEGER) 378901e04c3fSmrg return MESA_FORMAT_A8B8G8R8_UINT; 379001e04c3fSmrg else if (format == GL_BGRA_INTEGER) 379101e04c3fSmrg return MESA_FORMAT_A8R8G8B8_UINT; 379201e04c3fSmrg break; 379301e04c3fSmrg case GL_UNSIGNED_INT_8_8_8_8_REV: 379401e04c3fSmrg if (format == GL_RGBA) 379501e04c3fSmrg return MESA_FORMAT_R8G8B8A8_UNORM; 379601e04c3fSmrg else if (format == GL_BGRA) 379701e04c3fSmrg return MESA_FORMAT_B8G8R8A8_UNORM; 379801e04c3fSmrg else if (format == GL_ABGR_EXT) 379901e04c3fSmrg return MESA_FORMAT_A8B8G8R8_UNORM; 380001e04c3fSmrg else if (format == GL_RGBA_INTEGER) 380101e04c3fSmrg return MESA_FORMAT_R8G8B8A8_UINT; 380201e04c3fSmrg else if (format == GL_BGRA_INTEGER) 380301e04c3fSmrg return MESA_FORMAT_B8G8R8A8_UINT; 380401e04c3fSmrg break; 380501e04c3fSmrg case GL_UNSIGNED_SHORT_8_8_MESA: 380601e04c3fSmrg if (format == GL_YCBCR_MESA) 380701e04c3fSmrg return MESA_FORMAT_YCBCR; 380801e04c3fSmrg break; 380901e04c3fSmrg case GL_UNSIGNED_SHORT_8_8_REV_MESA: 381001e04c3fSmrg if (format == GL_YCBCR_MESA) 381101e04c3fSmrg return MESA_FORMAT_YCBCR_REV; 381201e04c3fSmrg break; 381301e04c3fSmrg case GL_UNSIGNED_INT_10F_11F_11F_REV: 381401e04c3fSmrg if (format == GL_RGB) 381501e04c3fSmrg return MESA_FORMAT_R11G11B10_FLOAT; 381601e04c3fSmrg break; 381701e04c3fSmrg case GL_FLOAT: 381801e04c3fSmrg if (format == GL_DEPTH_COMPONENT) 381901e04c3fSmrg return MESA_FORMAT_Z_FLOAT32; 382001e04c3fSmrg break; 382101e04c3fSmrg case GL_UNSIGNED_INT: 382201e04c3fSmrg if (format == GL_DEPTH_COMPONENT) 382301e04c3fSmrg return MESA_FORMAT_Z_UNORM32; 382401e04c3fSmrg break; 382501e04c3fSmrg case GL_UNSIGNED_SHORT: 382601e04c3fSmrg if (format == GL_DEPTH_COMPONENT) 382701e04c3fSmrg return MESA_FORMAT_Z_UNORM16; 382801e04c3fSmrg break; 382901e04c3fSmrg case GL_UNSIGNED_INT_24_8: 383001e04c3fSmrg if (format == GL_DEPTH_STENCIL) 38317ec681f3Smrg return MESA_FORMAT_S8_UINT_Z24_UNORM; 38327ec681f3Smrg else if (format == GL_DEPTH_COMPONENT) 38337ec681f3Smrg return MESA_FORMAT_X8_UINT_Z24_UNORM; 383401e04c3fSmrg break; 383501e04c3fSmrg case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: 383601e04c3fSmrg if (format == GL_DEPTH_STENCIL) 383701e04c3fSmrg return MESA_FORMAT_Z32_FLOAT_S8X24_UINT; 383801e04c3fSmrg break; 383901e04c3fSmrg default: 384001e04c3fSmrg break; 384101e04c3fSmrg } 384201e04c3fSmrg 38437ec681f3Smrg fprintf(stderr, "Unsupported format/type: %s/%s\n", 38447ec681f3Smrg _mesa_enum_to_string(format), 38457ec681f3Smrg _mesa_enum_to_string(type)); 38467ec681f3Smrg 384701e04c3fSmrg /* If we got here it means that we could not find a Mesa format that 384801e04c3fSmrg * matches the GL format/type provided. We may need to add a new Mesa 384901e04c3fSmrg * format in that case. 385001e04c3fSmrg */ 385101e04c3fSmrg unreachable("Unsupported format"); 385201e04c3fSmrg} 385301e04c3fSmrg 385401e04c3fSmrguint32_t 385501e04c3fSmrg_mesa_tex_format_from_format_and_type(const struct gl_context *ctx, 385601e04c3fSmrg GLenum gl_format, GLenum type) 385701e04c3fSmrg{ 385801e04c3fSmrg mesa_format format = _mesa_format_from_format_and_type(gl_format, type); 385901e04c3fSmrg 386001e04c3fSmrg if (_mesa_format_is_mesa_array_format(format)) 386101e04c3fSmrg format = _mesa_format_from_array_format(format); 386201e04c3fSmrg 386301e04c3fSmrg if (format == MESA_FORMAT_NONE || !ctx->TextureFormatSupported[format]) 386401e04c3fSmrg return MESA_FORMAT_NONE; 386501e04c3fSmrg 386601e04c3fSmrg return format; 386701e04c3fSmrg} 386801e04c3fSmrg 386901e04c3fSmrg/** 387001e04c3fSmrg * Returns true if \p internal_format is a sized internal format that 387101e04c3fSmrg * is marked "Color Renderable" in Table 8.10 of the ES 3.2 specification. 387201e04c3fSmrg */ 387301e04c3fSmrgbool 387401e04c3fSmrg_mesa_is_es3_color_renderable(const struct gl_context *ctx, 387501e04c3fSmrg GLenum internal_format) 387601e04c3fSmrg{ 387701e04c3fSmrg switch (internal_format) { 387801e04c3fSmrg case GL_R8: 387901e04c3fSmrg case GL_RG8: 388001e04c3fSmrg case GL_RGB8: 388101e04c3fSmrg case GL_RGB565: 388201e04c3fSmrg case GL_RGBA4: 388301e04c3fSmrg case GL_RGB5_A1: 388401e04c3fSmrg case GL_RGBA8: 388501e04c3fSmrg case GL_RGB10_A2: 388601e04c3fSmrg case GL_RGB10_A2UI: 388701e04c3fSmrg case GL_SRGB8_ALPHA8: 388801e04c3fSmrg case GL_R16F: 388901e04c3fSmrg case GL_RG16F: 389001e04c3fSmrg case GL_RGBA16F: 389101e04c3fSmrg case GL_R32F: 389201e04c3fSmrg case GL_RG32F: 389301e04c3fSmrg case GL_RGBA32F: 389401e04c3fSmrg case GL_R11F_G11F_B10F: 389501e04c3fSmrg case GL_R8I: 389601e04c3fSmrg case GL_R8UI: 389701e04c3fSmrg case GL_R16I: 389801e04c3fSmrg case GL_R16UI: 389901e04c3fSmrg case GL_R32I: 390001e04c3fSmrg case GL_R32UI: 390101e04c3fSmrg case GL_RG8I: 390201e04c3fSmrg case GL_RG8UI: 390301e04c3fSmrg case GL_RG16I: 390401e04c3fSmrg case GL_RG16UI: 390501e04c3fSmrg case GL_RG32I: 390601e04c3fSmrg case GL_RG32UI: 390701e04c3fSmrg case GL_RGBA8I: 390801e04c3fSmrg case GL_RGBA8UI: 390901e04c3fSmrg case GL_RGBA16I: 391001e04c3fSmrg case GL_RGBA16UI: 391101e04c3fSmrg case GL_RGBA32I: 391201e04c3fSmrg case GL_RGBA32UI: 391301e04c3fSmrg return true; 391401e04c3fSmrg case GL_R16: 391501e04c3fSmrg case GL_RG16: 391601e04c3fSmrg case GL_RGBA16: 391701e04c3fSmrg return _mesa_has_EXT_texture_norm16(ctx); 391801e04c3fSmrg case GL_R8_SNORM: 391901e04c3fSmrg case GL_RG8_SNORM: 392001e04c3fSmrg case GL_RGBA8_SNORM: 392101e04c3fSmrg return _mesa_has_EXT_render_snorm(ctx); 392201e04c3fSmrg case GL_R16_SNORM: 392301e04c3fSmrg case GL_RG16_SNORM: 392401e04c3fSmrg case GL_RGBA16_SNORM: 392501e04c3fSmrg return _mesa_has_EXT_texture_norm16(ctx) && 392601e04c3fSmrg _mesa_has_EXT_render_snorm(ctx); 392701e04c3fSmrg default: 392801e04c3fSmrg return false; 392901e04c3fSmrg } 393001e04c3fSmrg} 393101e04c3fSmrg 393201e04c3fSmrg/** 393301e04c3fSmrg * Returns true if \p internal_format is a sized internal format that 393401e04c3fSmrg * is marked "Texture Filterable" in Table 8.10 of the ES 3.2 specification. 393501e04c3fSmrg */ 393601e04c3fSmrgbool 393701e04c3fSmrg_mesa_is_es3_texture_filterable(const struct gl_context *ctx, 393801e04c3fSmrg GLenum internal_format) 393901e04c3fSmrg{ 394001e04c3fSmrg switch (internal_format) { 394101e04c3fSmrg case GL_R8: 394201e04c3fSmrg case GL_R8_SNORM: 394301e04c3fSmrg case GL_RG8: 394401e04c3fSmrg case GL_RG8_SNORM: 394501e04c3fSmrg case GL_RGB8: 394601e04c3fSmrg case GL_RGB8_SNORM: 394701e04c3fSmrg case GL_RGB565: 394801e04c3fSmrg case GL_RGBA4: 394901e04c3fSmrg case GL_RGB5_A1: 395001e04c3fSmrg case GL_RGBA8: 395101e04c3fSmrg case GL_RGBA8_SNORM: 395201e04c3fSmrg case GL_RGB10_A2: 395301e04c3fSmrg case GL_SRGB8: 395401e04c3fSmrg case GL_SRGB8_ALPHA8: 395501e04c3fSmrg case GL_R16F: 395601e04c3fSmrg case GL_RG16F: 395701e04c3fSmrg case GL_RGB16F: 395801e04c3fSmrg case GL_RGBA16F: 395901e04c3fSmrg case GL_R11F_G11F_B10F: 396001e04c3fSmrg case GL_RGB9_E5: 396101e04c3fSmrg return true; 396201e04c3fSmrg case GL_R16: 396301e04c3fSmrg case GL_R16_SNORM: 396401e04c3fSmrg case GL_RG16: 396501e04c3fSmrg case GL_RG16_SNORM: 396601e04c3fSmrg case GL_RGB16: 396701e04c3fSmrg case GL_RGB16_SNORM: 396801e04c3fSmrg case GL_RGBA16: 396901e04c3fSmrg case GL_RGBA16_SNORM: 397001e04c3fSmrg return _mesa_has_EXT_texture_norm16(ctx); 397101e04c3fSmrg case GL_R32F: 397201e04c3fSmrg case GL_RG32F: 397301e04c3fSmrg case GL_RGB32F: 397401e04c3fSmrg case GL_RGBA32F: 397501e04c3fSmrg /* The OES_texture_float_linear spec says: 397601e04c3fSmrg * 397701e04c3fSmrg * "When implemented against OpenGL ES 3.0 or later versions, sized 397801e04c3fSmrg * 32-bit floating-point formats become texture-filterable. This 397901e04c3fSmrg * should be noted by, for example, checking the ``TF'' column of 398001e04c3fSmrg * table 8.13 in the ES 3.1 Specification (``Correspondence of sized 398101e04c3fSmrg * internal formats to base internal formats ... and use cases ...'') 398201e04c3fSmrg * for the R32F, RG32F, RGB32F, and RGBA32F formats." 398301e04c3fSmrg */ 3984b9abf16eSmaya return _mesa_has_OES_texture_float_linear(ctx); 398501e04c3fSmrg default: 398601e04c3fSmrg return false; 398701e04c3fSmrg } 398801e04c3fSmrg} 3989