blob: 10abb77e4a978ee74573714db12f420ca8a7dc7a [file] [log] [blame]
//
// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Context.cpp: Implements the gl::Context class, managing all GL state and performing
// rendering operations. It is the GLES2 specific implementation of EGLContext.
#include "libANGLE/Context.h"
#include "libANGLE/Context.inl.h"
#include <string.h>
#include <iterator>
#include <sstream>
#include <vector>
#include "common/PackedEnums.h"
#include "common/matrix_utils.h"
#include "common/platform.h"
#include "common/utilities.h"
#include "common/version.h"
#include "libANGLE/Buffer.h"
#include "libANGLE/Compiler.h"
#include "libANGLE/Display.h"
#include "libANGLE/Fence.h"
#include "libANGLE/Framebuffer.h"
#include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/Path.h"
#include "libANGLE/Program.h"
#include "libANGLE/ProgramPipeline.h"
#include "libANGLE/Query.h"
#include "libANGLE/Renderbuffer.h"
#include "libANGLE/ResourceManager.h"
#include "libANGLE/Sampler.h"
#include "libANGLE/Surface.h"
#include "libANGLE/Texture.h"
#include "libANGLE/TransformFeedback.h"
#include "libANGLE/VertexArray.h"
#include "libANGLE/Workarounds.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/queryconversions.h"
#include "libANGLE/queryutils.h"
#include "libANGLE/renderer/BufferImpl.h"
#include "libANGLE/renderer/EGLImplFactory.h"
#include "libANGLE/renderer/Format.h"
#include "libANGLE/validationES.h"
namespace gl
{
namespace
{
template <typename T>
std::vector<Path *> GatherPaths(PathManager &resourceManager,
GLsizei numPaths,
const void *paths,
GLuint pathBase)
{
std::vector<Path *> ret;
ret.reserve(numPaths);
const auto *nameArray = static_cast<const T *>(paths);
for (GLsizei i = 0; i < numPaths; ++i)
{
const GLuint pathName = nameArray[i] + pathBase;
ret.push_back(resourceManager.getPath(pathName));
}
return ret;
}
std::vector<Path *> GatherPaths(PathManager &resourceManager,
GLsizei numPaths,
GLenum pathNameType,
const void *paths,
GLuint pathBase)
{
switch (pathNameType)
{
case GL_UNSIGNED_BYTE:
return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
case GL_BYTE:
return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
case GL_UNSIGNED_SHORT:
return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
case GL_SHORT:
return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
case GL_UNSIGNED_INT:
return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
case GL_INT:
return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
}
UNREACHABLE();
return std::vector<Path *>();
}
template <typename T>
angle::Result GetQueryObjectParameter(const Context *context, Query *query, GLenum pname, T *params)
{
ASSERT(query != nullptr);
switch (pname)
{
case GL_QUERY_RESULT_EXT:
return query->getResult(context, params);
case GL_QUERY_RESULT_AVAILABLE_EXT:
{
bool available;
ANGLE_TRY(query->isResultAvailable(context, &available));
*params = CastFromStateValue<T>(pname, static_cast<GLuint>(available));
return angle::Result::Continue;
}
default:
UNREACHABLE();
return angle::Result::Stop;
}
}
// Attribute map queries.
EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
{
return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
}
EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
{
return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
}
Version GetClientVersion(const egl::AttributeMap &attribs)
{
return Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
}
GLenum GetResetStrategy(const egl::AttributeMap &attribs)
{
EGLAttrib attrib =
attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
switch (attrib)
{
case EGL_NO_RESET_NOTIFICATION:
return GL_NO_RESET_NOTIFICATION_EXT;
case EGL_LOSE_CONTEXT_ON_RESET:
return GL_LOSE_CONTEXT_ON_RESET_EXT;
default:
UNREACHABLE();
return GL_NONE;
}
}
bool GetRobustAccess(const egl::AttributeMap &attribs)
{
return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
0);
}
bool GetDebug(const egl::AttributeMap &attribs)
{
return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
}
bool GetNoError(const egl::AttributeMap &attribs)
{
return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
}
bool GetWebGLContext(const egl::AttributeMap &attribs)
{
return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
}
bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
{
// If the context is WebGL, extensions are disabled by default
EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
}
bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
{
return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
}
bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
{
return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
}
bool GetRobustResourceInit(const egl::AttributeMap &attribs)
{
return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
}
std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
{
std::string labelName;
if (label != nullptr)
{
size_t labelLength = length < 0 ? strlen(label) : length;
labelName = std::string(label, labelLength);
}
return labelName;
}
void GetObjectLabelBase(const std::string &objectLabel,
GLsizei bufSize,
GLsizei *length,
GLchar *label)
{
size_t writeLength = objectLabel.length();
if (label != nullptr && bufSize > 0)
{
writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
label[writeLength] = '\0';
}
if (length != nullptr)
{
*length = static_cast<GLsizei>(writeLength);
}
}
template <typename CapT, typename MaxT>
void LimitCap(CapT *cap, MaxT maximum)
{
*cap = std::min(*cap, static_cast<CapT>(maximum));
}
// The rest default to false.
constexpr angle::PackedEnumMap<PrimitiveMode, bool, angle::EnumSize<PrimitiveMode>() + 1>
kValidBasicDrawModes = {{
{PrimitiveMode::Points, true},
{PrimitiveMode::Lines, true},
{PrimitiveMode::LineLoop, true},
{PrimitiveMode::LineStrip, true},
{PrimitiveMode::Triangles, true},
{PrimitiveMode::TriangleStrip, true},
{PrimitiveMode::TriangleFan, true},
}};
enum SubjectIndexes : angle::SubjectIndex
{
kTexture0SubjectIndex = 0,
kTextureMaxSubjectIndex = kTexture0SubjectIndex + IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
kUniformBuffer0SubjectIndex = kTextureMaxSubjectIndex,
kUniformBufferMaxSubjectIndex =
kUniformBuffer0SubjectIndex + IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS,
kSampler0SubjectIndex = kUniformBufferMaxSubjectIndex,
kSamplerMaxSubjectIndex = kSampler0SubjectIndex + IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
kVertexArraySubjectIndex = kSamplerMaxSubjectIndex,
kReadFramebufferSubjectIndex,
kDrawFramebufferSubjectIndex
};
} // anonymous namespace
Context::Context(rx::EGLImplFactory *implFactory,
const egl::Config *config,
const Context *shareContext,
TextureManager *shareTextures,
MemoryProgramCache *memoryProgramCache,
const egl::AttributeMap &attribs,
const egl::DisplayExtensions &displayExtensions,
const egl::ClientExtensions &clientExtensions)
: mState(reinterpret_cast<ContextID>(this),
shareContext ? &shareContext->mState : nullptr,
shareTextures,
GetClientVersion(attribs),
GetDebug(attribs),
GetBindGeneratesResource(attribs),
GetClientArraysEnabled(attribs),
GetRobustResourceInit(attribs),
memoryProgramCache != nullptr),
mSkipValidation(GetNoError(attribs)),
mDisplayTextureShareGroup(shareTextures != nullptr),
mErrors(this),
mImplementation(implFactory->createContext(mState, &mErrors, config, shareContext, attribs)),
mLabel(nullptr),
mCompiler(),
mConfig(config),
mClientType(EGL_OPENGL_ES_API),
mHasBeenCurrent(false),
mContextLost(false),
mResetStatus(GL_NO_ERROR),
mContextLostForced(false),
mResetStrategy(GetResetStrategy(attribs)),
mRobustAccess(GetRobustAccess(attribs)),
mSurfacelessSupported(displayExtensions.surfacelessContext),
mExplicitContextAvailable(clientExtensions.explicitContext),
mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
mWebGLContext(GetWebGLContext(attribs)),
mBufferAccessValidationEnabled(false),
mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
mMemoryProgramCache(memoryProgramCache),
mVertexArrayObserverBinding(this, kVertexArraySubjectIndex),
mDrawFramebufferObserverBinding(this, kDrawFramebufferSubjectIndex),
mReadFramebufferObserverBinding(this, kReadFramebufferSubjectIndex),
mScratchBuffer(1000u),
mZeroFilledBuffer(1000u),
mThreadPool(nullptr)
{
for (angle::SubjectIndex uboIndex = kUniformBuffer0SubjectIndex;
uboIndex < kUniformBufferMaxSubjectIndex; ++uboIndex)
{
mUniformBufferObserverBindings.emplace_back(this, uboIndex);
}
for (angle::SubjectIndex samplerIndex = kSampler0SubjectIndex;
samplerIndex < kSamplerMaxSubjectIndex; ++samplerIndex)
{
mSamplerObserverBindings.emplace_back(this, samplerIndex);
}
}
void Context::initialize()
{
mImplementation->setMemoryProgramCache(mMemoryProgramCache);
initCaps();
initWorkarounds();
mState.initialize(this);
mFenceNVHandleAllocator.setBaseHandle(0);
// [OpenGL ES 2.0.24] section 3.7 page 83:
// In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
// and cube map texture state vectors respectively associated with them.
// In order that access to these initial textures not be lost, they are treated as texture
// objects all of whose names are 0.
Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
if (getClientVersion() >= Version(3, 0))
{
// TODO: These could also be enabled via extension
Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
}
if (getClientVersion() >= Version(3, 1) || mSupportedExtensions.textureMultisample)
{
Texture *zeroTexture2DMultisample =
new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
}
if (getClientVersion() >= Version(3, 1))
{
Texture *zeroTexture2DMultisampleArray =
new Texture(mImplementation.get(), 0, TextureType::_2DMultisampleArray);
mZeroTextures[TextureType::_2DMultisampleArray].set(this, zeroTexture2DMultisampleArray);
for (unsigned int i = 0; i < mState.mCaps.maxAtomicCounterBufferBindings; i++)
{
bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
}
for (unsigned int i = 0; i < mState.mCaps.maxShaderStorageBufferBindings; i++)
{
bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
}
}
if (mSupportedExtensions.textureRectangle)
{
Texture *zeroTextureRectangle =
new Texture(mImplementation.get(), 0, TextureType::Rectangle);
mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
}
if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
{
Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
}
mState.initializeZeroTextures(this, mZeroTextures);
bindVertexArray(0);
if (getClientVersion() >= Version(3, 0))
{
// [OpenGL ES 3.0.2] section 2.14.1 pg 85:
// In the initial state, a default transform feedback object is bound and treated as
// a transform feedback object with a name of zero. That object is bound any time
// BindTransformFeedback is called with id of zero
bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
}
for (auto type : angle::AllEnums<BufferBinding>())
{
bindBuffer(type, 0);
}
bindRenderbuffer(GL_RENDERBUFFER, 0);
for (unsigned int i = 0; i < mState.mCaps.maxUniformBufferBindings; i++)
{
bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
}
// Initialize GLES1 renderer if appropriate.
if (getClientVersion() < Version(2, 0))
{
mGLES1Renderer.reset(new GLES1Renderer());
}
// Initialize dirty bit masks
mAllDirtyBits.set();
mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
mDrawDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
mDrawDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
mDrawDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
// No dirty objects.
// Readpixels uses the pack state and read FBO
mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
mComputeDirtyBits.set(State::DIRTY_BIT_UNIFORM_BUFFER_BINDINGS);
mComputeDirtyBits.set(State::DIRTY_BIT_ATOMIC_COUNTER_BUFFER_BINDING);
mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
mComputeDirtyBits.set(State::DIRTY_BIT_IMAGE_BINDINGS);
mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
mComputeDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
mComputeDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
ANGLE_CONTEXT_TRY(mImplementation->initialize());
}
egl::Error Context::onDestroy(const egl::Display *display)
{
if (mGLES1Renderer)
{
mGLES1Renderer->onDestroy(this, &mState);
}
ANGLE_TRY(releaseSurface(display));
for (auto fence : mFenceNVMap)
{
SafeDelete(fence.second);
}
mFenceNVMap.clear();
for (auto query : mQueryMap)
{
if (query.second != nullptr)
{
query.second->release(this);
}
}
mQueryMap.clear();
for (auto vertexArray : mVertexArrayMap)
{
if (vertexArray.second)
{
vertexArray.second->onDestroy(this);
}
}
mVertexArrayMap.clear();
for (auto transformFeedback : mTransformFeedbackMap)
{
if (transformFeedback.second != nullptr)
{
transformFeedback.second->release(this);
}
}
mTransformFeedbackMap.clear();
for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
{
if (zeroTexture.get() != nullptr)
{
zeroTexture.set(this, nullptr);
}
}
releaseShaderCompiler();
mState.reset(this);
mState.mBufferManager->release(this);
mState.mShaderProgramManager->release(this);
mState.mTextureManager->release(this);
mState.mRenderbufferManager->release(this);
mState.mSamplerManager->release(this);
mState.mSyncManager->release(this);
mState.mPathManager->release(this);
mState.mFramebufferManager->release(this);
mState.mProgramPipelineManager->release(this);
mThreadPool.reset();
mImplementation->onDestroy(this);
return egl::NoError();
}
Context::~Context() {}
void Context::setLabel(EGLLabelKHR label)
{
mLabel = label;
}
EGLLabelKHR Context::getLabel() const
{
return mLabel;
}
egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
{
mCurrentDisplay = display;
if (!mHasBeenCurrent)
{
initialize();
initRendererString();
initVersionStrings();
initExtensionStrings();
int width = 0;
int height = 0;
if (surface != nullptr)
{
width = surface->getWidth();
height = surface->getHeight();
}
mState.setViewportParams(0, 0, width, height);
mState.setScissorParams(0, 0, width, height);
mHasBeenCurrent = true;
}
// TODO(jmadill): Rework this when we support ContextImpl
mState.setAllDirtyBits();
mState.setAllDirtyObjects();
ANGLE_TRY(releaseSurface(display));
Framebuffer *newDefault = nullptr;
if (surface != nullptr)
{
ANGLE_TRY(surface->setIsCurrent(this, true));
mCurrentSurface = surface;
newDefault = surface->createDefaultFramebuffer(this);
}
else
{
newDefault = new Framebuffer(mImplementation.get());
}
// Update default framebuffer, the binding of the previous default
// framebuffer (or lack of) will have a nullptr.
{
mState.mFramebufferManager->setDefaultFramebuffer(newDefault);
if (mState.getReadFramebuffer() == nullptr)
{
bindReadFramebuffer(0);
}
if (mState.getDrawFramebuffer() == nullptr)
{
bindDrawFramebuffer(0);
}
}
// Notify the renderer of a context switch.
return angle::ResultToEGL(mImplementation->onMakeCurrent(this));
}
egl::Error Context::releaseSurface(const egl::Display *display)
{
gl::Framebuffer *defaultFramebuffer = mState.mFramebufferManager->getFramebuffer(0);
// Remove the default framebuffer
if (mState.getReadFramebuffer() == defaultFramebuffer)
{
mState.setReadFramebufferBinding(nullptr);
mReadFramebufferObserverBinding.bind(nullptr);
}
if (mState.getDrawFramebuffer() == defaultFramebuffer)
{
mState.setDrawFramebufferBinding(nullptr);
mDrawFramebufferObserverBinding.bind(nullptr);
}
if (defaultFramebuffer)
{
defaultFramebuffer->onDestroy(this);
delete defaultFramebuffer;
}
mState.mFramebufferManager->setDefaultFramebuffer(nullptr);
if (mCurrentSurface)
{
ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
mCurrentSurface = nullptr;
}
return egl::NoError();
}
GLuint Context::createBuffer()
{
return mState.mBufferManager->createBuffer();
}
GLuint Context::createProgram()
{
return mState.mShaderProgramManager->createProgram(mImplementation.get());
}
GLuint Context::createShader(ShaderType type)
{
return mState.mShaderProgramManager->createShader(mImplementation.get(), mState.mLimitations,
type);
}
GLuint Context::createTexture()
{
return mState.mTextureManager->createTexture();
}
GLuint Context::createRenderbuffer()
{
return mState.mRenderbufferManager->createRenderbuffer();
}
void Context::tryGenPaths(GLsizei range, GLuint *createdOut)
{
ANGLE_CONTEXT_TRY(mState.mPathManager->createPaths(this, range, createdOut));
}
GLuint Context::genPaths(GLsizei range)
{
GLuint created = 0;
tryGenPaths(range, &created);
return created;
}
// Returns an unused framebuffer name
GLuint Context::createFramebuffer()
{
return mState.mFramebufferManager->createFramebuffer();
}
void Context::genFencesNV(GLsizei n, GLuint *fences)
{
for (int i = 0; i < n; i++)
{
GLuint handle = mFenceNVHandleAllocator.allocate();
mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
fences[i] = handle;
}
}
GLuint Context::createProgramPipeline()
{
return mState.mProgramPipelineManager->createProgramPipeline();
}
GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
{
UNIMPLEMENTED();
return 0u;
}
void Context::deleteBuffer(GLuint bufferName)
{
Buffer *buffer = mState.mBufferManager->getBuffer(bufferName);
if (buffer)
{
detachBuffer(buffer);
}
mState.mBufferManager->deleteObject(this, bufferName);
}
void Context::deleteShader(GLuint shader)
{
mState.mShaderProgramManager->deleteShader(this, shader);
}
void Context::deleteProgram(GLuint program)
{
mState.mShaderProgramManager->deleteProgram(this, program);
}
void Context::deleteTexture(GLuint texture)
{
if (mState.mTextureManager->getTexture(texture))
{
detachTexture(texture);
}
mState.mTextureManager->deleteObject(this, texture);
}
void Context::deleteRenderbuffer(GLuint renderbuffer)
{
if (mState.mRenderbufferManager->getRenderbuffer(renderbuffer))
{
detachRenderbuffer(renderbuffer);
}
mState.mRenderbufferManager->deleteObject(this, renderbuffer);
}
void Context::deleteSync(GLsync sync)
{
// The spec specifies the underlying Fence object is not deleted until all current
// wait commands finish. However, since the name becomes invalid, we cannot query the fence,
// and since our API is currently designed for being called from a single thread, we can delete
// the fence immediately.
mState.mSyncManager->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
}
void Context::deleteProgramPipeline(GLuint pipeline)
{
if (mState.mProgramPipelineManager->getProgramPipeline(pipeline))
{
detachProgramPipeline(pipeline);
}
mState.mProgramPipelineManager->deleteObject(this, pipeline);
}
void Context::deletePaths(GLuint first, GLsizei range)
{
mState.mPathManager->deletePaths(first, range);
}
bool Context::isPath(GLuint path) const
{
const auto *pathObj = mState.mPathManager->getPath(path);
if (pathObj == nullptr)
return false;
return pathObj->hasPathData();
}
bool Context::isPathGenerated(GLuint path) const
{
return mState.mPathManager->hasPath(path);
}
void Context::pathCommands(GLuint path,
GLsizei numCommands,
const GLubyte *commands,
GLsizei numCoords,
GLenum coordType,
const void *coords)
{
auto *pathObject = mState.mPathManager->getPath(path);
ANGLE_CONTEXT_TRY(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
}
void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
{
Path *pathObj = mState.mPathManager->getPath(path);
switch (pname)
{
case GL_PATH_STROKE_WIDTH_CHROMIUM:
pathObj->setStrokeWidth(value);
break;
case GL_PATH_END_CAPS_CHROMIUM:
pathObj->setEndCaps(static_cast<GLenum>(value));
break;
case GL_PATH_JOIN_STYLE_CHROMIUM:
pathObj->setJoinStyle(static_cast<GLenum>(value));
break;
case GL_PATH_MITER_LIMIT_CHROMIUM:
pathObj->setMiterLimit(value);
break;
case GL_PATH_STROKE_BOUND_CHROMIUM:
pathObj->setStrokeBound(value);
break;
default:
UNREACHABLE();
break;
}
}
void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
{
// TODO(jmadill): Should use proper clamping/casting.
pathParameterf(path, pname, static_cast<GLfloat>(value));
}
void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
{
const Path *pathObj = mState.mPathManager->getPath(path);
switch (pname)
{
case GL_PATH_STROKE_WIDTH_CHROMIUM:
*value = pathObj->getStrokeWidth();
break;
case GL_PATH_END_CAPS_CHROMIUM:
*value = static_cast<GLfloat>(pathObj->getEndCaps());
break;
case GL_PATH_JOIN_STYLE_CHROMIUM:
*value = static_cast<GLfloat>(pathObj->getJoinStyle());
break;
case GL_PATH_MITER_LIMIT_CHROMIUM:
*value = pathObj->getMiterLimit();
break;
case GL_PATH_STROKE_BOUND_CHROMIUM:
*value = pathObj->getStrokeBound();
break;
default:
UNREACHABLE();
break;
}
}
void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
{
GLfloat val = 0.0f;
getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
if (value)
*value = static_cast<GLint>(val);
}
void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
{
mState.setPathStencilFunc(func, ref, mask);
}
void Context::deleteFramebuffer(GLuint framebuffer)
{
if (mState.mFramebufferManager->getFramebuffer(framebuffer))
{
detachFramebuffer(framebuffer);
}
mState.mFramebufferManager->deleteObject(this, framebuffer);
}
void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
{
for (int i = 0; i < n; i++)
{
GLuint fence = fences[i];
FenceNV *fenceObject = nullptr;
if (mFenceNVMap.erase(fence, &fenceObject))
{
mFenceNVHandleAllocator.release(fence);
delete fenceObject;
}
}
}
Buffer *Context::getBuffer(GLuint handle) const
{
return mState.mBufferManager->getBuffer(handle);
}
Renderbuffer *Context::getRenderbuffer(GLuint handle) const
{
return mState.mRenderbufferManager->getRenderbuffer(handle);
}
Sync *Context::getSync(GLsync handle) const
{
return mState.mSyncManager->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
}
VertexArray *Context::getVertexArray(GLuint handle) const
{
return mVertexArrayMap.query(handle);
}
Sampler *Context::getSampler(GLuint handle) const
{
return mState.mSamplerManager->getSampler(handle);
}
TransformFeedback *Context::getTransformFeedback(GLuint handle) const
{
return mTransformFeedbackMap.query(handle);
}
ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
{
return mState.mProgramPipelineManager->getProgramPipeline(handle);
}
gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
{
switch (identifier)
{
case GL_BUFFER:
return getBuffer(name);
case GL_SHADER:
return getShader(name);
case GL_PROGRAM:
return getProgramNoResolveLink(name);
case GL_VERTEX_ARRAY:
return getVertexArray(name);
case GL_QUERY:
return getQuery(name);
case GL_TRANSFORM_FEEDBACK:
return getTransformFeedback(name);
case GL_SAMPLER:
return getSampler(name);
case GL_TEXTURE:
return getTexture(name);
case GL_RENDERBUFFER:
return getRenderbuffer(name);
case GL_FRAMEBUFFER:
return getFramebuffer(name);
default:
UNREACHABLE();
return nullptr;
}
}
gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
{
return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
}
void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
{
gl::LabeledObject *object = getLabeledObject(identifier, name);
ASSERT(object != nullptr);
std::string labelName = GetObjectLabelFromPointer(length, label);
object->setLabel(this, labelName);
// TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
// specified object is active until we do this.
mState.setObjectDirty(identifier);
}
void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
{
gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
ASSERT(object != nullptr);
std::string labelName = GetObjectLabelFromPointer(length, label);
object->setLabel(this, labelName);
}
void Context::getObjectLabel(GLenum identifier,
GLuint name,
GLsizei bufSize,
GLsizei *length,
GLchar *label) const
{
gl::LabeledObject *object = getLabeledObject(identifier, name);
ASSERT(object != nullptr);
const std::string &objectLabel = object->getLabel();
GetObjectLabelBase(objectLabel, bufSize, length, label);
}
void Context::getObjectPtrLabel(const void *ptr,
GLsizei bufSize,
GLsizei *length,
GLchar *label) const
{
gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
ASSERT(object != nullptr);
const std::string &objectLabel = object->getLabel();
GetObjectLabelBase(objectLabel, bufSize, length, label);
}
bool Context::isSampler(GLuint samplerName) const
{
return mState.mSamplerManager->isSampler(samplerName);
}
void Context::bindTexture(TextureType target, GLuint handle)
{
Texture *texture = nullptr;
if (handle == 0)
{
texture = mZeroTextures[target].get();
}
else
{
texture =
mState.mTextureManager->checkTextureAllocation(mImplementation.get(), handle, target);
}
ASSERT(texture);
mState.setSamplerTexture(this, target, texture);
mStateCache.onActiveTextureChange(this);
}
void Context::bindReadFramebuffer(GLuint framebufferHandle)
{
Framebuffer *framebuffer = mState.mFramebufferManager->checkFramebufferAllocation(
mImplementation.get(), mState.mCaps, framebufferHandle);
mState.setReadFramebufferBinding(framebuffer);
mReadFramebufferObserverBinding.bind(framebuffer);
}
void Context::bindDrawFramebuffer(GLuint framebufferHandle)
{
Framebuffer *framebuffer = mState.mFramebufferManager->checkFramebufferAllocation(
mImplementation.get(), mState.mCaps, framebufferHandle);
mState.setDrawFramebufferBinding(framebuffer);
mDrawFramebufferObserverBinding.bind(framebuffer);
mStateCache.onDrawFramebufferChange(this);
}
void Context::bindVertexArray(GLuint vertexArrayHandle)
{
VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
mState.setVertexArrayBinding(this, vertexArray);
mVertexArrayObserverBinding.bind(vertexArray);
mStateCache.onVertexArrayBindingChange(this);
}
void Context::bindVertexBuffer(GLuint bindingIndex,
GLuint bufferHandle,
GLintptr offset,
GLsizei stride)
{
Buffer *buffer =
mState.mBufferManager->checkBufferAllocation(mImplementation.get(), bufferHandle);
mState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
mStateCache.onVertexArrayStateChange(this);
}
void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
{
ASSERT(textureUnit < mState.mCaps.maxCombinedTextureImageUnits);
Sampler *sampler =
mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), samplerHandle);
mState.setSamplerBinding(this, textureUnit, sampler);
mSamplerObserverBindings[textureUnit].bind(sampler);
}
void Context::bindImageTexture(GLuint unit,
GLuint texture,
GLint level,
GLboolean layered,
GLint layer,
GLenum access,
GLenum format)
{
Texture *tex = mState.mTextureManager->getTexture(texture);
mState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
}
void Context::useProgram(GLuint program)
{
ANGLE_CONTEXT_TRY(mState.setProgram(this, getProgramResolveLink(program)));
mStateCache.onProgramExecutableChange(this);
}
void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
{
UNIMPLEMENTED();
}
void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
{
ASSERT(target == GL_TRANSFORM_FEEDBACK);
TransformFeedback *transformFeedback =
checkTransformFeedbackAllocation(transformFeedbackHandle);
mState.setTransformFeedbackBinding(this, transformFeedback);
}
void Context::bindProgramPipeline(GLuint pipelineHandle)
{
ProgramPipeline *pipeline = mState.mProgramPipelineManager->checkProgramPipelineAllocation(
mImplementation.get(), pipelineHandle);
mState.setProgramPipelineBinding(this, pipeline);
}
void Context::beginQuery(QueryType target, GLuint query)
{
Query *queryObject = getQuery(query, true, target);
ASSERT(queryObject);
// begin query
ANGLE_CONTEXT_TRY(queryObject->begin(this));
// set query as active for specified target only if begin succeeded
mState.setActiveQuery(this, target, queryObject);
mStateCache.onQueryChange(this);
}
void Context::endQuery(QueryType target)
{
Query *queryObject = mState.getActiveQuery(target);
ASSERT(queryObject);
// Intentionally don't call try here. We don't want an early return.
(void)(queryObject->end(this));
// Always unbind the query, even if there was an error. This may delete the query object.
mState.setActiveQuery(this, target, nullptr);
mStateCache.onQueryChange(this);
}
void Context::queryCounter(GLuint id, QueryType target)
{
ASSERT(target == QueryType::Timestamp);
Query *queryObject = getQuery(id, true, target);
ASSERT(queryObject);
ANGLE_CONTEXT_TRY(queryObject->queryCounter(this));
}
void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
{
switch (pname)
{
case GL_CURRENT_QUERY_EXT:
params[0] = mState.getActiveQueryId(target);
break;
case GL_QUERY_COUNTER_BITS_EXT:
switch (target)
{
case QueryType::TimeElapsed:
params[0] = getExtensions().queryCounterBitsTimeElapsed;
break;
case QueryType::Timestamp:
params[0] = getExtensions().queryCounterBitsTimestamp;
break;
default:
UNREACHABLE();
params[0] = 0;
break;
}
break;
default:
UNREACHABLE();
return;
}
}
void Context::getQueryivRobust(QueryType target,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLint *params)
{
getQueryiv(target, pname, params);
}
void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
{
ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
}
void Context::getQueryObjectivRobust(GLuint id,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLint *params)
{
getQueryObjectiv(id, pname, params);
}
void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
{
ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
}
void Context::getQueryObjectuivRobust(GLuint id,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLuint *params)
{
getQueryObjectuiv(id, pname, params);
}
void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
{
ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
}
void Context::getQueryObjecti64vRobust(GLuint id,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLint64 *params)
{
getQueryObjecti64v(id, pname, params);
}
void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
{
ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
}
void Context::getQueryObjectui64vRobust(GLuint id,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLuint64 *params)
{
getQueryObjectui64v(id, pname, params);
}
Framebuffer *Context::getFramebuffer(GLuint handle) const
{
return mState.mFramebufferManager->getFramebuffer(handle);
}
FenceNV *Context::getFenceNV(GLuint handle)
{
return mFenceNVMap.query(handle);
}
Query *Context::getQuery(GLuint handle, bool create, QueryType type)
{
if (!mQueryMap.contains(handle))
{
return nullptr;
}
Query *query = mQueryMap.query(handle);
if (!query && create)
{
ASSERT(type != QueryType::InvalidEnum);
query = new Query(mImplementation->createQuery(type), handle);
query->addRef();
mQueryMap.assign(handle, query);
}
return query;
}
Query *Context::getQuery(GLuint handle) const
{
return mQueryMap.query(handle);
}
Texture *Context::getTargetTexture(TextureType type) const
{
ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
return mState.getTargetTexture(type);
}
Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
{
return mState.getSamplerTexture(sampler, type);
}
Compiler *Context::getCompiler() const
{
if (mCompiler.get() == nullptr)
{
mCompiler.set(this, new Compiler(mImplementation.get(), mState));
}
return mCompiler.get();
}
void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
{
switch (pname)
{
case GL_SHADER_COMPILER:
*params = GL_TRUE;
break;
case GL_CONTEXT_ROBUST_ACCESS_EXT:
*params = mRobustAccess ? GL_TRUE : GL_FALSE;
break;
default:
mState.getBooleanv(pname, params);
break;
}
}
void Context::getFloatvImpl(GLenum pname, GLfloat *params)
{
// Queries about context capabilities and maximums are answered by Context.
// Queries about current GL state values are answered by State.
switch (pname)
{
case GL_ALIASED_LINE_WIDTH_RANGE:
params[0] = mState.mCaps.minAliasedLineWidth;
params[1] = mState.mCaps.maxAliasedLineWidth;
break;
case GL_ALIASED_POINT_SIZE_RANGE:
params[0] = mState.mCaps.minAliasedPointSize;
params[1] = mState.mCaps.maxAliasedPointSize;
break;
case GL_SMOOTH_POINT_SIZE_RANGE:
params[0] = mState.mCaps.minSmoothPointSize;
params[1] = mState.mCaps.maxSmoothPointSize;
break;
case GL_SMOOTH_LINE_WIDTH_RANGE:
params[0] = mState.mCaps.minSmoothLineWidth;
params[1] = mState.mCaps.maxSmoothLineWidth;
break;
case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
ASSERT(mState.mExtensions.textureFilterAnisotropic);
*params = mState.mExtensions.maxTextureAnisotropy;
break;
case GL_MAX_TEXTURE_LOD_BIAS:
*params = mState.mCaps.maxLODBias;
break;
case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
{
// GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
// GLES1 constants for modelview/projection matrix.
if (getClientVersion() < Version(2, 0))
{
mState.getFloatv(pname, params);
}
else
{
ASSERT(mState.mExtensions.pathRendering);
const GLfloat *m = mState.getPathRenderingMatrix(pname);
memcpy(params, m, 16 * sizeof(GLfloat));
}
}
break;
default:
mState.getFloatv(pname, params);
break;
}
}
void Context::getIntegervImpl(GLenum pname, GLint *params)
{
// Queries about context capabilities and maximums are answered by Context.
// Queries about current GL state values are answered by State.
switch (pname)
{
case GL_MAX_VERTEX_ATTRIBS:
*params = mState.mCaps.maxVertexAttributes;
break;
case GL_MAX_VERTEX_UNIFORM_VECTORS:
*params = mState.mCaps.maxVertexUniformVectors;
break;
case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
*params = mState.mCaps.maxShaderUniformComponents[ShaderType::Vertex];
break;
case GL_MAX_VARYING_VECTORS:
*params = mState.mCaps.maxVaryingVectors;
break;
case GL_MAX_VARYING_COMPONENTS:
*params = mState.mCaps.maxVertexOutputComponents;
break;
case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
*params = mState.mCaps.maxCombinedTextureImageUnits;
break;
case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
*params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
break;
case GL_MAX_TEXTURE_IMAGE_UNITS:
*params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
break;
case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
*params = mState.mCaps.maxFragmentUniformVectors;
break;
case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
*params = mState.mCaps.maxShaderUniformComponents[ShaderType::Fragment];
break;
case GL_MAX_RENDERBUFFER_SIZE:
*params = mState.mCaps.maxRenderbufferSize;
break;
case GL_MAX_COLOR_ATTACHMENTS_EXT:
*params = mState.mCaps.maxColorAttachments;
break;
case GL_MAX_DRAW_BUFFERS_EXT:
*params = mState.mCaps.maxDrawBuffers;
break;
case GL_SUBPIXEL_BITS:
*params = 4;
break;
case GL_MAX_TEXTURE_SIZE:
*params = mState.mCaps.max2DTextureSize;
break;
case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
*params = mState.mCaps.maxRectangleTextureSize;
break;
case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
*params = mState.mCaps.maxCubeMapTextureSize;
break;
case GL_MAX_3D_TEXTURE_SIZE:
*params = mState.mCaps.max3DTextureSize;
break;
case GL_MAX_ARRAY_TEXTURE_LAYERS:
*params = mState.mCaps.maxArrayTextureLayers;
break;
case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
*params = mState.mCaps.uniformBufferOffsetAlignment;
break;
case GL_MAX_UNIFORM_BUFFER_BINDINGS:
*params = mState.mCaps.maxUniformBufferBindings;
break;
case GL_MAX_VERTEX_UNIFORM_BLOCKS:
*params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
break;
case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
*params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
break;
case GL_MAX_COMBINED_UNIFORM_BLOCKS:
*params = mState.mCaps.maxCombinedTextureImageUnits;
break;
case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
*params = mState.mCaps.maxVertexOutputComponents;
break;
case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
*params = mState.mCaps.maxFragmentInputComponents;
break;
case GL_MIN_PROGRAM_TEXEL_OFFSET:
*params = mState.mCaps.minProgramTexelOffset;
break;
case GL_MAX_PROGRAM_TEXEL_OFFSET:
*params = mState.mCaps.maxProgramTexelOffset;
break;
case GL_MAJOR_VERSION:
*params = getClientVersion().major;
break;
case GL_MINOR_VERSION:
*params = getClientVersion().minor;
break;
case GL_MAX_ELEMENTS_INDICES:
*params = mState.mCaps.maxElementsIndices;
break;
case GL_MAX_ELEMENTS_VERTICES:
*params = mState.mCaps.maxElementsVertices;
break;
case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
*params = mState.mCaps.maxTransformFeedbackInterleavedComponents;
break;
case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
*params = mState.mCaps.maxTransformFeedbackSeparateAttributes;
break;
case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
*params = mState.mCaps.maxTransformFeedbackSeparateComponents;
break;
case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
*params = static_cast<GLint>(mState.mCaps.compressedTextureFormats.size());
break;
case GL_MAX_SAMPLES_ANGLE:
*params = mState.mCaps.maxSamples;
break;
case GL_MAX_VIEWPORT_DIMS:
{
params[0] = mState.mCaps.maxViewportWidth;
params[1] = mState.mCaps.maxViewportHeight;
}
break;
case GL_COMPRESSED_TEXTURE_FORMATS:
std::copy(mState.mCaps.compressedTextureFormats.begin(),
mState.mCaps.compressedTextureFormats.end(), params);
break;
case GL_RESET_NOTIFICATION_STRATEGY_EXT:
*params = mResetStrategy;
break;
case GL_NUM_SHADER_BINARY_FORMATS:
*params = static_cast<GLint>(mState.mCaps.shaderBinaryFormats.size());
break;
case GL_SHADER_BINARY_FORMATS:
std::copy(mState.mCaps.shaderBinaryFormats.begin(),
mState.mCaps.shaderBinaryFormats.end(), params);
break;
case GL_NUM_PROGRAM_BINARY_FORMATS:
*params = static_cast<GLint>(mState.mCaps.programBinaryFormats.size());
break;
case GL_PROGRAM_BINARY_FORMATS:
std::copy(mState.mCaps.programBinaryFormats.begin(),
mState.mCaps.programBinaryFormats.end(), params);
break;
case GL_NUM_EXTENSIONS:
*params = static_cast<GLint>(mExtensionStrings.size());
break;
// GL_ANGLE_request_extension
case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
*params = static_cast<GLint>(mRequestableExtensionStrings.size());
break;
// GL_KHR_debug
case GL_MAX_DEBUG_MESSAGE_LENGTH:
*params = mState.mExtensions.maxDebugMessageLength;
break;
case GL_MAX_DEBUG_LOGGED_MESSAGES:
*params = mState.mExtensions.maxDebugLoggedMessages;
break;
case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
*params = mState.mExtensions.maxDebugGroupStackDepth;
break;
case GL_MAX_LABEL_LENGTH:
*params = mState.mExtensions.maxLabelLength;
break;
// GL_ANGLE_multiview
case GL_MAX_VIEWS_ANGLE:
*params = mState.mExtensions.maxViews;
break;
// GL_EXT_disjoint_timer_query
case GL_GPU_DISJOINT_EXT:
*params = mImplementation->getGPUDisjoint();
break;
case GL_MAX_FRAMEBUFFER_WIDTH:
*params = mState.mCaps.maxFramebufferWidth;
break;
case GL_MAX_FRAMEBUFFER_HEIGHT:
*params = mState.mCaps.maxFramebufferHeight;
break;
case GL_MAX_FRAMEBUFFER_SAMPLES:
*params = mState.mCaps.maxFramebufferSamples;
break;
case GL_MAX_SAMPLE_MASK_WORDS:
*params = mState.mCaps.maxSampleMaskWords;
break;
case GL_MAX_COLOR_TEXTURE_SAMPLES:
*params = mState.mCaps.maxColorTextureSamples;
break;
case GL_MAX_DEPTH_TEXTURE_SAMPLES:
*params = mState.mCaps.maxDepthTextureSamples;
break;
case GL_MAX_INTEGER_SAMPLES:
*params = mState.mCaps.maxIntegerSamples;
break;
case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
*params = mState.mCaps.maxVertexAttribRelativeOffset;
break;
case GL_MAX_VERTEX_ATTRIB_BINDINGS:
*params = mState.mCaps.maxVertexAttribBindings;
break;
case GL_MAX_VERTEX_ATTRIB_STRIDE:
*params = mState.mCaps.maxVertexAttribStride;
break;
case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
*params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
break;
case GL_MAX_VERTEX_ATOMIC_COUNTERS:
*params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
break;
case GL_MAX_VERTEX_IMAGE_UNIFORMS:
*params = mState.mCaps.maxShaderImageUniforms[ShaderType::Vertex];
break;
case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
*params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
break;
case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
*params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
break;
case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
*params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
break;
case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
*params = mState.mCaps.maxShaderImageUniforms[ShaderType::Fragment];
break;
case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
*params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
break;
case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
*params = mState.mCaps.minProgramTextureGatherOffset;
break;
case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
*params = mState.mCaps.maxProgramTextureGatherOffset;
break;
case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
*params = mState.mCaps.maxComputeWorkGroupInvocations;
break;
case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
*params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Compute];
break;
case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
*params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
break;
case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
*params = mState.mCaps.maxComputeSharedMemorySize;
break;
case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
*params = mState.mCaps.maxShaderUniformComponents[ShaderType::Compute];
break;
case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
*params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
break;
case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
*params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Compute];
break;
case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
*params = mState.mCaps.maxShaderImageUniforms[ShaderType::Compute];
break;
case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
*params = static_cast<GLint>(
mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
break;
case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
*params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Compute];
break;
case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
*params = mState.mCaps.maxCombinedShaderOutputResources;
break;
case GL_MAX_UNIFORM_LOCATIONS:
*params = mState.mCaps.maxUniformLocations;
break;
case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
*params = mState.mCaps.maxAtomicCounterBufferBindings;
break;
case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
*params = mState.mCaps.maxAtomicCounterBufferSize;
break;
case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
*params = mState.mCaps.maxCombinedAtomicCounterBuffers;
break;
case GL_MAX_COMBINED_ATOMIC_COUNTERS:
*params = mState.mCaps.maxCombinedAtomicCounters;
break;
case GL_MAX_IMAGE_UNITS:
*params = mState.mCaps.maxImageUnits;
break;
case GL_MAX_COMBINED_IMAGE_UNIFORMS:
*params = mState.mCaps.maxCombinedImageUniforms;
break;
case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
*params = mState.mCaps.maxShaderStorageBufferBindings;
break;
case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
*params = mState.mCaps.maxCombinedShaderStorageBlocks;
break;
case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
*params = mState.mCaps.shaderStorageBufferOffsetAlignment;
break;
// GL_EXT_geometry_shader
case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
*params = mState.mCaps.maxFramebufferLayers;
break;
case GL_LAYER_PROVOKING_VERTEX_EXT:
*params = mState.mCaps.layerProvokingVertex;
break;
case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
*params = mState.mCaps.maxShaderUniformComponents[ShaderType::Geometry];
break;
case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
*params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
break;
case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
*params = static_cast<GLint>(
mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
break;
case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
*params = mState.mCaps.maxGeometryInputComponents;
break;
case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
*params = mState.mCaps.maxGeometryOutputComponents;
break;
case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
*params = mState.mCaps.maxGeometryOutputVertices;
break;
case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
*params = mState.mCaps.maxGeometryTotalOutputComponents;
break;
case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
*params = mState.mCaps.maxGeometryShaderInvocations;
break;
case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
*params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
break;
case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
*params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
break;
case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
*params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
break;
case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
*params = mState.mCaps.maxShaderImageUniforms[ShaderType::Geometry];
break;
case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
*params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
break;
// GLES1 emulation: Caps queries
case GL_MAX_TEXTURE_UNITS:
*params = mState.mCaps.maxMultitextureUnits;
break;
case GL_MAX_MODELVIEW_STACK_DEPTH:
*params = mState.mCaps.maxModelviewMatrixStackDepth;
break;
case GL_MAX_PROJECTION_STACK_DEPTH:
*params = mState.mCaps.maxProjectionMatrixStackDepth;
break;
case GL_MAX_TEXTURE_STACK_DEPTH:
*params = mState.mCaps.maxTextureMatrixStackDepth;
break;
case GL_MAX_LIGHTS:
*params = mState.mCaps.maxLights;
break;
case GL_MAX_CLIP_PLANES:
*params = mState.mCaps.maxClipPlanes;
break;
// GLES1 emulation: Vertex attribute queries
case GL_VERTEX_ARRAY_BUFFER_BINDING:
case GL_NORMAL_ARRAY_BUFFER_BINDING:
case GL_COLOR_ARRAY_BUFFER_BINDING:
case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
break;
case GL_VERTEX_ARRAY_STRIDE:
case GL_NORMAL_ARRAY_STRIDE:
case GL_COLOR_ARRAY_STRIDE:
case GL_POINT_SIZE_ARRAY_STRIDE_OES:
case GL_TEXTURE_COORD_ARRAY_STRIDE:
getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
break;
case GL_VERTEX_ARRAY_SIZE:
case GL_COLOR_ARRAY_SIZE:
case GL_TEXTURE_COORD_ARRAY_SIZE:
getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
break;
case GL_VERTEX_ARRAY_TYPE:
case GL_COLOR_ARRAY_TYPE:
case GL_NORMAL_ARRAY_TYPE:
case GL_POINT_SIZE_ARRAY_TYPE_OES:
case GL_TEXTURE_COORD_ARRAY_TYPE:
getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
break;
// GL_KHR_parallel_shader_compile
case GL_MAX_SHADER_COMPILER_THREADS_KHR:
*params = mState.getMaxShaderCompilerThreads();
break;
// GL_EXT_blend_func_extended
case GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT:
*params = mState.mExtensions.maxDualSourceDrawBuffers;
break;
default:
ANGLE_CONTEXT_TRY(mState.getIntegerv(this, pname, params));
break;
}
}
void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
{
// Queries about context capabilities and maximums are answered by Context.
// Queries about current GL state values are answered by State.
switch (pname)
{
case GL_MAX_ELEMENT_INDEX:
*params = mState.mCaps.maxElementIndex;
break;
case GL_MAX_UNIFORM_BLOCK_SIZE:
*params = mState.mCaps.maxUniformBlockSize;
break;
case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
*params = mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
break;
case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
*params = mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
break;
case GL_MAX_SERVER_WAIT_TIMEOUT:
*params = mState.mCaps.maxServerWaitTimeout;
break;
// GL_EXT_disjoint_timer_query
case GL_TIMESTAMP_EXT:
*params = mImplementation->getTimestamp();
break;
case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
*params = mState.mCaps.maxShaderStorageBlockSize;
break;
default:
UNREACHABLE();
break;
}
}
void Context::getPointerv(GLenum pname, void **params) const
{
mState.getPointerv(this, pname, params);
}
void Context::getPointervRobustANGLERobust(GLenum pname,
GLsizei bufSize,
GLsizei *length,
void **params)
{
UNIMPLEMENTED();
}
void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
{
// Queries about context capabilities and maximums are answered by Context.
// Queries about current GL state values are answered by State.
GLenum nativeType;
unsigned int numParams;
bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
ASSERT(queryStatus);
if (nativeType == GL_INT)
{
switch (target)
{
case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
ASSERT(index < 3u);
*data = mState.mCaps.maxComputeWorkGroupCount[index];
break;
case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
ASSERT(index < 3u);
*data = mState.mCaps.maxComputeWorkGroupSize[index];
break;
default:
mState.getIntegeri_v(target, index, data);
}
}
else
{
CastIndexedStateValues(this, nativeType, target, index, numParams, data);
}
}
void Context::getIntegeri_vRobust(GLenum target,
GLuint index,
GLsizei bufSize,
GLsizei *length,
GLint *data)
{
getIntegeri_v(target, index, data);
}
void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
{
// Queries about context capabilities and maximums are answered by Context.
// Queries about current GL state values are answered by State.
GLenum nativeType;
unsigned int numParams;
bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
ASSERT(queryStatus);
if (nativeType == GL_INT_64_ANGLEX)
{
mState.getInteger64i_v(target, index, data);
}
else
{
CastIndexedStateValues(this, nativeType, target, index, numParams, data);
}
}
void Context::getInteger64i_vRobust(GLenum target,
GLuint index,
GLsizei bufSize,
GLsizei *length,
GLint64 *data)
{
getInteger64i_v(target, index, data);
}
void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
{
// Queries about context capabilities and maximums are answered by Context.
// Queries about current GL state values are answered by State.
GLenum nativeType;
unsigned int numParams;
bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
ASSERT(queryStatus);
if (nativeType == GL_BOOL)
{
mState.getBooleani_v(target, index, data);
}
else
{
CastIndexedStateValues(this, nativeType, target, index, numParams, data);
}
}
void Context::getBooleani_vRobust(GLenum target,
GLuint index,
GLsizei bufSize,
GLsizei *length,
GLboolean *data)
{
getBooleani_v(target, index, data);
}
void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
{
Buffer *buffer = mState.getTargetBuffer(target);
QueryBufferParameteriv(buffer, pname, params);
}
void Context::getBufferParameterivRobust(BufferBinding target,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLint *params)
{
getBufferParameteriv(target, pname, params);
}
void Context::getFramebufferAttachmentParameteriv(GLenum target,
GLenum attachment,
GLenum pname,
GLint *params)
{
const Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
}
void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
GLenum attachment,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLint *params)
{
getFramebufferAttachmentParameteriv(target, attachment, pname, params);
}
void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
{
Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
QueryRenderbufferiv(this, renderbuffer, pname, params);
}
void Context::getRenderbufferParameterivRobust(GLenum target,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLint *params)
{
getRenderbufferParameteriv(target, pname, params);
}
void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
{
const Texture *const texture = getTargetTexture(target);
QueryTexParameterfv(texture, pname, params);
}
void Context::getTexParameterfvRobust(TextureType target,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLfloat *params)
{
getTexParameterfv(target, pname, params);
}
void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
{
const Texture *const texture = getTargetTexture(target);
QueryTexParameteriv(texture, pname, params);
}
void Context::getTexParameterIiv(TextureType target, GLenum pname, GLint *params)
{
const Texture *const texture = getTargetTexture(target);
QueryTexParameterIiv(texture, pname, params);
}
void Context::getTexParameterIuiv(TextureType target, GLenum pname, GLuint *params)
{
const Texture *const texture = getTargetTexture(target);
QueryTexParameterIuiv(texture, pname, params);
}
void Context::getTexParameterivRobust(TextureType target,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLint *params)
{
getTexParameteriv(target, pname, params);
}
void Context::getTexParameterIivRobust(TextureType target,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLint *params)
{
UNIMPLEMENTED();
}
void Context::getTexParameterIuivRobust(TextureType target,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLuint *params)
{
UNIMPLEMENTED();
}
void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
{
Texture *texture = getTargetTexture(TextureTargetToType(target));
QueryTexLevelParameteriv(texture, target, level, pname, params);
}
void Context::getTexLevelParameterivRobust(TextureTarget target,
GLint level,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLint *params)
{
UNIMPLEMENTED();
}
void Context::getTexLevelParameterfv(TextureTarget target,
GLint level,
GLenum pname,
GLfloat *params)
{
Texture *texture = getTargetTexture(TextureTargetToType(target));
QueryTexLevelParameterfv(texture, target, level, pname, params);
}
void Context::getTexLevelParameterfvRobust(TextureTarget target,
GLint level,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLfloat *params)
{
UNIMPLEMENTED();
}
void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
{
Texture *const texture = getTargetTexture(target);
SetTexParameterf(this, texture, pname, param);
}
void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
{
Texture *const texture = getTargetTexture(target);
SetTexParameterfv(this, texture, pname, params);
}
void Context::texParameterfvRobust(TextureType target,
GLenum pname,
GLsizei bufSize,
const GLfloat *params)
{
texParameterfv(target, pname, params);
}
void Context::texParameteri(TextureType target, GLenum pname, GLint param)
{
Texture *const texture = getTargetTexture(target);
SetTexParameteri(this, texture, pname, param);
}
void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
{
Texture *const texture = getTargetTexture(target);
SetTexParameteriv(this, texture, pname, params);
}
void Context::texParameterIiv(TextureType target, GLenum pname, const GLint *params)
{
Texture *const texture = getTargetTexture(target);
SetTexParameterIiv(this, texture, pname, params);
}
void Context::texParameterIuiv(TextureType target, GLenum pname, const GLuint *params)
{
Texture *const texture = getTargetTexture(target);
SetTexParameterIuiv(this, texture, pname, params);
}
void Context::texParameterivRobust(TextureType target,
GLenum pname,
GLsizei bufSize,
const GLint *params)
{
texParameteriv(target, pname, params);
}
void Context::texParameterIivRobust(TextureType target,
GLenum pname,
GLsizei bufSize,
const GLint *params)
{
UNIMPLEMENTED();
}
void Context::texParameterIuivRobust(TextureType target,
GLenum pname,
GLsizei bufSize,
const GLuint *params)
{
UNIMPLEMENTED();
}
void Context::drawArraysInstanced(PrimitiveMode mode,
GLint first,
GLsizei count,
GLsizei instanceCount)
{
// No-op if count draws no primitives for given mode
if (noopDrawInstanced(mode, count, instanceCount))
{
return;
}
ANGLE_CONTEXT_TRY(prepareForDraw(mode));
ANGLE_CONTEXT_TRY(
mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
MarkTransformFeedbackBufferUsage(this, count, instanceCount);
}
void Context::drawElementsInstanced(PrimitiveMode mode,
GLsizei count,
DrawElementsType type,
const void *indices,
GLsizei instances)
{
// No-op if count draws no primitives for given mode
if (noopDrawInstanced(mode, count, instances))
{
return;
}
ANGLE_CONTEXT_TRY(prepareForDraw(mode));
ANGLE_CONTEXT_TRY(
mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
}
void Context::drawRangeElements(PrimitiveMode mode,
GLuint start,
GLuint end,
GLsizei count,
DrawElementsType type,
const void *indices)
{
// No-op if count draws no primitives for given mode
if (noopDraw(mode, count))
{
return;
}
ANGLE_CONTEXT_TRY(prepareForDraw(mode));
ANGLE_CONTEXT_TRY(
mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
}
void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
{
ANGLE_CONTEXT_TRY(prepareForDraw(mode));
ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
}
void Context::drawElementsIndirect(PrimitiveMode mode, DrawElementsType type, const void *indirect)
{
ANGLE_CONTEXT_TRY(prepareForDraw(mode));
ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
}
void Context::flush()
{
ANGLE_CONTEXT_TRY(mImplementation->flush(this));
}
void Context::finish()
{
ANGLE_CONTEXT_TRY(mImplementation->finish(this));
}
void Context::insertEventMarker(GLsizei length, const char *marker)
{
ASSERT(mImplementation);
mImplementation->insertEventMarker(length, marker);
}
void Context::pushGroupMarker(GLsizei length, const char *marker)
{
ASSERT(mImplementation);
if (marker == nullptr)
{
// From the EXT_debug_marker spec,
// "If <marker> is null then an empty string is pushed on the stack."
mImplementation->pushGroupMarker(length, "");
}
else
{
mImplementation->pushGroupMarker(length, marker);
}
}
void Context::popGroupMarker()
{
ASSERT(mImplementation);
mImplementation->popGroupMarker();
}
void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
{
Program *programObject = getProgramResolveLink(program);
ASSERT(programObject);
programObject->bindUniformLocation(location, name);
}
void Context::coverageModulation(GLenum components)
{
mState.setCoverageModulation(components);
}
void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
{
mState.loadPathRenderingMatrix(matrixMode, matrix);
}
void Context::matrixLoadIdentity(GLenum matrixMode)
{
GLfloat I[16];
angle::Matrix<GLfloat>::setToIdentity(I);
mState.loadPathRenderingMatrix(matrixMode, I);
}
void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
{
const auto *pathObj = mState.mPathManager->getPath(path);
if (!pathObj)
return;
ANGLE_CONTEXT_TRY(syncStateForPathOperation());
mImplementation->stencilFillPath(pathObj, fillMode, mask);
}
void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
{
const auto *pathObj = mState.mPathManager->getPath(path);
if (!pathObj)
return;
ANGLE_CONTEXT_TRY(syncStateForPathOperation());
mImplementation->stencilStrokePath(pathObj, reference, mask);
}
void Context::coverFillPath(GLuint path, GLenum coverMode)
{
const auto *pathObj = mState.mPathManager->getPath(path);
if (!pathObj)
return;
ANGLE_CONTEXT_TRY(syncStateForPathOperation());
mImplementation->coverFillPath(pathObj, coverMode);
}
void Context::coverStrokePath(GLuint path, GLenum coverMode)
{
const auto *pathObj = mState.mPathManager->getPath(path);
if (!pathObj)
return;
ANGLE_CONTEXT_TRY(syncStateForPathOperation());
mImplementation->coverStrokePath(pathObj, coverMode);
}
void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
{
const auto *pathObj = mState.mPathManager->getPath(path);
if (!pathObj)
return;
ANGLE_CONTEXT_TRY(syncStateForPathOperation());
mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
}
void Context::stencilThenCoverStrokePath(GLuint path,
GLint reference,
GLuint mask,
GLenum coverMode)
{
const auto *pathObj = mState.mPathManager->getPath(path);
if (!pathObj)
return;
ANGLE_CONTEXT_TRY(syncStateForPathOperation());
mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
}
void Context::coverFillPathInstanced(GLsizei numPaths,
GLenum pathNameType,
const void *paths,
GLuint pathBase,
GLenum coverMode,
GLenum transformType,
const GLfloat *transformValues)
{
const auto &pathObjects =
GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
ANGLE_CONTEXT_TRY(syncStateForPathOperation());
mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
}
void Context::coverStrokePathInstanced(GLsizei numPaths,
GLenum pathNameType,
const void *paths,
GLuint pathBase,
GLenum coverMode,
GLenum transformType,
const GLfloat *transformValues)
{
const auto &pathObjects =
GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
// TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
ANGLE_CONTEXT_TRY(syncStateForPathOperation());
mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
transformValues);
}
void Context::stencilFillPathInstanced(GLsizei numPaths,
GLenum pathNameType,
const void *paths,
GLuint pathBase,
GLenum fillMode,
GLuint mask,
GLenum transformType,
const GLfloat *transformValues)
{
const auto &pathObjects =
GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
// TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
ANGLE_CONTEXT_TRY(syncStateForPathOperation());
mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
transformValues);
}
void Context::stencilStrokePathInstanced(GLsizei numPaths,
GLenum pathNameType,
const void *paths,
GLuint pathBase,
GLint reference,
GLuint mask,
GLenum transformType,
const GLfloat *transformValues)
{
const auto &pathObjects =
GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
ANGLE_CONTEXT_TRY(syncStateForPathOperation());
mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
transformValues);
}
void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
GLenum pathNameType,
const void *paths,
GLuint pathBase,
GLenum fillMode,
GLuint mask,
GLenum coverMode,
GLenum transformType,
const GLfloat *transformValues)
{
const auto &pathObjects =
GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
ANGLE_CONTEXT_TRY(syncStateForPathOperation());
mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
transformType, transformValues);
}
void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
GLenum pathNameType,
const void *paths,
GLuint pathBase,
GLint reference,
GLuint mask,
GLenum coverMode,
GLenum transformType,
const GLfloat *transformValues)
{
const auto &pathObjects =
GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
ANGLE_CONTEXT_TRY(syncStateForPathOperation());
mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
transformType, transformValues);
}
void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
{
auto *programObject = getProgramResolveLink(program);
programObject->bindFragmentInputLocation(location, name);
}
void Context::programPathFragmentInputGen(GLuint program,
GLint location,
GLenum genMode,
GLint components,
const GLfloat *coeffs)
{
auto *programObject = getProgramResolveLink(program);
programObject->pathFragmentInputGen(location, genMode, components, coeffs);
}
GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
{
const Program *programObject = getProgramResolveLink(program);
return QueryProgramResourceIndex(programObject, programInterface, name);
}
void Context::getProgramResourceName(GLuint program,
GLenum programInterface,
GLuint index,
GLsizei bufSize,
GLsizei *length,
GLchar *name)
{
const Program *programObject = getProgramResolveLink(program);
QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
}
GLint Context::getProgramResourceLocation(GLuint program,
GLenum programInterface,
const GLchar *name)
{
const Program *programObject = getProgramResolveLink(program);
return QueryProgramResourceLocation(programObject, programInterface, name);
}
void Context::getProgramResourceiv(GLuint program,
GLenum programInterface,
GLuint index,
GLsizei propCount,
const GLenum *props,
GLsizei bufSize,
GLsizei *length,
GLint *params)
{
const Program *programObject = getProgramResolveLink(program);
QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
length, params);
}
void Context::getProgramInterfaceiv(GLuint program,
GLenum programInterface,
GLenum pname,
GLint *params)
{
const Program *programObject = getProgramResolveLink(program);
QueryProgramInterfaceiv(programObject, programInterface, pname, params);
}
void Context::getProgramInterfaceivRobust(GLuint program,
GLenum programInterface,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLint *params)
{
UNIMPLEMENTED();
}
void Context::handleError(GLenum errorCode,
const char *message,
const char *file,
const char *function,
unsigned int line)
{
mErrors.handleError(errorCode, message, file, function, line);
}
void Context::validationError(GLenum errorCode, const char *message)
{
mErrors.validationError(errorCode, message);
}
// Get one of the recorded errors and clear its flag, if any.
// [OpenGL ES 2.0.24] section 2.5 page 13.
GLenum Context::getError()
{
if (mErrors.empty())
{
return GL_NO_ERROR;
}
else
{
return mErrors.popError();
}
}
// NOTE: this function should not assume that this context is current!
void Context::markContextLost()
{
if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
{
mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
mContextLostForced = true;
}
mContextLost = true;
}
GLenum Context::getGraphicsResetStatus()
{
// Even if the application doesn't want to know about resets, we want to know
// as it will allow us to skip all the calls.
if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
{
if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
{
mContextLost = true;
}
// EXT_robustness, section 2.6: If the reset notification behavior is
// NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
// reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
return GL_NO_ERROR;
}
// The GL_EXT_robustness spec says that if a reset is encountered, a reset
// status should be returned at least once, and GL_NO_ERROR should be returned
// once the device has finished resetting.
if (!mContextLost)
{
ASSERT(mResetStatus == GL_NO_ERROR);
mResetStatus = mImplementation->getResetStatus();
if (mResetStatus != GL_NO_ERROR)
{
mContextLost = true;
}
}
else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
{
// If markContextLost was used to mark the context lost then
// assume that is not recoverable, and continue to report the
// lost reset status for the lifetime of this context.
mResetStatus = mImplementation->getResetStatus();
}
return mResetStatus;
}
bool Context::isResetNotificationEnabled()
{
return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
}
const egl::Config *Context::getConfig() const
{
return mConfig;
}
EGLenum Context::getClientType() const
{
return mClientType;
}
EGLenum Context::getRenderBuffer() const
{
const Framebuffer *framebuffer = mState.mFramebufferManager->getFramebuffer(0);
if (framebuffer == nullptr)
{
return EGL_NONE;
}
const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
ASSERT(backAttachment != nullptr);
return backAttachment->getSurface()->getRenderBuffer();
}
VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
{
// Only called after a prior call to Gen.
VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
if (!vertexArray)
{
vertexArray =
new VertexArray(mImplementation.get(), vertexArrayHandle,
mState.mCaps.maxVertexAttributes, mState.mCaps.maxVertexAttribBindings);
mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
}
return vertexArray;
}
TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
{
// Only called after a prior call to Gen.
TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
if (!transformFeedback)
{
transformFeedback =
new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mState.mCaps);