diff options
Diffstat (limited to 'src/3rdparty/angle/src/libGLESv2/Context.h')
-rw-r--r-- | src/3rdparty/angle/src/libGLESv2/Context.h | 478 |
1 files changed, 157 insertions, 321 deletions
diff --git a/src/3rdparty/angle/src/libGLESv2/Context.h b/src/3rdparty/angle/src/libGLESv2/Context.h index 3dc95e3b95..6c93c74e79 100644 --- a/src/3rdparty/angle/src/libGLESv2/Context.h +++ b/src/3rdparty/angle/src/libGLESv2/Context.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. +// 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. // @@ -10,26 +10,22 @@ #ifndef LIBGLESV2_CONTEXT_H_ #define LIBGLESV2_CONTEXT_H_ -#define GL_APICALL -#include <GLES2/gl2.h> -#include <GLES2/gl2ext.h> -#define EGLAPI -#include <EGL/egl.h> +#include "angle_gl.h" #include <string> -#include <map> #include <set> -#ifdef _MSC_VER -#include <hash_map> -#else +#include <map> #include <unordered_map> -#endif +#include <array> #include "common/angleutils.h" #include "common/RefCountObject.h" +#include "libGLESv2/Caps.h" #include "libGLESv2/HandleAllocator.h" #include "libGLESv2/angletypes.h" #include "libGLESv2/Constants.h" +#include "libGLESv2/VertexAttribute.h" +#include "libGLESv2/State.h" namespace rx { @@ -49,6 +45,8 @@ class ProgramBinary; class Texture; class Texture2D; class TextureCubeMap; +class Texture3D; +class Texture2DArray; class Framebuffer; class Renderbuffer; class RenderbufferStorage; @@ -56,222 +54,28 @@ class Colorbuffer; class Depthbuffer; class Stencilbuffer; class DepthStencilbuffer; -class Fence; +class FenceNV; +class FenceSync; class Query; class ResourceManager; class Buffer; - -enum QueryType -{ - QUERY_ANY_SAMPLES_PASSED, - QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE, - - QUERY_TYPE_COUNT -}; - -// Helper structure describing a single vertex attribute -class VertexAttribute -{ - public: - VertexAttribute() : mType(GL_FLOAT), mSize(4), mNormalized(false), mStride(0), mPointer(NULL), mArrayEnabled(false), mDivisor(0) - { - mCurrentValue[0] = 0.0f; - mCurrentValue[1] = 0.0f; - mCurrentValue[2] = 0.0f; - mCurrentValue[3] = 1.0f; - } - - int typeSize() const - { - switch (mType) - { - case GL_BYTE: return mSize * sizeof(GLbyte); - case GL_UNSIGNED_BYTE: return mSize * sizeof(GLubyte); - case GL_SHORT: return mSize * sizeof(GLshort); - case GL_UNSIGNED_SHORT: return mSize * sizeof(GLushort); - case GL_FIXED: return mSize * sizeof(GLfixed); - case GL_FLOAT: return mSize * sizeof(GLfloat); - default: UNREACHABLE(); return mSize * sizeof(GLfloat); - } - } - - GLsizei stride() const - { - return mStride ? mStride : typeSize(); - } - - // From glVertexAttribPointer - GLenum mType; - GLint mSize; - bool mNormalized; - GLsizei mStride; // 0 means natural stride - - union - { - const void *mPointer; - intptr_t mOffset; - }; - - BindingPointer<Buffer> mBoundBuffer; // Captured when glVertexAttribPointer is called. - - bool mArrayEnabled; // From glEnable/DisableVertexAttribArray - float mCurrentValue[4]; // From glVertexAttrib - unsigned int mDivisor; -}; - -// Helper structure to store all raw state -struct State -{ - Color colorClearValue; - GLclampf depthClearValue; - int stencilClearValue; - - RasterizerState rasterizer; - bool scissorTest; - Rectangle scissor; - - BlendState blend; - Color blendColor; - bool sampleCoverage; - GLclampf sampleCoverageValue; - bool sampleCoverageInvert; - - DepthStencilState depthStencil; - GLint stencilRef; - GLint stencilBackRef; - - GLfloat lineWidth; - - GLenum generateMipmapHint; - GLenum fragmentShaderDerivativeHint; - - Rectangle viewport; - float zNear; - float zFar; - - unsigned int activeSampler; // Active texture unit selector - GL_TEXTURE0 - BindingPointer<Buffer> arrayBuffer; - BindingPointer<Buffer> elementArrayBuffer; - GLuint readFramebuffer; - GLuint drawFramebuffer; - BindingPointer<Renderbuffer> renderbuffer; - GLuint currentProgram; - - VertexAttribute vertexAttribute[MAX_VERTEX_ATTRIBS]; - BindingPointer<Texture> samplerTexture[TEXTURE_TYPE_COUNT][IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS]; - BindingPointer<Query> activeQuery[QUERY_TYPE_COUNT]; - - GLint unpackAlignment; - GLint packAlignment; - bool packReverseRowOrder; -}; +struct VertexAttribute; +class VertexArray; +class Sampler; +class TransformFeedback; class Context { public: - Context(const gl::Context *shareContext, rx::Renderer *renderer, bool notifyResets, bool robustAccess); + Context(int clientVersion, const gl::Context *shareContext, rx::Renderer *renderer, bool notifyResets, bool robustAccess); - ~Context(); + virtual ~Context(); void makeCurrent(egl::Surface *surface); virtual void markContextLost(); bool isContextLost(); - // State manipulation - void setClearColor(float red, float green, float blue, float alpha); - - void setClearDepth(float depth); - - void setClearStencil(int stencil); - - void setCullFace(bool enabled); - bool isCullFaceEnabled() const; - - void setCullMode(GLenum mode); - - void setFrontFace(GLenum front); - - void setDepthTest(bool enabled); - bool isDepthTestEnabled() const; - - void setDepthFunc(GLenum depthFunc); - - void setDepthRange(float zNear, float zFar); - - void setBlend(bool enabled); - bool isBlendEnabled() const; - - void setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha); - void setBlendColor(float red, float green, float blue, float alpha); - void setBlendEquation(GLenum rgbEquation, GLenum alphaEquation); - - void setStencilTest(bool enabled); - bool isStencilTestEnabled() const; - - void setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask); - void setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask); - void setStencilWritemask(GLuint stencilWritemask); - void setStencilBackWritemask(GLuint stencilBackWritemask); - void setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass); - void setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass); - - void setPolygonOffsetFill(bool enabled); - bool isPolygonOffsetFillEnabled() const; - - void setPolygonOffsetParams(GLfloat factor, GLfloat units); - - void setSampleAlphaToCoverage(bool enabled); - bool isSampleAlphaToCoverageEnabled() const; - - void setSampleCoverage(bool enabled); - bool isSampleCoverageEnabled() const; - - void setSampleCoverageParams(GLclampf value, bool invert); - - void setScissorTest(bool enabled); - bool isScissorTestEnabled() const; - - void setDither(bool enabled); - bool isDitherEnabled() const; - - void setLineWidth(GLfloat width); - - void setGenerateMipmapHint(GLenum hint); - void setFragmentShaderDerivativeHint(GLenum hint); - - void setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height); - - void setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height); - - void setColorMask(bool red, bool green, bool blue, bool alpha); - void setDepthMask(bool mask); - - void setActiveSampler(unsigned int active); - - GLuint getReadFramebufferHandle() const; - GLuint getDrawFramebufferHandle() const; - GLuint getRenderbufferHandle() const; - - GLuint getArrayBufferHandle() const; - - GLuint getActiveQuery(GLenum target) const; - - void setEnableVertexAttribArray(unsigned int attribNum, bool enabled); - const VertexAttribute &getVertexAttribState(unsigned int attribNum); - void setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type, - bool normalized, GLsizei stride, const void *pointer); - const void *getVertexAttribPointer(unsigned int attribNum) const; - - void setUnpackAlignment(GLint alignment); - GLint getUnpackAlignment() const; - - void setPackAlignment(GLint alignment); - GLint getPackAlignment() const; - - void setPackReverseRowOrder(bool reverseRowOrder); - bool getPackReverseRowOrder() const; - // These create and destroy methods are merely pass-throughs to // ResourceManager, which owns these object types GLuint createBuffer(); @@ -279,35 +83,58 @@ class Context GLuint createProgram(); GLuint createTexture(); GLuint createRenderbuffer(); + GLuint createSampler(); + GLuint createTransformFeedback(); + GLsync createFenceSync(GLenum condition); void deleteBuffer(GLuint buffer); void deleteShader(GLuint shader); void deleteProgram(GLuint program); void deleteTexture(GLuint texture); void deleteRenderbuffer(GLuint renderbuffer); + void deleteSampler(GLuint sampler); + void deleteTransformFeedback(GLuint transformFeedback); + void deleteFenceSync(GLsync fenceSync); // Framebuffers are owned by the Context, so these methods do not pass through GLuint createFramebuffer(); void deleteFramebuffer(GLuint framebuffer); - // Fences are owned by the Context. - GLuint createFence(); - void deleteFence(GLuint fence); + // NV Fences are owned by the Context. + GLuint createFenceNV(); + void deleteFenceNV(GLuint fence); // Queries are owned by the Context; GLuint createQuery(); void deleteQuery(GLuint query); + // Vertex arrays are owned by the Context + GLuint createVertexArray(); + void deleteVertexArray(GLuint vertexArray); + void bindArrayBuffer(GLuint buffer); void bindElementArrayBuffer(GLuint buffer); void bindTexture2D(GLuint texture); void bindTextureCubeMap(GLuint texture); + void bindTexture3D(GLuint texture); + void bindTexture2DArray(GLuint texture); void bindReadFramebuffer(GLuint framebuffer); void bindDrawFramebuffer(GLuint framebuffer); void bindRenderbuffer(GLuint renderbuffer); + void bindVertexArray(GLuint vertexArray); + void bindSampler(GLuint textureUnit, GLuint sampler); + void bindGenericUniformBuffer(GLuint buffer); + void bindIndexedUniformBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size); + void bindGenericTransformFeedbackBuffer(GLuint buffer); + void bindIndexedTransformFeedbackBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size); + void bindCopyReadBuffer(GLuint buffer); + void bindCopyWriteBuffer(GLuint buffer); + void bindPixelPackBuffer(GLuint buffer); + void bindPixelUnpackBuffer(GLuint buffer); void useProgram(GLuint program); void linkProgram(GLuint program); void setProgramBinary(GLuint program, const void *binary, GLint length); + void bindTransformFeedback(GLuint transformFeedback); void beginQuery(GLenum target, GLuint query); void endQuery(GLenum target); @@ -316,35 +143,54 @@ class Context void setRenderbufferStorage(GLsizei width, GLsizei height, GLenum internalformat, GLsizei samples); - void setVertexAttrib(GLuint index, const GLfloat *values); void setVertexAttribDivisor(GLuint index, GLuint divisor); + void samplerParameteri(GLuint sampler, GLenum pname, GLint param); + void samplerParameterf(GLuint sampler, GLenum pname, GLfloat param); + GLint getSamplerParameteri(GLuint sampler, GLenum pname); + GLfloat getSamplerParameterf(GLuint sampler, GLenum pname); + Buffer *getBuffer(GLuint handle); - Fence *getFence(GLuint handle); - Shader *getShader(GLuint handle); - Program *getProgram(GLuint handle); - Texture *getTexture(GLuint handle); - Framebuffer *getFramebuffer(GLuint handle); + FenceNV *getFenceNV(GLuint handle); + FenceSync *getFenceSync(GLsync handle) const; + Shader *getShader(GLuint handle) const; + Program *getProgram(GLuint handle) const; + Texture *getTexture(GLuint handle) const; + Framebuffer *getFramebuffer(GLuint handle) const; Renderbuffer *getRenderbuffer(GLuint handle); + VertexArray *getVertexArray(GLuint handle) const; + Sampler *getSampler(GLuint handle) const; Query *getQuery(GLuint handle, bool create, GLenum type); + TransformFeedback *getTransformFeedback(GLuint handle) const; + + Texture *getTargetTexture(GLenum target) const; + Texture2D *getTexture2D() const; + TextureCubeMap *getTextureCubeMap() const; + Texture3D *getTexture3D() const; + Texture2DArray *getTexture2DArray() const; + + Texture *getSamplerTexture(unsigned int sampler, TextureType type) const; + + bool isSampler(GLuint samplerName) const; - Buffer *getArrayBuffer(); - Buffer *getElementArrayBuffer(); - ProgramBinary *getCurrentProgramBinary(); - Texture2D *getTexture2D(); - TextureCubeMap *getTextureCubeMap(); - Texture *getSamplerTexture(unsigned int sampler, TextureType type); - Framebuffer *getReadFramebuffer(); - Framebuffer *getDrawFramebuffer(); + void getBooleanv(GLenum pname, GLboolean *params); + void getFloatv(GLenum pname, GLfloat *params); + void getIntegerv(GLenum pname, GLint *params); + void getInteger64v(GLenum pname, GLint64 *params); - bool getFloatv(GLenum pname, GLfloat *params); - bool getIntegerv(GLenum pname, GLint *params); - bool getBooleanv(GLenum pname, GLboolean *params); + bool getIndexedIntegerv(GLenum target, GLuint index, GLint *data); + bool getIndexedInteger64v(GLenum target, GLuint index, GLint64 *data); bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams); + bool getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams); - void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei *bufSize, void* pixels); void clear(GLbitfield mask); + void clearBufferfv(GLenum buffer, int drawbuffer, const float *values); + void clearBufferuiv(GLenum buffer, int drawbuffer, const unsigned int *values); + void clearBufferiv(GLenum buffer, int drawbuffer, const int *values); + void clearBufferfi(GLenum buffer, int drawbuffer, float depth, int stencil); + + void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei *bufSize, void* pixels); void drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instances); void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instances); void sync(bool block); // flush/finish @@ -359,101 +205,120 @@ class Context GLenum getResetStatus(); virtual bool isResetNotificationEnabled(); + virtual int getClientVersion() const; + + const Caps &getCaps() const; + const TextureCapsMap &getTextureCaps() const; + const Extensions &getExtensions() const; + int getMajorShaderModel() const; - float getMaximumPointSize() const; unsigned int getMaximumCombinedTextureImageUnits() const; - int getMaximumRenderbufferDimension() const; - int getMaximumTextureDimension() const; - int getMaximumCubeTextureDimension() const; - int getMaximumTextureLevel() const; - unsigned int getMaximumRenderTargets() const; + unsigned int getMaximumCombinedUniformBufferBindings() const; GLsizei getMaxSupportedSamples() const; - const char *getExtensionString() const; - const char *getRendererString() const; - bool supportsEventQueries() const; - bool supportsOcclusionQueries() const; - bool supportsBGRATextures() const; - bool supportsDXT1Textures() const; - bool supportsDXT3Textures() const; - bool supportsDXT5Textures() const; - bool supportsFloat32Textures() const; - bool supportsFloat32LinearFilter() const; - bool supportsFloat32RenderableTextures() const; - bool supportsFloat16Textures() const; - bool supportsFloat16LinearFilter() const; - bool supportsFloat16RenderableTextures() const; - bool supportsLuminanceTextures() const; - bool supportsLuminanceAlphaTextures() const; - bool supportsDepthTextures() const; - bool supports32bitIndices() const; - bool supportsNonPower2Texture() const; - bool supportsInstancing() const; - bool supportsTextureFilterAnisotropy() const; - - bool getCurrentReadFormatType(GLenum *format, GLenum *type); - - float getTextureMaxAnisotropy() const; - - void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, - GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, - GLbitfield mask); + GLsizei getMaxSupportedFormatSamples(GLenum internalFormat) const; + GLsizei getNumSampleCounts(GLenum internalFormat) const; + void getSampleCounts(GLenum internalFormat, GLsizei bufSize, GLint *params) const; + unsigned int getMaxTransformFeedbackBufferBindings() const; + GLintptr getUniformBufferOffsetAlignment() const; + const std::string &getRendererString() const; + + const std::string &getExtensionString() const; + const std::string &getExtensionString(size_t idx) const; + size_t getExtensionStringCount() const; + + void getCurrentReadFormatType(GLenum *internalFormat, GLenum *format, GLenum *type); + + void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, + GLbitfield mask, GLenum filter); + + void invalidateFrameBuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, + GLint x, GLint y, GLsizei width, GLsizei height); + + bool hasMappedBuffer(GLenum target) const; rx::Renderer *getRenderer() { return mRenderer; } + State &getState() { return mState; } + const State &getState() const { return mState; } + private: DISALLOW_COPY_AND_ASSIGN(Context); + // TODO: std::array may become unavailable using older versions of GCC + typedef std::array<unsigned int, IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS> FramebufferTextureSerialArray; + bool applyRenderTarget(GLenum drawMode, bool ignoreViewport); void applyState(GLenum drawMode); - void applyShaders(); - void applyTextures(); - void applyTextures(SamplerType type); + void applyShaders(ProgramBinary *programBinary, bool transformFeedbackActive); + void applyTextures(SamplerType shaderType, Texture *textures[], TextureType *textureTypes, SamplerState *samplers, + size_t textureCount, const FramebufferTextureSerialArray& framebufferSerials, + size_t framebufferSerialCount); + bool applyUniformBuffers(); + bool applyTransformFeedbackBuffers(); + void markTransformFeedbackUsage(); void detachBuffer(GLuint buffer); void detachTexture(GLuint texture); void detachFramebuffer(GLuint framebuffer); void detachRenderbuffer(GLuint renderbuffer); + void detachVertexArray(GLuint vertexArray); + void detachTransformFeedback(GLuint transformFeedback); + void detachSampler(GLuint sampler); + void generateSwizzles(Texture *textures[], size_t count); + size_t getCurrentTexturesAndSamplerStates(ProgramBinary *programBinary, SamplerType type, Texture **outTextures, + TextureType *outTextureTypes, SamplerState *outSamplers); Texture *getIncompleteTexture(TextureType type); bool skipDraw(GLenum drawMode); - void initExtensionString(); void initRendererString(); + void initExtensionStrings(); - typedef std::set<unsigned> FramebufferTextureSerialSet; - FramebufferTextureSerialSet getBoundFramebufferTextureSerials(); + size_t getBoundFramebufferTextureSerials(FramebufferTextureSerialArray *outSerialArray); - rx::Renderer *const mRenderer; + void initCaps(GLuint clientVersion); + // Caps to use for validation + Caps mCaps; + TextureCapsMap mTextureCaps; + Extensions mExtensions; + + rx::Renderer *const mRenderer; State mState; + int mClientVersion; + BindingPointer<Texture2D> mTexture2DZero; BindingPointer<TextureCubeMap> mTextureCubeMapZero; + BindingPointer<Texture3D> mTexture3DZero; + BindingPointer<Texture2DArray> mTexture2DArrayZero; -#ifndef HASH_MAP -# ifdef _MSC_VER -# define HASH_MAP stdext::hash_map -# else -# define HASH_MAP std::unordered_map -# endif -#endif - - typedef HASH_MAP<GLuint, Framebuffer*> FramebufferMap; + typedef std::unordered_map<GLuint, Framebuffer*> FramebufferMap; FramebufferMap mFramebufferMap; HandleAllocator mFramebufferHandleAllocator; - typedef HASH_MAP<GLuint, Fence*> FenceMap; - FenceMap mFenceMap; - HandleAllocator mFenceHandleAllocator; + typedef std::unordered_map<GLuint, FenceNV*> FenceNVMap; + FenceNVMap mFenceNVMap; + HandleAllocator mFenceNVHandleAllocator; - typedef HASH_MAP<GLuint, Query*> QueryMap; + typedef std::unordered_map<GLuint, Query*> QueryMap; QueryMap mQueryMap; HandleAllocator mQueryHandleAllocator; - const char *mExtensionString; - const char *mRendererString; - + typedef std::unordered_map<GLuint, VertexArray*> VertexArrayMap; + VertexArrayMap mVertexArrayMap; + HandleAllocator mVertexArrayHandleAllocator; + + BindingPointer<TransformFeedback> mTransformFeedbackZero; + typedef std::unordered_map<GLuint, TransformFeedback*> TransformFeedbackMap; + TransformFeedbackMap mTransformFeedbackMap; + HandleAllocator mTransformFeedbackAllocator; + + std::string mRendererString; + std::string mExtensionString; + std::vector<std::string> mExtensionStrings; + BindingPointer<Texture> mIncompleteTextures[TEXTURE_TYPE_COUNT]; // Recorded errors @@ -470,37 +335,8 @@ class Context GLenum mResetStrategy; bool mRobustAccess; - BindingPointer<ProgramBinary> mCurrentProgramBinary; - Framebuffer *mBoundDrawFramebuffer; - int mMajorShaderModel; - float mMaximumPointSize; bool mSupportsVertexTexture; - bool mSupportsNonPower2Texture; - bool mSupportsInstancing; - int mMaxViewportDimension; - int mMaxRenderbufferDimension; - int mMaxTextureDimension; - int mMaxCubeTextureDimension; - int mMaxTextureLevel; - float mMaxTextureAnisotropy; - bool mSupportsEventQueries; - bool mSupportsOcclusionQueries; - bool mSupportsBGRATextures; - bool mSupportsDXT1Textures; - bool mSupportsDXT3Textures; - bool mSupportsDXT5Textures; - bool mSupportsFloat32Textures; - bool mSupportsFloat32LinearFilter; - bool mSupportsFloat32RenderableTextures; - bool mSupportsFloat16Textures; - bool mSupportsFloat16LinearFilter; - bool mSupportsFloat16RenderableTextures; - bool mSupportsLuminanceTextures; - bool mSupportsLuminanceAlphaTextures; - bool mSupportsDepthTextures; - bool mSupports32bitIndices; - bool mSupportsTextureFilterAnisotropy; int mNumCompressedTextureFormats; ResourceManager *mResourceManager; |