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