1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/gl/GLBlitHelper.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,116 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* vim: set ts=8 sts=4 et sw=4 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef GLBLITHELPER_H_ 1.11 +#define GLBLITHELPER_H_ 1.12 + 1.13 +#include "GLContextTypes.h" 1.14 +#include "GLConsts.h" 1.15 +#include "nsSize.h" 1.16 +#include "mozilla/Attributes.h" 1.17 +#include "mozilla/gfx/Point.h" 1.18 + 1.19 +namespace mozilla { 1.20 +namespace gl { 1.21 + 1.22 +class GLContext; 1.23 + 1.24 +/** 1.25 + * Helper function that creates a 2D texture aSize.width x aSize.height with 1.26 + * storage type specified by aFormats. Returns GL texture object id. 1.27 + * 1.28 + * See mozilla::gl::CreateTexture. 1.29 + */ 1.30 +GLuint CreateTextureForOffscreen(GLContext* aGL, const GLFormats& aFormats, 1.31 + const gfx::IntSize& aSize); 1.32 + 1.33 +/** 1.34 + * Helper function that creates a 2D texture aSize.width x aSize.height with 1.35 + * storage type aInternalFormat. Returns GL texture object id. 1.36 + * 1.37 + * Initialize textyre parameters to: 1.38 + * GL_TEXTURE_MIN_FILTER = GL_LINEAR 1.39 + * GL_TEXTURE_MAG_FILTER = GL_LINEAR 1.40 + * GL_TEXTURE_WRAP_S = GL_CLAMP_TO_EDGE 1.41 + * GL_TEXTURE_WRAP_T = GL_CLAMP_TO_EDGE 1.42 + */ 1.43 +GLuint CreateTexture(GLContext* aGL, GLenum aInternalFormat, GLenum aFormat, 1.44 + GLenum aType, const gfx::IntSize& aSize); 1.45 + 1.46 +/** 1.47 + * Helper function to create, potentially, multisample render buffers suitable 1.48 + * for offscreen rendering. Buffers of size aSize.width x aSize.height with 1.49 + * storage specified by aFormat. returns GL render buffer object id. 1.50 + */ 1.51 +GLuint CreateRenderbuffer(GLContext* aGL, GLenum aFormat, GLsizei aSamples, 1.52 + const gfx::IntSize& aSize); 1.53 + 1.54 +/** 1.55 + * Helper function to create, potentially, multisample render buffers suitable 1.56 + * for offscreen rendering. Buffers of size aSize.width x aSize.height with 1.57 + * storage specified by aFormats. GL render buffer object ids are returned via 1.58 + * aColorMSRB, aDepthRB, and aStencilRB 1.59 + */ 1.60 +void CreateRenderbuffersForOffscreen(GLContext* aGL, const GLFormats& aFormats, 1.61 + const gfx::IntSize& aSize, bool aMultisample, 1.62 + GLuint* aColorMSRB, GLuint* aDepthRB, 1.63 + GLuint* aStencilRB); 1.64 + 1.65 + 1.66 +/** Buffer blitting helper */ 1.67 +class GLBlitHelper MOZ_FINAL 1.68 +{ 1.69 + // The GLContext is the sole owner of the GLBlitHelper. 1.70 + GLContext* mGL; 1.71 + 1.72 + GLuint mTexBlit_Buffer; 1.73 + GLuint mTexBlit_VertShader; 1.74 + GLuint mTex2DBlit_FragShader; 1.75 + GLuint mTex2DRectBlit_FragShader; 1.76 + GLuint mTex2DBlit_Program; 1.77 + GLuint mTex2DRectBlit_Program; 1.78 + 1.79 + void UseBlitProgram(); 1.80 + void SetBlitFramebufferForDestTexture(GLuint aTexture); 1.81 + 1.82 + bool UseTexQuadProgram(GLenum target, const gfx::IntSize& srcSize); 1.83 + bool InitTexQuadProgram(GLenum target = LOCAL_GL_TEXTURE_2D); 1.84 + void DeleteTexBlitProgram(); 1.85 + 1.86 +public: 1.87 + 1.88 + GLBlitHelper(GLContext* gl); 1.89 + ~GLBlitHelper(); 1.90 + 1.91 + // If you don't have |srcFormats| for the 2nd definition, 1.92 + // then you'll need the framebuffer_blit extensions to use 1.93 + // the first BlitFramebufferToFramebuffer. 1.94 + void BlitFramebufferToFramebuffer(GLuint srcFB, GLuint destFB, 1.95 + const gfx::IntSize& srcSize, 1.96 + const gfx::IntSize& destSize); 1.97 + void BlitFramebufferToFramebuffer(GLuint srcFB, GLuint destFB, 1.98 + const gfx::IntSize& srcSize, 1.99 + const gfx::IntSize& destSize, 1.100 + const GLFormats& srcFormats); 1.101 + void BlitTextureToFramebuffer(GLuint srcTex, GLuint destFB, 1.102 + const gfx::IntSize& srcSize, 1.103 + const gfx::IntSize& destSize, 1.104 + GLenum srcTarget = LOCAL_GL_TEXTURE_2D); 1.105 + void BlitFramebufferToTexture(GLuint srcFB, GLuint destTex, 1.106 + const gfx::IntSize& srcSize, 1.107 + const gfx::IntSize& destSize, 1.108 + GLenum destTarget = LOCAL_GL_TEXTURE_2D); 1.109 + void BlitTextureToTexture(GLuint srcTex, GLuint destTex, 1.110 + const gfx::IntSize& srcSize, 1.111 + const gfx::IntSize& destSize, 1.112 + GLenum srcTarget = LOCAL_GL_TEXTURE_2D, 1.113 + GLenum destTarget = LOCAL_GL_TEXTURE_2D); 1.114 +}; 1.115 + 1.116 +} 1.117 +} 1.118 + 1.119 +#endif // GLBLITHELPER_H_