• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2015 Google Inc.
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 #ifndef GrGLTypes_DEFINED
10 #define GrGLTypes_DEFINED
11 
12 #include "include/core/SkRefCnt.h"
13 #include "include/gpu/gl/GrGLConfig.h"
14 
15 /**
16  * Classifies GL contexts by which standard they implement (currently as OpenGL vs. OpenGL ES).
17  */
18 enum GrGLStandard {
19     kNone_GrGLStandard,
20     kGL_GrGLStandard,
21     kGLES_GrGLStandard,
22     kWebGL_GrGLStandard,
23 };
24 static const int kGrGLStandardCnt = 4;
25 
26 // The following allow certain interfaces to be turned off at compile time
27 // (for example, to lower code size).
28 #if SK_ASSUME_GL_ES
29     #define GR_IS_GR_GL(standard) false
30     #define GR_IS_GR_GL_ES(standard) true
31     #define GR_IS_GR_WEBGL(standard) false
32     #define SK_DISABLE_GL_INTERFACE 1
33     #define SK_DISABLE_WEBGL_INTERFACE 1
34 #elif SK_ASSUME_GL
35     #define GR_IS_GR_GL(standard) true
36     #define GR_IS_GR_GL_ES(standard) false
37     #define GR_IS_GR_WEBGL(standard) false
38     #define SK_DISABLE_GL_ES_INTERFACE 1
39     #define SK_DISABLE_WEBGL_INTERFACE 1
40 #elif SK_ASSUME_WEBGL
41     #define GR_IS_GR_GL(standard) false
42     #define GR_IS_GR_GL_ES(standard) false
43     #define GR_IS_GR_WEBGL(standard) true
44     #define SK_DISABLE_GL_ES_INTERFACE 1
45     #define SK_DISABLE_GL_INTERFACE 1
46 #else
47     #define GR_IS_GR_GL(standard) (kGL_GrGLStandard == standard)
48     #define GR_IS_GR_GL_ES(standard) (kGLES_GrGLStandard == standard)
49     #define GR_IS_GR_WEBGL(standard) (kWebGL_GrGLStandard == standard)
50 #endif
51 
52 ///////////////////////////////////////////////////////////////////////////////
53 
54 /**
55  * The supported GL formats represented as an enum. Actual support by GrContext depends on GL
56  * context version and extensions.
57  */
58 enum class GrGLFormat {
59     kUnknown,
60 
61     kRGBA8,
62     kR8,
63     kALPHA8,
64     kLUMINANCE8,
65     kBGRA8,
66     kRGB565,
67     kRGBA16F,
68     kR16F,
69     kRGB8,
70     kRG8,
71     kRGB10_A2,
72     kRGBA4,
73     kRGBA32F,
74     kSRGB8_ALPHA8,
75     kCOMPRESSED_RGB8_ETC2,
76     kCOMPRESSED_ETC1_RGB8,
77     kR16,
78     kRG16,
79     kRGBA16,
80     kRG16F,
81     kLUMINANCE16F,
82     kCOMPRESSED_ASTC_RGB8,
83 
84     kLast = kCOMPRESSED_ASTC_RGB8
85 };
86 
87 ///////////////////////////////////////////////////////////////////////////////
88 /**
89  * Declares typedefs for all the GL functions used in GrGLInterface
90  */
91 
92 typedef unsigned int GrGLenum;
93 typedef unsigned char GrGLboolean;
94 typedef unsigned int GrGLbitfield;
95 typedef signed char GrGLbyte;
96 typedef char GrGLchar;
97 typedef short GrGLshort;
98 typedef int GrGLint;
99 typedef int GrGLsizei;
100 typedef int64_t GrGLint64;
101 typedef unsigned char GrGLubyte;
102 typedef unsigned short GrGLushort;
103 typedef unsigned int GrGLuint;
104 typedef uint64_t GrGLuint64;
105 typedef unsigned short int GrGLhalf;
106 typedef float GrGLfloat;
107 typedef float GrGLclampf;
108 typedef double GrGLdouble;
109 typedef double GrGLclampd;
110 typedef void GrGLvoid;
111 #ifdef _WIN64
112 typedef signed long long int GrGLintptr;
113 typedef signed long long int GrGLsizeiptr;
114 #else
115 typedef signed long int GrGLintptr;
116 typedef signed long int GrGLsizeiptr;
117 #endif
118 typedef void* GrGLeglImage;
119 typedef struct __GLsync* GrGLsync;
120 
121 struct GrGLDrawArraysIndirectCommand {
122     GrGLuint fCount;
123     GrGLuint fInstanceCount;
124     GrGLuint fFirst;
125     GrGLuint fBaseInstance;  // Requires EXT_base_instance on ES.
126 };
127 
128 GR_STATIC_ASSERT(16 == sizeof(GrGLDrawArraysIndirectCommand));
129 
130 struct GrGLDrawElementsIndirectCommand {
131     GrGLuint fCount;
132     GrGLuint fInstanceCount;
133     GrGLuint fFirstIndex;
134     GrGLuint fBaseVertex;
135     GrGLuint fBaseInstance;  // Requires EXT_base_instance on ES.
136 };
137 
138 GR_STATIC_ASSERT(20 == sizeof(GrGLDrawElementsIndirectCommand));
139 
140 /**
141  * KHR_debug
142  */
143 typedef void (GR_GL_FUNCTION_TYPE* GRGLDEBUGPROC)(GrGLenum source,
144                                                   GrGLenum type,
145                                                   GrGLuint id,
146                                                   GrGLenum severity,
147                                                   GrGLsizei length,
148                                                   const GrGLchar* message,
149                                                   const void* userParam);
150 
151 /**
152  * EGL types.
153  */
154 typedef void* GrEGLImage;
155 typedef void* GrEGLDisplay;
156 typedef void* GrEGLContext;
157 typedef void* GrEGLClientBuffer;
158 typedef unsigned int GrEGLenum;
159 typedef int32_t GrEGLint;
160 typedef unsigned int GrEGLBoolean;
161 
162 ///////////////////////////////////////////////////////////////////////////////
163 /**
164  * Types for interacting with GL resources created externally to Skia. GrBackendObjects for GL
165  * textures are really const GrGLTexture*. The fFormat here should be a sized, internal format
166  * for the texture. We will try to use the sized format if the GL Context supports it, otherwise
167  * we will internally fall back to using the base internal formats.
168  */
169 struct GrGLTextureInfo {
170     GrGLenum fTarget;
171     GrGLuint fID;
172     GrGLenum fFormat = 0;
173 
174     bool operator==(const GrGLTextureInfo& that) const {
175         return fTarget == that.fTarget && fID == that.fID && fFormat == that.fFormat;
176     }
177 };
178 
179 struct GrGLFramebufferInfo {
180     GrGLuint fFBOID;
181     GrGLenum fFormat = 0;
182 
183     bool operator==(const GrGLFramebufferInfo& that) const {
184         return fFBOID == that.fFBOID && fFormat == that.fFormat;
185     }
186 };
187 
188 #endif
189