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