diff options
Diffstat (limited to 'gfx/gl/GLContext.h')
-rw-r--r-- | gfx/gl/GLContext.h | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/gfx/gl/GLContext.h b/gfx/gl/GLContext.h index eea26024ae..4ee256b053 100644 --- a/gfx/gl/GLContext.h +++ b/gfx/gl/GLContext.h @@ -45,6 +45,12 @@ #include "mozilla/GenericRefCounted.h" #include "mozilla/WeakPtr.h" +template <class ElemT, class... More> +constexpr inline std::array<ElemT, 1 + sizeof...(More)> make_array( + ElemT&& arg1, More&&... more) { + return {std::forward<ElemT>(arg1), std::forward<ElemT>(more)...}; +} + #ifdef MOZ_WIDGET_ANDROID # include "mozilla/ProfilerLabels.h" #endif @@ -797,8 +803,15 @@ class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr { AFTER_GL_CALL; } + void InvalidateFramebuffer(GLenum target) { + constexpr auto ATTACHMENTS = make_array(GLenum{LOCAL_GL_COLOR_ATTACHMENT0}, + LOCAL_GL_DEPTH_STENCIL_ATTACHMENT); + fInvalidateFramebuffer(target, ATTACHMENTS.size(), ATTACHMENTS.data()); + } + void fInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments) { + if (!mSymbols.fInvalidateFramebuffer) return; BeforeGLDrawCall(); BEFORE_GL_CALL; ASSERT_SYMBOL_PRESENT(fInvalidateFramebuffer); @@ -810,6 +823,7 @@ class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr { void fInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height) { + if (!mSymbols.fInvalidateSubFramebuffer) return; BeforeGLDrawCall(); BEFORE_GL_CALL; ASSERT_SYMBOL_PRESENT(fInvalidateSubFramebuffer); @@ -825,6 +839,13 @@ class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr { AFTER_GL_CALL; } + void BindSamplerTexture(GLuint texUnitId, GLuint samplerHandle, + GLenum texTarget, GLuint texHandle) { + fBindSampler(texUnitId, samplerHandle); + fActiveTexture(LOCAL_GL_TEXTURE0 + texUnitId); + fBindTexture(texTarget, texHandle); + } + void fBlendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { BEFORE_GL_CALL; mSymbols.fBlendColor(red, green, blue, alpha); @@ -2028,7 +2049,11 @@ class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr { public: bool mElideDuplicateBindFramebuffers = false; - void fBindFramebuffer(const GLenum target, const GLuint fb) const { + // If e.g. GL_DRAW_FRAMEBUFFER isn't supported, will bind GL_FRAMEBUFFER. + void fBindFramebuffer(GLenum target, const GLuint fb) const { + if (!IsSupported(gl::GLFeature::framebuffer_blit)) { + target = LOCAL_GL_FRAMEBUFFER; + } if (mElideDuplicateBindFramebuffers) { MOZ_ASSERT(mCachedDrawFb == GetIntAs<GLuint>(LOCAL_GL_DRAW_FRAMEBUFFER_BINDING)); @@ -3861,6 +3886,30 @@ class Texture final { } }; +// - + +class Sampler final { + public: + const WeakPtr<GLContext> weakGl; + const GLuint name; + + private: + static GLuint Create(GLContext& gl) { + GLuint ret = 0; + gl.fGenSamplers(1, &ret); + return ret; + } + + public: + explicit Sampler(GLContext& gl) : weakGl(&gl), name(Create(gl)) {} + + ~Sampler() { + const RefPtr<GLContext> gl = weakGl.get(); + if (!gl || !gl->MakeCurrent()) return; + gl->fDeleteSamplers(1, &name); + } +}; + /** * Helper function that creates a 2D texture aSize.width x aSize.height with * storage type specified by aFormats. Returns GL texture object id. |