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