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