reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2010 Google Inc. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | #include "GrGLConfig.h" |
| 19 | |
| 20 | #if GR_SUPPORT_GLES1 || GR_SUPPORT_GLDESKTOP |
| 21 | |
| 22 | #include "GrGpuGLFixed.h" |
| 23 | #include "GrGpuVertex.h" |
| 24 | |
| 25 | #define SKIP_CACHE_CHECK true |
| 26 | |
| 27 | struct GrGpuMatrix { |
| 28 | GrScalar fMat[16]; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 29 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 30 | void reset() { |
| 31 | Gr_bzero(fMat, sizeof(fMat)); |
| 32 | fMat[0] = fMat[5] = fMat[10] = fMat[15] = GR_Scalar1; |
| 33 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 34 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 35 | void set(const GrMatrix& m) { |
| 36 | Gr_bzero(fMat, sizeof(fMat)); |
| 37 | fMat[0] = m[GrMatrix::kScaleX]; |
| 38 | fMat[4] = m[GrMatrix::kSkewX]; |
| 39 | fMat[12] = m[GrMatrix::kTransX]; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 40 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 41 | fMat[1] = m[GrMatrix::kSkewY]; |
| 42 | fMat[5] = m[GrMatrix::kScaleY]; |
| 43 | fMat[13] = m[GrMatrix::kTransY]; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 44 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 45 | fMat[3] = m[GrMatrix::kPersp0]; |
| 46 | fMat[7] = m[GrMatrix::kPersp1]; |
| 47 | fMat[15] = m[GrMatrix::kPersp2]; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 48 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 49 | fMat[10] = GR_Scalar1; // z-scale |
| 50 | } |
| 51 | }; |
| 52 | |
| 53 | // these must match the order in the corresponding enum in GrGpu.h |
| 54 | static const GLenum gMatrixMode2Enum[] = { |
| 55 | GL_MODELVIEW, GL_TEXTURE |
| 56 | }; |
| 57 | |
| 58 | /////////////////////////////////////////////////////////////////////////////// |
| 59 | |
| 60 | GrGpuGLFixed::GrGpuGLFixed() { |
| 61 | resetContextHelper(); |
| 62 | } |
| 63 | |
| 64 | GrGpuGLFixed::~GrGpuGLFixed() { |
| 65 | } |
| 66 | |
| 67 | void GrGpuGLFixed::resetContext() { |
| 68 | INHERITED::resetContext(); |
| 69 | resetContextHelper(); |
| 70 | } |
| 71 | |
| 72 | void GrGpuGLFixed::resetContextHelper() { |
| 73 | GR_GL(Disable(GL_TEXTURE_2D)); |
| 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 | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 77 | GR_GL(EnableClientState(GL_VERTEX_ARRAY)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 78 | GR_GL(TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE)); |
| 79 | GR_GL(TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE)); |
| 80 | GR_GL(TexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE0+s)); |
| 81 | GR_GL(TexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS)); |
| 82 | GR_GL(TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 83 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 84 | GR_GL(TexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE)); |
| 85 | GR_GL(TexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE0+s)); |
| 86 | GR_GL(TexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA)); |
| 87 | GR_GL(TexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PREVIOUS)); |
| 88 | GR_GL(TexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA)); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 89 | |
| 90 | // color oprand0 changes between GL_SRC_COLR and GL_SRC_ALPHA depending |
| 91 | // 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] | 92 | // texture, e.g.: |
| 93 | //glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 94 | fHWRGBOperand0[s] = (TextureEnvRGBOperands) -1; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 95 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 96 | |
| 97 | fHWGeometryState.fVertexLayout = 0; |
| 98 | fHWGeometryState.fPositionPtr = (void*) ~0; |
| 99 | GR_GL(EnableClientState(GL_VERTEX_ARRAY)); |
| 100 | GR_GL(DisableClientState(GL_TEXTURE_COORD_ARRAY)); |
| 101 | GR_GL(ShadeModel(GL_FLAT)); |
| 102 | GR_GL(DisableClientState(GL_COLOR_ARRAY)); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 103 | |
| 104 | GR_GL(PointSize(1.f)); |
| 105 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 106 | GrGLClearErr(); |
| 107 | fTextVerts = false; |
| 108 | |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 109 | fHWTextureOrientation = (GrGLTexture::Orientation)-1; // illegal |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 110 | fBaseVertex = 0xffffffff; |
| 111 | } |
| 112 | |
| 113 | |
| 114 | void GrGpuGLFixed::flushProjectionMatrix() { |
| 115 | float mat[16]; |
| 116 | Gr_bzero(mat, sizeof(mat)); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 117 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 118 | GrAssert(NULL != fCurrDrawState.fRenderTarget); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 119 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 120 | mat[0] = 2.f / fCurrDrawState.fRenderTarget->width(); |
| 121 | mat[5] = -2.f / fCurrDrawState.fRenderTarget->height(); |
| 122 | mat[10] = -1.f; |
| 123 | mat[15] = 1; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 124 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 125 | mat[12] = -1.f; |
| 126 | mat[13] = 1.f; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 127 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 128 | GR_GL(MatrixMode(GL_PROJECTION)); |
| 129 | GR_GL(LoadMatrixf(mat)); |
| 130 | } |
| 131 | |
| 132 | bool GrGpuGLFixed::flushGraphicsState(PrimitiveType type) { |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 133 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 134 | bool usingTextures[kNumStages]; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 135 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 136 | for (int s = 0; s < kNumStages; ++s) { |
| 137 | usingTextures[s] = VertexUsesStage(s, fGeometrySrc.fVertexLayout); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 138 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 139 | if (usingTextures[s] && fCurrDrawState.fSamplerStates[s].isGradient()) { |
| 140 | unimpl("Fixed pipe doesn't support radial/sweep gradients"); |
| 141 | return false; |
| 142 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 143 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 144 | |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 145 | if (!flushGLStateCommon(type)) { |
| 146 | return false; |
| 147 | } |
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 | if (fRenderTargetChanged) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 150 | flushProjectionMatrix(); |
| 151 | fRenderTargetChanged = false; |
| 152 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 153 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 154 | for (int s = 0; s < kNumStages; ++s) { |
| 155 | bool wasUsingTexture = VertexUsesStage(s, fHWGeometryState.fVertexLayout); |
| 156 | if (usingTextures[s] != wasUsingTexture) { |
| 157 | setTextureUnit(s); |
| 158 | if (usingTextures[s]) { |
| 159 | GR_GL(Enable(GL_TEXTURE_2D)); |
| 160 | } else { |
| 161 | GR_GL(Disable(GL_TEXTURE_2D)); |
| 162 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 163 | } |
| 164 | } |
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 | uint32_t vertColor = (fGeometrySrc.fVertexLayout & kColor_VertexLayoutBit); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 167 | uint32_t prevVertColor = (fHWGeometryState.fVertexLayout & |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 168 | kColor_VertexLayoutBit); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 169 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 170 | if (vertColor != prevVertColor) { |
| 171 | if (vertColor) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 172 | GR_GL(ShadeModel(GL_SMOOTH)); |
| 173 | // invalidate the immediate mode color |
| 174 | fHWDrawState.fColor = GrColor_ILLEGAL; |
| 175 | } else { |
| 176 | GR_GL(ShadeModel(GL_FLAT)); |
| 177 | } |
| 178 | } |
| 179 | |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 180 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 181 | if (!vertColor && fHWDrawState.fColor != fCurrDrawState.fColor) { |
| 182 | GR_GL(Color4ub(GrColorUnpackR(fCurrDrawState.fColor), |
| 183 | GrColorUnpackG(fCurrDrawState.fColor), |
| 184 | GrColorUnpackB(fCurrDrawState.fColor), |
| 185 | GrColorUnpackA(fCurrDrawState.fColor))); |
| 186 | fHWDrawState.fColor = fCurrDrawState.fColor; |
| 187 | } |
| 188 | |
| 189 | // 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] | 190 | for (int s = 0; s < kNumStages; ++s) { |
| 191 | if (usingTextures[s]) { |
| 192 | GrGLTexture* texture = (GrGLTexture*)fCurrDrawState.fTextures[s]; |
| 193 | if (NULL != texture) { |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 194 | TextureEnvRGBOperands nextRGBOperand0 = |
| 195 | (texture->config() == GrTexture::kAlpha_8_PixelConfig) ? |
| 196 | kAlpha_TextureEnvRGBOperand : |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 197 | kColor_TextureEnvRGBOperand; |
| 198 | if (fHWRGBOperand0[s] != nextRGBOperand0) { |
| 199 | setTextureUnit(s); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 200 | GR_GL(TexEnvi(GL_TEXTURE_ENV, |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 201 | GL_OPERAND0_RGB, |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 202 | (nextRGBOperand0==kAlpha_TextureEnvRGBOperand) ? |
| 203 | GL_SRC_ALPHA : |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 204 | GL_SRC_COLOR)); |
| 205 | fHWRGBOperand0[s] = nextRGBOperand0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 206 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 207 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 208 | if (fHWTextureOrientation != texture->orientation() || |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 209 | fHWDrawState.fTextureMatrices[s] != |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 210 | fCurrDrawState.fTextureMatrices[s]) { |
| 211 | GrGpuMatrix glm; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 212 | if (GrGLTexture::kBottomUp_Orientation == |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 213 | texture->orientation()) { |
| 214 | GrMatrix m( |
| 215 | GR_Scalar1, 0, 0, |
| 216 | 0, -GR_Scalar1, GR_Scalar1, |
| 217 | 0, 0, GrMatrix::I()[8] |
| 218 | ); |
| 219 | m.preConcat(fCurrDrawState.fTextureMatrices[s]); |
| 220 | glm.set(m); |
| 221 | } else { |
| 222 | glm.set(fCurrDrawState.fTextureMatrices[s]); |
| 223 | } |
| 224 | setTextureUnit(s); |
| 225 | GR_GL(MatrixMode(GL_TEXTURE)); |
| 226 | GR_GL(LoadMatrixf(glm.fMat)); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 227 | fHWDrawState.fTextureMatrices[s] = |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 228 | fCurrDrawState.fTextureMatrices[s]; |
| 229 | fHWTextureOrientation = texture->orientation(); |
| 230 | } |
| 231 | } else { |
| 232 | GrAssert(!"Rendering with texture vert flag set but no bound texture"); |
| 233 | return false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 234 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 238 | if (fHWDrawState.fViewMatrix != fCurrDrawState.fViewMatrix) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 239 | GrGpuMatrix glm; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 240 | glm.set(fCurrDrawState.fViewMatrix); |
| 241 | GR_GL(MatrixMode(GL_MODELVIEW)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 242 | GR_GL(LoadMatrixf(glm.fMat)); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 243 | fHWDrawState.fViewMatrix = |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 244 | fCurrDrawState.fViewMatrix; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 245 | } |
| 246 | return true; |
| 247 | } |
| 248 | |
| 249 | void GrGpuGLFixed::setupGeometry(uint32_t startVertex, |
| 250 | uint32_t startIndex, |
| 251 | uint32_t vertexCount, |
| 252 | uint32_t indexCount) { |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 253 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 254 | int newColorOffset; |
| 255 | int newTexCoordOffsets[kNumStages]; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 256 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 257 | GLsizei newStride = VertexSizeAndOffsetsByStage(fGeometrySrc.fVertexLayout, |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 258 | newTexCoordOffsets, |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 259 | &newColorOffset); |
| 260 | int oldColorOffset; |
| 261 | int oldTexCoordOffsets[kNumStages]; |
| 262 | GLsizei oldStride = VertexSizeAndOffsetsByStage(fHWGeometryState.fVertexLayout, |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 263 | oldTexCoordOffsets, |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 264 | &oldColorOffset); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 265 | |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 266 | const GLvoid* posPtr = setBuffersAndGetVertexStart(newStride, startVertex, |
| 267 | startIndex, vertexCount, |
| 268 | indexCount); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 269 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 270 | GLenum scalarType; |
| 271 | if (fGeometrySrc.fVertexLayout & kTextFormat_VertexLayoutBit) { |
| 272 | scalarType = GrGLTextType; |
| 273 | } else { |
| 274 | scalarType = GrGLType; |
| 275 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 276 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 277 | bool baseChange = posPtr != fHWGeometryState.fPositionPtr; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 278 | bool scalarChange = |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 279 | (GrGLTextType != GrGLType) && |
| 280 | (kTextFormat_VertexLayoutBit & |
| 281 | (fHWGeometryState.fVertexLayout ^ fGeometrySrc.fVertexLayout)); |
| 282 | bool strideChange = newStride != oldStride; |
| 283 | bool posChange = baseChange || scalarChange || strideChange; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 284 | |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 285 | if (posChange || fHWGeometryState.fArrayPtrsDirty) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 286 | GR_GL(VertexPointer(2, scalarType, newStride, posPtr)); |
| 287 | fHWGeometryState.fPositionPtr = posPtr; |
| 288 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 289 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 290 | for (int s = 0; s < kNumStages; ++s) { |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 291 | // need to enable array if tex coord offset is 0 |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 292 | // (using positions as coords) |
| 293 | if (newTexCoordOffsets[s] >= 0) { |
| 294 | GLvoid* texCoordPtr = (int8_t*)posPtr + newTexCoordOffsets[s]; |
| 295 | if (oldTexCoordOffsets[s] < 0) { |
| 296 | GR_GL(ClientActiveTexture(GL_TEXTURE0+s)); |
| 297 | GR_GL(EnableClientState(GL_TEXTURE_COORD_ARRAY)); |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 298 | GR_GL(TexCoordPointer(2, scalarType, newStride, texCoordPtr)); |
| 299 | } else if (fHWGeometryState.fArrayPtrsDirty || posChange || |
| 300 | newTexCoordOffsets[s] != oldTexCoordOffsets[s]) { |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 301 | GR_GL(ClientActiveTexture(GL_TEXTURE0+s)); |
| 302 | GR_GL(TexCoordPointer(2, scalarType, newStride, texCoordPtr)); |
| 303 | } |
| 304 | } else if (oldTexCoordOffsets[s] >= 0) { |
| 305 | GR_GL(ClientActiveTexture(GL_TEXTURE0+s)); |
| 306 | GR_GL(DisableClientState(GL_TEXTURE_COORD_ARRAY)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 307 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 308 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 309 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 310 | if (newColorOffset > 0) { |
| 311 | GLvoid* colorPtr = (int8_t*)posPtr + newColorOffset; |
| 312 | if (oldColorOffset <= 0) { |
| 313 | GR_GL(EnableClientState(GL_COLOR_ARRAY)); |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 314 | GR_GL(ColorPointer(4, GL_UNSIGNED_BYTE, newStride, colorPtr)); |
| 315 | } else if (fHWGeometryState.fArrayPtrsDirty || posChange || |
| 316 | newColorOffset != oldColorOffset) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 317 | GR_GL(ColorPointer(4, GL_UNSIGNED_BYTE, newStride, colorPtr)); |
| 318 | } |
| 319 | } else if (oldColorOffset > 0) { |
| 320 | GR_GL(DisableClientState(GL_COLOR_ARRAY)); |
| 321 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 322 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 323 | fHWGeometryState.fVertexLayout = fGeometrySrc.fVertexLayout; |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 324 | fHWGeometryState.fArrayPtrsDirty = false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | #endif |
| 328 | |