blob: c9d5844b4fe8db3d57933f41914bce714b5024cd [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.comac10a2d2010-12-22 21:39:39 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
reed@google.comac10a2d2010-12-22 21:39:39 +000011#include "GrGLConfig.h"
12
reed@google.comac10a2d2010-12-22 21:39:39 +000013#include "GrGpuGLFixed.h"
14#include "GrGpuVertex.h"
15
16#define SKIP_CACHE_CHECK true
17
18struct GrGpuMatrix {
twiz@google.com0f31ca72011-03-18 17:38:11 +000019 GrGLfloat fMat[16];
bsalomon@google.com5782d712011-01-21 21:03:59 +000020
reed@google.comac10a2d2010-12-22 21:39:39 +000021 void reset() {
22 Gr_bzero(fMat, sizeof(fMat));
23 fMat[0] = fMat[5] = fMat[10] = fMat[15] = GR_Scalar1;
24 }
bsalomon@google.com5782d712011-01-21 21:03:59 +000025
reed@google.comac10a2d2010-12-22 21:39:39 +000026 void set(const GrMatrix& m) {
27 Gr_bzero(fMat, sizeof(fMat));
bsalomon@google.comcc4dac32011-05-10 13:52:42 +000028 fMat[0] = GrScalarToFloat(m[GrMatrix::kMScaleX]);
29 fMat[4] = GrScalarToFloat(m[GrMatrix::kMSkewX]);
30 fMat[12] = GrScalarToFloat(m[GrMatrix::kMTransX]);
bsalomon@google.com5782d712011-01-21 21:03:59 +000031
bsalomon@google.comcc4dac32011-05-10 13:52:42 +000032 fMat[1] = GrScalarToFloat(m[GrMatrix::kMSkewY]);
33 fMat[5] = GrScalarToFloat(m[GrMatrix::kMScaleY]);
34 fMat[13] = GrScalarToFloat(m[GrMatrix::kMTransY]);
bsalomon@google.com5782d712011-01-21 21:03:59 +000035
bsalomon@google.comcc4dac32011-05-10 13:52:42 +000036 fMat[3] = GrScalarToFloat(m[GrMatrix::kMPersp0]);
37 fMat[7] = GrScalarToFloat(m[GrMatrix::kMPersp1]);
38 fMat[15] = GrScalarToFloat(m[GrMatrix::kMPersp2]);
bsalomon@google.com5782d712011-01-21 21:03:59 +000039
bsalomon@google.comc6cf7232011-02-17 16:43:10 +000040 fMat[10] = 1.f; // z-scale
reed@google.comac10a2d2010-12-22 21:39:39 +000041 }
42};
43
44// these must match the order in the corresponding enum in GrGpu.h
twiz@google.com0f31ca72011-03-18 17:38:11 +000045static const GrGLenum gMatrixMode2Enum[] = {
46 GR_GL_MODELVIEW, GR_GL_TEXTURE
reed@google.comac10a2d2010-12-22 21:39:39 +000047};
48
bsalomon@google.com0b77d682011-08-19 13:28:54 +000049#define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
reed@google.comac10a2d2010-12-22 21:39:39 +000050///////////////////////////////////////////////////////////////////////////////
51
bsalomon@google.com0b77d682011-08-19 13:28:54 +000052namespace {
53GrGLBinding 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
63GrGpuGLFixed::GrGpuGLFixed(const GrGLInterface* gl)
64 : GrGpuGL(gl, get_binding_in_use(gl)) {
reed@google.comac10a2d2010-12-22 21:39:39 +000065}
66
67GrGpuGLFixed::~GrGpuGLFixed() {
68}
69
70void GrGpuGLFixed::resetContext() {
71 INHERITED::resetContext();
reed@google.comac10a2d2010-12-22 21:39:39 +000072
bsalomon@google.com0b77d682011-08-19 13:28:54 +000073 GL_CALL(Disable(GR_GL_TEXTURE_2D));
reed@google.comac10a2d2010-12-22 21:39:39 +000074
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000075 for (int s = 0; s < kNumStages; ++s) {
76 setTextureUnit(s);
bsalomon@google.com0b77d682011-08-19 13:28:54 +000077 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.comac10a2d2010-12-22 21:39:39 +000093
bsalomon@google.com0b77d682011-08-19 13:28:54 +000094 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.com5782d712011-01-21 21:03:59 +0000109
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.com8531c1c2011-01-13 19:52:45 +0000112 // texture, e.g.:
113 //glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000114 fHWRGBOperand0[s] = (TextureEnvRGBOperands) -1;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000115 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000116
117 fHWGeometryState.fVertexLayout = 0;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000118 fHWGeometryState.fVertexOffset = ~0;
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000119 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.com5782d712011-01-21 21:03:59 +0000123
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000124 GL_CALL(PointSize(1.f));
bsalomon@google.com5782d712011-01-21 21:03:59 +0000125
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000126 GrGLClearErr(this->glInterface());
reed@google.comac10a2d2010-12-22 21:39:39 +0000127 fTextVerts = false;
128
reed@google.comac10a2d2010-12-22 21:39:39 +0000129 fBaseVertex = 0xffffffff;
130}
131
132
133void GrGpuGLFixed::flushProjectionMatrix() {
134 float mat[16];
135 Gr_bzero(mat, sizeof(mat));
bsalomon@google.com5782d712011-01-21 21:03:59 +0000136
reed@google.comac10a2d2010-12-22 21:39:39 +0000137 GrAssert(NULL != fCurrDrawState.fRenderTarget);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000138
reed@google.comac10a2d2010-12-22 21:39:39 +0000139 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.com5782d712011-01-21 21:03:59 +0000143
reed@google.comac10a2d2010-12-22 21:39:39 +0000144 mat[12] = -1.f;
145 mat[13] = 1.f;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000146
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000147 GL_CALL(MatrixMode(GR_GL_PROJECTION));
148 GL_CALL(LoadMatrixf(mat));
reed@google.comac10a2d2010-12-22 21:39:39 +0000149}
150
bsalomon@google.comffca4002011-02-22 20:34:01 +0000151bool GrGpuGLFixed::flushGraphicsState(GrPrimitiveType type) {
bsalomon@google.com5782d712011-01-21 21:03:59 +0000152
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000153 bool usingTextures[kNumStages];
bsalomon@google.com5782d712011-01-21 21:03:59 +0000154
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000155 for (int s = 0; s < kNumStages; ++s) {
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000156 usingTextures[s] = this->isStageEnabled(s);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000157 if (usingTextures[s] && fCurrDrawState.fSamplerStates[s].isGradient()) {
158 unimpl("Fixed pipe doesn't support radial/sweep gradients");
159 return false;
160 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000161 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000162
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000163 if (kES1_GrGLBinding == this->glBinding()) {
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000164 if (BlendCoeffReferencesConstant(fCurrDrawState.fSrcBlend) ||
165 BlendCoeffReferencesConstant(fCurrDrawState.fDstBlend)) {
twiz@google.comb65e0cb2011-03-18 20:41:44 +0000166 unimpl("ES1 doesn't support blend constant");
167 return false;
168 }
bsalomon@google.com080773c2011-03-15 19:09:25 +0000169 }
bsalomon@google.com080773c2011-03-15 19:09:25 +0000170
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000171 if (!flushGLStateCommon(type)) {
172 return false;
173 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000174
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000175 this->flushBlend(type, fCurrDrawState.fSrcBlend, fCurrDrawState.fDstBlend);
176
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000177 if (fDirtyFlags.fRenderTargetChanged) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000178 flushProjectionMatrix();
reed@google.comac10a2d2010-12-22 21:39:39 +0000179 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000180
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000181 for (int s = 0; s < kNumStages; ++s) {
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000182 bool wasUsingTexture = StageWillBeUsed(s, fHWGeometryState.fVertexLayout, fHWDrawState);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000183 if (usingTextures[s] != wasUsingTexture) {
184 setTextureUnit(s);
185 if (usingTextures[s]) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000186 GL_CALL(Enable(GR_GL_TEXTURE_2D));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000187 } else {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000188 GL_CALL(Disable(GR_GL_TEXTURE_2D));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000189 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000190 }
191 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000192
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000193 uint32_t vertColor = (this->getGeomSrc().fVertexLayout & kColor_VertexLayoutBit);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000194 uint32_t prevVertColor = (fHWGeometryState.fVertexLayout &
reed@google.comac10a2d2010-12-22 21:39:39 +0000195 kColor_VertexLayoutBit);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000196
reed@google.comac10a2d2010-12-22 21:39:39 +0000197 if (vertColor != prevVertColor) {
198 if (vertColor) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000199 GL_CALL(ShadeModel(GR_GL_SMOOTH));
reed@google.comac10a2d2010-12-22 21:39:39 +0000200 // invalidate the immediate mode color
201 fHWDrawState.fColor = GrColor_ILLEGAL;
202 } else {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000203 GL_CALL(ShadeModel(GR_GL_FLAT));
reed@google.comac10a2d2010-12-22 21:39:39 +0000204 }
205 }
206
bsalomon@google.com5782d712011-01-21 21:03:59 +0000207
reed@google.comac10a2d2010-12-22 21:39:39 +0000208 if (!vertColor && fHWDrawState.fColor != fCurrDrawState.fColor) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000209 GL_CALL(Color4ub(GrColorUnpackR(fCurrDrawState.fColor),
reed@google.comac10a2d2010-12-22 21:39:39 +0000210 GrColorUnpackG(fCurrDrawState.fColor),
211 GrColorUnpackB(fCurrDrawState.fColor),
212 GrColorUnpackA(fCurrDrawState.fColor)));
213 fHWDrawState.fColor = fCurrDrawState.fColor;
214 }
215
216 // set texture environment, decide whether we are modulating by RGB or A.
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000217 for (int s = 0; s < kNumStages; ++s) {
218 if (usingTextures[s]) {
219 GrGLTexture* texture = (GrGLTexture*)fCurrDrawState.fTextures[s];
220 if (NULL != texture) {
bsalomon@google.com5782d712011-01-21 21:03:59 +0000221 TextureEnvRGBOperands nextRGBOperand0 =
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000222 (GrPixelConfigIsAlphaOnly(texture->config())) ?
bsalomon@google.com5782d712011-01-21 21:03:59 +0000223 kAlpha_TextureEnvRGBOperand :
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000224 kColor_TextureEnvRGBOperand;
225 if (fHWRGBOperand0[s] != nextRGBOperand0) {
226 setTextureUnit(s);
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000227 GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
twiz@google.com0f31ca72011-03-18 17:38:11 +0000228 GR_GL_OPERAND0_RGB,
bsalomon@google.com5782d712011-01-21 21:03:59 +0000229 (nextRGBOperand0==kAlpha_TextureEnvRGBOperand) ?
twiz@google.com0f31ca72011-03-18 17:38:11 +0000230 GR_GL_SRC_ALPHA :
231 GR_GL_SRC_COLOR));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000232 fHWRGBOperand0[s] = nextRGBOperand0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000233 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000234
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000235 if (((1 << s) & fDirtyFlags.fTextureChangedMask) ||
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000236 (fHWDrawState.fSamplerStates[s].getMatrix() !=
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000237 getSamplerMatrix(s))) {
238
239 GrMatrix texMat = getSamplerMatrix(s);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000240 AdjustTextureMatrix(texture,
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000241 GrSamplerState::kNormal_SampleMode,
242 &texMat);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000243 GrGpuMatrix glm;
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000244 glm.set(texMat);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000245 setTextureUnit(s);
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000246 GL_CALL(MatrixMode(GR_GL_TEXTURE));
247 GL_CALL(LoadMatrixf(glm.fMat));
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000248 recordHWSamplerMatrix(s, getSamplerMatrix(s));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000249 }
250 } else {
251 GrAssert(!"Rendering with texture vert flag set but no bound texture");
252 return false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000253 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000254 }
255 }
256
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000257 if (fHWDrawState.fViewMatrix != fCurrDrawState.fViewMatrix) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000258 GrGpuMatrix glm;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000259 glm.set(fCurrDrawState.fViewMatrix);
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000260 GL_CALL(MatrixMode(GR_GL_MODELVIEW));
261 GL_CALL(LoadMatrixf(glm.fMat));
bsalomon@google.com5782d712011-01-21 21:03:59 +0000262 fHWDrawState.fViewMatrix =
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000263 fCurrDrawState.fViewMatrix;
reed@google.comac10a2d2010-12-22 21:39:39 +0000264 }
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000265 resetDirtyFlags();
reed@google.comac10a2d2010-12-22 21:39:39 +0000266 return true;
267}
268
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000269void GrGpuGLFixed::setupGeometry(int* startVertex,
270 int* startIndex,
271 int vertexCount,
272 int indexCount) {
bsalomon@google.com5782d712011-01-21 21:03:59 +0000273
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000274 int newColorOffset;
bsalomon@google.coma3108262011-10-10 14:08:47 +0000275 int newCoverageOffset;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000276 int newTexCoordOffsets[kNumStages];
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000277 int newEdgeOffset;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000278
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000279 GrGLsizei newStride = VertexSizeAndOffsetsByStage(this->getGeomSrc().fVertexLayout,
twiz@google.com0f31ca72011-03-18 17:38:11 +0000280 newTexCoordOffsets,
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000281 &newColorOffset,
bsalomon@google.coma3108262011-10-10 14:08:47 +0000282 &newCoverageOffset,
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000283 &newEdgeOffset);
284 GrAssert(-1 == newEdgeOffset); // not supported by fixed pipe
bsalomon@google.coma3108262011-10-10 14:08:47 +0000285 GrAssert(-1 == newCoverageOffset); // not supported by fixed pipe
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000286
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000287 int oldColorOffset;
bsalomon@google.coma3108262011-10-10 14:08:47 +0000288 int oldCoverageOffset;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000289 int oldTexCoordOffsets[kNumStages];
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000290 int oldEdgeOffset;
twiz@google.com0f31ca72011-03-18 17:38:11 +0000291 GrGLsizei oldStride = VertexSizeAndOffsetsByStage(fHWGeometryState.fVertexLayout,
292 oldTexCoordOffsets,
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000293 &oldColorOffset,
bsalomon@google.coma3108262011-10-10 14:08:47 +0000294 &oldCoverageOffset,
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000295 &oldEdgeOffset);
296 GrAssert(-1 == oldEdgeOffset);
bsalomon@google.coma3108262011-10-10 14:08:47 +0000297 GrAssert(-1 == oldCoverageOffset);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000298
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000299 bool indexed = NULL != startIndex;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000300
301 int extraVertexOffset;
302 int extraIndexOffset;
303 setBuffers(indexed, &extraVertexOffset, &extraIndexOffset);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000304
twiz@google.com0f31ca72011-03-18 17:38:11 +0000305 GrGLenum scalarType;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000306 if (this->getGeomSrc().fVertexLayout & kTextFormat_VertexLayoutBit) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000307 scalarType = GrGLTextType;
308 } else {
309 scalarType = GrGLType;
310 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000311
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000312 size_t vertexOffset = (*startVertex + extraVertexOffset) * newStride;
313 *startVertex = 0;
314 if (indexed) {
315 *startIndex += extraIndexOffset;
316 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000317
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000318 // all the Pointers must be set if any of these are true
319 bool allOffsetsChange = fHWGeometryState.fArrayPtrsDirty ||
320 vertexOffset != fHWGeometryState.fVertexOffset ||
321 newStride != oldStride;
322
323 // position and tex coord offsets change if above conditions are true
324 // or the type changed based on text vs nontext type coords.
325 bool posAndTexChange = allOffsetsChange ||
326 ((GrGLTextType != GrGLType) &&
327 (kTextFormat_VertexLayoutBit &
328 (fHWGeometryState.fVertexLayout ^
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000329 this->getGeomSrc().fVertexLayout)));
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000330
331 if (posAndTexChange) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000332 GL_CALL(VertexPointer(2, scalarType,
333 newStride, (GrGLvoid*)vertexOffset));
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000334 fHWGeometryState.fVertexOffset = vertexOffset;
reed@google.comac10a2d2010-12-22 21:39:39 +0000335 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000336
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000337 for (int s = 0; s < kNumStages; ++s) {
bsalomon@google.com5782d712011-01-21 21:03:59 +0000338 // need to enable array if tex coord offset is 0
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000339 // (using positions as coords)
340 if (newTexCoordOffsets[s] >= 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000341 GrGLvoid* texCoordOffset = (GrGLvoid*)(vertexOffset +
342 newTexCoordOffsets[s]);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000343 if (oldTexCoordOffsets[s] < 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000344 GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s));
345 GL_CALL(EnableClientState(GR_GL_TEXTURE_COORD_ARRAY));
346 GL_CALL(TexCoordPointer(2, scalarType,
347 newStride, texCoordOffset));
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000348 } else if (posAndTexChange ||
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +0000349 newTexCoordOffsets[s] != oldTexCoordOffsets[s]) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000350 GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s));
351 GL_CALL(TexCoordPointer(2, scalarType,
352 newStride, texCoordOffset));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000353 }
354 } else if (oldTexCoordOffsets[s] >= 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000355 GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s));
356 GL_CALL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY));
reed@google.comac10a2d2010-12-22 21:39:39 +0000357 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000358 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000359
reed@google.comac10a2d2010-12-22 21:39:39 +0000360 if (newColorOffset > 0) {
twiz@google.com0f31ca72011-03-18 17:38:11 +0000361 GrGLvoid* colorOffset = (GrGLvoid*)(vertexOffset + newColorOffset);
reed@google.comac10a2d2010-12-22 21:39:39 +0000362 if (oldColorOffset <= 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000363 GL_CALL(EnableClientState(GR_GL_COLOR_ARRAY));
364 GL_CALL(ColorPointer(4, GR_GL_UNSIGNED_BYTE,
365 newStride, colorOffset));
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000366 } else if (allOffsetsChange || newColorOffset != oldColorOffset) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000367 GL_CALL(ColorPointer(4, GR_GL_UNSIGNED_BYTE,
368 newStride, colorOffset));
reed@google.comac10a2d2010-12-22 21:39:39 +0000369 }
370 } else if (oldColorOffset > 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000371 GL_CALL(DisableClientState(GR_GL_COLOR_ARRAY));
reed@google.comac10a2d2010-12-22 21:39:39 +0000372 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000373
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000374 fHWGeometryState.fVertexLayout = this->getGeomSrc().fVertexLayout;
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +0000375 fHWGeometryState.fArrayPtrsDirty = false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000376}