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 | e06bda9 | 2012-11-28 19:42:18 +0000 | [diff] [blame] | 1718 | // storing the mRenderTargetDesc in Context will be removed once refactoring |
| 1719 | // of clear is complete |
| 1720 | // D3D9_REPLACE start |
| 1721 | gl::Renderbuffer *renderbufferObject = NULL; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1722 | if (framebufferObject->getColorbufferType() != GL_NONE) |
| 1723 | { |
| 1724 | renderbufferObject = framebufferObject->getColorbuffer(); |
| 1725 | } |
| 1726 | else |
| 1727 | { |
| 1728 | renderbufferObject = framebufferObject->getNullColorbuffer(); |
| 1729 | } |
| 1730 | if (!renderbufferObject) |
| 1731 | { |
| 1732 | ERR("unable to locate renderbuffer for FBO."); |
| 1733 | return false; |
| 1734 | } |
| 1735 | |
daniel@transgaming.com | e06bda9 | 2012-11-28 19:42:18 +0000 | [diff] [blame] | 1736 | mRenderTargetDesc.width = renderbufferObject->getWidth(); |
| 1737 | mRenderTargetDesc.height = renderbufferObject->getHeight(); |
| 1738 | mRenderTargetDesc.format = renderbufferObject->getActualFormat(); |
| 1739 | // D3D9_REPLACE end |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1740 | |
daniel@transgaming.com | 3ca082c | 2012-11-28 19:41:07 +0000 | [diff] [blame] | 1741 | Rectangle viewport = mState.viewport; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1742 | float zNear = clamp01(mState.zNear); |
| 1743 | float zFar = clamp01(mState.zFar); |
| 1744 | |
| 1745 | if (ignoreViewport) |
| 1746 | { |
daniel@transgaming.com | 3ca082c | 2012-11-28 19:41:07 +0000 | [diff] [blame] | 1747 | viewport.x = 0; |
| 1748 | viewport.y = 0; |
| 1749 | viewport.width = mRenderTargetDesc.width; |
| 1750 | viewport.height = mRenderTargetDesc.height; |
| 1751 | zNear = 0.0f; |
| 1752 | zFar = 1.0f; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1753 | } |
| 1754 | |
daniel@transgaming.com | 3ca082c | 2012-11-28 19:41:07 +0000 | [diff] [blame] | 1755 | ProgramBinary *programBinary = mState.currentProgram ? getCurrentProgramBinary() : NULL; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1756 | |
daniel@transgaming.com | e2f7b6b | 2012-11-28 21:00:51 +0000 | [diff] [blame] | 1757 | if (!mRenderer->setViewport(viewport, zNear, zFar, programBinary, mDxUniformsDirty)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1758 | { |
daniel@transgaming.com | 3ca082c | 2012-11-28 19:41:07 +0000 | [diff] [blame] | 1759 | return false; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1760 | } |
daniel@transgaming.com | 3ca082c | 2012-11-28 19:41:07 +0000 | [diff] [blame] | 1761 | mDxUniformsDirty = false; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1762 | |
daniel@transgaming.com | 04f1b33 | 2012-11-28 21:00:40 +0000 | [diff] [blame] | 1763 | mRenderer->setScissorRectangle(mState.scissor); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1764 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1765 | return true; |
| 1766 | } |
| 1767 | |
| 1768 | // Applies the fixed-function state (culling, depth test, alpha blending, stenciling, etc) to the Direct3D 9 device |
| 1769 | void Context::applyState(GLenum drawMode) |
| 1770 | { |
daniel@transgaming.com | 62a2846 | 2012-07-24 18:33:59 +0000 | [diff] [blame] | 1771 | ProgramBinary *programBinary = getCurrentProgramBinary(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1772 | |
| 1773 | Framebuffer *framebufferObject = getDrawFramebuffer(); |
| 1774 | |
| 1775 | GLint frontCCW = programBinary->getDxFrontCCWLocation(); |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 1776 | GLint ccw = (mState.rasterizer.frontFace == GL_CCW); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1777 | programBinary->setUniform1iv(frontCCW, 1, &ccw); |
| 1778 | |
| 1779 | GLint pointsOrLines = programBinary->getDxPointsOrLinesLocation(); |
| 1780 | GLint alwaysFront = !isTriangleMode(drawMode); |
| 1781 | programBinary->setUniform1iv(pointsOrLines, 1, &alwaysFront); |
| 1782 | |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 1783 | mRenderer->setRasterizerState(mState.rasterizer); |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1784 | |
| 1785 | unsigned int mask = 0; |
| 1786 | if (mState.sampleCoverage) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1787 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1788 | if (mState.sampleCoverageValue != 0) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1789 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1790 | float threshold = 0.5f; |
| 1791 | |
| 1792 | for (int i = 0; i < framebufferObject->getSamples(); ++i) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1793 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1794 | mask <<= 1; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1795 | |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1796 | if ((i + 1) * mState.sampleCoverageValue >= threshold) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1797 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1798 | threshold += 1.0f; |
| 1799 | mask |= 1; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1800 | } |
| 1801 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1802 | } |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1803 | |
| 1804 | if (mState.sampleCoverageInvert) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1805 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1806 | mask = ~mask; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1807 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1808 | } |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1809 | else |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1810 | { |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1811 | mask = 0xFFFFFFFF; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1812 | } |
daniel@transgaming.com | 2e25864 | 2012-11-28 19:36:18 +0000 | [diff] [blame] | 1813 | mRenderer->setBlendState(mState.blend, mState.blendColor, mask); |
| 1814 | |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 1815 | mRenderer->setDepthStencilState(mState.depthStencil, mState.stencilRef, mState.stencilBackRef, |
daniel@transgaming.com | 3a0ef48 | 2012-11-28 21:01:20 +0000 | [diff] [blame^] | 1816 | mState.rasterizer.frontFace == GL_CCW); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1817 | } |
| 1818 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1819 | // Applies the shaders and shader constants to the Direct3D 9 device |
| 1820 | void Context::applyShaders() |
| 1821 | { |
daniel@transgaming.com | 62a2846 | 2012-07-24 18:33:59 +0000 | [diff] [blame] | 1822 | ProgramBinary *programBinary = getCurrentProgramBinary(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1823 | |
daniel@transgaming.com | e6af4f9 | 2012-07-24 18:31:31 +0000 | [diff] [blame] | 1824 | if (programBinary->getSerial() != mAppliedProgramBinarySerial) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1825 | { |
daniel@transgaming.com | 5fbf177 | 2012-11-28 20:54:43 +0000 | [diff] [blame] | 1826 | mRenderer->applyShaders(programBinary); |
daniel@transgaming.com | e6af4f9 | 2012-07-24 18:31:31 +0000 | [diff] [blame] | 1827 | mAppliedProgramBinarySerial = programBinary->getSerial(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1828 | } |
daniel@transgaming.com | 5fbf177 | 2012-11-28 20:54:43 +0000 | [diff] [blame] | 1829 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1830 | programBinary->applyUniforms(); |
| 1831 | } |
| 1832 | |
| 1833 | // Applies the textures and sampler states to the Direct3D 9 device |
| 1834 | void Context::applyTextures() |
| 1835 | { |
| 1836 | applyTextures(SAMPLER_PIXEL); |
| 1837 | |
| 1838 | if (mSupportsVertexTexture) |
| 1839 | { |
| 1840 | applyTextures(SAMPLER_VERTEX); |
| 1841 | } |
| 1842 | } |
| 1843 | |
| 1844 | // For each Direct3D 9 sampler of either the pixel or vertex stage, |
| 1845 | // looks up the corresponding OpenGL texture image unit and texture type, |
| 1846 | // and sets the texture and its addressing/filtering state (or NULL when inactive). |
| 1847 | void Context::applyTextures(SamplerType type) |
| 1848 | { |
daniel@transgaming.com | 62a2846 | 2012-07-24 18:33:59 +0000 | [diff] [blame] | 1849 | ProgramBinary *programBinary = getCurrentProgramBinary(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1850 | |
| 1851 | int samplerCount = (type == SAMPLER_PIXEL) ? MAX_TEXTURE_IMAGE_UNITS : MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; // Range of Direct3D 9 samplers of given sampler type |
| 1852 | unsigned int *appliedTextureSerial = (type == SAMPLER_PIXEL) ? mAppliedTextureSerialPS : mAppliedTextureSerialVS; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1853 | int samplerRange = programBinary->getUsedSamplerRange(type); |
| 1854 | |
| 1855 | for (int samplerIndex = 0; samplerIndex < samplerRange; samplerIndex++) |
| 1856 | { |
| 1857 | int textureUnit = programBinary->getSamplerMapping(type, samplerIndex); // OpenGL texture image unit index |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1858 | |
| 1859 | if (textureUnit != -1) |
| 1860 | { |
| 1861 | TextureType textureType = programBinary->getSamplerTextureType(type, samplerIndex); |
| 1862 | |
| 1863 | Texture *texture = getSamplerTexture(textureUnit, textureType); |
| 1864 | unsigned int texSerial = texture->getTextureSerial(); |
| 1865 | |
| 1866 | if (appliedTextureSerial[samplerIndex] != texSerial || texture->hasDirtyParameters() || texture->hasDirtyImages()) |
| 1867 | { |
daniel@transgaming.com | a734f27 | 2012-10-31 18:07:48 +0000 | [diff] [blame] | 1868 | if (texture->isSamplerComplete()) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1869 | { |
| 1870 | if (appliedTextureSerial[samplerIndex] != texSerial || texture->hasDirtyParameters()) |
| 1871 | { |
daniel@transgaming.com | ebf139f | 2012-10-31 18:07:32 +0000 | [diff] [blame] | 1872 | SamplerState samplerState; |
| 1873 | texture->getSamplerState(&samplerState); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1874 | |
daniel@transgaming.com | ba0570e | 2012-10-31 18:07:39 +0000 | [diff] [blame] | 1875 | mRenderer->setSamplerState(type, samplerIndex, samplerState); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | if (appliedTextureSerial[samplerIndex] != texSerial || texture->hasDirtyImages()) |
| 1879 | { |
daniel@transgaming.com | a734f27 | 2012-10-31 18:07:48 +0000 | [diff] [blame] | 1880 | mRenderer->setTexture(type, samplerIndex, texture); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1881 | } |
| 1882 | } |
| 1883 | else |
| 1884 | { |
daniel@transgaming.com | a734f27 | 2012-10-31 18:07:48 +0000 | [diff] [blame] | 1885 | mRenderer->setTexture(type, samplerIndex, getIncompleteTexture(textureType)); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | appliedTextureSerial[samplerIndex] = texSerial; |
| 1889 | texture->resetDirty(); |
| 1890 | } |
| 1891 | } |
| 1892 | else |
| 1893 | { |
| 1894 | if (appliedTextureSerial[samplerIndex] != 0) |
| 1895 | { |
daniel@transgaming.com | a734f27 | 2012-10-31 18:07:48 +0000 | [diff] [blame] | 1896 | mRenderer->setTexture(type, samplerIndex, NULL); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1897 | appliedTextureSerial[samplerIndex] = 0; |
| 1898 | } |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | for (int samplerIndex = samplerRange; samplerIndex < samplerCount; samplerIndex++) |
| 1903 | { |
| 1904 | if (appliedTextureSerial[samplerIndex] != 0) |
| 1905 | { |
daniel@transgaming.com | a734f27 | 2012-10-31 18:07:48 +0000 | [diff] [blame] | 1906 | mRenderer->setTexture(type, samplerIndex, NULL); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1907 | appliedTextureSerial[samplerIndex] = 0; |
| 1908 | } |
| 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, |
| 1913 | GLenum format, GLenum type, GLsizei *bufSize, void* pixels) |
| 1914 | { |
| 1915 | Framebuffer *framebuffer = getReadFramebuffer(); |
| 1916 | |
| 1917 | if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 1918 | { |
| 1919 | return error(GL_INVALID_FRAMEBUFFER_OPERATION); |
| 1920 | } |
| 1921 | |
| 1922 | if (getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0) |
| 1923 | { |
| 1924 | return error(GL_INVALID_OPERATION); |
| 1925 | } |
| 1926 | |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 1927 | GLsizei outputPitch = ComputePitch(width, ConvertSizedInternalFormat(format, type), getPackAlignment()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1928 | // sized query sanity check |
| 1929 | if (bufSize) |
| 1930 | { |
| 1931 | int requiredSize = outputPitch * height; |
| 1932 | if (requiredSize > *bufSize) |
| 1933 | { |
| 1934 | return error(GL_INVALID_OPERATION); |
| 1935 | } |
| 1936 | } |
| 1937 | |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 1938 | 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] | 1939 | } |
| 1940 | |
| 1941 | void Context::clear(GLbitfield mask) |
| 1942 | { |
| 1943 | Framebuffer *framebufferObject = getDrawFramebuffer(); |
| 1944 | |
| 1945 | if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 1946 | { |
| 1947 | return error(GL_INVALID_FRAMEBUFFER_OPERATION); |
| 1948 | } |
| 1949 | |
| 1950 | DWORD flags = 0; |
daniel@transgaming.com | 084a257 | 2012-11-28 20:55:17 +0000 | [diff] [blame] | 1951 | GLbitfield finalMask = 0; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1952 | |
| 1953 | if (mask & GL_COLOR_BUFFER_BIT) |
| 1954 | { |
| 1955 | mask &= ~GL_COLOR_BUFFER_BIT; |
| 1956 | |
| 1957 | if (framebufferObject->getColorbufferType() != GL_NONE) |
| 1958 | { |
daniel@transgaming.com | 084a257 | 2012-11-28 20:55:17 +0000 | [diff] [blame] | 1959 | finalMask |= GL_COLOR_BUFFER_BIT; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1960 | } |
| 1961 | } |
| 1962 | |
| 1963 | if (mask & GL_DEPTH_BUFFER_BIT) |
| 1964 | { |
| 1965 | mask &= ~GL_DEPTH_BUFFER_BIT; |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 1966 | if (mState.depthStencil.depthMask && framebufferObject->getDepthbufferType() != GL_NONE) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1967 | { |
daniel@transgaming.com | 084a257 | 2012-11-28 20:55:17 +0000 | [diff] [blame] | 1968 | finalMask |= GL_DEPTH_BUFFER_BIT; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1969 | } |
| 1970 | } |
| 1971 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1972 | if (mask & GL_STENCIL_BUFFER_BIT) |
| 1973 | { |
| 1974 | mask &= ~GL_STENCIL_BUFFER_BIT; |
| 1975 | if (framebufferObject->getStencilbufferType() != GL_NONE) |
| 1976 | { |
daniel@transgaming.com | d62d714 | 2012-11-28 19:40:28 +0000 | [diff] [blame] | 1977 | rx::RenderTarget *depthStencil = framebufferObject->getStencilbuffer()->getDepthStencil(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1978 | if (!depthStencil) |
| 1979 | { |
| 1980 | ERR("Depth stencil pointer unexpectedly null."); |
| 1981 | return; |
| 1982 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1983 | |
daniel@transgaming.com | 2c1d0ab | 2012-11-28 20:55:42 +0000 | [diff] [blame] | 1984 | if (GetStencilSize(depthStencil->getActualFormat()) > 0) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1985 | { |
daniel@transgaming.com | 084a257 | 2012-11-28 20:55:17 +0000 | [diff] [blame] | 1986 | finalMask |= GL_STENCIL_BUFFER_BIT; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1987 | } |
| 1988 | } |
| 1989 | } |
| 1990 | |
| 1991 | if (mask != 0) |
| 1992 | { |
| 1993 | return error(GL_INVALID_VALUE); |
| 1994 | } |
| 1995 | |
| 1996 | if (!applyRenderTarget(true)) // Clips the clear to the scissor rectangle but not the viewport |
| 1997 | { |
| 1998 | return; |
| 1999 | } |
| 2000 | |
daniel@transgaming.com | 084a257 | 2012-11-28 20:55:17 +0000 | [diff] [blame] | 2001 | ClearParameters clearParams; |
| 2002 | clearParams.mask = finalMask; |
| 2003 | clearParams.colorClearValue = mState.colorClearValue; |
| 2004 | clearParams.colorMaskRed = mState.blend.colorMaskRed; |
| 2005 | clearParams.colorMaskGreen = mState.blend.colorMaskGreen; |
| 2006 | clearParams.colorMaskBlue = mState.blend.colorMaskBlue; |
| 2007 | clearParams.colorMaskAlpha = mState.blend.colorMaskAlpha; |
| 2008 | clearParams.depthClearValue = mState.depthClearValue; |
| 2009 | clearParams.stencilClearValue = mState.stencilClearValue; |
| 2010 | clearParams.stencilWriteMask = mState.depthStencil.stencilWritemask; |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 2011 | |
daniel@transgaming.com | 084a257 | 2012-11-28 20:55:17 +0000 | [diff] [blame] | 2012 | mRenderer->clear(clearParams, framebufferObject); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instances) |
| 2016 | { |
| 2017 | if (!mState.currentProgram) |
| 2018 | { |
| 2019 | return error(GL_INVALID_OPERATION); |
| 2020 | } |
| 2021 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 2022 | if (!mRenderer->applyPrimitiveType(mode, count)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2023 | { |
| 2024 | return; |
| 2025 | } |
| 2026 | |
| 2027 | if (!applyRenderTarget(false)) |
| 2028 | { |
| 2029 | return; |
| 2030 | } |
| 2031 | |
| 2032 | applyState(mode); |
| 2033 | |
daniel@transgaming.com | 92025f5 | 2012-11-28 20:52:54 +0000 | [diff] [blame] | 2034 | ProgramBinary *programBinary = getCurrentProgramBinary(); |
| 2035 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 2036 | GLenum err = mRenderer->applyVertexBuffer(programBinary, mState.vertexAttribute, first, count, instances); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2037 | if (err != GL_NO_ERROR) |
| 2038 | { |
| 2039 | return error(err); |
| 2040 | } |
| 2041 | |
| 2042 | applyShaders(); |
| 2043 | applyTextures(); |
| 2044 | |
daniel@transgaming.com | 92025f5 | 2012-11-28 20:52:54 +0000 | [diff] [blame] | 2045 | if (!programBinary->validateSamplers(NULL)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2046 | { |
| 2047 | return error(GL_INVALID_OPERATION); |
| 2048 | } |
| 2049 | |
daniel@transgaming.com | 087e578 | 2012-09-17 21:28:47 +0000 | [diff] [blame] | 2050 | if (!skipDraw(mode)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2051 | { |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 2052 | mRenderer->drawArrays(mode, count, instances); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2053 | } |
| 2054 | } |
| 2055 | |
| 2056 | void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instances) |
| 2057 | { |
| 2058 | if (!mState.currentProgram) |
| 2059 | { |
| 2060 | return error(GL_INVALID_OPERATION); |
| 2061 | } |
| 2062 | |
| 2063 | if (!indices && !mState.elementArrayBuffer) |
| 2064 | { |
| 2065 | return error(GL_INVALID_OPERATION); |
| 2066 | } |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 2067 | |
| 2068 | if (!mRenderer->applyPrimitiveType(mode, count)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2069 | { |
| 2070 | return; |
| 2071 | } |
| 2072 | |
| 2073 | if (!applyRenderTarget(false)) |
| 2074 | { |
| 2075 | return; |
| 2076 | } |
| 2077 | |
| 2078 | applyState(mode); |
| 2079 | |
| 2080 | TranslatedIndexData indexInfo; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 2081 | 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] | 2082 | if (err != GL_NO_ERROR) |
| 2083 | { |
| 2084 | return error(err); |
| 2085 | } |
| 2086 | |
daniel@transgaming.com | 92025f5 | 2012-11-28 20:52:54 +0000 | [diff] [blame] | 2087 | ProgramBinary *programBinary = getCurrentProgramBinary(); |
| 2088 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2089 | GLsizei vertexCount = indexInfo.maxIndex - indexInfo.minIndex + 1; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 2090 | err = mRenderer->applyVertexBuffer(programBinary, mState.vertexAttribute, indexInfo.minIndex, vertexCount, instances); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2091 | if (err != GL_NO_ERROR) |
| 2092 | { |
| 2093 | return error(err); |
| 2094 | } |
| 2095 | |
| 2096 | applyShaders(); |
| 2097 | applyTextures(); |
| 2098 | |
daniel@transgaming.com | 92025f5 | 2012-11-28 20:52:54 +0000 | [diff] [blame] | 2099 | if (!programBinary->validateSamplers(NULL)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2100 | { |
| 2101 | return error(GL_INVALID_OPERATION); |
| 2102 | } |
| 2103 | |
daniel@transgaming.com | 087e578 | 2012-09-17 21:28:47 +0000 | [diff] [blame] | 2104 | if (!skipDraw(mode)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2105 | { |
daniel@transgaming.com | 97400dd | 2012-11-28 20:57:00 +0000 | [diff] [blame] | 2106 | mRenderer->drawElements(mode, count, type, indices, mState.elementArrayBuffer.get(), indexInfo); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2107 | } |
| 2108 | } |
| 2109 | |
| 2110 | // Implements glFlush when block is false, glFinish when block is true |
| 2111 | void Context::sync(bool block) |
| 2112 | { |
daniel@transgaming.com | ef21ab2 | 2012-10-31 17:52:47 +0000 | [diff] [blame] | 2113 | mRenderer->sync(block); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2114 | } |
| 2115 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2116 | void Context::recordInvalidEnum() |
| 2117 | { |
| 2118 | mInvalidEnum = true; |
| 2119 | } |
| 2120 | |
| 2121 | void Context::recordInvalidValue() |
| 2122 | { |
| 2123 | mInvalidValue = true; |
| 2124 | } |
| 2125 | |
| 2126 | void Context::recordInvalidOperation() |
| 2127 | { |
| 2128 | mInvalidOperation = true; |
| 2129 | } |
| 2130 | |
| 2131 | void Context::recordOutOfMemory() |
| 2132 | { |
| 2133 | mOutOfMemory = true; |
| 2134 | } |
| 2135 | |
| 2136 | void Context::recordInvalidFramebufferOperation() |
| 2137 | { |
| 2138 | mInvalidFramebufferOperation = true; |
| 2139 | } |
| 2140 | |
| 2141 | // Get one of the recorded errors and clear its flag, if any. |
| 2142 | // [OpenGL ES 2.0.24] section 2.5 page 13. |
| 2143 | GLenum Context::getError() |
| 2144 | { |
| 2145 | if (mInvalidEnum) |
| 2146 | { |
| 2147 | mInvalidEnum = false; |
| 2148 | |
| 2149 | return GL_INVALID_ENUM; |
| 2150 | } |
| 2151 | |
| 2152 | if (mInvalidValue) |
| 2153 | { |
| 2154 | mInvalidValue = false; |
| 2155 | |
| 2156 | return GL_INVALID_VALUE; |
| 2157 | } |
| 2158 | |
| 2159 | if (mInvalidOperation) |
| 2160 | { |
| 2161 | mInvalidOperation = false; |
| 2162 | |
| 2163 | return GL_INVALID_OPERATION; |
| 2164 | } |
| 2165 | |
| 2166 | if (mOutOfMemory) |
| 2167 | { |
| 2168 | mOutOfMemory = false; |
| 2169 | |
| 2170 | return GL_OUT_OF_MEMORY; |
| 2171 | } |
| 2172 | |
| 2173 | if (mInvalidFramebufferOperation) |
| 2174 | { |
| 2175 | mInvalidFramebufferOperation = false; |
| 2176 | |
| 2177 | return GL_INVALID_FRAMEBUFFER_OPERATION; |
| 2178 | } |
| 2179 | |
| 2180 | return GL_NO_ERROR; |
| 2181 | } |
| 2182 | |
| 2183 | GLenum Context::getResetStatus() |
| 2184 | { |
| 2185 | if (mResetStatus == GL_NO_ERROR) |
| 2186 | { |
daniel@transgaming.com | f688c0d | 2012-10-31 17:52:57 +0000 | [diff] [blame] | 2187 | // mResetStatus will be set by the markContextLost callback |
| 2188 | // in the case a notification is sent |
| 2189 | mRenderer->testDeviceLost(true); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | GLenum status = mResetStatus; |
| 2193 | |
| 2194 | if (mResetStatus != GL_NO_ERROR) |
| 2195 | { |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 2196 | if (mRenderer->testDeviceResettable()) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2197 | { |
| 2198 | mResetStatus = GL_NO_ERROR; |
| 2199 | } |
| 2200 | } |
| 2201 | |
| 2202 | return status; |
| 2203 | } |
| 2204 | |
| 2205 | bool Context::isResetNotificationEnabled() |
| 2206 | { |
| 2207 | return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT); |
| 2208 | } |
| 2209 | |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 2210 | int Context::getMajorShaderModel() const |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2211 | { |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 2212 | return mMajorShaderModel; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2213 | } |
| 2214 | |
| 2215 | float Context::getMaximumPointSize() const |
| 2216 | { |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 2217 | return mMajorShaderModel >= 3 ? mMaximumPointSize : ALIASED_POINT_SIZE_RANGE_MAX_SM2; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | int Context::getMaximumVaryingVectors() const |
| 2221 | { |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 2222 | return mMajorShaderModel >= 3 ? MAX_VARYING_VECTORS_SM3 : MAX_VARYING_VECTORS_SM2; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2223 | } |
| 2224 | |
| 2225 | unsigned int Context::getMaximumVertexTextureImageUnits() const |
| 2226 | { |
| 2227 | return mSupportsVertexTexture ? MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF : 0; |
| 2228 | } |
| 2229 | |
| 2230 | unsigned int Context::getMaximumCombinedTextureImageUnits() const |
| 2231 | { |
| 2232 | return MAX_TEXTURE_IMAGE_UNITS + getMaximumVertexTextureImageUnits(); |
| 2233 | } |
| 2234 | |
| 2235 | int Context::getMaximumFragmentUniformVectors() const |
| 2236 | { |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 2237 | 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] | 2238 | } |
| 2239 | |
| 2240 | int Context::getMaxSupportedSamples() const |
| 2241 | { |
daniel@transgaming.com | b783398 | 2012-10-31 18:31:46 +0000 | [diff] [blame] | 2242 | return mRenderer->getMaxSupportedSamples(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2243 | } |
| 2244 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2245 | bool Context::supportsEventQueries() const |
| 2246 | { |
| 2247 | return mSupportsEventQueries; |
| 2248 | } |
| 2249 | |
| 2250 | bool Context::supportsOcclusionQueries() const |
| 2251 | { |
| 2252 | return mSupportsOcclusionQueries; |
| 2253 | } |
| 2254 | |
| 2255 | bool Context::supportsDXT1Textures() const |
| 2256 | { |
| 2257 | return mSupportsDXT1Textures; |
| 2258 | } |
| 2259 | |
| 2260 | bool Context::supportsDXT3Textures() const |
| 2261 | { |
| 2262 | return mSupportsDXT3Textures; |
| 2263 | } |
| 2264 | |
| 2265 | bool Context::supportsDXT5Textures() const |
| 2266 | { |
| 2267 | return mSupportsDXT5Textures; |
| 2268 | } |
| 2269 | |
| 2270 | bool Context::supportsFloat32Textures() const |
| 2271 | { |
| 2272 | return mSupportsFloat32Textures; |
| 2273 | } |
| 2274 | |
| 2275 | bool Context::supportsFloat32LinearFilter() const |
| 2276 | { |
| 2277 | return mSupportsFloat32LinearFilter; |
| 2278 | } |
| 2279 | |
| 2280 | bool Context::supportsFloat32RenderableTextures() const |
| 2281 | { |
| 2282 | return mSupportsFloat32RenderableTextures; |
| 2283 | } |
| 2284 | |
| 2285 | bool Context::supportsFloat16Textures() const |
| 2286 | { |
| 2287 | return mSupportsFloat16Textures; |
| 2288 | } |
| 2289 | |
| 2290 | bool Context::supportsFloat16LinearFilter() const |
| 2291 | { |
| 2292 | return mSupportsFloat16LinearFilter; |
| 2293 | } |
| 2294 | |
| 2295 | bool Context::supportsFloat16RenderableTextures() const |
| 2296 | { |
| 2297 | return mSupportsFloat16RenderableTextures; |
| 2298 | } |
| 2299 | |
| 2300 | int Context::getMaximumRenderbufferDimension() const |
| 2301 | { |
| 2302 | return mMaxRenderbufferDimension; |
| 2303 | } |
| 2304 | |
| 2305 | int Context::getMaximumTextureDimension() const |
| 2306 | { |
| 2307 | return mMaxTextureDimension; |
| 2308 | } |
| 2309 | |
| 2310 | int Context::getMaximumCubeTextureDimension() const |
| 2311 | { |
| 2312 | return mMaxCubeTextureDimension; |
| 2313 | } |
| 2314 | |
| 2315 | int Context::getMaximumTextureLevel() const |
| 2316 | { |
| 2317 | return mMaxTextureLevel; |
| 2318 | } |
| 2319 | |
| 2320 | bool Context::supportsLuminanceTextures() const |
| 2321 | { |
| 2322 | return mSupportsLuminanceTextures; |
| 2323 | } |
| 2324 | |
| 2325 | bool Context::supportsLuminanceAlphaTextures() const |
| 2326 | { |
| 2327 | return mSupportsLuminanceAlphaTextures; |
| 2328 | } |
| 2329 | |
| 2330 | bool Context::supportsDepthTextures() const |
| 2331 | { |
| 2332 | return mSupportsDepthTextures; |
| 2333 | } |
| 2334 | |
| 2335 | bool Context::supports32bitIndices() const |
| 2336 | { |
| 2337 | return mSupports32bitIndices; |
| 2338 | } |
| 2339 | |
| 2340 | bool Context::supportsNonPower2Texture() const |
| 2341 | { |
| 2342 | return mSupportsNonPower2Texture; |
| 2343 | } |
| 2344 | |
| 2345 | bool Context::supportsInstancing() const |
| 2346 | { |
| 2347 | return mSupportsInstancing; |
| 2348 | } |
| 2349 | |
daniel@transgaming.com | 07ab841 | 2012-07-12 15:17:09 +0000 | [diff] [blame] | 2350 | bool Context::supportsTextureFilterAnisotropy() const |
| 2351 | { |
| 2352 | return mSupportsTextureFilterAnisotropy; |
| 2353 | } |
| 2354 | |
| 2355 | float Context::getTextureMaxAnisotropy() const |
| 2356 | { |
| 2357 | return mMaxTextureAnisotropy; |
| 2358 | } |
| 2359 | |
daniel@transgaming.com | 42944b0 | 2012-09-27 17:45:57 +0000 | [diff] [blame] | 2360 | bool Context::getCurrentReadFormatType(GLenum *format, GLenum *type) |
| 2361 | { |
| 2362 | Framebuffer *framebuffer = getReadFramebuffer(); |
| 2363 | if (!framebuffer || framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 2364 | { |
| 2365 | return error(GL_INVALID_OPERATION, false); |
| 2366 | } |
| 2367 | |
| 2368 | Renderbuffer *renderbuffer = framebuffer->getColorbuffer(); |
| 2369 | if (!renderbuffer) |
| 2370 | { |
| 2371 | return error(GL_INVALID_OPERATION, false); |
| 2372 | } |
| 2373 | |
daniel@transgaming.com | 20d3666 | 2012-10-31 19:51:43 +0000 | [diff] [blame] | 2374 | *format = gl::ExtractFormat(renderbuffer->getActualFormat()); |
| 2375 | *type = gl::ExtractType(renderbuffer->getActualFormat()); |
daniel@transgaming.com | 42944b0 | 2012-09-27 17:45:57 +0000 | [diff] [blame] | 2376 | |
| 2377 | return true; |
| 2378 | } |
| 2379 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2380 | void Context::detachBuffer(GLuint buffer) |
| 2381 | { |
| 2382 | // [OpenGL ES 2.0.24] section 2.9 page 22: |
| 2383 | // If a buffer object is deleted while it is bound, all bindings to that object in the current context |
| 2384 | // (i.e. in the thread that called Delete-Buffers) are reset to zero. |
| 2385 | |
| 2386 | if (mState.arrayBuffer.id() == buffer) |
| 2387 | { |
| 2388 | mState.arrayBuffer.set(NULL); |
| 2389 | } |
| 2390 | |
| 2391 | if (mState.elementArrayBuffer.id() == buffer) |
| 2392 | { |
| 2393 | mState.elementArrayBuffer.set(NULL); |
| 2394 | } |
| 2395 | |
| 2396 | for (int attribute = 0; attribute < MAX_VERTEX_ATTRIBS; attribute++) |
| 2397 | { |
| 2398 | if (mState.vertexAttribute[attribute].mBoundBuffer.id() == buffer) |
| 2399 | { |
| 2400 | mState.vertexAttribute[attribute].mBoundBuffer.set(NULL); |
| 2401 | } |
| 2402 | } |
| 2403 | } |
| 2404 | |
| 2405 | void Context::detachTexture(GLuint texture) |
| 2406 | { |
| 2407 | // [OpenGL ES 2.0.24] section 3.8 page 84: |
| 2408 | // If a texture object is deleted, it is as if all texture units which are bound to that texture object are |
| 2409 | // rebound to texture object zero |
| 2410 | |
| 2411 | for (int type = 0; type < TEXTURE_TYPE_COUNT; type++) |
| 2412 | { |
| 2413 | for (int sampler = 0; sampler < MAX_COMBINED_TEXTURE_IMAGE_UNITS_VTF; sampler++) |
| 2414 | { |
| 2415 | if (mState.samplerTexture[type][sampler].id() == texture) |
| 2416 | { |
| 2417 | mState.samplerTexture[type][sampler].set(NULL); |
| 2418 | } |
| 2419 | } |
| 2420 | } |
| 2421 | |
| 2422 | // [OpenGL ES 2.0.24] section 4.4 page 112: |
| 2423 | // If a texture object is deleted while its image is attached to the currently bound framebuffer, then it is |
| 2424 | // as if FramebufferTexture2D had been called, with a texture of 0, for each attachment point to which this |
| 2425 | // image was attached in the currently bound framebuffer. |
| 2426 | |
| 2427 | Framebuffer *readFramebuffer = getReadFramebuffer(); |
| 2428 | Framebuffer *drawFramebuffer = getDrawFramebuffer(); |
| 2429 | |
| 2430 | if (readFramebuffer) |
| 2431 | { |
| 2432 | readFramebuffer->detachTexture(texture); |
| 2433 | } |
| 2434 | |
| 2435 | if (drawFramebuffer && drawFramebuffer != readFramebuffer) |
| 2436 | { |
| 2437 | drawFramebuffer->detachTexture(texture); |
| 2438 | } |
| 2439 | } |
| 2440 | |
| 2441 | void Context::detachFramebuffer(GLuint framebuffer) |
| 2442 | { |
| 2443 | // [OpenGL ES 2.0.24] section 4.4 page 107: |
| 2444 | // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as though |
| 2445 | // BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of zero. |
| 2446 | |
| 2447 | if (mState.readFramebuffer == framebuffer) |
| 2448 | { |
| 2449 | bindReadFramebuffer(0); |
| 2450 | } |
| 2451 | |
| 2452 | if (mState.drawFramebuffer == framebuffer) |
| 2453 | { |
| 2454 | bindDrawFramebuffer(0); |
| 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | void Context::detachRenderbuffer(GLuint renderbuffer) |
| 2459 | { |
| 2460 | // [OpenGL ES 2.0.24] section 4.4 page 109: |
| 2461 | // If a renderbuffer that is currently bound to RENDERBUFFER is deleted, it is as though BindRenderbuffer |
| 2462 | // had been executed with the target RENDERBUFFER and name of zero. |
| 2463 | |
| 2464 | if (mState.renderbuffer.id() == renderbuffer) |
| 2465 | { |
| 2466 | bindRenderbuffer(0); |
| 2467 | } |
| 2468 | |
| 2469 | // [OpenGL ES 2.0.24] section 4.4 page 111: |
| 2470 | // If a renderbuffer object is deleted while its image is attached to the currently bound framebuffer, |
| 2471 | // then it is as if FramebufferRenderbuffer had been called, with a renderbuffer of 0, for each attachment |
| 2472 | // point to which this image was attached in the currently bound framebuffer. |
| 2473 | |
| 2474 | Framebuffer *readFramebuffer = getReadFramebuffer(); |
| 2475 | Framebuffer *drawFramebuffer = getDrawFramebuffer(); |
| 2476 | |
| 2477 | if (readFramebuffer) |
| 2478 | { |
| 2479 | readFramebuffer->detachRenderbuffer(renderbuffer); |
| 2480 | } |
| 2481 | |
| 2482 | if (drawFramebuffer && drawFramebuffer != readFramebuffer) |
| 2483 | { |
| 2484 | drawFramebuffer->detachRenderbuffer(renderbuffer); |
| 2485 | } |
| 2486 | } |
| 2487 | |
| 2488 | Texture *Context::getIncompleteTexture(TextureType type) |
| 2489 | { |
| 2490 | Texture *t = mIncompleteTextures[type].get(); |
| 2491 | |
| 2492 | if (t == NULL) |
| 2493 | { |
| 2494 | static const GLubyte color[] = { 0, 0, 0, 255 }; |
| 2495 | |
| 2496 | switch (type) |
| 2497 | { |
| 2498 | default: |
| 2499 | UNREACHABLE(); |
| 2500 | // default falls through to TEXTURE_2D |
| 2501 | |
| 2502 | case TEXTURE_2D: |
| 2503 | { |
daniel@transgaming.com | 370482e | 2012-11-28 19:32:13 +0000 | [diff] [blame] | 2504 | Texture2D *incomplete2d = new Texture2D(mRenderer, Texture::INCOMPLETE_TEXTURE_ID); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2505 | incomplete2d->setImage(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 2506 | t = incomplete2d; |
| 2507 | } |
| 2508 | break; |
| 2509 | |
| 2510 | case TEXTURE_CUBE: |
| 2511 | { |
daniel@transgaming.com | 370482e | 2012-11-28 19:32:13 +0000 | [diff] [blame] | 2512 | TextureCubeMap *incompleteCube = new TextureCubeMap(mRenderer, Texture::INCOMPLETE_TEXTURE_ID); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2513 | |
| 2514 | incompleteCube->setImagePosX(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 2515 | incompleteCube->setImageNegX(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 2516 | incompleteCube->setImagePosY(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 2517 | incompleteCube->setImageNegY(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 2518 | incompleteCube->setImagePosZ(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 2519 | incompleteCube->setImageNegZ(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); |
| 2520 | |
| 2521 | t = incompleteCube; |
| 2522 | } |
| 2523 | break; |
| 2524 | } |
| 2525 | |
| 2526 | mIncompleteTextures[type].set(t); |
| 2527 | } |
| 2528 | |
| 2529 | return t; |
| 2530 | } |
| 2531 | |
daniel@transgaming.com | 087e578 | 2012-09-17 21:28:47 +0000 | [diff] [blame] | 2532 | bool Context::skipDraw(GLenum drawMode) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2533 | { |
daniel@transgaming.com | 087e578 | 2012-09-17 21:28:47 +0000 | [diff] [blame] | 2534 | if (drawMode == GL_POINTS) |
| 2535 | { |
| 2536 | // ProgramBinary assumes non-point rendering if gl_PointSize isn't written, |
| 2537 | // which affects varying interpolation. Since the value of gl_PointSize is |
| 2538 | // undefined when not written, just skip drawing to avoid unexpected results. |
| 2539 | if (!getCurrentProgramBinary()->usesPointSize()) |
| 2540 | { |
| 2541 | // This is stictly speaking not an error, but developers should be |
| 2542 | // notified of risking undefined behavior. |
| 2543 | ERR("Point rendering without writing to gl_PointSize."); |
| 2544 | |
| 2545 | return true; |
| 2546 | } |
| 2547 | } |
| 2548 | else if (isTriangleMode(drawMode)) |
| 2549 | { |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 2550 | if (mState.rasterizer.cullFace && mState.rasterizer.cullMode == GL_FRONT_AND_BACK) |
daniel@transgaming.com | 087e578 | 2012-09-17 21:28:47 +0000 | [diff] [blame] | 2551 | { |
| 2552 | return true; |
| 2553 | } |
| 2554 | } |
| 2555 | |
| 2556 | return false; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | bool Context::isTriangleMode(GLenum drawMode) |
| 2560 | { |
| 2561 | switch (drawMode) |
| 2562 | { |
| 2563 | case GL_TRIANGLES: |
| 2564 | case GL_TRIANGLE_FAN: |
| 2565 | case GL_TRIANGLE_STRIP: |
| 2566 | return true; |
| 2567 | case GL_POINTS: |
| 2568 | case GL_LINES: |
| 2569 | case GL_LINE_LOOP: |
| 2570 | case GL_LINE_STRIP: |
| 2571 | return false; |
| 2572 | default: UNREACHABLE(); |
| 2573 | } |
| 2574 | |
| 2575 | return false; |
| 2576 | } |
| 2577 | |
| 2578 | void Context::setVertexAttrib(GLuint index, const GLfloat *values) |
| 2579 | { |
| 2580 | ASSERT(index < gl::MAX_VERTEX_ATTRIBS); |
| 2581 | |
| 2582 | mState.vertexAttribute[index].mCurrentValue[0] = values[0]; |
| 2583 | mState.vertexAttribute[index].mCurrentValue[1] = values[1]; |
| 2584 | mState.vertexAttribute[index].mCurrentValue[2] = values[2]; |
| 2585 | mState.vertexAttribute[index].mCurrentValue[3] = values[3]; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2586 | } |
| 2587 | |
| 2588 | void Context::setVertexAttribDivisor(GLuint index, GLuint divisor) |
| 2589 | { |
| 2590 | ASSERT(index < gl::MAX_VERTEX_ATTRIBS); |
| 2591 | |
| 2592 | mState.vertexAttribute[index].mDivisor = divisor; |
| 2593 | } |
| 2594 | |
| 2595 | // keep list sorted in following order |
| 2596 | // OES extensions |
| 2597 | // EXT extensions |
| 2598 | // Vendor extensions |
| 2599 | void Context::initExtensionString() |
| 2600 | { |
| 2601 | mExtensionString = ""; |
| 2602 | |
| 2603 | // OES extensions |
| 2604 | if (supports32bitIndices()) |
| 2605 | { |
| 2606 | mExtensionString += "GL_OES_element_index_uint "; |
| 2607 | } |
| 2608 | |
| 2609 | mExtensionString += "GL_OES_packed_depth_stencil "; |
| 2610 | mExtensionString += "GL_OES_get_program_binary "; |
| 2611 | mExtensionString += "GL_OES_rgb8_rgba8 "; |
| 2612 | mExtensionString += "GL_OES_standard_derivatives "; |
| 2613 | |
| 2614 | if (supportsFloat16Textures()) |
| 2615 | { |
| 2616 | mExtensionString += "GL_OES_texture_half_float "; |
| 2617 | } |
| 2618 | if (supportsFloat16LinearFilter()) |
| 2619 | { |
| 2620 | mExtensionString += "GL_OES_texture_half_float_linear "; |
| 2621 | } |
| 2622 | if (supportsFloat32Textures()) |
| 2623 | { |
| 2624 | mExtensionString += "GL_OES_texture_float "; |
| 2625 | } |
| 2626 | if (supportsFloat32LinearFilter()) |
| 2627 | { |
| 2628 | mExtensionString += "GL_OES_texture_float_linear "; |
| 2629 | } |
| 2630 | |
| 2631 | if (supportsNonPower2Texture()) |
| 2632 | { |
| 2633 | mExtensionString += "GL_OES_texture_npot "; |
| 2634 | } |
| 2635 | |
| 2636 | // Multi-vendor (EXT) extensions |
| 2637 | if (supportsOcclusionQueries()) |
| 2638 | { |
| 2639 | mExtensionString += "GL_EXT_occlusion_query_boolean "; |
| 2640 | } |
| 2641 | |
| 2642 | mExtensionString += "GL_EXT_read_format_bgra "; |
| 2643 | mExtensionString += "GL_EXT_robustness "; |
| 2644 | |
| 2645 | if (supportsDXT1Textures()) |
| 2646 | { |
| 2647 | mExtensionString += "GL_EXT_texture_compression_dxt1 "; |
| 2648 | } |
| 2649 | |
daniel@transgaming.com | 07ab841 | 2012-07-12 15:17:09 +0000 | [diff] [blame] | 2650 | if (supportsTextureFilterAnisotropy()) |
| 2651 | { |
| 2652 | mExtensionString += "GL_EXT_texture_filter_anisotropic "; |
| 2653 | } |
| 2654 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2655 | mExtensionString += "GL_EXT_texture_format_BGRA8888 "; |
| 2656 | mExtensionString += "GL_EXT_texture_storage "; |
| 2657 | |
| 2658 | // ANGLE-specific extensions |
| 2659 | if (supportsDepthTextures()) |
| 2660 | { |
| 2661 | mExtensionString += "GL_ANGLE_depth_texture "; |
| 2662 | } |
| 2663 | |
| 2664 | mExtensionString += "GL_ANGLE_framebuffer_blit "; |
| 2665 | if (getMaxSupportedSamples() != 0) |
| 2666 | { |
| 2667 | mExtensionString += "GL_ANGLE_framebuffer_multisample "; |
| 2668 | } |
| 2669 | |
| 2670 | if (supportsInstancing()) |
| 2671 | { |
| 2672 | mExtensionString += "GL_ANGLE_instanced_arrays "; |
| 2673 | } |
| 2674 | |
| 2675 | mExtensionString += "GL_ANGLE_pack_reverse_row_order "; |
| 2676 | |
| 2677 | if (supportsDXT3Textures()) |
| 2678 | { |
| 2679 | mExtensionString += "GL_ANGLE_texture_compression_dxt3 "; |
| 2680 | } |
| 2681 | if (supportsDXT5Textures()) |
| 2682 | { |
| 2683 | mExtensionString += "GL_ANGLE_texture_compression_dxt5 "; |
| 2684 | } |
| 2685 | |
| 2686 | mExtensionString += "GL_ANGLE_texture_usage "; |
| 2687 | mExtensionString += "GL_ANGLE_translated_shader_source "; |
| 2688 | |
| 2689 | // Other vendor-specific extensions |
| 2690 | if (supportsEventQueries()) |
| 2691 | { |
| 2692 | mExtensionString += "GL_NV_fence "; |
| 2693 | } |
| 2694 | |
| 2695 | std::string::size_type end = mExtensionString.find_last_not_of(' '); |
| 2696 | if (end != std::string::npos) |
| 2697 | { |
| 2698 | mExtensionString.resize(end+1); |
| 2699 | } |
| 2700 | } |
| 2701 | |
| 2702 | const char *Context::getExtensionString() const |
| 2703 | { |
| 2704 | return mExtensionString.c_str(); |
| 2705 | } |
| 2706 | |
| 2707 | void Context::initRendererString() |
| 2708 | { |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2709 | mRendererString = "ANGLE ("; |
daniel@transgaming.com | 4ca789e | 2012-10-31 18:46:40 +0000 | [diff] [blame] | 2710 | mRendererString += mRenderer->getAdapterDescription(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2711 | mRendererString += ")"; |
| 2712 | } |
| 2713 | |
| 2714 | const char *Context::getRendererString() const |
| 2715 | { |
| 2716 | return mRendererString.c_str(); |
| 2717 | } |
| 2718 | |
| 2719 | void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 2720 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 2721 | GLbitfield mask) |
| 2722 | { |
| 2723 | Framebuffer *readFramebuffer = getReadFramebuffer(); |
| 2724 | Framebuffer *drawFramebuffer = getDrawFramebuffer(); |
| 2725 | |
| 2726 | if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE || |
| 2727 | !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 2728 | { |
| 2729 | return error(GL_INVALID_FRAMEBUFFER_OPERATION); |
| 2730 | } |
| 2731 | |
| 2732 | if (drawFramebuffer->getSamples() != 0) |
| 2733 | { |
| 2734 | return error(GL_INVALID_OPERATION); |
| 2735 | } |
| 2736 | |
| 2737 | int readBufferWidth = readFramebuffer->getColorbuffer()->getWidth(); |
| 2738 | int readBufferHeight = readFramebuffer->getColorbuffer()->getHeight(); |
| 2739 | int drawBufferWidth = drawFramebuffer->getColorbuffer()->getWidth(); |
| 2740 | int drawBufferHeight = drawFramebuffer->getColorbuffer()->getHeight(); |
| 2741 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2742 | Rectangle sourceRect; |
| 2743 | Rectangle destRect; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2744 | |
| 2745 | if (srcX0 < srcX1) |
| 2746 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2747 | sourceRect.x = srcX0; |
| 2748 | destRect.x = dstX0; |
| 2749 | sourceRect.width = srcX1 - srcX0; |
| 2750 | destRect.width = dstX1 - dstX0; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2751 | } |
| 2752 | else |
| 2753 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2754 | sourceRect.x = srcX1; |
| 2755 | destRect.x = dstX1; |
| 2756 | sourceRect.width = srcX0 - srcX1; |
| 2757 | destRect.width = dstX0 - dstX1; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2758 | } |
| 2759 | |
| 2760 | if (srcY0 < srcY1) |
| 2761 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2762 | sourceRect.height = srcY1 - srcY0; |
| 2763 | destRect.height = dstY1 - dstY0; |
| 2764 | sourceRect.y = srcY0; |
| 2765 | destRect.y = dstY0; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2766 | } |
| 2767 | else |
| 2768 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2769 | sourceRect.height = srcY0 - srcY1; |
| 2770 | destRect.height = dstY0 - srcY1; |
| 2771 | sourceRect.y = srcY1; |
| 2772 | destRect.y = dstY1; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2773 | } |
| 2774 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2775 | Rectangle sourceScissoredRect = sourceRect; |
| 2776 | Rectangle destScissoredRect = destRect; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2777 | |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 2778 | if (mState.rasterizer.scissorTest) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2779 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2780 | // Only write to parts of the destination framebuffer which pass the scissor test. |
| 2781 | if (destRect.x < mState.scissor.x) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2782 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2783 | int xDiff = mState.scissor.x - destRect.x; |
| 2784 | destScissoredRect.x = mState.scissor.x; |
| 2785 | destScissoredRect.width -= xDiff; |
| 2786 | sourceScissoredRect.x += xDiff; |
| 2787 | sourceScissoredRect.width -= xDiff; |
| 2788 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2789 | } |
| 2790 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2791 | if (destRect.x + destRect.width > mState.scissor.x + mState.scissor.width) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2792 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2793 | int xDiff = (destRect.x + destRect.width) - (mState.scissor.x + mState.scissor.width); |
| 2794 | destScissoredRect.width -= xDiff; |
| 2795 | sourceScissoredRect.width -= xDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2796 | } |
| 2797 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2798 | if (destRect.y < mState.scissor.y) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2799 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2800 | int yDiff = mState.scissor.y - destRect.y; |
| 2801 | destScissoredRect.y = mState.scissor.y; |
| 2802 | destScissoredRect.height -= yDiff; |
| 2803 | sourceScissoredRect.y += yDiff; |
| 2804 | sourceScissoredRect.height -= yDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2805 | } |
| 2806 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2807 | if (destRect.y + destRect.height > mState.scissor.y + mState.scissor.height) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2808 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2809 | int yDiff = (destRect.y + destRect.height) - (mState.scissor.y + mState.scissor.height); |
| 2810 | destScissoredRect.height -= yDiff; |
| 2811 | sourceScissoredRect.height -= yDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2812 | } |
| 2813 | } |
| 2814 | |
| 2815 | bool blitRenderTarget = false; |
| 2816 | bool blitDepthStencil = false; |
| 2817 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2818 | Rectangle sourceTrimmedRect = sourceScissoredRect; |
| 2819 | Rectangle destTrimmedRect = destScissoredRect; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2820 | |
| 2821 | // The source & destination rectangles also may need to be trimmed if they fall out of the bounds of |
| 2822 | // the actual draw and read surfaces. |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2823 | if (sourceTrimmedRect.x < 0) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2824 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2825 | int xDiff = 0 - sourceTrimmedRect.x; |
| 2826 | sourceTrimmedRect.x = 0; |
| 2827 | sourceTrimmedRect.width -= xDiff; |
| 2828 | destTrimmedRect.x += xDiff; |
| 2829 | destTrimmedRect.width -= xDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2830 | } |
| 2831 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2832 | if (sourceTrimmedRect.x + sourceTrimmedRect.width > readBufferWidth) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2833 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2834 | int xDiff = (sourceTrimmedRect.x + sourceTrimmedRect.width) - readBufferWidth; |
| 2835 | sourceTrimmedRect.width -= xDiff; |
| 2836 | destTrimmedRect.width -= xDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2837 | } |
| 2838 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2839 | if (sourceTrimmedRect.y < 0) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2840 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2841 | int yDiff = 0 - sourceTrimmedRect.y; |
| 2842 | sourceTrimmedRect.y = 0; |
| 2843 | sourceTrimmedRect.height -= yDiff; |
| 2844 | destTrimmedRect.y += yDiff; |
| 2845 | destTrimmedRect.height -= yDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2846 | } |
| 2847 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2848 | if (sourceTrimmedRect.y + sourceTrimmedRect.height > readBufferHeight) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2849 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2850 | int yDiff = (sourceTrimmedRect.y + sourceTrimmedRect.height) - readBufferHeight; |
| 2851 | sourceTrimmedRect.height -= yDiff; |
| 2852 | destTrimmedRect.height -= yDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2853 | } |
| 2854 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2855 | if (destTrimmedRect.x < 0) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2856 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2857 | int xDiff = 0 - destTrimmedRect.x; |
| 2858 | destTrimmedRect.x = 0; |
| 2859 | destTrimmedRect.width -= xDiff; |
| 2860 | sourceTrimmedRect.x += xDiff; |
| 2861 | sourceTrimmedRect.width -= xDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2862 | } |
| 2863 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2864 | if (destTrimmedRect.x + destTrimmedRect.width > drawBufferWidth) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2865 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2866 | int xDiff = (destTrimmedRect.x + destTrimmedRect.width) - drawBufferWidth; |
| 2867 | destTrimmedRect.width -= xDiff; |
| 2868 | sourceTrimmedRect.width -= xDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2869 | } |
| 2870 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2871 | if (destTrimmedRect.y < 0) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2872 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2873 | int yDiff = 0 - destTrimmedRect.y; |
| 2874 | destTrimmedRect.y = 0; |
| 2875 | destTrimmedRect.height -= yDiff; |
| 2876 | sourceTrimmedRect.y += yDiff; |
| 2877 | sourceTrimmedRect.height -= yDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2878 | } |
| 2879 | |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2880 | if (destTrimmedRect.y + destTrimmedRect.height > drawBufferHeight) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2881 | { |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2882 | int yDiff = (destTrimmedRect.y + destTrimmedRect.height) - drawBufferHeight; |
| 2883 | destTrimmedRect.height -= yDiff; |
| 2884 | sourceTrimmedRect.height -= yDiff; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | bool partialBufferCopy = false; |
daniel@transgaming.com | 48ab81c | 2012-11-28 19:39:21 +0000 | [diff] [blame] | 2888 | if (sourceTrimmedRect.height < readBufferHeight || |
| 2889 | sourceTrimmedRect.width < readBufferWidth || |
| 2890 | destTrimmedRect.height < drawBufferHeight || |
| 2891 | destTrimmedRect.width < drawBufferWidth || |
| 2892 | 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] | 2893 | { |
| 2894 | partialBufferCopy = true; |
| 2895 | } |
| 2896 | |
| 2897 | if (mask & GL_COLOR_BUFFER_BIT) |
| 2898 | { |
| 2899 | const bool validReadType = readFramebuffer->getColorbufferType() == GL_TEXTURE_2D || |
| 2900 | readFramebuffer->getColorbufferType() == GL_RENDERBUFFER; |
| 2901 | const bool validDrawType = drawFramebuffer->getColorbufferType() == GL_TEXTURE_2D || |
| 2902 | drawFramebuffer->getColorbufferType() == GL_RENDERBUFFER; |
| 2903 | if (!validReadType || !validDrawType || |
daniel@transgaming.com | 20d3666 | 2012-10-31 19:51:43 +0000 | [diff] [blame] | 2904 | readFramebuffer->getColorbuffer()->getActualFormat() != drawFramebuffer->getColorbuffer()->getActualFormat()) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2905 | { |
| 2906 | ERR("Color buffer format conversion in BlitFramebufferANGLE not supported by this implementation"); |
| 2907 | return error(GL_INVALID_OPERATION); |
| 2908 | } |
| 2909 | |
| 2910 | if (partialBufferCopy && readFramebuffer->getSamples() != 0) |
| 2911 | { |
| 2912 | return error(GL_INVALID_OPERATION); |
| 2913 | } |
| 2914 | |
| 2915 | blitRenderTarget = true; |
| 2916 | |
| 2917 | } |
| 2918 | |
| 2919 | if (mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) |
| 2920 | { |
| 2921 | Renderbuffer *readDSBuffer = NULL; |
| 2922 | Renderbuffer *drawDSBuffer = NULL; |
| 2923 | |
| 2924 | // We support OES_packed_depth_stencil, and do not support a separately attached depth and stencil buffer, so if we have |
| 2925 | // both a depth and stencil buffer, it will be the same buffer. |
| 2926 | |
| 2927 | if (mask & GL_DEPTH_BUFFER_BIT) |
| 2928 | { |
| 2929 | if (readFramebuffer->getDepthbuffer() && drawFramebuffer->getDepthbuffer()) |
| 2930 | { |
| 2931 | if (readFramebuffer->getDepthbufferType() != drawFramebuffer->getDepthbufferType() || |
daniel@transgaming.com | 20d3666 | 2012-10-31 19:51:43 +0000 | [diff] [blame] | 2932 | readFramebuffer->getDepthbuffer()->getActualFormat() != drawFramebuffer->getDepthbuffer()->getActualFormat()) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2933 | { |
| 2934 | return error(GL_INVALID_OPERATION); |
| 2935 | } |
| 2936 | |
| 2937 | blitDepthStencil = true; |
| 2938 | readDSBuffer = readFramebuffer->getDepthbuffer(); |
| 2939 | drawDSBuffer = drawFramebuffer->getDepthbuffer(); |
| 2940 | } |
| 2941 | } |
| 2942 | |
| 2943 | if (mask & GL_STENCIL_BUFFER_BIT) |
| 2944 | { |
| 2945 | if (readFramebuffer->getStencilbuffer() && drawFramebuffer->getStencilbuffer()) |
| 2946 | { |
| 2947 | if (readFramebuffer->getStencilbufferType() != drawFramebuffer->getStencilbufferType() || |
daniel@transgaming.com | 20d3666 | 2012-10-31 19:51:43 +0000 | [diff] [blame] | 2948 | readFramebuffer->getStencilbuffer()->getActualFormat() != drawFramebuffer->getStencilbuffer()->getActualFormat()) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2949 | { |
| 2950 | return error(GL_INVALID_OPERATION); |
| 2951 | } |
| 2952 | |
| 2953 | blitDepthStencil = true; |
| 2954 | readDSBuffer = readFramebuffer->getStencilbuffer(); |
| 2955 | drawDSBuffer = drawFramebuffer->getStencilbuffer(); |
| 2956 | } |
| 2957 | } |
| 2958 | |
| 2959 | if (partialBufferCopy) |
| 2960 | { |
| 2961 | ERR("Only whole-buffer depth and stencil blits are supported by this implementation."); |
| 2962 | return error(GL_INVALID_OPERATION); // only whole-buffer copies are permitted |
| 2963 | } |
| 2964 | |
| 2965 | if ((drawDSBuffer && drawDSBuffer->getSamples() != 0) || |
| 2966 | (readDSBuffer && readDSBuffer->getSamples() != 0)) |
| 2967 | { |
| 2968 | return error(GL_INVALID_OPERATION); |
| 2969 | } |
| 2970 | } |
| 2971 | |
| 2972 | if (blitRenderTarget || blitDepthStencil) |
| 2973 | { |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 2974 | mRenderer->blitRect(readFramebuffer, &sourceTrimmedRect, drawFramebuffer, &destTrimmedRect, blitRenderTarget, blitDepthStencil); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2975 | } |
| 2976 | } |
| 2977 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2978 | } |
| 2979 | |
| 2980 | extern "C" |
| 2981 | { |
daniel@transgaming.com | 03d3909 | 2012-11-28 19:31:59 +0000 | [diff] [blame] | 2982 | 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] | 2983 | { |
daniel@transgaming.com | 03d3909 | 2012-11-28 19:31:59 +0000 | [diff] [blame] | 2984 | return new gl::Context(shareContext, renderer, notifyResets, robustAccess); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | void glDestroyContext(gl::Context *context) |
| 2988 | { |
| 2989 | delete context; |
| 2990 | |
| 2991 | if (context == gl::getContext()) |
| 2992 | { |
| 2993 | gl::makeCurrent(NULL, NULL, NULL); |
| 2994 | } |
| 2995 | } |
| 2996 | |
| 2997 | void glMakeCurrent(gl::Context *context, egl::Display *display, egl::Surface *surface) |
| 2998 | { |
| 2999 | gl::makeCurrent(context, display, surface); |
| 3000 | } |
| 3001 | |
| 3002 | gl::Context *glGetCurrentContext() |
| 3003 | { |
| 3004 | return gl::getContext(); |
| 3005 | } |
daniel@transgaming.com | 621ce05 | 2012-10-31 17:52:29 +0000 | [diff] [blame] | 3006 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3007 | } |