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