1 // Copyright 2019 The ANGLE Project Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 // 5 // format_map_desktop: 6 // Determining the sized internal format from a (format,type) pair. 7 // Also check DesktopGL format combinations for validity. 8 9 #include "angle_gl.h" 10 #include "common/debug.h" 11 #include "formatutils.h" 12 #include "renderer/gl/functionsgl_enums.h" 13 14 // TODO(http://anglebug.com/3730): switch ANGLE to generate its own GL enum types from gl.xml 15 16 namespace gl 17 { 18 ValidDesktopFormat(GLenum format)19bool ValidDesktopFormat(GLenum format) 20 { 21 switch (format) 22 { 23 case GL_STENCIL_INDEX: 24 case GL_DEPTH_COMPONENT: 25 case GL_DEPTH_STENCIL: 26 case GL_RED: 27 case GL_GREEN: 28 case GL_BLUE: 29 case GL_RG: 30 case GL_RGB: 31 case GL_RGBA: 32 case GL_BGR: 33 case GL_BGRA: 34 case GL_RED_INTEGER: 35 case GL_GREEN_INTEGER: 36 case GL_BLUE_INTEGER: 37 case GL_RG_INTEGER: 38 case GL_RGB_INTEGER: 39 case GL_RGBA_INTEGER: 40 case GL_BGR_INTEGER: 41 case GL_BGRA_INTEGER: 42 return true; 43 44 default: 45 return false; 46 } 47 } 48 ValidDesktopType(GLenum type)49bool ValidDesktopType(GLenum type) 50 { 51 switch (type) 52 { 53 case GL_UNSIGNED_BYTE: 54 case GL_BYTE: 55 case GL_UNSIGNED_SHORT: 56 case GL_SHORT: 57 case GL_UNSIGNED_INT: 58 case GL_INT: 59 case GL_HALF_FLOAT: 60 case GL_FLOAT: 61 case GL_UNSIGNED_BYTE_3_3_2: 62 case GL_UNSIGNED_BYTE_2_3_3_REV: 63 case GL_UNSIGNED_SHORT_5_6_5: 64 case GL_UNSIGNED_SHORT_5_6_5_REV: 65 case GL_UNSIGNED_SHORT_4_4_4_4: 66 case GL_UNSIGNED_SHORT_4_4_4_4_REV: 67 case GL_UNSIGNED_SHORT_5_5_5_1: 68 case GL_UNSIGNED_SHORT_1_5_5_5_REV: 69 case GL_UNSIGNED_INT_10_10_10_2: 70 case GL_UNSIGNED_INT_2_10_10_10_REV: 71 case GL_UNSIGNED_INT_24_8: 72 case GL_UNSIGNED_INT_10F_11F_11F_REV: 73 case GL_UNSIGNED_INT_5_9_9_9_REV: 74 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: 75 return true; 76 77 default: 78 return false; 79 } 80 } 81 82 // From OpenGL 4.6 spec section 8.4 ValidDesktopFormatCombination(GLenum format,GLenum type,GLenum internalFormat)83bool ValidDesktopFormatCombination(GLenum format, GLenum type, GLenum internalFormat) 84 { 85 ASSERT(ValidDesktopFormat(format) && ValidDesktopType(type)); 86 const InternalFormat &internalFormatInfo = GetInternalFormatInfo(internalFormat, type); 87 const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); 88 89 switch (format) 90 { 91 case GL_RED_INTEGER: 92 case GL_GREEN_INTEGER: 93 case GL_BLUE_INTEGER: 94 case GL_RG_INTEGER: 95 case GL_RGB_INTEGER: 96 case GL_RGBA_INTEGER: 97 case GL_BGR_INTEGER: 98 case GL_BGRA_INTEGER: 99 switch (type) 100 { 101 case GL_HALF_FLOAT: 102 case GL_FLOAT: 103 case GL_UNSIGNED_INT_10F_11F_11F_REV: 104 case GL_UNSIGNED_INT_5_9_9_9_REV: 105 return false; 106 default: 107 break; 108 } 109 if (!internalFormatInfo.isInt()) 110 return false; 111 break; 112 default: 113 // format is not an integer 114 if (internalFormatInfo.isInt()) 115 return false; 116 117 if (formatInfo.isDepthOrStencil() != internalFormatInfo.isDepthOrStencil()) 118 return false; 119 120 if (format == GL_STENCIL_INDEX && internalFormat != GL_STENCIL_INDEX) 121 return false; 122 break; 123 } 124 125 return true; 126 } 127 128 } // namespace gl 129