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