Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / inc / opengl / texture.hxx
blobf555f09d24a5f2a64b289a6686de9ecc321d41aa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_VCL_INC_OPENGL_TEXTURE_H
21 #define INCLUDED_VCL_INC_OPENGL_TEXTURE_H
23 #include <GL/glew.h>
24 #include <vcl/dllapi.h>
25 #include <vcl/salgtype.hxx>
27 #include <tools/gen.hxx>
29 #include <memory>
30 #include <vector>
32 class ImplOpenGLTexture
34 public:
35 int mnRefCount;
36 GLuint mnTexture;
37 int mnWidth;
38 int mnHeight;
39 GLenum mnFilter;
41 std::unique_ptr<std::vector<int>> mpSlotReferences;
42 int mnFreeSlots;
44 ImplOpenGLTexture( int nWidth, int nHeight, bool bAllocate );
45 ImplOpenGLTexture( int nWidth, int nHeight, int nFormat, int nType, void const * pData );
46 ImplOpenGLTexture( int nX, int nY, int nWidth, int nHeight );
47 ~ImplOpenGLTexture();
49 bool InsertBuffer(int nX, int nY, int nWidth, int nHeight, int nFormat, int nType, sal_uInt8* pData);
51 void IncreaseRefCount(int nSlotNumber)
53 mnRefCount++;
54 if (mpSlotReferences && nSlotNumber >= 0)
56 if (mpSlotReferences->at(nSlotNumber) == 0)
57 mnFreeSlots--;
58 mpSlotReferences->at(nSlotNumber)++;
62 void DecreaseRefCount(int nSlotNumber)
64 mnRefCount--;
65 if (mpSlotReferences && nSlotNumber >= 0)
67 mpSlotReferences->at(nSlotNumber)--;
68 if (mpSlotReferences->at(nSlotNumber) == 0)
69 mnFreeSlots++;
73 bool ExistRefs()
75 return mnRefCount > 0;
78 bool InitializeSlots(int nSlotSize);
79 int FindFreeSlot();
82 class VCL_DLLPUBLIC OpenGLTexture
84 private:
85 // if the rect size doesn't match the mpImpl one, this instance
86 // is a sub-area from the real OpenGL texture
87 Rectangle maRect;
88 ImplOpenGLTexture* mpImpl;
89 int mnSlotNumber;
91 public:
92 OpenGLTexture();
93 OpenGLTexture(ImplOpenGLTexture* pImpl, Rectangle aRectangle, int nSlotNumber = 0);
95 OpenGLTexture( int nWidth, int nHeight, bool bAllocate = true );
96 OpenGLTexture( int nWidth, int nHeight, int nFormat, int nType, void const * pData );
97 OpenGLTexture( int nX, int nY, int nWidth, int nHeight );
98 OpenGLTexture( const OpenGLTexture& rTexture );
99 OpenGLTexture( const OpenGLTexture& rTexture, int nX, int nY, int nWidth, int nHeight );
100 virtual ~OpenGLTexture();
102 bool IsUnique() const;
104 GLuint Id() const;
105 int GetWidth() const;
106 int GetHeight() const;
107 void GetCoord( GLfloat* pCoord, const SalTwoRect& rPosAry, bool bInverted=false ) const;
108 void GetWholeCoord( GLfloat* pCoord ) const;
110 void Bind();
111 void Unbind();
112 bool Draw();
113 void Read( GLenum nFormat, GLenum nType, sal_uInt8* pData );
115 GLenum GetFilter() const;
116 void SetFilter( GLenum nFilter );
118 operator bool() const;
119 OpenGLTexture& operator=( const OpenGLTexture& rTexture );
120 bool operator==( const OpenGLTexture& rTexture ) const;
121 bool operator!=( const OpenGLTexture& rTexture ) const;
124 #endif // INCLUDED_VCL_INC_OPENGL_TEXTURE_H
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */