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