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