blob: 49f5ee7bf6b6dad54bd54874b3af5c23d02d07c5 [file] [log] [blame]
bsalomon2fc11d32015-10-19 09:03:23 -07001
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkRefCnt.h"
13#include "include/gpu/gl/GrGLConfig.h"
bsalomon2fc11d32015-10-19 09:03:23 -070014
15/**
16 * Classifies GL contexts by which standard they implement (currently as OpenGL vs. OpenGL ES).
17 */
18enum GrGLStandard {
19 kNone_GrGLStandard,
20 kGL_GrGLStandard,
21 kGLES_GrGLStandard,
Kevin Lubick39026282019-03-28 12:46:40 -040022 kWebGL_GrGLStandard,
bsalomon2fc11d32015-10-19 09:03:23 -070023};
Kevin Lubick39026282019-03-28 12:46:40 -040024static const int kGrGLStandardCnt = 4;
bsalomon2fc11d32015-10-19 09:03:23 -070025
Kevin Lubick8aa203c2019-03-19 13:23:10 -040026// 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
Kevin Lubick39026282019-03-28 12:46:40 -040031 #define GR_IS_GR_WEBGL(standard) false
Kevin Lubick8aa203c2019-03-19 13:23:10 -040032 #define SK_DISABLE_GL_INTERFACE 1
Kevin Lubick39026282019-03-28 12:46:40 -040033 #define SK_DISABLE_WEBGL_INTERFACE 1
Kevin Lubick8aa203c2019-03-19 13:23:10 -040034#elif SK_ASSUME_GL
35 #define GR_IS_GR_GL(standard) true
36 #define GR_IS_GR_GL_ES(standard) false
Kevin Lubick39026282019-03-28 12:46:40 -040037 #define GR_IS_GR_WEBGL(standard) false
Kevin Lubick8aa203c2019-03-19 13:23:10 -040038 #define SK_DISABLE_GL_ES_INTERFACE 1
Kevin Lubick39026282019-03-28 12:46:40 -040039 #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
Kevin Lubick8aa203c2019-03-19 13:23:10 -040046#else
47 #define GR_IS_GR_GL(standard) (kGL_GrGLStandard == standard)
48 #define GR_IS_GR_GL_ES(standard) (kGLES_GrGLStandard == standard)
Kevin Lubick39026282019-03-28 12:46:40 -040049 #define GR_IS_GR_WEBGL(standard) (kWebGL_GrGLStandard == standard)
Kevin Lubick8aa203c2019-03-19 13:23:10 -040050#endif
51
bsalomon2fc11d32015-10-19 09:03:23 -070052///////////////////////////////////////////////////////////////////////////////
53
54/**
Brian Salomond4764a12019-08-08 12:08:24 -040055 * The supported GL formats represented as an enum. Actual support by GrContext depends on GL
56 * context version and extensions.
57 */
58enum class GrGLFormat {
59 kUnknown,
60
61 kRGBA8,
62 kR8,
63 kALPHA8,
64 kLUMINANCE8,
Brian Salomon01ff5382020-12-15 16:06:26 -050065 kLUMINANCE8_ALPHA8,
Brian Salomond4764a12019-08-08 12:08:24 -040066 kBGRA8,
67 kRGB565,
68 kRGBA16F,
69 kR16F,
70 kRGB8,
71 kRG8,
72 kRGB10_A2,
73 kRGBA4,
Brian Salomond4764a12019-08-08 12:08:24 -040074 kSRGB8_ALPHA8,
Brian Salomond4764a12019-08-08 12:08:24 -040075 kCOMPRESSED_ETC1_RGB8,
Robert Phillipsb0855272020-01-15 12:56:52 -050076 kCOMPRESSED_RGB8_ETC2,
Robert Phillips8f259a02019-12-20 11:32:27 -050077 kCOMPRESSED_RGB8_BC1,
Robert Phillipsb0855272020-01-15 12:56:52 -050078 kCOMPRESSED_RGBA8_BC1,
Brian Salomond4764a12019-08-08 12:08:24 -040079 kR16,
80 kRG16,
81 kRGBA16,
82 kRG16F,
83 kLUMINANCE16F,
84
Greg Daniela7f69c22020-10-07 13:04:15 -040085 kLastColorFormat = kLUMINANCE16F,
86
87 // Depth/Stencil formats
88 kSTENCIL_INDEX8,
89 kSTENCIL_INDEX16,
90 kDEPTH24_STENCIL8,
91
92 kLast = kDEPTH24_STENCIL8
Brian Salomond4764a12019-08-08 12:08:24 -040093};
94
95///////////////////////////////////////////////////////////////////////////////
96/**
bsalomon2fc11d32015-10-19 09:03:23 -070097 * Declares typedefs for all the GL functions used in GrGLInterface
98 */
99
100typedef unsigned int GrGLenum;
101typedef unsigned char GrGLboolean;
102typedef unsigned int GrGLbitfield;
103typedef signed char GrGLbyte;
104typedef char GrGLchar;
105typedef short GrGLshort;
106typedef int GrGLint;
107typedef int GrGLsizei;
108typedef int64_t GrGLint64;
109typedef unsigned char GrGLubyte;
110typedef unsigned short GrGLushort;
111typedef unsigned int GrGLuint;
112typedef uint64_t GrGLuint64;
Brian Salomon26de56e2019-04-10 12:14:26 -0400113typedef unsigned short int GrGLhalf;
bsalomon2fc11d32015-10-19 09:03:23 -0700114typedef float GrGLfloat;
115typedef float GrGLclampf;
116typedef double GrGLdouble;
117typedef double GrGLclampd;
118typedef void GrGLvoid;
bsalomon2fc11d32015-10-19 09:03:23 -0700119#ifdef _WIN64
120typedef signed long long int GrGLintptr;
121typedef signed long long int GrGLsizeiptr;
122#else
123typedef signed long int GrGLintptr;
124typedef signed long int GrGLsizeiptr;
125#endif
bsalomon7ea33f52015-11-22 14:51:00 -0800126typedef void* GrGLeglImage;
Brian Salomon9dab18f2017-04-08 09:31:29 -0400127typedef struct __GLsync* GrGLsync;
cdalton06604b92016-02-05 10:09:51 -0800128
129struct GrGLDrawArraysIndirectCommand {
130 GrGLuint fCount;
131 GrGLuint fInstanceCount;
132 GrGLuint fFirst;
133 GrGLuint fBaseInstance; // Requires EXT_base_instance on ES.
134};
135
Brian Salomon4dea72a2019-12-18 10:43:10 -0500136// static_asserts must have messages in this file because its included in C++14 client code.
137static_assert(16 == sizeof(GrGLDrawArraysIndirectCommand), "");
cdalton06604b92016-02-05 10:09:51 -0800138
139struct GrGLDrawElementsIndirectCommand {
140 GrGLuint fCount;
141 GrGLuint fInstanceCount;
142 GrGLuint fFirstIndex;
143 GrGLuint fBaseVertex;
144 GrGLuint fBaseInstance; // Requires EXT_base_instance on ES.
145};
146
Brian Salomon4dea72a2019-12-18 10:43:10 -0500147static_assert(20 == sizeof(GrGLDrawElementsIndirectCommand), "");
cdalton06604b92016-02-05 10:09:51 -0800148
149/**
150 * KHR_debug
151 */
152typedef void (GR_GL_FUNCTION_TYPE* GRGLDEBUGPROC)(GrGLenum source,
153 GrGLenum type,
154 GrGLuint id,
155 GrGLenum severity,
156 GrGLsizei length,
157 const GrGLchar* message,
158 const void* userParam);
159
bsalomonb1a32ad2015-11-16 06:48:44 -0800160/**
161 * EGL types.
162 */
bsalomon7ea33f52015-11-22 14:51:00 -0800163typedef void* GrEGLImage;
bsalomonb1a32ad2015-11-16 06:48:44 -0800164typedef void* GrEGLDisplay;
165typedef void* GrEGLContext;
166typedef void* GrEGLClientBuffer;
167typedef unsigned int GrEGLenum;
168typedef int32_t GrEGLint;
169typedef unsigned int GrEGLBoolean;
170
bsalomon091f60c2015-11-10 11:54:56 -0800171///////////////////////////////////////////////////////////////////////////////
172/**
173 * Types for interacting with GL resources created externally to Skia. GrBackendObjects for GL
Greg Daniele7d8da42017-12-04 11:23:19 -0500174 * textures are really const GrGLTexture*. The fFormat here should be a sized, internal format
175 * for the texture. We will try to use the sized format if the GL Context supports it, otherwise
176 * we will internally fall back to using the base internal formats.
bsalomon091f60c2015-11-10 11:54:56 -0800177 */
bsalomon091f60c2015-11-10 11:54:56 -0800178struct GrGLTextureInfo {
179 GrGLenum fTarget;
180 GrGLuint fID;
Greg Daniele7d8da42017-12-04 11:23:19 -0500181 GrGLenum fFormat = 0;
Robert Phillipsc5509952018-04-04 15:54:55 -0400182
183 bool operator==(const GrGLTextureInfo& that) const {
184 return fTarget == that.fTarget && fID == that.fID && fFormat == that.fFormat;
185 }
bsalomon091f60c2015-11-10 11:54:56 -0800186};
187
Greg Danielbcf612b2017-05-01 13:50:58 +0000188struct GrGLFramebufferInfo {
189 GrGLuint fFBOID;
Greg Danielfaa095e2017-12-19 13:15:02 -0500190 GrGLenum fFormat = 0;
Robert Phillips8caf85f2018-04-05 09:30:38 -0400191
192 bool operator==(const GrGLFramebufferInfo& that) const {
193 return fFBOID == that.fFBOID && fFormat == that.fFormat;
194 }
Greg Danielbcf612b2017-05-01 13:50:58 +0000195};
196
Greg Daniel84261652021-09-19 17:53:40 -0400197struct GrGLSurfaceInfo {
198 uint32_t fSampleCount = 1;
199 uint32_t fLevelCount = 0;
200 GrProtected fProtected = GrProtected::kNo;
201
202 GrGLenum fTarget = 0;
203 GrGLenum fFormat = 0;
204};
205
bsalomon2fc11d32015-10-19 09:03:23 -0700206#endif