diff options
Diffstat (limited to '')
-rw-r--r-- | vcl/inc/opengl/TextureState.hxx | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/vcl/inc/opengl/TextureState.hxx b/vcl/inc/opengl/TextureState.hxx new file mode 100644 index 000000000..fbf2b9cee --- /dev/null +++ b/vcl/inc/opengl/TextureState.hxx @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#ifndef INCLUDED_VCL_INC_OPENGL_TEXTURE_STATE_H +#define INCLUDED_VCL_INC_OPENGL_TEXTURE_STATE_H + +#include <vcl/opengl/OpenGLHelper.hxx> + +class TextureState +{ +private: + GLuint mnCurrentTextureUnit; + std::vector<GLuint> maBoundTextures; + +public: + TextureState() + : mnCurrentTextureUnit(0) + , maBoundTextures(4, 0) + {} + + static void generate(GLuint& nTexture) + { + glGenTextures(1, &nTexture); + CHECK_GL_ERROR(); + } + + void active(GLuint nTextureUnit) + { + if (mnCurrentTextureUnit != nTextureUnit) + { + glActiveTexture(GL_TEXTURE0 + nTextureUnit); + CHECK_GL_ERROR(); + mnCurrentTextureUnit = nTextureUnit; + } + + } + + void bind(GLuint nTexture) + { + if (maBoundTextures[mnCurrentTextureUnit] != nTexture) + { + glBindTexture(GL_TEXTURE_2D, nTexture); + CHECK_GL_ERROR(); + maBoundTextures[mnCurrentTextureUnit] = nTexture; + } + } + + void unbindAndDelete(GLuint nTexture) + { + unbind(nTexture); + glDeleteTextures(1, &nTexture); + } + + void unbind(GLuint nTexture) + { + for (size_t i = 0; i < maBoundTextures.size(); i++) + { + if (nTexture == maBoundTextures[i]) + maBoundTextures[i] = 0; + } + } + +}; + + + +#endif // INCLUDED_VCL_INC_OPENGL_TEXTURE_STATE_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |