LibreOffice Module vcl (master)  1
TextureState.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  */
10 
11 #ifndef INCLUDED_VCL_INC_OPENGL_TEXTURE_STATE_H
12 #define INCLUDED_VCL_INC_OPENGL_TEXTURE_STATE_H
13 
15 
17 {
18 private:
20  std::vector<GLuint> maBoundTextures;
21 
22 public:
24  : mnCurrentTextureUnit(0)
25  , maBoundTextures(4, 0)
26  {}
27 
28  static void generate(GLuint& nTexture)
29  {
30  glGenTextures(1, &nTexture);
32  }
33 
34  void active(GLuint nTextureUnit)
35  {
36  if (mnCurrentTextureUnit != nTextureUnit)
37  {
38  glActiveTexture(GL_TEXTURE0 + nTextureUnit);
40  mnCurrentTextureUnit = nTextureUnit;
41  }
42 
43  }
44 
45  void bind(GLuint nTexture)
46  {
47  if (maBoundTextures[mnCurrentTextureUnit] != nTexture)
48  {
49  glBindTexture(GL_TEXTURE_2D, nTexture);
51  maBoundTextures[mnCurrentTextureUnit] = nTexture;
52  }
53  }
54 
55  void unbindAndDelete(GLuint nTexture)
56  {
57  unbind(nTexture);
58  glDeleteTextures(1, &nTexture);
59  }
60 
61  void unbind(GLuint nTexture)
62  {
63  for (size_t i = 0; i < maBoundTextures.size(); i++)
64  {
65  if (nTexture == maBoundTextures[i])
66  maBoundTextures[i] = 0;
67  }
68  }
69 
70 };
71 
72 
73 
74 #endif // INCLUDED_VCL_INC_OPENGL_TEXTURE_STATE_H
75 
76 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
GLuint mnCurrentTextureUnit
void active(GLuint nTextureUnit)
int i
static void generate(GLuint &nTexture)
void unbindAndDelete(GLuint nTexture)
void unbind(GLuint nTexture)
#define CHECK_GL_ERROR()
std::vector< GLuint > maBoundTextures
void bind(GLuint nTexture)