1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
24 #include <vcl/dllapi.h>
25 #include <vcl/salgtype.hxx>
26 #include <rtl/ustring.hxx>
27 #include <tools/gen.hxx>
33 class ImplOpenGLTexture
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
);
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)>();
70 class VCL_DLLPUBLIC OpenGLTexture final
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
;
79 inline void GetTextureRect(const SalTwoRect
& rPosAry
, GLfloat
& x1
, GLfloat
& x2
, GLfloat
& y1
, GLfloat
& y2
) const;
83 return (mpImpl
&& mpImpl
->mnTexture
!= 0);
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
);
98 bool IsUnique() 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;
108 void Read( GLenum nFormat
, GLenum nType
, sal_uInt8
* pData
);
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
)
133 template<> void OpenGLTexture::FillCoords
<GL_TRIANGLE_FAN
>(
134 std::vector
<GLfloat
>& aCoord
, const SalTwoRect
& rPosAry
)
137 #endif // INCLUDED_VCL_INC_OPENGL_TEXTURE_H
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */