| 1 | // | 
|---|---|
| 2 | // Copyright (c) 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(ARB_texture_rectangle) \ | 
| 17 | OP(ANGLE_texture_multisample) \ | 
| 18 | OP(ARM_shader_framebuffer_fetch) \ | 
| 19 | OP(EXT_blend_func_extended) \ | 
| 20 | OP(EXT_draw_buffers) \ | 
| 21 | OP(EXT_frag_depth) \ | 
| 22 | OP(EXT_geometry_shader) \ | 
| 23 | OP(EXT_shader_framebuffer_fetch) \ | 
| 24 | OP(EXT_shader_texture_lod) \ | 
| 25 | OP(EXT_YUV_target) \ | 
| 26 | OP(NV_EGL_stream_consumer_external) \ | 
| 27 | OP(NV_shader_framebuffer_fetch) \ | 
| 28 | OP(OES_EGL_image_external) \ | 
| 29 | OP(OES_EGL_image_external_essl3) \ | 
| 30 | OP(OES_standard_derivatives) \ | 
| 31 | OP(OES_texture_storage_multisample_2d_array) \ | 
| 32 | OP(OVR_multiview2) \ | 
| 33 | OP(ANGLE_multi_draw) | 
| 34 | |
| 35 | namespace sh | 
| 36 | { | 
| 37 | |
| 38 | #define RETURN_EXTENSION_NAME_CASE(ext) \ | 
| 39 | case TExtension::ext: \ | 
| 40 | return "GL_" #ext; | 
| 41 | |
| 42 | const char *GetExtensionNameString(TExtension extension) | 
| 43 | { | 
| 44 | switch (extension) | 
| 45 | { | 
| 46 | LIST_EXTENSIONS(RETURN_EXTENSION_NAME_CASE) | 
| 47 | default: | 
| 48 | UNREACHABLE(); | 
| 49 |             return "";  | 
| 50 | } | 
| 51 | } | 
| 52 | |
| 53 | #define RETURN_EXTENSION_IF_NAME_MATCHES(ext) \ | 
| 54 | if (strcmp(extWithoutGLPrefix, #ext) == 0) \ | 
| 55 | { \ | 
| 56 | return TExtension::ext; \ | 
| 57 | } | 
| 58 | |
| 59 | TExtension GetExtensionByName(const char *extension) | 
| 60 | { | 
| 61 | // If first characters of the extension don't equal "GL_", early out. | 
| 62 |     if (strncmp(extension, "GL_", 3) != 0)  | 
| 63 | { | 
| 64 | return TExtension::UNDEFINED; | 
| 65 | } | 
| 66 | const char *extWithoutGLPrefix = extension + 3; | 
| 67 | |
| 68 | LIST_EXTENSIONS(RETURN_EXTENSION_IF_NAME_MATCHES) | 
| 69 | |
| 70 | return TExtension::UNDEFINED; | 
| 71 | } | 
| 72 | |
| 73 | const char *GetBehaviorString(TBehavior b) | 
| 74 | { | 
| 75 | switch (b) | 
| 76 | { | 
| 77 | case EBhRequire: | 
| 78 |             return "require";  | 
| 79 | case EBhEnable: | 
| 80 |             return "enable";  | 
| 81 | case EBhWarn: | 
| 82 |             return "warn";  | 
| 83 | case EBhDisable: | 
| 84 |             return "disable";  | 
| 85 | default: | 
| 86 | return nullptr; | 
| 87 | } | 
| 88 | } | 
| 89 | |
| 90 | bool IsExtensionEnabled(const TExtensionBehavior &extBehavior, TExtension extension) | 
| 91 | { | 
| 92 | ASSERT(extension != TExtension::UNDEFINED); | 
| 93 | auto iter = extBehavior.find(extension); | 
| 94 | return iter != extBehavior.end() && | 
| 95 | (iter->second == EBhEnable || iter->second == EBhRequire || iter->second == EBhWarn); | 
| 96 | } | 
| 97 | |
| 98 | } // namespace sh | 
| 99 |