reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 8 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 9 | #include "GrGpuGL.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 10 | #include "GrGLStencilBuffer.h" |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 11 | #include "GrGLPath.h" |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 12 | #include "GrGLShaderBuilder.h" |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 13 | #include "GrTemplates.h" |
senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 14 | #include "GrTypes.h" |
bsalomon@google.com | 3582bf9 | 2011-06-30 21:32:31 +0000 | [diff] [blame] | 15 | #include "SkTemplates.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 16 | |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 17 | static const GrGLuint GR_MAX_GLUINT = ~0U; |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 18 | static const GrGLint GR_INVAL_GLINT = ~0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 19 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 20 | #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 21 | #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X) |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 22 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 23 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 24 | #define SKIP_CACHE_CHECK true |
| 25 | |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 26 | #if GR_GL_CHECK_ALLOC_WITH_GET_ERROR |
| 27 | #define CLEAR_ERROR_BEFORE_ALLOC(iface) GrGLClearErr(iface) |
| 28 | #define GL_ALLOC_CALL(iface, call) GR_GL_CALL_NOERRCHECK(iface, call) |
| 29 | #define CHECK_ALLOC_ERROR(iface) GR_GL_GET_ERROR(iface) |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 30 | #else |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 31 | #define CLEAR_ERROR_BEFORE_ALLOC(iface) |
| 32 | #define GL_ALLOC_CALL(iface, call) GR_GL_CALL(iface, call) |
| 33 | #define CHECK_ALLOC_ERROR(iface) GR_GL_NO_ERROR |
| 34 | #endif |
| 35 | |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 36 | |
| 37 | /////////////////////////////////////////////////////////////////////////////// |
| 38 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 39 | static const GrGLenum gXfermodeCoeff2Blend[] = { |
| 40 | GR_GL_ZERO, |
| 41 | GR_GL_ONE, |
| 42 | GR_GL_SRC_COLOR, |
| 43 | GR_GL_ONE_MINUS_SRC_COLOR, |
| 44 | GR_GL_DST_COLOR, |
| 45 | GR_GL_ONE_MINUS_DST_COLOR, |
| 46 | GR_GL_SRC_ALPHA, |
| 47 | GR_GL_ONE_MINUS_SRC_ALPHA, |
| 48 | GR_GL_DST_ALPHA, |
| 49 | GR_GL_ONE_MINUS_DST_ALPHA, |
| 50 | GR_GL_CONSTANT_COLOR, |
| 51 | GR_GL_ONE_MINUS_CONSTANT_COLOR, |
| 52 | GR_GL_CONSTANT_ALPHA, |
| 53 | GR_GL_ONE_MINUS_CONSTANT_ALPHA, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 54 | |
| 55 | // extended blend coeffs |
| 56 | GR_GL_SRC1_COLOR, |
| 57 | GR_GL_ONE_MINUS_SRC1_COLOR, |
| 58 | GR_GL_SRC1_ALPHA, |
| 59 | GR_GL_ONE_MINUS_SRC1_ALPHA, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 62 | bool GrGpuGL::BlendCoeffReferencesConstant(GrBlendCoeff coeff) { |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 63 | static const bool gCoeffReferencesBlendConst[] = { |
| 64 | false, |
| 65 | false, |
| 66 | false, |
| 67 | false, |
| 68 | false, |
| 69 | false, |
| 70 | false, |
| 71 | false, |
| 72 | false, |
| 73 | false, |
| 74 | true, |
| 75 | true, |
| 76 | true, |
| 77 | true, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 78 | |
| 79 | // extended blend coeffs |
| 80 | false, |
| 81 | false, |
| 82 | false, |
| 83 | false, |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 84 | }; |
| 85 | return gCoeffReferencesBlendConst[coeff]; |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 86 | GR_STATIC_ASSERT(kTotalGrBlendCoeffCount == |
| 87 | GR_ARRAY_COUNT(gCoeffReferencesBlendConst)); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 88 | |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 89 | GR_STATIC_ASSERT(0 == kZero_GrBlendCoeff); |
| 90 | GR_STATIC_ASSERT(1 == kOne_GrBlendCoeff); |
| 91 | GR_STATIC_ASSERT(2 == kSC_GrBlendCoeff); |
| 92 | GR_STATIC_ASSERT(3 == kISC_GrBlendCoeff); |
| 93 | GR_STATIC_ASSERT(4 == kDC_GrBlendCoeff); |
| 94 | GR_STATIC_ASSERT(5 == kIDC_GrBlendCoeff); |
| 95 | GR_STATIC_ASSERT(6 == kSA_GrBlendCoeff); |
| 96 | GR_STATIC_ASSERT(7 == kISA_GrBlendCoeff); |
| 97 | GR_STATIC_ASSERT(8 == kDA_GrBlendCoeff); |
| 98 | GR_STATIC_ASSERT(9 == kIDA_GrBlendCoeff); |
| 99 | GR_STATIC_ASSERT(10 == kConstC_GrBlendCoeff); |
| 100 | GR_STATIC_ASSERT(11 == kIConstC_GrBlendCoeff); |
| 101 | GR_STATIC_ASSERT(12 == kConstA_GrBlendCoeff); |
| 102 | GR_STATIC_ASSERT(13 == kIConstA_GrBlendCoeff); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 103 | |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 104 | GR_STATIC_ASSERT(14 == kS2C_GrBlendCoeff); |
| 105 | GR_STATIC_ASSERT(15 == kIS2C_GrBlendCoeff); |
| 106 | GR_STATIC_ASSERT(16 == kS2A_GrBlendCoeff); |
| 107 | GR_STATIC_ASSERT(17 == kIS2A_GrBlendCoeff); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 108 | |
| 109 | // assertion for gXfermodeCoeff2Blend have to be in GrGpu scope |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 110 | GR_STATIC_ASSERT(kTotalGrBlendCoeffCount == |
| 111 | GR_ARRAY_COUNT(gXfermodeCoeff2Blend)); |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 112 | } |
| 113 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 114 | /////////////////////////////////////////////////////////////////////////////// |
| 115 | |
rileya@google.com | e38160c | 2012-07-03 18:03:04 +0000 | [diff] [blame] | 116 | static bool gPrintStartupSpew; |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 117 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 118 | GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context) |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 119 | : GrGpu(context) |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 120 | , fGLContext(ctx) { |
bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 121 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 122 | GrAssert(ctx.isInitialized()); |
tomhudson@google.com | 747bf29 | 2011-06-14 18:16:52 +0000 | [diff] [blame] | 123 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 124 | fCaps.reset(SkRef(ctx.info().caps())); |
| 125 | |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 126 | fHWBoundTextures.reset(ctx.info().caps()->maxFragmentTextureUnits()); |
| 127 | |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 128 | fillInConfigRenderableTable(); |
| 129 | |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 130 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 131 | GrGLClearErr(fGLContext.interface()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 132 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 133 | if (gPrintStartupSpew) { |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 134 | const GrGLubyte* vendor; |
| 135 | const GrGLubyte* renderer; |
| 136 | const GrGLubyte* version; |
| 137 | GL_CALL_RET(vendor, GetString(GR_GL_VENDOR)); |
| 138 | GL_CALL_RET(renderer, GetString(GR_GL_RENDERER)); |
| 139 | GL_CALL_RET(version, GetString(GR_GL_VERSION)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 140 | GrPrintf("------------------------- create GrGpuGL %p --------------\n", |
| 141 | this); |
| 142 | GrPrintf("------ VENDOR %s\n", vendor); |
| 143 | GrPrintf("------ RENDERER %s\n", renderer); |
| 144 | GrPrintf("------ VERSION %s\n", version); |
bsalomon@google.com | 00142c4 | 2013-05-02 19:42:54 +0000 | [diff] [blame] | 145 | GrPrintf("------ EXTENSIONS\n"); |
| 146 | ctx.info().extensions().print(); |
| 147 | GrPrintf("\n"); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 148 | ctx.info().caps()->print(); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 149 | } |
| 150 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 151 | fProgramCache = SkNEW_ARGS(ProgramCache, (this->glContext())); |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 152 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 153 | GrAssert(this->glCaps().maxVertexAttributes() >= GrDrawState::kMaxVertexAttribCnt); |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 154 | |
bsalomon@google.com | fe67652 | 2011-06-17 18:12:21 +0000 | [diff] [blame] | 155 | fLastSuccessfulStencilFmtIdx = 0; |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 156 | fHWProgramID = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | GrGpuGL::~GrGpuGL() { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 160 | if (0 != fHWProgramID) { |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 161 | // detach the current program so there is no confusion on OpenGL's part |
| 162 | // that we want it to be deleted |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 163 | GrAssert(fHWProgramID == fCurrentProgram->programID()); |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 164 | GL_CALL(UseProgram(0)); |
| 165 | } |
| 166 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 167 | delete fProgramCache; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 168 | |
bsalomon@google.com | 4a018bb | 2011-10-28 19:50:21 +0000 | [diff] [blame] | 169 | // This must be called by before the GrDrawTarget destructor |
| 170 | this->releaseGeometry(); |
bsalomon@google.com | 15b11df | 2011-09-16 21:18:29 +0000 | [diff] [blame] | 171 | // This subclass must do this before the base class destructor runs |
| 172 | // since we will unref the GrGLInterface. |
| 173 | this->releaseResources(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 174 | } |
| 175 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 176 | /////////////////////////////////////////////////////////////////////////////// |
| 177 | |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 178 | void GrGpuGL::fillInConfigRenderableTable() { |
| 179 | |
| 180 | // OpenGL < 3.0 |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 181 | // no support for render targets unless the GL_ARB_framebuffer_object |
| 182 | // extension is supported (in which case we get ALPHA, RED, RG, RGB, |
| 183 | // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 184 | // probably don't get R8 in this case. |
| 185 | |
| 186 | // OpenGL 3.0 |
| 187 | // base color renderable: ALPHA, RED, RG, RGB, and RGBA |
| 188 | // sized derivatives: ALPHA8, R8, RGBA4, RGBA8 |
| 189 | |
| 190 | // >= OpenGL 3.1 |
| 191 | // base color renderable: RED, RG, RGB, and RGBA |
| 192 | // sized derivatives: R8, RGBA4, RGBA8 |
| 193 | // if the GL_ARB_compatibility extension is supported then we get back |
| 194 | // support for GL_ALPHA and ALPHA8 |
| 195 | |
| 196 | // GL_EXT_bgra adds BGRA render targets to any version |
| 197 | |
| 198 | // ES 2.0 |
| 199 | // color renderable: RGBA4, RGB5_A1, RGB565 |
| 200 | // GL_EXT_texture_rg adds support for R8 as a color render target |
| 201 | // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8 |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 202 | // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 203 | |
| 204 | if (kDesktop_GrGLBinding == this->glBinding()) { |
| 205 | // Post 3.0 we will get R8 |
| 206 | // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object) |
| 207 | if (this->glVersion() >= GR_GL_VER(3,0) || |
| 208 | this->hasExtension("GL_ARB_framebuffer_object")) { |
| 209 | fConfigRenderSupport[kAlpha_8_GrPixelConfig] = true; |
| 210 | } |
| 211 | } else { |
| 212 | // On ES we can only hope for R8 |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 213 | fConfigRenderSupport[kAlpha_8_GrPixelConfig] = |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 214 | this->glCaps().textureRedSupport(); |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | if (kDesktop_GrGLBinding != this->glBinding()) { |
| 218 | // only available in ES |
| 219 | fConfigRenderSupport[kRGB_565_GrPixelConfig] = true; |
| 220 | } |
| 221 | |
reed@google.com | 6ba4572 | 2013-06-21 18:30:53 +0000 | [diff] [blame] | 222 | // we no longer support 444 as a render target |
| 223 | fConfigRenderSupport[kRGBA_4444_GrPixelConfig] = false; |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 224 | |
| 225 | if (this->glCaps().rgba8RenderbufferSupport()) { |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 226 | fConfigRenderSupport[kRGBA_8888_GrPixelConfig] = true; |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | if (this->glCaps().bgraFormatSupport()) { |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 230 | fConfigRenderSupport[kBGRA_8888_GrPixelConfig] = true; |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 231 | } |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 232 | } |
| 233 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 234 | namespace { |
commit-bot@chromium.org | 5d1d79a | 2013-05-24 18:52:52 +0000 | [diff] [blame] | 235 | GrPixelConfig preferred_pixel_ops_config(GrPixelConfig cpuConfig, GrPixelConfig surfaceConfig) { |
| 236 | if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == cpuConfig) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 237 | return kBGRA_8888_GrPixelConfig; |
commit-bot@chromium.org | 5d1d79a | 2013-05-24 18:52:52 +0000 | [diff] [blame] | 238 | } else if (GrBytesPerPixel(cpuConfig) == 4 && |
| 239 | GrPixelConfigSwapRAndB(cpuConfig) == surfaceConfig) { |
| 240 | // Mesa 3D takes a slow path on when reading back BGRA from an RGBA surface and vice-versa. |
| 241 | // Perhaps this should be guarded by some compiletime or runtime check. |
| 242 | return surfaceConfig; |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 243 | } else { |
commit-bot@chromium.org | 5d1d79a | 2013-05-24 18:52:52 +0000 | [diff] [blame] | 244 | return cpuConfig; |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 245 | } |
| 246 | } |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 247 | } |
| 248 | |
commit-bot@chromium.org | 5d1d79a | 2013-05-24 18:52:52 +0000 | [diff] [blame] | 249 | GrPixelConfig GrGpuGL::preferredReadPixelsConfig(GrPixelConfig readConfig, |
| 250 | GrPixelConfig surfaceConfig) const { |
| 251 | return preferred_pixel_ops_config(readConfig, surfaceConfig); |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 252 | } |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 253 | |
commit-bot@chromium.org | 5d1d79a | 2013-05-24 18:52:52 +0000 | [diff] [blame] | 254 | GrPixelConfig GrGpuGL::preferredWritePixelsConfig(GrPixelConfig writeConfig, |
| 255 | GrPixelConfig surfaceConfig) const { |
| 256 | return preferred_pixel_ops_config(writeConfig, surfaceConfig); |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | bool GrGpuGL::canWriteTexturePixels(const GrTexture* texture, GrPixelConfig srcConfig) const { |
| 260 | if (kIndex_8_GrPixelConfig == srcConfig || kIndex_8_GrPixelConfig == texture->config()) { |
| 261 | return false; |
| 262 | } |
| 263 | if (srcConfig != texture->config() && kES2_GrGLBinding == this->glBinding()) { |
| 264 | // In general ES2 requires the internal format of the texture and the format of the src |
| 265 | // pixels to match. However, It may or may not be possible to upload BGRA data to a RGBA |
| 266 | // texture. It depends upon which extension added BGRA. The Apple extension allows it |
| 267 | // (BGRA's internal format is RGBA) while the EXT extension does not (BGRA is its own |
| 268 | // internal format). |
| 269 | if (this->glCaps().bgraFormatSupport() && |
| 270 | !this->glCaps().bgraIsInternalFormat() && |
| 271 | kBGRA_8888_GrPixelConfig == srcConfig && |
| 272 | kRGBA_8888_GrPixelConfig == texture->config()) { |
| 273 | return true; |
| 274 | } else { |
| 275 | return false; |
| 276 | } |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 277 | } else { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 278 | return true; |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 282 | bool GrGpuGL::fullReadPixelsIsFasterThanPartial() const { |
| 283 | return SkToBool(GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL); |
| 284 | } |
| 285 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 286 | void GrGpuGL::onResetContext(uint32_t resetBits) { |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 287 | // we don't use the zb at all |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 288 | if (resetBits & kMisc_GrGLBackendState) { |
| 289 | GL_CALL(Disable(GR_GL_DEPTH_TEST)); |
| 290 | GL_CALL(DepthMask(GR_GL_FALSE)); |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 291 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 292 | fHWDrawFace = GrDrawState::kInvalid_DrawFace; |
| 293 | fHWDitherEnabled = kUnknown_TriState; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 294 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 295 | if (kDesktop_GrGLBinding == this->glBinding()) { |
| 296 | // Desktop-only state that we never change |
| 297 | if (!this->glCaps().isCoreProfile()) { |
| 298 | GL_CALL(Disable(GR_GL_POINT_SMOOTH)); |
| 299 | GL_CALL(Disable(GR_GL_LINE_SMOOTH)); |
| 300 | GL_CALL(Disable(GR_GL_POLYGON_SMOOTH)); |
| 301 | GL_CALL(Disable(GR_GL_POLYGON_STIPPLE)); |
| 302 | GL_CALL(Disable(GR_GL_COLOR_LOGIC_OP)); |
| 303 | GL_CALL(Disable(GR_GL_INDEX_LOGIC_OP)); |
| 304 | } |
| 305 | // The windows NVIDIA driver has GL_ARB_imaging in the extension string when using a |
| 306 | // core profile. This seems like a bug since the core spec removes any mention of |
| 307 | // GL_ARB_imaging. |
| 308 | if (this->glCaps().imagingSupport() && !this->glCaps().isCoreProfile()) { |
| 309 | GL_CALL(Disable(GR_GL_COLOR_TABLE)); |
| 310 | } |
| 311 | GL_CALL(Disable(GR_GL_POLYGON_OFFSET_FILL)); |
| 312 | // Since ES doesn't support glPointSize at all we always use the VS to |
| 313 | // set the point size |
| 314 | GL_CALL(Enable(GR_GL_VERTEX_PROGRAM_POINT_SIZE)); |
| 315 | |
| 316 | // We should set glPolygonMode(FRONT_AND_BACK,FILL) here, too. It isn't |
| 317 | // currently part of our gl interface. There are probably others as |
| 318 | // well. |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame] | 319 | } |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 320 | fHWWriteToColor = kUnknown_TriState; |
| 321 | // we only ever use lines in hairline mode |
| 322 | GL_CALL(LineWidth(1)); |
bsalomon@google.com | cad107b | 2013-06-28 14:32:08 +0000 | [diff] [blame] | 323 | } |
edisonn@google.com | ba66999 | 2013-06-28 16:03:21 +0000 | [diff] [blame] | 324 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 325 | if (resetBits & kAA_GrGLBackendState) { |
| 326 | fHWAAState.invalidate(); |
| 327 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 328 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 329 | // invalid |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 330 | if (resetBits & kTextureBinding_GrGLBackendState) { |
| 331 | fHWActiveTextureUnitIdx = -1; |
| 332 | for (int s = 0; s < fHWBoundTextures.count(); ++s) { |
| 333 | fHWBoundTextures[s] = NULL; |
| 334 | } |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 335 | } |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 336 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 337 | if (resetBits & kBlend_GrGLBackendState) { |
| 338 | fHWBlendState.invalidate(); |
| 339 | } |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 340 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 341 | if (resetBits & kView_GrGLBackendState) { |
| 342 | fHWScissorSettings.invalidate(); |
| 343 | fHWViewport.invalidate(); |
| 344 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 345 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 346 | if (resetBits & kStencil_GrGLBackendState) { |
| 347 | fHWStencilSettings.invalidate(); |
| 348 | fHWStencilTestEnabled = kUnknown_TriState; |
| 349 | } |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 350 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 351 | // Vertex |
| 352 | if (resetBits & kVertex_GrGLBackendState) { |
| 353 | fHWGeometryState.invalidate(); |
| 354 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 355 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 356 | if (resetBits & kRenderTarget_GrGLBackendState) { |
| 357 | fHWBoundRenderTarget = NULL; |
| 358 | } |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 359 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 360 | if (resetBits & kPathStencil_GrGLBackendState) { |
| 361 | fHWPathStencilMatrixState.invalidate(); |
| 362 | if (this->caps()->pathStencilingSupport()) { |
| 363 | // we don't use the model view matrix. |
| 364 | GL_CALL(MatrixMode(GR_GL_MODELVIEW)); |
| 365 | GL_CALL(LoadIdentity()); |
| 366 | } |
bsalomon@google.com | 05a718c | 2012-06-29 14:01:53 +0000 | [diff] [blame] | 367 | } |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 368 | |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 369 | // we assume these values |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 370 | if (resetBits & kPixelStore_GrGLBackendState) { |
| 371 | if (this->glCaps().unpackRowLengthSupport()) { |
| 372 | GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
| 373 | } |
| 374 | if (this->glCaps().packRowLengthSupport()) { |
| 375 | GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); |
| 376 | } |
| 377 | if (this->glCaps().unpackFlipYSupport()) { |
| 378 | GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); |
| 379 | } |
| 380 | if (this->glCaps().packFlipYSupport()) { |
| 381 | GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, GR_GL_FALSE)); |
| 382 | } |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 383 | } |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 384 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 385 | if (resetBits & kProgram_GrGLBackendState) { |
| 386 | fHWProgramID = 0; |
| 387 | fSharedGLProgramState.invalidate(); |
| 388 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 389 | } |
| 390 | |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 391 | namespace { |
| 392 | |
| 393 | GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget) { |
| 394 | // By default, GrRenderTargets are GL's normal orientation so that they |
| 395 | // can be drawn to by the outside world without the client having |
| 396 | // to render upside down. |
| 397 | if (kDefault_GrSurfaceOrigin == origin) { |
| 398 | return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin; |
| 399 | } else { |
| 400 | return origin; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | } |
| 405 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 406 | GrTexture* GrGpuGL::onWrapBackendTexture(const GrBackendTextureDesc& desc) { |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 407 | if (!this->configToGLFormats(desc.fConfig, false, NULL, NULL, NULL)) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 408 | return NULL; |
| 409 | } |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 410 | |
robertphillips@google.com | b72e5d3 | 2012-10-30 15:18:10 +0000 | [diff] [blame] | 411 | if (0 == desc.fTextureHandle) { |
| 412 | return NULL; |
| 413 | } |
| 414 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 415 | int maxSize = this->caps()->maxTextureSize(); |
robertphillips@google.com | b72e5d3 | 2012-10-30 15:18:10 +0000 | [diff] [blame] | 416 | if (desc.fWidth > maxSize || desc.fHeight > maxSize) { |
| 417 | return NULL; |
| 418 | } |
| 419 | |
| 420 | GrGLTexture::Desc glTexDesc; |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 421 | // next line relies on GrBackendTextureDesc's flags matching GrTexture's |
robertphillips@google.com | 3271628 | 2012-06-04 12:48:45 +0000 | [diff] [blame] | 422 | glTexDesc.fFlags = (GrTextureFlags) desc.fFlags; |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 423 | glTexDesc.fWidth = desc.fWidth; |
| 424 | glTexDesc.fHeight = desc.fHeight; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 425 | glTexDesc.fConfig = desc.fConfig; |
robertphillips@google.com | 3271628 | 2012-06-04 12:48:45 +0000 | [diff] [blame] | 426 | glTexDesc.fSampleCnt = desc.fSampleCnt; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 427 | glTexDesc.fTextureID = static_cast<GrGLuint>(desc.fTextureHandle); |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 428 | glTexDesc.fIsWrapped = true; |
senorblanco@chromium.org | d092524 | 2013-06-10 15:06:09 +0000 | [diff] [blame] | 429 | bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFlag); |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 430 | // FIXME: this should be calling resolve_origin(), but Chrome code is currently |
| 431 | // assuming the old behaviour, which is that backend textures are always |
| 432 | // BottomLeft, even for non-RT's. Once Chrome is fixed, change this to: |
| 433 | // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); |
| 434 | if (kDefault_GrSurfaceOrigin == desc.fOrigin) { |
| 435 | glTexDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 436 | } else { |
| 437 | glTexDesc.fOrigin = desc.fOrigin; |
| 438 | } |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 439 | |
| 440 | GrGLTexture* texture = NULL; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 441 | if (renderTarget) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 442 | GrGLRenderTarget::Desc glRTDesc; |
| 443 | glRTDesc.fRTFBOID = 0; |
| 444 | glRTDesc.fTexFBOID = 0; |
| 445 | glRTDesc.fMSColorRenderbufferID = 0; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 446 | glRTDesc.fConfig = desc.fConfig; |
| 447 | glRTDesc.fSampleCnt = desc.fSampleCnt; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 448 | glRTDesc.fOrigin = glTexDesc.fOrigin; |
senorblanco@chromium.org | d092524 | 2013-06-10 15:06:09 +0000 | [diff] [blame] | 449 | glRTDesc.fCheckAllocation = false; |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 450 | if (!this->createRenderTargetObjects(glTexDesc.fWidth, |
| 451 | glTexDesc.fHeight, |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 452 | glTexDesc.fTextureID, |
| 453 | &glRTDesc)) { |
| 454 | return NULL; |
| 455 | } |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 456 | texture = SkNEW_ARGS(GrGLTexture, (this, glTexDesc, glRTDesc)); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 457 | } else { |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 458 | texture = SkNEW_ARGS(GrGLTexture, (this, glTexDesc)); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 459 | } |
| 460 | if (NULL == texture) { |
| 461 | return NULL; |
| 462 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 463 | |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 464 | return texture; |
| 465 | } |
| 466 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 467 | GrRenderTarget* GrGpuGL::onWrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 468 | GrGLRenderTarget::Desc glDesc; |
| 469 | glDesc.fConfig = desc.fConfig; |
| 470 | glDesc.fRTFBOID = static_cast<GrGLuint>(desc.fRenderTargetHandle); |
| 471 | glDesc.fMSColorRenderbufferID = 0; |
| 472 | glDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; |
| 473 | glDesc.fSampleCnt = desc.fSampleCnt; |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 474 | glDesc.fIsWrapped = true; |
senorblanco@chromium.org | d092524 | 2013-06-10 15:06:09 +0000 | [diff] [blame] | 475 | glDesc.fCheckAllocation = false; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 476 | |
| 477 | glDesc.fOrigin = resolve_origin(desc.fOrigin, true); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 478 | GrGLIRect viewport; |
| 479 | viewport.fLeft = 0; |
| 480 | viewport.fBottom = 0; |
| 481 | viewport.fWidth = desc.fWidth; |
| 482 | viewport.fHeight = desc.fHeight; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 483 | |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 484 | GrRenderTarget* tgt = SkNEW_ARGS(GrGLRenderTarget, |
| 485 | (this, glDesc, viewport)); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 486 | if (desc.fStencilBits) { |
| 487 | GrGLStencilBuffer::Format format; |
| 488 | format.fInternalFormat = GrGLStencilBuffer::kUnknownInternalFormat; |
| 489 | format.fPacked = false; |
| 490 | format.fStencilBits = desc.fStencilBits; |
| 491 | format.fTotalBits = desc.fStencilBits; |
bsalomon@google.com | 1f0f1a3 | 2013-01-23 21:32:32 +0000 | [diff] [blame] | 492 | static const bool kIsSBWrapped = false; |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 493 | GrGLStencilBuffer* sb = SkNEW_ARGS(GrGLStencilBuffer, |
| 494 | (this, |
bsalomon@google.com | 1f0f1a3 | 2013-01-23 21:32:32 +0000 | [diff] [blame] | 495 | kIsSBWrapped, |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 496 | 0, |
| 497 | desc.fWidth, |
| 498 | desc.fHeight, |
| 499 | desc.fSampleCnt, |
| 500 | format)); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 501 | tgt->setStencilBuffer(sb); |
| 502 | sb->unref(); |
| 503 | } |
| 504 | return tgt; |
| 505 | } |
| 506 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 507 | //////////////////////////////////////////////////////////////////////////////// |
| 508 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 509 | bool GrGpuGL::onWriteTexturePixels(GrTexture* texture, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 510 | int left, int top, int width, int height, |
| 511 | GrPixelConfig config, const void* buffer, |
| 512 | size_t rowBytes) { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 513 | if (NULL == buffer) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 514 | return false; |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 515 | } |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 516 | GrGLTexture* glTex = static_cast<GrGLTexture*>(texture); |
| 517 | |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 518 | this->setScratchTextureUnit(); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 519 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTex->textureID())); |
| 520 | GrGLTexture::Desc desc; |
robertphillips@google.com | 3271628 | 2012-06-04 12:48:45 +0000 | [diff] [blame] | 521 | desc.fFlags = glTex->desc().fFlags; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 522 | desc.fWidth = glTex->width(); |
| 523 | desc.fHeight = glTex->height(); |
robertphillips@google.com | 3271628 | 2012-06-04 12:48:45 +0000 | [diff] [blame] | 524 | desc.fConfig = glTex->config(); |
| 525 | desc.fSampleCnt = glTex->desc().fSampleCnt; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 526 | desc.fTextureID = glTex->textureID(); |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame] | 527 | desc.fOrigin = glTex->origin(); |
bsalomon@google.com | 9d6cfd8 | 2011-11-05 13:25:21 +0000 | [diff] [blame] | 528 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 529 | return this->uploadTexData(desc, false, |
| 530 | left, top, width, height, |
| 531 | config, buffer, rowBytes); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 532 | } |
| 533 | |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 534 | namespace { |
| 535 | bool adjust_pixel_ops_params(int surfaceWidth, |
| 536 | int surfaceHeight, |
| 537 | size_t bpp, |
| 538 | int* left, int* top, int* width, int* height, |
| 539 | const void** data, |
| 540 | size_t* rowBytes) { |
| 541 | if (!*rowBytes) { |
| 542 | *rowBytes = *width * bpp; |
| 543 | } |
| 544 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame^] | 545 | SkIRect subRect = SkIRect::MakeXYWH(*left, *top, *width, *height); |
| 546 | SkIRect bounds = SkIRect::MakeWH(surfaceWidth, surfaceHeight); |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 547 | |
| 548 | if (!subRect.intersect(bounds)) { |
| 549 | return false; |
| 550 | } |
| 551 | *data = reinterpret_cast<const void*>(reinterpret_cast<intptr_t>(*data) + |
| 552 | (subRect.fTop - *top) * *rowBytes + (subRect.fLeft - *left) * bpp); |
| 553 | |
| 554 | *left = subRect.fLeft; |
| 555 | *top = subRect.fTop; |
| 556 | *width = subRect.width(); |
| 557 | *height = subRect.height(); |
| 558 | return true; |
| 559 | } |
senorblanco@chromium.org | d092524 | 2013-06-10 15:06:09 +0000 | [diff] [blame] | 560 | |
| 561 | GrGLenum check_alloc_error(const GrTextureDesc& desc, const GrGLInterface* interface) { |
| 562 | if (SkToBool(desc.fFlags & kCheckAllocation_GrTextureFlagBit)) { |
| 563 | return GR_GL_GET_ERROR(interface); |
| 564 | } else { |
| 565 | return CHECK_ALLOC_ERROR(interface); |
| 566 | } |
| 567 | } |
| 568 | |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 569 | } |
| 570 | |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 571 | bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc, |
| 572 | bool isNewTexture, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 573 | int left, int top, int width, int height, |
| 574 | GrPixelConfig dataConfig, |
| 575 | const void* data, |
| 576 | size_t rowBytes) { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 577 | GrAssert(NULL != data || isNewTexture); |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 578 | |
| 579 | size_t bpp = GrBytesPerPixel(dataConfig); |
| 580 | if (!adjust_pixel_ops_params(desc.fWidth, desc.fHeight, bpp, &left, &top, |
| 581 | &width, &height, &data, &rowBytes)) { |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 582 | return false; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 583 | } |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 584 | size_t trimRowBytes = width * bpp; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 585 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 586 | // in case we need a temporary, trimmed copy of the src pixels |
| 587 | SkAutoSMalloc<128 * 128> tempStorage; |
| 588 | |
bsalomon@google.com | 313f019 | 2012-07-10 17:21:02 +0000 | [diff] [blame] | 589 | // paletted textures cannot be partially updated |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 590 | bool useTexStorage = isNewTexture && |
bsalomon@google.com | 313f019 | 2012-07-10 17:21:02 +0000 | [diff] [blame] | 591 | desc.fConfig != kIndex_8_GrPixelConfig && |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 592 | this->glCaps().texStorageSupport(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 593 | |
bsalomon@google.com | 313f019 | 2012-07-10 17:21:02 +0000 | [diff] [blame] | 594 | if (useTexStorage && kDesktop_GrGLBinding == this->glBinding()) { |
| 595 | // 565 is not a sized internal format on desktop GL. So on desktop with |
| 596 | // 565 we always use an unsized internal format to let the system pick |
| 597 | // the best sized format to convert the 565 data to. Since TexStorage |
| 598 | // only allows sized internal formats we will instead use TexImage2D. |
| 599 | useTexStorage = desc.fConfig != kRGB_565_GrPixelConfig; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | GrGLenum internalFormat; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 603 | GrGLenum externalFormat; |
| 604 | GrGLenum externalType; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 605 | // glTexStorage requires sized internal formats on both desktop and ES. ES |
| 606 | // glTexImage requires an unsized format. |
| 607 | if (!this->configToGLFormats(dataConfig, useTexStorage, &internalFormat, |
| 608 | &externalFormat, &externalType)) { |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 609 | return false; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 610 | } |
| 611 | |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 612 | if (!isNewTexture && GR_GL_PALETTE8_RGBA8 == internalFormat) { |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 613 | // paletted textures cannot be updated |
| 614 | return false; |
| 615 | } |
| 616 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 617 | /* |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 618 | * check whether to allocate a temporary buffer for flipping y or |
| 619 | * because our srcData has extra bytes past each row. If so, we need |
| 620 | * to trim those off here, since GL ES may not let us specify |
| 621 | * GL_UNPACK_ROW_LENGTH. |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 622 | */ |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 623 | bool restoreGLRowLength = false; |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 624 | bool swFlipY = false; |
| 625 | bool glFlipY = false; |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 626 | if (NULL != data) { |
senorblanco@chromium.org | ef5dbe1 | 2013-01-28 16:42:38 +0000 | [diff] [blame] | 627 | if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 628 | if (this->glCaps().unpackFlipYSupport()) { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 629 | glFlipY = true; |
| 630 | } else { |
| 631 | swFlipY = true; |
| 632 | } |
| 633 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 634 | if (this->glCaps().unpackRowLengthSupport() && !swFlipY) { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 635 | // can't use this for flipping, only non-neg values allowed. :( |
| 636 | if (rowBytes != trimRowBytes) { |
| 637 | GrGLint rowLength = static_cast<GrGLint>(rowBytes / bpp); |
| 638 | GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, rowLength)); |
| 639 | restoreGLRowLength = true; |
| 640 | } |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 641 | } else { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 642 | if (trimRowBytes != rowBytes || swFlipY) { |
| 643 | // copy data into our new storage, skipping the trailing bytes |
| 644 | size_t trimSize = height * trimRowBytes; |
| 645 | const char* src = (const char*)data; |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 646 | if (swFlipY) { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 647 | src += (height - 1) * rowBytes; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 648 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 649 | char* dst = (char*)tempStorage.reset(trimSize); |
| 650 | for (int y = 0; y < height; y++) { |
| 651 | memcpy(dst, src, trimRowBytes); |
| 652 | if (swFlipY) { |
| 653 | src -= rowBytes; |
| 654 | } else { |
| 655 | src += rowBytes; |
| 656 | } |
| 657 | dst += trimRowBytes; |
| 658 | } |
| 659 | // now point data to our copied version |
| 660 | data = tempStorage.get(); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 661 | } |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 662 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 663 | if (glFlipY) { |
| 664 | GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE)); |
| 665 | } |
| 666 | GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, static_cast<GrGLint>(bpp))); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 667 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 668 | bool succeeded = true; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 669 | if (isNewTexture && |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 670 | 0 == left && 0 == top && |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 671 | desc.fWidth == width && desc.fHeight == height) { |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 672 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 673 | if (useTexStorage) { |
| 674 | // We never resize or change formats of textures. We don't use |
| 675 | // mipmaps currently. |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 676 | GL_ALLOC_CALL(this->glInterface(), |
| 677 | TexStorage2D(GR_GL_TEXTURE_2D, |
| 678 | 1, // levels |
| 679 | internalFormat, |
| 680 | desc.fWidth, desc.fHeight)); |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 681 | } else { |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 682 | if (GR_GL_PALETTE8_RGBA8 == internalFormat) { |
| 683 | GrGLsizei imageSize = desc.fWidth * desc.fHeight + |
| 684 | kGrColorTableSize; |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 685 | GL_ALLOC_CALL(this->glInterface(), |
| 686 | CompressedTexImage2D(GR_GL_TEXTURE_2D, |
| 687 | 0, // level |
| 688 | internalFormat, |
| 689 | desc.fWidth, desc.fHeight, |
| 690 | 0, // border |
| 691 | imageSize, |
| 692 | data)); |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 693 | } else { |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 694 | GL_ALLOC_CALL(this->glInterface(), |
| 695 | TexImage2D(GR_GL_TEXTURE_2D, |
| 696 | 0, // level |
| 697 | internalFormat, |
| 698 | desc.fWidth, desc.fHeight, |
| 699 | 0, // border |
| 700 | externalFormat, externalType, |
| 701 | data)); |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 702 | } |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 703 | } |
senorblanco@chromium.org | d092524 | 2013-06-10 15:06:09 +0000 | [diff] [blame] | 704 | GrGLenum error = check_alloc_error(desc, this->glInterface()); |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 705 | if (error != GR_GL_NO_ERROR) { |
| 706 | succeeded = false; |
| 707 | } else { |
| 708 | // if we have data and we used TexStorage to create the texture, we |
| 709 | // now upload with TexSubImage. |
| 710 | if (NULL != data && useTexStorage) { |
| 711 | GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, |
| 712 | 0, // level |
| 713 | left, top, |
| 714 | width, height, |
| 715 | externalFormat, externalType, |
| 716 | data)); |
| 717 | } |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 718 | } |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 719 | } else { |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 720 | if (swFlipY || glFlipY) { |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 721 | top = desc.fHeight - (top + height); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 722 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 723 | GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, |
| 724 | 0, // level |
| 725 | left, top, |
| 726 | width, height, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 727 | externalFormat, externalType, data)); |
| 728 | } |
| 729 | |
| 730 | if (restoreGLRowLength) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 731 | GrAssert(this->glCaps().unpackRowLengthSupport()); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 732 | GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 733 | } |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 734 | if (glFlipY) { |
| 735 | GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); |
| 736 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 737 | return succeeded; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 738 | } |
| 739 | |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 740 | namespace { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 741 | bool renderbuffer_storage_msaa(GrGLContext& ctx, |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 742 | int sampleCount, |
| 743 | GrGLenum format, |
| 744 | int width, int height) { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 745 | CLEAR_ERROR_BEFORE_ALLOC(ctx.interface()); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 746 | GrAssert(GrGLCaps::kNone_MSFBOType != ctx.info().caps()->msFBOType()); |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 747 | bool created = false; |
| 748 | if (GrGLCaps::kNVDesktop_CoverageAAType == |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 749 | ctx.info().caps()->coverageAAType()) { |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 750 | const GrGLCaps::MSAACoverageMode& mode = |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 751 | ctx.info().caps()->getMSAACoverageMode(sampleCount); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 752 | GL_ALLOC_CALL(ctx.interface(), |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 753 | RenderbufferStorageMultisampleCoverage(GR_GL_RENDERBUFFER, |
| 754 | mode.fCoverageSampleCnt, |
| 755 | mode.fColorSampleCnt, |
| 756 | format, |
| 757 | width, height)); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 758 | created = (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface())); |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 759 | } |
| 760 | if (!created) { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 761 | GL_ALLOC_CALL(ctx.interface(), |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 762 | RenderbufferStorageMultisample(GR_GL_RENDERBUFFER, |
| 763 | sampleCount, |
| 764 | format, |
| 765 | width, height)); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 766 | created = (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface())); |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 767 | } |
| 768 | return created; |
| 769 | } |
| 770 | } |
| 771 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 772 | bool GrGpuGL::createRenderTargetObjects(int width, int height, |
| 773 | GrGLuint texID, |
| 774 | GrGLRenderTarget::Desc* desc) { |
| 775 | desc->fMSColorRenderbufferID = 0; |
| 776 | desc->fRTFBOID = 0; |
| 777 | desc->fTexFBOID = 0; |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 778 | desc->fIsWrapped = false; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 779 | |
| 780 | GrGLenum status; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 781 | |
bsalomon@google.com | ab15d61 | 2011-08-09 12:57:56 +0000 | [diff] [blame] | 782 | GrGLenum msColorFormat = 0; // suppress warning |
| 783 | |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 784 | if (desc->fSampleCnt > 0 && GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType()) { |
| 785 | goto FAILED; |
| 786 | } |
| 787 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 788 | GL_CALL(GenFramebuffers(1, &desc->fTexFBOID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 789 | if (!desc->fTexFBOID) { |
| 790 | goto FAILED; |
| 791 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 792 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 793 | |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 794 | // If we are using multisampling we will create two FBOS. We render to one and then resolve to |
| 795 | // the texture bound to the other. The exception is the IMG multisample extension. With this |
| 796 | // extension the texture is multisampled when rendered to and then auto-resolves it when it is |
| 797 | // rendered from. |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 798 | if (desc->fSampleCnt > 0 && this->glCaps().usesMSAARenderBuffers()) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 799 | GL_CALL(GenFramebuffers(1, &desc->fRTFBOID)); |
| 800 | GL_CALL(GenRenderbuffers(1, &desc->fMSColorRenderbufferID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 801 | if (!desc->fRTFBOID || |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 802 | !desc->fMSColorRenderbufferID || |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 803 | !this->configToGLFormats(desc->fConfig, |
| 804 | // GLES requires sized internal formats |
| 805 | kES2_GrGLBinding == this->glBinding(), |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 806 | &msColorFormat, |
| 807 | NULL, |
| 808 | NULL)) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 809 | goto FAILED; |
| 810 | } |
| 811 | } else { |
| 812 | desc->fRTFBOID = desc->fTexFBOID; |
| 813 | } |
| 814 | |
bsalomon@google.com | 0e9b41a | 2012-01-04 22:11:43 +0000 | [diff] [blame] | 815 | // below here we may bind the FBO |
bsalomon@google.com | c811ea3 | 2012-05-21 15:33:09 +0000 | [diff] [blame] | 816 | fHWBoundRenderTarget = NULL; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 817 | if (desc->fRTFBOID != desc->fTexFBOID) { |
bsalomon@google.com | 13ac3a3 | 2013-01-09 23:29:39 +0000 | [diff] [blame] | 818 | GrAssert(desc->fSampleCnt > 0); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 819 | GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 820 | desc->fMSColorRenderbufferID)); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 821 | if (!renderbuffer_storage_msaa(fGLContext, |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 822 | desc->fSampleCnt, |
| 823 | msColorFormat, |
| 824 | width, height)) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 825 | goto FAILED; |
| 826 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 827 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fRTFBOID)); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 828 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 829 | GR_GL_COLOR_ATTACHMENT0, |
| 830 | GR_GL_RENDERBUFFER, |
| 831 | desc->fMSColorRenderbufferID)); |
senorblanco@chromium.org | d092524 | 2013-06-10 15:06:09 +0000 | [diff] [blame] | 832 | if (desc->fCheckAllocation || |
| 833 | !this->glCaps().isConfigVerifiedColorAttachment(desc->fConfig)) { |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 834 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 835 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
| 836 | goto FAILED; |
| 837 | } |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 838 | fGLContext.info().caps()->markConfigAsValidColorAttachment(desc->fConfig); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 839 | } |
| 840 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 841 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 842 | |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 843 | if (this->glCaps().usesImplicitMSAAResolve() && desc->fSampleCnt > 0) { |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 844 | GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, |
| 845 | GR_GL_COLOR_ATTACHMENT0, |
| 846 | GR_GL_TEXTURE_2D, |
| 847 | texID, 0, desc->fSampleCnt)); |
| 848 | } else { |
| 849 | GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
| 850 | GR_GL_COLOR_ATTACHMENT0, |
| 851 | GR_GL_TEXTURE_2D, |
| 852 | texID, 0)); |
| 853 | } |
senorblanco@chromium.org | d092524 | 2013-06-10 15:06:09 +0000 | [diff] [blame] | 854 | if (desc->fCheckAllocation || |
| 855 | !this->glCaps().isConfigVerifiedColorAttachment(desc->fConfig)) { |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 856 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 857 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
| 858 | goto FAILED; |
| 859 | } |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 860 | fGLContext.info().caps()->markConfigAsValidColorAttachment(desc->fConfig); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | return true; |
| 864 | |
| 865 | FAILED: |
| 866 | if (desc->fMSColorRenderbufferID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 867 | GL_CALL(DeleteRenderbuffers(1, &desc->fMSColorRenderbufferID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 868 | } |
| 869 | if (desc->fRTFBOID != desc->fTexFBOID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 870 | GL_CALL(DeleteFramebuffers(1, &desc->fRTFBOID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 871 | } |
| 872 | if (desc->fTexFBOID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 873 | GL_CALL(DeleteFramebuffers(1, &desc->fTexFBOID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 874 | } |
| 875 | return false; |
| 876 | } |
| 877 | |
bsalomon@google.com | 3f3ffd6 | 2011-01-18 17:14:52 +0000 | [diff] [blame] | 878 | // good to set a break-point here to know when createTexture fails |
| 879 | static GrTexture* return_null_texture() { |
| 880 | // GrAssert(!"null texture"); |
| 881 | return NULL; |
| 882 | } |
| 883 | |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 884 | #if 0 && GR_DEBUG |
bsalomon@google.com | 3f3ffd6 | 2011-01-18 17:14:52 +0000 | [diff] [blame] | 885 | static size_t as_size_t(int x) { |
| 886 | return x; |
| 887 | } |
| 888 | #endif |
| 889 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 890 | GrTexture* GrGpuGL::onCreateTexture(const GrTextureDesc& desc, |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 891 | const void* srcData, |
| 892 | size_t rowBytes) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 893 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 894 | GrGLTexture::Desc glTexDesc; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 895 | GrGLRenderTarget::Desc glRTDesc; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 896 | |
bsalomon@google.com | 78d6cf9 | 2012-01-30 18:09:31 +0000 | [diff] [blame] | 897 | // Attempt to catch un- or wrongly initialized sample counts; |
| 898 | GrAssert(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 899 | // We fail if the MSAA was requested and is not available. |
| 900 | if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleCnt) { |
| 901 | //GrPrintf("MSAA RT requested but not supported on this platform."); |
| 902 | return return_null_texture(); |
| 903 | } |
| 904 | // If the sample count exceeds the max then we clamp it. |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 905 | glTexDesc.fSampleCnt = GrMin(desc.fSampleCnt, this->caps()->maxSampleCount()); |
bsalomon@google.com | 78d6cf9 | 2012-01-30 18:09:31 +0000 | [diff] [blame] | 906 | |
robertphillips@google.com | 3271628 | 2012-06-04 12:48:45 +0000 | [diff] [blame] | 907 | glTexDesc.fFlags = desc.fFlags; |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 908 | glTexDesc.fWidth = desc.fWidth; |
| 909 | glTexDesc.fHeight = desc.fHeight; |
bsalomon@google.com | 78d6cf9 | 2012-01-30 18:09:31 +0000 | [diff] [blame] | 910 | glTexDesc.fConfig = desc.fConfig; |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 911 | glTexDesc.fIsWrapped = false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 912 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 913 | glRTDesc.fMSColorRenderbufferID = 0; |
| 914 | glRTDesc.fRTFBOID = 0; |
| 915 | glRTDesc.fTexFBOID = 0; |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 916 | glRTDesc.fIsWrapped = false; |
bsalomon@google.com | 64c4fe4 | 2011-11-05 14:51:01 +0000 | [diff] [blame] | 917 | glRTDesc.fConfig = glTexDesc.fConfig; |
senorblanco@chromium.org | d092524 | 2013-06-10 15:06:09 +0000 | [diff] [blame] | 918 | glRTDesc.fCheckAllocation = SkToBool(desc.fFlags & kCheckAllocation_GrTextureFlagBit); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 919 | |
senorblanco@chromium.org | d092524 | 2013-06-10 15:06:09 +0000 | [diff] [blame] | 920 | bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrTextureFlagBit); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 921 | |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 922 | glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); |
| 923 | glRTDesc.fOrigin = glTexDesc.fOrigin; |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 924 | |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 925 | glRTDesc.fSampleCnt = glTexDesc.fSampleCnt; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 926 | if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && |
bsalomon@google.com | 78d6cf9 | 2012-01-30 18:09:31 +0000 | [diff] [blame] | 927 | desc.fSampleCnt) { |
bsalomon@google.com | 945bbe1 | 2012-06-15 14:30:34 +0000 | [diff] [blame] | 928 | //GrPrintf("MSAA RT requested but not supported on this platform."); |
| 929 | return return_null_texture(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 930 | } |
| 931 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 932 | if (renderTarget) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 933 | int maxRTSize = this->caps()->maxRenderTargetSize(); |
| 934 | if (glTexDesc.fWidth > maxRTSize || glTexDesc.fHeight > maxRTSize) { |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 935 | return return_null_texture(); |
| 936 | } |
sugoi@google.com | 6ba0b0f | 2013-05-03 13:52:32 +0000 | [diff] [blame] | 937 | } else { |
| 938 | int maxSize = this->caps()->maxTextureSize(); |
| 939 | if (glTexDesc.fWidth > maxSize || glTexDesc.fHeight > maxSize) { |
| 940 | return return_null_texture(); |
| 941 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 942 | } |
| 943 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 944 | GL_CALL(GenTextures(1, &glTexDesc.fTextureID)); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 945 | if (renderTarget && this->glCaps().textureUsageSupport()) { |
bsalomon@google.com | 07dd2bf | 2011-12-09 19:40:36 +0000 | [diff] [blame] | 946 | // provides a hint about how this texture will be used |
| 947 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 948 | GR_GL_TEXTURE_USAGE, |
| 949 | GR_GL_FRAMEBUFFER_ATTACHMENT)); |
| 950 | } |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 951 | if (!glTexDesc.fTextureID) { |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 952 | return return_null_texture(); |
| 953 | } |
| 954 | |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 955 | this->setScratchTextureUnit(); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 956 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTexDesc.fTextureID)); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 957 | |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 958 | // Some drivers like to know filter/wrap before seeing glTexImage2D. Some |
| 959 | // drivers have a bug where an FBO won't be complete if it includes a |
| 960 | // texture that is not mipmap complete (considering the filter in use). |
| 961 | GrGLTexture::TexParams initialTexParams; |
| 962 | // we only set a subset here so invalidate first |
| 963 | initialTexParams.invalidate(); |
| 964 | initialTexParams.fFilter = GR_GL_NEAREST; |
| 965 | initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE; |
| 966 | initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 967 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 968 | GR_GL_TEXTURE_MAG_FILTER, |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 969 | initialTexParams.fFilter)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 970 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 971 | GR_GL_TEXTURE_MIN_FILTER, |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 972 | initialTexParams.fFilter)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 973 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 974 | GR_GL_TEXTURE_WRAP_S, |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 975 | initialTexParams.fWrapS)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 976 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 977 | GR_GL_TEXTURE_WRAP_T, |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 978 | initialTexParams.fWrapT)); |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 979 | if (!this->uploadTexData(glTexDesc, true, 0, 0, |
| 980 | glTexDesc.fWidth, glTexDesc.fHeight, |
| 981 | desc.fConfig, srcData, rowBytes)) { |
| 982 | GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID)); |
| 983 | return return_null_texture(); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 984 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 985 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 986 | GrGLTexture* tex; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 987 | if (renderTarget) { |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 988 | // unbind the texture from the texture unit before binding it to the frame buffer |
| 989 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, 0)); |
| 990 | |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 991 | if (!this->createRenderTargetObjects(glTexDesc.fWidth, |
| 992 | glTexDesc.fHeight, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 993 | glTexDesc.fTextureID, |
| 994 | &glRTDesc)) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 995 | GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 996 | return return_null_texture(); |
| 997 | } |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 998 | tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc, glRTDesc)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 999 | } else { |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 1000 | tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1001 | } |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1002 | tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1003 | #ifdef TRACE_TEXTURE_CREATION |
bsalomon@google.com | 64c4fe4 | 2011-11-05 14:51:01 +0000 | [diff] [blame] | 1004 | GrPrintf("--- new texture [%d] size=(%d %d) config=%d\n", |
| 1005 | glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1006 | #endif |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1007 | return tex; |
| 1008 | } |
| 1009 | |
| 1010 | namespace { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1011 | |
| 1012 | const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount; |
| 1013 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1014 | void inline get_stencil_rb_sizes(const GrGLInterface* gl, |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1015 | GrGLStencilBuffer::Format* format) { |
sugoi@google.com | 6ba0b0f | 2013-05-03 13:52:32 +0000 | [diff] [blame] | 1016 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1017 | // we shouldn't ever know one size and not the other |
| 1018 | GrAssert((kUnknownBitCount == format->fStencilBits) == |
| 1019 | (kUnknownBitCount == format->fTotalBits)); |
| 1020 | if (kUnknownBitCount == format->fStencilBits) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1021 | GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1022 | GR_GL_RENDERBUFFER_STENCIL_SIZE, |
| 1023 | (GrGLint*)&format->fStencilBits); |
| 1024 | if (format->fPacked) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1025 | GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1026 | GR_GL_RENDERBUFFER_DEPTH_SIZE, |
| 1027 | (GrGLint*)&format->fTotalBits); |
| 1028 | format->fTotalBits += format->fStencilBits; |
| 1029 | } else { |
| 1030 | format->fTotalBits = format->fStencilBits; |
| 1031 | } |
| 1032 | } |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | bool GrGpuGL::createStencilBufferForRenderTarget(GrRenderTarget* rt, |
| 1037 | int width, int height) { |
| 1038 | |
| 1039 | // All internally created RTs are also textures. We don't create |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 1040 | // SBs for a client's standalone RT (that is a RT that isn't also a texture). |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1041 | GrAssert(rt->asTexture()); |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 1042 | GrAssert(width >= rt->width()); |
| 1043 | GrAssert(height >= rt->height()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1044 | |
| 1045 | int samples = rt->numSamples(); |
| 1046 | GrGLuint sbID; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1047 | GL_CALL(GenRenderbuffers(1, &sbID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1048 | if (!sbID) { |
| 1049 | return false; |
| 1050 | } |
| 1051 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1052 | int stencilFmtCnt = this->glCaps().stencilFormats().count(); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1053 | for (int i = 0; i < stencilFmtCnt; ++i) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1054 | GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1055 | // we start with the last stencil format that succeeded in hopes |
| 1056 | // that we won't go through this loop more than once after the |
| 1057 | // first (painful) stencil creation. |
| 1058 | int sIdx = (i + fLastSuccessfulStencilFmtIdx) % stencilFmtCnt; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1059 | const GrGLCaps::StencilFormat& sFmt = |
| 1060 | this->glCaps().stencilFormats()[sIdx]; |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 1061 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 1062 | // we do this "if" so that we don't call the multisample |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1063 | // version on a GL that doesn't have an MSAA extension. |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 1064 | bool created; |
| 1065 | if (samples > 0) { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 1066 | created = renderbuffer_storage_msaa(fGLContext, |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 1067 | samples, |
| 1068 | sFmt.fInternalFormat, |
| 1069 | width, height); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1070 | } else { |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 1071 | GL_ALLOC_CALL(this->glInterface(), |
| 1072 | RenderbufferStorage(GR_GL_RENDERBUFFER, |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1073 | sFmt.fInternalFormat, |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 1074 | width, height)); |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 1075 | created = |
senorblanco@chromium.org | d092524 | 2013-06-10 15:06:09 +0000 | [diff] [blame] | 1076 | (GR_GL_NO_ERROR == check_alloc_error(rt->desc(), this->glInterface())); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1077 | } |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 1078 | if (created) { |
| 1079 | // After sized formats we attempt an unsized format and take |
| 1080 | // whatever sizes GL gives us. In that case we query for the size. |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1081 | GrGLStencilBuffer::Format format = sFmt; |
sugoi@google.com | 6ba0b0f | 2013-05-03 13:52:32 +0000 | [diff] [blame] | 1082 | get_stencil_rb_sizes(this->glInterface(), &format); |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 1083 | static const bool kIsWrapped = false; |
robertphillips@google.com | f2e93fc | 2012-09-05 19:44:18 +0000 | [diff] [blame] | 1084 | SkAutoTUnref<GrStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer, |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 1085 | (this, kIsWrapped, sbID, width, height, |
robertphillips@google.com | f2e93fc | 2012-09-05 19:44:18 +0000 | [diff] [blame] | 1086 | samples, format))); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1087 | if (this->attachStencilBufferToRenderTarget(sb, rt)) { |
| 1088 | fLastSuccessfulStencilFmtIdx = sIdx; |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 1089 | sb->transferToCache(); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 1090 | rt->setStencilBuffer(sb); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1091 | return true; |
| 1092 | } |
| 1093 | sb->abandon(); // otherwise we lose sbID |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1094 | } |
| 1095 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1096 | GL_CALL(DeleteRenderbuffers(1, &sbID)); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 1097 | return false; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1100 | bool GrGpuGL::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, GrRenderTarget* rt) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1101 | GrGLRenderTarget* glrt = (GrGLRenderTarget*) rt; |
| 1102 | |
| 1103 | GrGLuint fbo = glrt->renderFBOID(); |
| 1104 | |
| 1105 | if (NULL == sb) { |
| 1106 | if (NULL != rt->getStencilBuffer()) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1107 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1108 | GR_GL_STENCIL_ATTACHMENT, |
| 1109 | GR_GL_RENDERBUFFER, 0)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1110 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1111 | GR_GL_DEPTH_ATTACHMENT, |
| 1112 | GR_GL_RENDERBUFFER, 0)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1113 | #if GR_DEBUG |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 1114 | GrGLenum status; |
| 1115 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1116 | GrAssert(GR_GL_FRAMEBUFFER_COMPLETE == status); |
| 1117 | #endif |
| 1118 | } |
| 1119 | return true; |
| 1120 | } else { |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1121 | GrGLStencilBuffer* glsb = static_cast<GrGLStencilBuffer*>(sb); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1122 | GrGLuint rb = glsb->renderbufferID(); |
| 1123 | |
bsalomon@google.com | c811ea3 | 2012-05-21 15:33:09 +0000 | [diff] [blame] | 1124 | fHWBoundRenderTarget = NULL; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1125 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo)); |
| 1126 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1127 | GR_GL_STENCIL_ATTACHMENT, |
| 1128 | GR_GL_RENDERBUFFER, rb)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1129 | if (glsb->format().fPacked) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1130 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1131 | GR_GL_DEPTH_ATTACHMENT, |
| 1132 | GR_GL_RENDERBUFFER, rb)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1133 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1134 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1135 | GR_GL_DEPTH_ATTACHMENT, |
| 1136 | GR_GL_RENDERBUFFER, 0)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1137 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1138 | |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 1139 | GrGLenum status; |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1140 | if (!this->glCaps().isColorConfigAndStencilFormatVerified(rt->config(), glsb->format())) { |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 1141 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 1142 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1143 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 1144 | GR_GL_STENCIL_ATTACHMENT, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1145 | GR_GL_RENDERBUFFER, 0)); |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 1146 | if (glsb->format().fPacked) { |
| 1147 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 1148 | GR_GL_DEPTH_ATTACHMENT, |
| 1149 | GR_GL_RENDERBUFFER, 0)); |
| 1150 | } |
| 1151 | return false; |
| 1152 | } else { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1153 | fGLContext.info().caps()->markColorConfigAndStencilFormatAsVerified( |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 1154 | rt->config(), |
| 1155 | glsb->format()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1156 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1157 | } |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 1158 | return true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1159 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 1162 | //////////////////////////////////////////////////////////////////////////////// |
| 1163 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 1164 | GrVertexBuffer* GrGpuGL::onCreateVertexBuffer(uint32_t size, bool dynamic) { |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 1165 | GrGLVertexBuffer::Desc desc; |
| 1166 | desc.fDynamic = dynamic; |
| 1167 | desc.fSizeInBytes = size; |
| 1168 | desc.fIsWrapped = false; |
| 1169 | |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 1170 | if (this->glCaps().useNonVBOVertexAndIndexDynamicData() && desc.fDynamic) { |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1171 | desc.fID = 0; |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 1172 | GrGLVertexBuffer* vertexBuffer = SkNEW_ARGS(GrGLVertexBuffer, (this, desc)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1173 | return vertexBuffer; |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1174 | } else { |
| 1175 | GL_CALL(GenBuffers(1, &desc.fID)); |
| 1176 | if (desc.fID) { |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 1177 | fHWGeometryState.setVertexBufferID(this, desc.fID); |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1178 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
| 1179 | // make sure driver can allocate memory for this buffer |
| 1180 | GL_ALLOC_CALL(this->glInterface(), |
| 1181 | BufferData(GR_GL_ARRAY_BUFFER, |
| 1182 | desc.fSizeInBytes, |
| 1183 | NULL, // data ptr |
| 1184 | desc.fDynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW)); |
| 1185 | if (CHECK_ALLOC_ERROR(this->glInterface()) != GR_GL_NO_ERROR) { |
| 1186 | GL_CALL(DeleteBuffers(1, &desc.fID)); |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 1187 | this->notifyVertexBufferDelete(desc.fID); |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1188 | return NULL; |
| 1189 | } |
| 1190 | GrGLVertexBuffer* vertexBuffer = SkNEW_ARGS(GrGLVertexBuffer, (this, desc)); |
| 1191 | return vertexBuffer; |
| 1192 | } |
| 1193 | return NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1194 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1195 | } |
| 1196 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 1197 | GrIndexBuffer* GrGpuGL::onCreateIndexBuffer(uint32_t size, bool dynamic) { |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 1198 | GrGLIndexBuffer::Desc desc; |
| 1199 | desc.fDynamic = dynamic; |
| 1200 | desc.fSizeInBytes = size; |
| 1201 | desc.fIsWrapped = false; |
| 1202 | |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 1203 | if (this->glCaps().useNonVBOVertexAndIndexDynamicData() && desc.fDynamic) { |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1204 | desc.fID = 0; |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 1205 | GrIndexBuffer* indexBuffer = SkNEW_ARGS(GrGLIndexBuffer, (this, desc)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1206 | return indexBuffer; |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1207 | } else { |
| 1208 | GL_CALL(GenBuffers(1, &desc.fID)); |
| 1209 | if (desc.fID) { |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 1210 | fHWGeometryState.setIndexBufferIDOnDefaultVertexArray(this, desc.fID); |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1211 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
| 1212 | // make sure driver can allocate memory for this buffer |
| 1213 | GL_ALLOC_CALL(this->glInterface(), |
| 1214 | BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, |
| 1215 | desc.fSizeInBytes, |
| 1216 | NULL, // data ptr |
| 1217 | desc.fDynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW)); |
| 1218 | if (CHECK_ALLOC_ERROR(this->glInterface()) != GR_GL_NO_ERROR) { |
| 1219 | GL_CALL(DeleteBuffers(1, &desc.fID)); |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 1220 | this->notifyIndexBufferDelete(desc.fID); |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1221 | return NULL; |
| 1222 | } |
| 1223 | GrIndexBuffer* indexBuffer = SkNEW_ARGS(GrGLIndexBuffer, (this, desc)); |
| 1224 | return indexBuffer; |
| 1225 | } |
| 1226 | return NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1227 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 1230 | GrPath* GrGpuGL::onCreatePath(const SkPath& inPath) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1231 | GrAssert(this->caps()->pathStencilingSupport()); |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 1232 | return SkNEW_ARGS(GrGLPath, (this, inPath)); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1235 | void GrGpuGL::flushScissor() { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1236 | const GrDrawState& drawState = this->getDrawState(); |
| 1237 | const GrGLRenderTarget* rt = |
| 1238 | static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget()); |
| 1239 | |
| 1240 | GrAssert(NULL != rt); |
| 1241 | const GrGLIRect& vp = rt->getViewport(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1242 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1243 | if (fScissorState.fEnabled) { |
| 1244 | GrGLIRect scissor; |
| 1245 | scissor.setRelativeTo(vp, |
| 1246 | fScissorState.fRect.fLeft, |
| 1247 | fScissorState.fRect.fTop, |
| 1248 | fScissorState.fRect.width(), |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1249 | fScissorState.fRect.height(), |
| 1250 | rt->origin()); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1251 | // if the scissor fully contains the viewport then we fall through and |
| 1252 | // disable the scissor test. |
| 1253 | if (!scissor.contains(vp)) { |
| 1254 | if (fHWScissorSettings.fRect != scissor) { |
| 1255 | scissor.pushToGLScissor(this->glInterface()); |
| 1256 | fHWScissorSettings.fRect = scissor; |
| 1257 | } |
| 1258 | if (kYes_TriState != fHWScissorSettings.fEnabled) { |
| 1259 | GL_CALL(Enable(GR_GL_SCISSOR_TEST)); |
| 1260 | fHWScissorSettings.fEnabled = kYes_TriState; |
| 1261 | } |
| 1262 | return; |
| 1263 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1264 | } |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1265 | if (kNo_TriState != fHWScissorSettings.fEnabled) { |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 1266 | GL_CALL(Disable(GR_GL_SCISSOR_TEST)); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1267 | fHWScissorSettings.fEnabled = kNo_TriState; |
| 1268 | return; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1269 | } |
| 1270 | } |
| 1271 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame^] | 1272 | void GrGpuGL::onClear(const SkIRect* rect, GrColor color) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1273 | const GrDrawState& drawState = this->getDrawState(); |
| 1274 | const GrRenderTarget* rt = drawState.getRenderTarget(); |
bsalomon@google.com | 0ba52fc | 2011-11-10 22:16:06 +0000 | [diff] [blame] | 1275 | // parent class should never let us get here with no RT |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1276 | GrAssert(NULL != rt); |
bsalomon@google.com | 0ba52fc | 2011-11-10 22:16:06 +0000 | [diff] [blame] | 1277 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame^] | 1278 | SkIRect clippedRect; |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 1279 | if (NULL != rect) { |
| 1280 | // flushScissor expects rect to be clipped to the target. |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1281 | clippedRect = *rect; |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame^] | 1282 | SkIRect rtRect = SkIRect::MakeWH(rt->width(), rt->height()); |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1283 | if (clippedRect.intersect(rtRect)) { |
| 1284 | rect = &clippedRect; |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 1285 | } else { |
| 1286 | return; |
| 1287 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1288 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1289 | this->flushRenderTarget(rect); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1290 | GrAutoTRestore<ScissorState> asr(&fScissorState); |
| 1291 | fScissorState.fEnabled = (NULL != rect); |
| 1292 | if (fScissorState.fEnabled) { |
| 1293 | fScissorState.fRect = *rect; |
| 1294 | } |
| 1295 | this->flushScissor(); |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1296 | |
| 1297 | GrGLfloat r, g, b, a; |
| 1298 | static const GrGLfloat scale255 = 1.f / 255.f; |
| 1299 | a = GrColorUnpackA(color) * scale255; |
| 1300 | GrGLfloat scaleRGB = scale255; |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1301 | r = GrColorUnpackR(color) * scaleRGB; |
| 1302 | g = GrColorUnpackG(color) * scaleRGB; |
| 1303 | b = GrColorUnpackB(color) * scaleRGB; |
| 1304 | |
| 1305 | GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE)); |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 1306 | fHWWriteToColor = kYes_TriState; |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1307 | GL_CALL(ClearColor(r, g, b, a)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1308 | GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1309 | } |
| 1310 | |
bsalomon@google.com | edc177d | 2011-08-05 15:46:40 +0000 | [diff] [blame] | 1311 | void GrGpuGL::clearStencil() { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1312 | if (NULL == this->getDrawState().getRenderTarget()) { |
bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 1313 | return; |
| 1314 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1315 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame^] | 1316 | this->flushRenderTarget(&SkIRect::EmptyIRect()); |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1317 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1318 | GrAutoTRestore<ScissorState> asr(&fScissorState); |
| 1319 | fScissorState.fEnabled = false; |
| 1320 | this->flushScissor(); |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 1321 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1322 | GL_CALL(StencilMask(0xffffffff)); |
| 1323 | GL_CALL(ClearStencil(0)); |
| 1324 | GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
bsalomon@google.com | 457b8a3 | 2012-05-21 21:19:58 +0000 | [diff] [blame] | 1325 | fHWStencilSettings.invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1326 | } |
| 1327 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame^] | 1328 | void GrGpuGL::clearStencilClip(const SkIRect& rect, bool insideClip) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1329 | const GrDrawState& drawState = this->getDrawState(); |
| 1330 | const GrRenderTarget* rt = drawState.getRenderTarget(); |
| 1331 | GrAssert(NULL != rt); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1332 | |
| 1333 | // this should only be called internally when we know we have a |
| 1334 | // stencil buffer. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1335 | GrAssert(NULL != rt->getStencilBuffer()); |
| 1336 | GrGLint stencilBitCount = rt->getStencilBuffer()->bits(); |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1337 | #if 0 |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1338 | GrAssert(stencilBitCount > 0); |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1339 | GrGLint clipStencilMask = (1 << (stencilBitCount - 1)); |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 1340 | #else |
| 1341 | // we could just clear the clip bit but when we go through |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1342 | // ANGLE a partial stencil mask will cause clears to be |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 1343 | // turned into draws. Our contract on GrDrawTarget says that |
| 1344 | // changing the clip between stencil passes may or may not |
| 1345 | // zero the client's clip bits. So we just clear the whole thing. |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1346 | static const GrGLint clipStencilMask = ~0; |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 1347 | #endif |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1348 | GrGLint value; |
| 1349 | if (insideClip) { |
| 1350 | value = (1 << (stencilBitCount - 1)); |
| 1351 | } else { |
| 1352 | value = 0; |
| 1353 | } |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame^] | 1354 | this->flushRenderTarget(&SkIRect::EmptyIRect()); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1355 | |
| 1356 | GrAutoTRestore<ScissorState> asr(&fScissorState); |
| 1357 | fScissorState.fEnabled = true; |
| 1358 | fScissorState.fRect = rect; |
| 1359 | this->flushScissor(); |
| 1360 | |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 1361 | GL_CALL(StencilMask((uint32_t) clipStencilMask)); |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1362 | GL_CALL(ClearStencil(value)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1363 | GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
bsalomon@google.com | 457b8a3 | 2012-05-21 21:19:58 +0000 | [diff] [blame] | 1364 | fHWStencilSettings.invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 1367 | void GrGpuGL::onForceRenderTargetFlush() { |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame^] | 1368 | this->flushRenderTarget(&SkIRect::EmptyIRect()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1371 | bool GrGpuGL::readPixelsWillPayForYFlip(GrRenderTarget* renderTarget, |
| 1372 | int left, int top, |
| 1373 | int width, int height, |
| 1374 | GrPixelConfig config, |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1375 | size_t rowBytes) const { |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1376 | // If this rendertarget is aready TopLeft, we don't need to flip. |
| 1377 | if (kTopLeft_GrSurfaceOrigin == renderTarget->origin()) { |
| 1378 | return false; |
| 1379 | } |
| 1380 | |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1381 | // if GL can do the flip then we'll never pay for it. |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1382 | if (this->glCaps().packFlipYSupport()) { |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1383 | return false; |
| 1384 | } |
| 1385 | |
| 1386 | // If we have to do memcpy to handle non-trim rowBytes then we |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 1387 | // get the flip for free. Otherwise it costs. |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1388 | if (this->glCaps().packRowLengthSupport()) { |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 1389 | return true; |
| 1390 | } |
| 1391 | // If we have to do memcpys to handle rowBytes then y-flip is free |
| 1392 | // Note the rowBytes might be tight to the passed in data, but if data |
| 1393 | // gets clipped in x to the target the rowBytes will no longer be tight. |
| 1394 | if (left >= 0 && (left + width) < renderTarget->width()) { |
| 1395 | return 0 == rowBytes || |
| 1396 | GrBytesPerPixel(config) * width == rowBytes; |
| 1397 | } else { |
| 1398 | return false; |
| 1399 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1400 | } |
| 1401 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1402 | bool GrGpuGL::onReadPixels(GrRenderTarget* target, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1403 | int left, int top, |
| 1404 | int width, int height, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1405 | GrPixelConfig config, |
| 1406 | void* buffer, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1407 | size_t rowBytes) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1408 | GrGLenum format; |
| 1409 | GrGLenum type; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1410 | bool flipY = kBottomLeft_GrSurfaceOrigin == target->origin(); |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 1411 | if (!this->configToGLFormats(config, false, NULL, &format, &type)) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1412 | return false; |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1413 | } |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 1414 | size_t bpp = GrBytesPerPixel(config); |
| 1415 | if (!adjust_pixel_ops_params(target->width(), target->height(), bpp, |
| 1416 | &left, &top, &width, &height, |
| 1417 | const_cast<const void**>(&buffer), |
| 1418 | &rowBytes)) { |
| 1419 | return false; |
| 1420 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1421 | |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1422 | // resolve the render target if necessary |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1423 | GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1424 | GrDrawState::AutoRenderTargetRestore artr; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1425 | switch (tgt->getResolveType()) { |
| 1426 | case GrGLRenderTarget::kCantResolve_ResolveType: |
| 1427 | return false; |
| 1428 | case GrGLRenderTarget::kAutoResolves_ResolveType: |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1429 | artr.set(this->drawState(), target); |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame^] | 1430 | this->flushRenderTarget(&SkIRect::EmptyIRect()); |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1431 | break; |
| 1432 | case GrGLRenderTarget::kCanResolve_ResolveType: |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 1433 | this->onResolveRenderTarget(tgt); |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1434 | // we don't track the state of the READ FBO ID. |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1435 | GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, |
| 1436 | tgt->textureFBOID())); |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1437 | break; |
| 1438 | default: |
| 1439 | GrCrash("Unknown resolve type"); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1440 | } |
| 1441 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1442 | const GrGLIRect& glvp = tgt->getViewport(); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1443 | |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 1444 | // the read rect is viewport-relative |
| 1445 | GrGLIRect readRect; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1446 | readRect.setRelativeTo(glvp, left, top, width, height, target->origin()); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1447 | |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 1448 | size_t tightRowBytes = bpp * width; |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1449 | if (0 == rowBytes) { |
| 1450 | rowBytes = tightRowBytes; |
| 1451 | } |
| 1452 | size_t readDstRowBytes = tightRowBytes; |
| 1453 | void* readDst = buffer; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1454 | |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1455 | // determine if GL can read using the passed rowBytes or if we need |
| 1456 | // a scratch buffer. |
| 1457 | SkAutoSMalloc<32 * sizeof(GrColor)> scratch; |
| 1458 | if (rowBytes != tightRowBytes) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1459 | if (this->glCaps().packRowLengthSupport()) { |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1460 | GrAssert(!(rowBytes % sizeof(GrColor))); |
| 1461 | GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, rowBytes / sizeof(GrColor))); |
| 1462 | readDstRowBytes = rowBytes; |
| 1463 | } else { |
| 1464 | scratch.reset(tightRowBytes * height); |
| 1465 | readDst = scratch.get(); |
| 1466 | } |
| 1467 | } |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1468 | if (flipY && this->glCaps().packFlipYSupport()) { |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1469 | GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 1)); |
| 1470 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1471 | GL_CALL(ReadPixels(readRect.fLeft, readRect.fBottom, |
| 1472 | readRect.fWidth, readRect.fHeight, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1473 | format, type, readDst)); |
| 1474 | if (readDstRowBytes != tightRowBytes) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1475 | GrAssert(this->glCaps().packRowLengthSupport()); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1476 | GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); |
| 1477 | } |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1478 | if (flipY && this->glCaps().packFlipYSupport()) { |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1479 | GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 0)); |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1480 | flipY = false; |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1481 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1482 | |
| 1483 | // now reverse the order of the rows, since GL's are bottom-to-top, but our |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1484 | // API presents top-to-bottom. We must preserve the padding contents. Note |
| 1485 | // that the above readPixels did not overwrite the padding. |
| 1486 | if (readDst == buffer) { |
| 1487 | GrAssert(rowBytes == readDstRowBytes); |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1488 | if (flipY) { |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1489 | scratch.reset(tightRowBytes); |
| 1490 | void* tmpRow = scratch.get(); |
| 1491 | // flip y in-place by rows |
| 1492 | const int halfY = height >> 1; |
| 1493 | char* top = reinterpret_cast<char*>(buffer); |
| 1494 | char* bottom = top + (height - 1) * rowBytes; |
| 1495 | for (int y = 0; y < halfY; y++) { |
| 1496 | memcpy(tmpRow, top, tightRowBytes); |
| 1497 | memcpy(top, bottom, tightRowBytes); |
| 1498 | memcpy(bottom, tmpRow, tightRowBytes); |
| 1499 | top += rowBytes; |
| 1500 | bottom -= rowBytes; |
| 1501 | } |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1502 | } |
| 1503 | } else { |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1504 | GrAssert(readDst != buffer); GrAssert(rowBytes != tightRowBytes); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1505 | // copy from readDst to buffer while flipping y |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 1506 | // const int halfY = height >> 1; |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1507 | const char* src = reinterpret_cast<const char*>(readDst); |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1508 | char* dst = reinterpret_cast<char*>(buffer); |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1509 | if (flipY) { |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1510 | dst += (height-1) * rowBytes; |
| 1511 | } |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1512 | for (int y = 0; y < height; y++) { |
| 1513 | memcpy(dst, src, tightRowBytes); |
| 1514 | src += readDstRowBytes; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1515 | if (!flipY) { |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1516 | dst += rowBytes; |
| 1517 | } else { |
| 1518 | dst -= rowBytes; |
| 1519 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1520 | } |
| 1521 | } |
| 1522 | return true; |
| 1523 | } |
| 1524 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame^] | 1525 | void GrGpuGL::flushRenderTarget(const SkIRect* bound) { |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1526 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1527 | GrGLRenderTarget* rt = |
| 1528 | static_cast<GrGLRenderTarget*>(this->drawState()->getRenderTarget()); |
| 1529 | GrAssert(NULL != rt); |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1530 | |
bsalomon@google.com | c811ea3 | 2012-05-21 15:33:09 +0000 | [diff] [blame] | 1531 | if (fHWBoundRenderTarget != rt) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1532 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID())); |
robertphillips@google.com | a6ffb58 | 2013-04-29 16:50:17 +0000 | [diff] [blame] | 1533 | #if GR_DEBUG |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 1534 | GrGLenum status; |
| 1535 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
bsalomon@google.com | c312bf9 | 2011-03-21 21:10:33 +0000 | [diff] [blame] | 1536 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
reed@google.com | b9255d5 | 2011-06-13 18:54:59 +0000 | [diff] [blame] | 1537 | GrPrintf("GrGpuGL::flushRenderTarget glCheckFramebufferStatus %x\n", status); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1538 | } |
robertphillips@google.com | a6ffb58 | 2013-04-29 16:50:17 +0000 | [diff] [blame] | 1539 | #endif |
bsalomon@google.com | c811ea3 | 2012-05-21 15:33:09 +0000 | [diff] [blame] | 1540 | fHWBoundRenderTarget = rt; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1541 | const GrGLIRect& vp = rt->getViewport(); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1542 | if (fHWViewport != vp) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1543 | vp.pushToGLViewport(this->glInterface()); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1544 | fHWViewport = vp; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1545 | } |
| 1546 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1547 | if (NULL == bound || !bound->isEmpty()) { |
| 1548 | rt->flagAsNeedingResolve(bound); |
| 1549 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1550 | } |
| 1551 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1552 | GrGLenum gPrimitiveType2GLMode[] = { |
| 1553 | GR_GL_TRIANGLES, |
| 1554 | GR_GL_TRIANGLE_STRIP, |
| 1555 | GR_GL_TRIANGLE_FAN, |
| 1556 | GR_GL_POINTS, |
| 1557 | GR_GL_LINES, |
| 1558 | GR_GL_LINE_STRIP |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1559 | }; |
| 1560 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1561 | #define SWAP_PER_DRAW 0 |
| 1562 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 1563 | #if SWAP_PER_DRAW |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1564 | #if GR_MAC_BUILD |
| 1565 | #include <AGL/agl.h> |
| 1566 | #elif GR_WIN32_BUILD |
bsalomon@google.com | ce7357d | 2012-06-25 17:49:25 +0000 | [diff] [blame] | 1567 | #include <gl/GL.h> |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1568 | void SwapBuf() { |
| 1569 | DWORD procID = GetCurrentProcessId(); |
| 1570 | HWND hwnd = GetTopWindow(GetDesktopWindow()); |
| 1571 | while(hwnd) { |
| 1572 | DWORD wndProcID = 0; |
| 1573 | GetWindowThreadProcessId(hwnd, &wndProcID); |
| 1574 | if(wndProcID == procID) { |
| 1575 | SwapBuffers(GetDC(hwnd)); |
| 1576 | } |
| 1577 | hwnd = GetNextWindow(hwnd, GW_HWNDNEXT); |
| 1578 | } |
| 1579 | } |
| 1580 | #endif |
| 1581 | #endif |
| 1582 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 1583 | void GrGpuGL::onGpuDraw(const DrawInfo& info) { |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 1584 | size_t indexOffsetInBytes; |
| 1585 | this->setupGeometry(info, &indexOffsetInBytes); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1586 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 1587 | GrAssert((size_t)info.primitiveType() < GR_ARRAY_COUNT(gPrimitiveType2GLMode)); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 1588 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 1589 | if (info.isIndexed()) { |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 1590 | GrGLvoid* indices = |
| 1591 | reinterpret_cast<GrGLvoid*>(indexOffsetInBytes + sizeof(uint16_t) * info.startIndex()); |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 1592 | // info.startVertex() was accounted for by setupGeometry. |
| 1593 | GL_CALL(DrawElements(gPrimitiveType2GLMode[info.primitiveType()], |
| 1594 | info.indexCount(), |
| 1595 | GR_GL_UNSIGNED_SHORT, |
| 1596 | indices)); |
| 1597 | } else { |
| 1598 | // Pass 0 for parameter first. We have to adjust glVertexAttribPointer() to account for |
| 1599 | // startVertex in the DrawElements case. So we always rely on setupGeometry to have |
| 1600 | // accounted for startVertex. |
| 1601 | GL_CALL(DrawArrays(gPrimitiveType2GLMode[info.primitiveType()], 0, info.vertexCount())); |
| 1602 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1603 | #if SWAP_PER_DRAW |
| 1604 | glFlush(); |
| 1605 | #if GR_MAC_BUILD |
| 1606 | aglSwapBuffers(aglGetCurrentContext()); |
| 1607 | int set_a_break_pt_here = 9; |
| 1608 | aglSwapBuffers(aglGetCurrentContext()); |
| 1609 | #elif GR_WIN32_BUILD |
| 1610 | SwapBuf(); |
| 1611 | int set_a_break_pt_here = 9; |
| 1612 | SwapBuf(); |
| 1613 | #endif |
| 1614 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1615 | } |
| 1616 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1617 | namespace { |
bsalomon@google.com | 100abf4 | 2012-09-05 17:40:04 +0000 | [diff] [blame] | 1618 | |
| 1619 | static const uint16_t kOnes16 = static_cast<uint16_t>(~0); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1620 | const GrStencilSettings& winding_nv_path_stencil_settings() { |
| 1621 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 1622 | kIncClamp_StencilOp, |
| 1623 | kIncClamp_StencilOp, |
| 1624 | kAlwaysIfInClip_StencilFunc, |
bsalomon@google.com | 100abf4 | 2012-09-05 17:40:04 +0000 | [diff] [blame] | 1625 | kOnes16, kOnes16, kOnes16); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1626 | return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 1627 | } |
| 1628 | const GrStencilSettings& even_odd_nv_path_stencil_settings() { |
| 1629 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 1630 | kInvert_StencilOp, |
| 1631 | kInvert_StencilOp, |
| 1632 | kAlwaysIfInClip_StencilFunc, |
bsalomon@google.com | 100abf4 | 2012-09-05 17:40:04 +0000 | [diff] [blame] | 1633 | kOnes16, kOnes16, kOnes16); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1634 | return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 1635 | } |
| 1636 | } |
| 1637 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1638 | void GrGpuGL::setStencilPathSettings(const GrPath&, |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 1639 | SkPath::FillType fill, |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1640 | GrStencilSettings* settings) { |
| 1641 | switch (fill) { |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 1642 | case SkPath::kEvenOdd_FillType: |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1643 | *settings = even_odd_nv_path_stencil_settings(); |
| 1644 | return; |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 1645 | case SkPath::kWinding_FillType: |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1646 | *settings = winding_nv_path_stencil_settings(); |
| 1647 | return; |
| 1648 | default: |
| 1649 | GrCrash("Unexpected path fill."); |
| 1650 | } |
| 1651 | } |
| 1652 | |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 1653 | void GrGpuGL::onGpuStencilPath(const GrPath* path, SkPath::FillType fill) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1654 | GrAssert(this->caps()->pathStencilingSupport()); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1655 | |
| 1656 | GrGLuint id = static_cast<const GrGLPath*>(path)->pathID(); |
| 1657 | GrDrawState* drawState = this->drawState(); |
| 1658 | GrAssert(NULL != drawState->getRenderTarget()); |
| 1659 | if (NULL == drawState->getRenderTarget()->getStencilBuffer()) { |
| 1660 | return; |
| 1661 | } |
| 1662 | |
| 1663 | // Decide how to manipulate the stencil buffer based on the fill rule. |
| 1664 | // Also, assert that the stencil settings we set in setStencilPathSettings |
| 1665 | // are present. |
| 1666 | GrAssert(!fStencilSettings.isTwoSided()); |
| 1667 | GrGLenum fillMode; |
| 1668 | switch (fill) { |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 1669 | case SkPath::kWinding_FillType: |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1670 | fillMode = GR_GL_COUNT_UP; |
| 1671 | GrAssert(kIncClamp_StencilOp == |
| 1672 | fStencilSettings.passOp(GrStencilSettings::kFront_Face)); |
| 1673 | GrAssert(kIncClamp_StencilOp == |
| 1674 | fStencilSettings.failOp(GrStencilSettings::kFront_Face)); |
| 1675 | break; |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 1676 | case SkPath::kEvenOdd_FillType: |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1677 | fillMode = GR_GL_INVERT; |
| 1678 | GrAssert(kInvert_StencilOp == |
| 1679 | fStencilSettings.passOp(GrStencilSettings::kFront_Face)); |
| 1680 | GrAssert(kInvert_StencilOp == |
| 1681 | fStencilSettings.failOp(GrStencilSettings::kFront_Face)); |
| 1682 | break; |
| 1683 | default: |
| 1684 | // Only the above two fill rules are allowed. |
| 1685 | GrCrash("Unexpected path fill."); |
bsalomon@google.com | 548a433 | 2012-07-11 19:45:22 +0000 | [diff] [blame] | 1686 | return; // suppress unused var warning. |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1687 | } |
| 1688 | GrGLint writeMask = fStencilSettings.writeMask(GrStencilSettings::kFront_Face); |
| 1689 | GL_CALL(StencilFillPath(id, fillMode, writeMask)); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 1690 | } |
| 1691 | |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 1692 | void GrGpuGL::onResolveRenderTarget(GrRenderTarget* target) { |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 1693 | GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1694 | if (rt->needsResolve()) { |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 1695 | // Some extensions automatically resolves the texture when it is read. |
| 1696 | if (this->glCaps().usesMSAARenderBuffers()) { |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1697 | GrAssert(rt->textureFBOID() != rt->renderFBOID()); |
| 1698 | GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); |
| 1699 | GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID())); |
| 1700 | // make sure we go through flushRenderTarget() since we've modified |
| 1701 | // the bound DRAW FBO ID. |
| 1702 | fHWBoundRenderTarget = NULL; |
| 1703 | const GrGLIRect& vp = rt->getViewport(); |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame^] | 1704 | const SkIRect dirtyRect = rt->getResolveRect(); |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1705 | GrGLIRect r; |
| 1706 | r.setRelativeTo(vp, dirtyRect.fLeft, dirtyRect.fTop, |
| 1707 | dirtyRect.width(), dirtyRect.height(), target->origin()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1708 | |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1709 | GrAutoTRestore<ScissorState> asr; |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 1710 | if (GrGLCaps::kES_Apple_MSFBOType == this->glCaps().msFBOType()) { |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1711 | // Apple's extension uses the scissor as the blit bounds. |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1712 | asr.reset(&fScissorState); |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1713 | fScissorState.fEnabled = true; |
| 1714 | fScissorState.fRect = dirtyRect; |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1715 | this->flushScissor(); |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1716 | GL_CALL(ResolveMultisampleFramebuffer()); |
| 1717 | } else { |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 1718 | if (GrGLCaps::kDesktop_EXT_MSFBOType == this->glCaps().msFBOType()) { |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1719 | // this respects the scissor during the blit, so disable it. |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1720 | asr.reset(&fScissorState); |
| 1721 | fScissorState.fEnabled = false; |
| 1722 | this->flushScissor(); |
| 1723 | } |
| 1724 | int right = r.fLeft + r.fWidth; |
| 1725 | int top = r.fBottom + r.fHeight; |
| 1726 | GL_CALL(BlitFramebuffer(r.fLeft, r.fBottom, right, top, |
| 1727 | r.fLeft, r.fBottom, right, top, |
| 1728 | GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST)); |
bsalomon@google.com | a9ecdad | 2011-03-23 13:50:34 +0000 | [diff] [blame] | 1729 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1730 | } |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1731 | rt->flagAsResolved(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1732 | } |
| 1733 | } |
| 1734 | |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1735 | namespace { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1736 | |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1737 | GrGLenum gr_to_gl_stencil_func(GrStencilFunc basicFunc) { |
| 1738 | static const GrGLenum gTable[] = { |
| 1739 | GR_GL_ALWAYS, // kAlways_StencilFunc |
| 1740 | GR_GL_NEVER, // kNever_StencilFunc |
| 1741 | GR_GL_GREATER, // kGreater_StencilFunc |
| 1742 | GR_GL_GEQUAL, // kGEqual_StencilFunc |
| 1743 | GR_GL_LESS, // kLess_StencilFunc |
| 1744 | GR_GL_LEQUAL, // kLEqual_StencilFunc, |
| 1745 | GR_GL_EQUAL, // kEqual_StencilFunc, |
| 1746 | GR_GL_NOTEQUAL, // kNotEqual_StencilFunc, |
| 1747 | }; |
| 1748 | GR_STATIC_ASSERT(GR_ARRAY_COUNT(gTable) == kBasicStencilFuncCount); |
| 1749 | GR_STATIC_ASSERT(0 == kAlways_StencilFunc); |
| 1750 | GR_STATIC_ASSERT(1 == kNever_StencilFunc); |
| 1751 | GR_STATIC_ASSERT(2 == kGreater_StencilFunc); |
| 1752 | GR_STATIC_ASSERT(3 == kGEqual_StencilFunc); |
| 1753 | GR_STATIC_ASSERT(4 == kLess_StencilFunc); |
| 1754 | GR_STATIC_ASSERT(5 == kLEqual_StencilFunc); |
| 1755 | GR_STATIC_ASSERT(6 == kEqual_StencilFunc); |
| 1756 | GR_STATIC_ASSERT(7 == kNotEqual_StencilFunc); |
| 1757 | GrAssert((unsigned) basicFunc < kBasicStencilFuncCount); |
| 1758 | |
| 1759 | return gTable[basicFunc]; |
| 1760 | } |
| 1761 | |
| 1762 | GrGLenum gr_to_gl_stencil_op(GrStencilOp op) { |
| 1763 | static const GrGLenum gTable[] = { |
| 1764 | GR_GL_KEEP, // kKeep_StencilOp |
| 1765 | GR_GL_REPLACE, // kReplace_StencilOp |
| 1766 | GR_GL_INCR_WRAP, // kIncWrap_StencilOp |
| 1767 | GR_GL_INCR, // kIncClamp_StencilOp |
| 1768 | GR_GL_DECR_WRAP, // kDecWrap_StencilOp |
| 1769 | GR_GL_DECR, // kDecClamp_StencilOp |
| 1770 | GR_GL_ZERO, // kZero_StencilOp |
| 1771 | GR_GL_INVERT, // kInvert_StencilOp |
| 1772 | }; |
| 1773 | GR_STATIC_ASSERT(GR_ARRAY_COUNT(gTable) == kStencilOpCount); |
| 1774 | GR_STATIC_ASSERT(0 == kKeep_StencilOp); |
| 1775 | GR_STATIC_ASSERT(1 == kReplace_StencilOp); |
| 1776 | GR_STATIC_ASSERT(2 == kIncWrap_StencilOp); |
| 1777 | GR_STATIC_ASSERT(3 == kIncClamp_StencilOp); |
| 1778 | GR_STATIC_ASSERT(4 == kDecWrap_StencilOp); |
| 1779 | GR_STATIC_ASSERT(5 == kDecClamp_StencilOp); |
| 1780 | GR_STATIC_ASSERT(6 == kZero_StencilOp); |
| 1781 | GR_STATIC_ASSERT(7 == kInvert_StencilOp); |
| 1782 | GrAssert((unsigned) op < kStencilOpCount); |
| 1783 | return gTable[op]; |
| 1784 | } |
| 1785 | |
| 1786 | void set_gl_stencil(const GrGLInterface* gl, |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1787 | const GrStencilSettings& settings, |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1788 | GrGLenum glFace, |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1789 | GrStencilSettings::Face grFace) { |
| 1790 | GrGLenum glFunc = gr_to_gl_stencil_func(settings.func(grFace)); |
| 1791 | GrGLenum glFailOp = gr_to_gl_stencil_op(settings.failOp(grFace)); |
| 1792 | GrGLenum glPassOp = gr_to_gl_stencil_op(settings.passOp(grFace)); |
| 1793 | |
| 1794 | GrGLint ref = settings.funcRef(grFace); |
| 1795 | GrGLint mask = settings.funcMask(grFace); |
| 1796 | GrGLint writeMask = settings.writeMask(grFace); |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1797 | |
| 1798 | if (GR_GL_FRONT_AND_BACK == glFace) { |
| 1799 | // we call the combined func just in case separate stencil is not |
| 1800 | // supported. |
| 1801 | GR_GL_CALL(gl, StencilFunc(glFunc, ref, mask)); |
| 1802 | GR_GL_CALL(gl, StencilMask(writeMask)); |
| 1803 | GR_GL_CALL(gl, StencilOp(glFailOp, glPassOp, glPassOp)); |
| 1804 | } else { |
| 1805 | GR_GL_CALL(gl, StencilFuncSeparate(glFace, glFunc, ref, mask)); |
| 1806 | GR_GL_CALL(gl, StencilMaskSeparate(glFace, writeMask)); |
| 1807 | GR_GL_CALL(gl, StencilOpSeparate(glFace, glFailOp, glPassOp, glPassOp)); |
| 1808 | } |
| 1809 | } |
| 1810 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1811 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1812 | void GrGpuGL::flushStencil(DrawType type) { |
| 1813 | if (kStencilPath_DrawType == type) { |
| 1814 | GrAssert(!fStencilSettings.isTwoSided()); |
| 1815 | // Just the func, ref, and mask is set here. The op and write mask are params to the call |
| 1816 | // that draws the path to the SB (glStencilFillPath) |
| 1817 | GrGLenum func = |
| 1818 | gr_to_gl_stencil_func(fStencilSettings.func(GrStencilSettings::kFront_Face)); |
| 1819 | GL_CALL(PathStencilFunc(func, |
| 1820 | fStencilSettings.funcRef(GrStencilSettings::kFront_Face), |
| 1821 | fStencilSettings.funcMask(GrStencilSettings::kFront_Face))); |
| 1822 | } else if (fHWStencilSettings != fStencilSettings) { |
| 1823 | if (fStencilSettings.isDisabled()) { |
| 1824 | if (kNo_TriState != fHWStencilTestEnabled) { |
| 1825 | GL_CALL(Disable(GR_GL_STENCIL_TEST)); |
| 1826 | fHWStencilTestEnabled = kNo_TriState; |
| 1827 | } |
| 1828 | } else { |
| 1829 | if (kYes_TriState != fHWStencilTestEnabled) { |
| 1830 | GL_CALL(Enable(GR_GL_STENCIL_TEST)); |
| 1831 | fHWStencilTestEnabled = kYes_TriState; |
| 1832 | } |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1833 | } |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1834 | if (!fStencilSettings.isDisabled()) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1835 | if (this->caps()->twoSidedStencilSupport()) { |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1836 | set_gl_stencil(this->glInterface(), |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1837 | fStencilSettings, |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1838 | GR_GL_FRONT, |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1839 | GrStencilSettings::kFront_Face); |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1840 | set_gl_stencil(this->glInterface(), |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1841 | fStencilSettings, |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1842 | GR_GL_BACK, |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1843 | GrStencilSettings::kBack_Face); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1844 | } else { |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1845 | set_gl_stencil(this->glInterface(), |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1846 | fStencilSettings, |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1847 | GR_GL_FRONT_AND_BACK, |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1848 | GrStencilSettings::kFront_Face); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1849 | } |
| 1850 | } |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1851 | fHWStencilSettings = fStencilSettings; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1852 | } |
| 1853 | } |
| 1854 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1855 | void GrGpuGL::flushAAState(DrawType type) { |
bsalomon@google.com | 202d139 | 2013-03-19 18:58:08 +0000 | [diff] [blame] | 1856 | // At least some ATI linux drivers will render GL_LINES incorrectly when MSAA state is enabled but |
| 1857 | // the target is not multisampled. Single pixel wide lines are rendered thicker than 1 pixel wide. |
| 1858 | #if 0 |
| 1859 | // Replace RT_HAS_MSAA with this definition once this driver bug is no longer a relevant concern |
| 1860 | #define RT_HAS_MSAA rt->isMultisampled() |
| 1861 | #else |
| 1862 | #define RT_HAS_MSAA (rt->isMultisampled() || kDrawLines_DrawType == type) |
| 1863 | #endif |
| 1864 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1865 | const GrRenderTarget* rt = this->getDrawState().getRenderTarget(); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1866 | if (kDesktop_GrGLBinding == this->glBinding()) { |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 1867 | // ES doesn't support toggling GL_MULTISAMPLE and doesn't have |
| 1868 | // smooth lines. |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 1869 | // we prefer smooth lines over multisampled lines |
bsalomon@google.com | 4d5f3fe | 2012-05-21 17:11:44 +0000 | [diff] [blame] | 1870 | bool smoothLines = false; |
| 1871 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1872 | if (kDrawLines_DrawType == type) { |
bsalomon@google.com | 4d5f3fe | 2012-05-21 17:11:44 +0000 | [diff] [blame] | 1873 | smoothLines = this->willUseHWAALines(); |
| 1874 | if (smoothLines) { |
| 1875 | if (kYes_TriState != fHWAAState.fSmoothLineEnabled) { |
| 1876 | GL_CALL(Enable(GR_GL_LINE_SMOOTH)); |
| 1877 | fHWAAState.fSmoothLineEnabled = kYes_TriState; |
| 1878 | // must disable msaa to use line smoothing |
bsalomon@google.com | 202d139 | 2013-03-19 18:58:08 +0000 | [diff] [blame] | 1879 | if (RT_HAS_MSAA && |
bsalomon@google.com | 4d5f3fe | 2012-05-21 17:11:44 +0000 | [diff] [blame] | 1880 | kNo_TriState != fHWAAState.fMSAAEnabled) { |
| 1881 | GL_CALL(Disable(GR_GL_MULTISAMPLE)); |
| 1882 | fHWAAState.fMSAAEnabled = kNo_TriState; |
| 1883 | } |
| 1884 | } |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 1885 | } else { |
bsalomon@google.com | 4d5f3fe | 2012-05-21 17:11:44 +0000 | [diff] [blame] | 1886 | if (kNo_TriState != fHWAAState.fSmoothLineEnabled) { |
| 1887 | GL_CALL(Disable(GR_GL_LINE_SMOOTH)); |
| 1888 | fHWAAState.fSmoothLineEnabled = kNo_TriState; |
| 1889 | } |
| 1890 | } |
| 1891 | } |
bsalomon@google.com | 202d139 | 2013-03-19 18:58:08 +0000 | [diff] [blame] | 1892 | if (!smoothLines && RT_HAS_MSAA) { |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1893 | // FIXME: GL_NV_pr doesn't seem to like MSAA disabled. The paths |
| 1894 | // convex hulls of each segment appear to get filled. |
| 1895 | bool enableMSAA = kStencilPath_DrawType == type || |
| 1896 | this->getDrawState().isHWAntialiasState(); |
| 1897 | if (enableMSAA) { |
bsalomon@google.com | 4d5f3fe | 2012-05-21 17:11:44 +0000 | [diff] [blame] | 1898 | if (kYes_TriState != fHWAAState.fMSAAEnabled) { |
| 1899 | GL_CALL(Enable(GR_GL_MULTISAMPLE)); |
| 1900 | fHWAAState.fMSAAEnabled = kYes_TriState; |
| 1901 | } |
| 1902 | } else { |
| 1903 | if (kNo_TriState != fHWAAState.fMSAAEnabled) { |
| 1904 | GL_CALL(Disable(GR_GL_MULTISAMPLE)); |
| 1905 | fHWAAState.fMSAAEnabled = kNo_TriState; |
| 1906 | } |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 1907 | } |
| 1908 | } |
| 1909 | } |
| 1910 | } |
| 1911 | |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 1912 | void GrGpuGL::flushBlend(bool isLines, |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1913 | GrBlendCoeff srcCoeff, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1914 | GrBlendCoeff dstCoeff) { |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 1915 | if (isLines && this->willUseHWAALines()) { |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 1916 | if (kYes_TriState != fHWBlendState.fEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1917 | GL_CALL(Enable(GR_GL_BLEND)); |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 1918 | fHWBlendState.fEnabled = kYes_TriState; |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1919 | } |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 1920 | if (kSA_GrBlendCoeff != fHWBlendState.fSrcCoeff || |
| 1921 | kISA_GrBlendCoeff != fHWBlendState.fDstCoeff) { |
| 1922 | GL_CALL(BlendFunc(gXfermodeCoeff2Blend[kSA_GrBlendCoeff], |
| 1923 | gXfermodeCoeff2Blend[kISA_GrBlendCoeff])); |
| 1924 | fHWBlendState.fSrcCoeff = kSA_GrBlendCoeff; |
| 1925 | fHWBlendState.fDstCoeff = kISA_GrBlendCoeff; |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1926 | } |
| 1927 | } else { |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1928 | // any optimization to disable blending should |
| 1929 | // have already been applied and tweaked the coeffs |
| 1930 | // to (1, 0). |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 1931 | bool blendOff = kOne_GrBlendCoeff == srcCoeff && |
| 1932 | kZero_GrBlendCoeff == dstCoeff; |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 1933 | if (blendOff) { |
| 1934 | if (kNo_TriState != fHWBlendState.fEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1935 | GL_CALL(Disable(GR_GL_BLEND)); |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 1936 | fHWBlendState.fEnabled = kNo_TriState; |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1937 | } |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 1938 | } else { |
| 1939 | if (kYes_TriState != fHWBlendState.fEnabled) { |
| 1940 | GL_CALL(Enable(GR_GL_BLEND)); |
| 1941 | fHWBlendState.fEnabled = kYes_TriState; |
| 1942 | } |
| 1943 | if (fHWBlendState.fSrcCoeff != srcCoeff || |
| 1944 | fHWBlendState.fDstCoeff != dstCoeff) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1945 | GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff], |
| 1946 | gXfermodeCoeff2Blend[dstCoeff])); |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 1947 | fHWBlendState.fSrcCoeff = srcCoeff; |
| 1948 | fHWBlendState.fDstCoeff = dstCoeff; |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1949 | } |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 1950 | GrColor blendConst = this->getDrawState().getBlendConstant(); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1951 | if ((BlendCoeffReferencesConstant(srcCoeff) || |
| 1952 | BlendCoeffReferencesConstant(dstCoeff)) && |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 1953 | (!fHWBlendState.fConstColorValid || |
| 1954 | fHWBlendState.fConstColor != blendConst)) { |
bsalomon@google.com | 7534747 | 2012-09-17 17:23:21 +0000 | [diff] [blame] | 1955 | GrGLfloat c[4]; |
| 1956 | GrColorToRGBAFloat(blendConst, c); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1957 | GL_CALL(BlendColor(c[0], c[1], c[2], c[3])); |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 1958 | fHWBlendState.fConstColor = blendConst; |
| 1959 | fHWBlendState.fConstColorValid = true; |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1960 | } |
| 1961 | } |
| 1962 | } |
| 1963 | } |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1964 | namespace { |
| 1965 | |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 1966 | inline void set_tex_swizzle(GrGLenum swizzle[4], const GrGLInterface* gl) { |
bsalomon@google.com | 4d063de | 2012-05-31 17:59:23 +0000 | [diff] [blame] | 1967 | GR_GL_CALL(gl, TexParameteriv(GR_GL_TEXTURE_2D, |
| 1968 | GR_GL_TEXTURE_SWIZZLE_RGBA, |
| 1969 | reinterpret_cast<const GrGLint*>(swizzle))); |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1970 | } |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 1971 | |
bsalomon@google.com | 6c76d24 | 2012-09-07 16:52:24 +0000 | [diff] [blame] | 1972 | inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) { |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 1973 | static const GrGLenum gWrapModes[] = { |
| 1974 | GR_GL_CLAMP_TO_EDGE, |
| 1975 | GR_GL_REPEAT, |
| 1976 | GR_GL_MIRRORED_REPEAT |
| 1977 | }; |
commit-bot@chromium.org | 5d7ca95 | 2013-04-22 20:26:44 +0000 | [diff] [blame] | 1978 | GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes)); |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 1979 | GR_STATIC_ASSERT(0 == SkShader::kClamp_TileMode); |
| 1980 | GR_STATIC_ASSERT(1 == SkShader::kRepeat_TileMode); |
| 1981 | GR_STATIC_ASSERT(2 == SkShader::kMirror_TileMode); |
| 1982 | return gWrapModes[tm]; |
| 1983 | } |
| 1984 | |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1985 | } |
| 1986 | |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 1987 | void GrGpuGL::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* texture) { |
| 1988 | GrAssert(NULL != texture); |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 1989 | |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 1990 | // If we created a rt/tex and rendered to it without using a texture and now we're texturing |
| 1991 | // from the rt it will still be the last bound texture, but it needs resolving. So keep this |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 1992 | // out of the "last != next" check. |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 1993 | GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderTarget()); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 1994 | if (NULL != texRT) { |
| 1995 | this->onResolveRenderTarget(texRT); |
| 1996 | } |
| 1997 | |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 1998 | if (fHWBoundTextures[unitIdx] != texture) { |
| 1999 | this->setTextureUnit(unitIdx); |
| 2000 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, texture->textureID())); |
| 2001 | fHWBoundTextures[unitIdx] = texture; |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2002 | } |
| 2003 | |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2004 | ResetTimestamp timestamp; |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2005 | const GrGLTexture::TexParams& oldTexParams = texture->getCachedTexParams(×tamp); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2006 | bool setAll = timestamp < this->getResetTimestamp(); |
| 2007 | GrGLTexture::TexParams newTexParams; |
| 2008 | |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 2009 | newTexParams.fFilter = params.isBilerp() ? GR_GL_LINEAR : GR_GL_NEAREST; |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2010 | |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 2011 | newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX()); |
| 2012 | newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY()); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2013 | memcpy(newTexParams.fSwizzleRGBA, |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2014 | GrGLShaderBuilder::GetTexParamSwizzle(texture->config(), this->glCaps()), |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2015 | sizeof(newTexParams.fSwizzleRGBA)); |
| 2016 | if (setAll || newTexParams.fFilter != oldTexParams.fFilter) { |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2017 | this->setTextureUnit(unitIdx); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2018 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 2019 | GR_GL_TEXTURE_MAG_FILTER, |
| 2020 | newTexParams.fFilter)); |
| 2021 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 2022 | GR_GL_TEXTURE_MIN_FILTER, |
| 2023 | newTexParams.fFilter)); |
| 2024 | } |
| 2025 | if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) { |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2026 | this->setTextureUnit(unitIdx); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2027 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 2028 | GR_GL_TEXTURE_WRAP_S, |
| 2029 | newTexParams.fWrapS)); |
| 2030 | } |
| 2031 | if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) { |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2032 | this->setTextureUnit(unitIdx); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2033 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 2034 | GR_GL_TEXTURE_WRAP_T, |
| 2035 | newTexParams.fWrapT)); |
| 2036 | } |
| 2037 | if (this->glCaps().textureSwizzleSupport() && |
| 2038 | (setAll || memcmp(newTexParams.fSwizzleRGBA, |
| 2039 | oldTexParams.fSwizzleRGBA, |
| 2040 | sizeof(newTexParams.fSwizzleRGBA)))) { |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2041 | this->setTextureUnit(unitIdx); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2042 | set_tex_swizzle(newTexParams.fSwizzleRGBA, |
| 2043 | this->glInterface()); |
| 2044 | } |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2045 | texture->setCachedTexParams(newTexParams, this->getResetTimestamp()); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2046 | } |
| 2047 | |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 2048 | void GrGpuGL::flushMiscFixedFunctionState() { |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2049 | |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 2050 | const GrDrawState& drawState = this->getDrawState(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2051 | |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 2052 | if (drawState.isDitherState()) { |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 2053 | if (kYes_TriState != fHWDitherEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2054 | GL_CALL(Enable(GR_GL_DITHER)); |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 2055 | fHWDitherEnabled = kYes_TriState; |
| 2056 | } |
| 2057 | } else { |
| 2058 | if (kNo_TriState != fHWDitherEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2059 | GL_CALL(Disable(GR_GL_DITHER)); |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 2060 | fHWDitherEnabled = kNo_TriState; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2061 | } |
| 2062 | } |
| 2063 | |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 2064 | if (drawState.isColorWriteDisabled()) { |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 2065 | if (kNo_TriState != fHWWriteToColor) { |
| 2066 | GL_CALL(ColorMask(GR_GL_FALSE, GR_GL_FALSE, |
| 2067 | GR_GL_FALSE, GR_GL_FALSE)); |
| 2068 | fHWWriteToColor = kNo_TriState; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2069 | } |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 2070 | } else { |
| 2071 | if (kYes_TriState != fHWWriteToColor) { |
| 2072 | GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE)); |
| 2073 | fHWWriteToColor = kYes_TriState; |
| 2074 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2075 | } |
| 2076 | |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 2077 | if (fHWDrawFace != drawState.getDrawFace()) { |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 2078 | switch (this->getDrawState().getDrawFace()) { |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 2079 | case GrDrawState::kCCW_DrawFace: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2080 | GL_CALL(Enable(GR_GL_CULL_FACE)); |
| 2081 | GL_CALL(CullFace(GR_GL_BACK)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2082 | break; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 2083 | case GrDrawState::kCW_DrawFace: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2084 | GL_CALL(Enable(GR_GL_CULL_FACE)); |
| 2085 | GL_CALL(CullFace(GR_GL_FRONT)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2086 | break; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 2087 | case GrDrawState::kBoth_DrawFace: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2088 | GL_CALL(Disable(GR_GL_CULL_FACE)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2089 | break; |
| 2090 | default: |
| 2091 | GrCrash("Unknown draw face."); |
| 2092 | } |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 2093 | fHWDrawFace = drawState.getDrawFace(); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2094 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2095 | } |
| 2096 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2097 | void GrGpuGL::notifyRenderTargetDelete(GrRenderTarget* renderTarget) { |
| 2098 | GrAssert(NULL != renderTarget); |
bsalomon@google.com | c811ea3 | 2012-05-21 15:33:09 +0000 | [diff] [blame] | 2099 | if (fHWBoundRenderTarget == renderTarget) { |
| 2100 | fHWBoundRenderTarget = NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2101 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | void GrGpuGL::notifyTextureDelete(GrGLTexture* texture) { |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 2105 | for (int s = 0; s < fHWBoundTextures.count(); ++s) { |
bsalomon@google.com | c811ea3 | 2012-05-21 15:33:09 +0000 | [diff] [blame] | 2106 | if (fHWBoundTextures[s] == texture) { |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2107 | // deleting bound texture does implied bind to 0 |
bsalomon@google.com | c811ea3 | 2012-05-21 15:33:09 +0000 | [diff] [blame] | 2108 | fHWBoundTextures[s] = NULL; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2109 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2110 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2111 | } |
| 2112 | |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2113 | bool GrGpuGL::configToGLFormats(GrPixelConfig config, |
| 2114 | bool getSizedInternalFormat, |
| 2115 | GrGLenum* internalFormat, |
| 2116 | GrGLenum* externalFormat, |
| 2117 | GrGLenum* externalType) { |
| 2118 | GrGLenum dontCare; |
| 2119 | if (NULL == internalFormat) { |
| 2120 | internalFormat = &dontCare; |
| 2121 | } |
| 2122 | if (NULL == externalFormat) { |
| 2123 | externalFormat = &dontCare; |
| 2124 | } |
| 2125 | if (NULL == externalType) { |
| 2126 | externalType = &dontCare; |
| 2127 | } |
| 2128 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2129 | switch (config) { |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 2130 | case kRGBA_8888_GrPixelConfig: |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 2131 | *internalFormat = GR_GL_RGBA; |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2132 | *externalFormat = GR_GL_RGBA; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2133 | if (getSizedInternalFormat) { |
| 2134 | *internalFormat = GR_GL_RGBA8; |
| 2135 | } else { |
| 2136 | *internalFormat = GR_GL_RGBA; |
| 2137 | } |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 2138 | *externalType = GR_GL_UNSIGNED_BYTE; |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 2139 | break; |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 2140 | case kBGRA_8888_GrPixelConfig: |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 2141 | if (!this->glCaps().bgraFormatSupport()) { |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 2142 | return false; |
| 2143 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 2144 | if (this->glCaps().bgraIsInternalFormat()) { |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2145 | if (getSizedInternalFormat) { |
| 2146 | *internalFormat = GR_GL_BGRA8; |
| 2147 | } else { |
| 2148 | *internalFormat = GR_GL_BGRA; |
| 2149 | } |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 2150 | } else { |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2151 | if (getSizedInternalFormat) { |
| 2152 | *internalFormat = GR_GL_RGBA8; |
| 2153 | } else { |
| 2154 | *internalFormat = GR_GL_RGBA; |
| 2155 | } |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 2156 | } |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2157 | *externalFormat = GR_GL_BGRA; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 2158 | *externalType = GR_GL_UNSIGNED_BYTE; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2159 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2160 | case kRGB_565_GrPixelConfig: |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2161 | *internalFormat = GR_GL_RGB; |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2162 | *externalFormat = GR_GL_RGB; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2163 | if (getSizedInternalFormat) { |
| 2164 | if (this->glBinding() == kDesktop_GrGLBinding) { |
| 2165 | return false; |
| 2166 | } else { |
| 2167 | *internalFormat = GR_GL_RGB565; |
| 2168 | } |
| 2169 | } else { |
| 2170 | *internalFormat = GR_GL_RGB; |
| 2171 | } |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 2172 | *externalType = GR_GL_UNSIGNED_SHORT_5_6_5; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2173 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2174 | case kRGBA_4444_GrPixelConfig: |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2175 | *internalFormat = GR_GL_RGBA; |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2176 | *externalFormat = GR_GL_RGBA; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2177 | if (getSizedInternalFormat) { |
| 2178 | *internalFormat = GR_GL_RGBA4; |
| 2179 | } else { |
| 2180 | *internalFormat = GR_GL_RGBA; |
| 2181 | } |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 2182 | *externalType = GR_GL_UNSIGNED_SHORT_4_4_4_4; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2183 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2184 | case kIndex_8_GrPixelConfig: |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 2185 | if (this->caps()->eightBitPaletteSupport()) { |
bsalomon@google.com | c312bf9 | 2011-03-21 21:10:33 +0000 | [diff] [blame] | 2186 | *internalFormat = GR_GL_PALETTE8_RGBA8; |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2187 | // glCompressedTexImage doesn't take external params |
| 2188 | *externalFormat = GR_GL_PALETTE8_RGBA8; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2189 | // no sized/unsized internal format distinction here |
| 2190 | *internalFormat = GR_GL_PALETTE8_RGBA8; |
| 2191 | // unused with CompressedTexImage |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2192 | *externalType = GR_GL_UNSIGNED_BYTE; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2193 | } else { |
| 2194 | return false; |
| 2195 | } |
| 2196 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2197 | case kAlpha_8_GrPixelConfig: |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 2198 | if (this->glCaps().textureRedSupport()) { |
| 2199 | *internalFormat = GR_GL_RED; |
| 2200 | *externalFormat = GR_GL_RED; |
| 2201 | if (getSizedInternalFormat) { |
| 2202 | *internalFormat = GR_GL_R8; |
| 2203 | } else { |
| 2204 | *internalFormat = GR_GL_RED; |
| 2205 | } |
| 2206 | *externalType = GR_GL_UNSIGNED_BYTE; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2207 | } else { |
| 2208 | *internalFormat = GR_GL_ALPHA; |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 2209 | *externalFormat = GR_GL_ALPHA; |
| 2210 | if (getSizedInternalFormat) { |
| 2211 | *internalFormat = GR_GL_ALPHA8; |
| 2212 | } else { |
| 2213 | *internalFormat = GR_GL_ALPHA; |
| 2214 | } |
| 2215 | *externalType = GR_GL_UNSIGNED_BYTE; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2216 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2217 | break; |
| 2218 | default: |
| 2219 | return false; |
| 2220 | } |
| 2221 | return true; |
| 2222 | } |
| 2223 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2224 | void GrGpuGL::setTextureUnit(int unit) { |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 2225 | GrAssert(unit >= 0 && unit < fHWBoundTextures.count()); |
| 2226 | if (unit != fHWActiveTextureUnitIdx) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2227 | GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + unit)); |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 2228 | fHWActiveTextureUnitIdx = unit; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2229 | } |
| 2230 | } |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 2231 | |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 2232 | void GrGpuGL::setScratchTextureUnit() { |
| 2233 | // Bind the last texture unit since it is the least likely to be used by GrGLProgram. |
| 2234 | int lastUnitIdx = fHWBoundTextures.count() - 1; |
| 2235 | if (lastUnitIdx != fHWActiveTextureUnitIdx) { |
| 2236 | GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + lastUnitIdx)); |
| 2237 | fHWActiveTextureUnitIdx = lastUnitIdx; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2238 | } |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 2239 | // clear out the this field so that if a program does use this unit it will rebind the correct |
| 2240 | // texture. |
| 2241 | fHWBoundTextures[lastUnitIdx] = NULL; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2242 | } |
| 2243 | |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2244 | namespace { |
| 2245 | // Determines whether glBlitFramebuffer could be used between src and dst. |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2246 | inline bool can_blit_framebuffer(const GrSurface* dst, |
| 2247 | const GrSurface* src, |
| 2248 | const GrGpuGL* gpu, |
| 2249 | bool* wouldNeedTempFBO = NULL) { |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 2250 | if (gpu->isConfigRenderable(dst->config()) && |
| 2251 | gpu->isConfigRenderable(src->config()) && |
| 2252 | gpu->glCaps().usesMSAARenderBuffers()) { |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2253 | if (NULL != wouldNeedTempFBO) { |
| 2254 | *wouldNeedTempFBO = NULL == dst->asRenderTarget() || NULL == src->asRenderTarget(); |
| 2255 | } |
| 2256 | return true; |
| 2257 | } else { |
| 2258 | return false; |
| 2259 | } |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2260 | } |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2261 | |
| 2262 | inline bool can_copy_texsubimage(const GrSurface* dst, |
| 2263 | const GrSurface* src, |
| 2264 | const GrGpuGL* gpu, |
| 2265 | bool* wouldNeedTempFBO = NULL) { |
| 2266 | // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSubImage |
| 2267 | // and BGRA isn't in the spec. There doesn't appear to be any extension that adds it. Perhaps |
| 2268 | // many drivers would allow it to work, but ANGLE does not. |
| 2269 | if (kES2_GrGLBinding == gpu->glBinding() && gpu->glCaps().bgraIsInternalFormat() && |
| 2270 | (kBGRA_8888_GrPixelConfig == dst->config() || kBGRA_8888_GrPixelConfig == src->config())) { |
| 2271 | return false; |
| 2272 | } |
| 2273 | const GrGLRenderTarget* dstRT = static_cast<const GrGLRenderTarget*>(dst->asRenderTarget()); |
| 2274 | // If dst is multisampled (and uses an extension where there is a separate MSAA renderbuffer) |
| 2275 | // then we don't want to copy to the texture but to the MSAA buffer. |
| 2276 | if (NULL != dstRT && dstRT->renderFBOID() != dstRT->textureFBOID()) { |
| 2277 | return false; |
| 2278 | } |
bsalomon@google.com | a271985 | 2013-04-17 14:25:27 +0000 | [diff] [blame] | 2279 | const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->asRenderTarget()); |
| 2280 | // If the src is multisampled (and uses an extension where there is a separate MSAA |
| 2281 | // renderbuffer) then it is an invalid operation to call CopyTexSubImage |
| 2282 | if (NULL != srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) { |
| 2283 | return false; |
| 2284 | } |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2285 | if (gpu->isConfigRenderable(src->config()) && NULL != dst->asTexture() && |
| 2286 | dst->origin() == src->origin() && kIndex_8_GrPixelConfig != src->config()) { |
| 2287 | if (NULL != wouldNeedTempFBO) { |
| 2288 | *wouldNeedTempFBO = NULL == src->asRenderTarget(); |
| 2289 | } |
| 2290 | return true; |
| 2291 | } else { |
| 2292 | return false; |
| 2293 | } |
| 2294 | } |
| 2295 | |
| 2296 | // If a temporary FBO was created, its non-zero ID is returned. The viewport that the copy rect is |
| 2297 | // relative to is output. |
| 2298 | inline GrGLuint bind_surface_as_fbo(const GrGLInterface* gl, |
| 2299 | GrSurface* surface, |
| 2300 | GrGLenum fboTarget, |
| 2301 | GrGLIRect* viewport) { |
| 2302 | GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderTarget()); |
| 2303 | GrGLuint tempFBOID; |
| 2304 | if (NULL == rt) { |
| 2305 | GrAssert(NULL != surface->asTexture()); |
| 2306 | GrGLuint texID = static_cast<GrGLTexture*>(surface->asTexture())->textureID(); |
| 2307 | GR_GL_CALL(gl, GenFramebuffers(1, &tempFBOID)); |
| 2308 | GR_GL_CALL(gl, BindFramebuffer(fboTarget, tempFBOID)); |
| 2309 | GR_GL_CALL(gl, FramebufferTexture2D(fboTarget, |
| 2310 | GR_GL_COLOR_ATTACHMENT0, |
| 2311 | GR_GL_TEXTURE_2D, |
| 2312 | texID, |
| 2313 | 0)); |
| 2314 | viewport->fLeft = 0; |
| 2315 | viewport->fBottom = 0; |
| 2316 | viewport->fWidth = surface->width(); |
| 2317 | viewport->fHeight = surface->height(); |
| 2318 | } else { |
| 2319 | tempFBOID = 0; |
| 2320 | GR_GL_CALL(gl, BindFramebuffer(fboTarget, rt->renderFBOID())); |
| 2321 | *viewport = rt->getViewport(); |
| 2322 | } |
| 2323 | return tempFBOID; |
| 2324 | } |
| 2325 | |
| 2326 | } |
| 2327 | |
| 2328 | void GrGpuGL::initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* desc) { |
| 2329 | // Check for format issues with glCopyTexSubImage2D |
| 2330 | if (kES2_GrGLBinding == this->glBinding() && this->glCaps().bgraIsInternalFormat() && |
| 2331 | kBGRA_8888_GrPixelConfig == src->config()) { |
| 2332 | // glCopyTexSubImage2D doesn't work with this config. We'll want to make it a render target |
bsalomon@google.com | 31c4e89 | 2013-04-15 13:55:02 +0000 | [diff] [blame] | 2333 | // in order to call glBlitFramebuffer or to copy to it by rendering. |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2334 | INHERITED::initCopySurfaceDstDesc(src, desc); |
bsalomon@google.com | a271985 | 2013-04-17 14:25:27 +0000 | [diff] [blame] | 2335 | return; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2336 | } else if (NULL == src->asRenderTarget()) { |
| 2337 | // We don't want to have to create an FBO just to use glCopyTexSubImage2D. Let the base |
| 2338 | // class handle it by rendering. |
| 2339 | INHERITED::initCopySurfaceDstDesc(src, desc); |
bsalomon@google.com | a271985 | 2013-04-17 14:25:27 +0000 | [diff] [blame] | 2340 | return; |
| 2341 | } |
| 2342 | |
| 2343 | const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->asRenderTarget()); |
| 2344 | if (NULL != srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) { |
| 2345 | // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. |
| 2346 | INHERITED::initCopySurfaceDstDesc(src, desc); |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2347 | } else { |
| 2348 | desc->fConfig = src->config(); |
| 2349 | desc->fOrigin = src->origin(); |
| 2350 | desc->fFlags = kNone_GrTextureFlags; |
| 2351 | } |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2352 | } |
| 2353 | |
| 2354 | bool GrGpuGL::onCopySurface(GrSurface* dst, |
| 2355 | GrSurface* src, |
| 2356 | const SkIRect& srcRect, |
| 2357 | const SkIPoint& dstPoint) { |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2358 | bool inheritedCouldCopy = INHERITED::onCanCopySurface(dst, src, srcRect, dstPoint); |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2359 | bool copied = false; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2360 | bool wouldNeedTempFBO = false; |
| 2361 | if (can_copy_texsubimage(dst, src, this, &wouldNeedTempFBO) && |
| 2362 | (!wouldNeedTempFBO || !inheritedCouldCopy)) { |
| 2363 | GrGLuint srcFBO; |
| 2364 | GrGLIRect srcVP; |
| 2365 | srcFBO = bind_surface_as_fbo(this->glInterface(), src, GR_GL_FRAMEBUFFER, &srcVP); |
| 2366 | GrGLTexture* dstTex = static_cast<GrGLTexture*>(dst->asTexture()); |
| 2367 | GrAssert(NULL != dstTex); |
| 2368 | // We modified the bound FBO |
| 2369 | fHWBoundRenderTarget = NULL; |
| 2370 | GrGLIRect srcGLRect; |
| 2371 | srcGLRect.setRelativeTo(srcVP, |
| 2372 | srcRect.fLeft, |
| 2373 | srcRect.fTop, |
| 2374 | srcRect.width(), |
| 2375 | srcRect.height(), |
| 2376 | src->origin()); |
| 2377 | |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 2378 | this->setScratchTextureUnit(); |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2379 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, dstTex->textureID())); |
| 2380 | GrGLint dstY; |
| 2381 | if (kBottomLeft_GrSurfaceOrigin == dst->origin()) { |
| 2382 | dstY = dst->height() - (dstPoint.fY + srcGLRect.fHeight); |
| 2383 | } else { |
| 2384 | dstY = dstPoint.fY; |
| 2385 | } |
| 2386 | GL_CALL(CopyTexSubImage2D(GR_GL_TEXTURE_2D, 0, |
| 2387 | dstPoint.fX, dstY, |
| 2388 | srcGLRect.fLeft, srcGLRect.fBottom, |
| 2389 | srcGLRect.fWidth, srcGLRect.fHeight)); |
| 2390 | copied = true; |
| 2391 | if (srcFBO) { |
| 2392 | GL_CALL(DeleteFramebuffers(1, &srcFBO)); |
| 2393 | } |
| 2394 | } else if (can_blit_framebuffer(dst, src, this, &wouldNeedTempFBO) && |
| 2395 | (!wouldNeedTempFBO || !inheritedCouldCopy)) { |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2396 | SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, |
| 2397 | srcRect.width(), srcRect.height()); |
| 2398 | bool selfOverlap = false; |
| 2399 | if (dst->isSameAs(src)) { |
| 2400 | selfOverlap = SkIRect::IntersectsNoEmptyCheck(dstRect, srcRect); |
| 2401 | } |
| 2402 | |
| 2403 | if (!selfOverlap) { |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2404 | GrGLuint dstFBO; |
| 2405 | GrGLuint srcFBO; |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2406 | GrGLIRect dstVP; |
| 2407 | GrGLIRect srcVP; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2408 | dstFBO = bind_surface_as_fbo(this->glInterface(), dst, GR_GL_DRAW_FRAMEBUFFER, &dstVP); |
| 2409 | srcFBO = bind_surface_as_fbo(this->glInterface(), src, GR_GL_READ_FRAMEBUFFER, &srcVP); |
| 2410 | // We modified the bound FBO |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2411 | fHWBoundRenderTarget = NULL; |
| 2412 | GrGLIRect srcGLRect; |
| 2413 | GrGLIRect dstGLRect; |
| 2414 | srcGLRect.setRelativeTo(srcVP, |
| 2415 | srcRect.fLeft, |
| 2416 | srcRect.fTop, |
| 2417 | srcRect.width(), |
| 2418 | srcRect.height(), |
| 2419 | src->origin()); |
| 2420 | dstGLRect.setRelativeTo(dstVP, |
| 2421 | dstRect.fLeft, |
| 2422 | dstRect.fTop, |
| 2423 | dstRect.width(), |
| 2424 | dstRect.height(), |
| 2425 | dst->origin()); |
| 2426 | |
| 2427 | GrAutoTRestore<ScissorState> asr; |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 2428 | if (GrGLCaps::kDesktop_EXT_MSFBOType == this->glCaps().msFBOType()) { |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2429 | // The EXT version applies the scissor during the blit, so disable it. |
| 2430 | asr.reset(&fScissorState); |
| 2431 | fScissorState.fEnabled = false; |
| 2432 | this->flushScissor(); |
| 2433 | } |
| 2434 | GrGLint srcY0; |
| 2435 | GrGLint srcY1; |
| 2436 | // Does the blit need to y-mirror or not? |
| 2437 | if (src->origin() == dst->origin()) { |
| 2438 | srcY0 = srcGLRect.fBottom; |
| 2439 | srcY1 = srcGLRect.fBottom + srcGLRect.fHeight; |
| 2440 | } else { |
| 2441 | srcY0 = srcGLRect.fBottom + srcGLRect.fHeight; |
| 2442 | srcY1 = srcGLRect.fBottom; |
| 2443 | } |
| 2444 | GL_CALL(BlitFramebuffer(srcGLRect.fLeft, |
| 2445 | srcY0, |
| 2446 | srcGLRect.fLeft + srcGLRect.fWidth, |
| 2447 | srcY1, |
| 2448 | dstGLRect.fLeft, |
| 2449 | dstGLRect.fBottom, |
| 2450 | dstGLRect.fLeft + dstGLRect.fWidth, |
| 2451 | dstGLRect.fBottom + dstGLRect.fHeight, |
| 2452 | GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST)); |
| 2453 | if (dstFBO) { |
| 2454 | GL_CALL(DeleteFramebuffers(1, &dstFBO)); |
| 2455 | } |
| 2456 | if (srcFBO) { |
| 2457 | GL_CALL(DeleteFramebuffers(1, &srcFBO)); |
| 2458 | } |
| 2459 | copied = true; |
| 2460 | } |
| 2461 | } |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2462 | if (!copied && inheritedCouldCopy) { |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2463 | copied = INHERITED::onCopySurface(dst, src, srcRect, dstPoint); |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2464 | GrAssert(copied); |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2465 | } |
| 2466 | return copied; |
| 2467 | } |
| 2468 | |
| 2469 | bool GrGpuGL::onCanCopySurface(GrSurface* dst, |
| 2470 | GrSurface* src, |
| 2471 | const SkIRect& srcRect, |
| 2472 | const SkIPoint& dstPoint) { |
| 2473 | // This mirrors the logic in onCopySurface. |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2474 | if (can_copy_texsubimage(dst, src, this)) { |
| 2475 | return true; |
| 2476 | } |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2477 | if (can_blit_framebuffer(dst, src, this)) { |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2478 | if (dst->isSameAs(src)) { |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2479 | SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, |
| 2480 | srcRect.width(), srcRect.height()); |
| 2481 | if(!SkIRect::IntersectsNoEmptyCheck(dstRect, srcRect)) { |
| 2482 | return true; |
| 2483 | } |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2484 | } else { |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2485 | return true; |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2486 | } |
| 2487 | } |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2488 | return INHERITED::onCanCopySurface(dst, src, srcRect, dstPoint); |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 2492 | /////////////////////////////////////////////////////////////////////////////// |
| 2493 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 2494 | GrGLAttribArrayState* GrGpuGL::HWGeometryState::bindArrayAndBuffersToDraw( |
| 2495 | GrGpuGL* gpu, |
| 2496 | const GrGLVertexBuffer* vbuffer, |
| 2497 | const GrGLIndexBuffer* ibuffer) { |
| 2498 | GrAssert(NULL != vbuffer); |
robertphillips@google.com | 4f65a27 | 2013-03-26 19:40:46 +0000 | [diff] [blame] | 2499 | GrGLAttribArrayState* attribState; |
| 2500 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 2501 | // We use a vertex array if we're on a core profile and the verts are in a VBO. |
| 2502 | if (gpu->glCaps().isCoreProfile() && !vbuffer->isCPUBacked()) { |
| 2503 | if (NULL == fVBOVertexArray || !fVBOVertexArray->isValid()) { |
| 2504 | SkSafeUnref(fVBOVertexArray); |
| 2505 | GrGLuint arrayID; |
| 2506 | GR_GL_CALL(gpu->glInterface(), GenVertexArrays(1, &arrayID)); |
| 2507 | int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 2508 | fVBOVertexArray = SkNEW_ARGS(GrGLVertexArray, (gpu, arrayID, attrCount)); |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 2509 | } |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 2510 | attribState = fVBOVertexArray->bindWithIndexBuffer(ibuffer); |
| 2511 | } else { |
| 2512 | if (NULL != ibuffer) { |
| 2513 | this->setIndexBufferIDOnDefaultVertexArray(gpu, ibuffer->bufferID()); |
| 2514 | } else { |
| 2515 | this->setVertexArrayID(gpu, 0); |
| 2516 | } |
| 2517 | int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 2518 | if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 2519 | fDefaultVertexArrayAttribState.resize(attrCount); |
| 2520 | } |
| 2521 | attribState = &fDefaultVertexArrayAttribState; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 2522 | } |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 2523 | return attribState; |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 2524 | } |