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