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