blob: a0c44ad3418be3aff3d4885d5e2718f407c4e13e [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"
Geoff Lang4751aab2017-10-30 15:14:52 -040026#include "libANGLE/renderer/ContextImpl.h"
Shannon Woods53a94a82014-06-24 15:20:36 -040027
Olli Etuahobbf1c102016-06-28 13:31:33 +030028namespace
29{
30
31GLenum ActiveQueryType(const GLenum type)
32{
33 return (type == GL_ANY_SAMPLES_PASSED_CONSERVATIVE) ? GL_ANY_SAMPLES_PASSED : type;
34}
35
36} // anonymous namepace
37
Shannon Woods53a94a82014-06-24 15:20:36 -040038namespace gl
39{
Geoff Lang76b10c92014-09-05 16:28:14 -040040
Shannon Woods53a94a82014-06-24 15:20:36 -040041State::State()
Jamie Madille79b1e12015-11-04 16:36:37 -050042 : mMaxDrawBuffers(0),
43 mMaxCombinedTextureImageUnits(0),
44 mDepthClearValue(0),
45 mStencilClearValue(0),
46 mScissorTest(false),
47 mSampleCoverage(false),
48 mSampleCoverageValue(0),
49 mSampleCoverageInvert(false),
Jiawei Shaodb342272017-09-27 10:21:45 +080050 mSampleMask(false),
51 mMaxSampleMaskWords(0),
Jamie Madille79b1e12015-11-04 16:36:37 -050052 mStencilRef(0),
53 mStencilBackRef(0),
54 mLineWidth(0),
55 mGenerateMipmapHint(GL_NONE),
56 mFragmentShaderDerivativeHint(GL_NONE),
Geoff Langf41a7152016-09-19 15:11:17 -040057 mBindGeneratesResource(true),
Geoff Langfeb8c682017-02-13 16:07:35 -050058 mClientArraysEnabled(true),
Jamie Madille79b1e12015-11-04 16:36:37 -050059 mNearZ(0),
60 mFarZ(0),
61 mReadFramebuffer(nullptr),
62 mDrawFramebuffer(nullptr),
63 mProgram(nullptr),
64 mVertexArray(nullptr),
65 mActiveSampler(0),
Sami Väisänen74c23472016-05-09 17:30:30 +030066 mPrimitiveRestart(false),
67 mMultiSampling(false),
Geoff Lang1d2c41d2016-10-19 16:14:46 -070068 mSampleAlphaToOne(false),
Jamie Madille08a1d32017-03-07 17:24:06 -050069 mFramebufferSRGB(true),
Jamie Madillc43be722017-07-13 16:22:14 -040070 mRobustResourceInit(false),
71 mProgramBinaryCacheEnabled(false)
Shannon Woods53a94a82014-06-24 15:20:36 -040072{
Geoff Lang76b10c92014-09-05 16:28:14 -040073}
74
75State::~State()
76{
Geoff Lang76b10c92014-09-05 16:28:14 -040077}
78
Jamie Madill4928b7c2017-06-20 12:57:39 -040079void State::initialize(const Context *context,
Geoff Langf41a7152016-09-19 15:11:17 -040080 bool debug,
Geoff Langfeb8c682017-02-13 16:07:35 -050081 bool bindGeneratesResource,
Jamie Madille08a1d32017-03-07 17:24:06 -050082 bool clientArraysEnabled,
Jamie Madillc43be722017-07-13 16:22:14 -040083 bool robustResourceInit,
84 bool programBinaryCacheEnabled)
Geoff Lang76b10c92014-09-05 16:28:14 -040085{
Jamie Madill4928b7c2017-06-20 12:57:39 -040086 const Caps &caps = context->getCaps();
87 const Extensions &extensions = context->getExtensions();
Geoff Lang4751aab2017-10-30 15:14:52 -040088 const Extensions &nativeExtensions = context->getImplementation()->getNativeExtensions();
Jamie Madill4928b7c2017-06-20 12:57:39 -040089 const Version &clientVersion = context->getClientVersion();
90
Shannon Woods2df6a602014-09-26 16:12:07 -040091 mMaxDrawBuffers = caps.maxDrawBuffers;
92 mMaxCombinedTextureImageUnits = caps.maxCombinedTextureImageUnits;
Shannon Woods53a94a82014-06-24 15:20:36 -040093
Jamie Madillf75ab352015-03-16 10:46:52 -040094 setColorClearValue(0.0f, 0.0f, 0.0f, 0.0f);
Shannon Woods53a94a82014-06-24 15:20:36 -040095
96 mDepthClearValue = 1.0f;
97 mStencilClearValue = 0;
98
Shannon Woods53a94a82014-06-24 15:20:36 -040099 mScissorTest = false;
100 mScissor.x = 0;
101 mScissor.y = 0;
102 mScissor.width = 0;
103 mScissor.height = 0;
104
Shannon Woods53a94a82014-06-24 15:20:36 -0400105 mBlendColor.red = 0;
106 mBlendColor.green = 0;
107 mBlendColor.blue = 0;
108 mBlendColor.alpha = 0;
109
Shannon Woods53a94a82014-06-24 15:20:36 -0400110 mStencilRef = 0;
111 mStencilBackRef = 0;
112
113 mSampleCoverage = false;
114 mSampleCoverageValue = 1.0f;
115 mSampleCoverageInvert = false;
Jiawei Shaodb342272017-09-27 10:21:45 +0800116
117 mMaxSampleMaskWords = caps.maxSampleMaskWords;
118 mSampleMask = false;
119 mSampleMaskValues.fill(~GLbitfield(0));
120
Shannon Woods53a94a82014-06-24 15:20:36 -0400121 mGenerateMipmapHint = GL_DONT_CARE;
122 mFragmentShaderDerivativeHint = GL_DONT_CARE;
123
Geoff Langf41a7152016-09-19 15:11:17 -0400124 mBindGeneratesResource = bindGeneratesResource;
Geoff Langfeb8c682017-02-13 16:07:35 -0500125 mClientArraysEnabled = clientArraysEnabled;
Geoff Langf41a7152016-09-19 15:11:17 -0400126
Shannon Woods53a94a82014-06-24 15:20:36 -0400127 mLineWidth = 1.0f;
128
129 mViewport.x = 0;
130 mViewport.y = 0;
131 mViewport.width = 0;
132 mViewport.height = 0;
133 mNearZ = 0.0f;
134 mFarZ = 1.0f;
135
136 mBlend.colorMaskRed = true;
137 mBlend.colorMaskGreen = true;
138 mBlend.colorMaskBlue = true;
139 mBlend.colorMaskAlpha = true;
140
Geoff Lang76b10c92014-09-05 16:28:14 -0400141 mActiveSampler = 0;
142
Shannon Woods23e05002014-09-22 19:07:27 -0400143 mVertexAttribCurrentValues.resize(caps.maxVertexAttributes);
Shannon Woods53a94a82014-06-24 15:20:36 -0400144
Geoff Lang4dc3af02016-11-18 14:09:27 -0500145 mUniformBuffers.resize(caps.maxUniformBufferBindings);
Shannon Woodsf3acaf92014-09-23 18:07:11 -0400146
Geoff Lang76b10c92014-09-05 16:28:14 -0400147 mSamplerTextures[GL_TEXTURE_2D].resize(caps.maxCombinedTextureImageUnits);
148 mSamplerTextures[GL_TEXTURE_CUBE_MAP].resize(caps.maxCombinedTextureImageUnits);
Geoff Langeb66a6e2016-10-31 13:06:12 -0400149 if (clientVersion >= Version(3, 0))
Shannon Woods53a94a82014-06-24 15:20:36 -0400150 {
Geoff Lang76b10c92014-09-05 16:28:14 -0400151 // TODO: These could also be enabled via extension
152 mSamplerTextures[GL_TEXTURE_2D_ARRAY].resize(caps.maxCombinedTextureImageUnits);
153 mSamplerTextures[GL_TEXTURE_3D].resize(caps.maxCombinedTextureImageUnits);
Shannon Woods53a94a82014-06-24 15:20:36 -0400154 }
Geoff Lang3b573612016-10-31 14:08:10 -0400155 if (clientVersion >= Version(3, 1))
156 {
157 mSamplerTextures[GL_TEXTURE_2D_MULTISAMPLE].resize(caps.maxCombinedTextureImageUnits);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800158
159 mAtomicCounterBuffers.resize(caps.maxAtomicCounterBufferBindings);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800160 mShaderStorageBuffers.resize(caps.maxShaderStorageBufferBindings);
Xinghua Cao65ec0b22017-03-28 16:10:52 +0800161 mImageUnits.resize(caps.maxImageUnits);
Geoff Lang3b573612016-10-31 14:08:10 -0400162 }
Geoff Lang4751aab2017-10-30 15:14:52 -0400163 if (nativeExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400164 {
165 mSamplerTextures[GL_TEXTURE_RECTANGLE_ANGLE].resize(caps.maxCombinedTextureImageUnits);
166 }
Geoff Lang4751aab2017-10-30 15:14:52 -0400167 if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400168 {
169 mSamplerTextures[GL_TEXTURE_EXTERNAL_OES].resize(caps.maxCombinedTextureImageUnits);
170 }
Jamie Madill81c2e252017-09-09 23:32:46 -0400171 mCompleteTextureCache.resize(caps.maxCombinedTextureImageUnits, nullptr);
172 mCompleteTextureBindings.reserve(caps.maxCombinedTextureImageUnits);
173 for (uint32_t textureIndex = 0; textureIndex < caps.maxCombinedTextureImageUnits;
174 ++textureIndex)
175 {
176 mCompleteTextureBindings.emplace_back(OnAttachmentDirtyBinding(this, textureIndex));
177 }
Shannon Woods53a94a82014-06-24 15:20:36 -0400178
Geoff Lang76b10c92014-09-05 16:28:14 -0400179 mSamplers.resize(caps.maxCombinedTextureImageUnits);
Shannon Woods53a94a82014-06-24 15:20:36 -0400180
Jamie Madill4928b7c2017-06-20 12:57:39 -0400181 mActiveQueries[GL_ANY_SAMPLES_PASSED].set(context, nullptr);
182 mActiveQueries[GL_ANY_SAMPLES_PASSED_CONSERVATIVE].set(context, nullptr);
183 mActiveQueries[GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN].set(context, nullptr);
184 mActiveQueries[GL_TIME_ELAPSED_EXT].set(context, nullptr);
185 mActiveQueries[GL_COMMANDS_COMPLETED_CHROMIUM].set(context, nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -0400186
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500187 mProgram = nullptr;
Shannon Woods53a94a82014-06-24 15:20:36 -0400188
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500189 mReadFramebuffer = nullptr;
190 mDrawFramebuffer = nullptr;
Jamie Madillb4b53c52015-02-03 15:22:48 -0500191
192 mPrimitiveRestart = false;
Geoff Lang70d0f492015-12-10 17:45:46 -0500193
194 mDebug.setOutputEnabled(debug);
195 mDebug.setMaxLoggedMessages(extensions.maxDebugLoggedMessages);
Sami Väisänen74c23472016-05-09 17:30:30 +0300196
Geoff Lang488130e2017-09-27 13:53:11 -0400197 mMultiSampling = true;
198 mSampleAlphaToOne = false;
Sami Väisänena797e062016-05-12 15:23:40 +0300199
200 mCoverageModulation = GL_NONE;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300201
202 angle::Matrix<GLfloat>::setToIdentity(mPathMatrixProj);
203 angle::Matrix<GLfloat>::setToIdentity(mPathMatrixMV);
204 mPathStencilFunc = GL_ALWAYS;
205 mPathStencilRef = 0;
206 mPathStencilMask = std::numeric_limits<GLuint>::max();
Jamie Madille08a1d32017-03-07 17:24:06 -0500207
208 mRobustResourceInit = robustResourceInit;
Jamie Madillc43be722017-07-13 16:22:14 -0400209 mProgramBinaryCacheEnabled = programBinaryCacheEnabled;
Shannon Woods53a94a82014-06-24 15:20:36 -0400210}
211
Jamie Madill6c1f6712017-02-14 19:08:04 -0500212void State::reset(const Context *context)
Shannon Woods53a94a82014-06-24 15:20:36 -0400213{
Jamie Madill8693bdb2017-09-02 15:32:14 -0400214 for (auto &bindingVec : mSamplerTextures)
Shannon Woods53a94a82014-06-24 15:20:36 -0400215 {
Jamie Madill8693bdb2017-09-02 15:32:14 -0400216 TextureBindingVector &textureVector = bindingVec.second;
Geoff Lang76b10c92014-09-05 16:28:14 -0400217 for (size_t textureIdx = 0; textureIdx < textureVector.size(); textureIdx++)
Shannon Woods53a94a82014-06-24 15:20:36 -0400218 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400219 textureVector[textureIdx].set(context, nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -0400220 }
221 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400222 for (size_t samplerIdx = 0; samplerIdx < mSamplers.size(); samplerIdx++)
223 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400224 mSamplers[samplerIdx].set(context, nullptr);
Geoff Lang76b10c92014-09-05 16:28:14 -0400225 }
Shannon Woods53a94a82014-06-24 15:20:36 -0400226
Xinghua Cao65ec0b22017-03-28 16:10:52 +0800227 for (auto &imageUnit : mImageUnits)
228 {
229 imageUnit.texture.set(context, nullptr);
230 imageUnit.level = 0;
231 imageUnit.layered = false;
232 imageUnit.layer = 0;
233 imageUnit.access = GL_READ_ONLY;
234 imageUnit.format = GL_R32UI;
235 }
236
Jamie Madill4928b7c2017-06-20 12:57:39 -0400237 mArrayBuffer.set(context, nullptr);
238 mDrawIndirectBuffer.set(context, nullptr);
239 mRenderbuffer.set(context, nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -0400240
Geoff Lang7dd2e102014-11-10 15:19:26 -0500241 if (mProgram)
242 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500243 mProgram->release(context);
Geoff Lang7dd2e102014-11-10 15:19:26 -0500244 }
Yunchao Hed7297bf2017-04-19 15:27:10 +0800245 mProgram = nullptr;
Geoff Lang7dd2e102014-11-10 15:19:26 -0500246
Yunchao Hea336b902017-08-02 16:05:21 +0800247 mProgramPipeline.set(context, nullptr);
248
Jamie Madill4928b7c2017-06-20 12:57:39 -0400249 mTransformFeedback.set(context, nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -0400250
251 for (State::ActiveQueryMap::iterator i = mActiveQueries.begin(); i != mActiveQueries.end(); i++)
252 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400253 i->second.set(context, nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -0400254 }
255
Jamie Madill4928b7c2017-06-20 12:57:39 -0400256 mGenericUniformBuffer.set(context, nullptr);
Shannon Woods8299bb02014-09-26 18:55:43 -0400257 for (BufferVector::iterator bufItr = mUniformBuffers.begin(); bufItr != mUniformBuffers.end(); ++bufItr)
Shannon Woods53a94a82014-06-24 15:20:36 -0400258 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400259 bufItr->set(context, nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -0400260 }
261
Jamie Madill4928b7c2017-06-20 12:57:39 -0400262 mCopyReadBuffer.set(context, nullptr);
263 mCopyWriteBuffer.set(context, nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -0400264
Corentin Wallezcda6af12017-10-30 19:20:37 -0400265 mPixelPackBuffer.set(context, nullptr);
266 mPixelUnpackBuffer.set(context, nullptr);
Geoff Lang7dd2e102014-11-10 15:19:26 -0500267
Jamie Madill4928b7c2017-06-20 12:57:39 -0400268 mGenericAtomicCounterBuffer.set(context, nullptr);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800269 for (auto &buf : mAtomicCounterBuffers)
270 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400271 buf.set(context, nullptr);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800272 }
273
Jamie Madill4928b7c2017-06-20 12:57:39 -0400274 mGenericShaderStorageBuffer.set(context, nullptr);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800275 for (auto &buf : mShaderStorageBuffers)
276 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400277 buf.set(context, nullptr);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800278 }
279
Sami Väisänene45e53b2016-05-25 10:36:04 +0300280 angle::Matrix<GLfloat>::setToIdentity(mPathMatrixProj);
281 angle::Matrix<GLfloat>::setToIdentity(mPathMatrixMV);
282 mPathStencilFunc = GL_ALWAYS;
283 mPathStencilRef = 0;
284 mPathStencilMask = std::numeric_limits<GLuint>::max();
285
Jamie Madill1b94d432015-08-07 13:23:23 -0400286 // TODO(jmadill): Is this necessary?
287 setAllDirtyBits();
Shannon Woods53a94a82014-06-24 15:20:36 -0400288}
289
290const RasterizerState &State::getRasterizerState() const
291{
292 return mRasterizer;
293}
294
295const BlendState &State::getBlendState() const
296{
297 return mBlend;
298}
299
300const DepthStencilState &State::getDepthStencilState() const
301{
302 return mDepthStencil;
303}
304
Jamie Madillf75ab352015-03-16 10:46:52 -0400305void State::setColorClearValue(float red, float green, float blue, float alpha)
Shannon Woods53a94a82014-06-24 15:20:36 -0400306{
307 mColorClearValue.red = red;
308 mColorClearValue.green = green;
309 mColorClearValue.blue = blue;
310 mColorClearValue.alpha = alpha;
Jamie Madill1b94d432015-08-07 13:23:23 -0400311 mDirtyBits.set(DIRTY_BIT_CLEAR_COLOR);
Shannon Woods53a94a82014-06-24 15:20:36 -0400312}
313
Jamie Madillf75ab352015-03-16 10:46:52 -0400314void State::setDepthClearValue(float depth)
Shannon Woods53a94a82014-06-24 15:20:36 -0400315{
316 mDepthClearValue = depth;
Jamie Madill1b94d432015-08-07 13:23:23 -0400317 mDirtyBits.set(DIRTY_BIT_CLEAR_DEPTH);
Shannon Woods53a94a82014-06-24 15:20:36 -0400318}
319
Jamie Madillf75ab352015-03-16 10:46:52 -0400320void State::setStencilClearValue(int stencil)
Shannon Woods53a94a82014-06-24 15:20:36 -0400321{
322 mStencilClearValue = stencil;
Jamie Madill1b94d432015-08-07 13:23:23 -0400323 mDirtyBits.set(DIRTY_BIT_CLEAR_STENCIL);
Shannon Woods53a94a82014-06-24 15:20:36 -0400324}
325
Shannon Woods53a94a82014-06-24 15:20:36 -0400326void State::setColorMask(bool red, bool green, bool blue, bool alpha)
327{
328 mBlend.colorMaskRed = red;
329 mBlend.colorMaskGreen = green;
330 mBlend.colorMaskBlue = blue;
331 mBlend.colorMaskAlpha = alpha;
Jamie Madill1b94d432015-08-07 13:23:23 -0400332 mDirtyBits.set(DIRTY_BIT_COLOR_MASK);
Shannon Woods53a94a82014-06-24 15:20:36 -0400333}
334
335void State::setDepthMask(bool mask)
336{
337 mDepthStencil.depthMask = mask;
Jamie Madill1b94d432015-08-07 13:23:23 -0400338 mDirtyBits.set(DIRTY_BIT_DEPTH_MASK);
Shannon Woods53a94a82014-06-24 15:20:36 -0400339}
340
341bool State::isRasterizerDiscardEnabled() const
342{
343 return mRasterizer.rasterizerDiscard;
344}
345
346void State::setRasterizerDiscard(bool enabled)
347{
348 mRasterizer.rasterizerDiscard = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400349 mDirtyBits.set(DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400350}
351
352bool State::isCullFaceEnabled() const
353{
354 return mRasterizer.cullFace;
355}
356
357void State::setCullFace(bool enabled)
358{
359 mRasterizer.cullFace = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400360 mDirtyBits.set(DIRTY_BIT_CULL_FACE_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400361}
362
Corentin Wallez2e568cf2017-09-18 17:05:22 -0400363void State::setCullMode(CullFaceMode mode)
Shannon Woods53a94a82014-06-24 15:20:36 -0400364{
365 mRasterizer.cullMode = mode;
Jamie Madill1b94d432015-08-07 13:23:23 -0400366 mDirtyBits.set(DIRTY_BIT_CULL_FACE);
Shannon Woods53a94a82014-06-24 15:20:36 -0400367}
368
369void State::setFrontFace(GLenum front)
370{
371 mRasterizer.frontFace = front;
Jamie Madill1b94d432015-08-07 13:23:23 -0400372 mDirtyBits.set(DIRTY_BIT_FRONT_FACE);
Shannon Woods53a94a82014-06-24 15:20:36 -0400373}
374
375bool State::isDepthTestEnabled() const
376{
377 return mDepthStencil.depthTest;
378}
379
380void State::setDepthTest(bool enabled)
381{
382 mDepthStencil.depthTest = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400383 mDirtyBits.set(DIRTY_BIT_DEPTH_TEST_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400384}
385
386void State::setDepthFunc(GLenum depthFunc)
387{
388 mDepthStencil.depthFunc = depthFunc;
Jamie Madill1b94d432015-08-07 13:23:23 -0400389 mDirtyBits.set(DIRTY_BIT_DEPTH_FUNC);
Shannon Woods53a94a82014-06-24 15:20:36 -0400390}
391
392void State::setDepthRange(float zNear, float zFar)
393{
394 mNearZ = zNear;
395 mFarZ = zFar;
Jamie Madill1b94d432015-08-07 13:23:23 -0400396 mDirtyBits.set(DIRTY_BIT_DEPTH_RANGE);
Shannon Woods53a94a82014-06-24 15:20:36 -0400397}
398
Geoff Langd42f5b82015-04-16 14:03:29 -0400399float State::getNearPlane() const
Shannon Woods53a94a82014-06-24 15:20:36 -0400400{
Geoff Langd42f5b82015-04-16 14:03:29 -0400401 return mNearZ;
402}
403
404float State::getFarPlane() const
405{
406 return mFarZ;
Shannon Woods53a94a82014-06-24 15:20:36 -0400407}
408
409bool State::isBlendEnabled() const
410{
411 return mBlend.blend;
412}
413
414void State::setBlend(bool enabled)
415{
416 mBlend.blend = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400417 mDirtyBits.set(DIRTY_BIT_BLEND_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400418}
419
420void State::setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha)
421{
422 mBlend.sourceBlendRGB = sourceRGB;
423 mBlend.destBlendRGB = destRGB;
424 mBlend.sourceBlendAlpha = sourceAlpha;
425 mBlend.destBlendAlpha = destAlpha;
Jamie Madill1b94d432015-08-07 13:23:23 -0400426 mDirtyBits.set(DIRTY_BIT_BLEND_FUNCS);
Shannon Woods53a94a82014-06-24 15:20:36 -0400427}
428
429void State::setBlendColor(float red, float green, float blue, float alpha)
430{
431 mBlendColor.red = red;
432 mBlendColor.green = green;
433 mBlendColor.blue = blue;
434 mBlendColor.alpha = alpha;
Jamie Madill1b94d432015-08-07 13:23:23 -0400435 mDirtyBits.set(DIRTY_BIT_BLEND_COLOR);
Shannon Woods53a94a82014-06-24 15:20:36 -0400436}
437
438void State::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation)
439{
440 mBlend.blendEquationRGB = rgbEquation;
441 mBlend.blendEquationAlpha = alphaEquation;
Jamie Madill1b94d432015-08-07 13:23:23 -0400442 mDirtyBits.set(DIRTY_BIT_BLEND_EQUATIONS);
Shannon Woods53a94a82014-06-24 15:20:36 -0400443}
444
445const ColorF &State::getBlendColor() const
446{
447 return mBlendColor;
448}
449
450bool State::isStencilTestEnabled() const
451{
452 return mDepthStencil.stencilTest;
453}
454
455void State::setStencilTest(bool enabled)
456{
457 mDepthStencil.stencilTest = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400458 mDirtyBits.set(DIRTY_BIT_STENCIL_TEST_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400459}
460
461void State::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask)
462{
463 mDepthStencil.stencilFunc = stencilFunc;
464 mStencilRef = (stencilRef > 0) ? stencilRef : 0;
465 mDepthStencil.stencilMask = stencilMask;
Jamie Madill1b94d432015-08-07 13:23:23 -0400466 mDirtyBits.set(DIRTY_BIT_STENCIL_FUNCS_FRONT);
Shannon Woods53a94a82014-06-24 15:20:36 -0400467}
468
469void State::setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask)
470{
471 mDepthStencil.stencilBackFunc = stencilBackFunc;
472 mStencilBackRef = (stencilBackRef > 0) ? stencilBackRef : 0;
473 mDepthStencil.stencilBackMask = stencilBackMask;
Jamie Madill1b94d432015-08-07 13:23:23 -0400474 mDirtyBits.set(DIRTY_BIT_STENCIL_FUNCS_BACK);
Shannon Woods53a94a82014-06-24 15:20:36 -0400475}
476
477void State::setStencilWritemask(GLuint stencilWritemask)
478{
479 mDepthStencil.stencilWritemask = stencilWritemask;
Jamie Madill1b94d432015-08-07 13:23:23 -0400480 mDirtyBits.set(DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
Shannon Woods53a94a82014-06-24 15:20:36 -0400481}
482
483void State::setStencilBackWritemask(GLuint stencilBackWritemask)
484{
485 mDepthStencil.stencilBackWritemask = stencilBackWritemask;
Jamie Madill1b94d432015-08-07 13:23:23 -0400486 mDirtyBits.set(DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Shannon Woods53a94a82014-06-24 15:20:36 -0400487}
488
489void State::setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass)
490{
491 mDepthStencil.stencilFail = stencilFail;
492 mDepthStencil.stencilPassDepthFail = stencilPassDepthFail;
493 mDepthStencil.stencilPassDepthPass = stencilPassDepthPass;
Jamie Madill1b94d432015-08-07 13:23:23 -0400494 mDirtyBits.set(DIRTY_BIT_STENCIL_OPS_FRONT);
Shannon Woods53a94a82014-06-24 15:20:36 -0400495}
496
497void State::setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass)
498{
499 mDepthStencil.stencilBackFail = stencilBackFail;
500 mDepthStencil.stencilBackPassDepthFail = stencilBackPassDepthFail;
501 mDepthStencil.stencilBackPassDepthPass = stencilBackPassDepthPass;
Jamie Madill1b94d432015-08-07 13:23:23 -0400502 mDirtyBits.set(DIRTY_BIT_STENCIL_OPS_BACK);
Shannon Woods53a94a82014-06-24 15:20:36 -0400503}
504
505GLint State::getStencilRef() const
506{
507 return mStencilRef;
508}
509
510GLint State::getStencilBackRef() const
511{
512 return mStencilBackRef;
513}
514
515bool State::isPolygonOffsetFillEnabled() const
516{
517 return mRasterizer.polygonOffsetFill;
518}
519
520void State::setPolygonOffsetFill(bool enabled)
521{
Jamie Madill1b94d432015-08-07 13:23:23 -0400522 mRasterizer.polygonOffsetFill = enabled;
523 mDirtyBits.set(DIRTY_BIT_POLYGON_OFFSET_FILL_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400524}
525
526void State::setPolygonOffsetParams(GLfloat factor, GLfloat units)
527{
528 // An application can pass NaN values here, so handle this gracefully
529 mRasterizer.polygonOffsetFactor = factor != factor ? 0.0f : factor;
530 mRasterizer.polygonOffsetUnits = units != units ? 0.0f : units;
Jamie Madill1b94d432015-08-07 13:23:23 -0400531 mDirtyBits.set(DIRTY_BIT_POLYGON_OFFSET);
Shannon Woods53a94a82014-06-24 15:20:36 -0400532}
533
534bool State::isSampleAlphaToCoverageEnabled() const
535{
536 return mBlend.sampleAlphaToCoverage;
537}
538
539void State::setSampleAlphaToCoverage(bool enabled)
540{
541 mBlend.sampleAlphaToCoverage = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400542 mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400543}
544
545bool State::isSampleCoverageEnabled() const
546{
547 return mSampleCoverage;
548}
549
550void State::setSampleCoverage(bool enabled)
551{
552 mSampleCoverage = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400553 mDirtyBits.set(DIRTY_BIT_SAMPLE_COVERAGE_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400554}
555
556void State::setSampleCoverageParams(GLclampf value, bool invert)
557{
558 mSampleCoverageValue = value;
559 mSampleCoverageInvert = invert;
Jamie Madill1b94d432015-08-07 13:23:23 -0400560 mDirtyBits.set(DIRTY_BIT_SAMPLE_COVERAGE);
Shannon Woods53a94a82014-06-24 15:20:36 -0400561}
562
Geoff Lang0fbb6002015-04-16 11:11:53 -0400563GLclampf State::getSampleCoverageValue() const
Shannon Woods53a94a82014-06-24 15:20:36 -0400564{
Geoff Lang0fbb6002015-04-16 11:11:53 -0400565 return mSampleCoverageValue;
566}
Shannon Woods53a94a82014-06-24 15:20:36 -0400567
Geoff Lang0fbb6002015-04-16 11:11:53 -0400568bool State::getSampleCoverageInvert() const
569{
570 return mSampleCoverageInvert;
Shannon Woods53a94a82014-06-24 15:20:36 -0400571}
572
Jiawei Shaodb342272017-09-27 10:21:45 +0800573bool State::isSampleMaskEnabled() const
574{
575 return mSampleMask;
576}
577
578void State::setSampleMaskEnabled(bool enabled)
579{
580 mSampleMask = enabled;
581 mDirtyBits.set(DIRTY_BIT_SAMPLE_MASK_ENABLED);
582}
583
584void State::setSampleMaskParams(GLuint maskNumber, GLbitfield mask)
585{
586 ASSERT(maskNumber < mMaxSampleMaskWords);
587 mSampleMaskValues[maskNumber] = mask;
Jamie Madillc67323a2017-11-02 23:11:41 -0400588 // TODO(jmadill): Use a child dirty bit if we ever use more than two words.
589 mDirtyBits.set(DIRTY_BIT_SAMPLE_MASK);
Jiawei Shaodb342272017-09-27 10:21:45 +0800590}
591
592GLbitfield State::getSampleMaskWord(GLuint maskNumber) const
593{
594 ASSERT(maskNumber < mMaxSampleMaskWords);
595 return mSampleMaskValues[maskNumber];
596}
597
598GLuint State::getMaxSampleMaskWords() const
599{
600 return mMaxSampleMaskWords;
601}
602
Sami Väisänen74c23472016-05-09 17:30:30 +0300603void State::setSampleAlphaToOne(bool enabled)
604{
605 mSampleAlphaToOne = enabled;
606 mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_ONE);
607}
608
609bool State::isSampleAlphaToOneEnabled() const
610{
611 return mSampleAlphaToOne;
612}
613
614void State::setMultisampling(bool enabled)
615{
616 mMultiSampling = enabled;
617 mDirtyBits.set(DIRTY_BIT_MULTISAMPLING);
618}
619
620bool State::isMultisamplingEnabled() const
621{
622 return mMultiSampling;
623}
624
Shannon Woods53a94a82014-06-24 15:20:36 -0400625bool State::isScissorTestEnabled() const
626{
627 return mScissorTest;
628}
629
630void State::setScissorTest(bool enabled)
631{
632 mScissorTest = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400633 mDirtyBits.set(DIRTY_BIT_SCISSOR_TEST_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400634}
635
636void State::setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height)
637{
638 mScissor.x = x;
639 mScissor.y = y;
640 mScissor.width = width;
641 mScissor.height = height;
Jamie Madill1b94d432015-08-07 13:23:23 -0400642 mDirtyBits.set(DIRTY_BIT_SCISSOR);
Shannon Woods53a94a82014-06-24 15:20:36 -0400643}
644
645const Rectangle &State::getScissor() const
646{
647 return mScissor;
648}
649
650bool State::isDitherEnabled() const
651{
652 return mBlend.dither;
653}
654
655void State::setDither(bool enabled)
656{
657 mBlend.dither = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400658 mDirtyBits.set(DIRTY_BIT_DITHER_ENABLED);
Shannon Woods53a94a82014-06-24 15:20:36 -0400659}
660
Jamie Madillb4b53c52015-02-03 15:22:48 -0500661bool State::isPrimitiveRestartEnabled() const
662{
663 return mPrimitiveRestart;
664}
665
666void State::setPrimitiveRestart(bool enabled)
667{
668 mPrimitiveRestart = enabled;
Jamie Madill1b94d432015-08-07 13:23:23 -0400669 mDirtyBits.set(DIRTY_BIT_PRIMITIVE_RESTART_ENABLED);
Jamie Madillb4b53c52015-02-03 15:22:48 -0500670}
671
Shannon Woods53a94a82014-06-24 15:20:36 -0400672void State::setEnableFeature(GLenum feature, bool enabled)
673{
674 switch (feature)
675 {
Sami Väisänen74c23472016-05-09 17:30:30 +0300676 case GL_MULTISAMPLE_EXT: setMultisampling(enabled); break;
677 case GL_SAMPLE_ALPHA_TO_ONE_EXT: setSampleAlphaToOne(enabled); break;
Shannon Woods53a94a82014-06-24 15:20:36 -0400678 case GL_CULL_FACE: setCullFace(enabled); break;
679 case GL_POLYGON_OFFSET_FILL: setPolygonOffsetFill(enabled); break;
680 case GL_SAMPLE_ALPHA_TO_COVERAGE: setSampleAlphaToCoverage(enabled); break;
681 case GL_SAMPLE_COVERAGE: setSampleCoverage(enabled); break;
682 case GL_SCISSOR_TEST: setScissorTest(enabled); break;
683 case GL_STENCIL_TEST: setStencilTest(enabled); break;
684 case GL_DEPTH_TEST: setDepthTest(enabled); break;
685 case GL_BLEND: setBlend(enabled); break;
686 case GL_DITHER: setDither(enabled); break;
Jamie Madillb4b53c52015-02-03 15:22:48 -0500687 case GL_PRIMITIVE_RESTART_FIXED_INDEX: setPrimitiveRestart(enabled); break;
Shannon Woods53a94a82014-06-24 15:20:36 -0400688 case GL_RASTERIZER_DISCARD: setRasterizerDiscard(enabled); break;
Geoff Lang3b573612016-10-31 14:08:10 -0400689 case GL_SAMPLE_MASK:
Jiawei Shaodb342272017-09-27 10:21:45 +0800690 setSampleMaskEnabled(enabled);
Geoff Lang3b573612016-10-31 14:08:10 -0400691 break;
Geoff Lang70d0f492015-12-10 17:45:46 -0500692 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
693 mDebug.setOutputSynchronous(enabled);
694 break;
695 case GL_DEBUG_OUTPUT:
696 mDebug.setOutputEnabled(enabled);
697 break;
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700698 case GL_FRAMEBUFFER_SRGB_EXT:
699 setFramebufferSRGB(enabled);
700 break;
Shannon Woods53a94a82014-06-24 15:20:36 -0400701 default: UNREACHABLE();
702 }
703}
704
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700705bool State::getEnableFeature(GLenum feature) const
Shannon Woods53a94a82014-06-24 15:20:36 -0400706{
707 switch (feature)
708 {
Sami Väisänen74c23472016-05-09 17:30:30 +0300709 case GL_MULTISAMPLE_EXT: return isMultisamplingEnabled();
710 case GL_SAMPLE_ALPHA_TO_ONE_EXT: return isSampleAlphaToOneEnabled();
Shannon Woods53a94a82014-06-24 15:20:36 -0400711 case GL_CULL_FACE: return isCullFaceEnabled();
712 case GL_POLYGON_OFFSET_FILL: return isPolygonOffsetFillEnabled();
713 case GL_SAMPLE_ALPHA_TO_COVERAGE: return isSampleAlphaToCoverageEnabled();
714 case GL_SAMPLE_COVERAGE: return isSampleCoverageEnabled();
715 case GL_SCISSOR_TEST: return isScissorTestEnabled();
716 case GL_STENCIL_TEST: return isStencilTestEnabled();
717 case GL_DEPTH_TEST: return isDepthTestEnabled();
718 case GL_BLEND: return isBlendEnabled();
719 case GL_DITHER: return isDitherEnabled();
Jamie Madillb4b53c52015-02-03 15:22:48 -0500720 case GL_PRIMITIVE_RESTART_FIXED_INDEX: return isPrimitiveRestartEnabled();
Shannon Woods53a94a82014-06-24 15:20:36 -0400721 case GL_RASTERIZER_DISCARD: return isRasterizerDiscardEnabled();
Geoff Langb5e997f2016-12-06 10:55:34 -0500722 case GL_SAMPLE_MASK:
Jiawei Shaodb342272017-09-27 10:21:45 +0800723 return isSampleMaskEnabled();
Geoff Lang70d0f492015-12-10 17:45:46 -0500724 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
725 return mDebug.isOutputSynchronous();
726 case GL_DEBUG_OUTPUT:
727 return mDebug.isOutputEnabled();
Geoff Langf41a7152016-09-19 15:11:17 -0400728 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
729 return isBindGeneratesResourceEnabled();
Geoff Langfeb8c682017-02-13 16:07:35 -0500730 case GL_CLIENT_ARRAYS_ANGLE:
731 return areClientArraysEnabled();
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700732 case GL_FRAMEBUFFER_SRGB_EXT:
733 return getFramebufferSRGB();
Geoff Langb433e872017-10-05 14:01:47 -0400734 case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE:
Jamie Madille08a1d32017-03-07 17:24:06 -0500735 return mRobustResourceInit;
Jamie Madillc43be722017-07-13 16:22:14 -0400736 case GL_PROGRAM_CACHE_ENABLED_ANGLE:
737 return mProgramBinaryCacheEnabled;
738
739 default:
740 UNREACHABLE();
741 return false;
Shannon Woods53a94a82014-06-24 15:20:36 -0400742 }
743}
744
745void State::setLineWidth(GLfloat width)
746{
747 mLineWidth = width;
Jamie Madill1b94d432015-08-07 13:23:23 -0400748 mDirtyBits.set(DIRTY_BIT_LINE_WIDTH);
Shannon Woods53a94a82014-06-24 15:20:36 -0400749}
750
Geoff Lang4b3f4162015-04-16 13:22:05 -0400751float State::getLineWidth() const
752{
753 return mLineWidth;
754}
755
Shannon Woods53a94a82014-06-24 15:20:36 -0400756void State::setGenerateMipmapHint(GLenum hint)
757{
758 mGenerateMipmapHint = hint;
Jamie Madill1b94d432015-08-07 13:23:23 -0400759 mDirtyBits.set(DIRTY_BIT_GENERATE_MIPMAP_HINT);
Shannon Woods53a94a82014-06-24 15:20:36 -0400760}
761
762void State::setFragmentShaderDerivativeHint(GLenum hint)
763{
764 mFragmentShaderDerivativeHint = hint;
Jamie Madill1b94d432015-08-07 13:23:23 -0400765 mDirtyBits.set(DIRTY_BIT_SHADER_DERIVATIVE_HINT);
Shannon Woods53a94a82014-06-24 15:20:36 -0400766 // TODO: Propagate the hint to shader translator so we can write
767 // ddx, ddx_coarse, or ddx_fine depending on the hint.
768 // Ignore for now. It is valid for implementations to ignore hint.
769}
770
Geoff Langf41a7152016-09-19 15:11:17 -0400771bool State::isBindGeneratesResourceEnabled() const
772{
773 return mBindGeneratesResource;
774}
775
Geoff Langfeb8c682017-02-13 16:07:35 -0500776bool State::areClientArraysEnabled() const
777{
778 return mClientArraysEnabled;
779}
780
Shannon Woods53a94a82014-06-24 15:20:36 -0400781void State::setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height)
782{
783 mViewport.x = x;
784 mViewport.y = y;
785 mViewport.width = width;
786 mViewport.height = height;
Jamie Madill1b94d432015-08-07 13:23:23 -0400787 mDirtyBits.set(DIRTY_BIT_VIEWPORT);
Shannon Woods53a94a82014-06-24 15:20:36 -0400788}
789
790const Rectangle &State::getViewport() const
791{
792 return mViewport;
793}
794
795void State::setActiveSampler(unsigned int active)
796{
797 mActiveSampler = active;
798}
799
800unsigned int State::getActiveSampler() const
801{
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700802 return static_cast<unsigned int>(mActiveSampler);
Shannon Woods53a94a82014-06-24 15:20:36 -0400803}
804
Jamie Madill4928b7c2017-06-20 12:57:39 -0400805void State::setSamplerTexture(const Context *context, GLenum type, Texture *texture)
Shannon Woods53a94a82014-06-24 15:20:36 -0400806{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400807 mSamplerTextures[type][mActiveSampler].set(context, texture);
Jamie Madill81c2e252017-09-09 23:32:46 -0400808 mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS);
809 mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES);
Shannon Woods53a94a82014-06-24 15:20:36 -0400810}
811
Jamie Madillc29968b2016-01-20 11:17:23 -0500812Texture *State::getTargetTexture(GLenum target) const
813{
814 return getSamplerTexture(static_cast<unsigned int>(mActiveSampler), target);
815}
816
Geoff Lang76b10c92014-09-05 16:28:14 -0400817Texture *State::getSamplerTexture(unsigned int sampler, GLenum type) const
Shannon Woods53a94a82014-06-24 15:20:36 -0400818{
Jamie Madill5864ac22015-01-12 14:43:07 -0500819 const auto it = mSamplerTextures.find(type);
820 ASSERT(it != mSamplerTextures.end());
Jamie Madill3d3d2f22015-09-23 16:47:51 -0400821 ASSERT(sampler < it->second.size());
Jamie Madill5864ac22015-01-12 14:43:07 -0500822 return it->second[sampler].get();
Shannon Woods53a94a82014-06-24 15:20:36 -0400823}
824
Geoff Lang76b10c92014-09-05 16:28:14 -0400825GLuint State::getSamplerTextureId(unsigned int sampler, GLenum type) const
Shannon Woods53a94a82014-06-24 15:20:36 -0400826{
Jamie Madill5864ac22015-01-12 14:43:07 -0500827 const auto it = mSamplerTextures.find(type);
828 ASSERT(it != mSamplerTextures.end());
Jamie Madill3d3d2f22015-09-23 16:47:51 -0400829 ASSERT(sampler < it->second.size());
Jamie Madill5864ac22015-01-12 14:43:07 -0500830 return it->second[sampler].id();
Shannon Woods53a94a82014-06-24 15:20:36 -0400831}
832
Jamie Madilla02315b2017-02-23 14:14:47 -0500833void State::detachTexture(const Context *context, const TextureMap &zeroTextures, GLuint texture)
Shannon Woods53a94a82014-06-24 15:20:36 -0400834{
835 // Textures have a detach method on State rather than a simple
836 // removeBinding, because the zero/null texture objects are managed
837 // separately, and don't have to go through the Context's maps or
838 // the ResourceManager.
839
840 // [OpenGL ES 2.0.24] section 3.8 page 84:
841 // If a texture object is deleted, it is as if all texture units which are bound to that texture object are
842 // rebound to texture object zero
843
Corentin Walleza2257da2016-04-19 16:43:12 -0400844 for (auto &bindingVec : mSamplerTextures)
Shannon Woods53a94a82014-06-24 15:20:36 -0400845 {
Corentin Walleza2257da2016-04-19 16:43:12 -0400846 GLenum textureType = bindingVec.first;
847 TextureBindingVector &textureVector = bindingVec.second;
Jamie Madill81c2e252017-09-09 23:32:46 -0400848 for (BindingPointer<Texture> &binding : textureVector)
Shannon Woods53a94a82014-06-24 15:20:36 -0400849 {
Geoff Lang76b10c92014-09-05 16:28:14 -0400850 if (binding.id() == texture)
Shannon Woods53a94a82014-06-24 15:20:36 -0400851 {
Jamie Madill5864ac22015-01-12 14:43:07 -0500852 auto it = zeroTextures.find(textureType);
853 ASSERT(it != zeroTextures.end());
Jamie Madille6382c32014-11-07 15:05:26 -0500854 // Zero textures are the "default" textures instead of NULL
Jamie Madill4928b7c2017-06-20 12:57:39 -0400855 binding.set(context, it->second.get());
Jamie Madill81c2e252017-09-09 23:32:46 -0400856 mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS);
Shannon Woods53a94a82014-06-24 15:20:36 -0400857 }
858 }
859 }
860
Xinghua Cao65ec0b22017-03-28 16:10:52 +0800861 for (auto &bindingImageUnit : mImageUnits)
862 {
863 if (bindingImageUnit.texture.id() == texture)
864 {
865 bindingImageUnit.texture.set(context, nullptr);
866 bindingImageUnit.level = 0;
867 bindingImageUnit.layered = false;
868 bindingImageUnit.layer = 0;
869 bindingImageUnit.access = GL_READ_ONLY;
870 bindingImageUnit.format = GL_R32UI;
871 break;
872 }
873 }
874
Shannon Woods53a94a82014-06-24 15:20:36 -0400875 // [OpenGL ES 2.0.24] section 4.4 page 112:
876 // If a texture object is deleted while its image is attached to the currently bound framebuffer, then it is
877 // as if Texture2DAttachment had been called, with a texture of 0, for each attachment point to which this
878 // image was attached in the currently bound framebuffer.
879
Jamie Madill8693bdb2017-09-02 15:32:14 -0400880 if (mReadFramebuffer && mReadFramebuffer->detachTexture(context, texture))
Shannon Woods53a94a82014-06-24 15:20:36 -0400881 {
Jamie Madill8693bdb2017-09-02 15:32:14 -0400882 mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
Shannon Woods53a94a82014-06-24 15:20:36 -0400883 }
884
Jamie Madill8693bdb2017-09-02 15:32:14 -0400885 if (mDrawFramebuffer && mDrawFramebuffer->detachTexture(context, texture))
Shannon Woods53a94a82014-06-24 15:20:36 -0400886 {
Jamie Madill8693bdb2017-09-02 15:32:14 -0400887 mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Shannon Woods53a94a82014-06-24 15:20:36 -0400888 }
889}
890
Jamie Madill4928b7c2017-06-20 12:57:39 -0400891void State::initializeZeroTextures(const Context *context, const TextureMap &zeroTextures)
Jamie Madille6382c32014-11-07 15:05:26 -0500892{
893 for (const auto &zeroTexture : zeroTextures)
894 {
895 auto &samplerTextureArray = mSamplerTextures[zeroTexture.first];
896
897 for (size_t textureUnit = 0; textureUnit < samplerTextureArray.size(); ++textureUnit)
898 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400899 samplerTextureArray[textureUnit].set(context, zeroTexture.second.get());
Jamie Madille6382c32014-11-07 15:05:26 -0500900 }
901 }
902}
903
Jamie Madill4928b7c2017-06-20 12:57:39 -0400904void State::setSamplerBinding(const Context *context, GLuint textureUnit, Sampler *sampler)
Shannon Woods53a94a82014-06-24 15:20:36 -0400905{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400906 mSamplers[textureUnit].set(context, sampler);
Jamie Madill81c2e252017-09-09 23:32:46 -0400907 mDirtyBits.set(DIRTY_BIT_SAMPLER_BINDINGS);
908 mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES);
Shannon Woods53a94a82014-06-24 15:20:36 -0400909}
910
911GLuint State::getSamplerId(GLuint textureUnit) const
912{
Geoff Lang76b10c92014-09-05 16:28:14 -0400913 ASSERT(textureUnit < mSamplers.size());
Shannon Woods53a94a82014-06-24 15:20:36 -0400914 return mSamplers[textureUnit].id();
915}
916
917Sampler *State::getSampler(GLuint textureUnit) const
918{
919 return mSamplers[textureUnit].get();
920}
921
Jamie Madill4928b7c2017-06-20 12:57:39 -0400922void State::detachSampler(const Context *context, GLuint sampler)
Shannon Woods53a94a82014-06-24 15:20:36 -0400923{
924 // [OpenGL ES 3.0.2] section 3.8.2 pages 123-124:
925 // If a sampler object that is currently bound to one or more texture units is
926 // deleted, it is as though BindSampler is called once for each texture unit to
927 // which the sampler is bound, with unit set to the texture unit and sampler set to zero.
Jamie Madill81c2e252017-09-09 23:32:46 -0400928 for (BindingPointer<Sampler> &samplerBinding : mSamplers)
Shannon Woods53a94a82014-06-24 15:20:36 -0400929 {
Geoff Lang76b10c92014-09-05 16:28:14 -0400930 if (samplerBinding.id() == sampler)
Shannon Woods53a94a82014-06-24 15:20:36 -0400931 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400932 samplerBinding.set(context, nullptr);
Jamie Madill81c2e252017-09-09 23:32:46 -0400933 mDirtyBits.set(DIRTY_BIT_SAMPLER_BINDINGS);
Shannon Woods53a94a82014-06-24 15:20:36 -0400934 }
935 }
936}
937
Jamie Madill4928b7c2017-06-20 12:57:39 -0400938void State::setRenderbufferBinding(const Context *context, Renderbuffer *renderbuffer)
Shannon Woods53a94a82014-06-24 15:20:36 -0400939{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400940 mRenderbuffer.set(context, renderbuffer);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400941 mDirtyBits.set(DIRTY_BIT_RENDERBUFFER_BINDING);
Shannon Woods53a94a82014-06-24 15:20:36 -0400942}
943
944GLuint State::getRenderbufferId() const
945{
946 return mRenderbuffer.id();
947}
948
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700949Renderbuffer *State::getCurrentRenderbuffer() const
Shannon Woods53a94a82014-06-24 15:20:36 -0400950{
951 return mRenderbuffer.get();
952}
953
Jamie Madilla02315b2017-02-23 14:14:47 -0500954void State::detachRenderbuffer(const Context *context, GLuint renderbuffer)
Shannon Woods53a94a82014-06-24 15:20:36 -0400955{
956 // [OpenGL ES 2.0.24] section 4.4 page 109:
957 // If a renderbuffer that is currently bound to RENDERBUFFER is deleted, it is as though BindRenderbuffer
958 // had been executed with the target RENDERBUFFER and name of zero.
959
960 if (mRenderbuffer.id() == renderbuffer)
961 {
Jamie Madill8693bdb2017-09-02 15:32:14 -0400962 setRenderbufferBinding(context, nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -0400963 }
964
965 // [OpenGL ES 2.0.24] section 4.4 page 111:
966 // If a renderbuffer object is deleted while its image is attached to the currently bound framebuffer,
967 // then it is as if FramebufferRenderbuffer had been called, with a renderbuffer of 0, for each attachment
968 // point to which this image was attached in the currently bound framebuffer.
969
970 Framebuffer *readFramebuffer = mReadFramebuffer;
971 Framebuffer *drawFramebuffer = mDrawFramebuffer;
972
Jamie Madill8693bdb2017-09-02 15:32:14 -0400973 if (readFramebuffer && readFramebuffer->detachRenderbuffer(context, renderbuffer))
Shannon Woods53a94a82014-06-24 15:20:36 -0400974 {
Jamie Madill8693bdb2017-09-02 15:32:14 -0400975 mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
Shannon Woods53a94a82014-06-24 15:20:36 -0400976 }
977
978 if (drawFramebuffer && drawFramebuffer != readFramebuffer)
979 {
Jamie Madill8693bdb2017-09-02 15:32:14 -0400980 if (drawFramebuffer->detachRenderbuffer(context, renderbuffer))
981 {
982 mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
983 }
Shannon Woods53a94a82014-06-24 15:20:36 -0400984 }
985
986}
987
988void State::setReadFramebufferBinding(Framebuffer *framebuffer)
989{
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500990 if (mReadFramebuffer == framebuffer)
991 return;
992
Shannon Woods53a94a82014-06-24 15:20:36 -0400993 mReadFramebuffer = framebuffer;
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500994 mDirtyBits.set(DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
995
996 if (mReadFramebuffer && mReadFramebuffer->hasAnyDirtyBit())
997 {
998 mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
999 }
Shannon Woods53a94a82014-06-24 15:20:36 -04001000}
1001
1002void State::setDrawFramebufferBinding(Framebuffer *framebuffer)
1003{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05001004 if (mDrawFramebuffer == framebuffer)
1005 return;
1006
Shannon Woods53a94a82014-06-24 15:20:36 -04001007 mDrawFramebuffer = framebuffer;
Jamie Madill60ec6ea2016-01-22 15:27:19 -05001008 mDirtyBits.set(DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
1009
1010 if (mDrawFramebuffer && mDrawFramebuffer->hasAnyDirtyBit())
1011 {
1012 mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
1013 }
Shannon Woods53a94a82014-06-24 15:20:36 -04001014}
1015
1016Framebuffer *State::getTargetFramebuffer(GLenum target) const
1017{
1018 switch (target)
1019 {
Jamie Madill60ec6ea2016-01-22 15:27:19 -05001020 case GL_READ_FRAMEBUFFER_ANGLE:
1021 return mReadFramebuffer;
1022 case GL_DRAW_FRAMEBUFFER_ANGLE:
1023 case GL_FRAMEBUFFER:
1024 return mDrawFramebuffer;
1025 default:
1026 UNREACHABLE();
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001027 return nullptr;
Shannon Woods53a94a82014-06-24 15:20:36 -04001028 }
1029}
1030
Jamie Madill51f40ec2016-06-15 14:06:00 -04001031Framebuffer *State::getReadFramebuffer() const
Shannon Woods53a94a82014-06-24 15:20:36 -04001032{
1033 return mReadFramebuffer;
1034}
1035
Jamie Madill51f40ec2016-06-15 14:06:00 -04001036Framebuffer *State::getDrawFramebuffer() const
Shannon Woods53a94a82014-06-24 15:20:36 -04001037{
1038 return mDrawFramebuffer;
1039}
1040
1041bool State::removeReadFramebufferBinding(GLuint framebuffer)
1042{
Jamie Madill77a72f62015-04-14 11:18:32 -04001043 if (mReadFramebuffer != nullptr &&
1044 mReadFramebuffer->id() == framebuffer)
Shannon Woods53a94a82014-06-24 15:20:36 -04001045 {
Jamie Madill60ec6ea2016-01-22 15:27:19 -05001046 setReadFramebufferBinding(nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -04001047 return true;
1048 }
1049
1050 return false;
1051}
1052
1053bool State::removeDrawFramebufferBinding(GLuint framebuffer)
1054{
Jamie Madill77a72f62015-04-14 11:18:32 -04001055 if (mReadFramebuffer != nullptr &&
1056 mDrawFramebuffer->id() == framebuffer)
Shannon Woods53a94a82014-06-24 15:20:36 -04001057 {
Jamie Madill60ec6ea2016-01-22 15:27:19 -05001058 setDrawFramebufferBinding(nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -04001059 return true;
1060 }
1061
1062 return false;
1063}
1064
1065void State::setVertexArrayBinding(VertexArray *vertexArray)
1066{
1067 mVertexArray = vertexArray;
Jamie Madill0b9e9032015-08-17 11:51:52 +00001068 mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING);
Jamie Madillc9d442d2016-01-20 11:17:24 -05001069
1070 if (mVertexArray && mVertexArray->hasAnyDirtyBit())
1071 {
1072 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
1073 }
Shannon Woods53a94a82014-06-24 15:20:36 -04001074}
1075
1076GLuint State::getVertexArrayId() const
1077{
Yunchao He4f285442017-04-21 12:15:49 +08001078 ASSERT(mVertexArray != nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -04001079 return mVertexArray->id();
1080}
1081
1082VertexArray *State::getVertexArray() const
1083{
Yunchao He4f285442017-04-21 12:15:49 +08001084 ASSERT(mVertexArray != nullptr);
Shannon Woods53a94a82014-06-24 15:20:36 -04001085 return mVertexArray;
1086}
1087
1088bool State::removeVertexArrayBinding(GLuint vertexArray)
1089{
1090 if (mVertexArray->id() == vertexArray)
1091 {
Yunchao Hed7297bf2017-04-19 15:27:10 +08001092 mVertexArray = nullptr;
Jamie Madill0b9e9032015-08-17 11:51:52 +00001093 mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING);
Jamie Madillc9d442d2016-01-20 11:17:24 -05001094 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
Shannon Woods53a94a82014-06-24 15:20:36 -04001095 return true;
1096 }
1097
1098 return false;
1099}
1100
Jamie Madill4928b7c2017-06-20 12:57:39 -04001101void State::setElementArrayBuffer(const Context *context, Buffer *buffer)
Shao80957d92017-02-20 21:25:59 +08001102{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001103 getVertexArray()->setElementArrayBuffer(context, buffer);
Shao80957d92017-02-20 21:25:59 +08001104 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
1105}
1106
Jamie Madill4928b7c2017-06-20 12:57:39 -04001107void State::bindVertexBuffer(const Context *context,
1108 GLuint bindingIndex,
Shao80957d92017-02-20 21:25:59 +08001109 Buffer *boundBuffer,
1110 GLintptr offset,
1111 GLsizei stride)
1112{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001113 getVertexArray()->bindVertexBuffer(context, bindingIndex, boundBuffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001114 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
1115}
1116
Shaodde78e82017-05-22 14:13:27 +08001117void State::setVertexAttribBinding(const Context *context, GLuint attribIndex, GLuint bindingIndex)
Shao80957d92017-02-20 21:25:59 +08001118{
Shaodde78e82017-05-22 14:13:27 +08001119 getVertexArray()->setVertexAttribBinding(context, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08001120 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
1121}
1122
1123void State::setVertexAttribFormat(GLuint attribIndex,
1124 GLint size,
1125 GLenum type,
1126 bool normalized,
1127 bool pureInteger,
1128 GLuint relativeOffset)
1129{
1130 getVertexArray()->setVertexAttribFormat(attribIndex, size, type, normalized, pureInteger,
1131 relativeOffset);
1132 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
1133}
1134
1135void State::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
1136{
1137 getVertexArray()->setVertexBindingDivisor(bindingIndex, divisor);
1138 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
1139}
1140
Jamie Madill6c1f6712017-02-14 19:08:04 -05001141void State::setProgram(const Context *context, Program *newProgram)
Shannon Woods53a94a82014-06-24 15:20:36 -04001142{
Geoff Lang7dd2e102014-11-10 15:19:26 -05001143 if (mProgram != newProgram)
Shannon Woods53a94a82014-06-24 15:20:36 -04001144 {
Geoff Lang7dd2e102014-11-10 15:19:26 -05001145 if (mProgram)
1146 {
Jamie Madill6c1f6712017-02-14 19:08:04 -05001147 mProgram->release(context);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001148 }
1149
1150 mProgram = newProgram;
1151
1152 if (mProgram)
1153 {
1154 newProgram->addRef();
Jamie Madill81c2e252017-09-09 23:32:46 -04001155 mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES);
Geoff Lang7dd2e102014-11-10 15:19:26 -05001156 }
Jamie Madilla779b612017-07-24 11:46:05 -04001157 mDirtyBits.set(DIRTY_BIT_PROGRAM_EXECUTABLE);
1158 mDirtyBits.set(DIRTY_BIT_PROGRAM_BINDING);
Shannon Woods53a94a82014-06-24 15:20:36 -04001159 }
1160}
1161
Geoff Lang7dd2e102014-11-10 15:19:26 -05001162Program *State::getProgram() const
Shannon Woods53a94a82014-06-24 15:20:36 -04001163{
Geoff Lang7dd2e102014-11-10 15:19:26 -05001164 return mProgram;
Shannon Woods53a94a82014-06-24 15:20:36 -04001165}
1166
Jamie Madill4928b7c2017-06-20 12:57:39 -04001167void State::setTransformFeedbackBinding(const Context *context,
1168 TransformFeedback *transformFeedback)
Shannon Woods53a94a82014-06-24 15:20:36 -04001169{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001170 mTransformFeedback.set(context, transformFeedback);
Shannon Woods53a94a82014-06-24 15:20:36 -04001171}
1172
1173TransformFeedback *State::getCurrentTransformFeedback() const
1174{
1175 return mTransformFeedback.get();
1176}
1177
Gregoire Payen de La Garanderie52742022015-02-04 14:55:39 +00001178bool State::isTransformFeedbackActiveUnpaused() const
1179{
Jamie Madill81c2e252017-09-09 23:32:46 -04001180 TransformFeedback *curTransformFeedback = getCurrentTransformFeedback();
Geoff Langbb0a0bb2015-03-27 12:16:57 -04001181 return curTransformFeedback && curTransformFeedback->isActive() && !curTransformFeedback->isPaused();
Gregoire Payen de La Garanderie52742022015-02-04 14:55:39 +00001182}
1183
Jamie Madill4928b7c2017-06-20 12:57:39 -04001184bool State::removeTransformFeedbackBinding(const Context *context, GLuint transformFeedback)
Shannon Woods53a94a82014-06-24 15:20:36 -04001185{
1186 if (mTransformFeedback.id() == transformFeedback)
1187 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001188 mTransformFeedback.set(context, nullptr);
Corentin Walleza2257da2016-04-19 16:43:12 -04001189 return true;
Shannon Woods53a94a82014-06-24 15:20:36 -04001190 }
Corentin Walleza2257da2016-04-19 16:43:12 -04001191
1192 return false;
Shannon Woods53a94a82014-06-24 15:20:36 -04001193}
1194
Yunchao Hea336b902017-08-02 16:05:21 +08001195void State::setProgramPipelineBinding(const Context *context, ProgramPipeline *pipeline)
1196{
1197 mProgramPipeline.set(context, pipeline);
1198}
1199
1200void State::detachProgramPipeline(const Context *context, GLuint pipeline)
1201{
1202 mProgramPipeline.set(context, nullptr);
1203}
1204
Olli Etuahobbf1c102016-06-28 13:31:33 +03001205bool State::isQueryActive(const GLenum type) const
Shannon Woods53a94a82014-06-24 15:20:36 -04001206{
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001207 for (auto &iter : mActiveQueries)
Shannon Woods53a94a82014-06-24 15:20:36 -04001208 {
Olli Etuahobbf1c102016-06-28 13:31:33 +03001209 const Query *query = iter.second.get();
1210 if (query != nullptr && ActiveQueryType(query->getType()) == ActiveQueryType(type))
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001211 {
1212 return true;
1213 }
1214 }
1215
1216 return false;
1217}
1218
1219bool State::isQueryActive(Query *query) const
1220{
1221 for (auto &iter : mActiveQueries)
1222 {
1223 if (iter.second.get() == query)
Shannon Woods53a94a82014-06-24 15:20:36 -04001224 {
1225 return true;
1226 }
1227 }
1228
1229 return false;
1230}
1231
Jamie Madill4928b7c2017-06-20 12:57:39 -04001232void State::setActiveQuery(const Context *context, GLenum target, Query *query)
Shannon Woods53a94a82014-06-24 15:20:36 -04001233{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001234 mActiveQueries[target].set(context, query);
Shannon Woods53a94a82014-06-24 15:20:36 -04001235}
1236
1237GLuint State::getActiveQueryId(GLenum target) const
1238{
1239 const Query *query = getActiveQuery(target);
1240 return (query ? query->id() : 0u);
1241}
1242
1243Query *State::getActiveQuery(GLenum target) const
1244{
Jamie Madill5864ac22015-01-12 14:43:07 -05001245 const auto it = mActiveQueries.find(target);
Shannon Woods53a94a82014-06-24 15:20:36 -04001246
Jamie Madill5864ac22015-01-12 14:43:07 -05001247 // All query types should already exist in the activeQueries map
1248 ASSERT(it != mActiveQueries.end());
1249
1250 return it->second.get();
Shannon Woods53a94a82014-06-24 15:20:36 -04001251}
1252
Jamie Madill4928b7c2017-06-20 12:57:39 -04001253void State::setArrayBufferBinding(const Context *context, Buffer *buffer)
Shannon Woods53a94a82014-06-24 15:20:36 -04001254{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001255 mArrayBuffer.set(context, buffer);
Shannon Woods53a94a82014-06-24 15:20:36 -04001256}
1257
1258GLuint State::getArrayBufferId() const
1259{
1260 return mArrayBuffer.id();
1261}
1262
Jamie Madill4928b7c2017-06-20 12:57:39 -04001263void State::setDrawIndirectBufferBinding(const Context *context, Buffer *buffer)
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08001264{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001265 mDrawIndirectBuffer.set(context, buffer);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08001266 mDirtyBits.set(DIRTY_BIT_DRAW_INDIRECT_BUFFER_BINDING);
1267}
1268
Jamie Madill4928b7c2017-06-20 12:57:39 -04001269void State::setGenericUniformBufferBinding(const Context *context, Buffer *buffer)
Shannon Woods53a94a82014-06-24 15:20:36 -04001270{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001271 mGenericUniformBuffer.set(context, buffer);
Shannon Woods53a94a82014-06-24 15:20:36 -04001272}
1273
Jamie Madill4928b7c2017-06-20 12:57:39 -04001274void State::setIndexedUniformBufferBinding(const Context *context,
1275 GLuint index,
1276 Buffer *buffer,
1277 GLintptr offset,
1278 GLsizeiptr size)
Shannon Woods53a94a82014-06-24 15:20:36 -04001279{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001280 mUniformBuffers[index].set(context, buffer, offset, size);
Shannon Woods53a94a82014-06-24 15:20:36 -04001281}
1282
Geoff Lang5d124a62015-09-15 13:03:27 -04001283const OffsetBindingPointer<Buffer> &State::getIndexedUniformBuffer(size_t index) const
Shannon Woods53a94a82014-06-24 15:20:36 -04001284{
Shannon Woodsf3acaf92014-09-23 18:07:11 -04001285 ASSERT(static_cast<size_t>(index) < mUniformBuffers.size());
Geoff Lang5d124a62015-09-15 13:03:27 -04001286 return mUniformBuffers[index];
Gregoire Payen de La Garanderie68694e92015-03-24 14:03:37 +00001287}
1288
Jamie Madill4928b7c2017-06-20 12:57:39 -04001289void State::setGenericAtomicCounterBufferBinding(const Context *context, Buffer *buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08001290{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001291 mGenericAtomicCounterBuffer.set(context, buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001292}
1293
Jamie Madill4928b7c2017-06-20 12:57:39 -04001294void State::setIndexedAtomicCounterBufferBinding(const Context *context,
1295 GLuint index,
Jiajia Qin6eafb042016-12-27 17:04:07 +08001296 Buffer *buffer,
1297 GLintptr offset,
1298 GLsizeiptr size)
1299{
1300 ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size());
Jamie Madill4928b7c2017-06-20 12:57:39 -04001301 mAtomicCounterBuffers[index].set(context, buffer, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001302}
1303
1304const OffsetBindingPointer<Buffer> &State::getIndexedAtomicCounterBuffer(size_t index) const
1305{
1306 ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size());
1307 return mAtomicCounterBuffers[index];
1308}
1309
Jamie Madill4928b7c2017-06-20 12:57:39 -04001310void State::setGenericShaderStorageBufferBinding(const Context *context, Buffer *buffer)
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001311{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001312 mGenericShaderStorageBuffer.set(context, buffer);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001313}
1314
Jamie Madill4928b7c2017-06-20 12:57:39 -04001315void State::setIndexedShaderStorageBufferBinding(const Context *context,
1316 GLuint index,
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001317 Buffer *buffer,
1318 GLintptr offset,
1319 GLsizeiptr size)
1320{
1321 ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size());
Jamie Madill4928b7c2017-06-20 12:57:39 -04001322 mShaderStorageBuffers[index].set(context, buffer, offset, size);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001323}
1324
1325const OffsetBindingPointer<Buffer> &State::getIndexedShaderStorageBuffer(size_t index) const
1326{
1327 ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size());
1328 return mShaderStorageBuffers[index];
1329}
1330
Jamie Madill4928b7c2017-06-20 12:57:39 -04001331void State::setCopyReadBufferBinding(const Context *context, Buffer *buffer)
Shannon Woods53a94a82014-06-24 15:20:36 -04001332{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001333 mCopyReadBuffer.set(context, buffer);
Shannon Woods53a94a82014-06-24 15:20:36 -04001334}
1335
Jamie Madill4928b7c2017-06-20 12:57:39 -04001336void State::setCopyWriteBufferBinding(const Context *context, Buffer *buffer)
Shannon Woods53a94a82014-06-24 15:20:36 -04001337{
Jamie Madill4928b7c2017-06-20 12:57:39 -04001338 mCopyWriteBuffer.set(context, buffer);
Shannon Woods53a94a82014-06-24 15:20:36 -04001339}
1340
Jamie Madill4928b7c2017-06-20 12:57:39 -04001341void State::setPixelPackBufferBinding(const Context *context, Buffer *buffer)
Shannon Woods53a94a82014-06-24 15:20:36 -04001342{
Corentin Wallezcda6af12017-10-30 19:20:37 -04001343 mPixelPackBuffer.set(context, buffer);
Corentin Wallez29a20992017-11-06 18:23:16 -05001344 mDirtyBits.set(DIRTY_BIT_PACK_BUFFER_BINDING);
Shannon Woods53a94a82014-06-24 15:20:36 -04001345}
1346
Jamie Madill4928b7c2017-06-20 12:57:39 -04001347void State::setPixelUnpackBufferBinding(const Context *context, Buffer *buffer)
Shannon Woods53a94a82014-06-24 15:20:36 -04001348{
Corentin Wallezcda6af12017-10-30 19:20:37 -04001349 mPixelUnpackBuffer.set(context, buffer);
Corentin Wallez29a20992017-11-06 18:23:16 -05001350 mDirtyBits.set(DIRTY_BIT_UNPACK_BUFFER_BINDING);
Shannon Woods53a94a82014-06-24 15:20:36 -04001351}
1352
1353Buffer *State::getTargetBuffer(GLenum target) const
1354{
1355 switch (target)
1356 {
1357 case GL_ARRAY_BUFFER: return mArrayBuffer.get();
1358 case GL_COPY_READ_BUFFER: return mCopyReadBuffer.get();
1359 case GL_COPY_WRITE_BUFFER: return mCopyWriteBuffer.get();
Jamie Madill8e344942015-07-09 14:22:07 -04001360 case GL_ELEMENT_ARRAY_BUFFER: return getVertexArray()->getElementArrayBuffer().get();
Corentin Wallezcda6af12017-10-30 19:20:37 -04001361 case GL_PIXEL_PACK_BUFFER:
1362 return mPixelPackBuffer.get();
1363 case GL_PIXEL_UNPACK_BUFFER:
1364 return mPixelUnpackBuffer.get();
Geoff Lang045536b2015-03-27 15:17:18 -04001365 case GL_TRANSFORM_FEEDBACK_BUFFER: return mTransformFeedback->getGenericBuffer().get();
Shannon Woods53a94a82014-06-24 15:20:36 -04001366 case GL_UNIFORM_BUFFER: return mGenericUniformBuffer.get();
Geoff Langb5e997f2016-12-06 10:55:34 -05001367 case GL_ATOMIC_COUNTER_BUFFER:
Jiajia Qin6eafb042016-12-27 17:04:07 +08001368 return mGenericAtomicCounterBuffer.get();
Geoff Langb5e997f2016-12-06 10:55:34 -05001369 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001370 return mGenericShaderStorageBuffer.get();
Geoff Langb5e997f2016-12-06 10:55:34 -05001371 case GL_DRAW_INDIRECT_BUFFER:
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08001372 return mDrawIndirectBuffer.get();
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001373 default:
1374 UNREACHABLE();
1375 return nullptr;
Shannon Woods53a94a82014-06-24 15:20:36 -04001376 }
1377}
1378
Jamie Madill4928b7c2017-06-20 12:57:39 -04001379void State::detachBuffer(const Context *context, GLuint bufferName)
Yuly Novikov5807a532015-12-03 13:01:22 -05001380{
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001381 BindingPointer<Buffer> *buffers[] = {
Corentin Wallezcda6af12017-10-30 19:20:37 -04001382 &mArrayBuffer, &mGenericAtomicCounterBuffer, &mCopyReadBuffer,
1383 &mCopyWriteBuffer, &mDrawIndirectBuffer, &mPixelPackBuffer,
1384 &mPixelUnpackBuffer, &mGenericUniformBuffer, &mGenericShaderStorageBuffer};
Yuly Novikov5807a532015-12-03 13:01:22 -05001385 for (auto buffer : buffers)
1386 {
1387 if (buffer->id() == bufferName)
1388 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001389 buffer->set(context, nullptr);
Yuly Novikov5807a532015-12-03 13:01:22 -05001390 }
1391 }
1392
1393 TransformFeedback *curTransformFeedback = getCurrentTransformFeedback();
1394 if (curTransformFeedback)
1395 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001396 curTransformFeedback->detachBuffer(context, bufferName);
Yuly Novikov5807a532015-12-03 13:01:22 -05001397 }
1398
Jamie Madill4928b7c2017-06-20 12:57:39 -04001399 getVertexArray()->detachBuffer(context, bufferName);
Yuly Novikov5807a532015-12-03 13:01:22 -05001400}
1401
Shannon Woods53a94a82014-06-24 15:20:36 -04001402void State::setEnableVertexAttribArray(unsigned int attribNum, bool enabled)
1403{
1404 getVertexArray()->enableAttribute(attribNum, enabled);
Jamie Madillc9d442d2016-01-20 11:17:24 -05001405 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
Shannon Woods53a94a82014-06-24 15:20:36 -04001406}
1407
1408void State::setVertexAttribf(GLuint index, const GLfloat values[4])
1409{
Shannon Woods23e05002014-09-22 19:07:27 -04001410 ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size());
Shannon Woods53a94a82014-06-24 15:20:36 -04001411 mVertexAttribCurrentValues[index].setFloatValues(values);
Jamie Madillc67323a2017-11-02 23:11:41 -04001412 mDirtyBits.set(DIRTY_BIT_CURRENT_VALUES);
1413 mDirtyCurrentValues.set(index);
Shannon Woods53a94a82014-06-24 15:20:36 -04001414}
1415
1416void State::setVertexAttribu(GLuint index, const GLuint values[4])
1417{
Shannon Woods23e05002014-09-22 19:07:27 -04001418 ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size());
Shannon Woods53a94a82014-06-24 15:20:36 -04001419 mVertexAttribCurrentValues[index].setUnsignedIntValues(values);
Jamie Madillc67323a2017-11-02 23:11:41 -04001420 mDirtyBits.set(DIRTY_BIT_CURRENT_VALUES);
1421 mDirtyCurrentValues.set(index);
Shannon Woods53a94a82014-06-24 15:20:36 -04001422}
1423
1424void State::setVertexAttribi(GLuint index, const GLint values[4])
1425{
Shannon Woods23e05002014-09-22 19:07:27 -04001426 ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size());
Shannon Woods53a94a82014-06-24 15:20:36 -04001427 mVertexAttribCurrentValues[index].setIntValues(values);
Jamie Madillc67323a2017-11-02 23:11:41 -04001428 mDirtyBits.set(DIRTY_BIT_CURRENT_VALUES);
1429 mDirtyCurrentValues.set(index);
Shannon Woods53a94a82014-06-24 15:20:36 -04001430}
1431
Shaodde78e82017-05-22 14:13:27 +08001432void State::setVertexAttribPointer(const Context *context,
1433 unsigned int attribNum,
1434 Buffer *boundBuffer,
1435 GLint size,
1436 GLenum type,
1437 bool normalized,
1438 bool pureInteger,
1439 GLsizei stride,
1440 const void *pointer)
Shannon Woods53a94a82014-06-24 15:20:36 -04001441{
Shaodde78e82017-05-22 14:13:27 +08001442 getVertexArray()->setVertexAttribPointer(context, attribNum, boundBuffer, size, type,
1443 normalized, pureInteger, stride, pointer);
Jamie Madillc9d442d2016-01-20 11:17:24 -05001444 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
Jamie Madill0b9e9032015-08-17 11:51:52 +00001445}
1446
Shaodde78e82017-05-22 14:13:27 +08001447void State::setVertexAttribDivisor(const Context *context, GLuint index, GLuint divisor)
Jamie Madill0b9e9032015-08-17 11:51:52 +00001448{
Shaodde78e82017-05-22 14:13:27 +08001449 getVertexArray()->setVertexAttribDivisor(context, index, divisor);
Jamie Madillc9d442d2016-01-20 11:17:24 -05001450 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
Shannon Woods53a94a82014-06-24 15:20:36 -04001451}
1452
Jamie Madill6de51852017-04-12 09:53:01 -04001453const VertexAttribCurrentValueData &State::getVertexAttribCurrentValue(size_t attribNum) const
Shannon Woods53a94a82014-06-24 15:20:36 -04001454{
Jamie Madill6de51852017-04-12 09:53:01 -04001455 ASSERT(attribNum < mVertexAttribCurrentValues.size());
Shannon Woods53a94a82014-06-24 15:20:36 -04001456 return mVertexAttribCurrentValues[attribNum];
1457}
1458
Shannon Woods53a94a82014-06-24 15:20:36 -04001459const void *State::getVertexAttribPointer(unsigned int attribNum) const
1460{
1461 return getVertexArray()->getVertexAttribute(attribNum).pointer;
1462}
1463
1464void State::setPackAlignment(GLint alignment)
1465{
1466 mPack.alignment = alignment;
Jamie Madillc67323a2017-11-02 23:11:41 -04001467 mDirtyBits.set(DIRTY_BIT_PACK_STATE);
Shannon Woods53a94a82014-06-24 15:20:36 -04001468}
1469
1470GLint State::getPackAlignment() const
1471{
1472 return mPack.alignment;
1473}
1474
1475void State::setPackReverseRowOrder(bool reverseRowOrder)
1476{
1477 mPack.reverseRowOrder = reverseRowOrder;
Jamie Madillc67323a2017-11-02 23:11:41 -04001478 mDirtyBits.set(DIRTY_BIT_PACK_STATE);
Shannon Woods53a94a82014-06-24 15:20:36 -04001479}
1480
1481bool State::getPackReverseRowOrder() const
1482{
1483 return mPack.reverseRowOrder;
1484}
1485
Minmin Gongadff67b2015-10-14 10:34:45 -04001486void State::setPackRowLength(GLint rowLength)
1487{
1488 mPack.rowLength = rowLength;
Jamie Madillc67323a2017-11-02 23:11:41 -04001489 mDirtyBits.set(DIRTY_BIT_PACK_STATE);
Minmin Gongadff67b2015-10-14 10:34:45 -04001490}
1491
1492GLint State::getPackRowLength() const
1493{
1494 return mPack.rowLength;
1495}
1496
1497void State::setPackSkipRows(GLint skipRows)
1498{
1499 mPack.skipRows = skipRows;
Jamie Madillc67323a2017-11-02 23:11:41 -04001500 mDirtyBits.set(DIRTY_BIT_PACK_STATE);
Minmin Gongadff67b2015-10-14 10:34:45 -04001501}
1502
1503GLint State::getPackSkipRows() const
1504{
1505 return mPack.skipRows;
1506}
1507
1508void State::setPackSkipPixels(GLint skipPixels)
1509{
1510 mPack.skipPixels = skipPixels;
Jamie Madillc67323a2017-11-02 23:11:41 -04001511 mDirtyBits.set(DIRTY_BIT_PACK_STATE);
Minmin Gongadff67b2015-10-14 10:34:45 -04001512}
1513
1514GLint State::getPackSkipPixels() const
1515{
1516 return mPack.skipPixels;
1517}
1518
Shannon Woods53a94a82014-06-24 15:20:36 -04001519const PixelPackState &State::getPackState() const
1520{
1521 return mPack;
1522}
1523
Jamie Madill87de3622015-03-16 10:41:44 -04001524PixelPackState &State::getPackState()
1525{
1526 return mPack;
1527}
1528
Shannon Woods53a94a82014-06-24 15:20:36 -04001529void State::setUnpackAlignment(GLint alignment)
1530{
1531 mUnpack.alignment = alignment;
Jamie Madillc67323a2017-11-02 23:11:41 -04001532 mDirtyBits.set(DIRTY_BIT_UNPACK_STATE);
Shannon Woods53a94a82014-06-24 15:20:36 -04001533}
1534
1535GLint State::getUnpackAlignment() const
1536{
1537 return mUnpack.alignment;
1538}
1539
Minmin Gongb8aee3b2015-01-27 14:42:36 -08001540void State::setUnpackRowLength(GLint rowLength)
1541{
1542 mUnpack.rowLength = rowLength;
Jamie Madillc67323a2017-11-02 23:11:41 -04001543 mDirtyBits.set(DIRTY_BIT_UNPACK_STATE);
Minmin Gongb8aee3b2015-01-27 14:42:36 -08001544}
1545
1546GLint State::getUnpackRowLength() const
1547{
1548 return mUnpack.rowLength;
1549}
1550
Minmin Gongadff67b2015-10-14 10:34:45 -04001551void State::setUnpackImageHeight(GLint imageHeight)
1552{
1553 mUnpack.imageHeight = imageHeight;
Jamie Madillc67323a2017-11-02 23:11:41 -04001554 mDirtyBits.set(DIRTY_BIT_UNPACK_STATE);
Minmin Gongadff67b2015-10-14 10:34:45 -04001555}
1556
1557GLint State::getUnpackImageHeight() const
1558{
1559 return mUnpack.imageHeight;
1560}
1561
1562void State::setUnpackSkipImages(GLint skipImages)
1563{
1564 mUnpack.skipImages = skipImages;
Jamie Madillc67323a2017-11-02 23:11:41 -04001565 mDirtyBits.set(DIRTY_BIT_UNPACK_STATE);
Minmin Gongadff67b2015-10-14 10:34:45 -04001566}
1567
1568GLint State::getUnpackSkipImages() const
1569{
1570 return mUnpack.skipImages;
1571}
1572
1573void State::setUnpackSkipRows(GLint skipRows)
1574{
1575 mUnpack.skipRows = skipRows;
Jamie Madillc67323a2017-11-02 23:11:41 -04001576 mDirtyBits.set(DIRTY_BIT_UNPACK_STATE);
Minmin Gongadff67b2015-10-14 10:34:45 -04001577}
1578
1579GLint State::getUnpackSkipRows() const
1580{
1581 return mUnpack.skipRows;
1582}
1583
1584void State::setUnpackSkipPixels(GLint skipPixels)
1585{
1586 mUnpack.skipPixels = skipPixels;
Jamie Madillc67323a2017-11-02 23:11:41 -04001587 mDirtyBits.set(DIRTY_BIT_UNPACK_STATE);
Minmin Gongadff67b2015-10-14 10:34:45 -04001588}
1589
1590GLint State::getUnpackSkipPixels() const
1591{
1592 return mUnpack.skipPixels;
1593}
1594
Shannon Woods53a94a82014-06-24 15:20:36 -04001595const PixelUnpackState &State::getUnpackState() const
1596{
1597 return mUnpack;
1598}
1599
Jamie Madill67102f02015-03-16 10:41:42 -04001600PixelUnpackState &State::getUnpackState()
1601{
1602 return mUnpack;
1603}
1604
Geoff Lang70d0f492015-12-10 17:45:46 -05001605const Debug &State::getDebug() const
1606{
1607 return mDebug;
1608}
1609
1610Debug &State::getDebug()
1611{
1612 return mDebug;
1613}
1614
Sami Väisänena797e062016-05-12 15:23:40 +03001615void State::setCoverageModulation(GLenum components)
1616{
1617 mCoverageModulation = components;
1618 mDirtyBits.set(DIRTY_BIT_COVERAGE_MODULATION);
1619}
1620
1621GLenum State::getCoverageModulation() const
1622{
1623 return mCoverageModulation;
1624}
1625
Sami Väisänene45e53b2016-05-25 10:36:04 +03001626void State::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1627{
1628 if (matrixMode == GL_PATH_MODELVIEW_CHROMIUM)
1629 {
1630 memcpy(mPathMatrixMV, matrix, 16 * sizeof(GLfloat));
1631 mDirtyBits.set(DIRTY_BIT_PATH_RENDERING_MATRIX_MV);
1632 }
1633 else if (matrixMode == GL_PATH_PROJECTION_CHROMIUM)
1634 {
1635 memcpy(mPathMatrixProj, matrix, 16 * sizeof(GLfloat));
1636 mDirtyBits.set(DIRTY_BIT_PATH_RENDERING_MATRIX_PROJ);
1637 }
1638 else
1639 {
1640 UNREACHABLE();
1641 }
1642}
1643
1644const GLfloat *State::getPathRenderingMatrix(GLenum which) const
1645{
1646 if (which == GL_PATH_MODELVIEW_MATRIX_CHROMIUM)
1647 {
1648 return mPathMatrixMV;
1649 }
1650 else if (which == GL_PATH_PROJECTION_MATRIX_CHROMIUM)
1651 {
1652 return mPathMatrixProj;
1653 }
1654
1655 UNREACHABLE();
1656 return nullptr;
1657}
1658
1659void State::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
1660{
1661 mPathStencilFunc = func;
1662 mPathStencilRef = ref;
1663 mPathStencilMask = mask;
1664 mDirtyBits.set(DIRTY_BIT_PATH_RENDERING_STENCIL_STATE);
1665}
1666
1667GLenum State::getPathStencilFunc() const
1668{
1669 return mPathStencilFunc;
1670}
1671
1672GLint State::getPathStencilRef() const
1673{
1674 return mPathStencilRef;
1675}
1676
1677GLuint State::getPathStencilMask() const
1678{
1679 return mPathStencilMask;
1680}
1681
Geoff Lang1d2c41d2016-10-19 16:14:46 -07001682void State::setFramebufferSRGB(bool sRGB)
1683{
1684 mFramebufferSRGB = sRGB;
1685 mDirtyBits.set(DIRTY_BIT_FRAMEBUFFER_SRGB);
1686}
1687
1688bool State::getFramebufferSRGB() const
1689{
1690 return mFramebufferSRGB;
1691}
1692
Shannon Woods53a94a82014-06-24 15:20:36 -04001693void State::getBooleanv(GLenum pname, GLboolean *params)
1694{
1695 switch (pname)
1696 {
1697 case GL_SAMPLE_COVERAGE_INVERT: *params = mSampleCoverageInvert; break;
1698 case GL_DEPTH_WRITEMASK: *params = mDepthStencil.depthMask; break;
1699 case GL_COLOR_WRITEMASK:
1700 params[0] = mBlend.colorMaskRed;
1701 params[1] = mBlend.colorMaskGreen;
1702 params[2] = mBlend.colorMaskBlue;
1703 params[3] = mBlend.colorMaskAlpha;
1704 break;
Corentin Wallez2e568cf2017-09-18 17:05:22 -04001705 case GL_CULL_FACE:
1706 *params = mRasterizer.cullFace;
1707 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001708 case GL_POLYGON_OFFSET_FILL: *params = mRasterizer.polygonOffsetFill; break;
1709 case GL_SAMPLE_ALPHA_TO_COVERAGE: *params = mBlend.sampleAlphaToCoverage; break;
1710 case GL_SAMPLE_COVERAGE: *params = mSampleCoverage; break;
Jiawei Shaodb342272017-09-27 10:21:45 +08001711 case GL_SAMPLE_MASK:
1712 *params = mSampleMask;
1713 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001714 case GL_SCISSOR_TEST: *params = mScissorTest; break;
1715 case GL_STENCIL_TEST: *params = mDepthStencil.stencilTest; break;
1716 case GL_DEPTH_TEST: *params = mDepthStencil.depthTest; break;
1717 case GL_BLEND: *params = mBlend.blend; break;
1718 case GL_DITHER: *params = mBlend.dither; break;
Geoff Langbb0a0bb2015-03-27 12:16:57 -04001719 case GL_TRANSFORM_FEEDBACK_ACTIVE: *params = getCurrentTransformFeedback()->isActive() ? GL_TRUE : GL_FALSE; break;
1720 case GL_TRANSFORM_FEEDBACK_PAUSED: *params = getCurrentTransformFeedback()->isPaused() ? GL_TRUE : GL_FALSE; break;
Jamie Madille2cd53d2015-10-27 11:15:46 -04001721 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1722 *params = mPrimitiveRestart;
1723 break;
Geoff Langab831f02015-12-01 09:39:10 -05001724 case GL_RASTERIZER_DISCARD:
1725 *params = isRasterizerDiscardEnabled() ? GL_TRUE : GL_FALSE;
1726 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001727 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
1728 *params = mDebug.isOutputSynchronous() ? GL_TRUE : GL_FALSE;
1729 break;
1730 case GL_DEBUG_OUTPUT:
1731 *params = mDebug.isOutputEnabled() ? GL_TRUE : GL_FALSE;
1732 break;
Sami Väisänen74c23472016-05-09 17:30:30 +03001733 case GL_MULTISAMPLE_EXT:
1734 *params = mMultiSampling;
1735 break;
1736 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
1737 *params = mSampleAlphaToOne;
1738 break;
Geoff Langf41a7152016-09-19 15:11:17 -04001739 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
1740 *params = isBindGeneratesResourceEnabled() ? GL_TRUE : GL_FALSE;
1741 break;
Geoff Langfeb8c682017-02-13 16:07:35 -05001742 case GL_CLIENT_ARRAYS_ANGLE:
1743 *params = areClientArraysEnabled() ? GL_TRUE : GL_FALSE;
1744 break;
Geoff Lang1d2c41d2016-10-19 16:14:46 -07001745 case GL_FRAMEBUFFER_SRGB_EXT:
1746 *params = getFramebufferSRGB() ? GL_TRUE : GL_FALSE;
1747 break;
Geoff Langb433e872017-10-05 14:01:47 -04001748 case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE:
Jamie Madille08a1d32017-03-07 17:24:06 -05001749 *params = mRobustResourceInit ? GL_TRUE : GL_FALSE;
1750 break;
Jamie Madillc43be722017-07-13 16:22:14 -04001751 case GL_PROGRAM_CACHE_ENABLED_ANGLE:
1752 *params = mProgramBinaryCacheEnabled ? GL_TRUE : GL_FALSE;
1753 break;
1754
Shannon Woods53a94a82014-06-24 15:20:36 -04001755 default:
1756 UNREACHABLE();
1757 break;
1758 }
1759}
1760
1761void State::getFloatv(GLenum pname, GLfloat *params)
1762{
1763 // Please note: DEPTH_CLEAR_VALUE is included in our internal getFloatv implementation
1764 // because it is stored as a float, despite the fact that the GL ES 2.0 spec names
1765 // GetIntegerv as its native query function. As it would require conversion in any
1766 // case, this should make no difference to the calling application.
1767 switch (pname)
1768 {
1769 case GL_LINE_WIDTH: *params = mLineWidth; break;
1770 case GL_SAMPLE_COVERAGE_VALUE: *params = mSampleCoverageValue; break;
1771 case GL_DEPTH_CLEAR_VALUE: *params = mDepthClearValue; break;
1772 case GL_POLYGON_OFFSET_FACTOR: *params = mRasterizer.polygonOffsetFactor; break;
1773 case GL_POLYGON_OFFSET_UNITS: *params = mRasterizer.polygonOffsetUnits; break;
1774 case GL_DEPTH_RANGE:
1775 params[0] = mNearZ;
1776 params[1] = mFarZ;
1777 break;
1778 case GL_COLOR_CLEAR_VALUE:
1779 params[0] = mColorClearValue.red;
1780 params[1] = mColorClearValue.green;
1781 params[2] = mColorClearValue.blue;
1782 params[3] = mColorClearValue.alpha;
1783 break;
1784 case GL_BLEND_COLOR:
1785 params[0] = mBlendColor.red;
1786 params[1] = mBlendColor.green;
1787 params[2] = mBlendColor.blue;
1788 params[3] = mBlendColor.alpha;
1789 break;
Sami Väisänen74c23472016-05-09 17:30:30 +03001790 case GL_MULTISAMPLE_EXT:
1791 *params = static_cast<GLfloat>(mMultiSampling);
1792 break;
1793 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
1794 *params = static_cast<GLfloat>(mSampleAlphaToOne);
Sami Väisänena797e062016-05-12 15:23:40 +03001795 case GL_COVERAGE_MODULATION_CHROMIUM:
Jamie Madille2e406c2016-06-02 13:04:10 -04001796 params[0] = static_cast<GLfloat>(mCoverageModulation);
1797 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001798 default:
1799 UNREACHABLE();
1800 break;
1801 }
1802}
1803
Jamie Madilldd43e6c2017-03-24 14:18:49 -04001804void State::getIntegerv(const Context *context, GLenum pname, GLint *params)
Shannon Woods53a94a82014-06-24 15:20:36 -04001805{
1806 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
1807 {
1808 unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0_EXT);
Shannon Woods2df6a602014-09-26 16:12:07 -04001809 ASSERT(colorAttachment < mMaxDrawBuffers);
Shannon Woods53a94a82014-06-24 15:20:36 -04001810 Framebuffer *framebuffer = mDrawFramebuffer;
1811 *params = framebuffer->getDrawBufferState(colorAttachment);
1812 return;
1813 }
1814
1815 // Please note: DEPTH_CLEAR_VALUE is not included in our internal getIntegerv implementation
1816 // because it is stored as a float, despite the fact that the GL ES 2.0 spec names
1817 // GetIntegerv as its native query function. As it would require conversion in any
1818 // case, this should make no difference to the calling application. You may find it in
1819 // State::getFloatv.
1820 switch (pname)
1821 {
1822 case GL_ARRAY_BUFFER_BINDING: *params = mArrayBuffer.id(); break;
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08001823 case GL_DRAW_INDIRECT_BUFFER_BINDING:
1824 *params = mDrawIndirectBuffer.id();
1825 break;
Jamie Madill8e344942015-07-09 14:22:07 -04001826 case GL_ELEMENT_ARRAY_BUFFER_BINDING: *params = getVertexArray()->getElementArrayBuffer().id(); break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001827 //case GL_FRAMEBUFFER_BINDING: // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1828 case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE: *params = mDrawFramebuffer->id(); break;
1829 case GL_READ_FRAMEBUFFER_BINDING_ANGLE: *params = mReadFramebuffer->id(); break;
1830 case GL_RENDERBUFFER_BINDING: *params = mRenderbuffer.id(); break;
1831 case GL_VERTEX_ARRAY_BINDING: *params = mVertexArray->id(); break;
Geoff Lang7dd2e102014-11-10 15:19:26 -05001832 case GL_CURRENT_PROGRAM: *params = mProgram ? mProgram->id() : 0; break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001833 case GL_PACK_ALIGNMENT: *params = mPack.alignment; break;
1834 case GL_PACK_REVERSE_ROW_ORDER_ANGLE: *params = mPack.reverseRowOrder; break;
Minmin Gongadff67b2015-10-14 10:34:45 -04001835 case GL_PACK_ROW_LENGTH:
1836 *params = mPack.rowLength;
1837 break;
1838 case GL_PACK_SKIP_ROWS:
1839 *params = mPack.skipRows;
1840 break;
1841 case GL_PACK_SKIP_PIXELS:
1842 *params = mPack.skipPixels;
1843 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001844 case GL_UNPACK_ALIGNMENT: *params = mUnpack.alignment; break;
Minmin Gongb8aee3b2015-01-27 14:42:36 -08001845 case GL_UNPACK_ROW_LENGTH: *params = mUnpack.rowLength; break;
Minmin Gongadff67b2015-10-14 10:34:45 -04001846 case GL_UNPACK_IMAGE_HEIGHT:
1847 *params = mUnpack.imageHeight;
1848 break;
1849 case GL_UNPACK_SKIP_IMAGES:
1850 *params = mUnpack.skipImages;
1851 break;
1852 case GL_UNPACK_SKIP_ROWS:
1853 *params = mUnpack.skipRows;
1854 break;
1855 case GL_UNPACK_SKIP_PIXELS:
1856 *params = mUnpack.skipPixels;
1857 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001858 case GL_GENERATE_MIPMAP_HINT: *params = mGenerateMipmapHint; break;
1859 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: *params = mFragmentShaderDerivativeHint; break;
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001860 case GL_ACTIVE_TEXTURE:
1861 *params = (static_cast<GLint>(mActiveSampler) + GL_TEXTURE0);
1862 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001863 case GL_STENCIL_FUNC: *params = mDepthStencil.stencilFunc; break;
1864 case GL_STENCIL_REF: *params = mStencilRef; break;
jchen10a99ed552017-09-22 08:10:32 +08001865 case GL_STENCIL_VALUE_MASK:
1866 *params = CastMaskValue(context, mDepthStencil.stencilMask);
1867 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001868 case GL_STENCIL_BACK_FUNC: *params = mDepthStencil.stencilBackFunc; break;
1869 case GL_STENCIL_BACK_REF: *params = mStencilBackRef; break;
jchen10a99ed552017-09-22 08:10:32 +08001870 case GL_STENCIL_BACK_VALUE_MASK:
1871 *params = CastMaskValue(context, mDepthStencil.stencilBackMask);
1872 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001873 case GL_STENCIL_FAIL: *params = mDepthStencil.stencilFail; break;
1874 case GL_STENCIL_PASS_DEPTH_FAIL: *params = mDepthStencil.stencilPassDepthFail; break;
1875 case GL_STENCIL_PASS_DEPTH_PASS: *params = mDepthStencil.stencilPassDepthPass; break;
1876 case GL_STENCIL_BACK_FAIL: *params = mDepthStencil.stencilBackFail; break;
1877 case GL_STENCIL_BACK_PASS_DEPTH_FAIL: *params = mDepthStencil.stencilBackPassDepthFail; break;
1878 case GL_STENCIL_BACK_PASS_DEPTH_PASS: *params = mDepthStencil.stencilBackPassDepthPass; break;
1879 case GL_DEPTH_FUNC: *params = mDepthStencil.depthFunc; break;
1880 case GL_BLEND_SRC_RGB: *params = mBlend.sourceBlendRGB; break;
1881 case GL_BLEND_SRC_ALPHA: *params = mBlend.sourceBlendAlpha; break;
1882 case GL_BLEND_DST_RGB: *params = mBlend.destBlendRGB; break;
1883 case GL_BLEND_DST_ALPHA: *params = mBlend.destBlendAlpha; break;
1884 case GL_BLEND_EQUATION_RGB: *params = mBlend.blendEquationRGB; break;
1885 case GL_BLEND_EQUATION_ALPHA: *params = mBlend.blendEquationAlpha; break;
jchen10a99ed552017-09-22 08:10:32 +08001886 case GL_STENCIL_WRITEMASK:
1887 *params = CastMaskValue(context, mDepthStencil.stencilWritemask);
1888 break;
1889 case GL_STENCIL_BACK_WRITEMASK:
1890 *params = CastMaskValue(context, mDepthStencil.stencilBackWritemask);
1891 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001892 case GL_STENCIL_CLEAR_VALUE: *params = mStencilClearValue; break;
Jamie Madill4928b7c2017-06-20 12:57:39 -04001893 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
1894 *params = mReadFramebuffer->getImplementationColorReadType(context);
1895 break;
1896 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
1897 *params = mReadFramebuffer->getImplementationColorReadFormat(context);
1898 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001899 case GL_SAMPLE_BUFFERS:
1900 case GL_SAMPLES:
1901 {
Jamie Madill81c2e252017-09-09 23:32:46 -04001902 Framebuffer *framebuffer = mDrawFramebuffer;
Jamie Madilldd43e6c2017-03-24 14:18:49 -04001903 if (framebuffer->checkStatus(context) == GL_FRAMEBUFFER_COMPLETE)
Shannon Woods53a94a82014-06-24 15:20:36 -04001904 {
1905 switch (pname)
1906 {
Jamie Madilla0016b72017-07-14 14:30:46 -04001907 case GL_SAMPLE_BUFFERS:
1908 if (framebuffer->getSamples(context) != 0)
1909 {
1910 *params = 1;
1911 }
1912 else
1913 {
1914 *params = 0;
1915 }
1916 break;
1917 case GL_SAMPLES:
1918 *params = framebuffer->getSamples(context);
1919 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001920 }
1921 }
1922 else
1923 {
1924 *params = 0;
1925 }
1926 }
1927 break;
1928 case GL_VIEWPORT:
1929 params[0] = mViewport.x;
1930 params[1] = mViewport.y;
1931 params[2] = mViewport.width;
1932 params[3] = mViewport.height;
1933 break;
1934 case GL_SCISSOR_BOX:
1935 params[0] = mScissor.x;
1936 params[1] = mScissor.y;
1937 params[2] = mScissor.width;
1938 params[3] = mScissor.height;
1939 break;
Corentin Wallez2e568cf2017-09-18 17:05:22 -04001940 case GL_CULL_FACE_MODE:
1941 *params = ToGLenum(mRasterizer.cullMode);
1942 break;
1943 case GL_FRONT_FACE:
1944 *params = mRasterizer.frontFace;
1945 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04001946 case GL_RED_BITS:
1947 case GL_GREEN_BITS:
1948 case GL_BLUE_BITS:
1949 case GL_ALPHA_BITS:
1950 {
Jamie Madill81c2e252017-09-09 23:32:46 -04001951 Framebuffer *framebuffer = getDrawFramebuffer();
1952 const FramebufferAttachment *colorbuffer = framebuffer->getFirstColorbuffer();
Shannon Woods53a94a82014-06-24 15:20:36 -04001953
1954 if (colorbuffer)
1955 {
1956 switch (pname)
1957 {
1958 case GL_RED_BITS: *params = colorbuffer->getRedSize(); break;
1959 case GL_GREEN_BITS: *params = colorbuffer->getGreenSize(); break;
1960 case GL_BLUE_BITS: *params = colorbuffer->getBlueSize(); break;
1961 case GL_ALPHA_BITS: *params = colorbuffer->getAlphaSize(); break;
1962 }
1963 }
1964 else
1965 {
1966 *params = 0;
1967 }
1968 }
1969 break;
1970 case GL_DEPTH_BITS:
1971 {
Jamie Madill81c2e252017-09-09 23:32:46 -04001972 const Framebuffer *framebuffer = getDrawFramebuffer();
1973 const FramebufferAttachment *depthbuffer = framebuffer->getDepthbuffer();
Shannon Woods53a94a82014-06-24 15:20:36 -04001974
1975 if (depthbuffer)
1976 {
1977 *params = depthbuffer->getDepthSize();
1978 }
1979 else
1980 {
1981 *params = 0;
1982 }
1983 }
1984 break;
1985 case GL_STENCIL_BITS:
1986 {
Jamie Madill81c2e252017-09-09 23:32:46 -04001987 const Framebuffer *framebuffer = getDrawFramebuffer();
1988 const FramebufferAttachment *stencilbuffer = framebuffer->getStencilbuffer();
Shannon Woods53a94a82014-06-24 15:20:36 -04001989
1990 if (stencilbuffer)
1991 {
1992 *params = stencilbuffer->getStencilSize();
1993 }
1994 else
1995 {
1996 *params = 0;
1997 }
1998 }
1999 break;
2000 case GL_TEXTURE_BINDING_2D:
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_2D);
Shannon Woods53a94a82014-06-24 15:20:36 -04002003 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04002004 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
2005 ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
2006 *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler),
2007 GL_TEXTURE_RECTANGLE_ANGLE);
2008 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002009 case GL_TEXTURE_BINDING_CUBE_MAP:
Shannon Woods2df6a602014-09-26 16:12:07 -04002010 ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
Cooper Partin4d61f7e2015-08-12 10:56:50 -07002011 *params =
2012 getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_CUBE_MAP);
Shannon Woods53a94a82014-06-24 15:20:36 -04002013 break;
2014 case GL_TEXTURE_BINDING_3D:
Shannon Woods2df6a602014-09-26 16:12:07 -04002015 ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
Cooper Partin4d61f7e2015-08-12 10:56:50 -07002016 *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_3D);
Shannon Woods53a94a82014-06-24 15:20:36 -04002017 break;
2018 case GL_TEXTURE_BINDING_2D_ARRAY:
Shannon Woods2df6a602014-09-26 16:12:07 -04002019 ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
Cooper Partin4d61f7e2015-08-12 10:56:50 -07002020 *params =
2021 getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_2D_ARRAY);
Shannon Woods53a94a82014-06-24 15:20:36 -04002022 break;
JiangYizhou24fe74c2017-07-06 16:56:50 +08002023 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
2024 ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
2025 *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler),
2026 GL_TEXTURE_2D_MULTISAMPLE);
2027 break;
John Bauman18319182016-09-28 14:22:27 -07002028 case GL_TEXTURE_BINDING_EXTERNAL_OES:
2029 ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
2030 *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler),
2031 GL_TEXTURE_EXTERNAL_OES);
2032 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002033 case GL_UNIFORM_BUFFER_BINDING:
2034 *params = mGenericUniformBuffer.id();
2035 break;
Frank Henigman22581ff2015-11-06 14:25:54 -05002036 case GL_TRANSFORM_FEEDBACK_BINDING:
Frank Henigmanb0f0b812015-11-21 17:49:29 -05002037 *params = mTransformFeedback.id();
Frank Henigman22581ff2015-11-06 14:25:54 -05002038 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002039 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang045536b2015-03-27 15:17:18 -04002040 *params = mTransformFeedback->getGenericBuffer().id();
Shannon Woods53a94a82014-06-24 15:20:36 -04002041 break;
2042 case GL_COPY_READ_BUFFER_BINDING:
2043 *params = mCopyReadBuffer.id();
2044 break;
2045 case GL_COPY_WRITE_BUFFER_BINDING:
2046 *params = mCopyWriteBuffer.id();
2047 break;
2048 case GL_PIXEL_PACK_BUFFER_BINDING:
Corentin Wallezcda6af12017-10-30 19:20:37 -04002049 *params = mPixelPackBuffer.id();
2050 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002051 case GL_PIXEL_UNPACK_BUFFER_BINDING:
Corentin Wallezcda6af12017-10-30 19:20:37 -04002052 *params = mPixelUnpackBuffer.id();
2053 break;
Olli Etuaho86821db2016-03-04 12:05:47 +02002054 case GL_READ_BUFFER:
2055 *params = mReadFramebuffer->getReadBufferState();
2056 break;
2057 case GL_SAMPLER_BINDING:
2058 ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits);
2059 *params = getSamplerId(static_cast<GLuint>(mActiveSampler));
2060 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05002061 case GL_DEBUG_LOGGED_MESSAGES:
2062 *params = static_cast<GLint>(mDebug.getMessageCount());
2063 break;
2064 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
2065 *params = static_cast<GLint>(mDebug.getNextMessageLength());
2066 break;
2067 case GL_DEBUG_GROUP_STACK_DEPTH:
2068 *params = static_cast<GLint>(mDebug.getGroupStackDepth());
2069 break;
Sami Väisänen74c23472016-05-09 17:30:30 +03002070 case GL_MULTISAMPLE_EXT:
2071 *params = static_cast<GLint>(mMultiSampling);
2072 break;
2073 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
2074 *params = static_cast<GLint>(mSampleAlphaToOne);
Sami Väisänena797e062016-05-12 15:23:40 +03002075 case GL_COVERAGE_MODULATION_CHROMIUM:
2076 *params = static_cast<GLint>(mCoverageModulation);
Sami Väisänen74c23472016-05-09 17:30:30 +03002077 break;
Jiajia Qin6eafb042016-12-27 17:04:07 +08002078 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
2079 *params = mGenericAtomicCounterBuffer.id();
2080 break;
Jiajia Qinf546e7d2017-03-27 14:12:59 +08002081 case GL_SHADER_STORAGE_BUFFER_BINDING:
2082 *params = mGenericShaderStorageBuffer.id();
2083 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002084 default:
2085 UNREACHABLE();
2086 break;
2087 }
2088}
2089
Geoff Lang70d0f492015-12-10 17:45:46 -05002090void State::getPointerv(GLenum pname, void **params) const
2091{
2092 switch (pname)
2093 {
2094 case GL_DEBUG_CALLBACK_FUNCTION:
2095 *params = reinterpret_cast<void *>(mDebug.getCallback());
2096 break;
2097 case GL_DEBUG_CALLBACK_USER_PARAM:
2098 *params = const_cast<void *>(mDebug.getUserParam());
2099 break;
2100 default:
2101 UNREACHABLE();
2102 break;
2103 }
2104}
2105
Martin Radev66fb8202016-07-28 11:45:20 +03002106void State::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods53a94a82014-06-24 15:20:36 -04002107{
2108 switch (target)
2109 {
2110 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Jiajia Qin6eafb042016-12-27 17:04:07 +08002111 ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount());
2112 *data = mTransformFeedback->getIndexedBuffer(index).id();
2113 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002114 case GL_UNIFORM_BUFFER_BINDING:
Jiajia Qin6eafb042016-12-27 17:04:07 +08002115 ASSERT(static_cast<size_t>(index) < mUniformBuffers.size());
2116 *data = mUniformBuffers[index].id();
2117 break;
2118 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
2119 ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size());
2120 *data = mAtomicCounterBuffers[index].id();
2121 break;
Jiajia Qinf546e7d2017-03-27 14:12:59 +08002122 case GL_SHADER_STORAGE_BUFFER_BINDING:
2123 ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size());
2124 *data = mShaderStorageBuffers[index].id();
2125 break;
Shao80957d92017-02-20 21:25:59 +08002126 case GL_VERTEX_BINDING_BUFFER:
2127 ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings());
Martin Radevdd5f27e2017-06-07 10:17:09 +03002128 *data = mVertexArray->getVertexBinding(index).getBuffer().id();
Shao80957d92017-02-20 21:25:59 +08002129 break;
2130 case GL_VERTEX_BINDING_DIVISOR:
2131 ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings());
Martin Radevdd5f27e2017-06-07 10:17:09 +03002132 *data = mVertexArray->getVertexBinding(index).getDivisor();
Shao80957d92017-02-20 21:25:59 +08002133 break;
2134 case GL_VERTEX_BINDING_OFFSET:
2135 ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings());
Martin Radevdd5f27e2017-06-07 10:17:09 +03002136 *data = static_cast<GLuint>(mVertexArray->getVertexBinding(index).getOffset());
Shao80957d92017-02-20 21:25:59 +08002137 break;
2138 case GL_VERTEX_BINDING_STRIDE:
2139 ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings());
Martin Radevdd5f27e2017-06-07 10:17:09 +03002140 *data = mVertexArray->getVertexBinding(index).getStride();
Shao80957d92017-02-20 21:25:59 +08002141 break;
Jiawei Shaodb342272017-09-27 10:21:45 +08002142 case GL_SAMPLE_MASK_VALUE:
2143 ASSERT(static_cast<size_t>(index) < mSampleMaskValues.size());
2144 *data = mSampleMaskValues[index];
2145 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002146 default:
Martin Radev66fb8202016-07-28 11:45:20 +03002147 UNREACHABLE();
2148 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002149 }
Shannon Woods53a94a82014-06-24 15:20:36 -04002150}
2151
Martin Radev66fb8202016-07-28 11:45:20 +03002152void State::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods53a94a82014-06-24 15:20:36 -04002153{
2154 switch (target)
2155 {
2156 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
Jiajia Qin6eafb042016-12-27 17:04:07 +08002157 ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount());
2158 *data = mTransformFeedback->getIndexedBuffer(index).getOffset();
2159 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002160 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
Jiajia Qin6eafb042016-12-27 17:04:07 +08002161 ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount());
2162 *data = mTransformFeedback->getIndexedBuffer(index).getSize();
2163 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002164 case GL_UNIFORM_BUFFER_START:
Jiajia Qin6eafb042016-12-27 17:04:07 +08002165 ASSERT(static_cast<size_t>(index) < mUniformBuffers.size());
2166 *data = mUniformBuffers[index].getOffset();
2167 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002168 case GL_UNIFORM_BUFFER_SIZE:
Jiajia Qin6eafb042016-12-27 17:04:07 +08002169 ASSERT(static_cast<size_t>(index) < mUniformBuffers.size());
2170 *data = mUniformBuffers[index].getSize();
2171 break;
2172 case GL_ATOMIC_COUNTER_BUFFER_START:
2173 ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size());
2174 *data = mAtomicCounterBuffers[index].getOffset();
2175 break;
2176 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
2177 ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size());
2178 *data = mAtomicCounterBuffers[index].getSize();
2179 break;
Jiajia Qinf546e7d2017-03-27 14:12:59 +08002180 case GL_SHADER_STORAGE_BUFFER_START:
2181 ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size());
2182 *data = mShaderStorageBuffers[index].getOffset();
2183 break;
2184 case GL_SHADER_STORAGE_BUFFER_SIZE:
2185 ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size());
2186 *data = mShaderStorageBuffers[index].getSize();
2187 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002188 default:
Martin Radev66fb8202016-07-28 11:45:20 +03002189 UNREACHABLE();
2190 break;
Shannon Woods53a94a82014-06-24 15:20:36 -04002191 }
Martin Radev66fb8202016-07-28 11:45:20 +03002192}
Shannon Woods53a94a82014-06-24 15:20:36 -04002193
Martin Radev66fb8202016-07-28 11:45:20 +03002194void State::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
2195{
2196 UNREACHABLE();
Shannon Woods53a94a82014-06-24 15:20:36 -04002197}
2198
Jamie Madilld9ba4f72014-08-04 10:47:59 -04002199bool State::hasMappedBuffer(GLenum target) const
2200{
2201 if (target == GL_ARRAY_BUFFER)
2202 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002203 const VertexArray *vao = getVertexArray();
Jamie Madilleea3a6e2015-04-15 10:02:48 -04002204 const auto &vertexAttribs = vao->getVertexAttributes();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002205 const auto &vertexBindings = vao->getVertexBindings();
Jamie Madill8e344942015-07-09 14:22:07 -04002206 size_t maxEnabledAttrib = vao->getMaxEnabledAttribute();
Jamie Madillaebf9dd2015-04-28 12:39:07 -04002207 for (size_t attribIndex = 0; attribIndex < maxEnabledAttrib; attribIndex++)
Jamie Madilld9ba4f72014-08-04 10:47:59 -04002208 {
Jamie Madill81c2e252017-09-09 23:32:46 -04002209 const VertexAttribute &vertexAttrib = vertexAttribs[attribIndex];
Martin Radevdd5f27e2017-06-07 10:17:09 +03002210 auto *boundBuffer = vertexBindings[vertexAttrib.bindingIndex].getBuffer().get();
Jamie Madilld9ba4f72014-08-04 10:47:59 -04002211 if (vertexAttrib.enabled && boundBuffer && boundBuffer->isMapped())
2212 {
2213 return true;
2214 }
2215 }
2216
2217 return false;
2218 }
2219 else
2220 {
2221 Buffer *buffer = getTargetBuffer(target);
2222 return (buffer && buffer->isMapped());
2223 }
2224}
2225
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002226void State::syncDirtyObjects(const Context *context)
Jamie Madillc9d442d2016-01-20 11:17:24 -05002227{
2228 if (!mDirtyObjects.any())
2229 return;
2230
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002231 syncDirtyObjects(context, mDirtyObjects);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002232}
2233
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002234void State::syncDirtyObjects(const Context *context, const DirtyObjects &bitset)
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002235{
Jamie Madill6de51852017-04-12 09:53:01 -04002236 for (auto dirtyObject : bitset)
Jamie Madillc9d442d2016-01-20 11:17:24 -05002237 {
2238 switch (dirtyObject)
2239 {
2240 case DIRTY_OBJECT_READ_FRAMEBUFFER:
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002241 ASSERT(mReadFramebuffer);
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002242 mReadFramebuffer->syncState(context);
Jamie Madillc9d442d2016-01-20 11:17:24 -05002243 break;
2244 case DIRTY_OBJECT_DRAW_FRAMEBUFFER:
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002245 ASSERT(mDrawFramebuffer);
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002246 mDrawFramebuffer->syncState(context);
Jamie Madillc9d442d2016-01-20 11:17:24 -05002247 break;
2248 case DIRTY_OBJECT_VERTEX_ARRAY:
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002249 ASSERT(mVertexArray);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002250 mVertexArray->syncState(context);
Jamie Madillc9d442d2016-01-20 11:17:24 -05002251 break;
Jamie Madill81c2e252017-09-09 23:32:46 -04002252 case DIRTY_OBJECT_PROGRAM_TEXTURES:
2253 syncProgramTextures(context);
2254 break;
2255
Jamie Madillc9d442d2016-01-20 11:17:24 -05002256 default:
2257 UNREACHABLE();
2258 break;
2259 }
2260 }
2261
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002262 mDirtyObjects &= ~bitset;
2263}
2264
Jamie Madill81c2e252017-09-09 23:32:46 -04002265void State::syncProgramTextures(const Context *context)
2266{
Jamie Madill81c2e252017-09-09 23:32:46 -04002267 // TODO(jmadill): Fine-grained updates.
2268 if (!mProgram)
2269 {
2270 return;
2271 }
2272
2273 ASSERT(mDirtyObjects[DIRTY_OBJECT_PROGRAM_TEXTURES]);
2274 mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS);
2275
Jamie Madill0f80ed82017-09-19 00:24:56 -04002276 ActiveTextureMask newActiveTextures;
2277
Jamie Madill81c2e252017-09-09 23:32:46 -04002278 for (const SamplerBinding &samplerBinding : mProgram->getSamplerBindings())
2279 {
2280 if (samplerBinding.unreferenced)
2281 continue;
2282
2283 GLenum textureType = samplerBinding.textureType;
2284 for (GLuint textureUnitIndex : samplerBinding.boundTextureUnits)
2285 {
2286 Texture *texture = getSamplerTexture(textureUnitIndex, textureType);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002287 Sampler *sampler = getSampler(textureUnitIndex);
Jamie Madill0f80ed82017-09-19 00:24:56 -04002288 ASSERT(static_cast<size_t>(textureUnitIndex) < mCompleteTextureCache.size());
2289 ASSERT(static_cast<size_t>(textureUnitIndex) < newActiveTextures.size());
Jamie Madill81c2e252017-09-09 23:32:46 -04002290
Jamie Madill42975642017-10-12 12:31:51 -04002291 ASSERT(texture);
Jamie Madill81c2e252017-09-09 23:32:46 -04002292
Jamie Madill42975642017-10-12 12:31:51 -04002293 // Mark the texture binding bit as dirty if the texture completeness changes.
2294 // TODO(jmadill): Use specific dirty bit for completeness change.
2295 if (texture->isSamplerComplete(context, sampler) &&
2296 !mDrawFramebuffer->hasTextureAttachment(texture))
2297 {
2298 texture->syncState();
2299 mCompleteTextureCache[textureUnitIndex] = texture;
Jamie Madill81c2e252017-09-09 23:32:46 -04002300 }
Jamie Madill42975642017-10-12 12:31:51 -04002301 else
2302 {
2303 mCompleteTextureCache[textureUnitIndex] = nullptr;
2304 }
2305
2306 // Bind the texture unconditionally, to recieve completeness change notifications.
2307 mCompleteTextureBindings[textureUnitIndex].bind(texture->getDirtyChannel());
Jamie Madilla59fc192017-11-02 12:57:58 -04002308 mActiveTexturesMask.set(textureUnitIndex);
Jamie Madill42975642017-10-12 12:31:51 -04002309 newActiveTextures.set(textureUnitIndex);
Jamie Madill81c2e252017-09-09 23:32:46 -04002310
Jamie Madill06ef36b2017-09-09 23:32:46 -04002311 if (sampler != nullptr)
2312 {
2313 sampler->syncState(context);
2314 }
Jamie Madill81c2e252017-09-09 23:32:46 -04002315 }
2316 }
Jamie Madill0f80ed82017-09-19 00:24:56 -04002317
2318 // Unset now missing textures.
Jamie Madilla59fc192017-11-02 12:57:58 -04002319 ActiveTextureMask negativeMask = mActiveTexturesMask & ~newActiveTextures;
Jamie Madill0f80ed82017-09-19 00:24:56 -04002320 if (negativeMask.any())
2321 {
2322 for (auto textureIndex : negativeMask)
2323 {
2324 mCompleteTextureBindings[textureIndex].reset();
2325 mCompleteTextureCache[textureIndex] = nullptr;
Jamie Madilla59fc192017-11-02 12:57:58 -04002326 mActiveTexturesMask.reset(textureIndex);
Jamie Madill0f80ed82017-09-19 00:24:56 -04002327 }
2328 }
Jamie Madill81c2e252017-09-09 23:32:46 -04002329}
2330
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002331void State::syncDirtyObject(const Context *context, GLenum target)
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002332{
2333 DirtyObjects localSet;
2334
2335 switch (target)
2336 {
2337 case GL_READ_FRAMEBUFFER:
2338 localSet.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
2339 break;
2340 case GL_DRAW_FRAMEBUFFER:
2341 localSet.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
2342 break;
2343 case GL_FRAMEBUFFER:
2344 localSet.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
2345 localSet.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
2346 break;
2347 case GL_VERTEX_ARRAY:
2348 localSet.set(DIRTY_OBJECT_VERTEX_ARRAY);
2349 break;
Jamie Madill81c2e252017-09-09 23:32:46 -04002350 case GL_TEXTURE:
2351 case GL_SAMPLER:
2352 case GL_PROGRAM:
2353 localSet.set(DIRTY_OBJECT_PROGRAM_TEXTURES);
2354 break;
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002355 }
2356
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002357 syncDirtyObjects(context, localSet);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002358}
2359
2360void State::setObjectDirty(GLenum target)
2361{
2362 switch (target)
2363 {
2364 case GL_READ_FRAMEBUFFER:
2365 mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
2366 break;
2367 case GL_DRAW_FRAMEBUFFER:
2368 mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
2369 break;
2370 case GL_FRAMEBUFFER:
2371 mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
2372 mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
2373 break;
2374 case GL_VERTEX_ARRAY:
2375 mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY);
2376 break;
Jamie Madill81c2e252017-09-09 23:32:46 -04002377 case GL_TEXTURE:
2378 case GL_SAMPLER:
Jamie Madill81c2e252017-09-09 23:32:46 -04002379 case GL_PROGRAM:
2380 mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES);
2381 mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS);
2382 break;
Jamie Madilla779b612017-07-24 11:46:05 -04002383 }
2384}
2385
2386void State::onProgramExecutableChange(Program *program)
2387{
2388 // OpenGL Spec:
2389 // "If LinkProgram or ProgramBinary successfully re-links a program object
2390 // that was already in use as a result of a previous call to UseProgram, then the
2391 // generated executable code will be installed as part of the current rendering state."
2392 if (program->isLinked() && mProgram == program)
2393 {
2394 mDirtyBits.set(DIRTY_BIT_PROGRAM_EXECUTABLE);
Jamie Madill81c2e252017-09-09 23:32:46 -04002395 mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002396 }
Shannon Woods53a94a82014-06-24 15:20:36 -04002397}
Jamie Madillc9d442d2016-01-20 11:17:24 -05002398
Xinghua Cao65ec0b22017-03-28 16:10:52 +08002399void State::setImageUnit(const Context *context,
2400 GLuint unit,
2401 Texture *texture,
2402 GLint level,
2403 GLboolean layered,
2404 GLint layer,
2405 GLenum access,
2406 GLenum format)
2407{
2408 mImageUnits[unit].texture.set(context, texture);
2409 mImageUnits[unit].level = level;
2410 mImageUnits[unit].layered = layered;
2411 mImageUnits[unit].layer = layer;
2412 mImageUnits[unit].access = access;
2413 mImageUnits[unit].format = format;
2414}
2415
2416const ImageUnit &State::getImageUnit(GLuint unit) const
2417{
2418 return mImageUnits[unit];
2419}
2420
Jamie Madill81c2e252017-09-09 23:32:46 -04002421// Handle a dirty texture event.
Jamie Madill05b35b22017-10-03 09:01:44 -04002422void State::signal(size_t textureIndex, InitState initState)
Jamie Madill81c2e252017-09-09 23:32:46 -04002423{
2424 // Conservatively assume all textures are dirty.
2425 // TODO(jmadill): More fine-grained update.
2426 mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES);
2427}
2428
Jamie Madill05b35b22017-10-03 09:01:44 -04002429Error State::clearUnclearedActiveTextures(const Context *context)
2430{
Jamie Madilla59fc192017-11-02 12:57:58 -04002431 ASSERT(mRobustResourceInit);
Jamie Madill05b35b22017-10-03 09:01:44 -04002432
Jamie Madilla59fc192017-11-02 12:57:58 -04002433 for (auto textureIndex : mActiveTexturesMask)
Jamie Madill05b35b22017-10-03 09:01:44 -04002434 {
Jamie Madilla59fc192017-11-02 12:57:58 -04002435 Texture *texture = mCompleteTextureCache[textureIndex];
Jamie Madill05b35b22017-10-03 09:01:44 -04002436 if (texture)
2437 {
2438 ANGLE_TRY(texture->ensureInitialized(context));
2439 }
2440 }
Jamie Madilla59fc192017-11-02 12:57:58 -04002441
Jamie Madill05b35b22017-10-03 09:01:44 -04002442 return NoError();
2443}
2444
Jamie Madillc67323a2017-11-02 23:11:41 -04002445AttributesMask State::getAndResetDirtyCurrentValues() const
2446{
2447 AttributesMask retVal = mDirtyCurrentValues;
2448 mDirtyCurrentValues.reset();
2449 return retVal;
2450}
2451
Jamie Madillc9d442d2016-01-20 11:17:24 -05002452} // namespace gl