~gabriel1984sibiu/minitube/qt5.6

« back to all changes in this revision

Viewing changes to src/3rdparty/angle/src/libANGLE/State.cpp

  • Committer: Grevutiu Gabriel
  • Date: 2017-06-13 08:43:17 UTC
  • Revision ID: gabriel1984sibiu@gmail.com-20170613084317-ek0zqe0u9g3ocvi8
OriginalĀ upstreamĀ code

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
 
3
// Use of this source code is governed by a BSD-style license that can be
 
4
// found in the LICENSE file.
 
5
//
 
6
 
 
7
// State.cpp: Implements the State class, encapsulating raw GL state.
 
8
 
 
9
#include "libANGLE/State.h"
 
10
 
 
11
#include "common/BitSetIterator.h"
 
12
#include "libANGLE/Context.h"
 
13
#include "libANGLE/Caps.h"
 
14
#include "libANGLE/Debug.h"
 
15
#include "libANGLE/Framebuffer.h"
 
16
#include "libANGLE/FramebufferAttachment.h"
 
17
#include "libANGLE/Query.h"
 
18
#include "libANGLE/VertexArray.h"
 
19
#include "libANGLE/formatutils.h"
 
20
 
 
21
namespace gl
 
22
{
 
23
 
 
24
State::State()
 
25
    : mMaxDrawBuffers(0),
 
26
      mMaxCombinedTextureImageUnits(0),
 
27
      mDepthClearValue(0),
 
28
      mStencilClearValue(0),
 
29
      mScissorTest(false),
 
30
      mSampleCoverage(false),
 
31
      mSampleCoverageValue(0),
 
32
      mSampleCoverageInvert(false),
 
33
      mStencilRef(0),
 
34
      mStencilBackRef(0),
 
35
      mLineWidth(0),
 
36
      mGenerateMipmapHint(GL_NONE),
 
37
      mFragmentShaderDerivativeHint(GL_NONE),
 
38
      mNearZ(0),
 
39
      mFarZ(0),
 
40
      mReadFramebuffer(nullptr),
 
41
      mDrawFramebuffer(nullptr),
 
42
      mProgram(nullptr),
 
43
      mVertexArray(nullptr),
 
44
      mActiveSampler(0),
 
45
      mPrimitiveRestart(false)
 
46
{
 
47
    // Initialize dirty bit masks
 
48
    // TODO(jmadill): additional ES3 state
 
49
    mUnpackStateBitMask.set(DIRTY_BIT_UNPACK_ALIGNMENT);
 
50
    mUnpackStateBitMask.set(DIRTY_BIT_UNPACK_ROW_LENGTH);
 
51
    mUnpackStateBitMask.set(DIRTY_BIT_UNPACK_IMAGE_HEIGHT);
 
52
    mUnpackStateBitMask.set(DIRTY_BIT_UNPACK_SKIP_IMAGES);
 
53
    mUnpackStateBitMask.set(DIRTY_BIT_UNPACK_SKIP_ROWS);
 
54
    mUnpackStateBitMask.set(DIRTY_BIT_UNPACK_SKIP_PIXELS);
 
55
 
 
56
    mPackStateBitMask.set(DIRTY_BIT_PACK_ALIGNMENT);
 
57
    mPackStateBitMask.set(DIRTY_BIT_PACK_REVERSE_ROW_ORDER);
 
58
    mPackStateBitMask.set(DIRTY_BIT_PACK_ROW_LENGTH);
 
59
    mPackStateBitMask.set(DIRTY_BIT_PACK_SKIP_ROWS);
 
60
    mPackStateBitMask.set(DIRTY_BIT_PACK_SKIP_PIXELS);
 
61
 
 
62
    mClearStateBitMask.set(DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
 
63
    mClearStateBitMask.set(DIRTY_BIT_SCISSOR_TEST_ENABLED);
 
64
    mClearStateBitMask.set(DIRTY_BIT_SCISSOR);
 
65
    mClearStateBitMask.set(DIRTY_BIT_VIEWPORT);
 
66
    mClearStateBitMask.set(DIRTY_BIT_CLEAR_COLOR);
 
67
    mClearStateBitMask.set(DIRTY_BIT_CLEAR_DEPTH);
 
68
    mClearStateBitMask.set(DIRTY_BIT_CLEAR_STENCIL);
 
69
    mClearStateBitMask.set(DIRTY_BIT_COLOR_MASK);
 
70
    mClearStateBitMask.set(DIRTY_BIT_DEPTH_MASK);
 
71
    mClearStateBitMask.set(DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
 
72
    mClearStateBitMask.set(DIRTY_BIT_STENCIL_WRITEMASK_BACK);
 
73
 
 
74
    mBlitStateBitMask.set(DIRTY_BIT_SCISSOR_TEST_ENABLED);
 
75
    mBlitStateBitMask.set(DIRTY_BIT_SCISSOR);
 
76
}
 
77
 
 
78
State::~State()
 
79
{
 
80
    reset();
 
81
}
 
82
 
 
83
void State::initialize(const Caps &caps,
 
84
                       const Extensions &extensions,
 
85
                       GLuint clientVersion,
 
86
                       bool debug)
 
87
{
 
88
    mMaxDrawBuffers = caps.maxDrawBuffers;
 
89
    mMaxCombinedTextureImageUnits = caps.maxCombinedTextureImageUnits;
 
90
 
 
91
    setColorClearValue(0.0f, 0.0f, 0.0f, 0.0f);
 
92
 
 
93
    mDepthClearValue = 1.0f;
 
94
    mStencilClearValue = 0;
 
95
 
 
96
    mRasterizer.rasterizerDiscard = false;
 
97
    mRasterizer.cullFace = false;
 
98
    mRasterizer.cullMode = GL_BACK;
 
99
    mRasterizer.frontFace = GL_CCW;
 
100
    mRasterizer.polygonOffsetFill = false;
 
101
    mRasterizer.polygonOffsetFactor = 0.0f;
 
102
    mRasterizer.polygonOffsetUnits = 0.0f;
 
103
    mRasterizer.pointDrawMode = false;
 
104
    mRasterizer.multiSample = false;
 
105
    mScissorTest = false;
 
106
    mScissor.x = 0;
 
107
    mScissor.y = 0;
 
108
    mScissor.width = 0;
 
109
    mScissor.height = 0;
 
110
 
 
111
    mBlend.blend = false;
 
112
    mBlend.sourceBlendRGB = GL_ONE;
 
113
    mBlend.sourceBlendAlpha = GL_ONE;
 
114
    mBlend.destBlendRGB = GL_ZERO;
 
115
    mBlend.destBlendAlpha = GL_ZERO;
 
116
    mBlend.blendEquationRGB = GL_FUNC_ADD;
 
117
    mBlend.blendEquationAlpha = GL_FUNC_ADD;
 
118
    mBlend.sampleAlphaToCoverage = false;
 
119
    mBlend.dither = true;
 
120
 
 
121
    mBlendColor.red = 0;
 
122
    mBlendColor.green = 0;
 
123
    mBlendColor.blue = 0;
 
124
    mBlendColor.alpha = 0;
 
125
 
 
126
    mDepthStencil.depthTest = false;
 
127
    mDepthStencil.depthFunc = GL_LESS;
 
128
    mDepthStencil.depthMask = true;
 
129
    mDepthStencil.stencilTest = false;
 
130
    mDepthStencil.stencilFunc = GL_ALWAYS;
 
131
    mDepthStencil.stencilMask = static_cast<GLuint>(-1);
 
132
    mDepthStencil.stencilWritemask = static_cast<GLuint>(-1);
 
133
    mDepthStencil.stencilBackFunc = GL_ALWAYS;
 
134
    mDepthStencil.stencilBackMask = static_cast<GLuint>(-1);
 
135
    mDepthStencil.stencilBackWritemask = static_cast<GLuint>(-1);
 
136
    mDepthStencil.stencilFail = GL_KEEP;
 
137
    mDepthStencil.stencilPassDepthFail = GL_KEEP;
 
138
    mDepthStencil.stencilPassDepthPass = GL_KEEP;
 
139
    mDepthStencil.stencilBackFail = GL_KEEP;
 
140
    mDepthStencil.stencilBackPassDepthFail = GL_KEEP;
 
141
    mDepthStencil.stencilBackPassDepthPass = GL_KEEP;
 
142
 
 
143
    mStencilRef = 0;
 
144
    mStencilBackRef = 0;
 
145
 
 
146
    mSampleCoverage = false;
 
147
    mSampleCoverageValue = 1.0f;
 
148
    mSampleCoverageInvert = false;
 
149
    mGenerateMipmapHint = GL_DONT_CARE;
 
150
    mFragmentShaderDerivativeHint = GL_DONT_CARE;
 
151
 
 
152
    mLineWidth = 1.0f;
 
153
 
 
154
    mViewport.x = 0;
 
155
    mViewport.y = 0;
 
156
    mViewport.width = 0;
 
157
    mViewport.height = 0;
 
158
    mNearZ = 0.0f;
 
159
    mFarZ = 1.0f;
 
160
 
 
161
    mBlend.colorMaskRed = true;
 
162
    mBlend.colorMaskGreen = true;
 
163
    mBlend.colorMaskBlue = true;
 
164
    mBlend.colorMaskAlpha = true;
 
165
 
 
166
    mActiveSampler = 0;
 
167
 
 
168
    mVertexAttribCurrentValues.resize(caps.maxVertexAttributes);
 
169
 
 
170
    mUniformBuffers.resize(caps.maxCombinedUniformBlocks);
 
171
 
 
172
    mSamplerTextures[GL_TEXTURE_2D].resize(caps.maxCombinedTextureImageUnits);
 
173
    mSamplerTextures[GL_TEXTURE_CUBE_MAP].resize(caps.maxCombinedTextureImageUnits);
 
174
    if (clientVersion >= 3)
 
175
    {
 
176
        // TODO: These could also be enabled via extension
 
177
        mSamplerTextures[GL_TEXTURE_2D_ARRAY].resize(caps.maxCombinedTextureImageUnits);
 
178
        mSamplerTextures[GL_TEXTURE_3D].resize(caps.maxCombinedTextureImageUnits);
 
179
    }
 
180
 
 
181
    mSamplers.resize(caps.maxCombinedTextureImageUnits);
 
182
 
 
183
    mActiveQueries[GL_ANY_SAMPLES_PASSED].set(nullptr);
 
184
    mActiveQueries[GL_ANY_SAMPLES_PASSED_CONSERVATIVE].set(nullptr);
 
185
    mActiveQueries[GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN].set(nullptr);
 
186
    mActiveQueries[GL_TIME_ELAPSED_EXT].set(nullptr);
 
187
 
 
188
    mProgram = nullptr;
 
189
 
 
190
    mReadFramebuffer = nullptr;
 
191
    mDrawFramebuffer = nullptr;
 
192
 
 
193
    mPrimitiveRestart = false;
 
194
 
 
195
    mDebug.setOutputEnabled(debug);
 
196
    mDebug.setMaxLoggedMessages(extensions.maxDebugLoggedMessages);
 
197
}
 
198
 
 
199
void State::reset()
 
200
{
 
201
    for (TextureBindingMap::iterator bindingVec = mSamplerTextures.begin(); bindingVec != mSamplerTextures.end(); bindingVec++)
 
202
    {
 
203
        TextureBindingVector &textureVector = bindingVec->second;
 
204
        for (size_t textureIdx = 0; textureIdx < textureVector.size(); textureIdx++)
 
205
        {
 
206
            textureVector[textureIdx].set(NULL);
 
207
        }
 
208
    }
 
209
    for (size_t samplerIdx = 0; samplerIdx < mSamplers.size(); samplerIdx++)
 
210
    {
 
211
        mSamplers[samplerIdx].set(NULL);
 
212
    }
 
213
 
 
214
    mArrayBuffer.set(NULL);
 
215
    mRenderbuffer.set(NULL);
 
216
 
 
217
    if (mProgram)
 
218
    {
 
219
        mProgram->release();
 
220
    }
 
221
    mProgram = NULL;
 
222
 
 
223
    mTransformFeedback.set(NULL);
 
224
 
 
225
    for (State::ActiveQueryMap::iterator i = mActiveQueries.begin(); i != mActiveQueries.end(); i++)
 
226
    {
 
227
        i->second.set(NULL);
 
228
    }
 
229
 
 
230
    mGenericUniformBuffer.set(NULL);
 
231
    for (BufferVector::iterator bufItr = mUniformBuffers.begin(); bufItr != mUniformBuffers.end(); ++bufItr)
 
232
    {
 
233
        bufItr->set(NULL);
 
234
    }
 
235
 
 
236
    mCopyReadBuffer.set(NULL);
 
237
    mCopyWriteBuffer.set(NULL);
 
238
 
 
239
    mPack.pixelBuffer.set(NULL);
 
240
    mUnpack.pixelBuffer.set(NULL);
 
241
 
 
242
    mProgram = NULL;
 
243
 
 
244
    // TODO(jmadill): Is this necessary?
 
245
    setAllDirtyBits();
 
246
}
 
247
 
 
248
const RasterizerState &State::getRasterizerState() const
 
249
{
 
250
    return mRasterizer;
 
251
}
 
252
 
 
253
const BlendState &State::getBlendState() const
 
254
{
 
255
    return mBlend;
 
256
}
 
257
 
 
258
const DepthStencilState &State::getDepthStencilState() const
 
259
{
 
260
    return mDepthStencil;
 
261
}
 
262
 
 
263
void State::setColorClearValue(float red, float green, float blue, float alpha)
 
264
{
 
265
    mColorClearValue.red = red;
 
266
    mColorClearValue.green = green;
 
267
    mColorClearValue.blue = blue;
 
268
    mColorClearValue.alpha = alpha;
 
269
    mDirtyBits.set(DIRTY_BIT_CLEAR_COLOR);
 
270
}
 
271
 
 
272
void State::setDepthClearValue(float depth)
 
273
{
 
274
    mDepthClearValue = depth;
 
275
    mDirtyBits.set(DIRTY_BIT_CLEAR_DEPTH);
 
276
}
 
277
 
 
278
void State::setStencilClearValue(int stencil)
 
279
{
 
280
    mStencilClearValue = stencil;
 
281
    mDirtyBits.set(DIRTY_BIT_CLEAR_STENCIL);
 
282
}
 
283
 
 
284
void State::setColorMask(bool red, bool green, bool blue, bool alpha)
 
285
{
 
286
    mBlend.colorMaskRed = red;
 
287
    mBlend.colorMaskGreen = green;
 
288
    mBlend.colorMaskBlue = blue;
 
289
    mBlend.colorMaskAlpha = alpha;
 
290
    mDirtyBits.set(DIRTY_BIT_COLOR_MASK);
 
291
}
 
292
 
 
293
void State::setDepthMask(bool mask)
 
294
{
 
295
    mDepthStencil.depthMask = mask;
 
296
    mDirtyBits.set(DIRTY_BIT_DEPTH_MASK);
 
297
}
 
298
 
 
299
bool State::isRasterizerDiscardEnabled() const
 
300
{
 
301
    return mRasterizer.rasterizerDiscard;
 
302
}
 
303
 
 
304
void State::setRasterizerDiscard(bool enabled)
 
305
{
 
306
    mRasterizer.rasterizerDiscard = enabled;
 
307
    mDirtyBits.set(DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
 
308
}
 
309
 
 
310
bool State::isCullFaceEnabled() const
 
311
{
 
312
    return mRasterizer.cullFace;
 
313
}
 
314
 
 
315
void State::setCullFace(bool enabled)
 
316
{
 
317
    mRasterizer.cullFace = enabled;
 
318
    mDirtyBits.set(DIRTY_BIT_CULL_FACE_ENABLED);
 
319
}
 
320
 
 
321
void State::setCullMode(GLenum mode)
 
322
{
 
323
    mRasterizer.cullMode = mode;
 
324
    mDirtyBits.set(DIRTY_BIT_CULL_FACE);
 
325
}
 
326
 
 
327
void State::setFrontFace(GLenum front)
 
328
{
 
329
    mRasterizer.frontFace = front;
 
330
    mDirtyBits.set(DIRTY_BIT_FRONT_FACE);
 
331
}
 
332
 
 
333
bool State::isDepthTestEnabled() const
 
334
{
 
335
    return mDepthStencil.depthTest;
 
336
}
 
337
 
 
338
void State::setDepthTest(bool enabled)
 
339
{
 
340
    mDepthStencil.depthTest = enabled;
 
341
    mDirtyBits.set(DIRTY_BIT_DEPTH_TEST_ENABLED);
 
342
}
 
343
 
 
344
void State::setDepthFunc(GLenum depthFunc)
 
345
{
 
346
     mDepthStencil.depthFunc = depthFunc;
 
347
     mDirtyBits.set(DIRTY_BIT_DEPTH_FUNC);
 
348
}
 
349
 
 
350
void State::setDepthRange(float zNear, float zFar)
 
351
{
 
352
    mNearZ = zNear;
 
353
    mFarZ = zFar;
 
354
    mDirtyBits.set(DIRTY_BIT_DEPTH_RANGE);
 
355
}
 
356
 
 
357
float State::getNearPlane() const
 
358
{
 
359
    return mNearZ;
 
360
}
 
361
 
 
362
float State::getFarPlane() const
 
363
{
 
364
    return mFarZ;
 
365
}
 
366
 
 
367
bool State::isBlendEnabled() const
 
368
{
 
369
    return mBlend.blend;
 
370
}
 
371
 
 
372
void State::setBlend(bool enabled)
 
373
{
 
374
    mBlend.blend = enabled;
 
375
    mDirtyBits.set(DIRTY_BIT_BLEND_ENABLED);
 
376
}
 
377
 
 
378
void State::setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha)
 
379
{
 
380
    mBlend.sourceBlendRGB = sourceRGB;
 
381
    mBlend.destBlendRGB = destRGB;
 
382
    mBlend.sourceBlendAlpha = sourceAlpha;
 
383
    mBlend.destBlendAlpha = destAlpha;
 
384
    mDirtyBits.set(DIRTY_BIT_BLEND_FUNCS);
 
385
}
 
386
 
 
387
void State::setBlendColor(float red, float green, float blue, float alpha)
 
388
{
 
389
    mBlendColor.red = red;
 
390
    mBlendColor.green = green;
 
391
    mBlendColor.blue = blue;
 
392
    mBlendColor.alpha = alpha;
 
393
    mDirtyBits.set(DIRTY_BIT_BLEND_COLOR);
 
394
}
 
395
 
 
396
void State::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation)
 
397
{
 
398
    mBlend.blendEquationRGB = rgbEquation;
 
399
    mBlend.blendEquationAlpha = alphaEquation;
 
400
    mDirtyBits.set(DIRTY_BIT_BLEND_EQUATIONS);
 
401
}
 
402
 
 
403
const ColorF &State::getBlendColor() const
 
404
{
 
405
    return mBlendColor;
 
406
}
 
407
 
 
408
bool State::isStencilTestEnabled() const
 
409
{
 
410
    return mDepthStencil.stencilTest;
 
411
}
 
412
 
 
413
void State::setStencilTest(bool enabled)
 
414
{
 
415
    mDepthStencil.stencilTest = enabled;
 
416
    mDirtyBits.set(DIRTY_BIT_STENCIL_TEST_ENABLED);
 
417
}
 
418
 
 
419
void State::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask)
 
420
{
 
421
    mDepthStencil.stencilFunc = stencilFunc;
 
422
    mStencilRef = (stencilRef > 0) ? stencilRef : 0;
 
423
    mDepthStencil.stencilMask = stencilMask;
 
424
    mDirtyBits.set(DIRTY_BIT_STENCIL_FUNCS_FRONT);
 
425
}
 
426
 
 
427
void State::setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask)
 
428
{
 
429
    mDepthStencil.stencilBackFunc = stencilBackFunc;
 
430
    mStencilBackRef = (stencilBackRef > 0) ? stencilBackRef : 0;
 
431
    mDepthStencil.stencilBackMask = stencilBackMask;
 
432
    mDirtyBits.set(DIRTY_BIT_STENCIL_FUNCS_BACK);
 
433
}
 
434
 
 
435
void State::setStencilWritemask(GLuint stencilWritemask)
 
436
{
 
437
    mDepthStencil.stencilWritemask = stencilWritemask;
 
438
    mDirtyBits.set(DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
 
439
}
 
440
 
 
441
void State::setStencilBackWritemask(GLuint stencilBackWritemask)
 
442
{
 
443
    mDepthStencil.stencilBackWritemask = stencilBackWritemask;
 
444
    mDirtyBits.set(DIRTY_BIT_STENCIL_WRITEMASK_BACK);
 
445
}
 
446
 
 
447
void State::setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass)
 
448
{
 
449
    mDepthStencil.stencilFail = stencilFail;
 
450
    mDepthStencil.stencilPassDepthFail = stencilPassDepthFail;
 
451
    mDepthStencil.stencilPassDepthPass = stencilPassDepthPass;
 
452
    mDirtyBits.set(DIRTY_BIT_STENCIL_OPS_FRONT);
 
453
}
 
454
 
 
455
void State::setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass)
 
456
{
 
457
    mDepthStencil.stencilBackFail = stencilBackFail;
 
458
    mDepthStencil.stencilBackPassDepthFail = stencilBackPassDepthFail;
 
459
    mDepthStencil.stencilBackPassDepthPass = stencilBackPassDepthPass;
 
460
    mDirtyBits.set(DIRTY_BIT_STENCIL_OPS_BACK);
 
461
}
 
462
 
 
463
GLint State::getStencilRef() const
 
464
{
 
465
    return mStencilRef;
 
466
}
 
467
 
 
468
GLint State::getStencilBackRef() const
 
469
{
 
470
    return mStencilBackRef;
 
471
}
 
472
 
 
473
bool State::isPolygonOffsetFillEnabled() const
 
474
{
 
475
    return mRasterizer.polygonOffsetFill;
 
476
}
 
477
 
 
478
void State::setPolygonOffsetFill(bool enabled)
 
479
{
 
480
    mRasterizer.polygonOffsetFill = enabled;
 
481
    mDirtyBits.set(DIRTY_BIT_POLYGON_OFFSET_FILL_ENABLED);
 
482
}
 
483
 
 
484
void State::setPolygonOffsetParams(GLfloat factor, GLfloat units)
 
485
{
 
486
    // An application can pass NaN values here, so handle this gracefully
 
487
    mRasterizer.polygonOffsetFactor = factor != factor ? 0.0f : factor;
 
488
    mRasterizer.polygonOffsetUnits = units != units ? 0.0f : units;
 
489
    mDirtyBits.set(DIRTY_BIT_POLYGON_OFFSET);
 
490
}
 
491
 
 
492
bool State::isSampleAlphaToCoverageEnabled() const
 
493
{
 
494
    return mBlend.sampleAlphaToCoverage;
 
495
}
 
496
 
 
497
void State::setSampleAlphaToCoverage(bool enabled)
 
498
{
 
499
    mBlend.sampleAlphaToCoverage = enabled;
 
500
    mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED);
 
501
}
 
502
 
 
503
bool State::isSampleCoverageEnabled() const
 
504
{
 
505
    return mSampleCoverage;
 
506
}
 
507
 
 
508
void State::setSampleCoverage(bool enabled)
 
509
{
 
510
    mSampleCoverage = enabled;
 
511
    mDirtyBits.set(DIRTY_BIT_SAMPLE_COVERAGE_ENABLED);
 
512
}
 
513
 
 
514
void State::setSampleCoverageParams(GLclampf value, bool invert)
 
515
{
 
516
    mSampleCoverageValue = value;
 
517
    mSampleCoverageInvert = invert;
 
518
    mDirtyBits.set(DIRTY_BIT_SAMPLE_COVERAGE);
 
519
}
 
520
 
 
521
GLclampf State::getSampleCoverageValue() const
 
522
{
 
523
    return mSampleCoverageValue;
 
524
}
 
525
 
 
526
bool State::getSampleCoverageInvert() const
 
527
{
 
528
    return mSampleCoverageInvert;
 
529
}
 
530
 
 
531
bool State::isScissorTestEnabled() const
 
532
{
 
533
    return mScissorTest;
 
534
}
 
535
 
 
536
void State::setScissorTest(bool enabled)
 
537
{
 
538
    mScissorTest = enabled;
 
539
    mDirtyBits.set(DIRTY_BIT_SCISSOR_TEST_ENABLED);
 
540
}
 
541
 
 
542
void State::setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height)
 
543
{
 
544
    mScissor.x = x;
 
545
    mScissor.y = y;
 
546
    mScissor.width = width;
 
547
    mScissor.height = height;
 
548
    mDirtyBits.set(DIRTY_BIT_SCISSOR);
 
549
}
 
550
 
 
551
const Rectangle &State::getScissor() const
 
552
{
 
553
    return mScissor;
 
554
}
 
555
 
 
556
bool State::isDitherEnabled() const
 
557
{
 
558
    return mBlend.dither;
 
559
}
 
560
 
 
561
void State::setDither(bool enabled)
 
562
{
 
563
    mBlend.dither = enabled;
 
564
    mDirtyBits.set(DIRTY_BIT_DITHER_ENABLED);
 
565
}
 
566
 
 
567
bool State::isPrimitiveRestartEnabled() const
 
568
{
 
569
    return mPrimitiveRestart;
 
570
}
 
571
 
 
572
void State::setPrimitiveRestart(bool enabled)
 
573
{
 
574
    mPrimitiveRestart = enabled;
 
575
    mDirtyBits.set(DIRTY_BIT_PRIMITIVE_RESTART_ENABLED);
 
576
}
 
577
 
 
578
void State::setEnableFeature(GLenum feature, bool enabled)
 
579
{
 
580
    switch (feature)
 
581
    {
 
582
      case GL_CULL_FACE:                     setCullFace(enabled);              break;
 
583
      case GL_POLYGON_OFFSET_FILL:           setPolygonOffsetFill(enabled);     break;
 
584
      case GL_SAMPLE_ALPHA_TO_COVERAGE:      setSampleAlphaToCoverage(enabled); break;
 
585
      case GL_SAMPLE_COVERAGE:               setSampleCoverage(enabled);        break;
 
586
      case GL_SCISSOR_TEST:                  setScissorTest(enabled);           break;
 
587
      case GL_STENCIL_TEST:                  setStencilTest(enabled);           break;
 
588
      case GL_DEPTH_TEST:                    setDepthTest(enabled);             break;
 
589
      case GL_BLEND:                         setBlend(enabled);                 break;
 
590
      case GL_DITHER:                        setDither(enabled);                break;
 
591
      case GL_PRIMITIVE_RESTART_FIXED_INDEX: setPrimitiveRestart(enabled);      break;
 
592
      case GL_RASTERIZER_DISCARD:            setRasterizerDiscard(enabled);     break;
 
593
      case GL_DEBUG_OUTPUT_SYNCHRONOUS:
 
594
          mDebug.setOutputSynchronous(enabled);
 
595
          break;
 
596
      case GL_DEBUG_OUTPUT:
 
597
          mDebug.setOutputEnabled(enabled);
 
598
          break;
 
599
      default:                               UNREACHABLE();
 
600
    }
 
601
}
 
602
 
 
603
bool State::getEnableFeature(GLenum feature)
 
604
{
 
605
    switch (feature)
 
606
    {
 
607
      case GL_CULL_FACE:                     return isCullFaceEnabled();
 
608
      case GL_POLYGON_OFFSET_FILL:           return isPolygonOffsetFillEnabled();
 
609
      case GL_SAMPLE_ALPHA_TO_COVERAGE:      return isSampleAlphaToCoverageEnabled();
 
610
      case GL_SAMPLE_COVERAGE:               return isSampleCoverageEnabled();
 
611
      case GL_SCISSOR_TEST:                  return isScissorTestEnabled();
 
612
      case GL_STENCIL_TEST:                  return isStencilTestEnabled();
 
613
      case GL_DEPTH_TEST:                    return isDepthTestEnabled();
 
614
      case GL_BLEND:                         return isBlendEnabled();
 
615
      case GL_DITHER:                        return isDitherEnabled();
 
616
      case GL_PRIMITIVE_RESTART_FIXED_INDEX: return isPrimitiveRestartEnabled();
 
617
      case GL_RASTERIZER_DISCARD:            return isRasterizerDiscardEnabled();
 
618
      case GL_DEBUG_OUTPUT_SYNCHRONOUS:
 
619
          return mDebug.isOutputSynchronous();
 
620
      case GL_DEBUG_OUTPUT:
 
621
          return mDebug.isOutputEnabled();
 
622
      default:                               UNREACHABLE(); return false;
 
623
    }
 
624
}
 
625
 
 
626
void State::setLineWidth(GLfloat width)
 
627
{
 
628
    mLineWidth = width;
 
629
    mDirtyBits.set(DIRTY_BIT_LINE_WIDTH);
 
630
}
 
631
 
 
632
float State::getLineWidth() const
 
633
{
 
634
    return mLineWidth;
 
635
}
 
636
 
 
637
void State::setGenerateMipmapHint(GLenum hint)
 
638
{
 
639
    mGenerateMipmapHint = hint;
 
640
    mDirtyBits.set(DIRTY_BIT_GENERATE_MIPMAP_HINT);
 
641
}
 
642
 
 
643
void State::setFragmentShaderDerivativeHint(GLenum hint)
 
644
{
 
645
    mFragmentShaderDerivativeHint = hint;
 
646
    mDirtyBits.set(DIRTY_BIT_SHADER_DERIVATIVE_HINT);
 
647
    // TODO: Propagate the hint to shader translator so we can write
 
648
    // ddx, ddx_coarse, or ddx_fine depending on the hint.
 
649
    // Ignore for now. It is valid for implementations to ignore hint.
 
650
}
 
651
 
 
652
void State::setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height)
 
653
{
 
654
    mViewport.x = x;
 
655
    mViewport.y = y;
 
656
    mViewport.width = width;
 
657
    mViewport.height = height;
 
658
    mDirtyBits.set(DIRTY_BIT_VIEWPORT);
 
659
}
 
660
 
 
661
const Rectangle &State::getViewport() const
 
662
{
 
663
    return mViewport;
 
664
}
 
665
 
 
666
void State::setActiveSampler(unsigned int active)
 
667
{
 
668
    mActiveSampler = active;
 
669
}
 
670
 
 
671
unsigned int State::getActiveSampler() const
 
