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