• 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(ANDROID_extension_pack_es31a)                   \
17     OP(ANGLE_base_vertex_base_instance_shader_builtin) \
18     OP(ANGLE_multi_draw)                               \
19     OP(ANGLE_texture_multisample)                      \
20     OP(APPLE_clip_distance)                            \
21     OP(ARB_texture_rectangle)                          \
22     OP(ARM_shader_framebuffer_fetch)                   \
23     OP(EXT_blend_func_extended)                        \
24     OP(EXT_clip_cull_distance)                         \
25     OP(EXT_draw_buffers)                               \
26     OP(EXT_frag_depth)                                 \
27     OP(EXT_geometry_shader)                            \
28     OP(OES_geometry_shader)                            \
29     OP(OES_shader_io_blocks)                           \
30     OP(EXT_shader_io_blocks)                           \
31     OP(EXT_gpu_shader5)                                \
32     OP(EXT_primitive_bounding_box)                     \
33     OP(OES_primitive_bounding_box)                     \
34     OP(EXT_shader_framebuffer_fetch)                   \
35     OP(EXT_shader_framebuffer_fetch_non_coherent)      \
36     OP(EXT_shader_non_constant_global_initializers)    \
37     OP(EXT_shader_texture_lod)                         \
38     OP(EXT_shadow_samplers)                            \
39     OP(EXT_tessellation_shader)                        \
40     OP(EXT_texture_buffer)                             \
41     OP(EXT_texture_cube_map_array)                     \
42     OP(EXT_YUV_target)                                 \
43     OP(KHR_blend_equation_advanced)                    \
44     OP(NV_EGL_stream_consumer_external)                \
45     OP(NV_shader_framebuffer_fetch)                    \
46     OP(NV_shader_noperspective_interpolation)          \
47     OP(OES_EGL_image_external)                         \
48     OP(OES_EGL_image_external_essl3)                   \
49     OP(OES_sample_variables)                           \
50     OP(OES_shader_multisample_interpolation)           \
51     OP(OES_shader_image_atomic)                        \
52     OP(OES_standard_derivatives)                       \
53     OP(OES_texture_3D)                                 \
54     OP(OES_texture_buffer)                             \
55     OP(OES_texture_cube_map_array)                     \
56     OP(OES_texture_storage_multisample_2d_array)       \
57     OP(OVR_multiview)                                  \
58     OP(OVR_multiview2)                                 \
59     OP(WEBGL_video_texture)
60 
61 namespace sh
62 {
63 
64 #define RETURN_EXTENSION_NAME_CASE(ext) \
65     case TExtension::ext:               \
66         return "GL_" #ext;
67 
GetExtensionNameString(TExtension extension)68 const char *GetExtensionNameString(TExtension extension)
69 {
70     switch (extension)
71     {
72         LIST_EXTENSIONS(RETURN_EXTENSION_NAME_CASE)
73         default:
74             UNREACHABLE();
75             return "";
76     }
77 }
78 
79 #define RETURN_EXTENSION_IF_NAME_MATCHES(ext)  \
80     if (strcmp(extWithoutGLPrefix, #ext) == 0) \
81     {                                          \
82         return TExtension::ext;                \
83     }
84 
GetExtensionByName(const char * extension)85 TExtension GetExtensionByName(const char *extension)
86 {
87     // If first characters of the extension don't equal "GL_", early out.
88     if (strncmp(extension, "GL_", 3) != 0)
89     {
90         return TExtension::UNDEFINED;
91     }
92     const char *extWithoutGLPrefix = extension + 3;
93 
94     LIST_EXTENSIONS(RETURN_EXTENSION_IF_NAME_MATCHES)
95 
96     return TExtension::UNDEFINED;
97 }
98 
GetBehaviorString(TBehavior b)99 const char *GetBehaviorString(TBehavior b)
100 {
101     switch (b)
102     {
103         case EBhRequire:
104             return "require";
105         case EBhEnable:
106             return "enable";
107         case EBhWarn:
108             return "warn";
109         case EBhDisable:
110             return "disable";
111         default:
112             return nullptr;
113     }
114 }
115 
IsExtensionEnabled(const TExtensionBehavior & extBehavior,TExtension extension)116 bool IsExtensionEnabled(const TExtensionBehavior &extBehavior, TExtension extension)
117 {
118     ASSERT(extension != TExtension::UNDEFINED);
119     auto iter = extBehavior.find(extension);
120     return iter != extBehavior.end() &&
121            (iter->second == EBhEnable || iter->second == EBhRequire || iter->second == EBhWarn);
122 }
123 
124 }  // namespace sh
125