1 // 2 // Copyright 2018 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 // entry_point_utils: 7 // These helpers are used in GL/GLES entry point routines. 8 9 #ifndef LIBANGLE_ENTRY_POINT_UTILS_H_ 10 #define LIBANGLE_ENTRY_POINT_UTILS_H_ 11 12 #include "angle_gl.h" 13 #include "common/Optional.h" 14 #include "common/PackedEnums.h" 15 #include "common/angleutils.h" 16 #include "common/mathutil.h" 17 #include "libANGLE/entry_points_enum_autogen.h" 18 19 namespace gl 20 { 21 // A template struct for determining the default value to return for each entry point. 22 template <EntryPoint EP, typename ReturnType> 23 struct DefaultReturnValue; 24 25 // Default return values for each basic return type. 26 template <EntryPoint EP> 27 struct DefaultReturnValue<EP, GLint> 28 { 29 static constexpr GLint kValue = -1; 30 }; 31 32 // This doubles as the GLenum return value. 33 template <EntryPoint EP> 34 struct DefaultReturnValue<EP, GLuint> 35 { 36 static constexpr GLuint kValue = 0; 37 }; 38 39 template <EntryPoint EP> 40 struct DefaultReturnValue<EP, GLboolean> 41 { 42 static constexpr GLboolean kValue = GL_FALSE; 43 }; 44 45 // Catch-all rules for pointer types. 46 template <EntryPoint EP, typename PointerType> 47 struct DefaultReturnValue<EP, const PointerType *> 48 { 49 static constexpr const PointerType *kValue = nullptr; 50 }; 51 52 template <EntryPoint EP, typename PointerType> 53 struct DefaultReturnValue<EP, PointerType *> 54 { 55 static constexpr PointerType *kValue = nullptr; 56 }; 57 58 // Overloaded to return invalid index 59 template <> 60 struct DefaultReturnValue<EntryPoint::GetUniformBlockIndex, GLuint> 61 { 62 static constexpr GLuint kValue = GL_INVALID_INDEX; 63 }; 64 65 // Specialized enum error value. 66 template <> 67 struct DefaultReturnValue<EntryPoint::ClientWaitSync, GLenum> 68 { 69 static constexpr GLenum kValue = GL_WAIT_FAILED; 70 }; 71 72 // glTestFenceNV should still return TRUE for an invalid fence. 73 template <> 74 struct DefaultReturnValue<EntryPoint::TestFenceNV, GLboolean> 75 { 76 static constexpr GLboolean kValue = GL_TRUE; 77 }; 78 79 template <EntryPoint EP, typename ReturnType> 80 constexpr ANGLE_INLINE ReturnType GetDefaultReturnValue() 81 { 82 return DefaultReturnValue<EP, ReturnType>::kValue; 83 } 84 85 #if ANGLE_CAPTURE_ENABLED 86 # define ANGLE_CAPTURE(Func, ...) CaptureCallToFrameCapture(Capture##Func, __VA_ARGS__) 87 #else 88 # define ANGLE_CAPTURE(...) 89 #endif // ANGLE_CAPTURE_ENABLED 90 91 } // namespace gl 92 93 #endif // LIBANGLE_ENTRY_POINT_UTILS_H_ 94