epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #include "GrGLConfig.h" |
| 12 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 13 | #include "GrGpuGLFixed.h" |
| 14 | #include "GrGpuVertex.h" |
| 15 | |
| 16 | #define SKIP_CACHE_CHECK true |
| 17 | |
| 18 | struct GrGpuMatrix { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 19 | GrGLfloat fMat[16]; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 20 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 21 | void reset() { |
| 22 | Gr_bzero(fMat, sizeof(fMat)); |
| 23 | fMat[0] = fMat[5] = fMat[10] = fMat[15] = GR_Scalar1; |
| 24 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 25 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 26 | void set(const GrMatrix& m) { |
| 27 | Gr_bzero(fMat, sizeof(fMat)); |
bsalomon@google.com | cc4dac3 | 2011-05-10 13:52:42 +0000 | [diff] [blame] | 28 | fMat[0] = GrScalarToFloat(m[GrMatrix::kMScaleX]); |
| 29 | fMat[4] = GrScalarToFloat(m[GrMatrix::kMSkewX]); |
| 30 | fMat[12] = GrScalarToFloat(m[GrMatrix::kMTransX]); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 31 | |
bsalomon@google.com | cc4dac3 | 2011-05-10 13:52:42 +0000 | [diff] [blame] | 32 | fMat[1] = GrScalarToFloat(m[GrMatrix::kMSkewY]); |
| 33 | fMat[5] = GrScalarToFloat(m[GrMatrix::kMScaleY]); |
| 34 | fMat[13] = GrScalarToFloat(m[GrMatrix::kMTransY]); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 35 | |
bsalomon@google.com | cc4dac3 | 2011-05-10 13:52:42 +0000 | [diff] [blame] | 36 | fMat[3] = GrScalarToFloat(m[GrMatrix::kMPersp0]); |
| 37 | fMat[7] = GrScalarToFloat(m[GrMatrix::kMPersp1]); |
| 38 | fMat[15] = GrScalarToFloat(m[GrMatrix::kMPersp2]); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 39 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 40 | fMat[10] = 1.f; // z-scale |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 41 | } |
| 42 | }; |
| 43 | |
| 44 | // these must match the order in the corresponding enum in GrGpu.h |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 45 | static const GrGLenum gMatrixMode2Enum[] = { |
| 46 | GR_GL_MODELVIEW, GR_GL_TEXTURE |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 49 | #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 50 | /////////////////////////////////////////////////////////////////////////////// |
| 51 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 52 | namespace { |
| 53 | GrGLBinding get_binding_in_use(const GrGLInterface* gl) { |
| 54 | if (gl->supportsDesktop()) { |
| 55 | return kDesktop_GrGLBinding; |
| 56 | } else { |
| 57 | GrAssert(gl->supportsES1()); |
| 58 | return kES1_GrGLBinding; |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | GrGpuGLFixed::GrGpuGLFixed(const GrGLInterface* gl) |
| 64 | : GrGpuGL(gl, get_binding_in_use(gl)) { |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 65 | f4X4DownsampleFilterSupport = false; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 66 | fDualSourceBlendingSupport = false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | GrGpuGLFixed::~GrGpuGLFixed() { |
| 70 | } |
| 71 | |
| 72 | void GrGpuGLFixed::resetContext() { |
| 73 | INHERITED::resetContext(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 74 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 75 | GL_CALL(Disable(GR_GL_TEXTURE_2D)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 76 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 77 | for (int s = 0; s < kNumStages; ++s) { |
| 78 | setTextureUnit(s); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 79 | GL_CALL(EnableClientState(GR_GL_VERTEX_ARRAY)); |
| 80 | GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV, |
| 81 | GR_GL_TEXTURE_ENV_MODE, |
| 82 | GR_GL_COMBINE)); |
| 83 | GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV, |
| 84 | GR_GL_COMBINE_RGB, |
| 85 | GR_GL_MODULATE)); |
| 86 | GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV, |
| 87 | GR_GL_SRC0_RGB, |
| 88 | GR_GL_TEXTURE0+s)); |
| 89 | GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV, |
| 90 | GR_GL_SRC1_RGB, |
| 91 | GR_GL_PREVIOUS)); |
| 92 | GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV, |
| 93 | GR_GL_OPERAND1_RGB, |
| 94 | GR_GL_SRC_COLOR)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 95 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 96 | GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV, |
| 97 | GR_GL_COMBINE_ALPHA, |
| 98 | GR_GL_MODULATE)); |
| 99 | GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV, |
| 100 | GR_GL_SRC0_ALPHA, |
| 101 | GR_GL_TEXTURE0+s)); |
| 102 | GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV, |
| 103 | GR_GL_OPERAND0_ALPHA, |
| 104 | GR_GL_SRC_ALPHA)); |
| 105 | GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV, |
| 106 | GR_GL_SRC1_ALPHA, |
| 107 | GR_GL_PREVIOUS)); |
| 108 | GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV, |
| 109 | GR_GL_OPERAND1_ALPHA, |
| 110 | GR_GL_SRC_ALPHA)); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 111 | |
| 112 | // color oprand0 changes between GL_SRC_COLR and GL_SRC_ALPHA depending |
| 113 | // upon whether we have a (premultiplied) RGBA texture or just an ALPHA |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 114 | // texture, e.g.: |
| 115 | //glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 116 | fHWRGBOperand0[s] = (TextureEnvRGBOperands) -1; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 117 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 118 | |
| 119 | fHWGeometryState.fVertexLayout = 0; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 120 | fHWGeometryState.fVertexOffset = ~0; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 121 | GL_CALL(EnableClientState(GR_GL_VERTEX_ARRAY)); |
| 122 | GL_CALL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY)); |
| 123 | GL_CALL(ShadeModel(GR_GL_FLAT)); |
| 124 | GL_CALL(DisableClientState(GR_GL_COLOR_ARRAY)); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 125 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 126 | GL_CALL(PointSize(1.f)); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 127 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 128 | GrGLClearErr(this->glInterface()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 129 | fTextVerts = false; |
| 130 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 131 | fBaseVertex = 0xffffffff; |
| 132 | } |
| 133 | |
| 134 | |
| 135 | void GrGpuGLFixed::flushProjectionMatrix() { |
| 136 | float mat[16]; |
| 137 | Gr_bzero(mat, sizeof(mat)); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 138 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 139 | GrAssert(NULL != fCurrDrawState.fRenderTarget); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 140 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 141 | mat[0] = 2.f / fCurrDrawState.fRenderTarget->width(); |
| 142 | mat[5] = -2.f / fCurrDrawState.fRenderTarget->height(); |
| 143 | mat[10] = -1.f; |
| 144 | mat[15] = 1; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 145 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 146 | mat[12] = -1.f; |
| 147 | mat[13] = 1.f; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 148 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 149 | GL_CALL(MatrixMode(GR_GL_PROJECTION)); |
| 150 | GL_CALL(LoadMatrixf(mat)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 151 | } |
| 152 | |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 153 | bool GrGpuGLFixed::flushGraphicsState(GrPrimitiveType type) { |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 154 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 155 | bool usingTextures[kNumStages]; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 156 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 157 | for (int s = 0; s < kNumStages; ++s) { |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 158 | usingTextures[s] = this->isStageEnabled(s); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 159 | if (usingTextures[s] && fCurrDrawState.fSamplerStates[s].isGradient()) { |
| 160 | unimpl("Fixed pipe doesn't support radial/sweep gradients"); |
| 161 | return false; |
| 162 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 163 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 164 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 165 | if (kES1_GrGLBinding == this->glBinding()) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 166 | if (BlendCoeffReferencesConstant(fCurrDrawState.fSrcBlend) || |
| 167 | BlendCoeffReferencesConstant(fCurrDrawState.fDstBlend)) { |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 168 | unimpl("ES1 doesn't support blend constant"); |
| 169 | return false; |
| 170 | } |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 171 | } |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 172 | |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 173 | if (!flushGLStateCommon(type)) { |
| 174 | return false; |
| 175 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 176 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 177 | this->flushBlend(type, fCurrDrawState.fSrcBlend, fCurrDrawState.fDstBlend); |
| 178 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 179 | if (fDirtyFlags.fRenderTargetChanged) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 180 | flushProjectionMatrix(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 181 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 182 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 183 | for (int s = 0; s < kNumStages; ++s) { |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 184 | bool wasUsingTexture = StageWillBeUsed(s, fHWGeometryState.fVertexLayout, fHWDrawState); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 185 | if (usingTextures[s] != wasUsingTexture) { |
| 186 | setTextureUnit(s); |
| 187 | if (usingTextures[s]) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 188 | GL_CALL(Enable(GR_GL_TEXTURE_2D)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 189 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 190 | GL_CALL(Disable(GR_GL_TEXTURE_2D)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 191 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 192 | } |
| 193 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 194 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 195 | uint32_t vertColor = (this->getGeomSrc().fVertexLayout & kColor_VertexLayoutBit); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 196 | uint32_t prevVertColor = (fHWGeometryState.fVertexLayout & |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 197 | kColor_VertexLayoutBit); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 198 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 199 | if (vertColor != prevVertColor) { |
| 200 | if (vertColor) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 201 | GL_CALL(ShadeModel(GR_GL_SMOOTH)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 202 | // invalidate the immediate mode color |
| 203 | fHWDrawState.fColor = GrColor_ILLEGAL; |
| 204 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 205 | GL_CALL(ShadeModel(GR_GL_FLAT)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 209 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 210 | if (!vertColor && fHWDrawState.fColor != fCurrDrawState.fColor) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 211 | GL_CALL(Color4ub(GrColorUnpackR(fCurrDrawState.fColor), |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 212 | GrColorUnpackG(fCurrDrawState.fColor), |
| 213 | GrColorUnpackB(fCurrDrawState.fColor), |
| 214 | GrColorUnpackA(fCurrDrawState.fColor))); |
| 215 | fHWDrawState.fColor = fCurrDrawState.fColor; |
| 216 | } |
| 217 | |
| 218 | // set texture environment, decide whether we are modulating by RGB or A. |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 219 | for (int s = 0; s < kNumStages; ++s) { |
| 220 | if (usingTextures[s]) { |
| 221 | GrGLTexture* texture = (GrGLTexture*)fCurrDrawState.fTextures[s]; |
| 222 | if (NULL != texture) { |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 223 | TextureEnvRGBOperands nextRGBOperand0 = |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 224 | (GrPixelConfigIsAlphaOnly(texture->config())) ? |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 225 | kAlpha_TextureEnvRGBOperand : |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 226 | kColor_TextureEnvRGBOperand; |
| 227 | if (fHWRGBOperand0[s] != nextRGBOperand0) { |
| 228 | setTextureUnit(s); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 229 | GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV, |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 230 | GR_GL_OPERAND0_RGB, |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 231 | (nextRGBOperand0==kAlpha_TextureEnvRGBOperand) ? |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 232 | GR_GL_SRC_ALPHA : |
| 233 | GR_GL_SRC_COLOR)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 234 | fHWRGBOperand0[s] = nextRGBOperand0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 235 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 236 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 237 | if (((1 << s) & fDirtyFlags.fTextureChangedMask) || |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 238 | (fHWDrawState.fSamplerStates[s].getMatrix() != |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 239 | getSamplerMatrix(s))) { |
| 240 | |
| 241 | GrMatrix texMat = getSamplerMatrix(s); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 242 | AdjustTextureMatrix(texture, |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 243 | GrSamplerState::kNormal_SampleMode, |
| 244 | &texMat); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 245 | GrGpuMatrix glm; |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 246 | glm.set(texMat); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 247 | setTextureUnit(s); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 248 | GL_CALL(MatrixMode(GR_GL_TEXTURE)); |
| 249 | GL_CALL(LoadMatrixf(glm.fMat)); |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 250 | recordHWSamplerMatrix(s, getSamplerMatrix(s)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 251 | } |
| 252 | } else { |
| 253 | GrAssert(!"Rendering with texture vert flag set but no bound texture"); |
| 254 | return false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 255 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 256 | } |
| 257 | } |
| 258 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 259 | if (fHWDrawState.fViewMatrix != fCurrDrawState.fViewMatrix) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 260 | GrGpuMatrix glm; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 261 | glm.set(fCurrDrawState.fViewMatrix); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 262 | GL_CALL(MatrixMode(GR_GL_MODELVIEW)); |
| 263 | GL_CALL(LoadMatrixf(glm.fMat)); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 264 | fHWDrawState.fViewMatrix = |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 265 | fCurrDrawState.fViewMatrix; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 266 | } |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 267 | resetDirtyFlags(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 268 | return true; |
| 269 | } |
| 270 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 271 | void GrGpuGLFixed::setupGeometry(int* startVertex, |
| 272 | int* startIndex, |
| 273 | int vertexCount, |
| 274 | int indexCount) { |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 275 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 276 | int newColorOffset; |
| 277 | int newTexCoordOffsets[kNumStages]; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 278 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 279 | GrGLsizei newStride = VertexSizeAndOffsetsByStage(this->getGeomSrc().fVertexLayout, |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 280 | newTexCoordOffsets, |
| 281 | &newColorOffset); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 282 | int oldColorOffset; |
| 283 | int oldTexCoordOffsets[kNumStages]; |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 284 | GrGLsizei oldStride = VertexSizeAndOffsetsByStage(fHWGeometryState.fVertexLayout, |
| 285 | oldTexCoordOffsets, |
| 286 | &oldColorOffset); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 287 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 288 | bool indexed = NULL != startIndex; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 289 | |
| 290 | int extraVertexOffset; |
| 291 | int extraIndexOffset; |
| 292 | setBuffers(indexed, &extraVertexOffset, &extraIndexOffset); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 293 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 294 | GrGLenum scalarType; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 295 | if (this->getGeomSrc().fVertexLayout & kTextFormat_VertexLayoutBit) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 296 | scalarType = GrGLTextType; |
| 297 | } else { |
| 298 | scalarType = GrGLType; |
| 299 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 300 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 301 | size_t vertexOffset = (*startVertex + extraVertexOffset) * newStride; |
| 302 | *startVertex = 0; |
| 303 | if (indexed) { |
| 304 | *startIndex += extraIndexOffset; |
| 305 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 306 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 307 | // all the Pointers must be set if any of these are true |
| 308 | bool allOffsetsChange = fHWGeometryState.fArrayPtrsDirty || |
| 309 | vertexOffset != fHWGeometryState.fVertexOffset || |
| 310 | newStride != oldStride; |
| 311 | |
| 312 | // position and tex coord offsets change if above conditions are true |
| 313 | // or the type changed based on text vs nontext type coords. |
| 314 | bool posAndTexChange = allOffsetsChange || |
| 315 | ((GrGLTextType != GrGLType) && |
| 316 | (kTextFormat_VertexLayoutBit & |
| 317 | (fHWGeometryState.fVertexLayout ^ |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 318 | this->getGeomSrc().fVertexLayout))); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 319 | |
| 320 | if (posAndTexChange) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 321 | GL_CALL(VertexPointer(2, scalarType, |
| 322 | newStride, (GrGLvoid*)vertexOffset)); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 323 | fHWGeometryState.fVertexOffset = vertexOffset; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 324 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 325 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 326 | for (int s = 0; s < kNumStages; ++s) { |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 327 | // need to enable array if tex coord offset is 0 |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 328 | // (using positions as coords) |
| 329 | if (newTexCoordOffsets[s] >= 0) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 330 | GrGLvoid* texCoordOffset = (GrGLvoid*)(vertexOffset + |
| 331 | newTexCoordOffsets[s]); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 332 | if (oldTexCoordOffsets[s] < 0) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 333 | GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s)); |
| 334 | GL_CALL(EnableClientState(GR_GL_TEXTURE_COORD_ARRAY)); |
| 335 | GL_CALL(TexCoordPointer(2, scalarType, |
| 336 | newStride, texCoordOffset)); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 337 | } else if (posAndTexChange || |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 338 | newTexCoordOffsets[s] != oldTexCoordOffsets[s]) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 339 | GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s)); |
| 340 | GL_CALL(TexCoordPointer(2, scalarType, |
| 341 | newStride, texCoordOffset)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 342 | } |
| 343 | } else if (oldTexCoordOffsets[s] >= 0) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 344 | GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s)); |
| 345 | GL_CALL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 346 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 347 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 348 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 349 | if (newColorOffset > 0) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 350 | GrGLvoid* colorOffset = (GrGLvoid*)(vertexOffset + newColorOffset); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 351 | if (oldColorOffset <= 0) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 352 | GL_CALL(EnableClientState(GR_GL_COLOR_ARRAY)); |
| 353 | GL_CALL(ColorPointer(4, GR_GL_UNSIGNED_BYTE, |
| 354 | newStride, colorOffset)); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 355 | } else if (allOffsetsChange || newColorOffset != oldColorOffset) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 356 | GL_CALL(ColorPointer(4, GR_GL_UNSIGNED_BYTE, |
| 357 | newStride, colorOffset)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 358 | } |
| 359 | } else if (oldColorOffset > 0) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 360 | GL_CALL(DisableClientState(GR_GL_COLOR_ARRAY)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 361 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 362 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 363 | fHWGeometryState.fVertexLayout = this->getGeomSrc().fVertexLayout; |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 364 | fHWGeometryState.fArrayPtrsDirty = false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 365 | } |