blob: 611485df1dcc126bb99b9596e70befa15f07b71d [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
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
28class GrGpuGL : public GrGpu {
29public:
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
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +000045 virtual GrRenderTarget* createRenderTargetFrom3DApiState();
reed@google.comac10a2d2010-12-22 21:39:39 +000046
47 virtual void eraseColor(GrColor color);
48
49 virtual void forceRenderTargetFlush();
50
51 virtual bool readPixels(int left, int top, int width, int height,
52 GrTexture::PixelConfig, void* buffer);
53
54 /**
55 * Gets the struct containing the GL extensions for the context
56 * underlying the GrGpuGL
57 *
58 * @param struct containing extension function pointers
59 */
60 const GrGLExts& extensions() { return fExts; }
61
62protected:
63 struct {
64 const void*
65 fPositionPtr;
66 GrVertexLayout fVertexLayout;
67 const GrVertexBuffer* fVertexBuffer;
68 const GrIndexBuffer* fIndexBuffer;
69 } fHWGeometryState;
70
reed@google.com8195f672011-01-12 18:14:28 +000071 DrState fHWDrawState;
72 bool fHWStencilClip;
reed@google.comac10a2d2010-12-22 21:39:39 +000073
74 virtual void drawIndexedHelper(PrimitiveType type,
75 uint32_t startVertex,
76 uint32_t startIndex,
77 uint32_t vertexCount,
78 uint32_t indexCount);
79
80 virtual void drawNonIndexedHelper(PrimitiveType type,
81 uint32_t vertexCount,
82 uint32_t numVertices);
83
84 virtual void flushScissor(const GrIRect* rect);
85
86 void eraseStencil(uint32_t value, uint32_t mask);
87 virtual void eraseStencilClip();
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000088
89 void setTextureUnit(int unitIdx);
reed@google.comac10a2d2010-12-22 21:39:39 +000090
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
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +000099 bool flushGLStateCommon(PrimitiveType type);
reed@google.comac10a2d2010-12-22 21:39:39 +0000100
reed@google.comac10a2d2010-12-22 21:39:39 +0000101 // set when this class changes the rendertarget.
102 // Subclass should notice at flush time, take appropriate action,
103 // and set false.
104 bool fRenderTargetChanged;
105
106 // set by eraseColor or eraseStencil. Picked up in in flushStencil.
107 bool fWriteMaskChanged;
108
109 // last scissor / viewport scissor state seen by the GL.
110 BoundsState fHWBounds;
111
reed@google.comac10a2d2010-12-22 21:39:39 +0000112 GrGLExts fExts;
113
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000114private:
reed@google.comac10a2d2010-12-22 21:39:39 +0000115 void resetContextHelper();
116
117 // notify callbacks to update state tracking when related
118 // objects are bound to GL or deleted outside of the class
119 void notifyVertexBufferBind(const GrGLVertexBuffer* buffer);
120 void notifyVertexBufferDelete(const GrGLVertexBuffer* buffer);
121 void notifyIndexBufferBind(const GrGLIndexBuffer* buffer);
122 void notifyIndexBufferDelete(const GrGLIndexBuffer* buffer);
reed@google.comac10a2d2010-12-22 21:39:39 +0000123 void notifyTextureDelete(GrGLTexture* texture);
124 void notifyRenderTargetDelete(GrRenderTarget* renderTarget);
125 void notifyTextureRemoveRenderTarget(GrGLTexture* texture);
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000126
127 void setSpareTextureUnit();
reed@google.comac10a2d2010-12-22 21:39:39 +0000128
129 void flushRenderTarget();
130 void flushStencil();
131 void resolveTextureRenderTarget(GrGLTexture* texture);
132
133 bool canBeTexture(GrTexture::PixelConfig config,
134 GLenum* internalFormat,
135 GLenum* format,
136 GLenum* type);
137 bool fboInternalFormat(GrTexture::PixelConfig config, GLenum* format);
138
139 friend class GrGLVertexBuffer;
140 friend class GrGLIndexBuffer;
141 friend class GrGLTexture;
142 friend class GrGLRenderTarget;
143
144 bool fHWBlendDisabled;
145
146 GLuint fAASamples[4];
147 enum {
148 kNone_MSFBO = 0,
149 kDesktop_MSFBO,
150 kApple_MSFBO,
151 kIMG_MSFBO
152 } fMSFBOType;
153
154 // Do we have stencil wrap ops.
155 bool fHasStencilWrap;
156
157 // ES requires an extension to support RGBA8 in RenderBufferStorage
158 bool fRGBA8Renderbuffer;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000159
160 int fActiveTextureUnitIdx;
161
reed@google.comac10a2d2010-12-22 21:39:39 +0000162 typedef GrGpu INHERITED;
163};
164
165bool has_gl_extension(const char* ext);
166void gl_version(int* major, int* minor);
167
168/**
169 * GrGL_RestoreResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write
170 * this wrapper, since GL_UNPACK_ROW_LENGTH is not available on all GL versions
171 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000172#if GR_SUPPORT_GLDESKTOP
reed@google.comac10a2d2010-12-22 21:39:39 +0000173 static inline void GrGL_RestoreResetRowLength() {
174 GR_GL(PixelStorei(GL_UNPACK_ROW_LENGTH, 0));
175 }
176#else
177 #define GrGL_RestoreResetRowLength()
178#endif
179
180#if SK_TextGLType != GL_FIXED
181 #define SK_GL_HAS_COLOR4UB
182#endif
183
reed@google.comac20fb92011-01-12 17:14:53 +0000184/*
185 * Some drivers want the var-int arg to be zero-initialized on input.
186 */
187#define GR_GL_INIT_ZERO 0
188#define GR_GL_GetIntegerv(e, p) \
189 do { \
190 *(p) = GR_GL_INIT_ZERO; \
191 GR_GL(GetIntegerv(e, p)); \
192 } while (0)
193
reed@google.comac10a2d2010-12-22 21:39:39 +0000194#endif
195
196