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.
7
// State.cpp: Implements the State class, encapsulating raw GL state.
9
#include "libANGLE/State.h"
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"
26
mMaxCombinedTextureImageUnits(0),
28
mStencilClearValue(0),
30
mSampleCoverage(false),
31
mSampleCoverageValue(0),
32
mSampleCoverageInvert(false),
36
mGenerateMipmapHint(GL_NONE),
37
mFragmentShaderDerivativeHint(GL_NONE),
40
mReadFramebuffer(nullptr),
41
mDrawFramebuffer(nullptr),
43
mVertexArray(nullptr),
45
mPrimitiveRestart(false)
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);
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);
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);
74
mBlitStateBitMask.set(DIRTY_BIT_SCISSOR_TEST_ENABLED);
75
mBlitStateBitMask.set(DIRTY_BIT_SCISSOR);
83
void State::initialize(const Caps &caps,
84
const Extensions &extensions,
88
mMaxDrawBuffers = caps.maxDrawBuffers;
89
mMaxCombinedTextureImageUnits = caps.maxCombinedTextureImageUnits;
91
setColorClearValue(0.0f, 0.0f, 0.0f, 0.0f);
93
mDepthClearValue = 1.0f;
94
mStencilClearValue = 0;
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;
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;
122
mBlendColor.green = 0;
123
mBlendColor.blue = 0;
124
mBlendColor.alpha = 0;
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;
146
mSampleCoverage = false;
147
mSampleCoverageValue = 1.0f;
148
mSampleCoverageInvert = false;
149
mGenerateMipmapHint = GL_DONT_CARE;
150
mFragmentShaderDerivativeHint = GL_DONT_CARE;
157
mViewport.height = 0;
161
mBlend.colorMaskRed = true;
162
mBlend.colorMaskGreen = true;
163
mBlend.colorMaskBlue = true;
164
mBlend.colorMaskAlpha = true;
168
mVertexAttribCurrentValues.resize(caps.maxVertexAttributes);
170
mUniformBuffers.resize(caps.maxCombinedUniformBlocks);
172
mSamplerTextures[GL_TEXTURE_2D].resize(caps.maxCombinedTextureImageUnits);
173
mSamplerTextures[GL_TEXTURE_CUBE_MAP].resize(caps.maxCombinedTextureImageUnits);
174
if (clientVersion >= 3)
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);
181
mSamplers.resize(caps.maxCombinedTextureImageUnits);
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);
190
mReadFramebuffer = nullptr;
191
mDrawFramebuffer = nullptr;
193
mPrimitiveRestart = false;
195
mDebug.setOutputEnabled(debug);
196
mDebug.setMaxLoggedMessages(extensions.maxDebugLoggedMessages);
201
for (TextureBindingMap::iterator bindingVec = mSamplerTextures.begin(); bindingVec != mSamplerTextures.end(); bindingVec++)
203
TextureBindingVector &textureVector = bindingVec->second;
204
for (size_t textureIdx = 0; textureIdx < textureVector.size(); textureIdx++)
206
textureVector[textureIdx].set(NULL);
209
for (size_t samplerIdx = 0; samplerIdx < mSamplers.size(); samplerIdx++)
211
mSamplers[samplerIdx].set(NULL);
214
mArrayBuffer.set(NULL);
215
mRenderbuffer.set(NULL);
223
mTransformFeedback.set(NULL);
225
for (State::ActiveQueryMap::iterator i = mActiveQueries.begin(); i != mActiveQueries.end(); i++)
230
mGenericUniformBuffer.set(NULL);
231
for (BufferVector::iterator bufItr = mUniformBuffers.begin(); bufItr != mUniformBuffers.end(); ++bufItr)
236
mCopyReadBuffer.set(NULL);
237
mCopyWriteBuffer.set(NULL);
239
mPack.pixelBuffer.set(NULL);
240
mUnpack.pixelBuffer.set(NULL);
244
// TODO(jmadill): Is this necessary?
248
const RasterizerState &State::getRasterizerState() const
253
const BlendState &State::getBlendState() const
258
const DepthStencilState &State::getDepthStencilState() const
260
return mDepthStencil;
263
void State::setColorClearValue(float red, float green, float blue, float alpha)
265
mColorClearValue.red = red;
266
mColorClearValue.green = green;
267
mColorClearValue.blue = blue;
268
mColorClearValue.alpha = alpha;
269
mDirtyBits.set(DIRTY_BIT_CLEAR_COLOR);
272
void State::setDepthClearValue(float depth)
274
mDepthClearValue = depth;
275
mDirtyBits.set(DIRTY_BIT_CLEAR_DEPTH);
278
void State::setStencilClearValue(int stencil)
280
mStencilClearValue = stencil;
281
mDirtyBits.set(DIRTY_BIT_CLEAR_STENCIL);
284
void State::setColorMask(bool red, bool green, bool blue, bool alpha)
286
mBlend.colorMaskRed = red;
287
mBlend.colorMaskGreen = green;
288
mBlend.colorMaskBlue = blue;
289
mBlend.colorMaskAlpha = alpha;
290
mDirtyBits.set(DIRTY_BIT_COLOR_MASK);
293
void State::setDepthMask(bool mask)
295
mDepthStencil.depthMask = mask;
296
mDirtyBits.set(DIRTY_BIT_DEPTH_MASK);
299
bool State::isRasterizerDiscardEnabled() const
301
return mRasterizer.rasterizerDiscard;
304
void State::setRasterizerDiscard(bool enabled)
306
mRasterizer.rasterizerDiscard = enabled;
307
mDirtyBits.set(DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
310
bool State::isCullFaceEnabled() const
312
return mRasterizer.cullFace;
315
void State::setCullFace(bool enabled)
317
mRasterizer.cullFace = enabled;
318
mDirtyBits.set(DIRTY_BIT_CULL_FACE_ENABLED);
321
void State::setCullMode(GLenum mode)
323
mRasterizer.cullMode = mode;
324
mDirtyBits.set(DIRTY_BIT_CULL_FACE);
327
void State::setFrontFace(GLenum front)
329
mRasterizer.frontFace = front;
330
mDirtyBits.set(DIRTY_BIT_FRONT_FACE);
333
bool State::isDepthTestEnabled() const
335
return mDepthStencil.depthTest;
338
void State::setDepthTest(bool enabled)
340
mDepthStencil.depthTest = enabled;
341
mDirtyBits.set(DIRTY_BIT_DEPTH_TEST_ENABLED);
344
void State::setDepthFunc(GLenum depthFunc)
346
mDepthStencil.depthFunc = depthFunc;
347
mDirtyBits.set(DIRTY_BIT_DEPTH_FUNC);
350
void State::setDepthRange(float zNear, float zFar)
354
mDirtyBits.set(DIRTY_BIT_DEPTH_RANGE);
357
float State::getNearPlane() const
362
float State::getFarPlane() const
367
bool State::isBlendEnabled() const
372
void State::setBlend(bool enabled)
374
mBlend.blend = enabled;
375
mDirtyBits.set(DIRTY_BIT_BLEND_ENABLED);
378
void State::setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha)
380
mBlend.sourceBlendRGB = sourceRGB;
381
mBlend.destBlendRGB = destRGB;
382
mBlend.sourceBlendAlpha = sourceAlpha;
383
mBlend.destBlendAlpha = destAlpha;
384
mDirtyBits.set(DIRTY_BIT_BLEND_FUNCS);
387
void State::setBlendColor(float red, float green, float blue, float alpha)
389
mBlendColor.red = red;
390
mBlendColor.green = green;
391
mBlendColor.blue = blue;
392
mBlendColor.alpha = alpha;
393
mDirtyBits.set(DIRTY_BIT_BLEND_COLOR);
396
void State::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation)
398
mBlend.blendEquationRGB = rgbEquation;
399
mBlend.blendEquationAlpha = alphaEquation;
400
mDirtyBits.set(DIRTY_BIT_BLEND_EQUATIONS);
403
const ColorF &State::getBlendColor() const
408
bool State::isStencilTestEnabled() const
410
return mDepthStencil.stencilTest;
413
void State::setStencilTest(bool enabled)
415
mDepthStencil.stencilTest = enabled;
416
mDirtyBits.set(DIRTY_BIT_STENCIL_TEST_ENABLED);
419
void State::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask)
421
mDepthStencil.stencilFunc = stencilFunc;
422
mStencilRef = (stencilRef > 0) ? stencilRef : 0;
423
mDepthStencil.stencilMask = stencilMask;
424
mDirtyBits.set(DIRTY_BIT_STENCIL_FUNCS_FRONT);
427
void State::setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask)
429
mDepthStencil.stencilBackFunc = stencilBackFunc;
430
mStencilBackRef = (stencilBackRef > 0) ? stencilBackRef : 0;
431
mDepthStencil.stencilBackMask = stencilBackMask;
432
mDirtyBits.set(DIRTY_BIT_STENCIL_FUNCS_BACK);
435
void State::setStencilWritemask(GLuint stencilWritemask)
437
mDepthStencil.stencilWritemask = stencilWritemask;
438
mDirtyBits.set(DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
441
void State::setStencilBackWritemask(GLuint stencilBackWritemask)
443
mDepthStencil.stencilBackWritemask = stencilBackWritemask;
444
mDirtyBits.set(DIRTY_BIT_STENCIL_WRITEMASK_BACK);
447
void State::setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass)
449
mDepthStencil.stencilFail = stencilFail;
450
mDepthStencil.stencilPassDepthFail = stencilPassDepthFail;
451
mDepthStencil.stencilPassDepthPass = stencilPassDepthPass;
452
mDirtyBits.set(DIRTY_BIT_STENCIL_OPS_FRONT);
455
void State::setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass)
457
mDepthStencil.stencilBackFail = stencilBackFail;
458
mDepthStencil.stencilBackPassDepthFail = stencilBackPassDepthFail;
459
mDepthStencil.stencilBackPassDepthPass = stencilBackPassDepthPass;
460
mDirtyBits.set(DIRTY_BIT_STENCIL_OPS_BACK);
463
GLint State::getStencilRef() const
468
GLint State::getStencilBackRef() const
470
return mStencilBackRef;
473
bool State::isPolygonOffsetFillEnabled() const
475
return mRasterizer.polygonOffsetFill;
478
void State::setPolygonOffsetFill(bool enabled)
480
mRasterizer.polygonOffsetFill = enabled;
481
mDirtyBits.set(DIRTY_BIT_POLYGON_OFFSET_FILL_ENABLED);
484
void State::setPolygonOffsetParams(GLfloat factor, GLfloat units)
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);
492
bool State::isSampleAlphaToCoverageEnabled() const
494
return mBlend.sampleAlphaToCoverage;
497
void State::setSampleAlphaToCoverage(bool enabled)
499
mBlend.sampleAlphaToCoverage = enabled;
500
mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED);
503
bool State::isSampleCoverageEnabled() const
505
return mSampleCoverage;
508
void State::setSampleCoverage(bool enabled)
510
mSampleCoverage = enabled;
511
mDirtyBits.set(DIRTY_BIT_SAMPLE_COVERAGE_ENABLED);
514
void State::setSampleCoverageParams(GLclampf value, bool invert)
516
mSampleCoverageValue = value;
517
mSampleCoverageInvert = invert;
518
mDirtyBits.set(DIRTY_BIT_SAMPLE_COVERAGE);
521
GLclampf State::getSampleCoverageValue() const
523
return mSampleCoverageValue;
526
bool State::getSampleCoverageInvert() const
528
return mSampleCoverageInvert;
531
bool State::isScissorTestEnabled() const
536
void State::setScissorTest(bool enabled)
538
mScissorTest = enabled;
539
mDirtyBits.set(DIRTY_BIT_SCISSOR_TEST_ENABLED);
542
void State::setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height)
546
mScissor.width = width;
547
mScissor.height = height;
548
mDirtyBits.set(DIRTY_BIT_SCISSOR);
551
const Rectangle &State::getScissor() const
556
bool State::isDitherEnabled() const
558
return mBlend.dither;
561
void State::setDither(bool enabled)
563
mBlend.dither = enabled;
564
mDirtyBits.set(DIRTY_BIT_DITHER_ENABLED);
567
bool State::isPrimitiveRestartEnabled() const
569
return mPrimitiveRestart;
572
void State::setPrimitiveRestart(bool enabled)
574
mPrimitiveRestart = enabled;
575
mDirtyBits.set(DIRTY_BIT_PRIMITIVE_RESTART_ENABLED);
578
void State::setEnableFeature(GLenum feature, bool enabled)
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);
596
case GL_DEBUG_OUTPUT:
597
mDebug.setOutputEnabled(enabled);
599
default: UNREACHABLE();
603
bool State::getEnableFeature(GLenum feature)
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;
626
void State::setLineWidth(GLfloat width)
629
mDirtyBits.set(DIRTY_BIT_LINE_WIDTH);
632
float State::getLineWidth() const
637
void State::setGenerateMipmapHint(GLenum hint)
639
mGenerateMipmapHint = hint;
640
mDirtyBits.set(DIRTY_BIT_GENERATE_MIPMAP_HINT);
643
void State::setFragmentShaderDerivativeHint(GLenum hint)
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.
652
void State::setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height)
656
mViewport.width = width;
657
mViewport.height = height;
658
mDirtyBits.set(DIRTY_BIT_VIEWPORT);
661
const Rectangle &State::getViewport() const
666
void State::setActiveSampler(unsigned int active)
668
mActiveSampler = active;
671
unsigned int State::getActiveSampler() const
673
return static_cast<unsigned int>(mActiveSampler);
676
void State::setSamplerTexture(GLenum type, Texture *texture)
678
mSamplerTextures[type][mActiveSampler].set(texture);
681
Texture *State::getTargetTexture(GLenum target) const
683
return getSamplerTexture(static_cast<unsigned int>(mActiveSampler), target);
686
Texture *State::getSamplerTexture(unsigned int sampler, GLenum type) const
688
const auto it = mSamplerTextures.find(type);
689
ASSERT(it != mSamplerTextures.end());
690
ASSERT(sampler < it->second.size());
691
return it->second[sampler].get();
694
GLuint State::getSamplerTextureId(unsigned int sampler, GLenum type) const
696
const auto it = mSamplerTextures.find(type);
697
ASSERT(it != mSamplerTextures.end());
698
ASSERT(sampler < it->second.size());
699
return it->second[sampler].id();
702
void State::detachTexture(const TextureMap &zeroTextures, GLuint texture)
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.
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
713
for (TextureBindingMap::iterator bindingVec = mSamplerTextures.begin(); bindingVec != mSamplerTextures.end(); bindingVec++)
715
GLenum textureType = bindingVec->first;
716
TextureBindingVector &textureVector = bindingVec->second;
717
for (size_t textureIdx = 0; textureIdx < textureVector.size(); textureIdx++)
719
BindingPointer<Texture> &binding = textureVector[textureIdx];
720
if (binding.id() == texture)
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());
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.
735
if (mReadFramebuffer)
737
mReadFramebuffer->detachTexture(texture);
740
if (mDrawFramebuffer)
742
mDrawFramebuffer->detachTexture(texture);
746
void State::initializeZeroTextures(const TextureMap &zeroTextures)
748
for (const auto &zeroTexture : zeroTextures)
750
auto &samplerTextureArray = mSamplerTextures[zeroTexture.first];
752
for (size_t textureUnit = 0; textureUnit < samplerTextureArray.size(); ++textureUnit)
754
samplerTextureArray[textureUnit].set(zeroTexture.second.get());
759
void State::setSamplerBinding(GLuint textureUnit, Sampler *sampler)
761
mSamplers[textureUnit].set(sampler);
764
GLuint State::getSamplerId(GLuint textureUnit) const
766
ASSERT(textureUnit < mSamplers.size());
767
return mSamplers[textureUnit].id();
770
Sampler *State::getSampler(GLuint textureUnit) const
772
return mSamplers[textureUnit].get();
775
void State::detachSampler(GLuint sampler)
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++)
783
BindingPointer<Sampler> &samplerBinding = mSamplers[textureUnit];
784
if (samplerBinding.id() == sampler)
786
samplerBinding.set(NULL);
791
void State::setRenderbufferBinding(Renderbuffer *renderbuffer)
793
mRenderbuffer.set(renderbuffer);
796
GLuint State::getRenderbufferId() const
798
return mRenderbuffer.id();
801
Renderbuffer *State::getCurrentRenderbuffer()
803
return mRenderbuffer.get();
806
void State::detachRenderbuffer(GLuint renderbuffer)
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.
812
if (mRenderbuffer.id() == renderbuffer)
814
mRenderbuffer.set(NULL);
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.
822
Framebuffer *readFramebuffer = mReadFramebuffer;
823
Framebuffer *drawFramebuffer = mDrawFramebuffer;
827
readFramebuffer->detachRenderbuffer(renderbuffer);
830
if (drawFramebuffer && drawFramebuffer != readFramebuffer)
832
drawFramebuffer->detachRenderbuffer(renderbuffer);
837
void State::setReadFramebufferBinding(Framebuffer *framebuffer)
839
if (mReadFramebuffer == framebuffer)
842
mReadFramebuffer = framebuffer;
843
mDirtyBits.set(DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
845
if (mReadFramebuffer && mReadFramebuffer->hasAnyDirtyBit())
847
mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
851
void State::setDrawFramebufferBinding(Framebuffer *framebuffer)
853
if (mDrawFramebuffer == framebuffer)
856
mDrawFramebuffer = framebuffer;
857
mDirtyBits.set(DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
859
if (mDrawFramebuffer && mDrawFramebuffer->hasAnyDirtyBit())
861
mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
865
Framebuffer *State::getTargetFramebuffer(GLenum target) const
869
case GL_READ_FRAMEBUFFER_ANGLE:
870
return mReadFramebuffer;
871
case GL_DRAW_FRAMEBUFFER_ANGLE:
873
return mDrawFramebuffer;
880
Framebuffer *State::getReadFramebuffer()
882
return mReadFramebuffer;
885
Framebuffer *State::getDrawFramebuffer()
887
return mDrawFramebuffer;
890
const Framebuffer *State::getReadFramebuffer() const
892
return mReadFramebuffer;
895
const Framebuffer *State::getDrawFramebuffer() const
897
return mDrawFramebuffer;
900
bool State::removeReadFramebufferBinding(GLuint framebuffer)
902
if (mReadFramebuffer != nullptr &&
903
mReadFramebuffer->id() == framebuffer)
905
setReadFramebufferBinding(nullptr);
912
bool State::removeDrawFramebufferBinding(GLuint framebuffer)
914
if (mReadFramebuffer != nullptr &&
915
mDrawFramebuffer->id() == framebuffer)
917
setDrawFramebufferBinding(nullptr);
924
void State::setVertexArrayBinding(VertexArray *vertexArray)
926
mVertexArray = vertexArray;
927
mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING);
929
if (mVertexArray && mVertexArray->hasAnyDirtyBit())
931
mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
935
GLuint State::getVertexArrayId() const
937
ASSERT(mVertexArray != NULL);
938
return mVertexArray->id();
941
VertexArray *State::getVertexArray() const
943
ASSERT(mVertexArray != NULL);
947
bool State::removeVertexArrayBinding(GLuint vertexArray)
949
if (mVertexArray->id() == vertexArray)
952
mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING);
953
mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
960
void State::setProgram(Program *newProgram)
962
if (mProgram != newProgram)
969
mProgram = newProgram;
973
newProgram->addRef();
978
Program *State::getProgram() const
983
void State::setTransformFeedbackBinding(TransformFeedback *transformFeedback)
985
mTransformFeedback.set(transformFeedback);
988
TransformFeedback *State::getCurrentTransformFeedback() const
990
return mTransformFeedback.get();
993
bool State::isTransformFeedbackActiveUnpaused() const
995
gl::TransformFeedback *curTransformFeedback = getCurrentTransformFeedback();
996
return curTransformFeedback && curTransformFeedback->isActive() && !curTransformFeedback->isPaused();
999
void State::detachTransformFeedback(GLuint transformFeedback)
1001
if (mTransformFeedback.id() == transformFeedback)
1003
mTransformFeedback.set(NULL);
1007
bool State::isQueryActive() const
1009
for (auto &iter : mActiveQueries)
1011
if (iter.second.get() != NULL)
1020
bool State::isQueryActive(Query *query) const
1022
for (auto &iter : mActiveQueries)
1024
if (iter.second.get() == query)
1033
void State::setActiveQuery(GLenum target, Query *query)
1035
mActiveQueries[target].set(query);
1038
GLuint State::getActiveQueryId(GLenum target) const
1040
const Query *query = getActiveQuery(target);
1041
return (query ? query->id() : 0u);
1044
Query *State::getActiveQuery(GLenum target) const
1046
const auto it = mActiveQueries.find(target);
1048
// All query types should already exist in the activeQueries map
1049
ASSERT(it != mActiveQueries.end());
1051
return it->second.get();
1054
void State::setArrayBufferBinding(Buffer *buffer)
1056
mArrayBuffer.set(buffer);
1059
GLuint State::getArrayBufferId() const
1061
return mArrayBuffer.id();
1064
void State::setGenericUniformBufferBinding(Buffer *buffer)
1066
mGenericUniformBuffer.set(buffer);
1069
void State::setIndexedUniformBufferBinding(GLuint index, Buffer *buffer, GLintptr offset, GLsizeiptr size)
1071
mUniformBuffers[index].set(buffer, offset, size);
1074
const OffsetBindingPointer<Buffer> &State::getIndexedUniformBuffer(size_t index) const
1076
ASSERT(static_cast<size_t>(index) < mUniformBuffers.size());
1077
return mUniformBuffers[index];
1080
void State::setCopyReadBufferBinding(Buffer *buffer)
1082
mCopyReadBuffer.set(buffer);
1085
void State::setCopyWriteBufferBinding(Buffer *buffer)
1087
mCopyWriteBuffer.set(buffer);
1090
void State::setPixelPackBufferBinding(Buffer *buffer)
1092
mPack.pixelBuffer.set(buffer);
1095
void State::setPixelUnpackBufferBinding(Buffer *buffer)
1097
mUnpack.pixelBuffer.set(buffer);
1100
Buffer *State::getTargetBuffer(GLenum target) const
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;
1116
void State::detachBuffer(GLuint bufferName)
1118
BindingPointer<Buffer> *buffers[] = {&mArrayBuffer, &mCopyReadBuffer,
1119
&mCopyWriteBuffer, &mPack.pixelBuffer,
1120
&mUnpack.pixelBuffer, &mGenericUniformBuffer};
1121
for (auto buffer : buffers)
1123
if (buffer->id() == bufferName)
1125
buffer->set(nullptr);
1129
TransformFeedback *curTransformFeedback = getCurrentTransformFeedback();
1130
if (curTransformFeedback)
1132
curTransformFeedback->detachBuffer(bufferName);
1135
getVertexArray()->detachBuffer(bufferName);
1138
void State::setEnableVertexAttribArray(unsigned int attribNum, bool enabled)
1140
getVertexArray()->enableAttribute(attribNum, enabled);
1141
mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
1144
void State::setVertexAttribf(GLuint index, const GLfloat values[4])
1146
ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size());
1147
mVertexAttribCurrentValues[index].setFloatValues(values);
1148
mDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_0 + index);
1151
void State::setVertexAttribu(GLuint index, const GLuint values[4])
1153
ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size());
1154
mVertexAttribCurrentValues[index].setUnsignedIntValues(values);
1155
mDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_0 + index);
1158
void State::setVertexAttribi(GLuint index, const GLint values[4])
1160
ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size());
1161
mVertexAttribCurrentValues[index].setIntValues(values);
1162
mDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_0 + index);
1165
void State::setVertexAttribState(unsigned int attribNum,
1166
Buffer *boundBuffer,
1172
const void *pointer)
1174
getVertexArray()->setAttributeState(attribNum, boundBuffer, size, type, normalized, pureInteger, stride, pointer);
1175
mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
1178
void State::setVertexAttribDivisor(GLuint index, GLuint divisor)
1180
getVertexArray()->setVertexAttribDivisor(index, divisor);
1181
mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
1184
const VertexAttribCurrentValueData &State::getVertexAttribCurrentValue(unsigned int attribNum) const
1186
ASSERT(static_cast<size_t>(attribNum) < mVertexAttribCurrentValues.size());
1187
return mVertexAttribCurrentValues[attribNum];
1190
const void *State::getVertexAttribPointer(unsigned int attribNum) const
1192
return getVertexArray()->getVertexAttribute(attribNum).pointer;
1195
void State::setPackAlignment(GLint alignment)
1197
mPack.alignment = alignment;
1198
mDirtyBits.set(DIRTY_BIT_PACK_ALIGNMENT);
1201
GLint State::getPackAlignment() const
1203
return mPack.alignment;
1206
void State::setPackReverseRowOrder(bool reverseRowOrder)
1208
mPack.reverseRowOrder = reverseRowOrder;
1209
mDirtyBits.set(DIRTY_BIT_PACK_REVERSE_ROW_ORDER);
1212
bool State::getPackReverseRowOrder() const
1214
return mPack.reverseRowOrder;
1217
void State::setPackRowLength(GLint rowLength)
1219
mPack.rowLength = rowLength;
1220
mDirtyBits.set(DIRTY_BIT_PACK_ROW_LENGTH);
1223
GLint State::getPackRowLength() const
1225
return mPack.rowLength;
1228
void State::setPackSkipRows(GLint skipRows)
1230
mPack.skipRows = skipRows;
1231
mDirtyBits.set(DIRTY_BIT_PACK_SKIP_ROWS);
1234
GLint State::getPackSkipRows() const
1236
return mPack.skipRows;
1239
void State::setPackSkipPixels(GLint skipPixels)
1241
mPack.skipPixels = skipPixels;
1242
mDirtyBits.set(DIRTY_BIT_PACK_SKIP_PIXELS);
1245
GLint State::getPackSkipPixels() const
1247
return mPack.skipPixels;
1250
const PixelPackState &State::getPackState() const
1255
PixelPackState &State::getPackState()
1260
void State::setUnpackAlignment(GLint alignment)
1262
mUnpack.alignment = alignment;
1263
mDirtyBits.set(DIRTY_BIT_UNPACK_ALIGNMENT);
1266
GLint State::getUnpackAlignment() const
1268
return mUnpack.alignment;
1271
void State::setUnpackRowLength(GLint rowLength)
1273
mUnpack.rowLength = rowLength;
1274
mDirtyBits.set(DIRTY_BIT_UNPACK_ROW_LENGTH);
1277
GLint State::getUnpackRowLength() const
1279
return mUnpack.rowLength;
1282
void State::setUnpackImageHeight(GLint imageHeight)
1284
mUnpack.imageHeight = imageHeight;
1285
mDirtyBits.set(DIRTY_BIT_UNPACK_IMAGE_HEIGHT);
1288
GLint State::getUnpackImageHeight() const
1290
return mUnpack.imageHeight;
1293
void State::setUnpackSkipImages(GLint skipImages)
1295
mUnpack.skipImages = skipImages;
1296
mDirtyBits.set(DIRTY_BIT_UNPACK_SKIP_IMAGES);
1299
GLint State::getUnpackSkipImages() const
1301
return mUnpack.skipImages;
1304
void State::setUnpackSkipRows(GLint skipRows)
1306
mUnpack.skipRows = skipRows;
1307
mDirtyBits.set(DIRTY_BIT_UNPACK_SKIP_ROWS);
1310
GLint State::getUnpackSkipRows() const
1312
return mUnpack.skipRows;
1315
void State::setUnpackSkipPixels(GLint skipPixels)
1317
mUnpack.skipPixels = skipPixels;
1318
mDirtyBits.set(DIRTY_BIT_UNPACK_SKIP_PIXELS);
1321
GLint State::getUnpackSkipPixels() const
1323
return mUnpack.skipPixels;
1326
const PixelUnpackState &State::getUnpackState() const
1331
PixelUnpackState &State::getUnpackState()
1336
const Debug &State::getDebug() const
1341
Debug &State::getDebug()
1346
void State::getBooleanv(GLenum pname, GLboolean *params)
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;
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;
1372
case GL_RASTERIZER_DISCARD:
1373
*params = isRasterizerDiscardEnabled() ? GL_TRUE : GL_FALSE;
1375
case GL_DEBUG_OUTPUT_SYNCHRONOUS:
1376
*params = mDebug.isOutputSynchronous() ? GL_TRUE : GL_FALSE;
1378
case GL_DEBUG_OUTPUT:
1379
*params = mDebug.isOutputEnabled() ? GL_TRUE : GL_FALSE;
1387
void State::getFloatv(GLenum pname, GLfloat *params)
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.
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:
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;
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;
1422
void State::getIntegerv(const gl::Data &data, GLenum pname, GLint *params)
1424
if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
1426
unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0_EXT);
1427
ASSERT(colorAttachment < mMaxDrawBuffers);
1428
Framebuffer *framebuffer = mDrawFramebuffer;
1429
*params = framebuffer->getDrawBufferState(colorAttachment);
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.
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;
1453
case GL_PACK_SKIP_ROWS:
1454
*params = mPack.skipRows;
1456
case GL_PACK_SKIP_PIXELS:
1457
*params = mPack.skipPixels;
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;
1464
case GL_UNPACK_SKIP_IMAGES:
1465
*params = mUnpack.skipImages;
1467
case GL_UNPACK_SKIP_ROWS:
1468
*params = mUnpack.skipRows;
1470
case GL_UNPACK_SKIP_PIXELS:
1471
*params = mUnpack.skipPixels;
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);
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:
1505
gl::Framebuffer *framebuffer = mDrawFramebuffer;
1506
if (framebuffer->checkStatus(data) == GL_FRAMEBUFFER_COMPLETE)
1510
case GL_SAMPLE_BUFFERS:
1511
if (framebuffer->getSamples(data) != 0)
1521
*params = framebuffer->getSamples(data);
1532
params[0] = mViewport.x;
1533
params[1] = mViewport.y;
1534
params[2] = mViewport.width;
1535
params[3] = mViewport.height;
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;
1543
case GL_CULL_FACE_MODE: *params = mRasterizer.cullMode; break;
1544
case GL_FRONT_FACE: *params = mRasterizer.frontFace; break;
1550
gl::Framebuffer *framebuffer = getDrawFramebuffer();
1551
const gl::FramebufferAttachment *colorbuffer = framebuffer->getFirstColorbuffer();
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;
1571
const gl::Framebuffer *framebuffer = getDrawFramebuffer();
1572
const gl::FramebufferAttachment *depthbuffer = framebuffer->getDepthbuffer();
1576
*params = depthbuffer->getDepthSize();
1584
case GL_STENCIL_BITS:
1586
const gl::Framebuffer *framebuffer = getDrawFramebuffer();
1587
const gl::FramebufferAttachment *stencilbuffer = framebuffer->getStencilbuffer();
1591
*params = stencilbuffer->getStencilSize();
1599
case GL_TEXTURE_BINDING_2D:
1600
ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
1601
*params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_2D);
1603
case GL_TEXTURE_BINDING_CUBE_MAP:
1604
ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
1606
getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_CUBE_MAP);
1608
case GL_TEXTURE_BINDING_3D:
1609
ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
1610
*params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_3D);
1612
case GL_TEXTURE_BINDING_2D_ARRAY:
1613
ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
1615
getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_2D_ARRAY);
1617
case GL_UNIFORM_BUFFER_BINDING:
1618
*params = mGenericUniformBuffer.id();
1620
case GL_TRANSFORM_FEEDBACK_BINDING:
1621
*params = mTransformFeedback.id();
1623
case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
1624
*params = mTransformFeedback->getGenericBuffer().id();
1626
case GL_COPY_READ_BUFFER_BINDING:
1627
*params = mCopyReadBuffer.id();
1629
case GL_COPY_WRITE_BUFFER_BINDING:
1630
*params = mCopyWriteBuffer.id();
1632
case GL_PIXEL_PACK_BUFFER_BINDING:
1633
*params = mPack.pixelBuffer.id();
1635
case GL_PIXEL_UNPACK_BUFFER_BINDING:
1636
*params = mUnpack.pixelBuffer.id();
1638
case GL_DEBUG_LOGGED_MESSAGES:
1639
*params = static_cast<GLint>(mDebug.getMessageCount());
1641
case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
1642
*params = static_cast<GLint>(mDebug.getNextMessageLength());
1644
case GL_DEBUG_GROUP_STACK_DEPTH:
1645
*params = static_cast<GLint>(mDebug.getGroupStackDepth());
1653
void State::getPointerv(GLenum pname, void **params) const
1657
case GL_DEBUG_CALLBACK_FUNCTION:
1658
*params = reinterpret_cast<void *>(mDebug.getCallback());
1660
case GL_DEBUG_CALLBACK_USER_PARAM:
1661
*params = const_cast<void *>(mDebug.getUserParam());
1669
bool State::getIndexedIntegerv(GLenum target, GLuint index, GLint *data)
1673
case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
1674
if (static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount())
1676
*data = mTransformFeedback->getIndexedBuffer(index).id();
1679
case GL_UNIFORM_BUFFER_BINDING:
1680
if (static_cast<size_t>(index) < mUniformBuffers.size())
1682
*data = mUniformBuffers[index].id();
1692
bool State::getIndexedInteger64v(GLenum target, GLuint index, GLint64 *data)
1696
case GL_TRANSFORM_FEEDBACK_BUFFER_START:
1697
if (static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount())
1699
*data = mTransformFeedback->getIndexedBuffer(index).getOffset();
1702
case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
1703
if (static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount())
1705
*data = mTransformFeedback->getIndexedBuffer(index).getSize();
1708
case GL_UNIFORM_BUFFER_START:
1709
if (static_cast<size_t>(index) < mUniformBuffers.size())
1711
*data = mUniformBuffers[index].getOffset();
1714
case GL_UNIFORM_BUFFER_SIZE:
1715
if (static_cast<size_t>(index) < mUniformBuffers.size())
1717
*data = mUniformBuffers[index].getSize();
1727
bool State::hasMappedBuffer(GLenum target) const
1729
if (target == GL_ARRAY_BUFFER)
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++)
1736
const gl::VertexAttribute &vertexAttrib = vertexAttribs[attribIndex];
1737
gl::Buffer *boundBuffer = vertexAttrib.buffer.get();
1738
if (vertexAttrib.enabled && boundBuffer && boundBuffer->isMapped())
1748
Buffer *buffer = getTargetBuffer(target);
1749
return (buffer && buffer->isMapped());
1753
void State::syncDirtyObjects()
1755
if (!mDirtyObjects.any())
1758
syncDirtyObjects(mDirtyObjects);
1761
void State::syncDirtyObjects(const DirtyObjects &bitset)
1763
for (auto dirtyObject : angle::IterateBitSet(bitset))
1765
switch (dirtyObject)
1767
case DIRTY_OBJECT_READ_FRAMEBUFFER:
1768
ASSERT(mReadFramebuffer);
1769
mReadFramebuffer->syncState();
1771
case DIRTY_OBJECT_DRAW_FRAMEBUFFER:
1772
ASSERT(mDrawFramebuffer);
1773
mDrawFramebuffer->syncState();
1775
case DIRTY_OBJECT_VERTEX_ARRAY:
1776
ASSERT(mVertexArray);
1777
mVertexArray->syncImplState();
1779
case DIRTY_OBJECT_PROGRAM:
1780
// TODO(jmadill): implement this
1788
mDirtyObjects &= ~bitset;
1791
void State::syncDirtyObject(GLenum target)
1793
DirtyObjects localSet;
1797
case GL_READ_FRAMEBUFFER:
1798
localSet.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
1800
case GL_DRAW_FRAMEBUFFER:
1801
localSet.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
1803
case GL_FRAMEBUFFER:
1804
localSet.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
1805
localSet.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
1807
case GL_VERTEX_ARRAY:
1808
localSet.set(DIRTY_OBJECT_VERTEX_ARRAY);
1811
localSet.set(DIRTY_OBJECT_PROGRAM);
1815
syncDirtyObjects(localSet);
1818
void State::setObjectDirty(GLenum target)
1822
case GL_READ_FRAMEBUFFER:
1823
mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
1825
case GL_DRAW_FRAMEBUFFER:
1826
mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
1828
case GL_FRAMEBUFFER:
1829
mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
1830
mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
1832
case GL_VERTEX_ARRAY:
1833
mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
1836
mDirtyObjects.set(DIRTY_OBJECT_PROGRAM);