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" |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 22 | #include "GrGLIRect.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 23 | #include "GrGLTexture.h" |
| 24 | |
| 25 | #include "GrGLVertexBuffer.h" |
| 26 | #include "GrGLIndexBuffer.h" |
| 27 | |
| 28 | class GrGpuGL : public GrGpu { |
| 29 | public: |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 30 | virtual ~GrGpuGL(); |
| 31 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 32 | protected: |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 33 | GrGpuGL(); |
| 34 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 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 | |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 43 | struct AAState { |
| 44 | bool fMSAAEnabled; |
| 45 | bool fSmoothLineEnabled; |
| 46 | } fHWAAState; |
| 47 | |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 48 | DrState fHWDrawState; |
| 49 | bool fHWStencilClip; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 50 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 51 | // As flush of GL state proceeds it updates fHDrawState |
| 52 | // to reflect the new state. Later parts of the state flush |
| 53 | // may perform cascaded changes but cannot refer to fHWDrawState. |
| 54 | // These code paths can refer to the dirty flags. Subclass should |
| 55 | // call resetDirtyFlags after its flush is complete |
| 56 | struct { |
| 57 | bool fRenderTargetChanged : 1; |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 58 | int fTextureChangedMask; |
| 59 | } fDirtyFlags; |
| 60 | GR_STATIC_ASSERT(8 * sizeof(int) >= kNumStages); |
| 61 | |
| 62 | // clears the dirty flags |
| 63 | void resetDirtyFlags(); |
| 64 | |
| 65 | // last scissor / viewport scissor state seen by the GL. |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 66 | struct { |
| 67 | bool fScissorEnabled; |
| 68 | GrGLIRect fScissorRect; |
| 69 | GrGLIRect fViewportRect; |
| 70 | } fHWBounds; |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 71 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 72 | // GrGpu overrides |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 73 | // overrides from GrGpu |
| 74 | virtual void resetContext(); |
| 75 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 76 | virtual GrTexture* onCreateTexture(const GrTextureDesc& desc, |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 77 | const void* srcData, |
| 78 | size_t rowBytes); |
| 79 | virtual GrVertexBuffer* onCreateVertexBuffer(uint32_t size, |
| 80 | bool dynamic); |
| 81 | virtual GrIndexBuffer* onCreateIndexBuffer(uint32_t size, |
| 82 | bool dynamic); |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 83 | virtual GrResource* onCreatePlatformSurface(const GrPlatformSurfaceDesc& desc); |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 84 | virtual GrRenderTarget* onCreateRenderTargetFrom3DApiState(); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 85 | |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 86 | virtual void onClear(const GrIRect* rect, GrColor color); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 87 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 88 | virtual void onForceRenderTargetFlush(); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 89 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 90 | virtual bool onReadPixels(GrRenderTarget* target, |
| 91 | int left, int top, int width, int height, |
| 92 | GrPixelConfig, void* buffer); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 93 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 94 | virtual void onDrawIndexed(GrPrimitiveType type, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 95 | uint32_t startVertex, |
| 96 | uint32_t startIndex, |
| 97 | uint32_t vertexCount, |
| 98 | uint32_t indexCount); |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 99 | virtual void onDrawNonIndexed(GrPrimitiveType type, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 100 | uint32_t vertexCount, |
| 101 | uint32_t numVertices); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 102 | virtual void flushScissor(const GrIRect* rect); |
bsalomon@google.com | 398109c | 2011-04-14 18:40:27 +0000 | [diff] [blame] | 103 | void clearStencil(uint32_t value, uint32_t mask); |
| 104 | virtual void clearStencilClip(const GrIRect& rect); |
senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 105 | virtual int getMaxEdges() const; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 106 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 107 | // binds texture unit in GL |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 108 | void setTextureUnit(int unitIdx); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 109 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 110 | // binds appropriate vertex and index buffers, also returns any extra |
| 111 | // extra verts or indices to offset by. |
| 112 | void setBuffers(bool indexed, |
| 113 | int* extraVertexOffset, |
| 114 | int* extraIndexOffset); |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 115 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 116 | // flushes state that is common to fixed and programmable GL |
| 117 | // dither |
| 118 | // line smoothing |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 119 | // texture binding |
| 120 | // sampler state (filtering, tiling) |
| 121 | // FBO binding |
| 122 | // line width |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 123 | bool flushGLStateCommon(GrPrimitiveType type); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 124 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 125 | // subclass should call this to flush the blend state |
| 126 | void flushBlend(GrPrimitiveType type, |
| 127 | GrBlendCoeff srcCoeff, |
| 128 | GrBlendCoeff dstCoeff); |
| 129 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 130 | // adjusts texture matrix to account for orientation, size, and npotness |
| 131 | static void AdjustTextureMatrix(const GrGLTexture* texture, |
| 132 | GrSamplerState::SampleMode mode, |
| 133 | GrMatrix* matrix); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 134 | |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 135 | // subclass may try to take advantage of identity tex matrices. |
| 136 | // This helper determines if matrix will be identity after all |
| 137 | // adjustments are applied. |
| 138 | static bool TextureMatrixIsIdentity(const GrGLTexture* texture, |
| 139 | const GrSamplerState& sampler); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 140 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 141 | static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff); |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 142 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 143 | private: |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 144 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 145 | // notify callbacks to update state tracking when related |
| 146 | // objects are bound to GL or deleted outside of the class |
| 147 | void notifyVertexBufferBind(const GrGLVertexBuffer* buffer); |
| 148 | void notifyVertexBufferDelete(const GrGLVertexBuffer* buffer); |
| 149 | void notifyIndexBufferBind(const GrGLIndexBuffer* buffer); |
| 150 | void notifyIndexBufferDelete(const GrGLIndexBuffer* buffer); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 151 | void notifyTextureDelete(GrGLTexture* texture); |
| 152 | void notifyRenderTargetDelete(GrRenderTarget* renderTarget); |
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 | void setSpareTextureUnit(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 155 | |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 156 | bool useSmoothLines(); |
| 157 | |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 158 | // bound is region that may be modified and therefore has to be resolved. |
| 159 | // NULL means whole target. Can be an empty rect. |
| 160 | void flushRenderTarget(const GrIRect* bound); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 161 | void flushStencil(); |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 162 | void flushAAState(GrPrimitiveType type); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 163 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 164 | void resolveRenderTarget(GrGLRenderTarget* texture); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 165 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 166 | bool canBeTexture(GrPixelConfig config, |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 167 | GrGLenum* internalFormat, |
| 168 | GrGLenum* format, |
| 169 | GrGLenum* type); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 170 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 171 | bool fboInternalFormat(GrPixelConfig config, GrGLenum* format); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 172 | |
| 173 | friend class GrGLVertexBuffer; |
| 174 | friend class GrGLIndexBuffer; |
| 175 | friend class GrGLTexture; |
| 176 | friend class GrGLRenderTarget; |
| 177 | |
| 178 | bool fHWBlendDisabled; |
| 179 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 180 | GrGLuint fAASamples[4]; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 181 | enum { |
bsalomon@google.com | a9ecdad | 2011-03-23 13:50:34 +0000 | [diff] [blame] | 182 | kNone_MSFBO = 0, //<! no support for MSAA FBOs |
| 183 | kDesktopARB_MSFBO,//<! GL3.0-style MSAA FBO (GL_ARB_framebuffer_object) |
| 184 | kDesktopEXT_MSFBO,//<! earlier GL_EXT_framebuffer* extensions |
| 185 | kAppleES_MSFBO, //<! GL_APPLE_framebuffer_multisample ES extension |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 186 | } fMSFBOType; |
| 187 | |
| 188 | // Do we have stencil wrap ops. |
| 189 | bool fHasStencilWrap; |
| 190 | |
senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 191 | // The maximum number of fragment uniform vectors (GLES has min. 16). |
| 192 | int fMaxFragmentUniformVectors; |
| 193 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 194 | // ES requires an extension to support RGBA8 in RenderBufferStorage |
| 195 | bool fRGBA8Renderbuffer; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 196 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 197 | int fActiveTextureUnitIdx; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 198 | |
bsalomon@google.com | fe67652 | 2011-06-17 18:12:21 +0000 | [diff] [blame^] | 199 | // we record what stencil format worked last time to hopefully exit early |
| 200 | // from our loop that tries stencil formats and calls check fb status. |
| 201 | int fLastSuccessfulStencilFmtIdx; |
| 202 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 203 | typedef GrGpu INHERITED; |
| 204 | }; |
| 205 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 206 | #endif |
bsalomon@google.com | fe67652 | 2011-06-17 18:12:21 +0000 | [diff] [blame^] | 207 | |