672
{
 
673
    return static_cast<unsigned int>(mActiveSampler);
 
674
}
 
675
 
 
676
void State::setSamplerTexture(GLenum type, Texture *texture)
 
677
{
 
678
    mSamplerTextures[type][mActiveSampler].set(texture);
 
679
}
 
680
 
 
681
Texture *State::getTargetTexture(GLenum target) const
 
682
{
 
683
    return getSamplerTexture(static_cast<unsigned int>(mActiveSampler), target);
 
684
}
 
685
 
 
686
Texture *State::getSamplerTexture(unsigned int sampler, GLenum type) const
 
687
{
 
688
    const auto it = mSamplerTextures.find(type);
 
689
    ASSERT(it != mSamplerTextures.end());
 
690
    ASSERT(sampler < it->second.size());
 
691
    return it->second[sampler].get();
 
692
}
 
693
 
 
694
GLuint State::getSamplerTextureId(unsigned int sampler, GLenum type) const
 
695
{
 
696
    const auto it = mSamplerTextures.find(type);
 
697
    ASSERT(it != mSamplerTextures.end());
 
698
    ASSERT(sampler < it->second.size());
 
699
    return it->second[sampler].id();
 
700
}
 
701
 
 
702
void State::detachTexture(const TextureMap &zeroTextures, GLuint texture)
 
703
{
 
704
    // Textures have a detach method on State rather than a simple
 
705
    // removeBinding, because the zero/null texture objects are managed
 
706
    // separately, and don't have to go through the Context's maps or
 
707
    // the ResourceManager.
 
708
 
 
709
    // [OpenGL ES 2.0.24] section 3.8 page 84:
 
710
    // If a texture object is deleted, it is as if all texture units which are bound to that texture object are
 
711
    // rebound to texture object zero
 
712
 
 
713
    for (TextureBindingMap::iterator bindingVec = mSamplerTextures.begin(); bindingVec != mSamplerTextures.end(); bindingVec++)
 
714
    {
 
715
        GLenum textureType = bindingVec->first;
 
716
        TextureBindingVector &textureVector = bindingVec->second;
 
717
        for (size_t textureIdx = 0; textureIdx < textureVector.size(); textureIdx++)
 
718
        {
 
719
            BindingPointer<Texture> &binding = textureVector[textureIdx];
 
720
            if (binding.id() == texture)
 
721
            {
 
722
                auto it = zeroTextures.find(textureType);
 
723
                ASSERT(it != zeroTextures.end());
 
724
                // Zero textures are the "default" textures instead of NULL
 
725
                binding.set(it->second.get());
 
726
            }
 
727
        }
 
728
    }
 
729
 
 
730
    // [OpenGL ES 2.0.24] section 4.4 page 112:
 
731
    // If a texture object is deleted while its image is attached to the currently bound framebuffer, then it is
 
732
    // as if Texture2DAttachment had been called, with a texture of 0, for each attachment point to which this
 
733
    // image was attached in the currently bound framebuffer.
 
734
 
 
735
    if (mReadFramebuffer)
 
736
    {
 
737
        mReadFramebuffer->detachTexture(texture);
 
738
    }
 
739
 
 
740
    if (mDrawFramebuffer)
 
741
    {
 
742
        mDrawFramebuffer->detachTexture(texture);
 
743
    }
 
744
}
 
745
 
 
746
void State::initializeZeroTextures(const TextureMap &zeroTextures)
 
747
{
 
748
    for (const auto &zeroTexture : zeroTextures)
 
749
    {
 
750
        auto &samplerTextureArray = mSamplerTextures[zeroTexture.first];
 
751
 
 
752
        for (size_t textureUnit = 0; textureUnit < samplerTextureArray.size(); ++textureUnit)
 
753
        {
 
754
            samplerTextureArray[textureUnit].set(zeroTexture.second.get());
 
755
        }
 
756
    }
 
757
}
 
758
 
 
759
void State::setSamplerBinding(GLuint textureUnit, Sampler *sampler)
 
760
{
 
761
    mSamplers[textureUnit].set(sampler);
 
762
}
 
763
 
 
764
GLuint State::getSamplerId(GLuint textureUnit) const
 
765
{
 
766
    ASSERT(textureUnit < mSamplers.size());
 
767
    return mSamplers[textureUnit].id();
 
768
}
 
769
 
 
770
Sampler *State::getSampler(GLuint textureUnit) const
 
771
{
 
772
    return mSamplers[textureUnit].get();
 
773
}
 
774
 
 
775
void State::detachSampler(GLuint sampler)
 
776
{
 
777
    // [OpenGL ES 3.0.2] section 3.8.2 pages 123-124:
 
778
    // If a sampler object that is currently bound to one or more texture units is
 
779
    // deleted, it is as though BindSampler is called once for each texture unit to
 
780
    // which the sampler is bound, with unit set to the texture unit and sampler set to zero.
 
781
    for (size_t textureUnit = 0; textureUnit < mSamplers.size(); textureUnit++)
 
782
    {
 
783
        BindingPointer<Sampler> &samplerBinding = mSamplers[textureUnit];
 
784
        if (samplerBinding.id() == sampler)
 
785
        {
 
786
            samplerBinding.set(NULL);
 
787
        }
 
788
    }
 
789
}
 
790
 
 
791
void State::setRenderbufferBinding(Renderbuffer *renderbuffer)
 
792
{
 
793
    mRenderbuffer.set(renderbuffer);
 
794
}
 
795
 
 
796
GLuint State::getRenderbufferId() const
 
797
{
 
798
    return mRenderbuffer.id();
 
799
}
 
800
 
 
801
Renderbuffer *State::getCurrentRenderbuffer()
 
802
{
 
803
    return mRenderbuffer.get();
 
804
}
 
805
 
 
806
void State::detachRenderbuffer(GLuint renderbuffer)
 
807
{
 
808
    // [OpenGL ES 2.0.24] section 4.4 page 109:
 
809
    // If a renderbuffer that is currently bound to RENDERBUFFER is deleted, it is as though BindRenderbuffer
 
810
    // had been executed with the target RENDERBUFFER and name of zero.
 
811
 
 
812
    if (mRenderbuffer.id() == renderbuffer)
 
813
    {
 
814
        mRenderbuffer.set(NULL);
 
815
    }
 
816
 
 
817
    // [OpenGL ES 2.0.24] section 4.4 page 111:
 
818
    // If a renderbuffer object is deleted while its image is attached to the currently bound framebuffer,
 
819
    // then it is as if FramebufferRenderbuffer had been called, with a renderbuffer of 0, for each attachment
 
820
    // point to which this image was attached in the currently bound framebuffer.
 
821
 
 
822
    Framebuffer *readFramebuffer = mReadFramebuffer;
 
823
    Framebuffer *drawFramebuffer = mDrawFramebuffer;
 
824
 
 
825
    if (readFramebuffer)
 
826
    {
 
827
        readFramebuffer->detachRenderbuffer(renderbuffer);
 
828
    }
 
829
 
 
830
    if (drawFramebuffer && drawFramebuffer != readFramebuffer)
 
831
    {
 
832
        drawFramebuffer->detachRenderbuffer(renderbuffer);
 
833
    }
 
834
 
 
835
}
 
836
 
 
837
void State::setReadFramebufferBinding(Framebuffer *framebuffer)
 
838
{
 
839
    if (mReadFramebuffer == framebuffer)
 
840
        return;
 
841
 
 
842
    mReadFramebuffer = framebuffer;
 
843
    mDirtyBits.set(DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
 
844
 
 
845
    if (mReadFramebuffer && mReadFramebuffer->hasAnyDirtyBit())
 
846
    {
 
847
        mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
 
848
    }
 
849
}
 
850
 
 
851
void State::setDrawFramebufferBinding(Framebuffer *framebuffer)
 
852
{
 
853
    if (mDrawFramebuffer == framebuffer)
 
854
        return;
 
855
 
 
856
    mDrawFramebuffer = framebuffer;
 
857
    mDirtyBits.set(DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
 
858
 
 
859
    if (mDrawFramebuffer && mDrawFramebuffer->hasAnyDirtyBit())
 
860
    {
 
861
        mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
 
862
    }
 
863
}
 
864
 
 
865
Framebuffer *State::getTargetFramebuffer(GLenum target) const
 
866
{
 
867
    switch (target)
 
868
    {
 
869
        case GL_READ_FRAMEBUFFER_ANGLE:
 
870
            return mReadFramebuffer;
 
871
        case GL_DRAW_FRAMEBUFFER_ANGLE:
 
872
        case GL_FRAMEBUFFER:
 
873
            return mDrawFramebuffer;
 
874
        default:
 
875
            UNREACHABLE();
 
876
            return NULL;
 
877
    }
 
878
}
 
879
 
 
880
Framebuffer *State::getReadFramebuffer()
 
881
{
 
882
    return mReadFramebuffer;
 
883
}
 
884
 
 
885
Framebuffer *State::getDrawFramebuffer()
 
886
{
 
887
    return mDrawFramebuffer;
 
888
}
 
889
 
 
890
const Framebuffer *State::getReadFramebuffer() const
 
891
{
 
892
    return mReadFramebuffer;
 
893
}
 
894
 
 
895
const Framebuffer *State::getDrawFramebuffer() const
 
896
{
 
897
    return mDrawFramebuffer;
 
898
}
 
899
 
 
900
bool State::removeReadFramebufferBinding(GLuint framebuffer)
 
901
{
 
902
    if (mReadFramebuffer != nullptr &&
 
903
        mReadFramebuffer->id() == framebuffer)
 
904
    {
 
905
        setReadFramebufferBinding(nullptr);
 
906
        return true;
 
907
    }
 
908
 
 
909
    return false;
 
910
}
 
911
 
 
912
bool State::removeDrawFramebufferBinding(GLuint framebuffer)
 
913
{
 
914
    if (mReadFramebuffer != nullptr &&
 
915
        mDrawFramebuffer->id() == framebuffer)
 
916
    {
 
917
        setDrawFramebufferBinding(nullptr);
 
918
        return true;
 
919
    }
 
920
 
 
921
    return false;
 
922
}
 
923
 
 
924
void State::setVertexArrayBinding(VertexArray *vertexArray)
 
925
{
 
926
    mVertexArray = vertexArray;
 
927
    mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING);
 
928
 
 
929
    if (mVertexArray && mVertexArray->hasAnyDirtyBit())
 
930
    {
 
931
        mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
 
932
    }
 
933
}
 
934
 
 
935
GLuint State::getVertexArrayId() const
 
936
{
 
937
    ASSERT(mVertexArray != NULL);
 
938
    return mVertexArray->id();
 
939
}
 
940
 
 
941
VertexArray *State::getVertexArray() const
 
942
{
 
943
    ASSERT(mVertexArray != NULL);
 
944
    return mVertexArray;
 
945
}
 
946
 
 
947
bool State::removeVertexArrayBinding(GLuint vertexArray)
 
948
{
 
949
    if (mVertexArray->id() == vertexArray)
 
950
    {
 
951
        mVertexArray = NULL;
 
952
        mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING);
 
953
        mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
 
954
        return true;
 
955
    }
 
956
 
 
957
    return false;
 
958
}
 
