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