Update with current status
[gnash.git] / librender / GnashTexture.h
blob6329f40168f8b1b92c1ef98e056073acdcd6cbbd
1 // GnashTexture.h: GnashImage class used for OpenGL rendering
2 //
3 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc.
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef GNASH_GNASHTEXTURE_H
22 #define GNASH_GNASHTEXTURE_H
24 #include "GnashImage.h"
26 namespace gnash {
28 /// Texture flags
29 enum {
30 GNASH_TEXTURE_VAAPI = 1 << 0
33 /// OpenGL texture format
34 class DSOEXPORT GnashTextureFormat {
35 unsigned int _internal_format;
36 unsigned int _format;
38 public:
39 GnashTextureFormat(image::ImageType type);
41 /// Return GL internal format
42 unsigned int internal_format() const
43 { return _internal_format; }
45 /// Return GL format
46 unsigned int format() const
47 { return _format; }
50 /// OpenGL texture abstraction
51 class DSOEXPORT GnashTexture {
52 unsigned int _width;
53 unsigned int _height;
54 unsigned int _texture;
55 GnashTextureFormat _format;
57 /// OpenGL texture state
58 struct TextureState {
59 unsigned int old_texture;
60 unsigned int was_enabled : 1;
61 unsigned int was_bound : 1;
62 } _texture_state;
64 protected:
65 unsigned int _flags;
67 private:
68 bool init();
70 public:
71 GnashTexture(unsigned int width, unsigned int height,
72 image::ImageType type);
73 virtual ~GnashTexture();
75 /// Return texture flags
76 unsigned int flags() const
77 { return _flags; }
79 /// Return texture width
80 unsigned int width() const
81 { return _width; }
83 /// Return texture height
84 unsigned int height() const
85 { return _height; }
87 /// Return GL texture
88 unsigned int texture() const
89 { return _texture; }
91 /// Return GL internal format
92 unsigned int internal_format() const
93 { return _format.internal_format(); }
95 /// Return GL format
96 unsigned int format() const
97 { return _format.format(); }
99 /// Bind texture to a texturing target
100 bool bind();
102 /// Release texture
103 void release();
105 /// Copy texture data from a buffer.
107 /// Note that this buffer MUST have the same _pitch, or unexpected things
108 /// will happen. In general, it is only safe to copy from another GnashImage
109 /// (or derivative thereof) or unexpected things will happen.
111 /// @param data buffer to copy data from.
112 void update(const std::uint8_t *data);
115 } // gnash namespace
117 #endif /* GNASH_GNASHTEXTURE_H */