blob: 423d87fe16d387117d116ca7fe86ffe9908baafc [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00006 */
7
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@google.comac10a2d2010-12-22 21:39:39 +000010#ifndef GrGpuGL_DEFINED
11#define GrGpuGL_DEFINED
12
robertphillips@google.com37ebe3f2013-03-04 20:03:44 +000013
bsalomon@google.comc1d2a582012-06-01 15:08:19 +000014#include "GrBinHashKey.h"
tomhudson@google.comd8f856c2012-05-10 12:13:36 +000015#include "GrDrawState.h"
16#include "GrGpu.h"
robertphillips@google.com6177e692013-02-28 20:16:25 +000017#include "GrGLContext.h"
bsalomon@google.com4043ae22011-08-02 14:19:11 +000018#include "GrGLIndexBuffer.h"
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000019#include "GrGLIRect.h"
bsalomon@google.com5739d2c2012-05-31 15:07:19 +000020#include "GrGLProgram.h"
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000021#include "GrGLStencilBuffer.h"
22#include "GrGLTexture.h"
bsalomon@google.com6918d482013-03-07 19:09:11 +000023#include "GrGLVertexArray.h"
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000024#include "GrGLVertexBuffer.h"
bsalomon@google.comc1d2a582012-06-01 15:08:19 +000025#include "../GrTHashCache.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000026
commit-bot@chromium.org174db772013-03-21 12:46:01 +000027#ifdef SK_DEVELOPER
jvanverth@google.com94878772013-03-12 16:00:54 +000028#define PROGRAM_CACHE_STATS
29#endif
30
reed@google.comac10a2d2010-12-22 21:39:39 +000031class GrGpuGL : public GrGpu {
32public:
robertphillips@google.com6177e692013-02-28 20:16:25 +000033 GrGpuGL(const GrGLContext& ctx, GrContext* context);
reed@google.comac10a2d2010-12-22 21:39:39 +000034 virtual ~GrGpuGL();
35
robertphillips@google.com6177e692013-02-28 20:16:25 +000036 const GrGLInterface* glInterface() const { return fGLContext.interface(); }
37 GrGLBinding glBinding() const { return fGLContext.info().binding(); }
38 GrGLVersion glVersion() const { return fGLContext.info().version(); }
39 GrGLSLGeneration glslGeneration() const { return fGLContext.info().glslGeneration(); }
bsalomon@google.com0b77d682011-08-19 13:28:54 +000040
bsalomon@google.com34cccde2013-01-04 18:34:30 +000041 // Used by GrGLProgram to bind necessary textures for GrGLEffects.
42 void bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* texture);
43
bsalomon@google.coma45afcf2013-02-04 18:46:49 +000044 bool programUnitTest(int maxStages);
bsalomon@google.com34cccde2013-01-04 18:34:30 +000045
bsalomon@google.com56d11e02011-11-30 19:59:08 +000046 // GrGpu overrides
bsalomon@google.com9c680582013-02-06 18:17:50 +000047 virtual GrPixelConfig preferredReadPixelsConfig(GrPixelConfig config) const SK_OVERRIDE;
48 virtual GrPixelConfig preferredWritePixelsConfig(GrPixelConfig config) const SK_OVERRIDE;
49 virtual bool canWriteTexturePixels(const GrTexture*, GrPixelConfig srcConfig) const SK_OVERRIDE;
bsalomon@google.comc4364992011-11-07 15:54:49 +000050 virtual bool readPixelsWillPayForYFlip(
51 GrRenderTarget* renderTarget,
52 int left, int top,
53 int width, int height,
54 GrPixelConfig config,
bsalomon@google.com56d11e02011-11-30 19:59:08 +000055 size_t rowBytes) const SK_OVERRIDE;
56 virtual bool fullReadPixelsIsFasterThanPartial() const SK_OVERRIDE;
bsalomon@google.com75f9f252012-01-31 13:35:56 +000057
bsalomon@google.com5739d2c2012-05-31 15:07:19 +000058 virtual void abandonResources() SK_OVERRIDE;
59
bsalomon@google.combcce8922013-03-25 15:38:39 +000060 const GrGLCaps& glCaps() const { return *fGLContext.info().caps(); }
bsalomon@google.com91207482013-02-12 21:45:24 +000061
bsalomon@google.com6918d482013-03-07 19:09:11 +000062 // These functions should be used to bind GL objects. They track the GL state and skip redundant
skia.committer@gmail.com754a3eb2013-03-08 07:01:25 +000063 // bindings. Making the equivalent glBind calls directly will confuse the state tracking.
bsalomon@google.com6918d482013-03-07 19:09:11 +000064 void bindVertexArray(GrGLuint id) {
65 fHWGeometryState.setVertexArrayID(this, id);
66 }
67 void bindIndexBufferAndDefaultVertexArray(GrGLuint id) {
68 fHWGeometryState.setIndexBufferIDOnDefaultVertexArray(this, id);
69 }
70 void bindVertexBuffer(GrGLuint id) {
71 fHWGeometryState.setVertexBufferID(this, id);
72 }
73
74 // These callbacks update state tracking when GL objects are deleted. They are called from
75 // GrGLResource onRelease functions.
76 void notifyVertexArrayDelete(GrGLuint id) {
77 fHWGeometryState.notifyVertexArrayDelete(id);
78 }
79 void notifyVertexBufferDelete(GrGLuint id) {
80 fHWGeometryState.notifyVertexBufferDelete(id);
81 }
82 void notifyIndexBufferDelete(GrGLuint id) {
83 fHWGeometryState.notifyIndexBufferDelete(id);
84 }
bsalomon@google.com880b8fc2013-02-19 20:17:28 +000085 void notifyTextureDelete(GrGLTexture* texture);
86 void notifyRenderTargetDelete(GrRenderTarget* renderTarget);
87
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +000088private:
bsalomon@google.com1c13c962011-02-14 16:51:21 +000089 // GrGpu overrides
bsalomon@google.com1bf1c212011-11-05 12:18:58 +000090 virtual void onResetContext() SK_OVERRIDE;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +000091
bsalomon@google.comfea37b52011-04-25 15:51:06 +000092 virtual GrTexture* onCreateTexture(const GrTextureDesc& desc,
bsalomon@google.combcdbbe62011-04-12 15:40:00 +000093 const void* srcData,
bsalomon@google.com13f1b6f2012-05-31 12:52:43 +000094 size_t rowBytes) SK_OVERRIDE;
bsalomon@google.combcdbbe62011-04-12 15:40:00 +000095 virtual GrVertexBuffer* onCreateVertexBuffer(uint32_t size,
bsalomon@google.com13f1b6f2012-05-31 12:52:43 +000096 bool dynamic) SK_OVERRIDE;
bsalomon@google.combcdbbe62011-04-12 15:40:00 +000097 virtual GrIndexBuffer* onCreateIndexBuffer(uint32_t size,
bsalomon@google.com13f1b6f2012-05-31 12:52:43 +000098 bool dynamic) SK_OVERRIDE;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000099 virtual GrPath* onCreatePath(const SkPath&) SK_OVERRIDE;
bsalomon@google.com16e3dde2012-10-25 18:43:28 +0000100 virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) SK_OVERRIDE;
101 virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) SK_OVERRIDE;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000102 virtual bool createStencilBufferForRenderTarget(GrRenderTarget* rt,
bsalomon@google.com13f1b6f2012-05-31 12:52:43 +0000103 int width,
104 int height) SK_OVERRIDE;
105 virtual bool attachStencilBufferToRenderTarget(
106 GrStencilBuffer* sb,
107 GrRenderTarget* rt) SK_OVERRIDE;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000108
bsalomon@google.com13f1b6f2012-05-31 12:52:43 +0000109 virtual void onClear(const GrIRect* rect, GrColor color) SK_OVERRIDE;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000110
bsalomon@google.com13f1b6f2012-05-31 12:52:43 +0000111 virtual void onForceRenderTargetFlush() SK_OVERRIDE;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000112
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000113 virtual bool onReadPixels(GrRenderTarget* target,
rmistry@google.comd6176b02012-08-23 18:14:13 +0000114 int left, int top,
bsalomon@google.comc6980972011-11-02 19:57:21 +0000115 int width, int height,
rmistry@google.comd6176b02012-08-23 18:14:13 +0000116 GrPixelConfig,
bsalomon@google.comc4364992011-11-07 15:54:49 +0000117 void* buffer,
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +0000118 size_t rowBytes) SK_OVERRIDE;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000119
bsalomon@google.com9c680582013-02-06 18:17:50 +0000120 virtual bool onWriteTexturePixels(GrTexture* texture,
bsalomon@google.com6f379512011-11-16 20:36:03 +0000121 int left, int top, int width, int height,
122 GrPixelConfig config, const void* buffer,
123 size_t rowBytes) SK_OVERRIDE;
124
bsalomon@google.com75f9f252012-01-31 13:35:56 +0000125 virtual void onResolveRenderTarget(GrRenderTarget* target) SK_OVERRIDE;
126
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000127 virtual void onGpuDraw(const DrawInfo&) SK_OVERRIDE;
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000128
129 virtual void setStencilPathSettings(const GrPath&,
sugoi@google.com12b4e272012-12-06 20:13:11 +0000130 SkPath::FillType,
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000131 GrStencilSettings* settings)
132 SK_OVERRIDE;
sugoi@google.com12b4e272012-12-06 20:13:11 +0000133 virtual void onGpuStencilPath(const GrPath*, SkPath::FillType) SK_OVERRIDE;
robertphillips@google.com730ebe52012-04-16 16:33:13 +0000134
bsalomon@google.com13f1b6f2012-05-31 12:52:43 +0000135 virtual void clearStencil() SK_OVERRIDE;
136 virtual void clearStencilClip(const GrIRect& rect,
137 bool insideClip) SK_OVERRIDE;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000138 virtual bool flushGraphicsState(DrawType) SK_OVERRIDE;
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000139
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000140 // binds texture unit in GL
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000141 void setTextureUnit(int unitIdx);
reed@google.comac10a2d2010-12-22 21:39:39 +0000142
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000143 // Sets up vertex attribute pointers and strides. On return indexOffsetInBytes gives the offset
144 // an into the index buffer. It does not account for drawInfo.startIndex() but rather the start
145 // index is relative to the returned offset.
146 void setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes);
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +0000147
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000148 // Subclasses should call this to flush the blend state.
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000149 // The params should be the final coefficients to apply
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000150 // (after any blending optimizations or dual source blending considerations
151 // have been accounted for).
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000152 void flushBlend(bool isLines, GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff);
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000153
robertphillips@google.com6177e692013-02-28 20:16:25 +0000154 bool hasExtension(const char* ext) const { return fGLContext.info().hasExtension(ext); }
bsalomon@google.com96399942012-02-13 14:39:16 +0000155
robertphillips@google.com6177e692013-02-28 20:16:25 +0000156 const GrGLContext& glContext() const { return fGLContext; }
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +0000157
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000158 static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff);
bsalomon@google.com080773c2011-03-15 19:09:25 +0000159
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000160 class ProgramCache : public ::GrNoncopyable {
161 public:
robertphillips@google.com6177e692013-02-28 20:16:25 +0000162 ProgramCache(const GrGLContext& gl);
jvanverth@google.com94878772013-03-12 16:00:54 +0000163 ~ProgramCache();
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000164
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000165 void abandon();
bsalomon@google.com2eaaefd2012-10-29 19:51:22 +0000166 GrGLProgram* getProgram(const GrGLProgram::Desc& desc, const GrEffectStage* stages[]);
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000167 private:
168 enum {
bsalomon@google.com91207482013-02-12 21:45:24 +0000169 kKeySize = sizeof(GrGLProgram::Desc),
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000170 // We may actually have kMaxEntries+1 shaders in the GL context because we create a new
171 // shader before evicting from the cache.
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000172 kMaxEntries = 32
173 };
174
175 class Entry;
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000176 // The value of the hash key is based on the ProgramDesc.
177 typedef GrTBinHashKey<Entry, kKeySize> ProgramHashKey;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000178
179 class Entry : public ::GrNoncopyable {
180 public:
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000181 Entry() : fProgram(NULL), fLRUStamp(0) {}
182 Entry& operator = (const Entry& entry) {
183 GrSafeRef(entry.fProgram.get());
184 fProgram.reset(entry.fProgram.get());
185 fKey = entry.fKey;
186 fLRUStamp = entry.fLRUStamp;
187 return *this;
188 }
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000189 int compare(const ProgramHashKey& key) const {
190 return fKey.compare(key);
191 }
192
193 public:
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000194 SkAutoTUnref<GrGLProgram> fProgram;
195 ProgramHashKey fKey;
196 unsigned int fLRUStamp; // Move outside entry?
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000197 };
198
199 GrTHashTable<Entry, ProgramHashKey, 8> fHashCache;
200
201 Entry fEntries[kMaxEntries];
202 int fCount;
203 unsigned int fCurrLRUStamp;
robertphillips@google.com6177e692013-02-28 20:16:25 +0000204 const GrGLContext& fGL;
jvanverth@google.com94878772013-03-12 16:00:54 +0000205#ifdef PROGRAM_CACHE_STATS
206 int fTotalRequests;
207 int fCacheMisses;
208#endif
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000209 };
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000210
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000211 // sets the matrix for path stenciling (uses the GL fixed pipe matrices)
212 void flushPathStencilMatrix();
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000213
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +0000214 // flushes dithering, color-mask, and face culling stat
215 void flushMiscFixedFunctionState();
216
bsalomon@google.coma3201942012-06-21 19:58:20 +0000217 // flushes the scissor. see the note on flushBoundTextureAndParams about
218 // flushing the scissor after that function is called.
219 void flushScissor();
220
bsalomon@google.com18c9c192011-09-22 21:01:31 +0000221 void initFSAASupport();
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000222
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +0000223 // determines valid stencil formats
bsalomon@google.com18c9c192011-09-22 21:01:31 +0000224 void initStencilFormats();
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +0000225
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000226 void setSpareTextureUnit();
reed@google.comac10a2d2010-12-22 21:39:39 +0000227
bsalomon@google.com8295dc12011-05-02 12:53:34 +0000228 // bound is region that may be modified and therefore has to be resolved.
229 // NULL means whole target. Can be an empty rect.
230 void flushRenderTarget(const GrIRect* bound);
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000231 void flushStencil(DrawType);
232 void flushAAState(DrawType);
bsalomon@google.com0650e812011-04-08 18:07:53 +0000233
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000234 bool configToGLFormats(GrPixelConfig config,
235 bool getSizedInternal,
236 GrGLenum* internalFormat,
237 GrGLenum* externalFormat,
238 GrGLenum* externalType);
bsalomon@google.com6f379512011-11-16 20:36:03 +0000239 // helper for onCreateTexture and writeTexturePixels
bsalomon@google.com136f55b2011-11-28 18:34:44 +0000240 bool uploadTexData(const GrGLTexture::Desc& desc,
bsalomon@google.com1e0e6072011-11-28 18:49:37 +0000241 bool isNewTexture,
bsalomon@google.com6f379512011-11-16 20:36:03 +0000242 int left, int top, int width, int height,
243 GrPixelConfig dataConfig,
244 const void* data,
245 size_t rowBytes);
bsalomon@google.com0650e812011-04-08 18:07:53 +0000246
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000247 bool createRenderTargetObjects(int width, int height,
248 GrGLuint texID,
249 GrGLRenderTarget::Desc* desc);
250
robertphillips@google.com99a5ac02012-04-10 19:26:38 +0000251 void fillInConfigRenderableTable();
252
robertphillips@google.com6177e692013-02-28 20:16:25 +0000253 GrGLContext fGLContext;
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +0000254
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000255 // GL program-related state
256 ProgramCache* fProgramCache;
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000257 SkAutoTUnref<GrGLProgram> fCurrentProgram;
bsalomon@google.com49209392012-06-05 15:13:46 +0000258
259 ///////////////////////////////////////////////////////////////////////////
260 ///@name Caching of GL State
261 ///@{
262 int fHWActiveTextureUnitIdx;
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000263 GrGLuint fHWProgramID;
bsalomon@google.com91207482013-02-12 21:45:24 +0000264
265 GrGLProgram::SharedGLState fSharedGLProgramState;
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000266
bsalomon@google.com49209392012-06-05 15:13:46 +0000267 enum TriState {
268 kNo_TriState,
269 kYes_TriState,
270 kUnknown_TriState
271 };
272
bsalomon@google.coma3201942012-06-21 19:58:20 +0000273 // last scissor / viewport scissor state seen by the GL.
274 struct {
275 TriState fEnabled;
276 GrGLIRect fRect;
277 void invalidate() {
278 fEnabled = kUnknown_TriState;
279 fRect.invalidate();
280 }
281 } fHWScissorSettings;
282
283 GrGLIRect fHWViewport;
284
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000285 /**
286 * Tracks bound vertex and index buffers and vertex attrib array state.
287 */
288 class HWGeometryState {
289 public:
bsalomon@google.com6918d482013-03-07 19:09:11 +0000290 HWGeometryState() { fVBOVertexArray = NULL; this->invalidate(); }
skia.committer@gmail.com754a3eb2013-03-08 07:01:25 +0000291
bsalomon@google.com6918d482013-03-07 19:09:11 +0000292 ~HWGeometryState() { SkSafeUnref(fVBOVertexArray); }
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000293
bsalomon@google.com6918d482013-03-07 19:09:11 +0000294 void invalidate() {
295 fBoundVertexArrayIDIsValid = false;
296 fBoundVertexBufferIDIsValid = false;
297 fDefaultVertexArrayBoundIndexBufferID = false;
298 fDefaultVertexArrayBoundIndexBufferIDIsValid = false;
299 fDefaultVertexArrayAttribState.invalidate();
300 }
301
302 void notifyVertexArrayDelete(GrGLuint id) {
303 if (fBoundVertexArrayIDIsValid && fBoundVertexArrayID == id) {
304 // Does implicit bind to 0
305 fBoundVertexArrayID = 0;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000306 }
307 }
308
bsalomon@google.com6918d482013-03-07 19:09:11 +0000309 void setVertexArrayID(GrGpuGL* gpu, GrGLuint arrayID) {
310 if (!gpu->glCaps().vertexArrayObjectSupport()) {
311 GrAssert(0 == arrayID);
312 return;
313 }
314 if (!fBoundVertexArrayIDIsValid || arrayID != fBoundVertexArrayID) {
315 GR_GL_CALL(gpu->glInterface(), BindVertexArray(arrayID));
316 fBoundVertexArrayIDIsValid = true;
317 fBoundVertexArrayID = arrayID;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000318 }
319 }
320
bsalomon@google.come49ad452013-02-20 19:33:20 +0000321 void notifyVertexBufferDelete(GrGLuint id) {
bsalomon@google.com6918d482013-03-07 19:09:11 +0000322 if (fBoundVertexBufferIDIsValid && id == fBoundVertexBufferID) {
323 fBoundVertexBufferID = 0;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000324 }
bsalomon@google.com6918d482013-03-07 19:09:11 +0000325 if (NULL != fVBOVertexArray) {
326 fVBOVertexArray->notifyVertexBufferDelete(id);
327 }
328 fDefaultVertexArrayAttribState.notifyVertexBufferDelete(id);
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000329 }
330
bsalomon@google.come49ad452013-02-20 19:33:20 +0000331 void notifyIndexBufferDelete(GrGLuint id) {
bsalomon@google.com6918d482013-03-07 19:09:11 +0000332 if (fDefaultVertexArrayBoundIndexBufferIDIsValid &&
333 id == fDefaultVertexArrayBoundIndexBufferID) {
334 fDefaultVertexArrayBoundIndexBufferID = 0;
335 }
336 if (NULL != fVBOVertexArray) {
337 fVBOVertexArray->notifyIndexBufferDelete(id);
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000338 }
339 }
340
bsalomon@google.com6918d482013-03-07 19:09:11 +0000341 void setVertexBufferID(GrGpuGL* gpu, GrGLuint id) {
342 if (!fBoundVertexBufferIDIsValid || id != fBoundVertexBufferID) {
343 GR_GL_CALL(gpu->glInterface(), BindBuffer(GR_GL_ARRAY_BUFFER, id));
344 fBoundVertexBufferIDIsValid = true;
345 fBoundVertexBufferID = id;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000346 }
347 }
348
bsalomon@google.com6918d482013-03-07 19:09:11 +0000349 /**
350 * Binds the default vertex array and binds the index buffer. This is used when binding
351 * an index buffer in order to update it.
352 */
353 void setIndexBufferIDOnDefaultVertexArray(GrGpuGL* gpu, GrGLuint id) {
354 this->setVertexArrayID(gpu, 0);
355 if (!fDefaultVertexArrayBoundIndexBufferIDIsValid ||
356 id != fDefaultVertexArrayBoundIndexBufferID) {
357 GR_GL_CALL(gpu->glInterface(), BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, id));
358 fDefaultVertexArrayBoundIndexBufferIDIsValid = true;
359 fDefaultVertexArrayBoundIndexBufferID = id;
360 }
361 }
362
363 /**
364 * Binds the vertex array object that should be used to render from the vertex buffer.
365 * The vertex array is bound and its attrib array state object is returned. The vertex
366 * buffer is bound. The index buffer (if non-NULL) is bound to the vertex array. The
skia.committer@gmail.com754a3eb2013-03-08 07:01:25 +0000367 * returned GrGLAttribArrayState should be used to set vertex attribute arrays.
bsalomon@google.com6918d482013-03-07 19:09:11 +0000368 */
369 GrGLAttribArrayState* bindArrayAndBuffersToDraw(GrGpuGL* gpu,
370 const GrGLVertexBuffer* vbuffer,
371 const GrGLIndexBuffer* ibuffer);
372
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000373 private:
bsalomon@google.com6918d482013-03-07 19:09:11 +0000374 GrGLuint fBoundVertexArrayID;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000375 GrGLuint fBoundVertexBufferID;
bsalomon@google.com6918d482013-03-07 19:09:11 +0000376 bool fBoundVertexArrayIDIsValid;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000377 bool fBoundVertexBufferIDIsValid;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000378
bsalomon@google.com6918d482013-03-07 19:09:11 +0000379 GrGLuint fDefaultVertexArrayBoundIndexBufferID;
380 bool fDefaultVertexArrayBoundIndexBufferIDIsValid;
381 // We return a non-const pointer to this from bindArrayAndBuffersToDraw when vertex array 0
382 // is bound. However, this class is internal to GrGpuGL and this object never leaks out of
383 // GrGpuGL.
384 GrGLAttribArrayState fDefaultVertexArrayAttribState;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000385
bsalomon@google.com6918d482013-03-07 19:09:11 +0000386 // This is used when we're using a core profile and the vertices are in a VBO.
387 GrGLVertexArray* fVBOVertexArray;
bsalomon@google.com49209392012-06-05 15:13:46 +0000388 } fHWGeometryState;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000389
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000390 struct {
391 GrBlendCoeff fSrcCoeff;
392 GrBlendCoeff fDstCoeff;
393 GrColor fConstColor;
394 bool fConstColorValid;
395 TriState fEnabled;
396
397 void invalidate() {
bsalomon@google.com47059542012-06-06 20:51:20 +0000398 fSrcCoeff = kInvalid_GrBlendCoeff;
399 fDstCoeff = kInvalid_GrBlendCoeff;
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000400 fConstColorValid = false;
401 fEnabled = kUnknown_TriState;
402 }
403 } fHWBlendState;
404
bsalomon@google.com4d5f3fe2012-05-21 17:11:44 +0000405 struct {
406 TriState fMSAAEnabled;
407 TriState fSmoothLineEnabled;
408 void invalidate() {
409 fMSAAEnabled = kUnknown_TriState;
410 fSmoothLineEnabled = kUnknown_TriState;
411 }
412 } fHWAAState;
413
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000414
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000415 GrGLProgram::MatrixState fHWPathStencilMatrixState;
bsalomon@google.com457b8a32012-05-21 21:19:58 +0000416
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000417 GrStencilSettings fHWStencilSettings;
418 TriState fHWStencilTestEnabled;
419
420 GrDrawState::DrawFace fHWDrawFace;
421 TriState fHWWriteToColor;
422 TriState fHWDitherEnabled;
423 GrRenderTarget* fHWBoundRenderTarget;
424 GrTexture* fHWBoundTextures[GrDrawState::kNumStages];
bsalomon@google.com49209392012-06-05 15:13:46 +0000425 ///@}
bsalomon@google.com978c8c62012-05-21 14:45:49 +0000426
bsalomon@google.comfe676522011-06-17 18:12:21 +0000427 // we record what stencil format worked last time to hopefully exit early
428 // from our loop that tries stencil formats and calls check fb status.
429 int fLastSuccessfulStencilFmtIdx;
430
reed@google.comac10a2d2010-12-22 21:39:39 +0000431 typedef GrGpu INHERITED;
432};
433
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000434#endif