1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/src/libGLESv2/Context.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,2972 @@ 1.4 +#include "precompiled.h" 1.5 +// 1.6 +// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. 1.7 +// Use of this source code is governed by a BSD-style license that can be 1.8 +// found in the LICENSE file. 1.9 +// 1.10 + 1.11 +// Context.cpp: Implements the gl::Context class, managing all GL state and performing 1.12 +// rendering operations. It is the GLES2 specific implementation of EGLContext. 1.13 + 1.14 +#include "libGLESv2/Context.h" 1.15 + 1.16 +#include "libGLESv2/main.h" 1.17 +#include "libGLESv2/utilities.h" 1.18 +#include "libGLESv2/Buffer.h" 1.19 +#include "libGLESv2/Fence.h" 1.20 +#include "libGLESv2/Framebuffer.h" 1.21 +#include "libGLESv2/Renderbuffer.h" 1.22 +#include "libGLESv2/Program.h" 1.23 +#include "libGLESv2/ProgramBinary.h" 1.24 +#include "libGLESv2/Query.h" 1.25 +#include "libGLESv2/Texture.h" 1.26 +#include "libGLESv2/ResourceManager.h" 1.27 +#include "libGLESv2/renderer/IndexDataManager.h" 1.28 +#include "libGLESv2/renderer/RenderTarget.h" 1.29 +#include "libGLESv2/renderer/Renderer.h" 1.30 + 1.31 +#include "libEGL/Surface.h" 1.32 + 1.33 +#undef near 1.34 +#undef far 1.35 + 1.36 +namespace gl 1.37 +{ 1.38 +static const char* makeStaticString(const std::string& str) 1.39 +{ 1.40 + static std::set<std::string> strings; 1.41 + std::set<std::string>::iterator it = strings.find(str); 1.42 + if (it != strings.end()) 1.43 + return it->c_str(); 1.44 + 1.45 + return strings.insert(str).first->c_str(); 1.46 +} 1.47 + 1.48 +Context::Context(const gl::Context *shareContext, rx::Renderer *renderer, bool notifyResets, bool robustAccess) : mRenderer(renderer) 1.49 +{ 1.50 + ASSERT(robustAccess == false); // Unimplemented 1.51 + 1.52 + mFenceHandleAllocator.setBaseHandle(0); 1.53 + 1.54 + setClearColor(0.0f, 0.0f, 0.0f, 0.0f); 1.55 + 1.56 + mState.depthClearValue = 1.0f; 1.57 + mState.stencilClearValue = 0; 1.58 + 1.59 + mState.rasterizer.cullFace = false; 1.60 + mState.rasterizer.cullMode = GL_BACK; 1.61 + mState.rasterizer.frontFace = GL_CCW; 1.62 + mState.rasterizer.polygonOffsetFill = false; 1.63 + mState.rasterizer.polygonOffsetFactor = 0.0f; 1.64 + mState.rasterizer.polygonOffsetUnits = 0.0f; 1.65 + mState.rasterizer.pointDrawMode = false; 1.66 + mState.rasterizer.multiSample = false; 1.67 + mState.scissorTest = false; 1.68 + mState.scissor.x = 0; 1.69 + mState.scissor.y = 0; 1.70 + mState.scissor.width = 0; 1.71 + mState.scissor.height = 0; 1.72 + 1.73 + mState.blend.blend = false; 1.74 + mState.blend.sourceBlendRGB = GL_ONE; 1.75 + mState.blend.sourceBlendAlpha = GL_ONE; 1.76 + mState.blend.destBlendRGB = GL_ZERO; 1.77 + mState.blend.destBlendAlpha = GL_ZERO; 1.78 + mState.blend.blendEquationRGB = GL_FUNC_ADD; 1.79 + mState.blend.blendEquationAlpha = GL_FUNC_ADD; 1.80 + mState.blend.sampleAlphaToCoverage = false; 1.81 + mState.blend.dither = true; 1.82 + 1.83 + mState.blendColor.red = 0; 1.84 + mState.blendColor.green = 0; 1.85 + mState.blendColor.blue = 0; 1.86 + mState.blendColor.alpha = 0; 1.87 + 1.88 + mState.depthStencil.depthTest = false; 1.89 + mState.depthStencil.depthFunc = GL_LESS; 1.90 + mState.depthStencil.depthMask = true; 1.91 + mState.depthStencil.stencilTest = false; 1.92 + mState.depthStencil.stencilFunc = GL_ALWAYS; 1.93 + mState.depthStencil.stencilMask = -1; 1.94 + mState.depthStencil.stencilWritemask = -1; 1.95 + mState.depthStencil.stencilBackFunc = GL_ALWAYS; 1.96 + mState.depthStencil.stencilBackMask = - 1; 1.97 + mState.depthStencil.stencilBackWritemask = -1; 1.98 + mState.depthStencil.stencilFail = GL_KEEP; 1.99 + mState.depthStencil.stencilPassDepthFail = GL_KEEP; 1.100 + mState.depthStencil.stencilPassDepthPass = GL_KEEP; 1.101 + mState.depthStencil.stencilBackFail = GL_KEEP; 1.102 + mState.depthStencil.stencilBackPassDepthFail = GL_KEEP; 1.103 + mState.depthStencil.stencilBackPassDepthPass = GL_KEEP; 1.104 + 1.105 + mState.stencilRef = 0; 1.106 + mState.stencilBackRef = 0; 1.107 + 1.108 + mState.sampleCoverage = false; 1.109 + mState.sampleCoverageValue = 1.0f; 1.110 + mState.sampleCoverageInvert = false; 1.111 + mState.generateMipmapHint = GL_DONT_CARE; 1.112 + mState.fragmentShaderDerivativeHint = GL_DONT_CARE; 1.113 + 1.114 + mState.lineWidth = 1.0f; 1.115 + 1.116 + mState.viewport.x = 0; 1.117 + mState.viewport.y = 0; 1.118 + mState.viewport.width = 0; 1.119 + mState.viewport.height = 0; 1.120 + mState.zNear = 0.0f; 1.121 + mState.zFar = 1.0f; 1.122 + 1.123 + mState.blend.colorMaskRed = true; 1.124 + mState.blend.colorMaskGreen = true; 1.125 + mState.blend.colorMaskBlue = true; 1.126 + mState.blend.colorMaskAlpha = true; 1.127 + 1.128 + if (shareContext != NULL) 1.129 + { 1.130 + mResourceManager = shareContext->mResourceManager; 1.131 + mResourceManager->addRef(); 1.132 + } 1.133 + else 1.134 + { 1.135 + mResourceManager = new ResourceManager(mRenderer); 1.136 + } 1.137 + 1.138 + // [OpenGL ES 2.0.24] section 3.7 page 83: 1.139 + // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional 1.140 + // and cube map texture state vectors respectively associated with them. 1.141 + // In order that access to these initial textures not be lost, they are treated as texture 1.142 + // objects all of whose names are 0. 1.143 + 1.144 + mTexture2DZero.set(new Texture2D(mRenderer, 0)); 1.145 + mTextureCubeMapZero.set(new TextureCubeMap(mRenderer, 0)); 1.146 + 1.147 + mState.activeSampler = 0; 1.148 + bindArrayBuffer(0); 1.149 + bindElementArrayBuffer(0); 1.150 + bindTextureCubeMap(0); 1.151 + bindTexture2D(0); 1.152 + bindReadFramebuffer(0); 1.153 + bindDrawFramebuffer(0); 1.154 + bindRenderbuffer(0); 1.155 + 1.156 + mState.currentProgram = 0; 1.157 + mCurrentProgramBinary.set(NULL); 1.158 + 1.159 + mState.packAlignment = 4; 1.160 + mState.unpackAlignment = 4; 1.161 + mState.packReverseRowOrder = false; 1.162 + 1.163 + mExtensionString = NULL; 1.164 + mRendererString = NULL; 1.165 + 1.166 + mInvalidEnum = false; 1.167 + mInvalidValue = false; 1.168 + mInvalidOperation = false; 1.169 + mOutOfMemory = false; 1.170 + mInvalidFramebufferOperation = false; 1.171 + 1.172 + mHasBeenCurrent = false; 1.173 + mContextLost = false; 1.174 + mResetStatus = GL_NO_ERROR; 1.175 + mResetStrategy = (notifyResets ? GL_LOSE_CONTEXT_ON_RESET_EXT : GL_NO_RESET_NOTIFICATION_EXT); 1.176 + mRobustAccess = robustAccess; 1.177 + 1.178 + mSupportsBGRATextures = false; 1.179 + mSupportsDXT1Textures = false; 1.180 + mSupportsDXT3Textures = false; 1.181 + mSupportsDXT5Textures = false; 1.182 + mSupportsEventQueries = false; 1.183 + mSupportsOcclusionQueries = false; 1.184 + mNumCompressedTextureFormats = 0; 1.185 +} 1.186 + 1.187 +Context::~Context() 1.188 +{ 1.189 + if (mState.currentProgram != 0) 1.190 + { 1.191 + Program *programObject = mResourceManager->getProgram(mState.currentProgram); 1.192 + if (programObject) 1.193 + { 1.194 + programObject->release(); 1.195 + } 1.196 + mState.currentProgram = 0; 1.197 + } 1.198 + mCurrentProgramBinary.set(NULL); 1.199 + 1.200 + while (!mFramebufferMap.empty()) 1.201 + { 1.202 + deleteFramebuffer(mFramebufferMap.begin()->first); 1.203 + } 1.204 + 1.205 + while (!mFenceMap.empty()) 1.206 + { 1.207 + deleteFence(mFenceMap.begin()->first); 1.208 + } 1.209 + 1.210 + while (!mQueryMap.empty()) 1.211 + { 1.212 + deleteQuery(mQueryMap.begin()->first); 1.213 + } 1.214 + 1.215 + for (int type = 0; type < TEXTURE_TYPE_COUNT; type++) 1.216 + { 1.217 + for (int sampler = 0; sampler < IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS; sampler++) 1.218 + { 1.219 + mState.samplerTexture[type][sampler].set(NULL); 1.220 + } 1.221 + } 1.222 + 1.223 + for (int type = 0; type < TEXTURE_TYPE_COUNT; type++) 1.224 + { 1.225 + mIncompleteTextures[type].set(NULL); 1.226 + } 1.227 + 1.228 + for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++) 1.229 + { 1.230 + mState.vertexAttribute[i].mBoundBuffer.set(NULL); 1.231 + } 1.232 + 1.233 + for (int i = 0; i < QUERY_TYPE_COUNT; i++) 1.234 + { 1.235 + mState.activeQuery[i].set(NULL); 1.236 + } 1.237 + 1.238 + mState.arrayBuffer.set(NULL); 1.239 + mState.elementArrayBuffer.set(NULL); 1.240 + mState.renderbuffer.set(NULL); 1.241 + 1.242 + mTexture2DZero.set(NULL); 1.243 + mTextureCubeMapZero.set(NULL); 1.244 + 1.245 + mResourceManager->release(); 1.246 +} 1.247 + 1.248 +void Context::makeCurrent(egl::Surface *surface) 1.249 +{ 1.250 + if (!mHasBeenCurrent) 1.251 + { 1.252 + mMajorShaderModel = mRenderer->getMajorShaderModel(); 1.253 + mMaximumPointSize = mRenderer->getMaxPointSize(); 1.254 + mSupportsVertexTexture = mRenderer->getVertexTextureSupport(); 1.255 + mSupportsNonPower2Texture = mRenderer->getNonPower2TextureSupport(); 1.256 + mSupportsInstancing = mRenderer->getInstancingSupport(); 1.257 + 1.258 + mMaxViewportDimension = mRenderer->getMaxViewportDimension(); 1.259 + mMaxTextureDimension = std::min(std::min(mRenderer->getMaxTextureWidth(), mRenderer->getMaxTextureHeight()), 1.260 + (int)gl::IMPLEMENTATION_MAX_TEXTURE_SIZE); 1.261 + mMaxCubeTextureDimension = std::min(mMaxTextureDimension, (int)gl::IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE); 1.262 + mMaxRenderbufferDimension = mMaxTextureDimension; 1.263 + mMaxTextureLevel = log2(mMaxTextureDimension) + 1; 1.264 + mMaxTextureAnisotropy = mRenderer->getTextureMaxAnisotropy(); 1.265 + TRACE("MaxTextureDimension=%d, MaxCubeTextureDimension=%d, MaxRenderbufferDimension=%d, MaxTextureLevel=%d, MaxTextureAnisotropy=%f", 1.266 + mMaxTextureDimension, mMaxCubeTextureDimension, mMaxRenderbufferDimension, mMaxTextureLevel, mMaxTextureAnisotropy); 1.267 + 1.268 + mSupportsEventQueries = mRenderer->getEventQuerySupport(); 1.269 + mSupportsOcclusionQueries = mRenderer->getOcclusionQuerySupport(); 1.270 + mSupportsBGRATextures = mRenderer->getBGRATextureSupport(); 1.271 + mSupportsDXT1Textures = mRenderer->getDXT1TextureSupport(); 1.272 + mSupportsDXT3Textures = mRenderer->getDXT3TextureSupport(); 1.273 + mSupportsDXT5Textures = mRenderer->getDXT5TextureSupport(); 1.274 + mSupportsFloat32Textures = mRenderer->getFloat32TextureSupport(&mSupportsFloat32LinearFilter, &mSupportsFloat32RenderableTextures); 1.275 + mSupportsFloat16Textures = mRenderer->getFloat16TextureSupport(&mSupportsFloat16LinearFilter, &mSupportsFloat16RenderableTextures); 1.276 + mSupportsLuminanceTextures = mRenderer->getLuminanceTextureSupport(); 1.277 + mSupportsLuminanceAlphaTextures = mRenderer->getLuminanceAlphaTextureSupport(); 1.278 + mSupportsDepthTextures = mRenderer->getDepthTextureSupport(); 1.279 + mSupportsTextureFilterAnisotropy = mRenderer->getTextureFilterAnisotropySupport(); 1.280 + mSupports32bitIndices = mRenderer->get32BitIndexSupport(); 1.281 + 1.282 + mNumCompressedTextureFormats = 0; 1.283 + if (supportsDXT1Textures()) 1.284 + { 1.285 + mNumCompressedTextureFormats += 2; 1.286 + } 1.287 + if (supportsDXT3Textures()) 1.288 + { 1.289 + mNumCompressedTextureFormats += 1; 1.290 + } 1.291 + if (supportsDXT5Textures()) 1.292 + { 1.293 + mNumCompressedTextureFormats += 1; 1.294 + } 1.295 + 1.296 + initExtensionString(); 1.297 + initRendererString(); 1.298 + 1.299 + mState.viewport.x = 0; 1.300 + mState.viewport.y = 0; 1.301 + mState.viewport.width = surface->getWidth(); 1.302 + mState.viewport.height = surface->getHeight(); 1.303 + 1.304 + mState.scissor.x = 0; 1.305 + mState.scissor.y = 0; 1.306 + mState.scissor.width = surface->getWidth(); 1.307 + mState.scissor.height = surface->getHeight(); 1.308 + 1.309 + mHasBeenCurrent = true; 1.310 + } 1.311 + 1.312 + // Wrap the existing swapchain resources into GL objects and assign them to the '0' names 1.313 + rx::SwapChain *swapchain = surface->getSwapChain(); 1.314 + 1.315 + Colorbuffer *colorbufferZero = new Colorbuffer(mRenderer, swapchain); 1.316 + DepthStencilbuffer *depthStencilbufferZero = new DepthStencilbuffer(mRenderer, swapchain); 1.317 + Framebuffer *framebufferZero = new DefaultFramebuffer(mRenderer, colorbufferZero, depthStencilbufferZero); 1.318 + 1.319 + setFramebufferZero(framebufferZero); 1.320 +} 1.321 + 1.322 +// NOTE: this function should not assume that this context is current! 1.323 +void Context::markContextLost() 1.324 +{ 1.325 + if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT) 1.326 + mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT; 1.327 + mContextLost = true; 1.328 +} 1.329 + 1.330 +bool Context::isContextLost() 1.331 +{ 1.332 + return mContextLost; 1.333 +} 1.334 + 1.335 +void Context::setClearColor(float red, float green, float blue, float alpha) 1.336 +{ 1.337 + mState.colorClearValue.red = red; 1.338 + mState.colorClearValue.green = green; 1.339 + mState.colorClearValue.blue = blue; 1.340 + mState.colorClearValue.alpha = alpha; 1.341 +} 1.342 + 1.343 +void Context::setClearDepth(float depth) 1.344 +{ 1.345 + mState.depthClearValue = depth; 1.346 +} 1.347 + 1.348 +void Context::setClearStencil(int stencil) 1.349 +{ 1.350 + mState.stencilClearValue = stencil; 1.351 +} 1.352 + 1.353 +void Context::setCullFace(bool enabled) 1.354 +{ 1.355 + mState.rasterizer.cullFace = enabled; 1.356 +} 1.357 + 1.358 +bool Context::isCullFaceEnabled() const 1.359 +{ 1.360 + return mState.rasterizer.cullFace; 1.361 +} 1.362 + 1.363 +void Context::setCullMode(GLenum mode) 1.364 +{ 1.365 + mState.rasterizer.cullMode = mode; 1.366 +} 1.367 + 1.368 +void Context::setFrontFace(GLenum front) 1.369 +{ 1.370 + mState.rasterizer.frontFace = front; 1.371 +} 1.372 + 1.373 +void Context::setDepthTest(bool enabled) 1.374 +{ 1.375 + mState.depthStencil.depthTest = enabled; 1.376 +} 1.377 + 1.378 +bool Context::isDepthTestEnabled() const 1.379 +{ 1.380 + return mState.depthStencil.depthTest; 1.381 +} 1.382 + 1.383 +void Context::setDepthFunc(GLenum depthFunc) 1.384 +{ 1.385 + mState.depthStencil.depthFunc = depthFunc; 1.386 +} 1.387 + 1.388 +void Context::setDepthRange(float zNear, float zFar) 1.389 +{ 1.390 + mState.zNear = zNear; 1.391 + mState.zFar = zFar; 1.392 +} 1.393 + 1.394 +void Context::setBlend(bool enabled) 1.395 +{ 1.396 + mState.blend.blend = enabled; 1.397 +} 1.398 + 1.399 +bool Context::isBlendEnabled() const 1.400 +{ 1.401 + return mState.blend.blend; 1.402 +} 1.403 + 1.404 +void Context::setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha) 1.405 +{ 1.406 + mState.blend.sourceBlendRGB = sourceRGB; 1.407 + mState.blend.destBlendRGB = destRGB; 1.408 + mState.blend.sourceBlendAlpha = sourceAlpha; 1.409 + mState.blend.destBlendAlpha = destAlpha; 1.410 +} 1.411 + 1.412 +void Context::setBlendColor(float red, float green, float blue, float alpha) 1.413 +{ 1.414 + mState.blendColor.red = red; 1.415 + mState.blendColor.green = green; 1.416 + mState.blendColor.blue = blue; 1.417 + mState.blendColor.alpha = alpha; 1.418 +} 1.419 + 1.420 +void Context::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation) 1.421 +{ 1.422 + mState.blend.blendEquationRGB = rgbEquation; 1.423 + mState.blend.blendEquationAlpha = alphaEquation; 1.424 +} 1.425 + 1.426 +void Context::setStencilTest(bool enabled) 1.427 +{ 1.428 + mState.depthStencil.stencilTest = enabled; 1.429 +} 1.430 + 1.431 +bool Context::isStencilTestEnabled() const 1.432 +{ 1.433 + return mState.depthStencil.stencilTest; 1.434 +} 1.435 + 1.436 +void Context::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask) 1.437 +{ 1.438 + mState.depthStencil.stencilFunc = stencilFunc; 1.439 + mState.stencilRef = (stencilRef > 0) ? stencilRef : 0; 1.440 + mState.depthStencil.stencilMask = stencilMask; 1.441 +} 1.442 + 1.443 +void Context::setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask) 1.444 +{ 1.445 + mState.depthStencil.stencilBackFunc = stencilBackFunc; 1.446 + mState.stencilBackRef = (stencilBackRef > 0) ? stencilBackRef : 0; 1.447 + mState.depthStencil.stencilBackMask = stencilBackMask; 1.448 +} 1.449 + 1.450 +void Context::setStencilWritemask(GLuint stencilWritemask) 1.451 +{ 1.452 + mState.depthStencil.stencilWritemask = stencilWritemask; 1.453 +} 1.454 + 1.455 +void Context::setStencilBackWritemask(GLuint stencilBackWritemask) 1.456 +{ 1.457 + mState.depthStencil.stencilBackWritemask = stencilBackWritemask; 1.458 +} 1.459 + 1.460 +void Context::setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass) 1.461 +{ 1.462 + mState.depthStencil.stencilFail = stencilFail; 1.463 + mState.depthStencil.stencilPassDepthFail = stencilPassDepthFail; 1.464 + mState.depthStencil.stencilPassDepthPass = stencilPassDepthPass; 1.465 +} 1.466 + 1.467 +void Context::setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass) 1.468 +{ 1.469 + mState.depthStencil.stencilBackFail = stencilBackFail; 1.470 + mState.depthStencil.stencilBackPassDepthFail = stencilBackPassDepthFail; 1.471 + mState.depthStencil.stencilBackPassDepthPass = stencilBackPassDepthPass; 1.472 +} 1.473 + 1.474 +void Context::setPolygonOffsetFill(bool enabled) 1.475 +{ 1.476 + mState.rasterizer.polygonOffsetFill = enabled; 1.477 +} 1.478 + 1.479 +bool Context::isPolygonOffsetFillEnabled() const 1.480 +{ 1.481 + return mState.rasterizer.polygonOffsetFill; 1.482 +} 1.483 + 1.484 +void Context::setPolygonOffsetParams(GLfloat factor, GLfloat units) 1.485 +{ 1.486 + // An application can pass NaN values here, so handle this gracefully 1.487 + mState.rasterizer.polygonOffsetFactor = factor != factor ? 0.0f : factor; 1.488 + mState.rasterizer.polygonOffsetUnits = units != units ? 0.0f : units; 1.489 +} 1.490 + 1.491 +void Context::setSampleAlphaToCoverage(bool enabled) 1.492 +{ 1.493 + mState.blend.sampleAlphaToCoverage = enabled; 1.494 +} 1.495 + 1.496 +bool Context::isSampleAlphaToCoverageEnabled() const 1.497 +{ 1.498 + return mState.blend.sampleAlphaToCoverage; 1.499 +} 1.500 + 1.501 +void Context::setSampleCoverage(bool enabled) 1.502 +{ 1.503 + mState.sampleCoverage = enabled; 1.504 +} 1.505 + 1.506 +bool Context::isSampleCoverageEnabled() const 1.507 +{ 1.508 + return mState.sampleCoverage; 1.509 +} 1.510 + 1.511 +void Context::setSampleCoverageParams(GLclampf value, bool invert) 1.512 +{ 1.513 + mState.sampleCoverageValue = value; 1.514 + mState.sampleCoverageInvert = invert; 1.515 +} 1.516 + 1.517 +void Context::setScissorTest(bool enabled) 1.518 +{ 1.519 + mState.scissorTest = enabled; 1.520 +} 1.521 + 1.522 +bool Context::isScissorTestEnabled() const 1.523 +{ 1.524 + return mState.scissorTest; 1.525 +} 1.526 + 1.527 +void Context::setDither(bool enabled) 1.528 +{ 1.529 + mState.blend.dither = enabled; 1.530 +} 1.531 + 1.532 +bool Context::isDitherEnabled() const 1.533 +{ 1.534 + return mState.blend.dither; 1.535 +} 1.536 + 1.537 +void Context::setLineWidth(GLfloat width) 1.538 +{ 1.539 + mState.lineWidth = width; 1.540 +} 1.541 + 1.542 +void Context::setGenerateMipmapHint(GLenum hint) 1.543 +{ 1.544 + mState.generateMipmapHint = hint; 1.545 +} 1.546 + 1.547 +void Context::setFragmentShaderDerivativeHint(GLenum hint) 1.548 +{ 1.549 + mState.fragmentShaderDerivativeHint = hint; 1.550 + // TODO: Propagate the hint to shader translator so we can write 1.551 + // ddx, ddx_coarse, or ddx_fine depending on the hint. 1.552 + // Ignore for now. It is valid for implementations to ignore hint. 1.553 +} 1.554 + 1.555 +void Context::setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height) 1.556 +{ 1.557 + mState.viewport.x = x; 1.558 + mState.viewport.y = y; 1.559 + mState.viewport.width = width; 1.560 + mState.viewport.height = height; 1.561 +} 1.562 + 1.563 +void Context::setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height) 1.564 +{ 1.565 + mState.scissor.x = x; 1.566 + mState.scissor.y = y; 1.567 + mState.scissor.width = width; 1.568 + mState.scissor.height = height; 1.569 +} 1.570 + 1.571 +void Context::setColorMask(bool red, bool green, bool blue, bool alpha) 1.572 +{ 1.573 + mState.blend.colorMaskRed = red; 1.574 + mState.blend.colorMaskGreen = green; 1.575 + mState.blend.colorMaskBlue = blue; 1.576 + mState.blend.colorMaskAlpha = alpha; 1.577 +} 1.578 + 1.579 +void Context::setDepthMask(bool mask) 1.580 +{ 1.581 + mState.depthStencil.depthMask = mask; 1.582 +} 1.583 + 1.584 +void Context::setActiveSampler(unsigned int active) 1.585 +{ 1.586 + mState.activeSampler = active; 1.587 +} 1.588 + 1.589 +GLuint Context::getReadFramebufferHandle() const 1.590 +{ 1.591 + return mState.readFramebuffer; 1.592 +} 1.593 + 1.594 +GLuint Context::getDrawFramebufferHandle() const 1.595 +{ 1.596 + return mState.drawFramebuffer; 1.597 +} 1.598 + 1.599 +GLuint Context::getRenderbufferHandle() const 1.600 +{ 1.601 + return mState.renderbuffer.id(); 1.602 +} 1.603 + 1.604 +GLuint Context::getArrayBufferHandle() const 1.605 +{ 1.606 + return mState.arrayBuffer.id(); 1.607 +} 1.608 + 1.609 +GLuint Context::getActiveQuery(GLenum target) const 1.610 +{ 1.611 + Query *queryObject = NULL; 1.612 + 1.613 + switch (target) 1.614 + { 1.615 + case GL_ANY_SAMPLES_PASSED_EXT: 1.616 + queryObject = mState.activeQuery[QUERY_ANY_SAMPLES_PASSED].get(); 1.617 + break; 1.618 + case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT: 1.619 + queryObject = mState.activeQuery[QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE].get(); 1.620 + break; 1.621 + default: 1.622 + ASSERT(false); 1.623 + } 1.624 + 1.625 + if (queryObject) 1.626 + { 1.627 + return queryObject->id(); 1.628 + } 1.629 + else 1.630 + { 1.631 + return 0; 1.632 + } 1.633 +} 1.634 + 1.635 +void Context::setEnableVertexAttribArray(unsigned int attribNum, bool enabled) 1.636 +{ 1.637 + mState.vertexAttribute[attribNum].mArrayEnabled = enabled; 1.638 +} 1.639 + 1.640 +const VertexAttribute &Context::getVertexAttribState(unsigned int attribNum) 1.641 +{ 1.642 + return mState.vertexAttribute[attribNum]; 1.643 +} 1.644 + 1.645 +void Context::setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type, bool normalized, 1.646 + GLsizei stride, const void *pointer) 1.647 +{ 1.648 + mState.vertexAttribute[attribNum].mBoundBuffer.set(boundBuffer); 1.649 + mState.vertexAttribute[attribNum].mSize = size; 1.650 + mState.vertexAttribute[attribNum].mType = type; 1.651 + mState.vertexAttribute[attribNum].mNormalized = normalized; 1.652 + mState.vertexAttribute[attribNum].mStride = stride; 1.653 + mState.vertexAttribute[attribNum].mPointer = pointer; 1.654 +} 1.655 + 1.656 +const void *Context::getVertexAttribPointer(unsigned int attribNum) const 1.657 +{ 1.658 + return mState.vertexAttribute[attribNum].mPointer; 1.659 +} 1.660 + 1.661 +void Context::setPackAlignment(GLint alignment) 1.662 +{ 1.663 + mState.packAlignment = alignment; 1.664 +} 1.665 + 1.666 +GLint Context::getPackAlignment() const 1.667 +{ 1.668 + return mState.packAlignment; 1.669 +} 1.670 + 1.671 +void Context::setUnpackAlignment(GLint alignment) 1.672 +{ 1.673 + mState.unpackAlignment = alignment; 1.674 +} 1.675 + 1.676 +GLint Context::getUnpackAlignment() const 1.677 +{ 1.678 + return mState.unpackAlignment; 1.679 +} 1.680 + 1.681 +void Context::setPackReverseRowOrder(bool reverseRowOrder) 1.682 +{ 1.683 + mState.packReverseRowOrder = reverseRowOrder; 1.684 +} 1.685 + 1.686 +bool Context::getPackReverseRowOrder() const 1.687 +{ 1.688 + return mState.packReverseRowOrder; 1.689 +} 1.690 + 1.691 +GLuint Context::createBuffer() 1.692 +{ 1.693 + return mResourceManager->createBuffer(); 1.694 +} 1.695 + 1.696 +GLuint Context::createProgram() 1.697 +{ 1.698 + return mResourceManager->createProgram(); 1.699 +} 1.700 + 1.701 +GLuint Context::createShader(GLenum type) 1.702 +{ 1.703 + return mResourceManager->createShader(type); 1.704 +} 1.705 + 1.706 +GLuint Context::createTexture() 1.707 +{ 1.708 + return mResourceManager->createTexture(); 1.709 +} 1.710 + 1.711 +GLuint Context::createRenderbuffer() 1.712 +{ 1.713 + return mResourceManager->createRenderbuffer(); 1.714 +} 1.715 + 1.716 +// Returns an unused framebuffer name 1.717 +GLuint Context::createFramebuffer() 1.718 +{ 1.719 + GLuint handle = mFramebufferHandleAllocator.allocate(); 1.720 + 1.721 + mFramebufferMap[handle] = NULL; 1.722 + 1.723 + return handle; 1.724 +} 1.725 + 1.726 +GLuint Context::createFence() 1.727 +{ 1.728 + GLuint handle = mFenceHandleAllocator.allocate(); 1.729 + 1.730 + mFenceMap[handle] = new Fence(mRenderer); 1.731 + 1.732 + return handle; 1.733 +} 1.734 + 1.735 +// Returns an unused query name 1.736 +GLuint Context::createQuery() 1.737 +{ 1.738 + GLuint handle = mQueryHandleAllocator.allocate(); 1.739 + 1.740 + mQueryMap[handle] = NULL; 1.741 + 1.742 + return handle; 1.743 +} 1.744 + 1.745 +void Context::deleteBuffer(GLuint buffer) 1.746 +{ 1.747 + if (mResourceManager->getBuffer(buffer)) 1.748 + { 1.749 + detachBuffer(buffer); 1.750 + } 1.751 + 1.752 + mResourceManager->deleteBuffer(buffer); 1.753 +} 1.754 + 1.755 +void Context::deleteShader(GLuint shader) 1.756 +{ 1.757 + mResourceManager->deleteShader(shader); 1.758 +} 1.759 + 1.760 +void Context::deleteProgram(GLuint program) 1.761 +{ 1.762 + mResourceManager->deleteProgram(program); 1.763 +} 1.764 + 1.765 +void Context::deleteTexture(GLuint texture) 1.766 +{ 1.767 + if (mResourceManager->getTexture(texture)) 1.768 + { 1.769 + detachTexture(texture); 1.770 + } 1.771 + 1.772 + mResourceManager->deleteTexture(texture); 1.773 +} 1.774 + 1.775 +void Context::deleteRenderbuffer(GLuint renderbuffer) 1.776 +{ 1.777 + if (mResourceManager->getRenderbuffer(renderbuffer)) 1.778 + { 1.779 + detachRenderbuffer(renderbuffer); 1.780 + } 1.781 + 1.782 + mResourceManager->deleteRenderbuffer(renderbuffer); 1.783 +} 1.784 + 1.785 +void Context::deleteFramebuffer(GLuint framebuffer) 1.786 +{ 1.787 + FramebufferMap::iterator framebufferObject = mFramebufferMap.find(framebuffer); 1.788 + 1.789 + if (framebufferObject != mFramebufferMap.end()) 1.790 + { 1.791 + detachFramebuffer(framebuffer); 1.792 + 1.793 + mFramebufferHandleAllocator.release(framebufferObject->first); 1.794 + delete framebufferObject->second; 1.795 + mFramebufferMap.erase(framebufferObject); 1.796 + } 1.797 +} 1.798 + 1.799 +void Context::deleteFence(GLuint fence) 1.800 +{ 1.801 + FenceMap::iterator fenceObject = mFenceMap.find(fence); 1.802 + 1.803 + if (fenceObject != mFenceMap.end()) 1.804 + { 1.805 + mFenceHandleAllocator.release(fenceObject->first); 1.806 + delete fenceObject->second; 1.807 + mFenceMap.erase(fenceObject); 1.808 + } 1.809 +} 1.810 + 1.811 +void Context::deleteQuery(GLuint query) 1.812 +{ 1.813 + QueryMap::iterator queryObject = mQueryMap.find(query); 1.814 + if (queryObject != mQueryMap.end()) 1.815 + { 1.816 + mQueryHandleAllocator.release(queryObject->first); 1.817 + if (queryObject->second) 1.818 + { 1.819 + queryObject->second->release(); 1.820 + } 1.821 + mQueryMap.erase(queryObject); 1.822 + } 1.823 +} 1.824 + 1.825 +Buffer *Context::getBuffer(GLuint handle) 1.826 +{ 1.827 + return mResourceManager->getBuffer(handle); 1.828 +} 1.829 + 1.830 +Shader *Context::getShader(GLuint handle) 1.831 +{ 1.832 + return mResourceManager->getShader(handle); 1.833 +} 1.834 + 1.835 +Program *Context::getProgram(GLuint handle) 1.836 +{ 1.837 + return mResourceManager->getProgram(handle); 1.838 +} 1.839 + 1.840 +Texture *Context::getTexture(GLuint handle) 1.841 +{ 1.842 + return mResourceManager->getTexture(handle); 1.843 +} 1.844 + 1.845 +Renderbuffer *Context::getRenderbuffer(GLuint handle) 1.846 +{ 1.847 + return mResourceManager->getRenderbuffer(handle); 1.848 +} 1.849 + 1.850 +Framebuffer *Context::getReadFramebuffer() 1.851 +{ 1.852 + return getFramebuffer(mState.readFramebuffer); 1.853 +} 1.854 + 1.855 +Framebuffer *Context::getDrawFramebuffer() 1.856 +{ 1.857 + return mBoundDrawFramebuffer; 1.858 +} 1.859 + 1.860 +void Context::bindArrayBuffer(unsigned int buffer) 1.861 +{ 1.862 + mResourceManager->checkBufferAllocation(buffer); 1.863 + 1.864 + mState.arrayBuffer.set(getBuffer(buffer)); 1.865 +} 1.866 + 1.867 +void Context::bindElementArrayBuffer(unsigned int buffer) 1.868 +{ 1.869 + mResourceManager->checkBufferAllocation(buffer); 1.870 + 1.871 + mState.elementArrayBuffer.set(getBuffer(buffer)); 1.872 +} 1.873 + 1.874 +void Context::bindTexture2D(GLuint texture) 1.875 +{ 1.876 + mResourceManager->checkTextureAllocation(texture, TEXTURE_2D); 1.877 + 1.878 + mState.samplerTexture[TEXTURE_2D][mState.activeSampler].set(getTexture(texture)); 1.879 +} 1.880 + 1.881 +void Context::bindTextureCubeMap(GLuint texture) 1.882 +{ 1.883 + mResourceManager->checkTextureAllocation(texture, TEXTURE_CUBE); 1.884 + 1.885 + mState.samplerTexture[TEXTURE_CUBE][mState.activeSampler].set(getTexture(texture)); 1.886 +} 1.887 + 1.888 +void Context::bindReadFramebuffer(GLuint framebuffer) 1.889 +{ 1.890 + if (!getFramebuffer(framebuffer)) 1.891 + { 1.892 + mFramebufferMap[framebuffer] = new Framebuffer(mRenderer); 1.893 + } 1.894 + 1.895 + mState.readFramebuffer = framebuffer; 1.896 +} 1.897 + 1.898 +void Context::bindDrawFramebuffer(GLuint framebuffer) 1.899 +{ 1.900 + if (!getFramebuffer(framebuffer)) 1.901 + { 1.902 + mFramebufferMap[framebuffer] = new Framebuffer(mRenderer); 1.903 + } 1.904 + 1.905 + mState.drawFramebuffer = framebuffer; 1.906 + 1.907 + mBoundDrawFramebuffer = getFramebuffer(framebuffer); 1.908 +} 1.909 + 1.910 +void Context::bindRenderbuffer(GLuint renderbuffer) 1.911 +{ 1.912 + mResourceManager->checkRenderbufferAllocation(renderbuffer); 1.913 + 1.914 + mState.renderbuffer.set(getRenderbuffer(renderbuffer)); 1.915 +} 1.916 + 1.917 +void Context::useProgram(GLuint program) 1.918 +{ 1.919 + GLuint priorProgram = mState.currentProgram; 1.920 + mState.currentProgram = program; // Must switch before trying to delete, otherwise it only gets flagged. 1.921 + 1.922 + if (priorProgram != program) 1.923 + { 1.924 + Program *newProgram = mResourceManager->getProgram(program); 1.925 + Program *oldProgram = mResourceManager->getProgram(priorProgram); 1.926 + mCurrentProgramBinary.set(NULL); 1.927 + 1.928 + if (newProgram) 1.929 + { 1.930 + newProgram->addRef(); 1.931 + mCurrentProgramBinary.set(newProgram->getProgramBinary()); 1.932 + } 1.933 + 1.934 + if (oldProgram) 1.935 + { 1.936 + oldProgram->release(); 1.937 + } 1.938 + } 1.939 +} 1.940 + 1.941 +void Context::linkProgram(GLuint program) 1.942 +{ 1.943 + Program *programObject = mResourceManager->getProgram(program); 1.944 + 1.945 + bool linked = programObject->link(); 1.946 + 1.947 + // if the current program was relinked successfully we 1.948 + // need to install the new executables 1.949 + if (linked && program == mState.currentProgram) 1.950 + { 1.951 + mCurrentProgramBinary.set(programObject->getProgramBinary()); 1.952 + } 1.953 +} 1.954 + 1.955 +void Context::setProgramBinary(GLuint program, const void *binary, GLint length) 1.956 +{ 1.957 + Program *programObject = mResourceManager->getProgram(program); 1.958 + 1.959 + bool loaded = programObject->setProgramBinary(binary, length); 1.960 + 1.961 + // if the current program was reloaded successfully we 1.962 + // need to install the new executables 1.963 + if (loaded && program == mState.currentProgram) 1.964 + { 1.965 + mCurrentProgramBinary.set(programObject->getProgramBinary()); 1.966 + } 1.967 + 1.968 +} 1.969 + 1.970 +void Context::beginQuery(GLenum target, GLuint query) 1.971 +{ 1.972 + // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> 1.973 + // of zero, if the active query object name for <target> is non-zero (for the 1.974 + // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if 1.975 + // the active query for either target is non-zero), if <id> is the name of an 1.976 + // existing query object whose type does not match <target>, or if <id> is the 1.977 + // active query object name for any query type, the error INVALID_OPERATION is 1.978 + // generated. 1.979 + 1.980 + // Ensure no other queries are active 1.981 + // NOTE: If other queries than occlusion are supported, we will need to check 1.982 + // separately that: 1.983 + // a) The query ID passed is not the current active query for any target/type 1.984 + // b) There are no active queries for the requested target (and in the case 1.985 + // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, 1.986 + // no query may be active for either if glBeginQuery targets either. 1.987 + for (int i = 0; i < QUERY_TYPE_COUNT; i++) 1.988 + { 1.989 + if (mState.activeQuery[i].get() != NULL) 1.990 + { 1.991 + return gl::error(GL_INVALID_OPERATION); 1.992 + } 1.993 + } 1.994 + 1.995 + QueryType qType; 1.996 + switch (target) 1.997 + { 1.998 + case GL_ANY_SAMPLES_PASSED_EXT: 1.999 + qType = QUERY_ANY_SAMPLES_PASSED; 1.1000 + break; 1.1001 + case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT: 1.1002 + qType = QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE; 1.1003 + break; 1.1004 + default: 1.1005 + ASSERT(false); 1.1006 + return; 1.1007 + } 1.1008 + 1.1009 + Query *queryObject = getQuery(query, true, target); 1.1010 + 1.1011 + // check that name was obtained with glGenQueries 1.1012 + if (!queryObject) 1.1013 + { 1.1014 + return gl::error(GL_INVALID_OPERATION); 1.1015 + } 1.1016 + 1.1017 + // check for type mismatch 1.1018 + if (queryObject->getType() != target) 1.1019 + { 1.1020 + return gl::error(GL_INVALID_OPERATION); 1.1021 + } 1.1022 + 1.1023 + // set query as active for specified target 1.1024 + mState.activeQuery[qType].set(queryObject); 1.1025 + 1.1026 + // begin query 1.1027 + queryObject->begin(); 1.1028 +} 1.1029 + 1.1030 +void Context::endQuery(GLenum target) 1.1031 +{ 1.1032 + QueryType qType; 1.1033 + 1.1034 + switch (target) 1.1035 + { 1.1036 + case GL_ANY_SAMPLES_PASSED_EXT: 1.1037 + qType = QUERY_ANY_SAMPLES_PASSED; 1.1038 + break; 1.1039 + case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT: 1.1040 + qType = QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE; 1.1041 + break; 1.1042 + default: 1.1043 + ASSERT(false); 1.1044 + return; 1.1045 + } 1.1046 + 1.1047 + Query *queryObject = mState.activeQuery[qType].get(); 1.1048 + 1.1049 + if (queryObject == NULL) 1.1050 + { 1.1051 + return gl::error(GL_INVALID_OPERATION); 1.1052 + } 1.1053 + 1.1054 + queryObject->end(); 1.1055 + 1.1056 + mState.activeQuery[qType].set(NULL); 1.1057 +} 1.1058 + 1.1059 +void Context::setFramebufferZero(Framebuffer *buffer) 1.1060 +{ 1.1061 + delete mFramebufferMap[0]; 1.1062 + mFramebufferMap[0] = buffer; 1.1063 + if (mState.drawFramebuffer == 0) 1.1064 + { 1.1065 + mBoundDrawFramebuffer = buffer; 1.1066 + } 1.1067 +} 1.1068 + 1.1069 +void Context::setRenderbufferStorage(GLsizei width, GLsizei height, GLenum internalformat, GLsizei samples) 1.1070 +{ 1.1071 + RenderbufferStorage *renderbuffer = NULL; 1.1072 + switch (internalformat) 1.1073 + { 1.1074 + case GL_DEPTH_COMPONENT16: 1.1075 + renderbuffer = new gl::Depthbuffer(mRenderer, width, height, samples); 1.1076 + break; 1.1077 + case GL_RGBA4: 1.1078 + case GL_RGB5_A1: 1.1079 + case GL_RGB565: 1.1080 + case GL_RGB8_OES: 1.1081 + case GL_RGBA8_OES: 1.1082 + renderbuffer = new gl::Colorbuffer(mRenderer,width, height, internalformat, samples); 1.1083 + break; 1.1084 + case GL_STENCIL_INDEX8: 1.1085 + renderbuffer = new gl::Stencilbuffer(mRenderer, width, height, samples); 1.1086 + break; 1.1087 + case GL_DEPTH24_STENCIL8_OES: 1.1088 + renderbuffer = new gl::DepthStencilbuffer(mRenderer, width, height, samples); 1.1089 + break; 1.1090 + default: 1.1091 + UNREACHABLE(); return; 1.1092 + } 1.1093 + 1.1094 + Renderbuffer *renderbufferObject = mState.renderbuffer.get(); 1.1095 + renderbufferObject->setStorage(renderbuffer); 1.1096 +} 1.1097 + 1.1098 +Framebuffer *Context::getFramebuffer(unsigned int handle) 1.1099 +{ 1.1100 + FramebufferMap::iterator framebuffer = mFramebufferMap.find(handle); 1.1101 + 1.1102 + if (framebuffer == mFramebufferMap.end()) 1.1103 + { 1.1104 + return NULL; 1.1105 + } 1.1106 + else 1.1107 + { 1.1108 + return framebuffer->second; 1.1109 + } 1.1110 +} 1.1111 + 1.1112 +Fence *Context::getFence(unsigned int handle) 1.1113 +{ 1.1114 + FenceMap::iterator fence = mFenceMap.find(handle); 1.1115 + 1.1116 + if (fence == mFenceMap.end()) 1.1117 + { 1.1118 + return NULL; 1.1119 + } 1.1120 + else 1.1121 + { 1.1122 + return fence->second; 1.1123 + } 1.1124 +} 1.1125 + 1.1126 +Query *Context::getQuery(unsigned int handle, bool create, GLenum type) 1.1127 +{ 1.1128 + QueryMap::iterator query = mQueryMap.find(handle); 1.1129 + 1.1130 + if (query == mQueryMap.end()) 1.1131 + { 1.1132 + return NULL; 1.1133 + } 1.1134 + else 1.1135 + { 1.1136 + if (!query->second && create) 1.1137 + { 1.1138 + query->second = new Query(mRenderer, type, handle); 1.1139 + query->second->addRef(); 1.1140 + } 1.1141 + return query->second; 1.1142 + } 1.1143 +} 1.1144 + 1.1145 +Buffer *Context::getArrayBuffer() 1.1146 +{ 1.1147 + return mState.arrayBuffer.get(); 1.1148 +} 1.1149 + 1.1150 +Buffer *Context::getElementArrayBuffer() 1.1151 +{ 1.1152 + return mState.elementArrayBuffer.get(); 1.1153 +} 1.1154 + 1.1155 +ProgramBinary *Context::getCurrentProgramBinary() 1.1156 +{ 1.1157 + return mCurrentProgramBinary.get(); 1.1158 +} 1.1159 + 1.1160 +Texture2D *Context::getTexture2D() 1.1161 +{ 1.1162 + return static_cast<Texture2D*>(getSamplerTexture(mState.activeSampler, TEXTURE_2D)); 1.1163 +} 1.1164 + 1.1165 +TextureCubeMap *Context::getTextureCubeMap() 1.1166 +{ 1.1167 + return static_cast<TextureCubeMap*>(getSamplerTexture(mState.activeSampler, TEXTURE_CUBE)); 1.1168 +} 1.1169 + 1.1170 +Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) 1.1171 +{ 1.1172 + GLuint texid = mState.samplerTexture[type][sampler].id(); 1.1173 + 1.1174 + if (texid == 0) // Special case: 0 refers to different initial textures based on the target 1.1175 + { 1.1176 + switch (type) 1.1177 + { 1.1178 + default: UNREACHABLE(); 1.1179 + case TEXTURE_2D: return mTexture2DZero.get(); 1.1180 + case TEXTURE_CUBE: return mTextureCubeMapZero.get(); 1.1181 + } 1.1182 + } 1.1183 + 1.1184 + return mState.samplerTexture[type][sampler].get(); 1.1185 +} 1.1186 + 1.1187 +bool Context::getBooleanv(GLenum pname, GLboolean *params) 1.1188 +{ 1.1189 + switch (pname) 1.1190 + { 1.1191 + case GL_SHADER_COMPILER: *params = GL_TRUE; break; 1.1192 + case GL_SAMPLE_COVERAGE_INVERT: *params = mState.sampleCoverageInvert; break; 1.1193 + case GL_DEPTH_WRITEMASK: *params = mState.depthStencil.depthMask; break; 1.1194 + case GL_COLOR_WRITEMASK: 1.1195 + params[0] = mState.blend.colorMaskRed; 1.1196 + params[1] = mState.blend.colorMaskGreen; 1.1197 + params[2] = mState.blend.colorMaskBlue; 1.1198 + params[3] = mState.blend.colorMaskAlpha; 1.1199 + break; 1.1200 + case GL_CULL_FACE: *params = mState.rasterizer.cullFace; break; 1.1201 + case GL_POLYGON_OFFSET_FILL: *params = mState.rasterizer.polygonOffsetFill; break; 1.1202 + case GL_SAMPLE_ALPHA_TO_COVERAGE: *params = mState.blend.sampleAlphaToCoverage; break; 1.1203 + case GL_SAMPLE_COVERAGE: *params = mState.sampleCoverage; break; 1.1204 + case GL_SCISSOR_TEST: *params = mState.scissorTest; break; 1.1205 + case GL_STENCIL_TEST: *params = mState.depthStencil.stencilTest; break; 1.1206 + case GL_DEPTH_TEST: *params = mState.depthStencil.depthTest; break; 1.1207 + case GL_BLEND: *params = mState.blend.blend; break; 1.1208 + case GL_DITHER: *params = mState.blend.dither; break; 1.1209 + case GL_CONTEXT_ROBUST_ACCESS_EXT: *params = mRobustAccess ? GL_TRUE : GL_FALSE; break; 1.1210 + default: 1.1211 + return false; 1.1212 + } 1.1213 + 1.1214 + return true; 1.1215 +} 1.1216 + 1.1217 +bool Context::getFloatv(GLenum pname, GLfloat *params) 1.1218 +{ 1.1219 + // Please note: DEPTH_CLEAR_VALUE is included in our internal getFloatv implementation 1.1220 + // because it is stored as a float, despite the fact that the GL ES 2.0 spec names 1.1221 + // GetIntegerv as its native query function. As it would require conversion in any 1.1222 + // case, this should make no difference to the calling application. 1.1223 + switch (pname) 1.1224 + { 1.1225 + case GL_LINE_WIDTH: *params = mState.lineWidth; break; 1.1226 + case GL_SAMPLE_COVERAGE_VALUE: *params = mState.sampleCoverageValue; break; 1.1227 + case GL_DEPTH_CLEAR_VALUE: *params = mState.depthClearValue; break; 1.1228 + case GL_POLYGON_OFFSET_FACTOR: *params = mState.rasterizer.polygonOffsetFactor; break; 1.1229 + case GL_POLYGON_OFFSET_UNITS: *params = mState.rasterizer.polygonOffsetUnits; break; 1.1230 + case GL_ALIASED_LINE_WIDTH_RANGE: 1.1231 + params[0] = gl::ALIASED_LINE_WIDTH_RANGE_MIN; 1.1232 + params[1] = gl::ALIASED_LINE_WIDTH_RANGE_MAX; 1.1233 + break; 1.1234 + case GL_ALIASED_POINT_SIZE_RANGE: 1.1235 + params[0] = gl::ALIASED_POINT_SIZE_RANGE_MIN; 1.1236 + params[1] = getMaximumPointSize(); 1.1237 + break; 1.1238 + case GL_DEPTH_RANGE: 1.1239 + params[0] = mState.zNear; 1.1240 + params[1] = mState.zFar; 1.1241 + break; 1.1242 + case GL_COLOR_CLEAR_VALUE: 1.1243 + params[0] = mState.colorClearValue.red; 1.1244 + params[1] = mState.colorClearValue.green; 1.1245 + params[2] = mState.colorClearValue.blue; 1.1246 + params[3] = mState.colorClearValue.alpha; 1.1247 + break; 1.1248 + case GL_BLEND_COLOR: 1.1249 + params[0] = mState.blendColor.red; 1.1250 + params[1] = mState.blendColor.green; 1.1251 + params[2] = mState.blendColor.blue; 1.1252 + params[3] = mState.blendColor.alpha; 1.1253 + break; 1.1254 + case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: 1.1255 + if (!supportsTextureFilterAnisotropy()) 1.1256 + { 1.1257 + return false; 1.1258 + } 1.1259 + *params = mMaxTextureAnisotropy; 1.1260 + break; 1.1261 + default: 1.1262 + return false; 1.1263 + } 1.1264 + 1.1265 + return true; 1.1266 +} 1.1267 + 1.1268 +bool Context::getIntegerv(GLenum pname, GLint *params) 1.1269 +{ 1.1270 + if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT) 1.1271 + { 1.1272 + unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0_EXT); 1.1273 + 1.1274 + if (colorAttachment >= mRenderer->getMaxRenderTargets()) 1.1275 + { 1.1276 + // return true to stop further operation in the parent call 1.1277 + return gl::error(GL_INVALID_OPERATION, true); 1.1278 + } 1.1279 + 1.1280 + Framebuffer *framebuffer = getDrawFramebuffer(); 1.1281 + 1.1282 + *params = framebuffer->getDrawBufferState(colorAttachment); 1.1283 + return true; 1.1284 + } 1.1285 + 1.1286 + // Please note: DEPTH_CLEAR_VALUE is not included in our internal getIntegerv implementation 1.1287 + // because it is stored as a float, despite the fact that the GL ES 2.0 spec names 1.1288 + // GetIntegerv as its native query function. As it would require conversion in any 1.1289 + // case, this should make no difference to the calling application. You may find it in 1.1290 + // Context::getFloatv. 1.1291 + switch (pname) 1.1292 + { 1.1293 + case GL_MAX_VERTEX_ATTRIBS: *params = gl::MAX_VERTEX_ATTRIBS; break; 1.1294 + case GL_MAX_VERTEX_UNIFORM_VECTORS: *params = mRenderer->getMaxVertexUniformVectors(); break; 1.1295 + case GL_MAX_VARYING_VECTORS: *params = mRenderer->getMaxVaryingVectors(); break; 1.1296 + case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: *params = mRenderer->getMaxCombinedTextureImageUnits(); break; 1.1297 + case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: *params = mRenderer->getMaxVertexTextureImageUnits(); break; 1.1298 + case GL_MAX_TEXTURE_IMAGE_UNITS: *params = gl::MAX_TEXTURE_IMAGE_UNITS; break; 1.1299 + case GL_MAX_FRAGMENT_UNIFORM_VECTORS: *params = mRenderer->getMaxFragmentUniformVectors(); break; 1.1300 + case GL_MAX_RENDERBUFFER_SIZE: *params = getMaximumRenderbufferDimension(); break; 1.1301 + case GL_MAX_COLOR_ATTACHMENTS_EXT: *params = mRenderer->getMaxRenderTargets(); break; 1.1302 + case GL_MAX_DRAW_BUFFERS_EXT: *params = mRenderer->getMaxRenderTargets(); break; 1.1303 + case GL_NUM_SHADER_BINARY_FORMATS: *params = 0; break; 1.1304 + case GL_SHADER_BINARY_FORMATS: /* no shader binary formats are supported */ break; 1.1305 + case GL_ARRAY_BUFFER_BINDING: *params = mState.arrayBuffer.id(); break; 1.1306 + case GL_ELEMENT_ARRAY_BUFFER_BINDING: *params = mState.elementArrayBuffer.id(); break; 1.1307 + //case GL_FRAMEBUFFER_BINDING: // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE 1.1308 + case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE: *params = mState.drawFramebuffer; break; 1.1309 + case GL_READ_FRAMEBUFFER_BINDING_ANGLE: *params = mState.readFramebuffer; break; 1.1310 + case GL_RENDERBUFFER_BINDING: *params = mState.renderbuffer.id(); break; 1.1311 + case GL_CURRENT_PROGRAM: *params = mState.currentProgram; break; 1.1312 + case GL_PACK_ALIGNMENT: *params = mState.packAlignment; break; 1.1313 + case GL_PACK_REVERSE_ROW_ORDER_ANGLE: *params = mState.packReverseRowOrder; break; 1.1314 + case GL_UNPACK_ALIGNMENT: *params = mState.unpackAlignment; break; 1.1315 + case GL_GENERATE_MIPMAP_HINT: *params = mState.generateMipmapHint; break; 1.1316 + case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: *params = mState.fragmentShaderDerivativeHint; break; 1.1317 + case GL_ACTIVE_TEXTURE: *params = (mState.activeSampler + GL_TEXTURE0); break; 1.1318 + case GL_STENCIL_FUNC: *params = mState.depthStencil.stencilFunc; break; 1.1319 + case GL_STENCIL_REF: *params = mState.stencilRef; break; 1.1320 + case GL_STENCIL_VALUE_MASK: *params = mState.depthStencil.stencilMask; break; 1.1321 + case GL_STENCIL_BACK_FUNC: *params = mState.depthStencil.stencilBackFunc; break; 1.1322 + case GL_STENCIL_BACK_REF: *params = mState.stencilBackRef; break; 1.1323 + case GL_STENCIL_BACK_VALUE_MASK: *params = mState.depthStencil.stencilBackMask; break; 1.1324 + case GL_STENCIL_FAIL: *params = mState.depthStencil.stencilFail; break; 1.1325 + case GL_STENCIL_PASS_DEPTH_FAIL: *params = mState.depthStencil.stencilPassDepthFail; break; 1.1326 + case GL_STENCIL_PASS_DEPTH_PASS: *params = mState.depthStencil.stencilPassDepthPass; break; 1.1327 + case GL_STENCIL_BACK_FAIL: *params = mState.depthStencil.stencilBackFail; break; 1.1328 + case GL_STENCIL_BACK_PASS_DEPTH_FAIL: *params = mState.depthStencil.stencilBackPassDepthFail; break; 1.1329 + case GL_STENCIL_BACK_PASS_DEPTH_PASS: *params = mState.depthStencil.stencilBackPassDepthPass; break; 1.1330 + case GL_DEPTH_FUNC: *params = mState.depthStencil.depthFunc; break; 1.1331 + case GL_BLEND_SRC_RGB: *params = mState.blend.sourceBlendRGB; break; 1.1332 + case GL_BLEND_SRC_ALPHA: *params = mState.blend.sourceBlendAlpha; break; 1.1333 + case GL_BLEND_DST_RGB: *params = mState.blend.destBlendRGB; break; 1.1334 + case GL_BLEND_DST_ALPHA: *params = mState.blend.destBlendAlpha; break; 1.1335 + case GL_BLEND_EQUATION_RGB: *params = mState.blend.blendEquationRGB; break; 1.1336 + case GL_BLEND_EQUATION_ALPHA: *params = mState.blend.blendEquationAlpha; break; 1.1337 + case GL_STENCIL_WRITEMASK: *params = mState.depthStencil.stencilWritemask; break; 1.1338 + case GL_STENCIL_BACK_WRITEMASK: *params = mState.depthStencil.stencilBackWritemask; break; 1.1339 + case GL_STENCIL_CLEAR_VALUE: *params = mState.stencilClearValue; break; 1.1340 + case GL_SUBPIXEL_BITS: *params = 4; break; 1.1341 + case GL_MAX_TEXTURE_SIZE: *params = getMaximumTextureDimension(); break; 1.1342 + case GL_MAX_CUBE_MAP_TEXTURE_SIZE: *params = getMaximumCubeTextureDimension(); break; 1.1343 + case GL_NUM_COMPRESSED_TEXTURE_FORMATS: 1.1344 + params[0] = mNumCompressedTextureFormats; 1.1345 + break; 1.1346 + case GL_MAX_SAMPLES_ANGLE: 1.1347 + { 1.1348 + GLsizei maxSamples = getMaxSupportedSamples(); 1.1349 + if (maxSamples != 0) 1.1350 + { 1.1351 + *params = maxSamples; 1.1352 + } 1.1353 + else 1.1354 + { 1.1355 + return false; 1.1356 + } 1.1357 + 1.1358 + break; 1.1359 + } 1.1360 + case GL_SAMPLE_BUFFERS: 1.1361 + case GL_SAMPLES: 1.1362 + { 1.1363 + gl::Framebuffer *framebuffer = getDrawFramebuffer(); 1.1364 + if (framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE) 1.1365 + { 1.1366 + switch (pname) 1.1367 + { 1.1368 + case GL_SAMPLE_BUFFERS: 1.1369 + if (framebuffer->getSamples() != 0) 1.1370 + { 1.1371 + *params = 1; 1.1372 + } 1.1373 + else 1.1374 + { 1.1375 + *params = 0; 1.1376 + } 1.1377 + break; 1.1378 + case GL_SAMPLES: 1.1379 + *params = framebuffer->getSamples(); 1.1380 + break; 1.1381 + } 1.1382 + } 1.1383 + else 1.1384 + { 1.1385 + *params = 0; 1.1386 + } 1.1387 + } 1.1388 + break; 1.1389 + case GL_IMPLEMENTATION_COLOR_READ_TYPE: 1.1390 + case GL_IMPLEMENTATION_COLOR_READ_FORMAT: 1.1391 + { 1.1392 + GLenum format, type; 1.1393 + if (getCurrentReadFormatType(&format, &type)) 1.1394 + { 1.1395 + if (pname == GL_IMPLEMENTATION_COLOR_READ_FORMAT) 1.1396 + *params = format; 1.1397 + else 1.1398 + *params = type; 1.1399 + } 1.1400 + } 1.1401 + break; 1.1402 + case GL_MAX_VIEWPORT_DIMS: 1.1403 + { 1.1404 + params[0] = mMaxViewportDimension; 1.1405 + params[1] = mMaxViewportDimension; 1.1406 + } 1.1407 + break; 1.1408 + case GL_COMPRESSED_TEXTURE_FORMATS: 1.1409 + { 1.1410 + if (supportsDXT1Textures()) 1.1411 + { 1.1412 + *params++ = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; 1.1413 + *params++ = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; 1.1414 + } 1.1415 + if (supportsDXT3Textures()) 1.1416 + { 1.1417 + *params++ = GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE; 1.1418 + } 1.1419 + if (supportsDXT5Textures()) 1.1420 + { 1.1421 + *params++ = GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE; 1.1422 + } 1.1423 + } 1.1424 + break; 1.1425 + case GL_VIEWPORT: 1.1426 + params[0] = mState.viewport.x; 1.1427 + params[1] = mState.viewport.y; 1.1428 + params[2] = mState.viewport.width; 1.1429 + params[3] = mState.viewport.height; 1.1430 + break; 1.1431 + case GL_SCISSOR_BOX: 1.1432 + params[0] = mState.scissor.x; 1.1433 + params[1] = mState.scissor.y; 1.1434 + params[2] = mState.scissor.width; 1.1435 + params[3] = mState.scissor.height; 1.1436 + break; 1.1437 + case GL_CULL_FACE_MODE: *params = mState.rasterizer.cullMode; break; 1.1438 + case GL_FRONT_FACE: *params = mState.rasterizer.frontFace; break; 1.1439 + case GL_RED_BITS: 1.1440 + case GL_GREEN_BITS: 1.1441 + case GL_BLUE_BITS: 1.1442 + case GL_ALPHA_BITS: 1.1443 + { 1.1444 + gl::Framebuffer *framebuffer = getDrawFramebuffer(); 1.1445 + gl::Renderbuffer *colorbuffer = framebuffer->getFirstColorbuffer(); 1.1446 + 1.1447 + if (colorbuffer) 1.1448 + { 1.1449 + switch (pname) 1.1450 + { 1.1451 + case GL_RED_BITS: *params = colorbuffer->getRedSize(); break; 1.1452 + case GL_GREEN_BITS: *params = colorbuffer->getGreenSize(); break; 1.1453 + case GL_BLUE_BITS: *params = colorbuffer->getBlueSize(); break; 1.1454 + case GL_ALPHA_BITS: *params = colorbuffer->getAlphaSize(); break; 1.1455 + } 1.1456 + } 1.1457 + else 1.1458 + { 1.1459 + *params = 0; 1.1460 + } 1.1461 + } 1.1462 + break; 1.1463 + case GL_DEPTH_BITS: 1.1464 + { 1.1465 + gl::Framebuffer *framebuffer = getDrawFramebuffer(); 1.1466 + gl::Renderbuffer *depthbuffer = framebuffer->getDepthbuffer(); 1.1467 + 1.1468 + if (depthbuffer) 1.1469 + { 1.1470 + *params = depthbuffer->getDepthSize(); 1.1471 + } 1.1472 + else 1.1473 + { 1.1474 + *params = 0; 1.1475 + } 1.1476 + } 1.1477 + break; 1.1478 + case GL_STENCIL_BITS: 1.1479 + { 1.1480 + gl::Framebuffer *framebuffer = getDrawFramebuffer(); 1.1481 + gl::Renderbuffer *stencilbuffer = framebuffer->getStencilbuffer(); 1.1482 + 1.1483 + if (stencilbuffer) 1.1484 + { 1.1485 + *params = stencilbuffer->getStencilSize(); 1.1486 + } 1.1487 + else 1.1488 + { 1.1489 + *params = 0; 1.1490 + } 1.1491 + } 1.1492 + break; 1.1493 + case GL_TEXTURE_BINDING_2D: 1.1494 + { 1.1495 + if (mState.activeSampler > mRenderer->getMaxCombinedTextureImageUnits() - 1) 1.1496 + { 1.1497 + gl::error(GL_INVALID_OPERATION); 1.1498 + return false; 1.1499 + } 1.1500 + 1.1501 + *params = mState.samplerTexture[TEXTURE_2D][mState.activeSampler].id(); 1.1502 + } 1.1503 + break; 1.1504 + case GL_TEXTURE_BINDING_CUBE_MAP: 1.1505 + { 1.1506 + if (mState.activeSampler > mRenderer->getMaxCombinedTextureImageUnits() - 1) 1.1507 + { 1.1508 + gl::error(GL_INVALID_OPERATION); 1.1509 + return false; 1.1510 + } 1.1511 + 1.1512 + *params = mState.samplerTexture[TEXTURE_CUBE][mState.activeSampler].id(); 1.1513 + } 1.1514 + break; 1.1515 + case GL_RESET_NOTIFICATION_STRATEGY_EXT: 1.1516 + *params = mResetStrategy; 1.1517 + break; 1.1518 + case GL_NUM_PROGRAM_BINARY_FORMATS_OES: 1.1519 + *params = 1; 1.1520 + break; 1.1521 + case GL_PROGRAM_BINARY_FORMATS_OES: 1.1522 + *params = GL_PROGRAM_BINARY_ANGLE; 1.1523 + break; 1.1524 + default: 1.1525 + return false; 1.1526 + } 1.1527 + 1.1528 + return true; 1.1529 +} 1.1530 + 1.1531 +bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams) 1.1532 +{ 1.1533 + if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT) 1.1534 + { 1.1535 + *type = GL_INT; 1.1536 + *numParams = 1; 1.1537 + return true; 1.1538 + } 1.1539 + 1.1540 + // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation 1.1541 + // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due 1.1542 + // to the fact that it is stored internally as a float, and so would require conversion 1.1543 + // if returned from Context::getIntegerv. Since this conversion is already implemented 1.1544 + // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we 1.1545 + // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling 1.1546 + // application. 1.1547 + switch (pname) 1.1548 + { 1.1549 + case GL_COMPRESSED_TEXTURE_FORMATS: 1.1550 + { 1.1551 + *type = GL_INT; 1.1552 + *numParams = mNumCompressedTextureFormats; 1.1553 + } 1.1554 + break; 1.1555 + case GL_SHADER_BINARY_FORMATS: 1.1556 + { 1.1557 + *type = GL_INT; 1.1558 + *numParams = 0; 1.1559 + } 1.1560 + break; 1.1561 + case GL_MAX_VERTEX_ATTRIBS: 1.1562 + case GL_MAX_VERTEX_UNIFORM_VECTORS: 1.1563 + case GL_MAX_VARYING_VECTORS: 1.1564 + case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: 1.1565 + case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: 1.1566 + case GL_MAX_TEXTURE_IMAGE_UNITS: 1.1567 + case GL_MAX_FRAGMENT_UNIFORM_VECTORS: 1.1568 + case GL_MAX_RENDERBUFFER_SIZE: 1.1569 + case GL_MAX_COLOR_ATTACHMENTS_EXT: 1.1570 + case GL_MAX_DRAW_BUFFERS_EXT: 1.1571 + case GL_NUM_SHADER_BINARY_FORMATS: 1.1572 + case GL_NUM_COMPRESSED_TEXTURE_FORMATS: 1.1573 + case GL_ARRAY_BUFFER_BINDING: 1.1574 + case GL_FRAMEBUFFER_BINDING: 1.1575 + case GL_RENDERBUFFER_BINDING: 1.1576 + case GL_CURRENT_PROGRAM: 1.1577 + case GL_PACK_ALIGNMENT: 1.1578 + case GL_PACK_REVERSE_ROW_ORDER_ANGLE: 1.1579 + case GL_UNPACK_ALIGNMENT: 1.1580 + case GL_GENERATE_MIPMAP_HINT: 1.1581 + case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: 1.1582 + case GL_RED_BITS: 1.1583 + case GL_GREEN_BITS: 1.1584 + case GL_BLUE_BITS: 1.1585 + case GL_ALPHA_BITS: 1.1586 + case GL_DEPTH_BITS: 1.1587 + case GL_STENCIL_BITS: 1.1588 + case GL_ELEMENT_ARRAY_BUFFER_BINDING: 1.1589 + case GL_CULL_FACE_MODE: 1.1590 + case GL_FRONT_FACE: 1.1591 + case GL_ACTIVE_TEXTURE: 1.1592 + case GL_STENCIL_FUNC: 1.1593 + case GL_STENCIL_VALUE_MASK: 1.1594 + case GL_STENCIL_REF: 1.1595 + case GL_STENCIL_FAIL: 1.1596 + case GL_STENCIL_PASS_DEPTH_FAIL: 1.1597 + case GL_STENCIL_PASS_DEPTH_PASS: 1.1598 + case GL_STENCIL_BACK_FUNC: 1.1599 + case GL_STENCIL_BACK_VALUE_MASK: 1.1600 + case GL_STENCIL_BACK_REF: 1.1601 + case GL_STENCIL_BACK_FAIL: 1.1602 + case GL_STENCIL_BACK_PASS_DEPTH_FAIL: 1.1603 + case GL_STENCIL_BACK_PASS_DEPTH_PASS: 1.1604 + case GL_DEPTH_FUNC: 1.1605 + case GL_BLEND_SRC_RGB: 1.1606 + case GL_BLEND_SRC_ALPHA: 1.1607 + case GL_BLEND_DST_RGB: 1.1608 + case GL_BLEND_DST_ALPHA: 1.1609 + case GL_BLEND_EQUATION_RGB: 1.1610 + case GL_BLEND_EQUATION_ALPHA: 1.1611 + case GL_STENCIL_WRITEMASK: 1.1612 + case GL_STENCIL_BACK_WRITEMASK: 1.1613 + case GL_STENCIL_CLEAR_VALUE: 1.1614 + case GL_SUBPIXEL_BITS: 1.1615 + case GL_MAX_TEXTURE_SIZE: 1.1616 + case GL_MAX_CUBE_MAP_TEXTURE_SIZE: 1.1617 + case GL_SAMPLE_BUFFERS: 1.1618 + case GL_SAMPLES: 1.1619 + case GL_IMPLEMENTATION_COLOR_READ_TYPE: 1.1620 + case GL_IMPLEMENTATION_COLOR_READ_FORMAT: 1.1621 + case GL_TEXTURE_BINDING_2D: 1.1622 + case GL_TEXTURE_BINDING_CUBE_MAP: 1.1623 + case GL_RESET_NOTIFICATION_STRATEGY_EXT: 1.1624 + case GL_NUM_PROGRAM_BINARY_FORMATS_OES: 1.1625 + case GL_PROGRAM_BINARY_FORMATS_OES: 1.1626 + { 1.1627 + *type = GL_INT; 1.1628 + *numParams = 1; 1.1629 + } 1.1630 + break; 1.1631 + case GL_MAX_SAMPLES_ANGLE: 1.1632 + { 1.1633 + if (getMaxSupportedSamples() != 0) 1.1634 + { 1.1635 + *type = GL_INT; 1.1636 + *numParams = 1; 1.1637 + } 1.1638 + else 1.1639 + { 1.1640 + return false; 1.1641 + } 1.1642 + } 1.1643 + break; 1.1644 + case GL_MAX_VIEWPORT_DIMS: 1.1645 + { 1.1646 + *type = GL_INT; 1.1647 + *numParams = 2; 1.1648 + } 1.1649 + break; 1.1650 + case GL_VIEWPORT: 1.1651 + case GL_SCISSOR_BOX: 1.1652 + { 1.1653 + *type = GL_INT; 1.1654 + *numParams = 4; 1.1655 + } 1.1656 + break; 1.1657 + case GL_SHADER_COMPILER: 1.1658 + case GL_SAMPLE_COVERAGE_INVERT: 1.1659 + case GL_DEPTH_WRITEMASK: 1.1660 + case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled, 1.1661 + case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries. 1.1662 + case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as bool-natural 1.1663 + case GL_SAMPLE_COVERAGE: 1.1664 + case GL_SCISSOR_TEST: 1.1665 + case GL_STENCIL_TEST: 1.1666 + case GL_DEPTH_TEST: 1.1667 + case GL_BLEND: 1.1668 + case GL_DITHER: 1.1669 + case GL_CONTEXT_ROBUST_ACCESS_EXT: 1.1670 + { 1.1671 + *type = GL_BOOL; 1.1672 + *numParams = 1; 1.1673 + } 1.1674 + break; 1.1675 + case GL_COLOR_WRITEMASK: 1.1676 + { 1.1677 + *type = GL_BOOL; 1.1678 + *numParams = 4; 1.1679 + } 1.1680 + break; 1.1681 + case GL_POLYGON_OFFSET_FACTOR: 1.1682 + case GL_POLYGON_OFFSET_UNITS: 1.1683 + case GL_SAMPLE_COVERAGE_VALUE: 1.1684 + case GL_DEPTH_CLEAR_VALUE: 1.1685 + case GL_LINE_WIDTH: 1.1686 + { 1.1687 + *type = GL_FLOAT; 1.1688 + *numParams = 1; 1.1689 + } 1.1690 + break; 1.1691 + case GL_ALIASED_LINE_WIDTH_RANGE: 1.1692 + case GL_ALIASED_POINT_SIZE_RANGE: 1.1693 + case GL_DEPTH_RANGE: 1.1694 + { 1.1695 + *type = GL_FLOAT; 1.1696 + *numParams = 2; 1.1697 + } 1.1698 + break; 1.1699 + case GL_COLOR_CLEAR_VALUE: 1.1700 + case GL_BLEND_COLOR: 1.1701 + { 1.1702 + *type = GL_FLOAT; 1.1703 + *numParams = 4; 1.1704 + } 1.1705 + break; 1.1706 + case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: 1.1707 + if (!supportsTextureFilterAnisotropy()) 1.1708 + { 1.1709 + return false; 1.1710 + } 1.1711 + *type = GL_FLOAT; 1.1712 + *numParams = 1; 1.1713 + break; 1.1714 + default: 1.1715 + return false; 1.1716 + } 1.1717 + 1.1718 + return true; 1.1719 +} 1.1720 + 1.1721 +// Applies the render target surface, depth stencil surface, viewport rectangle and 1.1722 +// scissor rectangle to the renderer 1.1723 +bool Context::applyRenderTarget(GLenum drawMode, bool ignoreViewport) 1.1724 +{ 1.1725 + Framebuffer *framebufferObject = getDrawFramebuffer(); 1.1726 + 1.1727 + if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE) 1.1728 + { 1.1729 + return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false); 1.1730 + } 1.1731 + 1.1732 + mRenderer->applyRenderTarget(framebufferObject); 1.1733 + 1.1734 + if (!mRenderer->setViewport(mState.viewport, mState.zNear, mState.zFar, drawMode, mState.rasterizer.frontFace, 1.1735 + ignoreViewport)) 1.1736 + { 1.1737 + return false; 1.1738 + } 1.1739 + 1.1740 + mRenderer->setScissorRectangle(mState.scissor, mState.scissorTest); 1.1741 + 1.1742 + return true; 1.1743 +} 1.1744 + 1.1745 +// Applies the fixed-function state (culling, depth test, alpha blending, stenciling, etc) to the Direct3D 9 device 1.1746 +void Context::applyState(GLenum drawMode) 1.1747 +{ 1.1748 + Framebuffer *framebufferObject = getDrawFramebuffer(); 1.1749 + int samples = framebufferObject->getSamples(); 1.1750 + 1.1751 + mState.rasterizer.pointDrawMode = (drawMode == GL_POINTS); 1.1752 + mState.rasterizer.multiSample = (samples != 0); 1.1753 + mRenderer->setRasterizerState(mState.rasterizer); 1.1754 + 1.1755 + unsigned int mask = 0; 1.1756 + if (mState.sampleCoverage) 1.1757 + { 1.1758 + if (mState.sampleCoverageValue != 0) 1.1759 + { 1.1760 + 1.1761 + float threshold = 0.5f; 1.1762 + 1.1763 + for (int i = 0; i < samples; ++i) 1.1764 + { 1.1765 + mask <<= 1; 1.1766 + 1.1767 + if ((i + 1) * mState.sampleCoverageValue >= threshold) 1.1768 + { 1.1769 + threshold += 1.0f; 1.1770 + mask |= 1; 1.1771 + } 1.1772 + } 1.1773 + } 1.1774 + 1.1775 + if (mState.sampleCoverageInvert) 1.1776 + { 1.1777 + mask = ~mask; 1.1778 + } 1.1779 + } 1.1780 + else 1.1781 + { 1.1782 + mask = 0xFFFFFFFF; 1.1783 + } 1.1784 + mRenderer->setBlendState(mState.blend, mState.blendColor, mask); 1.1785 + 1.1786 + mRenderer->setDepthStencilState(mState.depthStencil, mState.stencilRef, mState.stencilBackRef, 1.1787 + mState.rasterizer.frontFace == GL_CCW); 1.1788 +} 1.1789 + 1.1790 +// Applies the shaders and shader constants to the Direct3D 9 device 1.1791 +void Context::applyShaders() 1.1792 +{ 1.1793 + ProgramBinary *programBinary = getCurrentProgramBinary(); 1.1794 + 1.1795 + mRenderer->applyShaders(programBinary); 1.1796 + 1.1797 + programBinary->applyUniforms(); 1.1798 +} 1.1799 + 1.1800 +// Applies the textures and sampler states to the Direct3D 9 device 1.1801 +void Context::applyTextures() 1.1802 +{ 1.1803 + applyTextures(SAMPLER_PIXEL); 1.1804 + 1.1805 + if (mSupportsVertexTexture) 1.1806 + { 1.1807 + applyTextures(SAMPLER_VERTEX); 1.1808 + } 1.1809 +} 1.1810 + 1.1811 +// For each Direct3D 9 sampler of either the pixel or vertex stage, 1.1812 +// looks up the corresponding OpenGL texture image unit and texture type, 1.1813 +// and sets the texture and its addressing/filtering state (or NULL when inactive). 1.1814 +void Context::applyTextures(SamplerType type) 1.1815 +{ 1.1816 + ProgramBinary *programBinary = getCurrentProgramBinary(); 1.1817 + 1.1818 + // Range of Direct3D samplers of given sampler type 1.1819 + int samplerCount = (type == SAMPLER_PIXEL) ? MAX_TEXTURE_IMAGE_UNITS : mRenderer->getMaxVertexTextureImageUnits(); 1.1820 + int samplerRange = programBinary->getUsedSamplerRange(type); 1.1821 + 1.1822 + for (int samplerIndex = 0; samplerIndex < samplerRange; samplerIndex++) 1.1823 + { 1.1824 + int textureUnit = programBinary->getSamplerMapping(type, samplerIndex); // OpenGL texture image unit index 1.1825 + 1.1826 + if (textureUnit != -1) 1.1827 + { 1.1828 + TextureType textureType = programBinary->getSamplerTextureType(type, samplerIndex); 1.1829 + Texture *texture = getSamplerTexture(textureUnit, textureType); 1.1830 + 1.1831 + if (texture->isSamplerComplete()) 1.1832 + { 1.1833 + SamplerState samplerState; 1.1834 + texture->getSamplerState(&samplerState); 1.1835 + mRenderer->setSamplerState(type, samplerIndex, samplerState); 1.1836 + 1.1837 + mRenderer->setTexture(type, samplerIndex, texture); 1.1838 + 1.1839 + texture->resetDirty(); 1.1840 + } 1.1841 + else 1.1842 + { 1.1843 + mRenderer->setTexture(type, samplerIndex, getIncompleteTexture(textureType)); 1.1844 + } 1.1845 + } 1.1846 + else 1.1847 + { 1.1848 + mRenderer->setTexture(type, samplerIndex, NULL); 1.1849 + } 1.1850 + } 1.1851 + 1.1852 + for (int samplerIndex = samplerRange; samplerIndex < samplerCount; samplerIndex++) 1.1853 + { 1.1854 + mRenderer->setTexture(type, samplerIndex, NULL); 1.1855 + } 1.1856 +} 1.1857 + 1.1858 +void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, 1.1859 + GLenum format, GLenum type, GLsizei *bufSize, void* pixels) 1.1860 +{ 1.1861 + Framebuffer *framebuffer = getReadFramebuffer(); 1.1862 + 1.1863 + if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) 1.1864 + { 1.1865 + return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION); 1.1866 + } 1.1867 + 1.1868 + if (getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0) 1.1869 + { 1.1870 + return gl::error(GL_INVALID_OPERATION); 1.1871 + } 1.1872 + 1.1873 + GLsizei outputPitch = ComputePitch(width, ConvertSizedInternalFormat(format, type), getPackAlignment()); 1.1874 + // sized query sanity check 1.1875 + if (bufSize) 1.1876 + { 1.1877 + int requiredSize = outputPitch * height; 1.1878 + if (requiredSize > *bufSize) 1.1879 + { 1.1880 + return gl::error(GL_INVALID_OPERATION); 1.1881 + } 1.1882 + } 1.1883 + 1.1884 + mRenderer->readPixels(framebuffer, x, y, width, height, format, type, outputPitch, getPackReverseRowOrder(), getPackAlignment(), pixels); 1.1885 +} 1.1886 + 1.1887 +void Context::clear(GLbitfield mask) 1.1888 +{ 1.1889 + Framebuffer *framebufferObject = getDrawFramebuffer(); 1.1890 + 1.1891 + if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE) 1.1892 + { 1.1893 + return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION); 1.1894 + } 1.1895 + 1.1896 + DWORD flags = 0; 1.1897 + GLbitfield finalMask = 0; 1.1898 + 1.1899 + if (mask & GL_COLOR_BUFFER_BIT) 1.1900 + { 1.1901 + mask &= ~GL_COLOR_BUFFER_BIT; 1.1902 + 1.1903 + if (framebufferObject->hasEnabledColorAttachment()) 1.1904 + { 1.1905 + finalMask |= GL_COLOR_BUFFER_BIT; 1.1906 + } 1.1907 + } 1.1908 + 1.1909 + if (mask & GL_DEPTH_BUFFER_BIT) 1.1910 + { 1.1911 + mask &= ~GL_DEPTH_BUFFER_BIT; 1.1912 + if (mState.depthStencil.depthMask && framebufferObject->getDepthbufferType() != GL_NONE) 1.1913 + { 1.1914 + finalMask |= GL_DEPTH_BUFFER_BIT; 1.1915 + } 1.1916 + } 1.1917 + 1.1918 + if (mask & GL_STENCIL_BUFFER_BIT) 1.1919 + { 1.1920 + mask &= ~GL_STENCIL_BUFFER_BIT; 1.1921 + if (framebufferObject->getStencilbufferType() != GL_NONE) 1.1922 + { 1.1923 + rx::RenderTarget *depthStencil = framebufferObject->getStencilbuffer()->getDepthStencil(); 1.1924 + if (!depthStencil) 1.1925 + { 1.1926 + ERR("Depth stencil pointer unexpectedly null."); 1.1927 + return; 1.1928 + } 1.1929 + 1.1930 + if (GetStencilSize(depthStencil->getActualFormat()) > 0) 1.1931 + { 1.1932 + finalMask |= GL_STENCIL_BUFFER_BIT; 1.1933 + } 1.1934 + } 1.1935 + } 1.1936 + 1.1937 + if (mask != 0) 1.1938 + { 1.1939 + return gl::error(GL_INVALID_VALUE); 1.1940 + } 1.1941 + 1.1942 + if (!applyRenderTarget(GL_TRIANGLES, true)) // Clips the clear to the scissor rectangle but not the viewport 1.1943 + { 1.1944 + return; 1.1945 + } 1.1946 + 1.1947 + ClearParameters clearParams; 1.1948 + clearParams.mask = finalMask; 1.1949 + clearParams.colorClearValue = mState.colorClearValue; 1.1950 + clearParams.colorMaskRed = mState.blend.colorMaskRed; 1.1951 + clearParams.colorMaskGreen = mState.blend.colorMaskGreen; 1.1952 + clearParams.colorMaskBlue = mState.blend.colorMaskBlue; 1.1953 + clearParams.colorMaskAlpha = mState.blend.colorMaskAlpha; 1.1954 + clearParams.depthClearValue = mState.depthClearValue; 1.1955 + clearParams.stencilClearValue = mState.stencilClearValue; 1.1956 + clearParams.stencilWriteMask = mState.depthStencil.stencilWritemask; 1.1957 + 1.1958 + mRenderer->clear(clearParams, framebufferObject); 1.1959 +} 1.1960 + 1.1961 +void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instances) 1.1962 +{ 1.1963 + if (!mState.currentProgram) 1.1964 + { 1.1965 + return gl::error(GL_INVALID_OPERATION); 1.1966 + } 1.1967 + 1.1968 + if (!mRenderer->applyPrimitiveType(mode, count)) 1.1969 + { 1.1970 + return; 1.1971 + } 1.1972 + 1.1973 + if (!applyRenderTarget(mode, false)) 1.1974 + { 1.1975 + return; 1.1976 + } 1.1977 + 1.1978 + applyState(mode); 1.1979 + 1.1980 + ProgramBinary *programBinary = getCurrentProgramBinary(); 1.1981 + 1.1982 + GLenum err = mRenderer->applyVertexBuffer(programBinary, mState.vertexAttribute, first, count, instances); 1.1983 + if (err != GL_NO_ERROR) 1.1984 + { 1.1985 + return gl::error(err); 1.1986 + } 1.1987 + 1.1988 + applyShaders(); 1.1989 + applyTextures(); 1.1990 + 1.1991 + if (!programBinary->validateSamplers(NULL)) 1.1992 + { 1.1993 + return gl::error(GL_INVALID_OPERATION); 1.1994 + } 1.1995 + 1.1996 + if (!skipDraw(mode)) 1.1997 + { 1.1998 + mRenderer->drawArrays(mode, count, instances); 1.1999 + } 1.2000 +} 1.2001 + 1.2002 +void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instances) 1.2003 +{ 1.2004 + if (!mState.currentProgram) 1.2005 + { 1.2006 + return gl::error(GL_INVALID_OPERATION); 1.2007 + } 1.2008 + 1.2009 + if (!indices && !mState.elementArrayBuffer) 1.2010 + { 1.2011 + return gl::error(GL_INVALID_OPERATION); 1.2012 + } 1.2013 + 1.2014 + if (!mRenderer->applyPrimitiveType(mode, count)) 1.2015 + { 1.2016 + return; 1.2017 + } 1.2018 + 1.2019 + if (!applyRenderTarget(mode, false)) 1.2020 + { 1.2021 + return; 1.2022 + } 1.2023 + 1.2024 + applyState(mode); 1.2025 + 1.2026 + rx::TranslatedIndexData indexInfo; 1.2027 + GLenum err = mRenderer->applyIndexBuffer(indices, mState.elementArrayBuffer.get(), count, mode, type, &indexInfo); 1.2028 + if (err != GL_NO_ERROR) 1.2029 + { 1.2030 + return gl::error(err); 1.2031 + } 1.2032 + 1.2033 + ProgramBinary *programBinary = getCurrentProgramBinary(); 1.2034 + 1.2035 + GLsizei vertexCount = indexInfo.maxIndex - indexInfo.minIndex + 1; 1.2036 + err = mRenderer->applyVertexBuffer(programBinary, mState.vertexAttribute, indexInfo.minIndex, vertexCount, instances); 1.2037 + if (err != GL_NO_ERROR) 1.2038 + { 1.2039 + return gl::error(err); 1.2040 + } 1.2041 + 1.2042 + applyShaders(); 1.2043 + applyTextures(); 1.2044 + 1.2045 + if (!programBinary->validateSamplers(NULL)) 1.2046 + { 1.2047 + return gl::error(GL_INVALID_OPERATION); 1.2048 + } 1.2049 + 1.2050 + if (!skipDraw(mode)) 1.2051 + { 1.2052 + mRenderer->drawElements(mode, count, type, indices, mState.elementArrayBuffer.get(), indexInfo, instances); 1.2053 + } 1.2054 +} 1.2055 + 1.2056 +// Implements glFlush when block is false, glFinish when block is true 1.2057 +void Context::sync(bool block) 1.2058 +{ 1.2059 + mRenderer->sync(block); 1.2060 +} 1.2061 + 1.2062 +void Context::recordInvalidEnum() 1.2063 +{ 1.2064 + mInvalidEnum = true; 1.2065 +} 1.2066 + 1.2067 +void Context::recordInvalidValue() 1.2068 +{ 1.2069 + mInvalidValue = true; 1.2070 +} 1.2071 + 1.2072 +void Context::recordInvalidOperation() 1.2073 +{ 1.2074 + mInvalidOperation = true; 1.2075 +} 1.2076 + 1.2077 +void Context::recordOutOfMemory() 1.2078 +{ 1.2079 + mOutOfMemory = true; 1.2080 +} 1.2081 + 1.2082 +void Context::recordInvalidFramebufferOperation() 1.2083 +{ 1.2084 + mInvalidFramebufferOperation = true; 1.2085 +} 1.2086 + 1.2087 +// Get one of the recorded errors and clear its flag, if any. 1.2088 +// [OpenGL ES 2.0.24] section 2.5 page 13. 1.2089 +GLenum Context::getError() 1.2090 +{ 1.2091 + if (mInvalidEnum) 1.2092 + { 1.2093 + mInvalidEnum = false; 1.2094 + 1.2095 + return GL_INVALID_ENUM; 1.2096 + } 1.2097 + 1.2098 + if (mInvalidValue) 1.2099 + { 1.2100 + mInvalidValue = false; 1.2101 + 1.2102 + return GL_INVALID_VALUE; 1.2103 + } 1.2104 + 1.2105 + if (mInvalidOperation) 1.2106 + { 1.2107 + mInvalidOperation = false; 1.2108 + 1.2109 + return GL_INVALID_OPERATION; 1.2110 + } 1.2111 + 1.2112 + if (mOutOfMemory) 1.2113 + { 1.2114 + mOutOfMemory = false; 1.2115 + 1.2116 + return GL_OUT_OF_MEMORY; 1.2117 + } 1.2118 + 1.2119 + if (mInvalidFramebufferOperation) 1.2120 + { 1.2121 + mInvalidFramebufferOperation = false; 1.2122 + 1.2123 + return GL_INVALID_FRAMEBUFFER_OPERATION; 1.2124 + } 1.2125 + 1.2126 + return GL_NO_ERROR; 1.2127 +} 1.2128 + 1.2129 +GLenum Context::getResetStatus() 1.2130 +{ 1.2131 + if (mResetStatus == GL_NO_ERROR && !mContextLost) 1.2132 + { 1.2133 + // mResetStatus will be set by the markContextLost callback 1.2134 + // in the case a notification is sent 1.2135 + mRenderer->testDeviceLost(true); 1.2136 + } 1.2137 + 1.2138 + GLenum status = mResetStatus; 1.2139 + 1.2140 + if (mResetStatus != GL_NO_ERROR) 1.2141 + { 1.2142 + ASSERT(mContextLost); 1.2143 + 1.2144 + if (mRenderer->testDeviceResettable()) 1.2145 + { 1.2146 + mResetStatus = GL_NO_ERROR; 1.2147 + } 1.2148 + } 1.2149 + 1.2150 + return status; 1.2151 +} 1.2152 + 1.2153 +bool Context::isResetNotificationEnabled() 1.2154 +{ 1.2155 + return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT); 1.2156 +} 1.2157 + 1.2158 +int Context::getMajorShaderModel() const 1.2159 +{ 1.2160 + return mMajorShaderModel; 1.2161 +} 1.2162 + 1.2163 +float Context::getMaximumPointSize() const 1.2164 +{ 1.2165 + return mMaximumPointSize; 1.2166 +} 1.2167 + 1.2168 +unsigned int Context::getMaximumCombinedTextureImageUnits() const 1.2169 +{ 1.2170 + return mRenderer->getMaxCombinedTextureImageUnits(); 1.2171 +} 1.2172 + 1.2173 +int Context::getMaxSupportedSamples() const 1.2174 +{ 1.2175 + return mRenderer->getMaxSupportedSamples(); 1.2176 +} 1.2177 + 1.2178 +unsigned int Context::getMaximumRenderTargets() const 1.2179 +{ 1.2180 + return mRenderer->getMaxRenderTargets(); 1.2181 +} 1.2182 + 1.2183 +bool Context::supportsEventQueries() const 1.2184 +{ 1.2185 + return mSupportsEventQueries; 1.2186 +} 1.2187 + 1.2188 +bool Context::supportsOcclusionQueries() const 1.2189 +{ 1.2190 + return mSupportsOcclusionQueries; 1.2191 +} 1.2192 + 1.2193 +bool Context::supportsBGRATextures() const 1.2194 +{ 1.2195 + return mSupportsBGRATextures; 1.2196 +} 1.2197 + 1.2198 +bool Context::supportsDXT1Textures() const 1.2199 +{ 1.2200 + return mSupportsDXT1Textures; 1.2201 +} 1.2202 + 1.2203 +bool Context::supportsDXT3Textures() const 1.2204 +{ 1.2205 + return mSupportsDXT3Textures; 1.2206 +} 1.2207 + 1.2208 +bool Context::supportsDXT5Textures() const 1.2209 +{ 1.2210 + return mSupportsDXT5Textures; 1.2211 +} 1.2212 + 1.2213 +bool Context::supportsFloat32Textures() const 1.2214 +{ 1.2215 + return mSupportsFloat32Textures; 1.2216 +} 1.2217 + 1.2218 +bool Context::supportsFloat32LinearFilter() const 1.2219 +{ 1.2220 + return mSupportsFloat32LinearFilter; 1.2221 +} 1.2222 + 1.2223 +bool Context::supportsFloat32RenderableTextures() const 1.2224 +{ 1.2225 + return mSupportsFloat32RenderableTextures; 1.2226 +} 1.2227 + 1.2228 +bool Context::supportsFloat16Textures() const 1.2229 +{ 1.2230 + return mSupportsFloat16Textures; 1.2231 +} 1.2232 + 1.2233 +bool Context::supportsFloat16LinearFilter() const 1.2234 +{ 1.2235 + return mSupportsFloat16LinearFilter; 1.2236 +} 1.2237 + 1.2238 +bool Context::supportsFloat16RenderableTextures() const 1.2239 +{ 1.2240 + return mSupportsFloat16RenderableTextures; 1.2241 +} 1.2242 + 1.2243 +int Context::getMaximumRenderbufferDimension() const 1.2244 +{ 1.2245 + return mMaxRenderbufferDimension; 1.2246 +} 1.2247 + 1.2248 +int Context::getMaximumTextureDimension() const 1.2249 +{ 1.2250 + return mMaxTextureDimension; 1.2251 +} 1.2252 + 1.2253 +int Context::getMaximumCubeTextureDimension() const 1.2254 +{ 1.2255 + return mMaxCubeTextureDimension; 1.2256 +} 1.2257 + 1.2258 +int Context::getMaximumTextureLevel() const 1.2259 +{ 1.2260 + return mMaxTextureLevel; 1.2261 +} 1.2262 + 1.2263 +bool Context::supportsLuminanceTextures() const 1.2264 +{ 1.2265 + return mSupportsLuminanceTextures; 1.2266 +} 1.2267 + 1.2268 +bool Context::supportsLuminanceAlphaTextures() const 1.2269 +{ 1.2270 + return mSupportsLuminanceAlphaTextures; 1.2271 +} 1.2272 + 1.2273 +bool Context::supportsDepthTextures() const 1.2274 +{ 1.2275 + return mSupportsDepthTextures; 1.2276 +} 1.2277 + 1.2278 +bool Context::supports32bitIndices() const 1.2279 +{ 1.2280 + return mSupports32bitIndices; 1.2281 +} 1.2282 + 1.2283 +bool Context::supportsNonPower2Texture() const 1.2284 +{ 1.2285 + return mSupportsNonPower2Texture; 1.2286 +} 1.2287 + 1.2288 +bool Context::supportsInstancing() const 1.2289 +{ 1.2290 + return mSupportsInstancing; 1.2291 +} 1.2292 + 1.2293 +bool Context::supportsTextureFilterAnisotropy() const 1.2294 +{ 1.2295 + return mSupportsTextureFilterAnisotropy; 1.2296 +} 1.2297 + 1.2298 +float Context::getTextureMaxAnisotropy() const 1.2299 +{ 1.2300 + return mMaxTextureAnisotropy; 1.2301 +} 1.2302 + 1.2303 +bool Context::getCurrentReadFormatType(GLenum *format, GLenum *type) 1.2304 +{ 1.2305 + Framebuffer *framebuffer = getReadFramebuffer(); 1.2306 + if (!framebuffer || framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) 1.2307 + { 1.2308 + return gl::error(GL_INVALID_OPERATION, false); 1.2309 + } 1.2310 + 1.2311 + Renderbuffer *renderbuffer = framebuffer->getReadColorbuffer(); 1.2312 + if (!renderbuffer) 1.2313 + { 1.2314 + return gl::error(GL_INVALID_OPERATION, false); 1.2315 + } 1.2316 + 1.2317 + *format = gl::ExtractFormat(renderbuffer->getActualFormat()); 1.2318 + *type = gl::ExtractType(renderbuffer->getActualFormat()); 1.2319 + 1.2320 + return true; 1.2321 +} 1.2322 + 1.2323 +void Context::detachBuffer(GLuint buffer) 1.2324 +{ 1.2325 + // [OpenGL ES 2.0.24] section 2.9 page 22: 1.2326 + // If a buffer object is deleted while it is bound, all bindings to that object in the current context 1.2327 + // (i.e. in the thread that called Delete-Buffers) are reset to zero. 1.2328 + 1.2329 + if (mState.arrayBuffer.id() == buffer) 1.2330 + { 1.2331 + mState.arrayBuffer.set(NULL); 1.2332 + } 1.2333 + 1.2334 + if (mState.elementArrayBuffer.id() == buffer) 1.2335 + { 1.2336 + mState.elementArrayBuffer.set(NULL); 1.2337 + } 1.2338 + 1.2339 + for (int attribute = 0; attribute < MAX_VERTEX_ATTRIBS; attribute++) 1.2340 + { 1.2341 + if (mState.vertexAttribute[attribute].mBoundBuffer.id() == buffer) 1.2342 + { 1.2343 + mState.vertexAttribute[attribute].mBoundBuffer.set(NULL); 1.2344 + } 1.2345 + } 1.2346 +} 1.2347 + 1.2348 +void Context::detachTexture(GLuint texture) 1.2349 +{ 1.2350 + // [OpenGL ES 2.0.24] section 3.8 page 84: 1.2351 + // If a texture object is deleted, it is as if all texture units which are bound to that texture object are 1.2352 + // rebound to texture object zero 1.2353 + 1.2354 + for (int type = 0; type < TEXTURE_TYPE_COUNT; type++) 1.2355 + { 1.2356 + for (int sampler = 0; sampler < IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS; sampler++) 1.2357 + { 1.2358 + if (mState.samplerTexture[type][sampler].id() == texture) 1.2359 + { 1.2360 + mState.samplerTexture[type][sampler].set(NULL); 1.2361 + } 1.2362 + } 1.2363 + } 1.2364 + 1.2365 + // [OpenGL ES 2.0.24] section 4.4 page 112: 1.2366 + // If a texture object is deleted while its image is attached to the currently bound framebuffer, then it is 1.2367 + // as if FramebufferTexture2D had been called, with a texture of 0, for each attachment point to which this 1.2368 + // image was attached in the currently bound framebuffer. 1.2369 + 1.2370 + Framebuffer *readFramebuffer = getReadFramebuffer(); 1.2371 + Framebuffer *drawFramebuffer = getDrawFramebuffer(); 1.2372 + 1.2373 + if (readFramebuffer) 1.2374 + { 1.2375 + readFramebuffer->detachTexture(texture); 1.2376 + } 1.2377 + 1.2378 + if (drawFramebuffer && drawFramebuffer != readFramebuffer) 1.2379 + { 1.2380 + drawFramebuffer->detachTexture(texture); 1.2381 + } 1.2382 +} 1.2383 + 1.2384 +void Context::detachFramebuffer(GLuint framebuffer) 1.2385 +{ 1.2386 + // [OpenGL ES 2.0.24] section 4.4 page 107: 1.2387 + // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as though 1.2388 + // BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of zero. 1.2389 + 1.2390 + if (mState.readFramebuffer == framebuffer) 1.2391 + { 1.2392 + bindReadFramebuffer(0); 1.2393 + } 1.2394 + 1.2395 + if (mState.drawFramebuffer == framebuffer) 1.2396 + { 1.2397 + bindDrawFramebuffer(0); 1.2398 + } 1.2399 +} 1.2400 + 1.2401 +void Context::detachRenderbuffer(GLuint renderbuffer) 1.2402 +{ 1.2403 + // [OpenGL ES 2.0.24] section 4.4 page 109: 1.2404 + // If a renderbuffer that is currently bound to RENDERBUFFER is deleted, it is as though BindRenderbuffer 1.2405 + // had been executed with the target RENDERBUFFER and name of zero. 1.2406 + 1.2407 + if (mState.renderbuffer.id() == renderbuffer) 1.2408 + { 1.2409 + bindRenderbuffer(0); 1.2410 + } 1.2411 + 1.2412 + // [OpenGL ES 2.0.24] section 4.4 page 111: 1.2413 + // If a renderbuffer object is deleted while its image is attached to the currently bound framebuffer, 1.2414 + // then it is as if FramebufferRenderbuffer had been called, with a renderbuffer of 0, for each attachment 1.2415 + // point to which this image was attached in the currently bound framebuffer. 1.2416 + 1.2417 + Framebuffer *readFramebuffer = getReadFramebuffer(); 1.2418 + Framebuffer *drawFramebuffer = getDrawFramebuffer(); 1.2419 + 1.2420 + if (readFramebuffer) 1.2421 + { 1.2422 + readFramebuffer->detachRenderbuffer(renderbuffer); 1.2423 + } 1.2424 + 1.2425 + if (drawFramebuffer && drawFramebuffer != readFramebuffer) 1.2426 + { 1.2427 + drawFramebuffer->detachRenderbuffer(renderbuffer); 1.2428 + } 1.2429 +} 1.2430 + 1.2431 +Texture *Context::getIncompleteTexture(TextureType type) 1.2432 +{ 1.2433 + Texture *t = mIncompleteTextures[type].get(); 1.2434 + 1.2435 + if (t == NULL) 1.2436 + { 1.2437 + static const GLubyte color[] = { 0, 0, 0, 255 }; 1.2438 + 1.2439 + switch (type) 1.2440 + { 1.2441 + default: 1.2442 + UNREACHABLE(); 1.2443 + // default falls through to TEXTURE_2D 1.2444 + 1.2445 + case TEXTURE_2D: 1.2446 + { 1.2447 + Texture2D *incomplete2d = new Texture2D(mRenderer, Texture::INCOMPLETE_TEXTURE_ID); 1.2448 + incomplete2d->setImage(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); 1.2449 + t = incomplete2d; 1.2450 + } 1.2451 + break; 1.2452 + 1.2453 + case TEXTURE_CUBE: 1.2454 + { 1.2455 + TextureCubeMap *incompleteCube = new TextureCubeMap(mRenderer, Texture::INCOMPLETE_TEXTURE_ID); 1.2456 + 1.2457 + incompleteCube->setImagePosX(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); 1.2458 + incompleteCube->setImageNegX(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); 1.2459 + incompleteCube->setImagePosY(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); 1.2460 + incompleteCube->setImageNegY(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); 1.2461 + incompleteCube->setImagePosZ(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); 1.2462 + incompleteCube->setImageNegZ(0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, color); 1.2463 + 1.2464 + t = incompleteCube; 1.2465 + } 1.2466 + break; 1.2467 + } 1.2468 + 1.2469 + mIncompleteTextures[type].set(t); 1.2470 + } 1.2471 + 1.2472 + return t; 1.2473 +} 1.2474 + 1.2475 +bool Context::skipDraw(GLenum drawMode) 1.2476 +{ 1.2477 + if (drawMode == GL_POINTS) 1.2478 + { 1.2479 + // ProgramBinary assumes non-point rendering if gl_PointSize isn't written, 1.2480 + // which affects varying interpolation. Since the value of gl_PointSize is 1.2481 + // undefined when not written, just skip drawing to avoid unexpected results. 1.2482 + if (!getCurrentProgramBinary()->usesPointSize()) 1.2483 + { 1.2484 + // This is stictly speaking not an error, but developers should be 1.2485 + // notified of risking undefined behavior. 1.2486 + ERR("Point rendering without writing to gl_PointSize."); 1.2487 + 1.2488 + return true; 1.2489 + } 1.2490 + } 1.2491 + else if (IsTriangleMode(drawMode)) 1.2492 + { 1.2493 + if (mState.rasterizer.cullFace && mState.rasterizer.cullMode == GL_FRONT_AND_BACK) 1.2494 + { 1.2495 + return true; 1.2496 + } 1.2497 + } 1.2498 + 1.2499 + return false; 1.2500 +} 1.2501 + 1.2502 +void Context::setVertexAttrib(GLuint index, const GLfloat *values) 1.2503 +{ 1.2504 + ASSERT(index < gl::MAX_VERTEX_ATTRIBS); 1.2505 + 1.2506 + mState.vertexAttribute[index].mCurrentValue[0] = values[0]; 1.2507 + mState.vertexAttribute[index].mCurrentValue[1] = values[1]; 1.2508 + mState.vertexAttribute[index].mCurrentValue[2] = values[2]; 1.2509 + mState.vertexAttribute[index].mCurrentValue[3] = values[3]; 1.2510 +} 1.2511 + 1.2512 +void Context::setVertexAttribDivisor(GLuint index, GLuint divisor) 1.2513 +{ 1.2514 + ASSERT(index < gl::MAX_VERTEX_ATTRIBS); 1.2515 + 1.2516 + mState.vertexAttribute[index].mDivisor = divisor; 1.2517 +} 1.2518 + 1.2519 +// keep list sorted in following order 1.2520 +// OES extensions 1.2521 +// EXT extensions 1.2522 +// Vendor extensions 1.2523 +void Context::initExtensionString() 1.2524 +{ 1.2525 + std::string extensionString = ""; 1.2526 + 1.2527 + // OES extensions 1.2528 + if (supports32bitIndices()) 1.2529 + { 1.2530 + extensionString += "GL_OES_element_index_uint "; 1.2531 + } 1.2532 + 1.2533 + extensionString += "GL_OES_packed_depth_stencil "; 1.2534 + extensionString += "GL_OES_get_program_binary "; 1.2535 + extensionString += "GL_OES_rgb8_rgba8 "; 1.2536 + if (mRenderer->getDerivativeInstructionSupport()) 1.2537 + { 1.2538 + extensionString += "GL_OES_standard_derivatives "; 1.2539 + } 1.2540 + 1.2541 + if (supportsFloat16Textures()) 1.2542 + { 1.2543 + extensionString += "GL_OES_texture_half_float "; 1.2544 + } 1.2545 + if (supportsFloat16LinearFilter()) 1.2546 + { 1.2547 + extensionString += "GL_OES_texture_half_float_linear "; 1.2548 + } 1.2549 + if (supportsFloat32Textures()) 1.2550 + { 1.2551 + extensionString += "GL_OES_texture_float "; 1.2552 + } 1.2553 + if (supportsFloat32LinearFilter()) 1.2554 + { 1.2555 + extensionString += "GL_OES_texture_float_linear "; 1.2556 + } 1.2557 + 1.2558 + if (supportsNonPower2Texture()) 1.2559 + { 1.2560 + extensionString += "GL_OES_texture_npot "; 1.2561 + } 1.2562 + 1.2563 + // Multi-vendor (EXT) extensions 1.2564 + if (supportsOcclusionQueries()) 1.2565 + { 1.2566 + extensionString += "GL_EXT_occlusion_query_boolean "; 1.2567 + } 1.2568 + 1.2569 + extensionString += "GL_EXT_read_format_bgra "; 1.2570 + extensionString += "GL_EXT_robustness "; 1.2571 + 1.2572 + if (supportsDXT1Textures()) 1.2573 + { 1.2574 + extensionString += "GL_EXT_texture_compression_dxt1 "; 1.2575 + } 1.2576 + 1.2577 + if (supportsTextureFilterAnisotropy()) 1.2578 + { 1.2579 + extensionString += "GL_EXT_texture_filter_anisotropic "; 1.2580 + } 1.2581 + 1.2582 + if (supportsBGRATextures()) 1.2583 + { 1.2584 + extensionString += "GL_EXT_texture_format_BGRA8888 "; 1.2585 + } 1.2586 + 1.2587 + if (mRenderer->getMaxRenderTargets() > 1) 1.2588 + { 1.2589 + extensionString += "GL_EXT_draw_buffers "; 1.2590 + } 1.2591 + 1.2592 + extensionString += "GL_EXT_texture_storage "; 1.2593 + extensionString += "GL_EXT_frag_depth "; 1.2594 + 1.2595 + // ANGLE-specific extensions 1.2596 + if (supportsDepthTextures()) 1.2597 + { 1.2598 + extensionString += "GL_ANGLE_depth_texture "; 1.2599 + } 1.2600 + 1.2601 + extensionString += "GL_ANGLE_framebuffer_blit "; 1.2602 + if (getMaxSupportedSamples() != 0) 1.2603 + { 1.2604 + extensionString += "GL_ANGLE_framebuffer_multisample "; 1.2605 + } 1.2606 + 1.2607 + if (supportsInstancing()) 1.2608 + { 1.2609 + extensionString += "GL_ANGLE_instanced_arrays "; 1.2610 + } 1.2611 + 1.2612 + extensionString += "GL_ANGLE_pack_reverse_row_order "; 1.2613 + 1.2614 + if (supportsDXT3Textures()) 1.2615 + { 1.2616 + extensionString += "GL_ANGLE_texture_compression_dxt3 "; 1.2617 + } 1.2618 + if (supportsDXT5Textures()) 1.2619 + { 1.2620 + extensionString += "GL_ANGLE_texture_compression_dxt5 "; 1.2621 + } 1.2622 + 1.2623 + extensionString += "GL_ANGLE_texture_usage "; 1.2624 + extensionString += "GL_ANGLE_translated_shader_source "; 1.2625 + 1.2626 + // Other vendor-specific extensions 1.2627 + if (supportsEventQueries()) 1.2628 + { 1.2629 + extensionString += "GL_NV_fence "; 1.2630 + } 1.2631 + 1.2632 + std::string::size_type end = extensionString.find_last_not_of(' '); 1.2633 + if (end != std::string::npos) 1.2634 + { 1.2635 + extensionString.resize(end+1); 1.2636 + } 1.2637 + 1.2638 + mExtensionString = makeStaticString(extensionString); 1.2639 +} 1.2640 + 1.2641 +const char *Context::getExtensionString() const 1.2642 +{ 1.2643 + return mExtensionString; 1.2644 +} 1.2645 + 1.2646 +void Context::initRendererString() 1.2647 +{ 1.2648 + std::ostringstream rendererString; 1.2649 + rendererString << "ANGLE ("; 1.2650 + rendererString << mRenderer->getRendererDescription(); 1.2651 + rendererString << ")"; 1.2652 + 1.2653 + mRendererString = makeStaticString(rendererString.str()); 1.2654 +} 1.2655 + 1.2656 +const char *Context::getRendererString() const 1.2657 +{ 1.2658 + return mRendererString; 1.2659 +} 1.2660 + 1.2661 +void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, 1.2662 + GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, 1.2663 + GLbitfield mask) 1.2664 +{ 1.2665 + Framebuffer *readFramebuffer = getReadFramebuffer(); 1.2666 + Framebuffer *drawFramebuffer = getDrawFramebuffer(); 1.2667 + 1.2668 + if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE || 1.2669 + !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) 1.2670 + { 1.2671 + return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION); 1.2672 + } 1.2673 + 1.2674 + if (drawFramebuffer->getSamples() != 0) 1.2675 + { 1.2676 + return gl::error(GL_INVALID_OPERATION); 1.2677 + } 1.2678 + 1.2679 + Renderbuffer *readColorBuffer = readFramebuffer->getReadColorbuffer(); 1.2680 + Renderbuffer *drawColorBuffer = drawFramebuffer->getFirstColorbuffer(); 1.2681 + 1.2682 + if (drawColorBuffer == NULL) 1.2683 + { 1.2684 + ERR("Draw buffers formats don't match, which is not supported in this implementation of BlitFramebufferANGLE"); 1.2685 + return gl::error(GL_INVALID_OPERATION); 1.2686 + } 1.2687 + 1.2688 + int readBufferWidth = readColorBuffer->getWidth(); 1.2689 + int readBufferHeight = readColorBuffer->getHeight(); 1.2690 + int drawBufferWidth = drawColorBuffer->getWidth(); 1.2691 + int drawBufferHeight = drawColorBuffer->getHeight(); 1.2692 + 1.2693 + Rectangle sourceRect; 1.2694 + Rectangle destRect; 1.2695 + 1.2696 + if (srcX0 < srcX1) 1.2697 + { 1.2698 + sourceRect.x = srcX0; 1.2699 + destRect.x = dstX0; 1.2700 + sourceRect.width = srcX1 - srcX0; 1.2701 + destRect.width = dstX1 - dstX0; 1.2702 + } 1.2703 + else 1.2704 + { 1.2705 + sourceRect.x = srcX1; 1.2706 + destRect.x = dstX1; 1.2707 + sourceRect.width = srcX0 - srcX1; 1.2708 + destRect.width = dstX0 - dstX1; 1.2709 + } 1.2710 + 1.2711 + if (srcY0 < srcY1) 1.2712 + { 1.2713 + sourceRect.height = srcY1 - srcY0; 1.2714 + destRect.height = dstY1 - dstY0; 1.2715 + sourceRect.y = srcY0; 1.2716 + destRect.y = dstY0; 1.2717 + } 1.2718 + else 1.2719 + { 1.2720 + sourceRect.height = srcY0 - srcY1; 1.2721 + destRect.height = dstY0 - srcY1; 1.2722 + sourceRect.y = srcY1; 1.2723 + destRect.y = dstY1; 1.2724 + } 1.2725 + 1.2726 + Rectangle sourceScissoredRect = sourceRect; 1.2727 + Rectangle destScissoredRect = destRect; 1.2728 + 1.2729 + if (mState.scissorTest) 1.2730 + { 1.2731 + // Only write to parts of the destination framebuffer which pass the scissor test. 1.2732 + if (destRect.x < mState.scissor.x) 1.2733 + { 1.2734 + int xDiff = mState.scissor.x - destRect.x; 1.2735 + destScissoredRect.x = mState.scissor.x; 1.2736 + destScissoredRect.width -= xDiff; 1.2737 + sourceScissoredRect.x += xDiff; 1.2738 + sourceScissoredRect.width -= xDiff; 1.2739 + 1.2740 + } 1.2741 + 1.2742 + if (destRect.x + destRect.width > mState.scissor.x + mState.scissor.width) 1.2743 + { 1.2744 + int xDiff = (destRect.x + destRect.width) - (mState.scissor.x + mState.scissor.width); 1.2745 + destScissoredRect.width -= xDiff; 1.2746 + sourceScissoredRect.width -= xDiff; 1.2747 + } 1.2748 + 1.2749 + if (destRect.y < mState.scissor.y) 1.2750 + { 1.2751 + int yDiff = mState.scissor.y - destRect.y; 1.2752 + destScissoredRect.y = mState.scissor.y; 1.2753 + destScissoredRect.height -= yDiff; 1.2754 + sourceScissoredRect.y += yDiff; 1.2755 + sourceScissoredRect.height -= yDiff; 1.2756 + } 1.2757 + 1.2758 + if (destRect.y + destRect.height > mState.scissor.y + mState.scissor.height) 1.2759 + { 1.2760 + int yDiff = (destRect.y + destRect.height) - (mState.scissor.y + mState.scissor.height); 1.2761 + destScissoredRect.height -= yDiff; 1.2762 + sourceScissoredRect.height -= yDiff; 1.2763 + } 1.2764 + } 1.2765 + 1.2766 + bool blitRenderTarget = false; 1.2767 + bool blitDepthStencil = false; 1.2768 + 1.2769 + Rectangle sourceTrimmedRect = sourceScissoredRect; 1.2770 + Rectangle destTrimmedRect = destScissoredRect; 1.2771 + 1.2772 + // The source & destination rectangles also may need to be trimmed if they fall out of the bounds of 1.2773 + // the actual draw and read surfaces. 1.2774 + if (sourceTrimmedRect.x < 0) 1.2775 + { 1.2776 + int xDiff = 0 - sourceTrimmedRect.x; 1.2777 + sourceTrimmedRect.x = 0; 1.2778 + sourceTrimmedRect.width -= xDiff; 1.2779 + destTrimmedRect.x += xDiff; 1.2780 + destTrimmedRect.width -= xDiff; 1.2781 + } 1.2782 + 1.2783 + if (sourceTrimmedRect.x + sourceTrimmedRect.width > readBufferWidth) 1.2784 + { 1.2785 + int xDiff = (sourceTrimmedRect.x + sourceTrimmedRect.width) - readBufferWidth; 1.2786 + sourceTrimmedRect.width -= xDiff; 1.2787 + destTrimmedRect.width -= xDiff; 1.2788 + } 1.2789 + 1.2790 + if (sourceTrimmedRect.y < 0) 1.2791 + { 1.2792 + int yDiff = 0 - sourceTrimmedRect.y; 1.2793 + sourceTrimmedRect.y = 0; 1.2794 + sourceTrimmedRect.height -= yDiff; 1.2795 + destTrimmedRect.y += yDiff; 1.2796 + destTrimmedRect.height -= yDiff; 1.2797 + } 1.2798 + 1.2799 + if (sourceTrimmedRect.y + sourceTrimmedRect.height > readBufferHeight) 1.2800 + { 1.2801 + int yDiff = (sourceTrimmedRect.y + sourceTrimmedRect.height) - readBufferHeight; 1.2802 + sourceTrimmedRect.height -= yDiff; 1.2803 + destTrimmedRect.height -= yDiff; 1.2804 + } 1.2805 + 1.2806 + if (destTrimmedRect.x < 0) 1.2807 + { 1.2808 + int xDiff = 0 - destTrimmedRect.x; 1.2809 + destTrimmedRect.x = 0; 1.2810 + destTrimmedRect.width -= xDiff; 1.2811 + sourceTrimmedRect.x += xDiff; 1.2812 + sourceTrimmedRect.width -= xDiff; 1.2813 + } 1.2814 + 1.2815 + if (destTrimmedRect.x + destTrimmedRect.width > drawBufferWidth) 1.2816 + { 1.2817 + int xDiff = (destTrimmedRect.x + destTrimmedRect.width) - drawBufferWidth; 1.2818 + destTrimmedRect.width -= xDiff; 1.2819 + sourceTrimmedRect.width -= xDiff; 1.2820 + } 1.2821 + 1.2822 + if (destTrimmedRect.y < 0) 1.2823 + { 1.2824 + int yDiff = 0 - destTrimmedRect.y; 1.2825 + destTrimmedRect.y = 0; 1.2826 + destTrimmedRect.height -= yDiff; 1.2827 + sourceTrimmedRect.y += yDiff; 1.2828 + sourceTrimmedRect.height -= yDiff; 1.2829 + } 1.2830 + 1.2831 + if (destTrimmedRect.y + destTrimmedRect.height > drawBufferHeight) 1.2832 + { 1.2833 + int yDiff = (destTrimmedRect.y + destTrimmedRect.height) - drawBufferHeight; 1.2834 + destTrimmedRect.height -= yDiff; 1.2835 + sourceTrimmedRect.height -= yDiff; 1.2836 + } 1.2837 + 1.2838 + bool partialBufferCopy = false; 1.2839 + if (sourceTrimmedRect.height < readBufferHeight || 1.2840 + sourceTrimmedRect.width < readBufferWidth || 1.2841 + destTrimmedRect.height < drawBufferHeight || 1.2842 + destTrimmedRect.width < drawBufferWidth || 1.2843 + sourceTrimmedRect.y != 0 || destTrimmedRect.y != 0 || sourceTrimmedRect.x != 0 || destTrimmedRect.x != 0) 1.2844 + { 1.2845 + partialBufferCopy = true; 1.2846 + } 1.2847 + 1.2848 + if (mask & GL_COLOR_BUFFER_BIT) 1.2849 + { 1.2850 + const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType(); 1.2851 + const bool validReadType = (readColorbufferType == GL_TEXTURE_2D) || (readColorbufferType == GL_RENDERBUFFER); 1.2852 + bool validDrawType = true; 1.2853 + bool validDrawFormat = true; 1.2854 + 1.2855 + for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) 1.2856 + { 1.2857 + if (drawFramebuffer->isEnabledColorAttachment(colorAttachment)) 1.2858 + { 1.2859 + if (drawFramebuffer->getColorbufferType(colorAttachment) != GL_TEXTURE_2D && 1.2860 + drawFramebuffer->getColorbufferType(colorAttachment) != GL_RENDERBUFFER) 1.2861 + { 1.2862 + validDrawType = false; 1.2863 + } 1.2864 + 1.2865 + if (drawFramebuffer->getColorbuffer(colorAttachment)->getActualFormat() != readColorBuffer->getActualFormat()) 1.2866 + { 1.2867 + validDrawFormat = false; 1.2868 + } 1.2869 + } 1.2870 + } 1.2871 + 1.2872 + if (!validReadType || !validDrawType || !validDrawFormat) 1.2873 + { 1.2874 + ERR("Color buffer format conversion in BlitFramebufferANGLE not supported by this implementation"); 1.2875 + return gl::error(GL_INVALID_OPERATION); 1.2876 + } 1.2877 + 1.2878 + if (partialBufferCopy && readFramebuffer->getSamples() != 0) 1.2879 + { 1.2880 + return gl::error(GL_INVALID_OPERATION); 1.2881 + } 1.2882 + 1.2883 + blitRenderTarget = true; 1.2884 + 1.2885 + } 1.2886 + 1.2887 + if (mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) 1.2888 + { 1.2889 + Renderbuffer *readDSBuffer = NULL; 1.2890 + Renderbuffer *drawDSBuffer = NULL; 1.2891 + 1.2892 + // We support OES_packed_depth_stencil, and do not support a separately attached depth and stencil buffer, so if we have 1.2893 + // both a depth and stencil buffer, it will be the same buffer. 1.2894 + 1.2895 + if (mask & GL_DEPTH_BUFFER_BIT) 1.2896 + { 1.2897 + if (readFramebuffer->getDepthbuffer() && drawFramebuffer->getDepthbuffer()) 1.2898 + { 1.2899 + if (readFramebuffer->getDepthbufferType() != drawFramebuffer->getDepthbufferType() || 1.2900 + readFramebuffer->getDepthbuffer()->getActualFormat() != drawFramebuffer->getDepthbuffer()->getActualFormat()) 1.2901 + { 1.2902 + return gl::error(GL_INVALID_OPERATION); 1.2903 + } 1.2904 + 1.2905 + blitDepthStencil = true; 1.2906 + readDSBuffer = readFramebuffer->getDepthbuffer(); 1.2907 + drawDSBuffer = drawFramebuffer->getDepthbuffer(); 1.2908 + } 1.2909 + } 1.2910 + 1.2911 + if (mask & GL_STENCIL_BUFFER_BIT) 1.2912 + { 1.2913 + if (readFramebuffer->getStencilbuffer() && drawFramebuffer->getStencilbuffer()) 1.2914 + { 1.2915 + if (readFramebuffer->getStencilbufferType() != drawFramebuffer->getStencilbufferType() || 1.2916 + readFramebuffer->getStencilbuffer()->getActualFormat() != drawFramebuffer->getStencilbuffer()->getActualFormat()) 1.2917 + { 1.2918 + return gl::error(GL_INVALID_OPERATION); 1.2919 + } 1.2920 + 1.2921 + blitDepthStencil = true; 1.2922 + readDSBuffer = readFramebuffer->getStencilbuffer(); 1.2923 + drawDSBuffer = drawFramebuffer->getStencilbuffer(); 1.2924 + } 1.2925 + } 1.2926 + 1.2927 + if (partialBufferCopy) 1.2928 + { 1.2929 + ERR("Only whole-buffer depth and stencil blits are supported by this implementation."); 1.2930 + return gl::error(GL_INVALID_OPERATION); // only whole-buffer copies are permitted 1.2931 + } 1.2932 + 1.2933 + if ((drawDSBuffer && drawDSBuffer->getSamples() != 0) || 1.2934 + (readDSBuffer && readDSBuffer->getSamples() != 0)) 1.2935 + { 1.2936 + return gl::error(GL_INVALID_OPERATION); 1.2937 + } 1.2938 + } 1.2939 + 1.2940 + if (blitRenderTarget || blitDepthStencil) 1.2941 + { 1.2942 + mRenderer->blitRect(readFramebuffer, sourceTrimmedRect, drawFramebuffer, destTrimmedRect, blitRenderTarget, blitDepthStencil); 1.2943 + } 1.2944 +} 1.2945 + 1.2946 +} 1.2947 + 1.2948 +extern "C" 1.2949 +{ 1.2950 +gl::Context *glCreateContext(const gl::Context *shareContext, rx::Renderer *renderer, bool notifyResets, bool robustAccess) 1.2951 +{ 1.2952 + return new gl::Context(shareContext, renderer, notifyResets, robustAccess); 1.2953 +} 1.2954 + 1.2955 +void glDestroyContext(gl::Context *context) 1.2956 +{ 1.2957 + delete context; 1.2958 + 1.2959 + if (context == gl::getContext()) 1.2960 + { 1.2961 + gl::makeCurrent(NULL, NULL, NULL); 1.2962 + } 1.2963 +} 1.2964 + 1.2965 +void glMakeCurrent(gl::Context *context, egl::Display *display, egl::Surface *surface) 1.2966 +{ 1.2967 + gl::makeCurrent(context, display, surface); 1.2968 +} 1.2969 + 1.2970 +gl::Context *glGetCurrentContext() 1.2971 +{ 1.2972 + return gl::getContext(); 1.2973 +} 1.2974 + 1.2975 +}