ExtensionBehavior.cpp (4564B)
1 // 2 // Copyright 2017 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 // ExtensionBehavior.cpp: Extension name enumeration and data structures for storing extension 7 // behavior. 8 9 #include "compiler/translator/ExtensionBehavior.h" 10 11 #include "common/debug.h" 12 13 #include <string.h> 14 15 #define LIST_EXTENSIONS(OP) \ 16 OP(ANDROID_extension_pack_es31a) \ 17 OP(ANGLE_base_vertex_base_instance_shader_builtin) \ 18 OP(ANGLE_multi_draw) \ 19 OP(ANGLE_shader_pixel_local_storage) \ 20 OP(ANGLE_texture_multisample) \ 21 OP(APPLE_clip_distance) \ 22 OP(ARB_texture_rectangle) \ 23 OP(ARM_shader_framebuffer_fetch) \ 24 OP(EXT_blend_func_extended) \ 25 OP(EXT_clip_cull_distance) \ 26 OP(EXT_draw_buffers) \ 27 OP(EXT_frag_depth) \ 28 OP(EXT_geometry_shader) \ 29 OP(OES_geometry_shader) \ 30 OP(OES_shader_io_blocks) \ 31 OP(EXT_shader_io_blocks) \ 32 OP(EXT_gpu_shader5) \ 33 OP(EXT_primitive_bounding_box) \ 34 OP(OES_primitive_bounding_box) \ 35 OP(EXT_shader_framebuffer_fetch) \ 36 OP(EXT_shader_framebuffer_fetch_non_coherent) \ 37 OP(EXT_shader_non_constant_global_initializers) \ 38 OP(EXT_shader_texture_lod) \ 39 OP(EXT_shadow_samplers) \ 40 OP(EXT_tessellation_shader) \ 41 OP(EXT_texture_buffer) \ 42 OP(EXT_texture_cube_map_array) \ 43 OP(EXT_YUV_target) \ 44 OP(KHR_blend_equation_advanced) \ 45 OP(NV_EGL_stream_consumer_external) \ 46 OP(NV_shader_framebuffer_fetch) \ 47 OP(NV_shader_noperspective_interpolation) \ 48 OP(OES_EGL_image_external) \ 49 OP(OES_EGL_image_external_essl3) \ 50 OP(OES_sample_variables) \ 51 OP(OES_shader_multisample_interpolation) \ 52 OP(OES_shader_image_atomic) \ 53 OP(OES_standard_derivatives) \ 54 OP(OES_texture_3D) \ 55 OP(OES_texture_buffer) \ 56 OP(OES_texture_cube_map_array) \ 57 OP(OES_texture_storage_multisample_2d_array) \ 58 OP(OVR_multiview) \ 59 OP(OVR_multiview2) \ 60 OP(WEBGL_video_texture) 61 62 namespace sh 63 { 64 65 #define RETURN_EXTENSION_NAME_CASE(ext) \ 66 case TExtension::ext: \ 67 return "GL_" #ext; 68 69 const char *GetExtensionNameString(TExtension extension) 70 { 71 switch (extension) 72 { 73 LIST_EXTENSIONS(RETURN_EXTENSION_NAME_CASE) 74 default: 75 UNREACHABLE(); 76 return ""; 77 } 78 } 79 80 #define RETURN_EXTENSION_IF_NAME_MATCHES(ext) \ 81 if (strcmp(extWithoutGLPrefix, #ext) == 0) \ 82 { \ 83 return TExtension::ext; \ 84 } 85 86 TExtension GetExtensionByName(const char *extension) 87 { 88 // If first characters of the extension don't equal "GL_", early out. 89 if (strncmp(extension, "GL_", 3) != 0) 90 { 91 return TExtension::UNDEFINED; 92 } 93 const char *extWithoutGLPrefix = extension + 3; 94 95 LIST_EXTENSIONS(RETURN_EXTENSION_IF_NAME_MATCHES) 96 97 return TExtension::UNDEFINED; 98 } 99 100 const char *GetBehaviorString(TBehavior b) 101 { 102 switch (b) 103 { 104 case EBhRequire: 105 return "require"; 106 case EBhEnable: 107 return "enable"; 108 case EBhWarn: 109 return "warn"; 110 case EBhDisable: 111 return "disable"; 112 default: 113 return nullptr; 114 } 115 } 116 117 bool IsExtensionEnabled(const TExtensionBehavior &extBehavior, TExtension extension) 118 { 119 ASSERT(extension != TExtension::UNDEFINED); 120 auto iter = extBehavior.find(extension); 121 return iter != extBehavior.end() && 122 (iter->second == EBhEnable || iter->second == EBhRequire || iter->second == EBhWarn); 123 } 124 125 } // namespace sh