bsalomon | 2fc11d3 | 2015-10-19 09:03:23 -0700 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkRefCnt.h" |
| 13 | #include "include/gpu/gl/GrGLConfig.h" |
bsalomon | 2fc11d3 | 2015-10-19 09:03:23 -0700 | [diff] [blame] | 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, |
Kevin Lubick | 3902628 | 2019-03-28 12:46:40 -0400 | [diff] [blame] | 22 | kWebGL_GrGLStandard, |
bsalomon | 2fc11d3 | 2015-10-19 09:03:23 -0700 | [diff] [blame] | 23 | }; |
Kevin Lubick | 3902628 | 2019-03-28 12:46:40 -0400 | [diff] [blame] | 24 | static const int kGrGLStandardCnt = 4; |
bsalomon | 2fc11d3 | 2015-10-19 09:03:23 -0700 | [diff] [blame] | 25 | |
Kevin Lubick | 8aa203c | 2019-03-19 13:23:10 -0400 | [diff] [blame] | 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 |
Kevin Lubick | 3902628 | 2019-03-28 12:46:40 -0400 | [diff] [blame] | 31 | #define GR_IS_GR_WEBGL(standard) false |
Kevin Lubick | 8aa203c | 2019-03-19 13:23:10 -0400 | [diff] [blame] | 32 | #define SK_DISABLE_GL_INTERFACE 1 |
Kevin Lubick | 3902628 | 2019-03-28 12:46:40 -0400 | [diff] [blame] | 33 | #define SK_DISABLE_WEBGL_INTERFACE 1 |
Kevin Lubick | 8aa203c | 2019-03-19 13:23:10 -0400 | [diff] [blame] | 34 | #elif SK_ASSUME_GL |
| 35 | #define GR_IS_GR_GL(standard) true |
| 36 | #define GR_IS_GR_GL_ES(standard) false |
Kevin Lubick | 3902628 | 2019-03-28 12:46:40 -0400 | [diff] [blame] | 37 | #define GR_IS_GR_WEBGL(standard) false |
Kevin Lubick | 8aa203c | 2019-03-19 13:23:10 -0400 | [diff] [blame] | 38 | #define SK_DISABLE_GL_ES_INTERFACE 1 |
Kevin Lubick | 3902628 | 2019-03-28 12:46:40 -0400 | [diff] [blame] | 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 |
Kevin Lubick | 8aa203c | 2019-03-19 13:23:10 -0400 | [diff] [blame] | 46 | #else |
| 47 | #define GR_IS_GR_GL(standard) (kGL_GrGLStandard == standard) |
| 48 | #define GR_IS_GR_GL_ES(standard) (kGLES_GrGLStandard == standard) |
Kevin Lubick | 3902628 | 2019-03-28 12:46:40 -0400 | [diff] [blame] | 49 | #define GR_IS_GR_WEBGL(standard) (kWebGL_GrGLStandard == standard) |
Kevin Lubick | 8aa203c | 2019-03-19 13:23:10 -0400 | [diff] [blame] | 50 | #endif |
| 51 | |
bsalomon | 2fc11d3 | 2015-10-19 09:03:23 -0700 | [diff] [blame] | 52 | /////////////////////////////////////////////////////////////////////////////// |
| 53 | |
| 54 | /** |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 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, |
Brian Salomon | 01ff538 | 2020-12-15 16:06:26 -0500 | [diff] [blame] | 65 | kLUMINANCE8_ALPHA8, |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 66 | kBGRA8, |
| 67 | kRGB565, |
| 68 | kRGBA16F, |
| 69 | kR16F, |
| 70 | kRGB8, |
| 71 | kRG8, |
| 72 | kRGB10_A2, |
| 73 | kRGBA4, |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 74 | kSRGB8_ALPHA8, |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 75 | kCOMPRESSED_ETC1_RGB8, |
Robert Phillips | b085527 | 2020-01-15 12:56:52 -0500 | [diff] [blame] | 76 | kCOMPRESSED_RGB8_ETC2, |
Robert Phillips | 8f259a0 | 2019-12-20 11:32:27 -0500 | [diff] [blame] | 77 | kCOMPRESSED_RGB8_BC1, |
Robert Phillips | b085527 | 2020-01-15 12:56:52 -0500 | [diff] [blame] | 78 | kCOMPRESSED_RGBA8_BC1, |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 79 | kR16, |
| 80 | kRG16, |
| 81 | kRGBA16, |
| 82 | kRG16F, |
| 83 | kLUMINANCE16F, |
| 84 | |
Greg Daniel | a7f69c2 | 2020-10-07 13:04:15 -0400 | [diff] [blame] | 85 | kLastColorFormat = kLUMINANCE16F, |
| 86 | |
| 87 | // Depth/Stencil formats |
| 88 | kSTENCIL_INDEX8, |
| 89 | kSTENCIL_INDEX16, |
| 90 | kDEPTH24_STENCIL8, |
| 91 | |
| 92 | kLast = kDEPTH24_STENCIL8 |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | /////////////////////////////////////////////////////////////////////////////// |
| 96 | /** |
bsalomon | 2fc11d3 | 2015-10-19 09:03:23 -0700 | [diff] [blame] | 97 | * Declares typedefs for all the GL functions used in GrGLInterface |
| 98 | */ |
| 99 | |
| 100 | typedef unsigned int GrGLenum; |
| 101 | typedef unsigned char GrGLboolean; |
| 102 | typedef unsigned int GrGLbitfield; |
| 103 | typedef signed char GrGLbyte; |
| 104 | typedef char GrGLchar; |
| 105 | typedef short GrGLshort; |
| 106 | typedef int GrGLint; |
| 107 | typedef int GrGLsizei; |
| 108 | typedef int64_t GrGLint64; |
| 109 | typedef unsigned char GrGLubyte; |
| 110 | typedef unsigned short GrGLushort; |
| 111 | typedef unsigned int GrGLuint; |
| 112 | typedef uint64_t GrGLuint64; |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 113 | typedef unsigned short int GrGLhalf; |
bsalomon | 2fc11d3 | 2015-10-19 09:03:23 -0700 | [diff] [blame] | 114 | typedef float GrGLfloat; |
| 115 | typedef float GrGLclampf; |
| 116 | typedef double GrGLdouble; |
| 117 | typedef double GrGLclampd; |
| 118 | typedef void GrGLvoid; |
bsalomon | 2fc11d3 | 2015-10-19 09:03:23 -0700 | [diff] [blame] | 119 | #ifdef _WIN64 |
| 120 | typedef signed long long int GrGLintptr; |
| 121 | typedef signed long long int GrGLsizeiptr; |
| 122 | #else |
| 123 | typedef signed long int GrGLintptr; |
| 124 | typedef signed long int GrGLsizeiptr; |
| 125 | #endif |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 126 | typedef void* GrGLeglImage; |
Brian Salomon | 9dab18f | 2017-04-08 09:31:29 -0400 | [diff] [blame] | 127 | typedef struct __GLsync* GrGLsync; |
cdalton | 06604b9 | 2016-02-05 10:09:51 -0800 | [diff] [blame] | 128 | |
| 129 | struct GrGLDrawArraysIndirectCommand { |
| 130 | GrGLuint fCount; |
| 131 | GrGLuint fInstanceCount; |
| 132 | GrGLuint fFirst; |
| 133 | GrGLuint fBaseInstance; // Requires EXT_base_instance on ES. |
| 134 | }; |
| 135 | |
Brian Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 136 | // static_asserts must have messages in this file because its included in C++14 client code. |
| 137 | static_assert(16 == sizeof(GrGLDrawArraysIndirectCommand), ""); |
cdalton | 06604b9 | 2016-02-05 10:09:51 -0800 | [diff] [blame] | 138 | |
| 139 | struct 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 Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 147 | static_assert(20 == sizeof(GrGLDrawElementsIndirectCommand), ""); |
cdalton | 06604b9 | 2016-02-05 10:09:51 -0800 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * KHR_debug |
| 151 | */ |
| 152 | typedef 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 | |
bsalomon | b1a32ad | 2015-11-16 06:48:44 -0800 | [diff] [blame] | 160 | /** |
| 161 | * EGL types. |
| 162 | */ |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 163 | typedef void* GrEGLImage; |
bsalomon | b1a32ad | 2015-11-16 06:48:44 -0800 | [diff] [blame] | 164 | typedef void* GrEGLDisplay; |
| 165 | typedef void* GrEGLContext; |
| 166 | typedef void* GrEGLClientBuffer; |
| 167 | typedef unsigned int GrEGLenum; |
| 168 | typedef int32_t GrEGLint; |
| 169 | typedef unsigned int GrEGLBoolean; |
| 170 | |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 171 | /////////////////////////////////////////////////////////////////////////////// |
| 172 | /** |
| 173 | * Types for interacting with GL resources created externally to Skia. GrBackendObjects for GL |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 174 | * 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. |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 177 | */ |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 178 | struct GrGLTextureInfo { |
| 179 | GrGLenum fTarget; |
| 180 | GrGLuint fID; |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 181 | GrGLenum fFormat = 0; |
Robert Phillips | c550995 | 2018-04-04 15:54:55 -0400 | [diff] [blame] | 182 | |
| 183 | bool operator==(const GrGLTextureInfo& that) const { |
| 184 | return fTarget == that.fTarget && fID == that.fID && fFormat == that.fFormat; |
| 185 | } |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 186 | }; |
| 187 | |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 188 | struct GrGLFramebufferInfo { |
| 189 | GrGLuint fFBOID; |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 190 | GrGLenum fFormat = 0; |
Robert Phillips | 8caf85f | 2018-04-05 09:30:38 -0400 | [diff] [blame] | 191 | |
| 192 | bool operator==(const GrGLFramebufferInfo& that) const { |
| 193 | return fFBOID == that.fFBOID && fFormat == that.fFormat; |
| 194 | } |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 195 | }; |
| 196 | |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 197 | struct 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 | |
bsalomon | 2fc11d3 | 2015-10-19 09:03:23 -0700 | [diff] [blame] | 206 | #endif |