epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 10 | #include "GrGpuGL.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 11 | #include "GrGLStencilBuffer.h" |
senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 12 | #include "GrTypes.h" |
bsalomon@google.com | 3582bf9 | 2011-06-30 21:32:31 +0000 | [diff] [blame] | 13 | #include "SkTemplates.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 14 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 15 | static const GrGLuint GR_MAX_GLUINT = ~0; |
| 16 | static const GrGLint GR_INVAL_GLINT = ~0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 17 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 18 | #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 19 | #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] | 20 | |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 21 | // we use a spare texture unit to avoid |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 22 | // mucking with the state of any of the stages. |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 23 | static const int SPARE_TEX_UNIT = GrDrawState::kNumStages; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 24 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 25 | #define SKIP_CACHE_CHECK true |
| 26 | |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 27 | #if GR_GL_CHECK_ALLOC_WITH_GET_ERROR |
| 28 | #define CLEAR_ERROR_BEFORE_ALLOC(iface) GrGLClearErr(iface) |
| 29 | #define GL_ALLOC_CALL(iface, call) GR_GL_CALL_NOERRCHECK(iface, call) |
| 30 | #define CHECK_ALLOC_ERROR(iface) GR_GL_GET_ERROR(iface) |
| 31 | #else |
| 32 | #define CLEAR_ERROR_BEFORE_ALLOC(iface) |
| 33 | #define GL_ALLOC_CALL(iface, call) GR_GL_CALL(iface, call) |
| 34 | #define CHECK_ALLOC_ERROR(iface) GR_GL_NO_ERROR |
| 35 | #endif |
| 36 | |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame^] | 37 | /////////////////////////////////////////////////////////////////////////////// |
| 38 | |
| 39 | void GrGpuGL::GLCaps::markConfigAsValidColorAttachment(GrPixelConfig config) { |
| 40 | #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT |
| 41 | return; |
| 42 | #endif |
| 43 | GrAssert(config < kGrPixelConfigCount); |
| 44 | int u32Idx = config / 32; |
| 45 | int bitIdx = config % 32; |
| 46 | fVerifiedColorAttachmentConfigs[u32Idx] |= (1 << bitIdx); |
| 47 | } |
| 48 | |
| 49 | bool GrGpuGL::GLCaps::isConfigVerifiedColorAttachment( |
| 50 | GrPixelConfig config) const { |
| 51 | #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT |
| 52 | return false; |
| 53 | #endif |
| 54 | GrAssert((unsigned)config < kGrPixelConfigCount); |
| 55 | int u32Idx = config / 32; |
| 56 | int bitIdx = config % 32; |
| 57 | return SkToBool(fVerifiedColorAttachmentConfigs[u32Idx] & (1 << bitIdx)); |
| 58 | } |
| 59 | |
| 60 | void GrGpuGL::GLCaps::markColorConfigAndStencilFormatAsVerified( |
| 61 | GrPixelConfig config, |
| 62 | const GrGLStencilBuffer::Format& format) { |
| 63 | #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT |
| 64 | return; |
| 65 | #endif |
| 66 | GrAssert((unsigned)config < kGrPixelConfigCount); |
| 67 | int count = fStencilFormats.count(); |
| 68 | // we expect a really small number of possible formats so linear search |
| 69 | // should be OK |
| 70 | GrAssert(count < 16); |
| 71 | for (int i = 0; i < count; ++i) { |
| 72 | if (format.fInternalFormat == |
| 73 | fStencilFormats[i].fFormat.fInternalFormat) { |
| 74 | int u32Idx = config / 32; |
| 75 | int bitIdx = config % 32; |
| 76 | fStencilFormats[i].fVerifiedColorConfigs[u32Idx] |= (1 << bitIdx); |
| 77 | return; |
| 78 | } |
| 79 | } |
| 80 | SkDEBUGFAIL("Why are we seeing a stencil format that GLCaps doesn't know about."); |
| 81 | } |
| 82 | |
| 83 | bool GrGpuGL::GLCaps::isColorConfigAndStencilFormatVerified( |
| 84 | GrPixelConfig config, |
| 85 | const GrGLStencilBuffer::Format& format) const { |
| 86 | #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT |
| 87 | return false; |
| 88 | #endif |
| 89 | GrAssert((unsigned)config < kGrPixelConfigCount); |
| 90 | int count = fStencilFormats.count(); |
| 91 | // we expect a really small number of possible formats so linear search |
| 92 | // should be OK |
| 93 | GrAssert(count < 16); |
| 94 | for (int i = 0; i < count; ++i) { |
| 95 | if (format.fInternalFormat == |
| 96 | fStencilFormats[i].fFormat.fInternalFormat) { |
| 97 | int u32Idx = config / 32; |
| 98 | int bitIdx = config % 32; |
| 99 | return SkToBool(fStencilFormats[i].fVerifiedColorConfigs[u32Idx] & |
| 100 | (1 << bitIdx)); |
| 101 | } |
| 102 | } |
| 103 | SkDEBUGFAIL("Why are we seeing a stencil format that GLCaps doesn't know about."); |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | /////////////////////////////////////////////////////////////////////////////// |
| 108 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 109 | static const GrGLenum gXfermodeCoeff2Blend[] = { |
| 110 | GR_GL_ZERO, |
| 111 | GR_GL_ONE, |
| 112 | GR_GL_SRC_COLOR, |
| 113 | GR_GL_ONE_MINUS_SRC_COLOR, |
| 114 | GR_GL_DST_COLOR, |
| 115 | GR_GL_ONE_MINUS_DST_COLOR, |
| 116 | GR_GL_SRC_ALPHA, |
| 117 | GR_GL_ONE_MINUS_SRC_ALPHA, |
| 118 | GR_GL_DST_ALPHA, |
| 119 | GR_GL_ONE_MINUS_DST_ALPHA, |
| 120 | GR_GL_CONSTANT_COLOR, |
| 121 | GR_GL_ONE_MINUS_CONSTANT_COLOR, |
| 122 | GR_GL_CONSTANT_ALPHA, |
| 123 | GR_GL_ONE_MINUS_CONSTANT_ALPHA, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 124 | |
| 125 | // extended blend coeffs |
| 126 | GR_GL_SRC1_COLOR, |
| 127 | GR_GL_ONE_MINUS_SRC1_COLOR, |
| 128 | GR_GL_SRC1_ALPHA, |
| 129 | GR_GL_ONE_MINUS_SRC1_ALPHA, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 132 | bool GrGpuGL::BlendCoeffReferencesConstant(GrBlendCoeff coeff) { |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 133 | static const bool gCoeffReferencesBlendConst[] = { |
| 134 | false, |
| 135 | false, |
| 136 | false, |
| 137 | false, |
| 138 | false, |
| 139 | false, |
| 140 | false, |
| 141 | false, |
| 142 | false, |
| 143 | false, |
| 144 | true, |
| 145 | true, |
| 146 | true, |
| 147 | true, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 148 | |
| 149 | // extended blend coeffs |
| 150 | false, |
| 151 | false, |
| 152 | false, |
| 153 | false, |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 154 | }; |
| 155 | return gCoeffReferencesBlendConst[coeff]; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 156 | GR_STATIC_ASSERT(kTotalBlendCoeffCount == GR_ARRAY_COUNT(gCoeffReferencesBlendConst)); |
| 157 | |
| 158 | GR_STATIC_ASSERT(0 == kZero_BlendCoeff); |
| 159 | GR_STATIC_ASSERT(1 == kOne_BlendCoeff); |
| 160 | GR_STATIC_ASSERT(2 == kSC_BlendCoeff); |
| 161 | GR_STATIC_ASSERT(3 == kISC_BlendCoeff); |
| 162 | GR_STATIC_ASSERT(4 == kDC_BlendCoeff); |
| 163 | GR_STATIC_ASSERT(5 == kIDC_BlendCoeff); |
| 164 | GR_STATIC_ASSERT(6 == kSA_BlendCoeff); |
| 165 | GR_STATIC_ASSERT(7 == kISA_BlendCoeff); |
| 166 | GR_STATIC_ASSERT(8 == kDA_BlendCoeff); |
| 167 | GR_STATIC_ASSERT(9 == kIDA_BlendCoeff); |
| 168 | GR_STATIC_ASSERT(10 == kConstC_BlendCoeff); |
| 169 | GR_STATIC_ASSERT(11 == kIConstC_BlendCoeff); |
| 170 | GR_STATIC_ASSERT(12 == kConstA_BlendCoeff); |
| 171 | GR_STATIC_ASSERT(13 == kIConstA_BlendCoeff); |
| 172 | |
| 173 | GR_STATIC_ASSERT(14 == kS2C_BlendCoeff); |
| 174 | GR_STATIC_ASSERT(15 == kIS2C_BlendCoeff); |
| 175 | GR_STATIC_ASSERT(16 == kS2A_BlendCoeff); |
| 176 | GR_STATIC_ASSERT(17 == kIS2A_BlendCoeff); |
| 177 | |
| 178 | // assertion for gXfermodeCoeff2Blend have to be in GrGpu scope |
| 179 | GR_STATIC_ASSERT(kTotalBlendCoeffCount == GR_ARRAY_COUNT(gXfermodeCoeff2Blend)); |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 180 | } |
| 181 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 182 | /////////////////////////////////////////////////////////////////////////////// |
| 183 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 184 | void GrGpuGL::AdjustTextureMatrix(const GrGLTexture* texture, |
| 185 | GrSamplerState::SampleMode mode, |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 186 | GrMatrix* matrix) { |
| 187 | GrAssert(NULL != texture); |
| 188 | GrAssert(NULL != matrix); |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 189 | GrGLTexture::Orientation orientation = texture->orientation(); |
| 190 | if (GrGLTexture::kBottomUp_Orientation == orientation) { |
| 191 | GrMatrix invY; |
| 192 | invY.setAll(GR_Scalar1, 0, 0, |
| 193 | 0, -GR_Scalar1, GR_Scalar1, |
| 194 | 0, 0, GrMatrix::I()[8]); |
| 195 | matrix->postConcat(invY); |
| 196 | } else { |
| 197 | GrAssert(GrGLTexture::kTopDown_Orientation == orientation); |
| 198 | } |
| 199 | } |
| 200 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 201 | bool GrGpuGL::TextureMatrixIsIdentity(const GrGLTexture* texture, |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 202 | const GrSamplerState& sampler) { |
| 203 | GrAssert(NULL != texture); |
| 204 | if (!sampler.getMatrix().isIdentity()) { |
| 205 | return false; |
| 206 | } |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 207 | GrGLTexture::Orientation orientation = texture->orientation(); |
| 208 | if (GrGLTexture::kBottomUp_Orientation == orientation) { |
| 209 | return false; |
| 210 | } else { |
| 211 | GrAssert(GrGLTexture::kTopDown_Orientation == orientation); |
| 212 | } |
| 213 | return true; |
| 214 | } |
| 215 | |
| 216 | /////////////////////////////////////////////////////////////////////////////// |
| 217 | |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 218 | static bool gPrintStartupSpew; |
| 219 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 220 | static bool fbo_test(const GrGLInterface* gl, int w, int h) { |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 221 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 222 | GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE0 + SPARE_TEX_UNIT)); |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 223 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 224 | GrGLuint testFBO; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 225 | GR_GL_CALL(gl, GenFramebuffers(1, &testFBO)); |
| 226 | GR_GL_CALL(gl, BindFramebuffer(GR_GL_FRAMEBUFFER, testFBO)); |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 227 | GrGLuint testRTTex; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 228 | GR_GL_CALL(gl, GenTextures(1, &testRTTex)); |
| 229 | GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, testRTTex)); |
bsalomon@google.com | 2fbc7fa | 2011-01-05 16:34:41 +0000 | [diff] [blame] | 230 | // some implementations require texture to be mip-map complete before |
| 231 | // FBO with level 0 bound as color attachment will be framebuffer complete. |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 232 | GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 233 | GR_GL_TEXTURE_MIN_FILTER, |
| 234 | GR_GL_NEAREST)); |
| 235 | GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RGBA, w, h, |
| 236 | 0, GR_GL_RGBA, GR_GL_UNSIGNED_BYTE, NULL)); |
| 237 | GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, 0)); |
| 238 | GR_GL_CALL(gl, FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
| 239 | GR_GL_COLOR_ATTACHMENT0, |
| 240 | GR_GL_TEXTURE_2D, testRTTex, 0)); |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 241 | GrGLenum status; |
| 242 | GR_GL_CALL_RET(gl, status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 243 | GR_GL_CALL(gl, DeleteFramebuffers(1, &testFBO)); |
| 244 | GR_GL_CALL(gl, DeleteTextures(1, &testRTTex)); |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 245 | |
bsalomon@google.com | c312bf9 | 2011-03-21 21:10:33 +0000 | [diff] [blame] | 246 | return status == GR_GL_FRAMEBUFFER_COMPLETE; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 247 | } |
| 248 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 249 | GrGpuGL::GrGpuGL(const GrGLInterface* gl, GrGLBinding glBinding) { |
tomhudson@google.com | 747bf29 | 2011-06-14 18:16:52 +0000 | [diff] [blame] | 250 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 251 | fPrintedCaps = false; |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 252 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 253 | gl->ref(); |
| 254 | fGL = gl; |
| 255 | fGLBinding = glBinding; |
| 256 | switch (glBinding) { |
| 257 | case kDesktop_GrGLBinding: |
| 258 | GrAssert(gl->supportsDesktop()); |
| 259 | break; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 260 | case kES2_GrGLBinding: |
| 261 | GrAssert(gl->supportsES2()); |
| 262 | break; |
| 263 | default: |
| 264 | GrCrash("Expect exactly one valid GL binding bit to be in use."); |
reed@google.com | eeeb5a0 | 2010-12-23 15:12:59 +0000 | [diff] [blame] | 265 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 266 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 267 | GrGLClearErr(fGL); |
| 268 | |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 269 | const GrGLubyte* ext; |
| 270 | GL_CALL_RET(ext, GetString(GR_GL_EXTENSIONS)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 271 | if (gPrintStartupSpew) { |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 272 | const GrGLubyte* vendor; |
| 273 | const GrGLubyte* renderer; |
| 274 | const GrGLubyte* version; |
| 275 | GL_CALL_RET(vendor, GetString(GR_GL_VENDOR)); |
| 276 | GL_CALL_RET(renderer, GetString(GR_GL_RENDERER)); |
| 277 | GL_CALL_RET(version, GetString(GR_GL_VERSION)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 278 | GrPrintf("------------------------- create GrGpuGL %p --------------\n", |
| 279 | this); |
| 280 | GrPrintf("------ VENDOR %s\n", vendor); |
| 281 | GrPrintf("------ RENDERER %s\n", renderer); |
| 282 | GrPrintf("------ VERSION %s\n", version); |
| 283 | GrPrintf("------ EXTENSIONS\n %s \n", ext); |
| 284 | } |
| 285 | |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 286 | fGLVersion = GrGLGetVersion(gl); |
| 287 | GrAssert(0 != fGLVersion); |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 288 | fExtensionString = (const char*) ext; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 289 | |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 290 | this->resetDirtyFlags(); |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 291 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 292 | this->initCaps(); |
tomhudson@google.com | 747bf29 | 2011-06-14 18:16:52 +0000 | [diff] [blame] | 293 | |
bsalomon@google.com | fe67652 | 2011-06-17 18:12:21 +0000 | [diff] [blame] | 294 | fLastSuccessfulStencilFmtIdx = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | GrGpuGL::~GrGpuGL() { |
bsalomon@google.com | 4a018bb | 2011-10-28 19:50:21 +0000 | [diff] [blame] | 298 | // This must be called by before the GrDrawTarget destructor |
| 299 | this->releaseGeometry(); |
bsalomon@google.com | 15b11df | 2011-09-16 21:18:29 +0000 | [diff] [blame] | 300 | // This subclass must do this before the base class destructor runs |
| 301 | // since we will unref the GrGLInterface. |
| 302 | this->releaseResources(); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 303 | fGL->unref(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 304 | } |
| 305 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 306 | /////////////////////////////////////////////////////////////////////////////// |
| 307 | |
| 308 | static const GrGLuint kUnknownBitCount = ~0; |
| 309 | |
| 310 | void GrGpuGL::initCaps() { |
| 311 | GrGLint maxTextureUnits; |
| 312 | // check FS and fixed-function texture unit limits |
| 313 | // we only use textures in the fragment stage currently. |
| 314 | // checks are > to make sure we have a spare unit. |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 315 | GR_GL_GetIntegerv(fGL, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits); |
| 316 | GrAssert(maxTextureUnits > GrDrawState::kNumStages); |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 317 | if (kES2_GrGLBinding != this->glBinding()) { |
| 318 | GR_GL_GetIntegerv(fGL, GR_GL_MAX_TEXTURE_UNITS, &maxTextureUnits); |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 319 | GrAssert(maxTextureUnits > GrDrawState::kNumStages); |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 320 | } |
| 321 | if (kES2_GrGLBinding == this->glBinding()) { |
| 322 | GR_GL_GetIntegerv(fGL, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS, |
| 323 | &fGLCaps.fMaxFragmentUniformVectors); |
| 324 | } else if (kDesktop_GrGLBinding != this->glBinding()) { |
| 325 | GrGLint max; |
| 326 | GR_GL_GetIntegerv(fGL, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max); |
| 327 | fGLCaps.fMaxFragmentUniformVectors = max / 4; |
| 328 | } else { |
| 329 | fGLCaps.fMaxFragmentUniformVectors = 16; |
| 330 | } |
| 331 | |
| 332 | GrGLint numFormats; |
| 333 | GR_GL_GetIntegerv(fGL, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats); |
| 334 | SkAutoSTMalloc<10, GrGLint> formats(numFormats); |
| 335 | GR_GL_GetIntegerv(fGL, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats); |
| 336 | for (int i = 0; i < numFormats; ++i) { |
| 337 | if (formats[i] == GR_GL_PALETTE8_RGBA8) { |
| 338 | fCaps.f8BitPaletteSupport = true; |
| 339 | break; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | if (kDesktop_GrGLBinding == this->glBinding()) { |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 344 | // we could also look for GL_ATI_separate_stencil extension or |
| 345 | // GL_EXT_stencil_two_side but they use different function signatures |
| 346 | // than GL2.0+ (and than each other). |
| 347 | fCaps.fTwoSidedStencilSupport = (fGLVersion >= GR_GL_VER(2,0)); |
| 348 | // supported on GL 1.4 and higher or by extension |
| 349 | fCaps.fStencilWrapOpsSupport = (fGLVersion >= GR_GL_VER(1,4)) || |
| 350 | this->hasExtension("GL_EXT_stencil_wrap"); |
| 351 | } else { |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 352 | // ES 2 has two sided stencil and stencil wrap |
| 353 | fCaps.fTwoSidedStencilSupport = true; |
| 354 | fCaps.fStencilWrapOpsSupport = true; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | if (kDesktop_GrGLBinding == this->glBinding()) { |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 358 | fGLCaps.fRGBA8RenderbufferSupport = true; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 359 | } else { |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 360 | fGLCaps.fRGBA8RenderbufferSupport = |
| 361 | this->hasExtension("GL_OES_rgb8_rgba8") || |
| 362 | this->hasExtension("GL_ARM_rgba8"); |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 366 | if (kDesktop_GrGLBinding == this->glBinding()) { |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 367 | fGLCaps.fBGRAFormatSupport = this->glVersion() >= GR_GL_VER(1,2) || |
| 368 | this->hasExtension("GL_EXT_bgra"); |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 369 | } else { |
| 370 | bool hasBGRAExt = false; |
| 371 | if (this->hasExtension("GL_APPLE_texture_format_BGRA8888")) { |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 372 | fGLCaps.fBGRAFormatSupport = true; |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 373 | } else if (this->hasExtension("GL_EXT_texture_format_BGRA8888")) { |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 374 | fGLCaps.fBGRAFormatSupport = true; |
| 375 | fGLCaps.fBGRAIsInternalFormat = true; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 376 | } |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 377 | GrAssert(fGLCaps.fBGRAFormatSupport || |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 378 | kSkia8888_PM_GrPixelConfig != kBGRA_8888_PM_GrPixelConfig); |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | if (kDesktop_GrGLBinding == this->glBinding()) { |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 382 | fGLCaps.fTextureSwizzleSupport = this->glVersion() >= GR_GL_VER(3,3) || |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 383 | this->hasExtension("GL_ARB_texture_swizzle"); |
| 384 | } else { |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 385 | fGLCaps.fTextureSwizzleSupport = false; |
| 386 | } |
| 387 | |
| 388 | if (kDesktop_GrGLBinding == this->glBinding()) { |
| 389 | fGLCaps.fUnpackRowLengthSupport = true; |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 390 | fGLCaps.fUnpackFlipYSupport = false; |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 391 | fGLCaps.fPackRowLengthSupport = true; |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 392 | fGLCaps.fPackFlipYSupport = false; |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 393 | } else { |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 394 | fGLCaps.fUnpackRowLengthSupport =this->hasExtension("GL_EXT_unpack_subimage"); |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 395 | fGLCaps.fUnpackFlipYSupport = this->hasExtension("GL_CHROMIUM_flipy"); |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 396 | // no extension for pack row length |
| 397 | fGLCaps.fPackRowLengthSupport = false; |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 398 | fGLCaps.fPackFlipYSupport = |
| 399 | this->hasExtension("GL_ANGLE_pack_reverse_row_order"); |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | if (kDesktop_GrGLBinding == this->glBinding()) { |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 403 | fCaps.fBufferLockSupport = true; // we require VBO support and the desktop VBO |
| 404 | // extension includes glMapBuffer. |
| 405 | } else { |
| 406 | fCaps.fBufferLockSupport = this->hasExtension("GL_OES_mapbuffer"); |
| 407 | } |
| 408 | |
| 409 | if (kDesktop_GrGLBinding == this->glBinding()) { |
| 410 | if (fGLVersion >= GR_GL_VER(2,0) || |
| 411 | this->hasExtension("GL_ARB_texture_non_power_of_two")) { |
| 412 | fCaps.fNPOTTextureTileSupport = true; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 413 | } else { |
| 414 | fCaps.fNPOTTextureTileSupport = false; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 415 | } |
| 416 | } else { |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 417 | // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 418 | fCaps.fNPOTTextureTileSupport = this->hasExtension("GL_OES_texture_npot"); |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 419 | } |
| 420 | |
bsalomon@google.com | 07dd2bf | 2011-12-09 19:40:36 +0000 | [diff] [blame] | 421 | fGLCaps.fTextureUsageSupport = (kES2_GrGLBinding == this->glBinding()) && |
| 422 | this->hasExtension("GL_ANGLE_texture_usage"); |
| 423 | |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 424 | // Tex storage is in desktop 4.2 and can be an extension to desktop or ES. |
| 425 | fGLCaps.fTexStorageSupport = (kDesktop_GrGLBinding == this->glBinding() && |
| 426 | fGLVersion >= GR_GL_VER(4,2)) || |
| 427 | this->hasExtension("GL_ARB_texture_storage") || |
| 428 | this->hasExtension("GL_EXT_texture_storage"); |
| 429 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 430 | fCaps.fHWAALineSupport = (kDesktop_GrGLBinding == this->glBinding()); |
| 431 | |
| 432 | //////////////////////////////////////////////////////////////////////////// |
| 433 | // Experiments to determine limitations that can't be queried. |
| 434 | // TODO: Make these a preprocess that generate some compile time constants. |
| 435 | // TODO: probe once at startup, rather than once per context creation. |
| 436 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 437 | GR_GL_GetIntegerv(fGL, GR_GL_MAX_TEXTURE_SIZE, &fCaps.fMaxTextureSize); |
| 438 | GR_GL_GetIntegerv(fGL, GR_GL_MAX_RENDERBUFFER_SIZE, &fCaps.fMaxRenderTargetSize); |
| 439 | // Our render targets are always created with textures as the color |
| 440 | // attachment, hence this min: |
| 441 | fCaps.fMaxRenderTargetSize = GrMin(fCaps.fMaxTextureSize, fCaps.fMaxRenderTargetSize); |
| 442 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 443 | this->initFSAASupport(); |
| 444 | this->initStencilFormats(); |
| 445 | } |
| 446 | |
| 447 | void GrGpuGL::initFSAASupport() { |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 448 | |
| 449 | fGLCaps.fMSFBOType = GLCaps::kNone_MSFBO; |
| 450 | if (kDesktop_GrGLBinding != this->glBinding()) { |
| 451 | if (this->hasExtension("GL_CHROMIUM_framebuffer_multisample")) { |
| 452 | // chrome's extension is equivalent to the EXT msaa |
| 453 | // and fbo_blit extensions. |
| 454 | fGLCaps.fMSFBOType = GLCaps::kDesktopEXT_MSFBO; |
| 455 | } else if (this->hasExtension("GL_APPLE_framebuffer_multisample")) { |
| 456 | fGLCaps.fMSFBOType = GLCaps::kAppleES_MSFBO; |
| 457 | } |
| 458 | } else { |
| 459 | if ((fGLVersion >= GR_GL_VER(3,0)) || this->hasExtension("GL_ARB_framebuffer_object")) { |
| 460 | fGLCaps.fMSFBOType = GLCaps::kDesktopARB_MSFBO; |
| 461 | } else if (this->hasExtension("GL_EXT_framebuffer_multisample") && |
| 462 | this->hasExtension("GL_EXT_framebuffer_blit")) { |
| 463 | fGLCaps.fMSFBOType = GLCaps::kDesktopEXT_MSFBO; |
| 464 | } |
| 465 | } |
| 466 | |
bsalomon@google.com | 78d6cf9 | 2012-01-30 18:09:31 +0000 | [diff] [blame] | 467 | fCaps.fFSAASupport = GLCaps::kNone_MSFBO != fGLCaps.fMSFBOType; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | void GrGpuGL::initStencilFormats() { |
| 471 | |
| 472 | // Build up list of legal stencil formats (though perhaps not supported on |
| 473 | // the particular gpu/driver) from most preferred to least. |
| 474 | |
| 475 | // these consts are in order of most preferred to least preferred |
| 476 | // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8 |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame^] | 477 | |
| 478 | // Omitting fVerifiedColorConfigs from initializer list should init to 0. |
| 479 | static const GLCaps::StencilFormat |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 480 | // internal Format stencil bits total bits packed? |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame^] | 481 | gS8 = {{GR_GL_STENCIL_INDEX8, 8, 8, false}, {0U}}, |
| 482 | gS16 = {{GR_GL_STENCIL_INDEX16, 16, 16, false}, {0U}}, |
| 483 | gD24S8 = {{GR_GL_DEPTH24_STENCIL8, 8, 32, true }, {0U}}, |
| 484 | gS4 = {{GR_GL_STENCIL_INDEX4, 4, 4, false}, {0U}}, |
| 485 | gS = {{GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false}, {0U}}, |
| 486 | gDS = {{GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true }, {0U}}; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 487 | |
| 488 | if (kDesktop_GrGLBinding == this->glBinding()) { |
| 489 | bool supportsPackedDS = fGLVersion >= GR_GL_VER(3,0) || |
| 490 | this->hasExtension("GL_EXT_packed_depth_stencil") || |
| 491 | this->hasExtension("GL_ARB_framebuffer_object"); |
| 492 | |
| 493 | // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we |
| 494 | // require FBO support we can expect these are legal formats and don't |
| 495 | // check. These also all support the unsized GL_STENCIL_INDEX. |
| 496 | fGLCaps.fStencilFormats.push_back() = gS8; |
| 497 | fGLCaps.fStencilFormats.push_back() = gS16; |
| 498 | if (supportsPackedDS) { |
| 499 | fGLCaps.fStencilFormats.push_back() = gD24S8; |
| 500 | } |
| 501 | fGLCaps.fStencilFormats.push_back() = gS4; |
| 502 | if (supportsPackedDS) { |
| 503 | fGLCaps.fStencilFormats.push_back() = gDS; |
| 504 | } |
| 505 | } else { |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 506 | // ES2 has STENCIL_INDEX8 without extensions but requires extensions |
| 507 | // for other formats. |
| 508 | // ES doesn't support using the unsized format. |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 509 | |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 510 | fGLCaps.fStencilFormats.push_back() = gS8; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 511 | //fStencilFormats.push_back() = gS16; |
| 512 | if (this->hasExtension("GL_OES_packed_depth_stencil")) { |
| 513 | fGLCaps.fStencilFormats.push_back() = gD24S8; |
| 514 | } |
| 515 | if (this->hasExtension("GL_OES_stencil4")) { |
| 516 | fGLCaps.fStencilFormats.push_back() = gS4; |
| 517 | } |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 518 | } |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame^] | 519 | #if GR_DEBUG |
| 520 | // ensure that initially all color / stencil format combos have unverified |
| 521 | // fbo status. |
| 522 | for (int i = 0; i < fGLCaps.fStencilFormats.count(); ++i) { |
| 523 | int numU32 = |
| 524 | GR_ARRAY_COUNT(fGLCaps.fStencilFormats[i].fVerifiedColorConfigs); |
| 525 | for (int j = 0; j < numU32; ++j) { |
| 526 | GrAssert(0 == fGLCaps.fStencilFormats[i].fVerifiedColorConfigs[j]); |
| 527 | } |
| 528 | } |
| 529 | #endif |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 530 | } |
| 531 | |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 532 | GrPixelConfig GrGpuGL::preferredReadPixelsConfig(GrPixelConfig config) const { |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 533 | if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && GrPixelConfigIsRGBA8888(config)) { |
| 534 | return GrPixelConfigSwapRAndB(config); |
| 535 | } else { |
| 536 | return config; |
| 537 | } |
| 538 | } |
| 539 | |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 540 | GrPixelConfig GrGpuGL::preferredWritePixelsConfig(GrPixelConfig config) const { |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 541 | if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && GrPixelConfigIsRGBA8888(config)) { |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 542 | return GrPixelConfigSwapRAndB(config); |
| 543 | } else { |
| 544 | return config; |
| 545 | } |
| 546 | } |
| 547 | |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 548 | bool GrGpuGL::fullReadPixelsIsFasterThanPartial() const { |
| 549 | return SkToBool(GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL); |
| 550 | } |
| 551 | |
bsalomon@google.com | 1bf1c21 | 2011-11-05 12:18:58 +0000 | [diff] [blame] | 552 | void GrGpuGL::onResetContext() { |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 553 | if (gPrintStartupSpew && !fPrintedCaps) { |
| 554 | fPrintedCaps = true; |
| 555 | this->getCaps().print(); |
| 556 | fGLCaps.print(); |
| 557 | } |
| 558 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 559 | // We detect cases when blending is effectively off |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 560 | fHWBlendDisabled = false; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 561 | GL_CALL(Enable(GR_GL_BLEND)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 562 | |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 563 | // we don't use the zb at all |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 564 | GL_CALL(Disable(GR_GL_DEPTH_TEST)); |
| 565 | GL_CALL(DepthMask(GR_GL_FALSE)); |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 566 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 567 | GL_CALL(Disable(GR_GL_CULL_FACE)); |
| 568 | GL_CALL(FrontFace(GR_GL_CCW)); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 569 | fHWDrawState.setDrawFace(GrDrawState::kBoth_DrawFace); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 570 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 571 | GL_CALL(Disable(GR_GL_DITHER)); |
| 572 | if (kDesktop_GrGLBinding == this->glBinding()) { |
| 573 | GL_CALL(Disable(GR_GL_LINE_SMOOTH)); |
| 574 | GL_CALL(Disable(GR_GL_POINT_SMOOTH)); |
| 575 | GL_CALL(Disable(GR_GL_MULTISAMPLE)); |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 576 | fHWAAState.fMSAAEnabled = false; |
| 577 | fHWAAState.fSmoothLineEnabled = false; |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 578 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 579 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 580 | GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE)); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 581 | fHWDrawState.resetStateFlags(); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 582 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 583 | // we only ever use lines in hairline mode |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 584 | GL_CALL(LineWidth(1)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 585 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 586 | // invalid |
| 587 | fActiveTextureUnitIdx = -1; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 588 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 589 | // illegal values |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 590 | fHWDrawState.setBlendFunc((GrBlendCoeff)0xFF, (GrBlendCoeff)0xFF); |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 591 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 592 | fHWDrawState.setBlendConstant(0x00000000); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 593 | GL_CALL(BlendColor(0,0,0,0)); |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 594 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 595 | fHWDrawState.setColor(GrColor_ILLEGAL); |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 596 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 597 | fHWDrawState.setViewMatrix(GrMatrix::InvalidMatrix()); |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 598 | |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 599 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 600 | fHWDrawState.setTexture(s, NULL); |
| 601 | fHWDrawState.sampler(s)->setRadial2Params(-GR_ScalarMax, |
| 602 | -GR_ScalarMax, |
| 603 | true); |
bsalomon@google.com | aa814fe | 2011-12-12 18:45:07 +0000 | [diff] [blame] | 604 | *fHWDrawState.sampler(s)->matrix() = GrMatrix::InvalidMatrix(); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 605 | fHWDrawState.sampler(s)->setConvolutionParams(0, NULL, NULL); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 606 | } |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 607 | |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 608 | fHWBounds.fScissorRect.invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 609 | fHWBounds.fScissorEnabled = false; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 610 | GL_CALL(Disable(GR_GL_SCISSOR_TEST)); |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 611 | fHWBounds.fViewportRect.invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 612 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 613 | fHWDrawState.stencil()->invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 614 | fHWStencilClip = false; |
bsalomon@google.com | dea2f8d | 2011-08-01 15:51:05 +0000 | [diff] [blame] | 615 | fClipInStencil = false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 616 | |
| 617 | fHWGeometryState.fIndexBuffer = NULL; |
| 618 | fHWGeometryState.fVertexBuffer = NULL; |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 619 | |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 620 | fHWGeometryState.fArrayPtrsDirty = true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 621 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 622 | GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE)); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 623 | fHWDrawState.setRenderTarget(NULL); |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 624 | |
| 625 | // we assume these values |
| 626 | if (this->glCaps().fUnpackRowLengthSupport) { |
| 627 | GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
| 628 | } |
| 629 | if (this->glCaps().fPackRowLengthSupport) { |
| 630 | GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); |
| 631 | } |
| 632 | if (this->glCaps().fUnpackFlipYSupport) { |
| 633 | GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); |
| 634 | } |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 635 | if (this->glCaps().fPackFlipYSupport) { |
| 636 | GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, GR_GL_FALSE)); |
| 637 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 638 | } |
| 639 | |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 640 | GrTexture* GrGpuGL::onCreatePlatformTexture(const GrPlatformTextureDesc& desc) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 641 | GrGLTexture::Desc glTexDesc; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 642 | if (!configToGLFormats(desc.fConfig, false, NULL, NULL, NULL)) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 643 | return NULL; |
| 644 | } |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 645 | |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 646 | glTexDesc.fWidth = desc.fWidth; |
| 647 | glTexDesc.fHeight = desc.fHeight; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 648 | glTexDesc.fConfig = desc.fConfig; |
| 649 | glTexDesc.fTextureID = static_cast<GrGLuint>(desc.fTextureHandle); |
| 650 | glTexDesc.fOwnsID = false; |
| 651 | glTexDesc.fOrientation = GrGLTexture::kBottomUp_Orientation; |
| 652 | |
| 653 | GrGLTexture* texture = NULL; |
| 654 | if (desc.fFlags & kRenderTarget_GrPlatformTextureFlag) { |
| 655 | GrGLRenderTarget::Desc glRTDesc; |
| 656 | glRTDesc.fRTFBOID = 0; |
| 657 | glRTDesc.fTexFBOID = 0; |
| 658 | glRTDesc.fMSColorRenderbufferID = 0; |
| 659 | glRTDesc.fOwnIDs = true; |
| 660 | glRTDesc.fConfig = desc.fConfig; |
| 661 | glRTDesc.fSampleCnt = desc.fSampleCnt; |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 662 | if (!this->createRenderTargetObjects(glTexDesc.fWidth, |
| 663 | glTexDesc.fHeight, |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 664 | glTexDesc.fTextureID, |
| 665 | &glRTDesc)) { |
| 666 | return NULL; |
| 667 | } |
| 668 | texture = new GrGLTexture(this, glTexDesc, glRTDesc); |
| 669 | } else { |
| 670 | texture = new GrGLTexture(this, glTexDesc); |
| 671 | } |
| 672 | if (NULL == texture) { |
| 673 | return NULL; |
| 674 | } |
| 675 | |
| 676 | this->setSpareTextureUnit(); |
| 677 | return texture; |
| 678 | } |
| 679 | |
| 680 | GrRenderTarget* GrGpuGL::onCreatePlatformRenderTarget(const GrPlatformRenderTargetDesc& desc) { |
| 681 | GrGLRenderTarget::Desc glDesc; |
| 682 | glDesc.fConfig = desc.fConfig; |
| 683 | glDesc.fRTFBOID = static_cast<GrGLuint>(desc.fRenderTargetHandle); |
| 684 | glDesc.fMSColorRenderbufferID = 0; |
| 685 | glDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; |
| 686 | glDesc.fSampleCnt = desc.fSampleCnt; |
| 687 | glDesc.fOwnIDs = false; |
| 688 | GrGLIRect viewport; |
| 689 | viewport.fLeft = 0; |
| 690 | viewport.fBottom = 0; |
| 691 | viewport.fWidth = desc.fWidth; |
| 692 | viewport.fHeight = desc.fHeight; |
| 693 | |
| 694 | GrRenderTarget* tgt = new GrGLRenderTarget(this, glDesc, viewport); |
| 695 | if (desc.fStencilBits) { |
| 696 | GrGLStencilBuffer::Format format; |
| 697 | format.fInternalFormat = GrGLStencilBuffer::kUnknownInternalFormat; |
| 698 | format.fPacked = false; |
| 699 | format.fStencilBits = desc.fStencilBits; |
| 700 | format.fTotalBits = desc.fStencilBits; |
| 701 | GrGLStencilBuffer* sb = new GrGLStencilBuffer(this, |
| 702 | 0, |
| 703 | desc.fWidth, |
| 704 | desc.fHeight, |
| 705 | desc.fSampleCnt, |
| 706 | format); |
| 707 | tgt->setStencilBuffer(sb); |
| 708 | sb->unref(); |
| 709 | } |
| 710 | return tgt; |
| 711 | } |
| 712 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 713 | //////////////////////////////////////////////////////////////////////////////// |
| 714 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 715 | void GrGpuGL::onWriteTexturePixels(GrTexture* texture, |
| 716 | int left, int top, int width, int height, |
| 717 | GrPixelConfig config, const void* buffer, |
| 718 | size_t rowBytes) { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 719 | if (NULL == buffer) { |
| 720 | return; |
| 721 | } |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 722 | GrGLTexture* glTex = static_cast<GrGLTexture*>(texture); |
| 723 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 724 | this->setSpareTextureUnit(); |
| 725 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTex->textureID())); |
| 726 | GrGLTexture::Desc desc; |
| 727 | desc.fConfig = glTex->config(); |
| 728 | desc.fWidth = glTex->width(); |
| 729 | desc.fHeight = glTex->height(); |
| 730 | desc.fOrientation = glTex->orientation(); |
| 731 | desc.fTextureID = glTex->textureID(); |
bsalomon@google.com | 9d6cfd8 | 2011-11-05 13:25:21 +0000 | [diff] [blame] | 732 | |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 733 | this->uploadTexData(desc, false, |
| 734 | left, top, width, height, |
| 735 | config, buffer, rowBytes); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 736 | } |
| 737 | |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 738 | namespace { |
| 739 | bool adjust_pixel_ops_params(int surfaceWidth, |
| 740 | int surfaceHeight, |
| 741 | size_t bpp, |
| 742 | int* left, int* top, int* width, int* height, |
| 743 | const void** data, |
| 744 | size_t* rowBytes) { |
| 745 | if (!*rowBytes) { |
| 746 | *rowBytes = *width * bpp; |
| 747 | } |
| 748 | |
| 749 | GrIRect subRect = GrIRect::MakeXYWH(*left, *top, *width, *height); |
| 750 | GrIRect bounds = GrIRect::MakeWH(surfaceWidth, surfaceHeight); |
| 751 | |
| 752 | if (!subRect.intersect(bounds)) { |
| 753 | return false; |
| 754 | } |
| 755 | *data = reinterpret_cast<const void*>(reinterpret_cast<intptr_t>(*data) + |
| 756 | (subRect.fTop - *top) * *rowBytes + (subRect.fLeft - *left) * bpp); |
| 757 | |
| 758 | *left = subRect.fLeft; |
| 759 | *top = subRect.fTop; |
| 760 | *width = subRect.width(); |
| 761 | *height = subRect.height(); |
| 762 | return true; |
| 763 | } |
| 764 | } |
| 765 | |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 766 | bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc, |
| 767 | bool isNewTexture, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 768 | int left, int top, int width, int height, |
| 769 | GrPixelConfig dataConfig, |
| 770 | const void* data, |
| 771 | size_t rowBytes) { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 772 | GrAssert(NULL != data || isNewTexture); |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 773 | |
| 774 | size_t bpp = GrBytesPerPixel(dataConfig); |
| 775 | if (!adjust_pixel_ops_params(desc.fWidth, desc.fHeight, bpp, &left, &top, |
| 776 | &width, &height, &data, &rowBytes)) { |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 777 | return false; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 778 | } |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 779 | size_t trimRowBytes = width * bpp; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 780 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 781 | // in case we need a temporary, trimmed copy of the src pixels |
| 782 | SkAutoSMalloc<128 * 128> tempStorage; |
| 783 | |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 784 | bool useTexStorage = isNewTexture && |
| 785 | this->glCaps().fTexStorageSupport; |
| 786 | if (useTexStorage) { |
| 787 | if (kDesktop_GrGLBinding == this->glBinding()) { |
| 788 | // 565 is not a sized internal format on desktop GL. So on desktop |
| 789 | // with 565 we always use an unsized internal format to let the |
| 790 | // system pick the best sized format to convert the 565 data to. |
| 791 | // Since glTexStorage only allows sized internal formats we will |
| 792 | // instead fallback to glTexImage2D. |
| 793 | useTexStorage = desc.fConfig != kRGB_565_GrPixelConfig; |
| 794 | } else { |
| 795 | // ES doesn't allow paletted textures to be used with tex storage |
| 796 | useTexStorage = desc.fConfig != kIndex_8_GrPixelConfig; |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | GrGLenum internalFormat; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 801 | GrGLenum externalFormat; |
| 802 | GrGLenum externalType; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 803 | // glTexStorage requires sized internal formats on both desktop and ES. ES |
| 804 | // glTexImage requires an unsized format. |
| 805 | if (!this->configToGLFormats(dataConfig, useTexStorage, &internalFormat, |
| 806 | &externalFormat, &externalType)) { |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 807 | return false; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 808 | } |
| 809 | |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 810 | if (!isNewTexture && GR_GL_PALETTE8_RGBA8 == internalFormat) { |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 811 | // paletted textures cannot be updated |
| 812 | return false; |
| 813 | } |
| 814 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 815 | /* |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 816 | * check whether to allocate a temporary buffer for flipping y or |
| 817 | * because our srcData has extra bytes past each row. If so, we need |
| 818 | * to trim those off here, since GL ES may not let us specify |
| 819 | * GL_UNPACK_ROW_LENGTH. |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 820 | */ |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 821 | bool restoreGLRowLength = false; |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 822 | bool swFlipY = false; |
| 823 | bool glFlipY = false; |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 824 | if (NULL != data) { |
| 825 | if (GrGLTexture::kBottomUp_Orientation == desc.fOrientation) { |
| 826 | if (this->glCaps().fUnpackFlipYSupport) { |
| 827 | glFlipY = true; |
| 828 | } else { |
| 829 | swFlipY = true; |
| 830 | } |
| 831 | } |
| 832 | if (this->glCaps().fUnpackRowLengthSupport && !swFlipY) { |
| 833 | // can't use this for flipping, only non-neg values allowed. :( |
| 834 | if (rowBytes != trimRowBytes) { |
| 835 | GrGLint rowLength = static_cast<GrGLint>(rowBytes / bpp); |
| 836 | GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, rowLength)); |
| 837 | restoreGLRowLength = true; |
| 838 | } |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 839 | } else { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 840 | if (trimRowBytes != rowBytes || swFlipY) { |
| 841 | // copy data into our new storage, skipping the trailing bytes |
| 842 | size_t trimSize = height * trimRowBytes; |
| 843 | const char* src = (const char*)data; |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 844 | if (swFlipY) { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 845 | src += (height - 1) * rowBytes; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 846 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 847 | char* dst = (char*)tempStorage.reset(trimSize); |
| 848 | for (int y = 0; y < height; y++) { |
| 849 | memcpy(dst, src, trimRowBytes); |
| 850 | if (swFlipY) { |
| 851 | src -= rowBytes; |
| 852 | } else { |
| 853 | src += rowBytes; |
| 854 | } |
| 855 | dst += trimRowBytes; |
| 856 | } |
| 857 | // now point data to our copied version |
| 858 | data = tempStorage.get(); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 859 | } |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 860 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 861 | if (glFlipY) { |
| 862 | GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE)); |
| 863 | } |
| 864 | GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, static_cast<GrGLint>(bpp))); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 865 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 866 | bool succeeded = true; |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 867 | if (isNewTexture && |
| 868 | 0 == left && 0 == top && |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 869 | desc.fWidth == width && desc.fHeight == height) { |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 870 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 871 | if (useTexStorage) { |
| 872 | // We never resize or change formats of textures. We don't use |
| 873 | // mipmaps currently. |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 874 | GL_ALLOC_CALL(this->glInterface(), |
| 875 | TexStorage2D(GR_GL_TEXTURE_2D, |
| 876 | 1, // levels |
| 877 | internalFormat, |
| 878 | desc.fWidth, desc.fHeight)); |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 879 | } else { |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 880 | if (GR_GL_PALETTE8_RGBA8 == internalFormat) { |
| 881 | GrGLsizei imageSize = desc.fWidth * desc.fHeight + |
| 882 | kGrColorTableSize; |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 883 | GL_ALLOC_CALL(this->glInterface(), |
| 884 | CompressedTexImage2D(GR_GL_TEXTURE_2D, |
| 885 | 0, // level |
| 886 | internalFormat, |
| 887 | desc.fWidth, desc.fHeight, |
| 888 | 0, // border |
| 889 | imageSize, |
| 890 | data)); |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 891 | } else { |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 892 | GL_ALLOC_CALL(this->glInterface(), |
| 893 | TexImage2D(GR_GL_TEXTURE_2D, |
| 894 | 0, // level |
| 895 | internalFormat, |
| 896 | desc.fWidth, desc.fHeight, |
| 897 | 0, // border |
| 898 | externalFormat, externalType, |
| 899 | data)); |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 900 | } |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 901 | } |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 902 | GrGLenum error = CHECK_ALLOC_ERROR(this->glInterface()); |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 903 | if (error != GR_GL_NO_ERROR) { |
| 904 | succeeded = false; |
| 905 | } else { |
| 906 | // if we have data and we used TexStorage to create the texture, we |
| 907 | // now upload with TexSubImage. |
| 908 | if (NULL != data && useTexStorage) { |
| 909 | GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, |
| 910 | 0, // level |
| 911 | left, top, |
| 912 | width, height, |
| 913 | externalFormat, externalType, |
| 914 | data)); |
| 915 | } |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 916 | } |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 917 | } else { |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 918 | if (swFlipY || glFlipY) { |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 919 | top = desc.fHeight - (top + height); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 920 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 921 | GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, |
| 922 | 0, // level |
| 923 | left, top, |
| 924 | width, height, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 925 | externalFormat, externalType, data)); |
| 926 | } |
| 927 | |
| 928 | if (restoreGLRowLength) { |
| 929 | GrAssert(this->glCaps().fUnpackRowLengthSupport); |
| 930 | GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 931 | } |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 932 | if (glFlipY) { |
| 933 | GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); |
| 934 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 935 | return succeeded; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 936 | } |
| 937 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 938 | bool GrGpuGL::createRenderTargetObjects(int width, int height, |
| 939 | GrGLuint texID, |
| 940 | GrGLRenderTarget::Desc* desc) { |
| 941 | desc->fMSColorRenderbufferID = 0; |
| 942 | desc->fRTFBOID = 0; |
| 943 | desc->fTexFBOID = 0; |
| 944 | desc->fOwnIDs = true; |
| 945 | |
| 946 | GrGLenum status; |
| 947 | GrGLint err; |
| 948 | |
bsalomon@google.com | ab15d61 | 2011-08-09 12:57:56 +0000 | [diff] [blame] | 949 | GrGLenum msColorFormat = 0; // suppress warning |
| 950 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 951 | GL_CALL(GenFramebuffers(1, &desc->fTexFBOID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 952 | if (!desc->fTexFBOID) { |
| 953 | goto FAILED; |
| 954 | } |
| 955 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 956 | |
| 957 | // If we are using multisampling we will create two FBOS. We render |
| 958 | // to one and then resolve to the texture bound to the other. |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 959 | if (desc->fSampleCnt > 0) { |
| 960 | if (GLCaps::kNone_MSFBO == fGLCaps.fMSFBOType) { |
| 961 | goto FAILED; |
| 962 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 963 | GL_CALL(GenFramebuffers(1, &desc->fRTFBOID)); |
| 964 | GL_CALL(GenRenderbuffers(1, &desc->fMSColorRenderbufferID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 965 | if (!desc->fRTFBOID || |
| 966 | !desc->fMSColorRenderbufferID || |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 967 | !this->configToGLFormats(desc->fConfig, |
| 968 | // GLES requires sized internal formats |
| 969 | kES2_GrGLBinding == this->glBinding(), |
| 970 | &msColorFormat, NULL, NULL)) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 971 | goto FAILED; |
| 972 | } |
| 973 | } else { |
| 974 | desc->fRTFBOID = desc->fTexFBOID; |
| 975 | } |
| 976 | |
bsalomon@google.com | 0e9b41a | 2012-01-04 22:11:43 +0000 | [diff] [blame] | 977 | // below here we may bind the FBO |
| 978 | fHWDrawState.setRenderTarget(NULL); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 979 | if (desc->fRTFBOID != desc->fTexFBOID) { |
| 980 | GrAssert(desc->fSampleCnt > 1); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 981 | GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 982 | desc->fMSColorRenderbufferID)); |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 983 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
| 984 | GL_ALLOC_CALL(this->glInterface(), |
| 985 | RenderbufferStorageMultisample(GR_GL_RENDERBUFFER, |
| 986 | desc->fSampleCnt, |
| 987 | msColorFormat, |
| 988 | width, height)); |
| 989 | err = CHECK_ALLOC_ERROR(this->glInterface()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 990 | if (err != GR_GL_NO_ERROR) { |
| 991 | goto FAILED; |
| 992 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 993 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fRTFBOID)); |
| 994 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 995 | GR_GL_COLOR_ATTACHMENT0, |
| 996 | GR_GL_RENDERBUFFER, |
| 997 | desc->fMSColorRenderbufferID)); |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame^] | 998 | if (!fGLCaps.isConfigVerifiedColorAttachment(desc->fConfig)) { |
| 999 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 1000 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
| 1001 | goto FAILED; |
| 1002 | } |
| 1003 | fGLCaps.markConfigAsValidColorAttachment(desc->fConfig); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1004 | } |
| 1005 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1006 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1007 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1008 | GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
| 1009 | GR_GL_COLOR_ATTACHMENT0, |
| 1010 | GR_GL_TEXTURE_2D, |
| 1011 | texID, 0)); |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame^] | 1012 | if (!fGLCaps.isConfigVerifiedColorAttachment(desc->fConfig)) { |
| 1013 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 1014 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
| 1015 | goto FAILED; |
| 1016 | } |
| 1017 | fGLCaps.markConfigAsValidColorAttachment(desc->fConfig); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | return true; |
| 1021 | |
| 1022 | FAILED: |
| 1023 | if (desc->fMSColorRenderbufferID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1024 | GL_CALL(DeleteRenderbuffers(1, &desc->fMSColorRenderbufferID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1025 | } |
| 1026 | if (desc->fRTFBOID != desc->fTexFBOID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1027 | GL_CALL(DeleteFramebuffers(1, &desc->fRTFBOID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1028 | } |
| 1029 | if (desc->fTexFBOID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1030 | GL_CALL(DeleteFramebuffers(1, &desc->fTexFBOID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1031 | } |
| 1032 | return false; |
| 1033 | } |
| 1034 | |
bsalomon@google.com | 3f3ffd6 | 2011-01-18 17:14:52 +0000 | [diff] [blame] | 1035 | // good to set a break-point here to know when createTexture fails |
| 1036 | static GrTexture* return_null_texture() { |
| 1037 | // GrAssert(!"null texture"); |
| 1038 | return NULL; |
| 1039 | } |
| 1040 | |
| 1041 | #if GR_DEBUG |
| 1042 | static size_t as_size_t(int x) { |
| 1043 | return x; |
| 1044 | } |
| 1045 | #endif |
| 1046 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 1047 | GrTexture* GrGpuGL::onCreateTexture(const GrTextureDesc& desc, |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 1048 | const void* srcData, |
| 1049 | size_t rowBytes) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1050 | |
| 1051 | #if GR_COLLECT_STATS |
| 1052 | ++fStats.fTextureCreateCnt; |
| 1053 | #endif |
reed@google.com | 1fcd51e | 2011-01-05 15:50:27 +0000 | [diff] [blame] | 1054 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 1055 | GrGLTexture::Desc glTexDesc; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 1056 | GrGLRenderTarget::Desc glRTDesc; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1057 | |
bsalomon@google.com | 78d6cf9 | 2012-01-30 18:09:31 +0000 | [diff] [blame] | 1058 | // Attempt to catch un- or wrongly initialized sample counts; |
| 1059 | GrAssert(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); |
| 1060 | |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 1061 | glTexDesc.fWidth = desc.fWidth; |
| 1062 | glTexDesc.fHeight = desc.fHeight; |
bsalomon@google.com | 78d6cf9 | 2012-01-30 18:09:31 +0000 | [diff] [blame] | 1063 | glTexDesc.fConfig = desc.fConfig; |
| 1064 | glTexDesc.fOwnsID = true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1065 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 1066 | glRTDesc.fMSColorRenderbufferID = 0; |
| 1067 | glRTDesc.fRTFBOID = 0; |
| 1068 | glRTDesc.fTexFBOID = 0; |
| 1069 | glRTDesc.fOwnIDs = true; |
bsalomon@google.com | 64c4fe4 | 2011-11-05 14:51:01 +0000 | [diff] [blame] | 1070 | glRTDesc.fConfig = glTexDesc.fConfig; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 1071 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 1072 | bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrTextureFlagBit); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1073 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 1074 | const Caps& caps = this->getCaps(); |
| 1075 | |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 1076 | // We keep GrRenderTargets in GL's normal orientation so that they |
| 1077 | // can be drawn to by the outside world without the client having |
| 1078 | // to render upside down. |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 1079 | glTexDesc.fOrientation = renderTarget ? GrGLTexture::kBottomUp_Orientation : |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1080 | GrGLTexture::kTopDown_Orientation; |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 1081 | |
bsalomon@google.com | 78d6cf9 | 2012-01-30 18:09:31 +0000 | [diff] [blame] | 1082 | glRTDesc.fSampleCnt = desc.fSampleCnt; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 1083 | if (GLCaps::kNone_MSFBO == fGLCaps.fMSFBOType && |
bsalomon@google.com | 78d6cf9 | 2012-01-30 18:09:31 +0000 | [diff] [blame] | 1084 | desc.fSampleCnt) { |
| 1085 | GrPrintf("MSAA RT requested but not supported on this platform."); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1088 | if (renderTarget) { |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 1089 | if (glTexDesc.fWidth > caps.fMaxRenderTargetSize || |
| 1090 | glTexDesc.fHeight > caps.fMaxRenderTargetSize) { |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 1091 | return return_null_texture(); |
| 1092 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1095 | GL_CALL(GenTextures(1, &glTexDesc.fTextureID)); |
bsalomon@google.com | 07dd2bf | 2011-12-09 19:40:36 +0000 | [diff] [blame] | 1096 | if (renderTarget && this->glCaps().fTextureUsageSupport) { |
| 1097 | // provides a hint about how this texture will be used |
| 1098 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1099 | GR_GL_TEXTURE_USAGE, |
| 1100 | GR_GL_FRAMEBUFFER_ATTACHMENT)); |
| 1101 | } |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 1102 | if (!glTexDesc.fTextureID) { |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 1103 | return return_null_texture(); |
| 1104 | } |
| 1105 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 1106 | this->setSpareTextureUnit(); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1107 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTexDesc.fTextureID)); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 1108 | |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1109 | // Some drivers like to know filter/wrap before seeing glTexImage2D. Some |
| 1110 | // drivers have a bug where an FBO won't be complete if it includes a |
| 1111 | // texture that is not mipmap complete (considering the filter in use). |
| 1112 | GrGLTexture::TexParams initialTexParams; |
| 1113 | // we only set a subset here so invalidate first |
| 1114 | initialTexParams.invalidate(); |
| 1115 | initialTexParams.fFilter = GR_GL_NEAREST; |
| 1116 | initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE; |
| 1117 | initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1118 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1119 | GR_GL_TEXTURE_MAG_FILTER, |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1120 | initialTexParams.fFilter)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1121 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1122 | GR_GL_TEXTURE_MIN_FILTER, |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1123 | initialTexParams.fFilter)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1124 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1125 | GR_GL_TEXTURE_WRAP_S, |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1126 | initialTexParams.fWrapS)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1127 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1128 | GR_GL_TEXTURE_WRAP_T, |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1129 | initialTexParams.fWrapT)); |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 1130 | if (!this->uploadTexData(glTexDesc, true, 0, 0, |
| 1131 | glTexDesc.fWidth, glTexDesc.fHeight, |
| 1132 | desc.fConfig, srcData, rowBytes)) { |
| 1133 | GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID)); |
| 1134 | return return_null_texture(); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 1135 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1136 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1137 | GrGLTexture* tex; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1138 | if (renderTarget) { |
| 1139 | #if GR_COLLECT_STATS |
| 1140 | ++fStats.fRenderTargetCreateCnt; |
| 1141 | #endif |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 1142 | if (!this->createRenderTargetObjects(glTexDesc.fWidth, |
| 1143 | glTexDesc.fHeight, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1144 | glTexDesc.fTextureID, |
| 1145 | &glRTDesc)) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1146 | GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1147 | return return_null_texture(); |
| 1148 | } |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 1149 | tex = new GrGLTexture(this, glTexDesc, glRTDesc); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1150 | } else { |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 1151 | tex = new GrGLTexture(this, glTexDesc); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1152 | } |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1153 | tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1154 | #ifdef TRACE_TEXTURE_CREATION |
bsalomon@google.com | 64c4fe4 | 2011-11-05 14:51:01 +0000 | [diff] [blame] | 1155 | GrPrintf("--- new texture [%d] size=(%d %d) config=%d\n", |
| 1156 | glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1157 | #endif |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1158 | return tex; |
| 1159 | } |
| 1160 | |
| 1161 | namespace { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1162 | void inline get_stencil_rb_sizes(const GrGLInterface* gl, |
| 1163 | GrGLuint rb, |
| 1164 | GrGLStencilBuffer::Format* format) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1165 | // we shouldn't ever know one size and not the other |
| 1166 | GrAssert((kUnknownBitCount == format->fStencilBits) == |
| 1167 | (kUnknownBitCount == format->fTotalBits)); |
| 1168 | if (kUnknownBitCount == format->fStencilBits) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1169 | GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1170 | GR_GL_RENDERBUFFER_STENCIL_SIZE, |
| 1171 | (GrGLint*)&format->fStencilBits); |
| 1172 | if (format->fPacked) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1173 | GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1174 | GR_GL_RENDERBUFFER_DEPTH_SIZE, |
| 1175 | (GrGLint*)&format->fTotalBits); |
| 1176 | format->fTotalBits += format->fStencilBits; |
| 1177 | } else { |
| 1178 | format->fTotalBits = format->fStencilBits; |
| 1179 | } |
| 1180 | } |
| 1181 | } |
| 1182 | } |
| 1183 | |
| 1184 | bool GrGpuGL::createStencilBufferForRenderTarget(GrRenderTarget* rt, |
| 1185 | int width, int height) { |
| 1186 | |
| 1187 | // All internally created RTs are also textures. We don't create |
| 1188 | // SBs for a client's standalone RT (that is RT that isnt also a texture). |
| 1189 | GrAssert(rt->asTexture()); |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 1190 | GrAssert(width >= rt->width()); |
| 1191 | GrAssert(height >= rt->height()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1192 | |
| 1193 | int samples = rt->numSamples(); |
| 1194 | GrGLuint sbID; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1195 | GL_CALL(GenRenderbuffers(1, &sbID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1196 | if (!sbID) { |
| 1197 | return false; |
| 1198 | } |
| 1199 | |
| 1200 | GrGLStencilBuffer* sb = NULL; |
| 1201 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 1202 | int stencilFmtCnt = fGLCaps.fStencilFormats.count(); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1203 | for (int i = 0; i < stencilFmtCnt; ++i) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1204 | GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1205 | // we start with the last stencil format that succeeded in hopes |
| 1206 | // that we won't go through this loop more than once after the |
| 1207 | // first (painful) stencil creation. |
| 1208 | int sIdx = (i + fLastSuccessfulStencilFmtIdx) % stencilFmtCnt; |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame^] | 1209 | const GLCaps::StencilFormat& sFmt = fGLCaps.fStencilFormats[sIdx]; |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 1210 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 1211 | // 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] | 1212 | // version on a GL that doesn't have an MSAA extension. |
| 1213 | if (samples > 1) { |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 1214 | GL_ALLOC_CALL(this->glInterface(), |
| 1215 | RenderbufferStorageMultisample(GR_GL_RENDERBUFFER, |
| 1216 | samples, |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame^] | 1217 | sFmt.fFormat.fInternalFormat, |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 1218 | width, height)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1219 | } else { |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 1220 | GL_ALLOC_CALL(this->glInterface(), |
| 1221 | RenderbufferStorage(GR_GL_RENDERBUFFER, |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame^] | 1222 | sFmt.fFormat.fInternalFormat, |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 1223 | width, height)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1224 | } |
| 1225 | |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 1226 | GrGLenum err = CHECK_ALLOC_ERROR(this->glInterface()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1227 | if (err == GR_GL_NO_ERROR) { |
| 1228 | // After sized formats we attempt an unsized format and take whatever |
| 1229 | // sizes GL gives us. In that case we query for the size. |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame^] | 1230 | GrGLStencilBuffer::Format format = sFmt.fFormat; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1231 | get_stencil_rb_sizes(this->glInterface(), sbID, &format); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 1232 | sb = new GrGLStencilBuffer(this, sbID, width, height, |
| 1233 | samples, format); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1234 | if (this->attachStencilBufferToRenderTarget(sb, rt)) { |
| 1235 | fLastSuccessfulStencilFmtIdx = sIdx; |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 1236 | rt->setStencilBuffer(sb); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1237 | sb->unref(); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1238 | return true; |
| 1239 | } |
| 1240 | sb->abandon(); // otherwise we lose sbID |
| 1241 | sb->unref(); |
| 1242 | } |
| 1243 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1244 | GL_CALL(DeleteRenderbuffers(1, &sbID)); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 1245 | return false; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | bool GrGpuGL::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, |
| 1249 | GrRenderTarget* rt) { |
| 1250 | GrGLRenderTarget* glrt = (GrGLRenderTarget*) rt; |
| 1251 | |
| 1252 | GrGLuint fbo = glrt->renderFBOID(); |
| 1253 | |
| 1254 | if (NULL == sb) { |
| 1255 | if (NULL != rt->getStencilBuffer()) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1256 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1257 | GR_GL_STENCIL_ATTACHMENT, |
| 1258 | GR_GL_RENDERBUFFER, 0)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1259 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1260 | GR_GL_DEPTH_ATTACHMENT, |
| 1261 | GR_GL_RENDERBUFFER, 0)); |
| 1262 | #if GR_DEBUG |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 1263 | GrGLenum status; |
| 1264 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1265 | GrAssert(GR_GL_FRAMEBUFFER_COMPLETE == status); |
| 1266 | #endif |
| 1267 | } |
| 1268 | return true; |
| 1269 | } else { |
| 1270 | GrGLStencilBuffer* glsb = (GrGLStencilBuffer*) sb; |
| 1271 | GrGLuint rb = glsb->renderbufferID(); |
| 1272 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1273 | fHWDrawState.setRenderTarget(NULL); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1274 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo)); |
| 1275 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1276 | GR_GL_STENCIL_ATTACHMENT, |
| 1277 | GR_GL_RENDERBUFFER, rb)); |
| 1278 | if (glsb->format().fPacked) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1279 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1280 | GR_GL_DEPTH_ATTACHMENT, |
| 1281 | GR_GL_RENDERBUFFER, rb)); |
| 1282 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1283 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1284 | GR_GL_DEPTH_ATTACHMENT, |
| 1285 | GR_GL_RENDERBUFFER, 0)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1286 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1287 | |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 1288 | GrGLenum status; |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame^] | 1289 | if (!fGLCaps.isColorConfigAndStencilFormatVerified(rt->config(), |
| 1290 | glsb->format())) { |
| 1291 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 1292 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1293 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame^] | 1294 | GR_GL_STENCIL_ATTACHMENT, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1295 | GR_GL_RENDERBUFFER, 0)); |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame^] | 1296 | if (glsb->format().fPacked) { |
| 1297 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 1298 | GR_GL_DEPTH_ATTACHMENT, |
| 1299 | GR_GL_RENDERBUFFER, 0)); |
| 1300 | } |
| 1301 | return false; |
| 1302 | } else { |
| 1303 | fGLCaps.markColorConfigAndStencilFormatAsVerified( |
| 1304 | rt->config(), |
| 1305 | glsb->format()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1306 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1307 | } |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame^] | 1308 | return true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1309 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 1312 | //////////////////////////////////////////////////////////////////////////////// |
| 1313 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 1314 | GrVertexBuffer* GrGpuGL::onCreateVertexBuffer(uint32_t size, bool dynamic) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1315 | GrGLuint id; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1316 | GL_CALL(GenBuffers(1, &id)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1317 | if (id) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1318 | GL_CALL(BindBuffer(GR_GL_ARRAY_BUFFER, id)); |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 1319 | fHWGeometryState.fArrayPtrsDirty = true; |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 1320 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1321 | // make sure driver can allocate memory for this buffer |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 1322 | GL_ALLOC_CALL(this->glInterface(), |
| 1323 | BufferData(GR_GL_ARRAY_BUFFER, |
| 1324 | size, |
| 1325 | NULL, // data ptr |
| 1326 | dynamic ? GR_GL_DYNAMIC_DRAW : |
| 1327 | GR_GL_STATIC_DRAW)); |
| 1328 | if (CHECK_ALLOC_ERROR(this->glInterface()) != GR_GL_NO_ERROR) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1329 | GL_CALL(DeleteBuffers(1, &id)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1330 | // deleting bound buffer does implicit bind to 0 |
| 1331 | fHWGeometryState.fVertexBuffer = NULL; |
| 1332 | return NULL; |
| 1333 | } |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 1334 | GrGLVertexBuffer* vertexBuffer = new GrGLVertexBuffer(this, id, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1335 | size, dynamic); |
| 1336 | fHWGeometryState.fVertexBuffer = vertexBuffer; |
| 1337 | return vertexBuffer; |
| 1338 | } |
| 1339 | return NULL; |
| 1340 | } |
| 1341 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 1342 | GrIndexBuffer* GrGpuGL::onCreateIndexBuffer(uint32_t size, bool dynamic) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1343 | GrGLuint id; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1344 | GL_CALL(GenBuffers(1, &id)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1345 | if (id) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1346 | GL_CALL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, id)); |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 1347 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1348 | // make sure driver can allocate memory for this buffer |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 1349 | GL_ALLOC_CALL(this->glInterface(), |
| 1350 | BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, |
| 1351 | size, |
| 1352 | NULL, // data ptr |
| 1353 | dynamic ? GR_GL_DYNAMIC_DRAW : |
| 1354 | GR_GL_STATIC_DRAW)); |
| 1355 | if (CHECK_ALLOC_ERROR(this->glInterface()) != GR_GL_NO_ERROR) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1356 | GL_CALL(DeleteBuffers(1, &id)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1357 | // deleting bound buffer does implicit bind to 0 |
| 1358 | fHWGeometryState.fIndexBuffer = NULL; |
| 1359 | return NULL; |
| 1360 | } |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 1361 | GrIndexBuffer* indexBuffer = new GrGLIndexBuffer(this, id, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1362 | size, dynamic); |
| 1363 | fHWGeometryState.fIndexBuffer = indexBuffer; |
| 1364 | return indexBuffer; |
| 1365 | } |
| 1366 | return NULL; |
| 1367 | } |
| 1368 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1369 | void GrGpuGL::flushScissor(const GrIRect* rect) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1370 | const GrDrawState& drawState = this->getDrawState(); |
| 1371 | const GrGLRenderTarget* rt = |
| 1372 | static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget()); |
| 1373 | |
| 1374 | GrAssert(NULL != rt); |
| 1375 | const GrGLIRect& vp = rt->getViewport(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1376 | |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 1377 | GrGLIRect scissor; |
| 1378 | if (NULL != rect) { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1379 | scissor.setRelativeTo(vp, rect->fLeft, rect->fTop, |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 1380 | rect->width(), rect->height()); |
| 1381 | if (scissor.contains(vp)) { |
| 1382 | rect = NULL; |
| 1383 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | if (NULL != rect) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1387 | if (fHWBounds.fScissorRect != scissor) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1388 | scissor.pushToGLScissor(this->glInterface()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1389 | fHWBounds.fScissorRect = scissor; |
| 1390 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1391 | if (!fHWBounds.fScissorEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1392 | GL_CALL(Enable(GR_GL_SCISSOR_TEST)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1393 | fHWBounds.fScissorEnabled = true; |
| 1394 | } |
| 1395 | } else { |
| 1396 | if (fHWBounds.fScissorEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1397 | GL_CALL(Disable(GR_GL_SCISSOR_TEST)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1398 | fHWBounds.fScissorEnabled = false; |
| 1399 | } |
| 1400 | } |
| 1401 | } |
| 1402 | |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 1403 | void GrGpuGL::onClear(const GrIRect* rect, GrColor color) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1404 | const GrDrawState& drawState = this->getDrawState(); |
| 1405 | const GrRenderTarget* rt = drawState.getRenderTarget(); |
bsalomon@google.com | 0ba52fc | 2011-11-10 22:16:06 +0000 | [diff] [blame] | 1406 | // parent class should never let us get here with no RT |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1407 | GrAssert(NULL != rt); |
bsalomon@google.com | 0ba52fc | 2011-11-10 22:16:06 +0000 | [diff] [blame] | 1408 | |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1409 | GrIRect clippedRect; |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 1410 | if (NULL != rect) { |
| 1411 | // flushScissor expects rect to be clipped to the target. |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1412 | clippedRect = *rect; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1413 | GrIRect rtRect = SkIRect::MakeWH(rt->width(), rt->height()); |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1414 | if (clippedRect.intersect(rtRect)) { |
| 1415 | rect = &clippedRect; |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 1416 | } else { |
| 1417 | return; |
| 1418 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1419 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1420 | this->flushRenderTarget(rect); |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 1421 | this->flushScissor(rect); |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1422 | |
| 1423 | GrGLfloat r, g, b, a; |
| 1424 | static const GrGLfloat scale255 = 1.f / 255.f; |
| 1425 | a = GrColorUnpackA(color) * scale255; |
| 1426 | GrGLfloat scaleRGB = scale255; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1427 | if (GrPixelConfigIsUnpremultiplied(rt->config())) { |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1428 | scaleRGB *= a; |
| 1429 | } |
| 1430 | r = GrColorUnpackR(color) * scaleRGB; |
| 1431 | g = GrColorUnpackG(color) * scaleRGB; |
| 1432 | b = GrColorUnpackB(color) * scaleRGB; |
| 1433 | |
| 1434 | GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE)); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1435 | fHWDrawState.disableState(GrDrawState::kNoColorWrites_StateBit); |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1436 | GL_CALL(ClearColor(r, g, b, a)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1437 | GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
bsalomon@google.com | edc177d | 2011-08-05 15:46:40 +0000 | [diff] [blame] | 1440 | void GrGpuGL::clearStencil() { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1441 | if (NULL == this->getDrawState().getRenderTarget()) { |
bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 1442 | return; |
| 1443 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1444 | |
| 1445 | this->flushRenderTarget(&GrIRect::EmptyIRect()); |
| 1446 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1447 | if (fHWBounds.fScissorEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1448 | GL_CALL(Disable(GR_GL_SCISSOR_TEST)); |
bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 1449 | fHWBounds.fScissorEnabled = false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1450 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1451 | GL_CALL(StencilMask(0xffffffff)); |
| 1452 | GL_CALL(ClearStencil(0)); |
| 1453 | GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1454 | fHWDrawState.stencil()->invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1455 | } |
| 1456 | |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1457 | void GrGpuGL::clearStencilClip(const GrIRect& rect, bool insideClip) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1458 | const GrDrawState& drawState = this->getDrawState(); |
| 1459 | const GrRenderTarget* rt = drawState.getRenderTarget(); |
| 1460 | GrAssert(NULL != rt); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1461 | |
| 1462 | // this should only be called internally when we know we have a |
| 1463 | // stencil buffer. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1464 | GrAssert(NULL != rt->getStencilBuffer()); |
| 1465 | GrGLint stencilBitCount = rt->getStencilBuffer()->bits(); |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1466 | #if 0 |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1467 | GrAssert(stencilBitCount > 0); |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1468 | GrGLint clipStencilMask = (1 << (stencilBitCount - 1)); |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 1469 | #else |
| 1470 | // 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] | 1471 | // ANGLE a partial stencil mask will cause clears to be |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 1472 | // turned into draws. Our contract on GrDrawTarget says that |
| 1473 | // changing the clip between stencil passes may or may not |
| 1474 | // 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] | 1475 | static const GrGLint clipStencilMask = ~0; |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 1476 | #endif |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1477 | GrGLint value; |
| 1478 | if (insideClip) { |
| 1479 | value = (1 << (stencilBitCount - 1)); |
| 1480 | } else { |
| 1481 | value = 0; |
| 1482 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1483 | this->flushRenderTarget(&GrIRect::EmptyIRect()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1484 | this->flushScissor(&rect); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1485 | GL_CALL(StencilMask(clipStencilMask)); |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1486 | GL_CALL(ClearStencil(value)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1487 | GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1488 | fHWDrawState.stencil()->invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 1491 | void GrGpuGL::onForceRenderTargetFlush() { |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1492 | this->flushRenderTarget(&GrIRect::EmptyIRect()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1493 | } |
| 1494 | |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1495 | bool GrGpuGL::readPixelsWillPayForYFlip(GrRenderTarget* renderTarget, |
| 1496 | int left, int top, |
| 1497 | int width, int height, |
| 1498 | GrPixelConfig config, |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1499 | size_t rowBytes) const { |
| 1500 | // if GL can do the flip then we'll never pay for it. |
| 1501 | if (this->glCaps().fPackFlipYSupport) { |
| 1502 | return false; |
| 1503 | } |
| 1504 | |
| 1505 | // 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] | 1506 | // get the flip for free. Otherwise it costs. |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 1507 | if (this->glCaps().fPackRowLengthSupport) { |
| 1508 | return true; |
| 1509 | } |
| 1510 | // If we have to do memcpys to handle rowBytes then y-flip is free |
| 1511 | // Note the rowBytes might be tight to the passed in data, but if data |
| 1512 | // gets clipped in x to the target the rowBytes will no longer be tight. |
| 1513 | if (left >= 0 && (left + width) < renderTarget->width()) { |
| 1514 | return 0 == rowBytes || |
| 1515 | GrBytesPerPixel(config) * width == rowBytes; |
| 1516 | } else { |
| 1517 | return false; |
| 1518 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1521 | bool GrGpuGL::onReadPixels(GrRenderTarget* target, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1522 | int left, int top, |
| 1523 | int width, int height, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1524 | GrPixelConfig config, |
| 1525 | void* buffer, |
| 1526 | size_t rowBytes, |
| 1527 | bool invertY) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1528 | GrGLenum format; |
| 1529 | GrGLenum type; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 1530 | if (!this->configToGLFormats(config, false, NULL, &format, &type)) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1531 | return false; |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1532 | } |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 1533 | size_t bpp = GrBytesPerPixel(config); |
| 1534 | if (!adjust_pixel_ops_params(target->width(), target->height(), bpp, |
| 1535 | &left, &top, &width, &height, |
| 1536 | const_cast<const void**>(&buffer), |
| 1537 | &rowBytes)) { |
| 1538 | return false; |
| 1539 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1540 | |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1541 | // resolve the render target if necessary |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1542 | GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1543 | GrDrawState::AutoRenderTargetRestore artr; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1544 | switch (tgt->getResolveType()) { |
| 1545 | case GrGLRenderTarget::kCantResolve_ResolveType: |
| 1546 | return false; |
| 1547 | case GrGLRenderTarget::kAutoResolves_ResolveType: |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1548 | artr.set(this->drawState(), target); |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1549 | this->flushRenderTarget(&GrIRect::EmptyIRect()); |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1550 | break; |
| 1551 | case GrGLRenderTarget::kCanResolve_ResolveType: |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 1552 | this->onResolveRenderTarget(tgt); |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1553 | // we don't track the state of the READ FBO ID. |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1554 | GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, |
| 1555 | tgt->textureFBOID())); |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1556 | break; |
| 1557 | default: |
| 1558 | GrCrash("Unknown resolve type"); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1561 | const GrGLIRect& glvp = tgt->getViewport(); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1562 | |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 1563 | // the read rect is viewport-relative |
| 1564 | GrGLIRect readRect; |
| 1565 | readRect.setRelativeTo(glvp, left, top, width, height); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1566 | |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 1567 | size_t tightRowBytes = bpp * width; |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1568 | if (0 == rowBytes) { |
| 1569 | rowBytes = tightRowBytes; |
| 1570 | } |
| 1571 | size_t readDstRowBytes = tightRowBytes; |
| 1572 | void* readDst = buffer; |
| 1573 | |
| 1574 | // determine if GL can read using the passed rowBytes or if we need |
| 1575 | // a scratch buffer. |
| 1576 | SkAutoSMalloc<32 * sizeof(GrColor)> scratch; |
| 1577 | if (rowBytes != tightRowBytes) { |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 1578 | if (this->glCaps().fPackRowLengthSupport) { |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1579 | GrAssert(!(rowBytes % sizeof(GrColor))); |
| 1580 | GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, rowBytes / sizeof(GrColor))); |
| 1581 | readDstRowBytes = rowBytes; |
| 1582 | } else { |
| 1583 | scratch.reset(tightRowBytes * height); |
| 1584 | readDst = scratch.get(); |
| 1585 | } |
| 1586 | } |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1587 | if (!invertY && this->glCaps().fPackFlipYSupport) { |
| 1588 | GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 1)); |
| 1589 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1590 | GL_CALL(ReadPixels(readRect.fLeft, readRect.fBottom, |
| 1591 | readRect.fWidth, readRect.fHeight, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1592 | format, type, readDst)); |
| 1593 | if (readDstRowBytes != tightRowBytes) { |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 1594 | GrAssert(this->glCaps().fPackRowLengthSupport); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1595 | GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); |
| 1596 | } |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1597 | if (!invertY && this->glCaps().fPackFlipYSupport) { |
| 1598 | GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 0)); |
| 1599 | invertY = true; |
| 1600 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1601 | |
| 1602 | // 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] | 1603 | // API presents top-to-bottom. We must preserve the padding contents. Note |
| 1604 | // that the above readPixels did not overwrite the padding. |
| 1605 | if (readDst == buffer) { |
| 1606 | GrAssert(rowBytes == readDstRowBytes); |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1607 | if (!invertY) { |
| 1608 | scratch.reset(tightRowBytes); |
| 1609 | void* tmpRow = scratch.get(); |
| 1610 | // flip y in-place by rows |
| 1611 | const int halfY = height >> 1; |
| 1612 | char* top = reinterpret_cast<char*>(buffer); |
| 1613 | char* bottom = top + (height - 1) * rowBytes; |
| 1614 | for (int y = 0; y < halfY; y++) { |
| 1615 | memcpy(tmpRow, top, tightRowBytes); |
| 1616 | memcpy(top, bottom, tightRowBytes); |
| 1617 | memcpy(bottom, tmpRow, tightRowBytes); |
| 1618 | top += rowBytes; |
| 1619 | bottom -= rowBytes; |
| 1620 | } |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1621 | } |
| 1622 | } else { |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1623 | GrAssert(readDst != buffer); GrAssert(rowBytes != tightRowBytes); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1624 | // copy from readDst to buffer while flipping y |
| 1625 | const int halfY = height >> 1; |
| 1626 | const char* src = reinterpret_cast<const char*>(readDst); |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1627 | char* dst = reinterpret_cast<char*>(buffer); |
| 1628 | if (!invertY) { |
| 1629 | dst += (height-1) * rowBytes; |
| 1630 | } |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1631 | for (int y = 0; y < height; y++) { |
| 1632 | memcpy(dst, src, tightRowBytes); |
| 1633 | src += readDstRowBytes; |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1634 | if (invertY) { |
| 1635 | dst += rowBytes; |
| 1636 | } else { |
| 1637 | dst -= rowBytes; |
| 1638 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1639 | } |
| 1640 | } |
| 1641 | return true; |
| 1642 | } |
| 1643 | |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1644 | void GrGpuGL::flushRenderTarget(const GrIRect* bound) { |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1645 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1646 | GrGLRenderTarget* rt = |
| 1647 | static_cast<GrGLRenderTarget*>(this->drawState()->getRenderTarget()); |
| 1648 | GrAssert(NULL != rt); |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1649 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1650 | if (fHWDrawState.getRenderTarget() != rt) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1651 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID())); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1652 | #if GR_COLLECT_STATS |
| 1653 | ++fStats.fRenderTargetChngCnt; |
| 1654 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1655 | #if GR_DEBUG |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 1656 | GrGLenum status; |
| 1657 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
bsalomon@google.com | c312bf9 | 2011-03-21 21:10:33 +0000 | [diff] [blame] | 1658 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
reed@google.com | b9255d5 | 2011-06-13 18:54:59 +0000 | [diff] [blame] | 1659 | GrPrintf("GrGpuGL::flushRenderTarget glCheckFramebufferStatus %x\n", status); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1660 | } |
| 1661 | #endif |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 1662 | fDirtyFlags.fRenderTargetChanged = true; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1663 | fHWDrawState.setRenderTarget(rt); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1664 | const GrGLIRect& vp = rt->getViewport(); |
bsalomon@google.com | 649a862 | 2011-03-10 14:53:38 +0000 | [diff] [blame] | 1665 | if (fHWBounds.fViewportRect != vp) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1666 | vp.pushToGLViewport(this->glInterface()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1667 | fHWBounds.fViewportRect = vp; |
| 1668 | } |
| 1669 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1670 | if (NULL == bound || !bound->isEmpty()) { |
| 1671 | rt->flagAsNeedingResolve(bound); |
| 1672 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1675 | GrGLenum gPrimitiveType2GLMode[] = { |
| 1676 | GR_GL_TRIANGLES, |
| 1677 | GR_GL_TRIANGLE_STRIP, |
| 1678 | GR_GL_TRIANGLE_FAN, |
| 1679 | GR_GL_POINTS, |
| 1680 | GR_GL_LINES, |
| 1681 | GR_GL_LINE_STRIP |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1682 | }; |
| 1683 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1684 | #define SWAP_PER_DRAW 0 |
| 1685 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 1686 | #if SWAP_PER_DRAW |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1687 | #if GR_MAC_BUILD |
| 1688 | #include <AGL/agl.h> |
| 1689 | #elif GR_WIN32_BUILD |
| 1690 | void SwapBuf() { |
| 1691 | DWORD procID = GetCurrentProcessId(); |
| 1692 | HWND hwnd = GetTopWindow(GetDesktopWindow()); |
| 1693 | while(hwnd) { |
| 1694 | DWORD wndProcID = 0; |
| 1695 | GetWindowThreadProcessId(hwnd, &wndProcID); |
| 1696 | if(wndProcID == procID) { |
| 1697 | SwapBuffers(GetDC(hwnd)); |
| 1698 | } |
| 1699 | hwnd = GetNextWindow(hwnd, GW_HWNDNEXT); |
| 1700 | } |
| 1701 | } |
| 1702 | #endif |
| 1703 | #endif |
| 1704 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 1705 | void GrGpuGL::onGpuDrawIndexed(GrPrimitiveType type, |
| 1706 | uint32_t startVertex, |
| 1707 | uint32_t startIndex, |
| 1708 | uint32_t vertexCount, |
| 1709 | uint32_t indexCount) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1710 | GrAssert((size_t)type < GR_ARRAY_COUNT(gPrimitiveType2GLMode)); |
| 1711 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1712 | GrGLvoid* indices = (GrGLvoid*)(sizeof(uint16_t) * startIndex); |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 1713 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 1714 | GrAssert(NULL != fHWGeometryState.fIndexBuffer); |
| 1715 | GrAssert(NULL != fHWGeometryState.fVertexBuffer); |
| 1716 | |
| 1717 | // our setupGeometry better have adjusted this to zero since |
| 1718 | // DrawElements always draws from the begining of the arrays for idx 0. |
| 1719 | GrAssert(0 == startVertex); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1720 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1721 | GL_CALL(DrawElements(gPrimitiveType2GLMode[type], indexCount, |
| 1722 | GR_GL_UNSIGNED_SHORT, indices)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1723 | #if SWAP_PER_DRAW |
| 1724 | glFlush(); |
| 1725 | #if GR_MAC_BUILD |
| 1726 | aglSwapBuffers(aglGetCurrentContext()); |
| 1727 | int set_a_break_pt_here = 9; |
| 1728 | aglSwapBuffers(aglGetCurrentContext()); |
| 1729 | #elif GR_WIN32_BUILD |
| 1730 | SwapBuf(); |
| 1731 | int set_a_break_pt_here = 9; |
| 1732 | SwapBuf(); |
| 1733 | #endif |
| 1734 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1735 | } |
| 1736 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 1737 | void GrGpuGL::onGpuDrawNonIndexed(GrPrimitiveType type, |
| 1738 | uint32_t startVertex, |
| 1739 | uint32_t vertexCount) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1740 | GrAssert((size_t)type < GR_ARRAY_COUNT(gPrimitiveType2GLMode)); |
| 1741 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 1742 | GrAssert(NULL != fHWGeometryState.fVertexBuffer); |
| 1743 | |
| 1744 | // our setupGeometry better have adjusted this to zero. |
| 1745 | // DrawElements doesn't take an offset so we always adjus the startVertex. |
| 1746 | GrAssert(0 == startVertex); |
| 1747 | |
| 1748 | // pass 0 for parameter first. We have to adjust gl*Pointer() to |
| 1749 | // account for startVertex in the DrawElements case. So we always |
| 1750 | // rely on setupGeometry to have accounted for startVertex. |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1751 | GL_CALL(DrawArrays(gPrimitiveType2GLMode[type], 0, vertexCount)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1752 | #if SWAP_PER_DRAW |
| 1753 | glFlush(); |
| 1754 | #if GR_MAC_BUILD |
| 1755 | aglSwapBuffers(aglGetCurrentContext()); |
| 1756 | int set_a_break_pt_here = 9; |
| 1757 | aglSwapBuffers(aglGetCurrentContext()); |
| 1758 | #elif GR_WIN32_BUILD |
| 1759 | SwapBuf(); |
| 1760 | int set_a_break_pt_here = 9; |
| 1761 | SwapBuf(); |
| 1762 | #endif |
| 1763 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1764 | } |
| 1765 | |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 1766 | void GrGpuGL::onResolveRenderTarget(GrRenderTarget* target) { |
| 1767 | |
| 1768 | GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1769 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1770 | if (rt->needsResolve()) { |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 1771 | GrAssert(GLCaps::kNone_MSFBO != fGLCaps.fMSFBOType); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1772 | GrAssert(rt->textureFBOID() != rt->renderFBOID()); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1773 | GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, |
| 1774 | rt->renderFBOID())); |
| 1775 | GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, |
| 1776 | rt->textureFBOID())); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1777 | #if GR_COLLECT_STATS |
| 1778 | ++fStats.fRenderTargetChngCnt; |
| 1779 | #endif |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1780 | // make sure we go through flushRenderTarget() since we've modified |
| 1781 | // the bound DRAW FBO ID. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1782 | fHWDrawState.setRenderTarget(NULL); |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1783 | const GrGLIRect& vp = rt->getViewport(); |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1784 | const GrIRect dirtyRect = rt->getResolveRect(); |
| 1785 | GrGLIRect r; |
| 1786 | r.setRelativeTo(vp, dirtyRect.fLeft, dirtyRect.fTop, |
| 1787 | dirtyRect.width(), dirtyRect.height()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1788 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 1789 | if (GLCaps::kAppleES_MSFBO == fGLCaps.fMSFBOType) { |
bsalomon@google.com | a9ecdad | 2011-03-23 13:50:34 +0000 | [diff] [blame] | 1790 | // Apple's extension uses the scissor as the blit bounds. |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1791 | GL_CALL(Enable(GR_GL_SCISSOR_TEST)); |
| 1792 | GL_CALL(Scissor(r.fLeft, r.fBottom, |
| 1793 | r.fWidth, r.fHeight)); |
| 1794 | GL_CALL(ResolveMultisampleFramebuffer()); |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 1795 | fHWBounds.fScissorRect.invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1796 | fHWBounds.fScissorEnabled = true; |
| 1797 | } else { |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 1798 | if (GLCaps::kDesktopARB_MSFBO != fGLCaps.fMSFBOType) { |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1799 | // this respects the scissor during the blit, so disable it. |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 1800 | GrAssert(GLCaps::kDesktopEXT_MSFBO == fGLCaps.fMSFBOType); |
| 1801 | this->flushScissor(NULL); |
bsalomon@google.com | a9ecdad | 2011-03-23 13:50:34 +0000 | [diff] [blame] | 1802 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1803 | int right = r.fLeft + r.fWidth; |
| 1804 | int top = r.fBottom + r.fHeight; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1805 | GL_CALL(BlitFramebuffer(r.fLeft, r.fBottom, right, top, |
| 1806 | r.fLeft, r.fBottom, right, top, |
| 1807 | GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1808 | } |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1809 | rt->flagAsResolved(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1810 | } |
| 1811 | } |
| 1812 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1813 | static const GrGLenum grToGLStencilFunc[] = { |
| 1814 | GR_GL_ALWAYS, // kAlways_StencilFunc |
| 1815 | GR_GL_NEVER, // kNever_StencilFunc |
| 1816 | GR_GL_GREATER, // kGreater_StencilFunc |
| 1817 | GR_GL_GEQUAL, // kGEqual_StencilFunc |
| 1818 | GR_GL_LESS, // kLess_StencilFunc |
| 1819 | GR_GL_LEQUAL, // kLEqual_StencilFunc, |
| 1820 | GR_GL_EQUAL, // kEqual_StencilFunc, |
| 1821 | GR_GL_NOTEQUAL, // kNotEqual_StencilFunc, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1822 | }; |
| 1823 | GR_STATIC_ASSERT(GR_ARRAY_COUNT(grToGLStencilFunc) == kBasicStencilFuncCount); |
| 1824 | GR_STATIC_ASSERT(0 == kAlways_StencilFunc); |
| 1825 | GR_STATIC_ASSERT(1 == kNever_StencilFunc); |
| 1826 | GR_STATIC_ASSERT(2 == kGreater_StencilFunc); |
| 1827 | GR_STATIC_ASSERT(3 == kGEqual_StencilFunc); |
| 1828 | GR_STATIC_ASSERT(4 == kLess_StencilFunc); |
| 1829 | GR_STATIC_ASSERT(5 == kLEqual_StencilFunc); |
| 1830 | GR_STATIC_ASSERT(6 == kEqual_StencilFunc); |
| 1831 | GR_STATIC_ASSERT(7 == kNotEqual_StencilFunc); |
| 1832 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1833 | static const GrGLenum grToGLStencilOp[] = { |
| 1834 | GR_GL_KEEP, // kKeep_StencilOp |
| 1835 | GR_GL_REPLACE, // kReplace_StencilOp |
| 1836 | GR_GL_INCR_WRAP, // kIncWrap_StencilOp |
| 1837 | GR_GL_INCR, // kIncClamp_StencilOp |
| 1838 | GR_GL_DECR_WRAP, // kDecWrap_StencilOp |
| 1839 | GR_GL_DECR, // kDecClamp_StencilOp |
| 1840 | GR_GL_ZERO, // kZero_StencilOp |
| 1841 | GR_GL_INVERT, // kInvert_StencilOp |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1842 | }; |
| 1843 | GR_STATIC_ASSERT(GR_ARRAY_COUNT(grToGLStencilOp) == kStencilOpCount); |
| 1844 | GR_STATIC_ASSERT(0 == kKeep_StencilOp); |
| 1845 | GR_STATIC_ASSERT(1 == kReplace_StencilOp); |
| 1846 | GR_STATIC_ASSERT(2 == kIncWrap_StencilOp); |
| 1847 | GR_STATIC_ASSERT(3 == kIncClamp_StencilOp); |
| 1848 | GR_STATIC_ASSERT(4 == kDecWrap_StencilOp); |
| 1849 | GR_STATIC_ASSERT(5 == kDecClamp_StencilOp); |
| 1850 | GR_STATIC_ASSERT(6 == kZero_StencilOp); |
| 1851 | GR_STATIC_ASSERT(7 == kInvert_StencilOp); |
| 1852 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1853 | void GrGpuGL::flushStencil() { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1854 | const GrDrawState& drawState = this->getDrawState(); |
| 1855 | |
| 1856 | const GrStencilSettings* settings = &drawState.getStencil(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1857 | |
| 1858 | // use stencil for clipping if clipping is enabled and the clip |
| 1859 | // has been written into the stencil. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1860 | bool stencilClip = fClipInStencil && drawState.isClipState(); |
| 1861 | bool drawClipToStencil = |
| 1862 | drawState.isStateFlagEnabled(kModifyStencilClip_StateBit); |
bsalomon@google.com | 39dab77 | 2012-01-03 19:39:31 +0000 | [diff] [blame] | 1863 | bool stencilChange = (fHWDrawState.getStencil() != *settings) || |
| 1864 | (fHWStencilClip != stencilClip) || |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1865 | (fHWDrawState.isStateFlagEnabled(kModifyStencilClip_StateBit) != |
| 1866 | drawClipToStencil); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1867 | |
| 1868 | if (stencilChange) { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 1869 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1870 | // we can't simultaneously perform stencil-clipping and |
| 1871 | // modify the stencil clip |
| 1872 | GrAssert(!stencilClip || !drawClipToStencil); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1873 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1874 | if (settings->isDisabled()) { |
| 1875 | if (stencilClip) { |
epoger@google.com | 8722d7c | 2012-01-31 17:18:58 +0000 | [diff] [blame] | 1876 | settings = &gClipStencilSettings; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1877 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1878 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1879 | |
| 1880 | if (settings->isDisabled()) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1881 | GL_CALL(Disable(GR_GL_STENCIL_TEST)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1882 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1883 | GL_CALL(Enable(GR_GL_STENCIL_TEST)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1884 | #if GR_DEBUG |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 1885 | if (!this->getCaps().fStencilWrapOpsSupport) { |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 1886 | GrAssert(settings->frontPassOp() != kIncWrap_StencilOp); |
| 1887 | GrAssert(settings->frontPassOp() != kDecWrap_StencilOp); |
| 1888 | GrAssert(settings->frontFailOp() != kIncWrap_StencilOp); |
| 1889 | GrAssert(settings->backFailOp() != kDecWrap_StencilOp); |
| 1890 | GrAssert(settings->backPassOp() != kIncWrap_StencilOp); |
| 1891 | GrAssert(settings->backPassOp() != kDecWrap_StencilOp); |
| 1892 | GrAssert(settings->backFailOp() != kIncWrap_StencilOp); |
| 1893 | GrAssert(settings->frontFailOp() != kDecWrap_StencilOp); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1894 | } |
| 1895 | #endif |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1896 | int stencilBits = 0; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1897 | GrStencilBuffer* stencilBuffer = |
| 1898 | drawState.getRenderTarget()->getStencilBuffer(); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1899 | if (NULL != stencilBuffer) { |
| 1900 | stencilBits = stencilBuffer->bits(); |
| 1901 | } |
| 1902 | // TODO: dynamically attach a stencil buffer |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 1903 | GrAssert(stencilBits || settings->isDisabled()); |
bsalomon@google.com | 2cdfade | 2011-11-23 16:53:42 +0000 | [diff] [blame] | 1904 | |
| 1905 | GrGLuint clipStencilMask = 0; |
| 1906 | GrGLuint userStencilMask = ~0; |
| 1907 | if (stencilBits > 0) { |
| 1908 | clipStencilMask = 1 << (stencilBits - 1); |
| 1909 | userStencilMask = clipStencilMask - 1; |
| 1910 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1911 | |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 1912 | unsigned int frontRef = settings->frontFuncRef(); |
| 1913 | unsigned int frontMask = settings->frontFuncMask(); |
| 1914 | unsigned int frontWriteMask = settings->frontWriteMask(); |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1915 | GrGLenum frontFunc; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1916 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1917 | if (drawClipToStencil) { |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 1918 | GrAssert(settings->frontFunc() < kBasicStencilFuncCount); |
| 1919 | frontFunc = grToGLStencilFunc[settings->frontFunc()]; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1920 | } else { |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 1921 | frontFunc = grToGLStencilFunc[ConvertStencilFunc( |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 1922 | stencilClip, settings->frontFunc())]; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1923 | |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 1924 | ConvertStencilFuncAndMask(settings->frontFunc(), |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1925 | stencilClip, |
| 1926 | clipStencilMask, |
| 1927 | userStencilMask, |
| 1928 | &frontRef, |
| 1929 | &frontMask); |
| 1930 | frontWriteMask &= userStencilMask; |
| 1931 | } |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 1932 | GrAssert((size_t) |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 1933 | settings->frontFailOp() < GR_ARRAY_COUNT(grToGLStencilOp)); |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 1934 | GrAssert((size_t) |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 1935 | settings->frontPassOp() < GR_ARRAY_COUNT(grToGLStencilOp)); |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 1936 | GrAssert((size_t) |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 1937 | settings->backFailOp() < GR_ARRAY_COUNT(grToGLStencilOp)); |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 1938 | GrAssert((size_t) |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 1939 | settings->backPassOp() < GR_ARRAY_COUNT(grToGLStencilOp)); |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 1940 | if (this->getCaps().fTwoSidedStencilSupport) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1941 | GrGLenum backFunc; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1942 | |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 1943 | unsigned int backRef = settings->backFuncRef(); |
| 1944 | unsigned int backMask = settings->backFuncMask(); |
| 1945 | unsigned int backWriteMask = settings->backWriteMask(); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1946 | |
| 1947 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1948 | if (drawClipToStencil) { |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 1949 | GrAssert(settings->backFunc() < kBasicStencilFuncCount); |
| 1950 | backFunc = grToGLStencilFunc[settings->backFunc()]; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1951 | } else { |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 1952 | backFunc = grToGLStencilFunc[ConvertStencilFunc( |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 1953 | stencilClip, settings->backFunc())]; |
| 1954 | ConvertStencilFuncAndMask(settings->backFunc(), |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1955 | stencilClip, |
| 1956 | clipStencilMask, |
| 1957 | userStencilMask, |
| 1958 | &backRef, |
| 1959 | &backMask); |
| 1960 | backWriteMask &= userStencilMask; |
| 1961 | } |
| 1962 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1963 | GL_CALL(StencilFuncSeparate(GR_GL_FRONT, frontFunc, |
| 1964 | frontRef, frontMask)); |
| 1965 | GL_CALL(StencilMaskSeparate(GR_GL_FRONT, frontWriteMask)); |
| 1966 | GL_CALL(StencilFuncSeparate(GR_GL_BACK, backFunc, |
| 1967 | backRef, backMask)); |
| 1968 | GL_CALL(StencilMaskSeparate(GR_GL_BACK, backWriteMask)); |
| 1969 | GL_CALL(StencilOpSeparate(GR_GL_FRONT, |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 1970 | grToGLStencilOp[settings->frontFailOp()], |
| 1971 | grToGLStencilOp[settings->frontPassOp()], |
| 1972 | grToGLStencilOp[settings->frontPassOp()])); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1973 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1974 | GL_CALL(StencilOpSeparate(GR_GL_BACK, |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 1975 | grToGLStencilOp[settings->backFailOp()], |
| 1976 | grToGLStencilOp[settings->backPassOp()], |
| 1977 | grToGLStencilOp[settings->backPassOp()])); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1978 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1979 | GL_CALL(StencilFunc(frontFunc, frontRef, frontMask)); |
| 1980 | GL_CALL(StencilMask(frontWriteMask)); |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 1981 | GL_CALL(StencilOp(grToGLStencilOp[settings->frontFailOp()], |
| 1982 | grToGLStencilOp[settings->frontPassOp()], |
| 1983 | grToGLStencilOp[settings->frontPassOp()])); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1984 | } |
| 1985 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1986 | *fHWDrawState.stencil() = *settings; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1987 | fHWStencilClip = stencilClip; |
| 1988 | } |
| 1989 | } |
| 1990 | |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 1991 | void GrGpuGL::flushAAState(GrPrimitiveType type) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1992 | const GrRenderTarget* rt = this->getDrawState().getRenderTarget(); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1993 | if (kDesktop_GrGLBinding == this->glBinding()) { |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 1994 | // ES doesn't support toggling GL_MULTISAMPLE and doesn't have |
| 1995 | // smooth lines. |
| 1996 | |
| 1997 | // we prefer smooth lines over multisampled lines |
| 1998 | // msaa should be disabled if drawing smooth lines. |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1999 | if (GrIsPrimTypeLines(type)) { |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 2000 | bool smooth = this->willUseHWAALines(); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 2001 | if (!fHWAAState.fSmoothLineEnabled && smooth) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2002 | GL_CALL(Enable(GR_GL_LINE_SMOOTH)); |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 2003 | fHWAAState.fSmoothLineEnabled = true; |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 2004 | } else if (fHWAAState.fSmoothLineEnabled && !smooth) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2005 | GL_CALL(Disable(GR_GL_LINE_SMOOTH)); |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 2006 | fHWAAState.fSmoothLineEnabled = false; |
| 2007 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2008 | if (rt->isMultisampled() && |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 2009 | fHWAAState.fMSAAEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2010 | GL_CALL(Disable(GR_GL_MULTISAMPLE)); |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 2011 | fHWAAState.fMSAAEnabled = false; |
| 2012 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2013 | } else if (rt->isMultisampled() && |
| 2014 | this->getDrawState().isHWAntialiasState() != |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 2015 | fHWAAState.fMSAAEnabled) { |
| 2016 | if (fHWAAState.fMSAAEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2017 | GL_CALL(Disable(GR_GL_MULTISAMPLE)); |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 2018 | fHWAAState.fMSAAEnabled = false; |
| 2019 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2020 | GL_CALL(Enable(GR_GL_MULTISAMPLE)); |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 2021 | fHWAAState.fMSAAEnabled = true; |
| 2022 | } |
| 2023 | } |
| 2024 | } |
| 2025 | } |
| 2026 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 2027 | void GrGpuGL::flushBlend(GrPrimitiveType type, |
| 2028 | GrBlendCoeff srcCoeff, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 2029 | GrBlendCoeff dstCoeff) { |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 2030 | if (GrIsPrimTypeLines(type) && this->willUseHWAALines()) { |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 2031 | if (fHWBlendDisabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2032 | GL_CALL(Enable(GR_GL_BLEND)); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 2033 | fHWBlendDisabled = false; |
| 2034 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2035 | if (kSA_BlendCoeff != fHWDrawState.getSrcBlendCoeff() || |
| 2036 | kISA_BlendCoeff != fHWDrawState.getDstBlendCoeff()) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2037 | GL_CALL(BlendFunc(gXfermodeCoeff2Blend[kSA_BlendCoeff], |
| 2038 | gXfermodeCoeff2Blend[kISA_BlendCoeff])); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2039 | fHWDrawState.setBlendFunc(kSA_BlendCoeff, kISA_BlendCoeff); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 2040 | } |
| 2041 | } else { |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 2042 | // any optimization to disable blending should |
| 2043 | // have already been applied and tweaked the coeffs |
| 2044 | // to (1, 0). |
| 2045 | bool blendOff = kOne_BlendCoeff == srcCoeff && |
| 2046 | kZero_BlendCoeff == dstCoeff; |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 2047 | if (fHWBlendDisabled != blendOff) { |
| 2048 | if (blendOff) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2049 | GL_CALL(Disable(GR_GL_BLEND)); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 2050 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2051 | GL_CALL(Enable(GR_GL_BLEND)); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 2052 | } |
| 2053 | fHWBlendDisabled = blendOff; |
| 2054 | } |
| 2055 | if (!blendOff) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2056 | if (fHWDrawState.getSrcBlendCoeff() != srcCoeff || |
| 2057 | fHWDrawState.getDstBlendCoeff() != dstCoeff) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2058 | GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff], |
| 2059 | gXfermodeCoeff2Blend[dstCoeff])); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2060 | fHWDrawState.setBlendFunc(srcCoeff, dstCoeff); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 2061 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2062 | GrColor blendConst = fCurrDrawState.getBlendConstant(); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 2063 | if ((BlendCoeffReferencesConstant(srcCoeff) || |
| 2064 | BlendCoeffReferencesConstant(dstCoeff)) && |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2065 | fHWDrawState.getBlendConstant() != blendConst) { |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 2066 | |
| 2067 | float c[] = { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2068 | GrColorUnpackR(blendConst) / 255.f, |
| 2069 | GrColorUnpackG(blendConst) / 255.f, |
| 2070 | GrColorUnpackB(blendConst) / 255.f, |
| 2071 | GrColorUnpackA(blendConst) / 255.f |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 2072 | }; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2073 | GL_CALL(BlendColor(c[0], c[1], c[2], c[3])); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2074 | fHWDrawState.setBlendConstant(blendConst); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 2075 | } |
| 2076 | } |
| 2077 | } |
| 2078 | } |
| 2079 | |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 2080 | namespace { |
| 2081 | |
| 2082 | unsigned gr_to_gl_filter(GrSamplerState::Filter filter) { |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 2083 | switch (filter) { |
| 2084 | case GrSamplerState::kBilinear_Filter: |
| 2085 | case GrSamplerState::k4x4Downsample_Filter: |
| 2086 | return GR_GL_LINEAR; |
| 2087 | case GrSamplerState::kNearest_Filter: |
| 2088 | case GrSamplerState::kConvolution_Filter: |
| 2089 | return GR_GL_NEAREST; |
| 2090 | default: |
| 2091 | GrAssert(!"Unknown filter type"); |
| 2092 | return GR_GL_LINEAR; |
| 2093 | } |
| 2094 | } |
| 2095 | |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 2096 | const GrGLenum* get_swizzle(GrPixelConfig config, |
| 2097 | const GrSamplerState& sampler) { |
| 2098 | if (GrPixelConfigIsAlphaOnly(config)) { |
| 2099 | static const GrGLenum gAlphaSmear[] = { GR_GL_ALPHA, GR_GL_ALPHA, |
| 2100 | GR_GL_ALPHA, GR_GL_ALPHA }; |
| 2101 | return gAlphaSmear; |
| 2102 | } else if (sampler.swapsRAndB()) { |
| 2103 | static const GrGLenum gRedBlueSwap[] = { GR_GL_BLUE, GR_GL_GREEN, |
| 2104 | GR_GL_RED, GR_GL_ALPHA }; |
| 2105 | return gRedBlueSwap; |
| 2106 | } else { |
| 2107 | static const GrGLenum gStraight[] = { GR_GL_RED, GR_GL_GREEN, |
| 2108 | GR_GL_BLUE, GR_GL_ALPHA }; |
| 2109 | return gStraight; |
| 2110 | } |
| 2111 | } |
| 2112 | |
| 2113 | void set_tex_swizzle(GrGLenum swizzle[4], const GrGLInterface* gl) { |
| 2114 | // should add texparameteri to interface to make 1 instead of 4 calls here |
| 2115 | GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, |
| 2116 | GR_GL_TEXTURE_SWIZZLE_R, |
| 2117 | swizzle[0])); |
| 2118 | GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, |
| 2119 | GR_GL_TEXTURE_SWIZZLE_G, |
| 2120 | swizzle[1])); |
| 2121 | GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, |
| 2122 | GR_GL_TEXTURE_SWIZZLE_B, |
| 2123 | swizzle[2])); |
| 2124 | GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, |
| 2125 | GR_GL_TEXTURE_SWIZZLE_A, |
| 2126 | swizzle[3])); |
| 2127 | } |
| 2128 | } |
| 2129 | |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 2130 | bool GrGpuGL::flushGLStateCommon(GrPrimitiveType type) { |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2131 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2132 | GrDrawState* drawState = this->drawState(); |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2133 | // GrGpu::setupClipAndFlushState should have already checked this |
| 2134 | // and bailed if not true. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2135 | GrAssert(NULL != drawState->getRenderTarget()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2136 | |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 2137 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2138 | // bind texture and set sampler state |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 2139 | if (this->isStageEnabled(s)) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2140 | GrGLTexture* nextTexture = |
| 2141 | static_cast<GrGLTexture*>(drawState->getTexture(s)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2142 | |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 2143 | // true for now, but maybe not with GrEffect. |
| 2144 | GrAssert(NULL != nextTexture); |
| 2145 | // if we created a rt/tex and rendered to it without using a |
| 2146 | // texture and now we're texuring from the rt it will still be |
| 2147 | // the last bound texture, but it needs resolving. So keep this |
| 2148 | // out of the "last != next" check. |
| 2149 | GrGLRenderTarget* texRT = |
| 2150 | static_cast<GrGLRenderTarget*>(nextTexture->asRenderTarget()); |
| 2151 | if (NULL != texRT) { |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 2152 | this->onResolveRenderTarget(texRT); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2153 | } |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 2154 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2155 | if (fHWDrawState.getTexture(s) != nextTexture) { |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 2156 | setTextureUnit(s); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2157 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, nextTexture->textureID())); |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 2158 | #if GR_COLLECT_STATS |
| 2159 | ++fStats.fTextureChngCnt; |
| 2160 | #endif |
| 2161 | //GrPrintf("---- bindtexture %d\n", nextTexture->textureID()); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2162 | fHWDrawState.setTexture(s, nextTexture); |
bsalomon@google.com | cd19a5f | 2011-06-15 14:00:23 +0000 | [diff] [blame] | 2163 | // The texture matrix has to compensate for texture width/height |
| 2164 | // and NPOT-embedded-in-POT |
| 2165 | fDirtyFlags.fTextureChangedMask |= (1 << s); |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 2166 | } |
| 2167 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2168 | const GrSamplerState& sampler = drawState->getSampler(s); |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 2169 | ResetTimestamp timestamp; |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 2170 | const GrGLTexture::TexParams& oldTexParams = |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 2171 | nextTexture->getCachedTexParams(×tamp); |
| 2172 | bool setAll = timestamp < this->getResetTimestamp(); |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 2173 | GrGLTexture::TexParams newTexParams; |
| 2174 | |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 2175 | newTexParams.fFilter = gr_to_gl_filter(sampler.getFilter()); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 2176 | |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 2177 | const GrGLenum* wraps = GrGLTexture::WrapMode2GLWrap(); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2178 | newTexParams.fWrapS = wraps[sampler.getWrapX()]; |
| 2179 | newTexParams.fWrapT = wraps[sampler.getWrapY()]; |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 2180 | memcpy(newTexParams.fSwizzleRGBA, |
| 2181 | get_swizzle(nextTexture->config(), sampler), |
| 2182 | sizeof(newTexParams.fSwizzleRGBA)); |
| 2183 | if (setAll || newTexParams.fFilter != oldTexParams.fFilter) { |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 2184 | setTextureUnit(s); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2185 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 2186 | GR_GL_TEXTURE_MAG_FILTER, |
| 2187 | newTexParams.fFilter)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2188 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 2189 | GR_GL_TEXTURE_MIN_FILTER, |
| 2190 | newTexParams.fFilter)); |
| 2191 | } |
| 2192 | if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) { |
| 2193 | setTextureUnit(s); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2194 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 2195 | GR_GL_TEXTURE_WRAP_S, |
| 2196 | newTexParams.fWrapS)); |
| 2197 | } |
| 2198 | if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) { |
| 2199 | setTextureUnit(s); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2200 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 2201 | GR_GL_TEXTURE_WRAP_T, |
| 2202 | newTexParams.fWrapT)); |
| 2203 | } |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 2204 | if (this->glCaps().fTextureSwizzleSupport && |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 2205 | (setAll || |
| 2206 | memcmp(newTexParams.fSwizzleRGBA, |
| 2207 | oldTexParams.fSwizzleRGBA, |
| 2208 | sizeof(newTexParams.fSwizzleRGBA)))) { |
| 2209 | setTextureUnit(s); |
| 2210 | set_tex_swizzle(newTexParams.fSwizzleRGBA, |
| 2211 | this->glInterface()); |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 2212 | } |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 2213 | nextTexture->setCachedTexParams(newTexParams, |
| 2214 | this->getResetTimestamp()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2215 | } |
| 2216 | } |
| 2217 | |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 2218 | GrIRect* rect = NULL; |
| 2219 | GrIRect clipBounds; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2220 | if (drawState->isClipState() && |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 2221 | fClip.hasConservativeBounds()) { |
| 2222 | fClip.getConservativeBounds().roundOut(&clipBounds); |
| 2223 | rect = &clipBounds; |
| 2224 | } |
| 2225 | this->flushRenderTarget(rect); |
| 2226 | this->flushAAState(type); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 2227 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2228 | if (drawState->isDitherState() != fHWDrawState.isDitherState()) { |
| 2229 | if (drawState->isDitherState()) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2230 | GL_CALL(Enable(GR_GL_DITHER)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2231 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2232 | GL_CALL(Disable(GR_GL_DITHER)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2233 | } |
| 2234 | } |
| 2235 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2236 | if (drawState->isColorWriteDisabled() != |
| 2237 | fHWDrawState.isColorWriteDisabled()) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2238 | GrGLenum mask; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2239 | if (drawState->isColorWriteDisabled()) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2240 | mask = GR_GL_FALSE; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2241 | } else { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2242 | mask = GR_GL_TRUE; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2243 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2244 | GL_CALL(ColorMask(mask, mask, mask, mask)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2245 | } |
| 2246 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2247 | if (fHWDrawState.getDrawFace() != drawState->getDrawFace()) { |
| 2248 | switch (fCurrDrawState.getDrawFace()) { |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 2249 | case GrDrawState::kCCW_DrawFace: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2250 | GL_CALL(Enable(GR_GL_CULL_FACE)); |
| 2251 | GL_CALL(CullFace(GR_GL_BACK)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2252 | break; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 2253 | case GrDrawState::kCW_DrawFace: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2254 | GL_CALL(Enable(GR_GL_CULL_FACE)); |
| 2255 | GL_CALL(CullFace(GR_GL_FRONT)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2256 | break; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 2257 | case GrDrawState::kBoth_DrawFace: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2258 | GL_CALL(Disable(GR_GL_CULL_FACE)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2259 | break; |
| 2260 | default: |
| 2261 | GrCrash("Unknown draw face."); |
| 2262 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2263 | fHWDrawState.setDrawFace(drawState->getDrawFace()); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2264 | } |
| 2265 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2266 | #if GR_DEBUG |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2267 | // check for circular rendering |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 2268 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 2269 | GrAssert(!this->isStageEnabled(s) || |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2270 | NULL == drawState->getRenderTarget() || |
| 2271 | NULL == drawState->getTexture(s) || |
| 2272 | drawState->getTexture(s)->asRenderTarget() != |
| 2273 | drawState->getRenderTarget()); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2274 | } |
| 2275 | #endif |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 2276 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2277 | this->flushStencil(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2278 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2279 | // This copy must happen after flushStencil() is called. flushStencil() |
| 2280 | // relies on detecting when the kModifyStencilClip_StateBit state has |
| 2281 | // changed since the last draw. |
| 2282 | fHWDrawState.copyStateFlags(*drawState); |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2283 | return true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | void GrGpuGL::notifyVertexBufferBind(const GrGLVertexBuffer* buffer) { |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 2287 | if (fHWGeometryState.fVertexBuffer != buffer) { |
| 2288 | fHWGeometryState.fArrayPtrsDirty = true; |
| 2289 | fHWGeometryState.fVertexBuffer = buffer; |
| 2290 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | void GrGpuGL::notifyVertexBufferDelete(const GrGLVertexBuffer* buffer) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2294 | if (fHWGeometryState.fVertexBuffer == buffer) { |
| 2295 | // deleting bound buffer does implied bind to 0 |
| 2296 | fHWGeometryState.fVertexBuffer = NULL; |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 2297 | fHWGeometryState.fArrayPtrsDirty = true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2298 | } |
| 2299 | } |
| 2300 | |
| 2301 | void GrGpuGL::notifyIndexBufferBind(const GrGLIndexBuffer* buffer) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 2302 | fHWGeometryState.fIndexBuffer = buffer; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2303 | } |
| 2304 | |
| 2305 | void GrGpuGL::notifyIndexBufferDelete(const GrGLIndexBuffer* buffer) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2306 | if (fHWGeometryState.fIndexBuffer == buffer) { |
| 2307 | // deleting bound buffer does implied bind to 0 |
| 2308 | fHWGeometryState.fIndexBuffer = NULL; |
| 2309 | } |
| 2310 | } |
| 2311 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2312 | void GrGpuGL::notifyRenderTargetDelete(GrRenderTarget* renderTarget) { |
| 2313 | GrAssert(NULL != renderTarget); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2314 | GrDrawState* drawState = this->drawState(); |
| 2315 | if (drawState->getRenderTarget() == renderTarget) { |
| 2316 | drawState->setRenderTarget(NULL); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2317 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2318 | if (fHWDrawState.getRenderTarget() == renderTarget) { |
| 2319 | fHWDrawState.setRenderTarget(NULL); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2320 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | void GrGpuGL::notifyTextureDelete(GrGLTexture* texture) { |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 2324 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2325 | GrDrawState* drawState = this->drawState(); |
| 2326 | if (drawState->getTexture(s) == texture) { |
| 2327 | fCurrDrawState.setTexture(s, NULL); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2328 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2329 | if (fHWDrawState.getTexture(s) == texture) { |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2330 | // deleting bound texture does implied bind to 0 |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 2331 | fHWDrawState.setTexture(s, NULL); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2332 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2333 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2334 | } |
| 2335 | |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2336 | bool GrGpuGL::configToGLFormats(GrPixelConfig config, |
| 2337 | bool getSizedInternalFormat, |
| 2338 | GrGLenum* internalFormat, |
| 2339 | GrGLenum* externalFormat, |
| 2340 | GrGLenum* externalType) { |
| 2341 | GrGLenum dontCare; |
| 2342 | if (NULL == internalFormat) { |
| 2343 | internalFormat = &dontCare; |
| 2344 | } |
| 2345 | if (NULL == externalFormat) { |
| 2346 | externalFormat = &dontCare; |
| 2347 | } |
| 2348 | if (NULL == externalType) { |
| 2349 | externalType = &dontCare; |
| 2350 | } |
| 2351 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2352 | switch (config) { |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 2353 | case kRGBA_8888_PM_GrPixelConfig: |
| 2354 | case kRGBA_8888_UPM_GrPixelConfig: |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 2355 | *internalFormat = GR_GL_RGBA; |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2356 | *externalFormat = GR_GL_RGBA; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2357 | if (getSizedInternalFormat) { |
| 2358 | *internalFormat = GR_GL_RGBA8; |
| 2359 | } else { |
| 2360 | *internalFormat = GR_GL_RGBA; |
| 2361 | } |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 2362 | *externalType = GR_GL_UNSIGNED_BYTE; |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 2363 | break; |
| 2364 | case kBGRA_8888_PM_GrPixelConfig: |
| 2365 | case kBGRA_8888_UPM_GrPixelConfig: |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 2366 | if (!fGLCaps.fBGRAFormatSupport) { |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 2367 | return false; |
| 2368 | } |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 2369 | if (fGLCaps.fBGRAIsInternalFormat) { |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2370 | if (getSizedInternalFormat) { |
| 2371 | *internalFormat = GR_GL_BGRA8; |
| 2372 | } else { |
| 2373 | *internalFormat = GR_GL_BGRA; |
| 2374 | } |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 2375 | } else { |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2376 | if (getSizedInternalFormat) { |
| 2377 | *internalFormat = GR_GL_RGBA8; |
| 2378 | } else { |
| 2379 | *internalFormat = GR_GL_RGBA; |
| 2380 | } |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 2381 | } |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2382 | *externalFormat = GR_GL_BGRA; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 2383 | *externalType = GR_GL_UNSIGNED_BYTE; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2384 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2385 | case kRGB_565_GrPixelConfig: |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2386 | *internalFormat = GR_GL_RGB; |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2387 | *externalFormat = GR_GL_RGB; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2388 | if (getSizedInternalFormat) { |
| 2389 | if (this->glBinding() == kDesktop_GrGLBinding) { |
| 2390 | return false; |
| 2391 | } else { |
| 2392 | *internalFormat = GR_GL_RGB565; |
| 2393 | } |
| 2394 | } else { |
| 2395 | *internalFormat = GR_GL_RGB; |
| 2396 | } |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 2397 | *externalType = GR_GL_UNSIGNED_SHORT_5_6_5; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2398 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2399 | case kRGBA_4444_GrPixelConfig: |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2400 | *internalFormat = GR_GL_RGBA; |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2401 | *externalFormat = GR_GL_RGBA; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2402 | if (getSizedInternalFormat) { |
| 2403 | *internalFormat = GR_GL_RGBA4; |
| 2404 | } else { |
| 2405 | *internalFormat = GR_GL_RGBA; |
| 2406 | } |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 2407 | *externalType = GR_GL_UNSIGNED_SHORT_4_4_4_4; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2408 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2409 | case kIndex_8_GrPixelConfig: |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 2410 | if (this->getCaps().f8BitPaletteSupport) { |
bsalomon@google.com | c312bf9 | 2011-03-21 21:10:33 +0000 | [diff] [blame] | 2411 | *internalFormat = GR_GL_PALETTE8_RGBA8; |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2412 | // glCompressedTexImage doesn't take external params |
| 2413 | *externalFormat = GR_GL_PALETTE8_RGBA8; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2414 | // no sized/unsized internal format distinction here |
| 2415 | *internalFormat = GR_GL_PALETTE8_RGBA8; |
| 2416 | // unused with CompressedTexImage |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2417 | *externalType = GR_GL_UNSIGNED_BYTE; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2418 | } else { |
| 2419 | return false; |
| 2420 | } |
| 2421 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2422 | case kAlpha_8_GrPixelConfig: |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2423 | *internalFormat = GR_GL_ALPHA; |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2424 | *externalFormat = GR_GL_ALPHA; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2425 | if (getSizedInternalFormat) { |
| 2426 | *internalFormat = GR_GL_ALPHA8; |
| 2427 | } else { |
| 2428 | *internalFormat = GR_GL_ALPHA; |
| 2429 | } |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 2430 | *externalType = GR_GL_UNSIGNED_BYTE; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2431 | break; |
| 2432 | default: |
| 2433 | return false; |
| 2434 | } |
| 2435 | return true; |
| 2436 | } |
| 2437 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2438 | void GrGpuGL::setTextureUnit(int unit) { |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 2439 | GrAssert(unit >= 0 && unit < GrDrawState::kNumStages); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2440 | if (fActiveTextureUnitIdx != unit) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2441 | GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + unit)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2442 | fActiveTextureUnitIdx = unit; |
| 2443 | } |
| 2444 | } |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 2445 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2446 | void GrGpuGL::setSpareTextureUnit() { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2447 | if (fActiveTextureUnitIdx != (GR_GL_TEXTURE0 + SPARE_TEX_UNIT)) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2448 | GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + SPARE_TEX_UNIT)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2449 | fActiveTextureUnitIdx = SPARE_TEX_UNIT; |
| 2450 | } |
| 2451 | } |
| 2452 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 2453 | void GrGpuGL::resetDirtyFlags() { |
| 2454 | Gr_bzero(&fDirtyFlags, sizeof(fDirtyFlags)); |
| 2455 | } |
| 2456 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2457 | void GrGpuGL::setBuffers(bool indexed, |
| 2458 | int* extraVertexOffset, |
| 2459 | int* extraIndexOffset) { |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 2460 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2461 | GrAssert(NULL != extraVertexOffset); |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 2462 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 2463 | const GeometryPoolState& geoPoolState = this->getGeomPoolState(); |
| 2464 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2465 | GrGLVertexBuffer* vbuf; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 2466 | switch (this->getGeomSrc().fVertexSrc) { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2467 | case kBuffer_GeometrySrcType: |
| 2468 | *extraVertexOffset = 0; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 2469 | vbuf = (GrGLVertexBuffer*) this->getGeomSrc().fVertexBuffer; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2470 | break; |
| 2471 | case kArray_GeometrySrcType: |
| 2472 | case kReserved_GeometrySrcType: |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 2473 | this->finalizeReservedVertices(); |
| 2474 | *extraVertexOffset = geoPoolState.fPoolStartVertex; |
| 2475 | vbuf = (GrGLVertexBuffer*) geoPoolState.fPoolVertexBuffer; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2476 | break; |
| 2477 | default: |
| 2478 | vbuf = NULL; // suppress warning |
| 2479 | GrCrash("Unknown geometry src type!"); |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 2480 | } |
| 2481 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2482 | GrAssert(NULL != vbuf); |
| 2483 | GrAssert(!vbuf->isLocked()); |
| 2484 | if (fHWGeometryState.fVertexBuffer != vbuf) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2485 | GL_CALL(BindBuffer(GR_GL_ARRAY_BUFFER, vbuf->bufferID())); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2486 | fHWGeometryState.fArrayPtrsDirty = true; |
| 2487 | fHWGeometryState.fVertexBuffer = vbuf; |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 2488 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2489 | |
| 2490 | if (indexed) { |
| 2491 | GrAssert(NULL != extraIndexOffset); |
| 2492 | |
| 2493 | GrGLIndexBuffer* ibuf; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 2494 | switch (this->getGeomSrc().fIndexSrc) { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2495 | case kBuffer_GeometrySrcType: |
| 2496 | *extraIndexOffset = 0; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 2497 | ibuf = (GrGLIndexBuffer*)this->getGeomSrc().fIndexBuffer; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2498 | break; |
| 2499 | case kArray_GeometrySrcType: |
| 2500 | case kReserved_GeometrySrcType: |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 2501 | this->finalizeReservedIndices(); |
| 2502 | *extraIndexOffset = geoPoolState.fPoolStartIndex; |
| 2503 | ibuf = (GrGLIndexBuffer*) geoPoolState.fPoolIndexBuffer; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2504 | break; |
| 2505 | default: |
| 2506 | ibuf = NULL; // suppress warning |
| 2507 | GrCrash("Unknown geometry src type!"); |
| 2508 | } |
| 2509 | |
| 2510 | GrAssert(NULL != ibuf); |
| 2511 | GrAssert(!ibuf->isLocked()); |
| 2512 | if (fHWGeometryState.fIndexBuffer != ibuf) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2513 | GL_CALL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, ibuf->bufferID())); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2514 | fHWGeometryState.fIndexBuffer = ibuf; |
| 2515 | } |
| 2516 | } |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 2517 | } |
senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 2518 | |
| 2519 | int GrGpuGL::getMaxEdges() const { |
| 2520 | // FIXME: This is a pessimistic estimate based on how many other things |
| 2521 | // want to add uniforms. This should be centralized somewhere. |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 2522 | return GR_CT_MIN(fGLCaps.fMaxFragmentUniformVectors - 8, |
| 2523 | GrDrawState::kMaxEdges); |
senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 2524 | } |
bsalomon@google.com | fe67652 | 2011-06-17 18:12:21 +0000 | [diff] [blame] | 2525 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 2526 | void GrGpuGL::GLCaps::print() const { |
| 2527 | for (int i = 0; i < fStencilFormats.count(); ++i) { |
| 2528 | GrPrintf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n", |
| 2529 | i, |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame^] | 2530 | fStencilFormats[i].fFormat.fStencilBits, |
| 2531 | fStencilFormats[i].fFormat.fTotalBits); |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | GR_STATIC_ASSERT(0 == kNone_MSFBO); |
| 2535 | GR_STATIC_ASSERT(1 == kDesktopARB_MSFBO); |
| 2536 | GR_STATIC_ASSERT(2 == kDesktopEXT_MSFBO); |
| 2537 | GR_STATIC_ASSERT(3 == kAppleES_MSFBO); |
| 2538 | static const char* gMSFBOExtStr[] = { |
| 2539 | "None", |
| 2540 | "ARB", |
| 2541 | "EXT", |
| 2542 | "Apple", |
| 2543 | }; |
| 2544 | GrPrintf("MSAA Type: %s\n", gMSFBOExtStr[fMSFBOType]); |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 2545 | GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors); |
| 2546 | GrPrintf("Support RGBA8 Render Buffer: %s\n", |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 2547 | (fRGBA8RenderbufferSupport ? "YES": "NO")); |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 2548 | GrPrintf("BGRA is an internal format: %s\n", |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 2549 | (fBGRAIsInternalFormat ? "YES": "NO")); |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 2550 | GrPrintf("Support texture swizzle: %s\n", |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 2551 | (fTextureSwizzleSupport ? "YES": "NO")); |
| 2552 | GrPrintf("Unpack Row length support: %s\n", |
| 2553 | (fUnpackRowLengthSupport ? "YES": "NO")); |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 2554 | GrPrintf("Unpack Flip Y support: %s\n", |
| 2555 | (fUnpackFlipYSupport ? "YES": "NO")); |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 2556 | GrPrintf("Pack Row length support: %s\n", |
| 2557 | (fPackRowLengthSupport ? "YES": "NO")); |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 2558 | GrPrintf("Pack Flip Y support: %s\n", |
| 2559 | (fPackFlipYSupport ? "YES": "NO")); |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 2560 | } |