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 | #ifndef GrDrawTarget_DEFINED |
| 19 | #define GrDrawTarget_DEFINED |
| 20 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 21 | #include "GrMatrix.h" |
| 22 | #include "GrColor.h" |
| 23 | #include "GrRefCnt.h" |
| 24 | #include "GrSamplerState.h" |
| 25 | #include "GrClip.h" |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 26 | #include "GrTexture.h" |
| 27 | #include "GrStencil.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 28 | |
| 29 | class GrTexture; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 30 | class GrClipIterator; |
| 31 | class GrVertexBuffer; |
| 32 | class GrIndexBuffer; |
| 33 | |
| 34 | class GrDrawTarget : public GrRefCnt { |
| 35 | public: |
| 36 | /** |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 37 | * Number of texture stages. Each stage takes as input a color and |
| 38 | * 2D texture coordinates. The color input to the first enabled stage is the |
| 39 | * per-vertex color or the constant color (setColor/setAlpha) if there are |
| 40 | * no per-vertex colors. For subsequent stages the input color is the output |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 41 | * color from the previous enabled stage. The output color of each stage is |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 42 | * the input color modulated with the result of a texture lookup. Texture |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 43 | * lookups are specified by a texture a sampler (setSamplerState). Texture |
| 44 | * coordinates for each stage come from the vertices based on a |
| 45 | * GrVertexLayout bitfield. The output fragment color is the output color of |
| 46 | * the last enabled stage. The presence or absence of texture coordinates |
| 47 | * for each stage in the vertex layout indicates whether a stage is enabled |
| 48 | * or not. |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 49 | */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 50 | enum { |
bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 51 | kNumStages = 2, |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 52 | kMaxTexCoords = kNumStages |
| 53 | }; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 54 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 55 | /** |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 56 | * Bitfield used to indicate which stages are in use. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 57 | */ |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 58 | typedef int StageBitfield; |
| 59 | GR_STATIC_ASSERT(sizeof(StageBitfield)*8 >= kNumStages); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * Flags that affect rendering. Controlled using enable/disableState(). All |
| 63 | * default to disabled. |
| 64 | */ |
| 65 | enum StateBits { |
| 66 | kDither_StateBit = 0x1,//<! Perform color dithering |
| 67 | kAntialias_StateBit = 0x2,//<! Perform anti-aliasing. The render- |
| 68 | // target must support some form of AA |
| 69 | // (msaa, coverage sampling, etc). For |
| 70 | // GrGpu-created rendertarget/textures |
| 71 | // this is controlled by parameters |
| 72 | // passed to createTexture. |
| 73 | kClip_StateBit = 0x4,//<! Controls whether drawing is clipped |
| 74 | // against the region specified by |
| 75 | // setClip. |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 76 | kNoColorWrites_StateBit = 0x8,//<! If set it disables writing colors. |
| 77 | // Useful while performing stencil ops. |
| 78 | |
| 79 | // subclass may use additional bits internally |
| 80 | kDummyStateBit, |
| 81 | kLastPublicStateBit = kDummyStateBit-1 |
| 82 | }; |
| 83 | |
| 84 | enum DrawFace { |
| 85 | kBoth_DrawFace, |
| 86 | kCCW_DrawFace, |
| 87 | kCW_DrawFace, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 91 | * The DrawTarget may reserve some of the high bits of the stencil. The draw |
| 92 | * target will automatically trim reference and mask values so that the |
| 93 | * client doesn't overwrite these bits. |
| 94 | * The number of bits available is relative to the currently set render |
| 95 | *target. |
| 96 | * @return the number of bits usable by the draw target client. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 97 | */ |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 98 | int getUsableStencilBits() const { |
| 99 | int bits = fCurrDrawState.fRenderTarget->stencilBits(); |
| 100 | if (bits) { |
| 101 | return bits - 1; |
| 102 | } else { |
| 103 | return 0; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Sets the stencil settings to use for the next draw. |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame^] | 109 | * Changing the clip has the side-effect of possibly zeroing |
| 110 | * out the client settable stencil bits. So multipass algorithms |
| 111 | * using stencil should not change the clip between passes. |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 112 | * @param settings the stencil settings to use. |
| 113 | */ |
| 114 | void setStencil(const GrStencilSettings& settings) { |
| 115 | fCurrDrawState.fStencilSettings = settings; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Shortcut to disable stencil testing and ops. |
| 120 | */ |
| 121 | void disableStencil() { |
| 122 | fCurrDrawState.fStencilSettings.setDisabled(); |
| 123 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 124 | |
| 125 | protected: |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 126 | |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 127 | struct DrState { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 128 | DrState() { |
| 129 | // make sure any pad is zero for memcmp |
| 130 | // all DrState members should default to something |
| 131 | // valid by the memset |
| 132 | memset(this, 0, sizeof(DrState)); |
| 133 | GrAssert((intptr_t)(void*)NULL == 0LL); |
| 134 | GrAssert(fStencilSettings.isDisabled()); |
| 135 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 136 | uint32_t fFlagBits; |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 137 | GrBlendCoeff fSrcBlend; |
| 138 | GrBlendCoeff fDstBlend; |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 139 | GrTexture* fTextures[kNumStages]; |
| 140 | GrSamplerState fSamplerStates[kNumStages]; |
| 141 | GrRenderTarget* fRenderTarget; |
| 142 | GrColor fColor; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 143 | DrawFace fDrawFace; |
| 144 | |
| 145 | GrStencilSettings fStencilSettings; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 146 | GrMatrix fViewMatrix; |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 147 | bool operator ==(const DrState& s) const { |
| 148 | return 0 == memcmp(this, &s, sizeof(DrState)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 149 | } |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 150 | bool operator !=(const DrState& s) const { return !(*this == s); } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | public: |
| 154 | /////////////////////////////////////////////////////////////////////////// |
| 155 | |
| 156 | GrDrawTarget(); |
| 157 | |
| 158 | /** |
| 159 | * Sets the current clip to the region specified by clip. All draws will be |
| 160 | * clipped against this clip if kClip_StateBit is enabled. |
| 161 | * |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame^] | 162 | * Setting the clip may (or may not) zero out the client's stencil bits. |
| 163 | * |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 164 | * @param description of the clipping region |
| 165 | */ |
| 166 | void setClip(const GrClip& clip); |
| 167 | |
| 168 | /** |
| 169 | * Gets the current clip. |
| 170 | * |
| 171 | * @return the clip. |
| 172 | */ |
| 173 | const GrClip& getClip() const; |
| 174 | |
| 175 | /** |
| 176 | * Sets the texture used at the next drawing call |
| 177 | * |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 178 | * @param stage The texture stage for which the texture will be set |
| 179 | * |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 180 | * @param texture The texture to set. Can be NULL though there is no advantage |
| 181 | * to settings a NULL texture if doing non-textured drawing |
| 182 | */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 183 | void setTexture(int stage, GrTexture* texture); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 184 | |
| 185 | /** |
| 186 | * Retrieves the currently set texture. |
| 187 | * |
| 188 | * @return The currently set texture. The return value will be NULL if no |
| 189 | * texture has been set, NULL was most recently passed to |
| 190 | * setTexture, or the last setTexture was destroyed. |
| 191 | */ |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 192 | const GrTexture* getTexture(int stage) const; |
| 193 | GrTexture* getTexture(int stage); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 194 | |
| 195 | /** |
| 196 | * Sets the rendertarget used at the next drawing call |
| 197 | * |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 198 | * @param target The render target to set. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 199 | */ |
| 200 | void setRenderTarget(GrRenderTarget* target); |
| 201 | |
| 202 | /** |
| 203 | * Retrieves the currently set rendertarget. |
| 204 | * |
| 205 | * @return The currently set render target. |
| 206 | */ |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 207 | const GrRenderTarget* getRenderTarget() const; |
| 208 | GrRenderTarget* getRenderTarget(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 209 | |
| 210 | /** |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 211 | * Sets the sampler state for a stage used in subsequent draws. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 212 | * |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 213 | * The sampler state determines how texture coordinates are |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 214 | * intepretted and used to sample the texture. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 215 | * |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 216 | * @param stage the stage of the sampler to set |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 217 | * @param samplerState Specifies the sampler state. |
| 218 | */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 219 | void setSamplerState(int stage, const GrSamplerState& samplerState); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 220 | |
| 221 | /** |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 222 | * Concats the matrix of a stage's sampler. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 223 | * |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 224 | * @param stage the stage of the sampler to set |
| 225 | * @param matrix the matrix to concat |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 226 | */ |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 227 | void preConcatSamplerMatrix(int stage, const GrMatrix& matrix) { |
| 228 | GrAssert(stage >= 0 && stage < kNumStages); |
| 229 | fCurrDrawState.fSamplerStates[stage].preConcatMatrix(matrix); |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 230 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 231 | |
| 232 | /** |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 233 | * Gets the matrix of a stage's sampler |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 234 | * |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 235 | * @param stage the stage to of sampler to get |
| 236 | * @return the sampler state's matrix |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 237 | */ |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 238 | const GrMatrix& getSamplerMatrix(int stage) const { |
| 239 | return fCurrDrawState.fSamplerStates[stage].getMatrix(); |
| 240 | } |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 241 | |
| 242 | /** |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 243 | * Sets the matrix of a stage's sampler |
| 244 | * |
| 245 | * @param stage the stage of sampler set |
| 246 | * @param matrix the matrix to set |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 247 | */ |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 248 | const void setSamplerMatrix(int stage, const GrMatrix& matrix) { |
| 249 | fCurrDrawState.fSamplerStates[stage].setMatrix(matrix); |
| 250 | } |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 251 | |
| 252 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 253 | * Sets the matrix applied to veretx positions. |
| 254 | * |
| 255 | * In the post-view-matrix space the rectangle [0,w]x[0,h] |
| 256 | * fully covers the render target. (w and h are the width and height of the |
| 257 | * the rendertarget.) |
| 258 | * |
| 259 | * @param m the matrix used to transform the vertex positions. |
| 260 | */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 261 | void setViewMatrix(const GrMatrix& m); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 262 | |
| 263 | /** |
| 264 | * Multiplies the current view matrix by a matrix |
| 265 | * |
| 266 | * After this call V' = V*m where V is the old view matrix, |
| 267 | * m is the parameter to this function, and V' is the new view matrix. |
| 268 | * (We consider positions to be column vectors so position vector p is |
| 269 | * transformed by matrix X as p' = X*p.) |
| 270 | * |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 271 | * @param m the matrix used to modify the view matrix. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 272 | */ |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 273 | void preConcatViewMatrix(const GrMatrix& m); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 274 | |
| 275 | /** |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 276 | * Retrieves the current view matrix |
| 277 | * @return the current view matrix. |
| 278 | */ |
| 279 | const GrMatrix& getViewMatrix() const; |
| 280 | |
| 281 | /** |
| 282 | * Retrieves the inverse of the current view matrix. |
| 283 | * |
| 284 | * If the current view matrix is invertible, return true, and if matrix |
| 285 | * is non-null, copy the inverse into it. If the current view matrix is |
| 286 | * non-invertible, return false and ignore the matrix parameter. |
| 287 | * |
| 288 | * @param matrix if not null, will receive a copy of the current inverse. |
| 289 | */ |
| 290 | bool getViewInverse(GrMatrix* matrix) const; |
| 291 | |
| 292 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 293 | * Sets color for next draw to a premultiplied-alpha color. |
| 294 | * |
| 295 | * @param the color to set. |
| 296 | */ |
| 297 | void setColor(GrColor); |
| 298 | |
| 299 | /** |
| 300 | * Sets the color to be used for the next draw to be |
| 301 | * (r,g,b,a) = (alpha, alpha, alpha, alpha). |
| 302 | * |
| 303 | * @param alpha The alpha value to set as the color. |
| 304 | */ |
| 305 | void setAlpha(uint8_t alpha); |
| 306 | |
| 307 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 308 | * Controls whether clockwise, counterclockwise, or both faces are drawn. |
| 309 | * @param face the face(s) to draw. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 310 | */ |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 311 | void setDrawFace(DrawFace face) { fCurrDrawState.fDrawFace = face; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 312 | |
| 313 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 314 | * Gets whether the target is drawing clockwise, counterclockwise, |
| 315 | * or both faces. |
| 316 | * @return the current draw face(s). |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 317 | */ |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 318 | DrawFace getDrawFace() const { return fCurrDrawState.fDrawFace; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 319 | |
| 320 | /** |
| 321 | * Enable render state settings. |
| 322 | * |
| 323 | * @param flags bitfield of StateBits specifing the states to enable |
| 324 | */ |
| 325 | void enableState(uint32_t stateBits); |
| 326 | |
| 327 | /** |
| 328 | * Disable render state settings. |
| 329 | * |
| 330 | * @param flags bitfield of StateBits specifing the states to disable |
| 331 | */ |
| 332 | void disableState(uint32_t stateBits); |
| 333 | |
| 334 | bool isDitherState() const { |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 335 | return 0 != (fCurrDrawState.fFlagBits & kDither_StateBit); |
| 336 | } |
| 337 | |
| 338 | bool isClipState() const { |
| 339 | return 0 != (fCurrDrawState.fFlagBits & kClip_StateBit); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 340 | } |
| 341 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 342 | bool isColorWriteDisabled() const { |
| 343 | return 0 != (fCurrDrawState.fFlagBits & kNoColorWrites_StateBit); |
| 344 | } |
| 345 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 346 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 347 | * Sets the blending function coeffecients. |
| 348 | * |
| 349 | * The blend function will be: |
| 350 | * D' = sat(S*srcCoef + D*dstCoef) |
| 351 | * |
| 352 | * where D is the existing destination color, S is the incoming source |
| 353 | * color, and D' is the new destination color that will be written. sat() |
| 354 | * is the saturation function. |
| 355 | * |
| 356 | * @param srcCoef coeffecient applied to the src color. |
| 357 | * @param dstCoef coeffecient applied to the dst color. |
| 358 | */ |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 359 | void setBlendFunc(GrBlendCoeff srcCoef, GrBlendCoeff dstCoef); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 360 | |
| 361 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 362 | * Used to save and restore the GrGpu's drawing state |
| 363 | */ |
| 364 | struct SavedDrawState { |
| 365 | private: |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 366 | DrState fState; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 367 | friend class GrDrawTarget; |
| 368 | }; |
| 369 | |
| 370 | /** |
| 371 | * Saves the current draw state. The state can be restored at a later time |
| 372 | * with restoreDrawState. |
| 373 | * |
| 374 | * See also AutoStateRestore class. |
| 375 | * |
| 376 | * @param state will hold the state after the function returns. |
| 377 | */ |
| 378 | void saveCurrentDrawState(SavedDrawState* state) const; |
| 379 | |
| 380 | /** |
| 381 | * Restores previously saved draw state. The client guarantees that state |
| 382 | * was previously passed to saveCurrentDrawState and that the rendertarget |
| 383 | * and texture set at save are still valid. |
| 384 | * |
| 385 | * See also AutoStateRestore class. |
| 386 | * |
| 387 | * @param state the previously saved state to restore. |
| 388 | */ |
| 389 | void restoreDrawState(const SavedDrawState& state); |
| 390 | |
| 391 | /** |
| 392 | * Copies the draw state from another target to this target. |
| 393 | * |
| 394 | * @param srcTarget draw target used as src of the draw state. |
| 395 | */ |
| 396 | void copyDrawState(const GrDrawTarget& srcTarget); |
| 397 | |
| 398 | /** |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 399 | * The format of vertices is represented as a bitfield of flags. |
| 400 | * Flags that indicate the layout of vertex data. Vertices always contain |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 401 | * positions and may also contain up to kMaxTexCoords sets of 2D texture |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 402 | * coordinates and per-vertex colors. Each stage can use any of the texture |
| 403 | * coordinates as its input texture coordinates or it may use the positions. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 404 | * |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 405 | * If no texture coordinates are specified for a stage then the stage is |
| 406 | * disabled. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 407 | * |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 408 | * Only one type of texture coord can be specified per stage. For |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 409 | * example StageTexCoordVertexLayoutBit(0, 2) and |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 410 | * StagePosAsTexCoordVertexLayoutBit(0) cannot both be specified. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 411 | * |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 412 | * The order in memory is always (position, texture coord 0, ..., color) |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 413 | * with any unused fields omitted. Note that this means that if only texture |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 414 | * coordinates 1 is referenced then there is no texture coordinates 0 and |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 415 | * the order would be (position, texture coordinate 1[, color]). |
| 416 | */ |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 417 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 418 | /** |
| 419 | * Generates a bit indicating that a texture stage uses texture coordinates |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 420 | * |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 421 | * @param stage the stage that will use texture coordinates. |
| 422 | * @param texCoordIdx the index of the texture coordinates to use |
| 423 | * |
| 424 | * @return the bit to add to a GrVertexLayout bitfield. |
| 425 | */ |
| 426 | static int StageTexCoordVertexLayoutBit(int stage, int texCoordIdx) { |
| 427 | GrAssert(stage < kNumStages); |
| 428 | GrAssert(texCoordIdx < kMaxTexCoords); |
| 429 | return 1 << (stage + (texCoordIdx * kNumStages)); |
| 430 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 431 | |
| 432 | /** |
| 433 | * Determines if blend is effectively disabled. |
| 434 | * |
| 435 | * @return true if blend can be disabled without changing the rendering |
| 436 | * result given the current state including the vertex layout specified |
| 437 | * with the vertex source. |
| 438 | */ |
| 439 | bool canDisableBlend() const; |
| 440 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 441 | private: |
| 442 | static const int TEX_COORD_BIT_CNT = kNumStages*kMaxTexCoords; |
| 443 | public: |
| 444 | /** |
| 445 | * Generates a bit indicating that a texture stage uses the position |
| 446 | * as its texture coordinate. |
| 447 | * |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 448 | * @param stage the stage that will use position as texture |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 449 | * coordinates. |
| 450 | * |
| 451 | * @return the bit to add to a GrVertexLayout bitfield. |
| 452 | */ |
| 453 | static int StagePosAsTexCoordVertexLayoutBit(int stage) { |
| 454 | GrAssert(stage < kNumStages); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 455 | return (1 << (TEX_COORD_BIT_CNT + stage)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 456 | } |
| 457 | private: |
| 458 | static const int STAGE_BIT_CNT = TEX_COORD_BIT_CNT + kNumStages; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 459 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 460 | public: |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 461 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 462 | /** |
| 463 | * Additional Bits that can be specified in GrVertexLayout. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 464 | */ |
| 465 | enum VertexLayoutBits { |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 466 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 467 | kColor_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 0), |
| 468 | //<! vertices have colors |
| 469 | kTextFormat_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 1), |
| 470 | //<! use text vertices. (Pos |
| 471 | // and tex coords may be |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 472 | // a different type for |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 473 | // text [GrGpuTextVertex vs |
| 474 | // GrPoint].) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 475 | // for below assert |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 476 | kDummyVertexLayoutBit, |
| 477 | kHighVertexLayoutBit = kDummyVertexLayoutBit - 1 |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 478 | }; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 479 | // make sure we haven't exceeded the number of bits in GrVertexLayout. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 480 | GR_STATIC_ASSERT(kHighVertexLayoutBit < (1 << 8*sizeof(GrVertexLayout))); |
| 481 | |
| 482 | /** |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 483 | * There are three paths for specifying geometry (vertices and optionally |
| 484 | * indices) to the draw target. When indexed drawing the indices and vertices |
| 485 | * can be each use a different path. |
| 486 | * |
| 487 | * 1. Provide a cpu array (set*SourceToArray). This is useful when the |
| 488 | * caller's client has already provided vertex data in a format |
| 489 | * the time compatible with a GrVertexLayout. The array must contain the |
| 490 | * data at set*SourceToArray is called. The source stays in effect for |
| 491 | * drawIndexed & drawNonIndexed calls until set*SourceToArray is called |
| 492 | * again or one of the other two paths is chosen. |
| 493 | * |
| 494 | * 2. Reserve and Lock. This is most useful when the caller has data it must |
| 495 | * transform before drawing and will not likely render it again. The |
| 496 | * caller requests that the draw target make room for some amount of |
| 497 | * vertex and/or index data. The target provides ptrs to hold the data |
| 498 | * data. The caller can write the data into the pts up until the first |
| 499 | * drawIndexed or drawNonIndexed call. At this point the data is frozen |
| 500 | * and the ptrs are no longer guaranteed to be valid. All subsequent |
| 501 | * drawIndexed & drawNonIndexed calls will use this data until |
| 502 | * releaseReserved geometry is called. This must be called before another |
| 503 | * source is set. |
| 504 | * |
| 505 | * 3. Vertex and Index Buffers. This is most useful for geometry that will |
| 506 | * be rendered multiple times. SetVertexSourceToBuffer & |
| 507 | * SetIndexSourceToBuffer are used to set the buffer and subsequent |
| 508 | * drawIndexed and drawNonIndexed calls use this source until another |
| 509 | * source is set. |
| 510 | */ |
| 511 | |
| 512 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 513 | * Reserves space for vertices and/or indices. Draw target will use |
| 514 | * reserved vertices / indices at next draw. |
| 515 | * |
| 516 | * If succeeds: |
| 517 | * if vertexCount is nonzero, *vertices will be the array |
| 518 | * of vertices to be filled by caller. The next draw will read |
| 519 | * these vertices. |
| 520 | * |
| 521 | * if indecCount is nonzero, *indices will be the array of indices |
| 522 | * to be filled by caller. The next indexed draw will read from |
| 523 | * these indices. |
| 524 | * |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 525 | * If a client does not already have a vertex buffer then this is the |
| 526 | * preferred way to allocate vertex/index array. It allows the subclass of |
| 527 | * GrDrawTarget to decide whether to put data in buffers, to group vertex |
| 528 | * data that uses the same state (e.g. for deferred rendering), etc. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 529 | * |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 530 | * Following the first draw after reserveAndLockGeometry the ptrs returned |
| 531 | * by releaseReservedGeometry are no longer valid and the geometry data |
| 532 | * cannot be further modified. The contents that were put in the reserved |
| 533 | * space can be drawn by multiple draws, however. |
| 534 | * |
| 535 | * reserveAndLockGeometry must be matched with a releaseReservedGeometry |
| 536 | * call after all draws that reference the reserved geometry data have |
| 537 | * been called. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 538 | * |
| 539 | * AutoGeometryRelease can be used to automatically call the release. |
| 540 | * |
| 541 | * @param vertexCount the number of vertices to reserve space for. Can be 0. |
| 542 | * @param indexCount the number of indices to reserve space for. Can be 0. |
| 543 | * @param vertexLayout the format of vertices (ignored if vertexCount == 0). |
| 544 | * @param vertices will point to reserved vertex space if vertexCount is |
| 545 | * non-zero. Illegal to pass NULL if vertexCount > 0. |
| 546 | * @param indices will point to reserved index space if indexCount is |
| 547 | * non-zero. Illegal to pass NULL if indexCount > 0. |
| 548 | * |
| 549 | * @return true if succeeded in allocating space for the vertices and false |
| 550 | * if not. |
| 551 | */ |
| 552 | bool reserveAndLockGeometry(GrVertexLayout vertexLayout, |
| 553 | uint32_t vertexCount, |
| 554 | uint32_t indexCount, |
| 555 | void** vertices, |
| 556 | void** indices); |
| 557 | /** |
| 558 | * Provides hints to caller about the number of vertices and indices |
| 559 | * that can be allocated cheaply. This can be useful if caller is reserving |
| 560 | * space but doesn't know exactly how much geometry is needed. |
| 561 | * |
| 562 | * Also may hint whether the draw target should be flushed first. This is |
| 563 | * useful for deferred targets. |
| 564 | * |
| 565 | * @param vertexLayout layout of vertices caller would like to reserve |
| 566 | * @param vertexCount in: hint about how many vertices the caller would |
| 567 | * like to allocate. |
| 568 | * out: a hint about the number of vertices that can be |
| 569 | * allocated cheaply. Negative means no hint. |
| 570 | * Ignored if NULL. |
| 571 | * @param indexCount in: hint about how many indices the caller would |
| 572 | * like to allocate. |
| 573 | * out: a hint about the number of indices that can be |
| 574 | * allocated cheaply. Negative means no hint. |
| 575 | * Ignored if NULL. |
| 576 | * |
| 577 | * @return true if target should be flushed based on the input values. |
| 578 | */ |
| 579 | virtual bool geometryHints(GrVertexLayout vertexLayout, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 580 | int* vertexCount, |
| 581 | int* indexCount) const; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 582 | |
| 583 | /** |
| 584 | * Releases reserved vertex/index data from reserveAndLockGeometry(). |
| 585 | */ |
| 586 | void releaseReservedGeometry(); |
| 587 | |
| 588 | /** |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 589 | * Sets source of vertex data for the next draw. Array must contain |
| 590 | * the vertex data when this is called. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 591 | * |
| 592 | * @param array cpu array containing vertex data. |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 593 | * @param size size of the vertex data. |
| 594 | * @param vertexCount the number of vertices in the array. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 595 | */ |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 596 | void setVertexSourceToArray(GrVertexLayout vertexLayout, |
| 597 | const void* vertexArray, |
| 598 | int vertexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 599 | |
| 600 | /** |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 601 | * Sets source of index data for the next indexed draw. Array must contain |
| 602 | * the indices when this is called. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 603 | * |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 604 | * @param array cpu array containing index data. |
| 605 | * @param indexCount the number of indices in the array. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 606 | */ |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 607 | void setIndexSourceToArray(const void* indexArray, int indexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 608 | |
| 609 | /** |
| 610 | * Sets source of vertex data for the next draw. Data does not have to be |
| 611 | * in the buffer until drawIndexed or drawNonIndexed. |
| 612 | * |
| 613 | * @param buffer vertex buffer containing vertex data. Must be |
| 614 | * unlocked before draw call. |
| 615 | * @param vertexLayout layout of the vertex data in the buffer. |
| 616 | */ |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 617 | void setVertexSourceToBuffer(GrVertexLayout vertexLayout, |
| 618 | const GrVertexBuffer* buffer); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 619 | |
| 620 | /** |
| 621 | * Sets source of index data for the next indexed draw. Data does not have |
| 622 | * to be in the buffer until drawIndexed or drawNonIndexed. |
| 623 | * |
| 624 | * @param buffer index buffer containing indices. Must be unlocked |
| 625 | * before indexed draw call. |
| 626 | */ |
| 627 | void setIndexSourceToBuffer(const GrIndexBuffer* buffer); |
| 628 | |
| 629 | /** |
| 630 | * Draws indexed geometry using the current state and current vertex / index |
| 631 | * sources. |
| 632 | * |
| 633 | * @param type The type of primitives to draw. |
| 634 | * @param startVertex the vertex in the vertex array/buffer corresponding |
| 635 | * to index 0 |
| 636 | * @param startIndex first index to read from index src. |
| 637 | * @param vertexCount one greater than the max index. |
| 638 | * @param indexCount the number of index elements to read. The index count |
| 639 | * is effectively trimmed to the last completely |
| 640 | * specified primitive. |
| 641 | */ |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 642 | virtual void drawIndexed(GrPrimitiveType type, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 643 | int startVertex, |
| 644 | int startIndex, |
| 645 | int vertexCount, |
| 646 | int indexCount) = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 647 | |
| 648 | /** |
| 649 | * Draws non-indexed geometry using the current state and current vertex |
| 650 | * sources. |
| 651 | * |
| 652 | * @param type The type of primitives to draw. |
| 653 | * @param startVertex the vertex in the vertex array/buffer corresponding |
| 654 | * to index 0 |
| 655 | * @param vertexCount one greater than the max index. |
| 656 | */ |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 657 | virtual void drawNonIndexed(GrPrimitiveType type, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 658 | int startVertex, |
| 659 | int vertexCount) = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 660 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 661 | /** |
| 662 | * Helper function for drawing rects. This does not use the current index |
| 663 | * and vertex sources. After returning, the vertex and index sources may |
| 664 | * have changed. They should be reestablished before the next drawIndexed |
| 665 | * or drawNonIndexed. This cannot be called between reserving and releasing |
| 666 | * geometry. The GrDrawTarget subclass may be able to perform additional |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 667 | * optimizations if drawRect is used rather than drawIndexed or |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 668 | * drawNonIndexed. |
| 669 | * @param rect the rect to draw |
| 670 | * @param matrix optional matrix applied to rect (before viewMatrix) |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 671 | * @param stageEnableBitfield bitmask indicating which stages are enabled. |
| 672 | * Bit i indicates whether stage i is enabled. |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 673 | * @param srcRects specifies rects for stages enabled by stageEnableMask. |
| 674 | * if stageEnableMask bit i is 1, srcRects is not NULL, |
| 675 | * and srcRects[i] is not NULL, then srcRects[i] will be |
| 676 | * used as coordinates for stage i. Otherwise, if stage i |
| 677 | * is enabled then rect is used as the coordinates. |
| 678 | * @param srcMatrices optional matrices applied to srcRects. If |
| 679 | * srcRect[i] is non-NULL and srcMatrices[i] is |
| 680 | * non-NULL then srcRect[i] will be transformed by |
| 681 | * srcMatrix[i]. srcMatrices can be NULL when no |
| 682 | * srcMatrices are desired. |
| 683 | */ |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 684 | virtual void drawRect(const GrRect& rect, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 685 | const GrMatrix* matrix, |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 686 | StageBitfield stageEnableBitfield, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 687 | const GrRect* srcRects[], |
| 688 | const GrMatrix* srcMatrices[]); |
| 689 | |
| 690 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 691 | * Helper for drawRect when the caller doesn't need separate src rects or |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 692 | * matrices. |
| 693 | */ |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 694 | void drawSimpleRect(const GrRect& rect, |
| 695 | const GrMatrix* matrix, |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 696 | StageBitfield stageEnableBitfield) { |
| 697 | drawRect(rect, matrix, stageEnableBitfield, NULL, NULL); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 698 | } |
| 699 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 700 | /////////////////////////////////////////////////////////////////////////// |
| 701 | |
| 702 | class AutoStateRestore : ::GrNoncopyable { |
| 703 | public: |
| 704 | AutoStateRestore(GrDrawTarget* target); |
| 705 | ~AutoStateRestore(); |
| 706 | |
| 707 | private: |
| 708 | GrDrawTarget* fDrawTarget; |
| 709 | SavedDrawState fDrawState; |
| 710 | }; |
| 711 | |
| 712 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 713 | |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 714 | class AutoViewMatrixRestore : ::GrNoncopyable { |
| 715 | public: |
| 716 | AutoViewMatrixRestore() { |
| 717 | fDrawTarget = NULL; |
| 718 | } |
| 719 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 720 | AutoViewMatrixRestore(GrDrawTarget* target) |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 721 | : fDrawTarget(target), fMatrix(fDrawTarget->getViewMatrix()) { |
| 722 | GrAssert(NULL != target); |
| 723 | } |
| 724 | |
| 725 | void set(GrDrawTarget* target) { |
| 726 | GrAssert(NULL != target); |
| 727 | if (NULL != fDrawTarget) { |
| 728 | fDrawTarget->setViewMatrix(fMatrix); |
| 729 | } |
| 730 | fDrawTarget = target; |
| 731 | fMatrix = target->getViewMatrix(); |
| 732 | } |
| 733 | |
| 734 | ~AutoViewMatrixRestore() { |
| 735 | if (NULL != fDrawTarget) { |
| 736 | fDrawTarget->setViewMatrix(fMatrix); |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | private: |
| 741 | GrDrawTarget* fDrawTarget; |
| 742 | GrMatrix fMatrix; |
| 743 | }; |
| 744 | |
| 745 | /////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 746 | |
| 747 | class AutoReleaseGeometry : ::GrNoncopyable { |
| 748 | public: |
| 749 | AutoReleaseGeometry(GrDrawTarget* target, |
| 750 | GrVertexLayout vertexLayout, |
| 751 | uint32_t vertexCount, |
| 752 | uint32_t indexCount) { |
| 753 | fTarget = target; |
| 754 | fSuccess = fTarget->reserveAndLockGeometry(vertexLayout, |
| 755 | vertexCount, |
| 756 | indexCount, |
| 757 | &fVertices, |
| 758 | &fIndices); |
| 759 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 760 | |
| 761 | AutoReleaseGeometry() { |
| 762 | fSuccess = false; |
| 763 | } |
| 764 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 765 | ~AutoReleaseGeometry() { |
| 766 | if (fSuccess) { |
| 767 | fTarget->releaseReservedGeometry(); |
| 768 | } |
| 769 | } |
| 770 | |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 771 | bool set(GrDrawTarget* target, |
| 772 | GrVertexLayout vertexLayout, |
| 773 | uint32_t vertexCount, |
| 774 | uint32_t indexCount) { |
| 775 | if (fSuccess) { |
| 776 | fTarget->releaseReservedGeometry(); |
| 777 | } |
| 778 | fTarget = target; |
| 779 | fSuccess = fTarget->reserveAndLockGeometry(vertexLayout, |
| 780 | vertexCount, |
| 781 | indexCount, |
| 782 | &fVertices, |
| 783 | &fIndices); |
| 784 | return fSuccess; |
| 785 | } |
| 786 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 787 | bool succeeded() const { return fSuccess; } |
| 788 | void* vertices() const { return fVertices; } |
| 789 | void* indices() const { return fIndices; } |
| 790 | |
| 791 | GrPoint* positions() const { |
| 792 | return static_cast<GrPoint*>(fVertices); |
| 793 | } |
| 794 | |
| 795 | private: |
| 796 | GrDrawTarget* fTarget; |
| 797 | bool fSuccess; |
| 798 | void* fVertices; |
| 799 | void* fIndices; |
| 800 | }; |
| 801 | |
| 802 | /////////////////////////////////////////////////////////////////////////// |
| 803 | |
| 804 | class AutoClipRestore : ::GrNoncopyable { |
| 805 | public: |
| 806 | AutoClipRestore(GrDrawTarget* target) { |
| 807 | fTarget = target; |
| 808 | fClip = fTarget->getClip(); |
| 809 | } |
| 810 | |
| 811 | ~AutoClipRestore() { |
| 812 | fTarget->setClip(fClip); |
| 813 | } |
| 814 | private: |
| 815 | GrDrawTarget* fTarget; |
| 816 | GrClip fClip; |
| 817 | }; |
| 818 | |
| 819 | //////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 820 | // Helpers for picking apart vertex layouts |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 821 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 822 | /** |
| 823 | * Helper function to compute the size of a vertex from a vertex layout |
| 824 | * @return size of a single vertex. |
| 825 | */ |
| 826 | static size_t VertexSize(GrVertexLayout vertexLayout); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 827 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 828 | /** |
| 829 | * Helper function for determining the index of texture coordinates that |
| 830 | * is input for a texture stage. Note that a stage may instead use positions |
| 831 | * as texture coordinates, in which case the result of the function is |
| 832 | * indistinguishable from the case when the stage is disabled. |
| 833 | * |
| 834 | * @param stage the stage to query |
| 835 | * @param vertexLayout layout to query |
| 836 | * |
| 837 | * @return the texture coordinate index or -1 if the stage doesn't use |
| 838 | * separate (non-position) texture coordinates. |
| 839 | */ |
| 840 | static int VertexTexCoordsForStage(int stage, GrVertexLayout vertexLayout); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 841 | |
| 842 | /** |
| 843 | * Helper function to compute the offset of texture coordinates in a vertex |
| 844 | * @return offset of texture coordinates in vertex layout or -1 if the |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 845 | * layout has no texture coordinates. Will be 0 if positions are |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 846 | * used as texture coordinates for the stage. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 847 | */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 848 | static int VertexStageCoordOffset(int stage, GrVertexLayout vertexLayout); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 849 | |
| 850 | /** |
| 851 | * Helper function to compute the offset of the color in a vertex |
| 852 | * @return offset of color in vertex layout or -1 if the |
| 853 | * layout has no color. |
| 854 | */ |
| 855 | static int VertexColorOffset(GrVertexLayout vertexLayout); |
| 856 | |
| 857 | /** |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 858 | * Helper function to determine if vertex layout contains explicit texture |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 859 | * coordinates of some index. |
| 860 | * |
| 861 | * @param coordIndex the tex coord index to query |
| 862 | * @param vertexLayout layout to query |
| 863 | * |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 864 | * @return true if vertex specifies texture coordinates for the index, |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 865 | * false otherwise. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 866 | */ |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 867 | static bool VertexUsesTexCoordIdx(int coordIndex, |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 868 | GrVertexLayout vertexLayout); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 869 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 870 | /** |
| 871 | * Helper function to determine if vertex layout contains either explicit or |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 872 | * implicit texture coordinates for a stage. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 873 | * |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 874 | * @param stage the stage to query |
| 875 | * @param vertexLayout layout to query |
| 876 | * |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 877 | * @return true if vertex specifies texture coordinates for the stage, |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 878 | * false otherwise. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 879 | */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 880 | static bool VertexUsesStage(int stage, GrVertexLayout vertexLayout); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 881 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 882 | /** |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 883 | * Helper function to compute the size of each vertex and the offsets of |
| 884 | * texture coordinates and color. Determines tex coord offsets by tex coord |
| 885 | * index rather than by stage. (Each stage can be mapped to any t.c. index |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 886 | * by StageTexCoordVertexLayoutBit.) |
| 887 | * |
| 888 | * @param vertexLayout the layout to query |
| 889 | * @param texCoordOffsetsByIdx after return it is the offset of each |
| 890 | * tex coord index in the vertex or -1 if |
| 891 | * index isn't used. |
| 892 | * @return size of a single vertex |
| 893 | */ |
| 894 | static int VertexSizeAndOffsetsByIdx(GrVertexLayout vertexLayout, |
| 895 | int texCoordOffsetsByIdx[kMaxTexCoords], |
| 896 | int *colorOffset); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 897 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 898 | /** |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 899 | * Helper function to compute the size of each vertex and the offsets of |
| 900 | * texture coordinates and color. Determines tex coord offsets by stage |
| 901 | * rather than by index. (Each stage can be mapped to any t.c. index |
| 902 | * by StageTexCoordVertexLayoutBit.) If a stage uses positions for |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 903 | * tex coords then that stage's offset will be 0 (positions are always at 0). |
| 904 | * |
| 905 | * @param vertexLayout the layout to query |
| 906 | * @param texCoordOffsetsByStage after return it is the offset of each |
| 907 | * tex coord index in the vertex or -1 if |
| 908 | * index isn't used. |
| 909 | * @return size of a single vertex |
| 910 | */ |
| 911 | static int VertexSizeAndOffsetsByStage(GrVertexLayout vertexLayout, |
| 912 | int texCoordOffsetsByStage[kNumStages], |
| 913 | int *colorOffset); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 914 | |
| 915 | /** |
| 916 | * Accessing positions, texture coords, or colors, of a vertex within an |
| 917 | * array is a hassle involving casts and simple math. These helpers exist |
| 918 | * to keep GrDrawTarget clients' code a bit nicer looking. |
| 919 | */ |
| 920 | |
| 921 | /** |
| 922 | * Gets a pointer to a GrPoint of a vertex's position or texture |
| 923 | * coordinate. |
| 924 | * @param vertices the vetex array |
| 925 | * @param vertexIndex the index of the vertex in the array |
| 926 | * @param vertexSize the size of each vertex in the array |
| 927 | * @param offset the offset in bytes of the vertex component. |
| 928 | * Defaults to zero (corresponding to vertex position) |
| 929 | * @return pointer to the vertex component as a GrPoint |
| 930 | */ |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 931 | static GrPoint* GetVertexPoint(void* vertices, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 932 | int vertexIndex, |
| 933 | int vertexSize, |
| 934 | int offset = 0) { |
| 935 | intptr_t start = GrTCast<intptr_t>(vertices); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 936 | return GrTCast<GrPoint*>(start + offset + |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 937 | vertexIndex * vertexSize); |
| 938 | } |
| 939 | static const GrPoint* GetVertexPoint(const void* vertices, |
| 940 | int vertexIndex, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 941 | int vertexSize, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 942 | int offset = 0) { |
| 943 | intptr_t start = GrTCast<intptr_t>(vertices); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 944 | return GrTCast<const GrPoint*>(start + offset + |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 945 | vertexIndex * vertexSize); |
| 946 | } |
| 947 | |
| 948 | /** |
| 949 | * Gets a pointer to a GrColor inside a vertex within a vertex array. |
| 950 | * @param vertices the vetex array |
| 951 | * @param vertexIndex the index of the vertex in the array |
| 952 | * @param vertexSize the size of each vertex in the array |
| 953 | * @param offset the offset in bytes of the vertex color |
| 954 | * @return pointer to the vertex component as a GrColor |
| 955 | */ |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 956 | static GrColor* GetVertexColor(void* vertices, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 957 | int vertexIndex, |
| 958 | int vertexSize, |
| 959 | int offset) { |
| 960 | intptr_t start = GrTCast<intptr_t>(vertices); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 961 | return GrTCast<GrColor*>(start + offset + |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 962 | vertexIndex * vertexSize); |
| 963 | } |
| 964 | static const GrColor* GetVertexColor(const void* vertices, |
| 965 | int vertexIndex, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 966 | int vertexSize, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 967 | int offset) { |
| 968 | const intptr_t start = GrTCast<intptr_t>(vertices); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 969 | return GrTCast<const GrColor*>(start + offset + |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 970 | vertexIndex * vertexSize); |
| 971 | } |
| 972 | |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame^] | 973 | static void VertexLayoutUnitTest(); |
| 974 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 975 | protected: |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 976 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 977 | // Helpers for GrDrawTarget subclasses that won't have private access to |
| 978 | // SavedDrawState but need to peek at the state values. |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 979 | static DrState& accessSavedDrawState(SavedDrawState& sds) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 980 | { return sds.fState; } |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 981 | static const DrState& accessSavedDrawState(const SavedDrawState& sds) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 982 | { return sds.fState; } |
| 983 | |
| 984 | // implemented by subclass |
| 985 | virtual bool acquireGeometryHelper(GrVertexLayout vertexLayout, |
| 986 | void** vertices, |
| 987 | void** indices) = 0; |
| 988 | |
| 989 | virtual void releaseGeometryHelper() = 0; |
| 990 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 991 | // subclass overrides to be notified when clip is set. |
| 992 | virtual void clipWillBeSet(const GrClip& clip) = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 993 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 994 | virtual void setVertexSourceToArrayHelper(const void* vertexArray, |
| 995 | int vertexCount) = 0; |
| 996 | |
| 997 | virtual void setIndexSourceToArrayHelper(const void* indexArray, |
| 998 | int indexCount) = 0; |
| 999 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1000 | // Helpers for drawRect, protected so subclasses that override drawRect |
| 1001 | // can use them. |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 1002 | static GrVertexLayout GetRectVertexLayout(StageBitfield stageEnableBitfield, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1003 | const GrRect* srcRects[]); |
| 1004 | |
| 1005 | static void SetRectVertices(const GrRect& rect, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1006 | const GrMatrix* matrix, |
| 1007 | const GrRect* srcRects[], |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1008 | const GrMatrix* srcMatrices[], |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1009 | GrVertexLayout layout, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1010 | void* vertices); |
| 1011 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1012 | enum GeometrySrcType { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 1013 | kReserved_GeometrySrcType, // src was set using reserveAndLockGeometry |
| 1014 | kArray_GeometrySrcType, // src was set using set*SourceToArray |
| 1015 | kBuffer_GeometrySrcType // src was set using set*SourceToBuffer |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1016 | }; |
| 1017 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1018 | struct ReservedGeometry { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1019 | bool fLocked; |
| 1020 | uint32_t fVertexCount; |
| 1021 | uint32_t fIndexCount; |
| 1022 | } fReservedGeometry; |
| 1023 | |
| 1024 | struct GeometrySrc { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 1025 | GeometrySrcType fVertexSrc; |
| 1026 | const GrVertexBuffer* fVertexBuffer; // valid if src type is buffer |
| 1027 | GeometrySrcType fIndexSrc; |
| 1028 | const GrIndexBuffer* fIndexBuffer; // valid if src type is buffer |
| 1029 | GrVertexLayout fVertexLayout; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1030 | } fGeometrySrc; |
| 1031 | |
| 1032 | GrClip fClip; |
| 1033 | |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 1034 | DrState fCurrDrawState; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1035 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 1036 | // Not meant for external use. Only setVertexSourceToBuffer and |
| 1037 | // setIndexSourceToBuffer will work since GrDrawTarget subclasses don't |
| 1038 | // support nested reserveAndLockGeometry (and cpu arrays internally use the |
| 1039 | // same path). |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1040 | class AutoGeometrySrcRestore { |
| 1041 | public: |
| 1042 | AutoGeometrySrcRestore(GrDrawTarget* target) { |
| 1043 | fTarget = target; |
| 1044 | fGeometrySrc = fTarget->fGeometrySrc; |
| 1045 | } |
| 1046 | ~AutoGeometrySrcRestore() { |
| 1047 | fTarget->fGeometrySrc = fGeometrySrc; |
| 1048 | } |
| 1049 | private: |
| 1050 | GrDrawTarget *fTarget; |
| 1051 | GeometrySrc fGeometrySrc; |
| 1052 | |
| 1053 | AutoGeometrySrcRestore(); |
| 1054 | AutoGeometrySrcRestore(const AutoGeometrySrcRestore&); |
| 1055 | AutoGeometrySrcRestore& operator =(AutoGeometrySrcRestore&); |
| 1056 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1057 | }; |
| 1058 | |
| 1059 | #endif |