reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 2 | Copyright 2011 Google Inc. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 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 GrGpuGL_DEFINED |
| 19 | #define GrGpuGL_DEFINED |
| 20 | |
| 21 | #include "GrGpu.h" |
| 22 | #include "GrGLConfig.h" |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 23 | #include "GrGLIRect.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 24 | #include "GrGLTexture.h" |
| 25 | |
| 26 | #include "GrGLVertexBuffer.h" |
| 27 | #include "GrGLIndexBuffer.h" |
| 28 | |
| 29 | class GrGpuGL : public GrGpu { |
| 30 | public: |
| 31 | GrGpuGL(); |
| 32 | virtual ~GrGpuGL(); |
| 33 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 34 | protected: |
| 35 | struct { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 36 | size_t fVertexOffset; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 37 | GrVertexLayout fVertexLayout; |
| 38 | const GrVertexBuffer* fVertexBuffer; |
| 39 | const GrIndexBuffer* fIndexBuffer; |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 40 | bool fArrayPtrsDirty; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 41 | } fHWGeometryState; |
| 42 | |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 43 | DrState fHWDrawState; |
| 44 | bool fHWStencilClip; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 45 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 46 | // As flush of GL state proceeds it updates fHDrawState |
| 47 | // to reflect the new state. Later parts of the state flush |
| 48 | // may perform cascaded changes but cannot refer to fHWDrawState. |
| 49 | // These code paths can refer to the dirty flags. Subclass should |
| 50 | // call resetDirtyFlags after its flush is complete |
| 51 | struct { |
| 52 | bool fRenderTargetChanged : 1; |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 53 | int fTextureChangedMask; |
| 54 | } fDirtyFlags; |
| 55 | GR_STATIC_ASSERT(8 * sizeof(int) >= kNumStages); |
| 56 | |
| 57 | // clears the dirty flags |
| 58 | void resetDirtyFlags(); |
| 59 | |
| 60 | // last scissor / viewport scissor state seen by the GL. |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 61 | struct { |
| 62 | bool fScissorEnabled; |
| 63 | GrGLIRect fScissorRect; |
| 64 | GrGLIRect fViewportRect; |
| 65 | } fHWBounds; |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 66 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 67 | // GrGpu overrides |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 68 | // overrides from GrGpu |
| 69 | virtual void resetContext(); |
| 70 | |
| 71 | virtual GrTexture* createTextureHelper(const TextureDesc& desc, |
| 72 | const void* srcData, |
| 73 | size_t rowBytes); |
| 74 | virtual GrVertexBuffer* createVertexBufferHelper(uint32_t size, |
| 75 | bool dynamic); |
| 76 | virtual GrIndexBuffer* createIndexBufferHelper(uint32_t size, |
| 77 | bool dynamic); |
| 78 | |
| 79 | virtual GrRenderTarget* createPlatformRenderTargetHelper( |
| 80 | intptr_t platformRenderTarget, |
| 81 | int stencilBits, |
| 82 | int width, int height); |
| 83 | |
| 84 | virtual GrRenderTarget* createRenderTargetFrom3DApiStateHelper(); |
| 85 | |
| 86 | virtual void eraseColorHelper(GrColor color); |
| 87 | |
| 88 | virtual void forceRenderTargetFlushHelper(); |
| 89 | |
| 90 | virtual bool readPixelsHelper(int left, int top, int width, int height, |
| 91 | GrTexture::PixelConfig, void* buffer); |
| 92 | |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 93 | virtual void drawIndexedHelper(GrPrimitiveType type, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 94 | uint32_t startVertex, |
| 95 | uint32_t startIndex, |
| 96 | uint32_t vertexCount, |
| 97 | uint32_t indexCount); |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 98 | virtual void drawNonIndexedHelper(GrPrimitiveType type, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 99 | uint32_t vertexCount, |
| 100 | uint32_t numVertices); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 101 | virtual void flushScissor(const GrIRect* rect); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 102 | void eraseStencil(uint32_t value, uint32_t mask); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 103 | virtual void eraseStencilClip(const GrIRect& rect); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 104 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 105 | // binds texture unit in GL |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 106 | void setTextureUnit(int unitIdx); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 107 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 108 | // binds appropriate vertex and index buffers, also returns any extra |
| 109 | // extra verts or indices to offset by. |
| 110 | void setBuffers(bool indexed, |
| 111 | int* extraVertexOffset, |
| 112 | int* extraIndexOffset); |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 113 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 114 | // flushes state that is common to fixed and programmable GL |
| 115 | // dither |
| 116 | // line smoothing |
| 117 | // blend func |
| 118 | // texture binding |
| 119 | // sampler state (filtering, tiling) |
| 120 | // FBO binding |
| 121 | // line width |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 122 | bool flushGLStateCommon(GrPrimitiveType type); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 123 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 124 | // adjusts texture matrix to account for orientation, size, and npotness |
| 125 | static void AdjustTextureMatrix(const GrGLTexture* texture, |
| 126 | GrSamplerState::SampleMode mode, |
| 127 | GrMatrix* matrix); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 128 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 129 | // subclass may try to take advantage of identity tex matrices. |
| 130 | // This helper determines if matrix will be identity after all |
| 131 | // adjustments are applied. |
| 132 | static bool TextureMatrixIsIdentity(const GrGLTexture* texture, |
| 133 | const GrSamplerState& sampler); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 134 | |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame^] | 135 | static bool BlendCoefReferencesConstant(GrBlendCoeff coeff); |
| 136 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 137 | private: |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 138 | // notify callbacks to update state tracking when related |
| 139 | // objects are bound to GL or deleted outside of the class |
| 140 | void notifyVertexBufferBind(const GrGLVertexBuffer* buffer); |
| 141 | void notifyVertexBufferDelete(const GrGLVertexBuffer* buffer); |
| 142 | void notifyIndexBufferBind(const GrGLIndexBuffer* buffer); |
| 143 | void notifyIndexBufferDelete(const GrGLIndexBuffer* buffer); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 144 | void notifyTextureDelete(GrGLTexture* texture); |
| 145 | void notifyRenderTargetDelete(GrRenderTarget* renderTarget); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 146 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 147 | void setSpareTextureUnit(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 148 | |
| 149 | void flushRenderTarget(); |
| 150 | void flushStencil(); |
| 151 | void resolveTextureRenderTarget(GrGLTexture* texture); |
| 152 | |
| 153 | bool canBeTexture(GrTexture::PixelConfig config, |
| 154 | GLenum* internalFormat, |
| 155 | GLenum* format, |
| 156 | GLenum* type); |
| 157 | bool fboInternalFormat(GrTexture::PixelConfig config, GLenum* format); |
| 158 | |
| 159 | friend class GrGLVertexBuffer; |
| 160 | friend class GrGLIndexBuffer; |
| 161 | friend class GrGLTexture; |
| 162 | friend class GrGLRenderTarget; |
| 163 | |
| 164 | bool fHWBlendDisabled; |
| 165 | |
| 166 | GLuint fAASamples[4]; |
| 167 | enum { |
| 168 | kNone_MSFBO = 0, |
| 169 | kDesktop_MSFBO, |
| 170 | kApple_MSFBO, |
| 171 | kIMG_MSFBO |
| 172 | } fMSFBOType; |
| 173 | |
| 174 | // Do we have stencil wrap ops. |
| 175 | bool fHasStencilWrap; |
| 176 | |
| 177 | // ES requires an extension to support RGBA8 in RenderBufferStorage |
| 178 | bool fRGBA8Renderbuffer; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 179 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 180 | int fActiveTextureUnitIdx; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 181 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 182 | typedef GrGpu INHERITED; |
| 183 | }; |
| 184 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 185 | #endif |