959
 
 
960
void State::setProgram(Program *newProgram)
 
961
{
 
962
    if (mProgram != newProgram)
 
963
    {
 
964
        if (mProgram)
 
965
        {
 
966
            mProgram->release();
 
967
        }
 
968
 
 
969
        mProgram = newProgram;
 
970
 
 
971
        if (mProgram)
 
972
        {
 
973
            newProgram->addRef();
 
974
        }
 
975
    }
 
976
}
 
977
 
 
978
Program *State::getProgram() const
 
979
{
 
980
    return mProgram;
 
981
}
 
982
 
 
983
void State::setTransformFeedbackBinding(TransformFeedback *transformFeedback)
 
984
{
 
985
    mTransformFeedback.set(transformFeedback);
 
986
}
 
987
 
 
988
TransformFeedback *State::getCurrentTransformFeedback() const
 
989
{
 
990
    return mTransformFeedback.get();
 
991
}
 
992
 
 
993
bool State::isTransformFeedbackActiveUnpaused() const
 
994
{
 
995
    gl::TransformFeedback *curTransformFeedback = getCurrentTransformFeedback();
 
996
    return curTransformFeedback && curTransformFeedback->isActive() && !curTransformFeedback->isPaused();
 
997
}
 
998
 
 
999
void State::detachTransformFeedback(GLuint transformFeedback)
 
1000
{
 
1001
    if (mTransformFeedback.id() == transformFeedback)
 
1002
    {
 
1003
        mTransformFeedback.set(NULL);
 
1004
    }
 
1005
}
 
1006
 
 
1007
bool State::isQueryActive() const
 
1008
{
 
1009
    for (auto &iter : mActiveQueries)
 
1010
    {
 
1011
        if (iter.second.get() != NULL)
 
1012
        {
 
1013
            return true;
 
1014
        }
 
1015
    }
 
1016
 
 
1017
    return false;
 
1018
}
 
1019
 
 
1020
bool State::isQueryActive(Query *query) const
 
1021
{
 
1022
    for (auto &iter : mActiveQueries)
 
1023
    {
 
1024
        if (iter.second.get() == query)
 
1025
        {
 
1026
            return true;
 
1027
        }
 
1028
    }
 
1029
 
 
1030
    return false;
 
1031
}
 
1032
 
 
1033
void State::setActiveQuery(GLenum target, Query *query)
 
1034
{
 
1035
    mActiveQueries[target].set(query);
 
1036
}
 
1037
 
 
1038
GLuint State::getActiveQueryId(GLenum target) const
 
1039
{
 
1040
    const Query *query = getActiveQuery(target);
 
1041
    return (query ? query->id() : 0u);
 
1042
}
 
1043
 
 
1044
Query *State::getActiveQuery(GLenum target) const
 
1045
{
 
1046
    const auto it = mActiveQueries.find(target);
 
1047
 
 
1048
    // All query types should already exist in the activeQueries map
 
1049
    ASSERT(it != mActiveQueries.end());
 
1050
 
 
1051
    return it->second.get();
 
1052
}
 
1053
 
 
1054
void State::setArrayBufferBinding(Buffer *buffer)
 
1055
{
 
1056
    mArrayBuffer.set(buffer);
 
1057
}
 
1058
 
 
1059
GLuint State::getArrayBufferId() const
 
1060
{
 
1061
    return mArrayBuffer.id();
 
1062
}
 
1063
 
 
1064
void State::setGenericUniformBufferBinding(Buffer *buffer)
 
1065
{
 
1066
    mGenericUniformBuffer.set(buffer);
 
1067
}
 
1068
 
 
1069
void State::setIndexedUniformBufferBinding(GLuint index, Buffer *buffer, GLintptr offset, GLsizeiptr size)
 
1070
{
 
1071
    mUniformBuffers[index].set(buffer, offset, size);
 
1072
}
 
1073
 
 
1074
const OffsetBindingPointer<Buffer> &State::getIndexedUniformBuffer(size_t index) const
 
1075
{
 
1076
    ASSERT(static_cast<size_t>(index) < mUniformBuffers.size());
 
1077
    return mUniformBuffers[index];
 
1078
}
 
1079
 
 
1080
void State::setCopyReadBufferBinding(Buffer *buffer)
 
1081
{
 
1082
    mCopyReadBuffer.set(buffer);
 
1083
}
 
1084
 
 
1085
void State::setCopyWriteBufferBinding(Buffer *buffer)
 
1086
{
 
1087
    mCopyWriteBuffer.set(buffer);
 
1088
}
 
1089
 
 
1090
void State::setPixelPackBufferBinding(Buffer *buffer)
 
1091
{
 
1092
    mPack.pixelBuffer.set(buffer);
 
1093
}
 
1094
 
 
1095
void State::setPixelUnpackBufferBinding(Buffer *buffer)
 
1096
{
 
1097
    mUnpack.pixelBuffer.set(buffer);
 
1098
}
 
1099
 
 
1100
Buffer *State::getTargetBuffer(GLenum target) const
 
1101
{
 
1102
    switch (target)
 
1103
    {
 
1104
      case GL_ARRAY_BUFFER:              return mArrayBuffer.get();
 
1105
      case GL_COPY_READ_BUFFER:          return mCopyReadBuffer.get();
 
1106
      case GL_COPY_WRITE_BUFFER:         return mCopyWriteBuffer.get();
 
1107
      case GL_ELEMENT_ARRAY_BUFFER:      return getVertexArray()->getElementArrayBuffer().get();
 
1108
      case GL_PIXEL_PACK_BUFFER:         return mPack.pixelBuffer.get();
 
1109
      case GL_PIXEL_UNPACK_BUFFER:       return mUnpack.pixelBuffer.get();
 
1110
      case GL_TRANSFORM_FEEDBACK_BUFFER: return mTransformFeedback->getGenericBuffer().get();
 
1111
      case GL_UNIFORM_BUFFER:            return mGenericUniformBuffer.get();
 
1112
      default: UNREACHABLE();            return NULL;
 
1113
    }
 
1114
}
 
1115
 
 
1116
void State::detachBuffer(GLuint bufferName)
 
1117
{
 
1118
    BindingPointer<Buffer> *buffers[] = {&mArrayBuffer,        &mCopyReadBuffer,
 
1119
                                         &mCopyWriteBuffer,    &mPack.pixelBuffer,
 
1120
                                         &mUnpack.pixelBuffer, &mGenericUniformBuffer};
 
1121
    for (auto buffer : buffers)
 
1122
    {
 
1123
        if (buffer->id() == bufferName)
 
1124
        {
 
1125
            buffer->set(nullptr);
 
1126
        }
 
1127
    }
 
1128
 
 
1129
    TransformFeedback *curTransformFeedback = getCurrentTransformFeedback();
 
1130
    if (curTransformFeedback)
 
1131
    {
 
1132
        curTransformFeedback->detachBuffer(bufferName);
 
1133
    }
 
1134
 
 
1135
    getVertexArray()->detachBuffer(bufferName);
 
1136
}
 
1137
 
 
1138
void State::setEnableVertexAttribArray(unsigned int attribNum, bool enabled)
 
1139
{
 
1140
    getVertexArray()->enableAttribute(attribNum, enabled);
 
1141
    mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
 
1142
}
 
1143
 
 
1144
void State::setVertexAttribf(GLuint index, const GLfloat values[4])
 
1145
{
 
1146
    ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size());
 
1147
    mVertexAttribCurrentValues[index].setFloatValues(values);
 
1148
    mDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_0 + index);
 
1149
}
 
1150
 
 
1151
void State::setVertexAttribu(GLuint index, const GLuint values[4])
 
1152
{
 
1153
    ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size());
 
1154
    mVertexAttribCurrentValues[index].setUnsignedIntValues(values);
 
1155
    mDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_0 + index);
 
1156
}
 
1157
 
 
1158
void State::setVertexAttribi(GLuint index, const GLint values[4])
 
1159
{
 
1160
    ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size());
 
1161
    mVertexAttribCurrentValues[index].setIntValues(values);
 
1162
    mDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_0 + index);
 
1163
}
 
1164
 
 
1165
void State::setVertexAttribState(unsigned int attribNum,
 
1166
                                 Buffer *boundBuffer,
 
1167
                                 GLint size,
 
1168
                                 GLenum type,
 
1169
                                 bool normalized,
 
1170
                                 bool pureInteger,
 
1171
                                 GLsizei stride,
 
1172
                                 const void *pointer)
 
1173
{
 
1174
    getVertexArray()->setAttributeState(attribNum, boundBuffer, size, type, normalized, pureInteger, stride, pointer);
 
1175
    mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
 
1176
}
 
1177
 
 
1178
void State::setVertexAttribDivisor(GLuint index, GLuint divisor)
 
1179
{
 
1180
    getVertexArray()->setVertexAttribDivisor(index, divisor);
 
1181
    mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
 
1182
}
 
1183
 
 
1184
const VertexAttribCurrentValueData &State::getVertexAttribCurrentValue(unsigned int attribNum) const
 
1185
{
 
1186
    ASSERT(static_cast<size_t>(attribNum) < mVertexAttribCurrentValues.size());
 
1187
    return mVertexAttribCurrentValues[attribNum];
 
1188
}
 
1189
 
 
1190
const void *State::getVertexAttribPointer(unsigned int attribNum) const
 
1191
{
 
1192
    return getVertexArray()->getVertexAttribute(attribNum).pointer;
 
1193
}
 
