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