FastUIDraw
texture_image_gl.hpp
Go to the documentation of this file.
1 /*!
2  * \file texture_image_gl.hpp
3  * \brief file texture_image_gl.hpp
4  *
5  * Copyright 2016 by Intel.
6  *
7  * Contact: kevin.rogovin@gmail.com
8  *
9  * This Source Code Form is subject to the
10  * terms of the Mozilla Public License, v. 2.0.
11  * If a copy of the MPL was not distributed with
12  * this file, You can obtain one at
13  * http://mozilla.org/MPL/2.0/.
14  *
15  * \author Kevin Rogovin <kevin.rogovin@gmail.com>
16  *
17  */
18 
19 
20 #ifndef FASTUIDRAW_TEXTURE_IMAGE_GL_HPP
21 #define FASTUIDRAW_TEXTURE_IMAGE_GL_HPP
22 
23 #include <fastuidraw/image.hpp>
26 
27 namespace fastuidraw
28 {
29 namespace gl
30 {
31 /*!\addtogroup GLBackend
32  * @{
33  */
34 
35  /*!
36  * A TextureImage is an Image that is backed by a GL texture.
37  * Creating a TextureImage requires that a GL context is
38  * current. If the GL context supports bindless (i.e one
39  * of the GL_ARB_bindless_texture or GL_NV_bindless_texture
40  * is present), then the created TextureImage will have that
41  * Image::type() is Image::bindless_texture2d, otherwise it
42  * will be Image::context_texture2d.
43  */
44  class TextureImage:public Image
45  {
46  public:
47  /*!
48  * Create a TextureImage from a previously created GL texture
49  * whose binding target is GL_TEXTURE_2D.
50  * \param patlas the ImageAtlas that the created image is part of
51  * \param w width of the texture
52  * \param h height of the texture
53  * \param m number of mipmap levels of the texture
54  * \param texture GL texture name
55  * \param object_owns_texture the created TextureImage will own the
56  * GL texture and will delete the GL texture
57  * when the returned TextureImage is deleted.
58  * If false, the GL texture must be deleted
59  * by the caller AFTER the TextureImage is
60  * deleted.
61  * \param fmt format of the RGBA of the texture
62  * \param allow_bindless if both this is true and the GL/GLES implementation
63  * supports bindless texturing, return an object whose
64  * \ref type() returns \ref bindless_texture2d.
65  */
66  static
68  create(ImageAtlas &patlas, int w, int h, unsigned int m,
69  GLuint texture, bool object_owns_texture,
70  enum format_t fmt = rgba_format,
71  bool allow_bindless = true);
72 
73  /*!
74  * Create a GL texture and use it to back a TextureImage; the
75  * created TextureImage will own the GL texture.
76  * \param patlas the ImageAtlas that the created image is part of
77  * \param w width of the texture
78  * \param h height of the texture
79  * \param m number of mipmap levels of the texture
80  * \param tex_magnification magnification filter to get the texture
81  * \param tex_minification minification filter to get the texture
82  * \param fmt format of the RGBA of the texture
83  * \param allow_bindless if both this is true and the GL/GLES implementation
84  * supports bindless texturing, return an object whose
85  * \ref type() returns \ref bindless_texture2d.
86  */
87  static
89  create(ImageAtlas &patlas, int w, int h, unsigned int m,
90  GLenum tex_magnification, GLenum tex_minification,
91  enum format_t fmt = rgba_format,
92  bool allow_bindless = true);
93 
94  /*!
95  * Create a GL texture and use it to back a TextureImage; the
96  * created TextureImage will own the GL texture.
97  * \param w width of the image to create
98  * \param h height of the image to create
99  * \param patlas the ImageAtlas that the created image is part of
100  * \param image_data image data to which to initialize the image
101  * \param tex_magnification magnification filter to get the texture
102  * \param tex_minification minification filter to get the texture
103  * \param allow_bindless if both this is true and the GL/GLES implementation
104  * supports bindless texturing, return an object whose
105  * \ref type() returns \ref bindless_texture2d.
106  */
107  static
109  create(ImageAtlas &patlas, int w, int h,
110  const ImageSourceBase &image_data,
111  GLenum tex_magnification, GLenum tex_minification,
112  bool allow_bindless = true);
113 
114  ~TextureImage();
115 
116  /*!
117  * Returns the GL texture backing the TextureImage.
118  * The texture binding target is always GL_TEXTURE_2D.
119  * One can modify the -contents- of the texture via
120  * glGetTexParameter familiy of functions or the
121  * contents of the backing store via glTexSubImage2D,
122  * but one should never change its backing store
123  * (via glTexImage2D) or delete it (via glDeleteTextures).
124  * Lastly, recall that \ref Painter works by generating
125  * index and draw buffers that are sent to the GL/GLES
126  * API at Painter::end(), thus if one wants to modify
127  * the texture within a Painter::begin() / Painter::end()
128  * pair, one must modify it from a PainterDrawBreakAction
129  * so that the texture is consumed by the gfx API
130  * before it is modified.
131  */
132  GLuint
133  texture(void) const;
134 
135  private:
136  TextureImage(ImageAtlas &patlas, int w, int h, unsigned int m,
137  bool object_owns_texture, GLuint texture,
138  enum format_t fmt);
139  TextureImage(ImageAtlas &patlas, int w, int h, unsigned int m,
140  bool object_owns_texture, GLuint texture, GLuint64 handle,
141  enum format_t fmt);
142 
143  void *m_d;
144  };
145 /*! @} */
146 
147 } //namespace gl
148 } //namespace fastuidraw
149 
150 #endif
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
A wrapper over a pointer to implement reference counting.
file gl_header.hpp
An Image represents an image comprising of RGBA8 values. The texel values themselves are stored in a ...
Definition: image.hpp:44
static reference_counted_ptr< TextureImage > create(ImageAtlas &patlas, int w, int h, unsigned int m, GLuint texture, bool object_owns_texture, enum format_t fmt=rgba_format, bool allow_bindless=true)
An ImageAtlas is a common location to place images of an application.
GLuint texture(void) const
file image_atlas.hpp
file image.hpp
ImageSourceBase defines the inteface for copying texel data from a source (CPU memory, a file, etc) to an AtlasColorBackingStoreBase derived object.
Definition: image.hpp:234