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