1194
 
 
1195
void State::setPackAlignment(GLint alignment)
 
1196
{
 
1197
    mPack.alignment = alignment;
 
1198
    mDirtyBits.set(DIRTY_BIT_PACK_ALIGNMENT);
 
1199
}
 
1200
 
 
1201
GLint State::getPackAlignment() const
 
1202
{
 
1203
    return mPack.alignment;
 
1204
}
 
1205
 
 
1206
void State::setPackReverseRowOrder(bool reverseRowOrder)
 
1207
{
 
1208
    mPack.reverseRowOrder = reverseRowOrder;
 
1209
    mDirtyBits.set(DIRTY_BIT_PACK_REVERSE_ROW_ORDER);
 
1210
}
 
1211
 
 
1212
bool State::getPackReverseRowOrder() const
 
1213
{
 
1214
    return mPack.reverseRowOrder;
 
1215
}
 
1216
 
 
1217
void State::setPackRowLength(GLint rowLength)
 
1218
{
 
1219
    mPack.rowLength = rowLength;
 
1220
    mDirtyBits.set(DIRTY_BIT_PACK_ROW_LENGTH);
 
1221
}
 
1222
 
 
1223
GLint State::getPackRowLength() const
 
1224
{
 
1225
    return mPack.rowLength;
 
1226
}
 
1227
 
 
1228
void State::setPackSkipRows(GLint skipRows)
 
1229
{
 
1230
    mPack.skipRows = skipRows;
 
1231
    mDirtyBits.set(DIRTY_BIT_PACK_SKIP_ROWS);
 
1232
}
 
1233
 
 
1234
GLint State::getPackSkipRows() const
 
1235
{
 
1236
    return mPack.skipRows;
 
1237
}
 
1238
 
 
1239
void State::setPackSkipPixels(GLint skipPixels)
 
1240
{
 
1241
    mPack.skipPixels = skipPixels;
 
1242
    mDirtyBits.set(DIRTY_BIT_PACK_SKIP_PIXELS);
 
1243
}
 
1244
 
 
1245
GLint State::getPackSkipPixels() const
 
1246
{
 
1247
    return mPack.skipPixels;
 
1248
}
 
1249
 
 
1250
const PixelPackState &State::getPackState() const
 
1251
{
 
1252
    return mPack;
 
1253
}
 
1254
 
 
1255
PixelPackState &State::getPackState()
 
1256
{
 
1257
    return mPack;
 
1258
}
 
1259
 
 
1260
void State::setUnpackAlignment(GLint alignment)
 
1261
{
 
1262
    mUnpack.alignment = alignment;
 
1263
    mDirtyBits.set(DIRTY_BIT_UNPACK_ALIGNMENT);
 
1264
}
 
1265
 
 
1266
GLint State::getUnpackAlignment() const
 
1267
{
 
1268
    return mUnpack.alignment;
 
1269
}
 
1270
 
 
1271
void State::setUnpackRowLength(GLint rowLength)
 
1272
{
 
1273
    mUnpack.rowLength = rowLength;
 
1274
    mDirtyBits.set(DIRTY_BIT_UNPACK_ROW_LENGTH);
 
1275
}
 
1276
 
 
1277
GLint State::getUnpackRowLength() const
 
1278
{
 
1279
    return mUnpack.rowLength;
 
1280
}
 
1281
 
 
1282
void State::setUnpackImageHeight(GLint imageHeight)
 
1283
{
 
1284
    mUnpack.imageHeight = imageHeight;
 
1285
    mDirtyBits.set(DIRTY_BIT_UNPACK_IMAGE_HEIGHT);
 
1286
}
 
1287
 
 
1288
GLint State::getUnpackImageHeight() const
 
1289
{
 
1290
    return mUnpack.imageHeight;
 
1291
}
 
1292
 
 
1293
void State::setUnpackSkipImages(GLint skipImages)
 
1294
{
 
1295
    mUnpack.skipImages = skipImages;
 
1296
    mDirtyBits.set(DIRTY_BIT_UNPACK_SKIP_IMAGES);
 
1297
}
 
1298
 
 
1299
GLint State::getUnpackSkipImages() const
 
1300
{
 
1301
    return mUnpack.skipImages;
 
1302
}
 
1303
 
 
1304
void State::setUnpackSkipRows(GLint skipRows)
 
1305
{
 
1306
    mUnpack.skipRows = skipRows;
 
1307
    mDirtyBits.set(DIRTY_BIT_UNPACK_SKIP_ROWS);
 
1308
}
 
1309
 
 
1310
GLint State::getUnpackSkipRows() const
 
1311
{
 
1312
    return mUnpack.skipRows;
 
1313
}
 
1314
 
 
1315
void State::setUnpackSkipPixels(GLint skipPixels)
 
1316
{
 
1317
    mUnpack.skipPixels = skipPixels;
 
1318
    mDirtyBits.set(DIRTY_BIT_UNPACK_SKIP_PIXELS);
 
1319
}
 
1320
 
 
1321
GLint State::getUnpackSkipPixels() const
 
1322
{
 
1323
    return mUnpack.skipPixels;
 
1324
}
 
1325
 
 
1326
const PixelUnpackState &State::getUnpackState() const
 
1327
{
 
1328
    return mUnpack;
 
1329
}
 
1330
 
 
1331
PixelUnpackState &State::getUnpackState()
 
1332
{
 
1333
    return mUnpack;
 
1334
}
 
1335
 
 
1336
const Debug &State::getDebug() const
 
1337
{
 
1338
    return mDebug;
 
1339
}
 
1340
 
 
1341
Debug &State::getDebug()
 
1342
{
 
1343
    return mDebug;
 
1344
}
 
1345
 
 
1346
void State::getBooleanv(GLenum pname, GLboolean *params)
 
1347
{
 
1348
    switch (pname)
 
1349
    {
 
1350
      case GL_SAMPLE_COVERAGE_INVERT:    *params = mSampleCoverageInvert;         break;
 
1351
      case GL_DEPTH_WRITEMASK:           *params = mDepthStencil.depthMask;       break;
 
1352
      case GL_COLOR_WRITEMASK:
 
1353
        params[0] = mBlend.colorMaskRed;
 
1354
        params[1] = mBlend.colorMaskGreen;
 
1355
        params[2] = mBlend.colorMaskBlue;
 
1356
        params[3] = mBlend.colorMaskAlpha;
 
1357
        break;
 
1358
      case GL_CULL_FACE:                 *params = mRasterizer.cullFace;          break;
 
1359
      case GL_POLYGON_OFFSET_FILL:       *params = mRasterizer.polygonOffsetFill; break;
 
1360
      case GL_SAMPLE_ALPHA_TO_COVERAGE:  *params = mBlend.sampleAlphaToCoverage;  break;
 
1361
      case GL_SAMPLE_COVERAGE:           *params = mSampleCoverage;               break;
 
1362
      case GL_SCISSOR_TEST:              *params = mScissorTest;                  break;
 
1363
      case GL_STENCIL_TEST:              *params = mDepthStencil.stencilTest;     break;
 
1364
      case GL_DEPTH_TEST:                *params = mDepthStencil.depthTest;       break;
 
1365
      case GL_BLEND:                     *params = mBlend.blend;                  break;
 
1366
      case GL_DITHER:                    *params = mBlend.dither;                 break;
 
1367
      case GL_TRANSFORM_FEEDBACK_ACTIVE: *params = getCurrentTransformFeedback()->isActive() ? GL_TRUE : GL_FALSE; break;
 
1368
      case GL_TRANSFORM_FEEDBACK_PAUSED: *params = getCurrentTransformFeedback()->isPaused() ? GL_TRUE : GL_FALSE; break;
 
1369
      case GL_PRIMITIVE_RESTART_FIXED_INDEX:
 
1370
          *params = mPrimitiveRestart;
 
1371
          break;
 
1372
      case GL_RASTERIZER_DISCARD:
 
1373
          *params = isRasterizerDiscardEnabled() ? GL_TRUE : GL_FALSE;
 
1374
          break;
 
1375
      case GL_DEBUG_OUTPUT_SYNCHRONOUS:
 
1376
          *params = mDebug.isOutputSynchronous() ? GL_TRUE : GL_FALSE;
 
1377
          break;
 
1378
      case GL_DEBUG_OUTPUT:
 
1379
          *params = mDebug.isOutputEnabled() ? GL_TRUE : GL_FALSE;
 
1380
          break;
 
1381
      default:
 
1382
        UNREACHABLE();
 
1383
        break;
 
1384
    }
 
1385
}
 
1386
 
 
1387
void State::getFloatv(GLenum pname, GLfloat *params)
 
1388
{
 
1389
    // Please note: DEPTH_CLEAR_VALUE is included in our internal getFloatv implementation
 
1390
    // because it is stored as a float, despite the fact that the GL ES 2.0 spec names
 
1391
    // GetIntegerv as its native query function. As it would require conversion in any
 
1392
    // case, this should make no difference to the calling application.
 
1393
    switch (pname)
 
1394
    {
 
1395
      case GL_LINE_WIDTH:               *params = mLineWidth;                         break;
 
1396
      case GL_SAMPLE_COVERAGE_VALUE:    *params = mSampleCoverageValue;               break;
 
1397
      case GL_DEPTH_CLEAR_VALUE:        *params = mDepthClearValue;                   break;
 
1398
      case GL_POLYGON_OFFSET_FACTOR:    *params = mRasterizer.polygonOffsetFactor;    break;
 
1399
      case GL_POLYGON_OFFSET_UNITS:     *params = mRasterizer.polygonOffsetUnits;     break;
 
1400
      case GL_DEPTH_RANGE:
 
1401
        params[0] = mNearZ;
 
1402
        params[1] = mFarZ;
 
1403
        break;
 
1404
      case GL_COLOR_CLEAR_VALUE:
 
1405
        params[0] = mColorClearValue.red;
 
1406
        params[1] = mColorClearValue.green;
 
1407
        params[2] = mColorClearValue.blue;
 
1408
        params[3] = mColorClearValue.alpha;
 
1409
        break;
 
1410
      case GL_BLEND_COLOR:
 
1411
        params[0] = mBlendColor.red;
 
1412
        params[1] = mBlendColor.green;
 
1413
        params[2] = mBlendColor.blue;
 
1414
        params[3] = mBlendColor.alpha;
 
1415
        break;
 
1416
      default:
 
1417
        UNREACHABLE();
 
1418
        break;
 
1419
    }
 
1420
}
 
