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