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 GrGpuGL_DEFINED |
| 19 | #define GrGpuGL_DEFINED |
| 20 | |
| 21 | #include "GrGpu.h" |
| 22 | #include "GrGLConfig.h" |
| 23 | #include "GrGLTexture.h" |
| 24 | |
| 25 | #include "GrGLVertexBuffer.h" |
| 26 | #include "GrGLIndexBuffer.h" |
| 27 | |
| 28 | class GrGpuGL : public GrGpu { |
| 29 | public: |
| 30 | GrGpuGL(); |
| 31 | virtual ~GrGpuGL(); |
| 32 | |
| 33 | // overrides from GrGpu |
| 34 | virtual void resetContext(); |
| 35 | |
| 36 | virtual GrTexture* createTexture(const TextureDesc& desc, |
| 37 | const void* srcData, size_t rowBytes); |
| 38 | virtual GrVertexBuffer* createVertexBuffer(uint32_t size, bool dynamic); |
| 39 | virtual GrIndexBuffer* createIndexBuffer(uint32_t size, bool dynamic); |
| 40 | |
| 41 | virtual GrRenderTarget* createPlatformRenderTarget( |
| 42 | intptr_t platformRenderTarget, |
| 43 | int width, int height); |
| 44 | |
| 45 | virtual GrRenderTarget* defaultRenderTarget(); |
| 46 | |
| 47 | virtual void setDefaultRenderTargetSize(uint32_t width, uint32_t height); |
| 48 | |
| 49 | virtual void eraseColor(GrColor color); |
| 50 | |
| 51 | virtual void forceRenderTargetFlush(); |
| 52 | |
| 53 | virtual bool readPixels(int left, int top, int width, int height, |
| 54 | GrTexture::PixelConfig, void* buffer); |
| 55 | |
| 56 | /** |
| 57 | * Gets the struct containing the GL extensions for the context |
| 58 | * underlying the GrGpuGL |
| 59 | * |
| 60 | * @param struct containing extension function pointers |
| 61 | */ |
| 62 | const GrGLExts& extensions() { return fExts; } |
| 63 | |
| 64 | protected: |
| 65 | struct { |
| 66 | const void* |
| 67 | fPositionPtr; |
| 68 | GrVertexLayout fVertexLayout; |
| 69 | const GrVertexBuffer* fVertexBuffer; |
| 70 | const GrIndexBuffer* fIndexBuffer; |
| 71 | } fHWGeometryState; |
| 72 | |
| 73 | DrawState fHWDrawState; |
| 74 | bool fHWStencilClip; |
| 75 | |
| 76 | virtual void drawIndexedHelper(PrimitiveType type, |
| 77 | uint32_t startVertex, |
| 78 | uint32_t startIndex, |
| 79 | uint32_t vertexCount, |
| 80 | uint32_t indexCount); |
| 81 | |
| 82 | virtual void drawNonIndexedHelper(PrimitiveType type, |
| 83 | uint32_t vertexCount, |
| 84 | uint32_t numVertices); |
| 85 | |
| 86 | virtual void flushScissor(const GrIRect* rect); |
| 87 | |
| 88 | void eraseStencil(uint32_t value, uint32_t mask); |
| 89 | virtual void eraseStencilClip(); |
| 90 | |
| 91 | // flushes state that is common to fixed and programmable GL |
| 92 | // dither |
| 93 | // line smoothing |
| 94 | // blend func |
| 95 | // texture binding |
| 96 | // sampler state (filtering, tiling) |
| 97 | // FBO binding |
| 98 | // line width |
| 99 | void flushGLStateCommon(PrimitiveType type); |
| 100 | |
| 101 | // pushes the filtering and tiling modes to GL |
| 102 | void setSamplerStateImm(const GrSamplerState& samplerState); |
| 103 | |
| 104 | // set when this class changes the rendertarget. |
| 105 | // Subclass should notice at flush time, take appropriate action, |
| 106 | // and set false. |
| 107 | bool fRenderTargetChanged; |
| 108 | |
| 109 | // set by eraseColor or eraseStencil. Picked up in in flushStencil. |
| 110 | bool fWriteMaskChanged; |
| 111 | |
| 112 | // last scissor / viewport scissor state seen by the GL. |
| 113 | BoundsState fHWBounds; |
| 114 | |
| 115 | private: |
| 116 | GrGLExts fExts; |
| 117 | |
| 118 | GrGLRenderTarget* fDefaultRenderTarget; |
| 119 | |
| 120 | void resetContextHelper(); |
| 121 | |
| 122 | // notify callbacks to update state tracking when related |
| 123 | // objects are bound to GL or deleted outside of the class |
| 124 | void notifyVertexBufferBind(const GrGLVertexBuffer* buffer); |
| 125 | void notifyVertexBufferDelete(const GrGLVertexBuffer* buffer); |
| 126 | void notifyIndexBufferBind(const GrGLIndexBuffer* buffer); |
| 127 | void notifyIndexBufferDelete(const GrGLIndexBuffer* buffer); |
| 128 | void notifyTextureBind(GrGLTexture* texture); |
| 129 | void notifyTextureDelete(GrGLTexture* texture); |
| 130 | void notifyRenderTargetDelete(GrRenderTarget* renderTarget); |
| 131 | void notifyTextureRemoveRenderTarget(GrGLTexture* texture); |
| 132 | |
| 133 | void flushRenderTarget(); |
| 134 | void flushStencil(); |
| 135 | void resolveTextureRenderTarget(GrGLTexture* texture); |
| 136 | |
| 137 | bool canBeTexture(GrTexture::PixelConfig config, |
| 138 | GLenum* internalFormat, |
| 139 | GLenum* format, |
| 140 | GLenum* type); |
| 141 | bool fboInternalFormat(GrTexture::PixelConfig config, GLenum* format); |
| 142 | |
| 143 | friend class GrGLVertexBuffer; |
| 144 | friend class GrGLIndexBuffer; |
| 145 | friend class GrGLTexture; |
| 146 | friend class GrGLRenderTarget; |
| 147 | |
| 148 | bool fHWBlendDisabled; |
| 149 | |
| 150 | GLuint fAASamples[4]; |
| 151 | enum { |
| 152 | kNone_MSFBO = 0, |
| 153 | kDesktop_MSFBO, |
| 154 | kApple_MSFBO, |
| 155 | kIMG_MSFBO |
| 156 | } fMSFBOType; |
| 157 | |
| 158 | // Do we have stencil wrap ops. |
| 159 | bool fHasStencilWrap; |
| 160 | |
| 161 | // ES requires an extension to support RGBA8 in RenderBufferStorage |
| 162 | bool fRGBA8Renderbuffer; |
| 163 | |
| 164 | typedef GrGpu INHERITED; |
| 165 | }; |
| 166 | |
| 167 | bool has_gl_extension(const char* ext); |
| 168 | void gl_version(int* major, int* minor); |
| 169 | |
| 170 | /** |
| 171 | * GrGL_RestoreResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write |
| 172 | * this wrapper, since GL_UNPACK_ROW_LENGTH is not available on all GL versions |
| 173 | */ |
| 174 | #if GR_GL_DESKTOP |
| 175 | static inline void GrGL_RestoreResetRowLength() { |
| 176 | GR_GL(PixelStorei(GL_UNPACK_ROW_LENGTH, 0)); |
| 177 | } |
| 178 | #else |
| 179 | #define GrGL_RestoreResetRowLength() |
| 180 | #endif |
| 181 | |
| 182 | #if SK_TextGLType != GL_FIXED |
| 183 | #define SK_GL_HAS_COLOR4UB |
| 184 | #endif |
| 185 | |
| 186 | #endif |
| 187 | |
| 188 | |