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