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. |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 23 | static const int SPARE_TEX_UNIT = GrGpuGL::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 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 27 | static const GrGLenum gXfermodeCoeff2Blend[] = { |
| 28 | GR_GL_ZERO, |
| 29 | GR_GL_ONE, |
| 30 | GR_GL_SRC_COLOR, |
| 31 | GR_GL_ONE_MINUS_SRC_COLOR, |
| 32 | GR_GL_DST_COLOR, |
| 33 | GR_GL_ONE_MINUS_DST_COLOR, |
| 34 | GR_GL_SRC_ALPHA, |
| 35 | GR_GL_ONE_MINUS_SRC_ALPHA, |
| 36 | GR_GL_DST_ALPHA, |
| 37 | GR_GL_ONE_MINUS_DST_ALPHA, |
| 38 | GR_GL_CONSTANT_COLOR, |
| 39 | GR_GL_ONE_MINUS_CONSTANT_COLOR, |
| 40 | GR_GL_CONSTANT_ALPHA, |
| 41 | GR_GL_ONE_MINUS_CONSTANT_ALPHA, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 42 | |
| 43 | // extended blend coeffs |
| 44 | GR_GL_SRC1_COLOR, |
| 45 | GR_GL_ONE_MINUS_SRC1_COLOR, |
| 46 | GR_GL_SRC1_ALPHA, |
| 47 | GR_GL_ONE_MINUS_SRC1_ALPHA, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 50 | bool GrGpuGL::BlendCoeffReferencesConstant(GrBlendCoeff coeff) { |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 51 | static const bool gCoeffReferencesBlendConst[] = { |
| 52 | false, |
| 53 | false, |
| 54 | false, |
| 55 | false, |
| 56 | false, |
| 57 | false, |
| 58 | false, |
| 59 | false, |
| 60 | false, |
| 61 | false, |
| 62 | true, |
| 63 | true, |
| 64 | true, |
| 65 | true, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 66 | |
| 67 | // extended blend coeffs |
| 68 | false, |
| 69 | false, |
| 70 | false, |
| 71 | false, |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 72 | }; |
| 73 | return gCoeffReferencesBlendConst[coeff]; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 74 | GR_STATIC_ASSERT(kTotalBlendCoeffCount == GR_ARRAY_COUNT(gCoeffReferencesBlendConst)); |
| 75 | |
| 76 | GR_STATIC_ASSERT(0 == kZero_BlendCoeff); |
| 77 | GR_STATIC_ASSERT(1 == kOne_BlendCoeff); |
| 78 | GR_STATIC_ASSERT(2 == kSC_BlendCoeff); |
| 79 | GR_STATIC_ASSERT(3 == kISC_BlendCoeff); |
| 80 | GR_STATIC_ASSERT(4 == kDC_BlendCoeff); |
| 81 | GR_STATIC_ASSERT(5 == kIDC_BlendCoeff); |
| 82 | GR_STATIC_ASSERT(6 == kSA_BlendCoeff); |
| 83 | GR_STATIC_ASSERT(7 == kISA_BlendCoeff); |
| 84 | GR_STATIC_ASSERT(8 == kDA_BlendCoeff); |
| 85 | GR_STATIC_ASSERT(9 == kIDA_BlendCoeff); |
| 86 | GR_STATIC_ASSERT(10 == kConstC_BlendCoeff); |
| 87 | GR_STATIC_ASSERT(11 == kIConstC_BlendCoeff); |
| 88 | GR_STATIC_ASSERT(12 == kConstA_BlendCoeff); |
| 89 | GR_STATIC_ASSERT(13 == kIConstA_BlendCoeff); |
| 90 | |
| 91 | GR_STATIC_ASSERT(14 == kS2C_BlendCoeff); |
| 92 | GR_STATIC_ASSERT(15 == kIS2C_BlendCoeff); |
| 93 | GR_STATIC_ASSERT(16 == kS2A_BlendCoeff); |
| 94 | GR_STATIC_ASSERT(17 == kIS2A_BlendCoeff); |
| 95 | |
| 96 | // assertion for gXfermodeCoeff2Blend have to be in GrGpu scope |
| 97 | GR_STATIC_ASSERT(kTotalBlendCoeffCount == GR_ARRAY_COUNT(gXfermodeCoeff2Blend)); |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 98 | } |
| 99 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 100 | /////////////////////////////////////////////////////////////////////////////// |
| 101 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 102 | void GrGpuGL::AdjustTextureMatrix(const GrGLTexture* texture, |
| 103 | GrSamplerState::SampleMode mode, |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 104 | GrMatrix* matrix) { |
| 105 | GrAssert(NULL != texture); |
| 106 | GrAssert(NULL != matrix); |
| 107 | if (GR_Scalar1 != texture->contentScaleX() || |
| 108 | GR_Scalar1 != texture->contentScaleY()) { |
| 109 | if (GrSamplerState::kRadial_SampleMode == mode) { |
| 110 | GrMatrix scale; |
| 111 | scale.setScale(texture->contentScaleX(), texture->contentScaleX()); |
| 112 | matrix->postConcat(scale); |
| 113 | } else if (GrSamplerState::kNormal_SampleMode == mode) { |
| 114 | GrMatrix scale; |
| 115 | scale.setScale(texture->contentScaleX(), texture->contentScaleY()); |
| 116 | matrix->postConcat(scale); |
| 117 | } else { |
| 118 | GrPrintf("We haven't handled NPOT adjustment for other sample modes!"); |
| 119 | } |
| 120 | } |
| 121 | GrGLTexture::Orientation orientation = texture->orientation(); |
| 122 | if (GrGLTexture::kBottomUp_Orientation == orientation) { |
| 123 | GrMatrix invY; |
| 124 | invY.setAll(GR_Scalar1, 0, 0, |
| 125 | 0, -GR_Scalar1, GR_Scalar1, |
| 126 | 0, 0, GrMatrix::I()[8]); |
| 127 | matrix->postConcat(invY); |
| 128 | } else { |
| 129 | GrAssert(GrGLTexture::kTopDown_Orientation == orientation); |
| 130 | } |
| 131 | } |
| 132 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 133 | bool GrGpuGL::TextureMatrixIsIdentity(const GrGLTexture* texture, |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 134 | const GrSamplerState& sampler) { |
| 135 | GrAssert(NULL != texture); |
| 136 | if (!sampler.getMatrix().isIdentity()) { |
| 137 | return false; |
| 138 | } |
| 139 | if (GR_Scalar1 != texture->contentScaleX() || |
| 140 | GR_Scalar1 != texture->contentScaleY()) { |
| 141 | return false; |
| 142 | } |
| 143 | GrGLTexture::Orientation orientation = texture->orientation(); |
| 144 | if (GrGLTexture::kBottomUp_Orientation == orientation) { |
| 145 | return false; |
| 146 | } else { |
| 147 | GrAssert(GrGLTexture::kTopDown_Orientation == orientation); |
| 148 | } |
| 149 | return true; |
| 150 | } |
| 151 | |
| 152 | /////////////////////////////////////////////////////////////////////////////// |
| 153 | |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 154 | static bool gPrintStartupSpew; |
| 155 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 156 | static bool fbo_test(const GrGLInterface* gl, int w, int h) { |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 157 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 158 | GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE0 + SPARE_TEX_UNIT)); |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 159 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 160 | GrGLuint testFBO; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 161 | GR_GL_CALL(gl, GenFramebuffers(1, &testFBO)); |
| 162 | GR_GL_CALL(gl, BindFramebuffer(GR_GL_FRAMEBUFFER, testFBO)); |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 163 | GrGLuint testRTTex; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 164 | GR_GL_CALL(gl, GenTextures(1, &testRTTex)); |
| 165 | GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, testRTTex)); |
bsalomon@google.com | 2fbc7fa | 2011-01-05 16:34:41 +0000 | [diff] [blame] | 166 | // some implementations require texture to be mip-map complete before |
| 167 | // FBO with level 0 bound as color attachment will be framebuffer complete. |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 168 | GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, |
| 169 | GR_GL_TEXTURE_MIN_FILTER, |
| 170 | GR_GL_NEAREST)); |
| 171 | GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RGBA, w, h, |
| 172 | 0, GR_GL_RGBA, GR_GL_UNSIGNED_BYTE, NULL)); |
| 173 | GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, 0)); |
| 174 | GR_GL_CALL(gl, FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
| 175 | GR_GL_COLOR_ATTACHMENT0, |
| 176 | GR_GL_TEXTURE_2D, testRTTex, 0)); |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame^] | 177 | GrGLenum status; |
| 178 | GR_GL_CALL_RET(gl, status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 179 | GR_GL_CALL(gl, DeleteFramebuffers(1, &testFBO)); |
| 180 | GR_GL_CALL(gl, DeleteTextures(1, &testRTTex)); |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 181 | |
bsalomon@google.com | c312bf9 | 2011-03-21 21:10:33 +0000 | [diff] [blame] | 182 | return status == GR_GL_FRAMEBUFFER_COMPLETE; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 183 | } |
| 184 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 185 | static bool probe_for_npot_render_target_support(const GrGLInterface* gl, |
| 186 | bool hasNPOTTextureSupport) { |
tomhudson@google.com | 747bf29 | 2011-06-14 18:16:52 +0000 | [diff] [blame] | 187 | |
| 188 | /* Experimentation has found that some GLs that support NPOT textures |
| 189 | do not support FBOs with a NPOT texture. They report "unsupported" FBO |
| 190 | status. I don't know how to explicitly query for this. Do an |
| 191 | experiment. Note they may support NPOT with a renderbuffer but not a |
| 192 | texture. Presumably, the implementation bloats the renderbuffer |
| 193 | internally to the next POT. |
| 194 | */ |
| 195 | if (hasNPOTTextureSupport) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 196 | return fbo_test(gl, 200, 200); |
tomhudson@google.com | 747bf29 | 2011-06-14 18:16:52 +0000 | [diff] [blame] | 197 | } |
| 198 | return false; |
| 199 | } |
| 200 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 201 | static int probe_for_min_render_target_height(const GrGLInterface* gl, |
| 202 | bool hasNPOTRenderTargetSupport, |
tomhudson@google.com | 747bf29 | 2011-06-14 18:16:52 +0000 | [diff] [blame] | 203 | int maxRenderTargetSize) { |
| 204 | /* The iPhone 4 has a restriction that for an FBO with texture color |
| 205 | attachment with height <= 8 then the width must be <= height. Here |
| 206 | we look for such a limitation. |
| 207 | */ |
| 208 | if (gPrintStartupSpew) { |
| 209 | GrPrintf("Small height FBO texture experiments\n"); |
| 210 | } |
| 211 | int minRenderTargetHeight = GR_INVAL_GLINT; |
| 212 | for (GrGLuint i = 1; i <= 256; hasNPOTRenderTargetSupport ? ++i : i *= 2) { |
| 213 | GrGLuint w = maxRenderTargetSize; |
| 214 | GrGLuint h = i; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 215 | if (fbo_test(gl, w, h)) { |
tomhudson@google.com | 747bf29 | 2011-06-14 18:16:52 +0000 | [diff] [blame] | 216 | if (gPrintStartupSpew) { |
| 217 | GrPrintf("\t[%d, %d]: PASSED\n", w, h); |
| 218 | } |
| 219 | minRenderTargetHeight = i; |
| 220 | break; |
| 221 | } else { |
| 222 | if (gPrintStartupSpew) { |
| 223 | GrPrintf("\t[%d, %d]: FAILED\n", w, h); |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | GrAssert(GR_INVAL_GLINT != minRenderTargetHeight); |
| 228 | |
| 229 | return minRenderTargetHeight; |
| 230 | } |
| 231 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 232 | static int probe_for_min_render_target_width(const GrGLInterface* gl, |
| 233 | bool hasNPOTRenderTargetSupport, |
| 234 | int maxRenderTargetSize) { |
tomhudson@google.com | 747bf29 | 2011-06-14 18:16:52 +0000 | [diff] [blame] | 235 | |
| 236 | if (gPrintStartupSpew) { |
| 237 | GrPrintf("Small width FBO texture experiments\n"); |
| 238 | } |
| 239 | int minRenderTargetWidth = GR_INVAL_GLINT; |
| 240 | for (GrGLuint i = 1; i <= 256; hasNPOTRenderTargetSupport ? i *= 2 : ++i) { |
| 241 | GrGLuint w = i; |
| 242 | GrGLuint h = maxRenderTargetSize; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 243 | if (fbo_test(gl, w, h)) { |
tomhudson@google.com | 747bf29 | 2011-06-14 18:16:52 +0000 | [diff] [blame] | 244 | if (gPrintStartupSpew) { |
| 245 | GrPrintf("\t[%d, %d]: PASSED\n", w, h); |
| 246 | } |
| 247 | minRenderTargetWidth = i; |
| 248 | break; |
| 249 | } else { |
| 250 | if (gPrintStartupSpew) { |
| 251 | GrPrintf("\t[%d, %d]: FAILED\n", w, h); |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | GrAssert(GR_INVAL_GLINT != minRenderTargetWidth); |
| 256 | |
| 257 | return minRenderTargetWidth; |
| 258 | } |
| 259 | |
| 260 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 261 | GrGpuGL::GrGpuGL(const GrGLInterface* gl, GrGLBinding glBinding) |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 262 | : fStencilFormats(8) { |
| 263 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 264 | gl->ref(); |
| 265 | fGL = gl; |
| 266 | fGLBinding = glBinding; |
| 267 | switch (glBinding) { |
| 268 | case kDesktop_GrGLBinding: |
| 269 | GrAssert(gl->supportsDesktop()); |
| 270 | break; |
| 271 | case kES1_GrGLBinding: |
| 272 | GrAssert(gl->supportsES1()); |
| 273 | break; |
| 274 | case kES2_GrGLBinding: |
| 275 | GrAssert(gl->supportsES2()); |
| 276 | break; |
| 277 | default: |
| 278 | 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] | 279 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 280 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 281 | GrGLClearErr(fGL); |
| 282 | |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame^] | 283 | const GrGLubyte* ext; |
| 284 | GL_CALL_RET(ext, GetString(GR_GL_EXTENSIONS)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 285 | if (gPrintStartupSpew) { |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame^] | 286 | const GrGLubyte* vendor; |
| 287 | const GrGLubyte* renderer; |
| 288 | const GrGLubyte* version; |
| 289 | GL_CALL_RET(vendor, GetString(GR_GL_VENDOR)); |
| 290 | GL_CALL_RET(renderer, GetString(GR_GL_RENDERER)); |
| 291 | GL_CALL_RET(version, GetString(GR_GL_VERSION)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 292 | GrPrintf("------------------------- create GrGpuGL %p --------------\n", |
| 293 | this); |
| 294 | GrPrintf("------ VENDOR %s\n", vendor); |
| 295 | GrPrintf("------ RENDERER %s\n", renderer); |
| 296 | GrPrintf("------ VERSION %s\n", version); |
| 297 | GrPrintf("------ EXTENSIONS\n %s \n", ext); |
| 298 | } |
| 299 | |
| 300 | fGLVersion = gl_version_as_float(gl); |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame^] | 301 | fExtensionString = (const char*) ext; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 302 | |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 303 | this->resetDirtyFlags(); |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 304 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 305 | GrGLint maxTextureUnits; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 306 | // check FS and fixed-function texture unit limits |
| 307 | // we only use textures in the fragment stage currently. |
| 308 | // checks are > to make sure we have a spare unit. |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 309 | if (kES1_GrGLBinding != this->glBinding()) { |
| 310 | GR_GL_GetIntegerv(gl, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits); |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 311 | GrAssert(maxTextureUnits > kNumStages); |
| 312 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 313 | if (kES2_GrGLBinding != this->glBinding()) { |
| 314 | GR_GL_GetIntegerv(gl, GR_GL_MAX_TEXTURE_UNITS, &maxTextureUnits); |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 315 | GrAssert(maxTextureUnits > kNumStages); |
| 316 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 317 | if (kES2_GrGLBinding == this->glBinding()) { |
| 318 | GR_GL_GetIntegerv(gl, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS, |
senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 319 | &fMaxFragmentUniformVectors); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 320 | } else if (kDesktop_GrGLBinding != this->glBinding()) { |
senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 321 | GrGLint max; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 322 | GR_GL_GetIntegerv(gl, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max); |
senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 323 | fMaxFragmentUniformVectors = max / 4; |
| 324 | } else { |
| 325 | fMaxFragmentUniformVectors = 16; |
| 326 | } |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 327 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 328 | //////////////////////////////////////////////////////////////////////////// |
| 329 | // Check for supported features. |
| 330 | |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 331 | this->setupStencilFormats(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 332 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 333 | GrGLint numFormats; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 334 | GR_GL_GetIntegerv(gl, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats); |
bsalomon@google.com | 3582bf9 | 2011-06-30 21:32:31 +0000 | [diff] [blame] | 335 | SkAutoSTMalloc<10, GrGLint> formats(numFormats); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 336 | GR_GL_GetIntegerv(gl, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 337 | for (int i = 0; i < numFormats; ++i) { |
bsalomon@google.com | c312bf9 | 2011-03-21 21:10:33 +0000 | [diff] [blame] | 338 | if (formats[i] == GR_GL_PALETTE8_RGBA8) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 339 | f8bitPaletteSupport = true; |
| 340 | break; |
| 341 | } |
| 342 | } |
reed@google.com | eeeb5a0 | 2010-12-23 15:12:59 +0000 | [diff] [blame] | 343 | |
| 344 | if (gPrintStartupSpew) { |
| 345 | GrPrintf("Palette8 support: %s\n", (f8bitPaletteSupport ? "YES" : "NO")); |
| 346 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 347 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 348 | GR_STATIC_ASSERT(0 == kNone_GrAALevel); |
| 349 | GR_STATIC_ASSERT(1 == kLow_GrAALevel); |
| 350 | GR_STATIC_ASSERT(2 == kMed_GrAALevel); |
| 351 | GR_STATIC_ASSERT(3 == kHigh_GrAALevel); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 352 | |
| 353 | memset(fAASamples, 0, sizeof(fAASamples)); |
| 354 | fMSFBOType = kNone_MSFBO; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 355 | if (kDesktop_GrGLBinding != this->glBinding()) { |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 356 | if (this->hasExtension("GL_CHROMIUM_framebuffer_multisample")) { |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 357 | // chrome's extension is equivalent to the EXT msaa |
bsalomon@google.com | a9ecdad | 2011-03-23 13:50:34 +0000 | [diff] [blame] | 358 | // and fbo_blit extensions. |
| 359 | fMSFBOType = kDesktopEXT_MSFBO; |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 360 | } else if (this->hasExtension("GL_APPLE_framebuffer_multisample")) { |
bsalomon@google.com | a9ecdad | 2011-03-23 13:50:34 +0000 | [diff] [blame] | 361 | fMSFBOType = kAppleES_MSFBO; |
| 362 | } |
| 363 | } else { |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 364 | if ((fGLVersion >= 3.f) || this->hasExtension("GL_ARB_framebuffer_object")) { |
bsalomon@google.com | a9ecdad | 2011-03-23 13:50:34 +0000 | [diff] [blame] | 365 | fMSFBOType = kDesktopARB_MSFBO; |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 366 | } else if (this->hasExtension("GL_EXT_framebuffer_multisample") && |
| 367 | this->hasExtension("GL_EXT_framebuffer_blit")) { |
bsalomon@google.com | a9ecdad | 2011-03-23 13:50:34 +0000 | [diff] [blame] | 368 | fMSFBOType = kDesktopEXT_MSFBO; |
reed@google.com | eeeb5a0 | 2010-12-23 15:12:59 +0000 | [diff] [blame] | 369 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 370 | } |
bsalomon@google.com | a9ecdad | 2011-03-23 13:50:34 +0000 | [diff] [blame] | 371 | if (gPrintStartupSpew) { |
| 372 | switch (fMSFBOType) { |
| 373 | case kNone_MSFBO: |
| 374 | GrPrintf("MSAA Support: NONE\n"); |
| 375 | break; |
| 376 | case kDesktopARB_MSFBO: |
| 377 | GrPrintf("MSAA Support: DESKTOP ARB.\n"); |
| 378 | break; |
| 379 | case kDesktopEXT_MSFBO: |
| 380 | GrPrintf("MSAA Support: DESKTOP EXT.\n"); |
| 381 | break; |
| 382 | case kAppleES_MSFBO: |
| 383 | GrPrintf("MSAA Support: APPLE ES.\n"); |
| 384 | break; |
reed@google.com | eeeb5a0 | 2010-12-23 15:12:59 +0000 | [diff] [blame] | 385 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | if (kNone_MSFBO != fMSFBOType) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 389 | GrGLint maxSamples; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 390 | GR_GL_GetIntegerv(gl, GR_GL_MAX_SAMPLES, &maxSamples); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 391 | if (maxSamples > 1 ) { |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 392 | fAASamples[kNone_GrAALevel] = 0; |
| 393 | fAASamples[kLow_GrAALevel] = GrMax(2, |
| 394 | GrFixedFloorToInt((GR_FixedHalf) * |
| 395 | maxSamples)); |
| 396 | fAASamples[kMed_GrAALevel] = GrMax(2, |
| 397 | GrFixedFloorToInt(((GR_Fixed1*3)/4) * |
| 398 | maxSamples)); |
| 399 | fAASamples[kHigh_GrAALevel] = maxSamples; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 400 | } |
reed@google.com | eeeb5a0 | 2010-12-23 15:12:59 +0000 | [diff] [blame] | 401 | if (gPrintStartupSpew) { |
| 402 | GrPrintf("\tMax Samples: %d\n", maxSamples); |
| 403 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 404 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 405 | fFSAASupport = fAASamples[kHigh_GrAALevel] > 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 406 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 407 | if (kDesktop_GrGLBinding == this->glBinding()) { |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 408 | fHasStencilWrap = (fGLVersion >= 1.4f) || |
| 409 | this->hasExtension("GL_EXT_stencil_wrap"); |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 410 | } else { |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 411 | fHasStencilWrap = (fGLVersion >= 2.0f) || this->hasExtension("GL_OES_stencil_wrap"); |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 412 | } |
reed@google.com | eeeb5a0 | 2010-12-23 15:12:59 +0000 | [diff] [blame] | 413 | if (gPrintStartupSpew) { |
| 414 | GrPrintf("Stencil Wrap: %s\n", (fHasStencilWrap ? "YES" : "NO")); |
| 415 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 416 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 417 | if (kDesktop_GrGLBinding == this->glBinding()) { |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 418 | // we could also look for GL_ATI_separate_stencil extension or |
| 419 | // GL_EXT_stencil_two_side but they use different function signatures |
| 420 | // than GL2.0+ (and than each other). |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 421 | fTwoSidedStencilSupport = (fGLVersion >= 2.f); |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 422 | // supported on GL 1.4 and higher or by extension |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 423 | fStencilWrapOpsSupport = (fGLVersion >= 1.4f) || |
| 424 | this->hasExtension("GL_EXT_stencil_wrap"); |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 425 | } else { |
| 426 | // ES 2 has two sided stencil but 1.1 doesn't. There doesn't seem to be |
| 427 | // an ES1 extension. |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 428 | fTwoSidedStencilSupport = (fGLVersion >= 2.f); |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 429 | // stencil wrap support is in ES2, ES1 requires extension. |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 430 | fStencilWrapOpsSupport = (fGLVersion >= 2.f) || |
| 431 | this->hasExtension("GL_OES_stencil_wrap"); |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 432 | } |
reed@google.com | eeeb5a0 | 2010-12-23 15:12:59 +0000 | [diff] [blame] | 433 | if (gPrintStartupSpew) { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 434 | GrPrintf("Stencil Caps: TwoSide: %s, Wrap: %s\n", |
| 435 | (fTwoSidedStencilSupport ? "YES" : "NO"), |
| 436 | (fStencilWrapOpsSupport ? "YES" : "NO")); |
reed@google.com | eeeb5a0 | 2010-12-23 15:12:59 +0000 | [diff] [blame] | 437 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 438 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 439 | if (kDesktop_GrGLBinding == this->glBinding()) { |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 440 | fRGBA8Renderbuffer = true; |
| 441 | } else { |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 442 | fRGBA8Renderbuffer = this->hasExtension("GL_OES_rgb8_rgba8"); |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 443 | } |
reed@google.com | eeeb5a0 | 2010-12-23 15:12:59 +0000 | [diff] [blame] | 444 | if (gPrintStartupSpew) { |
| 445 | GrPrintf("RGBA Renderbuffer: %s\n", (fRGBA8Renderbuffer ? "YES" : "NO")); |
| 446 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 447 | |
| 448 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 449 | if (kDesktop_GrGLBinding != this->glBinding()) { |
bsalomon@google.com | c312bf9 | 2011-03-21 21:10:33 +0000 | [diff] [blame] | 450 | if (GR_GL_32BPP_COLOR_FORMAT == GR_GL_BGRA) { |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 451 | GrAssert(this->hasExtension("GL_EXT_texture_format_BGRA8888")); |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 455 | if (kDesktop_GrGLBinding == this->glBinding()) { |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 456 | fBufferLockSupport = true; // we require VBO support and the desktop VBO |
| 457 | // extension includes glMapBuffer. |
| 458 | } else { |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 459 | fBufferLockSupport = this->hasExtension("GL_OES_mapbuffer"); |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 460 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 461 | |
reed@google.com | eeeb5a0 | 2010-12-23 15:12:59 +0000 | [diff] [blame] | 462 | if (gPrintStartupSpew) { |
| 463 | GrPrintf("Map Buffer: %s\n", (fBufferLockSupport ? "YES" : "NO")); |
| 464 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 465 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 466 | if (kDesktop_GrGLBinding == this->glBinding()) { |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 467 | if (fGLVersion >= 2.f || |
| 468 | this->hasExtension("GL_ARB_texture_non_power_of_two")) { |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 469 | fNPOTTextureTileSupport = true; |
| 470 | fNPOTTextureSupport = true; |
| 471 | } else { |
| 472 | fNPOTTextureTileSupport = false; |
| 473 | fNPOTTextureSupport = false; |
| 474 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 475 | } else { |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 476 | if (fGLVersion >= 2.f) { |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 477 | fNPOTTextureSupport = true; |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 478 | fNPOTTextureTileSupport = this->hasExtension("GL_OES_texture_npot"); |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 479 | } else { |
| 480 | fNPOTTextureSupport = |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 481 | this->hasExtension("GL_APPLE_texture_2D_limited_npot"); |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 482 | fNPOTTextureTileSupport = false; |
| 483 | } |
bsalomon@google.com | 0748f21 | 2011-02-01 22:56:16 +0000 | [diff] [blame] | 484 | } |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 485 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 486 | fAALineSupport = (kDesktop_GrGLBinding == this->glBinding()); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 487 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 488 | //////////////////////////////////////////////////////////////////////////// |
tomhudson@google.com | 747bf29 | 2011-06-14 18:16:52 +0000 | [diff] [blame] | 489 | // Experiments to determine limitations that can't be queried. |
| 490 | // TODO: Make these a preprocess that generate some compile time constants. |
| 491 | // TODO: probe once at startup, rather than once per context creation. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 492 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 493 | int expectNPOTTargets = gl->fNPOTRenderTargetSupport; |
tomhudson@google.com | e67bd3f | 2011-06-16 14:08:04 +0000 | [diff] [blame] | 494 | if (expectNPOTTargets == kProbe_GrGLCapability) { |
tomhudson@google.com | 747bf29 | 2011-06-14 18:16:52 +0000 | [diff] [blame] | 495 | fNPOTRenderTargetSupport = |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 496 | probe_for_npot_render_target_support(gl, fNPOTTextureSupport); |
tomhudson@google.com | 30e4bb6 | 2011-06-15 19:41:46 +0000 | [diff] [blame] | 497 | } else { |
tomhudson@google.com | e67bd3f | 2011-06-16 14:08:04 +0000 | [diff] [blame] | 498 | GrAssert(expectNPOTTargets == 0 || expectNPOTTargets == 1); |
| 499 | fNPOTRenderTargetSupport = static_cast<bool>(expectNPOTTargets); |
bsalomon@google.com | 0748f21 | 2011-02-01 22:56:16 +0000 | [diff] [blame] | 500 | } |
bsalomon@google.com | 18908aa | 2011-02-07 14:51:55 +0000 | [diff] [blame] | 501 | |
bsalomon@google.com | 0748f21 | 2011-02-01 22:56:16 +0000 | [diff] [blame] | 502 | if (gPrintStartupSpew) { |
| 503 | if (fNPOTTextureSupport) { |
| 504 | GrPrintf("NPOT textures supported\n"); |
| 505 | if (fNPOTTextureTileSupport) { |
| 506 | GrPrintf("NPOT texture tiling supported\n"); |
| 507 | } else { |
| 508 | GrPrintf("NPOT texture tiling NOT supported\n"); |
| 509 | } |
| 510 | if (fNPOTRenderTargetSupport) { |
| 511 | GrPrintf("NPOT render targets supported\n"); |
| 512 | } else { |
| 513 | GrPrintf("NPOT render targets NOT supported\n"); |
reed@google.com | eeeb5a0 | 2010-12-23 15:12:59 +0000 | [diff] [blame] | 514 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 515 | } else { |
bsalomon@google.com | 0748f21 | 2011-02-01 22:56:16 +0000 | [diff] [blame] | 516 | GrPrintf("NPOT textures NOT supported\n"); |
reed@google.com | eeeb5a0 | 2010-12-23 15:12:59 +0000 | [diff] [blame] | 517 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 518 | } |
| 519 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 520 | GR_GL_GetIntegerv(gl, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize); |
| 521 | GR_GL_GetIntegerv(gl, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize); |
tomhudson@google.com | 747bf29 | 2011-06-14 18:16:52 +0000 | [diff] [blame] | 522 | // Our render targets are always created with textures as the color |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 523 | // attachment, hence this min: |
| 524 | fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize); |
bsalomon@google.com | 7aaee00 | 2011-04-11 19:54:04 +0000 | [diff] [blame] | 525 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 526 | fMinRenderTargetHeight = gl->fMinRenderTargetHeight; |
tomhudson@google.com | e67bd3f | 2011-06-16 14:08:04 +0000 | [diff] [blame] | 527 | if (fMinRenderTargetHeight == kProbe_GrGLCapability) { |
tomhudson@google.com | 747bf29 | 2011-06-14 18:16:52 +0000 | [diff] [blame] | 528 | fMinRenderTargetHeight = |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 529 | probe_for_min_render_target_height(gl,fNPOTRenderTargetSupport, |
tomhudson@google.com | 747bf29 | 2011-06-14 18:16:52 +0000 | [diff] [blame] | 530 | fMaxRenderTargetSize); |
reed@google.com | eeeb5a0 | 2010-12-23 15:12:59 +0000 | [diff] [blame] | 531 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 532 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 533 | fMinRenderTargetWidth = gl->fMinRenderTargetWidth; |
tomhudson@google.com | e67bd3f | 2011-06-16 14:08:04 +0000 | [diff] [blame] | 534 | if (fMinRenderTargetWidth == kProbe_GrGLCapability) { |
tomhudson@google.com | 747bf29 | 2011-06-14 18:16:52 +0000 | [diff] [blame] | 535 | fMinRenderTargetWidth = |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 536 | probe_for_min_render_target_width(gl, fNPOTRenderTargetSupport, |
tomhudson@google.com | 747bf29 | 2011-06-14 18:16:52 +0000 | [diff] [blame] | 537 | fMaxRenderTargetSize); |
reed@google.com | eeeb5a0 | 2010-12-23 15:12:59 +0000 | [diff] [blame] | 538 | } |
tomhudson@google.com | 747bf29 | 2011-06-14 18:16:52 +0000 | [diff] [blame] | 539 | |
bsalomon@google.com | fe67652 | 2011-06-17 18:12:21 +0000 | [diff] [blame] | 540 | fLastSuccessfulStencilFmtIdx = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | GrGpuGL::~GrGpuGL() { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 544 | fGL->unref(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 545 | } |
| 546 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 547 | void GrGpuGL::resetContext() { |
| 548 | // We detect cases when blending is effectively off |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 549 | fHWBlendDisabled = false; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 550 | GL_CALL(Enable(GR_GL_BLEND)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 551 | |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 552 | // we don't use the zb at all |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 553 | GL_CALL(Disable(GR_GL_DEPTH_TEST)); |
| 554 | GL_CALL(DepthMask(GR_GL_FALSE)); |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 555 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 556 | GL_CALL(Disable(GR_GL_CULL_FACE)); |
| 557 | GL_CALL(FrontFace(GR_GL_CCW)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 558 | fHWDrawState.fDrawFace = kBoth_DrawFace; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 559 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 560 | GL_CALL(Disable(GR_GL_DITHER)); |
| 561 | if (kDesktop_GrGLBinding == this->glBinding()) { |
| 562 | GL_CALL(Disable(GR_GL_LINE_SMOOTH)); |
| 563 | GL_CALL(Disable(GR_GL_POINT_SMOOTH)); |
| 564 | GL_CALL(Disable(GR_GL_MULTISAMPLE)); |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 565 | fHWAAState.fMSAAEnabled = false; |
| 566 | fHWAAState.fSmoothLineEnabled = false; |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 567 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 568 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 569 | GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 570 | fHWDrawState.fFlagBits = 0; |
| 571 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 572 | // we only ever use lines in hairline mode |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 573 | GL_CALL(LineWidth(1)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 574 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 575 | // invalid |
| 576 | fActiveTextureUnitIdx = -1; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 577 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 578 | // illegal values |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 579 | fHWDrawState.fSrcBlend = (GrBlendCoeff)-1; |
| 580 | fHWDrawState.fDstBlend = (GrBlendCoeff)-1; |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 581 | |
| 582 | fHWDrawState.fBlendConstant = 0x00000000; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 583 | GL_CALL(BlendColor(0,0,0,0)); |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 584 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 585 | fHWDrawState.fColor = GrColor_ILLEGAL; |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 586 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 587 | fHWDrawState.fViewMatrix = GrMatrix::InvalidMatrix(); |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 588 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 589 | for (int s = 0; s < kNumStages; ++s) { |
| 590 | fHWDrawState.fTextures[s] = NULL; |
| 591 | fHWDrawState.fSamplerStates[s].setRadial2Params(-GR_ScalarMax, |
| 592 | -GR_ScalarMax, |
| 593 | true); |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 594 | fHWDrawState.fSamplerStates[s].setMatrix(GrMatrix::InvalidMatrix()); |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 595 | fHWDrawState.fSamplerStates[s].setConvolutionParams(0, NULL, NULL); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 596 | } |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 597 | |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 598 | fHWBounds.fScissorRect.invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 599 | fHWBounds.fScissorEnabled = false; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 600 | GL_CALL(Disable(GR_GL_SCISSOR_TEST)); |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 601 | fHWBounds.fViewportRect.invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 602 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 603 | fHWDrawState.fStencilSettings.invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 604 | fHWStencilClip = false; |
bsalomon@google.com | dea2f8d | 2011-08-01 15:51:05 +0000 | [diff] [blame] | 605 | fClipInStencil = false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 606 | |
| 607 | fHWGeometryState.fIndexBuffer = NULL; |
| 608 | fHWGeometryState.fVertexBuffer = NULL; |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 609 | |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 610 | fHWGeometryState.fArrayPtrsDirty = true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 611 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 612 | GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 613 | fHWDrawState.fRenderTarget = NULL; |
| 614 | } |
| 615 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 616 | GrResource* GrGpuGL::onCreatePlatformSurface(const GrPlatformSurfaceDesc& desc) { |
| 617 | |
| 618 | bool isTexture = kTexture_GrPlatformSurfaceType == desc.fSurfaceType || |
| 619 | kTextureRenderTarget_GrPlatformSurfaceType == desc.fSurfaceType; |
| 620 | bool isRenderTarget = kRenderTarget_GrPlatformSurfaceType == desc.fSurfaceType || |
| 621 | kTextureRenderTarget_GrPlatformSurfaceType == desc.fSurfaceType; |
| 622 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 623 | GrGLRenderTarget::Desc rtDesc; |
bsalomon@google.com | a44f700 | 2011-08-09 15:30:41 +0000 | [diff] [blame] | 624 | SkAutoTUnref<GrGLStencilBuffer> sb; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 625 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 626 | if (isRenderTarget) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 627 | rtDesc.fRTFBOID = desc.fPlatformRenderTarget; |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 628 | rtDesc.fConfig = desc.fConfig; |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 629 | #if GR_USE_PLATFORM_CREATE_SAMPLE_COUNT |
| 630 | if (desc.fSampleCnt) { |
| 631 | #else |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 632 | if (kIsMultisampled_GrPlatformRenderTargetFlagBit & desc.fRenderTargetFlags) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 633 | #endif |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 634 | if (kGrCanResolve_GrPlatformRenderTargetFlagBit & desc.fRenderTargetFlags) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 635 | rtDesc.fTexFBOID = desc.fPlatformResolveDestination; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 636 | } else { |
| 637 | GrAssert(!isTexture); // this should have been filtered by GrContext |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 638 | rtDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 639 | } |
| 640 | } else { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 641 | rtDesc.fTexFBOID = desc.fPlatformRenderTarget; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 642 | } |
| 643 | // we don't know what the RB ids are without glGets and we don't care |
| 644 | // since we aren't responsible for deleting them. |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 645 | rtDesc.fMSColorRenderbufferID = 0; |
| 646 | #if GR_USE_PLATFORM_CREATE_SAMPLE_COUNT |
| 647 | rtDesc.fSampleCnt = desc.fSampleCnt; |
| 648 | #else |
| 649 | if (kIsMultisampled_GrPlatformRenderTargetFlagBit & desc.fRenderTargetFlags) { |
| 650 | // just guess, this code path is only compiled in WK and we aren't |
| 651 | // using MSAA anyway. This will be stripped out soon when WK sets |
| 652 | // the fSampleCnt in GrPlatformSurfaceDesc. |
| 653 | rtDesc.fSampleCnt = 4; |
| 654 | } else { |
| 655 | rtDesc.fSampleCnt = 0; |
| 656 | } |
| 657 | #endif |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 658 | if (desc.fStencilBits) { |
| 659 | GrGLStencilBuffer::Format format; |
| 660 | format.fInternalFormat = GrGLStencilBuffer::kUnknownInternalFormat; |
| 661 | format.fPacked = false; |
| 662 | format.fStencilBits = desc.fStencilBits; |
| 663 | format.fTotalBits = desc.fStencilBits; |
bsalomon@google.com | a44f700 | 2011-08-09 15:30:41 +0000 | [diff] [blame] | 664 | sb.reset(new GrGLStencilBuffer(this, 0, desc.fWidth, desc.fHeight, |
| 665 | rtDesc.fSampleCnt, format)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 666 | } |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 667 | rtDesc.fOwnIDs = false; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | if (isTexture) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 671 | GrGLTexture::Desc texDesc; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 672 | GrGLenum dontCare; |
| 673 | if (!canBeTexture(desc.fConfig, &dontCare, |
| 674 | &texDesc.fUploadFormat, |
| 675 | &texDesc.fUploadType)) { |
| 676 | return NULL; |
| 677 | } |
| 678 | |
| 679 | GrGLTexture::TexParams params; |
| 680 | |
| 681 | texDesc.fAllocWidth = texDesc.fContentWidth = desc.fWidth; |
| 682 | texDesc.fAllocHeight = texDesc.fContentHeight = desc.fHeight; |
| 683 | |
bsalomon@google.com | 9040593 | 2011-06-17 15:56:55 +0000 | [diff] [blame] | 684 | texDesc.fFormat = desc.fConfig; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 685 | texDesc.fOrientation = GrGLTexture::kBottomUp_Orientation; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 686 | texDesc.fTextureID = desc.fPlatformTexture; |
| 687 | texDesc.fUploadByteCount = GrBytesPerPixel(desc.fConfig); |
| 688 | texDesc.fOwnsID = false; |
| 689 | |
| 690 | params.invalidate(); // rather than do glGets. |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 691 | if (isRenderTarget) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 692 | GrTexture* tex = new GrGLTexture(this, texDesc, rtDesc, params); |
bsalomon@google.com | a44f700 | 2011-08-09 15:30:41 +0000 | [diff] [blame] | 693 | tex->asRenderTarget()->setStencilBuffer(sb.get()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 694 | return tex; |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 695 | } else { |
| 696 | return new GrGLTexture(this, texDesc, params); |
| 697 | } |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 698 | } else { |
| 699 | GrGLIRect viewport; |
| 700 | viewport.fLeft = 0; |
| 701 | viewport.fBottom = 0; |
| 702 | viewport.fWidth = desc.fWidth; |
| 703 | viewport.fHeight = desc.fHeight; |
| 704 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 705 | GrGLRenderTarget* rt = new GrGLRenderTarget(this, rtDesc, viewport); |
bsalomon@google.com | a44f700 | 2011-08-09 15:30:41 +0000 | [diff] [blame] | 706 | rt->setStencilBuffer(sb.get()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 707 | return rt; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 708 | } |
| 709 | } |
| 710 | |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 711 | /////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 712 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 713 | static const GrGLuint kUnknownBitCount = ~0; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 714 | |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 715 | void GrGpuGL::setupStencilFormats() { |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 716 | |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 717 | // Build up list of legal stencil formats (though perhaps not supported on |
| 718 | // the particular gpu/driver) from most preferred to least. |
bsalomon@google.com | 3f3ffd6 | 2011-01-18 17:14:52 +0000 | [diff] [blame] | 719 | |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 720 | // these consts are in order of most preferred to least preferred |
| 721 | // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8 |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 722 | static const GrGLStencilBuffer::Format |
| 723 | // internal Format stencil bits total bits packed? |
| 724 | gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false}, |
| 725 | gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false}, |
| 726 | gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true }, |
| 727 | gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false}, |
| 728 | gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false}, |
| 729 | gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true }; |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 730 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 731 | if (kDesktop_GrGLBinding == this->glBinding()) { |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 732 | bool supportsPackedDS = fGLVersion >= 3.0f || |
| 733 | this->hasExtension("GL_EXT_packed_depth_stencil") || |
| 734 | this->hasExtension("GL_ARB_framebuffer_object"); |
| 735 | |
| 736 | // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we |
| 737 | // require FBO support we can expect these are legal formats and don't |
| 738 | // check. These also all support the unsized GL_STENCIL_INDEX. |
| 739 | fStencilFormats.push_back() = gS8; |
| 740 | fStencilFormats.push_back() = gS16; |
| 741 | if (supportsPackedDS) { |
| 742 | fStencilFormats.push_back() = gD24S8; |
| 743 | } |
| 744 | fStencilFormats.push_back() = gS4; |
| 745 | if (supportsPackedDS) { |
| 746 | fStencilFormats.push_back() = gDS; |
| 747 | } |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 748 | } else { |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 749 | // ES2 has STENCIL_INDEX8 without extensions. |
| 750 | // ES1 with GL_OES_framebuffer_object (which we require for ES1) |
| 751 | // introduces tokens for S1 thu S8 but there are separate extensions |
| 752 | // that make them legal (GL_OES_stencil1, ...). |
| 753 | // GL_OES_packed_depth_stencil adds DEPTH24_STENCIL8 |
| 754 | // ES doesn't support using the unsized formats. |
| 755 | |
| 756 | if (fGLVersion >= 2.f || this->hasExtension("GL_OES_stencil8")) { |
| 757 | fStencilFormats.push_back() = gS8; |
| 758 | } |
| 759 | //fStencilFormats.push_back() = gS16; |
| 760 | if (this->hasExtension("GL_OES_packed_depth_stencil")) { |
| 761 | fStencilFormats.push_back() = gD24S8; |
| 762 | } |
| 763 | if (this->hasExtension("GL_OES_stencil4")) { |
| 764 | fStencilFormats.push_back() = gS4; |
| 765 | } |
| 766 | // we require some stencil format. |
| 767 | GrAssert(fStencilFormats.count() > 0); |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 768 | } |
| 769 | } |
| 770 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 771 | //////////////////////////////////////////////////////////////////////////////// |
| 772 | |
| 773 | void GrGpuGL::allocateAndUploadTexData(const GrGLTexture::Desc& desc, |
| 774 | GrGLenum internalFormat, |
| 775 | const void* data, |
| 776 | size_t rowBytes) { |
| 777 | // we assume the texture is bound; |
| 778 | if (!rowBytes) { |
| 779 | rowBytes = desc.fUploadByteCount * desc.fContentWidth; |
| 780 | } |
| 781 | |
| 782 | // in case we need a temporary, trimmed copy of the src pixels |
| 783 | SkAutoSMalloc<128 * 128> tempStorage; |
| 784 | |
| 785 | /* |
| 786 | * check whether to allocate a temporary buffer for flipping y or |
| 787 | * because our data has extra bytes past each row. If so, we need |
| 788 | * to trim those off here, since GL ES doesn't let us specify |
| 789 | * GL_UNPACK_ROW_LENGTH. |
| 790 | */ |
| 791 | bool flipY = GrGLTexture::kBottomUp_Orientation == desc.fOrientation; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 792 | if (kDesktop_GrGLBinding == this->glBinding() && !flipY) { |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 793 | if (data && rowBytes != desc.fContentWidth * desc.fUploadByteCount) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 794 | GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, |
| 795 | rowBytes / desc.fUploadByteCount)); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 796 | } |
| 797 | } else { |
| 798 | size_t trimRowBytes = desc.fContentWidth * desc.fUploadByteCount; |
| 799 | if (data && (trimRowBytes < rowBytes || flipY)) { |
| 800 | // copy the data into our new storage, skipping the trailing bytes |
| 801 | size_t trimSize = desc.fContentHeight * trimRowBytes; |
| 802 | const char* src = (const char*)data; |
| 803 | if (flipY) { |
| 804 | src += (desc.fContentHeight - 1) * rowBytes; |
| 805 | } |
| 806 | char* dst = (char*)tempStorage.realloc(trimSize); |
| 807 | for (int y = 0; y < desc.fContentHeight; y++) { |
| 808 | memcpy(dst, src, trimRowBytes); |
| 809 | if (flipY) { |
| 810 | src -= rowBytes; |
| 811 | } else { |
| 812 | src += rowBytes; |
| 813 | } |
| 814 | dst += trimRowBytes; |
| 815 | } |
| 816 | // now point data to our trimmed version |
| 817 | data = tempStorage.get(); |
| 818 | rowBytes = trimRowBytes; |
| 819 | } |
| 820 | } |
| 821 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 822 | GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, desc.fUploadByteCount)); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 823 | if (kIndex_8_GrPixelConfig == desc.fFormat && |
| 824 | supports8BitPalette()) { |
| 825 | // ES only supports CompressedTexImage2D, not CompressedTexSubimage2D |
| 826 | GrAssert(desc.fContentWidth == desc.fAllocWidth); |
| 827 | GrAssert(desc.fContentHeight == desc.fAllocHeight); |
| 828 | GrGLsizei imageSize = desc.fAllocWidth * desc.fAllocHeight + |
| 829 | kGrColorTableSize; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 830 | GL_CALL(CompressedTexImage2D(GR_GL_TEXTURE_2D, 0, desc.fUploadFormat, |
| 831 | desc.fAllocWidth, desc.fAllocHeight, |
| 832 | 0, imageSize, data)); |
| 833 | GrGLResetRowLength(this->glInterface()); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 834 | } else { |
| 835 | if (NULL != data && (desc.fAllocWidth != desc.fContentWidth || |
| 836 | desc.fAllocHeight != desc.fContentHeight)) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 837 | GL_CALL(TexImage2D(GR_GL_TEXTURE_2D, 0, internalFormat, |
| 838 | desc.fAllocWidth, desc.fAllocHeight, |
| 839 | 0, desc.fUploadFormat, desc.fUploadType, NULL)); |
| 840 | GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, 0, 0, desc.fContentWidth, |
| 841 | desc.fContentHeight, desc.fUploadFormat, |
| 842 | desc.fUploadType, data)); |
| 843 | GrGLResetRowLength(this->glInterface()); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 844 | |
| 845 | int extraW = desc.fAllocWidth - desc.fContentWidth; |
| 846 | int extraH = desc.fAllocHeight - desc.fContentHeight; |
| 847 | int maxTexels = extraW * extraH; |
| 848 | maxTexels = GrMax(extraW * desc.fContentHeight, maxTexels); |
| 849 | maxTexels = GrMax(desc.fContentWidth * extraH, maxTexels); |
| 850 | |
| 851 | SkAutoSMalloc<128*128> texels(desc.fUploadByteCount * maxTexels); |
| 852 | |
| 853 | // rowBytes is actual stride between rows in data |
| 854 | // rowDataBytes is the actual amount of non-pad data in a row |
| 855 | // and the stride used for uploading extraH rows. |
| 856 | uint32_t rowDataBytes = desc.fContentWidth * desc.fUploadByteCount; |
| 857 | if (extraH) { |
| 858 | uint8_t* lastRowStart = (uint8_t*) data + |
| 859 | (desc.fContentHeight - 1) * rowBytes; |
| 860 | uint8_t* extraRowStart = (uint8_t*)texels.get(); |
| 861 | |
| 862 | for (int i = 0; i < extraH; ++i) { |
| 863 | memcpy(extraRowStart, lastRowStart, rowDataBytes); |
| 864 | extraRowStart += rowDataBytes; |
| 865 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 866 | GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, 0, |
| 867 | desc.fContentHeight, desc.fContentWidth, |
| 868 | extraH, desc.fUploadFormat, |
| 869 | desc.fUploadType, texels.get())); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 870 | } |
| 871 | if (extraW) { |
| 872 | uint8_t* edgeTexel = (uint8_t*)data + |
| 873 | rowDataBytes - desc.fUploadByteCount; |
| 874 | uint8_t* extraTexel = (uint8_t*)texels.get(); |
| 875 | for (int j = 0; j < desc.fContentHeight; ++j) { |
| 876 | for (int i = 0; i < extraW; ++i) { |
| 877 | memcpy(extraTexel, edgeTexel, desc.fUploadByteCount); |
| 878 | extraTexel += desc.fUploadByteCount; |
| 879 | } |
| 880 | edgeTexel += rowBytes; |
| 881 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 882 | GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, desc.fContentWidth, |
| 883 | 0, extraW, desc.fContentHeight, |
| 884 | desc.fUploadFormat, desc.fUploadType, |
| 885 | texels.get())); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 886 | } |
| 887 | if (extraW && extraH) { |
| 888 | uint8_t* cornerTexel = (uint8_t*)data + |
| 889 | desc.fContentHeight * rowBytes - |
| 890 | desc.fUploadByteCount; |
| 891 | uint8_t* extraTexel = (uint8_t*)texels.get(); |
| 892 | for (int i = 0; i < extraW*extraH; ++i) { |
| 893 | memcpy(extraTexel, cornerTexel, desc.fUploadByteCount); |
| 894 | extraTexel += desc.fUploadByteCount; |
| 895 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 896 | GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, desc.fContentWidth, |
| 897 | desc.fContentHeight, extraW, extraH, |
| 898 | desc.fUploadFormat, desc.fUploadType, |
| 899 | texels.get())); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 903 | GL_CALL(TexImage2D(GR_GL_TEXTURE_2D, 0, internalFormat, |
| 904 | desc.fAllocWidth, desc.fAllocHeight, 0, |
| 905 | desc.fUploadFormat, desc.fUploadType, data)); |
| 906 | GrGLResetRowLength(this->glInterface()); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 907 | } |
| 908 | } |
| 909 | } |
| 910 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 911 | bool GrGpuGL::createRenderTargetObjects(int width, int height, |
| 912 | GrGLuint texID, |
| 913 | GrGLRenderTarget::Desc* desc) { |
| 914 | desc->fMSColorRenderbufferID = 0; |
| 915 | desc->fRTFBOID = 0; |
| 916 | desc->fTexFBOID = 0; |
| 917 | desc->fOwnIDs = true; |
| 918 | |
| 919 | GrGLenum status; |
| 920 | GrGLint err; |
| 921 | |
bsalomon@google.com | ab15d61 | 2011-08-09 12:57:56 +0000 | [diff] [blame] | 922 | GrGLenum msColorFormat = 0; // suppress warning |
| 923 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 924 | GL_CALL(GenFramebuffers(1, &desc->fTexFBOID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 925 | if (!desc->fTexFBOID) { |
| 926 | goto FAILED; |
| 927 | } |
| 928 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 929 | |
| 930 | // If we are using multisampling we will create two FBOS. We render |
| 931 | // to one and then resolve to the texture bound to the other. |
| 932 | if (desc->fSampleCnt > 1 && kNone_MSFBO != fMSFBOType) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 933 | GL_CALL(GenFramebuffers(1, &desc->fRTFBOID)); |
| 934 | GL_CALL(GenRenderbuffers(1, &desc->fMSColorRenderbufferID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 935 | if (!desc->fRTFBOID || |
| 936 | !desc->fMSColorRenderbufferID || |
| 937 | !this->fboInternalFormat(desc->fConfig, &msColorFormat)) { |
| 938 | goto FAILED; |
| 939 | } |
| 940 | } else { |
| 941 | desc->fRTFBOID = desc->fTexFBOID; |
| 942 | } |
| 943 | |
| 944 | if (desc->fRTFBOID != desc->fTexFBOID) { |
| 945 | GrAssert(desc->fSampleCnt > 1); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 946 | GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 947 | desc->fMSColorRenderbufferID)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 948 | GR_GL_CALL_NOERRCHECK(this->glInterface(), |
| 949 | RenderbufferStorageMultisample(GR_GL_RENDERBUFFER, |
| 950 | desc->fSampleCnt, |
| 951 | msColorFormat, |
| 952 | width, height)); |
| 953 | err = GR_GL_GET_ERROR(this->glInterface()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 954 | if (err != GR_GL_NO_ERROR) { |
| 955 | goto FAILED; |
| 956 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 957 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fRTFBOID)); |
| 958 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 959 | GR_GL_COLOR_ATTACHMENT0, |
| 960 | GR_GL_RENDERBUFFER, |
| 961 | desc->fMSColorRenderbufferID)); |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame^] | 962 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 963 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
| 964 | goto FAILED; |
| 965 | } |
| 966 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 967 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 968 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 969 | GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
| 970 | GR_GL_COLOR_ATTACHMENT0, |
| 971 | GR_GL_TEXTURE_2D, |
| 972 | texID, 0)); |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame^] | 973 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 974 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
| 975 | goto FAILED; |
| 976 | } |
| 977 | |
| 978 | return true; |
| 979 | |
| 980 | FAILED: |
| 981 | if (desc->fMSColorRenderbufferID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 982 | GL_CALL(DeleteRenderbuffers(1, &desc->fMSColorRenderbufferID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 983 | } |
| 984 | if (desc->fRTFBOID != desc->fTexFBOID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 985 | GL_CALL(DeleteFramebuffers(1, &desc->fRTFBOID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 986 | } |
| 987 | if (desc->fTexFBOID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 988 | GL_CALL(DeleteFramebuffers(1, &desc->fTexFBOID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 989 | } |
| 990 | return false; |
| 991 | } |
| 992 | |
bsalomon@google.com | 3f3ffd6 | 2011-01-18 17:14:52 +0000 | [diff] [blame] | 993 | // good to set a break-point here to know when createTexture fails |
| 994 | static GrTexture* return_null_texture() { |
| 995 | // GrAssert(!"null texture"); |
| 996 | return NULL; |
| 997 | } |
| 998 | |
| 999 | #if GR_DEBUG |
| 1000 | static size_t as_size_t(int x) { |
| 1001 | return x; |
| 1002 | } |
| 1003 | #endif |
| 1004 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 1005 | GrTexture* GrGpuGL::onCreateTexture(const GrTextureDesc& desc, |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 1006 | const void* srcData, |
| 1007 | size_t rowBytes) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1008 | |
| 1009 | #if GR_COLLECT_STATS |
| 1010 | ++fStats.fTextureCreateCnt; |
| 1011 | #endif |
reed@google.com | 1fcd51e | 2011-01-05 15:50:27 +0000 | [diff] [blame] | 1012 | |
bsalomon@google.com | da96ea0 | 2010-12-23 16:53:57 +0000 | [diff] [blame] | 1013 | static const GrGLTexture::TexParams DEFAULT_PARAMS = { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1014 | GR_GL_NEAREST, |
| 1015 | GR_GL_CLAMP_TO_EDGE, |
| 1016 | GR_GL_CLAMP_TO_EDGE |
bsalomon@google.com | da96ea0 | 2010-12-23 16:53:57 +0000 | [diff] [blame] | 1017 | }; |
reed@google.com | 1fcd51e | 2011-01-05 15:50:27 +0000 | [diff] [blame] | 1018 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 1019 | GrGLTexture::Desc glTexDesc; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 1020 | GrGLRenderTarget::Desc glRTDesc; |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1021 | GrGLenum internalFormat; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1022 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 1023 | glTexDesc.fContentWidth = desc.fWidth; |
| 1024 | glTexDesc.fContentHeight = desc.fHeight; |
| 1025 | glTexDesc.fAllocWidth = desc.fWidth; |
| 1026 | glTexDesc.fAllocHeight = desc.fHeight; |
| 1027 | glTexDesc.fFormat = desc.fFormat; |
| 1028 | glTexDesc.fOwnsID = true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1029 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 1030 | glRTDesc.fMSColorRenderbufferID = 0; |
| 1031 | glRTDesc.fRTFBOID = 0; |
| 1032 | glRTDesc.fTexFBOID = 0; |
| 1033 | glRTDesc.fOwnIDs = true; |
| 1034 | glRTDesc.fConfig = glTexDesc.fFormat; |
| 1035 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 1036 | bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrTextureFlagBit); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1037 | if (!canBeTexture(desc.fFormat, |
| 1038 | &internalFormat, |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 1039 | &glTexDesc.fUploadFormat, |
| 1040 | &glTexDesc.fUploadType)) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1041 | return return_null_texture(); |
| 1042 | } |
| 1043 | |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 1044 | // We keep GrRenderTargets in GL's normal orientation so that they |
| 1045 | // can be drawn to by the outside world without the client having |
| 1046 | // to render upside down. |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 1047 | glTexDesc.fOrientation = renderTarget ? GrGLTexture::kBottomUp_Orientation : |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1048 | GrGLTexture::kTopDown_Orientation; |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 1049 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1050 | GrAssert(as_size_t(desc.fAALevel) < GR_ARRAY_COUNT(fAASamples)); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 1051 | glRTDesc.fSampleCnt = fAASamples[desc.fAALevel]; |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 1052 | if (kNone_MSFBO == fMSFBOType && desc.fAALevel != kNone_GrAALevel) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1053 | GrPrintf("AA RT requested but not supported on this platform."); |
| 1054 | } |
| 1055 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 1056 | glTexDesc.fUploadByteCount = GrBytesPerPixel(desc.fFormat); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1057 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1058 | if (renderTarget) { |
bsalomon@google.com | 0748f21 | 2011-02-01 22:56:16 +0000 | [diff] [blame] | 1059 | if (!this->npotRenderTargetSupport()) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 1060 | glTexDesc.fAllocWidth = GrNextPow2(desc.fWidth); |
| 1061 | glTexDesc.fAllocHeight = GrNextPow2(desc.fHeight); |
bsalomon@google.com | 0748f21 | 2011-02-01 22:56:16 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 1064 | glTexDesc.fAllocWidth = GrMax(fMinRenderTargetWidth, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1065 | glTexDesc.fAllocWidth); |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 1066 | glTexDesc.fAllocHeight = GrMax(fMinRenderTargetHeight, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1067 | glTexDesc.fAllocHeight); |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 1068 | if (glTexDesc.fAllocWidth > fMaxRenderTargetSize || |
| 1069 | glTexDesc.fAllocHeight > fMaxRenderTargetSize) { |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 1070 | return return_null_texture(); |
| 1071 | } |
bsalomon@google.com | 0748f21 | 2011-02-01 22:56:16 +0000 | [diff] [blame] | 1072 | } else if (!this->npotTextureSupport()) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 1073 | glTexDesc.fAllocWidth = GrNextPow2(desc.fWidth); |
| 1074 | glTexDesc.fAllocHeight = GrNextPow2(desc.fHeight); |
| 1075 | if (glTexDesc.fAllocWidth > fMaxTextureSize || |
| 1076 | glTexDesc.fAllocHeight > fMaxTextureSize) { |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 1077 | return return_null_texture(); |
| 1078 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1081 | GL_CALL(GenTextures(1, &glTexDesc.fTextureID)); |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 1082 | if (!glTexDesc.fTextureID) { |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 1083 | return return_null_texture(); |
| 1084 | } |
| 1085 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 1086 | this->setSpareTextureUnit(); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1087 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTexDesc.fTextureID)); |
| 1088 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1089 | GR_GL_TEXTURE_MAG_FILTER, |
| 1090 | DEFAULT_PARAMS.fFilter)); |
| 1091 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1092 | GR_GL_TEXTURE_MIN_FILTER, |
| 1093 | DEFAULT_PARAMS.fFilter)); |
| 1094 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1095 | GR_GL_TEXTURE_WRAP_S, |
| 1096 | DEFAULT_PARAMS.fWrapS)); |
| 1097 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1098 | GR_GL_TEXTURE_WRAP_T, |
| 1099 | DEFAULT_PARAMS.fWrapT)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1100 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 1101 | this->allocateAndUploadTexData(glTexDesc, internalFormat,srcData, rowBytes); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1102 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1103 | GrGLTexture* tex; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1104 | if (renderTarget) { |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 1105 | GrGLenum msColorRenderbufferFormat = -1; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1106 | #if GR_COLLECT_STATS |
| 1107 | ++fStats.fRenderTargetCreateCnt; |
| 1108 | #endif |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1109 | if (!this->createRenderTargetObjects(glTexDesc.fAllocWidth, |
| 1110 | glTexDesc.fAllocHeight, |
| 1111 | glTexDesc.fTextureID, |
| 1112 | &glRTDesc)) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1113 | GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1114 | return return_null_texture(); |
| 1115 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1116 | tex = new GrGLTexture(this, glTexDesc, glRTDesc, DEFAULT_PARAMS); |
| 1117 | } else { |
| 1118 | tex = new GrGLTexture(this, glTexDesc, DEFAULT_PARAMS); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1119 | } |
| 1120 | #ifdef TRACE_TEXTURE_CREATION |
| 1121 | GrPrintf("--- new texture [%d] size=(%d %d) bpp=%d\n", |
| 1122 | tex->fTextureID, width, height, tex->fUploadByteCount); |
| 1123 | #endif |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1124 | return tex; |
| 1125 | } |
| 1126 | |
| 1127 | namespace { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1128 | void inline get_stencil_rb_sizes(const GrGLInterface* gl, |
| 1129 | GrGLuint rb, |
| 1130 | GrGLStencilBuffer::Format* format) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1131 | // we shouldn't ever know one size and not the other |
| 1132 | GrAssert((kUnknownBitCount == format->fStencilBits) == |
| 1133 | (kUnknownBitCount == format->fTotalBits)); |
| 1134 | if (kUnknownBitCount == format->fStencilBits) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1135 | GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1136 | GR_GL_RENDERBUFFER_STENCIL_SIZE, |
| 1137 | (GrGLint*)&format->fStencilBits); |
| 1138 | if (format->fPacked) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1139 | GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1140 | GR_GL_RENDERBUFFER_DEPTH_SIZE, |
| 1141 | (GrGLint*)&format->fTotalBits); |
| 1142 | format->fTotalBits += format->fStencilBits; |
| 1143 | } else { |
| 1144 | format->fTotalBits = format->fStencilBits; |
| 1145 | } |
| 1146 | } |
| 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | bool GrGpuGL::createStencilBufferForRenderTarget(GrRenderTarget* rt, |
| 1151 | int width, int height) { |
| 1152 | |
| 1153 | // All internally created RTs are also textures. We don't create |
| 1154 | // SBs for a client's standalone RT (that is RT that isnt also a texture). |
| 1155 | GrAssert(rt->asTexture()); |
bsalomon@google.com | 0168afc | 2011-08-08 13:21:05 +0000 | [diff] [blame] | 1156 | GrAssert(width >= rt->allocatedWidth()); |
| 1157 | GrAssert(height >= rt->allocatedHeight()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1158 | |
| 1159 | int samples = rt->numSamples(); |
| 1160 | GrGLuint sbID; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1161 | GL_CALL(GenRenderbuffers(1, &sbID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1162 | if (!sbID) { |
| 1163 | return false; |
| 1164 | } |
| 1165 | |
| 1166 | GrGLStencilBuffer* sb = NULL; |
| 1167 | |
| 1168 | int stencilFmtCnt = fStencilFormats.count(); |
| 1169 | for (int i = 0; i < stencilFmtCnt; ++i) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1170 | GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1171 | // we start with the last stencil format that succeeded in hopes |
| 1172 | // that we won't go through this loop more than once after the |
| 1173 | // first (painful) stencil creation. |
| 1174 | int sIdx = (i + fLastSuccessfulStencilFmtIdx) % stencilFmtCnt; |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 1175 | // 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] | 1176 | // version on a GL that doesn't have an MSAA extension. |
| 1177 | if (samples > 1) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1178 | GR_GL_CALL_NOERRCHECK(this->glInterface(), |
| 1179 | RenderbufferStorageMultisample( |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1180 | GR_GL_RENDERBUFFER, |
| 1181 | samples, |
| 1182 | fStencilFormats[sIdx].fInternalFormat, |
| 1183 | width, |
| 1184 | height)); |
| 1185 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1186 | GR_GL_CALL_NOERRCHECK(this->glInterface(), |
| 1187 | RenderbufferStorage(GR_GL_RENDERBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1188 | fStencilFormats[sIdx].fInternalFormat, |
| 1189 | width, height)); |
| 1190 | } |
| 1191 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1192 | GrGLenum err = GR_GL_GET_ERROR(this->glInterface()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1193 | if (err == GR_GL_NO_ERROR) { |
| 1194 | // After sized formats we attempt an unsized format and take whatever |
| 1195 | // sizes GL gives us. In that case we query for the size. |
| 1196 | GrGLStencilBuffer::Format format = fStencilFormats[sIdx]; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1197 | get_stencil_rb_sizes(this->glInterface(), sbID, &format); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 1198 | sb = new GrGLStencilBuffer(this, sbID, width, height, |
| 1199 | samples, format); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1200 | if (this->attachStencilBufferToRenderTarget(sb, rt)) { |
| 1201 | fLastSuccessfulStencilFmtIdx = sIdx; |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 1202 | rt->setStencilBuffer(sb); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1203 | sb->unref(); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1204 | return true; |
| 1205 | } |
| 1206 | sb->abandon(); // otherwise we lose sbID |
| 1207 | sb->unref(); |
| 1208 | } |
| 1209 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1210 | GL_CALL(DeleteRenderbuffers(1, &sbID)); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 1211 | return false; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | bool GrGpuGL::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, |
| 1215 | GrRenderTarget* rt) { |
| 1216 | GrGLRenderTarget* glrt = (GrGLRenderTarget*) rt; |
| 1217 | |
| 1218 | GrGLuint fbo = glrt->renderFBOID(); |
| 1219 | |
| 1220 | if (NULL == sb) { |
| 1221 | if (NULL != rt->getStencilBuffer()) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1222 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1223 | GR_GL_STENCIL_ATTACHMENT, |
| 1224 | GR_GL_RENDERBUFFER, 0)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1225 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1226 | GR_GL_DEPTH_ATTACHMENT, |
| 1227 | GR_GL_RENDERBUFFER, 0)); |
| 1228 | #if GR_DEBUG |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame^] | 1229 | GrGLenum status; |
| 1230 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1231 | GrAssert(GR_GL_FRAMEBUFFER_COMPLETE == status); |
| 1232 | #endif |
| 1233 | } |
| 1234 | return true; |
| 1235 | } else { |
| 1236 | GrGLStencilBuffer* glsb = (GrGLStencilBuffer*) sb; |
| 1237 | GrGLuint rb = glsb->renderbufferID(); |
| 1238 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1239 | fHWDrawState.fRenderTarget = NULL; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1240 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo)); |
| 1241 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1242 | GR_GL_STENCIL_ATTACHMENT, |
| 1243 | GR_GL_RENDERBUFFER, rb)); |
| 1244 | if (glsb->format().fPacked) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1245 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1246 | GR_GL_DEPTH_ATTACHMENT, |
| 1247 | GR_GL_RENDERBUFFER, rb)); |
| 1248 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1249 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1250 | GR_GL_DEPTH_ATTACHMENT, |
| 1251 | GR_GL_RENDERBUFFER, 0)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1252 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1253 | |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame^] | 1254 | GrGLenum status; |
| 1255 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1256 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1257 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1258 | GR_GL_STENCIL_ATTACHMENT, |
| 1259 | GR_GL_RENDERBUFFER, 0)); |
| 1260 | if (glsb->format().fPacked) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1261 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1262 | GR_GL_DEPTH_ATTACHMENT, |
| 1263 | GR_GL_RENDERBUFFER, 0)); |
| 1264 | } |
| 1265 | return false; |
| 1266 | } else { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1267 | return true; |
| 1268 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1269 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 1272 | //////////////////////////////////////////////////////////////////////////////// |
| 1273 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 1274 | GrVertexBuffer* GrGpuGL::onCreateVertexBuffer(uint32_t size, bool dynamic) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1275 | GrGLuint id; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1276 | GL_CALL(GenBuffers(1, &id)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1277 | if (id) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1278 | GL_CALL(BindBuffer(GR_GL_ARRAY_BUFFER, id)); |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 1279 | fHWGeometryState.fArrayPtrsDirty = true; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1280 | GrGLClearErr(this->glInterface()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1281 | // make sure driver can allocate memory for this buffer |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1282 | GR_GL_CALL_NOERRCHECK(this->glInterface(), |
| 1283 | BufferData(GR_GL_ARRAY_BUFFER, size, NULL, |
| 1284 | dynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW)); |
| 1285 | if (this->glInterface()->fGetError() != GR_GL_NO_ERROR) { |
| 1286 | GL_CALL(DeleteBuffers(1, &id)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1287 | // deleting bound buffer does implicit bind to 0 |
| 1288 | fHWGeometryState.fVertexBuffer = NULL; |
| 1289 | return NULL; |
| 1290 | } |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 1291 | GrGLVertexBuffer* vertexBuffer = new GrGLVertexBuffer(this, id, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1292 | size, dynamic); |
| 1293 | fHWGeometryState.fVertexBuffer = vertexBuffer; |
| 1294 | return vertexBuffer; |
| 1295 | } |
| 1296 | return NULL; |
| 1297 | } |
| 1298 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 1299 | GrIndexBuffer* GrGpuGL::onCreateIndexBuffer(uint32_t size, bool dynamic) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1300 | GrGLuint id; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1301 | GL_CALL(GenBuffers(1, &id)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1302 | if (id) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1303 | GL_CALL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, id)); |
| 1304 | GrGLClearErr(this->glInterface()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1305 | // make sure driver can allocate memory for this buffer |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1306 | GR_GL_CALL_NOERRCHECK(this->glInterface(), |
| 1307 | BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, size, NULL, |
| 1308 | dynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW)); |
| 1309 | if (this->glInterface()->fGetError() != GR_GL_NO_ERROR) { |
| 1310 | GL_CALL(DeleteBuffers(1, &id)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1311 | // deleting bound buffer does implicit bind to 0 |
| 1312 | fHWGeometryState.fIndexBuffer = NULL; |
| 1313 | return NULL; |
| 1314 | } |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 1315 | GrIndexBuffer* indexBuffer = new GrGLIndexBuffer(this, id, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1316 | size, dynamic); |
| 1317 | fHWGeometryState.fIndexBuffer = indexBuffer; |
| 1318 | return indexBuffer; |
| 1319 | } |
| 1320 | return NULL; |
| 1321 | } |
| 1322 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1323 | void GrGpuGL::flushScissor(const GrIRect* rect) { |
| 1324 | GrAssert(NULL != fCurrDrawState.fRenderTarget); |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 1325 | const GrGLIRect& vp = |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1326 | ((GrGLRenderTarget*)fCurrDrawState.fRenderTarget)->getViewport(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1327 | |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 1328 | GrGLIRect scissor; |
| 1329 | if (NULL != rect) { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1330 | scissor.setRelativeTo(vp, rect->fLeft, rect->fTop, |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 1331 | rect->width(), rect->height()); |
| 1332 | if (scissor.contains(vp)) { |
| 1333 | rect = NULL; |
| 1334 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | if (NULL != rect) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1338 | if (fHWBounds.fScissorRect != scissor) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1339 | scissor.pushToGLScissor(this->glInterface()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1340 | fHWBounds.fScissorRect = scissor; |
| 1341 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1342 | if (!fHWBounds.fScissorEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1343 | GL_CALL(Enable(GR_GL_SCISSOR_TEST)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1344 | fHWBounds.fScissorEnabled = true; |
| 1345 | } |
| 1346 | } else { |
| 1347 | if (fHWBounds.fScissorEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1348 | GL_CALL(Disable(GR_GL_SCISSOR_TEST)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1349 | fHWBounds.fScissorEnabled = false; |
| 1350 | } |
| 1351 | } |
| 1352 | } |
| 1353 | |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 1354 | void GrGpuGL::onClear(const GrIRect* rect, GrColor color) { |
bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 1355 | if (NULL == fCurrDrawState.fRenderTarget) { |
| 1356 | return; |
| 1357 | } |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 1358 | GrIRect r; |
| 1359 | if (NULL != rect) { |
| 1360 | // flushScissor expects rect to be clipped to the target. |
| 1361 | r = *rect; |
reed@google.com | 20efde7 | 2011-05-09 17:00:02 +0000 | [diff] [blame] | 1362 | GrIRect rtRect = SkIRect::MakeWH(fCurrDrawState.fRenderTarget->width(), |
| 1363 | fCurrDrawState.fRenderTarget->height()); |
| 1364 | if (r.intersect(rtRect)) { |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 1365 | rect = &r; |
| 1366 | } else { |
| 1367 | return; |
| 1368 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1369 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1370 | this->flushRenderTarget(rect); |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 1371 | this->flushScissor(rect); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1372 | GL_CALL(ColorMask(GR_GL_TRUE,GR_GL_TRUE,GR_GL_TRUE,GR_GL_TRUE)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1373 | fHWDrawState.fFlagBits &= ~kNoColorWrites_StateBit; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1374 | GL_CALL(ClearColor(GrColorUnpackR(color)/255.f, |
| 1375 | GrColorUnpackG(color)/255.f, |
| 1376 | GrColorUnpackB(color)/255.f, |
| 1377 | GrColorUnpackA(color)/255.f)); |
| 1378 | GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
bsalomon@google.com | edc177d | 2011-08-05 15:46:40 +0000 | [diff] [blame] | 1381 | void GrGpuGL::clearStencil() { |
bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 1382 | if (NULL == fCurrDrawState.fRenderTarget) { |
| 1383 | return; |
| 1384 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1385 | |
| 1386 | this->flushRenderTarget(&GrIRect::EmptyIRect()); |
| 1387 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1388 | if (fHWBounds.fScissorEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1389 | GL_CALL(Disable(GR_GL_SCISSOR_TEST)); |
bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 1390 | fHWBounds.fScissorEnabled = false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1391 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1392 | GL_CALL(StencilMask(0xffffffff)); |
| 1393 | GL_CALL(ClearStencil(0)); |
| 1394 | GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1395 | fHWDrawState.fStencilSettings.invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1396 | } |
| 1397 | |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1398 | void GrGpuGL::clearStencilClip(const GrIRect& rect, bool insideClip) { |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 1399 | GrAssert(NULL != fCurrDrawState.fRenderTarget); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1400 | |
| 1401 | // this should only be called internally when we know we have a |
| 1402 | // stencil buffer. |
| 1403 | GrAssert(NULL != fCurrDrawState.fRenderTarget->getStencilBuffer()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1404 | GrGLint stencilBitCount = |
| 1405 | fCurrDrawState.fRenderTarget->getStencilBuffer()->bits(); |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1406 | #if 0 |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1407 | GrAssert(stencilBitCount > 0); |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1408 | GrGLint clipStencilMask = (1 << (stencilBitCount - 1)); |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 1409 | #else |
| 1410 | // 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] | 1411 | // ANGLE a partial stencil mask will cause clears to be |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 1412 | // turned into draws. Our contract on GrDrawTarget says that |
| 1413 | // changing the clip between stencil passes may or may not |
| 1414 | // 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] | 1415 | static const GrGLint clipStencilMask = ~0; |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 1416 | #endif |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1417 | GrGLint value; |
| 1418 | if (insideClip) { |
| 1419 | value = (1 << (stencilBitCount - 1)); |
| 1420 | } else { |
| 1421 | value = 0; |
| 1422 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1423 | this->flushRenderTarget(&GrIRect::EmptyIRect()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1424 | this->flushScissor(&rect); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1425 | GL_CALL(StencilMask(clipStencilMask)); |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1426 | GL_CALL(ClearStencil(value)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1427 | GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1428 | fHWDrawState.fStencilSettings.invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 1431 | void GrGpuGL::onForceRenderTargetFlush() { |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1432 | this->flushRenderTarget(&GrIRect::EmptyIRect()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1433 | } |
| 1434 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1435 | bool GrGpuGL::onReadPixels(GrRenderTarget* target, |
| 1436 | int left, int top, int width, int height, |
| 1437 | GrPixelConfig config, void* buffer) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1438 | GrGLenum internalFormat; // we don't use this for glReadPixels |
| 1439 | GrGLenum format; |
| 1440 | GrGLenum type; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1441 | if (!this->canBeTexture(config, &internalFormat, &format, &type)) { |
| 1442 | return false; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1443 | } |
| 1444 | GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target); |
| 1445 | GrAutoTPtrValueRestore<GrRenderTarget*> autoTargetRestore; |
| 1446 | switch (tgt->getResolveType()) { |
| 1447 | case GrGLRenderTarget::kCantResolve_ResolveType: |
| 1448 | return false; |
| 1449 | case GrGLRenderTarget::kAutoResolves_ResolveType: |
| 1450 | autoTargetRestore.save(&fCurrDrawState.fRenderTarget); |
| 1451 | fCurrDrawState.fRenderTarget = target; |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1452 | this->flushRenderTarget(&GrIRect::EmptyIRect()); |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1453 | break; |
| 1454 | case GrGLRenderTarget::kCanResolve_ResolveType: |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1455 | this->resolveRenderTarget(tgt); |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1456 | // we don't track the state of the READ FBO ID. |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1457 | GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, |
| 1458 | tgt->textureFBOID())); |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1459 | break; |
| 1460 | default: |
| 1461 | GrCrash("Unknown resolve type"); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1464 | const GrGLIRect& glvp = tgt->getViewport(); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1465 | |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 1466 | // the read rect is viewport-relative |
| 1467 | GrGLIRect readRect; |
| 1468 | readRect.setRelativeTo(glvp, left, top, width, height); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1469 | GL_CALL(ReadPixels(readRect.fLeft, readRect.fBottom, |
| 1470 | readRect.fWidth, readRect.fHeight, |
| 1471 | format, type, buffer)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1472 | |
| 1473 | // now reverse the order of the rows, since GL's are bottom-to-top, but our |
| 1474 | // API presents top-to-bottom |
| 1475 | { |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 1476 | size_t stride = width * GrBytesPerPixel(config); |
bsalomon@google.com | 3582bf9 | 2011-06-30 21:32:31 +0000 | [diff] [blame] | 1477 | SkAutoMalloc rowStorage(stride); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1478 | void* tmp = rowStorage.get(); |
| 1479 | |
| 1480 | const int halfY = height >> 1; |
| 1481 | char* top = reinterpret_cast<char*>(buffer); |
| 1482 | char* bottom = top + (height - 1) * stride; |
| 1483 | for (int y = 0; y < halfY; y++) { |
| 1484 | memcpy(tmp, top, stride); |
| 1485 | memcpy(top, bottom, stride); |
| 1486 | memcpy(bottom, tmp, stride); |
| 1487 | top += stride; |
| 1488 | bottom -= stride; |
| 1489 | } |
| 1490 | } |
| 1491 | return true; |
| 1492 | } |
| 1493 | |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1494 | void GrGpuGL::flushRenderTarget(const GrIRect* bound) { |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1495 | |
| 1496 | GrAssert(NULL != fCurrDrawState.fRenderTarget); |
| 1497 | |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1498 | GrGLRenderTarget* rt = (GrGLRenderTarget*)fCurrDrawState.fRenderTarget; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1499 | if (fHWDrawState.fRenderTarget != fCurrDrawState.fRenderTarget) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1500 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID())); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1501 | #if GR_COLLECT_STATS |
| 1502 | ++fStats.fRenderTargetChngCnt; |
| 1503 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1504 | #if GR_DEBUG |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame^] | 1505 | GrGLenum status; |
| 1506 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
bsalomon@google.com | c312bf9 | 2011-03-21 21:10:33 +0000 | [diff] [blame] | 1507 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
reed@google.com | b9255d5 | 2011-06-13 18:54:59 +0000 | [diff] [blame] | 1508 | GrPrintf("GrGpuGL::flushRenderTarget glCheckFramebufferStatus %x\n", status); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1509 | } |
| 1510 | #endif |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 1511 | fDirtyFlags.fRenderTargetChanged = true; |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 1512 | fHWDrawState.fRenderTarget = fCurrDrawState.fRenderTarget; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1513 | const GrGLIRect& vp = rt->getViewport(); |
bsalomon@google.com | 649a862 | 2011-03-10 14:53:38 +0000 | [diff] [blame] | 1514 | if (fHWBounds.fViewportRect != vp) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1515 | vp.pushToGLViewport(this->glInterface()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1516 | fHWBounds.fViewportRect = vp; |
| 1517 | } |
| 1518 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1519 | if (NULL == bound || !bound->isEmpty()) { |
| 1520 | rt->flagAsNeedingResolve(bound); |
| 1521 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1524 | GrGLenum gPrimitiveType2GLMode[] = { |
| 1525 | GR_GL_TRIANGLES, |
| 1526 | GR_GL_TRIANGLE_STRIP, |
| 1527 | GR_GL_TRIANGLE_FAN, |
| 1528 | GR_GL_POINTS, |
| 1529 | GR_GL_LINES, |
| 1530 | GR_GL_LINE_STRIP |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1531 | }; |
| 1532 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1533 | #define SWAP_PER_DRAW 0 |
| 1534 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 1535 | #if SWAP_PER_DRAW |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1536 | #if GR_MAC_BUILD |
| 1537 | #include <AGL/agl.h> |
| 1538 | #elif GR_WIN32_BUILD |
| 1539 | void SwapBuf() { |
| 1540 | DWORD procID = GetCurrentProcessId(); |
| 1541 | HWND hwnd = GetTopWindow(GetDesktopWindow()); |
| 1542 | while(hwnd) { |
| 1543 | DWORD wndProcID = 0; |
| 1544 | GetWindowThreadProcessId(hwnd, &wndProcID); |
| 1545 | if(wndProcID == procID) { |
| 1546 | SwapBuffers(GetDC(hwnd)); |
| 1547 | } |
| 1548 | hwnd = GetNextWindow(hwnd, GW_HWNDNEXT); |
| 1549 | } |
| 1550 | } |
| 1551 | #endif |
| 1552 | #endif |
| 1553 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 1554 | void GrGpuGL::onGpuDrawIndexed(GrPrimitiveType type, |
| 1555 | uint32_t startVertex, |
| 1556 | uint32_t startIndex, |
| 1557 | uint32_t vertexCount, |
| 1558 | uint32_t indexCount) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1559 | GrAssert((size_t)type < GR_ARRAY_COUNT(gPrimitiveType2GLMode)); |
| 1560 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1561 | GrGLvoid* indices = (GrGLvoid*)(sizeof(uint16_t) * startIndex); |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 1562 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 1563 | GrAssert(NULL != fHWGeometryState.fIndexBuffer); |
| 1564 | GrAssert(NULL != fHWGeometryState.fVertexBuffer); |
| 1565 | |
| 1566 | // our setupGeometry better have adjusted this to zero since |
| 1567 | // DrawElements always draws from the begining of the arrays for idx 0. |
| 1568 | GrAssert(0 == startVertex); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1569 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1570 | GL_CALL(DrawElements(gPrimitiveType2GLMode[type], indexCount, |
| 1571 | GR_GL_UNSIGNED_SHORT, indices)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1572 | #if SWAP_PER_DRAW |
| 1573 | glFlush(); |
| 1574 | #if GR_MAC_BUILD |
| 1575 | aglSwapBuffers(aglGetCurrentContext()); |
| 1576 | int set_a_break_pt_here = 9; |
| 1577 | aglSwapBuffers(aglGetCurrentContext()); |
| 1578 | #elif GR_WIN32_BUILD |
| 1579 | SwapBuf(); |
| 1580 | int set_a_break_pt_here = 9; |
| 1581 | SwapBuf(); |
| 1582 | #endif |
| 1583 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1584 | } |
| 1585 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 1586 | void GrGpuGL::onGpuDrawNonIndexed(GrPrimitiveType type, |
| 1587 | uint32_t startVertex, |
| 1588 | uint32_t vertexCount) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1589 | GrAssert((size_t)type < GR_ARRAY_COUNT(gPrimitiveType2GLMode)); |
| 1590 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 1591 | GrAssert(NULL != fHWGeometryState.fVertexBuffer); |
| 1592 | |
| 1593 | // our setupGeometry better have adjusted this to zero. |
| 1594 | // DrawElements doesn't take an offset so we always adjus the startVertex. |
| 1595 | GrAssert(0 == startVertex); |
| 1596 | |
| 1597 | // pass 0 for parameter first. We have to adjust gl*Pointer() to |
| 1598 | // account for startVertex in the DrawElements case. So we always |
| 1599 | // rely on setupGeometry to have accounted for startVertex. |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1600 | GL_CALL(DrawArrays(gPrimitiveType2GLMode[type], 0, vertexCount)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1601 | #if SWAP_PER_DRAW |
| 1602 | glFlush(); |
| 1603 | #if GR_MAC_BUILD |
| 1604 | aglSwapBuffers(aglGetCurrentContext()); |
| 1605 | int set_a_break_pt_here = 9; |
| 1606 | aglSwapBuffers(aglGetCurrentContext()); |
| 1607 | #elif GR_WIN32_BUILD |
| 1608 | SwapBuf(); |
| 1609 | int set_a_break_pt_here = 9; |
| 1610 | SwapBuf(); |
| 1611 | #endif |
| 1612 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1613 | } |
| 1614 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1615 | void GrGpuGL::resolveRenderTarget(GrGLRenderTarget* rt) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1616 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1617 | if (rt->needsResolve()) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1618 | GrAssert(kNone_MSFBO != fMSFBOType); |
| 1619 | GrAssert(rt->textureFBOID() != rt->renderFBOID()); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1620 | GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, |
| 1621 | rt->renderFBOID())); |
| 1622 | GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, |
| 1623 | rt->textureFBOID())); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1624 | #if GR_COLLECT_STATS |
| 1625 | ++fStats.fRenderTargetChngCnt; |
| 1626 | #endif |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1627 | // make sure we go through flushRenderTarget() since we've modified |
| 1628 | // the bound DRAW FBO ID. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1629 | fHWDrawState.fRenderTarget = NULL; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1630 | const GrGLIRect& vp = rt->getViewport(); |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1631 | const GrIRect dirtyRect = rt->getResolveRect(); |
| 1632 | GrGLIRect r; |
| 1633 | r.setRelativeTo(vp, dirtyRect.fLeft, dirtyRect.fTop, |
| 1634 | dirtyRect.width(), dirtyRect.height()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1635 | |
bsalomon@google.com | a9ecdad | 2011-03-23 13:50:34 +0000 | [diff] [blame] | 1636 | if (kAppleES_MSFBO == fMSFBOType) { |
| 1637 | // Apple's extension uses the scissor as the blit bounds. |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1638 | GL_CALL(Enable(GR_GL_SCISSOR_TEST)); |
| 1639 | GL_CALL(Scissor(r.fLeft, r.fBottom, |
| 1640 | r.fWidth, r.fHeight)); |
| 1641 | GL_CALL(ResolveMultisampleFramebuffer()); |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 1642 | fHWBounds.fScissorRect.invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1643 | fHWBounds.fScissorEnabled = true; |
| 1644 | } else { |
bsalomon@google.com | a9ecdad | 2011-03-23 13:50:34 +0000 | [diff] [blame] | 1645 | if (kDesktopARB_MSFBO != fMSFBOType) { |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1646 | // this respects the scissor during the blit, so disable it. |
bsalomon@google.com | a9ecdad | 2011-03-23 13:50:34 +0000 | [diff] [blame] | 1647 | GrAssert(kDesktopEXT_MSFBO == fMSFBOType); |
| 1648 | flushScissor(NULL); |
| 1649 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1650 | int right = r.fLeft + r.fWidth; |
| 1651 | int top = r.fBottom + r.fHeight; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1652 | GL_CALL(BlitFramebuffer(r.fLeft, r.fBottom, right, top, |
| 1653 | r.fLeft, r.fBottom, right, top, |
| 1654 | GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1655 | } |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1656 | rt->flagAsResolved(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1657 | } |
| 1658 | } |
| 1659 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1660 | static const GrGLenum grToGLStencilFunc[] = { |
| 1661 | GR_GL_ALWAYS, // kAlways_StencilFunc |
| 1662 | GR_GL_NEVER, // kNever_StencilFunc |
| 1663 | GR_GL_GREATER, // kGreater_StencilFunc |
| 1664 | GR_GL_GEQUAL, // kGEqual_StencilFunc |
| 1665 | GR_GL_LESS, // kLess_StencilFunc |
| 1666 | GR_GL_LEQUAL, // kLEqual_StencilFunc, |
| 1667 | GR_GL_EQUAL, // kEqual_StencilFunc, |
| 1668 | GR_GL_NOTEQUAL, // kNotEqual_StencilFunc, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1669 | }; |
| 1670 | GR_STATIC_ASSERT(GR_ARRAY_COUNT(grToGLStencilFunc) == kBasicStencilFuncCount); |
| 1671 | GR_STATIC_ASSERT(0 == kAlways_StencilFunc); |
| 1672 | GR_STATIC_ASSERT(1 == kNever_StencilFunc); |
| 1673 | GR_STATIC_ASSERT(2 == kGreater_StencilFunc); |
| 1674 | GR_STATIC_ASSERT(3 == kGEqual_StencilFunc); |
| 1675 | GR_STATIC_ASSERT(4 == kLess_StencilFunc); |
| 1676 | GR_STATIC_ASSERT(5 == kLEqual_StencilFunc); |
| 1677 | GR_STATIC_ASSERT(6 == kEqual_StencilFunc); |
| 1678 | GR_STATIC_ASSERT(7 == kNotEqual_StencilFunc); |
| 1679 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1680 | static const GrGLenum grToGLStencilOp[] = { |
| 1681 | GR_GL_KEEP, // kKeep_StencilOp |
| 1682 | GR_GL_REPLACE, // kReplace_StencilOp |
| 1683 | GR_GL_INCR_WRAP, // kIncWrap_StencilOp |
| 1684 | GR_GL_INCR, // kIncClamp_StencilOp |
| 1685 | GR_GL_DECR_WRAP, // kDecWrap_StencilOp |
| 1686 | GR_GL_DECR, // kDecClamp_StencilOp |
| 1687 | GR_GL_ZERO, // kZero_StencilOp |
| 1688 | GR_GL_INVERT, // kInvert_StencilOp |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1689 | }; |
| 1690 | GR_STATIC_ASSERT(GR_ARRAY_COUNT(grToGLStencilOp) == kStencilOpCount); |
| 1691 | GR_STATIC_ASSERT(0 == kKeep_StencilOp); |
| 1692 | GR_STATIC_ASSERT(1 == kReplace_StencilOp); |
| 1693 | GR_STATIC_ASSERT(2 == kIncWrap_StencilOp); |
| 1694 | GR_STATIC_ASSERT(3 == kIncClamp_StencilOp); |
| 1695 | GR_STATIC_ASSERT(4 == kDecWrap_StencilOp); |
| 1696 | GR_STATIC_ASSERT(5 == kDecClamp_StencilOp); |
| 1697 | GR_STATIC_ASSERT(6 == kZero_StencilOp); |
| 1698 | GR_STATIC_ASSERT(7 == kInvert_StencilOp); |
| 1699 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1700 | void GrGpuGL::flushStencil() { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1701 | const GrStencilSettings* settings = &fCurrDrawState.fStencilSettings; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1702 | |
| 1703 | // use stencil for clipping if clipping is enabled and the clip |
| 1704 | // has been written into the stencil. |
bsalomon@google.com | dea2f8d | 2011-08-01 15:51:05 +0000 | [diff] [blame] | 1705 | bool stencilClip = fClipInStencil && |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1706 | (kClip_StateBit & fCurrDrawState.fFlagBits); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1707 | bool stencilChange = fHWStencilClip != stencilClip || |
| 1708 | fHWDrawState.fStencilSettings != *settings || |
| 1709 | ((fHWDrawState.fFlagBits & kModifyStencilClip_StateBit) != |
| 1710 | (fCurrDrawState.fFlagBits & kModifyStencilClip_StateBit)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1711 | |
| 1712 | if (stencilChange) { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 1713 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1714 | // we can't simultaneously perform stencil-clipping and modify the stencil clip |
| 1715 | GrAssert(!stencilClip || !(fCurrDrawState.fFlagBits & kModifyStencilClip_StateBit)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1716 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1717 | if (settings->isDisabled()) { |
| 1718 | if (stencilClip) { |
| 1719 | settings = &gClipStencilSettings; |
| 1720 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1721 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1722 | |
| 1723 | if (settings->isDisabled()) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1724 | GL_CALL(Disable(GR_GL_STENCIL_TEST)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1725 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1726 | GL_CALL(Enable(GR_GL_STENCIL_TEST)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1727 | #if GR_DEBUG |
| 1728 | if (!fStencilWrapOpsSupport) { |
| 1729 | GrAssert(settings->fFrontPassOp != kIncWrap_StencilOp); |
| 1730 | GrAssert(settings->fFrontPassOp != kDecWrap_StencilOp); |
| 1731 | GrAssert(settings->fFrontFailOp != kIncWrap_StencilOp); |
| 1732 | GrAssert(settings->fBackFailOp != kDecWrap_StencilOp); |
| 1733 | GrAssert(settings->fBackPassOp != kIncWrap_StencilOp); |
| 1734 | GrAssert(settings->fBackPassOp != kDecWrap_StencilOp); |
| 1735 | GrAssert(settings->fBackFailOp != kIncWrap_StencilOp); |
| 1736 | GrAssert(settings->fFrontFailOp != kDecWrap_StencilOp); |
| 1737 | } |
| 1738 | #endif |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1739 | int stencilBits = 0; |
| 1740 | GrStencilBuffer* stencilBuffer = |
| 1741 | fCurrDrawState.fRenderTarget->getStencilBuffer(); |
| 1742 | if (NULL != stencilBuffer) { |
| 1743 | stencilBits = stencilBuffer->bits(); |
| 1744 | } |
| 1745 | // TODO: dynamically attach a stencil buffer |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1746 | GrAssert(stencilBits || |
| 1747 | (GrStencilSettings::gDisabled == |
| 1748 | fCurrDrawState.fStencilSettings)); |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1749 | GrGLuint clipStencilMask = 1 << (stencilBits - 1); |
| 1750 | GrGLuint userStencilMask = clipStencilMask - 1; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1751 | |
| 1752 | unsigned int frontRef = settings->fFrontFuncRef; |
| 1753 | unsigned int frontMask = settings->fFrontFuncMask; |
| 1754 | unsigned int frontWriteMask = settings->fFrontWriteMask; |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1755 | GrGLenum frontFunc; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1756 | |
| 1757 | if (fCurrDrawState.fFlagBits & kModifyStencilClip_StateBit) { |
| 1758 | |
| 1759 | GrAssert(settings->fFrontFunc < kBasicStencilFuncCount); |
| 1760 | frontFunc = grToGLStencilFunc[settings->fFrontFunc]; |
| 1761 | } else { |
| 1762 | frontFunc = grToGLStencilFunc[ConvertStencilFunc(stencilClip, settings->fFrontFunc)]; |
| 1763 | |
| 1764 | ConvertStencilFuncAndMask(settings->fFrontFunc, |
| 1765 | stencilClip, |
| 1766 | clipStencilMask, |
| 1767 | userStencilMask, |
| 1768 | &frontRef, |
| 1769 | &frontMask); |
| 1770 | frontWriteMask &= userStencilMask; |
| 1771 | } |
| 1772 | GrAssert(settings->fFrontFailOp >= 0 && |
bsalomon@google.com | 2022c94 | 2011-03-30 21:43:04 +0000 | [diff] [blame] | 1773 | (unsigned) settings->fFrontFailOp < GR_ARRAY_COUNT(grToGLStencilOp)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1774 | GrAssert(settings->fFrontPassOp >= 0 && |
bsalomon@google.com | 2022c94 | 2011-03-30 21:43:04 +0000 | [diff] [blame] | 1775 | (unsigned) settings->fFrontPassOp < GR_ARRAY_COUNT(grToGLStencilOp)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1776 | GrAssert(settings->fBackFailOp >= 0 && |
bsalomon@google.com | 2022c94 | 2011-03-30 21:43:04 +0000 | [diff] [blame] | 1777 | (unsigned) settings->fBackFailOp < GR_ARRAY_COUNT(grToGLStencilOp)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1778 | GrAssert(settings->fBackPassOp >= 0 && |
bsalomon@google.com | 2022c94 | 2011-03-30 21:43:04 +0000 | [diff] [blame] | 1779 | (unsigned) settings->fBackPassOp < GR_ARRAY_COUNT(grToGLStencilOp)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1780 | if (fTwoSidedStencilSupport) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1781 | GrGLenum backFunc; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1782 | |
| 1783 | unsigned int backRef = settings->fBackFuncRef; |
| 1784 | unsigned int backMask = settings->fBackFuncMask; |
| 1785 | unsigned int backWriteMask = settings->fBackWriteMask; |
| 1786 | |
| 1787 | |
| 1788 | if (fCurrDrawState.fFlagBits & kModifyStencilClip_StateBit) { |
| 1789 | GrAssert(settings->fBackFunc < kBasicStencilFuncCount); |
| 1790 | backFunc = grToGLStencilFunc[settings->fBackFunc]; |
| 1791 | } else { |
| 1792 | backFunc = grToGLStencilFunc[ConvertStencilFunc(stencilClip, settings->fBackFunc)]; |
| 1793 | ConvertStencilFuncAndMask(settings->fBackFunc, |
| 1794 | stencilClip, |
| 1795 | clipStencilMask, |
| 1796 | userStencilMask, |
| 1797 | &backRef, |
| 1798 | &backMask); |
| 1799 | backWriteMask &= userStencilMask; |
| 1800 | } |
| 1801 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1802 | GL_CALL(StencilFuncSeparate(GR_GL_FRONT, frontFunc, |
| 1803 | frontRef, frontMask)); |
| 1804 | GL_CALL(StencilMaskSeparate(GR_GL_FRONT, frontWriteMask)); |
| 1805 | GL_CALL(StencilFuncSeparate(GR_GL_BACK, backFunc, |
| 1806 | backRef, backMask)); |
| 1807 | GL_CALL(StencilMaskSeparate(GR_GL_BACK, backWriteMask)); |
| 1808 | GL_CALL(StencilOpSeparate(GR_GL_FRONT, |
| 1809 | grToGLStencilOp[settings->fFrontFailOp], |
| 1810 | grToGLStencilOp[settings->fFrontPassOp], |
| 1811 | grToGLStencilOp[settings->fFrontPassOp])); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1812 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1813 | GL_CALL(StencilOpSeparate(GR_GL_BACK, |
| 1814 | grToGLStencilOp[settings->fBackFailOp], |
| 1815 | grToGLStencilOp[settings->fBackPassOp], |
| 1816 | grToGLStencilOp[settings->fBackPassOp])); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1817 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1818 | GL_CALL(StencilFunc(frontFunc, frontRef, frontMask)); |
| 1819 | GL_CALL(StencilMask(frontWriteMask)); |
| 1820 | GL_CALL(StencilOp(grToGLStencilOp[settings->fFrontFailOp], |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1821 | grToGLStencilOp[settings->fFrontPassOp], |
| 1822 | grToGLStencilOp[settings->fFrontPassOp])); |
| 1823 | } |
| 1824 | } |
| 1825 | fHWDrawState.fStencilSettings = fCurrDrawState.fStencilSettings; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1826 | fHWStencilClip = stencilClip; |
| 1827 | } |
| 1828 | } |
| 1829 | |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 1830 | void GrGpuGL::flushAAState(GrPrimitiveType type) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1831 | if (kDesktop_GrGLBinding == this->glBinding()) { |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 1832 | // ES doesn't support toggling GL_MULTISAMPLE and doesn't have |
| 1833 | // smooth lines. |
| 1834 | |
| 1835 | // we prefer smooth lines over multisampled lines |
| 1836 | // msaa should be disabled if drawing smooth lines. |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1837 | if (GrIsPrimTypeLines(type)) { |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 1838 | bool smooth = this->willUseHWAALines(); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1839 | if (!fHWAAState.fSmoothLineEnabled && smooth) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1840 | GL_CALL(Enable(GR_GL_LINE_SMOOTH)); |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 1841 | fHWAAState.fSmoothLineEnabled = true; |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1842 | } else if (fHWAAState.fSmoothLineEnabled && !smooth) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1843 | GL_CALL(Disable(GR_GL_LINE_SMOOTH)); |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 1844 | fHWAAState.fSmoothLineEnabled = false; |
| 1845 | } |
| 1846 | if (fCurrDrawState.fRenderTarget->isMultisampled() && |
| 1847 | fHWAAState.fMSAAEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1848 | GL_CALL(Disable(GR_GL_MULTISAMPLE)); |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 1849 | fHWAAState.fMSAAEnabled = false; |
| 1850 | } |
| 1851 | } else if (fCurrDrawState.fRenderTarget->isMultisampled() && |
| 1852 | !!(kAntialias_StateBit & fCurrDrawState.fFlagBits) != |
| 1853 | fHWAAState.fMSAAEnabled) { |
| 1854 | if (fHWAAState.fMSAAEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1855 | GL_CALL(Disable(GR_GL_MULTISAMPLE)); |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 1856 | fHWAAState.fMSAAEnabled = false; |
| 1857 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1858 | GL_CALL(Enable(GR_GL_MULTISAMPLE)); |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 1859 | fHWAAState.fMSAAEnabled = true; |
| 1860 | } |
| 1861 | } |
| 1862 | } |
| 1863 | } |
| 1864 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1865 | void GrGpuGL::flushBlend(GrPrimitiveType type, |
| 1866 | GrBlendCoeff srcCoeff, |
| 1867 | GrBlendCoeff dstCoeff) { |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 1868 | if (GrIsPrimTypeLines(type) && this->willUseHWAALines()) { |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1869 | if (fHWBlendDisabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1870 | GL_CALL(Enable(GR_GL_BLEND)); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1871 | fHWBlendDisabled = false; |
| 1872 | } |
| 1873 | if (kSA_BlendCoeff != fHWDrawState.fSrcBlend || |
| 1874 | kISA_BlendCoeff != fHWDrawState.fDstBlend) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1875 | GL_CALL(BlendFunc(gXfermodeCoeff2Blend[kSA_BlendCoeff], |
| 1876 | gXfermodeCoeff2Blend[kISA_BlendCoeff])); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1877 | fHWDrawState.fSrcBlend = kSA_BlendCoeff; |
| 1878 | fHWDrawState.fDstBlend = kISA_BlendCoeff; |
| 1879 | } |
| 1880 | } else { |
| 1881 | bool blendOff = canDisableBlend(); |
| 1882 | if (fHWBlendDisabled != blendOff) { |
| 1883 | if (blendOff) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1884 | GL_CALL(Disable(GR_GL_BLEND)); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1885 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1886 | GL_CALL(Enable(GR_GL_BLEND)); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1887 | } |
| 1888 | fHWBlendDisabled = blendOff; |
| 1889 | } |
| 1890 | if (!blendOff) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1891 | if (fHWDrawState.fSrcBlend != srcCoeff || |
| 1892 | fHWDrawState.fDstBlend != dstCoeff) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1893 | GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff], |
| 1894 | gXfermodeCoeff2Blend[dstCoeff])); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1895 | fHWDrawState.fSrcBlend = srcCoeff; |
| 1896 | fHWDrawState.fDstBlend = dstCoeff; |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1897 | } |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1898 | if ((BlendCoeffReferencesConstant(srcCoeff) || |
| 1899 | BlendCoeffReferencesConstant(dstCoeff)) && |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1900 | fHWDrawState.fBlendConstant != fCurrDrawState.fBlendConstant) { |
| 1901 | |
| 1902 | float c[] = { |
| 1903 | GrColorUnpackR(fCurrDrawState.fBlendConstant) / 255.f, |
| 1904 | GrColorUnpackG(fCurrDrawState.fBlendConstant) / 255.f, |
| 1905 | GrColorUnpackB(fCurrDrawState.fBlendConstant) / 255.f, |
| 1906 | GrColorUnpackA(fCurrDrawState.fBlendConstant) / 255.f |
| 1907 | }; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1908 | GL_CALL(BlendColor(c[0], c[1], c[2], c[3])); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1909 | fHWDrawState.fBlendConstant = fCurrDrawState.fBlendConstant; |
| 1910 | } |
| 1911 | } |
| 1912 | } |
| 1913 | } |
| 1914 | |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 1915 | static unsigned grToGLFilter(GrSamplerState::Filter filter) { |
| 1916 | switch (filter) { |
| 1917 | case GrSamplerState::kBilinear_Filter: |
| 1918 | case GrSamplerState::k4x4Downsample_Filter: |
| 1919 | return GR_GL_LINEAR; |
| 1920 | case GrSamplerState::kNearest_Filter: |
| 1921 | case GrSamplerState::kConvolution_Filter: |
| 1922 | return GR_GL_NEAREST; |
| 1923 | default: |
| 1924 | GrAssert(!"Unknown filter type"); |
| 1925 | return GR_GL_LINEAR; |
| 1926 | } |
| 1927 | } |
| 1928 | |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 1929 | bool GrGpuGL::flushGLStateCommon(GrPrimitiveType type) { |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1930 | |
| 1931 | // GrGpu::setupClipAndFlushState should have already checked this |
| 1932 | // and bailed if not true. |
| 1933 | GrAssert(NULL != fCurrDrawState.fRenderTarget); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1934 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1935 | for (int s = 0; s < kNumStages; ++s) { |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1936 | // bind texture and set sampler state |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 1937 | if (this->isStageEnabled(s)) { |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1938 | GrGLTexture* nextTexture = (GrGLTexture*)fCurrDrawState.fTextures[s]; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1939 | |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 1940 | // true for now, but maybe not with GrEffect. |
| 1941 | GrAssert(NULL != nextTexture); |
| 1942 | // if we created a rt/tex and rendered to it without using a |
| 1943 | // texture and now we're texuring from the rt it will still be |
| 1944 | // the last bound texture, but it needs resolving. So keep this |
| 1945 | // out of the "last != next" check. |
| 1946 | GrGLRenderTarget* texRT = |
| 1947 | static_cast<GrGLRenderTarget*>(nextTexture->asRenderTarget()); |
| 1948 | if (NULL != texRT) { |
| 1949 | resolveRenderTarget(texRT); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1950 | } |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 1951 | |
| 1952 | if (fHWDrawState.fTextures[s] != nextTexture) { |
| 1953 | setTextureUnit(s); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1954 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, nextTexture->textureID())); |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 1955 | #if GR_COLLECT_STATS |
| 1956 | ++fStats.fTextureChngCnt; |
| 1957 | #endif |
| 1958 | //GrPrintf("---- bindtexture %d\n", nextTexture->textureID()); |
| 1959 | fHWDrawState.fTextures[s] = nextTexture; |
bsalomon@google.com | cd19a5f | 2011-06-15 14:00:23 +0000 | [diff] [blame] | 1960 | // The texture matrix has to compensate for texture width/height |
| 1961 | // and NPOT-embedded-in-POT |
| 1962 | fDirtyFlags.fTextureChangedMask |= (1 << s); |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | const GrSamplerState& sampler = fCurrDrawState.fSamplerStates[s]; |
| 1966 | const GrGLTexture::TexParams& oldTexParams = |
| 1967 | nextTexture->getTexParams(); |
| 1968 | GrGLTexture::TexParams newTexParams; |
| 1969 | |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 1970 | newTexParams.fFilter = grToGLFilter(sampler.getFilter()); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 1971 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1972 | const GrGLenum* wraps = |
| 1973 | GrGLTexture::WrapMode2GLWrap(this->glBinding()); |
| 1974 | newTexParams.fWrapS = wraps[sampler.getWrapX()]; |
| 1975 | newTexParams.fWrapT = wraps[sampler.getWrapY()]; |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 1976 | |
| 1977 | if (newTexParams.fFilter != oldTexParams.fFilter) { |
| 1978 | setTextureUnit(s); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1979 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1980 | GR_GL_TEXTURE_MAG_FILTER, |
| 1981 | newTexParams.fFilter)); |
| 1982 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1983 | GR_GL_TEXTURE_MIN_FILTER, |
| 1984 | newTexParams.fFilter)); |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 1985 | } |
| 1986 | if (newTexParams.fWrapS != oldTexParams.fWrapS) { |
| 1987 | setTextureUnit(s); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1988 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1989 | GR_GL_TEXTURE_WRAP_S, |
| 1990 | newTexParams.fWrapS)); |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 1991 | } |
| 1992 | if (newTexParams.fWrapT != oldTexParams.fWrapT) { |
| 1993 | setTextureUnit(s); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1994 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1995 | GR_GL_TEXTURE_WRAP_T, |
| 1996 | newTexParams.fWrapT)); |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 1997 | } |
| 1998 | nextTexture->setTexParams(newTexParams); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1999 | } |
| 2000 | } |
| 2001 | |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 2002 | GrIRect* rect = NULL; |
| 2003 | GrIRect clipBounds; |
| 2004 | if ((fCurrDrawState.fFlagBits & kClip_StateBit) && |
| 2005 | fClip.hasConservativeBounds()) { |
| 2006 | fClip.getConservativeBounds().roundOut(&clipBounds); |
| 2007 | rect = &clipBounds; |
| 2008 | } |
| 2009 | this->flushRenderTarget(rect); |
| 2010 | this->flushAAState(type); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 2011 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2012 | if ((fCurrDrawState.fFlagBits & kDither_StateBit) != |
| 2013 | (fHWDrawState.fFlagBits & kDither_StateBit)) { |
| 2014 | if (fCurrDrawState.fFlagBits & kDither_StateBit) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2015 | GL_CALL(Enable(GR_GL_DITHER)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2016 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2017 | GL_CALL(Disable(GR_GL_DITHER)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2018 | } |
| 2019 | } |
| 2020 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2021 | if ((fCurrDrawState.fFlagBits & kNoColorWrites_StateBit) != |
| 2022 | (fHWDrawState.fFlagBits & kNoColorWrites_StateBit)) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2023 | GrGLenum mask; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2024 | if (fCurrDrawState.fFlagBits & kNoColorWrites_StateBit) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2025 | mask = GR_GL_FALSE; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2026 | } else { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2027 | mask = GR_GL_TRUE; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2028 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2029 | GL_CALL(ColorMask(mask, mask, mask, mask)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2030 | } |
| 2031 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2032 | if (fHWDrawState.fDrawFace != fCurrDrawState.fDrawFace) { |
| 2033 | switch (fCurrDrawState.fDrawFace) { |
| 2034 | case kCCW_DrawFace: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2035 | GL_CALL(Enable(GR_GL_CULL_FACE)); |
| 2036 | GL_CALL(CullFace(GR_GL_BACK)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2037 | break; |
| 2038 | case kCW_DrawFace: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2039 | GL_CALL(Enable(GR_GL_CULL_FACE)); |
| 2040 | GL_CALL(CullFace(GR_GL_FRONT)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2041 | break; |
| 2042 | case kBoth_DrawFace: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2043 | GL_CALL(Disable(GR_GL_CULL_FACE)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2044 | break; |
| 2045 | default: |
| 2046 | GrCrash("Unknown draw face."); |
| 2047 | } |
| 2048 | fHWDrawState.fDrawFace = fCurrDrawState.fDrawFace; |
| 2049 | } |
| 2050 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2051 | #if GR_DEBUG |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2052 | // check for circular rendering |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2053 | for (int s = 0; s < kNumStages; ++s) { |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 2054 | GrAssert(!this->isStageEnabled(s) || |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2055 | NULL == fCurrDrawState.fRenderTarget || |
| 2056 | NULL == fCurrDrawState.fTextures[s] || |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 2057 | fCurrDrawState.fTextures[s]->asRenderTarget() != |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2058 | fCurrDrawState.fRenderTarget); |
| 2059 | } |
| 2060 | #endif |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 2061 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2062 | flushStencil(); |
| 2063 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2064 | // flushStencil may look at the private state bits, so keep it before this. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2065 | fHWDrawState.fFlagBits = fCurrDrawState.fFlagBits; |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2066 | return true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | void GrGpuGL::notifyVertexBufferBind(const GrGLVertexBuffer* buffer) { |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 2070 | if (fHWGeometryState.fVertexBuffer != buffer) { |
| 2071 | fHWGeometryState.fArrayPtrsDirty = true; |
| 2072 | fHWGeometryState.fVertexBuffer = buffer; |
| 2073 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | void GrGpuGL::notifyVertexBufferDelete(const GrGLVertexBuffer* buffer) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2077 | if (fHWGeometryState.fVertexBuffer == buffer) { |
| 2078 | // deleting bound buffer does implied bind to 0 |
| 2079 | fHWGeometryState.fVertexBuffer = NULL; |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 2080 | fHWGeometryState.fArrayPtrsDirty = true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2081 | } |
| 2082 | } |
| 2083 | |
| 2084 | void GrGpuGL::notifyIndexBufferBind(const GrGLIndexBuffer* buffer) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 2085 | fHWGeometryState.fIndexBuffer = buffer; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | void GrGpuGL::notifyIndexBufferDelete(const GrGLIndexBuffer* buffer) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2089 | if (fHWGeometryState.fIndexBuffer == buffer) { |
| 2090 | // deleting bound buffer does implied bind to 0 |
| 2091 | fHWGeometryState.fIndexBuffer = NULL; |
| 2092 | } |
| 2093 | } |
| 2094 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2095 | void GrGpuGL::notifyRenderTargetDelete(GrRenderTarget* renderTarget) { |
| 2096 | GrAssert(NULL != renderTarget); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2097 | if (fCurrDrawState.fRenderTarget == renderTarget) { |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2098 | fCurrDrawState.fRenderTarget = NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2099 | } |
| 2100 | if (fHWDrawState.fRenderTarget == renderTarget) { |
| 2101 | fHWDrawState.fRenderTarget = NULL; |
| 2102 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | void GrGpuGL::notifyTextureDelete(GrGLTexture* texture) { |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2106 | for (int s = 0; s < kNumStages; ++s) { |
| 2107 | if (fCurrDrawState.fTextures[s] == texture) { |
| 2108 | fCurrDrawState.fTextures[s] = NULL; |
| 2109 | } |
| 2110 | if (fHWDrawState.fTextures[s] == texture) { |
| 2111 | // deleting bound texture does implied bind to 0 |
| 2112 | fHWDrawState.fTextures[s] = NULL; |
| 2113 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2114 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2115 | } |
| 2116 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2117 | bool GrGpuGL::canBeTexture(GrPixelConfig config, |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2118 | GrGLenum* internalFormat, |
| 2119 | GrGLenum* format, |
| 2120 | GrGLenum* type) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2121 | switch (config) { |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2122 | case kRGBA_8888_GrPixelConfig: |
| 2123 | case kRGBX_8888_GrPixelConfig: // todo: can we tell it our X? |
bsalomon@google.com | 2fbc7fa | 2011-01-05 16:34:41 +0000 | [diff] [blame] | 2124 | *format = GR_GL_32BPP_COLOR_FORMAT; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2125 | if (kDesktop_GrGLBinding != this->glBinding()) { |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 2126 | // according to GL_EXT_texture_format_BGRA8888 the *internal* |
| 2127 | // format for a BGRA is BGRA not RGBA (as on desktop) |
| 2128 | *internalFormat = GR_GL_32BPP_COLOR_FORMAT; |
| 2129 | } else { |
| 2130 | *internalFormat = GR_GL_RGBA; |
| 2131 | } |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2132 | *type = GR_GL_UNSIGNED_BYTE; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2133 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2134 | case kRGB_565_GrPixelConfig: |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2135 | *format = GR_GL_RGB; |
| 2136 | *internalFormat = GR_GL_RGB; |
| 2137 | *type = GR_GL_UNSIGNED_SHORT_5_6_5; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2138 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2139 | case kRGBA_4444_GrPixelConfig: |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2140 | *format = GR_GL_RGBA; |
| 2141 | *internalFormat = GR_GL_RGBA; |
| 2142 | *type = GR_GL_UNSIGNED_SHORT_4_4_4_4; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2143 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2144 | case kIndex_8_GrPixelConfig: |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2145 | if (this->supports8BitPalette()) { |
bsalomon@google.com | c312bf9 | 2011-03-21 21:10:33 +0000 | [diff] [blame] | 2146 | *format = GR_GL_PALETTE8_RGBA8; |
| 2147 | *internalFormat = GR_GL_PALETTE8_RGBA8; |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2148 | *type = GR_GL_UNSIGNED_BYTE; // unused I think |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2149 | } else { |
| 2150 | return false; |
| 2151 | } |
| 2152 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2153 | case kAlpha_8_GrPixelConfig: |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2154 | *format = GR_GL_ALPHA; |
| 2155 | *internalFormat = GR_GL_ALPHA; |
| 2156 | *type = GR_GL_UNSIGNED_BYTE; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2157 | break; |
| 2158 | default: |
| 2159 | return false; |
| 2160 | } |
| 2161 | return true; |
| 2162 | } |
| 2163 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2164 | void GrGpuGL::setTextureUnit(int unit) { |
| 2165 | GrAssert(unit >= 0 && unit < kNumStages); |
| 2166 | if (fActiveTextureUnitIdx != unit) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2167 | GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + unit)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2168 | fActiveTextureUnitIdx = unit; |
| 2169 | } |
| 2170 | } |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 2171 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2172 | void GrGpuGL::setSpareTextureUnit() { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2173 | if (fActiveTextureUnitIdx != (GR_GL_TEXTURE0 + SPARE_TEX_UNIT)) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2174 | GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + SPARE_TEX_UNIT)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2175 | fActiveTextureUnitIdx = SPARE_TEX_UNIT; |
| 2176 | } |
| 2177 | } |
| 2178 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2179 | /* On ES the internalFormat and format must match for TexImage and we use |
| 2180 | GL_RGB, GL_RGBA for color formats. We also generally like having the driver |
| 2181 | decide the internalFormat. However, on ES internalFormat for |
| 2182 | RenderBufferStorage* has to be a specific format (not a base format like |
| 2183 | GL_RGBA). |
| 2184 | */ |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2185 | bool GrGpuGL::fboInternalFormat(GrPixelConfig config, GrGLenum* format) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2186 | switch (config) { |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2187 | case kRGBA_8888_GrPixelConfig: |
| 2188 | case kRGBX_8888_GrPixelConfig: |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2189 | if (fRGBA8Renderbuffer) { |
bsalomon@google.com | c312bf9 | 2011-03-21 21:10:33 +0000 | [diff] [blame] | 2190 | *format = GR_GL_RGBA8; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2191 | return true; |
| 2192 | } else { |
| 2193 | return false; |
| 2194 | } |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2195 | case kRGB_565_GrPixelConfig: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2196 | // ES2 supports 565. ES1 supports it |
| 2197 | // with FBO extension desktop GL has |
| 2198 | // no such internal format |
| 2199 | GrAssert(kDesktop_GrGLBinding != this->glBinding()); |
bsalomon@google.com | c312bf9 | 2011-03-21 21:10:33 +0000 | [diff] [blame] | 2200 | *format = GR_GL_RGB565; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2201 | return true; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2202 | case kRGBA_4444_GrPixelConfig: |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2203 | *format = GR_GL_RGBA4; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2204 | return true; |
| 2205 | default: |
| 2206 | return false; |
| 2207 | } |
| 2208 | } |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 2209 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 2210 | void GrGpuGL::resetDirtyFlags() { |
| 2211 | Gr_bzero(&fDirtyFlags, sizeof(fDirtyFlags)); |
| 2212 | } |
| 2213 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2214 | void GrGpuGL::setBuffers(bool indexed, |
| 2215 | int* extraVertexOffset, |
| 2216 | int* extraIndexOffset) { |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 2217 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2218 | GrAssert(NULL != extraVertexOffset); |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 2219 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 2220 | const GeometryPoolState& geoPoolState = this->getGeomPoolState(); |
| 2221 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2222 | GrGLVertexBuffer* vbuf; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 2223 | switch (this->getGeomSrc().fVertexSrc) { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2224 | case kBuffer_GeometrySrcType: |
| 2225 | *extraVertexOffset = 0; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 2226 | vbuf = (GrGLVertexBuffer*) this->getGeomSrc().fVertexBuffer; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2227 | break; |
| 2228 | case kArray_GeometrySrcType: |
| 2229 | case kReserved_GeometrySrcType: |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 2230 | this->finalizeReservedVertices(); |
| 2231 | *extraVertexOffset = geoPoolState.fPoolStartVertex; |
| 2232 | vbuf = (GrGLVertexBuffer*) geoPoolState.fPoolVertexBuffer; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2233 | break; |
| 2234 | default: |
| 2235 | vbuf = NULL; // suppress warning |
| 2236 | GrCrash("Unknown geometry src type!"); |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 2237 | } |
| 2238 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2239 | GrAssert(NULL != vbuf); |
| 2240 | GrAssert(!vbuf->isLocked()); |
| 2241 | if (fHWGeometryState.fVertexBuffer != vbuf) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2242 | GL_CALL(BindBuffer(GR_GL_ARRAY_BUFFER, vbuf->bufferID())); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2243 | fHWGeometryState.fArrayPtrsDirty = true; |
| 2244 | fHWGeometryState.fVertexBuffer = vbuf; |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 2245 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2246 | |
| 2247 | if (indexed) { |
| 2248 | GrAssert(NULL != extraIndexOffset); |
| 2249 | |
| 2250 | GrGLIndexBuffer* ibuf; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 2251 | switch (this->getGeomSrc().fIndexSrc) { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2252 | case kBuffer_GeometrySrcType: |
| 2253 | *extraIndexOffset = 0; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 2254 | ibuf = (GrGLIndexBuffer*)this->getGeomSrc().fIndexBuffer; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2255 | break; |
| 2256 | case kArray_GeometrySrcType: |
| 2257 | case kReserved_GeometrySrcType: |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 2258 | this->finalizeReservedIndices(); |
| 2259 | *extraIndexOffset = geoPoolState.fPoolStartIndex; |
| 2260 | ibuf = (GrGLIndexBuffer*) geoPoolState.fPoolIndexBuffer; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2261 | break; |
| 2262 | default: |
| 2263 | ibuf = NULL; // suppress warning |
| 2264 | GrCrash("Unknown geometry src type!"); |
| 2265 | } |
| 2266 | |
| 2267 | GrAssert(NULL != ibuf); |
| 2268 | GrAssert(!ibuf->isLocked()); |
| 2269 | if (fHWGeometryState.fIndexBuffer != ibuf) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2270 | GL_CALL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, ibuf->bufferID())); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 2271 | fHWGeometryState.fIndexBuffer = ibuf; |
| 2272 | } |
| 2273 | } |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 2274 | } |
senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 2275 | |
| 2276 | int GrGpuGL::getMaxEdges() const { |
| 2277 | // FIXME: This is a pessimistic estimate based on how many other things |
| 2278 | // want to add uniforms. This should be centralized somewhere. |
| 2279 | return GR_CT_MIN(fMaxFragmentUniformVectors - 8, kMaxEdges); |
| 2280 | } |
bsalomon@google.com | fe67652 | 2011-06-17 18:12:21 +0000 | [diff] [blame] | 2281 | |