• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2012 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 
7 // renderergl_utils.h: Conversion functions and other utility routines
8 // specific to the OpenGL renderer.
9 
10 #ifndef LIBANGLE_RENDERER_GL_RENDERERGLUTILS_H_
11 #define LIBANGLE_RENDERER_GL_RENDERERGLUTILS_H_
12 
13 #include "common/debug.h"
14 #include "libANGLE/Error.h"
15 #include "libANGLE/Version.h"
16 #include "libANGLE/angletypes.h"
17 #include "libANGLE/renderer/driver_utils.h"
18 #include "libANGLE/renderer/gl/functionsgl_typedefs.h"
19 
20 #include <string>
21 #include <vector>
22 
23 namespace angle
24 {
25 struct FeaturesGL;
26 struct FrontendFeatures;
27 }  // namespace angle
28 
29 namespace gl
30 {
31 struct Caps;
32 class TextureCapsMap;
33 struct Extensions;
34 struct Version;
35 }  // namespace gl
36 
37 namespace rx
38 {
39 class BlitGL;
40 class ClearMultiviewGL;
41 class ContextGL;
42 class FunctionsGL;
43 class StateManagerGL;
44 enum class MultiviewImplementationTypeGL
45 {
46     NV_VIEWPORT_ARRAY2,
47     UNSPECIFIED
48 };
49 
50 // State-tracking data for the swap control to allow DisplayGL to remember per
51 // drawable information for swap control.
52 struct SwapControlData
53 {
54     SwapControlData();
55 
56     // Set by the drawable
57     int targetSwapInterval;
58 
59     // DisplayGL-side state-tracking
60     int maxSwapInterval;
61     int currentSwapInterval;
62 };
63 
64 VendorID GetVendorID(const FunctionsGL *functions);
65 
66 // Helpers for extracting the GL helper objects out of a context
67 const FunctionsGL *GetFunctionsGL(const gl::Context *context);
68 StateManagerGL *GetStateManagerGL(const gl::Context *context);
69 BlitGL *GetBlitGL(const gl::Context *context);
70 ClearMultiviewGL *GetMultiviewClearer(const gl::Context *context);
71 const angle::FeaturesGL &GetFeaturesGL(const gl::Context *context);
72 
73 // Clear all errors on the stored context, emits console warnings
74 void ClearErrors(const gl::Context *context,
75                  const char *file,
76                  const char *function,
77                  unsigned int line);
78 
79 // Check for a single error
80 angle::Result CheckError(const gl::Context *context,
81                          const char *call,
82                          const char *file,
83                          const char *function,
84                          unsigned int line);
85 
86 #define ANGLE_GL_TRY_ALWAYS_CHECK(context, call)                      \
87     (ClearErrors(context, __FILE__, __FUNCTION__, __LINE__), (call)); \
88     ANGLE_TRY(CheckError(context, #call, __FILE__, __FUNCTION__, __LINE__))
89 
90 #if defined(ANGLE_ENABLE_ASSERTS)
91 #    define ANGLE_GL_TRY(context, call) ANGLE_GL_TRY_ALWAYS_CHECK(context, call)
92 #else
93 #    define ANGLE_GL_TRY(context, call) call
94 #endif
95 
96 namespace nativegl_gl
97 {
98 
99 void GenerateCaps(const FunctionsGL *functions,
100                   const angle::FeaturesGL &features,
101                   gl::Caps *caps,
102                   gl::TextureCapsMap *textureCapsMap,
103                   gl::Extensions *extensions,
104                   gl::Version *maxSupportedESVersion,
105                   MultiviewImplementationTypeGL *multiviewImplementationType);
106 
107 void InitializeFeatures(const FunctionsGL *functions, angle::FeaturesGL *features);
108 void InitializeFrontendFeatures(const FunctionsGL *functions, angle::FrontendFeatures *features);
109 }  // namespace nativegl_gl
110 
111 namespace nativegl
112 {
113 bool SupportsCompute(const FunctionsGL *functions);
114 bool SupportsFenceSync(const FunctionsGL *functions);
115 bool SupportsOcclusionQueries(const FunctionsGL *functions);
116 bool SupportsNativeRendering(const FunctionsGL *functions,
117                              gl::TextureType type,
118                              GLenum internalFormat);
119 bool SupportsTexImage(gl::TextureType type);
120 bool UseTexImage2D(gl::TextureType textureType);
121 bool UseTexImage3D(gl::TextureType textureType);
122 GLenum GetTextureBindingQuery(gl::TextureType textureType);
123 GLenum GetTextureBindingTarget(gl::TextureType textureType);
124 GLenum GetTextureBindingTarget(gl::TextureTarget textureTarget);
125 GLenum GetBufferBindingQuery(gl::BufferBinding bufferBinding);
126 std::string GetBufferBindingString(gl::BufferBinding bufferBinding);
127 gl::TextureType GetNativeTextureType(gl::TextureType type);
128 gl::TextureTarget GetNativeTextureTarget(gl::TextureTarget target);
129 }  // namespace nativegl
130 
131 bool CanMapBufferForRead(const FunctionsGL *functions);
132 uint8_t *MapBufferRangeWithFallback(const FunctionsGL *functions,
133                                     GLenum target,
134                                     size_t offset,
135                                     size_t length,
136                                     GLbitfield access);
137 
138 angle::Result ShouldApplyLastRowPaddingWorkaround(ContextGL *contextGL,
139                                                   const gl::Extents &size,
140                                                   const gl::PixelStoreStateBase &state,
141                                                   const gl::Buffer *pixelBuffer,
142                                                   GLenum format,
143                                                   GLenum type,
144                                                   bool is3D,
145                                                   const void *pixels,
146                                                   bool *shouldApplyOut);
147 
148 struct ContextCreationTry
149 {
150     enum class Type
151     {
152         DESKTOP_CORE,
153         DESKTOP_LEGACY,
154         ES,
155     };
156 
ContextCreationTryContextCreationTry157     ContextCreationTry(EGLint displayType, Type type, gl::Version version)
158         : displayType(displayType), type(type), version(version)
159     {}
160 
161     EGLint displayType;
162     Type type;
163     gl::Version version;
164 };
165 
166 std::vector<ContextCreationTry> GenerateContextCreationToTry(EGLint requestedType, bool isMesaGLX);
167 }  // namespace rx
168 
169 #endif  // LIBANGLE_RENDERER_GL_RENDERERGLUTILS_H_
170