apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2002-2012 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 | // Context.cpp: Implements the gl::Context class, managing all GL state and performing |
| 8 | // rendering operations. It is the GLES2 specific implementation of EGLContext. |
| 9 | |
| 10 | #include "libGLESv2/Context.h" |
| 11 | |
| 12 | #include <algorithm> |
| 13 | |
| 14 | #include "libEGL/Display.h" |
| 15 | |
| 16 | #include "libGLESv2/main.h" |
| 17 | #include "libGLESv2/mathutil.h" |
| 18 | #include "libGLESv2/utilities.h" |
daniel@transgaming.com | d8e3656 | 2012-10-31 19:52:19 +0000 | [diff] [blame] | 19 | #include "libGLESv2/renderer/renderer9_utils.h" // D3D9_REPLACE |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 20 | #include "libGLESv2/ResourceManager.h" |
| 21 | #include "libGLESv2/Buffer.h" |
| 22 | #include "libGLESv2/Fence.h" |
daniel@transgaming.com | 29ab952 | 2012-08-27 16:25:37 +0000 | [diff] [blame] | 23 | #include "libGLESv2/Framebuffer.h" |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 24 | #include "libGLESv2/Program.h" |
| 25 | #include "libGLESv2/ProgramBinary.h" |
| 26 | #include "libGLESv2/Query.h" |
daniel@transgaming.com | 29ab952 | 2012-08-27 16:25:37 +0000 | [diff] [blame] | 27 | #include "libGLESv2/Renderbuffer.h" |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 28 | #include "libGLESv2/Shader.h" |
| 29 | #include "libGLESv2/Texture.h" |
| 30 | #include "libGLESv2/VertexDataManager.h" |
| 31 | #include "libGLESv2/IndexDataManager.h" |
| 32 | |
| 33 | #undef near |
| 34 | #undef far |
| 35 | |
| 36 | namespace gl |
| 37 | { |
daniel@transgaming.com | 03d3909 | 2012-11-28 19:31:59 +0000 | [diff] [blame] | 38 | Context::Context(const gl::Context *shareContext, rx::Renderer *renderer, bool notifyResets, bool robustAccess) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 39 | { |
| 40 | ASSERT(robustAccess == false); // Unimplemented |
| 41 | |
daniel@transgaming.com | 03d3909 | 2012-11-28 19:31:59 +0000 | [diff] [blame] | 42 | ASSERT(dynamic_cast<rx::Renderer9*>(renderer) != NULL); // D3D9_REPLACE |
| 43 | mRenderer = static_cast<rx::Renderer9*>(renderer); |
| 44 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 45 | mDevice = NULL; |
| 46 | |
| 47 | mFenceHandleAllocator.setBaseHandle(0); |
| 48 | |
| 49 | setClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 50 | |
| 51 | mState.depthClearValue = 1.0f; |
| 52 | mState.stencilClearValue = 0; |
| 53 | |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 54 | mState.rasterizer.cullFace = false; |
| 55 | mState.rasterizer.cullMode = GL_BACK; |
| 56 | mState.rasterizer.frontFace = GL_CCW; |
| 57 | mState.rasterizer.polygonOffsetFill = false; |
| 58 | mState.rasterizer.polygonOffsetFactor = 0.0f; |
| 59 | mState.rasterizer.polygonOffsetUnits = 0.0f; |
| 60 | mState.rasterizer.scissorTest = false; |
| 61 | mState.scissor.x = 0; |
| 62 | mState.scissor.y = 0; |
| 63 | mState.scissor.width = 0; |
| 64 | mState.scissor.height = 0; |
| 65 | |
| 66 | mState.blend.blend = false; |
| 67 | mState.blend.sourceBlendRGB = GL_ONE; |
| 68 | mState.blend.sourceBlendAlpha = GL_ONE; |
| 69 | mState.blend.destBlendRGB = GL_ZERO; |
| 70 | mState.blend.destBlendAlpha = GL_ZERO; |
| 71 | mState.blend.blendEquationRGB = GL_FUNC_ADD; |
| 72 | mState.blend.blendEquationAlpha = GL_FUNC_ADD; |
| 73 | mState.blend.sampleAlphaToCoverage = false; |
| 74 | mState.blend.dither = true; |
| 75 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 76 | mState.blendColor.red = 0; |
| 77 | mState.blendColor.green = 0; |
| 78 | mState.blendColor.blue = 0; |
| 79 | mState.blendColor.alpha = 0; |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 80 | |
| 81 | mState.depthStencil.depthTest = false; |
| 82 | mState.depthStencil.depthFunc = GL_LESS; |
| 83 | mState.depthStencil.depthMask = true; |
| 84 | mState.depthStencil.stencilTest = false; |
| 85 | mState.depthStencil.stencilFunc = GL_ALWAYS; |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 86 | mState.depthStencil.stencilMask = -1; |
| 87 | mState.depthStencil.stencilWritemask = -1; |
| 88 | mState.depthStencil.stencilBackFunc = GL_ALWAYS; |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 89 | mState.depthStencil.stencilBackMask = - 1; |
| 90 | mState.depthStencil.stencilBackWritemask = -1; |
| 91 | mState.depthStencil.stencilFail = GL_KEEP; |
| 92 | mState.depthStencil.stencilPassDepthFail = GL_KEEP; |
| 93 | mState.depthStencil.stencilPassDepthPass = GL_KEEP; |
| 94 | mState.depthStencil.stencilBackFail = GL_KEEP; |
| 95 | mState.depthStencil.stencilBackPassDepthFail = GL_KEEP; |
| 96 | mState.depthStencil.stencilBackPassDepthPass = GL_KEEP; |
| 97 | |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 98 | mState.stencilRef = 0; |
| 99 | mState.stencilBackRef = 0; |
| 100 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 101 | mState.sampleCoverage = false; |
| 102 | mState.sampleCoverageValue = 1.0f; |
| 103 | mState.sampleCoverageInvert = false; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 104 | mState.generateMipmapHint = GL_DONT_CARE; |
| 105 | mState.fragmentShaderDerivativeHint = GL_DONT_CARE; |
| 106 | |
| 107 | mState.lineWidth = 1.0f; |
| 108 | |
daniel@transgaming.com | 3884e2c | 2012-11-28 19:41:00 +0000 | [diff] [blame] | 109 | mState.viewport.x = 0; |
| 110 | mState.viewport.y = 0; |
| 111 | mState.viewport.width = 0; |
| 112 | mState.viewport.height = 0; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 113 | mState.zNear = 0.0f; |
| 114 | mState.zFar = 1.0f; |
| 115 | |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 116 | mState.blend.colorMaskRed = true; |
| 117 | mState.blend.colorMaskGreen = true; |
| 118 | mState.blend.colorMaskBlue = true; |
| 119 | mState.blend.colorMaskAlpha = true; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 120 | |
| 121 | if (shareContext != NULL) |
| 122 | { |
| 123 | mResourceManager = shareContext->mResourceManager; |
| 124 | mResourceManager->addRef(); |
| 125 | } |
| 126 | else |
| 127 | { |
daniel@transgaming.com | 370482e | 2012-11-28 19:32:13 +0000 | [diff] [blame] | 128 | mResourceManager = new ResourceManager(mRenderer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | // [OpenGL ES 2.0.24] section 3.7 page 83: |
| 132 | // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional |
| 133 | // and cube map texture state vectors respectively associated with them. |
| 134 | // In order that access to these initial textures not be lost, they are treated as texture |
| 135 | // objects all of whose names are 0. |
| 136 | |
daniel@transgaming.com | 370482e | 2012-11-28 19:32:13 +0000 | [diff] [blame] | 137 | mTexture2DZero.set(new Texture2D(mRenderer, 0)); |
| 138 | mTextureCubeMapZero.set(new TextureCubeMap(mRenderer, 0)); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 139 | |
| 140 | mState.activeSampler = 0; |
| 141 | bindArrayBuffer(0); |
| 142 | bindElementArrayBuffer(0); |
| 143 | bindTextureCubeMap(0); |
| 144 | bindTexture2D(0); |
| 145 | bindReadFramebuffer(0); |
| 146 | bindDrawFramebuffer(0); |
| 147 | bindRenderbuffer(0); |
| 148 | |
| 149 | mState.currentProgram = 0; |
daniel@transgaming.com | 989c1c8 | 2012-07-24 18:40:38 +0000 | [diff] [blame] | 150 | mCurrentProgramBinary.set(NULL); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 151 | |
| 152 | mState.packAlignment = 4; |
| 153 | mState.unpackAlignment = 4; |
| 154 | mState.packReverseRowOrder = false; |
| 155 | |
| 156 | mVertexDataManager = NULL; |
| 157 | mIndexDataManager = NULL; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 158 | mLineLoopIB = NULL; |
| 159 | |
| 160 | mInvalidEnum = false; |
| 161 | mInvalidValue = false; |
| 162 | mInvalidOperation = false; |
| 163 | mOutOfMemory = false; |
| 164 | mInvalidFramebufferOperation = false; |
| 165 | |
| 166 | mHasBeenCurrent = false; |
| 167 | mContextLost = false; |
| 168 | mResetStatus = GL_NO_ERROR; |
| 169 | mResetStrategy = (notifyResets ? GL_LOSE_CONTEXT_ON_RESET_EXT : GL_NO_RESET_NOTIFICATION_EXT); |
| 170 | mRobustAccess = robustAccess; |
| 171 | |
| 172 | mSupportsDXT1Textures = false; |
| 173 | mSupportsDXT3Textures = false; |
| 174 | mSupportsDXT5Textures = false; |
| 175 | mSupportsEventQueries = false; |
| 176 | mSupportsOcclusionQueries = false; |
| 177 | mNumCompressedTextureFormats = 0; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 178 | mMaskedClearSavedState = NULL; |
| 179 | markAllStateDirty(); |
| 180 | } |
| 181 | |
| 182 | Context::~Context() |
| 183 | { |
| 184 | if (mState.currentProgram != 0) |
| 185 | { |
| 186 | Program *programObject = mResourceManager->getProgram(mState.currentProgram); |
| 187 | if (programObject) |
| 188 | { |
| 189 | programObject->release(); |
| 190 | } |
| 191 | mState.currentProgram = 0; |
| 192 | } |
daniel@transgaming.com | 989c1c8 | 2012-07-24 18:40:38 +0000 | [diff] [blame] | 193 | mCurrentProgramBinary.set(NULL); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 194 | |
| 195 | while (!mFramebufferMap.empty()) |
| 196 | { |
| 197 | deleteFramebuffer(mFramebufferMap.begin()->first); |
| 198 | } |
| 199 | |
| 200 | while (!mFenceMap.empty()) |
| 201 | { |
| 202 | deleteFence(mFenceMap.begin()->first); |
| 203 | } |
| 204 | |
| 205 | while (!mQueryMap.empty()) |
| 206 | { |
| 207 | deleteQuery(mQueryMap.begin()->first); |
| 208 | } |
| 209 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 210 | for (int type = 0; type < TEXTURE_TYPE_COUNT; type++) |
| 211 | { |
| 212 | for (int sampler = 0; sampler < MAX_COMBINED_TEXTURE_IMAGE_UNITS_VTF; sampler++) |
| 213 | { |
| 214 | mState.samplerTexture[type][sampler].set(NULL); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | for (int type = 0; type < TEXTURE_TYPE_COUNT; type++) |
| 219 | { |
| 220 | mIncompleteTextures[type].set(NULL); |
| 221 | } |
| 222 | |
| 223 | for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++) |
| 224 | { |
| 225 | mState.vertexAttribute[i].mBoundBuffer.set(NULL); |
| 226 | } |
| 227 | |
| 228 | for (int i = 0; i < QUERY_TYPE_COUNT; i++) |
| 229 | { |
| 230 | mState.activeQuery[i].set(NULL); |
| 231 | } |
| 232 | |
| 233 | mState.arrayBuffer.set(NULL); |
| 234 | mState.elementArrayBuffer.set(NULL); |
| 235 | mState.renderbuffer.set(NULL); |
| 236 | |
| 237 | mTexture2DZero.set(NULL); |
| 238 | mTextureCubeMapZero.set(NULL); |
| 239 | |
| 240 | delete mVertexDataManager; |
| 241 | delete mIndexDataManager; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 242 | delete mLineLoopIB; |
| 243 | |
| 244 | if (mMaskedClearSavedState) |
| 245 | { |
| 246 | mMaskedClearSavedState->Release(); |
| 247 | } |
| 248 | |
| 249 | mResourceManager->release(); |
| 250 | } |
| 251 | |
daniel@transgaming.com | ad62987 | 2012-11-28 19:32:06 +0000 | [diff] [blame] | 252 | void Context::makeCurrent(egl::Surface *surface) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 253 | { |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 254 | mDevice = mRenderer->getDevice(); // D3D9_REMOVE |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 255 | |
| 256 | if (!mHasBeenCurrent) |
| 257 | { |
daniel@transgaming.com | 408caa5 | 2012-10-31 18:47:01 +0000 | [diff] [blame] | 258 | mVertexDataManager = new VertexDataManager(mRenderer); |
| 259 | mIndexDataManager = new IndexDataManager(mRenderer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 260 | |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 261 | mSupportsShaderModel3 = mRenderer->getShaderModel3Support(); |
| 262 | mMaximumPointSize = mRenderer->getMaxPointSize(); |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 263 | mSupportsVertexTexture = mRenderer->getVertexTextureSupport(); |
| 264 | mSupportsNonPower2Texture = mRenderer->getNonPower2TextureSupport(); |
| 265 | mSupportsInstancing = mRenderer->getInstancingSupport(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 266 | |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 267 | mMaxTextureDimension = std::min(std::min(mRenderer->getMaxTextureWidth(), mRenderer->getMaxTextureHeight()), |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 268 | (int)gl::IMPLEMENTATION_MAX_TEXTURE_SIZE); |
| 269 | mMaxCubeTextureDimension = std::min(mMaxTextureDimension, (int)gl::IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE); |
| 270 | mMaxRenderbufferDimension = mMaxTextureDimension; |
| 271 | mMaxTextureLevel = log2(mMaxTextureDimension) + 1; |
daniel@transgaming.com | ba0570e | 2012-10-31 18:07:39 +0000 | [diff] [blame] | 272 | mMaxTextureAnisotropy = mRenderer->getTextureMaxAnisotropy(); |
daniel@transgaming.com | 07ab841 | 2012-07-12 15:17:09 +0000 | [diff] [blame] | 273 | TRACE("MaxTextureDimension=%d, MaxCubeTextureDimension=%d, MaxRenderbufferDimension=%d, MaxTextureLevel=%d, MaxTextureAnisotropy=%f", |
| 274 | mMaxTextureDimension, mMaxCubeTextureDimension, mMaxRenderbufferDimension, mMaxTextureLevel, mMaxTextureAnisotropy); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 275 | |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 276 | mSupportsEventQueries = mRenderer->getEventQuerySupport(); |
| 277 | mSupportsOcclusionQueries = mRenderer->getOcclusionQuerySupport(); |
| 278 | mSupportsDXT1Textures = mRenderer->getDXT1TextureSupport(); |
| 279 | mSupportsDXT3Textures = mRenderer->getDXT3TextureSupport(); |
| 280 | mSupportsDXT5Textures = mRenderer->getDXT5TextureSupport(); |
| 281 | mSupportsFloat32Textures = mRenderer->getFloat32TextureSupport(&mSupportsFloat32LinearFilter, &mSupportsFloat32RenderableTextures); |
| 282 | mSupportsFloat16Textures = mRenderer->getFloat16TextureSupport(&mSupportsFloat16LinearFilter, &mSupportsFloat16RenderableTextures); |
| 283 | mSupportsLuminanceTextures = mRenderer->getLuminanceTextureSupport(); |
| 284 | mSupportsLuminanceAlphaTextures = mRenderer->getLuminanceAlphaTextureSupport(); |
| 285 | mSupportsDepthTextures = mRenderer->getDepthTextureSupport(); |
daniel@transgaming.com | ba0570e | 2012-10-31 18:07:39 +0000 | [diff] [blame] | 286 | mSupportsTextureFilterAnisotropy = mRenderer->getTextureFilterAnisotropySupport(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 287 | |
daniel@transgaming.com | 5f4c136 | 2012-10-31 18:29:00 +0000 | [diff] [blame] | 288 | mSupports32bitIndices = mRenderer->get32BitIndexSupport(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 289 | |
| 290 | mNumCompressedTextureFormats = 0; |
| 291 | if (supportsDXT1Textures()) |
| 292 | { |
| 293 | mNumCompressedTextureFormats += 2; |
| 294 | } |
| 295 | if (supportsDXT3Textures()) |
| 296 | { |
| 297 | mNumCompressedTextureFormats += 1; |
| 298 | } |
| 299 | if (supportsDXT5Textures()) |
| 300 | { |
| 301 | mNumCompressedTextureFormats += 1; |
| 302 | } |
| 303 | |
| 304 | initExtensionString(); |
| 305 | initRendererString(); |
| 306 | |
daniel@transgaming.com | 3884e2c | 2012-11-28 19:41:00 +0000 | [diff] [blame] | 307 | mState.viewport.x = 0; |
| 308 | mState.viewport.y = 0; |
| 309 | mState.viewport.width = surface->getWidth(); |
| 310 | mState.viewport.height = surface->getHeight(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 311 | |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 312 | mState.scissor.x = 0; |
| 313 | mState.scissor.y = 0; |
| 314 | mState.scissor.width = surface->getWidth(); |
| 315 | mState.scissor.height = surface->getHeight(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 316 | |
| 317 | mHasBeenCurrent = true; |
| 318 | } |
| 319 | |
daniel@transgaming.com | 024786d | 2012-10-31 18:42:55 +0000 | [diff] [blame] | 320 | // Wrap the existing swapchain resources into GL objects and assign them to the '0' names |
daniel@transgaming.com | 76d3e6e | 2012-10-31 19:55:33 +0000 | [diff] [blame] | 321 | rx::SwapChain *swapchain = surface->getSwapChain(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 322 | |
daniel@transgaming.com | 70062c9 | 2012-11-28 19:32:30 +0000 | [diff] [blame] | 323 | Colorbuffer *colorbufferZero = new Colorbuffer(mRenderer, swapchain); |
| 324 | DepthStencilbuffer *depthStencilbufferZero = new DepthStencilbuffer(mRenderer, swapchain); |
daniel@transgaming.com | 16418b1 | 2012-11-28 19:32:22 +0000 | [diff] [blame] | 325 | Framebuffer *framebufferZero = new DefaultFramebuffer(mRenderer, colorbufferZero, depthStencilbufferZero); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 326 | |
| 327 | setFramebufferZero(framebufferZero); |
| 328 | |
apatrick@chromium.org | 909f21c | 2012-08-17 20:06:02 +0000 | [diff] [blame] | 329 | // Reset pixel shader to null to work around a bug that only happens with Intel GPUs. |
| 330 | // http://crbug.com/110343 |
| 331 | mDevice->SetPixelShader(NULL); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 332 | |
| 333 | markAllStateDirty(); |
| 334 | } |
| 335 | |
| 336 | // This function will set all of the state-related dirty flags, so that all state is set during next pre-draw. |
| 337 | void Context::markAllStateDirty() |
| 338 | { |
| 339 | for (int t = 0; t < MAX_TEXTURE_IMAGE_UNITS; t++) |
| 340 | { |
| 341 | mAppliedTextureSerialPS[t] = 0; |
| 342 | } |
| 343 | |
| 344 | for (int t = 0; t < MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; t++) |
| 345 | { |
| 346 | mAppliedTextureSerialVS[t] = 0; |
| 347 | } |
| 348 | |
daniel@transgaming.com | e6af4f9 | 2012-07-24 18:31:31 +0000 | [diff] [blame] | 349 | mAppliedProgramBinarySerial = 0; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 350 | mAppliedIBSerial = 0; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 351 | |
| 352 | mVertexDeclarationCache.markStateDirty(); |
| 353 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 354 | mDxUniformsDirty = true; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | void Context::markDxUniformsDirty() |
| 358 | { |
| 359 | mDxUniformsDirty = true; |
| 360 | } |
| 361 | |
daniel@transgaming.com | f688c0d | 2012-10-31 17:52:57 +0000 | [diff] [blame] | 362 | // NOTE: this function should not assume that this context is current! |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 363 | void Context::markContextLost() |
| 364 | { |
| 365 | if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT) |
| 366 | mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT; |
| 367 | mContextLost = true; |
| 368 | } |
| 369 | |
| 370 | bool Context::isContextLost() |
| 371 | { |
| 372 | return mContextLost; |
| 373 | } |
| 374 | |
| 375 | void Context::setClearColor(float red, float green, float blue, float alpha) |
| 376 | { |
| 377 | mState.colorClearValue.red = red; |
| 378 | mState.colorClearValue.green = green; |
| 379 | mState.colorClearValue.blue = blue; |
| 380 | mState.colorClearValue.alpha = alpha; |
| 381 | } |
| 382 | |
| 383 | void Context::setClearDepth(float depth) |
| 384 | { |
| 385 | mState.depthClearValue = depth; |
| 386 | } |
| 387 | |
| 388 | void Context::setClearStencil(int stencil) |
| 389 | { |
| 390 | mState.stencilClearValue = stencil; |
| 391 | } |
| 392 | |
| 393 | void Context::setCullFace(bool enabled) |
| 394 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 395 | mState.rasterizer.cullFace = enabled; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | bool Context::isCullFaceEnabled() const |
| 399 | { |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 400 | return mState.rasterizer.cullFace; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | void Context::setCullMode(GLenum mode) |
| 404 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 405 | mState.rasterizer.cullMode = mode; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | void Context::setFrontFace(GLenum front) |
| 409 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 410 | mState.rasterizer.frontFace = front; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | void Context::setDepthTest(bool enabled) |
| 414 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 415 | mState.depthStencil.depthTest = enabled; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | bool Context::isDepthTestEnabled() const |
| 419 | { |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 420 | return mState.depthStencil.depthTest; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | void Context::setDepthFunc(GLenum depthFunc) |
| 424 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 425 | mState.depthStencil.depthFunc = depthFunc; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | void Context::setDepthRange(float zNear, float zFar) |
| 429 | { |
| 430 | mState.zNear = zNear; |
| 431 | mState.zFar = zFar; |
| 432 | } |
| 433 | |
| 434 | void Context::setBlend(bool enabled) |
| 435 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 436 | mState.blend.blend = enabled; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | bool Context::isBlendEnabled() const |
| 440 | { |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 441 | return mState.blend.blend; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | void Context::setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha) |
| 445 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 446 | mState.blend.sourceBlendRGB = sourceRGB; |
| 447 | mState.blend.destBlendRGB = destRGB; |
| 448 | mState.blend.sourceBlendAlpha = sourceAlpha; |
| 449 | mState.blend.destBlendAlpha = destAlpha; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | void Context::setBlendColor(float red, float green, float blue, float alpha) |
| 453 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 454 | mState.blendColor.red = red; |
| 455 | mState.blendColor.green = green; |
| 456 | mState.blendColor.blue = blue; |
| 457 | mState.blendColor.alpha = alpha; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | void Context::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation) |
| 461 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 462 | mState.blend.blendEquationRGB = rgbEquation; |
| 463 | mState.blend.blendEquationAlpha = alphaEquation; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | void Context::setStencilTest(bool enabled) |
| 467 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 468 | mState.depthStencil.stencilTest = enabled; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | bool Context::isStencilTestEnabled() const |
| 472 | { |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 473 | return mState.depthStencil.stencilTest; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | void Context::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask) |
| 477 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 478 | mState.depthStencil.stencilFunc = stencilFunc; |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 479 | mState.stencilRef = (stencilRef > 0) ? stencilRef : 0; |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 480 | mState.depthStencil.stencilMask = stencilMask; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | void Context::setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask) |
| 484 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 485 | mState.depthStencil.stencilBackFunc = stencilBackFunc; |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 486 | mState.stencilBackRef = (stencilBackRef > 0) ? stencilBackRef : 0; |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 487 | mState.depthStencil.stencilBackMask = stencilBackMask; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | void Context::setStencilWritemask(GLuint stencilWritemask) |
| 491 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 492 | mState.depthStencil.stencilWritemask = stencilWritemask; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | void Context::setStencilBackWritemask(GLuint stencilBackWritemask) |
| 496 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 497 | mState.depthStencil.stencilBackWritemask = stencilBackWritemask; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | void Context::setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass) |
| 501 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 502 | mState.depthStencil.stencilFail = stencilFail; |
| 503 | mState.depthStencil.stencilPassDepthFail = stencilPassDepthFail; |
| 504 | mState.depthStencil.stencilPassDepthPass = stencilPassDepthPass; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | void Context::setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass) |
| 508 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 509 | mState.depthStencil.stencilBackFail = stencilBackFail; |
| 510 | mState.depthStencil.stencilBackPassDepthFail = stencilBackPassDepthFail; |
| 511 | mState.depthStencil.stencilBackPassDepthPass = stencilBackPassDepthPass; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | void Context::setPolygonOffsetFill(bool enabled) |
| 515 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 516 | mState.rasterizer.polygonOffsetFill = enabled; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | bool Context::isPolygonOffsetFillEnabled() const |
| 520 | { |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 521 | return mState.rasterizer.polygonOffsetFill; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | void Context::setPolygonOffsetParams(GLfloat factor, GLfloat units) |
| 525 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 526 | mState.rasterizer.polygonOffsetFactor = factor; |
| 527 | mState.rasterizer.polygonOffsetUnits = units; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | void Context::setSampleAlphaToCoverage(bool enabled) |
| 531 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 532 | mState.blend.sampleAlphaToCoverage = enabled; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | bool Context::isSampleAlphaToCoverageEnabled() const |
| 536 | { |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 537 | return mState.blend.sampleAlphaToCoverage; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | void Context::setSampleCoverage(bool enabled) |
| 541 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 542 | mState.sampleCoverage = enabled; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | bool Context::isSampleCoverageEnabled() const |
| 546 | { |
| 547 | return mState.sampleCoverage; |
| 548 | } |
| 549 | |
| 550 | void Context::setSampleCoverageParams(GLclampf value, bool invert) |
| 551 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 552 | mState.sampleCoverageValue = value; |
| 553 | mState.sampleCoverageInvert = invert; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | void Context::setScissorTest(bool enabled) |
| 557 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 558 | mState.rasterizer.scissorTest = enabled; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | bool Context::isScissorTestEnabled() const |
| 562 | { |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 563 | return mState.rasterizer.scissorTest; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | void Context::setDither(bool enabled) |
| 567 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 568 | mState.blend.dither = enabled; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | bool Context::isDitherEnabled() const |
| 572 | { |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 573 | return mState.blend.dither; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | void Context::setLineWidth(GLfloat width) |
| 577 | { |
| 578 | mState.lineWidth = width; |
| 579 | } |
| 580 | |
| 581 | void Context::setGenerateMipmapHint(GLenum hint) |
| 582 | { |
| 583 | mState.generateMipmapHint = hint; |
| 584 | } |
| 585 | |
| 586 | void Context::setFragmentShaderDerivativeHint(GLenum hint) |
| 587 | { |
| 588 | mState.fragmentShaderDerivativeHint = hint; |
| 589 | // TODO: Propagate the hint to shader translator so we can write |
| 590 | // ddx, ddx_coarse, or ddx_fine depending on the hint. |
| 591 | // Ignore for now. It is valid for implementations to ignore hint. |
| 592 | } |
| 593 | |
| 594 | void Context::setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height) |
| 595 | { |
daniel@transgaming.com | 3884e2c | 2012-11-28 19:41:00 +0000 | [diff] [blame] | 596 | mState.viewport.x = x; |
| 597 | mState.viewport.y = y; |
| 598 | mState.viewport.width = width; |
| 599 | mState.viewport.height = height; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | void Context::setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height) |
| 603 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 604 | mState.scissor.x = x; |
| 605 | mState.scissor.y = y; |
| 606 | mState.scissor.width = width; |
| 607 | mState.scissor.height = height; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | void Context::setColorMask(bool red, bool green, bool blue, bool alpha) |
| 611 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 612 | mState.blend.colorMaskRed = red; |
| 613 | mState.blend.colorMaskGreen = green; |
| 614 | mState.blend.colorMaskBlue = blue; |
| 615 | mState.blend.colorMaskAlpha = alpha; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | void Context::setDepthMask(bool mask) |
| 619 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 620 | mState.depthStencil.depthMask = mask; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | void Context::setActiveSampler(unsigned int active) |
| 624 | { |
| 625 | mState.activeSampler = active; |
| 626 | } |
| 627 | |
| 628 | GLuint Context::getReadFramebufferHandle() const |
| 629 | { |
| 630 | return mState.readFramebuffer; |
| 631 | } |
| 632 | |
| 633 | GLuint Context::getDrawFramebufferHandle() const |
| 634 | { |
| 635 | return mState.drawFramebuffer; |
| 636 | } |
| 637 | |
| 638 | GLuint Context::getRenderbufferHandle() const |
| 639 | { |
| 640 | return mState.renderbuffer.id(); |
| 641 | } |
| 642 | |
| 643 | GLuint Context::getArrayBufferHandle() const |
| 644 | { |
| 645 | return mState.arrayBuffer.id(); |
| 646 | } |
| 647 | |
| 648 | GLuint Context::getActiveQuery(GLenum target) const |
| 649 | { |
| 650 | Query *queryObject = NULL; |
| 651 | |
| 652 | switch (target) |
| 653 | { |
| 654 | case GL_ANY_SAMPLES_PASSED_EXT: |
| 655 | queryObject = mState.activeQuery[QUERY_ANY_SAMPLES_PASSED].get(); |
| 656 | break; |
| 657 | case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT: |
| 658 | queryObject = mState.activeQuery[QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE].get(); |
| 659 | break; |
| 660 | default: |
| 661 | ASSERT(false); |
| 662 | } |
| 663 | |
| 664 | if (queryObject) |
| 665 | { |
| 666 | return queryObject->id(); |
| 667 | } |
| 668 | else |
| 669 | { |
| 670 | return 0; |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | void Context::setEnableVertexAttribArray(unsigned int attribNum, bool enabled) |
| 675 | { |
| 676 | mState.vertexAttribute[attribNum].mArrayEnabled = enabled; |
| 677 | } |
| 678 | |
| 679 | const VertexAttribute &Context::getVertexAttribState(unsigned int attribNum) |
| 680 | { |
| 681 | return mState.vertexAttribute[attribNum]; |
| 682 | } |
| 683 | |
| 684 | void Context::setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type, bool normalized, |
| 685 | GLsizei stride, const void *pointer) |
| 686 | { |
| 687 | mState.vertexAttribute[attribNum].mBoundBuffer.set(boundBuffer); |
| 688 | mState.vertexAttribute[attribNum].mSize = size; |
| 689 | mState.vertexAttribute[attribNum].mType = type; |
| 690 | mState.vertexAttribute[attribNum].mNormalized = normalized; |
| 691 | mState.vertexAttribute[attribNum].mStride = stride; |
| 692 | mState.vertexAttribute[attribNum].mPointer = pointer; |
| 693 | } |
| 694 | |
| 695 | const void *Context::getVertexAttribPointer(unsigned int attribNum) const |
| 696 | { |
| 697 | return mState.vertexAttribute[attribNum].mPointer; |
| 698 | } |
| 699 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 700 | void Context::setPackAlignment(GLint alignment) |
| 701 | { |
| 702 | mState.packAlignment = alignment; |
| 703 | } |
| 704 | |
| 705 | GLint Context::getPackAlignment() const |
| 706 | { |
| 707 | return mState.packAlignment; |
| 708 | } |
| 709 | |
| 710 | void Context::setUnpackAlignment(GLint alignment) |
| 711 | { |
| 712 | mState.unpackAlignment = alignment; |
| 713 | } |
| 714 | |
| 715 | GLint Context::getUnpackAlignment() const |
| 716 | { |
| 717 | return mState.unpackAlignment; |
| 718 | } |
| 719 | |
| 720 | void Context::setPackReverseRowOrder(bool reverseRowOrder) |
| 721 | { |
| 722 | mState.packReverseRowOrder = reverseRowOrder; |
| 723 | } |
| 724 | |
| 725 | bool Context::getPackReverseRowOrder() const |
| 726 | { |
| 727 | return mState.packReverseRowOrder; |
| 728 | } |
| 729 | |
| 730 | GLuint Context::createBuffer() |
| 731 | { |
| 732 | return mResourceManager->createBuffer(); |
| 733 | } |
| 734 | |
| 735 | GLuint Context::createProgram() |
| 736 | { |
| 737 | return mResourceManager->createProgram(); |
| 738 | } |
| 739 | |
| 740 | GLuint Context::createShader(GLenum type) |
| 741 | { |
| 742 | return mResourceManager->createShader(type); |
| 743 | } |
| 744 | |
| 745 | GLuint Context::createTexture() |
| 746 | { |
| 747 | return mResourceManager->createTexture(); |
| 748 | } |
| 749 | |
| 750 | GLuint Context::createRenderbuffer() |
| 751 | { |
| 752 | return mResourceManager->createRenderbuffer(); |
| 753 | } |
| 754 | |
| 755 | // Returns an unused framebuffer name |
| 756 | GLuint Context::createFramebuffer() |
| 757 | { |
| 758 | GLuint handle = mFramebufferHandleAllocator.allocate(); |
| 759 | |
| 760 | mFramebufferMap[handle] = NULL; |
| 761 | |
| 762 | return handle; |
| 763 | } |
| 764 | |
| 765 | GLuint Context::createFence() |
| 766 | { |
| 767 | GLuint handle = mFenceHandleAllocator.allocate(); |
| 768 | |
daniel@transgaming.com | ef21ab2 | 2012-10-31 17:52:47 +0000 | [diff] [blame] | 769 | mFenceMap[handle] = new Fence(mRenderer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 770 | |
| 771 | return handle; |
| 772 | } |
| 773 | |
| 774 | // Returns an unused query name |
| 775 | GLuint Context::createQuery() |
| 776 | { |
| 777 | GLuint handle = mQueryHandleAllocator.allocate(); |
| 778 | |
| 779 | mQueryMap[handle] = NULL; |
| 780 | |
| 781 | return handle; |
| 782 | } |
| 783 | |
| 784 | void Context::deleteBuffer(GLuint buffer) |
| 785 | { |
| 786 | if (mResourceManager->getBuffer(buffer)) |
| 787 | { |
| 788 | detachBuffer(buffer); |
| 789 | } |
| 790 | |
| 791 | mResourceManager->deleteBuffer(buffer); |
| 792 | } |
| 793 | |
| 794 | void Context::deleteShader(GLuint shader) |
| 795 | { |
| 796 | mResourceManager->deleteShader(shader); |
| 797 | } |
| 798 | |
| 799 | void Context::deleteProgram(GLuint program) |
| 800 | { |
| 801 | mResourceManager->deleteProgram(program); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | void Context::deleteTexture(GLuint texture) |
| 805 | { |
| 806 | if (mResourceManager->getTexture(texture)) |
| 807 | { |
| 808 | detachTexture(texture); |
| 809 | } |
| 810 | |
| 811 | mResourceManager->deleteTexture(texture); |
| 812 | } |
| 813 | |
| 814 | void Context::deleteRenderbuffer(GLuint renderbuffer) |
| 815 | { |
| 816 | if (mResourceManager->getRenderbuffer(renderbuffer)) |
| 817 | { |
| 818 | detachRenderbuffer(renderbuffer); |
| 819 | } |
| 820 | |
| 821 | mResourceManager->deleteRenderbuffer(renderbuffer); |
| 822 | } |
| 823 | |
| 824 | void Context::deleteFramebuffer(GLuint framebuffer) |
| 825 | { |
| 826 | FramebufferMap::iterator framebufferObject = mFramebufferMap.find(framebuffer); |
| 827 | |
| 828 | if (framebufferObject != mFramebufferMap.end()) |
| 829 | { |
| 830 | detachFramebuffer(framebuffer); |
| 831 | |
| 832 | mFramebufferHandleAllocator.release(framebufferObject->first); |
| 833 | delete framebufferObject->second; |
| 834 | mFramebufferMap.erase(framebufferObject); |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | void Context::deleteFence(GLuint fence) |
| 839 | { |
| 840 | FenceMap::iterator fenceObject = mFenceMap.find(fence); |
| 841 | |
| 842 | if (fenceObject != mFenceMap.end()) |
| 843 | { |
| 844 | mFenceHandleAllocator.release(fenceObject->first); |
| 845 | delete fenceObject->second; |
| 846 | mFenceMap.erase(fenceObject); |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | void Context::deleteQuery(GLuint query) |
| 851 | { |
| 852 | QueryMap::iterator queryObject = mQueryMap.find(query); |
| 853 | if (queryObject != mQueryMap.end()) |
| 854 | { |
| 855 | mQueryHandleAllocator.release(queryObject->first); |
| 856 | if (queryObject->second) |
| 857 | { |
| 858 | queryObject->second->release(); |
| 859 | } |
| 860 | mQueryMap.erase(queryObject); |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | Buffer *Context::getBuffer(GLuint handle) |
| 865 | { |
| 866 | return mResourceManager->getBuffer(handle); |
| 867 | } |
| 868 | |
| 869 | Shader *Context::getShader(GLuint handle) |
| 870 | { |
| 871 | return mResourceManager->getShader(handle); |
| 872 | } |
| 873 | |
| 874 | Program *Context::getProgram(GLuint handle) |
| 875 | { |
| 876 | return mResourceManager->getProgram(handle); |
| 877 | } |
| 878 | |
| 879 | Texture *Context::getTexture(GLuint handle) |
| 880 | { |
| 881 | return mResourceManager->getTexture(handle); |
| 882 | } |
| 883 | |
| 884 | Renderbuffer *Context::getRenderbuffer(GLuint handle) |
| 885 | { |
| 886 | return mResourceManager->getRenderbuffer(handle); |
| 887 | } |
| 888 | |
| 889 | Framebuffer *Context::getReadFramebuffer() |
| 890 | { |
| 891 | return getFramebuffer(mState.readFramebuffer); |
| 892 | } |
| 893 | |
| 894 | Framebuffer *Context::getDrawFramebuffer() |
| 895 | { |
| 896 | return mBoundDrawFramebuffer; |
| 897 | } |
| 898 | |
| 899 | void Context::bindArrayBuffer(unsigned int buffer) |
| 900 | { |
| 901 | mResourceManager->checkBufferAllocation(buffer); |
| 902 | |
| 903 | mState.arrayBuffer.set(getBuffer(buffer)); |
| 904 | } |
| 905 | |
| 906 | void Context::bindElementArrayBuffer(unsigned int buffer) |
| 907 | { |
| 908 | mResourceManager->checkBufferAllocation(buffer); |
| 909 | |
| 910 | mState.elementArrayBuffer.set(getBuffer(buffer)); |
| 911 | } |
| 912 | |
| 913 | void Context::bindTexture2D(GLuint texture) |
| 914 | { |
| 915 | mResourceManager->checkTextureAllocation(texture, TEXTURE_2D); |
| 916 | |
| 917 | mState.samplerTexture[TEXTURE_2D][mState.activeSampler].set(getTexture(texture)); |
| 918 | } |
| 919 | |
| 920 | void Context::bindTextureCubeMap(GLuint texture) |
| 921 | { |
| 922 | mResourceManager->checkTextureAllocation(texture, TEXTURE_CUBE); |
| 923 | |
| 924 | mState.samplerTexture[TEXTURE_CUBE][mState.activeSampler].set(getTexture(texture)); |
| 925 | } |
| 926 | |
| 927 | void Context::bindReadFramebuffer(GLuint framebuffer) |
| 928 | { |
| 929 | if (!getFramebuffer(framebuffer)) |
| 930 | { |
daniel@transgaming.com | 16418b1 | 2012-11-28 19:32:22 +0000 | [diff] [blame] | 931 | mFramebufferMap[framebuffer] = new Framebuffer(mRenderer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | mState.readFramebuffer = framebuffer; |
| 935 | } |
| 936 | |
| 937 | void Context::bindDrawFramebuffer(GLuint framebuffer) |
| 938 | { |
| 939 | if (!getFramebuffer(framebuffer)) |
| 940 | { |
daniel@transgaming.com | 16418b1 | 2012-11-28 19:32:22 +0000 | [diff] [blame] | 941 | mFramebufferMap[framebuffer] = new Framebuffer(mRenderer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | mState.drawFramebuffer = framebuffer; |
| 945 | |
| 946 | mBoundDrawFramebuffer = getFramebuffer(framebuffer); |
| 947 | } |
| 948 | |
| 949 | void Context::bindRenderbuffer(GLuint renderbuffer) |
| 950 | { |
| 951 | mResourceManager->checkRenderbufferAllocation(renderbuffer); |
| 952 | |
| 953 | mState.renderbuffer.set(getRenderbuffer(renderbuffer)); |
| 954 | } |
| 955 | |
| 956 | void Context::useProgram(GLuint program) |
| 957 | { |
| 958 | GLuint priorProgram = mState.currentProgram; |
| 959 | mState.currentProgram = program; // Must switch before trying to delete, otherwise it only gets flagged. |
| 960 | |
| 961 | if (priorProgram != program) |
| 962 | { |
| 963 | Program *newProgram = mResourceManager->getProgram(program); |
| 964 | Program *oldProgram = mResourceManager->getProgram(priorProgram); |
daniel@transgaming.com | 989c1c8 | 2012-07-24 18:40:38 +0000 | [diff] [blame] | 965 | mCurrentProgramBinary.set(NULL); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 966 | mDxUniformsDirty = true; |
| 967 | |
| 968 | if (newProgram) |
| 969 | { |
| 970 | newProgram->addRef(); |
daniel@transgaming.com | 989c1c8 | 2012-07-24 18:40:38 +0000 | [diff] [blame] | 971 | mCurrentProgramBinary.set(newProgram->getProgramBinary()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | if (oldProgram) |
| 975 | { |
| 976 | oldProgram->release(); |
| 977 | } |
| 978 | } |
| 979 | } |
| 980 | |
daniel@transgaming.com | 95d2942 | 2012-07-24 18:36:10 +0000 | [diff] [blame] | 981 | void Context::linkProgram(GLuint program) |
| 982 | { |
| 983 | Program *programObject = mResourceManager->getProgram(program); |
| 984 | |
daniel@transgaming.com | 12394cf | 2012-07-24 18:37:59 +0000 | [diff] [blame] | 985 | bool linked = programObject->link(); |
| 986 | |
| 987 | // if the current program was relinked successfully we |
| 988 | // need to install the new executables |
| 989 | if (linked && program == mState.currentProgram) |
| 990 | { |
daniel@transgaming.com | 989c1c8 | 2012-07-24 18:40:38 +0000 | [diff] [blame] | 991 | mCurrentProgramBinary.set(programObject->getProgramBinary()); |
daniel@transgaming.com | 12394cf | 2012-07-24 18:37:59 +0000 | [diff] [blame] | 992 | mDxUniformsDirty = true; |
| 993 | } |
daniel@transgaming.com | 95d2942 | 2012-07-24 18:36:10 +0000 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | void Context::setProgramBinary(GLuint program, const void *binary, GLint length) |
| 997 | { |
| 998 | Program *programObject = mResourceManager->getProgram(program); |
| 999 | |
daniel@transgaming.com | 12394cf | 2012-07-24 18:37:59 +0000 | [diff] [blame] | 1000 | bool loaded = programObject->setProgramBinary(binary, length); |
| 1001 | |
| 1002 | // if the current program was reloaded successfully we |
| 1003 | // need to install the new executables |
| 1004 | if (loaded && program == mState.currentProgram) |
| 1005 | { |
daniel@transgaming.com | 989c1c8 | 2012-07-24 18:40:38 +0000 | [diff] [blame] | 1006 | mCurrentProgramBinary.set(programObject->getProgramBinary()); |
daniel@transgaming.com | 12394cf | 2012-07-24 18:37:59 +0000 | [diff] [blame] | 1007 | mDxUniformsDirty = true; |
| 1008 | } |
| 1009 | |
daniel@transgaming.com | 95d2942 | 2012-07-24 18:36:10 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1012 | void Context::beginQuery(GLenum target, GLuint query) |
| 1013 | { |
| 1014 | // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> |
| 1015 | // of zero, if the active query object name for <target> is non-zero (for the |
| 1016 | // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if |
| 1017 | // the active query for either target is non-zero), if <id> is the name of an |
| 1018 | // existing query object whose type does not match <target>, or if <id> is the |
| 1019 | // active query object name for any query type, the error INVALID_OPERATION is |
| 1020 | // generated. |
| 1021 | |
| 1022 | // Ensure no other queries are active |
| 1023 | // NOTE: If other queries than occlusion are supported, we will need to check |
| 1024 | // separately that: |
| 1025 | // a) The query ID passed is not the current active query for any target/type |
| 1026 | // b) There are no active queries for the requested target (and in the case |
| 1027 | // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 1028 | // no query may be active for either if glBeginQuery targets either. |
| 1029 | for (int i = 0; i < QUERY_TYPE_COUNT; i++) |
| 1030 | { |
| 1031 | if (mState.activeQuery[i].get() != NULL) |
| 1032 | { |
| 1033 | return error(GL_INVALID_OPERATION); |
| 1034 | } |
| 1035 | } |
| 1036 | |
| 1037 | QueryType qType; |
| 1038 | switch (target) |
| 1039 | { |
| 1040 | case GL_ANY_SAMPLES_PASSED_EXT: |
| 1041 | qType = QUERY_ANY_SAMPLES_PASSED; |
| 1042 | break; |
| 1043 | case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT: |
| 1044 | qType = QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE; |
| 1045 | break; |
| 1046 | default: |
| 1047 | ASSERT(false); |
| 1048 | return; |
| 1049 | } |
| 1050 | |
| 1051 | Query *queryObject = getQuery(query, true, target); |
| 1052 | |
| 1053 | // check that name was obtained with glGenQueries |
| 1054 | if (!queryObject) |
| 1055 | { |
| 1056 | return error(GL_INVALID_OPERATION); |
| 1057 | } |
| 1058 | |
| 1059 | // check for type mismatch |
| 1060 | if (queryObject->getType() != target) |
| 1061 | { |
| 1062 | return error(GL_INVALID_OPERATION); |
| 1063 | } |
| 1064 | |
| 1065 | // set query as active for specified target |
| 1066 | mState.activeQuery[qType].set(queryObject); |
| 1067 | |
| 1068 | // begin query |
| 1069 | queryObject->begin(); |
| 1070 | } |
| 1071 | |
| 1072 | void Context::endQuery(GLenum target) |
| 1073 | { |
| 1074 | QueryType qType; |
| 1075 | |
| 1076 | switch (target) |
| 1077 | { |
| 1078 | case GL_ANY_SAMPLES_PASSED_EXT: |
| 1079 | qType = QUERY_ANY_SAMPLES_PASSED; |
| 1080 | break; |
| 1081 | case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT: |
| 1082 | qType = QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE; |
| 1083 | break; |
| 1084 | default: |
| 1085 | ASSERT(false); |
| 1086 | return; |
| 1087 | } |
| 1088 | |
| 1089 | Query *queryObject = mState.activeQuery[qType].get(); |
| 1090 | |
| 1091 | if (queryObject == NULL) |
| 1092 | { |
| 1093 | return error(GL_INVALID_OPERATION); |
| 1094 | } |
| 1095 | |
| 1096 | queryObject->end(); |
| 1097 | |
| 1098 | mState.activeQuery[qType].set(NULL); |
| 1099 | } |
| 1100 | |
| 1101 | void Context::setFramebufferZero(Framebuffer *buffer) |
| 1102 | { |
| 1103 | delete mFramebufferMap[0]; |
| 1104 | mFramebufferMap[0] = buffer; |
| 1105 | if (mState.drawFramebuffer == 0) |
| 1106 | { |
| 1107 | mBoundDrawFramebuffer = buffer; |
| 1108 | } |
| 1109 | } |
| 1110 | |
daniel@transgaming.com | 70062c9 | 2012-11-28 19:32:30 +0000 | [diff] [blame] | 1111 | void Context::setRenderbufferStorage(GLsizei width, GLsizei height, GLenum internalformat, GLsizei samples) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1112 | { |
daniel@transgaming.com | 70062c9 | 2012-11-28 19:32:30 +0000 | [diff] [blame] | 1113 | RenderbufferStorage *renderbuffer = NULL; |
| 1114 | switch (internalformat) |
| 1115 | { |
| 1116 | case GL_DEPTH_COMPONENT16: |
| 1117 | renderbuffer = new gl::Depthbuffer(mRenderer, width, height, samples); |
| 1118 | break; |
| 1119 | case GL_RGBA4: |
| 1120 | case GL_RGB5_A1: |
| 1121 | case GL_RGB565: |
| 1122 | case GL_RGB8_OES: |
| 1123 | case GL_RGBA8_OES: |
| 1124 | renderbuffer = new gl::Colorbuffer(mRenderer,width, height, internalformat, samples); |
| 1125 | break; |
| 1126 | case GL_STENCIL_INDEX8: |
| 1127 | renderbuffer = new gl::Stencilbuffer(mRenderer, width, height, samples); |
| 1128 | break; |
| 1129 | case GL_DEPTH24_STENCIL8_OES: |
| 1130 | renderbuffer = new gl::DepthStencilbuffer(mRenderer, width, height, samples); |
| 1131 | break; |
| 1132 | default: |
| 1133 | UNREACHABLE(); return; |
| 1134 | } |
| 1135 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1136 | Renderbuffer *renderbufferObject = mState.renderbuffer.get(); |
| 1137 | renderbufferObject->setStorage(renderbuffer); |
| 1138 | } |
| 1139 | |
| 1140 | Framebuffer *Context::getFramebuffer(unsigned int handle) |
| 1141 | { |
| 1142 | FramebufferMap::iterator framebuffer = mFramebufferMap.find(handle); |
| 1143 | |
| 1144 | if (framebuffer == mFramebufferMap.end()) |
| 1145 | { |
| 1146 | return NULL; |
| 1147 | } |
| 1148 | else |
| 1149 | { |
| 1150 | return framebuffer->second; |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | Fence *Context::getFence(unsigned int handle) |
| 1155 | { |
| 1156 | FenceMap::iterator fence = mFenceMap.find(handle); |
| 1157 | |
| 1158 | if (fence == mFenceMap.end()) |
| 1159 | { |
| 1160 | return NULL; |
| 1161 | } |
| 1162 | else |
| 1163 | { |
| 1164 | return fence->second; |
| 1165 | } |
| 1166 | } |
| 1167 | |
| 1168 | Query *Context::getQuery(unsigned int handle, bool create, GLenum type) |
| 1169 | { |
| 1170 | QueryMap::iterator query = mQueryMap.find(handle); |
| 1171 | |
| 1172 | if (query == mQueryMap.end()) |
| 1173 | { |
| 1174 | return NULL; |
| 1175 | } |
| 1176 | else |
| 1177 | { |
| 1178 | if (!query->second && create) |
| 1179 | { |
daniel@transgaming.com | ef21ab2 | 2012-10-31 17:52:47 +0000 | [diff] [blame] | 1180 | query->second = new Query(mRenderer, handle, type); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1181 | query->second->addRef(); |
| 1182 | } |
| 1183 | return query->second; |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | Buffer *Context::getArrayBuffer() |
| 1188 | { |
| 1189 | return mState.arrayBuffer.get(); |
| 1190 | } |
| 1191 | |
| 1192 | Buffer *Context::getElementArrayBuffer() |
| 1193 | { |
| 1194 | return mState.elementArrayBuffer.get(); |
| 1195 | } |
| 1196 | |
daniel@transgaming.com | 62a2846 | 2012-07-24 18:33:59 +0000 | [diff] [blame] | 1197 | ProgramBinary *Context::getCurrentProgramBinary() |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1198 | { |
daniel@transgaming.com | 989c1c8 | 2012-07-24 18:40:38 +0000 | [diff] [blame] | 1199 | return mCurrentProgramBinary.get(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | Texture2D *Context::getTexture2D() |
| 1203 | { |
| 1204 | return static_cast<Texture2D*>(getSamplerTexture(mState.activeSampler, TEXTURE_2D)); |
| 1205 | } |
| 1206 | |
| 1207 | TextureCubeMap *Context::getTextureCubeMap() |
| 1208 | { |
| 1209 | return static_cast<TextureCubeMap*>(getSamplerTexture(mState.activeSampler, TEXTURE_CUBE)); |
| 1210 | } |
| 1211 | |
| 1212 | Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) |
| 1213 | { |
| 1214 | GLuint texid = mState.samplerTexture[type][sampler].id(); |
| 1215 | |
| 1216 | if (texid == 0) // Special case: 0 refers to different initial textures based on the target |
| 1217 | { |
| 1218 | switch (type) |
| 1219 | { |
| 1220 | default: UNREACHABLE(); |
| 1221 | case TEXTURE_2D: return mTexture2DZero.get(); |
| 1222 | case TEXTURE_CUBE: return mTextureCubeMapZero.get(); |
| 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | return mState.samplerTexture[type][sampler].get(); |
| 1227 | } |
| 1228 | |
| 1229 | bool Context::getBooleanv(GLenum pname, GLboolean *params) |
| 1230 | { |
| 1231 | switch (pname) |
| 1232 | { |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 1233 | case GL_SHADER_COMPILER: *params = GL_TRUE; break; |
| 1234 | case GL_SAMPLE_COVERAGE_INVERT: *params = mState.sampleCoverageInvert; break; |
| 1235 | case GL_DEPTH_WRITEMASK: *params = mState.depthStencil.depthMask; break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1236 | case GL_COLOR_WRITEMASK: |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 1237 | params[0] = mState.blend.colorMaskRed; |
| 1238 | params[1] = mState.blend.colorMaskGreen; |
| 1239 | params[2] = mState.blend.colorMaskBlue; |
| 1240 | params[3] = mState.blend.colorMaskAlpha; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1241 | break; |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 1242 | case GL_CULL_FACE: *params = mState.rasterizer.cullFace; break; |
| 1243 | case GL_POLYGON_OFFSET_FILL: *params = mState.rasterizer.polygonOffsetFill; break; |
| 1244 | case GL_SAMPLE_ALPHA_TO_COVERAGE: *params = mState.blend.sampleAlphaToCoverage; break; |
| 1245 | case GL_SAMPLE_COVERAGE: *params = mState.sampleCoverage; break; |
| 1246 | case GL_SCISSOR_TEST: *params = mState.rasterizer.scissorTest; break; |
| 1247 | case GL_STENCIL_TEST: *params = mState.depthStencil.stencilTest; break; |
| 1248 | case GL_DEPTH_TEST: *params = mState.depthStencil.depthTest; break; |
| 1249 | case GL_BLEND: *params = mState.blend.blend; break; |
| 1250 | case GL_DITHER: *params = mState.blend.dither; break; |
| 1251 | case GL_CONTEXT_ROBUST_ACCESS_EXT: *params = mRobustAccess ? GL_TRUE : GL_FALSE; break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1252 | default: |
| 1253 | return false; |
| 1254 | } |
| 1255 | |
| 1256 | return true; |
| 1257 | } |
| 1258 | |
| 1259 | bool Context::getFloatv(GLenum pname, GLfloat *params) |
| 1260 | { |
| 1261 | // Please note: DEPTH_CLEAR_VALUE is included in our internal getFloatv implementation |
| 1262 | // because it is stored as a float, despite the fact that the GL ES 2.0 spec names |
| 1263 | // GetIntegerv as its native query function. As it would require conversion in any |
| 1264 | // case, this should make no difference to the calling application. |
| 1265 | switch (pname) |
| 1266 | { |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 1267 | case GL_LINE_WIDTH: *params = mState.lineWidth; break; |
| 1268 | case GL_SAMPLE_COVERAGE_VALUE: *params = mState.sampleCoverageValue; break; |
| 1269 | case GL_DEPTH_CLEAR_VALUE: *params = mState.depthClearValue; break; |
| 1270 | case GL_POLYGON_OFFSET_FACTOR: *params = mState.rasterizer.polygonOffsetFactor; break; |
| 1271 | case GL_POLYGON_OFFSET_UNITS: *params = mState.rasterizer.polygonOffsetUnits; break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1272 | case GL_ALIASED_LINE_WIDTH_RANGE: |
| 1273 | params[0] = gl::ALIASED_LINE_WIDTH_RANGE_MIN; |
| 1274 | params[1] = gl::ALIASED_LINE_WIDTH_RANGE_MAX; |
| 1275 | break; |
| 1276 | case GL_ALIASED_POINT_SIZE_RANGE: |
| 1277 | params[0] = gl::ALIASED_POINT_SIZE_RANGE_MIN; |
| 1278 | params[1] = getMaximumPointSize(); |
| 1279 | break; |
| 1280 | case GL_DEPTH_RANGE: |
| 1281 | params[0] = mState.zNear; |
| 1282 | params[1] = mState.zFar; |
| 1283 | break; |
| 1284 | case GL_COLOR_CLEAR_VALUE: |
| 1285 | params[0] = mState.colorClearValue.red; |
| 1286 | params[1] = mState.colorClearValue.green; |
| 1287 | params[2] = mState.colorClearValue.blue; |
| 1288 | params[3] = mState.colorClearValue.alpha; |
| 1289 | break; |
| 1290 | case GL_BLEND_COLOR: |
| 1291 | params[0] = mState.blendColor.red; |
| 1292 | params[1] = mState.blendColor.green; |
| 1293 | params[2] = mState.blendColor.blue; |
| 1294 | params[3] = mState.blendColor.alpha; |
| 1295 | break; |
daniel@transgaming.com | 07ab841 | 2012-07-12 15:17:09 +0000 | [diff] [blame] | 1296 | case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: |
| 1297 | if (!supportsTextureFilterAnisotropy()) |
| 1298 | { |
| 1299 | return false; |
| 1300 | } |
| 1301 | *params = mMaxTextureAnisotropy; |
| 1302 | break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1303 | default: |
| 1304 | return false; |
| 1305 | } |
| 1306 | |
| 1307 | return true; |
| 1308 | } |
| 1309 | |
| 1310 | bool Context::getIntegerv(GLenum pname, GLint *params) |
| 1311 | { |
| 1312 | // Please note: DEPTH_CLEAR_VALUE is not included in our internal getIntegerv implementation |
| 1313 | // because it is stored as a float, despite the fact that the GL ES 2.0 spec names |
| 1314 | // GetIntegerv as its native query function. As it would require conversion in any |
| 1315 | // case, this should make no difference to the calling application. You may find it in |
| 1316 | // Context::getFloatv. |
| 1317 | switch (pname) |
| 1318 | { |
| 1319 | case GL_MAX_VERTEX_ATTRIBS: *params = gl::MAX_VERTEX_ATTRIBS; break; |
| 1320 | case GL_MAX_VERTEX_UNIFORM_VECTORS: *params = gl::MAX_VERTEX_UNIFORM_VECTORS; break; |
| 1321 | case GL_MAX_VARYING_VECTORS: *params = getMaximumVaryingVectors(); break; |
| 1322 | case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: *params = getMaximumCombinedTextureImageUnits(); break; |
| 1323 | case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: *params = getMaximumVertexTextureImageUnits(); break; |
| 1324 | case GL_MAX_TEXTURE_IMAGE_UNITS: *params = gl::MAX_TEXTURE_IMAGE_UNITS; break; |
| 1325 | case GL_MAX_FRAGMENT_UNIFORM_VECTORS: *params = getMaximumFragmentUniformVectors(); break; |
| 1326 | case GL_MAX_RENDERBUFFER_SIZE: *params = getMaximumRenderbufferDimension(); break; |
| 1327 | case GL_NUM_SHADER_BINARY_FORMATS: *params = 0; break; |
| 1328 | case GL_SHADER_BINARY_FORMATS: /* no shader binary formats are supported */ break; |
| 1329 | case GL_ARRAY_BUFFER_BINDING: *params = mState.arrayBuffer.id(); break; |
| 1330 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: *params = mState.elementArrayBuffer.id(); break; |
| 1331 | //case GL_FRAMEBUFFER_BINDING: // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE |
| 1332 | case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE: *params = mState.drawFramebuffer; break; |
| 1333 | case GL_READ_FRAMEBUFFER_BINDING_ANGLE: *params = mState.readFramebuffer; break; |
| 1334 | case GL_RENDERBUFFER_BINDING: *params = mState.renderbuffer.id(); break; |
| 1335 | case GL_CURRENT_PROGRAM: *params = mState.currentProgram; break; |
| 1336 | case GL_PACK_ALIGNMENT: *params = mState.packAlignment; break; |
| 1337 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: *params = mState.packReverseRowOrder; break; |
| 1338 | case GL_UNPACK_ALIGNMENT: *params = mState.unpackAlignment; break; |
| 1339 | case GL_GENERATE_MIPMAP_HINT: *params = mState.generateMipmapHint; break; |
| 1340 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: *params = mState.fragmentShaderDerivativeHint; break; |
| 1341 | case GL_ACTIVE_TEXTURE: *params = (mState.activeSampler + GL_TEXTURE0); break; |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 1342 | case GL_STENCIL_FUNC: *params = mState.depthStencil.stencilFunc; break; |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 1343 | case GL_STENCIL_REF: *params = mState.stencilRef; break; |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 1344 | case GL_STENCIL_VALUE_MASK: *params = mState.depthStencil.stencilMask; break; |
| 1345 | case GL_STENCIL_BACK_FUNC: *params = mState.depthStencil.stencilBackFunc; break; |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 1346 | case GL_STENCIL_BACK_REF: *params = mState.stencilBackRef; break; |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 1347 | case GL_STENCIL_BACK_VALUE_MASK: *params = mState.depthStencil.stencilBackMask; break; |
| 1348 | case GL_STENCIL_FAIL: *params = mState.depthStencil.stencilFail; break; |
| 1349 | case GL_STENCIL_PASS_DEPTH_FAIL: *params = mState.depthStencil.stencilPassDepthFail; break; |
| 1350 | case GL_STENCIL_PASS_DEPTH_PASS: *params = mState.depthStencil.stencilPassDepthPass; break; |
| 1351 | case GL_STENCIL_BACK_FAIL: *params = mState.depthStencil.stencilBackFail; break; |
| 1352 | case GL_STENCIL_BACK_PASS_DEPTH_FAIL: *params = mState.depthStencil.stencilBackPassDepthFail; break; |
| 1353 | case GL_STENCIL_BACK_PASS_DEPTH_PASS: *params = mState.depthStencil.stencilBackPassDepthPass; break; |
| 1354 | case GL_DEPTH_FUNC: *params = mState.depthStencil.depthFunc; break; |
| 1355 | case GL_BLEND_SRC_RGB: *params = mState.blend.sourceBlendRGB; break; |
| 1356 | case GL_BLEND_SRC_ALPHA: *params = mState.blend.sourceBlendAlpha; break; |
| 1357 | case GL_BLEND_DST_RGB: *params = mState.blend.destBlendRGB; break; |
| 1358 | case GL_BLEND_DST_ALPHA: *params = mState.blend.destBlendAlpha; break; |
| 1359 | case GL_BLEND_EQUATION_RGB: *params = mState.blend.blendEquationRGB; break; |
| 1360 | case GL_BLEND_EQUATION_ALPHA: *params = mState.blend.blendEquationAlpha; break; |
| 1361 | case GL_STENCIL_WRITEMASK: *params = mState.depthStencil.stencilWritemask; break; |
| 1362 | case GL_STENCIL_BACK_WRITEMASK: *params = mState.depthStencil.stencilBackWritemask; break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1363 | case GL_STENCIL_CLEAR_VALUE: *params = mState.stencilClearValue; break; |
| 1364 | case GL_SUBPIXEL_BITS: *params = 4; break; |
| 1365 | case GL_MAX_TEXTURE_SIZE: *params = getMaximumTextureDimension(); break; |
| 1366 | case GL_MAX_CUBE_MAP_TEXTURE_SIZE: *params = getMaximumCubeTextureDimension(); break; |
| 1367 | case GL_NUM_COMPRESSED_TEXTURE_FORMATS: |
| 1368 | params[0] = mNumCompressedTextureFormats; |
| 1369 | break; |
| 1370 | case GL_MAX_SAMPLES_ANGLE: |
| 1371 | { |
| 1372 | GLsizei maxSamples = getMaxSupportedSamples(); |
| 1373 | if (maxSamples != 0) |
| 1374 | { |
| 1375 | *params = maxSamples; |
| 1376 | } |
| 1377 | else |
| 1378 | { |
| 1379 | return false; |
| 1380 | } |
| 1381 | |
| 1382 | break; |
| 1383 | } |
| 1384 | case GL_SAMPLE_BUFFERS: |
| 1385 | case GL_SAMPLES: |
| 1386 | { |
| 1387 | gl::Framebuffer *framebuffer = getDrawFramebuffer(); |
| 1388 | if (framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE) |
| 1389 | { |
| 1390 | switch (pname) |
| 1391 | { |
| 1392 | case GL_SAMPLE_BUFFERS: |
| 1393 | if (framebuffer->getSamples() != 0) |
| 1394 | { |
| 1395 | *params = 1; |
| 1396 | } |
| 1397 | else |
| 1398 | { |
| 1399 | *params = 0; |
| 1400 | } |
| 1401 | break; |
| 1402 | case GL_SAMPLES: |
| 1403 | *params = framebuffer->getSamples(); |
| 1404 | break; |
| 1405 | } |
| 1406 | } |
| 1407 | else |
| 1408 | { |
| 1409 | *params = 0; |
| 1410 | } |
| 1411 | } |
| 1412 | break; |
daniel@transgaming.com | 42944b0 | 2012-09-27 17:45:57 +0000 | [diff] [blame] | 1413 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 1414 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 1415 | { |
| 1416 | GLenum format, type; |
| 1417 | if (getCurrentReadFormatType(&format, &type)) |
| 1418 | { |
| 1419 | if (pname == GL_IMPLEMENTATION_COLOR_READ_FORMAT) |
| 1420 | *params = format; |
| 1421 | else |
| 1422 | *params = type; |
| 1423 | } |
| 1424 | } |
| 1425 | break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1426 | case GL_MAX_VIEWPORT_DIMS: |
| 1427 | { |
| 1428 | int maxDimension = std::max(getMaximumRenderbufferDimension(), getMaximumTextureDimension()); |
| 1429 | params[0] = maxDimension; |
| 1430 | params[1] = maxDimension; |
| 1431 | } |
| 1432 | break; |
| 1433 | case GL_COMPRESSED_TEXTURE_FORMATS: |
| 1434 | { |
| 1435 | if (supportsDXT1Textures()) |
| 1436 | { |
| 1437 | *params++ = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; |
| 1438 | *params++ = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; |
| 1439 | } |
| 1440 | if (supportsDXT3Textures()) |
| 1441 | { |
| 1442 | *params++ = GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE; |
| 1443 | } |
| 1444 | if (supportsDXT5Textures()) |
| 1445 | { |
| 1446 | *params++ = GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE; |
| 1447 | } |
| 1448 | } |
| 1449 | break; |
| 1450 | case GL_VIEWPORT: |
daniel@transgaming.com | 3884e2c | 2012-11-28 19:41:00 +0000 | [diff] [blame] | 1451 | params[0] = mState.viewport.x; |
| 1452 | params[1] = mState.viewport.y; |
| 1453 | params[2] = mState.viewport.width; |
| 1454 | params[3] = mState.viewport.height; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1455 | break; |
| 1456 | case GL_SCISSOR_BOX: |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 1457 | params[0] = mState.scissor.x; |
| 1458 | params[1] = mState.scissor.y; |
| 1459 | params[2] = mState.scissor.width; |
| 1460 | params[3] = mState.scissor.height; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1461 | break; |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 1462 | case GL_CULL_FACE_MODE: *params = mState.rasterizer.cullMode; break; |
| 1463 | case GL_FRONT_FACE: *params = mState.rasterizer.frontFace; break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1464 | case GL_RED_BITS: |
| 1465 | case GL_GREEN_BITS: |
| 1466 | case GL_BLUE_BITS: |
| 1467 | case GL_ALPHA_BITS: |
| 1468 | { |
| 1469 | gl::Framebuffer *framebuffer = getDrawFramebuffer(); |
| 1470 | gl::Renderbuffer *colorbuffer = framebuffer->getColorbuffer(); |
| 1471 | |
| 1472 | if (colorbuffer) |
| 1473 | { |
| 1474 | switch (pname) |
| 1475 | { |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 1476 | case GL_RED_BITS: *params = colorbuffer->getRedSize(); break; |
| 1477 | case GL_GREEN_BITS: *params = colorbuffer->getGreenSize(); break; |
| 1478 | case GL_BLUE_BITS: *params = colorbuffer->getBlueSize(); break; |
| 1479 | case GL_ALPHA_BITS: *params = colorbuffer->getAlphaSize(); break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1480 | } |
| 1481 | } |
| 1482 | else |
| 1483 | { |
| 1484 | *params = 0; |
| 1485 | } |
| 1486 | } |
| 1487 | break; |
| 1488 | case GL_DEPTH_BITS: |
| 1489 | { |
| 1490 | gl::Framebuffer *framebuffer = getDrawFramebuffer(); |
| 1491 | gl::Renderbuffer *depthbuffer = framebuffer->getDepthbuffer(); |
| 1492 | |
| 1493 | if (depthbuffer) |
| 1494 | { |
| 1495 | *params = depthbuffer->getDepthSize(); |
| 1496 | } |
| 1497 | else |
| 1498 | { |
| 1499 | *params = 0; |
| 1500 | } |
| 1501 | } |
| 1502 | break; |
| 1503 | case GL_STENCIL_BITS: |
| 1504 | { |
| 1505 | gl::Framebuffer *framebuffer = getDrawFramebuffer(); |
| 1506 | gl::Renderbuffer *stencilbuffer = framebuffer->getStencilbuffer(); |
| 1507 | |
| 1508 | if (stencilbuffer) |
| 1509 | { |
| 1510 | *params = stencilbuffer->getStencilSize(); |
| 1511 | } |
| 1512 | else |
| 1513 | { |
| 1514 | *params = 0; |
| 1515 | } |
| 1516 | } |
| 1517 | break; |
| 1518 | case GL_TEXTURE_BINDING_2D: |
| 1519 | { |
| 1520 | if (mState.activeSampler < 0 || mState.activeSampler > getMaximumCombinedTextureImageUnits() - 1) |
| 1521 | { |
| 1522 | error(GL_INVALID_OPERATION); |
| 1523 | return false; |
| 1524 | } |
| 1525 | |
| 1526 | *params = mState.samplerTexture[TEXTURE_2D][mState.activeSampler].id(); |
| 1527 | } |
| 1528 | break; |
| 1529 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 1530 | { |
| 1531 | if (mState.activeSampler < 0 || mState.activeSampler > getMaximumCombinedTextureImageUnits() - 1) |
| 1532 | { |
| 1533 | error(GL_INVALID_OPERATION); |
| 1534 | return false; |
| 1535 | } |
| 1536 | |
| 1537 | *params = mState.samplerTexture[TEXTURE_CUBE][mState.activeSampler].id(); |
| 1538 | } |
| 1539 | break; |
| 1540 | case GL_RESET_NOTIFICATION_STRATEGY_EXT: |
| 1541 | *params = mResetStrategy; |
| 1542 | break; |
| 1543 | case GL_NUM_PROGRAM_BINARY_FORMATS_OES: |
| 1544 | *params = 1; |
| 1545 | break; |
| 1546 | case GL_PROGRAM_BINARY_FORMATS_OES: |
| 1547 | *params = GL_PROGRAM_BINARY_ANGLE; |
| 1548 | break; |
| 1549 | default: |
| 1550 | return false; |
| 1551 | } |
| 1552 | |
| 1553 | return true; |
| 1554 | } |
| 1555 | |
| 1556 | bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams) |
| 1557 | { |
| 1558 | // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation |
| 1559 | // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due |
| 1560 | // to the fact that it is stored internally as a float, and so would require conversion |
| 1561 | // if returned from Context::getIntegerv. Since this conversion is already implemented |
| 1562 | // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we |
| 1563 | // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling |
| 1564 | // application. |
| 1565 | switch (pname) |
| 1566 | { |
| 1567 | case GL_COMPRESSED_TEXTURE_FORMATS: |
| 1568 | { |
| 1569 | *type = GL_INT; |
| 1570 | *numParams = mNumCompressedTextureFormats; |
| 1571 | } |
| 1572 | break; |
| 1573 | case GL_SHADER_BINARY_FORMATS: |
| 1574 | { |
| 1575 | *type = GL_INT; |
| 1576 | *numParams = 0; |
| 1577 | } |
| 1578 | break; |
| 1579 | case GL_MAX_VERTEX_ATTRIBS: |
| 1580 | case GL_MAX_VERTEX_UNIFORM_VECTORS: |
| 1581 | case GL_MAX_VARYING_VECTORS: |
| 1582 | case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: |
| 1583 | case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: |
| 1584 | case GL_MAX_TEXTURE_IMAGE_UNITS: |
| 1585 | case GL_MAX_FRAGMENT_UNIFORM_VECTORS: |
| 1586 | case GL_MAX_RENDERBUFFER_SIZE: |
| 1587 | case GL_NUM_SHADER_BINARY_FORMATS: |
| 1588 | case GL_NUM_COMPRESSED_TEXTURE_FORMATS: |
| 1589 | case GL_ARRAY_BUFFER_BINDING: |
| 1590 | case GL_FRAMEBUFFER_BINDING: |
| 1591 | case GL_RENDERBUFFER_BINDING: |
| 1592 | case GL_CURRENT_PROGRAM: |
| 1593 | case GL_PACK_ALIGNMENT: |
| 1594 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
| 1595 | case GL_UNPACK_ALIGNMENT: |
| 1596 | case GL_GENERATE_MIPMAP_HINT: |
| 1597 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: |
| 1598 | case GL_RED_BITS: |
| 1599 | case GL_GREEN_BITS: |
| 1600 | case GL_BLUE_BITS: |
| 1601 | case GL_ALPHA_BITS: |
| 1602 | case GL_DEPTH_BITS: |
| 1603 | case GL_STENCIL_BITS: |
| 1604 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: |
| 1605 | case GL_CULL_FACE_MODE: |
| 1606 | case GL_FRONT_FACE: |
| 1607 | case GL_ACTIVE_TEXTURE: |
| 1608 | case GL_STENCIL_FUNC: |
| 1609 | case GL_STENCIL_VALUE_MASK: |
| 1610 | case GL_STENCIL_REF: |
| 1611 | case GL_STENCIL_FAIL: |
| 1612 | case GL_STENCIL_PASS_DEPTH_FAIL: |
| 1613 | case GL_STENCIL_PASS_DEPTH_PASS: |
| 1614 | case GL_STENCIL_BACK_FUNC: |
| 1615 | case GL_STENCIL_BACK_VALUE_MASK: |
| 1616 | case GL_STENCIL_BACK_REF: |
| 1617 | case GL_STENCIL_BACK_FAIL: |
| 1618 | case GL_STENCIL_BACK_PASS_DEPTH_FAIL: |
| 1619 | case GL_STENCIL_BACK_PASS_DEPTH_PASS: |
| 1620 | case GL_DEPTH_FUNC: |
| 1621 | case GL_BLEND_SRC_RGB: |
| 1622 | case GL_BLEND_SRC_ALPHA: |
| 1623 | case GL_BLEND_DST_RGB: |
| 1624 | case GL_BLEND_DST_ALPHA: |
| 1625 | case GL_BLEND_EQUATION_RGB: |
| 1626 | case GL_BLEND_EQUATION_ALPHA: |
| 1627 | case GL_STENCIL_WRITEMASK: |
| 1628 | case GL_STENCIL_BACK_WRITEMASK: |
| 1629 | case GL_STENCIL_CLEAR_VALUE: |
| 1630 | case GL_SUBPIXEL_BITS: |
| 1631 | case GL_MAX_TEXTURE_SIZE: |
| 1632 | case GL_MAX_CUBE_MAP_TEXTURE_SIZE: |
| 1633 | case GL_SAMPLE_BUFFERS: |
| 1634 | case GL_SAMPLES: |
| 1635 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 1636 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 1637 | case GL_TEXTURE_BINDING_2D: |
| 1638 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 1639 | case GL_RESET_NOTIFICATION_STRATEGY_EXT: |
| 1640 | case GL_NUM_PROGRAM_BINARY_FORMATS_OES: |
| 1641 | case GL_PROGRAM_BINARY_FORMATS_OES: |
| 1642 | { |
| 1643 | *type = GL_INT; |
| 1644 | *numParams = 1; |
| 1645 | } |
| 1646 | break; |
| 1647 | case GL_MAX_SAMPLES_ANGLE: |
| 1648 | { |
| 1649 | if (getMaxSupportedSamples() != 0) |
| 1650 | { |
| 1651 | *type = GL_INT; |
| 1652 | *numParams = 1; |
| 1653 | } |
| 1654 | else |
| 1655 | { |
| 1656 | return false; |
| 1657 | } |
| 1658 | } |
| 1659 | break; |
| 1660 | case GL_MAX_VIEWPORT_DIMS: |
| 1661 | { |
| 1662 | *type = GL_INT; |
| 1663 | *numParams = 2; |
| 1664 | } |
| 1665 | break; |
| 1666 | case GL_VIEWPORT: |
| 1667 | case GL_SCISSOR_BOX: |
| 1668 | { |
| 1669 | *type = GL_INT; |
| 1670 | *numParams = 4; |
| 1671 | } |
| 1672 | break; |
| 1673 | case GL_SHADER_COMPILER: |
| 1674 | case GL_SAMPLE_COVERAGE_INVERT: |
| 1675 | case GL_DEPTH_WRITEMASK: |
| 1676 | case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled, |
| 1677 | case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries. |
| 1678 | case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as bool-natural |
| 1679 | case GL_SAMPLE_COVERAGE: |
| 1680 | case GL_SCISSOR_TEST: |
| 1681 | case GL_STENCIL_TEST: |
| 1682 | case GL_DEPTH_TEST: |
| 1683 | case GL_BLEND: |
| 1684 | case GL_DITHER: |
| 1685 | case GL_CONTEXT_ROBUST_ACCESS_EXT: |
| 1686 | { |
| 1687 | *type = GL_BOOL; |
| 1688 | *numParams = 1; |
| 1689 | } |
| 1690 | break; |
| 1691 | case GL_COLOR_WRITEMASK: |
| 1692 | { |
| 1693 | *type = GL_BOOL; |
| 1694 | *numParams = 4; |
| 1695 | } |
| 1696 | break; |
| 1697 | case GL_POLYGON_OFFSET_FACTOR: |
| 1698 | case GL_POLYGON_OFFSET_UNITS: |
| 1699 | case GL_SAMPLE_COVERAGE_VALUE: |
| 1700 | case GL_DEPTH_CLEAR_VALUE: |
| 1701 | case GL_LINE_WIDTH: |
| 1702 | { |
| 1703 | *type = GL_FLOAT; |
| 1704 | *numParams = 1; |
| 1705 | } |
| 1706 | break; |
| 1707 | case GL_ALIASED_LINE_WIDTH_RANGE: |
| 1708 | case GL_ALIASED_POINT_SIZE_RANGE: |
| 1709 | case GL_DEPTH_RANGE: |
| 1710 | { |
| 1711 | *type = GL_FLOAT; |
| 1712 | *numParams = 2; |
| 1713 | } |
| 1714 | break; |
| 1715 | case GL_COLOR_CLEAR_VALUE: |
| 1716 | case GL_BLEND_COLOR: |
| 1717 | { |
| 1718 | *type = GL_FLOAT; |
| 1719 | *numParams = 4; |
| 1720 | } |
| 1721 | break; |
daniel@transgaming.com | 07ab841 | 2012-07-12 15:17:09 +0000 | [diff] [blame] | 1722 | case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: |
| 1723 | if (!supportsTextureFilterAnisotropy()) |
| 1724 | { |
| 1725 | return false; |
| 1726 | } |
| 1727 | *type = GL_FLOAT; |
| 1728 | *numParams = 1; |
| 1729 | break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1730 | default: |
| 1731 | return false; |
| 1732 | } |
| 1733 | |
| 1734 | return true; |
| 1735 | } |
| 1736 | |
| 1737 | // Applies the render target surface, depth stencil surface, viewport rectangle and |
| 1738 | // scissor rectangle to the Direct3D 9 device |
| 1739 | bool Context::applyRenderTarget(bool ignoreViewport) |
| 1740 | { |
| 1741 | Framebuffer *framebufferObject = getDrawFramebuffer(); |
| 1742 | |
| 1743 | if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 1744 | { |
| 1745 | return error(GL_INVALID_FRAMEBUFFER_OPERATION, false); |
| 1746 | } |
| 1747 | |
daniel@transgaming.com | 8a8b24c | 2012-11-28 19:36:26 +0000 | [diff] [blame] | 1748 | mRenderer->applyRenderTarget(framebufferObject); |
| 1749 | |
daniel@transgaming.com | e06bda9 | 2012-11-28 19:42:18 +0000 | [diff] [blame] | 1750 | // storing the mRenderTargetDesc in Context will be removed once refactoring |
| 1751 | // of clear is complete |
| 1752 | // D3D9_REPLACE start |
| 1753 | gl::Renderbuffer *renderbufferObject = NULL; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1754 | if (framebufferObject->getColorbufferType() != GL_NONE) |
| 1755 | { |
| 1756 | renderbufferObject = framebufferObject->getColorbuffer(); |
| 1757 | } |
| 1758 | else |
| 1759 | { |
| 1760 | renderbufferObject = framebufferObject->getNullColorbuffer(); |
| 1761 | } |
| 1762 | if (!renderbufferObject) |
| 1763 | { |
| 1764 | ERR("unable to locate renderbuffer for FBO."); |
| 1765 | return false; |
| 1766 | } |
| 1767 | |
daniel@transgaming.com | e06bda9 | 2012-11-28 19:42:18 +0000 | [diff] [blame] | 1768 | mRenderTargetDesc.width = renderbufferObject->getWidth(); |
| 1769 | mRenderTargetDesc.height = renderbufferObject->getHeight(); |
| 1770 | mRenderTargetDesc.format = renderbufferObject->getActualFormat(); |
| 1771 | // D3D9_REPLACE end |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1772 | |
daniel@transgaming.com | 3ca082c | 2012-11-28 19:41:07 +0000 | [diff] [blame] | 1773 | Rectangle viewport = mState.viewport; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1774 | float zNear = clamp01(mState.zNear); |
| 1775 | float zFar = clamp01(mState.zFar); |
| 1776 | |
| 1777 | if (ignoreViewport) |
| 1778 | { |
daniel@transgaming.com | 3ca082c | 2012-11-28 19:41:07 +0000 | [diff] [blame] | 1779 | viewport.x = 0; |
| 1780 | viewport.y = 0; |
| 1781 | viewport.width = mRenderTargetDesc.width; |
| 1782 | viewport.height = mRenderTargetDesc.height; |
| 1783 | zNear = 0.0f; |
| 1784 | zFar = 1.0f; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1785 | } |
| 1786 | |
daniel@transgaming.com | 3ca082c | 2012-11-28 19:41:07 +0000 | [diff] [blame] | 1787 | ProgramBinary *programBinary = mState.currentProgram ? getCurrentProgramBinary() : NULL; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1788 | |
daniel@transgaming.com | 3ca082c | 2012-11-28 19:41:07 +0000 | [diff] [blame] | 1789 | if (!mRenderer->setViewport(viewport, zNear, zFar, mRenderTargetDesc.width, mRenderTargetDesc.height, |
| 1790 | programBinary, mDxUniformsDirty)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1791 | { |
daniel@transgaming.com | 3ca082c | 2012-11-28 19:41:07 +0000 | [diff] [blame] | 1792 | return false; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1793 | } |
daniel@transgaming.com | 3ca082c | 2012-11-28 19:41:07 +0000 | [diff] [blame] | 1794 | mDxUniformsDirty = false; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1795 | |
daniel@transgaming.com | 39cee2e | 2012-11-28 19:39:14 +0000 | [diff] [blame] | 1796 | mRenderer->setScissorRectangle(mState.scissor, static_cast<int>(mRenderTargetDesc.width), |
| 1797 | static_cast<int>(mRenderTargetDesc.height)); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1798 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1799 | return true; |
| 1800 | } |
| 1801 | |
| 1802 | // Applies the fixed-function state (culling, depth test, alpha blending, stenciling, etc) to the Direct3D 9 device |
| 1803 | void Context::applyState(GLenum drawMode) |
| 1804 | { |
daniel@transgaming.com | 62a2846 | 2012-07-24 18:33:59 +0000 | [diff] [blame] | 1805 | ProgramBinary *programBinary = getCurrentProgramBinary(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1806 | |
| 1807 | Framebuffer *framebufferObject = getDrawFramebuffer(); |
| 1808 | |
| 1809 | GLint frontCCW = programBinary->getDxFrontCCWLocation(); |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 1810 | GLint ccw = (mState.rasterizer.frontFace == GL_CCW); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1811 | programBinary->setUniform1iv(frontCCW, 1, &ccw); |
| 1812 | |
| 1813 | GLint pointsOrLines = programBinary->getDxPointsOrLinesLocation(); |
| 1814 | GLint alwaysFront = !isTriangleMode(drawMode); |
| 1815 | programBinary->setUniform1iv(pointsOrLines, 1, &alwaysFront); |
| 1816 | |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 1817 | const gl::Renderbuffer *depthbuffer = framebufferObject->getDepthbuffer(); |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1818 | unsigned int depthSize = depthbuffer ? depthbuffer->getDepthSize() : 0; |
| 1819 | |
| 1820 | mRenderer->setRasterizerState(mState.rasterizer, depthSize); |
| 1821 | |
| 1822 | unsigned int mask = 0; |
| 1823 | if (mState.sampleCoverage) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1824 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1825 | if (mState.sampleCoverageValue != 0) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1826 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1827 | float threshold = 0.5f; |
| 1828 | |
| 1829 | for (int i = 0; i < framebufferObject->getSamples(); ++i) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1830 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1831 | mask <<= 1; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1832 | |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1833 | if ((i + 1) * mState.sampleCoverageValue >= threshold) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1834 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1835 | threshold += 1.0f; |
| 1836 | mask |= 1; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1837 | } |
| 1838 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1839 | } |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1840 | |
| 1841 | if (mState.sampleCoverageInvert) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1842 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1843 | mask = ~mask; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1844 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1845 | } |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1846 | else |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1847 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1848 | mask = 0xFFFFFFFF; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1849 | } |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1850 | mRenderer->setBlendState(mState.blend, mState.blendColor, mask); |
| 1851 | |
| 1852 | unsigned int stencilSize = framebufferObject->hasStencil() ? framebufferObject->getStencilbuffer()->getStencilSize() : 0; |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 1853 | mRenderer->setDepthStencilState(mState.depthStencil, mState.stencilRef, mState.stencilBackRef, |
| 1854 | mState.rasterizer.frontFace == GL_CCW, stencilSize); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | GLenum Context::applyVertexBuffer(GLint first, GLsizei count, GLsizei instances, GLsizei *repeatDraw) |
| 1858 | { |
| 1859 | TranslatedAttribute attributes[MAX_VERTEX_ATTRIBS]; |
| 1860 | |
daniel@transgaming.com | 408caa5 | 2012-10-31 18:47:01 +0000 | [diff] [blame] | 1861 | ProgramBinary *programBinary = getCurrentProgramBinary(); |
| 1862 | GLenum err = mVertexDataManager->prepareVertexData(mState.vertexAttribute, programBinary, first, count, attributes, instances); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1863 | if (err != GL_NO_ERROR) |
| 1864 | { |
| 1865 | return err; |
| 1866 | } |
daniel@transgaming.com | 408caa5 | 2012-10-31 18:47:01 +0000 | [diff] [blame] | 1867 | |
daniel@transgaming.com | 5ae3ccc | 2012-07-24 18:29:38 +0000 | [diff] [blame] | 1868 | return mVertexDeclarationCache.applyDeclaration(mDevice, attributes, programBinary, instances, repeatDraw); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1869 | } |
| 1870 | |
| 1871 | // Applies the indices and element array bindings to the Direct3D 9 device |
| 1872 | GLenum Context::applyIndexBuffer(const GLvoid *indices, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) |
| 1873 | { |
| 1874 | GLenum err = mIndexDataManager->prepareIndexData(type, count, mState.elementArrayBuffer.get(), indices, indexInfo); |
| 1875 | |
| 1876 | if (err == GL_NO_ERROR) |
| 1877 | { |
| 1878 | if (indexInfo->serial != mAppliedIBSerial) |
| 1879 | { |
| 1880 | mDevice->SetIndices(indexInfo->indexBuffer); |
| 1881 | mAppliedIBSerial = indexInfo->serial; |
| 1882 | } |
| 1883 | } |
| 1884 | |
| 1885 | return err; |
| 1886 | } |
| 1887 | |
| 1888 | // Applies the shaders and shader constants to the Direct3D 9 device |
| 1889 | void Context::applyShaders() |
| 1890 | { |
daniel@transgaming.com | 62a2846 | 2012-07-24 18:33:59 +0000 | [diff] [blame] | 1891 | ProgramBinary *programBinary = getCurrentProgramBinary(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1892 | |
daniel@transgaming.com | e6af4f9 | 2012-07-24 18:31:31 +0000 | [diff] [blame] | 1893 | if (programBinary->getSerial() != mAppliedProgramBinarySerial) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1894 | { |
| 1895 | IDirect3DVertexShader9 *vertexShader = programBinary->getVertexShader(); |
| 1896 | IDirect3DPixelShader9 *pixelShader = programBinary->getPixelShader(); |
| 1897 | |
| 1898 | mDevice->SetPixelShader(pixelShader); |
| 1899 | mDevice->SetVertexShader(vertexShader); |
| 1900 | programBinary->dirtyAllUniforms(); |
daniel@transgaming.com | e6af4f9 | 2012-07-24 18:31:31 +0000 | [diff] [blame] | 1901 | mAppliedProgramBinarySerial = programBinary->getSerial(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1902 | } |
| 1903 | |
| 1904 | programBinary->applyUniforms(); |
| 1905 | } |
| 1906 | |
| 1907 | // Applies the textures and sampler states to the Direct3D 9 device |
| 1908 | void Context::applyTextures() |
| 1909 | { |
| 1910 | applyTextures(SAMPLER_PIXEL); |
| 1911 | |
| 1912 | if (mSupportsVertexTexture) |
| 1913 | { |
| 1914 | applyTextures(SAMPLER_VERTEX); |
| 1915 | } |
| 1916 | } |
| 1917 | |
| 1918 | // For each Direct3D 9 sampler of either the pixel or vertex stage, |
| 1919 | // looks up the corresponding OpenGL texture image unit and texture type, |
| 1920 | // and sets the texture and its addressing/filtering state (or NULL when inactive). |
| 1921 | void Context::applyTextures(SamplerType type) |
| 1922 | { |
daniel@transgaming.com | 62a2846 | 2012-07-24 18:33:59 +0000 | [diff] [blame] | 1923 | ProgramBinary *programBinary = getCurrentProgramBinary(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1924 | |
| 1925 | int samplerCount = (type == SAMPLER_PIXEL) ? MAX_TEXTURE_IMAGE_UNITS : MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; // Range of Direct3D 9 samplers of given sampler type |
| 1926 | unsigned int *appliedTextureSerial = (type == SAMPLER_PIXEL) ? mAppliedTextureSerialPS : mAppliedTextureSerialVS; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1927 | int samplerRange = programBinary->getUsedSamplerRange(type); |
| 1928 | |
| 1929 | for (int samplerIndex = 0; samplerIndex < samplerRange; samplerIndex++) |
| 1930 | { |
| 1931 | int textureUnit = programBinary->getSamplerMapping(type, samplerIndex); // OpenGL texture image unit index |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1932 | |
| 1933 | if (textureUnit != -1) |
| 1934 | { |
| 1935 | TextureType textureType = programBinary->getSamplerTextureType(type, samplerIndex); |
| 1936 | |
| 1937 | Texture *texture = getSamplerTexture(textureUnit, textureType); |
| 1938 | unsigned int texSerial = texture->getTextureSerial(); |
| 1939 | |
| 1940 | if (appliedTextureSerial[samplerIndex] != texSerial || texture->hasDirtyParameters() || texture->hasDirtyImages()) |
| 1941 | { |
daniel@transgaming.com | a734f27 | 2012-10-31 18:07:48 +0000 | [diff] [blame] | 1942 | if (texture->isSamplerComplete()) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1943 | { |
| 1944 | if (appliedTextureSerial[samplerIndex] != texSerial || texture->hasDirtyParameters()) |
| 1945 | { |
daniel@transgaming.com | ebf139f | 2012-10-31 18:07:32 +0000 | [diff] [blame] | 1946 | SamplerState samplerState; |
| 1947 | texture->getSamplerState(&samplerState); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1948 | |
daniel@transgaming.com | ba0570e | 2012-10-31 18:07:39 +0000 | [diff] [blame] | 1949 | mRenderer->setSamplerState(type, samplerIndex, samplerState); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | if (appliedTextureSerial[samplerIndex] != texSerial || texture->hasDirtyImages()) |
| 1953 | { |
daniel@transgaming.com | a734f27 | 2012-10-31 18:07:48 +0000 | [diff] [blame] | 1954 | mRenderer->setTexture(type, samplerIndex, texture); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1955 | } |
| 1956 | } |
| 1957 | else |
| 1958 | { |
daniel@transgaming.com | a734f27 | 2012-10-31 18:07:48 +0000 | [diff] [blame] | 1959 | mRenderer->setTexture(type, samplerIndex, getIncompleteTexture(textureType)); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | appliedTextureSerial[samplerIndex] = texSerial; |
| 1963 | texture->resetDirty(); |
| 1964 | } |
| 1965 | } |
| 1966 | else |
| 1967 | { |
| 1968 | if (appliedTextureSerial[samplerIndex] != 0) |
| 1969 | { |
daniel@transgaming.com | a734f27 | 2012-10-31 18:07:48 +0000 | [diff] [blame] | 1970 | mRenderer->setTexture(type, samplerIndex, NULL); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1971 | appliedTextureSerial[samplerIndex] = 0; |
| 1972 | } |
| 1973 | } |
| 1974 | } |
| 1975 | |
| 1976 | for (int samplerIndex = samplerRange; samplerIndex < samplerCount; samplerIndex++) |
| 1977 | { |
| 1978 | if (appliedTextureSerial[samplerIndex] != 0) |
| 1979 | { |
daniel@transgaming.com | a734f27 | 2012-10-31 18:07:48 +0000 | [diff] [blame] | 1980 | mRenderer->setTexture(type, samplerIndex, NULL); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1981 | appliedTextureSerial[samplerIndex] = 0; |
| 1982 | } |
| 1983 | } |
| 1984 | } |
| 1985 | |
| 1986 | void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, |
| 1987 | GLenum format, GLenum type, GLsizei *bufSize, void* pixels) |
| 1988 | { |
| 1989 | Framebuffer *framebuffer = getReadFramebuffer(); |
| 1990 | |
| 1991 | if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 1992 | { |
| 1993 | return error(GL_INVALID_FRAMEBUFFER_OPERATION); |
| 1994 | } |
| 1995 | |
| 1996 | if (getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0) |
| 1997 | { |
| 1998 | return error(GL_INVALID_OPERATION); |
| 1999 | } |
| 2000 | |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2001 | GLsizei outputPitch = ComputePitch(width, ConvertSizedInternalFormat(format, type), getPackAlignment()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2002 | // sized query sanity check |
| 2003 | if (bufSize) |
| 2004 | { |
| 2005 | int requiredSize = outputPitch * height; |
| 2006 | if (requiredSize > *bufSize) |
| 2007 | { |
| 2008 | return error(GL_INVALID_OPERATION); |
| 2009 | } |
| 2010 | } |
| 2011 | |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2012 | mRenderer->readPixels(framebuffer, x, y, width, height, format, type, outputPitch, getPackReverseRowOrder(), getPackAlignment(), pixels); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | void Context::clear(GLbitfield mask) |
| 2016 | { |
| 2017 | Framebuffer *framebufferObject = getDrawFramebuffer(); |
| 2018 | |
| 2019 | if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 2020 | { |
| 2021 | return error(GL_INVALID_FRAMEBUFFER_OPERATION); |
| 2022 | } |
| 2023 | |
| 2024 | DWORD flags = 0; |
| 2025 | |
| 2026 | if (mask & GL_COLOR_BUFFER_BIT) |
| 2027 | { |
| 2028 | mask &= ~GL_COLOR_BUFFER_BIT; |
| 2029 | |
| 2030 | if (framebufferObject->getColorbufferType() != GL_NONE) |
| 2031 | { |
| 2032 | flags |= D3DCLEAR_TARGET; |
| 2033 | } |
| 2034 | } |
| 2035 | |
| 2036 | if (mask & GL_DEPTH_BUFFER_BIT) |
| 2037 | { |
| 2038 | mask &= ~GL_DEPTH_BUFFER_BIT; |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 2039 | if (mState.depthStencil.depthMask && framebufferObject->getDepthbufferType() != GL_NONE) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2040 | { |
| 2041 | flags |= D3DCLEAR_ZBUFFER; |
| 2042 | } |
| 2043 | } |
| 2044 | |
| 2045 | GLuint stencilUnmasked = 0x0; |
| 2046 | |
| 2047 | if (mask & GL_STENCIL_BUFFER_BIT) |
| 2048 | { |
| 2049 | mask &= ~GL_STENCIL_BUFFER_BIT; |
| 2050 | if (framebufferObject->getStencilbufferType() != GL_NONE) |
| 2051 | { |
daniel@transgaming.com | d62d714 | 2012-11-28 19:40:28 +0000 | [diff] [blame] | 2052 | rx::RenderTarget *depthStencil = framebufferObject->getStencilbuffer()->getDepthStencil(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2053 | if (!depthStencil) |
| 2054 | { |
| 2055 | ERR("Depth stencil pointer unexpectedly null."); |
| 2056 | return; |
| 2057 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2058 | |
daniel@transgaming.com | d62d714 | 2012-11-28 19:40:28 +0000 | [diff] [blame] | 2059 | unsigned int stencilSize = gl::GetStencilSize(depthStencil->getActualFormat()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2060 | stencilUnmasked = (0x1 << stencilSize) - 1; |
| 2061 | |
| 2062 | if (stencilUnmasked != 0x0) |
| 2063 | { |
| 2064 | flags |= D3DCLEAR_STENCIL; |
| 2065 | } |
| 2066 | } |
| 2067 | } |
| 2068 | |
| 2069 | if (mask != 0) |
| 2070 | { |
| 2071 | return error(GL_INVALID_VALUE); |
| 2072 | } |
| 2073 | |
| 2074 | if (!applyRenderTarget(true)) // Clips the clear to the scissor rectangle but not the viewport |
| 2075 | { |
| 2076 | return; |
| 2077 | } |
| 2078 | |
| 2079 | D3DCOLOR color = D3DCOLOR_ARGB(unorm<8>(mState.colorClearValue.alpha), |
| 2080 | unorm<8>(mState.colorClearValue.red), |
| 2081 | unorm<8>(mState.colorClearValue.green), |
| 2082 | unorm<8>(mState.colorClearValue.blue)); |
| 2083 | float depth = clamp01(mState.depthClearValue); |
| 2084 | int stencil = mState.stencilClearValue & 0x000000FF; |
| 2085 | |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 2086 | |
daniel@transgaming.com | 39cee2e | 2012-11-28 19:39:14 +0000 | [diff] [blame] | 2087 | bool alphaUnmasked = (gl::GetAlphaSize(mRenderTargetDesc.format) == 0) || mState.blend.colorMaskAlpha; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2088 | |
| 2089 | const bool needMaskedStencilClear = (flags & D3DCLEAR_STENCIL) && |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 2090 | (mState.depthStencil.stencilWritemask & stencilUnmasked) != stencilUnmasked; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2091 | const bool needMaskedColorClear = (flags & D3DCLEAR_TARGET) && |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 2092 | !(mState.blend.colorMaskRed && mState.blend.colorMaskGreen && |
| 2093 | mState.blend.colorMaskBlue && alphaUnmasked); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2094 | |
| 2095 | if (needMaskedColorClear || needMaskedStencilClear) |
| 2096 | { |
| 2097 | // State which is altered in all paths from this point to the clear call is saved. |
| 2098 | // State which is altered in only some paths will be flagged dirty in the case that |
| 2099 | // that path is taken. |
| 2100 | HRESULT hr; |
| 2101 | if (mMaskedClearSavedState == NULL) |
| 2102 | { |
| 2103 | hr = mDevice->BeginStateBlock(); |
| 2104 | ASSERT(SUCCEEDED(hr) || hr == D3DERR_OUTOFVIDEOMEMORY || hr == E_OUTOFMEMORY); |
| 2105 | |
| 2106 | mDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); |
| 2107 | mDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS); |
| 2108 | mDevice->SetRenderState(D3DRS_ZENABLE, FALSE); |
| 2109 | mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); |
| 2110 | mDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); |
| 2111 | mDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); |
| 2112 | mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
| 2113 | mDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, 0); |
| 2114 | mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, 0); |
| 2115 | mDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE); |
| 2116 | mDevice->SetPixelShader(NULL); |
| 2117 | mDevice->SetVertexShader(NULL); |
| 2118 | mDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE); |
| 2119 | mDevice->SetStreamSource(0, NULL, 0, 0); |
| 2120 | mDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE); |
| 2121 | mDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); |
| 2122 | mDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR); |
| 2123 | mDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); |
| 2124 | mDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR); |
| 2125 | mDevice->SetRenderState(D3DRS_TEXTUREFACTOR, color); |
| 2126 | mDevice->SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF); |
| 2127 | |
| 2128 | for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++) |
| 2129 | { |
| 2130 | mDevice->SetStreamSourceFreq(i, 1); |
| 2131 | } |
| 2132 | |
| 2133 | hr = mDevice->EndStateBlock(&mMaskedClearSavedState); |
| 2134 | ASSERT(SUCCEEDED(hr) || hr == D3DERR_OUTOFVIDEOMEMORY || hr == E_OUTOFMEMORY); |
| 2135 | } |
| 2136 | |
| 2137 | ASSERT(mMaskedClearSavedState != NULL); |
| 2138 | |
| 2139 | if (mMaskedClearSavedState != NULL) |
| 2140 | { |
| 2141 | hr = mMaskedClearSavedState->Capture(); |
| 2142 | ASSERT(SUCCEEDED(hr)); |
| 2143 | } |
| 2144 | |
| 2145 | mDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); |
| 2146 | mDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS); |
| 2147 | mDevice->SetRenderState(D3DRS_ZENABLE, FALSE); |
| 2148 | mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); |
| 2149 | mDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); |
| 2150 | mDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); |
| 2151 | mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
| 2152 | mDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, 0); |
| 2153 | |
| 2154 | if (flags & D3DCLEAR_TARGET) |
| 2155 | { |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 2156 | mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, |
| 2157 | gl_d3d9::ConvertColorMask(mState.blend.colorMaskRed, |
| 2158 | mState.blend.colorMaskGreen, |
| 2159 | mState.blend.colorMaskBlue, |
| 2160 | mState.blend.colorMaskAlpha)); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2161 | } |
| 2162 | else |
| 2163 | { |
| 2164 | mDevice->SetRenderState(D3DRS_COLORWRITEENABLE, 0); |
| 2165 | } |
| 2166 | |
| 2167 | if (stencilUnmasked != 0x0 && (flags & D3DCLEAR_STENCIL)) |
| 2168 | { |
| 2169 | mDevice->SetRenderState(D3DRS_STENCILENABLE, TRUE); |
| 2170 | mDevice->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, FALSE); |
| 2171 | mDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS); |
| 2172 | mDevice->SetRenderState(D3DRS_STENCILREF, stencil); |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 2173 | mDevice->SetRenderState(D3DRS_STENCILWRITEMASK, mState.depthStencil.stencilWritemask); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2174 | mDevice->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_REPLACE); |
| 2175 | mDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_REPLACE); |
| 2176 | mDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2177 | } |
| 2178 | else |
| 2179 | { |
| 2180 | mDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE); |
| 2181 | } |
| 2182 | |
| 2183 | mDevice->SetPixelShader(NULL); |
| 2184 | mDevice->SetVertexShader(NULL); |
| 2185 | mDevice->SetFVF(D3DFVF_XYZRHW); |
| 2186 | mDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE); |
| 2187 | mDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); |
| 2188 | mDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR); |
| 2189 | mDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); |
| 2190 | mDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR); |
| 2191 | mDevice->SetRenderState(D3DRS_TEXTUREFACTOR, color); |
| 2192 | mDevice->SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF); |
| 2193 | |
| 2194 | for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++) |
| 2195 | { |
| 2196 | mDevice->SetStreamSourceFreq(i, 1); |
| 2197 | } |
| 2198 | |
| 2199 | float quad[4][4]; // A quadrilateral covering the target, aligned to match the edges |
| 2200 | quad[0][0] = -0.5f; |
daniel@transgaming.com | 39cee2e | 2012-11-28 19:39:14 +0000 | [diff] [blame] | 2201 | quad[0][1] = mRenderTargetDesc.height - 0.5f; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2202 | quad[0][2] = 0.0f; |
| 2203 | quad[0][3] = 1.0f; |
| 2204 | |
daniel@transgaming.com | 39cee2e | 2012-11-28 19:39:14 +0000 | [diff] [blame] | 2205 | quad[1][0] = mRenderTargetDesc.width - 0.5f; |
| 2206 | quad[1][1] = mRenderTargetDesc.height - 0.5f; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2207 | quad[1][2] = 0.0f; |
| 2208 | quad[1][3] = 1.0f; |
| 2209 | |
| 2210 | quad[2][0] = -0.5f; |
| 2211 | quad[2][1] = -0.5f; |
| 2212 | quad[2][2] = 0.0f; |
| 2213 | quad[2][3] = 1.0f; |
| 2214 | |
daniel@transgaming.com | 39cee2e | 2012-11-28 19:39:14 +0000 | [diff] [blame] | 2215 | quad[3][0] = mRenderTargetDesc.width - 0.5f; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2216 | quad[3][1] = -0.5f; |
| 2217 | quad[3][2] = 0.0f; |
| 2218 | quad[3][3] = 1.0f; |
| 2219 | |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2220 | mRenderer->startScene(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2221 | mDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, quad, sizeof(float[4])); |
| 2222 | |
| 2223 | if (flags & D3DCLEAR_ZBUFFER) |
| 2224 | { |
| 2225 | mDevice->SetRenderState(D3DRS_ZENABLE, TRUE); |
| 2226 | mDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE); |
| 2227 | mDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER, color, depth, stencil); |
| 2228 | } |
| 2229 | |
| 2230 | if (mMaskedClearSavedState != NULL) |
| 2231 | { |
| 2232 | mMaskedClearSavedState->Apply(); |
| 2233 | } |
| 2234 | } |
| 2235 | else if (flags) |
| 2236 | { |
| 2237 | mDevice->Clear(0, NULL, flags, color, depth, stencil); |
| 2238 | } |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 2239 | |
| 2240 | mRenderer->clear(mask, mState.colorClearValue, mState.depthClearValue, mState.stencilClearValue, |
| 2241 | framebufferObject); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2242 | } |
| 2243 | |
| 2244 | void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instances) |
| 2245 | { |
| 2246 | if (!mState.currentProgram) |
| 2247 | { |
| 2248 | return error(GL_INVALID_OPERATION); |
| 2249 | } |
| 2250 | |
| 2251 | D3DPRIMITIVETYPE primitiveType; |
| 2252 | int primitiveCount; |
| 2253 | |
daniel@transgaming.com | 682a37c | 2012-11-28 19:34:44 +0000 | [diff] [blame] | 2254 | if(!gl_d3d9::ConvertPrimitiveType(mode, count, &primitiveType, &primitiveCount)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2255 | return error(GL_INVALID_ENUM); |
| 2256 | |
| 2257 | if (primitiveCount <= 0) |
| 2258 | { |
| 2259 | return; |
| 2260 | } |
| 2261 | |
| 2262 | if (!applyRenderTarget(false)) |
| 2263 | { |
| 2264 | return; |
| 2265 | } |
| 2266 | |
| 2267 | applyState(mode); |
| 2268 | |
| 2269 | GLsizei repeatDraw = 1; |
| 2270 | GLenum err = applyVertexBuffer(first, count, instances, &repeatDraw); |
| 2271 | if (err != GL_NO_ERROR) |
| 2272 | { |
| 2273 | return error(err); |
| 2274 | } |
| 2275 | |
| 2276 | applyShaders(); |
| 2277 | applyTextures(); |
| 2278 | |
daniel@transgaming.com | 62a2846 | 2012-07-24 18:33:59 +0000 | [diff] [blame] | 2279 | if (!getCurrentProgramBinary()->validateSamplers(NULL)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2280 | { |
| 2281 | return error(GL_INVALID_OPERATION); |
| 2282 | } |
| 2283 | |
daniel@transgaming.com | 087e578 | 2012-09-17 21:28:47 +0000 | [diff] [blame] | 2284 | if (!skipDraw(mode)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2285 | { |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2286 | mRenderer->startScene(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2287 | |
| 2288 | if (mode == GL_LINE_LOOP) |
| 2289 | { |
| 2290 | drawLineLoop(count, GL_NONE, NULL, 0); |
| 2291 | } |
| 2292 | else if (instances > 0) |
| 2293 | { |
| 2294 | StaticIndexBuffer *countingIB = mIndexDataManager->getCountingIndices(count); |
| 2295 | if (countingIB) |
| 2296 | { |
| 2297 | if (mAppliedIBSerial != countingIB->getSerial()) |
| 2298 | { |
| 2299 | mDevice->SetIndices(countingIB->getBuffer()); |
| 2300 | mAppliedIBSerial = countingIB->getSerial(); |
| 2301 | } |
| 2302 | |
| 2303 | for (int i = 0; i < repeatDraw; i++) |
| 2304 | { |
| 2305 | mDevice->DrawIndexedPrimitive(primitiveType, 0, 0, count, 0, primitiveCount); |
| 2306 | } |
| 2307 | } |
| 2308 | else |
| 2309 | { |
| 2310 | ERR("Could not create a counting index buffer for glDrawArraysInstanced."); |
| 2311 | return error(GL_OUT_OF_MEMORY); |
| 2312 | } |
| 2313 | } |
| 2314 | else // Regular case |
| 2315 | { |
| 2316 | mDevice->DrawPrimitive(primitiveType, 0, primitiveCount); |
| 2317 | } |
| 2318 | } |
| 2319 | } |
| 2320 | |
| 2321 | void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instances) |
| 2322 | { |
| 2323 | if (!mState.currentProgram) |
| 2324 | { |
| 2325 | return error(GL_INVALID_OPERATION); |
| 2326 | } |
| 2327 | |
| 2328 | if (!indices && !mState.elementArrayBuffer) |
| 2329 | { |
| 2330 | return error(GL_INVALID_OPERATION); |
| 2331 | } |
| 2332 | |
| 2333 | D3DPRIMITIVETYPE primitiveType; |
| 2334 | int primitiveCount; |
| 2335 | |
daniel@transgaming.com | 682a37c | 2012-11-28 19:34:44 +0000 | [diff] [blame] | 2336 | if(!gl_d3d9::ConvertPrimitiveType(mode, count, &primitiveType, &primitiveCount)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2337 | return error(GL_INVALID_ENUM); |
| 2338 | |
| 2339 | if (primitiveCount <= 0) |
| 2340 | { |
| 2341 | return; |
| 2342 | } |
| 2343 | |
| 2344 | if (!applyRenderTarget(false)) |
| 2345 | { |
| 2346 | return; |
| 2347 | } |
| 2348 | |
| 2349 | applyState(mode); |
| 2350 | |
| 2351 | TranslatedIndexData indexInfo; |
| 2352 | GLenum err = applyIndexBuffer(indices, count, mode, type, &indexInfo); |
| 2353 | if (err != GL_NO_ERROR) |
| 2354 | { |
| 2355 | return error(err); |
| 2356 | } |
| 2357 | |
| 2358 | GLsizei vertexCount = indexInfo.maxIndex - indexInfo.minIndex + 1; |
| 2359 | GLsizei repeatDraw = 1; |
| 2360 | err = applyVertexBuffer(indexInfo.minIndex, vertexCount, instances, &repeatDraw); |
| 2361 | if (err != GL_NO_ERROR) |
| 2362 | { |
| 2363 | return error(err); |
| 2364 | } |
| 2365 | |
| 2366 | applyShaders(); |
| 2367 | applyTextures(); |
| 2368 | |
daniel@transgaming.com | 62a2846 | 2012-07-24 18:33:59 +0000 | [diff] [blame] | 2369 | if (!getCurrentProgramBinary()->validateSamplers(false)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2370 | { |
| 2371 | return error(GL_INVALID_OPERATION); |
| 2372 | } |
| 2373 | |
daniel@transgaming.com | 087e578 | 2012-09-17 21:28:47 +0000 | [diff] [blame] | 2374 | if (!skipDraw(mode)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2375 | { |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2376 | mRenderer->startScene(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2377 | |
| 2378 | if (mode == GL_LINE_LOOP) |
| 2379 | { |
| 2380 | drawLineLoop(count, type, indices, indexInfo.minIndex); |
| 2381 | } |
| 2382 | else |
| 2383 | { |
| 2384 | for (int i = 0; i < repeatDraw; i++) |
| 2385 | { |
| 2386 | mDevice->DrawIndexedPrimitive(primitiveType, -(INT)indexInfo.minIndex, indexInfo.minIndex, vertexCount, indexInfo.startIndex, primitiveCount); |
| 2387 | } |
| 2388 | } |
| 2389 | } |
| 2390 | } |
| 2391 | |
| 2392 | // Implements glFlush when block is false, glFinish when block is true |
| 2393 | void Context::sync(bool block) |
| 2394 | { |
daniel@transgaming.com | ef21ab2 | 2012-10-31 17:52:47 +0000 | [diff] [blame] | 2395 | mRenderer->sync(block); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2396 | } |
| 2397 | |
| 2398 | void Context::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex) |
| 2399 | { |
| 2400 | // Get the raw indices for an indexed draw |
| 2401 | if (type != GL_NONE && mState.elementArrayBuffer.get()) |
| 2402 | { |
| 2403 | Buffer *indexBuffer = mState.elementArrayBuffer.get(); |
| 2404 | intptr_t offset = reinterpret_cast<intptr_t>(indices); |
| 2405 | indices = static_cast<const GLubyte*>(indexBuffer->data()) + offset; |
| 2406 | } |
| 2407 | |
| 2408 | UINT startIndex = 0; |
| 2409 | bool succeeded = false; |
| 2410 | |
| 2411 | if (supports32bitIndices()) |
| 2412 | { |
| 2413 | const int spaceNeeded = (count + 1) * sizeof(unsigned int); |
| 2414 | |
| 2415 | if (!mLineLoopIB) |
| 2416 | { |
daniel@transgaming.com | 6716a27 | 2012-10-31 18:31:39 +0000 | [diff] [blame] | 2417 | mLineLoopIB = new StreamingIndexBuffer(mRenderer, INITIAL_INDEX_BUFFER_SIZE, D3DFMT_INDEX32); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2418 | } |
| 2419 | |
| 2420 | if (mLineLoopIB) |
| 2421 | { |
| 2422 | mLineLoopIB->reserveSpace(spaceNeeded, GL_UNSIGNED_INT); |
| 2423 | |
| 2424 | UINT offset = 0; |
| 2425 | unsigned int *data = static_cast<unsigned int*>(mLineLoopIB->map(spaceNeeded, &offset)); |
| 2426 | startIndex = offset / 4; |
| 2427 | |
| 2428 | if (data) |
| 2429 | { |
| 2430 | switch (type) |
| 2431 | { |
| 2432 | case GL_NONE: // Non-indexed draw |
| 2433 | for (int i = 0; i < count; i++) |
| 2434 | { |
| 2435 | data[i] = i; |
| 2436 | } |
| 2437 | data[count] = 0; |
| 2438 | break; |
| 2439 | case GL_UNSIGNED_BYTE: |
| 2440 | for (int i = 0; i < count; i++) |
| 2441 | { |
| 2442 | data[i] = static_cast<const GLubyte*>(indices)[i]; |
| 2443 | } |
| 2444 | data[count] = static_cast<const GLubyte*>(indices)[0]; |
| 2445 | break; |
| 2446 | case GL_UNSIGNED_SHORT: |
| 2447 | for (int i = 0; i < count; i++) |
| 2448 | { |
| 2449 | data[i] = static_cast<const GLushort*>(indices)[i]; |
| 2450 | } |
| 2451 | data[count] = static_cast<const GLushort*>(indices)[0]; |
| 2452 | break; |
| 2453 | case GL_UNSIGNED_INT: |
| 2454 | for (int i = 0; i < count; i++) |
| 2455 | { |
| 2456 | data[i] = static_cast<const GLuint*>(indices)[i]; |
| 2457 | } |
| 2458 | data[count] = static_cast<const GLuint*>(indices)[0]; |
| 2459 | break; |
| 2460 | default: UNREACHABLE(); |
| 2461 | } |
| 2462 | |
| 2463 | mLineLoopIB->unmap(); |
| 2464 | succeeded = true; |
| 2465 | } |
| 2466 | } |
| 2467 | } |
| 2468 | else |
| 2469 | { |
| 2470 | const int spaceNeeded = (count + 1) * sizeof(unsigned short); |
| 2471 | |
| 2472 | if (!mLineLoopIB) |
| 2473 | { |
daniel@transgaming.com | 6716a27 | 2012-10-31 18:31:39 +0000 | [diff] [blame] | 2474 | mLineLoopIB = new StreamingIndexBuffer(mRenderer, INITIAL_INDEX_BUFFER_SIZE, D3DFMT_INDEX16); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2475 | } |
| 2476 | |
| 2477 | if (mLineLoopIB) |
| 2478 | { |
| 2479 | mLineLoopIB->reserveSpace(spaceNeeded, GL_UNSIGNED_SHORT); |
| 2480 | |
| 2481 | UINT offset = 0; |
| 2482 | unsigned short *data = static_cast<unsigned short*>(mLineLoopIB->map(spaceNeeded, &offset)); |
| 2483 | startIndex = offset / 2; |
| 2484 | |
| 2485 | if (data) |
| 2486 | { |
| 2487 | switch (type) |
| 2488 | { |
| 2489 | case GL_NONE: // Non-indexed draw |
| 2490 | for (int i = 0; i < count; i++) |
| 2491 | { |
| 2492 | data[i] = i; |
| 2493 | } |
| 2494 | data[count] = 0; |
| 2495 | break; |
| 2496 | case GL_UNSIGNED_BYTE: |
| 2497 | for (int i = 0; i < count; i++) |
| 2498 | { |
| 2499 | data[i] = static_cast<const GLubyte*>(indices)[i]; |
| 2500 | } |
| 2501 | data[count] = static_cast<const GLubyte*>(indices)[0]; |
| 2502 | break; |
| 2503 | case GL_UNSIGNED_SHORT: |
| 2504 | for (int i = 0; i < count; i++) |
| 2505 | { |
| 2506 | data[i] = static_cast<const GLushort*>(indices)[i]; |
| 2507 | } |
| 2508 | data[count] = static_cast<const GLushort*>(indices)[0]; |
| 2509 | break; |
| 2510 | case GL_UNSIGNED_INT: |
| 2511 | for (int i = 0; i < count; i++) |
| 2512 | { |
| 2513 | data[i] = static_cast<const GLuint*>(indices)[i]; |
| 2514 | } |
| 2515 | data[count] = static_cast<const GLuint*>(indices)[0]; |
| 2516 | break; |
| 2517 | default: UNREACHABLE(); |
| 2518 | } |
| 2519 | |
| 2520 | mLineLoopIB->unmap(); |
| 2521 | succeeded = true; |
| 2522 | } |
| 2523 | } |
| 2524 | } |
| 2525 | |
| 2526 | if (succeeded) |
| 2527 | { |
| 2528 | if (mAppliedIBSerial != mLineLoopIB->getSerial()) |
| 2529 | { |
| 2530 | mDevice->SetIndices(mLineLoopIB->getBuffer()); |
| 2531 | mAppliedIBSerial = mLineLoopIB->getSerial(); |
| 2532 | } |
| 2533 | |
| 2534 | mDevice->DrawIndexedPrimitive(D3DPT_LINESTRIP, -minIndex, minIndex, count, startIndex, count); |
| 2535 | } |
| 2536 | else |
| 2537 | { |
| 2538 | ERR("Could not create a looping index buffer for GL_LINE_LOOP."); |
| 2539 | return error(GL_OUT_OF_MEMORY); |
| 2540 | } |
| 2541 | } |
| 2542 | |
| 2543 | void Context::recordInvalidEnum() |
| 2544 | { |
| 2545 | mInvalidEnum = true; |
| 2546 | } |
| 2547 | |
| 2548 | void Context::recordInvalidValue() |
| 2549 | { |
| 2550 | mInvalidValue = true; |
| 2551 | } |
| 2552 | |
| 2553 | void Context::recordInvalidOperation() |
| 2554 | { |
| 2555 | mInvalidOperation = true; |
| 2556 | } |
| 2557 | |
| 2558 | void Context::recordOutOfMemory() |
| 2559 | { |
| 2560 | mOutOfMemory = true; |
| 2561 | } |
| 2562 | |
| 2563 | void Context::recordInvalidFramebufferOperation() |
| 2564 | { |
| 2565 | mInvalidFramebufferOperation = true; |
| 2566 | } |
| 2567 | |
| 2568 | // Get one of the recorded errors and clear its flag, if any. |
| 2569 | // [OpenGL ES 2.0.24] section 2.5 page 13. |
| 2570 | GLenum Context::getError() |
| 2571 | { |
| 2572 | if (mInvalidEnum) |
| 2573 | { |
| 2574 | mInvalidEnum = false; |
| 2575 | |
| 2576 | return GL_INVALID_ENUM; |
| 2577 | } |
| 2578 | |
| 2579 | if (mInvalidValue) |
| 2580 | { |
| 2581 | mInvalidValue = false; |
| 2582 | |
| 2583 | return GL_INVALID_VALUE; |
| 2584 | } |
| 2585 | |
| 2586 | if (mInvalidOperation) |
| 2587 | { |
| 2588 | mInvalidOperation = false; |
| 2589 | |
| 2590 | return GL_INVALID_OPERATION; |
| 2591 | } |
| 2592 | |
| 2593 | if (mOutOfMemory) |
| 2594 | { |
| 2595 | mOutOfMemory = false; |
| 2596 | |
| 2597 | return GL_OUT_OF_MEMORY; |
| 2598 | } |
| 2599 | |
| 2600 | if (mInvalidFramebufferOperation) |
| 2601 | { |
| 2602 | mInvalidFramebufferOperation = false; |
| 2603 | |
| 2604 | return GL_INVALID_FRAMEBUFFER_OPERATION; |
| 2605 | } |
| 2606 | |
| 2607 | return GL_NO_ERROR; |
| 2608 | } |
| 2609 | |
| 2610 | GLenum Context::getResetStatus() |
| 2611 | { |
| 2612 | if (mResetStatus == GL_NO_ERROR) |
| 2613 | { |
daniel@transgaming.com | f688c0d | 2012-10-31 17:52:57 +0000 | [diff] [blame] | 2614 | // mResetStatus will be set by the markContextLost callback |
| 2615 | // in the case a notification is sent |
| 2616 | mRenderer->testDeviceLost(true); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | GLenum status = mResetStatus; |
| 2620 | |
| 2621 | if (mResetStatus != GL_NO_ERROR) |
| 2622 | { |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2623 | if (mRenderer->testDeviceResettable()) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2624 | { |
| 2625 | mResetStatus = GL_NO_ERROR; |
| 2626 | } |
| 2627 | } |
| 2628 | |
| 2629 | return status; |
| 2630 | } |
| 2631 | |
| 2632 | bool Context::isResetNotificationEnabled() |
| 2633 | { |
| 2634 | return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT); |
| 2635 | } |
| 2636 | |
| 2637 | bool Context::supportsShaderModel3() const |
| 2638 | { |
| 2639 | return mSupportsShaderModel3; |
| 2640 | } |
| 2641 | |
| 2642 | float Context::getMaximumPointSize() const |
| 2643 | { |
| 2644 | return mSupportsShaderModel3 ? mMaximumPointSize : ALIASED_POINT_SIZE_RANGE_MAX_SM2; |
| 2645 | } |
| 2646 | |
| 2647 | int Context::getMaximumVaryingVectors() const |
| 2648 | { |
| 2649 | return mSupportsShaderModel3 ? MAX_VARYING_VECTORS_SM3 : MAX_VARYING_VECTORS_SM2; |
| 2650 | } |
| 2651 | |
| 2652 | unsigned int Context::getMaximumVertexTextureImageUnits() const |
| 2653 | { |
| 2654 | return mSupportsVertexTexture ? MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF : 0; |
| 2655 | } |
| 2656 | |
| 2657 | unsigned int Context::getMaximumCombinedTextureImageUnits() const |
| 2658 | { |
| 2659 | return MAX_TEXTURE_IMAGE_UNITS + getMaximumVertexTextureImageUnits(); |
| 2660 | } |
| 2661 | |
| 2662 | int Context::getMaximumFragmentUniformVectors() const |
| 2663 | { |
| 2664 | return mSupportsShaderModel3 ? MAX_FRAGMENT_UNIFORM_VECTORS_SM3 : MAX_FRAGMENT_UNIFORM_VECTORS_SM2; |
| 2665 | } |
| 2666 | |
| 2667 | int Context::getMaxSupportedSamples() const |
| 2668 | { |
daniel@transgaming.com | b783398 | 2012-10-31 18:31:46 +0000 | [diff] [blame] | 2669 | return mRenderer->getMaxSupportedSamples(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2670 | } |
| 2671 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2672 | bool Context::supportsEventQueries() const |
| 2673 | { |
| 2674 | return mSupportsEventQueries; |
| 2675 | } |
| 2676 | |
| 2677 | bool Context::supportsOcclusionQueries() const |
| 2678 | { |
| 2679 | return mSupportsOcclusionQueries; |
| 2680 | } |
| 2681 | |
| 2682 | bool Context::supportsDXT1Textures() const |
| 2683 | { |
| 2684 | return mSupportsDXT1Textures; |
| 2685 | } |
| 2686 | |
| 2687 | bool Context::supportsDXT3Textures() const |
| 2688 | { |
| 2689 | return mSupportsDXT3Textures; |
| 2690 | } |
| 2691 | |
| 2692 | bool Context::supportsDXT5Textures() const |
| 2693 | { |
| 2694 | return mSupportsDXT5Textures; |
| 2695 | } |
| 2696 | |
| 2697 | bool Context::supportsFloat32Textures() const |
| 2698 | { |
| 2699 | return mSupportsFloat32Textures; |
| 2700 | } |
| 2701 | |
| 2702 | bool Context::supportsFloat32LinearFilter() const |
| 2703 | { |
| 2704 | return mSupportsFloat32LinearFilter; |
| 2705 | } |
| 2706 | |
| 2707 | bool Context::supportsFloat32RenderableTextures() const |
| 2708 | { |
| 2709 | return mSupportsFloat32RenderableTextures; |
| 2710 | } |
| 2711 | |
| 2712 | bool Context::supportsFloat16Textures() const |
| 2713 | { |
| 2714 | return mSupportsFloat16Textures; |
| 2715 | } |
| 2716 | |
| 2717 | bool Context::supportsFloat16LinearFilter() const |
| 2718 | { |
| 2719 | return mSupportsFloat16LinearFilter; |
| 2720 | } |
| 2721 | |
| 2722 | bool Context::supportsFloat16RenderableTextures() const |
| 2723 | { |
| 2724 | return mSupportsFloat16RenderableTextures; |
| 2725 | } |
| 2726 | |
| 2727 | int Context::getMaximumRenderbufferDimension() const |
| 2728 | { |
| 2729 | return mMaxRenderbufferDimension; |
| 2730 | } |
| 2731 | |
| 2732 | int Context::getMaximumTextureDimension() const |
| 2733 | { |
| 2734 | return mMaxTextureDimension; |
| 2735 | } |
| 2736 | |
| 2737 | int Context::getMaximumCubeTextureDimension() const |
| 2738 | { |
| 2739 | return mMaxCubeTextureDimension; |
| 2740 | } |
| 2741 | |
| 2742 | int Context::getMaximumTextureLevel() const |
| 2743 | { |
| 2744 | return mMaxTextureLevel; |
| 2745 | } |
| 2746 | |
| 2747 | bool Context::supportsLuminanceTextures() const |
| 2748 | { |
| 2749 | return mSupportsLuminanceTextures; |
| 2750 | } |
| 2751 | |
| 2752 | bool Context::supportsLuminanceAlphaTextures() const |
| 2753 | { |
| 2754 | return mSupportsLuminanceAlphaTextures; |
| 2755 | } |
| 2756 | |
| 2757 | bool Context::supportsDepthTextures() const |
| 2758 | { |
| 2759 | return mSupportsDepthTextures; |
| 2760 | } |
| 2761 | |
| 2762 | bool Context::supports32bitIndices() const |
| 2763 | { |
| 2764 | return mSupports32bitIndices; |
| 2765 | } |
| 2766 | |
| 2767 | bool Context::supportsNonPower2Texture() const |
| 2768 | { |
| 2769 | return mSupportsNonPower2Texture; |
| 2770 | } |
| 2771 | |
| 2772 | bool Context::supportsInstancing() const |
| 2773 | { |
| 2774 | return mSupportsInstancing; |
| 2775 | } |
| 2776 | |
daniel@transgaming.com | 07ab841 | 2012-07-12 15:17:09 +0000 | [diff] [blame] | 2777 | bool Context::supportsTextureFilterAnisotropy() const |
| 2778 | { |
| 2779 | return mSupportsTextureFilterAnisotropy; |
| 2780 | } |
| 2781 | |
| 2782 | float Context::getTextureMaxAnisotropy() const |
| 2783 | { |
| 2784 | return mMaxTextureAnisotropy; |
| 2785 | } |
| 2786 | |
daniel@transgaming.com | 42944b0 | 2012-09-27 17:45:57 +0000 | [diff] [blame] | 2787 | bool Context::getCurrentReadFormatType(GLenum *format, GLenum *type) |
| 2788 | { |
| 2789 | Framebuffer *framebuffer = getReadFramebuffer(); |
| 2790 | if (!framebuffer || framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 2791 | { |
| 2792 | return error(GL_INVALID_OPERATION, false); |
| 2793 | } |
| 2794 | |
| 2795 | Renderbuffer *renderbuffer = framebuffer->getColorbuffer(); |
| 2796 | if (!renderbuffer) |
| 2797 | { |
| 2798 | return error(GL_INVALID_OPERATION, false); |
| 2799 | } |
| 2800 | |
daniel@transgaming.com | 20d3666 | 2012-10-31 19:51:43 +0000 | [diff] [blame] | 2801 | *format = gl::ExtractFormat(renderbuffer->getActualFormat()); |
| 2802 | *type = gl::ExtractType(renderbuffer->getActualFormat()); |
daniel@transgaming.com | 42944b0 | 2012-09-27 17:45:57 +0000 | [diff] [blame] | 2803 | |
| 2804 | return true; |
| 2805 | } |
| 2806 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2807 | void Context::detachBuffer(GLuint buffer) |
| 2808 | { |
| 2809 | // [OpenGL ES 2.0.24] section 2.9 page 22: |
| 2810 | // If a buffer object is deleted while it is bound, all bindings to that object in the current context |
| 2811 | // (i.e. in the thread that called Delete-Buffers) are reset to zero. |
| 2812 | |
| 2813 | if (mState.arrayBuffer.id() == buffer) |
| 2814 | { |
| 2815 | mState.arrayBuffer.set(NULL); |
| 2816 | } |
| 2817 | |
| 2818 | if (mState.elementArrayBuffer.id() == buffer) |
| 2819 | { |
| 2820 | mState.elementArrayBuffer.set(NULL); |
| 2821 | } |
| 2822 | |
| 2823 | for (int attribute = 0; attribute < MAX_VERTEX_ATTRIBS; attribute++) |
| 2824 | { |
| 2825 | if (mState.vertexAttribute[attribute].mBoundBuffer.id() == buffer) |
| 2826 | { |
| 2827 | mState.vertexAttribute[attribute].mBoundBuffer.set(NULL); |
| 2828 | } |
| 2829 | } |
| 2830 | } |
| 2831 | |
| 2832 | void Context::detachTexture(GLuint texture) |
| 2833 | { |
| 2834 | // [OpenGL ES 2.0.24] section 3.8 page 84: |
| 2835 | // If a texture object is deleted, it is as if all texture units which are bound to that texture object are |
| 2836 | // rebound to texture object zero |
| 2837 | |
| 2838 | for (int type = 0; type < TEXTURE_TYPE_COUNT; type++) |
| 2839 | { |
| 2840 | for (int sampler = 0; sampler < MAX_COMBINED_TEXTURE_IMAGE_UNITS_VTF; sampler++) |
| 2841 | { |
| 2842 | if (mState.samplerTexture[type][sampler].id() == texture) |
| 2843 | { |
| 2844 | mState.samplerTexture[type][sampler].set(NULL); |
| 2845 | } |
| 2846 | } |
| 2847 | } |
| 2848 | |
| 2849 | // [OpenGL ES 2.0.24] section 4.4 page 112: |
| 2850 | // If a texture object is deleted while its image is attached to the currently bound framebuffer, then it is |
| 2851 | // as if FramebufferTexture2D had been called, with a texture of 0, for each attachment point to which this |
| 2852 | // image was attached in the currently bound framebuffer. |
| 2853 | |
| 2854 | Framebuffer *readFramebuffer = getReadFramebuffer(); |
| 2855 | Framebuffer *drawFramebuffer = getDrawFramebuffer(); |
| 2856 | |
| 2857 | if (readFramebuffer) |
| 2858 | { |
| 2859 | readFramebuffer->detachTexture(texture); |
| 2860 | } |
| 2861 | |
| 2862 | if (drawFramebuffer && drawFramebuffer != readFramebuffer) |
| 2863 | { |
| 2864 | drawFramebuffer->detachTexture(texture); |
| 2865 | } |
| 2866 | } |
| 2867 | |
| 2868 | void Context::detachFramebuffer(GLuint framebuffer) |
| 2869 | { |
| 2870 | // [OpenGL ES 2.0.24] section 4.4 page 107: |
| 2871 | // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as though |
| 2872 | // BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of zero. |
| 2873 | |
| 2874 | if (mState.readFramebuffer == framebuffer) |
| 2875 | { |
| 2876 | bindReadFramebuffer(0); |
| 2877 | } |
| 2878 | |
| 2879 | if (mState.drawFramebuffer == framebuffer) |
| 2880 | { |
| 2881 | bindDrawFramebuffer(0); |
| 2882 | } |
| 2883 | } |
| 2884 | |
| 2885 | void Context::detachRenderbuffer(GLuint renderbuffer) |
| 2886 | { |
| 2887 | // [OpenGL ES 2.0.24] section 4.4 page 109: |
| 2888 | // If a renderbuffer that is currently bound to RENDERBUFFER is deleted, it is as though BindRenderbuffer |
| 2889 | // had been executed with the target RENDERBUFFER and name of zero. |
| 2890 | |
| 2891 | if (mState.renderbuffer.id() == renderbuffer) |
| 2892 | { |
| 2893 | bindRenderbuffer(0); |
| 2894 | } |
| 2895 | |
| 2896 | // [OpenGL ES 2.0.24] section 4.4 page 111: |
| 2897 | // If a renderbuffer object is deleted while its image is attached to the currently bound framebuffer, |
| 2898 | // then it is as if FramebufferRenderbuffer had been called, with a renderbuffer of 0, for each attachment |
| 2899 | // point to which this image was attached in the currently bound framebuffer. |
| 2900 | |
| 2901 | Framebuffer *readFramebuffer = getReadFramebuffer(); |
| 2902 | Framebuffer *drawFramebuffer = getDrawFramebuffer(); |
| 2903 | |
| 2904 | if (readFramebuffer) |
| 2905 | { |
| 2906 | readFramebuffer->detachRenderbuffer(renderbuffer); |
| 2907 | } |
| 2908 | |
| 2909 | if (drawFramebuffer && drawFramebuffer != readFramebuffer) |
| 2910 | { |
| 2911 | drawFramebuffer->detachRenderbuffer(renderbuffer); |
| 2912 | } |
| 2913 | } |
| 2914 | |
| 2915 | Texture *Context::getIncompleteTexture(TextureType type) |
| 2916 | { |
| 2917 | Texture *t = mIncompleteTextures[type].get(); |
| 2918 | |
| 2919 | if (t == NULL) |
| 2920 | { |
| 2921 | static const GLubyte color[] = { 0, 0, 0, 255 }; |
| 2922 | |
| 2923 | switch (type) |
| 2924 | { |
| 2925 | default: |
| 2926 | UNREACHABLE(); |
| 2927 | // default falls through to TEXTURE_2D |
| 2928 | |
| 2929 | case TEXTURE_2D: |
| 2930 | { |
daniel@transgaming.com | 370482e | 2012-11-28 19:32:13 +0000 | [diff] [blame] | 2931 | Texture2D *incomplete2d = new Texture2D(mRenderer, Texture::INCOMPLETE_TEXTURE_ID); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2932 | incomplete2d->setImage(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 2933 | t = incomplete2d; |
| 2934 | } |
| 2935 | break; |
| 2936 | |
| 2937 | case TEXTURE_CUBE: |
| 2938 | { |
daniel@transgaming.com | 370482e | 2012-11-28 19:32:13 +0000 | [diff] [blame] | 2939 | TextureCubeMap *incompleteCube = new TextureCubeMap(mRenderer, Texture::INCOMPLETE_TEXTURE_ID); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2940 | |
| 2941 | incompleteCube->setImagePosX(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 2942 | incompleteCube->setImageNegX(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 2943 | incompleteCube->setImagePosY(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 2944 | incompleteCube->setImageNegY(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 2945 | incompleteCube->setImagePosZ(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 2946 | incompleteCube->setImageNegZ(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 2947 | |
| 2948 | t = incompleteCube; |
| 2949 | } |
| 2950 | break; |
| 2951 | } |
| 2952 | |
| 2953 | mIncompleteTextures[type].set(t); |
| 2954 | } |
| 2955 | |
| 2956 | return t; |
| 2957 | } |
| 2958 | |
daniel@transgaming.com | 087e578 | 2012-09-17 21:28:47 +0000 | [diff] [blame] | 2959 | bool Context::skipDraw(GLenum drawMode) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2960 | { |
daniel@transgaming.com | 087e578 | 2012-09-17 21:28:47 +0000 | [diff] [blame] | 2961 | if (drawMode == GL_POINTS) |
| 2962 | { |
| 2963 | // ProgramBinary assumes non-point rendering if gl_PointSize isn't written, |
| 2964 | // which affects varying interpolation. Since the value of gl_PointSize is |
| 2965 | // undefined when not written, just skip drawing to avoid unexpected results. |
| 2966 | if (!getCurrentProgramBinary()->usesPointSize()) |
| 2967 | { |
| 2968 | // This is stictly speaking not an error, but developers should be |
| 2969 | // notified of risking undefined behavior. |
| 2970 | ERR("Point rendering without writing to gl_PointSize."); |
| 2971 | |
| 2972 | return true; |
| 2973 | } |
| 2974 | } |
| 2975 | else if (isTriangleMode(drawMode)) |
| 2976 | { |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 2977 | if (mState.rasterizer.cullFace && mState.rasterizer.cullMode == GL_FRONT_AND_BACK) |
daniel@transgaming.com | 087e578 | 2012-09-17 21:28:47 +0000 | [diff] [blame] | 2978 | { |
| 2979 | return true; |
| 2980 | } |
| 2981 | } |
| 2982 | |
| 2983 | return false; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | bool Context::isTriangleMode(GLenum drawMode) |
| 2987 | { |
| 2988 | switch (drawMode) |
| 2989 | { |
| 2990 | case GL_TRIANGLES: |
| 2991 | case GL_TRIANGLE_FAN: |
| 2992 | case GL_TRIANGLE_STRIP: |
| 2993 | return true; |
| 2994 | case GL_POINTS: |
| 2995 | case GL_LINES: |
| 2996 | case GL_LINE_LOOP: |
| 2997 | case GL_LINE_STRIP: |
| 2998 | return false; |
| 2999 | default: UNREACHABLE(); |
| 3000 | } |
| 3001 | |
| 3002 | return false; |
| 3003 | } |
| 3004 | |
| 3005 | void Context::setVertexAttrib(GLuint index, const GLfloat *values) |
| 3006 | { |
| 3007 | ASSERT(index < gl::MAX_VERTEX_ATTRIBS); |
| 3008 | |
| 3009 | mState.vertexAttribute[index].mCurrentValue[0] = values[0]; |
| 3010 | mState.vertexAttribute[index].mCurrentValue[1] = values[1]; |
| 3011 | mState.vertexAttribute[index].mCurrentValue[2] = values[2]; |
| 3012 | mState.vertexAttribute[index].mCurrentValue[3] = values[3]; |
| 3013 | |
| 3014 | mVertexDataManager->dirtyCurrentValue(index); |
| 3015 | } |
| 3016 | |
| 3017 | void Context::setVertexAttribDivisor(GLuint index, GLuint divisor) |
| 3018 | { |
| 3019 | ASSERT(index < gl::MAX_VERTEX_ATTRIBS); |
| 3020 | |
| 3021 | mState.vertexAttribute[index].mDivisor = divisor; |
| 3022 | } |
| 3023 | |
| 3024 | // keep list sorted in following order |
| 3025 | // OES extensions |
| 3026 | // EXT extensions |
| 3027 | // Vendor extensions |
| 3028 | void Context::initExtensionString() |
| 3029 | { |
| 3030 | mExtensionString = ""; |
| 3031 | |
| 3032 | // OES extensions |
| 3033 | if (supports32bitIndices()) |
| 3034 | { |
| 3035 | mExtensionString += "GL_OES_element_index_uint "; |
| 3036 | } |
| 3037 | |
| 3038 | mExtensionString += "GL_OES_packed_depth_stencil "; |
| 3039 | mExtensionString += "GL_OES_get_program_binary "; |
| 3040 | mExtensionString += "GL_OES_rgb8_rgba8 "; |
| 3041 | mExtensionString += "GL_OES_standard_derivatives "; |
| 3042 | |
| 3043 | if (supportsFloat16Textures()) |
| 3044 | { |
| 3045 | mExtensionString += "GL_OES_texture_half_float "; |
| 3046 | } |
| 3047 | if (supportsFloat16LinearFilter()) |
| 3048 | { |
| 3049 | mExtensionString += "GL_OES_texture_half_float_linear "; |
| 3050 | } |
| 3051 | if (supportsFloat32Textures()) |
| 3052 | { |
| 3053 | mExtensionString += "GL_OES_texture_float "; |
| 3054 | } |
| 3055 | if (supportsFloat32LinearFilter()) |
| 3056 | { |
| 3057 | mExtensionString += "GL_OES_texture_float_linear "; |
| 3058 | } |
| 3059 | |
| 3060 | if (supportsNonPower2Texture()) |
| 3061 | { |
| 3062 | mExtensionString += "GL_OES_texture_npot "; |
| 3063 | } |
| 3064 | |
| 3065 | // Multi-vendor (EXT) extensions |
| 3066 | if (supportsOcclusionQueries()) |
| 3067 | { |
| 3068 | mExtensionString += "GL_EXT_occlusion_query_boolean "; |
| 3069 | } |
| 3070 | |
| 3071 | mExtensionString += "GL_EXT_read_format_bgra "; |
| 3072 | mExtensionString += "GL_EXT_robustness "; |
| 3073 | |
| 3074 | if (supportsDXT1Textures()) |
| 3075 | { |
| 3076 | mExtensionString += "GL_EXT_texture_compression_dxt1 "; |
| 3077 | } |
| 3078 | |
daniel@transgaming.com | 07ab841 | 2012-07-12 15:17:09 +0000 | [diff] [blame] | 3079 | if (supportsTextureFilterAnisotropy()) |
| 3080 | { |
| 3081 | mExtensionString += "GL_EXT_texture_filter_anisotropic "; |
| 3082 | } |
| 3083 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3084 | mExtensionString += "GL_EXT_texture_format_BGRA8888 "; |
| 3085 | mExtensionString += "GL_EXT_texture_storage "; |
| 3086 | |
| 3087 | // ANGLE-specific extensions |
| 3088 | if (supportsDepthTextures()) |
| 3089 | { |
| 3090 | mExtensionString += "GL_ANGLE_depth_texture "; |
| 3091 | } |
| 3092 | |
| 3093 | mExtensionString += "GL_ANGLE_framebuffer_blit "; |
| 3094 | if (getMaxSupportedSamples() != 0) |
| 3095 | { |
| 3096 | mExtensionString += "GL_ANGLE_framebuffer_multisample "; |
| 3097 | } |
| 3098 | |
| 3099 | if (supportsInstancing()) |
| 3100 | { |
| 3101 | mExtensionString += "GL_ANGLE_instanced_arrays "; |
| 3102 | } |
| 3103 | |
| 3104 | mExtensionString += "GL_ANGLE_pack_reverse_row_order "; |
| 3105 | |
| 3106 | if (supportsDXT3Textures()) |
| 3107 | { |
| 3108 | mExtensionString += "GL_ANGLE_texture_compression_dxt3 "; |
| 3109 | } |
| 3110 | if (supportsDXT5Textures()) |
| 3111 | { |
| 3112 | mExtensionString += "GL_ANGLE_texture_compression_dxt5 "; |
| 3113 | } |
| 3114 | |
| 3115 | mExtensionString += "GL_ANGLE_texture_usage "; |
| 3116 | mExtensionString += "GL_ANGLE_translated_shader_source "; |
| 3117 | |
| 3118 | // Other vendor-specific extensions |
| 3119 | if (supportsEventQueries()) |
| 3120 | { |
| 3121 | mExtensionString += "GL_NV_fence "; |
| 3122 | } |
| 3123 | |
| 3124 | std::string::size_type end = mExtensionString.find_last_not_of(' '); |
| 3125 | if (end != std::string::npos) |
| 3126 | { |
| 3127 | mExtensionString.resize(end+1); |
| 3128 | } |
| 3129 | } |
| 3130 | |
| 3131 | const char *Context::getExtensionString() const |
| 3132 | { |
| 3133 | return mExtensionString.c_str(); |
| 3134 | } |
| 3135 | |
| 3136 | void Context::initRendererString() |
| 3137 | { |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3138 | mRendererString = "ANGLE ("; |
daniel@transgaming.com | 4ca789e | 2012-10-31 18:46:40 +0000 | [diff] [blame] | 3139 | mRendererString += mRenderer->getAdapterDescription(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3140 | mRendererString += ")"; |
| 3141 | } |
| 3142 | |
| 3143 | const char *Context::getRendererString() const |
| 3144 | { |
| 3145 | return mRendererString.c_str(); |
| 3146 | } |
| 3147 | |
| 3148 | void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 3149 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 3150 | GLbitfield mask) |
| 3151 | { |
| 3152 | Framebuffer *readFramebuffer = getReadFramebuffer(); |
| 3153 | Framebuffer *drawFramebuffer = getDrawFramebuffer(); |
| 3154 | |
| 3155 | if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE || |
| 3156 | !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 3157 | { |
| 3158 | return error(GL_INVALID_FRAMEBUFFER_OPERATION); |
| 3159 | } |
| 3160 | |
| 3161 | if (drawFramebuffer->getSamples() != 0) |
| 3162 | { |
| 3163 | return error(GL_INVALID_OPERATION); |
| 3164 | } |
| 3165 | |
| 3166 | int readBufferWidth = readFramebuffer->getColorbuffer()->getWidth(); |
| 3167 | int readBufferHeight = readFramebuffer->getColorbuffer()->getHeight(); |
| 3168 | int drawBufferWidth = drawFramebuffer->getColorbuffer()->getWidth(); |
| 3169 | int drawBufferHeight = drawFramebuffer->getColorbuffer()->getHeight(); |
| 3170 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3171 | Rectangle sourceRect; |
| 3172 | Rectangle destRect; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3173 | |
| 3174 | if (srcX0 < srcX1) |
| 3175 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3176 | sourceRect.x = srcX0; |
| 3177 | destRect.x = dstX0; |
| 3178 | sourceRect.width = srcX1 - srcX0; |
| 3179 | destRect.width = dstX1 - dstX0; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3180 | } |
| 3181 | else |
| 3182 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3183 | sourceRect.x = srcX1; |
| 3184 | destRect.x = dstX1; |
| 3185 | sourceRect.width = srcX0 - srcX1; |
| 3186 | destRect.width = dstX0 - dstX1; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3187 | } |
| 3188 | |
| 3189 | if (srcY0 < srcY1) |
| 3190 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3191 | sourceRect.height = srcY1 - srcY0; |
| 3192 | destRect.height = dstY1 - dstY0; |
| 3193 | sourceRect.y = srcY0; |
| 3194 | destRect.y = dstY0; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3195 | } |
| 3196 | else |
| 3197 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3198 | sourceRect.height = srcY0 - srcY1; |
| 3199 | destRect.height = dstY0 - srcY1; |
| 3200 | sourceRect.y = srcY1; |
| 3201 | destRect.y = dstY1; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3202 | } |
| 3203 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3204 | Rectangle sourceScissoredRect = sourceRect; |
| 3205 | Rectangle destScissoredRect = destRect; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3206 | |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 3207 | if (mState.rasterizer.scissorTest) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3208 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3209 | // Only write to parts of the destination framebuffer which pass the scissor test. |
| 3210 | if (destRect.x < mState.scissor.x) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3211 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3212 | int xDiff = mState.scissor.x - destRect.x; |
| 3213 | destScissoredRect.x = mState.scissor.x; |
| 3214 | destScissoredRect.width -= xDiff; |
| 3215 | sourceScissoredRect.x += xDiff; |
| 3216 | sourceScissoredRect.width -= xDiff; |
| 3217 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3218 | } |
| 3219 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3220 | if (destRect.x + destRect.width > mState.scissor.x + mState.scissor.width) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3221 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3222 | int xDiff = (destRect.x + destRect.width) - (mState.scissor.x + mState.scissor.width); |
| 3223 | destScissoredRect.width -= xDiff; |
| 3224 | sourceScissoredRect.width -= xDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3225 | } |
| 3226 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3227 | if (destRect.y < mState.scissor.y) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3228 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3229 | int yDiff = mState.scissor.y - destRect.y; |
| 3230 | destScissoredRect.y = mState.scissor.y; |
| 3231 | destScissoredRect.height -= yDiff; |
| 3232 | sourceScissoredRect.y += yDiff; |
| 3233 | sourceScissoredRect.height -= yDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3234 | } |
| 3235 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3236 | if (destRect.y + destRect.height > mState.scissor.y + mState.scissor.height) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3237 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3238 | int yDiff = (destRect.y + destRect.height) - (mState.scissor.y + mState.scissor.height); |
| 3239 | destScissoredRect.height -= yDiff; |
| 3240 | sourceScissoredRect.height -= yDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3241 | } |
| 3242 | } |
| 3243 | |
| 3244 | bool blitRenderTarget = false; |
| 3245 | bool blitDepthStencil = false; |
| 3246 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3247 | Rectangle sourceTrimmedRect = sourceScissoredRect; |
| 3248 | Rectangle destTrimmedRect = destScissoredRect; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3249 | |
| 3250 | // The source & destination rectangles also may need to be trimmed if they fall out of the bounds of |
| 3251 | // the actual draw and read surfaces. |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3252 | if (sourceTrimmedRect.x < 0) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3253 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3254 | int xDiff = 0 - sourceTrimmedRect.x; |
| 3255 | sourceTrimmedRect.x = 0; |
| 3256 | sourceTrimmedRect.width -= xDiff; |
| 3257 | destTrimmedRect.x += xDiff; |
| 3258 | destTrimmedRect.width -= xDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3259 | } |
| 3260 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3261 | if (sourceTrimmedRect.x + sourceTrimmedRect.width > readBufferWidth) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3262 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3263 | int xDiff = (sourceTrimmedRect.x + sourceTrimmedRect.width) - readBufferWidth; |
| 3264 | sourceTrimmedRect.width -= xDiff; |
| 3265 | destTrimmedRect.width -= xDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3266 | } |
| 3267 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3268 | if (sourceTrimmedRect.y < 0) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3269 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3270 | int yDiff = 0 - sourceTrimmedRect.y; |
| 3271 | sourceTrimmedRect.y = 0; |
| 3272 | sourceTrimmedRect.height -= yDiff; |
| 3273 | destTrimmedRect.y += yDiff; |
| 3274 | destTrimmedRect.height -= yDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3275 | } |
| 3276 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3277 | if (sourceTrimmedRect.y + sourceTrimmedRect.height > readBufferHeight) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3278 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3279 | int yDiff = (sourceTrimmedRect.y + sourceTrimmedRect.height) - readBufferHeight; |
| 3280 | sourceTrimmedRect.height -= yDiff; |
| 3281 | destTrimmedRect.height -= yDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3282 | } |
| 3283 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3284 | if (destTrimmedRect.x < 0) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3285 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3286 | int xDiff = 0 - destTrimmedRect.x; |
| 3287 | destTrimmedRect.x = 0; |
| 3288 | destTrimmedRect.width -= xDiff; |
| 3289 | sourceTrimmedRect.x += xDiff; |
| 3290 | sourceTrimmedRect.width -= xDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3291 | } |
| 3292 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3293 | if (destTrimmedRect.x + destTrimmedRect.width > drawBufferWidth) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3294 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3295 | int xDiff = (destTrimmedRect.x + destTrimmedRect.width) - drawBufferWidth; |
| 3296 | destTrimmedRect.width -= xDiff; |
| 3297 | sourceTrimmedRect.width -= xDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3298 | } |
| 3299 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3300 | if (destTrimmedRect.y < 0) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3301 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3302 | int yDiff = 0 - destTrimmedRect.y; |
| 3303 | destTrimmedRect.y = 0; |
| 3304 | destTrimmedRect.height -= yDiff; |
| 3305 | sourceTrimmedRect.y += yDiff; |
| 3306 | sourceTrimmedRect.height -= yDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3307 | } |
| 3308 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3309 | if (destTrimmedRect.y + destTrimmedRect.height > drawBufferHeight) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3310 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3311 | int yDiff = (destTrimmedRect.y + destTrimmedRect.height) - drawBufferHeight; |
| 3312 | destTrimmedRect.height -= yDiff; |
| 3313 | sourceTrimmedRect.height -= yDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3314 | } |
| 3315 | |
| 3316 | bool partialBufferCopy = false; |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 3317 | if (sourceTrimmedRect.height < readBufferHeight || |
| 3318 | sourceTrimmedRect.width < readBufferWidth || |
| 3319 | destTrimmedRect.height < drawBufferHeight || |
| 3320 | destTrimmedRect.width < drawBufferWidth || |
| 3321 | sourceTrimmedRect.y != 0 || destTrimmedRect.y != 0 || sourceTrimmedRect.x != 0 || destTrimmedRect.x != 0) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3322 | { |
| 3323 | partialBufferCopy = true; |
| 3324 | } |
| 3325 | |
| 3326 | if (mask & GL_COLOR_BUFFER_BIT) |
| 3327 | { |
| 3328 | const bool validReadType = readFramebuffer->getColorbufferType() == GL_TEXTURE_2D || |
| 3329 | readFramebuffer->getColorbufferType() == GL_RENDERBUFFER; |
| 3330 | const bool validDrawType = drawFramebuffer->getColorbufferType() == GL_TEXTURE_2D || |
| 3331 | drawFramebuffer->getColorbufferType() == GL_RENDERBUFFER; |
| 3332 | if (!validReadType || !validDrawType || |
daniel@transgaming.com | 20d3666 | 2012-10-31 19:51:43 +0000 | [diff] [blame] | 3333 | readFramebuffer->getColorbuffer()->getActualFormat() != drawFramebuffer->getColorbuffer()->getActualFormat()) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3334 | { |
| 3335 | ERR("Color buffer format conversion in BlitFramebufferANGLE not supported by this implementation"); |
| 3336 | return error(GL_INVALID_OPERATION); |
| 3337 | } |
| 3338 | |
| 3339 | if (partialBufferCopy && readFramebuffer->getSamples() != 0) |
| 3340 | { |
| 3341 | return error(GL_INVALID_OPERATION); |
| 3342 | } |
| 3343 | |
| 3344 | blitRenderTarget = true; |
| 3345 | |
| 3346 | } |
| 3347 | |
| 3348 | if (mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) |
| 3349 | { |
| 3350 | Renderbuffer *readDSBuffer = NULL; |
| 3351 | Renderbuffer *drawDSBuffer = NULL; |
| 3352 | |
| 3353 | // We support OES_packed_depth_stencil, and do not support a separately attached depth and stencil buffer, so if we have |
| 3354 | // both a depth and stencil buffer, it will be the same buffer. |
| 3355 | |
| 3356 | if (mask & GL_DEPTH_BUFFER_BIT) |
| 3357 | { |
| 3358 | if (readFramebuffer->getDepthbuffer() && drawFramebuffer->getDepthbuffer()) |
| 3359 | { |
| 3360 | if (readFramebuffer->getDepthbufferType() != drawFramebuffer->getDepthbufferType() || |
daniel@transgaming.com | 20d3666 | 2012-10-31 19:51:43 +0000 | [diff] [blame] | 3361 | readFramebuffer->getDepthbuffer()->getActualFormat() != drawFramebuffer->getDepthbuffer()->getActualFormat()) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3362 | { |
| 3363 | return error(GL_INVALID_OPERATION); |
| 3364 | } |
| 3365 | |
| 3366 | blitDepthStencil = true; |
| 3367 | readDSBuffer = readFramebuffer->getDepthbuffer(); |
| 3368 | drawDSBuffer = drawFramebuffer->getDepthbuffer(); |
| 3369 | } |
| 3370 | } |
| 3371 | |
| 3372 | if (mask & GL_STENCIL_BUFFER_BIT) |
| 3373 | { |
| 3374 | if (readFramebuffer->getStencilbuffer() && drawFramebuffer->getStencilbuffer()) |
| 3375 | { |
| 3376 | if (readFramebuffer->getStencilbufferType() != drawFramebuffer->getStencilbufferType() || |
daniel@transgaming.com | 20d3666 | 2012-10-31 19:51:43 +0000 | [diff] [blame] | 3377 | readFramebuffer->getStencilbuffer()->getActualFormat() != drawFramebuffer->getStencilbuffer()->getActualFormat()) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3378 | { |
| 3379 | return error(GL_INVALID_OPERATION); |
| 3380 | } |
| 3381 | |
| 3382 | blitDepthStencil = true; |
| 3383 | readDSBuffer = readFramebuffer->getStencilbuffer(); |
| 3384 | drawDSBuffer = drawFramebuffer->getStencilbuffer(); |
| 3385 | } |
| 3386 | } |
| 3387 | |
| 3388 | if (partialBufferCopy) |
| 3389 | { |
| 3390 | ERR("Only whole-buffer depth and stencil blits are supported by this implementation."); |
| 3391 | return error(GL_INVALID_OPERATION); // only whole-buffer copies are permitted |
| 3392 | } |
| 3393 | |
| 3394 | if ((drawDSBuffer && drawDSBuffer->getSamples() != 0) || |
| 3395 | (readDSBuffer && readDSBuffer->getSamples() != 0)) |
| 3396 | { |
| 3397 | return error(GL_INVALID_OPERATION); |
| 3398 | } |
| 3399 | } |
| 3400 | |
| 3401 | if (blitRenderTarget || blitDepthStencil) |
| 3402 | { |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 3403 | mRenderer->blitRect(readFramebuffer, &sourceTrimmedRect, drawFramebuffer, &destTrimmedRect, blitRenderTarget, blitDepthStencil); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3404 | } |
| 3405 | } |
| 3406 | |
| 3407 | VertexDeclarationCache::VertexDeclarationCache() : mMaxLru(0) |
| 3408 | { |
| 3409 | for (int i = 0; i < NUM_VERTEX_DECL_CACHE_ENTRIES; i++) |
| 3410 | { |
| 3411 | mVertexDeclCache[i].vertexDeclaration = NULL; |
| 3412 | mVertexDeclCache[i].lruCount = 0; |
| 3413 | } |
| 3414 | } |
| 3415 | |
| 3416 | VertexDeclarationCache::~VertexDeclarationCache() |
| 3417 | { |
| 3418 | for (int i = 0; i < NUM_VERTEX_DECL_CACHE_ENTRIES; i++) |
| 3419 | { |
| 3420 | if (mVertexDeclCache[i].vertexDeclaration) |
| 3421 | { |
| 3422 | mVertexDeclCache[i].vertexDeclaration->Release(); |
| 3423 | } |
| 3424 | } |
| 3425 | } |
| 3426 | |
daniel@transgaming.com | 5ae3ccc | 2012-07-24 18:29:38 +0000 | [diff] [blame] | 3427 | GLenum VertexDeclarationCache::applyDeclaration(IDirect3DDevice9 *device, TranslatedAttribute attributes[], ProgramBinary *programBinary, GLsizei instances, GLsizei *repeatDraw) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3428 | { |
| 3429 | *repeatDraw = 1; |
| 3430 | |
| 3431 | int indexedAttribute = MAX_VERTEX_ATTRIBS; |
| 3432 | int instancedAttribute = MAX_VERTEX_ATTRIBS; |
| 3433 | |
| 3434 | if (instances > 0) |
| 3435 | { |
| 3436 | // Find an indexed attribute to be mapped to D3D stream 0 |
| 3437 | for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++) |
| 3438 | { |
| 3439 | if (attributes[i].active) |
| 3440 | { |
| 3441 | if (indexedAttribute == MAX_VERTEX_ATTRIBS) |
| 3442 | { |
| 3443 | if (attributes[i].divisor == 0) |
| 3444 | { |
| 3445 | indexedAttribute = i; |
| 3446 | } |
| 3447 | } |
| 3448 | else if (instancedAttribute == MAX_VERTEX_ATTRIBS) |
| 3449 | { |
| 3450 | if (attributes[i].divisor != 0) |
| 3451 | { |
| 3452 | instancedAttribute = i; |
| 3453 | } |
| 3454 | } |
| 3455 | else break; // Found both an indexed and instanced attribute |
| 3456 | } |
| 3457 | } |
| 3458 | |
| 3459 | if (indexedAttribute == MAX_VERTEX_ATTRIBS) |
| 3460 | { |
| 3461 | return GL_INVALID_OPERATION; |
| 3462 | } |
| 3463 | } |
| 3464 | |
| 3465 | D3DVERTEXELEMENT9 elements[MAX_VERTEX_ATTRIBS + 1]; |
| 3466 | D3DVERTEXELEMENT9 *element = &elements[0]; |
| 3467 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3468 | for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++) |
| 3469 | { |
| 3470 | if (attributes[i].active) |
| 3471 | { |
| 3472 | int stream = i; |
| 3473 | |
| 3474 | if (instances > 0) |
| 3475 | { |
| 3476 | // Due to a bug on ATI cards we can't enable instancing when none of the attributes are instanced. |
| 3477 | if (instancedAttribute == MAX_VERTEX_ATTRIBS) |
| 3478 | { |
| 3479 | *repeatDraw = instances; |
| 3480 | } |
| 3481 | else |
| 3482 | { |
| 3483 | if (i == indexedAttribute) |
| 3484 | { |
| 3485 | stream = 0; |
| 3486 | } |
| 3487 | else if (i == 0) |
| 3488 | { |
| 3489 | stream = indexedAttribute; |
| 3490 | } |
| 3491 | |
| 3492 | UINT frequency = 1; |
| 3493 | |
| 3494 | if (attributes[i].divisor == 0) |
| 3495 | { |
| 3496 | frequency = D3DSTREAMSOURCE_INDEXEDDATA | instances; |
| 3497 | } |
| 3498 | else |
| 3499 | { |
| 3500 | frequency = D3DSTREAMSOURCE_INSTANCEDATA | attributes[i].divisor; |
| 3501 | } |
| 3502 | |
| 3503 | device->SetStreamSourceFreq(stream, frequency); |
| 3504 | mInstancingEnabled = true; |
| 3505 | } |
| 3506 | } |
| 3507 | |
| 3508 | if (mAppliedVBs[stream].serial != attributes[i].serial || |
| 3509 | mAppliedVBs[stream].stride != attributes[i].stride || |
| 3510 | mAppliedVBs[stream].offset != attributes[i].offset) |
| 3511 | { |
| 3512 | device->SetStreamSource(stream, attributes[i].vertexBuffer, attributes[i].offset, attributes[i].stride); |
| 3513 | mAppliedVBs[stream].serial = attributes[i].serial; |
| 3514 | mAppliedVBs[stream].stride = attributes[i].stride; |
| 3515 | mAppliedVBs[stream].offset = attributes[i].offset; |
| 3516 | } |
| 3517 | |
| 3518 | element->Stream = stream; |
| 3519 | element->Offset = 0; |
| 3520 | element->Type = attributes[i].type; |
| 3521 | element->Method = D3DDECLMETHOD_DEFAULT; |
| 3522 | element->Usage = D3DDECLUSAGE_TEXCOORD; |
| 3523 | element->UsageIndex = programBinary->getSemanticIndex(i); |
| 3524 | element++; |
| 3525 | } |
| 3526 | } |
| 3527 | |
| 3528 | if (instances == 0 || instancedAttribute == MAX_VERTEX_ATTRIBS) |
| 3529 | { |
| 3530 | if (mInstancingEnabled) |
| 3531 | { |
| 3532 | for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++) |
| 3533 | { |
| 3534 | device->SetStreamSourceFreq(i, 1); |
| 3535 | } |
| 3536 | |
| 3537 | mInstancingEnabled = false; |
| 3538 | } |
| 3539 | } |
| 3540 | |
| 3541 | static const D3DVERTEXELEMENT9 end = D3DDECL_END(); |
| 3542 | *(element++) = end; |
| 3543 | |
| 3544 | for (int i = 0; i < NUM_VERTEX_DECL_CACHE_ENTRIES; i++) |
| 3545 | { |
| 3546 | VertexDeclCacheEntry *entry = &mVertexDeclCache[i]; |
| 3547 | if (memcmp(entry->cachedElements, elements, (element - elements) * sizeof(D3DVERTEXELEMENT9)) == 0 && entry->vertexDeclaration) |
| 3548 | { |
| 3549 | entry->lruCount = ++mMaxLru; |
| 3550 | if(entry->vertexDeclaration != mLastSetVDecl) |
| 3551 | { |
| 3552 | device->SetVertexDeclaration(entry->vertexDeclaration); |
| 3553 | mLastSetVDecl = entry->vertexDeclaration; |
| 3554 | } |
| 3555 | |
| 3556 | return GL_NO_ERROR; |
| 3557 | } |
| 3558 | } |
| 3559 | |
| 3560 | VertexDeclCacheEntry *lastCache = mVertexDeclCache; |
| 3561 | |
| 3562 | for (int i = 0; i < NUM_VERTEX_DECL_CACHE_ENTRIES; i++) |
| 3563 | { |
| 3564 | if (mVertexDeclCache[i].lruCount < lastCache->lruCount) |
| 3565 | { |
| 3566 | lastCache = &mVertexDeclCache[i]; |
| 3567 | } |
| 3568 | } |
| 3569 | |
| 3570 | if (lastCache->vertexDeclaration != NULL) |
| 3571 | { |
| 3572 | lastCache->vertexDeclaration->Release(); |
| 3573 | lastCache->vertexDeclaration = NULL; |
| 3574 | // mLastSetVDecl is set to the replacement, so we don't have to worry |
| 3575 | // about it. |
| 3576 | } |
| 3577 | |
| 3578 | memcpy(lastCache->cachedElements, elements, (element - elements) * sizeof(D3DVERTEXELEMENT9)); |
| 3579 | device->CreateVertexDeclaration(elements, &lastCache->vertexDeclaration); |
| 3580 | device->SetVertexDeclaration(lastCache->vertexDeclaration); |
| 3581 | mLastSetVDecl = lastCache->vertexDeclaration; |
| 3582 | lastCache->lruCount = ++mMaxLru; |
| 3583 | |
| 3584 | return GL_NO_ERROR; |
| 3585 | } |
| 3586 | |
| 3587 | void VertexDeclarationCache::markStateDirty() |
| 3588 | { |
| 3589 | for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++) |
| 3590 | { |
| 3591 | mAppliedVBs[i].serial = 0; |
| 3592 | } |
| 3593 | |
| 3594 | mLastSetVDecl = NULL; |
| 3595 | mInstancingEnabled = true; // Forces it to be disabled when not used |
| 3596 | } |
| 3597 | |
| 3598 | } |
| 3599 | |
| 3600 | extern "C" |
| 3601 | { |
daniel@transgaming.com | 03d3909 | 2012-11-28 19:31:59 +0000 | [diff] [blame] | 3602 | gl::Context *glCreateContext(const gl::Context *shareContext, rx::Renderer *renderer, bool notifyResets, bool robustAccess) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3603 | { |
daniel@transgaming.com | 03d3909 | 2012-11-28 19:31:59 +0000 | [diff] [blame] | 3604 | return new gl::Context(shareContext, renderer, notifyResets, robustAccess); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3605 | } |
| 3606 | |
| 3607 | void glDestroyContext(gl::Context *context) |
| 3608 | { |
| 3609 | delete context; |
| 3610 | |
| 3611 | if (context == gl::getContext()) |
| 3612 | { |
| 3613 | gl::makeCurrent(NULL, NULL, NULL); |
| 3614 | } |
| 3615 | } |
| 3616 | |
| 3617 | void glMakeCurrent(gl::Context *context, egl::Display *display, egl::Surface *surface) |
| 3618 | { |
| 3619 | gl::makeCurrent(context, display, surface); |
| 3620 | } |
| 3621 | |
| 3622 | gl::Context *glGetCurrentContext() |
| 3623 | { |
| 3624 | return gl::getContext(); |
| 3625 | } |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 3626 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3627 | } |