• 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 VendorID GetVendorID(const FunctionsGL *functions);
51 
52 // Helpers for extracting the GL helper objects out of a context
53 const FunctionsGL *GetFunctionsGL(const gl::Context *context);
54 StateManagerGL *GetStateManagerGL(const gl::Context *context);
55 BlitGL *GetBlitGL(const gl::Context *context);
56 ClearMultiviewGL *GetMultiviewClearer(const gl::Context *context);
57 const angle::FeaturesGL &GetFeaturesGL(const gl::Context *context);
58 
59 // Clear all errors on the stored context, emits console warnings
60 void ClearErrors(const gl::Context *context,
61                  const char *file,
62                  const char *function,
63                  unsigned int line);
64 
65 // Check for a single error
66 angle::Result CheckError(const gl::Context *context,
67                          const char *call,
68                          const char *file,
69                          const char *function,
70                          unsigned int line);
71 
72 #define ANGLE_GL_TRY_ALWAYS_CHECK(context, call)                      \
73     (ClearErrors(context, __FILE__, __FUNCTION__, __LINE__), (call)); \
74     ANGLE_TRY(CheckError(context, #call, __FILE__, __FUNCTION__, __LINE__))
75 
76 #if defined(ANGLE_ENABLE_ASSERTS)
77 #    define ANGLE_GL_TRY(context, call) ANGLE_GL_TRY_ALWAYS_CHECK(context, call)
78 #else
79 #    define ANGLE_GL_TRY(context, call) call
80 #endif
81 
82 namespace nativegl_gl
83 {
84 
85 void GenerateCaps(const FunctionsGL *functions,
86                   const angle::FeaturesGL &features,
87                   gl::Caps *caps,
88                   gl::TextureCapsMap *textureCapsMap,
89                   gl::Extensions *extensions,
90                   gl::Version *maxSupportedESVersion,
91                   MultiviewImplementationTypeGL *multiviewImplementationType);
92 
93 void InitializeFeatures(const FunctionsGL *functions, angle::FeaturesGL *features);
94 void InitializeFrontendFeatures(const FunctionsGL *functions, angle::FrontendFeatures *features);
95 }  // namespace nativegl_gl
96 
97 namespace nativegl
98 {
99 bool SupportsCompute(const FunctionsGL *functions);
100 bool SupportsFenceSync(const FunctionsGL *functions);
101 bool SupportsOcclusionQueries(const FunctionsGL *functions);
102 bool SupportsNativeRendering(const FunctionsGL *functions,
103                              gl::TextureType type,
104                              GLenum internalFormat);
105 bool SupportsTexImage(gl::TextureType type);
106 bool UseTexImage2D(gl::TextureType textureType);
107 bool UseTexImage3D(gl::TextureType textureType);
108 GLenum GetTextureBindingQuery(gl::TextureType textureType);
109 GLenum GetTextureBindingTarget(gl::TextureType textureType);
110 GLenum GetTextureBindingTarget(gl::TextureTarget textureTarget);
111 GLenum GetBufferBindingQuery(gl::BufferBinding bufferBinding);
112 std::string GetBufferBindingString(gl::BufferBinding bufferBinding);
113 gl::TextureType GetNativeTextureType(gl::TextureType type);
114 gl::TextureTarget GetNativeTextureTarget(gl::TextureTarget target);
115 }  // namespace nativegl
116 
117 bool CanMapBufferForRead(const FunctionsGL *functions);
118 uint8_t *MapBufferRangeWithFallback(const FunctionsGL *functions,
119                                     GLenum target,
120                                     size_t offset,
121                                     size_t length,
122                                     GLbitfield access);
123 
124 angle::Result ShouldApplyLastRowPaddingWorkaround(ContextGL *contextGL,
125                                                   const gl::Extents &size,
126                                                   const gl::PixelStoreStateBase &state,
127                                                   const gl::Buffer *pixelBuffer,
128                                                   GLenum format,
129                                                   GLenum type,
130                                                   bool is3D,
131                                                   const void *pixels,
132                                                   bool *shouldApplyOut);
133 
134 struct ContextCreationTry
135 {
136     enum class Type
137     {
138         DESKTOP_CORE,
139         DESKTOP_LEGACY,
140         ES,
141     };
142 
ContextCreationTryContextCreationTry143     ContextCreationTry(EGLint displayType, Type type, gl::Version version)
144         : displayType(displayType), type(type), version(version)
145     {}
146 
147     EGLint displayType;
148     Type type;
149     gl::Version version;
150 };
151 
152 std::vector<ContextCreationTry> GenerateContextCreationToTry(EGLint requestedType, bool isMesaGLX);
153 }  // namespace rx
154 
155 #endif  // LIBANGLE_RENDERER_GL_RENDERERGLUTILS_H_
156