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 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 20 | #include "GrGpuGLFixed.h" |
| 21 | #include "GrGpuVertex.h" |
| 22 | |
| 23 | #define SKIP_CACHE_CHECK true |
| 24 | |
| 25 | struct GrGpuMatrix { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 26 | GrGLfloat fMat[16]; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 27 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 28 | void reset() { |
| 29 | Gr_bzero(fMat, sizeof(fMat)); |
| 30 | fMat[0] = fMat[5] = fMat[10] = fMat[15] = GR_Scalar1; |
| 31 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 32 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 33 | void set(const GrMatrix& m) { |
| 34 | Gr_bzero(fMat, sizeof(fMat)); |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 35 | fMat[0] = GrScalarToFloat(m[GrMatrix::kScaleX]); |
| 36 | fMat[4] = GrScalarToFloat(m[GrMatrix::kSkewX]); |
| 37 | fMat[12] = GrScalarToFloat(m[GrMatrix::kTransX]); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 38 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 39 | fMat[1] = GrScalarToFloat(m[GrMatrix::kSkewY]); |
| 40 | fMat[5] = GrScalarToFloat(m[GrMatrix::kScaleY]); |
| 41 | fMat[13] = GrScalarToFloat(m[GrMatrix::kTransY]); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 42 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 43 | fMat[3] = GrScalarToFloat(m[GrMatrix::kPersp0]); |
| 44 | fMat[7] = GrScalarToFloat(m[GrMatrix::kPersp1]); |
| 45 | fMat[15] = GrScalarToFloat(m[GrMatrix::kPersp2]); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 46 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 47 | fMat[10] = 1.f; // z-scale |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 48 | } |
| 49 | }; |
| 50 | |
| 51 | // these must match the order in the corresponding enum in GrGpu.h |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 52 | static const GrGLenum gMatrixMode2Enum[] = { |
| 53 | GR_GL_MODELVIEW, GR_GL_TEXTURE |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | /////////////////////////////////////////////////////////////////////////////// |
| 57 | |
| 58 | GrGpuGLFixed::GrGpuGLFixed() { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | GrGpuGLFixed::~GrGpuGLFixed() { |
| 62 | } |
| 63 | |
| 64 | void GrGpuGLFixed::resetContext() { |
| 65 | INHERITED::resetContext(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 66 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 67 | GR_GL(Disable(GR_GL_TEXTURE_2D)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 68 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 69 | for (int s = 0; s < kNumStages; ++s) { |
| 70 | setTextureUnit(s); |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 71 | GR_GL(EnableClientState(GR_GL_VERTEX_ARRAY)); |
| 72 | GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_TEXTURE_ENV_MODE, GR_GL_COMBINE)); |
| 73 | GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_COMBINE_RGB, GR_GL_MODULATE)); |
| 74 | GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC0_RGB, GR_GL_TEXTURE0+s)); |
| 75 | GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC1_RGB, GR_GL_PREVIOUS)); |
| 76 | GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_OPERAND1_RGB, GR_GL_SRC_COLOR)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 77 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 78 | GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_COMBINE_ALPHA, GR_GL_MODULATE)); |
| 79 | GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC0_ALPHA, GR_GL_TEXTURE0+s)); |
| 80 | GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_OPERAND0_ALPHA, GR_GL_SRC_ALPHA)); |
| 81 | GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC1_ALPHA, GR_GL_PREVIOUS)); |
| 82 | GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_OPERAND1_ALPHA, GR_GL_SRC_ALPHA)); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 83 | |
| 84 | // color oprand0 changes between GL_SRC_COLR and GL_SRC_ALPHA depending |
| 85 | // 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] | 86 | // texture, e.g.: |
| 87 | //glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 88 | fHWRGBOperand0[s] = (TextureEnvRGBOperands) -1; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 89 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 90 | |
| 91 | fHWGeometryState.fVertexLayout = 0; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 92 | fHWGeometryState.fVertexOffset = ~0; |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 93 | GR_GL(EnableClientState(GR_GL_VERTEX_ARRAY)); |
| 94 | GR_GL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY)); |
| 95 | GR_GL(ShadeModel(GR_GL_FLAT)); |
| 96 | GR_GL(DisableClientState(GR_GL_COLOR_ARRAY)); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 97 | |
| 98 | GR_GL(PointSize(1.f)); |
| 99 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 100 | GrGLClearErr(); |
| 101 | fTextVerts = false; |
| 102 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 103 | fBaseVertex = 0xffffffff; |
| 104 | } |
| 105 | |
| 106 | |
| 107 | void GrGpuGLFixed::flushProjectionMatrix() { |
| 108 | float mat[16]; |
| 109 | Gr_bzero(mat, sizeof(mat)); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 110 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 111 | GrAssert(NULL != fCurrDrawState.fRenderTarget); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 112 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 113 | mat[0] = 2.f / fCurrDrawState.fRenderTarget->width(); |
| 114 | mat[5] = -2.f / fCurrDrawState.fRenderTarget->height(); |
| 115 | mat[10] = -1.f; |
| 116 | mat[15] = 1; |
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 | mat[12] = -1.f; |
| 119 | mat[13] = 1.f; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 120 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 121 | GR_GL(MatrixMode(GR_GL_PROJECTION)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 122 | GR_GL(LoadMatrixf(mat)); |
| 123 | } |
| 124 | |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 125 | bool GrGpuGLFixed::flushGraphicsState(GrPrimitiveType type) { |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 126 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 127 | bool usingTextures[kNumStages]; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 128 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 129 | for (int s = 0; s < kNumStages; ++s) { |
| 130 | usingTextures[s] = VertexUsesStage(s, fGeometrySrc.fVertexLayout); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 131 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 132 | if (usingTextures[s] && fCurrDrawState.fSamplerStates[s].isGradient()) { |
| 133 | unimpl("Fixed pipe doesn't support radial/sweep gradients"); |
| 134 | return false; |
| 135 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 136 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 137 | |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 138 | if (GR_GL_SUPPORT_ES1) { |
| 139 | if (BlendCoefReferencesConstant(fCurrDrawState.fSrcBlend) || |
| 140 | BlendCoefReferencesConstant(fCurrDrawState.fDstBlend)) { |
| 141 | unimpl("ES1 doesn't support blend constant"); |
| 142 | return false; |
| 143 | } |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 144 | } |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 145 | |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 146 | if (!flushGLStateCommon(type)) { |
| 147 | return false; |
| 148 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 149 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 150 | if (fDirtyFlags.fRenderTargetChanged) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 151 | flushProjectionMatrix(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 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]) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 159 | GR_GL(Enable(GR_GL_TEXTURE_2D)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 160 | } else { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 161 | GR_GL(Disable(GR_GL_TEXTURE_2D)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 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) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 172 | GR_GL(ShadeModel(GR_GL_SMOOTH)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 173 | // invalidate the immediate mode color |
| 174 | fHWDrawState.fColor = GrColor_ILLEGAL; |
| 175 | } else { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 176 | GR_GL(ShadeModel(GR_GL_FLAT)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 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); |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 200 | GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, |
| 201 | GR_GL_OPERAND0_RGB, |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 202 | (nextRGBOperand0==kAlpha_TextureEnvRGBOperand) ? |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 203 | GR_GL_SRC_ALPHA : |
| 204 | GR_GL_SRC_COLOR)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 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 | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 208 | if (((1 << s) & fDirtyFlags.fTextureChangedMask) || |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 209 | (fHWDrawState.fSamplerStates[s].getMatrix() != |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 210 | getSamplerMatrix(s))) { |
| 211 | |
| 212 | GrMatrix texMat = getSamplerMatrix(s); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 213 | AdjustTextureMatrix(texture, |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 214 | GrSamplerState::kNormal_SampleMode, |
| 215 | &texMat); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 216 | GrGpuMatrix glm; |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 217 | glm.set(texMat); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 218 | setTextureUnit(s); |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 219 | GR_GL(MatrixMode(GR_GL_TEXTURE)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 220 | GR_GL(LoadMatrixf(glm.fMat)); |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 221 | recordHWSamplerMatrix(s, getSamplerMatrix(s)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 222 | } |
| 223 | } else { |
| 224 | GrAssert(!"Rendering with texture vert flag set but no bound texture"); |
| 225 | return false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 226 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 230 | if (fHWDrawState.fViewMatrix != fCurrDrawState.fViewMatrix) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 231 | GrGpuMatrix glm; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 232 | glm.set(fCurrDrawState.fViewMatrix); |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 233 | GR_GL(MatrixMode(GR_GL_MODELVIEW)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 234 | GR_GL(LoadMatrixf(glm.fMat)); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 235 | fHWDrawState.fViewMatrix = |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 236 | fCurrDrawState.fViewMatrix; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 237 | } |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 238 | resetDirtyFlags(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 239 | return true; |
| 240 | } |
| 241 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 242 | void GrGpuGLFixed::setupGeometry(int* startVertex, |
| 243 | int* startIndex, |
| 244 | int vertexCount, |
| 245 | int indexCount) { |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 246 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 247 | int newColorOffset; |
| 248 | int newTexCoordOffsets[kNumStages]; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 249 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 250 | GrGLsizei newStride = VertexSizeAndOffsetsByStage(fGeometrySrc.fVertexLayout, |
| 251 | newTexCoordOffsets, |
| 252 | &newColorOffset); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 253 | int oldColorOffset; |
| 254 | int oldTexCoordOffsets[kNumStages]; |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 255 | GrGLsizei oldStride = VertexSizeAndOffsetsByStage(fHWGeometryState.fVertexLayout, |
| 256 | oldTexCoordOffsets, |
| 257 | &oldColorOffset); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 258 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 259 | bool indexed = NULL != startIndex; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 260 | |
| 261 | int extraVertexOffset; |
| 262 | int extraIndexOffset; |
| 263 | setBuffers(indexed, &extraVertexOffset, &extraIndexOffset); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 264 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 265 | GrGLenum scalarType; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 266 | if (fGeometrySrc.fVertexLayout & kTextFormat_VertexLayoutBit) { |
| 267 | scalarType = GrGLTextType; |
| 268 | } else { |
| 269 | scalarType = GrGLType; |
| 270 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 271 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 272 | size_t vertexOffset = (*startVertex + extraVertexOffset) * newStride; |
| 273 | *startVertex = 0; |
| 274 | if (indexed) { |
| 275 | *startIndex += extraIndexOffset; |
| 276 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 277 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 278 | // all the Pointers must be set if any of these are true |
| 279 | bool allOffsetsChange = fHWGeometryState.fArrayPtrsDirty || |
| 280 | vertexOffset != fHWGeometryState.fVertexOffset || |
| 281 | newStride != oldStride; |
| 282 | |
| 283 | // position and tex coord offsets change if above conditions are true |
| 284 | // or the type changed based on text vs nontext type coords. |
| 285 | bool posAndTexChange = allOffsetsChange || |
| 286 | ((GrGLTextType != GrGLType) && |
| 287 | (kTextFormat_VertexLayoutBit & |
| 288 | (fHWGeometryState.fVertexLayout ^ |
| 289 | fGeometrySrc.fVertexLayout))); |
| 290 | |
| 291 | if (posAndTexChange) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 292 | GR_GL(VertexPointer(2, scalarType, newStride, (GrGLvoid*)vertexOffset)); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 293 | fHWGeometryState.fVertexOffset = vertexOffset; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 294 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 295 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 296 | for (int s = 0; s < kNumStages; ++s) { |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 297 | // need to enable array if tex coord offset is 0 |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 298 | // (using positions as coords) |
| 299 | if (newTexCoordOffsets[s] >= 0) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 300 | GrGLvoid* texCoordOffset = (GrGLvoid*)(vertexOffset + newTexCoordOffsets[s]); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 301 | if (oldTexCoordOffsets[s] < 0) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 302 | GR_GL(ClientActiveTexture(GR_GL_TEXTURE0+s)); |
| 303 | GR_GL(EnableClientState(GR_GL_TEXTURE_COORD_ARRAY)); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 304 | GR_GL(TexCoordPointer(2, scalarType, newStride, texCoordOffset)); |
| 305 | } else if (posAndTexChange || |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 306 | newTexCoordOffsets[s] != oldTexCoordOffsets[s]) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 307 | GR_GL(ClientActiveTexture(GR_GL_TEXTURE0+s)); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 308 | GR_GL(TexCoordPointer(2, scalarType, newStride, texCoordOffset)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 309 | } |
| 310 | } else if (oldTexCoordOffsets[s] >= 0) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 311 | GR_GL(ClientActiveTexture(GR_GL_TEXTURE0+s)); |
| 312 | GR_GL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 313 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 314 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 315 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 316 | if (newColorOffset > 0) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 317 | GrGLvoid* colorOffset = (GrGLvoid*)(vertexOffset + newColorOffset); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 318 | if (oldColorOffset <= 0) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 319 | GR_GL(EnableClientState(GR_GL_COLOR_ARRAY)); |
| 320 | GR_GL(ColorPointer(4, GR_GL_UNSIGNED_BYTE, newStride, colorOffset)); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 321 | } else if (allOffsetsChange || newColorOffset != oldColorOffset) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 322 | GR_GL(ColorPointer(4, GR_GL_UNSIGNED_BYTE, newStride, colorOffset)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 323 | } |
| 324 | } else if (oldColorOffset > 0) { |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 325 | GR_GL(DisableClientState(GR_GL_COLOR_ARRAY)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 326 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 327 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 328 | fHWGeometryState.fVertexLayout = fGeometrySrc.fVertexLayout; |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 329 | fHWGeometryState.fArrayPtrsDirty = false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 330 | } |