reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 8 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 9 | #include "GrGpuGL.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 10 | #include "GrGLStencilBuffer.h" |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 11 | #include "GrGLPath.h" |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 12 | #include "GrGLShaderBuilder.h" |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 13 | #include "GrTemplates.h" |
senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 14 | #include "GrTypes.h" |
bsalomon@google.com | 3582bf9 | 2011-06-30 21:32:31 +0000 | [diff] [blame] | 15 | #include "SkTemplates.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 16 | |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 17 | static const GrGLuint GR_MAX_GLUINT = ~0U; |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 18 | static const GrGLint GR_INVAL_GLINT = ~0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 19 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 20 | #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 21 | #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X) |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 22 | |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 23 | // we use a spare texture unit to avoid |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 24 | // mucking with the state of any of the stages. |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 25 | static const int SPARE_TEX_UNIT = GrDrawState::kNumStages; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 26 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 27 | #define SKIP_CACHE_CHECK true |
| 28 | |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 29 | #if GR_GL_CHECK_ALLOC_WITH_GET_ERROR |
| 30 | #define CLEAR_ERROR_BEFORE_ALLOC(iface) GrGLClearErr(iface) |
| 31 | #define GL_ALLOC_CALL(iface, call) GR_GL_CALL_NOERRCHECK(iface, call) |
| 32 | #define CHECK_ALLOC_ERROR(iface) GR_GL_GET_ERROR(iface) |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 33 | #else |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 34 | #define CLEAR_ERROR_BEFORE_ALLOC(iface) |
| 35 | #define GL_ALLOC_CALL(iface, call) GR_GL_CALL(iface, call) |
| 36 | #define CHECK_ALLOC_ERROR(iface) GR_GL_NO_ERROR |
| 37 | #endif |
| 38 | |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 39 | |
| 40 | /////////////////////////////////////////////////////////////////////////////// |
| 41 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 42 | static const GrGLenum gXfermodeCoeff2Blend[] = { |
| 43 | GR_GL_ZERO, |
| 44 | GR_GL_ONE, |
| 45 | GR_GL_SRC_COLOR, |
| 46 | GR_GL_ONE_MINUS_SRC_COLOR, |
| 47 | GR_GL_DST_COLOR, |
| 48 | GR_GL_ONE_MINUS_DST_COLOR, |
| 49 | GR_GL_SRC_ALPHA, |
| 50 | GR_GL_ONE_MINUS_SRC_ALPHA, |
| 51 | GR_GL_DST_ALPHA, |
| 52 | GR_GL_ONE_MINUS_DST_ALPHA, |
| 53 | GR_GL_CONSTANT_COLOR, |
| 54 | GR_GL_ONE_MINUS_CONSTANT_COLOR, |
| 55 | GR_GL_CONSTANT_ALPHA, |
| 56 | GR_GL_ONE_MINUS_CONSTANT_ALPHA, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 57 | |
| 58 | // extended blend coeffs |
| 59 | GR_GL_SRC1_COLOR, |
| 60 | GR_GL_ONE_MINUS_SRC1_COLOR, |
| 61 | GR_GL_SRC1_ALPHA, |
| 62 | GR_GL_ONE_MINUS_SRC1_ALPHA, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 65 | bool GrGpuGL::BlendCoeffReferencesConstant(GrBlendCoeff coeff) { |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 66 | static const bool gCoeffReferencesBlendConst[] = { |
| 67 | false, |
| 68 | false, |
| 69 | false, |
| 70 | false, |
| 71 | false, |
| 72 | false, |
| 73 | false, |
| 74 | false, |
| 75 | false, |
| 76 | false, |
| 77 | true, |
| 78 | true, |
| 79 | true, |
| 80 | true, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 81 | |
| 82 | // extended blend coeffs |
| 83 | false, |
| 84 | false, |
| 85 | false, |
| 86 | false, |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 87 | }; |
| 88 | return gCoeffReferencesBlendConst[coeff]; |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 89 | GR_STATIC_ASSERT(kTotalGrBlendCoeffCount == |
| 90 | GR_ARRAY_COUNT(gCoeffReferencesBlendConst)); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 91 | |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 92 | GR_STATIC_ASSERT(0 == kZero_GrBlendCoeff); |
| 93 | GR_STATIC_ASSERT(1 == kOne_GrBlendCoeff); |
| 94 | GR_STATIC_ASSERT(2 == kSC_GrBlendCoeff); |
| 95 | GR_STATIC_ASSERT(3 == kISC_GrBlendCoeff); |
| 96 | GR_STATIC_ASSERT(4 == kDC_GrBlendCoeff); |
| 97 | GR_STATIC_ASSERT(5 == kIDC_GrBlendCoeff); |
| 98 | GR_STATIC_ASSERT(6 == kSA_GrBlendCoeff); |
| 99 | GR_STATIC_ASSERT(7 == kISA_GrBlendCoeff); |
| 100 | GR_STATIC_ASSERT(8 == kDA_GrBlendCoeff); |
| 101 | GR_STATIC_ASSERT(9 == kIDA_GrBlendCoeff); |
| 102 | GR_STATIC_ASSERT(10 == kConstC_GrBlendCoeff); |
| 103 | GR_STATIC_ASSERT(11 == kIConstC_GrBlendCoeff); |
| 104 | GR_STATIC_ASSERT(12 == kConstA_GrBlendCoeff); |
| 105 | GR_STATIC_ASSERT(13 == kIConstA_GrBlendCoeff); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 106 | |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 107 | GR_STATIC_ASSERT(14 == kS2C_GrBlendCoeff); |
| 108 | GR_STATIC_ASSERT(15 == kIS2C_GrBlendCoeff); |
| 109 | GR_STATIC_ASSERT(16 == kS2A_GrBlendCoeff); |
| 110 | GR_STATIC_ASSERT(17 == kIS2A_GrBlendCoeff); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 111 | |
| 112 | // assertion for gXfermodeCoeff2Blend have to be in GrGpu scope |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 113 | GR_STATIC_ASSERT(kTotalGrBlendCoeffCount == |
| 114 | GR_ARRAY_COUNT(gXfermodeCoeff2Blend)); |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 115 | } |
| 116 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 117 | /////////////////////////////////////////////////////////////////////////////// |
| 118 | |
rileya@google.com | e38160c | 2012-07-03 18:03:04 +0000 | [diff] [blame] | 119 | static bool gPrintStartupSpew; |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 120 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 121 | static bool fbo_test(const GrGLInterface* gl, int w, int h) { |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 122 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 123 | GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE0 + SPARE_TEX_UNIT)); |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 124 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 125 | GrGLuint testFBO; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 126 | GR_GL_CALL(gl, GenFramebuffers(1, &testFBO)); |
| 127 | GR_GL_CALL(gl, BindFramebuffer(GR_GL_FRAMEBUFFER, testFBO)); |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 128 | GrGLuint testRTTex; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 129 | GR_GL_CALL(gl, GenTextures(1, &testRTTex)); |
| 130 | GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, testRTTex)); |
bsalomon@google.com | 2fbc7fa | 2011-01-05 16:34:41 +0000 | [diff] [blame] | 131 | // some implementations require texture to be mip-map complete before |
| 132 | // FBO with level 0 bound as color attachment will be framebuffer complete. |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 133 | GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 134 | GR_GL_TEXTURE_MIN_FILTER, |
| 135 | GR_GL_NEAREST)); |
| 136 | GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RGBA, w, h, |
| 137 | 0, GR_GL_RGBA, GR_GL_UNSIGNED_BYTE, NULL)); |
| 138 | GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, 0)); |
| 139 | GR_GL_CALL(gl, FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
| 140 | GR_GL_COLOR_ATTACHMENT0, |
| 141 | GR_GL_TEXTURE_2D, testRTTex, 0)); |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 142 | GrGLenum status; |
| 143 | GR_GL_CALL_RET(gl, status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 144 | GR_GL_CALL(gl, DeleteFramebuffers(1, &testFBO)); |
| 145 | GR_GL_CALL(gl, DeleteTextures(1, &testRTTex)); |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 146 | |
bsalomon@google.com | c312bf9 | 2011-03-21 21:10:33 +0000 | [diff] [blame] | 147 | return status == GR_GL_FRAMEBUFFER_COMPLETE; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 148 | } |
| 149 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 150 | GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context) |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 151 | : GrGpu(context) |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 152 | , fGLContext(ctx) { |
bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 153 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 154 | GrAssert(ctx.isInitialized()); |
tomhudson@google.com | 747bf29 | 2011-06-14 18:16:52 +0000 | [diff] [blame] | 155 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 156 | fCaps.reset(SkRef(ctx.info().caps())); |
| 157 | |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 158 | fillInConfigRenderableTable(); |
| 159 | |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 160 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 161 | GrGLClearErr(fGLContext.interface()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 162 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 163 | if (gPrintStartupSpew) { |
bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 164 | const GrGLubyte* ext; |
| 165 | GL_CALL_RET(ext, GetString(GR_GL_EXTENSIONS)); |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 166 | const GrGLubyte* vendor; |
| 167 | const GrGLubyte* renderer; |
| 168 | const GrGLubyte* version; |
| 169 | GL_CALL_RET(vendor, GetString(GR_GL_VENDOR)); |
| 170 | GL_CALL_RET(renderer, GetString(GR_GL_RENDERER)); |
| 171 | GL_CALL_RET(version, GetString(GR_GL_VERSION)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 172 | GrPrintf("------------------------- create GrGpuGL %p --------------\n", |
| 173 | this); |
| 174 | GrPrintf("------ VENDOR %s\n", vendor); |
| 175 | GrPrintf("------ RENDERER %s\n", renderer); |
| 176 | GrPrintf("------ VERSION %s\n", version); |
| 177 | GrPrintf("------ EXTENSIONS\n %s \n", ext); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 178 | ctx.info().caps()->print(); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 179 | } |
| 180 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 181 | fProgramCache = SkNEW_ARGS(ProgramCache, (this->glContext())); |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 182 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame^] | 183 | GrAssert(this->glCaps().maxVertexAttributes() >= GrDrawState::kMaxVertexAttribCnt); |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 184 | |
bsalomon@google.com | fe67652 | 2011-06-17 18:12:21 +0000 | [diff] [blame] | 185 | fLastSuccessfulStencilFmtIdx = 0; |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 186 | if (false) { // avoid bit rot, suppress warning |
| 187 | fbo_test(this->glInterface(), 0, 0); |
| 188 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | GrGpuGL::~GrGpuGL() { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 192 | if (0 != fHWProgramID) { |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 193 | // detach the current program so there is no confusion on OpenGL's part |
| 194 | // that we want it to be deleted |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 195 | GrAssert(fHWProgramID == fCurrentProgram->programID()); |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 196 | GL_CALL(UseProgram(0)); |
| 197 | } |
| 198 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 199 | delete fProgramCache; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 200 | |
bsalomon@google.com | 4a018bb | 2011-10-28 19:50:21 +0000 | [diff] [blame] | 201 | // This must be called by before the GrDrawTarget destructor |
| 202 | this->releaseGeometry(); |
bsalomon@google.com | 15b11df | 2011-09-16 21:18:29 +0000 | [diff] [blame] | 203 | // This subclass must do this before the base class destructor runs |
| 204 | // since we will unref the GrGLInterface. |
| 205 | this->releaseResources(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 206 | } |
| 207 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 208 | /////////////////////////////////////////////////////////////////////////////// |
| 209 | |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 210 | void GrGpuGL::fillInConfigRenderableTable() { |
| 211 | |
| 212 | // OpenGL < 3.0 |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 213 | // no support for render targets unless the GL_ARB_framebuffer_object |
| 214 | // extension is supported (in which case we get ALPHA, RED, RG, RGB, |
| 215 | // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 216 | // probably don't get R8 in this case. |
| 217 | |
| 218 | // OpenGL 3.0 |
| 219 | // base color renderable: ALPHA, RED, RG, RGB, and RGBA |
| 220 | // sized derivatives: ALPHA8, R8, RGBA4, RGBA8 |
| 221 | |
| 222 | // >= OpenGL 3.1 |
| 223 | // base color renderable: RED, RG, RGB, and RGBA |
| 224 | // sized derivatives: R8, RGBA4, RGBA8 |
| 225 | // if the GL_ARB_compatibility extension is supported then we get back |
| 226 | // support for GL_ALPHA and ALPHA8 |
| 227 | |
| 228 | // GL_EXT_bgra adds BGRA render targets to any version |
| 229 | |
| 230 | // ES 2.0 |
| 231 | // color renderable: RGBA4, RGB5_A1, RGB565 |
| 232 | // GL_EXT_texture_rg adds support for R8 as a color render target |
| 233 | // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8 |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 234 | // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 235 | |
| 236 | if (kDesktop_GrGLBinding == this->glBinding()) { |
| 237 | // Post 3.0 we will get R8 |
| 238 | // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object) |
| 239 | if (this->glVersion() >= GR_GL_VER(3,0) || |
| 240 | this->hasExtension("GL_ARB_framebuffer_object")) { |
| 241 | fConfigRenderSupport[kAlpha_8_GrPixelConfig] = true; |
| 242 | } |
| 243 | } else { |
| 244 | // On ES we can only hope for R8 |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 245 | fConfigRenderSupport[kAlpha_8_GrPixelConfig] = |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 246 | this->glCaps().textureRedSupport(); |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | if (kDesktop_GrGLBinding != this->glBinding()) { |
| 250 | // only available in ES |
| 251 | fConfigRenderSupport[kRGB_565_GrPixelConfig] = true; |
| 252 | } |
| 253 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 254 | // Pre 3.0, Ganesh relies on either GL_ARB_framebuffer_object or |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 255 | // GL_EXT_framebuffer_object for FBO support. Both of these |
| 256 | // allow RGBA4 render targets so this is always supported. |
| 257 | fConfigRenderSupport[kRGBA_4444_GrPixelConfig] = true; |
| 258 | |
| 259 | if (this->glCaps().rgba8RenderbufferSupport()) { |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 260 | fConfigRenderSupport[kRGBA_8888_GrPixelConfig] = true; |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | if (this->glCaps().bgraFormatSupport()) { |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 264 | fConfigRenderSupport[kBGRA_8888_GrPixelConfig] = true; |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 265 | } |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 266 | } |
| 267 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 268 | namespace { |
| 269 | GrPixelConfig preferred_pixel_ops_config(GrPixelConfig config) { |
| 270 | if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == config) { |
| 271 | return kBGRA_8888_GrPixelConfig; |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 272 | } else { |
| 273 | return config; |
| 274 | } |
| 275 | } |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | GrPixelConfig GrGpuGL::preferredReadPixelsConfig(GrPixelConfig config) const { |
| 279 | return preferred_pixel_ops_config(config); |
| 280 | } |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 281 | |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 282 | GrPixelConfig GrGpuGL::preferredWritePixelsConfig(GrPixelConfig config) const { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 283 | return preferred_pixel_ops_config(config); |
| 284 | } |
| 285 | |
| 286 | bool GrGpuGL::canWriteTexturePixels(const GrTexture* texture, GrPixelConfig srcConfig) const { |
| 287 | if (kIndex_8_GrPixelConfig == srcConfig || kIndex_8_GrPixelConfig == texture->config()) { |
| 288 | return false; |
| 289 | } |
| 290 | if (srcConfig != texture->config() && kES2_GrGLBinding == this->glBinding()) { |
| 291 | // In general ES2 requires the internal format of the texture and the format of the src |
| 292 | // pixels to match. However, It may or may not be possible to upload BGRA data to a RGBA |
| 293 | // texture. It depends upon which extension added BGRA. The Apple extension allows it |
| 294 | // (BGRA's internal format is RGBA) while the EXT extension does not (BGRA is its own |
| 295 | // internal format). |
| 296 | if (this->glCaps().bgraFormatSupport() && |
| 297 | !this->glCaps().bgraIsInternalFormat() && |
| 298 | kBGRA_8888_GrPixelConfig == srcConfig && |
| 299 | kRGBA_8888_GrPixelConfig == texture->config()) { |
| 300 | return true; |
| 301 | } else { |
| 302 | return false; |
| 303 | } |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 304 | } else { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 305 | return true; |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 306 | } |
| 307 | } |
| 308 | |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 309 | bool GrGpuGL::fullReadPixelsIsFasterThanPartial() const { |
| 310 | return SkToBool(GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL); |
| 311 | } |
| 312 | |
bsalomon@google.com | 1bf1c21 | 2011-11-05 12:18:58 +0000 | [diff] [blame] | 313 | void GrGpuGL::onResetContext() { |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 314 | |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 315 | // we don't use the zb at all |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 316 | GL_CALL(Disable(GR_GL_DEPTH_TEST)); |
| 317 | GL_CALL(DepthMask(GR_GL_FALSE)); |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 318 | |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 319 | fHWDrawFace = GrDrawState::kInvalid_DrawFace; |
| 320 | fHWDitherEnabled = kUnknown_TriState; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 321 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 322 | if (kDesktop_GrGLBinding == this->glBinding()) { |
bsalomon@google.com | 469d0dd | 2012-05-21 20:14:29 +0000 | [diff] [blame] | 323 | // Desktop-only state that we never change |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame] | 324 | if (!this->glCaps().isCoreProfile()) { |
| 325 | GL_CALL(Disable(GR_GL_POINT_SMOOTH)); |
| 326 | GL_CALL(Disable(GR_GL_LINE_SMOOTH)); |
| 327 | GL_CALL(Disable(GR_GL_POLYGON_SMOOTH)); |
| 328 | GL_CALL(Disable(GR_GL_POLYGON_STIPPLE)); |
| 329 | GL_CALL(Disable(GR_GL_COLOR_LOGIC_OP)); |
| 330 | GL_CALL(Disable(GR_GL_INDEX_LOGIC_OP)); |
| 331 | } |
commit-bot@chromium.org | dd4400b | 2013-03-21 19:58:22 +0000 | [diff] [blame] | 332 | // The windows NVIDIA driver has GL_ARB_imaging in the extension string when using a core |
| 333 | // profile. This seems like a bug since the core spec removes any mention of GL_ARB_imaging. |
| 334 | if (this->glCaps().imagingSupport() && !this->glCaps().isCoreProfile()) { |
bsalomon@google.com | e76b7cc | 2012-06-18 12:47:06 +0000 | [diff] [blame] | 335 | GL_CALL(Disable(GR_GL_COLOR_TABLE)); |
| 336 | } |
bsalomon@google.com | 469d0dd | 2012-05-21 20:14:29 +0000 | [diff] [blame] | 337 | GL_CALL(Disable(GR_GL_POLYGON_OFFSET_FILL)); |
| 338 | // Since ES doesn't support glPointSize at all we always use the VS to |
| 339 | // set the point size |
| 340 | GL_CALL(Enable(GR_GL_VERTEX_PROGRAM_POINT_SIZE)); |
| 341 | |
| 342 | // We should set glPolygonMode(FRONT_AND_BACK,FILL) here, too. It isn't |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 343 | // currently part of our gl interface. There are probably others as |
bsalomon@google.com | 469d0dd | 2012-05-21 20:14:29 +0000 | [diff] [blame] | 344 | // well. |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 345 | } |
bsalomon@google.com | 4d5f3fe | 2012-05-21 17:11:44 +0000 | [diff] [blame] | 346 | fHWAAState.invalidate(); |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 347 | fHWWriteToColor = kUnknown_TriState; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 348 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 349 | // we only ever use lines in hairline mode |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 350 | GL_CALL(LineWidth(1)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 351 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 352 | // invalid |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 353 | fHWActiveTextureUnitIdx = -1; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 354 | |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 355 | fHWBlendState.invalidate(); |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 356 | |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 357 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
bsalomon@google.com | c811ea3 | 2012-05-21 15:33:09 +0000 | [diff] [blame] | 358 | fHWBoundTextures[s] = NULL; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 359 | } |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 360 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 361 | fHWScissorSettings.invalidate(); |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 362 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 363 | fHWViewport.invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 364 | |
bsalomon@google.com | 457b8a3 | 2012-05-21 21:19:58 +0000 | [diff] [blame] | 365 | fHWStencilSettings.invalidate(); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 366 | fHWStencilTestEnabled = kUnknown_TriState; |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 367 | |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 368 | fHWGeometryState.invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 369 | |
bsalomon@google.com | c811ea3 | 2012-05-21 15:33:09 +0000 | [diff] [blame] | 370 | fHWBoundRenderTarget = NULL; |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 371 | |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 372 | fHWPathStencilMatrixState.invalidate(); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 373 | if (this->caps()->pathStencilingSupport()) { |
bsalomon@google.com | 05a718c | 2012-06-29 14:01:53 +0000 | [diff] [blame] | 374 | // we don't use the model view matrix. |
| 375 | GL_CALL(MatrixMode(GR_GL_MODELVIEW)); |
| 376 | GL_CALL(LoadIdentity()); |
| 377 | } |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 378 | |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 379 | // we assume these values |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 380 | if (this->glCaps().unpackRowLengthSupport()) { |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 381 | GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
| 382 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 383 | if (this->glCaps().packRowLengthSupport()) { |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 384 | GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); |
| 385 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 386 | if (this->glCaps().unpackFlipYSupport()) { |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 387 | GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); |
| 388 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 389 | if (this->glCaps().packFlipYSupport()) { |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 390 | GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, GR_GL_FALSE)); |
| 391 | } |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 392 | |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 393 | fHWProgramID = 0; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 394 | fSharedGLProgramState.invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 395 | } |
| 396 | |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 397 | namespace { |
| 398 | |
| 399 | GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget) { |
| 400 | // By default, GrRenderTargets are GL's normal orientation so that they |
| 401 | // can be drawn to by the outside world without the client having |
| 402 | // to render upside down. |
| 403 | if (kDefault_GrSurfaceOrigin == origin) { |
| 404 | return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin; |
| 405 | } else { |
| 406 | return origin; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | } |
| 411 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 412 | GrTexture* GrGpuGL::onWrapBackendTexture(const GrBackendTextureDesc& desc) { |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 413 | if (!this->configToGLFormats(desc.fConfig, false, NULL, NULL, NULL)) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 414 | return NULL; |
| 415 | } |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 416 | |
robertphillips@google.com | b72e5d3 | 2012-10-30 15:18:10 +0000 | [diff] [blame] | 417 | if (0 == desc.fTextureHandle) { |
| 418 | return NULL; |
| 419 | } |
| 420 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 421 | int maxSize = this->caps()->maxTextureSize(); |
robertphillips@google.com | b72e5d3 | 2012-10-30 15:18:10 +0000 | [diff] [blame] | 422 | if (desc.fWidth > maxSize || desc.fHeight > maxSize) { |
| 423 | return NULL; |
| 424 | } |
| 425 | |
| 426 | GrGLTexture::Desc glTexDesc; |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 427 | // next line relies on GrBackendTextureDesc's flags matching GrTexture's |
robertphillips@google.com | 3271628 | 2012-06-04 12:48:45 +0000 | [diff] [blame] | 428 | glTexDesc.fFlags = (GrTextureFlags) desc.fFlags; |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 429 | glTexDesc.fWidth = desc.fWidth; |
| 430 | glTexDesc.fHeight = desc.fHeight; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 431 | glTexDesc.fConfig = desc.fConfig; |
robertphillips@google.com | 3271628 | 2012-06-04 12:48:45 +0000 | [diff] [blame] | 432 | glTexDesc.fSampleCnt = desc.fSampleCnt; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 433 | glTexDesc.fTextureID = static_cast<GrGLuint>(desc.fTextureHandle); |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 434 | glTexDesc.fIsWrapped = true; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 435 | bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrBackendTextureFlag); |
| 436 | // FIXME: this should be calling resolve_origin(), but Chrome code is currently |
| 437 | // assuming the old behaviour, which is that backend textures are always |
| 438 | // BottomLeft, even for non-RT's. Once Chrome is fixed, change this to: |
| 439 | // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); |
| 440 | if (kDefault_GrSurfaceOrigin == desc.fOrigin) { |
| 441 | glTexDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 442 | } else { |
| 443 | glTexDesc.fOrigin = desc.fOrigin; |
| 444 | } |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 445 | |
| 446 | GrGLTexture* texture = NULL; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 447 | if (renderTarget) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 448 | GrGLRenderTarget::Desc glRTDesc; |
| 449 | glRTDesc.fRTFBOID = 0; |
| 450 | glRTDesc.fTexFBOID = 0; |
| 451 | glRTDesc.fMSColorRenderbufferID = 0; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 452 | glRTDesc.fConfig = desc.fConfig; |
| 453 | glRTDesc.fSampleCnt = desc.fSampleCnt; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 454 | glRTDesc.fOrigin = glTexDesc.fOrigin; |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 455 | if (!this->createRenderTargetObjects(glTexDesc.fWidth, |
| 456 | glTexDesc.fHeight, |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 457 | glTexDesc.fTextureID, |
| 458 | &glRTDesc)) { |
| 459 | return NULL; |
| 460 | } |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 461 | texture = SkNEW_ARGS(GrGLTexture, (this, glTexDesc, glRTDesc)); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 462 | } else { |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 463 | texture = SkNEW_ARGS(GrGLTexture, (this, glTexDesc)); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 464 | } |
| 465 | if (NULL == texture) { |
| 466 | return NULL; |
| 467 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 468 | |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 469 | this->setSpareTextureUnit(); |
| 470 | return texture; |
| 471 | } |
| 472 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 473 | GrRenderTarget* GrGpuGL::onWrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 474 | GrGLRenderTarget::Desc glDesc; |
| 475 | glDesc.fConfig = desc.fConfig; |
| 476 | glDesc.fRTFBOID = static_cast<GrGLuint>(desc.fRenderTargetHandle); |
| 477 | glDesc.fMSColorRenderbufferID = 0; |
| 478 | glDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; |
| 479 | glDesc.fSampleCnt = desc.fSampleCnt; |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 480 | glDesc.fIsWrapped = true; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 481 | glDesc.fOrigin = desc.fOrigin; |
| 482 | if (glDesc.fRTFBOID == 0) { |
| 483 | GrAssert(desc.fOrigin == kBottomLeft_GrSurfaceOrigin); |
| 484 | } |
| 485 | |
| 486 | glDesc.fOrigin = resolve_origin(desc.fOrigin, true); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 487 | GrGLIRect viewport; |
| 488 | viewport.fLeft = 0; |
| 489 | viewport.fBottom = 0; |
| 490 | viewport.fWidth = desc.fWidth; |
| 491 | viewport.fHeight = desc.fHeight; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 492 | |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 493 | GrRenderTarget* tgt = SkNEW_ARGS(GrGLRenderTarget, |
| 494 | (this, glDesc, viewport)); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 495 | if (desc.fStencilBits) { |
| 496 | GrGLStencilBuffer::Format format; |
| 497 | format.fInternalFormat = GrGLStencilBuffer::kUnknownInternalFormat; |
| 498 | format.fPacked = false; |
| 499 | format.fStencilBits = desc.fStencilBits; |
| 500 | format.fTotalBits = desc.fStencilBits; |
bsalomon@google.com | 1f0f1a3 | 2013-01-23 21:32:32 +0000 | [diff] [blame] | 501 | static const bool kIsSBWrapped = false; |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 502 | GrGLStencilBuffer* sb = SkNEW_ARGS(GrGLStencilBuffer, |
| 503 | (this, |
bsalomon@google.com | 1f0f1a3 | 2013-01-23 21:32:32 +0000 | [diff] [blame] | 504 | kIsSBWrapped, |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 505 | 0, |
| 506 | desc.fWidth, |
| 507 | desc.fHeight, |
| 508 | desc.fSampleCnt, |
| 509 | format)); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 510 | tgt->setStencilBuffer(sb); |
| 511 | sb->unref(); |
| 512 | } |
| 513 | return tgt; |
| 514 | } |
| 515 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 516 | //////////////////////////////////////////////////////////////////////////////// |
| 517 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 518 | bool GrGpuGL::onWriteTexturePixels(GrTexture* texture, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 519 | int left, int top, int width, int height, |
| 520 | GrPixelConfig config, const void* buffer, |
| 521 | size_t rowBytes) { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 522 | if (NULL == buffer) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 523 | return false; |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 524 | } |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 525 | GrGLTexture* glTex = static_cast<GrGLTexture*>(texture); |
| 526 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 527 | this->setSpareTextureUnit(); |
| 528 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTex->textureID())); |
| 529 | GrGLTexture::Desc desc; |
robertphillips@google.com | 3271628 | 2012-06-04 12:48:45 +0000 | [diff] [blame] | 530 | desc.fFlags = glTex->desc().fFlags; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 531 | desc.fWidth = glTex->width(); |
| 532 | desc.fHeight = glTex->height(); |
robertphillips@google.com | 3271628 | 2012-06-04 12:48:45 +0000 | [diff] [blame] | 533 | desc.fConfig = glTex->config(); |
| 534 | desc.fSampleCnt = glTex->desc().fSampleCnt; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 535 | desc.fTextureID = glTex->textureID(); |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame] | 536 | desc.fOrigin = glTex->origin(); |
bsalomon@google.com | 9d6cfd8 | 2011-11-05 13:25:21 +0000 | [diff] [blame] | 537 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 538 | return this->uploadTexData(desc, false, |
| 539 | left, top, width, height, |
| 540 | config, buffer, rowBytes); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 541 | } |
| 542 | |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 543 | namespace { |
| 544 | bool adjust_pixel_ops_params(int surfaceWidth, |
| 545 | int surfaceHeight, |
| 546 | size_t bpp, |
| 547 | int* left, int* top, int* width, int* height, |
| 548 | const void** data, |
| 549 | size_t* rowBytes) { |
| 550 | if (!*rowBytes) { |
| 551 | *rowBytes = *width * bpp; |
| 552 | } |
| 553 | |
| 554 | GrIRect subRect = GrIRect::MakeXYWH(*left, *top, *width, *height); |
| 555 | GrIRect bounds = GrIRect::MakeWH(surfaceWidth, surfaceHeight); |
| 556 | |
| 557 | if (!subRect.intersect(bounds)) { |
| 558 | return false; |
| 559 | } |
| 560 | *data = reinterpret_cast<const void*>(reinterpret_cast<intptr_t>(*data) + |
| 561 | (subRect.fTop - *top) * *rowBytes + (subRect.fLeft - *left) * bpp); |
| 562 | |
| 563 | *left = subRect.fLeft; |
| 564 | *top = subRect.fTop; |
| 565 | *width = subRect.width(); |
| 566 | *height = subRect.height(); |
| 567 | return true; |
| 568 | } |
| 569 | } |
| 570 | |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 571 | bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc, |
| 572 | bool isNewTexture, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 573 | int left, int top, int width, int height, |
| 574 | GrPixelConfig dataConfig, |
| 575 | const void* data, |
| 576 | size_t rowBytes) { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 577 | GrAssert(NULL != data || isNewTexture); |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 578 | |
| 579 | size_t bpp = GrBytesPerPixel(dataConfig); |
| 580 | if (!adjust_pixel_ops_params(desc.fWidth, desc.fHeight, bpp, &left, &top, |
| 581 | &width, &height, &data, &rowBytes)) { |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 582 | return false; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 583 | } |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 584 | size_t trimRowBytes = width * bpp; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 585 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 586 | // in case we need a temporary, trimmed copy of the src pixels |
| 587 | SkAutoSMalloc<128 * 128> tempStorage; |
| 588 | |
bsalomon@google.com | 313f019 | 2012-07-10 17:21:02 +0000 | [diff] [blame] | 589 | // paletted textures cannot be partially updated |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 590 | bool useTexStorage = isNewTexture && |
bsalomon@google.com | 313f019 | 2012-07-10 17:21:02 +0000 | [diff] [blame] | 591 | desc.fConfig != kIndex_8_GrPixelConfig && |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 592 | this->glCaps().texStorageSupport(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 593 | |
bsalomon@google.com | 313f019 | 2012-07-10 17:21:02 +0000 | [diff] [blame] | 594 | if (useTexStorage && kDesktop_GrGLBinding == this->glBinding()) { |
| 595 | // 565 is not a sized internal format on desktop GL. So on desktop with |
| 596 | // 565 we always use an unsized internal format to let the system pick |
| 597 | // the best sized format to convert the 565 data to. Since TexStorage |
| 598 | // only allows sized internal formats we will instead use TexImage2D. |
| 599 | useTexStorage = desc.fConfig != kRGB_565_GrPixelConfig; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | GrGLenum internalFormat; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 603 | GrGLenum externalFormat; |
| 604 | GrGLenum externalType; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 605 | // glTexStorage requires sized internal formats on both desktop and ES. ES |
| 606 | // glTexImage requires an unsized format. |
| 607 | if (!this->configToGLFormats(dataConfig, useTexStorage, &internalFormat, |
| 608 | &externalFormat, &externalType)) { |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 609 | return false; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 610 | } |
| 611 | |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 612 | if (!isNewTexture && GR_GL_PALETTE8_RGBA8 == internalFormat) { |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 613 | // paletted textures cannot be updated |
| 614 | return false; |
| 615 | } |
| 616 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 617 | /* |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 618 | * check whether to allocate a temporary buffer for flipping y or |
| 619 | * because our srcData has extra bytes past each row. If so, we need |
| 620 | * to trim those off here, since GL ES may not let us specify |
| 621 | * GL_UNPACK_ROW_LENGTH. |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 622 | */ |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 623 | bool restoreGLRowLength = false; |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 624 | bool swFlipY = false; |
| 625 | bool glFlipY = false; |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 626 | if (NULL != data) { |
senorblanco@chromium.org | ef5dbe1 | 2013-01-28 16:42:38 +0000 | [diff] [blame] | 627 | if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 628 | if (this->glCaps().unpackFlipYSupport()) { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 629 | glFlipY = true; |
| 630 | } else { |
| 631 | swFlipY = true; |
| 632 | } |
| 633 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 634 | if (this->glCaps().unpackRowLengthSupport() && !swFlipY) { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 635 | // can't use this for flipping, only non-neg values allowed. :( |
| 636 | if (rowBytes != trimRowBytes) { |
| 637 | GrGLint rowLength = static_cast<GrGLint>(rowBytes / bpp); |
| 638 | GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, rowLength)); |
| 639 | restoreGLRowLength = true; |
| 640 | } |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 641 | } else { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 642 | if (trimRowBytes != rowBytes || swFlipY) { |
| 643 | // copy data into our new storage, skipping the trailing bytes |
| 644 | size_t trimSize = height * trimRowBytes; |
| 645 | const char* src = (const char*)data; |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 646 | if (swFlipY) { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 647 | src += (height - 1) * rowBytes; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 648 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 649 | char* dst = (char*)tempStorage.reset(trimSize); |
| 650 | for (int y = 0; y < height; y++) { |
| 651 | memcpy(dst, src, trimRowBytes); |
| 652 | if (swFlipY) { |
| 653 | src -= rowBytes; |
| 654 | } else { |
| 655 | src += rowBytes; |
| 656 | } |
| 657 | dst += trimRowBytes; |
| 658 | } |
| 659 | // now point data to our copied version |
| 660 | data = tempStorage.get(); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 661 | } |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 662 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 663 | if (glFlipY) { |
| 664 | GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE)); |
| 665 | } |
| 666 | GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, static_cast<GrGLint>(bpp))); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 667 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 668 | bool succeeded = true; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 669 | if (isNewTexture && |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 670 | 0 == left && 0 == top && |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 671 | desc.fWidth == width && desc.fHeight == height) { |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 672 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 673 | if (useTexStorage) { |
| 674 | // We never resize or change formats of textures. We don't use |
| 675 | // mipmaps currently. |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 676 | GL_ALLOC_CALL(this->glInterface(), |
| 677 | TexStorage2D(GR_GL_TEXTURE_2D, |
| 678 | 1, // levels |
| 679 | internalFormat, |
| 680 | desc.fWidth, desc.fHeight)); |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 681 | } else { |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 682 | if (GR_GL_PALETTE8_RGBA8 == internalFormat) { |
| 683 | GrGLsizei imageSize = desc.fWidth * desc.fHeight + |
| 684 | kGrColorTableSize; |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 685 | GL_ALLOC_CALL(this->glInterface(), |
| 686 | CompressedTexImage2D(GR_GL_TEXTURE_2D, |
| 687 | 0, // level |
| 688 | internalFormat, |
| 689 | desc.fWidth, desc.fHeight, |
| 690 | 0, // border |
| 691 | imageSize, |
| 692 | data)); |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 693 | } else { |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 694 | GL_ALLOC_CALL(this->glInterface(), |
| 695 | TexImage2D(GR_GL_TEXTURE_2D, |
| 696 | 0, // level |
| 697 | internalFormat, |
| 698 | desc.fWidth, desc.fHeight, |
| 699 | 0, // border |
| 700 | externalFormat, externalType, |
| 701 | data)); |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 702 | } |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 703 | } |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 704 | GrGLenum error = CHECK_ALLOC_ERROR(this->glInterface()); |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 705 | if (error != GR_GL_NO_ERROR) { |
| 706 | succeeded = false; |
| 707 | } else { |
| 708 | // if we have data and we used TexStorage to create the texture, we |
| 709 | // now upload with TexSubImage. |
| 710 | if (NULL != data && useTexStorage) { |
| 711 | GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, |
| 712 | 0, // level |
| 713 | left, top, |
| 714 | width, height, |
| 715 | externalFormat, externalType, |
| 716 | data)); |
| 717 | } |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 718 | } |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 719 | } else { |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 720 | if (swFlipY || glFlipY) { |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 721 | top = desc.fHeight - (top + height); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 722 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 723 | GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, |
| 724 | 0, // level |
| 725 | left, top, |
| 726 | width, height, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 727 | externalFormat, externalType, data)); |
| 728 | } |
| 729 | |
| 730 | if (restoreGLRowLength) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 731 | GrAssert(this->glCaps().unpackRowLengthSupport()); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 732 | GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 733 | } |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 734 | if (glFlipY) { |
| 735 | GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); |
| 736 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 737 | return succeeded; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 738 | } |
| 739 | |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 740 | namespace { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 741 | bool renderbuffer_storage_msaa(GrGLContext& ctx, |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 742 | int sampleCount, |
| 743 | GrGLenum format, |
| 744 | int width, int height) { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 745 | CLEAR_ERROR_BEFORE_ALLOC(ctx.interface()); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 746 | GrAssert(GrGLCaps::kNone_MSFBOType != ctx.info().caps()->msFBOType()); |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 747 | bool created = false; |
| 748 | if (GrGLCaps::kNVDesktop_CoverageAAType == |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 749 | ctx.info().caps()->coverageAAType()) { |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 750 | const GrGLCaps::MSAACoverageMode& mode = |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 751 | ctx.info().caps()->getMSAACoverageMode(sampleCount); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 752 | GL_ALLOC_CALL(ctx.interface(), |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 753 | RenderbufferStorageMultisampleCoverage(GR_GL_RENDERBUFFER, |
| 754 | mode.fCoverageSampleCnt, |
| 755 | mode.fColorSampleCnt, |
| 756 | format, |
| 757 | width, height)); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 758 | created = (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface())); |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 759 | } |
| 760 | if (!created) { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 761 | GL_ALLOC_CALL(ctx.interface(), |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 762 | RenderbufferStorageMultisample(GR_GL_RENDERBUFFER, |
| 763 | sampleCount, |
| 764 | format, |
| 765 | width, height)); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 766 | created = (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface())); |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 767 | } |
| 768 | return created; |
| 769 | } |
| 770 | } |
| 771 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 772 | bool GrGpuGL::createRenderTargetObjects(int width, int height, |
| 773 | GrGLuint texID, |
| 774 | GrGLRenderTarget::Desc* desc) { |
| 775 | desc->fMSColorRenderbufferID = 0; |
| 776 | desc->fRTFBOID = 0; |
| 777 | desc->fTexFBOID = 0; |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 778 | desc->fIsWrapped = false; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 779 | |
| 780 | GrGLenum status; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 781 | |
bsalomon@google.com | ab15d61 | 2011-08-09 12:57:56 +0000 | [diff] [blame] | 782 | GrGLenum msColorFormat = 0; // suppress warning |
| 783 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 784 | GL_CALL(GenFramebuffers(1, &desc->fTexFBOID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 785 | if (!desc->fTexFBOID) { |
| 786 | goto FAILED; |
| 787 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 788 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 789 | |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 790 | // If we are using multisampling we will create two FBOS. We render to one and then resolve to |
| 791 | // the texture bound to the other. The exception is the IMG multisample extension. With this |
| 792 | // extension the texture is multisampled when rendered to and then auto-resolves it when it is |
| 793 | // rendered from. |
| 794 | if (desc->fSampleCnt > 0 && GrGLCaps::kImaginationES_MSFBOType != this->glCaps().msFBOType()) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 795 | if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType()) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 796 | goto FAILED; |
| 797 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 798 | GL_CALL(GenFramebuffers(1, &desc->fRTFBOID)); |
| 799 | GL_CALL(GenRenderbuffers(1, &desc->fMSColorRenderbufferID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 800 | if (!desc->fRTFBOID || |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 801 | !desc->fMSColorRenderbufferID || |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 802 | !this->configToGLFormats(desc->fConfig, |
| 803 | // GLES requires sized internal formats |
| 804 | kES2_GrGLBinding == this->glBinding(), |
| 805 | &msColorFormat, NULL, NULL)) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 806 | goto FAILED; |
| 807 | } |
| 808 | } else { |
| 809 | desc->fRTFBOID = desc->fTexFBOID; |
| 810 | } |
| 811 | |
bsalomon@google.com | 0e9b41a | 2012-01-04 22:11:43 +0000 | [diff] [blame] | 812 | // below here we may bind the FBO |
bsalomon@google.com | c811ea3 | 2012-05-21 15:33:09 +0000 | [diff] [blame] | 813 | fHWBoundRenderTarget = NULL; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 814 | if (desc->fRTFBOID != desc->fTexFBOID) { |
bsalomon@google.com | 13ac3a3 | 2013-01-09 23:29:39 +0000 | [diff] [blame] | 815 | GrAssert(desc->fSampleCnt > 0); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 816 | GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 817 | desc->fMSColorRenderbufferID)); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 818 | if (!renderbuffer_storage_msaa(fGLContext, |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 819 | desc->fSampleCnt, |
| 820 | msColorFormat, |
| 821 | width, height)) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 822 | goto FAILED; |
| 823 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 824 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fRTFBOID)); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 825 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 826 | GR_GL_COLOR_ATTACHMENT0, |
| 827 | GR_GL_RENDERBUFFER, |
| 828 | desc->fMSColorRenderbufferID)); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 829 | if (!this->glCaps().isConfigVerifiedColorAttachment(desc->fConfig)) { |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 830 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 831 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
| 832 | goto FAILED; |
| 833 | } |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 834 | fGLContext.info().caps()->markConfigAsValidColorAttachment(desc->fConfig); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 835 | } |
| 836 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 837 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 838 | |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 839 | if (GrGLCaps::kImaginationES_MSFBOType == this->glCaps().msFBOType() && desc->fSampleCnt > 0) { |
| 840 | GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, |
| 841 | GR_GL_COLOR_ATTACHMENT0, |
| 842 | GR_GL_TEXTURE_2D, |
| 843 | texID, 0, desc->fSampleCnt)); |
| 844 | } else { |
| 845 | GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
| 846 | GR_GL_COLOR_ATTACHMENT0, |
| 847 | GR_GL_TEXTURE_2D, |
| 848 | texID, 0)); |
| 849 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 850 | if (!this->glCaps().isConfigVerifiedColorAttachment(desc->fConfig)) { |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 851 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 852 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
| 853 | goto FAILED; |
| 854 | } |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 855 | fGLContext.info().caps()->markConfigAsValidColorAttachment(desc->fConfig); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | return true; |
| 859 | |
| 860 | FAILED: |
| 861 | if (desc->fMSColorRenderbufferID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 862 | GL_CALL(DeleteRenderbuffers(1, &desc->fMSColorRenderbufferID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 863 | } |
| 864 | if (desc->fRTFBOID != desc->fTexFBOID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 865 | GL_CALL(DeleteFramebuffers(1, &desc->fRTFBOID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 866 | } |
| 867 | if (desc->fTexFBOID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 868 | GL_CALL(DeleteFramebuffers(1, &desc->fTexFBOID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 869 | } |
| 870 | return false; |
| 871 | } |
| 872 | |
bsalomon@google.com | 3f3ffd6 | 2011-01-18 17:14:52 +0000 | [diff] [blame] | 873 | // good to set a break-point here to know when createTexture fails |
| 874 | static GrTexture* return_null_texture() { |
| 875 | // GrAssert(!"null texture"); |
| 876 | return NULL; |
| 877 | } |
| 878 | |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 879 | #if 0 && GR_DEBUG |
bsalomon@google.com | 3f3ffd6 | 2011-01-18 17:14:52 +0000 | [diff] [blame] | 880 | static size_t as_size_t(int x) { |
| 881 | return x; |
| 882 | } |
| 883 | #endif |
| 884 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 885 | GrTexture* GrGpuGL::onCreateTexture(const GrTextureDesc& desc, |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 886 | const void* srcData, |
| 887 | size_t rowBytes) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 888 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 889 | GrGLTexture::Desc glTexDesc; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 890 | GrGLRenderTarget::Desc glRTDesc; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 891 | |
bsalomon@google.com | 78d6cf9 | 2012-01-30 18:09:31 +0000 | [diff] [blame] | 892 | // Attempt to catch un- or wrongly initialized sample counts; |
| 893 | GrAssert(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 894 | // We fail if the MSAA was requested and is not available. |
| 895 | if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleCnt) { |
| 896 | //GrPrintf("MSAA RT requested but not supported on this platform."); |
| 897 | return return_null_texture(); |
| 898 | } |
| 899 | // If the sample count exceeds the max then we clamp it. |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 900 | glTexDesc.fSampleCnt = GrMin(desc.fSampleCnt, this->caps()->maxSampleCount()); |
bsalomon@google.com | 78d6cf9 | 2012-01-30 18:09:31 +0000 | [diff] [blame] | 901 | |
robertphillips@google.com | 3271628 | 2012-06-04 12:48:45 +0000 | [diff] [blame] | 902 | glTexDesc.fFlags = desc.fFlags; |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 903 | glTexDesc.fWidth = desc.fWidth; |
| 904 | glTexDesc.fHeight = desc.fHeight; |
bsalomon@google.com | 78d6cf9 | 2012-01-30 18:09:31 +0000 | [diff] [blame] | 905 | glTexDesc.fConfig = desc.fConfig; |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 906 | glTexDesc.fIsWrapped = false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 907 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 908 | glRTDesc.fMSColorRenderbufferID = 0; |
| 909 | glRTDesc.fRTFBOID = 0; |
| 910 | glRTDesc.fTexFBOID = 0; |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 911 | glRTDesc.fIsWrapped = false; |
bsalomon@google.com | 64c4fe4 | 2011-11-05 14:51:01 +0000 | [diff] [blame] | 912 | glRTDesc.fConfig = glTexDesc.fConfig; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 913 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 914 | bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrTextureFlagBit); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 915 | |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 916 | glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); |
| 917 | glRTDesc.fOrigin = glTexDesc.fOrigin; |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 918 | |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 919 | glRTDesc.fSampleCnt = glTexDesc.fSampleCnt; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 920 | if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && |
bsalomon@google.com | 78d6cf9 | 2012-01-30 18:09:31 +0000 | [diff] [blame] | 921 | desc.fSampleCnt) { |
bsalomon@google.com | 945bbe1 | 2012-06-15 14:30:34 +0000 | [diff] [blame] | 922 | //GrPrintf("MSAA RT requested but not supported on this platform."); |
| 923 | return return_null_texture(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 924 | } |
| 925 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 926 | if (renderTarget) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 927 | int maxRTSize = this->caps()->maxRenderTargetSize(); |
| 928 | if (glTexDesc.fWidth > maxRTSize || glTexDesc.fHeight > maxRTSize) { |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 929 | return return_null_texture(); |
| 930 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 931 | } |
| 932 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 933 | GL_CALL(GenTextures(1, &glTexDesc.fTextureID)); |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 934 | if (renderTarget && this->glCaps().textureUsageSupport()) { |
bsalomon@google.com | 07dd2bf | 2011-12-09 19:40:36 +0000 | [diff] [blame] | 935 | // provides a hint about how this texture will be used |
| 936 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 937 | GR_GL_TEXTURE_USAGE, |
| 938 | GR_GL_FRAMEBUFFER_ATTACHMENT)); |
| 939 | } |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 940 | if (!glTexDesc.fTextureID) { |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 941 | return return_null_texture(); |
| 942 | } |
| 943 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 944 | this->setSpareTextureUnit(); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 945 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTexDesc.fTextureID)); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 946 | |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 947 | // Some drivers like to know filter/wrap before seeing glTexImage2D. Some |
| 948 | // drivers have a bug where an FBO won't be complete if it includes a |
| 949 | // texture that is not mipmap complete (considering the filter in use). |
| 950 | GrGLTexture::TexParams initialTexParams; |
| 951 | // we only set a subset here so invalidate first |
| 952 | initialTexParams.invalidate(); |
| 953 | initialTexParams.fFilter = GR_GL_NEAREST; |
| 954 | initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE; |
| 955 | initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 956 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 957 | GR_GL_TEXTURE_MAG_FILTER, |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 958 | initialTexParams.fFilter)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 959 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 960 | GR_GL_TEXTURE_MIN_FILTER, |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 961 | initialTexParams.fFilter)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 962 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 963 | GR_GL_TEXTURE_WRAP_S, |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 964 | initialTexParams.fWrapS)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 965 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 966 | GR_GL_TEXTURE_WRAP_T, |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 967 | initialTexParams.fWrapT)); |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 968 | if (!this->uploadTexData(glTexDesc, true, 0, 0, |
| 969 | glTexDesc.fWidth, glTexDesc.fHeight, |
| 970 | desc.fConfig, srcData, rowBytes)) { |
| 971 | GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID)); |
| 972 | return return_null_texture(); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 973 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 974 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 975 | GrGLTexture* tex; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 976 | if (renderTarget) { |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 977 | // unbind the texture from the texture unit before binding it to the frame buffer |
| 978 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, 0)); |
| 979 | |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 980 | if (!this->createRenderTargetObjects(glTexDesc.fWidth, |
| 981 | glTexDesc.fHeight, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 982 | glTexDesc.fTextureID, |
| 983 | &glRTDesc)) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 984 | GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 985 | return return_null_texture(); |
| 986 | } |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 987 | tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc, glRTDesc)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 988 | } else { |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 989 | tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 990 | } |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 991 | tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 992 | #ifdef TRACE_TEXTURE_CREATION |
bsalomon@google.com | 64c4fe4 | 2011-11-05 14:51:01 +0000 | [diff] [blame] | 993 | GrPrintf("--- new texture [%d] size=(%d %d) config=%d\n", |
| 994 | glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 995 | #endif |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 996 | return tex; |
| 997 | } |
| 998 | |
| 999 | namespace { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1000 | |
| 1001 | const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount; |
| 1002 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1003 | void inline get_stencil_rb_sizes(const GrGLInterface* gl, |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1004 | GrGLuint rb, |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1005 | GrGLStencilBuffer::Format* format) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1006 | // we shouldn't ever know one size and not the other |
| 1007 | GrAssert((kUnknownBitCount == format->fStencilBits) == |
| 1008 | (kUnknownBitCount == format->fTotalBits)); |
| 1009 | if (kUnknownBitCount == format->fStencilBits) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1010 | GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1011 | GR_GL_RENDERBUFFER_STENCIL_SIZE, |
| 1012 | (GrGLint*)&format->fStencilBits); |
| 1013 | if (format->fPacked) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1014 | GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1015 | GR_GL_RENDERBUFFER_DEPTH_SIZE, |
| 1016 | (GrGLint*)&format->fTotalBits); |
| 1017 | format->fTotalBits += format->fStencilBits; |
| 1018 | } else { |
| 1019 | format->fTotalBits = format->fStencilBits; |
| 1020 | } |
| 1021 | } |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | bool GrGpuGL::createStencilBufferForRenderTarget(GrRenderTarget* rt, |
| 1026 | int width, int height) { |
| 1027 | |
| 1028 | // All internally created RTs are also textures. We don't create |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 1029 | // SBs for a client's standalone RT (that is a RT that isn't also a texture). |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1030 | GrAssert(rt->asTexture()); |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 1031 | GrAssert(width >= rt->width()); |
| 1032 | GrAssert(height >= rt->height()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1033 | |
| 1034 | int samples = rt->numSamples(); |
| 1035 | GrGLuint sbID; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1036 | GL_CALL(GenRenderbuffers(1, &sbID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1037 | if (!sbID) { |
| 1038 | return false; |
| 1039 | } |
| 1040 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1041 | int stencilFmtCnt = this->glCaps().stencilFormats().count(); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1042 | for (int i = 0; i < stencilFmtCnt; ++i) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1043 | GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1044 | // we start with the last stencil format that succeeded in hopes |
| 1045 | // that we won't go through this loop more than once after the |
| 1046 | // first (painful) stencil creation. |
| 1047 | int sIdx = (i + fLastSuccessfulStencilFmtIdx) % stencilFmtCnt; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1048 | const GrGLCaps::StencilFormat& sFmt = |
| 1049 | this->glCaps().stencilFormats()[sIdx]; |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 1050 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 1051 | // we do this "if" so that we don't call the multisample |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1052 | // version on a GL that doesn't have an MSAA extension. |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 1053 | bool created; |
| 1054 | if (samples > 0) { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 1055 | created = renderbuffer_storage_msaa(fGLContext, |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 1056 | samples, |
| 1057 | sFmt.fInternalFormat, |
| 1058 | width, height); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1059 | } else { |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 1060 | GL_ALLOC_CALL(this->glInterface(), |
| 1061 | RenderbufferStorage(GR_GL_RENDERBUFFER, |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1062 | sFmt.fInternalFormat, |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 1063 | width, height)); |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 1064 | created = |
| 1065 | (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(this->glInterface())); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1066 | } |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 1067 | if (created) { |
| 1068 | // After sized formats we attempt an unsized format and take |
| 1069 | // whatever sizes GL gives us. In that case we query for the size. |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1070 | GrGLStencilBuffer::Format format = sFmt; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1071 | get_stencil_rb_sizes(this->glInterface(), sbID, &format); |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 1072 | static const bool kIsWrapped = false; |
robertphillips@google.com | f2e93fc | 2012-09-05 19:44:18 +0000 | [diff] [blame] | 1073 | SkAutoTUnref<GrStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer, |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 1074 | (this, kIsWrapped, sbID, width, height, |
robertphillips@google.com | f2e93fc | 2012-09-05 19:44:18 +0000 | [diff] [blame] | 1075 | samples, format))); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1076 | if (this->attachStencilBufferToRenderTarget(sb, rt)) { |
| 1077 | fLastSuccessfulStencilFmtIdx = sIdx; |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 1078 | sb->transferToCache(); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 1079 | rt->setStencilBuffer(sb); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1080 | return true; |
| 1081 | } |
| 1082 | sb->abandon(); // otherwise we lose sbID |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1083 | } |
| 1084 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1085 | GL_CALL(DeleteRenderbuffers(1, &sbID)); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 1086 | return false; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1087 | } |
| 1088 | |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1089 | bool GrGpuGL::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, GrRenderTarget* rt) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1090 | GrGLRenderTarget* glrt = (GrGLRenderTarget*) rt; |
| 1091 | |
| 1092 | GrGLuint fbo = glrt->renderFBOID(); |
| 1093 | |
| 1094 | if (NULL == sb) { |
| 1095 | if (NULL != rt->getStencilBuffer()) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1096 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1097 | GR_GL_STENCIL_ATTACHMENT, |
| 1098 | GR_GL_RENDERBUFFER, 0)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1099 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1100 | GR_GL_DEPTH_ATTACHMENT, |
| 1101 | GR_GL_RENDERBUFFER, 0)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1102 | #if GR_DEBUG |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 1103 | GrGLenum status; |
| 1104 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1105 | GrAssert(GR_GL_FRAMEBUFFER_COMPLETE == status); |
| 1106 | #endif |
| 1107 | } |
| 1108 | return true; |
| 1109 | } else { |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1110 | GrGLStencilBuffer* glsb = static_cast<GrGLStencilBuffer*>(sb); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1111 | GrGLuint rb = glsb->renderbufferID(); |
| 1112 | |
bsalomon@google.com | c811ea3 | 2012-05-21 15:33:09 +0000 | [diff] [blame] | 1113 | fHWBoundRenderTarget = NULL; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1114 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo)); |
| 1115 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1116 | GR_GL_STENCIL_ATTACHMENT, |
| 1117 | GR_GL_RENDERBUFFER, rb)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1118 | if (glsb->format().fPacked) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1119 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1120 | GR_GL_DEPTH_ATTACHMENT, |
| 1121 | GR_GL_RENDERBUFFER, rb)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1122 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1123 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1124 | GR_GL_DEPTH_ATTACHMENT, |
| 1125 | GR_GL_RENDERBUFFER, 0)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1126 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1127 | |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 1128 | GrGLenum status; |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1129 | if (!this->glCaps().isColorConfigAndStencilFormatVerified(rt->config(), glsb->format())) { |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 1130 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 1131 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1132 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 1133 | GR_GL_STENCIL_ATTACHMENT, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1134 | GR_GL_RENDERBUFFER, 0)); |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 1135 | if (glsb->format().fPacked) { |
| 1136 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 1137 | GR_GL_DEPTH_ATTACHMENT, |
| 1138 | GR_GL_RENDERBUFFER, 0)); |
| 1139 | } |
| 1140 | return false; |
| 1141 | } else { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1142 | fGLContext.info().caps()->markColorConfigAndStencilFormatAsVerified( |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 1143 | rt->config(), |
| 1144 | glsb->format()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1145 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1146 | } |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 1147 | return true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1148 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 1151 | //////////////////////////////////////////////////////////////////////////////// |
| 1152 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 1153 | GrVertexBuffer* GrGpuGL::onCreateVertexBuffer(uint32_t size, bool dynamic) { |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 1154 | GrGLVertexBuffer::Desc desc; |
| 1155 | desc.fDynamic = dynamic; |
| 1156 | desc.fSizeInBytes = size; |
| 1157 | desc.fIsWrapped = false; |
| 1158 | |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 1159 | if (this->glCaps().useNonVBOVertexAndIndexDynamicData() && desc.fDynamic) { |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1160 | desc.fID = 0; |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 1161 | GrGLVertexBuffer* vertexBuffer = SkNEW_ARGS(GrGLVertexBuffer, (this, desc)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1162 | return vertexBuffer; |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1163 | } else { |
| 1164 | GL_CALL(GenBuffers(1, &desc.fID)); |
| 1165 | if (desc.fID) { |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 1166 | fHWGeometryState.setVertexBufferID(this, desc.fID); |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1167 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
| 1168 | // make sure driver can allocate memory for this buffer |
| 1169 | GL_ALLOC_CALL(this->glInterface(), |
| 1170 | BufferData(GR_GL_ARRAY_BUFFER, |
| 1171 | desc.fSizeInBytes, |
| 1172 | NULL, // data ptr |
| 1173 | desc.fDynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW)); |
| 1174 | if (CHECK_ALLOC_ERROR(this->glInterface()) != GR_GL_NO_ERROR) { |
| 1175 | GL_CALL(DeleteBuffers(1, &desc.fID)); |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 1176 | this->notifyVertexBufferDelete(desc.fID); |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1177 | return NULL; |
| 1178 | } |
| 1179 | GrGLVertexBuffer* vertexBuffer = SkNEW_ARGS(GrGLVertexBuffer, (this, desc)); |
| 1180 | return vertexBuffer; |
| 1181 | } |
| 1182 | return NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1183 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 1186 | GrIndexBuffer* GrGpuGL::onCreateIndexBuffer(uint32_t size, bool dynamic) { |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 1187 | GrGLIndexBuffer::Desc desc; |
| 1188 | desc.fDynamic = dynamic; |
| 1189 | desc.fSizeInBytes = size; |
| 1190 | desc.fIsWrapped = false; |
| 1191 | |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 1192 | if (this->glCaps().useNonVBOVertexAndIndexDynamicData() && desc.fDynamic) { |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1193 | desc.fID = 0; |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 1194 | GrIndexBuffer* indexBuffer = SkNEW_ARGS(GrGLIndexBuffer, (this, desc)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1195 | return indexBuffer; |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1196 | } else { |
| 1197 | GL_CALL(GenBuffers(1, &desc.fID)); |
| 1198 | if (desc.fID) { |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 1199 | fHWGeometryState.setIndexBufferIDOnDefaultVertexArray(this, desc.fID); |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1200 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
| 1201 | // make sure driver can allocate memory for this buffer |
| 1202 | GL_ALLOC_CALL(this->glInterface(), |
| 1203 | BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, |
| 1204 | desc.fSizeInBytes, |
| 1205 | NULL, // data ptr |
| 1206 | desc.fDynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW)); |
| 1207 | if (CHECK_ALLOC_ERROR(this->glInterface()) != GR_GL_NO_ERROR) { |
| 1208 | GL_CALL(DeleteBuffers(1, &desc.fID)); |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 1209 | this->notifyIndexBufferDelete(desc.fID); |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1210 | return NULL; |
| 1211 | } |
| 1212 | GrIndexBuffer* indexBuffer = SkNEW_ARGS(GrGLIndexBuffer, (this, desc)); |
| 1213 | return indexBuffer; |
| 1214 | } |
| 1215 | return NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1216 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 1219 | GrPath* GrGpuGL::onCreatePath(const SkPath& inPath) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1220 | GrAssert(this->caps()->pathStencilingSupport()); |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 1221 | return SkNEW_ARGS(GrGLPath, (this, inPath)); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 1222 | } |
| 1223 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1224 | void GrGpuGL::flushScissor() { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1225 | const GrDrawState& drawState = this->getDrawState(); |
| 1226 | const GrGLRenderTarget* rt = |
| 1227 | static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget()); |
| 1228 | |
| 1229 | GrAssert(NULL != rt); |
| 1230 | const GrGLIRect& vp = rt->getViewport(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1231 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1232 | if (fScissorState.fEnabled) { |
| 1233 | GrGLIRect scissor; |
| 1234 | scissor.setRelativeTo(vp, |
| 1235 | fScissorState.fRect.fLeft, |
| 1236 | fScissorState.fRect.fTop, |
| 1237 | fScissorState.fRect.width(), |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1238 | fScissorState.fRect.height(), |
| 1239 | rt->origin()); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1240 | // if the scissor fully contains the viewport then we fall through and |
| 1241 | // disable the scissor test. |
| 1242 | if (!scissor.contains(vp)) { |
| 1243 | if (fHWScissorSettings.fRect != scissor) { |
| 1244 | scissor.pushToGLScissor(this->glInterface()); |
| 1245 | fHWScissorSettings.fRect = scissor; |
| 1246 | } |
| 1247 | if (kYes_TriState != fHWScissorSettings.fEnabled) { |
| 1248 | GL_CALL(Enable(GR_GL_SCISSOR_TEST)); |
| 1249 | fHWScissorSettings.fEnabled = kYes_TriState; |
| 1250 | } |
| 1251 | return; |
| 1252 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1253 | } |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1254 | if (kNo_TriState != fHWScissorSettings.fEnabled) { |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 1255 | GL_CALL(Disable(GR_GL_SCISSOR_TEST)); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1256 | fHWScissorSettings.fEnabled = kNo_TriState; |
| 1257 | return; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1258 | } |
| 1259 | } |
| 1260 | |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 1261 | void GrGpuGL::onClear(const GrIRect* rect, GrColor color) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1262 | const GrDrawState& drawState = this->getDrawState(); |
| 1263 | const GrRenderTarget* rt = drawState.getRenderTarget(); |
bsalomon@google.com | 0ba52fc | 2011-11-10 22:16:06 +0000 | [diff] [blame] | 1264 | // parent class should never let us get here with no RT |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1265 | GrAssert(NULL != rt); |
bsalomon@google.com | 0ba52fc | 2011-11-10 22:16:06 +0000 | [diff] [blame] | 1266 | |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1267 | GrIRect clippedRect; |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 1268 | if (NULL != rect) { |
| 1269 | // flushScissor expects rect to be clipped to the target. |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1270 | clippedRect = *rect; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1271 | GrIRect rtRect = SkIRect::MakeWH(rt->width(), rt->height()); |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1272 | if (clippedRect.intersect(rtRect)) { |
| 1273 | rect = &clippedRect; |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 1274 | } else { |
| 1275 | return; |
| 1276 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1277 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1278 | this->flushRenderTarget(rect); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1279 | GrAutoTRestore<ScissorState> asr(&fScissorState); |
| 1280 | fScissorState.fEnabled = (NULL != rect); |
| 1281 | if (fScissorState.fEnabled) { |
| 1282 | fScissorState.fRect = *rect; |
| 1283 | } |
| 1284 | this->flushScissor(); |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1285 | |
| 1286 | GrGLfloat r, g, b, a; |
| 1287 | static const GrGLfloat scale255 = 1.f / 255.f; |
| 1288 | a = GrColorUnpackA(color) * scale255; |
| 1289 | GrGLfloat scaleRGB = scale255; |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1290 | r = GrColorUnpackR(color) * scaleRGB; |
| 1291 | g = GrColorUnpackG(color) * scaleRGB; |
| 1292 | b = GrColorUnpackB(color) * scaleRGB; |
| 1293 | |
| 1294 | GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE)); |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 1295 | fHWWriteToColor = kYes_TriState; |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1296 | GL_CALL(ClearColor(r, g, b, a)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1297 | GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
bsalomon@google.com | edc177d | 2011-08-05 15:46:40 +0000 | [diff] [blame] | 1300 | void GrGpuGL::clearStencil() { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1301 | if (NULL == this->getDrawState().getRenderTarget()) { |
bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 1302 | return; |
| 1303 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1304 | |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1305 | this->flushRenderTarget(&GrIRect::EmptyIRect()); |
| 1306 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1307 | GrAutoTRestore<ScissorState> asr(&fScissorState); |
| 1308 | fScissorState.fEnabled = false; |
| 1309 | this->flushScissor(); |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 1310 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1311 | GL_CALL(StencilMask(0xffffffff)); |
| 1312 | GL_CALL(ClearStencil(0)); |
| 1313 | GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
bsalomon@google.com | 457b8a3 | 2012-05-21 21:19:58 +0000 | [diff] [blame] | 1314 | fHWStencilSettings.invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1317 | void GrGpuGL::clearStencilClip(const GrIRect& rect, bool insideClip) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1318 | const GrDrawState& drawState = this->getDrawState(); |
| 1319 | const GrRenderTarget* rt = drawState.getRenderTarget(); |
| 1320 | GrAssert(NULL != rt); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1321 | |
| 1322 | // this should only be called internally when we know we have a |
| 1323 | // stencil buffer. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1324 | GrAssert(NULL != rt->getStencilBuffer()); |
| 1325 | GrGLint stencilBitCount = rt->getStencilBuffer()->bits(); |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1326 | #if 0 |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1327 | GrAssert(stencilBitCount > 0); |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1328 | GrGLint clipStencilMask = (1 << (stencilBitCount - 1)); |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 1329 | #else |
| 1330 | // we could just clear the clip bit but when we go through |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1331 | // ANGLE a partial stencil mask will cause clears to be |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 1332 | // turned into draws. Our contract on GrDrawTarget says that |
| 1333 | // changing the clip between stencil passes may or may not |
| 1334 | // 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] | 1335 | static const GrGLint clipStencilMask = ~0; |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 1336 | #endif |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1337 | GrGLint value; |
| 1338 | if (insideClip) { |
| 1339 | value = (1 << (stencilBitCount - 1)); |
| 1340 | } else { |
| 1341 | value = 0; |
| 1342 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1343 | this->flushRenderTarget(&GrIRect::EmptyIRect()); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1344 | |
| 1345 | GrAutoTRestore<ScissorState> asr(&fScissorState); |
| 1346 | fScissorState.fEnabled = true; |
| 1347 | fScissorState.fRect = rect; |
| 1348 | this->flushScissor(); |
| 1349 | |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 1350 | GL_CALL(StencilMask((uint32_t) clipStencilMask)); |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1351 | GL_CALL(ClearStencil(value)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1352 | GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
bsalomon@google.com | 457b8a3 | 2012-05-21 21:19:58 +0000 | [diff] [blame] | 1353 | fHWStencilSettings.invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 1356 | void GrGpuGL::onForceRenderTargetFlush() { |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1357 | this->flushRenderTarget(&GrIRect::EmptyIRect()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1358 | } |
| 1359 | |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1360 | bool GrGpuGL::readPixelsWillPayForYFlip(GrRenderTarget* renderTarget, |
| 1361 | int left, int top, |
| 1362 | int width, int height, |
| 1363 | GrPixelConfig config, |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1364 | size_t rowBytes) const { |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1365 | // If this rendertarget is aready TopLeft, we don't need to flip. |
| 1366 | if (kTopLeft_GrSurfaceOrigin == renderTarget->origin()) { |
| 1367 | return false; |
| 1368 | } |
| 1369 | |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1370 | // if GL can do the flip then we'll never pay for it. |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1371 | if (this->glCaps().packFlipYSupport()) { |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1372 | return false; |
| 1373 | } |
| 1374 | |
| 1375 | // If we have to do memcpy to handle non-trim rowBytes then we |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 1376 | // get the flip for free. Otherwise it costs. |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1377 | if (this->glCaps().packRowLengthSupport()) { |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 1378 | return true; |
| 1379 | } |
| 1380 | // If we have to do memcpys to handle rowBytes then y-flip is free |
| 1381 | // Note the rowBytes might be tight to the passed in data, but if data |
| 1382 | // gets clipped in x to the target the rowBytes will no longer be tight. |
| 1383 | if (left >= 0 && (left + width) < renderTarget->width()) { |
| 1384 | return 0 == rowBytes || |
| 1385 | GrBytesPerPixel(config) * width == rowBytes; |
| 1386 | } else { |
| 1387 | return false; |
| 1388 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1391 | bool GrGpuGL::onReadPixels(GrRenderTarget* target, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1392 | int left, int top, |
| 1393 | int width, int height, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1394 | GrPixelConfig config, |
| 1395 | void* buffer, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1396 | size_t rowBytes) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1397 | GrGLenum format; |
| 1398 | GrGLenum type; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1399 | bool flipY = kBottomLeft_GrSurfaceOrigin == target->origin(); |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 1400 | if (!this->configToGLFormats(config, false, NULL, &format, &type)) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1401 | return false; |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1402 | } |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 1403 | size_t bpp = GrBytesPerPixel(config); |
| 1404 | if (!adjust_pixel_ops_params(target->width(), target->height(), bpp, |
| 1405 | &left, &top, &width, &height, |
| 1406 | const_cast<const void**>(&buffer), |
| 1407 | &rowBytes)) { |
| 1408 | return false; |
| 1409 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1410 | |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1411 | // resolve the render target if necessary |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1412 | GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1413 | GrDrawState::AutoRenderTargetRestore artr; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1414 | switch (tgt->getResolveType()) { |
| 1415 | case GrGLRenderTarget::kCantResolve_ResolveType: |
| 1416 | return false; |
| 1417 | case GrGLRenderTarget::kAutoResolves_ResolveType: |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1418 | artr.set(this->drawState(), target); |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1419 | this->flushRenderTarget(&GrIRect::EmptyIRect()); |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1420 | break; |
| 1421 | case GrGLRenderTarget::kCanResolve_ResolveType: |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 1422 | this->onResolveRenderTarget(tgt); |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1423 | // we don't track the state of the READ FBO ID. |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1424 | GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, |
| 1425 | tgt->textureFBOID())); |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1426 | break; |
| 1427 | default: |
| 1428 | GrCrash("Unknown resolve type"); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1431 | const GrGLIRect& glvp = tgt->getViewport(); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1432 | |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 1433 | // the read rect is viewport-relative |
| 1434 | GrGLIRect readRect; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1435 | readRect.setRelativeTo(glvp, left, top, width, height, target->origin()); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1436 | |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 1437 | size_t tightRowBytes = bpp * width; |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1438 | if (0 == rowBytes) { |
| 1439 | rowBytes = tightRowBytes; |
| 1440 | } |
| 1441 | size_t readDstRowBytes = tightRowBytes; |
| 1442 | void* readDst = buffer; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1443 | |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1444 | // determine if GL can read using the passed rowBytes or if we need |
| 1445 | // a scratch buffer. |
| 1446 | SkAutoSMalloc<32 * sizeof(GrColor)> scratch; |
| 1447 | if (rowBytes != tightRowBytes) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1448 | if (this->glCaps().packRowLengthSupport()) { |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1449 | GrAssert(!(rowBytes % sizeof(GrColor))); |
| 1450 | GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, rowBytes / sizeof(GrColor))); |
| 1451 | readDstRowBytes = rowBytes; |
| 1452 | } else { |
| 1453 | scratch.reset(tightRowBytes * height); |
| 1454 | readDst = scratch.get(); |
| 1455 | } |
| 1456 | } |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1457 | if (flipY && this->glCaps().packFlipYSupport()) { |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1458 | GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 1)); |
| 1459 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1460 | GL_CALL(ReadPixels(readRect.fLeft, readRect.fBottom, |
| 1461 | readRect.fWidth, readRect.fHeight, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1462 | format, type, readDst)); |
| 1463 | if (readDstRowBytes != tightRowBytes) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1464 | GrAssert(this->glCaps().packRowLengthSupport()); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1465 | GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); |
| 1466 | } |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1467 | if (flipY && this->glCaps().packFlipYSupport()) { |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1468 | GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 0)); |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1469 | flipY = false; |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1470 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1471 | |
| 1472 | // now reverse the order of the rows, since GL's are bottom-to-top, but our |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1473 | // API presents top-to-bottom. We must preserve the padding contents. Note |
| 1474 | // that the above readPixels did not overwrite the padding. |
| 1475 | if (readDst == buffer) { |
| 1476 | GrAssert(rowBytes == readDstRowBytes); |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1477 | if (flipY) { |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1478 | scratch.reset(tightRowBytes); |
| 1479 | void* tmpRow = scratch.get(); |
| 1480 | // flip y in-place by rows |
| 1481 | const int halfY = height >> 1; |
| 1482 | char* top = reinterpret_cast<char*>(buffer); |
| 1483 | char* bottom = top + (height - 1) * rowBytes; |
| 1484 | for (int y = 0; y < halfY; y++) { |
| 1485 | memcpy(tmpRow, top, tightRowBytes); |
| 1486 | memcpy(top, bottom, tightRowBytes); |
| 1487 | memcpy(bottom, tmpRow, tightRowBytes); |
| 1488 | top += rowBytes; |
| 1489 | bottom -= rowBytes; |
| 1490 | } |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1491 | } |
| 1492 | } else { |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1493 | GrAssert(readDst != buffer); GrAssert(rowBytes != tightRowBytes); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1494 | // copy from readDst to buffer while flipping y |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 1495 | // const int halfY = height >> 1; |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1496 | const char* src = reinterpret_cast<const char*>(readDst); |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1497 | char* dst = reinterpret_cast<char*>(buffer); |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1498 | if (flipY) { |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1499 | dst += (height-1) * rowBytes; |
| 1500 | } |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1501 | for (int y = 0; y < height; y++) { |
| 1502 | memcpy(dst, src, tightRowBytes); |
| 1503 | src += readDstRowBytes; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1504 | if (!flipY) { |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1505 | dst += rowBytes; |
| 1506 | } else { |
| 1507 | dst -= rowBytes; |
| 1508 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1509 | } |
| 1510 | } |
| 1511 | return true; |
| 1512 | } |
| 1513 | |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1514 | void GrGpuGL::flushRenderTarget(const GrIRect* bound) { |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1515 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1516 | GrGLRenderTarget* rt = |
| 1517 | static_cast<GrGLRenderTarget*>(this->drawState()->getRenderTarget()); |
| 1518 | GrAssert(NULL != rt); |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1519 | |
bsalomon@google.com | c811ea3 | 2012-05-21 15:33:09 +0000 | [diff] [blame] | 1520 | if (fHWBoundRenderTarget != rt) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1521 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID())); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1522 | #if GR_DEBUG |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 1523 | GrGLenum status; |
| 1524 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
bsalomon@google.com | c312bf9 | 2011-03-21 21:10:33 +0000 | [diff] [blame] | 1525 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
reed@google.com | b9255d5 | 2011-06-13 18:54:59 +0000 | [diff] [blame] | 1526 | GrPrintf("GrGpuGL::flushRenderTarget glCheckFramebufferStatus %x\n", status); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1527 | } |
| 1528 | #endif |
bsalomon@google.com | c811ea3 | 2012-05-21 15:33:09 +0000 | [diff] [blame] | 1529 | fHWBoundRenderTarget = rt; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1530 | const GrGLIRect& vp = rt->getViewport(); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1531 | if (fHWViewport != vp) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1532 | vp.pushToGLViewport(this->glInterface()); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1533 | fHWViewport = vp; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1534 | } |
| 1535 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1536 | if (NULL == bound || !bound->isEmpty()) { |
| 1537 | rt->flagAsNeedingResolve(bound); |
| 1538 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1539 | } |
| 1540 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1541 | GrGLenum gPrimitiveType2GLMode[] = { |
| 1542 | GR_GL_TRIANGLES, |
| 1543 | GR_GL_TRIANGLE_STRIP, |
| 1544 | GR_GL_TRIANGLE_FAN, |
| 1545 | GR_GL_POINTS, |
| 1546 | GR_GL_LINES, |
| 1547 | GR_GL_LINE_STRIP |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1548 | }; |
| 1549 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1550 | #define SWAP_PER_DRAW 0 |
| 1551 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 1552 | #if SWAP_PER_DRAW |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1553 | #if GR_MAC_BUILD |
| 1554 | #include <AGL/agl.h> |
| 1555 | #elif GR_WIN32_BUILD |
bsalomon@google.com | ce7357d | 2012-06-25 17:49:25 +0000 | [diff] [blame] | 1556 | #include <gl/GL.h> |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1557 | void SwapBuf() { |
| 1558 | DWORD procID = GetCurrentProcessId(); |
| 1559 | HWND hwnd = GetTopWindow(GetDesktopWindow()); |
| 1560 | while(hwnd) { |
| 1561 | DWORD wndProcID = 0; |
| 1562 | GetWindowThreadProcessId(hwnd, &wndProcID); |
| 1563 | if(wndProcID == procID) { |
| 1564 | SwapBuffers(GetDC(hwnd)); |
| 1565 | } |
| 1566 | hwnd = GetNextWindow(hwnd, GW_HWNDNEXT); |
| 1567 | } |
| 1568 | } |
| 1569 | #endif |
| 1570 | #endif |
| 1571 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 1572 | void GrGpuGL::onGpuDraw(const DrawInfo& info) { |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 1573 | size_t indexOffsetInBytes; |
| 1574 | this->setupGeometry(info, &indexOffsetInBytes); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1575 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 1576 | GrAssert((size_t)info.primitiveType() < GR_ARRAY_COUNT(gPrimitiveType2GLMode)); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 1577 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 1578 | if (info.isIndexed()) { |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 1579 | GrGLvoid* indices = |
| 1580 | reinterpret_cast<GrGLvoid*>(indexOffsetInBytes + sizeof(uint16_t) * info.startIndex()); |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 1581 | // info.startVertex() was accounted for by setupGeometry. |
| 1582 | GL_CALL(DrawElements(gPrimitiveType2GLMode[info.primitiveType()], |
| 1583 | info.indexCount(), |
| 1584 | GR_GL_UNSIGNED_SHORT, |
| 1585 | indices)); |
| 1586 | } else { |
| 1587 | // Pass 0 for parameter first. We have to adjust glVertexAttribPointer() to account for |
| 1588 | // startVertex in the DrawElements case. So we always rely on setupGeometry to have |
| 1589 | // accounted for startVertex. |
| 1590 | GL_CALL(DrawArrays(gPrimitiveType2GLMode[info.primitiveType()], 0, info.vertexCount())); |
| 1591 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1592 | #if SWAP_PER_DRAW |
| 1593 | glFlush(); |
| 1594 | #if GR_MAC_BUILD |
| 1595 | aglSwapBuffers(aglGetCurrentContext()); |
| 1596 | int set_a_break_pt_here = 9; |
| 1597 | aglSwapBuffers(aglGetCurrentContext()); |
| 1598 | #elif GR_WIN32_BUILD |
| 1599 | SwapBuf(); |
| 1600 | int set_a_break_pt_here = 9; |
| 1601 | SwapBuf(); |
| 1602 | #endif |
| 1603 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1604 | } |
| 1605 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1606 | namespace { |
bsalomon@google.com | 100abf4 | 2012-09-05 17:40:04 +0000 | [diff] [blame] | 1607 | |
| 1608 | static const uint16_t kOnes16 = static_cast<uint16_t>(~0); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1609 | const GrStencilSettings& winding_nv_path_stencil_settings() { |
| 1610 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 1611 | kIncClamp_StencilOp, |
| 1612 | kIncClamp_StencilOp, |
| 1613 | kAlwaysIfInClip_StencilFunc, |
bsalomon@google.com | 100abf4 | 2012-09-05 17:40:04 +0000 | [diff] [blame] | 1614 | kOnes16, kOnes16, kOnes16); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1615 | return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 1616 | } |
| 1617 | const GrStencilSettings& even_odd_nv_path_stencil_settings() { |
| 1618 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 1619 | kInvert_StencilOp, |
| 1620 | kInvert_StencilOp, |
| 1621 | kAlwaysIfInClip_StencilFunc, |
bsalomon@google.com | 100abf4 | 2012-09-05 17:40:04 +0000 | [diff] [blame] | 1622 | kOnes16, kOnes16, kOnes16); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1623 | return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 1624 | } |
| 1625 | } |
| 1626 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1627 | void GrGpuGL::setStencilPathSettings(const GrPath&, |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 1628 | SkPath::FillType fill, |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1629 | GrStencilSettings* settings) { |
| 1630 | switch (fill) { |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 1631 | case SkPath::kEvenOdd_FillType: |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1632 | *settings = even_odd_nv_path_stencil_settings(); |
| 1633 | return; |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 1634 | case SkPath::kWinding_FillType: |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1635 | *settings = winding_nv_path_stencil_settings(); |
| 1636 | return; |
| 1637 | default: |
| 1638 | GrCrash("Unexpected path fill."); |
| 1639 | } |
| 1640 | } |
| 1641 | |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 1642 | void GrGpuGL::onGpuStencilPath(const GrPath* path, SkPath::FillType fill) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1643 | GrAssert(this->caps()->pathStencilingSupport()); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1644 | |
| 1645 | GrGLuint id = static_cast<const GrGLPath*>(path)->pathID(); |
| 1646 | GrDrawState* drawState = this->drawState(); |
| 1647 | GrAssert(NULL != drawState->getRenderTarget()); |
| 1648 | if (NULL == drawState->getRenderTarget()->getStencilBuffer()) { |
| 1649 | return; |
| 1650 | } |
| 1651 | |
| 1652 | // Decide how to manipulate the stencil buffer based on the fill rule. |
| 1653 | // Also, assert that the stencil settings we set in setStencilPathSettings |
| 1654 | // are present. |
| 1655 | GrAssert(!fStencilSettings.isTwoSided()); |
| 1656 | GrGLenum fillMode; |
| 1657 | switch (fill) { |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 1658 | case SkPath::kWinding_FillType: |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1659 | fillMode = GR_GL_COUNT_UP; |
| 1660 | GrAssert(kIncClamp_StencilOp == |
| 1661 | fStencilSettings.passOp(GrStencilSettings::kFront_Face)); |
| 1662 | GrAssert(kIncClamp_StencilOp == |
| 1663 | fStencilSettings.failOp(GrStencilSettings::kFront_Face)); |
| 1664 | break; |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 1665 | case SkPath::kEvenOdd_FillType: |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1666 | fillMode = GR_GL_INVERT; |
| 1667 | GrAssert(kInvert_StencilOp == |
| 1668 | fStencilSettings.passOp(GrStencilSettings::kFront_Face)); |
| 1669 | GrAssert(kInvert_StencilOp == |
| 1670 | fStencilSettings.failOp(GrStencilSettings::kFront_Face)); |
| 1671 | break; |
| 1672 | default: |
| 1673 | // Only the above two fill rules are allowed. |
| 1674 | GrCrash("Unexpected path fill."); |
bsalomon@google.com | 548a433 | 2012-07-11 19:45:22 +0000 | [diff] [blame] | 1675 | return; // suppress unused var warning. |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1676 | } |
| 1677 | GrGLint writeMask = fStencilSettings.writeMask(GrStencilSettings::kFront_Face); |
| 1678 | GL_CALL(StencilFillPath(id, fillMode, writeMask)); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 1679 | } |
| 1680 | |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 1681 | void GrGpuGL::onResolveRenderTarget(GrRenderTarget* target) { |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 1682 | GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1683 | if (rt->needsResolve()) { |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1684 | // The IMG extension automatically resolves the texture when it is read. |
| 1685 | if (GrGLCaps::kImaginationES_MSFBOType != this->glCaps().msFBOType()) { |
| 1686 | GrAssert(GrGLCaps::kNone_MSFBOType != this->glCaps().msFBOType()); |
| 1687 | GrAssert(rt->textureFBOID() != rt->renderFBOID()); |
| 1688 | GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); |
| 1689 | GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID())); |
| 1690 | // make sure we go through flushRenderTarget() since we've modified |
| 1691 | // the bound DRAW FBO ID. |
| 1692 | fHWBoundRenderTarget = NULL; |
| 1693 | const GrGLIRect& vp = rt->getViewport(); |
| 1694 | const GrIRect dirtyRect = rt->getResolveRect(); |
| 1695 | GrGLIRect r; |
| 1696 | r.setRelativeTo(vp, dirtyRect.fLeft, dirtyRect.fTop, |
| 1697 | dirtyRect.width(), dirtyRect.height(), target->origin()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1698 | |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1699 | GrAutoTRestore<ScissorState> asr; |
| 1700 | if (GrGLCaps::kAppleES_MSFBOType == this->glCaps().msFBOType()) { |
| 1701 | // Apple's extension uses the scissor as the blit bounds. |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1702 | asr.reset(&fScissorState); |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1703 | fScissorState.fEnabled = true; |
| 1704 | fScissorState.fRect = dirtyRect; |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1705 | this->flushScissor(); |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1706 | GL_CALL(ResolveMultisampleFramebuffer()); |
| 1707 | } else { |
| 1708 | if (GrGLCaps::kDesktopARB_MSFBOType != this->glCaps().msFBOType()) { |
| 1709 | // this respects the scissor during the blit, so disable it. |
| 1710 | GrAssert(GrGLCaps::kDesktopEXT_MSFBOType == this->glCaps().msFBOType()); |
| 1711 | asr.reset(&fScissorState); |
| 1712 | fScissorState.fEnabled = false; |
| 1713 | this->flushScissor(); |
| 1714 | } |
| 1715 | int right = r.fLeft + r.fWidth; |
| 1716 | int top = r.fBottom + r.fHeight; |
| 1717 | GL_CALL(BlitFramebuffer(r.fLeft, r.fBottom, right, top, |
| 1718 | r.fLeft, r.fBottom, right, top, |
| 1719 | GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST)); |
bsalomon@google.com | a9ecdad | 2011-03-23 13:50:34 +0000 | [diff] [blame] | 1720 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1721 | } |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1722 | rt->flagAsResolved(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1723 | } |
| 1724 | } |
| 1725 | |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1726 | namespace { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1727 | |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1728 | GrGLenum gr_to_gl_stencil_func(GrStencilFunc basicFunc) { |
| 1729 | static const GrGLenum gTable[] = { |
| 1730 | GR_GL_ALWAYS, // kAlways_StencilFunc |
| 1731 | GR_GL_NEVER, // kNever_StencilFunc |
| 1732 | GR_GL_GREATER, // kGreater_StencilFunc |
| 1733 | GR_GL_GEQUAL, // kGEqual_StencilFunc |
| 1734 | GR_GL_LESS, // kLess_StencilFunc |
| 1735 | GR_GL_LEQUAL, // kLEqual_StencilFunc, |
| 1736 | GR_GL_EQUAL, // kEqual_StencilFunc, |
| 1737 | GR_GL_NOTEQUAL, // kNotEqual_StencilFunc, |
| 1738 | }; |
| 1739 | GR_STATIC_ASSERT(GR_ARRAY_COUNT(gTable) == kBasicStencilFuncCount); |
| 1740 | GR_STATIC_ASSERT(0 == kAlways_StencilFunc); |
| 1741 | GR_STATIC_ASSERT(1 == kNever_StencilFunc); |
| 1742 | GR_STATIC_ASSERT(2 == kGreater_StencilFunc); |
| 1743 | GR_STATIC_ASSERT(3 == kGEqual_StencilFunc); |
| 1744 | GR_STATIC_ASSERT(4 == kLess_StencilFunc); |
| 1745 | GR_STATIC_ASSERT(5 == kLEqual_StencilFunc); |
| 1746 | GR_STATIC_ASSERT(6 == kEqual_StencilFunc); |
| 1747 | GR_STATIC_ASSERT(7 == kNotEqual_StencilFunc); |
| 1748 | GrAssert((unsigned) basicFunc < kBasicStencilFuncCount); |
| 1749 | |
| 1750 | return gTable[basicFunc]; |
| 1751 | } |
| 1752 | |
| 1753 | GrGLenum gr_to_gl_stencil_op(GrStencilOp op) { |
| 1754 | static const GrGLenum gTable[] = { |
| 1755 | GR_GL_KEEP, // kKeep_StencilOp |
| 1756 | GR_GL_REPLACE, // kReplace_StencilOp |
| 1757 | GR_GL_INCR_WRAP, // kIncWrap_StencilOp |
| 1758 | GR_GL_INCR, // kIncClamp_StencilOp |
| 1759 | GR_GL_DECR_WRAP, // kDecWrap_StencilOp |
| 1760 | GR_GL_DECR, // kDecClamp_StencilOp |
| 1761 | GR_GL_ZERO, // kZero_StencilOp |
| 1762 | GR_GL_INVERT, // kInvert_StencilOp |
| 1763 | }; |
| 1764 | GR_STATIC_ASSERT(GR_ARRAY_COUNT(gTable) == kStencilOpCount); |
| 1765 | GR_STATIC_ASSERT(0 == kKeep_StencilOp); |
| 1766 | GR_STATIC_ASSERT(1 == kReplace_StencilOp); |
| 1767 | GR_STATIC_ASSERT(2 == kIncWrap_StencilOp); |
| 1768 | GR_STATIC_ASSERT(3 == kIncClamp_StencilOp); |
| 1769 | GR_STATIC_ASSERT(4 == kDecWrap_StencilOp); |
| 1770 | GR_STATIC_ASSERT(5 == kDecClamp_StencilOp); |
| 1771 | GR_STATIC_ASSERT(6 == kZero_StencilOp); |
| 1772 | GR_STATIC_ASSERT(7 == kInvert_StencilOp); |
| 1773 | GrAssert((unsigned) op < kStencilOpCount); |
| 1774 | return gTable[op]; |
| 1775 | } |
| 1776 | |
| 1777 | void set_gl_stencil(const GrGLInterface* gl, |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1778 | const GrStencilSettings& settings, |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1779 | GrGLenum glFace, |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1780 | GrStencilSettings::Face grFace) { |
| 1781 | GrGLenum glFunc = gr_to_gl_stencil_func(settings.func(grFace)); |
| 1782 | GrGLenum glFailOp = gr_to_gl_stencil_op(settings.failOp(grFace)); |
| 1783 | GrGLenum glPassOp = gr_to_gl_stencil_op(settings.passOp(grFace)); |
| 1784 | |
| 1785 | GrGLint ref = settings.funcRef(grFace); |
| 1786 | GrGLint mask = settings.funcMask(grFace); |
| 1787 | GrGLint writeMask = settings.writeMask(grFace); |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1788 | |
| 1789 | if (GR_GL_FRONT_AND_BACK == glFace) { |
| 1790 | // we call the combined func just in case separate stencil is not |
| 1791 | // supported. |
| 1792 | GR_GL_CALL(gl, StencilFunc(glFunc, ref, mask)); |
| 1793 | GR_GL_CALL(gl, StencilMask(writeMask)); |
| 1794 | GR_GL_CALL(gl, StencilOp(glFailOp, glPassOp, glPassOp)); |
| 1795 | } else { |
| 1796 | GR_GL_CALL(gl, StencilFuncSeparate(glFace, glFunc, ref, mask)); |
| 1797 | GR_GL_CALL(gl, StencilMaskSeparate(glFace, writeMask)); |
| 1798 | GR_GL_CALL(gl, StencilOpSeparate(glFace, glFailOp, glPassOp, glPassOp)); |
| 1799 | } |
| 1800 | } |
| 1801 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1802 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1803 | void GrGpuGL::flushStencil(DrawType type) { |
| 1804 | if (kStencilPath_DrawType == type) { |
| 1805 | GrAssert(!fStencilSettings.isTwoSided()); |
| 1806 | // Just the func, ref, and mask is set here. The op and write mask are params to the call |
| 1807 | // that draws the path to the SB (glStencilFillPath) |
| 1808 | GrGLenum func = |
| 1809 | gr_to_gl_stencil_func(fStencilSettings.func(GrStencilSettings::kFront_Face)); |
| 1810 | GL_CALL(PathStencilFunc(func, |
| 1811 | fStencilSettings.funcRef(GrStencilSettings::kFront_Face), |
| 1812 | fStencilSettings.funcMask(GrStencilSettings::kFront_Face))); |
| 1813 | } else if (fHWStencilSettings != fStencilSettings) { |
| 1814 | if (fStencilSettings.isDisabled()) { |
| 1815 | if (kNo_TriState != fHWStencilTestEnabled) { |
| 1816 | GL_CALL(Disable(GR_GL_STENCIL_TEST)); |
| 1817 | fHWStencilTestEnabled = kNo_TriState; |
| 1818 | } |
| 1819 | } else { |
| 1820 | if (kYes_TriState != fHWStencilTestEnabled) { |
| 1821 | GL_CALL(Enable(GR_GL_STENCIL_TEST)); |
| 1822 | fHWStencilTestEnabled = kYes_TriState; |
| 1823 | } |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1824 | } |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1825 | if (!fStencilSettings.isDisabled()) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1826 | if (this->caps()->twoSidedStencilSupport()) { |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1827 | set_gl_stencil(this->glInterface(), |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1828 | fStencilSettings, |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1829 | GR_GL_FRONT, |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1830 | GrStencilSettings::kFront_Face); |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1831 | set_gl_stencil(this->glInterface(), |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1832 | fStencilSettings, |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1833 | GR_GL_BACK, |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1834 | GrStencilSettings::kBack_Face); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1835 | } else { |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1836 | set_gl_stencil(this->glInterface(), |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1837 | fStencilSettings, |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 1838 | GR_GL_FRONT_AND_BACK, |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1839 | GrStencilSettings::kFront_Face); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1840 | } |
| 1841 | } |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1842 | fHWStencilSettings = fStencilSettings; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1843 | } |
| 1844 | } |
| 1845 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1846 | void GrGpuGL::flushAAState(DrawType type) { |
bsalomon@google.com | 202d139 | 2013-03-19 18:58:08 +0000 | [diff] [blame] | 1847 | // At least some ATI linux drivers will render GL_LINES incorrectly when MSAA state is enabled but |
| 1848 | // the target is not multisampled. Single pixel wide lines are rendered thicker than 1 pixel wide. |
| 1849 | #if 0 |
| 1850 | // Replace RT_HAS_MSAA with this definition once this driver bug is no longer a relevant concern |
| 1851 | #define RT_HAS_MSAA rt->isMultisampled() |
| 1852 | #else |
| 1853 | #define RT_HAS_MSAA (rt->isMultisampled() || kDrawLines_DrawType == type) |
| 1854 | #endif |
| 1855 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1856 | const GrRenderTarget* rt = this->getDrawState().getRenderTarget(); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1857 | if (kDesktop_GrGLBinding == this->glBinding()) { |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 1858 | // ES doesn't support toggling GL_MULTISAMPLE and doesn't have |
| 1859 | // smooth lines. |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 1860 | // we prefer smooth lines over multisampled lines |
bsalomon@google.com | 4d5f3fe | 2012-05-21 17:11:44 +0000 | [diff] [blame] | 1861 | bool smoothLines = false; |
| 1862 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1863 | if (kDrawLines_DrawType == type) { |
bsalomon@google.com | 4d5f3fe | 2012-05-21 17:11:44 +0000 | [diff] [blame] | 1864 | smoothLines = this->willUseHWAALines(); |
| 1865 | if (smoothLines) { |
| 1866 | if (kYes_TriState != fHWAAState.fSmoothLineEnabled) { |
| 1867 | GL_CALL(Enable(GR_GL_LINE_SMOOTH)); |
| 1868 | fHWAAState.fSmoothLineEnabled = kYes_TriState; |
| 1869 | // must disable msaa to use line smoothing |
bsalomon@google.com | 202d139 | 2013-03-19 18:58:08 +0000 | [diff] [blame] | 1870 | if (RT_HAS_MSAA && |
bsalomon@google.com | 4d5f3fe | 2012-05-21 17:11:44 +0000 | [diff] [blame] | 1871 | kNo_TriState != fHWAAState.fMSAAEnabled) { |
| 1872 | GL_CALL(Disable(GR_GL_MULTISAMPLE)); |
| 1873 | fHWAAState.fMSAAEnabled = kNo_TriState; |
| 1874 | } |
| 1875 | } |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 1876 | } else { |
bsalomon@google.com | 4d5f3fe | 2012-05-21 17:11:44 +0000 | [diff] [blame] | 1877 | if (kNo_TriState != fHWAAState.fSmoothLineEnabled) { |
| 1878 | GL_CALL(Disable(GR_GL_LINE_SMOOTH)); |
| 1879 | fHWAAState.fSmoothLineEnabled = kNo_TriState; |
| 1880 | } |
| 1881 | } |
| 1882 | } |
bsalomon@google.com | 202d139 | 2013-03-19 18:58:08 +0000 | [diff] [blame] | 1883 | if (!smoothLines && RT_HAS_MSAA) { |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 1884 | // FIXME: GL_NV_pr doesn't seem to like MSAA disabled. The paths |
| 1885 | // convex hulls of each segment appear to get filled. |
| 1886 | bool enableMSAA = kStencilPath_DrawType == type || |
| 1887 | this->getDrawState().isHWAntialiasState(); |
| 1888 | if (enableMSAA) { |
bsalomon@google.com | 4d5f3fe | 2012-05-21 17:11:44 +0000 | [diff] [blame] | 1889 | if (kYes_TriState != fHWAAState.fMSAAEnabled) { |
| 1890 | GL_CALL(Enable(GR_GL_MULTISAMPLE)); |
| 1891 | fHWAAState.fMSAAEnabled = kYes_TriState; |
| 1892 | } |
| 1893 | } else { |
| 1894 | if (kNo_TriState != fHWAAState.fMSAAEnabled) { |
| 1895 | GL_CALL(Disable(GR_GL_MULTISAMPLE)); |
| 1896 | fHWAAState.fMSAAEnabled = kNo_TriState; |
| 1897 | } |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 1898 | } |
| 1899 | } |
| 1900 | } |
| 1901 | } |
| 1902 | |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 1903 | void GrGpuGL::flushBlend(bool isLines, |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1904 | GrBlendCoeff srcCoeff, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1905 | GrBlendCoeff dstCoeff) { |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 1906 | if (isLines && this->willUseHWAALines()) { |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 1907 | if (kYes_TriState != fHWBlendState.fEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1908 | GL_CALL(Enable(GR_GL_BLEND)); |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 1909 | fHWBlendState.fEnabled = kYes_TriState; |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1910 | } |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 1911 | if (kSA_GrBlendCoeff != fHWBlendState.fSrcCoeff || |
| 1912 | kISA_GrBlendCoeff != fHWBlendState.fDstCoeff) { |
| 1913 | GL_CALL(BlendFunc(gXfermodeCoeff2Blend[kSA_GrBlendCoeff], |
| 1914 | gXfermodeCoeff2Blend[kISA_GrBlendCoeff])); |
| 1915 | fHWBlendState.fSrcCoeff = kSA_GrBlendCoeff; |
| 1916 | fHWBlendState.fDstCoeff = kISA_GrBlendCoeff; |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1917 | } |
| 1918 | } else { |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1919 | // any optimization to disable blending should |
| 1920 | // have already been applied and tweaked the coeffs |
| 1921 | // to (1, 0). |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 1922 | bool blendOff = kOne_GrBlendCoeff == srcCoeff && |
| 1923 | kZero_GrBlendCoeff == dstCoeff; |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 1924 | if (blendOff) { |
| 1925 | if (kNo_TriState != fHWBlendState.fEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1926 | GL_CALL(Disable(GR_GL_BLEND)); |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 1927 | fHWBlendState.fEnabled = kNo_TriState; |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1928 | } |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 1929 | } else { |
| 1930 | if (kYes_TriState != fHWBlendState.fEnabled) { |
| 1931 | GL_CALL(Enable(GR_GL_BLEND)); |
| 1932 | fHWBlendState.fEnabled = kYes_TriState; |
| 1933 | } |
| 1934 | if (fHWBlendState.fSrcCoeff != srcCoeff || |
| 1935 | fHWBlendState.fDstCoeff != dstCoeff) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1936 | GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff], |
| 1937 | gXfermodeCoeff2Blend[dstCoeff])); |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 1938 | fHWBlendState.fSrcCoeff = srcCoeff; |
| 1939 | fHWBlendState.fDstCoeff = dstCoeff; |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1940 | } |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 1941 | GrColor blendConst = this->getDrawState().getBlendConstant(); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1942 | if ((BlendCoeffReferencesConstant(srcCoeff) || |
| 1943 | BlendCoeffReferencesConstant(dstCoeff)) && |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 1944 | (!fHWBlendState.fConstColorValid || |
| 1945 | fHWBlendState.fConstColor != blendConst)) { |
bsalomon@google.com | 7534747 | 2012-09-17 17:23:21 +0000 | [diff] [blame] | 1946 | GrGLfloat c[4]; |
| 1947 | GrColorToRGBAFloat(blendConst, c); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1948 | GL_CALL(BlendColor(c[0], c[1], c[2], c[3])); |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 1949 | fHWBlendState.fConstColor = blendConst; |
| 1950 | fHWBlendState.fConstColorValid = true; |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 1951 | } |
| 1952 | } |
| 1953 | } |
| 1954 | } |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1955 | namespace { |
| 1956 | |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 1957 | inline void set_tex_swizzle(GrGLenum swizzle[4], const GrGLInterface* gl) { |
bsalomon@google.com | 4d063de | 2012-05-31 17:59:23 +0000 | [diff] [blame] | 1958 | GR_GL_CALL(gl, TexParameteriv(GR_GL_TEXTURE_2D, |
| 1959 | GR_GL_TEXTURE_SWIZZLE_RGBA, |
| 1960 | reinterpret_cast<const GrGLint*>(swizzle))); |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1961 | } |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 1962 | |
bsalomon@google.com | 6c76d24 | 2012-09-07 16:52:24 +0000 | [diff] [blame] | 1963 | inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) { |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 1964 | static const GrGLenum gWrapModes[] = { |
| 1965 | GR_GL_CLAMP_TO_EDGE, |
| 1966 | GR_GL_REPEAT, |
| 1967 | GR_GL_MIRRORED_REPEAT |
| 1968 | }; |
| 1969 | GrAssert((unsigned) tm <= SK_ARRAY_COUNT(gWrapModes)); |
| 1970 | GR_STATIC_ASSERT(0 == SkShader::kClamp_TileMode); |
| 1971 | GR_STATIC_ASSERT(1 == SkShader::kRepeat_TileMode); |
| 1972 | GR_STATIC_ASSERT(2 == SkShader::kMirror_TileMode); |
| 1973 | return gWrapModes[tm]; |
| 1974 | } |
| 1975 | |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1976 | } |
| 1977 | |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 1978 | void GrGpuGL::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* texture) { |
| 1979 | GrAssert(NULL != texture); |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 1980 | |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 1981 | // If we created a rt/tex and rendered to it without using a texture and now we're texturing |
| 1982 | // from the rt it will still be the last bound texture, but it needs resolving. So keep this |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 1983 | // out of the "last != next" check. |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 1984 | GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderTarget()); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 1985 | if (NULL != texRT) { |
| 1986 | this->onResolveRenderTarget(texRT); |
| 1987 | } |
| 1988 | |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 1989 | if (fHWBoundTextures[unitIdx] != texture) { |
| 1990 | this->setTextureUnit(unitIdx); |
| 1991 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, texture->textureID())); |
| 1992 | fHWBoundTextures[unitIdx] = texture; |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 1993 | } |
| 1994 | |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 1995 | ResetTimestamp timestamp; |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 1996 | const GrGLTexture::TexParams& oldTexParams = texture->getCachedTexParams(×tamp); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 1997 | bool setAll = timestamp < this->getResetTimestamp(); |
| 1998 | GrGLTexture::TexParams newTexParams; |
| 1999 | |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 2000 | newTexParams.fFilter = params.isBilerp() ? GR_GL_LINEAR : GR_GL_NEAREST; |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2001 | |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 2002 | newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX()); |
| 2003 | newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY()); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2004 | memcpy(newTexParams.fSwizzleRGBA, |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2005 | GrGLShaderBuilder::GetTexParamSwizzle(texture->config(), this->glCaps()), |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2006 | sizeof(newTexParams.fSwizzleRGBA)); |
| 2007 | if (setAll || newTexParams.fFilter != oldTexParams.fFilter) { |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2008 | this->setTextureUnit(unitIdx); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2009 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 2010 | GR_GL_TEXTURE_MAG_FILTER, |
| 2011 | newTexParams.fFilter)); |
| 2012 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 2013 | GR_GL_TEXTURE_MIN_FILTER, |
| 2014 | newTexParams.fFilter)); |
| 2015 | } |
| 2016 | if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) { |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2017 | this->setTextureUnit(unitIdx); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2018 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 2019 | GR_GL_TEXTURE_WRAP_S, |
| 2020 | newTexParams.fWrapS)); |
| 2021 | } |
| 2022 | if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) { |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2023 | this->setTextureUnit(unitIdx); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2024 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 2025 | GR_GL_TEXTURE_WRAP_T, |
| 2026 | newTexParams.fWrapT)); |
| 2027 | } |
| 2028 | if (this->glCaps().textureSwizzleSupport() && |
| 2029 | (setAll || memcmp(newTexParams.fSwizzleRGBA, |
| 2030 | oldTexParams.fSwizzleRGBA, |
| 2031 | sizeof(newTexParams.fSwizzleRGBA)))) { |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2032 | this->setTextureUnit(unitIdx); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2033 | set_tex_swizzle(newTexParams.fSwizzleRGBA, |
| 2034 | this->glInterface()); |
| 2035 | } |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2036 | texture->setCachedTexParams(newTexParams, this->getResetTimestamp()); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2037 | } |
| 2038 | |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 2039 | void GrGpuGL::flushMiscFixedFunctionState() { |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 2040 | |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 2041 | const GrDrawState& drawState = this->getDrawState(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2042 | |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 2043 | if (drawState.isDitherState()) { |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 2044 | if (kYes_TriState != fHWDitherEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2045 | GL_CALL(Enable(GR_GL_DITHER)); |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 2046 | fHWDitherEnabled = kYes_TriState; |
| 2047 | } |
| 2048 | } else { |
| 2049 | if (kNo_TriState != fHWDitherEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2050 | GL_CALL(Disable(GR_GL_DITHER)); |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 2051 | fHWDitherEnabled = kNo_TriState; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2052 | } |
| 2053 | } |
| 2054 | |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 2055 | if (drawState.isColorWriteDisabled()) { |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 2056 | if (kNo_TriState != fHWWriteToColor) { |
| 2057 | GL_CALL(ColorMask(GR_GL_FALSE, GR_GL_FALSE, |
| 2058 | GR_GL_FALSE, GR_GL_FALSE)); |
| 2059 | fHWWriteToColor = kNo_TriState; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2060 | } |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 2061 | } else { |
| 2062 | if (kYes_TriState != fHWWriteToColor) { |
| 2063 | GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE)); |
| 2064 | fHWWriteToColor = kYes_TriState; |
| 2065 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2066 | } |
| 2067 | |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 2068 | if (fHWDrawFace != drawState.getDrawFace()) { |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 2069 | switch (this->getDrawState().getDrawFace()) { |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 2070 | case GrDrawState::kCCW_DrawFace: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2071 | GL_CALL(Enable(GR_GL_CULL_FACE)); |
| 2072 | GL_CALL(CullFace(GR_GL_BACK)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2073 | break; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 2074 | case GrDrawState::kCW_DrawFace: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2075 | GL_CALL(Enable(GR_GL_CULL_FACE)); |
| 2076 | GL_CALL(CullFace(GR_GL_FRONT)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2077 | break; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 2078 | case GrDrawState::kBoth_DrawFace: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2079 | GL_CALL(Disable(GR_GL_CULL_FACE)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2080 | break; |
| 2081 | default: |
| 2082 | GrCrash("Unknown draw face."); |
| 2083 | } |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 2084 | fHWDrawFace = drawState.getDrawFace(); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2085 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2086 | } |
| 2087 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2088 | void GrGpuGL::notifyRenderTargetDelete(GrRenderTarget* renderTarget) { |
| 2089 | GrAssert(NULL != renderTarget); |
bsalomon@google.com | c811ea3 | 2012-05-21 15:33:09 +0000 | [diff] [blame] | 2090 | if (fHWBoundRenderTarget == renderTarget) { |
| 2091 | fHWBoundRenderTarget = NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2092 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | void GrGpuGL::notifyTextureDelete(GrGLTexture* texture) { |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 2096 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
bsalomon@google.com | c811ea3 | 2012-05-21 15:33:09 +0000 | [diff] [blame] | 2097 | if (fHWBoundTextures[s] == texture) { |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2098 | // deleting bound texture does implied bind to 0 |
bsalomon@google.com | c811ea3 | 2012-05-21 15:33:09 +0000 | [diff] [blame] | 2099 | fHWBoundTextures[s] = NULL; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2100 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2101 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2102 | } |
| 2103 | |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2104 | bool GrGpuGL::configToGLFormats(GrPixelConfig config, |
| 2105 | bool getSizedInternalFormat, |
| 2106 | GrGLenum* internalFormat, |
| 2107 | GrGLenum* externalFormat, |
| 2108 | GrGLenum* externalType) { |
| 2109 | GrGLenum dontCare; |
| 2110 | if (NULL == internalFormat) { |
| 2111 | internalFormat = &dontCare; |
| 2112 | } |
| 2113 | if (NULL == externalFormat) { |
| 2114 | externalFormat = &dontCare; |
| 2115 | } |
| 2116 | if (NULL == externalType) { |
| 2117 | externalType = &dontCare; |
| 2118 | } |
| 2119 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2120 | switch (config) { |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 2121 | case kRGBA_8888_GrPixelConfig: |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 2122 | *internalFormat = GR_GL_RGBA; |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2123 | *externalFormat = GR_GL_RGBA; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2124 | if (getSizedInternalFormat) { |
| 2125 | *internalFormat = GR_GL_RGBA8; |
| 2126 | } else { |
| 2127 | *internalFormat = GR_GL_RGBA; |
| 2128 | } |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 2129 | *externalType = GR_GL_UNSIGNED_BYTE; |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 2130 | break; |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 2131 | case kBGRA_8888_GrPixelConfig: |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 2132 | if (!this->glCaps().bgraFormatSupport()) { |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 2133 | return false; |
| 2134 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 2135 | if (this->glCaps().bgraIsInternalFormat()) { |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2136 | if (getSizedInternalFormat) { |
| 2137 | *internalFormat = GR_GL_BGRA8; |
| 2138 | } else { |
| 2139 | *internalFormat = GR_GL_BGRA; |
| 2140 | } |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 2141 | } else { |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2142 | if (getSizedInternalFormat) { |
| 2143 | *internalFormat = GR_GL_RGBA8; |
| 2144 | } else { |
| 2145 | *internalFormat = GR_GL_RGBA; |
| 2146 | } |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 2147 | } |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2148 | *externalFormat = GR_GL_BGRA; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 2149 | *externalType = GR_GL_UNSIGNED_BYTE; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2150 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2151 | case kRGB_565_GrPixelConfig: |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2152 | *internalFormat = GR_GL_RGB; |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2153 | *externalFormat = GR_GL_RGB; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2154 | if (getSizedInternalFormat) { |
| 2155 | if (this->glBinding() == kDesktop_GrGLBinding) { |
| 2156 | return false; |
| 2157 | } else { |
| 2158 | *internalFormat = GR_GL_RGB565; |
| 2159 | } |
| 2160 | } else { |
| 2161 | *internalFormat = GR_GL_RGB; |
| 2162 | } |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 2163 | *externalType = GR_GL_UNSIGNED_SHORT_5_6_5; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2164 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2165 | case kRGBA_4444_GrPixelConfig: |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2166 | *internalFormat = GR_GL_RGBA; |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2167 | *externalFormat = GR_GL_RGBA; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2168 | if (getSizedInternalFormat) { |
| 2169 | *internalFormat = GR_GL_RGBA4; |
| 2170 | } else { |
| 2171 | *internalFormat = GR_GL_RGBA; |
| 2172 | } |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 2173 | *externalType = GR_GL_UNSIGNED_SHORT_4_4_4_4; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2174 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2175 | case kIndex_8_GrPixelConfig: |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 2176 | if (this->caps()->eightBitPaletteSupport()) { |
bsalomon@google.com | c312bf9 | 2011-03-21 21:10:33 +0000 | [diff] [blame] | 2177 | *internalFormat = GR_GL_PALETTE8_RGBA8; |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2178 | // glCompressedTexImage doesn't take external params |
| 2179 | *externalFormat = GR_GL_PALETTE8_RGBA8; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2180 | // no sized/unsized internal format distinction here |
| 2181 | *internalFormat = GR_GL_PALETTE8_RGBA8; |
| 2182 | // unused with CompressedTexImage |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2183 | *externalType = GR_GL_UNSIGNED_BYTE; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2184 | } else { |
| 2185 | return false; |
| 2186 | } |
| 2187 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2188 | case kAlpha_8_GrPixelConfig: |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 2189 | if (this->glCaps().textureRedSupport()) { |
| 2190 | *internalFormat = GR_GL_RED; |
| 2191 | *externalFormat = GR_GL_RED; |
| 2192 | if (getSizedInternalFormat) { |
| 2193 | *internalFormat = GR_GL_R8; |
| 2194 | } else { |
| 2195 | *internalFormat = GR_GL_RED; |
| 2196 | } |
| 2197 | *externalType = GR_GL_UNSIGNED_BYTE; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2198 | } else { |
| 2199 | *internalFormat = GR_GL_ALPHA; |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 2200 | *externalFormat = GR_GL_ALPHA; |
| 2201 | if (getSizedInternalFormat) { |
| 2202 | *internalFormat = GR_GL_ALPHA8; |
| 2203 | } else { |
| 2204 | *internalFormat = GR_GL_ALPHA; |
| 2205 | } |
| 2206 | *externalType = GR_GL_UNSIGNED_BYTE; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2207 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2208 | break; |
| 2209 | default: |
| 2210 | return false; |
| 2211 | } |
| 2212 | return true; |
| 2213 | } |
| 2214 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2215 | void GrGpuGL::setTextureUnit(int unit) { |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 2216 | GrAssert(unit >= 0 && unit < GrDrawState::kNumStages); |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 2217 | if (fHWActiveTextureUnitIdx != unit) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2218 | GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + unit)); |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 2219 | fHWActiveTextureUnitIdx = unit; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2220 | } |
| 2221 | } |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 2222 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2223 | void GrGpuGL::setSpareTextureUnit() { |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 2224 | if (fHWActiveTextureUnitIdx != (GR_GL_TEXTURE0 + SPARE_TEX_UNIT)) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2225 | GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + SPARE_TEX_UNIT)); |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 2226 | fHWActiveTextureUnitIdx = SPARE_TEX_UNIT; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2227 | } |
| 2228 | } |
| 2229 | |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 2230 | /////////////////////////////////////////////////////////////////////////////// |
| 2231 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 2232 | GrGLAttribArrayState* GrGpuGL::HWGeometryState::bindArrayAndBuffersToDraw( |
| 2233 | GrGpuGL* gpu, |
| 2234 | const GrGLVertexBuffer* vbuffer, |
| 2235 | const GrGLIndexBuffer* ibuffer) { |
| 2236 | GrAssert(NULL != vbuffer); |
robertphillips@google.com | 4f65a27 | 2013-03-26 19:40:46 +0000 | [diff] [blame] | 2237 | GrGLAttribArrayState* attribState; |
| 2238 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 2239 | // We use a vertex array if we're on a core profile and the verts are in a VBO. |
| 2240 | if (gpu->glCaps().isCoreProfile() && !vbuffer->isCPUBacked()) { |
| 2241 | if (NULL == fVBOVertexArray || !fVBOVertexArray->isValid()) { |
| 2242 | SkSafeUnref(fVBOVertexArray); |
| 2243 | GrGLuint arrayID; |
| 2244 | GR_GL_CALL(gpu->glInterface(), GenVertexArrays(1, &arrayID)); |
| 2245 | int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 2246 | fVBOVertexArray = SkNEW_ARGS(GrGLVertexArray, (gpu, arrayID, attrCount)); |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 2247 | } |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 2248 | attribState = fVBOVertexArray->bindWithIndexBuffer(ibuffer); |
| 2249 | } else { |
| 2250 | if (NULL != ibuffer) { |
| 2251 | this->setIndexBufferIDOnDefaultVertexArray(gpu, ibuffer->bufferID()); |
| 2252 | } else { |
| 2253 | this->setVertexArrayID(gpu, 0); |
| 2254 | } |
| 2255 | int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 2256 | if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 2257 | fDefaultVertexArrayAttribState.resize(attrCount); |
| 2258 | } |
| 2259 | attribState = &fDefaultVertexArrayAttribState; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 2260 | } |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 2261 | return attribState; |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 2262 | } |