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), |
| 48 | mStencilRef(0), |
| 49 | mStencilBackRef(0), |
| 50 | mLineWidth(0), |
| 51 | mGenerateMipmapHint(GL_NONE), |
| 52 | mFragmentShaderDerivativeHint(GL_NONE), |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 53 | mBindGeneratesResource(true), |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 54 | mClientArraysEnabled(true), |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 55 | mNearZ(0), |
| 56 | mFarZ(0), |
| 57 | mReadFramebuffer(nullptr), |
| 58 | mDrawFramebuffer(nullptr), |
| 59 | mProgram(nullptr), |
| 60 | mVertexArray(nullptr), |
| 61 | mActiveSampler(0), |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 62 | mPrimitiveRestart(false), |
| 63 | mMultiSampling(false), |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 64 | mSampleAlphaToOne(false), |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 65 | mFramebufferSRGB(true), |
| 66 | mRobustResourceInit(false) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 67 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | State::~State() |
| 71 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 74 | void State::initialize(const Context *context, |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 75 | bool debug, |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 76 | bool bindGeneratesResource, |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 77 | bool clientArraysEnabled, |
| 78 | bool robustResourceInit) |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 79 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 80 | const Caps &caps = context->getCaps(); |
| 81 | const Extensions &extensions = context->getExtensions(); |
| 82 | const Version &clientVersion = context->getClientVersion(); |
| 83 | |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 84 | mMaxDrawBuffers = caps.maxDrawBuffers; |
| 85 | mMaxCombinedTextureImageUnits = caps.maxCombinedTextureImageUnits; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 86 | |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 87 | setColorClearValue(0.0f, 0.0f, 0.0f, 0.0f); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 88 | |
| 89 | mDepthClearValue = 1.0f; |
| 90 | mStencilClearValue = 0; |
| 91 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 92 | mScissorTest = false; |
| 93 | mScissor.x = 0; |
| 94 | mScissor.y = 0; |
| 95 | mScissor.width = 0; |
| 96 | mScissor.height = 0; |
| 97 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 98 | mBlendColor.red = 0; |
| 99 | mBlendColor.green = 0; |
| 100 | mBlendColor.blue = 0; |
| 101 | mBlendColor.alpha = 0; |
| 102 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 103 | mStencilRef = 0; |
| 104 | mStencilBackRef = 0; |
| 105 | |
| 106 | mSampleCoverage = false; |
| 107 | mSampleCoverageValue = 1.0f; |
| 108 | mSampleCoverageInvert = false; |
| 109 | mGenerateMipmapHint = GL_DONT_CARE; |
| 110 | mFragmentShaderDerivativeHint = GL_DONT_CARE; |
| 111 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 112 | mBindGeneratesResource = bindGeneratesResource; |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 113 | mClientArraysEnabled = clientArraysEnabled; |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 114 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 115 | mLineWidth = 1.0f; |
| 116 | |
| 117 | mViewport.x = 0; |
| 118 | mViewport.y = 0; |
| 119 | mViewport.width = 0; |
| 120 | mViewport.height = 0; |
| 121 | mNearZ = 0.0f; |
| 122 | mFarZ = 1.0f; |
| 123 | |
| 124 | mBlend.colorMaskRed = true; |
| 125 | mBlend.colorMaskGreen = true; |
| 126 | mBlend.colorMaskBlue = true; |
| 127 | mBlend.colorMaskAlpha = true; |
| 128 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 129 | mActiveSampler = 0; |
| 130 | |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 131 | mVertexAttribCurrentValues.resize(caps.maxVertexAttributes); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 132 | |
Geoff Lang | 4dc3af0 | 2016-11-18 14:09:27 -0500 | [diff] [blame] | 133 | mUniformBuffers.resize(caps.maxUniformBufferBindings); |
Shannon Woods | f3acaf9 | 2014-09-23 18:07:11 -0400 | [diff] [blame] | 134 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 135 | mSamplerTextures[GL_TEXTURE_2D].resize(caps.maxCombinedTextureImageUnits); |
| 136 | mSamplerTextures[GL_TEXTURE_CUBE_MAP].resize(caps.maxCombinedTextureImageUnits); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 137 | if (clientVersion >= Version(3, 0)) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 138 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 139 | // TODO: These could also be enabled via extension |
| 140 | mSamplerTextures[GL_TEXTURE_2D_ARRAY].resize(caps.maxCombinedTextureImageUnits); |
| 141 | mSamplerTextures[GL_TEXTURE_3D].resize(caps.maxCombinedTextureImageUnits); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 142 | } |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 143 | if (clientVersion >= Version(3, 1)) |
| 144 | { |
| 145 | mSamplerTextures[GL_TEXTURE_2D_MULTISAMPLE].resize(caps.maxCombinedTextureImageUnits); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 146 | |
| 147 | mAtomicCounterBuffers.resize(caps.maxAtomicCounterBufferBindings); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 148 | mShaderStorageBuffers.resize(caps.maxShaderStorageBufferBindings); |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 149 | mImageUnits.resize(caps.maxImageUnits); |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 150 | } |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 151 | if (extensions.eglImageExternal || extensions.eglStreamConsumerExternal) |
| 152 | { |
| 153 | mSamplerTextures[GL_TEXTURE_EXTERNAL_OES].resize(caps.maxCombinedTextureImageUnits); |
| 154 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 155 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 156 | mSamplers.resize(caps.maxCombinedTextureImageUnits); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 157 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 158 | mActiveQueries[GL_ANY_SAMPLES_PASSED].set(context, nullptr); |
| 159 | mActiveQueries[GL_ANY_SAMPLES_PASSED_CONSERVATIVE].set(context, nullptr); |
| 160 | mActiveQueries[GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN].set(context, nullptr); |
| 161 | mActiveQueries[GL_TIME_ELAPSED_EXT].set(context, nullptr); |
| 162 | mActiveQueries[GL_COMMANDS_COMPLETED_CHROMIUM].set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 163 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 164 | mProgram = nullptr; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 165 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 166 | mReadFramebuffer = nullptr; |
| 167 | mDrawFramebuffer = nullptr; |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 168 | |
| 169 | mPrimitiveRestart = false; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 170 | |
| 171 | mDebug.setOutputEnabled(debug); |
| 172 | mDebug.setMaxLoggedMessages(extensions.maxDebugLoggedMessages); |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 173 | |
| 174 | if (extensions.framebufferMultisample) |
| 175 | { |
| 176 | mMultiSampling = true; |
| 177 | mSampleAlphaToOne = false; |
| 178 | } |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 179 | |
| 180 | mCoverageModulation = GL_NONE; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 181 | |
| 182 | angle::Matrix<GLfloat>::setToIdentity(mPathMatrixProj); |
| 183 | angle::Matrix<GLfloat>::setToIdentity(mPathMatrixMV); |
| 184 | mPathStencilFunc = GL_ALWAYS; |
| 185 | mPathStencilRef = 0; |
| 186 | mPathStencilMask = std::numeric_limits<GLuint>::max(); |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 187 | |
| 188 | mRobustResourceInit = robustResourceInit; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 189 | } |
| 190 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 191 | void State::reset(const Context *context) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 192 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 193 | for (TextureBindingMap::iterator bindingVec = mSamplerTextures.begin(); bindingVec != mSamplerTextures.end(); bindingVec++) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 194 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 195 | TextureBindingVector &textureVector = bindingVec->second; |
| 196 | for (size_t textureIdx = 0; textureIdx < textureVector.size(); textureIdx++) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 197 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 198 | textureVector[textureIdx].set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 199 | } |
| 200 | } |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 201 | for (size_t samplerIdx = 0; samplerIdx < mSamplers.size(); samplerIdx++) |
| 202 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 203 | mSamplers[samplerIdx].set(context, nullptr); |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 204 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 205 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 206 | for (auto &imageUnit : mImageUnits) |
| 207 | { |
| 208 | imageUnit.texture.set(context, nullptr); |
| 209 | imageUnit.level = 0; |
| 210 | imageUnit.layered = false; |
| 211 | imageUnit.layer = 0; |
| 212 | imageUnit.access = GL_READ_ONLY; |
| 213 | imageUnit.format = GL_R32UI; |
| 214 | } |
| 215 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 216 | mArrayBuffer.set(context, nullptr); |
| 217 | mDrawIndirectBuffer.set(context, nullptr); |
| 218 | mRenderbuffer.set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 219 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 220 | if (mProgram) |
| 221 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 222 | mProgram->release(context); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 223 | } |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 224 | mProgram = nullptr; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 225 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 226 | mTransformFeedback.set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 227 | |
| 228 | for (State::ActiveQueryMap::iterator i = mActiveQueries.begin(); i != mActiveQueries.end(); i++) |
| 229 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 230 | i->second.set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 231 | } |
| 232 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 233 | mGenericUniformBuffer.set(context, nullptr); |
Shannon Woods | 8299bb0 | 2014-09-26 18:55:43 -0400 | [diff] [blame] | 234 | for (BufferVector::iterator bufItr = mUniformBuffers.begin(); bufItr != mUniformBuffers.end(); ++bufItr) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 235 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 236 | bufItr->set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 237 | } |
| 238 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 239 | mCopyReadBuffer.set(context, nullptr); |
| 240 | mCopyWriteBuffer.set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 241 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 242 | mPack.pixelBuffer.set(context, nullptr); |
| 243 | mUnpack.pixelBuffer.set(context, nullptr); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 244 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 245 | mGenericAtomicCounterBuffer.set(context, nullptr); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 246 | for (auto &buf : mAtomicCounterBuffers) |
| 247 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 248 | buf.set(context, nullptr); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 249 | } |
| 250 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 251 | mGenericShaderStorageBuffer.set(context, nullptr); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 252 | for (auto &buf : mShaderStorageBuffers) |
| 253 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 254 | buf.set(context, nullptr); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 255 | } |
| 256 | |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 257 | mProgram = nullptr; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 258 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 259 | angle::Matrix<GLfloat>::setToIdentity(mPathMatrixProj); |
| 260 | angle::Matrix<GLfloat>::setToIdentity(mPathMatrixMV); |
| 261 | mPathStencilFunc = GL_ALWAYS; |
| 262 | mPathStencilRef = 0; |
| 263 | mPathStencilMask = std::numeric_limits<GLuint>::max(); |
| 264 | |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 265 | // TODO(jmadill): Is this necessary? |
| 266 | setAllDirtyBits(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | const RasterizerState &State::getRasterizerState() const |
| 270 | { |
| 271 | return mRasterizer; |
| 272 | } |
| 273 | |
| 274 | const BlendState &State::getBlendState() const |
| 275 | { |
| 276 | return mBlend; |
| 277 | } |
| 278 | |
| 279 | const DepthStencilState &State::getDepthStencilState() const |
| 280 | { |
| 281 | return mDepthStencil; |
| 282 | } |
| 283 | |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 284 | void State::setColorClearValue(float red, float green, float blue, float alpha) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 285 | { |
| 286 | mColorClearValue.red = red; |
| 287 | mColorClearValue.green = green; |
| 288 | mColorClearValue.blue = blue; |
| 289 | mColorClearValue.alpha = alpha; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 290 | mDirtyBits.set(DIRTY_BIT_CLEAR_COLOR); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 291 | } |
| 292 | |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 293 | void State::setDepthClearValue(float depth) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 294 | { |
| 295 | mDepthClearValue = depth; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 296 | mDirtyBits.set(DIRTY_BIT_CLEAR_DEPTH); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 297 | } |
| 298 | |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 299 | void State::setStencilClearValue(int stencil) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 300 | { |
| 301 | mStencilClearValue = stencil; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 302 | mDirtyBits.set(DIRTY_BIT_CLEAR_STENCIL); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 303 | } |
| 304 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 305 | void State::setColorMask(bool red, bool green, bool blue, bool alpha) |
| 306 | { |
| 307 | mBlend.colorMaskRed = red; |
| 308 | mBlend.colorMaskGreen = green; |
| 309 | mBlend.colorMaskBlue = blue; |
| 310 | mBlend.colorMaskAlpha = alpha; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 311 | mDirtyBits.set(DIRTY_BIT_COLOR_MASK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | void State::setDepthMask(bool mask) |
| 315 | { |
| 316 | mDepthStencil.depthMask = mask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 317 | mDirtyBits.set(DIRTY_BIT_DEPTH_MASK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | bool State::isRasterizerDiscardEnabled() const |
| 321 | { |
| 322 | return mRasterizer.rasterizerDiscard; |
| 323 | } |
| 324 | |
| 325 | void State::setRasterizerDiscard(bool enabled) |
| 326 | { |
| 327 | mRasterizer.rasterizerDiscard = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 328 | mDirtyBits.set(DIRTY_BIT_RASTERIZER_DISCARD_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | bool State::isCullFaceEnabled() const |
| 332 | { |
| 333 | return mRasterizer.cullFace; |
| 334 | } |
| 335 | |
| 336 | void State::setCullFace(bool enabled) |
| 337 | { |
| 338 | mRasterizer.cullFace = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 339 | mDirtyBits.set(DIRTY_BIT_CULL_FACE_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | void State::setCullMode(GLenum mode) |
| 343 | { |
| 344 | mRasterizer.cullMode = mode; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 345 | mDirtyBits.set(DIRTY_BIT_CULL_FACE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | void State::setFrontFace(GLenum front) |
| 349 | { |
| 350 | mRasterizer.frontFace = front; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 351 | mDirtyBits.set(DIRTY_BIT_FRONT_FACE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | bool State::isDepthTestEnabled() const |
| 355 | { |
| 356 | return mDepthStencil.depthTest; |
| 357 | } |
| 358 | |
| 359 | void State::setDepthTest(bool enabled) |
| 360 | { |
| 361 | mDepthStencil.depthTest = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 362 | mDirtyBits.set(DIRTY_BIT_DEPTH_TEST_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | void State::setDepthFunc(GLenum depthFunc) |
| 366 | { |
| 367 | mDepthStencil.depthFunc = depthFunc; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 368 | mDirtyBits.set(DIRTY_BIT_DEPTH_FUNC); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | void State::setDepthRange(float zNear, float zFar) |
| 372 | { |
| 373 | mNearZ = zNear; |
| 374 | mFarZ = zFar; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 375 | mDirtyBits.set(DIRTY_BIT_DEPTH_RANGE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 376 | } |
| 377 | |
Geoff Lang | d42f5b8 | 2015-04-16 14:03:29 -0400 | [diff] [blame] | 378 | float State::getNearPlane() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 379 | { |
Geoff Lang | d42f5b8 | 2015-04-16 14:03:29 -0400 | [diff] [blame] | 380 | return mNearZ; |
| 381 | } |
| 382 | |
| 383 | float State::getFarPlane() const |
| 384 | { |
| 385 | return mFarZ; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | bool State::isBlendEnabled() const |
| 389 | { |
| 390 | return mBlend.blend; |
| 391 | } |
| 392 | |
| 393 | void State::setBlend(bool enabled) |
| 394 | { |
| 395 | mBlend.blend = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 396 | mDirtyBits.set(DIRTY_BIT_BLEND_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | void State::setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha) |
| 400 | { |
| 401 | mBlend.sourceBlendRGB = sourceRGB; |
| 402 | mBlend.destBlendRGB = destRGB; |
| 403 | mBlend.sourceBlendAlpha = sourceAlpha; |
| 404 | mBlend.destBlendAlpha = destAlpha; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 405 | mDirtyBits.set(DIRTY_BIT_BLEND_FUNCS); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | void State::setBlendColor(float red, float green, float blue, float alpha) |
| 409 | { |
| 410 | mBlendColor.red = red; |
| 411 | mBlendColor.green = green; |
| 412 | mBlendColor.blue = blue; |
| 413 | mBlendColor.alpha = alpha; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 414 | mDirtyBits.set(DIRTY_BIT_BLEND_COLOR); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | void State::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation) |
| 418 | { |
| 419 | mBlend.blendEquationRGB = rgbEquation; |
| 420 | mBlend.blendEquationAlpha = alphaEquation; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 421 | mDirtyBits.set(DIRTY_BIT_BLEND_EQUATIONS); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | const ColorF &State::getBlendColor() const |
| 425 | { |
| 426 | return mBlendColor; |
| 427 | } |
| 428 | |
| 429 | bool State::isStencilTestEnabled() const |
| 430 | { |
| 431 | return mDepthStencil.stencilTest; |
| 432 | } |
| 433 | |
| 434 | void State::setStencilTest(bool enabled) |
| 435 | { |
| 436 | mDepthStencil.stencilTest = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 437 | mDirtyBits.set(DIRTY_BIT_STENCIL_TEST_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | void State::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask) |
| 441 | { |
| 442 | mDepthStencil.stencilFunc = stencilFunc; |
| 443 | mStencilRef = (stencilRef > 0) ? stencilRef : 0; |
| 444 | mDepthStencil.stencilMask = stencilMask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 445 | mDirtyBits.set(DIRTY_BIT_STENCIL_FUNCS_FRONT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | void State::setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask) |
| 449 | { |
| 450 | mDepthStencil.stencilBackFunc = stencilBackFunc; |
| 451 | mStencilBackRef = (stencilBackRef > 0) ? stencilBackRef : 0; |
| 452 | mDepthStencil.stencilBackMask = stencilBackMask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 453 | mDirtyBits.set(DIRTY_BIT_STENCIL_FUNCS_BACK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | void State::setStencilWritemask(GLuint stencilWritemask) |
| 457 | { |
| 458 | mDepthStencil.stencilWritemask = stencilWritemask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 459 | mDirtyBits.set(DIRTY_BIT_STENCIL_WRITEMASK_FRONT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | void State::setStencilBackWritemask(GLuint stencilBackWritemask) |
| 463 | { |
| 464 | mDepthStencil.stencilBackWritemask = stencilBackWritemask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 465 | mDirtyBits.set(DIRTY_BIT_STENCIL_WRITEMASK_BACK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | void State::setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass) |
| 469 | { |
| 470 | mDepthStencil.stencilFail = stencilFail; |
| 471 | mDepthStencil.stencilPassDepthFail = stencilPassDepthFail; |
| 472 | mDepthStencil.stencilPassDepthPass = stencilPassDepthPass; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 473 | mDirtyBits.set(DIRTY_BIT_STENCIL_OPS_FRONT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | void State::setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass) |
| 477 | { |
| 478 | mDepthStencil.stencilBackFail = stencilBackFail; |
| 479 | mDepthStencil.stencilBackPassDepthFail = stencilBackPassDepthFail; |
| 480 | mDepthStencil.stencilBackPassDepthPass = stencilBackPassDepthPass; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 481 | mDirtyBits.set(DIRTY_BIT_STENCIL_OPS_BACK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | GLint State::getStencilRef() const |
| 485 | { |
| 486 | return mStencilRef; |
| 487 | } |
| 488 | |
| 489 | GLint State::getStencilBackRef() const |
| 490 | { |
| 491 | return mStencilBackRef; |
| 492 | } |
| 493 | |
| 494 | bool State::isPolygonOffsetFillEnabled() const |
| 495 | { |
| 496 | return mRasterizer.polygonOffsetFill; |
| 497 | } |
| 498 | |
| 499 | void State::setPolygonOffsetFill(bool enabled) |
| 500 | { |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 501 | mRasterizer.polygonOffsetFill = enabled; |
| 502 | mDirtyBits.set(DIRTY_BIT_POLYGON_OFFSET_FILL_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | void State::setPolygonOffsetParams(GLfloat factor, GLfloat units) |
| 506 | { |
| 507 | // An application can pass NaN values here, so handle this gracefully |
| 508 | mRasterizer.polygonOffsetFactor = factor != factor ? 0.0f : factor; |
| 509 | mRasterizer.polygonOffsetUnits = units != units ? 0.0f : units; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 510 | mDirtyBits.set(DIRTY_BIT_POLYGON_OFFSET); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | bool State::isSampleAlphaToCoverageEnabled() const |
| 514 | { |
| 515 | return mBlend.sampleAlphaToCoverage; |
| 516 | } |
| 517 | |
| 518 | void State::setSampleAlphaToCoverage(bool enabled) |
| 519 | { |
| 520 | mBlend.sampleAlphaToCoverage = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 521 | mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | bool State::isSampleCoverageEnabled() const |
| 525 | { |
| 526 | return mSampleCoverage; |
| 527 | } |
| 528 | |
| 529 | void State::setSampleCoverage(bool enabled) |
| 530 | { |
| 531 | mSampleCoverage = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 532 | mDirtyBits.set(DIRTY_BIT_SAMPLE_COVERAGE_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | void State::setSampleCoverageParams(GLclampf value, bool invert) |
| 536 | { |
| 537 | mSampleCoverageValue = value; |
| 538 | mSampleCoverageInvert = invert; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 539 | mDirtyBits.set(DIRTY_BIT_SAMPLE_COVERAGE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 540 | } |
| 541 | |
Geoff Lang | 0fbb600 | 2015-04-16 11:11:53 -0400 | [diff] [blame] | 542 | GLclampf State::getSampleCoverageValue() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 543 | { |
Geoff Lang | 0fbb600 | 2015-04-16 11:11:53 -0400 | [diff] [blame] | 544 | return mSampleCoverageValue; |
| 545 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 546 | |
Geoff Lang | 0fbb600 | 2015-04-16 11:11:53 -0400 | [diff] [blame] | 547 | bool State::getSampleCoverageInvert() const |
| 548 | { |
| 549 | return mSampleCoverageInvert; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 550 | } |
| 551 | |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 552 | void State::setSampleAlphaToOne(bool enabled) |
| 553 | { |
| 554 | mSampleAlphaToOne = enabled; |
| 555 | mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_ONE); |
| 556 | } |
| 557 | |
| 558 | bool State::isSampleAlphaToOneEnabled() const |
| 559 | { |
| 560 | return mSampleAlphaToOne; |
| 561 | } |
| 562 | |
| 563 | void State::setMultisampling(bool enabled) |
| 564 | { |
| 565 | mMultiSampling = enabled; |
| 566 | mDirtyBits.set(DIRTY_BIT_MULTISAMPLING); |
| 567 | } |
| 568 | |
| 569 | bool State::isMultisamplingEnabled() const |
| 570 | { |
| 571 | return mMultiSampling; |
| 572 | } |
| 573 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 574 | bool State::isScissorTestEnabled() const |
| 575 | { |
| 576 | return mScissorTest; |
| 577 | } |
| 578 | |
| 579 | void State::setScissorTest(bool enabled) |
| 580 | { |
| 581 | mScissorTest = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 582 | mDirtyBits.set(DIRTY_BIT_SCISSOR_TEST_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | void State::setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height) |
| 586 | { |
| 587 | mScissor.x = x; |
| 588 | mScissor.y = y; |
| 589 | mScissor.width = width; |
| 590 | mScissor.height = height; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 591 | mDirtyBits.set(DIRTY_BIT_SCISSOR); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | const Rectangle &State::getScissor() const |
| 595 | { |
| 596 | return mScissor; |
| 597 | } |
| 598 | |
| 599 | bool State::isDitherEnabled() const |
| 600 | { |
| 601 | return mBlend.dither; |
| 602 | } |
| 603 | |
| 604 | void State::setDither(bool enabled) |
| 605 | { |
| 606 | mBlend.dither = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 607 | mDirtyBits.set(DIRTY_BIT_DITHER_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 608 | } |
| 609 | |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 610 | bool State::isPrimitiveRestartEnabled() const |
| 611 | { |
| 612 | return mPrimitiveRestart; |
| 613 | } |
| 614 | |
| 615 | void State::setPrimitiveRestart(bool enabled) |
| 616 | { |
| 617 | mPrimitiveRestart = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 618 | mDirtyBits.set(DIRTY_BIT_PRIMITIVE_RESTART_ENABLED); |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 619 | } |
| 620 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 621 | void State::setEnableFeature(GLenum feature, bool enabled) |
| 622 | { |
| 623 | switch (feature) |
| 624 | { |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 625 | case GL_MULTISAMPLE_EXT: setMultisampling(enabled); break; |
| 626 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: setSampleAlphaToOne(enabled); break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 627 | case GL_CULL_FACE: setCullFace(enabled); break; |
| 628 | case GL_POLYGON_OFFSET_FILL: setPolygonOffsetFill(enabled); break; |
| 629 | case GL_SAMPLE_ALPHA_TO_COVERAGE: setSampleAlphaToCoverage(enabled); break; |
| 630 | case GL_SAMPLE_COVERAGE: setSampleCoverage(enabled); break; |
| 631 | case GL_SCISSOR_TEST: setScissorTest(enabled); break; |
| 632 | case GL_STENCIL_TEST: setStencilTest(enabled); break; |
| 633 | case GL_DEPTH_TEST: setDepthTest(enabled); break; |
| 634 | case GL_BLEND: setBlend(enabled); break; |
| 635 | case GL_DITHER: setDither(enabled); break; |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 636 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: setPrimitiveRestart(enabled); break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 637 | case GL_RASTERIZER_DISCARD: setRasterizerDiscard(enabled); break; |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 638 | case GL_SAMPLE_MASK: |
Geoff Lang | 9f09037 | 2016-12-02 10:20:43 -0500 | [diff] [blame] | 639 | if (enabled) |
| 640 | { |
| 641 | // Enabling this feature is not implemented yet. |
| 642 | UNIMPLEMENTED(); |
| 643 | } |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 644 | break; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 645 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 646 | mDebug.setOutputSynchronous(enabled); |
| 647 | break; |
| 648 | case GL_DEBUG_OUTPUT: |
| 649 | mDebug.setOutputEnabled(enabled); |
| 650 | break; |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 651 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 652 | setFramebufferSRGB(enabled); |
| 653 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 654 | default: UNREACHABLE(); |
| 655 | } |
| 656 | } |
| 657 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 658 | bool State::getEnableFeature(GLenum feature) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 659 | { |
| 660 | switch (feature) |
| 661 | { |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 662 | case GL_MULTISAMPLE_EXT: return isMultisamplingEnabled(); |
| 663 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: return isSampleAlphaToOneEnabled(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 664 | case GL_CULL_FACE: return isCullFaceEnabled(); |
| 665 | case GL_POLYGON_OFFSET_FILL: return isPolygonOffsetFillEnabled(); |
| 666 | case GL_SAMPLE_ALPHA_TO_COVERAGE: return isSampleAlphaToCoverageEnabled(); |
| 667 | case GL_SAMPLE_COVERAGE: return isSampleCoverageEnabled(); |
| 668 | case GL_SCISSOR_TEST: return isScissorTestEnabled(); |
| 669 | case GL_STENCIL_TEST: return isStencilTestEnabled(); |
| 670 | case GL_DEPTH_TEST: return isDepthTestEnabled(); |
| 671 | case GL_BLEND: return isBlendEnabled(); |
| 672 | case GL_DITHER: return isDitherEnabled(); |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 673 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: return isPrimitiveRestartEnabled(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 674 | case GL_RASTERIZER_DISCARD: return isRasterizerDiscardEnabled(); |
Geoff Lang | b5e997f | 2016-12-06 10:55:34 -0500 | [diff] [blame] | 675 | case GL_SAMPLE_MASK: |
| 676 | UNIMPLEMENTED(); |
| 677 | return false; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 678 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 679 | return mDebug.isOutputSynchronous(); |
| 680 | case GL_DEBUG_OUTPUT: |
| 681 | return mDebug.isOutputEnabled(); |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 682 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 683 | return isBindGeneratesResourceEnabled(); |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 684 | case GL_CLIENT_ARRAYS_ANGLE: |
| 685 | return areClientArraysEnabled(); |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 686 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 687 | return getFramebufferSRGB(); |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 688 | case GL_CONTEXT_ROBUST_RESOURCE_INITIALIZATION_ANGLE: |
| 689 | return mRobustResourceInit; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 690 | default: UNREACHABLE(); return false; |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | void State::setLineWidth(GLfloat width) |
| 695 | { |
| 696 | mLineWidth = width; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 697 | mDirtyBits.set(DIRTY_BIT_LINE_WIDTH); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 698 | } |
| 699 | |
Geoff Lang | 4b3f416 | 2015-04-16 13:22:05 -0400 | [diff] [blame] | 700 | float State::getLineWidth() const |
| 701 | { |
| 702 | return mLineWidth; |
| 703 | } |
| 704 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 705 | void State::setGenerateMipmapHint(GLenum hint) |
| 706 | { |
| 707 | mGenerateMipmapHint = hint; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 708 | mDirtyBits.set(DIRTY_BIT_GENERATE_MIPMAP_HINT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | void State::setFragmentShaderDerivativeHint(GLenum hint) |
| 712 | { |
| 713 | mFragmentShaderDerivativeHint = hint; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 714 | mDirtyBits.set(DIRTY_BIT_SHADER_DERIVATIVE_HINT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 715 | // TODO: Propagate the hint to shader translator so we can write |
| 716 | // ddx, ddx_coarse, or ddx_fine depending on the hint. |
| 717 | // Ignore for now. It is valid for implementations to ignore hint. |
| 718 | } |
| 719 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 720 | bool State::isBindGeneratesResourceEnabled() const |
| 721 | { |
| 722 | return mBindGeneratesResource; |
| 723 | } |
| 724 | |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 725 | bool State::areClientArraysEnabled() const |
| 726 | { |
| 727 | return mClientArraysEnabled; |
| 728 | } |
| 729 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 730 | void State::setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height) |
| 731 | { |
| 732 | mViewport.x = x; |
| 733 | mViewport.y = y; |
| 734 | mViewport.width = width; |
| 735 | mViewport.height = height; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 736 | mDirtyBits.set(DIRTY_BIT_VIEWPORT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | const Rectangle &State::getViewport() const |
| 740 | { |
| 741 | return mViewport; |
| 742 | } |
| 743 | |
| 744 | void State::setActiveSampler(unsigned int active) |
| 745 | { |
| 746 | mActiveSampler = active; |
| 747 | } |
| 748 | |
| 749 | unsigned int State::getActiveSampler() const |
| 750 | { |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 751 | return static_cast<unsigned int>(mActiveSampler); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 752 | } |
| 753 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 754 | void State::setSamplerTexture(const Context *context, GLenum type, Texture *texture) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 755 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 756 | mSamplerTextures[type][mActiveSampler].set(context, texture); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 757 | } |
| 758 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 759 | Texture *State::getTargetTexture(GLenum target) const |
| 760 | { |
| 761 | return getSamplerTexture(static_cast<unsigned int>(mActiveSampler), target); |
| 762 | } |
| 763 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 764 | Texture *State::getSamplerTexture(unsigned int sampler, GLenum type) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 765 | { |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 766 | const auto it = mSamplerTextures.find(type); |
| 767 | ASSERT(it != mSamplerTextures.end()); |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 768 | ASSERT(sampler < it->second.size()); |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 769 | return it->second[sampler].get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 770 | } |
| 771 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 772 | GLuint State::getSamplerTextureId(unsigned int sampler, GLenum type) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 773 | { |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 774 | const auto it = mSamplerTextures.find(type); |
| 775 | ASSERT(it != mSamplerTextures.end()); |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 776 | ASSERT(sampler < it->second.size()); |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 777 | return it->second[sampler].id(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 778 | } |
| 779 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 780 | void State::detachTexture(const Context *context, const TextureMap &zeroTextures, GLuint texture) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 781 | { |
| 782 | // Textures have a detach method on State rather than a simple |
| 783 | // removeBinding, because the zero/null texture objects are managed |
| 784 | // separately, and don't have to go through the Context's maps or |
| 785 | // the ResourceManager. |
| 786 | |
| 787 | // [OpenGL ES 2.0.24] section 3.8 page 84: |
| 788 | // If a texture object is deleted, it is as if all texture units which are bound to that texture object are |
| 789 | // rebound to texture object zero |
| 790 | |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 791 | for (auto &bindingVec : mSamplerTextures) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 792 | { |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 793 | GLenum textureType = bindingVec.first; |
| 794 | TextureBindingVector &textureVector = bindingVec.second; |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 795 | for (size_t textureIdx = 0; textureIdx < textureVector.size(); textureIdx++) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 796 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 797 | BindingPointer<Texture> &binding = textureVector[textureIdx]; |
| 798 | if (binding.id() == texture) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 799 | { |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 800 | auto it = zeroTextures.find(textureType); |
| 801 | ASSERT(it != zeroTextures.end()); |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 802 | // Zero textures are the "default" textures instead of NULL |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 803 | binding.set(context, it->second.get()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 804 | } |
| 805 | } |
| 806 | } |
| 807 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 808 | for (auto &bindingImageUnit : mImageUnits) |
| 809 | { |
| 810 | if (bindingImageUnit.texture.id() == texture) |
| 811 | { |
| 812 | bindingImageUnit.texture.set(context, nullptr); |
| 813 | bindingImageUnit.level = 0; |
| 814 | bindingImageUnit.layered = false; |
| 815 | bindingImageUnit.layer = 0; |
| 816 | bindingImageUnit.access = GL_READ_ONLY; |
| 817 | bindingImageUnit.format = GL_R32UI; |
| 818 | break; |
| 819 | } |
| 820 | } |
| 821 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 822 | // [OpenGL ES 2.0.24] section 4.4 page 112: |
| 823 | // If a texture object is deleted while its image is attached to the currently bound framebuffer, then it is |
| 824 | // as if Texture2DAttachment had been called, with a texture of 0, for each attachment point to which this |
| 825 | // image was attached in the currently bound framebuffer. |
| 826 | |
| 827 | if (mReadFramebuffer) |
| 828 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 829 | mReadFramebuffer->detachTexture(context, texture); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | if (mDrawFramebuffer) |
| 833 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 834 | mDrawFramebuffer->detachTexture(context, texture); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 835 | } |
| 836 | } |
| 837 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 838 | void State::initializeZeroTextures(const Context *context, const TextureMap &zeroTextures) |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 839 | { |
| 840 | for (const auto &zeroTexture : zeroTextures) |
| 841 | { |
| 842 | auto &samplerTextureArray = mSamplerTextures[zeroTexture.first]; |
| 843 | |
| 844 | for (size_t textureUnit = 0; textureUnit < samplerTextureArray.size(); ++textureUnit) |
| 845 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 846 | samplerTextureArray[textureUnit].set(context, zeroTexture.second.get()); |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 847 | } |
| 848 | } |
| 849 | } |
| 850 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 851 | void State::setSamplerBinding(const Context *context, GLuint textureUnit, Sampler *sampler) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 852 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 853 | mSamplers[textureUnit].set(context, sampler); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | GLuint State::getSamplerId(GLuint textureUnit) const |
| 857 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 858 | ASSERT(textureUnit < mSamplers.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 859 | return mSamplers[textureUnit].id(); |
| 860 | } |
| 861 | |
| 862 | Sampler *State::getSampler(GLuint textureUnit) const |
| 863 | { |
| 864 | return mSamplers[textureUnit].get(); |
| 865 | } |
| 866 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 867 | void State::detachSampler(const Context *context, GLuint sampler) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 868 | { |
| 869 | // [OpenGL ES 3.0.2] section 3.8.2 pages 123-124: |
| 870 | // If a sampler object that is currently bound to one or more texture units is |
| 871 | // deleted, it is as though BindSampler is called once for each texture unit to |
| 872 | // which the sampler is bound, with unit set to the texture unit and sampler set to zero. |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 873 | for (size_t textureUnit = 0; textureUnit < mSamplers.size(); textureUnit++) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 874 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 875 | BindingPointer<Sampler> &samplerBinding = mSamplers[textureUnit]; |
| 876 | if (samplerBinding.id() == sampler) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 877 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 878 | samplerBinding.set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 879 | } |
| 880 | } |
| 881 | } |
| 882 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 883 | void State::setRenderbufferBinding(const Context *context, Renderbuffer *renderbuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 884 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 885 | mRenderbuffer.set(context, renderbuffer); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | GLuint State::getRenderbufferId() const |
| 889 | { |
| 890 | return mRenderbuffer.id(); |
| 891 | } |
| 892 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 893 | Renderbuffer *State::getCurrentRenderbuffer() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 894 | { |
| 895 | return mRenderbuffer.get(); |
| 896 | } |
| 897 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 898 | void State::detachRenderbuffer(const Context *context, GLuint renderbuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 899 | { |
| 900 | // [OpenGL ES 2.0.24] section 4.4 page 109: |
| 901 | // If a renderbuffer that is currently bound to RENDERBUFFER is deleted, it is as though BindRenderbuffer |
| 902 | // had been executed with the target RENDERBUFFER and name of zero. |
| 903 | |
| 904 | if (mRenderbuffer.id() == renderbuffer) |
| 905 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 906 | mRenderbuffer.set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | // [OpenGL ES 2.0.24] section 4.4 page 111: |
| 910 | // If a renderbuffer object is deleted while its image is attached to the currently bound framebuffer, |
| 911 | // then it is as if FramebufferRenderbuffer had been called, with a renderbuffer of 0, for each attachment |
| 912 | // point to which this image was attached in the currently bound framebuffer. |
| 913 | |
| 914 | Framebuffer *readFramebuffer = mReadFramebuffer; |
| 915 | Framebuffer *drawFramebuffer = mDrawFramebuffer; |
| 916 | |
| 917 | if (readFramebuffer) |
| 918 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 919 | readFramebuffer->detachRenderbuffer(context, renderbuffer); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | if (drawFramebuffer && drawFramebuffer != readFramebuffer) |
| 923 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 924 | drawFramebuffer->detachRenderbuffer(context, renderbuffer); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | } |
| 928 | |
| 929 | void State::setReadFramebufferBinding(Framebuffer *framebuffer) |
| 930 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 931 | if (mReadFramebuffer == framebuffer) |
| 932 | return; |
| 933 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 934 | mReadFramebuffer = framebuffer; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 935 | mDirtyBits.set(DIRTY_BIT_READ_FRAMEBUFFER_BINDING); |
| 936 | |
| 937 | if (mReadFramebuffer && mReadFramebuffer->hasAnyDirtyBit()) |
| 938 | { |
| 939 | mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 940 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | void State::setDrawFramebufferBinding(Framebuffer *framebuffer) |
| 944 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 945 | if (mDrawFramebuffer == framebuffer) |
| 946 | return; |
| 947 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 948 | mDrawFramebuffer = framebuffer; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 949 | mDirtyBits.set(DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING); |
| 950 | |
| 951 | if (mDrawFramebuffer && mDrawFramebuffer->hasAnyDirtyBit()) |
| 952 | { |
| 953 | mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 954 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | Framebuffer *State::getTargetFramebuffer(GLenum target) const |
| 958 | { |
| 959 | switch (target) |
| 960 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 961 | case GL_READ_FRAMEBUFFER_ANGLE: |
| 962 | return mReadFramebuffer; |
| 963 | case GL_DRAW_FRAMEBUFFER_ANGLE: |
| 964 | case GL_FRAMEBUFFER: |
| 965 | return mDrawFramebuffer; |
| 966 | default: |
| 967 | UNREACHABLE(); |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 968 | return nullptr; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 969 | } |
| 970 | } |
| 971 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 972 | Framebuffer *State::getReadFramebuffer() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 973 | { |
| 974 | return mReadFramebuffer; |
| 975 | } |
| 976 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 977 | Framebuffer *State::getDrawFramebuffer() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 978 | { |
| 979 | return mDrawFramebuffer; |
| 980 | } |
| 981 | |
| 982 | bool State::removeReadFramebufferBinding(GLuint framebuffer) |
| 983 | { |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 984 | if (mReadFramebuffer != nullptr && |
| 985 | mReadFramebuffer->id() == framebuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 986 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 987 | setReadFramebufferBinding(nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 988 | return true; |
| 989 | } |
| 990 | |
| 991 | return false; |
| 992 | } |
| 993 | |
| 994 | bool State::removeDrawFramebufferBinding(GLuint framebuffer) |
| 995 | { |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 996 | if (mReadFramebuffer != nullptr && |
| 997 | mDrawFramebuffer->id() == framebuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 998 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 999 | setDrawFramebufferBinding(nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1000 | return true; |
| 1001 | } |
| 1002 | |
| 1003 | return false; |
| 1004 | } |
| 1005 | |
| 1006 | void State::setVertexArrayBinding(VertexArray *vertexArray) |
| 1007 | { |
| 1008 | mVertexArray = vertexArray; |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1009 | mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1010 | |
| 1011 | if (mVertexArray && mVertexArray->hasAnyDirtyBit()) |
| 1012 | { |
| 1013 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1014 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | GLuint State::getVertexArrayId() const |
| 1018 | { |
Yunchao He | 4f28544 | 2017-04-21 12:15:49 +0800 | [diff] [blame] | 1019 | ASSERT(mVertexArray != nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1020 | return mVertexArray->id(); |
| 1021 | } |
| 1022 | |
| 1023 | VertexArray *State::getVertexArray() const |
| 1024 | { |
Yunchao He | 4f28544 | 2017-04-21 12:15:49 +0800 | [diff] [blame] | 1025 | ASSERT(mVertexArray != nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1026 | return mVertexArray; |
| 1027 | } |
| 1028 | |
| 1029 | bool State::removeVertexArrayBinding(GLuint vertexArray) |
| 1030 | { |
| 1031 | if (mVertexArray->id() == vertexArray) |
| 1032 | { |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 1033 | mVertexArray = nullptr; |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1034 | mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1035 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1036 | return true; |
| 1037 | } |
| 1038 | |
| 1039 | return false; |
| 1040 | } |
| 1041 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1042 | void State::setElementArrayBuffer(const Context *context, Buffer *buffer) |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1043 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1044 | getVertexArray()->setElementArrayBuffer(context, buffer); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1045 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1046 | } |
| 1047 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1048 | void State::bindVertexBuffer(const Context *context, |
| 1049 | GLuint bindingIndex, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1050 | Buffer *boundBuffer, |
| 1051 | GLintptr offset, |
| 1052 | GLsizei stride) |
| 1053 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1054 | getVertexArray()->bindVertexBuffer(context, bindingIndex, boundBuffer, offset, stride); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1055 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1056 | } |
| 1057 | |
| 1058 | void State::setVertexAttribBinding(GLuint attribIndex, GLuint bindingIndex) |
| 1059 | { |
| 1060 | getVertexArray()->setVertexAttribBinding(attribIndex, bindingIndex); |
| 1061 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1062 | } |
| 1063 | |
| 1064 | void State::setVertexAttribFormat(GLuint attribIndex, |
| 1065 | GLint size, |
| 1066 | GLenum type, |
| 1067 | bool normalized, |
| 1068 | bool pureInteger, |
| 1069 | GLuint relativeOffset) |
| 1070 | { |
| 1071 | getVertexArray()->setVertexAttribFormat(attribIndex, size, type, normalized, pureInteger, |
| 1072 | relativeOffset); |
| 1073 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1074 | } |
| 1075 | |
| 1076 | void State::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor) |
| 1077 | { |
| 1078 | getVertexArray()->setVertexBindingDivisor(bindingIndex, divisor); |
| 1079 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1080 | } |
| 1081 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 1082 | void State::setProgram(const Context *context, Program *newProgram) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1083 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1084 | if (mProgram != newProgram) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1085 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1086 | if (mProgram) |
| 1087 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 1088 | mProgram->release(context); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | mProgram = newProgram; |
| 1092 | |
| 1093 | if (mProgram) |
| 1094 | { |
| 1095 | newProgram->addRef(); |
| 1096 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1097 | } |
| 1098 | } |
| 1099 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1100 | Program *State::getProgram() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1101 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1102 | return mProgram; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1103 | } |
| 1104 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1105 | void State::setTransformFeedbackBinding(const Context *context, |
| 1106 | TransformFeedback *transformFeedback) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1107 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1108 | mTransformFeedback.set(context, transformFeedback); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | TransformFeedback *State::getCurrentTransformFeedback() const |
| 1112 | { |
| 1113 | return mTransformFeedback.get(); |
| 1114 | } |
| 1115 | |
Gregoire Payen de La Garanderie | 5274202 | 2015-02-04 14:55:39 +0000 | [diff] [blame] | 1116 | bool State::isTransformFeedbackActiveUnpaused() const |
| 1117 | { |
| 1118 | gl::TransformFeedback *curTransformFeedback = getCurrentTransformFeedback(); |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 1119 | return curTransformFeedback && curTransformFeedback->isActive() && !curTransformFeedback->isPaused(); |
Gregoire Payen de La Garanderie | 5274202 | 2015-02-04 14:55:39 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1122 | bool State::removeTransformFeedbackBinding(const Context *context, GLuint transformFeedback) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1123 | { |
| 1124 | if (mTransformFeedback.id() == transformFeedback) |
| 1125 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1126 | mTransformFeedback.set(context, nullptr); |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 1127 | return true; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1128 | } |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 1129 | |
| 1130 | return false; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1131 | } |
| 1132 | |
Olli Etuaho | bbf1c10 | 2016-06-28 13:31:33 +0300 | [diff] [blame] | 1133 | bool State::isQueryActive(const GLenum type) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1134 | { |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1135 | for (auto &iter : mActiveQueries) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1136 | { |
Olli Etuaho | bbf1c10 | 2016-06-28 13:31:33 +0300 | [diff] [blame] | 1137 | const Query *query = iter.second.get(); |
| 1138 | if (query != nullptr && ActiveQueryType(query->getType()) == ActiveQueryType(type)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1139 | { |
| 1140 | return true; |
| 1141 | } |
| 1142 | } |
| 1143 | |
| 1144 | return false; |
| 1145 | } |
| 1146 | |
| 1147 | bool State::isQueryActive(Query *query) const |
| 1148 | { |
| 1149 | for (auto &iter : mActiveQueries) |
| 1150 | { |
| 1151 | if (iter.second.get() == query) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1152 | { |
| 1153 | return true; |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | return false; |
| 1158 | } |
| 1159 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1160 | void State::setActiveQuery(const Context *context, GLenum target, Query *query) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1161 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1162 | mActiveQueries[target].set(context, query); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | GLuint State::getActiveQueryId(GLenum target) const |
| 1166 | { |
| 1167 | const Query *query = getActiveQuery(target); |
| 1168 | return (query ? query->id() : 0u); |
| 1169 | } |
| 1170 | |
| 1171 | Query *State::getActiveQuery(GLenum target) const |
| 1172 | { |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 1173 | const auto it = mActiveQueries.find(target); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1174 | |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 1175 | // All query types should already exist in the activeQueries map |
| 1176 | ASSERT(it != mActiveQueries.end()); |
| 1177 | |
| 1178 | return it->second.get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1179 | } |
| 1180 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1181 | void State::setArrayBufferBinding(const Context *context, Buffer *buffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1182 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1183 | mArrayBuffer.set(context, buffer); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | GLuint State::getArrayBufferId() const |
| 1187 | { |
| 1188 | return mArrayBuffer.id(); |
| 1189 | } |
| 1190 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1191 | void State::setDrawIndirectBufferBinding(const Context *context, Buffer *buffer) |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1192 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1193 | mDrawIndirectBuffer.set(context, buffer); |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1194 | mDirtyBits.set(DIRTY_BIT_DRAW_INDIRECT_BUFFER_BINDING); |
| 1195 | } |
| 1196 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1197 | void State::setGenericUniformBufferBinding(const Context *context, Buffer *buffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1198 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1199 | mGenericUniformBuffer.set(context, buffer); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1200 | } |
| 1201 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1202 | void State::setIndexedUniformBufferBinding(const Context *context, |
| 1203 | GLuint index, |
| 1204 | Buffer *buffer, |
| 1205 | GLintptr offset, |
| 1206 | GLsizeiptr size) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1207 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1208 | mUniformBuffers[index].set(context, buffer, offset, size); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1209 | } |
| 1210 | |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 1211 | const OffsetBindingPointer<Buffer> &State::getIndexedUniformBuffer(size_t index) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1212 | { |
Shannon Woods | f3acaf9 | 2014-09-23 18:07:11 -0400 | [diff] [blame] | 1213 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 1214 | return mUniformBuffers[index]; |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1215 | } |
| 1216 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1217 | void State::setGenericAtomicCounterBufferBinding(const Context *context, Buffer *buffer) |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1218 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1219 | mGenericAtomicCounterBuffer.set(context, buffer); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1220 | } |
| 1221 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1222 | void State::setIndexedAtomicCounterBufferBinding(const Context *context, |
| 1223 | GLuint index, |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1224 | Buffer *buffer, |
| 1225 | GLintptr offset, |
| 1226 | GLsizeiptr size) |
| 1227 | { |
| 1228 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1229 | mAtomicCounterBuffers[index].set(context, buffer, offset, size); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | const OffsetBindingPointer<Buffer> &State::getIndexedAtomicCounterBuffer(size_t index) const |
| 1233 | { |
| 1234 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
| 1235 | return mAtomicCounterBuffers[index]; |
| 1236 | } |
| 1237 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1238 | void State::setGenericShaderStorageBufferBinding(const Context *context, Buffer *buffer) |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1239 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1240 | mGenericShaderStorageBuffer.set(context, buffer); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1241 | } |
| 1242 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1243 | void State::setIndexedShaderStorageBufferBinding(const Context *context, |
| 1244 | GLuint index, |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1245 | Buffer *buffer, |
| 1246 | GLintptr offset, |
| 1247 | GLsizeiptr size) |
| 1248 | { |
| 1249 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1250 | mShaderStorageBuffers[index].set(context, buffer, offset, size); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | const OffsetBindingPointer<Buffer> &State::getIndexedShaderStorageBuffer(size_t index) const |
| 1254 | { |
| 1255 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
| 1256 | return mShaderStorageBuffers[index]; |
| 1257 | } |
| 1258 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1259 | void State::setCopyReadBufferBinding(const Context *context, Buffer *buffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1260 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1261 | mCopyReadBuffer.set(context, buffer); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1262 | } |
| 1263 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1264 | void State::setCopyWriteBufferBinding(const Context *context, Buffer *buffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1265 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1266 | mCopyWriteBuffer.set(context, buffer); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1267 | } |
| 1268 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1269 | void State::setPixelPackBufferBinding(const Context *context, Buffer *buffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1270 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1271 | mPack.pixelBuffer.set(context, buffer); |
Corentin Wallez | bbd663a | 2016-04-20 17:49:17 -0400 | [diff] [blame] | 1272 | mDirtyBits.set(DIRTY_BIT_PACK_BUFFER_BINDING); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1273 | } |
| 1274 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1275 | void State::setPixelUnpackBufferBinding(const Context *context, Buffer *buffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1276 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1277 | mUnpack.pixelBuffer.set(context, buffer); |
Corentin Wallez | bbd663a | 2016-04-20 17:49:17 -0400 | [diff] [blame] | 1278 | mDirtyBits.set(DIRTY_BIT_UNPACK_BUFFER_BINDING); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | Buffer *State::getTargetBuffer(GLenum target) const |
| 1282 | { |
| 1283 | switch (target) |
| 1284 | { |
| 1285 | case GL_ARRAY_BUFFER: return mArrayBuffer.get(); |
| 1286 | case GL_COPY_READ_BUFFER: return mCopyReadBuffer.get(); |
| 1287 | case GL_COPY_WRITE_BUFFER: return mCopyWriteBuffer.get(); |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 1288 | case GL_ELEMENT_ARRAY_BUFFER: return getVertexArray()->getElementArrayBuffer().get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1289 | case GL_PIXEL_PACK_BUFFER: return mPack.pixelBuffer.get(); |
| 1290 | case GL_PIXEL_UNPACK_BUFFER: return mUnpack.pixelBuffer.get(); |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 1291 | case GL_TRANSFORM_FEEDBACK_BUFFER: return mTransformFeedback->getGenericBuffer().get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1292 | case GL_UNIFORM_BUFFER: return mGenericUniformBuffer.get(); |
Geoff Lang | b5e997f | 2016-12-06 10:55:34 -0500 | [diff] [blame] | 1293 | case GL_ATOMIC_COUNTER_BUFFER: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1294 | return mGenericAtomicCounterBuffer.get(); |
Geoff Lang | b5e997f | 2016-12-06 10:55:34 -0500 | [diff] [blame] | 1295 | case GL_SHADER_STORAGE_BUFFER: |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1296 | return mGenericShaderStorageBuffer.get(); |
Geoff Lang | b5e997f | 2016-12-06 10:55:34 -0500 | [diff] [blame] | 1297 | case GL_DRAW_INDIRECT_BUFFER: |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1298 | return mDrawIndirectBuffer.get(); |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 1299 | default: |
| 1300 | UNREACHABLE(); |
| 1301 | return nullptr; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1302 | } |
| 1303 | } |
| 1304 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1305 | void State::detachBuffer(const Context *context, GLuint bufferName) |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1306 | { |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1307 | BindingPointer<Buffer> *buffers[] = { |
| 1308 | &mArrayBuffer, &mGenericAtomicCounterBuffer, &mCopyReadBuffer, |
| 1309 | &mCopyWriteBuffer, &mDrawIndirectBuffer, &mPack.pixelBuffer, |
| 1310 | &mUnpack.pixelBuffer, &mGenericUniformBuffer, &mGenericShaderStorageBuffer}; |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1311 | for (auto buffer : buffers) |
| 1312 | { |
| 1313 | if (buffer->id() == bufferName) |
| 1314 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1315 | buffer->set(context, nullptr); |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1316 | } |
| 1317 | } |
| 1318 | |
| 1319 | TransformFeedback *curTransformFeedback = getCurrentTransformFeedback(); |
| 1320 | if (curTransformFeedback) |
| 1321 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1322 | curTransformFeedback->detachBuffer(context, bufferName); |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1323 | } |
| 1324 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1325 | getVertexArray()->detachBuffer(context, bufferName); |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1326 | } |
| 1327 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1328 | void State::setEnableVertexAttribArray(unsigned int attribNum, bool enabled) |
| 1329 | { |
| 1330 | getVertexArray()->enableAttribute(attribNum, enabled); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1331 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | void State::setVertexAttribf(GLuint index, const GLfloat values[4]) |
| 1335 | { |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 1336 | ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1337 | mVertexAttribCurrentValues[index].setFloatValues(values); |
Jamie Madill | 1e0bc3a | 2015-08-11 08:12:21 -0400 | [diff] [blame] | 1338 | mDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_0 + index); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | void State::setVertexAttribu(GLuint index, const GLuint values[4]) |
| 1342 | { |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 1343 | ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1344 | mVertexAttribCurrentValues[index].setUnsignedIntValues(values); |
Jamie Madill | 1e0bc3a | 2015-08-11 08:12:21 -0400 | [diff] [blame] | 1345 | mDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_0 + index); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | void State::setVertexAttribi(GLuint index, const GLint values[4]) |
| 1349 | { |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 1350 | ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1351 | mVertexAttribCurrentValues[index].setIntValues(values); |
Jamie Madill | 1e0bc3a | 2015-08-11 08:12:21 -0400 | [diff] [blame] | 1352 | mDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_0 + index); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1353 | } |
| 1354 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1355 | void State::setVertexAttribState(const Context *context, |
| 1356 | unsigned int attribNum, |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1357 | Buffer *boundBuffer, |
| 1358 | GLint size, |
| 1359 | GLenum type, |
| 1360 | bool normalized, |
| 1361 | bool pureInteger, |
| 1362 | GLsizei stride, |
| 1363 | const void *pointer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1364 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1365 | getVertexArray()->setAttributeState(context, attribNum, boundBuffer, size, type, normalized, |
| 1366 | pureInteger, stride, pointer); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1367 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | void State::setVertexAttribDivisor(GLuint index, GLuint divisor) |
| 1371 | { |
| 1372 | getVertexArray()->setVertexAttribDivisor(index, divisor); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1373 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1374 | } |
| 1375 | |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 1376 | const VertexAttribCurrentValueData &State::getVertexAttribCurrentValue(size_t attribNum) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1377 | { |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 1378 | ASSERT(attribNum < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1379 | return mVertexAttribCurrentValues[attribNum]; |
| 1380 | } |
| 1381 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1382 | const void *State::getVertexAttribPointer(unsigned int attribNum) const |
| 1383 | { |
| 1384 | return getVertexArray()->getVertexAttribute(attribNum).pointer; |
| 1385 | } |
| 1386 | |
| 1387 | void State::setPackAlignment(GLint alignment) |
| 1388 | { |
| 1389 | mPack.alignment = alignment; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1390 | mDirtyBits.set(DIRTY_BIT_PACK_ALIGNMENT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | GLint State::getPackAlignment() const |
| 1394 | { |
| 1395 | return mPack.alignment; |
| 1396 | } |
| 1397 | |
| 1398 | void State::setPackReverseRowOrder(bool reverseRowOrder) |
| 1399 | { |
| 1400 | mPack.reverseRowOrder = reverseRowOrder; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1401 | mDirtyBits.set(DIRTY_BIT_PACK_REVERSE_ROW_ORDER); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | bool State::getPackReverseRowOrder() const |
| 1405 | { |
| 1406 | return mPack.reverseRowOrder; |
| 1407 | } |
| 1408 | |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1409 | void State::setPackRowLength(GLint rowLength) |
| 1410 | { |
| 1411 | mPack.rowLength = rowLength; |
| 1412 | mDirtyBits.set(DIRTY_BIT_PACK_ROW_LENGTH); |
| 1413 | } |
| 1414 | |
| 1415 | GLint State::getPackRowLength() const |
| 1416 | { |
| 1417 | return mPack.rowLength; |
| 1418 | } |
| 1419 | |
| 1420 | void State::setPackSkipRows(GLint skipRows) |
| 1421 | { |
| 1422 | mPack.skipRows = skipRows; |
| 1423 | mDirtyBits.set(DIRTY_BIT_PACK_SKIP_ROWS); |
| 1424 | } |
| 1425 | |
| 1426 | GLint State::getPackSkipRows() const |
| 1427 | { |
| 1428 | return mPack.skipRows; |
| 1429 | } |
| 1430 | |
| 1431 | void State::setPackSkipPixels(GLint skipPixels) |
| 1432 | { |
| 1433 | mPack.skipPixels = skipPixels; |
| 1434 | mDirtyBits.set(DIRTY_BIT_PACK_SKIP_PIXELS); |
| 1435 | } |
| 1436 | |
| 1437 | GLint State::getPackSkipPixels() const |
| 1438 | { |
| 1439 | return mPack.skipPixels; |
| 1440 | } |
| 1441 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1442 | const PixelPackState &State::getPackState() const |
| 1443 | { |
| 1444 | return mPack; |
| 1445 | } |
| 1446 | |
Jamie Madill | 87de362 | 2015-03-16 10:41:44 -0400 | [diff] [blame] | 1447 | PixelPackState &State::getPackState() |
| 1448 | { |
| 1449 | return mPack; |
| 1450 | } |
| 1451 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1452 | void State::setUnpackAlignment(GLint alignment) |
| 1453 | { |
| 1454 | mUnpack.alignment = alignment; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1455 | mDirtyBits.set(DIRTY_BIT_UNPACK_ALIGNMENT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | GLint State::getUnpackAlignment() const |
| 1459 | { |
| 1460 | return mUnpack.alignment; |
| 1461 | } |
| 1462 | |
Minmin Gong | b8aee3b | 2015-01-27 14:42:36 -0800 | [diff] [blame] | 1463 | void State::setUnpackRowLength(GLint rowLength) |
| 1464 | { |
| 1465 | mUnpack.rowLength = rowLength; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1466 | mDirtyBits.set(DIRTY_BIT_UNPACK_ROW_LENGTH); |
Minmin Gong | b8aee3b | 2015-01-27 14:42:36 -0800 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | GLint State::getUnpackRowLength() const |
| 1470 | { |
| 1471 | return mUnpack.rowLength; |
| 1472 | } |
| 1473 | |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1474 | void State::setUnpackImageHeight(GLint imageHeight) |
| 1475 | { |
| 1476 | mUnpack.imageHeight = imageHeight; |
| 1477 | mDirtyBits.set(DIRTY_BIT_UNPACK_IMAGE_HEIGHT); |
| 1478 | } |
| 1479 | |
| 1480 | GLint State::getUnpackImageHeight() const |
| 1481 | { |
| 1482 | return mUnpack.imageHeight; |
| 1483 | } |
| 1484 | |
| 1485 | void State::setUnpackSkipImages(GLint skipImages) |
| 1486 | { |
| 1487 | mUnpack.skipImages = skipImages; |
| 1488 | mDirtyBits.set(DIRTY_BIT_UNPACK_SKIP_IMAGES); |
| 1489 | } |
| 1490 | |
| 1491 | GLint State::getUnpackSkipImages() const |
| 1492 | { |
| 1493 | return mUnpack.skipImages; |
| 1494 | } |
| 1495 | |
| 1496 | void State::setUnpackSkipRows(GLint skipRows) |
| 1497 | { |
| 1498 | mUnpack.skipRows = skipRows; |
| 1499 | mDirtyBits.set(DIRTY_BIT_UNPACK_SKIP_ROWS); |
| 1500 | } |
| 1501 | |
| 1502 | GLint State::getUnpackSkipRows() const |
| 1503 | { |
| 1504 | return mUnpack.skipRows; |
| 1505 | } |
| 1506 | |
| 1507 | void State::setUnpackSkipPixels(GLint skipPixels) |
| 1508 | { |
| 1509 | mUnpack.skipPixels = skipPixels; |
| 1510 | mDirtyBits.set(DIRTY_BIT_UNPACK_SKIP_PIXELS); |
| 1511 | } |
| 1512 | |
| 1513 | GLint State::getUnpackSkipPixels() const |
| 1514 | { |
| 1515 | return mUnpack.skipPixels; |
| 1516 | } |
| 1517 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1518 | const PixelUnpackState &State::getUnpackState() const |
| 1519 | { |
| 1520 | return mUnpack; |
| 1521 | } |
| 1522 | |
Jamie Madill | 67102f0 | 2015-03-16 10:41:42 -0400 | [diff] [blame] | 1523 | PixelUnpackState &State::getUnpackState() |
| 1524 | { |
| 1525 | return mUnpack; |
| 1526 | } |
| 1527 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1528 | const Debug &State::getDebug() const |
| 1529 | { |
| 1530 | return mDebug; |
| 1531 | } |
| 1532 | |
| 1533 | Debug &State::getDebug() |
| 1534 | { |
| 1535 | return mDebug; |
| 1536 | } |
| 1537 | |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 1538 | void State::setCoverageModulation(GLenum components) |
| 1539 | { |
| 1540 | mCoverageModulation = components; |
| 1541 | mDirtyBits.set(DIRTY_BIT_COVERAGE_MODULATION); |
| 1542 | } |
| 1543 | |
| 1544 | GLenum State::getCoverageModulation() const |
| 1545 | { |
| 1546 | return mCoverageModulation; |
| 1547 | } |
| 1548 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1549 | void State::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix) |
| 1550 | { |
| 1551 | if (matrixMode == GL_PATH_MODELVIEW_CHROMIUM) |
| 1552 | { |
| 1553 | memcpy(mPathMatrixMV, matrix, 16 * sizeof(GLfloat)); |
| 1554 | mDirtyBits.set(DIRTY_BIT_PATH_RENDERING_MATRIX_MV); |
| 1555 | } |
| 1556 | else if (matrixMode == GL_PATH_PROJECTION_CHROMIUM) |
| 1557 | { |
| 1558 | memcpy(mPathMatrixProj, matrix, 16 * sizeof(GLfloat)); |
| 1559 | mDirtyBits.set(DIRTY_BIT_PATH_RENDERING_MATRIX_PROJ); |
| 1560 | } |
| 1561 | else |
| 1562 | { |
| 1563 | UNREACHABLE(); |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | const GLfloat *State::getPathRenderingMatrix(GLenum which) const |
| 1568 | { |
| 1569 | if (which == GL_PATH_MODELVIEW_MATRIX_CHROMIUM) |
| 1570 | { |
| 1571 | return mPathMatrixMV; |
| 1572 | } |
| 1573 | else if (which == GL_PATH_PROJECTION_MATRIX_CHROMIUM) |
| 1574 | { |
| 1575 | return mPathMatrixProj; |
| 1576 | } |
| 1577 | |
| 1578 | UNREACHABLE(); |
| 1579 | return nullptr; |
| 1580 | } |
| 1581 | |
| 1582 | void State::setPathStencilFunc(GLenum func, GLint ref, GLuint mask) |
| 1583 | { |
| 1584 | mPathStencilFunc = func; |
| 1585 | mPathStencilRef = ref; |
| 1586 | mPathStencilMask = mask; |
| 1587 | mDirtyBits.set(DIRTY_BIT_PATH_RENDERING_STENCIL_STATE); |
| 1588 | } |
| 1589 | |
| 1590 | GLenum State::getPathStencilFunc() const |
| 1591 | { |
| 1592 | return mPathStencilFunc; |
| 1593 | } |
| 1594 | |
| 1595 | GLint State::getPathStencilRef() const |
| 1596 | { |
| 1597 | return mPathStencilRef; |
| 1598 | } |
| 1599 | |
| 1600 | GLuint State::getPathStencilMask() const |
| 1601 | { |
| 1602 | return mPathStencilMask; |
| 1603 | } |
| 1604 | |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 1605 | void State::setFramebufferSRGB(bool sRGB) |
| 1606 | { |
| 1607 | mFramebufferSRGB = sRGB; |
| 1608 | mDirtyBits.set(DIRTY_BIT_FRAMEBUFFER_SRGB); |
| 1609 | } |
| 1610 | |
| 1611 | bool State::getFramebufferSRGB() const |
| 1612 | { |
| 1613 | return mFramebufferSRGB; |
| 1614 | } |
| 1615 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1616 | void State::getBooleanv(GLenum pname, GLboolean *params) |
| 1617 | { |
| 1618 | switch (pname) |
| 1619 | { |
| 1620 | case GL_SAMPLE_COVERAGE_INVERT: *params = mSampleCoverageInvert; break; |
| 1621 | case GL_DEPTH_WRITEMASK: *params = mDepthStencil.depthMask; break; |
| 1622 | case GL_COLOR_WRITEMASK: |
| 1623 | params[0] = mBlend.colorMaskRed; |
| 1624 | params[1] = mBlend.colorMaskGreen; |
| 1625 | params[2] = mBlend.colorMaskBlue; |
| 1626 | params[3] = mBlend.colorMaskAlpha; |
| 1627 | break; |
| 1628 | case GL_CULL_FACE: *params = mRasterizer.cullFace; break; |
| 1629 | case GL_POLYGON_OFFSET_FILL: *params = mRasterizer.polygonOffsetFill; break; |
| 1630 | case GL_SAMPLE_ALPHA_TO_COVERAGE: *params = mBlend.sampleAlphaToCoverage; break; |
| 1631 | case GL_SAMPLE_COVERAGE: *params = mSampleCoverage; break; |
| 1632 | case GL_SCISSOR_TEST: *params = mScissorTest; break; |
| 1633 | case GL_STENCIL_TEST: *params = mDepthStencil.stencilTest; break; |
| 1634 | case GL_DEPTH_TEST: *params = mDepthStencil.depthTest; break; |
| 1635 | case GL_BLEND: *params = mBlend.blend; break; |
| 1636 | case GL_DITHER: *params = mBlend.dither; break; |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 1637 | case GL_TRANSFORM_FEEDBACK_ACTIVE: *params = getCurrentTransformFeedback()->isActive() ? GL_TRUE : GL_FALSE; break; |
| 1638 | 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] | 1639 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: |
| 1640 | *params = mPrimitiveRestart; |
| 1641 | break; |
Geoff Lang | ab831f0 | 2015-12-01 09:39:10 -0500 | [diff] [blame] | 1642 | case GL_RASTERIZER_DISCARD: |
| 1643 | *params = isRasterizerDiscardEnabled() ? GL_TRUE : GL_FALSE; |
| 1644 | break; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1645 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 1646 | *params = mDebug.isOutputSynchronous() ? GL_TRUE : GL_FALSE; |
| 1647 | break; |
| 1648 | case GL_DEBUG_OUTPUT: |
| 1649 | *params = mDebug.isOutputEnabled() ? GL_TRUE : GL_FALSE; |
| 1650 | break; |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 1651 | case GL_MULTISAMPLE_EXT: |
| 1652 | *params = mMultiSampling; |
| 1653 | break; |
| 1654 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 1655 | *params = mSampleAlphaToOne; |
| 1656 | break; |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 1657 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 1658 | *params = isBindGeneratesResourceEnabled() ? GL_TRUE : GL_FALSE; |
| 1659 | break; |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 1660 | case GL_CLIENT_ARRAYS_ANGLE: |
| 1661 | *params = areClientArraysEnabled() ? GL_TRUE : GL_FALSE; |
| 1662 | break; |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 1663 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 1664 | *params = getFramebufferSRGB() ? GL_TRUE : GL_FALSE; |
| 1665 | break; |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 1666 | case GL_CONTEXT_ROBUST_RESOURCE_INITIALIZATION_ANGLE: |
| 1667 | *params = mRobustResourceInit ? GL_TRUE : GL_FALSE; |
| 1668 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1669 | default: |
| 1670 | UNREACHABLE(); |
| 1671 | break; |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | void State::getFloatv(GLenum pname, GLfloat *params) |
| 1676 | { |
| 1677 | // Please note: DEPTH_CLEAR_VALUE is included in our internal getFloatv implementation |
| 1678 | // because it is stored as a float, despite the fact that the GL ES 2.0 spec names |
| 1679 | // GetIntegerv as its native query function. As it would require conversion in any |
| 1680 | // case, this should make no difference to the calling application. |
| 1681 | switch (pname) |
| 1682 | { |
| 1683 | case GL_LINE_WIDTH: *params = mLineWidth; break; |
| 1684 | case GL_SAMPLE_COVERAGE_VALUE: *params = mSampleCoverageValue; break; |
| 1685 | case GL_DEPTH_CLEAR_VALUE: *params = mDepthClearValue; break; |
| 1686 | case GL_POLYGON_OFFSET_FACTOR: *params = mRasterizer.polygonOffsetFactor; break; |
| 1687 | case GL_POLYGON_OFFSET_UNITS: *params = mRasterizer.polygonOffsetUnits; break; |
| 1688 | case GL_DEPTH_RANGE: |
| 1689 | params[0] = mNearZ; |
| 1690 | params[1] = mFarZ; |
| 1691 | break; |
| 1692 | case GL_COLOR_CLEAR_VALUE: |
| 1693 | params[0] = mColorClearValue.red; |
| 1694 | params[1] = mColorClearValue.green; |
| 1695 | params[2] = mColorClearValue.blue; |
| 1696 | params[3] = mColorClearValue.alpha; |
| 1697 | break; |
| 1698 | case GL_BLEND_COLOR: |
| 1699 | params[0] = mBlendColor.red; |
| 1700 | params[1] = mBlendColor.green; |
| 1701 | params[2] = mBlendColor.blue; |
| 1702 | params[3] = mBlendColor.alpha; |
| 1703 | break; |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 1704 | case GL_MULTISAMPLE_EXT: |
| 1705 | *params = static_cast<GLfloat>(mMultiSampling); |
| 1706 | break; |
| 1707 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 1708 | *params = static_cast<GLfloat>(mSampleAlphaToOne); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 1709 | case GL_COVERAGE_MODULATION_CHROMIUM: |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1710 | params[0] = static_cast<GLfloat>(mCoverageModulation); |
| 1711 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1712 | default: |
| 1713 | UNREACHABLE(); |
| 1714 | break; |
| 1715 | } |
| 1716 | } |
| 1717 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1718 | void State::getIntegerv(const Context *context, GLenum pname, GLint *params) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1719 | { |
| 1720 | if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT) |
| 1721 | { |
| 1722 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0_EXT); |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1723 | ASSERT(colorAttachment < mMaxDrawBuffers); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1724 | Framebuffer *framebuffer = mDrawFramebuffer; |
| 1725 | *params = framebuffer->getDrawBufferState(colorAttachment); |
| 1726 | return; |
| 1727 | } |
| 1728 | |
| 1729 | // Please note: DEPTH_CLEAR_VALUE is not included in our internal getIntegerv implementation |
| 1730 | // because it is stored as a float, despite the fact that the GL ES 2.0 spec names |
| 1731 | // GetIntegerv as its native query function. As it would require conversion in any |
| 1732 | // case, this should make no difference to the calling application. You may find it in |
| 1733 | // State::getFloatv. |
| 1734 | switch (pname) |
| 1735 | { |
| 1736 | case GL_ARRAY_BUFFER_BINDING: *params = mArrayBuffer.id(); break; |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1737 | case GL_DRAW_INDIRECT_BUFFER_BINDING: |
| 1738 | *params = mDrawIndirectBuffer.id(); |
| 1739 | break; |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 1740 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: *params = getVertexArray()->getElementArrayBuffer().id(); break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1741 | //case GL_FRAMEBUFFER_BINDING: // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE |
| 1742 | case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE: *params = mDrawFramebuffer->id(); break; |
| 1743 | case GL_READ_FRAMEBUFFER_BINDING_ANGLE: *params = mReadFramebuffer->id(); break; |
| 1744 | case GL_RENDERBUFFER_BINDING: *params = mRenderbuffer.id(); break; |
| 1745 | case GL_VERTEX_ARRAY_BINDING: *params = mVertexArray->id(); break; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1746 | case GL_CURRENT_PROGRAM: *params = mProgram ? mProgram->id() : 0; break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1747 | case GL_PACK_ALIGNMENT: *params = mPack.alignment; break; |
| 1748 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: *params = mPack.reverseRowOrder; break; |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1749 | case GL_PACK_ROW_LENGTH: |
| 1750 | *params = mPack.rowLength; |
| 1751 | break; |
| 1752 | case GL_PACK_SKIP_ROWS: |
| 1753 | *params = mPack.skipRows; |
| 1754 | break; |
| 1755 | case GL_PACK_SKIP_PIXELS: |
| 1756 | *params = mPack.skipPixels; |
| 1757 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1758 | case GL_UNPACK_ALIGNMENT: *params = mUnpack.alignment; break; |
Minmin Gong | b8aee3b | 2015-01-27 14:42:36 -0800 | [diff] [blame] | 1759 | case GL_UNPACK_ROW_LENGTH: *params = mUnpack.rowLength; break; |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1760 | case GL_UNPACK_IMAGE_HEIGHT: |
| 1761 | *params = mUnpack.imageHeight; |
| 1762 | break; |
| 1763 | case GL_UNPACK_SKIP_IMAGES: |
| 1764 | *params = mUnpack.skipImages; |
| 1765 | break; |
| 1766 | case GL_UNPACK_SKIP_ROWS: |
| 1767 | *params = mUnpack.skipRows; |
| 1768 | break; |
| 1769 | case GL_UNPACK_SKIP_PIXELS: |
| 1770 | *params = mUnpack.skipPixels; |
| 1771 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1772 | case GL_GENERATE_MIPMAP_HINT: *params = mGenerateMipmapHint; break; |
| 1773 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: *params = mFragmentShaderDerivativeHint; break; |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1774 | case GL_ACTIVE_TEXTURE: |
| 1775 | *params = (static_cast<GLint>(mActiveSampler) + GL_TEXTURE0); |
| 1776 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1777 | case GL_STENCIL_FUNC: *params = mDepthStencil.stencilFunc; break; |
| 1778 | case GL_STENCIL_REF: *params = mStencilRef; break; |
| 1779 | case GL_STENCIL_VALUE_MASK: *params = clampToInt(mDepthStencil.stencilMask); break; |
| 1780 | case GL_STENCIL_BACK_FUNC: *params = mDepthStencil.stencilBackFunc; break; |
| 1781 | case GL_STENCIL_BACK_REF: *params = mStencilBackRef; break; |
| 1782 | case GL_STENCIL_BACK_VALUE_MASK: *params = clampToInt(mDepthStencil.stencilBackMask); break; |
| 1783 | case GL_STENCIL_FAIL: *params = mDepthStencil.stencilFail; break; |
| 1784 | case GL_STENCIL_PASS_DEPTH_FAIL: *params = mDepthStencil.stencilPassDepthFail; break; |
| 1785 | case GL_STENCIL_PASS_DEPTH_PASS: *params = mDepthStencil.stencilPassDepthPass; break; |
| 1786 | case GL_STENCIL_BACK_FAIL: *params = mDepthStencil.stencilBackFail; break; |
| 1787 | case GL_STENCIL_BACK_PASS_DEPTH_FAIL: *params = mDepthStencil.stencilBackPassDepthFail; break; |
| 1788 | case GL_STENCIL_BACK_PASS_DEPTH_PASS: *params = mDepthStencil.stencilBackPassDepthPass; break; |
| 1789 | case GL_DEPTH_FUNC: *params = mDepthStencil.depthFunc; break; |
| 1790 | case GL_BLEND_SRC_RGB: *params = mBlend.sourceBlendRGB; break; |
| 1791 | case GL_BLEND_SRC_ALPHA: *params = mBlend.sourceBlendAlpha; break; |
| 1792 | case GL_BLEND_DST_RGB: *params = mBlend.destBlendRGB; break; |
| 1793 | case GL_BLEND_DST_ALPHA: *params = mBlend.destBlendAlpha; break; |
| 1794 | case GL_BLEND_EQUATION_RGB: *params = mBlend.blendEquationRGB; break; |
| 1795 | case GL_BLEND_EQUATION_ALPHA: *params = mBlend.blendEquationAlpha; break; |
| 1796 | case GL_STENCIL_WRITEMASK: *params = clampToInt(mDepthStencil.stencilWritemask); break; |
| 1797 | case GL_STENCIL_BACK_WRITEMASK: *params = clampToInt(mDepthStencil.stencilBackWritemask); break; |
| 1798 | case GL_STENCIL_CLEAR_VALUE: *params = mStencilClearValue; break; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1799 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 1800 | *params = mReadFramebuffer->getImplementationColorReadType(context); |
| 1801 | break; |
| 1802 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 1803 | *params = mReadFramebuffer->getImplementationColorReadFormat(context); |
| 1804 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1805 | case GL_SAMPLE_BUFFERS: |
| 1806 | case GL_SAMPLES: |
| 1807 | { |
| 1808 | gl::Framebuffer *framebuffer = mDrawFramebuffer; |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1809 | if (framebuffer->checkStatus(context) == GL_FRAMEBUFFER_COMPLETE) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1810 | { |
| 1811 | switch (pname) |
| 1812 | { |
| 1813 | case GL_SAMPLE_BUFFERS: |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1814 | if (framebuffer->getSamples(context) != 0) |
| 1815 | { |
| 1816 | *params = 1; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1817 | } |
| 1818 | else |
| 1819 | { |
| 1820 | *params = 0; |
| 1821 | } |
| 1822 | break; |
| 1823 | case GL_SAMPLES: |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1824 | *params = framebuffer->getSamples(context); |
| 1825 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1826 | } |
| 1827 | } |
| 1828 | else |
| 1829 | { |
| 1830 | *params = 0; |
| 1831 | } |
| 1832 | } |
| 1833 | break; |
| 1834 | case GL_VIEWPORT: |
| 1835 | params[0] = mViewport.x; |
| 1836 | params[1] = mViewport.y; |
| 1837 | params[2] = mViewport.width; |
| 1838 | params[3] = mViewport.height; |
| 1839 | break; |
| 1840 | case GL_SCISSOR_BOX: |
| 1841 | params[0] = mScissor.x; |
| 1842 | params[1] = mScissor.y; |
| 1843 | params[2] = mScissor.width; |
| 1844 | params[3] = mScissor.height; |
| 1845 | break; |
| 1846 | case GL_CULL_FACE_MODE: *params = mRasterizer.cullMode; break; |
| 1847 | case GL_FRONT_FACE: *params = mRasterizer.frontFace; break; |
| 1848 | case GL_RED_BITS: |
| 1849 | case GL_GREEN_BITS: |
| 1850 | case GL_BLUE_BITS: |
| 1851 | case GL_ALPHA_BITS: |
| 1852 | { |
| 1853 | gl::Framebuffer *framebuffer = getDrawFramebuffer(); |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 1854 | const gl::FramebufferAttachment *colorbuffer = framebuffer->getFirstColorbuffer(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1855 | |
| 1856 | if (colorbuffer) |
| 1857 | { |
| 1858 | switch (pname) |
| 1859 | { |
| 1860 | case GL_RED_BITS: *params = colorbuffer->getRedSize(); break; |
| 1861 | case GL_GREEN_BITS: *params = colorbuffer->getGreenSize(); break; |
| 1862 | case GL_BLUE_BITS: *params = colorbuffer->getBlueSize(); break; |
| 1863 | case GL_ALPHA_BITS: *params = colorbuffer->getAlphaSize(); break; |
| 1864 | } |
| 1865 | } |
| 1866 | else |
| 1867 | { |
| 1868 | *params = 0; |
| 1869 | } |
| 1870 | } |
| 1871 | break; |
| 1872 | case GL_DEPTH_BITS: |
| 1873 | { |
Jamie Madill | e3ef715 | 2015-04-28 16:55:17 +0000 | [diff] [blame] | 1874 | const gl::Framebuffer *framebuffer = getDrawFramebuffer(); |
| 1875 | const gl::FramebufferAttachment *depthbuffer = framebuffer->getDepthbuffer(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1876 | |
| 1877 | if (depthbuffer) |
| 1878 | { |
| 1879 | *params = depthbuffer->getDepthSize(); |
| 1880 | } |
| 1881 | else |
| 1882 | { |
| 1883 | *params = 0; |
| 1884 | } |
| 1885 | } |
| 1886 | break; |
| 1887 | case GL_STENCIL_BITS: |
| 1888 | { |
Jamie Madill | e3ef715 | 2015-04-28 16:55:17 +0000 | [diff] [blame] | 1889 | const gl::Framebuffer *framebuffer = getDrawFramebuffer(); |
| 1890 | const gl::FramebufferAttachment *stencilbuffer = framebuffer->getStencilbuffer(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1891 | |
| 1892 | if (stencilbuffer) |
| 1893 | { |
| 1894 | *params = stencilbuffer->getStencilSize(); |
| 1895 | } |
| 1896 | else |
| 1897 | { |
| 1898 | *params = 0; |
| 1899 | } |
| 1900 | } |
| 1901 | break; |
| 1902 | case GL_TEXTURE_BINDING_2D: |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1903 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1904 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_2D); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1905 | break; |
| 1906 | case GL_TEXTURE_BINDING_CUBE_MAP: |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1907 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1908 | *params = |
| 1909 | getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_CUBE_MAP); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1910 | break; |
| 1911 | case GL_TEXTURE_BINDING_3D: |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1912 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1913 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_3D); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1914 | break; |
| 1915 | case GL_TEXTURE_BINDING_2D_ARRAY: |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1916 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1917 | *params = |
| 1918 | getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_2D_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1919 | break; |
John Bauman | 1831918 | 2016-09-28 14:22:27 -0700 | [diff] [blame] | 1920 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 1921 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
| 1922 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), |
| 1923 | GL_TEXTURE_EXTERNAL_OES); |
| 1924 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1925 | case GL_UNIFORM_BUFFER_BINDING: |
| 1926 | *params = mGenericUniformBuffer.id(); |
| 1927 | break; |
Frank Henigman | 22581ff | 2015-11-06 14:25:54 -0500 | [diff] [blame] | 1928 | case GL_TRANSFORM_FEEDBACK_BINDING: |
Frank Henigman | b0f0b81 | 2015-11-21 17:49:29 -0500 | [diff] [blame] | 1929 | *params = mTransformFeedback.id(); |
Frank Henigman | 22581ff | 2015-11-06 14:25:54 -0500 | [diff] [blame] | 1930 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1931 | case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 1932 | *params = mTransformFeedback->getGenericBuffer().id(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1933 | break; |
| 1934 | case GL_COPY_READ_BUFFER_BINDING: |
| 1935 | *params = mCopyReadBuffer.id(); |
| 1936 | break; |
| 1937 | case GL_COPY_WRITE_BUFFER_BINDING: |
| 1938 | *params = mCopyWriteBuffer.id(); |
| 1939 | break; |
| 1940 | case GL_PIXEL_PACK_BUFFER_BINDING: |
| 1941 | *params = mPack.pixelBuffer.id(); |
| 1942 | break; |
| 1943 | case GL_PIXEL_UNPACK_BUFFER_BINDING: |
| 1944 | *params = mUnpack.pixelBuffer.id(); |
| 1945 | break; |
Olli Etuaho | 86821db | 2016-03-04 12:05:47 +0200 | [diff] [blame] | 1946 | case GL_READ_BUFFER: |
| 1947 | *params = mReadFramebuffer->getReadBufferState(); |
| 1948 | break; |
| 1949 | case GL_SAMPLER_BINDING: |
| 1950 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
| 1951 | *params = getSamplerId(static_cast<GLuint>(mActiveSampler)); |
| 1952 | break; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1953 | case GL_DEBUG_LOGGED_MESSAGES: |
| 1954 | *params = static_cast<GLint>(mDebug.getMessageCount()); |
| 1955 | break; |
| 1956 | case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH: |
| 1957 | *params = static_cast<GLint>(mDebug.getNextMessageLength()); |
| 1958 | break; |
| 1959 | case GL_DEBUG_GROUP_STACK_DEPTH: |
| 1960 | *params = static_cast<GLint>(mDebug.getGroupStackDepth()); |
| 1961 | break; |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 1962 | case GL_MULTISAMPLE_EXT: |
| 1963 | *params = static_cast<GLint>(mMultiSampling); |
| 1964 | break; |
| 1965 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 1966 | *params = static_cast<GLint>(mSampleAlphaToOne); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 1967 | case GL_COVERAGE_MODULATION_CHROMIUM: |
| 1968 | *params = static_cast<GLint>(mCoverageModulation); |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 1969 | break; |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1970 | case GL_ATOMIC_COUNTER_BUFFER_BINDING: |
| 1971 | *params = mGenericAtomicCounterBuffer.id(); |
| 1972 | break; |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1973 | case GL_SHADER_STORAGE_BUFFER_BINDING: |
| 1974 | *params = mGenericShaderStorageBuffer.id(); |
| 1975 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1976 | default: |
| 1977 | UNREACHABLE(); |
| 1978 | break; |
| 1979 | } |
| 1980 | } |
| 1981 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1982 | void State::getPointerv(GLenum pname, void **params) const |
| 1983 | { |
| 1984 | switch (pname) |
| 1985 | { |
| 1986 | case GL_DEBUG_CALLBACK_FUNCTION: |
| 1987 | *params = reinterpret_cast<void *>(mDebug.getCallback()); |
| 1988 | break; |
| 1989 | case GL_DEBUG_CALLBACK_USER_PARAM: |
| 1990 | *params = const_cast<void *>(mDebug.getUserParam()); |
| 1991 | break; |
| 1992 | default: |
| 1993 | UNREACHABLE(); |
| 1994 | break; |
| 1995 | } |
| 1996 | } |
| 1997 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1998 | void State::getIntegeri_v(GLenum target, GLuint index, GLint *data) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1999 | { |
| 2000 | switch (target) |
| 2001 | { |
| 2002 | case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2003 | ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount()); |
| 2004 | *data = mTransformFeedback->getIndexedBuffer(index).id(); |
| 2005 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2006 | case GL_UNIFORM_BUFFER_BINDING: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2007 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
| 2008 | *data = mUniformBuffers[index].id(); |
| 2009 | break; |
| 2010 | case GL_ATOMIC_COUNTER_BUFFER_BINDING: |
| 2011 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
| 2012 | *data = mAtomicCounterBuffers[index].id(); |
| 2013 | break; |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 2014 | case GL_SHADER_STORAGE_BUFFER_BINDING: |
| 2015 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
| 2016 | *data = mShaderStorageBuffers[index].id(); |
| 2017 | break; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2018 | case GL_VERTEX_BINDING_BUFFER: |
| 2019 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 2020 | *data = mVertexArray->getVertexBinding(index).getBuffer().id(); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2021 | break; |
| 2022 | case GL_VERTEX_BINDING_DIVISOR: |
| 2023 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 2024 | *data = mVertexArray->getVertexBinding(index).getDivisor(); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2025 | break; |
| 2026 | case GL_VERTEX_BINDING_OFFSET: |
| 2027 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 2028 | *data = static_cast<GLuint>(mVertexArray->getVertexBinding(index).getOffset()); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2029 | break; |
| 2030 | case GL_VERTEX_BINDING_STRIDE: |
| 2031 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 2032 | *data = mVertexArray->getVertexBinding(index).getStride(); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2033 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2034 | default: |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2035 | UNREACHABLE(); |
| 2036 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2037 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2038 | } |
| 2039 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2040 | void State::getInteger64i_v(GLenum target, GLuint index, GLint64 *data) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2041 | { |
| 2042 | switch (target) |
| 2043 | { |
| 2044 | case GL_TRANSFORM_FEEDBACK_BUFFER_START: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2045 | ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount()); |
| 2046 | *data = mTransformFeedback->getIndexedBuffer(index).getOffset(); |
| 2047 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2048 | case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2049 | ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount()); |
| 2050 | *data = mTransformFeedback->getIndexedBuffer(index).getSize(); |
| 2051 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2052 | case GL_UNIFORM_BUFFER_START: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2053 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
| 2054 | *data = mUniformBuffers[index].getOffset(); |
| 2055 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2056 | case GL_UNIFORM_BUFFER_SIZE: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2057 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
| 2058 | *data = mUniformBuffers[index].getSize(); |
| 2059 | break; |
| 2060 | case GL_ATOMIC_COUNTER_BUFFER_START: |
| 2061 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
| 2062 | *data = mAtomicCounterBuffers[index].getOffset(); |
| 2063 | break; |
| 2064 | case GL_ATOMIC_COUNTER_BUFFER_SIZE: |
| 2065 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
| 2066 | *data = mAtomicCounterBuffers[index].getSize(); |
| 2067 | break; |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 2068 | case GL_SHADER_STORAGE_BUFFER_START: |
| 2069 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
| 2070 | *data = mShaderStorageBuffers[index].getOffset(); |
| 2071 | break; |
| 2072 | case GL_SHADER_STORAGE_BUFFER_SIZE: |
| 2073 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
| 2074 | *data = mShaderStorageBuffers[index].getSize(); |
| 2075 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2076 | default: |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2077 | UNREACHABLE(); |
| 2078 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2079 | } |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2080 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2081 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2082 | void State::getBooleani_v(GLenum target, GLuint index, GLboolean *data) |
| 2083 | { |
| 2084 | UNREACHABLE(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2085 | } |
| 2086 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2087 | bool State::hasMappedBuffer(GLenum target) const |
| 2088 | { |
| 2089 | if (target == GL_ARRAY_BUFFER) |
| 2090 | { |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 2091 | const VertexArray *vao = getVertexArray(); |
Jamie Madill | eea3a6e | 2015-04-15 10:02:48 -0400 | [diff] [blame] | 2092 | const auto &vertexAttribs = vao->getVertexAttributes(); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 2093 | const auto &vertexBindings = vao->getVertexBindings(); |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 2094 | size_t maxEnabledAttrib = vao->getMaxEnabledAttribute(); |
Jamie Madill | aebf9dd | 2015-04-28 12:39:07 -0400 | [diff] [blame] | 2095 | for (size_t attribIndex = 0; attribIndex < maxEnabledAttrib; attribIndex++) |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2096 | { |
Jamie Madill | eea3a6e | 2015-04-15 10:02:48 -0400 | [diff] [blame] | 2097 | const gl::VertexAttribute &vertexAttrib = vertexAttribs[attribIndex]; |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 2098 | auto *boundBuffer = vertexBindings[vertexAttrib.bindingIndex].getBuffer().get(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2099 | if (vertexAttrib.enabled && boundBuffer && boundBuffer->isMapped()) |
| 2100 | { |
| 2101 | return true; |
| 2102 | } |
| 2103 | } |
| 2104 | |
| 2105 | return false; |
| 2106 | } |
| 2107 | else |
| 2108 | { |
| 2109 | Buffer *buffer = getTargetBuffer(target); |
| 2110 | return (buffer && buffer->isMapped()); |
| 2111 | } |
| 2112 | } |
| 2113 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2114 | void State::syncDirtyObjects(const Context *context) |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2115 | { |
| 2116 | if (!mDirtyObjects.any()) |
| 2117 | return; |
| 2118 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2119 | syncDirtyObjects(context, mDirtyObjects); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2120 | } |
| 2121 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2122 | void State::syncDirtyObjects(const Context *context, const DirtyObjects &bitset) |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2123 | { |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 2124 | for (auto dirtyObject : bitset) |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2125 | { |
| 2126 | switch (dirtyObject) |
| 2127 | { |
| 2128 | case DIRTY_OBJECT_READ_FRAMEBUFFER: |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2129 | ASSERT(mReadFramebuffer); |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2130 | mReadFramebuffer->syncState(context); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2131 | break; |
| 2132 | case DIRTY_OBJECT_DRAW_FRAMEBUFFER: |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2133 | ASSERT(mDrawFramebuffer); |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2134 | mDrawFramebuffer->syncState(context); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2135 | break; |
| 2136 | case DIRTY_OBJECT_VERTEX_ARRAY: |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2137 | ASSERT(mVertexArray); |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2138 | mVertexArray->syncImplState(context); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2139 | break; |
| 2140 | case DIRTY_OBJECT_PROGRAM: |
| 2141 | // TODO(jmadill): implement this |
| 2142 | break; |
| 2143 | default: |
| 2144 | UNREACHABLE(); |
| 2145 | break; |
| 2146 | } |
| 2147 | } |
| 2148 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2149 | mDirtyObjects &= ~bitset; |
| 2150 | } |
| 2151 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2152 | void State::syncDirtyObject(const Context *context, GLenum target) |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2153 | { |
| 2154 | DirtyObjects localSet; |
| 2155 | |
| 2156 | switch (target) |
| 2157 | { |
| 2158 | case GL_READ_FRAMEBUFFER: |
| 2159 | localSet.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 2160 | break; |
| 2161 | case GL_DRAW_FRAMEBUFFER: |
| 2162 | localSet.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 2163 | break; |
| 2164 | case GL_FRAMEBUFFER: |
| 2165 | localSet.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 2166 | localSet.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 2167 | break; |
| 2168 | case GL_VERTEX_ARRAY: |
| 2169 | localSet.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 2170 | break; |
| 2171 | case GL_PROGRAM: |
| 2172 | localSet.set(DIRTY_OBJECT_PROGRAM); |
| 2173 | break; |
| 2174 | } |
| 2175 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2176 | syncDirtyObjects(context, localSet); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | void State::setObjectDirty(GLenum target) |
| 2180 | { |
| 2181 | switch (target) |
| 2182 | { |
| 2183 | case GL_READ_FRAMEBUFFER: |
| 2184 | mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 2185 | break; |
| 2186 | case GL_DRAW_FRAMEBUFFER: |
| 2187 | mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 2188 | break; |
| 2189 | case GL_FRAMEBUFFER: |
| 2190 | mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 2191 | mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 2192 | break; |
| 2193 | case GL_VERTEX_ARRAY: |
| 2194 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 2195 | break; |
| 2196 | case GL_PROGRAM: |
| 2197 | mDirtyObjects.set(DIRTY_OBJECT_PROGRAM); |
| 2198 | break; |
| 2199 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2200 | } |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2201 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 2202 | void State::setImageUnit(const Context *context, |
| 2203 | GLuint unit, |
| 2204 | Texture *texture, |
| 2205 | GLint level, |
| 2206 | GLboolean layered, |
| 2207 | GLint layer, |
| 2208 | GLenum access, |
| 2209 | GLenum format) |
| 2210 | { |
| 2211 | mImageUnits[unit].texture.set(context, texture); |
| 2212 | mImageUnits[unit].level = level; |
| 2213 | mImageUnits[unit].layered = layered; |
| 2214 | mImageUnits[unit].layer = layer; |
| 2215 | mImageUnits[unit].access = access; |
| 2216 | mImageUnits[unit].format = format; |
| 2217 | } |
| 2218 | |
| 2219 | const ImageUnit &State::getImageUnit(GLuint unit) const |
| 2220 | { |
| 2221 | return mImageUnits[unit]; |
| 2222 | } |
| 2223 | |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2224 | } // namespace gl |