1421
 
 
1422
void State::getIntegerv(const gl::Data &data, GLenum pname, GLint *params)
 
1423
{
 
1424
    if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
 
1425
    {
 
1426
        unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0_EXT);
 
1427
        ASSERT(colorAttachment < mMaxDrawBuffers);
 
1428
        Framebuffer *framebuffer = mDrawFramebuffer;
 
1429
        *params = framebuffer->getDrawBufferState(colorAttachment);
 
1430
        return;
 
1431
    }
 
1432
 
 
1433
    // Please note: DEPTH_CLEAR_VALUE is not included in our internal getIntegerv implementation
 
1434
    // because it is stored as a float, despite the fact that the GL ES 2.0 spec names
 
1435
    // GetIntegerv as its native query function. As it would require conversion in any
 
1436
    // case, this should make no difference to the calling application. You may find it in
 
1437
    // State::getFloatv.
 
1438
    switch (pname)
 
1439
    {
 
1440
      case GL_ARRAY_BUFFER_BINDING:                     *params = mArrayBuffer.id();                              break;
 
1441
      case GL_ELEMENT_ARRAY_BUFFER_BINDING:             *params = getVertexArray()->getElementArrayBuffer().id(); break;
 
1442
        //case GL_FRAMEBUFFER_BINDING:                    // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
 
1443
      case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE:           *params = mDrawFramebuffer->id();                         break;
 
1444
      case GL_READ_FRAMEBUFFER_BINDING_ANGLE:           *params = mReadFramebuffer->id();                         break;
 
1445
      case GL_RENDERBUFFER_BINDING:                     *params = mRenderbuffer.id();                             break;
 
1446
      case GL_VERTEX_ARRAY_BINDING:                     *params = mVertexArray->id();                             break;
 
1447
      case GL_CURRENT_PROGRAM:                          *params = mProgram ? mProgram->id() : 0;                  break;
 
1448
      case GL_PACK_ALIGNMENT:                           *params = mPack.alignment;                                break;
 
1449
      case GL_PACK_REVERSE_ROW_ORDER_ANGLE:             *params = mPack.reverseRowOrder;                          break;
 
1450
      case GL_PACK_ROW_LENGTH:
 
1451
          *params = mPack.rowLength;
 
1452
          break;
 
1453
      case GL_PACK_SKIP_ROWS:
 
1454
          *params = mPack.skipRows;
 
1455
          break;
 
1456
      case GL_PACK_SKIP_PIXELS:
 
1457
          *params = mPack.skipPixels;
 
1458
          break;
 
1459
      case GL_UNPACK_ALIGNMENT:                         *params = mUnpack.alignment;                              break;
 
1460
      case GL_UNPACK_ROW_LENGTH:                        *params = mUnpack.rowLength;                              break;
 
1461
      case GL_UNPACK_IMAGE_HEIGHT:
 
1462
          *params = mUnpack.imageHeight;
 
1463
          break;
 
1464
      case GL_UNPACK_SKIP_IMAGES:
 
1465
          *params = mUnpack.skipImages;
 
1466
          break;
 
1467
      case GL_UNPACK_SKIP_ROWS:
 
1468
          *params = mUnpack.skipRows;
 
1469
          break;
 
1470
      case GL_UNPACK_SKIP_PIXELS:
 
1471
          *params = mUnpack.skipPixels;
 
1472
          break;
 
1473
      case GL_GENERATE_MIPMAP_HINT:                     *params = mGenerateMipmapHint;                            break;
 
1474
      case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:      *params = mFragmentShaderDerivativeHint;                  break;
 
1475
      case GL_ACTIVE_TEXTURE:
 
1476
          *params = (static_cast<GLint>(mActiveSampler) + GL_TEXTURE0);
 
1477
          break;
 
1478
      case GL_STENCIL_FUNC:                             *params = mDepthStencil.stencilFunc;                      break;
 
1479
      case GL_STENCIL_REF:                              *params = mStencilRef;                                    break;
 
1480
      case GL_STENCIL_VALUE_MASK:                       *params = clampToInt(mDepthStencil.stencilMask);          break;
 
1481
      case GL_STENCIL_BACK_FUNC:                        *params = mDepthStencil.stencilBackFunc;                  break;
 
1482
      case GL_STENCIL_BACK_REF:                         *params = mStencilBackRef;                                break;
 
1483
      case GL_STENCIL_BACK_VALUE_MASK:                  *params = clampToInt(mDepthStencil.stencilBackMask);      break;
 
1484
      case GL_STENCIL_FAIL:                             *params = mDepthStencil.stencilFail;                      break;
 
1485
      case GL_STENCIL_PASS_DEPTH_FAIL:                  *params = mDepthStencil.stencilPassDepthFail;             break;
 
1486
      case GL_STENCIL_PASS_DEPTH_PASS:                  *params = mDepthStencil.stencilPassDepthPass;             break;
 
1487
      case GL_STENCIL_BACK_FAIL:                        *params = mDepthStencil.stencilBackFail;                  break;
 
1488
      case GL_STENCIL_BACK_PASS_DEPTH_FAIL:             *params = mDepthStencil.stencilBackPassDepthFail;         break;
 
1489
      case GL_STENCIL_BACK_PASS_DEPTH_PASS:             *params = mDepthStencil.stencilBackPassDepthPass;         break;
 
1490
      case GL_DEPTH_FUNC:                               *params = mDepthStencil.depthFunc;                        break;
 
1491
      case GL_BLEND_SRC_RGB:                            *params = mBlend.sourceBlendRGB;                          break;
 
1492
      case GL_BLEND_SRC_ALPHA:                          *params = mBlend.sourceBlendAlpha;                        break;
 
1493
      case GL_BLEND_DST_RGB:                            *params = mBlend.destBlendRGB;                            break;
 
1494
      case GL_BLEND_DST_ALPHA:                          *params = mBlend.destBlendAlpha;                          break;
 
1495
      case GL_BLEND_EQUATION_RGB:                       *params = mBlend.blendEquationRGB;                        break;
 
1496
      case GL_BLEND_EQUATION_ALPHA:                     *params = mBlend.blendEquationAlpha;                      break;
 
1497
      case GL_STENCIL_WRITEMASK:                        *params = clampToInt(mDepthStencil.stencilWritemask);     break;
 
1498
      case GL_STENCIL_BACK_WRITEMASK:                   *params = clampToInt(mDepthStencil.stencilBackWritemask); break;
 
1499
      case GL_STENCIL_CLEAR_VALUE:                      *params = mStencilClearValue;                             break;
 
1500
      case GL_IMPLEMENTATION_COLOR_READ_TYPE:           *params = mReadFramebuffer->getImplementationColorReadType();   break;
 
1501
      case GL_IMPLEMENTATION_COLOR_READ_FORMAT:         *params = mReadFramebuffer->getImplementationColorReadFormat(); break;
 
1502
      case GL_SAMPLE_BUFFERS:
 
1503
      case GL_SAMPLES:
 
1504
        {
 
1505
            gl::Framebuffer *framebuffer = mDrawFramebuffer;
 
1506
            if (framebuffer->checkStatus(data) == GL_FRAMEBUFFER_COMPLETE)
 
1507
            {
 
1508
                switch (pname)
 
1509
                {
 
1510
                  case GL_SAMPLE_BUFFERS:
 
1511
                    if (framebuffer->getSamples(data) != 0)
 
1512
                    {
 
1513
                        *params = 1;
 
1514
                    }
 
1515
                    else
 
1516
                    {
 
1517
                        *params = 0;
 
1518
                    }
 
1519
                    break;
 
1520
                  case GL_SAMPLES:
 
1521
                    *params = framebuffer->getSamples(data);
 
1522
                    break;
 
1523
                }
 
1524
            }
 
1525
            else
 
1526
            {
 
1527
                *params = 0;
 
1528
            }
 
1529
        }
 
1530
        break;
 
1531
      case GL_VIEWPORT:
 
1532
        params[0] = mViewport.x;
 
1533
        params[1] = mViewport.y;
 
1534
        params[2] = mViewport.width;
 
1535
        params[3] = mViewport.height;
 
1536
        break;
 
1537
      case GL_SCISSOR_BOX:
 
1538
        params[0] = mScissor.x;
 
1539
        params[1] = mScissor.y;
 
1540
        params[2] = mScissor.width;
 
1541
        params[3] = mScissor.height;
 
1542
        break;
 
1543
      case GL_CULL_FACE_MODE:                   *params = mRasterizer.cullMode;   break;
 
1544
      case GL_FRONT_FACE:                       *params = mRasterizer.frontFace;  break;
 
1545
      case GL_RED_BITS:
 
1546
      case GL_GREEN_BITS:
 
1547
      case GL_BLUE_BITS:
 
1548
      case GL_ALPHA_BITS:
 
1549
        {
 
1550
            gl::Framebuffer *framebuffer = getDrawFramebuffer();
 
1551
            const gl::FramebufferAttachment *colorbuffer = framebuffer->getFirstColorbuffer();
 
1552
 
 
1553
            if (colorbuffer)
 
1554
            {
 
1555
                switch (pname)
 
1556
                {
 
1557
                case GL_RED_BITS:   *params = colorbuffer->getRedSize();      break;
 
1558
                case GL_GREEN_BITS: *params = colorbuffer->getGreenSize();    break;
 
1559
                case GL_BLUE_BITS:  *params = colorbuffer->getBlueSize();     break;
 
1560
                case GL_ALPHA_BITS: *params = colorbuffer->getAlphaSize();    break;
 
1561
                }
 
1562
            }
 
1563
            else
 
1564
            {
 
1565
                *params = 0;
 
1566
            }
 
1567
        }
 
1568
        break;
 
1569
      case GL_DEPTH_BITS:
 
1570
        {
 
1571
            const gl::Framebuffer *framebuffer = getDrawFramebuffer();
 
1572
            const gl::FramebufferAttachment *depthbuffer = framebuffer->getDepthbuffer();
 
1573
 
 
1574
            if (depthbuffer)
 
1575
            {
 
1576
                *params = depthbuffer->getDepthSize();
 
1577
            }
 
1578
            else
 
1579
            {
 
1580
                *params = 0;
 
1581
            }
 
1582
        }
 
1583
        break;
 
1584
      case GL_STENCIL_BITS:
 
1585
        {
 
1586
            const gl::Framebuffer *framebuffer = getDrawFramebuffer();
 
1587
            const gl::FramebufferAttachment *stencilbuffer = framebuffer->getStencilbuffer();
 
1588
 
 
1589
            if (stencilbuffer)
 
1590
            {
 
1591
                *params = stencilbuffer->getStencilSize();
 
1592
            }
 
1593
            else
 
1594
            {
 
1595
                *params = 0;
 
1596
            }
 
1597
        }
 
1598
        break;
 
1599
      case GL_TEXTURE_BINDING_2D:
 
1600
        ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
 
1601
        *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_2D);
 
