blob: b88d72af2463f0438a24193591e45e1d56985641 [file] [log] [blame]
Shannon Woods53a94a82014-06-24 15:20:36 -04001//
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
Geoff Lang2b5420c2014-11-19 14:20:15 -05009#include "libANGLE/State.h"
Shannon Woods53a94a82014-06-24 15:20:36 -040010
Sami Väisänene45e53b2016-05-25 10:36:04 +030011#include <limits>
12#include <string.h>
13
Jamie Madill20e005b2017-04-07 14:19:22 -040014#include "common/bitset_utils.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030015#include "common/mathutil.h"
jchen10a99ed552017-09-22 08:10:32 +080016#include "common/matrix_utils.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050017#include "libANGLE/Caps.h"
jchen10a99ed552017-09-22 08:10:32 +080018#include "libANGLE/Context.h"
Geoff Lang70d0f492015-12-10 17:45:46 -050019#include "libANGLE/Debug.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050020#include "libANGLE/Framebuffer.h"
21#include "libANGLE/FramebufferAttachment.h"
22#include "libANGLE/Query.h"
23#include "libANGLE/VertexArray.h"
24#include "libANGLE/formatutils.h"
jchen10a99ed552017-09-22 08:10:32 +080025#include "libANGLE/queryconversions.h"
Shannon Woods53a94a82014-06-24 15:20:36 -040026
Olli Etuahobbf1c102016-06-28 13:31:33 +030027namespace
28{
29
30GLenum ActiveQueryType(const GLenum type)
31{
32 return (type == GL_ANY_SAMPLES_PASSED_CONSERVATIVE) ? GL_ANY_SAMPLES_PASSED : type;
33}
34
35} // anonymous namepace
36
Shannon Woods53a94a82014-06-24 15:20:36 -040037namespace gl
38{
Geoff Lang76b10c92014-09-05 16:28:14 -040039
Shannon Woods53a94a82014-06-24 15:20:36 -040040State::State()
Jamie Madille79b1e12015-11-04 16:36:37 -050041 : mMaxDrawBuffers(0),
42 mMaxCombinedTextureImageUnits(0),
43 mDepthClearValue(0),
44 mStencilClearValue(0),
45 mScissorTest(false),
46 mSampleCoverage(false),
47 mSampleCoverageValue(0),
48 mSampleCoverageInvert(false),
Jiawei Shaodb342272017-09-27 10:21:45 +080049 mSampleMask(false),
50 mMaxSampleMaskWords(0),
Jamie Madille79b1e12015-11-04 16:36:37 -050051 mStencilRef(0),
52 mStencilBackRef(0),
53 mLineWidth(0),
54 mGenerateMipmapHint(GL_NONE),
55 mFragmentShaderDerivativeHint(GL_NONE),
Geoff Langf41a7152016-09-19 15:11:17 -040056 mBindGeneratesResource(true),
Geoff Langfeb8c682017-02-13 16:07:35 -050057 mClientArraysEnabled(true),
Jamie Madille79b1e12015-11-04 16:36:37 -050058 mNearZ(0),
59 mFarZ(0),
60 mReadFramebuffer(nullptr),
61 mDrawFramebuffer(nullptr),
62 mProgram(nullptr),
63 mVertexArray(nullptr),
64 mActiveSampler(0),
Sami Väisänen74c23472016-05-09 17:30:30 +030065 mPrimitiveRestart(false),
66 mMultiSampling(false),
Geoff Lang1d2c41d2016-10-19 16:14:46 -070067 mSampleAlphaToOne(false),
Jamie Madille08a1d32017-03-07 17:24:06 -050068 mFramebufferSRGB(true),
Jamie Madillc43be722017-07-13 16:22:14 -040069 mRobustResourceInit(false),
70 mProgramBinaryCacheEnabled(false)
Shannon Woods53a94a82014-06-24 15:20:36 -040071{
Geoff Lang76b10c92014-09-05 16:28:14 -040072}
73
74State::~State()
75{
Geoff Lang76b10c92014-09-05 16:28:14 -040076}
77
Jamie Madill4928b7c2017-06-20 12:57:39 -040078void State::initialize(const Context *context,
Geoff Langf41a7152016-09-19 15:11:17 -040079 bool debug,
Geoff Langfeb8c682017-02-13 16:07:35 -050080 bool bindGeneratesResource,
Jamie Madille08a1d32017-03-07 17:24:06 -050081 bool clientArraysEnabled,
Jamie Madillc43be722017-07-13 16:22:14 -040082 bool robustResourceInit,
83 bool programBinaryCacheEnabled)
Geoff Lang76b10c92014-09-05 16:28:14 -040084{
Jamie Madill4928b7c2017-06-20 12:57:39 -040085 const Caps &caps = context->getCaps();
86 const Extensions &extensions = context->getExtensions();
87 const Version &clientVersion = context->getClientVersion();
88
Shannon Woods2df6a602014-09-26 16:12:07 -040089 mMaxDrawBuffers = caps.maxDrawBuffers;
90 mMaxCombinedTextureImageUnits = caps.maxCombinedTextureImageUnits;
Shannon Woods53a94a82014-06-24 15:20:36 -040091
Jamie Madillf75ab352015-03-16 10:46:52 -040092 setColorClearValue(0.0f, 0.0f, 0.0f, 0.0f);
Shannon Woods53a94a82014-06-24 15:20:36 -040093
94 mDepthClearValue = 1.0f;
95 mStencilClearValue = 0;
96
Shannon Woods53a94a82014-06-24 15:20:36 -040097 mScissorTest = false;
98 mScissor.x = 0;
99 mScissor.y = 0;
100 mScissor.width = 0;
101 mScissor.height = 0;
102
Shannon Woods53a94a82014-06-24 15:20:36 -0400103 mBlendColor.red = 0;
104 mBlendColor.green = 0;
105 mBlendColor.blue = 0;
106 mBlendColor.alpha = 0;
107
Shannon Woods53a94a82014-06-24 15:20:36 -0400108 mStencilRef = 0;
109 mStencilBackRef = 0;
110
111 mSampleCoverage = false;
112 mSampleCoverageValue = 1.0f;
113 mSampleCoverageInvert = false;
Jiawei Shaodb342272017-09-27 10:21:45 +0800114
115 mMaxSampleMaskWords = caps.maxSampleMaskWords;
116 mSampleMask = false;
117 mSampleMaskValues.fill(~GLbitfield(0));
118
Shannon Woods53a94a82014-06-24 15:20:36 -0400119 mGenerateMipmapHint = GL_DONT_CARE;
120 mFragmentShaderDerivativeHint = GL_DONT_CARE;
121
Geoff Langf41a7152016-09-19 15:11:17 -0400122 mBindGeneratesResource = bindGeneratesResource;
Geoff Langfeb8c682017-02-13 16:07:35 -0500123 mClientArraysEnabled = clientArraysEnabled;
Geoff Langf41a7152016-09-19 15:11:17 -0400124
Shannon Woods53a94a82014-06-24 15:20:36 -0400125 mLineWidth = 1.0f;
126
127 mViewport.x = 0;
128 mViewport.y = 0;
129 mViewport.width = 0;
130 mViewport.height = 0;
131 mNearZ = 0.0f;
132 mFarZ = 1.0f;
133
134 mBlend.colorMaskRed = true;
135 mBlend.colorMaskGreen = true;
136 mBlend.colorMaskBlue = true;
137 mBlend.colorMaskAlpha = true;
138
Geoff Lang76b10c92014-09-05 16:28:14 -0400139 mActiveSampler = 0;
140
Shannon Woods23e05002014-09-22 19:07:27 -0400141 mVertexAttribCurrentValues.resize(caps.maxVertexAttributes);
Shannon Woods53a94a82014-06-24 15:20:36 -0400142
Geoff Lang4dc3af02016-11-18 14:09:27 -0500143 mUniformBuffers.resize(caps.maxUniformBufferBindings);
Shannon Woodsf3acaf92014-09-23 18:07:11 -0400144
Geoff Lang76b10c92014-09-05 16:28:14 -0400145 mSamplerTextures[GL_TEXTURE_2D].resize(caps.maxCombinedTextureImageUnits);
146 mSamplerTextures[GL_TEXTURE_CUBE_MAP].resize(caps.maxCombinedTextureImageUnits);
Geoff Langeb66a6e2016-10-31 13:06:12 -0400147 if (clientVersion >= Version(3, 0))
Shannon Woods53a94a82014-06-24 15:20:36 -0400148 {
Geoff Lang76b10c92014-09-05 16:28:14 -0400149 // TODO: These could also be enabled via extension
150 mSamplerTextures[GL_TEXTURE_2D_ARRAY].resize(caps.maxCombinedTextureImageUnits);
151 mSamplerTextures[GL_TEXTURE_3D].resize(caps.maxCombinedTextureImageUnits);
Shannon Woods53a94a82014-06-24 15:20:36 -0400152 }
Geoff Lang3b573612016-10-31 14:08:10 -0400153 if (clientVersion >= Version(3, 1))
154 {
155 mSamplerTextures[GL_TEXTURE_2D_MULTISAMPLE].resize(caps.maxCombinedTextureImageUnits);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800156
157 mAtomicCounterBuffers.resize(caps.maxAtomicCounterBufferBindings);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800158 mShaderStorageBuffers.resize(caps.maxShaderStorageBufferBindings);
Xinghua Cao65ec0b22017-03-28 16:10:52 +0800159 mImageUnits.resize(caps.maxImageUnits);
Geoff Lang3b573612016-10-31 14:08:10 -0400160 }
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400161 if (extensions.textureRectangle)
162 {
163 mSamplerTextures[GL_TEXTURE_RECTANGLE_ANGLE].resize(caps.maxCombinedTextureImageUnits);
164 }
Ian Ewellbda75592016-04-18 17:25:54 -0400165 if (extensions.eglImageExternal || extensions.eglStreamConsumerExternal)
166 {
167 mSamplerTextures[GL_TEXTURE_EXTERNAL_OES].resize(caps.maxCombinedTextureImageUnits);
168 }
Jamie Madill81c2e252017-09-09 23:32:46 -0400169 mCompleteTextureCache.resize(caps.maxCombinedTextureImageUnits, nullptr);
170 mCompleteTextureBindings.reserve(caps.maxCombinedTextureImageUnits);
171 for (uint32_t textureIndex = 0; textureIndex < caps.maxCombinedTextureImageUnits;
172 ++textureIndex)
173 {
174 mCompleteTextureBindings.emplace_back(OnAttachmentDirtyBinding(this, textureIndex));
175 }
Shannon Woods53a94a82014-06-24 15:20:36 -0400176
Geoff Lang76b10c92014-09-05 16:28:14 -0400177 mSamplers.resize(caps.maxCombinedTextureImageUnits);
Shannon Woods53a94a82014-06-24 15:20:36 -0400178
Jamie Madill4928b7c2017-06-20 12:57:39 -0400179 mActiveQueries[GL_ANY_SAMPLES_PASSED].set(context, nullptr);
180 mActiveQueries[GL_ANY_SAMPLES_PASSED_CONSERVATIVE].set(context, nullptr);
181 mActiveQueries[GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN].set(context, nullptr);
182 mActiveQueries[GL_TIME_ELAPSED_EXT].set(context, nullptr);
183 mActiveQueries[GL_COMMANDS_COMPLETED_CHROMIUM].set(context, nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -0400184
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500185 mProgram = nullptr;
Shannon Woods53a94a82014-06-24 15:20:36 -0400186
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500187 mReadFramebuffer = nullptr;
188 mDrawFramebuffer = nullptr;
Jamie Madillb4b53c52015-02-03 15:22:48 -0500189
190 mPrimitiveRestart = false;
Geoff Lang70d0f492015-12-10 17:45:46 -0500191
192 mDebug.setOutputEnabled(debug);
193 mDebug.setMaxLoggedMessages(extensions.maxDebugLoggedMessages);
Sami Väisänen74c23472016-05-09 17:30:30 +0300194
Geoff Lang488130e2017-09-27 13:53:11 -0400195 mMultiSampling = true;
196 mSampleAlphaToOne = false;
Sami Väisänena797e062016-05-12 15:23:40 +0300197
198 mCoverageModulation = GL_NONE;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300199
200 angle::Matrix<GLfloat>::setToIdentity(mPathMatrixProj);
201 angle::Matrix<GLfloat>::setToIdentity(mPathMatrixMV);
202 mPathStencilFunc = GL_ALWAYS;
203 mPathStencilRef = 0;
204 mPathStencilMask = std::numeric_limits<GLuint>::max();
Jamie Madille08a1d32017-03-07 17:24:06 -0500205
206 mRobustResourceInit = robustResourceInit;
Jamie Madillc43be722017-07-13 16:22:14 -0400207 mProgramBinaryCacheEnabled = programBinaryCacheEnabled;
Shannon Woods53a94a82014-06-24 15:20:36 -0400208}
209
Jamie Madill6c1f6712017-02-14 19:08:04 -0500210void State::reset(const Context *context)
Shannon Woods53a94a82014-06-24 15:20:36 -0400211{
Jamie Madill8693bdb2017-09-02 15:32:14 -0400212 for (auto &bindingVec : mSamplerTextures)
Shannon Woods53a94a82014-06-24 15:20:36 -0400213 {
Jamie Madill8693bdb2017-09-02 15:32:14 -0400214 TextureBindingVector &textureVector = bindingVec.second;
Geoff Lang76b10c92014-09-05 16:28:14 -0400215 for (size_t textureIdx = 0; textureIdx < textureVector.size(); textureIdx++)
Shannon Woods53a94a82014-06-24 15:20:36 -0400216 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400217 textureVector[textureIdx].set(context, nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -0400218 }
219 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400220 for (size_t samplerIdx = 0; samplerIdx < mSamplers.size(); samplerIdx++)
221 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400222 mSamplers[samplerIdx].set(context, nullptr);
Geoff Lang76b10c92014-09-05 16:28:14 -0400223 }
Shannon Woods53a94a82014-06-24 15:20:36 -0400224
Xinghua Cao65ec0b22017-03-28 16:10:52 +0800225 for (auto &imageUnit : mImageUnits)
226 {
227 imageUnit.texture.set(context, nullptr);
228 imageUnit.level = 0;
229 imageUnit.layered = false;
230 imageUnit.layer = 0;
231 imageUnit.access = GL_READ_ONLY;
232 imageUnit.format = GL_R32UI;
233 }
234
Jamie Madill4928b7c2017-06-20 12:57:39 -0400235 mArrayBuffer.set(context, nullptr);
236 mDrawIndirectBuffer.set(context, nullptr);
237 mRenderbuffer.set(context, nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -0400238
Geoff Lang7dd2e102014-11-10 15:19:26 -0500239 if (mProgram)
240 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500241 mProgram->release(context);
Geoff Lang7dd2e102014-11-10 15:19:26 -0500242 }
Yunchao Hed7297bf2017-04-19 15:27:10 +0800243 mProgram = nullptr;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500244
Yunchao Hea336b902017-08-02 16:05:21 +0800245 mProgramPipeline.set(context, nullptr);
246
Jamie Madill4928b7c2017-06-20 12:57:39 -0400247 mTransformFeedback.set(context, nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -0400248
249 for (State::ActiveQueryMap::iterator i = mActiveQueries.begin(); i != mActiveQueries.end(); i++)
250 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400251 i->second.set(context, nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -0400252 }
253
Jamie Madill4928b7c2017-06-20 12:57:39 -0400254 mGenericUniformBuffer.set(context, nullptr);
Shannon Woods8299bb02014-09-26 18:55:43 -0400255 for (BufferVector::iterator bufItr = mUniformBuffers.begin(); bufItr != mUniformBuffers.end(); ++bufItr)
Shannon Woods53a94a82014-06-24 15:20:36 -0400256 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400257 bufItr->set(context, nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -0400258 }
259
Jamie Madill4928b7c2017-06-20 12:57:39 -0400260 mCopyReadBuffer.set(context, nullptr);
261 mCopyWriteBuffer.set(context, nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -0400262
Jamie Madill4928b7c2017-06-20 12:57:39 -0400263 mPack.pixelBuffer.set(context, nullptr);
264 mUnpack.pixelBuffer.set(context, nullptr);
Geoff Lang7dd2e102014-11-10 15:19:26 -0500265
Jamie Madill4928b7c2017-06-20 12:57:39 -0400266 mGenericAtomicCounterBuffer.set(context, nullptr);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800267 for (auto &buf : mAtomicCounterBuffers)
268 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400269 buf.set(context, nullptr);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800270 }
271
Jamie Madill4928b7c2017-06-20 12:57:39 -0400272 mGenericShaderStorageBuffer.set(context, nullptr);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800273 for (auto &buf : mShaderStorageBuffers)
274 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400275 buf.set(context, nullptr);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800276 }
277
Sami Väisänene45e53b2016-05-25 10:36:04 +0300278 angle::Matrix<GLfloat>::setToIdentity(mPathMatrixProj);
279 angle::Matrix<GLfloat>::setToIdentity(mPathMatrixMV);
280 mPathStencilFunc = GL_ALWAYS;
281 mPathStencilRef = 0;
282 mPathStencilMask = std::numeric_limits<GLuint>::max();
283
Jamie Madill1b94d432015-08-07 13:23:23 -0400284 // TODO(jmadill): Is this necessary?
285 setAllDirtyBits();
Shannon Woods53a94a82014-06-24 15:20:36 -0400286}
287
288const RasterizerState &State::getRasterizerState() const
289{
290 return mRasterizer;
291}
292
293const BlendState &State::getBlendState() const
294{
295 return mBlend;
296}
297
298const DepthStencilState &State::getDepthStencilState() const
299{
300 return mDepthStencil;
301}
302
Jamie Madillf75ab352015-03-16 10:46:52 -0400303void State::setColorClearValue(float red, float green, float blue, float alpha)
Shannon Woods53a94a82014-06-24 15:20:36 -0400304{
305 mColorClearValue.red = red;
306 mColorClearValue.green = green;
307 mColorClearValue.blue = blue;
308 mColorClearValue.alpha = alpha;
Jamie Madill1b94d432015-08-07 13:23:23 -0400309 mDirtyBits.set(DIRTY_BIT_CLEAR_COLOR);
Shannon Woods53a94a82014-06-24 15:20:36 -0400310}
311
Jamie Madillf75ab352015-03-16 10:46:52 -0400312void State::setDepthClearValue(float depth)
Shannon Woods53a94a82014-06-24 15:20:36 -0400313{
314 mDepthClearValue = depth;
Jamie Madill1b94d432015-08-07 13:23:23 -0400315 mDirtyBits.set(DIRTY_BIT_CLEAR_DEPTH);
Shannon Woods53a94a82014-06-24 15:20:36 -0400316}
317
Jamie Madillf75ab352015-03-16 10:46:52 -0400318void State::setStencilClearValue(int stencil)
Shannon Woods53a94a82014-06-24 15:20:36 -0400319{
320 mStencilClearValue = stencil;
Jamie Madill1b94d432015-08-07 13:23:23 -0400321 mDirtyBits.set(DIRTY_BIT_CLEAR_STENCIL);
Shannon Woods53a94a82014-06-24 15:20:36 -0400322}
323
Shannon Woods53a94a82014-06-24 15:20:36 -0400324void State::setColorMask(bool red, bool green, bool blue, bool alpha)
325{
326 mBlend.colorMaskRed = red;
327 mBlend.colorMaskGreen = green;
328 mBlend.colorMaskBlue = blue;
329 mBlend.colorMaskAlpha = alpha;
Jamie Madill1b94d432015-08-07 13:23:23 -0400330 mDirtyBits.set(DIRTY_BIT_COLOR_MASK);
Shannon Woods53a94a82014-06-24 15:20:36 -0400331}
332
333void State::setDepthMask(bool mask)
334{
335 mDepthStencil.depthMask = mask;
Jamie Madill1b94d432015-08-07 13:23:23 -0400336 mDirtyBits.set(DIRTY_BIT_DEPTH_MASK);
Shannon Woods53a94a82014-06-24 15:20:36 -0400337}
338
339bool State::isRasterizerDiscardEnabled() const
340{
341 return mRasterizer.rasterizerDiscard;
342}
343
344void State::setRasterizerDiscard(bool enabled)
345{
346 mRasterizer.rasterizerDiscard = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400347 mDirtyBits.set(DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400348}
349
350bool State::isCullFaceEnabled() const
351{
352 return mRasterizer.cullFace;
353}
354
355void State::setCullFace(bool enabled)
356{
357 mRasterizer.cullFace = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400358 mDirtyBits.set(DIRTY_BIT_CULL_FACE_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400359}
360
361void State::setCullMode(GLenum mode)
362{
363 mRasterizer.cullMode = mode;
Jamie Madill1b94d432015-08-07 13:23:23 -0400364 mDirtyBits.set(DIRTY_BIT_CULL_FACE);
Shannon Woods53a94a82014-06-24 15:20:36 -0400365}
366
367void State::setFrontFace(GLenum front)
368{
369 mRasterizer.frontFace = front;
Jamie Madill1b94d432015-08-07 13:23:23 -0400370 mDirtyBits.set(DIRTY_BIT_FRONT_FACE);
Shannon Woods53a94a82014-06-24 15:20:36 -0400371}
372
373bool State::isDepthTestEnabled() const
374{
375 return mDepthStencil.depthTest;
376}
377
378void State::setDepthTest(bool enabled)
379{
380 mDepthStencil.depthTest = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400381 mDirtyBits.set(DIRTY_BIT_DEPTH_TEST_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400382}
383
384void State::setDepthFunc(GLenum depthFunc)
385{
386 mDepthStencil.depthFunc = depthFunc;
Jamie Madill1b94d432015-08-07 13:23:23 -0400387 mDirtyBits.set(DIRTY_BIT_DEPTH_FUNC);
Shannon Woods53a94a82014-06-24 15:20:36 -0400388}
389
390void State::setDepthRange(float zNear, float zFar)
391{
392 mNearZ = zNear;
393 mFarZ = zFar;
Jamie Madill1b94d432015-08-07 13:23:23 -0400394 mDirtyBits.set(DIRTY_BIT_DEPTH_RANGE);
Shannon Woods53a94a82014-06-24 15:20:36 -0400395}
396
Geoff Langd42f5b82015-04-16 14:03:29 -0400397float State::getNearPlane() const
Shannon Woods53a94a82014-06-24 15:20:36 -0400398{
Geoff Langd42f5b82015-04-16 14:03:29 -0400399 return mNearZ;
400}
401
402float State::getFarPlane() const
403{
404 return mFarZ;
Shannon Woods53a94a82014-06-24 15:20:36 -0400405}
406
407bool State::isBlendEnabled() const
408{
409 return mBlend.blend;
410}
411
412void State::setBlend(bool enabled)
413{
414 mBlend.blend = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400415 mDirtyBits.set(DIRTY_BIT_BLEND_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400416}
417
418void State::setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha)
419{
420 mBlend.sourceBlendRGB = sourceRGB;
421 mBlend.destBlendRGB = destRGB;
422 mBlend.sourceBlendAlpha = sourceAlpha;
423 mBlend.destBlendAlpha = destAlpha;
Jamie Madill1b94d432015-08-07 13:23:23 -0400424 mDirtyBits.set(DIRTY_BIT_BLEND_FUNCS);
Shannon Woods53a94a82014-06-24 15:20:36 -0400425}
426
427void State::setBlendColor(float red, float green, float blue, float alpha)
428{
429 mBlendColor.red = red;
430 mBlendColor.green = green;
431 mBlendColor.blue = blue;
432 mBlendColor.alpha = alpha;
Jamie Madill1b94d432015-08-07 13:23:23 -0400433 mDirtyBits.set(DIRTY_BIT_BLEND_COLOR);
Shannon Woods53a94a82014-06-24 15:20:36 -0400434}
435
436void State::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation)
437{
438 mBlend.blendEquationRGB = rgbEquation;
439 mBlend.blendEquationAlpha = alphaEquation;
Jamie Madill1b94d432015-08-07 13:23:23 -0400440 mDirtyBits.set(DIRTY_BIT_BLEND_EQUATIONS);
Shannon Woods53a94a82014-06-24 15:20:36 -0400441}
442
443const ColorF &State::getBlendColor() const
444{
445 return mBlendColor;
446}
447
448bool State::isStencilTestEnabled() const
449{
450 return mDepthStencil.stencilTest;
451}
452
453void State::setStencilTest(bool enabled)
454{
455 mDepthStencil.stencilTest = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400456 mDirtyBits.set(DIRTY_BIT_STENCIL_TEST_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400457}
458
459void State::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask)
460{
461 mDepthStencil.stencilFunc = stencilFunc;
462 mStencilRef = (stencilRef > 0) ? stencilRef : 0;
463 mDepthStencil.stencilMask = stencilMask;
Jamie Madill1b94d432015-08-07 13:23:23 -0400464 mDirtyBits.set(DIRTY_BIT_STENCIL_FUNCS_FRONT);
Shannon Woods53a94a82014-06-24 15:20:36 -0400465}
466
467void State::setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask)
468{
469 mDepthStencil.stencilBackFunc = stencilBackFunc;
470 mStencilBackRef = (stencilBackRef > 0) ? stencilBackRef : 0;
471 mDepthStencil.stencilBackMask = stencilBackMask;
Jamie Madill1b94d432015-08-07 13:23:23 -0400472 mDirtyBits.set(DIRTY_BIT_STENCIL_FUNCS_BACK);
Shannon Woods53a94a82014-06-24 15:20:36 -0400473}
474
475void State::setStencilWritemask(GLuint stencilWritemask)
476{
477 mDepthStencil.stencilWritemask = stencilWritemask;
Jamie Madill1b94d432015-08-07 13:23:23 -0400478 mDirtyBits.set(DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
Shannon Woods53a94a82014-06-24 15:20:36 -0400479}
480
481void State::setStencilBackWritemask(GLuint stencilBackWritemask)
482{
483 mDepthStencil.stencilBackWritemask = stencilBackWritemask;
Jamie Madill1b94d432015-08-07 13:23:23 -0400484 mDirtyBits.set(DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Shannon Woods53a94a82014-06-24 15:20:36 -0400485}
486
487void State::setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass)
488{
489 mDepthStencil.stencilFail = stencilFail;
490 mDepthStencil.stencilPassDepthFail = stencilPassDepthFail;
491 mDepthStencil.stencilPassDepthPass = stencilPassDepthPass;
Jamie Madill1b94d432015-08-07 13:23:23 -0400492 mDirtyBits.set(DIRTY_BIT_STENCIL_OPS_FRONT);
Shannon Woods53a94a82014-06-24 15:20:36 -0400493}
494
495void State::setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass)
496{
497 mDepthStencil.stencilBackFail = stencilBackFail;
498 mDepthStencil.stencilBackPassDepthFail = stencilBackPassDepthFail;
499 mDepthStencil.stencilBackPassDepthPass = stencilBackPassDepthPass;
Jamie Madill1b94d432015-08-07 13:23:23 -0400500 mDirtyBits.set(DIRTY_BIT_STENCIL_OPS_BACK);
Shannon Woods53a94a82014-06-24 15:20:36 -0400501}
502
503GLint State::getStencilRef() const
504{
505 return mStencilRef;
506}
507
508GLint State::getStencilBackRef() const
509{
510 return mStencilBackRef;
511}
512
513bool State::isPolygonOffsetFillEnabled() const
514{
515 return mRasterizer.polygonOffsetFill;
516}
517
518void State::setPolygonOffsetFill(bool enabled)
519{
Jamie Madill1b94d432015-08-07 13:23:23 -0400520 mRasterizer.polygonOffsetFill = enabled;
521 mDirtyBits.set(DIRTY_BIT_POLYGON_OFFSET_FILL_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400522}
523
524void State::setPolygonOffsetParams(GLfloat factor, GLfloat units)
525{
526 // An application can pass NaN values here, so handle this gracefully
527 mRasterizer.polygonOffsetFactor = factor != factor ? 0.0f : factor;
528 mRasterizer.polygonOffsetUnits = units != units ? 0.0f : units;
Jamie Madill1b94d432015-08-07 13:23:23 -0400529 mDirtyBits.set(DIRTY_BIT_POLYGON_OFFSET);
Shannon Woods53a94a82014-06-24 15:20:36 -0400530}
531
532bool State::isSampleAlphaToCoverageEnabled() const
533{
534 return mBlend.sampleAlphaToCoverage;
535}
536
537void State::setSampleAlphaToCoverage(bool enabled)
538{
539 mBlend.sampleAlphaToCoverage = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400540 mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400541}
542
543bool State::isSampleCoverageEnabled() const
544{
545 return mSampleCoverage;
546}
547
548void State::setSampleCoverage(bool enabled)
549{
550 mSampleCoverage = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400551 mDirtyBits.set(DIRTY_BIT_SAMPLE_COVERAGE_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400552}
553
554void State::setSampleCoverageParams(GLclampf value, bool invert)
555{
556 mSampleCoverageValue = value;
557 mSampleCoverageInvert = invert;
Jamie Madill1b94d432015-08-07 13:23:23 -0400558 mDirtyBits.set(DIRTY_BIT_SAMPLE_COVERAGE);
Shannon Woods53a94a82014-06-24 15:20:36 -0400559}
560
Geoff Lang0fbb6002015-04-16 11:11:53 -0400561GLclampf State::getSampleCoverageValue() const
Shannon Woods53a94a82014-06-24 15:20:36 -0400562{
Geoff Lang0fbb6002015-04-16 11:11:53 -0400563 return mSampleCoverageValue;
564}
Shannon Woods53a94a82014-06-24 15:20:36 -0400565
Geoff Lang0fbb6002015-04-16 11:11:53 -0400566bool State::getSampleCoverageInvert() const
567{
568 return mSampleCoverageInvert;
Shannon Woods53a94a82014-06-24 15:20:36 -0400569}
570
Jiawei Shaodb342272017-09-27 10:21:45 +0800571bool State::isSampleMaskEnabled() const
572{
573 return mSampleMask;
574}
575
576void State::setSampleMaskEnabled(bool enabled)
577{
578 mSampleMask = enabled;
579 mDirtyBits.set(DIRTY_BIT_SAMPLE_MASK_ENABLED);
580}
581
582void State::setSampleMaskParams(GLuint maskNumber, GLbitfield mask)
583{
584 ASSERT(maskNumber < mMaxSampleMaskWords);
585 mSampleMaskValues[maskNumber] = mask;
586 mDirtyBits.set(DIRTY_BIT_SAMPLE_MASK_WORD_0 + maskNumber);
587}
588
589GLbitfield State::getSampleMaskWord(GLuint maskNumber) const
590{
591 ASSERT(maskNumber < mMaxSampleMaskWords);
592 return mSampleMaskValues[maskNumber];
593}
594
595GLuint State::getMaxSampleMaskWords() const
596{
597 return mMaxSampleMaskWords;
598}
599
Sami Väisänen74c23472016-05-09 17:30:30 +0300600void State::setSampleAlphaToOne(bool enabled)
601{
602 mSampleAlphaToOne = enabled;
603 mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_ONE);
604}
605
606bool State::isSampleAlphaToOneEnabled() const
607{
608 return mSampleAlphaToOne;
609}
610
611void State::setMultisampling(bool enabled)
612{
613 mMultiSampling = enabled;
614 mDirtyBits.set(DIRTY_BIT_MULTISAMPLING);
615}
616
617bool State::isMultisamplingEnabled() const
618{
619 return mMultiSampling;
620}
621
Shannon Woods53a94a82014-06-24 15:20:36 -0400622bool State::isScissorTestEnabled() const
623{
624 return mScissorTest;
625}
626
627void State::setScissorTest(bool enabled)
628{
629 mScissorTest = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400630 mDirtyBits.set(DIRTY_BIT_SCISSOR_TEST_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400631}
632
633void State::setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height)
634{
635 mScissor.x = x;
636 mScissor.y = y;
637 mScissor.width = width;
638 mScissor.height = height;
Jamie Madill1b94d432015-08-07 13:23:23 -0400639 mDirtyBits.set(DIRTY_BIT_SCISSOR);
Shannon Woods53a94a82014-06-24 15:20:36 -0400640}
641
642const Rectangle &State::getScissor() const
643{
644 return mScissor;
645}
646
647bool State::isDitherEnabled() const
648{
649 return mBlend.dither;
650}
651
652void State::setDither(bool enabled)
653{
654 mBlend.dither = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400655 mDirtyBits.set(DIRTY_BIT_DITHER_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400656}
657
Jamie Madillb4b53c52015-02-03 15:22:48 -0500658bool State::isPrimitiveRestartEnabled() const
659{
660 return mPrimitiveRestart;
661}
662
663void State::setPrimitiveRestart(bool enabled)
664{
665 mPrimitiveRestart = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400666 mDirtyBits.set(DIRTY_BIT_PRIMITIVE_RESTART_ENABLED);
Jamie Madillb4b53c52015-02-03 15:22:48 -0500667}
668
Shannon Woods53a94a82014-06-24 15:20:36 -0400669void State::setEnableFeature(GLenum feature, bool enabled)
670{
671 switch (feature)
672 {
Sami Väisänen74c23472016-05-09 17:30:30 +0300673 case GL_MULTISAMPLE_EXT: setMultisampling(enabled); break;
674 case GL_SAMPLE_ALPHA_TO_ONE_EXT: setSampleAlphaToOne(enabled); break;
Shannon Woods53a94a82014-06-24 15:20:36 -0400675 case GL_CULL_FACE: setCullFace(enabled); break;
676 case GL_POLYGON_OFFSET_FILL: setPolygonOffsetFill(enabled); break;
677 case GL_SAMPLE_ALPHA_TO_COVERAGE: setSampleAlphaToCoverage(enabled); break;
678 case GL_SAMPLE_COVERAGE: setSampleCoverage(enabled); break;
679 case GL_SCISSOR_TEST: setScissorTest(enabled); break;
680 case GL_STENCIL_TEST: setStencilTest(enabled); break;
681 case GL_DEPTH_TEST: setDepthTest(enabled); break;
682 case GL_BLEND: setBlend(enabled); break;
683 case GL_DITHER: setDither(enabled); break;
Jamie Madillb4b53c52015-02-03 15:22:48 -0500684 case GL_PRIMITIVE_RESTART_FIXED_INDEX: setPrimitiveRestart(enabled); break;
Shannon Woods53a94a82014-06-24 15:20:36 -0400685 case GL_RASTERIZER_DISCARD: setRasterizerDiscard(enabled); break;
Geoff Lang3b573612016-10-31 14:08:10 -0400686 case GL_SAMPLE_MASK:
Jiawei Shaodb342272017-09-27 10:21:45 +0800687 setSampleMaskEnabled(enabled);
Geoff Lang3b573612016-10-31 14:08:10 -0400688 break;
Geoff Lang70d0f492015-12-10 17:45:46 -0500689 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
690 mDebug.setOutputSynchronous(enabled);
691 break;
692 case GL_DEBUG_OUTPUT:
693 mDebug.setOutputEnabled(enabled);
694 break;
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700695 case GL_FRAMEBUFFER_SRGB_EXT:
696 setFramebufferSRGB(enabled);
697 break;
Shannon Woods53a94a82014-06-24 15:20:36 -0400698 default: UNREACHABLE();
699 }
700}
701
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700702bool State::getEnableFeature(GLenum feature) const
Shannon Woods53a94a82014-06-24 15:20:36 -0400703{
704 switch (feature)
705 {
Sami Väisänen74c23472016-05-09 17:30:30 +0300706 case GL_MULTISAMPLE_EXT: return isMultisamplingEnabled();
707 case GL_SAMPLE_ALPHA_TO_ONE_EXT: return isSampleAlphaToOneEnabled();
Shannon Woods53a94a82014-06-24 15:20:36 -0400708 case GL_CULL_FACE: return isCullFaceEnabled();
709 case GL_POLYGON_OFFSET_FILL: return isPolygonOffsetFillEnabled();
710 case GL_SAMPLE_ALPHA_TO_COVERAGE: return isSampleAlphaToCoverageEnabled();
711 case GL_SAMPLE_COVERAGE: return isSampleCoverageEnabled();
712 case GL_SCISSOR_TEST: return isScissorTestEnabled();
713 case GL_STENCIL_TEST: return isStencilTestEnabled();
714 case GL_DEPTH_TEST: return isDepthTestEnabled();
715 case GL_BLEND: return isBlendEnabled();
716 case GL_DITHER: return isDitherEnabled();
Jamie Madillb4b53c52015-02-03 15:22:48 -0500717 case GL_PRIMITIVE_RESTART_FIXED_INDEX: return isPrimitiveRestartEnabled();
Shannon Woods53a94a82014-06-24 15:20:36 -0400718 case GL_RASTERIZER_DISCARD: return isRasterizerDiscardEnabled();
Geoff Langb5e997f2016-12-06 10:55:34 -0500719 case GL_SAMPLE_MASK:
Jiawei Shaodb342272017-09-27 10:21:45 +0800720 return isSampleMaskEnabled();
Geoff Lang70d0f492015-12-10 17:45:46 -0500721 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
722 return mDebug.isOutputSynchronous();
723 case GL_DEBUG_OUTPUT:
724 return mDebug.isOutputEnabled();
Geoff Langf41a7152016-09-19 15:11:17 -0400725 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
726 return isBindGeneratesResourceEnabled();
Geoff Langfeb8c682017-02-13 16:07:35 -0500727 case GL_CLIENT_ARRAYS_ANGLE:
728 return areClientArraysEnabled();
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700729 case GL_FRAMEBUFFER_SRGB_EXT:
730 return getFramebufferSRGB();
Jamie Madille08a1d32017-03-07 17:24:06 -0500731 case GL_CONTEXT_ROBUST_RESOURCE_INITIALIZATION_ANGLE:
732 return mRobustResourceInit;
Jamie Madillc43be722017-07-13 16:22:14 -0400733 case GL_PROGRAM_CACHE_ENABLED_ANGLE:
734 return mProgramBinaryCacheEnabled;
735
736 default:
737 UNREACHABLE();
738 return false;
Shannon Woods53a94a82014-06-24 15:20:36 -0400739 }
740}
741
742void State::setLineWidth(GLfloat width)
743{
744 mLineWidth = width;
Jamie Madill1b94d432015-08-07 13:23:23 -0400745 mDirtyBits.set(DIRTY_BIT_LINE_WIDTH);
Shannon Woods53a94a82014-06-24 15:20:36 -0400746}
747
Geoff Lang4b3f4162015-04-16 13:22:05 -0400748float State::getLineWidth() const
749{
750 return mLineWidth;
751}
752
Shannon Woods53a94a82014-06-24 15:20:36 -0400753void State::setGenerateMipmapHint(GLenum hint)
754{
755 mGenerateMipmapHint = hint;
Jamie Madill1b94d432015-08-07 13:23:23 -0400756 mDirtyBits.set(DIRTY_BIT_GENERATE_MIPMAP_HINT);
Shannon Woods53a94a82014-06-24 15:20:36 -0400757}
758
759void State::setFragmentShaderDerivativeHint(GLenum hint)
760{
761 mFragmentShaderDerivativeHint = hint;
Jamie Madill1b94d432015-08-07 13:23:23 -0400762 mDirtyBits.set(DIRTY_BIT_SHADER_DERIVATIVE_HINT);
Shannon Woods53a94a82014-06-24 15:20:36 -0400763 // TODO: Propagate the hint to shader translator so we can write
764 // ddx, ddx_coarse, or ddx_fine depending on the hint.
765 // Ignore for now. It is valid for implementations to ignore hint.
766}
767
Geoff Langf41a7152016-09-19 15:11:17 -0400768bool State::isBindGeneratesResourceEnabled() const
769{
770 return mBindGeneratesResource;
771}
772
Geoff Langfeb8c682017-02-13 16:07:35 -0500773bool State::areClientArraysEnabled() const
774{
775 return mClientArraysEnabled;
776}
777
Shannon Woods53a94a82014-06-24 15:20:36 -0400778void State::setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height)
779{
780 mViewport.x = x;
781 mViewport.y = y;
782 mViewport.width = width;
783 mViewport.height = height;
Jamie Madill1b94d432015-08-07 13:23:23 -0400784 mDirtyBits.set(DIRTY_BIT_VIEWPORT);
Shannon Woods53a94a82014-06-24 15:20:36 -0400785}
786
787const Rectangle &State::getViewport() const
788{
789 return mViewport;
790}
791
792void State::setActiveSampler(unsigned int active)
793{
794 mActiveSampler = active;
795}
796
797unsigned int State::getActiveSampler() const
798{
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700799 return static_cast<unsigned int>(mActiveSampler);
Shannon Woods53a94a82014-06-24 15:20:36 -0400800}
801
Jamie Madill4928b7c2017-06-20 12:57:39 -0400802void State::setSamplerTexture(const Context *context, GLenum type, Texture *texture)
Shannon Woods53a94a82014-06-24 15:20:36 -0400803{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400804 mSamplerTextures[type][mActiveSampler].set(context, texture);
Jamie Madill81c2e252017-09-09 23:32:46 -0400805 mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS);
806 mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES);
Shannon Woods53a94a82014-06-24 15:20:36 -0400807}
808
Jamie Madillc29968b2016-01-20 11:17:23 -0500809Texture *State::getTargetTexture(GLenum target) const
810{
811 return getSamplerTexture(static_cast<unsigned int>(mActiveSampler), target);
812}
813
Geoff Lang76b10c92014-09-05 16:28:14 -0400814Texture *State::getSamplerTexture(unsigned int sampler, GLenum type) const
Shannon Woods53a94a82014-06-24 15:20:36 -0400815{
Jamie Madill5864ac22015-01-12 14:43:07 -0500816 const auto it = mSamplerTextures.find(type);
817 ASSERT(it != mSamplerTextures.end());
Jamie Madill3d3d2f22015-09-23 16:47:51 -0400818 ASSERT(sampler < it->second.size());
Jamie Madill5864ac22015-01-12 14:43:07 -0500819 return it->second[sampler].get();
Shannon Woods53a94a82014-06-24 15:20:36 -0400820}
821
Geoff Lang76b10c92014-09-05 16:28:14 -0400822GLuint State::getSamplerTextureId(unsigned int sampler, GLenum type) const
Shannon Woods53a94a82014-06-24 15:20:36 -0400823{
Jamie Madill5864ac22015-01-12 14:43:07 -0500824 const auto it = mSamplerTextures.find(type);
825 ASSERT(it != mSamplerTextures.end());
Jamie Madill3d3d2f22015-09-23 16:47:51 -0400826 ASSERT(sampler < it->second.size());
Jamie Madill5864ac22015-01-12 14:43:07 -0500827 return it->second[sampler].id();
Shannon Woods53a94a82014-06-24 15:20:36 -0400828}
829
Jamie Madilla02315b2017-02-23 14:14:47 -0500830void State::detachTexture(const Context *context, const TextureMap &zeroTextures, GLuint texture)
Shannon Woods53a94a82014-06-24 15:20:36 -0400831{
832 // Textures have a detach method on State rather than a simple
833 // removeBinding, because the zero/null texture objects are managed
834 // separately, and don't have to go through the Context's maps or
835 // the ResourceManager.
836
837 // [OpenGL ES 2.0.24] section 3.8 page 84:
838 // If a texture object is deleted, it is as if all texture units which are bound to that texture object are
839 // rebound to texture object zero
840
Corentin Walleza2257da2016-04-19 16:43:12 -0400841 for (auto &bindingVec : mSamplerTextures)
Shannon Woods53a94a82014-06-24 15:20:36 -0400842 {
Corentin Walleza2257da2016-04-19 16:43:12 -0400843 GLenum textureType = bindingVec.first;
844 TextureBindingVector &textureVector = bindingVec.second;
Jamie Madill81c2e252017-09-09 23:32:46 -0400845 for (BindingPointer<Texture> &binding : textureVector)
Shannon Woods53a94a82014-06-24 15:20:36 -0400846 {
Geoff Lang76b10c92014-09-05 16:28:14 -0400847 if (binding.id() == texture)
Shannon Woods53a94a82014-06-24 15:20:36 -0400848 {
Jamie Madill5864ac22015-01-12 14:43:07 -0500849 auto it = zeroTextures.find(textureType);
850 ASSERT(it != zeroTextures.end());
Jamie Madille6382c32014-11-07 15:05:26 -0500851 // Zero textures are the "default" textures instead of NULL
Jamie Madill4928b7c2017-06-20 12:57:39 -0400852 binding.set(context, it->second.get());
Jamie Madill81c2e252017-09-09 23:32:46 -0400853 mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS);
Shannon Woods53a94a82014-06-24 15:20:36 -0400854 }
855 }
856 }
857
Xinghua Cao65ec0b22017-03-28 16:10:52 +0800858 for (auto &bindingImageUnit : mImageUnits)
859 {
860 if (bindingImageUnit.texture.id() == texture)
861 {
862 bindingImageUnit.texture.set(context, nullptr);
863 bindingImageUnit.level = 0;
864 bindingImageUnit.layered = false;
865 bindingImageUnit.layer = 0;
866 bindingImageUnit.access = GL_READ_ONLY;
867 bindingImageUnit.format = GL_R32UI;
868 break;
869 }
870 }
871
Shannon Woods53a94a82014-06-24 15:20:36 -0400872 // [OpenGL ES 2.0.24] section 4.4 page 112:
873 // If a texture object is deleted while its image is attached to the currently bound framebuffer, then it is
874 // as if Texture2DAttachment had been called, with a texture of 0, for each attachment point to which this
875 // image was attached in the currently bound framebuffer.
876
Jamie Madill8693bdb2017-09-02 15:32:14 -0400877 if (mReadFramebuffer && mReadFramebuffer->detachTexture(context, texture))
Shannon Woods53a94a82014-06-24 15:20:36 -0400878 {
Jamie Madill8693bdb2017-09-02 15:32:14 -0400879 mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
Shannon Woods53a94a82014-06-24 15:20:36 -0400880 }
881
Jamie Madill8693bdb2017-09-02 15:32:14 -0400882 if (mDrawFramebuffer && mDrawFramebuffer->detachTexture(context, texture))
Shannon Woods53a94a82014-06-24 15:20:36 -0400883 {
Jamie Madill8693bdb2017-09-02 15:32:14 -0400884 mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Shannon Woods53a94a82014-06-24 15:20:36 -0400885 }
886}
887
Jamie Madill4928b7c2017-06-20 12:57:39 -0400888void State::initializeZeroTextures(const Context *context, const TextureMap &zeroTextures)
Jamie Madille6382c32014-11-07 15:05:26 -0500889{
890 for (const auto &zeroTexture : zeroTextures)
891 {
892 auto &samplerTextureArray = mSamplerTextures[zeroTexture.first];
893
894 for (size_t textureUnit = 0; textureUnit < samplerTextureArray.size(); ++textureUnit)
895 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400896 samplerTextureArray[textureUnit].set(context, zeroTexture.second.get());
Jamie Madille6382c32014-11-07 15:05:26 -0500897 }
898 }
899}
900
Jamie Madill4928b7c2017-06-20 12:57:39 -0400901void State::setSamplerBinding(const Context *context, GLuint textureUnit, Sampler *sampler)
Shannon Woods53a94a82014-06-24 15:20:36 -0400902{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400903 mSamplers[textureUnit].set(context, sampler);
Jamie Madill81c2e252017-09-09 23:32:46 -0400904 mDirtyBits.set(DIRTY_BIT_SAMPLER_BINDINGS);
905 mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES);
Shannon Woods53a94a82014-06-24 15:20:36 -0400906}
907
908GLuint State::getSamplerId(GLuint textureUnit) const
909{
Geoff Lang76b10c92014-09-05 16:28:14 -0400910 ASSERT(textureUnit < mSamplers.size());
Shannon Woods53a94a82014-06-24 15:20:36 -0400911 return mSamplers[textureUnit].id();
912}
913
914Sampler *State::getSampler(GLuint textureUnit) const
915{
916 return mSamplers[textureUnit].get();
917}
918
Jamie Madill4928b7c2017-06-20 12:57:39 -0400919void State::detachSampler(const Context *context, GLuint sampler)
Shannon Woods53a94a82014-06-24 15:20:36 -0400920{
921 // [OpenGL ES 3.0.2] section 3.8.2 pages 123-124:
922 // If a sampler object that is currently bound to one or more texture units is
923 // deleted, it is as though BindSampler is called once for each texture unit to
924 // which the sampler is bound, with unit set to the texture unit and sampler set to zero.
Jamie Madill81c2e252017-09-09 23:32:46 -0400925 for (BindingPointer<Sampler> &samplerBinding : mSamplers)
Shannon Woods53a94a82014-06-24 15:20:36 -0400926 {
Geoff Lang76b10c92014-09-05 16:28:14 -0400927 if (samplerBinding.id() == sampler)
Shannon Woods53a94a82014-06-24 15:20:36 -0400928 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400929 samplerBinding.set(context, nullptr);
Jamie Madill81c2e252017-09-09 23:32:46 -0400930 mDirtyBits.set(DIRTY_BIT_SAMPLER_BINDINGS);
Shannon Woods53a94a82014-06-24 15:20:36 -0400931 }
932 }
933}
934
Jamie Madill4928b7c2017-06-20 12:57:39 -0400935void State::setRenderbufferBinding(const Context *context, Renderbuffer *renderbuffer)
Shannon Woods53a94a82014-06-24 15:20:36 -0400936{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400937 mRenderbuffer.set(context, renderbuffer);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400938 mDirtyBits.set(DIRTY_BIT_RENDERBUFFER_BINDING);
Shannon Woods53a94a82014-06-24 15:20:36 -0400939}
940
941GLuint State::getRenderbufferId() const
942{
943 return mRenderbuffer.id();
944}
945
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700946Renderbuffer *State::getCurrentRenderbuffer() const
Shannon Woods53a94a82014-06-24 15:20:36 -0400947{
948 return mRenderbuffer.get();
949}
950
Jamie Madilla02315b2017-02-23 14:14:47 -0500951void State::detachRenderbuffer(const Context *context, GLuint renderbuffer)
Shannon Woods53a94a82014-06-24 15:20:36 -0400952{
953 // [OpenGL ES 2.0.24] section 4.4 page 109:
954 // If a renderbuffer that is currently bound to RENDERBUFFER is deleted, it is as though BindRenderbuffer
955 // had been executed with the target RENDERBUFFER and name of zero.
956
957 if (mRenderbuffer.id() == renderbuffer)
958 {
Jamie Madill8693bdb2017-09-02 15:32:14 -0400959 setRenderbufferBinding(context, nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -0400960 }
961
962 // [OpenGL ES 2.0.24] section 4.4 page 111:
963 // If a renderbuffer object is deleted while its image is attached to the currently bound framebuffer,
964 // then it is as if FramebufferRenderbuffer had been called, with a renderbuffer of 0, for each attachment
965 // point to which this image was attached in the currently bound framebuffer.
966
967 Framebuffer *readFramebuffer = mReadFramebuffer;
968 Framebuffer *drawFramebuffer = mDrawFramebuffer;
969
Jamie Madill8693bdb2017-09-02 15:32:14 -0400970 if (readFramebuffer && readFramebuffer->detachRenderbuffer(context, renderbuffer))
Shannon Woods53a94a82014-06-24 15:20:36 -0400971 {
Jamie Madill8693bdb2017-09-02 15:32:14 -0400972 mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
Shannon Woods53a94a82014-06-24 15:20:36 -0400973 }
974
975 if (drawFramebuffer && drawFramebuffer != readFramebuffer)
976 {
Jamie Madill8693bdb2017-09-02 15:32:14 -0400977 if (drawFramebuffer->detachRenderbuffer(context, renderbuffer))
978 {
979 mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
980 }
Shannon Woods53a94a82014-06-24 15:20:36 -0400981 }
982
983}
984
985void State::setReadFramebufferBinding(Framebuffer *framebuffer)
986{
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500987 if (mReadFramebuffer == framebuffer)
988 return;
989
Shannon Woods53a94a82014-06-24 15:20:36 -0400990 mReadFramebuffer = framebuffer;
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500991 mDirtyBits.set(DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
992
993 if (mReadFramebuffer && mReadFramebuffer->hasAnyDirtyBit())
994 {
995 mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
996 }
Shannon Woods53a94a82014-06-24 15:20:36 -0400997}
998
999void State::setDrawFramebufferBinding(Framebuffer *framebuffer)
1000{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05001001 if (mDrawFramebuffer == framebuffer)
1002 return;
1003
Shannon Woods53a94a82014-06-24 15:20:36 -04001004 mDrawFramebuffer = framebuffer;
Jamie Madill60ec6ea2016-01-22 15:27:19 -05001005 mDirtyBits.set(DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
1006
1007 if (mDrawFramebuffer && mDrawFramebuffer->hasAnyDirtyBit())
1008 {
1009 mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
1010 }
Shannon Woods53a94a82014-06-24 15:20:36 -04001011}
1012
1013Framebuffer *State::getTargetFramebuffer(GLenum target) const
1014{
1015 switch (target)
1016 {
Jamie Madill60ec6ea2016-01-22 15:27:19 -05001017 case GL_READ_FRAMEBUFFER_ANGLE:
1018 return mReadFramebuffer;
1019 case GL_DRAW_FRAMEBUFFER_ANGLE:
1020 case GL_FRAMEBUFFER:
1021 return mDrawFramebuffer;
1022 default:
1023 UNREACHABLE();
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001024 return nullptr;
Shannon Woods53a94a82014-06-24 15:20:36 -04001025 }
1026}
1027
Jamie Madill51f40ec2016-06-15 14:06:00 -04001028Framebuffer *State::getReadFramebuffer() const
Shannon Woods53a94a82014-06-24 15:20:36 -04001029{
1030 return mReadFramebuffer;
1031}
1032
Jamie Madill51f40ec2016-06-15 14:06:00 -04001033Framebuffer *State::getDrawFramebuffer() const
Shannon Woods53a94a82014-06-24 15:20:36 -04001034{
1035 return mDrawFramebuffer;
1036}
1037
1038bool State::removeReadFramebufferBinding(GLuint framebuffer)
1039{
Jamie Madill77a72f62015-04-14 11:18:32 -04001040 if (mReadFramebuffer != nullptr &&
1041 mReadFramebuffer->id() == framebuffer)
Shannon Woods53a94a82014-06-24 15:20:36 -04001042 {
Jamie Madill60ec6ea2016-01-22 15:27:19 -05001043 setReadFramebufferBinding(nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -04001044 return true;
1045 }
1046
1047 return false;
1048}
1049
1050bool State::removeDrawFramebufferBinding(GLuint framebuffer)
1051{
Jamie Madill77a72f62015-04-14 11:18:32 -04001052 if (mReadFramebuffer != nullptr &&
1053 mDrawFramebuffer->id() == framebuffer)
Shannon Woods53a94a82014-06-24 15:20:36 -04001054 {
Jamie Madill60ec6ea2016-01-22 15:27:19 -05001055 setDrawFramebufferBinding(nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -04001056 return true;
1057 }
1058
1059 return false;
1060}
1061
1062void State::setVertexArrayBinding(VertexArray *vertexArray)
1063{
1064 mVertexArray = vertexArray;
Jamie Madill0b9e9032015-08-17 11:51:52 +00001065 mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING);
Jamie Madillc9d442d2016-01-20 11:17:24 -05001066
1067 if (mVertexArray && mVertexArray->hasAnyDirtyBit())
1068 {
1069 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
1070 }
Shannon Woods53a94a82014-06-24 15:20:36 -04001071}
1072
1073GLuint State::getVertexArrayId() const
1074{
Yunchao He4f285442017-04-21 12:15:49 +08001075 ASSERT(mVertexArray != nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -04001076 return mVertexArray->id();
1077}
1078
1079VertexArray *State::getVertexArray() const
1080{
Yunchao He4f285442017-04-21 12:15:49 +08001081 ASSERT(mVertexArray != nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -04001082 return mVertexArray;
1083}
1084
1085bool State::removeVertexArrayBinding(GLuint vertexArray)
1086{
1087 if (mVertexArray->id() == vertexArray)
1088 {
Yunchao Hed7297bf2017-04-19 15:27:10 +08001089 mVertexArray = nullptr;
Jamie Madill0b9e9032015-08-17 11:51:52 +00001090 mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING);
Jamie Madillc9d442d2016-01-20 11:17:24 -05001091 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
Shannon Woods53a94a82014-06-24 15:20:36 -04001092 return true;
1093 }
1094
1095 return false;
1096}
1097
Jamie Madill4928b7c2017-06-20 12:57:39 -04001098void State::setElementArrayBuffer(const Context *context, Buffer *buffer)
Shao80957d92017-02-20 21:25:59 +08001099{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001100 getVertexArray()->setElementArrayBuffer(context, buffer);
Shao80957d92017-02-20 21:25:59 +08001101 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
1102}
1103
Jamie Madill4928b7c2017-06-20 12:57:39 -04001104void State::bindVertexBuffer(const Context *context,
1105 GLuint bindingIndex,
Shao80957d92017-02-20 21:25:59 +08001106 Buffer *boundBuffer,
1107 GLintptr offset,
1108 GLsizei stride)
1109{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001110 getVertexArray()->bindVertexBuffer(context, bindingIndex, boundBuffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001111 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
1112}
1113
Shaodde78e82017-05-22 14:13:27 +08001114void State::setVertexAttribBinding(const Context *context, GLuint attribIndex, GLuint bindingIndex)
Shao80957d92017-02-20 21:25:59 +08001115{
Shaodde78e82017-05-22 14:13:27 +08001116 getVertexArray()->setVertexAttribBinding(context, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08001117 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
1118}
1119
1120void State::setVertexAttribFormat(GLuint attribIndex,
1121 GLint size,
1122 GLenum type,
1123 bool normalized,
1124 bool pureInteger,
1125 GLuint relativeOffset)
1126{
1127 getVertexArray()->setVertexAttribFormat(attribIndex, size, type, normalized, pureInteger,
1128 relativeOffset);
1129 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
1130}
1131
1132void State::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
1133{
1134 getVertexArray()->setVertexBindingDivisor(bindingIndex, divisor);
1135 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
1136}
1137
Jamie Madill6c1f6712017-02-14 19:08:04 -05001138void State::setProgram(const Context *context, Program *newProgram)
Shannon Woods53a94a82014-06-24 15:20:36 -04001139{
Geoff Lang7dd2e102014-11-10 15:19:26 -05001140 if (mProgram != newProgram)
Shannon Woods53a94a82014-06-24 15:20:36 -04001141 {
Geoff Lang7dd2e102014-11-10 15:19:26 -05001142 if (mProgram)
1143 {
Jamie Madill6c1f6712017-02-14 19:08:04 -05001144 mProgram->release(context);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001145 }
1146
1147 mProgram = newProgram;
1148
1149 if (mProgram)
1150 {
1151 newProgram->addRef();
Jamie Madill81c2e252017-09-09 23:32:46 -04001152 mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001153 }
Jamie Madilla779b612017-07-24 11:46:05 -04001154 mDirtyBits.set(DIRTY_BIT_PROGRAM_EXECUTABLE);
1155 mDirtyBits.set(DIRTY_BIT_PROGRAM_BINDING);
Shannon Woods53a94a82014-06-24 15:20:36 -04001156 }
1157}
1158
Geoff Lang7dd2e102014-11-10 15:19:26 -05001159Program *State::getProgram() const
Shannon Woods53a94a82014-06-24 15:20:36 -04001160{
Geoff Lang7dd2e102014-11-10 15:19:26 -05001161 return mProgram;
Shannon Woods53a94a82014-06-24 15:20:36 -04001162}
1163
Jamie Madill4928b7c2017-06-20 12:57:39 -04001164void State::setTransformFeedbackBinding(const Context *context,
1165 TransformFeedback *transformFeedback)
Shannon Woods53a94a82014-06-24 15:20:36 -04001166{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001167 mTransformFeedback.set(context, transformFeedback);
Shannon Woods53a94a82014-06-24 15:20:36 -04001168}
1169
1170TransformFeedback *State::getCurrentTransformFeedback() const
1171{
1172 return mTransformFeedback.get();
1173}
1174
Gregoire Payen de La Garanderie52742022015-02-04 14:55:39 +00001175bool State::isTransformFeedbackActiveUnpaused() const
1176{
Jamie Madill81c2e252017-09-09 23:32:46 -04001177 TransformFeedback *curTransformFeedback = getCurrentTransformFeedback();
Geoff Langbb0a0bb2015-03-27 12:16:57 -04001178 return curTransformFeedback && curTransformFeedback->isActive() && !curTransformFeedback->isPaused();
Gregoire Payen de La Garanderie52742022015-02-04 14:55:39 +00001179}
1180
Jamie Madill4928b7c2017-06-20 12:57:39 -04001181bool State::removeTransformFeedbackBinding(const Context *context, GLuint transformFeedback)
Shannon Woods53a94a82014-06-24 15:20:36 -04001182{
1183 if (mTransformFeedback.id() == transformFeedback)
1184 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001185 mTransformFeedback.set(context, nullptr);
Corentin Walleza2257da2016-04-19 16:43:12 -04001186 return true;
Shannon Woods53a94a82014-06-24 15:20:36 -04001187 }
Corentin Walleza2257da2016-04-19 16:43:12 -04001188
1189 return false;
Shannon Woods53a94a82014-06-24 15:20:36 -04001190}
1191
Yunchao Hea336b902017-08-02 16:05:21 +08001192void State::setProgramPipelineBinding(const Context *context, ProgramPipeline *pipeline)
1193{
1194 mProgramPipeline.set(context, pipeline);
1195}
1196
1197void State::detachProgramPipeline(const Context *context, GLuint pipeline)
1198{
1199 mProgramPipeline.set(context, nullptr);
1200}
1201
Olli Etuahobbf1c102016-06-28 13:31:33 +03001202bool State::isQueryActive(const GLenum type) const
Shannon Woods53a94a82014-06-24 15:20:36 -04001203{
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001204 for (auto &iter : mActiveQueries)
Shannon Woods53a94a82014-06-24 15:20:36 -04001205 {
Olli Etuahobbf1c102016-06-28 13:31:33 +03001206 const Query *query = iter.second.get();
1207 if (query != nullptr && ActiveQueryType(query->getType()) == ActiveQueryType(type))
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001208 {
1209 return true;
1210 }
1211 }
1212
1213 return false;
1214}
1215
1216bool State::isQueryActive(Query *query) const
1217{
1218 for (auto &iter : mActiveQueries)
1219 {
1220 if (iter.second.get() == query)
Shannon Woods53a94a82014-06-24 15:20:36 -04001221 {
1222 return true;
1223 }
1224 }
1225
1226 return false;
1227}
1228
Jamie Madill4928b7c2017-06-20 12:57:39 -04001229void State::setActiveQuery(const Context *context, GLenum target, Query *query)
Shannon Woods53a94a82014-06-24 15:20:36 -04001230{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001231 mActiveQueries[target].set(context, query);
Shannon Woods53a94a82014-06-24 15:20:36 -04001232}
1233
1234GLuint State::getActiveQueryId(GLenum target) const
1235{
1236 const Query *query = getActiveQuery(target);
1237 return (query ? query->id() : 0u);
1238}
1239
1240Query *State::getActiveQuery(GLenum target) const
1241{
Jamie Madill5864ac22015-01-12 14:43:07 -05001242 const auto it = mActiveQueries.find(target);
Shannon Woods53a94a82014-06-24 15:20:36 -04001243
Jamie Madill5864ac22015-01-12 14:43:07 -05001244 // All query types should already exist in the activeQueries map
1245 ASSERT(it != mActiveQueries.end());
1246
1247 return it->second.get();
Shannon Woods53a94a82014-06-24 15:20:36 -04001248}
1249
Jamie Madill4928b7c2017-06-20 12:57:39 -04001250void State::setArrayBufferBinding(const Context *context, Buffer *buffer)
Shannon Woods53a94a82014-06-24 15:20:36 -04001251{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001252 mArrayBuffer.set(context, buffer);
Shannon Woods53a94a82014-06-24 15:20:36 -04001253}
1254
1255GLuint State::getArrayBufferId() const
1256{
1257 return mArrayBuffer.id();
1258}
1259
Jamie Madill4928b7c2017-06-20 12:57:39 -04001260void State::setDrawIndirectBufferBinding(const Context *context, Buffer *buffer)
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08001261{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001262 mDrawIndirectBuffer.set(context, buffer);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08001263 mDirtyBits.set(DIRTY_BIT_DRAW_INDIRECT_BUFFER_BINDING);
1264}
1265
Jamie Madill4928b7c2017-06-20 12:57:39 -04001266void State::setGenericUniformBufferBinding(const Context *context, Buffer *buffer)
Shannon Woods53a94a82014-06-24 15:20:36 -04001267{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001268 mGenericUniformBuffer.set(context, buffer);
Shannon Woods53a94a82014-06-24 15:20:36 -04001269}
1270
Jamie Madill4928b7c2017-06-20 12:57:39 -04001271void State::setIndexedUniformBufferBinding(const Context *context,
1272 GLuint index,
1273 Buffer *buffer,
1274 GLintptr offset,
1275 GLsizeiptr size)
Shannon Woods53a94a82014-06-24 15:20:36 -04001276{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001277 mUniformBuffers[index].set(context, buffer, offset, size);
Shannon Woods53a94a82014-06-24 15:20:36 -04001278}
1279
Geoff Lang5d124a62015-09-15 13:03:27 -04001280const OffsetBindingPointer<Buffer> &State::getIndexedUniformBuffer(size_t index) const
Shannon Woods53a94a82014-06-24 15:20:36 -04001281{
Shannon Woodsf3acaf92014-09-23 18:07:11 -04001282 ASSERT(static_cast<size_t>(index) < mUniformBuffers.size());
Geoff Lang5d124a62015-09-15 13:03:27 -04001283 return mUniformBuffers[index];
Gregoire Payen de La Garanderie68694e92015-03-24 14:03:37 +00001284}
1285
Jamie Madill4928b7c2017-06-20 12:57:39 -04001286void State::setGenericAtomicCounterBufferBinding(const Context *context, Buffer *buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08001287{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001288 mGenericAtomicCounterBuffer.set(context, buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001289}
1290
Jamie Madill4928b7c2017-06-20 12:57:39 -04001291void State::setIndexedAtomicCounterBufferBinding(const Context *context,
1292 GLuint index,
Jiajia Qin6eafb042016-12-27 17:04:07 +08001293 Buffer *buffer,
1294 GLintptr offset,
1295 GLsizeiptr size)
1296{
1297 ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size());
Jamie Madill4928b7c2017-06-20 12:57:39 -04001298 mAtomicCounterBuffers[index].set(context, buffer, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001299}
1300
1301const OffsetBindingPointer<Buffer> &State::getIndexedAtomicCounterBuffer(size_t index) const
1302{
1303 ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size());
1304 return mAtomicCounterBuffers[index];
1305}
1306
Jamie Madill4928b7c2017-06-20 12:57:39 -04001307void State::setGenericShaderStorageBufferBinding(const Context *context, Buffer *buffer)
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001308{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001309 mGenericShaderStorageBuffer.set(context, buffer);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001310}
1311
Jamie Madill4928b7c2017-06-20 12:57:39 -04001312void State::setIndexedShaderStorageBufferBinding(const Context *context,
1313 GLuint index,
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001314 Buffer *buffer,
1315 GLintptr offset,
1316 GLsizeiptr size)
1317{
1318 ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size());
Jamie Madill4928b7c2017-06-20 12:57:39 -04001319 mShaderStorageBuffers[index].set(context, buffer, offset, size);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001320}
1321
1322const OffsetBindingPointer<Buffer> &State::getIndexedShaderStorageBuffer(size_t index) const
1323{
1324 ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size());
1325 return mShaderStorageBuffers[index];
1326}
1327
Jamie Madill4928b7c2017-06-20 12:57:39 -04001328void State::setCopyReadBufferBinding(const Context *context, Buffer *buffer)
Shannon Woods53a94a82014-06-24 15:20:36 -04001329{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001330 mCopyReadBuffer.set(context, buffer);
Shannon Woods53a94a82014-06-24 15:20:36 -04001331}
1332
Jamie Madill4928b7c2017-06-20 12:57:39 -04001333void State::setCopyWriteBufferBinding(const Context *context, Buffer *buffer)
Shannon Woods53a94a82014-06-24 15:20:36 -04001334{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001335 mCopyWriteBuffer.set(context, buffer);
Shannon Woods53a94a82014-06-24 15:20:36 -04001336}
1337
Jamie Madill4928b7c2017-06-20 12:57:39 -04001338void State::setPixelPackBufferBinding(const Context *context, Buffer *buffer)
Shannon Woods53a94a82014-06-24 15:20:36 -04001339{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001340 mPack.pixelBuffer.set(context, buffer);
Corentin Wallezbbd663a2016-04-20 17:49:17 -04001341 mDirtyBits.set(DIRTY_BIT_PACK_BUFFER_BINDING);
Shannon Woods53a94a82014-06-24 15:20:36 -04001342}
1343
Jamie Madill4928b7c2017-06-20 12:57:39 -04001344void State::setPixelUnpackBufferBinding(const Context *context, Buffer *buffer)
Shannon Woods53a94a82014-06-24 15:20:36 -04001345{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001346 mUnpack.pixelBuffer.set(context, buffer);
Corentin Wallezbbd663a2016-04-20 17:49:17 -04001347 mDirtyBits.set(DIRTY_BIT_UNPACK_BUFFER_BINDING);
Shannon Woods53a94a82014-06-24 15:20:36 -04001348}
1349
1350Buffer *State::getTargetBuffer(GLenum target) const
1351{
1352 switch (target)
1353 {
1354 case GL_ARRAY_BUFFER: return mArrayBuffer.get();
1355 case GL_COPY_READ_BUFFER: return mCopyReadBuffer.get();
1356 case GL_COPY_WRITE_BUFFER: return mCopyWriteBuffer.get();
Jamie Madill8e344942015-07-09 14:22:07 -04001357 case GL_ELEMENT_ARRAY_BUFFER: return getVertexArray()->getElementArrayBuffer().get();
Shannon Woods53a94a82014-06-24 15:20:36 -04001358 case GL_PIXEL_PACK_BUFFER: return mPack.pixelBuffer.get();
1359 case GL_PIXEL_UNPACK_BUFFER: return mUnpack.pixelBuffer.get();
Geoff Lang045536b2015-03-27 15:17:18 -04001360 case GL_TRANSFORM_FEEDBACK_BUFFER: return mTransformFeedback->getGenericBuffer().get();
Shannon Woods53a94a82014-06-24 15:20:36 -04001361 case GL_UNIFORM_BUFFER: return mGenericUniformBuffer.get();
Geoff Langb5e997f2016-12-06 10:55:34 -05001362 case GL_ATOMIC_COUNTER_BUFFER:
Jiajia Qin6eafb042016-12-27 17:04:07 +08001363 return mGenericAtomicCounterBuffer.get();
Geoff Langb5e997f2016-12-06 10:55:34 -05001364 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001365 return mGenericShaderStorageBuffer.get();
Geoff Langb5e997f2016-12-06 10:55:34 -05001366 case GL_DRAW_INDIRECT_BUFFER:
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08001367 return mDrawIndirectBuffer.get();
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001368 default:
1369 UNREACHABLE();
1370 return nullptr;
Shannon Woods53a94a82014-06-24 15:20:36 -04001371 }
1372}
1373
Jamie Madill4928b7c2017-06-20 12:57:39 -04001374void State::detachBuffer(const Context *context, GLuint bufferName)
Yuly Novikov5807a532015-12-03 13:01:22 -05001375{
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001376 BindingPointer<Buffer> *buffers[] = {
1377 &mArrayBuffer, &mGenericAtomicCounterBuffer, &mCopyReadBuffer,
1378 &mCopyWriteBuffer, &mDrawIndirectBuffer, &mPack.pixelBuffer,
1379 &mUnpack.pixelBuffer, &mGenericUniformBuffer, &mGenericShaderStorageBuffer};
Yuly Novikov5807a532015-12-03 13:01:22 -05001380 for (auto buffer : buffers)
1381 {
1382 if (buffer->id() == bufferName)
1383 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001384 buffer->set(context, nullptr);
Yuly Novikov5807a532015-12-03 13:01:22 -05001385 }
1386 }
1387
1388 TransformFeedback *curTransformFeedback = getCurrentTransformFeedback();
1389 if (curTransformFeedback)
1390 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001391 curTransformFeedback->detachBuffer(context, bufferName);
Yuly Novikov5807a532015-12-03 13:01:22 -05001392 }
1393
Jamie Madill4928b7c2017-06-20 12:57:39 -04001394 getVertexArray()->detachBuffer(context, bufferName);
Yuly Novikov5807a532015-12-03 13:01:22 -05001395}
1396
Shannon Woods53a94a82014-06-24 15:20:36 -04001397void State::setEnableVertexAttribArray(unsigned int attribNum, bool enabled)
1398{
1399 getVertexArray()->enableAttribute(attribNum, enabled);
Jamie Madillc9d442d2016-01-20 11:17:24 -05001400 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
Shannon Woods53a94a82014-06-24 15:20:36 -04001401}
1402
1403void State::setVertexAttribf(GLuint index, const GLfloat values[4])
1404{
Shannon Woods23e05002014-09-22 19:07:27 -04001405 ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size());
Shannon Woods53a94a82014-06-24 15:20:36 -04001406 mVertexAttribCurrentValues[index].setFloatValues(values);
Jamie Madill1e0bc3a2015-08-11 08:12:21 -04001407 mDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_0 + index);
Shannon Woods53a94a82014-06-24 15:20:36 -04001408}
1409
1410void State::setVertexAttribu(GLuint index, const GLuint values[4])
1411{
Shannon Woods23e05002014-09-22 19:07:27 -04001412 ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size());
Shannon Woods53a94a82014-06-24 15:20:36 -04001413 mVertexAttribCurrentValues[index].setUnsignedIntValues(values);
Jamie Madill1e0bc3a2015-08-11 08:12:21 -04001414 mDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_0 + index);
Shannon Woods53a94a82014-06-24 15:20:36 -04001415}
1416
1417void State::setVertexAttribi(GLuint index, const GLint values[4])
1418{
Shannon Woods23e05002014-09-22 19:07:27 -04001419 ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size());
Shannon Woods53a94a82014-06-24 15:20:36 -04001420 mVertexAttribCurrentValues[index].setIntValues(values);
Jamie Madill1e0bc3a2015-08-11 08:12:21 -04001421 mDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_0 + index);
Shannon Woods53a94a82014-06-24 15:20:36 -04001422}
1423
Shaodde78e82017-05-22 14:13:27 +08001424void State::setVertexAttribPointer(const Context *context,
1425 unsigned int attribNum,
1426 Buffer *boundBuffer,
1427 GLint size,
1428 GLenum type,
1429 bool normalized,
1430 bool pureInteger,
1431 GLsizei stride,
1432 const void *pointer)
Shannon Woods53a94a82014-06-24 15:20:36 -04001433{
Shaodde78e82017-05-22 14:13:27 +08001434 getVertexArray()->setVertexAttribPointer(context, attribNum, boundBuffer, size, type,
1435 normalized, pureInteger, stride, pointer);
Jamie Madillc9d442d2016-01-20 11:17:24 -05001436 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
Jamie Madill0b9e9032015-08-17 11:51:52 +00001437}
1438
Shaodde78e82017-05-22 14:13:27 +08001439void State::setVertexAttribDivisor(const Context *context, GLuint index, GLuint divisor)
Jamie Madill0b9e9032015-08-17 11:51:52 +00001440{
Shaodde78e82017-05-22 14:13:27 +08001441 getVertexArray()->setVertexAttribDivisor(context, index, divisor);
Jamie Madillc9d442d2016-01-20 11:17:24 -05001442 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
Shannon Woods53a94a82014-06-24 15:20:36 -04001443}
1444
Jamie Madill6de51852017-04-12 09:53:01 -04001445const VertexAttribCurrentValueData &State::getVertexAttribCurrentValue(size_t attribNum) const
Shannon Woods53a94a82014-06-24 15:20:36 -04001446{
Jamie Madill6de51852017-04-12 09:53:01 -04001447 ASSERT(attribNum < mVertexAttribCurrentValues.size());
Shannon Woods53a94a82014-06-24 15:20:36 -04001448 return mVertexAttribCurrentValues[attribNum];
1449}
1450
Shannon Woods53a94a82014-06-24 15:20:36 -04001451const void *State::getVertexAttribPointer(unsigned int attribNum) const
1452{
1453 return getVertexArray()->getVertexAttribute(attribNum).pointer;
1454}
1455
1456void State::setPackAlignment(GLint alignment)
1457{
1458 mPack.alignment = alignment;
Jamie Madill1b94d432015-08-07 13:23:23 -04001459 mDirtyBits.set(DIRTY_BIT_PACK_ALIGNMENT);
Shannon Woods53a94a82014-06-24 15:20:36 -04001460}
1461
1462GLint State::getPackAlignment() const
1463{
1464 return mPack.alignment;
1465}
1466
1467void State::setPackReverseRowOrder(bool reverseRowOrder)
1468{
1469 mPack.reverseRowOrder = reverseRowOrder;
Jamie Madill1b94d432015-08-07 13:23:23 -04001470 mDirtyBits.set(DIRTY_BIT_PACK_REVERSE_ROW_ORDER);
Shannon Woods53a94a82014-06-24 15:20:36 -04001471}
1472
1473bool State::getPackReverseRowOrder() const
1474{
1475 return mPack.reverseRowOrder;
1476}
1477
Minmin Gongadff67b2015-10-14 10:34:45 -04001478void State::setPackRowLength(GLint rowLength)
1479{
1480 mPack.rowLength = rowLength;
1481 mDirtyBits.set(DIRTY_BIT_PACK_ROW_LENGTH);
1482}
1483
1484GLint State::getPackRowLength() const
1485{
1486 return mPack.rowLength;
1487}
1488
1489void State::setPackSkipRows(GLint skipRows)
1490{
1491 mPack.skipRows = skipRows;
1492 mDirtyBits.set(DIRTY_BIT_PACK_SKIP_ROWS);
1493}
1494
1495GLint State::getPackSkipRows() const
1496{
1497 return mPack.skipRows;
1498}
1499
1500void State::setPackSkipPixels(GLint skipPixels)
1501{
1502 mPack.skipPixels = skipPixels;
1503 mDirtyBits.set(DIRTY_BIT_PACK_SKIP_PIXELS);
1504}
1505
1506GLint State::getPackSkipPixels() const
1507{
1508 return mPack.skipPixels;
1509}
1510
Shannon Woods53a94a82014-06-24 15:20:36 -04001511const PixelPackState &State::getPackState() const
1512{
1513 return mPack;
1514}
1515
Jamie Madill87de3622015-03-16 10:41:44 -04001516PixelPackState &State::getPackState()
1517{
1518 return mPack;
1519}
1520
Shannon Woods53a94a82014-06-24 15:20:36 -04001521void State::setUnpackAlignment(GLint alignment)
1522{
1523 mUnpack.alignment = alignment;
Jamie Madill1b94d432015-08-07 13:23:23 -04001524 mDirtyBits.set(DIRTY_BIT_UNPACK_ALIGNMENT);
Shannon Woods53a94a82014-06-24 15:20:36 -04001525}
1526
1527GLint State::getUnpackAlignment() const
1528{
1529 return mUnpack.alignment;
1530}
1531
Minmin Gongb8aee3b2015-01-27 14:42:36 -08001532void State::setUnpackRowLength(GLint rowLength)
1533{
1534 mUnpack.rowLength = rowLength;
Jamie Madill1b94d432015-08-07 13:23:23 -04001535 mDirtyBits.set(DIRTY_BIT_UNPACK_ROW_LENGTH);
Minmin Gongb8aee3b2015-01-27 14:42:36 -08001536}
1537
1538GLint State::getUnpackRowLength() const
1539{
1540 return mUnpack.rowLength;
1541}
1542
Minmin Gongadff67b2015-10-14 10:34:45 -04001543void State::setUnpackImageHeight(GLint imageHeight)
1544{
1545 mUnpack.imageHeight = imageHeight;
1546 mDirtyBits.set(DIRTY_BIT_UNPACK_IMAGE_HEIGHT);
1547}
1548
1549GLint State::getUnpackImageHeight() const
1550{
1551 return mUnpack.imageHeight;
1552}
1553
1554void State::setUnpackSkipImages(GLint skipImages)
1555{
1556 mUnpack.skipImages = skipImages;
1557 mDirtyBits.set(DIRTY_BIT_UNPACK_SKIP_IMAGES);
1558}
1559
1560GLint State::getUnpackSkipImages() const
1561{
1562 return mUnpack.skipImages;
1563}
1564
1565void State::setUnpackSkipRows(GLint skipRows)
1566{
1567 mUnpack.skipRows = skipRows;
1568 mDirtyBits.set(DIRTY_BIT_UNPACK_SKIP_ROWS);
1569}
1570
1571GLint State::getUnpackSkipRows() const
1572{
1573 return mUnpack.skipRows;
1574}
1575
1576void State::setUnpackSkipPixels(GLint skipPixels)
1577{
1578 mUnpack.skipPixels = skipPixels;
1579 mDirtyBits.set(DIRTY_BIT_UNPACK_SKIP_PIXELS);
1580}
1581
1582GLint State::getUnpackSkipPixels() const
1583{
1584 return mUnpack.skipPixels;
1585}
1586
Shannon Woods53a94a82014-06-24 15:20:36 -04001587const PixelUnpackState &State::getUnpackState() const
1588{
1589 return mUnpack;
1590}
1591
Jamie Madill67102f02015-03-16 10:41:42 -04001592PixelUnpackState &State::getUnpackState()
1593{
1594 return mUnpack;
1595}
1596
Geoff Lang70d0f492015-12-10 17:45:46 -05001597const Debug &State::getDebug() const
1598{
1599 return mDebug;
1600}
1601
1602Debug &State::getDebug()
1603{
1604 return mDebug;
1605}
1606
Sami Väisänena797e062016-05-12 15:23:40 +03001607void State::setCoverageModulation(GLenum components)
1608{
1609 mCoverageModulation = components;
1610 mDirtyBits.set(DIRTY_BIT_COVERAGE_MODULATION);
1611}
1612
1613GLenum State::getCoverageModulation() const
1614{
1615 return mCoverageModulation;
1616}
1617
Sami Väisänene45e53b2016-05-25 10:36:04 +03001618void State::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1619{
1620 if (matrixMode == GL_PATH_MODELVIEW_CHROMIUM)
1621 {
1622 memcpy(mPathMatrixMV, matrix, 16 * sizeof(GLfloat));
1623 mDirtyBits.set(DIRTY_BIT_PATH_RENDERING_MATRIX_MV);
1624 }
1625 else if (matrixMode == GL_PATH_PROJECTION_CHROMIUM)
1626 {
1627 memcpy(mPathMatrixProj, matrix, 16 * sizeof(GLfloat));
1628 mDirtyBits.set(DIRTY_BIT_PATH_RENDERING_MATRIX_PROJ);
1629 }
1630 else
1631 {
1632 UNREACHABLE();
1633 }
1634}
1635
1636const GLfloat *State::getPathRenderingMatrix(GLenum which) const
1637{
1638 if (which == GL_PATH_MODELVIEW_MATRIX_CHROMIUM)
1639 {
1640 return mPathMatrixMV;
1641 }
1642 else if (which == GL_PATH_PROJECTION_MATRIX_CHROMIUM)
1643 {
1644 return mPathMatrixProj;
1645 }
1646
1647 UNREACHABLE();
1648 return nullptr;
1649}
1650
1651void State::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
1652{
1653 mPathStencilFunc = func;
1654 mPathStencilRef = ref;
1655 mPathStencilMask = mask;
1656 mDirtyBits.set(DIRTY_BIT_PATH_RENDERING_STENCIL_STATE);
1657}
1658
1659GLenum State::getPathStencilFunc() const
1660{
1661 return mPathStencilFunc;
1662}
1663
1664GLint State::getPathStencilRef() const
1665{
1666 return mPathStencilRef;
1667}
1668
1669GLuint State::getPathStencilMask() const
1670{
1671 return mPathStencilMask;
1672}
1673
Geoff Lang1d2c41d2016-10-19 16:14:46 -07001674void State::setFramebufferSRGB(bool sRGB)
1675{
1676 mFramebufferSRGB = sRGB;
1677 mDirtyBits.set(DIRTY_BIT_FRAMEBUFFER_SRGB);
1678}
1679
1680bool State::getFramebufferSRGB() const
1681{
1682 return mFramebufferSRGB;
1683}
1684
Shannon Woods53a94a82014-06-24 15:20:36 -04001685void State::getBooleanv(GLenum pname, GLboolean *params)
1686{
1687 switch (pname)
1688 {
1689 case GL_SAMPLE_COVERAGE_INVERT: *params = mSampleCoverageInvert; break;
1690 case GL_DEPTH_WRITEMASK: *params = mDepthStencil.depthMask; break;
1691 case GL_COLOR_WRITEMASK:
1692 params[0] = mBlend.colorMaskRed;
1693 params[1] = mBlend.colorMaskGreen;
1694 params[2] = mBlend.colorMaskBlue;
1695 params[3] = mBlend.colorMaskAlpha;
1696 break;
1697 case GL_CULL_FACE: *params = mRasterizer.cullFace; break;
1698 case GL_POLYGON_OFFSET_FILL: *params = mRasterizer.polygonOffsetFill; break;
1699 case GL_SAMPLE_ALPHA_TO_COVERAGE: *params = mBlend.sampleAlphaToCoverage; break;
1700 case GL_SAMPLE_COVERAGE: *params = mSampleCoverage; break;
Jiawei Shaodb342272017-09-27 10:21:45 +08001701 case GL_SAMPLE_MASK:
1702 *params = mSampleMask;
1703 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001704 case GL_SCISSOR_TEST: *params = mScissorTest; break;
1705 case GL_STENCIL_TEST: *params = mDepthStencil.stencilTest; break;
1706 case GL_DEPTH_TEST: *params = mDepthStencil.depthTest; break;
1707 case GL_BLEND: *params = mBlend.blend; break;
1708 case GL_DITHER: *params = mBlend.dither; break;
Geoff Langbb0a0bb2015-03-27 12:16:57 -04001709 case GL_TRANSFORM_FEEDBACK_ACTIVE: *params = getCurrentTransformFeedback()->isActive() ? GL_TRUE : GL_FALSE; break;
1710 case GL_TRANSFORM_FEEDBACK_PAUSED: *params = getCurrentTransformFeedback()->isPaused() ? GL_TRUE : GL_FALSE; break;
Jamie Madille2cd53d2015-10-27 11:15:46 -04001711 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1712 *params = mPrimitiveRestart;
1713 break;
Geoff Langab831f02015-12-01 09:39:10 -05001714 case GL_RASTERIZER_DISCARD:
1715 *params = isRasterizerDiscardEnabled() ? GL_TRUE : GL_FALSE;
1716 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001717 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
1718 *params = mDebug.isOutputSynchronous() ? GL_TRUE : GL_FALSE;
1719 break;
1720 case GL_DEBUG_OUTPUT:
1721 *params = mDebug.isOutputEnabled() ? GL_TRUE : GL_FALSE;
1722 break;
Sami Väisänen74c23472016-05-09 17:30:30 +03001723 case GL_MULTISAMPLE_EXT:
1724 *params = mMultiSampling;
1725 break;
1726 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
1727 *params = mSampleAlphaToOne;
1728 break;
Geoff Langf41a7152016-09-19 15:11:17 -04001729 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
1730 *params = isBindGeneratesResourceEnabled() ? GL_TRUE : GL_FALSE;
1731 break;
Geoff Langfeb8c682017-02-13 16:07:35 -05001732 case GL_CLIENT_ARRAYS_ANGLE:
1733 *params = areClientArraysEnabled() ? GL_TRUE : GL_FALSE;
1734 break;
Geoff Lang1d2c41d2016-10-19 16:14:46 -07001735 case GL_FRAMEBUFFER_SRGB_EXT:
1736 *params = getFramebufferSRGB() ? GL_TRUE : GL_FALSE;
1737 break;
Jamie Madille08a1d32017-03-07 17:24:06 -05001738 case GL_CONTEXT_ROBUST_RESOURCE_INITIALIZATION_ANGLE:
1739 *params = mRobustResourceInit ? GL_TRUE : GL_FALSE;
1740 break;
Jamie Madillc43be722017-07-13 16:22:14 -04001741 case GL_PROGRAM_CACHE_ENABLED_ANGLE:
1742 *params = mProgramBinaryCacheEnabled ? GL_TRUE : GL_FALSE;
1743 break;
1744
Shannon Woods53a94a82014-06-24 15:20:36 -04001745 default:
1746 UNREACHABLE();
1747 break;
1748 }
1749}
1750
1751void State::getFloatv(GLenum pname, GLfloat *params)
1752{
1753 // Please note: DEPTH_CLEAR_VALUE is included in our internal getFloatv implementation
1754 // because it is stored as a float, despite the fact that the GL ES 2.0 spec names
1755 // GetIntegerv as its native query function. As it would require conversion in any
1756 // case, this should make no difference to the calling application.
1757 switch (pname)
1758 {
1759 case GL_LINE_WIDTH: *params = mLineWidth; break;
1760 case GL_SAMPLE_COVERAGE_VALUE: *params = mSampleCoverageValue; break;
1761 case GL_DEPTH_CLEAR_VALUE: *params = mDepthClearValue; break;
1762 case GL_POLYGON_OFFSET_FACTOR: *params = mRasterizer.polygonOffsetFactor; break;
1763 case GL_POLYGON_OFFSET_UNITS: *params = mRasterizer.polygonOffsetUnits; break;
1764 case GL_DEPTH_RANGE:
1765 params[0] = mNearZ;
1766 params[1] = mFarZ;
1767 break;
1768 case GL_COLOR_CLEAR_VALUE:
1769 params[0] = mColorClearValue.red;
1770 params[1] = mColorClearValue.green;
1771 params[2] = mColorClearValue.blue;
1772 params[3] = mColorClearValue.alpha;
1773 break;
1774 case GL_BLEND_COLOR:
1775 params[0] = mBlendColor.red;
1776 params[1] = mBlendColor.green;
1777 params[2] = mBlendColor.blue;
1778 params[3] = mBlendColor.alpha;
1779 break;
Sami Väisänen74c23472016-05-09 17:30:30 +03001780 case GL_MULTISAMPLE_EXT:
1781 *params = static_cast<GLfloat>(mMultiSampling);
1782 break;
1783 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
1784 *params = static_cast<GLfloat>(mSampleAlphaToOne);
Sami Väisänena797e062016-05-12 15:23:40 +03001785 case GL_COVERAGE_MODULATION_CHROMIUM:
Jamie Madille2e406c2016-06-02 13:04:10 -04001786 params[0] = static_cast<GLfloat>(mCoverageModulation);
1787 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001788 default:
1789 UNREACHABLE();
1790 break;
1791 }
1792}
1793
Jamie Madilldd43e6c2017-03-24 14:18:49 -04001794void State::getIntegerv(const Context *context, GLenum pname, GLint *params)
Shannon Woods53a94a82014-06-24 15:20:36 -04001795{
1796 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
1797 {
1798 unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0_EXT);
Shannon Woods2df6a602014-09-26 16:12:07 -04001799 ASSERT(colorAttachment < mMaxDrawBuffers);
Shannon Woods53a94a82014-06-24 15:20:36 -04001800 Framebuffer *framebuffer = mDrawFramebuffer;
1801 *params = framebuffer->getDrawBufferState(colorAttachment);
1802 return;
1803 }
1804
1805 // Please note: DEPTH_CLEAR_VALUE is not included in our internal getIntegerv implementation
1806 // because it is stored as a float, despite the fact that the GL ES 2.0 spec names
1807 // GetIntegerv as its native query function. As it would require conversion in any
1808 // case, this should make no difference to the calling application. You may find it in
1809 // State::getFloatv.
1810 switch (pname)
1811 {
1812 case GL_ARRAY_BUFFER_BINDING: *params = mArrayBuffer.id(); break;
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08001813 case GL_DRAW_INDIRECT_BUFFER_BINDING:
1814 *params = mDrawIndirectBuffer.id();
1815 break;
Jamie Madill8e344942015-07-09 14:22:07 -04001816 case GL_ELEMENT_ARRAY_BUFFER_BINDING: *params = getVertexArray()->getElementArrayBuffer().id(); break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001817 //case GL_FRAMEBUFFER_BINDING: // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1818 case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE: *params = mDrawFramebuffer->id(); break;
1819 case GL_READ_FRAMEBUFFER_BINDING_ANGLE: *params = mReadFramebuffer->id(); break;
1820 case GL_RENDERBUFFER_BINDING: *params = mRenderbuffer.id(); break;
1821 case GL_VERTEX_ARRAY_BINDING: *params = mVertexArray->id(); break;
Geoff Lang7dd2e102014-11-10 15:19:26 -05001822 case GL_CURRENT_PROGRAM: *params = mProgram ? mProgram->id() : 0; break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001823 case GL_PACK_ALIGNMENT: *params = mPack.alignment; break;
1824 case GL_PACK_REVERSE_ROW_ORDER_ANGLE: *params = mPack.reverseRowOrder; break;
Minmin Gongadff67b2015-10-14 10:34:45 -04001825 case GL_PACK_ROW_LENGTH:
1826 *params = mPack.rowLength;
1827 break;
1828 case GL_PACK_SKIP_ROWS:
1829 *params = mPack.skipRows;
1830 break;
1831 case GL_PACK_SKIP_PIXELS:
1832 *params = mPack.skipPixels;
1833 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001834 case GL_UNPACK_ALIGNMENT: *params = mUnpack.alignment; break;
Minmin Gongb8aee3b2015-01-27 14:42:36 -08001835 case GL_UNPACK_ROW_LENGTH: *params = mUnpack.rowLength; break;
Minmin Gongadff67b2015-10-14 10:34:45 -04001836 case GL_UNPACK_IMAGE_HEIGHT:
1837 *params = mUnpack.imageHeight;
1838 break;
1839 case GL_UNPACK_SKIP_IMAGES:
1840 *params = mUnpack.skipImages;
1841 break;
1842 case GL_UNPACK_SKIP_ROWS:
1843 *params = mUnpack.skipRows;
1844 break;
1845 case GL_UNPACK_SKIP_PIXELS:
1846 *params = mUnpack.skipPixels;
1847 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001848 case GL_GENERATE_MIPMAP_HINT: *params = mGenerateMipmapHint; break;
1849 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: *params = mFragmentShaderDerivativeHint; break;
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001850 case GL_ACTIVE_TEXTURE:
1851 *params = (static_cast<GLint>(mActiveSampler) + GL_TEXTURE0);
1852 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001853 case GL_STENCIL_FUNC: *params = mDepthStencil.stencilFunc; break;
1854 case GL_STENCIL_REF: *params = mStencilRef; break;
jchen10a99ed552017-09-22 08:10:32 +08001855 case GL_STENCIL_VALUE_MASK:
1856 *params = CastMaskValue(context, mDepthStencil.stencilMask);
1857 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001858 case GL_STENCIL_BACK_FUNC: *params = mDepthStencil.stencilBackFunc; break;
1859 case GL_STENCIL_BACK_REF: *params = mStencilBackRef; break;
jchen10a99ed552017-09-22 08:10:32 +08001860 case GL_STENCIL_BACK_VALUE_MASK:
1861 *params = CastMaskValue(context, mDepthStencil.stencilBackMask);
1862 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001863 case GL_STENCIL_FAIL: *params = mDepthStencil.stencilFail; break;
1864 case GL_STENCIL_PASS_DEPTH_FAIL: *params = mDepthStencil.stencilPassDepthFail; break;
1865 case GL_STENCIL_PASS_DEPTH_PASS: *params = mDepthStencil.stencilPassDepthPass; break;
1866 case GL_STENCIL_BACK_FAIL: *params = mDepthStencil.stencilBackFail; break;
1867 case GL_STENCIL_BACK_PASS_DEPTH_FAIL: *params = mDepthStencil.stencilBackPassDepthFail; break;
1868 case GL_STENCIL_BACK_PASS_DEPTH_PASS: *params = mDepthStencil.stencilBackPassDepthPass; break;
1869 case GL_DEPTH_FUNC: *params = mDepthStencil.depthFunc; break;
1870 case GL_BLEND_SRC_RGB: *params = mBlend.sourceBlendRGB; break;
1871 case GL_BLEND_SRC_ALPHA: *params = mBlend.sourceBlendAlpha; break;
1872 case GL_BLEND_DST_RGB: *params = mBlend.destBlendRGB; break;
1873 case GL_BLEND_DST_ALPHA: *params = mBlend.destBlendAlpha; break;
1874 case GL_BLEND_EQUATION_RGB: *params = mBlend.blendEquationRGB; break;
1875 case GL_BLEND_EQUATION_ALPHA: *params = mBlend.blendEquationAlpha; break;
jchen10a99ed552017-09-22 08:10:32 +08001876 case GL_STENCIL_WRITEMASK:
1877 *params = CastMaskValue(context, mDepthStencil.stencilWritemask);
1878 break;
1879 case GL_STENCIL_BACK_WRITEMASK:
1880 *params = CastMaskValue(context, mDepthStencil.stencilBackWritemask);
1881 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001882 case GL_STENCIL_CLEAR_VALUE: *params = mStencilClearValue; break;
Jamie Madill4928b7c2017-06-20 12:57:39 -04001883 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
1884 *params = mReadFramebuffer->getImplementationColorReadType(context);
1885 break;
1886 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
1887 *params = mReadFramebuffer->getImplementationColorReadFormat(context);
1888 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001889 case GL_SAMPLE_BUFFERS:
1890 case GL_SAMPLES:
1891 {
Jamie Madill81c2e252017-09-09 23:32:46 -04001892 Framebuffer *framebuffer = mDrawFramebuffer;
Jamie Madilldd43e6c2017-03-24 14:18:49 -04001893 if (framebuffer->checkStatus(context) == GL_FRAMEBUFFER_COMPLETE)
Shannon Woods53a94a82014-06-24 15:20:36 -04001894 {
1895 switch (pname)
1896 {
Jamie Madilla0016b72017-07-14 14:30:46 -04001897 case GL_SAMPLE_BUFFERS:
1898 if (framebuffer->getSamples(context) != 0)
1899 {
1900 *params = 1;
1901 }
1902 else
1903 {
1904 *params = 0;
1905 }
1906 break;
1907 case GL_SAMPLES:
1908 *params = framebuffer->getSamples(context);
1909 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001910 }
1911 }
1912 else
1913 {
1914 *params = 0;
1915 }
1916 }
1917 break;
1918 case GL_VIEWPORT:
1919 params[0] = mViewport.x;
1920 params[1] = mViewport.y;
1921 params[2] = mViewport.width;
1922 params[3] = mViewport.height;
1923 break;
1924 case GL_SCISSOR_BOX:
1925 params[0] = mScissor.x;
1926 params[1] = mScissor.y;
1927 params[2] = mScissor.width;
1928 params[3] = mScissor.height;
1929 break;
1930 case GL_CULL_FACE_MODE: *params = mRasterizer.cullMode; break;
1931 case GL_FRONT_FACE: *params = mRasterizer.frontFace; break;
1932 case GL_RED_BITS:
1933 case GL_GREEN_BITS:
1934 case GL_BLUE_BITS:
1935 case GL_ALPHA_BITS:
1936 {
Jamie Madill81c2e252017-09-09 23:32:46 -04001937 Framebuffer *framebuffer = getDrawFramebuffer();
1938 const FramebufferAttachment *colorbuffer = framebuffer->getFirstColorbuffer();
Shannon Woods53a94a82014-06-24 15:20:36 -04001939
1940 if (colorbuffer)
1941 {
1942 switch (pname)
1943 {
1944 case GL_RED_BITS: *params = colorbuffer->getRedSize(); break;
1945 case GL_GREEN_BITS: *params = colorbuffer->getGreenSize(); break;
1946 case GL_BLUE_BITS: *params = colorbuffer->getBlueSize(); break;
1947 case GL_ALPHA_BITS: *params = colorbuffer->getAlphaSize(); break;
1948 }
1949 }
1950 else
1951 {
1952 *params = 0;
1953 }
1954 }
1955 break;
1956 case GL_DEPTH_BITS:
1957 {
Jamie Madill81c2e252017-09-09 23:32:46 -04001958 const Framebuffer *framebuffer = getDrawFramebuffer();
1959 const FramebufferAttachment *depthbuffer = framebuffer->getDepthbuffer();
Shannon Woods53a94a82014-06-24 15:20:36 -04001960
1961 if (depthbuffer)
1962 {
1963 *params = depthbuffer->getDepthSize();
1964 }
1965 else
1966 {
1967 *params = 0;
1968 }
1969 }
1970 break;
1971 case GL_STENCIL_BITS:
1972 {
Jamie Madill81c2e252017-09-09 23:32:46 -04001973 const Framebuffer *framebuffer = getDrawFramebuffer();
1974 const FramebufferAttachment *stencilbuffer = framebuffer->getStencilbuffer();
Shannon Woods53a94a82014-06-24 15:20:36 -04001975
1976 if (stencilbuffer)
1977 {
1978 *params = stencilbuffer->getStencilSize();
1979 }
1980 else
1981 {
1982 *params = 0;
1983 }
1984 }
1985 break;
1986 case GL_TEXTURE_BINDING_2D:
Shannon Woods2df6a602014-09-26 16:12:07 -04001987 ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001988 *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_2D);
Shannon Woods53a94a82014-06-24 15:20:36 -04001989 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001990 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
1991 ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
1992 *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler),
1993 GL_TEXTURE_RECTANGLE_ANGLE);
1994 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001995 case GL_TEXTURE_BINDING_CUBE_MAP:
Shannon Woods2df6a602014-09-26 16:12:07 -04001996 ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001997 *params =
1998 getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_CUBE_MAP);
Shannon Woods53a94a82014-06-24 15:20:36 -04001999 break;
2000 case GL_TEXTURE_BINDING_3D:
Shannon Woods2df6a602014-09-26 16:12:07 -04002001 ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
Cooper Partin4d61f7e2015-08-12 10:56:50 -07002002 *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_3D);
Shannon Woods53a94a82014-06-24 15:20:36 -04002003 break;
2004 case GL_TEXTURE_BINDING_2D_ARRAY:
Shannon Woods2df6a602014-09-26 16:12:07 -04002005 ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
Cooper Partin4d61f7e2015-08-12 10:56:50 -07002006 *params =
2007 getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_2D_ARRAY);
Shannon Woods53a94a82014-06-24 15:20:36 -04002008 break;
JiangYizhou24fe74c2017-07-06 16:56:50 +08002009 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
2010 ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
2011 *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler),
2012 GL_TEXTURE_2D_MULTISAMPLE);
2013 break;
John Bauman18319182016-09-28 14:22:27 -07002014 case GL_TEXTURE_BINDING_EXTERNAL_OES:
2015 ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
2016 *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler),
2017 GL_TEXTURE_EXTERNAL_OES);
2018 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002019 case GL_UNIFORM_BUFFER_BINDING:
2020 *params = mGenericUniformBuffer.id();
2021 break;
Frank Henigman22581ff2015-11-06 14:25:54 -05002022 case GL_TRANSFORM_FEEDBACK_BINDING:
Frank Henigmanb0f0b812015-11-21 17:49:29 -05002023 *params = mTransformFeedback.id();
Frank Henigman22581ff2015-11-06 14:25:54 -05002024 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002025 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang045536b2015-03-27 15:17:18 -04002026 *params = mTransformFeedback->getGenericBuffer().id();
Shannon Woods53a94a82014-06-24 15:20:36 -04002027 break;
2028 case GL_COPY_READ_BUFFER_BINDING:
2029 *params = mCopyReadBuffer.id();
2030 break;
2031 case GL_COPY_WRITE_BUFFER_BINDING:
2032 *params = mCopyWriteBuffer.id();
2033 break;
2034 case GL_PIXEL_PACK_BUFFER_BINDING:
2035 *params = mPack.pixelBuffer.id();
2036 break;
2037 case GL_PIXEL_UNPACK_BUFFER_BINDING:
2038 *params = mUnpack.pixelBuffer.id();
2039 break;
Olli Etuaho86821db2016-03-04 12:05:47 +02002040 case GL_READ_BUFFER:
2041 *params = mReadFramebuffer->getReadBufferState();
2042 break;
2043 case GL_SAMPLER_BINDING:
2044 ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
2045 *params = getSamplerId(static_cast<GLuint>(mActiveSampler));
2046 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05002047 case GL_DEBUG_LOGGED_MESSAGES:
2048 *params = static_cast<GLint>(mDebug.getMessageCount());
2049 break;
2050 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
2051 *params = static_cast<GLint>(mDebug.getNextMessageLength());
2052 break;
2053 case GL_DEBUG_GROUP_STACK_DEPTH:
2054 *params = static_cast<GLint>(mDebug.getGroupStackDepth());
2055 break;
Sami Väisänen74c23472016-05-09 17:30:30 +03002056 case GL_MULTISAMPLE_EXT:
2057 *params = static_cast<GLint>(mMultiSampling);
2058 break;
2059 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
2060 *params = static_cast<GLint>(mSampleAlphaToOne);
Sami Väisänena797e062016-05-12 15:23:40 +03002061 case GL_COVERAGE_MODULATION_CHROMIUM:
2062 *params = static_cast<GLint>(mCoverageModulation);
Sami Väisänen74c23472016-05-09 17:30:30 +03002063 break;
Jiajia Qin6eafb042016-12-27 17:04:07 +08002064 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
2065 *params = mGenericAtomicCounterBuffer.id();
2066 break;
Jiajia Qinf546e7d2017-03-27 14:12:59 +08002067 case GL_SHADER_STORAGE_BUFFER_BINDING:
2068 *params = mGenericShaderStorageBuffer.id();
2069 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002070 default:
2071 UNREACHABLE();
2072 break;
2073 }
2074}
2075
Geoff Lang70d0f492015-12-10 17:45:46 -05002076void State::getPointerv(GLenum pname, void **params) const
2077{
2078 switch (pname)
2079 {
2080 case GL_DEBUG_CALLBACK_FUNCTION:
2081 *params = reinterpret_cast<void *>(mDebug.getCallback());
2082 break;
2083 case GL_DEBUG_CALLBACK_USER_PARAM:
2084 *params = const_cast<void *>(mDebug.getUserParam());
2085 break;
2086 default:
2087 UNREACHABLE();
2088 break;
2089 }
2090}
2091
Martin Radev66fb8202016-07-28 11:45:20 +03002092void State::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods53a94a82014-06-24 15:20:36 -04002093{
2094 switch (target)
2095 {
2096 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Jiajia Qin6eafb042016-12-27 17:04:07 +08002097 ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount());
2098 *data = mTransformFeedback->getIndexedBuffer(index).id();
2099 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002100 case GL_UNIFORM_BUFFER_BINDING:
Jiajia Qin6eafb042016-12-27 17:04:07 +08002101 ASSERT(static_cast<size_t>(index) < mUniformBuffers.size());
2102 *data = mUniformBuffers[index].id();
2103 break;
2104 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
2105 ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size());
2106 *data = mAtomicCounterBuffers[index].id();
2107 break;
Jiajia Qinf546e7d2017-03-27 14:12:59 +08002108 case GL_SHADER_STORAGE_BUFFER_BINDING:
2109 ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size());
2110 *data = mShaderStorageBuffers[index].id();
2111 break;
Shao80957d92017-02-20 21:25:59 +08002112 case GL_VERTEX_BINDING_BUFFER:
2113 ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings());
Martin Radevdd5f27e2017-06-07 10:17:09 +03002114 *data = mVertexArray->getVertexBinding(index).getBuffer().id();
Shao80957d92017-02-20 21:25:59 +08002115 break;
2116 case GL_VERTEX_BINDING_DIVISOR:
2117 ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings());
Martin Radevdd5f27e2017-06-07 10:17:09 +03002118 *data = mVertexArray->getVertexBinding(index).getDivisor();
Shao80957d92017-02-20 21:25:59 +08002119 break;
2120 case GL_VERTEX_BINDING_OFFSET:
2121 ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings());
Martin Radevdd5f27e2017-06-07 10:17:09 +03002122 *data = static_cast<GLuint>(mVertexArray->getVertexBinding(index).getOffset());
Shao80957d92017-02-20 21:25:59 +08002123 break;
2124 case GL_VERTEX_BINDING_STRIDE:
2125 ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings());
Martin Radevdd5f27e2017-06-07 10:17:09 +03002126 *data = mVertexArray->getVertexBinding(index).getStride();
Shao80957d92017-02-20 21:25:59 +08002127 break;
Jiawei Shaodb342272017-09-27 10:21:45 +08002128 case GL_SAMPLE_MASK_VALUE:
2129 ASSERT(static_cast<size_t>(index) < mSampleMaskValues.size());
2130 *data = mSampleMaskValues[index];
2131 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002132 default:
Martin Radev66fb8202016-07-28 11:45:20 +03002133 UNREACHABLE();
2134 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002135 }
Shannon Woods53a94a82014-06-24 15:20:36 -04002136}
2137
Martin Radev66fb8202016-07-28 11:45:20 +03002138void State::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods53a94a82014-06-24 15:20:36 -04002139{
2140 switch (target)
2141 {
2142 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
Jiajia Qin6eafb042016-12-27 17:04:07 +08002143 ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount());
2144 *data = mTransformFeedback->getIndexedBuffer(index).getOffset();
2145 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002146 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
Jiajia Qin6eafb042016-12-27 17:04:07 +08002147 ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount());
2148 *data = mTransformFeedback->getIndexedBuffer(index).getSize();
2149 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002150 case GL_UNIFORM_BUFFER_START:
Jiajia Qin6eafb042016-12-27 17:04:07 +08002151 ASSERT(static_cast<size_t>(index) < mUniformBuffers.size());
2152 *data = mUniformBuffers[index].getOffset();
2153 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002154 case GL_UNIFORM_BUFFER_SIZE:
Jiajia Qin6eafb042016-12-27 17:04:07 +08002155 ASSERT(static_cast<size_t>(index) < mUniformBuffers.size());
2156 *data = mUniformBuffers[index].getSize();
2157 break;
2158 case GL_ATOMIC_COUNTER_BUFFER_START:
2159 ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size());
2160 *data = mAtomicCounterBuffers[index].getOffset();
2161 break;
2162 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
2163 ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size());
2164 *data = mAtomicCounterBuffers[index].getSize();
2165 break;
Jiajia Qinf546e7d2017-03-27 14:12:59 +08002166 case GL_SHADER_STORAGE_BUFFER_START:
2167 ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size());
2168 *data = mShaderStorageBuffers[index].getOffset();
2169 break;
2170 case GL_SHADER_STORAGE_BUFFER_SIZE:
2171 ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size());
2172 *data = mShaderStorageBuffers[index].getSize();
2173 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002174 default:
Martin Radev66fb8202016-07-28 11:45:20 +03002175 UNREACHABLE();
2176 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002177 }
Martin Radev66fb8202016-07-28 11:45:20 +03002178}
Shannon Woods53a94a82014-06-24 15:20:36 -04002179
Martin Radev66fb8202016-07-28 11:45:20 +03002180void State::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
2181{
2182 UNREACHABLE();
Shannon Woods53a94a82014-06-24 15:20:36 -04002183}
2184
Jamie Madilld9ba4f72014-08-04 10:47:59 -04002185bool State::hasMappedBuffer(GLenum target) const
2186{
2187 if (target == GL_ARRAY_BUFFER)
2188 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002189 const VertexArray *vao = getVertexArray();
Jamie Madilleea3a6e2015-04-15 10:02:48 -04002190 const auto &vertexAttribs = vao->getVertexAttributes();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002191 const auto &vertexBindings = vao->getVertexBindings();
Jamie Madill8e344942015-07-09 14:22:07 -04002192 size_t maxEnabledAttrib = vao->getMaxEnabledAttribute();
Jamie Madillaebf9dd2015-04-28 12:39:07 -04002193 for (size_t attribIndex = 0; attribIndex < maxEnabledAttrib; attribIndex++)
Jamie Madilld9ba4f72014-08-04 10:47:59 -04002194 {
Jamie Madill81c2e252017-09-09 23:32:46 -04002195 const VertexAttribute &vertexAttrib = vertexAttribs[attribIndex];
Martin Radevdd5f27e2017-06-07 10:17:09 +03002196 auto *boundBuffer = vertexBindings[vertexAttrib.bindingIndex].getBuffer().get();
Jamie Madilld9ba4f72014-08-04 10:47:59 -04002197 if (vertexAttrib.enabled && boundBuffer && boundBuffer->isMapped())
2198 {
2199 return true;
2200 }
2201 }
2202
2203 return false;
2204 }
2205 else
2206 {
2207 Buffer *buffer = getTargetBuffer(target);
2208 return (buffer && buffer->isMapped());
2209 }
2210}
2211
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002212void State::syncDirtyObjects(const Context *context)
Jamie Madillc9d442d2016-01-20 11:17:24 -05002213{
2214 if (!mDirtyObjects.any())
2215 return;
2216
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002217 syncDirtyObjects(context, mDirtyObjects);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002218}
2219
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002220void State::syncDirtyObjects(const Context *context, const DirtyObjects &bitset)
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002221{
Jamie Madill6de51852017-04-12 09:53:01 -04002222 for (auto dirtyObject : bitset)
Jamie Madillc9d442d2016-01-20 11:17:24 -05002223 {
2224 switch (dirtyObject)
2225 {
2226 case DIRTY_OBJECT_READ_FRAMEBUFFER:
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002227 ASSERT(mReadFramebuffer);
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002228 mReadFramebuffer->syncState(context);
Jamie Madillc9d442d2016-01-20 11:17:24 -05002229 break;
2230 case DIRTY_OBJECT_DRAW_FRAMEBUFFER:
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002231 ASSERT(mDrawFramebuffer);
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002232 mDrawFramebuffer->syncState(context);
Jamie Madillc9d442d2016-01-20 11:17:24 -05002233 break;
2234 case DIRTY_OBJECT_VERTEX_ARRAY:
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002235 ASSERT(mVertexArray);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002236 mVertexArray->syncState(context);
Jamie Madillc9d442d2016-01-20 11:17:24 -05002237 break;
Jamie Madill81c2e252017-09-09 23:32:46 -04002238 case DIRTY_OBJECT_PROGRAM_TEXTURES:
2239 syncProgramTextures(context);
2240 break;
2241
Jamie Madillc9d442d2016-01-20 11:17:24 -05002242 default:
2243 UNREACHABLE();
2244 break;
2245 }
2246 }
2247
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002248 mDirtyObjects &= ~bitset;
2249}
2250
Jamie Madill81c2e252017-09-09 23:32:46 -04002251void State::syncProgramTextures(const Context *context)
2252{
Jamie Madill81c2e252017-09-09 23:32:46 -04002253 // TODO(jmadill): Fine-grained updates.
2254 if (!mProgram)
2255 {
2256 return;
2257 }
2258
2259 ASSERT(mDirtyObjects[DIRTY_OBJECT_PROGRAM_TEXTURES]);
2260 mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS);
2261
Jamie Madill0f80ed82017-09-19 00:24:56 -04002262 ActiveTextureMask newActiveTextures;
2263
Jamie Madill81c2e252017-09-09 23:32:46 -04002264 for (const SamplerBinding &samplerBinding : mProgram->getSamplerBindings())
2265 {
2266 if (samplerBinding.unreferenced)
2267 continue;
2268
2269 GLenum textureType = samplerBinding.textureType;
2270 for (GLuint textureUnitIndex : samplerBinding.boundTextureUnits)
2271 {
2272 Texture *texture = getSamplerTexture(textureUnitIndex, textureType);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002273 Sampler *sampler = getSampler(textureUnitIndex);
Jamie Madill0f80ed82017-09-19 00:24:56 -04002274 ASSERT(static_cast<size_t>(textureUnitIndex) < mCompleteTextureCache.size());
2275 ASSERT(static_cast<size_t>(textureUnitIndex) < newActiveTextures.size());
Jamie Madill81c2e252017-09-09 23:32:46 -04002276
2277 if (texture != nullptr)
2278 {
Jamie Madill81c2e252017-09-09 23:32:46 -04002279 // Mark the texture binding bit as dirty if the texture completeness changes.
2280 // TODO(jmadill): Use specific dirty bit for completeness change.
2281 if (texture->isSamplerComplete(context, sampler))
2282 {
Jamie Madill06ef36b2017-09-09 23:32:46 -04002283 texture->syncState();
Jamie Madill81c2e252017-09-09 23:32:46 -04002284 mCompleteTextureCache[textureUnitIndex] = texture;
2285 }
Jamie Madill0f80ed82017-09-19 00:24:56 -04002286 else
2287 {
2288 mCompleteTextureCache[textureUnitIndex] = nullptr;
2289 }
Jamie Madill81c2e252017-09-09 23:32:46 -04002290
2291 // Bind the texture unconditionally, to recieve completeness change notifications.
2292 mCompleteTextureBindings[textureUnitIndex].bind(texture->getDirtyChannel());
Jamie Madill0f80ed82017-09-19 00:24:56 -04002293 newActiveTextures.set(textureUnitIndex);
2294 mCompleteTexturesMask.set(textureUnitIndex);
Jamie Madill81c2e252017-09-09 23:32:46 -04002295 }
2296
Jamie Madill06ef36b2017-09-09 23:32:46 -04002297 if (sampler != nullptr)
2298 {
2299 sampler->syncState(context);
2300 }
Jamie Madill81c2e252017-09-09 23:32:46 -04002301 }
2302 }
Jamie Madill0f80ed82017-09-19 00:24:56 -04002303
2304 // Unset now missing textures.
2305 ActiveTextureMask negativeMask = mCompleteTexturesMask & ~newActiveTextures;
2306 if (negativeMask.any())
2307 {
2308 for (auto textureIndex : negativeMask)
2309 {
2310 mCompleteTextureBindings[textureIndex].reset();
2311 mCompleteTextureCache[textureIndex] = nullptr;
2312 mCompleteTexturesMask.reset(textureIndex);
2313 }
2314 }
Jamie Madill81c2e252017-09-09 23:32:46 -04002315}
2316
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002317void State::syncDirtyObject(const Context *context, GLenum target)
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002318{
2319 DirtyObjects localSet;
2320
2321 switch (target)
2322 {
2323 case GL_READ_FRAMEBUFFER:
2324 localSet.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
2325 break;
2326 case GL_DRAW_FRAMEBUFFER:
2327 localSet.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
2328 break;
2329 case GL_FRAMEBUFFER:
2330 localSet.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
2331 localSet.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
2332 break;
2333 case GL_VERTEX_ARRAY:
2334 localSet.set(DIRTY_OBJECT_VERTEX_ARRAY);
2335 break;
Jamie Madill81c2e252017-09-09 23:32:46 -04002336 case GL_TEXTURE:
2337 case GL_SAMPLER:
2338 case GL_PROGRAM:
2339 localSet.set(DIRTY_OBJECT_PROGRAM_TEXTURES);
2340 break;
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002341 }
2342
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002343 syncDirtyObjects(context, localSet);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002344}
2345
2346void State::setObjectDirty(GLenum target)
2347{
2348 switch (target)
2349 {
2350 case GL_READ_FRAMEBUFFER:
2351 mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
2352 break;
2353 case GL_DRAW_FRAMEBUFFER:
2354 mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
2355 break;
2356 case GL_FRAMEBUFFER:
2357 mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
2358 mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
2359 break;
2360 case GL_VERTEX_ARRAY:
2361 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
2362 break;
Jamie Madill81c2e252017-09-09 23:32:46 -04002363 case GL_TEXTURE:
2364 case GL_SAMPLER:
Jamie Madill81c2e252017-09-09 23:32:46 -04002365 case GL_PROGRAM:
2366 mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES);
2367 mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS);
2368 break;
Jamie Madilla779b612017-07-24 11:46:05 -04002369 }
2370}
2371
2372void State::onProgramExecutableChange(Program *program)
2373{
2374 // OpenGL Spec:
2375 // "If LinkProgram or ProgramBinary successfully re-links a program object
2376 // that was already in use as a result of a previous call to UseProgram, then the
2377 // generated executable code will be installed as part of the current rendering state."
2378 if (program->isLinked() && mProgram == program)
2379 {
2380 mDirtyBits.set(DIRTY_BIT_PROGRAM_EXECUTABLE);
Jamie Madill81c2e252017-09-09 23:32:46 -04002381 mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002382 }
Shannon Woods53a94a82014-06-24 15:20:36 -04002383}
Jamie Madillc9d442d2016-01-20 11:17:24 -05002384
Xinghua Cao65ec0b22017-03-28 16:10:52 +08002385void State::setImageUnit(const Context *context,
2386 GLuint unit,
2387 Texture *texture,
2388 GLint level,
2389 GLboolean layered,
2390 GLint layer,
2391 GLenum access,
2392 GLenum format)
2393{
2394 mImageUnits[unit].texture.set(context, texture);
2395 mImageUnits[unit].level = level;
2396 mImageUnits[unit].layered = layered;
2397 mImageUnits[unit].layer = layer;
2398 mImageUnits[unit].access = access;
2399 mImageUnits[unit].format = format;
2400}
2401
2402const ImageUnit &State::getImageUnit(GLuint unit) const
2403{
2404 return mImageUnits[unit];
2405}
2406
Jamie Madill81c2e252017-09-09 23:32:46 -04002407// Handle a dirty texture event.
Jamie Madill05b35b22017-10-03 09:01:44 -04002408void State::signal(size_t textureIndex, InitState initState)
Jamie Madill81c2e252017-09-09 23:32:46 -04002409{
2410 // Conservatively assume all textures are dirty.
2411 // TODO(jmadill): More fine-grained update.
2412 mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES);
2413}
2414
Jamie Madill05b35b22017-10-03 09:01:44 -04002415Error State::clearUnclearedActiveTextures(const Context *context)
2416{
2417 if (!mRobustResourceInit)
2418 {
2419 return NoError();
2420 }
2421
2422 // TODO(jmadill): Investigate improving the speed here.
2423 for (Texture *texture : mCompleteTextureCache)
2424 {
2425 if (texture)
2426 {
2427 ANGLE_TRY(texture->ensureInitialized(context));
2428 }
2429 }
2430 return NoError();
2431}
2432
Jamie Madillc9d442d2016-01-20 11:17:24 -05002433} // namespace gl