|
1 /* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef GLUploadHelpers_h_ |
|
7 #define GLUploadHelpers_h_ |
|
8 |
|
9 #include "GLDefs.h" |
|
10 #include "mozilla/gfx/Types.h" |
|
11 #include "nsPoint.h" |
|
12 |
|
13 class nsIntRegion; |
|
14 |
|
15 namespace mozilla { |
|
16 |
|
17 namespace gfx { |
|
18 class DataSourceSurface; |
|
19 } |
|
20 |
|
21 namespace gl { |
|
22 |
|
23 class GLContext; |
|
24 |
|
25 /** |
|
26 * Creates a RGB/RGBA texture (or uses one provided) and uploads the surface |
|
27 * contents to it within aSrcRect. |
|
28 * |
|
29 * aSrcRect.x/y will be uploaded to 0/0 in the texture, and the size |
|
30 * of the texture with be aSrcRect.width/height. |
|
31 * |
|
32 * If an existing texture is passed through aTexture, it is assumed it |
|
33 * has already been initialised with glTexImage2D (or this function), |
|
34 * and that its size is equal to or greater than aSrcRect + aDstPoint. |
|
35 * You can alternatively set the overwrite flag to true and have a new |
|
36 * texture memory block allocated. |
|
37 * |
|
38 * The aDstPoint parameter is ignored if no texture was provided |
|
39 * or aOverwrite is true. |
|
40 * |
|
41 * \param aData Image data to upload. |
|
42 * \param aDstRegion Region of texture to upload to. |
|
43 * \param aTexture Texture to use, or 0 to have one created for you. |
|
44 * \param aOverwrite Over an existing texture with a new one. |
|
45 * \param aSrcPoint Offset into aSrc where the region's bound's |
|
46 * TopLeft() sits. |
|
47 * \param aPixelBuffer Pass true to upload texture data with an |
|
48 * offset from the base data (generally for pixel buffer objects), |
|
49 * otherwise textures are upload with an absolute pointer to the data. |
|
50 * \param aTextureUnit, the texture unit used temporarily to upload the |
|
51 * surface. This testure may be overridden, clients should not rely on |
|
52 * the contents of this texture after this call or even on this |
|
53 * texture unit being active. |
|
54 * \return Surface format of this texture. |
|
55 */ |
|
56 gfx::SurfaceFormat |
|
57 UploadImageDataToTexture(GLContext* gl, |
|
58 unsigned char* aData, |
|
59 int32_t aStride, |
|
60 gfx::SurfaceFormat aFormat, |
|
61 const nsIntRegion& aDstRegion, |
|
62 GLuint& aTexture, |
|
63 bool aOverwrite = false, |
|
64 bool aPixelBuffer = false, |
|
65 GLenum aTextureUnit = LOCAL_GL_TEXTURE0, |
|
66 GLenum aTextureTarget = LOCAL_GL_TEXTURE_2D); |
|
67 |
|
68 /** |
|
69 * Convenience wrapper around UploadImageDataToTexture for gfx::DataSourceSurface's. |
|
70 */ |
|
71 gfx::SurfaceFormat |
|
72 UploadSurfaceToTexture(GLContext* gl, |
|
73 gfx::DataSourceSurface *aSurface, |
|
74 const nsIntRegion& aDstRegion, |
|
75 GLuint& aTexture, |
|
76 bool aOverwrite = false, |
|
77 const nsIntPoint& aSrcPoint = nsIntPoint(0, 0), |
|
78 bool aPixelBuffer = false, |
|
79 GLenum aTextureUnit = LOCAL_GL_TEXTURE0, |
|
80 GLenum aTextureTarget = LOCAL_GL_TEXTURE_2D); |
|
81 |
|
82 bool CanUploadSubTextures(GLContext* gl); |
|
83 bool CanUploadNonPowerOfTwo(GLContext* gl); |
|
84 |
|
85 } |
|
86 } |
|
87 |
|
88 #endif |