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