blob: 69bf94f533a73919866d69b4522daeb24cb37b18 [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)) {
bsalomon@google.com1f221a72011-08-23 20:54:07 +000065 fShaderSupport = false;
66 fShaderDerivativeSupport = false;
bsalomon@google.com271cffc2011-05-20 14:13:56 +000067 fDualSourceBlendingSupport = false;
reed@google.comac10a2d2010-12-22 21:39:39 +000068}
69
70GrGpuGLFixed::~GrGpuGLFixed() {
71}
72
73void GrGpuGLFixed::resetContext() {
74 INHERITED::resetContext();
reed@google.comac10a2d2010-12-22 21:39:39 +000075
bsalomon@google.com0b77d682011-08-19 13:28:54 +000076 GL_CALL(Disable(GR_GL_TEXTURE_2D));
reed@google.comac10a2d2010-12-22 21:39:39 +000077
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000078 for (int s = 0; s < kNumStages; ++s) {
79 setTextureUnit(s);
bsalomon@google.com0b77d682011-08-19 13:28:54 +000080 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.comac10a2d2010-12-22 21:39:39 +000096
bsalomon@google.com0b77d682011-08-19 13:28:54 +000097 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.com5782d712011-01-21 21:03:59 +0000112
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.com8531c1c2011-01-13 19:52:45 +0000115 // texture, e.g.:
116 //glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000117 fHWRGBOperand0[s] = (TextureEnvRGBOperands) -1;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000118 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000119
120 fHWGeometryState.fVertexLayout = 0;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000121 fHWGeometryState.fVertexOffset = ~0;
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000122 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.com5782d712011-01-21 21:03:59 +0000126
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000127 GL_CALL(PointSize(1.f));
bsalomon@google.com5782d712011-01-21 21:03:59 +0000128
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000129 GrGLClearErr(this->glInterface());
reed@google.comac10a2d2010-12-22 21:39:39 +0000130 fTextVerts = false;
131
reed@google.comac10a2d2010-12-22 21:39:39 +0000132 fBaseVertex = 0xffffffff;
133}
134
135
136void GrGpuGLFixed::flushProjectionMatrix() {
137 float mat[16];
138 Gr_bzero(mat, sizeof(mat));
bsalomon@google.com5782d712011-01-21 21:03:59 +0000139
reed@google.comac10a2d2010-12-22 21:39:39 +0000140 GrAssert(NULL != fCurrDrawState.fRenderTarget);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000141
reed@google.comac10a2d2010-12-22 21:39:39 +0000142 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.com5782d712011-01-21 21:03:59 +0000146
reed@google.comac10a2d2010-12-22 21:39:39 +0000147 mat[12] = -1.f;
148 mat[13] = 1.f;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000149
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000150 GL_CALL(MatrixMode(GR_GL_PROJECTION));
151 GL_CALL(LoadMatrixf(mat));
reed@google.comac10a2d2010-12-22 21:39:39 +0000152}
153
bsalomon@google.comffca4002011-02-22 20:34:01 +0000154bool GrGpuGLFixed::flushGraphicsState(GrPrimitiveType type) {
bsalomon@google.com5782d712011-01-21 21:03:59 +0000155
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000156 bool usingTextures[kNumStages];
bsalomon@google.com5782d712011-01-21 21:03:59 +0000157
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000158 for (int s = 0; s < kNumStages; ++s) {
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000159 usingTextures[s] = this->isStageEnabled(s);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000160 if (usingTextures[s] && fCurrDrawState.fSamplerStates[s].isGradient()) {
161 unimpl("Fixed pipe doesn't support radial/sweep gradients");
162 return false;
163 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000164 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000165
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000166 if (kES1_GrGLBinding == this->glBinding()) {
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000167 if (BlendCoeffReferencesConstant(fCurrDrawState.fSrcBlend) ||
168 BlendCoeffReferencesConstant(fCurrDrawState.fDstBlend)) {
twiz@google.comb65e0cb2011-03-18 20:41:44 +0000169 unimpl("ES1 doesn't support blend constant");
170 return false;
171 }
bsalomon@google.com080773c2011-03-15 19:09:25 +0000172 }
bsalomon@google.com080773c2011-03-15 19:09:25 +0000173
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000174 if (!flushGLStateCommon(type)) {
175 return false;
176 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000177
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000178 this->flushBlend(type, fCurrDrawState.fSrcBlend, fCurrDrawState.fDstBlend);
179
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000180 if (fDirtyFlags.fRenderTargetChanged) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000181 flushProjectionMatrix();
reed@google.comac10a2d2010-12-22 21:39:39 +0000182 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000183
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000184 for (int s = 0; s < kNumStages; ++s) {
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000185 bool wasUsingTexture = StageWillBeUsed(s, fHWGeometryState.fVertexLayout, fHWDrawState);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000186 if (usingTextures[s] != wasUsingTexture) {
187 setTextureUnit(s);
188 if (usingTextures[s]) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000189 GL_CALL(Enable(GR_GL_TEXTURE_2D));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000190 } else {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000191 GL_CALL(Disable(GR_GL_TEXTURE_2D));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000192 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000193 }
194 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000195
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000196 uint32_t vertColor = (this->getGeomSrc().fVertexLayout & kColor_VertexLayoutBit);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000197 uint32_t prevVertColor = (fHWGeometryState.fVertexLayout &
reed@google.comac10a2d2010-12-22 21:39:39 +0000198 kColor_VertexLayoutBit);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000199
reed@google.comac10a2d2010-12-22 21:39:39 +0000200 if (vertColor != prevVertColor) {
201 if (vertColor) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000202 GL_CALL(ShadeModel(GR_GL_SMOOTH));
reed@google.comac10a2d2010-12-22 21:39:39 +0000203 // invalidate the immediate mode color
204 fHWDrawState.fColor = GrColor_ILLEGAL;
205 } else {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000206 GL_CALL(ShadeModel(GR_GL_FLAT));
reed@google.comac10a2d2010-12-22 21:39:39 +0000207 }
208 }
209
bsalomon@google.com5782d712011-01-21 21:03:59 +0000210
reed@google.comac10a2d2010-12-22 21:39:39 +0000211 if (!vertColor && fHWDrawState.fColor != fCurrDrawState.fColor) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000212 GL_CALL(Color4ub(GrColorUnpackR(fCurrDrawState.fColor),
reed@google.comac10a2d2010-12-22 21:39:39 +0000213 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.com8531c1c2011-01-13 19:52:45 +0000220 for (int s = 0; s < kNumStages; ++s) {
221 if (usingTextures[s]) {
222 GrGLTexture* texture = (GrGLTexture*)fCurrDrawState.fTextures[s];
223 if (NULL != texture) {
bsalomon@google.com5782d712011-01-21 21:03:59 +0000224 TextureEnvRGBOperands nextRGBOperand0 =
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000225 (GrPixelConfigIsAlphaOnly(texture->config())) ?
bsalomon@google.com5782d712011-01-21 21:03:59 +0000226 kAlpha_TextureEnvRGBOperand :
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000227 kColor_TextureEnvRGBOperand;
228 if (fHWRGBOperand0[s] != nextRGBOperand0) {
229 setTextureUnit(s);
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000230 GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
twiz@google.com0f31ca72011-03-18 17:38:11 +0000231 GR_GL_OPERAND0_RGB,
bsalomon@google.com5782d712011-01-21 21:03:59 +0000232 (nextRGBOperand0==kAlpha_TextureEnvRGBOperand) ?
twiz@google.com0f31ca72011-03-18 17:38:11 +0000233 GR_GL_SRC_ALPHA :
234 GR_GL_SRC_COLOR));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000235 fHWRGBOperand0[s] = nextRGBOperand0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000236 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000237
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000238 if (((1 << s) & fDirtyFlags.fTextureChangedMask) ||
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000239 (fHWDrawState.fSamplerStates[s].getMatrix() !=
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000240 getSamplerMatrix(s))) {
241
242 GrMatrix texMat = getSamplerMatrix(s);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000243 AdjustTextureMatrix(texture,
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000244 GrSamplerState::kNormal_SampleMode,
245 &texMat);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000246 GrGpuMatrix glm;
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000247 glm.set(texMat);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000248 setTextureUnit(s);
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000249 GL_CALL(MatrixMode(GR_GL_TEXTURE));
250 GL_CALL(LoadMatrixf(glm.fMat));
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000251 recordHWSamplerMatrix(s, getSamplerMatrix(s));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000252 }
253 } else {
254 GrAssert(!"Rendering with texture vert flag set but no bound texture");
255 return false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000256 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000257 }
258 }
259
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000260 if (fHWDrawState.fViewMatrix != fCurrDrawState.fViewMatrix) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000261 GrGpuMatrix glm;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000262 glm.set(fCurrDrawState.fViewMatrix);
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000263 GL_CALL(MatrixMode(GR_GL_MODELVIEW));
264 GL_CALL(LoadMatrixf(glm.fMat));
bsalomon@google.com5782d712011-01-21 21:03:59 +0000265 fHWDrawState.fViewMatrix =
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000266 fCurrDrawState.fViewMatrix;
reed@google.comac10a2d2010-12-22 21:39:39 +0000267 }
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000268 resetDirtyFlags();
reed@google.comac10a2d2010-12-22 21:39:39 +0000269 return true;
270}
271
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000272void GrGpuGLFixed::setupGeometry(int* startVertex,
273 int* startIndex,
274 int vertexCount,
275 int indexCount) {
bsalomon@google.com5782d712011-01-21 21:03:59 +0000276
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000277 int newColorOffset;
278 int newTexCoordOffsets[kNumStages];
bsalomon@google.com5782d712011-01-21 21:03:59 +0000279
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000280 GrGLsizei newStride = VertexSizeAndOffsetsByStage(this->getGeomSrc().fVertexLayout,
twiz@google.com0f31ca72011-03-18 17:38:11 +0000281 newTexCoordOffsets,
282 &newColorOffset);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000283 int oldColorOffset;
284 int oldTexCoordOffsets[kNumStages];
twiz@google.com0f31ca72011-03-18 17:38:11 +0000285 GrGLsizei oldStride = VertexSizeAndOffsetsByStage(fHWGeometryState.fVertexLayout,
286 oldTexCoordOffsets,
287 &oldColorOffset);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000288
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000289 bool indexed = NULL != startIndex;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000290
291 int extraVertexOffset;
292 int extraIndexOffset;
293 setBuffers(indexed, &extraVertexOffset, &extraIndexOffset);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000294
twiz@google.com0f31ca72011-03-18 17:38:11 +0000295 GrGLenum scalarType;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000296 if (this->getGeomSrc().fVertexLayout & kTextFormat_VertexLayoutBit) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000297 scalarType = GrGLTextType;
298 } else {
299 scalarType = GrGLType;
300 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000301
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000302 size_t vertexOffset = (*startVertex + extraVertexOffset) * newStride;
303 *startVertex = 0;
304 if (indexed) {
305 *startIndex += extraIndexOffset;
306 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000307
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000308 // 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.com25fb21f2011-06-21 18:17:25 +0000319 this->getGeomSrc().fVertexLayout)));
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000320
321 if (posAndTexChange) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000322 GL_CALL(VertexPointer(2, scalarType,
323 newStride, (GrGLvoid*)vertexOffset));
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000324 fHWGeometryState.fVertexOffset = vertexOffset;
reed@google.comac10a2d2010-12-22 21:39:39 +0000325 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000326
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000327 for (int s = 0; s < kNumStages; ++s) {
bsalomon@google.com5782d712011-01-21 21:03:59 +0000328 // need to enable array if tex coord offset is 0
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000329 // (using positions as coords)
330 if (newTexCoordOffsets[s] >= 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000331 GrGLvoid* texCoordOffset = (GrGLvoid*)(vertexOffset +
332 newTexCoordOffsets[s]);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000333 if (oldTexCoordOffsets[s] < 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000334 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.com1c13c962011-02-14 16:51:21 +0000338 } else if (posAndTexChange ||
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +0000339 newTexCoordOffsets[s] != oldTexCoordOffsets[s]) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000340 GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s));
341 GL_CALL(TexCoordPointer(2, scalarType,
342 newStride, texCoordOffset));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000343 }
344 } else if (oldTexCoordOffsets[s] >= 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000345 GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s));
346 GL_CALL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY));
reed@google.comac10a2d2010-12-22 21:39:39 +0000347 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000348 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000349
reed@google.comac10a2d2010-12-22 21:39:39 +0000350 if (newColorOffset > 0) {
twiz@google.com0f31ca72011-03-18 17:38:11 +0000351 GrGLvoid* colorOffset = (GrGLvoid*)(vertexOffset + newColorOffset);
reed@google.comac10a2d2010-12-22 21:39:39 +0000352 if (oldColorOffset <= 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000353 GL_CALL(EnableClientState(GR_GL_COLOR_ARRAY));
354 GL_CALL(ColorPointer(4, GR_GL_UNSIGNED_BYTE,
355 newStride, colorOffset));
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000356 } else if (allOffsetsChange || newColorOffset != oldColorOffset) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000357 GL_CALL(ColorPointer(4, GR_GL_UNSIGNED_BYTE,
358 newStride, colorOffset));
reed@google.comac10a2d2010-12-22 21:39:39 +0000359 }
360 } else if (oldColorOffset > 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000361 GL_CALL(DisableClientState(GR_GL_COLOR_ARRAY));
reed@google.comac10a2d2010-12-22 21:39:39 +0000362 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000363
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000364 fHWGeometryState.fVertexLayout = this->getGeomSrc().fVertexLayout;
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +0000365 fHWGeometryState.fArrayPtrsDirty = false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000366}