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