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