bump product version to 6.4.0.3
[LibreOffice.git] / vcl / inc / opengl / texture.hxx
blob384e2a8790976f3a6a91d295956833b449f447ce
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 <epoxy/gl.h>
24 #include <vcl/dllapi.h>
25 #include <vcl/salgtype.hxx>
26 #include <rtl/ustring.hxx>
27 #include <tools/gen.hxx>
29 #include <functional>
30 #include <memory>
31 #include <vector>
33 class ImplOpenGLTexture
35 public:
36 GLuint mnTexture;
37 int mnWidth;
38 int const mnHeight;
39 GLenum mnFilter;
40 GLuint mnOptStencil;
42 std::unique_ptr<std::vector<int>> mpSlotReferences;
43 std::function<void(int)> mFunctSlotDeallocateCallback;
45 ImplOpenGLTexture( int nWidth, int nHeight, bool bAllocate );
46 ImplOpenGLTexture( int nWidth, int nHeight, int nFormat, int nType, void const * pData );
47 ImplOpenGLTexture( int nX, int nY, int nWidth, int nHeight );
48 ~ImplOpenGLTexture();
50 bool InsertBuffer(int nX, int nY, int nWidth, int nHeight, int nFormat, int nType, sal_uInt8 const * pData);
52 void IncreaseRefCount(int nSlotNumber);
53 void DecreaseRefCount(int nSlotNumber);
55 void InitializeSlotMechanism(int nInitialSlotSize);
57 void SetSlotDeallocateCallback(std::function<void(int)> aCallback)
59 mFunctSlotDeallocateCallback = aCallback;
62 void ResetSlotDeallocateCallback()
64 mFunctSlotDeallocateCallback = std::function<void(int)>();
67 GLuint AddStencil();
70 class VCL_DLLPUBLIC OpenGLTexture final
72 private:
73 // if the rect size doesn't match the mpImpl one, this instance
74 // is a sub-area from the real OpenGL texture
75 tools::Rectangle maRect;
76 std::shared_ptr<ImplOpenGLTexture> mpImpl;
77 int mnSlotNumber;
79 inline void GetTextureRect(const SalTwoRect& rPosAry, GLfloat& x1, GLfloat& x2, GLfloat& y1, GLfloat& y2) const;
81 bool IsValid() const
83 return (mpImpl && mpImpl->mnTexture != 0);
86 public:
87 OpenGLTexture();
88 OpenGLTexture(const std::shared_ptr<ImplOpenGLTexture>& pImpl, tools::Rectangle aRectangle, int nSlotNumber);
90 OpenGLTexture( int nWidth, int nHeight, bool bAllocate = true );
91 OpenGLTexture( int nWidth, int nHeight, int nFormat, int nType, void const * pData );
92 OpenGLTexture( int nX, int nY, int nWidth, int nHeight );
93 OpenGLTexture( const OpenGLTexture& rTexture );
94 OpenGLTexture( OpenGLTexture&& rTexture ) noexcept;
95 OpenGLTexture( const OpenGLTexture& rTexture, int nX, int nY, int nWidth, int nHeight );
96 ~OpenGLTexture();
98 bool IsUnique() const;
100 GLuint Id() const;
101 int GetWidth() const;
102 int GetHeight() const;
104 void GetCoord( GLfloat* pCoord, const SalTwoRect& rPosAry, bool bInverted=false ) const;
105 void GetWholeCoord( GLfloat* pCoord ) const;
106 void Bind();
107 void Unbind();
108 void Read( GLenum nFormat, GLenum nType, sal_uInt8* pData );
109 GLuint AddStencil();
110 GLuint StencilId() const;
112 bool CopyData(int nWidth, int nHeight, int nFormat, int nType, sal_uInt8 const * pData);
114 void SaveToFile(const OUString& rFileName);
116 GLenum GetFilter() const;
117 void SetFilter( GLenum nFilter );
119 operator bool() const;
120 OpenGLTexture& operator=( const OpenGLTexture& rTexture );
121 OpenGLTexture& operator=( OpenGLTexture&& rTexture );
122 bool operator==( const OpenGLTexture& rTexture ) const;
123 bool operator!=( const OpenGLTexture& rTexture ) const;
125 template<GLenum type>
126 void FillCoords(std::vector<GLfloat>& aCoordVector, const SalTwoRect& rPosAry) const;
129 template<> void OpenGLTexture::FillCoords<GL_TRIANGLES>(
130 std::vector<GLfloat>& aCoord, const SalTwoRect& rPosAry)
131 const;
133 template<> void OpenGLTexture::FillCoords<GL_TRIANGLE_FAN>(
134 std::vector<GLfloat>& aCoord, const SalTwoRect& rPosAry)
135 const;
137 #endif // INCLUDED_VCL_INC_OPENGL_TEXTURE_H
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */