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/matrix_utils.h" |
| 16 | #include "common/mathutil.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 17 | #include "libANGLE/Context.h" |
| 18 | #include "libANGLE/Caps.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" |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 25 | |
Olli Etuaho | bbf1c10 | 2016-06-28 13:31:33 +0300 | [diff] [blame] | 26 | namespace |
| 27 | { |
| 28 | |
| 29 | GLenum ActiveQueryType(const GLenum type) |
| 30 | { |
| 31 | return (type == GL_ANY_SAMPLES_PASSED_CONSERVATIVE) ? GL_ANY_SAMPLES_PASSED : type; |
| 32 | } |
| 33 | |
| 34 | } // anonymous namepace |
| 35 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 36 | namespace gl |
| 37 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 38 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 39 | State::State() |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 40 | : mMaxDrawBuffers(0), |
| 41 | mMaxCombinedTextureImageUnits(0), |
| 42 | mDepthClearValue(0), |
| 43 | mStencilClearValue(0), |
| 44 | mScissorTest(false), |
| 45 | mSampleCoverage(false), |
| 46 | mSampleCoverageValue(0), |
| 47 | mSampleCoverageInvert(false), |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame^] | 48 | mSampleMask(false), |
| 49 | mMaxSampleMaskWords(0), |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 50 | mStencilRef(0), |
| 51 | mStencilBackRef(0), |
| 52 | mLineWidth(0), |
| 53 | mGenerateMipmapHint(GL_NONE), |
| 54 | mFragmentShaderDerivativeHint(GL_NONE), |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 55 | mBindGeneratesResource(true), |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 56 | mClientArraysEnabled(true), |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 57 | mNearZ(0), |
| 58 | mFarZ(0), |
| 59 | mReadFramebuffer(nullptr), |
| 60 | mDrawFramebuffer(nullptr), |
| 61 | mProgram(nullptr), |
| 62 | mVertexArray(nullptr), |
| 63 | mActiveSampler(0), |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 64 | mPrimitiveRestart(false), |
| 65 | mMultiSampling(false), |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 66 | mSampleAlphaToOne(false), |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 67 | mFramebufferSRGB(true), |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 68 | mRobustResourceInit(false), |
| 69 | mProgramBinaryCacheEnabled(false) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 70 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | State::~State() |
| 74 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 75 | } |
| 76 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 77 | void State::initialize(const Context *context, |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 78 | bool debug, |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 79 | bool bindGeneratesResource, |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 80 | bool clientArraysEnabled, |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 81 | bool robustResourceInit, |
| 82 | bool programBinaryCacheEnabled) |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 83 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 84 | const Caps &caps = context->getCaps(); |
| 85 | const Extensions &extensions = context->getExtensions(); |
| 86 | const Version &clientVersion = context->getClientVersion(); |
| 87 | |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 88 | mMaxDrawBuffers = caps.maxDrawBuffers; |
| 89 | mMaxCombinedTextureImageUnits = caps.maxCombinedTextureImageUnits; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 90 | |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 91 | setColorClearValue(0.0f, 0.0f, 0.0f, 0.0f); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 92 | |
| 93 | mDepthClearValue = 1.0f; |
| 94 | mStencilClearValue = 0; |
| 95 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 96 | mScissorTest = false; |
| 97 | mScissor.x = 0; |
| 98 | mScissor.y = 0; |
| 99 | mScissor.width = 0; |
| 100 | mScissor.height = 0; |
| 101 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 102 | mBlendColor.red = 0; |
| 103 | mBlendColor.green = 0; |
| 104 | mBlendColor.blue = 0; |
| 105 | mBlendColor.alpha = 0; |
| 106 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 107 | mStencilRef = 0; |
| 108 | mStencilBackRef = 0; |
| 109 | |
| 110 | mSampleCoverage = false; |
| 111 | mSampleCoverageValue = 1.0f; |
| 112 | mSampleCoverageInvert = false; |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame^] | 113 | |
| 114 | mMaxSampleMaskWords = caps.maxSampleMaskWords; |
| 115 | mSampleMask = false; |
| 116 | mSampleMaskValues.fill(~GLbitfield(0)); |
| 117 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 118 | mGenerateMipmapHint = GL_DONT_CARE; |
| 119 | mFragmentShaderDerivativeHint = GL_DONT_CARE; |
| 120 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 121 | mBindGeneratesResource = bindGeneratesResource; |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 122 | mClientArraysEnabled = clientArraysEnabled; |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 123 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 124 | mLineWidth = 1.0f; |
| 125 | |
| 126 | mViewport.x = 0; |
| 127 | mViewport.y = 0; |
| 128 | mViewport.width = 0; |
| 129 | mViewport.height = 0; |
| 130 | mNearZ = 0.0f; |
| 131 | mFarZ = 1.0f; |
| 132 | |
| 133 | mBlend.colorMaskRed = true; |
| 134 | mBlend.colorMaskGreen = true; |
| 135 | mBlend.colorMaskBlue = true; |
| 136 | mBlend.colorMaskAlpha = true; |
| 137 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 138 | mActiveSampler = 0; |
| 139 | |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 140 | mVertexAttribCurrentValues.resize(caps.maxVertexAttributes); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 141 | |
Geoff Lang | 4dc3af0 | 2016-11-18 14:09:27 -0500 | [diff] [blame] | 142 | mUniformBuffers.resize(caps.maxUniformBufferBindings); |
Shannon Woods | f3acaf9 | 2014-09-23 18:07:11 -0400 | [diff] [blame] | 143 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 144 | mSamplerTextures[GL_TEXTURE_2D].resize(caps.maxCombinedTextureImageUnits); |
| 145 | mSamplerTextures[GL_TEXTURE_CUBE_MAP].resize(caps.maxCombinedTextureImageUnits); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 146 | if (clientVersion >= Version(3, 0)) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 147 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 148 | // TODO: These could also be enabled via extension |
| 149 | mSamplerTextures[GL_TEXTURE_2D_ARRAY].resize(caps.maxCombinedTextureImageUnits); |
| 150 | mSamplerTextures[GL_TEXTURE_3D].resize(caps.maxCombinedTextureImageUnits); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 151 | } |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 152 | if (clientVersion >= Version(3, 1)) |
| 153 | { |
| 154 | mSamplerTextures[GL_TEXTURE_2D_MULTISAMPLE].resize(caps.maxCombinedTextureImageUnits); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 155 | |
| 156 | mAtomicCounterBuffers.resize(caps.maxAtomicCounterBufferBindings); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 157 | mShaderStorageBuffers.resize(caps.maxShaderStorageBufferBindings); |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 158 | mImageUnits.resize(caps.maxImageUnits); |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 159 | } |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 160 | if (extensions.textureRectangle) |
| 161 | { |
| 162 | mSamplerTextures[GL_TEXTURE_RECTANGLE_ANGLE].resize(caps.maxCombinedTextureImageUnits); |
| 163 | } |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 164 | if (extensions.eglImageExternal || extensions.eglStreamConsumerExternal) |
| 165 | { |
| 166 | mSamplerTextures[GL_TEXTURE_EXTERNAL_OES].resize(caps.maxCombinedTextureImageUnits); |
| 167 | } |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 168 | mCompleteTextureCache.resize(caps.maxCombinedTextureImageUnits, nullptr); |
| 169 | mCompleteTextureBindings.reserve(caps.maxCombinedTextureImageUnits); |
| 170 | for (uint32_t textureIndex = 0; textureIndex < caps.maxCombinedTextureImageUnits; |
| 171 | ++textureIndex) |
| 172 | { |
| 173 | mCompleteTextureBindings.emplace_back(OnAttachmentDirtyBinding(this, textureIndex)); |
| 174 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 175 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 176 | mSamplers.resize(caps.maxCombinedTextureImageUnits); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 177 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 178 | mActiveQueries[GL_ANY_SAMPLES_PASSED].set(context, nullptr); |
| 179 | mActiveQueries[GL_ANY_SAMPLES_PASSED_CONSERVATIVE].set(context, nullptr); |
| 180 | mActiveQueries[GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN].set(context, nullptr); |
| 181 | mActiveQueries[GL_TIME_ELAPSED_EXT].set(context, nullptr); |
| 182 | mActiveQueries[GL_COMMANDS_COMPLETED_CHROMIUM].set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 183 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 184 | mProgram = nullptr; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 185 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 186 | mReadFramebuffer = nullptr; |
| 187 | mDrawFramebuffer = nullptr; |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 188 | |
| 189 | mPrimitiveRestart = false; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 190 | |
| 191 | mDebug.setOutputEnabled(debug); |
| 192 | mDebug.setMaxLoggedMessages(extensions.maxDebugLoggedMessages); |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 193 | |
| 194 | if (extensions.framebufferMultisample) |
| 195 | { |
| 196 | mMultiSampling = true; |
| 197 | mSampleAlphaToOne = false; |
| 198 | } |
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 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 265 | mPack.pixelBuffer.set(context, nullptr); |
| 266 | mUnpack.pixelBuffer.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 | |
| 363 | void State::setCullMode(GLenum mode) |
| 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; |
| 588 | mDirtyBits.set(DIRTY_BIT_SAMPLE_MASK_WORD_0 + maskNumber); |
| 589 | } |
| 590 | |
| 591 | GLbitfield State::getSampleMaskWord(GLuint maskNumber) const |
| 592 | { |
| 593 | ASSERT(maskNumber < mMaxSampleMaskWords); |
| 594 | return mSampleMaskValues[maskNumber]; |
| 595 | } |
| 596 | |
| 597 | GLuint State::getMaxSampleMaskWords() const |
| 598 | { |
| 599 | return mMaxSampleMaskWords; |
| 600 | } |
| 601 | |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 602 | void State::setSampleAlphaToOne(bool enabled) |
| 603 | { |
| 604 | mSampleAlphaToOne = enabled; |
| 605 | mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_ONE); |
| 606 | } |
| 607 | |
| 608 | bool State::isSampleAlphaToOneEnabled() const |
| 609 | { |
| 610 | return mSampleAlphaToOne; |
| 611 | } |
| 612 | |
| 613 | void State::setMultisampling(bool enabled) |
| 614 | { |
| 615 | mMultiSampling = enabled; |
| 616 | mDirtyBits.set(DIRTY_BIT_MULTISAMPLING); |
| 617 | } |
| 618 | |
| 619 | bool State::isMultisamplingEnabled() const |
| 620 | { |
| 621 | return mMultiSampling; |
| 622 | } |
| 623 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 624 | bool State::isScissorTestEnabled() const |
| 625 | { |
| 626 | return mScissorTest; |
| 627 | } |
| 628 | |
| 629 | void State::setScissorTest(bool enabled) |
| 630 | { |
| 631 | mScissorTest = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 632 | mDirtyBits.set(DIRTY_BIT_SCISSOR_TEST_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | void State::setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height) |
| 636 | { |
| 637 | mScissor.x = x; |
| 638 | mScissor.y = y; |
| 639 | mScissor.width = width; |
| 640 | mScissor.height = height; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 641 | mDirtyBits.set(DIRTY_BIT_SCISSOR); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | const Rectangle &State::getScissor() const |
| 645 | { |
| 646 | return mScissor; |
| 647 | } |
| 648 | |
| 649 | bool State::isDitherEnabled() const |
| 650 | { |
| 651 | return mBlend.dither; |
| 652 | } |
| 653 | |
| 654 | void State::setDither(bool enabled) |
| 655 | { |
| 656 | mBlend.dither = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 657 | mDirtyBits.set(DIRTY_BIT_DITHER_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 658 | } |
| 659 | |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 660 | bool State::isPrimitiveRestartEnabled() const |
| 661 | { |
| 662 | return mPrimitiveRestart; |
| 663 | } |
| 664 | |
| 665 | void State::setPrimitiveRestart(bool enabled) |
| 666 | { |
| 667 | mPrimitiveRestart = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 668 | mDirtyBits.set(DIRTY_BIT_PRIMITIVE_RESTART_ENABLED); |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 669 | } |
| 670 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 671 | void State::setEnableFeature(GLenum feature, bool enabled) |
| 672 | { |
| 673 | switch (feature) |
| 674 | { |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 675 | case GL_MULTISAMPLE_EXT: setMultisampling(enabled); break; |
| 676 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: setSampleAlphaToOne(enabled); break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 677 | case GL_CULL_FACE: setCullFace(enabled); break; |
| 678 | case GL_POLYGON_OFFSET_FILL: setPolygonOffsetFill(enabled); break; |
| 679 | case GL_SAMPLE_ALPHA_TO_COVERAGE: setSampleAlphaToCoverage(enabled); break; |
| 680 | case GL_SAMPLE_COVERAGE: setSampleCoverage(enabled); break; |
| 681 | case GL_SCISSOR_TEST: setScissorTest(enabled); break; |
| 682 | case GL_STENCIL_TEST: setStencilTest(enabled); break; |
| 683 | case GL_DEPTH_TEST: setDepthTest(enabled); break; |
| 684 | case GL_BLEND: setBlend(enabled); break; |
| 685 | case GL_DITHER: setDither(enabled); break; |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 686 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: setPrimitiveRestart(enabled); break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 687 | case GL_RASTERIZER_DISCARD: setRasterizerDiscard(enabled); break; |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 688 | case GL_SAMPLE_MASK: |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame^] | 689 | setSampleMaskEnabled(enabled); |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 690 | break; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 691 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 692 | mDebug.setOutputSynchronous(enabled); |
| 693 | break; |
| 694 | case GL_DEBUG_OUTPUT: |
| 695 | mDebug.setOutputEnabled(enabled); |
| 696 | break; |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 697 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 698 | setFramebufferSRGB(enabled); |
| 699 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 700 | default: UNREACHABLE(); |
| 701 | } |
| 702 | } |
| 703 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 704 | bool State::getEnableFeature(GLenum feature) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 705 | { |
| 706 | switch (feature) |
| 707 | { |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 708 | case GL_MULTISAMPLE_EXT: return isMultisamplingEnabled(); |
| 709 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: return isSampleAlphaToOneEnabled(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 710 | case GL_CULL_FACE: return isCullFaceEnabled(); |
| 711 | case GL_POLYGON_OFFSET_FILL: return isPolygonOffsetFillEnabled(); |
| 712 | case GL_SAMPLE_ALPHA_TO_COVERAGE: return isSampleAlphaToCoverageEnabled(); |
| 713 | case GL_SAMPLE_COVERAGE: return isSampleCoverageEnabled(); |
| 714 | case GL_SCISSOR_TEST: return isScissorTestEnabled(); |
| 715 | case GL_STENCIL_TEST: return isStencilTestEnabled(); |
| 716 | case GL_DEPTH_TEST: return isDepthTestEnabled(); |
| 717 | case GL_BLEND: return isBlendEnabled(); |
| 718 | case GL_DITHER: return isDitherEnabled(); |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 719 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: return isPrimitiveRestartEnabled(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 720 | case GL_RASTERIZER_DISCARD: return isRasterizerDiscardEnabled(); |
Geoff Lang | b5e997f | 2016-12-06 10:55:34 -0500 | [diff] [blame] | 721 | case GL_SAMPLE_MASK: |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame^] | 722 | return isSampleMaskEnabled(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 723 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 724 | return mDebug.isOutputSynchronous(); |
| 725 | case GL_DEBUG_OUTPUT: |
| 726 | return mDebug.isOutputEnabled(); |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 727 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 728 | return isBindGeneratesResourceEnabled(); |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 729 | case GL_CLIENT_ARRAYS_ANGLE: |
| 730 | return areClientArraysEnabled(); |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 731 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 732 | return getFramebufferSRGB(); |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 733 | case GL_CONTEXT_ROBUST_RESOURCE_INITIALIZATION_ANGLE: |
| 734 | return mRobustResourceInit; |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 735 | case GL_PROGRAM_CACHE_ENABLED_ANGLE: |
| 736 | return mProgramBinaryCacheEnabled; |
| 737 | |
| 738 | default: |
| 739 | UNREACHABLE(); |
| 740 | return false; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 741 | } |
| 742 | } |
| 743 | |
| 744 | void State::setLineWidth(GLfloat width) |
| 745 | { |
| 746 | mLineWidth = width; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 747 | mDirtyBits.set(DIRTY_BIT_LINE_WIDTH); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 748 | } |
| 749 | |
Geoff Lang | 4b3f416 | 2015-04-16 13:22:05 -0400 | [diff] [blame] | 750 | float State::getLineWidth() const |
| 751 | { |
| 752 | return mLineWidth; |
| 753 | } |
| 754 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 755 | void State::setGenerateMipmapHint(GLenum hint) |
| 756 | { |
| 757 | mGenerateMipmapHint = hint; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 758 | mDirtyBits.set(DIRTY_BIT_GENERATE_MIPMAP_HINT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | void State::setFragmentShaderDerivativeHint(GLenum hint) |
| 762 | { |
| 763 | mFragmentShaderDerivativeHint = hint; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 764 | mDirtyBits.set(DIRTY_BIT_SHADER_DERIVATIVE_HINT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 765 | // TODO: Propagate the hint to shader translator so we can write |
| 766 | // ddx, ddx_coarse, or ddx_fine depending on the hint. |
| 767 | // Ignore for now. It is valid for implementations to ignore hint. |
| 768 | } |
| 769 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 770 | bool State::isBindGeneratesResourceEnabled() const |
| 771 | { |
| 772 | return mBindGeneratesResource; |
| 773 | } |
| 774 | |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 775 | bool State::areClientArraysEnabled() const |
| 776 | { |
| 777 | return mClientArraysEnabled; |
| 778 | } |
| 779 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 780 | void State::setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height) |
| 781 | { |
| 782 | mViewport.x = x; |
| 783 | mViewport.y = y; |
| 784 | mViewport.width = width; |
| 785 | mViewport.height = height; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 786 | mDirtyBits.set(DIRTY_BIT_VIEWPORT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | const Rectangle &State::getViewport() const |
| 790 | { |
| 791 | return mViewport; |
| 792 | } |
| 793 | |
| 794 | void State::setActiveSampler(unsigned int active) |
| 795 | { |
| 796 | mActiveSampler = active; |
| 797 | } |
| 798 | |
| 799 | unsigned int State::getActiveSampler() const |
| 800 | { |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 801 | return static_cast<unsigned int>(mActiveSampler); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 802 | } |
| 803 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 804 | void State::setSamplerTexture(const Context *context, GLenum type, Texture *texture) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 805 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 806 | mSamplerTextures[type][mActiveSampler].set(context, texture); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 807 | mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS); |
| 808 | mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 809 | } |
| 810 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 811 | Texture *State::getTargetTexture(GLenum target) const |
| 812 | { |
| 813 | return getSamplerTexture(static_cast<unsigned int>(mActiveSampler), target); |
| 814 | } |
| 815 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 816 | Texture *State::getSamplerTexture(unsigned int sampler, GLenum type) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 817 | { |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 818 | const auto it = mSamplerTextures.find(type); |
| 819 | ASSERT(it != mSamplerTextures.end()); |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 820 | ASSERT(sampler < it->second.size()); |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 821 | return it->second[sampler].get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 822 | } |
| 823 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 824 | GLuint State::getSamplerTextureId(unsigned int sampler, GLenum type) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 825 | { |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 826 | const auto it = mSamplerTextures.find(type); |
| 827 | ASSERT(it != mSamplerTextures.end()); |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 828 | ASSERT(sampler < it->second.size()); |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 829 | return it->second[sampler].id(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 830 | } |
| 831 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 832 | void State::detachTexture(const Context *context, const TextureMap &zeroTextures, GLuint texture) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 833 | { |
| 834 | // Textures have a detach method on State rather than a simple |
| 835 | // removeBinding, because the zero/null texture objects are managed |
| 836 | // separately, and don't have to go through the Context's maps or |
| 837 | // the ResourceManager. |
| 838 | |
| 839 | // [OpenGL ES 2.0.24] section 3.8 page 84: |
| 840 | // If a texture object is deleted, it is as if all texture units which are bound to that texture object are |
| 841 | // rebound to texture object zero |
| 842 | |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 843 | for (auto &bindingVec : mSamplerTextures) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 844 | { |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 845 | GLenum textureType = bindingVec.first; |
| 846 | TextureBindingVector &textureVector = bindingVec.second; |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 847 | for (BindingPointer<Texture> &binding : textureVector) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 848 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 849 | if (binding.id() == texture) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 850 | { |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 851 | auto it = zeroTextures.find(textureType); |
| 852 | ASSERT(it != zeroTextures.end()); |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 853 | // Zero textures are the "default" textures instead of NULL |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 854 | binding.set(context, it->second.get()); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 855 | mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 856 | } |
| 857 | } |
| 858 | } |
| 859 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 860 | for (auto &bindingImageUnit : mImageUnits) |
| 861 | { |
| 862 | if (bindingImageUnit.texture.id() == texture) |
| 863 | { |
| 864 | bindingImageUnit.texture.set(context, nullptr); |
| 865 | bindingImageUnit.level = 0; |
| 866 | bindingImageUnit.layered = false; |
| 867 | bindingImageUnit.layer = 0; |
| 868 | bindingImageUnit.access = GL_READ_ONLY; |
| 869 | bindingImageUnit.format = GL_R32UI; |
| 870 | break; |
| 871 | } |
| 872 | } |
| 873 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 874 | // [OpenGL ES 2.0.24] section 4.4 page 112: |
| 875 | // If a texture object is deleted while its image is attached to the currently bound framebuffer, then it is |
| 876 | // as if Texture2DAttachment had been called, with a texture of 0, for each attachment point to which this |
| 877 | // image was attached in the currently bound framebuffer. |
| 878 | |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 879 | if (mReadFramebuffer && mReadFramebuffer->detachTexture(context, texture)) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 880 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 881 | mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 882 | } |
| 883 | |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 884 | if (mDrawFramebuffer && mDrawFramebuffer->detachTexture(context, texture)) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 885 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 886 | mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 887 | } |
| 888 | } |
| 889 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 890 | void State::initializeZeroTextures(const Context *context, const TextureMap &zeroTextures) |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 891 | { |
| 892 | for (const auto &zeroTexture : zeroTextures) |
| 893 | { |
| 894 | auto &samplerTextureArray = mSamplerTextures[zeroTexture.first]; |
| 895 | |
| 896 | for (size_t textureUnit = 0; textureUnit < samplerTextureArray.size(); ++textureUnit) |
| 897 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 898 | samplerTextureArray[textureUnit].set(context, zeroTexture.second.get()); |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 899 | } |
| 900 | } |
| 901 | } |
| 902 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 903 | void State::setSamplerBinding(const Context *context, GLuint textureUnit, Sampler *sampler) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 904 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 905 | mSamplers[textureUnit].set(context, sampler); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 906 | mDirtyBits.set(DIRTY_BIT_SAMPLER_BINDINGS); |
| 907 | mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | GLuint State::getSamplerId(GLuint textureUnit) const |
| 911 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 912 | ASSERT(textureUnit < mSamplers.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 913 | return mSamplers[textureUnit].id(); |
| 914 | } |
| 915 | |
| 916 | Sampler *State::getSampler(GLuint textureUnit) const |
| 917 | { |
| 918 | return mSamplers[textureUnit].get(); |
| 919 | } |
| 920 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 921 | void State::detachSampler(const Context *context, GLuint sampler) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 922 | { |
| 923 | // [OpenGL ES 3.0.2] section 3.8.2 pages 123-124: |
| 924 | // If a sampler object that is currently bound to one or more texture units is |
| 925 | // deleted, it is as though BindSampler is called once for each texture unit to |
| 926 | // 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] | 927 | for (BindingPointer<Sampler> &samplerBinding : mSamplers) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 928 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 929 | if (samplerBinding.id() == sampler) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 930 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 931 | samplerBinding.set(context, nullptr); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 932 | mDirtyBits.set(DIRTY_BIT_SAMPLER_BINDINGS); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 933 | } |
| 934 | } |
| 935 | } |
| 936 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 937 | void State::setRenderbufferBinding(const Context *context, Renderbuffer *renderbuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 938 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 939 | mRenderbuffer.set(context, renderbuffer); |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 940 | mDirtyBits.set(DIRTY_BIT_RENDERBUFFER_BINDING); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | GLuint State::getRenderbufferId() const |
| 944 | { |
| 945 | return mRenderbuffer.id(); |
| 946 | } |
| 947 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 948 | Renderbuffer *State::getCurrentRenderbuffer() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 949 | { |
| 950 | return mRenderbuffer.get(); |
| 951 | } |
| 952 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 953 | void State::detachRenderbuffer(const Context *context, GLuint renderbuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 954 | { |
| 955 | // [OpenGL ES 2.0.24] section 4.4 page 109: |
| 956 | // If a renderbuffer that is currently bound to RENDERBUFFER is deleted, it is as though BindRenderbuffer |
| 957 | // had been executed with the target RENDERBUFFER and name of zero. |
| 958 | |
| 959 | if (mRenderbuffer.id() == renderbuffer) |
| 960 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 961 | setRenderbufferBinding(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | // [OpenGL ES 2.0.24] section 4.4 page 111: |
| 965 | // If a renderbuffer object is deleted while its image is attached to the currently bound framebuffer, |
| 966 | // then it is as if FramebufferRenderbuffer had been called, with a renderbuffer of 0, for each attachment |
| 967 | // point to which this image was attached in the currently bound framebuffer. |
| 968 | |
| 969 | Framebuffer *readFramebuffer = mReadFramebuffer; |
| 970 | Framebuffer *drawFramebuffer = mDrawFramebuffer; |
| 971 | |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 972 | if (readFramebuffer && readFramebuffer->detachRenderbuffer(context, renderbuffer)) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 973 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 974 | mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | if (drawFramebuffer && drawFramebuffer != readFramebuffer) |
| 978 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 979 | if (drawFramebuffer->detachRenderbuffer(context, renderbuffer)) |
| 980 | { |
| 981 | mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 982 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | } |
| 986 | |
| 987 | void State::setReadFramebufferBinding(Framebuffer *framebuffer) |
| 988 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 989 | if (mReadFramebuffer == framebuffer) |
| 990 | return; |
| 991 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 992 | mReadFramebuffer = framebuffer; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 993 | mDirtyBits.set(DIRTY_BIT_READ_FRAMEBUFFER_BINDING); |
| 994 | |
| 995 | if (mReadFramebuffer && mReadFramebuffer->hasAnyDirtyBit()) |
| 996 | { |
| 997 | mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 998 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | void State::setDrawFramebufferBinding(Framebuffer *framebuffer) |
| 1002 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1003 | if (mDrawFramebuffer == framebuffer) |
| 1004 | return; |
| 1005 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1006 | mDrawFramebuffer = framebuffer; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1007 | mDirtyBits.set(DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING); |
| 1008 | |
| 1009 | if (mDrawFramebuffer && mDrawFramebuffer->hasAnyDirtyBit()) |
| 1010 | { |
| 1011 | mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 1012 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | Framebuffer *State::getTargetFramebuffer(GLenum target) const |
| 1016 | { |
| 1017 | switch (target) |
| 1018 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1019 | case GL_READ_FRAMEBUFFER_ANGLE: |
| 1020 | return mReadFramebuffer; |
| 1021 | case GL_DRAW_FRAMEBUFFER_ANGLE: |
| 1022 | case GL_FRAMEBUFFER: |
| 1023 | return mDrawFramebuffer; |
| 1024 | default: |
| 1025 | UNREACHABLE(); |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 1026 | return nullptr; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1027 | } |
| 1028 | } |
| 1029 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1030 | Framebuffer *State::getReadFramebuffer() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1031 | { |
| 1032 | return mReadFramebuffer; |
| 1033 | } |
| 1034 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1035 | Framebuffer *State::getDrawFramebuffer() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1036 | { |
| 1037 | return mDrawFramebuffer; |
| 1038 | } |
| 1039 | |
| 1040 | bool State::removeReadFramebufferBinding(GLuint framebuffer) |
| 1041 | { |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 1042 | if (mReadFramebuffer != nullptr && |
| 1043 | mReadFramebuffer->id() == framebuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1044 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1045 | setReadFramebufferBinding(nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1046 | return true; |
| 1047 | } |
| 1048 | |
| 1049 | return false; |
| 1050 | } |
| 1051 | |
| 1052 | bool State::removeDrawFramebufferBinding(GLuint framebuffer) |
| 1053 | { |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 1054 | if (mReadFramebuffer != nullptr && |
| 1055 | mDrawFramebuffer->id() == framebuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1056 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1057 | setDrawFramebufferBinding(nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1058 | return true; |
| 1059 | } |
| 1060 | |
| 1061 | return false; |
| 1062 | } |
| 1063 | |
| 1064 | void State::setVertexArrayBinding(VertexArray *vertexArray) |
| 1065 | { |
| 1066 | mVertexArray = vertexArray; |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1067 | mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1068 | |
| 1069 | if (mVertexArray && mVertexArray->hasAnyDirtyBit()) |
| 1070 | { |
| 1071 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1072 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | GLuint State::getVertexArrayId() const |
| 1076 | { |
Yunchao He | 4f28544 | 2017-04-21 12:15:49 +0800 | [diff] [blame] | 1077 | ASSERT(mVertexArray != nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1078 | return mVertexArray->id(); |
| 1079 | } |
| 1080 | |
| 1081 | VertexArray *State::getVertexArray() const |
| 1082 | { |
Yunchao He | 4f28544 | 2017-04-21 12:15:49 +0800 | [diff] [blame] | 1083 | ASSERT(mVertexArray != nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1084 | return mVertexArray; |
| 1085 | } |
| 1086 | |
| 1087 | bool State::removeVertexArrayBinding(GLuint vertexArray) |
| 1088 | { |
| 1089 | if (mVertexArray->id() == vertexArray) |
| 1090 | { |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 1091 | mVertexArray = nullptr; |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1092 | mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1093 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1094 | return true; |
| 1095 | } |
| 1096 | |
| 1097 | return false; |
| 1098 | } |
| 1099 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1100 | void State::setElementArrayBuffer(const Context *context, Buffer *buffer) |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1101 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1102 | getVertexArray()->setElementArrayBuffer(context, buffer); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1103 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1104 | } |
| 1105 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1106 | void State::bindVertexBuffer(const Context *context, |
| 1107 | GLuint bindingIndex, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1108 | Buffer *boundBuffer, |
| 1109 | GLintptr offset, |
| 1110 | GLsizei stride) |
| 1111 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1112 | getVertexArray()->bindVertexBuffer(context, bindingIndex, boundBuffer, offset, stride); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1113 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1114 | } |
| 1115 | |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 1116 | void State::setVertexAttribBinding(const Context *context, GLuint attribIndex, GLuint bindingIndex) |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1117 | { |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 1118 | getVertexArray()->setVertexAttribBinding(context, attribIndex, bindingIndex); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1119 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1120 | } |
| 1121 | |
| 1122 | void State::setVertexAttribFormat(GLuint attribIndex, |
| 1123 | GLint size, |
| 1124 | GLenum type, |
| 1125 | bool normalized, |
| 1126 | bool pureInteger, |
| 1127 | GLuint relativeOffset) |
| 1128 | { |
| 1129 | getVertexArray()->setVertexAttribFormat(attribIndex, size, type, normalized, pureInteger, |
| 1130 | relativeOffset); |
| 1131 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1132 | } |
| 1133 | |
| 1134 | void State::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor) |
| 1135 | { |
| 1136 | getVertexArray()->setVertexBindingDivisor(bindingIndex, divisor); |
| 1137 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1138 | } |
| 1139 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 1140 | void State::setProgram(const Context *context, Program *newProgram) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1141 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1142 | if (mProgram != newProgram) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1143 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1144 | if (mProgram) |
| 1145 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 1146 | mProgram->release(context); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | mProgram = newProgram; |
| 1150 | |
| 1151 | if (mProgram) |
| 1152 | { |
| 1153 | newProgram->addRef(); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1154 | mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1155 | } |
Jamie Madill | a779b61 | 2017-07-24 11:46:05 -0400 | [diff] [blame] | 1156 | mDirtyBits.set(DIRTY_BIT_PROGRAM_EXECUTABLE); |
| 1157 | mDirtyBits.set(DIRTY_BIT_PROGRAM_BINDING); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1158 | } |
| 1159 | } |
| 1160 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1161 | Program *State::getProgram() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1162 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1163 | return mProgram; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1164 | } |
| 1165 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1166 | void State::setTransformFeedbackBinding(const Context *context, |
| 1167 | TransformFeedback *transformFeedback) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1168 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1169 | mTransformFeedback.set(context, transformFeedback); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | TransformFeedback *State::getCurrentTransformFeedback() const |
| 1173 | { |
| 1174 | return mTransformFeedback.get(); |
| 1175 | } |
| 1176 | |
Gregoire Payen de La Garanderie | 5274202 | 2015-02-04 14:55:39 +0000 | [diff] [blame] | 1177 | bool State::isTransformFeedbackActiveUnpaused() const |
| 1178 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1179 | TransformFeedback *curTransformFeedback = getCurrentTransformFeedback(); |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 1180 | return curTransformFeedback && curTransformFeedback->isActive() && !curTransformFeedback->isPaused(); |
Gregoire Payen de La Garanderie | 5274202 | 2015-02-04 14:55:39 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1183 | bool State::removeTransformFeedbackBinding(const Context *context, GLuint transformFeedback) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1184 | { |
| 1185 | if (mTransformFeedback.id() == transformFeedback) |
| 1186 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1187 | mTransformFeedback.set(context, nullptr); |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 1188 | return true; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1189 | } |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 1190 | |
| 1191 | return false; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1192 | } |
| 1193 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 1194 | void State::setProgramPipelineBinding(const Context *context, ProgramPipeline *pipeline) |
| 1195 | { |
| 1196 | mProgramPipeline.set(context, pipeline); |
| 1197 | } |
| 1198 | |
| 1199 | void State::detachProgramPipeline(const Context *context, GLuint pipeline) |
| 1200 | { |
| 1201 | mProgramPipeline.set(context, nullptr); |
| 1202 | } |
| 1203 | |
Olli Etuaho | bbf1c10 | 2016-06-28 13:31:33 +0300 | [diff] [blame] | 1204 | bool State::isQueryActive(const GLenum type) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1205 | { |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1206 | for (auto &iter : mActiveQueries) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1207 | { |
Olli Etuaho | bbf1c10 | 2016-06-28 13:31:33 +0300 | [diff] [blame] | 1208 | const Query *query = iter.second.get(); |
| 1209 | if (query != nullptr && ActiveQueryType(query->getType()) == ActiveQueryType(type)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1210 | { |
| 1211 | return true; |
| 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | return false; |
| 1216 | } |
| 1217 | |
| 1218 | bool State::isQueryActive(Query *query) const |
| 1219 | { |
| 1220 | for (auto &iter : mActiveQueries) |
| 1221 | { |
| 1222 | if (iter.second.get() == query) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1223 | { |
| 1224 | return true; |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | return false; |
| 1229 | } |
| 1230 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1231 | void State::setActiveQuery(const Context *context, GLenum target, Query *query) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1232 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1233 | mActiveQueries[target].set(context, query); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | GLuint State::getActiveQueryId(GLenum target) const |
| 1237 | { |
| 1238 | const Query *query = getActiveQuery(target); |
| 1239 | return (query ? query->id() : 0u); |
| 1240 | } |
| 1241 | |
| 1242 | Query *State::getActiveQuery(GLenum target) const |
| 1243 | { |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 1244 | const auto it = mActiveQueries.find(target); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1245 | |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 1246 | // All query types should already exist in the activeQueries map |
| 1247 | ASSERT(it != mActiveQueries.end()); |
| 1248 | |
| 1249 | return it->second.get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1250 | } |
| 1251 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1252 | void State::setArrayBufferBinding(const Context *context, Buffer *buffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1253 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1254 | mArrayBuffer.set(context, buffer); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | GLuint State::getArrayBufferId() const |
| 1258 | { |
| 1259 | return mArrayBuffer.id(); |
| 1260 | } |
| 1261 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1262 | void State::setDrawIndirectBufferBinding(const Context *context, Buffer *buffer) |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1263 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1264 | mDrawIndirectBuffer.set(context, buffer); |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1265 | mDirtyBits.set(DIRTY_BIT_DRAW_INDIRECT_BUFFER_BINDING); |
| 1266 | } |
| 1267 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1268 | void State::setGenericUniformBufferBinding(const Context *context, Buffer *buffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1269 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1270 | mGenericUniformBuffer.set(context, buffer); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1271 | } |
| 1272 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1273 | void State::setIndexedUniformBufferBinding(const Context *context, |
| 1274 | GLuint index, |
| 1275 | Buffer *buffer, |
| 1276 | GLintptr offset, |
| 1277 | GLsizeiptr size) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1278 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1279 | mUniformBuffers[index].set(context, buffer, offset, size); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1280 | } |
| 1281 | |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 1282 | const OffsetBindingPointer<Buffer> &State::getIndexedUniformBuffer(size_t index) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1283 | { |
Shannon Woods | f3acaf9 | 2014-09-23 18:07:11 -0400 | [diff] [blame] | 1284 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 1285 | return mUniformBuffers[index]; |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1288 | void State::setGenericAtomicCounterBufferBinding(const Context *context, Buffer *buffer) |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1289 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1290 | mGenericAtomicCounterBuffer.set(context, buffer); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1291 | } |
| 1292 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1293 | void State::setIndexedAtomicCounterBufferBinding(const Context *context, |
| 1294 | GLuint index, |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1295 | Buffer *buffer, |
| 1296 | GLintptr offset, |
| 1297 | GLsizeiptr size) |
| 1298 | { |
| 1299 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1300 | mAtomicCounterBuffers[index].set(context, buffer, offset, size); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | const OffsetBindingPointer<Buffer> &State::getIndexedAtomicCounterBuffer(size_t index) const |
| 1304 | { |
| 1305 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
| 1306 | return mAtomicCounterBuffers[index]; |
| 1307 | } |
| 1308 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1309 | void State::setGenericShaderStorageBufferBinding(const Context *context, Buffer *buffer) |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1310 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1311 | mGenericShaderStorageBuffer.set(context, buffer); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1312 | } |
| 1313 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1314 | void State::setIndexedShaderStorageBufferBinding(const Context *context, |
| 1315 | GLuint index, |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1316 | Buffer *buffer, |
| 1317 | GLintptr offset, |
| 1318 | GLsizeiptr size) |
| 1319 | { |
| 1320 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1321 | mShaderStorageBuffers[index].set(context, buffer, offset, size); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | const OffsetBindingPointer<Buffer> &State::getIndexedShaderStorageBuffer(size_t index) const |
| 1325 | { |
| 1326 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
| 1327 | return mShaderStorageBuffers[index]; |
| 1328 | } |
| 1329 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1330 | void State::setCopyReadBufferBinding(const Context *context, Buffer *buffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1331 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1332 | mCopyReadBuffer.set(context, buffer); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1333 | } |
| 1334 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1335 | void State::setCopyWriteBufferBinding(const Context *context, Buffer *buffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1336 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1337 | mCopyWriteBuffer.set(context, buffer); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1338 | } |
| 1339 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1340 | void State::setPixelPackBufferBinding(const Context *context, Buffer *buffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1341 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1342 | mPack.pixelBuffer.set(context, buffer); |
Corentin Wallez | bbd663a | 2016-04-20 17:49:17 -0400 | [diff] [blame] | 1343 | mDirtyBits.set(DIRTY_BIT_PACK_BUFFER_BINDING); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1344 | } |
| 1345 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1346 | void State::setPixelUnpackBufferBinding(const Context *context, Buffer *buffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1347 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1348 | mUnpack.pixelBuffer.set(context, buffer); |
Corentin Wallez | bbd663a | 2016-04-20 17:49:17 -0400 | [diff] [blame] | 1349 | mDirtyBits.set(DIRTY_BIT_UNPACK_BUFFER_BINDING); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | Buffer *State::getTargetBuffer(GLenum target) const |
| 1353 | { |
| 1354 | switch (target) |
| 1355 | { |
| 1356 | case GL_ARRAY_BUFFER: return mArrayBuffer.get(); |
| 1357 | case GL_COPY_READ_BUFFER: return mCopyReadBuffer.get(); |
| 1358 | case GL_COPY_WRITE_BUFFER: return mCopyWriteBuffer.get(); |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 1359 | case GL_ELEMENT_ARRAY_BUFFER: return getVertexArray()->getElementArrayBuffer().get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1360 | case GL_PIXEL_PACK_BUFFER: return mPack.pixelBuffer.get(); |
| 1361 | case GL_PIXEL_UNPACK_BUFFER: return mUnpack.pixelBuffer.get(); |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 1362 | case GL_TRANSFORM_FEEDBACK_BUFFER: return mTransformFeedback->getGenericBuffer().get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1363 | case GL_UNIFORM_BUFFER: return mGenericUniformBuffer.get(); |
Geoff Lang | b5e997f | 2016-12-06 10:55:34 -0500 | [diff] [blame] | 1364 | case GL_ATOMIC_COUNTER_BUFFER: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1365 | return mGenericAtomicCounterBuffer.get(); |
Geoff Lang | b5e997f | 2016-12-06 10:55:34 -0500 | [diff] [blame] | 1366 | case GL_SHADER_STORAGE_BUFFER: |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1367 | return mGenericShaderStorageBuffer.get(); |
Geoff Lang | b5e997f | 2016-12-06 10:55:34 -0500 | [diff] [blame] | 1368 | case GL_DRAW_INDIRECT_BUFFER: |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1369 | return mDrawIndirectBuffer.get(); |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 1370 | default: |
| 1371 | UNREACHABLE(); |
| 1372 | return nullptr; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1373 | } |
| 1374 | } |
| 1375 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1376 | void State::detachBuffer(const Context *context, GLuint bufferName) |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1377 | { |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1378 | BindingPointer<Buffer> *buffers[] = { |
| 1379 | &mArrayBuffer, &mGenericAtomicCounterBuffer, &mCopyReadBuffer, |
| 1380 | &mCopyWriteBuffer, &mDrawIndirectBuffer, &mPack.pixelBuffer, |
| 1381 | &mUnpack.pixelBuffer, &mGenericUniformBuffer, &mGenericShaderStorageBuffer}; |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1382 | for (auto buffer : buffers) |
| 1383 | { |
| 1384 | if (buffer->id() == bufferName) |
| 1385 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1386 | buffer->set(context, nullptr); |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | TransformFeedback *curTransformFeedback = getCurrentTransformFeedback(); |
| 1391 | if (curTransformFeedback) |
| 1392 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1393 | curTransformFeedback->detachBuffer(context, bufferName); |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1394 | } |
| 1395 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1396 | getVertexArray()->detachBuffer(context, bufferName); |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1397 | } |
| 1398 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1399 | void State::setEnableVertexAttribArray(unsigned int attribNum, bool enabled) |
| 1400 | { |
| 1401 | getVertexArray()->enableAttribute(attribNum, enabled); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1402 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | void State::setVertexAttribf(GLuint index, const GLfloat values[4]) |
| 1406 | { |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 1407 | ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1408 | mVertexAttribCurrentValues[index].setFloatValues(values); |
Jamie Madill | 1e0bc3a | 2015-08-11 08:12:21 -0400 | [diff] [blame] | 1409 | mDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_0 + index); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | void State::setVertexAttribu(GLuint index, const GLuint values[4]) |
| 1413 | { |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 1414 | ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1415 | mVertexAttribCurrentValues[index].setUnsignedIntValues(values); |
Jamie Madill | 1e0bc3a | 2015-08-11 08:12:21 -0400 | [diff] [blame] | 1416 | mDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_0 + index); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | void State::setVertexAttribi(GLuint index, const GLint values[4]) |
| 1420 | { |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 1421 | ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1422 | mVertexAttribCurrentValues[index].setIntValues(values); |
Jamie Madill | 1e0bc3a | 2015-08-11 08:12:21 -0400 | [diff] [blame] | 1423 | mDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_0 + index); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1424 | } |
| 1425 | |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 1426 | void State::setVertexAttribPointer(const Context *context, |
| 1427 | unsigned int attribNum, |
| 1428 | Buffer *boundBuffer, |
| 1429 | GLint size, |
| 1430 | GLenum type, |
| 1431 | bool normalized, |
| 1432 | bool pureInteger, |
| 1433 | GLsizei stride, |
| 1434 | const void *pointer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1435 | { |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 1436 | getVertexArray()->setVertexAttribPointer(context, attribNum, boundBuffer, size, type, |
| 1437 | normalized, pureInteger, stride, pointer); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1438 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 1441 | void State::setVertexAttribDivisor(const Context *context, GLuint index, GLuint divisor) |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1442 | { |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 1443 | getVertexArray()->setVertexAttribDivisor(context, index, divisor); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1444 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1445 | } |
| 1446 | |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 1447 | const VertexAttribCurrentValueData &State::getVertexAttribCurrentValue(size_t attribNum) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1448 | { |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 1449 | ASSERT(attribNum < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1450 | return mVertexAttribCurrentValues[attribNum]; |
| 1451 | } |
| 1452 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1453 | const void *State::getVertexAttribPointer(unsigned int attribNum) const |
| 1454 | { |
| 1455 | return getVertexArray()->getVertexAttribute(attribNum).pointer; |
| 1456 | } |
| 1457 | |
| 1458 | void State::setPackAlignment(GLint alignment) |
| 1459 | { |
| 1460 | mPack.alignment = alignment; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1461 | mDirtyBits.set(DIRTY_BIT_PACK_ALIGNMENT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | GLint State::getPackAlignment() const |
| 1465 | { |
| 1466 | return mPack.alignment; |
| 1467 | } |
| 1468 | |
| 1469 | void State::setPackReverseRowOrder(bool reverseRowOrder) |
| 1470 | { |
| 1471 | mPack.reverseRowOrder = reverseRowOrder; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1472 | mDirtyBits.set(DIRTY_BIT_PACK_REVERSE_ROW_ORDER); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | bool State::getPackReverseRowOrder() const |
| 1476 | { |
| 1477 | return mPack.reverseRowOrder; |
| 1478 | } |
| 1479 | |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1480 | void State::setPackRowLength(GLint rowLength) |
| 1481 | { |
| 1482 | mPack.rowLength = rowLength; |
| 1483 | mDirtyBits.set(DIRTY_BIT_PACK_ROW_LENGTH); |
| 1484 | } |
| 1485 | |
| 1486 | GLint State::getPackRowLength() const |
| 1487 | { |
| 1488 | return mPack.rowLength; |
| 1489 | } |
| 1490 | |
| 1491 | void State::setPackSkipRows(GLint skipRows) |
| 1492 | { |
| 1493 | mPack.skipRows = skipRows; |
| 1494 | mDirtyBits.set(DIRTY_BIT_PACK_SKIP_ROWS); |
| 1495 | } |
| 1496 | |
| 1497 | GLint State::getPackSkipRows() const |
| 1498 | { |
| 1499 | return mPack.skipRows; |
| 1500 | } |
| 1501 | |
| 1502 | void State::setPackSkipPixels(GLint skipPixels) |
| 1503 | { |
| 1504 | mPack.skipPixels = skipPixels; |
| 1505 | mDirtyBits.set(DIRTY_BIT_PACK_SKIP_PIXELS); |
| 1506 | } |
| 1507 | |
| 1508 | GLint State::getPackSkipPixels() const |
| 1509 | { |
| 1510 | return mPack.skipPixels; |
| 1511 | } |
| 1512 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1513 | const PixelPackState &State::getPackState() const |
| 1514 | { |
| 1515 | return mPack; |
| 1516 | } |
| 1517 | |
Jamie Madill | 87de362 | 2015-03-16 10:41:44 -0400 | [diff] [blame] | 1518 | PixelPackState &State::getPackState() |
| 1519 | { |
| 1520 | return mPack; |
| 1521 | } |
| 1522 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1523 | void State::setUnpackAlignment(GLint alignment) |
| 1524 | { |
| 1525 | mUnpack.alignment = alignment; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1526 | mDirtyBits.set(DIRTY_BIT_UNPACK_ALIGNMENT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | GLint State::getUnpackAlignment() const |
| 1530 | { |
| 1531 | return mUnpack.alignment; |
| 1532 | } |
| 1533 | |
Minmin Gong | b8aee3b | 2015-01-27 14:42:36 -0800 | [diff] [blame] | 1534 | void State::setUnpackRowLength(GLint rowLength) |
| 1535 | { |
| 1536 | mUnpack.rowLength = rowLength; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1537 | mDirtyBits.set(DIRTY_BIT_UNPACK_ROW_LENGTH); |
Minmin Gong | b8aee3b | 2015-01-27 14:42:36 -0800 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | GLint State::getUnpackRowLength() const |
| 1541 | { |
| 1542 | return mUnpack.rowLength; |
| 1543 | } |
| 1544 | |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1545 | void State::setUnpackImageHeight(GLint imageHeight) |
| 1546 | { |
| 1547 | mUnpack.imageHeight = imageHeight; |
| 1548 | mDirtyBits.set(DIRTY_BIT_UNPACK_IMAGE_HEIGHT); |
| 1549 | } |
| 1550 | |
| 1551 | GLint State::getUnpackImageHeight() const |
| 1552 | { |
| 1553 | return mUnpack.imageHeight; |
| 1554 | } |
| 1555 | |
| 1556 | void State::setUnpackSkipImages(GLint skipImages) |
| 1557 | { |
| 1558 | mUnpack.skipImages = skipImages; |
| 1559 | mDirtyBits.set(DIRTY_BIT_UNPACK_SKIP_IMAGES); |
| 1560 | } |
| 1561 | |
| 1562 | GLint State::getUnpackSkipImages() const |
| 1563 | { |
| 1564 | return mUnpack.skipImages; |
| 1565 | } |
| 1566 | |
| 1567 | void State::setUnpackSkipRows(GLint skipRows) |
| 1568 | { |
| 1569 | mUnpack.skipRows = skipRows; |
| 1570 | mDirtyBits.set(DIRTY_BIT_UNPACK_SKIP_ROWS); |
| 1571 | } |
| 1572 | |
| 1573 | GLint State::getUnpackSkipRows() const |
| 1574 | { |
| 1575 | return mUnpack.skipRows; |
| 1576 | } |
| 1577 | |
| 1578 | void State::setUnpackSkipPixels(GLint skipPixels) |
| 1579 | { |
| 1580 | mUnpack.skipPixels = skipPixels; |
| 1581 | mDirtyBits.set(DIRTY_BIT_UNPACK_SKIP_PIXELS); |
| 1582 | } |
| 1583 | |
| 1584 | GLint State::getUnpackSkipPixels() const |
| 1585 | { |
| 1586 | return mUnpack.skipPixels; |
| 1587 | } |
| 1588 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1589 | const PixelUnpackState &State::getUnpackState() const |
| 1590 | { |
| 1591 | return mUnpack; |
| 1592 | } |
| 1593 | |
Jamie Madill | 67102f0 | 2015-03-16 10:41:42 -0400 | [diff] [blame] | 1594 | PixelUnpackState &State::getUnpackState() |
| 1595 | { |
| 1596 | return mUnpack; |
| 1597 | } |
| 1598 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1599 | const Debug &State::getDebug() const |
| 1600 | { |
| 1601 | return mDebug; |
| 1602 | } |
| 1603 | |
| 1604 | Debug &State::getDebug() |
| 1605 | { |
| 1606 | return mDebug; |
| 1607 | } |
| 1608 | |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 1609 | void State::setCoverageModulation(GLenum components) |
| 1610 | { |
| 1611 | mCoverageModulation = components; |
| 1612 | mDirtyBits.set(DIRTY_BIT_COVERAGE_MODULATION); |
| 1613 | } |
| 1614 | |
| 1615 | GLenum State::getCoverageModulation() const |
| 1616 | { |
| 1617 | return mCoverageModulation; |
| 1618 | } |
| 1619 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1620 | void State::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix) |
| 1621 | { |
| 1622 | if (matrixMode == GL_PATH_MODELVIEW_CHROMIUM) |
| 1623 | { |
| 1624 | memcpy(mPathMatrixMV, matrix, 16 * sizeof(GLfloat)); |
| 1625 | mDirtyBits.set(DIRTY_BIT_PATH_RENDERING_MATRIX_MV); |
| 1626 | } |
| 1627 | else if (matrixMode == GL_PATH_PROJECTION_CHROMIUM) |
| 1628 | { |
| 1629 | memcpy(mPathMatrixProj, matrix, 16 * sizeof(GLfloat)); |
| 1630 | mDirtyBits.set(DIRTY_BIT_PATH_RENDERING_MATRIX_PROJ); |
| 1631 | } |
| 1632 | else |
| 1633 | { |
| 1634 | UNREACHABLE(); |
| 1635 | } |
| 1636 | } |
| 1637 | |
| 1638 | const GLfloat *State::getPathRenderingMatrix(GLenum which) const |
| 1639 | { |
| 1640 | if (which == GL_PATH_MODELVIEW_MATRIX_CHROMIUM) |
| 1641 | { |
| 1642 | return mPathMatrixMV; |
| 1643 | } |
| 1644 | else if (which == GL_PATH_PROJECTION_MATRIX_CHROMIUM) |
| 1645 | { |
| 1646 | return mPathMatrixProj; |
| 1647 | } |
| 1648 | |
| 1649 | UNREACHABLE(); |
| 1650 | return nullptr; |
| 1651 | } |
| 1652 | |
| 1653 | void State::setPathStencilFunc(GLenum func, GLint ref, GLuint mask) |
| 1654 | { |
| 1655 | mPathStencilFunc = func; |
| 1656 | mPathStencilRef = ref; |
| 1657 | mPathStencilMask = mask; |
| 1658 | mDirtyBits.set(DIRTY_BIT_PATH_RENDERING_STENCIL_STATE); |
| 1659 | } |
| 1660 | |
| 1661 | GLenum State::getPathStencilFunc() const |
| 1662 | { |
| 1663 | return mPathStencilFunc; |
| 1664 | } |
| 1665 | |
| 1666 | GLint State::getPathStencilRef() const |
| 1667 | { |
| 1668 | return mPathStencilRef; |
| 1669 | } |
| 1670 | |
| 1671 | GLuint State::getPathStencilMask() const |
| 1672 | { |
| 1673 | return mPathStencilMask; |
| 1674 | } |
| 1675 | |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 1676 | void State::setFramebufferSRGB(bool sRGB) |
| 1677 | { |
| 1678 | mFramebufferSRGB = sRGB; |
| 1679 | mDirtyBits.set(DIRTY_BIT_FRAMEBUFFER_SRGB); |
| 1680 | } |
| 1681 | |
| 1682 | bool State::getFramebufferSRGB() const |
| 1683 | { |
| 1684 | return mFramebufferSRGB; |
| 1685 | } |
| 1686 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1687 | void State::getBooleanv(GLenum pname, GLboolean *params) |
| 1688 | { |
| 1689 | switch (pname) |
| 1690 | { |
| 1691 | case GL_SAMPLE_COVERAGE_INVERT: *params = mSampleCoverageInvert; break; |
| 1692 | case GL_DEPTH_WRITEMASK: *params = mDepthStencil.depthMask; break; |
| 1693 | case GL_COLOR_WRITEMASK: |
| 1694 | params[0] = mBlend.colorMaskRed; |
| 1695 | params[1] = mBlend.colorMaskGreen; |
| 1696 | params[2] = mBlend.colorMaskBlue; |
| 1697 | params[3] = mBlend.colorMaskAlpha; |
| 1698 | break; |
| 1699 | case GL_CULL_FACE: *params = mRasterizer.cullFace; break; |
| 1700 | case GL_POLYGON_OFFSET_FILL: *params = mRasterizer.polygonOffsetFill; break; |
| 1701 | case GL_SAMPLE_ALPHA_TO_COVERAGE: *params = mBlend.sampleAlphaToCoverage; break; |
| 1702 | case GL_SAMPLE_COVERAGE: *params = mSampleCoverage; break; |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame^] | 1703 | case GL_SAMPLE_MASK: |
| 1704 | *params = mSampleMask; |
| 1705 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1706 | case GL_SCISSOR_TEST: *params = mScissorTest; break; |
| 1707 | case GL_STENCIL_TEST: *params = mDepthStencil.stencilTest; break; |
| 1708 | case GL_DEPTH_TEST: *params = mDepthStencil.depthTest; break; |
| 1709 | case GL_BLEND: *params = mBlend.blend; break; |
| 1710 | case GL_DITHER: *params = mBlend.dither; break; |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 1711 | case GL_TRANSFORM_FEEDBACK_ACTIVE: *params = getCurrentTransformFeedback()->isActive() ? GL_TRUE : GL_FALSE; break; |
| 1712 | 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] | 1713 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: |
| 1714 | *params = mPrimitiveRestart; |
| 1715 | break; |
Geoff Lang | ab831f0 | 2015-12-01 09:39:10 -0500 | [diff] [blame] | 1716 | case GL_RASTERIZER_DISCARD: |
| 1717 | *params = isRasterizerDiscardEnabled() ? GL_TRUE : GL_FALSE; |
| 1718 | break; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1719 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 1720 | *params = mDebug.isOutputSynchronous() ? GL_TRUE : GL_FALSE; |
| 1721 | break; |
| 1722 | case GL_DEBUG_OUTPUT: |
| 1723 | *params = mDebug.isOutputEnabled() ? GL_TRUE : GL_FALSE; |
| 1724 | break; |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 1725 | case GL_MULTISAMPLE_EXT: |
| 1726 | *params = mMultiSampling; |
| 1727 | break; |
| 1728 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 1729 | *params = mSampleAlphaToOne; |
| 1730 | break; |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 1731 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 1732 | *params = isBindGeneratesResourceEnabled() ? GL_TRUE : GL_FALSE; |
| 1733 | break; |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 1734 | case GL_CLIENT_ARRAYS_ANGLE: |
| 1735 | *params = areClientArraysEnabled() ? GL_TRUE : GL_FALSE; |
| 1736 | break; |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 1737 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 1738 | *params = getFramebufferSRGB() ? GL_TRUE : GL_FALSE; |
| 1739 | break; |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 1740 | case GL_CONTEXT_ROBUST_RESOURCE_INITIALIZATION_ANGLE: |
| 1741 | *params = mRobustResourceInit ? GL_TRUE : GL_FALSE; |
| 1742 | break; |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 1743 | case GL_PROGRAM_CACHE_ENABLED_ANGLE: |
| 1744 | *params = mProgramBinaryCacheEnabled ? GL_TRUE : GL_FALSE; |
| 1745 | break; |
| 1746 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1747 | default: |
| 1748 | UNREACHABLE(); |
| 1749 | break; |
| 1750 | } |
| 1751 | } |
| 1752 | |
| 1753 | void State::getFloatv(GLenum pname, GLfloat *params) |
| 1754 | { |
| 1755 | // Please note: DEPTH_CLEAR_VALUE is included in our internal getFloatv implementation |
| 1756 | // because it is stored as a float, despite the fact that the GL ES 2.0 spec names |
| 1757 | // GetIntegerv as its native query function. As it would require conversion in any |
| 1758 | // case, this should make no difference to the calling application. |
| 1759 | switch (pname) |
| 1760 | { |
| 1761 | case GL_LINE_WIDTH: *params = mLineWidth; break; |
| 1762 | case GL_SAMPLE_COVERAGE_VALUE: *params = mSampleCoverageValue; break; |
| 1763 | case GL_DEPTH_CLEAR_VALUE: *params = mDepthClearValue; break; |
| 1764 | case GL_POLYGON_OFFSET_FACTOR: *params = mRasterizer.polygonOffsetFactor; break; |
| 1765 | case GL_POLYGON_OFFSET_UNITS: *params = mRasterizer.polygonOffsetUnits; break; |
| 1766 | case GL_DEPTH_RANGE: |
| 1767 | params[0] = mNearZ; |
| 1768 | params[1] = mFarZ; |
| 1769 | break; |
| 1770 | case GL_COLOR_CLEAR_VALUE: |
| 1771 | params[0] = mColorClearValue.red; |
| 1772 | params[1] = mColorClearValue.green; |
| 1773 | params[2] = mColorClearValue.blue; |
| 1774 | params[3] = mColorClearValue.alpha; |
| 1775 | break; |
| 1776 | case GL_BLEND_COLOR: |
| 1777 | params[0] = mBlendColor.red; |
| 1778 | params[1] = mBlendColor.green; |
| 1779 | params[2] = mBlendColor.blue; |
| 1780 | params[3] = mBlendColor.alpha; |
| 1781 | break; |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 1782 | case GL_MULTISAMPLE_EXT: |
| 1783 | *params = static_cast<GLfloat>(mMultiSampling); |
| 1784 | break; |
| 1785 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 1786 | *params = static_cast<GLfloat>(mSampleAlphaToOne); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 1787 | case GL_COVERAGE_MODULATION_CHROMIUM: |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1788 | params[0] = static_cast<GLfloat>(mCoverageModulation); |
| 1789 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1790 | default: |
| 1791 | UNREACHABLE(); |
| 1792 | break; |
| 1793 | } |
| 1794 | } |
| 1795 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1796 | void State::getIntegerv(const Context *context, GLenum pname, GLint *params) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1797 | { |
| 1798 | if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT) |
| 1799 | { |
| 1800 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0_EXT); |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1801 | ASSERT(colorAttachment < mMaxDrawBuffers); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1802 | Framebuffer *framebuffer = mDrawFramebuffer; |
| 1803 | *params = framebuffer->getDrawBufferState(colorAttachment); |
| 1804 | return; |
| 1805 | } |
| 1806 | |
| 1807 | // Please note: DEPTH_CLEAR_VALUE is not included in our internal getIntegerv implementation |
| 1808 | // because it is stored as a float, despite the fact that the GL ES 2.0 spec names |
| 1809 | // GetIntegerv as its native query function. As it would require conversion in any |
| 1810 | // case, this should make no difference to the calling application. You may find it in |
| 1811 | // State::getFloatv. |
| 1812 | switch (pname) |
| 1813 | { |
| 1814 | case GL_ARRAY_BUFFER_BINDING: *params = mArrayBuffer.id(); break; |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1815 | case GL_DRAW_INDIRECT_BUFFER_BINDING: |
| 1816 | *params = mDrawIndirectBuffer.id(); |
| 1817 | break; |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 1818 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: *params = getVertexArray()->getElementArrayBuffer().id(); break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1819 | //case GL_FRAMEBUFFER_BINDING: // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE |
| 1820 | case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE: *params = mDrawFramebuffer->id(); break; |
| 1821 | case GL_READ_FRAMEBUFFER_BINDING_ANGLE: *params = mReadFramebuffer->id(); break; |
| 1822 | case GL_RENDERBUFFER_BINDING: *params = mRenderbuffer.id(); break; |
| 1823 | case GL_VERTEX_ARRAY_BINDING: *params = mVertexArray->id(); break; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1824 | case GL_CURRENT_PROGRAM: *params = mProgram ? mProgram->id() : 0; break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1825 | case GL_PACK_ALIGNMENT: *params = mPack.alignment; break; |
| 1826 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: *params = mPack.reverseRowOrder; break; |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1827 | case GL_PACK_ROW_LENGTH: |
| 1828 | *params = mPack.rowLength; |
| 1829 | break; |
| 1830 | case GL_PACK_SKIP_ROWS: |
| 1831 | *params = mPack.skipRows; |
| 1832 | break; |
| 1833 | case GL_PACK_SKIP_PIXELS: |
| 1834 | *params = mPack.skipPixels; |
| 1835 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1836 | case GL_UNPACK_ALIGNMENT: *params = mUnpack.alignment; break; |
Minmin Gong | b8aee3b | 2015-01-27 14:42:36 -0800 | [diff] [blame] | 1837 | case GL_UNPACK_ROW_LENGTH: *params = mUnpack.rowLength; break; |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1838 | case GL_UNPACK_IMAGE_HEIGHT: |
| 1839 | *params = mUnpack.imageHeight; |
| 1840 | break; |
| 1841 | case GL_UNPACK_SKIP_IMAGES: |
| 1842 | *params = mUnpack.skipImages; |
| 1843 | break; |
| 1844 | case GL_UNPACK_SKIP_ROWS: |
| 1845 | *params = mUnpack.skipRows; |
| 1846 | break; |
| 1847 | case GL_UNPACK_SKIP_PIXELS: |
| 1848 | *params = mUnpack.skipPixels; |
| 1849 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1850 | case GL_GENERATE_MIPMAP_HINT: *params = mGenerateMipmapHint; break; |
| 1851 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: *params = mFragmentShaderDerivativeHint; break; |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1852 | case GL_ACTIVE_TEXTURE: |
| 1853 | *params = (static_cast<GLint>(mActiveSampler) + GL_TEXTURE0); |
| 1854 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1855 | case GL_STENCIL_FUNC: *params = mDepthStencil.stencilFunc; break; |
| 1856 | case GL_STENCIL_REF: *params = mStencilRef; break; |
| 1857 | case GL_STENCIL_VALUE_MASK: *params = clampToInt(mDepthStencil.stencilMask); break; |
| 1858 | case GL_STENCIL_BACK_FUNC: *params = mDepthStencil.stencilBackFunc; break; |
| 1859 | case GL_STENCIL_BACK_REF: *params = mStencilBackRef; break; |
| 1860 | case GL_STENCIL_BACK_VALUE_MASK: *params = clampToInt(mDepthStencil.stencilBackMask); break; |
| 1861 | case GL_STENCIL_FAIL: *params = mDepthStencil.stencilFail; break; |
| 1862 | case GL_STENCIL_PASS_DEPTH_FAIL: *params = mDepthStencil.stencilPassDepthFail; break; |
| 1863 | case GL_STENCIL_PASS_DEPTH_PASS: *params = mDepthStencil.stencilPassDepthPass; break; |
| 1864 | case GL_STENCIL_BACK_FAIL: *params = mDepthStencil.stencilBackFail; break; |
| 1865 | case GL_STENCIL_BACK_PASS_DEPTH_FAIL: *params = mDepthStencil.stencilBackPassDepthFail; break; |
| 1866 | case GL_STENCIL_BACK_PASS_DEPTH_PASS: *params = mDepthStencil.stencilBackPassDepthPass; break; |
| 1867 | case GL_DEPTH_FUNC: *params = mDepthStencil.depthFunc; break; |
| 1868 | case GL_BLEND_SRC_RGB: *params = mBlend.sourceBlendRGB; break; |
| 1869 | case GL_BLEND_SRC_ALPHA: *params = mBlend.sourceBlendAlpha; break; |
| 1870 | case GL_BLEND_DST_RGB: *params = mBlend.destBlendRGB; break; |
| 1871 | case GL_BLEND_DST_ALPHA: *params = mBlend.destBlendAlpha; break; |
| 1872 | case GL_BLEND_EQUATION_RGB: *params = mBlend.blendEquationRGB; break; |
| 1873 | case GL_BLEND_EQUATION_ALPHA: *params = mBlend.blendEquationAlpha; break; |
| 1874 | case GL_STENCIL_WRITEMASK: *params = clampToInt(mDepthStencil.stencilWritemask); break; |
| 1875 | case GL_STENCIL_BACK_WRITEMASK: *params = clampToInt(mDepthStencil.stencilBackWritemask); break; |
| 1876 | case GL_STENCIL_CLEAR_VALUE: *params = mStencilClearValue; break; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1877 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 1878 | *params = mReadFramebuffer->getImplementationColorReadType(context); |
| 1879 | break; |
| 1880 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 1881 | *params = mReadFramebuffer->getImplementationColorReadFormat(context); |
| 1882 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1883 | case GL_SAMPLE_BUFFERS: |
| 1884 | case GL_SAMPLES: |
| 1885 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1886 | Framebuffer *framebuffer = mDrawFramebuffer; |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1887 | if (framebuffer->checkStatus(context) == GL_FRAMEBUFFER_COMPLETE) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1888 | { |
| 1889 | switch (pname) |
| 1890 | { |
Jamie Madill | a0016b7 | 2017-07-14 14:30:46 -0400 | [diff] [blame] | 1891 | case GL_SAMPLE_BUFFERS: |
| 1892 | if (framebuffer->getSamples(context) != 0) |
| 1893 | { |
| 1894 | *params = 1; |
| 1895 | } |
| 1896 | else |
| 1897 | { |
| 1898 | *params = 0; |
| 1899 | } |
| 1900 | break; |
| 1901 | case GL_SAMPLES: |
| 1902 | *params = framebuffer->getSamples(context); |
| 1903 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1904 | } |
| 1905 | } |
| 1906 | else |
| 1907 | { |
| 1908 | *params = 0; |
| 1909 | } |
| 1910 | } |
| 1911 | break; |
| 1912 | case GL_VIEWPORT: |
| 1913 | params[0] = mViewport.x; |
| 1914 | params[1] = mViewport.y; |
| 1915 | params[2] = mViewport.width; |
| 1916 | params[3] = mViewport.height; |
| 1917 | break; |
| 1918 | case GL_SCISSOR_BOX: |
| 1919 | params[0] = mScissor.x; |
| 1920 | params[1] = mScissor.y; |
| 1921 | params[2] = mScissor.width; |
| 1922 | params[3] = mScissor.height; |
| 1923 | break; |
| 1924 | case GL_CULL_FACE_MODE: *params = mRasterizer.cullMode; break; |
| 1925 | case GL_FRONT_FACE: *params = mRasterizer.frontFace; break; |
| 1926 | case GL_RED_BITS: |
| 1927 | case GL_GREEN_BITS: |
| 1928 | case GL_BLUE_BITS: |
| 1929 | case GL_ALPHA_BITS: |
| 1930 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1931 | Framebuffer *framebuffer = getDrawFramebuffer(); |
| 1932 | const FramebufferAttachment *colorbuffer = framebuffer->getFirstColorbuffer(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1933 | |
| 1934 | if (colorbuffer) |
| 1935 | { |
| 1936 | switch (pname) |
| 1937 | { |
| 1938 | case GL_RED_BITS: *params = colorbuffer->getRedSize(); break; |
| 1939 | case GL_GREEN_BITS: *params = colorbuffer->getGreenSize(); break; |
| 1940 | case GL_BLUE_BITS: *params = colorbuffer->getBlueSize(); break; |
| 1941 | case GL_ALPHA_BITS: *params = colorbuffer->getAlphaSize(); break; |
| 1942 | } |
| 1943 | } |
| 1944 | else |
| 1945 | { |
| 1946 | *params = 0; |
| 1947 | } |
| 1948 | } |
| 1949 | break; |
| 1950 | case GL_DEPTH_BITS: |
| 1951 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1952 | const Framebuffer *framebuffer = getDrawFramebuffer(); |
| 1953 | const FramebufferAttachment *depthbuffer = framebuffer->getDepthbuffer(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1954 | |
| 1955 | if (depthbuffer) |
| 1956 | { |
| 1957 | *params = depthbuffer->getDepthSize(); |
| 1958 | } |
| 1959 | else |
| 1960 | { |
| 1961 | *params = 0; |
| 1962 | } |
| 1963 | } |
| 1964 | break; |
| 1965 | case GL_STENCIL_BITS: |
| 1966 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1967 | const Framebuffer *framebuffer = getDrawFramebuffer(); |
| 1968 | const FramebufferAttachment *stencilbuffer = framebuffer->getStencilbuffer(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1969 | |
| 1970 | if (stencilbuffer) |
| 1971 | { |
| 1972 | *params = stencilbuffer->getStencilSize(); |
| 1973 | } |
| 1974 | else |
| 1975 | { |
| 1976 | *params = 0; |
| 1977 | } |
| 1978 | } |
| 1979 | break; |
| 1980 | case GL_TEXTURE_BINDING_2D: |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1981 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1982 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_2D); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1983 | break; |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1984 | case GL_TEXTURE_BINDING_RECTANGLE_ANGLE: |
| 1985 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
| 1986 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), |
| 1987 | GL_TEXTURE_RECTANGLE_ANGLE); |
| 1988 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1989 | case GL_TEXTURE_BINDING_CUBE_MAP: |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1990 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1991 | *params = |
| 1992 | getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_CUBE_MAP); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1993 | break; |
| 1994 | case GL_TEXTURE_BINDING_3D: |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1995 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1996 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_3D); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1997 | break; |
| 1998 | case GL_TEXTURE_BINDING_2D_ARRAY: |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1999 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 2000 | *params = |
| 2001 | getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_2D_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2002 | break; |
JiangYizhou | 24fe74c | 2017-07-06 16:56:50 +0800 | [diff] [blame] | 2003 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE: |
| 2004 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
| 2005 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), |
| 2006 | GL_TEXTURE_2D_MULTISAMPLE); |
| 2007 | break; |
John Bauman | 1831918 | 2016-09-28 14:22:27 -0700 | [diff] [blame] | 2008 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 2009 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
| 2010 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), |
| 2011 | GL_TEXTURE_EXTERNAL_OES); |
| 2012 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2013 | case GL_UNIFORM_BUFFER_BINDING: |
| 2014 | *params = mGenericUniformBuffer.id(); |
| 2015 | break; |
Frank Henigman | 22581ff | 2015-11-06 14:25:54 -0500 | [diff] [blame] | 2016 | case GL_TRANSFORM_FEEDBACK_BINDING: |
Frank Henigman | b0f0b81 | 2015-11-21 17:49:29 -0500 | [diff] [blame] | 2017 | *params = mTransformFeedback.id(); |
Frank Henigman | 22581ff | 2015-11-06 14:25:54 -0500 | [diff] [blame] | 2018 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2019 | case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 2020 | *params = mTransformFeedback->getGenericBuffer().id(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2021 | break; |
| 2022 | case GL_COPY_READ_BUFFER_BINDING: |
| 2023 | *params = mCopyReadBuffer.id(); |
| 2024 | break; |
| 2025 | case GL_COPY_WRITE_BUFFER_BINDING: |
| 2026 | *params = mCopyWriteBuffer.id(); |
| 2027 | break; |
| 2028 | case GL_PIXEL_PACK_BUFFER_BINDING: |
| 2029 | *params = mPack.pixelBuffer.id(); |
| 2030 | break; |
| 2031 | case GL_PIXEL_UNPACK_BUFFER_BINDING: |
| 2032 | *params = mUnpack.pixelBuffer.id(); |
| 2033 | break; |
Olli Etuaho | 86821db | 2016-03-04 12:05:47 +0200 | [diff] [blame] | 2034 | case GL_READ_BUFFER: |
| 2035 | *params = mReadFramebuffer->getReadBufferState(); |
| 2036 | break; |
| 2037 | case GL_SAMPLER_BINDING: |
| 2038 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
| 2039 | *params = getSamplerId(static_cast<GLuint>(mActiveSampler)); |
| 2040 | break; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2041 | case GL_DEBUG_LOGGED_MESSAGES: |
| 2042 | *params = static_cast<GLint>(mDebug.getMessageCount()); |
| 2043 | break; |
| 2044 | case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH: |
| 2045 | *params = static_cast<GLint>(mDebug.getNextMessageLength()); |
| 2046 | break; |
| 2047 | case GL_DEBUG_GROUP_STACK_DEPTH: |
| 2048 | *params = static_cast<GLint>(mDebug.getGroupStackDepth()); |
| 2049 | break; |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 2050 | case GL_MULTISAMPLE_EXT: |
| 2051 | *params = static_cast<GLint>(mMultiSampling); |
| 2052 | break; |
| 2053 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 2054 | *params = static_cast<GLint>(mSampleAlphaToOne); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 2055 | case GL_COVERAGE_MODULATION_CHROMIUM: |
| 2056 | *params = static_cast<GLint>(mCoverageModulation); |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 2057 | break; |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2058 | case GL_ATOMIC_COUNTER_BUFFER_BINDING: |
| 2059 | *params = mGenericAtomicCounterBuffer.id(); |
| 2060 | break; |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 2061 | case GL_SHADER_STORAGE_BUFFER_BINDING: |
| 2062 | *params = mGenericShaderStorageBuffer.id(); |
| 2063 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2064 | default: |
| 2065 | UNREACHABLE(); |
| 2066 | break; |
| 2067 | } |
| 2068 | } |
| 2069 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2070 | void State::getPointerv(GLenum pname, void **params) const |
| 2071 | { |
| 2072 | switch (pname) |
| 2073 | { |
| 2074 | case GL_DEBUG_CALLBACK_FUNCTION: |
| 2075 | *params = reinterpret_cast<void *>(mDebug.getCallback()); |
| 2076 | break; |
| 2077 | case GL_DEBUG_CALLBACK_USER_PARAM: |
| 2078 | *params = const_cast<void *>(mDebug.getUserParam()); |
| 2079 | break; |
| 2080 | default: |
| 2081 | UNREACHABLE(); |
| 2082 | break; |
| 2083 | } |
| 2084 | } |
| 2085 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2086 | void State::getIntegeri_v(GLenum target, GLuint index, GLint *data) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2087 | { |
| 2088 | switch (target) |
| 2089 | { |
| 2090 | case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2091 | ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount()); |
| 2092 | *data = mTransformFeedback->getIndexedBuffer(index).id(); |
| 2093 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2094 | case GL_UNIFORM_BUFFER_BINDING: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2095 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
| 2096 | *data = mUniformBuffers[index].id(); |
| 2097 | break; |
| 2098 | case GL_ATOMIC_COUNTER_BUFFER_BINDING: |
| 2099 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
| 2100 | *data = mAtomicCounterBuffers[index].id(); |
| 2101 | break; |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 2102 | case GL_SHADER_STORAGE_BUFFER_BINDING: |
| 2103 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
| 2104 | *data = mShaderStorageBuffers[index].id(); |
| 2105 | break; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2106 | case GL_VERTEX_BINDING_BUFFER: |
| 2107 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 2108 | *data = mVertexArray->getVertexBinding(index).getBuffer().id(); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2109 | break; |
| 2110 | case GL_VERTEX_BINDING_DIVISOR: |
| 2111 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 2112 | *data = mVertexArray->getVertexBinding(index).getDivisor(); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2113 | break; |
| 2114 | case GL_VERTEX_BINDING_OFFSET: |
| 2115 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 2116 | *data = static_cast<GLuint>(mVertexArray->getVertexBinding(index).getOffset()); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2117 | break; |
| 2118 | case GL_VERTEX_BINDING_STRIDE: |
| 2119 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 2120 | *data = mVertexArray->getVertexBinding(index).getStride(); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2121 | break; |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame^] | 2122 | case GL_SAMPLE_MASK_VALUE: |
| 2123 | ASSERT(static_cast<size_t>(index) < mSampleMaskValues.size()); |
| 2124 | *data = mSampleMaskValues[index]; |
| 2125 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2126 | default: |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2127 | UNREACHABLE(); |
| 2128 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2129 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2130 | } |
| 2131 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2132 | void State::getInteger64i_v(GLenum target, GLuint index, GLint64 *data) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2133 | { |
| 2134 | switch (target) |
| 2135 | { |
| 2136 | case GL_TRANSFORM_FEEDBACK_BUFFER_START: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2137 | ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount()); |
| 2138 | *data = mTransformFeedback->getIndexedBuffer(index).getOffset(); |
| 2139 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2140 | case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2141 | ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount()); |
| 2142 | *data = mTransformFeedback->getIndexedBuffer(index).getSize(); |
| 2143 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2144 | case GL_UNIFORM_BUFFER_START: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2145 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
| 2146 | *data = mUniformBuffers[index].getOffset(); |
| 2147 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2148 | case GL_UNIFORM_BUFFER_SIZE: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2149 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
| 2150 | *data = mUniformBuffers[index].getSize(); |
| 2151 | break; |
| 2152 | case GL_ATOMIC_COUNTER_BUFFER_START: |
| 2153 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
| 2154 | *data = mAtomicCounterBuffers[index].getOffset(); |
| 2155 | break; |
| 2156 | case GL_ATOMIC_COUNTER_BUFFER_SIZE: |
| 2157 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
| 2158 | *data = mAtomicCounterBuffers[index].getSize(); |
| 2159 | break; |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 2160 | case GL_SHADER_STORAGE_BUFFER_START: |
| 2161 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
| 2162 | *data = mShaderStorageBuffers[index].getOffset(); |
| 2163 | break; |
| 2164 | case GL_SHADER_STORAGE_BUFFER_SIZE: |
| 2165 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
| 2166 | *data = mShaderStorageBuffers[index].getSize(); |
| 2167 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2168 | default: |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2169 | UNREACHABLE(); |
| 2170 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2171 | } |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2172 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2173 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2174 | void State::getBooleani_v(GLenum target, GLuint index, GLboolean *data) |
| 2175 | { |
| 2176 | UNREACHABLE(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2177 | } |
| 2178 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2179 | bool State::hasMappedBuffer(GLenum target) const |
| 2180 | { |
| 2181 | if (target == GL_ARRAY_BUFFER) |
| 2182 | { |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 2183 | const VertexArray *vao = getVertexArray(); |
Jamie Madill | eea3a6e | 2015-04-15 10:02:48 -0400 | [diff] [blame] | 2184 | const auto &vertexAttribs = vao->getVertexAttributes(); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 2185 | const auto &vertexBindings = vao->getVertexBindings(); |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 2186 | size_t maxEnabledAttrib = vao->getMaxEnabledAttribute(); |
Jamie Madill | aebf9dd | 2015-04-28 12:39:07 -0400 | [diff] [blame] | 2187 | for (size_t attribIndex = 0; attribIndex < maxEnabledAttrib; attribIndex++) |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2188 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2189 | const VertexAttribute &vertexAttrib = vertexAttribs[attribIndex]; |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 2190 | auto *boundBuffer = vertexBindings[vertexAttrib.bindingIndex].getBuffer().get(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2191 | if (vertexAttrib.enabled && boundBuffer && boundBuffer->isMapped()) |
| 2192 | { |
| 2193 | return true; |
| 2194 | } |
| 2195 | } |
| 2196 | |
| 2197 | return false; |
| 2198 | } |
| 2199 | else |
| 2200 | { |
| 2201 | Buffer *buffer = getTargetBuffer(target); |
| 2202 | return (buffer && buffer->isMapped()); |
| 2203 | } |
| 2204 | } |
| 2205 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2206 | void State::syncDirtyObjects(const Context *context) |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2207 | { |
| 2208 | if (!mDirtyObjects.any()) |
| 2209 | return; |
| 2210 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2211 | syncDirtyObjects(context, mDirtyObjects); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2212 | } |
| 2213 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2214 | void State::syncDirtyObjects(const Context *context, const DirtyObjects &bitset) |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2215 | { |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 2216 | for (auto dirtyObject : bitset) |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2217 | { |
| 2218 | switch (dirtyObject) |
| 2219 | { |
| 2220 | case DIRTY_OBJECT_READ_FRAMEBUFFER: |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2221 | ASSERT(mReadFramebuffer); |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2222 | mReadFramebuffer->syncState(context); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2223 | break; |
| 2224 | case DIRTY_OBJECT_DRAW_FRAMEBUFFER: |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2225 | ASSERT(mDrawFramebuffer); |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2226 | mDrawFramebuffer->syncState(context); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2227 | break; |
| 2228 | case DIRTY_OBJECT_VERTEX_ARRAY: |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2229 | ASSERT(mVertexArray); |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2230 | mVertexArray->syncState(context); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2231 | break; |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2232 | case DIRTY_OBJECT_PROGRAM_TEXTURES: |
| 2233 | syncProgramTextures(context); |
| 2234 | break; |
| 2235 | |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2236 | default: |
| 2237 | UNREACHABLE(); |
| 2238 | break; |
| 2239 | } |
| 2240 | } |
| 2241 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2242 | mDirtyObjects &= ~bitset; |
| 2243 | } |
| 2244 | |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2245 | void State::syncProgramTextures(const Context *context) |
| 2246 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2247 | // TODO(jmadill): Fine-grained updates. |
| 2248 | if (!mProgram) |
| 2249 | { |
| 2250 | return; |
| 2251 | } |
| 2252 | |
| 2253 | ASSERT(mDirtyObjects[DIRTY_OBJECT_PROGRAM_TEXTURES]); |
| 2254 | mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS); |
| 2255 | |
Jamie Madill | 0f80ed8 | 2017-09-19 00:24:56 -0400 | [diff] [blame] | 2256 | ActiveTextureMask newActiveTextures; |
| 2257 | |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2258 | for (const SamplerBinding &samplerBinding : mProgram->getSamplerBindings()) |
| 2259 | { |
| 2260 | if (samplerBinding.unreferenced) |
| 2261 | continue; |
| 2262 | |
| 2263 | GLenum textureType = samplerBinding.textureType; |
| 2264 | for (GLuint textureUnitIndex : samplerBinding.boundTextureUnits) |
| 2265 | { |
| 2266 | Texture *texture = getSamplerTexture(textureUnitIndex, textureType); |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2267 | Sampler *sampler = getSampler(textureUnitIndex); |
Jamie Madill | 0f80ed8 | 2017-09-19 00:24:56 -0400 | [diff] [blame] | 2268 | ASSERT(static_cast<size_t>(textureUnitIndex) < mCompleteTextureCache.size()); |
| 2269 | ASSERT(static_cast<size_t>(textureUnitIndex) < newActiveTextures.size()); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2270 | |
| 2271 | if (texture != nullptr) |
| 2272 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2273 | // Mark the texture binding bit as dirty if the texture completeness changes. |
| 2274 | // TODO(jmadill): Use specific dirty bit for completeness change. |
| 2275 | if (texture->isSamplerComplete(context, sampler)) |
| 2276 | { |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2277 | texture->syncState(); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2278 | mCompleteTextureCache[textureUnitIndex] = texture; |
| 2279 | } |
Jamie Madill | 0f80ed8 | 2017-09-19 00:24:56 -0400 | [diff] [blame] | 2280 | else |
| 2281 | { |
| 2282 | mCompleteTextureCache[textureUnitIndex] = nullptr; |
| 2283 | } |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2284 | |
| 2285 | // Bind the texture unconditionally, to recieve completeness change notifications. |
| 2286 | mCompleteTextureBindings[textureUnitIndex].bind(texture->getDirtyChannel()); |
Jamie Madill | 0f80ed8 | 2017-09-19 00:24:56 -0400 | [diff] [blame] | 2287 | newActiveTextures.set(textureUnitIndex); |
| 2288 | mCompleteTexturesMask.set(textureUnitIndex); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2289 | } |
| 2290 | |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2291 | if (sampler != nullptr) |
| 2292 | { |
| 2293 | sampler->syncState(context); |
| 2294 | } |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2295 | } |
| 2296 | } |
Jamie Madill | 0f80ed8 | 2017-09-19 00:24:56 -0400 | [diff] [blame] | 2297 | |
| 2298 | // Unset now missing textures. |
| 2299 | ActiveTextureMask negativeMask = mCompleteTexturesMask & ~newActiveTextures; |
| 2300 | if (negativeMask.any()) |
| 2301 | { |
| 2302 | for (auto textureIndex : negativeMask) |
| 2303 | { |
| 2304 | mCompleteTextureBindings[textureIndex].reset(); |
| 2305 | mCompleteTextureCache[textureIndex] = nullptr; |
| 2306 | mCompleteTexturesMask.reset(textureIndex); |
| 2307 | } |
| 2308 | } |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2309 | } |
| 2310 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2311 | void State::syncDirtyObject(const Context *context, GLenum target) |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2312 | { |
| 2313 | DirtyObjects localSet; |
| 2314 | |
| 2315 | switch (target) |
| 2316 | { |
| 2317 | case GL_READ_FRAMEBUFFER: |
| 2318 | localSet.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 2319 | break; |
| 2320 | case GL_DRAW_FRAMEBUFFER: |
| 2321 | localSet.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 2322 | break; |
| 2323 | case GL_FRAMEBUFFER: |
| 2324 | localSet.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 2325 | localSet.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 2326 | break; |
| 2327 | case GL_VERTEX_ARRAY: |
| 2328 | localSet.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 2329 | break; |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2330 | case GL_TEXTURE: |
| 2331 | case GL_SAMPLER: |
| 2332 | case GL_PROGRAM: |
| 2333 | localSet.set(DIRTY_OBJECT_PROGRAM_TEXTURES); |
| 2334 | break; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2335 | } |
| 2336 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2337 | syncDirtyObjects(context, localSet); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | void State::setObjectDirty(GLenum target) |
| 2341 | { |
| 2342 | switch (target) |
| 2343 | { |
| 2344 | case GL_READ_FRAMEBUFFER: |
| 2345 | mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 2346 | break; |
| 2347 | case GL_DRAW_FRAMEBUFFER: |
| 2348 | mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 2349 | break; |
| 2350 | case GL_FRAMEBUFFER: |
| 2351 | mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 2352 | mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 2353 | break; |
| 2354 | case GL_VERTEX_ARRAY: |
| 2355 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 2356 | break; |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2357 | case GL_TEXTURE: |
| 2358 | case GL_SAMPLER: |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2359 | case GL_PROGRAM: |
| 2360 | mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES); |
| 2361 | mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS); |
| 2362 | break; |
Jamie Madill | a779b61 | 2017-07-24 11:46:05 -0400 | [diff] [blame] | 2363 | } |
| 2364 | } |
| 2365 | |
| 2366 | void State::onProgramExecutableChange(Program *program) |
| 2367 | { |
| 2368 | // OpenGL Spec: |
| 2369 | // "If LinkProgram or ProgramBinary successfully re-links a program object |
| 2370 | // that was already in use as a result of a previous call to UseProgram, then the |
| 2371 | // generated executable code will be installed as part of the current rendering state." |
| 2372 | if (program->isLinked() && mProgram == program) |
| 2373 | { |
| 2374 | mDirtyBits.set(DIRTY_BIT_PROGRAM_EXECUTABLE); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2375 | mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2376 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2377 | } |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2378 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 2379 | void State::setImageUnit(const Context *context, |
| 2380 | GLuint unit, |
| 2381 | Texture *texture, |
| 2382 | GLint level, |
| 2383 | GLboolean layered, |
| 2384 | GLint layer, |
| 2385 | GLenum access, |
| 2386 | GLenum format) |
| 2387 | { |
| 2388 | mImageUnits[unit].texture.set(context, texture); |
| 2389 | mImageUnits[unit].level = level; |
| 2390 | mImageUnits[unit].layered = layered; |
| 2391 | mImageUnits[unit].layer = layer; |
| 2392 | mImageUnits[unit].access = access; |
| 2393 | mImageUnits[unit].format = format; |
| 2394 | } |
| 2395 | |
| 2396 | const ImageUnit &State::getImageUnit(GLuint unit) const |
| 2397 | { |
| 2398 | return mImageUnits[unit]; |
| 2399 | } |
| 2400 | |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2401 | // Handle a dirty texture event. |
| 2402 | void State::signal(uint32_t textureIndex) |
| 2403 | { |
| 2404 | // Conservatively assume all textures are dirty. |
| 2405 | // TODO(jmadill): More fine-grained update. |
| 2406 | mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES); |
| 2407 | } |
| 2408 | |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2409 | } // namespace gl |