michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim: set ts=8 sts=4 et sw=4 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef GLBLITHELPER_H_ michael@0: #define GLBLITHELPER_H_ michael@0: michael@0: #include "GLContextTypes.h" michael@0: #include "GLConsts.h" michael@0: #include "nsSize.h" michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/gfx/Point.h" michael@0: michael@0: namespace mozilla { michael@0: namespace gl { michael@0: michael@0: class GLContext; michael@0: michael@0: /** michael@0: * Helper function that creates a 2D texture aSize.width x aSize.height with michael@0: * storage type specified by aFormats. Returns GL texture object id. michael@0: * michael@0: * See mozilla::gl::CreateTexture. michael@0: */ michael@0: GLuint CreateTextureForOffscreen(GLContext* aGL, const GLFormats& aFormats, michael@0: const gfx::IntSize& aSize); michael@0: michael@0: /** michael@0: * Helper function that creates a 2D texture aSize.width x aSize.height with michael@0: * storage type aInternalFormat. Returns GL texture object id. michael@0: * michael@0: * Initialize textyre parameters to: michael@0: * GL_TEXTURE_MIN_FILTER = GL_LINEAR michael@0: * GL_TEXTURE_MAG_FILTER = GL_LINEAR michael@0: * GL_TEXTURE_WRAP_S = GL_CLAMP_TO_EDGE michael@0: * GL_TEXTURE_WRAP_T = GL_CLAMP_TO_EDGE michael@0: */ michael@0: GLuint CreateTexture(GLContext* aGL, GLenum aInternalFormat, GLenum aFormat, michael@0: GLenum aType, const gfx::IntSize& aSize); michael@0: michael@0: /** michael@0: * Helper function to create, potentially, multisample render buffers suitable michael@0: * for offscreen rendering. Buffers of size aSize.width x aSize.height with michael@0: * storage specified by aFormat. returns GL render buffer object id. michael@0: */ michael@0: GLuint CreateRenderbuffer(GLContext* aGL, GLenum aFormat, GLsizei aSamples, michael@0: const gfx::IntSize& aSize); michael@0: michael@0: /** michael@0: * Helper function to create, potentially, multisample render buffers suitable michael@0: * for offscreen rendering. Buffers of size aSize.width x aSize.height with michael@0: * storage specified by aFormats. GL render buffer object ids are returned via michael@0: * aColorMSRB, aDepthRB, and aStencilRB michael@0: */ michael@0: void CreateRenderbuffersForOffscreen(GLContext* aGL, const GLFormats& aFormats, michael@0: const gfx::IntSize& aSize, bool aMultisample, michael@0: GLuint* aColorMSRB, GLuint* aDepthRB, michael@0: GLuint* aStencilRB); michael@0: michael@0: michael@0: /** Buffer blitting helper */ michael@0: class GLBlitHelper MOZ_FINAL michael@0: { michael@0: // The GLContext is the sole owner of the GLBlitHelper. michael@0: GLContext* mGL; michael@0: michael@0: GLuint mTexBlit_Buffer; michael@0: GLuint mTexBlit_VertShader; michael@0: GLuint mTex2DBlit_FragShader; michael@0: GLuint mTex2DRectBlit_FragShader; michael@0: GLuint mTex2DBlit_Program; michael@0: GLuint mTex2DRectBlit_Program; michael@0: michael@0: void UseBlitProgram(); michael@0: void SetBlitFramebufferForDestTexture(GLuint aTexture); michael@0: michael@0: bool UseTexQuadProgram(GLenum target, const gfx::IntSize& srcSize); michael@0: bool InitTexQuadProgram(GLenum target = LOCAL_GL_TEXTURE_2D); michael@0: void DeleteTexBlitProgram(); michael@0: michael@0: public: michael@0: michael@0: GLBlitHelper(GLContext* gl); michael@0: ~GLBlitHelper(); michael@0: michael@0: // If you don't have |srcFormats| for the 2nd definition, michael@0: // then you'll need the framebuffer_blit extensions to use michael@0: // the first BlitFramebufferToFramebuffer. michael@0: void BlitFramebufferToFramebuffer(GLuint srcFB, GLuint destFB, michael@0: const gfx::IntSize& srcSize, michael@0: const gfx::IntSize& destSize); michael@0: void BlitFramebufferToFramebuffer(GLuint srcFB, GLuint destFB, michael@0: const gfx::IntSize& srcSize, michael@0: const gfx::IntSize& destSize, michael@0: const GLFormats& srcFormats); michael@0: void BlitTextureToFramebuffer(GLuint srcTex, GLuint destFB, michael@0: const gfx::IntSize& srcSize, michael@0: const gfx::IntSize& destSize, michael@0: GLenum srcTarget = LOCAL_GL_TEXTURE_2D); michael@0: void BlitFramebufferToTexture(GLuint srcFB, GLuint destTex, michael@0: const gfx::IntSize& srcSize, michael@0: const gfx::IntSize& destSize, michael@0: GLenum destTarget = LOCAL_GL_TEXTURE_2D); michael@0: void BlitTextureToTexture(GLuint srcTex, GLuint destTex, michael@0: const gfx::IntSize& srcSize, michael@0: const gfx::IntSize& destSize, michael@0: GLenum srcTarget = LOCAL_GL_TEXTURE_2D, michael@0: GLenum destTarget = LOCAL_GL_TEXTURE_2D); michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif // GLBLITHELPER_H_