| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #ifndef GrGpuGL_DEFINED |
| 12 | #define GrGpuGL_DEFINED |
| 13 | |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 14 | #include "GrDrawState.h" |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 15 | #include "GrGpu.h" |
| bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame^] | 16 | #include "GrGLContextInfo.h" |
| bsalomon@google.com | 4043ae2 | 2011-08-02 14:19:11 +0000 | [diff] [blame] | 17 | #include "GrGLIndexBuffer.h" |
| bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 18 | #include "GrGLIRect.h" |
| 19 | #include "GrGLStencilBuffer.h" |
| 20 | #include "GrGLTexture.h" |
| 21 | #include "GrGLVertexBuffer.h" |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 22 | |
| 23 | class GrGpuGL : public GrGpu { |
| 24 | public: |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 25 | virtual ~GrGpuGL(); |
| 26 | |
| bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame^] | 27 | const GrGLInterface* glInterface() const { |
| 28 | return fGLContextInfo.interface(); |
| 29 | } |
| 30 | const GrGLBinding glBinding() const { return fGLContextInfo.binding(); } |
| 31 | const GrGLVersion glVersion() const { return fGLContextInfo.version(); } |
| 32 | const GrGLSLGeneration glslGeneration() const { |
| 33 | return fGLContextInfo.glslGeneration(); |
| 34 | } |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 35 | |
| bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 36 | // GrGpu overrides |
| bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 37 | virtual GrPixelConfig preferredReadPixelsConfig(GrPixelConfig config) |
| bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 38 | const SK_OVERRIDE; |
| bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 39 | virtual GrPixelConfig preferredWritePixelsConfig(GrPixelConfig config) |
| bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 40 | const SK_OVERRIDE; |
| bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 41 | virtual bool readPixelsWillPayForYFlip( |
| 42 | GrRenderTarget* renderTarget, |
| 43 | int left, int top, |
| 44 | int width, int height, |
| 45 | GrPixelConfig config, |
| bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 46 | size_t rowBytes) const SK_OVERRIDE; |
| 47 | virtual bool fullReadPixelsIsFasterThanPartial() const SK_OVERRIDE; |
| bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 48 | |
| bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 49 | protected: |
| bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame^] | 50 | GrGpuGL(const GrGLContextInfo& ctxInfo); |
| bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 51 | |
| bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 52 | struct GLCaps { |
| 53 | GLCaps() |
| 54 | // make defaults be the most restrictive |
| bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 55 | : fStencilFormats(8) // prealloc space for stencil formats |
| 56 | , fMSFBOType(kNone_MSFBO) |
| bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 57 | , fMaxFragmentUniformVectors(0) |
| bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 58 | , fRGBA8RenderbufferSupport(false) |
| 59 | , fBGRAFormatSupport(false) |
| 60 | , fBGRAIsInternalFormat(false) |
| 61 | , fTextureSwizzleSupport(false) |
| 62 | , fUnpackRowLengthSupport(false) |
| bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 63 | , fUnpackFlipYSupport(false) |
| bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 64 | , fPackRowLengthSupport(false) |
| bsalomon@google.com | 07dd2bf | 2011-12-09 19:40:36 +0000 | [diff] [blame] | 65 | , fPackFlipYSupport(false) |
| bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 66 | , fTextureUsageSupport(false) |
| 67 | , fTexStorageSupport(false) { |
| bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 68 | memset(&fVerifiedColorAttachmentConfigs, 0, |
| 69 | sizeof(fVerifiedColorAttachmentConfigs)); |
| bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 70 | } |
| bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 71 | |
| 72 | // Call to note that a color config has been verified as a valid |
| 73 | // color attachment. This may save future calls to |
| 74 | // CheckFramebufferStatus |
| 75 | void markConfigAsValidColorAttachment(GrPixelConfig config); |
| 76 | |
| 77 | // Call to check whether a config has been verified as a valid color |
| 78 | // attachment. |
| 79 | bool isConfigVerifiedColorAttachment(GrPixelConfig config) const; |
| 80 | |
| 81 | // Call to note that a color config / stencil format pair passed |
| 82 | // FBO status check. We may skip calling CheckFramebufferStatus for |
| 83 | // this combination in the future. |
| 84 | void markColorConfigAndStencilFormatAsVerified( |
| 85 | GrPixelConfig config, |
| 86 | const GrGLStencilBuffer::Format& format); |
| 87 | |
| 88 | // Call to check whether color config / stencil format pair has already |
| 89 | // passed FBO status check. |
| 90 | bool isColorConfigAndStencilFormatVerified( |
| 91 | GrPixelConfig config, |
| 92 | const GrGLStencilBuffer::Format& format) const; |
| 93 | |
| 94 | void print() const; |
| 95 | |
| 96 | struct StencilFormat { |
| 97 | GrGLStencilBuffer::Format fFormat; |
| 98 | uint32_t fVerifiedColorConfigs[(kGrPixelConfigCount + 31) / 32]; |
| 99 | }; |
| 100 | |
| 101 | SkTArray<StencilFormat, true> fStencilFormats; |
| 102 | |
| bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 103 | |
| bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 104 | enum { |
| 105 | /** |
| 106 | * no support for MSAA FBOs |
| 107 | */ |
| 108 | kNone_MSFBO = 0, |
| 109 | /** |
| 110 | * GL3.0-style MSAA FBO (GL_ARB_framebuffer_object) |
| 111 | */ |
| 112 | kDesktopARB_MSFBO, |
| 113 | /** |
| 114 | * earlier GL_EXT_framebuffer* extensions |
| 115 | */ |
| 116 | kDesktopEXT_MSFBO, |
| 117 | /** |
| 118 | * GL_APPLE_framebuffer_multisample ES extension |
| 119 | */ |
| 120 | kAppleES_MSFBO, |
| 121 | } fMSFBOType; |
| bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 122 | |
| bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 123 | // The maximum number of fragment uniform vectors (GLES has min. 16). |
| 124 | int fMaxFragmentUniformVectors; |
| bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 125 | |
| bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 126 | // ES requires an extension to support RGBA8 in RenderBufferStorage |
| bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 127 | bool fRGBA8RenderbufferSupport; |
| bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 128 | |
| bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 129 | // Is GL_BGRA supported |
| bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 130 | bool fBGRAFormatSupport; |
| bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 131 | |
| 132 | // Depending on the ES extensions present the BGRA external format may |
| 133 | // correspond either a BGRA or RGBA internalFormat. On desktop GL it is |
| 134 | // RGBA |
| bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 135 | bool fBGRAIsInternalFormat; |
| bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 136 | |
| bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 137 | // GL_ARB_texture_swizzle support |
| bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 138 | bool fTextureSwizzleSupport; |
| bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 139 | |
| bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 140 | // Is there support for GL_UNPACK_ROW_LENGTH |
| 141 | bool fUnpackRowLengthSupport; |
| 142 | |
| bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 143 | // Is there support for GL_UNPACK_FLIP_Y |
| 144 | bool fUnpackFlipYSupport; |
| 145 | |
| bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 146 | // Is there support for GL_PACK_ROW_LENGTH |
| 147 | bool fPackRowLengthSupport; |
| bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 148 | |
| 149 | // Is there support for GL_PACK_REVERSE_ROW_ORDER |
| 150 | bool fPackFlipYSupport; |
| 151 | |
| bsalomon@google.com | 07dd2bf | 2011-12-09 19:40:36 +0000 | [diff] [blame] | 152 | // Is there support for texture parameter GL_TEXTURE_USAGE |
| 153 | bool fTextureUsageSupport; |
| 154 | |
| bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 155 | // Is there support for glTexStorage |
| 156 | bool fTexStorageSupport; |
| 157 | |
| bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 158 | private: |
| 159 | uint32_t fVerifiedColorAttachmentConfigs[(kGrPixelConfigCount + 31) / 32]; |
| bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 160 | } fGLCaps; |
| bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 161 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 162 | struct { |
| bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 163 | size_t fVertexOffset; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 164 | GrVertexLayout fVertexLayout; |
| 165 | const GrVertexBuffer* fVertexBuffer; |
| 166 | const GrIndexBuffer* fIndexBuffer; |
| bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 167 | bool fArrayPtrsDirty; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 168 | } fHWGeometryState; |
| 169 | |
| bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 170 | struct AAState { |
| 171 | bool fMSAAEnabled; |
| 172 | bool fSmoothLineEnabled; |
| 173 | } fHWAAState; |
| 174 | |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 175 | GrDrawState fHWDrawState; |
| 176 | bool fHWStencilClip; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 177 | |
| bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 178 | // As flush of GL state proceeds it updates fHDrawState |
| 179 | // to reflect the new state. Later parts of the state flush |
| 180 | // may perform cascaded changes but cannot refer to fHWDrawState. |
| 181 | // These code paths can refer to the dirty flags. Subclass should |
| 182 | // call resetDirtyFlags after its flush is complete |
| 183 | struct { |
| 184 | bool fRenderTargetChanged : 1; |
| bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 185 | int fTextureChangedMask; |
| 186 | } fDirtyFlags; |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 187 | GR_STATIC_ASSERT(8 * sizeof(int) >= GrDrawState::kNumStages); |
| bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 188 | |
| 189 | // clears the dirty flags |
| 190 | void resetDirtyFlags(); |
| 191 | |
| 192 | // last scissor / viewport scissor state seen by the GL. |
| bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 193 | struct { |
| 194 | bool fScissorEnabled; |
| 195 | GrGLIRect fScissorRect; |
| 196 | GrGLIRect fViewportRect; |
| 197 | } fHWBounds; |
| bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 198 | |
| bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 199 | const GLCaps& glCaps() const { return fGLCaps; } |
| 200 | |
| bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 201 | // GrGpu overrides |
| bsalomon@google.com | 1bf1c21 | 2011-11-05 12:18:58 +0000 | [diff] [blame] | 202 | virtual void onResetContext() SK_OVERRIDE; |
| bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 203 | |
| bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 204 | virtual GrTexture* onCreateTexture(const GrTextureDesc& desc, |
| bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 205 | const void* srcData, |
| 206 | size_t rowBytes); |
| 207 | virtual GrVertexBuffer* onCreateVertexBuffer(uint32_t size, |
| 208 | bool dynamic); |
| 209 | virtual GrIndexBuffer* onCreateIndexBuffer(uint32_t size, |
| 210 | bool dynamic); |
| bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 211 | virtual GrTexture* onCreatePlatformTexture(const GrPlatformTextureDesc& desc) SK_OVERRIDE; |
| 212 | virtual GrRenderTarget* onCreatePlatformRenderTarget(const GrPlatformRenderTargetDesc& desc) SK_OVERRIDE; |
| bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 213 | virtual bool createStencilBufferForRenderTarget(GrRenderTarget* rt, |
| 214 | int width, int height); |
| 215 | virtual bool attachStencilBufferToRenderTarget(GrStencilBuffer* sb, |
| 216 | GrRenderTarget* rt); |
| bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 217 | |
| bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 218 | virtual void onClear(const GrIRect* rect, GrColor color); |
| bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 219 | |
| bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 220 | virtual void onForceRenderTargetFlush(); |
| bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 221 | |
| bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 222 | virtual bool onReadPixels(GrRenderTarget* target, |
| bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 223 | int left, int top, |
| 224 | int width, int height, |
| 225 | GrPixelConfig, |
| bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 226 | void* buffer, |
| 227 | size_t rowBytes, |
| 228 | bool invertY) SK_OVERRIDE; |
| bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 229 | |
| bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 230 | virtual void onWriteTexturePixels(GrTexture* texture, |
| 231 | int left, int top, int width, int height, |
| 232 | GrPixelConfig config, const void* buffer, |
| 233 | size_t rowBytes) SK_OVERRIDE; |
| 234 | |
| bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 235 | virtual void onResolveRenderTarget(GrRenderTarget* target) SK_OVERRIDE; |
| 236 | |
| 237 | |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 238 | virtual void onGpuDrawIndexed(GrPrimitiveType type, |
| 239 | uint32_t startVertex, |
| 240 | uint32_t startIndex, |
| 241 | uint32_t vertexCount, |
| 242 | uint32_t indexCount); |
| 243 | virtual void onGpuDrawNonIndexed(GrPrimitiveType type, |
| 244 | uint32_t vertexCount, |
| 245 | uint32_t numVertices); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 246 | virtual void flushScissor(const GrIRect* rect); |
| bsalomon@google.com | edc177d | 2011-08-05 15:46:40 +0000 | [diff] [blame] | 247 | virtual void clearStencil(); |
| bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 248 | virtual void clearStencilClip(const GrIRect& rect, bool insideClip); |
| senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 249 | virtual int getMaxEdges() const; |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 250 | |
| bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 251 | // binds texture unit in GL |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 252 | void setTextureUnit(int unitIdx); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 253 | |
| bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 254 | // binds appropriate vertex and index buffers, also returns any extra |
| 255 | // extra verts or indices to offset by. |
| 256 | void setBuffers(bool indexed, |
| 257 | int* extraVertexOffset, |
| 258 | int* extraIndexOffset); |
| bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 259 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 260 | // flushes state that is common to fixed and programmable GL |
| 261 | // dither |
| 262 | // line smoothing |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 263 | // texture binding |
| 264 | // sampler state (filtering, tiling) |
| 265 | // FBO binding |
| 266 | // line width |
| bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 267 | bool flushGLStateCommon(GrPrimitiveType type); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 268 | |
| bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 269 | // Subclasses should call this to flush the blend state. |
| 270 | // The params should be the final coeffecients to apply |
| 271 | // (after any blending optimizations or dual source blending considerations |
| 272 | // have been accounted for). |
| bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 273 | void flushBlend(GrPrimitiveType type, |
| 274 | GrBlendCoeff srcCoeff, |
| 275 | GrBlendCoeff dstCoeff); |
| 276 | |
| bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame^] | 277 | bool hasExtension(const char* ext) const { |
| 278 | return fGLContextInfo.hasExtension(ext); |
| 279 | } |
| bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 280 | |
| bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 281 | // adjusts texture matrix to account for orientation |
| bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 282 | static void AdjustTextureMatrix(const GrGLTexture* texture, |
| 283 | GrSamplerState::SampleMode mode, |
| 284 | GrMatrix* matrix); |
| bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 285 | |
| 286 | // subclass may try to take advantage of identity tex matrices. |
| 287 | // This helper determines if matrix will be identity after all |
| 288 | // adjustments are applied. |
| 289 | static bool TextureMatrixIsIdentity(const GrGLTexture* texture, |
| 290 | const GrSamplerState& sampler); |
| 291 | |
| bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 292 | static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff); |
| bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 293 | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 294 | private: |
| bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 295 | // Inits GrDrawTarget::Caps and GLCaps, sublcass may enable |
| 296 | // additional caps. |
| 297 | void initCaps(); |
| 298 | |
| 299 | void initFSAASupport(); |
| bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 300 | |
| bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 301 | // determines valid stencil formats |
| bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 302 | void initStencilFormats(); |
| bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 303 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 304 | // notify callbacks to update state tracking when related |
| 305 | // objects are bound to GL or deleted outside of the class |
| 306 | void notifyVertexBufferBind(const GrGLVertexBuffer* buffer); |
| 307 | void notifyVertexBufferDelete(const GrGLVertexBuffer* buffer); |
| 308 | void notifyIndexBufferBind(const GrGLIndexBuffer* buffer); |
| 309 | void notifyIndexBufferDelete(const GrGLIndexBuffer* buffer); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 310 | void notifyTextureDelete(GrGLTexture* texture); |
| 311 | void notifyRenderTargetDelete(GrRenderTarget* renderTarget); |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 312 | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 313 | void setSpareTextureUnit(); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 314 | |
| bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 315 | // bound is region that may be modified and therefore has to be resolved. |
| 316 | // NULL means whole target. Can be an empty rect. |
| 317 | void flushRenderTarget(const GrIRect* bound); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 318 | void flushStencil(); |
| bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 319 | void flushAAState(GrPrimitiveType type); |
| bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 320 | |
| bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 321 | bool configToGLFormats(GrPixelConfig config, |
| 322 | bool getSizedInternal, |
| 323 | GrGLenum* internalFormat, |
| 324 | GrGLenum* externalFormat, |
| 325 | GrGLenum* externalType); |
| bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 326 | // helper for onCreateTexture and writeTexturePixels |
| bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 327 | bool uploadTexData(const GrGLTexture::Desc& desc, |
| bsalomon@google.com | 1e0e607 | 2011-11-28 18:49:37 +0000 | [diff] [blame] | 328 | bool isNewTexture, |
| bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 329 | int left, int top, int width, int height, |
| 330 | GrPixelConfig dataConfig, |
| 331 | const void* data, |
| 332 | size_t rowBytes); |
| bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 333 | |
| bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 334 | bool createRenderTargetObjects(int width, int height, |
| 335 | GrGLuint texID, |
| 336 | GrGLRenderTarget::Desc* desc); |
| 337 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 338 | friend class GrGLVertexBuffer; |
| 339 | friend class GrGLIndexBuffer; |
| 340 | friend class GrGLTexture; |
| 341 | friend class GrGLRenderTarget; |
| 342 | |
| bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame^] | 343 | GrGLContextInfo fGLContextInfo; |
| bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 344 | |
| bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 345 | // we want to clear stencil buffers when they are created. We want to clear |
| 346 | // the entire buffer even if it is larger than the color attachment. We |
| 347 | // attach it to this fbo with no color attachment to do the initial clear. |
| 348 | GrGLuint fStencilClearFBO; |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 349 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 350 | bool fHWBlendDisabled; |
| 351 | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 352 | int fActiveTextureUnitIdx; |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 353 | |
| bsalomon@google.com | fe67652 | 2011-06-17 18:12:21 +0000 | [diff] [blame] | 354 | // we record what stencil format worked last time to hopefully exit early |
| 355 | // from our loop that tries stencil formats and calls check fb status. |
| 356 | int fLastSuccessfulStencilFmtIdx; |
| 357 | |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 358 | |
| bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 359 | bool fPrintedCaps; |
| 360 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 361 | typedef GrGpu INHERITED; |
| 362 | }; |
| 363 | |
| bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 364 | #endif |
| bsalomon@google.com | fe67652 | 2011-06-17 18:12:21 +0000 | [diff] [blame] | 365 | |