LibreOffice Module vcl (master)  1
texture.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  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_VCL_INC_OPENGL_TEXTURE_H
21 #define INCLUDED_VCL_INC_OPENGL_TEXTURE_H
22 
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>
28 
29 #include <functional>
30 #include <memory>
31 #include <vector>
32 
34 {
35 public:
36  GLuint mnTexture;
37  int mnWidth;
38  int const mnHeight;
39  GLenum mnFilter;
40  GLuint mnOptStencil;
41 
42  std::unique_ptr<std::vector<int>> mpSlotReferences;
43  std::function<void(int)> mFunctSlotDeallocateCallback;
44 
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 );
49 
50  bool InsertBuffer(int nX, int nY, int nWidth, int nHeight, int nFormat, int nType, sal_uInt8 const * pData);
51 
52  void IncreaseRefCount(int nSlotNumber);
53  void DecreaseRefCount(int nSlotNumber);
54 
55  void InitializeSlotMechanism(int nInitialSlotSize);
56 
57  void SetSlotDeallocateCallback(std::function<void(int)> aCallback)
58  {
59  mFunctSlotDeallocateCallback = aCallback;
60  }
61 
63  {
64  mFunctSlotDeallocateCallback = std::function<void(int)>();
65  }
66 
67  GLuint AddStencil();
68 };
69 
71 {
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
76  std::shared_ptr<ImplOpenGLTexture> mpImpl;
78 
79  inline void GetTextureRect(const SalTwoRect& rPosAry, GLfloat& x1, GLfloat& x2, GLfloat& y1, GLfloat& y2) const;
80 
81  bool IsValid() const
82  {
83  return (mpImpl && mpImpl->mnTexture != 0);
84  }
85 
86 public:
87  OpenGLTexture();
88  OpenGLTexture(const std::shared_ptr<ImplOpenGLTexture>& pImpl, tools::Rectangle aRectangle, int nSlotNumber);
89 
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();
97 
98  bool IsUnique() const;
99 
100  GLuint Id() const;
101  int GetWidth() const;
102  int GetHeight() const;
103 
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;
111 
112  bool CopyData(int nWidth, int nHeight, int nFormat, int nType, sal_uInt8 const * pData);
113 
114  void SaveToFile(const OUString& rFileName);
115 
116  GLenum GetFilter() const;
117  void SetFilter( GLenum nFilter );
118 
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;
124 
125  template<GLenum type>
126  void FillCoords(std::vector<GLfloat>& aCoordVector, const SalTwoRect& rPosAry) const;
127 };
128 
129 template<> void OpenGLTexture::FillCoords<GL_TRIANGLES>(
130  std::vector<GLfloat>& aCoord, const SalTwoRect& rPosAry)
131  const;
132 
133 template<> void OpenGLTexture::FillCoords<GL_TRIANGLE_FAN>(
134  std::vector<GLfloat>& aCoord, const SalTwoRect& rPosAry)
135  const;
136 
137 #endif // INCLUDED_VCL_INC_OPENGL_TEXTURE_H
138 
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< ImplOpenGLTexture > mpImpl
Definition: texture.hxx:76
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
void DecreaseRefCount(int nSlotNumber)
ImplOpenGLTexture(int nWidth, int nHeight, bool bAllocate)
void SetSlotDeallocateCallback(std::function< void(int)> aCallback)
Definition: texture.hxx:57
void InitializeSlotMechanism(int nInitialSlotSize)
bool InsertBuffer(int nX, int nY, int nWidth, int nHeight, int nFormat, int nType, sal_uInt8 const *pData)
int const mnHeight
Definition: texture.hxx:38
void IncreaseRefCount(int nSlotNumber)
GLuint mnTexture
Definition: texture.hxx:36
unsigned char sal_uInt8
void ResetSlotDeallocateCallback()
Definition: texture.hxx:62
tools::Rectangle maRect
Definition: texture.hxx:75
std::function< void(int)> mFunctSlotDeallocateCallback
Definition: texture.hxx:43
bool IsValid() const
Definition: texture.hxx:81
int mnSlotNumber
Definition: texture.hxx:77
GLuint mnOptStencil
Definition: texture.hxx:40
std::unique_ptr< std::vector< int > > mpSlotReferences
Definition: texture.hxx:42