michael@0: /* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */ 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 GLUploadHelpers_h_ michael@0: #define GLUploadHelpers_h_ michael@0: michael@0: #include "GLDefs.h" michael@0: #include "mozilla/gfx/Types.h" michael@0: #include "nsPoint.h" michael@0: michael@0: class nsIntRegion; michael@0: michael@0: namespace mozilla { michael@0: michael@0: namespace gfx { michael@0: class DataSourceSurface; michael@0: } michael@0: michael@0: namespace gl { michael@0: michael@0: class GLContext; michael@0: michael@0: /** michael@0: * Creates a RGB/RGBA texture (or uses one provided) and uploads the surface michael@0: * contents to it within aSrcRect. michael@0: * michael@0: * aSrcRect.x/y will be uploaded to 0/0 in the texture, and the size michael@0: * of the texture with be aSrcRect.width/height. michael@0: * michael@0: * If an existing texture is passed through aTexture, it is assumed it michael@0: * has already been initialised with glTexImage2D (or this function), michael@0: * and that its size is equal to or greater than aSrcRect + aDstPoint. michael@0: * You can alternatively set the overwrite flag to true and have a new michael@0: * texture memory block allocated. michael@0: * michael@0: * The aDstPoint parameter is ignored if no texture was provided michael@0: * or aOverwrite is true. michael@0: * michael@0: * \param aData Image data to upload. michael@0: * \param aDstRegion Region of texture to upload to. michael@0: * \param aTexture Texture to use, or 0 to have one created for you. michael@0: * \param aOverwrite Over an existing texture with a new one. michael@0: * \param aSrcPoint Offset into aSrc where the region's bound's michael@0: * TopLeft() sits. michael@0: * \param aPixelBuffer Pass true to upload texture data with an michael@0: * offset from the base data (generally for pixel buffer objects), michael@0: * otherwise textures are upload with an absolute pointer to the data. michael@0: * \param aTextureUnit, the texture unit used temporarily to upload the michael@0: * surface. This testure may be overridden, clients should not rely on michael@0: * the contents of this texture after this call or even on this michael@0: * texture unit being active. michael@0: * \return Surface format of this texture. michael@0: */ michael@0: gfx::SurfaceFormat michael@0: UploadImageDataToTexture(GLContext* gl, michael@0: unsigned char* aData, michael@0: int32_t aStride, michael@0: gfx::SurfaceFormat aFormat, michael@0: const nsIntRegion& aDstRegion, michael@0: GLuint& aTexture, michael@0: bool aOverwrite = false, michael@0: bool aPixelBuffer = false, michael@0: GLenum aTextureUnit = LOCAL_GL_TEXTURE0, michael@0: GLenum aTextureTarget = LOCAL_GL_TEXTURE_2D); michael@0: michael@0: /** michael@0: * Convenience wrapper around UploadImageDataToTexture for gfx::DataSourceSurface's. michael@0: */ michael@0: gfx::SurfaceFormat michael@0: UploadSurfaceToTexture(GLContext* gl, michael@0: gfx::DataSourceSurface *aSurface, michael@0: const nsIntRegion& aDstRegion, michael@0: GLuint& aTexture, michael@0: bool aOverwrite = false, michael@0: const nsIntPoint& aSrcPoint = nsIntPoint(0, 0), michael@0: bool aPixelBuffer = false, michael@0: GLenum aTextureUnit = LOCAL_GL_TEXTURE0, michael@0: GLenum aTextureTarget = LOCAL_GL_TEXTURE_2D); michael@0: michael@0: bool CanUploadSubTextures(GLContext* gl); michael@0: bool CanUploadNonPowerOfTwo(GLContext* gl); michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif