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