blob: ea0c081cd2b5bc7b71dfe64cdfd072bde39e72b9 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
bsalomon@google.com1da07462011-03-10 14:51:57 +00002 Copyright 2011 Google Inc.
reed@google.comac10a2d2010-12-22 21:39:39 +00003
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"
bsalomon@google.com8895a7a2011-02-18 16:09:55 +000023#include "GrGLIRect.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000024#include "GrGLTexture.h"
25
26#include "GrGLVertexBuffer.h"
27#include "GrGLIndexBuffer.h"
28
29class GrGpuGL : public GrGpu {
30public:
31 GrGpuGL();
32 virtual ~GrGpuGL();
33
reed@google.comac10a2d2010-12-22 21:39:39 +000034protected:
35 struct {
bsalomon@google.com1c13c962011-02-14 16:51:21 +000036 size_t fVertexOffset;
reed@google.comac10a2d2010-12-22 21:39:39 +000037 GrVertexLayout fVertexLayout;
38 const GrVertexBuffer* fVertexBuffer;
39 const GrIndexBuffer* fIndexBuffer;
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +000040 bool fArrayPtrsDirty;
reed@google.comac10a2d2010-12-22 21:39:39 +000041 } fHWGeometryState;
42
reed@google.com8195f672011-01-12 18:14:28 +000043 DrState fHWDrawState;
44 bool fHWStencilClip;
reed@google.comac10a2d2010-12-22 21:39:39 +000045
bsalomon@google.comc6cf7232011-02-17 16:43:10 +000046 // As flush of GL state proceeds it updates fHDrawState
47 // to reflect the new state. Later parts of the state flush
48 // may perform cascaded changes but cannot refer to fHWDrawState.
49 // These code paths can refer to the dirty flags. Subclass should
50 // call resetDirtyFlags after its flush is complete
51 struct {
52 bool fRenderTargetChanged : 1;
bsalomon@google.comc6cf7232011-02-17 16:43:10 +000053 int fTextureChangedMask;
54 } fDirtyFlags;
55 GR_STATIC_ASSERT(8 * sizeof(int) >= kNumStages);
56
57 // clears the dirty flags
58 void resetDirtyFlags();
59
60 // last scissor / viewport scissor state seen by the GL.
bsalomon@google.com8895a7a2011-02-18 16:09:55 +000061 struct {
62 bool fScissorEnabled;
63 GrGLIRect fScissorRect;
64 GrGLIRect fViewportRect;
65 } fHWBounds;
bsalomon@google.comc6cf7232011-02-17 16:43:10 +000066
bsalomon@google.com1c13c962011-02-14 16:51:21 +000067 // GrGpu overrides
bsalomon@google.coma7f84e12011-03-10 14:13:19 +000068 // overrides from GrGpu
69 virtual void resetContext();
70
71 virtual GrTexture* createTextureHelper(const TextureDesc& desc,
72 const void* srcData,
73 size_t rowBytes);
74 virtual GrVertexBuffer* createVertexBufferHelper(uint32_t size,
75 bool dynamic);
76 virtual GrIndexBuffer* createIndexBufferHelper(uint32_t size,
77 bool dynamic);
78
79 virtual GrRenderTarget* createPlatformRenderTargetHelper(
80 intptr_t platformRenderTarget,
81 int stencilBits,
82 int width, int height);
83
84 virtual GrRenderTarget* createRenderTargetFrom3DApiStateHelper();
85
86 virtual void eraseColorHelper(GrColor color);
87
88 virtual void forceRenderTargetFlushHelper();
89
90 virtual bool readPixelsHelper(int left, int top, int width, int height,
91 GrTexture::PixelConfig, void* buffer);
92
bsalomon@google.comffca4002011-02-22 20:34:01 +000093 virtual void drawIndexedHelper(GrPrimitiveType type,
reed@google.comac10a2d2010-12-22 21:39:39 +000094 uint32_t startVertex,
95 uint32_t startIndex,
96 uint32_t vertexCount,
97 uint32_t indexCount);
bsalomon@google.comffca4002011-02-22 20:34:01 +000098 virtual void drawNonIndexedHelper(GrPrimitiveType type,
reed@google.comac10a2d2010-12-22 21:39:39 +000099 uint32_t vertexCount,
100 uint32_t numVertices);
reed@google.comac10a2d2010-12-22 21:39:39 +0000101 virtual void flushScissor(const GrIRect* rect);
reed@google.comac10a2d2010-12-22 21:39:39 +0000102 void eraseStencil(uint32_t value, uint32_t mask);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000103 virtual void eraseStencilClip(const GrIRect& rect);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000104
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000105 // binds texture unit in GL
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000106 void setTextureUnit(int unitIdx);
reed@google.comac10a2d2010-12-22 21:39:39 +0000107
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000108 // binds appropriate vertex and index buffers, also returns any extra
109 // extra verts or indices to offset by.
110 void setBuffers(bool indexed,
111 int* extraVertexOffset,
112 int* extraIndexOffset);
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +0000113
reed@google.comac10a2d2010-12-22 21:39:39 +0000114 // flushes state that is common to fixed and programmable GL
115 // dither
116 // line smoothing
117 // blend func
118 // texture binding
119 // sampler state (filtering, tiling)
120 // FBO binding
121 // line width
bsalomon@google.comffca4002011-02-22 20:34:01 +0000122 bool flushGLStateCommon(GrPrimitiveType type);
reed@google.comac10a2d2010-12-22 21:39:39 +0000123
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000124 // adjusts texture matrix to account for orientation, size, and npotness
125 static void AdjustTextureMatrix(const GrGLTexture* texture,
126 GrSamplerState::SampleMode mode,
127 GrMatrix* matrix);
reed@google.comac10a2d2010-12-22 21:39:39 +0000128
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000129 // subclass may try to take advantage of identity tex matrices.
130 // This helper determines if matrix will be identity after all
131 // adjustments are applied.
132 static bool TextureMatrixIsIdentity(const GrGLTexture* texture,
133 const GrSamplerState& sampler);
reed@google.comac10a2d2010-12-22 21:39:39 +0000134
bsalomon@google.com080773c2011-03-15 19:09:25 +0000135 static bool BlendCoefReferencesConstant(GrBlendCoeff coeff);
136
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000137private:
reed@google.comac10a2d2010-12-22 21:39:39 +0000138 // notify callbacks to update state tracking when related
139 // objects are bound to GL or deleted outside of the class
140 void notifyVertexBufferBind(const GrGLVertexBuffer* buffer);
141 void notifyVertexBufferDelete(const GrGLVertexBuffer* buffer);
142 void notifyIndexBufferBind(const GrGLIndexBuffer* buffer);
143 void notifyIndexBufferDelete(const GrGLIndexBuffer* buffer);
reed@google.comac10a2d2010-12-22 21:39:39 +0000144 void notifyTextureDelete(GrGLTexture* texture);
145 void notifyRenderTargetDelete(GrRenderTarget* renderTarget);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000146
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000147 void setSpareTextureUnit();
reed@google.comac10a2d2010-12-22 21:39:39 +0000148
149 void flushRenderTarget();
150 void flushStencil();
151 void resolveTextureRenderTarget(GrGLTexture* texture);
152
153 bool canBeTexture(GrTexture::PixelConfig config,
154 GLenum* internalFormat,
155 GLenum* format,
156 GLenum* type);
157 bool fboInternalFormat(GrTexture::PixelConfig config, GLenum* format);
158
159 friend class GrGLVertexBuffer;
160 friend class GrGLIndexBuffer;
161 friend class GrGLTexture;
162 friend class GrGLRenderTarget;
163
164 bool fHWBlendDisabled;
165
166 GLuint fAASamples[4];
167 enum {
168 kNone_MSFBO = 0,
169 kDesktop_MSFBO,
170 kApple_MSFBO,
171 kIMG_MSFBO
172 } fMSFBOType;
173
174 // Do we have stencil wrap ops.
175 bool fHasStencilWrap;
176
177 // ES requires an extension to support RGBA8 in RenderBufferStorage
178 bool fRGBA8Renderbuffer;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000179
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000180 int fActiveTextureUnitIdx;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000181
reed@google.comac10a2d2010-12-22 21:39:39 +0000182 typedef GrGpu INHERITED;
183};
184
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000185#endif