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