Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // State.cpp: Implements the State class, encapsulating raw GL state. |
| 8 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/State.h" |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 10 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 11 | #include <limits> |
| 12 | #include <string.h> |
| 13 | |
Jamie Madill | 20e005b | 2017-04-07 14:19:22 -0400 | [diff] [blame] | 14 | #include "common/bitset_utils.h" |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 15 | #include "common/mathutil.h" |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 16 | #include "common/matrix_utils.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 17 | #include "libANGLE/Caps.h" |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 18 | #include "libANGLE/Context.h" |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 19 | #include "libANGLE/Debug.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 20 | #include "libANGLE/Framebuffer.h" |
| 21 | #include "libANGLE/FramebufferAttachment.h" |
| 22 | #include "libANGLE/Query.h" |
| 23 | #include "libANGLE/VertexArray.h" |
| 24 | #include "libANGLE/formatutils.h" |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 25 | #include "libANGLE/queryconversions.h" |
Geoff Lang | 4751aab | 2017-10-30 15:14:52 -0400 | [diff] [blame] | 26 | #include "libANGLE/renderer/ContextImpl.h" |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 27 | |
Olli Etuaho | bbf1c10 | 2016-06-28 13:31:33 +0300 | [diff] [blame] | 28 | namespace |
| 29 | { |
| 30 | |
| 31 | GLenum 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 Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 38 | namespace gl |
| 39 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 40 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 41 | State::State() |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 42 | : mMaxDrawBuffers(0), |
| 43 | mMaxCombinedTextureImageUnits(0), |
| 44 | mDepthClearValue(0), |
| 45 | mStencilClearValue(0), |
| 46 | mScissorTest(false), |
| 47 | mSampleCoverage(false), |
| 48 | mSampleCoverageValue(0), |
| 49 | mSampleCoverageInvert(false), |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame] | 50 | mSampleMask(false), |
| 51 | mMaxSampleMaskWords(0), |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 52 | mStencilRef(0), |
| 53 | mStencilBackRef(0), |
| 54 | mLineWidth(0), |
| 55 | mGenerateMipmapHint(GL_NONE), |
| 56 | mFragmentShaderDerivativeHint(GL_NONE), |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 57 | mBindGeneratesResource(true), |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 58 | mClientArraysEnabled(true), |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 59 | mNearZ(0), |
| 60 | mFarZ(0), |
| 61 | mReadFramebuffer(nullptr), |
| 62 | mDrawFramebuffer(nullptr), |
| 63 | mProgram(nullptr), |
| 64 | mVertexArray(nullptr), |
| 65 | mActiveSampler(0), |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 66 | mPrimitiveRestart(false), |
| 67 | mMultiSampling(false), |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 68 | mSampleAlphaToOne(false), |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 69 | mFramebufferSRGB(true), |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 70 | mRobustResourceInit(false), |
| 71 | mProgramBinaryCacheEnabled(false) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 72 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | State::~State() |
| 76 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 77 | } |
| 78 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 79 | void State::initialize(const Context *context, |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 80 | bool debug, |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 81 | bool bindGeneratesResource, |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 82 | bool clientArraysEnabled, |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 83 | bool robustResourceInit, |
| 84 | bool programBinaryCacheEnabled) |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 85 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 86 | const Caps &caps = context->getCaps(); |
| 87 | const Extensions &extensions = context->getExtensions(); |
Geoff Lang | 4751aab | 2017-10-30 15:14:52 -0400 | [diff] [blame] | 88 | const Extensions &nativeExtensions = context->getImplementation()->getNativeExtensions(); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 89 | const Version &clientVersion = context->getClientVersion(); |
| 90 | |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 91 | mMaxDrawBuffers = caps.maxDrawBuffers; |
| 92 | mMaxCombinedTextureImageUnits = caps.maxCombinedTextureImageUnits; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 93 | |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 94 | setColorClearValue(0.0f, 0.0f, 0.0f, 0.0f); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 95 | |
| 96 | mDepthClearValue = 1.0f; |
| 97 | mStencilClearValue = 0; |
| 98 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 99 | mScissorTest = false; |
| 100 | mScissor.x = 0; |
| 101 | mScissor.y = 0; |
| 102 | mScissor.width = 0; |
| 103 | mScissor.height = 0; |
| 104 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 105 | mBlendColor.red = 0; |
| 106 | mBlendColor.green = 0; |
| 107 | mBlendColor.blue = 0; |
| 108 | mBlendColor.alpha = 0; |
| 109 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 110 | mStencilRef = 0; |
| 111 | mStencilBackRef = 0; |
| 112 | |
| 113 | mSampleCoverage = false; |
| 114 | mSampleCoverageValue = 1.0f; |
| 115 | mSampleCoverageInvert = false; |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame] | 116 | |
| 117 | mMaxSampleMaskWords = caps.maxSampleMaskWords; |
| 118 | mSampleMask = false; |
| 119 | mSampleMaskValues.fill(~GLbitfield(0)); |
| 120 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 121 | mGenerateMipmapHint = GL_DONT_CARE; |
| 122 | mFragmentShaderDerivativeHint = GL_DONT_CARE; |
| 123 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 124 | mBindGeneratesResource = bindGeneratesResource; |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 125 | mClientArraysEnabled = clientArraysEnabled; |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 126 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 127 | 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 Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 141 | mActiveSampler = 0; |
| 142 | |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 143 | mVertexAttribCurrentValues.resize(caps.maxVertexAttributes); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 144 | |
Geoff Lang | 4dc3af0 | 2016-11-18 14:09:27 -0500 | [diff] [blame] | 145 | mUniformBuffers.resize(caps.maxUniformBufferBindings); |
Shannon Woods | f3acaf9 | 2014-09-23 18:07:11 -0400 | [diff] [blame] | 146 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 147 | mSamplerTextures[GL_TEXTURE_2D].resize(caps.maxCombinedTextureImageUnits); |
| 148 | mSamplerTextures[GL_TEXTURE_CUBE_MAP].resize(caps.maxCombinedTextureImageUnits); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 149 | if (clientVersion >= Version(3, 0)) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 150 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 151 | // 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 Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 154 | } |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 155 | if (clientVersion >= Version(3, 1)) |
| 156 | { |
| 157 | mSamplerTextures[GL_TEXTURE_2D_MULTISAMPLE].resize(caps.maxCombinedTextureImageUnits); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 158 | |
| 159 | mAtomicCounterBuffers.resize(caps.maxAtomicCounterBufferBindings); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 160 | mShaderStorageBuffers.resize(caps.maxShaderStorageBufferBindings); |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 161 | mImageUnits.resize(caps.maxImageUnits); |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 162 | } |
Geoff Lang | 4751aab | 2017-10-30 15:14:52 -0400 | [diff] [blame] | 163 | if (nativeExtensions.textureRectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 164 | { |
| 165 | mSamplerTextures[GL_TEXTURE_RECTANGLE_ANGLE].resize(caps.maxCombinedTextureImageUnits); |
| 166 | } |
Geoff Lang | 4751aab | 2017-10-30 15:14:52 -0400 | [diff] [blame] | 167 | if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal) |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 168 | { |
| 169 | mSamplerTextures[GL_TEXTURE_EXTERNAL_OES].resize(caps.maxCombinedTextureImageUnits); |
| 170 | } |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 171 | 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 Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 178 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 179 | mSamplers.resize(caps.maxCombinedTextureImageUnits); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 180 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 181 | 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 Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 186 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 187 | mProgram = nullptr; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 188 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 189 | mReadFramebuffer = nullptr; |
| 190 | mDrawFramebuffer = nullptr; |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 191 | |
| 192 | mPrimitiveRestart = false; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 193 | |
| 194 | mDebug.setOutputEnabled(debug); |
| 195 | mDebug.setMaxLoggedMessages(extensions.maxDebugLoggedMessages); |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 196 | |
Geoff Lang | 488130e | 2017-09-27 13:53:11 -0400 | [diff] [blame] | 197 | mMultiSampling = true; |
| 198 | mSampleAlphaToOne = false; |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 199 | |
| 200 | mCoverageModulation = GL_NONE; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 201 | |
| 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 Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 207 | |
| 208 | mRobustResourceInit = robustResourceInit; |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 209 | mProgramBinaryCacheEnabled = programBinaryCacheEnabled; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 210 | } |
| 211 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 212 | void State::reset(const Context *context) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 213 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 214 | for (auto &bindingVec : mSamplerTextures) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 215 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 216 | TextureBindingVector &textureVector = bindingVec.second; |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 217 | for (size_t textureIdx = 0; textureIdx < textureVector.size(); textureIdx++) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 218 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 219 | textureVector[textureIdx].set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 220 | } |
| 221 | } |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 222 | for (size_t samplerIdx = 0; samplerIdx < mSamplers.size(); samplerIdx++) |
| 223 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 224 | mSamplers[samplerIdx].set(context, nullptr); |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 225 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 226 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 227 | 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 Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 237 | mArrayBuffer.set(context, nullptr); |
| 238 | mDrawIndirectBuffer.set(context, nullptr); |
| 239 | mRenderbuffer.set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 240 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 241 | if (mProgram) |
| 242 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 243 | mProgram->release(context); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 244 | } |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 245 | mProgram = nullptr; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 246 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 247 | mProgramPipeline.set(context, nullptr); |
| 248 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 249 | mTransformFeedback.set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 250 | |
| 251 | for (State::ActiveQueryMap::iterator i = mActiveQueries.begin(); i != mActiveQueries.end(); i++) |
| 252 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 253 | i->second.set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 254 | } |
| 255 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 256 | mGenericUniformBuffer.set(context, nullptr); |
Shannon Woods | 8299bb0 | 2014-09-26 18:55:43 -0400 | [diff] [blame] | 257 | for (BufferVector::iterator bufItr = mUniformBuffers.begin(); bufItr != mUniformBuffers.end(); ++bufItr) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 258 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 259 | bufItr->set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 260 | } |
| 261 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 262 | mCopyReadBuffer.set(context, nullptr); |
| 263 | mCopyWriteBuffer.set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 264 | |
Corentin Wallez | cda6af1 | 2017-10-30 19:20:37 -0400 | [diff] [blame^] | 265 | mPixelPackBuffer.set(context, nullptr); |
| 266 | mPixelUnpackBuffer.set(context, nullptr); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 267 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 268 | mGenericAtomicCounterBuffer.set(context, nullptr); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 269 | for (auto &buf : mAtomicCounterBuffers) |
| 270 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 271 | buf.set(context, nullptr); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 272 | } |
| 273 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 274 | mGenericShaderStorageBuffer.set(context, nullptr); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 275 | for (auto &buf : mShaderStorageBuffers) |
| 276 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 277 | buf.set(context, nullptr); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 278 | } |
| 279 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 280 | 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 Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 286 | // TODO(jmadill): Is this necessary? |
| 287 | setAllDirtyBits(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | const RasterizerState &State::getRasterizerState() const |
| 291 | { |
| 292 | return mRasterizer; |
| 293 | } |
| 294 | |
| 295 | const BlendState &State::getBlendState() const |
| 296 | { |
| 297 | return mBlend; |
| 298 | } |
| 299 | |
| 300 | const DepthStencilState &State::getDepthStencilState() const |
| 301 | { |
| 302 | return mDepthStencil; |
| 303 | } |
| 304 | |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 305 | void State::setColorClearValue(float red, float green, float blue, float alpha) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 306 | { |
| 307 | mColorClearValue.red = red; |
| 308 | mColorClearValue.green = green; |
| 309 | mColorClearValue.blue = blue; |
| 310 | mColorClearValue.alpha = alpha; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 311 | mDirtyBits.set(DIRTY_BIT_CLEAR_COLOR); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 312 | } |
| 313 | |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 314 | void State::setDepthClearValue(float depth) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 315 | { |
| 316 | mDepthClearValue = depth; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 317 | mDirtyBits.set(DIRTY_BIT_CLEAR_DEPTH); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 318 | } |
| 319 | |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 320 | void State::setStencilClearValue(int stencil) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 321 | { |
| 322 | mStencilClearValue = stencil; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 323 | mDirtyBits.set(DIRTY_BIT_CLEAR_STENCIL); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 324 | } |
| 325 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 326 | void 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 Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 332 | mDirtyBits.set(DIRTY_BIT_COLOR_MASK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | void State::setDepthMask(bool mask) |
| 336 | { |
| 337 | mDepthStencil.depthMask = mask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 338 | mDirtyBits.set(DIRTY_BIT_DEPTH_MASK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | bool State::isRasterizerDiscardEnabled() const |
| 342 | { |
| 343 | return mRasterizer.rasterizerDiscard; |
| 344 | } |
| 345 | |
| 346 | void State::setRasterizerDiscard(bool enabled) |
| 347 | { |
| 348 | mRasterizer.rasterizerDiscard = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 349 | mDirtyBits.set(DIRTY_BIT_RASTERIZER_DISCARD_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | bool State::isCullFaceEnabled() const |
| 353 | { |
| 354 | return mRasterizer.cullFace; |
| 355 | } |
| 356 | |
| 357 | void State::setCullFace(bool enabled) |
| 358 | { |
| 359 | mRasterizer.cullFace = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 360 | mDirtyBits.set(DIRTY_BIT_CULL_FACE_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 361 | } |
| 362 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 363 | void State::setCullMode(CullFaceMode mode) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 364 | { |
| 365 | mRasterizer.cullMode = mode; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 366 | mDirtyBits.set(DIRTY_BIT_CULL_FACE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | void State::setFrontFace(GLenum front) |
| 370 | { |
| 371 | mRasterizer.frontFace = front; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 372 | mDirtyBits.set(DIRTY_BIT_FRONT_FACE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | bool State::isDepthTestEnabled() const |
| 376 | { |
| 377 | return mDepthStencil.depthTest; |
| 378 | } |
| 379 | |
| 380 | void State::setDepthTest(bool enabled) |
| 381 | { |
| 382 | mDepthStencil.depthTest = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 383 | mDirtyBits.set(DIRTY_BIT_DEPTH_TEST_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | void State::setDepthFunc(GLenum depthFunc) |
| 387 | { |
| 388 | mDepthStencil.depthFunc = depthFunc; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 389 | mDirtyBits.set(DIRTY_BIT_DEPTH_FUNC); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | void State::setDepthRange(float zNear, float zFar) |
| 393 | { |
| 394 | mNearZ = zNear; |
| 395 | mFarZ = zFar; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 396 | mDirtyBits.set(DIRTY_BIT_DEPTH_RANGE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 397 | } |
| 398 | |
Geoff Lang | d42f5b8 | 2015-04-16 14:03:29 -0400 | [diff] [blame] | 399 | float State::getNearPlane() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 400 | { |
Geoff Lang | d42f5b8 | 2015-04-16 14:03:29 -0400 | [diff] [blame] | 401 | return mNearZ; |
| 402 | } |
| 403 | |
| 404 | float State::getFarPlane() const |
| 405 | { |
| 406 | return mFarZ; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | bool State::isBlendEnabled() const |
| 410 | { |
| 411 | return mBlend.blend; |
| 412 | } |
| 413 | |
| 414 | void State::setBlend(bool enabled) |
| 415 | { |
| 416 | mBlend.blend = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 417 | mDirtyBits.set(DIRTY_BIT_BLEND_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | void 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 Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 426 | mDirtyBits.set(DIRTY_BIT_BLEND_FUNCS); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | void 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 Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 435 | mDirtyBits.set(DIRTY_BIT_BLEND_COLOR); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | void State::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation) |
| 439 | { |
| 440 | mBlend.blendEquationRGB = rgbEquation; |
| 441 | mBlend.blendEquationAlpha = alphaEquation; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 442 | mDirtyBits.set(DIRTY_BIT_BLEND_EQUATIONS); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | const ColorF &State::getBlendColor() const |
| 446 | { |
| 447 | return mBlendColor; |
| 448 | } |
| 449 | |
| 450 | bool State::isStencilTestEnabled() const |
| 451 | { |
| 452 | return mDepthStencil.stencilTest; |
| 453 | } |
| 454 | |
| 455 | void State::setStencilTest(bool enabled) |
| 456 | { |
| 457 | mDepthStencil.stencilTest = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 458 | mDirtyBits.set(DIRTY_BIT_STENCIL_TEST_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | void State::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask) |
| 462 | { |
| 463 | mDepthStencil.stencilFunc = stencilFunc; |
| 464 | mStencilRef = (stencilRef > 0) ? stencilRef : 0; |
| 465 | mDepthStencil.stencilMask = stencilMask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 466 | mDirtyBits.set(DIRTY_BIT_STENCIL_FUNCS_FRONT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | void State::setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask) |
| 470 | { |
| 471 | mDepthStencil.stencilBackFunc = stencilBackFunc; |
| 472 | mStencilBackRef = (stencilBackRef > 0) ? stencilBackRef : 0; |
| 473 | mDepthStencil.stencilBackMask = stencilBackMask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 474 | mDirtyBits.set(DIRTY_BIT_STENCIL_FUNCS_BACK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | void State::setStencilWritemask(GLuint stencilWritemask) |
| 478 | { |
| 479 | mDepthStencil.stencilWritemask = stencilWritemask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 480 | mDirtyBits.set(DIRTY_BIT_STENCIL_WRITEMASK_FRONT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | void State::setStencilBackWritemask(GLuint stencilBackWritemask) |
| 484 | { |
| 485 | mDepthStencil.stencilBackWritemask = stencilBackWritemask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 486 | mDirtyBits.set(DIRTY_BIT_STENCIL_WRITEMASK_BACK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | void State::setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass) |
| 490 | { |
| 491 | mDepthStencil.stencilFail = stencilFail; |
| 492 | mDepthStencil.stencilPassDepthFail = stencilPassDepthFail; |
| 493 | mDepthStencil.stencilPassDepthPass = stencilPassDepthPass; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 494 | mDirtyBits.set(DIRTY_BIT_STENCIL_OPS_FRONT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | void State::setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass) |
| 498 | { |
| 499 | mDepthStencil.stencilBackFail = stencilBackFail; |
| 500 | mDepthStencil.stencilBackPassDepthFail = stencilBackPassDepthFail; |
| 501 | mDepthStencil.stencilBackPassDepthPass = stencilBackPassDepthPass; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 502 | mDirtyBits.set(DIRTY_BIT_STENCIL_OPS_BACK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | GLint State::getStencilRef() const |
| 506 | { |
| 507 | return mStencilRef; |
| 508 | } |
| 509 | |
| 510 | GLint State::getStencilBackRef() const |
| 511 | { |
| 512 | return mStencilBackRef; |
| 513 | } |
| 514 | |
| 515 | bool State::isPolygonOffsetFillEnabled() const |
| 516 | { |
| 517 | return mRasterizer.polygonOffsetFill; |
| 518 | } |
| 519 | |
| 520 | void State::setPolygonOffsetFill(bool enabled) |
| 521 | { |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 522 | mRasterizer.polygonOffsetFill = enabled; |
| 523 | mDirtyBits.set(DIRTY_BIT_POLYGON_OFFSET_FILL_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | void 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 Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 531 | mDirtyBits.set(DIRTY_BIT_POLYGON_OFFSET); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | bool State::isSampleAlphaToCoverageEnabled() const |
| 535 | { |
| 536 | return mBlend.sampleAlphaToCoverage; |
| 537 | } |
| 538 | |
| 539 | void State::setSampleAlphaToCoverage(bool enabled) |
| 540 | { |
| 541 | mBlend.sampleAlphaToCoverage = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 542 | mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | bool State::isSampleCoverageEnabled() const |
| 546 | { |
| 547 | return mSampleCoverage; |
| 548 | } |
| 549 | |
| 550 | void State::setSampleCoverage(bool enabled) |
| 551 | { |
| 552 | mSampleCoverage = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 553 | mDirtyBits.set(DIRTY_BIT_SAMPLE_COVERAGE_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | void State::setSampleCoverageParams(GLclampf value, bool invert) |
| 557 | { |
| 558 | mSampleCoverageValue = value; |
| 559 | mSampleCoverageInvert = invert; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 560 | mDirtyBits.set(DIRTY_BIT_SAMPLE_COVERAGE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 561 | } |
| 562 | |
Geoff Lang | 0fbb600 | 2015-04-16 11:11:53 -0400 | [diff] [blame] | 563 | GLclampf State::getSampleCoverageValue() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 564 | { |
Geoff Lang | 0fbb600 | 2015-04-16 11:11:53 -0400 | [diff] [blame] | 565 | return mSampleCoverageValue; |
| 566 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 567 | |
Geoff Lang | 0fbb600 | 2015-04-16 11:11:53 -0400 | [diff] [blame] | 568 | bool State::getSampleCoverageInvert() const |
| 569 | { |
| 570 | return mSampleCoverageInvert; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 571 | } |
| 572 | |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame] | 573 | bool State::isSampleMaskEnabled() const |
| 574 | { |
| 575 | return mSampleMask; |
| 576 | } |
| 577 | |
| 578 | void State::setSampleMaskEnabled(bool enabled) |
| 579 | { |
| 580 | mSampleMask = enabled; |
| 581 | mDirtyBits.set(DIRTY_BIT_SAMPLE_MASK_ENABLED); |
| 582 | } |
| 583 | |
| 584 | void State::setSampleMaskParams(GLuint maskNumber, GLbitfield mask) |
| 585 | { |
| 586 | ASSERT(maskNumber < mMaxSampleMaskWords); |
| 587 | mSampleMaskValues[maskNumber] = mask; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 588 | // TODO(jmadill): Use a child dirty bit if we ever use more than two words. |
| 589 | mDirtyBits.set(DIRTY_BIT_SAMPLE_MASK); |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | GLbitfield State::getSampleMaskWord(GLuint maskNumber) const |
| 593 | { |
| 594 | ASSERT(maskNumber < mMaxSampleMaskWords); |
| 595 | return mSampleMaskValues[maskNumber]; |
| 596 | } |
| 597 | |
| 598 | GLuint State::getMaxSampleMaskWords() const |
| 599 | { |
| 600 | return mMaxSampleMaskWords; |
| 601 | } |
| 602 | |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 603 | void State::setSampleAlphaToOne(bool enabled) |
| 604 | { |
| 605 | mSampleAlphaToOne = enabled; |
| 606 | mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_ONE); |
| 607 | } |
| 608 | |
| 609 | bool State::isSampleAlphaToOneEnabled() const |
| 610 | { |
| 611 | return mSampleAlphaToOne; |
| 612 | } |
| 613 | |
| 614 | void State::setMultisampling(bool enabled) |
| 615 | { |
| 616 | mMultiSampling = enabled; |
| 617 | mDirtyBits.set(DIRTY_BIT_MULTISAMPLING); |
| 618 | } |
| 619 | |
| 620 | bool State::isMultisamplingEnabled() const |
| 621 | { |
| 622 | return mMultiSampling; |
| 623 | } |
| 624 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 625 | bool State::isScissorTestEnabled() const |
| 626 | { |
| 627 | return mScissorTest; |
| 628 | } |
| 629 | |
| 630 | void State::setScissorTest(bool enabled) |
| 631 | { |
| 632 | mScissorTest = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 633 | mDirtyBits.set(DIRTY_BIT_SCISSOR_TEST_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | void 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 Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 642 | mDirtyBits.set(DIRTY_BIT_SCISSOR); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | const Rectangle &State::getScissor() const |
| 646 | { |
| 647 | return mScissor; |
| 648 | } |
| 649 | |
| 650 | bool State::isDitherEnabled() const |
| 651 | { |
| 652 | return mBlend.dither; |
| 653 | } |
| 654 | |
| 655 | void State::setDither(bool enabled) |
| 656 | { |
| 657 | mBlend.dither = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 658 | mDirtyBits.set(DIRTY_BIT_DITHER_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 659 | } |
| 660 | |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 661 | bool State::isPrimitiveRestartEnabled() const |
| 662 | { |
| 663 | return mPrimitiveRestart; |
| 664 | } |
| 665 | |
| 666 | void State::setPrimitiveRestart(bool enabled) |
| 667 | { |
| 668 | mPrimitiveRestart = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 669 | mDirtyBits.set(DIRTY_BIT_PRIMITIVE_RESTART_ENABLED); |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 670 | } |
| 671 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 672 | void State::setEnableFeature(GLenum feature, bool enabled) |
| 673 | { |
| 674 | switch (feature) |
| 675 | { |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 676 | case GL_MULTISAMPLE_EXT: setMultisampling(enabled); break; |
| 677 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: setSampleAlphaToOne(enabled); break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 678 | 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 Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 687 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: setPrimitiveRestart(enabled); break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 688 | case GL_RASTERIZER_DISCARD: setRasterizerDiscard(enabled); break; |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 689 | case GL_SAMPLE_MASK: |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame] | 690 | setSampleMaskEnabled(enabled); |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 691 | break; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 692 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 693 | mDebug.setOutputSynchronous(enabled); |
| 694 | break; |
| 695 | case GL_DEBUG_OUTPUT: |
| 696 | mDebug.setOutputEnabled(enabled); |
| 697 | break; |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 698 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 699 | setFramebufferSRGB(enabled); |
| 700 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 701 | default: UNREACHABLE(); |
| 702 | } |
| 703 | } |
| 704 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 705 | bool State::getEnableFeature(GLenum feature) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 706 | { |
| 707 | switch (feature) |
| 708 | { |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 709 | case GL_MULTISAMPLE_EXT: return isMultisamplingEnabled(); |
| 710 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: return isSampleAlphaToOneEnabled(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 711 | 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 Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 720 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: return isPrimitiveRestartEnabled(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 721 | case GL_RASTERIZER_DISCARD: return isRasterizerDiscardEnabled(); |
Geoff Lang | b5e997f | 2016-12-06 10:55:34 -0500 | [diff] [blame] | 722 | case GL_SAMPLE_MASK: |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame] | 723 | return isSampleMaskEnabled(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 724 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 725 | return mDebug.isOutputSynchronous(); |
| 726 | case GL_DEBUG_OUTPUT: |
| 727 | return mDebug.isOutputEnabled(); |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 728 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 729 | return isBindGeneratesResourceEnabled(); |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 730 | case GL_CLIENT_ARRAYS_ANGLE: |
| 731 | return areClientArraysEnabled(); |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 732 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 733 | return getFramebufferSRGB(); |
Geoff Lang | b433e87 | 2017-10-05 14:01:47 -0400 | [diff] [blame] | 734 | case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE: |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 735 | return mRobustResourceInit; |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 736 | case GL_PROGRAM_CACHE_ENABLED_ANGLE: |
| 737 | return mProgramBinaryCacheEnabled; |
| 738 | |
| 739 | default: |
| 740 | UNREACHABLE(); |
| 741 | return false; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 742 | } |
| 743 | } |
| 744 | |
| 745 | void State::setLineWidth(GLfloat width) |
| 746 | { |
| 747 | mLineWidth = width; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 748 | mDirtyBits.set(DIRTY_BIT_LINE_WIDTH); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 749 | } |
| 750 | |
Geoff Lang | 4b3f416 | 2015-04-16 13:22:05 -0400 | [diff] [blame] | 751 | float State::getLineWidth() const |
| 752 | { |
| 753 | return mLineWidth; |
| 754 | } |
| 755 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 756 | void State::setGenerateMipmapHint(GLenum hint) |
| 757 | { |
| 758 | mGenerateMipmapHint = hint; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 759 | mDirtyBits.set(DIRTY_BIT_GENERATE_MIPMAP_HINT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | void State::setFragmentShaderDerivativeHint(GLenum hint) |
| 763 | { |
| 764 | mFragmentShaderDerivativeHint = hint; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 765 | mDirtyBits.set(DIRTY_BIT_SHADER_DERIVATIVE_HINT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 766 | // 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 Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 771 | bool State::isBindGeneratesResourceEnabled() const |
| 772 | { |
| 773 | return mBindGeneratesResource; |
| 774 | } |
| 775 | |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 776 | bool State::areClientArraysEnabled() const |
| 777 | { |
| 778 | return mClientArraysEnabled; |
| 779 | } |
| 780 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 781 | void 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 Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 787 | mDirtyBits.set(DIRTY_BIT_VIEWPORT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | const Rectangle &State::getViewport() const |
| 791 | { |
| 792 | return mViewport; |
| 793 | } |
| 794 | |
| 795 | void State::setActiveSampler(unsigned int active) |
| 796 | { |
| 797 | mActiveSampler = active; |
| 798 | } |
| 799 | |
| 800 | unsigned int State::getActiveSampler() const |
| 801 | { |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 802 | return static_cast<unsigned int>(mActiveSampler); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 803 | } |
| 804 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 805 | void State::setSamplerTexture(const Context *context, GLenum type, Texture *texture) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 806 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 807 | mSamplerTextures[type][mActiveSampler].set(context, texture); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 808 | mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS); |
| 809 | mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 810 | } |
| 811 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 812 | Texture *State::getTargetTexture(GLenum target) const |
| 813 | { |
| 814 | return getSamplerTexture(static_cast<unsigned int>(mActiveSampler), target); |
| 815 | } |
| 816 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 817 | Texture *State::getSamplerTexture(unsigned int sampler, GLenum type) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 818 | { |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 819 | const auto it = mSamplerTextures.find(type); |
| 820 | ASSERT(it != mSamplerTextures.end()); |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 821 | ASSERT(sampler < it->second.size()); |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 822 | return it->second[sampler].get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 823 | } |
| 824 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 825 | GLuint State::getSamplerTextureId(unsigned int sampler, GLenum type) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 826 | { |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 827 | const auto it = mSamplerTextures.find(type); |
| 828 | ASSERT(it != mSamplerTextures.end()); |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 829 | ASSERT(sampler < it->second.size()); |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 830 | return it->second[sampler].id(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 831 | } |
| 832 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 833 | void State::detachTexture(const Context *context, const TextureMap &zeroTextures, GLuint texture) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 834 | { |
| 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 Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 844 | for (auto &bindingVec : mSamplerTextures) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 845 | { |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 846 | GLenum textureType = bindingVec.first; |
| 847 | TextureBindingVector &textureVector = bindingVec.second; |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 848 | for (BindingPointer<Texture> &binding : textureVector) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 849 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 850 | if (binding.id() == texture) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 851 | { |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 852 | auto it = zeroTextures.find(textureType); |
| 853 | ASSERT(it != zeroTextures.end()); |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 854 | // Zero textures are the "default" textures instead of NULL |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 855 | binding.set(context, it->second.get()); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 856 | mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 857 | } |
| 858 | } |
| 859 | } |
| 860 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 861 | 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 Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 875 | // [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 Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 880 | if (mReadFramebuffer && mReadFramebuffer->detachTexture(context, texture)) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 881 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 882 | mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 883 | } |
| 884 | |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 885 | if (mDrawFramebuffer && mDrawFramebuffer->detachTexture(context, texture)) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 886 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 887 | mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 888 | } |
| 889 | } |
| 890 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 891 | void State::initializeZeroTextures(const Context *context, const TextureMap &zeroTextures) |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 892 | { |
| 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 Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 899 | samplerTextureArray[textureUnit].set(context, zeroTexture.second.get()); |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 900 | } |
| 901 | } |
| 902 | } |
| 903 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 904 | void State::setSamplerBinding(const Context *context, GLuint textureUnit, Sampler *sampler) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 905 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 906 | mSamplers[textureUnit].set(context, sampler); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 907 | mDirtyBits.set(DIRTY_BIT_SAMPLER_BINDINGS); |
| 908 | mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | GLuint State::getSamplerId(GLuint textureUnit) const |
| 912 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 913 | ASSERT(textureUnit < mSamplers.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 914 | return mSamplers[textureUnit].id(); |
| 915 | } |
| 916 | |
| 917 | Sampler *State::getSampler(GLuint textureUnit) const |
| 918 | { |
| 919 | return mSamplers[textureUnit].get(); |
| 920 | } |
| 921 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 922 | void State::detachSampler(const Context *context, GLuint sampler) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 923 | { |
| 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 Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 928 | for (BindingPointer<Sampler> &samplerBinding : mSamplers) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 929 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 930 | if (samplerBinding.id() == sampler) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 931 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 932 | samplerBinding.set(context, nullptr); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 933 | mDirtyBits.set(DIRTY_BIT_SAMPLER_BINDINGS); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 934 | } |
| 935 | } |
| 936 | } |
| 937 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 938 | void State::setRenderbufferBinding(const Context *context, Renderbuffer *renderbuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 939 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 940 | mRenderbuffer.set(context, renderbuffer); |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 941 | mDirtyBits.set(DIRTY_BIT_RENDERBUFFER_BINDING); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | GLuint State::getRenderbufferId() const |
| 945 | { |
| 946 | return mRenderbuffer.id(); |
| 947 | } |
| 948 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 949 | Renderbuffer *State::getCurrentRenderbuffer() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 950 | { |
| 951 | return mRenderbuffer.get(); |
| 952 | } |
| 953 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 954 | void State::detachRenderbuffer(const Context *context, GLuint renderbuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 955 | { |
| 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 Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 962 | setRenderbufferBinding(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 963 | } |
| 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 Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 973 | if (readFramebuffer && readFramebuffer->detachRenderbuffer(context, renderbuffer)) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 974 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 975 | mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | if (drawFramebuffer && drawFramebuffer != readFramebuffer) |
| 979 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 980 | if (drawFramebuffer->detachRenderbuffer(context, renderbuffer)) |
| 981 | { |
| 982 | mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 983 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | } |
| 987 | |
| 988 | void State::setReadFramebufferBinding(Framebuffer *framebuffer) |
| 989 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 990 | if (mReadFramebuffer == framebuffer) |
| 991 | return; |
| 992 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 993 | mReadFramebuffer = framebuffer; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 994 | mDirtyBits.set(DIRTY_BIT_READ_FRAMEBUFFER_BINDING); |
| 995 | |
| 996 | if (mReadFramebuffer && mReadFramebuffer->hasAnyDirtyBit()) |
| 997 | { |
| 998 | mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 999 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | void State::setDrawFramebufferBinding(Framebuffer *framebuffer) |
| 1003 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1004 | if (mDrawFramebuffer == framebuffer) |
| 1005 | return; |
| 1006 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1007 | mDrawFramebuffer = framebuffer; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1008 | mDirtyBits.set(DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING); |
| 1009 | |
| 1010 | if (mDrawFramebuffer && mDrawFramebuffer->hasAnyDirtyBit()) |
| 1011 | { |
| 1012 | mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 1013 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | Framebuffer *State::getTargetFramebuffer(GLenum target) const |
| 1017 | { |
| 1018 | switch (target) |
| 1019 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1020 | 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 He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 1027 | return nullptr; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1028 | } |
| 1029 | } |
| 1030 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1031 | Framebuffer *State::getReadFramebuffer() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1032 | { |
| 1033 | return mReadFramebuffer; |
| 1034 | } |
| 1035 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1036 | Framebuffer *State::getDrawFramebuffer() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1037 | { |
| 1038 | return mDrawFramebuffer; |
| 1039 | } |
| 1040 | |
| 1041 | bool State::removeReadFramebufferBinding(GLuint framebuffer) |
| 1042 | { |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 1043 | if (mReadFramebuffer != nullptr && |
| 1044 | mReadFramebuffer->id() == framebuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1045 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1046 | setReadFramebufferBinding(nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1047 | return true; |
| 1048 | } |
| 1049 | |
| 1050 | return false; |
| 1051 | } |
| 1052 | |
| 1053 | bool State::removeDrawFramebufferBinding(GLuint framebuffer) |
| 1054 | { |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 1055 | if (mReadFramebuffer != nullptr && |
| 1056 | mDrawFramebuffer->id() == framebuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1057 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1058 | setDrawFramebufferBinding(nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1059 | return true; |
| 1060 | } |
| 1061 | |
| 1062 | return false; |
| 1063 | } |
| 1064 | |
| 1065 | void State::setVertexArrayBinding(VertexArray *vertexArray) |
| 1066 | { |
| 1067 | mVertexArray = vertexArray; |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1068 | mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1069 | |
| 1070 | if (mVertexArray && mVertexArray->hasAnyDirtyBit()) |
| 1071 | { |
| 1072 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1073 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | GLuint State::getVertexArrayId() const |
| 1077 | { |
Yunchao He | 4f28544 | 2017-04-21 12:15:49 +0800 | [diff] [blame] | 1078 | ASSERT(mVertexArray != nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1079 | return mVertexArray->id(); |
| 1080 | } |
| 1081 | |
| 1082 | VertexArray *State::getVertexArray() const |
| 1083 | { |
Yunchao He | 4f28544 | 2017-04-21 12:15:49 +0800 | [diff] [blame] | 1084 | ASSERT(mVertexArray != nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1085 | return mVertexArray; |
| 1086 | } |
| 1087 | |
| 1088 | bool State::removeVertexArrayBinding(GLuint vertexArray) |
| 1089 | { |
| 1090 | if (mVertexArray->id() == vertexArray) |
| 1091 | { |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 1092 | mVertexArray = nullptr; |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1093 | mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1094 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1095 | return true; |
| 1096 | } |
| 1097 | |
| 1098 | return false; |
| 1099 | } |
| 1100 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1101 | void State::setElementArrayBuffer(const Context *context, Buffer *buffer) |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1102 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1103 | getVertexArray()->setElementArrayBuffer(context, buffer); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1104 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1105 | } |
| 1106 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1107 | void State::bindVertexBuffer(const Context *context, |
| 1108 | GLuint bindingIndex, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1109 | Buffer *boundBuffer, |
| 1110 | GLintptr offset, |
| 1111 | GLsizei stride) |
| 1112 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1113 | getVertexArray()->bindVertexBuffer(context, bindingIndex, boundBuffer, offset, stride); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1114 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1115 | } |
| 1116 | |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 1117 | void State::setVertexAttribBinding(const Context *context, GLuint attribIndex, GLuint bindingIndex) |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1118 | { |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 1119 | getVertexArray()->setVertexAttribBinding(context, attribIndex, bindingIndex); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1120 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1121 | } |
| 1122 | |
| 1123 | void 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 | |
| 1135 | void State::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor) |
| 1136 | { |
| 1137 | getVertexArray()->setVertexBindingDivisor(bindingIndex, divisor); |
| 1138 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1139 | } |
| 1140 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 1141 | void State::setProgram(const Context *context, Program *newProgram) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1142 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1143 | if (mProgram != newProgram) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1144 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1145 | if (mProgram) |
| 1146 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 1147 | mProgram->release(context); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | mProgram = newProgram; |
| 1151 | |
| 1152 | if (mProgram) |
| 1153 | { |
| 1154 | newProgram->addRef(); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1155 | mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1156 | } |
Jamie Madill | a779b61 | 2017-07-24 11:46:05 -0400 | [diff] [blame] | 1157 | mDirtyBits.set(DIRTY_BIT_PROGRAM_EXECUTABLE); |
| 1158 | mDirtyBits.set(DIRTY_BIT_PROGRAM_BINDING); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1159 | } |
| 1160 | } |
| 1161 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1162 | Program *State::getProgram() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1163 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1164 | return mProgram; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1165 | } |
| 1166 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1167 | void State::setTransformFeedbackBinding(const Context *context, |
| 1168 | TransformFeedback *transformFeedback) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1169 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1170 | mTransformFeedback.set(context, transformFeedback); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | TransformFeedback *State::getCurrentTransformFeedback() const |
| 1174 | { |
| 1175 | return mTransformFeedback.get(); |
| 1176 | } |
| 1177 | |
Gregoire Payen de La Garanderie | 5274202 | 2015-02-04 14:55:39 +0000 | [diff] [blame] | 1178 | bool State::isTransformFeedbackActiveUnpaused() const |
| 1179 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1180 | TransformFeedback *curTransformFeedback = getCurrentTransformFeedback(); |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 1181 | return curTransformFeedback && curTransformFeedback->isActive() && !curTransformFeedback->isPaused(); |
Gregoire Payen de La Garanderie | 5274202 | 2015-02-04 14:55:39 +0000 | [diff] [blame] | 1182 | } |
| 1183 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1184 | bool State::removeTransformFeedbackBinding(const Context *context, GLuint transformFeedback) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1185 | { |
| 1186 | if (mTransformFeedback.id() == transformFeedback) |
| 1187 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1188 | mTransformFeedback.set(context, nullptr); |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 1189 | return true; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1190 | } |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 1191 | |
| 1192 | return false; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1193 | } |
| 1194 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 1195 | void State::setProgramPipelineBinding(const Context *context, ProgramPipeline *pipeline) |
| 1196 | { |
| 1197 | mProgramPipeline.set(context, pipeline); |
| 1198 | } |
| 1199 | |
| 1200 | void State::detachProgramPipeline(const Context *context, GLuint pipeline) |
| 1201 | { |
| 1202 | mProgramPipeline.set(context, nullptr); |
| 1203 | } |
| 1204 | |
Olli Etuaho | bbf1c10 | 2016-06-28 13:31:33 +0300 | [diff] [blame] | 1205 | bool State::isQueryActive(const GLenum type) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1206 | { |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1207 | for (auto &iter : mActiveQueries) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1208 | { |
Olli Etuaho | bbf1c10 | 2016-06-28 13:31:33 +0300 | [diff] [blame] | 1209 | const Query *query = iter.second.get(); |
| 1210 | if (query != nullptr && ActiveQueryType(query->getType()) == ActiveQueryType(type)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1211 | { |
| 1212 | return true; |
| 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | return false; |
| 1217 | } |
| 1218 | |
| 1219 | bool State::isQueryActive(Query *query) const |
| 1220 | { |
| 1221 | for (auto &iter : mActiveQueries) |
| 1222 | { |
| 1223 | if (iter.second.get() == query) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1224 | { |
| 1225 | return true; |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | return false; |
| 1230 | } |
| 1231 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1232 | void State::setActiveQuery(const Context *context, GLenum target, Query *query) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1233 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1234 | mActiveQueries[target].set(context, query); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | GLuint State::getActiveQueryId(GLenum target) const |
| 1238 | { |
| 1239 | const Query *query = getActiveQuery(target); |
| 1240 | return (query ? query->id() : 0u); |
| 1241 | } |
| 1242 | |
| 1243 | Query *State::getActiveQuery(GLenum target) const |
| 1244 | { |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 1245 | const auto it = mActiveQueries.find(target); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1246 | |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 1247 | // All query types should already exist in the activeQueries map |
| 1248 | ASSERT(it != mActiveQueries.end()); |
| 1249 | |
| 1250 | return it->second.get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1251 | } |
| 1252 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1253 | void State::setArrayBufferBinding(const Context *context, Buffer *buffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1254 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1255 | mArrayBuffer.set(context, buffer); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | GLuint State::getArrayBufferId() const |
| 1259 | { |
| 1260 | return mArrayBuffer.id(); |
| 1261 | } |
| 1262 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1263 | void State::setDrawIndirectBufferBinding(const Context *context, Buffer *buffer) |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1264 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1265 | mDrawIndirectBuffer.set(context, buffer); |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1266 | mDirtyBits.set(DIRTY_BIT_DRAW_INDIRECT_BUFFER_BINDING); |
| 1267 | } |
| 1268 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1269 | void State::setGenericUniformBufferBinding(const Context *context, Buffer *buffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1270 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1271 | mGenericUniformBuffer.set(context, buffer); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1272 | } |
| 1273 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1274 | void State::setIndexedUniformBufferBinding(const Context *context, |
| 1275 | GLuint index, |
| 1276 | Buffer *buffer, |
| 1277 | GLintptr offset, |
| 1278 | GLsizeiptr size) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1279 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1280 | mUniformBuffers[index].set(context, buffer, offset, size); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1281 | } |
| 1282 | |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 1283 | const OffsetBindingPointer<Buffer> &State::getIndexedUniformBuffer(size_t index) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1284 | { |
Shannon Woods | f3acaf9 | 2014-09-23 18:07:11 -0400 | [diff] [blame] | 1285 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 1286 | return mUniformBuffers[index]; |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1287 | } |
| 1288 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1289 | void State::setGenericAtomicCounterBufferBinding(const Context *context, Buffer *buffer) |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1290 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1291 | mGenericAtomicCounterBuffer.set(context, buffer); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1292 | } |
| 1293 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1294 | void State::setIndexedAtomicCounterBufferBinding(const Context *context, |
| 1295 | GLuint index, |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1296 | Buffer *buffer, |
| 1297 | GLintptr offset, |
| 1298 | GLsizeiptr size) |
| 1299 | { |
| 1300 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1301 | mAtomicCounterBuffers[index].set(context, buffer, offset, size); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | const 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 Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1310 | void State::setGenericShaderStorageBufferBinding(const Context *context, Buffer *buffer) |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1311 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1312 | mGenericShaderStorageBuffer.set(context, buffer); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1313 | } |
| 1314 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1315 | void State::setIndexedShaderStorageBufferBinding(const Context *context, |
| 1316 | GLuint index, |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1317 | Buffer *buffer, |
| 1318 | GLintptr offset, |
| 1319 | GLsizeiptr size) |
| 1320 | { |
| 1321 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1322 | mShaderStorageBuffers[index].set(context, buffer, offset, size); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | const 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 Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1331 | void State::setCopyReadBufferBinding(const Context *context, Buffer *buffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1332 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1333 | mCopyReadBuffer.set(context, buffer); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1334 | } |
| 1335 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1336 | void State::setCopyWriteBufferBinding(const Context *context, Buffer *buffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1337 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1338 | mCopyWriteBuffer.set(context, buffer); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1339 | } |
| 1340 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1341 | void State::setPixelPackBufferBinding(const Context *context, Buffer *buffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1342 | { |
Corentin Wallez | cda6af1 | 2017-10-30 19:20:37 -0400 | [diff] [blame^] | 1343 | mPixelPackBuffer.set(context, buffer); |
Corentin Wallez | 29a2099 | 2017-11-06 18:23:16 -0500 | [diff] [blame] | 1344 | mDirtyBits.set(DIRTY_BIT_PACK_BUFFER_BINDING); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1345 | } |
| 1346 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1347 | void State::setPixelUnpackBufferBinding(const Context *context, Buffer *buffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1348 | { |
Corentin Wallez | cda6af1 | 2017-10-30 19:20:37 -0400 | [diff] [blame^] | 1349 | mPixelUnpackBuffer.set(context, buffer); |
Corentin Wallez | 29a2099 | 2017-11-06 18:23:16 -0500 | [diff] [blame] | 1350 | mDirtyBits.set(DIRTY_BIT_UNPACK_BUFFER_BINDING); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | Buffer *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 Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 1360 | case GL_ELEMENT_ARRAY_BUFFER: return getVertexArray()->getElementArrayBuffer().get(); |
Corentin Wallez | cda6af1 | 2017-10-30 19:20:37 -0400 | [diff] [blame^] | 1361 | case GL_PIXEL_PACK_BUFFER: |
| 1362 | return mPixelPackBuffer.get(); |
| 1363 | case GL_PIXEL_UNPACK_BUFFER: |
| 1364 | return mPixelUnpackBuffer.get(); |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 1365 | case GL_TRANSFORM_FEEDBACK_BUFFER: return mTransformFeedback->getGenericBuffer().get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1366 | case GL_UNIFORM_BUFFER: return mGenericUniformBuffer.get(); |
Geoff Lang | b5e997f | 2016-12-06 10:55:34 -0500 | [diff] [blame] | 1367 | case GL_ATOMIC_COUNTER_BUFFER: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1368 | return mGenericAtomicCounterBuffer.get(); |
Geoff Lang | b5e997f | 2016-12-06 10:55:34 -0500 | [diff] [blame] | 1369 | case GL_SHADER_STORAGE_BUFFER: |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1370 | return mGenericShaderStorageBuffer.get(); |
Geoff Lang | b5e997f | 2016-12-06 10:55:34 -0500 | [diff] [blame] | 1371 | case GL_DRAW_INDIRECT_BUFFER: |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1372 | return mDrawIndirectBuffer.get(); |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 1373 | default: |
| 1374 | UNREACHABLE(); |
| 1375 | return nullptr; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1376 | } |
| 1377 | } |
| 1378 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1379 | void State::detachBuffer(const Context *context, GLuint bufferName) |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1380 | { |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1381 | BindingPointer<Buffer> *buffers[] = { |
Corentin Wallez | cda6af1 | 2017-10-30 19:20:37 -0400 | [diff] [blame^] | 1382 | &mArrayBuffer, &mGenericAtomicCounterBuffer, &mCopyReadBuffer, |
| 1383 | &mCopyWriteBuffer, &mDrawIndirectBuffer, &mPixelPackBuffer, |
| 1384 | &mPixelUnpackBuffer, &mGenericUniformBuffer, &mGenericShaderStorageBuffer}; |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1385 | for (auto buffer : buffers) |
| 1386 | { |
| 1387 | if (buffer->id() == bufferName) |
| 1388 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1389 | buffer->set(context, nullptr); |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | TransformFeedback *curTransformFeedback = getCurrentTransformFeedback(); |
| 1394 | if (curTransformFeedback) |
| 1395 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1396 | curTransformFeedback->detachBuffer(context, bufferName); |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1397 | } |
| 1398 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1399 | getVertexArray()->detachBuffer(context, bufferName); |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1400 | } |
| 1401 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1402 | void State::setEnableVertexAttribArray(unsigned int attribNum, bool enabled) |
| 1403 | { |
| 1404 | getVertexArray()->enableAttribute(attribNum, enabled); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1405 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | void State::setVertexAttribf(GLuint index, const GLfloat values[4]) |
| 1409 | { |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 1410 | ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1411 | mVertexAttribCurrentValues[index].setFloatValues(values); |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1412 | mDirtyBits.set(DIRTY_BIT_CURRENT_VALUES); |
| 1413 | mDirtyCurrentValues.set(index); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | void State::setVertexAttribu(GLuint index, const GLuint values[4]) |
| 1417 | { |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 1418 | ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1419 | mVertexAttribCurrentValues[index].setUnsignedIntValues(values); |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1420 | mDirtyBits.set(DIRTY_BIT_CURRENT_VALUES); |
| 1421 | mDirtyCurrentValues.set(index); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | void State::setVertexAttribi(GLuint index, const GLint values[4]) |
| 1425 | { |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 1426 | ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1427 | mVertexAttribCurrentValues[index].setIntValues(values); |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1428 | mDirtyBits.set(DIRTY_BIT_CURRENT_VALUES); |
| 1429 | mDirtyCurrentValues.set(index); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1430 | } |
| 1431 | |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 1432 | void 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 Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1441 | { |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 1442 | getVertexArray()->setVertexAttribPointer(context, attribNum, boundBuffer, size, type, |
| 1443 | normalized, pureInteger, stride, pointer); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1444 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1445 | } |
| 1446 | |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 1447 | void State::setVertexAttribDivisor(const Context *context, GLuint index, GLuint divisor) |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1448 | { |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 1449 | getVertexArray()->setVertexAttribDivisor(context, index, divisor); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1450 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1451 | } |
| 1452 | |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 1453 | const VertexAttribCurrentValueData &State::getVertexAttribCurrentValue(size_t attribNum) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1454 | { |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 1455 | ASSERT(attribNum < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1456 | return mVertexAttribCurrentValues[attribNum]; |
| 1457 | } |
| 1458 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1459 | const void *State::getVertexAttribPointer(unsigned int attribNum) const |
| 1460 | { |
| 1461 | return getVertexArray()->getVertexAttribute(attribNum).pointer; |
| 1462 | } |
| 1463 | |
| 1464 | void State::setPackAlignment(GLint alignment) |
| 1465 | { |
| 1466 | mPack.alignment = alignment; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1467 | mDirtyBits.set(DIRTY_BIT_PACK_STATE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | GLint State::getPackAlignment() const |
| 1471 | { |
| 1472 | return mPack.alignment; |
| 1473 | } |
| 1474 | |
| 1475 | void State::setPackReverseRowOrder(bool reverseRowOrder) |
| 1476 | { |
| 1477 | mPack.reverseRowOrder = reverseRowOrder; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1478 | mDirtyBits.set(DIRTY_BIT_PACK_STATE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | bool State::getPackReverseRowOrder() const |
| 1482 | { |
| 1483 | return mPack.reverseRowOrder; |
| 1484 | } |
| 1485 | |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1486 | void State::setPackRowLength(GLint rowLength) |
| 1487 | { |
| 1488 | mPack.rowLength = rowLength; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1489 | mDirtyBits.set(DIRTY_BIT_PACK_STATE); |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1490 | } |
| 1491 | |
| 1492 | GLint State::getPackRowLength() const |
| 1493 | { |
| 1494 | return mPack.rowLength; |
| 1495 | } |
| 1496 | |
| 1497 | void State::setPackSkipRows(GLint skipRows) |
| 1498 | { |
| 1499 | mPack.skipRows = skipRows; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1500 | mDirtyBits.set(DIRTY_BIT_PACK_STATE); |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | GLint State::getPackSkipRows() const |
| 1504 | { |
| 1505 | return mPack.skipRows; |
| 1506 | } |
| 1507 | |
| 1508 | void State::setPackSkipPixels(GLint skipPixels) |
| 1509 | { |
| 1510 | mPack.skipPixels = skipPixels; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1511 | mDirtyBits.set(DIRTY_BIT_PACK_STATE); |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | GLint State::getPackSkipPixels() const |
| 1515 | { |
| 1516 | return mPack.skipPixels; |
| 1517 | } |
| 1518 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1519 | const PixelPackState &State::getPackState() const |
| 1520 | { |
| 1521 | return mPack; |
| 1522 | } |
| 1523 | |
Jamie Madill | 87de362 | 2015-03-16 10:41:44 -0400 | [diff] [blame] | 1524 | PixelPackState &State::getPackState() |
| 1525 | { |
| 1526 | return mPack; |
| 1527 | } |
| 1528 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1529 | void State::setUnpackAlignment(GLint alignment) |
| 1530 | { |
| 1531 | mUnpack.alignment = alignment; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1532 | mDirtyBits.set(DIRTY_BIT_UNPACK_STATE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | GLint State::getUnpackAlignment() const |
| 1536 | { |
| 1537 | return mUnpack.alignment; |
| 1538 | } |
| 1539 | |
Minmin Gong | b8aee3b | 2015-01-27 14:42:36 -0800 | [diff] [blame] | 1540 | void State::setUnpackRowLength(GLint rowLength) |
| 1541 | { |
| 1542 | mUnpack.rowLength = rowLength; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1543 | mDirtyBits.set(DIRTY_BIT_UNPACK_STATE); |
Minmin Gong | b8aee3b | 2015-01-27 14:42:36 -0800 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | GLint State::getUnpackRowLength() const |
| 1547 | { |
| 1548 | return mUnpack.rowLength; |
| 1549 | } |
| 1550 | |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1551 | void State::setUnpackImageHeight(GLint imageHeight) |
| 1552 | { |
| 1553 | mUnpack.imageHeight = imageHeight; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1554 | mDirtyBits.set(DIRTY_BIT_UNPACK_STATE); |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | GLint State::getUnpackImageHeight() const |
| 1558 | { |
| 1559 | return mUnpack.imageHeight; |
| 1560 | } |
| 1561 | |
| 1562 | void State::setUnpackSkipImages(GLint skipImages) |
| 1563 | { |
| 1564 | mUnpack.skipImages = skipImages; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1565 | mDirtyBits.set(DIRTY_BIT_UNPACK_STATE); |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | GLint State::getUnpackSkipImages() const |
| 1569 | { |
| 1570 | return mUnpack.skipImages; |
| 1571 | } |
| 1572 | |
| 1573 | void State::setUnpackSkipRows(GLint skipRows) |
| 1574 | { |
| 1575 | mUnpack.skipRows = skipRows; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1576 | mDirtyBits.set(DIRTY_BIT_UNPACK_STATE); |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | GLint State::getUnpackSkipRows() const |
| 1580 | { |
| 1581 | return mUnpack.skipRows; |
| 1582 | } |
| 1583 | |
| 1584 | void State::setUnpackSkipPixels(GLint skipPixels) |
| 1585 | { |
| 1586 | mUnpack.skipPixels = skipPixels; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1587 | mDirtyBits.set(DIRTY_BIT_UNPACK_STATE); |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | GLint State::getUnpackSkipPixels() const |
| 1591 | { |
| 1592 | return mUnpack.skipPixels; |
| 1593 | } |
| 1594 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1595 | const PixelUnpackState &State::getUnpackState() const |
| 1596 | { |
| 1597 | return mUnpack; |
| 1598 | } |
| 1599 | |
Jamie Madill | 67102f0 | 2015-03-16 10:41:42 -0400 | [diff] [blame] | 1600 | PixelUnpackState &State::getUnpackState() |
| 1601 | { |
| 1602 | return mUnpack; |
| 1603 | } |
| 1604 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1605 | const Debug &State::getDebug() const |
| 1606 | { |
| 1607 | return mDebug; |
| 1608 | } |
| 1609 | |
| 1610 | Debug &State::getDebug() |
| 1611 | { |
| 1612 | return mDebug; |
| 1613 | } |
| 1614 | |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 1615 | void State::setCoverageModulation(GLenum components) |
| 1616 | { |
| 1617 | mCoverageModulation = components; |
| 1618 | mDirtyBits.set(DIRTY_BIT_COVERAGE_MODULATION); |
| 1619 | } |
| 1620 | |
| 1621 | GLenum State::getCoverageModulation() const |
| 1622 | { |
| 1623 | return mCoverageModulation; |
| 1624 | } |
| 1625 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1626 | void 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 | |
| 1644 | const 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 | |
| 1659 | void 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 | |
| 1667 | GLenum State::getPathStencilFunc() const |
| 1668 | { |
| 1669 | return mPathStencilFunc; |
| 1670 | } |
| 1671 | |
| 1672 | GLint State::getPathStencilRef() const |
| 1673 | { |
| 1674 | return mPathStencilRef; |
| 1675 | } |
| 1676 | |
| 1677 | GLuint State::getPathStencilMask() const |
| 1678 | { |
| 1679 | return mPathStencilMask; |
| 1680 | } |
| 1681 | |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 1682 | void State::setFramebufferSRGB(bool sRGB) |
| 1683 | { |
| 1684 | mFramebufferSRGB = sRGB; |
| 1685 | mDirtyBits.set(DIRTY_BIT_FRAMEBUFFER_SRGB); |
| 1686 | } |
| 1687 | |
| 1688 | bool State::getFramebufferSRGB() const |
| 1689 | { |
| 1690 | return mFramebufferSRGB; |
| 1691 | } |
| 1692 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1693 | void 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 Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 1705 | case GL_CULL_FACE: |
| 1706 | *params = mRasterizer.cullFace; |
| 1707 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1708 | 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 Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame] | 1711 | case GL_SAMPLE_MASK: |
| 1712 | *params = mSampleMask; |
| 1713 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1714 | 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 Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 1719 | 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 Madill | e2cd53d | 2015-10-27 11:15:46 -0400 | [diff] [blame] | 1721 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: |
| 1722 | *params = mPrimitiveRestart; |
| 1723 | break; |
Geoff Lang | ab831f0 | 2015-12-01 09:39:10 -0500 | [diff] [blame] | 1724 | case GL_RASTERIZER_DISCARD: |
| 1725 | *params = isRasterizerDiscardEnabled() ? GL_TRUE : GL_FALSE; |
| 1726 | break; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1727 | 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änen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 1733 | case GL_MULTISAMPLE_EXT: |
| 1734 | *params = mMultiSampling; |
| 1735 | break; |
| 1736 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 1737 | *params = mSampleAlphaToOne; |
| 1738 | break; |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 1739 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 1740 | *params = isBindGeneratesResourceEnabled() ? GL_TRUE : GL_FALSE; |
| 1741 | break; |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 1742 | case GL_CLIENT_ARRAYS_ANGLE: |
| 1743 | *params = areClientArraysEnabled() ? GL_TRUE : GL_FALSE; |
| 1744 | break; |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 1745 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 1746 | *params = getFramebufferSRGB() ? GL_TRUE : GL_FALSE; |
| 1747 | break; |
Geoff Lang | b433e87 | 2017-10-05 14:01:47 -0400 | [diff] [blame] | 1748 | case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE: |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 1749 | *params = mRobustResourceInit ? GL_TRUE : GL_FALSE; |
| 1750 | break; |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 1751 | case GL_PROGRAM_CACHE_ENABLED_ANGLE: |
| 1752 | *params = mProgramBinaryCacheEnabled ? GL_TRUE : GL_FALSE; |
| 1753 | break; |
| 1754 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1755 | default: |
| 1756 | UNREACHABLE(); |
| 1757 | break; |
| 1758 | } |
| 1759 | } |
| 1760 | |
| 1761 | void 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änen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 1790 | 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änen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 1795 | case GL_COVERAGE_MODULATION_CHROMIUM: |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1796 | params[0] = static_cast<GLfloat>(mCoverageModulation); |
| 1797 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1798 | default: |
| 1799 | UNREACHABLE(); |
| 1800 | break; |
| 1801 | } |
| 1802 | } |
| 1803 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1804 | void State::getIntegerv(const Context *context, GLenum pname, GLint *params) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1805 | { |
| 1806 | if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT) |
| 1807 | { |
| 1808 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0_EXT); |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1809 | ASSERT(colorAttachment < mMaxDrawBuffers); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1810 | 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 Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1823 | case GL_DRAW_INDIRECT_BUFFER_BINDING: |
| 1824 | *params = mDrawIndirectBuffer.id(); |
| 1825 | break; |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 1826 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: *params = getVertexArray()->getElementArrayBuffer().id(); break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1827 | //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 Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1832 | case GL_CURRENT_PROGRAM: *params = mProgram ? mProgram->id() : 0; break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1833 | case GL_PACK_ALIGNMENT: *params = mPack.alignment; break; |
| 1834 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: *params = mPack.reverseRowOrder; break; |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1835 | 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 Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1844 | case GL_UNPACK_ALIGNMENT: *params = mUnpack.alignment; break; |
Minmin Gong | b8aee3b | 2015-01-27 14:42:36 -0800 | [diff] [blame] | 1845 | case GL_UNPACK_ROW_LENGTH: *params = mUnpack.rowLength; break; |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1846 | 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 Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1858 | case GL_GENERATE_MIPMAP_HINT: *params = mGenerateMipmapHint; break; |
| 1859 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: *params = mFragmentShaderDerivativeHint; break; |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1860 | case GL_ACTIVE_TEXTURE: |
| 1861 | *params = (static_cast<GLint>(mActiveSampler) + GL_TEXTURE0); |
| 1862 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1863 | case GL_STENCIL_FUNC: *params = mDepthStencil.stencilFunc; break; |
| 1864 | case GL_STENCIL_REF: *params = mStencilRef; break; |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 1865 | case GL_STENCIL_VALUE_MASK: |
| 1866 | *params = CastMaskValue(context, mDepthStencil.stencilMask); |
| 1867 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1868 | case GL_STENCIL_BACK_FUNC: *params = mDepthStencil.stencilBackFunc; break; |
| 1869 | case GL_STENCIL_BACK_REF: *params = mStencilBackRef; break; |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 1870 | case GL_STENCIL_BACK_VALUE_MASK: |
| 1871 | *params = CastMaskValue(context, mDepthStencil.stencilBackMask); |
| 1872 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1873 | 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; |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 1886 | 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 Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1892 | case GL_STENCIL_CLEAR_VALUE: *params = mStencilClearValue; break; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1893 | 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 Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1899 | case GL_SAMPLE_BUFFERS: |
| 1900 | case GL_SAMPLES: |
| 1901 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1902 | Framebuffer *framebuffer = mDrawFramebuffer; |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1903 | if (framebuffer->checkStatus(context) == GL_FRAMEBUFFER_COMPLETE) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1904 | { |
| 1905 | switch (pname) |
| 1906 | { |
Jamie Madill | a0016b7 | 2017-07-14 14:30:46 -0400 | [diff] [blame] | 1907 | 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 Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1920 | } |
| 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 Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 1940 | case GL_CULL_FACE_MODE: |
| 1941 | *params = ToGLenum(mRasterizer.cullMode); |
| 1942 | break; |
| 1943 | case GL_FRONT_FACE: |
| 1944 | *params = mRasterizer.frontFace; |
| 1945 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1946 | case GL_RED_BITS: |
| 1947 | case GL_GREEN_BITS: |
| 1948 | case GL_BLUE_BITS: |
| 1949 | case GL_ALPHA_BITS: |
| 1950 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1951 | Framebuffer *framebuffer = getDrawFramebuffer(); |
| 1952 | const FramebufferAttachment *colorbuffer = framebuffer->getFirstColorbuffer(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1953 | |
| 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 Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1972 | const Framebuffer *framebuffer = getDrawFramebuffer(); |
| 1973 | const FramebufferAttachment *depthbuffer = framebuffer->getDepthbuffer(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1974 | |
| 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 Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1987 | const Framebuffer *framebuffer = getDrawFramebuffer(); |
| 1988 | const FramebufferAttachment *stencilbuffer = framebuffer->getStencilbuffer(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1989 | |
| 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 Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 2001 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 2002 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_2D); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2003 | break; |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2004 | 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 Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2009 | case GL_TEXTURE_BINDING_CUBE_MAP: |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 2010 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 2011 | *params = |
| 2012 | getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_CUBE_MAP); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2013 | break; |
| 2014 | case GL_TEXTURE_BINDING_3D: |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 2015 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 2016 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_3D); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2017 | break; |
| 2018 | case GL_TEXTURE_BINDING_2D_ARRAY: |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 2019 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 2020 | *params = |
| 2021 | getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_2D_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2022 | break; |
JiangYizhou | 24fe74c | 2017-07-06 16:56:50 +0800 | [diff] [blame] | 2023 | 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 Bauman | 1831918 | 2016-09-28 14:22:27 -0700 | [diff] [blame] | 2028 | 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 Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2033 | case GL_UNIFORM_BUFFER_BINDING: |
| 2034 | *params = mGenericUniformBuffer.id(); |
| 2035 | break; |
Frank Henigman | 22581ff | 2015-11-06 14:25:54 -0500 | [diff] [blame] | 2036 | case GL_TRANSFORM_FEEDBACK_BINDING: |
Frank Henigman | b0f0b81 | 2015-11-21 17:49:29 -0500 | [diff] [blame] | 2037 | *params = mTransformFeedback.id(); |
Frank Henigman | 22581ff | 2015-11-06 14:25:54 -0500 | [diff] [blame] | 2038 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2039 | case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 2040 | *params = mTransformFeedback->getGenericBuffer().id(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2041 | 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 Wallez | cda6af1 | 2017-10-30 19:20:37 -0400 | [diff] [blame^] | 2049 | *params = mPixelPackBuffer.id(); |
| 2050 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2051 | case GL_PIXEL_UNPACK_BUFFER_BINDING: |
Corentin Wallez | cda6af1 | 2017-10-30 19:20:37 -0400 | [diff] [blame^] | 2052 | *params = mPixelUnpackBuffer.id(); |
| 2053 | break; |
Olli Etuaho | 86821db | 2016-03-04 12:05:47 +0200 | [diff] [blame] | 2054 | 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 Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2061 | 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änen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 2070 | 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änen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 2075 | case GL_COVERAGE_MODULATION_CHROMIUM: |
| 2076 | *params = static_cast<GLint>(mCoverageModulation); |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 2077 | break; |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2078 | case GL_ATOMIC_COUNTER_BUFFER_BINDING: |
| 2079 | *params = mGenericAtomicCounterBuffer.id(); |
| 2080 | break; |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 2081 | case GL_SHADER_STORAGE_BUFFER_BINDING: |
| 2082 | *params = mGenericShaderStorageBuffer.id(); |
| 2083 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2084 | default: |
| 2085 | UNREACHABLE(); |
| 2086 | break; |
| 2087 | } |
| 2088 | } |
| 2089 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2090 | void 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 Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2106 | void State::getIntegeri_v(GLenum target, GLuint index, GLint *data) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2107 | { |
| 2108 | switch (target) |
| 2109 | { |
| 2110 | case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2111 | ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount()); |
| 2112 | *data = mTransformFeedback->getIndexedBuffer(index).id(); |
| 2113 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2114 | case GL_UNIFORM_BUFFER_BINDING: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2115 | 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 Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 2122 | case GL_SHADER_STORAGE_BUFFER_BINDING: |
| 2123 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
| 2124 | *data = mShaderStorageBuffers[index].id(); |
| 2125 | break; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2126 | case GL_VERTEX_BINDING_BUFFER: |
| 2127 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 2128 | *data = mVertexArray->getVertexBinding(index).getBuffer().id(); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2129 | break; |
| 2130 | case GL_VERTEX_BINDING_DIVISOR: |
| 2131 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 2132 | *data = mVertexArray->getVertexBinding(index).getDivisor(); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2133 | break; |
| 2134 | case GL_VERTEX_BINDING_OFFSET: |
| 2135 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 2136 | *data = static_cast<GLuint>(mVertexArray->getVertexBinding(index).getOffset()); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2137 | break; |
| 2138 | case GL_VERTEX_BINDING_STRIDE: |
| 2139 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 2140 | *data = mVertexArray->getVertexBinding(index).getStride(); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2141 | break; |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame] | 2142 | case GL_SAMPLE_MASK_VALUE: |
| 2143 | ASSERT(static_cast<size_t>(index) < mSampleMaskValues.size()); |
| 2144 | *data = mSampleMaskValues[index]; |
| 2145 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2146 | default: |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2147 | UNREACHABLE(); |
| 2148 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2149 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2150 | } |
| 2151 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2152 | void State::getInteger64i_v(GLenum target, GLuint index, GLint64 *data) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2153 | { |
| 2154 | switch (target) |
| 2155 | { |
| 2156 | case GL_TRANSFORM_FEEDBACK_BUFFER_START: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2157 | ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount()); |
| 2158 | *data = mTransformFeedback->getIndexedBuffer(index).getOffset(); |
| 2159 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2160 | case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2161 | ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount()); |
| 2162 | *data = mTransformFeedback->getIndexedBuffer(index).getSize(); |
| 2163 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2164 | case GL_UNIFORM_BUFFER_START: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2165 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
| 2166 | *data = mUniformBuffers[index].getOffset(); |
| 2167 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2168 | case GL_UNIFORM_BUFFER_SIZE: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2169 | 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 Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 2180 | 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 Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2188 | default: |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2189 | UNREACHABLE(); |
| 2190 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2191 | } |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2192 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2193 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2194 | void State::getBooleani_v(GLenum target, GLuint index, GLboolean *data) |
| 2195 | { |
| 2196 | UNREACHABLE(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2197 | } |
| 2198 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2199 | bool State::hasMappedBuffer(GLenum target) const |
| 2200 | { |
| 2201 | if (target == GL_ARRAY_BUFFER) |
| 2202 | { |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 2203 | const VertexArray *vao = getVertexArray(); |
Jamie Madill | eea3a6e | 2015-04-15 10:02:48 -0400 | [diff] [blame] | 2204 | const auto &vertexAttribs = vao->getVertexAttributes(); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 2205 | const auto &vertexBindings = vao->getVertexBindings(); |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 2206 | size_t maxEnabledAttrib = vao->getMaxEnabledAttribute(); |
Jamie Madill | aebf9dd | 2015-04-28 12:39:07 -0400 | [diff] [blame] | 2207 | for (size_t attribIndex = 0; attribIndex < maxEnabledAttrib; attribIndex++) |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2208 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2209 | const VertexAttribute &vertexAttrib = vertexAttribs[attribIndex]; |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 2210 | auto *boundBuffer = vertexBindings[vertexAttrib.bindingIndex].getBuffer().get(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2211 | 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 Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2226 | void State::syncDirtyObjects(const Context *context) |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2227 | { |
| 2228 | if (!mDirtyObjects.any()) |
| 2229 | return; |
| 2230 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2231 | syncDirtyObjects(context, mDirtyObjects); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2232 | } |
| 2233 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2234 | void State::syncDirtyObjects(const Context *context, const DirtyObjects &bitset) |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2235 | { |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 2236 | for (auto dirtyObject : bitset) |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2237 | { |
| 2238 | switch (dirtyObject) |
| 2239 | { |
| 2240 | case DIRTY_OBJECT_READ_FRAMEBUFFER: |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2241 | ASSERT(mReadFramebuffer); |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2242 | mReadFramebuffer->syncState(context); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2243 | break; |
| 2244 | case DIRTY_OBJECT_DRAW_FRAMEBUFFER: |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2245 | ASSERT(mDrawFramebuffer); |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2246 | mDrawFramebuffer->syncState(context); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2247 | break; |
| 2248 | case DIRTY_OBJECT_VERTEX_ARRAY: |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2249 | ASSERT(mVertexArray); |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2250 | mVertexArray->syncState(context); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2251 | break; |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2252 | case DIRTY_OBJECT_PROGRAM_TEXTURES: |
| 2253 | syncProgramTextures(context); |
| 2254 | break; |
| 2255 | |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2256 | default: |
| 2257 | UNREACHABLE(); |
| 2258 | break; |
| 2259 | } |
| 2260 | } |
| 2261 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2262 | mDirtyObjects &= ~bitset; |
| 2263 | } |
| 2264 | |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2265 | void State::syncProgramTextures(const Context *context) |
| 2266 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2267 | // 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 Madill | 0f80ed8 | 2017-09-19 00:24:56 -0400 | [diff] [blame] | 2276 | ActiveTextureMask newActiveTextures; |
| 2277 | |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2278 | 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 Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2287 | Sampler *sampler = getSampler(textureUnitIndex); |
Jamie Madill | 0f80ed8 | 2017-09-19 00:24:56 -0400 | [diff] [blame] | 2288 | ASSERT(static_cast<size_t>(textureUnitIndex) < mCompleteTextureCache.size()); |
| 2289 | ASSERT(static_cast<size_t>(textureUnitIndex) < newActiveTextures.size()); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2290 | |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 2291 | ASSERT(texture); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2292 | |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 2293 | // 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 Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2300 | } |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 2301 | 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 Madill | a59fc19 | 2017-11-02 12:57:58 -0400 | [diff] [blame] | 2308 | mActiveTexturesMask.set(textureUnitIndex); |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 2309 | newActiveTextures.set(textureUnitIndex); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2310 | |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2311 | if (sampler != nullptr) |
| 2312 | { |
| 2313 | sampler->syncState(context); |
| 2314 | } |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2315 | } |
| 2316 | } |
Jamie Madill | 0f80ed8 | 2017-09-19 00:24:56 -0400 | [diff] [blame] | 2317 | |
| 2318 | // Unset now missing textures. |
Jamie Madill | a59fc19 | 2017-11-02 12:57:58 -0400 | [diff] [blame] | 2319 | ActiveTextureMask negativeMask = mActiveTexturesMask & ~newActiveTextures; |
Jamie Madill | 0f80ed8 | 2017-09-19 00:24:56 -0400 | [diff] [blame] | 2320 | if (negativeMask.any()) |
| 2321 | { |
| 2322 | for (auto textureIndex : negativeMask) |
| 2323 | { |
| 2324 | mCompleteTextureBindings[textureIndex].reset(); |
| 2325 | mCompleteTextureCache[textureIndex] = nullptr; |
Jamie Madill | a59fc19 | 2017-11-02 12:57:58 -0400 | [diff] [blame] | 2326 | mActiveTexturesMask.reset(textureIndex); |
Jamie Madill | 0f80ed8 | 2017-09-19 00:24:56 -0400 | [diff] [blame] | 2327 | } |
| 2328 | } |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2329 | } |
| 2330 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2331 | void State::syncDirtyObject(const Context *context, GLenum target) |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2332 | { |
| 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 Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2350 | case GL_TEXTURE: |
| 2351 | case GL_SAMPLER: |
| 2352 | case GL_PROGRAM: |
| 2353 | localSet.set(DIRTY_OBJECT_PROGRAM_TEXTURES); |
| 2354 | break; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2355 | } |
| 2356 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2357 | syncDirtyObjects(context, localSet); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | void 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 Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2377 | case GL_TEXTURE: |
| 2378 | case GL_SAMPLER: |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2379 | case GL_PROGRAM: |
| 2380 | mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES); |
| 2381 | mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS); |
| 2382 | break; |
Jamie Madill | a779b61 | 2017-07-24 11:46:05 -0400 | [diff] [blame] | 2383 | } |
| 2384 | } |
| 2385 | |
| 2386 | void 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 Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2395 | mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2396 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2397 | } |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2398 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 2399 | void 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 | |
| 2416 | const ImageUnit &State::getImageUnit(GLuint unit) const |
| 2417 | { |
| 2418 | return mImageUnits[unit]; |
| 2419 | } |
| 2420 | |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2421 | // Handle a dirty texture event. |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2422 | void State::signal(size_t textureIndex, InitState initState) |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2423 | { |
| 2424 | // Conservatively assume all textures are dirty. |
| 2425 | // TODO(jmadill): More fine-grained update. |
| 2426 | mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES); |
| 2427 | } |
| 2428 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2429 | Error State::clearUnclearedActiveTextures(const Context *context) |
| 2430 | { |
Jamie Madill | a59fc19 | 2017-11-02 12:57:58 -0400 | [diff] [blame] | 2431 | ASSERT(mRobustResourceInit); |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2432 | |
Jamie Madill | a59fc19 | 2017-11-02 12:57:58 -0400 | [diff] [blame] | 2433 | for (auto textureIndex : mActiveTexturesMask) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2434 | { |
Jamie Madill | a59fc19 | 2017-11-02 12:57:58 -0400 | [diff] [blame] | 2435 | Texture *texture = mCompleteTextureCache[textureIndex]; |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2436 | if (texture) |
| 2437 | { |
| 2438 | ANGLE_TRY(texture->ensureInitialized(context)); |
| 2439 | } |
| 2440 | } |
Jamie Madill | a59fc19 | 2017-11-02 12:57:58 -0400 | [diff] [blame] | 2441 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2442 | return NoError(); |
| 2443 | } |
| 2444 | |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 2445 | AttributesMask State::getAndResetDirtyCurrentValues() const |
| 2446 | { |
| 2447 | AttributesMask retVal = mDirtyCurrentValues; |
| 2448 | mDirtyCurrentValues.reset(); |
| 2449 | return retVal; |
| 2450 | } |
| 2451 | |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2452 | } // namespace gl |