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