blob: 728a5d343b49dbe2a9a0e1e8ee32cddbfb68edb4 [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
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
64protected:
65 struct {
66 const void*
67 fPositionPtr;
68 GrVertexLayout fVertexLayout;
69 const GrVertexBuffer* fVertexBuffer;
70 const GrIndexBuffer* fIndexBuffer;
71 } fHWGeometryState;
72
reed@google.com8195f672011-01-12 18:14:28 +000073 DrState fHWDrawState;
74 bool fHWStencilClip;
reed@google.comac10a2d2010-12-22 21:39:39 +000075
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
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
112private:
113 GrGLExts fExts;
114
115 GrGLRenderTarget* fDefaultRenderTarget;
116
117 void resetContextHelper();
118
119 // notify callbacks to update state tracking when related
120 // objects are bound to GL or deleted outside of the class
121 void notifyVertexBufferBind(const GrGLVertexBuffer* buffer);
122 void notifyVertexBufferDelete(const GrGLVertexBuffer* buffer);
123 void notifyIndexBufferBind(const GrGLIndexBuffer* buffer);
124 void notifyIndexBufferDelete(const GrGLIndexBuffer* buffer);
125 void notifyTextureBind(GrGLTexture* texture);
126 void notifyTextureDelete(GrGLTexture* texture);
127 void notifyRenderTargetDelete(GrRenderTarget* renderTarget);
128 void notifyTextureRemoveRenderTarget(GrGLTexture* texture);
129
130 void flushRenderTarget();
131 void flushStencil();
132 void resolveTextureRenderTarget(GrGLTexture* texture);
133
134 bool canBeTexture(GrTexture::PixelConfig config,
135 GLenum* internalFormat,
136 GLenum* format,
137 GLenum* type);
138 bool fboInternalFormat(GrTexture::PixelConfig config, GLenum* format);
139
140 friend class GrGLVertexBuffer;
141 friend class GrGLIndexBuffer;
142 friend class GrGLTexture;
143 friend class GrGLRenderTarget;
144
145 bool fHWBlendDisabled;
146
147 GLuint fAASamples[4];
148 enum {
149 kNone_MSFBO = 0,
150 kDesktop_MSFBO,
151 kApple_MSFBO,
152 kIMG_MSFBO
153 } fMSFBOType;
154
155 // Do we have stencil wrap ops.
156 bool fHasStencilWrap;
157
158 // ES requires an extension to support RGBA8 in RenderBufferStorage
159 bool fRGBA8Renderbuffer;
160
161 typedef GrGpu INHERITED;
162};
163
164bool has_gl_extension(const char* ext);
165void gl_version(int* major, int* minor);
166
167/**
168 * GrGL_RestoreResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write
169 * this wrapper, since GL_UNPACK_ROW_LENGTH is not available on all GL versions
170 */
171#if GR_GL_DESKTOP
172 static inline void GrGL_RestoreResetRowLength() {
173 GR_GL(PixelStorei(GL_UNPACK_ROW_LENGTH, 0));
174 }
175#else
176 #define GrGL_RestoreResetRowLength()
177#endif
178
179#if SK_TextGLType != GL_FIXED
180 #define SK_GL_HAS_COLOR4UB
181#endif
182
reed@google.comac20fb92011-01-12 17:14:53 +0000183/*
184 * Some drivers want the var-int arg to be zero-initialized on input.
185 */
186#define GR_GL_INIT_ZERO 0
187#define GR_GL_GetIntegerv(e, p) \
188 do { \
189 *(p) = GR_GL_INIT_ZERO; \
190 GR_GL(GetIntegerv(e, p)); \
191 } while (0)
192
reed@google.comac10a2d2010-12-22 21:39:39 +0000193#endif
194
195