1602
        break;
 
1603
      case GL_TEXTURE_BINDING_CUBE_MAP:
 
1604
        ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
 
1605
        *params =
 
1606
            getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_CUBE_MAP);
 
1607
        break;
 
1608
      case GL_TEXTURE_BINDING_3D:
 
1609
        ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
 
1610
        *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_3D);
 
1611
        break;
 
1612
      case GL_TEXTURE_BINDING_2D_ARRAY:
 
1613
        ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
 
1614
        *params =
 
1615
            getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_2D_ARRAY);
 
1616
        break;
 
1617
      case GL_UNIFORM_BUFFER_BINDING:
 
1618
        *params = mGenericUniformBuffer.id();
 
1619
        break;
 
1620
      case GL_TRANSFORM_FEEDBACK_BINDING:
 
1621
        *params = mTransformFeedback.id();
 
1622
        break;
 
1623
      case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
 
1624
        *params = mTransformFeedback->getGenericBuffer().id();
 
1625
        break;
 
1626
      case GL_COPY_READ_BUFFER_BINDING:
 
1627
        *params = mCopyReadBuffer.id();
 
1628
        break;
 
1629
      case GL_COPY_WRITE_BUFFER_BINDING:
 
1630
        *params = mCopyWriteBuffer.id();
 
1631
        break;
 
1632
      case GL_PIXEL_PACK_BUFFER_BINDING:
 
1633
        *params = mPack.pixelBuffer.id();
 
1634
        break;
 
1635
      case GL_PIXEL_UNPACK_BUFFER_BINDING:
 
1636
        *params = mUnpack.pixelBuffer.id();
 
1637
        break;
 
1638
      case GL_DEBUG_LOGGED_MESSAGES:
 
1639
          *params = static_cast<GLint>(mDebug.getMessageCount());
 
1640
          break;
 
1641
      case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
 
1642
          *params = static_cast<GLint>(mDebug.getNextMessageLength());
 
1643
          break;
 
1644
      case GL_DEBUG_GROUP_STACK_DEPTH:
 
1645
          *params = static_cast<GLint>(mDebug.getGroupStackDepth());
 
1646
          break;
 
1647
      default:
 
1648
        UNREACHABLE();
 
1649
        break;
 
1650
    }
 
1651
}
 
1652
 
 
1653
void State::getPointerv(GLenum pname, void **params) const
 
1654
{
 
1655
    switch (pname)
 
1656
    {
 
1657
        case GL_DEBUG_CALLBACK_FUNCTION:
 
1658
            *params = reinterpret_cast<void *>(mDebug.getCallback());
 
1659
            break;
 
1660
        case GL_DEBUG_CALLBACK_USER_PARAM:
 
1661
            *params = const_cast<void *>(mDebug.getUserParam());
 
1662
            break;
 
1663
        default:
 
1664
            UNREACHABLE();
 
1665
            break;
 
1666
    }
 
1667
}
 
1668
 
 
1669
bool State::getIndexedIntegerv(GLenum target, GLuint index, GLint *data)
 
1670
{
 
1671
    switch (target)
 
1672
    {
 
1673
      case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
 
1674
        if (static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount())
 
1675
        {
 
1676
            *data = mTransformFeedback->getIndexedBuffer(index).id();
 
1677
        }
 
1678
        break;
 
1679
      case GL_UNIFORM_BUFFER_BINDING:
 
1680
        if (static_cast<size_t>(index) < mUniformBuffers.size())
 
1681
        {
 
1682
            *data = mUniformBuffers[index].id();
 
1683
        }
 
1684
        break;
 
1685
      default:
 
1686
        return false;
 
1687
    }
 
1688
 
 
1689
    return true;
 
1690
}
 
1691
 
 
1692
bool State::getIndexedInteger64v(GLenum target, GLuint index, GLint64 *data)
 
1693
{
 
1694
    switch (target)
 
1695
    {
 
1696
      case GL_TRANSFORM_FEEDBACK_BUFFER_START:
 
1697
        if (static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount())
 
1698
        {
 
1699
            *data = mTransformFeedback->getIndexedBuffer(index).getOffset();
 
1700
        }
 
1701
        break;
 
1702
      case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
 
1703
        if (static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount())
 
1704
        {
 
1705
            *data = mTransformFeedback->getIndexedBuffer(index).getSize();
 
1706
        }
 
1707
        break;
 
1708
      case GL_UNIFORM_BUFFER_START:
 
1709
        if (static_cast<size_t>(index) < mUniformBuffers.size())
 
1710
        {
 
1711
            *data = mUniformBuffers[index].getOffset();
 
1712
        }
 
1713
        break;
 
1714
      case GL_UNIFORM_BUFFER_SIZE:
 
1715
        if (static_cast<size_t>(index) < mUniformBuffers.size())
 
1716
        {
 
1717
            *data = mUniformBuffers[index].getSize();
 
1718
        }
 
1719
        break;
 
1720
      default:
 
1721
        return false;
 
1722
    }
 
1723
 
 
1724
    return true;
 
1725
}
 
1726
 
 
1727
bool State::hasMappedBuffer(GLenum target) const
 
1728
{
 
1729
    if (target == GL_ARRAY_BUFFER)
 
1730
    {
 
1731
        const VertexArray *vao = getVertexArray();
 
1732
        const auto &vertexAttribs = vao->getVertexAttributes();
 
1733
        size_t maxEnabledAttrib = vao->getMaxEnabledAttribute();
 
1734
        for (size_t attribIndex = 0; attribIndex < maxEnabledAttrib; attribIndex++)
 
1735
        {
 
1736
            const gl::VertexAttribute &vertexAttrib = vertexAttribs[attribIndex];
 
1737
            gl::Buffer *boundBuffer = vertexAttrib.buffer.get();
 
1738
            if (vertexAttrib.enabled && boundBuffer && boundBuffer->isMapped())
 
1739
            {
 
1740
                return true;
 
1741
            }
 
1742
        }
 
1743
 
 
1744
        return false;
 
1745
    }
 
1746
    else
 
1747
    {
 
1748
        Buffer *buffer = getTargetBuffer(target);
 
1749
        return (buffer && buffer->isMapped());
 
1750
    }
 
1751
}
 
1752
 
 
1753
void State::syncDirtyObjects()
 
1754
{
 
1755
    if (!mDirtyObjects.any())
 
1756
        return;
 
1757
 
 
1758
    syncDirtyObjects(mDirtyObjects);
 
1759
}
 
1760
 
 
1761
void State::syncDirtyObjects(const DirtyObjects &bitset)
 
1762
{
 
1763
    for (auto dirtyObject : angle::IterateBitSet(bitset))
 
1764
    {
 
1765
        switch (dirtyObject)
 
1766
        {
 
1767
            case DIRTY_OBJECT_READ_FRAMEBUFFER:
 
1768
                ASSERT(mReadFramebuffer);
 
1769
                mReadFramebuffer->syncState();
 
1770
                break;
 
1771
            case DIRTY_OBJECT_DRAW_FRAMEBUFFER:
 
1772
                ASSERT(mDrawFramebuffer);
 
1773
                mDrawFramebuffer->syncState();
 
1774
                break;
 
1775
            case DIRTY_OBJECT_VERTEX_ARRAY:
 
1776
                ASSERT(mVertexArray);
 
1777
                mVertexArray->syncImplState();
 
1778
                break;
 
1779
            case DIRTY_OBJECT_PROGRAM:
 
1780
                // TODO(jmadill): implement this
 
1781
                break;
 
1782
            default:
 
1783
                UNREACHABLE();
 
1784
                break;
 
1785
        }
 
1786
    }
 
1787
 
 
1788
    mDirtyObjects &= ~bitset;
 
1789
}
 
1790
 
 
1791
void State::syncDirtyObject(GLenum target)
 
1792
{
 
1793
    DirtyObjects localSet;
 
1794
 
 
1795
    switch (target)
 
1796
    {
 
1797
        case GL_READ_FRAMEBUFFER:
 
1798
            localSet.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
 
1799
            break;
 
1800
        case GL_DRAW_FRAMEBUFFER:
 
1801
            localSet.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
 
1802
            break;
 
1803
        case GL_FRAMEBUFFER:
 
1804
            localSet.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
 
1805
            localSet.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
 
1806
            break;
 
1807
        case GL_VERTEX_ARRAY:
 
1808
            localSet.set(DIRTY_OBJECT_VERTEX_ARRAY);
 
1809
            break;
 
1810
        case GL_PROGRAM:
 
1811
            localSet.set(DIRTY_OBJECT_PROGRAM);
 
1812
            break;
 
1813
    }
 
1814
 
 
1815
    syncDirtyObjects(localSet);
 
1816
}
 
1817
 
 
1818
void State::setObjectDirty(GLenum target)
 
1819
{
 
1820
    switch (target)
 
1821
    {
 
1822
        case GL_READ_FRAMEBUFFER:
 
1823
            mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
 
1824
            break;
 
1825
        case GL_DRAW_FRAMEBUFFER:
 
1826
            mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
 
1827
            break;
 
1828
        case GL_FRAMEBUFFER:
 
1829
            mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
 
1830
            mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
 
1831
            break;
 
1832
        case GL_VERTEX_ARRAY:
 
1833
            mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
 
1834
            break;
 
1835
        case GL_PROGRAM:
 
1836
            mDirtyObjects.set(DIRTY_OBJECT_PROGRAM);
 
1837
            break;
 
1838
    }
 
1839
}
 
1840
 
 
1841
}  // namespace gl