blob: 336b687be8eb6046ea7ec93ae16f3ebfd627353d [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.com86c1f712011-10-12 14:54:26 +0000175 GrBlendCoeff srcCoeff, dstCoeff;
176 if (kSkipDraw_BlendOptFlag &
177 this->getBlendOpts(false, &srcCoeff, &dstCoeff)) {
178 return false;
179 }
180
181 this->flushBlend(type, srcCoeff, dstCoeff);
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000182
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000183 if (fDirtyFlags.fRenderTargetChanged) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000184 flushProjectionMatrix();
reed@google.comac10a2d2010-12-22 21:39:39 +0000185 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000186
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000187 for (int s = 0; s < kNumStages; ++s) {
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000188 bool wasUsingTexture = StageWillBeUsed(s, fHWGeometryState.fVertexLayout, fHWDrawState);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000189 if (usingTextures[s] != wasUsingTexture) {
190 setTextureUnit(s);
191 if (usingTextures[s]) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000192 GL_CALL(Enable(GR_GL_TEXTURE_2D));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000193 } else {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000194 GL_CALL(Disable(GR_GL_TEXTURE_2D));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000195 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000196 }
197 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000198
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000199 uint32_t vertColor = (this->getGeomSrc().fVertexLayout & kColor_VertexLayoutBit);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000200 uint32_t prevVertColor = (fHWGeometryState.fVertexLayout &
reed@google.comac10a2d2010-12-22 21:39:39 +0000201 kColor_VertexLayoutBit);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000202
reed@google.comac10a2d2010-12-22 21:39:39 +0000203 if (vertColor != prevVertColor) {
204 if (vertColor) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000205 GL_CALL(ShadeModel(GR_GL_SMOOTH));
reed@google.comac10a2d2010-12-22 21:39:39 +0000206 // invalidate the immediate mode color
207 fHWDrawState.fColor = GrColor_ILLEGAL;
208 } else {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000209 GL_CALL(ShadeModel(GR_GL_FLAT));
reed@google.comac10a2d2010-12-22 21:39:39 +0000210 }
211 }
212
bsalomon@google.com5782d712011-01-21 21:03:59 +0000213
reed@google.comac10a2d2010-12-22 21:39:39 +0000214 if (!vertColor && fHWDrawState.fColor != fCurrDrawState.fColor) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000215 GL_CALL(Color4ub(GrColorUnpackR(fCurrDrawState.fColor),
reed@google.comac10a2d2010-12-22 21:39:39 +0000216 GrColorUnpackG(fCurrDrawState.fColor),
217 GrColorUnpackB(fCurrDrawState.fColor),
218 GrColorUnpackA(fCurrDrawState.fColor)));
219 fHWDrawState.fColor = fCurrDrawState.fColor;
220 }
221
222 // set texture environment, decide whether we are modulating by RGB or A.
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000223 for (int s = 0; s < kNumStages; ++s) {
224 if (usingTextures[s]) {
225 GrGLTexture* texture = (GrGLTexture*)fCurrDrawState.fTextures[s];
226 if (NULL != texture) {
bsalomon@google.com5782d712011-01-21 21:03:59 +0000227 TextureEnvRGBOperands nextRGBOperand0 =
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000228 (GrPixelConfigIsAlphaOnly(texture->config())) ?
bsalomon@google.com5782d712011-01-21 21:03:59 +0000229 kAlpha_TextureEnvRGBOperand :
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000230 kColor_TextureEnvRGBOperand;
231 if (fHWRGBOperand0[s] != nextRGBOperand0) {
232 setTextureUnit(s);
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000233 GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
twiz@google.com0f31ca72011-03-18 17:38:11 +0000234 GR_GL_OPERAND0_RGB,
bsalomon@google.com5782d712011-01-21 21:03:59 +0000235 (nextRGBOperand0==kAlpha_TextureEnvRGBOperand) ?
twiz@google.com0f31ca72011-03-18 17:38:11 +0000236 GR_GL_SRC_ALPHA :
237 GR_GL_SRC_COLOR));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000238 fHWRGBOperand0[s] = nextRGBOperand0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000239 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000240
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000241 if (((1 << s) & fDirtyFlags.fTextureChangedMask) ||
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000242 (fHWDrawState.fSamplerStates[s].getMatrix() !=
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000243 getSamplerMatrix(s))) {
244
245 GrMatrix texMat = getSamplerMatrix(s);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000246 AdjustTextureMatrix(texture,
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000247 GrSamplerState::kNormal_SampleMode,
248 &texMat);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000249 GrGpuMatrix glm;
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000250 glm.set(texMat);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000251 setTextureUnit(s);
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000252 GL_CALL(MatrixMode(GR_GL_TEXTURE));
253 GL_CALL(LoadMatrixf(glm.fMat));
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000254 recordHWSamplerMatrix(s, getSamplerMatrix(s));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000255 }
256 } else {
257 GrAssert(!"Rendering with texture vert flag set but no bound texture");
258 return false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000259 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000260 }
261 }
262
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000263 if (fHWDrawState.fViewMatrix != fCurrDrawState.fViewMatrix) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000264 GrGpuMatrix glm;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000265 glm.set(fCurrDrawState.fViewMatrix);
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000266 GL_CALL(MatrixMode(GR_GL_MODELVIEW));
267 GL_CALL(LoadMatrixf(glm.fMat));
bsalomon@google.com5782d712011-01-21 21:03:59 +0000268 fHWDrawState.fViewMatrix =
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000269 fCurrDrawState.fViewMatrix;
reed@google.comac10a2d2010-12-22 21:39:39 +0000270 }
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000271 resetDirtyFlags();
reed@google.comac10a2d2010-12-22 21:39:39 +0000272 return true;
273}
274
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000275void GrGpuGLFixed::setupGeometry(int* startVertex,
276 int* startIndex,
277 int vertexCount,
278 int indexCount) {
bsalomon@google.com5782d712011-01-21 21:03:59 +0000279
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000280 int newColorOffset;
bsalomon@google.coma3108262011-10-10 14:08:47 +0000281 int newCoverageOffset;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000282 int newTexCoordOffsets[kNumStages];
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000283 int newEdgeOffset;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000284
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000285 GrGLsizei newStride = VertexSizeAndOffsetsByStage(this->getGeomSrc().fVertexLayout,
twiz@google.com0f31ca72011-03-18 17:38:11 +0000286 newTexCoordOffsets,
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000287 &newColorOffset,
bsalomon@google.coma3108262011-10-10 14:08:47 +0000288 &newCoverageOffset,
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000289 &newEdgeOffset);
290 GrAssert(-1 == newEdgeOffset); // not supported by fixed pipe
bsalomon@google.coma3108262011-10-10 14:08:47 +0000291 GrAssert(-1 == newCoverageOffset); // not supported by fixed pipe
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000292
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000293 int oldColorOffset;
bsalomon@google.coma3108262011-10-10 14:08:47 +0000294 int oldCoverageOffset;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000295 int oldTexCoordOffsets[kNumStages];
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000296 int oldEdgeOffset;
twiz@google.com0f31ca72011-03-18 17:38:11 +0000297 GrGLsizei oldStride = VertexSizeAndOffsetsByStage(fHWGeometryState.fVertexLayout,
298 oldTexCoordOffsets,
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000299 &oldColorOffset,
bsalomon@google.coma3108262011-10-10 14:08:47 +0000300 &oldCoverageOffset,
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000301 &oldEdgeOffset);
302 GrAssert(-1 == oldEdgeOffset);
bsalomon@google.coma3108262011-10-10 14:08:47 +0000303 GrAssert(-1 == oldCoverageOffset);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000304
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000305 bool indexed = NULL != startIndex;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000306
307 int extraVertexOffset;
308 int extraIndexOffset;
309 setBuffers(indexed, &extraVertexOffset, &extraIndexOffset);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000310
twiz@google.com0f31ca72011-03-18 17:38:11 +0000311 GrGLenum scalarType;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000312 if (this->getGeomSrc().fVertexLayout & kTextFormat_VertexLayoutBit) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000313 scalarType = GrGLTextType;
314 } else {
315 scalarType = GrGLType;
316 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000317
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000318 size_t vertexOffset = (*startVertex + extraVertexOffset) * newStride;
319 *startVertex = 0;
320 if (indexed) {
321 *startIndex += extraIndexOffset;
322 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000323
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000324 // all the Pointers must be set if any of these are true
325 bool allOffsetsChange = fHWGeometryState.fArrayPtrsDirty ||
326 vertexOffset != fHWGeometryState.fVertexOffset ||
327 newStride != oldStride;
328
329 // position and tex coord offsets change if above conditions are true
330 // or the type changed based on text vs nontext type coords.
331 bool posAndTexChange = allOffsetsChange ||
332 ((GrGLTextType != GrGLType) &&
333 (kTextFormat_VertexLayoutBit &
334 (fHWGeometryState.fVertexLayout ^
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000335 this->getGeomSrc().fVertexLayout)));
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000336
337 if (posAndTexChange) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000338 GL_CALL(VertexPointer(2, scalarType,
339 newStride, (GrGLvoid*)vertexOffset));
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000340 fHWGeometryState.fVertexOffset = vertexOffset;
reed@google.comac10a2d2010-12-22 21:39:39 +0000341 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000342
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000343 for (int s = 0; s < kNumStages; ++s) {
bsalomon@google.com5782d712011-01-21 21:03:59 +0000344 // need to enable array if tex coord offset is 0
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000345 // (using positions as coords)
346 if (newTexCoordOffsets[s] >= 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000347 GrGLvoid* texCoordOffset = (GrGLvoid*)(vertexOffset +
348 newTexCoordOffsets[s]);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000349 if (oldTexCoordOffsets[s] < 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000350 GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s));
351 GL_CALL(EnableClientState(GR_GL_TEXTURE_COORD_ARRAY));
352 GL_CALL(TexCoordPointer(2, scalarType,
353 newStride, texCoordOffset));
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000354 } else if (posAndTexChange ||
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +0000355 newTexCoordOffsets[s] != oldTexCoordOffsets[s]) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000356 GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s));
357 GL_CALL(TexCoordPointer(2, scalarType,
358 newStride, texCoordOffset));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000359 }
360 } else if (oldTexCoordOffsets[s] >= 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000361 GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s));
362 GL_CALL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY));
reed@google.comac10a2d2010-12-22 21:39:39 +0000363 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000364 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000365
reed@google.comac10a2d2010-12-22 21:39:39 +0000366 if (newColorOffset > 0) {
twiz@google.com0f31ca72011-03-18 17:38:11 +0000367 GrGLvoid* colorOffset = (GrGLvoid*)(vertexOffset + newColorOffset);
reed@google.comac10a2d2010-12-22 21:39:39 +0000368 if (oldColorOffset <= 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000369 GL_CALL(EnableClientState(GR_GL_COLOR_ARRAY));
370 GL_CALL(ColorPointer(4, GR_GL_UNSIGNED_BYTE,
371 newStride, colorOffset));
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000372 } else if (allOffsetsChange || newColorOffset != oldColorOffset) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000373 GL_CALL(ColorPointer(4, GR_GL_UNSIGNED_BYTE,
374 newStride, colorOffset));
reed@google.comac10a2d2010-12-22 21:39:39 +0000375 }
376 } else if (oldColorOffset > 0) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000377 GL_CALL(DisableClientState(GR_GL_COLOR_ARRAY));
reed@google.comac10a2d2010-12-22 21:39:39 +0000378 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000379
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000380 fHWGeometryState.fVertexLayout = this->getGeomSrc().fVertexLayout;
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +0000381 fHWGeometryState.fArrayPtrsDirty = false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000382}