blob: 87b051bc9cfe905f36ccdee44fc6111786923b64 [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.com6aef1fb2011-05-05 12:33:22 +000065 f4X4DownsampleFilterSupport = false;
bsalomon@google.com271cffc2011-05-20 14:13:56 +000066 fDualSourceBlendingSupport = false;
reed@google.comac10a2d2010-12-22 21:39:39 +000067}
68
69GrGpuGLFixed::~GrGpuGLFixed() {
70}
71
72void GrGpuGLFixed::resetContext() {
73 INHERITED::resetContext();
reed@google.comac10a2d2010-12-22 21:39:39 +000074
bsalomon@google.com0b77d682011-08-19 13:28:54 +000075 GL_CALL(Disable(GR_GL_TEXTURE_2D));
reed@google.comac10a2d2010-12-22 21:39:39 +000076
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000077 for (int s = 0; s < kNumStages; ++s) {
78 setTextureUnit(s);
bsalomon@google.com0b77d682011-08-19 13:28:54 +000079 GL_CALL(EnableClientState(GR_GL_VERTEX_ARRAY));
80 GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
81 GR_GL_TEXTURE_ENV_MODE,
82 GR_GL_COMBINE));
83 GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
84 GR_GL_COMBINE_RGB,
85 GR_GL_MODULATE));
86 GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
87 GR_GL_SRC0_RGB,
88 GR_GL_TEXTURE0+s));
89 GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
90 GR_GL_SRC1_RGB,
91 GR_GL_PREVIOUS));
92 GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
93 GR_GL_OPERAND1_RGB,
94 GR_GL_SRC_COLOR));
reed@google.comac10a2d2010-12-22 21:39:39 +000095
bsalomon@google.com0b77d682011-08-19 13:28:54 +000096 GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
97 GR_GL_COMBINE_ALPHA,
98 GR_GL_MODULATE));
99 GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
100 GR_GL_SRC0_ALPHA,
101 GR_GL_TEXTURE0+s));
102 GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
103 GR_GL_OPERAND0_ALPHA,
104 GR_GL_SRC_ALPHA));
105 GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
106 GR_GL_SRC1_ALPHA,
107 GR_GL_PREVIOUS));
108 GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
109 GR_GL_OPERAND1_ALPHA,
110 GR_GL_SRC_ALPHA));
bsalomon@google.com5782d712011-01-21 21:03:59 +0000111
112 // color oprand0 changes between GL_SRC_COLR and GL_SRC_ALPHA depending
113 // upon whether we have a (premultiplied) RGBA texture or just an ALPHA
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000114 // texture, e.g.:
115 //glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000116 fHWRGBOperand0[s] = (TextureEnvRGBOperands) -1;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000117 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000118
119 fHWGeometryState.fVertexLayout = 0;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000120 fHWGeometryState.fVertexOffset = ~0;
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000121 GL_CALL(EnableClientState(GR_GL_VERTEX_ARRAY));
122 GL_CALL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY));
123 GL_CALL(ShadeModel(GR_GL_FLAT));
124 GL_CALL(DisableClientState(GR_GL_COLOR_ARRAY));
bsalomon@google.com5782d712011-01-21 21:03:59 +0000125
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000126 GL_CALL(PointSize(1.f));
bsalomon@google.com5782d712011-01-21 21:03:59 +0000127
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000128 GrGLClearErr(this->glInterface());
reed@google.comac10a2d2010-12-22 21:39:39 +0000129 fTextVerts = false;
130
reed@google.comac10a2d2010-12-22 21:39:39 +0000131 fBaseVertex = 0xffffffff;
132}
133
134
135void GrGpuGLFixed::flushProjectionMatrix() {
136 float mat[16];
137 Gr_bzero(mat, sizeof(mat));
bsalomon@google.com5782d712011-01-21 21:03:59 +0000138
reed@google.comac10a2d2010-12-22 21:39:39 +0000139 GrAssert(NULL != fCurrDrawState.fRenderTarget);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000140
reed@google.comac10a2d2010-12-22 21:39:39 +0000141 mat[0] = 2.f / fCurrDrawState.fRenderTarget->width();
142 mat[5] = -2.f / fCurrDrawState.fRenderTarget->height();
143 mat[10] = -1.f;
144 mat[15] = 1;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000145
reed@google.comac10a2d2010-12-22 21:39:39 +0000146 mat[12] = -1.f;
147 mat[13] = 1.f;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000148
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000149 GL_CALL(MatrixMode(GR_GL_PROJECTION));
150 GL_CALL(LoadMatrixf(mat));
reed@google.comac10a2d2010-12-22 21:39:39 +0000151}
152
bsalomon@google.comffca4002011-02-22 20:34:01 +0000153bool GrGpuGLFixed::flushGraphicsState(GrPrimitiveType type) {
bsalomon@google.com5782d712011-01-21 21:03:59 +0000154
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000155 bool usingTextures[kNumStages];
bsalomon@google.com5782d712011-01-21 21:03:59 +0000156
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000157 for (int s = 0; s < kNumStages; ++s) {
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000158 usingTextures[s] = this->isStageEnabled(s);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000159 if (usingTextures[s] && fCurrDrawState.fSamplerStates[s].isGradient()) {
160 unimpl("Fixed pipe doesn't support radial/sweep gradients");
161 return false;
162 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000163 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000164
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000165 if (kES1_GrGLBinding == this->glBinding()) {
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000166 if (BlendCoeffReferencesConstant(fCurrDrawState.fSrcBlend) ||
167 BlendCoeffReferencesConstant(fCurrDrawState.fDstBlend)) {
twiz@google.comb65e0cb2011-03-18 20:41:44 +0000168 unimpl("ES1 doesn't support blend constant");
169 return false;
170 }
bsalomon@google.com080773c2011-03-15 19:09:25 +0000171 }
bsalomon@google.com080773c2011-03-15 19:09:25 +0000172
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000173 if (!flushGLStateCommon(type)) {
174 return false;
175 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000176
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000177 this->flushBlend(type, fCurrDrawState.fSrcBlend, fCurrDrawState.fDstBlend);
178
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000179 if (fDirtyFlags.fRenderTargetChanged) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000180 flushProjectionMatrix();
reed@google.comac10a2d2010-12-22 21:39:39 +0000181 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000182
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000183 for (int s = 0; s < kNumStages; ++s) {
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000184 bool wasUsingTexture = StageWillBeUsed(s, fHWGeometryState.fVertexLayout, fHWDrawState);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000185 if (usingTextures[s] != wasUsingTexture) {
186 setTextureUnit(s);
187 if (usingTextures[s]) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000188 GL_CALL(Enable(GR_GL_TEXTURE_2D));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000189 } else {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000190 GL_CALL(Disable(GR_GL_TEXTURE_2D));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000191 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000192 }
193 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000194
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000195 uint32_t vertColor = (this->getGeomSrc().fVertexLayout & kColor_VertexLayoutBit);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000196 uint32_t prevVertColor = (fHWGeometryState.fVertexLayout &
reed@google.comac10a2d2010-12-22 21:39:39 +0000197 kColor_VertexLayoutBit);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000198
reed@google.comac10a2d2010-12-22 21:39:39 +0000199 if (vertColor != prevVertColor) {
200 if (vertColor) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000201 GL_CALL(ShadeModel(GR_GL_SMOOTH));
reed@google.comac10a2d2010-12-22 21:39:39 +0000202 // invalidate the immediate mode color
203 fHWDrawState.fColor = GrColor_ILLEGAL;
204 } else {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000205 GL_CALL(ShadeModel(GR_GL_FLAT));
reed@google.comac10a2d2010-12-22 21:39:39 +0000206 }
207 }
208
bsalomon@google.com5782d712011-01-21 21:03:59 +0000209
reed@google.comac10a2d2010-12-22 21:39:39 +0000210 if (!vertColor && fHWDrawState.fColor != fCurrDrawState.fColor) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000211 GL_CALL(Color4ub(GrColorUnpackR(fCurrDrawState.fColor),
reed@google.comac10a2d2010-12-22 21:39:39 +0000212 GrColorUnpackG(fCurrDrawState.fColor),
213 GrColorUnpackB(fCurrDrawState.fColor),
214 GrColorUnpackA(fCurrDrawState.fColor)));
215 fHWDrawState.fColor = fCurrDrawState.fColor;
216 }
217
218 // set texture environment, decide whether we are modulating by RGB or A.
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000219 for (int s = 0; s < kNumStages; ++s) {
220 if (usingTextures[s]) {
221 GrGLTexture* texture = (GrGLTexture*)fCurrDrawState.fTextures[s];
222 if (NULL != texture) {
bsalomon@google.com5782d712011-01-21 21:03:59 +0000223 TextureEnvRGBOperands nextRGBOperand0 =
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000224 (GrPixelConfigIsAlphaOnly(texture->config())) ?
bsalomon@google.com5782d712011-01-21 21:03:59 +0000225 kAlpha_TextureEnvRGBOperand :
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000226 kColor_TextureEnvRGBOperand;
227 if (fHWRGBOperand0[s] != nextRGBOperand0) {
228 setTextureUnit(s);
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000229 GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
twiz@google.com0f31ca72011-03-18 17:38:11 +0000230 GR_GL_OPERAND0_RGB,
bsalomon@google.com5782d712011-01-21 21:03:59 +0000231 (nextRGBOperand0==kAlpha_TextureEnvRGBOperand) ?
twiz@google.com0f31ca72011-03-18 17:38:11 +0000232 GR_GL_SRC_ALPHA :
233 GR_GL_SRC_COLOR));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000234 fHWRGBOperand0[s] = nextRGBOperand0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000235 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000236
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000237 if (((1 << s) & fDirtyFlags.fTextureChangedMask) ||
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000238 (fHWDrawState.fSamplerStates[s].getMatrix() !=
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000239 getSamplerMatrix(s))) {
240
241 GrMatrix texMat = getSamplerMatrix(s);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000242 AdjustTextureMatrix(texture,
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000243 GrSamplerState::kNormal_SampleMode,
244 &texMat);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000245 GrGpuMatrix glm;
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000246 glm.set(texMat);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000247 setTextureUnit(s);
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000248 GL_CALL(MatrixMode(GR_GL_TEXTURE));
249 GL_CALL(LoadMatrixf(glm.fMat));
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000250 recordHWSamplerMatrix(s, getSamplerMatrix(s));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000251 }
252 } else {
253 GrAssert(!"Rendering with texture vert flag set but no bound texture");
254 return false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000255 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000256 }
257 }
258
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000259 if (fHWDrawState.fViewMatrix != fCurrDrawState.fViewMatrix) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000260 GrGpuMatrix glm;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000261 glm.set(fCurrDrawState.fViewMatrix);
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000262 GL_CALL(MatrixMode(GR_GL_MODELVIEW));
263 GL_CALL(LoadMatrixf(glm.fMat));
bsalomon@google.com5782d712011-01-21 21:03:59 +0000264 fHWDrawState.fViewMatrix =
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000265 fCurrDrawState.fViewMatrix;
reed@google.comac10a2d2010-12-22 21:39:39 +0000266 }
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000267 resetDirtyFlags();
reed@google.comac10a2d2010-12-22 21:39:39 +0000268 return true;
269}
270
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000271void GrGpuGLFixed::setupGeometry(int* startVertex,
272 int* startIndex,
273 int vertexCount,
274 int indexCount) {
bsalomon@google.com5782d712011-01-21 21:03:59 +0000275
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000276 int newColorOffset;
277 int newTexCoordOffsets[kNumStages];
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,
281 &newColorOffset);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000282 int oldColorOffset;
283 int oldTexCoordOffsets[kNumStages];
twiz@google.com0f31ca72011-03-18 17:38:11 +0000284 GrGLsizei oldStride = VertexSizeAndOffsetsByStage(fHWGeometryState.fVertexLayout,
285 oldTexCoordOffsets,
286 &oldColorOffset);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000287
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000288 bool indexed = NULL != startIndex;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000289
290 int extraVertexOffset;
291 int extraIndexOffset;
292 setBuffers(indexed, &extraVertexOffset, &extraIndexOffset);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000293
twiz@google.com0f31ca72011-03-18 17:38:11 +0000294 GrGLenum scalarType;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000295 if (this->getGeomSrc().fVertexLayout & kTextFormat_VertexLayoutBit) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000296 scalarType = GrGLTextType;
297 } else {
298 scalarType = GrGLType;
299 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000300
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000301 size_t vertexOffset = (*startVertex + extraVertexOffset) * newStride;
302 *startVertex = 0;
303 if (indexed) {
304 *startIndex += extraIndexOffset;
305 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000306
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000307 // all the Pointers must be set if any of these are true
308 bool allOffsetsChange = fHWGeometryState.fArrayPtrsDirty ||
309 vertexOffset != fHWGeometryState.fVertexOffset ||
310 newStride != oldStride;
311
312 // position and tex coord offsets change if above conditions are true
313 // or the type changed based on text vs nontext type coords.
314 bool posAndTexChange = allOffsetsChange ||
315 ((GrGLTextType != GrGLType) &&
316 (kTextFormat_VertexLayoutBit &
317 (fHWGeometryState.fVertexLayout ^
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000318 this->getGeomSrc().fVertexLayout)));
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000319
320 if (posAndTexChange) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000321 GL_CALL(VertexPointer(2, scalarType,
322 newStride, (GrGLvoid*)vertexOffset));
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000323 fHWGeometryState.fVertexOffset = vertexOffset;
reed@google.comac10a2d2010-12-22 21:39:39 +0000324 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000325
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000326 for (int s = 0; s < kNumStages; ++s) {
bsalomon@google.com5782d712011-01-21 21:03:59 +0000327 // need to enable array if tex coord offset is 0
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000328 // (using positions as coords)
329 if (newTexCoordOffsets[s] >= 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000330 GrGLvoid* texCoordOffset = (GrGLvoid*)(vertexOffset +
331 newTexCoordOffsets[s]);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000332 if (oldTexCoordOffsets[s] < 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000333 GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s));
334 GL_CALL(EnableClientState(GR_GL_TEXTURE_COORD_ARRAY));
335 GL_CALL(TexCoordPointer(2, scalarType,
336 newStride, texCoordOffset));
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000337 } else if (posAndTexChange ||
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +0000338 newTexCoordOffsets[s] != oldTexCoordOffsets[s]) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000339 GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s));
340 GL_CALL(TexCoordPointer(2, scalarType,
341 newStride, texCoordOffset));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000342 }
343 } else if (oldTexCoordOffsets[s] >= 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000344 GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s));
345 GL_CALL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY));
reed@google.comac10a2d2010-12-22 21:39:39 +0000346 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000347 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000348
reed@google.comac10a2d2010-12-22 21:39:39 +0000349 if (newColorOffset > 0) {
twiz@google.com0f31ca72011-03-18 17:38:11 +0000350 GrGLvoid* colorOffset = (GrGLvoid*)(vertexOffset + newColorOffset);
reed@google.comac10a2d2010-12-22 21:39:39 +0000351 if (oldColorOffset <= 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000352 GL_CALL(EnableClientState(GR_GL_COLOR_ARRAY));
353 GL_CALL(ColorPointer(4, GR_GL_UNSIGNED_BYTE,
354 newStride, colorOffset));
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000355 } else if (allOffsetsChange || newColorOffset != oldColorOffset) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000356 GL_CALL(ColorPointer(4, GR_GL_UNSIGNED_BYTE,
357 newStride, colorOffset));
reed@google.comac10a2d2010-12-22 21:39:39 +0000358 }
359 } else if (oldColorOffset > 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000360 GL_CALL(DisableClientState(GR_GL_COLOR_ARRAY));
reed@google.comac10a2d2010-12-22 21:39:39 +0000361 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000362
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000363 fHWGeometryState.fVertexLayout = this->getGeomSrc().fVertexLayout;
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +0000364 fHWGeometryState.fArrayPtrsDirty = false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000365}