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